@clagentic/console 1.12.0 → 1.13.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/README.md +7 -1
  2. package/bin/cli.js +18 -15
  3. package/lib/agent-roster-ws.js +38 -13
  4. package/lib/agent-roster.js +111 -12
  5. package/lib/agents.js +68 -33
  6. package/lib/atomic-install.js +334 -0
  7. package/lib/build-changes.js +33 -4
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-offer.js +12 -0
  10. package/lib/chat-width.js +31 -0
  11. package/lib/cli/agent-usage.js +126 -0
  12. package/lib/cli/arg-validation.js +1 -1
  13. package/lib/cli/compact-output.js +69 -0
  14. package/lib/cli/ipc-subcommands.js +92 -67
  15. package/lib/cli/output.js +28 -0
  16. package/lib/cli/restart-verb.js +132 -0
  17. package/lib/cli/schedule-input-subcommands.js +45 -8
  18. package/lib/cli/session-subcommands.js +37 -11
  19. package/lib/cli/settings-subcommands.js +74 -0
  20. package/lib/cli-transcript-title.js +56 -3
  21. package/lib/client-files.js +79 -0
  22. package/lib/daemon.js +100 -28
  23. package/lib/default-avatar-color.js +4 -0
  24. package/lib/drain.js +58 -10
  25. package/lib/mcp-tool-input.js +2 -2
  26. package/lib/model-families.js +49 -1
  27. package/lib/notify/type-registry.js +4 -0
  28. package/lib/notify/types.js +7 -4
  29. package/lib/pages.js +13 -63
  30. package/lib/permission-summary.js +12 -16
  31. package/lib/plan-usage-reader.js +70 -0
  32. package/lib/project-connection.js +4 -2
  33. package/lib/project-filesystem.js +6 -7
  34. package/lib/project-notifications.js +55 -8
  35. package/lib/project-prompt-expiry-settings.js +42 -0
  36. package/lib/project-sessions.js +52 -0
  37. package/lib/project-settings-gate.js +98 -0
  38. package/lib/project-user-mention.js +3 -2
  39. package/lib/project.js +1 -1
  40. package/lib/prompt-expiry-settings.js +49 -0
  41. package/lib/prompt-expiry.js +24 -3
  42. package/lib/prompt-kinds/codecs.js +6 -2
  43. package/lib/public/app.js +36 -36
  44. package/lib/public/css/admin.css +156 -170
  45. package/lib/public/css/agent-messages.css +24 -24
  46. package/lib/public/css/agent-picker.css +90 -38
  47. package/lib/public/css/agent-roster.css +61 -27
  48. package/lib/public/css/at-agents.css +10 -10
  49. package/lib/public/css/base.css +207 -184
  50. package/lib/public/css/chat-layout.css +228 -0
  51. package/lib/public/css/command-palette.css +86 -88
  52. package/lib/public/css/diagnostics.css +78 -204
  53. package/lib/public/css/diff.css +10 -10
  54. package/lib/public/css/filebrowser.css +32 -60
  55. package/lib/public/css/home-hub.css +100 -100
  56. package/lib/public/css/icon-strip.css +195 -238
  57. package/lib/public/css/input.css +191 -212
  58. package/lib/public/css/login-panel.css +16 -16
  59. package/lib/public/css/loop.css +96 -187
  60. package/lib/public/css/mention.css +49 -110
  61. package/lib/public/css/menus.css +162 -169
  62. package/lib/public/css/messages.css +49 -123
  63. package/lib/public/css/mobile-nav.css +207 -264
  64. package/lib/public/css/notifications-center.css +45 -124
  65. package/lib/public/css/overlay.css +269 -0
  66. package/lib/public/css/overlays.css +134 -156
  67. package/lib/public/css/playbook.css +41 -41
  68. package/lib/public/css/profile.css +43 -112
  69. package/lib/public/css/rewind.css +112 -112
  70. package/lib/public/css/scheduler-modal.css +27 -135
  71. package/lib/public/css/scheduler.css +204 -210
  72. package/lib/public/css/server-settings.css +173 -239
  73. package/lib/public/css/session-search.css +20 -20
  74. package/lib/public/css/settings-nav.css +197 -0
  75. package/lib/public/css/sidebar.css +213 -304
  76. package/lib/public/css/skills.css +121 -135
  77. package/lib/public/css/sticky-notes.css +114 -200
  78. package/lib/public/css/stt.css +17 -26
  79. package/lib/public/css/team-panel.css +36 -36
  80. package/lib/public/css/team-view.css +9 -9
  81. package/lib/public/css/title-bar.css +83 -100
  82. package/lib/public/css/tooltip.css +10 -10
  83. package/lib/public/css/user-settings.css +78 -131
  84. package/lib/public/css/user-shell.css +125 -29
  85. package/lib/public/index.html +178 -177
  86. package/lib/public/manifest.json +0 -2
  87. package/lib/public/modules/admin.js +54 -92
  88. package/lib/public/modules/agent-avatar.js +134 -3
  89. package/lib/public/modules/agent-messages.js +2 -1
  90. package/lib/public/modules/agent-picker.js +23 -21
  91. package/lib/public/modules/agent-roster-groups.js +128 -0
  92. package/lib/public/modules/agent-roster.js +40 -11
  93. package/lib/public/modules/app-connection.js +13 -1
  94. package/lib/public/modules/app-cursors.js +9 -9
  95. package/lib/public/modules/app-favicon.js +8 -16
  96. package/lib/public/modules/app-header.js +28 -19
  97. package/lib/public/modules/app-history-replay.js +67 -4
  98. package/lib/public/modules/app-home-hub.js +15 -0
  99. package/lib/public/modules/app-loop-ui.js +41 -47
  100. package/lib/public/modules/app-loop-wizard.js +9 -10
  101. package/lib/public/modules/app-messages.js +32 -36
  102. package/lib/public/modules/app-misc.js +22 -92
  103. package/lib/public/modules/app-modals.js +98 -0
  104. package/lib/public/modules/app-notifications.js +124 -135
  105. package/lib/public/modules/app-panels.js +28 -32
  106. package/lib/public/modules/app-projects.js +30 -40
  107. package/lib/public/modules/app-rate-limit.js +26 -9
  108. package/lib/public/modules/app-rendering.js +128 -110
  109. package/lib/public/modules/app-skills-install.js +6 -4
  110. package/lib/public/modules/assistant-identity.js +55 -0
  111. package/lib/public/modules/at-agents.js +3 -0
  112. package/lib/public/modules/build-guard.js +25 -11
  113. package/lib/public/modules/chat-width-choice.js +75 -0
  114. package/lib/public/modules/chat-width-prefs.js +52 -0
  115. package/lib/public/modules/chat-width.js +102 -0
  116. package/lib/public/modules/collapsible-text.js +36 -4
  117. package/lib/public/modules/command-palette.js +28 -34
  118. package/lib/public/modules/context-sources.js +3 -5
  119. package/lib/public/modules/diagnostics.js +130 -129
  120. package/lib/public/modules/info-panel.js +31 -0
  121. package/lib/public/modules/injected-identity.js +8 -8
  122. package/lib/public/modules/input-list-menu.js +39 -0
  123. package/lib/public/modules/input.js +22 -21
  124. package/lib/public/modules/markdown.js +10 -11
  125. package/lib/public/modules/mcp-ui.js +4 -14
  126. package/lib/public/modules/mention.js +100 -229
  127. package/lib/public/modules/message-header.js +80 -0
  128. package/lib/public/modules/message-participants.js +39 -0
  129. package/lib/public/modules/mobile-action-sheet.js +46 -0
  130. package/lib/public/modules/mobile-nav-sheet.js +104 -0
  131. package/lib/public/modules/model-families.js +41 -4
  132. package/lib/public/modules/note-order.js +39 -0
  133. package/lib/public/modules/notifications.js +35 -52
  134. package/lib/public/modules/overlay-history.js +73 -19
  135. package/lib/public/modules/overlay-menu.js +123 -0
  136. package/lib/public/modules/overlay-modal.js +186 -0
  137. package/lib/public/modules/overlay-registry.js +392 -0
  138. package/lib/public/modules/overlay-stack.js +110 -0
  139. package/lib/public/modules/overlay.js +117 -0
  140. package/lib/public/modules/popover-position.js +18 -2
  141. package/lib/public/modules/preference-sync.js +28 -0
  142. package/lib/public/modules/profile.js +24 -49
  143. package/lib/public/modules/project-settings.js +27 -172
  144. package/lib/public/modules/prompt-expiry-controls.js +46 -0
  145. package/lib/public/modules/prompt-kinds/command-summary.js +149 -0
  146. package/lib/public/modules/prompt-kinds/permission.js +70 -92
  147. package/lib/public/modules/prompts.js +1 -2
  148. package/lib/public/modules/qrcode.js +6 -21
  149. package/lib/public/modules/queued-button.js +15 -2
  150. package/lib/public/modules/rewind.js +9 -3
  151. package/lib/public/modules/schedule-time.js +32 -7
  152. package/lib/public/modules/scheduled-outbox.js +51 -18
  153. package/lib/public/modules/scheduler-config.js +87 -127
  154. package/lib/public/modules/scheduler.js +29 -26
  155. package/lib/public/modules/serialized-save.js +79 -0
  156. package/lib/public/modules/server-settings.js +75 -65
  157. package/lib/public/modules/session-grants.js +16 -19
  158. package/lib/public/modules/session-list-avatars.js +98 -0
  159. package/lib/public/modules/session-vendor-state.js +86 -0
  160. package/lib/public/modules/settings-access.js +35 -0
  161. package/lib/public/modules/settings-hub.js +125 -0
  162. package/lib/public/modules/settings-nav.js +182 -0
  163. package/lib/public/modules/shell-line.js +24 -0
  164. package/lib/public/modules/sidebar-mobile.js +151 -195
  165. package/lib/public/modules/sidebar-projects.js +88 -129
  166. package/lib/public/modules/sidebar-sessions.js +66 -34
  167. package/lib/public/modules/sidebar.js +2 -2
  168. package/lib/public/modules/skills.js +11 -26
  169. package/lib/public/modules/sticky-notes.js +19 -16
  170. package/lib/public/modules/stt.js +9 -23
  171. package/lib/public/modules/terminal.js +86 -90
  172. package/lib/public/modules/theme-choice.js +126 -0
  173. package/lib/public/modules/theme-colors.js +19 -0
  174. package/lib/public/modules/theme-prefs.js +121 -0
  175. package/lib/public/modules/theme.js +227 -605
  176. package/lib/public/modules/tool-palette.js +7 -17
  177. package/lib/public/modules/tools.js +8 -10
  178. package/lib/public/modules/user-settings.js +59 -115
  179. package/lib/public/modules/user-shell.js +9 -2
  180. package/lib/public/modules/utils.js +10 -12
  181. package/lib/public/modules/vendor-picker.js +4 -2
  182. package/lib/public/modules/vendor-registry.js +1 -2
  183. package/lib/public/style.css +3 -1
  184. package/lib/public/sw.js +9 -2
  185. package/lib/public/theme-core.js +411 -0
  186. package/lib/request-body.js +70 -0
  187. package/lib/sdk-bridge.js +227 -88
  188. package/lib/sdk-message-processor.js +44 -16
  189. package/lib/server-admin.js +198 -200
  190. package/lib/server-auth.js +16 -13
  191. package/lib/server-dm.js +4 -3
  192. package/lib/server-settings.js +177 -130
  193. package/lib/server.js +87 -36
  194. package/lib/session-background-tasks.js +79 -0
  195. package/lib/session-directory.js +138 -13
  196. package/lib/session-input-ipc.js +2 -0
  197. package/lib/session-input.js +39 -5
  198. package/lib/session-list-avatars.js +16 -0
  199. package/lib/session-reclaim.js +37 -25
  200. package/lib/session-vendor.js +37 -0
  201. package/lib/sessions.js +99 -34
  202. package/lib/settings-ipc.js +60 -0
  203. package/lib/settings-registry.js +86 -0
  204. package/lib/terminal-manager.js +17 -5
  205. package/lib/theme-files.js +132 -0
  206. package/lib/theme-seed.js +136 -0
  207. package/lib/themes/clagentic-dark.json +13 -6
  208. package/lib/themes/clagentic-light.json +12 -5
  209. package/lib/updater.js +6 -4
  210. package/lib/usage-store.js +97 -10
  211. package/lib/users-preferences.js +118 -19
  212. package/lib/users.js +19 -10
  213. package/lib/vendor-catalog.js +130 -0
  214. package/lib/ws-schema.js +4 -2
  215. package/lib/yoke/adapters/claude.js +81 -1
  216. package/lib/yoke/adapters/codex-user-shell.js +87 -23
  217. package/lib/yoke/adapters/codex.js +89 -5
  218. package/lib/yoke/codex-binary.js +59 -0
  219. package/package.json +1 -1
  220. package/scripts/check-test-count.js +5 -0
  221. package/scripts/install-local-test.js +50 -9
  222. package/scripts/write-build-sha.js +18 -2
  223. package/lib/public/css/channel-layout.css +0 -329
  224. package/lib/themes/ayu-light.json +0 -9
  225. package/lib/themes/catppuccin-latte.json +0 -9
  226. package/lib/themes/catppuccin-mocha.json +0 -9
  227. package/lib/themes/dracula.json +0 -9
  228. package/lib/themes/everforest-light.json +0 -9
  229. package/lib/themes/everforest.json +0 -9
  230. package/lib/themes/github-light.json +0 -9
  231. package/lib/themes/gruvbox-dark.json +0 -9
  232. package/lib/themes/gruvbox-light.json +0 -9
  233. package/lib/themes/monokai.json +0 -9
  234. package/lib/themes/nord-light.json +0 -9
  235. package/lib/themes/nord.json +0 -9
  236. package/lib/themes/one-dark.json +0 -9
  237. package/lib/themes/one-light.json +0 -9
  238. package/lib/themes/rose-pine-dawn.json +0 -9
  239. package/lib/themes/rose-pine.json +0 -9
  240. package/lib/themes/solarized-dark.json +0 -9
  241. package/lib/themes/solarized-light.json +0 -9
  242. package/lib/themes/tokyo-night-light.json +0 -9
  243. package/lib/themes/tokyo-night.json +0 -9
@@ -0,0 +1,46 @@
1
+ // mobile-action-sheet.js - the phone's short list of actions for one thing (the
2
+ // project actions behind the Chat sheet's "..." button).
3
+ //
4
+ // It opens through the shared overlay component as a "sheet": the scrim, the
5
+ // layer, the close control, and closing on Escape or a tap on the scrim are the
6
+ // component's. Only the rows are drawn here.
7
+
8
+ import { showOverlay } from './overlay.js';
9
+ import { iconHtml } from './icons.js';
10
+
11
+ /**
12
+ * @param {object} opts
13
+ * @param {{icon: string, label: string, handler: function(): void}[]} opts.actions
14
+ * in the order shown. Choosing one closes the sheet, then runs its handler.
15
+ * @param {string} [opts.cancelLabel="Cancel"] the last row, which only closes it.
16
+ * @param {Document} [opts.doc]
17
+ * @returns {{el: Element, close: function(object=): void, isOpen: function(): boolean}}
18
+ */
19
+ export function showActionSheet(opts) {
20
+ var doc = opts.doc || document;
21
+ var handle = null;
22
+ var rows = [];
23
+
24
+ opts.actions.forEach(function (action) {
25
+ var btn = doc.createElement("button");
26
+ btn.className = "mobile-action-sheet-item";
27
+ btn.innerHTML = iconHtml(action.icon);
28
+ var label = doc.createElement("span");
29
+ label.textContent = action.label;
30
+ btn.appendChild(label);
31
+ btn.addEventListener("click", function () {
32
+ handle.close();
33
+ action.handler();
34
+ });
35
+ rows.push(btn);
36
+ });
37
+
38
+ var cancel = doc.createElement("button");
39
+ cancel.className = "mobile-action-sheet-cancel";
40
+ cancel.textContent = opts.cancelLabel || "Cancel";
41
+ cancel.addEventListener("click", function () { handle.close(); });
42
+ rows.push(cancel);
43
+
44
+ handle = showOverlay({ kind: "sheet", doc: doc, dialogClass: "mobile-action-sheet", content: rows, closeLabel: "Close" });
45
+ return handle;
46
+ }
@@ -0,0 +1,104 @@
1
+ // mobile-nav-sheet.js - the one rule for every sheet a phone bottom-nav button opens.
2
+ //
3
+ // Projects, Chat, Team and More each show their list in the page's #mobile-sheet
4
+ // (and a sheet that one of them opens, such as Files from More, is the same node).
5
+ // It opens through the shared overlay component as a "sheet" that stops above the
6
+ // nav, so the nav stays in view and tappable:
7
+ // - the same nav button closes the sheet;
8
+ // - another nav button switches the sheet to its own list;
9
+ // - the close control, Escape and the scrim close it.
10
+ // The middle button's full-screen view is not a nav sheet and is not handled here.
11
+
12
+ import { showOverlay } from './overlay.js';
13
+
14
+ var SHEET_ID = "mobile-sheet";
15
+
16
+ // The sheet each nav button opens, by the button's data-tab.
17
+ var NAV_SHEETS = { projects: "projects", chat: "sessions", team: "team", more: "more" };
18
+
19
+ // Matches the slide-down animation of #mobile-sheet.closing in css/mobile-nav.css.
20
+ export var NAV_SHEET_EXIT_MS = 230;
21
+
22
+ var handle = null;
23
+ var openType = null;
24
+
25
+ /**
26
+ * Open the nav sheet, or keep it open and change what it shows. The caller fills
27
+ * the sheet's title and list.
28
+ *
29
+ * @param {string} type projects, sessions, team, more or files.
30
+ * @param {object} [opts]
31
+ * @param {function(Element)} [opts.onClose] the sheet closed, however.
32
+ * @param {Document} [opts.doc]
33
+ * @returns {?{el: Element, close: function(object=): void, isOpen: function(): boolean}}
34
+ */
35
+ export function showNavSheet(type, opts) {
36
+ var o = opts || {};
37
+ var doc = o.doc || document;
38
+ var el = doc.getElementById(SHEET_ID);
39
+ if (!el) return null;
40
+ openType = type;
41
+ handle = showOverlay({
42
+ kind: "sheet", el: el, doc: doc, navSheet: true, closeLabel: "Close",
43
+ exit: { className: "closing", ms: NAV_SHEET_EXIT_MS },
44
+ onRemove: function (node) {
45
+ openType = null;
46
+ if (o.onClose) o.onClose(node);
47
+ },
48
+ });
49
+ return handle;
50
+ }
51
+
52
+ /**
53
+ * Close the nav sheet.
54
+ * @param {object} [opts]
55
+ * @param {boolean} [opts.immediate] skip the slide-down.
56
+ */
57
+ export function closeNavSheet(opts) {
58
+ if (handle) handle.close(opts);
59
+ }
60
+
61
+ /** @returns {boolean} whether the nav sheet is open. */
62
+ export function isNavSheetOpen() {
63
+ return !!handle && handle.isOpen();
64
+ }
65
+
66
+ /** @returns {?string} what the open nav sheet shows, or null when it is closed. */
67
+ export function navSheetType() {
68
+ return isNavSheetOpen() ? openType : null;
69
+ }
70
+
71
+ /**
72
+ * What a tap on a nav button does now.
73
+ * @param {string} tab the button's data-tab.
74
+ * @returns {?{action: "open", type: string}|{action: "close"}} null for a button
75
+ * that opens no nav sheet.
76
+ */
77
+ export function navTabAction(tab) {
78
+ var type = NAV_SHEETS[tab];
79
+ if (!type) return null;
80
+ return navSheetType() === type ? { action: "close" } : { action: "open", type: type };
81
+ }
82
+
83
+ /**
84
+ * Wire the nav buttons: the button of the open sheet closes it, any other opens
85
+ * its own sheet in place of it.
86
+ *
87
+ * @param {Element[]} tabs the buttons, each with a data-tab.
88
+ * @param {object} hooks
89
+ * @param {function(string, string): void} hooks.open show the sheet for (type, tab).
90
+ * @param {function(): void} hooks.close close the sheet.
91
+ */
92
+ export function wireNavTabs(tabs, hooks) {
93
+ for (var i = 0; i < tabs.length; i++) {
94
+ (function (tab) {
95
+ tab.addEventListener("click", function () {
96
+ var name = tab.dataset.tab;
97
+ var act = navTabAction(name);
98
+ if (!act) return;
99
+ if (act.action === "close") hooks.close();
100
+ else hooks.open(act.type, name);
101
+ });
102
+ })(tabs[i]);
103
+ }
104
+ }
@@ -21,12 +21,49 @@
21
21
  * model release the code has never seen gets a sane display name and correct
22
22
  * latest/older tiering with zero code changes.
23
23
  *
24
- * When adding a new family (e.g. a brand-new Claude product line): update
25
- * BOTH this file and lib/model-families.js. The parity test will fail if
26
- * they disagree.
24
+ * A new family needs no code change: the families are derived from the
25
+ * vendor's own alias entries (see setClaudeModelFamilies). The literal below
26
+ * is the documented last-resort fallback, kept equal to the one in
27
+ * lib/model-families.js (the parity test checks it).
27
28
  */
28
29
 
29
- export var CLAUDE_MODEL_FAMILIES = ["opus", "sonnet", "haiku", "fable"];
30
+ var CLAUDE_MODEL_FAMILIES_FALLBACK = ["opus", "sonnet", "haiku", "fable"];
31
+ export var CLAUDE_MODEL_FAMILIES = CLAUDE_MODEL_FAMILIES_FALLBACK.slice();
32
+
33
+ /**
34
+ * The family names a vendor model list's alias entries spell, in list order
35
+ * (the values with no "claude-" prefix other than "default"); [] when none.
36
+ */
37
+ export function deriveClaudeFamilies(models) {
38
+ var out = [];
39
+ (Array.isArray(models) ? models : []).forEach(function(m) {
40
+ var value = (m && typeof m === "object") ? m.value : m;
41
+ if (typeof value !== "string") return;
42
+ var alias = value.toLowerCase();
43
+ if (!/^[a-z]+$/.test(alias) || alias === "default" || out.indexOf(alias) !== -1) return;
44
+ out.push(alias);
45
+ });
46
+ return out;
47
+ }
48
+
49
+ /**
50
+ * Use the families derived from a vendor model list; a list with no alias
51
+ * entry changes nothing, so the fallback stays in force. Mutates
52
+ * CLAUDE_MODEL_FAMILIES in place. Returns true when the families came from the list.
53
+ */
54
+ export function setClaudeModelFamilies(models) {
55
+ var derived = deriveClaudeFamilies(models);
56
+ if (derived.length === 0) return false;
57
+ CLAUDE_MODEL_FAMILIES.length = 0;
58
+ derived.forEach(function(f) { CLAUDE_MODEL_FAMILIES.push(f); });
59
+ return true;
60
+ }
61
+
62
+ /** Back to the fallback literal. */
63
+ export function resetClaudeModelFamilies() {
64
+ CLAUDE_MODEL_FAMILIES.length = 0;
65
+ CLAUDE_MODEL_FAMILIES_FALLBACK.forEach(function(f) { CLAUDE_MODEL_FAMILIES.push(f); });
66
+ }
30
67
 
31
68
  /**
32
69
  * True if the given model ID string belongs to the given family (substring
@@ -0,0 +1,39 @@
1
+ // note-order.js - a sticky note's place in the note layer.
2
+ //
3
+ // The server keeps a bring-to-front counter per note (lib/notes.js); css/sticky-notes.css
4
+ // adds it to --z-note. The layer has to stay inside --z-note + 0..99 so it sits under the
5
+ // nav, but the counter only grows. While every counter fits the band it is used as is;
6
+ // once one passes it, the open notes are dense-ranked from the top, so the order between
7
+ // them survives and the most recently raised note is strictly on top.
8
+
9
+ export var NOTE_ORDER_MAX = 99;
10
+
11
+ /**
12
+ * @param {*} zIndex the note's counter as the server sent it.
13
+ * @returns {number} a whole number from 0 to NOTE_ORDER_MAX.
14
+ */
15
+ export function noteLayerOrder(zIndex) {
16
+ var n = Math.floor(Number(zIndex));
17
+ if (!isFinite(n)) return 0;
18
+ return Math.max(0, Math.min(NOTE_ORDER_MAX, n));
19
+ }
20
+
21
+ /**
22
+ * @param {Array} zIndexes the counters of every open note, as the server sent them.
23
+ * @returns {number[]} one whole number from 0 to NOTE_ORDER_MAX per input, in input
24
+ * order, keeping the relative order of the counters.
25
+ */
26
+ export function noteLayerOrders(zIndexes) {
27
+ var raw = zIndexes.map(function (z) {
28
+ var n = Math.floor(Number(z));
29
+ return isFinite(n) ? Math.max(0, n) : 0;
30
+ });
31
+ var top = raw.reduce(function (a, b) { return Math.max(a, b); }, 0);
32
+ if (top <= NOTE_ORDER_MAX) return raw;
33
+ var distinct = raw.filter(function (n, i) { return raw.indexOf(n) === i; })
34
+ .sort(function (a, b) { return a - b; });
35
+ return raw.map(function (n) {
36
+ var fromTop = distinct.length - 1 - distinct.indexOf(n);
37
+ return Math.max(0, NOTE_ORDER_MAX - fromTop);
38
+ });
39
+ }
@@ -2,6 +2,23 @@ import { copyToClipboard, showToast } from './utils.js';
2
2
  import { iconHtml, refreshIcons } from './icons.js';
3
3
  import { store } from './store.js';
4
4
  import { routeTo } from './notify-client.js';
5
+ import { showReloadBanner } from './build-guard.js';
6
+ import { showOverlay } from './overlay.js';
7
+ import { closeMenu, isMenuOpen } from './overlay-registry.js';
8
+
9
+ // Opens a popover that index.html already carries, hung from its pill, or closes
10
+ // it when it is open. The pill's own click calls this; outside click and Escape
11
+ // are the registry's.
12
+ function togglePillPopover(el, pill, place) {
13
+ if (isMenuOpen(el)) {
14
+ closeMenu(el);
15
+ return;
16
+ }
17
+ showOverlay({
18
+ kind: "popover", el: el, retain: true, anchor: pill, opener: pill,
19
+ placement: place.placement, gap: place.gap,
20
+ });
21
+ }
5
22
 
6
23
  var ctx;
7
24
  var basePath = "/";
@@ -152,15 +169,9 @@ export function initNotifications(_ctx) {
152
169
  if (pillBtn) {
153
170
  pillBtn.addEventListener("click", function (e) {
154
171
  e.stopPropagation();
155
- popover.classList.toggle("visible");
172
+ togglePillPopover(popover, pillBtn, { placement: "below-right-aligned", gap: 6 });
156
173
  });
157
174
  }
158
-
159
- document.addEventListener("click", function (e) {
160
- if (!popover.contains(e.target) && e.target !== pillBtn && !pillBtn.contains(e.target)) {
161
- popover.classList.remove("visible");
162
- }
163
- });
164
175
  })();
165
176
 
166
177
  // --- Extension pill popover ---
@@ -205,16 +216,10 @@ export function initNotifications(_ctx) {
205
216
  // Toggle popover
206
217
  extPillBtn.addEventListener("click", function (e) {
207
218
  e.stopPropagation();
208
- extPopover.classList.toggle("visible");
219
+ togglePillPopover(extPopover, extPillBtn, { placement: "below", gap: 8 });
209
220
  refreshIcons(extPopover);
210
221
  });
211
222
 
212
- document.addEventListener("click", function (e) {
213
- if (!extPopover.contains(e.target) && e.target !== extPillBtn && !extPillBtn.contains(e.target)) {
214
- extPopover.classList.remove("visible");
215
- }
216
- });
217
-
218
223
  // Download button
219
224
  if (extDownloadBtn) {
220
225
  extDownloadBtn.addEventListener("click", function (e) {
@@ -249,7 +254,7 @@ export function initNotifications(_ctx) {
249
254
  }).catch(function (err) {
250
255
  if (extDownloadStatus) {
251
256
  extDownloadStatus.textContent = "Failed: " + err.message;
252
- extDownloadStatus.style.color = "var(--danger, #e53935)";
257
+ extDownloadStatus.style.color = "var(--danger)";
253
258
  }
254
259
  showToast("Download failed");
255
260
  }).finally(function () {
@@ -348,15 +353,16 @@ export function initNotifications(_ctx) {
348
353
 
349
354
  notifBtn.addEventListener("click", function (e) {
350
355
  e.stopPropagation();
351
- var open = notifMenu.classList.toggle("hidden");
352
- notifBtn.classList.toggle("active", !open);
353
- });
354
-
355
- document.addEventListener("click", function (e) {
356
- if (!notifMenu.contains(e.target) && e.target !== notifBtn) {
357
- notifMenu.classList.add("hidden");
358
- notifBtn.classList.remove("active");
356
+ if (isMenuOpen(notifMenu)) {
357
+ closeMenu(notifMenu);
358
+ return;
359
359
  }
360
+ notifBtn.classList.add("active");
361
+ showOverlay({
362
+ kind: "menu", el: notifMenu, retain: true, anchor: notifBtn, opener: notifBtn,
363
+ placement: "below-right-aligned", gap: 6,
364
+ onRemove: function () { notifBtn.classList.remove("active"); },
365
+ });
360
366
  });
361
367
 
362
368
  var notifBlockedHint = $("notif-blocked-hint");
@@ -390,6 +396,7 @@ export function initNotifications(_ctx) {
390
396
  // --- Notification help modal ---
391
397
  var notifHelpModal = $("notif-help-modal");
392
398
  var notifHelpClose = $("notif-help-close");
399
+ var notifHelpHandle = null;
393
400
  var notifLearnMore = $("notif-learn-more");
394
401
  var notifUrlCopy = $("notif-url-copy");
395
402
  var notifSettingsUrl = $("notif-settings-url");
@@ -407,16 +414,11 @@ export function initNotifications(_ctx) {
407
414
 
408
415
  notifLearnMore.addEventListener("click", function (e) {
409
416
  e.preventDefault();
410
- notifHelpModal.classList.remove("hidden");
411
- refreshIcons();
417
+ notifHelpHandle = showOverlay({ kind: "modal", el: notifHelpModal });
412
418
  });
413
419
 
414
420
  notifHelpClose.addEventListener("click", function () {
415
- notifHelpModal.classList.add("hidden");
416
- });
417
-
418
- notifHelpModal.querySelector(".confirm-backdrop").addEventListener("click", function () {
419
- notifHelpModal.classList.add("hidden");
421
+ if (notifHelpHandle) notifHelpHandle.close();
420
422
  });
421
423
 
422
424
  notifUrlCopy.addEventListener("click", function () {
@@ -648,28 +650,9 @@ export function initNotifications(_ctx) {
648
650
  return;
649
651
  }
650
652
 
651
- // Page is visible: show a persistent banner so the user can reload when ready
652
- var existing = document.getElementById("sw-update-banner");
653
- if (existing) return; // already showing
654
-
655
- var banner = document.createElement("div");
656
- banner.id = "sw-update-banner";
657
- banner.className = "sw-update-banner";
658
- banner.innerHTML =
659
- '<span class="sw-update-banner-text">New version available</span>' +
660
- '<button class="sw-update-banner-btn" id="sw-update-reload">Reload</button>' +
661
- '<button class="sw-update-banner-dismiss" id="sw-update-dismiss" aria-label="Dismiss">&#x2715;</button>';
662
- document.body.appendChild(banner);
663
-
664
- requestAnimationFrame(function () { banner.classList.add("visible"); });
665
-
666
- document.getElementById("sw-update-reload").addEventListener("click", function () {
667
- window.location.reload();
668
- });
669
- document.getElementById("sw-update-dismiss").addEventListener("click", function () {
670
- banner.classList.remove("visible");
671
- setTimeout(function () { banner.remove(); }, 300);
672
- });
653
+ // Page is visible: show a persistent banner so the user can reload when
654
+ // ready. Drawn once: the build guard's banner shares its id.
655
+ showReloadBanner(document, function () { window.location.reload(); }, { text: "New version available", dismissible: true });
673
656
  });
674
657
  })();
675
658
 
@@ -7,12 +7,20 @@
7
7
  // Pattern:
8
8
  // - Each overlay calls pushOverlayState() on open.
9
9
  // - Each overlay's close function calls popOverlayState().
10
+ // - A panel opened through the shared overlay (overlay-modal.js, the panel
11
+ // option) does both itself, naming itself as the owner of its entry; its
12
+ // close runs on Escape, the close control and a back swipe alike.
10
13
  // - The central popstate handler in app.js:
11
- // 1. Calls consumeOverlayPopstate() — returns true if an overlay entry
12
- // was active (and suppresses the redundant history.back() in the
13
- // subsequent popOverlayState() call).
14
- // 2. If true, calls the appropriate close function and returns.
15
- // 3. Otherwise falls through to normal project-switch logic.
14
+ // 1. Calls consumeOwnPopstate() — true when the event is the echo of a
15
+ // history.back() this module issued; nothing closes.
16
+ // 2. Otherwise asks the registry to close an open menu or dialog first
17
+ // (overlay-registry.js closeTopBlockingOverlay): those hold no entry,
18
+ // so restoreOverlayState() puts the entry the browser just popped back.
19
+ // 3. Else calls consumeOverlayPopstate() (suppresses the redundant
20
+ // history.back() in the subsequent popOverlayState() call) and closes the
21
+ // overlay that owns the top entry: the panel, or one of the overlays
22
+ // that still keep their own anonymous entry.
23
+ // 4. Otherwise falls through to normal project-switch logic.
16
24
  //
17
25
  // The key invariant: history.back() must be called exactly once per sentinel.
18
26
  // When the user closes via UI (X / Escape), popOverlayState() calls
@@ -20,33 +28,71 @@
20
28
  // pop (back swipe), consumeOverlayPopstate() sets a suppress flag so the
21
29
  // close function's popOverlayState() call is a no-op.
22
30
 
23
- var _depth = 0;
31
+ // The open entries, oldest first: the owner of each (a panel's node), or null for
32
+ // an overlay that keeps its own entry without naming itself.
33
+ var _entries = [];
24
34
  var _suppressBack = false;
35
+ // history.back() calls this module made itself whose popstate has not arrived.
36
+ // With overlays nested (the phone Settings list under a settings panel),
37
+ // closing the top one leaves another sentinel active, so its own popstate
38
+ // would otherwise read as a back swipe and close the one underneath.
39
+ var _ownPops = 0;
40
+
41
+ function indexOfOwner(owner) {
42
+ var want = owner || null;
43
+ for (var i = _entries.length - 1; i >= 0; i--) if (_entries[i] === want) return i;
44
+ return -1;
45
+ }
25
46
 
26
47
  // Call when an overlay opens. Pushes a sentinel history entry.
27
- export function pushOverlayState() {
28
- _depth++;
29
- history.pushState({ overlay: true, depth: _depth }, "");
48
+ export function pushOverlayState(owner) {
49
+ _entries.push(owner || null);
50
+ history.pushState({ overlay: true, depth: _entries.length }, "");
30
51
  }
31
52
 
32
53
  // Call when an overlay closes. If the close is user-initiated (not from a
33
54
  // popstate callback), calls history.back() to remove the sentinel we pushed.
34
55
  // If _suppressBack is set (we're inside the popstate handler), skip the
35
56
  // history.back() — it already happened.
36
- export function popOverlayState() {
37
- if (_depth > 0) {
38
- _depth--;
39
- if (_suppressBack) {
40
- _suppressBack = false;
41
- } else {
42
- history.back();
43
- }
57
+ export function popOverlayState(owner) {
58
+ var at = indexOfOwner(owner);
59
+ if (at === -1) return;
60
+ _entries.splice(at, 1);
61
+ if (_suppressBack) {
62
+ _suppressBack = false;
63
+ } else {
64
+ _ownPops++;
65
+ history.back();
44
66
  }
45
67
  }
46
68
 
69
+ // Release an entry without history.back(): the page navigates next and pushes its
70
+ // own entry, so a queued back would land on the old sentinel and leave the URL on
71
+ // the page it came from. The spent sentinel stays under the navigation's entry.
72
+ export function releaseOverlayState(owner) {
73
+ var at = indexOfOwner(owner);
74
+ if (at !== -1) _entries.splice(at, 1);
75
+ }
76
+
77
+ // Called first by the popstate handler. True when this popstate is the echo of
78
+ // a history.back() popOverlayState() issued, which closes nothing further.
79
+ export function consumeOwnPopstate() {
80
+ if (_ownPops > 0) {
81
+ _ownPops--;
82
+ return true;
83
+ }
84
+ return false;
85
+ }
86
+
47
87
  // Returns true if at least one overlay history entry is active.
48
88
  export function hasOverlayState() {
49
- return _depth > 0;
89
+ return _entries.length > 0;
90
+ }
91
+
92
+ // The owner of the newest entry: the panel node, or null when it is an overlay
93
+ // that keeps its own entry. Only meaningful while hasOverlayState() is true.
94
+ export function topOverlayOwner() {
95
+ return _entries.length ? _entries[_entries.length - 1] : null;
50
96
  }
51
97
 
52
98
  // Called by the popstate handler before invoking the overlay close function.
@@ -54,9 +100,17 @@ export function hasOverlayState() {
54
100
  // popOverlayState() call (since the browser already did the pop).
55
101
  // Returns true if an overlay entry was consumed, false if none was active.
56
102
  export function consumeOverlayPopstate() {
57
- if (_depth > 0) {
103
+ if (_entries.length > 0) {
58
104
  _suppressBack = true;
59
105
  return true;
60
106
  }
61
107
  return false;
62
108
  }
109
+
110
+ // The back closed something that holds no entry (a dialog or a menu opened over an
111
+ // overlay), so the entry the browser popped is put back: the overlay under it
112
+ // stays open with its entry, and one back closed one thing.
113
+ export function restoreOverlayState() {
114
+ _suppressBack = false;
115
+ if (_entries.length) history.pushState({ overlay: true, depth: _entries.length }, "");
116
+ }
@@ -0,0 +1,123 @@
1
+ // overlay-menu.js - the anchored kinds of the shared overlay component: a menu
2
+ // or popover placed at an element or a point.
3
+ //
4
+ // Called through showOverlay (overlay.js) with kind "menu" or "popover". The
5
+ // card chrome, the layer (--z-menu) and the optional close control are drawn by
6
+ // css/overlay.css; placement is modules/popover-position.js; one-open, outside
7
+ // click and Escape are the registry (overlay-registry.js).
8
+
9
+ import { iconHtml, refreshIcons } from './icons.js';
10
+ import { positionPopover, positionAtPoint } from './popover-position.js';
11
+ import { openMenu, closeMenu, isMenuOpen } from './overlay-registry.js';
12
+
13
+ var KIND_CLASS = { menu: "", popover: "overlay-popover" };
14
+
15
+ function nextFrame(fn) {
16
+ if (typeof requestAnimationFrame === "function") requestAnimationFrame(fn);
17
+ else fn();
18
+ }
19
+
20
+ function addClasses(el, names) {
21
+ String(names || "").split(/\s+/).filter(Boolean).forEach(function (n) { el.classList.add(n); });
22
+ }
23
+
24
+ /**
25
+ * Open a menu or popover.
26
+ *
27
+ * @param {object} opts
28
+ * @param {"menu"|"popover"} opts.kind
29
+ * @param {Element|{x:number,y:number}} [opts.anchor] an element to hang from, or a
30
+ * viewport point (a contextmenu event's clientX/clientY). Absent: left where
31
+ * the surface's own styling puts it.
32
+ * @param {"right"|"below"|"below-center"|"above"|"below-right-aligned"} [opts.placement] see
33
+ * popover-position.js; element anchors only.
34
+ * @param {boolean} [opts.inline] the card keeps its place in its container's flow
35
+ * (a panel stacked with others in one column) instead of floating at an anchor;
36
+ * it still takes the card chrome, the registry and the close control.
37
+ * @param {Element} [opts.parent] the open menu this one belongs to (a dropdown
38
+ * inside a popover): opening it leaves the parent open; see overlay-registry.js.
39
+ * @param {function(Event): boolean} [opts.onEscape] Escape is offered here first
40
+ * while this is the innermost menu; true means it was spent inside the card.
41
+ * @param {number} [opts.gap] gap between anchor and menu; element anchors only.
42
+ * @param {number} [opts.margin] least gap to the viewport edge.
43
+ * @param {boolean} [opts.mobile] force the phone (centred) or anchored placement;
44
+ * absent, the viewport width decides. A notice that belongs under its anchor
45
+ * passes false; element anchors only.
46
+ * @param {Element} [opts.opener] the control that toggles it; a click on it is
47
+ * not an outside click, so the surface's own handler can close it.
48
+ * @param {Element} [opts.el] a node the surface built or already has: it is the
49
+ * card instead of a new element, and stays where it is when it already has a
50
+ * parent (otherwise it is appended to the body).
51
+ * @param {boolean} [opts.passive] a transient notice (the rate-limit notice): it
52
+ * does not close the menu the user has open; see overlay-registry.js.
53
+ * @param {boolean} [opts.retain] closing hides the node (the "hidden" class)
54
+ * instead of removing it: for a node that lives in the page (index.html), which
55
+ * the surface opens again later.
56
+ * @param {string|Node|Node[]} [opts.content] markup the caller has already
57
+ * escaped, or nodes. Absent on an adopted node keeps what it holds.
58
+ * @param {boolean} [opts.closeButton] draw the shared .overlay-close, top-right.
59
+ * @param {string} [opts.closeLabel] the close control's accessible name.
60
+ * @param {string} [opts.id]
61
+ * @param {string} [opts.className] extra classes for the surface's content styling.
62
+ * @param {Object<string,string>} [opts.attrs]
63
+ * @param {function(Element)} [opts.onDismiss] the close control was used.
64
+ * @param {function(Element)} [opts.onRemove] it closed, however.
65
+ * @param {Document} [opts.doc]
66
+ * @returns {{el: Element, close: function(): void, reposition: function(): void, isOpen: function(): boolean}}
67
+ */
68
+ export function showMenu(opts) {
69
+ var doc = opts.doc || document;
70
+ var el = opts.el || doc.createElement("div");
71
+ var anchor = opts.anchor || null;
72
+ var isPoint = !!anchor && typeof anchor.x === "number" && typeof anchor.y === "number";
73
+
74
+ addClasses(el, "overlay-menu " + KIND_CLASS[opts.kind] + " " + (opts.inline ? "overlay-menu-inline " : "") + (opts.className || ""));
75
+ if (opts.id) el.id = opts.id;
76
+ el.setAttribute("data-overlay-kind", opts.kind);
77
+ Object.keys(opts.attrs || {}).forEach(function (name) { el.setAttribute(name, opts.attrs[name]); });
78
+
79
+ var content = opts.content;
80
+ if (typeof content === "string") el.innerHTML = content;
81
+ else if (content) [].concat(content).forEach(function (node) { el.appendChild(node); });
82
+
83
+ function close() { closeMenu(el); }
84
+
85
+ if (opts.closeButton && !el.querySelector(".overlay-close")) {
86
+ var x = doc.createElement("button");
87
+ x.className = "overlay-close";
88
+ x.setAttribute("type", "button");
89
+ x.setAttribute("aria-label", opts.closeLabel || "Close");
90
+ x.innerHTML = iconHtml("x");
91
+ x.addEventListener("click", function (e) {
92
+ if (e && e.stopPropagation) e.stopPropagation();
93
+ close();
94
+ if (opts.onDismiss) opts.onDismiss(el);
95
+ });
96
+ el.appendChild(x);
97
+ }
98
+
99
+ // Registered before it is drawn so the menu it replaces is already gone.
100
+ openMenu(el, { opener: opts.opener, parent: opts.parent, passive: !!opts.passive, retain: !!opts.retain, onClose: opts.onRemove, onEscape: opts.onEscape, doc: doc });
101
+
102
+ if (opts.retain) el.classList.remove("hidden");
103
+ if (!el.parentNode) doc.body.appendChild(el);
104
+
105
+ function reposition() {
106
+ if (!anchor) return;
107
+ if (isPoint) {
108
+ positionAtPoint(el, anchor, { margin: opts.margin });
109
+ return;
110
+ }
111
+ var place = { placement: opts.placement };
112
+ if (typeof opts.gap === "number") place.gap = opts.gap;
113
+ if (typeof opts.margin === "number") place.margin = opts.margin;
114
+ if (typeof opts.mobile === "boolean") place.mobile = opts.mobile;
115
+ positionPopover(el, anchor, place);
116
+ }
117
+ reposition();
118
+ // Icons the surface draws change the card's size once they render.
119
+ refreshIcons();
120
+ nextFrame(function () { if (isMenuOpen(el)) reposition(); });
121
+
122
+ return { el: el, close: close, reposition: reposition, isOpen: function () { return isMenuOpen(el); } };
123
+ }