@dxos/plugin-wnfs 0.7.4 → 0.7.5-labs.401163d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/dist/lib/browser/FileContainer-6CC7F4KO.mjs +94 -0
  2. package/dist/lib/browser/FileContainer-6CC7F4KO.mjs.map +7 -0
  3. package/dist/lib/browser/blockstore-RFH5C42Z.mjs +192 -0
  4. package/dist/lib/browser/blockstore-RFH5C42Z.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-EELFT4QP.mjs +15 -0
  6. package/dist/lib/browser/chunk-EELFT4QP.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-KENG3KHT.mjs +16 -0
  8. package/dist/lib/browser/chunk-KENG3KHT.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-KFKLBRAQ.mjs +16 -0
  10. package/dist/lib/browser/chunk-KFKLBRAQ.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-RYOWC7TX.mjs +60 -0
  12. package/dist/lib/browser/chunk-RYOWC7TX.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-SCQWJNHD.mjs +157 -0
  14. package/dist/lib/browser/chunk-SCQWJNHD.mjs.map +7 -0
  15. package/dist/lib/browser/file-uploader-3DF5T3EZ.mjs +29 -0
  16. package/dist/lib/browser/file-uploader-3DF5T3EZ.mjs.map +7 -0
  17. package/dist/lib/browser/index.mjs +96 -494
  18. package/dist/lib/browser/index.mjs.map +4 -4
  19. package/dist/lib/browser/intent-resolver-6IX7MROZ.mjs +49 -0
  20. package/dist/lib/browser/intent-resolver-6IX7MROZ.mjs.map +7 -0
  21. package/dist/lib/browser/markdown-MGMT4KWF.mjs +198 -0
  22. package/dist/lib/browser/markdown-MGMT4KWF.mjs.map +7 -0
  23. package/dist/lib/browser/meta.json +1 -1
  24. package/dist/lib/browser/react-surface-2UHNQPX4.mjs +81 -0
  25. package/dist/lib/browser/react-surface-2UHNQPX4.mjs.map +7 -0
  26. package/dist/lib/browser/types/index.mjs +2 -2
  27. package/dist/types/src/WnfsPlugin.d.ts +1 -3
  28. package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
  29. package/dist/types/src/blockstore.d.ts +4 -1
  30. package/dist/types/src/blockstore.d.ts.map +1 -1
  31. package/dist/types/src/capabilities/blockstore.d.ts +4 -0
  32. package/dist/types/src/capabilities/blockstore.d.ts.map +1 -0
  33. package/dist/types/src/capabilities/capabilities.d.ts +12 -0
  34. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
  35. package/dist/types/src/capabilities/file-uploader.d.ts +4 -0
  36. package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -0
  37. package/dist/types/src/capabilities/index.d.ts +7 -0
  38. package/dist/types/src/capabilities/index.d.ts.map +1 -0
  39. package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
  40. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
  41. package/dist/types/src/capabilities/markdown.d.ts +4 -0
  42. package/dist/types/src/capabilities/markdown.d.ts.map +1 -0
  43. package/dist/types/src/capabilities/react-surface.d.ts +4 -0
  44. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  45. package/dist/types/src/components/FileContainer.d.ts +8 -0
  46. package/dist/types/src/components/FileContainer.d.ts.map +1 -0
  47. package/dist/types/src/components/FileInput.d.ts +8 -0
  48. package/dist/types/src/components/FileInput.d.ts.map +1 -0
  49. package/dist/types/src/components/index.d.ts +4 -11
  50. package/dist/types/src/components/index.d.ts.map +1 -1
  51. package/dist/types/src/extensions/image.d.ts +5 -0
  52. package/dist/types/src/extensions/image.d.ts.map +1 -1
  53. package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
  54. package/dist/types/src/helpers/common.d.ts.map +1 -0
  55. package/dist/types/src/helpers/index.d.ts +5 -0
  56. package/dist/types/src/helpers/index.d.ts.map +1 -0
  57. package/dist/types/src/helpers/load.d.ts +13 -0
  58. package/dist/types/src/helpers/load.d.ts.map +1 -0
  59. package/dist/types/src/helpers/upload.d.ts +15 -0
  60. package/dist/types/src/helpers/upload.d.ts.map +1 -0
  61. package/dist/types/src/helpers/wnfs-url.d.ts +11 -0
  62. package/dist/types/src/helpers/wnfs-url.d.ts.map +1 -0
  63. package/dist/types/src/index.d.ts +2 -2
  64. package/dist/types/src/index.d.ts.map +1 -1
  65. package/dist/types/src/meta.d.ts +2 -4
  66. package/dist/types/src/meta.d.ts.map +1 -1
  67. package/dist/types/src/translations.d.ts +15 -1
  68. package/dist/types/src/translations.d.ts.map +1 -1
  69. package/dist/types/src/types/file.d.ts +7 -11
  70. package/dist/types/src/types/file.d.ts.map +1 -1
  71. package/dist/types/src/types/types.d.ts +49 -6
  72. package/dist/types/src/types/types.d.ts.map +1 -1
  73. package/dist/types/tsconfig.tsbuildinfo +1 -0
  74. package/package.json +28 -26
  75. package/src/WnfsPlugin.tsx +76 -92
  76. package/src/blockstore.ts +151 -21
  77. package/src/capabilities/blockstore.ts +18 -0
  78. package/src/capabilities/capabilities.ts +18 -0
  79. package/src/capabilities/file-uploader.ts +24 -0
  80. package/src/capabilities/index.ts +13 -0
  81. package/src/capabilities/intent-resolver.ts +32 -0
  82. package/src/capabilities/markdown.ts +25 -0
  83. package/src/capabilities/react-surface.tsx +41 -0
  84. package/src/components/FileContainer.tsx +46 -0
  85. package/src/components/FileInput.tsx +46 -0
  86. package/src/components/index.ts +3 -5
  87. package/src/extensions/image.stories.tsx +26 -68
  88. package/src/extensions/image.tsx +203 -0
  89. package/src/{common.ts → helpers/common.ts} +1 -1
  90. package/src/helpers/index.ts +8 -0
  91. package/src/{load.ts → helpers/load.ts} +38 -9
  92. package/src/{upload.ts → helpers/upload.ts} +18 -4
  93. package/src/helpers/wnfs-url.ts +36 -0
  94. package/src/index.ts +2 -4
  95. package/src/meta.ts +2 -3
  96. package/src/translations.ts +5 -0
  97. package/src/types/file.ts +2 -3
  98. package/src/types/types.ts +30 -19
  99. package/dist/lib/browser/FileCard-HJIZDWJF.mjs +0 -39
  100. package/dist/lib/browser/FileCard-HJIZDWJF.mjs.map +0 -7
  101. package/dist/lib/browser/FileMain-WEWTX7QB.mjs +0 -27
  102. package/dist/lib/browser/FileMain-WEWTX7QB.mjs.map +0 -7
  103. package/dist/lib/browser/FileSection-BEUGJ7EI.mjs +0 -24
  104. package/dist/lib/browser/FileSection-BEUGJ7EI.mjs.map +0 -7
  105. package/dist/lib/browser/FileSlide-NYBGZEZS.mjs +0 -21
  106. package/dist/lib/browser/FileSlide-NYBGZEZS.mjs.map +0 -7
  107. package/dist/lib/browser/chunk-2I63TM7M.mjs +0 -27
  108. package/dist/lib/browser/chunk-2I63TM7M.mjs.map +0 -7
  109. package/dist/lib/browser/chunk-JDSKIDDR.mjs +0 -30
  110. package/dist/lib/browser/chunk-JDSKIDDR.mjs.map +0 -7
  111. package/dist/lib/browser/chunk-VL3H7P4F.mjs +0 -18
  112. package/dist/lib/browser/chunk-VL3H7P4F.mjs.map +0 -7
  113. package/dist/lib/browser/meta.mjs +0 -9
  114. package/dist/lib/browser/meta.mjs.map +0 -7
  115. package/dist/types/src/common.d.ts.map +0 -1
  116. package/dist/types/src/components/FileCard.d.ts +0 -9
  117. package/dist/types/src/components/FileCard.d.ts.map +0 -1
  118. package/dist/types/src/components/FileMain.d.ts +0 -7
  119. package/dist/types/src/components/FileMain.d.ts.map +0 -1
  120. package/dist/types/src/components/FileSection.d.ts +0 -8
  121. package/dist/types/src/components/FileSection.d.ts.map +0 -1
  122. package/dist/types/src/components/FileSlide.d.ts +0 -8
  123. package/dist/types/src/components/FileSlide.d.ts.map +0 -1
  124. package/dist/types/src/load.d.ts +0 -8
  125. package/dist/types/src/load.d.ts.map +0 -1
  126. package/dist/types/src/upload.d.ts +0 -10
  127. package/dist/types/src/upload.d.ts.map +0 -1
  128. package/dist/types/src/wnfs-url.d.ts +0 -2
  129. package/dist/types/src/wnfs-url.d.ts.map +0 -1
  130. package/src/components/FileCard.tsx +0 -45
  131. package/src/components/FileMain.tsx +0 -28
  132. package/src/components/FileSection.tsx +0 -20
  133. package/src/components/FileSlide.tsx +0 -20
  134. package/src/extensions/image.ts +0 -244
  135. package/src/wnfs-url.ts +0 -7
  136. /package/dist/types/src/{common.d.ts → helpers/common.d.ts} +0 -0
@@ -1,517 +1,119 @@
1
1
  import {
2
- FileType
3
- } from "./chunk-JDSKIDDR.mjs";
2
+ Blockstore,
3
+ FileUploader,
4
+ IntentResolver,
5
+ Markdown,
6
+ ReactSurface
7
+ } from "./chunk-KENG3KHT.mjs";
8
+ import {
9
+ WnfsCapabilities
10
+ } from "./chunk-KFKLBRAQ.mjs";
11
+ import {
12
+ FileType,
13
+ WnfsAction
14
+ } from "./chunk-RYOWC7TX.mjs";
4
15
  import {
5
16
  WNFS_PLUGIN,
6
- meta_default
7
- } from "./chunk-VL3H7P4F.mjs";
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-EELFT4QP.mjs";
17
19
 
18
- // packages/plugins/experimental/plugin-wnfs/src/blockstore.ts
19
- import { BaseBlockstore } from "blockstore-core";
20
- import { IDBBlockstore } from "blockstore-idb";
20
+ // packages/plugins/plugin-wnfs/src/WnfsPlugin.tsx
21
+ import { pipe } from "effect";
22
+ import { Capabilities, Events, chain, contributes, createIntent, defineModule, definePlugin } from "@dxos/app-framework";
23
+ import { ClientCapabilities, ClientEvents } from "@dxos/plugin-client";
21
24
 
22
- // packages/plugins/experimental/plugin-wnfs/src/common.ts
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/experimental/plugin-wnfs/src/upload.ts
362
- import { CID as CID3 } from "multiformats";
363
- import * as Raw from "multiformats/codecs/raw";
364
- import { sha256 as sha2562 } from "multiformats/hashes/sha2";
365
- import { log as log2 } from "@dxos/log";
366
-
367
- // packages/plugins/experimental/plugin-wnfs/src/wnfs-url.ts
368
- var wnfsUrl = (filePath2) => {
369
- return "wnfs://" + filePath2.map((f) => encodeURIComponent(f)).join("/");
370
- };
371
-
372
- // packages/plugins/experimental/plugin-wnfs/src/upload.ts
373
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-wnfs/src/upload.ts";
374
- var upload = async ({ blockstore, file, space }) => {
375
- const { directory, forest } = await loadWnfs(space, blockstore);
376
- const wnfsStore = store(blockstore);
377
- const bytes = new Uint8Array(await file.arrayBuffer());
378
- const hash = await sha2562.digest(bytes);
379
- const cid = CID3.create(1, Raw.code, hash);
380
- const path = filePath(cid.toString(), space);
381
- const result = await directory.write(path, true, bytes, /* @__PURE__ */ new Date(), forest, wnfsStore, new Rng());
382
- const [_, updatedForest] = await result.rootDir.store(result.forest, wnfsStore, new Rng());
383
- const cidBytes = await updatedForest.store(wnfsStore);
384
- space.properties.wnfs_private_forest_cid = CID3.decode(cidBytes).toString();
385
- const info = {
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: Events.SetupMetadata,
65
+ activate: () => contributes(Capabilities.Metadata, {
66
+ id: FileType.typename,
423
67
  metadata: {
424
- records: {
425
- [FileType.typename]: {
426
- placeholder: [
427
- "file title placeholder",
428
- {
429
- ns: WNFS_PLUGIN
430
- }
431
- ],
432
- icon: (props) => /* @__PURE__ */ React2.createElement(FileCloud, props)
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
- return null;
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
- // packages/plugins/experimental/plugin-wnfs/src/index.ts
512
- var src_default = WnfsPlugin;
83
+ })
84
+ }),
85
+ defineModule({
86
+ id: `${meta.id}/module/schema`,
87
+ activatesOn: ClientEvents.SetupSchema,
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.SetupSurfaces,
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
- src_default as default
117
+ meta
516
118
  };
517
119
  //# sourceMappingURL=index.mjs.map