@kabmo-labs/kabmo 0.28.0 → 0.29.0
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/bunfig.toml +6 -0
- package/dist/client/index.html +2 -2
- package/dist/client/index.js +481 -472
- package/dist/client/static/js/{index-xzvyrxya.js → index-43z47ngg.js} +1193 -1049
- package/dist/client/static/js/index-naa91727.css +1 -0
- package/dist/client/static/{manifest-q6h8k9e0.webmanifest → manifest-vdvdqpre.webmanifest} +1 -0
- package/package.json +3 -2
- package/public/manifest.webmanifest +1 -0
- package/src/client/components/common/ComposerTextarea.test.tsx +109 -0
- package/src/client/components/common/ComposerTextarea.tsx +6 -0
- package/src/client/components/common/ReloadPageButton.test.tsx +14 -0
- package/src/client/components/common/ReloadPageButton.tsx +11 -2
- package/src/client/components/common/diagram-viewer/read-block.test.ts +71 -0
- package/src/client/components/common/diagram-viewer/read-block.ts +40 -16
- package/src/client/components/common/file-icon/index.tsx +7 -1
- package/src/client/components/common/harness-glyph/brands.ts +7 -1
- package/src/client/components/common/image-viewer/index.tsx +37 -165
- package/src/client/components/common/picker-search/index.tsx +70 -0
- package/src/client/components/common/search-select/index.tsx +2 -7
- package/src/client/components/common/zoom-pan-stage/index.tsx +258 -0
- package/src/client/components/common/zoom-pan-stage/zoom-pan-stage.test.tsx +87 -0
- package/src/client/components/layout/session-sidebar/ClassicView.tsx +1 -1
- package/src/client/components/layout/session-sidebar/SessionListNotice.tsx +7 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +4 -1
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +12 -1
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.test.tsx +82 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +23 -3
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +1 -0
- package/src/client/components/layout/session-sidebar/modern/index.tsx +1 -1
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +6 -4
- package/src/client/components/layout/session-sidebar/session-list-states.test.tsx +8 -0
- package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +25 -0
- package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +1 -1
- package/src/client/components/settings/Sidebar.tsx +6 -8
- package/src/client/components/settings/categories/HarnessSettings.tsx +4 -2
- package/src/client/components/settings/categories/PanelPluginSettings.tsx +2 -2
- package/src/client/components/settings/categories/PluginSettings.tsx +1 -1
- package/src/client/components/settings/categories/harness-settings/ConfigForm.tsx +3 -6
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.test.tsx +36 -0
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +1 -3
- package/src/client/components/settings/categories/panel-plugins/Toolbar.tsx +18 -4
- package/src/client/components/settings/categories/plugin-settings/MarketplacePane.tsx +64 -61
- package/src/client/components/settings/categories/plugin-settings/SidebarList.tsx +15 -4
- package/src/client/components/settings/groups.test.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/IrcNotice.test.tsx +55 -0
- package/src/client/components/workspace/chat-timeline/IrcNotice.tsx +71 -0
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +4 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +19 -0
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +8 -3
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.search.test.tsx +72 -0
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +42 -15
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +28 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +28 -10
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.test.tsx +47 -1
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +55 -5
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +3 -2
- package/src/client/components/workspace/editor/FilePane.tsx +32 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +4 -0
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +1 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +5 -2
- package/src/client/components/workspace/editor/viewers/CsvGrid.tsx +52 -5
- package/src/client/components/workspace/editor/viewers/DataGrid.tsx +227 -41
- package/src/client/components/workspace/editor/viewers/DrawioView.tsx +93 -0
- package/src/client/components/workspace/editor/viewers/GridRow.tsx +91 -0
- package/src/client/components/workspace/editor/viewers/GridToolbar.tsx +53 -0
- package/src/client/components/workspace/editor/viewers/SheetView.tsx +152 -57
- package/src/client/components/workspace/editor/viewers/dispatch.tsx +42 -9
- package/src/client/components/workspace/editor/viewers/drawio-pages.test.ts +80 -0
- package/src/client/components/workspace/editor/viewers/drawio-pages.ts +63 -0
- package/src/client/components/workspace/editor/viewers/grid.test.ts +296 -0
- package/src/client/components/workspace/editor/viewers/use-cell-edit.ts +64 -0
- package/src/client/components/workspace/editor/viewers/use-grid-interaction.ts +216 -0
- package/src/client/components/workspace/editor/viewers/viewers.test.ts +47 -2
- package/src/client/components/workspace/editor/viewers/workbook.ts +149 -0
- package/src/client/components/workspace/file-explorer/ArchiveModals.tsx +262 -0
- package/src/client/components/workspace/file-explorer/ContextMenu.tsx +30 -6
- package/src/client/components/workspace/file-explorer/Modals.tsx +8 -3
- package/src/client/components/workspace/file-explorer/RootOverlays.tsx +60 -0
- package/src/client/components/workspace/file-explorer/RowLabel.tsx +6 -2
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +39 -49
- package/src/client/components/workspace/file-explorer/TreeItemModals.tsx +80 -0
- package/src/client/components/workspace/file-explorer/index.tsx +53 -29
- package/src/client/components/workspace/file-explorer/selection.test.tsx +109 -0
- package/src/client/data/settings/omp-schema.json +169 -22
- package/src/client/glass.css +39 -14
- package/src/client/glass.test.ts +37 -0
- package/src/client/hooks/chat/composer/history.test.ts +267 -0
- package/src/client/hooks/chat/composer/history.ts +146 -0
- package/src/client/hooks/chat/timeline/ask-frames.test.ts +54 -0
- package/src/client/hooks/chat/timeline/ask-frames.ts +29 -1
- package/src/client/hooks/chat/timeline/timeline-rail.test.ts +34 -2
- package/src/client/hooks/chat/timeline/user-turns.ts +31 -2
- package/src/client/hooks/editor/file-editor-types.ts +15 -0
- package/src/client/hooks/editor/save-bytes.ts +79 -0
- package/src/client/hooks/editor/use-file-editor.test.ts +30 -0
- package/src/client/hooks/editor/use-file-editor.ts +53 -5
- package/src/client/hooks/editor/use-file-read.ts +21 -2
- package/src/client/hooks/editor/use-grid-selection.ts +160 -0
- package/src/client/hooks/models/use-harness-update.test.ts +35 -2
- package/src/client/hooks/models/use-harness-update.ts +49 -10
- package/src/client/hooks/workspace/diff-file.test.ts +72 -0
- package/src/client/hooks/workspace/diff-file.ts +12 -6
- package/src/client/hooks/workspace/file-archive.ts +220 -0
- package/src/client/hooks/workspace/file-clipboard.test.ts +4 -4
- package/src/client/hooks/workspace/file-clipboard.ts +37 -26
- package/src/client/hooks/workspace/file-selection.test.ts +67 -0
- package/src/client/hooks/workspace/file-selection.ts +156 -0
- package/src/client/hooks/workspace/file-tree-actions-clipboard.test.ts +5 -5
- package/src/client/hooks/workspace/file-tree-actions.ts +36 -8
- package/src/client/lib/editor/workbook-drafts.ts +42 -0
- package/src/client/lib/launch/file-handlers.ts +2 -2
- package/src/client/lib/scrollbar-activity.test.ts +21 -88
- package/src/client/lib/scrollbar-activity.ts +71 -73
- package/src/client/lib/scrollbar-events.ts +143 -0
- package/src/client/lib/scrollbar-input.test.ts +126 -0
- package/src/client/lib/scrollbar-probe.test-util.ts +107 -0
- package/src/client/tailwind.css +32 -1
- package/src/server/db.server.test.ts +50 -1
- package/src/server/db.server.ts +36 -3
- package/src/server/lib/chat/prompt-history.server.test.ts +92 -0
- package/src/server/lib/chat/prompt-history.server.ts +65 -0
- package/src/server/lib/chat/schema.server.ts +35 -0
- package/src/server/lib/db/schema.ts +3 -0
- package/src/server/lib/fs/archive.test.ts +139 -0
- package/src/server/lib/fs/archive.ts +259 -0
- package/src/server/lib/fs/git-diff.test.ts +26 -1
- package/src/server/lib/fs/git-diff.ts +43 -15
- package/src/server/lib/harness/launch-table.ts +19 -0
- package/src/server/lib/harness/provider-entry.ts +1 -1
- package/src/server/lib/harness/provider-file.server.ts +1 -1
- package/src/server/lib/harness/provider-sources.server.ts +2 -1
- package/src/server/lib/harness/provider-write.server.ts +2 -1
- package/src/server/lib/harness/update-job-store.ts +12 -0
- package/src/server/lib/harness/update-queue.server.ts +15 -10
- package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +5 -1
- package/src/server/lib/omp/rpc/frame-fold.test.ts +5 -1
- package/src/server/lib/omp/rpc/lifecycle.test.ts +4 -0
- package/src/server/lib/omp/session/auto-title.server.test.ts +4 -0
- package/src/server/lib/omp/session/delete.server.ts +1 -0
- package/src/server/lib/omp/session/goal-driver.test.ts +5 -1
- package/src/server/lib/omp/session/goal-settings.test.ts +5 -1
- package/src/server/lib/panels/auto-update.server.test.ts +5 -2
- package/src/server/lib/panels/git-update.server.test.ts +5 -2
- package/src/server/lib/panels/install.server.test.ts +5 -2
- package/src/server/lib/panels/remove.server.test.ts +5 -2
- package/src/server/routes/agent/command.ts +11 -0
- package/src/server/routes/agent/new.ts +5 -0
- package/src/server/routes/chat/index.ts +5 -0
- package/src/server/routes/chat/prompt-history.test.ts +67 -0
- package/src/server/routes/chat/prompt-history.ts +31 -0
- package/src/server/routes/chat/stream.test.ts +21 -0
- package/src/server/routes/chat/stream.ts +5 -0
- package/src/server/routes/fs/action-archive.test.ts +128 -0
- package/src/server/routes/fs/action-bulk.ts +106 -0
- package/src/server/routes/fs/action-save-bytes.test.ts +59 -0
- package/src/server/routes/fs/action-transfer.test.ts +26 -0
- package/src/server/routes/fs/action.ts +91 -11
- package/src/server/routes/fs/archive.ts +20 -0
- package/src/server/routes/fs/grant.test.ts +5 -2
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/scope.test.ts +6 -2
- package/src/server/routes/harness/import-action.ts +1 -1
- package/src/server/routes/harness/root.ts +6 -1
- package/src/server/routes/harness/summary.test.ts +50 -0
- package/src/server/routes/harness/update-status.ts +41 -2
- package/src/server/routes/harness/update.test.ts +56 -2
- package/src/server/routes/sessions/delete.test.ts +4 -0
- package/src/shared/lib/chat/ask-form/index.ts +39 -31
- package/src/shared/lib/chat/ask-form/labels.ts +46 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +11 -2
- package/src/shared/lib/chat/ask-form.test.ts +57 -0
- package/src/shared/lib/chat/ask-questions.ts +31 -0
- package/src/shared/lib/chat/composer/history.test.ts +67 -0
- package/src/shared/lib/chat/composer/history.ts +61 -0
- package/src/shared/lib/chat/irc-notice.ts +42 -0
- package/src/shared/lib/chat/timeline/fork-anchor.test.ts +2 -0
- package/src/shared/lib/chat/todo/parser.ts +6 -4
- package/src/shared/lib/fs/archive.test.ts +101 -0
- package/src/shared/lib/fs/archive.ts +191 -0
- package/src/shared/lib/fs/clipboard.test.ts +32 -7
- package/src/shared/lib/fs/clipboard.ts +59 -14
- package/src/shared/lib/fs/csv.test.ts +50 -0
- package/src/shared/lib/fs/csv.ts +40 -0
- package/src/shared/lib/fs/document-kind.test.ts +13 -6
- package/src/shared/lib/fs/document-kind.ts +18 -6
- package/src/shared/lib/fs/file-kind-classify.test.ts +4 -0
- package/src/shared/lib/fs/file-kind.test.ts +2 -7
- package/src/shared/lib/fs/file-kind.ts +4 -2
- package/src/shared/lib/fs/grid-edit.test.ts +24 -0
- package/src/shared/lib/fs/grid-edit.ts +29 -0
- package/src/shared/lib/fs/grid-selection.test.ts +137 -0
- package/src/shared/lib/fs/grid-selection.ts +138 -0
- package/src/shared/lib/harness/brand-color.ts +5 -0
- package/src/shared/lib/harness/catalog.test.ts +22 -0
- package/src/shared/lib/harness/catalog.ts +12 -1
- package/src/shared/lib/harness/config-fields.test.ts +25 -0
- package/src/shared/lib/harness/config-fields.ts +33 -3
- package/src/shared/lib/harness/dialects.ts +1 -1
- package/src/shared/lib/harness/mcp-facts.ts +4 -0
- package/src/shared/lib/harness/provider-contracts.ts +109 -0
- package/src/shared/lib/harness/provider-facts.test.ts +2 -1
- package/src/shared/lib/harness/provider-facts.ts +24 -115
- package/src/shared/lib/harness/provider-lookup.ts +37 -0
- package/src/shared/lib/harness/providers.ts +2 -1
- package/src/shared/lib/harness/updates.ts +10 -0
- package/src/shared/lib/omp/session/mapper.test.ts +31 -0
- package/src/shared/lib/omp/session/mapper.ts +17 -0
- package/src/shared/lib/omp/session/messages-map-notice.test.ts +68 -0
- package/src/shared/lib/omp/session/messages-map.test.ts +1 -35
- package/src/shared/lib/omp/session/messages-map.ts +17 -0
- package/src/shared/lib/omp/session/wait.ts +10 -1
- package/src/shared/lib/settings/sections.ts +8 -4
- package/src/shared/lib/ui/picker-filter.test.ts +23 -0
- package/src/shared/lib/ui/picker-filter.ts +20 -0
- package/src/shared/types/chat.ts +4 -0
- package/src/shared/types/harness.ts +5 -1
- package/src/shared/types/omp/session.ts +18 -0
- package/src/shared/types/settings/state.ts +6 -6
- package/src/shared/types/todo.ts +3 -1
- package/src/test-support/file-actions.test-util.ts +4 -0
- package/src/test-support/file-archive.test-util.ts +41 -0
- package/src/test-support/file-clipboard.test-util.ts +9 -6
- package/src/test-support/harness-table.test-util.ts +2 -0
- package/src/test-support/preload.ts +46 -0
- package/dist/client/static/js/index-81f7berm.css +0 -1
|
@@ -32,7 +32,7 @@ describe('useFileActions clipboard', () => {
|
|
|
32
32
|
|
|
33
33
|
await harness.step(() => harness.actions()?.handleAction('cut'));
|
|
34
34
|
expect(harness.clipboard()?.calls).toEqual([
|
|
35
|
-
{ action: 'cut',
|
|
35
|
+
{ action: 'cut', targets: [{ path: 'src/a.ts', name: 'a.ts', kind: 'file' }] },
|
|
36
36
|
]);
|
|
37
37
|
|
|
38
38
|
await harness.step(() => harness.actions()?.handleAction('copy'));
|
|
@@ -53,7 +53,7 @@ describe('useFileActions clipboard', () => {
|
|
|
53
53
|
// so the two entry points — a row's menu and the background's — cannot
|
|
54
54
|
// drift on what a duplicate does.
|
|
55
55
|
expect(harness.clipboard()?.calls).toEqual([
|
|
56
|
-
{ action: 'duplicate',
|
|
56
|
+
{ action: 'duplicate', targets: [{ path: 'src/a.ts', name: 'a.ts', kind: 'file' }] },
|
|
57
57
|
]);
|
|
58
58
|
expect(srv.requests).toEqual([]);
|
|
59
59
|
});
|
|
@@ -68,7 +68,7 @@ describe('useFileActions clipboard', () => {
|
|
|
68
68
|
// The row delegates: the panel's hook is what knows the clipboard's source
|
|
69
69
|
// path, and sending the row's own path would move a file onto itself.
|
|
70
70
|
expect(harness.clipboard()?.calls).toEqual([
|
|
71
|
-
{ action: 'paste',
|
|
71
|
+
{ action: 'paste', targets: [{ path: 'dest', name: 'dest', kind: 'folder' }] },
|
|
72
72
|
]);
|
|
73
73
|
expect(srv.requests).toEqual([]);
|
|
74
74
|
});
|
|
@@ -82,7 +82,7 @@ describe('useFileActions clipboard', () => {
|
|
|
82
82
|
await harness.step(() => harness.actions()?.handleAction('copy'));
|
|
83
83
|
expect(harness.actions()?.pasteLabel).toBeNull();
|
|
84
84
|
|
|
85
|
-
const clip = { scope: '/root\u0000.', path: 'a.ts', name: 'a.ts', kind: 'file' as const, mode: 'copy' as const };
|
|
85
|
+
const clip = { scope: '/root\u0000.', entries: [{ path: 'a.ts', name: 'a.ts', kind: 'file' as const }], mode: 'copy' as const };
|
|
86
86
|
await harness.mount({ path: 'dest', name: 'dest' }, { clipboard: { clip } });
|
|
87
87
|
expect(harness.actions()?.pasteLabel).toBe('Paste a.ts');
|
|
88
88
|
|
|
@@ -100,7 +100,7 @@ describe('useFileActions clipboard', () => {
|
|
|
100
100
|
await harness.step(() => harness.actions()?.handleAction('cut'));
|
|
101
101
|
|
|
102
102
|
expect(harness.clipboard()?.calls).toEqual([
|
|
103
|
-
{ action: 'cut',
|
|
103
|
+
{ action: 'cut', targets: [{ path: 'src', name: 'src', kind: 'folder' }] },
|
|
104
104
|
]);
|
|
105
105
|
});
|
|
106
106
|
});
|
|
@@ -23,7 +23,10 @@ import { useFetcher } from '@/client/lib/router/fetcher';
|
|
|
23
23
|
import { toAbsolutePath } from '@/shared/lib/fs/paths';
|
|
24
24
|
import { copyToClipboard } from '@/client/hooks/ui/clipboard';
|
|
25
25
|
import { useFileCreate, type CreatedEntry } from '@/client/hooks/workspace/file-create';
|
|
26
|
-
import type { FileClipboard } from '@/client/hooks/workspace/file-clipboard';
|
|
26
|
+
import type { FileClipboard, ClipboardTarget } from '@/client/hooks/workspace/file-clipboard';
|
|
27
|
+
import type { FileArchive } from '@/client/hooks/workspace/file-archive';
|
|
28
|
+
import { clipboardLabel } from '@/shared/lib/fs/clipboard';
|
|
29
|
+
import { isArchiveName } from '@/shared/lib/fs/archive';
|
|
27
30
|
import type { FsActionResponse } from '@/shared/types';
|
|
28
31
|
|
|
29
32
|
export interface FileActionTarget {
|
|
@@ -65,6 +68,16 @@ export interface FileActionDeps {
|
|
|
65
68
|
clipboard: FileClipboard;
|
|
66
69
|
/** Whether this row is a folder — what Cut/Copy/Paste need to name their target. */
|
|
67
70
|
isFolder: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* The rows the panel has MARKED. When this row is one of several, every batch
|
|
73
|
+
* verb acts on the whole selection; the row that was right-clicked only
|
|
74
|
+
* supplies the menu.
|
|
75
|
+
*/
|
|
76
|
+
selection: readonly ClipboardTarget[];
|
|
77
|
+
/** True when this row is part of the marked set. */
|
|
78
|
+
selected: boolean;
|
|
79
|
+
/** The panel's archive dialogs. */
|
|
80
|
+
archive: FileArchive;
|
|
68
81
|
}
|
|
69
82
|
|
|
70
83
|
export interface FileActions {
|
|
@@ -90,6 +103,10 @@ export interface FileActions {
|
|
|
90
103
|
busy: boolean;
|
|
91
104
|
/** Label of the row's Paste action, or null when a paste cannot land here. */
|
|
92
105
|
pasteLabel: string | null;
|
|
106
|
+
/** How many rows the batch verbs act on — one, or the panel's selection. */
|
|
107
|
+
selectionCount: number;
|
|
108
|
+
/** True when the row itself is an archive the Extract flow understands. */
|
|
109
|
+
isArchive: boolean;
|
|
93
110
|
/**
|
|
94
111
|
* True when the row's label names more than one directory — a collapsed
|
|
95
112
|
* chain, whose inner levels are not rows and therefore not renameable until
|
|
@@ -111,7 +128,7 @@ export interface FileActions {
|
|
|
111
128
|
closeHistory: () => void;
|
|
112
129
|
}
|
|
113
130
|
|
|
114
|
-
export function useFileActions({ file, diff, onOpenFile, onActionComplete, onCreated, onRenamed, onUnfold, onFold, clipboard, isFolder }: FileActionDeps): FileActions {
|
|
131
|
+
export function useFileActions({ file, diff, onOpenFile, onActionComplete, onCreated, onRenamed, onUnfold, onFold, clipboard, isFolder, selection, selected, archive }: FileActionDeps): FileActions {
|
|
115
132
|
const actionFetcher = useFetcher<FsActionResponse>();
|
|
116
133
|
const [contextMenu, setContextMenu] = useState<{ x: number; y: number } | null>(null);
|
|
117
134
|
const contextMenuRef = useRef<HTMLDivElement>(null);
|
|
@@ -183,7 +200,11 @@ export function useFileActions({ file, diff, onOpenFile, onActionComplete, onCre
|
|
|
183
200
|
onOpenFile?.({ path: file.path, name: file.name, root: rootPath, repo: repo || '.' });
|
|
184
201
|
};
|
|
185
202
|
|
|
186
|
-
const clipboardTarget = { path: file.path, name: file.name, kind: isFolder ? 'folder'
|
|
203
|
+
const clipboardTarget: ClipboardTarget = { path: file.path, name: file.name, kind: isFolder ? 'folder' : 'file' };
|
|
204
|
+
// The menu's verbs act on the marked rows when this row is one of them; a
|
|
205
|
+
// right-click on an unmarked row never gets here — the panel selects it first.
|
|
206
|
+
const targets = selected && selection.length > 1 ? selection : [clipboardTarget];
|
|
207
|
+
const archiveTarget = isArchiveName(file.name);
|
|
187
208
|
/**
|
|
188
209
|
* The row's Paste label, or null when a paste cannot land here.
|
|
189
210
|
*
|
|
@@ -194,7 +215,7 @@ export function useFileActions({ file, diff, onOpenFile, onActionComplete, onCre
|
|
|
194
215
|
* background menu, which cannot know which rows are illegal.
|
|
195
216
|
*/
|
|
196
217
|
const pasteLabel = clipboard.clip && !clipboard.refusalFor(clipboardTarget)
|
|
197
|
-
? `Paste ${clipboard.clip
|
|
218
|
+
? `Paste ${clipboardLabel(clipboard.clip) ?? 'item'}`
|
|
198
219
|
: null;
|
|
199
220
|
|
|
200
221
|
const handleAction = (actionType: string) => {
|
|
@@ -241,9 +262,13 @@ export function useFileActions({ file, diff, onOpenFile, onActionComplete, onCre
|
|
|
241
262
|
} else if (actionType === 'delete') {
|
|
242
263
|
setShowDeleteModal(true);
|
|
243
264
|
} else if (actionType === 'cut') {
|
|
244
|
-
clipboard.cut(
|
|
265
|
+
clipboard.cut(targets);
|
|
245
266
|
} else if (actionType === 'copy') {
|
|
246
|
-
clipboard.copy(
|
|
267
|
+
clipboard.copy(targets);
|
|
268
|
+
} else if (actionType === 'compress') {
|
|
269
|
+
archive.openCompress(targets);
|
|
270
|
+
} else if (actionType === 'extract') {
|
|
271
|
+
archive.openExtract(clipboardTarget);
|
|
247
272
|
} else if (actionType === 'duplicate') {
|
|
248
273
|
clipboard.duplicate(clipboardTarget);
|
|
249
274
|
} else if (actionType === 'paste') {
|
|
@@ -264,7 +289,8 @@ export function useFileActions({ file, diff, onOpenFile, onActionComplete, onCre
|
|
|
264
289
|
const submitDelete = () => {
|
|
265
290
|
const fd = new FormData();
|
|
266
291
|
fd.append('actionType', 'delete');
|
|
267
|
-
fd.append('
|
|
292
|
+
if (targets.length > 1) fd.append('paths', JSON.stringify(targets.map((target) => target.path)));
|
|
293
|
+
else fd.append('path', file.path);
|
|
268
294
|
submitAction(fd);
|
|
269
295
|
};
|
|
270
296
|
|
|
@@ -284,8 +310,10 @@ export function useFileActions({ file, diff, onOpenFile, onActionComplete, onCre
|
|
|
284
310
|
renameValue,
|
|
285
311
|
setRenameValue,
|
|
286
312
|
renameError,
|
|
287
|
-
busy: actionFetcher.state !== 'idle' || create.busy || clipboard.busy,
|
|
313
|
+
busy: actionFetcher.state !== 'idle' || create.busy || clipboard.busy || archive.busy,
|
|
288
314
|
pasteLabel,
|
|
315
|
+
selectionCount: targets.length,
|
|
316
|
+
isArchive: archiveTarget,
|
|
289
317
|
chainLabel: onUnfold !== undefined,
|
|
290
318
|
foldable: onFold !== undefined,
|
|
291
319
|
fetcherState: actionFetcher.state,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Edited workbooks that are not on disk yet, keyed by the file they belong to.
|
|
8
|
+
*
|
|
9
|
+
* The grid's edits live in the viewer, and the viewer unmounts when the user
|
|
10
|
+
* switches tabs — so a draft kept in component state would be lost by a glance
|
|
11
|
+
* at another file while the tab still said "edited". This map is the smallest
|
|
12
|
+
* thing that survives that: one entry per workbook with unsaved edits, dropped
|
|
13
|
+
* when the save lands.
|
|
14
|
+
*
|
|
15
|
+
* It is deliberately NOT a cache of every workbook ever opened: a clean
|
|
16
|
+
* workbook is re-read from disk, which is the only copy that can be trusted
|
|
17
|
+
* after an external change.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { LoadedWorkbook } from '@/client/components/workspace/editor/viewers/workbook';
|
|
21
|
+
|
|
22
|
+
export interface WorkbookDraft {
|
|
23
|
+
workbook: LoadedWorkbook;
|
|
24
|
+
dirty: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const drafts = new Map<string, WorkbookDraft>();
|
|
28
|
+
|
|
29
|
+
/** The draft for a file, or undefined when it has none. */
|
|
30
|
+
export function draftFor(key: string): WorkbookDraft | undefined {
|
|
31
|
+
return drafts.get(key);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Keep an edited workbook for a file. */
|
|
35
|
+
export function rememberDraft(key: string, draft: WorkbookDraft): void {
|
|
36
|
+
drafts.set(key, draft);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Drop a file's draft — the save landed, or the edits were discarded. */
|
|
40
|
+
export function forgetDraft(key: string): void {
|
|
41
|
+
drafts.delete(key);
|
|
42
|
+
}
|
|
@@ -145,7 +145,7 @@ export type HandleWriteResult = 'written' | 'needs-permission' | 'failed';
|
|
|
145
145
|
*/
|
|
146
146
|
export async function writeThroughHandle(
|
|
147
147
|
handleId: string,
|
|
148
|
-
|
|
148
|
+
data: string | Uint8Array,
|
|
149
149
|
options: { interactive: boolean },
|
|
150
150
|
): Promise<HandleWriteResult> {
|
|
151
151
|
const handle = handles.get(handleId);
|
|
@@ -162,7 +162,7 @@ export async function writeThroughHandle(
|
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
const writable = await handle.createWritable();
|
|
165
|
-
await writable.write(
|
|
165
|
+
await writable.write(data);
|
|
166
166
|
await writable.close();
|
|
167
167
|
return 'written';
|
|
168
168
|
} catch {
|
|
@@ -3,107 +3,40 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* The app-wide scrollbar reveal rule.
|
|
8
|
-
*
|
|
9
|
-
* What this file pins is the part that is easy to get wrong and impossible to
|
|
10
|
-
* notice by hand: `scroll` does not bubble, so a document listener only sees
|
|
11
|
-
* the reveal if it is registered in the CAPTURE phase with `event.target` read
|
|
12
|
-
* as the scroller. Get that wrong and the code still runs, still adds no error
|
|
13
|
-
* anywhere, and simply never reveals a bar on any container except the page
|
|
14
|
-
* itself — which looks exactly like a CSS problem.
|
|
15
|
-
*
|
|
16
|
-
* The other half is the gate, and it is the reason this module exists in the
|
|
17
|
-
* shape it does: a PROGRAMMATIC scroll is a real, trusted `scroll` event, so a
|
|
18
|
-
* reveal keyed on the event alone pins the bar on screen for as long as
|
|
19
|
-
* anything else moves the container — measured as a chat timeline whose bar
|
|
20
|
-
* never faded during a stream, with nobody touching the page. Every case below
|
|
21
|
-
* that asserts a reveal therefore produces INPUT first, and the cases that
|
|
22
|
-
* assert no reveal are the ones with a bare scroll.
|
|
23
|
-
*
|
|
24
|
-
* Each case gets its OWN document and its own install, because the module is
|
|
25
|
-
* idempotent per document and its input clock is per install: a shared document
|
|
26
|
-
* would make every case inherit the previous one's wheel (and would make a
|
|
27
|
-
* `useFakeTimers` clock that restarts at real time read as recent input).
|
|
28
|
-
*
|
|
29
|
-
* Mounted against happy-dom, the same way the other client tests are.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
6
|
import { afterAll, afterEach, beforeAll, describe, expect, jest, test } from 'bun:test';
|
|
33
|
-
import { Window } from 'happy-dom';
|
|
34
7
|
|
|
35
8
|
import {
|
|
36
|
-
installScrollbarActivity,
|
|
37
9
|
SCROLLBAR_ACTIVE_ATTRIBUTE,
|
|
38
10
|
SCROLLBAR_IDLE_MS,
|
|
39
|
-
|
|
11
|
+
installScrollbarActivity,
|
|
40
12
|
} from '@/client/lib/scrollbar-activity';
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (!(key in nativeGlobals)) nativeGlobals[key] = target[key];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
13
|
+
import {
|
|
14
|
+
ARM_MS,
|
|
15
|
+
IDLE_MS,
|
|
16
|
+
freshPage,
|
|
17
|
+
inputAt,
|
|
18
|
+
restoreNativeGlobals,
|
|
19
|
+
saveNativeGlobals,
|
|
20
|
+
scrollAt,
|
|
21
|
+
scroller,
|
|
22
|
+
} from '@/client/lib/scrollbar-probe.test-util';
|
|
23
|
+
|
|
24
|
+
beforeAll(saveNativeGlobals);
|
|
25
|
+
afterAll(restoreNativeGlobals);
|
|
58
26
|
afterEach(() => {
|
|
59
27
|
jest.useRealTimers();
|
|
60
28
|
});
|
|
61
29
|
|
|
62
|
-
afterAll(() => {
|
|
63
|
-
const target = globalThis as unknown as Record<string, unknown>;
|
|
64
|
-
for (const key of DOM_GLOBALS) {
|
|
65
|
-
if (nativeGlobals[key] === undefined) delete target[key];
|
|
66
|
-
else target[key] = nativeGlobals[key];
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
30
|
/**
|
|
71
|
-
*
|
|
31
|
+
* The reveal gate: which scrolls may paint a bar, and for how long.
|
|
72
32
|
*
|
|
73
|
-
* A
|
|
74
|
-
*
|
|
75
|
-
*
|
|
33
|
+
* A `scroll` event alone is not proof of a user — a stream's auto-follow emits
|
|
34
|
+
* real, trusted scroll events — so the gate asks whether the user's input
|
|
35
|
+
* produced this scroll. Everything here is that question, its escape hatches
|
|
36
|
+
* (a held pointer, a delayed delivery) and the fade window.
|
|
76
37
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const target = globalThis as unknown as Record<string, unknown>;
|
|
80
|
-
for (const key of DOM_GLOBALS) target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
81
|
-
installScrollbarActivity(IDLE_MS, ARM_MS);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** A scroll container in the live document. */
|
|
85
|
-
function scroller(): HTMLElement {
|
|
86
|
-
const element = document.createElement('div');
|
|
87
|
-
document.body.appendChild(element);
|
|
88
|
-
return element;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** The event a browser dispatches at a scroller — it does not bubble. */
|
|
92
|
-
function scrollAt(element: Element): void {
|
|
93
|
-
element.dispatchEvent(new Event('scroll'));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** The input a browser delivers before a scroll the USER caused.
|
|
97
|
-
*
|
|
98
|
-
* Dispatched ON the scroller, because that is what a wheel does: it is targeted
|
|
99
|
-
* at the element under the pointer, and the arm is bound to that subtree so a
|
|
100
|
-
* wheel that could not move its container cannot later vouch for a programmatic
|
|
101
|
-
* scroll somewhere else. */
|
|
102
|
-
function inputAt(element: Element = document.body): void {
|
|
103
|
-
element.dispatchEvent(new Event('wheel'));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
describe('installScrollbarActivity', () => {
|
|
38
|
+
|
|
39
|
+
describe('the scrollbar reveal gate', () => {
|
|
107
40
|
test('a user-driven scroll on a nested container reveals ITS bar, not the page\'s', () => {
|
|
108
41
|
jest.useFakeTimers();
|
|
109
42
|
freshPage();
|
|
@@ -16,6 +16,17 @@
|
|
|
16
16
|
* timeline and the sidebar faded. Nothing about that is a per-component
|
|
17
17
|
* decision, so nothing about it should be wired per component.
|
|
18
18
|
*
|
|
19
|
+
* ## Painted on the INPUT, not on the scroll it causes
|
|
20
|
+
*
|
|
21
|
+
* The bar is painted by the `wheel`/`touch*` handler itself, on the nearest
|
|
22
|
+
* ancestor under the pointer that can overflow. Waiting for the `scroll` event
|
|
23
|
+
* means painting a frame late at best and not at all at worst — a browser
|
|
24
|
+
* dispatches `scroll` at its own frame boundary, and the gate below declines
|
|
25
|
+
* the scrolls it cannot attribute to a user. The `scroll` path is still wired,
|
|
26
|
+
* and it is the one that covers a scrollbar-thumb drag and the document's own
|
|
27
|
+
* scroll; the input path is what makes "the bar appears the moment you scroll"
|
|
28
|
+
* true without depending on either.
|
|
29
|
+
*
|
|
19
30
|
* ## Why one document listener is enough
|
|
20
31
|
*
|
|
21
32
|
* `scroll` does not bubble, so a bubble-phase listener on `document` would only
|
|
@@ -80,6 +91,14 @@
|
|
|
80
91
|
* on `documentElement`.
|
|
81
92
|
*/
|
|
82
93
|
|
|
94
|
+
import {
|
|
95
|
+
belongsTo,
|
|
96
|
+
eventMoment,
|
|
97
|
+
isScrollKey,
|
|
98
|
+
nearestScroller,
|
|
99
|
+
scrolledElement,
|
|
100
|
+
} from '@/client/lib/scrollbar-events';
|
|
101
|
+
|
|
83
102
|
/** The attribute `tailwind.css` selects on. One name, two files. */
|
|
84
103
|
export const SCROLLBAR_ACTIVE_ATTRIBUTE = 'data-scrollbar-active';
|
|
85
104
|
|
|
@@ -115,68 +134,6 @@ interface ScrollbarActivityHost {
|
|
|
115
134
|
* and Bun/Node typings disagree on what `setTimeout` returns. */
|
|
116
135
|
type FadeTimer = ReturnType<typeof setTimeout>;
|
|
117
136
|
|
|
118
|
-
/** The element whose scrollbar the event describes. */
|
|
119
|
-
function scrolledElement(target: EventTarget | null): Element | null {
|
|
120
|
-
if (target === document || target === window || target === null) {
|
|
121
|
-
// The viewport's own scroll: the bar that is painted belongs to the root
|
|
122
|
-
// element, not to the document the event names.
|
|
123
|
-
return document.documentElement;
|
|
124
|
-
}
|
|
125
|
-
return target instanceof Element ? target : null;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* WHEN an event happened, on the one clock the arm is compared on.
|
|
130
|
-
*
|
|
131
|
-
* `Date.now()` read inside a handler is when the handler RAN, and the two are
|
|
132
|
-
* not the same moment: scroll events are coalesced and delivered at the next
|
|
133
|
-
* frame, so a main thread busy with a long task (a streamed markdown render, a
|
|
134
|
-
* 36 000px transcript re-layout) can delay delivery by hundreds of milliseconds.
|
|
135
|
-
* `Event.timeStamp` is stamped when the event is CREATED, which is what makes
|
|
136
|
-
* the arm's expiry mean "this input is old" rather than "this handler is late".
|
|
137
|
-
*
|
|
138
|
-
* Engines disagree about the scroll stamp — Chrome stamps at creation, WebKit
|
|
139
|
-
* at dispatch — so this clock cannot decide whether a scroll was the user's.
|
|
140
|
-
* That is why the gate is an ARM (did any input happen since the last reveal?)
|
|
141
|
-
* and not a gap: the arm only has to bound how stale an input may be, and both
|
|
142
|
-
* engines answer that.
|
|
143
|
-
*
|
|
144
|
-
* The fallback covers synthetic events and engines that report a non-positive
|
|
145
|
-
* stamp (`0` is what a hand-built `new Event('scroll')` carries). It answers
|
|
146
|
-
* `performance.now()` and not `Date.now()`: `Event.timeStamp` is a
|
|
147
|
-
* `DOMHighResTimeStamp`, so mixing in wall time would make the subtraction a
|
|
148
|
-
* difference of two different clocks — measured as a negative gap, which would
|
|
149
|
-
* make every programmatic scroll look armed.
|
|
150
|
-
*/
|
|
151
|
-
function eventMoment(event: Event): number {
|
|
152
|
-
const stamp = event.timeStamp;
|
|
153
|
-
return Number.isFinite(stamp) && stamp > 0 ? stamp : performance.now();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Whether an input happened INSIDE the container that scrolled.
|
|
158
|
-
*
|
|
159
|
-
* An arm is spent by the first scroll that follows it, which is what stops a
|
|
160
|
-
* stream from pinning a bar — but "first scroll anywhere" was too loose: a
|
|
161
|
-
* wheel that cannot move its container (already at the top) produces no scroll
|
|
162
|
-
* event, so its arm stayed unspent for the rest of its life and the next
|
|
163
|
-
* PROGRAMMATIC scroll in any other panel could spend it. Measured: wheel up at
|
|
164
|
-
* `scrollTop = 0`, then `scrollTop = 500` 250ms later, and the bar lit for a
|
|
165
|
-
* scroll nobody made.
|
|
166
|
-
*
|
|
167
|
-
* Binding the arm to the subtree the input happened in closes that without
|
|
168
|
-
* adding a layout read: `contains` is a tree walk, not a `getComputedStyle`,
|
|
169
|
-
* and the wheel's target is already the element under the pointer.
|
|
170
|
-
*
|
|
171
|
-
* An input that names the document or the window itself (a keydown with nothing
|
|
172
|
-
* focused) is deliberately NOT bound — the scroller it drives is the focused
|
|
173
|
-
* one, which no target reveals, so it keeps the unbound behaviour.
|
|
174
|
-
*/
|
|
175
|
-
function belongsTo(element: Element, inputTarget: EventTarget | null): boolean {
|
|
176
|
-
if (inputTarget === null || inputTarget === document || inputTarget === window) return true;
|
|
177
|
-
if (inputTarget === element) return true;
|
|
178
|
-
return inputTarget instanceof Node ? element.contains(inputTarget) : false;
|
|
179
|
-
}
|
|
180
137
|
|
|
181
138
|
/**
|
|
182
139
|
* Wire the reveal rule for one document. Idempotent per document.
|
|
@@ -225,6 +182,45 @@ export function installScrollbarActivity(
|
|
|
225
182
|
armedAt = eventMoment(event);
|
|
226
183
|
armedIn = event.target;
|
|
227
184
|
};
|
|
185
|
+
|
|
186
|
+
/** Paint `element`'s bar and start its idle window over. */
|
|
187
|
+
const reveal = (element: Element) => {
|
|
188
|
+
element.setAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE, '');
|
|
189
|
+
clearTimeout(timers.get(element));
|
|
190
|
+
timers.set(
|
|
191
|
+
element,
|
|
192
|
+
setTimeout(() => {
|
|
193
|
+
timers.delete(element);
|
|
194
|
+
element.removeAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE);
|
|
195
|
+
}, idleMs),
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Reveal the surface the user's input is aimed at, AT INPUT TIME.
|
|
201
|
+
*
|
|
202
|
+
* Waiting for the `scroll` event means the bar is painted on the frame after
|
|
203
|
+
* the input — and a scroll the gate declines (a programmatic follow, an
|
|
204
|
+
* engine that dispatches the scroll after the frame budget) paints nothing at
|
|
205
|
+
* all. Painting here makes "the bar appears the moment you scroll" true by
|
|
206
|
+
* construction, and it costs no layout: the walk stops at the first ancestor
|
|
207
|
+
* that can actually overflow.
|
|
208
|
+
*
|
|
209
|
+
* Only input paints, so a stream's auto-follow still cannot light a bar. Each
|
|
210
|
+
* wheel event of a gesture restarts the idle window, which is what makes the
|
|
211
|
+
* bar stay up for as long as the user keeps scrolling instead of for 5s after
|
|
212
|
+
* the first tick of the gesture.
|
|
213
|
+
*/
|
|
214
|
+
const revealUnderPointer = (event: Event) => {
|
|
215
|
+
const element = nearestScroller(event.target);
|
|
216
|
+
if (element) reveal(element);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const noteScrollingInput = (event: Event) => {
|
|
220
|
+
noteInput(event);
|
|
221
|
+
revealUnderPointer(event);
|
|
222
|
+
};
|
|
223
|
+
|
|
228
224
|
const pressPointer = (event: Event) => {
|
|
229
225
|
heldPointer = true;
|
|
230
226
|
noteInput(event);
|
|
@@ -238,9 +234,19 @@ export function installScrollbarActivity(
|
|
|
238
234
|
// Every one of these is passive: none of them ever calls `preventDefault`,
|
|
239
235
|
// and a non-passive wheel listener is a documented cause of scroll jank.
|
|
240
236
|
const INPUT_OPTIONS = { capture: true, passive: true } as const;
|
|
241
|
-
for (const type of ['wheel', 'touchstart', 'touchmove'
|
|
242
|
-
document.addEventListener(type,
|
|
237
|
+
for (const type of ['wheel', 'touchstart', 'touchmove'] as const) {
|
|
238
|
+
document.addEventListener(type, noteScrollingInput, INPUT_OPTIONS);
|
|
243
239
|
}
|
|
240
|
+
// Only the keys that scroll arm the gate. A keydown that types a character
|
|
241
|
+
// says nothing about scrolling, and arming on it let a stream's next
|
|
242
|
+
// auto-follow paint a bar while the reader was typing in the composer.
|
|
243
|
+
document.addEventListener(
|
|
244
|
+
'keydown',
|
|
245
|
+
(event) => {
|
|
246
|
+
if (isScrollKey(event as KeyboardEvent)) noteInput(event);
|
|
247
|
+
},
|
|
248
|
+
INPUT_OPTIONS,
|
|
249
|
+
);
|
|
244
250
|
// `mousedown`/`mouseup` ride along with the pointer pair so an engine that
|
|
245
251
|
// synthesizes no pointer events for a native scrollbar still counts the drag.
|
|
246
252
|
document.addEventListener('pointerdown', pressPointer, INPUT_OPTIONS);
|
|
@@ -282,15 +288,7 @@ export function installScrollbarActivity(
|
|
|
282
288
|
armedAt = null;
|
|
283
289
|
armedIn = null;
|
|
284
290
|
}
|
|
285
|
-
element
|
|
286
|
-
clearTimeout(timers.get(element));
|
|
287
|
-
timers.set(
|
|
288
|
-
element,
|
|
289
|
-
setTimeout(() => {
|
|
290
|
-
timers.delete(element);
|
|
291
|
-
element.removeAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE);
|
|
292
|
-
}, idleMs),
|
|
293
|
-
);
|
|
291
|
+
reveal(element);
|
|
294
292
|
},
|
|
295
293
|
// Passive for the same reason the input listeners are.
|
|
296
294
|
{ capture: true, passive: true },
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The DOM questions the scrollbar reveal rule asks, split from the rule itself
|
|
8
|
+
* so each file stays readable: WHICH element a scroll is about, WHICH element
|
|
9
|
+
* an input is aimed at, WHEN an event happened, and whether a key scrolls.
|
|
10
|
+
*
|
|
11
|
+
* Nothing here keeps state. `scrollbar-activity.ts` owns the listener, the arm
|
|
12
|
+
* and the fade timer; these are the pure answers it consults, kept separate so
|
|
13
|
+
* they can be reasoned about (and changed) without reading the gate.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** The element whose scrollbar the event describes. */
|
|
17
|
+
export function scrolledElement(target: EventTarget | null): Element | null {
|
|
18
|
+
if (target === document || target === window || target === null) {
|
|
19
|
+
// The viewport's own scroll: the bar that is painted belongs to the root
|
|
20
|
+
// element, not to the document the event names.
|
|
21
|
+
return document.documentElement;
|
|
22
|
+
}
|
|
23
|
+
return target instanceof Element ? target : null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* WHEN an event happened, on the one clock the arm is compared on.
|
|
28
|
+
*
|
|
29
|
+
* `Date.now()` read inside a handler is when the handler RAN, and the two are
|
|
30
|
+
* not the same moment: scroll events are coalesced and delivered at the next
|
|
31
|
+
* frame, so a main thread busy with a long task (a streamed markdown render, a
|
|
32
|
+
* 36 000px transcript re-layout) can delay delivery by hundreds of milliseconds.
|
|
33
|
+
* `Event.timeStamp` is stamped when the event is CREATED, which is what makes
|
|
34
|
+
* the arm's expiry mean "this input is old" rather than "this handler is late".
|
|
35
|
+
*
|
|
36
|
+
* Engines disagree about the scroll stamp — Chrome stamps at creation, WebKit
|
|
37
|
+
* at dispatch — so this clock cannot decide whether a scroll was the user's.
|
|
38
|
+
* That is why the gate is an ARM (did any input happen since the last reveal?)
|
|
39
|
+
* and not a gap: the arm only has to bound how stale an input may be, and both
|
|
40
|
+
* engines answer that.
|
|
41
|
+
*
|
|
42
|
+
* The fallback covers synthetic events and engines that report a non-positive
|
|
43
|
+
* stamp (`0` is what a hand-built `new Event('scroll')` carries). It answers
|
|
44
|
+
* `performance.now()` and not `Date.now()`: `Event.timeStamp` is a
|
|
45
|
+
* `DOMHighResTimeStamp`, so mixing in wall time would make the subtraction a
|
|
46
|
+
* difference of two different clocks — measured as a negative gap, which would
|
|
47
|
+
* make every programmatic scroll look armed.
|
|
48
|
+
*/
|
|
49
|
+
export function eventMoment(event: Event): number {
|
|
50
|
+
const stamp = event.timeStamp;
|
|
51
|
+
return Number.isFinite(stamp) && stamp > 0 ? stamp : performance.now();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The `overflow` values that make an element a surface the USER can scroll. */
|
|
55
|
+
const SCROLLABLE_OVERFLOW: Readonly<Record<string, true>> = { auto: true, scroll: true, overlay: true };
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The nearest ancestor of `target` that the user's input would scroll.
|
|
59
|
+
*
|
|
60
|
+
* This answers, at INPUT time, the question the `scroll` event answers a frame
|
|
61
|
+
* later — which is what lets the bar be painted the moment the wheel turns
|
|
62
|
+
* instead of after the scroll lands. `target` itself is checked first, since a
|
|
63
|
+
* wheel over a scroller's own padding targets the scroller.
|
|
64
|
+
*
|
|
65
|
+
* No fallback to the document: an input over an element that names no scroller
|
|
66
|
+
* leaves the page's own reveal to the `scroll` path (where the root element is
|
|
67
|
+
* known to be the painted surface). Returning the root here would light the
|
|
68
|
+
* page's bar for a wheel that moved a panel.
|
|
69
|
+
*/
|
|
70
|
+
export function nearestScroller(target: EventTarget | null): Element | null {
|
|
71
|
+
let node: Element | null = target instanceof Element ? target : null;
|
|
72
|
+
for (; node && node !== document.body; node = node.parentElement) {
|
|
73
|
+
// The size test runs first: a node that cannot overflow is not a scroll
|
|
74
|
+
// surface whatever its `overflow` says, and reading it costs no style pass.
|
|
75
|
+
if (node.scrollHeight <= node.clientHeight + 1 && node.scrollWidth <= node.clientWidth + 1) continue;
|
|
76
|
+
// Through the node's own window rather than the global: the same tree is
|
|
77
|
+
// mounted in a document this module did not capture, and `getComputedStyle`
|
|
78
|
+
// is not a global in every host that runs it (the unit tests included).
|
|
79
|
+
const view = node.ownerDocument?.defaultView;
|
|
80
|
+
if (!view) continue;
|
|
81
|
+
const style = view.getComputedStyle(node);
|
|
82
|
+
if (SCROLLABLE_OVERFLOW[style.overflowY] || SCROLLABLE_OVERFLOW[style.overflowX]) return node;
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The keys that scroll the focused surface (never a typing key). */
|
|
88
|
+
const SCROLL_KEYS: Readonly<Record<string, true>> = {
|
|
89
|
+
ArrowUp: true,
|
|
90
|
+
ArrowDown: true,
|
|
91
|
+
ArrowLeft: true,
|
|
92
|
+
ArrowRight: true,
|
|
93
|
+
PageUp: true,
|
|
94
|
+
PageDown: true,
|
|
95
|
+
Home: true,
|
|
96
|
+
End: true,
|
|
97
|
+
' ': true,
|
|
98
|
+
Spacebar: true,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether an input happened INSIDE the container that scrolled.
|
|
103
|
+
*
|
|
104
|
+
* An arm is spent by the first scroll that follows it, which is what stops a
|
|
105
|
+
* stream from pinning a bar — but "first scroll anywhere" was too loose: a
|
|
106
|
+
* wheel that cannot move its container (already at the top) produces no scroll
|
|
107
|
+
* event, so its arm stayed unspent for the rest of its life and the next
|
|
108
|
+
* PROGRAMMATIC scroll in any other panel could spend it. Measured: wheel up at
|
|
109
|
+
* `scrollTop = 0`, then `scrollTop = 500` 250ms later, and the bar lit for a
|
|
110
|
+
* scroll nobody made.
|
|
111
|
+
*
|
|
112
|
+
* Binding the arm to the subtree the input happened in closes that without
|
|
113
|
+
* adding a layout read: `contains` is a tree walk, not a `getComputedStyle`,
|
|
114
|
+
* and the wheel's target is already the element under the pointer.
|
|
115
|
+
*
|
|
116
|
+
* An input that names the document or the window itself (a keydown with nothing
|
|
117
|
+
* focused) is deliberately NOT bound — the scroller it drives is the focused
|
|
118
|
+
* one, which no target reveals, so it keeps the unbound behaviour. `body` and
|
|
119
|
+
* the root element are the same case in practice: a keydown with nothing
|
|
120
|
+
* focused targets `body`, and MEASURED in Chromium and WebKit 27.2, PageDown
|
|
121
|
+
* there scrolls the panel the reader last clicked — a container `body` neither
|
|
122
|
+
* contains nor is contained by. Treating `body` as bound is what made keyboard
|
|
123
|
+
* scrolling reveal no bar at all.
|
|
124
|
+
*/
|
|
125
|
+
export function belongsTo(element: Element, inputTarget: EventTarget | null): boolean {
|
|
126
|
+
if (
|
|
127
|
+
inputTarget === null
|
|
128
|
+
|| inputTarget === document
|
|
129
|
+
|| inputTarget === window
|
|
130
|
+
|| inputTarget === document.body
|
|
131
|
+
|| inputTarget === document.documentElement
|
|
132
|
+
) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
if (inputTarget === element) return true;
|
|
136
|
+
return inputTarget instanceof Node ? element.contains(inputTarget) : false;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Whether a key press is a scroll of the focused surface (never a typing key). */
|
|
140
|
+
export function isScrollKey(event: KeyboardEvent): boolean {
|
|
141
|
+
if (event.metaKey || event.ctrlKey || event.altKey) return false;
|
|
142
|
+
return SCROLL_KEYS[event.key] === true;
|
|
143
|
+
}
|