@w100n/documents 0.17.0 → 0.18.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 (37) hide show
  1. package/dist/{SheetView-SBLAFGTL.js → SheetView-F4CBWEOS.js} +4 -4
  2. package/dist/{TextEditor-X2GSL4QM.js → TextEditor-ZY4B7YIF.js} +5 -5
  3. package/dist/{chunk-A6AHJCEK.js → chunk-2G34AIPU.js} +3 -3
  4. package/dist/{chunk-A6AHJCEK.js.map → chunk-2G34AIPU.js.map} +1 -1
  5. package/dist/{chunk-B7C6NBBQ.js → chunk-BWU6FPPZ.js} +28 -1
  6. package/dist/chunk-BWU6FPPZ.js.map +1 -0
  7. package/dist/{chunk-ASTNK6WZ.js → chunk-TSB2QS56.js} +2 -2
  8. package/dist/{chunk-FFXAOK4A.js → chunk-Z5STMOD6.js} +2 -2
  9. package/dist/collab.cjs +28 -1
  10. package/dist/collab.cjs.map +1 -1
  11. package/dist/collab.d.cts +1 -1
  12. package/dist/collab.d.ts +1 -1
  13. package/dist/collab.js +2 -2
  14. package/dist/index.cjs +277 -45
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.css +28 -2
  17. package/dist/index.css.map +1 -1
  18. package/dist/index.d.cts +2 -2
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.js +261 -53
  21. package/dist/index.js.map +1 -1
  22. package/dist/kinds.d.cts +1 -1
  23. package/dist/kinds.d.ts +1 -1
  24. package/dist/memory.cjs +33 -5
  25. package/dist/memory.cjs.map +1 -1
  26. package/dist/memory.d.cts +1 -1
  27. package/dist/memory.d.ts +1 -1
  28. package/dist/memory.js +33 -5
  29. package/dist/memory.js.map +1 -1
  30. package/dist/{types-CHmV8GLx.d.cts → types-DyonaPQf.d.cts} +11 -1
  31. package/dist/{types-CHmV8GLx.d.ts → types-DyonaPQf.d.ts} +11 -1
  32. package/package.json +1 -1
  33. package/dist/chunk-B7C6NBBQ.js.map +0 -1
  34. /package/dist/{SheetView-SBLAFGTL.js.map → SheetView-F4CBWEOS.js.map} +0 -0
  35. /package/dist/{TextEditor-X2GSL4QM.js.map → TextEditor-ZY4B7YIF.js.map} +0 -0
  36. /package/dist/{chunk-ASTNK6WZ.js.map → chunk-TSB2QS56.js.map} +0 -0
  37. /package/dist/{chunk-FFXAOK4A.js.map → chunk-Z5STMOD6.js.map} +0 -0
package/dist/kinds.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as DocumentKind } from './types-CHmV8GLx.cjs';
1
+ import { b as DocumentKind } from './types-DyonaPQf.cjs';
2
2
 
3
3
  declare const kinds: DocumentKind[];
4
4
  declare function kindOf(name: string, mimeType?: string | null): DocumentKind | null;
package/dist/kinds.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as DocumentKind } from './types-CHmV8GLx.js';
1
+ import { b as DocumentKind } from './types-DyonaPQf.js';
2
2
 
3
3
  declare const kinds: DocumentKind[];
4
4
  declare function kindOf(name: string, mimeType?: string | null): DocumentKind | null;
package/dist/memory.cjs CHANGED
@@ -66,6 +66,9 @@ function memoryHost({ me, spaces, files, collab, people = [] }) {
66
66
  if (!found || found.author.id !== me.id) throw new Error("only the author changes a comment");
67
67
  return found;
68
68
  };
69
+ const made = /* @__PURE__ */ new Set();
70
+ const within = (folder, path) => folder === path || (folder ?? "").startsWith(`${path}/`);
71
+ const moved = (folder, from, to) => to + folder.slice(from.length);
69
72
  const summary = (file) => ({
70
73
  id: file.id,
71
74
  spaceId: file.spaceId,
@@ -122,7 +125,7 @@ function memoryHost({ me, spaces, files, collab, people = [] }) {
122
125
  const file = find(id);
123
126
  let n = (file.comments?.length ?? 0) + 1;
124
127
  while (file.comments?.some((c) => c.id === `c${n}`)) n++;
125
- const made = {
128
+ const made2 = {
126
129
  id: `c${n}`,
127
130
  documentId: id,
128
131
  author: me,
@@ -133,8 +136,8 @@ function memoryHost({ me, spaces, files, collab, people = [] }) {
133
136
  resolved: false,
134
137
  assignee: people.find((p) => p.id === entry.assignee) ?? null
135
138
  };
136
- file.comments = [...file.comments ?? [], made];
137
- return made;
139
+ file.comments = [...file.comments ?? [], made2];
140
+ return made2;
138
141
  },
139
142
  resolveComment: async (id, commentId, resolved) => {
140
143
  const file = find(id);
@@ -159,6 +162,31 @@ function memoryHost({ me, spaces, files, collab, people = [] }) {
159
162
  remove: async (id) => {
160
163
  files.splice(files.indexOf(find(id)), 1);
161
164
  },
165
+ folders: async (spaceId) => {
166
+ const all = new Set([...made].filter((key) => key.startsWith(`${spaceId}:`)).map((key) => key.slice(spaceId.length + 1)));
167
+ for (const file of files) if (file.spaceId === spaceId && file.folder) file.folder.split("/").forEach((_, i, parts) => all.add(parts.slice(0, i + 1).join("/")));
168
+ return [...all].sort();
169
+ },
170
+ makeFolder: async ({ spaceId, folder }, name) => {
171
+ made.add(`${spaceId}:${folder ? `${folder}/` : ""}${name}`);
172
+ },
173
+ renameFolder: async ({ spaceId, folder }, name) => {
174
+ const to = [...folder.split("/").slice(0, -1), name].join("/");
175
+ for (const file of files) if (file.spaceId === spaceId && within(file.folder, folder)) file.folder = moved(file.folder, folder, to);
176
+ for (const key of [...made]) if (key.startsWith(`${spaceId}:`) && within(key.slice(spaceId.length + 1), folder)) {
177
+ made.delete(key);
178
+ made.add(`${spaceId}:${moved(key.slice(spaceId.length + 1), folder, to)}`);
179
+ }
180
+ },
181
+ removeFolder: async ({ spaceId, folder }) => {
182
+ for (const file of files.filter((file2) => file2.spaceId === spaceId && within(file2.folder, folder))) files.splice(files.indexOf(file), 1);
183
+ for (const key of [...made]) if (key.startsWith(`${spaceId}:`) && within(key.slice(spaceId.length + 1), folder)) made.delete(key);
184
+ },
185
+ move: async (id, { spaceId, folder }) => {
186
+ const file = find(id);
187
+ if (file.folder) made.add(`${file.spaceId}:${file.folder}`);
188
+ Object.assign(file, { spaceId, folder: folder || void 0 });
189
+ },
162
190
  templates: async () => files.filter((file) => file.folder === "Templates").map(summary),
163
191
  saveTemplate: async (id) => {
164
192
  const from = find(id);
@@ -178,9 +206,9 @@ function memoryHost({ me, spaces, files, collab, people = [] }) {
178
206
  },
179
207
  ...spaces.length ? {
180
208
  createIn: `${spaces[0].name} / Documents`,
181
- create: async ({ name, bytes, near }) => {
209
+ create: async ({ name, bytes, near, at }) => {
182
210
  const by = near ? find(near) : null;
183
- const file = { id: `new-${files.length + 1}`, spaceId: by?.spaceId ?? spaces[0].id, name, folder: by ? by.folder : "Documents", bytes, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
211
+ const file = { id: `new-${files.length + 1}`, spaceId: at?.spaceId ?? by?.spaceId ?? spaces[0].id, name, folder: at ? at.folder || void 0 : by ? by.folder : "Documents", bytes, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
184
212
  files.push(file);
185
213
  return summary(file);
186
214
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/memory.ts","../src/kinds.ts"],"sourcesContent":["import { kindOf } from './kinds';\nimport type { Comment, DocumentsHost, Person, Rights, Signature, Space } from './types';\n\ntype Bytes = ArrayBuffer | string;\n\nexport type MemoryFile = {\n id: string;\n spaceId: string;\n name: string;\n folder?: string;\n bytes: Bytes;\n version?: string;\n note?: string;\n updatedAt?: string;\n rights?: Partial<Rights>;\n versions?: { id: string; createdAt: string; bytes: Bytes; note?: string }[];\n signatures?: Signature[];\n comments?: Comment[];\n};\n\nconst mimes = { pdf: 'application/pdf', docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', md: 'text/markdown' };\n\nconst encode = (bytes: Bytes) => typeof bytes === 'string' ? new TextEncoder().encode(bytes).buffer as ArrayBuffer : bytes;\n\nexport function memoryHost({ me, spaces, files, collab, people = [] }: { me: Person; spaces: Space[]; files: MemoryFile[]; collab?: string; people?: Person[] }): DocumentsHost {\n const find = (id: string) => {\n const file = files.find(item => item.id === id);\n if (!file) throw new Error('document not found');\n return file;\n };\n const own = (file: MemoryFile, commentId: string) => {\n const found = file.comments?.find(c => c.id === commentId);\n if (!found || found.author.id !== me.id) throw new Error('only the author changes a comment');\n return found;\n };\n const summary = (file: MemoryFile) => ({\n id: file.id, spaceId: file.spaceId, name: file.name, kind: kindOf(file.name)!, size: encode(file.bytes).byteLength,\n updatedAt: file.updatedAt ?? '2026-10-19T09:00:00Z', updatedBy: me, createdAt: '2026-10-01T09:00:00Z', createdBy: me, folder: file.folder ?? null,\n });\n const archive = (file: MemoryFile, bytes: Bytes, note?: string) => {\n const versions = [{ id: file.version ?? `v${(file.versions?.length ?? 0) + 1}`, createdAt: file.updatedAt ?? '2026-10-19T09:00:00Z', bytes: file.bytes, note: file.note }, ...(file.versions ?? [])];\n const version = `v${versions.length + 1}`;\n Object.assign(file, { versions, version, bytes, note, updatedAt: new Date().toISOString() });\n return version;\n };\n return {\n me,\n ...(collab ? { collab: { url: `memory:${collab}`, token: async () => me.id } } : {}),\n spaces: async () => spaces,\n documents: async spaceId => files.filter(file => file.spaceId === spaceId && kindOf(file.name)).map(summary),\n document: async id => ({ ...summary(find(id)), rights: { view: true, comment: true, edit: true, ...find(id).rights }, live: !!collab }),\n versions: async id => {\n const file = find(id);\n return [\n { id: file.version ?? 'current', createdAt: summary(file).updatedAt, size: summary(file).size, author: me, note: file.note ?? null, current: true },\n ...(file.versions ?? []).map(v => ({ id: v.id, createdAt: v.createdAt, size: encode(v.bytes).byteLength, author: me, note: v.note ?? null, current: false })),\n ];\n },\n content: async (id, versionId) => {\n const file = find(id);\n const old = versionId && versionId !== 'current' && versionId !== file.version ? file.versions?.find(v => v.id === versionId) : undefined;\n return encode(old ? old.bytes : file.bytes);\n },\n restore: async (id, versionId) => {\n const file = find(id);\n const old = file.versions?.find(v => v.id === versionId);\n if (!old) throw new Error('version not found');\n archive(file, old.bytes);\n },\n save: async (id, bytes, note) => ({ versionId: archive(find(id), bytes, note) }),\n signatures: async id => [...(find(id).signatures ?? [])].reverse(),\n sign: async (id, entry) => {\n const file = find(id);\n const signature = { id: `s${(file.signatures?.length ?? 0) + 1}`, signer: me, signedAt: new Date().toISOString(), ...entry };\n file.signatures = [...(file.signatures ?? []), signature];\n return signature;\n },\n comments: async id => [...(find(id).comments ?? [])],\n people: async () => [me, ...people],\n comment: async (id, entry) => {\n const file = find(id);\n let n = (file.comments?.length ?? 0) + 1;\n while (file.comments?.some(c => c.id === `c${n}`)) n++;\n const made: Comment = { id: `c${n}`, documentId: id, author: me, body: entry.body, createdAt: new Date().toISOString(), quote: entry.quote, replyTo: entry.replyTo, resolved: false,\n assignee: people.find(p => p.id === entry.assignee) ?? null };\n file.comments = [...(file.comments ?? []), made];\n return made;\n },\n resolveComment: async (id, commentId, resolved) => {\n const file = find(id);\n file.comments = (file.comments ?? []).map(c => c.id === commentId ? { ...c, resolved } : c);\n },\n editComment: async (id, commentId, body) => {\n const file = find(id);\n const mine = own(file, commentId);\n const edited = { ...mine, body };\n file.comments = file.comments!.map(c => c === mine ? edited : c);\n return edited;\n },\n deleteComment: async (id, commentId) => {\n const file = find(id);\n if (!file.comments?.find(c => c.id === commentId)?.author.id.startsWith('guest:')) own(file, commentId);\n file.comments = file.comments!.filter(c => c.id !== commentId && c.replyTo !== commentId);\n },\n rename: async (id, name) => { find(id).name = name; },\n href: id => `https://docs.test/${id}`,\n remove: async id => { files.splice(files.indexOf(find(id)), 1); },\n templates: async () => files.filter(file => file.folder === 'Templates').map(summary),\n saveTemplate: async id => {\n const from = find(id);\n const file = { id: `t${files.length + 1}`, spaceId: from.spaceId, name: from.name, folder: 'Templates', bytes: from.bytes, updatedAt: new Date().toISOString() };\n files.push(file);\n return summary(file);\n },\n search: async text => files.flatMap(file => {\n const body = typeof file.bytes === 'string' && /\\.(md|txt)$/.test(file.name) ? file.bytes.replace(/\\s+/g, ' ') : '';\n const at = body.toLocaleLowerCase().indexOf(text.toLocaleLowerCase());\n return at < 0 ? [] : [{ id: file.id, excerpt: `${body.slice(Math.max(0, at - 30), at)}«${body.slice(at, at + text.length)}»${body.slice(at + text.length, at + text.length + 40)}` }];\n }),\n exportAs: async (id, format) => {\n const file = find(id);\n if ((format === 'md' ? 'markdown' : format) !== kindOf(file.name)) throw new Error('this format needs a converter on the host');\n return new Blob([encode(file.bytes)], { type: mimes[format] });\n },\n ...(spaces.length ? {\n createIn: `${spaces[0].name} / Documents`,\n create: async ({ name, bytes, near }: { name: string; bytes: ArrayBuffer; near?: string }) => {\n const by = near ? find(near) : null;\n const file = { id: `new-${files.length + 1}`, spaceId: by?.spaceId ?? spaces[0].id, name, folder: by ? by.folder : 'Documents', bytes, updatedAt: new Date().toISOString() };\n files.push(file);\n return summary(file);\n },\n } : {}),\n };\n}\n","import type { DocumentKind } from './types';\n\nconst byExtension: Record<string, DocumentKind> = {\n docx: 'docx', md: 'markdown', markdown: 'markdown', pdf: 'pdf', xlsx: 'sheet', csv: 'sheet', xls: 'sheet', ods: 'sheet', tsv: 'sheet', html: 'slides', htm: 'slides',\n};\n\nconst byMime: Record<string, DocumentKind> = {\n 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',\n 'text/markdown': 'markdown',\n 'application/pdf': 'pdf',\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'sheet',\n 'text/csv': 'sheet',\n 'text/html': 'slides',\n};\n\nexport const kinds: DocumentKind[] = ['docx', 'markdown', 'pdf', 'sheet', 'slides'];\n\nexport function kindOf(name: string, mimeType?: string | null): DocumentKind | null {\n const extension = name.includes('.') ? name.split('.').pop()!.toLowerCase() : '';\n return byExtension[extension] ?? (mimeType ? byMime[mimeType.split(';')[0].trim().toLowerCase()] : undefined) ?? null;\n}\n\nexport function readable(name: string, mimeType?: string | null): DocumentKind | null {\n const kind = kindOf(name, mimeType);\n return kind !== 'sheet' || /\\.(xlsx|csv)$/i.test(name) || /spreadsheetml|text\\/csv/.test(mimeType ?? '') ? kind : null;\n}\n\nexport function matches(doc: { name: string; kind: DocumentKind }, query: string, picked: DocumentKind[]) {\n const words = query.toLocaleLowerCase().split(/\\s+/).filter(Boolean);\n return (!picked.length || picked.includes(doc.kind)) && words.every(word => doc.name.toLocaleLowerCase().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,GAAG,EAAE,CAAC,OAAI,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM,CAAC,OAAI,KAAK,MAAM,KAAK,KAAK,QAAQ,KAAK,KAAK,SAAS,EAAE,CAAC,GAAG,CAAC;AAAA,IACtL,CAAC;AAAA,IACD,UAAU,OAAO,IAAI,WAAW;AAC9B,YAAM,OAAO,KAAK,EAAE;AACpB,WAAK,WAAW,OAAO,aAAa,YAAY,OAAO,KAAK,IAAI,EAAG,OAAM,IAAI,MAAM,2CAA2C;AAC9H,aAAO,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,GAAG,EAAE,MAAM,MAAM,MAAM,EAAE,CAAC;AAAA,IAC/D;AAAA,IACA,GAAI,OAAO,SAAS;AAAA,MAClB,UAAU,GAAG,OAAO,CAAC,EAAE,IAAI;AAAA,MAC3B,QAAQ,OAAO,EAAE,MAAM,OAAO,KAAK,MAA2D;AAC5F,cAAM,KAAK,OAAO,KAAK,IAAI,IAAI;AAC/B,cAAM,OAAO,EAAE,IAAI,OAAO,MAAM,SAAS,CAAC,IAAI,SAAS,IAAI,WAAW,OAAO,CAAC,EAAE,IAAI,MAAM,QAAQ,KAAK,GAAG,SAAS,aAAa,OAAO,YAAW,oBAAI,KAAK,GAAE,YAAY,EAAE;AAC3K,cAAM,KAAK,IAAI;AACf,eAAO,QAAQ,IAAI;AAAA,MACrB;AAAA,IACF,IAAI,CAAC;AAAA,EACP;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/memory.ts","../src/kinds.ts"],"sourcesContent":["import { kindOf } from './kinds';\nimport type { Comment, DocumentsHost, Person, Rights, Signature, Space } from './types';\n\ntype Bytes = ArrayBuffer | string;\n\nexport type MemoryFile = {\n id: string;\n spaceId: string;\n name: string;\n folder?: string;\n bytes: Bytes;\n version?: string;\n note?: string;\n updatedAt?: string;\n rights?: Partial<Rights>;\n versions?: { id: string; createdAt: string; bytes: Bytes; note?: string }[];\n signatures?: Signature[];\n comments?: Comment[];\n};\n\nconst mimes = { pdf: 'application/pdf', docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', md: 'text/markdown' };\n\nconst encode = (bytes: Bytes) => typeof bytes === 'string' ? new TextEncoder().encode(bytes).buffer as ArrayBuffer : bytes;\n\nexport function memoryHost({ me, spaces, files, collab, people = [] }: { me: Person; spaces: Space[]; files: MemoryFile[]; collab?: string; people?: Person[] }): DocumentsHost {\n const find = (id: string) => {\n const file = files.find(item => item.id === id);\n if (!file) throw new Error('document not found');\n return file;\n };\n const own = (file: MemoryFile, commentId: string) => {\n const found = file.comments?.find(c => c.id === commentId);\n if (!found || found.author.id !== me.id) throw new Error('only the author changes a comment');\n return found;\n };\n const made = new Set<string>();\n const within = (folder: string | undefined, path: string) => folder === path || (folder ?? '').startsWith(`${path}/`);\n const moved = (folder: string, from: string, to: string) => to + folder.slice(from.length);\n const summary = (file: MemoryFile) => ({\n id: file.id, spaceId: file.spaceId, name: file.name, kind: kindOf(file.name)!, size: encode(file.bytes).byteLength,\n updatedAt: file.updatedAt ?? '2026-10-19T09:00:00Z', updatedBy: me, createdAt: '2026-10-01T09:00:00Z', createdBy: me, folder: file.folder ?? null,\n });\n const archive = (file: MemoryFile, bytes: Bytes, note?: string) => {\n const versions = [{ id: file.version ?? `v${(file.versions?.length ?? 0) + 1}`, createdAt: file.updatedAt ?? '2026-10-19T09:00:00Z', bytes: file.bytes, note: file.note }, ...(file.versions ?? [])];\n const version = `v${versions.length + 1}`;\n Object.assign(file, { versions, version, bytes, note, updatedAt: new Date().toISOString() });\n return version;\n };\n return {\n me,\n ...(collab ? { collab: { url: `memory:${collab}`, token: async () => me.id } } : {}),\n spaces: async () => spaces,\n documents: async spaceId => files.filter(file => file.spaceId === spaceId && kindOf(file.name)).map(summary),\n document: async id => ({ ...summary(find(id)), rights: { view: true, comment: true, edit: true, ...find(id).rights }, live: !!collab }),\n versions: async id => {\n const file = find(id);\n return [\n { id: file.version ?? 'current', createdAt: summary(file).updatedAt, size: summary(file).size, author: me, note: file.note ?? null, current: true },\n ...(file.versions ?? []).map(v => ({ id: v.id, createdAt: v.createdAt, size: encode(v.bytes).byteLength, author: me, note: v.note ?? null, current: false })),\n ];\n },\n content: async (id, versionId) => {\n const file = find(id);\n const old = versionId && versionId !== 'current' && versionId !== file.version ? file.versions?.find(v => v.id === versionId) : undefined;\n return encode(old ? old.bytes : file.bytes);\n },\n restore: async (id, versionId) => {\n const file = find(id);\n const old = file.versions?.find(v => v.id === versionId);\n if (!old) throw new Error('version not found');\n archive(file, old.bytes);\n },\n save: async (id, bytes, note) => ({ versionId: archive(find(id), bytes, note) }),\n signatures: async id => [...(find(id).signatures ?? [])].reverse(),\n sign: async (id, entry) => {\n const file = find(id);\n const signature = { id: `s${(file.signatures?.length ?? 0) + 1}`, signer: me, signedAt: new Date().toISOString(), ...entry };\n file.signatures = [...(file.signatures ?? []), signature];\n return signature;\n },\n comments: async id => [...(find(id).comments ?? [])],\n people: async () => [me, ...people],\n comment: async (id, entry) => {\n const file = find(id);\n let n = (file.comments?.length ?? 0) + 1;\n while (file.comments?.some(c => c.id === `c${n}`)) n++;\n const made: Comment = { id: `c${n}`, documentId: id, author: me, body: entry.body, createdAt: new Date().toISOString(), quote: entry.quote, replyTo: entry.replyTo, resolved: false,\n assignee: people.find(p => p.id === entry.assignee) ?? null };\n file.comments = [...(file.comments ?? []), made];\n return made;\n },\n resolveComment: async (id, commentId, resolved) => {\n const file = find(id);\n file.comments = (file.comments ?? []).map(c => c.id === commentId ? { ...c, resolved } : c);\n },\n editComment: async (id, commentId, body) => {\n const file = find(id);\n const mine = own(file, commentId);\n const edited = { ...mine, body };\n file.comments = file.comments!.map(c => c === mine ? edited : c);\n return edited;\n },\n deleteComment: async (id, commentId) => {\n const file = find(id);\n if (!file.comments?.find(c => c.id === commentId)?.author.id.startsWith('guest:')) own(file, commentId);\n file.comments = file.comments!.filter(c => c.id !== commentId && c.replyTo !== commentId);\n },\n rename: async (id, name) => { find(id).name = name; },\n href: id => `https://docs.test/${id}`,\n remove: async id => { files.splice(files.indexOf(find(id)), 1); },\n folders: async spaceId => {\n const all = new Set([...made].filter(key => key.startsWith(`${spaceId}:`)).map(key => key.slice(spaceId.length + 1)));\n for (const file of files) if (file.spaceId === spaceId && file.folder) file.folder.split('/').forEach((_, i, parts) => all.add(parts.slice(0, i + 1).join('/')));\n return [...all].sort();\n },\n makeFolder: async ({ spaceId, folder }, name) => { made.add(`${spaceId}:${folder ? `${folder}/` : ''}${name}`); },\n renameFolder: async ({ spaceId, folder }, name) => {\n const to = [...folder.split('/').slice(0, -1), name].join('/');\n for (const file of files) if (file.spaceId === spaceId && within(file.folder, folder)) file.folder = moved(file.folder!, folder, to);\n for (const key of [...made]) if (key.startsWith(`${spaceId}:`) && within(key.slice(spaceId.length + 1), folder)) {\n made.delete(key);\n made.add(`${spaceId}:${moved(key.slice(spaceId.length + 1), folder, to)}`);\n }\n },\n removeFolder: async ({ spaceId, folder }) => {\n for (const file of files.filter(file => file.spaceId === spaceId && within(file.folder, folder))) files.splice(files.indexOf(file), 1);\n for (const key of [...made]) if (key.startsWith(`${spaceId}:`) && within(key.slice(spaceId.length + 1), folder)) made.delete(key);\n },\n move: async (id, { spaceId, folder }) => {\n const file = find(id);\n if (file.folder) made.add(`${file.spaceId}:${file.folder}`);\n Object.assign(file, { spaceId, folder: folder || undefined });\n },\n templates: async () => files.filter(file => file.folder === 'Templates').map(summary),\n saveTemplate: async id => {\n const from = find(id);\n const file = { id: `t${files.length + 1}`, spaceId: from.spaceId, name: from.name, folder: 'Templates', bytes: from.bytes, updatedAt: new Date().toISOString() };\n files.push(file);\n return summary(file);\n },\n search: async text => files.flatMap(file => {\n const body = typeof file.bytes === 'string' && /\\.(md|txt)$/.test(file.name) ? file.bytes.replace(/\\s+/g, ' ') : '';\n const at = body.toLocaleLowerCase().indexOf(text.toLocaleLowerCase());\n return at < 0 ? [] : [{ id: file.id, excerpt: `${body.slice(Math.max(0, at - 30), at)}«${body.slice(at, at + text.length)}»${body.slice(at + text.length, at + text.length + 40)}` }];\n }),\n exportAs: async (id, format) => {\n const file = find(id);\n if ((format === 'md' ? 'markdown' : format) !== kindOf(file.name)) throw new Error('this format needs a converter on the host');\n return new Blob([encode(file.bytes)], { type: mimes[format] });\n },\n ...(spaces.length ? {\n createIn: `${spaces[0].name} / Documents`,\n create: async ({ name, bytes, near, at }: { name: string; bytes: ArrayBuffer; near?: string; at?: { spaceId: string; folder: string } }) => {\n const by = near ? find(near) : null;\n const file = { id: `new-${files.length + 1}`, spaceId: at?.spaceId ?? by?.spaceId ?? spaces[0].id, name, folder: at ? at.folder || undefined : by ? by.folder : 'Documents', bytes, updatedAt: new Date().toISOString() };\n files.push(file);\n return summary(file);\n },\n } : {}),\n };\n}\n","import type { DocumentKind } from './types';\n\nconst byExtension: Record<string, DocumentKind> = {\n docx: 'docx', md: 'markdown', markdown: 'markdown', pdf: 'pdf', xlsx: 'sheet', csv: 'sheet', xls: 'sheet', ods: 'sheet', tsv: 'sheet', html: 'slides', htm: 'slides',\n};\n\nconst byMime: Record<string, DocumentKind> = {\n 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',\n 'text/markdown': 'markdown',\n 'application/pdf': 'pdf',\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'sheet',\n 'text/csv': 'sheet',\n 'text/html': 'slides',\n};\n\nexport const kinds: DocumentKind[] = ['docx', 'markdown', 'pdf', 'sheet', 'slides'];\n\nexport function kindOf(name: string, mimeType?: string | null): DocumentKind | null {\n const extension = name.includes('.') ? name.split('.').pop()!.toLowerCase() : '';\n return byExtension[extension] ?? (mimeType ? byMime[mimeType.split(';')[0].trim().toLowerCase()] : undefined) ?? null;\n}\n\nexport function readable(name: string, mimeType?: string | null): DocumentKind | null {\n const kind = kindOf(name, mimeType);\n return kind !== 'sheet' || /\\.(xlsx|csv)$/i.test(name) || /spreadsheetml|text\\/csv/.test(mimeType ?? '') ? kind : null;\n}\n\nexport function matches(doc: { name: string; kind: DocumentKind }, query: string, picked: DocumentKind[]) {\n const words = query.toLocaleLowerCase().split(/\\s+/).filter(Boolean);\n return (!picked.length || picked.includes(doc.kind)) && words.every(word => doc.name.toLocaleLowerCase().includes(word));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAM,cAA4C;AAAA,EAChD,MAAM;AAAA,EAAQ,IAAI;AAAA,EAAY,UAAU;AAAA,EAAY,KAAK;AAAA,EAAO,MAAM;AAAA,EAAS,KAAK;AAAA,EAAS,KAAK;AAAA,EAAS,KAAK;AAAA,EAAS,KAAK;AAAA,EAAS,MAAM;AAAA,EAAU,KAAK;AAC9J;AAEA,IAAM,SAAuC;AAAA,EAC3C,2EAA2E;AAAA,EAC3E,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,qEAAqE;AAAA,EACrE,YAAY;AAAA,EACZ,aAAa;AACf;AAIO,SAAS,OAAO,MAAc,UAA+C;AAClF,QAAM,YAAY,KAAK,SAAS,GAAG,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI,EAAG,YAAY,IAAI;AAC9E,SAAO,YAAY,SAAS,MAAM,WAAW,OAAO,SAAS,MAAM,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,IAAI,WAAc;AACnH;;;ADAA,IAAM,QAAQ,EAAE,KAAK,mBAAmB,MAAM,2EAA2E,IAAI,gBAAgB;AAE7I,IAAM,SAAS,CAAC,UAAiB,OAAO,UAAU,WAAW,IAAI,YAAY,EAAE,OAAO,KAAK,EAAE,SAAwB;AAE9G,SAAS,WAAW,EAAE,IAAI,QAAQ,OAAO,QAAQ,SAAS,CAAC,EAAE,GAA4G;AAC9K,QAAM,OAAO,CAAC,OAAe;AAC3B,UAAM,OAAO,MAAM,KAAK,UAAQ,KAAK,OAAO,EAAE;AAC9C,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,oBAAoB;AAC/C,WAAO;AAAA,EACT;AACA,QAAM,MAAM,CAAC,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AAE,MAAM,MAAM,MAAM,EAAE,CAAC;AAAA,IAC/D;AAAA,IACA,GAAI,OAAO,SAAS;AAAA,MAClB,UAAU,GAAG,OAAO,CAAC,EAAE,IAAI;AAAA,MAC3B,QAAQ,OAAO,EAAE,MAAM,OAAO,MAAM,GAAG,MAAqG;AAC1I,cAAM,KAAK,OAAO,KAAK,IAAI,IAAI;AAC/B,cAAM,OAAO,EAAE,IAAI,OAAO,MAAM,SAAS,CAAC,IAAI,SAAS,IAAI,WAAW,IAAI,WAAW,OAAO,CAAC,EAAE,IAAI,MAAM,QAAQ,KAAK,GAAG,UAAU,SAAY,KAAK,GAAG,SAAS,aAAa,OAAO,YAAW,oBAAI,KAAK,GAAE,YAAY,EAAE;AACxN,cAAM,KAAK,IAAI;AACf,eAAO,QAAQ,IAAI;AAAA,MACrB;AAAA,IACF,IAAI,CAAC;AAAA,EACP;AACF;","names":["made","file"]}
package/dist/memory.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { R as Rights, S as Signature, C as Comment, h as Person, j as Space, D as DocumentsHost } from './types-CHmV8GLx.cjs';
1
+ import { R as Rights, S as Signature, C as Comment, i as Person, k as Space, D as DocumentsHost } from './types-DyonaPQf.cjs';
2
2
 
3
3
  type Bytes = ArrayBuffer | string;
4
4
  type MemoryFile = {
package/dist/memory.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { R as Rights, S as Signature, C as Comment, h as Person, j as Space, D as DocumentsHost } from './types-CHmV8GLx.js';
1
+ import { R as Rights, S as Signature, C as Comment, i as Person, k as Space, D as DocumentsHost } from './types-DyonaPQf.js';
2
2
 
3
3
  type Bytes = ArrayBuffer | string;
4
4
  type MemoryFile = {
package/dist/memory.js CHANGED
@@ -17,6 +17,9 @@ function memoryHost({ me, spaces, files, collab, people = [] }) {
17
17
  if (!found || found.author.id !== me.id) throw new Error("only the author changes a comment");
18
18
  return found;
19
19
  };
20
+ const made = /* @__PURE__ */ new Set();
21
+ const within = (folder, path) => folder === path || (folder ?? "").startsWith(`${path}/`);
22
+ const moved = (folder, from, to) => to + folder.slice(from.length);
20
23
  const summary = (file) => ({
21
24
  id: file.id,
22
25
  spaceId: file.spaceId,
@@ -73,7 +76,7 @@ function memoryHost({ me, spaces, files, collab, people = [] }) {
73
76
  const file = find(id);
74
77
  let n = (file.comments?.length ?? 0) + 1;
75
78
  while (file.comments?.some((c) => c.id === `c${n}`)) n++;
76
- const made = {
79
+ const made2 = {
77
80
  id: `c${n}`,
78
81
  documentId: id,
79
82
  author: me,
@@ -84,8 +87,8 @@ function memoryHost({ me, spaces, files, collab, people = [] }) {
84
87
  resolved: false,
85
88
  assignee: people.find((p) => p.id === entry.assignee) ?? null
86
89
  };
87
- file.comments = [...file.comments ?? [], made];
88
- return made;
90
+ file.comments = [...file.comments ?? [], made2];
91
+ return made2;
89
92
  },
90
93
  resolveComment: async (id, commentId, resolved) => {
91
94
  const file = find(id);
@@ -110,6 +113,31 @@ function memoryHost({ me, spaces, files, collab, people = [] }) {
110
113
  remove: async (id) => {
111
114
  files.splice(files.indexOf(find(id)), 1);
112
115
  },
116
+ folders: async (spaceId) => {
117
+ const all = new Set([...made].filter((key) => key.startsWith(`${spaceId}:`)).map((key) => key.slice(spaceId.length + 1)));
118
+ for (const file of files) if (file.spaceId === spaceId && file.folder) file.folder.split("/").forEach((_, i, parts) => all.add(parts.slice(0, i + 1).join("/")));
119
+ return [...all].sort();
120
+ },
121
+ makeFolder: async ({ spaceId, folder }, name) => {
122
+ made.add(`${spaceId}:${folder ? `${folder}/` : ""}${name}`);
123
+ },
124
+ renameFolder: async ({ spaceId, folder }, name) => {
125
+ const to = [...folder.split("/").slice(0, -1), name].join("/");
126
+ for (const file of files) if (file.spaceId === spaceId && within(file.folder, folder)) file.folder = moved(file.folder, folder, to);
127
+ for (const key of [...made]) if (key.startsWith(`${spaceId}:`) && within(key.slice(spaceId.length + 1), folder)) {
128
+ made.delete(key);
129
+ made.add(`${spaceId}:${moved(key.slice(spaceId.length + 1), folder, to)}`);
130
+ }
131
+ },
132
+ removeFolder: async ({ spaceId, folder }) => {
133
+ for (const file of files.filter((file2) => file2.spaceId === spaceId && within(file2.folder, folder))) files.splice(files.indexOf(file), 1);
134
+ for (const key of [...made]) if (key.startsWith(`${spaceId}:`) && within(key.slice(spaceId.length + 1), folder)) made.delete(key);
135
+ },
136
+ move: async (id, { spaceId, folder }) => {
137
+ const file = find(id);
138
+ if (file.folder) made.add(`${file.spaceId}:${file.folder}`);
139
+ Object.assign(file, { spaceId, folder: folder || void 0 });
140
+ },
113
141
  templates: async () => files.filter((file) => file.folder === "Templates").map(summary),
114
142
  saveTemplate: async (id) => {
115
143
  const from = find(id);
@@ -129,9 +157,9 @@ function memoryHost({ me, spaces, files, collab, people = [] }) {
129
157
  },
130
158
  ...spaces.length ? {
131
159
  createIn: `${spaces[0].name} / Documents`,
132
- create: async ({ name, bytes, near }) => {
160
+ create: async ({ name, bytes, near, at }) => {
133
161
  const by = near ? find(near) : null;
134
- const file = { id: `new-${files.length + 1}`, spaceId: by?.spaceId ?? spaces[0].id, name, folder: by ? by.folder : "Documents", bytes, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
162
+ const file = { id: `new-${files.length + 1}`, spaceId: at?.spaceId ?? by?.spaceId ?? spaces[0].id, name, folder: at ? at.folder || void 0 : by ? by.folder : "Documents", bytes, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
135
163
  files.push(file);
136
164
  return summary(file);
137
165
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/memory.ts"],"sourcesContent":["import { kindOf } from './kinds';\nimport type { Comment, DocumentsHost, Person, Rights, Signature, Space } from './types';\n\ntype Bytes = ArrayBuffer | string;\n\nexport type MemoryFile = {\n id: string;\n spaceId: string;\n name: string;\n folder?: string;\n bytes: Bytes;\n version?: string;\n note?: string;\n updatedAt?: string;\n rights?: Partial<Rights>;\n versions?: { id: string; createdAt: string; bytes: Bytes; note?: string }[];\n signatures?: Signature[];\n comments?: Comment[];\n};\n\nconst mimes = { pdf: 'application/pdf', docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', md: 'text/markdown' };\n\nconst encode = (bytes: Bytes) => typeof bytes === 'string' ? new TextEncoder().encode(bytes).buffer as ArrayBuffer : bytes;\n\nexport function memoryHost({ me, spaces, files, collab, people = [] }: { me: Person; spaces: Space[]; files: MemoryFile[]; collab?: string; people?: Person[] }): DocumentsHost {\n const find = (id: string) => {\n const file = files.find(item => item.id === id);\n if (!file) throw new Error('document not found');\n return file;\n };\n const own = (file: MemoryFile, commentId: string) => {\n const found = file.comments?.find(c => c.id === commentId);\n if (!found || found.author.id !== me.id) throw new Error('only the author changes a comment');\n return found;\n };\n const summary = (file: MemoryFile) => ({\n id: file.id, spaceId: file.spaceId, name: file.name, kind: kindOf(file.name)!, size: encode(file.bytes).byteLength,\n updatedAt: file.updatedAt ?? '2026-10-19T09:00:00Z', updatedBy: me, createdAt: '2026-10-01T09:00:00Z', createdBy: me, folder: file.folder ?? null,\n });\n const archive = (file: MemoryFile, bytes: Bytes, note?: string) => {\n const versions = [{ id: file.version ?? `v${(file.versions?.length ?? 0) + 1}`, createdAt: file.updatedAt ?? '2026-10-19T09:00:00Z', bytes: file.bytes, note: file.note }, ...(file.versions ?? [])];\n const version = `v${versions.length + 1}`;\n Object.assign(file, { versions, version, bytes, note, updatedAt: new Date().toISOString() });\n return version;\n };\n return {\n me,\n ...(collab ? { collab: { url: `memory:${collab}`, token: async () => me.id } } : {}),\n spaces: async () => spaces,\n documents: async spaceId => files.filter(file => file.spaceId === spaceId && kindOf(file.name)).map(summary),\n document: async id => ({ ...summary(find(id)), rights: { view: true, comment: true, edit: true, ...find(id).rights }, live: !!collab }),\n versions: async id => {\n const file = find(id);\n return [\n { id: file.version ?? 'current', createdAt: summary(file).updatedAt, size: summary(file).size, author: me, note: file.note ?? null, current: true },\n ...(file.versions ?? []).map(v => ({ id: v.id, createdAt: v.createdAt, size: encode(v.bytes).byteLength, author: me, note: v.note ?? null, current: false })),\n ];\n },\n content: async (id, versionId) => {\n const file = find(id);\n const old = versionId && versionId !== 'current' && versionId !== file.version ? file.versions?.find(v => v.id === versionId) : undefined;\n return encode(old ? old.bytes : file.bytes);\n },\n restore: async (id, versionId) => {\n const file = find(id);\n const old = file.versions?.find(v => v.id === versionId);\n if (!old) throw new Error('version not found');\n archive(file, old.bytes);\n },\n save: async (id, bytes, note) => ({ versionId: archive(find(id), bytes, note) }),\n signatures: async id => [...(find(id).signatures ?? [])].reverse(),\n sign: async (id, entry) => {\n const file = find(id);\n const signature = { id: `s${(file.signatures?.length ?? 0) + 1}`, signer: me, signedAt: new Date().toISOString(), ...entry };\n file.signatures = [...(file.signatures ?? []), signature];\n return signature;\n },\n comments: async id => [...(find(id).comments ?? [])],\n people: async () => [me, ...people],\n comment: async (id, entry) => {\n const file = find(id);\n let n = (file.comments?.length ?? 0) + 1;\n while (file.comments?.some(c => c.id === `c${n}`)) n++;\n const made: Comment = { id: `c${n}`, documentId: id, author: me, body: entry.body, createdAt: new Date().toISOString(), quote: entry.quote, replyTo: entry.replyTo, resolved: false,\n assignee: people.find(p => p.id === entry.assignee) ?? null };\n file.comments = [...(file.comments ?? []), made];\n return made;\n },\n resolveComment: async (id, commentId, resolved) => {\n const file = find(id);\n file.comments = (file.comments ?? []).map(c => c.id === commentId ? { ...c, resolved } : c);\n },\n editComment: async (id, commentId, body) => {\n const file = find(id);\n const mine = own(file, commentId);\n const edited = { ...mine, body };\n file.comments = file.comments!.map(c => c === mine ? edited : c);\n return edited;\n },\n deleteComment: async (id, commentId) => {\n const file = find(id);\n if (!file.comments?.find(c => c.id === commentId)?.author.id.startsWith('guest:')) own(file, commentId);\n file.comments = file.comments!.filter(c => c.id !== commentId && c.replyTo !== commentId);\n },\n rename: async (id, name) => { find(id).name = name; },\n href: id => `https://docs.test/${id}`,\n remove: async id => { files.splice(files.indexOf(find(id)), 1); },\n templates: async () => files.filter(file => file.folder === 'Templates').map(summary),\n saveTemplate: async id => {\n const from = find(id);\n const file = { id: `t${files.length + 1}`, spaceId: from.spaceId, name: from.name, folder: 'Templates', bytes: from.bytes, updatedAt: new Date().toISOString() };\n files.push(file);\n return summary(file);\n },\n search: async text => files.flatMap(file => {\n const body = typeof file.bytes === 'string' && /\\.(md|txt)$/.test(file.name) ? file.bytes.replace(/\\s+/g, ' ') : '';\n const at = body.toLocaleLowerCase().indexOf(text.toLocaleLowerCase());\n return at < 0 ? [] : [{ id: file.id, excerpt: `${body.slice(Math.max(0, at - 30), at)}«${body.slice(at, at + text.length)}»${body.slice(at + text.length, at + text.length + 40)}` }];\n }),\n exportAs: async (id, format) => {\n const file = find(id);\n if ((format === 'md' ? 'markdown' : format) !== kindOf(file.name)) throw new Error('this format needs a converter on the host');\n return new Blob([encode(file.bytes)], { type: mimes[format] });\n },\n ...(spaces.length ? {\n createIn: `${spaces[0].name} / Documents`,\n create: async ({ name, bytes, near }: { name: string; bytes: ArrayBuffer; near?: string }) => {\n const by = near ? find(near) : null;\n const file = { id: `new-${files.length + 1}`, spaceId: by?.spaceId ?? spaces[0].id, name, folder: by ? by.folder : 'Documents', bytes, updatedAt: new Date().toISOString() };\n files.push(file);\n return summary(file);\n },\n } : {}),\n };\n}\n"],"mappings":";;;;;;AAoBA,IAAM,QAAQ,EAAE,KAAK,mBAAmB,MAAM,2EAA2E,IAAI,gBAAgB;AAE7I,IAAM,SAAS,CAAC,UAAiB,OAAO,UAAU,WAAW,IAAI,YAAY,EAAE,OAAO,KAAK,EAAE,SAAwB;AAE9G,SAAS,WAAW,EAAE,IAAI,QAAQ,OAAO,QAAQ,SAAS,CAAC,EAAE,GAA4G;AAC9K,QAAM,OAAO,CAAC,OAAe;AAC3B,UAAM,OAAO,MAAM,KAAK,UAAQ,KAAK,OAAO,EAAE;AAC9C,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,oBAAoB;AAC/C,WAAO;AAAA,EACT;AACA,QAAM,MAAM,CAAC,MAAkB,cAAsB;AACnD,UAAM,QAAQ,KAAK,UAAU,KAA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AK,IAAI,SAAS,GAAG,KAAK,MAAM,KAAK,IAAI,GAAG,KAAK,EAAE,GAAG,EAAE,CAAC,OAAI,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM,CAAC,OAAI,KAAK,MAAM,KAAK,KAAK,QAAQ,KAAK,KAAK,SAAS,EAAE,CAAC,GAAG,CAAC;AAAA,IACtL,CAAC;AAAA,IACD,UAAU,OAAO,IAAI,WAAW;AAC9B,YAAM,OAAO,KAAK,EAAE;AACpB,WAAK,WAAW,OAAO,aAAa,YAAY,OAAO,KAAK,IAAI,EAAG,OAAM,IAAI,MAAM,2CAA2C;AAC9H,aAAO,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,GAAG,EAAE,MAAM,MAAM,MAAM,EAAE,CAAC;AAAA,IAC/D;AAAA,IACA,GAAI,OAAO,SAAS;AAAA,MAClB,UAAU,GAAG,OAAO,CAAC,EAAE,IAAI;AAAA,MAC3B,QAAQ,OAAO,EAAE,MAAM,OAAO,KAAK,MAA2D;AAC5F,cAAM,KAAK,OAAO,KAAK,IAAI,IAAI;AAC/B,cAAM,OAAO,EAAE,IAAI,OAAO,MAAM,SAAS,CAAC,IAAI,SAAS,IAAI,WAAW,OAAO,CAAC,EAAE,IAAI,MAAM,QAAQ,KAAK,GAAG,SAAS,aAAa,OAAO,YAAW,oBAAI,KAAK,GAAE,YAAY,EAAE;AAC3K,cAAM,KAAK,IAAI;AACf,eAAO,QAAQ,IAAI;AAAA,MACrB;AAAA,IACF,IAAI,CAAC;AAAA,EACP;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/memory.ts"],"sourcesContent":["import { kindOf } from './kinds';\nimport type { Comment, DocumentsHost, Person, Rights, Signature, Space } from './types';\n\ntype Bytes = ArrayBuffer | string;\n\nexport type MemoryFile = {\n id: string;\n spaceId: string;\n name: string;\n folder?: string;\n bytes: Bytes;\n version?: string;\n note?: string;\n updatedAt?: string;\n rights?: Partial<Rights>;\n versions?: { id: string; createdAt: string; bytes: Bytes; note?: string }[];\n signatures?: Signature[];\n comments?: Comment[];\n};\n\nconst mimes = { pdf: 'application/pdf', docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', md: 'text/markdown' };\n\nconst encode = (bytes: Bytes) => typeof bytes === 'string' ? new TextEncoder().encode(bytes).buffer as ArrayBuffer : bytes;\n\nexport function memoryHost({ me, spaces, files, collab, people = [] }: { me: Person; spaces: Space[]; files: MemoryFile[]; collab?: string; people?: Person[] }): DocumentsHost {\n const find = (id: string) => {\n const file = files.find(item => item.id === id);\n if (!file) throw new Error('document not found');\n return file;\n };\n const own = (file: MemoryFile, commentId: string) => {\n const found = file.comments?.find(c => c.id === commentId);\n if (!found || found.author.id !== me.id) throw new Error('only the author changes a comment');\n return found;\n };\n const made = new Set<string>();\n const within = (folder: string | undefined, path: string) => folder === path || (folder ?? '').startsWith(`${path}/`);\n const moved = (folder: string, from: string, to: string) => to + folder.slice(from.length);\n const summary = (file: MemoryFile) => ({\n id: file.id, spaceId: file.spaceId, name: file.name, kind: kindOf(file.name)!, size: encode(file.bytes).byteLength,\n updatedAt: file.updatedAt ?? '2026-10-19T09:00:00Z', updatedBy: me, createdAt: '2026-10-01T09:00:00Z', createdBy: me, folder: file.folder ?? null,\n });\n const archive = (file: MemoryFile, bytes: Bytes, note?: string) => {\n const versions = [{ id: file.version ?? `v${(file.versions?.length ?? 0) + 1}`, createdAt: file.updatedAt ?? '2026-10-19T09:00:00Z', bytes: file.bytes, note: file.note }, ...(file.versions ?? [])];\n const version = `v${versions.length + 1}`;\n Object.assign(file, { versions, version, bytes, note, updatedAt: new Date().toISOString() });\n return version;\n };\n return {\n me,\n ...(collab ? { collab: { url: `memory:${collab}`, token: async () => me.id } } : {}),\n spaces: async () => spaces,\n documents: async spaceId => files.filter(file => file.spaceId === spaceId && kindOf(file.name)).map(summary),\n document: async id => ({ ...summary(find(id)), rights: { view: true, comment: true, edit: true, ...find(id).rights }, live: !!collab }),\n versions: async id => {\n const file = find(id);\n return [\n { id: file.version ?? 'current', createdAt: summary(file).updatedAt, size: summary(file).size, author: me, note: file.note ?? null, current: true },\n ...(file.versions ?? []).map(v => ({ id: v.id, createdAt: v.createdAt, size: encode(v.bytes).byteLength, author: me, note: v.note ?? null, current: false })),\n ];\n },\n content: async (id, versionId) => {\n const file = find(id);\n const old = versionId && versionId !== 'current' && versionId !== file.version ? file.versions?.find(v => v.id === versionId) : undefined;\n return encode(old ? old.bytes : file.bytes);\n },\n restore: async (id, versionId) => {\n const file = find(id);\n const old = file.versions?.find(v => v.id === versionId);\n if (!old) throw new Error('version not found');\n archive(file, old.bytes);\n },\n save: async (id, bytes, note) => ({ versionId: archive(find(id), bytes, note) }),\n signatures: async id => [...(find(id).signatures ?? [])].reverse(),\n sign: async (id, entry) => {\n const file = find(id);\n const signature = { id: `s${(file.signatures?.length ?? 0) + 1}`, signer: me, signedAt: new Date().toISOString(), ...entry };\n file.signatures = [...(file.signatures ?? []), signature];\n return signature;\n },\n comments: async id => [...(find(id).comments ?? [])],\n people: async () => [me, ...people],\n comment: async (id, entry) => {\n const file = find(id);\n let n = (file.comments?.length ?? 0) + 1;\n while (file.comments?.some(c => c.id === `c${n}`)) n++;\n const made: Comment = { id: `c${n}`, documentId: id, author: me, body: entry.body, createdAt: new Date().toISOString(), quote: entry.quote, replyTo: entry.replyTo, resolved: false,\n assignee: people.find(p => p.id === entry.assignee) ?? null };\n file.comments = [...(file.comments ?? []), made];\n return made;\n },\n resolveComment: async (id, commentId, resolved) => {\n const file = find(id);\n file.comments = (file.comments ?? []).map(c => c.id === commentId ? { ...c, resolved } : c);\n },\n editComment: async (id, commentId, body) => {\n const file = find(id);\n const mine = own(file, commentId);\n const edited = { ...mine, body };\n file.comments = file.comments!.map(c => c === mine ? edited : c);\n return edited;\n },\n deleteComment: async (id, commentId) => {\n const file = find(id);\n if (!file.comments?.find(c => c.id === commentId)?.author.id.startsWith('guest:')) own(file, commentId);\n file.comments = file.comments!.filter(c => c.id !== commentId && c.replyTo !== commentId);\n },\n rename: async (id, name) => { find(id).name = name; },\n href: id => `https://docs.test/${id}`,\n remove: async id => { files.splice(files.indexOf(find(id)), 1); },\n folders: async spaceId => {\n const all = new Set([...made].filter(key => key.startsWith(`${spaceId}:`)).map(key => key.slice(spaceId.length + 1)));\n for (const file of files) if (file.spaceId === spaceId && file.folder) file.folder.split('/').forEach((_, i, parts) => all.add(parts.slice(0, i + 1).join('/')));\n return [...all].sort();\n },\n makeFolder: async ({ spaceId, folder }, name) => { made.add(`${spaceId}:${folder ? `${folder}/` : ''}${name}`); },\n renameFolder: async ({ spaceId, folder }, name) => {\n const to = [...folder.split('/').slice(0, -1), name].join('/');\n for (const file of files) if (file.spaceId === spaceId && within(file.folder, folder)) file.folder = moved(file.folder!, folder, to);\n for (const key of [...made]) if (key.startsWith(`${spaceId}:`) && within(key.slice(spaceId.length + 1), folder)) {\n made.delete(key);\n made.add(`${spaceId}:${moved(key.slice(spaceId.length + 1), folder, to)}`);\n }\n },\n removeFolder: async ({ spaceId, folder }) => {\n for (const file of files.filter(file => file.spaceId === spaceId && within(file.folder, folder))) files.splice(files.indexOf(file), 1);\n for (const key of [...made]) if (key.startsWith(`${spaceId}:`) && within(key.slice(spaceId.length + 1), folder)) made.delete(key);\n },\n move: async (id, { spaceId, folder }) => {\n const file = find(id);\n if (file.folder) made.add(`${file.spaceId}:${file.folder}`);\n Object.assign(file, { spaceId, folder: folder || undefined });\n },\n templates: async () => files.filter(file => file.folder === 'Templates').map(summary),\n saveTemplate: async id => {\n const from = find(id);\n const file = { id: `t${files.length + 1}`, spaceId: from.spaceId, name: from.name, folder: 'Templates', bytes: from.bytes, updatedAt: new Date().toISOString() };\n files.push(file);\n return summary(file);\n },\n search: async text => files.flatMap(file => {\n const body = typeof file.bytes === 'string' && /\\.(md|txt)$/.test(file.name) ? file.bytes.replace(/\\s+/g, ' ') : '';\n const at = body.toLocaleLowerCase().indexOf(text.toLocaleLowerCase());\n return at < 0 ? [] : [{ id: file.id, excerpt: `${body.slice(Math.max(0, at - 30), at)}«${body.slice(at, at + text.length)}»${body.slice(at + text.length, at + text.length + 40)}` }];\n }),\n exportAs: async (id, format) => {\n const file = find(id);\n if ((format === 'md' ? 'markdown' : format) !== kindOf(file.name)) throw new Error('this format needs a converter on the host');\n return new Blob([encode(file.bytes)], { type: mimes[format] });\n },\n ...(spaces.length ? {\n createIn: `${spaces[0].name} / Documents`,\n create: async ({ name, bytes, near, at }: { name: string; bytes: ArrayBuffer; near?: string; at?: { spaceId: string; folder: string } }) => {\n const by = near ? find(near) : null;\n const file = { id: `new-${files.length + 1}`, spaceId: at?.spaceId ?? by?.spaceId ?? spaces[0].id, name, folder: at ? at.folder || undefined : by ? by.folder : 'Documents', bytes, updatedAt: new Date().toISOString() };\n files.push(file);\n return summary(file);\n },\n } : {}),\n };\n}\n"],"mappings":";;;;;;AAoBA,IAAM,QAAQ,EAAE,KAAK,mBAAmB,MAAM,2EAA2E,IAAI,gBAAgB;AAE7I,IAAM,SAAS,CAAC,UAAiB,OAAO,UAAU,WAAW,IAAI,YAAY,EAAE,OAAO,KAAK,EAAE,SAAwB;AAE9G,SAAS,WAAW,EAAE,IAAI,QAAQ,OAAO,QAAQ,SAAS,CAAC,EAAE,GAA4G;AAC9K,QAAM,OAAO,CAAC,OAAe;AAC3B,UAAM,OAAO,MAAM,KAAK,UAAQ,KAAK,OAAO,EAAE;AAC9C,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,oBAAoB;AAC/C,WAAO;AAAA,EACT;AACA,QAAM,MAAM,CAAC,MAAkB,cAAsB;AACnD,UAAM,QAAQ,KAAK,UAAU,KAAK,OAAK,EAAE,OAAO,SAAS;AACzD,QAAI,CAAC,SAAS,MAAM,OAAO,OAAO,GAAG,GAAI,OAAM,IAAI,MAAM,mCAAmC;AAC5F,WAAO;AAAA,EACT;AACA,QAAM,OAAO,oBAAI,IAAY;AAC7B,QAAM,SAAS,CAAC,QAA4B,SAAiB,WAAW,SAAS,UAAU,IAAI,WAAW,GAAG,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,IAAI,SAAS,IAAI,WAAW,IAAI,WAAW,OAAO,CAAC,EAAE,IAAI,MAAM,QAAQ,KAAK,GAAG,UAAU,SAAY,KAAK,GAAG,SAAS,aAAa,OAAO,YAAW,oBAAI,KAAK,GAAE,YAAY,EAAE;AACxN,cAAM,KAAK,IAAI;AACf,eAAO,QAAQ,IAAI;AAAA,MACrB;AAAA,IACF,IAAI,CAAC;AAAA,EACP;AACF;","names":["made","file"]}
@@ -168,7 +168,13 @@ interface DocumentsHost {
168
168
  bytes: ArrayBuffer;
169
169
  mimeType: string;
170
170
  near?: string;
171
+ at?: FolderPlace;
171
172
  }): Promise<DocumentSummary>;
173
+ folders?(spaceId: string, opts?: Fetch): Promise<string[]>;
174
+ makeFolder?(at: FolderPlace, name: string): Promise<void>;
175
+ renameFolder?(at: FolderPlace, name: string): Promise<void>;
176
+ removeFolder?(at: FolderPlace): Promise<void>;
177
+ move?(id: string, to: FolderPlace): Promise<void>;
172
178
  createIn?: string;
173
179
  links?(id: string, opts?: Fetch): Promise<GuestLink[]>;
174
180
  share?(id: string, entry: LinkEntry): Promise<GuestLink>;
@@ -183,5 +189,9 @@ type Place = {
183
189
  spaceId: string | null;
184
190
  documentId: string | null;
185
191
  };
192
+ type FolderPlace = {
193
+ spaceId: string;
194
+ folder: string;
195
+ };
186
196
 
187
- export type { Comment as C, DocumentsHost as D, Fetch as F, GuestHost as G, Language as L, Place as P, Rights as R, Signature as S, DocumentFile as a, DocumentKind as b, DocumentSummary as c, DocumentVersion as d, GuestFile as e, GuestLink as f, LinkEntry as g, Person as h, SignatureMethod as i, Space as j };
197
+ export type { Comment as C, DocumentsHost as D, Fetch as F, GuestHost as G, Language as L, Place as P, Rights as R, Signature as S, DocumentFile as a, DocumentKind as b, DocumentSummary as c, DocumentVersion as d, FolderPlace as e, GuestFile as f, GuestLink as g, LinkEntry as h, Person as i, SignatureMethod as j, Space as k };
@@ -168,7 +168,13 @@ interface DocumentsHost {
168
168
  bytes: ArrayBuffer;
169
169
  mimeType: string;
170
170
  near?: string;
171
+ at?: FolderPlace;
171
172
  }): Promise<DocumentSummary>;
173
+ folders?(spaceId: string, opts?: Fetch): Promise<string[]>;
174
+ makeFolder?(at: FolderPlace, name: string): Promise<void>;
175
+ renameFolder?(at: FolderPlace, name: string): Promise<void>;
176
+ removeFolder?(at: FolderPlace): Promise<void>;
177
+ move?(id: string, to: FolderPlace): Promise<void>;
172
178
  createIn?: string;
173
179
  links?(id: string, opts?: Fetch): Promise<GuestLink[]>;
174
180
  share?(id: string, entry: LinkEntry): Promise<GuestLink>;
@@ -183,5 +189,9 @@ type Place = {
183
189
  spaceId: string | null;
184
190
  documentId: string | null;
185
191
  };
192
+ type FolderPlace = {
193
+ spaceId: string;
194
+ folder: string;
195
+ };
186
196
 
187
- export type { Comment as C, DocumentsHost as D, Fetch as F, GuestHost as G, Language as L, Place as P, Rights as R, Signature as S, DocumentFile as a, DocumentKind as b, DocumentSummary as c, DocumentVersion as d, GuestFile as e, GuestLink as f, LinkEntry as g, Person as h, SignatureMethod as i, Space as j };
197
+ export type { Comment as C, DocumentsHost as D, Fetch as F, GuestHost as G, Language as L, Place as P, Rights as R, Signature as S, DocumentFile as a, DocumentKind as b, DocumentSummary as c, DocumentVersion as d, FolderPlace as e, GuestFile as f, GuestLink as g, LinkEntry as h, Person as i, SignatureMethod as j, Space as k };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w100n/documents",
3
- "version": "0.17.0",
3
+ "version": "0.18.1",
4
4
  "description": "Documents workspace for Web100Now projects: DOCX, Markdown, PDF, slides and sheets",
5
5
  "license": "MIT",
6
6
  "type": "module",