@dxos/plugin-wnfs 0.8.4-main.f5c0578 → 0.8.4-main.fcc0d83b33
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/README.md +1 -1
- package/dist/lib/browser/chunk-4D4K5JCC.mjs +66 -0
- package/dist/lib/browser/chunk-4D4K5JCC.mjs.map +7 -0
- package/dist/lib/browser/{chunk-D6VTEQIE.mjs → chunk-7KFJ6LYH.mjs} +43 -18
- package/dist/lib/browser/chunk-7KFJ6LYH.mjs.map +7 -0
- package/dist/lib/browser/chunk-DK62NQ5T.mjs +71 -0
- package/dist/lib/browser/chunk-DK62NQ5T.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/browser/create-QRLX4IMZ.mjs +25 -0
- package/dist/lib/browser/create-QRLX4IMZ.mjs.map +7 -0
- package/dist/lib/browser/create-file-INAT56PX.mjs +42 -0
- package/dist/lib/browser/create-file-INAT56PX.mjs.map +7 -0
- package/dist/lib/browser/helpers/index.mjs +26 -0
- package/dist/lib/browser/helpers/index.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +79 -105
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operations/index.mjs +14 -0
- package/dist/lib/browser/operations/index.mjs.map +7 -0
- package/dist/lib/browser/translations.mjs +30 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +8 -6
- package/dist/lib/browser/upload-ZQI66T4Y.mjs +35 -0
- package/dist/lib/browser/upload-ZQI66T4Y.mjs.map +7 -0
- package/dist/types/src/WnfsPlugin.d.ts +2 -1
- package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
- 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/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 +7 -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.d.ts → FileInput/FileInput.d.ts} +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/FileContainer/FileContainer.d.ts +7 -0
- package/dist/types/src/containers/FileContainer/FileContainer.d.ts.map +1 -0
- package/dist/types/src/containers/FileContainer/index.d.ts +2 -0
- package/dist/types/src/containers/FileContainer/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 +5 -4
- 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 +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -3
- 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/definitions.d.ts +38 -0
- package/dist/types/src/operations/definitions.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +4 -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/translations.d.ts +24 -12
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/File.d.ts +16 -0
- package/dist/types/src/types/File.d.ts.map +1 -0
- package/dist/types/src/{capabilities → types}/capabilities.d.ts +3 -2
- package/dist/types/src/types/capabilities.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +4 -46
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +71 -47
- package/src/WnfsPlugin.tsx +66 -85
- package/src/blockstore.ts +1 -1
- package/src/capabilities/blockstore.ts +15 -11
- package/src/capabilities/file-uploader.ts +25 -15
- package/src/capabilities/index.ts +10 -8
- package/src/capabilities/markdown.ts +24 -12
- package/src/capabilities/operation-handler.ts +16 -0
- package/src/capabilities/react-surface.tsx +50 -35
- package/src/components/{FileInput.tsx → FileInput/FileInput.tsx} +8 -8
- 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/containers/FileContainer/FileContainer.tsx +57 -0
- package/src/containers/FileContainer/index.ts +5 -0
- package/src/containers/index.ts +7 -0
- package/src/extensions/image.stories.tsx +21 -19
- package/src/extensions/image.tsx +9 -8
- package/src/helpers/load.ts +12 -7
- package/src/helpers/upload.ts +5 -2
- package/src/index.ts +1 -1
- package/src/meta.ts +9 -6
- package/src/operations/create-file.ts +31 -0
- package/src/operations/create.ts +22 -0
- package/src/operations/definitions.ts +41 -0
- package/src/operations/index.ts +13 -0
- package/src/operations/upload.ts +29 -0
- package/src/translations.ts +14 -10
- package/src/types/File.ts +28 -0
- package/src/{capabilities → types}/capabilities.ts +4 -4
- package/src/types/index.ts +2 -1
- package/src/types/types.ts +3 -20
- package/dist/lib/browser/FileContainer-LTKYOYSO.mjs +0 -105
- package/dist/lib/browser/FileContainer-LTKYOYSO.mjs.map +0 -7
- package/dist/lib/browser/blockstore-PSYZCC2O.mjs +0 -191
- package/dist/lib/browser/blockstore-PSYZCC2O.mjs.map +0 -7
- package/dist/lib/browser/chunk-CW4BENRQ.mjs +0 -64
- package/dist/lib/browser/chunk-CW4BENRQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-D6VTEQIE.mjs.map +0 -7
- package/dist/lib/browser/chunk-KZANQHJY.mjs +0 -16
- package/dist/lib/browser/chunk-KZANQHJY.mjs.map +0 -7
- package/dist/lib/browser/chunk-VDDGZWAY.mjs +0 -15
- package/dist/lib/browser/chunk-VDDGZWAY.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZMH2OULB.mjs +0 -16
- package/dist/lib/browser/chunk-ZMH2OULB.mjs.map +0 -7
- package/dist/lib/browser/file-uploader-YRZPRETS.mjs +0 -29
- package/dist/lib/browser/file-uploader-YRZPRETS.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-CKGJNE6P.mjs +0 -49
- package/dist/lib/browser/intent-resolver-CKGJNE6P.mjs.map +0 -7
- package/dist/lib/browser/markdown-RAGCVYGE.mjs +0 -198
- package/dist/lib/browser/markdown-RAGCVYGE.mjs.map +0 -7
- package/dist/lib/browser/react-surface-HGWZDLP2.mjs +0 -88
- package/dist/lib/browser/react-surface-HGWZDLP2.mjs.map +0 -7
- 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/intent-resolver.ts +0 -33
- package/src/components/FileContainer.tsx +0 -52
- package/src/components/FilePreview.tsx +0 -23
- package/src/types/file.ts +0 -17
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
6
|
import React, { useCallback } from 'react';
|
|
7
7
|
import { useDropzone } from 'react-dropzone';
|
|
8
8
|
|
|
9
9
|
import { findAnnotation } from '@dxos/effect';
|
|
10
10
|
import { useTranslation } from '@dxos/react-ui';
|
|
11
|
-
import { mx } from '@dxos/
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
12
|
|
|
13
|
-
import {
|
|
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;
|
|
@@ -19,7 +19,7 @@ export type FileInputProps = {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export const FileInput = ({ schema, onChange }: FileInputProps) => {
|
|
22
|
-
const { t } = useTranslation(
|
|
22
|
+
const { t } = useTranslation(meta.id);
|
|
23
23
|
const accept = findAnnotation<Record<string, string[]>>(schema.ast, WnfsAction.UploadAnnotationId);
|
|
24
24
|
|
|
25
25
|
const onDropAccepted = useCallback((files: File[]) => onChange?.(files[0]), [onChange]);
|
|
@@ -36,12 +36,12 @@ export const FileInput = ({ schema, onChange }: FileInputProps) => {
|
|
|
36
36
|
className={mx(
|
|
37
37
|
'flex flex-col items-center p-8 border border-separator',
|
|
38
38
|
isFocused && 'focus-ring',
|
|
39
|
-
isDragAccept && 'bg-attention',
|
|
40
|
-
isDragReject && 'border-
|
|
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
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useCapability } from '@dxos/app-framework/ui';
|
|
8
|
+
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
9
|
+
import { invariant } from '@dxos/invariant';
|
|
10
|
+
import { getSpace } from '@dxos/react-client/echo';
|
|
11
|
+
import { Panel, useAsyncEffect } from '@dxos/react-ui';
|
|
12
|
+
|
|
13
|
+
import { FilePreview } from '#components';
|
|
14
|
+
import { WnfsCapabilities, type WnfsFile } from '#types';
|
|
15
|
+
|
|
16
|
+
import { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../../helpers';
|
|
17
|
+
|
|
18
|
+
export type FileContainerProps = AppSurface.ObjectArticleProps<WnfsFile.File>;
|
|
19
|
+
|
|
20
|
+
export const FileContainer = ({ role, subject: file }: FileContainerProps) => {
|
|
21
|
+
const blockstore = useCapability(WnfsCapabilities.Blockstore);
|
|
22
|
+
const instances = useCapability(WnfsCapabilities.Instances);
|
|
23
|
+
const [blobUrl, setBlobUrl] = useState<string>();
|
|
24
|
+
|
|
25
|
+
useAsyncEffect(async () => {
|
|
26
|
+
const space = getSpace(file);
|
|
27
|
+
invariant(space);
|
|
28
|
+
const { directory, forest } = await loadWnfs({
|
|
29
|
+
blockstore,
|
|
30
|
+
instances,
|
|
31
|
+
space,
|
|
32
|
+
});
|
|
33
|
+
const path = filePath(file.cid.toString(), space);
|
|
34
|
+
const url = await getBlobUrl({
|
|
35
|
+
wnfsUrl: wnfsUrl(path),
|
|
36
|
+
blockstore,
|
|
37
|
+
directory,
|
|
38
|
+
forest,
|
|
39
|
+
type: file.type,
|
|
40
|
+
});
|
|
41
|
+
setBlobUrl(url);
|
|
42
|
+
}, [file]);
|
|
43
|
+
|
|
44
|
+
if (!blobUrl) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Panel.Root role={role} className='dx-document'>
|
|
50
|
+
<Panel.Content asChild>
|
|
51
|
+
<FilePreview type={file.type} url={blobUrl} />
|
|
52
|
+
</Panel.Content>
|
|
53
|
+
</Panel.Root>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default FileContainer;
|
|
@@ -2,37 +2,35 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
6
|
import type { Blockstore } from 'interface-blockstore';
|
|
8
7
|
import React, { type ChangeEvent, useEffect, useState } from 'react';
|
|
9
8
|
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { random } from '@dxos/random';
|
|
10
|
+
import { useSpaces } from '@dxos/react-client/echo';
|
|
12
11
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
13
12
|
import { useThemeContext } from '@dxos/react-ui';
|
|
13
|
+
import { useTextEditor } from '@dxos/react-ui-editor';
|
|
14
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
15
|
import {
|
|
15
16
|
createBasicExtensions,
|
|
16
17
|
createMarkdownExtensions,
|
|
17
18
|
createThemeExtensions,
|
|
18
19
|
decorateMarkdown,
|
|
19
20
|
processEditorPayload,
|
|
20
|
-
|
|
21
|
-
} from '@dxos/react-ui-editor';
|
|
22
|
-
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
21
|
+
} from '@dxos/ui-editor';
|
|
23
22
|
|
|
24
23
|
import { create as createBlockstore } from '../blockstore';
|
|
25
24
|
import { upload } from '../helpers';
|
|
26
|
-
|
|
27
25
|
import { image } from './image';
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
const initialValue =
|
|
27
|
+
random.seed(1);
|
|
28
|
+
const initialValue = random.lorem.paragraphs(100);
|
|
31
29
|
const instances = {};
|
|
32
30
|
|
|
33
|
-
const
|
|
31
|
+
const DefaultStory = () => {
|
|
34
32
|
const { themeMode } = useThemeContext();
|
|
35
|
-
const space =
|
|
33
|
+
const [space] = useSpaces();
|
|
36
34
|
const [blockstore, setBlockstore] = useState<Blockstore>();
|
|
37
35
|
|
|
38
36
|
useEffect(() => {
|
|
@@ -55,7 +53,7 @@ const Story = () => {
|
|
|
55
53
|
initialValue,
|
|
56
54
|
extensions: [
|
|
57
55
|
createBasicExtensions(),
|
|
58
|
-
createMarkdownExtensions(
|
|
56
|
+
createMarkdownExtensions(),
|
|
59
57
|
createThemeExtensions({ themeMode, syntaxHighlighting: true }),
|
|
60
58
|
blockstore && space ? [image({ blockstore, instances, space })] : [],
|
|
61
59
|
decorateMarkdown(),
|
|
@@ -92,10 +90,14 @@ const Story = () => {
|
|
|
92
90
|
);
|
|
93
91
|
};
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
title: 'plugins/plugin-wnfs/image',
|
|
97
|
-
render:
|
|
98
|
-
decorators: [withClientProvider({ createIdentity: true, createSpace: true })
|
|
99
|
-
}
|
|
93
|
+
const meta = {
|
|
94
|
+
title: 'plugins/plugin-wnfs/extensions/image',
|
|
95
|
+
render: DefaultStory,
|
|
96
|
+
decorators: [withTheme(), withClientProvider({ createIdentity: true, createSpace: true })],
|
|
97
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
98
|
+
|
|
99
|
+
export default meta;
|
|
100
|
+
|
|
101
|
+
type Story = StoryObj<typeof meta>;
|
|
100
102
|
|
|
101
|
-
export const Default = {};
|
|
103
|
+
export const Default: Story = {};
|
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;
|
|
@@ -80,16 +81,16 @@ export const image = (options: ImageOptions): Extension[] => {
|
|
|
80
81
|
};
|
|
81
82
|
|
|
82
83
|
const buildDecorations = ({
|
|
84
|
+
state,
|
|
83
85
|
from,
|
|
84
86
|
to,
|
|
85
|
-
state,
|
|
86
87
|
blobUrlCache,
|
|
87
88
|
preload,
|
|
88
89
|
options: { blockstore, instances, space },
|
|
89
90
|
}: {
|
|
91
|
+
state: EditorState;
|
|
90
92
|
from: number;
|
|
91
93
|
to: number;
|
|
92
|
-
state: EditorState;
|
|
93
94
|
blobUrlCache: Record<string, string>;
|
|
94
95
|
preload: (url: string) => void;
|
|
95
96
|
options: ImageOptions;
|
|
@@ -165,11 +166,11 @@ class WnfsImageWidget extends WidgetType {
|
|
|
165
166
|
super();
|
|
166
167
|
}
|
|
167
168
|
|
|
168
|
-
override eq(other: this)
|
|
169
|
-
return this._wnfsUrl ===
|
|
169
|
+
override eq(other: this) {
|
|
170
|
+
return this._wnfsUrl === other._wnfsUrl;
|
|
170
171
|
}
|
|
171
172
|
|
|
172
|
-
override toDOM(view: EditorView)
|
|
173
|
+
override toDOM(view: EditorView) {
|
|
173
174
|
if (typeof this._url === 'string') {
|
|
174
175
|
return createImg(view, this._url);
|
|
175
176
|
}
|
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,14 +2,17 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
6
7
|
|
|
7
|
-
export const
|
|
8
|
-
|
|
9
|
-
export const meta: PluginMeta = {
|
|
10
|
-
id: WNFS_PLUGIN,
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
9
|
+
id: 'org.dxos.plugin.wnfs',
|
|
11
10
|
name: 'WNFS',
|
|
12
|
-
description:
|
|
11
|
+
description: trim`
|
|
12
|
+
Decentralized file storage using the Web Native File System protocol.
|
|
13
|
+
Store and sync files with end-to-end encryption across devices without central servers.
|
|
14
|
+
`,
|
|
13
15
|
icon: 'ph--file-cloud--regular',
|
|
16
|
+
iconHue: 'teal',
|
|
14
17
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',
|
|
15
18
|
};
|
|
@@ -0,0 +1,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 { Operation } from '@dxos/compute';
|
|
9
|
+
import { invariant } from '@dxos/invariant';
|
|
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/compute';
|
|
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 { Operation } from '@dxos/compute';
|
|
10
|
+
import { Database } from '@dxos/echo';
|
|
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/compute';
|
|
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 { Operation } from '@dxos/compute';
|
|
9
|
+
import { invariant } from '@dxos/invariant';
|
|
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;
|
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 {
|
|
7
|
+
import { meta } from '#meta';
|
|
8
|
+
import { WnfsFile } from '#types';
|
|
9
9
|
|
|
10
10
|
export const translations = [
|
|
11
11
|
{
|
|
12
12
|
'en-US': {
|
|
13
|
-
[
|
|
14
|
-
'typename
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
13
|
+
[WnfsFile.File.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,28 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { Annotation, Obj, Type } from '@dxos/echo';
|
|
8
|
+
import { FormInputAnnotation } from '@dxos/echo/internal';
|
|
9
|
+
|
|
10
|
+
export const File = Schema.Struct({
|
|
11
|
+
name: Schema.String.pipe(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
|
+
}).pipe(
|
|
16
|
+
Type.object({
|
|
17
|
+
typename: 'org.dxos.type.file',
|
|
18
|
+
version: '0.1.0',
|
|
19
|
+
}),
|
|
20
|
+
Annotation.IconAnnotation.set({
|
|
21
|
+
icon: 'ph--file--regular',
|
|
22
|
+
hue: 'teal',
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export type File = Schema.Schema.Type<typeof File>;
|
|
27
|
+
|
|
28
|
+
export const make = (props: Obj.MakeProps<typeof File>) => Obj.make(File, props);
|
|
@@ -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 {
|
|
8
|
+
import { Capability } from '@dxos/app-framework';
|
|
9
9
|
import { type SpaceId } from '@dxos/keys';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { meta } from '#meta';
|
|
12
12
|
|
|
13
13
|
export namespace WnfsCapabilities {
|
|
14
|
-
export const 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 =
|
|
17
|
+
export const Instances = Capability.make<Instances>(`${meta.id}.capability.instances`);
|
|
18
18
|
}
|