@dxos/plugin-wnfs 0.8.3 → 0.8.4-main.1da679c
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/dist/lib/browser/{FileContainer-7YOCEQ6P.mjs → FileContainer-CNZDVRG5.mjs} +38 -41
- package/dist/lib/browser/FileContainer-CNZDVRG5.mjs.map +7 -0
- package/dist/lib/browser/blockstore-AICVJ7HY.mjs +273 -0
- package/dist/lib/browser/blockstore-AICVJ7HY.mjs.map +7 -0
- package/dist/lib/browser/chunk-4XHHV7ZE.mjs +16 -0
- package/dist/lib/browser/{chunk-SCL6PT4P.mjs → chunk-CW4BENRQ.mjs} +4 -4
- package/dist/lib/browser/{chunk-SCL6PT4P.mjs.map → chunk-CW4BENRQ.mjs.map} +2 -2
- package/dist/lib/browser/{chunk-YYAW4U6J.mjs → chunk-D6VTEQIE.mjs} +8 -8
- package/dist/lib/browser/{chunk-YYAW4U6J.mjs.map → chunk-D6VTEQIE.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-DL7BBH57.mjs → chunk-KZANQHJY.mjs} +3 -3
- package/dist/lib/browser/{chunk-PHTWWADN.mjs → chunk-VDDGZWAY.mjs} +2 -2
- package/dist/lib/browser/{file-uploader-RHINBPDQ.mjs → file-uploader-RXUX4WWK.mjs} +6 -6
- package/dist/lib/browser/{file-uploader-RHINBPDQ.mjs.map → file-uploader-RXUX4WWK.mjs.map} +2 -2
- package/dist/lib/browser/index.mjs +13 -11
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-JDRRPIZC.mjs → intent-resolver-SJHCR77B.mjs} +9 -9
- package/dist/lib/browser/intent-resolver-SJHCR77B.mjs.map +7 -0
- package/dist/lib/browser/{markdown-BWBHUHHH.mjs → markdown-R7FKWIPJ.mjs} +26 -13
- package/dist/lib/browser/markdown-R7FKWIPJ.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-6GM4J4YG.mjs → react-surface-UOBYZYX5.mjs} +12 -12
- package/dist/lib/browser/{react-surface-6GM4J4YG.mjs.map → react-surface-UOBYZYX5.mjs.map} +3 -3
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/types/src/capabilities/blockstore.d.ts +1 -1
- package/dist/types/src/capabilities/blockstore.d.ts.map +1 -1
- package/dist/types/src/capabilities/file-uploader.d.ts +1 -1
- package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +5 -5
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/markdown.d.ts +1 -1
- package/dist/types/src/capabilities/markdown.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/FileContainer.d.ts +4 -3
- package/dist/types/src/components/FileContainer.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -4
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/extensions/image.stories.d.ts +5 -3
- package/dist/types/src/extensions/image.stories.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.map +1 -1
- package/dist/types/src/translations.d.ts +13 -11
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +30 -30
- package/src/WnfsPlugin.tsx +1 -1
- package/src/blockstore.ts +2 -2
- package/src/capabilities/blockstore.ts +3 -2
- package/src/capabilities/file-uploader.ts +1 -1
- package/src/capabilities/intent-resolver.ts +3 -2
- package/src/capabilities/markdown.ts +3 -2
- package/src/capabilities/react-surface.tsx +1 -1
- package/src/components/FileContainer.tsx +18 -15
- package/src/extensions/image.stories.tsx +14 -8
- package/src/extensions/image.tsx +3 -3
- package/src/helpers/load.ts +3 -2
- package/src/helpers/upload.ts +2 -1
- package/src/translations.ts +8 -4
- package/src/types/types.ts +2 -1
- package/dist/lib/browser/FileContainer-7YOCEQ6P.mjs.map +0 -7
- package/dist/lib/browser/blockstore-UT7233RJ.mjs +0 -191
- package/dist/lib/browser/blockstore-UT7233RJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-WJVYRUYQ.mjs +0 -16
- package/dist/lib/browser/intent-resolver-JDRRPIZC.mjs.map +0 -7
- package/dist/lib/browser/markdown-BWBHUHHH.mjs.map +0 -7
- /package/dist/lib/browser/{chunk-WJVYRUYQ.mjs.map → chunk-4XHHV7ZE.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-DL7BBH57.mjs.map → chunk-KZANQHJY.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-PHTWWADN.mjs.map → chunk-VDDGZWAY.mjs.map} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-wnfs",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.1da679c",
|
|
4
4
|
"description": "WNFS file management plugin",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
"type": "module",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
+
"source": "./src/index.ts",
|
|
12
13
|
"types": "./dist/types/src/index.d.ts",
|
|
13
14
|
"browser": "./dist/lib/browser/index.mjs"
|
|
14
15
|
},
|
|
15
16
|
"./types": {
|
|
17
|
+
"source": "./src/types/index.ts",
|
|
16
18
|
"types": "./dist/types/src/types/index.d.ts",
|
|
17
19
|
"browser": "./dist/lib/browser/types/index.mjs"
|
|
18
20
|
}
|
|
@@ -30,15 +32,15 @@
|
|
|
30
32
|
"src"
|
|
31
33
|
],
|
|
32
34
|
"dependencies": {
|
|
33
|
-
"@codemirror/language": "^6.
|
|
34
|
-
"@codemirror/state": "^6.
|
|
35
|
-
"@codemirror/view": "^6.
|
|
35
|
+
"@codemirror/language": "^6.11.3",
|
|
36
|
+
"@codemirror/state": "^6.5.2",
|
|
37
|
+
"@codemirror/view": "^6.38.2",
|
|
36
38
|
"@ipld/car": "^5.3.3",
|
|
37
39
|
"@preact-signals/safe-react": "^0.9.0",
|
|
38
40
|
"blockstore-core": "^5.0.1",
|
|
39
41
|
"blockstore-idb": "^2.0.0",
|
|
40
42
|
"debounce": "^2.2.0",
|
|
41
|
-
"effect": "3.
|
|
43
|
+
"effect": "3.17.7",
|
|
42
44
|
"idb-keyval": "^6.2.1",
|
|
43
45
|
"interface-blockstore": "^5.2.10",
|
|
44
46
|
"it-all": "^3.0.6",
|
|
@@ -46,42 +48,40 @@
|
|
|
46
48
|
"react-dropzone": "^14.2.3",
|
|
47
49
|
"uint8arrays": "^5.1.0",
|
|
48
50
|
"wnfs": "0.2.2",
|
|
49
|
-
"@dxos/crypto": "0.8.
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/plugin-client": "0.8.
|
|
58
|
-
"@dxos/plugin-
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/react-client": "0.8.
|
|
61
|
-
"@dxos/react-ui
|
|
62
|
-
"@dxos/react-ui": "0.8.
|
|
63
|
-
"@dxos/react-ui-
|
|
64
|
-
"@dxos/util": "0.8.
|
|
65
|
-
"@dxos/react-ui-
|
|
51
|
+
"@dxos/crypto": "0.8.4-main.1da679c",
|
|
52
|
+
"@dxos/app-framework": "0.8.4-main.1da679c",
|
|
53
|
+
"@dxos/echo": "0.8.4-main.1da679c",
|
|
54
|
+
"@dxos/effect": "0.8.4-main.1da679c",
|
|
55
|
+
"@dxos/invariant": "0.8.4-main.1da679c",
|
|
56
|
+
"@dxos/echo-schema": "0.8.4-main.1da679c",
|
|
57
|
+
"@dxos/log": "0.8.4-main.1da679c",
|
|
58
|
+
"@dxos/plugin-markdown": "0.8.4-main.1da679c",
|
|
59
|
+
"@dxos/plugin-client": "0.8.4-main.1da679c",
|
|
60
|
+
"@dxos/plugin-space": "0.8.4-main.1da679c",
|
|
61
|
+
"@dxos/local-storage": "0.8.4-main.1da679c",
|
|
62
|
+
"@dxos/react-client": "0.8.4-main.1da679c",
|
|
63
|
+
"@dxos/react-ui": "0.8.4-main.1da679c",
|
|
64
|
+
"@dxos/react-ui-editor": "0.8.4-main.1da679c",
|
|
65
|
+
"@dxos/react-ui-stack": "0.8.4-main.1da679c",
|
|
66
|
+
"@dxos/util": "0.8.4-main.1da679c",
|
|
67
|
+
"@dxos/react-ui-form": "0.8.4-main.1da679c"
|
|
66
68
|
},
|
|
67
69
|
"devDependencies": {
|
|
68
|
-
"@phosphor-icons/react": "^2.1.5",
|
|
69
70
|
"@types/react": "~18.2.0",
|
|
70
71
|
"@types/react-dom": "~18.2.0",
|
|
71
72
|
"react": "~18.2.0",
|
|
72
73
|
"react-dom": "~18.2.0",
|
|
73
|
-
"vite": "
|
|
74
|
-
"@dxos/random": "0.8.
|
|
75
|
-
"@dxos/storybook-utils": "0.8.
|
|
76
|
-
"@dxos/react-ui-theme": "0.8.
|
|
74
|
+
"vite": "7.1.1",
|
|
75
|
+
"@dxos/random": "0.8.4-main.1da679c",
|
|
76
|
+
"@dxos/storybook-utils": "0.8.4-main.1da679c",
|
|
77
|
+
"@dxos/react-ui-theme": "0.8.4-main.1da679c"
|
|
77
78
|
},
|
|
78
79
|
"peerDependencies": {
|
|
79
|
-
"@phosphor-icons/react": "^2.0.5",
|
|
80
80
|
"effect": "^3.13.3",
|
|
81
81
|
"react": "~18.2.0",
|
|
82
82
|
"react-dom": "~18.2.0",
|
|
83
|
-
"@dxos/react-ui": "0.8.
|
|
84
|
-
"@dxos/react-ui-theme": "0.8.
|
|
83
|
+
"@dxos/react-ui": "0.8.4-main.1da679c",
|
|
84
|
+
"@dxos/react-ui-theme": "0.8.4-main.1da679c"
|
|
85
85
|
},
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"access": "public"
|
package/src/WnfsPlugin.tsx
CHANGED
|
@@ -20,7 +20,7 @@ import { defineObjectForm } from '@dxos/plugin-space/types';
|
|
|
20
20
|
|
|
21
21
|
import { Blockstore, FileUploader, IntentResolver, Markdown, ReactSurface, WnfsCapabilities } from './capabilities';
|
|
22
22
|
import { meta } from './meta';
|
|
23
|
-
import translations from './translations';
|
|
23
|
+
import { translations } from './translations';
|
|
24
24
|
import { FileType, WnfsAction } from './types';
|
|
25
25
|
|
|
26
26
|
export const WnfsPlugin = () =>
|
package/src/blockstore.ts
CHANGED
|
@@ -126,7 +126,7 @@ export class MixedBlockstore extends BaseBlockstore {
|
|
|
126
126
|
if (this.#apiHost) {
|
|
127
127
|
await fetch(this.url(this.#apiHost, key), {
|
|
128
128
|
method: 'POST',
|
|
129
|
-
body: val
|
|
129
|
+
body: val as Uint8Array<ArrayBuffer>,
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
}
|
|
@@ -138,7 +138,7 @@ export class MixedBlockstore extends BaseBlockstore {
|
|
|
138
138
|
headers: {
|
|
139
139
|
'Content-Type': 'application/vnd.ipld.car',
|
|
140
140
|
},
|
|
141
|
-
body: car
|
|
141
|
+
body: car as Uint8Array<ArrayBuffer>,
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
}
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { type PluginContext, contributes } from '@dxos/app-framework';
|
|
6
6
|
import { ClientCapabilities } from '@dxos/plugin-client';
|
|
7
7
|
|
|
8
|
-
import { WnfsCapabilities } from './capabilities';
|
|
9
8
|
import * as Blockstore from '../blockstore';
|
|
10
9
|
|
|
10
|
+
import { WnfsCapabilities } from './capabilities';
|
|
11
|
+
|
|
11
12
|
export default async (context: PluginContext) => {
|
|
12
13
|
const client = context.getCapability(ClientCapabilities.Client);
|
|
13
14
|
const apiHost = client.config.values.runtime?.services?.edge?.url || 'http://localhost:8787';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { Effect, pipe } from 'effect';
|
|
6
6
|
|
|
7
|
-
import { Capabilities, chain, contributes, createIntent
|
|
7
|
+
import { Capabilities, type PluginContext, chain, contributes, createIntent } from '@dxos/app-framework';
|
|
8
8
|
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
9
9
|
|
|
10
10
|
import { WnfsAction } from '../types';
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Capabilities, type PluginContext, contributes, createResolver } from '@dxos/app-framework';
|
|
6
6
|
import { Obj } from '@dxos/echo';
|
|
7
7
|
|
|
8
|
-
import { WnfsCapabilities } from './capabilities';
|
|
9
8
|
import { upload } from '../helpers';
|
|
10
9
|
import { FileType, WnfsAction } from '../types';
|
|
11
10
|
|
|
11
|
+
import { WnfsCapabilities } from './capabilities';
|
|
12
|
+
|
|
12
13
|
export default (context: PluginContext) =>
|
|
13
14
|
contributes(Capabilities.IntentResolver, [
|
|
14
15
|
// TODO(wittjosiah): Deleting the object doesn't delete the wnfs blob.
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { type PluginContext, contributes } from '@dxos/app-framework';
|
|
6
6
|
import { MarkdownCapabilities } from '@dxos/plugin-markdown';
|
|
7
7
|
import { getSpace } from '@dxos/react-client/echo';
|
|
8
8
|
|
|
9
|
-
import { WnfsCapabilities } from './capabilities';
|
|
10
9
|
import { image } from '../extensions';
|
|
11
10
|
|
|
11
|
+
import { WnfsCapabilities } from './capabilities';
|
|
12
|
+
|
|
12
13
|
export default (context: PluginContext) =>
|
|
13
14
|
contributes(MarkdownCapabilities.Extensions, [
|
|
14
15
|
({ document }) => {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { type Schema } from 'effect';
|
|
6
6
|
import React, { useCallback } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
|
|
9
9
|
import { Obj } from '@dxos/echo';
|
|
10
10
|
import { findAnnotation } from '@dxos/effect';
|
|
11
11
|
import { type InputProps } from '@dxos/react-ui-form';
|
|
@@ -2,34 +2,37 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, {
|
|
5
|
+
import React, { useState } from 'react';
|
|
6
6
|
|
|
7
7
|
import { useCapability } from '@dxos/app-framework';
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
9
|
import { getSpace } from '@dxos/react-client/echo';
|
|
10
|
+
import { useAsyncEffect } from '@dxos/react-ui';
|
|
10
11
|
import { StackItem } from '@dxos/react-ui-stack';
|
|
11
12
|
|
|
12
|
-
import { FilePreview } from './FilePreview';
|
|
13
13
|
import { WnfsCapabilities } from '../capabilities';
|
|
14
14
|
import { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../helpers';
|
|
15
15
|
import { type FileType } from '../types';
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
import { FilePreview } from './FilePreview';
|
|
18
|
+
|
|
19
|
+
export type FileContainerProps = {
|
|
20
|
+
role: string;
|
|
21
|
+
file: FileType;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const FileContainer = ({ file }: FileContainerProps) => {
|
|
18
25
|
const blockstore = useCapability(WnfsCapabilities.Blockstore);
|
|
19
26
|
const instances = useCapability(WnfsCapabilities.Instances);
|
|
20
27
|
const [blobUrl, setBlobUrl] = useState<string>();
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
setBlobUrl(url);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
return () => clearTimeout(timeout);
|
|
29
|
+
useAsyncEffect(async () => {
|
|
30
|
+
const space = getSpace(file);
|
|
31
|
+
invariant(space);
|
|
32
|
+
const { directory, forest } = await loadWnfs({ blockstore, instances, space });
|
|
33
|
+
const path = filePath(file.cid.toString(), space);
|
|
34
|
+
const url = await getBlobUrl({ wnfsUrl: wnfsUrl(path), blockstore, directory, forest, type: file.type });
|
|
35
|
+
setBlobUrl(url);
|
|
33
36
|
}, [file]);
|
|
34
37
|
|
|
35
38
|
if (!blobUrl) {
|
|
@@ -37,7 +40,7 @@ const FileContainer = ({ file, role }: { file: FileType; role: string }) => {
|
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
return (
|
|
40
|
-
<StackItem.Content
|
|
43
|
+
<StackItem.Content>
|
|
41
44
|
<FilePreview type={file.type} url={blobUrl} />
|
|
42
45
|
</StackItem.Content>
|
|
43
46
|
);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
8
|
import type { Blockstore } from 'interface-blockstore';
|
|
8
9
|
import React, { type ChangeEvent, useEffect, useState } from 'react';
|
|
9
10
|
|
|
@@ -19,17 +20,18 @@ import {
|
|
|
19
20
|
processEditorPayload,
|
|
20
21
|
useTextEditor,
|
|
21
22
|
} from '@dxos/react-ui-editor';
|
|
22
|
-
import {
|
|
23
|
+
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
23
24
|
|
|
24
|
-
import { image } from './image';
|
|
25
25
|
import { create as createBlockstore } from '../blockstore';
|
|
26
26
|
import { upload } from '../helpers';
|
|
27
27
|
|
|
28
|
+
import { image } from './image';
|
|
29
|
+
|
|
28
30
|
faker.seed(1);
|
|
29
31
|
const initialValue = faker.lorem.paragraphs(100);
|
|
30
32
|
const instances = {};
|
|
31
33
|
|
|
32
|
-
const
|
|
34
|
+
const DefaultStory = () => {
|
|
33
35
|
const { themeMode } = useThemeContext();
|
|
34
36
|
const space = useSpace();
|
|
35
37
|
const [blockstore, setBlockstore] = useState<Blockstore>();
|
|
@@ -54,7 +56,7 @@ const Story = () => {
|
|
|
54
56
|
initialValue,
|
|
55
57
|
extensions: [
|
|
56
58
|
createBasicExtensions(),
|
|
57
|
-
createMarkdownExtensions(
|
|
59
|
+
createMarkdownExtensions(),
|
|
58
60
|
createThemeExtensions({ themeMode, syntaxHighlighting: true }),
|
|
59
61
|
blockstore && space ? [image({ blockstore, instances, space })] : [],
|
|
60
62
|
decorateMarkdown(),
|
|
@@ -91,10 +93,14 @@ const Story = () => {
|
|
|
91
93
|
);
|
|
92
94
|
};
|
|
93
95
|
|
|
94
|
-
|
|
96
|
+
const meta = {
|
|
95
97
|
title: 'plugins/plugin-wnfs/image',
|
|
96
|
-
render:
|
|
98
|
+
render: DefaultStory,
|
|
97
99
|
decorators: [withClientProvider({ createIdentity: true, createSpace: true }), withTheme, withLayout()],
|
|
98
|
-
}
|
|
100
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
101
|
+
|
|
102
|
+
export default meta;
|
|
103
|
+
|
|
104
|
+
type Story = StoryObj<typeof meta>;
|
|
99
105
|
|
|
100
|
-
export const Default = {};
|
|
106
|
+
export const Default: Story = {};
|
package/src/extensions/image.tsx
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { syntaxTree } from '@codemirror/language';
|
|
6
|
-
import { type EditorState, type Extension,
|
|
6
|
+
import { type EditorState, type Extension, type Range, StateField } from '@codemirror/state';
|
|
7
7
|
import { Decoration, EditorView, WidgetType } from '@codemirror/view';
|
|
8
8
|
import type { Blockstore } from 'interface-blockstore';
|
|
9
9
|
import React from 'react';
|
|
@@ -80,16 +80,16 @@ export const image = (options: ImageOptions): Extension[] => {
|
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
const buildDecorations = ({
|
|
83
|
+
state,
|
|
83
84
|
from,
|
|
84
85
|
to,
|
|
85
|
-
state,
|
|
86
86
|
blobUrlCache,
|
|
87
87
|
preload,
|
|
88
88
|
options: { blockstore, instances, space },
|
|
89
89
|
}: {
|
|
90
|
+
state: EditorState;
|
|
90
91
|
from: number;
|
|
91
92
|
to: number;
|
|
92
|
-
state: EditorState;
|
|
93
93
|
blobUrlCache: Record<string, string>;
|
|
94
94
|
preload: (url: string) => void;
|
|
95
95
|
options: ImageOptions;
|
package/src/helpers/load.ts
CHANGED
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
import type { Blockstore } from 'interface-blockstore';
|
|
6
6
|
import { CID } from 'multiformats';
|
|
7
7
|
import * as Uint8Arrays from 'uint8arrays';
|
|
8
|
-
import { AccessKey,
|
|
8
|
+
import { AccessKey, PrivateDirectory, PrivateForest, PrivateNode } from 'wnfs';
|
|
9
9
|
|
|
10
10
|
import { type Space } from '@dxos/react-client/echo';
|
|
11
11
|
|
|
12
|
-
import { Rng, store } from './common';
|
|
13
12
|
import { type WnfsCapabilities } from '../capabilities';
|
|
14
13
|
|
|
14
|
+
import { Rng, store } from './common';
|
|
15
|
+
|
|
15
16
|
//
|
|
16
17
|
// LOAD
|
|
17
18
|
//
|
package/src/helpers/upload.ts
CHANGED
|
@@ -10,10 +10,11 @@ import { sha256 } from 'multiformats/hashes/sha2';
|
|
|
10
10
|
import type { Space } from '@dxos/client/echo';
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
12
|
|
|
13
|
+
import { type WnfsCapabilities } from '../capabilities';
|
|
14
|
+
|
|
13
15
|
import { Rng, filePath, store } from './common';
|
|
14
16
|
import { loadWnfs } from './load';
|
|
15
17
|
import { wnfsUrl } from './wnfs-url';
|
|
16
|
-
import { type WnfsCapabilities } from '../capabilities';
|
|
17
18
|
|
|
18
19
|
export const upload = async ({
|
|
19
20
|
file,
|
package/src/translations.ts
CHANGED
|
@@ -2,21 +2,25 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { type Resource } from '@dxos/react-ui';
|
|
6
|
+
|
|
7
|
+
import { meta } from './meta';
|
|
6
8
|
import { FileType } from './types';
|
|
7
9
|
|
|
8
|
-
export
|
|
10
|
+
export const translations = [
|
|
9
11
|
{
|
|
10
12
|
'en-US': {
|
|
11
13
|
[FileType.typename]: {
|
|
12
14
|
'typename label': 'File',
|
|
13
15
|
'object name placeholder': 'New file',
|
|
16
|
+
'rename object label': 'Rename file',
|
|
17
|
+
'delete object label': 'Delete file',
|
|
14
18
|
},
|
|
15
|
-
[
|
|
19
|
+
[meta.id]: {
|
|
16
20
|
'plugin name': 'Files',
|
|
17
21
|
'delete object label': 'Delete',
|
|
18
22
|
'file input placeholder': 'Drop a file here, or click to select a file',
|
|
19
23
|
},
|
|
20
24
|
},
|
|
21
25
|
},
|
|
22
|
-
];
|
|
26
|
+
] as const satisfies Resource[];
|
package/src/types/types.ts
CHANGED
|
@@ -7,9 +7,10 @@ import { Schema } from 'effect';
|
|
|
7
7
|
import { FileInfoSchema } from '@dxos/app-framework';
|
|
8
8
|
import { SpaceSchema } from '@dxos/react-client/echo';
|
|
9
9
|
|
|
10
|
-
import { FileType } from './file';
|
|
11
10
|
import { WNFS_PLUGIN } from '../meta';
|
|
12
11
|
|
|
12
|
+
import { FileType } from './file';
|
|
13
|
+
|
|
13
14
|
export namespace WnfsAction {
|
|
14
15
|
export class Create extends Schema.TaggedClass<Create>()(`${WNFS_PLUGIN}/action/create`, {
|
|
15
16
|
input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
|
|
@@ -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, { useEffect, useState } from 'react';\n\nimport { useCapability } from '@dxos/app-framework';\nimport { invariant } from '@dxos/invariant';\nimport { getSpace } from '@dxos/react-client/echo';\nimport { StackItem } from '@dxos/react-ui-stack';\n\nimport { FilePreview } from './FilePreview';\nimport { WnfsCapabilities } from '../capabilities';\nimport { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../helpers';\nimport { type FileType } from '../types';\n\nconst FileContainer = ({ file, role }: { file: FileType; role: string }) => {\n const blockstore = useCapability(WnfsCapabilities.Blockstore);\n const instances = useCapability(WnfsCapabilities.Instances);\n const [blobUrl, setBlobUrl] = useState<string>();\n\n useEffect(() => {\n const timeout = setTimeout(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 });\n\n return () => clearTimeout(timeout);\n }, [file]);\n\n if (!blobUrl) {\n return null;\n }\n\n return (\n <StackItem.Content role={role}>\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,WAAWC,gBAAgB;AAE3C,SAASC,qBAAqB;AAC9B,SAASC,iBAAiB;AAC1B,SAASC,gBAAgB;AACzB,SAASC,iBAAiB;;;;ACL1B,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;;;;ADNA,IAAMU,gBAAgB,CAAC,EAAEC,MAAMC,KAAI,MAAoC;;;AACrE,UAAMC,aAAaC,cAAcC,iBAAiBC,UAAU;AAC5D,UAAMC,YAAYH,cAAcC,iBAAiBG,SAAS;AAC1D,UAAM,CAACC,SAASC,UAAAA,IAAcC,SAAAA;AAE9BC,cAAU,MAAA;AACR,YAAMC,UAAUC,WAAW,YAAA;AACzB,cAAMC,QAAQC,SAASf,IAAAA;AACvBgB,kBAAUF,OAAAA,QAAAA;;;;;;;;;AACV,cAAM,EAAEG,WAAWC,OAAM,IAAK,MAAMC,SAAS;UAAEjB;UAAYI;UAAWQ;QAAM,CAAA;AAC5E,cAAMM,OAAOC,SAASrB,KAAKsB,IAAIC,SAAQ,GAAIT,KAAAA;AAC3C,cAAMU,MAAM,MAAMC,WAAW;UAAEC,SAASA,QAAQN,IAAAA;UAAOlB;UAAYe;UAAWC;UAAQS,MAAM3B,KAAK2B;QAAK,CAAA;AACtGlB,mBAAWe,GAAAA;MACb,CAAA;AAEA,aAAO,MAAMI,aAAahB,OAAAA;IAC5B,GAAG;MAACZ;KAAK;AAET,QAAI,CAACQ,SAAS;AACZ,aAAO;IACT;AAEA,WACE,gBAAAqB,OAAA,cAACC,UAAUC,SAAO;MAAC9B;OACjB,gBAAA4B,OAAA,cAACG,aAAAA;MAAYL,MAAM3B,KAAK2B;MAAMH,KAAKhB;;;;;AAGzC;AAEA,IAAA,wBAAeT;",
|
|
6
|
-
"names": ["React", "useEffect", "useState", "useCapability", "invariant", "getSpace", "StackItem", "React", "mx", "FilePreview", "type", "url", "classNames", "startsWith", "img", "className", "mx", "src", "video", "controls", "iframe", "FileContainer", "file", "role", "blockstore", "useCapability", "WnfsCapabilities", "Blockstore", "instances", "Instances", "blobUrl", "setBlobUrl", "useState", "useEffect", "timeout", "setTimeout", "space", "getSpace", "invariant", "directory", "forest", "loadWnfs", "path", "filePath", "cid", "toString", "url", "getBlobUrl", "wnfsUrl", "type", "clearTimeout", "React", "StackItem", "Content", "FilePreview"]
|
|
7
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
storeName
|
|
3
|
-
} from "./chunk-YYAW4U6J.mjs";
|
|
4
|
-
import {
|
|
5
|
-
WnfsCapabilities
|
|
6
|
-
} from "./chunk-DL7BBH57.mjs";
|
|
7
|
-
import "./chunk-PHTWWADN.mjs";
|
|
8
|
-
|
|
9
|
-
// packages/plugins/plugin-wnfs/src/capabilities/blockstore.ts
|
|
10
|
-
import { contributes } from "@dxos/app-framework";
|
|
11
|
-
import { ClientCapabilities } from "@dxos/plugin-client";
|
|
12
|
-
|
|
13
|
-
// packages/plugins/plugin-wnfs/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
|
-
var create = (apiHost) => {
|
|
23
|
-
return new MixedBlockstore(apiHost);
|
|
24
|
-
};
|
|
25
|
-
var MixedBlockstore = class extends BaseBlockstore {
|
|
26
|
-
constructor(apiHost) {
|
|
27
|
-
super();
|
|
28
|
-
// QUEUE
|
|
29
|
-
this.queueCacheName = `${storeName()}/state/queue`;
|
|
30
|
-
this.#apiHost = apiHost ? apiHost.replace(/\/?$/, "") : void 0;
|
|
31
|
-
this.#localStore = new IDBBlockstore(storeName());
|
|
32
|
-
this.#isConnected = navigator.onLine;
|
|
33
|
-
this.#queue = [];
|
|
34
|
-
this.#flushQueue = debounce(this.#flushQueueInt, 5e3);
|
|
35
|
-
}
|
|
36
|
-
#apiHost;
|
|
37
|
-
#localStore;
|
|
38
|
-
#isConnected;
|
|
39
|
-
#flushQueue;
|
|
40
|
-
#queue;
|
|
41
|
-
async open() {
|
|
42
|
-
await this.#localStore.open();
|
|
43
|
-
await this.#restoreQueue();
|
|
44
|
-
window.addEventListener("offline", async () => {
|
|
45
|
-
this.#isConnected = false;
|
|
46
|
-
});
|
|
47
|
-
window.addEventListener("online", async () => {
|
|
48
|
-
this.#isConnected = true;
|
|
49
|
-
this.#flushQueue();
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
url(apiHost, cid) {
|
|
53
|
-
const path = cid ? cid.toString() : "";
|
|
54
|
-
return `${apiHost}/api/file${path.length ? "/" + path : ""}`;
|
|
55
|
-
}
|
|
56
|
-
// BLOCKSTORE IMPLEMENTATION
|
|
57
|
-
async delete(key) {
|
|
58
|
-
await this.#localStore.delete(key);
|
|
59
|
-
if (this.#isConnected && this.#apiHost) {
|
|
60
|
-
await fetch(this.url(this.#apiHost, key), {
|
|
61
|
-
method: "DELETE"
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async get(key) {
|
|
66
|
-
if (await this.#localStore.has(key)) {
|
|
67
|
-
return await this.#localStore.get(key);
|
|
68
|
-
}
|
|
69
|
-
if (this.#isConnected && this.#apiHost) {
|
|
70
|
-
const block = await fetch(this.url(this.#apiHost, key), {
|
|
71
|
-
method: "GET"
|
|
72
|
-
}).then((r) => r.arrayBuffer()).then((r) => new Uint8Array(r));
|
|
73
|
-
await this.#localStore.put(key, block);
|
|
74
|
-
return block;
|
|
75
|
-
}
|
|
76
|
-
return await this.#localStore.get(key);
|
|
77
|
-
}
|
|
78
|
-
async has(key) {
|
|
79
|
-
if (await this.#localStore.has(key)) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
if (this.#isConnected && this.#apiHost) {
|
|
83
|
-
return await fetch(this.url(this.#apiHost, key), {
|
|
84
|
-
method: "HEAD"
|
|
85
|
-
}).then((r) => r.ok);
|
|
86
|
-
}
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
async put(key, val) {
|
|
90
|
-
await this.#localStore.put(key, val);
|
|
91
|
-
await this.#addToQueue(key);
|
|
92
|
-
this.#flushQueue();
|
|
93
|
-
return key;
|
|
94
|
-
}
|
|
95
|
-
async destroy() {
|
|
96
|
-
await this.#localStore.destroy();
|
|
97
|
-
}
|
|
98
|
-
// REMOTE
|
|
99
|
-
async putRemote(key, val) {
|
|
100
|
-
if (this.#apiHost) {
|
|
101
|
-
await fetch(this.url(this.#apiHost, key), {
|
|
102
|
-
method: "POST",
|
|
103
|
-
body: val
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
async putCarRemote(car) {
|
|
108
|
-
if (this.#apiHost) {
|
|
109
|
-
await fetch(this.url(this.#apiHost), {
|
|
110
|
-
method: "POST",
|
|
111
|
-
headers: {
|
|
112
|
-
"Content-Type": "application/vnd.ipld.car"
|
|
113
|
-
},
|
|
114
|
-
body: car
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
async #addToQueue(key) {
|
|
119
|
-
await this.#saveQueue([
|
|
120
|
-
...this.#queue,
|
|
121
|
-
key.toString()
|
|
122
|
-
]);
|
|
123
|
-
}
|
|
124
|
-
async #flushQueueInt() {
|
|
125
|
-
if (!this.#isConnected || !this.#apiHost) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const keys = [
|
|
129
|
-
...this.#queue
|
|
130
|
-
];
|
|
131
|
-
if (keys.length === 0) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const blocks = await Promise.all(keys.map(async (key) => {
|
|
135
|
-
const cid = CID.parse(key);
|
|
136
|
-
const bytes = await this.#localStore.get(cid);
|
|
137
|
-
return {
|
|
138
|
-
cid,
|
|
139
|
-
bytes
|
|
140
|
-
};
|
|
141
|
-
}));
|
|
142
|
-
const car = await this.#createCar(blocks);
|
|
143
|
-
await this.putCarRemote(car);
|
|
144
|
-
const queue = [
|
|
145
|
-
...this.#queue
|
|
146
|
-
].filter((k) => {
|
|
147
|
-
if (keys.includes(k)) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
return true;
|
|
151
|
-
});
|
|
152
|
-
await this.#saveQueue(queue);
|
|
153
|
-
}
|
|
154
|
-
async #restoreQueue() {
|
|
155
|
-
const fromCache = await IDB.get(this.queueCacheName);
|
|
156
|
-
if (fromCache && Array.isArray(fromCache)) {
|
|
157
|
-
this.#queue = fromCache;
|
|
158
|
-
this.#flushQueue();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
async #saveQueue(items) {
|
|
162
|
-
const arr = [
|
|
163
|
-
...items
|
|
164
|
-
];
|
|
165
|
-
this.#queue = arr;
|
|
166
|
-
await IDB.set(this.queueCacheName, arr);
|
|
167
|
-
}
|
|
168
|
-
// 🛠️
|
|
169
|
-
async #createCar(blocks) {
|
|
170
|
-
const { writer, out } = CarWriter.create();
|
|
171
|
-
const outPromise = all(out);
|
|
172
|
-
await Promise.all(blocks.map((block) => {
|
|
173
|
-
return writer.put(block);
|
|
174
|
-
}));
|
|
175
|
-
await writer.close();
|
|
176
|
-
return Uint8Arrays.concat(await outPromise);
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
// packages/plugins/plugin-wnfs/src/capabilities/blockstore.ts
|
|
181
|
-
var blockstore_default = async (context) => {
|
|
182
|
-
const client = context.getCapability(ClientCapabilities.Client);
|
|
183
|
-
const apiHost = client.config.values.runtime?.services?.edge?.url || "http://localhost:8787";
|
|
184
|
-
const blockstore = create(apiHost);
|
|
185
|
-
await blockstore.open();
|
|
186
|
-
return contributes(WnfsCapabilities.Blockstore, blockstore);
|
|
187
|
-
};
|
|
188
|
-
export {
|
|
189
|
-
blockstore_default as default
|
|
190
|
-
};
|
|
191
|
-
//# sourceMappingURL=blockstore-UT7233RJ.mjs.map
|