@bendyline/docblocks 1.0.0 → 1.1.1

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 (54) hide show
  1. package/dist/{chunk-NSVTXALR.js → chunk-LORJUBON.js} +314 -25
  2. package/dist/chunk-LORJUBON.js.map +1 -0
  3. package/dist/chunk-ME76RUMR.js +23 -0
  4. package/dist/chunk-ME76RUMR.js.map +1 -0
  5. package/dist/filesystem/electron-provider.d.ts +32 -0
  6. package/dist/filesystem/electron-provider.d.ts.map +1 -0
  7. package/dist/filesystem/electron-provider.js +64 -0
  8. package/dist/filesystem/electron-provider.js.map +1 -0
  9. package/dist/filesystem/file-media-provider.d.ts +23 -0
  10. package/dist/filesystem/file-media-provider.d.ts.map +1 -0
  11. package/dist/filesystem/file-media-provider.js +85 -0
  12. package/dist/filesystem/file-media-provider.js.map +1 -0
  13. package/dist/filesystem/filesystem-content-container.d.ts +24 -0
  14. package/dist/filesystem/filesystem-content-container.d.ts.map +1 -0
  15. package/dist/filesystem/filesystem-content-container.js +116 -0
  16. package/dist/filesystem/filesystem-content-container.js.map +1 -0
  17. package/dist/filesystem/index.d.ts +3 -0
  18. package/dist/filesystem/index.d.ts.map +1 -1
  19. package/dist/filesystem/index.js +3 -0
  20. package/dist/filesystem/index.js.map +1 -1
  21. package/dist/filesystem/indexeddb-provider.d.ts.map +1 -1
  22. package/dist/filesystem/indexeddb-provider.js +60 -18
  23. package/dist/filesystem/indexeddb-provider.js.map +1 -1
  24. package/dist/filesystem/native-provider.d.ts +1 -0
  25. package/dist/filesystem/native-provider.d.ts.map +1 -1
  26. package/dist/filesystem/native-provider.js +40 -8
  27. package/dist/filesystem/native-provider.js.map +1 -1
  28. package/dist/host/index.d.ts +14 -0
  29. package/dist/host/index.d.ts.map +1 -0
  30. package/dist/host/index.js +28 -0
  31. package/dist/host/index.js.map +1 -0
  32. package/dist/host/types.d.ts +149 -0
  33. package/dist/host/types.d.ts.map +1 -0
  34. package/dist/host/types.js +10 -0
  35. package/dist/host/types.js.map +1 -0
  36. package/dist/index-Bunj8Kb_.d.ts +213 -0
  37. package/dist/index.d.ts +2 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +2 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/workspace/types.d.ts +16 -2
  42. package/dist/workspace/types.d.ts.map +1 -1
  43. package/package.json +7 -7
  44. package/src/filesystem/electron-provider.ts +88 -0
  45. package/src/filesystem/file-media-provider.ts +103 -0
  46. package/src/filesystem/filesystem-content-container.ts +126 -0
  47. package/src/filesystem/index.ts +4 -0
  48. package/src/filesystem/indexeddb-provider.ts +65 -19
  49. package/src/filesystem/native-provider.ts +41 -8
  50. package/src/host/index.ts +47 -0
  51. package/src/host/types.ts +153 -0
  52. package/src/index.ts +2 -1
  53. package/src/workspace/types.ts +16 -2
  54. package/dist/chunk-NSVTXALR.js.map +0 -1
@@ -1,3 +1,7 @@
1
+ import {
2
+ maybeGetDocBlocksHost
3
+ } from "./chunk-ME76RUMR.js";
4
+
1
5
  // src/filesystem/indexeddb-provider.ts
2
6
  import { LocalForageAdapter } from "@bendyline/squisq/storage";
3
7
  function normalisePath(p) {
@@ -103,6 +107,59 @@ var IndexedDBFileSystemProvider = class {
103
107
  async rename(oldPath, newPath) {
104
108
  const op = normalisePath(oldPath);
105
109
  const np = normalisePath(newPath);
110
+ if (op === np) return;
111
+ if (!op || !np) {
112
+ throw new Error("Cannot rename the filesystem root");
113
+ }
114
+ if (np.startsWith(op + "/")) {
115
+ throw new Error("Cannot move a directory into itself");
116
+ }
117
+ const dirs = await this.getDirs();
118
+ if (dirs.has(op)) {
119
+ const newParent2 = parentDir(np);
120
+ if (newParent2) {
121
+ await this.ensureDir(newParent2);
122
+ }
123
+ const allKeys = await this.store.keys();
124
+ const oldKeyPrefix = `fs:${op}/`;
125
+ const newKeyPrefix = `fs:${np}/`;
126
+ const metaSuffix = ":meta";
127
+ const keysToMove = allKeys.filter((k) => k.startsWith(oldKeyPrefix));
128
+ await Promise.all(
129
+ keysToMove.map(async (oldKey) => {
130
+ const newKey = newKeyPrefix + oldKey.slice(oldKeyPrefix.length);
131
+ if (oldKey.endsWith(metaSuffix)) {
132
+ const meta2 = await this.store.get(oldKey);
133
+ if (meta2) {
134
+ const newFilePath = newKey.slice(3, -metaSuffix.length);
135
+ await this.store.set(metaKey(newFilePath), {
136
+ ...meta2,
137
+ name: baseName(newFilePath),
138
+ path: newFilePath
139
+ });
140
+ }
141
+ } else {
142
+ const value = await this.store.get(oldKey);
143
+ if (value !== null) {
144
+ await this.store.set(newKey, value);
145
+ }
146
+ }
147
+ await this.store.remove(oldKey);
148
+ })
149
+ );
150
+ dirs.delete(op);
151
+ dirs.add(np);
152
+ const oldPrefix = op + "/";
153
+ const newPrefix = np + "/";
154
+ for (const d of [...dirs]) {
155
+ if (d.startsWith(oldPrefix)) {
156
+ dirs.delete(d);
157
+ dirs.add(newPrefix + d.slice(oldPrefix.length));
158
+ }
159
+ }
160
+ await this.saveDirs(dirs);
161
+ return;
162
+ }
106
163
  const content = await this.store.get(contentKey(op));
107
164
  const binary = await this.store.get(binaryKey(op));
108
165
  const meta = await this.store.get(metaKey(op));
@@ -113,9 +170,11 @@ var IndexedDBFileSystemProvider = class {
113
170
  await this.store.set(binaryKey(np), binary);
114
171
  }
115
172
  if (meta) {
116
- meta.name = baseName(np);
117
- meta.path = np;
118
- await this.store.set(metaKey(np), meta);
173
+ await this.store.set(metaKey(np), {
174
+ ...meta,
175
+ name: baseName(np),
176
+ path: np
177
+ });
119
178
  }
120
179
  const newParent = parentDir(np);
121
180
  if (newParent) {
@@ -124,20 +183,6 @@ var IndexedDBFileSystemProvider = class {
124
183
  await this.store.remove(contentKey(op));
125
184
  await this.store.remove(binaryKey(op));
126
185
  await this.store.remove(metaKey(op));
127
- const dirs = await this.getDirs();
128
- if (dirs.has(op)) {
129
- dirs.delete(op);
130
- dirs.add(np);
131
- const oldPrefix = op + "/";
132
- const newPrefix = np + "/";
133
- for (const d of [...dirs]) {
134
- if (d.startsWith(oldPrefix)) {
135
- dirs.delete(d);
136
- dirs.add(newPrefix + d.slice(oldPrefix.length));
137
- }
138
- }
139
- await this.saveDirs(dirs);
140
- }
141
186
  }
142
187
  async readDirectory(path) {
143
188
  const p = normalisePath(path);
@@ -296,6 +341,164 @@ var IndexedDBContentContainer = class {
296
341
  }
297
342
  };
298
343
 
344
+ // src/filesystem/filesystem-content-container.ts
345
+ import { findDocumentPath as findDocumentPath2 } from "@bendyline/squisq/storage";
346
+ var EXTENSION_MIME_MAP2 = {
347
+ ".md": "text/markdown",
348
+ ".txt": "text/plain",
349
+ ".json": "application/json",
350
+ ".jpg": "image/jpeg",
351
+ ".jpeg": "image/jpeg",
352
+ ".png": "image/png",
353
+ ".gif": "image/gif",
354
+ ".svg": "image/svg+xml",
355
+ ".webp": "image/webp",
356
+ ".avif": "image/avif",
357
+ ".mp4": "video/mp4",
358
+ ".webm": "video/webm",
359
+ ".mp3": "audio/mpeg",
360
+ ".wav": "audio/wav",
361
+ ".ogg": "audio/ogg"
362
+ };
363
+ function guessMimeType2(path) {
364
+ const dot = path.lastIndexOf(".");
365
+ if (dot === -1) return "application/octet-stream";
366
+ const ext = path.slice(dot).toLowerCase();
367
+ return EXTENSION_MIME_MAP2[ext] ?? "application/octet-stream";
368
+ }
369
+ function joinPrefix(prefix, p) {
370
+ const clean = p.replace(/^\/+/, "");
371
+ return prefix.replace(/\/+$/, "") + "/" + clean;
372
+ }
373
+ var FileSystemContentContainer = class {
374
+ constructor(provider, prefix = ".docblocks/media") {
375
+ this.provider = provider;
376
+ this.prefix = prefix.replace(/^\/+/, "").replace(/\/+$/, "");
377
+ }
378
+ async readFile(path) {
379
+ const full = joinPrefix(this.prefix, path);
380
+ const binary = await this.provider.readBinary(full);
381
+ if (binary) return binary;
382
+ const text = await this.provider.readFile(full);
383
+ if (text === null) return null;
384
+ return new TextEncoder().encode(text).buffer;
385
+ }
386
+ async writeFile(path, data, _mimeType) {
387
+ await this.provider.writeBinary(joinPrefix(this.prefix, path), data);
388
+ }
389
+ async removeFile(path) {
390
+ await this.provider.delete(joinPrefix(this.prefix, path));
391
+ }
392
+ async listFiles(prefix) {
393
+ const entries = [];
394
+ const walk = async (dir) => {
395
+ let children;
396
+ try {
397
+ children = await this.provider.readDirectory(dir);
398
+ } catch {
399
+ return;
400
+ }
401
+ for (const child of children) {
402
+ if (child.kind === "directory") {
403
+ await walk(child.path);
404
+ } else {
405
+ const rel = child.path.replace(new RegExp("^/?" + this.prefix + "/?"), "");
406
+ if (prefix && !rel.startsWith(prefix)) continue;
407
+ const meta = await this.provider.stat(child.path);
408
+ entries.push({
409
+ path: rel,
410
+ mimeType: guessMimeType2(rel),
411
+ size: meta?.size ?? 0
412
+ });
413
+ }
414
+ }
415
+ };
416
+ await walk("/" + this.prefix);
417
+ return entries;
418
+ }
419
+ async exists(path) {
420
+ return this.provider.exists(joinPrefix(this.prefix, path));
421
+ }
422
+ async getDocumentPath() {
423
+ return findDocumentPath2(await this.listFiles());
424
+ }
425
+ async readDocument() {
426
+ const docPath = await this.getDocumentPath();
427
+ if (!docPath) return null;
428
+ const data = await this.readFile(docPath);
429
+ if (!data) return null;
430
+ return new TextDecoder().decode(data);
431
+ }
432
+ async writeDocument(markdown, filename) {
433
+ const name = filename ?? "index.md";
434
+ const data = new TextEncoder().encode(markdown);
435
+ await this.writeFile(name, data, "text/markdown");
436
+ }
437
+ };
438
+
439
+ // src/filesystem/file-media-provider.ts
440
+ function stripExt(name) {
441
+ return name.replace(/\.[^.]+$/, "");
442
+ }
443
+ function createFileMediaProvider(container, markdownBasename) {
444
+ const folder = stripExt(markdownBasename) + "_files";
445
+ const prefix = folder + "/";
446
+ const blobUrlCache = /* @__PURE__ */ new Map();
447
+ function toKey(ref) {
448
+ const clean = ref.replace(/^\/+/, "");
449
+ return clean.startsWith(prefix) ? clean : prefix + clean;
450
+ }
451
+ return {
452
+ async resolveUrl(ref) {
453
+ const key = toKey(ref);
454
+ const cached = blobUrlCache.get(key);
455
+ if (cached) return cached;
456
+ const data = await container.readFile(key);
457
+ if (!data) return ref;
458
+ const entries = await container.listFiles();
459
+ const entry = entries.find((e) => e.path === key);
460
+ const mimeType = entry?.mimeType ?? "application/octet-stream";
461
+ const url = URL.createObjectURL(new Blob([data], { type: mimeType }));
462
+ blobUrlCache.set(key, url);
463
+ return url;
464
+ },
465
+ async listMedia() {
466
+ const entries = await container.listFiles(prefix);
467
+ return entries.filter((e) => !e.path.toLowerCase().endsWith(".md")).map((e) => ({
468
+ name: e.path,
469
+ mimeType: e.mimeType,
470
+ size: e.size
471
+ }));
472
+ },
473
+ async addMedia(name, data, mimeType) {
474
+ const key = toKey(name);
475
+ const cached = blobUrlCache.get(key);
476
+ if (cached) {
477
+ URL.revokeObjectURL(cached);
478
+ blobUrlCache.delete(key);
479
+ }
480
+ const buffer = data instanceof Blob ? new Uint8Array(await data.arrayBuffer()) : data;
481
+ await container.writeFile(key, buffer, mimeType);
482
+ return key;
483
+ },
484
+ async removeMedia(ref) {
485
+ const key = toKey(ref);
486
+ const cached = blobUrlCache.get(key);
487
+ if (cached) {
488
+ URL.revokeObjectURL(cached);
489
+ blobUrlCache.delete(key);
490
+ }
491
+ await container.removeFile(key);
492
+ },
493
+ dispose() {
494
+ for (const url of blobUrlCache.values()) {
495
+ URL.revokeObjectURL(url);
496
+ }
497
+ blobUrlCache.clear();
498
+ }
499
+ };
500
+ }
501
+
299
502
  // src/filesystem/native-provider.ts
300
503
  function isNativeFileSystemSupported() {
301
504
  return typeof globalThis !== "undefined" && "showDirectoryPicker" in globalThis;
@@ -396,6 +599,23 @@ var NativeFileSystemProvider = class {
396
599
  this.label = root.name;
397
600
  this.root = root;
398
601
  }
602
+ async copyDirectory(oldDirPath, newDirPath) {
603
+ const source = await resolveDir(this.root, oldDirPath);
604
+ if (!source) return false;
605
+ await resolveDirCreate(this.root, newDirPath);
606
+ for await (const [name, handle] of source) {
607
+ const oldChild = oldDirPath ? `${oldDirPath}/${name}` : name;
608
+ const newChild = newDirPath ? `${newDirPath}/${name}` : name;
609
+ if (handle.kind === "directory") {
610
+ await this.copyDirectory(oldChild, newChild);
611
+ } else {
612
+ const fileHandle = await source.getFileHandle(name);
613
+ const file = await fileHandle.getFile();
614
+ await this.writeBinary(newChild, await file.arrayBuffer());
615
+ }
616
+ }
617
+ return true;
618
+ }
399
619
  async readFile(path) {
400
620
  const p = normalisePath2(path);
401
621
  const dir = await resolveDir(this.root, parentDir2(p));
@@ -427,15 +647,25 @@ var NativeFileSystemProvider = class {
427
647
  async rename(oldPath, newPath) {
428
648
  const op = normalisePath2(oldPath);
429
649
  const np = normalisePath2(newPath);
430
- const content = await this.readFile(op);
431
- if (content !== null) {
432
- await this.writeFile(np, content);
650
+ if (op === np) return;
651
+ if (!op || !np) {
652
+ throw new Error("Cannot rename the filesystem root");
653
+ }
654
+ if (np.startsWith(op + "/")) {
655
+ throw new Error("Cannot move a directory into itself");
656
+ }
657
+ const oldParent = await resolveDir(this.root, parentDir2(op));
658
+ if (!oldParent) return;
659
+ try {
660
+ const fileHandle = await oldParent.getFileHandle(baseName2(op));
661
+ const file = await fileHandle.getFile();
662
+ await this.writeBinary(np, await file.arrayBuffer());
433
663
  await this.delete(op);
434
664
  return;
665
+ } catch {
435
666
  }
436
- const binary = await this.readBinary(op);
437
- if (binary !== null) {
438
- await this.writeBinary(np, binary);
667
+ const copied = await this.copyDirectory(op, np);
668
+ if (copied) {
439
669
  await this.delete(op);
440
670
  }
441
671
  }
@@ -545,15 +775,74 @@ async function restoreNativeFolder(workspaceId) {
545
775
  return null;
546
776
  }
547
777
 
778
+ // src/filesystem/electron-provider.ts
779
+ function getHostFs() {
780
+ const host = maybeGetDocBlocksHost();
781
+ if (!host) {
782
+ throw new Error(
783
+ "ElectronFileSystemProvider: docBlocksHost is not available \u2014 not running under Electron?"
784
+ );
785
+ }
786
+ return host.fs;
787
+ }
788
+ var ElectronFileSystemProvider = class {
789
+ constructor(id, label, rootPath) {
790
+ this.id = id;
791
+ this.label = label;
792
+ this.rootPath = rootPath;
793
+ }
794
+ /** Absolute path this provider is rooted at. */
795
+ getRootPath() {
796
+ return this.rootPath;
797
+ }
798
+ readFile(path) {
799
+ return getHostFs().readFile(this.rootPath, path);
800
+ }
801
+ writeFile(path, content) {
802
+ return getHostFs().writeFile(this.rootPath, path, content);
803
+ }
804
+ delete(path) {
805
+ return getHostFs().delete(this.rootPath, path);
806
+ }
807
+ rename(oldPath, newPath) {
808
+ return getHostFs().rename(this.rootPath, oldPath, newPath);
809
+ }
810
+ readDirectory(path) {
811
+ return getHostFs().readDirectory(this.rootPath, path);
812
+ }
813
+ exists(path) {
814
+ return getHostFs().exists(this.rootPath, path);
815
+ }
816
+ createDirectory(path) {
817
+ return getHostFs().createDirectory(this.rootPath, path);
818
+ }
819
+ stat(path) {
820
+ return getHostFs().stat(this.rootPath, path);
821
+ }
822
+ readBinary(path) {
823
+ return getHostFs().readBinary(this.rootPath, path);
824
+ }
825
+ writeBinary(path, data) {
826
+ return getHostFs().writeBinary(this.rootPath, path, data);
827
+ }
828
+ /** Subscribe to external change notifications under this root. */
829
+ watch(onChange) {
830
+ return getHostFs().watch(this.rootPath, onChange);
831
+ }
832
+ };
833
+
548
834
  export {
549
835
  IndexedDBFileSystemProvider,
550
836
  IndexedDBContentContainer,
837
+ FileSystemContentContainer,
838
+ createFileMediaProvider,
551
839
  isNativeFileSystemSupported,
552
840
  storeDirectoryHandle,
553
841
  loadDirectoryHandle,
554
842
  removeDirectoryHandle,
555
843
  NativeFileSystemProvider,
556
844
  openNativeFolder,
557
- restoreNativeFolder
845
+ restoreNativeFolder,
846
+ ElectronFileSystemProvider
558
847
  };
559
- //# sourceMappingURL=chunk-NSVTXALR.js.map
848
+ //# sourceMappingURL=chunk-LORJUBON.js.map
@@ -0,0 +1 @@
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 if (op === np) return;\n if (!op || !np) {\n throw new Error('Cannot rename the filesystem root');\n }\n if (np.startsWith(op + '/')) {\n throw new Error('Cannot move a directory into itself');\n }\n\n const dirs = await this.getDirs();\n\n // Handle directory rename by moving every tracked child directory and\n // every file record keyed under the old directory prefix.\n if (dirs.has(op)) {\n const newParent = parentDir(np);\n if (newParent) {\n await this.ensureDir(newParent);\n }\n\n const allKeys = await this.store.keys();\n const oldKeyPrefix = `fs:${op}/`;\n const newKeyPrefix = `fs:${np}/`;\n const metaSuffix = ':meta';\n const keysToMove = allKeys.filter((k) => k.startsWith(oldKeyPrefix));\n\n await Promise.all(\n keysToMove.map(async (oldKey) => {\n const newKey = newKeyPrefix + oldKey.slice(oldKeyPrefix.length);\n if (oldKey.endsWith(metaSuffix)) {\n const meta = await this.store.get<FileMeta>(oldKey);\n if (meta) {\n const newFilePath = newKey.slice(3, -metaSuffix.length);\n await this.store.set(metaKey(newFilePath), {\n ...meta,\n name: baseName(newFilePath),\n path: newFilePath,\n });\n }\n } else {\n const value = await this.store.get<unknown>(oldKey);\n if (value !== null) {\n await this.store.set(newKey, value);\n }\n }\n await this.store.remove(oldKey);\n }),\n );\n\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 return;\n }\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 await this.store.set(metaKey(np), {\n ...meta,\n name: baseName(np),\n path: np,\n });\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\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 const full = joinPrefix(this.prefix, path);\n const binary = await this.provider.readBinary(full);\n if (binary) return binary;\n // IndexedDB-backed workspaces store text via `writeFile(string)` and\n // binary via `writeBinary(ArrayBuffer)` under separate keys, so a\n // markdown file written through the text API is invisible to\n // `readBinary`. Fall back to text-then-UTF-8 so consumers like the\n // recursive HTML export can resolve sibling `.md` links uniformly\n // across browser and native workspaces.\n const text = await this.provider.readFile(full);\n if (text === null) return null;\n return new TextEncoder().encode(text).buffer as ArrayBuffer;\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 private async copyDirectory(oldDirPath: string, newDirPath: string): Promise<boolean> {\n const source = await resolveDir(this.root, oldDirPath);\n if (!source) return false;\n await resolveDirCreate(this.root, newDirPath);\n\n for await (const [name, handle] of source as unknown as AsyncIterable<\n [string, FileSystemHandle]\n >) {\n const oldChild = oldDirPath ? `${oldDirPath}/${name}` : name;\n const newChild = newDirPath ? `${newDirPath}/${name}` : name;\n if (handle.kind === 'directory') {\n await this.copyDirectory(oldChild, newChild);\n } else {\n const fileHandle = await source.getFileHandle(name);\n const file = await fileHandle.getFile();\n await this.writeBinary(newChild, await file.arrayBuffer());\n }\n }\n\n return true;\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 if (op === np) return;\n if (!op || !np) {\n throw new Error('Cannot rename the filesystem root');\n }\n if (np.startsWith(op + '/')) {\n throw new Error('Cannot move a directory into itself');\n }\n\n // The File System Access API doesn't have a native rename.\n // Copy → delete.\n const oldParent = await resolveDir(this.root, parentDir(op));\n if (!oldParent) return;\n\n try {\n const fileHandle = await oldParent.getFileHandle(baseName(op));\n const file = await fileHandle.getFile();\n await this.writeBinary(np, await file.arrayBuffer());\n await this.delete(op);\n return;\n } catch {\n // Not a file; try directory below.\n }\n\n const copied = await this.copyDirectory(op, np);\n if (copied) {\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,GAAG,GAAG;AACzC;AAGA,SAAS,SAAS,GAAmB;AACnC,QAAM,MAAM,EAAE,YAAY,GAAG;AAC7B,SAAO,QAAQ,KAAK,IAAI,EAAE,MAAM,MAAM,CAAC;AACzC;AAIA,SAAS,WAAW,MAAsB;AACxC,SAAO,MAAM,IAAI;AACnB;AAEA,SAAS,UAAU,MAAsB;AACvC,SAAO,MAAM,IAAI;AACnB;AAEA,SAAS,QAAQ,MAAsB;AACrC,SAAO,MAAM,IAA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gBAAgB,MAA6B;AAC3C,WAAO,UAAU,EAAE,gBAAgB,KAAK,UAAU,IAAI;AAAA,EACxD;AAAA,EAEA,KAAK,MAAwC;AAC3C,WAAO,UAAU,EAAE,KAAK,KAAK,UAAU,IAAI;AAAA,EAC7C;AAAA,EAEA,WAAW,MAA2C;AACpD,WAAO,UAAU,EAAE,WAAW,KAAK,UAAU,IAAI;AAAA,EACnD;AAAA,EAEA,YAAY,MAAc,MAA+C;AACvE,WAAO,UAAU,EAAE,YAAY,KAAK,UAAU,MAAM,IAAI;AAAA,EAC1D;AAAA;AAAA,EAGA,MAAM,UAAqD;AACzD,WAAO,UAAU,EAAE,MAAM,KAAK,UAAU,QAAQ;AAAA,EAClD;AACF;","names":["newParent","meta","findDocumentPath","EXTENSION_MIME_MAP","guessMimeType","normalisePath","parentDir","baseName"]}
@@ -0,0 +1,23 @@
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-ME76RUMR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/host/index.ts"],"sourcesContent":["/**\n * Host bridge — shared types + runtime access for the Electron desktop\n * host. The renderer calls `getDocBlocksHost()` to reach the preload\n * contextBridge; `isElectronHost()` gates desktop-only UI branches.\n */\n\nexport type {\n DocBlocksHostAPI,\n DocBlocksHostFsAPI,\n DocBlocksHostWorkspacesAPI,\n DocBlocksHostShellAPI,\n DocBlocksHostFfmpegAPI,\n DocBlocksHostUpdaterAPI,\n ElectronWorkspaceInfo,\n HostEnvironment,\n MenuCommand,\n OpenRequest,\n UpdaterStatus,\n} from './types.js';\n\nimport type { DocBlocksHostAPI } from './types.js';\n\n/** True when running inside the Electron desktop shell. */\nexport function isElectronHost(): boolean {\n if (typeof globalThis === 'undefined') return false;\n const host = (globalThis as { docBlocksHost?: unknown }).docBlocksHost;\n return (\n typeof host === 'object' &&\n host !== null &&\n typeof (host as { fs?: unknown }).fs === 'object' &&\n (host as { fs?: unknown }).fs !== null\n );\n}\n\n/** Return the host API, or throw if not running under Electron. */\nexport function getDocBlocksHost(): DocBlocksHostAPI {\n const host = (globalThis as { docBlocksHost?: DocBlocksHostAPI }).docBlocksHost;\n if (!host) {\n throw new Error('docBlocksHost is not available — not running under Electron?');\n }\n return host;\n}\n\n/** Return the host API, or null if not running under Electron. */\nexport function maybeGetDocBlocksHost(): DocBlocksHostAPI | null {\n return (globalThis as { docBlocksHost?: DocBlocksHostAPI }).docBlocksHost ?? null;\n}\n"],"mappings":";AAuBO,SAAS,iBAA0B;AACxC,MAAI,OAAO,eAAe,YAAa,QAAO;AAC9C,QAAM,OAAQ,WAA2C;AACzD,SACE,OAAO,SAAS,YAChB,SAAS,QACT,OAAQ,KAA0B,OAAO,YACxC,KAA0B,OAAO;AAEtC;AAGO,SAAS,mBAAqC;AACnD,QAAM,OAAQ,WAAoD;AAClE,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,mEAA8D;AAAA,EAChF;AACA,SAAO;AACT;AAGO,SAAS,wBAAiD;AAC/D,SAAQ,WAAoD,iBAAiB;AAC/E;","names":[]}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * ElectronFileSystemProvider — implements FileSystemProvider by delegating
3
+ * to the Electron desktop host's fs IPC bridge. Every operation is scoped
4
+ * to an absolute root path that the main process validates against a
5
+ * whitelist of registered workspace roots.
6
+ *
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.
9
+ */
10
+ import type { FileSystemProvider, FileSystemEntry, FileMeta } from './types.js';
11
+ export { isElectronHost } from '../host/index.js';
12
+ export declare class ElectronFileSystemProvider implements FileSystemProvider {
13
+ readonly id: string;
14
+ readonly label: string;
15
+ private readonly rootPath;
16
+ constructor(id: string, label: string, rootPath: string);
17
+ /** Absolute path this provider is rooted at. */
18
+ getRootPath(): string;
19
+ readFile(path: string): Promise<string | null>;
20
+ writeFile(path: string, content: string): Promise<void>;
21
+ delete(path: string): Promise<void>;
22
+ rename(oldPath: string, newPath: string): Promise<void>;
23
+ readDirectory(path: string): Promise<FileSystemEntry[]>;
24
+ exists(path: string): Promise<boolean>;
25
+ createDirectory(path: string): Promise<void>;
26
+ stat(path: string): Promise<FileMeta | null>;
27
+ readBinary(path: string): Promise<ArrayBuffer | null>;
28
+ writeBinary(path: string, data: ArrayBuffer | Uint8Array): Promise<void>;
29
+ /** Subscribe to external change notifications under this root. */
30
+ watch(onChange: (changedPath: string) => void): () => void;
31
+ }
32
+ //# sourceMappingURL=electron-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"electron-provider.d.ts","sourceRoot":"","sources":["../../src/filesystem/electron-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAIhF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAYlD,qBAAa,0BAA2B,YAAW,kBAAkB;IACnE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAMvD,gDAAgD;IAChD,WAAW,IAAI,MAAM;IAIrB,Q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