@dxos/plugin-wnfs 0.8.4-main.5ea62a8 → 0.8.4-main.ae835ea
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/lib/browser/{FileContainer-KTD63EBQ.mjs → FileContainer-4U23PNBL.mjs} +4 -4
- package/dist/lib/browser/{FileContainer-KTD63EBQ.mjs.map → FileContainer-4U23PNBL.mjs.map} +1 -1
- package/dist/lib/browser/blockstore-2JFU4NBU.mjs +191 -0
- package/dist/lib/browser/{blockstore-7ZSJRK6J.mjs.map → blockstore-2JFU4NBU.mjs.map} +2 -2
- package/dist/lib/browser/chunk-7MEFQJWE.mjs +16 -0
- package/dist/lib/browser/{chunk-CW4BENRQ.mjs → chunk-CWMKN2F6.mjs} +27 -20
- package/dist/lib/browser/chunk-CWMKN2F6.mjs.map +7 -0
- package/dist/lib/browser/chunk-F4QHZWQD.mjs +16 -0
- package/dist/lib/browser/chunk-F4QHZWQD.mjs.map +7 -0
- package/dist/lib/browser/chunk-OGPGLJCV.mjs +25 -0
- package/dist/lib/browser/chunk-OGPGLJCV.mjs.map +7 -0
- package/dist/lib/browser/{file-uploader-YRZPRETS.mjs → file-uploader-W6TJLAAK.mjs} +11 -10
- package/dist/lib/browser/file-uploader-W6TJLAAK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +13 -15
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-CKGJNE6P.mjs → intent-resolver-FSW2EQF4.mjs} +8 -9
- package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs.map +7 -0
- package/dist/lib/browser/{markdown-5FPQ3X4O.mjs → markdown-3ZLVJIGT.mjs} +11 -22
- package/dist/lib/browser/{markdown-5FPQ3X4O.mjs.map → markdown-3ZLVJIGT.mjs.map} +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-J7EAO24E.mjs → react-surface-SLRIZ3UR.mjs} +12 -12
- package/dist/lib/browser/react-surface-SLRIZ3UR.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +5 -5
- package/dist/types/src/WnfsPlugin.d.ts +1 -1
- package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
- package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/components/FileContainer.d.ts +2 -2
- package/dist/types/src/components/FileContainer.d.ts.map +1 -1
- package/dist/types/src/components/FileInput.d.ts +1 -1
- package/dist/types/src/components/FileInput.d.ts.map +1 -1
- package/dist/types/src/extensions/image.stories.d.ts +0 -1
- package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +0 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/File.d.ts +16 -0
- package/dist/types/src/types/File.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +13 -9
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +33 -34
- package/src/WnfsPlugin.tsx +71 -69
- package/src/capabilities/capabilities.ts +3 -3
- package/src/capabilities/file-uploader.ts +8 -5
- package/src/capabilities/intent-resolver.ts +2 -3
- package/src/capabilities/react-surface.tsx +6 -6
- package/src/components/FileContainer.tsx +2 -2
- package/src/components/FileInput.tsx +3 -3
- package/src/extensions/image.stories.tsx +3 -5
- package/src/extensions/image.tsx +2 -2
- package/src/meta.ts +7 -4
- package/src/translations.ts +2 -2
- package/src/types/File.ts +24 -0
- package/src/types/index.ts +1 -1
- package/src/types/types.ts +8 -8
- package/dist/lib/browser/blockstore-7ZSJRK6J.mjs +0 -273
- package/dist/lib/browser/chunk-7X2PSKY2.mjs +0 -16
- package/dist/lib/browser/chunk-CW4BENRQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-KZANQHJY.mjs +0 -16
- package/dist/lib/browser/chunk-KZANQHJY.mjs.map +0 -7
- package/dist/lib/browser/chunk-VDDGZWAY.mjs +0 -15
- package/dist/lib/browser/chunk-VDDGZWAY.mjs.map +0 -7
- package/dist/lib/browser/file-uploader-YRZPRETS.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-CKGJNE6P.mjs.map +0 -7
- package/dist/lib/browser/react-surface-J7EAO24E.mjs.map +0 -7
- package/dist/types/src/types/file.d.ts +0 -16
- package/dist/types/src/types/file.d.ts.map +0 -1
- package/src/types/file.ts +0 -17
- /package/dist/lib/browser/{chunk-7X2PSKY2.mjs.map → chunk-7MEFQJWE.mjs.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./chunk-
|
|
1
|
+
import "./chunk-7MEFQJWE.mjs";
|
|
2
2
|
import {
|
|
3
3
|
filePath,
|
|
4
4
|
getBlobUrl,
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
} from "./chunk-D6VTEQIE.mjs";
|
|
8
8
|
import {
|
|
9
9
|
WnfsCapabilities
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import "./chunk-
|
|
10
|
+
} from "./chunk-F4QHZWQD.mjs";
|
|
11
|
+
import "./chunk-OGPGLJCV.mjs";
|
|
12
12
|
|
|
13
13
|
// src/components/FileContainer.tsx
|
|
14
14
|
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
@@ -100,4 +100,4 @@ export {
|
|
|
100
100
|
FileContainer,
|
|
101
101
|
FileContainer_default as default
|
|
102
102
|
};
|
|
103
|
-
//# sourceMappingURL=FileContainer-
|
|
103
|
+
//# sourceMappingURL=FileContainer-4U23PNBL.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/FileContainer.tsx", "../../../src/components/FilePreview.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { useState } from 'react';\n\nimport { useCapability } from '@dxos/app-framework';\nimport { invariant } from '@dxos/invariant';\nimport { getSpace } from '@dxos/react-client/echo';\nimport { useAsyncEffect } from '@dxos/react-ui';\nimport { StackItem } from '@dxos/react-ui-stack';\n\nimport { WnfsCapabilities } from '../capabilities';\nimport { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../helpers';\nimport { type
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { useState } from 'react';\n\nimport { useCapability } from '@dxos/app-framework';\nimport { invariant } from '@dxos/invariant';\nimport { getSpace } from '@dxos/react-client/echo';\nimport { useAsyncEffect } from '@dxos/react-ui';\nimport { StackItem } from '@dxos/react-ui-stack';\n\nimport { WnfsCapabilities } from '../capabilities';\nimport { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../helpers';\nimport { type WnfsFile } from '../types';\n\nimport { FilePreview } from './FilePreview';\n\nexport type FileContainerProps = {\n role: string;\n file: WnfsFile.File;\n};\n\nexport const FileContainer = ({ file }: FileContainerProps) => {\n const blockstore = useCapability(WnfsCapabilities.Blockstore);\n const instances = useCapability(WnfsCapabilities.Instances);\n const [blobUrl, setBlobUrl] = useState<string>();\n\n useAsyncEffect(async () => {\n const space = getSpace(file);\n invariant(space);\n const { directory, forest } = await loadWnfs({ blockstore, instances, space });\n const path = filePath(file.cid.toString(), space);\n const url = await getBlobUrl({ wnfsUrl: wnfsUrl(path), blockstore, directory, forest, type: file.type });\n setBlobUrl(url);\n }, [file]);\n\n if (!blobUrl) {\n return null;\n }\n\n return (\n <StackItem.Content>\n <FilePreview type={file.type} url={blobUrl} />\n </StackItem.Content>\n );\n};\n\nexport default FileContainer;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nexport type FilePreviewProps = ThemedClassName<{ type: string; url: string }>;\n\n/**\n * File/content preview iframe.\n */\nexport const FilePreview = ({ type, url, classNames }: FilePreviewProps) => {\n if (type.startsWith('image/')) {\n return <img className={mx('w-full h-full object-contain', classNames)} src={url} />;\n } else if (type.startsWith('video/')) {\n return <video className={mx('w-full h-full object-contain', classNames)} src={url} controls />;\n } else {\n return <iframe className={mx('w-full h-full overflow-auto', classNames)} src={url} />;\n }\n};\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAIA,OAAOA,UAASC,gBAAgB;AAEhC,SAASC,qBAAqB;AAC9B,SAASC,iBAAiB;AAC1B,SAASC,gBAAgB;AACzB,SAASC,sBAAsB;AAC/B,SAASC,iBAAiB;;;;ACN1B,OAAOC,WAAW;AAGlB,SAASC,UAAU;AAOZ,IAAMC,cAAc,CAAC,EAAEC,MAAMC,KAAKC,WAAU,MAAoB;;;AACrE,QAAIF,KAAKG,WAAW,QAAA,GAAW;AAC7B,aAAO,sBAAA,cAACC,OAAAA;QAAIC,WAAWC,GAAG,gCAAgCJ,UAAAA;QAAaK,KAAKN;;IAC9E,WAAWD,KAAKG,WAAW,QAAA,GAAW;AACpC,aAAO,sBAAA,cAACK,SAAAA;QAAMH,WAAWC,GAAG,gCAAgCJ,UAAAA;QAAaK,KAAKN;QAAKQ,UAAAA;;IACrF,OAAO;AACL,aAAO,sBAAA,cAACC,UAAAA;QAAOL,WAAWC,GAAG,+BAA+BJ,UAAAA;QAAaK,KAAKN;;IAChF;;;;AACF;;;;ADCO,IAAMU,gBAAgB,CAAC,EAAEC,KAAI,MAAsB;;;AACxD,UAAMC,aAAaC,cAAcC,iBAAiBC,UAAU;AAC5D,UAAMC,YAAYH,cAAcC,iBAAiBG,SAAS;AAC1D,UAAM,CAACC,SAASC,UAAAA,IAAcC,SAAAA;AAE9BC,mBAAe,YAAA;AACb,YAAMC,QAAQC,SAASZ,IAAAA;AACvBa,gBAAUF,OAAAA,QAAAA;;;;;;;;;AACV,YAAM,EAAEG,WAAWC,OAAM,IAAK,MAAMC,SAAS;QAAEf;QAAYI;QAAWM;MAAM,CAAA;AAC5E,YAAMM,OAAOC,SAASlB,KAAKmB,IAAIC,SAAQ,GAAIT,KAAAA;AAC3C,YAAMU,MAAM,MAAMC,WAAW;QAAEC,SAASA,QAAQN,IAAAA;QAAOhB;QAAYa;QAAWC;QAAQS,MAAMxB,KAAKwB;MAAK,CAAA;AACtGhB,iBAAWa,GAAAA;IACb,GAAG;MAACrB;KAAK;AAET,QAAI,CAACO,SAAS;AACZ,aAAO;IACT;AAEA,WACE,gBAAAkB,OAAA,cAACC,UAAUC,SAAO,MAChB,gBAAAF,OAAA,cAACG,aAAAA;MAAYJ,MAAMxB,KAAKwB;MAAMH,KAAKd;;;;;AAGzC;AAEA,IAAA,wBAAeR;",
|
|
6
6
|
"names": ["React", "useState", "useCapability", "invariant", "getSpace", "useAsyncEffect", "StackItem", "React", "mx", "FilePreview", "type", "url", "classNames", "startsWith", "img", "className", "mx", "src", "video", "controls", "iframe", "FileContainer", "file", "blockstore", "useCapability", "WnfsCapabilities", "Blockstore", "instances", "Instances", "blobUrl", "setBlobUrl", "useState", "useAsyncEffect", "space", "getSpace", "invariant", "directory", "forest", "loadWnfs", "path", "filePath", "cid", "toString", "url", "getBlobUrl", "wnfsUrl", "type", "React", "StackItem", "Content", "FilePreview"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {
|
|
2
|
+
storeName
|
|
3
|
+
} from "./chunk-D6VTEQIE.mjs";
|
|
4
|
+
import {
|
|
5
|
+
WnfsCapabilities
|
|
6
|
+
} from "./chunk-F4QHZWQD.mjs";
|
|
7
|
+
import "./chunk-OGPGLJCV.mjs";
|
|
8
|
+
|
|
9
|
+
// src/capabilities/blockstore.ts
|
|
10
|
+
import { contributes } from "@dxos/app-framework";
|
|
11
|
+
import { ClientCapabilities } from "@dxos/plugin-client";
|
|
12
|
+
|
|
13
|
+
// src/blockstore.ts
|
|
14
|
+
import { CarWriter } from "@ipld/car";
|
|
15
|
+
import { BaseBlockstore } from "blockstore-core";
|
|
16
|
+
import { IDBBlockstore } from "blockstore-idb";
|
|
17
|
+
import debounce from "debounce";
|
|
18
|
+
import * as IDB from "idb-keyval";
|
|
19
|
+
import all from "it-all";
|
|
20
|
+
import { CID } from "multiformats";
|
|
21
|
+
import * as Uint8Arrays from "uint8arrays";
|
|
22
|
+
var create = (apiHost) => {
|
|
23
|
+
return new MixedBlockstore(apiHost);
|
|
24
|
+
};
|
|
25
|
+
var MixedBlockstore = class extends BaseBlockstore {
|
|
26
|
+
#apiHost;
|
|
27
|
+
#localStore;
|
|
28
|
+
#isConnected;
|
|
29
|
+
#flushQueue;
|
|
30
|
+
#queue;
|
|
31
|
+
constructor(apiHost) {
|
|
32
|
+
super();
|
|
33
|
+
this.#apiHost = apiHost ? apiHost.replace(/\/?$/, "") : void 0;
|
|
34
|
+
this.#localStore = new IDBBlockstore(storeName());
|
|
35
|
+
this.#isConnected = navigator.onLine;
|
|
36
|
+
this.#queue = [];
|
|
37
|
+
this.#flushQueue = debounce(this.#flushQueueInt, 5e3);
|
|
38
|
+
}
|
|
39
|
+
async open() {
|
|
40
|
+
await this.#localStore.open();
|
|
41
|
+
await this.#restoreQueue();
|
|
42
|
+
window.addEventListener("offline", async () => {
|
|
43
|
+
this.#isConnected = false;
|
|
44
|
+
});
|
|
45
|
+
window.addEventListener("online", async () => {
|
|
46
|
+
this.#isConnected = true;
|
|
47
|
+
this.#flushQueue();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
url(apiHost, cid) {
|
|
51
|
+
const path = cid ? cid.toString() : "";
|
|
52
|
+
return `${apiHost}/api/file${path.length ? "/" + path : ""}`;
|
|
53
|
+
}
|
|
54
|
+
// BLOCKSTORE IMPLEMENTATION
|
|
55
|
+
async delete(key) {
|
|
56
|
+
await this.#localStore.delete(key);
|
|
57
|
+
if (this.#isConnected && this.#apiHost) {
|
|
58
|
+
await fetch(this.url(this.#apiHost, key), {
|
|
59
|
+
method: "DELETE"
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async get(key) {
|
|
64
|
+
if (await this.#localStore.has(key)) {
|
|
65
|
+
return await this.#localStore.get(key);
|
|
66
|
+
}
|
|
67
|
+
if (this.#isConnected && this.#apiHost) {
|
|
68
|
+
const block = await fetch(this.url(this.#apiHost, key), {
|
|
69
|
+
method: "GET"
|
|
70
|
+
}).then((r) => r.arrayBuffer()).then((r) => new Uint8Array(r));
|
|
71
|
+
await this.#localStore.put(key, block);
|
|
72
|
+
return block;
|
|
73
|
+
}
|
|
74
|
+
return await this.#localStore.get(key);
|
|
75
|
+
}
|
|
76
|
+
async has(key) {
|
|
77
|
+
if (await this.#localStore.has(key)) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
if (this.#isConnected && this.#apiHost) {
|
|
81
|
+
return await fetch(this.url(this.#apiHost, key), {
|
|
82
|
+
method: "HEAD"
|
|
83
|
+
}).then((r) => r.ok);
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
async put(key, val) {
|
|
88
|
+
await this.#localStore.put(key, val);
|
|
89
|
+
await this.#addToQueue(key);
|
|
90
|
+
this.#flushQueue();
|
|
91
|
+
return key;
|
|
92
|
+
}
|
|
93
|
+
async destroy() {
|
|
94
|
+
await this.#localStore.destroy();
|
|
95
|
+
}
|
|
96
|
+
// REMOTE
|
|
97
|
+
async putRemote(key, val) {
|
|
98
|
+
if (this.#apiHost) {
|
|
99
|
+
await fetch(this.url(this.#apiHost, key), {
|
|
100
|
+
method: "POST",
|
|
101
|
+
body: val
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async putCarRemote(car) {
|
|
106
|
+
if (this.#apiHost) {
|
|
107
|
+
await fetch(this.url(this.#apiHost), {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: {
|
|
110
|
+
"Content-Type": "application/vnd.ipld.car"
|
|
111
|
+
},
|
|
112
|
+
body: car
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// QUEUE
|
|
117
|
+
queueCacheName = `${storeName()}/state/queue`;
|
|
118
|
+
async #addToQueue(key) {
|
|
119
|
+
await this.#saveQueue([
|
|
120
|
+
...this.#queue,
|
|
121
|
+
key.toString()
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
async #flushQueueInt() {
|
|
125
|
+
if (!this.#isConnected || !this.#apiHost) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const keys = [
|
|
129
|
+
...this.#queue
|
|
130
|
+
];
|
|
131
|
+
if (keys.length === 0) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const blocks = await Promise.all(keys.map(async (key) => {
|
|
135
|
+
const cid = CID.parse(key);
|
|
136
|
+
const bytes = await this.#localStore.get(cid);
|
|
137
|
+
return {
|
|
138
|
+
cid,
|
|
139
|
+
bytes
|
|
140
|
+
};
|
|
141
|
+
}));
|
|
142
|
+
const car = await this.#createCar(blocks);
|
|
143
|
+
await this.putCarRemote(car);
|
|
144
|
+
const queue = [
|
|
145
|
+
...this.#queue
|
|
146
|
+
].filter((k) => {
|
|
147
|
+
if (keys.includes(k)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
return true;
|
|
151
|
+
});
|
|
152
|
+
await this.#saveQueue(queue);
|
|
153
|
+
}
|
|
154
|
+
async #restoreQueue() {
|
|
155
|
+
const fromCache = await IDB.get(this.queueCacheName);
|
|
156
|
+
if (fromCache && Array.isArray(fromCache)) {
|
|
157
|
+
this.#queue = fromCache;
|
|
158
|
+
this.#flushQueue();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async #saveQueue(items) {
|
|
162
|
+
const arr = [
|
|
163
|
+
...items
|
|
164
|
+
];
|
|
165
|
+
this.#queue = arr;
|
|
166
|
+
await IDB.set(this.queueCacheName, arr);
|
|
167
|
+
}
|
|
168
|
+
// 🛠️
|
|
169
|
+
async #createCar(blocks) {
|
|
170
|
+
const { writer, out } = CarWriter.create();
|
|
171
|
+
const outPromise = all(out);
|
|
172
|
+
await Promise.all(blocks.map((block) => {
|
|
173
|
+
return writer.put(block);
|
|
174
|
+
}));
|
|
175
|
+
await writer.close();
|
|
176
|
+
return Uint8Arrays.concat(await outPromise);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// src/capabilities/blockstore.ts
|
|
181
|
+
var blockstore_default = (async (context) => {
|
|
182
|
+
const client = context.getCapability(ClientCapabilities.Client);
|
|
183
|
+
const apiHost = client.config.values.runtime?.services?.edge?.url || "http://localhost:8787";
|
|
184
|
+
const blockstore = create(apiHost);
|
|
185
|
+
await blockstore.open();
|
|
186
|
+
return contributes(WnfsCapabilities.Blockstore, blockstore);
|
|
187
|
+
});
|
|
188
|
+
export {
|
|
189
|
+
blockstore_default as default
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=blockstore-2JFU4NBU.mjs.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/capabilities/blockstore.ts", "../../../src/blockstore.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type PluginContext, contributes } from '@dxos/app-framework';\nimport { ClientCapabilities } from '@dxos/plugin-client';\n\nimport * as Blockstore from '../blockstore';\n\nimport { WnfsCapabilities } from './capabilities';\n\nexport default async (context: PluginContext) => {\n const client = context.getCapability(ClientCapabilities.Client);\n const apiHost = client.config.values.runtime?.services?.edge?.url || 'http://localhost:8787';\n const blockstore = Blockstore.create(apiHost);\n await blockstore.open();\n\n return contributes(WnfsCapabilities.Blockstore, blockstore);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { CarWriter } from '@ipld/car';\nimport type { Block } from '@ipld/car/reader';\nimport { BaseBlockstore } from 'blockstore-core';\nimport { IDBBlockstore } from 'blockstore-idb';\nimport debounce from 'debounce';\nimport * as IDB from 'idb-keyval';\nimport all from 'it-all';\nimport { CID } from 'multiformats';\nimport * as Uint8Arrays from 'uint8arrays';\n\nimport { storeName } from './helpers';\n\nexport const create = (apiHost?: string) => {\n return new MixedBlockstore(apiHost);\n};\n\n/**\n * A blockstore that communicates with the DXOS blob service,\n * and which uses an indexedDB blockstore as a client cache.\n */\nexport class MixedBlockstore extends BaseBlockstore {\n readonly #apiHost: string | undefined;\n readonly #localStore: IDBBlockstore;\n\n #isConnected: boolean;\n #flushQueue: () => void;\n #queue: string[];\n\n constructor(apiHost?: string) {\n super();\n\n this.#apiHost = apiHost ? apiHost.replace(/\\/?$/, '') : undefined;\n this.#localStore = new IDBBlockstore(storeName());\n this.#isConnected = navigator.onLine;\n this.#queue = [];\n\n this.#flushQueue = debounce(this.#flushQueueInt, 5000);\n }\n\n async open(): Promise<void> {\n await this.#localStore.open();\n await this.#restoreQueue();\n\n window.addEventListener('offline', async () => {\n this.#isConnected = false;\n });\n\n window.addEventListener('online', async () => {\n this.#isConnected = true;\n this.#flushQueue();\n });\n }\n\n url(apiHost: string, cid?: CID): string {\n const path = cid ? cid.toString() : '';\n return `${apiHost}/api/file${path.length ? '/' + path : ''}`;\n }\n\n // BLOCKSTORE IMPLEMENTATION\n\n override async delete(key: CID): Promise<void> {\n await this.#localStore.delete(key);\n\n if (this.#isConnected && this.#apiHost) {\n await fetch(this.url(this.#apiHost, key), {\n method: 'DELETE',\n });\n }\n }\n\n override async get(key: CID): Promise<Uint8Array> {\n if (await this.#localStore.has(key)) {\n return await this.#localStore.get(key);\n }\n\n if (this.#isConnected && this.#apiHost) {\n const block = await fetch(this.url(this.#apiHost, key), {\n method: 'GET',\n })\n .then((r) => r.arrayBuffer())\n .then((r) => new Uint8Array(r));\n\n // Make sure it is cached locally\n await this.#localStore.put(key, block);\n\n return block;\n }\n\n return await this.#localStore.get(key);\n }\n\n override async has(key: CID): Promise<boolean> {\n if (await this.#localStore.has(key)) {\n return true;\n }\n\n if (this.#isConnected && this.#apiHost) {\n return await fetch(this.url(this.#apiHost, key), {\n method: 'HEAD',\n }).then((r) => r.ok);\n }\n\n return false;\n }\n\n override async put(key: CID, val: Uint8Array): Promise<CID> {\n await this.#localStore.put(key, val);\n\n await this.#addToQueue(key);\n this.#flushQueue();\n\n return key;\n }\n\n async destroy(): Promise<void> {\n await this.#localStore.destroy();\n }\n\n // REMOTE\n\n async putRemote(key: CID, val: Uint8Array): Promise<void> {\n if (this.#apiHost) {\n await fetch(this.url(this.#apiHost, key), {\n method: 'POST',\n body: val as Uint8Array<ArrayBuffer>,\n });\n }\n }\n\n async putCarRemote(car: Uint8Array): Promise<void> {\n if (this.#apiHost) {\n await fetch(this.url(this.#apiHost), {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/vnd.ipld.car',\n },\n body: car as Uint8Array<ArrayBuffer>,\n });\n }\n }\n\n // QUEUE\n\n readonly queueCacheName = `${storeName()}/state/queue`;\n\n async #addToQueue(key: CID): Promise<void> {\n await this.#saveQueue([...this.#queue, key.toString()]);\n }\n\n async #flushQueueInt(): Promise<void> {\n if (!this.#isConnected || !this.#apiHost) {\n return;\n }\n\n const keys = [...this.#queue];\n if (keys.length === 0) {\n return;\n }\n\n // Collect blocks\n const blocks = await Promise.all(\n keys.map(async (key) => {\n const cid = CID.parse(key);\n const bytes = await this.#localStore.get(cid);\n return { cid, bytes };\n }),\n );\n\n // Create & submit CAR\n const car = await this.#createCar(blocks);\n await this.putCarRemote(car);\n\n // Adjust queue\n const queue = [...this.#queue].filter((k) => {\n if (keys.includes(k)) {\n return false;\n }\n\n return true;\n });\n\n await this.#saveQueue(queue);\n }\n\n async #restoreQueue(): Promise<void> {\n const fromCache = await IDB.get(this.queueCacheName);\n if (fromCache && Array.isArray(fromCache)) {\n this.#queue = fromCache;\n this.#flushQueue();\n }\n }\n\n async #saveQueue(items: string[]): Promise<void> {\n const arr = [...items];\n this.#queue = arr;\n await IDB.set(this.queueCacheName, arr);\n }\n\n // 🛠️\n\n async #createCar(blocks: Block[]): Promise<Uint8Array> {\n const { writer, out } = CarWriter.create();\n const outPromise = all(out);\n\n await Promise.all(\n blocks.map((block) => {\n return writer.put(block);\n }),\n );\n\n await writer.close();\n return Uint8Arrays.concat(await outPromise);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;AAIA,SAA6BA,mBAAmB;AAChD,SAASC,0BAA0B;;;ACDnC,SAASC,iBAAiB;AAE1B,SAASC,sBAAsB;AAC/B,SAASC,qBAAqB;AAC9B,OAAOC,cAAc;AACrB,YAAYC,SAAS;AACrB,OAAOC,SAAS;AAChB,SAASC,WAAW;AACpB,YAAYC,iBAAiB;
|
|
6
|
-
"names": ["contributes", "ClientCapabilities", "CarWriter", "BaseBlockstore", "IDBBlockstore", "debounce", "IDB", "all", "CID", "Uint8Arrays", "create", "apiHost", "MixedBlockstore", "BaseBlockstore", "open", "window", "addEventListener", "url", "cid", "path", "toString", "length", "delete", "key", "fetch", "method", "get", "has", "block", "then", "r", "arrayBuffer", "Uint8Array", "put", "ok", "val", "destroy", "putRemote", "body", "putCarRemote", "car", "headers", "queueCacheName", "
|
|
5
|
+
"mappings": ";;;;;;;;;AAIA,SAA6BA,mBAAmB;AAChD,SAASC,0BAA0B;;;ACDnC,SAASC,iBAAiB;AAE1B,SAASC,sBAAsB;AAC/B,SAASC,qBAAqB;AAC9B,OAAOC,cAAc;AACrB,YAAYC,SAAS;AACrB,OAAOC,SAAS;AAChB,SAASC,WAAW;AACpB,YAAYC,iBAAiB;AAItB,IAAMC,SAAS,CAACC,YAAAA;AACrB,SAAO,IAAIC,gBAAgBD,OAAAA;AAC7B;AAMO,IAAMC,kBAAN,cAA8BC,eAAAA;EAC1B;EACA;EAET;EACA;EACA;EAEA,YAAYF,SAAkB;AAC5B,UAAK;AAEL,SAAK,WAAWA,UAAUA,QAAQG,QAAQ,QAAQ,EAAA,IAAMC;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BC,YAAYL,UAAAA;AAClD;",
|
|
6
|
+
"names": ["contributes", "ClientCapabilities", "CarWriter", "BaseBlockstore", "IDBBlockstore", "debounce", "IDB", "all", "CID", "Uint8Arrays", "create", "apiHost", "MixedBlockstore", "BaseBlockstore", "replace", "undefined", "IDBBlockstore", "storeName", "navigator", "onLine", "debounce", "open", "window", "addEventListener", "url", "cid", "path", "toString", "length", "delete", "key", "fetch", "method", "get", "has", "block", "then", "r", "arrayBuffer", "Uint8Array", "put", "ok", "val", "destroy", "putRemote", "body", "putCarRemote", "car", "headers", "queueCacheName", "keys", "blocks", "Promise", "all", "map", "CID", "parse", "bytes", "queue", "filter", "k", "includes", "fromCache", "Array", "isArray", "items", "arr", "set", "writer", "out", "CarWriter", "outPromise", "close", "concat", "context", "client", "getCapability", "ClientCapabilities", "Client", "apiHost", "config", "values", "runtime", "services", "edge", "url", "blockstore", "create", "open", "contributes", "WnfsCapabilities", "Blockstore"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/capabilities/index.ts
|
|
2
|
+
import { lazy } from "@dxos/app-framework";
|
|
3
|
+
var Blockstore = lazy(() => import("./blockstore-2JFU4NBU.mjs"));
|
|
4
|
+
var FileUploader = lazy(() => import("./file-uploader-W6TJLAAK.mjs"));
|
|
5
|
+
var IntentResolver = lazy(() => import("./intent-resolver-FSW2EQF4.mjs"));
|
|
6
|
+
var Markdown = lazy(() => import("./markdown-3ZLVJIGT.mjs"));
|
|
7
|
+
var ReactSurface = lazy(() => import("./react-surface-SLRIZ3UR.mjs"));
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
Blockstore,
|
|
11
|
+
FileUploader,
|
|
12
|
+
IntentResolver,
|
|
13
|
+
Markdown,
|
|
14
|
+
ReactSurface
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=chunk-7MEFQJWE.mjs.map
|
|
@@ -1,35 +1,42 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
__export,
|
|
3
|
+
meta
|
|
4
|
+
} from "./chunk-OGPGLJCV.mjs";
|
|
4
5
|
|
|
5
|
-
// src/types/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
// src/types/File.ts
|
|
7
|
+
var File_exports = {};
|
|
8
|
+
__export(File_exports, {
|
|
9
|
+
File: () => File,
|
|
10
|
+
make: () => make
|
|
11
|
+
});
|
|
12
|
+
import * as Schema from "effect/Schema";
|
|
13
|
+
import { Obj, Type } from "@dxos/echo";
|
|
14
|
+
import { FormAnnotation } from "@dxos/echo/internal";
|
|
15
|
+
var File = Schema.Struct({
|
|
16
|
+
name: Schema.String.pipe(Schema.optional),
|
|
17
|
+
type: Schema.String.pipe(FormAnnotation.set(false)),
|
|
18
|
+
cid: Schema.String.pipe(FormAnnotation.set(false)),
|
|
19
|
+
timestamp: Schema.String.pipe(FormAnnotation.set(false), Schema.optional)
|
|
20
|
+
}).pipe(Type.Obj({
|
|
9
21
|
typename: "dxos.org/type/File",
|
|
10
22
|
version: "0.1.0"
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
type: Schema.String,
|
|
14
|
-
cid: Schema.String,
|
|
15
|
-
timestamp: Schema.optional(Schema.String)
|
|
16
|
-
}) {
|
|
17
|
-
};
|
|
23
|
+
}));
|
|
24
|
+
var make = (props) => Obj.make(File, props);
|
|
18
25
|
|
|
19
26
|
// src/types/types.ts
|
|
20
|
-
import
|
|
27
|
+
import * as Schema2 from "effect/Schema";
|
|
21
28
|
import { FileInfoSchema } from "@dxos/app-framework";
|
|
22
29
|
import { SpaceSchema } from "@dxos/react-client/echo";
|
|
23
30
|
(function(WnfsAction2) {
|
|
24
|
-
class Create extends Schema2.TaggedClass()(`${
|
|
31
|
+
class Create extends Schema2.TaggedClass()(`${meta.id}/action/create`, {
|
|
25
32
|
input: FileInfoSchema.pick("name", "type", "cid").pipe(Schema2.required),
|
|
26
33
|
output: Schema2.Struct({
|
|
27
|
-
object:
|
|
34
|
+
object: File
|
|
28
35
|
})
|
|
29
36
|
}) {
|
|
30
37
|
}
|
|
31
38
|
WnfsAction2.Create = Create;
|
|
32
|
-
WnfsAction2.UploadAnnotationId = Symbol.for(`${
|
|
39
|
+
WnfsAction2.UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);
|
|
33
40
|
WnfsAction2.UploadFileSchema = Schema2.Struct({
|
|
34
41
|
file: Schema2.instanceOf(File).annotations({
|
|
35
42
|
[WnfsAction2.UploadAnnotationId]: {
|
|
@@ -46,7 +53,7 @@ import { SpaceSchema } from "@dxos/react-client/echo";
|
|
|
46
53
|
}
|
|
47
54
|
})
|
|
48
55
|
});
|
|
49
|
-
class Upload extends Schema2.TaggedClass()(`${
|
|
56
|
+
class Upload extends Schema2.TaggedClass()(`${meta.id}/action/upload`, {
|
|
50
57
|
input: Schema2.extend(WnfsAction2.UploadFileSchema, Schema2.Struct({
|
|
51
58
|
space: SpaceSchema
|
|
52
59
|
})),
|
|
@@ -58,7 +65,7 @@ import { SpaceSchema } from "@dxos/react-client/echo";
|
|
|
58
65
|
var WnfsAction;
|
|
59
66
|
|
|
60
67
|
export {
|
|
61
|
-
|
|
68
|
+
File_exports,
|
|
62
69
|
WnfsAction
|
|
63
70
|
};
|
|
64
|
-
//# sourceMappingURL=chunk-
|
|
71
|
+
//# sourceMappingURL=chunk-CWMKN2F6.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/File.ts", "../../../src/types/types.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Obj, Type } from '@dxos/echo';\nimport { FormAnnotation } from '@dxos/echo/internal';\n\nexport const File = Schema.Struct({\n name: Schema.String.pipe(Schema.optional),\n type: Schema.String.pipe(FormAnnotation.set(false)),\n cid: Schema.String.pipe(FormAnnotation.set(false)),\n timestamp: Schema.String.pipe(FormAnnotation.set(false), Schema.optional),\n}).pipe(\n Type.Obj({\n typename: 'dxos.org/type/File',\n version: '0.1.0',\n }),\n);\n\nexport type File = Schema.Schema.Type<typeof File>;\n\nexport const make = (props: Obj.MakeProps<typeof File>) => Obj.make(File, props);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { FileInfoSchema } from '@dxos/app-framework';\nimport { SpaceSchema } from '@dxos/react-client/echo';\n\nimport { meta } from '../meta';\n\nimport * as File from './File';\n\nexport namespace WnfsAction {\n export class Create extends Schema.TaggedClass<Create>()(`${meta.id}/action/create`, {\n input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),\n output: Schema.Struct({\n object: File.File,\n }),\n }) {}\n\n export const UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);\n\n export const UploadFileSchema = Schema.Struct({\n file: Schema.instanceOf(File.File).annotations({\n [UploadAnnotationId]: {\n // Accept file types.\n 'image/*': ['.jpg', '.jpeg', '.png', '.gif'],\n 'application/pdf': ['.pdf'],\n // TODO(wittjosiah): Add more file types.\n },\n }),\n });\n\n export type UploadFileForm = Schema.Schema.Type<typeof UploadFileSchema>;\n\n export class Upload extends Schema.TaggedClass<Upload>()(`${meta.id}/action/upload`, {\n input: Schema.extend(UploadFileSchema, Schema.Struct({ space: SpaceSchema })),\n output: Schema.required(FileInfoSchema),\n }) {}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;AAAA;;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,KAAKC,YAAY;AAC1B,SAASC,sBAAsB;AAExB,IAAMC,OAAcC,cAAO;EAChCC,MAAaC,cAAOC,KAAYC,eAAQ;EACxCC,MAAaH,cAAOC,KAAKG,eAAeC,IAAI,KAAA,CAAA;EAC5CC,KAAYN,cAAOC,KAAKG,eAAeC,IAAI,KAAA,CAAA;EAC3CE,WAAkBP,cAAOC,KAAKG,eAAeC,IAAI,KAAA,GAAeH,eAAQ;AAC1E,CAAA,EAAGD,KACDO,KAAKC,IAAI;EACPC,UAAU;EACVC,SAAS;AACX,CAAA,CAAA;AAKK,IAAMC,OAAO,CAACC,UAAsCJ,IAAIG,KAAKf,MAAMgB,KAAAA;;;ACnB1E,YAAYC,aAAY;AAExB,SAASC,sBAAsB;AAC/B,SAASC,mBAAmB;UAMXC,aAAAA;EACR,MAAMC,eAAsBC,oBAAW,EAAW,GAAGC,KAAKC,EAAE,kBAAkB;IACnFC,OAAOC,eAAeC,KAAK,QAAQ,QAAQ,KAAA,EAAOC,KAAYC,gBAAQ;IACtEC,QAAeC,eAAO;MACpBC,QAAaC;IACf,CAAA;EACF,CAAA,EAAA;EAAI;cALSZ,SAAAA;cAOAa,qBAAqBC,OAAOC,IAAI,GAAGb,KAAKC,EAAE,oBAAoB;cAE9Da,mBAA0BN,eAAO;IAC5CO,MAAaC,mBAAgBN,IAAI,EAAEO,YAAY;MAC7C,CAAApB,YAACc,kBAAAA,GAAqB;;QAEpB,WAAW;UAAC;UAAQ;UAAS;UAAQ;;QACrC,mBAAmB;UAAC;;MAEtB;IACF,CAAA;EACF,CAAA;EAIO,MAAMO,eAAsBnB,oBAAW,EAAW,GAAGC,KAAKC,EAAE,kBAAkB;IACnFC,OAAciB,eAAMtB,YAACiB,kBAAyBN,eAAO;MAAEY,OAAOC;IAAY,CAAA,CAAA;IAC1Ed,QAAeD,iBAASH,cAAAA;EAC1B,CAAA,EAAA;EAAI;cAHSe,SAAAA;AAIf,GA3BiBrB,eAAAA,aAAAA,CAAAA,EAAAA;;",
|
|
6
|
+
"names": ["Schema", "Obj", "Type", "FormAnnotation", "File", "Struct", "name", "String", "pipe", "optional", "type", "FormAnnotation", "set", "cid", "timestamp", "Type", "Obj", "typename", "version", "make", "props", "Schema", "FileInfoSchema", "SpaceSchema", "WnfsAction", "Create", "TaggedClass", "meta", "id", "input", "FileInfoSchema", "pick", "pipe", "required", "output", "Struct", "object", "File", "UploadAnnotationId", "Symbol", "for", "UploadFileSchema", "file", "instanceOf", "annotations", "Upload", "extend", "space", "SpaceSchema"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
meta
|
|
3
|
+
} from "./chunk-OGPGLJCV.mjs";
|
|
4
|
+
|
|
5
|
+
// src/capabilities/capabilities.ts
|
|
6
|
+
import { defineCapability } from "@dxos/app-framework";
|
|
7
|
+
(function(WnfsCapabilities2) {
|
|
8
|
+
WnfsCapabilities2.Blockstore = defineCapability(`${meta.id}/capability/blockstore`);
|
|
9
|
+
WnfsCapabilities2.Instances = defineCapability(`${meta.id}/capability/instances`);
|
|
10
|
+
})(WnfsCapabilities || (WnfsCapabilities = {}));
|
|
11
|
+
var WnfsCapabilities;
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
WnfsCapabilities
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=chunk-F4QHZWQD.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/capabilities/capabilities.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Blockstore } from 'interface-blockstore';\nimport { type PrivateDirectory, type PrivateForest } from 'wnfs';\n\nimport { defineCapability } from '@dxos/app-framework';\nimport { type SpaceId } from '@dxos/keys';\n\nimport { meta } from '../meta';\n\nexport namespace WnfsCapabilities {\n export const Blockstore = defineCapability<Blockstore>(`${meta.id}/capability/blockstore`);\n\n export type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;\n export const Instances = defineCapability<Instances>(`${meta.id}/capability/instances`);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAOA,SAASA,wBAAwB;UAKhBC,mBAAAA;oBACFC,aAAaC,iBAA6B,GAAGC,KAAKC,EAAE,wBAAwB;oBAG5EC,YAAYH,iBAA4B,GAAGC,KAAKC,EAAE,uBAAuB;AACxF,GALiBJ,qBAAAA,mBAAAA,CAAAA,EAAAA;;",
|
|
6
|
+
"names": ["defineCapability", "WnfsCapabilities", "Blockstore", "defineCapability", "meta", "id", "Instances"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/meta.ts
|
|
8
|
+
import { trim } from "@dxos/util";
|
|
9
|
+
var meta = {
|
|
10
|
+
id: "dxos.org/plugin/wnfs",
|
|
11
|
+
name: "WNFS",
|
|
12
|
+
description: trim`
|
|
13
|
+
Decentralized file storage using the Web Native File System protocol.
|
|
14
|
+
Store and sync files with end-to-end encryption across devices without central servers.
|
|
15
|
+
`,
|
|
16
|
+
icon: "ph--file-cloud--regular",
|
|
17
|
+
iconHue: "teal",
|
|
18
|
+
source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs"
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
__export,
|
|
23
|
+
meta
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-OGPGLJCV.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/meta.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\nimport { trim } from '@dxos/util';\n\nexport const meta: PluginMeta = {\n id: 'dxos.org/plugin/wnfs',\n name: 'WNFS',\n description: trim`\n Decentralized file storage using the Web Native File System protocol.\n Store and sync files with end-to-end encryption across devices without central servers.\n `,\n icon: 'ph--file-cloud--regular',\n iconHue: 'teal',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAKA,SAASA,YAAY;AAEd,IAAMC,OAAmB;EAC9BC,IAAI;EACJC,MAAM;EACNC,aAAaC;;;;EAIbC,MAAM;EACNC,SAAS;EACTC,QAAQ;AACV;",
|
|
6
|
+
"names": ["trim", "meta", "id", "name", "description", "trim", "icon", "iconHue", "source"]
|
|
7
|
+
}
|
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WnfsAction
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-CWMKN2F6.mjs";
|
|
4
|
+
import "./chunk-OGPGLJCV.mjs";
|
|
5
5
|
|
|
6
6
|
// src/capabilities/file-uploader.ts
|
|
7
|
-
import
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Function from "effect/Function";
|
|
8
9
|
import { Capabilities, chain, contributes, createIntent } from "@dxos/app-framework";
|
|
9
10
|
import { SpaceAction } from "@dxos/plugin-space/types";
|
|
10
|
-
var file_uploader_default = (context) => {
|
|
11
|
-
return contributes(Capabilities.FileUploader, (
|
|
11
|
+
var file_uploader_default = ((context) => {
|
|
12
|
+
return contributes(Capabilities.FileUploader, (space, file) => {
|
|
12
13
|
const { dispatch } = context.getCapability(Capabilities.IntentDispatcher);
|
|
13
14
|
const program = Effect.gen(function* () {
|
|
14
15
|
const fileInfo = yield* dispatch(createIntent(WnfsAction.Upload, {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
space,
|
|
17
|
+
file
|
|
17
18
|
}));
|
|
18
|
-
yield* dispatch(pipe(createIntent(WnfsAction.Create, fileInfo), chain(SpaceAction.AddObject, {
|
|
19
|
+
yield* dispatch(Function.pipe(createIntent(WnfsAction.Create, fileInfo), chain(SpaceAction.AddObject, {
|
|
19
20
|
target: space
|
|
20
21
|
})));
|
|
21
22
|
return fileInfo;
|
|
22
23
|
});
|
|
23
24
|
return Effect.runPromise(program);
|
|
24
25
|
});
|
|
25
|
-
};
|
|
26
|
+
});
|
|
26
27
|
export {
|
|
27
28
|
file_uploader_default as default
|
|
28
29
|
};
|
|
29
|
-
//# sourceMappingURL=file-uploader-
|
|
30
|
+
//# sourceMappingURL=file-uploader-W6TJLAAK.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/capabilities/file-uploader.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Function from 'effect/Function';\n\nimport { Capabilities, type PluginContext, chain, contributes, createIntent } from '@dxos/app-framework';\nimport { SpaceAction } from '@dxos/plugin-space/types';\n\nimport { WnfsAction } from '../types';\n\nexport default (context: PluginContext) => {\n return contributes(Capabilities.FileUploader, (space, file) => {\n const { dispatch } = context.getCapability(Capabilities.IntentDispatcher);\n const program = Effect.gen(function* () {\n const fileInfo = yield* dispatch(createIntent(WnfsAction.Upload, { space, file }));\n yield* dispatch(\n Function.pipe(createIntent(WnfsAction.Create, fileInfo), chain(SpaceAction.AddObject, { target: space })),\n );\n\n return fileInfo;\n });\n\n return Effect.runPromise(program);\n });\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,YAAYA,YAAY;AACxB,YAAYC,cAAc;AAE1B,SAASC,cAAkCC,OAAOC,aAAaC,oBAAoB;AACnF,SAASC,mBAAmB;AAI5B,IAAA,yBAAe,CAACC,YAAAA;AACd,SAAOC,YAAYC,aAAaC,cAAc,CAACC,OAAOC,SAAAA;AACpD,UAAM,EAAEC,SAAQ,IAAKN,QAAQO,cAAcL,aAAaM,gBAAgB;AACxE,UAAMC,UAAiBC,WAAI,aAAA;AACzB,YAAMC,WAAW,OAAOL,SAASM,aAAaC,WAAWC,QAAQ;QAAEV;QAAOC;MAAK,CAAA,CAAA;AAC/E,aAAOC,SACIS,cAAKH,aAAaC,WAAWG,QAAQL,QAAAA,GAAWM,MAAMC,YAAYC,WAAW;QAAEC,QAAQhB;MAAM,CAAA,CAAA,CAAA;AAGxG,aAAOO;IACT,CAAA;AAEA,WAAcU,kBAAWZ,OAAAA;EAC3B,CAAA;AACF;",
|
|
6
|
+
"names": ["Effect", "Function", "Capabilities", "chain", "contributes", "createIntent", "SpaceAction", "context", "contributes", "Capabilities", "FileUploader", "space", "file", "dispatch", "getCapability", "IntentDispatcher", "program", "gen", "fileInfo", "createIntent", "WnfsAction", "Upload", "pipe", "Create", "chain", "SpaceAction", "AddObject", "target", "runPromise"]
|
|
7
|
+
}
|
|
@@ -4,21 +4,20 @@ import {
|
|
|
4
4
|
IntentResolver,
|
|
5
5
|
Markdown,
|
|
6
6
|
ReactSurface
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-7MEFQJWE.mjs";
|
|
8
8
|
import {
|
|
9
9
|
WnfsCapabilities
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-F4QHZWQD.mjs";
|
|
11
11
|
import {
|
|
12
|
-
|
|
12
|
+
File_exports,
|
|
13
13
|
WnfsAction
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-CWMKN2F6.mjs";
|
|
15
15
|
import {
|
|
16
|
-
WNFS_PLUGIN,
|
|
17
16
|
meta
|
|
18
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-OGPGLJCV.mjs";
|
|
19
18
|
|
|
20
19
|
// src/WnfsPlugin.tsx
|
|
21
|
-
import
|
|
20
|
+
import * as Function from "effect/Function";
|
|
22
21
|
import { Capabilities, Events, chain, contributes, createIntent, defineModule, definePlugin } from "@dxos/app-framework";
|
|
23
22
|
import { ClientEvents } from "@dxos/plugin-client";
|
|
24
23
|
import { MarkdownEvents } from "@dxos/plugin-markdown";
|
|
@@ -29,7 +28,7 @@ import { defineObjectForm } from "@dxos/plugin-space/types";
|
|
|
29
28
|
var translations = [
|
|
30
29
|
{
|
|
31
30
|
"en-US": {
|
|
32
|
-
[
|
|
31
|
+
[File_exports.File.typename]: {
|
|
33
32
|
"typename label": "File",
|
|
34
33
|
"object name placeholder": "New file",
|
|
35
34
|
"rename object label": "Rename file",
|
|
@@ -45,7 +44,7 @@ var translations = [
|
|
|
45
44
|
];
|
|
46
45
|
|
|
47
46
|
// src/WnfsPlugin.tsx
|
|
48
|
-
var WnfsPlugin = () =>
|
|
47
|
+
var WnfsPlugin = definePlugin(meta, () => [
|
|
49
48
|
defineModule({
|
|
50
49
|
id: `${meta.id}/module/blockstore`,
|
|
51
50
|
activatesOn: ClientEvents.ClientReady,
|
|
@@ -68,11 +67,11 @@ var WnfsPlugin = () => definePlugin(meta, [
|
|
|
68
67
|
id: `${meta.id}/module/metadata`,
|
|
69
68
|
activatesOn: Events.SetupMetadata,
|
|
70
69
|
activate: () => contributes(Capabilities.Metadata, {
|
|
71
|
-
id:
|
|
70
|
+
id: File_exports.File.typename,
|
|
72
71
|
metadata: {
|
|
73
|
-
label: (object) => object instanceof FileType ? object.name : void 0,
|
|
74
72
|
// TODO(wittjosiah): Would be nice if icon could change based on the type of the file.
|
|
75
|
-
icon: "ph--file--regular"
|
|
73
|
+
icon: "ph--file--regular",
|
|
74
|
+
iconHue: "teal"
|
|
76
75
|
}
|
|
77
76
|
})
|
|
78
77
|
}),
|
|
@@ -80,9 +79,9 @@ var WnfsPlugin = () => definePlugin(meta, [
|
|
|
80
79
|
id: `${meta.id}/module/object-form`,
|
|
81
80
|
activatesOn: ClientEvents.SetupSchema,
|
|
82
81
|
activate: () => contributes(SpaceCapabilities.ObjectForm, defineObjectForm({
|
|
83
|
-
objectSchema:
|
|
82
|
+
objectSchema: File_exports.File,
|
|
84
83
|
formSchema: WnfsAction.UploadFileSchema,
|
|
85
|
-
getIntent: (props, options) => pipe(createIntent(WnfsAction.Upload, {
|
|
84
|
+
getIntent: (props, options) => Function.pipe(createIntent(WnfsAction.Upload, {
|
|
86
85
|
...props,
|
|
87
86
|
space: options.space
|
|
88
87
|
}), chain(WnfsAction.Create, {}))
|
|
@@ -110,7 +109,6 @@ var WnfsPlugin = () => definePlugin(meta, [
|
|
|
110
109
|
})
|
|
111
110
|
]);
|
|
112
111
|
export {
|
|
113
|
-
WNFS_PLUGIN,
|
|
114
112
|
WnfsCapabilities,
|
|
115
113
|
WnfsPlugin,
|
|
116
114
|
meta
|