@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
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Archive names, formats and destinations — the facts BOTH ends need.
|
|
8
|
+
*
|
|
9
|
+
* The Files panel decides which menu rows to offer (Extract only on an archive,
|
|
10
|
+
* Compress on any selection) and which name a new archive should take; the
|
|
11
|
+
* server decides which binary runs and refuses what cannot be written. Keeping
|
|
12
|
+
* the suffix table, the format list and the default names in one module is what
|
|
13
|
+
* stops the dialog from offering `.zip` while the route expects `.7z`.
|
|
14
|
+
*
|
|
15
|
+
* The compress list is intentionally shorter than the extract list: extracting
|
|
16
|
+
* a `.rar` only needs a reader, while creating one needs the proprietary `rar`
|
|
17
|
+
* binary, which most machines do not ship. The dialog reports the formats the
|
|
18
|
+
* server can actually run.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** A format the Compress dialog can write. */
|
|
22
|
+
export type ArchiveFormat = 'zip' | '7z' | 'rar' | 'tar' | 'tar.gz';
|
|
23
|
+
|
|
24
|
+
/** Every archive spelling the Extract menu recognises. */
|
|
25
|
+
export type ArchiveKind =
|
|
26
|
+
| 'zip'
|
|
27
|
+
| '7z'
|
|
28
|
+
| 'rar'
|
|
29
|
+
| 'tar'
|
|
30
|
+
| 'tar.gz'
|
|
31
|
+
| 'tar.bz2'
|
|
32
|
+
| 'tar.xz'
|
|
33
|
+
| 'gz'
|
|
34
|
+
| 'bz2'
|
|
35
|
+
| 'xz';
|
|
36
|
+
|
|
37
|
+
export interface ArchiveFormatInfo {
|
|
38
|
+
id: ArchiveFormat;
|
|
39
|
+
/** What the dialog shows. */
|
|
40
|
+
label: string;
|
|
41
|
+
/** The suffix the default name takes, without a dot. */
|
|
42
|
+
extension: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const COMPRESS_FORMATS: readonly ArchiveFormatInfo[] = [
|
|
46
|
+
{ id: 'zip', label: 'ZIP', extension: 'zip' },
|
|
47
|
+
{ id: '7z', label: '7Z', extension: '7z' },
|
|
48
|
+
{ id: 'rar', label: 'RAR', extension: 'rar' },
|
|
49
|
+
{ id: 'tar', label: 'TAR', extension: 'tar' },
|
|
50
|
+
{ id: 'tar.gz', label: 'TAR.GZ', extension: 'tar.gz' },
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
/** Suffix → kind, longest first so `.tar.gz` is not read as `.gz`. */
|
|
54
|
+
const KIND_SUFFIXES: ReadonlyArray<readonly [string, ArchiveKind]> = [
|
|
55
|
+
['.tar.gz', 'tar.gz'],
|
|
56
|
+
['.tar.bz2', 'tar.bz2'],
|
|
57
|
+
['.tar.xz', 'tar.xz'],
|
|
58
|
+
['.tgz', 'tar.gz'],
|
|
59
|
+
['.tbz2', 'tar.bz2'],
|
|
60
|
+
['.txz', 'tar.xz'],
|
|
61
|
+
['.tar', 'tar'],
|
|
62
|
+
['.zip', 'zip'],
|
|
63
|
+
['.7z', '7z'],
|
|
64
|
+
['.rar', 'rar'],
|
|
65
|
+
['.gz', 'gz'],
|
|
66
|
+
['.bz2', 'bz2'],
|
|
67
|
+
['.xz', 'xz'],
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
/** The archive kind `name` is spelled as, or null when it is not one. */
|
|
71
|
+
export function archiveKindOf(name: string): ArchiveKind | null {
|
|
72
|
+
const lower = name.toLowerCase();
|
|
73
|
+
for (const [suffix, kind] of KIND_SUFFIXES) {
|
|
74
|
+
if (lower.endsWith(suffix)) return kind;
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Whether a row is an archive the panel can offer Extract for. */
|
|
80
|
+
export function isArchiveName(name: string): boolean {
|
|
81
|
+
return archiveKindOf(name) !== null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The format entry for an id, or undefined for an unknown id. */
|
|
85
|
+
export function archiveFormatInfo(format: string): ArchiveFormatInfo | undefined {
|
|
86
|
+
return COMPRESS_FORMATS.find((entry) => entry.id === format);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The extension a format's file name ends with, without the dot. */
|
|
90
|
+
export function archiveExtension(format: ArchiveFormat): string {
|
|
91
|
+
return archiveFormatInfo(format)?.extension ?? 'zip';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The name with any recognised archive suffix removed (`a.tar.gz` → `a`). */
|
|
95
|
+
export function stripArchiveSuffix(name: string): string {
|
|
96
|
+
const lower = name.toLowerCase();
|
|
97
|
+
for (const [suffix] of KIND_SUFFIXES) {
|
|
98
|
+
if (lower.endsWith(suffix)) return name.slice(0, -suffix.length);
|
|
99
|
+
}
|
|
100
|
+
return name;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The folder part of a relative POSIX path, `.` at the top. */
|
|
104
|
+
export function parentDirOf(path: string): string {
|
|
105
|
+
const cut = path.lastIndexOf('/');
|
|
106
|
+
return cut === -1 ? '.' : path.slice(0, cut) || '.';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The last segment of a relative POSIX path. */
|
|
110
|
+
export function baseNameOf(path: string): string {
|
|
111
|
+
const cut = path.lastIndexOf('/');
|
|
112
|
+
return cut === -1 ? path : path.slice(cut + 1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The deepest folder that contains every path.
|
|
117
|
+
*
|
|
118
|
+
* A compress runs with that folder as its working directory, so every argument
|
|
119
|
+
* is a clean relative name rather than a `../` climb — which is also the rule
|
|
120
|
+
* the server enforces. Paths from different branches therefore share `.` and
|
|
121
|
+
* the archive sits at the listing root.
|
|
122
|
+
*/
|
|
123
|
+
export function commonParentDir(paths: readonly string[]): string {
|
|
124
|
+
if (paths.length === 0) return '.';
|
|
125
|
+
const split = paths.map((path) => parentDirOf(path).split('/').filter((segment) => segment !== '.'));
|
|
126
|
+
let shared = split[0] ?? [];
|
|
127
|
+
for (const segments of split.slice(1)) {
|
|
128
|
+
let index = 0;
|
|
129
|
+
while (index < shared.length && index < segments.length && shared[index] === segments[index]) index += 1;
|
|
130
|
+
shared = shared.slice(0, index);
|
|
131
|
+
}
|
|
132
|
+
return shared.length === 0 ? '.' : shared.join('/');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface ArchiveNameSource {
|
|
136
|
+
path: string;
|
|
137
|
+
name: string;
|
|
138
|
+
kind: 'file' | 'folder';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The name a Compress dialog proposes.
|
|
143
|
+
*
|
|
144
|
+
* One file keeps its stem (`report.pdf` → `report.zip`), one folder its own
|
|
145
|
+
* name (`src` → `src.zip`), and a multi-selection takes the name of the folder
|
|
146
|
+
* they live in — naming the archive after the first arbitrary file would hide
|
|
147
|
+
* what it holds.
|
|
148
|
+
*/
|
|
149
|
+
export function defaultArchiveName(entries: readonly ArchiveNameSource[], format: ArchiveFormat): string {
|
|
150
|
+
const extension = archiveExtension(format);
|
|
151
|
+
if (entries.length === 1) {
|
|
152
|
+
const entry = entries[0]!;
|
|
153
|
+
// A file's own extension is dropped too: `report.pdf` compresses to
|
|
154
|
+
// `report.zip`, not `report.pdf.zip`, which reads as an archive of a PDF
|
|
155
|
+
// renamed twice.
|
|
156
|
+
const withoutArchive = stripArchiveSuffix(entry.name);
|
|
157
|
+
const dot = withoutArchive.lastIndexOf('.');
|
|
158
|
+
const stem = entry.kind === 'folder'
|
|
159
|
+
? entry.name
|
|
160
|
+
: dot > 0 ? withoutArchive.slice(0, dot) : withoutArchive;
|
|
161
|
+
return `${stem || 'archive'}.${extension}`;
|
|
162
|
+
}
|
|
163
|
+
const common = commonParentDir(entries.map((entry) => entry.path));
|
|
164
|
+
const folder = baseNameOf(common);
|
|
165
|
+
return `${folder === '.' || folder === '' ? 'archive' : folder}.${extension}`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The destination a Compress dialog proposes: the folder the selection lives
|
|
170
|
+
* in, which is where the archive appears beside it.
|
|
171
|
+
*/
|
|
172
|
+
export function defaultArchiveDestination(entries: readonly ArchiveNameSource[]): string {
|
|
173
|
+
return commonParentDir(entries.map((entry) => entry.path));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The folder an Extract dialog proposes: a sibling of the archive named after
|
|
178
|
+
* its stem (`src.zip` → `src`). Extracting in place is the same call with `.`
|
|
179
|
+
* typed in the field, so the default never scatters files beside the archive.
|
|
180
|
+
*/
|
|
181
|
+
export function defaultExtractDestination(archivePath: string): string {
|
|
182
|
+
const parent = parentDirOf(archivePath);
|
|
183
|
+
const stem = stripArchiveSuffix(baseNameOf(archivePath));
|
|
184
|
+
if (!stem) return parent;
|
|
185
|
+
return parent === '.' ? stem : `${parent}/${stem}`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** The display name of an archive kind, for the dialog's subtitle. */
|
|
189
|
+
export function archiveKindLabel(kind: ArchiveKind): string {
|
|
190
|
+
return kind.toUpperCase();
|
|
191
|
+
}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import { describe, expect, test } from 'bun:test';
|
|
17
17
|
import {
|
|
18
|
+
clipboardLabel,
|
|
18
19
|
dropRefusal,
|
|
19
20
|
duplicateName,
|
|
20
21
|
fsClipboardScope,
|
|
@@ -29,9 +30,7 @@ import {
|
|
|
29
30
|
|
|
30
31
|
const clip = (over: Partial<FsClipboard> = {}): FsClipboard => ({
|
|
31
32
|
scope: 'ws\u0000.',
|
|
32
|
-
path: 'src/a.ts',
|
|
33
|
-
name: 'a.ts',
|
|
34
|
-
kind: 'file',
|
|
33
|
+
entries: [{ path: 'src/a.ts', name: 'a.ts', kind: 'file' }],
|
|
35
34
|
mode: 'copy',
|
|
36
35
|
...over,
|
|
37
36
|
});
|
|
@@ -140,15 +139,26 @@ describe('pasteRefusal', () => {
|
|
|
140
139
|
|
|
141
140
|
test('allows a paste of this listing’s entry and applies the folder rule', () => {
|
|
142
141
|
expect(pasteRefusal(clip(), 'ws\u0000.', 'other')).toBeNull();
|
|
143
|
-
expect(pasteRefusal(clip({ path: 'src', kind: 'folder' }), 'ws\u0000.', 'src/sub')).toContain('itself');
|
|
142
|
+
expect(pasteRefusal(clip({ entries: [{ path: 'src', name: 'src', kind: 'folder' }] }), 'ws\u0000.', 'src/sub')).toContain('itself');
|
|
144
143
|
});
|
|
145
144
|
|
|
146
145
|
test('a CUT into its own folder is refused; a COPY into it is how a copy is made', () => {
|
|
147
146
|
// The two modes differ here on purpose: copying a file into the directory
|
|
148
147
|
// it already lives in is how `a copy.ts` is produced, while a cut there
|
|
149
148
|
// would have nothing to do.
|
|
150
|
-
expect(pasteRefusal(clip({
|
|
151
|
-
expect(pasteRefusal(clip({
|
|
149
|
+
expect(pasteRefusal(clip({ mode: 'cut' }), 'ws\u0000.', 'src')).toBe('Already in this folder');
|
|
150
|
+
expect(pasteRefusal(clip({ mode: 'copy' }), 'ws\u0000.', 'src')).toBeNull();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe('clipboardLabel', () => {
|
|
155
|
+
test('names the one entry, or counts a selection', () => {
|
|
156
|
+
expect(clipboardLabel(null)).toBeNull();
|
|
157
|
+
expect(clipboardLabel(clip())).toBe('a.ts');
|
|
158
|
+
expect(clipboardLabel(clip({ entries: [
|
|
159
|
+
{ path: 'a.ts', name: 'a.ts', kind: 'file' },
|
|
160
|
+
{ path: 'b.ts', name: 'b.ts', kind: 'file' },
|
|
161
|
+
] }))).toBe('2 items');
|
|
152
162
|
});
|
|
153
163
|
});
|
|
154
164
|
|
|
@@ -165,10 +175,23 @@ describe('readFsClipboard', () => {
|
|
|
165
175
|
expect(readFsClipboard(clip())).toEqual(clip());
|
|
166
176
|
});
|
|
167
177
|
|
|
178
|
+
test('accepts a multi-entry selection', () => {
|
|
179
|
+
const multi = clip({ entries: [
|
|
180
|
+
{ path: 'src/a.ts', name: 'a.ts', kind: 'file' },
|
|
181
|
+
{ path: 'src/deep', name: 'deep', kind: 'folder' },
|
|
182
|
+
] });
|
|
183
|
+
expect(readFsClipboard(multi)).toEqual(multi);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('migrates the single-entry shape an older tab wrote', () => {
|
|
187
|
+
const legacy = { scope: 'ws\u0000.', path: 'src/a.ts', name: 'a.ts', kind: 'file', mode: 'copy' };
|
|
188
|
+
expect(readFsClipboard(legacy)).toEqual(clip());
|
|
189
|
+
});
|
|
190
|
+
|
|
168
191
|
test('rejects a path that names no child of the listing root', () => {
|
|
169
192
|
// Every one of these would resolve outside the folder the entry claims.
|
|
170
193
|
for (const path of ['.', '', '..', 'a/../b', '/etc/passwd', 'a//b']) {
|
|
171
|
-
expect(readFsClipboard(clip({ path }))).toBeNull();
|
|
194
|
+
expect(readFsClipboard(clip({ entries: [{ path, name: 'x', kind: 'file' }] }))).toBeNull();
|
|
172
195
|
}
|
|
173
196
|
});
|
|
174
197
|
|
|
@@ -178,5 +201,7 @@ describe('readFsClipboard', () => {
|
|
|
178
201
|
expect(readFsClipboard({ path: 'a.ts', name: 'a.ts', scope: 's', kind: 'file' })).toBeNull();
|
|
179
202
|
expect(readFsClipboard({ path: 'a.ts', name: 'a.ts', scope: 's', mode: 'copy' })).toBeNull();
|
|
180
203
|
expect(readFsClipboard({ path: 'a.ts', name: 'a.ts', scope: 's', kind: 'file', mode: 'move' })).toBeNull();
|
|
204
|
+
expect(readFsClipboard({ scope: 's', entries: [], mode: 'copy' })).toBeNull();
|
|
205
|
+
expect(readFsClipboard({ scope: 's', entries: [{ path: 'a.ts', name: 'a.ts', kind: 'link' }], mode: 'copy' })).toBeNull();
|
|
181
206
|
});
|
|
182
207
|
});
|
|
@@ -20,17 +20,30 @@
|
|
|
20
20
|
* user copied somewhere else.
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
export interface
|
|
25
|
-
/** The `\0`-joined `root\0repo` the path is relative to. */
|
|
26
|
-
scope: string;
|
|
23
|
+
/** One entry a Cut or a Copy put on the clipboard. */
|
|
24
|
+
export interface FsClipboardEntry {
|
|
27
25
|
/** Path relative to the listed root; never `.` — the root itself cannot be moved. */
|
|
28
26
|
path: string;
|
|
29
27
|
name: string;
|
|
30
28
|
kind: 'file' | 'folder';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** What a Cut or a Copy put on the clipboard: one entry, or a whole selection. */
|
|
32
|
+
export interface FsClipboard {
|
|
33
|
+
/** The `\0`-joined `root\0repo` the paths are relative to. */
|
|
34
|
+
scope: string;
|
|
35
|
+
/** The entries in the order they were selected; never empty. */
|
|
36
|
+
entries: FsClipboardEntry[];
|
|
31
37
|
mode: 'copy' | 'cut';
|
|
32
38
|
}
|
|
33
39
|
|
|
40
|
+
/** The label a Paste row shows for a multi-entry clipboard. */
|
|
41
|
+
export function clipboardLabel(clip: FsClipboard | null): string | null {
|
|
42
|
+
if (!clip) return null;
|
|
43
|
+
if (clip.entries.length === 1) return clip.entries[0]!.name;
|
|
44
|
+
return `${clip.entries.length} items`;
|
|
45
|
+
}
|
|
46
|
+
|
|
34
47
|
/** The scope key a panel's listing uses: `${rootPath}\0${repo}`. */
|
|
35
48
|
export function fsClipboardScope(rootPath: string | undefined, repo: string): string {
|
|
36
49
|
return `${rootPath ?? ''}\u0000${repo}`;
|
|
@@ -112,13 +125,21 @@ export function dropRefusal(
|
|
|
112
125
|
* route holds the resolved directory.
|
|
113
126
|
*/
|
|
114
127
|
export function pasteRefusal(clip: FsClipboard | null, scope: string, targetDir: string): string | null {
|
|
115
|
-
if (!clip) return 'Nothing to paste';
|
|
128
|
+
if (!clip || clip.entries.length === 0) return 'Nothing to paste';
|
|
116
129
|
if (clip.scope !== scope) return 'The clipboard holds an entry from another workspace';
|
|
117
130
|
// A cut has nothing to do in the folder it is already in — the entry would be
|
|
118
131
|
// renamed to a `copy` name, which is the opposite of what a cut means. The
|
|
119
|
-
// route refuses the same case in the same words.
|
|
120
|
-
|
|
121
|
-
|
|
132
|
+
// route refuses the same case in the same words. A multi-entry cut refuses
|
|
133
|
+
// whole if ANY entry already sits there: pasting the rest while silently
|
|
134
|
+
// dropping one is not the operation the user asked for.
|
|
135
|
+
if (clip.mode === 'cut' && clip.entries.some((entry) => targetDir === parentOf(entry.path))) {
|
|
136
|
+
return 'Already in this folder';
|
|
137
|
+
}
|
|
138
|
+
for (const entry of clip.entries) {
|
|
139
|
+
const refusal = transferRefusal(entry, targetDir);
|
|
140
|
+
if (refusal) return refusal;
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
122
143
|
}
|
|
123
144
|
|
|
124
145
|
/**
|
|
@@ -167,16 +188,40 @@ export function duplicateName(name: string, kind: 'file' | 'folder', taken: (can
|
|
|
167
188
|
* whose shape is not what Cut/Copy wrote is dropped rather than trusted. The
|
|
168
189
|
* path check is the one that matters: a `.`, a `..` segment or an absolute
|
|
169
190
|
* spelling would name a directory other than the one the entry claims.
|
|
191
|
+
*
|
|
192
|
+
* The single-entry shape from before multi-selection is migrated rather than
|
|
193
|
+
* dropped: a clipboard taken in an older tab must still paste after an update,
|
|
194
|
+
* and the two shapes differ only in nesting.
|
|
170
195
|
*/
|
|
171
196
|
export function readFsClipboard(value: unknown): FsClipboard | null {
|
|
172
197
|
if (typeof value !== 'object' || value === null) return null;
|
|
173
|
-
const clip = value as
|
|
174
|
-
if (typeof clip.scope !== 'string'
|
|
175
|
-
if (clip.kind !== 'file' && clip.kind !== 'folder') return null;
|
|
198
|
+
const clip = value as { scope?: unknown; mode?: unknown; entries?: unknown; path?: unknown; name?: unknown; kind?: unknown };
|
|
199
|
+
if (typeof clip.scope !== 'string') return null;
|
|
176
200
|
if (clip.mode !== 'copy' && clip.mode !== 'cut') return null;
|
|
177
|
-
const
|
|
178
|
-
|
|
201
|
+
const rawEntries = Array.isArray(clip.entries)
|
|
202
|
+
? clip.entries
|
|
203
|
+
: typeof clip.path === 'string'
|
|
204
|
+
? [{ path: clip.path, name: clip.name, kind: clip.kind }]
|
|
205
|
+
: [];
|
|
206
|
+
const entries: FsClipboardEntry[] = [];
|
|
207
|
+
for (const raw of rawEntries) {
|
|
208
|
+
const entry = readEntry(raw);
|
|
209
|
+
if (!entry) return null;
|
|
210
|
+
entries.push(entry);
|
|
211
|
+
}
|
|
212
|
+
if (entries.length === 0) return null;
|
|
213
|
+
return { scope: clip.scope, entries, mode: clip.mode };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** One clipboard entry, or null when its shape or path is not trustworthy. */
|
|
217
|
+
function readEntry(value: unknown): FsClipboardEntry | null {
|
|
218
|
+
if (typeof value !== 'object' || value === null) return null;
|
|
219
|
+
const entry = value as Partial<FsClipboardEntry>;
|
|
220
|
+
if (typeof entry.path !== 'string' || typeof entry.name !== 'string') return null;
|
|
221
|
+
if (entry.kind !== 'file' && entry.kind !== 'folder') return null;
|
|
222
|
+
const segments = entry.path.split('/');
|
|
223
|
+
if (entry.path === '' || entry.path.startsWith('/') || segments.some((segment) => segment === '' || segment === '.' || segment === '..')) {
|
|
179
224
|
return null;
|
|
180
225
|
}
|
|
181
|
-
return {
|
|
226
|
+
return { path: entry.path, name: entry.name, kind: entry.kind };
|
|
182
227
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Writing a table back as delimited text.
|
|
8
|
+
*
|
|
9
|
+
* The failure this prevents is the parser's, in the other direction: a cell
|
|
10
|
+
* holding a comma, a quote or a newline must not split the row it is written
|
|
11
|
+
* into. The two normalizations (minimal quoting, no trailing empty fields) are
|
|
12
|
+
* pinned because they are what a round trip through the grid actually does to
|
|
13
|
+
* a file.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
import { parseCsv, serializeCsv } from '@/shared/lib/fs/csv';
|
|
18
|
+
|
|
19
|
+
describe('serializeCsv', () => {
|
|
20
|
+
test('a plain table is written with the delimiter and LF', () => {
|
|
21
|
+
expect(serializeCsv(['Name', 'Qty'], [['Widget', '3']], ',')).toBe('Name,Qty\nWidget,3');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('a tab-delimited table keeps its delimiter', () => {
|
|
25
|
+
expect(serializeCsv(['a', 'b'], [['1', '2']], '\t')).toBe('a\tb\n1\t2');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('a field holding the delimiter, a quote or a newline is quoted', () => {
|
|
29
|
+
expect(serializeCsv(['a'], [['x,y'], ['say "hi"'], ['line\nbreak']], ',')).toBe(
|
|
30
|
+
'a\n"x,y"\n"say ""hi"""\n"line\nbreak"',
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('a trailing newline is preserved when the original had one', () => {
|
|
35
|
+
expect(serializeCsv(['a'], [['1']], ',', true)).toBe('a\n1\n');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// `parseCsv` pads every row to the header's width so the grid's columns line
|
|
39
|
+
// up; writing that padding back would add delimiters the file never had.
|
|
40
|
+
test('trailing empty fields are dropped, and a row keeps one field', () => {
|
|
41
|
+
expect(serializeCsv(['a', 'b', 'c'], [['1', '', '']], ',')).toBe('a,b,c\n1');
|
|
42
|
+
expect(serializeCsv(['a'], [['']], ',')).toBe('a\n');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('a round trip through the parser keeps the cells', () => {
|
|
46
|
+
const text = 'Name,Qty\n"Widget, large",3\nGadget,1\n';
|
|
47
|
+
const table = parseCsv(text, 'data.csv');
|
|
48
|
+
expect(serializeCsv(table.header, table.rows, table.delimiter, true)).toBe(text);
|
|
49
|
+
});
|
|
50
|
+
});
|
package/src/shared/lib/fs/csv.ts
CHANGED
|
@@ -157,3 +157,43 @@ function padRow(row: string[], width: number): string[] {
|
|
|
157
157
|
while (next.length < width) next.push('');
|
|
158
158
|
return next;
|
|
159
159
|
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Write a table back as delimited text.
|
|
163
|
+
*
|
|
164
|
+
* The inverse of `parseCsv`, and it exists because the grid is now editable:
|
|
165
|
+
* a cell edit has to become the file's text again, and a naive `join(',')`
|
|
166
|
+
* would corrupt the first cell that holds a comma, a quote or a newline — the
|
|
167
|
+
* same failure the parser exists to prevent, in the other direction.
|
|
168
|
+
*
|
|
169
|
+
* Two normalizations are deliberate and are the price of editing a file through
|
|
170
|
+
* a parsed model:
|
|
171
|
+
*
|
|
172
|
+
* - **Quoting is minimal.** A field is quoted only when it must be (it holds
|
|
173
|
+
* the delimiter, a quote, CR or LF), so a file that quoted every field comes
|
|
174
|
+
* back with the quotes it needs and no more.
|
|
175
|
+
* - **Trailing empty fields are dropped.** `parseCsv` pads every row to the
|
|
176
|
+
* header's width so the grid's columns line up; writing that padding back
|
|
177
|
+
* would add delimiters the file never had. A row keeps at least one field.
|
|
178
|
+
*
|
|
179
|
+
* The line ending is LF because the editor's buffer is LF-only; the save path
|
|
180
|
+
* restores the file's own ending from `eol`. `trailingNewline` is the caller's
|
|
181
|
+
* observation of the original text, so a file that ended with a newline still
|
|
182
|
+
* does.
|
|
183
|
+
*/
|
|
184
|
+
export function serializeCsv(
|
|
185
|
+
header: readonly string[],
|
|
186
|
+
rows: readonly (readonly string[])[],
|
|
187
|
+
delimiter: ',' | '\t',
|
|
188
|
+
trailingNewline = false,
|
|
189
|
+
): string {
|
|
190
|
+
const field = (value: string) =>
|
|
191
|
+
value.includes(delimiter) || /["\r\n]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value;
|
|
192
|
+
const line = (cells: readonly string[]) => {
|
|
193
|
+
let end = cells.length;
|
|
194
|
+
while (end > 1 && cells[end - 1] === '') end -= 1;
|
|
195
|
+
return cells.slice(0, end).map(field).join(delimiter);
|
|
196
|
+
};
|
|
197
|
+
const text = [header, ...rows].map(line).join('\n');
|
|
198
|
+
return trailingNewline ? `${text}\n` : text;
|
|
199
|
+
}
|
|
@@ -25,8 +25,11 @@ describe('viewerKindFor', () => {
|
|
|
25
25
|
expect(viewerKindFor('a.png')).toBe('image');
|
|
26
26
|
expect(viewerKindFor('a.pdf')).toBe('pdf');
|
|
27
27
|
expect(viewerKindFor('a.docx')).toBe('docx');
|
|
28
|
+
expect(viewerKindFor('a.xls')).toBe('spreadsheet');
|
|
28
29
|
expect(viewerKindFor('a.xlsx')).toBe('spreadsheet');
|
|
29
30
|
expect(viewerKindFor('a.xlsm')).toBe('spreadsheet');
|
|
31
|
+
expect(viewerKindFor('flow.drawio')).toBe('drawio');
|
|
32
|
+
expect(viewerKindFor('flow.dio')).toBe('drawio');
|
|
30
33
|
});
|
|
31
34
|
|
|
32
35
|
// SVG is a picture to the eye while its bytes are editable XML text, and
|
|
@@ -43,11 +46,11 @@ describe('viewerKindFor', () => {
|
|
|
43
46
|
expect(viewerKindFor(undefined)).toBe('code');
|
|
44
47
|
});
|
|
45
48
|
|
|
46
|
-
// `.xls` is the legacy OLE2
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
test('legacy .xls is
|
|
50
|
-
expect(viewerKindFor('legacy.xls')).toBe('
|
|
49
|
+
// `.xls` is the legacy OLE2/BIFF format, which SheetJS reads — the same
|
|
50
|
+
// viewer draws it. Before the reader change it landed on the code path and
|
|
51
|
+
// was refused as binary, which is what "the xls file will not open" was.
|
|
52
|
+
test('legacy .xls is claimed by the sheet viewer', () => {
|
|
53
|
+
expect(viewerKindFor('legacy.xls')).toBe('spreadsheet');
|
|
51
54
|
});
|
|
52
55
|
|
|
53
56
|
test('the uppercase extension is recognised', () => {
|
|
@@ -56,7 +59,7 @@ describe('viewerKindFor', () => {
|
|
|
56
59
|
});
|
|
57
60
|
|
|
58
61
|
test('every kind has a row in both lookup tables', () => {
|
|
59
|
-
const kinds: ViewerKind[] = ['code', 'markdown', 'svg', 'csv', 'image', 'pdf', 'docx', 'spreadsheet'];
|
|
62
|
+
const kinds: ViewerKind[] = ['code', 'markdown', 'svg', 'csv', 'image', 'pdf', 'docx', 'spreadsheet', 'drawio'];
|
|
60
63
|
for (const kind of kinds) {
|
|
61
64
|
expect(kind in BINARY_VIEWERS).toBe(true);
|
|
62
65
|
expect(kind in RENDERED_VIEWERS).toBe(true);
|
|
@@ -71,6 +74,10 @@ describe('viewerKindFor', () => {
|
|
|
71
74
|
expect(BINARY_VIEWERS.csv).toBeUndefined();
|
|
72
75
|
expect(RENDERED_VIEWERS.csv).toBe(true);
|
|
73
76
|
expect(RENDERED_VIEWERS.pdf).toBeUndefined();
|
|
77
|
+
// A drawio file is editable XML, so it has both a source and a rendered
|
|
78
|
+
// form — the eye toggle's pair — and no byte fetch.
|
|
79
|
+
expect(RENDERED_VIEWERS.drawio).toBe(true);
|
|
80
|
+
expect(BINARY_VIEWERS.drawio).toBeUndefined();
|
|
74
81
|
// A byte viewer's label is its document kind, never the language badge the
|
|
75
82
|
// empty buffer would otherwise produce.
|
|
76
83
|
expect(VIEWER_LABELS.pdf).toBe('PDF');
|
|
@@ -36,18 +36,18 @@ export type ViewerKind =
|
|
|
36
36
|
| 'image'
|
|
37
37
|
| 'pdf'
|
|
38
38
|
| 'docx'
|
|
39
|
-
| 'spreadsheet'
|
|
39
|
+
| 'spreadsheet'
|
|
40
|
+
| 'drawio';
|
|
40
41
|
|
|
41
42
|
/** Word-processing documents mammoth reads. */
|
|
42
43
|
const DOCX_EXTENSIONS: Record<string, true> = { docx: true };
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
|
-
* Workbooks
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* where the honest answer is "not text, cannot be shown here".
|
|
46
|
+
* Workbooks the sheet viewer reads. `.xls` is the legacy OLE2/BIFF format and
|
|
47
|
+
* `.xlsx`/`.xlsm` are the ZIP-based OOXML ones; SheetJS reads all three, which
|
|
48
|
+
* is why the viewer claims the legacy extension too.
|
|
49
49
|
*/
|
|
50
|
-
const SHEET_EXTENSIONS: Record<string, true> = { xlsx: true, xlsm: true };
|
|
50
|
+
const SHEET_EXTENSIONS: Record<string, true> = { xls: true, xlsx: true, xlsm: true };
|
|
51
51
|
|
|
52
52
|
/** Delimited text rendered as a grid. */
|
|
53
53
|
const CSV_EXTENSIONS: Record<string, true> = { csv: true, tsv: true };
|
|
@@ -55,6 +55,14 @@ const CSV_EXTENSIONS: Record<string, true> = { csv: true, tsv: true };
|
|
|
55
55
|
/** Markdown, whose preview is the rendered document. */
|
|
56
56
|
const MARKDOWN_EXTENSIONS: Record<string, true> = { md: true, markdown: true, mdx: true };
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* drawio diagrams. `.dio` is the same format under the older extension; the
|
|
60
|
+
* `.drawio.svg`/`.drawio.png` exports are NOT here — those are an SVG and a
|
|
61
|
+
* raster image with the model embedded, and the `svg`/`image` viewers already
|
|
62
|
+
* draw them.
|
|
63
|
+
*/
|
|
64
|
+
const DRAWIO_EXTENSIONS: Record<string, true> = { drawio: true, dio: true };
|
|
65
|
+
|
|
58
66
|
/**
|
|
59
67
|
* A viewer that draws BYTES rather than a text buffer.
|
|
60
68
|
*
|
|
@@ -72,6 +80,7 @@ export const BINARY_VIEWERS: Record<ViewerKind, true | undefined> = {
|
|
|
72
80
|
markdown: undefined,
|
|
73
81
|
svg: undefined,
|
|
74
82
|
csv: undefined,
|
|
83
|
+
drawio: undefined,
|
|
75
84
|
};
|
|
76
85
|
|
|
77
86
|
/**
|
|
@@ -86,6 +95,7 @@ export const RENDERED_VIEWERS: Record<ViewerKind, true | undefined> = {
|
|
|
86
95
|
markdown: true,
|
|
87
96
|
svg: true,
|
|
88
97
|
csv: true,
|
|
98
|
+
drawio: true,
|
|
89
99
|
code: undefined,
|
|
90
100
|
image: undefined,
|
|
91
101
|
pdf: undefined,
|
|
@@ -111,6 +121,7 @@ export const VIEWER_LABELS: Record<ViewerKind, string> = {
|
|
|
111
121
|
pdf: 'PDF',
|
|
112
122
|
docx: 'Document',
|
|
113
123
|
spreadsheet: 'Spreadsheet',
|
|
124
|
+
drawio: 'Diagram',
|
|
114
125
|
};
|
|
115
126
|
|
|
116
127
|
/**
|
|
@@ -126,6 +137,7 @@ export function viewerKindFor(filePath: string | undefined | null): ViewerKind {
|
|
|
126
137
|
const ext = getFileExtension(filePath);
|
|
127
138
|
if (!ext) return 'code';
|
|
128
139
|
if (ext === 'svg') return 'svg';
|
|
140
|
+
if (DRAWIO_EXTENSIONS[ext]) return 'drawio';
|
|
129
141
|
if (MARKDOWN_EXTENSIONS[ext]) return 'markdown';
|
|
130
142
|
if (getImageMimeType(filePath)) return 'image';
|
|
131
143
|
if (ext === 'pdf') return 'pdf';
|
|
@@ -63,6 +63,9 @@ describe('classifyEditorFile', () => {
|
|
|
63
63
|
expect(classifyEditorFile({ path: 'doc.docx', size: 4096, head: bytes(0x50, 0x4b, 0x03, 0x04, 0x00) })).toBe('document');
|
|
64
64
|
expect(classifyEditorFile({ path: 'sheet.xlsx', size: 4096, head: bytes(0x50, 0x4b, 0x03, 0x04, 0x00) })).toBe('document');
|
|
65
65
|
expect(classifyEditorFile({ path: 'sheet.xlsm', size: 4096 })).toBe('document');
|
|
66
|
+
// The legacy OLE2 workbook is a container too: its header carries NULs, so
|
|
67
|
+
// the sniff would refuse the file the sheet viewer exists for.
|
|
68
|
+
expect(classifyEditorFile({ path: 'legacy.xls', size: 4096, head: bytes(0xd0, 0xcf, 0x11, 0xe0, 0x00) })).toBe('document');
|
|
66
69
|
});
|
|
67
70
|
|
|
68
71
|
// A PDF is the exception: its viewer is an `<iframe>` on `/api/fs/raw`, so the
|
|
@@ -87,6 +90,7 @@ describe('classifyEditorFile', () => {
|
|
|
87
90
|
expect(classifyEditorFile({ path: 'big.docx', size: 6 * 1024 * 1024 })).toBe('document');
|
|
88
91
|
expect(classifyEditorFile({ path: 'big.xlsx', size: 19 * 1024 * 1024 })).toBe('document');
|
|
89
92
|
expect(classifyEditorFile({ path: 'big.xlsm', size: DOCUMENT_MAX_FILE_BYTES })).toBe('document');
|
|
93
|
+
expect(classifyEditorFile({ path: 'big.xls', size: DOCUMENT_MAX_FILE_BYTES })).toBe('document');
|
|
90
94
|
});
|
|
91
95
|
|
|
92
96
|
test('a DOCX and an XLSX past the document ceiling are refused for size', () => {
|
|
@@ -140,16 +140,11 @@ describe('getDocumentMimeType', () => {
|
|
|
140
140
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
141
141
|
);
|
|
142
142
|
expect(getDocumentMimeType('a.xlsm')).toBe('application/vnd.ms-excel.sheet.macroEnabled.12');
|
|
143
|
+
expect(getDocumentMimeType('a.xls')).toBe('application/vnd.ms-excel');
|
|
143
144
|
});
|
|
144
145
|
|
|
145
146
|
test('the table covers exactly the extensions above', () => {
|
|
146
|
-
expect(Object.keys(DOCUMENT_MIME_BY_EXT).sort()).toEqual(['docx', 'pdf', 'xlsm', 'xlsx']);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// `.xls` is the legacy OLE2 binary the reader refuses; naming it as a
|
|
150
|
-
// spreadsheet type would advertise a viewer that cannot open it.
|
|
151
|
-
test('legacy .xls has no MIME entry', () => {
|
|
152
|
-
expect(getDocumentMimeType('legacy.xls')).toBeNull();
|
|
147
|
+
expect(Object.keys(DOCUMENT_MIME_BY_EXT).sort()).toEqual(['docx', 'pdf', 'xls', 'xlsm', 'xlsx']);
|
|
153
148
|
});
|
|
154
149
|
|
|
155
150
|
test('images and unknown extensions are null', () => {
|
|
@@ -56,6 +56,7 @@ export function getFileExtension(filePath: string | undefined | null): string {
|
|
|
56
56
|
export const DOCUMENT_MIME_BY_EXT: Record<string, string> = {
|
|
57
57
|
pdf: 'application/pdf',
|
|
58
58
|
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
59
|
+
xls: 'application/vnd.ms-excel',
|
|
59
60
|
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
60
61
|
xlsm: 'application/vnd.ms-excel.sheet.macroEnabled.12',
|
|
61
62
|
};
|
|
@@ -184,7 +185,7 @@ export const EDITOR_MAX_FILE_BYTES = 32 * 1024 * 1024;
|
|
|
184
185
|
/**
|
|
185
186
|
* The largest Word document or workbook the editor opens.
|
|
186
187
|
*
|
|
187
|
-
* `mammoth` and
|
|
188
|
+
* `mammoth` and SheetJS parse the fetched `ArrayBuffer` in the page,
|
|
188
189
|
* so the file does sit in memory — but it is unzipped and converted once and
|
|
189
190
|
* then released, where a text buffer is held for as long as the tab is open and
|
|
190
191
|
* re-posted on every save. That is why these get a ceiling of their own rather
|
|
@@ -234,6 +235,7 @@ export const PDF_MAX_FILE_BYTES = 30 * 1024 * 1024;
|
|
|
234
235
|
export const EDITOR_MAX_BYTES_BY_EXT: Record<string, number> = {
|
|
235
236
|
pdf: PDF_MAX_FILE_BYTES,
|
|
236
237
|
docx: DOCUMENT_MAX_FILE_BYTES,
|
|
238
|
+
xls: DOCUMENT_MAX_FILE_BYTES,
|
|
237
239
|
xlsx: DOCUMENT_MAX_FILE_BYTES,
|
|
238
240
|
xlsm: DOCUMENT_MAX_FILE_BYTES,
|
|
239
241
|
};
|
|
@@ -262,7 +264,7 @@ export type EditorFileKind = 'image' | 'document' | 'text' | 'binary' | 'too-lar
|
|
|
262
264
|
* viewer is an `<iframe>` on `/api/fs/raw`, so the bytes are streamed to
|
|
263
265
|
* Chrome's own plugin and never held in the page.
|
|
264
266
|
*
|
|
265
|
-
* A DOCX and
|
|
267
|
+
* A DOCX and a workbook are the middle case: `mammoth` and SheetJS parse
|
|
266
268
|
* the fetched `ArrayBuffer` in the page, so the file IS held — but only for the
|
|
267
269
|
* conversion, not for the life of the tab, which is what buys them
|
|
268
270
|
* `DOCUMENT_MAX_FILE_BYTES` (20 MiB) instead of the text ceiling.
|