@kabmo-labs/kabmo 0.9.0 → 0.10.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.
Files changed (180) hide show
  1. package/README.md +45 -0
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +333 -333
  4. package/dist/client/static/js/index-18xe7655.css +1 -0
  5. package/dist/client/static/js/{index-bpptfkz2.js → index-nxpe7835.js} +768 -763
  6. package/package.json +3 -1
  7. package/src/client/components/common/code-surface/bracket-guide.test.ts +249 -0
  8. package/src/client/components/common/code-surface/bracket-guide.ts +131 -0
  9. package/src/client/components/common/code-surface/documents.test.ts +5 -3
  10. package/src/client/components/common/code-surface/documents.ts +85 -0
  11. package/src/client/components/common/code-surface/extensions.test.ts +5 -0
  12. package/src/client/components/common/code-surface/extensions.ts +140 -7
  13. package/src/client/components/common/code-surface/fold-stack.test.ts +218 -0
  14. package/src/client/components/common/code-surface/fold.test.ts +148 -0
  15. package/src/client/components/common/code-surface/fold.ts +118 -0
  16. package/src/client/components/common/code-surface/indent-guide.ts +104 -0
  17. package/src/client/components/common/code-surface/indent.test.ts +239 -0
  18. package/src/client/components/common/code-surface/indent.ts +124 -0
  19. package/src/client/components/common/code-surface/index.tsx +76 -46
  20. package/src/client/components/common/code-surface/keymap.ts +12 -23
  21. package/src/client/components/common/code-surface/line-commands.test.ts +90 -0
  22. package/src/client/components/common/code-surface/line-commands.ts +103 -0
  23. package/src/client/components/common/code-surface/props.ts +87 -0
  24. package/src/client/components/common/code-surface/stream-language.test.ts +118 -0
  25. package/src/client/components/common/code-surface/stream-language.ts +123 -0
  26. package/src/client/components/common/code-surface/theme.test.ts +40 -5
  27. package/src/client/components/common/code-surface/theme.ts +113 -0
  28. package/src/client/components/common/code-surface/typing.test.ts +97 -0
  29. package/src/client/components/common/code-surface/typing.ts +111 -0
  30. package/src/client/components/common/toolbar-row/index.test.tsx +53 -4
  31. package/src/client/components/common/toolbar-row/index.tsx +101 -30
  32. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +17 -0
  33. package/src/client/components/layout/desktop-layout/index.tsx +18 -0
  34. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +35 -33
  35. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +20 -1
  36. package/src/client/components/mobile/mobile-right-sidebar/editor-props.ts +25 -0
  37. package/src/client/components/settings/categories/AppearanceSettings.tsx +6 -0
  38. package/src/client/components/settings/categories/appearance-settings/EditorIndentSection.tsx +87 -0
  39. package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +99 -0
  40. package/src/client/components/workspace/chat-timeline/chat-input/expansion.ts +9 -4
  41. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +15 -11
  42. package/src/client/components/workspace/chat-timeline/chat-input/stretch-send.test.tsx +165 -0
  43. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.test.ts +17 -3
  44. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.tsx +10 -6
  45. package/src/client/components/workspace/editor/Body.tsx +24 -0
  46. package/src/client/components/workspace/editor/CommandPalette.tsx +4 -4
  47. package/src/client/components/workspace/editor/ConflictStrip.tsx +77 -0
  48. package/src/client/components/workspace/editor/Dialogs.tsx +53 -0
  49. package/src/client/components/workspace/editor/EmptyEditor.tsx +23 -0
  50. package/src/client/components/workspace/editor/ExternalChangeStrip.tsx +61 -0
  51. package/src/client/components/workspace/editor/FileDocument.tsx +89 -1
  52. package/src/client/components/workspace/editor/FilePane.tsx +43 -0
  53. package/src/client/components/workspace/editor/FindWidget.test.ts +9 -5
  54. package/src/client/components/workspace/editor/FindWidget.tsx +29 -0
  55. package/src/client/components/workspace/editor/GoToLineModal.tsx +123 -0
  56. package/src/client/components/workspace/editor/Notices.tsx +71 -0
  57. package/src/client/components/workspace/editor/Pane.tsx +118 -0
  58. package/src/client/components/workspace/editor/PluginColumn.tsx +32 -0
  59. package/src/client/components/workspace/editor/QuickOpenModal.tsx +146 -0
  60. package/src/client/components/workspace/editor/SaveAsModal.tsx +175 -0
  61. package/src/client/components/workspace/editor/SplitColumn.tsx +98 -0
  62. package/src/client/components/workspace/editor/SplitPane.tsx +57 -0
  63. package/src/client/components/workspace/editor/StatusBar.tsx +106 -0
  64. package/src/client/components/workspace/editor/TabContextMenu.tsx +75 -0
  65. package/src/client/components/workspace/editor/Tabs.tsx +195 -18
  66. package/src/client/components/workspace/editor/Toolbar.tsx +54 -181
  67. package/src/client/components/workspace/editor/index.tsx +199 -189
  68. package/src/client/components/workspace/editor/props.ts +64 -0
  69. package/src/client/components/workspace/editor/toolbar-clusters.tsx +300 -0
  70. package/src/client/components/workspace/file-explorer/Modals.tsx +14 -1
  71. package/src/client/components/workspace/file-explorer/TreeItem.tsx +2 -1
  72. package/src/client/components/workspace/file-explorer/clipboard.test.ts +3 -1
  73. package/src/client/components/workspace/file-explorer/index.test.ts +61 -0
  74. package/src/client/components/workspace/file-explorer/index.tsx +10 -48
  75. package/src/client/components/workspace/file-explorer/local-edit.test.ts +8 -3
  76. package/src/client/components/workspace/search-panel/Body.tsx +6 -1
  77. package/src/client/hooks/chat/composer/file-drop.ts +22 -37
  78. package/src/client/hooks/chat/composer/pipeline.test.ts +76 -0
  79. package/src/client/hooks/chat/composer/pipeline.ts +12 -1
  80. package/src/client/hooks/editor/caret-position.test.ts +58 -0
  81. package/src/client/hooks/editor/caret-position.ts +48 -0
  82. package/src/client/hooks/editor/file-editor-types.ts +200 -0
  83. package/src/client/hooks/editor/find-history.test.ts +132 -0
  84. package/src/client/hooks/editor/find-history.ts +46 -0
  85. package/src/client/hooks/editor/find-selection-range.test.ts +100 -0
  86. package/src/client/hooks/editor/find-selection-range.ts +49 -0
  87. package/src/client/hooks/editor/find-state.ts +13 -0
  88. package/src/client/hooks/editor/font.test.ts +0 -93
  89. package/src/client/hooks/editor/indent-settings.test.ts +104 -0
  90. package/src/client/hooks/editor/indent-settings.ts +88 -0
  91. package/src/client/hooks/editor/quick-open.test.ts +141 -0
  92. package/src/client/hooks/editor/quick-open.ts +127 -0
  93. package/src/client/hooks/editor/save-as.test.ts +156 -0
  94. package/src/client/hooks/editor/save-as.ts +122 -0
  95. package/src/client/hooks/editor/save-file.test.ts +179 -0
  96. package/src/client/hooks/editor/save-file.ts +73 -28
  97. package/src/client/hooks/editor/typing-settings.test.ts +73 -0
  98. package/src/client/hooks/editor/typing-settings.ts +65 -0
  99. package/src/client/hooks/editor/use-close-guard.ts +98 -0
  100. package/src/client/hooks/editor/use-editor-drop-overlay.test.ts +159 -0
  101. package/src/client/hooks/editor/use-editor-drop.shell.test.ts +224 -0
  102. package/src/client/hooks/editor/use-editor-drop.ts +58 -68
  103. package/src/client/hooks/editor/use-editor-find.test.ts +2 -2
  104. package/src/client/hooks/editor/use-editor-find.ts +38 -3
  105. package/src/client/hooks/editor/use-editor-panel-keys.ts +152 -0
  106. package/src/client/hooks/editor/use-editor-tab-state.ts +71 -0
  107. package/src/client/hooks/editor/use-external-change-notice.ts +71 -0
  108. package/src/client/hooks/editor/use-external-change.test.ts +88 -0
  109. package/src/client/hooks/editor/use-external-change.ts +146 -0
  110. package/src/client/hooks/editor/use-file-editor.ts +83 -116
  111. package/src/client/hooks/editor/use-file-read.ts +16 -8
  112. package/src/client/hooks/editor/use-file-writes.ts +28 -3
  113. package/src/client/hooks/editor/use-mobile-editor-find.ts +69 -0
  114. package/src/client/hooks/editor/use-mobile-reveal.ts +53 -0
  115. package/src/client/hooks/editor/use-search-reveal-jump.ts +57 -0
  116. package/src/client/hooks/editor/use-split-editor.test.tsx +169 -0
  117. package/src/client/hooks/editor/use-split-editor.ts +91 -0
  118. package/src/client/hooks/editor/use-unload-guard.tsx +117 -0
  119. package/src/client/hooks/editor/use-write-conflict.test.ts +164 -0
  120. package/src/client/hooks/editor/use-write-conflict.ts +152 -0
  121. package/src/client/hooks/editor/wheel-zoom.test.ts +141 -0
  122. package/src/client/hooks/editor/wheel-zoom.ts +96 -0
  123. package/src/client/hooks/ui/drag-presence.test.ts +193 -0
  124. package/src/client/hooks/ui/drag-presence.ts +108 -0
  125. package/src/client/hooks/ui/settings-modal.test.ts +115 -0
  126. package/src/client/hooks/workspace/file-listing.ts +36 -24
  127. package/src/client/hooks/workspace/file-tabs.test.ts +90 -0
  128. package/src/client/hooks/workspace/file-tabs.ts +46 -0
  129. package/src/client/hooks/workspace/file-tree-edits.ts +103 -0
  130. package/src/client/lib/desktop/dropped-paths.ts +83 -0
  131. package/src/client/lib/editor/tab-menu.test.ts +127 -0
  132. package/src/client/lib/editor/tab-menu.ts +127 -0
  133. package/src/client/lib/editor-dirty-tabs.test.ts +102 -0
  134. package/src/client/lib/editor-dirty-tabs.ts +103 -0
  135. package/src/client/lib/native/resume.test.ts +66 -0
  136. package/src/client/lib/native/resume.ts +42 -0
  137. package/src/client/main.tsx +8 -0
  138. package/src/client/tailwind.css +38 -0
  139. package/src/server/lib/bundler/css.test.ts +31 -0
  140. package/src/server/lib/fs/listing.test.ts +81 -16
  141. package/src/server/lib/fs/listing.ts +72 -5
  142. package/src/server/lib/fs/write-conflict.test.ts +68 -0
  143. package/src/server/lib/fs/write-conflict.ts +84 -0
  144. package/src/server/routes/fs/action-save-as.test.ts +82 -0
  145. package/src/server/routes/fs/action.test.ts +82 -0
  146. package/src/server/routes/fs/action.ts +54 -1
  147. package/src/server/routes/fs/exists.ts +11 -1
  148. package/src/server/routes/fs/read.ts +6 -1
  149. package/src/shared/lib/code/editor/find-replace.test.ts +1 -1
  150. package/src/shared/lib/code/editor/find-scan.test.ts +1 -1
  151. package/src/shared/lib/code/editor/find-scan.ts +22 -1
  152. package/src/shared/lib/code/editor/find-selection.test.ts +56 -0
  153. package/src/shared/lib/code/editor/indent-guide-rule.test.ts +65 -0
  154. package/src/shared/lib/code/editor/indent-guide-rule.ts +47 -0
  155. package/src/shared/lib/code/editor/indent-rules.test.ts +219 -0
  156. package/src/shared/lib/code/editor/indent-rules.ts +198 -0
  157. package/src/shared/lib/code/editor/keymap.test.ts +23 -0
  158. package/src/shared/lib/code/editor/keymap.ts +40 -3
  159. package/src/shared/lib/code/editor/palette.test.ts +25 -2
  160. package/src/shared/lib/code/editor/palette.ts +10 -0
  161. package/src/shared/lib/code/editor/stream-modes.ts +225 -0
  162. package/src/shared/lib/code/syntax-highlight.test.ts +1 -1
  163. package/src/shared/lib/fs/file-tree.test.ts +41 -0
  164. package/src/shared/lib/fs/file-tree.ts +126 -34
  165. package/src/shared/lib/fs/folder-chain.test.ts +87 -0
  166. package/src/shared/lib/fs/folder-chain.ts +91 -0
  167. package/src/shared/lib/fs/fs-helpers.test.ts +4 -50
  168. package/src/shared/lib/realtime/connection.test.ts +5 -1
  169. package/src/shared/lib/realtime/connection.ts +25 -119
  170. package/src/shared/lib/realtime/frozen-recovery.test.ts +93 -0
  171. package/src/shared/lib/realtime/resume.ts +223 -0
  172. package/src/shared/lib/realtime/state.ts +22 -0
  173. package/src/shared/lib/realtime/watchdog-wiring.test.ts +224 -0
  174. package/src/shared/lib/realtime/watchdog.test.ts +99 -0
  175. package/src/shared/lib/realtime/watchdog.ts +72 -0
  176. package/src/shared/lib/workspace/split-editor.test.ts +104 -0
  177. package/src/shared/lib/workspace/split-editor.ts +129 -0
  178. package/src/test-support/file-explorer-disk.test-util.ts +30 -3
  179. package/src/test-support/pristine-globals.ts +7 -0
  180. package/dist/client/static/js/index-k315p1e8.css +0 -1
@@ -0,0 +1,146 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Quick open (⌘P): a file picker over `/api/fs/list`.
8
+ *
9
+ * The index is fetched once per scope and cached for the session: the route walks
10
+ * the tree, so re-reading it on every keystroke would be a walk per character. A
11
+ * `workspace-dirty` signal invalidates it, because a file created by the agent (or
12
+ * by the New File dialog) is exactly the file a picker should be able to find.
13
+ *
14
+ * ## The dialog is the same shell as Go-to-line, deliberately
15
+ *
16
+ * Two one-field modals that look different read as two different features; the
17
+ * keyboard contract (type, arrows, Enter, Escape) is the only thing the user has to
18
+ * learn, so both use it.
19
+ */
20
+
21
+ import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
22
+ import type { TargetedKeyboardEvent } from 'preact';
23
+ import { FileIcon } from '@/client/components/common/file-icon';
24
+ import { Modal } from '@/client/components/common/Modal';
25
+ import { fetchQuickOpenIndex, rankQuickOpen, type QuickOpenEntry } from '@/client/hooks/editor/quick-open';
26
+
27
+ interface QuickOpenModalProps {
28
+ root?: string | null;
29
+ repo?: string | null;
30
+ onOpen: (path: string) => void;
31
+ onClose: () => void;
32
+ }
33
+
34
+ /** Index cache, keyed by scope. `bun --hot` keeps it, which is the point. */
35
+ const indexCache = new Map<string, QuickOpenEntry[]>();
36
+
37
+ /** Drop the cached index — a `workspace-dirty` signal means a file may be new. */
38
+ export function invalidateQuickOpenIndex(): void {
39
+ indexCache.clear();
40
+ }
41
+
42
+ export function QuickOpenModal({ root, repo, onOpen, onClose }: QuickOpenModalProps) {
43
+ const scope = `${root ?? ''}\u0000${repo ?? '.'}`;
44
+ const [query, setQuery] = useState('');
45
+ const [index, setIndex] = useState<QuickOpenEntry[]>(() => indexCache.get(scope) ?? []);
46
+ const [activeIndex, setActiveIndex] = useState(0);
47
+ const inputRef = useRef<HTMLInputElement | null>(null);
48
+
49
+ useEffect(() => {
50
+ inputRef.current?.focus();
51
+ }, []);
52
+
53
+ // One fetch per scope, cached for the session. The dialog stays usable while it
54
+ // lands: a query against an empty index shows "no files" for a beat, which is the
55
+ // honest state rather than a spinner over a list that is about to appear.
56
+ useEffect(() => {
57
+ if (indexCache.has(scope)) return;
58
+ let cancelled = false;
59
+ void fetchQuickOpenIndex(root, repo).then((entries) => {
60
+ if (cancelled) return;
61
+ indexCache.set(scope, entries);
62
+ setIndex(entries);
63
+ });
64
+ return () => {
65
+ cancelled = true;
66
+ };
67
+ }, [scope, root, repo]);
68
+
69
+ const matches = useMemo(() => rankQuickOpen(index, query), [index, query]);
70
+
71
+ useEffect(() => {
72
+ setActiveIndex((previous) => Math.min(previous, Math.max(matches.length - 1, 0)));
73
+ }, [matches.length]);
74
+
75
+ const commit = (entry: QuickOpenEntry | undefined) => {
76
+ if (!entry) return;
77
+ onOpen(entry.path);
78
+ };
79
+
80
+ const onKeyDown = (event: TargetedKeyboardEvent<HTMLInputElement>) => {
81
+ if (event.key === 'Escape') {
82
+ event.preventDefault();
83
+ onClose();
84
+ return;
85
+ }
86
+ if (event.key === 'Enter') {
87
+ event.preventDefault();
88
+ commit(matches[activeIndex]);
89
+ return;
90
+ }
91
+ if (event.key === 'ArrowDown') {
92
+ event.preventDefault();
93
+ setActiveIndex((previous) => (matches.length === 0 ? 0 : (previous + 1) % matches.length));
94
+ return;
95
+ }
96
+ if (event.key === 'ArrowUp') {
97
+ event.preventDefault();
98
+ setActiveIndex((previous) => (matches.length === 0 ? 0 : (previous - 1 + matches.length) % matches.length));
99
+ }
100
+ };
101
+
102
+ return (
103
+ <Modal
104
+ onClose={onClose}
105
+ maxWidthClass="max-w-lg"
106
+ header={<span className="text-sm font-semibold text-ink">Open file</span>}
107
+ >
108
+ <div className="px-4 py-3 space-y-2">
109
+ <input
110
+ ref={inputRef}
111
+ value={query}
112
+ onInput={(event) => setQuery((event.target as HTMLInputElement).value)}
113
+ onKeyDown={onKeyDown}
114
+ placeholder="Search by file name"
115
+ aria-label="File name"
116
+ className="w-full bg-paper border border-ink/20 rounded px-2 py-1.5 text-xs font-mono text-ink outline-none focus:border-ink/40"
117
+ />
118
+ <div className="max-h-[45vh] overflow-y-auto scrollbar-overlay-container rounded border border-ink/10 divide-y divide-ink/5">
119
+ {matches.length === 0 ? (
120
+ <div className="px-3 py-2 text-[11px] text-ink/40 font-mono">
121
+ {index.length === 0 ? 'Reading the file index…' : 'No file matches'}
122
+ </div>
123
+ ) : (
124
+ matches.map((entry, position) => (
125
+ <button
126
+ key={entry.path}
127
+ type="button"
128
+ onClick={() => commit(entry)}
129
+ onMouseEnter={() => setActiveIndex(position)}
130
+ className={`w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors cursor-pointer ${
131
+ position === activeIndex ? 'bg-ink/10' : 'hover:bg-ink/5'
132
+ }`}
133
+ >
134
+ <FileIcon name={entry.name} size={13} className="flex-shrink-0 opacity-70" />
135
+ <span className="text-xs font-mono text-ink truncate">{entry.name}</span>
136
+ {entry.directory ? (
137
+ <span className="text-[10px] font-mono text-ink/40 truncate ml-auto">{entry.directory}</span>
138
+ ) : null}
139
+ </button>
140
+ ))
141
+ )}
142
+ </div>
143
+ </div>
144
+ </Modal>
145
+ );
146
+ }
@@ -0,0 +1,175 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The Save As dialog.
8
+ *
9
+ * Two fields, because a destination is two facts: which DIRECTORY, and what NAME. The
10
+ * directory is workspace-relative — the editor only ever deals in paths relative to the
11
+ * scope it was opened in, and an absolute path would be a value the server has to refuse
12
+ * (`resolveWithinRoot` is the boundary). The name starts as `<file> copy.<ext>` rather than
13
+ * `copy` alone: a destination that lost its extension would be saved as a file the surface
14
+ * no longer recognises, so the language would change under the user.
15
+ *
16
+ * ## A refusal keeps the dialog open, with the name still in it
17
+ *
18
+ * An existing destination is the common refusal and it is not a failure — the user picked a
19
+ * name that is taken. Closing the dialog on a `409` would read as success and leave them
20
+ * wondering where the file went, so the refusal is shown inline and the field stays.
21
+ *
22
+ * ## What Save As does NOT do
23
+ *
24
+ * The original file is untouched and the ORIGINAL tab stays open. The new file gets its own
25
+ * tab, which is what makes the operation reversible by closing one tab — and what makes it
26
+ * different from a rename (which is the Files panel's job).
27
+ */
28
+
29
+ import { useEffect, useRef, useState } from 'preact/hooks';
30
+ import type { TargetedKeyboardEvent } from 'preact';
31
+ import { CornerDownLeft, Loader2 } from 'lucide-preact';
32
+
33
+ import { Modal } from '@/client/components/common/Modal';
34
+ import {
35
+ isSingleSegmentName,
36
+ saveAsSuggestedName,
37
+ saveFileAs,
38
+ type SaveAsOutcome,
39
+ } from '@/client/hooks/editor/save-as';
40
+
41
+ interface SaveAsModalProps {
42
+ /** The open file: its name seeds the field, its path seeds the directory. */
43
+ fileName: string;
44
+ /** Workspace-relative path of the source, so the directory starts where it lives. */
45
+ filePath: string;
46
+ /** The buffer, LF-only. */
47
+ content: string;
48
+ eol: 'lf' | 'crlf';
49
+ root?: string;
50
+ repo?: string;
51
+ onSaved: (outcome: { path: string }) => void;
52
+ onClose: () => void;
53
+ }
54
+
55
+ /** The directory part of a workspace-relative path, or `''` at the root. */
56
+ export function directoryOf(path: string): string {
57
+ const cut = path.lastIndexOf('/');
58
+ return cut === -1 ? '' : path.slice(0, cut);
59
+ }
60
+
61
+ export function SaveAsModal({
62
+ fileName,
63
+ filePath,
64
+ content,
65
+ eol,
66
+ root,
67
+ repo,
68
+ onSaved,
69
+ onClose,
70
+ }: SaveAsModalProps) {
71
+ const [directory, setDirectory] = useState(() => directoryOf(filePath));
72
+ const [name, setName] = useState(() => saveAsSuggestedName(fileName));
73
+ const [busy, setBusy] = useState(false);
74
+ const [refusal, setRefusal] = useState<string | null>(null);
75
+ const nameRef = useRef<HTMLInputElement | null>(null);
76
+
77
+ useEffect(() => {
78
+ nameRef.current?.focus();
79
+ // Select the stem so typing replaces it — the suggested name is a starting point,
80
+ // and a user who types immediately means to replace it, not append to it.
81
+ nameRef.current?.select();
82
+ }, []);
83
+
84
+ const valid = isSingleSegmentName(name);
85
+
86
+ const submit = async () => {
87
+ if (!valid || busy) return;
88
+ setBusy(true);
89
+ setRefusal(null);
90
+ const outcome: SaveAsOutcome = await saveFileAs({ parent: directory, name, content, eol, root, repo });
91
+ setBusy(false);
92
+ if (outcome.status === 'written') {
93
+ onSaved({ path: outcome.path });
94
+ return;
95
+ }
96
+ // Both refusals keep the dialog open with the field intact: the user picked a name
97
+ // that cannot be used, and closing would read as success.
98
+ setRefusal(outcome.reason);
99
+ };
100
+
101
+ const onKeyDown = (event: TargetedKeyboardEvent<HTMLInputElement>) => {
102
+ if (event.key === 'Enter') {
103
+ event.preventDefault();
104
+ void submit();
105
+ return;
106
+ }
107
+ if (event.key === 'Escape') {
108
+ event.preventDefault();
109
+ onClose();
110
+ }
111
+ };
112
+
113
+ return (
114
+ <Modal
115
+ onClose={onClose}
116
+ maxWidthClass="max-w-md"
117
+ header={<span className="text-sm font-semibold text-ink">Save as</span>}
118
+ footer={
119
+ <div className="flex items-center justify-end gap-2 px-4 py-3 border-t border-ink/10">
120
+ <button
121
+ type="button"
122
+ onClick={onClose}
123
+ className="px-3 py-1.5 rounded border border-ink/20 text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer"
124
+ >
125
+ Cancel
126
+ </button>
127
+ <button
128
+ type="button"
129
+ onClick={() => void submit()}
130
+ disabled={!valid || busy}
131
+ className="flex items-center gap-1.5 px-3 py-1.5 rounded bg-ink text-paper disabled:opacity-40 disabled:cursor-default cursor-pointer"
132
+ >
133
+ {busy ? <Loader2 size={12} className="animate-spin" /> : <CornerDownLeft size={12} />}
134
+ Save
135
+ </button>
136
+ </div>
137
+ }
138
+ >
139
+ <div className="px-4 py-3 space-y-2 text-xs">
140
+ <label className="block">
141
+ <span className="block text-[10px] uppercase tracking-wide text-ink/50 mb-1">Folder</span>
142
+ <input
143
+ value={directory}
144
+ onInput={(event) => setDirectory((event.target as HTMLInputElement).value)}
145
+ onKeyDown={onKeyDown}
146
+ placeholder="(workspace root)"
147
+ aria-label="Destination folder"
148
+ className="w-full bg-paper border border-ink/20 rounded px-2 py-1 font-mono text-ink outline-none focus:border-ink/40"
149
+ />
150
+ </label>
151
+ <label className="block">
152
+ <span className="block text-[10px] uppercase tracking-wide text-ink/50 mb-1">Name</span>
153
+ <input
154
+ ref={nameRef}
155
+ value={name}
156
+ onInput={(event) => setName((event.target as HTMLInputElement).value)}
157
+ onKeyDown={onKeyDown}
158
+ aria-label="File name"
159
+ aria-invalid={!valid}
160
+ className={`w-full bg-paper border rounded px-2 py-1 font-mono text-ink outline-none ${
161
+ valid ? 'border-ink/20 focus:border-ink/40' : 'border-error text-error'
162
+ }`}
163
+ />
164
+ </label>
165
+ {!valid ? (
166
+ <div className="text-[10px] text-error font-mono">Enter a file name without a path separator</div>
167
+ ) : null}
168
+ {refusal ? <div className="text-[10px] text-error font-mono">{refusal}</div> : null}
169
+ <div className="text-[10px] text-ink/40">
170
+ The original file stays where it is, and its tab stays open.
171
+ </div>
172
+ </div>
173
+ </Modal>
174
+ );
175
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Two panes and the divider between them.
8
+ *
9
+ * The split divides the width the editor panel ALREADY has — its fraction, its floor and
10
+ * its diff variant are untouched — so nothing about the group's coupled-pair width model
11
+ * changes. Splitting a column is a different decision from how wide the column is, and
12
+ * keeping them apart is what made this feature cheap.
13
+ *
14
+ * ## The divider uses pointer capture
15
+ *
16
+ * A 3px handle is easy to leave mid-drag, and a listener on the handle alone would stop
17
+ * receiving `pointermove` the moment the pointer crossed into a pane. Capture keeps the
18
+ * events coming for the whole gesture, so a fast drag resizes instead of stalling.
19
+ *
20
+ * ## The position is a FRACTION
21
+ *
22
+ * A pixel width is only right on the display it was dragged on. The parent persists the
23
+ * fraction and clamps it (`clampSplitFraction`), so neither pane can be squeezed out of
24
+ * existence by a drag or by a hand-edited blob.
25
+ */
26
+
27
+ import { useRef } from 'preact/hooks';
28
+ import type { ComponentChildren } from 'preact';
29
+
30
+ import { SplitPane } from '@/client/components/workspace/editor/SplitPane';
31
+ import { clampSplitFraction } from '@/shared/lib/workspace/split-editor';
32
+
33
+ interface SplitColumnProps {
34
+ /** The divider's position, 0–1. */
35
+ fraction: number;
36
+ onFraction: (fraction: number) => void;
37
+ rightPaneName: string;
38
+ onClosePane: () => void;
39
+ rightPane: ComponentChildren;
40
+ /** The left pane — the panel body, strip included. */
41
+ children: ComponentChildren;
42
+ }
43
+
44
+ export function SplitColumn({
45
+ fraction,
46
+ onFraction,
47
+ rightPaneName,
48
+ onClosePane,
49
+ rightPane,
50
+ children,
51
+ }: SplitColumnProps) {
52
+ const columnRef = useRef<HTMLDivElement | null>(null);
53
+
54
+ const startDrag = (event: PointerEvent) => {
55
+ const handle = event.currentTarget as HTMLElement | null;
56
+ const column = columnRef.current;
57
+ if (!handle || !column) return;
58
+ handle.setPointerCapture(event.pointerId);
59
+
60
+ const move = (moveEvent: PointerEvent) => {
61
+ const rect = column.getBoundingClientRect();
62
+ // A zero-width column (a collapsed panel mid-transition) has no meaningful
63
+ // fraction to compute, and dividing by it would write NaN into the session blob.
64
+ if (rect.width === 0) return;
65
+ onFraction(clampSplitFraction((moveEvent.clientX - rect.left) / rect.width));
66
+ };
67
+ const up = () => {
68
+ handle.releasePointerCapture(event.pointerId);
69
+ handle.removeEventListener('pointermove', move);
70
+ handle.removeEventListener('pointerup', up);
71
+ };
72
+ handle.addEventListener('pointermove', move);
73
+ handle.addEventListener('pointerup', up);
74
+ };
75
+
76
+ return (
77
+ <div ref={columnRef} className="flex w-full h-full" data-split-column="">
78
+ <div
79
+ className="flex flex-col min-w-0 h-full"
80
+ style={{ width: `${Math.round(clampSplitFraction(fraction) * 100)}%` }}
81
+ >
82
+ {children}
83
+ </div>
84
+ <div
85
+ className="w-[3px] flex-shrink-0 cursor-col-resize bg-ink/10 hover:bg-ink/40 transition-colors"
86
+ role="separator"
87
+ aria-orientation="vertical"
88
+ aria-label="Resize split panes"
89
+ onPointerDown={startDrag}
90
+ />
91
+ <div className="flex-1 min-w-0 h-full">
92
+ <SplitPane fileName={rightPaneName} onClose={onClosePane}>
93
+ {rightPane}
94
+ </SplitPane>
95
+ </div>
96
+ </div>
97
+ );
98
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The right pane of a split editor column.
8
+ *
9
+ * It is a SECOND `Editor`, not a second document list: the pane takes the tab it should
10
+ * show and renders the same panel with that tab forced active. Everything about it — the
11
+ * toolbar, the find bar, the surface, the save path — is the panel the left pane already
12
+ * uses, so a split cannot have a feature the unsplit editor lacks.
13
+ *
14
+ * ## Why a forced `activeFileId` rather than a second tab list
15
+ *
16
+ * The strip stays in the LEFT pane and stays the single owner of the tab order and of
17
+ * `activeFileId`. The right pane is given its own id to render and is told to keep it: a
18
+ * click on its tab strip would move the left pane's active tab, which is the behaviour the
19
+ * user is not asking for when they split.
20
+ *
21
+ * ## Closing the pane closes the VIEW, not the tab
22
+ *
23
+ * The tab stays in the strip, which is what makes the split a layout decision rather than a
24
+ * document one.
25
+ */
26
+
27
+ import type { ComponentChildren } from 'preact';
28
+ import { X } from 'lucide-preact';
29
+
30
+ interface SplitPaneProps {
31
+ /** The tab's name, for the header that identifies which document this is. */
32
+ fileName: string;
33
+ onClose: () => void;
34
+ children: ComponentChildren;
35
+ }
36
+
37
+ export function SplitPane({ fileName, onClose, children }: SplitPaneProps) {
38
+ return (
39
+ <div className="flex flex-col h-full min-w-0" data-split-pane="">
40
+ <div className="flex items-center justify-between gap-2 px-3 py-1 border-b border-ink/10 bg-canvas flex-shrink-0">
41
+ <span className="text-[11px] font-mono text-ink/60 truncate" title={fileName}>
42
+ {fileName}
43
+ </span>
44
+ <button
45
+ type="button"
46
+ onClick={onClose}
47
+ className="p-0.5 rounded hover:bg-ink/10 text-ink/50 hover:text-ink transition-colors cursor-pointer flex-shrink-0"
48
+ title="Close this pane (the tab stays open)"
49
+ aria-label="Close split pane"
50
+ >
51
+ <X size={12} />
52
+ </button>
53
+ </div>
54
+ <div className="flex-1 min-h-0">{children}</div>
55
+ </div>
56
+ );
57
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The desktop editor's status bar: where the caret is, how the file is indented, and
8
+ * how it ends.
9
+ *
10
+ * The phone has had a status strip since the editor was rebuilt (`lines · chars ·
11
+ * language`); the desktop pane had nothing, so the only way to know the caret's line
12
+ * was to count. This is the missing half, and it is also where the two settings that
13
+ * change the BYTES of a save are reported — the indent unit and the line ending —
14
+ * because a user who cannot see them cannot tell whether a 4-space repository is
15
+ * being indented correctly.
16
+ *
17
+ * ## It does not hide
18
+ *
19
+ * The panel has a 320px floor (`MIN_EDITOR_PANEL_WIDTH`), so there is always room for
20
+ * one 24px row — and a readout that disappears at some widths is a readout the user
21
+ * cannot rely on. A container query was tried and removed: the strip's own root has no
22
+ * `@container` ancestor, so `@[240px]:flex` never matched and the row was `hidden` at
23
+ * every width, which a test caught rather than a reader.
24
+ *
25
+ * ## The right half is the SAVE state, not a second copy of the toolbar's
26
+ *
27
+ * The toolbar already shows saving/saved/error through its icon. Repeating it here
28
+ * would be two indicators for one fact, so the right half carries only what the
29
+ * toolbar cannot: the file's own line ending, and the language the surface resolved.
30
+ */
31
+
32
+ import { VIEWER_LABELS, type ViewerKind } from '@/shared/lib/fs/document-kind';
33
+ import type { CaretPosition } from '@/client/hooks/editor/caret-position';
34
+ import type { LineEnding } from '@/shared/lib/code/line-endings';
35
+
36
+ interface EditorStatusBarProps {
37
+ /** `null` before the surface reports a state, and for a byte viewer. */
38
+ caret: CaretPosition | null;
39
+ /** The file's own ending, which the next save restores. */
40
+ eol: LineEnding;
41
+ /** Change the ending the next save writes. */
42
+ onSetEol: (eol: LineEnding) => void;
43
+ /** One indentation level, already resolved from the setting. */
44
+ indentWidth: number;
45
+ insertSpaces: boolean;
46
+ /** The Shiki language id the surface resolved. */
47
+ language: string;
48
+ /** A byte-drawing viewer prints its KIND instead of a caret. */
49
+ byteViewer: boolean;
50
+ viewerKind: ViewerKind;
51
+ lineCount: number;
52
+ }
53
+
54
+ /** `Spaces: 2` / `Tabs`, which is what the indent actually inserts. */
55
+ function indentLabel(width: number, insertSpaces: boolean): string {
56
+ return insertSpaces ? `Spaces: ${width}` : 'Tabs';
57
+ }
58
+
59
+ export function EditorStatusBar({
60
+ caret,
61
+ eol,
62
+ onSetEol,
63
+ indentWidth,
64
+ insertSpaces,
65
+ language,
66
+ byteViewer,
67
+ viewerKind,
68
+ lineCount,
69
+ }: EditorStatusBarProps) {
70
+ return (
71
+ <footer
72
+ className="flex bg-canvas border-t border-ink/10 px-3 items-center justify-between text-[10px] text-ink/50 flex-shrink-0 font-mono h-6"
73
+ data-editor-status-bar=""
74
+ >
75
+ <div className="flex items-center gap-3 min-w-0">
76
+ {byteViewer ? (
77
+ <span className="uppercase">{VIEWER_LABELS[viewerKind]}</span>
78
+ ) : (
79
+ <>
80
+ {/* `Ln 12, Col 34` is the shape every editor uses, and it is also what a
81
+ stack trace gives the user to look for. */}
82
+ <span className="tabular-nums">
83
+ {caret ? `Ln ${caret.line}, Col ${caret.column}` : 'Ln —, Col —'}
84
+ </span>
85
+ <span>{indentLabel(indentWidth, insertSpaces)}</span>
86
+ {/* A control, not a label: the ending is a choice the write path already
87
+ carries, and a file that arrived as CRLF had no way to become LF. */}
88
+ <button
89
+ type="button"
90
+ onClick={() => onSetEol(eol === 'lf' ? 'crlf' : 'lf')}
91
+ className="uppercase hover:text-ink transition-colors cursor-pointer"
92
+ title={`Line endings: ${eol.toUpperCase()} — click to switch`}
93
+ aria-label={`Line endings ${eol.toUpperCase()}, switch`}
94
+ >
95
+ {eol}
96
+ </button>
97
+ <span>{lineCount} lines</span>
98
+ </>
99
+ )}
100
+ </div>
101
+ <div className="flex items-center gap-3 min-w-0">
102
+ <span className="uppercase text-ink/40">{language}</span>
103
+ </div>
104
+ </footer>
105
+ );
106
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The tab strip's context menu, drawn from `tab-menu.ts`'s rows.
8
+ *
9
+ * A portal to `document.body`, like every other menu here: the tab strip is a
10
+ * horizontal scroller inside a resizable panel, and a `position: fixed` menu nested in
11
+ * one is clipped the moment the panel is narrower than the menu.
12
+ *
13
+ * The geometry is measured, not guessed — a hand-written height puts the last rows off
14
+ * screen the moment a row is added, which is the failure the Files panel's own menu
15
+ * documents.
16
+ */
17
+
18
+ import { useLayoutEffect, useRef, useState } from 'preact/hooks';
19
+ import { createPortal } from 'preact/compat';
20
+
21
+ import type { TabMenuAction, TabMenuRow } from '@/client/lib/editor/tab-menu';
22
+
23
+ interface TabContextMenuProps {
24
+ x: number;
25
+ y: number;
26
+ rows: TabMenuRow[];
27
+ onAction: (action: TabMenuAction) => void;
28
+ onClose: () => void;
29
+ }
30
+
31
+ export function TabContextMenu({ x, y, rows, onAction, onClose }: TabContextMenuProps) {
32
+ const menuRef = useRef<HTMLDivElement | null>(null);
33
+ const [position, setPosition] = useState({ left: x, top: y });
34
+
35
+ // Clamp against the viewport's edges once the menu has a real height. A menu opened
36
+ // near the bottom would otherwise draw its last rows past the window.
37
+ useLayoutEffect(() => {
38
+ const menu = menuRef.current;
39
+ if (!menu) return;
40
+ const { width, height } = menu.getBoundingClientRect();
41
+ setPosition({
42
+ left: Math.min(x, Math.max(0, window.innerWidth - width - 8)),
43
+ top: Math.min(y, Math.max(0, window.innerHeight - height - 8)),
44
+ });
45
+ }, [x, y, rows.length]);
46
+
47
+ return createPortal(
48
+ <div className="fixed inset-0 z-[70]" onClick={onClose} onContextMenu={(event) => { event.preventDefault(); onClose(); }}>
49
+ <div
50
+ ref={menuRef}
51
+ role="menu"
52
+ aria-label="Tab actions"
53
+ className="absolute w-52 bg-paper border border-ink/15 rounded-md shadow-xl py-1 text-xs text-ink"
54
+ style={{ left: `${position.left}px`, top: `${position.top}px` }}
55
+ onClick={(event) => event.stopPropagation()}
56
+ >
57
+ {rows.map((row) => (
58
+ <button
59
+ key={row.action}
60
+ type="button"
61
+ role="menuitem"
62
+ onClick={() => {
63
+ onAction(row.action);
64
+ onClose();
65
+ }}
66
+ className="w-full text-left px-3 py-1.5 hover:bg-ink/5 transition-colors cursor-pointer"
67
+ >
68
+ {row.label}
69
+ </button>
70
+ ))}
71
+ </div>
72
+ </div>,
73
+ document.body,
74
+ );
75
+ }