@firstpick/pi-package-webui 0.11.1 → 0.11.3
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 +151 -12
- package/README.md +34 -6
- package/TECHNICAL.md +75 -8
- package/bin/pi-webui.mjs +5390 -11423
- package/index.ts +10 -3
- 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 +4 -4
- 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 -3886
- 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 +322 -169
- package/public/subagent-launch-slot-state.mjs +2 -2
- 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/action-feedback-gutter.spec.mjs +251 -0
- 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-fast-mode-static.test.mjs +16 -11
- package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
- package/tests/codex-usage-source.test.mjs +4 -3
- 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-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 +21 -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-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,168 @@
|
|
|
1
|
+
/** Present caller-owned context actions; the parent owns validation and nested transitions. */
|
|
2
|
+
export function createContextActions({ document, onInvoke, onMore, onClose }) {
|
|
3
|
+
const node = (tag, className, text) => {
|
|
4
|
+
const element = document.createElement(tag);
|
|
5
|
+
if (className) element.className = className;
|
|
6
|
+
if (text !== undefined) element.textContent = text;
|
|
7
|
+
return element;
|
|
8
|
+
};
|
|
9
|
+
const button = (className, text) => {
|
|
10
|
+
const element = node('button', className, text);
|
|
11
|
+
element.type = 'button';
|
|
12
|
+
return element;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const element = node('dialog');
|
|
16
|
+
element.id = 'shellContextActions';
|
|
17
|
+
element.setAttribute('aria-labelledby', 'shellContextActionsTitle');
|
|
18
|
+
const header = node('header', 'context-actions-header');
|
|
19
|
+
const heading = node('h2', '', 'Context actions');
|
|
20
|
+
heading.id = 'shellContextActionsTitle';
|
|
21
|
+
const closeButton = button('context-actions-close', 'Close');
|
|
22
|
+
closeButton.setAttribute('aria-label', 'Close context actions');
|
|
23
|
+
const context = node('p', 'context-actions-context');
|
|
24
|
+
const runControls = node('div', 'context-actions-run-controls');
|
|
25
|
+
runControls.setAttribute('role', 'group');
|
|
26
|
+
const body = node('section', 'context-actions-body');
|
|
27
|
+
body.setAttribute('aria-label', 'Context actions');
|
|
28
|
+
const list = node('ul', 'context-actions-list');
|
|
29
|
+
const empty = node('p', 'context-actions-empty', 'No actions available here. Browse all tools for more actions.');
|
|
30
|
+
const footer = node('footer', 'context-actions-footer');
|
|
31
|
+
const moreButton = button('context-actions-more', 'More actions');
|
|
32
|
+
header.append(heading, closeButton);
|
|
33
|
+
body.append(list, empty);
|
|
34
|
+
footer.append(moreButton);
|
|
35
|
+
element.append(header, context, runControls, body, footer);
|
|
36
|
+
|
|
37
|
+
let actions = [];
|
|
38
|
+
let category;
|
|
39
|
+
let rows = [];
|
|
40
|
+
let trigger;
|
|
41
|
+
let closePending = false;
|
|
42
|
+
let disposed = false;
|
|
43
|
+
|
|
44
|
+
function finishClose() {
|
|
45
|
+
if (!closePending) return;
|
|
46
|
+
closePending = false;
|
|
47
|
+
const opener = trigger;
|
|
48
|
+
trigger = undefined;
|
|
49
|
+
// Restore before notifying the parent, which may immediately open another modal.
|
|
50
|
+
if (opener?.isConnected && !opener.disabled && opener.getClientRects().length
|
|
51
|
+
&& !opener.closest('[hidden], [inert]')
|
|
52
|
+
&& document.defaultView.getComputedStyle(opener).visibility === 'visible') {
|
|
53
|
+
opener.focus({ preventScroll: true });
|
|
54
|
+
}
|
|
55
|
+
onClose?.();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function close() {
|
|
59
|
+
if (disposed) return;
|
|
60
|
+
if (element.open) element.close();
|
|
61
|
+
finishClose();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function handleNativeClose() {
|
|
65
|
+
if (!element.open) finishClose();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function handleCancel(event) {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
close();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function update(snapshot = {}) {
|
|
74
|
+
if (disposed) return;
|
|
75
|
+
if (snapshot.actions !== undefined) actions = snapshot.actions;
|
|
76
|
+
if (snapshot.category !== undefined) category = snapshot.category;
|
|
77
|
+
if (snapshot.title !== undefined) heading.textContent = snapshot.title;
|
|
78
|
+
if (snapshot.contextLabel !== undefined) context.textContent = snapshot.contextLabel;
|
|
79
|
+
context.hidden = !context.textContent;
|
|
80
|
+
const active = document.activeElement;
|
|
81
|
+
const focusedRow = rows.find((row) => row.invoke === active);
|
|
82
|
+
rows = actions.map((action, index) => {
|
|
83
|
+
const row = node('li', 'context-actions-row');
|
|
84
|
+
const invoke = button('context-actions-action');
|
|
85
|
+
invoke.disabled = action.available === false;
|
|
86
|
+
invoke.setAttribute('aria-label', action.label);
|
|
87
|
+
const label = node('span', 'context-actions-label', action.label);
|
|
88
|
+
const description = node('span', 'context-actions-description', action.description);
|
|
89
|
+
description.hidden = !action.description;
|
|
90
|
+
invoke.append(label, description);
|
|
91
|
+
const reason = node('p', 'context-actions-reason', action.unavailableReason || 'This action is currently unavailable.');
|
|
92
|
+
reason.id = `shellContextActionsReason${index}`;
|
|
93
|
+
reason.hidden = !invoke.disabled;
|
|
94
|
+
if (invoke.disabled) invoke.setAttribute('aria-describedby', reason.id);
|
|
95
|
+
const entry = { action, row, invoke };
|
|
96
|
+
invoke.addEventListener('click', () => {
|
|
97
|
+
// Detached buttons from an earlier snapshot must never dispatch stale records.
|
|
98
|
+
if (!disposed && element.open && rows.includes(entry) && action.available !== false) onInvoke?.(action);
|
|
99
|
+
});
|
|
100
|
+
row.append(invoke, reason);
|
|
101
|
+
return entry;
|
|
102
|
+
});
|
|
103
|
+
list.replaceChildren(...rows.map((row) => row.row));
|
|
104
|
+
empty.hidden = rows.length > 0;
|
|
105
|
+
if (focusedRow) {
|
|
106
|
+
const replacement = rows.find((row) => row.action.id === focusedRow.action.id)?.invoke;
|
|
107
|
+
(replacement && !replacement.disabled ? replacement : moreButton).focus({ preventScroll: true });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function open(snapshot = {}, opener = document.activeElement) {
|
|
112
|
+
if (disposed) return;
|
|
113
|
+
if (!element.open) {
|
|
114
|
+
trigger = opener;
|
|
115
|
+
category = undefined;
|
|
116
|
+
heading.textContent = 'Context actions';
|
|
117
|
+
context.textContent = '';
|
|
118
|
+
actions = [];
|
|
119
|
+
}
|
|
120
|
+
update(snapshot);
|
|
121
|
+
if (!element.open) element.showModal();
|
|
122
|
+
closePending = true;
|
|
123
|
+
(rows.find((row) => !row.invoke.disabled)?.invoke ?? moreButton).focus({ preventScroll: true });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function handleMore() {
|
|
127
|
+
if (!disposed && element.open) onMore?.(category);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function handleKeydown(event) {
|
|
131
|
+
if (event.defaultPrevented || event.isComposing || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
132
|
+
if (!rows.some((row) => row.invoke === event.target)) return;
|
|
133
|
+
if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) return;
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
const available = rows.filter((row) => !row.invoke.disabled).map((row) => row.invoke);
|
|
136
|
+
if (!available.length) return;
|
|
137
|
+
const index = available.indexOf(event.target);
|
|
138
|
+
let next;
|
|
139
|
+
if (event.key === 'Home') next = 0;
|
|
140
|
+
else if (event.key === 'End') next = available.length - 1;
|
|
141
|
+
else if (event.key === 'ArrowDown') next = (index + 1) % available.length;
|
|
142
|
+
else next = (index - 1 + available.length) % available.length;
|
|
143
|
+
available[next].focus();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function dispose() {
|
|
147
|
+
if (disposed) return;
|
|
148
|
+
disposed = true;
|
|
149
|
+
if (element.open) element.close();
|
|
150
|
+
finishClose();
|
|
151
|
+
closeButton.removeEventListener('click', close);
|
|
152
|
+
moreButton.removeEventListener('click', handleMore);
|
|
153
|
+
element.removeEventListener('close', handleNativeClose);
|
|
154
|
+
element.removeEventListener('cancel', handleCancel);
|
|
155
|
+
element.removeEventListener('keydown', handleKeydown);
|
|
156
|
+
element.remove();
|
|
157
|
+
actions = [];
|
|
158
|
+
rows = [];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
closeButton.addEventListener('click', close);
|
|
162
|
+
moreButton.addEventListener('click', handleMore);
|
|
163
|
+
element.addEventListener('close', handleNativeClose);
|
|
164
|
+
element.addEventListener('cancel', handleCancel);
|
|
165
|
+
element.addEventListener('keydown', handleKeydown);
|
|
166
|
+
update();
|
|
167
|
+
return { element, slots: { runControls }, open, update, close, dispose };
|
|
168
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export const INSPECTOR_WIDTH_MIN = 240;
|
|
2
|
+
export const INSPECTOR_WIDTH_MAX = 640;
|
|
3
|
+
export const INSPECTOR_WIDTH_DEFAULT = 320;
|
|
4
|
+
|
|
5
|
+
/** Keep layout clamping separate from the user's explicitly committed width. */
|
|
6
|
+
export function createInspectorResize({ element, body, handle, onCommit }) {
|
|
7
|
+
let preferred = INSPECTOR_WIDTH_DEFAULT;
|
|
8
|
+
let drag = null;
|
|
9
|
+
let enabled = false;
|
|
10
|
+
let disposed = false;
|
|
11
|
+
const removers = [];
|
|
12
|
+
function bounds() {
|
|
13
|
+
const available = body.getBoundingClientRect().width;
|
|
14
|
+
// Match the CSS cap, including when a wide sidebar constrains the body.
|
|
15
|
+
const max = Math.max(0, Math.min(INSPECTOR_WIDTH_MAX, Math.floor(available * 0.45), Math.floor(available - 320)));
|
|
16
|
+
return { min: Math.min(INSPECTOR_WIDTH_MIN, max), max };
|
|
17
|
+
}
|
|
18
|
+
function clamp(value) {
|
|
19
|
+
const { min, max } = bounds();
|
|
20
|
+
return Math.max(min, Math.min(max, Math.round(value)));
|
|
21
|
+
}
|
|
22
|
+
const width = () => clamp(drag?.width ?? preferred);
|
|
23
|
+
function render() {
|
|
24
|
+
const { min, max } = bounds();
|
|
25
|
+
const current = width();
|
|
26
|
+
element.style.setProperty('--focused-inspector-width', `${current}px`);
|
|
27
|
+
handle.setAttribute('aria-valuemin', String(min));
|
|
28
|
+
handle.setAttribute('aria-valuemax', String(max));
|
|
29
|
+
handle.setAttribute('aria-valuenow', String(current));
|
|
30
|
+
handle.setAttribute('aria-valuetext', `${current} pixels`);
|
|
31
|
+
}
|
|
32
|
+
function save(value) {
|
|
33
|
+
if (value === preferred) return;
|
|
34
|
+
const previous = preferred;
|
|
35
|
+
preferred = value;
|
|
36
|
+
try {
|
|
37
|
+
if (onCommit?.(value) === false) preferred = previous;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
preferred = previous;
|
|
40
|
+
throw error;
|
|
41
|
+
} finally {
|
|
42
|
+
render();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function finish(commit) {
|
|
46
|
+
if (!drag) return;
|
|
47
|
+
const current = drag;
|
|
48
|
+
drag = null;
|
|
49
|
+
element.ownerDocument.removeEventListener('keydown', cancelOnEscape, true);
|
|
50
|
+
element.classList.remove('focused-inspector-resizing');
|
|
51
|
+
if (handle.hasPointerCapture(current.pointerId)) handle.releasePointerCapture(current.pointerId);
|
|
52
|
+
if (commit && current.width !== current.start) save(clamp(current.width));
|
|
53
|
+
else render();
|
|
54
|
+
}
|
|
55
|
+
function cancelOnEscape(event) {
|
|
56
|
+
if (!drag || event.key !== 'Escape') return;
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
event.stopPropagation();
|
|
59
|
+
finish(false);
|
|
60
|
+
}
|
|
61
|
+
function listen(type, callback) {
|
|
62
|
+
handle.addEventListener(type, callback);
|
|
63
|
+
removers.push(() => handle.removeEventListener(type, callback));
|
|
64
|
+
}
|
|
65
|
+
listen('pointerdown', event => {
|
|
66
|
+
if (!enabled || event.button !== 0 || drag) return;
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
handle.focus({ preventScroll: true });
|
|
69
|
+
drag = { pointerId: event.pointerId, x: event.clientX, start: width(), width: width() };
|
|
70
|
+
handle.setPointerCapture(event.pointerId);
|
|
71
|
+
element.ownerDocument.addEventListener('keydown', cancelOnEscape, true);
|
|
72
|
+
element.classList.add('focused-inspector-resizing');
|
|
73
|
+
});
|
|
74
|
+
listen('pointermove', event => {
|
|
75
|
+
if (!drag || drag.pointerId !== event.pointerId) return;
|
|
76
|
+
drag.width = clamp(drag.start + drag.x - event.clientX);
|
|
77
|
+
render();
|
|
78
|
+
});
|
|
79
|
+
listen('pointerup', event => {
|
|
80
|
+
if (drag?.pointerId === event.pointerId) finish(true);
|
|
81
|
+
});
|
|
82
|
+
listen('pointercancel', event => {
|
|
83
|
+
if (drag?.pointerId === event.pointerId) finish(false);
|
|
84
|
+
});
|
|
85
|
+
listen('lostpointercapture', () => finish(false));
|
|
86
|
+
listen('dblclick', event => {
|
|
87
|
+
if (!enabled) return;
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
finish(false);
|
|
90
|
+
save(INSPECTOR_WIDTH_DEFAULT);
|
|
91
|
+
});
|
|
92
|
+
listen('keydown', event => {
|
|
93
|
+
if (!enabled || drag || !['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
const { min, max } = bounds();
|
|
96
|
+
const step = event.shiftKey ? 50 : 10;
|
|
97
|
+
const current = width();
|
|
98
|
+
const next = clamp(event.key === 'Home' ? min : event.key === 'End' ? max
|
|
99
|
+
: current + (event.key === 'ArrowLeft' ? step : -step));
|
|
100
|
+
if (next !== current) save(next);
|
|
101
|
+
});
|
|
102
|
+
const observer = new element.ownerDocument.defaultView.ResizeObserver(render);
|
|
103
|
+
observer.observe(body);
|
|
104
|
+
return {
|
|
105
|
+
update({ inspectorWidth, active }) {
|
|
106
|
+
if (disposed) return;
|
|
107
|
+
enabled = active;
|
|
108
|
+
handle.hidden = !enabled;
|
|
109
|
+
if (!enabled) finish(false);
|
|
110
|
+
preferred = Number.isFinite(inspectorWidth)
|
|
111
|
+
? Math.max(INSPECTOR_WIDTH_MIN, Math.min(INSPECTOR_WIDTH_MAX, Math.round(inspectorWidth)))
|
|
112
|
+
: INSPECTOR_WIDTH_DEFAULT;
|
|
113
|
+
render();
|
|
114
|
+
},
|
|
115
|
+
dispose() {
|
|
116
|
+
if (disposed) return;
|
|
117
|
+
disposed = true;
|
|
118
|
+
enabled = false;
|
|
119
|
+
finish(false);
|
|
120
|
+
observer.disconnect();
|
|
121
|
+
for (const remove of removers) remove();
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export const NAVIGATION_WIDTH_MIN = 180;
|
|
2
|
+
export const NAVIGATION_WIDTH_MAX = 420;
|
|
3
|
+
export const NAVIGATION_WIDTH_DEFAULT = 202;
|
|
4
|
+
|
|
5
|
+
/** Resize presentation immediately; persist only explicit completed changes. */
|
|
6
|
+
export function createNavigationResize({ element, handle, onCommit }) {
|
|
7
|
+
let preferred = NAVIGATION_WIDTH_DEFAULT;
|
|
8
|
+
let drag = null;
|
|
9
|
+
let enabled = false;
|
|
10
|
+
let disposed = false;
|
|
11
|
+
const removers = [];
|
|
12
|
+
const limit = () => Math.max(NAVIGATION_WIDTH_MIN,
|
|
13
|
+
Math.min(NAVIGATION_WIDTH_MAX, Math.floor(element.getBoundingClientRect().width - 46 - 480)));
|
|
14
|
+
const clamp = value => Math.max(NAVIGATION_WIDTH_MIN, Math.min(limit(), Math.round(value)));
|
|
15
|
+
const width = () => clamp(drag?.width ?? preferred);
|
|
16
|
+
function render() {
|
|
17
|
+
element.style.setProperty('--focused-navigation-width', `${width()}px`);
|
|
18
|
+
handle.setAttribute('aria-valuemin', String(NAVIGATION_WIDTH_MIN));
|
|
19
|
+
handle.setAttribute('aria-valuemax', String(limit()));
|
|
20
|
+
handle.setAttribute('aria-valuenow', String(width()));
|
|
21
|
+
handle.setAttribute('aria-valuetext', `${width()} pixels`);
|
|
22
|
+
}
|
|
23
|
+
function listen(type, callback) {
|
|
24
|
+
handle.addEventListener(type, callback);
|
|
25
|
+
removers.push(() => handle.removeEventListener(type, callback));
|
|
26
|
+
}
|
|
27
|
+
function finish(commit) {
|
|
28
|
+
if (!drag) return;
|
|
29
|
+
const current = drag;
|
|
30
|
+
drag = null;
|
|
31
|
+
element.ownerDocument.removeEventListener('keydown', cancelDragOnEscape, true);
|
|
32
|
+
element.classList.remove('focused-navigation-resizing');
|
|
33
|
+
if (handle.hasPointerCapture(current.pointerId)) handle.releasePointerCapture(current.pointerId);
|
|
34
|
+
if (commit && clamp(current.width) !== current.start) save(clamp(current.width));
|
|
35
|
+
else render();
|
|
36
|
+
}
|
|
37
|
+
function save(value) {
|
|
38
|
+
const previous = preferred;
|
|
39
|
+
preferred = value;
|
|
40
|
+
if (onCommit?.(value) === false) preferred = previous;
|
|
41
|
+
render();
|
|
42
|
+
}
|
|
43
|
+
function cancelDragOnEscape(event) {
|
|
44
|
+
if (!drag || event.key !== 'Escape') return;
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
event.stopPropagation();
|
|
47
|
+
finish(false);
|
|
48
|
+
}
|
|
49
|
+
listen('pointerdown', event => {
|
|
50
|
+
if (!enabled || event.button !== 0 || drag) return;
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
handle.focus({ preventScroll: true });
|
|
53
|
+
drag = { pointerId: event.pointerId, x: event.clientX, start: width(), width: width() };
|
|
54
|
+
handle.setPointerCapture(event.pointerId);
|
|
55
|
+
element.ownerDocument.addEventListener('keydown', cancelDragOnEscape, true);
|
|
56
|
+
element.classList.add('focused-navigation-resizing');
|
|
57
|
+
});
|
|
58
|
+
listen('pointermove', event => {
|
|
59
|
+
if (!drag || drag.pointerId !== event.pointerId) return;
|
|
60
|
+
drag.width = clamp(drag.start + event.clientX - drag.x);
|
|
61
|
+
render();
|
|
62
|
+
});
|
|
63
|
+
listen('pointerup', event => {
|
|
64
|
+
if (drag?.pointerId === event.pointerId) finish(true);
|
|
65
|
+
});
|
|
66
|
+
listen('pointercancel', event => {
|
|
67
|
+
if (drag?.pointerId === event.pointerId) finish(false);
|
|
68
|
+
});
|
|
69
|
+
listen('lostpointercapture', () => finish(false));
|
|
70
|
+
listen('dblclick', event => {
|
|
71
|
+
if (!enabled) return;
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
finish(false);
|
|
74
|
+
save(NAVIGATION_WIDTH_DEFAULT);
|
|
75
|
+
});
|
|
76
|
+
listen('keydown', event => {
|
|
77
|
+
if (!enabled) return;
|
|
78
|
+
if (drag || !['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
const step = event.shiftKey ? 50 : 10;
|
|
81
|
+
const next = event.key === 'Home' ? NAVIGATION_WIDTH_MIN : event.key === 'End' ? limit()
|
|
82
|
+
: width() + (event.key === 'ArrowLeft' ? -step : step);
|
|
83
|
+
save(clamp(next));
|
|
84
|
+
});
|
|
85
|
+
const observer = new element.ownerDocument.defaultView.ResizeObserver(render);
|
|
86
|
+
observer.observe(element);
|
|
87
|
+
return {
|
|
88
|
+
update({ navigationWidth, active }) {
|
|
89
|
+
if (disposed) return;
|
|
90
|
+
enabled = active;
|
|
91
|
+
handle.hidden = !enabled;
|
|
92
|
+
if (!enabled) finish(false);
|
|
93
|
+
preferred = Number.isInteger(navigationWidth)
|
|
94
|
+
? Math.max(NAVIGATION_WIDTH_MIN, Math.min(NAVIGATION_WIDTH_MAX, navigationWidth))
|
|
95
|
+
: NAVIGATION_WIDTH_DEFAULT;
|
|
96
|
+
render();
|
|
97
|
+
},
|
|
98
|
+
dispose() {
|
|
99
|
+
if (disposed) return;
|
|
100
|
+
disposed = true;
|
|
101
|
+
enabled = false;
|
|
102
|
+
finish(false);
|
|
103
|
+
observer.disconnect();
|
|
104
|
+
for (const remove of removers) remove();
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { MOBILE_ROUTES, MOBILE_SURFACES, normalizeMobileNavigationTarget } from "./mobile-shell-state.mjs";
|
|
2
|
+
|
|
3
|
+
const FOCUSED_DESTINATIONS = new Set(["conversation", "home", "project", "activity", "settings"]);
|
|
4
|
+
|
|
5
|
+
function isStableId(value) {
|
|
6
|
+
return typeof value === "string" && /^[a-z][a-z0-9:_-]{0,119}$/i.exec(value)?.[0] === value;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function isRecord(value) {
|
|
10
|
+
if (!value || typeof value !== "object") return false;
|
|
11
|
+
const prototype = Object.getPrototypeOf(value);
|
|
12
|
+
return prototype === Object.prototype || prototype === null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function navigationPatch(state) {
|
|
16
|
+
if (!isRecord(state) || Reflect.ownKeys(state).some((key) =>
|
|
17
|
+
key !== "piMobileShellV2" && key !== "mobileShellState" && key !== "focusedShellState")) {
|
|
18
|
+
throw new TypeError("History state must contain only shell navigation fields");
|
|
19
|
+
}
|
|
20
|
+
const patch = {};
|
|
21
|
+
if (Object.hasOwn(state, "focusedShellState")) {
|
|
22
|
+
const focused = state.focusedShellState;
|
|
23
|
+
if (!isRecord(focused) || Reflect.ownKeys(focused).some(key => !["destination", "inspector", "setting"].includes(key)) ||
|
|
24
|
+
!Object.hasOwn(focused, "destination") || !Object.hasOwn(focused, "inspector") ||
|
|
25
|
+
!FOCUSED_DESTINATIONS.has(focused.destination) ||
|
|
26
|
+
(focused.inspector !== null && !isStableId(focused.inspector)) ||
|
|
27
|
+
(Object.hasOwn(focused, "setting") && (focused.destination !== "settings" ||
|
|
28
|
+
(focused.setting !== null && !isStableId(focused.setting))))) {
|
|
29
|
+
throw new TypeError("Invalid serialized focused shell navigation state");
|
|
30
|
+
}
|
|
31
|
+
patch.focusedShellState = { destination: focused.destination, inspector: focused.inspector };
|
|
32
|
+
if (Object.hasOwn(focused, "setting")) patch.focusedShellState.setting = focused.setting;
|
|
33
|
+
}
|
|
34
|
+
if (Object.hasOwn(state, "piMobileShellV2")) {
|
|
35
|
+
if (state.piMobileShellV2 !== true) throw new TypeError("piMobileShellV2 must be true");
|
|
36
|
+
patch.piMobileShellV2 = true;
|
|
37
|
+
}
|
|
38
|
+
if (Object.hasOwn(state, "mobileShellState")) {
|
|
39
|
+
const mobile = state.mobileShellState;
|
|
40
|
+
const keys = ["route", "surface", "surfacePage", "routeHistory"];
|
|
41
|
+
if (!isRecord(mobile) || Reflect.ownKeys(mobile).length !== keys.length || keys.some((key) => !Object.hasOwn(mobile, key)) ||
|
|
42
|
+
!MOBILE_ROUTES.has(mobile.route) || !MOBILE_SURFACES.has(mobile.surface) ||
|
|
43
|
+
typeof mobile.surfacePage !== "string" || !mobile.surfacePage ||
|
|
44
|
+
!Array.isArray(mobile.routeHistory) || mobile.routeHistory.length > 16 ||
|
|
45
|
+
Array.from(mobile.routeHistory).some((route) => !MOBILE_ROUTES.has(route))) {
|
|
46
|
+
throw new TypeError("Invalid serialized mobile shell navigation state");
|
|
47
|
+
}
|
|
48
|
+
patch.mobileShellState = {
|
|
49
|
+
route: mobile.route,
|
|
50
|
+
surface: mobile.surface,
|
|
51
|
+
surfacePage: mobile.surfacePage,
|
|
52
|
+
routeHistory: Array.from(mobile.routeHistory),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return patch;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function navigationUrl(url, currentHref) {
|
|
59
|
+
if (typeof url !== "string" && !(url instanceof URL)) throw new TypeError("History URL must be a string or URL");
|
|
60
|
+
const current = new URL(currentHref);
|
|
61
|
+
const next = new URL(url, current);
|
|
62
|
+
if (next.origin !== current.origin) throw new TypeError("History URL must remain same-origin");
|
|
63
|
+
for (const key of ["tab", "run", "blocker"]) {
|
|
64
|
+
for (const id of next.searchParams.getAll(key)) {
|
|
65
|
+
const field = { tab: "tabId", run: "runId", blocker: "blockerId" }[key];
|
|
66
|
+
const target = normalizeMobileNavigationTarget({ v: 1, route: "chat", [field]: id });
|
|
67
|
+
if (target?.[field] !== id) throw new TypeError(`Invalid navigation identifier: ${key}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (next.searchParams.getAll("mobileRoute").some((route) => !MOBILE_ROUTES.has(route))) {
|
|
71
|
+
throw new TypeError("Invalid mobileRoute");
|
|
72
|
+
}
|
|
73
|
+
if (next.searchParams.getAll("view").some((destination) => !FOCUSED_DESTINATIONS.has(destination))) {
|
|
74
|
+
throw new TypeError("Invalid view");
|
|
75
|
+
}
|
|
76
|
+
for (const key of ["inspector", "setting"]) {
|
|
77
|
+
if (next.searchParams.getAll(key).some(value => !isStableId(value))) {
|
|
78
|
+
throw new TypeError(`Invalid ${key}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return next.href;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Own one popstate listener without writing an initial entry. The caller confirms
|
|
86
|
+
* destructive navigation before write. Invalid input throws TypeError; browser
|
|
87
|
+
* history failures propagate. write/back throw after disposal; dispose is idempotent.
|
|
88
|
+
*/
|
|
89
|
+
export function createShellHistory({ window, onPopState } = {}) {
|
|
90
|
+
if (!window || typeof window.addEventListener !== "function" || typeof window.removeEventListener !== "function" ||
|
|
91
|
+
!window.history || ["pushState", "replaceState", "back"].some((method) => typeof window.history[method] !== "function") ||
|
|
92
|
+
typeof onPopState !== "function") {
|
|
93
|
+
throw new TypeError("Shell history requires a window with history and an onPopState callback");
|
|
94
|
+
}
|
|
95
|
+
let disposed = false;
|
|
96
|
+
const handlePopState = (event) => {
|
|
97
|
+
if (!disposed) onPopState(event);
|
|
98
|
+
};
|
|
99
|
+
window.addEventListener("popstate", handlePopState);
|
|
100
|
+
|
|
101
|
+
function assertActive() {
|
|
102
|
+
if (disposed) throw new Error("Shell history is disposed");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
write({ state, replace = false, url } = {}) {
|
|
107
|
+
assertActive();
|
|
108
|
+
if (typeof replace !== "boolean") throw new TypeError("replace must be a boolean");
|
|
109
|
+
const patch = navigationPatch(state);
|
|
110
|
+
const nextUrl = url === undefined ? undefined : navigationUrl(url, window.location.href);
|
|
111
|
+
const existing = window.history.state;
|
|
112
|
+
const merged = { ...(isRecord(existing) ? existing : {}), ...patch };
|
|
113
|
+
const method = replace ? "replaceState" : "pushState";
|
|
114
|
+
if (nextUrl === undefined) window.history[method](merged, "");
|
|
115
|
+
else window.history[method](merged, "", nextUrl);
|
|
116
|
+
},
|
|
117
|
+
back() {
|
|
118
|
+
assertActive();
|
|
119
|
+
window.history.back();
|
|
120
|
+
},
|
|
121
|
+
dispose() {
|
|
122
|
+
if (disposed) return;
|
|
123
|
+
disposed = true;
|
|
124
|
+
window.removeEventListener("popstate", handlePopState);
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { isMobileShellV2Enabled } from "./mobile-shell-state.mjs";
|
|
2
|
+
|
|
3
|
+
import { NAVIGATION_WIDTH_MIN, NAVIGATION_WIDTH_MAX } from "./shell-navigation-resize.mjs";
|
|
4
|
+
|
|
5
|
+
export const SHELL_PREFERENCES_STORAGE_KEY = "pi-webui-shell-preferences-v1";
|
|
6
|
+
|
|
7
|
+
function defaultPreferences() {
|
|
8
|
+
return { v: 1, desktopLayout: "classic" };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function normalizePreferences(value) {
|
|
12
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || value.v !== 1) return null;
|
|
13
|
+
if (value.desktopLayout !== "classic" && value.desktopLayout !== "focused") return null;
|
|
14
|
+
const normalized = { v: 1, desktopLayout: value.desktopLayout };
|
|
15
|
+
if (Object.hasOwn(value, "navigation")) {
|
|
16
|
+
if (value.navigation !== "left" && value.navigation !== "top") return null;
|
|
17
|
+
normalized.navigation = value.navigation;
|
|
18
|
+
}
|
|
19
|
+
if (Object.hasOwn(value, "navCollapsed")) {
|
|
20
|
+
if (typeof value.navCollapsed !== "boolean") return null;
|
|
21
|
+
normalized.navCollapsed = value.navCollapsed;
|
|
22
|
+
}
|
|
23
|
+
if (Object.hasOwn(value, "overviewOpen")) {
|
|
24
|
+
if (typeof value.overviewOpen !== "boolean") return null;
|
|
25
|
+
normalized.overviewOpen = value.overviewOpen;
|
|
26
|
+
}
|
|
27
|
+
if (Object.hasOwn(value, "pinnedActions")) {
|
|
28
|
+
if (!Array.isArray(value.pinnedActions)) return null;
|
|
29
|
+
const pins = new Set();
|
|
30
|
+
for (const id of value.pinnedActions) {
|
|
31
|
+
if (typeof id !== "string" || /^[a-z][\x21-\x7e]{0,511}$/i.exec(id)?.[0] !== id) return null;
|
|
32
|
+
pins.add(id);
|
|
33
|
+
if (pins.size > 20) return null;
|
|
34
|
+
}
|
|
35
|
+
normalized.pinnedActions = [...pins];
|
|
36
|
+
}
|
|
37
|
+
if (Object.hasOwn(value, "navigationWidth")) {
|
|
38
|
+
if (!Number.isInteger(value.navigationWidth) || value.navigationWidth < NAVIGATION_WIDTH_MIN || value.navigationWidth > NAVIGATION_WIDTH_MAX) return null;
|
|
39
|
+
normalized.navigationWidth = value.navigationWidth;
|
|
40
|
+
}
|
|
41
|
+
if (Object.hasOwn(value, "inspectorWidth")) {
|
|
42
|
+
if (!Number.isInteger(value.inspectorWidth) || value.inspectorWidth < 240 || value.inspectorWidth > 640) return null;
|
|
43
|
+
normalized.inspectorWidth = value.inspectorWidth;
|
|
44
|
+
}
|
|
45
|
+
return normalized;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Read only the preview record. Invalid and future records remain untouched. */
|
|
49
|
+
export function readShellPreferences(storage) {
|
|
50
|
+
let raw;
|
|
51
|
+
try {
|
|
52
|
+
raw = storage.getItem(SHELL_PREFERENCES_STORAGE_KEY);
|
|
53
|
+
} catch {
|
|
54
|
+
return { status: "unavailable", value: defaultPreferences() };
|
|
55
|
+
}
|
|
56
|
+
if (raw === null) return { status: "absent", value: defaultPreferences() };
|
|
57
|
+
try {
|
|
58
|
+
const value = normalizePreferences(JSON.parse(raw));
|
|
59
|
+
if (value) return { status: "valid", value };
|
|
60
|
+
} catch {
|
|
61
|
+
// A failed parse must not turn a read into a storage repair.
|
|
62
|
+
}
|
|
63
|
+
return { status: "invalid", value: defaultPreferences() };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Resolve a read result without persisting cohort defaults or repairing records. */
|
|
67
|
+
export function effectiveShellPreferences(record, serverCohort = null) {
|
|
68
|
+
try {
|
|
69
|
+
if (!record || typeof record !== "object" || Array.isArray(record)) return defaultPreferences();
|
|
70
|
+
if (record.status === "valid") return normalizePreferences(record.value) ?? defaultPreferences();
|
|
71
|
+
if (record.status === "absent" && serverCohort === "fresh") return { v: 1, desktopLayout: "focused" };
|
|
72
|
+
} catch {
|
|
73
|
+
// Unreadable fields cannot establish an explicit choice or a fresh default.
|
|
74
|
+
}
|
|
75
|
+
return defaultPreferences();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Explicit writes store only validated preview fields; failures never escape to chat. */
|
|
79
|
+
export function writeShellPreferences(storage, value) {
|
|
80
|
+
let normalized;
|
|
81
|
+
try {
|
|
82
|
+
normalized = normalizePreferences(value);
|
|
83
|
+
} catch {
|
|
84
|
+
return { ok: false, reason: "invalid" };
|
|
85
|
+
}
|
|
86
|
+
if (!normalized) return { ok: false, reason: "invalid" };
|
|
87
|
+
try {
|
|
88
|
+
storage.setItem(SHELL_PREFERENCES_STORAGE_KEY, JSON.stringify(normalized));
|
|
89
|
+
return { ok: true, reason: null };
|
|
90
|
+
} catch {
|
|
91
|
+
return { ok: false, reason: "unavailable" };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function resolveShellMode({
|
|
96
|
+
recovery = false,
|
|
97
|
+
viewportMode = "desktop",
|
|
98
|
+
desktopLayout = "classic",
|
|
99
|
+
phoneMode = "legacy",
|
|
100
|
+
tabletMode = "legacy",
|
|
101
|
+
} = {}) {
|
|
102
|
+
if (recovery === true) return "classic";
|
|
103
|
+
if (viewportMode === "phone" || viewportMode === "tablet") {
|
|
104
|
+
if (!isMobileShellV2Enabled(phoneMode, viewportMode, tabletMode)) return "classic";
|
|
105
|
+
return viewportMode === "phone" ? "mobile-v2" : "tablet-v2";
|
|
106
|
+
}
|
|
107
|
+
return viewportMode === "desktop" && desktopLayout === "focused" ? "focused" : "classic";
|
|
108
|
+
}
|