feat: application shell, localized texts and user preferences (M3, part 1)
The pages built so far now live inside the shell of the mockups instead of the M0 placeholder, every interface text comes from Resources/it-IT, and each user keeps their own look and start page. - Shell: top bar, collapsible side menu with fly-out sub-menus, status bar and tabs that keep each page alive (page type and route values per tab, so a tab never shows another page); at most 12 tabs, least-used clean tab evicted. - One shortcut table with Alt variants for the combinations browsers keep (Ctrl+W, Ctrl+Tab, Ctrl+N); command palette for pages and commands. - ITexts over embedded JSON; tests forbid literal texts in .razor components and check that every key used exists. - User settings in sys_user_settings / user_settings; theme written on the server; profile page with live preview, start page, sessions and shortcuts. - Home, coming-soon pages for later milestones, localized sign-in and error pages; ADR 0020; wiki, CHANGELOG, STATUS and data model updated. Refs #25 #26 #31 #33 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1c30054e3d
commit
cf6f849cc1
72 files changed
+5785
-259
No files matched your search
@@ -0,0 +1,99 @@
|
||||
// Khaemhat browser interop (SPEC §1.1: JavaScript only as minimal interop, no framework, no bundler).
|
||||
// Everything lives under window.khaemhat; .NET calls these functions through IJSRuntime.
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
let shortcutTarget = null;
|
||||
let shortcutCombos = new Set();
|
||||
let unloadGuard = false;
|
||||
|
||||
// The combination of a key event in the form used by KeyboardShortcuts.cs: "Ctrl+Shift+K", "F9", "Alt+1", "Escape".
|
||||
function comboOf(e) {
|
||||
let key;
|
||||
if (/^Key[A-Z]$/.test(e.code)) key = e.code.substring(3);
|
||||
else if (/^Digit[0-9]$/.test(e.code)) key = e.code.substring(5);
|
||||
else if (e.key === " ") key = "Space";
|
||||
else key = e.key;
|
||||
if (key === "Control" || key === "Alt" || key === "Shift" || key === "Meta") return null;
|
||||
let combo = "";
|
||||
if (e.ctrlKey || e.metaKey) combo += "Ctrl+";
|
||||
if (e.altKey) combo += "Alt+";
|
||||
if (e.shiftKey) combo += "Shift+";
|
||||
return combo + key;
|
||||
}
|
||||
|
||||
function onKeyDown(e) {
|
||||
if (!shortcutTarget || e.isComposing) return;
|
||||
const combo = comboOf(e);
|
||||
if (!combo || !shortcutCombos.has(combo)) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
shortcutTarget.invokeMethodAsync("OnShortcut", combo).catch(function () { /* circuit gone */ });
|
||||
}
|
||||
|
||||
function onBeforeUnload(e) {
|
||||
if (!unloadGuard) return;
|
||||
e.preventDefault();
|
||||
e.returnValue = "";
|
||||
}
|
||||
|
||||
window.khaemhat = {
|
||||
// Sets (or removes, with null) attributes of the root element: data-theme, data-accent, data-density...
|
||||
applyRoot: function (attributes) {
|
||||
const root = document.documentElement;
|
||||
for (const name in attributes) {
|
||||
const value = attributes[name];
|
||||
if (value === null || value === undefined) root.removeAttribute(name);
|
||||
else root.setAttribute(name, value);
|
||||
}
|
||||
},
|
||||
|
||||
// Registers the .NET object that receives the shortcuts, and the combinations it wants.
|
||||
startShortcuts: function (target, combos) {
|
||||
shortcutTarget = target;
|
||||
shortcutCombos = new Set(combos);
|
||||
document.removeEventListener("keydown", onKeyDown, true);
|
||||
document.addEventListener("keydown", onKeyDown, true);
|
||||
},
|
||||
|
||||
stopShortcuts: function () {
|
||||
shortcutTarget = null;
|
||||
document.removeEventListener("keydown", onKeyDown, true);
|
||||
},
|
||||
|
||||
// Asks the browser to confirm leaving the page while a tab has unsaved changes.
|
||||
setUnloadGuard: function (on) {
|
||||
unloadGuard = !!on;
|
||||
window.removeEventListener("beforeunload", onBeforeUnload);
|
||||
if (unloadGuard) window.addEventListener("beforeunload", onBeforeUnload);
|
||||
},
|
||||
|
||||
// The window width, to collapse the menu under 1100 px when the user never chose.
|
||||
viewportWidth: function () {
|
||||
return window.innerWidth;
|
||||
},
|
||||
|
||||
// Round trip for the latency shown in the status bar.
|
||||
ping: function () {
|
||||
return true;
|
||||
},
|
||||
|
||||
// Moves the focus to the first element matching a selector.
|
||||
focus: function (selector) {
|
||||
const element = document.querySelector(selector);
|
||||
if (element) {
|
||||
element.focus();
|
||||
if (typeof element.select === "function") element.select();
|
||||
}
|
||||
},
|
||||
|
||||
print: function () {
|
||||
window.print();
|
||||
},
|
||||
|
||||
// Opens an address (the wiki help) in a new window, without giving it access to this one.
|
||||
openWindow: function (url) {
|
||||
window.open(url, "_blank", "noopener");
|
||||
}
|
||||
};
|
||||
})();
|
||||
Reference in new issue
Block a user