@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,56 @@
|
|
|
1
|
+
export function createSessionComposerStore() {
|
|
2
|
+
const drafts = new Map();
|
|
3
|
+
const attachments = new Map();
|
|
4
|
+
const pendingCompactions = new Set();
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
getDraft(tabId) {
|
|
8
|
+
return drafts.get(tabId) ?? "";
|
|
9
|
+
},
|
|
10
|
+
setDraft(tabId, draft) {
|
|
11
|
+
if (tabId) drafts.set(tabId, String(draft ?? ""));
|
|
12
|
+
},
|
|
13
|
+
hasDraft(tabId) {
|
|
14
|
+
return drafts.has(tabId);
|
|
15
|
+
},
|
|
16
|
+
deleteDraft(tabId) {
|
|
17
|
+
return drafts.delete(tabId);
|
|
18
|
+
},
|
|
19
|
+
draftEntries() {
|
|
20
|
+
return drafts.entries();
|
|
21
|
+
},
|
|
22
|
+
getAttachments(tabId) {
|
|
23
|
+
return attachments.get(tabId) ?? [];
|
|
24
|
+
},
|
|
25
|
+
ensureAttachments(tabId) {
|
|
26
|
+
if (!tabId) return [];
|
|
27
|
+
if (!attachments.has(tabId)) attachments.set(tabId, []);
|
|
28
|
+
return attachments.get(tabId);
|
|
29
|
+
},
|
|
30
|
+
setAttachments(tabId, items) {
|
|
31
|
+
if (tabId) attachments.set(tabId, items);
|
|
32
|
+
},
|
|
33
|
+
hasAttachments(tabId) {
|
|
34
|
+
return attachments.has(tabId);
|
|
35
|
+
},
|
|
36
|
+
deleteAttachments(tabId) {
|
|
37
|
+
return attachments.delete(tabId);
|
|
38
|
+
},
|
|
39
|
+
clearTab(tabId) {
|
|
40
|
+
drafts.delete(tabId);
|
|
41
|
+
attachments.delete(tabId);
|
|
42
|
+
pendingCompactions.delete(tabId);
|
|
43
|
+
},
|
|
44
|
+
beginCompaction(tabId) {
|
|
45
|
+
if (!tabId || pendingCompactions.has(tabId)) return false;
|
|
46
|
+
pendingCompactions.add(tabId);
|
|
47
|
+
return true;
|
|
48
|
+
},
|
|
49
|
+
endCompaction(tabId) {
|
|
50
|
+
return pendingCompactions.delete(tabId);
|
|
51
|
+
},
|
|
52
|
+
isCompactionPending(tabId) {
|
|
53
|
+
return pendingCompactions.has(tabId);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export function createSessionContext() {
|
|
2
|
+
let activeTabId = null;
|
|
3
|
+
let generation = 0;
|
|
4
|
+
const sessionIdentities = new Map();
|
|
5
|
+
const lifetimes = new Map();
|
|
6
|
+
|
|
7
|
+
function advanceLifetime(tabId) {
|
|
8
|
+
if (tabId) lifetimes.set(tabId, (lifetimes.get(tabId) || 0) + 1);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function capture(tabId = activeTabId) {
|
|
12
|
+
return { tabId: tabId || null, generation };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
get activeTabId() { return activeTabId; },
|
|
17
|
+
get generation() { return generation; },
|
|
18
|
+
activate(tabId) {
|
|
19
|
+
const nextTabId = tabId || null;
|
|
20
|
+
if (nextTabId !== activeTabId) generation += 1;
|
|
21
|
+
activeTabId = nextTabId;
|
|
22
|
+
return capture();
|
|
23
|
+
},
|
|
24
|
+
capture,
|
|
25
|
+
captureLifetime(tabId = activeTabId) {
|
|
26
|
+
return { tabId: tabId || null, revision: lifetimes.get(tabId) || 0 };
|
|
27
|
+
},
|
|
28
|
+
isLifetimeCurrent(context) {
|
|
29
|
+
return !!context?.tabId && context.revision === (lifetimes.get(context.tabId) || 0);
|
|
30
|
+
},
|
|
31
|
+
isCurrent(context) {
|
|
32
|
+
return !!context && context.tabId === activeTabId && context.generation === generation;
|
|
33
|
+
},
|
|
34
|
+
invalidate(tabId = activeTabId) {
|
|
35
|
+
const targetTabId = tabId || null;
|
|
36
|
+
sessionIdentities.delete(targetTabId);
|
|
37
|
+
advanceLifetime(targetTabId);
|
|
38
|
+
if (targetTabId === activeTabId) generation += 1;
|
|
39
|
+
return capture(targetTabId);
|
|
40
|
+
},
|
|
41
|
+
observeSession(tabId, identity) {
|
|
42
|
+
const targetTabId = tabId || null;
|
|
43
|
+
if (!targetTabId || !identity) return { changed: false, context: capture(targetTabId) };
|
|
44
|
+
const changed = sessionIdentities.has(targetTabId) && sessionIdentities.get(targetTabId) !== identity;
|
|
45
|
+
sessionIdentities.set(targetTabId, identity);
|
|
46
|
+
if (changed) advanceLifetime(targetTabId);
|
|
47
|
+
if (changed && targetTabId === activeTabId) generation += 1;
|
|
48
|
+
return { changed, context: capture(targetTabId) };
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
function validIdentifier(value) {
|
|
2
|
+
return typeof value === "string" && value.length > 0;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Keep blocking requests by exact tab/id without sending responses or cancelling
|
|
7
|
+
* work. enqueue returns a boolean; invalid identifiers leave state unchanged.
|
|
8
|
+
* pending lists queued requests only. clear includes active first. Requests keep
|
|
9
|
+
* their original references; ownership keys are captured when enqueued.
|
|
10
|
+
*/
|
|
11
|
+
export function createExtensionRequestStore() {
|
|
12
|
+
let queue = [];
|
|
13
|
+
let active = null;
|
|
14
|
+
|
|
15
|
+
function matches(entry, tabId, id) {
|
|
16
|
+
return entry !== null && entry.tabId === tabId && entry.id === id;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function has(tabId, id) {
|
|
20
|
+
if (!validIdentifier(tabId) || !validIdentifier(id)) return false;
|
|
21
|
+
return matches(active, tabId, id) || queue.some((entry) => matches(entry, tabId, id));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
enqueue(request) {
|
|
26
|
+
const tabId = request?.tabId;
|
|
27
|
+
const id = request?.id;
|
|
28
|
+
if (!validIdentifier(tabId) || !validIdentifier(id) || has(tabId, id)) return false;
|
|
29
|
+
queue.push({ tabId, id, request });
|
|
30
|
+
return true;
|
|
31
|
+
},
|
|
32
|
+
takeNext() {
|
|
33
|
+
if (active || queue.length === 0) return null;
|
|
34
|
+
active = queue.shift();
|
|
35
|
+
return active.request;
|
|
36
|
+
},
|
|
37
|
+
get active() { return active?.request ?? null; },
|
|
38
|
+
has,
|
|
39
|
+
remove(tabId, ids = []) {
|
|
40
|
+
if (!validIdentifier(tabId) || !Array.isArray(ids) || Array.from(ids).some((id) => !validIdentifier(id))) {
|
|
41
|
+
return { activeRemoved: false, pendingRemoved: [] };
|
|
42
|
+
}
|
|
43
|
+
const selected = new Set(ids);
|
|
44
|
+
const activeRemoved = active !== null && active.tabId === tabId && selected.has(active.id);
|
|
45
|
+
const pendingRemoved = [];
|
|
46
|
+
queue = queue.filter((entry) => {
|
|
47
|
+
if (entry.tabId !== tabId || !selected.has(entry.id)) return true;
|
|
48
|
+
pendingRemoved.push(entry.request);
|
|
49
|
+
return false;
|
|
50
|
+
});
|
|
51
|
+
if (activeRemoved) active = null;
|
|
52
|
+
return { activeRemoved, pendingRemoved };
|
|
53
|
+
},
|
|
54
|
+
clear() {
|
|
55
|
+
const requests = queue.map((entry) => entry.request);
|
|
56
|
+
if (active) requests.unshift(active.request);
|
|
57
|
+
active = null;
|
|
58
|
+
queue = [];
|
|
59
|
+
return requests;
|
|
60
|
+
},
|
|
61
|
+
pending() { return queue.map((entry) => entry.request); },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
export const SESSION_SHELF_STORAGE_KEY = "pi-webui-session-shelves-v1";
|
|
2
|
+
|
|
3
|
+
const MAX_SETTLED = 512;
|
|
4
|
+
const MAX_ID_LENGTH = 512;
|
|
5
|
+
const MAX_IDENTITY_LENGTH = 4096;
|
|
6
|
+
// Covers 512 maximum-length marks even when JSON escapes every string character.
|
|
7
|
+
const MAX_STORAGE_LENGTH = 16 * 1024 * 1024;
|
|
8
|
+
const SECTIONS = ["inbox", "working", "settled"];
|
|
9
|
+
const STATES = ["idle", "done", "input", "working"];
|
|
10
|
+
|
|
11
|
+
function validString(value, maxLength) {
|
|
12
|
+
return typeof value === "string" && value.length > 0 && value.length <= maxLength;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function normalizeMark(value) {
|
|
16
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
17
|
+
const { id, identity, completionSerial } = value;
|
|
18
|
+
if (!validString(id, MAX_ID_LENGTH) || !validString(identity, MAX_IDENTITY_LENGTH)
|
|
19
|
+
|| !Number.isSafeInteger(completionSerial) || completionSerial < 0) return null;
|
|
20
|
+
return { id, identity, completionSerial };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function normalizeRecord(value) {
|
|
24
|
+
try {
|
|
25
|
+
const mark = normalizeMark(value);
|
|
26
|
+
const state = value?.state;
|
|
27
|
+
return mark && STATES.includes(state) ? { ...mark, state } : null;
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function readState(storage) {
|
|
34
|
+
const fallback = { settled: new Map(), expanded: { inbox: true, working: true, settled: false } };
|
|
35
|
+
let raw;
|
|
36
|
+
try {
|
|
37
|
+
raw = storage.getItem(SESSION_SHELF_STORAGE_KEY);
|
|
38
|
+
} catch {
|
|
39
|
+
return { ...fallback, blockedReason: "unavailable" };
|
|
40
|
+
}
|
|
41
|
+
if (raw === null) return { ...fallback, blockedReason: null };
|
|
42
|
+
if (typeof raw !== "string" || raw.length > MAX_STORAGE_LENGTH) {
|
|
43
|
+
return { ...fallback, blockedReason: "invalid-storage" };
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const value = JSON.parse(raw);
|
|
47
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("invalid");
|
|
48
|
+
if (Number.isSafeInteger(value.v) && value.v > 1) return { ...fallback, blockedReason: "future-storage" };
|
|
49
|
+
if (value.v !== 1 || !Array.isArray(value.settled) || value.settled.length > MAX_SETTLED
|
|
50
|
+
|| !value.expanded || typeof value.expanded !== "object" || Array.isArray(value.expanded)
|
|
51
|
+
|| !SECTIONS.every((section) => typeof value.expanded[section] === "boolean")) throw new Error("invalid");
|
|
52
|
+
const settled = new Map();
|
|
53
|
+
for (const entry of value.settled) {
|
|
54
|
+
const mark = normalizeMark(entry);
|
|
55
|
+
if (!mark || settled.has(mark.id)) throw new Error("invalid");
|
|
56
|
+
settled.set(mark.id, mark);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
settled,
|
|
60
|
+
expanded: Object.fromEntries(SECTIONS.map((section) => [section, value.expanded[section]])),
|
|
61
|
+
blockedReason: null,
|
|
62
|
+
};
|
|
63
|
+
} catch {
|
|
64
|
+
return { ...fallback, blockedReason: "invalid-storage" };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Browser-local organization only. Caller owns record identity and activity precedence. */
|
|
69
|
+
export function createSessionShelfState({ storage } = {}) {
|
|
70
|
+
const { settled, expanded, blockedReason } = readState(storage);
|
|
71
|
+
let persistence = { ok: blockedReason === null, reason: blockedReason };
|
|
72
|
+
|
|
73
|
+
function serializableState() {
|
|
74
|
+
return { v: 1, settled: [...settled.values()].map((mark) => ({ ...mark })), expanded: { ...expanded } };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function persist() {
|
|
78
|
+
// An unreadable record may belong to a newer client; never replace it implicitly.
|
|
79
|
+
if (blockedReason) return { ...persistence };
|
|
80
|
+
try {
|
|
81
|
+
storage.setItem(SESSION_SHELF_STORAGE_KEY, JSON.stringify(serializableState()));
|
|
82
|
+
persistence = { ok: true, reason: null };
|
|
83
|
+
} catch {
|
|
84
|
+
persistence = { ok: false, reason: "unavailable" };
|
|
85
|
+
}
|
|
86
|
+
return { ...persistence };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
reconcile(records, { pruneMissing = false } = {}) {
|
|
91
|
+
const input = Array.isArray(records) ? records : [];
|
|
92
|
+
const normalized = Array.from(input, normalizeRecord);
|
|
93
|
+
const present = new Set();
|
|
94
|
+
let changed = false;
|
|
95
|
+
for (const record of normalized) {
|
|
96
|
+
if (!record) continue;
|
|
97
|
+
present.add(record.id);
|
|
98
|
+
const mark = settled.get(record.id);
|
|
99
|
+
if (mark && (record.identity !== mark.identity || record.state === "input" || record.state === "working"
|
|
100
|
+
|| record.completionSerial > mark.completionSerial)) {
|
|
101
|
+
settled.delete(record.id);
|
|
102
|
+
changed = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Invalid/partial catalogs cannot establish which sessions no longer exist.
|
|
106
|
+
if (pruneMissing === true && Array.isArray(records) && normalized.every(Boolean)) {
|
|
107
|
+
for (const id of settled.keys()) {
|
|
108
|
+
if (!present.has(id)) {
|
|
109
|
+
settled.delete(id);
|
|
110
|
+
changed = true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (changed) persist();
|
|
115
|
+
const result = { inbox: [], working: [], settled: [], expanded: { ...expanded } };
|
|
116
|
+
input.forEach((record, index) => {
|
|
117
|
+
const current = normalized[index];
|
|
118
|
+
const section = !current ? "inbox" : current.state === "working" ? "working"
|
|
119
|
+
: settled.has(current.id) ? "settled" : "inbox";
|
|
120
|
+
result[section].push(record);
|
|
121
|
+
});
|
|
122
|
+
return result;
|
|
123
|
+
},
|
|
124
|
+
settle(record) {
|
|
125
|
+
const current = normalizeRecord(record);
|
|
126
|
+
if (!current) return { ok: false, reason: "invalid-record" };
|
|
127
|
+
if (current.state === "working" || current.state === "input") return { ok: false, reason: current.state };
|
|
128
|
+
const previous = settled.get(current.id);
|
|
129
|
+
if (previous?.identity === current.identity && previous.completionSerial === current.completionSerial) {
|
|
130
|
+
return { ...persistence };
|
|
131
|
+
}
|
|
132
|
+
if (!previous && settled.size >= MAX_SETTLED) return { ok: false, reason: "limit" };
|
|
133
|
+
settled.set(current.id, { id: current.id, identity: current.identity, completionSerial: current.completionSerial });
|
|
134
|
+
return persist();
|
|
135
|
+
},
|
|
136
|
+
restore(id) {
|
|
137
|
+
if (!validString(id, MAX_ID_LENGTH)) return { ok: false, reason: "invalid-id" };
|
|
138
|
+
return settled.delete(id) ? persist() : { ...persistence };
|
|
139
|
+
},
|
|
140
|
+
setExpanded(section, value) {
|
|
141
|
+
if (!SECTIONS.includes(section)) return { ok: false, reason: "invalid-section" };
|
|
142
|
+
if (typeof value !== "boolean") return { ok: false, reason: "invalid-expanded" };
|
|
143
|
+
if (expanded[section] === value) return { ...persistence };
|
|
144
|
+
expanded[section] = value;
|
|
145
|
+
return persist();
|
|
146
|
+
},
|
|
147
|
+
snapshot() {
|
|
148
|
+
return { ...serializableState(), persistence: { ...persistence } };
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
.session-shelves {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex: 1 1 auto;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
align-self: stretch;
|
|
6
|
+
min-width: 0;
|
|
7
|
+
min-height: 0;
|
|
8
|
+
max-width: 100%;
|
|
9
|
+
overflow: auto;
|
|
10
|
+
overscroll-behavior: contain;
|
|
11
|
+
scrollbar-width: none;
|
|
12
|
+
scrollbar-gutter: auto;
|
|
13
|
+
color: var(--text);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.session-shelves::-webkit-scrollbar { display: none; }
|
|
17
|
+
|
|
18
|
+
.session-shelves .session-shelf {
|
|
19
|
+
flex: 0 0 auto;
|
|
20
|
+
min-width: 0;
|
|
21
|
+
max-width: 100%;
|
|
22
|
+
padding-bottom: 0.35rem;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.session-shelves .session-shelf[data-session-shelf="settled"] {
|
|
26
|
+
margin-top: auto;
|
|
27
|
+
padding-bottom: 0;
|
|
28
|
+
border-top: 1px solid var(--border);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.session-shelves .session-shelf-header {
|
|
32
|
+
display: flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: 0.4rem;
|
|
35
|
+
width: 100%;
|
|
36
|
+
min-width: 0;
|
|
37
|
+
min-height: 1.875rem;
|
|
38
|
+
padding: 0.3rem 0.4rem;
|
|
39
|
+
border: 0;
|
|
40
|
+
border-radius: 0.25rem;
|
|
41
|
+
background: transparent;
|
|
42
|
+
box-shadow: none;
|
|
43
|
+
color: var(--muted);
|
|
44
|
+
font: inherit;
|
|
45
|
+
font-size: var(--text-xs, 0.75rem);
|
|
46
|
+
font-weight: 600;
|
|
47
|
+
line-height: 1.3;
|
|
48
|
+
text-align: left;
|
|
49
|
+
text-transform: none;
|
|
50
|
+
letter-spacing: normal;
|
|
51
|
+
transform: none;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.session-shelves .session-shelf-header:hover {
|
|
55
|
+
background: var(--panel-2);
|
|
56
|
+
color: var(--text);
|
|
57
|
+
box-shadow: none;
|
|
58
|
+
transform: none;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.session-shelves .session-shelf-header:focus-visible {
|
|
62
|
+
outline: 2px solid var(--accent);
|
|
63
|
+
outline-offset: -2px;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.session-shelves .session-shelf-chevron {
|
|
67
|
+
display: inline-grid;
|
|
68
|
+
flex: 0 0 0.75rem;
|
|
69
|
+
place-items: center;
|
|
70
|
+
font-size: 1rem;
|
|
71
|
+
line-height: 1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.session-shelves .session-shelf-header[aria-expanded="true"] .session-shelf-chevron {
|
|
75
|
+
transform: rotate(90deg);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.session-shelves .session-shelf-label {
|
|
79
|
+
min-width: 0;
|
|
80
|
+
overflow: hidden;
|
|
81
|
+
text-overflow: ellipsis;
|
|
82
|
+
white-space: nowrap;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.session-shelves .session-shelf-count {
|
|
86
|
+
flex: 0 0 auto;
|
|
87
|
+
margin-left: auto;
|
|
88
|
+
font-weight: 400;
|
|
89
|
+
font-variant-numeric: tabular-nums;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.session-shelves .session-shelf-body {
|
|
93
|
+
display: flex;
|
|
94
|
+
flex-direction: column;
|
|
95
|
+
gap: 0.3rem;
|
|
96
|
+
min-width: 0;
|
|
97
|
+
padding-block: 0.15rem;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.session-shelves .session-shelf-body[hidden] { display: none; }
|
|
101
|
+
|
|
102
|
+
.session-shelves .session-shelf-body > :is(.terminal-tab, .terminal-tab-group) {
|
|
103
|
+
flex: 0 0 auto;
|
|
104
|
+
width: 100%;
|
|
105
|
+
min-width: 0;
|
|
106
|
+
max-width: 100%;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* Reserve each action independently, including the optional Settle/Restore control. */
|
|
110
|
+
#focusedWorkspace .session-shelves .terminal-tab-actions,
|
|
111
|
+
#focusedWorkspace #tabBar .session-shelves .terminal-tab-actions {
|
|
112
|
+
display: grid;
|
|
113
|
+
grid-auto-flow: column;
|
|
114
|
+
grid-auto-columns: 26px;
|
|
115
|
+
flex: 0 0 auto;
|
|
116
|
+
min-width: max-content;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#focusedWorkspace .session-shelves .terminal-tab-actions > button { flex: 0 0 26px; min-width: 26px; }
|
|
120
|
+
|
|
121
|
+
@media (forced-colors: active) {
|
|
122
|
+
.session-shelves .session-shelf-header:focus-visible { outline-color: Highlight; }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
#focusedWorkspace #tabBar .session-shelves :is(.terminal-tab:not(.terminal-tab-group):not(.terminal-tab-subagent), .terminal-tab-group-item:not(.terminal-tab-subagent)) {
|
|
126
|
+
display: grid;
|
|
127
|
+
grid-template-columns: minmax(0, 1fr) 28px;
|
|
128
|
+
}
|
|
129
|
+
#focusedWorkspace #tabBar .session-shelves :is(.terminal-tab:not(.terminal-tab-group):not(.terminal-tab-subagent), .terminal-tab-group-item:not(.terminal-tab-subagent)) > .terminal-tab-button { grid-column: 1 / -1; }
|
|
130
|
+
#focusedWorkspace #tabBar .session-shelves .terminal-tab-actions {
|
|
131
|
+
grid-column: 1;
|
|
132
|
+
justify-self: end;
|
|
133
|
+
border-left: 0;
|
|
134
|
+
}
|
|
135
|
+
#focusedWorkspace #tabBar .session-shelves :is(.terminal-tab:not(.terminal-tab-group):not(.terminal-tab-subagent), .terminal-tab-group-item:not(.terminal-tab-subagent)) > .terminal-tab-close {
|
|
136
|
+
grid-column: 2;
|
|
137
|
+
grid-row: 2;
|
|
138
|
+
min-height: 28px;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#tabBar .terminal-tab-draft > .terminal-tab-button {
|
|
142
|
+
display: flex;
|
|
143
|
+
flex-direction: column;
|
|
144
|
+
align-items: flex-start;
|
|
145
|
+
min-width: 0;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#tabBar .terminal-tab-draft .terminal-tab-title {
|
|
149
|
+
max-width: 100%;
|
|
150
|
+
overflow: hidden;
|
|
151
|
+
text-overflow: ellipsis;
|
|
152
|
+
white-space: nowrap;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
#focusedWorkspace #tabBar .session-shelves .terminal-tab.terminal-tab-draft:not(.terminal-tab-group):not(.terminal-tab-subagent) > .terminal-tab-button {
|
|
156
|
+
grid-column: 1;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#focusedWorkspace #tabBar .session-shelves .terminal-tab.terminal-tab-draft:not(.terminal-tab-group):not(.terminal-tab-subagent) > .terminal-tab-close {
|
|
160
|
+
grid-row: 1;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.draft-storage-status {
|
|
164
|
+
margin: 0;
|
|
165
|
+
padding: 0.35rem 0.5rem;
|
|
166
|
+
color: var(--text);
|
|
167
|
+
border: 1px solid var(--border);
|
|
168
|
+
border-radius: 0.25rem;
|
|
169
|
+
font-size: var(--text-xs, 0.75rem);
|
|
170
|
+
overflow-wrap: anywhere;
|
|
171
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const SECTIONS = ['inbox', 'working', 'settled'];
|
|
2
|
+
const LABELS = { inbox: 'Inbox', working: 'Working', settled: 'Settled' };
|
|
3
|
+
let nextInstance = 0;
|
|
4
|
+
|
|
5
|
+
function countLabel(value) {
|
|
6
|
+
if (!Number.isSafeInteger(value) || value < 0) return '0';
|
|
7
|
+
return value > 999 ? '999+' : String(value);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hosts caller-owned canonical rows. Toggle callbacks request a state change;
|
|
12
|
+
* the caller applies it through update. Move rows out of slots before dispose
|
|
13
|
+
* to keep them mounted. Otherwise they remain intact in the detached slots.
|
|
14
|
+
*/
|
|
15
|
+
export function createSessionShelves({ document, onToggle } = {}) {
|
|
16
|
+
const element = document.createElement('div');
|
|
17
|
+
element.className = 'session-shelves';
|
|
18
|
+
const slots = {};
|
|
19
|
+
const controls = {};
|
|
20
|
+
const expanded = { inbox: true, working: true, settled: false };
|
|
21
|
+
let disposed = false;
|
|
22
|
+
|
|
23
|
+
for (const section of SECTIONS) {
|
|
24
|
+
let prefix;
|
|
25
|
+
do {
|
|
26
|
+
prefix = `session-shelf-${++nextInstance}`;
|
|
27
|
+
} while (document.getElementById(`${prefix}-label`) || document.getElementById(`${prefix}-body`));
|
|
28
|
+
|
|
29
|
+
const region = document.createElement('section');
|
|
30
|
+
region.className = 'session-shelf';
|
|
31
|
+
region.dataset.sessionShelf = section;
|
|
32
|
+
region.setAttribute('aria-labelledby', `${prefix}-label`);
|
|
33
|
+
|
|
34
|
+
const header = document.createElement('button');
|
|
35
|
+
header.type = 'button';
|
|
36
|
+
header.className = 'session-shelf-header';
|
|
37
|
+
header.dataset.sessionShelfToggle = section;
|
|
38
|
+
header.setAttribute('aria-controls', `${prefix}-body`);
|
|
39
|
+
header.setAttribute('aria-expanded', String(expanded[section]));
|
|
40
|
+
|
|
41
|
+
const chevron = document.createElement('span');
|
|
42
|
+
chevron.className = 'session-shelf-chevron';
|
|
43
|
+
chevron.setAttribute('aria-hidden', 'true');
|
|
44
|
+
chevron.textContent = '›';
|
|
45
|
+
const label = document.createElement('span');
|
|
46
|
+
label.id = `${prefix}-label`;
|
|
47
|
+
label.className = 'session-shelf-label';
|
|
48
|
+
label.textContent = LABELS[section];
|
|
49
|
+
const count = document.createElement('span');
|
|
50
|
+
count.className = 'session-shelf-count';
|
|
51
|
+
count.textContent = '0';
|
|
52
|
+
header.append(chevron, label, count);
|
|
53
|
+
|
|
54
|
+
const body = document.createElement('div');
|
|
55
|
+
body.id = `${prefix}-body`;
|
|
56
|
+
body.className = 'session-shelf-body';
|
|
57
|
+
body.dataset.sessionShelfBody = section;
|
|
58
|
+
body.hidden = !expanded[section];
|
|
59
|
+
region.append(header, body);
|
|
60
|
+
element.append(region);
|
|
61
|
+
slots[section] = body;
|
|
62
|
+
|
|
63
|
+
const toggle = () => {
|
|
64
|
+
if (!disposed) onToggle?.(section, !expanded[section]);
|
|
65
|
+
};
|
|
66
|
+
header.addEventListener('click', toggle);
|
|
67
|
+
controls[section] = { header, count, toggle };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function update({ counts = {}, expanded: nextExpanded = {} } = {}) {
|
|
71
|
+
if (disposed) return;
|
|
72
|
+
for (const section of SECTIONS) {
|
|
73
|
+
const { header, count } = controls[section];
|
|
74
|
+
const body = slots[section];
|
|
75
|
+
if (Object.hasOwn(counts, section)) count.textContent = countLabel(counts[section]);
|
|
76
|
+
if (typeof nextExpanded[section] !== 'boolean') continue;
|
|
77
|
+
expanded[section] = nextExpanded[section];
|
|
78
|
+
if (!expanded[section] && body.contains(document.activeElement)) header.focus({ preventScroll: true });
|
|
79
|
+
header.setAttribute('aria-expanded', String(expanded[section]));
|
|
80
|
+
body.hidden = !expanded[section];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function dispose() {
|
|
85
|
+
if (disposed) return;
|
|
86
|
+
disposed = true;
|
|
87
|
+
for (const section of SECTIONS) {
|
|
88
|
+
const { header, toggle } = controls[section];
|
|
89
|
+
header.removeEventListener('click', toggle);
|
|
90
|
+
}
|
|
91
|
+
element.remove();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return { element, slots, update, dispose };
|
|
95
|
+
}
|