@dxos/plugin-wnfs 0.8.4-main.72ec0f3 → 0.8.4-main.765dc60934
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.
- package/LICENSE +102 -5
- package/README.md +2 -2
- package/dist/lib/neutral/FileArticle-B3NF2VKL.mjs +58 -0
- package/dist/lib/neutral/FileArticle-B3NF2VKL.mjs.map +7 -0
- package/dist/lib/neutral/WnfsPlugin.mjs +50 -0
- package/dist/lib/neutral/WnfsPlugin.mjs.map +7 -0
- package/dist/lib/neutral/WnfsPlugin.node.mjs +23 -0
- package/dist/lib/neutral/WnfsPlugin.node.mjs.map +7 -0
- package/dist/lib/{browser/blockstore-2JFU4NBU.mjs → neutral/blockstore-3NLSWC7Z.mjs} +12 -13
- package/dist/lib/neutral/blockstore-3NLSWC7Z.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +19 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/{browser/chunk-D6VTEQIE.mjs → neutral/chunk-7KFJ6LYH.mjs} +43 -18
- package/dist/lib/neutral/chunk-7KFJ6LYH.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/{browser/chunk-OGPGLJCV.mjs → neutral/chunk-LHUHUCBD.mjs} +2 -9
- package/dist/lib/neutral/chunk-LHUHUCBD.mjs.map +7 -0
- package/dist/lib/neutral/chunk-UIZBWELF.mjs +8 -0
- package/dist/lib/neutral/chunk-UIZBWELF.mjs.map +7 -0
- package/dist/lib/neutral/chunk-VWVCHTUK.mjs +125 -0
- package/dist/lib/neutral/chunk-VWVCHTUK.mjs.map +7 -0
- package/dist/lib/neutral/components/index.mjs +63 -0
- package/dist/lib/neutral/components/index.mjs.map +7 -0
- package/dist/lib/neutral/containers/index.mjs +9 -0
- package/dist/lib/neutral/containers/index.mjs.map +7 -0
- package/dist/lib/neutral/create-4ERE5CA4.mjs +23 -0
- package/dist/lib/neutral/create-4ERE5CA4.mjs.map +7 -0
- package/dist/lib/neutral/create-file-RAHDIJVU.mjs +40 -0
- package/dist/lib/neutral/create-file-RAHDIJVU.mjs.map +7 -0
- package/dist/lib/neutral/create-object-7PJC47BB.mjs +33 -0
- package/dist/lib/neutral/create-object-7PJC47BB.mjs.map +7 -0
- package/dist/lib/neutral/file-uploader-WOF3H3FN.mjs +34 -0
- package/dist/lib/neutral/file-uploader-WOF3H3FN.mjs.map +7 -0
- package/dist/lib/neutral/helpers/index.mjs +26 -0
- package/dist/lib/neutral/helpers/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +40 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/{browser/markdown-WYQDCVFQ.mjs → neutral/markdown-I4FYAUCA.mjs} +23 -17
- package/dist/lib/neutral/markdown-I4FYAUCA.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +8 -0
- package/dist/lib/neutral/meta.mjs.map +7 -0
- package/dist/lib/neutral/operation-handler-NPYSIPMR.mjs +13 -0
- package/dist/lib/neutral/operation-handler-NPYSIPMR.mjs.map +7 -0
- package/dist/lib/neutral/operations/index.mjs +8 -0
- package/dist/lib/neutral/operations/index.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +16 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/react-surface-6QHCDYC3.mjs +53 -0
- package/dist/lib/neutral/react-surface-6QHCDYC3.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +30 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +14 -0
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/lib/neutral/upload-VA5CSUEP.mjs +33 -0
- package/dist/lib/neutral/upload-VA5CSUEP.mjs.map +7 -0
- package/dist/types/src/WnfsPlugin.d.ts +3 -1
- package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
- package/dist/types/src/WnfsPlugin.node.d.ts +4 -0
- package/dist/types/src/WnfsPlugin.node.d.ts.map +1 -0
- package/dist/types/src/WnfsPlugin.test.d.ts +2 -0
- package/dist/types/src/WnfsPlugin.test.d.ts.map +1 -0
- package/dist/types/src/blockstore.d.ts.map +1 -1
- package/dist/types/src/capabilities/blockstore.d.ts +3 -2
- package/dist/types/src/capabilities/blockstore.d.ts.map +1 -1
- package/dist/types/src/capabilities/create-object.d.ts +11 -0
- package/dist/types/src/capabilities/create-object.d.ts.map +1 -0
- package/dist/types/src/capabilities/file-uploader.d.ts +4 -2
- package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +13 -6
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/markdown.d.ts +4 -2
- package/dist/types/src/capabilities/markdown.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/FileInput/FileInput.d.ts.map +1 -0
- package/dist/types/src/components/FileInput/index.d.ts +2 -0
- package/dist/types/src/components/FileInput/index.d.ts.map +1 -0
- package/dist/types/src/components/FilePreview/FilePreview.d.ts +12 -0
- package/dist/types/src/components/FilePreview/FilePreview.d.ts.map +1 -0
- package/dist/types/src/components/FilePreview/index.d.ts +2 -0
- package/dist/types/src/components/FilePreview/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/FileArticle/FileArticle.d.ts +7 -0
- package/dist/types/src/containers/FileArticle/FileArticle.d.ts.map +1 -0
- package/dist/types/src/containers/FileArticle/index.d.ts +2 -0
- package/dist/types/src/containers/FileArticle/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +3 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/extensions/image.d.ts +1 -1
- package/dist/types/src/extensions/image.d.ts.map +1 -1
- package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
- package/dist/types/src/helpers/common.d.ts.map +1 -1
- package/dist/types/src/helpers/load.d.ts +1 -1
- package/dist/types/src/helpers/load.d.ts.map +1 -1
- package/dist/types/src/helpers/upload.d.ts +1 -1
- package/dist/types/src/helpers/upload.d.ts.map +1 -1
- package/dist/types/src/helpers/wnfs-url.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/operations/create-file.d.ts +5 -0
- package/dist/types/src/operations/create-file.d.ts.map +1 -0
- package/dist/types/src/operations/create.d.ts +5 -0
- package/dist/types/src/operations/create.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +3 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/upload.d.ts +5 -0
- package/dist/types/src/operations/upload.d.ts.map +1 -0
- package/dist/types/src/plugin.d.ts +4 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +24 -12
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/WnfsCapabilities.d.ts +11 -0
- package/dist/types/src/types/WnfsCapabilities.d.ts.map +1 -0
- package/dist/types/src/types/WnfsFile.d.ts +16 -0
- package/dist/types/src/types/WnfsFile.d.ts.map +1 -0
- package/dist/types/src/types/WnfsOperation.d.ts +38 -0
- package/dist/types/src/types/WnfsOperation.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +3 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +4 -50
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +104 -49
- package/src/WnfsPlugin.node.ts +19 -0
- package/src/WnfsPlugin.test.ts +27 -0
- package/src/WnfsPlugin.tsx +28 -73
- package/src/blockstore.ts +1 -1
- package/src/capabilities/blockstore.ts +14 -10
- package/src/capabilities/create-object.ts +33 -0
- package/src/capabilities/file-uploader.ts +24 -17
- package/src/capabilities/index.ts +11 -8
- package/src/capabilities/markdown.ts +24 -12
- package/src/capabilities/operation-handler.ts +16 -0
- package/src/capabilities/react-surface.tsx +49 -34
- package/src/components/{FileInput.tsx → FileInput/FileInput.tsx} +6 -6
- package/src/components/FileInput/index.ts +5 -0
- package/src/components/FilePreview/FilePreview.tsx +43 -0
- package/src/components/FilePreview/index.ts +5 -0
- package/src/components/index.ts +1 -4
- package/src/{components/FileContainer.tsx → containers/FileArticle/FileArticle.tsx} +14 -16
- package/src/containers/FileArticle/index.ts +5 -0
- package/src/containers/index.ts +7 -0
- package/src/extensions/image.stories.tsx +10 -11
- package/src/extensions/image.tsx +4 -3
- package/src/helpers/load.ts +12 -7
- package/src/helpers/upload.ts +5 -2
- package/src/index.ts +2 -2
- package/src/meta.ts +3 -3
- package/src/operations/create-file.ts +30 -0
- package/src/operations/create.ts +21 -0
- package/src/operations/index.ts +11 -0
- package/src/operations/upload.ts +28 -0
- package/src/plugin.ts +11 -0
- package/src/translations.ts +14 -10
- package/src/types/WnfsCapabilities.ts +18 -0
- package/src/types/WnfsFile.ts +30 -0
- package/src/types/WnfsOperation.ts +44 -0
- package/src/types/index.ts +4 -1
- package/src/types/types.ts +3 -20
- package/dist/lib/browser/FileContainer-LLNI7WXR.mjs +0 -103
- package/dist/lib/browser/FileContainer-LLNI7WXR.mjs.map +0 -7
- package/dist/lib/browser/blockstore-2JFU4NBU.mjs.map +0 -7
- package/dist/lib/browser/chunk-CWMKN2F6.mjs +0 -71
- package/dist/lib/browser/chunk-CWMKN2F6.mjs.map +0 -7
- package/dist/lib/browser/chunk-D6VTEQIE.mjs.map +0 -7
- package/dist/lib/browser/chunk-F4QHZWQD.mjs +0 -16
- package/dist/lib/browser/chunk-F4QHZWQD.mjs.map +0 -7
- package/dist/lib/browser/chunk-OGPGLJCV.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZFPJA5F4.mjs +0 -16
- package/dist/lib/browser/chunk-ZFPJA5F4.mjs.map +0 -7
- package/dist/lib/browser/file-uploader-W6TJLAAK.mjs +0 -30
- package/dist/lib/browser/file-uploader-W6TJLAAK.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -116
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs +0 -48
- package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs.map +0 -7
- package/dist/lib/browser/markdown-WYQDCVFQ.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/react-surface-DMU47U3X.mjs +0 -88
- package/dist/lib/browser/react-surface-DMU47U3X.mjs.map +0 -7
- package/dist/lib/browser/types/index.mjs +0 -10
- package/dist/types/src/capabilities/capabilities.d.ts +0 -12
- package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/components/FileContainer.d.ts +0 -9
- package/dist/types/src/components/FileContainer.d.ts.map +0 -1
- package/dist/types/src/components/FileInput.d.ts.map +0 -1
- package/dist/types/src/components/FilePreview.d.ts +0 -11
- package/dist/types/src/components/FilePreview.d.ts.map +0 -1
- package/dist/types/src/types/File.d.ts +0 -16
- package/dist/types/src/types/File.d.ts.map +0 -1
- package/src/capabilities/capabilities.ts +0 -18
- package/src/capabilities/intent-resolver.ts +0 -32
- package/src/components/FilePreview.tsx +0 -23
- package/src/types/File.ts +0 -24
- /package/dist/lib/{browser/types/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/types/src/components/{FileInput.d.ts → FileInput/FileInput.d.ts} +0 -0
|
@@ -2,44 +2,59 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
5
6
|
import type * as Schema from 'effect/Schema';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
6
8
|
import React, { useCallback } from 'react';
|
|
7
9
|
|
|
8
|
-
import { Capabilities,
|
|
9
|
-
import {
|
|
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
|
|
14
|
+
import { type FormFieldComponentProps } from '@dxos/react-ui-form';
|
|
12
15
|
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { WnfsAction, WnfsFile } from '
|
|
16
|
+
import { FileInput } from '#components';
|
|
17
|
+
import { FileArticle } from '#containers';
|
|
18
|
+
import { WnfsAction, WnfsFile } from '#types';
|
|
16
19
|
|
|
17
|
-
export default () =>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
20
|
+
export default Capability.makeModule(() =>
|
|
21
|
+
Effect.succeed(
|
|
22
|
+
Capability.contributes(Capabilities.ReactSurface, [
|
|
23
|
+
Surface.create({
|
|
24
|
+
id: 'article',
|
|
25
|
+
// TODO(wittjosiah): Split into multiple surfaces if this filter proves too strict for non-article roles.
|
|
26
|
+
filter: AppSurface.oneOf(
|
|
27
|
+
AppSurface.object(AppSurface.Article, WnfsFile.WnfsFile),
|
|
28
|
+
AppSurface.object(AppSurface.Section, WnfsFile.WnfsFile),
|
|
29
|
+
AppSurface.object(AppSurface.Slide, WnfsFile.WnfsFile),
|
|
30
|
+
),
|
|
31
|
+
component: ({ data, role }) => <FileArticle role={role} subject={data.subject} />,
|
|
32
|
+
}),
|
|
33
|
+
Surface.create({
|
|
34
|
+
id: 'create-form',
|
|
35
|
+
role: 'form-input',
|
|
36
|
+
filter: (data): data is { prop: string; schema: Schema.Schema.Any; fieldPropertyAst?: SchemaAST.AST } => {
|
|
37
|
+
const annotation = findAnnotation<boolean>(
|
|
38
|
+
(data.schema as Schema.Schema.All).ast,
|
|
39
|
+
WnfsAction.UploadAnnotationId,
|
|
40
|
+
);
|
|
41
|
+
return !!annotation;
|
|
42
|
+
},
|
|
43
|
+
component: ({ data: { schema, fieldPropertyAst }, ...props }) => {
|
|
44
|
+
const ast = fieldPropertyAst;
|
|
45
|
+
if (!ast) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
41
48
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
const inputProps = { ...props, type: ast } as unknown as FormFieldComponentProps;
|
|
50
|
+
const handleChange = useCallback(
|
|
51
|
+
(file: File) => inputProps.onValueChange?.(ast, file),
|
|
52
|
+
[ast, inputProps.onValueChange],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return <FileInput schema={schema} onChange={handleChange} />;
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
]),
|
|
59
|
+
),
|
|
60
|
+
);
|
|
@@ -8,10 +8,10 @@ import { useDropzone } from 'react-dropzone';
|
|
|
8
8
|
|
|
9
9
|
import { findAnnotation } from '@dxos/effect';
|
|
10
10
|
import { useTranslation } from '@dxos/react-ui';
|
|
11
|
-
import { mx } from '@dxos/
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
12
|
|
|
13
|
-
import { meta } from '
|
|
14
|
-
import { WnfsAction } from '
|
|
13
|
+
import { meta } from '#meta';
|
|
14
|
+
import { WnfsAction } from '#types';
|
|
15
15
|
|
|
16
16
|
export type FileInputProps = {
|
|
17
17
|
schema: Schema.Schema.Any;
|
|
@@ -36,12 +36,12 @@ export const FileInput = ({ schema, onChange }: FileInputProps) => {
|
|
|
36
36
|
className={mx(
|
|
37
37
|
'flex flex-col items-center p-8 border border-separator',
|
|
38
38
|
isFocused && 'focus-ring',
|
|
39
|
-
isDragAccept && 'bg-attention',
|
|
40
|
-
isDragReject && 'border-
|
|
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
|
|
44
|
+
{acceptedFiles[0] ? <p>{acceptedFiles[0].name}</p> : <p>{t('file-input.placeholder')}</p>}
|
|
45
45
|
</div>
|
|
46
46
|
);
|
|
47
47
|
};
|
|
@@ -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
|
+
);
|
package/src/components/index.ts
CHANGED
|
@@ -4,24 +4,20 @@
|
|
|
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/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 {
|
|
14
|
-
import {
|
|
15
|
-
import { type WnfsFile } from '../types';
|
|
13
|
+
import { FilePreview } from '#components';
|
|
14
|
+
import { WnfsCapabilities, type WnfsFile } from '#types';
|
|
16
15
|
|
|
17
|
-
import {
|
|
16
|
+
import { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../../helpers';
|
|
18
17
|
|
|
19
|
-
export type
|
|
20
|
-
role: string;
|
|
21
|
-
file: WnfsFile.File;
|
|
22
|
-
};
|
|
18
|
+
export type FileArticleProps = AppSurface.ObjectArticleProps<WnfsFile.WnfsFile>;
|
|
23
19
|
|
|
24
|
-
export const
|
|
20
|
+
export const FileArticle = ({ role, subject: file }: FileArticleProps) => {
|
|
25
21
|
const blockstore = useCapability(WnfsCapabilities.Blockstore);
|
|
26
22
|
const instances = useCapability(WnfsCapabilities.Instances);
|
|
27
23
|
const [blobUrl, setBlobUrl] = useState<string>();
|
|
@@ -50,10 +46,12 @@ export const FileContainer = ({ file }: FileContainerProps) => {
|
|
|
50
46
|
}
|
|
51
47
|
|
|
52
48
|
return (
|
|
53
|
-
<
|
|
54
|
-
<
|
|
55
|
-
|
|
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
|
|
|
59
|
-
export default
|
|
57
|
+
export default FileArticle;
|
|
@@ -6,10 +6,11 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import type { Blockstore } from 'interface-blockstore';
|
|
7
7
|
import React, { type ChangeEvent, useEffect, useState } from 'react';
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { random } from '@dxos/random';
|
|
10
|
+
import { useSpaces } from '@dxos/react-client/echo';
|
|
11
11
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
12
12
|
import { useThemeContext } from '@dxos/react-ui';
|
|
13
|
+
import { useTextEditor } from '@dxos/react-ui-editor';
|
|
13
14
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
15
|
import {
|
|
15
16
|
createBasicExtensions,
|
|
@@ -17,21 +18,19 @@ import {
|
|
|
17
18
|
createThemeExtensions,
|
|
18
19
|
decorateMarkdown,
|
|
19
20
|
processEditorPayload,
|
|
20
|
-
|
|
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
|
-
|
|
29
|
-
const initialValue =
|
|
27
|
+
random.seed(1);
|
|
28
|
+
const initialValue = random.lorem.paragraphs(100);
|
|
30
29
|
const instances = {};
|
|
31
30
|
|
|
32
31
|
const DefaultStory = () => {
|
|
33
32
|
const { themeMode } = useThemeContext();
|
|
34
|
-
const space =
|
|
33
|
+
const [space] = useSpaces();
|
|
35
34
|
const [blockstore, setBlockstore] = useState<Blockstore>();
|
|
36
35
|
|
|
37
36
|
useEffect(() => {
|
|
@@ -86,15 +85,15 @@ const DefaultStory = () => {
|
|
|
86
85
|
<div className='mb-2'>
|
|
87
86
|
<input type='file' accept='image/*' onChange={onFileChange} />
|
|
88
87
|
</div>
|
|
89
|
-
<div className='
|
|
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;
|
package/src/extensions/image.tsx
CHANGED
|
@@ -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/
|
|
15
|
-
import { defaultTx } from '@dxos/
|
|
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 '
|
|
18
|
+
import { type WnfsCapabilities } from '#types';
|
|
19
|
+
|
|
19
20
|
import { getBlobUrl, getPathFromUrl, loadWnfs } from '../helpers';
|
|
20
21
|
|
|
21
22
|
const WAIT_UNTIL_LOADER = 1500;
|
package/src/helpers/load.ts
CHANGED
|
@@ -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 '
|
|
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
|
-
|
|
33
|
-
|
|
33
|
+
Obj.update(space.properties, (obj) => {
|
|
34
|
+
delete obj['wnfs_access_key'];
|
|
35
|
+
delete obj['wnfs_private_forest_cid'];
|
|
36
|
+
});
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
const cacheKey = space.properties.wnfs?.privateForestCid;
|
|
@@ -65,10 +68,12 @@ const createWnfsDir = async (blockstore: Blockstore, space: Space) => {
|
|
|
65
68
|
|
|
66
69
|
const cidBytes = await newForest.store(wnfsStore);
|
|
67
70
|
|
|
68
|
-
space.properties
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
Obj.update(space.properties, (obj) => {
|
|
72
|
+
obj.wnfs = {
|
|
73
|
+
accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), 'base64'),
|
|
74
|
+
privateForestCid: CID.decode(cidBytes).toString(),
|
|
75
|
+
};
|
|
76
|
+
});
|
|
72
77
|
|
|
73
78
|
return {
|
|
74
79
|
directory: dir,
|
package/src/helpers/upload.ts
CHANGED
|
@@ -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 '
|
|
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
|
|
50
|
+
Obj.update(space.properties, (obj) => {
|
|
51
|
+
obj.wnfs.privateForestCid = CID.decode(cidBytes).toString();
|
|
52
|
+
});
|
|
50
53
|
|
|
51
54
|
// Generate `wnfs://` URL & return the info.
|
|
52
55
|
const info = {
|
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
6
|
import { trim } from '@dxos/util';
|
|
7
7
|
|
|
8
|
-
export const meta:
|
|
9
|
-
id: 'dxos.
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
9
|
+
id: 'org.dxos.plugin.wnfs',
|
|
10
10
|
name: 'WNFS',
|
|
11
11
|
description: trim`
|
|
12
12
|
Decentralized file storage using the Web Native File System protocol.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Capability } from '@dxos/app-framework';
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
import { invariant } from '@dxos/invariant';
|
|
10
|
+
import { ClientCapabilities } from '@dxos/plugin-client';
|
|
11
|
+
|
|
12
|
+
import { upload } from '../helpers';
|
|
13
|
+
import { WnfsCapabilities, WnfsFile, WnfsOperation } from '../types';
|
|
14
|
+
|
|
15
|
+
const handler: Operation.WithHandler<typeof WnfsOperation.CreateFile> = WnfsOperation.CreateFile.pipe(
|
|
16
|
+
Operation.withHandler(
|
|
17
|
+
Effect.fnUntraced(function* ({ file, db }) {
|
|
18
|
+
const client = yield* Capability.get(ClientCapabilities.Client);
|
|
19
|
+
const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
|
|
20
|
+
const space = client.spaces.get(db.spaceId);
|
|
21
|
+
invariant(space, 'Space not found');
|
|
22
|
+
const info = yield* Effect.promise(() => upload({ file, blockstore, space }));
|
|
23
|
+
return {
|
|
24
|
+
object: WnfsFile.make({ name: info.name, type: info.type, cid: info.cid }),
|
|
25
|
+
};
|
|
26
|
+
}),
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export default handler;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Operation } from '@dxos/compute';
|
|
8
|
+
|
|
9
|
+
import { WnfsFile, WnfsOperation } from '../types';
|
|
10
|
+
|
|
11
|
+
const handler: Operation.WithHandler<typeof WnfsOperation.Create> = WnfsOperation.Create.pipe(
|
|
12
|
+
Operation.withHandler(
|
|
13
|
+
Effect.fnUntraced(function* ({ name, type, cid }) {
|
|
14
|
+
return {
|
|
15
|
+
object: WnfsFile.make({ name, type, cid }),
|
|
16
|
+
};
|
|
17
|
+
}),
|
|
18
|
+
),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export default handler;
|
|
@@ -0,0 +1,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
package/src/translations.ts
CHANGED
|
@@ -4,22 +4,26 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
|
-
import { meta } from '
|
|
8
|
-
import { WnfsFile } from '
|
|
7
|
+
import { meta } from '#meta';
|
|
8
|
+
import { WnfsFile } from '#types';
|
|
9
9
|
|
|
10
10
|
export const translations = [
|
|
11
11
|
{
|
|
12
12
|
'en-US': {
|
|
13
|
-
[WnfsFile.
|
|
14
|
-
'typename
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
13
|
+
[WnfsFile.WnfsFile.typename]: {
|
|
14
|
+
'typename.label': 'File',
|
|
15
|
+
'typename.label_zero': 'Files',
|
|
16
|
+
'typename.label_one': 'File',
|
|
17
|
+
'typename.label_other': 'Files',
|
|
18
|
+
'object-name.placeholder': 'New file',
|
|
19
|
+
'add-object.label': 'Add file',
|
|
20
|
+
'rename-object.label': 'Rename file',
|
|
21
|
+
'delete-object.label': 'Delete file',
|
|
22
|
+
'object-deleted.label': 'File deleted',
|
|
18
23
|
},
|
|
19
24
|
[meta.id]: {
|
|
20
|
-
'plugin
|
|
21
|
-
'
|
|
22
|
-
'file input placeholder': 'Drop a file here, or click to select a file',
|
|
25
|
+
'plugin.name': 'Files',
|
|
26
|
+
'file-input.placeholder': 'Drop a file here, or click to select a file',
|
|
23
27
|
},
|
|
24
28
|
},
|
|
25
29
|
},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
import { type Blockstore as BlockstoreInterface } from 'interface-blockstore';
|
|
8
|
+
import { type PrivateDirectory, type PrivateForest } from 'wnfs';
|
|
9
|
+
|
|
10
|
+
import { Capability } from '@dxos/app-framework';
|
|
11
|
+
import { type SpaceId } from '@dxos/keys';
|
|
12
|
+
|
|
13
|
+
import { meta } from '#meta';
|
|
14
|
+
|
|
15
|
+
export const Blockstore = Capability.make<BlockstoreInterface>(`${meta.id}.capability.blockstore`);
|
|
16
|
+
|
|
17
|
+
export type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;
|
|
18
|
+
export const Instances = Capability.make<Instances>(`${meta.id}.capability.instances`);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
|
|
9
|
+
import { Annotation, Obj, Type } from '@dxos/echo';
|
|
10
|
+
import { FormInputAnnotation } from '@dxos/echo/internal';
|
|
11
|
+
|
|
12
|
+
export const WnfsFile = Schema.Struct({
|
|
13
|
+
name: Schema.String.pipe(Schema.optional),
|
|
14
|
+
type: Schema.String.pipe(FormInputAnnotation.set(false)),
|
|
15
|
+
cid: Schema.String.pipe(FormInputAnnotation.set(false)),
|
|
16
|
+
timestamp: Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
17
|
+
}).pipe(
|
|
18
|
+
Type.object({
|
|
19
|
+
typename: 'org.dxos.type.file',
|
|
20
|
+
version: '0.1.0',
|
|
21
|
+
}),
|
|
22
|
+
Annotation.IconAnnotation.set({
|
|
23
|
+
icon: 'ph--file--regular',
|
|
24
|
+
hue: 'teal',
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export type WnfsFile = Schema.Schema.Type<typeof WnfsFile>;
|
|
29
|
+
|
|
30
|
+
export const make = (props: Obj.MakeProps<typeof WnfsFile>) => Obj.make(WnfsFile, props);
|