@bendyline/docblocks 1.1.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/README.md +76 -11
  2. package/dist/chunk-2D7Y4IR3.js +1293 -0
  3. package/dist/chunk-2D7Y4IR3.js.map +1 -0
  4. package/dist/chunk-5MYAICRE.js +957 -0
  5. package/dist/chunk-5MYAICRE.js.map +1 -0
  6. package/dist/chunk-75UUF6C4.js +802 -0
  7. package/dist/chunk-75UUF6C4.js.map +1 -0
  8. package/dist/chunk-AEHCVWU5.js +25 -0
  9. package/dist/chunk-AEHCVWU5.js.map +1 -0
  10. package/dist/chunk-AYZ4HN5M.js +20 -0
  11. package/dist/chunk-AYZ4HN5M.js.map +1 -0
  12. package/dist/chunk-EGNDADXB.js +111 -0
  13. package/dist/chunk-EGNDADXB.js.map +1 -0
  14. package/dist/chunk-EZKJZUNJ.js +13 -0
  15. package/dist/chunk-EZKJZUNJ.js.map +1 -0
  16. package/dist/chunk-FNW556FN.js +75 -0
  17. package/dist/chunk-FNW556FN.js.map +1 -0
  18. package/dist/chunk-GCPBEMMH.js +563 -0
  19. package/dist/chunk-GCPBEMMH.js.map +1 -0
  20. package/dist/chunk-J32GU3F3.js +1664 -0
  21. package/dist/chunk-J32GU3F3.js.map +1 -0
  22. package/dist/chunk-PGR7LK6D.js +1062 -0
  23. package/dist/chunk-PGR7LK6D.js.map +1 -0
  24. package/dist/chunk-RQJRQF46.js +787 -0
  25. package/dist/chunk-RQJRQF46.js.map +1 -0
  26. package/dist/{chunk-ME76RUMR.js → chunk-RVQHY3XU.js} +15 -1
  27. package/dist/chunk-RVQHY3XU.js.map +1 -0
  28. package/dist/chunk-SI2LU2RP.js +224 -0
  29. package/dist/chunk-SI2LU2RP.js.map +1 -0
  30. package/dist/chunk-W5UUUII5.js +142 -0
  31. package/dist/chunk-W5UUUII5.js.map +1 -0
  32. package/dist/document/document-session.d.ts +127 -0
  33. package/dist/document/document-session.d.ts.map +1 -0
  34. package/dist/document/document-session.js +749 -0
  35. package/dist/document/document-session.js.map +1 -0
  36. package/dist/document/filesystem-target.d.ts +17 -0
  37. package/dist/document/filesystem-target.d.ts.map +1 -0
  38. package/dist/document/filesystem-target.js +70 -0
  39. package/dist/document/filesystem-target.js.map +1 -0
  40. package/dist/document/index.d.ts +6 -0
  41. package/dist/document/index.d.ts.map +1 -0
  42. package/dist/document/index.js +4 -0
  43. package/dist/document/index.js.map +1 -0
  44. package/dist/document/recovery-journal.d.ts +125 -0
  45. package/dist/document/recovery-journal.d.ts.map +1 -0
  46. package/dist/document/recovery-journal.js +385 -0
  47. package/dist/document/recovery-journal.js.map +1 -0
  48. package/dist/document/types.d.ts +89 -0
  49. package/dist/document/types.d.ts.map +1 -0
  50. package/dist/document/types.js +9 -0
  51. package/dist/document/types.js.map +1 -0
  52. package/dist/filesystem/commit-lock.d.ts +3 -0
  53. package/dist/filesystem/commit-lock.d.ts.map +1 -0
  54. package/dist/filesystem/commit-lock.js +20 -0
  55. package/dist/filesystem/commit-lock.js.map +1 -0
  56. package/dist/filesystem/dbk-workspace.d.ts +34 -0
  57. package/dist/filesystem/dbk-workspace.d.ts.map +1 -0
  58. package/dist/filesystem/dbk-workspace.js +85 -0
  59. package/dist/filesystem/dbk-workspace.js.map +1 -0
  60. package/dist/filesystem/electron-provider-v2.d.ts +36 -0
  61. package/dist/filesystem/electron-provider-v2.d.ts.map +1 -0
  62. package/dist/filesystem/electron-provider-v2.js +503 -0
  63. package/dist/filesystem/electron-provider-v2.js.map +1 -0
  64. package/dist/filesystem/electron-provider.d.ts +6 -3
  65. package/dist/filesystem/electron-provider.d.ts.map +1 -1
  66. package/dist/filesystem/electron-provider.js +18 -13
  67. package/dist/filesystem/electron-provider.js.map +1 -1
  68. package/dist/filesystem/electron.d.ts +4 -0
  69. package/dist/filesystem/electron.d.ts.map +1 -0
  70. package/dist/filesystem/electron.js +4 -0
  71. package/dist/filesystem/electron.js.map +1 -0
  72. package/dist/filesystem/filesystem-content-container.d.ts +1 -1
  73. package/dist/filesystem/filesystem-content-container.d.ts.map +1 -1
  74. package/dist/filesystem/filesystem-content-container.js +50 -13
  75. package/dist/filesystem/filesystem-content-container.js.map +1 -1
  76. package/dist/filesystem/fs-error.d.ts +46 -0
  77. package/dist/filesystem/fs-error.d.ts.map +1 -0
  78. package/dist/filesystem/fs-error.js +170 -0
  79. package/dist/filesystem/fs-error.js.map +1 -0
  80. package/dist/filesystem/index.d.ts +15 -1
  81. package/dist/filesystem/index.d.ts.map +1 -1
  82. package/dist/filesystem/index.js +13 -0
  83. package/dist/filesystem/index.js.map +1 -1
  84. package/dist/filesystem/indexeddb-content-container.d.ts +3 -1
  85. package/dist/filesystem/indexeddb-content-container.d.ts.map +1 -1
  86. package/dist/filesystem/indexeddb-content-container.js +18 -11
  87. package/dist/filesystem/indexeddb-content-container.js.map +1 -1
  88. package/dist/filesystem/indexeddb-provider-v2.d.ts +96 -0
  89. package/dist/filesystem/indexeddb-provider-v2.d.ts.map +1 -0
  90. package/dist/filesystem/indexeddb-provider-v2.js +1241 -0
  91. package/dist/filesystem/indexeddb-provider-v2.js.map +1 -0
  92. package/dist/filesystem/indexeddb-provider.d.ts +21 -14
  93. package/dist/filesystem/indexeddb-provider.d.ts.map +1 -1
  94. package/dist/filesystem/indexeddb-provider.js +111 -261
  95. package/dist/filesystem/indexeddb-provider.js.map +1 -1
  96. package/dist/filesystem/indexeddb-store.d.ts +34 -0
  97. package/dist/filesystem/indexeddb-store.d.ts.map +1 -0
  98. package/dist/filesystem/indexeddb-store.js +165 -0
  99. package/dist/filesystem/indexeddb-store.js.map +1 -0
  100. package/dist/filesystem/indexeddb.d.ts +5 -0
  101. package/dist/filesystem/indexeddb.d.ts.map +1 -0
  102. package/dist/filesystem/indexeddb.js +5 -0
  103. package/dist/filesystem/indexeddb.js.map +1 -0
  104. package/dist/filesystem/legacy-v2-adapter.d.ts +62 -0
  105. package/dist/filesystem/legacy-v2-adapter.d.ts.map +1 -0
  106. package/dist/filesystem/legacy-v2-adapter.js +499 -0
  107. package/dist/filesystem/legacy-v2-adapter.js.map +1 -0
  108. package/dist/filesystem/memory-provider-v2.d.ts +92 -0
  109. package/dist/filesystem/memory-provider-v2.d.ts.map +1 -0
  110. package/dist/filesystem/memory-provider-v2.js +615 -0
  111. package/dist/filesystem/memory-provider-v2.js.map +1 -0
  112. package/dist/filesystem/memory-provider.d.ts +54 -0
  113. package/dist/filesystem/memory-provider.d.ts.map +1 -0
  114. package/dist/filesystem/memory-provider.js +132 -0
  115. package/dist/filesystem/memory-provider.js.map +1 -0
  116. package/dist/filesystem/memory.d.ts +4 -0
  117. package/dist/filesystem/memory.d.ts.map +1 -0
  118. package/dist/filesystem/memory.js +4 -0
  119. package/dist/filesystem/memory.js.map +1 -0
  120. package/dist/filesystem/move-entry.d.ts +9 -0
  121. package/dist/filesystem/move-entry.d.ts.map +1 -0
  122. package/dist/filesystem/move-entry.js +103 -0
  123. package/dist/filesystem/move-entry.js.map +1 -0
  124. package/dist/filesystem/move-error.d.ts +53 -0
  125. package/dist/filesystem/move-error.d.ts.map +1 -0
  126. package/dist/filesystem/move-error.js +99 -0
  127. package/dist/filesystem/move-error.js.map +1 -0
  128. package/dist/filesystem/native-provider-v2.d.ts +75 -0
  129. package/dist/filesystem/native-provider-v2.d.ts.map +1 -0
  130. package/dist/filesystem/native-provider-v2.js +849 -0
  131. package/dist/filesystem/native-provider-v2.js.map +1 -0
  132. package/dist/filesystem/native-provider.d.ts +9 -1
  133. package/dist/filesystem/native-provider.d.ts.map +1 -1
  134. package/dist/filesystem/native-provider.js +172 -37
  135. package/dist/filesystem/native-provider.js.map +1 -1
  136. package/dist/filesystem/native.d.ts +4 -0
  137. package/dist/filesystem/native.d.ts.map +1 -0
  138. package/dist/filesystem/native.js +4 -0
  139. package/dist/filesystem/native.js.map +1 -0
  140. package/dist/filesystem/types.d.ts +37 -4
  141. package/dist/filesystem/types.d.ts.map +1 -1
  142. package/dist/filesystem/types.js +11 -3
  143. package/dist/filesystem/types.js.map +1 -1
  144. package/dist/filesystem/v2.d.ts +172 -0
  145. package/dist/filesystem/v2.d.ts.map +1 -0
  146. package/dist/filesystem/v2.js +16 -0
  147. package/dist/filesystem/v2.js.map +1 -0
  148. package/dist/filesystem/workspace-path.d.ts +21 -0
  149. package/dist/filesystem/workspace-path.d.ts.map +1 -0
  150. package/dist/filesystem/workspace-path.js +80 -0
  151. package/dist/filesystem/workspace-path.js.map +1 -0
  152. package/dist/host/filesystem-v2.d.ts +45 -0
  153. package/dist/host/filesystem-v2.d.ts.map +1 -0
  154. package/dist/host/filesystem-v2.js +13 -0
  155. package/dist/host/filesystem-v2.js.map +1 -0
  156. package/dist/host/git.d.ts +200 -0
  157. package/dist/host/git.d.ts.map +1 -0
  158. package/dist/host/git.js +15 -0
  159. package/dist/host/git.js.map +1 -0
  160. package/dist/host/index.d.ts +4 -1
  161. package/dist/host/index.d.ts.map +1 -1
  162. package/dist/host/index.js +2 -0
  163. package/dist/host/index.js.map +1 -1
  164. package/dist/host/types.d.ts +114 -31
  165. package/dist/host/types.d.ts.map +1 -1
  166. package/dist/host/wire-policy.d.ts +22 -0
  167. package/dist/host/wire-policy.d.ts.map +1 -0
  168. package/dist/host/wire-policy.js +92 -0
  169. package/dist/host/wire-policy.js.map +1 -0
  170. package/dist/index.d.ts +2 -1
  171. package/dist/index.d.ts.map +1 -1
  172. package/dist/index.js +2 -1
  173. package/dist/index.js.map +1 -1
  174. package/dist/mcp/index.d.ts +4 -0
  175. package/dist/mcp/index.d.ts.map +1 -0
  176. package/dist/mcp/index.js +4 -0
  177. package/dist/mcp/index.js.map +1 -0
  178. package/dist/mcp/types.d.ts +466 -0
  179. package/dist/mcp/types.d.ts.map +1 -0
  180. package/dist/mcp/types.js +25 -0
  181. package/dist/mcp/types.js.map +1 -0
  182. package/dist/mcp/wire.d.ts +29 -0
  183. package/dist/mcp/wire.d.ts.map +1 -0
  184. package/dist/mcp/wire.js +1046 -0
  185. package/dist/mcp/wire.js.map +1 -0
  186. package/dist/mcp/zod.d.ts +5763 -0
  187. package/dist/mcp/zod.d.ts.map +1 -0
  188. package/dist/mcp/zod.js +908 -0
  189. package/dist/mcp/zod.js.map +1 -0
  190. package/dist/types-CX893hgH.d.ts +468 -0
  191. package/dist/types-CsX6EN2t.d.ts +301 -0
  192. package/dist/types-eOlt9J7n.d.ts +478 -0
  193. package/dist/vscode/index.d.ts +3 -0
  194. package/dist/vscode/index.d.ts.map +1 -0
  195. package/dist/vscode/index.js +3 -0
  196. package/dist/vscode/index.js.map +1 -0
  197. package/dist/vscode/messages.d.ts +204 -0
  198. package/dist/vscode/messages.d.ts.map +1 -0
  199. package/dist/vscode/messages.js +494 -0
  200. package/dist/vscode/messages.js.map +1 -0
  201. package/dist/workspace/index.d.ts +3 -2
  202. package/dist/workspace/index.d.ts.map +1 -1
  203. package/dist/workspace/index.js +2 -1
  204. package/dist/workspace/index.js.map +1 -1
  205. package/dist/workspace/reconcile-electron.d.ts +19 -0
  206. package/dist/workspace/reconcile-electron.d.ts.map +1 -0
  207. package/dist/workspace/reconcile-electron.js +42 -0
  208. package/dist/workspace/reconcile-electron.js.map +1 -0
  209. package/dist/workspace/types.d.ts +41 -1
  210. package/dist/workspace/types.d.ts.map +1 -1
  211. package/dist/workspace/types.js +0 -4
  212. package/dist/workspace/types.js.map +1 -1
  213. package/dist/workspace/workspace-manager.d.ts +17 -5
  214. package/dist/workspace/workspace-manager.d.ts.map +1 -1
  215. package/dist/workspace/workspace-manager.js +55 -11
  216. package/dist/workspace/workspace-manager.js.map +1 -1
  217. package/dist/workspace-path-CWVrcuPL.d.ts +21 -0
  218. package/package.json +43 -2
  219. package/src/document/document-session.ts +834 -0
  220. package/src/document/filesystem-target.ts +109 -0
  221. package/src/document/index.ts +41 -0
  222. package/src/document/recovery-journal.ts +536 -0
  223. package/src/document/types.ts +116 -0
  224. package/src/filesystem/commit-lock.ts +29 -0
  225. package/src/filesystem/dbk-workspace.ts +135 -0
  226. package/src/filesystem/electron-provider-v2.ts +630 -0
  227. package/src/filesystem/electron-provider.ts +25 -14
  228. package/src/filesystem/electron.ts +3 -0
  229. package/src/filesystem/filesystem-content-container.ts +53 -15
  230. package/src/filesystem/fs-error.ts +234 -0
  231. package/src/filesystem/index.ts +119 -0
  232. package/src/filesystem/indexeddb-content-container.ts +20 -12
  233. package/src/filesystem/indexeddb-provider-v2.ts +1740 -0
  234. package/src/filesystem/indexeddb-provider.ts +126 -300
  235. package/src/filesystem/indexeddb-store.ts +207 -0
  236. package/src/filesystem/indexeddb.ts +12 -0
  237. package/src/filesystem/legacy-v2-adapter.ts +779 -0
  238. package/src/filesystem/memory-provider-v2.ts +896 -0
  239. package/src/filesystem/memory-provider.ts +180 -0
  240. package/src/filesystem/memory.ts +15 -0
  241. package/src/filesystem/move-entry.ts +142 -0
  242. package/src/filesystem/move-error.ts +159 -0
  243. package/src/filesystem/native-provider-v2.ts +1165 -0
  244. package/src/filesystem/native-provider.ts +194 -41
  245. package/src/filesystem/native.ts +16 -0
  246. package/src/filesystem/types.ts +49 -4
  247. package/src/filesystem/v2.ts +231 -0
  248. package/src/filesystem/workspace-path.ts +92 -0
  249. package/src/host/filesystem-v2.ts +104 -0
  250. package/src/host/git.ts +246 -0
  251. package/src/host/index.ts +46 -0
  252. package/src/host/types.ts +155 -34
  253. package/src/host/wire-policy.ts +103 -0
  254. package/src/index.ts +2 -1
  255. package/src/mcp/index.ts +3 -0
  256. package/src/mcp/types.ts +594 -0
  257. package/src/mcp/wire.ts +1280 -0
  258. package/src/mcp/zod.ts +1000 -0
  259. package/src/vscode/index.ts +2 -0
  260. package/src/vscode/messages.ts +704 -0
  261. package/src/workspace/index.ts +8 -1
  262. package/src/workspace/reconcile-electron.ts +65 -0
  263. package/src/workspace/types.ts +39 -1
  264. package/src/workspace/workspace-manager.ts +71 -10
  265. package/dist/chunk-GUNM43XZ.js +0 -63
  266. package/dist/chunk-GUNM43XZ.js.map +0 -1
  267. package/dist/chunk-IM7LCQJ6.js +0 -850
  268. package/dist/chunk-IM7LCQJ6.js.map +0 -1
  269. package/dist/chunk-ME76RUMR.js.map +0 -1
  270. package/dist/index-pgBHBQ9G.d.ts +0 -213
@@ -1,850 +0,0 @@
1
- import {
2
- maybeGetDocBlocksHost
3
- } from "./chunk-ME76RUMR.js";
4
-
5
- // src/filesystem/indexeddb-provider.ts
6
- import { LocalForageAdapter } from "@bendyline/squisq/storage";
7
- function normalisePath(p) {
8
- return p.replace(/\\/g, "/").replace(/\/+/g, "/").replace(/^\//, "").replace(/\/$/, "");
9
- }
10
- function parentDir(p) {
11
- const idx = p.lastIndexOf("/");
12
- return idx === -1 ? "" : p.slice(0, idx);
13
- }
14
- function baseName(p) {
15
- const idx = p.lastIndexOf("/");
16
- return idx === -1 ? p : p.slice(idx + 1);
17
- }
18
- function contentKey(path) {
19
- return `fs:${path}:content`;
20
- }
21
- function binaryKey(path) {
22
- return `fs:${path}:binary`;
23
- }
24
- function metaKey(path) {
25
- return `fs:${path}:meta`;
26
- }
27
- var DIRS_KEY = "fs:dirs";
28
- var IndexedDBFileSystemProvider = class {
29
- constructor(id, label) {
30
- this.id = id;
31
- this.label = label;
32
- this.store = new LocalForageAdapter({
33
- name: `docblocks-fs-${id}`,
34
- storeName: "files"
35
- });
36
- }
37
- // ── Directory tracking ──────────────────────────────────────────
38
- async getDirs() {
39
- const raw = await this.store.get(DIRS_KEY);
40
- return new Set(raw ?? []);
41
- }
42
- async saveDirs(dirs) {
43
- await this.store.set(DIRS_KEY, [...dirs]);
44
- }
45
- /** Ensure a directory (and all ancestors) are tracked. */
46
- async ensureDir(dirPath) {
47
- if (!dirPath) return;
48
- const dirs = await this.getDirs();
49
- const parts = dirPath.split("/");
50
- let current = "";
51
- let changed = false;
52
- for (const part of parts) {
53
- current = current ? `${current}/${part}` : part;
54
- if (!dirs.has(current)) {
55
- dirs.add(current);
56
- changed = true;
57
- }
58
- }
59
- if (changed) {
60
- await this.saveDirs(dirs);
61
- }
62
- }
63
- // ── FileSystemProvider implementation ───────────────────────────
64
- async readFile(path) {
65
- const p = normalisePath(path);
66
- return this.store.get(contentKey(p));
67
- }
68
- async writeFile(path, content) {
69
- const p = normalisePath(path);
70
- const parent = parentDir(p);
71
- if (parent) {
72
- await this.ensureDir(parent);
73
- }
74
- const meta = {
75
- name: baseName(p),
76
- path: p,
77
- size: new Blob([content]).size,
78
- lastModified: (/* @__PURE__ */ new Date()).toISOString()
79
- };
80
- await this.store.set(contentKey(p), content);
81
- await this.store.set(metaKey(p), meta);
82
- }
83
- async delete(path) {
84
- const p = normalisePath(path);
85
- await this.store.remove(contentKey(p));
86
- await this.store.remove(binaryKey(p));
87
- await this.store.remove(metaKey(p));
88
- const dirs = await this.getDirs();
89
- if (dirs.has(p)) {
90
- const prefix = p + "/";
91
- const toRemove = [p];
92
- for (const d of dirs) {
93
- if (d.startsWith(prefix)) {
94
- toRemove.push(d);
95
- }
96
- }
97
- for (const d of toRemove) {
98
- dirs.delete(d);
99
- }
100
- await this.saveDirs(dirs);
101
- const allKeys = await this.store.keys();
102
- const filePrefix = `fs:${p}/`;
103
- const keysToRemove = allKeys.filter((k) => k.startsWith(filePrefix));
104
- await Promise.all(keysToRemove.map((k) => this.store.remove(k)));
105
- }
106
- }
107
- async rename(oldPath, newPath) {
108
- const op = normalisePath(oldPath);
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
- }
163
- const content = await this.store.get(contentKey(op));
164
- const binary = await this.store.get(binaryKey(op));
165
- const meta = await this.store.get(metaKey(op));
166
- if (content !== null) {
167
- await this.store.set(contentKey(np), content);
168
- }
169
- if (binary !== null) {
170
- await this.store.set(binaryKey(np), binary);
171
- }
172
- if (meta) {
173
- await this.store.set(metaKey(np), {
174
- ...meta,
175
- name: baseName(np),
176
- path: np
177
- });
178
- }
179
- const newParent = parentDir(np);
180
- if (newParent) {
181
- await this.ensureDir(newParent);
182
- }
183
- await this.store.remove(contentKey(op));
184
- await this.store.remove(binaryKey(op));
185
- await this.store.remove(metaKey(op));
186
- }
187
- async readDirectory(path) {
188
- const p = normalisePath(path);
189
- const dirs = await this.getDirs();
190
- const entries = [];
191
- const seen = /* @__PURE__ */ new Set();
192
- const prefix = p ? p + "/" : "";
193
- for (const d of dirs) {
194
- if (!p && !d.includes("/")) {
195
- if (!seen.has(d)) {
196
- seen.add(d);
197
- entries.push({ kind: "directory", name: d, path: d });
198
- }
199
- } else if (p && d.startsWith(prefix)) {
200
- const rest = d.slice(prefix.length);
201
- if (!rest.includes("/")) {
202
- if (!seen.has(rest)) {
203
- seen.add(rest);
204
- entries.push({ kind: "directory", name: rest, path: d });
205
- }
206
- }
207
- }
208
- }
209
- const allKeys = await this.store.keys();
210
- const metaPrefix = p ? `fs:${p}/` : "fs:";
211
- const metaSuffix = ":meta";
212
- for (const key of allKeys) {
213
- if (!key.startsWith(metaPrefix) || !key.endsWith(metaSuffix)) continue;
214
- const filePath = key.slice(3, -metaSuffix.length);
215
- const rel = p ? filePath.slice(prefix.length) : filePath;
216
- if (rel.includes("/")) continue;
217
- if (!seen.has(rel)) {
218
- seen.add(rel);
219
- entries.push({ kind: "file", name: rel, path: filePath });
220
- }
221
- }
222
- entries.sort((a, b) => {
223
- if (a.kind !== b.kind) return a.kind === "directory" ? -1 : 1;
224
- return a.name.localeCompare(b.name);
225
- });
226
- return entries;
227
- }
228
- async exists(path) {
229
- const p = normalisePath(path);
230
- const dirs = await this.getDirs();
231
- if (dirs.has(p)) return true;
232
- const meta = await this.store.get(metaKey(p));
233
- return meta !== null;
234
- }
235
- async createDirectory(path) {
236
- const p = normalisePath(path);
237
- await this.ensureDir(p);
238
- }
239
- async stat(path) {
240
- const p = normalisePath(path);
241
- return this.store.get(metaKey(p));
242
- }
243
- async readBinary(path) {
244
- const p = normalisePath(path);
245
- return this.store.get(binaryKey(p));
246
- }
247
- async writeBinary(path, data) {
248
- const p = normalisePath(path);
249
- const parent = parentDir(p);
250
- if (parent) {
251
- await this.ensureDir(parent);
252
- }
253
- const meta = {
254
- name: baseName(p),
255
- path: p,
256
- size: data.byteLength,
257
- lastModified: (/* @__PURE__ */ new Date()).toISOString()
258
- };
259
- await this.store.set(binaryKey(p), data);
260
- await this.store.set(metaKey(p), meta);
261
- }
262
- };
263
-
264
- // src/filesystem/indexeddb-content-container.ts
265
- import { findDocumentPath } from "@bendyline/squisq/storage";
266
- var EXTENSION_MIME_MAP = {
267
- ".md": "text/markdown",
268
- ".txt": "text/plain",
269
- ".json": "application/json",
270
- ".jpg": "image/jpeg",
271
- ".jpeg": "image/jpeg",
272
- ".png": "image/png",
273
- ".gif": "image/gif",
274
- ".svg": "image/svg+xml",
275
- ".webp": "image/webp",
276
- ".avif": "image/avif",
277
- ".mp4": "video/mp4",
278
- ".webm": "video/webm",
279
- ".mp3": "audio/mpeg",
280
- ".wav": "audio/wav",
281
- ".ogg": "audio/ogg"
282
- };
283
- function guessMimeType(path) {
284
- const dot = path.lastIndexOf(".");
285
- if (dot === -1) return "application/octet-stream";
286
- const ext = path.slice(dot).toLowerCase();
287
- return EXTENSION_MIME_MAP[ext] ?? "application/octet-stream";
288
- }
289
- var IndexedDBContentContainer = class {
290
- constructor(workspaceId) {
291
- this.provider = new IndexedDBFileSystemProvider(`${workspaceId}-media`, "Media Storage");
292
- }
293
- async readFile(path) {
294
- return this.provider.readBinary(path);
295
- }
296
- async writeFile(path, data, _mimeType) {
297
- await this.provider.writeBinary(path, data);
298
- }
299
- async removeFile(path) {
300
- await this.provider.delete(path);
301
- }
302
- async listFiles(prefix) {
303
- const entries = [];
304
- const walk = async (dir) => {
305
- const children = await this.provider.readDirectory(dir);
306
- for (const child of children) {
307
- if (child.kind === "directory") {
308
- await walk(child.path);
309
- } else {
310
- const filePath = child.path.replace(/^\//, "");
311
- if (prefix && !filePath.startsWith(prefix)) continue;
312
- const meta = await this.provider.stat(child.path);
313
- entries.push({
314
- path: filePath,
315
- mimeType: guessMimeType(filePath),
316
- size: meta?.size ?? 0
317
- });
318
- }
319
- }
320
- };
321
- await walk("/");
322
- return entries;
323
- }
324
- async exists(path) {
325
- return this.provider.exists(path);
326
- }
327
- async getDocumentPath() {
328
- return findDocumentPath(await this.listFiles());
329
- }
330
- async readDocument() {
331
- const docPath = await this.getDocumentPath();
332
- if (!docPath) return null;
333
- const data = await this.readFile(docPath);
334
- if (!data) return null;
335
- return new TextDecoder().decode(data);
336
- }
337
- async writeDocument(markdown, filename) {
338
- const name = filename ?? "index.md";
339
- const data = new TextEncoder().encode(markdown);
340
- await this.writeFile(name, data, "text/markdown");
341
- }
342
- };
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
-
502
- // src/filesystem/native-provider.ts
503
- function isNativeFileSystemSupported() {
504
- return typeof globalThis !== "undefined" && "showDirectoryPicker" in globalThis;
505
- }
506
- var HANDLE_DB_NAME = "docblocks-handles";
507
- var HANDLE_STORE_NAME = "directory-handles";
508
- function openHandleDB() {
509
- return new Promise((resolve, reject) => {
510
- const req = indexedDB.open(HANDLE_DB_NAME, 1);
511
- req.onupgradeneeded = () => {
512
- req.result.createObjectStore(HANDLE_STORE_NAME);
513
- };
514
- req.onsuccess = () => resolve(req.result);
515
- req.onerror = () => reject(req.error);
516
- });
517
- }
518
- async function storeDirectoryHandle(workspaceId, handle) {
519
- const db = await openHandleDB();
520
- return new Promise((resolve, reject) => {
521
- const tx = db.transaction(HANDLE_STORE_NAME, "readwrite");
522
- tx.objectStore(HANDLE_STORE_NAME).put(handle, workspaceId);
523
- tx.oncomplete = () => {
524
- db.close();
525
- resolve();
526
- };
527
- tx.onerror = () => {
528
- db.close();
529
- reject(tx.error);
530
- };
531
- });
532
- }
533
- async function loadDirectoryHandle(workspaceId) {
534
- const db = await openHandleDB();
535
- return new Promise((resolve, reject) => {
536
- const tx = db.transaction(HANDLE_STORE_NAME, "readonly");
537
- const req = tx.objectStore(HANDLE_STORE_NAME).get(workspaceId);
538
- req.onsuccess = () => {
539
- db.close();
540
- resolve(req.result ?? null);
541
- };
542
- req.onerror = () => {
543
- db.close();
544
- reject(req.error);
545
- };
546
- });
547
- }
548
- async function removeDirectoryHandle(workspaceId) {
549
- const db = await openHandleDB();
550
- return new Promise((resolve, reject) => {
551
- const tx = db.transaction(HANDLE_STORE_NAME, "readwrite");
552
- tx.objectStore(HANDLE_STORE_NAME).delete(workspaceId);
553
- tx.oncomplete = () => {
554
- db.close();
555
- resolve();
556
- };
557
- tx.onerror = () => {
558
- db.close();
559
- reject(tx.error);
560
- };
561
- });
562
- }
563
- function normalisePath2(p) {
564
- return p.replace(/\\/g, "/").replace(/\/+/g, "/").replace(/^\//, "").replace(/\/$/, "");
565
- }
566
- async function resolveDir(root, dirPath) {
567
- if (!dirPath) return root;
568
- const parts = dirPath.split("/");
569
- let current = root;
570
- for (const part of parts) {
571
- try {
572
- current = await current.getDirectoryHandle(part);
573
- } catch {
574
- return null;
575
- }
576
- }
577
- return current;
578
- }
579
- async function resolveDirCreate(root, dirPath) {
580
- if (!dirPath) return root;
581
- const parts = dirPath.split("/");
582
- let current = root;
583
- for (const part of parts) {
584
- current = await current.getDirectoryHandle(part, { create: true });
585
- }
586
- return current;
587
- }
588
- function parentDir2(p) {
589
- const idx = p.lastIndexOf("/");
590
- return idx === -1 ? "" : p.slice(0, idx);
591
- }
592
- function baseName2(p) {
593
- const idx = p.lastIndexOf("/");
594
- return idx === -1 ? p : p.slice(idx + 1);
595
- }
596
- function toWritableBinary(data) {
597
- if (data instanceof ArrayBuffer) return data;
598
- const copy = new Uint8Array(data.byteLength);
599
- copy.set(data);
600
- return copy.buffer;
601
- }
602
- var NativeFileSystemProvider = class {
603
- constructor(id, root) {
604
- this.id = id;
605
- this.label = root.name;
606
- this.root = root;
607
- }
608
- async copyDirectory(oldDirPath, newDirPath) {
609
- const source = await resolveDir(this.root, oldDirPath);
610
- if (!source) return false;
611
- await resolveDirCreate(this.root, newDirPath);
612
- for await (const [name, handle] of source) {
613
- const oldChild = oldDirPath ? `${oldDirPath}/${name}` : name;
614
- const newChild = newDirPath ? `${newDirPath}/${name}` : name;
615
- if (handle.kind === "directory") {
616
- await this.copyDirectory(oldChild, newChild);
617
- } else {
618
- const fileHandle = await source.getFileHandle(name);
619
- const file = await fileHandle.getFile();
620
- await this.writeBinary(newChild, await file.arrayBuffer());
621
- }
622
- }
623
- return true;
624
- }
625
- async readFile(path) {
626
- const p = normalisePath2(path);
627
- const dir = await resolveDir(this.root, parentDir2(p));
628
- if (!dir) return null;
629
- try {
630
- const fileHandle = await dir.getFileHandle(baseName2(p));
631
- const file = await fileHandle.getFile();
632
- return file.text();
633
- } catch {
634
- return null;
635
- }
636
- }
637
- async writeFile(path, content) {
638
- const p = normalisePath2(path);
639
- const dir = await resolveDirCreate(this.root, parentDir2(p));
640
- const fileHandle = await dir.getFileHandle(baseName2(p), { create: true });
641
- const writable = await fileHandle.createWritable();
642
- await writable.write(content);
643
- await writable.close();
644
- }
645
- async delete(path) {
646
- const p = normalisePath2(path);
647
- const parent = parentDir2(p);
648
- const name = baseName2(p);
649
- const dir = await resolveDir(this.root, parent);
650
- if (!dir) return;
651
- await dir.removeEntry(name, { recursive: true });
652
- }
653
- async rename(oldPath, newPath) {
654
- const op = normalisePath2(oldPath);
655
- const np = normalisePath2(newPath);
656
- if (op === np) return;
657
- if (!op || !np) {
658
- throw new Error("Cannot rename the filesystem root");
659
- }
660
- if (np.startsWith(op + "/")) {
661
- throw new Error("Cannot move a directory into itself");
662
- }
663
- const oldParent = await resolveDir(this.root, parentDir2(op));
664
- if (!oldParent) return;
665
- try {
666
- const fileHandle = await oldParent.getFileHandle(baseName2(op));
667
- const file = await fileHandle.getFile();
668
- await this.writeBinary(np, await file.arrayBuffer());
669
- await this.delete(op);
670
- return;
671
- } catch {
672
- }
673
- const copied = await this.copyDirectory(op, np);
674
- if (copied) {
675
- await this.delete(op);
676
- }
677
- }
678
- async readDirectory(path) {
679
- const p = normalisePath2(path);
680
- const dir = await resolveDir(this.root, p);
681
- if (!dir) return [];
682
- const entries = [];
683
- for await (const [name, handle] of dir) {
684
- const entryPath = p ? `${p}/${name}` : name;
685
- if (handle.kind === "directory") {
686
- entries.push({ kind: "directory", name, path: entryPath });
687
- } else {
688
- entries.push({ kind: "file", name, path: entryPath });
689
- }
690
- }
691
- entries.sort((a, b) => {
692
- if (a.kind !== b.kind) return a.kind === "directory" ? -1 : 1;
693
- return a.name.localeCompare(b.name);
694
- });
695
- return entries;
696
- }
697
- async exists(path) {
698
- const p = normalisePath2(path);
699
- const parent = parentDir2(p);
700
- const name = baseName2(p);
701
- const dir = await resolveDir(this.root, parent);
702
- if (!dir) return false;
703
- try {
704
- await dir.getFileHandle(name);
705
- return true;
706
- } catch {
707
- try {
708
- await dir.getDirectoryHandle(name);
709
- return true;
710
- } catch {
711
- return false;
712
- }
713
- }
714
- }
715
- async createDirectory(path) {
716
- const p = normalisePath2(path);
717
- await resolveDirCreate(this.root, p);
718
- }
719
- async stat(path) {
720
- const p = normalisePath2(path);
721
- const dir = await resolveDir(this.root, parentDir2(p));
722
- if (!dir) return null;
723
- try {
724
- const fileHandle = await dir.getFileHandle(baseName2(p));
725
- const file = await fileHandle.getFile();
726
- return {
727
- name: file.name,
728
- path: p,
729
- size: file.size,
730
- lastModified: new Date(file.lastModified).toISOString()
731
- };
732
- } catch {
733
- return null;
734
- }
735
- }
736
- async readBinary(path) {
737
- const p = normalisePath2(path);
738
- const dir = await resolveDir(this.root, parentDir2(p));
739
- if (!dir) return null;
740
- try {
741
- const fileHandle = await dir.getFileHandle(baseName2(p));
742
- const file = await fileHandle.getFile();
743
- return file.arrayBuffer();
744
- } catch {
745
- return null;
746
- }
747
- }
748
- async writeBinary(path, data) {
749
- const p = normalisePath2(path);
750
- const dir = await resolveDirCreate(this.root, parentDir2(p));
751
- const fileHandle = await dir.getFileHandle(baseName2(p), { create: true });
752
- const writable = await fileHandle.createWritable();
753
- await writable.write(toWritableBinary(data));
754
- await writable.close();
755
- }
756
- };
757
- async function openNativeFolder() {
758
- if (!isNativeFileSystemSupported()) {
759
- throw new Error("File System Access API is not supported in this browser");
760
- }
761
- const handle = await globalThis.showDirectoryPicker();
762
- const id = `native-${handle.name}-${Date.now()}`;
763
- await storeDirectoryHandle(id, handle);
764
- return new NativeFileSystemProvider(id, handle);
765
- }
766
- async function restoreNativeFolder(workspaceId) {
767
- const handle = await loadDirectoryHandle(workspaceId);
768
- if (!handle) return null;
769
- const opts = { mode: "readwrite" };
770
- const h = handle;
771
- if (await h.queryPermission(opts) === "granted") {
772
- return new NativeFileSystemProvider(workspaceId, handle);
773
- }
774
- if (await h.requestPermission(opts) === "granted") {
775
- return new NativeFileSystemProvider(workspaceId, handle);
776
- }
777
- return null;
778
- }
779
-
780
- // src/filesystem/electron-provider.ts
781
- function getHostFs() {
782
- const host = maybeGetDocBlocksHost();
783
- if (!host) {
784
- throw new Error(
785
- "ElectronFileSystemProvider: docBlocksHost is not available \u2014 not running under Electron?"
786
- );
787
- }
788
- return host.fs;
789
- }
790
- var ElectronFileSystemProvider = class {
791
- constructor(id, label, rootPath) {
792
- this.id = id;
793
- this.label = label;
794
- this.rootPath = rootPath;
795
- }
796
- /** Absolute path this provider is rooted at. */
797
- getRootPath() {
798
- return this.rootPath;
799
- }
800
- readFile(path) {
801
- return getHostFs().readFile(this.rootPath, path);
802
- }
803
- writeFile(path, content) {
804
- return getHostFs().writeFile(this.rootPath, path, content);
805
- }
806
- delete(path) {
807
- return getHostFs().delete(this.rootPath, path);
808
- }
809
- rename(oldPath, newPath) {
810
- return getHostFs().rename(this.rootPath, oldPath, newPath);
811
- }
812
- readDirectory(path) {
813
- return getHostFs().readDirectory(this.rootPath, path);
814
- }
815
- exists(path) {
816
- return getHostFs().exists(this.rootPath, path);
817
- }
818
- createDirectory(path) {
819
- return getHostFs().createDirectory(this.rootPath, path);
820
- }
821
- stat(path) {
822
- return getHostFs().stat(this.rootPath, path);
823
- }
824
- readBinary(path) {
825
- return getHostFs().readBinary(this.rootPath, path);
826
- }
827
- writeBinary(path, data) {
828
- return getHostFs().writeBinary(this.rootPath, path, data);
829
- }
830
- /** Subscribe to external change notifications under this root. */
831
- watch(onChange) {
832
- return getHostFs().watch(this.rootPath, onChange);
833
- }
834
- };
835
-
836
- export {
837
- IndexedDBFileSystemProvider,
838
- IndexedDBContentContainer,
839
- FileSystemContentContainer,
840
- createFileMediaProvider,
841
- isNativeFileSystemSupported,
842
- storeDirectoryHandle,
843
- loadDirectoryHandle,
844
- removeDirectoryHandle,
845
- NativeFileSystemProvider,
846
- openNativeFolder,
847
- restoreNativeFolder,
848
- ElectronFileSystemProvider
849
- };
850
- //# sourceMappingURL=chunk-IM7LCQJ6.js.map