@dxos/plugin-wnfs 0.7.5-main.499c70c → 0.7.5-main.6a330ac

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