@dxos/plugin-wnfs 0.7.5-main.9d26e3a → 0.7.5-main.e9bb01b

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-OEGOSGBH.mjs +94 -0
  2. package/dist/lib/browser/FileContainer-OEGOSGBH.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-KFKLBRAQ.mjs +16 -0
  8. package/dist/lib/browser/chunk-KFKLBRAQ.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-RYOWC7TX.mjs +60 -0
  10. package/dist/lib/browser/chunk-RYOWC7TX.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-SCQWJNHD.mjs +157 -0
  12. package/dist/lib/browser/chunk-SCQWJNHD.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-W6SFXQTJ.mjs +16 -0
  14. package/dist/lib/browser/chunk-W6SFXQTJ.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 -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-INP3T25J.mjs +81 -0
  25. package/dist/lib/browser/react-surface-INP3T25J.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 +4 -6
  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 -1
  74. package/package.json +28 -26
  75. package/src/WnfsPlugin.tsx +76 -86
  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 -4
  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
@@ -0,0 +1,16 @@
1
+ // packages/plugins/plugin-wnfs/src/capabilities/index.ts
2
+ import { lazy } from "@dxos/app-framework";
3
+ var Blockstore = lazy(() => import("./blockstore-RFH5C42Z.mjs"));
4
+ var FileUploader = lazy(() => import("./file-uploader-3DF5T3EZ.mjs"));
5
+ var IntentResolver = lazy(() => import("./intent-resolver-6IX7MROZ.mjs"));
6
+ var Markdown = lazy(() => import("./markdown-MGMT4KWF.mjs"));
7
+ var ReactSurface = lazy(() => import("./react-surface-INP3T25J.mjs"));
8
+
9
+ export {
10
+ Blockstore,
11
+ FileUploader,
12
+ IntentResolver,
13
+ Markdown,
14
+ ReactSurface
15
+ };
16
+ //# sourceMappingURL=chunk-W6SFXQTJ.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/capabilities/index.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { lazy } from '@dxos/app-framework';\n\nexport const Blockstore = lazy(() => import('./blockstore'));\nexport const FileUploader = lazy(() => import('./file-uploader'));\nexport const IntentResolver = lazy(() => import('./intent-resolver'));\nexport const Markdown = lazy(() => import('./markdown'));\nexport const ReactSurface = lazy(() => import('./react-surface'));\n\nexport * from './capabilities';\n"],
5
+ "mappings": ";AAIA,SAASA,YAAY;AAEd,IAAMC,aAAaC,KAAK,MAAM,OAAO,2BAAA,CAAA;AACrC,IAAMC,eAAeD,KAAK,MAAM,OAAO,8BAAA,CAAA;AACvC,IAAME,iBAAiBF,KAAK,MAAM,OAAO,gCAAA,CAAA;AACzC,IAAMG,WAAWH,KAAK,MAAM,OAAO,yBAAA,CAAA;AACnC,IAAMI,eAAeJ,KAAK,MAAM,OAAO,8BAAA,CAAA;",
6
+ "names": ["lazy", "Blockstore", "lazy", "FileUploader", "IntentResolver", "Markdown", "ReactSurface"]
7
+ }
@@ -0,0 +1,29 @@
1
+ import {
2
+ WnfsAction
3
+ } from "./chunk-RYOWC7TX.mjs";
4
+ import "./chunk-EELFT4QP.mjs";
5
+
6
+ // packages/plugins/plugin-wnfs/src/capabilities/file-uploader.ts
7
+ import { Effect, pipe } from "effect";
8
+ import { Capabilities, chain, contributes, createIntent } from "@dxos/app-framework";
9
+ import { SpaceAction } from "@dxos/plugin-space/types";
10
+ var file_uploader_default = (context) => {
11
+ return contributes(Capabilities.FileUploader, (file, space) => {
12
+ const { dispatch } = context.requestCapability(Capabilities.IntentDispatcher);
13
+ const program = Effect.gen(function* () {
14
+ const fileInfo = yield* dispatch(createIntent(WnfsAction.Upload, {
15
+ file,
16
+ space
17
+ }));
18
+ yield* dispatch(pipe(createIntent(WnfsAction.Create, fileInfo), chain(SpaceAction.AddObject, {
19
+ target: space
20
+ })));
21
+ return fileInfo;
22
+ });
23
+ return Effect.runPromise(program);
24
+ });
25
+ };
26
+ export {
27
+ file_uploader_default as default
28
+ };
29
+ //# sourceMappingURL=file-uploader-3DF5T3EZ.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 { Effect, pipe } from 'effect';\n\nimport { Capabilities, chain, contributes, createIntent, type PluginsContext } from '@dxos/app-framework';\nimport { SpaceAction } from '@dxos/plugin-space/types';\n\nimport { WnfsAction } from '../types';\n\nexport default (context: PluginsContext) => {\n return contributes(Capabilities.FileUploader, (file, space) => {\n const { dispatch } = context.requestCapability(Capabilities.IntentDispatcher);\n\n const program = Effect.gen(function* () {\n const fileInfo = yield* dispatch(createIntent(WnfsAction.Upload, { file, space }));\n yield* dispatch(pipe(createIntent(WnfsAction.Create, fileInfo), chain(SpaceAction.AddObject, { target: space })));\n return fileInfo;\n });\n\n return Effect.runPromise(program);\n });\n};\n"],
5
+ "mappings": ";;;;;;AAIA,SAASA,QAAQC,YAAY;AAE7B,SAASC,cAAcC,OAAOC,aAAaC,oBAAyC;AACpF,SAASC,mBAAmB;AAI5B,IAAA,wBAAe,CAACC,YAAAA;AACd,SAAOC,YAAYC,aAAaC,cAAc,CAACC,MAAMC,UAAAA;AACnD,UAAM,EAAEC,SAAQ,IAAKN,QAAQO,kBAAkBL,aAAaM,gBAAgB;AAE5E,UAAMC,UAAUC,OAAOC,IAAI,aAAA;AACzB,YAAMC,WAAW,OAAON,SAASO,aAAaC,WAAWC,QAAQ;QAAEX;QAAMC;MAAM,CAAA,CAAA;AAC/E,aAAOC,SAASU,KAAKH,aAAaC,WAAWG,QAAQL,QAAAA,GAAWM,MAAMC,YAAYC,WAAW;QAAEC,QAAQhB;MAAM,CAAA,CAAA,CAAA;AAC7G,aAAOO;IACT,CAAA;AAEA,WAAOF,OAAOY,WAAWb,OAAAA;EAC3B,CAAA;AACF;",
6
+ "names": ["Effect", "pipe", "Capabilities", "chain", "contributes", "createIntent", "SpaceAction", "context", "contributes", "Capabilities", "FileUploader", "file", "space", "dispatch", "requestCapability", "IntentDispatcher", "program", "Effect", "gen", "fileInfo", "createIntent", "WnfsAction", "Upload", "pipe", "Create", "chain", "SpaceAction", "AddObject", "target", "runPromise"]
7
+ }
@@ -1,509 +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-W6SFXQTJ.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 { ClientCapabilities, ClientEvents } from "@dxos/plugin-client";
346
24
 
347
- // packages/plugins/experimental/plugin-wnfs/src/translations.ts
25
+ // packages/plugins/plugin-wnfs/src/translations.ts
348
26
  var translations_default = [
349
27
  {
350
28
  "en-US": {
29
+ [FileType.typename]: {
30
+ "typename label": "File"
31
+ },
351
32
  [WNFS_PLUGIN]: {
352
33
  "plugin name": "Files",
353
34
  "file title placeholder": "New file",
354
- "delete object label": "Delete"
35
+ "delete object label": "Delete",
36
+ "file input placeholder": "Drop a file here, or click to select a file"
355
37
  }
356
38
  }
357
39
  }
358
40
  ];
359
41
 
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,
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,
422
67
  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");
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
445
78
  }
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
- ]
79
+ ],
80
+ // TODO(wittjosiah): Would be nice if icon could change based on the type of the file.
81
+ icon: "ph--file--regular"
498
82
  }
499
- }
500
- };
501
- };
502
-
503
- // packages/plugins/experimental/plugin-wnfs/src/index.ts
504
- 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
+ ]);
505
113
  export {
114
+ WNFS_PLUGIN,
115
+ WnfsCapabilities,
506
116
  WnfsPlugin,
507
- src_default as default
117
+ meta
508
118
  };
509
119
  //# sourceMappingURL=index.mjs.map