@bendyline/docblocks 1.1.0 → 1.1.2

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 (35) hide show
  1. package/README.md +38 -12
  2. package/dist/{chunk-OGJN2J4P.js → chunk-IM7LCQJ6.js} +109 -34
  3. package/dist/chunk-IM7LCQJ6.js.map +1 -0
  4. package/dist/chunk-ME76RUMR.js +23 -0
  5. package/dist/{chunk-AOBPNSU6.js.map → chunk-ME76RUMR.js.map} +1 -1
  6. package/dist/filesystem/electron-provider.d.ts +1 -1
  7. package/dist/filesystem/electron-provider.js +4 -4
  8. package/dist/filesystem/filesystem-content-container.d.ts.map +1 -1
  9. package/dist/filesystem/filesystem-content-container.js +14 -1
  10. package/dist/filesystem/filesystem-content-container.js.map +1 -1
  11. package/dist/filesystem/indexeddb-provider.d.ts.map +1 -1
  12. package/dist/filesystem/indexeddb-provider.js +60 -18
  13. package/dist/filesystem/indexeddb-provider.js.map +1 -1
  14. package/dist/filesystem/native-provider.d.ts +1 -0
  15. package/dist/filesystem/native-provider.d.ts.map +1 -1
  16. package/dist/filesystem/native-provider.js +48 -14
  17. package/dist/filesystem/native-provider.js.map +1 -1
  18. package/dist/host/index.d.ts +5 -5
  19. package/dist/host/index.js +7 -7
  20. package/dist/host/types.d.ts +18 -18
  21. package/dist/host/types.d.ts.map +1 -1
  22. package/dist/host/types.js +2 -2
  23. package/dist/{index-TtDaQ3vS.d.ts → index-pgBHBQ9G.d.ts} +22 -22
  24. package/dist/workspace/types.d.ts +7 -0
  25. package/dist/workspace/types.d.ts.map +1 -1
  26. package/package.json +2 -7
  27. package/src/filesystem/electron-provider.ts +6 -6
  28. package/src/filesystem/filesystem-content-container.ts +12 -1
  29. package/src/filesystem/indexeddb-provider.ts +65 -19
  30. package/src/filesystem/native-provider.ts +49 -13
  31. package/src/host/index.ts +14 -14
  32. package/src/host/types.ts +18 -18
  33. package/src/workspace/types.ts +7 -0
  34. package/dist/chunk-AOBPNSU6.js +0 -23
  35. package/dist/chunk-OGJN2J4P.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/docblocks",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Core data structures and filesystem abstractions for DocBlocks",
5
5
  "license": "MIT",
6
6
  "author": "Bendyline",
@@ -54,11 +54,6 @@
54
54
  "typecheck": "tsc --noEmit"
55
55
  },
56
56
  "dependencies": {
57
- "@bendyline/squisq": "1.3.0",
58
- "@bendyline/squisq-editor-react": "1.4.0",
59
- "@bendyline/squisq-formats": "1.2.3",
60
- "@bendyline/squisq-react": "1.2.0",
61
- "@bendyline/squisq-video": "1.0.5",
62
- "@bendyline/squisq-video-react": "1.0.5"
57
+ "@bendyline/squisq": "1.5.1"
63
58
  }
64
59
  }
@@ -5,20 +5,20 @@
5
5
  * whitelist of registered workspace roots.
6
6
  *
7
7
  * This file has no Electron dependency — it is a pure IPC client that
8
- * relies on the `docblocksHost` global installed by the preload script.
8
+ * relies on the `docBlocksHost` global installed by the preload script.
9
9
  */
10
10
 
11
11
  import type { FileSystemProvider, FileSystemEntry, FileMeta } from './types.js';
12
- import { maybeGetDocblocksHost } from '../host/index.js';
13
- import type { DocblocksHostFsAPI } from '../host/types.js';
12
+ import { maybeGetDocBlocksHost } from '../host/index.js';
13
+ import type { DocBlocksHostFsAPI } from '../host/types.js';
14
14
 
15
15
  export { isElectronHost } from '../host/index.js';
16
16
 
17
- function getHostFs(): DocblocksHostFsAPI {
18
- const host = maybeGetDocblocksHost();
17
+ function getHostFs(): DocBlocksHostFsAPI {
18
+ const host = maybeGetDocBlocksHost();
19
19
  if (!host) {
20
20
  throw new Error(
21
- 'ElectronFileSystemProvider: docblocksHost is not available — not running under Electron?',
21
+ 'ElectronFileSystemProvider: docBlocksHost is not available — not running under Electron?',
22
22
  );
23
23
  }
24
24
  return host.fs;
@@ -52,7 +52,18 @@ export class FileSystemContentContainer implements ContentContainer {
52
52
  }
53
53
 
54
54
  async readFile(path: string): Promise<ArrayBuffer | null> {
55
- return this.provider.readBinary(joinPrefix(this.prefix, path));
55
+ const full = joinPrefix(this.prefix, path);
56
+ const binary = await this.provider.readBinary(full);
57
+ if (binary) return binary;
58
+ // IndexedDB-backed workspaces store text via `writeFile(string)` and
59
+ // binary via `writeBinary(ArrayBuffer)` under separate keys, so a
60
+ // markdown file written through the text API is invisible to
61
+ // `readBinary`. Fall back to text-then-UTF-8 so consumers like the
62
+ // recursive HTML export can resolve sibling `.md` links uniformly
63
+ // across browser and native workspaces.
64
+ const text = await this.provider.readFile(full);
65
+ if (text === null) return null;
66
+ return new TextEncoder().encode(text).buffer as ArrayBuffer;
56
67
  }
57
68
 
58
69
  async writeFile(path: string, data: ArrayBuffer | Uint8Array, _mimeType?: string): Promise<void> {
@@ -153,6 +153,66 @@ export class IndexedDBFileSystemProvider implements FileSystemProvider {
153
153
  async rename(oldPath: string, newPath: string): Promise<void> {
154
154
  const op = normalisePath(oldPath);
155
155
  const np = normalisePath(newPath);
156
+ if (op === np) return;
157
+ if (!op || !np) {
158
+ throw new Error('Cannot rename the filesystem root');
159
+ }
160
+ if (np.startsWith(op + '/')) {
161
+ throw new Error('Cannot move a directory into itself');
162
+ }
163
+
164
+ const dirs = await this.getDirs();
165
+
166
+ // Handle directory rename by moving every tracked child directory and
167
+ // every file record keyed under the old directory prefix.
168
+ if (dirs.has(op)) {
169
+ const newParent = parentDir(np);
170
+ if (newParent) {
171
+ await this.ensureDir(newParent);
172
+ }
173
+
174
+ const allKeys = await this.store.keys();
175
+ const oldKeyPrefix = `fs:${op}/`;
176
+ const newKeyPrefix = `fs:${np}/`;
177
+ const metaSuffix = ':meta';
178
+ const keysToMove = allKeys.filter((k) => k.startsWith(oldKeyPrefix));
179
+
180
+ await Promise.all(
181
+ keysToMove.map(async (oldKey) => {
182
+ const newKey = newKeyPrefix + oldKey.slice(oldKeyPrefix.length);
183
+ if (oldKey.endsWith(metaSuffix)) {
184
+ const meta = await this.store.get<FileMeta>(oldKey);
185
+ if (meta) {
186
+ const newFilePath = newKey.slice(3, -metaSuffix.length);
187
+ await this.store.set(metaKey(newFilePath), {
188
+ ...meta,
189
+ name: baseName(newFilePath),
190
+ path: newFilePath,
191
+ });
192
+ }
193
+ } else {
194
+ const value = await this.store.get<unknown>(oldKey);
195
+ if (value !== null) {
196
+ await this.store.set(newKey, value);
197
+ }
198
+ }
199
+ await this.store.remove(oldKey);
200
+ }),
201
+ );
202
+
203
+ dirs.delete(op);
204
+ dirs.add(np);
205
+ const oldPrefix = op + '/';
206
+ const newPrefix = np + '/';
207
+ for (const d of [...dirs]) {
208
+ if (d.startsWith(oldPrefix)) {
209
+ dirs.delete(d);
210
+ dirs.add(newPrefix + d.slice(oldPrefix.length));
211
+ }
212
+ }
213
+ await this.saveDirs(dirs);
214
+ return;
215
+ }
156
216
 
157
217
  // Read existing data
158
218
  const content = await this.store.get<string>(contentKey(op));
@@ -167,9 +227,11 @@ export class IndexedDBFileSystemProvider implements FileSystemProvider {
167
227
  await this.store.set(binaryKey(np), binary);
168
228
  }
169
229
  if (meta) {
170
- meta.name = baseName(np);
171
- meta.path = np;
172
- await this.store.set(metaKey(np), meta);
230
+ await this.store.set(metaKey(np), {
231
+ ...meta,
232
+ name: baseName(np),
233
+ path: np,
234
+ });
173
235
  }
174
236
 
175
237
  // Ensure parent dir of new path exists
@@ -182,22 +244,6 @@ export class IndexedDBFileSystemProvider implements FileSystemProvider {
182
244
  await this.store.remove(contentKey(op));
183
245
  await this.store.remove(binaryKey(op));
184
246
  await this.store.remove(metaKey(op));
185
-
186
- // Handle directory rename
187
- const dirs = await this.getDirs();
188
- if (dirs.has(op)) {
189
- dirs.delete(op);
190
- dirs.add(np);
191
- const oldPrefix = op + '/';
192
- const newPrefix = np + '/';
193
- for (const d of [...dirs]) {
194
- if (d.startsWith(oldPrefix)) {
195
- dirs.delete(d);
196
- dirs.add(newPrefix + d.slice(oldPrefix.length));
197
- }
198
- }
199
- await this.saveDirs(dirs);
200
- }
201
247
  }
202
248
 
203
249
  async readDirectory(path: string): Promise<FileSystemEntry[]> {
@@ -139,6 +139,13 @@ function baseName(p: string): string {
139
139
  return idx === -1 ? p : p.slice(idx + 1);
140
140
  }
141
141
 
142
+ function toWritableBinary(data: ArrayBuffer | Uint8Array): ArrayBuffer {
143
+ if (data instanceof ArrayBuffer) return data;
144
+ const copy = new Uint8Array(data.byteLength);
145
+ copy.set(data);
146
+ return copy.buffer;
147
+ }
148
+
142
149
  // ── Implementation ─────────────────────────────────────────────────
143
150
 
144
151
  export class NativeFileSystemProvider implements FileSystemProvider {
@@ -153,6 +160,28 @@ export class NativeFileSystemProvider implements FileSystemProvider {
153
160
  this.root = root;
154
161
  }
155
162
 
163
+ private async copyDirectory(oldDirPath: string, newDirPath: string): Promise<boolean> {
164
+ const source = await resolveDir(this.root, oldDirPath);
165
+ if (!source) return false;
166
+ await resolveDirCreate(this.root, newDirPath);
167
+
168
+ for await (const [name, handle] of source as unknown as AsyncIterable<
169
+ [string, FileSystemHandle]
170
+ >) {
171
+ const oldChild = oldDirPath ? `${oldDirPath}/${name}` : name;
172
+ const newChild = newDirPath ? `${newDirPath}/${name}` : name;
173
+ if (handle.kind === 'directory') {
174
+ await this.copyDirectory(oldChild, newChild);
175
+ } else {
176
+ const fileHandle = await source.getFileHandle(name);
177
+ const file = await fileHandle.getFile();
178
+ await this.writeBinary(newChild, await file.arrayBuffer());
179
+ }
180
+ }
181
+
182
+ return true;
183
+ }
184
+
156
185
  async readFile(path: string): Promise<string | null> {
157
186
  const p = normalisePath(path);
158
187
  const dir = await resolveDir(this.root, parentDir(p));
@@ -187,20 +216,31 @@ export class NativeFileSystemProvider implements FileSystemProvider {
187
216
  async rename(oldPath: string, newPath: string): Promise<void> {
188
217
  const op = normalisePath(oldPath);
189
218
  const np = normalisePath(newPath);
219
+ if (op === np) return;
220
+ if (!op || !np) {
221
+ throw new Error('Cannot rename the filesystem root');
222
+ }
223
+ if (np.startsWith(op + '/')) {
224
+ throw new Error('Cannot move a directory into itself');
225
+ }
190
226
 
191
227
  // The File System Access API doesn't have a native rename.
192
- // Readwrite → delete.
193
- const content = await this.readFile(op);
194
- if (content !== null) {
195
- await this.writeFile(np, content);
228
+ // Copy → delete.
229
+ const oldParent = await resolveDir(this.root, parentDir(op));
230
+ if (!oldParent) return;
231
+
232
+ try {
233
+ const fileHandle = await oldParent.getFileHandle(baseName(op));
234
+ const file = await fileHandle.getFile();
235
+ await this.writeBinary(np, await file.arrayBuffer());
196
236
  await this.delete(op);
197
237
  return;
238
+ } catch {
239
+ // Not a file; try directory below.
198
240
  }
199
241
 
200
- // Try binary
201
- const binary = await this.readBinary(op);
202
- if (binary !== null) {
203
- await this.writeBinary(np, binary);
242
+ const copied = await this.copyDirectory(op, np);
243
+ if (copied) {
204
244
  await this.delete(op);
205
245
  }
206
246
  }
@@ -293,11 +333,7 @@ export class NativeFileSystemProvider implements FileSystemProvider {
293
333
  const dir = await resolveDirCreate(this.root, parentDir(p));
294
334
  const fileHandle = await dir.getFileHandle(baseName(p), { create: true });
295
335
  const writable = await fileHandle.createWritable();
296
- if (data instanceof ArrayBuffer) {
297
- await writable.write(data);
298
- } else {
299
- await writable.write(data.buffer as ArrayBuffer);
300
- }
336
+ await writable.write(toWritableBinary(data));
301
337
  await writable.close();
302
338
  }
303
339
  }
package/src/host/index.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  /**
2
2
  * Host bridge — shared types + runtime access for the Electron desktop
3
- * host. The renderer calls `getDocblocksHost()` to reach the preload
3
+ * host. The renderer calls `getDocBlocksHost()` to reach the preload
4
4
  * contextBridge; `isElectronHost()` gates desktop-only UI branches.
5
5
  */
6
6
 
7
7
  export type {
8
- DocblocksHostAPI,
9
- DocblocksHostFsAPI,
10
- DocblocksHostWorkspacesAPI,
11
- DocblocksHostShellAPI,
12
- DocblocksHostFfmpegAPI,
13
- DocblocksHostUpdaterAPI,
8
+ DocBlocksHostAPI,
9
+ DocBlocksHostFsAPI,
10
+ DocBlocksHostWorkspacesAPI,
11
+ DocBlocksHostShellAPI,
12
+ DocBlocksHostFfmpegAPI,
13
+ DocBlocksHostUpdaterAPI,
14
14
  ElectronWorkspaceInfo,
15
15
  HostEnvironment,
16
16
  MenuCommand,
@@ -18,12 +18,12 @@ export type {
18
18
  UpdaterStatus,
19
19
  } from './types.js';
20
20
 
21
- import type { DocblocksHostAPI } from './types.js';
21
+ import type { DocBlocksHostAPI } from './types.js';
22
22
 
23
23
  /** True when running inside the Electron desktop shell. */
24
24
  export function isElectronHost(): boolean {
25
25
  if (typeof globalThis === 'undefined') return false;
26
- const host = (globalThis as { docblocksHost?: unknown }).docblocksHost;
26
+ const host = (globalThis as { docBlocksHost?: unknown }).docBlocksHost;
27
27
  return (
28
28
  typeof host === 'object' &&
29
29
  host !== null &&
@@ -33,15 +33,15 @@ export function isElectronHost(): boolean {
33
33
  }
34
34
 
35
35
  /** Return the host API, or throw if not running under Electron. */
36
- export function getDocblocksHost(): DocblocksHostAPI {
37
- const host = (globalThis as { docblocksHost?: DocblocksHostAPI }).docblocksHost;
36
+ export function getDocBlocksHost(): DocBlocksHostAPI {
37
+ const host = (globalThis as { docBlocksHost?: DocBlocksHostAPI }).docBlocksHost;
38
38
  if (!host) {
39
- throw new Error('docblocksHost is not available — not running under Electron?');
39
+ throw new Error('docBlocksHost is not available — not running under Electron?');
40
40
  }
41
41
  return host;
42
42
  }
43
43
 
44
44
  /** Return the host API, or null if not running under Electron. */
45
- export function maybeGetDocblocksHost(): DocblocksHostAPI | null {
46
- return (globalThis as { docblocksHost?: DocblocksHostAPI }).docblocksHost ?? null;
45
+ export function maybeGetDocBlocksHost(): DocBlocksHostAPI | null {
46
+ return (globalThis as { docBlocksHost?: DocBlocksHostAPI }).docBlocksHost ?? null;
47
47
  }
package/src/host/types.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  /**
2
- * DocblocksHostAPI — the contract exposed by the Electron desktop shell
2
+ * DocBlocksHostAPI — the contract exposed by the Electron desktop shell
3
3
  * to its renderer process via contextBridge.
4
4
  *
5
5
  * This file is the single source of truth for the host ↔ renderer
6
6
  * bridge. The Electron preload script exposes an implementation matching
7
- * this shape; the React renderer calls it through `window.docblocksHost`.
7
+ * this shape; the React renderer calls it through `window.docBlocksHost`.
8
8
  */
9
9
 
10
10
  import type { FileSystemEntry, FileMeta } from '../filesystem/types.js';
11
11
 
12
12
  /** Filesystem operations scoped to a registered absolute root path. */
13
- export interface DocblocksHostFsAPI {
13
+ export interface DocBlocksHostFsAPI {
14
14
  readFile(rootPath: string, path: string): Promise<string | null>;
15
15
  writeFile(rootPath: string, path: string, content: string): Promise<void>;
16
16
  delete(rootPath: string, path: string): Promise<void>;
@@ -36,7 +36,7 @@ export interface ElectronWorkspaceInfo {
36
36
  }
37
37
 
38
38
  /** Workspace-management operations exposed to the renderer. */
39
- export interface DocblocksHostWorkspacesAPI {
39
+ export interface DocBlocksHostWorkspacesAPI {
40
40
  /**
41
41
  * Return the default workspace (creating ~/Documents/DocBlocks on first
42
42
  * call, or the user's configured default).
@@ -58,7 +58,7 @@ export interface DocblocksHostWorkspacesAPI {
58
58
  }
59
59
 
60
60
  /** Shell operations — reveal in Finder/Explorer, open external URLs. */
61
- export interface DocblocksHostShellAPI {
61
+ export interface DocBlocksHostShellAPI {
62
62
  /** Reveal a file (by absolute path) in the OS file manager. */
63
63
  revealInFolder(absolutePath: string): Promise<void>;
64
64
  /** Open a URL in the default browser. */
@@ -66,7 +66,7 @@ export interface DocblocksHostShellAPI {
66
66
  }
67
67
 
68
68
  /** System ffmpeg detection and invocation. */
69
- export interface DocblocksHostFfmpegAPI {
69
+ export interface DocBlocksHostFfmpegAPI {
70
70
  /** True if `ffmpeg` is available on PATH (or bundled). */
71
71
  available(): Promise<boolean>;
72
72
  /** Version string from `ffmpeg -version`, or null if unavailable. */
@@ -83,7 +83,7 @@ export interface DocblocksHostFfmpegAPI {
83
83
  }
84
84
 
85
85
  /** Auto-updater control. */
86
- export interface DocblocksHostUpdaterAPI {
86
+ export interface DocBlocksHostUpdaterAPI {
87
87
  /** Kick off a check; resolves to true if an update is available. */
88
88
  checkForUpdates(): Promise<boolean>;
89
89
  /** Current app version string. */
@@ -117,12 +117,12 @@ export type MenuCommand =
117
117
  | 'help:checkForUpdates'
118
118
  | 'help:viewOnGitHub';
119
119
 
120
- /** Deep-link event: the user opened a docblocks:// URL or dropped a file. */
120
+ /** Deep-link event resolved by the host into a trusted workspace file. */
121
121
  export interface OpenRequest {
122
- /** For docblocks:// URLs — the full URL string. */
123
- url?: string;
124
- /** For file drops / open-with absolute path to the file. */
125
- filePath?: string;
122
+ kind: 'workspace-file';
123
+ workspaceId: string;
124
+ /** Slash-prefixed path relative to the workspace root. */
125
+ path: string;
126
126
  }
127
127
 
128
128
  /** Environment metadata provided by the host. */
@@ -133,13 +133,13 @@ export interface HostEnvironment {
133
133
  }
134
134
 
135
135
  /** The full DocBlocks desktop host API. */
136
- export interface DocblocksHostAPI {
136
+ export interface DocBlocksHostAPI {
137
137
  env: HostEnvironment;
138
- fs: DocblocksHostFsAPI;
139
- workspaces: DocblocksHostWorkspacesAPI;
140
- shell: DocblocksHostShellAPI;
141
- ffmpeg: DocblocksHostFfmpegAPI;
142
- updater: DocblocksHostUpdaterAPI;
138
+ fs: DocBlocksHostFsAPI;
139
+ workspaces: DocBlocksHostWorkspacesAPI;
140
+ shell: DocBlocksHostShellAPI;
141
+ ffmpeg: DocBlocksHostFfmpegAPI;
142
+ updater: DocBlocksHostUpdaterAPI;
143
143
  /**
144
144
  * Subscribe to menu commands dispatched by the native menu.
145
145
  * Returns an unsubscribe function.
@@ -19,4 +19,11 @@ export interface WorkspaceDescriptor {
19
19
  lastOpened: string;
20
20
  /** Absolute filesystem path for 'electron-native' workspaces. */
21
21
  rootPath?: string;
22
+ /**
23
+ * Per-workspace override for the global versioning preference. When
24
+ * `'inherit'` (or absent), the global preference applies. `'on'` /
25
+ * `'off'` force the corresponding behavior regardless of the global
26
+ * setting. See `resolveVersioningEnabled` in the preferences module.
27
+ */
28
+ versioningOverride?: 'inherit' | 'on' | 'off';
22
29
  }
@@ -1,23 +0,0 @@
1
- // src/host/index.ts
2
- function isElectronHost() {
3
- if (typeof globalThis === "undefined") return false;
4
- const host = globalThis.docblocksHost;
5
- return typeof host === "object" && host !== null && typeof host.fs === "object" && host.fs !== null;
6
- }
7
- function getDocblocksHost() {
8
- const host = globalThis.docblocksHost;
9
- if (!host) {
10
- throw new Error("docblocksHost is not available \u2014 not running under Electron?");
11
- }
12
- return host;
13
- }
14
- function maybeGetDocblocksHost() {
15
- return globalThis.docblocksHost ?? null;
16
- }
17
-
18
- export {
19
- isElectronHost,
20
- getDocblocksHost,
21
- maybeGetDocblocksHost
22
- };
23
- //# sourceMappingURL=chunk-AOBPNSU6.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/filesystem/indexeddb-provider.ts","../src/filesystem/indexeddb-content-container.ts","../src/filesystem/filesystem-content-container.ts","../src/filesystem/file-media-provider.ts","../src/filesystem/native-provider.ts","../src/filesystem/electron-provider.ts"],"sourcesContent":["/**\n * IndexedDBFileSystemProvider — virtualises a filesystem on top of IndexedDB\n * using the LocalForageAdapter from @bendyline/squisq/storage.\n *\n * Key schema:\n * fs:{path}:content → string (text file contents)\n * fs:{path}:binary → ArrayBuffer (binary file contents)\n * fs:{path}:meta → FileMeta object\n * fs:dirs → Set<string> of known directory paths\n */\n\nimport { LocalForageAdapter } from '@bendyline/squisq/storage';\nimport type { FileSystemProvider, FileSystemEntry, FileMeta } from './types.js';\n\n// ── Helpers ────────────────────────────────────────────────────────\n\n/** Normalise a path: strip leading/trailing slashes, collapse doubles. */\nfunction normalisePath(p: string): string {\n return p.replace(/\\\\/g, '/').replace(/\\/+/g, '/').replace(/^\\//, '').replace(/\\/$/, '');\n}\n\n/** Get the parent directory of a path, or empty string for root-level. */\nfunction parentDir(p: string): string {\n const idx = p.lastIndexOf('/');\n return idx === -1 ? '' : p.slice(0, idx);\n}\n\n/** Get the filename component of a path. */\nfunction baseName(p: string): string {\n const idx = p.lastIndexOf('/');\n return idx === -1 ? p : p.slice(idx + 1);\n}\n\n// ── Key helpers ────────────────────────────────────────────────────\n\nfunction contentKey(path: string): string {\n return `fs:${path}:content`;\n}\n\nfunction binaryKey(path: string): string {\n return `fs:${path}:binary`;\n}\n\nfunction metaKey(path: string): string {\n return `fs:${path}:meta`;\n}\n\nconst DIRS_KEY = 'fs:dirs';\n\n// ── Implementation ─────────────────────────────────────────────────\n\nexport class IndexedDBFileSystemProvider implements FileSystemProvider {\n readonly id: string;\n readonly label: string;\n\n private store: LocalForageAdapter;\n\n constructor(id: string, label: string) {\n this.id = id;\n this.label = label;\n this.store = new LocalForageAdapter({\n name: `docblocks-fs-${id}`,\n storeName: 'files',\n });\n }\n\n // ── Directory tracking ──────────────────────────────────────────\n\n private async getDirs(): Promise<Set<string>> {\n const raw = await this.store.get<string[]>(DIRS_KEY);\n return new Set(raw ?? []);\n }\n\n private async saveDirs(dirs: Set<string>): Promise<void> {\n await this.store.set(DIRS_KEY, [...dirs]);\n }\n\n /** Ensure a directory (and all ancestors) are tracked. */\n private async ensureDir(dirPath: string): Promise<void> {\n if (!dirPath) return;\n const dirs = await this.getDirs();\n const parts = dirPath.split('/');\n let current = '';\n let changed = false;\n for (const part of parts) {\n current = current ? `${current}/${part}` : part;\n if (!dirs.has(current)) {\n dirs.add(current);\n changed = true;\n }\n }\n if (changed) {\n await this.saveDirs(dirs);\n }\n }\n\n // ── FileSystemProvider implementation ───────────────────────────\n\n async readFile(path: string): Promise<string | null> {\n const p = normalisePath(path);\n return this.store.get<string>(contentKey(p));\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n const p = normalisePath(path);\n const parent = parentDir(p);\n if (parent) {\n await this.ensureDir(parent);\n }\n\n const meta: FileMeta = {\n name: baseName(p),\n path: p,\n size: new Blob([content]).size,\n lastModified: new Date().toISOString(),\n };\n\n await this.store.set(contentKey(p), content);\n await this.store.set(metaKey(p), meta);\n }\n\n async delete(path: string): Promise<void> {\n const p = normalisePath(path);\n\n // Remove file keys\n await this.store.remove(contentKey(p));\n await this.store.remove(binaryKey(p));\n await this.store.remove(metaKey(p));\n\n // If it was a directory, remove it and all children\n const dirs = await this.getDirs();\n if (dirs.has(p)) {\n const prefix = p + '/';\n const toRemove: string[] = [p];\n for (const d of dirs) {\n if (d.startsWith(prefix)) {\n toRemove.push(d);\n }\n }\n for (const d of toRemove) {\n dirs.delete(d);\n }\n await this.saveDirs(dirs);\n\n // Remove all file keys under this directory\n const allKeys = await this.store.keys();\n const filePrefix = `fs:${p}/`;\n const keysToRemove = allKeys.filter((k) => k.startsWith(filePrefix));\n await Promise.all(keysToRemove.map((k) => this.store.remove(k)));\n }\n }\n\n async rename(oldPath: string, newPath: string): Promise<void> {\n const op = normalisePath(oldPath);\n const np = normalisePath(newPath);\n\n // Read existing data\n const content = await this.store.get<string>(contentKey(op));\n const binary = await this.store.get<ArrayBuffer>(binaryKey(op));\n const meta = await this.store.get<FileMeta>(metaKey(op));\n\n // Write to new location\n if (content !== null) {\n await this.store.set(contentKey(np), content);\n }\n if (binary !== null) {\n await this.store.set(binaryKey(np), binary);\n }\n if (meta) {\n meta.name = baseName(np);\n meta.path = np;\n await this.store.set(metaKey(np), meta);\n }\n\n // Ensure parent dir of new path exists\n const newParent = parentDir(np);\n if (newParent) {\n await this.ensureDir(newParent);\n }\n\n // Delete old\n await this.store.remove(contentKey(op));\n await this.store.remove(binaryKey(op));\n await this.store.remove(metaKey(op));\n\n // Handle directory rename\n const dirs = await this.getDirs();\n if (dirs.has(op)) {\n dirs.delete(op);\n dirs.add(np);\n const oldPrefix = op + '/';\n const newPrefix = np + '/';\n for (const d of [...dirs]) {\n if (d.startsWith(oldPrefix)) {\n dirs.delete(d);\n dirs.add(newPrefix + d.slice(oldPrefix.length));\n }\n }\n await this.saveDirs(dirs);\n }\n }\n\n async readDirectory(path: string): Promise<FileSystemEntry[]> {\n const p = normalisePath(path);\n const dirs = await this.getDirs();\n const entries: FileSystemEntry[] = [];\n const seen = new Set<string>();\n\n // Find child directories\n const prefix = p ? p + '/' : '';\n for (const d of dirs) {\n if (!p && !d.includes('/')) {\n // Root-level directory\n if (!seen.has(d)) {\n seen.add(d);\n entries.push({ kind: 'directory', name: d, path: d });\n }\n } else if (p && d.startsWith(prefix)) {\n const rest = d.slice(prefix.length);\n if (!rest.includes('/')) {\n // Direct child directory\n if (!seen.has(rest)) {\n seen.add(rest);\n entries.push({ kind: 'directory', name: rest, path: d });\n }\n }\n }\n }\n\n // Find child files by scanning meta keys\n const allKeys = await this.store.keys();\n const metaPrefix = p ? `fs:${p}/` : 'fs:';\n const metaSuffix = ':meta';\n\n for (const key of allKeys) {\n if (!key.startsWith(metaPrefix) || !key.endsWith(metaSuffix)) continue;\n\n const filePath = key.slice(3, -metaSuffix.length); // strip \"fs:\" and \":meta\"\n const rel = p ? filePath.slice(prefix.length) : filePath;\n\n // Only direct children (no further slashes)\n if (rel.includes('/')) continue;\n\n if (!seen.has(rel)) {\n seen.add(rel);\n entries.push({ kind: 'file', name: rel, path: filePath });\n }\n }\n\n // Sort: directories first, then alphabetical\n entries.sort((a, b) => {\n if (a.kind !== b.kind) return a.kind === 'directory' ? -1 : 1;\n return a.name.localeCompare(b.name);\n });\n\n return entries;\n }\n\n async exists(path: string): Promise<boolean> {\n const p = normalisePath(path);\n const dirs = await this.getDirs();\n if (dirs.has(p)) return true;\n const meta = await this.store.get(metaKey(p));\n return meta !== null;\n }\n\n async createDirectory(path: string): Promise<void> {\n const p = normalisePath(path);\n await this.ensureDir(p);\n }\n\n async stat(path: string): Promise<FileMeta | null> {\n const p = normalisePath(path);\n return this.store.get<FileMeta>(metaKey(p));\n }\n\n async readBinary(path: string): Promise<ArrayBuffer | null> {\n const p = normalisePath(path);\n return this.store.get<ArrayBuffer>(binaryKey(p));\n }\n\n async writeBinary(path: string, data: ArrayBuffer | Uint8Array): Promise<void> {\n const p = normalisePath(path);\n const parent = parentDir(p);\n if (parent) {\n await this.ensureDir(parent);\n }\n\n const meta: FileMeta = {\n name: baseName(p),\n path: p,\n size: data.byteLength,\n lastModified: new Date().toISOString(),\n };\n\n await this.store.set(binaryKey(p), data);\n await this.store.set(metaKey(p), meta);\n }\n}\n","/**\n * IndexedDBContentContainer — a ContentContainer backed by IndexedDB.\n *\n * Uses a dedicated IndexedDBFileSystemProvider instance (separate store)\n * to persist media files across page refreshes.\n */\n\nimport type { ContentContainer, ContentEntry } from '@bendyline/squisq/storage';\nimport { findDocumentPath } from '@bendyline/squisq/storage';\nimport { IndexedDBFileSystemProvider } from './indexeddb-provider.js';\n\n// ── MIME type guessing ─────────────────────────────────────────────\n\nconst EXTENSION_MIME_MAP: Record<string, string> = {\n '.md': 'text/markdown',\n '.txt': 'text/plain',\n '.json': 'application/json',\n '.jpg': 'image/jpeg',\n '.jpeg': 'image/jpeg',\n '.png': 'image/png',\n '.gif': 'image/gif',\n '.svg': 'image/svg+xml',\n '.webp': 'image/webp',\n '.avif': 'image/avif',\n '.mp4': 'video/mp4',\n '.webm': 'video/webm',\n '.mp3': 'audio/mpeg',\n '.wav': 'audio/wav',\n '.ogg': 'audio/ogg',\n};\n\nfunction guessMimeType(path: string): string {\n const dot = path.lastIndexOf('.');\n if (dot === -1) return 'application/octet-stream';\n const ext = path.slice(dot).toLowerCase();\n return EXTENSION_MIME_MAP[ext] ?? 'application/octet-stream';\n}\n\n// ── Implementation ─────────────────────────────────────────────────\n\nexport class IndexedDBContentContainer implements ContentContainer {\n private provider: IndexedDBFileSystemProvider;\n\n constructor(workspaceId: string) {\n this.provider = new IndexedDBFileSystemProvider(`${workspaceId}-media`, 'Media Storage');\n }\n\n async readFile(path: string): Promise<ArrayBuffer | null> {\n return this.provider.readBinary(path);\n }\n\n async writeFile(path: string, data: ArrayBuffer | Uint8Array, _mimeType?: string): Promise<void> {\n await this.provider.writeBinary(path, data);\n }\n\n async removeFile(path: string): Promise<void> {\n await this.provider.delete(path);\n }\n\n async listFiles(prefix?: string): Promise<ContentEntry[]> {\n const entries: ContentEntry[] = [];\n const walk = async (dir: string) => {\n const children = await this.provider.readDirectory(dir);\n for (const child of children) {\n if (child.kind === 'directory') {\n await walk(child.path);\n } else {\n const filePath = child.path.replace(/^\\//, '');\n if (prefix && !filePath.startsWith(prefix)) continue;\n const meta = await this.provider.stat(child.path);\n entries.push({\n path: filePath,\n mimeType: guessMimeType(filePath),\n size: meta?.size ?? 0,\n });\n }\n }\n };\n await walk('/');\n return entries;\n }\n\n async exists(path: string): Promise<boolean> {\n return this.provider.exists(path);\n }\n\n async getDocumentPath(): Promise<string | null> {\n return findDocumentPath(await this.listFiles());\n }\n\n async readDocument(): Promise<string | null> {\n const docPath = await this.getDocumentPath();\n if (!docPath) return null;\n const data = await this.readFile(docPath);\n if (!data) return null;\n return new TextDecoder().decode(data);\n }\n\n async writeDocument(markdown: string, filename?: string): Promise<void> {\n const name = filename ?? 'index.md';\n const data = new TextEncoder().encode(markdown);\n await this.writeFile(name, data, 'text/markdown');\n }\n}\n","/**\n * FileSystemContentContainer — a ContentContainer backed by any\n * FileSystemProvider, scoped to a sub-path (e.g., \".docblocks/media/\").\n *\n * Used by the Electron desktop app so media lives inside the workspace\n * folder (visible as regular files) rather than in a separate IndexedDB\n * origin that only the app can see.\n */\n\nimport type { ContentContainer, ContentEntry } from '@bendyline/squisq/storage';\nimport { findDocumentPath } from '@bendyline/squisq/storage';\nimport type { FileSystemProvider } from './types.js';\n\nconst EXTENSION_MIME_MAP: Record<string, string> = {\n '.md': 'text/markdown',\n '.txt': 'text/plain',\n '.json': 'application/json',\n '.jpg': 'image/jpeg',\n '.jpeg': 'image/jpeg',\n '.png': 'image/png',\n '.gif': 'image/gif',\n '.svg': 'image/svg+xml',\n '.webp': 'image/webp',\n '.avif': 'image/avif',\n '.mp4': 'video/mp4',\n '.webm': 'video/webm',\n '.mp3': 'audio/mpeg',\n '.wav': 'audio/wav',\n '.ogg': 'audio/ogg',\n};\n\nfunction guessMimeType(path: string): string {\n const dot = path.lastIndexOf('.');\n if (dot === -1) return 'application/octet-stream';\n const ext = path.slice(dot).toLowerCase();\n return EXTENSION_MIME_MAP[ext] ?? 'application/octet-stream';\n}\n\nfunction joinPrefix(prefix: string, p: string): string {\n const clean = p.replace(/^\\/+/, '');\n return prefix.replace(/\\/+$/, '') + '/' + clean;\n}\n\nexport class FileSystemContentContainer implements ContentContainer {\n private readonly prefix: string;\n\n constructor(\n private readonly provider: FileSystemProvider,\n prefix = '.docblocks/media',\n ) {\n this.prefix = prefix.replace(/^\\/+/, '').replace(/\\/+$/, '');\n }\n\n async readFile(path: string): Promise<ArrayBuffer | null> {\n return this.provider.readBinary(joinPrefix(this.prefix, path));\n }\n\n async writeFile(path: string, data: ArrayBuffer | Uint8Array, _mimeType?: string): Promise<void> {\n await this.provider.writeBinary(joinPrefix(this.prefix, path), data);\n }\n\n async removeFile(path: string): Promise<void> {\n await this.provider.delete(joinPrefix(this.prefix, path));\n }\n\n async listFiles(prefix?: string): Promise<ContentEntry[]> {\n const entries: ContentEntry[] = [];\n const walk = async (dir: string) => {\n let children;\n try {\n children = await this.provider.readDirectory(dir);\n } catch {\n return;\n }\n for (const child of children) {\n if (child.kind === 'directory') {\n await walk(child.path);\n } else {\n const rel = child.path.replace(new RegExp('^/?' + this.prefix + '/?'), '');\n if (prefix && !rel.startsWith(prefix)) continue;\n const meta = await this.provider.stat(child.path);\n entries.push({\n path: rel,\n mimeType: guessMimeType(rel),\n size: meta?.size ?? 0,\n });\n }\n }\n };\n await walk('/' + this.prefix);\n return entries;\n }\n\n async exists(path: string): Promise<boolean> {\n return this.provider.exists(joinPrefix(this.prefix, path));\n }\n\n async getDocumentPath(): Promise<string | null> {\n return findDocumentPath(await this.listFiles());\n }\n\n async readDocument(): Promise<string | null> {\n const docPath = await this.getDocumentPath();\n if (!docPath) return null;\n const data = await this.readFile(docPath);\n if (!data) return null;\n return new TextDecoder().decode(data);\n }\n\n async writeDocument(markdown: string, filename?: string): Promise<void> {\n const name = filename ?? 'index.md';\n const data = new TextEncoder().encode(markdown);\n await this.writeFile(name, data, 'text/markdown');\n }\n}\n","/**\n * createFileMediaProvider — per-file media storage following the pandoc /\n * Word convention: a markdown file `notes.md` gets a sibling folder\n * `notes_files/` that holds its images, audio, and video.\n *\n * Given:\n * • `container` — a ContentContainer scoped to the markdown file's\n * parent directory (so `readFile('notes_files/image.png')` maps to the\n * parent-relative path)\n * • `markdownBasename` — e.g. `\"notes.md\"`\n *\n * Returns a MediaProvider that:\n * • Writes new media under `{basename}_files/{name}` in the parent dir\n * • Returns the folder-qualified path (`notes_files/image.png`) from\n * addMedia so the markdown stays portable outside DocBlocks\n * • Resolves both bare (`image.png`) and folder-qualified\n * (`notes_files/image.png`) references — so legacy markdown and\n * exports from other tools both work\n */\n\nimport type { MediaProvider, MediaEntry } from '@bendyline/squisq/schemas';\nimport type { ContentContainer } from '@bendyline/squisq/storage';\n\nfunction stripExt(name: string): string {\n return name.replace(/\\.[^.]+$/, '');\n}\n\nexport function createFileMediaProvider(\n container: ContentContainer,\n markdownBasename: string,\n): MediaProvider {\n const folder = stripExt(markdownBasename) + '_files';\n const prefix = folder + '/';\n const blobUrlCache = new Map<string, string>();\n\n function toKey(ref: string): string {\n const clean = ref.replace(/^\\/+/, '');\n return clean.startsWith(prefix) ? clean : prefix + clean;\n }\n\n return {\n async resolveUrl(ref: string): Promise<string> {\n const key = toKey(ref);\n const cached = blobUrlCache.get(key);\n if (cached) return cached;\n\n const data = await container.readFile(key);\n if (!data) return ref;\n\n const entries = await container.listFiles();\n const entry = entries.find((e) => e.path === key);\n const mimeType = entry?.mimeType ?? 'application/octet-stream';\n\n const url = URL.createObjectURL(new Blob([data], { type: mimeType }));\n blobUrlCache.set(key, url);\n return url;\n },\n\n async listMedia(): Promise<MediaEntry[]> {\n const entries = await container.listFiles(prefix);\n return entries\n .filter((e) => !e.path.toLowerCase().endsWith('.md'))\n .map((e) => ({\n name: e.path,\n mimeType: e.mimeType,\n size: e.size,\n }));\n },\n\n async addMedia(\n name: string,\n data: ArrayBuffer | Blob | Uint8Array,\n mimeType: string,\n ): Promise<string> {\n const key = toKey(name);\n const cached = blobUrlCache.get(key);\n if (cached) {\n URL.revokeObjectURL(cached);\n blobUrlCache.delete(key);\n }\n const buffer = data instanceof Blob ? new Uint8Array(await data.arrayBuffer()) : data;\n await container.writeFile(key, buffer, mimeType);\n return key;\n },\n\n async removeMedia(ref: string): Promise<void> {\n const key = toKey(ref);\n const cached = blobUrlCache.get(key);\n if (cached) {\n URL.revokeObjectURL(cached);\n blobUrlCache.delete(key);\n }\n await container.removeFile(key);\n },\n\n dispose(): void {\n for (const url of blobUrlCache.values()) {\n URL.revokeObjectURL(url);\n }\n blobUrlCache.clear();\n },\n };\n}\n","/**\n * NativeFileSystemProvider — wraps the File System Access API\n * (window.showDirectoryPicker / FileSystemDirectoryHandle).\n *\n * Progressive enhancement: only available in browsers that support\n * the API (Chrome, Edge). Feature-detect with `isNativeFileSystemSupported()`.\n */\n\nimport type { FileSystemProvider, FileSystemEntry, FileMeta } from './types.js';\n\n// ── Feature detection ──────────────────────────────────────────────\n\nexport function isNativeFileSystemSupported(): boolean {\n return typeof globalThis !== 'undefined' && 'showDirectoryPicker' in globalThis;\n}\n\n// ── Handle persistence (IndexedDB, structured clone) ───────────────\n\nconst HANDLE_DB_NAME = 'docblocks-handles';\nconst HANDLE_STORE_NAME = 'directory-handles';\n\nfunction openHandleDB(): Promise<IDBDatabase> {\n return new Promise((resolve, reject) => {\n const req = indexedDB.open(HANDLE_DB_NAME, 1);\n req.onupgradeneeded = () => {\n req.result.createObjectStore(HANDLE_STORE_NAME);\n };\n req.onsuccess = () => resolve(req.result);\n req.onerror = () => reject(req.error);\n });\n}\n\n/** Persist a FileSystemDirectoryHandle so it survives page reloads. */\nexport async function storeDirectoryHandle(\n workspaceId: string,\n handle: FileSystemDirectoryHandle,\n): Promise<void> {\n const db = await openHandleDB();\n return new Promise((resolve, reject) => {\n const tx = db.transaction(HANDLE_STORE_NAME, 'readwrite');\n tx.objectStore(HANDLE_STORE_NAME).put(handle, workspaceId);\n tx.oncomplete = () => {\n db.close();\n resolve();\n };\n tx.onerror = () => {\n db.close();\n reject(tx.error);\n };\n });\n}\n\n/** Retrieve a previously stored handle. Returns null if not found. */\nexport async function loadDirectoryHandle(\n workspaceId: string,\n): Promise<FileSystemDirectoryHandle | null> {\n const db = await openHandleDB();\n return new Promise((resolve, reject) => {\n const tx = db.transaction(HANDLE_STORE_NAME, 'readonly');\n const req = tx.objectStore(HANDLE_STORE_NAME).get(workspaceId);\n req.onsuccess = () => {\n db.close();\n resolve(req.result ?? null);\n };\n req.onerror = () => {\n db.close();\n reject(req.error);\n };\n });\n}\n\n/** Remove a stored handle (e.g. when deleting a workspace). */\nexport async function removeDirectoryHandle(workspaceId: string): Promise<void> {\n const db = await openHandleDB();\n return new Promise((resolve, reject) => {\n const tx = db.transaction(HANDLE_STORE_NAME, 'readwrite');\n tx.objectStore(HANDLE_STORE_NAME).delete(workspaceId);\n tx.oncomplete = () => {\n db.close();\n resolve();\n };\n tx.onerror = () => {\n db.close();\n reject(tx.error);\n };\n });\n}\n\n// ── Helpers ────────────────────────────────────────────────────────\n\nfunction normalisePath(p: string): string {\n return p.replace(/\\\\/g, '/').replace(/\\/+/g, '/').replace(/^\\//, '').replace(/\\/$/, '');\n}\n\n/**\n * Walk a chain of path segments to reach a FileSystemDirectoryHandle.\n * Returns null if any segment is missing.\n */\nasync function resolveDir(\n root: FileSystemDirectoryHandle,\n dirPath: string,\n): Promise<FileSystemDirectoryHandle | null> {\n if (!dirPath) return root;\n const parts = dirPath.split('/');\n let current = root;\n for (const part of parts) {\n try {\n current = await current.getDirectoryHandle(part);\n } catch {\n return null;\n }\n }\n return current;\n}\n\n/**\n * Walk path segments, creating directories as needed.\n */\nasync function resolveDirCreate(\n root: FileSystemDirectoryHandle,\n dirPath: string,\n): Promise<FileSystemDirectoryHandle> {\n if (!dirPath) return root;\n const parts = dirPath.split('/');\n let current = root;\n for (const part of parts) {\n current = await current.getDirectoryHandle(part, { create: true });\n }\n return current;\n}\n\nfunction parentDir(p: string): string {\n const idx = p.lastIndexOf('/');\n return idx === -1 ? '' : p.slice(0, idx);\n}\n\nfunction baseName(p: string): string {\n const idx = p.lastIndexOf('/');\n return idx === -1 ? p : p.slice(idx + 1);\n}\n\n// ── Implementation ─────────────────────────────────────────────────\n\nexport class NativeFileSystemProvider implements FileSystemProvider {\n readonly id: string;\n readonly label: string;\n\n private root: FileSystemDirectoryHandle;\n\n constructor(id: string, root: FileSystemDirectoryHandle) {\n this.id = id;\n this.label = root.name;\n this.root = root;\n }\n\n async readFile(path: string): Promise<string | null> {\n const p = normalisePath(path);\n const dir = await resolveDir(this.root, parentDir(p));\n if (!dir) return null;\n try {\n const fileHandle = await dir.getFileHandle(baseName(p));\n const file = await fileHandle.getFile();\n return file.text();\n } catch {\n return null;\n }\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n const p = normalisePath(path);\n const dir = await resolveDirCreate(this.root, parentDir(p));\n const fileHandle = await dir.getFileHandle(baseName(p), { create: true });\n const writable = await fileHandle.createWritable();\n await writable.write(content);\n await writable.close();\n }\n\n async delete(path: string): Promise<void> {\n const p = normalisePath(path);\n const parent = parentDir(p);\n const name = baseName(p);\n const dir = await resolveDir(this.root, parent);\n if (!dir) return;\n await dir.removeEntry(name, { recursive: true });\n }\n\n async rename(oldPath: string, newPath: string): Promise<void> {\n const op = normalisePath(oldPath);\n const np = normalisePath(newPath);\n\n // The File System Access API doesn't have a native rename.\n // Read → write → delete.\n const content = await this.readFile(op);\n if (content !== null) {\n await this.writeFile(np, content);\n await this.delete(op);\n return;\n }\n\n // Try binary\n const binary = await this.readBinary(op);\n if (binary !== null) {\n await this.writeBinary(np, binary);\n await this.delete(op);\n }\n }\n\n async readDirectory(path: string): Promise<FileSystemEntry[]> {\n const p = normalisePath(path);\n const dir = await resolveDir(this.root, p);\n if (!dir) return [];\n\n const entries: FileSystemEntry[] = [];\n for await (const [name, handle] of dir as unknown as AsyncIterable<\n [string, FileSystemHandle]\n >) {\n const entryPath = p ? `${p}/${name}` : name;\n if (handle.kind === 'directory') {\n entries.push({ kind: 'directory', name, path: entryPath });\n } else {\n entries.push({ kind: 'file', name, path: entryPath });\n }\n }\n\n // Sort: directories first, then alphabetical\n entries.sort((a, b) => {\n if (a.kind !== b.kind) return a.kind === 'directory' ? -1 : 1;\n return a.name.localeCompare(b.name);\n });\n\n return entries;\n }\n\n async exists(path: string): Promise<boolean> {\n const p = normalisePath(path);\n const parent = parentDir(p);\n const name = baseName(p);\n const dir = await resolveDir(this.root, parent);\n if (!dir) return false;\n\n try {\n await dir.getFileHandle(name);\n return true;\n } catch {\n try {\n await dir.getDirectoryHandle(name);\n return true;\n } catch {\n return false;\n }\n }\n }\n\n async createDirectory(path: string): Promise<void> {\n const p = normalisePath(path);\n await resolveDirCreate(this.root, p);\n }\n\n async stat(path: string): Promise<FileMeta | null> {\n const p = normalisePath(path);\n const dir = await resolveDir(this.root, parentDir(p));\n if (!dir) return null;\n\n try {\n const fileHandle = await dir.getFileHandle(baseName(p));\n const file = await fileHandle.getFile();\n return {\n name: file.name,\n path: p,\n size: file.size,\n lastModified: new Date(file.lastModified).toISOString(),\n };\n } catch {\n return null;\n }\n }\n\n async readBinary(path: string): Promise<ArrayBuffer | null> {\n const p = normalisePath(path);\n const dir = await resolveDir(this.root, parentDir(p));\n if (!dir) return null;\n try {\n const fileHandle = await dir.getFileHandle(baseName(p));\n const file = await fileHandle.getFile();\n return file.arrayBuffer();\n } catch {\n return null;\n }\n }\n\n async writeBinary(path: string, data: ArrayBuffer | Uint8Array): Promise<void> {\n const p = normalisePath(path);\n const dir = await resolveDirCreate(this.root, parentDir(p));\n const fileHandle = await dir.getFileHandle(baseName(p), { create: true });\n const writable = await fileHandle.createWritable();\n if (data instanceof ArrayBuffer) {\n await writable.write(data);\n } else {\n await writable.write(data.buffer as ArrayBuffer);\n }\n await writable.close();\n }\n}\n\n/**\n * Prompt the user to pick a local folder and return a NativeFileSystemProvider.\n * The directory handle is persisted in IndexedDB so it can be restored later.\n * Throws if the user cancels or the API is unsupported.\n */\nexport async function openNativeFolder(): Promise<NativeFileSystemProvider> {\n if (!isNativeFileSystemSupported()) {\n throw new Error('File System Access API is not supported in this browser');\n }\n\n const handle = await (\n globalThis as unknown as { showDirectoryPicker: () => Promise<FileSystemDirectoryHandle> }\n ).showDirectoryPicker();\n const id = `native-${handle.name}-${Date.now()}`;\n await storeDirectoryHandle(id, handle);\n return new NativeFileSystemProvider(id, handle);\n}\n\n/**\n * Restore a previously opened native folder from a persisted handle.\n * Re-requests read/write permission (browser will show a prompt).\n * Returns null if the handle is not found or permission is denied.\n */\nexport async function restoreNativeFolder(\n workspaceId: string,\n): Promise<NativeFileSystemProvider | null> {\n const handle = await loadDirectoryHandle(workspaceId);\n if (!handle) return null;\n\n // Verify/request permission\n const opts = { mode: 'readwrite' as const };\n const h = handle as FileSystemDirectoryHandle & {\n queryPermission(desc: { mode: string }): Promise<string>;\n requestPermission(desc: { mode: string }): Promise<string>;\n };\n if ((await h.queryPermission(opts)) === 'granted') {\n return new NativeFileSystemProvider(workspaceId, handle);\n }\n if ((await h.requestPermission(opts)) === 'granted') {\n return new NativeFileSystemProvider(workspaceId, handle);\n }\n\n return null;\n}\n","/**\n * ElectronFileSystemProvider — implements FileSystemProvider by delegating\n * to the Electron desktop host's fs IPC bridge. Every operation is scoped\n * to an absolute root path that the main process validates against a\n * whitelist of registered workspace roots.\n *\n * This file has no Electron dependency — it is a pure IPC client that\n * relies on the `docblocksHost` global installed by the preload script.\n */\n\nimport type { FileSystemProvider, FileSystemEntry, FileMeta } from './types.js';\nimport { maybeGetDocblocksHost } from '../host/index.js';\nimport type { DocblocksHostFsAPI } from '../host/types.js';\n\nexport { isElectronHost } from '../host/index.js';\n\nfunction getHostFs(): DocblocksHostFsAPI {\n const host = maybeGetDocblocksHost();\n if (!host) {\n throw new Error(\n 'ElectronFileSystemProvider: docblocksHost is not available — not running under Electron?',\n );\n }\n return host.fs;\n}\n\nexport class ElectronFileSystemProvider implements FileSystemProvider {\n readonly id: string;\n readonly label: string;\n\n private readonly rootPath: string;\n\n constructor(id: string, label: string, rootPath: string) {\n this.id = id;\n this.label = label;\n this.rootPath = rootPath;\n }\n\n /** Absolute path this provider is rooted at. */\n getRootPath(): string {\n return this.rootPath;\n }\n\n readFile(path: string): Promise<string | null> {\n return getHostFs().readFile(this.rootPath, path);\n }\n\n writeFile(path: string, content: string): Promise<void> {\n return getHostFs().writeFile(this.rootPath, path, content);\n }\n\n delete(path: string): Promise<void> {\n return getHostFs().delete(this.rootPath, path);\n }\n\n rename(oldPath: string, newPath: string): Promise<void> {\n return getHostFs().rename(this.rootPath, oldPath, newPath);\n }\n\n readDirectory(path: string): Promise<FileSystemEntry[]> {\n return getHostFs().readDirectory(this.rootPath, path);\n }\n\n exists(path: string): Promise<boolean> {\n return getHostFs().exists(this.rootPath, path);\n }\n\n createDirectory(path: string): Promise<void> {\n return getHostFs().createDirectory(this.rootPath, path);\n }\n\n stat(path: string): Promise<FileMeta | null> {\n return getHostFs().stat(this.rootPath, path);\n }\n\n readBinary(path: string): Promise<ArrayBuffer | null> {\n return getHostFs().readBinary(this.rootPath, path);\n }\n\n writeBinary(path: string, data: ArrayBuffer | Uint8Array): Promise<void> {\n return getHostFs().writeBinary(this.rootPath, path, data);\n }\n\n /** Subscribe to external change notifications under this root. */\n watch(onChange: (changedPath: string) => void): () => void {\n return getHostFs().watch(this.rootPath, onChange);\n }\n}\n"],"mappings":";;;;;AAWA,SAAS,0BAA0B;AAMnC,SAAS,cAAc,GAAmB;AACxC,SAAO,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,QAAQ,GAAG,EAAE,QAAQ,OAAO,EAAE,EAAE,QAAQ,OAAO,EAAE;AACxF;AAGA,SAAS,UAAU,GAAmB;AACpC,QAAM,MAAM,EAAE,YAAY,GAAG;AAC7B,SAAO,QAAQ,KAAK,KAAK,EAAE,MAAM,GAA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