@dxos/plugin-wnfs 0.8.3 → 0.8.4-main.03d5cd7b56

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 (206) hide show
  1. package/README.md +1 -1
  2. package/dist/lib/neutral/FileContainer-YXSTSMA6.mjs +58 -0
  3. package/dist/lib/neutral/FileContainer-YXSTSMA6.mjs.map +7 -0
  4. package/dist/lib/neutral/WnfsPlugin.mjs +50 -0
  5. package/dist/lib/neutral/WnfsPlugin.mjs.map +7 -0
  6. package/dist/lib/neutral/WnfsPlugin.node.mjs +23 -0
  7. package/dist/lib/neutral/WnfsPlugin.node.mjs.map +7 -0
  8. package/dist/lib/{browser/blockstore-UT7233RJ.mjs → neutral/blockstore-3NLSWC7Z.mjs} +21 -22
  9. package/dist/lib/neutral/blockstore-3NLSWC7Z.mjs.map +7 -0
  10. package/dist/lib/neutral/capabilities/index.mjs +19 -0
  11. package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
  12. package/dist/lib/{browser/chunk-YYAW4U6J.mjs → neutral/chunk-7KFJ6LYH.mjs} +49 -24
  13. package/dist/lib/neutral/chunk-7KFJ6LYH.mjs.map +7 -0
  14. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  15. package/dist/lib/neutral/chunk-LHUHUCBD.mjs +18 -0
  16. package/dist/lib/neutral/chunk-LHUHUCBD.mjs.map +7 -0
  17. package/dist/lib/neutral/chunk-UIZBWELF.mjs +8 -0
  18. package/dist/lib/neutral/chunk-UIZBWELF.mjs.map +7 -0
  19. package/dist/lib/neutral/chunk-VWVCHTUK.mjs +125 -0
  20. package/dist/lib/neutral/chunk-VWVCHTUK.mjs.map +7 -0
  21. package/dist/lib/neutral/components/index.mjs +63 -0
  22. package/dist/lib/neutral/components/index.mjs.map +7 -0
  23. package/dist/lib/neutral/containers/index.mjs +9 -0
  24. package/dist/lib/neutral/containers/index.mjs.map +7 -0
  25. package/dist/lib/neutral/create-4ERE5CA4.mjs +23 -0
  26. package/dist/lib/neutral/create-4ERE5CA4.mjs.map +7 -0
  27. package/dist/lib/neutral/create-file-RAHDIJVU.mjs +40 -0
  28. package/dist/lib/neutral/create-file-RAHDIJVU.mjs.map +7 -0
  29. package/dist/lib/neutral/create-object-7PJC47BB.mjs +33 -0
  30. package/dist/lib/neutral/create-object-7PJC47BB.mjs.map +7 -0
  31. package/dist/lib/neutral/file-uploader-WOF3H3FN.mjs +34 -0
  32. package/dist/lib/neutral/file-uploader-WOF3H3FN.mjs.map +7 -0
  33. package/dist/lib/neutral/helpers/index.mjs +26 -0
  34. package/dist/lib/neutral/helpers/index.mjs.map +7 -0
  35. package/dist/lib/neutral/index.mjs +40 -0
  36. package/dist/lib/neutral/index.mjs.map +7 -0
  37. package/dist/lib/{browser/markdown-BWBHUHHH.mjs → neutral/markdown-I4FYAUCA.mjs} +29 -21
  38. package/dist/lib/neutral/markdown-I4FYAUCA.mjs.map +7 -0
  39. package/dist/lib/neutral/meta.json +1 -0
  40. package/dist/lib/neutral/meta.mjs +8 -0
  41. package/dist/lib/neutral/meta.mjs.map +7 -0
  42. package/dist/lib/neutral/operation-handler-NPYSIPMR.mjs +13 -0
  43. package/dist/lib/neutral/operation-handler-NPYSIPMR.mjs.map +7 -0
  44. package/dist/lib/neutral/operations/index.mjs +8 -0
  45. package/dist/lib/neutral/operations/index.mjs.map +7 -0
  46. package/dist/lib/neutral/plugin.mjs +16 -0
  47. package/dist/lib/neutral/plugin.mjs.map +7 -0
  48. package/dist/lib/neutral/react-surface-S4FB2UJ2.mjs +53 -0
  49. package/dist/lib/neutral/react-surface-S4FB2UJ2.mjs.map +7 -0
  50. package/dist/lib/neutral/translations.mjs +30 -0
  51. package/dist/lib/neutral/translations.mjs.map +7 -0
  52. package/dist/lib/neutral/types/index.mjs +14 -0
  53. package/dist/lib/neutral/types/index.mjs.map +7 -0
  54. package/dist/lib/neutral/upload-VA5CSUEP.mjs +33 -0
  55. package/dist/lib/neutral/upload-VA5CSUEP.mjs.map +7 -0
  56. package/dist/types/src/WnfsPlugin.d.ts +3 -1
  57. package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
  58. package/dist/types/src/WnfsPlugin.node.d.ts +4 -0
  59. package/dist/types/src/WnfsPlugin.node.d.ts.map +1 -0
  60. package/dist/types/src/WnfsPlugin.test.d.ts +2 -0
  61. package/dist/types/src/WnfsPlugin.test.d.ts.map +1 -0
  62. package/dist/types/src/blockstore.d.ts.map +1 -1
  63. package/dist/types/src/capabilities/blockstore.d.ts +3 -2
  64. package/dist/types/src/capabilities/blockstore.d.ts.map +1 -1
  65. package/dist/types/src/capabilities/create-object.d.ts +11 -0
  66. package/dist/types/src/capabilities/create-object.d.ts.map +1 -0
  67. package/dist/types/src/capabilities/file-uploader.d.ts +4 -2
  68. package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -1
  69. package/dist/types/src/capabilities/index.d.ts +13 -6
  70. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  71. package/dist/types/src/capabilities/markdown.d.ts +4 -2
  72. package/dist/types/src/capabilities/markdown.d.ts.map +1 -1
  73. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  74. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  75. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  76. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  77. package/dist/types/src/components/{FileInput.d.ts → FileInput/FileInput.d.ts} +1 -1
  78. package/dist/types/src/components/FileInput/FileInput.d.ts.map +1 -0
  79. package/dist/types/src/components/FileInput/index.d.ts +2 -0
  80. package/dist/types/src/components/FileInput/index.d.ts.map +1 -0
  81. package/dist/types/src/components/FilePreview/FilePreview.d.ts +12 -0
  82. package/dist/types/src/components/FilePreview/FilePreview.d.ts.map +1 -0
  83. package/dist/types/src/components/FilePreview/index.d.ts +2 -0
  84. package/dist/types/src/components/FilePreview/index.d.ts.map +1 -0
  85. package/dist/types/src/components/index.d.ts +1 -4
  86. package/dist/types/src/components/index.d.ts.map +1 -1
  87. package/dist/types/src/containers/FileContainer/FileContainer.d.ts +7 -0
  88. package/dist/types/src/containers/FileContainer/FileContainer.d.ts.map +1 -0
  89. package/dist/types/src/containers/FileContainer/index.d.ts +2 -0
  90. package/dist/types/src/containers/FileContainer/index.d.ts.map +1 -0
  91. package/dist/types/src/containers/index.d.ts +3 -0
  92. package/dist/types/src/containers/index.d.ts.map +1 -0
  93. package/dist/types/src/extensions/image.d.ts +1 -1
  94. package/dist/types/src/extensions/image.d.ts.map +1 -1
  95. package/dist/types/src/extensions/image.stories.d.ts +5 -4
  96. package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
  97. package/dist/types/src/helpers/common.d.ts.map +1 -1
  98. package/dist/types/src/helpers/load.d.ts +2 -2
  99. package/dist/types/src/helpers/load.d.ts.map +1 -1
  100. package/dist/types/src/helpers/upload.d.ts +1 -1
  101. package/dist/types/src/helpers/upload.d.ts.map +1 -1
  102. package/dist/types/src/helpers/wnfs-url.d.ts.map +1 -1
  103. package/dist/types/src/index.d.ts +2 -2
  104. package/dist/types/src/index.d.ts.map +1 -1
  105. package/dist/types/src/meta.d.ts +2 -3
  106. package/dist/types/src/meta.d.ts.map +1 -1
  107. package/dist/types/src/operations/create-file.d.ts +5 -0
  108. package/dist/types/src/operations/create-file.d.ts.map +1 -0
  109. package/dist/types/src/operations/create.d.ts +5 -0
  110. package/dist/types/src/operations/create.d.ts.map +1 -0
  111. package/dist/types/src/operations/index.d.ts +3 -0
  112. package/dist/types/src/operations/index.d.ts.map +1 -0
  113. package/dist/types/src/operations/upload.d.ts +5 -0
  114. package/dist/types/src/operations/upload.d.ts.map +1 -0
  115. package/dist/types/src/plugin.d.ts +4 -0
  116. package/dist/types/src/plugin.d.ts.map +1 -0
  117. package/dist/types/src/translations.d.ts +27 -13
  118. package/dist/types/src/translations.d.ts.map +1 -1
  119. package/dist/types/src/types/WnfsCapabilities.d.ts +11 -0
  120. package/dist/types/src/types/WnfsCapabilities.d.ts.map +1 -0
  121. package/dist/types/src/types/WnfsFile.d.ts +16 -0
  122. package/dist/types/src/types/WnfsFile.d.ts.map +1 -0
  123. package/dist/types/src/types/WnfsOperation.d.ts +38 -0
  124. package/dist/types/src/types/WnfsOperation.d.ts.map +1 -0
  125. package/dist/types/src/types/index.d.ts +3 -1
  126. package/dist/types/src/types/index.d.ts.map +1 -1
  127. package/dist/types/src/types/types.d.ts +4 -46
  128. package/dist/types/src/types/types.d.ts.map +1 -1
  129. package/dist/types/tsconfig.tsbuildinfo +1 -1
  130. package/package.json +106 -52
  131. package/src/WnfsPlugin.node.ts +19 -0
  132. package/src/WnfsPlugin.test.ts +27 -0
  133. package/src/WnfsPlugin.tsx +40 -83
  134. package/src/blockstore.ts +3 -3
  135. package/src/capabilities/blockstore.ts +14 -9
  136. package/src/capabilities/create-object.ts +33 -0
  137. package/src/capabilities/file-uploader.ts +25 -15
  138. package/src/capabilities/index.ts +11 -8
  139. package/src/capabilities/markdown.ts +25 -12
  140. package/src/capabilities/operation-handler.ts +16 -0
  141. package/src/capabilities/react-surface.tsx +50 -35
  142. package/src/components/{FileInput.tsx → FileInput/FileInput.tsx} +8 -8
  143. package/src/components/FileInput/index.ts +5 -0
  144. package/src/components/FilePreview/FilePreview.tsx +43 -0
  145. package/src/components/FilePreview/index.ts +5 -0
  146. package/src/components/index.ts +1 -4
  147. package/src/containers/FileContainer/FileContainer.tsx +57 -0
  148. package/src/containers/FileContainer/index.ts +5 -0
  149. package/src/containers/index.ts +7 -0
  150. package/src/extensions/image.stories.tsx +22 -19
  151. package/src/extensions/image.tsx +10 -9
  152. package/src/helpers/load.ts +14 -8
  153. package/src/helpers/upload.ts +6 -2
  154. package/src/index.ts +2 -2
  155. package/src/meta.ts +9 -6
  156. package/src/operations/create-file.ts +30 -0
  157. package/src/operations/create.ts +21 -0
  158. package/src/operations/index.ts +11 -0
  159. package/src/operations/upload.ts +28 -0
  160. package/src/plugin.ts +11 -0
  161. package/src/translations.ts +19 -11
  162. package/src/types/WnfsCapabilities.ts +18 -0
  163. package/src/types/WnfsFile.ts +30 -0
  164. package/src/types/WnfsOperation.ts +44 -0
  165. package/src/types/index.ts +4 -1
  166. package/src/types/types.ts +3 -19
  167. package/dist/lib/browser/FileContainer-7YOCEQ6P.mjs +0 -106
  168. package/dist/lib/browser/FileContainer-7YOCEQ6P.mjs.map +0 -7
  169. package/dist/lib/browser/blockstore-UT7233RJ.mjs.map +0 -7
  170. package/dist/lib/browser/chunk-DL7BBH57.mjs +0 -16
  171. package/dist/lib/browser/chunk-DL7BBH57.mjs.map +0 -7
  172. package/dist/lib/browser/chunk-PHTWWADN.mjs +0 -15
  173. package/dist/lib/browser/chunk-PHTWWADN.mjs.map +0 -7
  174. package/dist/lib/browser/chunk-SCL6PT4P.mjs +0 -64
  175. package/dist/lib/browser/chunk-SCL6PT4P.mjs.map +0 -7
  176. package/dist/lib/browser/chunk-WJVYRUYQ.mjs +0 -16
  177. package/dist/lib/browser/chunk-WJVYRUYQ.mjs.map +0 -7
  178. package/dist/lib/browser/chunk-YYAW4U6J.mjs.map +0 -7
  179. package/dist/lib/browser/file-uploader-RHINBPDQ.mjs +0 -29
  180. package/dist/lib/browser/file-uploader-RHINBPDQ.mjs.map +0 -7
  181. package/dist/lib/browser/index.mjs +0 -116
  182. package/dist/lib/browser/index.mjs.map +0 -7
  183. package/dist/lib/browser/intent-resolver-JDRRPIZC.mjs +0 -49
  184. package/dist/lib/browser/intent-resolver-JDRRPIZC.mjs.map +0 -7
  185. package/dist/lib/browser/markdown-BWBHUHHH.mjs.map +0 -7
  186. package/dist/lib/browser/meta.json +0 -1
  187. package/dist/lib/browser/react-surface-6GM4J4YG.mjs +0 -88
  188. package/dist/lib/browser/react-surface-6GM4J4YG.mjs.map +0 -7
  189. package/dist/lib/browser/types/index.mjs +0 -10
  190. package/dist/types/src/capabilities/capabilities.d.ts +0 -12
  191. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  192. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  193. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  194. package/dist/types/src/components/FileContainer.d.ts +0 -8
  195. package/dist/types/src/components/FileContainer.d.ts.map +0 -1
  196. package/dist/types/src/components/FileInput.d.ts.map +0 -1
  197. package/dist/types/src/components/FilePreview.d.ts +0 -11
  198. package/dist/types/src/components/FilePreview.d.ts.map +0 -1
  199. package/dist/types/src/types/file.d.ts +0 -16
  200. package/dist/types/src/types/file.d.ts.map +0 -1
  201. package/src/capabilities/capabilities.ts +0 -18
  202. package/src/capabilities/intent-resolver.ts +0 -32
  203. package/src/components/FileContainer.tsx +0 -46
  204. package/src/components/FilePreview.tsx +0 -23
  205. package/src/types/file.ts +0 -17
  206. /package/dist/lib/{browser/types/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
@@ -2,44 +2,59 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type Schema } from 'effect';
5
+ import * as Effect from 'effect/Effect';
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 { contributes, Capabilities, 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 { WNFS_PLUGIN } from '../meta';
15
- import { FileType, WnfsAction } from '../types';
16
+ import { FileInput } from '#components';
17
+ import { FileContainer } from '#containers';
18
+ import { WnfsAction, WnfsFile } from '#types';
16
19
 
17
- export default () =>
18
- contributes(Capabilities.ReactSurface, [
19
- createSurface({
20
- id: `${WNFS_PLUGIN}/article`,
21
- role: ['article', 'section', 'slide'],
22
- filter: (data): data is { subject: FileType } => Obj.instanceOf(FileType, data.subject),
23
- component: ({ data, role }) => <FileContainer role={role} file={data.subject} />,
24
- }),
25
- createSurface({
26
- id: `${WNFS_PLUGIN}/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 }) => <FileContainer 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
+ );
@@ -2,16 +2,16 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type Schema } from 'effect';
5
+ import type * as Schema from 'effect/Schema';
6
6
  import React, { useCallback } from 'react';
7
7
  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 { WNFS_PLUGIN } 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;
@@ -19,7 +19,7 @@ export type FileInputProps = {
19
19
  };
20
20
 
21
21
  export const FileInput = ({ schema, onChange }: FileInputProps) => {
22
- const { t } = useTranslation(WNFS_PLUGIN);
22
+ const { t } = useTranslation(meta.id);
23
23
  const accept = findAnnotation<Record<string, string[]>>(schema.ast, WnfsAction.UploadAnnotationId);
24
24
 
25
25
  const onDropAccepted = useCallback((files: File[]) => onChange?.(files[0]), [onChange]);
@@ -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 FileContainerProps = AppSurface.ObjectArticleProps<WnfsFile.WnfsFile>;
19
+
20
+ export const FileContainer = ({ role, subject: file }: FileContainerProps) => {
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 FileContainer;
@@ -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'));
@@ -2,36 +2,35 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
7
6
  import type { Blockstore } from 'interface-blockstore';
8
7
  import React, { type ChangeEvent, useEffect, useState } from 'react';
9
8
 
10
- import { faker } from '@dxos/random';
11
- import { useSpace } from '@dxos/react-client/echo';
9
+ import { random } from '@dxos/random';
10
+ import { useSpaces } from '@dxos/react-client/echo';
12
11
  import { withClientProvider } from '@dxos/react-client/testing';
13
12
  import { useThemeContext } from '@dxos/react-ui';
13
+ import { useTextEditor } from '@dxos/react-ui-editor';
14
+ import { withTheme } from '@dxos/react-ui/testing';
14
15
  import {
15
16
  createBasicExtensions,
16
17
  createMarkdownExtensions,
17
18
  createThemeExtensions,
18
19
  decorateMarkdown,
19
20
  processEditorPayload,
20
- useTextEditor,
21
- } from '@dxos/react-ui-editor';
22
- import { withTheme, withLayout } from '@dxos/storybook-utils';
21
+ } from '@dxos/ui-editor';
23
22
 
24
- import { image } from './image';
25
23
  import { create as createBlockstore } from '../blockstore';
26
24
  import { upload } from '../helpers';
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
- const Story = () => {
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(() => {
@@ -54,7 +53,7 @@ const Story = () => {
54
53
  initialValue,
55
54
  extensions: [
56
55
  createBasicExtensions(),
57
- createMarkdownExtensions({ themeMode }),
56
+ createMarkdownExtensions(),
58
57
  createThemeExtensions({ themeMode, syntaxHighlighting: true }),
59
58
  blockstore && space ? [image({ blockstore, instances, space })] : [],
60
59
  decorateMarkdown(),
@@ -91,10 +90,14 @@ const Story = () => {
91
90
  );
92
91
  };
93
92
 
94
- export default {
95
- title: 'plugins/plugin-wnfs/image',
96
- render: Story,
97
- decorators: [withClientProvider({ createIdentity: true, createSpace: true }), withTheme, withLayout()],
98
- };
93
+ const meta = {
94
+ title: 'plugins/plugin-wnfs/extensions/image',
95
+ render: DefaultStory,
96
+ decorators: [withTheme(), withClientProvider({ createIdentity: true, createSpace: true })],
97
+ } satisfies Meta<typeof DefaultStory>;
98
+
99
+ export default meta;
100
+
101
+ type Story = StoryObj<typeof meta>;
99
102
 
100
- export const Default = {};
103
+ export const Default: Story = {};
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { syntaxTree } from '@codemirror/language';
6
- import { type EditorState, type Extension, StateField, type Range } from '@codemirror/state';
6
+ import { type EditorState, type Extension, type Range, StateField } from '@codemirror/state';
7
7
  import { Decoration, EditorView, WidgetType } from '@codemirror/view';
8
8
  import type { Blockstore } from 'interface-blockstore';
9
9
  import React from 'react';
@@ -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;
@@ -80,16 +81,16 @@ export const image = (options: ImageOptions): Extension[] => {
80
81
  };
81
82
 
82
83
  const buildDecorations = ({
84
+ state,
83
85
  from,
84
86
  to,
85
- state,
86
87
  blobUrlCache,
87
88
  preload,
88
89
  options: { blockstore, instances, space },
89
90
  }: {
91
+ state: EditorState;
90
92
  from: number;
91
93
  to: number;
92
- state: EditorState;
93
94
  blobUrlCache: Record<string, string>;
94
95
  preload: (url: string) => void;
95
96
  options: ImageOptions;
@@ -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
  }
@@ -5,12 +5,14 @@
5
5
  import type { Blockstore } from 'interface-blockstore';
6
6
  import { CID } from 'multiformats';
7
7
  import * as Uint8Arrays from 'uint8arrays';
8
- import { AccessKey, PrivateForest, PrivateDirectory, PrivateNode } from 'wnfs';
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
 
13
+ import { type WnfsCapabilities } from '#types';
14
+
12
15
  import { Rng, store } from './common';
13
- import { type WnfsCapabilities } from '../capabilities';
14
16
 
15
17
  //
16
18
  // LOAD
@@ -28,8 +30,10 @@ export const loadWnfs = async ({
28
30
  // TODO(wittjosiah): Remove.
29
31
  // Delete old properties if they exist.
30
32
  if (space.properties.wnfs_access_key !== undefined && space.properties.wnfs_private_forest_cid !== undefined) {
31
- delete space.properties.wnfs_access_key;
32
- 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
+ });
33
37
  }
34
38
 
35
39
  const cacheKey = space.properties.wnfs?.privateForestCid;
@@ -64,10 +68,12 @@ const createWnfsDir = async (blockstore: Blockstore, space: Space) => {
64
68
 
65
69
  const cidBytes = await newForest.store(wnfsStore);
66
70
 
67
- space.properties.wnfs = {
68
- accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), 'base64'),
69
- privateForestCid: CID.decode(cidBytes).toString(),
70
- };
71
+ Obj.update(space.properties, (obj) => {
72
+ obj.wnfs = {
73
+ accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), 'base64'),
74
+ privateForestCid: CID.decode(cidBytes).toString(),
75
+ };
76
+ });
71
77
 
72
78
  return {
73
79
  directory: dir,
@@ -8,12 +8,14 @@ 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
 
14
+ import { type WnfsCapabilities } from '#types';
15
+
13
16
  import { Rng, filePath, store } from './common';
14
17
  import { loadWnfs } from './load';
15
18
  import { wnfsUrl } from './wnfs-url';
16
- import { type WnfsCapabilities } from '../capabilities';
17
19
 
18
20
  export const upload = async ({
19
21
  file,
@@ -45,7 +47,9 @@ export const upload = async ({
45
47
  const cidBytes = await updatedForest.store(wnfsStore);
46
48
 
47
49
  // Update the forest pointer on the associated space.
48
- space.properties.wnfs.privateForestCid = CID.decode(cidBytes).toString();
50
+ Obj.update(space.properties, (obj) => {
51
+ obj.wnfs.privateForestCid = CID.decode(cidBytes).toString();
52
+ });
49
53
 
50
54
  // Generate `wnfs://` URL & return the info.
51
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,14 +2,17 @@
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
+ import { trim } from '@dxos/util';
6
7
 
7
- export const WNFS_PLUGIN = 'dxos.org/plugin/wnfs';
8
-
9
- export const meta: PluginMeta = {
10
- id: WNFS_PLUGIN,
8
+ export const meta: Plugin.Meta = {
9
+ id: 'org.dxos.plugin.wnfs',
11
10
  name: 'WNFS',
12
- description: 'Manage and view files with via the Web Native File System (WNFS).',
11
+ description: trim`
12
+ Decentralized file storage using the Web Native File System protocol.
13
+ Store and sync files with end-to-end encryption across devices without central servers.
14
+ `,
13
15
  icon: 'ph--file-cloud--regular',
16
+ iconHue: 'teal',
14
17
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',
15
18
  };
@@ -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';