@dxos/plugin-wnfs 0.8.4-main.406dc2a → 0.8.4-main.548089c

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 (61) hide show
  1. package/dist/lib/browser/{FileContainer-A4OJVMVS.mjs → FileContainer-LZM2L3MR.mjs} +8 -8
  2. package/dist/lib/browser/FileContainer-LZM2L3MR.mjs.map +7 -0
  3. package/dist/lib/browser/blockstore-2JFU4NBU.mjs +191 -0
  4. package/dist/lib/browser/{blockstore-HK4IYHJJ.mjs.map → blockstore-2JFU4NBU.mjs.map} +2 -2
  5. package/dist/lib/browser/{chunk-QQB5IBX7.mjs → chunk-CWMKN2F6.mjs} +21 -14
  6. package/dist/lib/browser/chunk-CWMKN2F6.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-PAIK4SJ3.mjs → chunk-F4QHZWQD.mjs} +2 -2
  8. package/dist/lib/browser/chunk-OGPGLJCV.mjs +25 -0
  9. package/dist/lib/browser/chunk-OGPGLJCV.mjs.map +7 -0
  10. package/dist/lib/browser/chunk-XERN2ODE.mjs +16 -0
  11. package/dist/lib/browser/{file-uploader-5S37ZZCW.mjs → file-uploader-W6TJLAAK.mjs} +6 -6
  12. package/dist/lib/browser/{file-uploader-5S37ZZCW.mjs.map → file-uploader-W6TJLAAK.mjs.map} +3 -3
  13. package/dist/lib/browser/index.mjs +10 -10
  14. package/dist/lib/browser/index.mjs.map +3 -3
  15. package/dist/lib/browser/{intent-resolver-3KMIEDBO.mjs → intent-resolver-FSW2EQF4.mjs} +6 -7
  16. package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs.map +7 -0
  17. package/dist/lib/browser/{markdown-5XD3I2NQ.mjs → markdown-WYQDCVFQ.mjs} +8 -19
  18. package/dist/lib/browser/{markdown-5XD3I2NQ.mjs.map → markdown-WYQDCVFQ.mjs.map} +3 -3
  19. package/dist/lib/browser/meta.json +1 -1
  20. package/dist/lib/browser/{react-surface-5D7M3Y4W.mjs → react-surface-RO47W47I.mjs} +6 -6
  21. package/dist/lib/browser/react-surface-RO47W47I.mjs.map +7 -0
  22. package/dist/lib/browser/types/index.mjs +5 -5
  23. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  24. package/dist/types/src/components/FileContainer.d.ts +2 -2
  25. package/dist/types/src/components/FileContainer.d.ts.map +1 -1
  26. package/dist/types/src/meta.d.ts.map +1 -1
  27. package/dist/types/src/translations.d.ts +2 -2
  28. package/dist/types/src/translations.d.ts.map +1 -1
  29. package/dist/types/src/types/File.d.ts +16 -0
  30. package/dist/types/src/types/File.d.ts.map +1 -0
  31. package/dist/types/src/types/index.d.ts +1 -1
  32. package/dist/types/src/types/index.d.ts.map +1 -1
  33. package/dist/types/src/types/types.d.ts +8 -4
  34. package/dist/types/src/types/types.d.ts.map +1 -1
  35. package/dist/types/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +23 -23
  37. package/src/WnfsPlugin.tsx +4 -4
  38. package/src/capabilities/file-uploader.ts +3 -3
  39. package/src/capabilities/intent-resolver.ts +2 -3
  40. package/src/capabilities/react-surface.tsx +2 -2
  41. package/src/components/FileContainer.tsx +15 -5
  42. package/src/components/FilePreview.tsx +3 -3
  43. package/src/extensions/image.tsx +3 -3
  44. package/src/meta.ts +6 -1
  45. package/src/translations.ts +2 -2
  46. package/src/types/File.ts +24 -0
  47. package/src/types/index.ts +1 -1
  48. package/src/types/types.ts +3 -3
  49. package/dist/lib/browser/FileContainer-A4OJVMVS.mjs.map +0 -7
  50. package/dist/lib/browser/blockstore-HK4IYHJJ.mjs +0 -273
  51. package/dist/lib/browser/chunk-FYRZOKHG.mjs +0 -13
  52. package/dist/lib/browser/chunk-FYRZOKHG.mjs.map +0 -7
  53. package/dist/lib/browser/chunk-QQB5IBX7.mjs.map +0 -7
  54. package/dist/lib/browser/chunk-Y5JMTQ74.mjs +0 -16
  55. package/dist/lib/browser/intent-resolver-3KMIEDBO.mjs.map +0 -7
  56. package/dist/lib/browser/react-surface-5D7M3Y4W.mjs.map +0 -7
  57. package/dist/types/src/types/file.d.ts +0 -16
  58. package/dist/types/src/types/file.d.ts.map +0 -1
  59. package/src/types/file.ts +0 -17
  60. /package/dist/lib/browser/{chunk-PAIK4SJ3.mjs.map → chunk-F4QHZWQD.mjs.map} +0 -0
  61. /package/dist/lib/browser/{chunk-Y5JMTQ74.mjs.map → chunk-XERN2ODE.mjs.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/plugin-wnfs",
3
- "version": "0.8.4-main.406dc2a",
3
+ "version": "0.8.4-main.548089c",
4
4
  "description": "WNFS file management plugin",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -48,39 +48,39 @@
48
48
  "react-dropzone": "^14.2.3",
49
49
  "uint8arrays": "^5.1.0",
50
50
  "wnfs": "0.2.2",
51
- "@dxos/app-framework": "0.8.4-main.406dc2a",
52
- "@dxos/echo": "0.8.4-main.406dc2a",
53
- "@dxos/effect": "0.8.4-main.406dc2a",
54
- "@dxos/invariant": "0.8.4-main.406dc2a",
55
- "@dxos/log": "0.8.4-main.406dc2a",
56
- "@dxos/plugin-client": "0.8.4-main.406dc2a",
57
- "@dxos/local-storage": "0.8.4-main.406dc2a",
58
- "@dxos/react-client": "0.8.4-main.406dc2a",
59
- "@dxos/plugin-space": "0.8.4-main.406dc2a",
60
- "@dxos/react-ui": "0.8.4-main.406dc2a",
61
- "@dxos/react-ui-editor": "0.8.4-main.406dc2a",
62
- "@dxos/crypto": "0.8.4-main.406dc2a",
63
- "@dxos/plugin-markdown": "0.8.4-main.406dc2a",
64
- "@dxos/react-ui-stack": "0.8.4-main.406dc2a",
65
- "@dxos/util": "0.8.4-main.406dc2a",
66
- "@dxos/react-ui-form": "0.8.4-main.406dc2a"
51
+ "@dxos/app-framework": "0.8.4-main.548089c",
52
+ "@dxos/crypto": "0.8.4-main.548089c",
53
+ "@dxos/echo": "0.8.4-main.548089c",
54
+ "@dxos/invariant": "0.8.4-main.548089c",
55
+ "@dxos/effect": "0.8.4-main.548089c",
56
+ "@dxos/log": "0.8.4-main.548089c",
57
+ "@dxos/local-storage": "0.8.4-main.548089c",
58
+ "@dxos/plugin-markdown": "0.8.4-main.548089c",
59
+ "@dxos/plugin-client": "0.8.4-main.548089c",
60
+ "@dxos/plugin-space": "0.8.4-main.548089c",
61
+ "@dxos/react-client": "0.8.4-main.548089c",
62
+ "@dxos/react-ui": "0.8.4-main.548089c",
63
+ "@dxos/react-ui-editor": "0.8.4-main.548089c",
64
+ "@dxos/react-ui-form": "0.8.4-main.548089c",
65
+ "@dxos/react-ui-stack": "0.8.4-main.548089c",
66
+ "@dxos/util": "0.8.4-main.548089c"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/react": "~19.2.2",
70
- "@types/react-dom": "~19.2.1",
70
+ "@types/react-dom": "~19.2.2",
71
71
  "react": "~19.2.0",
72
72
  "react-dom": "~19.2.0",
73
73
  "vite": "7.1.9",
74
- "@dxos/random": "0.8.4-main.406dc2a",
75
- "@dxos/react-ui-theme": "0.8.4-main.406dc2a",
76
- "@dxos/storybook-utils": "0.8.4-main.406dc2a"
74
+ "@dxos/random": "0.8.4-main.548089c",
75
+ "@dxos/react-ui-theme": "0.8.4-main.548089c",
76
+ "@dxos/storybook-utils": "0.8.4-main.548089c"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "effect": "^3.13.3",
80
80
  "react": "^19.0.0",
81
81
  "react-dom": "^19.0.0",
82
- "@dxos/react-ui": "0.8.4-main.406dc2a",
83
- "@dxos/react-ui-theme": "0.8.4-main.406dc2a"
82
+ "@dxos/react-ui": "0.8.4-main.548089c",
83
+ "@dxos/react-ui-theme": "0.8.4-main.548089c"
84
84
  },
85
85
  "publishConfig": {
86
86
  "access": "public"
@@ -21,7 +21,7 @@ import { defineObjectForm } from '@dxos/plugin-space/types';
21
21
  import { Blockstore, FileUploader, IntentResolver, Markdown, ReactSurface, WnfsCapabilities } from './capabilities';
22
22
  import { meta } from './meta';
23
23
  import { translations } from './translations';
24
- import { FileType, WnfsAction } from './types';
24
+ import { WnfsAction, WnfsFile } from './types';
25
25
 
26
26
  export const WnfsPlugin = definePlugin(meta, () => [
27
27
  defineModule({
@@ -47,11 +47,11 @@ export const WnfsPlugin = definePlugin(meta, () => [
47
47
  activatesOn: Events.SetupMetadata,
48
48
  activate: () =>
49
49
  contributes(Capabilities.Metadata, {
50
- id: FileType.typename,
50
+ id: WnfsFile.File.typename,
51
51
  metadata: {
52
- label: (object: any) => (object instanceof FileType ? object.name : undefined),
53
52
  // TODO(wittjosiah): Would be nice if icon could change based on the type of the file.
54
53
  icon: 'ph--file--regular',
54
+ iconHue: 'teal',
55
55
  },
56
56
  }),
57
57
  }),
@@ -62,7 +62,7 @@ export const WnfsPlugin = definePlugin(meta, () => [
62
62
  contributes(
63
63
  SpaceCapabilities.ObjectForm,
64
64
  defineObjectForm({
65
- objectSchema: FileType,
65
+ objectSchema: WnfsFile.File,
66
66
  formSchema: WnfsAction.UploadFileSchema,
67
67
  getIntent: (props, options) =>
68
68
  Function.pipe(
@@ -11,14 +11,14 @@ import { SpaceAction } from '@dxos/plugin-space/types';
11
11
  import { WnfsAction } from '../types';
12
12
 
13
13
  export default (context: PluginContext) => {
14
- return contributes(Capabilities.FileUploader, (file, space) => {
14
+ return contributes(Capabilities.FileUploader, (space, file) => {
15
15
  const { dispatch } = context.getCapability(Capabilities.IntentDispatcher);
16
-
17
16
  const program = Effect.gen(function* () {
18
- const fileInfo = yield* dispatch(createIntent(WnfsAction.Upload, { file, space }));
17
+ const fileInfo = yield* dispatch(createIntent(WnfsAction.Upload, { space, file }));
19
18
  yield* dispatch(
20
19
  Function.pipe(createIntent(WnfsAction.Create, fileInfo), chain(SpaceAction.AddObject, { target: space })),
21
20
  );
21
+
22
22
  return fileInfo;
23
23
  });
24
24
 
@@ -3,10 +3,9 @@
3
3
  //
4
4
 
5
5
  import { Capabilities, type PluginContext, contributes, createResolver } from '@dxos/app-framework';
6
- import { Obj } from '@dxos/echo';
7
6
 
8
7
  import { upload } from '../helpers';
9
- import { FileType, WnfsAction } from '../types';
8
+ import { WnfsAction, WnfsFile } from '../types';
10
9
 
11
10
  import { WnfsCapabilities } from './capabilities';
12
11
 
@@ -18,7 +17,7 @@ export default (context: PluginContext) =>
18
17
  intent: WnfsAction.Create,
19
18
  resolve: ({ name, type, cid }) => ({
20
19
  data: {
21
- object: Obj.make(FileType, { name, type, cid }),
20
+ object: WnfsFile.make({ name, type, cid }),
22
21
  },
23
22
  }),
24
23
  }),
@@ -12,14 +12,14 @@ import { type InputProps } from '@dxos/react-ui-form';
12
12
 
13
13
  import { FileContainer, FileInput } from '../components';
14
14
  import { meta } from '../meta';
15
- import { FileType, WnfsAction } from '../types';
15
+ import { WnfsAction, WnfsFile } from '../types';
16
16
 
17
17
  export default () =>
18
18
  contributes(Capabilities.ReactSurface, [
19
19
  createSurface({
20
20
  id: `${meta.id}/article`,
21
21
  role: ['article', 'section', 'slide'],
22
- filter: (data): data is { subject: FileType } => Obj.instanceOf(FileType, data.subject),
22
+ filter: (data): data is { subject: WnfsFile.File } => Obj.instanceOf(WnfsFile.File, data.subject),
23
23
  component: ({ data, role }) => <FileContainer role={role} file={data.subject} />,
24
24
  }),
25
25
  createSurface({
@@ -4,7 +4,7 @@
4
4
 
5
5
  import React, { useState } from 'react';
6
6
 
7
- import { useCapability } from '@dxos/app-framework';
7
+ import { useCapability } from '@dxos/app-framework/react';
8
8
  import { invariant } from '@dxos/invariant';
9
9
  import { getSpace } from '@dxos/react-client/echo';
10
10
  import { useAsyncEffect } from '@dxos/react-ui';
@@ -12,13 +12,13 @@ import { StackItem } from '@dxos/react-ui-stack';
12
12
 
13
13
  import { WnfsCapabilities } from '../capabilities';
14
14
  import { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../helpers';
15
- import { type FileType } from '../types';
15
+ import { type WnfsFile } from '../types';
16
16
 
17
17
  import { FilePreview } from './FilePreview';
18
18
 
19
19
  export type FileContainerProps = {
20
20
  role: string;
21
- file: FileType;
21
+ file: WnfsFile.File;
22
22
  };
23
23
 
24
24
  export const FileContainer = ({ file }: FileContainerProps) => {
@@ -29,9 +29,19 @@ export const FileContainer = ({ file }: FileContainerProps) => {
29
29
  useAsyncEffect(async () => {
30
30
  const space = getSpace(file);
31
31
  invariant(space);
32
- const { directory, forest } = await loadWnfs({ blockstore, instances, space });
32
+ const { directory, forest } = await loadWnfs({
33
+ blockstore,
34
+ instances,
35
+ space,
36
+ });
33
37
  const path = filePath(file.cid.toString(), space);
34
- const url = await getBlobUrl({ wnfsUrl: wnfsUrl(path), blockstore, directory, forest, type: file.type });
38
+ const url = await getBlobUrl({
39
+ wnfsUrl: wnfsUrl(path),
40
+ blockstore,
41
+ directory,
42
+ forest,
43
+ type: file.type,
44
+ });
35
45
  setBlobUrl(url);
36
46
  }, [file]);
37
47
 
@@ -14,10 +14,10 @@ export type FilePreviewProps = ThemedClassName<{ type: string; url: string }>;
14
14
  */
15
15
  export const FilePreview = ({ type, url, classNames }: FilePreviewProps) => {
16
16
  if (type.startsWith('image/')) {
17
- return <img className={mx('w-full h-full object-contain', classNames)} src={url} />;
17
+ return <img className={mx('is-full bs-full object-contain', classNames)} src={url} />;
18
18
  } else if (type.startsWith('video/')) {
19
- return <video className={mx('w-full h-full object-contain', classNames)} src={url} controls />;
19
+ return <video className={mx('is-full bs-full object-contain', classNames)} src={url} controls />;
20
20
  } else {
21
- return <iframe className={mx('w-full h-full overflow-auto', classNames)} src={url} />;
21
+ return <iframe className={mx('is-full bs-full overflow-auto', classNames)} src={url} />;
22
22
  }
23
23
  };
@@ -165,11 +165,11 @@ class WnfsImageWidget extends WidgetType {
165
165
  super();
166
166
  }
167
167
 
168
- override eq(other: this): boolean {
169
- return this._wnfsUrl === (other as any as WnfsImageWidget)._wnfsUrl;
168
+ override eq(other: this) {
169
+ return this._wnfsUrl === other._wnfsUrl;
170
170
  }
171
171
 
172
- override toDOM(view: EditorView): HTMLDivElement {
172
+ override toDOM(view: EditorView) {
173
173
  if (typeof this._url === 'string') {
174
174
  return createImg(view, this._url);
175
175
  }
package/src/meta.ts CHANGED
@@ -3,11 +3,16 @@
3
3
  //
4
4
 
5
5
  import { type PluginMeta } from '@dxos/app-framework';
6
+ import { trim } from '@dxos/util';
6
7
 
7
8
  export const meta: PluginMeta = {
8
9
  id: 'dxos.org/plugin/wnfs',
9
10
  name: 'WNFS',
10
- 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
+ `,
11
15
  icon: 'ph--file-cloud--regular',
16
+ iconHue: 'teal',
12
17
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',
13
18
  };
@@ -5,12 +5,12 @@
5
5
  import { type Resource } from '@dxos/react-ui';
6
6
 
7
7
  import { meta } from './meta';
8
- import { FileType } from './types';
8
+ import { WnfsFile } from './types';
9
9
 
10
10
  export const translations = [
11
11
  {
12
12
  'en-US': {
13
- [FileType.typename]: {
13
+ [WnfsFile.File.typename]: {
14
14
  'typename label': 'File',
15
15
  'object name placeholder': 'New file',
16
16
  'rename object label': 'Rename file',
@@ -0,0 +1,24 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { Obj, Type } from '@dxos/echo';
8
+ import { FormAnnotation } from '@dxos/echo/internal';
9
+
10
+ export const File = Schema.Struct({
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),
15
+ }).pipe(
16
+ Type.Obj({
17
+ typename: 'dxos.org/type/File',
18
+ version: '0.1.0',
19
+ }),
20
+ );
21
+
22
+ export type File = Schema.Schema.Type<typeof File>;
23
+
24
+ export const make = (props: Obj.MakeProps<typeof File>) => Obj.make(File, props);
@@ -2,5 +2,5 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export * from './file';
5
+ export * as WnfsFile from './File';
6
6
  export * from './types';
@@ -9,20 +9,20 @@ import { SpaceSchema } from '@dxos/react-client/echo';
9
9
 
10
10
  import { meta } from '../meta';
11
11
 
12
- import { FileType } from './file';
12
+ import * as File from './File';
13
13
 
14
14
  export namespace WnfsAction {
15
15
  export class Create extends Schema.TaggedClass<Create>()(`${meta.id}/action/create`, {
16
16
  input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
17
17
  output: Schema.Struct({
18
- object: FileType,
18
+ object: File.File,
19
19
  }),
20
20
  }) {}
21
21
 
22
22
  export const UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);
23
23
 
24
24
  export const UploadFileSchema = Schema.Struct({
25
- file: Schema.instanceOf(File).annotations({
25
+ file: Schema.instanceOf(File.File).annotations({
26
26
  [UploadAnnotationId]: {
27
27
  // Accept file types.
28
28
  'image/*': ['.jpg', '.jpeg', '.png', '.gif'],
@@ -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';\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 FileType } from '../types';\n\nimport { FilePreview } from './FilePreview';\n\nexport type FileContainerProps = {\n role: string;\n file: FileType;\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({ blockstore, instances, space });\n const path = filePath(file.cid.toString(), space);\n const url = await getBlobUrl({ wnfsUrl: wnfsUrl(path), blockstore, directory, forest, type: file.type });\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('w-full h-full object-contain', classNames)} src={url} />;\n } else if (type.startsWith('video/')) {\n return <video className={mx('w-full h-full object-contain', classNames)} src={url} controls />;\n } else {\n return <iframe className={mx('w-full h-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,gCAAgCJ,UAAAA;QAAaK,KAAKN;;IAC9E,WAAWD,KAAKG,WAAW,QAAA,GAAW;AACpC,aAAO,sBAAA,cAACK,SAAAA;QAAMH,WAAWC,GAAG,gCAAgCJ,UAAAA;QAAaK,KAAKN;QAAKQ,UAAAA;;IACrF,OAAO;AACL,aAAO,sBAAA,cAACC,UAAAA;QAAOL,WAAWC,GAAG,+BAA+BJ,UAAAA;QAAaK,KAAKN;;IAChF;;;;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;QAAEf;QAAYI;QAAWM;MAAM,CAAA;AAC5E,YAAMM,OAAOC,SAASlB,KAAKmB,IAAIC,SAAQ,GAAIT,KAAAA;AAC3C,YAAMU,MAAM,MAAMC,WAAW;QAAEC,SAASA,QAAQN,IAAAA;QAAOhB;QAAYa;QAAWC;QAAQS,MAAMxB,KAAKwB;MAAK,CAAA;AACtGhB,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
- }
@@ -1,273 +0,0 @@
1
- import {
2
- storeName
3
- } from "./chunk-D6VTEQIE.mjs";
4
- import {
5
- WnfsCapabilities
6
- } from "./chunk-PAIK4SJ3.mjs";
7
- import "./chunk-FYRZOKHG.mjs";
8
-
9
- // src/capabilities/blockstore.ts
10
- import { contributes } from "@dxos/app-framework";
11
- import { ClientCapabilities } from "@dxos/plugin-client";
12
-
13
- // src/blockstore.ts
14
- import { CarWriter } from "@ipld/car";
15
- import { BaseBlockstore } from "blockstore-core";
16
- import { IDBBlockstore } from "blockstore-idb";
17
- import debounce from "debounce";
18
- import * as IDB from "idb-keyval";
19
- import all from "it-all";
20
- import { CID } from "multiformats";
21
- import * as Uint8Arrays from "uint8arrays";
22
- function _check_private_redeclaration(obj, privateCollection) {
23
- if (privateCollection.has(obj)) {
24
- throw new TypeError("Cannot initialize the same private elements twice on an object");
25
- }
26
- }
27
- function _class_apply_descriptor_get(receiver, descriptor) {
28
- if (descriptor.get) {
29
- return descriptor.get.call(receiver);
30
- }
31
- return descriptor.value;
32
- }
33
- function _class_apply_descriptor_set(receiver, descriptor, value) {
34
- if (descriptor.set) {
35
- descriptor.set.call(receiver, value);
36
- } else {
37
- if (!descriptor.writable) {
38
- throw new TypeError("attempted to set read only private field");
39
- }
40
- descriptor.value = value;
41
- }
42
- }
43
- function _class_extract_field_descriptor(receiver, privateMap, action) {
44
- if (!privateMap.has(receiver)) {
45
- throw new TypeError("attempted to " + action + " private field on non-instance");
46
- }
47
- return privateMap.get(receiver);
48
- }
49
- function _class_private_field_get(receiver, privateMap) {
50
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
51
- return _class_apply_descriptor_get(receiver, descriptor);
52
- }
53
- function _class_private_field_init(obj, privateMap, value) {
54
- _check_private_redeclaration(obj, privateMap);
55
- privateMap.set(obj, value);
56
- }
57
- function _class_private_field_set(receiver, privateMap, value) {
58
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
59
- _class_apply_descriptor_set(receiver, descriptor, value);
60
- return value;
61
- }
62
- function _class_private_method_get(receiver, privateSet, fn) {
63
- if (!privateSet.has(receiver)) {
64
- throw new TypeError("attempted to get private field on non-instance");
65
- }
66
- return fn;
67
- }
68
- function _class_private_method_init(obj, privateSet) {
69
- _check_private_redeclaration(obj, privateSet);
70
- privateSet.add(obj);
71
- }
72
- function _define_property(obj, key, value) {
73
- if (key in obj) {
74
- Object.defineProperty(obj, key, {
75
- value,
76
- enumerable: true,
77
- configurable: true,
78
- writable: true
79
- });
80
- } else {
81
- obj[key] = value;
82
- }
83
- return obj;
84
- }
85
- var create = (apiHost) => {
86
- return new MixedBlockstore(apiHost);
87
- };
88
- var _apiHost = /* @__PURE__ */ new WeakMap();
89
- var _localStore = /* @__PURE__ */ new WeakMap();
90
- var _isConnected = /* @__PURE__ */ new WeakMap();
91
- var _flushQueue = /* @__PURE__ */ new WeakMap();
92
- var _queue = /* @__PURE__ */ new WeakMap();
93
- var _addToQueue = /* @__PURE__ */ new WeakSet();
94
- var _flushQueueInt = /* @__PURE__ */ new WeakSet();
95
- var _restoreQueue = /* @__PURE__ */ new WeakSet();
96
- var _saveQueue = /* @__PURE__ */ new WeakSet();
97
- var _createCar = /* @__PURE__ */ new WeakSet();
98
- var MixedBlockstore = class extends BaseBlockstore {
99
- async open() {
100
- await _class_private_field_get(this, _localStore).open();
101
- await _class_private_method_get(this, _restoreQueue, restoreQueue).call(this);
102
- window.addEventListener("offline", async () => {
103
- _class_private_field_set(this, _isConnected, false);
104
- });
105
- window.addEventListener("online", async () => {
106
- _class_private_field_set(this, _isConnected, true);
107
- _class_private_field_get(this, _flushQueue).call(this);
108
- });
109
- }
110
- url(apiHost, cid) {
111
- const path = cid ? cid.toString() : "";
112
- return `${apiHost}/api/file${path.length ? "/" + path : ""}`;
113
- }
114
- // BLOCKSTORE IMPLEMENTATION
115
- async delete(key) {
116
- await _class_private_field_get(this, _localStore).delete(key);
117
- if (_class_private_field_get(this, _isConnected) && _class_private_field_get(this, _apiHost)) {
118
- await fetch(this.url(_class_private_field_get(this, _apiHost), key), {
119
- method: "DELETE"
120
- });
121
- }
122
- }
123
- async get(key) {
124
- if (await _class_private_field_get(this, _localStore).has(key)) {
125
- return await _class_private_field_get(this, _localStore).get(key);
126
- }
127
- if (_class_private_field_get(this, _isConnected) && _class_private_field_get(this, _apiHost)) {
128
- const block = await fetch(this.url(_class_private_field_get(this, _apiHost), key), {
129
- method: "GET"
130
- }).then((r) => r.arrayBuffer()).then((r) => new Uint8Array(r));
131
- await _class_private_field_get(this, _localStore).put(key, block);
132
- return block;
133
- }
134
- return await _class_private_field_get(this, _localStore).get(key);
135
- }
136
- async has(key) {
137
- if (await _class_private_field_get(this, _localStore).has(key)) {
138
- return true;
139
- }
140
- if (_class_private_field_get(this, _isConnected) && _class_private_field_get(this, _apiHost)) {
141
- return await fetch(this.url(_class_private_field_get(this, _apiHost), key), {
142
- method: "HEAD"
143
- }).then((r) => r.ok);
144
- }
145
- return false;
146
- }
147
- async put(key, val) {
148
- await _class_private_field_get(this, _localStore).put(key, val);
149
- await _class_private_method_get(this, _addToQueue, addToQueue).call(this, key);
150
- _class_private_field_get(this, _flushQueue).call(this);
151
- return key;
152
- }
153
- async destroy() {
154
- await _class_private_field_get(this, _localStore).destroy();
155
- }
156
- // REMOTE
157
- async putRemote(key, val) {
158
- if (_class_private_field_get(this, _apiHost)) {
159
- await fetch(this.url(_class_private_field_get(this, _apiHost), key), {
160
- method: "POST",
161
- body: val
162
- });
163
- }
164
- }
165
- async putCarRemote(car) {
166
- if (_class_private_field_get(this, _apiHost)) {
167
- await fetch(this.url(_class_private_field_get(this, _apiHost)), {
168
- method: "POST",
169
- headers: {
170
- "Content-Type": "application/vnd.ipld.car"
171
- },
172
- body: car
173
- });
174
- }
175
- }
176
- constructor(apiHost) {
177
- super(), _class_private_method_init(this, _addToQueue), _class_private_method_init(this, _flushQueueInt), _class_private_method_init(this, _restoreQueue), _class_private_method_init(this, _saveQueue), // 🛠️
178
- _class_private_method_init(this, _createCar), _class_private_field_init(this, _apiHost, {
179
- writable: true,
180
- value: void 0
181
- }), _class_private_field_init(this, _localStore, {
182
- writable: true,
183
- value: void 0
184
- }), _class_private_field_init(this, _isConnected, {
185
- writable: true,
186
- value: void 0
187
- }), _class_private_field_init(this, _flushQueue, {
188
- writable: true,
189
- value: void 0
190
- }), _class_private_field_init(this, _queue, {
191
- writable: true,
192
- value: void 0
193
- }), // QUEUE
194
- _define_property(this, "queueCacheName", `${storeName()}/state/queue`);
195
- _class_private_field_set(this, _apiHost, apiHost ? apiHost.replace(/\/?$/, "") : void 0);
196
- _class_private_field_set(this, _localStore, new IDBBlockstore(storeName()));
197
- _class_private_field_set(this, _isConnected, navigator.onLine);
198
- _class_private_field_set(this, _queue, []);
199
- _class_private_field_set(this, _flushQueue, debounce(_class_private_method_get(this, _flushQueueInt, flushQueueInt), 5e3));
200
- }
201
- };
202
- async function addToQueue(key) {
203
- await _class_private_method_get(this, _saveQueue, saveQueue).call(this, [
204
- ..._class_private_field_get(this, _queue),
205
- key.toString()
206
- ]);
207
- }
208
- async function flushQueueInt() {
209
- if (!_class_private_field_get(this, _isConnected) || !_class_private_field_get(this, _apiHost)) {
210
- return;
211
- }
212
- const keys = [
213
- ..._class_private_field_get(this, _queue)
214
- ];
215
- if (keys.length === 0) {
216
- return;
217
- }
218
- const blocks = await Promise.all(keys.map(async (key) => {
219
- const cid = CID.parse(key);
220
- const bytes = await _class_private_field_get(this, _localStore).get(cid);
221
- return {
222
- cid,
223
- bytes
224
- };
225
- }));
226
- const car = await _class_private_method_get(this, _createCar, createCar).call(this, blocks);
227
- await this.putCarRemote(car);
228
- const queue = [
229
- ..._class_private_field_get(this, _queue)
230
- ].filter((k) => {
231
- if (keys.includes(k)) {
232
- return false;
233
- }
234
- return true;
235
- });
236
- await _class_private_method_get(this, _saveQueue, saveQueue).call(this, queue);
237
- }
238
- async function restoreQueue() {
239
- const fromCache = await IDB.get(this.queueCacheName);
240
- if (fromCache && Array.isArray(fromCache)) {
241
- _class_private_field_set(this, _queue, fromCache);
242
- _class_private_field_get(this, _flushQueue).call(this);
243
- }
244
- }
245
- async function saveQueue(items) {
246
- const arr = [
247
- ...items
248
- ];
249
- _class_private_field_set(this, _queue, arr);
250
- await IDB.set(this.queueCacheName, arr);
251
- }
252
- async function createCar(blocks) {
253
- const { writer, out } = CarWriter.create();
254
- const outPromise = all(out);
255
- await Promise.all(blocks.map((block) => {
256
- return writer.put(block);
257
- }));
258
- await writer.close();
259
- return Uint8Arrays.concat(await outPromise);
260
- }
261
-
262
- // src/capabilities/blockstore.ts
263
- var blockstore_default = (async (context) => {
264
- const client = context.getCapability(ClientCapabilities.Client);
265
- const apiHost = client.config.values.runtime?.services?.edge?.url || "http://localhost:8787";
266
- const blockstore = create(apiHost);
267
- await blockstore.open();
268
- return contributes(WnfsCapabilities.Blockstore, blockstore);
269
- });
270
- export {
271
- blockstore_default as default
272
- };
273
- //# sourceMappingURL=blockstore-HK4IYHJJ.mjs.map
@@ -1,13 +0,0 @@
1
- // src/meta.ts
2
- var meta = {
3
- id: "dxos.org/plugin/wnfs",
4
- name: "WNFS",
5
- description: "Manage and view files with via the Web Native File System (WNFS).",
6
- icon: "ph--file-cloud--regular",
7
- source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs"
8
- };
9
-
10
- export {
11
- meta
12
- };
13
- //# sourceMappingURL=chunk-FYRZOKHG.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/meta.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const meta: PluginMeta = {\n id: 'dxos.org/plugin/wnfs',\n name: 'WNFS',\n description: 'Manage and view files with via the Web Native File System (WNFS).',\n icon: 'ph--file-cloud--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',\n};\n"],
5
- "mappings": ";AAMO,IAAMA,OAAmB;EAC9BC,IAAI;EACJC,MAAM;EACNC,aAAa;EACbC,MAAM;EACNC,QAAQ;AACV;",
6
- "names": ["meta", "id", "name", "description", "icon", "source"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/types/file.ts", "../../../src/types/types.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { TypedObject } from '@dxos/echo/internal';\n\nexport class FileType extends TypedObject({\n typename: 'dxos.org/type/File',\n version: '0.1.0',\n})({\n name: Schema.optional(Schema.String),\n type: Schema.String,\n cid: Schema.String,\n timestamp: Schema.optional(Schema.String),\n}) {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { FileInfoSchema } from '@dxos/app-framework';\nimport { SpaceSchema } from '@dxos/react-client/echo';\n\nimport { meta } from '../meta';\n\nimport { FileType } from './file';\n\nexport namespace WnfsAction {\n export class Create extends Schema.TaggedClass<Create>()(`${meta.id}/action/create`, {\n input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),\n output: Schema.Struct({\n object: FileType,\n }),\n }) {}\n\n export const UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);\n\n export const UploadFileSchema = Schema.Struct({\n file: Schema.instanceOf(File).annotations({\n [UploadAnnotationId]: {\n // Accept file types.\n 'image/*': ['.jpg', '.jpeg', '.png', '.gif'],\n 'application/pdf': ['.pdf'],\n // TODO(wittjosiah): Add more file types.\n },\n }),\n });\n\n export type UploadFileForm = Schema.Schema.Type<typeof UploadFileSchema>;\n\n export class Upload extends Schema.TaggedClass<Upload>()(`${meta.id}/action/upload`, {\n input: Schema.extend(UploadFileSchema, Schema.Struct({ space: SpaceSchema })),\n output: Schema.required(FileInfoSchema),\n }) {}\n}\n"],
5
- "mappings": ";;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,mBAAmB;AAErB,IAAMC,WAAN,cAAuBC,YAAY;EACxCC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDC,MAAaC,gBAAgBC,aAAM;EACnCC,MAAaD;EACbE,KAAYF;EACZG,WAAkBJ,gBAAgBC,aAAM;AAC1C,CAAA,EAAA;AAAI;;;ACZJ,YAAYI,aAAY;AAExB,SAASC,sBAAsB;AAC/B,SAASC,mBAAmB;UAMXC,aAAAA;EACR,MAAMC,eAAsBC,oBAAW,EAAW,GAAGC,KAAKC,EAAE,kBAAkB;IACnFC,OAAOC,eAAeC,KAAK,QAAQ,QAAQ,KAAA,EAAOC,KAAYC,gBAAQ;IACtEC,QAAeC,eAAO;MACpBC,QAAQC;IACV,CAAA;EACF,CAAA,EAAA;EAAI;cALSZ,SAAAA;cAOAa,qBAAqBC,OAAOC,IAAI,GAAGb,KAAKC,EAAE,oBAAoB;cAE9Da,mBAA0BN,eAAO;IAC5CO,MAAaC,mBAAWC,IAAAA,EAAMC,YAAY;MACxC,CAAArB,YAACc,kBAAAA,GAAqB;;QAEpB,WAAW;UAAC;UAAQ;UAAS;UAAQ;;QACrC,mBAAmB;UAAC;;MAEtB;IACF,CAAA;EACF,CAAA;EAIO,MAAMQ,eAAsBpB,oBAAW,EAAW,GAAGC,KAAKC,EAAE,kBAAkB;IACnFC,OAAckB,eAAMvB,YAACiB,kBAAyBN,eAAO;MAAEa,OAAOC;IAAY,CAAA,CAAA;IAC1Ef,QAAeD,iBAASH,cAAAA;EAC1B,CAAA,EAAA;EAAI;cAHSgB,SAAAA;AAIf,GA3BiBtB,eAAAA,aAAAA,CAAAA,EAAAA;;",
6
- "names": ["Schema", "TypedObject", "FileType", "TypedObject", "typename", "version", "name", "optional", "String", "type", "cid", "timestamp", "Schema", "FileInfoSchema", "SpaceSchema", "WnfsAction", "Create", "TaggedClass", "meta", "id", "input", "FileInfoSchema", "pick", "pipe", "required", "output", "Struct", "object", "FileType", "UploadAnnotationId", "Symbol", "for", "UploadFileSchema", "file", "instanceOf", "File", "annotations", "Upload", "extend", "space", "SpaceSchema"]
7
- }