@clagentic/console 1.12.0-beta.3 → 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.
- package/README.md +7 -1
- package/bin/cli.js +18 -15
- package/lib/agent-roster-ws.js +38 -13
- package/lib/agent-roster.js +111 -12
- package/lib/agents.js +68 -33
- package/lib/atomic-install.js +334 -0
- package/lib/build-changes.js +33 -4
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +12 -0
- package/lib/chat-width.js +31 -0
- package/lib/cli/agent-usage.js +126 -0
- package/lib/cli/arg-validation.js +1 -1
- package/lib/cli/compact-output.js +69 -0
- package/lib/cli/ipc-subcommands.js +92 -67
- package/lib/cli/output.js +28 -0
- package/lib/cli/restart-verb.js +132 -0
- package/lib/cli/schedule-input-subcommands.js +45 -8
- package/lib/cli/session-subcommands.js +37 -11
- package/lib/cli/settings-subcommands.js +74 -0
- package/lib/cli-transcript-title.js +56 -3
- package/lib/client-files.js +79 -0
- package/lib/daemon.js +100 -28
- package/lib/default-avatar-color.js +4 -0
- package/lib/drain.js +58 -10
- package/lib/mcp-tool-input.js +2 -2
- package/lib/model-families.js +49 -1
- package/lib/notify/type-registry.js +4 -0
- package/lib/notify/types.js +7 -4
- package/lib/pages.js +13 -63
- package/lib/permission-summary.js +12 -16
- package/lib/plan-usage-reader.js +70 -0
- package/lib/project-connection.js +4 -2
- package/lib/project-filesystem.js +6 -7
- package/lib/project-notifications.js +55 -8
- package/lib/project-prompt-expiry-settings.js +42 -0
- package/lib/project-sessions.js +52 -0
- package/lib/project-settings-gate.js +98 -0
- package/lib/project-user-mention.js +3 -2
- package/lib/project.js +1 -1
- package/lib/prompt-expiry-settings.js +49 -0
- package/lib/prompt-expiry.js +24 -3
- package/lib/prompt-kinds/codecs.js +6 -2
- package/lib/public/app.js +36 -36
- package/lib/public/css/admin.css +156 -170
- package/lib/public/css/agent-messages.css +24 -24
- package/lib/public/css/agent-picker.css +90 -38
- package/lib/public/css/agent-roster.css +61 -27
- package/lib/public/css/at-agents.css +10 -10
- package/lib/public/css/base.css +207 -184
- package/lib/public/css/chat-layout.css +228 -0
- package/lib/public/css/command-palette.css +86 -88
- package/lib/public/css/diagnostics.css +78 -204
- package/lib/public/css/diff.css +10 -10
- package/lib/public/css/filebrowser.css +32 -60
- package/lib/public/css/home-hub.css +100 -100
- package/lib/public/css/icon-strip.css +195 -238
- package/lib/public/css/input.css +191 -212
- package/lib/public/css/login-panel.css +16 -16
- package/lib/public/css/loop.css +96 -187
- package/lib/public/css/mention.css +49 -110
- package/lib/public/css/menus.css +162 -169
- package/lib/public/css/messages.css +49 -123
- package/lib/public/css/mobile-nav.css +207 -264
- package/lib/public/css/notifications-center.css +45 -124
- package/lib/public/css/overlay.css +269 -0
- package/lib/public/css/overlays.css +134 -156
- package/lib/public/css/playbook.css +41 -41
- package/lib/public/css/profile.css +43 -112
- package/lib/public/css/rewind.css +112 -112
- package/lib/public/css/scheduler-modal.css +27 -135
- package/lib/public/css/scheduler.css +204 -210
- package/lib/public/css/server-settings.css +173 -239
- package/lib/public/css/session-search.css +20 -20
- package/lib/public/css/settings-nav.css +197 -0
- package/lib/public/css/sidebar.css +213 -304
- package/lib/public/css/skills.css +121 -135
- package/lib/public/css/sticky-notes.css +114 -200
- package/lib/public/css/stt.css +17 -26
- package/lib/public/css/team-panel.css +36 -36
- package/lib/public/css/team-view.css +9 -9
- package/lib/public/css/title-bar.css +83 -100
- package/lib/public/css/tooltip.css +10 -10
- package/lib/public/css/user-settings.css +78 -131
- package/lib/public/css/user-shell.css +125 -29
- package/lib/public/index.html +178 -177
- package/lib/public/manifest.json +0 -2
- package/lib/public/modules/admin.js +54 -92
- package/lib/public/modules/agent-avatar.js +134 -3
- package/lib/public/modules/agent-messages.js +2 -1
- package/lib/public/modules/agent-picker.js +23 -21
- package/lib/public/modules/agent-roster-groups.js +128 -0
- package/lib/public/modules/agent-roster.js +40 -11
- package/lib/public/modules/app-connection.js +13 -1
- package/lib/public/modules/app-cursors.js +9 -9
- package/lib/public/modules/app-favicon.js +8 -16
- package/lib/public/modules/app-header.js +28 -19
- package/lib/public/modules/app-history-replay.js +67 -4
- package/lib/public/modules/app-home-hub.js +15 -0
- package/lib/public/modules/app-loop-ui.js +41 -47
- package/lib/public/modules/app-loop-wizard.js +9 -10
- package/lib/public/modules/app-messages.js +32 -36
- package/lib/public/modules/app-misc.js +22 -92
- package/lib/public/modules/app-modals.js +98 -0
- package/lib/public/modules/app-notifications.js +124 -135
- package/lib/public/modules/app-panels.js +28 -32
- package/lib/public/modules/app-projects.js +30 -40
- package/lib/public/modules/app-rate-limit.js +26 -9
- package/lib/public/modules/app-rendering.js +128 -110
- package/lib/public/modules/app-skills-install.js +6 -4
- package/lib/public/modules/assistant-identity.js +55 -0
- package/lib/public/modules/at-agents.js +3 -0
- package/lib/public/modules/build-guard.js +25 -11
- package/lib/public/modules/chat-width-choice.js +75 -0
- package/lib/public/modules/chat-width-prefs.js +52 -0
- package/lib/public/modules/chat-width.js +102 -0
- package/lib/public/modules/collapsible-text.js +36 -4
- package/lib/public/modules/command-palette.js +28 -34
- package/lib/public/modules/context-sources.js +3 -5
- package/lib/public/modules/diagnostics.js +130 -129
- package/lib/public/modules/info-panel.js +31 -0
- package/lib/public/modules/injected-identity.js +8 -8
- package/lib/public/modules/input-list-menu.js +39 -0
- package/lib/public/modules/input.js +22 -21
- package/lib/public/modules/markdown.js +10 -11
- package/lib/public/modules/mcp-ui.js +4 -14
- package/lib/public/modules/mention.js +100 -229
- package/lib/public/modules/message-header.js +80 -0
- package/lib/public/modules/message-participants.js +39 -0
- package/lib/public/modules/mobile-action-sheet.js +46 -0
- package/lib/public/modules/mobile-nav-sheet.js +104 -0
- package/lib/public/modules/model-families.js +41 -4
- package/lib/public/modules/note-order.js +39 -0
- package/lib/public/modules/notifications.js +35 -52
- package/lib/public/modules/overlay-history.js +73 -19
- package/lib/public/modules/overlay-menu.js +123 -0
- package/lib/public/modules/overlay-modal.js +186 -0
- package/lib/public/modules/overlay-registry.js +392 -0
- package/lib/public/modules/overlay-stack.js +110 -0
- package/lib/public/modules/overlay.js +117 -0
- package/lib/public/modules/popover-position.js +18 -2
- package/lib/public/modules/preference-sync.js +28 -0
- package/lib/public/modules/profile.js +24 -49
- package/lib/public/modules/project-settings.js +27 -172
- package/lib/public/modules/prompt-expiry-controls.js +46 -0
- package/lib/public/modules/prompt-kinds/command-summary.js +149 -0
- package/lib/public/modules/prompt-kinds/permission.js +70 -92
- package/lib/public/modules/prompts.js +1 -2
- package/lib/public/modules/qrcode.js +6 -21
- package/lib/public/modules/queued-button.js +15 -2
- package/lib/public/modules/rewind.js +9 -3
- package/lib/public/modules/schedule-time.js +32 -7
- package/lib/public/modules/scheduled-outbox.js +51 -18
- package/lib/public/modules/scheduler-config.js +87 -127
- package/lib/public/modules/scheduler.js +29 -26
- package/lib/public/modules/serialized-save.js +79 -0
- package/lib/public/modules/server-settings.js +75 -65
- package/lib/public/modules/session-grants.js +16 -19
- package/lib/public/modules/session-list-avatars.js +98 -0
- package/lib/public/modules/session-vendor-state.js +86 -0
- package/lib/public/modules/settings-access.js +35 -0
- package/lib/public/modules/settings-hub.js +125 -0
- package/lib/public/modules/settings-nav.js +182 -0
- package/lib/public/modules/shell-line.js +24 -0
- package/lib/public/modules/sidebar-mobile.js +151 -195
- package/lib/public/modules/sidebar-projects.js +88 -129
- package/lib/public/modules/sidebar-sessions.js +66 -34
- package/lib/public/modules/sidebar.js +2 -2
- package/lib/public/modules/skills.js +11 -26
- package/lib/public/modules/sticky-notes.js +19 -16
- package/lib/public/modules/stt.js +9 -23
- package/lib/public/modules/terminal.js +86 -90
- package/lib/public/modules/theme-choice.js +126 -0
- package/lib/public/modules/theme-colors.js +19 -0
- package/lib/public/modules/theme-prefs.js +121 -0
- package/lib/public/modules/theme.js +227 -605
- package/lib/public/modules/tool-palette.js +7 -17
- package/lib/public/modules/tools.js +8 -10
- package/lib/public/modules/user-settings.js +59 -115
- package/lib/public/modules/user-shell.js +9 -2
- package/lib/public/modules/utils.js +10 -12
- package/lib/public/modules/vendor-picker.js +4 -2
- package/lib/public/modules/vendor-registry.js +1 -2
- package/lib/public/style.css +3 -1
- package/lib/public/sw.js +9 -2
- package/lib/public/theme-core.js +411 -0
- package/lib/request-body.js +70 -0
- package/lib/sdk-bridge.js +227 -88
- package/lib/sdk-message-processor.js +44 -16
- package/lib/server-admin.js +198 -200
- package/lib/server-auth.js +16 -13
- package/lib/server-dm.js +4 -3
- package/lib/server-settings.js +177 -130
- package/lib/server.js +87 -36
- package/lib/session-background-tasks.js +79 -0
- package/lib/session-directory.js +138 -13
- package/lib/session-input-ipc.js +2 -0
- package/lib/session-input.js +39 -5
- package/lib/session-list-avatars.js +16 -0
- package/lib/session-reclaim.js +37 -25
- package/lib/session-vendor.js +37 -0
- package/lib/sessions.js +99 -34
- package/lib/settings-ipc.js +60 -0
- package/lib/settings-registry.js +86 -0
- package/lib/terminal-manager.js +17 -5
- package/lib/theme-files.js +132 -0
- package/lib/theme-seed.js +136 -0
- package/lib/themes/clagentic-dark.json +13 -6
- package/lib/themes/clagentic-light.json +12 -5
- package/lib/updater.js +6 -4
- package/lib/usage-store.js +97 -10
- package/lib/users-preferences.js +118 -19
- package/lib/users.js +19 -10
- package/lib/vendor-catalog.js +130 -0
- package/lib/ws-schema.js +4 -2
- package/lib/yoke/adapters/claude.js +81 -1
- package/lib/yoke/adapters/codex-user-shell.js +87 -23
- package/lib/yoke/adapters/codex.js +89 -5
- package/lib/yoke/codex-binary.js +59 -0
- package/package.json +1 -1
- package/scripts/check-test-count.js +5 -0
- package/scripts/install-local-test.js +50 -9
- package/scripts/write-build-sha.js +18 -2
- package/lib/public/css/channel-layout.css +0 -329
- package/lib/themes/ayu-light.json +0 -9
- package/lib/themes/catppuccin-latte.json +0 -9
- package/lib/themes/catppuccin-mocha.json +0 -9
- package/lib/themes/dracula.json +0 -9
- package/lib/themes/everforest-light.json +0 -9
- package/lib/themes/everforest.json +0 -9
- package/lib/themes/github-light.json +0 -9
- package/lib/themes/gruvbox-dark.json +0 -9
- package/lib/themes/gruvbox-light.json +0 -9
- package/lib/themes/monokai.json +0 -9
- package/lib/themes/nord-light.json +0 -9
- package/lib/themes/nord.json +0 -9
- package/lib/themes/one-dark.json +0 -9
- package/lib/themes/one-light.json +0 -9
- package/lib/themes/rose-pine-dawn.json +0 -9
- package/lib/themes/rose-pine.json +0 -9
- package/lib/themes/solarized-dark.json +0 -9
- package/lib/themes/solarized-light.json +0 -9
- package/lib/themes/tokyo-night-light.json +0 -9
- package/lib/themes/tokyo-night.json +0 -9
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// overlay.js - the one component behind every toast, banner, menu, popover,
|
|
2
|
+
// modal and sheet.
|
|
3
|
+
//
|
|
4
|
+
// A surface describes what it shows with options; the component draws the card
|
|
5
|
+
// (css/overlay.css), the close control, the severity edge, the auto-dismiss and
|
|
6
|
+
// the keyboard dismissal, and hands the card to the stacking manager
|
|
7
|
+
// (overlay-stack.js). A menu or popover (kind "menu" or "popover", see
|
|
8
|
+
// overlay-menu.js) is anchored to an element or a point instead and tracked by
|
|
9
|
+
// the open-menu registry (overlay-registry.js). A modal or sheet (kind "modal"
|
|
10
|
+
// or "sheet", see overlay-modal.js) is a dialog on a scrim, closed by Escape, the
|
|
11
|
+
// scrim or the close control, and tracked by the same registry; its panel option
|
|
12
|
+
// makes it a full-page panel on the layer under the dialogs, held in the browser
|
|
13
|
+
// history so a back swipe closes it. A variant is an option, not another component.
|
|
14
|
+
|
|
15
|
+
import { iconHtml, refreshIcons } from './icons.js';
|
|
16
|
+
import { addToStack, removeFromStack } from './overlay-stack.js';
|
|
17
|
+
import { showMenu } from './overlay-menu.js';
|
|
18
|
+
import { showModal } from './overlay-modal.js';
|
|
19
|
+
|
|
20
|
+
var KIND_CLASS = { toast: "overlay-toast", banner: "overlay-banner" };
|
|
21
|
+
// "warning" is the diagnostics wording for the same level as "warn".
|
|
22
|
+
var SEVERITY = { info: "info", success: "success", warn: "warn", warning: "warn", error: "error" };
|
|
23
|
+
|
|
24
|
+
function nextFrame(fn) {
|
|
25
|
+
if (typeof requestAnimationFrame === "function") requestAnimationFrame(fn);
|
|
26
|
+
else fn();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Draw a toast or banner in the stack, open an anchored menu or popover (options
|
|
31
|
+
* of the menu kinds: overlay-menu.js showMenu), or open a modal or sheet (options
|
|
32
|
+
* of those kinds: overlay-modal.js showModal).
|
|
33
|
+
*
|
|
34
|
+
* @param {object} opts
|
|
35
|
+
* @param {"toast"|"banner"|"menu"|"popover"|"modal"|"sheet"} opts.kind toast: content reads top
|
|
36
|
+
* to bottom; banner: left to right (an icon, then text).
|
|
37
|
+
* @param {string|Node|Node[]} [opts.content] markup the caller has already
|
|
38
|
+
* escaped, or the nodes to put in the card.
|
|
39
|
+
* @param {string} [opts.severity] info, success, warn (or warning) or error: the
|
|
40
|
+
* card's left edge. None draws a neutral card.
|
|
41
|
+
* @param {boolean} [opts.dismissible=true] false draws no close control and
|
|
42
|
+
* takes no key dismissal (a state the operator cannot clear, such as a page
|
|
43
|
+
* that no longer matches its server).
|
|
44
|
+
* @param {string} [opts.closeLabel] the close control's accessible name.
|
|
45
|
+
* @param {?number} [opts.timeout] ms until it leaves by itself; absent stays.
|
|
46
|
+
* @param {string} [opts.source] key a surface finds its cards by, to replace or
|
|
47
|
+
* withdraw them (overlay-stack.js cardsBySource).
|
|
48
|
+
* @param {string} [opts.group] key a surface clears all its cards by.
|
|
49
|
+
* @param {string} [opts.id] element id; a surface that must never draw twice
|
|
50
|
+
* looks it up first.
|
|
51
|
+
* @param {string} [opts.className] extra classes for the surface's content styling.
|
|
52
|
+
* @param {Object<string,string>} [opts.attrs] extra attributes.
|
|
53
|
+
* @param {boolean} [opts.first] top of the stack instead of the bottom.
|
|
54
|
+
* @param {function(Element)} [opts.onDismiss] the operator closed it (the close
|
|
55
|
+
* control or a key).
|
|
56
|
+
* @param {function(Element)} [opts.onRemove] it started to leave, however it was
|
|
57
|
+
* closed: the operator, its timeout, or removeFromStack.
|
|
58
|
+
* @param {Document} [opts.doc] defaults to the page's document.
|
|
59
|
+
* @returns {{el: Element, close: function(): void}}
|
|
60
|
+
*/
|
|
61
|
+
export function showOverlay(opts) {
|
|
62
|
+
if (opts && (opts.kind === "menu" || opts.kind === "popover")) return showMenu(opts);
|
|
63
|
+
if (opts && (opts.kind === "modal" || opts.kind === "sheet")) return showModal(opts);
|
|
64
|
+
if (!opts || !KIND_CLASS[opts.kind]) {
|
|
65
|
+
throw new Error("showOverlay: kind must be toast or banner, or menu, popover, modal or sheet, got " + (opts && opts.kind));
|
|
66
|
+
}
|
|
67
|
+
var doc = opts.doc || document;
|
|
68
|
+
var dismissible = opts.dismissible !== false;
|
|
69
|
+
|
|
70
|
+
var el = doc.createElement("div");
|
|
71
|
+
el.className = ["overlay", KIND_CLASS[opts.kind], dismissible ? "overlay-dismissible" : "", opts.className || ""]
|
|
72
|
+
.filter(Boolean).join(" ");
|
|
73
|
+
if (opts.id) el.id = opts.id;
|
|
74
|
+
el.setAttribute("data-overlay-kind", opts.kind);
|
|
75
|
+
if (SEVERITY[opts.severity]) el.setAttribute("data-severity", SEVERITY[opts.severity]);
|
|
76
|
+
if (typeof opts.source === "string") el.setAttribute("data-overlay-source", opts.source);
|
|
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 dismiss() {
|
|
84
|
+
removeFromStack(el);
|
|
85
|
+
if (opts.onDismiss) opts.onDismiss(el);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (dismissible) {
|
|
89
|
+
var close = doc.createElement("button");
|
|
90
|
+
close.className = "overlay-close";
|
|
91
|
+
close.setAttribute("type", "button");
|
|
92
|
+
close.setAttribute("aria-label", opts.closeLabel || "Dismiss");
|
|
93
|
+
close.innerHTML = iconHtml("x");
|
|
94
|
+
// The card may itself be clickable (a banner opens its session): closing is
|
|
95
|
+
// not that click.
|
|
96
|
+
close.addEventListener("click", function (e) {
|
|
97
|
+
if (e && e.stopPropagation) e.stopPropagation();
|
|
98
|
+
dismiss();
|
|
99
|
+
});
|
|
100
|
+
el.appendChild(close);
|
|
101
|
+
|
|
102
|
+
// Enter and Space bubble up from the card's own buttons when they are
|
|
103
|
+
// activated; that must activate the button, not close the card.
|
|
104
|
+
el.addEventListener("keydown", function (e) {
|
|
105
|
+
var fromButton = e.target && e.target.tagName === "BUTTON";
|
|
106
|
+
if (e.key === "Escape" || ((e.key === "Enter" || e.key === " ") && !fromButton)) dismiss();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
addToStack(el, { doc: doc, first: opts.first, timeout: opts.timeout, group: opts.group, onRemove: opts.onRemove });
|
|
111
|
+
// Draws the close icon. A surface whose own content carries icons refreshes
|
|
112
|
+
// them too; the refresh is one scan per frame however many ask.
|
|
113
|
+
if (dismissible) refreshIcons();
|
|
114
|
+
nextFrame(function () { el.classList.add("visible"); });
|
|
115
|
+
|
|
116
|
+
return { el: el, close: function () { removeFromStack(el); } };
|
|
117
|
+
}
|
|
@@ -77,9 +77,11 @@ export function clampRect(rect, viewport, opts) {
|
|
|
77
77
|
* @param {{top:number, left:number, right:number, bottom:number}} anchorRect Anchor element's getBoundingClientRect().
|
|
78
78
|
* @param {{innerWidth:number, innerHeight:number}} viewport
|
|
79
79
|
* @param {object} [opts]
|
|
80
|
-
* @param {"right"|"below"|"below-right-aligned"} [opts.placement="right"]
|
|
80
|
+
* @param {"right"|"below"|"below-center"|"above"|"below-right-aligned"} [opts.placement="right"]
|
|
81
81
|
* Preferred side: "right" of the anchor (default, matches existing
|
|
82
|
-
* ctx-menu behavior), "below" the anchor left-aligned,
|
|
82
|
+
* ctx-menu behavior), "below" the anchor left-aligned, "below-center" it
|
|
83
|
+
* centred on the anchor, "above" it left-aligned (flipping below when the top
|
|
84
|
+
* edge would be crossed), or
|
|
83
85
|
* "below-right-aligned" (below the anchor with the popover's right edge
|
|
84
86
|
* aligned to the anchor's right edge — matches session/loop ctx-menu
|
|
85
87
|
* `right: window.innerWidth - btnRect.right` anchoring).
|
|
@@ -109,6 +111,20 @@ export function computePopoverPosition(popoverSize, anchorRect, viewport, opts)
|
|
|
109
111
|
if (top2 + popoverSize.height > viewport.innerHeight - margin) {
|
|
110
112
|
top2 = anchorRect.top - popoverSize.height - gap;
|
|
111
113
|
}
|
|
114
|
+
} else if (placement === "below-center") {
|
|
115
|
+
left2 = anchorRect.left + (anchorRect.right - anchorRect.left) / 2 - popoverSize.width / 2;
|
|
116
|
+
top2 = anchorRect.bottom + gap;
|
|
117
|
+
if (top2 + popoverSize.height > viewport.innerHeight - margin) {
|
|
118
|
+
top2 = anchorRect.top - popoverSize.height - gap;
|
|
119
|
+
}
|
|
120
|
+
} else if (placement === "above") {
|
|
121
|
+
// For an anchor at the bottom of the page (the composer, the user island).
|
|
122
|
+
left2 = anchorRect.left;
|
|
123
|
+
top2 = anchorRect.top - popoverSize.height - gap;
|
|
124
|
+
// Flip below the anchor if it would overflow the top edge.
|
|
125
|
+
if (top2 < margin) {
|
|
126
|
+
top2 = anchorRect.bottom + gap;
|
|
127
|
+
}
|
|
112
128
|
} else if (placement === "below") {
|
|
113
129
|
left2 = anchorRect.left;
|
|
114
130
|
top2 = anchorRect.bottom + gap;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// preference-sync.js - the one place a per-user preference's server round trip is
|
|
2
|
+
// reported and the profile is read at load.
|
|
3
|
+
//
|
|
4
|
+
// The theme, the chat width and the session-list avatars are cached in
|
|
5
|
+
// localStorage and reconciled with the server, best effort: a failed save or a
|
|
6
|
+
// failed profile load must not stop the page, but it must not vanish either.
|
|
7
|
+
// Every such failure goes through reportPreferenceFailure, so the way it is
|
|
8
|
+
// reported changes in one place.
|
|
9
|
+
|
|
10
|
+
export function reportPreferenceFailure(message, err) {
|
|
11
|
+
if (err === undefined) console.error(message);
|
|
12
|
+
else console.error(message, err);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Reads /api/profile and hands it to `apply`. A network error, a non-OK status,
|
|
16
|
+
// an unreadable body or an `apply` that throws is reported, naming the
|
|
17
|
+
// preference, and leaves what this browser already had in place. Resolves
|
|
18
|
+
// either way.
|
|
19
|
+
export function loadProfilePreference(name, apply) {
|
|
20
|
+
return fetch("/api/profile").then(function (res) {
|
|
21
|
+
if (!res.ok) throw new Error("HTTP " + res.status);
|
|
22
|
+
return res.json();
|
|
23
|
+
}).then(function (profile) {
|
|
24
|
+
if (profile) apply(profile);
|
|
25
|
+
}).catch(function (err) {
|
|
26
|
+
reportPreferenceFailure("Loading the " + name + " preference failed:", err);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -6,6 +6,8 @@ import { iconHtml, refreshIcons } from './icons.js';
|
|
|
6
6
|
import { setSTTLang } from './stt.js';
|
|
7
7
|
import { avatarUrl, AVATAR_STYLES } from './avatar.js';
|
|
8
8
|
import { store } from './store.js';
|
|
9
|
+
import { showOverlay } from './overlay.js';
|
|
10
|
+
import { closeMenu } from './overlay-registry.js';
|
|
9
11
|
|
|
10
12
|
var ctx;
|
|
11
13
|
var profile = { name: '', lang: 'en-US', avatarStyle: 'thumbs', avatarSeed: '', avatarColor: '#7c3aed', avatarCustom: '' };
|
|
@@ -126,17 +128,10 @@ export function showAvatarPositioner(img, objectUrl, onDone) {
|
|
|
126
128
|
previewImg.style.transform = 'translate(' + tx + 'px, ' + ty + 'px)';
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
overlay.className = 'avatar-positioner-overlay';
|
|
132
|
-
|
|
131
|
+
// What goes inside the dialog; the scrim, card, layer and close control are the
|
|
132
|
+
// shared overlay component's.
|
|
133
133
|
var container = document.createElement('div');
|
|
134
|
-
container.className = 'avatar-positioner-
|
|
135
|
-
|
|
136
|
-
var closeBtn = document.createElement('button');
|
|
137
|
-
closeBtn.className = 'avatar-positioner-close';
|
|
138
|
-
closeBtn.innerHTML = '×';
|
|
139
|
-
container.appendChild(closeBtn);
|
|
134
|
+
container.className = 'avatar-positioner-body';
|
|
140
135
|
|
|
141
136
|
var title = document.createElement('div');
|
|
142
137
|
title.className = 'avatar-positioner-title';
|
|
@@ -181,8 +176,13 @@ export function showAvatarPositioner(img, objectUrl, onDone) {
|
|
|
181
176
|
btnRow.appendChild(doneBtn);
|
|
182
177
|
container.appendChild(btnRow);
|
|
183
178
|
|
|
184
|
-
|
|
185
|
-
|
|
179
|
+
// Escape, the scrim and the close control cancel the same way the Cancel button does.
|
|
180
|
+
var handle = showOverlay({
|
|
181
|
+
kind: 'modal',
|
|
182
|
+
dialogClass: 'avatar-positioner-container',
|
|
183
|
+
content: container,
|
|
184
|
+
onDismiss: function() { URL.revokeObjectURL(objectUrl); },
|
|
185
|
+
});
|
|
186
186
|
updatePreview();
|
|
187
187
|
|
|
188
188
|
// Drag
|
|
@@ -246,11 +246,10 @@ export function showAvatarPositioner(img, objectUrl, onDone) {
|
|
|
246
246
|
}, { passive: false });
|
|
247
247
|
|
|
248
248
|
function cleanup(revoke) {
|
|
249
|
-
|
|
249
|
+
handle.close();
|
|
250
250
|
if (revoke) URL.revokeObjectURL(objectUrl);
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
closeBtn.addEventListener('click', function() { cleanup(true); });
|
|
254
253
|
cancelBtn.addEventListener('click', function() { cleanup(true); });
|
|
255
254
|
|
|
256
255
|
doneBtn.addEventListener('click', function() {
|
|
@@ -283,7 +282,6 @@ function showPopover() {
|
|
|
283
282
|
}
|
|
284
283
|
|
|
285
284
|
popoverEl = document.createElement('div');
|
|
286
|
-
popoverEl.className = 'profile-popover';
|
|
287
285
|
|
|
288
286
|
var displayName = profile.name || '';
|
|
289
287
|
var currentColor = profile.avatarColor || '#7c3aed';
|
|
@@ -293,10 +291,8 @@ function showPopover() {
|
|
|
293
291
|
|
|
294
292
|
var html = '';
|
|
295
293
|
|
|
296
|
-
// Banner
|
|
297
|
-
html += '<div class="profile-banner" style="background:' + currentColor + '">';
|
|
298
|
-
html += '<button class="profile-close-btn">×</button>';
|
|
299
|
-
html += '</div>';
|
|
294
|
+
// Banner (the close control is the shared one, added by the component)
|
|
295
|
+
html += '<div class="profile-banner" style="background:' + currentColor + '"></div>';
|
|
300
296
|
|
|
301
297
|
// Avatar row (overlapping banner)
|
|
302
298
|
html += '<div class="profile-avatar-row">';
|
|
@@ -356,11 +352,6 @@ function showPopover() {
|
|
|
356
352
|
popoverEl.innerHTML = html;
|
|
357
353
|
|
|
358
354
|
// --- Events ---
|
|
359
|
-
popoverEl.querySelector('.profile-close-btn').addEventListener('click', function(e) {
|
|
360
|
-
e.stopPropagation();
|
|
361
|
-
hidePopover();
|
|
362
|
-
});
|
|
363
|
-
|
|
364
355
|
var nameInput = popoverEl.querySelector('#profile-name-input');
|
|
365
356
|
nameInput.addEventListener('input', function() {
|
|
366
357
|
profile.name = nameInput.value.trim();
|
|
@@ -476,18 +467,20 @@ function showPopover() {
|
|
|
476
467
|
e.stopPropagation();
|
|
477
468
|
});
|
|
478
469
|
|
|
470
|
+
// Hung above the user island; the close control, outside click and Escape are
|
|
471
|
+
// the shared component's and the registry's.
|
|
479
472
|
var island = document.getElementById('user-island');
|
|
480
|
-
|
|
473
|
+
var card = popoverEl;
|
|
474
|
+
showOverlay({
|
|
475
|
+
kind: 'popover', el: card, className: 'profile-popover', closeButton: true, closeLabel: 'Close profile',
|
|
476
|
+
anchor: island, placement: 'above', gap: 8, opener: island,
|
|
477
|
+
onRemove: function() { if (popoverEl === card) popoverEl = null; },
|
|
478
|
+
});
|
|
481
479
|
refreshIcons();
|
|
482
480
|
|
|
483
481
|
if (!profile.name) {
|
|
484
482
|
nameInput.focus();
|
|
485
483
|
}
|
|
486
|
-
|
|
487
|
-
setTimeout(function() {
|
|
488
|
-
document.addEventListener('click', closeOnOutside);
|
|
489
|
-
document.addEventListener('keydown', closeOnEscape);
|
|
490
|
-
}, 0);
|
|
491
484
|
}
|
|
492
485
|
|
|
493
486
|
function updatePopoverHeader() {
|
|
@@ -509,26 +502,8 @@ function refreshAvatarPreviews() {
|
|
|
509
502
|
});
|
|
510
503
|
}
|
|
511
504
|
|
|
512
|
-
function closeOnOutside(e) {
|
|
513
|
-
var island = document.getElementById('user-island');
|
|
514
|
-
if (popoverEl && !popoverEl.contains(e.target) && !island.contains(e.target)) {
|
|
515
|
-
hidePopover();
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
function closeOnEscape(e) {
|
|
520
|
-
if (e.key === 'Escape' && popoverEl) {
|
|
521
|
-
hidePopover();
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
505
|
function hidePopover() {
|
|
526
|
-
if (popoverEl)
|
|
527
|
-
popoverEl.remove();
|
|
528
|
-
popoverEl = null;
|
|
529
|
-
}
|
|
530
|
-
document.removeEventListener('click', closeOnOutside);
|
|
531
|
-
document.removeEventListener('keydown', closeOnEscape);
|
|
506
|
+
if (popoverEl) closeMenu(popoverEl);
|
|
532
507
|
}
|
|
533
508
|
|
|
534
509
|
function escapeAttr(str) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// project-settings.js — Project settings panel (profile, defaults, instructions, env)
|
|
2
2
|
import { refreshIcons } from './icons.js';
|
|
3
3
|
import { buildEmojiPicker } from './emoji-picker.js';
|
|
4
|
-
import { showToast
|
|
4
|
+
import { showToast } from './utils.js';
|
|
5
5
|
import { parseEmojis } from './markdown.js';
|
|
6
6
|
import { renderProjectIcon } from './project-icon.js';
|
|
7
7
|
import { pushOverlayState, popOverlayState } from './overlay-history.js';
|
|
@@ -9,6 +9,9 @@ import { closeFileViewer } from './filebrowser.js';
|
|
|
9
9
|
import { renderModelList, renderModeList, renderEffortBar, renderThinkingBar, renderBetaCard } from './settings-defaults.js';
|
|
10
10
|
import { capabilitiesFor, defaultVendorId } from './vendor-registry.js';
|
|
11
11
|
import { renderShadowNotice } from './env-shadow-notice.js';
|
|
12
|
+
import { store } from './store.js';
|
|
13
|
+
import { canOpenProjectSettings } from './settings-access.js';
|
|
14
|
+
import { mountSettingsBack } from './settings-nav.js';
|
|
12
15
|
|
|
13
16
|
var ctx = null;
|
|
14
17
|
var panelEl = null;
|
|
@@ -17,18 +20,8 @@ var sections = null;
|
|
|
17
20
|
var currentSlug = null;
|
|
18
21
|
var currentProject = null; // { slug, name, icon }
|
|
19
22
|
|
|
20
|
-
// ===== PS Palette =====
|
|
21
23
|
var currentPsSection = "profile";
|
|
22
|
-
var
|
|
23
|
-
var psPaletteHighlight = -1;
|
|
24
|
-
|
|
25
|
-
var PS_SECTIONS = [
|
|
26
|
-
{ section: "profile", label: "Profile", group: "General", icon: "user" },
|
|
27
|
-
{ section: "defaults", label: "Model", group: "General", icon: "cpu" },
|
|
28
|
-
{ section: "instructions", label: "Instructions", group: "Config", icon: "file-text" },
|
|
29
|
-
{ section: "environment", label: "Environment", group: "Config", icon: "terminal" },
|
|
30
|
-
{ section: "lite", label: "Lite", group: "Config", icon: "zap", conditionalId: "ps-nav-lite" },
|
|
31
|
-
];
|
|
24
|
+
var backBar = null;
|
|
32
25
|
|
|
33
26
|
// ===== Init =====
|
|
34
27
|
export function initProjectSettings(appCtx) {
|
|
@@ -46,30 +39,12 @@ export function initProjectSettings(appCtx) {
|
|
|
46
39
|
});
|
|
47
40
|
}
|
|
48
41
|
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// PS palette
|
|
58
|
-
var psPaletteEl = document.getElementById("ps-palette");
|
|
59
|
-
if (psPaletteEl) {
|
|
60
|
-
var psPaletteBackdrop = psPaletteEl.querySelector(".settings-palette-backdrop");
|
|
61
|
-
if (psPaletteBackdrop) {
|
|
62
|
-
psPaletteBackdrop.addEventListener("click", function () { closePsPalette(); });
|
|
63
|
-
}
|
|
64
|
-
var psPaletteInput = document.getElementById("ps-palette-input");
|
|
65
|
-
if (psPaletteInput) {
|
|
66
|
-
psPaletteInput.addEventListener("input", function () {
|
|
67
|
-
psPaletteHighlight = -1;
|
|
68
|
-
renderPsPaletteResults(psPaletteInput.value);
|
|
69
|
-
});
|
|
70
|
-
psPaletteInput.addEventListener("keydown", function (e) { handlePsPaletteKey(e); });
|
|
71
|
-
}
|
|
72
|
-
}
|
|
42
|
+
// Phone: the Back bar stands in for the section list, which the shared
|
|
43
|
+
// Settings list replaces there.
|
|
44
|
+
backBar = mountSettingsBack(panelEl.querySelector(".project-settings-nav-inner"), {
|
|
45
|
+
label: "Back to Settings",
|
|
46
|
+
onBack: closeProjectSettings,
|
|
47
|
+
});
|
|
73
48
|
|
|
74
49
|
// Close button
|
|
75
50
|
var closeBtn = document.getElementById("project-settings-close");
|
|
@@ -82,7 +57,6 @@ export function initProjectSettings(appCtx) {
|
|
|
82
57
|
// ESC key
|
|
83
58
|
document.addEventListener("keydown", function (e) {
|
|
84
59
|
if (e.key === "Escape") {
|
|
85
|
-
if (psPaletteOpen) { closePsPalette(); return; }
|
|
86
60
|
if (panelEl && !panelEl.classList.contains("hidden")) {
|
|
87
61
|
closeProjectSettings();
|
|
88
62
|
}
|
|
@@ -198,8 +172,12 @@ export function initProjectSettings(appCtx) {
|
|
|
198
172
|
}
|
|
199
173
|
|
|
200
174
|
// ===== Open / Close =====
|
|
201
|
-
|
|
175
|
+
// The one way into Project Settings. Every route (the project menu, the phone
|
|
176
|
+
// Settings list, a phone project action) passes the project-settings
|
|
177
|
+
// permission here; `section` opens on that section instead of the first.
|
|
178
|
+
export function openProjectSettings(slug, project, section) {
|
|
202
179
|
if (!panelEl) return;
|
|
180
|
+
if (!canOpenProjectSettings(store.get('permissions'))) return;
|
|
203
181
|
currentSlug = slug;
|
|
204
182
|
currentProject = project;
|
|
205
183
|
|
|
@@ -207,8 +185,8 @@ export function openProjectSettings(slug, project) {
|
|
|
207
185
|
var navTitle = document.getElementById("ps-nav-title");
|
|
208
186
|
if (navTitle) navTitle.textContent = project.name || slug;
|
|
209
187
|
|
|
210
|
-
// Reset to first section
|
|
211
|
-
switchSection("profile");
|
|
188
|
+
// Reset to the first section, or the one asked for
|
|
189
|
+
switchSection(section || "profile");
|
|
212
190
|
|
|
213
191
|
// Populate profile
|
|
214
192
|
populateProfile();
|
|
@@ -253,8 +231,7 @@ function switchSection(name) {
|
|
|
253
231
|
sections[j].classList.toggle("active", active2);
|
|
254
232
|
}
|
|
255
233
|
|
|
256
|
-
|
|
257
|
-
updatePsPill(name);
|
|
234
|
+
syncBackTitle();
|
|
258
235
|
|
|
259
236
|
// Lazy-load section data
|
|
260
237
|
if (name === "defaults") populateDefaults();
|
|
@@ -274,136 +251,11 @@ function switchSection(name) {
|
|
|
274
251
|
}
|
|
275
252
|
}
|
|
276
253
|
|
|
277
|
-
//
|
|
278
|
-
function
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
for (var i = 0; i < PS_SECTIONS.length; i++) {
|
|
283
|
-
if (PS_SECTIONS[i].section === sectionName) { found = PS_SECTIONS[i]; break; }
|
|
284
|
-
}
|
|
285
|
-
var groupEl = document.getElementById("ps-nav-pill-group");
|
|
286
|
-
var labelEl = document.getElementById("ps-nav-pill-label");
|
|
287
|
-
if (found) {
|
|
288
|
-
if (groupEl) groupEl.textContent = found.group;
|
|
289
|
-
if (labelEl) labelEl.textContent = found.label;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function openPsPalette() {
|
|
294
|
-
var palette = document.getElementById("ps-palette");
|
|
295
|
-
if (!palette) return;
|
|
296
|
-
psPaletteOpen = true;
|
|
297
|
-
psPaletteHighlight = -1;
|
|
298
|
-
palette.classList.remove("hidden");
|
|
299
|
-
var pill = document.getElementById("ps-nav-pill");
|
|
300
|
-
if (pill) pill.setAttribute("aria-expanded", "true");
|
|
301
|
-
var input = document.getElementById("ps-palette-input");
|
|
302
|
-
if (input) {
|
|
303
|
-
input.value = "";
|
|
304
|
-
if (window.matchMedia("(pointer: fine)").matches) input.focus();
|
|
305
|
-
}
|
|
306
|
-
renderPsPaletteResults("");
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
function closePsPalette() {
|
|
310
|
-
var palette = document.getElementById("ps-palette");
|
|
311
|
-
if (!palette) return;
|
|
312
|
-
psPaletteOpen = false;
|
|
313
|
-
palette.classList.add("hidden");
|
|
314
|
-
var pill = document.getElementById("ps-nav-pill");
|
|
315
|
-
if (pill) {
|
|
316
|
-
pill.setAttribute("aria-expanded", "false");
|
|
317
|
-
if (window.matchMedia("(pointer: fine)").matches) pill.focus();
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function renderPsPaletteResults(query) {
|
|
322
|
-
var container = document.getElementById("ps-palette-results");
|
|
323
|
-
if (!container) return;
|
|
324
|
-
var q = (query || "").toLowerCase().trim();
|
|
325
|
-
|
|
326
|
-
var visible = [];
|
|
327
|
-
for (var i = 0; i < PS_SECTIONS.length; i++) {
|
|
328
|
-
var s = PS_SECTIONS[i];
|
|
329
|
-
// Skip conditional sections that are hidden
|
|
330
|
-
if (s.conditionalId) {
|
|
331
|
-
var condEl = document.getElementById(s.conditionalId);
|
|
332
|
-
if (!condEl || condEl.classList.contains("hidden")) continue;
|
|
333
|
-
}
|
|
334
|
-
if (!q || s.label.toLowerCase().indexOf(q) !== -1 || s.group.toLowerCase().indexOf(q) !== -1) {
|
|
335
|
-
visible.push(s);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (!visible.length) {
|
|
340
|
-
container.innerHTML = '<div class="settings-palette-empty">No sections found</div>';
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
var html = "";
|
|
345
|
-
var lastGroup = null;
|
|
346
|
-
for (var j = 0; j < visible.length; j++) {
|
|
347
|
-
var sec = visible[j];
|
|
348
|
-
if (sec.group !== lastGroup) {
|
|
349
|
-
html += '<div class="settings-palette-group-header">' + escapeHtml(sec.group) + '</div>';
|
|
350
|
-
lastGroup = sec.group;
|
|
351
|
-
}
|
|
352
|
-
var isCurrent = sec.section === currentPsSection;
|
|
353
|
-
html += '<button class="settings-palette-item' +
|
|
354
|
-
(isCurrent ? ' current' : '') +
|
|
355
|
-
(j === psPaletteHighlight ? ' highlighted' : '') +
|
|
356
|
-
'" data-section="' + escapeHtml(sec.section) + '">' +
|
|
357
|
-
'<span class="settings-palette-item-icon"><i data-lucide="' + escapeHtml(sec.icon) + '"></i></span>' +
|
|
358
|
-
'<span class="settings-palette-item-label">' + escapeHtml(sec.label) + '</span>' +
|
|
359
|
-
(isCurrent ? '<span class="settings-palette-item-check"><i data-lucide="check"></i></span>' : '') +
|
|
360
|
-
'</button>';
|
|
361
|
-
}
|
|
362
|
-
container.innerHTML = html;
|
|
363
|
-
|
|
364
|
-
var items = container.querySelectorAll(".settings-palette-item");
|
|
365
|
-
for (var k = 0; k < items.length; k++) {
|
|
366
|
-
items[k].addEventListener("click", function () {
|
|
367
|
-
var sec = this.dataset.section;
|
|
368
|
-
closePsPalette();
|
|
369
|
-
switchSection(sec);
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
if (typeof refreshIcons === "function") refreshIcons();
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
function handlePsPaletteKey(e) {
|
|
376
|
-
var container = document.getElementById("ps-palette-results");
|
|
377
|
-
if (!container) return;
|
|
378
|
-
var items = container.querySelectorAll(".settings-palette-item");
|
|
379
|
-
if (e.key === "ArrowDown") {
|
|
380
|
-
e.preventDefault();
|
|
381
|
-
psPaletteHighlight = Math.min(psPaletteHighlight + 1, items.length - 1);
|
|
382
|
-
updatePsPaletteHighlight(items);
|
|
383
|
-
} else if (e.key === "ArrowUp") {
|
|
384
|
-
e.preventDefault();
|
|
385
|
-
psPaletteHighlight = Math.max(psPaletteHighlight - 1, 0);
|
|
386
|
-
updatePsPaletteHighlight(items);
|
|
387
|
-
} else if (e.key === "Enter") {
|
|
388
|
-
e.preventDefault();
|
|
389
|
-
var idx = psPaletteHighlight >= 0 ? psPaletteHighlight : 0;
|
|
390
|
-
if (items[idx]) {
|
|
391
|
-
var sec = items[idx].dataset.section;
|
|
392
|
-
closePsPalette();
|
|
393
|
-
switchSection(sec);
|
|
394
|
-
}
|
|
395
|
-
} else if (e.key === "Escape") {
|
|
396
|
-
e.preventDefault();
|
|
397
|
-
closePsPalette();
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
function updatePsPaletteHighlight(items) {
|
|
402
|
-
for (var i = 0; i < items.length; i++) {
|
|
403
|
-
items[i].classList.toggle("highlighted", i === psPaletteHighlight);
|
|
404
|
-
}
|
|
405
|
-
if (items[psPaletteHighlight]) {
|
|
406
|
-
items[psPaletteHighlight].scrollIntoView({ block: "nearest" });
|
|
254
|
+
// The phone Back bar names the open section; desktop does not show it.
|
|
255
|
+
function syncBackTitle() {
|
|
256
|
+
if (!backBar) return;
|
|
257
|
+
for (var i = 0; i < navItems.length; i++) {
|
|
258
|
+
if (navItems[i].dataset.section === currentPsSection) backBar.setTitle(navItems[i].textContent.trim());
|
|
407
259
|
}
|
|
408
260
|
}
|
|
409
261
|
|
|
@@ -574,6 +426,9 @@ function showPsEmojiPicker() {
|
|
|
574
426
|
},
|
|
575
427
|
});
|
|
576
428
|
|
|
429
|
+
// Inline in the settings page, not a popover: it has the shared card chrome
|
|
430
|
+
// but is not placed or tracked as a menu.
|
|
431
|
+
picker.classList.add("overlay-card");
|
|
577
432
|
picker.style.position = "relative";
|
|
578
433
|
picker.style.left = "0";
|
|
579
434
|
picker.style.top = "0";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// prompt-expiry-controls.js - the "Expire unanswered prompts after" input on the
|
|
2
|
+
// server settings page. The server holds the value and sends it on connect and
|
|
3
|
+
// after every change; only an administrator's change is accepted, and the card
|
|
4
|
+
// is shown to administrators only. The message handler is registered by
|
|
5
|
+
// app-messages.js.
|
|
6
|
+
|
|
7
|
+
// The default the server runs with until it says otherwise, and the largest
|
|
8
|
+
// value it accepts (lib/prompt-expiry.js); a value outside the range is not sent.
|
|
9
|
+
var DEFAULT_MINUTES = 30;
|
|
10
|
+
var MAX_MINUTES = 35791;
|
|
11
|
+
|
|
12
|
+
var currentMinutes = DEFAULT_MINUTES;
|
|
13
|
+
var sendSetting = null;
|
|
14
|
+
|
|
15
|
+
function showProblem(text) {
|
|
16
|
+
var el = document.getElementById("ss-prompt-expiry-problem");
|
|
17
|
+
if (el) el.textContent = text;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Draws the input from the latest value. sendMsg(type, data) is the page's
|
|
22
|
+
* WebSocket sender; it is kept for the control to use.
|
|
23
|
+
*/
|
|
24
|
+
export function renderPromptExpirySettings(sendMsg) {
|
|
25
|
+
if (sendMsg) sendSetting = sendMsg;
|
|
26
|
+
var input = document.getElementById("ss-prompt-expiry");
|
|
27
|
+
if (!input) return;
|
|
28
|
+
input.value = String(currentMinutes);
|
|
29
|
+
input.onchange = function () {
|
|
30
|
+
var typed = input.value.trim();
|
|
31
|
+
var n = Number(typed);
|
|
32
|
+
if (typed === "" || !isFinite(n) || Math.floor(n) !== n || n < 0 || n > MAX_MINUTES) {
|
|
33
|
+
showProblem("The expiry must be a whole number of minutes from 0 to " + MAX_MINUTES + ". 0 turns expiry off.");
|
|
34
|
+
input.value = String(currentMinutes);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
showProblem("");
|
|
38
|
+
if (sendSetting) sendSetting("set_prompt_expiry_settings", { promptExpiryMinutes: n });
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function handlePromptExpirySettings(msg) {
|
|
43
|
+
var n = msg.promptExpiryMinutes;
|
|
44
|
+
currentMinutes = typeof n === "number" && isFinite(n) && n >= 0 ? n : DEFAULT_MINUTES;
|
|
45
|
+
renderPromptExpirySettings();
|
|
46
|
+
}
|