@w100n/documents 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-KEV4R7W5.js +37 -0
- package/dist/chunk-KEV4R7W5.js.map +1 -0
- package/dist/index.cjs +475 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +569 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +412 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.cjs +92 -0
- package/dist/memory.cjs.map +1 -0
- package/dist/memory.d.cts +24 -0
- package/dist/memory.d.ts +24 -0
- package/dist/memory.js +45 -0
- package/dist/memory.js.map +1 -0
- package/dist/types-aZrEQFiC.d.cts +57 -0
- package/dist/types-aZrEQFiC.d.ts +57 -0
- package/package.json +64 -0
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { R as Rights, e as Person, S as Space, D as DocumentsHost } from './types-aZrEQFiC.js';
|
|
2
|
+
|
|
3
|
+
type Bytes = ArrayBuffer | string;
|
|
4
|
+
type MemoryFile = {
|
|
5
|
+
id: string;
|
|
6
|
+
spaceId: string;
|
|
7
|
+
name: string;
|
|
8
|
+
bytes: Bytes;
|
|
9
|
+
updatedAt?: string;
|
|
10
|
+
rights?: Partial<Rights>;
|
|
11
|
+
versions?: {
|
|
12
|
+
id: string;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
bytes: Bytes;
|
|
15
|
+
note?: string;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
declare function memoryHost({ me, spaces, files }: {
|
|
19
|
+
me: Person;
|
|
20
|
+
spaces: Space[];
|
|
21
|
+
files: MemoryFile[];
|
|
22
|
+
}): DocumentsHost;
|
|
23
|
+
|
|
24
|
+
export { type MemoryFile, memoryHost };
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
kindOf
|
|
4
|
+
} from "./chunk-KEV4R7W5.js";
|
|
5
|
+
|
|
6
|
+
// src/memory.ts
|
|
7
|
+
var encode = (bytes) => typeof bytes === "string" ? new TextEncoder().encode(bytes).buffer : bytes;
|
|
8
|
+
function memoryHost({ me, spaces, files }) {
|
|
9
|
+
const find = (id) => {
|
|
10
|
+
const file = files.find((item) => item.id === id);
|
|
11
|
+
if (!file) throw new Error("document not found");
|
|
12
|
+
return file;
|
|
13
|
+
};
|
|
14
|
+
const summary = (file) => ({
|
|
15
|
+
id: file.id,
|
|
16
|
+
spaceId: file.spaceId,
|
|
17
|
+
name: file.name,
|
|
18
|
+
kind: kindOf(file.name),
|
|
19
|
+
size: encode(file.bytes).byteLength,
|
|
20
|
+
updatedAt: file.updatedAt ?? "2026-10-19T09:00:00Z",
|
|
21
|
+
updatedBy: me
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
me,
|
|
25
|
+
spaces: async () => spaces,
|
|
26
|
+
documents: async (spaceId) => files.filter((file) => file.spaceId === spaceId && kindOf(file.name)).map(summary),
|
|
27
|
+
document: async (id) => ({ ...summary(find(id)), rights: { view: true, comment: true, edit: true, ...find(id).rights } }),
|
|
28
|
+
versions: async (id) => {
|
|
29
|
+
const file = find(id);
|
|
30
|
+
return [
|
|
31
|
+
{ id: "current", createdAt: summary(file).updatedAt, size: summary(file).size, author: me, current: true },
|
|
32
|
+
...(file.versions ?? []).map((v) => ({ id: v.id, createdAt: v.createdAt, size: encode(v.bytes).byteLength, author: me, note: v.note ?? null, current: false }))
|
|
33
|
+
];
|
|
34
|
+
},
|
|
35
|
+
content: async (id, versionId) => {
|
|
36
|
+
const file = find(id);
|
|
37
|
+
const old = versionId && versionId !== "current" ? file.versions?.find((v) => v.id === versionId) : void 0;
|
|
38
|
+
return encode(old ? old.bytes : file.bytes);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
memoryHost
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/memory.ts"],"sourcesContent":["import { kindOf } from './kinds';\nimport type { DocumentsHost, Person, Rights, Space } from './types';\n\ntype Bytes = ArrayBuffer | string;\n\nexport type MemoryFile = {\n id: string;\n spaceId: string;\n name: string;\n bytes: Bytes;\n updatedAt?: string;\n rights?: Partial<Rights>;\n versions?: { id: string; createdAt: string; bytes: Bytes; note?: string }[];\n};\n\nconst encode = (bytes: Bytes) => typeof bytes === 'string' ? new TextEncoder().encode(bytes).buffer as ArrayBuffer : bytes;\n\nexport function memoryHost({ me, spaces, files }: { me: Person; spaces: Space[]; files: MemoryFile[] }): 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 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,\n });\n return {\n me,\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 } }),\n versions: async id => {\n const file = find(id);\n return [\n { id: 'current', createdAt: summary(file).updatedAt, size: summary(file).size, author: me, 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' ? file.versions?.find(v => v.id === versionId) : undefined;\n return encode(old ? old.bytes : file.bytes);\n },\n };\n}\n"],"mappings":";;;;;;AAeA,IAAM,SAAS,CAAC,UAAiB,OAAO,UAAU,WAAW,IAAI,YAAY,EAAE,OAAO,KAAK,EAAE,SAAwB;AA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AE;AACpB,YAAM,MAAM,aAAa,cAAc,YAAY,KAAK,UAAU,KAAK,OAAK,EAAE,OAAO,SAAS,IAAI;AAClG,aAAO,OAAO,MAAM,IAAI,QAAQ,KAAK,KAAK;AAAA,IAC5C;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
type DocumentKind = 'docx' | 'markdown' | 'pdf' | 'sheet' | 'slides';
|
|
2
|
+
type Language = 'en' | 'pl' | 'uk';
|
|
3
|
+
type Person = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
avatarUrl?: string | null;
|
|
7
|
+
};
|
|
8
|
+
type Space = {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
color?: string | null;
|
|
12
|
+
};
|
|
13
|
+
type Rights = {
|
|
14
|
+
view: boolean;
|
|
15
|
+
comment: boolean;
|
|
16
|
+
edit: boolean;
|
|
17
|
+
};
|
|
18
|
+
type DocumentSummary = {
|
|
19
|
+
id: string;
|
|
20
|
+
spaceId: string;
|
|
21
|
+
name: string;
|
|
22
|
+
kind: DocumentKind;
|
|
23
|
+
size: number;
|
|
24
|
+
updatedAt: string;
|
|
25
|
+
updatedBy?: Person | null;
|
|
26
|
+
thumbnailUrl?: string | null;
|
|
27
|
+
};
|
|
28
|
+
type DocumentFile = DocumentSummary & {
|
|
29
|
+
rights: Rights;
|
|
30
|
+
mimeType?: string | null;
|
|
31
|
+
};
|
|
32
|
+
type DocumentVersion = {
|
|
33
|
+
id: string;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
size: number;
|
|
36
|
+
author?: Person | null;
|
|
37
|
+
note?: string | null;
|
|
38
|
+
current: boolean;
|
|
39
|
+
};
|
|
40
|
+
type Fetch = {
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
};
|
|
43
|
+
interface DocumentsHost {
|
|
44
|
+
me: Person;
|
|
45
|
+
pdfWorker?: () => Worker;
|
|
46
|
+
spaces(opts?: Fetch): Promise<Space[]>;
|
|
47
|
+
documents(spaceId: string, opts?: Fetch): Promise<DocumentSummary[]>;
|
|
48
|
+
document(id: string, opts?: Fetch): Promise<DocumentFile>;
|
|
49
|
+
versions(id: string, opts?: Fetch): Promise<DocumentVersion[]>;
|
|
50
|
+
content(id: string, versionId?: string | null, opts?: Fetch): Promise<ArrayBuffer>;
|
|
51
|
+
}
|
|
52
|
+
type Place = {
|
|
53
|
+
spaceId: string | null;
|
|
54
|
+
documentId: string | null;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type { DocumentsHost as D, Fetch as F, Language as L, Place as P, Rights as R, Space as S, DocumentKind as a, DocumentFile as b, DocumentSummary as c, DocumentVersion as d, Person as e };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
type DocumentKind = 'docx' | 'markdown' | 'pdf' | 'sheet' | 'slides';
|
|
2
|
+
type Language = 'en' | 'pl' | 'uk';
|
|
3
|
+
type Person = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
avatarUrl?: string | null;
|
|
7
|
+
};
|
|
8
|
+
type Space = {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
color?: string | null;
|
|
12
|
+
};
|
|
13
|
+
type Rights = {
|
|
14
|
+
view: boolean;
|
|
15
|
+
comment: boolean;
|
|
16
|
+
edit: boolean;
|
|
17
|
+
};
|
|
18
|
+
type DocumentSummary = {
|
|
19
|
+
id: string;
|
|
20
|
+
spaceId: string;
|
|
21
|
+
name: string;
|
|
22
|
+
kind: DocumentKind;
|
|
23
|
+
size: number;
|
|
24
|
+
updatedAt: string;
|
|
25
|
+
updatedBy?: Person | null;
|
|
26
|
+
thumbnailUrl?: string | null;
|
|
27
|
+
};
|
|
28
|
+
type DocumentFile = DocumentSummary & {
|
|
29
|
+
rights: Rights;
|
|
30
|
+
mimeType?: string | null;
|
|
31
|
+
};
|
|
32
|
+
type DocumentVersion = {
|
|
33
|
+
id: string;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
size: number;
|
|
36
|
+
author?: Person | null;
|
|
37
|
+
note?: string | null;
|
|
38
|
+
current: boolean;
|
|
39
|
+
};
|
|
40
|
+
type Fetch = {
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
};
|
|
43
|
+
interface DocumentsHost {
|
|
44
|
+
me: Person;
|
|
45
|
+
pdfWorker?: () => Worker;
|
|
46
|
+
spaces(opts?: Fetch): Promise<Space[]>;
|
|
47
|
+
documents(spaceId: string, opts?: Fetch): Promise<DocumentSummary[]>;
|
|
48
|
+
document(id: string, opts?: Fetch): Promise<DocumentFile>;
|
|
49
|
+
versions(id: string, opts?: Fetch): Promise<DocumentVersion[]>;
|
|
50
|
+
content(id: string, versionId?: string | null, opts?: Fetch): Promise<ArrayBuffer>;
|
|
51
|
+
}
|
|
52
|
+
type Place = {
|
|
53
|
+
spaceId: string | null;
|
|
54
|
+
documentId: string | null;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type { DocumentsHost as D, Fetch as F, Language as L, Place as P, Rights as R, Space as S, DocumentKind as a, DocumentFile as b, DocumentSummary as c, DocumentVersion as d, Person as e };
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@w100n/documents",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Documents workspace for Web100Now projects: DOCX, Markdown, PDF, slides and sheets",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./memory": {
|
|
17
|
+
"types": "./dist/memory.d.ts",
|
|
18
|
+
"import": "./dist/memory.js",
|
|
19
|
+
"require": "./dist/memory.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./styles.css": "./dist/index.css",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": ["dist"],
|
|
25
|
+
"sideEffects": ["*.css"],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"dev": "vite playground",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"type-check": "tsc --noEmit",
|
|
31
|
+
"prepublishOnly": "npm run build"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": ">=18",
|
|
35
|
+
"react-dom": ">=18"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"docx-preview": "^0.4.1",
|
|
39
|
+
"dompurify": "^3.4.17",
|
|
40
|
+
"lucide-react": "^0.562.0",
|
|
41
|
+
"marked": "^18.1.1",
|
|
42
|
+
"pdfjs-dist": "^6.4.299"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@testing-library/react": "^16.3.3",
|
|
46
|
+
"@types/react": "^19.0.0",
|
|
47
|
+
"@types/react-dom": "^19.0.0",
|
|
48
|
+
"@vitejs/plugin-react": "^5.0.5",
|
|
49
|
+
"jsdom": "^30.1.3",
|
|
50
|
+
"react": "^19.2.3",
|
|
51
|
+
"react-dom": "^19.2.3",
|
|
52
|
+
"tsup": "^8.5.0",
|
|
53
|
+
"typescript": "^5.6.0",
|
|
54
|
+
"vite": "^7.1.0",
|
|
55
|
+
"vitest": "^4.1.10"
|
|
56
|
+
},
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "git+https://github.com/Web100Now-Organization/-w100n_documents.git"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "restricted"
|
|
63
|
+
}
|
|
64
|
+
}
|