@firstpick/pi-package-webui 0.11.0 → 0.11.2
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/DEVELOPMENT.md +181 -12
- package/README.md +41 -9
- package/TECHNICAL.md +91 -8
- package/bin/pi-webui.mjs +5432 -11428
- package/index.ts +10 -3
- package/lib/codex-cli-usage.mjs +232 -0
- package/lib/codex-usage-auth.mjs +39 -3
- package/lib/codex-usage-source.mjs +36 -0
- package/lib/component-update-state.mjs +2 -2
- package/lib/git-workflow-preference-values.mjs +122 -0
- package/lib/git-workflow-preferences.mjs +35 -563
- package/lib/package-updates.mjs +260 -0
- package/lib/rpc-supervisor-client.mjs +8 -4
- package/lib/server/app-runners.mjs +1667 -0
- package/lib/server/codex-fast-mode.mjs +161 -0
- package/lib/server/conversation-mode.mjs +218 -0
- package/lib/server/conversation-voice.mjs +318 -0
- package/lib/server/extension-ui-requests.mjs +114 -0
- package/lib/server/git-generation.mjs +459 -0
- package/lib/server/git-mutations.mjs +1827 -0
- package/lib/server/git-reads.mjs +608 -0
- package/lib/server/git-worktree-sessions.mjs +408 -0
- package/lib/server/helper-requests.mjs +82 -0
- package/lib/server/no-project-workspaces.mjs +103 -0
- package/lib/server/rpc-transports.mjs +394 -0
- package/lib/server/settings-store.mjs +544 -0
- package/lib/server/sse-delivery.mjs +138 -0
- package/lib/server/workspace-files.mjs +563 -0
- package/lib/update/supervisor.mjs +4 -0
- package/lib/webui-workspaces.mjs +2 -0
- package/package.json +5 -5
- package/public/activity-agents-controller.mjs +269 -0
- package/public/activity-events-controller.mjs +236 -0
- package/public/activity-intercom-controller.mjs +627 -0
- package/public/activity-queue-controller.mjs +534 -0
- package/public/activity-todo-view.mjs +89 -0
- package/public/activity-usage-controller.mjs +589 -0
- package/public/app.js +3761 -3878
- package/public/conversation-overview.css +84 -0
- package/public/conversation-overview.mjs +193 -0
- package/public/draft-conversations.mjs +135 -0
- package/public/focused-composer-controls.css +111 -0
- package/public/focused-composer-controls.mjs +143 -0
- package/public/focused-composer-disclosure.mjs +223 -0
- package/public/focused-shell-adapter.css +264 -0
- package/public/focused-shell-adapter.mjs +257 -0
- package/public/index.html +137 -80
- package/public/model-catalog-order.mjs +63 -0
- package/public/platform-event-stream.mjs +64 -0
- package/public/project-artifact-controller.mjs +218 -0
- package/public/project-file-viewer-controller.mjs +383 -0
- package/public/project-git-tools-controller.mjs +181 -0
- package/public/project-runners-controller.mjs +220 -0
- package/public/service-worker.js +52 -1
- package/public/session-attention-scheduler.mjs +182 -0
- package/public/session-composer-store.mjs +56 -0
- package/public/session-context.mjs +51 -0
- package/public/session-extension-requests.mjs +63 -0
- package/public/session-shelf-state.mjs +151 -0
- package/public/session-shelves.css +171 -0
- package/public/session-shelves.mjs +95 -0
- package/public/settings-navigation-controller.mjs +249 -0
- package/public/settings-navigation.css +61 -0
- package/public/settings-resource-controller.mjs +232 -0
- package/public/settings-workspace.css +19 -0
- package/public/settings-workspace.mjs +175 -0
- package/public/shell-actions.mjs +87 -0
- package/public/shell-attention-inbox.css +72 -0
- package/public/shell-attention-inbox.mjs +198 -0
- package/public/shell-context-actions.css +61 -0
- package/public/shell-context-actions.mjs +168 -0
- package/public/shell-inspector-resize.mjs +124 -0
- package/public/shell-navigation-resize.mjs +107 -0
- package/public/shell-navigation.mjs +127 -0
- package/public/shell-preferences.mjs +108 -0
- package/public/shell-surfaces.mjs +99 -0
- package/public/shell-tools-launcher.css +97 -0
- package/public/shell-tools-launcher.mjs +222 -0
- package/public/shell-view-host.mjs +115 -0
- package/public/shell-workspace.css +266 -0
- package/public/shell-workspace.mjs +402 -0
- package/public/sidebar-update-menu.css +190 -0
- package/public/sidebar-update-menu.mjs +512 -0
- package/public/styles.css +320 -169
- package/public/subagent-launch-slot-state.mjs +2 -2
- package/public/theme-contract.mjs +1 -1
- package/public/themed-selects.css +156 -0
- package/public/workspace-choices.mjs +104 -0
- package/tests/activity-agents-controller.test.mjs +652 -0
- package/tests/activity-events-controller.test.mjs +511 -0
- package/tests/app-runner-terminal-static.test.mjs +3 -3
- package/tests/append-system-http.test.mjs +7 -6
- package/tests/append-system-selector-static.test.mjs +6 -6
- package/tests/aur-review-widget-static.test.mjs +11 -3
- package/tests/boot-failure-diagnostics.test.mjs +8 -3
- package/tests/browser/activity-intercom-controller.spec.mjs +457 -0
- package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
- package/tests/browser/activity-owner-integration.spec.mjs +201 -0
- package/tests/browser/activity-queue-controller.spec.mjs +405 -0
- package/tests/browser/activity-section-picker.spec.mjs +294 -0
- package/tests/browser/activity-todo-view.spec.mjs +60 -0
- package/tests/browser/activity-usage-controller.spec.mjs +416 -0
- package/tests/browser/compact-layout-integration.spec.mjs +58 -0
- package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
- package/tests/browser/composer-disclosure.spec.mjs +389 -0
- package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
- package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
- package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
- package/tests/browser/control-visibility.spec.mjs +5 -0
- package/tests/browser/controls-layout.spec.mjs +21 -2
- package/tests/browser/conversation-overview.spec.mjs +251 -0
- package/tests/browser/draft-conversations.spec.mjs +276 -0
- package/tests/browser/empty-startup-fixture.mjs +135 -0
- package/tests/browser/empty-startup.spec.mjs +282 -0
- package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
- package/tests/browser/focused-composer-more.spec.mjs +127 -0
- package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
- package/tests/browser/focused-navigation-fixture.mjs +32 -0
- package/tests/browser/focused-project-activity.spec.mjs +111 -0
- package/tests/browser/focused-shell-integration.spec.mjs +208 -0
- package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
- package/tests/browser/folder-picker-layout.spec.mjs +302 -0
- package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
- package/tests/browser/git-setup-cancel.spec.mjs +251 -0
- package/tests/browser/guided-git-fallback.spec.mjs +40 -21
- package/tests/browser/inspector-header.spec.mjs +221 -0
- package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
- package/tests/browser/inspector-resize.spec.mjs +227 -0
- package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
- package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
- package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
- package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
- package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
- package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
- package/tests/browser/interaction-continuity.spec.mjs +50 -26
- package/tests/browser/interaction-model-picker.spec.mjs +86 -0
- package/tests/browser/last-terminal-close.spec.mjs +280 -0
- package/tests/browser/mobile-foundation.spec.mjs +172 -20
- package/tests/browser/model-catalog-groups.spec.mjs +104 -0
- package/tests/browser/more-row-menus.spec.mjs +258 -0
- package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
- package/tests/browser/no-project-conversation.spec.mjs +113 -0
- package/tests/browser/optimistic-prompt.spec.mjs +3 -0
- package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
- package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
- package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
- package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
- package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
- package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
- package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
- package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
- package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
- package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
- package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
- package/tests/browser/project-artifact-controller.spec.mjs +324 -0
- package/tests/browser/project-artifact-integration.spec.mjs +103 -0
- package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
- package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
- package/tests/browser/session-fixture.mjs +118 -0
- package/tests/browser/session-ownership.spec.mjs +175 -0
- package/tests/browser/session-shelves-integration.spec.mjs +219 -0
- package/tests/browser/session-shelves.spec.mjs +340 -0
- package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
- package/tests/browser/session-summary.spec.mjs +17 -12
- package/tests/browser/settings-complete-home.spec.mjs +463 -0
- package/tests/browser/settings-entrypoint.spec.mjs +104 -0
- package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
- package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
- package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
- package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
- package/tests/browser/shell-ownership.spec.mjs +398 -0
- package/tests/browser/shell-rollout-fixture.mjs +259 -0
- package/tests/browser/shell-rollout.spec.mjs +357 -0
- package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
- package/tests/browser/shell-workspace.spec.mjs +433 -0
- package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
- package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
- package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
- package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
- package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
- package/tests/browser/stream-output-isolation.spec.mjs +6 -3
- package/tests/browser/themed-selects.spec.mjs +297 -0
- package/tests/browser/thread-start-flow.spec.mjs +481 -0
- package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
- package/tests/browser/ui-polish-features.spec.mjs +85 -0
- package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
- package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
- package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
- package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
- package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
- package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
- package/tests/browser/windows-drive-parent.spec.mjs +4 -2
- package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
- package/tests/codex-cli-usage.test.mjs +189 -0
- package/tests/codex-fast-mode-static.test.mjs +16 -11
- package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
- package/tests/codex-usage-auth.test.mjs +168 -9
- package/tests/codex-usage-http.test.mjs +124 -0
- package/tests/codex-usage-source.test.mjs +146 -0
- package/tests/component-update-api-static.test.mjs +2 -2
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-deck-component-updates-static.test.mjs +9 -4
- package/tests/control-visibility-static.test.mjs +3 -3
- package/tests/controls-layout-static.test.mjs +5 -5
- package/tests/conversation-overview-adapter.test.mjs +100 -0
- package/tests/document-artifact-static.test.mjs +2 -1
- package/tests/draft-conversations.test.mjs +205 -0
- package/tests/empty-startup-launcher.test.mjs +197 -0
- package/tests/events-tree-context-menu-static.test.mjs +22 -18
- package/tests/fake-pi-session-ownership.test.mjs +302 -0
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
- package/tests/file-viewer-image-static.test.mjs +15 -11
- package/tests/file-viewer-search-static.test.mjs +5 -5
- package/tests/fixtures/fake-codex-app-server.mjs +61 -0
- package/tests/fixtures/fake-pi.mjs +41 -9
- package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
- package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
- package/tests/git-footer-context-menu-static.test.mjs +1 -1
- package/tests/git-panel-file-preview-static.test.mjs +41 -48
- package/tests/git-panel-live-updates-static.test.mjs +2 -1
- package/tests/git-workflow-dispatch.test.mjs +66 -0
- package/tests/git-workflow-preferences.test.mjs +9 -1
- package/tests/guided-git-activation-static.test.mjs +14 -11
- package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
- package/tests/guided-git-message-reliability-static.test.mjs +10 -6
- package/tests/guided-git-publication-backend-static.test.mjs +16 -11
- package/tests/http-endpoints-harness.test.mjs +29 -9
- package/tests/interaction-state-stability-static.test.mjs +4 -3
- package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
- package/tests/intercom-tag-layout-static.test.mjs +13 -12
- package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
- package/tests/main-output-loading-static.test.mjs +4 -4
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-compact-layout.test.mjs +2 -2
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +10 -7
- package/tests/mobile-phone-experience-static.test.mjs +3 -2
- package/tests/mobile-static.test.mjs +173 -135
- package/tests/model-catalog-order.test.mjs +103 -0
- package/tests/native-parity.test.mjs +6 -4
- package/tests/native-session-choice-owner.test.mjs +102 -0
- package/tests/native-update-lifecycle.test.mjs +10 -5
- package/tests/no-project-http-harness.test.mjs +328 -0
- package/tests/no-project-navigation.test.mjs +54 -0
- package/tests/no-project-workspaces.test.mjs +77 -0
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-migration-frontend.test.mjs +4 -4
- package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
- package/tests/package-updates.test.mjs +630 -0
- package/tests/persistent-ui-layout-static.test.mjs +3 -3
- package/tests/platform-event-stream.test.mjs +253 -0
- package/tests/project-file-viewer-controller.test.mjs +652 -0
- package/tests/project-git-tools-adapter.test.mjs +103 -0
- package/tests/project-git-tools-controller.test.mjs +577 -0
- package/tests/project-runners-controller.test.mjs +453 -0
- package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
- package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
- package/tests/questionnaire-dialog.test.mjs +6 -6
- package/tests/queue-edit-reorder-static.test.mjs +48 -51
- package/tests/rpc-supervisor-host.test.mjs +4 -1
- package/tests/safety-guard-auto-review-static.test.mjs +1 -1
- package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
- package/tests/server-app-runners.test.mjs +536 -0
- package/tests/server-codex-fast-mode.test.mjs +346 -0
- package/tests/server-conversation-mode.test.mjs +386 -0
- package/tests/server-conversation-voice.test.mjs +426 -0
- package/tests/server-extension-ui-requests.test.mjs +357 -0
- package/tests/server-git-generation.test.mjs +558 -0
- package/tests/server-git-mutations.test.mjs +729 -0
- package/tests/server-git-reads.test.mjs +381 -0
- package/tests/server-git-worktree-sessions.test.mjs +502 -0
- package/tests/server-helper-requests.test.mjs +364 -0
- package/tests/server-rpc-transports.test.mjs +553 -0
- package/tests/server-settings-store.test.mjs +132 -0
- package/tests/server-shell-rollout.test.mjs +478 -0
- package/tests/server-sse-delivery.test.mjs +410 -0
- package/tests/server-workspace-files.test.mjs +546 -0
- package/tests/session-attention-scheduler.test.mjs +514 -0
- package/tests/session-composer-store.test.mjs +153 -0
- package/tests/session-context.test.mjs +134 -0
- package/tests/session-extension-requests.test.mjs +193 -0
- package/tests/session-ownership-adapter.test.mjs +130 -0
- package/tests/session-sampling-ui-static.test.mjs +10 -4
- package/tests/session-send-lifetime.test.mjs +140 -0
- package/tests/session-shelf-state.test.mjs +348 -0
- package/tests/session-shelves-adapter.test.mjs +79 -0
- package/tests/session-summary-lifetime.test.mjs +54 -0
- package/tests/settings-resource-controller.test.mjs +548 -0
- package/tests/shell-action-adapter.test.mjs +169 -0
- package/tests/shell-actions.test.mjs +182 -0
- package/tests/shell-navigation.test.mjs +348 -0
- package/tests/shell-preferences.test.mjs +367 -0
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/stream-output-isolation-static.test.mjs +1 -1
- package/tests/subagent-gate-visibility.test.mjs +1 -1
- package/tests/subagent-launch-slot-state.test.mjs +2 -2
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/subagent-reliability-integration.test.mjs +13 -30
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- package/tests/tab-close-continuity-static.test.mjs +1 -1
- package/tests/tab-metadata-ordering.test.mjs +99 -0
- package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
- package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
- package/tests/terminal-tab-workspace-static.test.mjs +5 -4
- package/tests/terminal-tabs-resize-static.test.mjs +1 -1
- package/tests/theme-contract.test.mjs +10 -3
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/thread-display-title.test.mjs +44 -0
- package/tests/update-api-harness.test.mjs +15 -14
- package/tests/update-tab-restore-harness.test.mjs +3 -0
- package/tests/webui-settings-locking.test.mjs +2 -2
- package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
- package/tests/workspace-choices.test.mjs +114 -0
- package/tests/workspace-save-load-static.test.mjs +7 -4
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
export const SIDEBAR_UPDATE_ICON = '<svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 7v5h-5"/><path d="M4 17v-5h5"/><path d="M6.1 7a7 7 0 0 1 11.6-1L20 9M4 15l2.3 3A7 7 0 0 0 17.9 17"/></svg>';
|
|
2
|
+
|
|
3
|
+
const CHOICES = [
|
|
4
|
+
['all', 'Pi and extensions + WebUI', 'Update Pi, extensions and WebUI.'],
|
|
5
|
+
['webui', 'WebUI only', 'Update existing WebUI installations.'],
|
|
6
|
+
['pi', 'Pi only', 'Update the Pi coding agent.'],
|
|
7
|
+
];
|
|
8
|
+
const PROGRESS_STATES = ['launching', 'running', 'success', 'unchanged', 'partial', 'failed', 'unknown'];
|
|
9
|
+
const RUNNING_STATES = ['launching', 'running'];
|
|
10
|
+
let nextId = 0;
|
|
11
|
+
|
|
12
|
+
/** Present update scopes. The caller owns discovery and execution. */
|
|
13
|
+
export function createSidebarUpdateMenu({ button, onSelect }) {
|
|
14
|
+
const document = button.ownerDocument;
|
|
15
|
+
const window = document.defaultView;
|
|
16
|
+
const id = `sidebarUpdateMenu${++nextId}`;
|
|
17
|
+
const originalAttributes = new Map(['aria-haspopup', 'aria-expanded', 'aria-controls', 'aria-describedby', 'aria-disabled', 'aria-busy', 'title', 'disabled']
|
|
18
|
+
.map((name) => [name, button.getAttribute(name)]));
|
|
19
|
+
const hadTriggerClass = button.classList.contains('sidebar-update-trigger');
|
|
20
|
+
const lifetime = new window.AbortController();
|
|
21
|
+
const listen = (target, type, handler, options = {}) => target.addEventListener(type, handler, { ...options, signal: lifetime.signal });
|
|
22
|
+
const node = (tag, className, text) => {
|
|
23
|
+
const element = document.createElement(tag);
|
|
24
|
+
element.className = className;
|
|
25
|
+
if (text !== undefined) element.textContent = text;
|
|
26
|
+
return element;
|
|
27
|
+
};
|
|
28
|
+
const setText = (element, text) => {
|
|
29
|
+
if (element.textContent !== text) element.textContent = text;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const popup = node('div', 'sidebar-update-menu');
|
|
33
|
+
popup.id = id;
|
|
34
|
+
popup.hidden = true;
|
|
35
|
+
const usesPopover = typeof popup.showPopover === 'function';
|
|
36
|
+
if (usesPopover) popup.setAttribute('popover', 'manual');
|
|
37
|
+
const title = node('h2', 'sidebar-update-menu-title', 'Updates');
|
|
38
|
+
title.id = `${id}Title`;
|
|
39
|
+
const availability = node('p', 'sidebar-update-menu-availability');
|
|
40
|
+
availability.id = `${id}Availability`;
|
|
41
|
+
const status = node('p', 'sidebar-update-menu-status');
|
|
42
|
+
status.id = `${id}Status`;
|
|
43
|
+
status.setAttribute('role', 'status');
|
|
44
|
+
status.setAttribute('aria-live', 'polite');
|
|
45
|
+
status.setAttribute('aria-atomic', 'true');
|
|
46
|
+
const menu = node('div', 'sidebar-update-menu-choices');
|
|
47
|
+
menu.setAttribute('role', 'menu');
|
|
48
|
+
menu.setAttribute('aria-labelledby', title.id);
|
|
49
|
+
const choices = CHOICES.map(([mode, label, description]) => {
|
|
50
|
+
const item = node('button', 'sidebar-update-menu-choice');
|
|
51
|
+
item.type = 'button';
|
|
52
|
+
item.dataset.mode = mode;
|
|
53
|
+
item.tabIndex = -1;
|
|
54
|
+
item.setAttribute('role', 'menuitem');
|
|
55
|
+
item.setAttribute('aria-label', label);
|
|
56
|
+
const detail = node('span', 'sidebar-update-menu-description', description);
|
|
57
|
+
detail.id = `${id}${mode}Description`;
|
|
58
|
+
item.setAttribute('aria-describedby', detail.id);
|
|
59
|
+
item.append(node('span', 'sidebar-update-menu-label', label), detail);
|
|
60
|
+
menu.append(item);
|
|
61
|
+
return item;
|
|
62
|
+
});
|
|
63
|
+
const returnToProgress = node('button', 'sidebar-update-menu-return', 'Back to progress');
|
|
64
|
+
returnToProgress.type = 'button';
|
|
65
|
+
returnToProgress.hidden = true;
|
|
66
|
+
popup.append(title, availability, status, menu, returnToProgress);
|
|
67
|
+
const card = node('section', 'sidebar-update-progress');
|
|
68
|
+
card.hidden = true;
|
|
69
|
+
card.setAttribute('aria-labelledby', `${id}ProgressTitle`);
|
|
70
|
+
const summary = node('div', 'sidebar-update-progress-summary');
|
|
71
|
+
summary.setAttribute('role', 'status');
|
|
72
|
+
summary.setAttribute('aria-live', 'polite');
|
|
73
|
+
summary.setAttribute('aria-atomic', 'true');
|
|
74
|
+
const progressTitle = node('h2', 'sidebar-update-progress-title');
|
|
75
|
+
progressTitle.id = `${id}ProgressTitle`;
|
|
76
|
+
const progressLabel = node('p', 'sidebar-update-progress-label');
|
|
77
|
+
const result = node('p', 'sidebar-update-progress-result');
|
|
78
|
+
summary.append(progressTitle, progressLabel, result);
|
|
79
|
+
const step = node('p', 'sidebar-update-progress-step');
|
|
80
|
+
const timing = node('p', 'sidebar-update-progress-timing');
|
|
81
|
+
timing.setAttribute('aria-live', 'off');
|
|
82
|
+
const track = node('div', 'sidebar-update-progress-track');
|
|
83
|
+
track.setAttribute('role', 'img');
|
|
84
|
+
const fill = node('div', 'sidebar-update-progress-fill');
|
|
85
|
+
track.append(fill);
|
|
86
|
+
const heuristic = node('p', 'sidebar-update-progress-heuristic', 'Time-based estimate · about 60s per command');
|
|
87
|
+
const output = node('div', 'sidebar-update-progress-output');
|
|
88
|
+
const stdout = node('pre', 'sidebar-update-progress-stdout');
|
|
89
|
+
stdout.setAttribute('aria-label', 'Current command output');
|
|
90
|
+
const stderr = node('pre', 'sidebar-update-progress-stderr');
|
|
91
|
+
stderr.setAttribute('aria-label', 'Current command error output');
|
|
92
|
+
output.append(stdout, stderr);
|
|
93
|
+
const actions = node('div', 'sidebar-update-progress-actions');
|
|
94
|
+
const details = node('button', 'sidebar-update-progress-details', 'Details');
|
|
95
|
+
details.type = 'button';
|
|
96
|
+
details.setAttribute('aria-controls', `${id}Results`);
|
|
97
|
+
details.setAttribute('aria-expanded', 'false');
|
|
98
|
+
const dismiss = node('button', 'sidebar-update-progress-dismiss', 'Dismiss');
|
|
99
|
+
dismiss.type = 'button';
|
|
100
|
+
dismiss.setAttribute('aria-label', 'Dismiss update result');
|
|
101
|
+
const back = node('button', 'sidebar-update-progress-back', 'Back to progress');
|
|
102
|
+
back.type = 'button';
|
|
103
|
+
back.hidden = true;
|
|
104
|
+
actions.append(back, details, dismiss);
|
|
105
|
+
const commandResults = node('div', 'sidebar-update-command-results');
|
|
106
|
+
commandResults.id = `${id}Results`;
|
|
107
|
+
commandResults.hidden = true;
|
|
108
|
+
const resultsTitle = node('h3', 'sidebar-update-results-title', 'Command results');
|
|
109
|
+
commandResults.setAttribute('role', 'group');
|
|
110
|
+
commandResults.setAttribute('aria-label', 'Command results');
|
|
111
|
+
const commands = node('pre', 'sidebar-update-receipts');
|
|
112
|
+
const receipts = node('pre', 'sidebar-update-receipts');
|
|
113
|
+
commandResults.append(resultsTitle, commands, receipts);
|
|
114
|
+
card.append(summary, actions, step, timing, track, heuristic, commandResults, output);
|
|
115
|
+
document.body.append(popup, card);
|
|
116
|
+
button.classList.add('sidebar-update-trigger');
|
|
117
|
+
button.disabled = false;
|
|
118
|
+
button.setAttribute('aria-haspopup', 'menu');
|
|
119
|
+
button.setAttribute('aria-controls', id);
|
|
120
|
+
button.setAttribute('aria-expanded', 'false');
|
|
121
|
+
|
|
122
|
+
let opened = false;
|
|
123
|
+
let showingDetails = false;
|
|
124
|
+
let disposed = false;
|
|
125
|
+
let blocked = false;
|
|
126
|
+
let frame = null;
|
|
127
|
+
let progress = null;
|
|
128
|
+
let dismissedJobId = null;
|
|
129
|
+
let lastJobId = null;
|
|
130
|
+
let timer = null;
|
|
131
|
+
let lastEstimate = 0;
|
|
132
|
+
|
|
133
|
+
function isRunning() {
|
|
134
|
+
return progress && RUNNING_STATES.includes(progress.state);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function positionCard() {
|
|
138
|
+
if (card.hidden || disposed) return;
|
|
139
|
+
const viewport = window.visualViewport;
|
|
140
|
+
const margin = 8;
|
|
141
|
+
const gap = 6;
|
|
142
|
+
const left = (viewport?.offsetLeft ?? 0) + margin;
|
|
143
|
+
const top = (viewport?.offsetTop ?? 0) + margin;
|
|
144
|
+
const right = left + (viewport?.width ?? window.innerWidth) - margin * 2;
|
|
145
|
+
const bottom = top + (viewport?.height ?? window.innerHeight) - margin * 2;
|
|
146
|
+
const anchor = button.getBoundingClientRect();
|
|
147
|
+
const width = Math.max(0, right - left);
|
|
148
|
+
const height = Math.max(0, bottom - top);
|
|
149
|
+
card.style.maxWidth = `${width}px`;
|
|
150
|
+
card.style.maxHeight = `${height}px`;
|
|
151
|
+
const bounds = card.getBoundingClientRect();
|
|
152
|
+
const spaces = [
|
|
153
|
+
{ left, top, width, height: Math.max(0, Math.min(bottom, anchor.top - gap) - top), side: 'above' },
|
|
154
|
+
{ left, top: Math.max(top, anchor.bottom + gap), width, height: Math.max(0, bottom - Math.max(top, anchor.bottom + gap)), side: 'below' },
|
|
155
|
+
{ left: Math.max(left, anchor.right + gap), top, width: Math.max(0, right - Math.max(left, anchor.right + gap)), height, side: 'right' },
|
|
156
|
+
{ left, top, width: Math.max(0, Math.min(right, anchor.left - gap) - left), height, side: 'left' },
|
|
157
|
+
];
|
|
158
|
+
// Prefer above/below; constrain the card to free space instead of covering Updates.
|
|
159
|
+
const space = spaces.find((space) => space.width >= bounds.width && space.height >= bounds.height)
|
|
160
|
+
|| spaces.reduce((best, space) => space.width * space.height > best.width * best.height ? space : best);
|
|
161
|
+
card.style.maxWidth = `${space.width}px`;
|
|
162
|
+
card.style.maxHeight = `${space.height}px`;
|
|
163
|
+
const fitted = card.getBoundingClientRect();
|
|
164
|
+
card.style.left = `${Math.max(space.left, Math.min(anchor.left, space.left + space.width - fitted.width))}px`;
|
|
165
|
+
card.style.top = `${space.side === 'above' ? space.top + space.height - fitted.height : space.top}px`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function refreshCardVisibility() {
|
|
169
|
+
const visible = progress && progress.jobId !== dismissedJobId && !opened;
|
|
170
|
+
card.hidden = !visible;
|
|
171
|
+
positionCard();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function refreshTiming() {
|
|
175
|
+
if (!progress) return;
|
|
176
|
+
const running = isRunning();
|
|
177
|
+
const total = Math.max(0, Math.trunc(progress.totalSteps) || 0);
|
|
178
|
+
const completed = Math.max(0, Math.min(total, Math.trunc(progress.completedSteps) || 0));
|
|
179
|
+
const secondsSince = (timestamp) => Math.max(0, (Date.now() - Date.parse(timestamp)) / 1000) || 0;
|
|
180
|
+
const elapsed = Math.max(0, Math.floor(((progress.stoppedAt ?? Date.now()) - Date.parse(progress.startedAt)) / 1000)) || 0;
|
|
181
|
+
if (running) {
|
|
182
|
+
const stepFraction = progress.state === 'running' ? Math.min(0.95, secondsSince(progress.stepStartedAt) / 60) : 0;
|
|
183
|
+
const estimate = total ? Math.floor(100 * (completed + stepFraction) / total) : 0;
|
|
184
|
+
lastEstimate = Math.max(lastEstimate, Math.min(99, estimate));
|
|
185
|
+
timing.textContent = `Elapsed ${elapsed}s · Estimated ${lastEstimate}%`;
|
|
186
|
+
track.setAttribute('aria-label', `Estimated ${lastEstimate} percent, based on time, not measured work`);
|
|
187
|
+
fill.style.width = `${lastEstimate}%`;
|
|
188
|
+
} else {
|
|
189
|
+
timing.textContent = `Elapsed ${elapsed}s`;
|
|
190
|
+
const complete = ['success', 'unchanged'].includes(progress.state);
|
|
191
|
+
fill.style.width = `${complete ? 100 : lastEstimate}%`;
|
|
192
|
+
track.setAttribute('aria-label', complete ? 'Commands finished' : 'Update has no confirmed completion');
|
|
193
|
+
}
|
|
194
|
+
heuristic.hidden = !running;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function updateProgress(snapshot, statusText) {
|
|
198
|
+
const next = snapshot && PROGRESS_STATES.includes(snapshot.state) ? snapshot : null;
|
|
199
|
+
if (next && next.jobId !== lastJobId) {
|
|
200
|
+
lastJobId = next.jobId;
|
|
201
|
+
dismissedJobId = null;
|
|
202
|
+
lastEstimate = 0;
|
|
203
|
+
card.scrollTop = 0;
|
|
204
|
+
output.scrollTop = 0;
|
|
205
|
+
showingDetails = false;
|
|
206
|
+
}
|
|
207
|
+
const wasRunning = isRunning();
|
|
208
|
+
// Freeze elapsed time at the first terminal snapshot, including repeated polls.
|
|
209
|
+
const stoppedAt = next && !RUNNING_STATES.includes(next.state)
|
|
210
|
+
? (progress?.jobId === next.jobId && !wasRunning ? progress.stoppedAt : Date.now()) : null;
|
|
211
|
+
progress = next ? { ...next, stoppedAt } : null;
|
|
212
|
+
if (timer !== null) window.clearInterval(timer);
|
|
213
|
+
timer = null;
|
|
214
|
+
const running = Boolean(isRunning());
|
|
215
|
+
button.classList.toggle('sidebar-update-trigger-running', running);
|
|
216
|
+
if (!running && opened && document.activeElement === returnToProgress) {
|
|
217
|
+
choices[0].focus({ preventScroll: true });
|
|
218
|
+
choices[0].scrollIntoView({ block: 'nearest' });
|
|
219
|
+
}
|
|
220
|
+
returnToProgress.hidden = !running;
|
|
221
|
+
if (!progress) {
|
|
222
|
+
showingDetails = false;
|
|
223
|
+
refreshCardVisibility();
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
card.dataset.state = progress.state;
|
|
227
|
+
setText(progressTitle, {
|
|
228
|
+
launching: 'Preparing update', running: 'Updating', success: 'Update complete',
|
|
229
|
+
unchanged: 'Already up to date', partial: 'Update partly completed',
|
|
230
|
+
failed: 'Update failed', unknown: 'Update status unknown',
|
|
231
|
+
}[progress.state]);
|
|
232
|
+
setText(progressLabel, progress.label || '');
|
|
233
|
+
progressLabel.hidden = !progressLabel.textContent;
|
|
234
|
+
setText(result, running ? '' : statusText);
|
|
235
|
+
result.hidden = !result.textContent;
|
|
236
|
+
const total = Math.max(0, Math.trunc(progress.totalSteps) || 0);
|
|
237
|
+
const completed = Math.max(0, Math.min(total, Math.trunc(progress.completedSteps) || 0));
|
|
238
|
+
step.textContent = running && total > completed
|
|
239
|
+
? `Step ${completed + 1} of ${total}${progress.currentTargetId ? ` · ${progress.currentTargetId}` : ''}`
|
|
240
|
+
: `${completed} of ${total} steps completed`;
|
|
241
|
+
stdout.textContent = String(progress.stdout || '').slice(-8000);
|
|
242
|
+
stderr.textContent = String(progress.stderr || '').slice(-8000);
|
|
243
|
+
stdout.hidden = !stdout.textContent;
|
|
244
|
+
stderr.hidden = !stderr.textContent;
|
|
245
|
+
output.hidden = stdout.hidden && stderr.hidden;
|
|
246
|
+
const steps = progress.steps || [];
|
|
247
|
+
const commandLines = steps.map((item) => {
|
|
248
|
+
const receipt = item.receipt;
|
|
249
|
+
const state = receipt?.status || (progress.currentTargetId === item.id && running ? 'running' : 'pending');
|
|
250
|
+
const command = item.command ? [item.command.command, ...(item.command.args || [])].map((part) => JSON.stringify(part)).join(' ') : '';
|
|
251
|
+
return [
|
|
252
|
+
`${item.id}: ${state}${receipt?.exitCode != null ? ` · exit ${receipt.exitCode}` : ''}${receipt?.signal ? ` · signal ${receipt.signal}` : ''}${receipt?.afterVersion ? ` · installed ${receipt.afterVersion}` : ''}`,
|
|
253
|
+
item.installedRoot ? `Installation: ${item.installedRoot}` : '',
|
|
254
|
+
...(item.coveredInstallations || []).map((covered) => `Includes ${covered.id} at ${covered.installedRoot}`), command,
|
|
255
|
+
].filter(Boolean).join('\n');
|
|
256
|
+
}).join('\n\n');
|
|
257
|
+
setText(commands, commandLines || 'Waiting for command results.');
|
|
258
|
+
const lines = steps.filter((item) => item.receipt).map(({ id, receipt }) => [
|
|
259
|
+
`${id} output`,
|
|
260
|
+
receipt.stdout ? `stdout: ${String(receipt.stdout).slice(-2000)}` : '',
|
|
261
|
+
receipt.stderr ? `stderr: ${String(receipt.stderr).slice(-2000)}` : '',
|
|
262
|
+
receipt.error ? `error: ${String(receipt.error).slice(-600)}` : '',
|
|
263
|
+
].filter(Boolean).join('\n')).join('\n\n').slice(-8000);
|
|
264
|
+
setText(receipts, lines);
|
|
265
|
+
receipts.hidden = !lines;
|
|
266
|
+
refreshTiming();
|
|
267
|
+
refreshDetails();
|
|
268
|
+
if (running) timer = window.setInterval(refreshTiming, 1000);
|
|
269
|
+
refreshCardVisibility();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function refreshDetails() {
|
|
273
|
+
const minimal = progress?.state === 'unchanged' && !showingDetails;
|
|
274
|
+
card.dataset.details = String(showingDetails);
|
|
275
|
+
details.hidden = showingDetails;
|
|
276
|
+
details.setAttribute('aria-expanded', String(showingDetails));
|
|
277
|
+
back.hidden = !showingDetails;
|
|
278
|
+
commandResults.hidden = !showingDetails;
|
|
279
|
+
result.hidden = minimal || !result.textContent;
|
|
280
|
+
step.hidden = minimal;
|
|
281
|
+
timing.hidden = minimal;
|
|
282
|
+
track.hidden = minimal;
|
|
283
|
+
heuristic.hidden = !isRunning() || minimal;
|
|
284
|
+
output.hidden = (stdout.hidden && stderr.hidden) || (!isRunning() && !showingDetails)
|
|
285
|
+
|| (showingDetails && !isRunning() && progress?.steps?.some((item) => item.receipt));
|
|
286
|
+
dismiss.hidden = Boolean(isRunning()) || showingDetails;
|
|
287
|
+
setText(back, isRunning() ? 'Back to progress' : 'Back to result');
|
|
288
|
+
positionCard();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function showProgress() {
|
|
292
|
+
showingDetails = false;
|
|
293
|
+
refreshDetails();
|
|
294
|
+
details.focus({ preventScroll: true });
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function position() {
|
|
298
|
+
if (!opened || disposed) return;
|
|
299
|
+
if (!button.isConnected || !button.getClientRects().length) {
|
|
300
|
+
close({ restoreFocus: false });
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const viewport = window.visualViewport;
|
|
304
|
+
const margin = 8;
|
|
305
|
+
const gap = 6;
|
|
306
|
+
const leftEdge = (viewport?.offsetLeft ?? 0) + margin;
|
|
307
|
+
const topEdge = (viewport?.offsetTop ?? 0) + margin;
|
|
308
|
+
const width = viewport?.width ?? window.innerWidth;
|
|
309
|
+
const height = viewport?.height ?? window.innerHeight;
|
|
310
|
+
const rightEdge = leftEdge + width - margin * 2;
|
|
311
|
+
const bottomEdge = topEdge + height - margin * 2;
|
|
312
|
+
popup.style.maxWidth = `${Math.max(0, width - margin * 2)}px`;
|
|
313
|
+
popup.style.maxHeight = `${Math.max(0, height - margin * 2)}px`;
|
|
314
|
+
const anchor = button.getBoundingClientRect();
|
|
315
|
+
const bounds = popup.getBoundingClientRect();
|
|
316
|
+
let left = anchor.left;
|
|
317
|
+
let top = anchor.top - gap - bounds.height;
|
|
318
|
+
if (top < topEdge) {
|
|
319
|
+
top = anchor.bottom + gap;
|
|
320
|
+
if (top + bounds.height > bottomEdge) {
|
|
321
|
+
top = anchor.top;
|
|
322
|
+
if (anchor.right + gap + bounds.width <= rightEdge) left = anchor.right + gap;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
popup.style.left = `${Math.max(leftEdge, Math.min(left, rightEdge - bounds.width))}px`;
|
|
326
|
+
popup.style.top = `${Math.max(topEdge, Math.min(top, bottomEdge - bounds.height))}px`;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function schedulePosition() {
|
|
330
|
+
if ((!opened && card.hidden) || disposed || frame !== null) return;
|
|
331
|
+
frame = window.requestAnimationFrame(() => {
|
|
332
|
+
frame = null;
|
|
333
|
+
position();
|
|
334
|
+
positionCard();
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function close({ restoreFocus = true } = {}) {
|
|
339
|
+
if (disposed || !opened) return;
|
|
340
|
+
opened = false;
|
|
341
|
+
if (frame !== null) window.cancelAnimationFrame(frame);
|
|
342
|
+
frame = null;
|
|
343
|
+
if (usesPopover && popup.matches(':popover-open')) popup.hidePopover();
|
|
344
|
+
popup.hidden = true;
|
|
345
|
+
button.setAttribute('aria-expanded', 'false');
|
|
346
|
+
refreshCardVisibility();
|
|
347
|
+
if (restoreFocus && button.isConnected) button.focus({ preventScroll: true });
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function open(index = 0) {
|
|
351
|
+
if (disposed || !button.isConnected) return;
|
|
352
|
+
if (!opened) {
|
|
353
|
+
opened = true;
|
|
354
|
+
popup.hidden = false;
|
|
355
|
+
refreshCardVisibility();
|
|
356
|
+
popup.scrollTop = 0;
|
|
357
|
+
if (usesPopover) popup.showPopover();
|
|
358
|
+
button.setAttribute('aria-expanded', 'true');
|
|
359
|
+
position();
|
|
360
|
+
}
|
|
361
|
+
choices[index].focus({ preventScroll: true });
|
|
362
|
+
choices[index].scrollIntoView({ block: 'nearest' });
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* progress is optional: {jobId, state, label, totalSteps, completedSteps,
|
|
367
|
+
* currentTargetId, startedAt, stepStartedAt, stdout, stderr, steps}. Timestamps are ISO
|
|
368
|
+
* strings; state is launching/running/success/unchanged/partial/failed/unknown.
|
|
369
|
+
* The parent owns result wording in statusText. Omission removes the job card.
|
|
370
|
+
*/
|
|
371
|
+
function update({ busy = false, disabledReason = '', statusText = '', statusTone = '', progress: snapshot } = {}) {
|
|
372
|
+
if (disposed) return;
|
|
373
|
+
updateProgress(snapshot, statusText);
|
|
374
|
+
const running = Boolean(isRunning());
|
|
375
|
+
blocked = Boolean(busy || running || disabledReason);
|
|
376
|
+
availability.textContent = disabledReason || (busy || running ? 'An update is in progress.' : '');
|
|
377
|
+
availability.hidden = !availability.textContent;
|
|
378
|
+
setText(status, statusText);
|
|
379
|
+
status.hidden = !statusText;
|
|
380
|
+
status.dataset.tone = ['error', 'danger', 'warning', 'success'].includes(statusTone) ? statusTone : '';
|
|
381
|
+
const descriptions = [originalAttributes.get('aria-describedby'),
|
|
382
|
+
availability.hidden ? '' : availability.id, status.hidden ? '' : status.id].filter(Boolean);
|
|
383
|
+
if (descriptions.length) button.setAttribute('aria-describedby', descriptions.join(' '));
|
|
384
|
+
else button.removeAttribute('aria-describedby');
|
|
385
|
+
button.disabled = false;
|
|
386
|
+
button.setAttribute('aria-disabled', 'false');
|
|
387
|
+
button.setAttribute('aria-busy', String(Boolean(busy || running)));
|
|
388
|
+
button.title = blocked ? `Updates unavailable: ${availability.textContent} Open for status.` : 'Updates';
|
|
389
|
+
for (const item of choices) item.setAttribute('aria-disabled', String(blocked));
|
|
390
|
+
position();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
listen(details, 'click', () => {
|
|
394
|
+
showingDetails = true;
|
|
395
|
+
refreshDetails();
|
|
396
|
+
back.focus({ preventScroll: true });
|
|
397
|
+
});
|
|
398
|
+
listen(back, 'click', showProgress);
|
|
399
|
+
listen(returnToProgress, 'click', () => {
|
|
400
|
+
if (!isRunning()) return;
|
|
401
|
+
dismissedJobId = null;
|
|
402
|
+
close({ restoreFocus: false });
|
|
403
|
+
showProgress();
|
|
404
|
+
});
|
|
405
|
+
listen(dismiss, 'click', () => {
|
|
406
|
+
if (!progress || isRunning()) return;
|
|
407
|
+
dismissedJobId = progress.jobId;
|
|
408
|
+
refreshCardVisibility();
|
|
409
|
+
button.focus({ preventScroll: true });
|
|
410
|
+
});
|
|
411
|
+
listen(button, 'click', () => {
|
|
412
|
+
if (opened) close();
|
|
413
|
+
else open();
|
|
414
|
+
});
|
|
415
|
+
listen(button, 'keydown', (event) => {
|
|
416
|
+
if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp') return;
|
|
417
|
+
event.preventDefault();
|
|
418
|
+
event.stopPropagation();
|
|
419
|
+
open(event.key === 'ArrowUp' ? choices.length - 1 : 0);
|
|
420
|
+
});
|
|
421
|
+
listen(menu, 'click', (event) => {
|
|
422
|
+
const item = event.target.closest('[role="menuitem"]');
|
|
423
|
+
if (!opened || blocked || !choices.includes(item)) return;
|
|
424
|
+
const mode = item.dataset.mode;
|
|
425
|
+
close();
|
|
426
|
+
onSelect(mode);
|
|
427
|
+
});
|
|
428
|
+
listen(menu, 'keydown', (event) => {
|
|
429
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.isComposing) return;
|
|
430
|
+
const index = choices.indexOf(document.activeElement);
|
|
431
|
+
let next;
|
|
432
|
+
if (event.key === 'Home') next = 0;
|
|
433
|
+
else if (event.key === 'End') next = choices.length - 1;
|
|
434
|
+
else if (event.key === 'ArrowDown') next = (index + 1) % choices.length;
|
|
435
|
+
else if (event.key === 'ArrowUp') next = (index - 1 + choices.length) % choices.length;
|
|
436
|
+
else if (event.key === 'Tab') {
|
|
437
|
+
if (!event.shiftKey && !returnToProgress.hidden) {
|
|
438
|
+
event.preventDefault();
|
|
439
|
+
returnToProgress.focus({ preventScroll: true });
|
|
440
|
+
returnToProgress.scrollIntoView({ block: 'nearest' });
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
close();
|
|
444
|
+
return;
|
|
445
|
+
} else return;
|
|
446
|
+
event.preventDefault();
|
|
447
|
+
event.stopPropagation();
|
|
448
|
+
choices[next].focus({ preventScroll: true });
|
|
449
|
+
choices[next].scrollIntoView({ block: 'nearest' });
|
|
450
|
+
});
|
|
451
|
+
listen(returnToProgress, 'keydown', (event) => {
|
|
452
|
+
if (event.key !== 'Tab') return;
|
|
453
|
+
event.preventDefault();
|
|
454
|
+
if (event.shiftKey) {
|
|
455
|
+
choices.at(-1).focus({ preventScroll: true });
|
|
456
|
+
choices.at(-1).scrollIntoView({ block: 'nearest' });
|
|
457
|
+
}
|
|
458
|
+
else close();
|
|
459
|
+
});
|
|
460
|
+
listen(document, 'keydown', (event) => {
|
|
461
|
+
if (event.key !== 'Escape') return;
|
|
462
|
+
if (!opened && showingDetails && !card.hidden && card.contains(document.activeElement)) {
|
|
463
|
+
event.preventDefault();
|
|
464
|
+
event.stopPropagation();
|
|
465
|
+
showProgress();
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (!opened) return;
|
|
469
|
+
event.preventDefault();
|
|
470
|
+
event.stopPropagation();
|
|
471
|
+
close();
|
|
472
|
+
}, { capture: true });
|
|
473
|
+
listen(document, 'pointerdown', (event) => {
|
|
474
|
+
if (opened && !popup.contains(event.target) && !button.contains(event.target)) close({ restoreFocus: false });
|
|
475
|
+
}, { capture: true });
|
|
476
|
+
listen(document, 'focusin', (event) => {
|
|
477
|
+
if (opened && !popup.contains(event.target) && !button.contains(event.target)) close({ restoreFocus: false });
|
|
478
|
+
});
|
|
479
|
+
listen(window, 'resize', schedulePosition, { passive: true });
|
|
480
|
+
listen(document, 'scroll', schedulePosition, { passive: true, capture: true });
|
|
481
|
+
if (window.visualViewport) {
|
|
482
|
+
listen(window.visualViewport, 'resize', schedulePosition, { passive: true });
|
|
483
|
+
listen(window.visualViewport, 'scroll', schedulePosition, { passive: true });
|
|
484
|
+
}
|
|
485
|
+
const observer = new window.ResizeObserver(schedulePosition);
|
|
486
|
+
observer.observe(popup);
|
|
487
|
+
observer.observe(button);
|
|
488
|
+
observer.observe(card);
|
|
489
|
+
|
|
490
|
+
function dispose() {
|
|
491
|
+
if (disposed) return;
|
|
492
|
+
close();
|
|
493
|
+
disposed = true;
|
|
494
|
+
if (frame !== null) window.cancelAnimationFrame(frame);
|
|
495
|
+
if (timer !== null) window.clearInterval(timer);
|
|
496
|
+
frame = null;
|
|
497
|
+
timer = null;
|
|
498
|
+
lifetime.abort();
|
|
499
|
+
observer.disconnect();
|
|
500
|
+
popup.remove();
|
|
501
|
+
card.remove();
|
|
502
|
+
button.classList.remove('sidebar-update-trigger-running');
|
|
503
|
+
if (!hadTriggerClass) button.classList.remove('sidebar-update-trigger');
|
|
504
|
+
for (const [name, value] of originalAttributes) {
|
|
505
|
+
if (value === null) button.removeAttribute(name);
|
|
506
|
+
else button.setAttribute(name, value);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
update();
|
|
511
|
+
return { update, close, dispose };
|
|
512
|
+
}
|