dsh-workspace-browser 0.0.0-stage → 0.4.12
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/LICENSE +21 -0
- package/README.md +23 -2
- package/cordis.patch.yml +3 -0
- package/lib/client.js +1330 -0
- package/lib/index.js +2 -0
- package/package.json +38 -4
- package/scripts/build.mjs +30 -0
- package/src/browser.css +438 -0
- package/src/client.js +1042 -0
- package/src/folder.svg +4 -0
- package/src/gesture.css +30 -0
- package/src/mouse-gestures.js +273 -0
- package/src/session.svg +6 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,1330 @@
|
|
|
1
|
+
// Generated by scripts/build.mjs.
|
|
2
|
+
window.__ModuleLoader__.load({
|
|
3
|
+
id: "dsh-workspace-browser",
|
|
4
|
+
factory(require) {
|
|
5
|
+
const id = "dsh-workspace-browser";
|
|
6
|
+
const react = require('react');
|
|
7
|
+
const { createPortal, flushSync } = require('react-dom');
|
|
8
|
+
const ui = require('@deepseek-ai/dsh-client-ui-primitives');
|
|
9
|
+
const css = "[data-dwb-grid] > :not(.dwb-mount) { display: none; }\n.dwb-mount[hidden] { display: none; }\n.dwb-toolbar-mount[hidden], .dwb-address-mount[hidden] { display: none; }\n\n@property --dwb-reveal-size {\n syntax: '<length>';\n inherits: true;\n initial-value: 0px;\n}\n\n[data-dwb-layout] {\n --dwb-edge-end: 9px;\n --dwb-content-start: 14px;\n --dwb-list-item-padding: 8px;\n --dwb-nav-width: 95px;\n --dwb-tile-start: calc(var(--dwb-content-start) - var(--dwb-list-item-padding));\n --dwb-heading-opacity: 1;\n --dwb-heading-visibility: visible;\n --dwb-heading-hide-delay: 0ms;\n --dwb-reveal-height: 40px;\n --dwb-reveal-delay: 0ms;\n --dwb-reveal-size: 0px;\n --dwb-control-opacity: 0;\n --dwb-control-visibility: hidden;\n --dwb-fade-duration: 42.5ms;\n --dwb-visibility-delay: 42.5ms;\n container-type: inline-size;\n min-block-size: 0;\n position: relative;\n transition: --dwb-reveal-size 95ms ease var(--dwb-reveal-delay);\n}\n\n[data-dwb-layout]:is([data-dwb-reveal-held], [data-dwb-reveal-hover], :has(> .dwb-toolbar-mount .dwb-nav-buttons :focus-visible, > [data-dwb-header] :focus-visible, > .dwb-address-mount :focus-visible)) {\n --dwb-reveal-delay: 50ms;\n --dwb-reveal-size: var(--dwb-reveal-height);\n --dwb-heading-opacity: 0;\n --dwb-heading-visibility: hidden;\n --dwb-heading-hide-delay: 117.5ms;\n --dwb-control-opacity: 1;\n --dwb-control-visibility: visible;\n --dwb-fade-duration: 67.5ms;\n --dwb-visibility-delay: var(--dwb-reveal-delay);\n}\n\n[data-slot='sidebar.workspaces'] [data-dwb-layout] > [data-dwb-grid] {\n margin-inline: 0;\n padding-inline: 0;\n flex: 1 1 0;\n min-block-size: 0;\n display: block;\n overflow: hidden;\n overflow-y: auto;\n overscroll-behavior-y: contain;\n}\n\n.dwb-heading[hidden], [data-dwb-replaced-heading] { display: none; }\n.dwb-heading {\n display: flex;\n align-items: center;\n gap: 4px;\n max-width: calc(100cqi - var(--dsh-sidebar-row-padding, 12px) - 104px);\n min-width: 0;\n flex: none;\n white-space: nowrap;\n line-height: 20px;\n height: 22px;\n position: absolute;\n top: 21px;\n inset-inline-start: var(--dwb-content-start);\n z-index: 3;\n pointer-events: none;\n}\n\n.dwb-heading:has(> .dwb-notifications) {\n /* Center the 22px dot in the same 23px slot as the back arrow. */\n inset-inline-start: calc(var(--dwb-tile-start) + 0.5px);\n}\n\n.dwb-heading-name {\n overflow: hidden;\n text-overflow: ellipsis;\n translate: 0 var(--dwb-reveal-size);\n opacity: var(--dwb-heading-opacity);\n visibility: var(--dwb-heading-visibility);\n transition: opacity 67.5ms ease var(--dwb-reveal-delay), visibility 0s linear var(--dwb-heading-hide-delay);\n}\n\n[data-dwb-header]:has(button[aria-expanded='true']) .dwb-heading-name { display: none; }\n\n[data-slot='sidebar.workspaces'] [data-dwb-layout] > .dwb-toolbar-mount + [data-dwb-header] {\n margin-block-start: 0;\n}\n\n[data-slot='sidebar.workspaces'] [data-dwb-layout] > [data-dwb-header]:has(button[aria-expanded='true']) {\n padding-inline-start: calc(var(--dwb-tile-start) + var(--dwb-nav-width));\n}\n\n[data-slot='sidebar.workspaces'] [data-dwb-layout] > [data-dwb-header]:not(:has(button[aria-expanded='true'])) {\n margin-inline-end: 0;\n /* The native header reserves one 4px gap after its tool group. */\n padding-inline-end: calc(var(--dwb-edge-end) - 4px);\n}\n\n.dwb-menu-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }\n.dwb-menu-label svg { flex: none; }\n\n/* In this grouping mode, only the new grouping row carries a check. */\n[data-dwb-selected] .dwb-native-group > svg:last-child { visibility: hidden; }\n\n.dwb-browser {\n min-width: 0;\n padding: 0 0 10px;\n color: var(--dsw-alias-label-primary);\n font-size: 13px;\n}\n\n.dwb-toolbar-mount { flex: none; }\n.dwb-reveal-zone {\n min-height: 2px;\n padding-block-end: 2px;\n}\n\n.dwb-address-mount {\n flex: none;\n block-size: var(--dwb-reveal-size);\n}\n\n.dwb-reveal-control {\n visibility: var(--dwb-control-visibility);\n opacity: var(--dwb-control-opacity);\n transition: opacity var(--dwb-fade-duration) ease var(--dwb-reveal-delay),\n visibility 0s linear var(--dwb-visibility-delay);\n}\n\n@media (prefers-reduced-motion: reduce) {\n .dwb-reveal-control, .dwb-heading-name, [data-dwb-layout] { transition: none; }\n}\n\n.dwb-divider {\n position: relative;\n width: 100cqi;\n height: 12px;\n touch-action: none;\n}\n\n.dwb-divider[role='separator'] { cursor: row-resize; }\n\n.dwb-divider::before {\n content: '';\n position: absolute;\n inset: 50% 0 auto;\n transform: translateY(-50%);\n pointer-events: none;\n border-top: 0.5px solid var(--dsw-alias-border-l3);\n}\n\n[data-dwb-resized-navigation] {\n height: var(--dwb-navigation-height);\n min-height: 0;\n overflow-y: auto;\n scrollbar-width: thin;\n flex-shrink: 0;\n}\n\n[data-dwb-resized-navigation] > * { flex-shrink: 0; }\n\n.dwb-nav-buttons {\n position: absolute;\n top: 19px;\n inset-inline-start: var(--dwb-tile-start);\n z-index: 2;\n display: flex;\n gap: 1px;\n}\n\n.dwb-nav-buttons .dwb-nav-button {\n width: 23px;\n height: 26px;\n padding: 0;\n justify-content: center;\n}\n\n.dwb-nav-buttons .dwb-nav-button:disabled { cursor: default; }\n\n.dwb-path {\n position: absolute;\n top: calc(59px - var(--dwb-reveal-height));\n translate: 0 var(--dwb-reveal-size);\n inset-inline-start: var(--dwb-tile-start);\n width: calc(100cqi - var(--dwb-tile-start) - var(--dwb-edge-end));\n z-index: 2;\n box-sizing: border-box;\n display: flex;\n align-items: center;\n gap: 2px;\n min-width: 0;\n height: 30px;\n padding: 0 5px;\n overflow-x: auto;\n scrollbar-width: none;\n border: 0.5px solid var(--dsw-alias-border-l3);\n border-radius: var(--dsw-radius-md);\n background: var(--dsw-alias-bg-layer-1);\n}\n\n.dwb-crumb {\n display: inline-flex;\n flex: none;\n align-items: center;\n gap: 2px;\n white-space: nowrap;\n}\n\n.dwb-crumb button { min-height: 24px; height: 24px; padding-inline: 4px; font-size: 12px; }\n.dwb-current { padding: 0 4px; }\n.dwb-indicator { flex: none; color: var(--dsw-alias-label-tertiary); }\n\n.dwb-list {\n box-sizing: border-box;\n display: grid;\n grid-template-columns: repeat(auto-fill, minmax(min(100%, 76px), 1fr));\n gap: 4px 5px;\n list-style: none;\n width: calc(100cqi - var(--dwb-edge-end));\n margin: 8px 0 0;\n padding-inline: var(--dwb-tile-start) 0;\n}\n\n.dwb-list > li { min-width: 0; position: relative; }\n.dwb-list > li[data-dwb-drop]::after {\n content: '';\n pointer-events: none;\n position: absolute;\n z-index: 1;\n border-radius: 2px;\n background: var(--dsw-alias-state-business-primary, #3975ea);\n}\n.dwb-list[data-dwb-display='icons'] > li[data-dwb-drop]::after { inset-block: 0; width: 2px; }\n.dwb-list[data-dwb-display='icons'] > li[data-dwb-drop='before']::after { inset-inline-start: -2px; }\n.dwb-list[data-dwb-display='icons'] > li[data-dwb-drop='after']::after { inset-inline-end: -2px; }\n.dwb-list[data-dwb-display='list'] > li[data-dwb-drop]::after { inset-inline: 0; height: 2px; }\n.dwb-list[data-dwb-display='list'] > li[data-dwb-drop='before']::after { inset-block-start: 0; }\n.dwb-list[data-dwb-display='list'] > li[data-dwb-drop='after']::after { inset-block-end: 0; }\n\n.dwb-list .dwb-tile {\n position: relative;\n width: 100%;\n height: 82px;\n padding: 9px 4px 5px;\n flex-direction: column;\n justify-content: flex-start;\n gap: 5px;\n border-radius: var(--dsw-radius-md);\n font-size: 12px;\n font-weight: 400;\n line-height: 15px;\n color: var(--dsw-alias-label-primary);\n user-select: none;\n}\n\n.dwb-list .dwb-tile {\n --dwb-tile-fill: transparent;\n background: var(--dwb-tile-fill);\n}\n\n.dwb-list .dwb-tile[data-dwb-guide] { --dwb-tile-fill: #F1F3F5; }\n:where([data-ds-dark-theme]) .dwb-list .dwb-tile[data-dwb-guide] { --dwb-tile-fill: var(--dsw-alias-bg-layer-2); }\n\n@media (hover: hover) {\n .dwb-list .dwb-tile:hover { --dwb-tile-fill: var(--dsw-alias-interactive-bg-hover); }\n}\n\n.dwb-list .dwb-tile[aria-pressed='true'] { --dwb-tile-fill: var(--dsw-alias-interactive-bg-hover); }\n\n.dwb-list .dwb-tile[aria-current] {\n --dwb-tile-fill: var(--dsw-alias-interactive-bg-active);\n}\n\n.dwb-list .dwb-tile:is(:hover, :active):not(:disabled) { background: var(--dwb-tile-fill); }\n\n.dwb-tile-icon {\n position: relative;\n display: flex;\n align-items: center;\n justify-content: center;\n color: var(--dsw-alias-label-secondary);\n}\n\n.dwb-tile[aria-current] .dwb-tile-icon { color: var(--dsw-alias-state-business-primary, var(--dsw-alias-label-primary)); }\n.dwb-tile-icon img { display: block; object-fit: contain; }\n.dwb-session-icon {\n display: block;\n background: #C3C3C3;\n mask: center / contain no-repeat;\n}\n.dwb-tile[aria-current] .dwb-session-icon { background: #61666B; }\n\n.dwb-label {\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 2;\n width: 100%;\n overflow: hidden;\n overflow-wrap: anywhere;\n white-space: normal;\n text-align: center;\n}\n\n.dwb-status { margin: 10px 8px; color: var(--dsw-alias-label-secondary); }\n\n.dwb-menu-grid {\n display: block;\n width: 14px;\n height: 14px;\n background: linear-gradient(currentColor 0 0) 0 0 / 6px 6px,\n linear-gradient(currentColor 0 0) 100% 0 / 6px 6px,\n linear-gradient(currentColor 0 0) 0 100% / 6px 6px,\n linear-gradient(currentColor 0 0) 100% 100% / 6px 6px;\n background-repeat: no-repeat;\n}\n\n.dwb-list[data-dwb-display='list'] { grid-template-columns: minmax(0, 1fr); gap: 0; }\n\n.dwb-list[data-dwb-display='list'] .dwb-tile {\n height: 32px;\n padding: 0 var(--dwb-list-item-padding);\n flex-direction: row;\n align-items: center;\n gap: 8px;\n font-size: 14px;\n}\n\n.dwb-list[data-dwb-display='list'] .dwb-tile-icon { flex: none; }\n.dwb-list[data-dwb-display='list'] .dwb-label {\n display: block;\n text-align: start;\n white-space: nowrap;\n text-overflow: ellipsis;\n}\n\n.dwb-notifications { display: inline-flex; align-items: center; flex: none; gap: 2px; }\n.dwb-notification { display: inline-flex; }\n.dwb-notification[data-dwb-notification='done'] {\n --dsw-alias-state-done-primary: #48AD00;\n --dsw-alias-state-success-primary: #48AD00;\n}\n.dwb-notification:is([data-dwb-notification='error'], [data-dwb-notification='warning']) {\n animation: dwb-notification-pulse 1.2s ease-in-out infinite;\n}\n\n.dwb-tile-status, .dwb-status-marks {\n display: flex;\n align-items: center;\n justify-content: flex-end;\n flex-wrap: wrap;\n gap: 2px 4px;\n color: var(--dsw-alias-label-secondary);\n}\n.dwb-tile-status:empty { display: none; }\n.dwb-running {\n display: inline-flex;\n flex: none;\n align-items: center;\n justify-content: center;\n min-block-size: 16px;\n padding-inline: 4px;\n border-radius: 4px;\n background: #D1E4C2;\n color: #3D9300;\n font-size: 11px;\n font-weight: 700;\n line-height: 14px;\n white-space: nowrap;\n}\n.dwb-running[data-dwb-running-count] {\n box-sizing: border-box;\n aspect-ratio: 1;\n block-size: 16px;\n min-inline-size: 16px;\n}\n.dwb-row-mark { display: inline-flex; flex: none; }\n.dwb-tile-status .dwb-notifications { flex-direction: row-reverse; flex-wrap: wrap; justify-content: flex-start; max-inline-size: 100%; }\n\n.dwb-list[data-dwb-display='icons'] .dwb-tile-status {\n --dwb-corner-inset: 3px;\n position: absolute;\n inset: var(--dwb-corner-inset) var(--dwb-corner-inset) auto;\n justify-content: flex-start;\n flex-wrap: nowrap;\n pointer-events: none;\n z-index: 1;\n}\n.dwb-list[data-dwb-display='icons'] .dwb-running {\n border-radius: max(0px, calc(var(--dsw-radius-md) - var(--dwb-corner-inset)));\n}\n.dwb-list[data-dwb-display='icons'] .dwb-tile-status > .dwb-notifications {\n flex: 0 1 auto;\n min-inline-size: 0;\n justify-content: flex-end;\n max-block-size: 24px;\n overflow: hidden;\n}\n.dwb-tile[data-dwb-kind='folder'] .dwb-tile-status,\n.dwb-tile[data-dwb-kind='folder'] .dwb-notifications {\n gap: 4px;\n}\n.dwb-tile[data-dwb-kind='folder'] .dwb-notification {\n /* StateDot paints the middle 60% of its 22px box. Space the visible circles. */\n position: relative;\n flex: none;\n inline-size: 13.2px;\n block-size: 22px;\n}\n.dwb-tile[data-dwb-kind='folder'] .dwb-notification > [data-state] {\n position: absolute;\n inset-inline-start: 50%;\n translate: -50% 0;\n}\n.dwb-tile[data-dwb-kind='folder']:dir(rtl) .dwb-notification > [data-state] {\n translate: 50% 0;\n}\n.dwb-list[data-dwb-display='icons'] .dwb-status-marks {\n flex: none;\n margin-inline-start: auto;\n max-inline-size: 50%;\n max-block-size: 24px;\n overflow: hidden;\n}\n.dwb-list[data-dwb-display='list'] .dwb-tile-status {\n flex: none;\n max-inline-size: 60%;\n max-block-size: 100%;\n overflow-y: auto;\n scrollbar-width: none;\n}\n\n@keyframes dwb-notification-pulse { 50% { opacity: 0.35; } }\n@media (prefers-reduced-motion: reduce) { .dwb-notification[data-dwb-notification] { animation: none; } }\n\n[data-dwb-mouse-gesture-tracking] :is(iframe, webview, object, embed) { pointer-events: none !important; }\r\n[data-dwb-mouse-gesture-dragging] .dwb-mouse-gesture { pointer-events: auto; cursor: default; }\r\n.dwb-mouse-gesture {\r\n position: fixed; inset: 0; z-index: 2147483647;\r\n display: grid; place-items: center; pointer-events: none; user-select: none;\r\n}\r\n.dwb-mouse-gesture > * { pointer-events: none; }\r\n.dwb-mouse-gesture-trail {\r\n position: absolute; inset: 0; width: 100%; height: 100%;\r\n fill: none; stroke: #3262E9; stroke-width: 6px; stroke-linecap: round; stroke-linejoin: round;\r\n}\r\n.dwb-mouse-gesture[data-stable-click] .dwb-mouse-gesture-trail { visibility: hidden; }\r\n.dwb-mouse-gesture[data-finished] .dwb-mouse-gesture-trail {\r\n animation: dwb-mouse-gesture-trail-fade 220ms ease-out forwards;\r\n}\r\n@keyframes dwb-mouse-gesture-trail-fade { to { opacity: 0; } }\r\n.dwb-mouse-gesture-badge {\r\n position: absolute; left: var(--dwb-gesture-badge-x); top: var(--dwb-gesture-badge-y);\r\n transform: translate(-50%, -50%);\r\n display: none; flex-direction: column; align-items: center; justify-content: center;\r\n width: 112px; height: 112px; gap: 8px; border-radius: 20px;\r\n background: rgb(0 0 0 / 74%); color: white; font-size: 14px; font-weight: 600; line-height: 1.25;\r\n}\r\n.dwb-mouse-gesture[data-action] .dwb-mouse-gesture-badge { display: flex; }\r\n.dwb-mouse-gesture-badge svg {\r\n width: 46px; height: 46px; fill: none; stroke: currentColor; stroke-width: 2;\r\n stroke-linecap: round; stroke-linejoin: round;\r\n}\r\n.dwb-mouse-gesture[data-action=\"left\"] .dwb-mouse-gesture-badge svg { transform: rotate(180deg); }\r\n.dwb-mouse-gesture[data-action=\"up\"] .dwb-mouse-gesture-badge svg { transform: rotate(-90deg); }\n";
|
|
10
|
+
const folderIcon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDUiIGhlaWdodD0iNDEiIHZpZXdCb3g9IjAgMCA0NSA0MSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTAgNS41QzAgMi41IDEuNSAwIDUuNSAwSDEzQzE1LjUgMCAxNyAxIDE4LjUgMi41TDIxLjUgNS41QzIyLjUgNi41IDI0IDcgMjUuNSA3SDQwLjVDNDMgNyA0NSA5IDQ1IDExVjM3QzQ1IDM5IDQzLjUgNDEgNDEgNDFINUMyLjUgNDEgMCAzOSAwIDM2LjVWNS41WiIgZmlsbD0iI0MzQzNDMyIvPgo8cmVjdCB4PSIzLjUiIHk9IjEwLjUiIHdpZHRoPSIzOCIgaGVpZ2h0PSI0IiByeD0iMS41IiBmaWxsPSIjRjlGQUZCIi8+Cjwvc3ZnPgo=";
|
|
11
|
+
const sessionIcon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDQiIGhlaWdodD0iNDIiIHZpZXdCb3g9IjAgMCA0NCA0MiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTQuMTA3MjYgMzAuNTIzM0MyLjQ0NzA3IDI3LjcwNjkgMS41MDA0OSAyNC40NTg2IDEuNTAwNDkgMjFDMS41MDA0OSAxMC4yMzA0IDEwLjY3ODcgMS41IDIyLjAwMDUgMS41QzMzLjMyMjMgMS41IDQyLjUwMDUgMTAuMjMwNCA0Mi41MDA1IDIxQzQyLjUwMDUgMzEuNzY5NiAzMy4zMjIzIDQwLjUgMjIuMDAwNSA0MC41QzE4LjU1ODEgNDAuNSAxNS41Nzg1IDM5Ljc2NzIgMTMuNDE5MSAzOC42ODZDMTEuMjU5NyAzNy42MDQ5IDcuMjcwNjkgMzcuNzc5MSA1LjMxNDQ0IDM4LjY4NkMzLjAyNjA3IDM5Ljc0NyAyLjEzNjE1IDQwLjE5NzcgMS41MDA0OSA0MC41IiBzdHJva2Utd2lkdGg9IjMiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlPSIjQzNDM0MzIi8+CjxjaXJjbGUgY3g9IjEzLjAwMDUiIGN5PSIyMSIgcj0iMi41IiBmaWxsPSIjQzNDM0MzIi8+CjxjaXJjbGUgY3g9IjIyLjAwMDUiIGN5PSIyMSIgcj0iMi41IiBmaWxsPSIjQzNDM0MzIi8+CjxjaXJjbGUgY3g9IjMxLjAwMDUiIGN5PSIyMSIgcj0iMi41IiBmaWxsPSIjQzNDM0MzIi8+Cjwvc3ZnPgo=";
|
|
12
|
+
const dragDistance = 2;
|
|
13
|
+
const sampleDistance = 2;
|
|
14
|
+
const minimumStraightness = 0.75;
|
|
15
|
+
const curveTolerance = 10;
|
|
16
|
+
const rightButton = 2;
|
|
17
|
+
const menuDelay = 650;
|
|
18
|
+
const feedbackDelay = 450;
|
|
19
|
+
const recognitionDelay = 34;
|
|
20
|
+
const trackingAttribute = 'data-dwb-mouse-gesture-tracking';
|
|
21
|
+
const draggingAttribute = 'data-dwb-mouse-gesture-dragging';
|
|
22
|
+
|
|
23
|
+
function recordPoint(gesture, { clientX: x, clientY: y, timeStamp }) {
|
|
24
|
+
// Pointer and compatibility mouse events may report the same samples.
|
|
25
|
+
if (timeStamp < gesture.lastSampleTime) return;
|
|
26
|
+
gesture.lastSampleTime = timeStamp;
|
|
27
|
+
const last = gesture.points.at(-1);
|
|
28
|
+
const segment = Math.hypot(x - last.x, y - last.y);
|
|
29
|
+
const start = gesture.points[0];
|
|
30
|
+
gesture.tip = { x, y, remainder: segment };
|
|
31
|
+
if (segment >= sampleDistance) {
|
|
32
|
+
gesture.points.push(gesture.tip);
|
|
33
|
+
gesture.length += segment;
|
|
34
|
+
gesture.tip.remainder = 0;
|
|
35
|
+
}
|
|
36
|
+
gesture.maxDistance = Math.max(gesture.maxDistance, Math.hypot(x - start.x, y - start.y));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isStableClick(gesture) {
|
|
40
|
+
return gesture.maxDistance < dragDistance;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function directionOf(gesture) {
|
|
44
|
+
const start = gesture.points[0];
|
|
45
|
+
const x = gesture.tip.x - start.x;
|
|
46
|
+
const y = gesture.tip.y - start.y;
|
|
47
|
+
const distance = Math.hypot(x, y);
|
|
48
|
+
const length = gesture.length + gesture.tip.remainder;
|
|
49
|
+
// A straight stroke has a ratio of one. Detours and reversals increase the traveled length.
|
|
50
|
+
if (distance < dragDistance || (length - distance > curveTolerance && distance < length * minimumStraightness)) {
|
|
51
|
+
return 'invalid';
|
|
52
|
+
}
|
|
53
|
+
// The diagonals are the 45° boundaries between the four directions.
|
|
54
|
+
if (Math.abs(x) >= Math.abs(y)) return x < 0 ? 'left' : 'right';
|
|
55
|
+
return y < 0 ? 'up' : 'invalid';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function createFeedback(getBadgeBounds, actionLabel) {
|
|
59
|
+
const overlay = document.createElement('div');
|
|
60
|
+
overlay.className = 'dwb-mouse-gesture';
|
|
61
|
+
overlay.setAttribute('aria-hidden', 'true');
|
|
62
|
+
overlay.innerHTML = [
|
|
63
|
+
'<svg class="dwb-mouse-gesture-trail"><polyline /></svg>',
|
|
64
|
+
'<div class="dwb-mouse-gesture-badge">',
|
|
65
|
+
'<svg viewBox="0 0 24 24"><path /></svg><span></span>',
|
|
66
|
+
'</div>',
|
|
67
|
+
].join('');
|
|
68
|
+
const trail = overlay.querySelector('polyline');
|
|
69
|
+
const icon = overlay.querySelector('.dwb-mouse-gesture-badge path');
|
|
70
|
+
const label = overlay.querySelector('span');
|
|
71
|
+
let timer;
|
|
72
|
+
let frame;
|
|
73
|
+
let displayed;
|
|
74
|
+
|
|
75
|
+
function hide() {
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
cancelAnimationFrame(frame);
|
|
78
|
+
frame = undefined;
|
|
79
|
+
displayed = undefined;
|
|
80
|
+
trail.removeAttribute('points');
|
|
81
|
+
overlay.removeAttribute('data-finished');
|
|
82
|
+
overlay.removeAttribute('data-action');
|
|
83
|
+
overlay.removeAttribute('data-stable-click');
|
|
84
|
+
overlay.remove();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function render(gesture) {
|
|
88
|
+
const points = gesture.points.map(({ x, y }) => x + ',' + y);
|
|
89
|
+
points.push(gesture.tip.x + ',' + gesture.tip.y);
|
|
90
|
+
trail.setAttribute('points', points.join(' '));
|
|
91
|
+
overlay.toggleAttribute('data-stable-click', isStableClick(gesture));
|
|
92
|
+
if (!overlay.isConnected) document.body.append(overlay);
|
|
93
|
+
displayed = gesture;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function draw(gesture) {
|
|
97
|
+
if (frame !== undefined) return;
|
|
98
|
+
frame = requestAnimationFrame(() => {
|
|
99
|
+
frame = undefined;
|
|
100
|
+
render(gesture);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function finish(gesture) {
|
|
105
|
+
cancelAnimationFrame(frame);
|
|
106
|
+
frame = undefined;
|
|
107
|
+
render(gesture);
|
|
108
|
+
overlay.setAttribute('data-finished', '');
|
|
109
|
+
timer = setTimeout(hide, feedbackDelay);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function showAction(gesture, action) {
|
|
113
|
+
if (displayed !== gesture) return;
|
|
114
|
+
const bounds = getBadgeBounds();
|
|
115
|
+
if (!bounds) return;
|
|
116
|
+
overlay.style.setProperty('--dwb-gesture-badge-x', bounds.left + bounds.width / 2 + 'px');
|
|
117
|
+
overlay.style.setProperty('--dwb-gesture-badge-y', bounds.top + bounds.height / 2 + 'px');
|
|
118
|
+
overlay.dataset.action = action;
|
|
119
|
+
icon.setAttribute('d', action === 'invalid' ? 'M6 6l12 12M18 6 6 18' : 'M5 12h14m-6-6 6 6-6 6');
|
|
120
|
+
label.textContent = actionLabel(action);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return { draw, render, finish, showAction, hide, overlay };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function installMouseGestures(resolveAction, getBadgeBounds, acceptsTarget, actionLabel) {
|
|
127
|
+
const lifetime = new AbortController();
|
|
128
|
+
const options = { capture: true, signal: lifetime.signal };
|
|
129
|
+
const feedback = createFeedback(getBadgeBounds, actionLabel);
|
|
130
|
+
const root = document.documentElement;
|
|
131
|
+
let gesture;
|
|
132
|
+
let suppressMenuUntil = -Infinity;
|
|
133
|
+
|
|
134
|
+
function cancel() {
|
|
135
|
+
if (gesture) gesture.cancelled = true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function block(event) {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
event.stopImmediatePropagation();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function start(event) {
|
|
144
|
+
if (gesture && (!isStableClick(gesture) || event.button !== rightButton)) {
|
|
145
|
+
block(event);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const pointer = event.type === 'pointerdown';
|
|
149
|
+
if (pointer && event.pointerType !== 'mouse') return;
|
|
150
|
+
if (event.button !== rightButton || !(event.buttons & rightButton)) return;
|
|
151
|
+
if (!pointer && gesture && gesture.id !== undefined) return;
|
|
152
|
+
gesture = undefined;
|
|
153
|
+
suppressMenuUntil = -Infinity;
|
|
154
|
+
feedback.hide();
|
|
155
|
+
root.removeAttribute(trackingAttribute);
|
|
156
|
+
const target = event.target;
|
|
157
|
+
if (!(target instanceof Element) || !acceptsTarget(target)) return;
|
|
158
|
+
const origin = { x: event.clientX, y: event.clientY, remainder: 0 };
|
|
159
|
+
gesture = {
|
|
160
|
+
id: pointer ? event.pointerId : undefined,
|
|
161
|
+
points: [origin],
|
|
162
|
+
tip: origin,
|
|
163
|
+
length: 0,
|
|
164
|
+
maxDistance: 0,
|
|
165
|
+
lastSampleTime: event.timeStamp,
|
|
166
|
+
perform: resolveAction(target),
|
|
167
|
+
};
|
|
168
|
+
feedback.draw(gesture);
|
|
169
|
+
// Chromium can send the first fast move straight to an embedded preview.
|
|
170
|
+
root.setAttribute(trackingAttribute, '');
|
|
171
|
+
// Capture on the original hit target so a click still opens that target's menu.
|
|
172
|
+
// Capturing at press also keeps the first fast move when it crosses a pane or frame.
|
|
173
|
+
if (pointer) {
|
|
174
|
+
try { target.setPointerCapture(event.pointerId); } catch { /* The mouse listeners can finish the stroke. */ }
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function move(event) {
|
|
179
|
+
if (!gesture || (event.pointerType && event.pointerType !== 'mouse')) return;
|
|
180
|
+
if (gesture.outside && !(event.buttons & rightButton)) {
|
|
181
|
+
complete(event.timeStamp);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
gesture.outside = event.clientX < 0 || event.clientX >= innerWidth
|
|
185
|
+
|| event.clientY < 0 || event.clientY >= innerHeight;
|
|
186
|
+
for (const point of event.getCoalescedEvents?.() ?? []) recordPoint(gesture, point);
|
|
187
|
+
recordPoint(gesture, event);
|
|
188
|
+
if (!isStableClick(gesture)) {
|
|
189
|
+
if (!root.hasAttribute(draggingAttribute)) {
|
|
190
|
+
feedback.render(gesture);
|
|
191
|
+
root.setAttribute(draggingAttribute, '');
|
|
192
|
+
if (gesture.id !== undefined) {
|
|
193
|
+
try { feedback.overlay.setPointerCapture(gesture.id); } catch { /* Window capture listeners still isolate the stroke. */ }
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
block(event);
|
|
197
|
+
}
|
|
198
|
+
feedback.draw(gesture);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function release(event) {
|
|
202
|
+
if (!gesture) return;
|
|
203
|
+
if (event.button !== rightButton) { block(event); return; }
|
|
204
|
+
if (event.pointerType && event.pointerType !== 'mouse') return;
|
|
205
|
+
recordPoint(gesture, event);
|
|
206
|
+
if (!isStableClick(gesture)) block(event);
|
|
207
|
+
complete(event.timeStamp);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function complete(timeStamp) {
|
|
211
|
+
const finished = gesture;
|
|
212
|
+
gesture = undefined;
|
|
213
|
+
root.removeAttribute(trackingAttribute);
|
|
214
|
+
root.removeAttribute(draggingAttribute);
|
|
215
|
+
if (isStableClick(finished) || finished.aborted) {
|
|
216
|
+
feedback.hide();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
suppressMenuUntil = timeStamp + menuDelay;
|
|
220
|
+
feedback.finish(finished);
|
|
221
|
+
setTimeout(() => {
|
|
222
|
+
if (lifetime.signal.aborted) return;
|
|
223
|
+
const action = finished.cancelled ? 'invalid' : directionOf(finished);
|
|
224
|
+
feedback.showAction(finished, finished.perform ? action : 'invalid');
|
|
225
|
+
if (action !== 'invalid') finished.perform?.(action);
|
|
226
|
+
}, recognitionDelay);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function contextMenu(event) {
|
|
230
|
+
if (event.button !== rightButton && event.pointerType !== 'mouse') return;
|
|
231
|
+
if (gesture && !(event.buttons & rightButton)) {
|
|
232
|
+
recordPoint(gesture, event);
|
|
233
|
+
complete(event.timeStamp);
|
|
234
|
+
}
|
|
235
|
+
if ((!gesture || isStableClick(gesture)) && event.timeStamp > suppressMenuUntil) return;
|
|
236
|
+
event.preventDefault();
|
|
237
|
+
event.stopImmediatePropagation();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function guardInteraction(event) {
|
|
241
|
+
if (gesture && !isStableClick(gesture)) block(event);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function abort() {
|
|
245
|
+
if (!gesture) return;
|
|
246
|
+
const { id } = gesture;
|
|
247
|
+
gesture.aborted = true;
|
|
248
|
+
complete(performance.now());
|
|
249
|
+
if (id !== undefined && feedback.overlay.hasPointerCapture(id)) feedback.overlay.releasePointerCapture(id);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
window.addEventListener('pointerdown', start, options);
|
|
253
|
+
window.addEventListener('mousedown', start, options);
|
|
254
|
+
window.addEventListener('pointermove', move, options);
|
|
255
|
+
window.addEventListener('mousemove', move, options);
|
|
256
|
+
window.addEventListener('pointerout', event => {
|
|
257
|
+
if (!event.relatedTarget && (event.buttons & rightButton)) move(event);
|
|
258
|
+
}, options);
|
|
259
|
+
window.addEventListener('pointerup', release, options);
|
|
260
|
+
window.addEventListener('mouseup', release, options);
|
|
261
|
+
window.addEventListener('pointercancel', abort, options);
|
|
262
|
+
for (const type of ['click', 'dblclick', 'wheel', 'dragstart', 'pointerover', 'pointerout', 'mouseover', 'mouseout']) {
|
|
263
|
+
window.addEventListener(type, guardInteraction, { ...options, passive: false });
|
|
264
|
+
}
|
|
265
|
+
window.addEventListener('keydown', event => {
|
|
266
|
+
if (event.key === 'Escape' && gesture) cancel();
|
|
267
|
+
}, options);
|
|
268
|
+
window.addEventListener('contextmenu', contextMenu, options);
|
|
269
|
+
window.addEventListener('auxclick', event => {
|
|
270
|
+
guardInteraction(event);
|
|
271
|
+
if (event.button === rightButton) contextMenu(event);
|
|
272
|
+
}, options);
|
|
273
|
+
window.addEventListener('blur', event => {
|
|
274
|
+
// Capture also sees blur from inputs and rows when the right press moves focus.
|
|
275
|
+
if (event.target !== window) return;
|
|
276
|
+
abort();
|
|
277
|
+
}, options);
|
|
278
|
+
return () => {
|
|
279
|
+
lifetime.abort();
|
|
280
|
+
feedback.hide();
|
|
281
|
+
root.removeAttribute(trackingAttribute);
|
|
282
|
+
root.removeAttribute(draggingAttribute);
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const { createElement: h, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } = react;
|
|
287
|
+
const {
|
|
288
|
+
Button, MenuItemButton, StateDot, IconCheckOutlineRegular, IconChevronLeftOutlineRegular, IconChevronRightOutlineRegular,
|
|
289
|
+
IconChevronUpOutlineRegular, IconFolderOpenRegular,
|
|
290
|
+
IconPinFillRegular, IconFlatListOutlineRegular, IconArchiveOutlineRegular, IconClockOutlineRegular,
|
|
291
|
+
} = ui;
|
|
292
|
+
|
|
293
|
+
const inject = ['slots', 'locale', 'workspaces', 'sessions', 'uiSession', 'uiWorkspace', 'layout', 'remote', 'remote.schedule'];
|
|
294
|
+
const ungrouped = '';
|
|
295
|
+
const defaultOptions = {};
|
|
296
|
+
const emptyView = { getSnapshot: () => defaultOptions, subscribe: () => () => {} };
|
|
297
|
+
const preferenceKey = `${id}.sidebar`;
|
|
298
|
+
const unreadKey = preferenceKey + '.unread';
|
|
299
|
+
const emptyOrder = {};
|
|
300
|
+
const emptySchedule = { records: [] };
|
|
301
|
+
function scheduleSourceFor(ctx) {
|
|
302
|
+
let snapshot = emptySchedule;
|
|
303
|
+
let revision = 0;
|
|
304
|
+
return {
|
|
305
|
+
getSnapshot: () => snapshot,
|
|
306
|
+
subscribe(listener) {
|
|
307
|
+
async function refresh() {
|
|
308
|
+
const request = ++revision;
|
|
309
|
+
try {
|
|
310
|
+
const result = await ctx.remote.schedule.catalog();
|
|
311
|
+
if (request !== revision || !result.ok) return;
|
|
312
|
+
snapshot = { records: result.value };
|
|
313
|
+
listener();
|
|
314
|
+
} catch {
|
|
315
|
+
// A later catalog change or reconnect retries the read.
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const stopChanged = ctx.remote.$on('schedule/changed', refresh);
|
|
319
|
+
const stopReset = ctx.on('connection/reset', refresh);
|
|
320
|
+
refresh();
|
|
321
|
+
return () => {
|
|
322
|
+
revision++;
|
|
323
|
+
stopChanged();
|
|
324
|
+
stopReset();
|
|
325
|
+
};
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
const folderKey = key => 'folder:' + key;
|
|
330
|
+
const sessionKey = key => 'session:' + key;
|
|
331
|
+
const pageKey = folder => folder === null ? 'home' : folderKey(folder);
|
|
332
|
+
|
|
333
|
+
// The native new-session button carries no stable attribute, so it is recognised
|
|
334
|
+
// by its own new-chat glyph or by a shortcut, minus the sidebar toggles and
|
|
335
|
+
// everything inside the workspaces region (add workspace also has a shortcut).
|
|
336
|
+
function isNewSessionButton(button) {
|
|
337
|
+
if (!button || button.disabled) return false;
|
|
338
|
+
if (button.closest('[data-sidebar-toggle], [data-sidebar-opener], [data-slot="sidebar.workspaces"]')) return false;
|
|
339
|
+
return Boolean(button.querySelector('[data-icon^="dsw-icon-new-chat"]')) || button.hasAttribute('aria-keyshortcuts');
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function getNewSessionButton(event) {
|
|
343
|
+
const button = event.target instanceof Element ? event.target.closest('button') : null;
|
|
344
|
+
return isNewSessionButton(button) && button.closest('[data-slot="sidebar"]') ? button : null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const dictionaries = {
|
|
348
|
+
zh: {
|
|
349
|
+
panel: '文件夹浏览', home: '主页', path: '工作区路径', back: '后退', forward: '前进', up: '上一级',
|
|
350
|
+
ungrouped: '未分组会话', locate: '回到当前会话', createError: '暂时无法新建会话。',
|
|
351
|
+
loading: '正在加载…', loadError: '暂时无法读取工作区。', openError: '暂时无法打开此会话。',
|
|
352
|
+
emptyHome: '还没有工作区。', emptyFolder: '此工作区没有子工作区或会话。', noArchives: '没有已归档会话。',
|
|
353
|
+
archived: '已归档会话', scheduled: '有定时任务', running: '运行中', oneRunningSession: '1 个会话运行中', runningSessions: '{n} 个会话运行中',
|
|
354
|
+
gestureUp: '返回上一级', gestureInvalid: '无效手势',
|
|
355
|
+
display: '视图选项', icons: '大图标', list: '列表', resize: '调整工作区分隔位置',
|
|
356
|
+
},
|
|
357
|
+
en: {
|
|
358
|
+
panel: 'Browse folders', home: 'Home', path: 'Workspace path', back: 'Back', forward: 'Forward', up: 'Up one level',
|
|
359
|
+
ungrouped: 'Ungrouped sessions', locate: 'Go to current session', createError: 'Could not start a new session.',
|
|
360
|
+
loading: 'Loading…', loadError: 'Could not load workspaces.', openError: 'Could not open this session.',
|
|
361
|
+
emptyHome: 'No workspaces yet.', emptyFolder: 'No child workspaces or sessions in this workspace.',
|
|
362
|
+
noArchives: 'No archived sessions.', archived: 'Archived session', scheduled: 'Has scheduled tasks', running: 'Running',
|
|
363
|
+
runningSessions: '{n} sessions running', oneRunningSession: '1 session running',
|
|
364
|
+
gestureUp: 'Up one level', gestureInvalid: 'Invalid gesture',
|
|
365
|
+
display: 'View options', icons: 'Large icons', list: 'List', resize: 'Resize workspace area',
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
function workspacePath(path) {
|
|
370
|
+
const windows = /^[A-Za-z]:[/\\]/.test(path) || path.startsWith('\\\\');
|
|
371
|
+
const normalized = (windows ? path.replaceAll('\\', '/') : path).replace(/\/+$/, '');
|
|
372
|
+
return { normalized, folded: windows ? normalized.toLowerCase() : undefined };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function workspaceTree(items) {
|
|
376
|
+
const byId = new Map(items.map(item => [item.workspaceId, item]));
|
|
377
|
+
const paths = new Map(items.map(item => [item.path, item.workspaceId]));
|
|
378
|
+
const folders = [...paths].map(([path, id]) => ({ ...workspacePath(path), id }));
|
|
379
|
+
const parents = new Map();
|
|
380
|
+
const children = new Map();
|
|
381
|
+
for (const item of items) {
|
|
382
|
+
const child = workspacePath(item.path);
|
|
383
|
+
let parent = null;
|
|
384
|
+
let length = -1;
|
|
385
|
+
let exactParent = false;
|
|
386
|
+
for (const folder of folders) {
|
|
387
|
+
if (folder.normalized.length >= child.normalized.length || folder.normalized.length < length) continue;
|
|
388
|
+
const exact = child.normalized.startsWith(`${folder.normalized}/`);
|
|
389
|
+
const folded = folder.folded !== undefined && child.folded?.startsWith(`${folder.folded}/`);
|
|
390
|
+
if ((!exact && !folded) || (folder.normalized.length === length && (exactParent || !exact))) continue;
|
|
391
|
+
parent = folder.id;
|
|
392
|
+
length = folder.normalized.length;
|
|
393
|
+
exactParent = exact;
|
|
394
|
+
}
|
|
395
|
+
parents.set(item.workspaceId, parent);
|
|
396
|
+
if (!children.has(parent)) children.set(parent, []);
|
|
397
|
+
children.get(parent).push(item);
|
|
398
|
+
}
|
|
399
|
+
return { byId, parents, children };
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function sessionRows(workspaceState, sessions, options) {
|
|
403
|
+
const { byId, ids } = sessions;
|
|
404
|
+
const archived = new Set(workspaceState.archivedSessionIds);
|
|
405
|
+
const pinned = new Set(workspaceState.pinnedSessionIds);
|
|
406
|
+
const assigned = new Set(workspaceState.items.flatMap(workspace => workspace.sessionIds));
|
|
407
|
+
const filter = options.archivedFilter ?? 'default';
|
|
408
|
+
const visible = session => session && session.origin !== 'subagent' && (!session.blank || session.retainedBy?.mainView > 0)
|
|
409
|
+
&& (filter === 'show' || (filter === 'only') === archived.has(session.id));
|
|
410
|
+
const sorted = (members, account) => {
|
|
411
|
+
const manual = options.orderBy === 'manual';
|
|
412
|
+
const order = new Map((manual ? options.sessionOrderByAccount?.[account] ?? [] : []).map((id, index) => [id, index]));
|
|
413
|
+
const rank = session => session.blank ? 0 : pinned.has(session.id) && !archived.has(session.id) ? 1 : 2;
|
|
414
|
+
return members.map(id => byId[id]).filter(visible).sort((a, b) => rank(a) - rank(b)
|
|
415
|
+
|| (order.get(a.id) ?? Infinity) - (order.get(b.id) ?? Infinity)
|
|
416
|
+
|| (manual ? Number(archived.has(a.id)) - Number(archived.has(b.id)) : 0)
|
|
417
|
+
|| b.updatedAt - a.updatedAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
418
|
+
};
|
|
419
|
+
const byWorkspace = new Map(workspaceState.items.map(workspace => [workspace.workspaceId, sorted(workspace.sessionIds, workspace.workspaceId)]));
|
|
420
|
+
byWorkspace.set(ungrouped, sorted(ids.filter(id => !assigned.has(id)), ungrouped));
|
|
421
|
+
return { byWorkspace, pinned, archived };
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const statusDetails = {
|
|
425
|
+
approval: { state: 'error', label: 'status.waitingApproval', priority: 3 },
|
|
426
|
+
question: { state: 'warning', label: 'status.waitingAnswer', priority: 2 },
|
|
427
|
+
'plan-review': { state: 'warning', label: 'status.planReview', priority: 2 },
|
|
428
|
+
completed: { state: 'done', label: 'status.completed', priority: 1 },
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
function completionSource(ctx) {
|
|
432
|
+
const list = ctx.sessions.list;
|
|
433
|
+
const status = ctx.uiSession.sessionStatus;
|
|
434
|
+
const panel = ctx.layout.panelInfo;
|
|
435
|
+
const listeners = new Set();
|
|
436
|
+
let unread = new Set();
|
|
437
|
+
try {
|
|
438
|
+
const saved = JSON.parse(localStorage.getItem(unreadKey));
|
|
439
|
+
if (Array.isArray(saved)) unread = new Set(saved.filter(id => typeof id === 'string'));
|
|
440
|
+
} catch { /* Storage may be unavailable. */ }
|
|
441
|
+
|
|
442
|
+
let previous = new Set();
|
|
443
|
+
function sync() {
|
|
444
|
+
const sessions = list.getSnapshot();
|
|
445
|
+
const completed = new Set();
|
|
446
|
+
const next = new Set(unread);
|
|
447
|
+
for (const [id, state] of status.getSnapshot()) {
|
|
448
|
+
if (!state.completionUnread) continue;
|
|
449
|
+
completed.add(id);
|
|
450
|
+
if (!previous.has(id)) next.add(id);
|
|
451
|
+
}
|
|
452
|
+
previous = completed;
|
|
453
|
+
|
|
454
|
+
const conversationVisible = panel.getSnapshot().activePanelId === null;
|
|
455
|
+
for (const id of next) {
|
|
456
|
+
const session = sessions.byId[id];
|
|
457
|
+
if ((!session && sessions.phase === 'ready') || (conversationVisible && session?.retainedBy?.mainView > 0)) {
|
|
458
|
+
next.delete(id);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
if (next.size === unread.size && [...next].every(id => unread.has(id))) return;
|
|
462
|
+
unread = next;
|
|
463
|
+
try { localStorage.setItem(unreadKey, JSON.stringify([...unread])); } catch { /* Keep the in-memory state. */ }
|
|
464
|
+
for (const listener of listeners) listener();
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
ctx.effect(() => {
|
|
468
|
+
const stops = [status.subscribe(sync), list.subscribe(sync), panel.subscribe(sync)];
|
|
469
|
+
sync();
|
|
470
|
+
return () => stops.forEach(stop => stop());
|
|
471
|
+
});
|
|
472
|
+
return {
|
|
473
|
+
getSnapshot: () => unread,
|
|
474
|
+
subscribe(listener) {
|
|
475
|
+
listeners.add(listener);
|
|
476
|
+
return () => listeners.delete(listener);
|
|
477
|
+
},
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function workspaceNotifications(workspaces, sessions, statuses, parents, archived, unread) {
|
|
482
|
+
const owners = new Map();
|
|
483
|
+
for (const workspace of workspaces) {
|
|
484
|
+
for (const sessionId of workspace.sessionIds) owners.set(sessionId, workspace.workspaceId);
|
|
485
|
+
}
|
|
486
|
+
const bySession = new Map();
|
|
487
|
+
const byFolder = new Map();
|
|
488
|
+
const runningBySession = new Map();
|
|
489
|
+
const runningByFolder = new Map();
|
|
490
|
+
for (const id of sessions.ids) {
|
|
491
|
+
const session = sessions.byId[id];
|
|
492
|
+
if (!session || session.blank || session.origin === 'subagent' || archived.has(id)) continue;
|
|
493
|
+
const running = (statuses.get(id)?.running ?? session.running) === true;
|
|
494
|
+
const subagents = sessions.projectionsBySession?.[id]?.values?.subagentCatalog?.filter(child =>
|
|
495
|
+
(statuses.get(child.id)?.running ?? sessions.byId[child.id]?.running) === true).length ?? 0;
|
|
496
|
+
if (running || subagents > 0) runningBySession.set(id, { running, subagents });
|
|
497
|
+
if (!running) continue;
|
|
498
|
+
for (let folder = owners.get(id) ?? ungrouped; folder !== null; folder = parents.get(folder) ?? null) {
|
|
499
|
+
runningByFolder.set(folder, (runningByFolder.get(folder) ?? 0) + 1);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
const all = [];
|
|
503
|
+
for (const sessionId of sessions.ids) {
|
|
504
|
+
const session = sessions.byId[sessionId];
|
|
505
|
+
if (!session || session.blank || session.origin === 'subagent' || archived.has(sessionId)) continue;
|
|
506
|
+
const detail = statusDetails[statuses.get(sessionId)?.pendingInteraction?.kind]
|
|
507
|
+
?? (unread.has(sessionId) && !runningBySession.has(sessionId) ? statusDetails.completed : undefined);
|
|
508
|
+
if (!detail) continue;
|
|
509
|
+
const notification = { ...detail, sessionId };
|
|
510
|
+
bySession.set(sessionId, notification);
|
|
511
|
+
all.push(notification);
|
|
512
|
+
for (let folder = owners.get(sessionId) ?? ungrouped; folder !== null; folder = parents.get(folder) ?? null) {
|
|
513
|
+
if (!byFolder.has(folder)) byFolder.set(folder, []);
|
|
514
|
+
byFolder.get(folder).push(notification);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
for (const notifications of byFolder.values()) notifications.sort((a, b) => b.priority - a.priority);
|
|
518
|
+
return { bySession, byFolder, all, runningBySession, runningByFolder };
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function NotificationDots({ entries, translate, size }) {
|
|
522
|
+
return h('span', { className: 'dwb-notifications' }, entries.map(entry => {
|
|
523
|
+
const label = translate(entry.label);
|
|
524
|
+
return h('span', { key: entry.sessionId, role: 'img', 'aria-label': label, title: label,
|
|
525
|
+
className: 'dwb-notification', 'data-dwb-notification': entry.state }, h(StateDot, { state: entry.state, size }));
|
|
526
|
+
}));
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function readPreference() {
|
|
530
|
+
try { return JSON.parse(localStorage.getItem(preferenceKey)) ?? {}; }
|
|
531
|
+
catch { return {}; }
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function savePreference(value) {
|
|
535
|
+
try { localStorage.setItem(preferenceKey, JSON.stringify(value)); }
|
|
536
|
+
catch { /* The view can still be used without storage. */ }
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function usePageFade() {
|
|
540
|
+
const running = useRef(new Map());
|
|
541
|
+
useEffect(() => () => {
|
|
542
|
+
for (const animation of running.current.values()) animation.cancel();
|
|
543
|
+
running.current.clear();
|
|
544
|
+
}, []);
|
|
545
|
+
|
|
546
|
+
const [fade] = useState(() => async (element, update) => {
|
|
547
|
+
if (!element?.isConnected || matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
548
|
+
update();
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
const animations = running.current;
|
|
552
|
+
const opacity = getComputedStyle(element).opacity;
|
|
553
|
+
animations.get(element)?.cancel();
|
|
554
|
+
const outgoing = element.animate([{ opacity }, { opacity: 0 }], { duration: 42.5, easing: 'ease-out', fill: 'forwards' });
|
|
555
|
+
animations.set(element, outgoing);
|
|
556
|
+
try {
|
|
557
|
+
await outgoing.finished;
|
|
558
|
+
if (animations.get(element) !== outgoing || !element.isConnected) return;
|
|
559
|
+
flushSync(update);
|
|
560
|
+
const incoming = element.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 67.5, easing: 'ease-in-out' });
|
|
561
|
+
outgoing.cancel();
|
|
562
|
+
animations.set(element, incoming);
|
|
563
|
+
await incoming.finished;
|
|
564
|
+
if (animations.get(element) === incoming) animations.delete(element);
|
|
565
|
+
} catch (error) {
|
|
566
|
+
if (error.name !== 'AbortError') console.warn(`${id}: page transition failed`, error);
|
|
567
|
+
} finally {
|
|
568
|
+
if (animations.get(element) === outgoing) {
|
|
569
|
+
outgoing.cancel();
|
|
570
|
+
animations.delete(element);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
return fade;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// Slot wrappers use `display: contents` and own no box, so climb past them
|
|
578
|
+
// before reading a container's geometry.
|
|
579
|
+
function containerOf(node) {
|
|
580
|
+
let current = node ?? null;
|
|
581
|
+
while (current && current !== document.body && getComputedStyle(current).display === 'contents') {
|
|
582
|
+
current = current.parentElement;
|
|
583
|
+
}
|
|
584
|
+
return current && current !== document.body ? current : null;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// The host has no grouping-item slot. Walk down from the one stable anchor
|
|
588
|
+
// (`[data-slot="sidebar.workspaces"]`) and read the browser's own boxes by
|
|
589
|
+
// position: our mounts are known by class, the header is the first native child
|
|
590
|
+
// of the region and the list is the last one.
|
|
591
|
+
function useSidebarMounts(nativeText, setEnabled) {
|
|
592
|
+
const [mounts, setMounts] = useState({});
|
|
593
|
+
useLayoutEffect(() => {
|
|
594
|
+
const grid = document.createElement('div');
|
|
595
|
+
grid.className = 'dwb-mount';
|
|
596
|
+
grid.hidden = true;
|
|
597
|
+
const toolbar = document.createElement('div');
|
|
598
|
+
toolbar.className = 'dwb-toolbar-mount';
|
|
599
|
+
toolbar.hidden = true;
|
|
600
|
+
const address = document.createElement('div');
|
|
601
|
+
address.className = 'dwb-address-mount';
|
|
602
|
+
address.hidden = true;
|
|
603
|
+
const heading = document.createElement('span');
|
|
604
|
+
heading.className = 'dwb-heading';
|
|
605
|
+
heading.hidden = true;
|
|
606
|
+
const menuMount = document.createElement('div');
|
|
607
|
+
menuMount.className = 'dwb-menu-mount';
|
|
608
|
+
let active;
|
|
609
|
+
let workspace;
|
|
610
|
+
let frame = 0;
|
|
611
|
+
|
|
612
|
+
function sync() {
|
|
613
|
+
workspace = document.querySelector('[data-slot="sidebar.workspaces"]');
|
|
614
|
+
const region = containerOf(workspace?.firstElementChild);
|
|
615
|
+
const area = containerOf(region?.parentElement);
|
|
616
|
+
const panel = containerOf(area?.parentElement);
|
|
617
|
+
const natives = region
|
|
618
|
+
? [...region.children].filter(child => ![...child.classList].some(name => name.startsWith('dwb-')))
|
|
619
|
+
: [];
|
|
620
|
+
const header = natives.length > 1 ? natives[0] : null;
|
|
621
|
+
const list = natives.length > 1 ? natives[natives.length - 1] : null;
|
|
622
|
+
const trigger = [...header?.querySelectorAll('button[aria-label]') ?? []]
|
|
623
|
+
.find(button => button.getAttribute('aria-label') === nativeText('viewOptions.label'));
|
|
624
|
+
const searchButton = header?.querySelector('button[aria-expanded]') ?? null;
|
|
625
|
+
const searchInput = header?.querySelector('input[type="text"], input[type="search"]') ?? null;
|
|
626
|
+
// The native title sits immediately before the search control.
|
|
627
|
+
const title = searchButton?.parentElement?.parentElement?.previousElementSibling ?? null;
|
|
628
|
+
const nativeHeading = title?.matches('span:not(.dwb-heading)') ? title : null;
|
|
629
|
+
// The popup is recognised by the grouping rows it is the only menu to list
|
|
630
|
+
// (the same localized strings the trigger is found by), so the body-level
|
|
631
|
+
// workspace context menu -- a menu too, with other rows -- never adopts us.
|
|
632
|
+
const groupLabels = ['groupBy.workspace', 'groupBy.workspaceTree', 'groupBy.flat'].map(key => {
|
|
633
|
+
try {
|
|
634
|
+
return nativeText(key);
|
|
635
|
+
} catch {
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
let menu = active?.menu?.isConnected ? active.menu : null;
|
|
640
|
+
if (!menu) {
|
|
641
|
+
const menus = [...document.body.querySelectorAll(':scope > [role="menu"]:not([data-context-menu])')];
|
|
642
|
+
menu = menus.reverse().find(node => [...node.querySelectorAll('button[role="menuitem"]')]
|
|
643
|
+
.some(row => !menuMount.contains(row) && groupLabels.includes(row.textContent?.trim()))) ?? null;
|
|
644
|
+
}
|
|
645
|
+
// Our own separator lives inside the mount, so skip it and take the first
|
|
646
|
+
// native one: every grouping row precedes it and nothing else does.
|
|
647
|
+
const menuSeparator = menu
|
|
648
|
+
? [...menu.querySelectorAll('[role="separator"]')].find(node => !menuMount.contains(node)) ?? null
|
|
649
|
+
: null;
|
|
650
|
+
const groupRows = menu && menuSeparator
|
|
651
|
+
? [...menu.querySelectorAll('button[role="menuitem"]')].filter(row => !menuMount.contains(row)
|
|
652
|
+
&& Boolean(menuSeparator.compareDocumentPosition(row) & Node.DOCUMENT_POSITION_PRECEDING))
|
|
653
|
+
: [];
|
|
654
|
+
const lastGroup = groupRows.length > 0 ? groupRows[groupRows.length - 1].parentElement : null;
|
|
655
|
+
const menuBody = groupRows.length > 0 ? groupRows[0].parentElement?.parentElement ?? null : null;
|
|
656
|
+
const label = menuSeparator?.nextElementSibling ?? null;
|
|
657
|
+
const menuLabel = label?.getAttribute('role') === 'presentation' ? label : null;
|
|
658
|
+
|
|
659
|
+
if (trigger && header && list) {
|
|
660
|
+
if (toolbar.nextElementSibling !== header) header.before(toolbar);
|
|
661
|
+
if (header.nextElementSibling !== address) header.after(address);
|
|
662
|
+
if (grid.parentElement !== list) list.prepend(grid);
|
|
663
|
+
} else {
|
|
664
|
+
toolbar.remove();
|
|
665
|
+
address.remove();
|
|
666
|
+
grid.remove();
|
|
667
|
+
}
|
|
668
|
+
if (nativeHeading) {
|
|
669
|
+
if (heading.nextElementSibling !== nativeHeading) nativeHeading.before(heading);
|
|
670
|
+
} else heading.remove();
|
|
671
|
+
if (lastGroup) {
|
|
672
|
+
groupRows.forEach(row => row.classList.add('dwb-native-group'));
|
|
673
|
+
if (lastGroup.nextElementSibling !== menuMount) lastGroup.after(menuMount);
|
|
674
|
+
} else menuMount.remove();
|
|
675
|
+
const searchOpen = searchButton?.getAttribute('aria-expanded') === 'true';
|
|
676
|
+
const searching = Boolean(searchOpen && searchInput?.value.trim());
|
|
677
|
+
const next = { grid, list, toolbar, address, header, heading, nativeHeading, trigger, menu, menuMount, menuSeparator, menuLabel, groupRows, searching, searchOpen, region, area, panel, menuBody };
|
|
678
|
+
const changed = active?.menu !== menu || active?.list !== list || active?.header !== header
|
|
679
|
+
|| active?.nativeHeading !== nativeHeading || active?.trigger !== trigger || active?.searching !== searching
|
|
680
|
+
|| active?.searchOpen !== searchOpen || active?.region !== region || active?.area !== area
|
|
681
|
+
|| active?.panel !== panel || active?.menuBody !== menuBody;
|
|
682
|
+
active = next;
|
|
683
|
+
if (changed) setMounts(next);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function schedule() {
|
|
687
|
+
if (frame) return;
|
|
688
|
+
frame = requestAnimationFrame(() => { frame = 0; sync(); });
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
function selectNative(event) {
|
|
692
|
+
// Only our injected menu proves this is the view-options menu.
|
|
693
|
+
if (!active?.menuBody?.contains(active.menuMount) || !(event.target instanceof Element)) return;
|
|
694
|
+
if (active.groupRows.includes(event.target.closest('button'))) setEnabled(false, active.list);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
const observer = new MutationObserver(records => {
|
|
698
|
+
if (!workspace?.isConnected || records.some(record =>
|
|
699
|
+
workspace.contains(record.target) || active?.menu?.contains(record.target)
|
|
700
|
+
|| (record.target === document.body && [...record.addedNodes, ...record.removedNodes]
|
|
701
|
+
.some(node => node instanceof Element && node.matches('[role="menu"]'))))) schedule();
|
|
702
|
+
});
|
|
703
|
+
observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['aria-expanded', 'aria-label'] });
|
|
704
|
+
document.addEventListener('input', schedule);
|
|
705
|
+
document.addEventListener('click', selectNative, true);
|
|
706
|
+
sync();
|
|
707
|
+
return () => {
|
|
708
|
+
observer.disconnect();
|
|
709
|
+
cancelAnimationFrame(frame);
|
|
710
|
+
document.removeEventListener('input', schedule);
|
|
711
|
+
document.removeEventListener('click', selectNative, true);
|
|
712
|
+
grid.remove();
|
|
713
|
+
toolbar.remove();
|
|
714
|
+
address.remove();
|
|
715
|
+
heading.remove();
|
|
716
|
+
menuMount.remove();
|
|
717
|
+
};
|
|
718
|
+
}, [nativeText, setEnabled]);
|
|
719
|
+
return mounts;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
function NavButton({ icon, label, disabled, onClick }) {
|
|
723
|
+
return h(Button, {
|
|
724
|
+
size: 'sm', className: 'dwb-nav-button', icon: icon && h(icon, { size: 16, 'aria-hidden': true }),
|
|
725
|
+
title: label, 'aria-label': label, disabled, onClick,
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function LocateIcon({ size }) {
|
|
730
|
+
return h('svg', { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', 'aria-hidden': true,
|
|
731
|
+
stroke: 'currentColor', strokeWidth: 1.5, strokeLinecap: 'round' },
|
|
732
|
+
h('circle', { cx: 12, cy: 12, r: 7 }),
|
|
733
|
+
h('path', { d: 'M12 2v4m0 12v4M2 12h4m12 0h4' }),
|
|
734
|
+
h('circle', { cx: 12, cy: 12, r: 1.5, fill: 'currentColor', stroke: 'none' }));
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
function SidebarDivider({ label, toolbar, area, ratio, saveRatio }) {
|
|
738
|
+
const drag = useRef(null);
|
|
739
|
+
// The region area owns the navigation list right above it.
|
|
740
|
+
const navigation = area?.previousElementSibling ?? null;
|
|
741
|
+
const upper = navigation?.matches('nav') ? navigation : null;
|
|
742
|
+
|
|
743
|
+
function maximum() {
|
|
744
|
+
const viewport = upper.parentElement;
|
|
745
|
+
return Math.max(0, viewport.getBoundingClientRect().bottom - upper.getBoundingClientRect().top - 138);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
useLayoutEffect(() => {
|
|
749
|
+
if (!upper || !Number.isFinite(ratio)) return;
|
|
750
|
+
const resize = () => upper.style.setProperty('--dwb-navigation-height', `${Math.round(ratio * maximum())}px`);
|
|
751
|
+
upper.setAttribute('data-dwb-resized-navigation', '');
|
|
752
|
+
const observer = new ResizeObserver(resize);
|
|
753
|
+
observer.observe(upper.parentElement);
|
|
754
|
+
resize();
|
|
755
|
+
return () => {
|
|
756
|
+
observer.disconnect();
|
|
757
|
+
upper.removeAttribute('data-dwb-resized-navigation');
|
|
758
|
+
upper.style.removeProperty('--dwb-navigation-height');
|
|
759
|
+
};
|
|
760
|
+
}, [upper, ratio]);
|
|
761
|
+
|
|
762
|
+
function resize(height) {
|
|
763
|
+
const available = maximum();
|
|
764
|
+
if (available > 0) saveRatio(Math.max(0, Math.min(1, height / available)));
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
return h('div', {
|
|
768
|
+
className: 'dwb-divider',
|
|
769
|
+
...(upper && {
|
|
770
|
+
role: 'separator', 'aria-label': label, 'aria-orientation': 'horizontal', tabIndex: 0,
|
|
771
|
+
'aria-valuenow': Math.round((ratio ?? Math.min(1, upper.offsetHeight / Math.max(1, maximum()))) * 100),
|
|
772
|
+
onPointerDown: event => {
|
|
773
|
+
if (event.button !== 0) return;
|
|
774
|
+
event.preventDefault();
|
|
775
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
776
|
+
drag.current = { y: event.clientY, height: upper.offsetHeight };
|
|
777
|
+
},
|
|
778
|
+
onPointerMove: event => {
|
|
779
|
+
if (!drag.current || !event.currentTarget.hasPointerCapture(event.pointerId)) return;
|
|
780
|
+
const distance = event.clientY - drag.current.y;
|
|
781
|
+
if (distance !== 0) resize(drag.current.height + distance);
|
|
782
|
+
},
|
|
783
|
+
onLostPointerCapture: () => { drag.current = null; },
|
|
784
|
+
onDoubleClick: () => saveRatio(null),
|
|
785
|
+
onKeyDown: event => {
|
|
786
|
+
if (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') return;
|
|
787
|
+
event.preventDefault();
|
|
788
|
+
resize(upper.offsetHeight + (event.key === 'ArrowUp' ? -16 : 16));
|
|
789
|
+
},
|
|
790
|
+
}),
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
function FolderIcon({ size }) {
|
|
795
|
+
return h('img', { src: folderIcon, alt: '', width: size, height: size, draggable: false });
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
function SessionIcon({ size }) {
|
|
799
|
+
return h('span', { className: 'dwb-session-icon', style: { width: size, height: size, maskImage: `url("${sessionIcon}")` } });
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
function Browser({ t, nativeText, workspaceSource, sessionSource, view, startFolder, rememberFolder, openSession, toolbar, address, heading, area, panel, display, split, saveSplit, animatePage, useContextMenu, useSessionStatus, startSession, placements, savePlacement, panelSource, scheduleSource, unreadSource }) {
|
|
803
|
+
const { getTriggerProps } = useContextMenu();
|
|
804
|
+
const workspaceState = useSyncExternalStore(workspaceSource.subscribe, workspaceSource.getSnapshot);
|
|
805
|
+
const sessions = useSyncExternalStore(sessionSource.subscribe, sessionSource.getSnapshot);
|
|
806
|
+
const statuses = useSessionStatus(snapshot => snapshot);
|
|
807
|
+
const unread = useSyncExternalStore(unreadSource.subscribe, unreadSource.getSnapshot);
|
|
808
|
+
const { activePanelId } = useSyncExternalStore(panelSource.subscribe, panelSource.getSnapshot);
|
|
809
|
+
const sessionVisible = activePanelId === null;
|
|
810
|
+
const catalog = useSyncExternalStore(scheduleSource.subscribe, scheduleSource.getSnapshot);
|
|
811
|
+
const scheduledSessions = useMemo(() => {
|
|
812
|
+
const ids = new Set();
|
|
813
|
+
for (const task of catalog.records) {
|
|
814
|
+
if (task.status !== 'active') continue;
|
|
815
|
+
for (const id of task.involvedSessionIds) ids.add(id);
|
|
816
|
+
const target = task.target.kind === 'new' ? task.lastDelivery?.targetSessionId : task.target.sessionId;
|
|
817
|
+
if (target) ids.add(target);
|
|
818
|
+
}
|
|
819
|
+
return ids;
|
|
820
|
+
}, [catalog.records]);
|
|
821
|
+
const options = useSyncExternalStore(view.subscribe, view.getSnapshot);
|
|
822
|
+
const { byId, parents, children } = useMemo(() => workspaceTree(workspaceState.items), [workspaceState.items]);
|
|
823
|
+
const { byWorkspace, pinned, archived } = useMemo(() => sessionRows(workspaceState, sessions, options), [workspaceState, sessions, options]);
|
|
824
|
+
const notifications = useMemo(() => workspaceNotifications(workspaceState.items, sessions, statuses, parents, archived, unread),
|
|
825
|
+
[workspaceState.items, sessions, statuses, parents, archived, unread]);
|
|
826
|
+
const [history, setHistory] = useState(() => startFolder === null
|
|
827
|
+
? { entries: [null], index: 0 } : { entries: [null, startFolder], index: 1 });
|
|
828
|
+
const [openError, setOpenError] = useState(null);
|
|
829
|
+
const [selectedFolder, setSelectedFolder] = useState(null);
|
|
830
|
+
const [dropTarget, setDropTarget] = useState(null);
|
|
831
|
+
const dragged = useRef(null);
|
|
832
|
+
const locate = useRef(null);
|
|
833
|
+
const crumbsRef = useRef(null);
|
|
834
|
+
useEffect(() => {
|
|
835
|
+
const path = crumbsRef.current;
|
|
836
|
+
function scrollPath(event) {
|
|
837
|
+
if (event.ctrlKey || event.metaKey || event.deltaX !== 0 || event.deltaY === 0 || path.scrollWidth <= path.clientWidth) return;
|
|
838
|
+
const scale = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? path.clientWidth : 1;
|
|
839
|
+
event.preventDefault();
|
|
840
|
+
event.stopPropagation();
|
|
841
|
+
path.scrollLeft += event.deltaY * scale;
|
|
842
|
+
}
|
|
843
|
+
path.addEventListener('wheel', scrollPath, { passive: false });
|
|
844
|
+
return () => path.removeEventListener('wheel', scrollPath);
|
|
845
|
+
}, [address]);
|
|
846
|
+
const browserRef = useRef(null);
|
|
847
|
+
useEffect(() => {
|
|
848
|
+
if (selectedFolder === null) return;
|
|
849
|
+
function clearSelection(event) {
|
|
850
|
+
if (event.button !== 0 || (event.type === 'click' && event.detail > 0)) return;
|
|
851
|
+
if (getNewSessionButton(event)) return;
|
|
852
|
+
const selectedTile = browserRef.current?.querySelector('.dwb-tile[data-dwb-kind="folder"][aria-pressed="true"]');
|
|
853
|
+
if (!event.composedPath().includes(selectedTile)) setSelectedFolder(null);
|
|
854
|
+
}
|
|
855
|
+
window.addEventListener('pointerdown', clearSelection, true);
|
|
856
|
+
window.addEventListener('click', clearSelection, true);
|
|
857
|
+
return () => {
|
|
858
|
+
window.removeEventListener('pointerdown', clearSelection, true);
|
|
859
|
+
window.removeEventListener('click', clearSelection, true);
|
|
860
|
+
};
|
|
861
|
+
}, [selectedFolder]);
|
|
862
|
+
|
|
863
|
+
const exists = key => key === null || key === ungrouped || byId.has(key);
|
|
864
|
+
const current = history.entries[history.index];
|
|
865
|
+
const folder = exists(current) ? current : null;
|
|
866
|
+
const parent = parents.get(folder) ?? null;
|
|
867
|
+
const activeSession = Object.values(sessions.byId).find(session => session.retainedBy?.mainView > 0);
|
|
868
|
+
const activeOwner = activeSession && workspaceState.items.find(item => item.sessionIds.includes(activeSession.id));
|
|
869
|
+
let guideFolder;
|
|
870
|
+
if (activeSession) {
|
|
871
|
+
for (let child = activeOwner?.workspaceId ?? ungrouped; child !== null && child !== folder; child = parents.get(child) ?? null) {
|
|
872
|
+
if ((parents.get(child) ?? null) !== folder) continue;
|
|
873
|
+
guideFolder = child;
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
const onlyArchived = options.archivedFilter === 'only';
|
|
878
|
+
const foldersWithArchives = useMemo(() => {
|
|
879
|
+
const visible = new Set();
|
|
880
|
+
if (onlyArchived) for (const [key, rows] of byWorkspace) {
|
|
881
|
+
if (rows.length === 0) continue;
|
|
882
|
+
for (let item = key; item !== null && !visible.has(item); item = parents.get(item) ?? null) visible.add(item);
|
|
883
|
+
}
|
|
884
|
+
return visible;
|
|
885
|
+
}, [byWorkspace, onlyArchived, parents]);
|
|
886
|
+
const folders = (children.get(folder) ?? []).filter(item => !onlyArchived || foldersWithArchives.has(item.workspaceId));
|
|
887
|
+
const placement = placements?.[pageKey(folder)];
|
|
888
|
+
const order = placement?.order ?? [];
|
|
889
|
+
const rows = byWorkspace.get(folder) ?? [];
|
|
890
|
+
const rowIds = new Set(rows.map(row => row.id));
|
|
891
|
+
const shortcuts = (placement?.shortcuts ?? []).map(id => sessions.byId[id]).filter(session => session
|
|
892
|
+
&& !rowIds.has(session.id) && (!session.blank || session.retainedBy?.mainView > 0)
|
|
893
|
+
&& (options.archivedFilter === 'show' || onlyArchived === archived.has(session.id)));
|
|
894
|
+
const inside = new Set(notifications.byFolder.get(folder)?.map(entry => entry.sessionId));
|
|
895
|
+
for (const session of shortcuts) inside.add(session.id);
|
|
896
|
+
const outside = folder === null ? undefined : notifications.all.reduce((highest, entry) =>
|
|
897
|
+
!inside.has(entry.sessionId) && entry.priority > (highest?.priority ?? 0) ? entry : highest, undefined);
|
|
898
|
+
const workspaceLabel = workspace => workspace.title === 'default-workspace' ? nativeText('workspace.defaultName') : workspace.title;
|
|
899
|
+
const crumbs = [{ key: null, label: t('home') }];
|
|
900
|
+
if (folder === ungrouped) {
|
|
901
|
+
crumbs.push({ key: ungrouped, label: t('ungrouped') });
|
|
902
|
+
} else if (folder !== null) {
|
|
903
|
+
const trail = [];
|
|
904
|
+
for (let key = folder; key !== null; key = parents.get(key) ?? null) {
|
|
905
|
+
const workspace = byId.get(key);
|
|
906
|
+
trail.push({ key, label: workspaceLabel(workspace), path: workspace.path });
|
|
907
|
+
}
|
|
908
|
+
crumbs.push(...trail.reverse());
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
function visit(key) {
|
|
912
|
+
if (key === folder) return;
|
|
913
|
+
animatePage(() => {
|
|
914
|
+
setOpenError(null);
|
|
915
|
+
setSelectedFolder(null);
|
|
916
|
+
rememberFolder(key);
|
|
917
|
+
setHistory(previous => ({
|
|
918
|
+
entries: [...previous.entries.slice(0, previous.index + 1), key], index: previous.index + 1,
|
|
919
|
+
}));
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
function historyTarget(direction) {
|
|
924
|
+
let index = history.index + direction;
|
|
925
|
+
while (index >= 0 && index < history.entries.length) {
|
|
926
|
+
if (exists(history.entries[index])) return index;
|
|
927
|
+
index += direction;
|
|
928
|
+
}
|
|
929
|
+
return undefined;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
function go(index) {
|
|
933
|
+
animatePage(() => {
|
|
934
|
+
setOpenError(null);
|
|
935
|
+
setSelectedFolder(null);
|
|
936
|
+
rememberFolder(history.entries[index]);
|
|
937
|
+
setHistory(previous => ({ ...previous, index }));
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
const back = historyTarget(-1);
|
|
942
|
+
const forward = historyTarget(1);
|
|
943
|
+
const gestureAction = useRef(null);
|
|
944
|
+
useLayoutEffect(() => {
|
|
945
|
+
gestureAction.current = direction => {
|
|
946
|
+
if (direction === 'up') { visit(parent); return; }
|
|
947
|
+
const index = direction === 'left' ? back : forward;
|
|
948
|
+
if (index !== undefined) go(index);
|
|
949
|
+
};
|
|
950
|
+
});
|
|
951
|
+
useEffect(() => installMouseGestures(
|
|
952
|
+
() => direction => gestureAction.current?.(direction),
|
|
953
|
+
() => {
|
|
954
|
+
const bounds = panel?.getBoundingClientRect();
|
|
955
|
+
if (bounds?.width >= 112 && bounds.height >= 112) return bounds;
|
|
956
|
+
},
|
|
957
|
+
target => Boolean(panel?.contains(target)) && !panel.closest('[inert]') && !toolbar.hidden,
|
|
958
|
+
direction => t({ left: 'back', right: 'forward', up: 'gestureUp', invalid: 'gestureInvalid' }[direction]),
|
|
959
|
+
), [toolbar, panel, t]);
|
|
960
|
+
const hasUngrouped = folder === null && byWorkspace.get(ungrouped).length > 0;
|
|
961
|
+
const loading = workspaceState.state !== 'error' && (workspaceState.phase !== 'ready' || sessions.phase !== 'ready');
|
|
962
|
+
const entries = new Map([
|
|
963
|
+
...folders.map(item => [folderKey(item.workspaceId), item]),
|
|
964
|
+
...(hasUngrouped ? [[folderKey(ungrouped), null]] : []),
|
|
965
|
+
...[...rows, ...shortcuts].map(session => [sessionKey(session.id), session]),
|
|
966
|
+
]);
|
|
967
|
+
const keys = [...new Set([...order.filter(key => entries.has(key)), ...entries.keys()])];
|
|
968
|
+
const activeKey = activeSession && sessionKey(activeSession.id);
|
|
969
|
+
const hasActiveTile = entries.has(activeKey);
|
|
970
|
+
const empty = keys.length === 0;
|
|
971
|
+
|
|
972
|
+
useLayoutEffect(() => {
|
|
973
|
+
function createSession(event) {
|
|
974
|
+
if (event.defaultPrevented || toolbar.hidden || !getNewSessionButton(event)) return;
|
|
975
|
+
const selected = entries.get(selectedFolder);
|
|
976
|
+
const inWorkspace = byId.has(folder);
|
|
977
|
+
const workspaceId = inWorkspace ? folder : selected?.workspaceId ?? activeOwner?.workspaceId;
|
|
978
|
+
if (!workspaceState.items.length) return;
|
|
979
|
+
event.preventDefault();
|
|
980
|
+
event.stopPropagation();
|
|
981
|
+
const activeAnchor = hasActiveTile ? activeKey : folderKey(guideFolder);
|
|
982
|
+
const anchor = entries.has(selectedFolder) ? selectedFolder : activeAnchor;
|
|
983
|
+
setSelectedFolder(null);
|
|
984
|
+
setOpenError(null);
|
|
985
|
+
startSession(workspaceId, sessionId => {
|
|
986
|
+
const key = sessionKey(sessionId);
|
|
987
|
+
savePlacement(folder, (saved = {}) => {
|
|
988
|
+
const next = [...new Set([...(saved.order ?? []), ...keys])].filter(item => item !== key);
|
|
989
|
+
const index = next.indexOf(anchor);
|
|
990
|
+
next.splice(index < 0 ? next.length : index + 1, 0, key);
|
|
991
|
+
const shortcuts = saved.shortcuts ?? [];
|
|
992
|
+
return { order: next, shortcuts: inWorkspace || shortcuts.includes(sessionId) ? shortcuts : [...shortcuts, sessionId] };
|
|
993
|
+
});
|
|
994
|
+
}).catch(() => setOpenError('create'));
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
document.addEventListener('click', createSession, true);
|
|
998
|
+
return () => document.removeEventListener('click', createSession, true);
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
function locateCurrentSession() {
|
|
1002
|
+
locate.current = activeSession.id;
|
|
1003
|
+
if (!hasActiveTile && folder !== (activeOwner?.workspaceId ?? ungrouped) && !onlyArchived) {
|
|
1004
|
+
visit(activeOwner?.workspaceId ?? ungrouped);
|
|
1005
|
+
} else {
|
|
1006
|
+
revealCurrentSession();
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
function revealCurrentSession() {
|
|
1011
|
+
if (locate.current === null) return;
|
|
1012
|
+
const item = browserRef.current.querySelector('[data-dwb-session-id="' + CSS.escape(locate.current) + '"] > button');
|
|
1013
|
+
if (!item) { locate.current = null; return; }
|
|
1014
|
+
locate.current = null;
|
|
1015
|
+
item.focus({ preventScroll: true });
|
|
1016
|
+
item.scrollIntoView({ block: 'nearest' });
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
function draggedPosition(event) {
|
|
1020
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
1021
|
+
if (display === 'list') return event.clientY < box.top + box.height / 2 ? 'before' : 'after';
|
|
1022
|
+
const before = event.clientX < box.left + box.width / 2;
|
|
1023
|
+
return before !== (getComputedStyle(event.currentTarget).direction === 'rtl') ? 'before' : 'after';
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
function dragProps(key) {
|
|
1027
|
+
return {
|
|
1028
|
+
draggable: true,
|
|
1029
|
+
'data-dwb-drop': dropTarget?.key === key ? dropTarget.position : undefined,
|
|
1030
|
+
onDragStart: event => {
|
|
1031
|
+
dragged.current = key;
|
|
1032
|
+
event.dataTransfer.effectAllowed = 'move';
|
|
1033
|
+
event.dataTransfer.setData('application/x-dsh-workspace-browser', key);
|
|
1034
|
+
},
|
|
1035
|
+
onDragOver: event => {
|
|
1036
|
+
if (dragged.current === null || dragged.current === key) {
|
|
1037
|
+
setDropTarget(null);
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
event.preventDefault();
|
|
1041
|
+
event.dataTransfer.dropEffect = 'move';
|
|
1042
|
+
const position = draggedPosition(event);
|
|
1043
|
+
setDropTarget(previous => previous?.key === key && previous.position === position ? previous : { key, position });
|
|
1044
|
+
},
|
|
1045
|
+
onDragLeave: event => {
|
|
1046
|
+
if (event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget)) return;
|
|
1047
|
+
setDropTarget(previous => previous?.key === key ? null : previous);
|
|
1048
|
+
},
|
|
1049
|
+
onDrop: event => {
|
|
1050
|
+
const source = dragged.current;
|
|
1051
|
+
if (source === null || source === key || !entries.has(source)) return;
|
|
1052
|
+
event.preventDefault();
|
|
1053
|
+
const position = draggedPosition(event);
|
|
1054
|
+
const next = keys.filter(item => item !== source);
|
|
1055
|
+
next.splice(next.indexOf(key) + (position === 'after' ? 1 : 0), 0, source);
|
|
1056
|
+
savePlacement(folder, (saved = {}) => {
|
|
1057
|
+
let index = 0;
|
|
1058
|
+
const order = (saved.order ?? []).map(item => entries.has(item) ? next[index++] : item);
|
|
1059
|
+
return { ...saved, order: [...order, ...next.slice(index)] };
|
|
1060
|
+
});
|
|
1061
|
+
dragged.current = null;
|
|
1062
|
+
setDropTarget(null);
|
|
1063
|
+
},
|
|
1064
|
+
onDragEnd: () => {
|
|
1065
|
+
dragged.current = null;
|
|
1066
|
+
setDropTarget(null);
|
|
1067
|
+
},
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
useLayoutEffect(() => {
|
|
1072
|
+
const crumbsElement = crumbsRef.current;
|
|
1073
|
+
crumbsElement.scrollLeft = crumbsElement.scrollWidth;
|
|
1074
|
+
const list = browserRef.current.closest('[data-dwb-grid]');
|
|
1075
|
+
if (list) list.scrollTop = 0;
|
|
1076
|
+
revealCurrentSession();
|
|
1077
|
+
}, [folder, display]);
|
|
1078
|
+
|
|
1079
|
+
function tile({ key, label, title = label, icon, kind, activate, active, guided, pinned, archived, scheduled, menuTarget, dots, sessionId, runningText, runningCount, subagents }) {
|
|
1080
|
+
const subagentLabel = subagents ? nativeText(subagents === 1 ? 'status.subagentsRunning.one' : 'status.subagentsRunning.other', { n: subagents }) : undefined;
|
|
1081
|
+
const countBadge = display === 'icons' && runningCount > 0;
|
|
1082
|
+
const description = [runningText, subagentLabel, scheduled && t('scheduled'), ...(dots ?? []).map(entry => nativeText(entry.label))].filter(Boolean).join(', ');
|
|
1083
|
+
return h('li', { key, 'data-dwb-session-id': sessionId, ...dragProps(key) }, h(Button, {
|
|
1084
|
+
className: 'dwb-tile', title, 'data-dwb-kind': kind,
|
|
1085
|
+
'aria-label': label,
|
|
1086
|
+
'aria-description': description || undefined,
|
|
1087
|
+
'aria-current': active ? 'true' : undefined,
|
|
1088
|
+
'data-dwb-guide': guided ? '' : undefined,
|
|
1089
|
+
'aria-pressed': kind === 'folder' ? selectedFolder === key : undefined,
|
|
1090
|
+
...getTriggerProps(menuTarget),
|
|
1091
|
+
onClick: event => {
|
|
1092
|
+
if (kind === 'session' || event.detail === 0) activate();
|
|
1093
|
+
else setSelectedFolder(key);
|
|
1094
|
+
},
|
|
1095
|
+
onDoubleClick: kind === 'folder' ? activate : undefined,
|
|
1096
|
+
}, h('span', { className: 'dwb-tile-icon', 'aria-hidden': true }, h(icon, { size: display === 'list' ? 16 : 30 })),
|
|
1097
|
+
h('span', { className: 'dwb-label' }, label),
|
|
1098
|
+
h('span', { className: 'dwb-tile-status' },
|
|
1099
|
+
runningText && h('span', {
|
|
1100
|
+
className: 'dwb-running', 'data-dwb-running-count': countBadge ? '' : undefined, 'aria-hidden': true,
|
|
1101
|
+
}, countBadge ? runningCount : runningText),
|
|
1102
|
+
dots?.length > 0 && h(NotificationDots, { entries: dots, translate: nativeText, size: 22 }),
|
|
1103
|
+
(subagentLabel || scheduled || pinned || archived) && h('span', { className: 'dwb-status-marks' },
|
|
1104
|
+
subagentLabel && h('span', { className: 'dwb-row-mark', role: 'img', 'aria-label': subagentLabel, title: subagentLabel },
|
|
1105
|
+
h(StateDot, { state: 'ongoing' })),
|
|
1106
|
+
scheduled && h(IconClockOutlineRegular, { className: 'dwb-row-mark', size: 14, 'aria-label': t('scheduled'), role: 'img' }),
|
|
1107
|
+
pinned && h(IconPinFillRegular, { className: 'dwb-row-mark', size: 13, 'aria-label': nativeText('menu.unpin'), role: 'img' }),
|
|
1108
|
+
archived && h(IconArchiveOutlineRegular, { className: 'dwb-row-mark', size: 13, 'aria-label': t('archived'), role: 'img' })))));
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
function folderTile(key, label, path) {
|
|
1112
|
+
const menuTarget = key === ungrouped ? undefined : { kind: 'workspace', value: { workspaceId: key, path, displayTitle: label } };
|
|
1113
|
+
const count = notifications.runningByFolder.get(key);
|
|
1114
|
+
const runningText = count ? t(count === 1 ? 'oneRunningSession' : 'runningSessions', { n: count }) : undefined;
|
|
1115
|
+
return tile({ key: folderKey(key), label, title: path ?? label, icon: FolderIcon, kind: 'folder',
|
|
1116
|
+
activate: () => visit(key), guided: sessionVisible && key === guideFolder, menuTarget, runningText, runningCount: count, dots: notifications.byFolder.get(key) });
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
return h('section', { className: 'dwb-browser', 'aria-label': t('panel'), ref: browserRef },
|
|
1120
|
+
createPortal(h(react.Fragment, null, outside && h(NotificationDots, { entries: [outside], translate: nativeText, size: 22 }),
|
|
1121
|
+
h('span', { className: 'dwb-heading-name' }, folder === null ? nativeText('section.workspaces') : crumbs.at(-1).label)), heading),
|
|
1122
|
+
createPortal(h('div', { className: 'dwb-toolbar' },
|
|
1123
|
+
h(SidebarDivider, { label: t('resize'), toolbar, area, ratio: split, saveRatio: saveSplit }),
|
|
1124
|
+
h('div', { className: 'dwb-reveal-zone' }),
|
|
1125
|
+
h('div', { className: 'dwb-nav-buttons dwb-reveal-control' },
|
|
1126
|
+
h(NavButton, { icon: outside ? undefined : IconChevronLeftOutlineRegular, label: t('back'), disabled: back === undefined, onClick: () => go(back) }),
|
|
1127
|
+
h(NavButton, { icon: IconChevronRightOutlineRegular, label: t('forward'), disabled: forward === undefined, onClick: () => go(forward) }),
|
|
1128
|
+
h(NavButton, { icon: IconChevronUpOutlineRegular, label: t('up'), disabled: folder === null, onClick: () => visit(parent) }),
|
|
1129
|
+
h(NavButton, { icon: LocateIcon, label: t('locate'), disabled: !activeSession || (onlyArchived && !hasActiveTile),
|
|
1130
|
+
onClick: locateCurrentSession }))), toolbar),
|
|
1131
|
+
createPortal(h('nav', { className: 'dwb-path dwb-reveal-control', 'aria-label': t('path'), ref: crumbsRef },
|
|
1132
|
+
h(IconFolderOpenRegular, { size: 16, className: 'dwb-indicator', 'aria-hidden': true }),
|
|
1133
|
+
crumbs.map(({ key, label, path }, index) => h('span', { className: 'dwb-crumb', key: key === ungrouped ? 'ungrouped' : key ?? 'home' },
|
|
1134
|
+
index > 0 && h(IconChevronRightOutlineRegular, { size: 12, className: 'dwb-indicator', 'aria-hidden': true }),
|
|
1135
|
+
index === crumbs.length - 1
|
|
1136
|
+
? h('span', { className: 'dwb-current', title: path, 'aria-current': 'location' }, label)
|
|
1137
|
+
: h(Button, { size: 'sm', title: path, onClick: () => visit(key) }, label)))), address),
|
|
1138
|
+
h('div', { 'aria-busy': loading },
|
|
1139
|
+
workspaceState.state === 'error' && h('p', { className: 'dwb-status', role: 'status' }, t('loadError')),
|
|
1140
|
+
openError && h('p', { className: 'dwb-status', role: 'alert' }, openError === 'archived'
|
|
1141
|
+
? nativeText('toast.archivedNotOpenable') : t(openError === 'create' ? 'createError' : 'openError')),
|
|
1142
|
+
empty && workspaceState.state !== 'error' && h('p', { className: 'dwb-status', role: 'status' },
|
|
1143
|
+
t(loading ? 'loading' : onlyArchived ? 'noArchives' : folder === null ? 'emptyHome' : 'emptyFolder')),
|
|
1144
|
+
!empty && h('ul', { className: 'dwb-list', 'data-dwb-display': display },
|
|
1145
|
+
keys.map(key => {
|
|
1146
|
+
const item = entries.get(key);
|
|
1147
|
+
if (item === null) return folderTile(ungrouped, t('ungrouped'));
|
|
1148
|
+
if (key.startsWith('folder:')) return folderTile(item.workspaceId, workspaceLabel(item), item.path);
|
|
1149
|
+
const session = item;
|
|
1150
|
+
const label = session.blank ? nativeText('session.new') : session.title?.trim() || nativeText('session.untitled');
|
|
1151
|
+
const isArchived = archived.has(session.id);
|
|
1152
|
+
const activity = notifications.runningBySession.get(session.id);
|
|
1153
|
+
const active = sessionVisible && activeKey === key;
|
|
1154
|
+
return tile({ key, sessionId: session.id, label, title: isArchived ? `${label} · ${t('archived')}` : label,
|
|
1155
|
+
icon: SessionIcon, kind: 'session',
|
|
1156
|
+
pinned: !isArchived && pinned.has(session.id), archived: isArchived, scheduled: !isArchived && !session.blank && scheduledSessions.has(session.id), active,
|
|
1157
|
+
runningText: activity?.running ? t('running') : undefined, subagents: activity?.subagents,
|
|
1158
|
+
dots: notifications.bySession.has(session.id) ? [notifications.bySession.get(session.id)] : undefined,
|
|
1159
|
+
menuTarget: session.blank ? undefined : { kind: 'session', value: { sessionId: session.id, displayTitle: label } },
|
|
1160
|
+
activate: () => {
|
|
1161
|
+
setOpenError(isArchived ? 'archived' : null);
|
|
1162
|
+
if (!isArchived && !active) openSession(session.id, () => setOpenError('open'));
|
|
1163
|
+
},
|
|
1164
|
+
});
|
|
1165
|
+
}))));
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
function SidebarExtension({ t, nativeText, workspaceSource, sessionSource, nativeEntry, openSession, startSession, useContextMenu, useSessionStatus, panelSource, scheduleSource, unreadSource }) {
|
|
1169
|
+
const [preference, setPreference] = useState(readPreference);
|
|
1170
|
+
const enabled = preference.enabled === true;
|
|
1171
|
+
const fade = usePageFade();
|
|
1172
|
+
const [actions] = useState(() => ({
|
|
1173
|
+
setEnabled: (enabled, list) => {
|
|
1174
|
+
const update = () => setPreference(previous => ({ ...previous, enabled }));
|
|
1175
|
+
if (list?.hasAttribute('data-dwb-grid') === enabled) return;
|
|
1176
|
+
fade(list, update);
|
|
1177
|
+
},
|
|
1178
|
+
rememberFolder: folder => setPreference(previous => ({ ...previous, folder })),
|
|
1179
|
+
setDisplay: display => setPreference(previous => ({ ...previous, display })),
|
|
1180
|
+
saveSplit: split => setPreference(previous => ({ ...previous, split })),
|
|
1181
|
+
savePlacement: (folder, update) => setPreference(previous => {
|
|
1182
|
+
const placements = previous.placements ?? emptyOrder;
|
|
1183
|
+
const key = pageKey(folder);
|
|
1184
|
+
return { ...previous, placements: { ...placements, [key]: update(placements[key]) } };
|
|
1185
|
+
}),
|
|
1186
|
+
}));
|
|
1187
|
+
const { grid, list, toolbar, address, header, heading, nativeHeading, trigger, menu, menuMount, menuSeparator, menuLabel, searching, searchOpen, region, area, panel } = useSidebarMounts(nativeText, actions.setEnabled);
|
|
1188
|
+
const display = preference.display === 'list' ? 'list' : 'icons';
|
|
1189
|
+
const entry = useSyncExternalStore(nativeEntry.subscribe, nativeEntry.getSnapshot);
|
|
1190
|
+
const view = useMemo(() => entry?.store?.create() ?? emptyView, [entry]);
|
|
1191
|
+
const animatePage = update => fade(list, update);
|
|
1192
|
+
|
|
1193
|
+
function openConversation(sessionId, onError) {
|
|
1194
|
+
const main = document.querySelector('[data-slot="main"]');
|
|
1195
|
+
fade(main?.parentElement, () => {
|
|
1196
|
+
try { openSession(sessionId); } catch { onError(); }
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
useEffect(() => { savePreference(preference); }, [preference]);
|
|
1201
|
+
useLayoutEffect(() => {
|
|
1202
|
+
if (!grid || !list || !header || !region) return;
|
|
1203
|
+
const show = enabled && Boolean(trigger);
|
|
1204
|
+
grid.hidden = !show || searching;
|
|
1205
|
+
toolbar.hidden = !show;
|
|
1206
|
+
address.hidden = !show;
|
|
1207
|
+
heading.hidden = !show;
|
|
1208
|
+
nativeHeading?.toggleAttribute('data-dwb-replaced-heading', show);
|
|
1209
|
+
region.toggleAttribute('data-dwb-layout', show);
|
|
1210
|
+
header.toggleAttribute('data-dwb-header', show);
|
|
1211
|
+
list.toggleAttribute('data-dwb-grid', show && !searching);
|
|
1212
|
+
return () => {
|
|
1213
|
+
region.removeAttribute('data-dwb-layout');
|
|
1214
|
+
header.removeAttribute('data-dwb-header');
|
|
1215
|
+
list.removeAttribute('data-dwb-grid');
|
|
1216
|
+
grid.hidden = true;
|
|
1217
|
+
toolbar.hidden = true;
|
|
1218
|
+
address.hidden = true;
|
|
1219
|
+
heading.hidden = true;
|
|
1220
|
+
nativeHeading?.removeAttribute('data-dwb-replaced-heading');
|
|
1221
|
+
};
|
|
1222
|
+
}, [grid, list, toolbar, address, header, heading, nativeHeading, enabled, trigger, searching, region]);
|
|
1223
|
+
useLayoutEffect(() => {
|
|
1224
|
+
region?.toggleAttribute('data-dwb-reveal-held', enabled && Boolean(searchOpen || menu));
|
|
1225
|
+
return () => region?.removeAttribute('data-dwb-reveal-held');
|
|
1226
|
+
}, [region, enabled, searchOpen, menu]);
|
|
1227
|
+
useLayoutEffect(() => {
|
|
1228
|
+
if (!enabled || !trigger || !header || !toolbar || !address || !region) return;
|
|
1229
|
+
const sidebar = panel ?? region;
|
|
1230
|
+
const divider = toolbar.querySelector('.dwb-divider');
|
|
1231
|
+
if (!divider) return;
|
|
1232
|
+
const clear = () => region.removeAttribute('data-dwb-reveal-hover');
|
|
1233
|
+
function update(event) {
|
|
1234
|
+
if (event.pointerType === 'touch') return;
|
|
1235
|
+
const { clientX: x, clientY: y } = event;
|
|
1236
|
+
const { left, right } = sidebar.getBoundingClientRect();
|
|
1237
|
+
const top = divider.getBoundingClientRect().bottom;
|
|
1238
|
+
const bottom = address.getBoundingClientRect().bottom;
|
|
1239
|
+
region.toggleAttribute('data-dwb-reveal-hover', x >= left && x < right && y >= top && y < bottom);
|
|
1240
|
+
}
|
|
1241
|
+
window.addEventListener('pointermove', update);
|
|
1242
|
+
sidebar.addEventListener('pointerleave', clear);
|
|
1243
|
+
window.addEventListener('blur', clear);
|
|
1244
|
+
return () => {
|
|
1245
|
+
window.removeEventListener('pointermove', update);
|
|
1246
|
+
sidebar.removeEventListener('pointerleave', clear);
|
|
1247
|
+
window.removeEventListener('blur', clear);
|
|
1248
|
+
clear();
|
|
1249
|
+
};
|
|
1250
|
+
}, [enabled, trigger, header, toolbar, address, region, panel]);
|
|
1251
|
+
useLayoutEffect(() => {
|
|
1252
|
+
if (!menu) return;
|
|
1253
|
+
menu.toggleAttribute('data-dwb-selected', enabled);
|
|
1254
|
+
return () => menu.removeAttribute('data-dwb-selected');
|
|
1255
|
+
}, [menu, enabled]);
|
|
1256
|
+
|
|
1257
|
+
function closeMenu() {
|
|
1258
|
+
trigger.focus({ preventScroll: true });
|
|
1259
|
+
trigger.click();
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
function menuItem(label, icon, current, select) {
|
|
1263
|
+
return h(MenuItemButton, { current, icon, onSelect: () => { select(); closeMenu(); } },
|
|
1264
|
+
h('span', { className: 'dwb-menu-label' }, t(label), current && h(IconCheckOutlineRegular, { size: 14, 'aria-hidden': true })));
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
return h(react.Fragment, null,
|
|
1268
|
+
menu && createPortal(h(react.Fragment, null,
|
|
1269
|
+
menuItem('panel', h(IconFolderOpenRegular, { size: 16, 'aria-hidden': true }), enabled, () => actions.setEnabled(true, list)),
|
|
1270
|
+
enabled && h(react.Fragment, null,
|
|
1271
|
+
h('div', { role: 'separator', className: menuSeparator?.className }),
|
|
1272
|
+
h('div', { role: 'presentation', className: menuLabel?.className }, t('display')),
|
|
1273
|
+
menuItem('icons', h('span', { className: 'dwb-menu-grid', 'aria-hidden': true }), display === 'icons', () => {
|
|
1274
|
+
if (display !== 'icons') animatePage(() => actions.setDisplay('icons'));
|
|
1275
|
+
}),
|
|
1276
|
+
menuItem('list', h(IconFlatListOutlineRegular, { size: 16, 'aria-hidden': true }), display === 'list', () => {
|
|
1277
|
+
if (display !== 'list') animatePage(() => actions.setDisplay('list'));
|
|
1278
|
+
}),
|
|
1279
|
+
)), menuMount),
|
|
1280
|
+
enabled && grid && createPortal(h(Browser, {
|
|
1281
|
+
t, nativeText, workspaceSource, sessionSource, view, openSession: openConversation, toolbar, address, heading, area, panel, display, animatePage, useContextMenu, useSessionStatus,
|
|
1282
|
+
split: !trigger ? null : preference.split, saveSplit: actions.saveSplit,
|
|
1283
|
+
startSession, placements: preference.placements, savePlacement: actions.savePlacement, panelSource, scheduleSource, unreadSource,
|
|
1284
|
+
startFolder: typeof preference.folder === 'string' ? preference.folder : null, rememberFolder: actions.rememberFolder,
|
|
1285
|
+
}), grid));
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
function apply(ctx) {
|
|
1289
|
+
const nativeText = ctx.locale.bind('workspace');
|
|
1290
|
+
const slots = ctx.slots;
|
|
1291
|
+
ctx.effect(() => ctx.locale.register(id, dictionaries));
|
|
1292
|
+
ctx.effect(() => {
|
|
1293
|
+
const style = document.createElement('style');
|
|
1294
|
+
style.textContent = css;
|
|
1295
|
+
document.head.append(style);
|
|
1296
|
+
return () => style.remove();
|
|
1297
|
+
});
|
|
1298
|
+
const workspaces = ctx.workspaces.list;
|
|
1299
|
+
const sessions = ctx.sessions.list;
|
|
1300
|
+
const navigation = ctx.uiWorkspace;
|
|
1301
|
+
const panel = ctx.layout.panelInfo;
|
|
1302
|
+
const panelSource = { subscribe: listener => panel.subscribe(listener), getSnapshot: () => panel.getSnapshot() };
|
|
1303
|
+
const workspaceSource = { subscribe: listener => workspaces.subscribe(listener), getSnapshot: () => workspaces.getSnapshot() };
|
|
1304
|
+
const sessionSource = { subscribe: listener => sessions.subscribe(listener), getSnapshot: () => sessions.getSnapshot() };
|
|
1305
|
+
const nativeEntry = {
|
|
1306
|
+
subscribe: listener => slots.subscribe('sidebar.workspaces', listener),
|
|
1307
|
+
getSnapshot: () => slots.entries('sidebar.workspaces').find(entry => entry.locale === 'workspace' && entry.store),
|
|
1308
|
+
};
|
|
1309
|
+
const scheduleSource = scheduleSourceFor(ctx);
|
|
1310
|
+
const unreadSource = completionSource(ctx);
|
|
1311
|
+
slots.inject('shell.overlay', () => slots.register({
|
|
1312
|
+
name: 'shell.overlay', id, locale: id,
|
|
1313
|
+
inject: () => ({
|
|
1314
|
+
nativeText, workspaceSource, sessionSource, nativeEntry, panelSource, scheduleSource, unreadSource,
|
|
1315
|
+
openSession: sessionId => navigation.openSession(sessionId),
|
|
1316
|
+
startSession: (workspaceId, onCreated) => {
|
|
1317
|
+
const snapshot = sessions.getSnapshot();
|
|
1318
|
+
const target = workspaceId ?? workspaces.getSnapshot().items.reduce((recent, item) => {
|
|
1319
|
+
const latest = item.sessionIds.reduce((time, id) => Math.max(time, snapshot.byId[id]?.updatedAt ?? -Infinity), -Infinity);
|
|
1320
|
+
const activity = latest === -Infinity ? Date.parse(item.createdAt) : latest;
|
|
1321
|
+
return !recent || activity > recent.activity ? { workspaceId: item.workspaceId, activity } : recent;
|
|
1322
|
+
}, undefined)?.workspaceId;
|
|
1323
|
+
return target === undefined ? Promise.resolve() : navigation.openWorkspace(target, onCreated);
|
|
1324
|
+
},
|
|
1325
|
+
}),
|
|
1326
|
+
}, SidebarExtension));
|
|
1327
|
+
}
|
|
1328
|
+
return { apply, inject };
|
|
1329
|
+
},
|
|
1330
|
+
});
|