@dxos/plugin-wnfs 0.7.4-staging.f7e8224 → 0.7.5-labs.5f04cf6
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-4FF5D2ZF.mjs +94 -0
- package/dist/lib/browser/FileContainer-4FF5D2ZF.mjs.map +7 -0
- package/dist/lib/browser/blockstore-6U5XTSIH.mjs +192 -0
- package/dist/lib/browser/blockstore-6U5XTSIH.mjs.map +7 -0
- package/dist/lib/browser/chunk-357BWHML.mjs +16 -0
- package/dist/lib/browser/chunk-357BWHML.mjs.map +7 -0
- package/dist/lib/browser/{chunk-VL3H7P4F.mjs → chunk-6YFT42F7.mjs} +5 -8
- package/dist/lib/browser/chunk-6YFT42F7.mjs.map +7 -0
- package/dist/lib/browser/chunk-ED7HMPYN.mjs +16 -0
- package/dist/lib/browser/chunk-ED7HMPYN.mjs.map +7 -0
- package/dist/lib/browser/chunk-EMRQJXBW.mjs +60 -0
- package/dist/lib/browser/chunk-EMRQJXBW.mjs.map +7 -0
- package/dist/lib/browser/chunk-SCQWJNHD.mjs +157 -0
- package/dist/lib/browser/chunk-SCQWJNHD.mjs.map +7 -0
- package/dist/lib/browser/file-uploader-EDHMSKYS.mjs +29 -0
- package/dist/lib/browser/file-uploader-EDHMSKYS.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +96 -494
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-WDO4EIG3.mjs +43 -0
- package/dist/lib/browser/intent-resolver-WDO4EIG3.mjs.map +7 -0
- package/dist/lib/browser/markdown-MGSH5CVQ.mjs +198 -0
- package/dist/lib/browser/markdown-MGSH5CVQ.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-OUVGXVOP.mjs +81 -0
- package/dist/lib/browser/react-surface-OUVGXVOP.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/types/src/WnfsPlugin.d.ts +1 -3
- package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
- package/dist/types/src/blockstore.d.ts +4 -1
- package/dist/types/src/blockstore.d.ts.map +1 -1
- package/dist/types/src/capabilities/blockstore.d.ts +4 -0
- package/dist/types/src/capabilities/blockstore.d.ts.map +1 -0
- package/dist/types/src/capabilities/capabilities.d.ts +12 -0
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
- package/dist/types/src/capabilities/file-uploader.d.ts +4 -0
- package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +7 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/markdown.d.ts +4 -0
- package/dist/types/src/capabilities/markdown.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +4 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/components/FileContainer.d.ts +8 -0
- package/dist/types/src/components/FileContainer.d.ts.map +1 -0
- package/dist/types/src/components/FileInput.d.ts +8 -0
- package/dist/types/src/components/FileInput.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +4 -11
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/extensions/image.d.ts +5 -0
- package/dist/types/src/extensions/image.d.ts.map +1 -1
- package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
- package/dist/types/src/helpers/common.d.ts.map +1 -0
- package/dist/types/src/helpers/index.d.ts +5 -0
- package/dist/types/src/helpers/index.d.ts.map +1 -0
- package/dist/types/src/helpers/load.d.ts +13 -0
- package/dist/types/src/helpers/load.d.ts.map +1 -0
- package/dist/types/src/helpers/upload.d.ts +15 -0
- package/dist/types/src/helpers/upload.d.ts.map +1 -0
- package/dist/types/src/helpers/wnfs-url.d.ts +11 -0
- package/dist/types/src/helpers/wnfs-url.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +1 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +14 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/file.d.ts +7 -11
- package/dist/types/src/types/file.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +49 -6
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +28 -26
- package/src/WnfsPlugin.tsx +77 -92
- package/src/blockstore.ts +151 -21
- package/src/capabilities/blockstore.ts +18 -0
- package/src/capabilities/capabilities.ts +18 -0
- package/src/capabilities/file-uploader.ts +24 -0
- package/src/capabilities/index.ts +13 -0
- package/src/capabilities/intent-resolver.ts +26 -0
- package/src/capabilities/markdown.ts +25 -0
- package/src/capabilities/react-surface.tsx +41 -0
- package/src/components/FileContainer.tsx +46 -0
- package/src/components/FileInput.tsx +46 -0
- package/src/components/index.ts +3 -5
- package/src/extensions/image.stories.tsx +26 -68
- package/src/extensions/image.tsx +203 -0
- package/src/{common.ts → helpers/common.ts} +1 -1
- package/src/helpers/index.ts +8 -0
- package/src/{load.ts → helpers/load.ts} +38 -9
- package/src/{upload.ts → helpers/upload.ts} +18 -4
- package/src/helpers/wnfs-url.ts +36 -0
- package/src/index.ts +2 -4
- package/src/meta.ts +1 -2
- package/src/translations.ts +5 -0
- package/src/types/file.ts +2 -3
- package/src/types/types.ts +30 -19
- package/dist/lib/browser/FileCard-HJIZDWJF.mjs +0 -39
- package/dist/lib/browser/FileCard-HJIZDWJF.mjs.map +0 -7
- package/dist/lib/browser/FileMain-WEWTX7QB.mjs +0 -27
- package/dist/lib/browser/FileMain-WEWTX7QB.mjs.map +0 -7
- package/dist/lib/browser/FileSection-BEUGJ7EI.mjs +0 -24
- package/dist/lib/browser/FileSection-BEUGJ7EI.mjs.map +0 -7
- package/dist/lib/browser/FileSlide-NYBGZEZS.mjs +0 -21
- package/dist/lib/browser/FileSlide-NYBGZEZS.mjs.map +0 -7
- package/dist/lib/browser/chunk-2I63TM7M.mjs +0 -27
- package/dist/lib/browser/chunk-2I63TM7M.mjs.map +0 -7
- package/dist/lib/browser/chunk-JDSKIDDR.mjs +0 -30
- package/dist/lib/browser/chunk-JDSKIDDR.mjs.map +0 -7
- package/dist/lib/browser/chunk-VL3H7P4F.mjs.map +0 -7
- package/dist/lib/browser/meta.mjs +0 -9
- package/dist/lib/browser/meta.mjs.map +0 -7
- package/dist/types/src/common.d.ts.map +0 -1
- package/dist/types/src/components/FileCard.d.ts +0 -9
- package/dist/types/src/components/FileCard.d.ts.map +0 -1
- package/dist/types/src/components/FileMain.d.ts +0 -7
- package/dist/types/src/components/FileMain.d.ts.map +0 -1
- package/dist/types/src/components/FileSection.d.ts +0 -8
- package/dist/types/src/components/FileSection.d.ts.map +0 -1
- package/dist/types/src/components/FileSlide.d.ts +0 -8
- package/dist/types/src/components/FileSlide.d.ts.map +0 -1
- package/dist/types/src/load.d.ts +0 -8
- package/dist/types/src/load.d.ts.map +0 -1
- package/dist/types/src/upload.d.ts +0 -10
- package/dist/types/src/upload.d.ts.map +0 -1
- package/dist/types/src/wnfs-url.d.ts +0 -2
- package/dist/types/src/wnfs-url.d.ts.map +0 -1
- package/src/components/FileCard.tsx +0 -45
- package/src/components/FileMain.tsx +0 -28
- package/src/components/FileSection.tsx +0 -20
- package/src/components/FileSlide.tsx +0 -20
- package/src/extensions/image.ts +0 -244
- package/src/wnfs-url.ts +0 -7
- /package/dist/types/src/{common.d.ts → helpers/common.d.ts} +0 -0
|
@@ -1,517 +1,119 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
Blockstore,
|
|
3
|
+
FileUploader,
|
|
4
|
+
IntentResolver,
|
|
5
|
+
Markdown,
|
|
6
|
+
ReactSurface
|
|
7
|
+
} from "./chunk-ED7HMPYN.mjs";
|
|
8
|
+
import {
|
|
9
|
+
WnfsCapabilities
|
|
10
|
+
} from "./chunk-357BWHML.mjs";
|
|
11
|
+
import {
|
|
12
|
+
FileType,
|
|
13
|
+
WnfsAction
|
|
14
|
+
} from "./chunk-EMRQJXBW.mjs";
|
|
4
15
|
import {
|
|
5
16
|
WNFS_PLUGIN,
|
|
6
|
-
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
|
|
9
|
-
// packages/plugins/experimental/plugin-wnfs/src/WnfsPlugin.tsx
|
|
10
|
-
import { FileCloud } from "@phosphor-icons/react";
|
|
11
|
-
import React2 from "react";
|
|
12
|
-
import { isObject, resolvePlugin } from "@dxos/app-framework";
|
|
13
|
-
import { invariant } from "@dxos/invariant";
|
|
14
|
-
import { parseClientPlugin } from "@dxos/plugin-client";
|
|
15
|
-
import { getSpace } from "@dxos/react-client/echo";
|
|
16
|
-
import { isTileComponentProps } from "@dxos/react-ui-mosaic";
|
|
17
|
+
meta
|
|
18
|
+
} from "./chunk-6YFT42F7.mjs";
|
|
17
19
|
|
|
18
|
-
// packages/plugins/
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
20
|
+
// packages/plugins/plugin-wnfs/src/WnfsPlugin.tsx
|
|
21
|
+
import { pipe } from "effect";
|
|
22
|
+
import { Capabilities, Events, chain, contributes, createIntent, defineModule, definePlugin, oneOf } from "@dxos/app-framework";
|
|
23
|
+
import { ClientCapabilities, ClientEvents } from "@dxos/plugin-client";
|
|
21
24
|
|
|
22
|
-
// packages/plugins/
|
|
23
|
-
import { CID } from "multiformats/cid";
|
|
24
|
-
import { sha256 } from "multiformats/hashes/sha2";
|
|
25
|
-
import * as crypto from "@dxos/crypto";
|
|
26
|
-
var filePath = (fileName, space) => {
|
|
27
|
-
return [
|
|
28
|
-
"spaces",
|
|
29
|
-
space.properties.id,
|
|
30
|
-
"files",
|
|
31
|
-
fileName
|
|
32
|
-
];
|
|
33
|
-
};
|
|
34
|
-
var Rng = class {
|
|
35
|
-
randomBytes(count) {
|
|
36
|
-
return new Uint8Array(crypto.randomBytes(count));
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
var store = (blockstore) => {
|
|
40
|
-
const getBlock = async (cid) => {
|
|
41
|
-
const decodedCid = CID.decode(cid);
|
|
42
|
-
return await blockstore.get(decodedCid);
|
|
43
|
-
};
|
|
44
|
-
const hasBlock = async (cid) => {
|
|
45
|
-
const decodedCid = CID.decode(cid);
|
|
46
|
-
return await blockstore.has(decodedCid);
|
|
47
|
-
};
|
|
48
|
-
const putBlockKeyed = async (cid, bytes) => {
|
|
49
|
-
const decodedCid = CID.decode(cid);
|
|
50
|
-
await blockstore.put(decodedCid, bytes);
|
|
51
|
-
};
|
|
52
|
-
const putBlock = async (bytes, codec) => {
|
|
53
|
-
const hash = await sha256.digest(bytes);
|
|
54
|
-
const cid = CID.create(1, codec, hash);
|
|
55
|
-
await blockstore.put(cid, bytes);
|
|
56
|
-
return cid.bytes;
|
|
57
|
-
};
|
|
58
|
-
return {
|
|
59
|
-
getBlock,
|
|
60
|
-
hasBlock,
|
|
61
|
-
putBlockKeyed,
|
|
62
|
-
putBlock
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
var storeName = () => "dxos/wnfs";
|
|
66
|
-
|
|
67
|
-
// packages/plugins/experimental/plugin-wnfs/src/blockstore.ts
|
|
68
|
-
var create = (apiHost) => {
|
|
69
|
-
return new MixedBlockstore(apiHost);
|
|
70
|
-
};
|
|
71
|
-
var MixedBlockstore = class extends BaseBlockstore {
|
|
72
|
-
#apiHost;
|
|
73
|
-
#idbStore;
|
|
74
|
-
constructor(apiHost) {
|
|
75
|
-
super();
|
|
76
|
-
this.#apiHost = apiHost;
|
|
77
|
-
this.#idbStore = new IDBBlockstore(storeName());
|
|
78
|
-
}
|
|
79
|
-
async open() {
|
|
80
|
-
await this.#idbStore.open();
|
|
81
|
-
}
|
|
82
|
-
url(apiHost, cid) {
|
|
83
|
-
const path = cid ? cid.toString() : "";
|
|
84
|
-
return `${apiHost}/api/file/${path}`;
|
|
85
|
-
}
|
|
86
|
-
// Blockstore implementation
|
|
87
|
-
async delete(key) {
|
|
88
|
-
await this.#idbStore.delete(key);
|
|
89
|
-
if (this.#apiHost) {
|
|
90
|
-
await fetch(this.url(this.#apiHost, key), {
|
|
91
|
-
method: "DELETE"
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
async get(key) {
|
|
96
|
-
if (await this.#idbStore.has(key)) {
|
|
97
|
-
return await this.#idbStore.get(key);
|
|
98
|
-
}
|
|
99
|
-
if (this.#apiHost) {
|
|
100
|
-
return await fetch(this.url(this.#apiHost, key), {
|
|
101
|
-
method: "GET"
|
|
102
|
-
}).then((r) => r.arrayBuffer()).then((r) => new Uint8Array(r));
|
|
103
|
-
}
|
|
104
|
-
return await this.#idbStore.get(key);
|
|
105
|
-
}
|
|
106
|
-
async has(key) {
|
|
107
|
-
if (await this.#idbStore.has(key)) {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
if (this.#apiHost) {
|
|
111
|
-
return await fetch(this.url(this.#apiHost, key), {
|
|
112
|
-
method: "HEAD"
|
|
113
|
-
}).then((r) => r.ok);
|
|
114
|
-
}
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
async put(key, val) {
|
|
118
|
-
await this.#idbStore.put(key, val);
|
|
119
|
-
if (this.#apiHost) {
|
|
120
|
-
await fetch(this.url(this.#apiHost, key), {
|
|
121
|
-
method: "POST",
|
|
122
|
-
body: val
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return key;
|
|
126
|
-
}
|
|
127
|
-
async destroy() {
|
|
128
|
-
await this.#idbStore.destroy();
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// packages/plugins/experimental/plugin-wnfs/src/components/index.ts
|
|
133
|
-
import React from "react";
|
|
134
|
-
var FileCard = React.lazy(() => import("./FileCard-HJIZDWJF.mjs"));
|
|
135
|
-
var FileMain = React.lazy(() => import("./FileMain-WEWTX7QB.mjs"));
|
|
136
|
-
var FileSection = React.lazy(() => import("./FileSection-BEUGJ7EI.mjs"));
|
|
137
|
-
var FileSlide = React.lazy(() => import("./FileSlide-NYBGZEZS.mjs"));
|
|
138
|
-
|
|
139
|
-
// packages/plugins/experimental/plugin-wnfs/src/extensions/image.ts
|
|
140
|
-
import { syntaxTree } from "@codemirror/language";
|
|
141
|
-
import { StateField, StateEffect } from "@codemirror/state";
|
|
142
|
-
import { Decoration, EditorView, WidgetType, ViewPlugin } from "@codemirror/view";
|
|
143
|
-
import { log } from "@dxos/log";
|
|
144
|
-
|
|
145
|
-
// packages/plugins/experimental/plugin-wnfs/src/load.ts
|
|
146
|
-
import { CID as CID2 } from "multiformats";
|
|
147
|
-
import * as Uint8Arrays from "uint8arrays";
|
|
148
|
-
import { AccessKey, PrivateForest, PrivateDirectory, PrivateNode } from "wnfs";
|
|
149
|
-
var loadWnfs = async (space, blockstore) => {
|
|
150
|
-
const exists = space.properties.wnfs_access_key !== void 0 && space.properties.wnfs_private_forest_cid !== void 0;
|
|
151
|
-
return exists ? await loadWnfsDir(blockstore, space) : await createWnfsDir(blockstore, space);
|
|
152
|
-
};
|
|
153
|
-
var createWnfsDir = async (blockstore, space) => {
|
|
154
|
-
const wnfsStore = store(blockstore);
|
|
155
|
-
const rng = new Rng();
|
|
156
|
-
const forest = new PrivateForest(rng);
|
|
157
|
-
const dirResult = await PrivateDirectory.newAndStore(forest.emptyName(), /* @__PURE__ */ new Date(), forest, wnfsStore, rng);
|
|
158
|
-
const dir = dirResult.rootDir;
|
|
159
|
-
const [accessKeyRaw, newForest] = await dir.asNode().store(dirResult.forest, wnfsStore, rng);
|
|
160
|
-
const cidBytes = await newForest.store(wnfsStore);
|
|
161
|
-
space.properties.wnfs_access_key = Uint8Arrays.toString(accessKeyRaw.toBytes(), "base64");
|
|
162
|
-
space.properties.wnfs_private_forest_cid = CID2.decode(cidBytes).toString();
|
|
163
|
-
return {
|
|
164
|
-
directory: dir,
|
|
165
|
-
forest: newForest
|
|
166
|
-
};
|
|
167
|
-
};
|
|
168
|
-
var loadWnfsDir = async (blockstore, space) => {
|
|
169
|
-
const wnfsStore = store(blockstore);
|
|
170
|
-
const accessKey = AccessKey.fromBytes(Uint8Arrays.fromString(space.properties.wnfs_access_key, "base64"));
|
|
171
|
-
const forest = await PrivateForest.load(CID2.parse(space.properties.wnfs_private_forest_cid).bytes, wnfsStore);
|
|
172
|
-
const node = await PrivateNode.load(accessKey, forest, wnfsStore);
|
|
173
|
-
return {
|
|
174
|
-
directory: node.asDir(),
|
|
175
|
-
forest
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// packages/plugins/experimental/plugin-wnfs/src/extensions/image.ts
|
|
180
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-wnfs/src/extensions/image.ts";
|
|
181
|
-
var image = (options) => {
|
|
182
|
-
return [
|
|
183
|
-
stateField(options),
|
|
184
|
-
viewPlugin(options)
|
|
185
|
-
];
|
|
186
|
-
};
|
|
187
|
-
var loadedWnfsInstances = {};
|
|
188
|
-
var stateEffect = StateEffect.define({});
|
|
189
|
-
var stateField = (options) => StateField.define({
|
|
190
|
-
create: () => {
|
|
191
|
-
return Decoration.none;
|
|
192
|
-
},
|
|
193
|
-
update: (value, tr) => {
|
|
194
|
-
for (const effect of tr.effects) {
|
|
195
|
-
if (effect.is(stateEffect)) {
|
|
196
|
-
return value.map(tr.changes).update({
|
|
197
|
-
filterFrom: effect.value.from,
|
|
198
|
-
filterTo: effect.value.to,
|
|
199
|
-
filter: () => false,
|
|
200
|
-
add: effect.value.decorations
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return value;
|
|
205
|
-
},
|
|
206
|
-
provide: (f) => {
|
|
207
|
-
return EditorView.decorations.from(f);
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
var viewPlugin = (options) => ViewPlugin.define((view) => {
|
|
211
|
-
buildDecorations({
|
|
212
|
-
from: 0,
|
|
213
|
-
to: view.state.doc.length,
|
|
214
|
-
state: view.state,
|
|
215
|
-
options
|
|
216
|
-
}).then((decorations) => {
|
|
217
|
-
view.dispatch({
|
|
218
|
-
effects: stateEffect.of({
|
|
219
|
-
decorations,
|
|
220
|
-
from: 0,
|
|
221
|
-
to: view.state.doc.length
|
|
222
|
-
})
|
|
223
|
-
});
|
|
224
|
-
}).catch((err) => {
|
|
225
|
-
throw new Error(err);
|
|
226
|
-
});
|
|
227
|
-
const update = (update2) => {
|
|
228
|
-
if (!update2.docChanged) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const { from, to } = changedRange(update2);
|
|
232
|
-
buildDecorations({
|
|
233
|
-
from,
|
|
234
|
-
to,
|
|
235
|
-
state: view.state,
|
|
236
|
-
options
|
|
237
|
-
}).then((decorations) => {
|
|
238
|
-
view.dispatch({
|
|
239
|
-
effects: stateEffect.of({
|
|
240
|
-
decorations,
|
|
241
|
-
from,
|
|
242
|
-
to
|
|
243
|
-
})
|
|
244
|
-
});
|
|
245
|
-
}).catch((err) => {
|
|
246
|
-
log.catch(err, void 0, {
|
|
247
|
-
F: __dxlog_file,
|
|
248
|
-
L: 107,
|
|
249
|
-
S: void 0,
|
|
250
|
-
C: (f, a) => f(...a)
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
};
|
|
254
|
-
return {
|
|
255
|
-
update
|
|
256
|
-
};
|
|
257
|
-
});
|
|
258
|
-
var changedRange = (update) => {
|
|
259
|
-
const cursor = update.state.selection.main.head;
|
|
260
|
-
const oldCursor = update.changes.mapPos(update.startState.selection.main.head);
|
|
261
|
-
let from = Math.min(cursor, oldCursor);
|
|
262
|
-
let to = Math.max(cursor, oldCursor);
|
|
263
|
-
update.changes.iterChangedRanges((fromA, toA, fromB, toB) => {
|
|
264
|
-
from = Math.min(from, fromB);
|
|
265
|
-
to = Math.max(to, toB);
|
|
266
|
-
});
|
|
267
|
-
from = update.state.doc.lineAt(from).from;
|
|
268
|
-
to = update.state.doc.lineAt(to).to;
|
|
269
|
-
return {
|
|
270
|
-
from,
|
|
271
|
-
to
|
|
272
|
-
};
|
|
273
|
-
};
|
|
274
|
-
var buildDecorations = async ({ from, to, state, options }) => {
|
|
275
|
-
const cursor = state.selection.main.head;
|
|
276
|
-
let nodes = [];
|
|
277
|
-
syntaxTree(state).iterate({
|
|
278
|
-
enter: (node) => {
|
|
279
|
-
if (node.name === "Image") {
|
|
280
|
-
const urlNode = node.node.getChild("URL");
|
|
281
|
-
if (urlNode) {
|
|
282
|
-
const hide = state.readOnly || cursor < node.from || cursor > node.to;
|
|
283
|
-
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
|
284
|
-
if (url.startsWith("wnfs://")) {
|
|
285
|
-
nodes.push({
|
|
286
|
-
from: node.from,
|
|
287
|
-
to: node.to,
|
|
288
|
-
hide,
|
|
289
|
-
url
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
},
|
|
295
|
-
from,
|
|
296
|
-
to
|
|
297
|
-
});
|
|
298
|
-
nodes = nodes.sort((a, b) => {
|
|
299
|
-
return a.from - b.from;
|
|
300
|
-
});
|
|
301
|
-
const decorations = await nodes.reduce(async (acc, node) => {
|
|
302
|
-
const array = await acc;
|
|
303
|
-
const path = node.url.replace(/^wnfs:\/\//, "").split("/").map((p) => decodeURIComponent(p));
|
|
304
|
-
const spaceIdFromUrl = path[1];
|
|
305
|
-
if (spaceIdFromUrl !== options.space.properties.id) {
|
|
306
|
-
return array;
|
|
307
|
-
}
|
|
308
|
-
const cacheKey = options.space.properties.wnfs_private_forest_cid;
|
|
309
|
-
const { directory, forest } = loadedWnfsInstances[cacheKey] ? loadedWnfsInstances[cacheKey] : await loadWnfs(options.space, options.blockstore);
|
|
310
|
-
loadedWnfsInstances[cacheKey] = {
|
|
311
|
-
directory,
|
|
312
|
-
forest
|
|
313
|
-
};
|
|
314
|
-
const wnfsStore = store(options.blockstore);
|
|
315
|
-
const { result } = await directory.read(path, true, forest, wnfsStore);
|
|
316
|
-
const blob = new Blob([
|
|
317
|
-
result
|
|
318
|
-
]);
|
|
319
|
-
const blobUrl = URL.createObjectURL(blob);
|
|
320
|
-
return [
|
|
321
|
-
...array,
|
|
322
|
-
Decoration.replace({
|
|
323
|
-
block: true,
|
|
324
|
-
widget: new WnfsImageWidget(blobUrl)
|
|
325
|
-
}).range(node.hide ? node.from : node.to, node.to)
|
|
326
|
-
];
|
|
327
|
-
}, Promise.resolve([]));
|
|
328
|
-
return decorations;
|
|
329
|
-
};
|
|
330
|
-
var WnfsImageWidget = class extends WidgetType {
|
|
331
|
-
constructor(_url) {
|
|
332
|
-
super();
|
|
333
|
-
this._url = _url;
|
|
334
|
-
}
|
|
335
|
-
eq(other) {
|
|
336
|
-
return this._url === other._url;
|
|
337
|
-
}
|
|
338
|
-
toDOM(view) {
|
|
339
|
-
const img = document.createElement("img");
|
|
340
|
-
img.setAttribute("loading", "lazy");
|
|
341
|
-
img.setAttribute("src", this._url);
|
|
342
|
-
img.setAttribute("class", "cm-image");
|
|
343
|
-
img.onload = () => img.classList.add("cm-loaded-image");
|
|
344
|
-
return img;
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
// packages/plugins/experimental/plugin-wnfs/src/translations.ts
|
|
25
|
+
// packages/plugins/plugin-wnfs/src/translations.ts
|
|
349
26
|
var translations_default = [
|
|
350
27
|
{
|
|
351
28
|
"en-US": {
|
|
29
|
+
[FileType.typename]: {
|
|
30
|
+
"typename label": "File"
|
|
31
|
+
},
|
|
352
32
|
[WNFS_PLUGIN]: {
|
|
353
33
|
"plugin name": "Files",
|
|
354
34
|
"file title placeholder": "New file",
|
|
355
|
-
"delete object label": "Delete"
|
|
35
|
+
"delete object label": "Delete",
|
|
36
|
+
"file input placeholder": "Drop a file here, or click to select a file"
|
|
356
37
|
}
|
|
357
38
|
}
|
|
358
39
|
}
|
|
359
40
|
];
|
|
360
41
|
|
|
361
|
-
// packages/plugins/
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
url: wnfsUrl(path)
|
|
387
|
-
};
|
|
388
|
-
log2("upload", {
|
|
389
|
-
file,
|
|
390
|
-
info
|
|
391
|
-
}, {
|
|
392
|
-
F: __dxlog_file2,
|
|
393
|
-
L: 44,
|
|
394
|
-
S: void 0,
|
|
395
|
-
C: (f, a) => f(...a)
|
|
396
|
-
});
|
|
397
|
-
return info;
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
// packages/plugins/experimental/plugin-wnfs/src/WnfsPlugin.tsx
|
|
401
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-wnfs/src/WnfsPlugin.tsx";
|
|
402
|
-
var WnfsPlugin = () => {
|
|
403
|
-
let blockstore;
|
|
404
|
-
return {
|
|
405
|
-
meta: meta_default,
|
|
406
|
-
ready: async (plugins) => {
|
|
407
|
-
const client = resolvePlugin(plugins, parseClientPlugin)?.provides.client;
|
|
408
|
-
invariant(client, void 0, {
|
|
409
|
-
F: __dxlog_file3,
|
|
410
|
-
L: 31,
|
|
411
|
-
S: void 0,
|
|
412
|
-
A: [
|
|
413
|
-
"client",
|
|
414
|
-
""
|
|
415
|
-
]
|
|
416
|
-
});
|
|
417
|
-
const apiHost = client.config.values.runtime?.services?.edge?.url || "http://localhost:8787";
|
|
418
|
-
blockstore = create(apiHost);
|
|
419
|
-
await blockstore.open();
|
|
420
|
-
},
|
|
421
|
-
provides: {
|
|
422
|
-
translations: translations_default,
|
|
42
|
+
// packages/plugins/plugin-wnfs/src/WnfsPlugin.tsx
|
|
43
|
+
var WnfsPlugin = () => definePlugin(meta, [
|
|
44
|
+
defineModule({
|
|
45
|
+
id: `${meta.id}/module/blockstore`,
|
|
46
|
+
activatesOn: ClientEvents.ClientReady,
|
|
47
|
+
activate: Blockstore
|
|
48
|
+
}),
|
|
49
|
+
defineModule({
|
|
50
|
+
id: `${meta.id}/module/instances`,
|
|
51
|
+
activatesOn: Events.Startup,
|
|
52
|
+
activate: () => {
|
|
53
|
+
const instances = {};
|
|
54
|
+
return contributes(WnfsCapabilities.Instances, instances);
|
|
55
|
+
}
|
|
56
|
+
}),
|
|
57
|
+
defineModule({
|
|
58
|
+
id: `${meta.id}/module/translations`,
|
|
59
|
+
activatesOn: Events.SetupTranslations,
|
|
60
|
+
activate: () => contributes(Capabilities.Translations, translations_default)
|
|
61
|
+
}),
|
|
62
|
+
defineModule({
|
|
63
|
+
id: `${meta.id}/module/metadata`,
|
|
64
|
+
activatesOn: oneOf(Events.Startup, Events.SetupAppGraph),
|
|
65
|
+
activate: () => contributes(Capabilities.Metadata, {
|
|
66
|
+
id: FileType.typename,
|
|
423
67
|
metadata: {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
435
|
-
},
|
|
436
|
-
echo: {
|
|
437
|
-
system: [
|
|
438
|
-
FileType
|
|
439
|
-
]
|
|
440
|
-
},
|
|
441
|
-
// TODO(burdon): Add intent to upload file.
|
|
442
|
-
file: {
|
|
443
|
-
upload: async (file, space) => {
|
|
444
|
-
if (!blockstore) {
|
|
445
|
-
throw new Error("Blockstore is not ready yet");
|
|
446
|
-
}
|
|
447
|
-
return await upload({
|
|
448
|
-
blockstore,
|
|
449
|
-
file,
|
|
450
|
-
space
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
},
|
|
454
|
-
markdown: {
|
|
455
|
-
extensions: ({ document: document2 }) => {
|
|
456
|
-
if (!blockstore) {
|
|
457
|
-
throw new Error("Blockstore is not ready yet");
|
|
458
|
-
}
|
|
459
|
-
if (document2) {
|
|
460
|
-
const space = getSpace(document2);
|
|
461
|
-
return space ? [
|
|
462
|
-
image({
|
|
463
|
-
blockstore,
|
|
464
|
-
space
|
|
465
|
-
})
|
|
466
|
-
] : [];
|
|
467
|
-
}
|
|
468
|
-
return [];
|
|
469
|
-
}
|
|
470
|
-
},
|
|
471
|
-
surface: {
|
|
472
|
-
component: ({ data, role, ...props }, forwardedRef) => {
|
|
473
|
-
switch (role) {
|
|
474
|
-
case "main":
|
|
475
|
-
return data.active instanceof FileType ? /* @__PURE__ */ React2.createElement(FileMain, {
|
|
476
|
-
file: data.active
|
|
477
|
-
}) : null;
|
|
478
|
-
case "slide":
|
|
479
|
-
return data.slide instanceof FileType ? /* @__PURE__ */ React2.createElement(FileSlide, {
|
|
480
|
-
file: data.slide,
|
|
481
|
-
cover: false
|
|
482
|
-
}) : null;
|
|
483
|
-
case "section":
|
|
484
|
-
return data.object instanceof FileType ? /* @__PURE__ */ React2.createElement(FileSection, {
|
|
485
|
-
file: data.object
|
|
486
|
-
}) : null;
|
|
487
|
-
case "card": {
|
|
488
|
-
if (isObject(data.content) && typeof data.content.id === "string" && data.content.object instanceof FileType) {
|
|
489
|
-
const cardProps = {
|
|
490
|
-
...props,
|
|
491
|
-
item: {
|
|
492
|
-
id: data.content.id,
|
|
493
|
-
object: data.content.object
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
return isTileComponentProps(cardProps) ? /* @__PURE__ */ React2.createElement(FileCard, {
|
|
497
|
-
...cardProps,
|
|
498
|
-
ref: forwardedRef
|
|
499
|
-
}) : null;
|
|
500
|
-
}
|
|
501
|
-
break;
|
|
502
|
-
}
|
|
68
|
+
creationSchema: WnfsAction.UploadFileSchema,
|
|
69
|
+
createObject: ({ file }, { space }) => pipe(createIntent(WnfsAction.Upload, {
|
|
70
|
+
file,
|
|
71
|
+
space
|
|
72
|
+
}), chain(WnfsAction.Create, {})),
|
|
73
|
+
label: (object) => object instanceof FileType ? object.name : void 0,
|
|
74
|
+
placeholder: [
|
|
75
|
+
"file title placeholder",
|
|
76
|
+
{
|
|
77
|
+
ns: WNFS_PLUGIN
|
|
503
78
|
}
|
|
504
|
-
|
|
505
|
-
|
|
79
|
+
],
|
|
80
|
+
// TODO(wittjosiah): Would be nice if icon could change based on the type of the file.
|
|
81
|
+
icon: "ph--file--regular"
|
|
506
82
|
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
83
|
+
})
|
|
84
|
+
}),
|
|
85
|
+
defineModule({
|
|
86
|
+
id: `${meta.id}/module/schema`,
|
|
87
|
+
activatesOn: ClientEvents.SetupClient,
|
|
88
|
+
activate: () => contributes(ClientCapabilities.Schema, [
|
|
89
|
+
FileType
|
|
90
|
+
])
|
|
91
|
+
}),
|
|
92
|
+
defineModule({
|
|
93
|
+
id: `${meta.id}/module/file-uploader`,
|
|
94
|
+
activatesOn: ClientEvents.ClientReady,
|
|
95
|
+
activate: FileUploader
|
|
96
|
+
}),
|
|
97
|
+
defineModule({
|
|
98
|
+
id: `${meta.id}/module/markdown`,
|
|
99
|
+
activatesOn: Events.Startup,
|
|
100
|
+
activate: Markdown
|
|
101
|
+
}),
|
|
102
|
+
defineModule({
|
|
103
|
+
id: `${meta.id}/module/react-surface`,
|
|
104
|
+
activatesOn: Events.Startup,
|
|
105
|
+
activate: ReactSurface
|
|
106
|
+
}),
|
|
107
|
+
defineModule({
|
|
108
|
+
id: `${meta.id}/module/intent-resolver`,
|
|
109
|
+
activatesOn: Events.SetupIntents,
|
|
110
|
+
activate: IntentResolver
|
|
111
|
+
})
|
|
112
|
+
]);
|
|
513
113
|
export {
|
|
114
|
+
WNFS_PLUGIN,
|
|
115
|
+
WnfsCapabilities,
|
|
514
116
|
WnfsPlugin,
|
|
515
|
-
|
|
117
|
+
meta
|
|
516
118
|
};
|
|
517
119
|
//# sourceMappingURL=index.mjs.map
|