@dxos/plugin-wnfs 0.8.4-main.9735255 → 0.8.4-main.abd8ff62ef

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 (172) hide show
  1. package/README.md +1 -1
  2. package/dist/lib/browser/chunk-4D4K5JCC.mjs +66 -0
  3. package/dist/lib/browser/chunk-4D4K5JCC.mjs.map +7 -0
  4. package/dist/lib/browser/{chunk-NCTUASHL.mjs → chunk-7KFJ6LYH.mjs} +36 -19
  5. package/dist/lib/browser/chunk-7KFJ6LYH.mjs.map +7 -0
  6. package/dist/lib/browser/chunk-DK62NQ5T.mjs +71 -0
  7. package/dist/lib/browser/chunk-DK62NQ5T.mjs.map +7 -0
  8. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  9. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  10. package/dist/lib/browser/create-QRLX4IMZ.mjs +25 -0
  11. package/dist/lib/browser/create-QRLX4IMZ.mjs.map +7 -0
  12. package/dist/lib/browser/create-file-INAT56PX.mjs +42 -0
  13. package/dist/lib/browser/create-file-INAT56PX.mjs.map +7 -0
  14. package/dist/lib/browser/helpers/index.mjs +26 -0
  15. package/dist/lib/browser/helpers/index.mjs.map +7 -0
  16. package/dist/lib/browser/index.mjs +22 -108
  17. package/dist/lib/browser/index.mjs.map +4 -4
  18. package/dist/lib/browser/meta.json +1 -1
  19. package/dist/lib/browser/operations/index.mjs +14 -0
  20. package/dist/lib/browser/operations/index.mjs.map +7 -0
  21. package/dist/lib/browser/translations.mjs +30 -0
  22. package/dist/lib/browser/translations.mjs.map +7 -0
  23. package/dist/lib/browser/types/index.mjs +4 -5
  24. package/dist/lib/browser/upload-ZQI66T4Y.mjs +35 -0
  25. package/dist/lib/browser/upload-ZQI66T4Y.mjs.map +7 -0
  26. package/dist/types/src/WnfsPlugin.d.ts +1 -0
  27. package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
  28. package/dist/types/src/WnfsPlugin.node.d.ts +4 -0
  29. package/dist/types/src/WnfsPlugin.node.d.ts.map +1 -0
  30. package/dist/types/src/WnfsPlugin.test.d.ts +2 -0
  31. package/dist/types/src/WnfsPlugin.test.d.ts.map +1 -0
  32. package/dist/types/src/blockstore.d.ts.map +1 -1
  33. package/dist/types/src/capabilities/blockstore.d.ts +5 -0
  34. package/dist/types/src/capabilities/blockstore.d.ts.map +1 -0
  35. package/dist/types/src/capabilities/file-uploader.d.ts +6 -0
  36. package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -0
  37. package/dist/types/src/capabilities/index.d.ts +7 -5
  38. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  39. package/dist/types/src/capabilities/markdown.d.ts +6 -0
  40. package/dist/types/src/capabilities/markdown.d.ts.map +1 -0
  41. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  42. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  43. package/dist/types/src/capabilities/react-surface.d.ts +5 -0
  44. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  45. package/dist/types/src/components/FileInput/FileInput.d.ts.map +1 -0
  46. package/dist/types/src/components/FileInput/index.d.ts +2 -0
  47. package/dist/types/src/components/FileInput/index.d.ts.map +1 -0
  48. package/dist/types/src/components/FilePreview/FilePreview.d.ts +12 -0
  49. package/dist/types/src/components/FilePreview/FilePreview.d.ts.map +1 -0
  50. package/dist/types/src/components/FilePreview/index.d.ts +2 -0
  51. package/dist/types/src/components/FilePreview/index.d.ts.map +1 -0
  52. package/dist/types/src/components/index.d.ts +1 -1
  53. package/dist/types/src/components/index.d.ts.map +1 -1
  54. package/dist/types/src/containers/FileContainer/FileContainer.d.ts +7 -0
  55. package/dist/types/src/containers/FileContainer/FileContainer.d.ts.map +1 -0
  56. package/dist/types/src/containers/FileContainer/index.d.ts +2 -0
  57. package/dist/types/src/containers/FileContainer/index.d.ts.map +1 -0
  58. package/dist/types/src/containers/index.d.ts +3 -0
  59. package/dist/types/src/containers/index.d.ts.map +1 -0
  60. package/dist/types/src/extensions/image.d.ts +1 -1
  61. package/dist/types/src/extensions/image.d.ts.map +1 -1
  62. package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
  63. package/dist/types/src/helpers/common.d.ts.map +1 -1
  64. package/dist/types/src/helpers/load.d.ts +1 -1
  65. package/dist/types/src/helpers/load.d.ts.map +1 -1
  66. package/dist/types/src/helpers/upload.d.ts +1 -1
  67. package/dist/types/src/helpers/upload.d.ts.map +1 -1
  68. package/dist/types/src/helpers/wnfs-url.d.ts.map +1 -1
  69. package/dist/types/src/index.d.ts +3 -2
  70. package/dist/types/src/index.d.ts.map +1 -1
  71. package/dist/types/src/operations/create-file.d.ts +5 -0
  72. package/dist/types/src/operations/create-file.d.ts.map +1 -0
  73. package/dist/types/src/operations/create.d.ts +5 -0
  74. package/dist/types/src/operations/create.d.ts.map +1 -0
  75. package/dist/types/src/operations/definitions.d.ts +38 -0
  76. package/dist/types/src/operations/definitions.d.ts.map +1 -0
  77. package/dist/types/src/operations/index.d.ts +4 -0
  78. package/dist/types/src/operations/index.d.ts.map +1 -0
  79. package/dist/types/src/operations/upload.d.ts +5 -0
  80. package/dist/types/src/operations/upload.d.ts.map +1 -0
  81. package/dist/types/src/translations.d.ts +24 -15
  82. package/dist/types/src/translations.d.ts.map +1 -1
  83. package/dist/types/src/types/File.d.ts +1 -1
  84. package/dist/types/src/types/File.d.ts.map +1 -1
  85. package/dist/types/src/types/capabilities.d.ts.map +1 -1
  86. package/dist/types/src/types/types.d.ts +1 -104
  87. package/dist/types/src/types/types.d.ts.map +1 -1
  88. package/dist/types/tsconfig.tsbuildinfo +1 -1
  89. package/package.json +62 -37
  90. package/src/WnfsPlugin.node.ts +47 -0
  91. package/src/WnfsPlugin.test.ts +27 -0
  92. package/src/WnfsPlugin.tsx +40 -39
  93. package/src/blockstore.ts +1 -1
  94. package/src/capabilities/{blockstore/blockstore.ts → blockstore.ts} +4 -3
  95. package/src/capabilities/{file-uploader/file-uploader.ts → file-uploader.ts} +6 -5
  96. package/src/capabilities/index.ts +11 -5
  97. package/src/capabilities/markdown.ts +38 -0
  98. package/src/capabilities/operation-handler.ts +16 -0
  99. package/src/capabilities/react-surface.tsx +60 -0
  100. package/src/components/{FileInput.tsx → FileInput/FileInput.tsx} +5 -5
  101. package/src/components/FileInput/index.ts +5 -0
  102. package/src/components/FilePreview/FilePreview.tsx +43 -0
  103. package/src/components/FilePreview/index.ts +5 -0
  104. package/src/components/index.ts +1 -4
  105. package/src/{components → containers/FileContainer}/FileContainer.tsx +12 -11
  106. package/src/containers/FileContainer/index.ts +5 -0
  107. package/src/containers/index.ts +7 -0
  108. package/src/extensions/image.stories.tsx +9 -10
  109. package/src/extensions/image.tsx +2 -1
  110. package/src/helpers/load.ts +6 -6
  111. package/src/helpers/upload.ts +3 -3
  112. package/src/index.ts +8 -2
  113. package/src/meta.ts +1 -1
  114. package/src/operations/create-file.ts +31 -0
  115. package/src/operations/create.ts +22 -0
  116. package/src/operations/definitions.ts +41 -0
  117. package/src/operations/index.ts +13 -0
  118. package/src/operations/upload.ts +29 -0
  119. package/src/translations.ts +13 -12
  120. package/src/types/File.ts +6 -2
  121. package/src/types/capabilities.ts +3 -3
  122. package/src/types/types.ts +3 -59
  123. package/dist/lib/browser/FileContainer-O5YFSIWV.mjs +0 -91
  124. package/dist/lib/browser/FileContainer-O5YFSIWV.mjs.map +0 -7
  125. package/dist/lib/browser/blockstore-KKFOALUH.mjs +0 -191
  126. package/dist/lib/browser/blockstore-KKFOALUH.mjs.map +0 -7
  127. package/dist/lib/browser/chunk-GXXEH7H6.mjs +0 -154
  128. package/dist/lib/browser/chunk-GXXEH7H6.mjs.map +0 -7
  129. package/dist/lib/browser/chunk-NCTUASHL.mjs.map +0 -7
  130. package/dist/lib/browser/file-uploader-BUHAXRSV.mjs +0 -34
  131. package/dist/lib/browser/file-uploader-BUHAXRSV.mjs.map +0 -7
  132. package/dist/lib/browser/markdown-BRT2MN6C.mjs +0 -201
  133. package/dist/lib/browser/markdown-BRT2MN6C.mjs.map +0 -7
  134. package/dist/lib/browser/operation-resolver-F6GUL54A.mjs +0 -99
  135. package/dist/lib/browser/operation-resolver-F6GUL54A.mjs.map +0 -7
  136. package/dist/lib/browser/react-surface-UNAYSIAC.mjs +0 -81
  137. package/dist/lib/browser/react-surface-UNAYSIAC.mjs.map +0 -7
  138. package/dist/types/src/capabilities/blockstore/blockstore.d.ts +0 -5
  139. package/dist/types/src/capabilities/blockstore/blockstore.d.ts.map +0 -1
  140. package/dist/types/src/capabilities/blockstore/index.d.ts +0 -3
  141. package/dist/types/src/capabilities/blockstore/index.d.ts.map +0 -1
  142. package/dist/types/src/capabilities/file-uploader/file-uploader.d.ts +0 -5
  143. package/dist/types/src/capabilities/file-uploader/file-uploader.d.ts.map +0 -1
  144. package/dist/types/src/capabilities/file-uploader/index.d.ts +0 -3
  145. package/dist/types/src/capabilities/file-uploader/index.d.ts.map +0 -1
  146. package/dist/types/src/capabilities/markdown/index.d.ts +0 -3
  147. package/dist/types/src/capabilities/markdown/index.d.ts.map +0 -1
  148. package/dist/types/src/capabilities/markdown/markdown.d.ts +0 -5
  149. package/dist/types/src/capabilities/markdown/markdown.d.ts.map +0 -1
  150. package/dist/types/src/capabilities/operation-resolver/index.d.ts +0 -3
  151. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +0 -1
  152. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +0 -5
  153. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +0 -1
  154. package/dist/types/src/capabilities/react-surface/index.d.ts +0 -3
  155. package/dist/types/src/capabilities/react-surface/index.d.ts.map +0 -1
  156. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +0 -5
  157. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +0 -1
  158. package/dist/types/src/components/FileContainer.d.ts +0 -7
  159. package/dist/types/src/components/FileContainer.d.ts.map +0 -1
  160. package/dist/types/src/components/FileInput.d.ts.map +0 -1
  161. package/dist/types/src/components/FilePreview.d.ts +0 -11
  162. package/dist/types/src/components/FilePreview.d.ts.map +0 -1
  163. package/src/capabilities/blockstore/index.ts +0 -7
  164. package/src/capabilities/file-uploader/index.ts +0 -7
  165. package/src/capabilities/markdown/index.ts +0 -7
  166. package/src/capabilities/markdown/markdown.ts +0 -33
  167. package/src/capabilities/operation-resolver/index.ts +0 -7
  168. package/src/capabilities/operation-resolver/operation-resolver.ts +0 -62
  169. package/src/capabilities/react-surface/index.ts +0 -7
  170. package/src/capabilities/react-surface/react-surface.tsx +0 -49
  171. package/src/components/FilePreview.tsx +0 -23
  172. /package/dist/types/src/components/{FileInput.d.ts → FileInput/FileInput.d.ts} +0 -0
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export { FileContainer as default } from './FileContainer';
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type ComponentType, lazy } from 'react';
6
+
7
+ export const FileContainer: ComponentType<any> = lazy(() => import('./FileContainer'));
@@ -6,12 +6,12 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
6
6
  import type { Blockstore } from 'interface-blockstore';
7
7
  import React, { type ChangeEvent, useEffect, useState } from 'react';
8
8
 
9
- import { faker } from '@dxos/random';
10
- import { useSpace } from '@dxos/react-client/echo';
9
+ import { random } from '@dxos/random';
10
+ import { useSpaces } from '@dxos/react-client/echo';
11
11
  import { withClientProvider } from '@dxos/react-client/testing';
12
12
  import { useThemeContext } from '@dxos/react-ui';
13
- import { withTheme } from '@dxos/react-ui/testing';
14
13
  import { useTextEditor } from '@dxos/react-ui-editor';
14
+ import { withTheme } from '@dxos/react-ui/testing';
15
15
  import {
16
16
  createBasicExtensions,
17
17
  createMarkdownExtensions,
@@ -22,16 +22,15 @@ import {
22
22
 
23
23
  import { create as createBlockstore } from '../blockstore';
24
24
  import { upload } from '../helpers';
25
-
26
25
  import { image } from './image';
27
26
 
28
- faker.seed(1);
29
- const initialValue = faker.lorem.paragraphs(100);
27
+ random.seed(1);
28
+ const initialValue = random.lorem.paragraphs(100);
30
29
  const instances = {};
31
30
 
32
31
  const DefaultStory = () => {
33
32
  const { themeMode } = useThemeContext();
34
- const space = useSpace();
33
+ const [space] = useSpaces();
35
34
  const [blockstore, setBlockstore] = useState<Blockstore>();
36
35
 
37
36
  useEffect(() => {
@@ -86,15 +85,15 @@ const DefaultStory = () => {
86
85
  <div className='mb-2'>
87
86
  <input type='file' accept='image/*' onChange={onFileChange} />
88
87
  </div>
89
- <div className='is-[50rem]' ref={parentRef} {...focusAttributes} />
88
+ <div className='w-[50rem]' ref={parentRef} {...focusAttributes} />
90
89
  </>
91
90
  );
92
91
  };
93
92
 
94
93
  const meta = {
95
- title: 'plugins/plugin-wnfs/image',
94
+ title: 'plugins/plugin-wnfs/extensions/image',
96
95
  render: DefaultStory,
97
- decorators: [withTheme, withClientProvider({ createIdentity: true, createSpace: true })],
96
+ decorators: [withTheme(), withClientProvider({ createIdentity: true, createSpace: true })],
98
97
  } satisfies Meta<typeof DefaultStory>;
99
98
 
100
99
  export default meta;
@@ -15,8 +15,9 @@ import { focusField } from '@dxos/ui-editor';
15
15
  import { defaultTx } from '@dxos/ui-theme';
16
16
  import { type MaybePromise } from '@dxos/util';
17
17
 
18
+ import { type WnfsCapabilities } from '#types';
19
+
18
20
  import { getBlobUrl, getPathFromUrl, loadWnfs } from '../helpers';
19
- import { type WnfsCapabilities } from '../types';
20
21
 
21
22
  const WAIT_UNTIL_LOADER = 1500;
22
23
 
@@ -10,7 +10,7 @@ import { AccessKey, PrivateDirectory, PrivateForest, PrivateNode } from 'wnfs';
10
10
  import { Obj } from '@dxos/echo';
11
11
  import { type Space } from '@dxos/react-client/echo';
12
12
 
13
- import { type WnfsCapabilities } from '../types';
13
+ import { type WnfsCapabilities } from '#types';
14
14
 
15
15
  import { Rng, store } from './common';
16
16
 
@@ -30,9 +30,9 @@ export const loadWnfs = async ({
30
30
  // TODO(wittjosiah): Remove.
31
31
  // Delete old properties if they exist.
32
32
  if (space.properties.wnfs_access_key !== undefined && space.properties.wnfs_private_forest_cid !== undefined) {
33
- Obj.change(space.properties, (p) => {
34
- delete p['wnfs_access_key'];
35
- delete p['wnfs_private_forest_cid'];
33
+ Obj.update(space.properties, (obj) => {
34
+ delete obj['wnfs_access_key'];
35
+ delete obj['wnfs_private_forest_cid'];
36
36
  });
37
37
  }
38
38
 
@@ -68,8 +68,8 @@ const createWnfsDir = async (blockstore: Blockstore, space: Space) => {
68
68
 
69
69
  const cidBytes = await newForest.store(wnfsStore);
70
70
 
71
- Obj.change(space.properties, (p) => {
72
- p.wnfs = {
71
+ Obj.update(space.properties, (obj) => {
72
+ obj.wnfs = {
73
73
  accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), 'base64'),
74
74
  privateForestCid: CID.decode(cidBytes).toString(),
75
75
  };
@@ -11,7 +11,7 @@ import type { Space } from '@dxos/client/echo';
11
11
  import { Obj } from '@dxos/echo';
12
12
  import { log } from '@dxos/log';
13
13
 
14
- import { type WnfsCapabilities } from '../types';
14
+ import { type WnfsCapabilities } from '#types';
15
15
 
16
16
  import { Rng, filePath, store } from './common';
17
17
  import { loadWnfs } from './load';
@@ -47,8 +47,8 @@ export const upload = async ({
47
47
  const cidBytes = await updatedForest.store(wnfsStore);
48
48
 
49
49
  // Update the forest pointer on the associated space.
50
- Obj.change(space.properties, (p) => {
51
- p.wnfs.privateForestCid = CID.decode(cidBytes).toString();
50
+ Obj.update(space.properties, (obj) => {
51
+ obj.wnfs.privateForestCid = CID.decode(cidBytes).toString();
52
52
  });
53
53
 
54
54
  // Generate `wnfs://` URL & return the info.
package/src/index.ts CHANGED
@@ -2,6 +2,12 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export { WnfsCapabilities } from './types';
5
+ import { Plugin } from '@dxos/app-framework';
6
+
7
+ import { meta } from './meta';
8
+
9
+ export const WnfsPlugin = Plugin.lazy(meta, () => import('#plugin'));
10
+
6
11
  export * from './meta';
7
- export * from './WnfsPlugin';
12
+
13
+ export { WnfsCapabilities } from './types';
package/src/meta.ts CHANGED
@@ -6,7 +6,7 @@ import { type Plugin } from '@dxos/app-framework';
6
6
  import { trim } from '@dxos/util';
7
7
 
8
8
  export const meta: Plugin.Meta = {
9
- id: 'dxos.org/plugin/wnfs',
9
+ id: 'org.dxos.plugin.wnfs',
10
10
  name: 'WNFS',
11
11
  description: trim`
12
12
  Decentralized file storage using the Web Native File System protocol.
@@ -0,0 +1,31 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+
7
+ import { Capability } from '@dxos/app-framework';
8
+ import { Operation } from '@dxos/compute';
9
+ import { invariant } from '@dxos/invariant';
10
+ import { ClientCapabilities } from '@dxos/plugin-client/types';
11
+
12
+ import { upload } from '../helpers';
13
+ import { WnfsCapabilities, WnfsFile } from '../types';
14
+ import { CreateFile } from './definitions';
15
+
16
+ const handler: Operation.WithHandler<typeof CreateFile> = CreateFile.pipe(
17
+ Operation.withHandler(
18
+ Effect.fnUntraced(function* ({ file, db }) {
19
+ const client = yield* Capability.get(ClientCapabilities.Client);
20
+ const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
21
+ const space = client.spaces.get(db.spaceId);
22
+ invariant(space, 'Space not found');
23
+ const info = yield* Effect.promise(() => upload({ file, blockstore, space }));
24
+ return {
25
+ object: WnfsFile.make({ name: info.name, type: info.type, cid: info.cid }),
26
+ };
27
+ }),
28
+ ),
29
+ );
30
+
31
+ export default handler;
@@ -0,0 +1,22 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+
7
+ import { Operation } from '@dxos/compute';
8
+
9
+ import { WnfsFile } from '../types';
10
+ import { Create } from './definitions';
11
+
12
+ const handler: Operation.WithHandler<typeof Create> = Create.pipe(
13
+ Operation.withHandler(
14
+ Effect.fnUntraced(function* ({ name, type, cid }) {
15
+ return {
16
+ object: WnfsFile.make({ name, type, cid }),
17
+ };
18
+ }),
19
+ ),
20
+ );
21
+
22
+ export default handler;
@@ -0,0 +1,41 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { Capability } from '@dxos/app-framework';
8
+ import { FileInfoSchema } from '@dxos/app-toolkit';
9
+ import { Operation } from '@dxos/compute';
10
+ import { Database } from '@dxos/echo';
11
+
12
+ import { meta } from '#meta';
13
+
14
+ import { WnfsFile, WnfsAction } from '../types';
15
+
16
+ const WNFS_OPERATION = `${meta.id}.operation`;
17
+
18
+ export const Create = Operation.make({
19
+ meta: { key: `${WNFS_OPERATION}.create`, name: 'Create WNFS File' },
20
+ services: [Capability.Service],
21
+ input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
22
+ output: Schema.Struct({
23
+ object: WnfsFile.File,
24
+ }),
25
+ });
26
+
27
+ export const Upload = Operation.make({
28
+ meta: { key: `${WNFS_OPERATION}.upload`, name: 'Upload File' },
29
+ services: [Capability.Service],
30
+ input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),
31
+ output: Schema.required(FileInfoSchema),
32
+ });
33
+
34
+ export const CreateFile = Operation.make({
35
+ meta: { key: `${WNFS_OPERATION}.create-file`, name: 'Create File' },
36
+ services: [Capability.Service],
37
+ input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),
38
+ output: Schema.Struct({
39
+ object: WnfsFile.File,
40
+ }),
41
+ });
@@ -0,0 +1,13 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { OperationHandlerSet } from '@dxos/compute';
6
+
7
+ export * as WnfsOperation from './definitions';
8
+
9
+ export const WnfsOperationHandlerSet = OperationHandlerSet.lazy(
10
+ () => import('./create'),
11
+ () => import('./create-file'),
12
+ () => import('./upload'),
13
+ );
@@ -0,0 +1,29 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+
7
+ import { Capability } from '@dxos/app-framework';
8
+ import { Operation } from '@dxos/compute';
9
+ import { invariant } from '@dxos/invariant';
10
+ import { ClientCapabilities } from '@dxos/plugin-client/types';
11
+
12
+ import { upload } from '../helpers';
13
+ import { WnfsCapabilities } from '../types';
14
+ import { Upload } from './definitions';
15
+
16
+ const handler: Operation.WithHandler<typeof Upload> = Upload.pipe(
17
+ Operation.withHandler(
18
+ Effect.fnUntraced(function* ({ file, db }) {
19
+ const client = yield* Capability.get(ClientCapabilities.Client);
20
+ const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
21
+ const space = client.spaces.get(db.spaceId);
22
+ invariant(space, 'Space not found');
23
+ const info = yield* Effect.promise(() => upload({ file, blockstore, space }));
24
+ return info;
25
+ }),
26
+ ),
27
+ );
28
+
29
+ export default handler;
@@ -4,25 +4,26 @@
4
4
 
5
5
  import { type Resource } from '@dxos/react-ui';
6
6
 
7
- import { meta } from './meta';
8
- import { WnfsFile } from './types';
7
+ import { meta } from '#meta';
8
+ import { WnfsFile } from '#types';
9
9
 
10
10
  export const translations = [
11
11
  {
12
12
  'en-US': {
13
13
  [WnfsFile.File.typename]: {
14
- 'typename label': 'File',
15
- 'typename label_zero': 'Files',
16
- 'typename label_one': 'File',
17
- 'typename label_other': 'Files',
18
- 'object name placeholder': 'New file',
19
- 'rename object label': 'Rename file',
20
- 'delete object label': 'Delete file',
21
- 'object deleted label': 'File deleted',
14
+ 'typename.label': 'File',
15
+ 'typename.label_zero': 'Files',
16
+ 'typename.label_one': 'File',
17
+ 'typename.label_other': 'Files',
18
+ 'object-name.placeholder': 'New file',
19
+ 'add-object.label': 'Add file',
20
+ 'rename-object.label': 'Rename file',
21
+ 'delete-object.label': 'Delete file',
22
+ 'object-deleted.label': 'File deleted',
22
23
  },
23
24
  [meta.id]: {
24
- 'plugin name': 'Files',
25
- 'file input placeholder': 'Drop a file here, or click to select a file',
25
+ 'plugin.name': 'Files',
26
+ 'file-input.placeholder': 'Drop a file here, or click to select a file',
26
27
  },
27
28
  },
28
29
  },
package/src/types/File.ts CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { Obj, Type } from '@dxos/echo';
7
+ import { Annotation, Obj, Type } from '@dxos/echo';
8
8
  import { FormInputAnnotation } from '@dxos/echo/internal';
9
9
 
10
10
  export const File = Schema.Struct({
@@ -14,9 +14,13 @@ export const File = Schema.Struct({
14
14
  timestamp: Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional),
15
15
  }).pipe(
16
16
  Type.object({
17
- typename: 'dxos.org/type/File',
17
+ typename: 'org.dxos.type.file',
18
18
  version: '0.1.0',
19
19
  }),
20
+ Annotation.IconAnnotation.set({
21
+ icon: 'ph--file--regular',
22
+ hue: 'teal',
23
+ }),
20
24
  );
21
25
 
22
26
  export type File = Schema.Schema.Type<typeof File>;
@@ -8,11 +8,11 @@ import { type PrivateDirectory, type PrivateForest } from 'wnfs';
8
8
  import { Capability } from '@dxos/app-framework';
9
9
  import { type SpaceId } from '@dxos/keys';
10
10
 
11
- import { meta } from '../meta';
11
+ import { meta } from '#meta';
12
12
 
13
13
  export namespace WnfsCapabilities {
14
- export const Blockstore = Capability.make<Blockstore>(`${meta.id}/capability/blockstore`);
14
+ export const Blockstore = Capability.make<Blockstore>(`${meta.id}.capability.blockstore`);
15
15
 
16
16
  export type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;
17
- export const Instances = Capability.make<Instances>(`${meta.id}/capability/instances`);
17
+ export const Instances = Capability.make<Instances>(`${meta.id}.capability.instances`);
18
18
  }
@@ -4,21 +4,13 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { Capability, Common } from '@dxos/app-framework';
8
- import { Database } from '@dxos/echo';
9
- import { Operation } from '@dxos/operation';
10
- import { SpaceSchema } from '@dxos/react-client/echo';
11
- import { Collection } from '@dxos/schema';
12
-
13
- import { meta } from '../meta';
14
-
15
- import * as File from './File';
7
+ import { meta } from '#meta';
16
8
 
17
9
  export namespace WnfsAction {
18
- export const UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);
10
+ export const UploadAnnotationId = Symbol.for(`${meta.id}.annotation.upload`);
19
11
 
20
12
  export const UploadFileSchema = Schema.Struct({
21
- file: Schema.instanceOf(File.File).annotations({
13
+ file: Schema.instanceOf(File).annotations({
22
14
  [UploadAnnotationId]: {
23
15
  // Accept file types.
24
16
  'image/*': ['.jpg', '.jpeg', '.png', '.gif'],
@@ -30,51 +22,3 @@ export namespace WnfsAction {
30
22
 
31
23
  export type UploadFileForm = Schema.Schema.Type<typeof UploadFileSchema>;
32
24
  }
33
-
34
- const WNFS_OPERATION = `${meta.id}/operation`;
35
-
36
- export namespace WnfsOperation {
37
- export const OnCreateSpace = Operation.make({
38
- meta: { key: `${WNFS_OPERATION}/on-create-space`, name: 'On Create Space' },
39
- services: [Capability.Service],
40
- schema: {
41
- input: Schema.Struct({
42
- space: SpaceSchema,
43
- rootCollection: Collection.Collection,
44
- isDefault: Schema.optional(Schema.Boolean),
45
- }),
46
- output: Schema.Void,
47
- },
48
- });
49
-
50
- export const Create = Operation.make({
51
- meta: { key: `${WNFS_OPERATION}/create`, name: 'Create WNFS File' },
52
- services: [Capability.Service],
53
- schema: {
54
- input: Common.FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
55
- output: Schema.Struct({
56
- object: File.File,
57
- }),
58
- },
59
- });
60
-
61
- export const Upload = Operation.make({
62
- meta: { key: `${WNFS_OPERATION}/upload`, name: 'Upload File' },
63
- services: [Capability.Service],
64
- schema: {
65
- input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),
66
- output: Schema.required(Common.FileInfoSchema),
67
- },
68
- });
69
-
70
- export const CreateFile = Operation.make({
71
- meta: { key: `${WNFS_OPERATION}/create-file`, name: 'Create File' },
72
- services: [Capability.Service],
73
- schema: {
74
- input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),
75
- output: Schema.Struct({
76
- object: File.File,
77
- }),
78
- },
79
- });
80
- }
@@ -1,91 +0,0 @@
1
- import {
2
- filePath,
3
- getBlobUrl,
4
- loadWnfs,
5
- wnfsUrl
6
- } from "./chunk-NCTUASHL.mjs";
7
- import {
8
- WnfsCapabilities
9
- } from "./chunk-GXXEH7H6.mjs";
10
-
11
- // src/components/FileContainer.tsx
12
- import React2, { useState } from "react";
13
- import { useCapability } from "@dxos/app-framework/react";
14
- import { invariant } from "@dxos/invariant";
15
- import { getSpace } from "@dxos/react-client/echo";
16
- import { useAsyncEffect } from "@dxos/react-ui";
17
- import { Layout } from "@dxos/react-ui-mosaic";
18
-
19
- // src/components/FilePreview.tsx
20
- import React from "react";
21
- import { mx } from "@dxos/ui-theme";
22
- var FilePreview = ({ type, url, classNames }) => {
23
- if (type.startsWith("image/")) {
24
- return /* @__PURE__ */ React.createElement("img", {
25
- className: mx("is-full bs-full object-contain", classNames),
26
- src: url
27
- });
28
- } else if (type.startsWith("video/")) {
29
- return /* @__PURE__ */ React.createElement("video", {
30
- className: mx("is-full bs-full object-contain", classNames),
31
- src: url,
32
- controls: true
33
- });
34
- } else {
35
- return /* @__PURE__ */ React.createElement("iframe", {
36
- className: mx("is-full bs-full overflow-auto", classNames),
37
- src: url
38
- });
39
- }
40
- };
41
-
42
- // src/components/FileContainer.tsx
43
- var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/components/FileContainer.tsx";
44
- var FileContainer = ({ role, subject: file }) => {
45
- const blockstore = useCapability(WnfsCapabilities.Blockstore);
46
- const instances = useCapability(WnfsCapabilities.Instances);
47
- const [blobUrl, setBlobUrl] = useState();
48
- useAsyncEffect(async () => {
49
- const space = getSpace(file);
50
- invariant(space, void 0, {
51
- F: __dxlog_file,
52
- L: 28,
53
- S: void 0,
54
- A: [
55
- "space",
56
- ""
57
- ]
58
- });
59
- const { directory, forest } = await loadWnfs({
60
- blockstore,
61
- instances,
62
- space
63
- });
64
- const path = filePath(file.cid.toString(), space);
65
- const url = await getBlobUrl({
66
- wnfsUrl: wnfsUrl(path),
67
- blockstore,
68
- directory,
69
- forest,
70
- type: file.type
71
- });
72
- setBlobUrl(url);
73
- }, [
74
- file
75
- ]);
76
- if (!blobUrl) {
77
- return null;
78
- }
79
- return /* @__PURE__ */ React2.createElement(Layout.Main, {
80
- role
81
- }, /* @__PURE__ */ React2.createElement(FilePreview, {
82
- type: file.type,
83
- url: blobUrl
84
- }));
85
- };
86
- var FileContainer_default = FileContainer;
87
- export {
88
- FileContainer,
89
- FileContainer_default as default
90
- };
91
- //# sourceMappingURL=FileContainer-O5YFSIWV.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/FileContainer.tsx", "../../../src/components/FilePreview.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { useState } from 'react';\n\nimport { type SurfaceComponentProps, useCapability } from '@dxos/app-framework/react';\nimport { invariant } from '@dxos/invariant';\nimport { getSpace } from '@dxos/react-client/echo';\nimport { useAsyncEffect } from '@dxos/react-ui';\nimport { Layout } from '@dxos/react-ui-mosaic';\n\nimport { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../helpers';\nimport { WnfsCapabilities } from '../types';\nimport { type WnfsFile } from '../types';\n\nimport { FilePreview } from './FilePreview';\n\nexport type FileContainerProps = SurfaceComponentProps<WnfsFile.File>;\n\nexport const FileContainer = ({ role, subject: file }: FileContainerProps) => {\n const blockstore = useCapability(WnfsCapabilities.Blockstore);\n const instances = useCapability(WnfsCapabilities.Instances);\n const [blobUrl, setBlobUrl] = useState<string>();\n\n useAsyncEffect(async () => {\n const space = getSpace(file);\n invariant(space);\n const { directory, forest } = await loadWnfs({\n blockstore,\n instances,\n space,\n });\n const path = filePath(file.cid.toString(), space);\n const url = await getBlobUrl({\n wnfsUrl: wnfsUrl(path),\n blockstore,\n directory,\n forest,\n type: file.type,\n });\n setBlobUrl(url);\n }, [file]);\n\n if (!blobUrl) {\n return null;\n }\n\n return (\n <Layout.Main role={role}>\n <FilePreview type={file.type} url={blobUrl} />\n </Layout.Main>\n );\n};\n\nexport default FileContainer;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/ui-theme';\n\nexport type FilePreviewProps = ThemedClassName<{ type: string; url: string }>;\n\n/**\n * File/content preview iframe.\n */\nexport const FilePreview = ({ type, url, classNames }: FilePreviewProps) => {\n if (type.startsWith('image/')) {\n return <img className={mx('is-full bs-full object-contain', classNames)} src={url} />;\n } else if (type.startsWith('video/')) {\n return <video className={mx('is-full bs-full object-contain', classNames)} src={url} controls />;\n } else {\n return <iframe className={mx('is-full bs-full overflow-auto', classNames)} src={url} />;\n }\n};\n"],
5
- "mappings": ";;;;;;;;;;;AAIA,OAAOA,UAASC,gBAAgB;AAEhC,SAAqCC,qBAAqB;AAC1D,SAASC,iBAAiB;AAC1B,SAASC,gBAAgB;AACzB,SAASC,sBAAsB;AAC/B,SAASC,cAAc;;;ACNvB,OAAOC,WAAW;AAGlB,SAASC,UAAU;AAOZ,IAAMC,cAAc,CAAC,EAAEC,MAAMC,KAAKC,WAAU,MAAoB;AACrE,MAAIF,KAAKG,WAAW,QAAA,GAAW;AAC7B,WAAO,sBAAA,cAACC,OAAAA;MAAIC,WAAWC,GAAG,kCAAkCJ,UAAAA;MAAaK,KAAKN;;EAChF,WAAWD,KAAKG,WAAW,QAAA,GAAW;AACpC,WAAO,sBAAA,cAACK,SAAAA;MAAMH,WAAWC,GAAG,kCAAkCJ,UAAAA;MAAaK,KAAKN;MAAKQ,UAAAA;;EACvF,OAAO;AACL,WAAO,sBAAA,cAACC,UAAAA;MAAOL,WAAWC,GAAG,iCAAiCJ,UAAAA;MAAaK,KAAKN;;EAClF;AACF;;;;ADFO,IAAMU,gBAAgB,CAAC,EAAEC,MAAMC,SAASC,KAAI,MAAsB;AACvE,QAAMC,aAAaC,cAAcC,iBAAiBC,UAAU;AAC5D,QAAMC,YAAYH,cAAcC,iBAAiBG,SAAS;AAC1D,QAAM,CAACC,SAASC,UAAAA,IAAcC,SAAAA;AAE9BC,iBAAe,YAAA;AACb,UAAMC,QAAQC,SAASZ,IAAAA;AACvBa,cAAUF,OAAAA,QAAAA;;;;;;;;;AACV,UAAM,EAAEG,WAAWC,OAAM,IAAK,MAAMC,SAAS;MAC3Cf;MACAI;MACAM;IACF,CAAA;AACA,UAAMM,OAAOC,SAASlB,KAAKmB,IAAIC,SAAQ,GAAIT,KAAAA;AAC3C,UAAMU,MAAM,MAAMC,WAAW;MAC3BC,SAASA,QAAQN,IAAAA;MACjBhB;MACAa;MACAC;MACAS,MAAMxB,KAAKwB;IACb,CAAA;AACAhB,eAAWa,GAAAA;EACb,GAAG;IAACrB;GAAK;AAET,MAAI,CAACO,SAAS;AACZ,WAAO;EACT;AAEA,SACE,gBAAAkB,OAAA,cAACC,OAAOC,MAAI;IAAC7B;KACX,gBAAA2B,OAAA,cAACG,aAAAA;IAAYJ,MAAMxB,KAAKwB;IAAMH,KAAKd;;AAGzC;AAEA,IAAA,wBAAeV;",
6
- "names": ["React", "useState", "useCapability", "invariant", "getSpace", "useAsyncEffect", "Layout", "React", "mx", "FilePreview", "type", "url", "classNames", "startsWith", "img", "className", "mx", "src", "video", "controls", "iframe", "FileContainer", "role", "subject", "file", "blockstore", "useCapability", "WnfsCapabilities", "Blockstore", "instances", "Instances", "blobUrl", "setBlobUrl", "useState", "useAsyncEffect", "space", "getSpace", "invariant", "directory", "forest", "loadWnfs", "path", "filePath", "cid", "toString", "url", "getBlobUrl", "wnfsUrl", "type", "React", "Layout", "Main", "FilePreview"]
7
- }