@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,186 @@
|
|
|
1
|
+
// overlay-modal.js - the modal and sheet kinds of the shared overlay component: a
|
|
2
|
+
// scrim over the page with one dialog card on it.
|
|
3
|
+
//
|
|
4
|
+
// Called through showOverlay (overlay.js) with kind "modal" (a centred dialog) or
|
|
5
|
+
// "sheet" (a panel rising from the bottom edge). The scrim, the card, the layer
|
|
6
|
+
// (--z-modal) and the close control are drawn by css/overlay.css; open modals are
|
|
7
|
+
// tracked, and closed by Escape, by the registry (overlay-registry.js). The
|
|
8
|
+
// scrim closes the modal too, and so does the shared close control, top-right.
|
|
9
|
+
//
|
|
10
|
+
// A modal is built here from its content, or adopts a node the page already has
|
|
11
|
+
// (opts.el): that node carries a .overlay-modal-backdrop and a
|
|
12
|
+
// .overlay-modal-dialog of its own, and the component keeps it hidden between
|
|
13
|
+
// uses.
|
|
14
|
+
|
|
15
|
+
import { iconHtml, refreshIcons } from './icons.js';
|
|
16
|
+
import { openModal, closeModal, dismissModal, isModalOpen, isPanelBlocked } from './overlay-registry.js';
|
|
17
|
+
import { pushOverlayState, popOverlayState, releaseOverlayState } from './overlay-history.js';
|
|
18
|
+
|
|
19
|
+
// Scrims already listening, so a node opened again is not wired twice.
|
|
20
|
+
var wired = new WeakSet();
|
|
21
|
+
// Panels that hold an entry in the browser history right now: one entry each,
|
|
22
|
+
// however many times the panel is opened while it is open.
|
|
23
|
+
var holding = new WeakSet();
|
|
24
|
+
|
|
25
|
+
// Whether a panel opening now holds a history entry: on by default, or as the
|
|
26
|
+
// caller's option (a boolean, or a function asked at each open).
|
|
27
|
+
function wantsHistoryEntry(opts) {
|
|
28
|
+
if (typeof opts.history === "function") return !!opts.history();
|
|
29
|
+
return opts.history !== false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function addClasses(el, names) {
|
|
33
|
+
String(names || "").split(/\s+/).filter(Boolean).forEach(function (n) { el.classList.add(n); });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function fill(el, content) {
|
|
37
|
+
if (typeof content === "string") el.innerHTML = content;
|
|
38
|
+
else if (content) [].concat(content).forEach(function (node) { el.appendChild(node); });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Open a modal or sheet.
|
|
43
|
+
*
|
|
44
|
+
* @param {object} opts
|
|
45
|
+
* @param {"modal"|"sheet"} opts.kind
|
|
46
|
+
* @param {string|Node|Node[]} [opts.content] markup the caller has already
|
|
47
|
+
* escaped, or nodes, for the dialog. Absent on an adopted node keeps what it holds.
|
|
48
|
+
* @param {Element} [opts.el] a node the page already has, kept in place and hidden
|
|
49
|
+
* (the "hidden" class) when it closes; it holds the scrim and the dialog.
|
|
50
|
+
* @param {boolean} [opts.dismissible=true] false: no close control, and neither
|
|
51
|
+
* Escape nor the scrim closes it.
|
|
52
|
+
* @param {boolean} [opts.card=true] false draws the dialog without card chrome (a
|
|
53
|
+
* lightbox, where the content is the picture); its close control then hangs from
|
|
54
|
+
* the viewport corner.
|
|
55
|
+
* @param {"dark"|"solid"} [opts.scrim] dark: a darker scrim. solid: the page's own
|
|
56
|
+
* background, so nothing under it shows (a screen the operator must finish).
|
|
57
|
+
* @param {boolean} [opts.navSheet] a sheet a bottom-nav button opens: it stops
|
|
58
|
+
* above the nav so the nav stays in view and usable.
|
|
59
|
+
* @param {boolean} [opts.panel] a panel (a modal only): a full-page surface on
|
|
60
|
+
* the panel layer (--z-panel), under the dialogs a panel opens. Escape, the
|
|
61
|
+
* scrim and the shared close control close it as they close a modal, and it
|
|
62
|
+
* holds an entry in the browser history so a back swipe closes it too
|
|
63
|
+
* (overlay-history.js, routed by closeTopHeldPanel). The dialog fills the page;
|
|
64
|
+
* a surface that is a card or a drop-down sizes its own dialogClass. A panel is
|
|
65
|
+
* refused while a dialog is open: the returned handle has refused: true and
|
|
66
|
+
* isOpen() false, and the caller does nothing more.
|
|
67
|
+
* @param {boolean|function(): boolean} [opts.history=true] a panel only: whether
|
|
68
|
+
* it holds a history entry. A function is asked at each open (a panel that is
|
|
69
|
+
* a page of the phone Settings list holds one on a phone only).
|
|
70
|
+
* @param {{className: string, ms: number}} [opts.exit] a class that plays the exit
|
|
71
|
+
* animation before the node is hidden or removed after ms.
|
|
72
|
+
* @param {string} [opts.closeLabel] the close control's accessible name.
|
|
73
|
+
* @param {string} [opts.id]
|
|
74
|
+
* @param {string} [opts.className] extra classes for the surface's content styling.
|
|
75
|
+
* @param {string} [opts.dialogClass] extra classes for the dialog card.
|
|
76
|
+
* @param {Object<string,string>} [opts.attrs]
|
|
77
|
+
* @param {function(Element)} [opts.onDismiss] the operator closed it (Escape, the
|
|
78
|
+
* scrim or the close control). A confirmation resolves as cancel here.
|
|
79
|
+
* @param {function(Event): boolean} [opts.onEscape] Escape while it is the top
|
|
80
|
+
* modal; returning true means the key was spent on something inside it (a detail
|
|
81
|
+
* view stepping back to its list) and the modal stays open.
|
|
82
|
+
* @param {function(Element)} [opts.onRemove] it closed, however.
|
|
83
|
+
* @param {Document} [opts.doc]
|
|
84
|
+
* @returns {{el: Element, dialog: ?Element, refused: (boolean|undefined), close: function({immediate: boolean, keepHistory: boolean}=): void, isOpen: function(): boolean}}
|
|
85
|
+
* close's keepHistory: a panel releases its history entry without history.back()
|
|
86
|
+
* because the page pushes an entry of its own next.
|
|
87
|
+
*/
|
|
88
|
+
export function showModal(opts) {
|
|
89
|
+
var doc = opts.doc || document;
|
|
90
|
+
var isSheet = opts.kind === "sheet";
|
|
91
|
+
var isPanel = !!opts.panel && !isSheet;
|
|
92
|
+
var dismissible = opts.dismissible !== false;
|
|
93
|
+
var el = opts.el || doc.createElement("div");
|
|
94
|
+
// A panel does not open while a dialog is open (overlay-registry.js isPanelBlocked):
|
|
95
|
+
// nothing is drawn, no history entry is held and no hook runs. The caller sees it
|
|
96
|
+
// in isOpen() and in refused.
|
|
97
|
+
if (isPanel && isPanelBlocked(el)) {
|
|
98
|
+
return { el: el, dialog: null, refused: true, close: function () {}, isOpen: function () { return false; } };
|
|
99
|
+
}
|
|
100
|
+
var backdrop;
|
|
101
|
+
var dialog;
|
|
102
|
+
|
|
103
|
+
addClasses(el, "overlay-modal " + (isSheet ? "overlay-sheet " : "") + (opts.scrim === "dark" ? "overlay-scrim-dark " : "") +
|
|
104
|
+
(opts.scrim === "solid" ? "overlay-scrim-solid " : "") + (isPanel ? "overlay-panel " : "") +
|
|
105
|
+
(opts.navSheet ? "overlay-nav-sheet " : "") + (opts.className || ""));
|
|
106
|
+
if (opts.id) el.id = opts.id;
|
|
107
|
+
el.setAttribute("data-overlay-kind", opts.kind);
|
|
108
|
+
Object.keys(opts.attrs || {}).forEach(function (name) { el.setAttribute(name, opts.attrs[name]); });
|
|
109
|
+
|
|
110
|
+
if (opts.el) {
|
|
111
|
+
backdrop = el.querySelector(".overlay-modal-backdrop");
|
|
112
|
+
dialog = el.querySelector(".overlay-modal-dialog");
|
|
113
|
+
if (opts.content) fill(dialog || el, opts.content);
|
|
114
|
+
} else {
|
|
115
|
+
backdrop = doc.createElement("div");
|
|
116
|
+
backdrop.className = "overlay-modal-backdrop";
|
|
117
|
+
dialog = doc.createElement("div");
|
|
118
|
+
dialog.className = "overlay-modal-dialog";
|
|
119
|
+
fill(dialog, opts.content);
|
|
120
|
+
el.appendChild(backdrop);
|
|
121
|
+
el.appendChild(dialog);
|
|
122
|
+
}
|
|
123
|
+
if (dialog) {
|
|
124
|
+
if (isSheet) dialog.classList.add("overlay-sheet-dialog");
|
|
125
|
+
if (isPanel) dialog.classList.add("overlay-panel-dialog");
|
|
126
|
+
if (opts.card === false) dialog.classList.add("overlay-modal-bare");
|
|
127
|
+
addClasses(dialog, opts.dialogClass);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (dismissible && dialog && !dialog.querySelector(".overlay-close")) {
|
|
131
|
+
var x = doc.createElement("button");
|
|
132
|
+
x.className = "overlay-close";
|
|
133
|
+
x.setAttribute("type", "button");
|
|
134
|
+
x.setAttribute("aria-label", opts.closeLabel || "Close");
|
|
135
|
+
x.innerHTML = iconHtml("x");
|
|
136
|
+
x.addEventListener("click", function (e) {
|
|
137
|
+
if (e && e.stopPropagation) e.stopPropagation();
|
|
138
|
+
dismissModal(el);
|
|
139
|
+
});
|
|
140
|
+
dialog.appendChild(x);
|
|
141
|
+
}
|
|
142
|
+
// The listener asks the registry, which holds the current options, so a node
|
|
143
|
+
// opened again with other hooks is still handled by the one listener.
|
|
144
|
+
if (backdrop && !wired.has(backdrop)) {
|
|
145
|
+
wired.add(backdrop);
|
|
146
|
+
backdrop.addEventListener("click", function () { dismissModal(el); });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (isPanel && !holding.has(el) && wantsHistoryEntry(opts)) {
|
|
150
|
+
pushOverlayState(el);
|
|
151
|
+
holding.add(el);
|
|
152
|
+
}
|
|
153
|
+
// The history entry goes when the panel closes, by whatever way: Escape, the
|
|
154
|
+
// close control, a back swipe (the entry is then already gone, see
|
|
155
|
+
// popOverlayState) or the surface itself.
|
|
156
|
+
var onClose = function (node) {
|
|
157
|
+
if (holding.has(node)) {
|
|
158
|
+
holding.delete(node);
|
|
159
|
+
popOverlayState(node);
|
|
160
|
+
}
|
|
161
|
+
if (opts.onRemove) opts.onRemove(node);
|
|
162
|
+
};
|
|
163
|
+
openModal(el, {
|
|
164
|
+
onClose: onClose, onDismiss: opts.onDismiss, onEscape: opts.onEscape, dismissible: dismissible, retain: !!opts.el, exit: opts.exit,
|
|
165
|
+
panel: isPanel, held: holding.has(el), doc: doc,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
if (opts.el) el.classList.remove("hidden");
|
|
169
|
+
if (!el.parentNode) doc.body.appendChild(el);
|
|
170
|
+
refreshIcons();
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
el: el,
|
|
174
|
+
dialog: dialog,
|
|
175
|
+
close: function (closeOpts) {
|
|
176
|
+
// The page navigates right after (it pushes its own entry): the panel's
|
|
177
|
+
// entry is released without the history.back() that would race the push.
|
|
178
|
+
if (closeOpts && closeOpts.keepHistory && holding.has(el)) {
|
|
179
|
+
holding.delete(el);
|
|
180
|
+
releaseOverlayState(el);
|
|
181
|
+
}
|
|
182
|
+
closeModal(el, closeOpts);
|
|
183
|
+
},
|
|
184
|
+
isOpen: function () { return isModalOpen(el); },
|
|
185
|
+
};
|
|
186
|
+
}
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
// overlay-registry.js - the one registry of open menus and popovers.
|
|
2
|
+
//
|
|
3
|
+
// At most one menu is open, plus the menus it owns: a dropdown that a popover
|
|
4
|
+
// opens (a task list inside the scheduler's create popover) is registered with
|
|
5
|
+
// that popover as its parent and does not close it. Opening any other menu
|
|
6
|
+
// closes the lot. One document click handler (capture phase) and one Escape
|
|
7
|
+
// handler close what is open, so no surface carries its own document listener to
|
|
8
|
+
// dismiss a menu. A toast or banner is never in it, and Escape here never reaches
|
|
9
|
+
// one.
|
|
10
|
+
//
|
|
11
|
+
// The registry also keeps the open modals and sheets (overlay-modal.js): Escape
|
|
12
|
+
// closes the top one when no menu is open, and each is numbered so a later one
|
|
13
|
+
// sits over an earlier one. A panel (full-page settings, the palette) is kept
|
|
14
|
+
// here too, on the layer under the modals.
|
|
15
|
+
//
|
|
16
|
+
// A menu is any element: one the component built (overlay-menu.js), or one a
|
|
17
|
+
// surface already has in the page (a node in index.html), which the registry
|
|
18
|
+
// hides with the "hidden" class instead of removing.
|
|
19
|
+
|
|
20
|
+
// The open menus, outermost first; the last is the innermost.
|
|
21
|
+
// Each: { el, opener, onClose, onEscape, retain, doc }.
|
|
22
|
+
var stack = [];
|
|
23
|
+
// Documents that already carry the two handlers, so each gets them once.
|
|
24
|
+
var wired = new WeakSet();
|
|
25
|
+
|
|
26
|
+
function indexOf(el) {
|
|
27
|
+
for (var i = 0; i < stack.length; i++) if (stack[i].el === el) return i;
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// The open modals and sheets, earliest first; the last is the top one. Kept apart
|
|
32
|
+
// from the menus: a modal does not close a menu or another modal by opening, except
|
|
33
|
+
// an input autocomplete list, which it does close.
|
|
34
|
+
// Each: { el, onClose, onDismiss, onEscape, dismissible, retain, exit, panel, held, doc }.
|
|
35
|
+
var modals = [];
|
|
36
|
+
// A modal that is leaving (its exit class is on, its node not yet hidden), with
|
|
37
|
+
// the timer that finishes it, so opening it again cancels the exit.
|
|
38
|
+
var exiting = new WeakMap();
|
|
39
|
+
|
|
40
|
+
function indexOfModal(el) {
|
|
41
|
+
for (var i = 0; i < modals.length; i++) if (modals[i].el === el) return i;
|
|
42
|
+
return -1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Later modals sit over earlier ones, whatever their place in the page: the modal
|
|
46
|
+
// layer adds this number to --z-modal (css/overlay.css). Panels are numbered among
|
|
47
|
+
// themselves and clamped, so the panel layer (--z-panel plus this number) stays
|
|
48
|
+
// under the modal layer however many are open.
|
|
49
|
+
var PANEL_ORDER_MAX = 40;
|
|
50
|
+
|
|
51
|
+
function numberModals() {
|
|
52
|
+
var panelIndex = 0;
|
|
53
|
+
modals.forEach(function (c, i) {
|
|
54
|
+
var order = c.panel ? Math.min(panelIndex++, PANEL_ORDER_MAX) : i;
|
|
55
|
+
c.el.style.setProperty("--overlay-order", String(order));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The one rule for a panel and a dialog that meet: a panel is never opened while a
|
|
60
|
+
// dialog is open. A panel is on a lower layer than a dialog (--z-panel under
|
|
61
|
+
// --z-modal), so one opened over a dialog would render hidden under it while the
|
|
62
|
+
// back routing, which reads the open order, took it for the topmost. Refusing at
|
|
63
|
+
// the registry covers every way in (Ctrl+K, a banner or push route, a focused page
|
|
64
|
+
// opener) and a dialog that cannot be dismissed (a forced PIN change) stays the
|
|
65
|
+
// only thing the operator can reach. A panel already open is not refused: opening
|
|
66
|
+
// it again only refreshes it in place. The order of the open list is therefore
|
|
67
|
+
// always panels first, then dialogs, which is also the visual order.
|
|
68
|
+
//
|
|
69
|
+
// @param {Element} el the panel node that wants to open.
|
|
70
|
+
// @returns {boolean} whether a dialog (or sheet) is open and el is not already open.
|
|
71
|
+
export function isPanelBlocked(el) {
|
|
72
|
+
if (indexOfModal(el) !== -1) return false;
|
|
73
|
+
return modals.some(function (c) { return !c.panel; });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// The modal Escape and the page's own dismissal act on. A panel is on a lower
|
|
77
|
+
// layer than a dialog (--z-panel under --z-modal), so a dialog opened from a
|
|
78
|
+
// panel is the one the operator sees on top, whichever opened last: it takes the
|
|
79
|
+
// key first.
|
|
80
|
+
function topModalEntry() {
|
|
81
|
+
for (var i = modals.length - 1; i >= 0; i--) if (!modals[i].panel) return modals[i];
|
|
82
|
+
return modals.length ? modals[modals.length - 1] : null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function finishModal(c) {
|
|
86
|
+
if (c.retain) c.el.classList.add("hidden");
|
|
87
|
+
else c.el.remove();
|
|
88
|
+
if (c.exit) c.el.classList.remove(c.exit.className);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Passive notices (a transient popover such as the rate-limit notice): outside
|
|
92
|
+
// the one-open stack, so showing one never closes the menu the user has open.
|
|
93
|
+
// Each: { el, opener, onClose, retain, doc }.
|
|
94
|
+
var passives = [];
|
|
95
|
+
|
|
96
|
+
function release(c) {
|
|
97
|
+
if (c.retain) c.el.classList.add("hidden");
|
|
98
|
+
else c.el.remove();
|
|
99
|
+
if (c.onClose) c.onClose(c.el);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Close the innermost menu. Its close hook may open or close others.
|
|
103
|
+
function finishTop() {
|
|
104
|
+
var c = stack.pop();
|
|
105
|
+
if (!c) return;
|
|
106
|
+
release(c);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function finishPassive(el) {
|
|
110
|
+
for (var i = 0; i < passives.length; i++) {
|
|
111
|
+
if (passives[i].el === el) {
|
|
112
|
+
release(passives.splice(i, 1)[0]);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// A click outside a passive notice and its opener closes it.
|
|
119
|
+
function closePassivesForClick(target) {
|
|
120
|
+
passives.slice().forEach(function (c) {
|
|
121
|
+
if (target && (c.el.contains(target) || (c.opener && c.opener.contains(target)))) return;
|
|
122
|
+
finishPassive(c.el);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Close every menu from the innermost down to, and including, stack[index]. The
|
|
127
|
+
// set to close is taken off the stack before any close hook runs, so a menu a
|
|
128
|
+
// hook opens is not part of this pass and stays open.
|
|
129
|
+
function finishFrom(index) {
|
|
130
|
+
var closing = stack.splice(index);
|
|
131
|
+
while (closing.length) release(closing.pop());
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function onDocumentClick(e) {
|
|
135
|
+
var target = e && e.target;
|
|
136
|
+
closePassivesForClick(target);
|
|
137
|
+
if (!stack.length) return;
|
|
138
|
+
if (!target) { finishFrom(0); return; }
|
|
139
|
+
// The innermost menu the click is in, or on the opener of: that menu and the
|
|
140
|
+
// ones around it stay; the ones it owns close.
|
|
141
|
+
var keep = -1;
|
|
142
|
+
for (var i = stack.length - 1; i >= 0; i--) {
|
|
143
|
+
var c = stack[i];
|
|
144
|
+
// The opener toggles its own menu; closing here too would reopen it.
|
|
145
|
+
if (c.el.contains(target) || (c.opener && c.opener.contains(target))) { keep = i; break; }
|
|
146
|
+
}
|
|
147
|
+
finishFrom(keep + 1);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function onDocumentKeydown(e) {
|
|
151
|
+
if (!e || e.key !== "Escape") return;
|
|
152
|
+
// A menu is opened from the surface under it, so it yields first: Escape closes
|
|
153
|
+
// the open menu, then the top modal, and a passive notice only when neither is
|
|
154
|
+
// open.
|
|
155
|
+
if (!stack.length) {
|
|
156
|
+
if (modals.length) {
|
|
157
|
+
var topModal = topModalEntry();
|
|
158
|
+
// As for a menu: a modal with something inside to step back from (a detail
|
|
159
|
+
// view over a list) takes the key, and returning true leaves it open.
|
|
160
|
+
if (topModal.onEscape && topModal.onEscape(e) === true) return;
|
|
161
|
+
dismissModal(topModal.el);
|
|
162
|
+
} else if (passives.length) finishPassive(passives[passives.length - 1].el);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
var top = stack[stack.length - 1];
|
|
166
|
+
// A surface with something inside to dismiss first (an open accordion) takes
|
|
167
|
+
// the key; returning true leaves the menu open.
|
|
168
|
+
if (top.onEscape && top.onEscape(e) === true) return;
|
|
169
|
+
finishTop();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function wire(doc) {
|
|
173
|
+
if (wired.has(doc)) return;
|
|
174
|
+
wired.add(doc);
|
|
175
|
+
// Capture: a menu's opener or an item may stop the click from bubbling.
|
|
176
|
+
doc.addEventListener("click", onDocumentClick, true);
|
|
177
|
+
doc.addEventListener("keydown", onDocumentKeydown);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Make an element the open menu, closing any other. Opening the one that is
|
|
182
|
+
* already open only refreshes its options.
|
|
183
|
+
*
|
|
184
|
+
* @param {Element} el
|
|
185
|
+
* @param {object} [opts]
|
|
186
|
+
* @param {Element} [opts.opener] the control that opens it; a click on it is not
|
|
187
|
+
* an outside click.
|
|
188
|
+
* @param {Element} [opts.parent] the open menu this one belongs to (a dropdown
|
|
189
|
+
* inside a popover): opening it leaves that menu open, a click inside the
|
|
190
|
+
* parent but outside this one closes only this one, and closing the parent
|
|
191
|
+
* closes this one. A parent that is not open counts as no parent: the menu is
|
|
192
|
+
* top-level and closes every other open menu (one-open).
|
|
193
|
+
* @param {boolean} [opts.retain] close by adding "hidden" and keep the element
|
|
194
|
+
* (a node that lives in the page); absent, closing removes it.
|
|
195
|
+
* @param {function(Element)} [opts.onClose] called once when it closes, however.
|
|
196
|
+
* @param {function(Event): boolean} [opts.onEscape] called on Escape while this
|
|
197
|
+
* is the innermost menu; returning true means the key was spent on something
|
|
198
|
+
* inside it and the menu stays open.
|
|
199
|
+
* @param {boolean} [opts.inputList] an input autocomplete list (input-list-menu.js):
|
|
200
|
+
* it claims Escape for its text box, so opening a modal closes it (openModal),
|
|
201
|
+
* which keeps a list from sitting above a modal and blocking its Escape.
|
|
202
|
+
* @param {boolean} [opts.passive] a transient notice, not a menu the user opened:
|
|
203
|
+
* it is kept outside the one-open stack, so showing it closes nothing and an
|
|
204
|
+
* open menu stays open. It still closes on an outside click, and on Escape when
|
|
205
|
+
* no menu is open.
|
|
206
|
+
* @param {Document} [opts.doc] defaults to the page's document.
|
|
207
|
+
*/
|
|
208
|
+
export function openMenu(el, opts) {
|
|
209
|
+
var o = opts || {};
|
|
210
|
+
var doc = o.doc || document;
|
|
211
|
+
var entry = { el: el, opener: o.opener || null, onClose: o.onClose || null, onEscape: o.onEscape || null, retain: !!o.retain, inputList: !!o.inputList, doc: doc };
|
|
212
|
+
if (o.passive) {
|
|
213
|
+
finishPassive(el);
|
|
214
|
+
passives.push(entry);
|
|
215
|
+
wire(doc);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
var at = indexOf(el);
|
|
219
|
+
if (at !== -1) {
|
|
220
|
+
// Refresh in place; whatever it owns is closed so it starts clean.
|
|
221
|
+
finishFrom(at + 1);
|
|
222
|
+
stack[at] = entry;
|
|
223
|
+
} else {
|
|
224
|
+
var parentAt = o.parent ? indexOf(o.parent) : -1;
|
|
225
|
+
finishFrom(parentAt + 1);
|
|
226
|
+
stack.push(entry);
|
|
227
|
+
}
|
|
228
|
+
wire(doc);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Close a menu if it is open, and the menus it owns. Safe to call twice, or for
|
|
233
|
+
* a menu that a later one already replaced.
|
|
234
|
+
* @param {Element} el
|
|
235
|
+
*/
|
|
236
|
+
export function closeMenu(el) {
|
|
237
|
+
var at = indexOf(el);
|
|
238
|
+
if (at !== -1) finishFrom(at);
|
|
239
|
+
else finishPassive(el);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Close whichever menus are open. */
|
|
243
|
+
export function closeOpenMenu() {
|
|
244
|
+
finishFrom(0);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* @param {Element} el
|
|
249
|
+
* @returns {boolean} whether it is open.
|
|
250
|
+
*/
|
|
251
|
+
export function isMenuOpen(el) {
|
|
252
|
+
return indexOf(el) !== -1 || passives.some(function (c) { return c.el === el; });
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** @returns {?Element} the innermost open menu. */
|
|
256
|
+
export function getOpenMenu() {
|
|
257
|
+
return stack.length ? stack[stack.length - 1].el : null;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Make an element an open modal or sheet, on top of the others. Opening one that
|
|
262
|
+
* is already open refreshes its options and keeps its place; opening one that is
|
|
263
|
+
* leaving cancels the exit.
|
|
264
|
+
*
|
|
265
|
+
* @param {Element} el
|
|
266
|
+
* @param {object} [opts]
|
|
267
|
+
* @param {function(Element)} [opts.onClose] called once when it closes, however.
|
|
268
|
+
* @param {function(Element)} [opts.onDismiss] called when the operator closed it
|
|
269
|
+
* (Escape, the backdrop or the close control), after it closed.
|
|
270
|
+
* @param {boolean} [opts.dismissible=true] false: Escape and dismissModal leave it.
|
|
271
|
+
* @param {function(Event): boolean} [opts.onEscape] called on Escape while this is
|
|
272
|
+
* the top modal; returning true means the key was spent on something inside it
|
|
273
|
+
* and the modal stays open.
|
|
274
|
+
* @param {boolean} [opts.retain] close by adding "hidden" and keep the node.
|
|
275
|
+
* @param {{className: string, ms: number}} [opts.exit] a class that plays the exit
|
|
276
|
+
* animation; the node is hidden or removed after ms.
|
|
277
|
+
* @param {boolean} [opts.panel] a panel (overlay-modal.js): it sits on the panel
|
|
278
|
+
* layer under the dialogs, and Escape closes a dialog before it.
|
|
279
|
+
* @param {boolean} [opts.held] the panel holds an entry in the browser history
|
|
280
|
+
* (overlay-history.js), so a back swipe closes it (closeHeldPanel).
|
|
281
|
+
* @param {Document} [opts.doc] defaults to the page's document.
|
|
282
|
+
*/
|
|
283
|
+
export function openModal(el, opts) {
|
|
284
|
+
var o = opts || {};
|
|
285
|
+
var doc = o.doc || document;
|
|
286
|
+
var pending = exiting.get(el);
|
|
287
|
+
if (pending) {
|
|
288
|
+
clearTimeout(pending.timer);
|
|
289
|
+
exiting.delete(el);
|
|
290
|
+
if (pending.entry.exit) el.classList.remove(pending.entry.exit.className);
|
|
291
|
+
}
|
|
292
|
+
var entry = {
|
|
293
|
+
el: el, onClose: o.onClose || null, onDismiss: o.onDismiss || null, onEscape: o.onEscape || null, dismissible: o.dismissible !== false,
|
|
294
|
+
retain: !!o.retain, exit: o.exit || null, panel: !!o.panel, held: !!o.held, doc: doc,
|
|
295
|
+
};
|
|
296
|
+
// An input list claims every Escape while it is the innermost menu, so one left
|
|
297
|
+
// open under a modal would make the modal impossible to dismiss from the keyboard.
|
|
298
|
+
// Ordinary menus are left as they are.
|
|
299
|
+
for (var i = 0; i < stack.length; i++) {
|
|
300
|
+
if (stack[i].inputList) { finishFrom(i); break; }
|
|
301
|
+
}
|
|
302
|
+
var at = indexOfModal(el);
|
|
303
|
+
if (at !== -1) modals[at] = entry;
|
|
304
|
+
else modals.push(entry);
|
|
305
|
+
numberModals();
|
|
306
|
+
wire(doc);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Close a modal if it is open. Safe to call twice.
|
|
311
|
+
* @param {Element} el
|
|
312
|
+
* @param {object} [opts]
|
|
313
|
+
* @param {boolean} [opts.immediate] skip the exit animation.
|
|
314
|
+
*/
|
|
315
|
+
export function closeModal(el, opts) {
|
|
316
|
+
var at = indexOfModal(el);
|
|
317
|
+
if (at === -1) return;
|
|
318
|
+
var c = modals.splice(at, 1)[0];
|
|
319
|
+
numberModals();
|
|
320
|
+
if (c.exit && !(opts && opts.immediate)) {
|
|
321
|
+
c.el.classList.add(c.exit.className);
|
|
322
|
+
exiting.set(c.el, {
|
|
323
|
+
entry: c,
|
|
324
|
+
timer: setTimeout(function () { exiting.delete(c.el); finishModal(c); }, c.exit.ms),
|
|
325
|
+
});
|
|
326
|
+
} else {
|
|
327
|
+
finishModal(c);
|
|
328
|
+
}
|
|
329
|
+
if (c.onClose) c.onClose(c.el);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* The operator closes a modal (Escape, the backdrop, the close control): it
|
|
334
|
+
* closes and its dismiss hook runs. A modal that is not dismissible stays.
|
|
335
|
+
* @param {Element} el
|
|
336
|
+
*/
|
|
337
|
+
export function dismissModal(el) {
|
|
338
|
+
var at = indexOfModal(el);
|
|
339
|
+
if (at === -1 || !modals[at].dismissible) return;
|
|
340
|
+
var c = modals[at];
|
|
341
|
+
closeModal(el);
|
|
342
|
+
if (c.onDismiss) c.onDismiss(c.el);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* The browser's back (a phone back swipe) first closes what is on top of the
|
|
347
|
+
* overlays that hold history entries: an open menu, else the topmost modal only.
|
|
348
|
+
* A dismissible dialog is dismissed (its dismiss hook runs); a dialog that is not
|
|
349
|
+
* dismissible closes nothing and still counts as handled, so back is blocked.
|
|
350
|
+
* Neither holds an entry, so the caller restores the one the browser popped
|
|
351
|
+
* (overlay-history.js restoreOverlayState). A panel on top is left to the caller's
|
|
352
|
+
* owner routing. Nothing below the top modal is ever reached.
|
|
353
|
+
* @returns {boolean} whether a menu or a dialog took the back; false when the top
|
|
354
|
+
* modal is a panel or there is none.
|
|
355
|
+
*/
|
|
356
|
+
export function closeTopBlockingOverlay() {
|
|
357
|
+
if (stack.length) {
|
|
358
|
+
finishTop();
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
if (!modals.length) return false;
|
|
362
|
+
var top = modals[modals.length - 1];
|
|
363
|
+
if (top.panel) return false;
|
|
364
|
+
if (top.dismissible) dismissModal(top.el);
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* The browser's back closes the panel that owns the newest history entry, when it
|
|
370
|
+
* is on top; the operator dismissed it, so its dismiss hook runs.
|
|
371
|
+
* @param {Element} el the panel node that owns the entry.
|
|
372
|
+
* @returns {boolean} whether the panel was closed.
|
|
373
|
+
*/
|
|
374
|
+
export function closeHeldPanel(el) {
|
|
375
|
+
var at = indexOfModal(el);
|
|
376
|
+
if (at === -1 || !modals[at].panel || !modals[at].held || !modals[at].dismissible) return false;
|
|
377
|
+
dismissModal(el);
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* @param {Element} el
|
|
383
|
+
* @returns {boolean} whether it is an open modal.
|
|
384
|
+
*/
|
|
385
|
+
export function isModalOpen(el) {
|
|
386
|
+
return indexOfModal(el) !== -1;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/** @returns {?Element} the top open modal. */
|
|
390
|
+
export function getTopModal() {
|
|
391
|
+
return modals.length ? modals[modals.length - 1].el : null;
|
|
392
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// overlay-stack.js - the one stacking manager for toasts and banners.
|
|
2
|
+
//
|
|
3
|
+
// Every toast and banner is a child of one container (css/overlay.css gives it
|
|
4
|
+
// a fixed column), so two of them can never share a spot: placement is the
|
|
5
|
+
// flow of that column, not a per-surface position. The manager owns the
|
|
6
|
+
// container, where a card goes in it, when a card leaves, and the lookups a
|
|
7
|
+
// surface needs to replace or clear its own cards.
|
|
8
|
+
|
|
9
|
+
var STACK_ID = "overlay-stack";
|
|
10
|
+
// Matches the exit transition in css/overlay.css.
|
|
11
|
+
var EXIT_MS = 300;
|
|
12
|
+
|
|
13
|
+
// Per card: its auto-dismiss timer, its removal hook, and whether it is leaving.
|
|
14
|
+
var records = new WeakMap();
|
|
15
|
+
var cached = null;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The stack container, created on first use.
|
|
19
|
+
* @param {Document} [doc] defaults to the page's document.
|
|
20
|
+
* @returns {Element}
|
|
21
|
+
*/
|
|
22
|
+
export function getStack(doc) {
|
|
23
|
+
var d = doc || document;
|
|
24
|
+
var found = d.getElementById(STACK_ID);
|
|
25
|
+
if (found) { cached = found; return found; }
|
|
26
|
+
if (cached && cached.parentNode === d.body) return cached;
|
|
27
|
+
var el = d.createElement("div");
|
|
28
|
+
el.id = STACK_ID;
|
|
29
|
+
el.className = "overlay-stack";
|
|
30
|
+
d.body.appendChild(el);
|
|
31
|
+
cached = el;
|
|
32
|
+
return el;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Put a card in the stack.
|
|
37
|
+
* @param {Element} el
|
|
38
|
+
* @param {object} [opts]
|
|
39
|
+
* @param {Document} [opts.doc]
|
|
40
|
+
* @param {boolean} [opts.first] top of the stack instead of the bottom.
|
|
41
|
+
* @param {?number} [opts.timeout] ms until it leaves by itself; null or absent stays.
|
|
42
|
+
* @param {?string} [opts.group] a name surfaces clear their cards by (clearGroup).
|
|
43
|
+
* @param {function(Element)} [opts.onRemove] called once, when it starts to leave.
|
|
44
|
+
*/
|
|
45
|
+
export function addToStack(el, opts) {
|
|
46
|
+
var o = opts || {};
|
|
47
|
+
var stack = getStack(o.doc);
|
|
48
|
+
var record = { timer: null, onRemove: o.onRemove || null, removing: false };
|
|
49
|
+
records.set(el, record);
|
|
50
|
+
if (o.group) el.setAttribute("data-overlay-group", o.group);
|
|
51
|
+
if (o.first) stack.insertBefore(el, stack.firstChild);
|
|
52
|
+
else stack.appendChild(el);
|
|
53
|
+
if (typeof o.timeout === "number") {
|
|
54
|
+
record.timer = setTimeout(function () { removeFromStack(el); }, o.timeout);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Take a card out: it fades, then goes. Safe to call twice.
|
|
60
|
+
* @param {Element} el
|
|
61
|
+
*/
|
|
62
|
+
export function removeFromStack(el) {
|
|
63
|
+
if (!el || !el.parentNode) return;
|
|
64
|
+
var record = records.get(el);
|
|
65
|
+
if (record) {
|
|
66
|
+
if (record.removing) return;
|
|
67
|
+
record.removing = true;
|
|
68
|
+
clearTimeout(record.timer);
|
|
69
|
+
}
|
|
70
|
+
el.classList.remove("visible");
|
|
71
|
+
el.classList.add("hide");
|
|
72
|
+
if (record && record.onRemove) record.onRemove(el);
|
|
73
|
+
setTimeout(function () {
|
|
74
|
+
if (el.parentNode) el.parentNode.removeChild(el);
|
|
75
|
+
}, EXIT_MS);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Take every card of one group out at once, with no fade, as a surface does when
|
|
80
|
+
* it redraws all of its cards.
|
|
81
|
+
* @param {string} group
|
|
82
|
+
* @param {Document} [doc]
|
|
83
|
+
*/
|
|
84
|
+
export function clearGroup(group, doc) {
|
|
85
|
+
var stack = getStack(doc);
|
|
86
|
+
var gone = stack.querySelectorAll('[data-overlay-group="' + group + '"]');
|
|
87
|
+
var hooks = [];
|
|
88
|
+
for (var i = 0; i < gone.length; i++) {
|
|
89
|
+
var record = records.get(gone[i]);
|
|
90
|
+
if (record) {
|
|
91
|
+
clearTimeout(record.timer);
|
|
92
|
+
record.removing = true;
|
|
93
|
+
if (record.onRemove) hooks.push([record.onRemove, gone[i]]);
|
|
94
|
+
}
|
|
95
|
+
if (gone[i].parentNode) gone[i].parentNode.removeChild(gone[i]);
|
|
96
|
+
}
|
|
97
|
+
// After every card is out, so a hook that counts the stack sees the end state.
|
|
98
|
+
hooks.forEach(function (h) { h[0](h[1]); });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The cards a surface raised under one source key, or under any when none is given.
|
|
103
|
+
* @param {string} [source]
|
|
104
|
+
* @param {Document} [doc]
|
|
105
|
+
* @returns {Element[]}
|
|
106
|
+
*/
|
|
107
|
+
export function cardsBySource(source, doc) {
|
|
108
|
+
var sel = source === undefined ? "[data-overlay-source]" : '[data-overlay-source="' + source + '"]';
|
|
109
|
+
return Array.prototype.slice.call(getStack(doc).querySelectorAll(sel));
|
|
110
|
+
}
|