@dxos/plugin-wnfs 0.8.4-main.3eb6e50203 → 0.8.4-main.4a85c3132b
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-FUAINNAS.mjs → FileContainer-EILNV5LV.mjs} +22 -39
- package/dist/lib/browser/FileContainer-EILNV5LV.mjs.map +7 -0
- package/dist/lib/browser/{blockstore-U42RF6KA.mjs → blockstore-Q66HQJ4Q.mjs} +3 -3
- package/dist/lib/browser/{chunk-PCYQNMXS.mjs → chunk-BXGCJRL2.mjs} +3 -3
- package/dist/lib/browser/{chunk-PCYQNMXS.mjs.map → chunk-BXGCJRL2.mjs.map} +3 -3
- package/dist/lib/browser/chunk-HXVPBJ3A.mjs +56 -0
- package/dist/lib/browser/chunk-HXVPBJ3A.mjs.map +7 -0
- package/dist/lib/browser/{chunk-NCTUASHL.mjs → chunk-UC4HMNZZ.mjs} +8 -6
- package/dist/lib/browser/chunk-UC4HMNZZ.mjs.map +7 -0
- package/dist/lib/browser/{file-uploader-VBBUS2GG.mjs → file-uploader-QL4DTOMM.mjs} +2 -2
- package/dist/lib/browser/index.mjs +6 -6
- package/dist/lib/browser/{markdown-ZLOS5HZU.mjs → markdown-AYCVG6TJ.mjs} +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{operation-resolver-7TLMWGST.mjs → operation-resolver-YYWUF6EY.mjs} +5 -5
- package/dist/lib/browser/operation-resolver-YYWUF6EY.mjs.map +7 -0
- package/dist/lib/browser/react-surface-3LKVDPH7.mjs +60 -0
- package/dist/lib/browser/react-surface-3LKVDPH7.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/types/src/capabilities/blockstore/blockstore.d.ts +1 -1
- package/dist/types/src/capabilities/file-uploader/file-uploader.d.ts +1 -1
- package/dist/types/src/capabilities/markdown/markdown.d.ts +1 -1
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -1
- 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/{components → containers/FileContainer}/FileContainer.d.ts +1 -1
- package/dist/types/src/containers/FileContainer/FileContainer.d.ts.map +1 -0
- package/dist/types/src/containers/FileContainer/index.d.ts +3 -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/types/File.d.ts +1 -1
- package/dist/types/src/types/types.d.ts +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -29
- package/src/capabilities/operation-resolver/operation-resolver.ts +2 -2
- package/src/capabilities/react-surface/react-surface.tsx +2 -1
- package/src/components/FileInput.tsx +2 -2
- package/src/components/FilePreview.tsx +3 -3
- package/src/components/index.ts +1 -4
- package/src/{components → containers/FileContainer}/FileContainer.tsx +11 -10
- package/src/containers/FileContainer/index.ts +7 -0
- package/src/containers/index.ts +7 -0
- package/src/extensions/image.stories.tsx +2 -2
- package/src/types/types.ts +1 -1
- package/dist/lib/browser/FileContainer-FUAINNAS.mjs.map +0 -7
- package/dist/lib/browser/chunk-NCTUASHL.mjs.map +0 -7
- package/dist/lib/browser/operation-resolver-7TLMWGST.mjs.map +0 -7
- package/dist/lib/browser/react-surface-YTIVVF2C.mjs +0 -82
- package/dist/lib/browser/react-surface-YTIVVF2C.mjs.map +0 -7
- package/dist/types/src/components/FileContainer.d.ts.map +0 -1
- /package/dist/lib/browser/{blockstore-U42RF6KA.mjs.map → blockstore-Q66HQJ4Q.mjs.map} +0 -0
- /package/dist/lib/browser/{file-uploader-VBBUS2GG.mjs.map → file-uploader-QL4DTOMM.mjs.map} +0 -0
- /package/dist/lib/browser/{markdown-ZLOS5HZU.mjs.map → markdown-AYCVG6TJ.mjs.map} +0 -0
|
@@ -3,44 +3,21 @@ import {
|
|
|
3
3
|
getBlobUrl,
|
|
4
4
|
loadWnfs,
|
|
5
5
|
wnfsUrl
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-UC4HMNZZ.mjs";
|
|
7
|
+
import {
|
|
8
|
+
FilePreview
|
|
9
|
+
} from "./chunk-HXVPBJ3A.mjs";
|
|
7
10
|
import {
|
|
8
11
|
WnfsCapabilities
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-BXGCJRL2.mjs";
|
|
10
13
|
|
|
11
|
-
// src/
|
|
12
|
-
import
|
|
14
|
+
// src/containers/FileContainer/FileContainer.tsx
|
|
15
|
+
import React, { useState } from "react";
|
|
13
16
|
import { useCapability } from "@dxos/app-framework/ui";
|
|
14
17
|
import { invariant } from "@dxos/invariant";
|
|
15
18
|
import { getSpace } from "@dxos/react-client/echo";
|
|
16
|
-
import { useAsyncEffect } from "@dxos/react-ui";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// src/components/FilePreview.tsx
|
|
20
|
-
import React from "react";
|
|
21
|
-
import { mx } from "@dxos/ui-theme";
|
|
22
|
-
var FilePreview = ({ type, url, classNames }) => {
|
|
23
|
-
if (type.startsWith("image/")) {
|
|
24
|
-
return /* @__PURE__ */ React.createElement("img", {
|
|
25
|
-
className: mx("is-full bs-full object-contain", classNames),
|
|
26
|
-
src: url
|
|
27
|
-
});
|
|
28
|
-
} else if (type.startsWith("video/")) {
|
|
29
|
-
return /* @__PURE__ */ React.createElement("video", {
|
|
30
|
-
className: mx("is-full bs-full object-contain", classNames),
|
|
31
|
-
src: url,
|
|
32
|
-
controls: true
|
|
33
|
-
});
|
|
34
|
-
} else {
|
|
35
|
-
return /* @__PURE__ */ React.createElement("iframe", {
|
|
36
|
-
className: mx("is-full bs-full overflow-auto", classNames),
|
|
37
|
-
src: url
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// src/components/FileContainer.tsx
|
|
43
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/components/FileContainer.tsx";
|
|
19
|
+
import { Panel, useAsyncEffect } from "@dxos/react-ui";
|
|
20
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/containers/FileContainer/FileContainer.tsx";
|
|
44
21
|
var FileContainer = ({ role, subject: file }) => {
|
|
45
22
|
const blockstore = useCapability(WnfsCapabilities.Blockstore);
|
|
46
23
|
const instances = useCapability(WnfsCapabilities.Instances);
|
|
@@ -49,7 +26,7 @@ var FileContainer = ({ role, subject: file }) => {
|
|
|
49
26
|
const space = getSpace(file);
|
|
50
27
|
invariant(space, void 0, {
|
|
51
28
|
F: __dxlog_file,
|
|
52
|
-
L:
|
|
29
|
+
L: 26,
|
|
53
30
|
S: void 0,
|
|
54
31
|
A: [
|
|
55
32
|
"space",
|
|
@@ -76,16 +53,22 @@ var FileContainer = ({ role, subject: file }) => {
|
|
|
76
53
|
if (!blobUrl) {
|
|
77
54
|
return null;
|
|
78
55
|
}
|
|
79
|
-
return /* @__PURE__ */
|
|
80
|
-
role
|
|
81
|
-
|
|
56
|
+
return /* @__PURE__ */ React.createElement(Panel.Root, {
|
|
57
|
+
role,
|
|
58
|
+
className: "dx-article"
|
|
59
|
+
}, /* @__PURE__ */ React.createElement(Panel.Content, {
|
|
60
|
+
asChild: true
|
|
61
|
+
}, /* @__PURE__ */ React.createElement(Panel.Content, {
|
|
62
|
+
asChild: true
|
|
63
|
+
}, /* @__PURE__ */ React.createElement(FilePreview, {
|
|
82
64
|
type: file.type,
|
|
83
65
|
url: blobUrl
|
|
84
|
-
}));
|
|
66
|
+
}))));
|
|
85
67
|
};
|
|
68
|
+
|
|
69
|
+
// src/containers/FileContainer/index.ts
|
|
86
70
|
var FileContainer_default = FileContainer;
|
|
87
71
|
export {
|
|
88
|
-
FileContainer,
|
|
89
72
|
FileContainer_default as default
|
|
90
73
|
};
|
|
91
|
-
//# sourceMappingURL=FileContainer-
|
|
74
|
+
//# sourceMappingURL=FileContainer-EILNV5LV.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/containers/FileContainer/FileContainer.tsx", "../../../src/containers/FileContainer/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { useState } from 'react';\n\nimport { useCapability } from '@dxos/app-framework/ui';\nimport { type SurfaceComponentProps } from '@dxos/app-toolkit/ui';\nimport { invariant } from '@dxos/invariant';\nimport { getSpace } from '@dxos/react-client/echo';\nimport { Panel, useAsyncEffect } from '@dxos/react-ui';\n\nimport { FilePreview } from '../../components';\nimport { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../../helpers';\nimport { WnfsCapabilities, type WnfsFile } from '../../types';\n\nexport type FileContainerProps = SurfaceComponentProps<WnfsFile.File>;\n\nexport const FileContainer = ({ role, subject: file }: FileContainerProps) => {\n const blockstore = useCapability(WnfsCapabilities.Blockstore);\n const instances = useCapability(WnfsCapabilities.Instances);\n const [blobUrl, setBlobUrl] = useState<string>();\n\n useAsyncEffect(async () => {\n const space = getSpace(file);\n invariant(space);\n const { directory, forest } = await loadWnfs({\n blockstore,\n instances,\n space,\n });\n const path = filePath(file.cid.toString(), space);\n const url = await getBlobUrl({\n wnfsUrl: wnfsUrl(path),\n blockstore,\n directory,\n forest,\n type: file.type,\n });\n setBlobUrl(url);\n }, [file]);\n\n if (!blobUrl) {\n return null;\n }\n\n return (\n <Panel.Root role={role} className='dx-article'>\n <Panel.Content asChild>\n <Panel.Content asChild>\n <FilePreview type={file.type} url={blobUrl} />\n </Panel.Content>\n </Panel.Content>\n </Panel.Root>\n );\n};\n\nexport default FileContainer;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { FileContainer } from './FileContainer';\n\nexport default FileContainer;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAIA,OAAOA,SAASC,gBAAgB;AAEhC,SAASC,qBAAqB;AAE9B,SAASC,iBAAiB;AAC1B,SAASC,gBAAgB;AACzB,SAASC,OAAOC,sBAAsB;;AAQ/B,IAAMC,gBAAgB,CAAC,EAAEC,MAAMC,SAASC,KAAI,MAAsB;AACvE,QAAMC,aAAaC,cAAcC,iBAAiBC,UAAU;AAC5D,QAAMC,YAAYH,cAAcC,iBAAiBG,SAAS;AAC1D,QAAM,CAACC,SAASC,UAAAA,IAAcC,SAAAA;AAE9BC,iBAAe,YAAA;AACb,UAAMC,QAAQC,SAASZ,IAAAA;AACvBa,cAAUF,OAAAA,QAAAA;;;;;;;;;AACV,UAAM,EAAEG,WAAWC,OAAM,IAAK,MAAMC,SAAS;MAC3Cf;MACAI;MACAM;IACF,CAAA;AACA,UAAMM,OAAOC,SAASlB,KAAKmB,IAAIC,SAAQ,GAAIT,KAAAA;AAC3C,UAAMU,MAAM,MAAMC,WAAW;MAC3BC,SAASA,QAAQN,IAAAA;MACjBhB;MACAa;MACAC;MACAS,MAAMxB,KAAKwB;IACb,CAAA;AACAhB,eAAWa,GAAAA;EACb,GAAG;IAACrB;GAAK;AAET,MAAI,CAACO,SAAS;AACZ,WAAO;EACT;AAEA,SACE,sBAAA,cAACkB,MAAMC,MAAI;IAAC5B;IAAY6B,WAAU;KAChC,sBAAA,cAACF,MAAMG,SAAO;IAACC,SAAAA;KACb,sBAAA,cAACJ,MAAMG,SAAO;IAACC,SAAAA;KACb,sBAAA,cAACC,aAAAA;IAAYN,MAAMxB,KAAKwB;IAAMH,KAAKd;;AAK7C;;;ACjDA,IAAA,wBAAewB;",
|
|
6
|
+
"names": ["React", "useState", "useCapability", "invariant", "getSpace", "Panel", "useAsyncEffect", "FileContainer", "role", "subject", "file", "blockstore", "useCapability", "WnfsCapabilities", "Blockstore", "instances", "Instances", "blobUrl", "setBlobUrl", "useState", "useAsyncEffect", "space", "getSpace", "invariant", "directory", "forest", "loadWnfs", "path", "filePath", "cid", "toString", "url", "getBlobUrl", "wnfsUrl", "type", "Panel", "Root", "className", "Content", "asChild", "FilePreview", "FileContainer"]
|
|
7
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
storeName
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UC4HMNZZ.mjs";
|
|
4
4
|
import {
|
|
5
5
|
WnfsCapabilities
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BXGCJRL2.mjs";
|
|
7
7
|
|
|
8
8
|
// src/capabilities/blockstore/blockstore.ts
|
|
9
9
|
import * as Effect from "effect/Effect";
|
|
@@ -188,4 +188,4 @@ var blockstore_default = Capability.makeModule(Effect.fnUntraced(function* () {
|
|
|
188
188
|
export {
|
|
189
189
|
blockstore_default as default
|
|
190
190
|
};
|
|
191
|
-
//# sourceMappingURL=blockstore-
|
|
191
|
+
//# sourceMappingURL=blockstore-Q66HQJ4Q.mjs.map
|
|
@@ -53,11 +53,11 @@ import * as Schema2 from "effect/Schema";
|
|
|
53
53
|
import { Capability as Capability2 } from "@dxos/app-framework";
|
|
54
54
|
import { FileInfoSchema } from "@dxos/app-toolkit";
|
|
55
55
|
import { Database } from "@dxos/echo";
|
|
56
|
+
import { Collection } from "@dxos/echo";
|
|
56
57
|
import { Operation } from "@dxos/operation";
|
|
57
58
|
import { SpaceSchema } from "@dxos/react-client/echo";
|
|
58
|
-
import { Collection } from "@dxos/schema";
|
|
59
59
|
(function(WnfsAction2) {
|
|
60
|
-
WnfsAction2.UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);
|
|
60
|
+
WnfsAction2.UploadAnnotationId = /* @__PURE__ */ Symbol.for(`${meta.id}/annotation/upload`);
|
|
61
61
|
WnfsAction2.UploadFileSchema = Schema2.Struct({
|
|
62
62
|
file: Schema2.instanceOf(File).annotations({
|
|
63
63
|
[WnfsAction2.UploadAnnotationId]: {
|
|
@@ -152,4 +152,4 @@ export {
|
|
|
152
152
|
WnfsAction,
|
|
153
153
|
WnfsOperation
|
|
154
154
|
};
|
|
155
|
-
//# sourceMappingURL=chunk-
|
|
155
|
+
//# sourceMappingURL=chunk-BXGCJRL2.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/types/capabilities.ts", "../../../src/meta.ts", "../../../src/types/File.ts", "../../../src/types/types.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 { Capability } from '@dxos/app-framework';\nimport { type SpaceId } from '@dxos/keys';\n\nimport { meta } from '../meta';\n\nexport namespace WnfsCapabilities {\n export const Blockstore = Capability.make<Blockstore>(`${meta.id}/capability/blockstore`);\n\n export type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;\n export const Instances = Capability.make<Instances>(`${meta.id}/capability/instances`);\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Plugin } from '@dxos/app-framework';\nimport { trim } from '@dxos/util';\n\nexport const meta: Plugin.Meta = {\n id: 'dxos.org/plugin/wnfs',\n name: 'WNFS',\n description: trim`\n Decentralized file storage using the Web Native File System protocol.\n Store and sync files with end-to-end encryption across devices without central servers.\n `,\n icon: 'ph--file-cloud--regular',\n iconHue: 'teal',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Obj, Type } from '@dxos/echo';\nimport { FormInputAnnotation } from '@dxos/echo/internal';\n\nexport const File = Schema.Struct({\n name: Schema.String.pipe(Schema.optional),\n type: Schema.String.pipe(FormInputAnnotation.set(false)),\n cid: Schema.String.pipe(FormInputAnnotation.set(false)),\n timestamp: Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional),\n}).pipe(\n Type.object({\n typename: 'dxos.org/type/File',\n version: '0.1.0',\n }),\n);\n\nexport type File = Schema.Schema.Type<typeof File>;\n\nexport const make = (props: Obj.MakeProps<typeof File>) => Obj.make(File, props);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Capability } from '@dxos/app-framework';\nimport { FileInfoSchema } from '@dxos/app-toolkit';\nimport { Database } from '@dxos/echo';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;AAOA,SAASA,kBAAkB;;;ACF3B,SAASC,YAAY;AAEd,IAAMC,OAAoB;EAC/BC,IAAI;EACJC,MAAM;EACNC,aAAaC;;;;EAIbC,MAAM;EACNC,SAAS;EACTC,QAAQ;AACV;;;UDLiBC,mBAAAA;oBACFC,aAAaC,WAAWC,KAAiB,GAAGC,KAAKC,EAAE,wBAAwB;oBAG3EC,YAAYJ,WAAWC,KAAgB,GAAGC,KAAKC,EAAE,uBAAuB;AACvF,GALiBL,qBAAAA,mBAAAA,CAAAA,EAAAA;;;;AEZjB;;;;;AAIA,YAAYO,YAAY;AAExB,SAASC,KAAKC,YAAY;AAC1B,SAASC,2BAA2B;AAE7B,IAAMC,OAAcC,cAAO;EAChCC,MAAaC,cAAOC,KAAYC,eAAQ;EACxCC,MAAaH,cAAOC,KAAKG,oBAAoBC,IAAI,KAAA,CAAA;EACjDC,KAAYN,cAAOC,KAAKG,oBAAoBC,IAAI,KAAA,CAAA;EAChDE,WAAkBP,cAAOC,KAAKG,oBAAoBC,IAAI,KAAA,GAAeH,eAAQ;AAC/E,CAAA,EAAGD,KACDO,KAAKC,OAAO;EACVC,UAAU;EACVC,SAAS;AACX,CAAA,CAAA;AAKK,IAAMC,OAAO,CAACC,UAAsCC,IAAIF,KAAKf,MAAMgB,KAAAA;;;ACnB1E,YAAYE,aAAY;AAExB,SAASC,cAAAA,mBAAkB;AAC3B,SAASC,sBAAsB;AAC/B,SAASC,gBAAgB;AACzB,SAASC,
|
|
6
|
-
"names": ["Capability", "trim", "meta", "id", "name", "description", "trim", "icon", "iconHue", "source", "WnfsCapabilities", "Blockstore", "Capability", "make", "meta", "id", "Instances", "Schema", "Obj", "Type", "FormInputAnnotation", "File", "Struct", "name", "String", "pipe", "optional", "type", "FormInputAnnotation", "set", "cid", "timestamp", "Type", "object", "typename", "version", "make", "props", "Obj", "Schema", "Capability", "FileInfoSchema", "Database", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Blockstore } from 'interface-blockstore';\nimport { type PrivateDirectory, type PrivateForest } from 'wnfs';\n\nimport { Capability } from '@dxos/app-framework';\nimport { type SpaceId } from '@dxos/keys';\n\nimport { meta } from '../meta';\n\nexport namespace WnfsCapabilities {\n export const Blockstore = Capability.make<Blockstore>(`${meta.id}/capability/blockstore`);\n\n export type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;\n export const Instances = Capability.make<Instances>(`${meta.id}/capability/instances`);\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Plugin } from '@dxos/app-framework';\nimport { trim } from '@dxos/util';\n\nexport const meta: Plugin.Meta = {\n id: 'dxos.org/plugin/wnfs',\n name: 'WNFS',\n description: trim`\n Decentralized file storage using the Web Native File System protocol.\n Store and sync files with end-to-end encryption across devices without central servers.\n `,\n icon: 'ph--file-cloud--regular',\n iconHue: 'teal',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Obj, Type } from '@dxos/echo';\nimport { FormInputAnnotation } from '@dxos/echo/internal';\n\nexport const File = Schema.Struct({\n name: Schema.String.pipe(Schema.optional),\n type: Schema.String.pipe(FormInputAnnotation.set(false)),\n cid: Schema.String.pipe(FormInputAnnotation.set(false)),\n timestamp: Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional),\n}).pipe(\n Type.object({\n typename: 'dxos.org/type/File',\n version: '0.1.0',\n }),\n);\n\nexport type File = Schema.Schema.Type<typeof File>;\n\nexport const make = (props: Obj.MakeProps<typeof File>) => Obj.make(File, props);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Capability } from '@dxos/app-framework';\nimport { FileInfoSchema } from '@dxos/app-toolkit';\nimport { Database } from '@dxos/echo';\nimport { Collection } from '@dxos/echo';\nimport { Operation } from '@dxos/operation';\nimport { SpaceSchema } from '@dxos/react-client/echo';\n\nimport { meta } from '../meta';\n\nimport * as File from './File';\n\nexport namespace WnfsAction {\n export const UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);\n\n export const UploadFileSchema = Schema.Struct({\n file: Schema.instanceOf(File.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\nconst WNFS_OPERATION = `${meta.id}/operation`;\n\nexport namespace WnfsOperation {\n export const OnCreateSpace = Operation.make({\n meta: { key: `${WNFS_OPERATION}/on-create-space`, name: 'On Create Space' },\n services: [Capability.Service],\n schema: {\n input: Schema.Struct({\n space: SpaceSchema,\n rootCollection: Collection.Collection,\n isDefault: Schema.optional(Schema.Boolean),\n }),\n output: Schema.Void,\n },\n });\n\n export const Create = Operation.make({\n meta: { key: `${WNFS_OPERATION}/create`, name: 'Create WNFS File' },\n services: [Capability.Service],\n schema: {\n input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),\n output: Schema.Struct({\n object: File.File,\n }),\n },\n });\n\n export const Upload = Operation.make({\n meta: { key: `${WNFS_OPERATION}/upload`, name: 'Upload File' },\n services: [Capability.Service],\n schema: {\n input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),\n output: Schema.required(FileInfoSchema),\n },\n });\n\n export const CreateFile = Operation.make({\n meta: { key: `${WNFS_OPERATION}/create-file`, name: 'Create File' },\n services: [Capability.Service],\n schema: {\n input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),\n output: Schema.Struct({\n object: File.File,\n }),\n },\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAOA,SAASA,kBAAkB;;;ACF3B,SAASC,YAAY;AAEd,IAAMC,OAAoB;EAC/BC,IAAI;EACJC,MAAM;EACNC,aAAaC;;;;EAIbC,MAAM;EACNC,SAAS;EACTC,QAAQ;AACV;;;UDLiBC,mBAAAA;oBACFC,aAAaC,WAAWC,KAAiB,GAAGC,KAAKC,EAAE,wBAAwB;oBAG3EC,YAAYJ,WAAWC,KAAgB,GAAGC,KAAKC,EAAE,uBAAuB;AACvF,GALiBL,qBAAAA,mBAAAA,CAAAA,EAAAA;;;;AEZjB;;;;;AAIA,YAAYO,YAAY;AAExB,SAASC,KAAKC,YAAY;AAC1B,SAASC,2BAA2B;AAE7B,IAAMC,OAAcC,cAAO;EAChCC,MAAaC,cAAOC,KAAYC,eAAQ;EACxCC,MAAaH,cAAOC,KAAKG,oBAAoBC,IAAI,KAAA,CAAA;EACjDC,KAAYN,cAAOC,KAAKG,oBAAoBC,IAAI,KAAA,CAAA;EAChDE,WAAkBP,cAAOC,KAAKG,oBAAoBC,IAAI,KAAA,GAAeH,eAAQ;AAC/E,CAAA,EAAGD,KACDO,KAAKC,OAAO;EACVC,UAAU;EACVC,SAAS;AACX,CAAA,CAAA;AAKK,IAAMC,OAAO,CAACC,UAAsCC,IAAIF,KAAKf,MAAMgB,KAAAA;;;ACnB1E,YAAYE,aAAY;AAExB,SAASC,cAAAA,mBAAkB;AAC3B,SAASC,sBAAsB;AAC/B,SAASC,gBAAgB;AACzB,SAASC,kBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,mBAAmB;UAMXC,aAAAA;cACFC,qBAAqBC,uBAAOC,IAAI,GAAGC,KAAKC,EAAE,oBAAoB;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ACtBC,QAAQ;MACNC,OAAciB,eAAOxC,WAAWM,kBAAyBC,eAAO;QAAEkC,IAAIC,SAASA;MAAS,CAAA,CAAA;MACxFX,QAAexB,eAAO;QACpB+B,QAAa5B;MACf,CAAA;IACF;EACF,CAAA;AACF,GA5CiBG,kBAAAA,gBAAAA,CAAAA,EAAAA;;;",
|
|
6
|
+
"names": ["Capability", "trim", "meta", "id", "name", "description", "trim", "icon", "iconHue", "source", "WnfsCapabilities", "Blockstore", "Capability", "make", "meta", "id", "Instances", "Schema", "Obj", "Type", "FormInputAnnotation", "File", "Struct", "name", "String", "pipe", "optional", "type", "FormInputAnnotation", "set", "cid", "timestamp", "Type", "object", "typename", "version", "make", "props", "Obj", "Schema", "Capability", "FileInfoSchema", "Database", "Collection", "Operation", "SpaceSchema", "WnfsAction", "UploadAnnotationId", "Symbol", "for", "meta", "id", "UploadFileSchema", "Struct", "file", "instanceOf", "File", "annotations", "WNFS_OPERATION", "WnfsOperation", "OnCreateSpace", "Operation", "make", "key", "name", "services", "Capability", "Service", "schema", "input", "space", "SpaceSchema", "rootCollection", "Collection", "isDefault", "optional", "Boolean", "output", "Void", "Create", "FileInfoSchema", "pick", "pipe", "required", "object", "Upload", "extend", "db", "Database", "CreateFile"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WnfsAction,
|
|
3
|
+
meta
|
|
4
|
+
} from "./chunk-BXGCJRL2.mjs";
|
|
5
|
+
|
|
6
|
+
// src/components/FileInput.tsx
|
|
7
|
+
import React, { useCallback } from "react";
|
|
8
|
+
import { useDropzone } from "react-dropzone";
|
|
9
|
+
import { findAnnotation } from "@dxos/effect";
|
|
10
|
+
import { useTranslation } from "@dxos/react-ui";
|
|
11
|
+
import { mx } from "@dxos/ui-theme";
|
|
12
|
+
var FileInput = ({ schema, onChange }) => {
|
|
13
|
+
const { t } = useTranslation(meta.id);
|
|
14
|
+
const accept = findAnnotation(schema.ast, WnfsAction.UploadAnnotationId);
|
|
15
|
+
const onDropAccepted = useCallback((files) => onChange?.(files[0]), [
|
|
16
|
+
onChange
|
|
17
|
+
]);
|
|
18
|
+
const { acceptedFiles, getRootProps, getInputProps, isFocused, isDragAccept, isDragReject } = useDropzone({
|
|
19
|
+
multiple: false,
|
|
20
|
+
accept,
|
|
21
|
+
onDropAccepted
|
|
22
|
+
});
|
|
23
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
24
|
+
...getRootProps(),
|
|
25
|
+
className: mx("flex flex-col items-center p-8 border border-separator", isFocused && "focus-ring", isDragAccept && "bg-attention-surface", isDragReject && "border-rose-fill")
|
|
26
|
+
}, /* @__PURE__ */ React.createElement("input", getInputProps()), acceptedFiles[0] ? /* @__PURE__ */ React.createElement("p", null, acceptedFiles[0].name) : /* @__PURE__ */ React.createElement("p", null, t("file input placeholder")));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/components/FilePreview.tsx
|
|
30
|
+
import React2 from "react";
|
|
31
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
32
|
+
var FilePreview = ({ type, url, classNames }) => {
|
|
33
|
+
if (type.startsWith("image/")) {
|
|
34
|
+
return /* @__PURE__ */ React2.createElement("img", {
|
|
35
|
+
className: mx2("w-full h-full object-contain", classNames),
|
|
36
|
+
src: url
|
|
37
|
+
});
|
|
38
|
+
} else if (type.startsWith("video/")) {
|
|
39
|
+
return /* @__PURE__ */ React2.createElement("video", {
|
|
40
|
+
className: mx2("w-full h-full object-contain", classNames),
|
|
41
|
+
src: url,
|
|
42
|
+
controls: true
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
return /* @__PURE__ */ React2.createElement("iframe", {
|
|
46
|
+
className: mx2("w-full h-full overflow-auto", classNames),
|
|
47
|
+
src: url
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
FileInput,
|
|
54
|
+
FilePreview
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=chunk-HXVPBJ3A.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/FileInput.tsx", "../../../src/components/FilePreview.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Schema from 'effect/Schema';\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/ui-theme';\n\nimport { meta } 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(meta.id);\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-surface',\n isDragReject && 'border-rose-fill',\n )}\n >\n <input {...getInputProps()} />\n {acceptedFiles[0] ? <p>{acceptedFiles[0].name}</p> : <p>{t('file input placeholder')}</p>}\n </div>\n );\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/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": ";;;;;;AAKA,OAAOA,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,QAAM,EAAEC,EAAC,IAAKC,eAAeC,KAAKC,EAAE;AACpC,QAAMC,SAASC,eAAyCP,OAAOQ,KAAKC,WAAWC,kBAAkB;AAEjG,QAAMC,iBAAiBC,YAAY,CAACC,UAAkBZ,WAAWY,MAAM,CAAA,CAAE,GAAG;IAACZ;GAAS;AAEtF,QAAM,EAAEa,eAAeC,cAAcC,eAAeC,WAAWC,cAAcC,aAAY,IAAKC,YAAY;IACxGC,UAAU;IACVf;IACAK;EACF,CAAA;AAEA,SACE,sBAAA,cAACW,OAAAA;IACE,GAAGP,aAAAA;IACJQ,WAAWC,GACT,0DACAP,aAAa,cACbC,gBAAgB,wBAChBC,gBAAgB,kBAAA;KAGlB,sBAAA,cAACM,SAAUT,cAAAA,CAAAA,GACVF,cAAc,CAAA,IAAK,sBAAA,cAACY,KAAAA,MAAGZ,cAAc,CAAA,EAAGa,IAAI,IAAQ,sBAAA,cAACD,KAAAA,MAAGxB,EAAE,wBAAA,CAAA,CAAA;AAGjE;;;AC1CA,OAAO0B,YAAW;AAGlB,SAASC,MAAAA,WAAU;AAOZ,IAAMC,cAAc,CAAC,EAAEC,MAAMC,KAAKC,WAAU,MAAoB;AACrE,MAAIF,KAAKG,WAAW,QAAA,GAAW;AAC7B,WAAO,gBAAAC,OAAA,cAACC,OAAAA;MAAIC,WAAWC,IAAG,gCAAgCL,UAAAA;MAAaM,KAAKP;;EAC9E,WAAWD,KAAKG,WAAW,QAAA,GAAW;AACpC,WAAO,gBAAAC,OAAA,cAACK,SAAAA;MAAMH,WAAWC,IAAG,gCAAgCL,UAAAA;MAAaM,KAAKP;MAAKS,UAAAA;;EACrF,OAAO;AACL,WAAO,gBAAAN,OAAA,cAACO,UAAAA;MAAOL,WAAWC,IAAG,+BAA+BL,UAAAA;MAAaM,KAAKP;;EAChF;AACF;",
|
|
6
|
+
"names": ["React", "useCallback", "useDropzone", "findAnnotation", "useTranslation", "mx", "FileInput", "schema", "onChange", "t", "useTranslation", "meta", "id", "accept", "findAnnotation", "ast", "WnfsAction", "UploadAnnotationId", "onDropAccepted", "useCallback", "files", "acceptedFiles", "getRootProps", "getInputProps", "isFocused", "isDragAccept", "isDragReject", "useDropzone", "multiple", "div", "className", "mx", "input", "p", "name", "React", "mx", "FilePreview", "type", "url", "classNames", "startsWith", "React", "img", "className", "mx", "src", "video", "controls", "iframe"]
|
|
7
|
+
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// src/helpers/upload.ts
|
|
2
|
+
import { CID as CID3 } from "multiformats";
|
|
3
|
+
import * as Raw from "multiformats/codecs/raw";
|
|
4
|
+
import { sha256 as sha2562 } from "multiformats/hashes/sha2";
|
|
5
|
+
import { Obj as Obj2 } from "@dxos/echo";
|
|
6
|
+
import { log } from "@dxos/log";
|
|
7
|
+
|
|
1
8
|
// src/helpers/common.ts
|
|
2
9
|
import { CID } from "multiformats/cid";
|
|
3
10
|
import { sha256 } from "multiformats/hashes/sha2";
|
|
@@ -114,11 +121,6 @@ var getBlobUrl = async ({ wnfsUrl: wnfsUrl2, blockstore, forest, directory, type
|
|
|
114
121
|
};
|
|
115
122
|
|
|
116
123
|
// src/helpers/upload.ts
|
|
117
|
-
import { CID as CID3 } from "multiformats";
|
|
118
|
-
import * as Raw from "multiformats/codecs/raw";
|
|
119
|
-
import { sha256 as sha2562 } from "multiformats/hashes/sha2";
|
|
120
|
-
import { Obj as Obj2 } from "@dxos/echo";
|
|
121
|
-
import { log } from "@dxos/log";
|
|
122
124
|
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/helpers/upload.ts";
|
|
123
125
|
var upload = async ({ file, blockstore, instances, space }) => {
|
|
124
126
|
const { directory, forest } = await loadWnfs({
|
|
@@ -164,4 +166,4 @@ export {
|
|
|
164
166
|
getBlobUrl,
|
|
165
167
|
upload
|
|
166
168
|
};
|
|
167
|
-
//# sourceMappingURL=chunk-
|
|
169
|
+
//# sourceMappingURL=chunk-UC4HMNZZ.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/helpers/upload.ts", "../../../src/helpers/common.ts", "../../../src/helpers/load.ts", "../../../src/helpers/wnfs-url.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Blockstore } from 'interface-blockstore';\nimport { CID } from 'multiformats';\nimport * as Raw from 'multiformats/codecs/raw';\nimport { sha256 } from 'multiformats/hashes/sha2';\n\nimport type { Space } from '@dxos/client/echo';\nimport { Obj } from '@dxos/echo';\nimport { log } from '@dxos/log';\n\nimport { type WnfsCapabilities } from '../types';\n\nimport { Rng, filePath, store } from './common';\nimport { loadWnfs } from './load';\nimport { wnfsUrl } from './wnfs-url';\n\nexport const upload = async ({\n file,\n blockstore,\n instances,\n space,\n}: {\n file: File;\n blockstore: Blockstore;\n instances?: WnfsCapabilities.Instances;\n space: Space;\n}) => {\n const { directory, forest } = await loadWnfs({ blockstore, instances, space });\n const wnfsStore = store(blockstore);\n\n const bytes = new Uint8Array(await file.arrayBuffer());\n const hash = await sha256.digest(bytes);\n const cid = CID.create(1, Raw.code, hash);\n\n const path = filePath(cid.toString(), space);\n\n // Given the root directory of the private file system,\n // write the file contents to `path` in said directory.\n const result = await directory.write(path, true, bytes, new Date(), forest, wnfsStore, new Rng());\n\n // Given the new immutable instance of the root directory after writing to it,\n // **store** the changes in the \"dark forest\" and the associated (block) store.\n const [_, updatedForest] = await result.rootDir.store(result.forest, wnfsStore, new Rng());\n const cidBytes = await updatedForest.store(wnfsStore);\n\n // Update the forest pointer on the associated space.\n Obj.change(space.properties, (p) => {\n p.wnfs.privateForestCid = CID.decode(cidBytes).toString();\n });\n\n // Generate `wnfs://` URL & return the info.\n const info = {\n name: file.name,\n type: file.type,\n url: wnfsUrl(path),\n cid: cid.toString(),\n };\n\n log('upload', { file, info });\n return info;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Blockstore } from 'interface-blockstore';\nimport { CID } from 'multiformats/cid';\nimport { sha256 } from 'multiformats/hashes/sha2';\nimport { type BlockStore as WnfsBlockStore } from 'wnfs';\n\nimport * as crypto from '@dxos/crypto';\nimport { type Space } from '@dxos/react-client/echo';\n\n//\n// PATH\n//\n\nexport const filePath = (fileName: string, space: Space) => {\n return ['spaces', space.id, 'files', fileName];\n};\n\n//\n// RNG\n//\n\nexport class Rng {\n randomBytes(count: number): Uint8Array {\n return new Uint8Array(crypto.randomBytes(count));\n }\n}\n\n//\n// STORE\n//\n\nexport const store = (blockstore: Blockstore): WnfsBlockStore => {\n const getBlock = async (cid: Uint8Array): Promise<Uint8Array | undefined> => {\n const decodedCid = CID.decode(cid);\n return await blockstore.get(decodedCid);\n };\n\n const hasBlock = async (cid: Uint8Array): Promise<boolean> => {\n const decodedCid = CID.decode(cid);\n return await blockstore.has(decodedCid);\n };\n\n const putBlockKeyed = async (cid: Uint8Array, bytes: Uint8Array): Promise<void> => {\n const decodedCid = CID.decode(cid);\n await blockstore.put(decodedCid, bytes);\n };\n\n // Don't hash blocks with the rs-wnfs default Blake 3, sha256 has better support.\n const putBlock = async (bytes: Uint8Array, codec: number): Promise<Uint8Array> => {\n const hash = await sha256.digest(bytes);\n const cid = CID.create(1, codec, hash);\n await blockstore.put(cid, bytes);\n return cid.bytes;\n };\n\n return { getBlock, hasBlock, putBlockKeyed, putBlock };\n};\n\nexport const storeName = () => 'dxos/wnfs';\n\n//\n// OTHER\n//\n\nexport const readFile = (file: File): Promise<Uint8Array> => {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = (event) => {\n const result = event.target?.result;\n if (result === null || result === undefined || typeof result === 'string') {\n reject(new Error('Expected an ArrayBuffer'));\n return;\n }\n resolve(new Uint8Array(result));\n };\n reader.onerror = (err) => {\n reject(err);\n };\n reader.readAsArrayBuffer(file);\n });\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Blockstore } from 'interface-blockstore';\nimport { CID } from 'multiformats';\nimport * as Uint8Arrays from 'uint8arrays';\nimport { AccessKey, PrivateDirectory, PrivateForest, PrivateNode } from 'wnfs';\n\nimport { Obj } from '@dxos/echo';\nimport { type Space } from '@dxos/react-client/echo';\n\nimport { type WnfsCapabilities } from '../types';\n\nimport { Rng, store } from './common';\n\n//\n// LOAD\n//\n\nexport const loadWnfs = async ({\n space,\n blockstore,\n instances,\n}: {\n space: Space;\n blockstore: Blockstore;\n instances?: WnfsCapabilities.Instances;\n}) => {\n // TODO(wittjosiah): Remove.\n // Delete old properties if they exist.\n if (space.properties.wnfs_access_key !== undefined && space.properties.wnfs_private_forest_cid !== undefined) {\n Obj.change(space.properties, (p) => {\n delete p['wnfs_access_key'];\n delete p['wnfs_private_forest_cid'];\n });\n }\n\n const cacheKey = space.properties.wnfs?.privateForestCid;\n if (instances?.[cacheKey]) {\n return instances[cacheKey];\n }\n\n const exists = !!space.properties.wnfs;\n const instance = exists ? await loadWnfsDir(blockstore, space) : await createWnfsDir(blockstore, space);\n if (instances) {\n instances[cacheKey] = instance;\n }\n\n return instance;\n};\n\n//\n// PRIVATE\n//\n\nconst createWnfsDir = async (blockstore: Blockstore, space: Space) => {\n const wnfsStore = store(blockstore);\n const rng = new Rng();\n const forest = new PrivateForest(rng);\n\n const dirResult = await PrivateDirectory.newAndStore(forest.emptyName(), new Date(), forest, wnfsStore, rng);\n const dir = dirResult.rootDir as PrivateDirectory;\n\n const [accessKeyRaw, newForest]: [AccessKey, PrivateForest] = await dir\n .asNode()\n .store(dirResult.forest as PrivateForest, wnfsStore, rng);\n\n const cidBytes = await newForest.store(wnfsStore);\n\n Obj.change(space.properties, (p) => {\n p.wnfs = {\n accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), 'base64'),\n privateForestCid: CID.decode(cidBytes).toString(),\n };\n });\n\n return {\n directory: dir,\n forest: newForest,\n };\n};\n\nconst loadWnfsDir = async (blockstore: Blockstore, space: Space) => {\n const wnfsStore = store(blockstore);\n\n const accessKey = AccessKey.fromBytes(Uint8Arrays.fromString(space.properties.wnfs.accessKey, 'base64'));\n const forest: PrivateForest = await PrivateForest.load(\n CID.parse(space.properties.wnfs.privateForestCid).bytes,\n wnfsStore,\n );\n const node: PrivateNode = await PrivateNode.load(accessKey, forest, wnfsStore);\n\n return {\n directory: node.asDir(),\n forest,\n };\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Blockstore } from 'interface-blockstore';\nimport { type PrivateDirectory, type PrivateForest } from 'wnfs';\n\nimport { store } from './common';\n\nexport const wnfsUrl = (filePath: string[]) => {\n return 'wnfs://' + filePath.map((f) => encodeURIComponent(f)).join('/');\n};\n\nexport const getPathFromUrl = (wnfsUrl: string) =>\n wnfsUrl\n .replace(/^wnfs:\\/\\//, '')\n .split('/')\n .map((p) => decodeURIComponent(p));\n\nexport const getBlobUrl = async ({\n wnfsUrl,\n blockstore,\n forest,\n directory,\n type,\n}: {\n wnfsUrl: string;\n blockstore: Blockstore;\n forest: PrivateForest;\n directory: PrivateDirectory;\n type?: string;\n}) => {\n const path = getPathFromUrl(wnfsUrl);\n const wnfsStore = store(blockstore);\n const { result } = await directory.read(path, true, forest, wnfsStore);\n const blob = new Blob([result], { type });\n return URL.createObjectURL(blob);\n};\n"],
|
|
5
|
+
"mappings": ";AAKA,SAASA,OAAAA,YAAW;AACpB,YAAYC,SAAS;AACrB,SAASC,UAAAA,eAAc;AAGvB,SAASC,OAAAA,YAAW;AACpB,SAASC,WAAW;;;ACNpB,SAASC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,IAAAA;AAEpC,QAAMO,OAAOC,SAASL,IAAIM,SAAQ,GAAIlB,KAAAA;AAItC,QAAMmB,SAAS,MAAMlB,UAAUmB,MAAMJ,MAAM,MAAMV,OAAO,oBAAIe,KAAAA,GAAQnB,QAAQE,WAAW,IAAIkB,IAAAA,CAAAA;AAI3F,QAAM,CAACC,GAAGC,aAAAA,IAAiB,MAAML,OAAOM,QAAQpB,MAAMc,OAAOjB,QAAQE,WAAW,IAAIkB,IAAAA,CAAAA;AACpF,QAAMI,WAAW,MAAMF,cAAcnB,MAAMD,SAAAA;AAG3CuB,EAAAA,KAAIC,OAAO5B,MAAM6B,YAAY,CAACC,MAAAA;AAC5BA,MAAEC,KAAKC,mBAAmBnB,KAAIoB,OAAOP,QAAAA,EAAUR,SAAQ;EACzD,CAAA;AAGA,QAAMgB,OAAO;IACXC,MAAMtC,KAAKsC;IACXC,MAAMvC,KAAKuC;IACXC,KAAKC,QAAQtB,IAAAA;IACbJ,KAAKA,IAAIM,SAAQ;EACnB;AAEAqB,MAAI,UAAU;IAAE1C;IAAMqC;EAAK,GAAA;;;;;;AAC3B,SAAOA;AACT;",
|
|
6
|
+
"names": ["CID", "Raw", "sha256", "Obj", "log", "CID", "sha256", "crypto", "filePath", "fileName", "space", "id", "Rng", "randomBytes", "count", "Uint8Array", "store", "blockstore", "getBlock", "cid", "decodedCid", "CID", "decode", "get", "hasBlock", "has", "putBlockKeyed", "bytes", "put", "putBlock", "codec", "hash", "sha256", "digest", "create", "storeName", "CID", "Uint8Arrays", "AccessKey", "PrivateDirectory", "PrivateForest", "PrivateNode", "Obj", "loadWnfs", "space", "blockstore", "instances", "properties", "wnfs_access_key", "undefined", "wnfs_private_forest_cid", "Obj", "change", "p", "cacheKey", "wnfs", "privateForestCid", "exists", "instance", "loadWnfsDir", "createWnfsDir", "wnfsStore", "store", "rng", "Rng", "forest", "PrivateForest", "dirResult", "PrivateDirectory", "newAndStore", "emptyName", "Date", "dir", "rootDir", "accessKeyRaw", "newForest", "asNode", "cidBytes", "accessKey", "toString", "toBytes", "CID", "decode", "directory", "AccessKey", "fromBytes", "fromString", "load", "parse", "bytes", "node", "PrivateNode", "asDir", "wnfsUrl", "filePath", "map", "f", "encodeURIComponent", "join", "getPathFromUrl", "replace", "split", "p", "decodeURIComponent", "getBlobUrl", "blockstore", "forest", "directory", "type", "path", "wnfsStore", "store", "result", "read", "blob", "Blob", "URL", "createObjectURL", "upload", "file", "blockstore", "instances", "space", "directory", "forest", "loadWnfs", "wnfsStore", "store", "bytes", "Uint8Array", "arrayBuffer", "hash", "sha256", "digest", "cid", "CID", "create", "code", "path", "filePath", "toString", "result", "write", "Date", "Rng", "_", "updatedForest", "rootDir", "cidBytes", "Obj", "change", "properties", "p", "wnfs", "privateForestCid", "decode", "info", "name", "type", "url", "wnfsUrl", "log"]
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WnfsOperation
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-BXGCJRL2.mjs";
|
|
4
4
|
|
|
5
5
|
// src/capabilities/file-uploader/file-uploader.ts
|
|
6
6
|
import * as Effect from "effect/Effect";
|
|
@@ -32,4 +32,4 @@ var file_uploader_default = Capability.makeModule(Effect.fnUntraced(function* ()
|
|
|
32
32
|
export {
|
|
33
33
|
file_uploader_default as default
|
|
34
34
|
};
|
|
35
|
-
//# sourceMappingURL=file-uploader-
|
|
35
|
+
//# sourceMappingURL=file-uploader-QL4DTOMM.mjs.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
WnfsCapabilities,
|
|
5
5
|
WnfsOperation,
|
|
6
6
|
meta
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-BXGCJRL2.mjs";
|
|
8
8
|
|
|
9
9
|
// src/WnfsPlugin.tsx
|
|
10
10
|
import * as Effect from "effect/Effect";
|
|
@@ -17,23 +17,23 @@ import { SpaceCapabilities, SpaceEvents } from "@dxos/plugin-space";
|
|
|
17
17
|
|
|
18
18
|
// src/capabilities/blockstore/index.ts
|
|
19
19
|
import { Capability } from "@dxos/app-framework";
|
|
20
|
-
var Blockstore = Capability.lazy("Blockstore", () => import("./blockstore-
|
|
20
|
+
var Blockstore = Capability.lazy("Blockstore", () => import("./blockstore-Q66HQJ4Q.mjs"));
|
|
21
21
|
|
|
22
22
|
// src/capabilities/file-uploader/index.ts
|
|
23
23
|
import { Capability as Capability2 } from "@dxos/app-framework";
|
|
24
|
-
var FileUploader = Capability2.lazy("FileUploader", () => import("./file-uploader-
|
|
24
|
+
var FileUploader = Capability2.lazy("FileUploader", () => import("./file-uploader-QL4DTOMM.mjs"));
|
|
25
25
|
|
|
26
26
|
// src/capabilities/markdown/index.ts
|
|
27
27
|
import { Capability as Capability3 } from "@dxos/app-framework";
|
|
28
|
-
var Markdown = Capability3.lazy("Markdown", () => import("./markdown-
|
|
28
|
+
var Markdown = Capability3.lazy("Markdown", () => import("./markdown-AYCVG6TJ.mjs"));
|
|
29
29
|
|
|
30
30
|
// src/capabilities/operation-resolver/index.ts
|
|
31
31
|
import { Capability as Capability4 } from "@dxos/app-framework";
|
|
32
|
-
var OperationResolver = Capability4.lazy("OperationResolver", () => import("./operation-resolver-
|
|
32
|
+
var OperationResolver = Capability4.lazy("OperationResolver", () => import("./operation-resolver-YYWUF6EY.mjs"));
|
|
33
33
|
|
|
34
34
|
// src/capabilities/react-surface/index.ts
|
|
35
35
|
import { Capability as Capability5 } from "@dxos/app-framework";
|
|
36
|
-
var ReactSurface = Capability5.lazy("ReactSurface", () => import("./react-surface-
|
|
36
|
+
var ReactSurface = Capability5.lazy("ReactSurface", () => import("./react-surface-3LKVDPH7.mjs"));
|
|
37
37
|
|
|
38
38
|
// src/translations.ts
|
|
39
39
|
var translations = [
|
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
getBlobUrl,
|
|
3
3
|
getPathFromUrl,
|
|
4
4
|
loadWnfs
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-UC4HMNZZ.mjs";
|
|
6
6
|
import {
|
|
7
7
|
WnfsCapabilities
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-BXGCJRL2.mjs";
|
|
9
9
|
|
|
10
10
|
// src/capabilities/markdown/markdown.ts
|
|
11
11
|
import * as Effect from "effect/Effect";
|
|
@@ -198,4 +198,4 @@ var markdown_default = Capability.makeModule(Effect.fnUntraced(function* () {
|
|
|
198
198
|
export {
|
|
199
199
|
markdown_default as default
|
|
200
200
|
};
|
|
201
|
-
//# sourceMappingURL=markdown-
|
|
201
|
+
//# sourceMappingURL=markdown-AYCVG6TJ.mjs.map
|