@dxos/plugin-wnfs 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc

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 (210) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +2 -2
  3. package/dist/lib/neutral/FileArticle-B3NF2VKL.mjs +58 -0
  4. package/dist/lib/neutral/FileArticle-B3NF2VKL.mjs.map +7 -0
  5. package/dist/lib/neutral/WnfsPlugin.mjs +50 -0
  6. package/dist/lib/neutral/WnfsPlugin.mjs.map +7 -0
  7. package/dist/lib/neutral/WnfsPlugin.node.mjs +23 -0
  8. package/dist/lib/neutral/WnfsPlugin.node.mjs.map +7 -0
  9. package/dist/lib/neutral/WnfsPlugin.workerd.mjs +21 -0
  10. package/dist/lib/neutral/WnfsPlugin.workerd.mjs.map +7 -0
  11. package/dist/lib/{browser/blockstore-2JFU4NBU.mjs → neutral/blockstore-3NLSWC7Z.mjs} +12 -13
  12. package/dist/lib/neutral/blockstore-3NLSWC7Z.mjs.map +7 -0
  13. package/dist/lib/neutral/capabilities/index.mjs +19 -0
  14. package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
  15. package/dist/lib/{browser/chunk-D6VTEQIE.mjs → neutral/chunk-7KFJ6LYH.mjs} +43 -18
  16. package/dist/lib/neutral/chunk-7KFJ6LYH.mjs.map +7 -0
  17. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  18. package/dist/lib/{browser/chunk-OGPGLJCV.mjs → neutral/chunk-LHUHUCBD.mjs} +2 -9
  19. package/dist/lib/neutral/chunk-LHUHUCBD.mjs.map +7 -0
  20. package/dist/lib/neutral/chunk-UIZBWELF.mjs +8 -0
  21. package/dist/lib/neutral/chunk-UIZBWELF.mjs.map +7 -0
  22. package/dist/lib/neutral/chunk-VWVCHTUK.mjs +125 -0
  23. package/dist/lib/neutral/chunk-VWVCHTUK.mjs.map +7 -0
  24. package/dist/lib/neutral/components/index.mjs +63 -0
  25. package/dist/lib/neutral/components/index.mjs.map +7 -0
  26. package/dist/lib/neutral/containers/index.mjs +9 -0
  27. package/dist/lib/neutral/containers/index.mjs.map +7 -0
  28. package/dist/lib/neutral/create-4ERE5CA4.mjs +23 -0
  29. package/dist/lib/neutral/create-4ERE5CA4.mjs.map +7 -0
  30. package/dist/lib/neutral/create-file-RAHDIJVU.mjs +40 -0
  31. package/dist/lib/neutral/create-file-RAHDIJVU.mjs.map +7 -0
  32. package/dist/lib/neutral/create-object-7PJC47BB.mjs +33 -0
  33. package/dist/lib/neutral/create-object-7PJC47BB.mjs.map +7 -0
  34. package/dist/lib/neutral/file-uploader-WOF3H3FN.mjs +34 -0
  35. package/dist/lib/neutral/file-uploader-WOF3H3FN.mjs.map +7 -0
  36. package/dist/lib/neutral/helpers/index.mjs +26 -0
  37. package/dist/lib/neutral/helpers/index.mjs.map +7 -0
  38. package/dist/lib/neutral/index.mjs +40 -0
  39. package/dist/lib/neutral/index.mjs.map +7 -0
  40. package/dist/lib/{browser/markdown-3ZLVJIGT.mjs → neutral/markdown-I4FYAUCA.mjs} +23 -17
  41. package/dist/lib/neutral/markdown-I4FYAUCA.mjs.map +7 -0
  42. package/dist/lib/neutral/meta.json +1 -0
  43. package/dist/lib/neutral/meta.mjs +8 -0
  44. package/dist/lib/neutral/meta.mjs.map +7 -0
  45. package/dist/lib/neutral/operation-handler-NPYSIPMR.mjs +13 -0
  46. package/dist/lib/neutral/operation-handler-NPYSIPMR.mjs.map +7 -0
  47. package/dist/lib/neutral/operations/index.mjs +8 -0
  48. package/dist/lib/neutral/operations/index.mjs.map +7 -0
  49. package/dist/lib/neutral/plugin.mjs +16 -0
  50. package/dist/lib/neutral/plugin.mjs.map +7 -0
  51. package/dist/lib/neutral/react-surface-6QHCDYC3.mjs +53 -0
  52. package/dist/lib/neutral/react-surface-6QHCDYC3.mjs.map +7 -0
  53. package/dist/lib/neutral/translations.mjs +30 -0
  54. package/dist/lib/neutral/translations.mjs.map +7 -0
  55. package/dist/lib/neutral/types/index.mjs +14 -0
  56. package/dist/lib/neutral/types/index.mjs.map +7 -0
  57. package/dist/lib/neutral/upload-VA5CSUEP.mjs +33 -0
  58. package/dist/lib/neutral/upload-VA5CSUEP.mjs.map +7 -0
  59. package/dist/types/src/WnfsPlugin.d.ts +3 -1
  60. package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
  61. package/dist/types/src/WnfsPlugin.node.d.ts +4 -0
  62. package/dist/types/src/WnfsPlugin.node.d.ts.map +1 -0
  63. package/dist/types/src/WnfsPlugin.test.d.ts +2 -0
  64. package/dist/types/src/WnfsPlugin.test.d.ts.map +1 -0
  65. package/dist/types/src/WnfsPlugin.workerd.d.ts +4 -0
  66. package/dist/types/src/WnfsPlugin.workerd.d.ts.map +1 -0
  67. package/dist/types/src/blockstore.d.ts.map +1 -1
  68. package/dist/types/src/capabilities/blockstore.d.ts +3 -2
  69. package/dist/types/src/capabilities/blockstore.d.ts.map +1 -1
  70. package/dist/types/src/capabilities/create-object.d.ts +11 -0
  71. package/dist/types/src/capabilities/create-object.d.ts.map +1 -0
  72. package/dist/types/src/capabilities/file-uploader.d.ts +4 -2
  73. package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -1
  74. package/dist/types/src/capabilities/index.d.ts +13 -6
  75. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  76. package/dist/types/src/capabilities/markdown.d.ts +4 -2
  77. package/dist/types/src/capabilities/markdown.d.ts.map +1 -1
  78. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  79. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  80. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  81. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  82. package/dist/types/src/components/FileInput/FileInput.d.ts.map +1 -0
  83. package/dist/types/src/components/FileInput/index.d.ts +2 -0
  84. package/dist/types/src/components/FileInput/index.d.ts.map +1 -0
  85. package/dist/types/src/components/FilePreview/FilePreview.d.ts +12 -0
  86. package/dist/types/src/components/FilePreview/FilePreview.d.ts.map +1 -0
  87. package/dist/types/src/components/FilePreview/index.d.ts +2 -0
  88. package/dist/types/src/components/FilePreview/index.d.ts.map +1 -0
  89. package/dist/types/src/components/index.d.ts +1 -1
  90. package/dist/types/src/components/index.d.ts.map +1 -1
  91. package/dist/types/src/containers/FileArticle/FileArticle.d.ts +7 -0
  92. package/dist/types/src/containers/FileArticle/FileArticle.d.ts.map +1 -0
  93. package/dist/types/src/containers/FileArticle/index.d.ts +2 -0
  94. package/dist/types/src/containers/FileArticle/index.d.ts.map +1 -0
  95. package/dist/types/src/containers/index.d.ts +3 -0
  96. package/dist/types/src/containers/index.d.ts.map +1 -0
  97. package/dist/types/src/extensions/image.d.ts +1 -1
  98. package/dist/types/src/extensions/image.d.ts.map +1 -1
  99. package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
  100. package/dist/types/src/helpers/common.d.ts.map +1 -1
  101. package/dist/types/src/helpers/load.d.ts +1 -1
  102. package/dist/types/src/helpers/load.d.ts.map +1 -1
  103. package/dist/types/src/helpers/upload.d.ts +1 -1
  104. package/dist/types/src/helpers/upload.d.ts.map +1 -1
  105. package/dist/types/src/helpers/wnfs-url.d.ts.map +1 -1
  106. package/dist/types/src/index.d.ts +2 -2
  107. package/dist/types/src/index.d.ts.map +1 -1
  108. package/dist/types/src/meta.d.ts +2 -2
  109. package/dist/types/src/meta.d.ts.map +1 -1
  110. package/dist/types/src/operations/create-file.d.ts +5 -0
  111. package/dist/types/src/operations/create-file.d.ts.map +1 -0
  112. package/dist/types/src/operations/create.d.ts +5 -0
  113. package/dist/types/src/operations/create.d.ts.map +1 -0
  114. package/dist/types/src/operations/index.d.ts +3 -0
  115. package/dist/types/src/operations/index.d.ts.map +1 -0
  116. package/dist/types/src/operations/upload.d.ts +5 -0
  117. package/dist/types/src/operations/upload.d.ts.map +1 -0
  118. package/dist/types/src/plugin.d.ts +4 -0
  119. package/dist/types/src/plugin.d.ts.map +1 -0
  120. package/dist/types/src/translations.d.ts +24 -12
  121. package/dist/types/src/translations.d.ts.map +1 -1
  122. package/dist/types/src/types/WnfsCapabilities.d.ts +11 -0
  123. package/dist/types/src/types/WnfsCapabilities.d.ts.map +1 -0
  124. package/dist/types/src/types/WnfsFile.d.ts +16 -0
  125. package/dist/types/src/types/WnfsFile.d.ts.map +1 -0
  126. package/dist/types/src/types/WnfsOperation.d.ts +38 -0
  127. package/dist/types/src/types/WnfsOperation.d.ts.map +1 -0
  128. package/dist/types/src/types/index.d.ts +3 -1
  129. package/dist/types/src/types/index.d.ts.map +1 -1
  130. package/dist/types/src/types/types.d.ts +4 -50
  131. package/dist/types/src/types/types.d.ts.map +1 -1
  132. package/dist/types/tsconfig.tsbuildinfo +1 -1
  133. package/package.json +106 -49
  134. package/src/WnfsPlugin.node.ts +19 -0
  135. package/src/WnfsPlugin.test.ts +27 -0
  136. package/src/WnfsPlugin.tsx +28 -73
  137. package/src/WnfsPlugin.workerd.ts +18 -0
  138. package/src/blockstore.ts +1 -1
  139. package/src/capabilities/blockstore.ts +14 -10
  140. package/src/capabilities/create-object.ts +33 -0
  141. package/src/capabilities/file-uploader.ts +24 -17
  142. package/src/capabilities/index.ts +11 -8
  143. package/src/capabilities/markdown.ts +24 -12
  144. package/src/capabilities/operation-handler.ts +16 -0
  145. package/src/capabilities/react-surface.tsx +49 -34
  146. package/src/components/{FileInput.tsx → FileInput/FileInput.tsx} +6 -6
  147. package/src/components/FileInput/index.ts +5 -0
  148. package/src/components/FilePreview/FilePreview.tsx +43 -0
  149. package/src/components/FilePreview/index.ts +5 -0
  150. package/src/components/index.ts +1 -4
  151. package/src/containers/FileArticle/FileArticle.tsx +57 -0
  152. package/src/containers/FileArticle/index.ts +5 -0
  153. package/src/containers/index.ts +7 -0
  154. package/src/extensions/image.stories.tsx +9 -10
  155. package/src/extensions/image.tsx +7 -6
  156. package/src/helpers/load.ts +12 -7
  157. package/src/helpers/upload.ts +5 -2
  158. package/src/index.ts +2 -2
  159. package/src/meta.ts +3 -3
  160. package/src/operations/create-file.ts +30 -0
  161. package/src/operations/create.ts +21 -0
  162. package/src/operations/index.ts +11 -0
  163. package/src/operations/upload.ts +28 -0
  164. package/src/plugin.ts +11 -0
  165. package/src/translations.ts +14 -10
  166. package/src/types/WnfsCapabilities.ts +18 -0
  167. package/src/types/WnfsFile.ts +30 -0
  168. package/src/types/WnfsOperation.ts +44 -0
  169. package/src/types/index.ts +4 -1
  170. package/src/types/types.ts +3 -20
  171. package/dist/lib/browser/FileContainer-4U23PNBL.mjs +0 -103
  172. package/dist/lib/browser/FileContainer-4U23PNBL.mjs.map +0 -7
  173. package/dist/lib/browser/blockstore-2JFU4NBU.mjs.map +0 -7
  174. package/dist/lib/browser/chunk-7MEFQJWE.mjs +0 -16
  175. package/dist/lib/browser/chunk-7MEFQJWE.mjs.map +0 -7
  176. package/dist/lib/browser/chunk-CWMKN2F6.mjs +0 -71
  177. package/dist/lib/browser/chunk-CWMKN2F6.mjs.map +0 -7
  178. package/dist/lib/browser/chunk-D6VTEQIE.mjs.map +0 -7
  179. package/dist/lib/browser/chunk-F4QHZWQD.mjs +0 -16
  180. package/dist/lib/browser/chunk-F4QHZWQD.mjs.map +0 -7
  181. package/dist/lib/browser/chunk-OGPGLJCV.mjs.map +0 -7
  182. package/dist/lib/browser/file-uploader-W6TJLAAK.mjs +0 -30
  183. package/dist/lib/browser/file-uploader-W6TJLAAK.mjs.map +0 -7
  184. package/dist/lib/browser/index.mjs +0 -116
  185. package/dist/lib/browser/index.mjs.map +0 -7
  186. package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs +0 -48
  187. package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs.map +0 -7
  188. package/dist/lib/browser/markdown-3ZLVJIGT.mjs.map +0 -7
  189. package/dist/lib/browser/meta.json +0 -1
  190. package/dist/lib/browser/react-surface-SLRIZ3UR.mjs +0 -88
  191. package/dist/lib/browser/react-surface-SLRIZ3UR.mjs.map +0 -7
  192. package/dist/lib/browser/types/index.mjs +0 -10
  193. package/dist/types/src/capabilities/capabilities.d.ts +0 -12
  194. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  195. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  196. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  197. package/dist/types/src/components/FileContainer.d.ts +0 -9
  198. package/dist/types/src/components/FileContainer.d.ts.map +0 -1
  199. package/dist/types/src/components/FileInput.d.ts.map +0 -1
  200. package/dist/types/src/components/FilePreview.d.ts +0 -11
  201. package/dist/types/src/components/FilePreview.d.ts.map +0 -1
  202. package/dist/types/src/types/File.d.ts +0 -16
  203. package/dist/types/src/types/File.d.ts.map +0 -1
  204. package/src/capabilities/capabilities.ts +0 -18
  205. package/src/capabilities/intent-resolver.ts +0 -32
  206. package/src/components/FileContainer.tsx +0 -49
  207. package/src/components/FilePreview.tsx +0 -23
  208. package/src/types/File.ts +0 -24
  209. /package/dist/lib/{browser/types/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
  210. /package/dist/types/src/components/{FileInput.d.ts → FileInput/FileInput.d.ts} +0 -0
@@ -2,44 +2,59 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import * as Effect from 'effect/Effect';
5
6
  import type * as Schema from 'effect/Schema';
7
+ import * as SchemaAST from 'effect/SchemaAST';
6
8
  import React, { useCallback } from 'react';
7
9
 
8
- import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
9
- import { Obj } from '@dxos/echo';
10
+ import { Capabilities, Capability } from '@dxos/app-framework';
11
+ import { Surface } from '@dxos/app-framework/ui';
12
+ import { AppSurface } from '@dxos/app-toolkit/ui';
10
13
  import { findAnnotation } from '@dxos/effect';
11
- import { type InputProps } from '@dxos/react-ui-form';
14
+ import { type FormFieldComponentProps } from '@dxos/react-ui-form';
12
15
 
13
- import { FileContainer, FileInput } from '../components';
14
- import { meta } from '../meta';
15
- import { WnfsAction, WnfsFile } from '../types';
16
+ import { FileInput } from '#components';
17
+ import { FileArticle } from '#containers';
18
+ import { WnfsAction, WnfsFile } from '#types';
16
19
 
17
- export default () =>
18
- contributes(Capabilities.ReactSurface, [
19
- createSurface({
20
- id: `${meta.id}/article`,
21
- role: ['article', 'section', 'slide'],
22
- filter: (data): data is { subject: WnfsFile.File } => Obj.instanceOf(WnfsFile.File, data.subject),
23
- component: ({ data, role }) => <FileContainer role={role} file={data.subject} />,
24
- }),
25
- createSurface({
26
- id: `${meta.id}/create-form`,
27
- role: 'form-input',
28
- filter: (data): data is { prop: string; schema: Schema.Schema.Any } => {
29
- const annotation = findAnnotation<boolean>(
30
- (data.schema as Schema.Schema.All).ast,
31
- WnfsAction.UploadAnnotationId,
32
- );
33
- return !!annotation;
34
- },
35
- component: ({ data: { prop, schema }, ...props }) => {
36
- const inputProps = props as unknown as InputProps;
37
- const handleChange = useCallback(
38
- (file: File) => inputProps.onValueChange?.('object', file),
39
- [prop, inputProps.onValueChange],
40
- );
20
+ export default Capability.makeModule(() =>
21
+ Effect.succeed(
22
+ Capability.contributes(Capabilities.ReactSurface, [
23
+ Surface.create({
24
+ id: 'article',
25
+ // TODO(wittjosiah): Split into multiple surfaces if this filter proves too strict for non-article roles.
26
+ filter: AppSurface.oneOf(
27
+ AppSurface.object(AppSurface.Article, WnfsFile.WnfsFile),
28
+ AppSurface.object(AppSurface.Section, WnfsFile.WnfsFile),
29
+ AppSurface.object(AppSurface.Slide, WnfsFile.WnfsFile),
30
+ ),
31
+ component: ({ data, role }) => <FileArticle role={role} subject={data.subject} />,
32
+ }),
33
+ Surface.create({
34
+ id: 'create-form',
35
+ role: 'form-input',
36
+ filter: (data): data is { prop: string; schema: Schema.Schema.Any; fieldPropertyAst?: SchemaAST.AST } => {
37
+ const annotation = findAnnotation<boolean>(
38
+ (data.schema as Schema.Schema.All).ast,
39
+ WnfsAction.UploadAnnotationId,
40
+ );
41
+ return !!annotation;
42
+ },
43
+ component: ({ data: { schema, fieldPropertyAst }, ...props }) => {
44
+ const ast = fieldPropertyAst;
45
+ if (!ast) {
46
+ return null;
47
+ }
41
48
 
42
- return <FileInput schema={schema} onChange={handleChange} />;
43
- },
44
- }),
45
- ]);
49
+ const inputProps = { ...props, type: ast } as unknown as FormFieldComponentProps;
50
+ const handleChange = useCallback(
51
+ (file: File) => inputProps.onValueChange?.(ast, file),
52
+ [ast, inputProps.onValueChange],
53
+ );
54
+
55
+ return <FileInput schema={schema} onChange={handleChange} />;
56
+ },
57
+ }),
58
+ ]),
59
+ ),
60
+ );
@@ -8,10 +8,10 @@ import { useDropzone } from 'react-dropzone';
8
8
 
9
9
  import { findAnnotation } from '@dxos/effect';
10
10
  import { useTranslation } from '@dxos/react-ui';
11
- import { mx } from '@dxos/react-ui-theme';
11
+ import { mx } from '@dxos/ui-theme';
12
12
 
13
- import { meta } from '../meta';
14
- import { WnfsAction } from '../types';
13
+ import { meta } from '#meta';
14
+ import { WnfsAction } from '#types';
15
15
 
16
16
  export type FileInputProps = {
17
17
  schema: Schema.Schema.Any;
@@ -36,12 +36,12 @@ export const FileInput = ({ schema, onChange }: FileInputProps) => {
36
36
  className={mx(
37
37
  'flex flex-col items-center p-8 border border-separator',
38
38
  isFocused && 'focus-ring',
39
- isDragAccept && 'bg-attention',
40
- isDragReject && 'border-error',
39
+ isDragAccept && 'bg-attention-surface',
40
+ isDragReject && 'border-rose-fill',
41
41
  )}
42
42
  >
43
43
  <input {...getInputProps()} />
44
- {acceptedFiles[0] ? <p>{acceptedFiles[0].name}</p> : <p>{t('file input placeholder')}</p>}
44
+ {acceptedFiles[0] ? <p>{acceptedFiles[0].name}</p> : <p>{t('file-input.placeholder')}</p>}
45
45
  </div>
46
46
  );
47
47
  };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './FileInput';
@@ -0,0 +1,43 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React, { ForwardedRef } from 'react';
6
+
7
+ import { composable, composableProps } from '@dxos/ui-theme';
8
+
9
+ export type FilePreviewProps = { type: string; url: string };
10
+
11
+ /**
12
+ * File/content preview iframe.
13
+ */
14
+ export const FilePreview = composable<HTMLElement, FilePreviewProps>(
15
+ ({ type, url, children, ...props }, forwardedRef) => {
16
+ if (type.startsWith('image/')) {
17
+ return (
18
+ <img
19
+ {...composableProps(props, { classNames: 'h-full w-full object-contain' })}
20
+ src={url}
21
+ ref={forwardedRef as ForwardedRef<HTMLImageElement>}
22
+ />
23
+ );
24
+ } else if (type.startsWith('video/')) {
25
+ return (
26
+ <video
27
+ {...composableProps(props, { classNames: 'h-full w-full object-contain' })}
28
+ src={url}
29
+ controls
30
+ ref={forwardedRef as ForwardedRef<HTMLVideoElement>}
31
+ />
32
+ );
33
+ } else {
34
+ return (
35
+ <iframe
36
+ {...composableProps(props, { classNames: 'h-full w-full overflow-auto' })}
37
+ src={url}
38
+ ref={forwardedRef as ForwardedRef<HTMLIFrameElement>}
39
+ />
40
+ );
41
+ }
42
+ },
43
+ );
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './FilePreview';
@@ -2,8 +2,5 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { lazy } from 'react';
6
-
7
- export const FileContainer = lazy(() => import('./FileContainer'));
8
-
9
5
  export * from './FileInput';
6
+ export * from './FilePreview';
@@ -0,0 +1,57 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React, { useState } from 'react';
6
+
7
+ import { useCapability } from '@dxos/app-framework/ui';
8
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
9
+ import { invariant } from '@dxos/invariant';
10
+ import { getSpace } from '@dxos/react-client/echo';
11
+ import { Panel, useAsyncEffect } from '@dxos/react-ui';
12
+
13
+ import { FilePreview } from '#components';
14
+ import { WnfsCapabilities, type WnfsFile } from '#types';
15
+
16
+ import { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../../helpers';
17
+
18
+ export type FileArticleProps = AppSurface.ObjectArticleProps<WnfsFile.WnfsFile>;
19
+
20
+ export const FileArticle = ({ role, subject: file }: FileArticleProps) => {
21
+ const blockstore = useCapability(WnfsCapabilities.Blockstore);
22
+ const instances = useCapability(WnfsCapabilities.Instances);
23
+ const [blobUrl, setBlobUrl] = useState<string>();
24
+
25
+ useAsyncEffect(async () => {
26
+ const space = getSpace(file);
27
+ invariant(space);
28
+ const { directory, forest } = await loadWnfs({
29
+ blockstore,
30
+ instances,
31
+ space,
32
+ });
33
+ const path = filePath(file.cid.toString(), space);
34
+ const url = await getBlobUrl({
35
+ wnfsUrl: wnfsUrl(path),
36
+ blockstore,
37
+ directory,
38
+ forest,
39
+ type: file.type,
40
+ });
41
+ setBlobUrl(url);
42
+ }, [file]);
43
+
44
+ if (!blobUrl) {
45
+ return null;
46
+ }
47
+
48
+ return (
49
+ <Panel.Root role={role} className='dx-document'>
50
+ <Panel.Content asChild>
51
+ <FilePreview type={file.type} url={blobUrl} />
52
+ </Panel.Content>
53
+ </Panel.Root>
54
+ );
55
+ };
56
+
57
+ export default FileArticle;
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export { FileArticle as default } from './FileArticle';
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type ComponentType, lazy } from 'react';
6
+
7
+ export const FileArticle: ComponentType<any> = lazy(() => import('./FileArticle'));
@@ -6,10 +6,11 @@ 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 { useTextEditor } from '@dxos/react-ui-editor';
13
14
  import { withTheme } from '@dxos/react-ui/testing';
14
15
  import {
15
16
  createBasicExtensions,
@@ -17,21 +18,19 @@ import {
17
18
  createThemeExtensions,
18
19
  decorateMarkdown,
19
20
  processEditorPayload,
20
- useTextEditor,
21
- } from '@dxos/react-ui-editor';
21
+ } from '@dxos/ui-editor';
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(() => {
@@ -92,9 +91,9 @@ const DefaultStory = () => {
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;
@@ -11,11 +11,12 @@ import { createRoot } from 'react-dom/client';
11
11
 
12
12
  import { type Space } from '@dxos/react-client/echo';
13
13
  import { Status, ThemeProvider } from '@dxos/react-ui';
14
- import { focusField } from '@dxos/react-ui-editor';
15
- import { defaultTx } from '@dxos/react-ui-theme';
14
+ import { focusField } from '@dxos/ui-editor';
15
+ import { defaultTx } from '@dxos/ui-theme';
16
16
  import { type MaybePromise } from '@dxos/util';
17
17
 
18
- import { type WnfsCapabilities } from '../capabilities';
18
+ import { type WnfsCapabilities } from '#types';
19
+
19
20
  import { getBlobUrl, getPathFromUrl, loadWnfs } from '../helpers';
20
21
 
21
22
  const WAIT_UNTIL_LOADER = 1500;
@@ -165,11 +166,11 @@ class WnfsImageWidget extends WidgetType {
165
166
  super();
166
167
  }
167
168
 
168
- override eq(other: this): boolean {
169
- return this._wnfsUrl === (other as any as WnfsImageWidget)._wnfsUrl;
169
+ override eq(other: this) {
170
+ return this._wnfsUrl === other._wnfsUrl;
170
171
  }
171
172
 
172
- override toDOM(view: EditorView): HTMLDivElement {
173
+ override toDOM(view: EditorView) {
173
174
  if (typeof this._url === 'string') {
174
175
  return createImg(view, this._url);
175
176
  }
@@ -7,9 +7,10 @@ import { CID } from 'multiformats';
7
7
  import * as Uint8Arrays from 'uint8arrays';
8
8
  import { AccessKey, PrivateDirectory, PrivateForest, PrivateNode } from 'wnfs';
9
9
 
10
+ import { Obj } from '@dxos/echo';
10
11
  import { type Space } from '@dxos/react-client/echo';
11
12
 
12
- import { type WnfsCapabilities } from '../capabilities';
13
+ import { type WnfsCapabilities } from '#types';
13
14
 
14
15
  import { Rng, store } from './common';
15
16
 
@@ -29,8 +30,10 @@ export const loadWnfs = async ({
29
30
  // TODO(wittjosiah): Remove.
30
31
  // Delete old properties if they exist.
31
32
  if (space.properties.wnfs_access_key !== undefined && space.properties.wnfs_private_forest_cid !== undefined) {
32
- delete space.properties.wnfs_access_key;
33
- delete space.properties.wnfs_private_forest_cid;
33
+ Obj.update(space.properties, (obj) => {
34
+ delete obj['wnfs_access_key'];
35
+ delete obj['wnfs_private_forest_cid'];
36
+ });
34
37
  }
35
38
 
36
39
  const cacheKey = space.properties.wnfs?.privateForestCid;
@@ -65,10 +68,12 @@ const createWnfsDir = async (blockstore: Blockstore, space: Space) => {
65
68
 
66
69
  const cidBytes = await newForest.store(wnfsStore);
67
70
 
68
- space.properties.wnfs = {
69
- accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), 'base64'),
70
- privateForestCid: CID.decode(cidBytes).toString(),
71
- };
71
+ Obj.update(space.properties, (obj) => {
72
+ obj.wnfs = {
73
+ accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), 'base64'),
74
+ privateForestCid: CID.decode(cidBytes).toString(),
75
+ };
76
+ });
72
77
 
73
78
  return {
74
79
  directory: dir,
@@ -8,9 +8,10 @@ import * as Raw from 'multiformats/codecs/raw';
8
8
  import { sha256 } from 'multiformats/hashes/sha2';
9
9
 
10
10
  import type { Space } from '@dxos/client/echo';
11
+ import { Obj } from '@dxos/echo';
11
12
  import { log } from '@dxos/log';
12
13
 
13
- import { type WnfsCapabilities } from '../capabilities';
14
+ import { type WnfsCapabilities } from '#types';
14
15
 
15
16
  import { Rng, filePath, store } from './common';
16
17
  import { loadWnfs } from './load';
@@ -46,7 +47,9 @@ export const upload = async ({
46
47
  const cidBytes = await updatedForest.store(wnfsStore);
47
48
 
48
49
  // Update the forest pointer on the associated space.
49
- space.properties.wnfs.privateForestCid = CID.decode(cidBytes).toString();
50
+ Obj.update(space.properties, (obj) => {
51
+ obj.wnfs.privateForestCid = CID.decode(cidBytes).toString();
52
+ });
50
53
 
51
54
  // Generate `wnfs://` URL & return the info.
52
55
  const info = {
package/src/index.ts CHANGED
@@ -2,6 +2,6 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export { WnfsCapabilities } from './capabilities';
5
+ export * from './helpers';
6
6
  export * from './meta';
7
- export * from './WnfsPlugin';
7
+ export * from './types';
package/src/meta.ts CHANGED
@@ -2,11 +2,11 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { type PluginMeta } from '@dxos/app-framework';
5
+ import { type Plugin } from '@dxos/app-framework';
6
6
  import { trim } from '@dxos/util';
7
7
 
8
- export const meta: PluginMeta = {
9
- id: 'dxos.org/plugin/wnfs',
8
+ export const meta: Plugin.Meta = {
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,30 @@
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';
11
+
12
+ import { upload } from '../helpers';
13
+ import { WnfsCapabilities, WnfsFile, WnfsOperation } from '../types';
14
+
15
+ const handler: Operation.WithHandler<typeof WnfsOperation.CreateFile> = WnfsOperation.CreateFile.pipe(
16
+ Operation.withHandler(
17
+ Effect.fnUntraced(function* ({ file, db }) {
18
+ const client = yield* Capability.get(ClientCapabilities.Client);
19
+ const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
20
+ const space = client.spaces.get(db.spaceId);
21
+ invariant(space, 'Space not found');
22
+ const info = yield* Effect.promise(() => upload({ file, blockstore, space }));
23
+ return {
24
+ object: WnfsFile.make({ name: info.name, type: info.type, cid: info.cid }),
25
+ };
26
+ }),
27
+ ),
28
+ );
29
+
30
+ export default handler;
@@ -0,0 +1,21 @@
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, WnfsOperation } from '../types';
10
+
11
+ const handler: Operation.WithHandler<typeof WnfsOperation.Create> = WnfsOperation.Create.pipe(
12
+ Operation.withHandler(
13
+ Effect.fnUntraced(function* ({ name, type, cid }) {
14
+ return {
15
+ object: WnfsFile.make({ name, type, cid }),
16
+ };
17
+ }),
18
+ ),
19
+ );
20
+
21
+ export default handler;
@@ -0,0 +1,11 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { OperationHandlerSet } from '@dxos/compute';
6
+
7
+ export const WnfsOperationHandlerSet = OperationHandlerSet.lazy(
8
+ () => import('./create'),
9
+ () => import('./create-file'),
10
+ () => import('./upload'),
11
+ );
@@ -0,0 +1,28 @@
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';
11
+
12
+ import { upload } from '../helpers';
13
+ import { WnfsCapabilities, WnfsOperation } from '../types';
14
+
15
+ const handler: Operation.WithHandler<typeof WnfsOperation.Upload> = WnfsOperation.Upload.pipe(
16
+ Operation.withHandler(
17
+ Effect.fnUntraced(function* ({ file, db }) {
18
+ const client = yield* Capability.get(ClientCapabilities.Client);
19
+ const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
20
+ const space = client.spaces.get(db.spaceId);
21
+ invariant(space, 'Space not found');
22
+ const info = yield* Effect.promise(() => upload({ file, blockstore, space }));
23
+ return info;
24
+ }),
25
+ ),
26
+ );
27
+
28
+ export default handler;
package/src/plugin.ts ADDED
@@ -0,0 +1,11 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { Plugin } from '@dxos/app-framework';
6
+
7
+ import { meta } from './meta';
8
+
9
+ export const WnfsPlugin = Plugin.lazy(meta, () => import('#plugin'));
10
+
11
+ export { WnfsOperationHandlerSet } from './operations';
@@ -4,22 +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
- [WnfsFile.File.typename]: {
14
- 'typename label': 'File',
15
- 'object name placeholder': 'New file',
16
- 'rename object label': 'Rename file',
17
- 'delete object label': 'Delete file',
13
+ [WnfsFile.WnfsFile.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
+ 'add-object.label': 'Add file',
20
+ 'rename-object.label': 'Rename file',
21
+ 'delete-object.label': 'Delete file',
22
+ 'object-deleted.label': 'File deleted',
18
23
  },
19
24
  [meta.id]: {
20
- 'plugin name': 'Files',
21
- 'delete object label': 'Delete',
22
- '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',
23
27
  },
24
28
  },
25
29
  },
@@ -0,0 +1,18 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ // @import-as-namespace
6
+
7
+ import { type Blockstore as BlockstoreInterface } from 'interface-blockstore';
8
+ import { type PrivateDirectory, type PrivateForest } from 'wnfs';
9
+
10
+ import { Capability } from '@dxos/app-framework';
11
+ import { type SpaceId } from '@dxos/keys';
12
+
13
+ import { meta } from '#meta';
14
+
15
+ export const Blockstore = Capability.make<BlockstoreInterface>(`${meta.id}.capability.blockstore`);
16
+
17
+ export type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;
18
+ export const Instances = Capability.make<Instances>(`${meta.id}.capability.instances`);
@@ -0,0 +1,30 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ // @import-as-namespace
6
+
7
+ import * as Schema from 'effect/Schema';
8
+
9
+ import { Annotation, Obj, Type } from '@dxos/echo';
10
+ import { FormInputAnnotation } from '@dxos/echo/internal';
11
+
12
+ export const WnfsFile = Schema.Struct({
13
+ name: Schema.String.pipe(Schema.optional),
14
+ type: Schema.String.pipe(FormInputAnnotation.set(false)),
15
+ cid: Schema.String.pipe(FormInputAnnotation.set(false)),
16
+ timestamp: Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional),
17
+ }).pipe(
18
+ Type.object({
19
+ typename: 'org.dxos.type.file',
20
+ version: '0.1.0',
21
+ }),
22
+ Annotation.IconAnnotation.set({
23
+ icon: 'ph--file--regular',
24
+ hue: 'teal',
25
+ }),
26
+ );
27
+
28
+ export type WnfsFile = Schema.Schema.Type<typeof WnfsFile>;
29
+
30
+ export const make = (props: Obj.MakeProps<typeof WnfsFile>) => Obj.make(WnfsFile, props);