@kabmo-labs/kabmo 0.28.0 → 0.30.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-5vjbp04s.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-palette.test.ts +72 -0
- package/src/client/glass.css +39 -14
- package/src/client/glass.test.ts +28 -67
- 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-dirty-tracking.test.ts +73 -0
- package/src/client/hooks/editor/use-dirty-tracking.ts +96 -0
- package/src/client/hooks/editor/use-file-cache.ts +1 -0
- package/src/client/hooks/editor/use-file-editor.test.ts +30 -0
- package/src/client/hooks/editor/use-file-editor.ts +20 -17
- 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 +198 -0
- package/src/server/lib/fs/archive.ts +278 -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/icons/tint-hues.generated.ts +14 -13
- 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/file-editor.test-util.ts +3 -2
- package/src/test-support/glass-css.ts +30 -0
- 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
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The spreadsheet grid's interaction contract, mounted against happy-dom.
|
|
8
|
+
*
|
|
9
|
+
* The pure halves (the selection arithmetic, the TSV payload) are pinned in
|
|
10
|
+
* `shared/lib/fs/grid-selection.test.ts`. What is left is the wiring, and each
|
|
11
|
+
* claim here is one that fails silently in a browser:
|
|
12
|
+
*
|
|
13
|
+
* - a workbook's sheet tabs switch the grid, and a legacy `.xls` opens at all;
|
|
14
|
+
* - a click selects a cell, a drag selects the block between the anchor and the
|
|
15
|
+
* pointer, and an arrow key moves the active cell;
|
|
16
|
+
* - the copy button writes the selected block as the TSV Excel pastes as cells.
|
|
17
|
+
*
|
|
18
|
+
* Rendered with `h()` (no JSX) against happy-dom, following `viewers.test.ts`.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
22
|
+
import { Window } from 'happy-dom';
|
|
23
|
+
import * as XLSX from 'xlsx';
|
|
24
|
+
import { h, render } from 'preact';
|
|
25
|
+
import { act } from 'preact/test-utils';
|
|
26
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
27
|
+
import type { ByteSource } from '@/client/components/workspace/editor/viewers/bytes';
|
|
28
|
+
import type { CsvGrid as CsvGridType } from '@/client/components/workspace/editor/viewers/CsvGrid';
|
|
29
|
+
import type { SheetView as SheetViewType } from '@/client/components/workspace/editor/viewers/SheetView';
|
|
30
|
+
|
|
31
|
+
let CsvGrid: typeof CsvGridType;
|
|
32
|
+
let SheetView: typeof SheetViewType;
|
|
33
|
+
let container: HTMLElement;
|
|
34
|
+
|
|
35
|
+
beforeAll(async () => {
|
|
36
|
+
const win = new Window({ url: 'http://localhost' });
|
|
37
|
+
installDomGlobals(win);
|
|
38
|
+
({ CsvGrid } = await import('@/client/components/workspace/editor/viewers/CsvGrid'));
|
|
39
|
+
({ SheetView } = await import('@/client/components/workspace/editor/viewers/SheetView'));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterAll(() => restoreDomGlobals());
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
if (container) render(null, container);
|
|
46
|
+
container?.remove();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/** Mount a node and settle the async load. */
|
|
50
|
+
async function mount(node: unknown) {
|
|
51
|
+
container = document.createElement('div');
|
|
52
|
+
document.body.appendChild(container);
|
|
53
|
+
await act(async () => {
|
|
54
|
+
render(node as never, container);
|
|
55
|
+
});
|
|
56
|
+
for (let i = 0; i < 20; i += 1) await Promise.resolve();
|
|
57
|
+
await act(async () => {
|
|
58
|
+
for (let i = 0; i < 20; i += 1) await Promise.resolve();
|
|
59
|
+
});
|
|
60
|
+
return container;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Dispatch a pointer event and let Preact commit the state it caused.
|
|
65
|
+
*
|
|
66
|
+
* The constructor comes off the happy-dom WINDOW: `PointerEvent` is not one of
|
|
67
|
+
* the globals `installDomGlobals` installs, so the bare name is a
|
|
68
|
+
* ReferenceError under `bun test`.
|
|
69
|
+
*/
|
|
70
|
+
async function pointer(target: Element, type: string, init: PointerEventInit = {}) {
|
|
71
|
+
await act(async () => {
|
|
72
|
+
target.dispatchEvent(new window.PointerEvent(type, { bubbles: true, button: 0, ...init }));
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A two-sheet workbook in the requested container format. */
|
|
77
|
+
function workbookBytes(bookType: 'xlsx' | 'xls'): ArrayBuffer {
|
|
78
|
+
const workbook = XLSX.utils.book_new();
|
|
79
|
+
XLSX.utils.book_append_sheet(workbook, XLSX.utils.aoa_to_sheet([['Name', 'Qty'], ['Widget', 3]]), 'First');
|
|
80
|
+
XLSX.utils.book_append_sheet(workbook, XLSX.utils.aoa_to_sheet([['Code'], ['X-1']]), 'Second');
|
|
81
|
+
return XLSX.write(workbook, { type: 'array', bookType }) as ArrayBuffer;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function workbookSource(bytes: ArrayBuffer): ByteSource {
|
|
85
|
+
return {
|
|
86
|
+
id: 'workbook',
|
|
87
|
+
url: null,
|
|
88
|
+
loadBytes: async () => bytes,
|
|
89
|
+
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
describe('SheetView sheets', () => {
|
|
94
|
+
test('every sheet is a tab, and clicking one switches the grid', async () => {
|
|
95
|
+
await mount(h(SheetView, { source: workbookSource(workbookBytes('xlsx')), name: 'book.xlsx', revision: 0 }));
|
|
96
|
+
const tabs = Array.from(container.querySelectorAll('[role="tab"]'));
|
|
97
|
+
expect(tabs.map((tab) => tab.textContent)).toEqual(['First', 'Second']);
|
|
98
|
+
expect(container.textContent).toContain('Widget');
|
|
99
|
+
|
|
100
|
+
await act(async () => {
|
|
101
|
+
(tabs[1] as HTMLElement).dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
|
|
102
|
+
});
|
|
103
|
+
expect(container.textContent).toContain('X-1');
|
|
104
|
+
expect(container.textContent).not.toContain('Widget');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// The legacy OLE2 container is the format the old reader refused outright;
|
|
108
|
+
// this is the claim that `.xls` now opens in the same viewer.
|
|
109
|
+
test('a legacy .xls workbook is read', async () => {
|
|
110
|
+
await mount(h(SheetView, { source: workbookSource(workbookBytes('xls')), name: 'legacy.xls', revision: 0 }));
|
|
111
|
+
expect(container.textContent).toContain('Widget');
|
|
112
|
+
expect(container.querySelectorAll('[role="tab"]').length).toBe(2);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('DataGrid selection', () => {
|
|
117
|
+
const csv = 'Name,Qty\nWidget,3\nGadget,1';
|
|
118
|
+
|
|
119
|
+
test('a click selects one cell and marks it active', async () => {
|
|
120
|
+
await mount(h(CsvGrid, { content: csv, path: 'data.csv' }));
|
|
121
|
+
const cell = container.querySelector('[data-row="0"][data-col="0"]') as HTMLElement;
|
|
122
|
+
await pointer(cell, 'pointerdown');
|
|
123
|
+
expect(cell.className).toContain('ring-info');
|
|
124
|
+
expect(container.textContent).toContain('A1 · 1×1');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('a drag selects the block between the anchor and the pointer', async () => {
|
|
128
|
+
await mount(h(CsvGrid, { content: csv, path: 'data.csv' }));
|
|
129
|
+
const start = container.querySelector('[data-row="0"][data-col="0"]') as HTMLElement;
|
|
130
|
+
const end = container.querySelector('[data-row="1"][data-col="1"]') as HTMLElement;
|
|
131
|
+
await pointer(start, 'pointerdown');
|
|
132
|
+
await pointer(end, 'pointerover');
|
|
133
|
+
await act(async () => {
|
|
134
|
+
window.dispatchEvent(new window.PointerEvent('pointerup', { bubbles: true }));
|
|
135
|
+
});
|
|
136
|
+
expect(container.textContent).toContain('A1:B2 · 2×2');
|
|
137
|
+
expect(end.className).toContain('bg-info/10');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('the copy button writes the selected block as TSV', async () => {
|
|
141
|
+
const written: string[] = [];
|
|
142
|
+
Object.defineProperty(navigator, 'clipboard', {
|
|
143
|
+
configurable: true,
|
|
144
|
+
value: { writeText: async (text: string) => void written.push(text) },
|
|
145
|
+
});
|
|
146
|
+
// happy-dom leaves `isSecureContext` undefined, and the clipboard helper
|
|
147
|
+
// refuses the async API without it — the fallback is `execCommand`, which
|
|
148
|
+
// happy-dom does not implement.
|
|
149
|
+
Object.defineProperty(window, 'isSecureContext', { configurable: true, value: true });
|
|
150
|
+
await mount(h(CsvGrid, { content: csv, path: 'data.csv' }));
|
|
151
|
+
const start = container.querySelector('[data-row="0"][data-col="0"]') as HTMLElement;
|
|
152
|
+
const end = container.querySelector('[data-row="1"][data-col="1"]') as HTMLElement;
|
|
153
|
+
await pointer(start, 'pointerdown');
|
|
154
|
+
await pointer(end, 'pointerover');
|
|
155
|
+
const button = Array.from(container.querySelectorAll('button')).find((node) => node.textContent?.includes('Copy'));
|
|
156
|
+
await act(async () => {
|
|
157
|
+
(button as HTMLElement).dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
|
|
158
|
+
// The copy is async: the confirmation is a state update after the
|
|
159
|
+
// clipboard promise settles.
|
|
160
|
+
for (let i = 0; i < 5; i += 1) await Promise.resolve();
|
|
161
|
+
});
|
|
162
|
+
// The CSV's first row is the header strip, so the data block starts at
|
|
163
|
+
// Widget — the same rows the grid numbers 1 and 2.
|
|
164
|
+
expect(written).toEqual(['Widget\t3\r\nGadget\t1']);
|
|
165
|
+
expect(container.textContent).toContain('Copied');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// The grid has no writer, so a paste must say so rather than do nothing.
|
|
169
|
+
test('a paste is refused in words', async () => {
|
|
170
|
+
await mount(h(CsvGrid, { content: csv, path: 'data.csv' }));
|
|
171
|
+
const grid = container.querySelector('[role="grid"]') as HTMLElement;
|
|
172
|
+
await act(async () => {
|
|
173
|
+
grid.dispatchEvent(new window.Event('paste', { bubbles: true }));
|
|
174
|
+
});
|
|
175
|
+
expect(container.textContent).toContain('This grid is read-only');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('an arrow key moves the active cell', async () => {
|
|
179
|
+
await mount(h(CsvGrid, { content: csv, path: 'data.csv' }));
|
|
180
|
+
const grid = container.querySelector('[role="grid"]') as HTMLElement;
|
|
181
|
+
const first = container.querySelector('[data-row="0"][data-col="0"]') as HTMLElement;
|
|
182
|
+
await pointer(first, 'pointerdown');
|
|
183
|
+
await act(async () => {
|
|
184
|
+
grid.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true }));
|
|
185
|
+
});
|
|
186
|
+
const next = container.querySelector('[data-row="0"][data-col="1"]') as HTMLElement;
|
|
187
|
+
expect(next.className).toContain('ring-info');
|
|
188
|
+
expect(container.textContent).toContain('B1 · 1×1');
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
/** Open a cell's inline editor with a double-click. */
|
|
193
|
+
async function openEditor(cell: Element) {
|
|
194
|
+
await act(async () => {
|
|
195
|
+
cell.dispatchEvent(new window.MouseEvent('dblclick', { bubbles: true }));
|
|
196
|
+
});
|
|
197
|
+
return container.querySelector('[data-edit-input]') as HTMLInputElement | null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Type into the open editor and press a key. */
|
|
201
|
+
async function typeAndPress(input: HTMLInputElement, value: string, key: string) {
|
|
202
|
+
await act(async () => {
|
|
203
|
+
input.value = value;
|
|
204
|
+
input.dispatchEvent(new window.Event('input', { bubbles: true }));
|
|
205
|
+
});
|
|
206
|
+
await act(async () => {
|
|
207
|
+
input.dispatchEvent(new window.KeyboardEvent('keydown', { key, bubbles: true }));
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
describe('DataGrid editing', () => {
|
|
212
|
+
const csv = 'Name,Qty\nWidget,3\nGadget,1';
|
|
213
|
+
|
|
214
|
+
test('a double-click opens the cell, and Enter writes the text back', async () => {
|
|
215
|
+
const changes: string[] = [];
|
|
216
|
+
await mount(h(CsvGrid, { content: csv, path: 'data.csv', onChange: (next) => changes.push(next) }));
|
|
217
|
+
const cell = container.querySelector('[data-row="0"][data-col="1"]') as HTMLElement;
|
|
218
|
+
const input = await openEditor(cell);
|
|
219
|
+
expect(input).not.toBeNull();
|
|
220
|
+
expect(input?.value).toBe('3');
|
|
221
|
+
|
|
222
|
+
await typeAndPress(input as HTMLInputElement, '7', 'Enter');
|
|
223
|
+
expect(changes).toEqual(['Name,Qty\nWidget,7\nGadget,1']);
|
|
224
|
+
expect(container.querySelector('[data-edit-input]')).toBeNull();
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test('Escape closes the editor without writing', async () => {
|
|
228
|
+
const changes: string[] = [];
|
|
229
|
+
await mount(h(CsvGrid, { content: csv, path: 'data.csv', onChange: (next) => changes.push(next) }));
|
|
230
|
+
const cell = container.querySelector('[data-row="0"][data-col="1"]') as HTMLElement;
|
|
231
|
+
const input = await openEditor(cell);
|
|
232
|
+
await typeAndPress(input as HTMLInputElement, '9', 'Escape');
|
|
233
|
+
expect(changes).toEqual([]);
|
|
234
|
+
expect(container.querySelector('[data-edit-input]')).toBeNull();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('a header cell is editable too', async () => {
|
|
238
|
+
const changes: string[] = [];
|
|
239
|
+
await mount(h(CsvGrid, { content: csv, path: 'data.csv', onChange: (next) => changes.push(next) }));
|
|
240
|
+
const header = container.querySelector('[data-col-header="1"]') as HTMLElement;
|
|
241
|
+
const input = await openEditor(header);
|
|
242
|
+
await typeAndPress(input as HTMLInputElement, 'Count', 'Enter');
|
|
243
|
+
expect(changes).toEqual(['Name,Count\nWidget,3\nGadget,1']);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// A capped parse holds only the first rows; writing that table back would
|
|
247
|
+
// drop every row past the cap, so the grid refuses to edit at all.
|
|
248
|
+
test('a truncated CSV is not editable', async () => {
|
|
249
|
+
const lines = ['h'];
|
|
250
|
+
for (let i = 0; i < 2100; i += 1) lines.push(String(i));
|
|
251
|
+
const changes: string[] = [];
|
|
252
|
+
await mount(h(CsvGrid, { content: lines.join('\n'), path: 'big.csv', onChange: (next) => changes.push(next) }));
|
|
253
|
+
const cell = container.querySelector('[data-row="0"][data-col="0"]') as HTMLElement;
|
|
254
|
+
expect(await openEditor(cell)).toBeNull();
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe('SheetView editing', () => {
|
|
259
|
+
test('an edited cell is written back into the workbook bytes', async () => {
|
|
260
|
+
const saved: Uint8Array[] = [];
|
|
261
|
+
const dirty: boolean[] = [];
|
|
262
|
+
await mount(
|
|
263
|
+
h(SheetView, {
|
|
264
|
+
source: workbookSource(workbookBytes('xlsx')),
|
|
265
|
+
name: 'book.xlsx',
|
|
266
|
+
path: 'book.xlsx',
|
|
267
|
+
revision: 0,
|
|
268
|
+
onSaveBytes: async (bytes: Uint8Array) => {
|
|
269
|
+
saved.push(bytes);
|
|
270
|
+
return { ok: true };
|
|
271
|
+
},
|
|
272
|
+
onDirtyChange: (value: boolean) => dirty.push(value),
|
|
273
|
+
}),
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
const cell = container.querySelector('[data-row="0"][data-col="1"]') as HTMLElement;
|
|
277
|
+
const input = await openEditor(cell);
|
|
278
|
+
await typeAndPress(input as HTMLInputElement, '7', 'Enter');
|
|
279
|
+
// The mount reports "clean" first: the editor has to state the flag it
|
|
280
|
+
// knows, or a flag left over from a closed tab would stay armed.
|
|
281
|
+
expect(dirty).toEqual([false, true]);
|
|
282
|
+
expect(container.textContent).toContain('Saving rewrites the workbook');
|
|
283
|
+
|
|
284
|
+
const save = Array.from(container.querySelectorAll('button')).find((node) => node.textContent === 'Save');
|
|
285
|
+
await act(async () => {
|
|
286
|
+
(save as HTMLElement).dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
|
|
287
|
+
for (let i = 0; i < 5; i += 1) await Promise.resolve();
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
expect(saved.length).toBe(1);
|
|
291
|
+
const written = XLSX.read(saved[0], { type: 'array' });
|
|
292
|
+
const rows = XLSX.utils.sheet_to_json<string[]>(written.Sheets.First, { header: 1, raw: false, defval: '' });
|
|
293
|
+
expect(rows[1]).toEqual(['Widget', '7']);
|
|
294
|
+
expect(dirty).toEqual([false, true, false]);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The grid's inline cell editor: which cell is open, what has been typed, and
|
|
8
|
+
* the two ways it closes.
|
|
9
|
+
*
|
|
10
|
+
* The draft is kept here rather than in the cell, because the cell is a memoised
|
|
11
|
+
* row that must not re-render for a keystroke in a different row. The grid
|
|
12
|
+
* renders the input from `edit`, and the input's own events are delegated from
|
|
13
|
+
* the scroller like every other pointer/key event.
|
|
14
|
+
*
|
|
15
|
+
* A commit is only reported when the text actually changed: opening a cell and
|
|
16
|
+
* pressing Enter must not mark the file dirty, which would make every glance at
|
|
17
|
+
* a workbook look like an edit.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { useCallback, useState } from 'preact/hooks';
|
|
21
|
+
|
|
22
|
+
export type CellSection = 'data' | 'header';
|
|
23
|
+
|
|
24
|
+
export interface CellEdit {
|
|
25
|
+
section: CellSection;
|
|
26
|
+
/** Data row, or 0 for the header strip. */
|
|
27
|
+
row: number;
|
|
28
|
+
col: number;
|
|
29
|
+
/** The text in the input. */
|
|
30
|
+
value: string;
|
|
31
|
+
/** The text the cell held when the editor opened. */
|
|
32
|
+
initial: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface CellEditor {
|
|
36
|
+
edit: CellEdit | null;
|
|
37
|
+
begin: (section: CellSection, row: number, col: number, initial: string) => void;
|
|
38
|
+
change: (value: string) => void;
|
|
39
|
+
/** Close the editor, reporting the new value when it differs. */
|
|
40
|
+
commit: () => void;
|
|
41
|
+
/** Close the editor and keep the old value. */
|
|
42
|
+
cancel: () => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function useCellEdit(onCommit: (edit: CellEdit) => void): CellEditor {
|
|
46
|
+
const [edit, setEdit] = useState<CellEdit | null>(null);
|
|
47
|
+
|
|
48
|
+
const begin = useCallback((section: CellSection, row: number, col: number, initial: string) => {
|
|
49
|
+
setEdit({ section, row, col, value: initial, initial });
|
|
50
|
+
}, []);
|
|
51
|
+
|
|
52
|
+
const change = useCallback((value: string) => {
|
|
53
|
+
setEdit((previous) => (previous ? { ...previous, value } : previous));
|
|
54
|
+
}, []);
|
|
55
|
+
|
|
56
|
+
const commit = useCallback(() => {
|
|
57
|
+
if (edit && edit.value !== edit.initial) onCommit(edit);
|
|
58
|
+
setEdit(null);
|
|
59
|
+
}, [edit, onCommit]);
|
|
60
|
+
|
|
61
|
+
const cancel = useCallback(() => setEdit(null), []);
|
|
62
|
+
|
|
63
|
+
return { edit, begin, change, commit, cancel };
|
|
64
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The grid's delegated event handlers: pointer, keyboard, clipboard and the
|
|
8
|
+
* inline editor's input.
|
|
9
|
+
*
|
|
10
|
+
* One listener per event on the scroller, not one per cell: a 2000-row sheet is
|
|
11
|
+
* 200 000 cells, and a closure per cell is what makes such a grid unresponsive.
|
|
12
|
+
* The handler reads `data-row`/`data-col` off the event target instead.
|
|
13
|
+
*
|
|
14
|
+
* Split from `DataGrid` for the repository's line ceiling, and because the
|
|
15
|
+
* handlers are a self-contained cluster: they translate DOM events into
|
|
16
|
+
* selection and edit operations and own no rendering.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { RefObject } from 'preact';
|
|
20
|
+
import type { GridSelection } from '@/client/hooks/editor/use-grid-selection';
|
|
21
|
+
import type { CellEditor, CellSection } from '@/client/components/workspace/editor/viewers/use-cell-edit';
|
|
22
|
+
import type { CopyState } from '@/client/components/workspace/editor/viewers/GridToolbar';
|
|
23
|
+
import { rangeToTsv, type GridCell } from '@/shared/lib/fs/grid-selection';
|
|
24
|
+
|
|
25
|
+
interface GridInteractionOptions {
|
|
26
|
+
cells: string[][];
|
|
27
|
+
width: number;
|
|
28
|
+
selection: GridSelection;
|
|
29
|
+
editor: CellEditor;
|
|
30
|
+
scrollerRef: RefObject<HTMLDivElement>;
|
|
31
|
+
startEdit: (section: CellSection, row: number, col: number, initial?: string) => void;
|
|
32
|
+
onEditCell?: (row: number, col: number, value: string) => void;
|
|
33
|
+
setCopyState: (state: CopyState) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface GridInteraction {
|
|
37
|
+
onPointerDown: (event: PointerEvent) => void;
|
|
38
|
+
onPointerOver: (event: PointerEvent) => void;
|
|
39
|
+
onDoubleClick: (event: MouseEvent) => void;
|
|
40
|
+
onInput: (event: Event) => void;
|
|
41
|
+
onKeyDown: (event: KeyboardEvent) => void;
|
|
42
|
+
onCopy: (event: ClipboardEvent) => void;
|
|
43
|
+
onPaste: (event: ClipboardEvent) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The cell a pointer event landed on, or null. */
|
|
47
|
+
function cellFromEvent(event: Event): GridCell | null {
|
|
48
|
+
const cell = (event.target as Element | null)?.closest?.('[data-row][data-col]') as HTMLElement | null;
|
|
49
|
+
if (!cell) return null;
|
|
50
|
+
return { row: Number(cell.dataset.row), col: Number(cell.dataset.col) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function useGridInteraction({
|
|
54
|
+
cells,
|
|
55
|
+
width,
|
|
56
|
+
selection,
|
|
57
|
+
editor,
|
|
58
|
+
scrollerRef,
|
|
59
|
+
startEdit,
|
|
60
|
+
onEditCell,
|
|
61
|
+
setCopyState,
|
|
62
|
+
}: GridInteractionOptions): GridInteraction {
|
|
63
|
+
const edit = editor.edit;
|
|
64
|
+
const active = selection.active;
|
|
65
|
+
|
|
66
|
+
const onPointerDown = (event: PointerEvent) => {
|
|
67
|
+
if (event.button !== 0) return;
|
|
68
|
+
const target = event.target as Element | null;
|
|
69
|
+
if (target?.closest?.('[data-edit-input]')) return;
|
|
70
|
+
// A click anywhere else closes the open editor first, so the click's own
|
|
71
|
+
// meaning (select, drag, header) is what happens next.
|
|
72
|
+
if (edit) editor.commit();
|
|
73
|
+
const cell = cellFromEvent(event);
|
|
74
|
+
if (cell) {
|
|
75
|
+
scrollerRef.current?.focus();
|
|
76
|
+
selection.begin(cell, event.shiftKey);
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const column = target?.closest?.('[data-col-header]') as HTMLElement | null;
|
|
81
|
+
if (column) {
|
|
82
|
+
scrollerRef.current?.focus();
|
|
83
|
+
selection.selectColumn(Number(column.dataset.colHeader), event.shiftKey);
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const row = target?.closest?.('[data-row-header]') as HTMLElement | null;
|
|
88
|
+
if (row) {
|
|
89
|
+
scrollerRef.current?.focus();
|
|
90
|
+
selection.selectRow(Number(row.dataset.rowHeader), event.shiftKey);
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (target?.closest?.('[data-corner]')) {
|
|
95
|
+
scrollerRef.current?.focus();
|
|
96
|
+
selection.selectAll();
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const onPointerOver = (event: PointerEvent) => {
|
|
102
|
+
// `extendTo` reads the drag flag from a ref, not from this render's state:
|
|
103
|
+
// the first pointerover can arrive before the pointerdown's state update
|
|
104
|
+
// has been committed.
|
|
105
|
+
const cell = cellFromEvent(event);
|
|
106
|
+
if (cell) selection.extendTo(cell);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const onDoubleClick = (event: MouseEvent) => {
|
|
110
|
+
const cell = cellFromEvent(event);
|
|
111
|
+
if (cell) {
|
|
112
|
+
startEdit('data', cell.row, cell.col);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const column = (event.target as Element | null)?.closest?.('[data-col-header]') as HTMLElement | null;
|
|
116
|
+
if (column) startEdit('header', 0, Number(column.dataset.colHeader));
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const onInput = (event: Event) => {
|
|
120
|
+
const input = event.target as HTMLInputElement;
|
|
121
|
+
if (input.matches?.('[data-edit-input]')) editor.change(input.value);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
125
|
+
if (edit) {
|
|
126
|
+
if (event.key === 'Enter') {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
editor.commit();
|
|
129
|
+
selection.move(event.shiftKey ? -1 : 1, 0, false);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (event.key === 'Tab') {
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
editor.commit();
|
|
135
|
+
selection.move(0, event.shiftKey ? -1 : 1, false);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (event.key === 'Escape') {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
editor.cancel();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const meta = event.metaKey || event.ctrlKey;
|
|
146
|
+
if (meta && event.key.toLowerCase() === 'a') {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
selection.selectAll();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (event.key === 'Escape') {
|
|
152
|
+
selection.clear();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (event.key === 'Enter' || event.key === 'F2') {
|
|
156
|
+
if (!onEditCell || !active) return;
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
startEdit('data', active.row, active.col);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (event.key === 'Delete' || event.key === 'Backspace') {
|
|
162
|
+
if (!onEditCell || !active) return;
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
onEditCell(active.row, active.col, '');
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (event.key.length === 1 && !meta && !event.altKey) {
|
|
168
|
+
if (!onEditCell || !active) return;
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
startEdit('data', active.row, active.col, event.key);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const step: Record<string, [number, number]> = {
|
|
174
|
+
ArrowUp: [-1, 0],
|
|
175
|
+
ArrowDown: [1, 0],
|
|
176
|
+
ArrowLeft: [0, -1],
|
|
177
|
+
ArrowRight: [0, 1],
|
|
178
|
+
};
|
|
179
|
+
const delta = step[event.key];
|
|
180
|
+
if (delta) {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
selection.move(delta[0], delta[1], event.shiftKey);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (event.key === 'Home' || event.key === 'End') {
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
const column = event.key === 'Home' ? 0 : width - 1;
|
|
188
|
+
const row = meta ? (event.key === 'Home' ? 0 : cells.length - 1) : (active?.row ?? 0);
|
|
189
|
+
selection.move(row - (active?.row ?? 0), column - (active?.col ?? 0), event.shiftKey);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// The browser's own copy event is the one Ctrl/Cmd+C and the context menu
|
|
194
|
+
// both raise, so the payload is written there rather than in a key handler.
|
|
195
|
+
//
|
|
196
|
+
// An open cell editor OWNS the clipboard: while a value is being typed,
|
|
197
|
+
// Ctrl/Cmd+C means "copy what I selected in the input", and hijacking it with
|
|
198
|
+
// the cell range would make editing a cell with a copied fragment impossible.
|
|
199
|
+
const onCopy = (event: ClipboardEvent) => {
|
|
200
|
+
if (edit) return;
|
|
201
|
+
if (!selection.range) return;
|
|
202
|
+
event.clipboardData?.setData('text/plain', rangeToTsv(cells, selection.range));
|
|
203
|
+
event.preventDefault();
|
|
204
|
+
setCopyState('copied');
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// A paste is REFUSED in words, not swallowed: the grid has no writer, and a
|
|
208
|
+
// paste that silently did nothing would read as a broken clipboard.
|
|
209
|
+
const onPaste = (event: ClipboardEvent) => {
|
|
210
|
+
if (edit) return;
|
|
211
|
+
event.preventDefault();
|
|
212
|
+
setCopyState('refused');
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
return { onPointerDown, onPointerOver, onDoubleClick, onInput, onKeyDown, onCopy, onPaste };
|
|
216
|
+
}
|
|
@@ -32,12 +32,14 @@ import type { CsvGrid as CsvGridType } from '@/client/components/workspace/edito
|
|
|
32
32
|
import type { SvgPreview as SvgPreviewType } from '@/client/components/workspace/editor/viewers/SvgPreview';
|
|
33
33
|
import type { DocxView as DocxViewType } from '@/client/components/workspace/editor/viewers/DocxView';
|
|
34
34
|
import type { SheetView as SheetViewType } from '@/client/components/workspace/editor/viewers/SheetView';
|
|
35
|
+
import type { DrawioView as DrawioViewType } from '@/client/components/workspace/editor/viewers/DrawioView';
|
|
35
36
|
import type { ViewerSurface as ViewerSurfaceType, hasViewerSurface as HasViewerSurfaceType } from '@/client/components/workspace/editor/viewers/dispatch';
|
|
36
37
|
|
|
37
38
|
let CsvGrid: typeof CsvGridType;
|
|
38
39
|
let SvgPreview: typeof SvgPreviewType;
|
|
39
40
|
let DocxView: typeof DocxViewType;
|
|
40
41
|
let SheetView: typeof SheetViewType;
|
|
42
|
+
let DrawioView: typeof DrawioViewType;
|
|
41
43
|
let ViewerSurface: typeof ViewerSurfaceType;
|
|
42
44
|
let hasViewerSurface: typeof HasViewerSurfaceType;
|
|
43
45
|
let container: HTMLElement;
|
|
@@ -49,6 +51,7 @@ beforeAll(async () => {
|
|
|
49
51
|
({ SvgPreview } = await import('@/client/components/workspace/editor/viewers/SvgPreview'));
|
|
50
52
|
({ DocxView } = await import('@/client/components/workspace/editor/viewers/DocxView'));
|
|
51
53
|
({ SheetView } = await import('@/client/components/workspace/editor/viewers/SheetView'));
|
|
54
|
+
({ DrawioView } = await import('@/client/components/workspace/editor/viewers/DrawioView'));
|
|
52
55
|
({ ViewerSurface, hasViewerSurface } = await import('@/client/components/workspace/editor/viewers/dispatch'));
|
|
53
56
|
});
|
|
54
57
|
|
|
@@ -87,7 +90,7 @@ describe('CsvGrid', () => {
|
|
|
87
90
|
// grid: a quoted comma must stay inside one cell.
|
|
88
91
|
test('a quoted cell keeps its comma, so the row is not split', async () => {
|
|
89
92
|
await mount(h(CsvGrid, { content: 'a,b\n"x,y",z', path: 'data.csv' }));
|
|
90
|
-
const cells = Array.from(container.querySelectorAll('tbody tr:first-child
|
|
93
|
+
const cells = Array.from(container.querySelectorAll('tbody tr:first-child > *')).map((cell) => cell.textContent);
|
|
91
94
|
// The first cell is the row number; then the two data cells.
|
|
92
95
|
expect(cells).toEqual(['1', 'x,y', 'z']);
|
|
93
96
|
});
|
|
@@ -225,7 +228,7 @@ describe('DocxView', () => {
|
|
|
225
228
|
|
|
226
229
|
describe('hasViewerSurface', () => {
|
|
227
230
|
test('the drawn kinds have a surface; text kinds do not', () => {
|
|
228
|
-
for (const kind of ['image', 'pdf', 'docx', 'spreadsheet', 'csv', 'svg'] as const) {
|
|
231
|
+
for (const kind of ['image', 'pdf', 'docx', 'spreadsheet', 'csv', 'svg', 'drawio'] as const) {
|
|
229
232
|
expect(hasViewerSurface(kind)).toBe(true);
|
|
230
233
|
}
|
|
231
234
|
for (const kind of ['code', 'markdown'] as const) {
|
|
@@ -247,12 +250,54 @@ describe('ViewerSurface routing', () => {
|
|
|
247
250
|
expect(container.textContent).toContain('b');
|
|
248
251
|
});
|
|
249
252
|
|
|
253
|
+
// A drawio file reads the TEXT buffer, so the diagram renders with no byte
|
|
254
|
+
// source at all — proving the dispatch routed to DrawioView.
|
|
255
|
+
test('a drawio kind draws the diagram from the text buffer', async () => {
|
|
256
|
+
const content =
|
|
257
|
+
'<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/>' +
|
|
258
|
+
'<mxCell id="a" value="Hello" vertex="1" parent="1"><mxGeometry x="0" y="0" width="80" height="40" as="geometry"/></mxCell>' +
|
|
259
|
+
'</root></mxGraphModel>';
|
|
260
|
+
await mount(
|
|
261
|
+
h(ViewerSurface, { kind: 'drawio', path: 'flow.drawio', name: 'flow.drawio', source: noSource, content, revision: 0 }),
|
|
262
|
+
);
|
|
263
|
+
// happy-dom drops inline SVG children set through `innerHTML`, so the
|
|
264
|
+
// drawing itself is pinned in `drawio-pages.test.ts`; here the claim is the
|
|
265
|
+
// dispatch — the drawio kind reached the diagram surface, not the code one.
|
|
266
|
+
expect(container.querySelector('.drawio-preview svg')).not.toBeNull();
|
|
267
|
+
});
|
|
268
|
+
|
|
250
269
|
test('a kind with no surface here renders nothing', async () => {
|
|
251
270
|
await mount(h(ViewerSurface, { kind: 'code', path: 'a.ts', name: 'a.ts', source: noSource, content: 'x', revision: 0 }));
|
|
252
271
|
expect(container.textContent).toBe('');
|
|
253
272
|
});
|
|
254
273
|
});
|
|
255
274
|
|
|
275
|
+
describe('DrawioView', () => {
|
|
276
|
+
const page = (name: string, label: string) =>
|
|
277
|
+
`<diagram name="${name}"><mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/>` +
|
|
278
|
+
`<mxCell id="a" value="${label}" vertex="1" parent="1"><mxGeometry x="0" y="0" width="80" height="40" as="geometry"/></mxCell>` +
|
|
279
|
+
`</root></mxGraphModel></diagram>`;
|
|
280
|
+
|
|
281
|
+
// A five-page document must not silently show page one. (The drawing itself
|
|
282
|
+
// is pinned in `drawio-pages.test.ts`; happy-dom drops inline SVG children
|
|
283
|
+
// set through `innerHTML`, so this asserts the chrome.)
|
|
284
|
+
test('draws every page with its own caption', async () => {
|
|
285
|
+
await mount(h(DrawioView, { content: `<mxfile>${page('One', 'First')}${page('Two', 'Second')}</mxfile>`, name: 'flow.drawio' }));
|
|
286
|
+
expect(container.querySelectorAll('.drawio-preview svg')).toHaveLength(2);
|
|
287
|
+
expect(container.textContent).toContain('One');
|
|
288
|
+
expect(container.textContent).toContain('Two');
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// A file that cannot be read is REPORTED with the parser's own sentence,
|
|
292
|
+
// never drawn as an empty page.
|
|
293
|
+
test('a file that is not drawio is reported, not drawn', async () => {
|
|
294
|
+
await mount(h(DrawioView, { content: '<html><body/></html>', name: 'broken.drawio' }));
|
|
295
|
+
expect(container.querySelector('.drawio-preview')).toBeNull();
|
|
296
|
+
expect(container.textContent).toContain('Could not show broken.drawio');
|
|
297
|
+
expect(container.textContent).toContain('not a draw.io file');
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
256
301
|
describe('SheetView', () => {
|
|
257
302
|
// A workbook that cannot be parsed reports the parser's own sentence, never an
|
|
258
303
|
// empty grid — the same failure shape DocxView pins.
|