@w100n/documents 0.16.0 → 0.16.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.
- package/dist/{SheetView-EFBSMY7K.js → SheetView-FVLKQR7J.js} +4 -4
- package/dist/{TextEditor-MGCSGGGA.js → TextEditor-BF6HCNHL.js} +389 -343
- package/dist/TextEditor-BF6HCNHL.js.map +1 -0
- package/dist/{chunk-2L3TK7UF.js → chunk-GN3ZOD36.js} +3 -3
- package/dist/{chunk-2L3TK7UF.js.map → chunk-GN3ZOD36.js.map} +1 -1
- package/dist/{chunk-RKV3N6OS.js → chunk-LZYITB56.js} +22 -1
- package/dist/chunk-LZYITB56.js.map +1 -0
- package/dist/{chunk-3OLRFIHQ.js → chunk-NPVH2YDI.js} +2 -2
- package/dist/collab.cjs +22 -1
- package/dist/collab.cjs.map +1 -1
- package/dist/collab.d.cts +1 -1
- package/dist/collab.d.ts +1 -1
- package/dist/collab.js +2 -2
- package/dist/index.cjs +992 -873
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +52 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +58 -14
- package/dist/index.js.map +1 -1
- package/dist/kinds.d.cts +1 -1
- package/dist/kinds.d.ts +1 -1
- package/dist/memory.cjs +25 -2
- package/dist/memory.cjs.map +1 -1
- package/dist/memory.d.cts +3 -2
- package/dist/memory.d.ts +3 -2
- package/dist/memory.js +25 -2
- package/dist/memory.js.map +1 -1
- package/dist/{types-BTsVooZw.d.cts → types-DNcaU6SK.d.cts} +9 -0
- package/dist/{types-BTsVooZw.d.ts → types-DNcaU6SK.d.ts} +9 -0
- package/package.json +1 -1
- package/dist/TextEditor-MGCSGGGA.js.map +0 -1
- package/dist/chunk-RKV3N6OS.js.map +0 -1
- /package/dist/{SheetView-EFBSMY7K.js.map → SheetView-FVLKQR7J.js.map} +0 -0
- /package/dist/{chunk-3OLRFIHQ.js.map → chunk-NPVH2YDI.js.map} +0 -0
package/dist/kinds.d.cts
CHANGED
package/dist/kinds.d.ts
CHANGED
package/dist/memory.cjs
CHANGED
|
@@ -55,7 +55,7 @@ function kindOf(name, mimeType) {
|
|
|
55
55
|
// src/memory.ts
|
|
56
56
|
var mimes = { pdf: "application/pdf", docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", md: "text/markdown" };
|
|
57
57
|
var encode = (bytes) => typeof bytes === "string" ? new TextEncoder().encode(bytes).buffer : bytes;
|
|
58
|
-
function memoryHost({ me, spaces, files, collab }) {
|
|
58
|
+
function memoryHost({ me, spaces, files, collab, people = [] }) {
|
|
59
59
|
const find = (id) => {
|
|
60
60
|
const file = files.find((item) => item.id === id);
|
|
61
61
|
if (!file) throw new Error("document not found");
|
|
@@ -115,11 +115,22 @@ function memoryHost({ me, spaces, files, collab }) {
|
|
|
115
115
|
return signature;
|
|
116
116
|
},
|
|
117
117
|
comments: async (id) => [...find(id).comments ?? []],
|
|
118
|
+
people: async () => [me, ...people],
|
|
118
119
|
comment: async (id, entry) => {
|
|
119
120
|
const file = find(id);
|
|
120
121
|
let n = (file.comments?.length ?? 0) + 1;
|
|
121
122
|
while (file.comments?.some((c) => c.id === `c${n}`)) n++;
|
|
122
|
-
const made = {
|
|
123
|
+
const made = {
|
|
124
|
+
id: `c${n}`,
|
|
125
|
+
documentId: id,
|
|
126
|
+
author: me,
|
|
127
|
+
body: entry.body,
|
|
128
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
129
|
+
quote: entry.quote,
|
|
130
|
+
replyTo: entry.replyTo,
|
|
131
|
+
resolved: false,
|
|
132
|
+
assignee: people.find((p) => p.id === entry.assignee) ?? null
|
|
133
|
+
};
|
|
123
134
|
file.comments = [...file.comments ?? [], made];
|
|
124
135
|
return made;
|
|
125
136
|
},
|
|
@@ -142,6 +153,18 @@ function memoryHost({ me, spaces, files, collab }) {
|
|
|
142
153
|
rename: async (id, name) => {
|
|
143
154
|
find(id).name = name;
|
|
144
155
|
},
|
|
156
|
+
templates: async () => files.filter((file) => file.folder === "Templates").map(summary),
|
|
157
|
+
saveTemplate: async (id) => {
|
|
158
|
+
const from = find(id);
|
|
159
|
+
const file = { id: `t${files.length + 1}`, spaceId: from.spaceId, name: from.name, folder: "Templates", bytes: from.bytes, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
160
|
+
files.push(file);
|
|
161
|
+
return summary(file);
|
|
162
|
+
},
|
|
163
|
+
search: async (text) => files.flatMap((file) => {
|
|
164
|
+
const body = typeof file.bytes === "string" && /\.(md|txt)$/.test(file.name) ? file.bytes.replace(/\s+/g, " ") : "";
|
|
165
|
+
const at = body.toLocaleLowerCase().indexOf(text.toLocaleLowerCase());
|
|
166
|
+
return at < 0 ? [] : [{ id: file.id, excerpt: `${body.slice(Math.max(0, at - 30), at)}\xAB${body.slice(at, at + text.length)}\xBB${body.slice(at + text.length, at + text.length + 40)}` }];
|
|
167
|
+
}),
|
|
145
168
|
exportAs: async (id, format) => {
|
|
146
169
|
const file = find(id);
|
|
147
170
|
if ((format === "md" ? "markdown" : format) !== kindOf(file.name)) throw new Error("this format needs a converter on the host");
|
package/dist/memory.cjs.map
CHANGED
|
@@ -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 }: { me: Person; spaces: Space[]; files: MemoryFile[]; collab?: string }): 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, 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 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 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 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 }: { name: string; bytes: ArrayBuffer }) => {\n const file = { id: `new-${files.length + 1}`, spaceId: spaces[0].id, name, 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,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,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,MAAM,MAA4C;AACvE,cAAM,OAAO,EAAE,IAAI,OAAO,MAAM,SAAS,CAAC,IAAI,SAAS,OAAO,CAAC,EAAE,IAAI,MAAM,QAAQ,aAAa,OAAO,YAAW,oBAAI,KAAK,GAAE,YAAY,EAAE;AAC3I,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 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, 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 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 }: { name: string; bytes: ArrayBuffer }) => {\n const file = { id: `new-${files.length + 1}`, spaceId: spaces[0].id, name, 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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AAG,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,MAAM,MAA4C;AACvE,cAAM,OAAO,EAAE,IAAI,OAAO,MAAM,SAAS,CAAC,IAAI,SAAS,OAAO,CAAC,EAAE,IAAI,MAAM,QAAQ,aAAa,OAAO,YAAW,oBAAI,KAAK,GAAE,YAAY,EAAE;AAC3I,cAAM,KAAK,IAAI;AACf,eAAO,QAAQ,IAAI;AAAA,MACrB;AAAA,IACF,IAAI,CAAC;AAAA,EACP;AACF;","names":[]}
|
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-
|
|
1
|
+
import { R as Rights, S as Signature, C as Comment, h as Person, j as Space, D as DocumentsHost } from './types-DNcaU6SK.cjs';
|
|
2
2
|
|
|
3
3
|
type Bytes = ArrayBuffer | string;
|
|
4
4
|
type MemoryFile = {
|
|
@@ -20,11 +20,12 @@ type MemoryFile = {
|
|
|
20
20
|
signatures?: Signature[];
|
|
21
21
|
comments?: Comment[];
|
|
22
22
|
};
|
|
23
|
-
declare function memoryHost({ me, spaces, files, collab }: {
|
|
23
|
+
declare function memoryHost({ me, spaces, files, collab, people }: {
|
|
24
24
|
me: Person;
|
|
25
25
|
spaces: Space[];
|
|
26
26
|
files: MemoryFile[];
|
|
27
27
|
collab?: string;
|
|
28
|
+
people?: Person[];
|
|
28
29
|
}): DocumentsHost;
|
|
29
30
|
|
|
30
31
|
export { type MemoryFile, memoryHost };
|
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-
|
|
1
|
+
import { R as Rights, S as Signature, C as Comment, h as Person, j as Space, D as DocumentsHost } from './types-DNcaU6SK.js';
|
|
2
2
|
|
|
3
3
|
type Bytes = ArrayBuffer | string;
|
|
4
4
|
type MemoryFile = {
|
|
@@ -20,11 +20,12 @@ type MemoryFile = {
|
|
|
20
20
|
signatures?: Signature[];
|
|
21
21
|
comments?: Comment[];
|
|
22
22
|
};
|
|
23
|
-
declare function memoryHost({ me, spaces, files, collab }: {
|
|
23
|
+
declare function memoryHost({ me, spaces, files, collab, people }: {
|
|
24
24
|
me: Person;
|
|
25
25
|
spaces: Space[];
|
|
26
26
|
files: MemoryFile[];
|
|
27
27
|
collab?: string;
|
|
28
|
+
people?: Person[];
|
|
28
29
|
}): DocumentsHost;
|
|
29
30
|
|
|
30
31
|
export { type MemoryFile, memoryHost };
|
package/dist/memory.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
// src/memory.ts
|
|
7
7
|
var mimes = { pdf: "application/pdf", docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", md: "text/markdown" };
|
|
8
8
|
var encode = (bytes) => typeof bytes === "string" ? new TextEncoder().encode(bytes).buffer : bytes;
|
|
9
|
-
function memoryHost({ me, spaces, files, collab }) {
|
|
9
|
+
function memoryHost({ me, spaces, files, collab, people = [] }) {
|
|
10
10
|
const find = (id) => {
|
|
11
11
|
const file = files.find((item) => item.id === id);
|
|
12
12
|
if (!file) throw new Error("document not found");
|
|
@@ -66,11 +66,22 @@ function memoryHost({ me, spaces, files, collab }) {
|
|
|
66
66
|
return signature;
|
|
67
67
|
},
|
|
68
68
|
comments: async (id) => [...find(id).comments ?? []],
|
|
69
|
+
people: async () => [me, ...people],
|
|
69
70
|
comment: async (id, entry) => {
|
|
70
71
|
const file = find(id);
|
|
71
72
|
let n = (file.comments?.length ?? 0) + 1;
|
|
72
73
|
while (file.comments?.some((c) => c.id === `c${n}`)) n++;
|
|
73
|
-
const made = {
|
|
74
|
+
const made = {
|
|
75
|
+
id: `c${n}`,
|
|
76
|
+
documentId: id,
|
|
77
|
+
author: me,
|
|
78
|
+
body: entry.body,
|
|
79
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
80
|
+
quote: entry.quote,
|
|
81
|
+
replyTo: entry.replyTo,
|
|
82
|
+
resolved: false,
|
|
83
|
+
assignee: people.find((p) => p.id === entry.assignee) ?? null
|
|
84
|
+
};
|
|
74
85
|
file.comments = [...file.comments ?? [], made];
|
|
75
86
|
return made;
|
|
76
87
|
},
|
|
@@ -93,6 +104,18 @@ function memoryHost({ me, spaces, files, collab }) {
|
|
|
93
104
|
rename: async (id, name) => {
|
|
94
105
|
find(id).name = name;
|
|
95
106
|
},
|
|
107
|
+
templates: async () => files.filter((file) => file.folder === "Templates").map(summary),
|
|
108
|
+
saveTemplate: async (id) => {
|
|
109
|
+
const from = find(id);
|
|
110
|
+
const file = { id: `t${files.length + 1}`, spaceId: from.spaceId, name: from.name, folder: "Templates", bytes: from.bytes, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
111
|
+
files.push(file);
|
|
112
|
+
return summary(file);
|
|
113
|
+
},
|
|
114
|
+
search: async (text) => files.flatMap((file) => {
|
|
115
|
+
const body = typeof file.bytes === "string" && /\.(md|txt)$/.test(file.name) ? file.bytes.replace(/\s+/g, " ") : "";
|
|
116
|
+
const at = body.toLocaleLowerCase().indexOf(text.toLocaleLowerCase());
|
|
117
|
+
return at < 0 ? [] : [{ id: file.id, excerpt: `${body.slice(Math.max(0, at - 30), at)}\xAB${body.slice(at, at + text.length)}\xBB${body.slice(at + text.length, at + text.length + 40)}` }];
|
|
118
|
+
}),
|
|
96
119
|
exportAs: async (id, format) => {
|
|
97
120
|
const file = find(id);
|
|
98
121
|
if ((format === "md" ? "markdown" : format) !== kindOf(file.name)) throw new Error("this format needs a converter on the host");
|
package/dist/memory.js.map
CHANGED
|
@@ -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 }: { me: Person; spaces: Space[]; files: MemoryFile[]; collab?: string }): 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, 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 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 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 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 }: { name: string; bytes: ArrayBuffer }) => {\n const file = { id: `new-${files.length + 1}`, spaceId: spaces[0].id, name, 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,OAAO,GAAyF;AAC9I,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,UAAU,CAAC,UAAsB;AAAA,IACrC,IAAI,KAAK;AAAA,IAAI,SAAS,KAAK;AAAA,IAAS,MAAM,KAAK;AAAA,IAAM,MAAM,OAAO,KAAK,IAAI;AAAA,IAAI,MAAM,OAAO,KAAK,KAAK,EAAE;AAAA,IACxG,WAAW,KAAK,aAAa;AAAA,IAAwB,WAAW;AAAA,IAAI,QAAQ,KAAK,UAAU;AAAA,EAC7F;AACA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C,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,MAAM,MAA4C;AACvE,cAAM,OAAO,EAAE,IAAI,OAAO,MAAM,SAAS,CAAC,IAAI,SAAS,OAAO,CAAC,EAAE,IAAI,MAAM,QAAQ,aAAa,OAAO,YAAW,oBAAI,KAAK,GAAE,YAAY,EAAE;AAC3I,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 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, 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 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 }: { name: string; bytes: ArrayBuffer }) => {\n const file = { id: `new-${files.length + 1}`, spaceId: spaces[0].id, name, 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,UAAU,CAAC,UAAsB;AAAA,IACrC,IAAI,KAAK;AAAA,IAAI,SAAS,KAAK;AAAA,IAAS,MAAM,KAAK;AAAA,IAAM,MAAM,OAAO,KAAK,IAAI;AAAA,IAAI,MAAM,OAAO,KAAK,KAAK,EAAE;AAAA,IACxG,WAAW,KAAK,aAAa;AAAA,IAAwB,WAAW;AAAA,IAAI,QAAQ,KAAK,UAAU;AAAA,EAC7F;AACA,QAAM,UAAU,CAAC,MAAkB,OAAc,SAAkB;AACjE,UAAM,WAAW,CAAC,EAAE,IAAI,KAAK,WAAW,KAAK,KAAK,UAAU,UAAU,KAAK,CAAC,IAAI,WAAW,KAAK,aAAa,wBAAwB,OAAO,KA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GAAE,YAAY,EAAE;AAC3I,cAAM,KAAK,IAAI;AACf,eAAO,QAAQ,IAAI;AAAA,MACrB;AAAA,IACF,IAAI,CAAC;AAAA,EACP;AACF;","names":[]}
|
|
@@ -64,6 +64,7 @@ type Comment = {
|
|
|
64
64
|
quote: string;
|
|
65
65
|
replyTo: string | null;
|
|
66
66
|
resolved: boolean;
|
|
67
|
+
assignee?: Person | null;
|
|
67
68
|
};
|
|
68
69
|
type GuestLink = {
|
|
69
70
|
id: string;
|
|
@@ -142,13 +143,21 @@ interface DocumentsHost {
|
|
|
142
143
|
quote: string;
|
|
143
144
|
replyTo: string | null;
|
|
144
145
|
anchor: string;
|
|
146
|
+
assignee?: string | null;
|
|
145
147
|
}): Promise<Comment>;
|
|
148
|
+
people?(id: string, opts?: Fetch): Promise<Person[]>;
|
|
146
149
|
resolveComment?(id: string, commentId: string, resolved: boolean): Promise<void>;
|
|
147
150
|
editComment?(id: string, commentId: string, body: string): Promise<Comment>;
|
|
148
151
|
deleteComment?(id: string, commentId: string): Promise<void>;
|
|
149
152
|
exportAs?(id: string, format: 'pdf' | 'docx' | 'md'): Promise<Blob>;
|
|
150
153
|
copyAs?(id: string, format: 'xlsx'): Promise<DocumentSummary>;
|
|
151
154
|
rename?(id: string, name: string): Promise<void>;
|
|
155
|
+
search?(text: string, opts?: Fetch): Promise<{
|
|
156
|
+
id: string;
|
|
157
|
+
excerpt: string;
|
|
158
|
+
}[]>;
|
|
159
|
+
templates?(opts?: Fetch): Promise<DocumentSummary[]>;
|
|
160
|
+
saveTemplate?(id: string): Promise<DocumentSummary>;
|
|
152
161
|
create?(entry: {
|
|
153
162
|
name: string;
|
|
154
163
|
bytes: ArrayBuffer;
|
|
@@ -64,6 +64,7 @@ type Comment = {
|
|
|
64
64
|
quote: string;
|
|
65
65
|
replyTo: string | null;
|
|
66
66
|
resolved: boolean;
|
|
67
|
+
assignee?: Person | null;
|
|
67
68
|
};
|
|
68
69
|
type GuestLink = {
|
|
69
70
|
id: string;
|
|
@@ -142,13 +143,21 @@ interface DocumentsHost {
|
|
|
142
143
|
quote: string;
|
|
143
144
|
replyTo: string | null;
|
|
144
145
|
anchor: string;
|
|
146
|
+
assignee?: string | null;
|
|
145
147
|
}): Promise<Comment>;
|
|
148
|
+
people?(id: string, opts?: Fetch): Promise<Person[]>;
|
|
146
149
|
resolveComment?(id: string, commentId: string, resolved: boolean): Promise<void>;
|
|
147
150
|
editComment?(id: string, commentId: string, body: string): Promise<Comment>;
|
|
148
151
|
deleteComment?(id: string, commentId: string): Promise<void>;
|
|
149
152
|
exportAs?(id: string, format: 'pdf' | 'docx' | 'md'): Promise<Blob>;
|
|
150
153
|
copyAs?(id: string, format: 'xlsx'): Promise<DocumentSummary>;
|
|
151
154
|
rename?(id: string, name: string): Promise<void>;
|
|
155
|
+
search?(text: string, opts?: Fetch): Promise<{
|
|
156
|
+
id: string;
|
|
157
|
+
excerpt: string;
|
|
158
|
+
}[]>;
|
|
159
|
+
templates?(opts?: Fetch): Promise<DocumentSummary[]>;
|
|
160
|
+
saveTemplate?(id: string): Promise<DocumentSummary>;
|
|
152
161
|
create?(entry: {
|
|
153
162
|
name: string;
|
|
154
163
|
bytes: ArrayBuffer;
|