@dxos/plugin-wnfs 0.8.4-main.67995b8 → 0.8.4-main.72ec0f3
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-6P2SYTVH.mjs → FileContainer-LLNI7WXR.mjs} +35 -37
- package/dist/lib/browser/FileContainer-LLNI7WXR.mjs.map +7 -0
- package/dist/lib/browser/{blockstore-KQO2NTVM.mjs → blockstore-2JFU4NBU.mjs} +13 -13
- package/dist/lib/browser/blockstore-2JFU4NBU.mjs.map +7 -0
- package/dist/lib/browser/{chunk-GVBV2QWA.mjs → chunk-CWMKN2F6.mjs} +27 -20
- package/dist/lib/browser/chunk-CWMKN2F6.mjs.map +7 -0
- package/dist/lib/browser/{chunk-VRRXG6IB.mjs → chunk-D6VTEQIE.mjs} +3 -3
- package/dist/lib/browser/{chunk-VRRXG6IB.mjs.map → chunk-D6VTEQIE.mjs.map} +3 -3
- package/dist/lib/browser/chunk-F4QHZWQD.mjs +16 -0
- package/dist/lib/browser/chunk-F4QHZWQD.mjs.map +7 -0
- package/dist/lib/browser/chunk-OGPGLJCV.mjs +25 -0
- package/dist/lib/browser/chunk-OGPGLJCV.mjs.map +7 -0
- package/dist/lib/browser/chunk-ZFPJA5F4.mjs +16 -0
- package/dist/lib/browser/{file-uploader-JA55DPMW.mjs → file-uploader-W6TJLAAK.mjs} +11 -10
- package/dist/lib/browser/file-uploader-W6TJLAAK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +13 -15
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-YM6QRFIH.mjs → intent-resolver-FSW2EQF4.mjs} +10 -11
- package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs.map +7 -0
- package/dist/lib/browser/{markdown-6VH477GB.mjs → markdown-WYQDCVFQ.mjs} +9 -7
- package/dist/lib/browser/markdown-WYQDCVFQ.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-NOSB5MZ2.mjs → react-surface-DMU47U3X.mjs} +14 -14
- package/dist/lib/browser/react-surface-DMU47U3X.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +5 -5
- package/dist/types/src/WnfsPlugin.d.ts +1 -1
- package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
- 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/capabilities.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 +2 -2
- package/dist/types/src/components/FileContainer.d.ts.map +1 -1
- package/dist/types/src/components/FileInput.d.ts +1 -1
- package/dist/types/src/components/FileInput.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/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/meta.d.ts +0 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- 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/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +13 -9
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +37 -38
- package/src/WnfsPlugin.tsx +71 -69
- package/src/blockstore.ts +2 -2
- package/src/capabilities/blockstore.ts +3 -2
- package/src/capabilities/capabilities.ts +3 -3
- package/src/capabilities/file-uploader.ts +9 -6
- package/src/capabilities/intent-resolver.ts +5 -5
- package/src/capabilities/markdown.ts +3 -2
- package/src/capabilities/react-surface.tsx +7 -7
- package/src/components/FileContainer.tsx +23 -15
- package/src/components/FileInput.tsx +4 -4
- package/src/components/FilePreview.tsx +3 -3
- package/src/extensions/image.stories.tsx +16 -12
- package/src/extensions/image.tsx +6 -6
- package/src/helpers/load.ts +3 -2
- package/src/helpers/upload.ts +2 -1
- package/src/meta.ts +7 -4
- package/src/translations.ts +2 -2
- package/src/types/File.ts +24 -0
- package/src/types/index.ts +1 -1
- package/src/types/types.ts +9 -8
- package/dist/lib/browser/FileContainer-6P2SYTVH.mjs.map +0 -7
- package/dist/lib/browser/blockstore-KQO2NTVM.mjs.map +0 -7
- package/dist/lib/browser/chunk-GVBV2QWA.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-WTYTESSC.mjs +0 -16
- package/dist/lib/browser/file-uploader-JA55DPMW.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-YM6QRFIH.mjs.map +0 -7
- package/dist/lib/browser/markdown-6VH477GB.mjs.map +0 -7
- package/dist/lib/browser/react-surface-NOSB5MZ2.mjs.map +0 -7
- package/dist/types/src/types/file.d.ts +0 -16
- package/dist/types/src/types/file.d.ts.map +0 -1
- package/src/types/file.ts +0 -17
- /package/dist/lib/browser/{chunk-WTYTESSC.mjs.map → chunk-ZFPJA5F4.mjs.map} +0 -0
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;
|
|
@@ -165,11 +165,11 @@ class WnfsImageWidget extends WidgetType {
|
|
|
165
165
|
super();
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
override eq(other: this)
|
|
169
|
-
return this._wnfsUrl ===
|
|
168
|
+
override eq(other: this) {
|
|
169
|
+
return this._wnfsUrl === other._wnfsUrl;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
override toDOM(view: EditorView)
|
|
172
|
+
override toDOM(view: EditorView) {
|
|
173
173
|
if (typeof this._url === 'string') {
|
|
174
174
|
return createImg(view, this._url);
|
|
175
175
|
}
|
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/meta.ts
CHANGED
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type PluginMeta } from '@dxos/app-framework';
|
|
6
|
-
|
|
7
|
-
export const WNFS_PLUGIN = 'dxos.org/plugin/wnfs';
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
8
7
|
|
|
9
8
|
export const meta: PluginMeta = {
|
|
10
|
-
id:
|
|
9
|
+
id: 'dxos.org/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
|
};
|
package/src/translations.ts
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
7
|
import { meta } from './meta';
|
|
8
|
-
import {
|
|
8
|
+
import { WnfsFile } from './types';
|
|
9
9
|
|
|
10
10
|
export const translations = [
|
|
11
11
|
{
|
|
12
12
|
'en-US': {
|
|
13
|
-
[
|
|
13
|
+
[WnfsFile.File.typename]: {
|
|
14
14
|
'typename label': 'File',
|
|
15
15
|
'object name placeholder': 'New file',
|
|
16
16
|
'rename object label': 'Rename file',
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { Obj, Type } from '@dxos/echo';
|
|
8
|
+
import { FormAnnotation } from '@dxos/echo/internal';
|
|
9
|
+
|
|
10
|
+
export const File = Schema.Struct({
|
|
11
|
+
name: Schema.String.pipe(Schema.optional),
|
|
12
|
+
type: Schema.String.pipe(FormAnnotation.set(false)),
|
|
13
|
+
cid: Schema.String.pipe(FormAnnotation.set(false)),
|
|
14
|
+
timestamp: Schema.String.pipe(FormAnnotation.set(false), Schema.optional),
|
|
15
|
+
}).pipe(
|
|
16
|
+
Type.Obj({
|
|
17
|
+
typename: 'dxos.org/type/File',
|
|
18
|
+
version: '0.1.0',
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export type File = Schema.Schema.Type<typeof File>;
|
|
23
|
+
|
|
24
|
+
export const make = (props: Obj.MakeProps<typeof File>) => Obj.make(File, props);
|
package/src/types/index.ts
CHANGED
package/src/types/types.ts
CHANGED
|
@@ -2,26 +2,27 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
7
|
import { FileInfoSchema } from '@dxos/app-framework';
|
|
8
8
|
import { SpaceSchema } from '@dxos/react-client/echo';
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
|
|
10
|
+
import { meta } from '../meta';
|
|
11
|
+
|
|
12
|
+
import * as File from './File';
|
|
12
13
|
|
|
13
14
|
export namespace WnfsAction {
|
|
14
|
-
export class Create extends Schema.TaggedClass<Create>()(`${
|
|
15
|
+
export class Create extends Schema.TaggedClass<Create>()(`${meta.id}/action/create`, {
|
|
15
16
|
input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
|
|
16
17
|
output: Schema.Struct({
|
|
17
|
-
object:
|
|
18
|
+
object: File.File,
|
|
18
19
|
}),
|
|
19
20
|
}) {}
|
|
20
21
|
|
|
21
|
-
export const UploadAnnotationId = Symbol.for(`${
|
|
22
|
+
export const UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);
|
|
22
23
|
|
|
23
24
|
export const UploadFileSchema = Schema.Struct({
|
|
24
|
-
file: Schema.instanceOf(File).annotations({
|
|
25
|
+
file: Schema.instanceOf(File.File).annotations({
|
|
25
26
|
[UploadAnnotationId]: {
|
|
26
27
|
// Accept file types.
|
|
27
28
|
'image/*': ['.jpg', '.jpeg', '.png', '.gif'],
|
|
@@ -33,7 +34,7 @@ export namespace WnfsAction {
|
|
|
33
34
|
|
|
34
35
|
export type UploadFileForm = Schema.Schema.Type<typeof UploadFileSchema>;
|
|
35
36
|
|
|
36
|
-
export class Upload extends Schema.TaggedClass<Upload>()(`${
|
|
37
|
+
export class Upload extends Schema.TaggedClass<Upload>()(`${meta.id}/action/upload`, {
|
|
37
38
|
input: Schema.extend(UploadFileSchema, Schema.Struct({ space: SpaceSchema })),
|
|
38
39
|
output: Schema.required(FileInfoSchema),
|
|
39
40
|
}) {}
|
|
@@ -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\nexport type FileContainerProps = {\n role: string;\n file: FileType;\n};\n\nexport const FileContainer = ({ file }: FileContainerProps) => {\n const blockstore = useCapability(WnfsCapabilities.Blockstore);\n const instances = useCapability(WnfsCapabilities.Instances);\n const [blobUrl, setBlobUrl] = useState<string>();\n\n 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>\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;;;;ADDO,IAAMU,gBAAgB,CAAC,EAAEC,KAAI,MAAsB;;;AACxD,UAAMC,aAAaC,cAAcC,iBAAiBC,UAAU;AAC5D,UAAMC,YAAYH,cAAcC,iBAAiBG,SAAS;AAC1D,UAAM,CAACC,SAASC,UAAAA,IAAcC,SAAAA;AAE9BC,cAAU,MAAA;AACR,YAAMC,UAAUC,WAAW,YAAA;AACzB,cAAMC,QAAQC,SAASd,IAAAA;AACvBe,kBAAUF,OAAAA,QAAAA;;;;;;;;;AACV,cAAM,EAAEG,WAAWC,OAAM,IAAK,MAAMC,SAAS;UAAEjB;UAAYI;UAAWQ;QAAM,CAAA;AAC5E,cAAMM,OAAOC,SAASpB,KAAKqB,IAAIC,SAAQ,GAAIT,KAAAA;AAC3C,cAAMU,MAAM,MAAMC,WAAW;UAAEC,SAASA,QAAQN,IAAAA;UAAOlB;UAAYe;UAAWC;UAAQS,MAAM1B,KAAK0B;QAAK,CAAA;AACtGlB,mBAAWe,GAAAA;MACb,CAAA;AAEA,aAAO,MAAMI,aAAahB,OAAAA;IAC5B,GAAG;MAACX;KAAK;AAET,QAAI,CAACO,SAAS;AACZ,aAAO;IACT;AAEA,WACE,gBAAAqB,OAAA,cAACC,UAAUC,SAAO,MAChB,gBAAAF,OAAA,cAACG,aAAAA;MAAYL,MAAM1B,KAAK0B;MAAMH,KAAKhB;;;;;AAGzC;AAEA,IAAA,wBAAeR;",
|
|
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", "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,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/blockstore.ts", "../../../src/blockstore.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { contributes, type PluginContext } from '@dxos/app-framework';\nimport { ClientCapabilities } from '@dxos/plugin-client';\n\nimport { WnfsCapabilities } from './capabilities';\nimport * as Blockstore from '../blockstore';\n\nexport default async (context: PluginContext) => {\n const client = context.getCapability(ClientCapabilities.Client);\n const apiHost = client.config.values.runtime?.services?.edge?.url || 'http://localhost:8787';\n const blockstore = Blockstore.create(apiHost);\n await blockstore.open();\n\n return contributes(WnfsCapabilities.Blockstore, blockstore);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { CarWriter } from '@ipld/car';\nimport type { Block } from '@ipld/car/reader';\nimport { BaseBlockstore } from 'blockstore-core';\nimport { IDBBlockstore } from 'blockstore-idb';\nimport debounce from 'debounce';\nimport * as IDB from 'idb-keyval';\nimport all from 'it-all';\nimport { CID } from 'multiformats';\nimport * as Uint8Arrays from 'uint8arrays';\n\nimport { storeName } from './helpers';\n\nexport const create = (apiHost?: string) => {\n return new MixedBlockstore(apiHost);\n};\n\n/**\n * A blockstore that communicates with the DXOS blob service,\n * and which uses an indexedDB blockstore as a client cache.\n */\nexport class MixedBlockstore extends BaseBlockstore {\n readonly #apiHost: string | undefined;\n readonly #localStore: IDBBlockstore;\n\n #isConnected: boolean;\n #flushQueue: () => void;\n #queue: string[];\n\n constructor(apiHost?: string) {\n super();\n\n this.#apiHost = apiHost ? apiHost.replace(/\\/?$/, '') : undefined;\n this.#localStore = new IDBBlockstore(storeName());\n this.#isConnected = navigator.onLine;\n this.#queue = [];\n\n this.#flushQueue = debounce(this.#flushQueueInt, 5000);\n }\n\n async open(): Promise<void> {\n await this.#localStore.open();\n await this.#restoreQueue();\n\n window.addEventListener('offline', async () => {\n this.#isConnected = false;\n });\n\n window.addEventListener('online', async () => {\n this.#isConnected = true;\n this.#flushQueue();\n });\n }\n\n url(apiHost: string, cid?: CID): string {\n const path = cid ? cid.toString() : '';\n return `${apiHost}/api/file${path.length ? '/' + path : ''}`;\n }\n\n // BLOCKSTORE IMPLEMENTATION\n\n override async delete(key: CID): Promise<void> {\n await this.#localStore.delete(key);\n\n if (this.#isConnected && this.#apiHost) {\n await fetch(this.url(this.#apiHost, key), {\n method: 'DELETE',\n });\n }\n }\n\n override async get(key: CID): Promise<Uint8Array> {\n if (await this.#localStore.has(key)) {\n return await this.#localStore.get(key);\n }\n\n if (this.#isConnected && this.#apiHost) {\n const block = await fetch(this.url(this.#apiHost, key), {\n method: 'GET',\n })\n .then((r) => r.arrayBuffer())\n .then((r) => new Uint8Array(r));\n\n // Make sure it is cached locally\n await this.#localStore.put(key, block);\n\n return block;\n }\n\n return await this.#localStore.get(key);\n }\n\n override async has(key: CID): Promise<boolean> {\n if (await this.#localStore.has(key)) {\n return true;\n }\n\n if (this.#isConnected && this.#apiHost) {\n return await fetch(this.url(this.#apiHost, key), {\n method: 'HEAD',\n }).then((r) => r.ok);\n }\n\n return false;\n }\n\n override async put(key: CID, val: Uint8Array): Promise<CID> {\n await this.#localStore.put(key, val);\n\n await this.#addToQueue(key);\n this.#flushQueue();\n\n return key;\n }\n\n async destroy(): Promise<void> {\n await this.#localStore.destroy();\n }\n\n // REMOTE\n\n async putRemote(key: CID, val: Uint8Array): Promise<void> {\n if (this.#apiHost) {\n await fetch(this.url(this.#apiHost, key), {\n method: 'POST',\n body: val,\n });\n }\n }\n\n async putCarRemote(car: Uint8Array): Promise<void> {\n if (this.#apiHost) {\n await fetch(this.url(this.#apiHost), {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/vnd.ipld.car',\n },\n body: car,\n });\n }\n }\n\n // QUEUE\n\n readonly queueCacheName = `${storeName()}/state/queue`;\n\n async #addToQueue(key: CID): Promise<void> {\n await this.#saveQueue([...this.#queue, key.toString()]);\n }\n\n async #flushQueueInt(): Promise<void> {\n if (!this.#isConnected || !this.#apiHost) {\n return;\n }\n\n const keys = [...this.#queue];\n if (keys.length === 0) {\n return;\n }\n\n // Collect blocks\n const blocks = await Promise.all(\n keys.map(async (key) => {\n const cid = CID.parse(key);\n const bytes = await this.#localStore.get(cid);\n return { cid, bytes };\n }),\n );\n\n // Create & submit CAR\n const car = await this.#createCar(blocks);\n await this.putCarRemote(car);\n\n // Adjust queue\n const queue = [...this.#queue].filter((k) => {\n if (keys.includes(k)) {\n return false;\n }\n\n return true;\n });\n\n await this.#saveQueue(queue);\n }\n\n async #restoreQueue(): Promise<void> {\n const fromCache = await IDB.get(this.queueCacheName);\n if (fromCache && Array.isArray(fromCache)) {\n this.#queue = fromCache;\n this.#flushQueue();\n }\n }\n\n async #saveQueue(items: string[]): Promise<void> {\n const arr = [...items];\n this.#queue = arr;\n await IDB.set(this.queueCacheName, arr);\n }\n\n // 🛠️\n\n async #createCar(blocks: Block[]): Promise<Uint8Array> {\n const { writer, out } = CarWriter.create();\n const outPromise = all(out);\n\n await Promise.all(\n blocks.map((block) => {\n return writer.put(block);\n }),\n );\n\n await writer.close();\n return Uint8Arrays.concat(await outPromise);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;AAIA,SAASA,mBAAuC;AAChD,SAASC,0BAA0B;;;ACDnC,SAASC,iBAAiB;AAE1B,SAASC,sBAAsB;AAC/B,SAASC,qBAAqB;AAC9B,OAAOC,cAAc;AACrB,YAAYC,SAAS;AACrB,OAAOC,SAAS;AAChB,SAASC,WAAW;AACpB,YAAYC,iBAAiB;AAItB,IAAMC,SAAS,CAACC,YAAAA;AACrB,SAAO,IAAIC,gBAAgBD,OAAAA;AAC7B;AAMO,IAAMC,kBAAN,cAA8BC,eAAAA;EAQnC,YAAYF,SAAkB;AAC5B,UAAK;AAkHEG;0BAAiB,GAAGC,UAAAA,CAAAA;AAhH3B,SAAK,WAAWJ,UAAUA,QAAQK,QAAQ,QAAQ,EAAA,IAAMC;AACxD,SAAK,cAAc,IAAIC,cAAcH,UAAAA,CAAAA;AACrC,SAAK,eAAeI,UAAUC;AAC9B,SAAK,SAAS,CAAA;AAEd,SAAK,cAAcC,SAAS,KAAK,gBAAgB,GAAA;EACnD;EAhBS;EACA;EAET;EACA;EACA;EAaA,MAAMC,OAAsB;AAC1B,UAAM,KAAK,YAAYA,KAAI;AAC3B,UAAM,KAAK,cAAa;AAExBC,WAAOC,iBAAiB,WAAW,YAAA;AACjC,WAAK,eAAe;IACtB,CAAA;AAEAD,WAAOC,iBAAiB,UAAU,YAAA;AAChC,WAAK,eAAe;AACpB,WAAK,YAAW;IAClB,CAAA;EACF;EAEAC,IAAId,SAAiBe,KAAmB;AACtC,UAAMC,OAAOD,MAAMA,IAAIE,SAAQ,IA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,QAAQF,SAAAA,GAAY;AACzC,WAAK,SAASA;AACd,WAAK,YAAW;IAClB;EACF;EAEA,MAAM,WAAWG,OAAe;AAC9B,UAAMC,MAAM;SAAID;;AAChB,SAAK,SAASC;AACd,UAAUC,QAAI,KAAKrD,gBAAgBoD,GAAAA;EACrC;;EAIA,MAAM,WAAWf,QAAe;AAC9B,UAAM,EAAEiB,QAAQC,IAAG,IAAKC,UAAU5D,OAAM;AACxC,UAAM6D,aAAalB,IAAIgB,GAAAA;AAEvB,UAAMjB,QAAQC,IACZF,OAAOG,IAAI,CAAClB,UAAAA;AACV,aAAOgC,OAAO3B,IAAIL,KAAAA;IACpB,CAAA,CAAA;AAGF,UAAMgC,OAAOI,MAAK;AAClB,WAAmBC,mBAAO,MAAMF,UAAAA;EAClC;AACF;;;AD/MA,IAAA,qBAAe,OAAOG,YAAAA;AACpB,QAAMC,SAASD,QAAQE,cAAcC,mBAAmBC,MAAM;AAC9D,QAAMC,UAAUJ,OAAOK,OAAOC,OAAOC,SAASC,UAAUC,MAAMC,OAAO;AACrE,QAAMC,aAAwBC,OAAOR,OAAAA;AACrC,QAAMO,WAAWE,KAAI;AAErB,SAAOC,YAAYC,iBAAiBC,YAAYL,UAAAA;AAClD;",
|
|
6
|
-
"names": ["contributes", "ClientCapabilities", "CarWriter", "BaseBlockstore", "IDBBlockstore", "debounce", "IDB", "all", "CID", "Uint8Arrays", "create", "apiHost", "MixedBlockstore", "BaseBlockstore", "queueCacheName", "storeName", "replace", "undefined", "IDBBlockstore", "navigator", "onLine", "debounce", "open", "window", "addEventListener", "url", "cid", "path", "toString", "length", "delete", "key", "fetch", "method", "get", "has", "block", "then", "r", "arrayBuffer", "Uint8Array", "put", "ok", "val", "destroy", "putRemote", "body", "putCarRemote", "car", "headers", "keys", "blocks", "Promise", "all", "map", "CID", "parse", "bytes", "queue", "filter", "k", "includes", "fromCache", "Array", "isArray", "items", "arr", "set", "writer", "out", "CarWriter", "outPromise", "close", "concat", "context", "client", "getCapability", "ClientCapabilities", "Client", "apiHost", "config", "values", "runtime", "services", "edge", "url", "blockstore", "create", "open", "contributes", "WnfsCapabilities", "Blockstore"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/types/file.ts", "../../../src/types/types.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { TypedObject } from '@dxos/echo-schema';\n\nexport class FileType extends TypedObject({\n typename: 'dxos.org/type/File',\n version: '0.1.0',\n})({\n name: Schema.optional(Schema.String),\n type: Schema.String,\n cid: Schema.String,\n timestamp: Schema.optional(Schema.String),\n}) {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { FileInfoSchema } from '@dxos/app-framework';\nimport { SpaceSchema } from '@dxos/react-client/echo';\n\nimport { FileType } from './file';\nimport { WNFS_PLUGIN } from '../meta';\n\nexport namespace WnfsAction {\n export class Create extends Schema.TaggedClass<Create>()(`${WNFS_PLUGIN}/action/create`, {\n input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),\n output: Schema.Struct({\n object: FileType,\n }),\n }) {}\n\n export const UploadAnnotationId = Symbol.for(`${WNFS_PLUGIN}/annotation/upload`);\n\n export const UploadFileSchema = Schema.Struct({\n file: Schema.instanceOf(File).annotations({\n [UploadAnnotationId]: {\n // Accept file types.\n 'image/*': ['.jpg', '.jpeg', '.png', '.gif'],\n 'application/pdf': ['.pdf'],\n // TODO(wittjosiah): Add more file types.\n },\n }),\n });\n\n export type UploadFileForm = Schema.Schema.Type<typeof UploadFileSchema>;\n\n export class Upload extends Schema.TaggedClass<Upload>()(`${WNFS_PLUGIN}/action/upload`, {\n input: Schema.extend(UploadFileSchema, Schema.Struct({ space: SpaceSchema })),\n output: Schema.required(FileInfoSchema),\n }) {}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;AAIA,SAASA,cAAc;AAEvB,SAASC,mBAAmB;AAErB,IAAMC,WAAN,cAAuBC,YAAY;EACxCC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDC,MAAMC,OAAOC,SAASD,OAAOE,MAAM;EACnCC,MAAMH,OAAOE;EACbE,KAAKJ,OAAOE;EACZG,WAAWL,OAAOC,SAASD,OAAOE,MAAM;AAC1C,CAAA,EAAA;AAAI;;;ACZJ,SAASI,UAAAA,eAAc;AAEvB,SAASC,sBAAsB;AAC/B,SAASC,mBAAmB;UAKXC,aAAAA;EACR,MAAMC,eAAeC,QAAOC,YAAW,EAAW,GAAGC,WAAAA,kBAA6B;IACvFC,OAAOC,eAAeC,KAAK,QAAQ,QAAQ,KAAA,EAAOC,KAAKN,QAAOO,QAAQ;IACtEC,QAAQR,QAAOS,OAAO;MACpBC,QAAQC;IACV,CAAA;EACF,CAAA,EAAA;EAAI;cALSZ,SAAAA;cAOAa,qBAAqBC,OAAOC,IAAI,GAAGZ,WAAAA,oBAA+B;cAElEa,mBAAmBf,QAAOS,OAAO;IAC5CO,MAAMhB,QAAOiB,WAAWC,IAAAA,EAAMC,YAAY;MACxC,CAAArB,YAACc,kBAAAA,GAAqB;;QAEpB,WAAW;UAAC;UAAQ;UAAS;UAAQ;;QACrC,mBAAmB;UAAC;;MAEtB;IACF,CAAA;EACF,CAAA;EAIO,MAAMQ,eAAepB,QAAOC,YAAW,EAAW,GAAGC,WAAAA,kBAA6B;IACvFC,OAAOH,QAAOqB,OAAMvB,YAACiB,kBAAkBf,QAAOS,OAAO;MAAEa,OAAOC;IAAY,CAAA,CAAA;IAC1Ef,QAAQR,QAAOO,SAASH,cAAAA;EAC1B,CAAA,EAAA;EAAI;cAHSgB,SAAAA;AAIf,GA3BiBtB,eAAAA,aAAAA,CAAAA,EAAAA;;",
|
|
6
|
-
"names": ["Schema", "TypedObject", "FileType", "TypedObject", "typename", "version", "name", "Schema", "optional", "String", "type", "cid", "timestamp", "Schema", "FileInfoSchema", "SpaceSchema", "WnfsAction", "Create", "Schema", "TaggedClass", "WNFS_PLUGIN", "input", "FileInfoSchema", "pick", "pipe", "required", "output", "Struct", "object", "FileType", "UploadAnnotationId", "Symbol", "for", "UploadFileSchema", "file", "instanceOf", "File", "annotations", "Upload", "extend", "space", "SpaceSchema"]
|
|
7
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WNFS_PLUGIN
|
|
3
|
-
} from "./chunk-VDDGZWAY.mjs";
|
|
4
|
-
|
|
5
|
-
// src/capabilities/capabilities.ts
|
|
6
|
-
import { defineCapability } from "@dxos/app-framework";
|
|
7
|
-
(function(WnfsCapabilities2) {
|
|
8
|
-
WnfsCapabilities2.Blockstore = defineCapability(`${WNFS_PLUGIN}/capability/blockstore`);
|
|
9
|
-
WnfsCapabilities2.Instances = defineCapability(`${WNFS_PLUGIN}/capability/instances`);
|
|
10
|
-
})(WnfsCapabilities || (WnfsCapabilities = {}));
|
|
11
|
-
var WnfsCapabilities;
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
WnfsCapabilities
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=chunk-KZANQHJY.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/capabilities.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Blockstore } from 'interface-blockstore';\nimport { type PrivateDirectory, type PrivateForest } from 'wnfs';\n\nimport { defineCapability } from '@dxos/app-framework';\nimport { type SpaceId } from '@dxos/keys';\n\nimport { WNFS_PLUGIN } from '../meta';\n\nexport namespace WnfsCapabilities {\n export const Blockstore = defineCapability<Blockstore>(`${WNFS_PLUGIN}/capability/blockstore`);\n\n export type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;\n export const Instances = defineCapability<Instances>(`${WNFS_PLUGIN}/capability/instances`);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;AAOA,SAASA,wBAAwB;UAKhBC,mBAAAA;oBACFC,aAAaC,iBAA6B,GAAGC,WAAAA,wBAAmC;oBAGhFC,YAAYF,iBAA4B,GAAGC,WAAAA,uBAAkC;AAC5F,GALiBH,qBAAAA,mBAAAA,CAAAA,EAAAA;;",
|
|
6
|
-
"names": ["defineCapability", "WnfsCapabilities", "Blockstore", "defineCapability", "WNFS_PLUGIN", "Instances"]
|
|
7
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// src/meta.ts
|
|
2
|
-
var WNFS_PLUGIN = "dxos.org/plugin/wnfs";
|
|
3
|
-
var meta = {
|
|
4
|
-
id: WNFS_PLUGIN,
|
|
5
|
-
name: "WNFS",
|
|
6
|
-
description: "Manage and view files with via the Web Native File System (WNFS).",
|
|
7
|
-
icon: "ph--file-cloud--regular",
|
|
8
|
-
source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs"
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
WNFS_PLUGIN,
|
|
13
|
-
meta
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=chunk-VDDGZWAY.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/meta.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const WNFS_PLUGIN = 'dxos.org/plugin/wnfs';\n\nexport const meta: PluginMeta = {\n id: WNFS_PLUGIN,\n name: 'WNFS',\n description: 'Manage and view files with via the Web Native File System (WNFS).',\n icon: 'ph--file-cloud--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',\n};\n"],
|
|
5
|
-
"mappings": ";AAMO,IAAMA,cAAc;AAEpB,IAAMC,OAAmB;EAC9BC,IAAIF;EACJG,MAAM;EACNC,aAAa;EACbC,MAAM;EACNC,QAAQ;AACV;",
|
|
6
|
-
"names": ["WNFS_PLUGIN", "meta", "id", "name", "description", "icon", "source"]
|
|
7
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// src/capabilities/index.ts
|
|
2
|
-
import { lazy } from "@dxos/app-framework";
|
|
3
|
-
var Blockstore = lazy(() => import("./blockstore-KQO2NTVM.mjs"));
|
|
4
|
-
var FileUploader = lazy(() => import("./file-uploader-JA55DPMW.mjs"));
|
|
5
|
-
var IntentResolver = lazy(() => import("./intent-resolver-YM6QRFIH.mjs"));
|
|
6
|
-
var Markdown = lazy(() => import("./markdown-6VH477GB.mjs"));
|
|
7
|
-
var ReactSurface = lazy(() => import("./react-surface-NOSB5MZ2.mjs"));
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
Blockstore,
|
|
11
|
-
FileUploader,
|
|
12
|
-
IntentResolver,
|
|
13
|
-
Markdown,
|
|
14
|
-
ReactSurface
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=chunk-WTYTESSC.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/file-uploader.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Effect, pipe } from 'effect';\n\nimport { Capabilities, chain, contributes, createIntent, type PluginContext } from '@dxos/app-framework';\nimport { SpaceAction } from '@dxos/plugin-space/types';\n\nimport { WnfsAction } from '../types';\n\nexport default (context: PluginContext) => {\n return contributes(Capabilities.FileUploader, (file, space) => {\n const { dispatch } = context.getCapability(Capabilities.IntentDispatcher);\n\n const program = Effect.gen(function* () {\n const fileInfo = yield* dispatch(createIntent(WnfsAction.Upload, { file, space }));\n yield* dispatch(pipe(createIntent(WnfsAction.Create, fileInfo), chain(SpaceAction.AddObject, { target: space })));\n return fileInfo;\n });\n\n return Effect.runPromise(program);\n });\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;AAIA,SAASA,QAAQC,YAAY;AAE7B,SAASC,cAAcC,OAAOC,aAAaC,oBAAwC;AACnF,SAASC,mBAAmB;AAI5B,IAAA,wBAAe,CAACC,YAAAA;AACd,SAAOC,YAAYC,aAAaC,cAAc,CAACC,MAAMC,UAAAA;AACnD,UAAM,EAAEC,SAAQ,IAAKN,QAAQO,cAAcL,aAAaM,gBAAgB;AAExE,UAAMC,UAAUC,OAAOC,IAAI,aAAA;AACzB,YAAMC,WAAW,OAAON,SAASO,aAAaC,WAAWC,QAAQ;QAAEX;QAAMC;MAAM,CAAA,CAAA;AAC/E,aAAOC,SAASU,KAAKH,aAAaC,WAAWG,QAAQL,QAAAA,GAAWM,MAAMC,YAAYC,WAAW;QAAEC,QAAQhB;MAAM,CAAA,CAAA,CAAA;AAC7G,aAAOO;IACT,CAAA;AAEA,WAAOF,OAAOY,WAAWb,OAAAA;EAC3B,CAAA;AACF;",
|
|
6
|
-
"names": ["Effect", "pipe", "Capabilities", "chain", "contributes", "createIntent", "SpaceAction", "context", "contributes", "Capabilities", "FileUploader", "file", "space", "dispatch", "getCapability", "IntentDispatcher", "program", "Effect", "gen", "fileInfo", "createIntent", "WnfsAction", "Upload", "pipe", "Create", "chain", "SpaceAction", "AddObject", "target", "runPromise"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/intent-resolver.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { contributes, Capabilities, createResolver, type PluginContext } from '@dxos/app-framework';\nimport { Obj } from '@dxos/echo';\n\nimport { WnfsCapabilities } from './capabilities';\nimport { upload } from '../helpers';\nimport { FileType, WnfsAction } from '../types';\n\nexport default (context: PluginContext) =>\n contributes(Capabilities.IntentResolver, [\n // TODO(wittjosiah): Deleting the object doesn't delete the wnfs blob.\n // Consider ways to trigger blob deletion based on object deletion and/or adding file system manager.\n createResolver({\n intent: WnfsAction.Create,\n resolve: ({ name, type, cid }) => ({\n data: {\n object: Obj.make(FileType, { name, type, cid }),\n },\n }),\n }),\n createResolver({\n intent: WnfsAction.Upload,\n resolve: async ({ file, space }) => {\n const blockstore = context.getCapability(WnfsCapabilities.Blockstore);\n const info = await upload({ file, blockstore, space });\n return { data: info };\n },\n }),\n ]);\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;AAIA,SAASA,aAAaC,cAAcC,sBAA0C;AAC9E,SAASC,WAAW;AAMpB,IAAA,0BAAe,CAACC,YACdC,YAAYC,aAAaC,gBAAgB;;;EAGvCC,eAAe;IACbC,QAAQC,WAAWC;IACnBC,SAAS,CAAC,EAAEC,MAAMC,MAAMC,IAAG,OAAQ;MACjCC,MAAM;QACJC,QAAQC,IAAIC,KAAKC,UAAU;UAAEP;UAAMC;UAAMC;QAAI,CAAA;MAC/C;IACF;EACF,CAAA;EACAP,eAAe;IACbC,QAAQC,WAAWW;IACnBT,SAAS,OAAO,EAAEU,MAAMC,MAAK,MAAE;AAC7B,YAAMC,aAAapB,QAAQqB,cAAcC,iBAAiBC,UAAU;AACpE,YAAMC,OAAO,MAAMC,OAAO;QAAEP;QAAME;QAAYD;MAAM,CAAA;AACpD,aAAO;QAAEP,MAAMY;MAAK;IACtB;EACF,CAAA;CACD;",
|
|
6
|
-
"names": ["contributes", "Capabilities", "createResolver", "Obj", "context", "contributes", "Capabilities", "IntentResolver", "createResolver", "intent", "WnfsAction", "Create", "resolve", "name", "type", "cid", "data", "object", "Obj", "make", "FileType", "Upload", "file", "space", "blockstore", "getCapability", "WnfsCapabilities", "Blockstore", "info", "upload"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/markdown.ts", "../../../src/extensions/image.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { contributes, type PluginContext } from '@dxos/app-framework';\nimport { MarkdownCapabilities } from '@dxos/plugin-markdown';\nimport { getSpace } from '@dxos/react-client/echo';\n\nimport { WnfsCapabilities } from './capabilities';\nimport { image } from '../extensions';\n\nexport default (context: PluginContext) =>\n contributes(MarkdownCapabilities.Extensions, [\n ({ document }) => {\n const blockstore = context.getCapability(WnfsCapabilities.Blockstore);\n const instances = context.getCapability(WnfsCapabilities.Instances);\n\n if (document) {\n const space = getSpace(document);\n return space ? [image({ blockstore, instances, space })] : [];\n }\n\n return [];\n },\n ]);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { syntaxTree } from '@codemirror/language';\nimport { type EditorState, type Extension, StateField, type Range } from '@codemirror/state';\nimport { Decoration, EditorView, WidgetType } from '@codemirror/view';\nimport type { Blockstore } from 'interface-blockstore';\nimport React from 'react';\nimport { createRoot } from 'react-dom/client';\n\nimport { type Space } from '@dxos/react-client/echo';\nimport { Status, ThemeProvider } from '@dxos/react-ui';\nimport { focusField } from '@dxos/react-ui-editor';\nimport { defaultTx } from '@dxos/react-ui-theme';\nimport { type MaybePromise } from '@dxos/util';\n\nimport { type WnfsCapabilities } from '../capabilities';\nimport { getBlobUrl, getPathFromUrl, loadWnfs } from '../helpers';\n\nconst WAIT_UNTIL_LOADER = 1500;\n\nexport type ImageOptions = {\n blockstore: Blockstore;\n instances: WnfsCapabilities.Instances;\n space: Space;\n};\n\n/**\n * Create WNFS image decorations.\n */\nexport const image = (options: ImageOptions): Extension[] => {\n const blobUrlCache: Record<string, string> = {};\n const preloaded = new Set<string>();\n\n const preload = (url: string) => {\n if (!preloaded.has(url)) {\n const img = document.createElement('img');\n img.src = url;\n preloaded.add(url);\n }\n };\n\n return [\n StateField.define({\n create: (state) => {\n return Decoration.set(\n buildDecorations({ from: 0, to: state.doc.length, state, blobUrlCache, preload, options }),\n );\n },\n update: (value, tr) => {\n if (!tr.docChanged && !tr.selection) {\n return value;\n }\n\n // Find range of changes and cursor changes.\n const cursor = tr.state.selection.main.head;\n const oldCursor = tr.changes.mapPos(tr.startState.selection.main.head);\n let from = Math.min(cursor, oldCursor);\n let to = Math.max(cursor, oldCursor);\n tr.changes.iterChangedRanges((fromA, toA, fromB, toB) => {\n from = Math.min(from, fromB);\n to = Math.max(to, toB);\n });\n\n // Expand to cover lines.\n from = tr.state.doc.lineAt(from).from;\n to = tr.state.doc.lineAt(to).to;\n\n return value.map(tr.changes).update({\n filterFrom: from,\n filterTo: to,\n filter: () => false,\n add: buildDecorations({ from, to, state: tr.state, blobUrlCache, preload, options }),\n });\n },\n provide: (field) => EditorView.decorations.from(field),\n }),\n ];\n};\n\nconst buildDecorations = ({\n from,\n to,\n state,\n blobUrlCache,\n preload,\n options: { blockstore, instances, space },\n}: {\n from: number;\n to: number;\n state: EditorState;\n blobUrlCache: Record<string, string>;\n preload: (url: string) => void;\n options: ImageOptions;\n}) => {\n const decorations: Range<Decoration>[] = [];\n const cursor = state.selection.main.head;\n syntaxTree(state).iterate({\n enter: (node) => {\n if (node.name !== 'Image') {\n return;\n }\n\n const urlNode = node.node.getChild('URL');\n if (!urlNode) {\n return;\n }\n\n const hide = state.readOnly || cursor < node.from || cursor > node.to;\n const wnfsUrl = state.sliceDoc(urlNode.from, urlNode.to);\n if (!wnfsUrl.startsWith('wnfs://')) {\n return;\n }\n\n const path = getPathFromUrl(wnfsUrl);\n\n // Cannot load images from other spaces\n const spaceId = path[1];\n if (spaceId !== space.id) {\n return;\n }\n\n // Load image contents into memory blob\n const blobUrlPromise = (async () => {\n const { directory, forest } = await loadWnfs({ blockstore, instances, space });\n const url = await getBlobUrl({ wnfsUrl, blockstore, directory, forest });\n blobUrlCache[path.join('/')] = url;\n preload(url);\n return url;\n })();\n\n decorations.push(\n Decoration.replace({\n block: true, // Prevent cursor from entering.\n widget: new WnfsImageWidget(wnfsUrl, blobUrlCache[path.join('/')] ?? blobUrlPromise),\n }).range(hide ? node.from : node.to, node.to),\n );\n },\n from,\n to,\n });\n\n return decorations;\n};\n\nconst createImg = (view: EditorView, url: string) => {\n const img = document.createElement('img');\n img.setAttribute('src', url);\n img.setAttribute('class', 'cm-image-with-loader');\n // If focused, hide image until successfully loaded to avoid flickering effects.\n if (view.state.field(focusField)) {\n img.onload = () => img.classList.add('cm-loaded-image');\n } else {\n img.classList.add('cm-loaded-image');\n }\n return img;\n};\n\nclass WnfsImageWidget extends WidgetType {\n constructor(\n readonly _wnfsUrl: string,\n readonly _url: MaybePromise<string>,\n ) {\n super();\n }\n\n override eq(other: this): boolean {\n return this._wnfsUrl === (other as any as WnfsImageWidget)._wnfsUrl;\n }\n\n override toDOM(view: EditorView): HTMLDivElement {\n if (typeof this._url === 'string') {\n return createImg(view, this._url);\n }\n\n const widget = document.createElement('div');\n widget.className = 'cm-image-wrapper';\n const loader = document.createElement('div');\n loader.className = 'mx-auto transition-opacity';\n let loaderAdded = false;\n\n const timeout = setTimeout(() => {\n const root = createRoot(loader);\n root.render(\n <ThemeProvider tx={defaultTx}>\n <Status indeterminate />\n </ThemeProvider>,\n );\n widget.appendChild(loader);\n loaderAdded = true;\n }, WAIT_UNTIL_LOADER);\n\n void this._url.then((url) => {\n clearTimeout(timeout);\n const img = createImg(view, url);\n loaderAdded && widget.removeChild(loader);\n widget.appendChild(img);\n });\n\n return widget;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;AAIA,SAASA,mBAAuC;AAChD,SAASC,4BAA4B;AACrC,SAASC,gBAAgB;;;ACFzB,SAASC,kBAAkB;AAC3B,SAA2CC,kBAA8B;AACzE,SAASC,YAAYC,YAAYC,kBAAkB;AAEnD,OAAOC,WAAW;AAClB,SAASC,kBAAkB;AAG3B,SAASC,QAAQC,qBAAqB;AACtC,SAASC,kBAAkB;AAC3B,SAASC,iBAAiB;AAM1B,IAAMC,oBAAoB;AAWnB,IAAMC,QAAQ,CAACC,YAAAA;AACpB,QAAMC,eAAuC,CAAC;AAC9C,QAAMC,YAAY,oBAAI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,OAAO+B,YAAYf,MAAAA;AAClChB,aAAO4B,YAAYrG,GAAAA;IACrB,CAAA;AAEA,WAAOyE;EACT;AACF;;;AD/LA,IAAA,mBAAe,CAACgC,YACdC,YAAYC,qBAAqBC,YAAY;EAC3C,CAAC,EAAEC,UAAAA,UAAQ,MAAE;AACX,UAAMC,aAAaL,QAAQM,cAAcC,iBAAiBC,UAAU;AACpE,UAAMC,YAAYT,QAAQM,cAAcC,iBAAiBG,SAAS;AAElE,QAAIN,WAAU;AACZ,YAAMO,QAAQC,SAASR,SAAAA;AACvB,aAAOO,QAAQ;QAACE,MAAM;UAAER;UAAYI;UAAWE;QAAM,CAAA;UAAM,CAAA;IAC7D;AAEA,WAAO,CAAA;EACT;CACD;",
|
|
6
|
-
"names": ["contributes", "MarkdownCapabilities", "getSpace", "syntaxTree", "StateField", "Decoration", "EditorView", "WidgetType", "React", "createRoot", "Status", "ThemeProvider", "focusField", "defaultTx", "WAIT_UNTIL_LOADER", "image", "options", "blobUrlCache", "preloaded", "Set", "preload", "url", "has", "img", "document", "createElement", "src", "add", "StateField", "define", "create", "state", "Decoration", "set", "buildDecorations", "from", "to", "doc", "length", "update", "value", "tr", "docChanged", "selection", "cursor", "main", "head", "oldCursor", "changes", "mapPos", "startState", "Math", "min", "max", "iterChangedRanges", "fromA", "toA", "fromB", "toB", "lineAt", "map", "filterFrom", "filterTo", "filter", "provide", "field", "EditorView", "decorations", "blockstore", "instances", "space", "syntaxTree", "iterate", "enter", "node", "name", "urlNode", "getChild", "hide", "readOnly", "wnfsUrl", "sliceDoc", "startsWith", "path", "getPathFromUrl", "spaceId", "id", "blobUrlPromise", "directory", "forest", "loadWnfs", "getBlobUrl", "join", "push", "replace", "block", "widget", "WnfsImageWidget", "range", "createImg", "view", "setAttribute", "focusField", "onload", "classList", "WidgetType", "_wnfsUrl", "_url", "eq", "other", "toDOM", "className", "loader", "loaderAdded", "timeout", "setTimeout", "root", "createRoot", "render", "ThemeProvider", "tx", "defaultTx", "Status", "indeterminate", "appendChild", "then", "clearTimeout", "removeChild", "context", "contributes", "MarkdownCapabilities", "Extensions", "document", "blockstore", "getCapability", "WnfsCapabilities", "Blockstore", "instances", "Instances", "space", "getSpace", "image"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/react-surface.tsx", "../../../src/components/index.ts", "../../../src/components/FileInput.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\nimport React, { useCallback } from 'react';\n\nimport { contributes, Capabilities, createSurface } from '@dxos/app-framework';\nimport { Obj } from '@dxos/echo';\nimport { findAnnotation } from '@dxos/effect';\nimport { type InputProps } from '@dxos/react-ui-form';\n\nimport { FileContainer, FileInput } from '../components';\nimport { WNFS_PLUGIN } from '../meta';\nimport { FileType, WnfsAction } from '../types';\n\nexport default () =>\n contributes(Capabilities.ReactSurface, [\n createSurface({\n id: `${WNFS_PLUGIN}/article`,\n role: ['article', 'section', 'slide'],\n filter: (data): data is { subject: FileType } => Obj.instanceOf(FileType, data.subject),\n component: ({ data, role }) => <FileContainer role={role} file={data.subject} />,\n }),\n createSurface({\n id: `${WNFS_PLUGIN}/create-form`,\n role: 'form-input',\n filter: (data): data is { prop: string; schema: Schema.Schema.Any } => {\n const annotation = findAnnotation<boolean>(\n (data.schema as Schema.Schema.All).ast,\n WnfsAction.UploadAnnotationId,\n );\n return !!annotation;\n },\n component: ({ data: { prop, schema }, ...props }) => {\n const inputProps = props as unknown as InputProps;\n const handleChange = useCallback(\n (file: File) => inputProps.onValueChange?.('object', file),\n [prop, inputProps.onValueChange],\n );\n\n return <FileInput schema={schema} onChange={handleChange} />;\n },\n }),\n ]);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { lazy } from 'react';\n\nexport const FileContainer = lazy(() => import('./FileContainer'));\n\nexport * from './FileInput';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\nimport React, { useCallback } from 'react';\nimport { useDropzone } from 'react-dropzone';\n\nimport { findAnnotation } from '@dxos/effect';\nimport { useTranslation } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { WNFS_PLUGIN } from '../meta';\nimport { WnfsAction } from '../types';\n\nexport type FileInputProps = {\n schema: Schema.Schema.Any;\n onChange: (file: File) => void;\n};\n\nexport const FileInput = ({ schema, onChange }: FileInputProps) => {\n const { t } = useTranslation(WNFS_PLUGIN);\n const accept = findAnnotation<Record<string, string[]>>(schema.ast, WnfsAction.UploadAnnotationId);\n\n const onDropAccepted = useCallback((files: File[]) => onChange?.(files[0]), [onChange]);\n\n const { acceptedFiles, getRootProps, getInputProps, isFocused, isDragAccept, isDragReject } = useDropzone({\n multiple: false,\n accept,\n onDropAccepted,\n });\n\n return (\n <div\n {...getRootProps()}\n className={mx(\n 'flex flex-col items-center p-8 border border-separator',\n isFocused && 'focus-ring',\n isDragAccept && 'bg-attention',\n isDragReject && 'border-error',\n )}\n >\n <input {...getInputProps()} />\n {acceptedFiles[0] ? <p>{acceptedFiles[0].name}</p> : <p>{t('file input placeholder')}</p>}\n </div>\n );\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;AAKA,OAAOA,UAASC,eAAAA,oBAAmB;AAEnC,SAASC,aAAaC,cAAcC,qBAAqB;AACzD,SAASC,WAAW;AACpB,SAASC,kBAAAA,uBAAsB;;;ACL/B,SAASC,YAAY;;;;ACCrB,OAAOC,SAASC,mBAAmB;AACnC,SAASC,mBAAmB;AAE5B,SAASC,sBAAsB;AAC/B,SAASC,sBAAsB;AAC/B,SAASC,UAAU;AAUZ,IAAMC,YAAY,CAAC,EAAEC,QAAQC,SAAQ,MAAkB;;;AAC5D,UAAM,EAAEC,EAAC,IAAKC,eAAeC,WAAAA;AAC7B,UAAMC,SAASC,eAAyCN,OAAOO,KAAKC,WAAWC,kBAAkB;AAEjG,UAAMC,iBAA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AGlC,aAAO,gBAAAd,OAAA,cAACe,WAAAA;QAAUV;QAAgBW,UAAUJ;;IAC9C;EACF,CAAA;CACD;",
|
|
6
|
-
"names": ["React", "useCallback", "contributes", "Capabilities", "createSurface", "Obj", "findAnnotation", "lazy", "React", "useCallback", "useDropzone", "findAnnotation", "useTranslation", "mx", "FileInput", "schema", "onChange", "t", "useTranslation", "WNFS_PLUGIN", "accept", "findAnnotation", "ast", "WnfsAction", "UploadAnnotationId", "onDropAccepted", "useCallback", "files", "acceptedFiles", "getRootProps", "getInputProps", "isFocused", "isDragAccept", "isDragReject", "useDropzone", "multiple", "div", "className", "mx", "input", "p", "name", "FileContainer", "lazy", "contributes", "Capabilities", "ReactSurface", "createSurface", "id", "WNFS_PLUGIN", "role", "filter", "data", "Obj", "instanceOf", "FileType", "subject", "component", "React", "FileContainer", "file", "annotation", "findAnnotation", "schema", "ast", "WnfsAction", "UploadAnnotationId", "prop", "props", "inputProps", "handleChange", "useCallback", "onValueChange", "FileInput", "onChange"]
|
|
7
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Schema } from 'effect';
|
|
2
|
-
declare const FileType_base: import("@dxos/echo-schema").TypedObjectPrototype<import("@dxos/echo-schema").TypedObjectFields<{
|
|
3
|
-
name: Schema.optional<typeof Schema.String>;
|
|
4
|
-
type: typeof Schema.String;
|
|
5
|
-
cid: typeof Schema.String;
|
|
6
|
-
timestamp: Schema.optional<typeof Schema.String>;
|
|
7
|
-
}, import("@dxos/echo-schema").TypedObjectOptions>, Schema.Struct.Encoded<{
|
|
8
|
-
name: Schema.optional<typeof Schema.String>;
|
|
9
|
-
type: typeof Schema.String;
|
|
10
|
-
cid: typeof Schema.String;
|
|
11
|
-
timestamp: Schema.optional<typeof Schema.String>;
|
|
12
|
-
}>>;
|
|
13
|
-
export declare class FileType extends FileType_base {
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=file.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../../src/types/file.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;;;;;;;;;AAIhC,qBAAa,QAAS,SAAQ,aAQ5B;CAAG"}
|
package/src/types/file.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
|
-
|
|
7
|
-
import { TypedObject } from '@dxos/echo-schema';
|
|
8
|
-
|
|
9
|
-
export class FileType extends TypedObject({
|
|
10
|
-
typename: 'dxos.org/type/File',
|
|
11
|
-
version: '0.1.0',
|
|
12
|
-
})({
|
|
13
|
-
name: Schema.optional(Schema.String),
|
|
14
|
-
type: Schema.String,
|
|
15
|
-
cid: Schema.String,
|
|
16
|
-
timestamp: Schema.optional(Schema.String),
|
|
17
|
-
}) {}
|
|
File without changes
|