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

+6
View File
@@ -74,6 +74,12 @@ button.sw { text-align: left; color: var(--kh-text); }
padding: 0 8px; font: inherit; }
.kh-inset { margin: 0 14px 14px; }
.kh-h2 { font-size: var(--kh-fs-lg); font-weight: 600; margin: 6px 0 0; }
/* Profile forms (issue #31): actions at the end of a form, read-only facts. */
.form .kh-formactions, .kh-formactions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.kh-facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; padding: 12px 14px; font-size: 12.5px; }
.kh-facts dt { color: var(--kh-text-2); }
.kh-facts dd { margin: 0; }
.fgroup .pb > p:first-child { margin-top: 0; }
.kh-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.kh-table th { text-align: left; font-weight: 600; color: var(--kh-text-2); font-size: var(--kh-fs-sm); padding: 6px 10px; border-bottom: 1px solid var(--kh-border-strong); }
.kh-table td { padding: 7px 10px; border-bottom: 1px solid var(--kh-border); vertical-align: middle; }
@@ -140,3 +140,81 @@ a.tab { text-decoration: none; }
@media (max-width: 899px) {
.gsearch .ph { display: none; }
}
/* ---- Kh components (issues #27, #29) ---- */
/* Form fields */
input.in.num, .f .in input.num { text-align: right; font-variant-numeric: tabular-nums; }
input.in.mono { font-family: var(--kh-mono); font-size: 12px; font-weight: 600; color: var(--kh-accent-text); }
.kh-datebox svg.i { color: var(--kh-text-3); flex: none; }
.kh-check { height: auto; min-height: 30px; cursor: pointer; }
.kh-check input { accent-color: var(--kh-accent); width: 15px; height: 15px; margin: 0; }
.kh-switch { display: inline-flex; align-items: center; gap: 8px; height: 30px; border: 0; background: none; padding: 0; font: inherit; color: var(--kh-text); cursor: pointer; }
.kh-switch:disabled { opacity: .55; cursor: default; }
.kh-vsum { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--kh-radius-lg); background: var(--kh-err-soft); color: var(--kh-err-text); font-size: 12.5px; }
.kh-vsum.wide { grid-column: 1 / -1; }
.kh-vsum ul { margin: 4px 0 0; padding-left: 18px; }
.kh-vsum:focus { outline: 2px solid var(--kh-err); outline-offset: 2px; }
.kh-link { border: 0; background: none; padding: 0; font: inherit; color: inherit; text-decoration: underline; cursor: pointer; text-align: left; }
/* Hotlink */
.kh-hotlink { position: relative; }
.kh-hotlink .in input.code { flex: none; width: 10ch; }
.kh-lk { border: 0; background: none; padding: 2px; color: var(--kh-text-3); cursor: pointer; border-radius: 4px; display: grid; place-items: center; }
.kh-lk:hover { color: var(--kh-accent-text); background: var(--kh-surface-3); }
.kh-hits { position: absolute; top: calc(100% + 3px); left: 0; right: 0; z-index: 15; list-style: none; margin: 0; padding: 4px; max-height: 260px; overflow: auto;
background: var(--kh-surface); border: 1px solid var(--kh-border); border-radius: 8px; box-shadow: var(--kh-shadow-lg); }
.kh-hits li { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 6px; font-size: 12.5px; cursor: pointer; white-space: nowrap; overflow: hidden; }
.kh-hits li .code { font: 600 12px var(--kh-mono); color: var(--kh-accent-text); min-width: 8ch; }
.kh-hits li .desc { overflow: hidden; text-overflow: ellipsis; color: var(--kh-text-2); }
.kh-hits li.on, .kh-hits li:hover { background: var(--kh-accent-soft); }
.kh-hits li.none { color: var(--kh-text-3); cursor: default; background: none; }
.kh-hits li.new { color: var(--kh-accent-text); border-top: 1px solid var(--kh-border); margin-top: 3px; }
/* Display */
.kh-money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.kh-money.neg { color: var(--kh-err); }
a.kh-tilelink { color: inherit; text-decoration: none; }
a.kh-tilelink:hover { border-color: var(--kh-accent); }
.kh-chipx { border: 0; background: none; padding: 0; color: inherit; display: grid; place-items: center; cursor: pointer; }
.kh-steps { list-style: none; margin: 0; }
.steps.kh-steps { padding: 4px 0; }
.vsteps.kh-steps { padding: 6px 0; }
button.tab { border: 0; border-bottom: 2px solid transparent; background: none; font: inherit; cursor: pointer; }
button.tab.active { border-bottom-color: var(--kh-accent); }
/* Dialog and drawer */
.dialog.kh-sm { width: 420px; } .dialog.kh-md { width: 640px; } .dialog.kh-lg { width: 860px; }
.dialog .db { max-height: calc(100vh - 220px); overflow: auto; }
.drawer.wide { width: 560px; }
.kh-close { width: 28px; height: 28px; background: none; cursor: pointer; }
@media (max-width: 700px) { .drawer, .drawer.wide { width: 100vw; } }
/* Toolbar */
.kh-toolbar { flex-wrap: nowrap; min-width: 0; }
.kh-toolbar .grp { flex: none; }
.kh-toolbar [data-ovf-hidden] { display: none !important; }
button.ib { background: none; padding: 0; cursor: pointer; font: inherit; }
button.ib.primary { background: var(--kh-accent); }
.ib:disabled, .ib.disabled { opacity: .35; cursor: default; pointer-events: none; }
button.ctx { cursor: pointer; }
.ctx:disabled { opacity: .45; cursor: default; }
.kh-morewrap { position: relative; flex: none; }
.kh-catch { position: fixed; inset: 0; z-index: 19; }
.kh-moremenu { min-width: 240px; }
.popmenu .mi.danger, .popmenu .mi.danger svg.i { color: var(--kh-err); }
.popmenu .mi:disabled { opacity: .45; }
/* Document header and record pages */
.kh-min0 { min-width: 0; }
.kh-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kh-record { display: flex; flex-direction: column; gap: var(--kh-gap); min-width: 0; }
.kh-recordbody { overflow: visible; }
.kh-recordtab { min-width: 0; overflow-x: auto; }
@media (max-width: 1200px) { .dochead { grid-template-columns: 1fr 1fr; } .dochead > div:last-child { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--kh-border); align-items: flex-start; text-align: left; } }
@media (max-width: 800px) { .dochead { grid-template-columns: 1fr; } .dochead > div + div { border-left: 0; border-top: 1px solid var(--kh-border); } }
/* Component catalog (development) */
.kh-catalog { display: flex; flex-direction: column; gap: var(--kh-gap); padding-top: var(--kh-gap); }
.kh-catalogrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.kh-catalogbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 11px; }
.kh-resizable { resize: horizontal; overflow: hidden; min-width: 240px; max-width: 100%; padding: 2px 6px 12px 2px; border: 1px dashed var(--kh-border); border-radius: var(--kh-radius-lg); }
+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();
},