@dxos/plugin-wnfs 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0

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 (144) hide show
  1. package/dist/lib/browser/chunk-BM3MEFES.mjs +69 -0
  2. package/dist/lib/browser/chunk-BM3MEFES.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-D6VTEQIE.mjs → chunk-N6Y4QPNF.mjs} +23 -32
  4. package/dist/lib/browser/chunk-N6Y4QPNF.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-VXUCZHVZ.mjs +69 -0
  6. package/dist/lib/browser/chunk-VXUCZHVZ.mjs.map +7 -0
  7. package/dist/lib/browser/create-NOHKWE67.mjs +24 -0
  8. package/dist/lib/browser/create-NOHKWE67.mjs.map +7 -0
  9. package/dist/lib/browser/create-file-N7ADCFOF.mjs +49 -0
  10. package/dist/lib/browser/create-file-N7ADCFOF.mjs.map +7 -0
  11. package/dist/lib/browser/index.mjs +92 -91
  12. package/dist/lib/browser/index.mjs.map +4 -4
  13. package/dist/lib/browser/meta.json +1 -1
  14. package/dist/lib/browser/operations/index.mjs +13 -0
  15. package/dist/lib/browser/operations/index.mjs.map +7 -0
  16. package/dist/lib/browser/types/index.mjs +4 -3
  17. package/dist/lib/browser/upload-DA7GBOXF.mjs +42 -0
  18. package/dist/lib/browser/upload-DA7GBOXF.mjs.map +7 -0
  19. package/dist/types/src/WnfsPlugin.d.ts +2 -1
  20. package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
  21. package/dist/types/src/capabilities/blockstore.d.ts +3 -2
  22. package/dist/types/src/capabilities/blockstore.d.ts.map +1 -1
  23. package/dist/types/src/capabilities/file-uploader.d.ts +4 -2
  24. package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -1
  25. package/dist/types/src/capabilities/index.d.ts +7 -6
  26. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  27. package/dist/types/src/capabilities/markdown.d.ts +3 -2
  28. package/dist/types/src/capabilities/markdown.d.ts.map +1 -1
  29. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  30. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  31. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  32. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  33. package/dist/types/src/components/FileInput/FileInput.d.ts.map +1 -0
  34. package/dist/types/src/components/FileInput/index.d.ts +2 -0
  35. package/dist/types/src/components/FileInput/index.d.ts.map +1 -0
  36. package/dist/types/src/components/FilePreview/FilePreview.d.ts +16 -0
  37. package/dist/types/src/components/FilePreview/FilePreview.d.ts.map +1 -0
  38. package/dist/types/src/components/FilePreview/index.d.ts +2 -0
  39. package/dist/types/src/components/FilePreview/index.d.ts.map +1 -0
  40. package/dist/types/src/components/index.d.ts +1 -1
  41. package/dist/types/src/components/index.d.ts.map +1 -1
  42. package/dist/types/src/containers/FileContainer/FileContainer.d.ts +7 -0
  43. package/dist/types/src/containers/FileContainer/FileContainer.d.ts.map +1 -0
  44. package/dist/types/src/containers/FileContainer/index.d.ts +2 -0
  45. package/dist/types/src/containers/FileContainer/index.d.ts.map +1 -0
  46. package/dist/types/src/containers/index.d.ts +3 -0
  47. package/dist/types/src/containers/index.d.ts.map +1 -0
  48. package/dist/types/src/extensions/image.d.ts +1 -1
  49. package/dist/types/src/extensions/image.d.ts.map +1 -1
  50. package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
  51. package/dist/types/src/helpers/load.d.ts +1 -1
  52. package/dist/types/src/helpers/load.d.ts.map +1 -1
  53. package/dist/types/src/helpers/upload.d.ts +1 -1
  54. package/dist/types/src/helpers/upload.d.ts.map +1 -1
  55. package/dist/types/src/index.d.ts +1 -1
  56. package/dist/types/src/index.d.ts.map +1 -1
  57. package/dist/types/src/meta.d.ts +2 -2
  58. package/dist/types/src/meta.d.ts.map +1 -1
  59. package/dist/types/src/operations/create-file.d.ts +5 -0
  60. package/dist/types/src/operations/create-file.d.ts.map +1 -0
  61. package/dist/types/src/operations/create.d.ts +5 -0
  62. package/dist/types/src/operations/create.d.ts.map +1 -0
  63. package/dist/types/src/operations/definitions.d.ts +38 -0
  64. package/dist/types/src/operations/definitions.d.ts.map +1 -0
  65. package/dist/types/src/operations/index.d.ts +4 -0
  66. package/dist/types/src/operations/index.d.ts.map +1 -0
  67. package/dist/types/src/operations/upload.d.ts +5 -0
  68. package/dist/types/src/operations/upload.d.ts.map +1 -0
  69. package/dist/types/src/translations.d.ts +13 -9
  70. package/dist/types/src/translations.d.ts.map +1 -1
  71. package/dist/types/src/types/File.d.ts +11 -11
  72. package/dist/types/src/types/File.d.ts.map +1 -1
  73. package/dist/types/src/{capabilities → types}/capabilities.d.ts +3 -2
  74. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  75. package/dist/types/src/types/index.d.ts +1 -0
  76. package/dist/types/src/types/index.d.ts.map +1 -1
  77. package/dist/types/src/types/types.d.ts +4 -50
  78. package/dist/types/src/types/types.d.ts.map +1 -1
  79. package/dist/types/tsconfig.tsbuildinfo +1 -1
  80. package/package.json +59 -36
  81. package/src/WnfsPlugin.tsx +53 -73
  82. package/src/blockstore.ts +1 -1
  83. package/src/capabilities/blockstore.ts +15 -11
  84. package/src/capabilities/file-uploader.ts +24 -17
  85. package/src/capabilities/index.ts +10 -8
  86. package/src/capabilities/markdown.ts +22 -14
  87. package/src/capabilities/operation-handler.ts +16 -0
  88. package/src/capabilities/react-surface.tsx +40 -34
  89. package/src/components/{FileInput.tsx → FileInput/FileInput.tsx} +6 -6
  90. package/src/components/FileInput/index.ts +5 -0
  91. package/src/components/FilePreview/FilePreview.tsx +43 -0
  92. package/src/components/FilePreview/index.ts +5 -0
  93. package/src/components/index.ts +1 -4
  94. package/src/{components → containers/FileContainer}/FileContainer.tsx +13 -15
  95. package/src/containers/FileContainer/index.ts +5 -0
  96. package/src/containers/index.ts +7 -0
  97. package/src/extensions/image.stories.tsx +8 -9
  98. package/src/extensions/image.tsx +4 -3
  99. package/src/helpers/load.ts +12 -7
  100. package/src/helpers/upload.ts +5 -2
  101. package/src/index.ts +1 -1
  102. package/src/meta.ts +3 -3
  103. package/src/operations/create-file.ts +31 -0
  104. package/src/operations/create.ts +22 -0
  105. package/src/operations/definitions.ts +41 -0
  106. package/src/operations/index.ts +13 -0
  107. package/src/operations/upload.ts +29 -0
  108. package/src/translations.ts +13 -9
  109. package/src/types/File.ts +11 -7
  110. package/src/{capabilities → types}/capabilities.ts +4 -4
  111. package/src/types/index.ts +1 -0
  112. package/src/types/types.ts +3 -20
  113. package/dist/lib/browser/FileContainer-LLNI7WXR.mjs +0 -103
  114. package/dist/lib/browser/FileContainer-LLNI7WXR.mjs.map +0 -7
  115. package/dist/lib/browser/blockstore-2JFU4NBU.mjs +0 -191
  116. package/dist/lib/browser/blockstore-2JFU4NBU.mjs.map +0 -7
  117. package/dist/lib/browser/chunk-CWMKN2F6.mjs +0 -71
  118. package/dist/lib/browser/chunk-CWMKN2F6.mjs.map +0 -7
  119. package/dist/lib/browser/chunk-D6VTEQIE.mjs.map +0 -7
  120. package/dist/lib/browser/chunk-F4QHZWQD.mjs +0 -16
  121. package/dist/lib/browser/chunk-F4QHZWQD.mjs.map +0 -7
  122. package/dist/lib/browser/chunk-OGPGLJCV.mjs +0 -25
  123. package/dist/lib/browser/chunk-OGPGLJCV.mjs.map +0 -7
  124. package/dist/lib/browser/chunk-ZFPJA5F4.mjs +0 -16
  125. package/dist/lib/browser/chunk-ZFPJA5F4.mjs.map +0 -7
  126. package/dist/lib/browser/file-uploader-W6TJLAAK.mjs +0 -30
  127. package/dist/lib/browser/file-uploader-W6TJLAAK.mjs.map +0 -7
  128. package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs +0 -48
  129. package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs.map +0 -7
  130. package/dist/lib/browser/markdown-WYQDCVFQ.mjs +0 -198
  131. package/dist/lib/browser/markdown-WYQDCVFQ.mjs.map +0 -7
  132. package/dist/lib/browser/react-surface-DMU47U3X.mjs +0 -88
  133. package/dist/lib/browser/react-surface-DMU47U3X.mjs.map +0 -7
  134. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  135. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  136. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  137. package/dist/types/src/components/FileContainer.d.ts +0 -9
  138. package/dist/types/src/components/FileContainer.d.ts.map +0 -1
  139. package/dist/types/src/components/FileInput.d.ts.map +0 -1
  140. package/dist/types/src/components/FilePreview.d.ts +0 -11
  141. package/dist/types/src/components/FilePreview.d.ts.map +0 -1
  142. package/src/capabilities/intent-resolver.ts +0 -32
  143. package/src/components/FilePreview.tsx +0 -23
  144. /package/dist/types/src/components/{FileInput.d.ts → FileInput/FileInput.d.ts} +0 -0
@@ -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';
@@ -4,24 +4,20 @@
4
4
 
5
5
  import React, { useState } from 'react';
6
6
 
7
- import { useCapability } from '@dxos/app-framework/react';
7
+ import { useCapability } from '@dxos/app-framework/ui';
8
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
8
9
  import { invariant } from '@dxos/invariant';
9
10
  import { getSpace } from '@dxos/react-client/echo';
10
- import { useAsyncEffect } from '@dxos/react-ui';
11
- import { StackItem } from '@dxos/react-ui-stack';
11
+ import { Panel, useAsyncEffect } from '@dxos/react-ui';
12
12
 
13
- import { WnfsCapabilities } from '../capabilities';
14
- import { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../helpers';
15
- import { type WnfsFile } from '../types';
13
+ import { FilePreview } from '#components';
14
+ import { WnfsCapabilities, type WnfsFile } from '#types';
16
15
 
17
- import { FilePreview } from './FilePreview';
16
+ import { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../../helpers';
18
17
 
19
- export type FileContainerProps = {
20
- role: string;
21
- file: WnfsFile.File;
22
- };
18
+ export type FileContainerProps = AppSurface.ObjectArticleProps<WnfsFile.File>;
23
19
 
24
- export const FileContainer = ({ file }: FileContainerProps) => {
20
+ export const FileContainer = ({ role, subject: file }: FileContainerProps) => {
25
21
  const blockstore = useCapability(WnfsCapabilities.Blockstore);
26
22
  const instances = useCapability(WnfsCapabilities.Instances);
27
23
  const [blobUrl, setBlobUrl] = useState<string>();
@@ -50,9 +46,11 @@ export const FileContainer = ({ file }: FileContainerProps) => {
50
46
  }
51
47
 
52
48
  return (
53
- <StackItem.Content>
54
- <FilePreview type={file.type} url={blobUrl} />
55
- </StackItem.Content>
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>
56
54
  );
57
55
  };
58
56
 
@@ -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,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';
9
+ import { random } from '@dxos/random';
10
10
  import { useSpace } 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,16 +18,14 @@ 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 = () => {
@@ -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;
@@ -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;
@@ -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.change(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.change(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.change(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 { WnfsCapabilities } from './types';
6
6
  export * from './meta';
7
7
  export * from './WnfsPlugin';
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,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 { invariant } from '@dxos/invariant';
9
+ import { Operation } from '@dxos/operation';
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/operation';
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 { Database } from '@dxos/echo';
10
+ import { Operation } from '@dxos/operation';
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/operation';
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 { invariant } from '@dxos/invariant';
9
+ import { Operation } from '@dxos/operation';
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,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
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',
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
  },
package/src/types/File.ts CHANGED
@@ -4,19 +4,23 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { Obj, Type } from '@dxos/echo';
8
- import { FormAnnotation } from '@dxos/echo/internal';
7
+ import { Annotation, Obj, Type } from '@dxos/echo';
8
+ import { FormInputAnnotation } from '@dxos/echo/internal';
9
9
 
10
10
  export const File = Schema.Struct({
11
11
  name: Schema.String.pipe(Schema.optional),
12
- type: Schema.String.pipe(FormAnnotation.set(false)),
13
- cid: Schema.String.pipe(FormAnnotation.set(false)),
14
- timestamp: Schema.String.pipe(FormAnnotation.set(false), Schema.optional),
12
+ type: Schema.String.pipe(FormInputAnnotation.set(false)),
13
+ cid: Schema.String.pipe(FormInputAnnotation.set(false)),
14
+ timestamp: Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional),
15
15
  }).pipe(
16
- Type.Obj({
17
- typename: 'dxos.org/type/File',
16
+ Type.object({
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>;
@@ -5,14 +5,14 @@
5
5
  import { type Blockstore } from 'interface-blockstore';
6
6
  import { type PrivateDirectory, type PrivateForest } from 'wnfs';
7
7
 
8
- import { defineCapability } from '@dxos/app-framework';
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 = defineCapability<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 = defineCapability<Instances>(`${meta.id}/capability/instances`);
17
+ export const Instances = Capability.make<Instances>(`${meta.id}.capability.instances`);
18
18
  }
@@ -2,5 +2,6 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ export * from './capabilities';
5
6
  export * as WnfsFile from './File';
6
7
  export * from './types';
@@ -4,25 +4,13 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { FileInfoSchema } from '@dxos/app-framework';
8
- import { SpaceSchema } from '@dxos/react-client/echo';
9
-
10
- import { meta } from '../meta';
11
-
12
- import * as File from './File';
7
+ import { meta } from '#meta';
13
8
 
14
9
  export namespace WnfsAction {
15
- export class Create extends Schema.TaggedClass<Create>()(`${meta.id}/action/create`, {
16
- input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
17
- output: Schema.Struct({
18
- object: File.File,
19
- }),
20
- }) {}
21
-
22
- export const UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);
10
+ export const UploadAnnotationId = Symbol.for(`${meta.id}.annotation.upload`);
23
11
 
24
12
  export const UploadFileSchema = Schema.Struct({
25
- file: Schema.instanceOf(File.File).annotations({
13
+ file: Schema.instanceOf(File).annotations({
26
14
  [UploadAnnotationId]: {
27
15
  // Accept file types.
28
16
  'image/*': ['.jpg', '.jpeg', '.png', '.gif'],
@@ -33,9 +21,4 @@ export namespace WnfsAction {
33
21
  });
34
22
 
35
23
  export type UploadFileForm = Schema.Schema.Type<typeof UploadFileSchema>;
36
-
37
- export class Upload extends Schema.TaggedClass<Upload>()(`${meta.id}/action/upload`, {
38
- input: Schema.extend(UploadFileSchema, Schema.Struct({ space: SpaceSchema })),
39
- output: Schema.required(FileInfoSchema),
40
- }) {}
41
24
  }
@@ -1,103 +0,0 @@
1
- import "./chunk-ZFPJA5F4.mjs";
2
- import {
3
- filePath,
4
- getBlobUrl,
5
- loadWnfs,
6
- wnfsUrl
7
- } from "./chunk-D6VTEQIE.mjs";
8
- import {
9
- WnfsCapabilities
10
- } from "./chunk-F4QHZWQD.mjs";
11
- import "./chunk-OGPGLJCV.mjs";
12
-
13
- // src/components/FileContainer.tsx
14
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
15
- import React2, { useState } from "react";
16
- import { useCapability } from "@dxos/app-framework/react";
17
- import { invariant } from "@dxos/invariant";
18
- import { getSpace } from "@dxos/react-client/echo";
19
- import { useAsyncEffect } from "@dxos/react-ui";
20
- import { StackItem } from "@dxos/react-ui-stack";
21
-
22
- // src/components/FilePreview.tsx
23
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
24
- import React from "react";
25
- import { mx } from "@dxos/react-ui-theme";
26
- var FilePreview = ({ type, url, classNames }) => {
27
- var _effect = _useSignals();
28
- try {
29
- if (type.startsWith("image/")) {
30
- return /* @__PURE__ */ React.createElement("img", {
31
- className: mx("is-full bs-full object-contain", classNames),
32
- src: url
33
- });
34
- } else if (type.startsWith("video/")) {
35
- return /* @__PURE__ */ React.createElement("video", {
36
- className: mx("is-full bs-full object-contain", classNames),
37
- src: url,
38
- controls: true
39
- });
40
- } else {
41
- return /* @__PURE__ */ React.createElement("iframe", {
42
- className: mx("is-full bs-full overflow-auto", classNames),
43
- src: url
44
- });
45
- }
46
- } finally {
47
- _effect.f();
48
- }
49
- };
50
-
51
- // src/components/FileContainer.tsx
52
- var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/components/FileContainer.tsx";
53
- var FileContainer = ({ file }) => {
54
- var _effect = _useSignals2();
55
- try {
56
- const blockstore = useCapability(WnfsCapabilities.Blockstore);
57
- const instances = useCapability(WnfsCapabilities.Instances);
58
- const [blobUrl, setBlobUrl] = useState();
59
- useAsyncEffect(async () => {
60
- const space = getSpace(file);
61
- invariant(space, void 0, {
62
- F: __dxlog_file,
63
- L: 31,
64
- S: void 0,
65
- A: [
66
- "space",
67
- ""
68
- ]
69
- });
70
- const { directory, forest } = await loadWnfs({
71
- blockstore,
72
- instances,
73
- space
74
- });
75
- const path = filePath(file.cid.toString(), space);
76
- const url = await getBlobUrl({
77
- wnfsUrl: wnfsUrl(path),
78
- blockstore,
79
- directory,
80
- forest,
81
- type: file.type
82
- });
83
- setBlobUrl(url);
84
- }, [
85
- file
86
- ]);
87
- if (!blobUrl) {
88
- return null;
89
- }
90
- return /* @__PURE__ */ React2.createElement(StackItem.Content, null, /* @__PURE__ */ React2.createElement(FilePreview, {
91
- type: file.type,
92
- url: blobUrl
93
- }));
94
- } finally {
95
- _effect.f();
96
- }
97
- };
98
- var FileContainer_default = FileContainer;
99
- export {
100
- FileContainer,
101
- FileContainer_default as default
102
- };
103
- //# sourceMappingURL=FileContainer-LLNI7WXR.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 { 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 { StackItem } from '@dxos/react-ui-stack';\n\nimport { WnfsCapabilities } from '../capabilities';\nimport { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../helpers';\nimport { type WnfsFile } from '../types';\n\nimport { FilePreview } from './FilePreview';\n\nexport type FileContainerProps = {\n role: string;\n file: WnfsFile.File;\n};\n\nexport const FileContainer = ({ 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 <StackItem.Content>\n <FilePreview type={file.type} url={blobUrl} />\n </StackItem.Content>\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/react-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,SAASC,qBAAqB;AAC9B,SAASC,iBAAiB;AAC1B,SAASC,gBAAgB;AACzB,SAASC,sBAAsB;AAC/B,SAASC,iBAAiB;;;;ACN1B,OAAOC,WAAW;AAGlB,SAASC,UAAU;AAOZ,IAAMC,cAAc,CAAC,EAAEC,MAAMC,KAAKC,WAAU,MAAoB;;;AACrE,QAAIF,KAAKG,WAAW,QAAA,GAAW;AAC7B,aAAO,sBAAA,cAACC,OAAAA;QAAIC,WAAWC,GAAG,kCAAkCJ,UAAAA;QAAaK,KAAKN;;IAChF,WAAWD,KAAKG,WAAW,QAAA,GAAW;AACpC,aAAO,sBAAA,cAACK,SAAAA;QAAMH,WAAWC,GAAG,kCAAkCJ,UAAAA;QAAaK,KAAKN;QAAKQ,UAAAA;;IACvF,OAAO;AACL,aAAO,sBAAA,cAACC,UAAAA;QAAOL,WAAWC,GAAG,iCAAiCJ,UAAAA;QAAaK,KAAKN;;IAClF;;;;AACF;;;;ADCO,IAAMU,gBAAgB,CAAC,EAAEC,KAAI,MAAsB;;;AACxD,UAAMC,aAAaC,cAAcC,iBAAiBC,UAAU;AAC5D,UAAMC,YAAYH,cAAcC,iBAAiBG,SAAS;AAC1D,UAAM,CAACC,SAASC,UAAAA,IAAcC,SAAAA;AAE9BC,mBAAe,YAAA;AACb,YAAMC,QAAQC,SAASZ,IAAAA;AACvBa,gBAAUF,OAAAA,QAAAA;;;;;;;;;AACV,YAAM,EAAEG,WAAWC,OAAM,IAAK,MAAMC,SAAS;QAC3Cf;QACAI;QACAM;MACF,CAAA;AACA,YAAMM,OAAOC,SAASlB,KAAKmB,IAAIC,SAAQ,GAAIT,KAAAA;AAC3C,YAAMU,MAAM,MAAMC,WAAW;QAC3BC,SAASA,QAAQN,IAAAA;QACjBhB;QACAa;QACAC;QACAS,MAAMxB,KAAKwB;MACb,CAAA;AACAhB,iBAAWa,GAAAA;IACb,GAAG;MAACrB;KAAK;AAET,QAAI,CAACO,SAAS;AACZ,aAAO;IACT;AAEA,WACE,gBAAAkB,OAAA,cAACC,UAAUC,SAAO,MAChB,gBAAAF,OAAA,cAACG,aAAAA;MAAYJ,MAAMxB,KAAKwB;MAAMH,KAAKd;;;;;AAGzC;AAEA,IAAA,wBAAeR;",
6
- "names": ["React", "useState", "useCapability", "invariant", "getSpace", "useAsyncEffect", "StackItem", "React", "mx", "FilePreview", "type", "url", "classNames", "startsWith", "img", "className", "mx", "src", "video", "controls", "iframe", "FileContainer", "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", "StackItem", "Content", "FilePreview"]
7
- }