feat: Kh component library, record pages and profile security (M3, part 2)

Adds the building blocks every later screen uses, so modules are built from
one set of components instead of ad hoc markup:

- Form components (KhForm, KhTextBox, KhNumberBox, KhDateBox, KhSelect,
  KhCheck, KhSwitch, KhHotlink) with Italian number and date input, inline
  calculation (=10*3), field messages plus a summary that focuses the field,
  and service errors added by field name.
- Display and window components (panels, tiles, badges, chips, money, tabs
  with Alt+1..9, steps, dialog, side drawer and DrawerService).
- KhIconToolbar that keeps one line and moves less used commands into the
  "..." menu, KhDocHead, and the RecordPage/DocumentPage/MasterDataPage bases
  with standard commands, shortcuts and save/cancel/delete flow (#27, #29).
- Development-only component catalog and sample document page.
- Profile: personal data, password change that ends other sessions, TOTP
  enable/disable and recovery codes through ProfileService (#31).

Refs #27 #29 #31

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-11 18:11:16 +01:00
1 parent cf6f849cc1
commit d958e7372d
57 files changed
+5249 -12

No files matched your search

+104 -1
View File
@@ -22,10 +22,16 @@
return combo + key;
}
// The keys an element handles itself (data-kh-prevent="ArrowDown F4"): the page shortcuts leave them alone.
function preventedBy(element, combo) {
const list = element && element.getAttribute ? element.getAttribute("data-kh-prevent") : null;
return !!list && list.split(" ").indexOf(combo) >= 0;
}
function onKeyDown(e) {
if (!shortcutTarget || e.isComposing) return;
const combo = comboOf(e);
if (!combo || !shortcutCombos.has(combo)) return;
if (!combo || !shortcutCombos.has(combo) || preventedBy(e.target, combo)) return;
e.preventDefault();
e.stopPropagation();
shortcutTarget.invokeMethodAsync("OnShortcut", combo).catch(function () { /* circuit gone */ });
@@ -87,6 +93,103 @@
}
},
// Stops the browser default of the keys listed in data-kh-prevent (read at each key, so Blazor can change it):
// arrows and Enter in an open hotlink list, + and - in a date field.
preventKeys: function (element) {
if (!element || element.khPrevent) return;
element.khPrevent = true;
element.addEventListener("keydown", function (e) {
// Date fields: + and - move one day when the field holds a whole date, and are typed otherwise (5-3-26, +30).
if ((e.key === "+" || e.key === "-") && !e.ctrlKey && !e.altKey && element.hasAttribute("data-kh-datestep")
&& /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(element.value)) {
e.preventDefault();
e.stopPropagation();
element.dispatchEvent(new KeyboardEvent("keydown", { key: e.key === "+" ? "ArrowUp" : "ArrowDown", bubbles: true }));
return;
}
const combo = comboOf(e);
if (combo && preventedBy(element, combo)) e.preventDefault();
});
},
// Places a drop-down menu under its button with fixed coordinates, aligned right, shorter when the window is.
placeMenu: function (menu) {
const anchor = menu && menu.parentElement;
if (!anchor) return;
const r = anchor.getBoundingClientRect();
const below = window.innerHeight - r.bottom - 12;
const above = r.top - 12;
menu.style.position = "fixed";
menu.style.right = Math.max(8, window.innerWidth - r.right) + "px";
menu.style.left = "auto";
if (below >= 200 || below >= above) {
menu.style.top = (r.bottom + 6) + "px";
menu.style.bottom = "auto";
menu.style.maxHeight = below + "px";
} else {
menu.style.bottom = (window.innerHeight - r.top + 6) + "px";
menu.style.top = "auto";
menu.style.maxHeight = above + "px";
}
menu.style.overflowY = "auto";
},
// Moves the focus to the first field or button inside an element (dialogs, side panels).
focusFirst: function (element) {
if (!element) return;
const target = element.querySelector("[autofocus], input:not([type=hidden]):not([disabled]):not([readonly]), select:not([disabled]), textarea:not([disabled]):not([readonly]), .db button:not([disabled]), .df button:not([disabled])")
|| element.querySelector("button:not([disabled])");
if (target) target.focus();
},
// Keeps a toolbar on one line: the commands with the highest data-ovf move out (data-ovf-hidden) until the bar
// fits, then .NET is told which ones, to list them in the "..." menu.
watchToolbar: function (element, target) {
if (!element) return;
element.khToolbar = target;
element.khObserver = new ResizeObserver(function () { window.khaemhat.fitToolbar(element); });
element.khObserver.observe(element);
window.khaemhat.fitToolbar(element);
},
fitToolbar: function (element) {
if (!element || !element.khToolbar || element.clientWidth === 0) return;
const items = Array.prototype.slice.call(element.querySelectorAll("[data-ovf]"));
const groups = element.querySelectorAll("[data-ovf-group]");
items.forEach(function (item) { item.removeAttribute("data-ovf-hidden"); });
groups.forEach(function (group) { group.removeAttribute("data-ovf-hidden"); });
const order = items.map(function (item, index) { return { item: item, index: index, priority: Number(item.getAttribute("data-ovf")) || 0 }; })
.sort(function (a, b) { return b.priority - a.priority || b.index - a.index; });
const hidden = [];
for (let i = 0; i < order.length && element.scrollWidth > element.clientWidth; i++) {
order[i].item.setAttribute("data-ovf-hidden", "");
hidden.push(order[i].item.getAttribute("data-id"));
}
groups.forEach(function (group) {
const children = group.querySelectorAll("[data-ovf]");
if (children.length > 0 && Array.prototype.every.call(children, function (c) { return c.hasAttribute("data-ovf-hidden"); })) {
group.setAttribute("data-ovf-hidden", "");
}
});
element.querySelectorAll(".sep").forEach(function (sep) {
const next = sep.nextElementSibling;
if (next && next.hasAttribute("data-ovf-hidden")) sep.setAttribute("data-ovf-hidden", "");
else sep.removeAttribute("data-ovf-hidden");
});
const key = hidden.join(",");
if (element.khOverflow !== key) {
element.khOverflow = key;
element.khToolbar.invokeMethodAsync("SetOverflow", hidden).catch(function () { /* circuit gone */ });
}
},
unwatchToolbar: function (element) {
if (!element) return;
if (element.khObserver) element.khObserver.disconnect();
element.khObserver = null;
element.khToolbar = null;
},
print: function () {
window.print();
},