@dxos/plugin-wnfs 0.8.4-main.f9ba587 → 0.8.4-main.fcc0d83b33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/lib/browser/chunk-4D4K5JCC.mjs +66 -0
- package/dist/lib/browser/chunk-4D4K5JCC.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-CGW32EZB.mjs → browser/chunk-7KFJ6LYH.mjs} +44 -21
- package/dist/lib/browser/chunk-7KFJ6LYH.mjs.map +7 -0
- package/dist/lib/browser/chunk-DK62NQ5T.mjs +71 -0
- package/dist/lib/browser/chunk-DK62NQ5T.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/create-QRLX4IMZ.mjs +25 -0
- package/dist/lib/browser/create-QRLX4IMZ.mjs.map +7 -0
- package/dist/lib/browser/create-file-INAT56PX.mjs +42 -0
- package/dist/lib/browser/create-file-INAT56PX.mjs.map +7 -0
- package/dist/lib/browser/helpers/index.mjs +26 -0
- package/dist/lib/browser/helpers/index.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +79 -103
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operations/index.mjs +14 -0
- package/dist/lib/browser/operations/index.mjs.map +7 -0
- package/dist/lib/browser/translations.mjs +30 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +8 -6
- package/dist/lib/browser/upload-ZQI66T4Y.mjs +35 -0
- package/dist/lib/browser/upload-ZQI66T4Y.mjs.map +7 -0
- package/dist/types/src/WnfsPlugin.d.ts +2 -1
- package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
- package/dist/types/src/blockstore.d.ts.map +1 -1
- package/dist/types/src/capabilities/blockstore.d.ts +3 -2
- package/dist/types/src/capabilities/blockstore.d.ts.map +1 -1
- package/dist/types/src/capabilities/file-uploader.d.ts +4 -2
- package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +7 -6
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/markdown.d.ts +4 -2
- package/dist/types/src/capabilities/markdown.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/{FileInput.d.ts → FileInput/FileInput.d.ts} +1 -1
- package/dist/types/src/components/FileInput/FileInput.d.ts.map +1 -0
- package/dist/types/src/components/FileInput/index.d.ts +2 -0
- package/dist/types/src/components/FileInput/index.d.ts.map +1 -0
- package/dist/types/src/components/FilePreview/FilePreview.d.ts +12 -0
- package/dist/types/src/components/FilePreview/FilePreview.d.ts.map +1 -0
- package/dist/types/src/components/FilePreview/index.d.ts +2 -0
- package/dist/types/src/components/FilePreview/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/FileContainer/FileContainer.d.ts +7 -0
- package/dist/types/src/containers/FileContainer/FileContainer.d.ts.map +1 -0
- package/dist/types/src/containers/FileContainer/index.d.ts +2 -0
- package/dist/types/src/containers/FileContainer/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +3 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/extensions/image.d.ts +1 -1
- package/dist/types/src/extensions/image.d.ts.map +1 -1
- package/dist/types/src/extensions/image.stories.d.ts +5 -4
- package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
- package/dist/types/src/helpers/common.d.ts.map +1 -1
- package/dist/types/src/helpers/load.d.ts +2 -2
- package/dist/types/src/helpers/load.d.ts.map +1 -1
- package/dist/types/src/helpers/upload.d.ts +1 -1
- package/dist/types/src/helpers/upload.d.ts.map +1 -1
- package/dist/types/src/helpers/wnfs-url.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/operations/create-file.d.ts +5 -0
- package/dist/types/src/operations/create-file.d.ts.map +1 -0
- package/dist/types/src/operations/create.d.ts +5 -0
- package/dist/types/src/operations/create.d.ts.map +1 -0
- package/dist/types/src/operations/definitions.d.ts +38 -0
- package/dist/types/src/operations/definitions.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +4 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/upload.d.ts +5 -0
- package/dist/types/src/operations/upload.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +24 -10
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/File.d.ts +16 -0
- package/dist/types/src/types/File.d.ts.map +1 -0
- package/dist/types/src/{capabilities → types}/capabilities.d.ts +3 -2
- package/dist/types/src/types/capabilities.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +4 -46
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +73 -47
- package/src/WnfsPlugin.tsx +66 -85
- package/src/blockstore.ts +3 -3
- package/src/capabilities/blockstore.ts +15 -10
- package/src/capabilities/file-uploader.ts +25 -15
- package/src/capabilities/index.ts +10 -8
- package/src/capabilities/markdown.ts +25 -12
- package/src/capabilities/operation-handler.ts +16 -0
- package/src/capabilities/react-surface.tsx +50 -35
- package/src/components/{FileInput.tsx → FileInput/FileInput.tsx} +8 -8
- package/src/components/FileInput/index.ts +5 -0
- package/src/components/FilePreview/FilePreview.tsx +43 -0
- package/src/components/FilePreview/index.ts +5 -0
- package/src/components/index.ts +1 -4
- package/src/containers/FileContainer/FileContainer.tsx +57 -0
- package/src/containers/FileContainer/index.ts +5 -0
- package/src/containers/index.ts +7 -0
- package/src/extensions/image.stories.tsx +22 -19
- package/src/extensions/image.tsx +10 -9
- package/src/helpers/load.ts +14 -8
- package/src/helpers/upload.ts +6 -2
- package/src/index.ts +1 -1
- package/src/meta.ts +9 -6
- package/src/operations/create-file.ts +31 -0
- package/src/operations/create.ts +22 -0
- package/src/operations/definitions.ts +41 -0
- package/src/operations/index.ts +13 -0
- package/src/operations/upload.ts +29 -0
- package/src/translations.ts +14 -8
- package/src/types/File.ts +28 -0
- package/src/{capabilities → types}/capabilities.ts +4 -4
- package/src/types/index.ts +2 -1
- package/src/types/types.ts +3 -19
- package/dist/lib/browser/FileContainer-Q4GUPBVD.mjs +0 -107
- package/dist/lib/browser/FileContainer-Q4GUPBVD.mjs.map +0 -7
- package/dist/lib/browser/blockstore-KQO2NTVM.mjs +0 -191
- package/dist/lib/browser/blockstore-KQO2NTVM.mjs.map +0 -7
- package/dist/lib/browser/chunk-BANMVVJV.mjs +0 -16
- package/dist/lib/browser/chunk-BANMVVJV.mjs.map +0 -7
- package/dist/lib/browser/chunk-GVBV2QWA.mjs +0 -64
- 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-VRRXG6IB.mjs +0 -159
- package/dist/lib/browser/chunk-VRRXG6IB.mjs.map +0 -7
- package/dist/lib/browser/file-uploader-JA55DPMW.mjs +0 -29
- package/dist/lib/browser/file-uploader-JA55DPMW.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-YM6QRFIH.mjs +0 -49
- package/dist/lib/browser/intent-resolver-YM6QRFIH.mjs.map +0 -7
- package/dist/lib/browser/markdown-6VH477GB.mjs +0 -196
- package/dist/lib/browser/markdown-6VH477GB.mjs.map +0 -7
- package/dist/lib/browser/react-surface-XAHVMWIH.mjs +0 -88
- package/dist/lib/browser/react-surface-XAHVMWIH.mjs.map +0 -7
- package/dist/lib/node-esm/FileContainer-22IPNDDA.mjs +0 -108
- package/dist/lib/node-esm/FileContainer-22IPNDDA.mjs.map +0 -7
- package/dist/lib/node-esm/blockstore-7KQTFHK5.mjs +0 -192
- package/dist/lib/node-esm/blockstore-7KQTFHK5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-47QYKNA6.mjs +0 -17
- package/dist/lib/node-esm/chunk-47QYKNA6.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BM37ZAHF.mjs +0 -65
- package/dist/lib/node-esm/chunk-BM37ZAHF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CGW32EZB.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-DWYM7FD7.mjs +0 -18
- package/dist/lib/node-esm/chunk-DWYM7FD7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YTWL64Z6.mjs +0 -17
- package/dist/lib/node-esm/chunk-YTWL64Z6.mjs.map +0 -7
- package/dist/lib/node-esm/file-uploader-WGDG2YV5.mjs +0 -30
- package/dist/lib/node-esm/file-uploader-WGDG2YV5.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -117
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-5QOT2SLD.mjs +0 -50
- package/dist/lib/node-esm/intent-resolver-5QOT2SLD.mjs.map +0 -7
- package/dist/lib/node-esm/markdown-R4PBXDJO.mjs +0 -197
- package/dist/lib/node-esm/markdown-R4PBXDJO.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/react-surface-HAOUJUXJ.mjs +0 -89
- package/dist/lib/node-esm/react-surface-HAOUJUXJ.mjs.map +0 -7
- package/dist/lib/node-esm/types/index.mjs +0 -11
- package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/components/FileContainer.d.ts +0 -9
- package/dist/types/src/components/FileContainer.d.ts.map +0 -1
- package/dist/types/src/components/FileInput.d.ts.map +0 -1
- package/dist/types/src/components/FilePreview.d.ts +0 -11
- package/dist/types/src/components/FilePreview.d.ts.map +0 -1
- package/dist/types/src/types/file.d.ts +0 -16
- package/dist/types/src/types/file.d.ts.map +0 -1
- package/src/capabilities/intent-resolver.ts +0 -32
- package/src/components/FileContainer.tsx +0 -51
- package/src/components/FilePreview.tsx +0 -23
- package/src/types/file.ts +0 -17
- /package/dist/lib/{node-esm/types/index.mjs.map → browser/chunk-J5LGTIGS.mjs.map} +0 -0
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
// src/helpers/common.ts
|
|
2
|
-
import { CID } from "multiformats/cid";
|
|
3
|
-
import { sha256 } from "multiformats/hashes/sha2";
|
|
4
|
-
import * as crypto from "@dxos/crypto";
|
|
5
|
-
var filePath = (fileName, space) => {
|
|
6
|
-
return [
|
|
7
|
-
"spaces",
|
|
8
|
-
space.id,
|
|
9
|
-
"files",
|
|
10
|
-
fileName
|
|
11
|
-
];
|
|
12
|
-
};
|
|
13
|
-
var Rng = class {
|
|
14
|
-
randomBytes(count) {
|
|
15
|
-
return new Uint8Array(crypto.randomBytes(count));
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var store = (blockstore) => {
|
|
19
|
-
const getBlock = async (cid) => {
|
|
20
|
-
const decodedCid = CID.decode(cid);
|
|
21
|
-
return await blockstore.get(decodedCid);
|
|
22
|
-
};
|
|
23
|
-
const hasBlock = async (cid) => {
|
|
24
|
-
const decodedCid = CID.decode(cid);
|
|
25
|
-
return await blockstore.has(decodedCid);
|
|
26
|
-
};
|
|
27
|
-
const putBlockKeyed = async (cid, bytes) => {
|
|
28
|
-
const decodedCid = CID.decode(cid);
|
|
29
|
-
await blockstore.put(decodedCid, bytes);
|
|
30
|
-
};
|
|
31
|
-
const putBlock = async (bytes, codec) => {
|
|
32
|
-
const hash = await sha256.digest(bytes);
|
|
33
|
-
const cid = CID.create(1, codec, hash);
|
|
34
|
-
await blockstore.put(cid, bytes);
|
|
35
|
-
return cid.bytes;
|
|
36
|
-
};
|
|
37
|
-
return {
|
|
38
|
-
getBlock,
|
|
39
|
-
hasBlock,
|
|
40
|
-
putBlockKeyed,
|
|
41
|
-
putBlock
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
var storeName = () => "dxos/wnfs";
|
|
45
|
-
|
|
46
|
-
// src/helpers/load.ts
|
|
47
|
-
import { CID as CID2 } from "multiformats";
|
|
48
|
-
import * as Uint8Arrays from "uint8arrays";
|
|
49
|
-
import { AccessKey, PrivateForest, PrivateDirectory, PrivateNode } from "wnfs";
|
|
50
|
-
var loadWnfs = async ({ space, blockstore, instances }) => {
|
|
51
|
-
if (space.properties.wnfs_access_key !== void 0 && space.properties.wnfs_private_forest_cid !== void 0) {
|
|
52
|
-
delete space.properties.wnfs_access_key;
|
|
53
|
-
delete space.properties.wnfs_private_forest_cid;
|
|
54
|
-
}
|
|
55
|
-
const cacheKey = space.properties.wnfs?.privateForestCid;
|
|
56
|
-
if (instances?.[cacheKey]) {
|
|
57
|
-
return instances[cacheKey];
|
|
58
|
-
}
|
|
59
|
-
const exists = !!space.properties.wnfs;
|
|
60
|
-
const instance = exists ? await loadWnfsDir(blockstore, space) : await createWnfsDir(blockstore, space);
|
|
61
|
-
if (instances) {
|
|
62
|
-
instances[cacheKey] = instance;
|
|
63
|
-
}
|
|
64
|
-
return instance;
|
|
65
|
-
};
|
|
66
|
-
var createWnfsDir = async (blockstore, space) => {
|
|
67
|
-
const wnfsStore = store(blockstore);
|
|
68
|
-
const rng = new Rng();
|
|
69
|
-
const forest = new PrivateForest(rng);
|
|
70
|
-
const dirResult = await PrivateDirectory.newAndStore(forest.emptyName(), /* @__PURE__ */ new Date(), forest, wnfsStore, rng);
|
|
71
|
-
const dir = dirResult.rootDir;
|
|
72
|
-
const [accessKeyRaw, newForest] = await dir.asNode().store(dirResult.forest, wnfsStore, rng);
|
|
73
|
-
const cidBytes = await newForest.store(wnfsStore);
|
|
74
|
-
space.properties.wnfs = {
|
|
75
|
-
accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), "base64"),
|
|
76
|
-
privateForestCid: CID2.decode(cidBytes).toString()
|
|
77
|
-
};
|
|
78
|
-
return {
|
|
79
|
-
directory: dir,
|
|
80
|
-
forest: newForest
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
var loadWnfsDir = async (blockstore, space) => {
|
|
84
|
-
const wnfsStore = store(blockstore);
|
|
85
|
-
const accessKey = AccessKey.fromBytes(Uint8Arrays.fromString(space.properties.wnfs.accessKey, "base64"));
|
|
86
|
-
const forest = await PrivateForest.load(CID2.parse(space.properties.wnfs.privateForestCid).bytes, wnfsStore);
|
|
87
|
-
const node = await PrivateNode.load(accessKey, forest, wnfsStore);
|
|
88
|
-
return {
|
|
89
|
-
directory: node.asDir(),
|
|
90
|
-
forest
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
// src/helpers/wnfs-url.ts
|
|
95
|
-
var wnfsUrl = (filePath2) => {
|
|
96
|
-
return "wnfs://" + filePath2.map((f) => encodeURIComponent(f)).join("/");
|
|
97
|
-
};
|
|
98
|
-
var getPathFromUrl = (wnfsUrl2) => wnfsUrl2.replace(/^wnfs:\/\//, "").split("/").map((p) => decodeURIComponent(p));
|
|
99
|
-
var getBlobUrl = async ({ wnfsUrl: wnfsUrl2, blockstore, forest, directory, type }) => {
|
|
100
|
-
const path = getPathFromUrl(wnfsUrl2);
|
|
101
|
-
const wnfsStore = store(blockstore);
|
|
102
|
-
const { result } = await directory.read(path, true, forest, wnfsStore);
|
|
103
|
-
const blob = new Blob([
|
|
104
|
-
result
|
|
105
|
-
], {
|
|
106
|
-
type
|
|
107
|
-
});
|
|
108
|
-
return URL.createObjectURL(blob);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// src/helpers/upload.ts
|
|
112
|
-
import { CID as CID3 } from "multiformats";
|
|
113
|
-
import * as Raw from "multiformats/codecs/raw";
|
|
114
|
-
import { sha256 as sha2562 } from "multiformats/hashes/sha2";
|
|
115
|
-
import { log } from "@dxos/log";
|
|
116
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/helpers/upload.ts";
|
|
117
|
-
var upload = async ({ file, blockstore, instances, space }) => {
|
|
118
|
-
const { directory, forest } = await loadWnfs({
|
|
119
|
-
blockstore,
|
|
120
|
-
instances,
|
|
121
|
-
space
|
|
122
|
-
});
|
|
123
|
-
const wnfsStore = store(blockstore);
|
|
124
|
-
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
125
|
-
const hash = await sha2562.digest(bytes);
|
|
126
|
-
const cid = CID3.create(1, Raw.code, hash);
|
|
127
|
-
const path = filePath(cid.toString(), space);
|
|
128
|
-
const result = await directory.write(path, true, bytes, /* @__PURE__ */ new Date(), forest, wnfsStore, new Rng());
|
|
129
|
-
const [_, updatedForest] = await result.rootDir.store(result.forest, wnfsStore, new Rng());
|
|
130
|
-
const cidBytes = await updatedForest.store(wnfsStore);
|
|
131
|
-
space.properties.wnfs.privateForestCid = CID3.decode(cidBytes).toString();
|
|
132
|
-
const info = {
|
|
133
|
-
name: file.name,
|
|
134
|
-
type: file.type,
|
|
135
|
-
url: wnfsUrl(path),
|
|
136
|
-
cid: cid.toString()
|
|
137
|
-
};
|
|
138
|
-
log("upload", {
|
|
139
|
-
file,
|
|
140
|
-
info
|
|
141
|
-
}, {
|
|
142
|
-
F: __dxlog_file,
|
|
143
|
-
L: 58,
|
|
144
|
-
S: void 0,
|
|
145
|
-
C: (f, a) => f(...a)
|
|
146
|
-
});
|
|
147
|
-
return info;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
export {
|
|
151
|
-
filePath,
|
|
152
|
-
storeName,
|
|
153
|
-
loadWnfs,
|
|
154
|
-
wnfsUrl,
|
|
155
|
-
getPathFromUrl,
|
|
156
|
-
getBlobUrl,
|
|
157
|
-
upload
|
|
158
|
-
};
|
|
159
|
-
//# sourceMappingURL=chunk-VRRXG6IB.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/helpers/common.ts", "../../../src/helpers/load.ts", "../../../src/helpers/wnfs-url.ts", "../../../src/helpers/upload.ts"],
|
|
4
|
-
"sourcesContent": ["//\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, PrivateForest, PrivateDirectory, PrivateNode } from 'wnfs';\n\nimport { type Space } from '@dxos/react-client/echo';\n\nimport { Rng, store } from './common';\nimport { type WnfsCapabilities } from '../capabilities';\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 delete space.properties.wnfs_access_key;\n delete space.properties.wnfs_private_forest_cid;\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 space.properties.wnfs = {\n accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), 'base64'),\n privateForestCid: CID.decode(cidBytes).toString(),\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", "//\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 { log } from '@dxos/log';\n\nimport { Rng, filePath, store } from './common';\nimport { loadWnfs } from './load';\nimport { wnfsUrl } from './wnfs-url';\nimport { type WnfsCapabilities } from '../capabilities';\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 space.properties.wnfs.privateForestCid = CID.decode(cidBytes).toString();\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"],
|
|
5
|
-
"mappings": ";AAKA,SAASA,WAAW;AACpB,SAASC,cAAc;AAGvB,YAAYC,YAAY;AAOjB,IAAMC,WAAW,CAACC,UAAkBC,UAAAA;AACzC,SAAO;IAAC;IAAUA,MAAMC;IAAI;IAASF;;AACvC;AAMO,IAAMG,MAAN,MAAMA;EACXC,YAAYC,OAA2B;AACrC,WAAO,IAAIC,WAAkBF,mBAAYC,KAAAA,CAAAA;EAC3C;AACF;AAMO,IAAME,QAAQ,CAACC,eAAAA;AACpB,QAAMC,WAAW,OAAOC,QAAAA;AACtB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M2B,WAAWC,KAAKC,mBAAmBhB,KAAIiB,OAAOJ,QAAAA,EAAUR,SAAQ;AAGtE,QAAMa,OAAO;IACXC,MAAMnC,KAAKmC;IACXC,MAAMpC,KAAKoC;IACXC,KAAKC,QAAQnB,IAAAA;IACbJ,KAAKA,IAAIM,SAAQ;EACnB;AAEAkB,MAAI,UAAU;IAAEvC;IAAMkC;EAAK,GAAA;;;;;;AAC3B,SAAOA;AACT;",
|
|
6
|
-
"names": ["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", "PrivateForest", "PrivateDirectory", "PrivateNode", "loadWnfs", "space", "blockstore", "instances", "properties", "wnfs_access_key", "undefined", "wnfs_private_forest_cid", "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", "CID", "Raw", "sha256", "log", "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", "properties", "wnfs", "privateForestCid", "decode", "info", "name", "type", "url", "wnfsUrl", "log"]
|
|
7
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WnfsAction
|
|
3
|
-
} from "./chunk-GVBV2QWA.mjs";
|
|
4
|
-
import "./chunk-VDDGZWAY.mjs";
|
|
5
|
-
|
|
6
|
-
// src/capabilities/file-uploader.ts
|
|
7
|
-
import { Effect, pipe } from "effect";
|
|
8
|
-
import { Capabilities, chain, contributes, createIntent } from "@dxos/app-framework";
|
|
9
|
-
import { SpaceAction } from "@dxos/plugin-space/types";
|
|
10
|
-
var file_uploader_default = (context) => {
|
|
11
|
-
return contributes(Capabilities.FileUploader, (file, space) => {
|
|
12
|
-
const { dispatch } = context.getCapability(Capabilities.IntentDispatcher);
|
|
13
|
-
const program = Effect.gen(function* () {
|
|
14
|
-
const fileInfo = yield* dispatch(createIntent(WnfsAction.Upload, {
|
|
15
|
-
file,
|
|
16
|
-
space
|
|
17
|
-
}));
|
|
18
|
-
yield* dispatch(pipe(createIntent(WnfsAction.Create, fileInfo), chain(SpaceAction.AddObject, {
|
|
19
|
-
target: space
|
|
20
|
-
})));
|
|
21
|
-
return fileInfo;
|
|
22
|
-
});
|
|
23
|
-
return Effect.runPromise(program);
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
export {
|
|
27
|
-
file_uploader_default as default
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=file-uploader-JA55DPMW.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,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
upload
|
|
3
|
-
} from "./chunk-VRRXG6IB.mjs";
|
|
4
|
-
import {
|
|
5
|
-
WnfsCapabilities
|
|
6
|
-
} from "./chunk-KZANQHJY.mjs";
|
|
7
|
-
import {
|
|
8
|
-
FileType,
|
|
9
|
-
WnfsAction
|
|
10
|
-
} from "./chunk-GVBV2QWA.mjs";
|
|
11
|
-
import "./chunk-VDDGZWAY.mjs";
|
|
12
|
-
|
|
13
|
-
// src/capabilities/intent-resolver.ts
|
|
14
|
-
import { contributes, Capabilities, createResolver } from "@dxos/app-framework";
|
|
15
|
-
import { Obj } from "@dxos/echo";
|
|
16
|
-
var intent_resolver_default = (context) => contributes(Capabilities.IntentResolver, [
|
|
17
|
-
// TODO(wittjosiah): Deleting the object doesn't delete the wnfs blob.
|
|
18
|
-
// Consider ways to trigger blob deletion based on object deletion and/or adding file system manager.
|
|
19
|
-
createResolver({
|
|
20
|
-
intent: WnfsAction.Create,
|
|
21
|
-
resolve: ({ name, type, cid }) => ({
|
|
22
|
-
data: {
|
|
23
|
-
object: Obj.make(FileType, {
|
|
24
|
-
name,
|
|
25
|
-
type,
|
|
26
|
-
cid
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
}),
|
|
31
|
-
createResolver({
|
|
32
|
-
intent: WnfsAction.Upload,
|
|
33
|
-
resolve: async ({ file, space }) => {
|
|
34
|
-
const blockstore = context.getCapability(WnfsCapabilities.Blockstore);
|
|
35
|
-
const info = await upload({
|
|
36
|
-
file,
|
|
37
|
-
blockstore,
|
|
38
|
-
space
|
|
39
|
-
});
|
|
40
|
-
return {
|
|
41
|
-
data: info
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
]);
|
|
46
|
-
export {
|
|
47
|
-
intent_resolver_default as default
|
|
48
|
-
};
|
|
49
|
-
//# sourceMappingURL=intent-resolver-YM6QRFIH.mjs.map
|
|
@@ -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,196 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getBlobUrl,
|
|
3
|
-
getPathFromUrl,
|
|
4
|
-
loadWnfs
|
|
5
|
-
} from "./chunk-VRRXG6IB.mjs";
|
|
6
|
-
import {
|
|
7
|
-
WnfsCapabilities
|
|
8
|
-
} from "./chunk-KZANQHJY.mjs";
|
|
9
|
-
import "./chunk-VDDGZWAY.mjs";
|
|
10
|
-
|
|
11
|
-
// src/capabilities/markdown.ts
|
|
12
|
-
import { contributes } from "@dxos/app-framework";
|
|
13
|
-
import { MarkdownCapabilities } from "@dxos/plugin-markdown";
|
|
14
|
-
import { getSpace } from "@dxos/react-client/echo";
|
|
15
|
-
|
|
16
|
-
// src/extensions/image.tsx
|
|
17
|
-
import { syntaxTree } from "@codemirror/language";
|
|
18
|
-
import { StateField } from "@codemirror/state";
|
|
19
|
-
import { Decoration, EditorView, WidgetType } from "@codemirror/view";
|
|
20
|
-
import React from "react";
|
|
21
|
-
import { createRoot } from "react-dom/client";
|
|
22
|
-
import { Status, ThemeProvider } from "@dxos/react-ui";
|
|
23
|
-
import { focusField } from "@dxos/react-ui-editor";
|
|
24
|
-
import { defaultTx } from "@dxos/react-ui-theme";
|
|
25
|
-
var WAIT_UNTIL_LOADER = 1500;
|
|
26
|
-
var image = (options) => {
|
|
27
|
-
const blobUrlCache = {};
|
|
28
|
-
const preloaded = /* @__PURE__ */ new Set();
|
|
29
|
-
const preload = (url) => {
|
|
30
|
-
if (!preloaded.has(url)) {
|
|
31
|
-
const img = document.createElement("img");
|
|
32
|
-
img.src = url;
|
|
33
|
-
preloaded.add(url);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
return [
|
|
37
|
-
StateField.define({
|
|
38
|
-
create: (state) => {
|
|
39
|
-
return Decoration.set(buildDecorations({
|
|
40
|
-
from: 0,
|
|
41
|
-
to: state.doc.length,
|
|
42
|
-
state,
|
|
43
|
-
blobUrlCache,
|
|
44
|
-
preload,
|
|
45
|
-
options
|
|
46
|
-
}));
|
|
47
|
-
},
|
|
48
|
-
update: (value, tr) => {
|
|
49
|
-
if (!tr.docChanged && !tr.selection) {
|
|
50
|
-
return value;
|
|
51
|
-
}
|
|
52
|
-
const cursor = tr.state.selection.main.head;
|
|
53
|
-
const oldCursor = tr.changes.mapPos(tr.startState.selection.main.head);
|
|
54
|
-
let from = Math.min(cursor, oldCursor);
|
|
55
|
-
let to = Math.max(cursor, oldCursor);
|
|
56
|
-
tr.changes.iterChangedRanges((fromA, toA, fromB, toB) => {
|
|
57
|
-
from = Math.min(from, fromB);
|
|
58
|
-
to = Math.max(to, toB);
|
|
59
|
-
});
|
|
60
|
-
from = tr.state.doc.lineAt(from).from;
|
|
61
|
-
to = tr.state.doc.lineAt(to).to;
|
|
62
|
-
return value.map(tr.changes).update({
|
|
63
|
-
filterFrom: from,
|
|
64
|
-
filterTo: to,
|
|
65
|
-
filter: () => false,
|
|
66
|
-
add: buildDecorations({
|
|
67
|
-
from,
|
|
68
|
-
to,
|
|
69
|
-
state: tr.state,
|
|
70
|
-
blobUrlCache,
|
|
71
|
-
preload,
|
|
72
|
-
options
|
|
73
|
-
})
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
provide: (field) => EditorView.decorations.from(field)
|
|
77
|
-
})
|
|
78
|
-
];
|
|
79
|
-
};
|
|
80
|
-
var buildDecorations = ({ from, to, state, blobUrlCache, preload, options: { blockstore, instances, space } }) => {
|
|
81
|
-
const decorations = [];
|
|
82
|
-
const cursor = state.selection.main.head;
|
|
83
|
-
syntaxTree(state).iterate({
|
|
84
|
-
enter: (node) => {
|
|
85
|
-
if (node.name !== "Image") {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
const urlNode = node.node.getChild("URL");
|
|
89
|
-
if (!urlNode) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const hide = state.readOnly || cursor < node.from || cursor > node.to;
|
|
93
|
-
const wnfsUrl = state.sliceDoc(urlNode.from, urlNode.to);
|
|
94
|
-
if (!wnfsUrl.startsWith("wnfs://")) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const path = getPathFromUrl(wnfsUrl);
|
|
98
|
-
const spaceId = path[1];
|
|
99
|
-
if (spaceId !== space.id) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const blobUrlPromise = (async () => {
|
|
103
|
-
const { directory, forest } = await loadWnfs({
|
|
104
|
-
blockstore,
|
|
105
|
-
instances,
|
|
106
|
-
space
|
|
107
|
-
});
|
|
108
|
-
const url = await getBlobUrl({
|
|
109
|
-
wnfsUrl,
|
|
110
|
-
blockstore,
|
|
111
|
-
directory,
|
|
112
|
-
forest
|
|
113
|
-
});
|
|
114
|
-
blobUrlCache[path.join("/")] = url;
|
|
115
|
-
preload(url);
|
|
116
|
-
return url;
|
|
117
|
-
})();
|
|
118
|
-
decorations.push(Decoration.replace({
|
|
119
|
-
block: true,
|
|
120
|
-
widget: new WnfsImageWidget(wnfsUrl, blobUrlCache[path.join("/")] ?? blobUrlPromise)
|
|
121
|
-
}).range(hide ? node.from : node.to, node.to));
|
|
122
|
-
},
|
|
123
|
-
from,
|
|
124
|
-
to
|
|
125
|
-
});
|
|
126
|
-
return decorations;
|
|
127
|
-
};
|
|
128
|
-
var createImg = (view, url) => {
|
|
129
|
-
const img = document.createElement("img");
|
|
130
|
-
img.setAttribute("src", url);
|
|
131
|
-
img.setAttribute("class", "cm-image-with-loader");
|
|
132
|
-
if (view.state.field(focusField)) {
|
|
133
|
-
img.onload = () => img.classList.add("cm-loaded-image");
|
|
134
|
-
} else {
|
|
135
|
-
img.classList.add("cm-loaded-image");
|
|
136
|
-
}
|
|
137
|
-
return img;
|
|
138
|
-
};
|
|
139
|
-
var WnfsImageWidget = class extends WidgetType {
|
|
140
|
-
constructor(_wnfsUrl, _url) {
|
|
141
|
-
super(), this._wnfsUrl = _wnfsUrl, this._url = _url;
|
|
142
|
-
}
|
|
143
|
-
eq(other) {
|
|
144
|
-
return this._wnfsUrl === other._wnfsUrl;
|
|
145
|
-
}
|
|
146
|
-
toDOM(view) {
|
|
147
|
-
if (typeof this._url === "string") {
|
|
148
|
-
return createImg(view, this._url);
|
|
149
|
-
}
|
|
150
|
-
const widget = document.createElement("div");
|
|
151
|
-
widget.className = "cm-image-wrapper";
|
|
152
|
-
const loader = document.createElement("div");
|
|
153
|
-
loader.className = "mx-auto transition-opacity";
|
|
154
|
-
let loaderAdded = false;
|
|
155
|
-
const timeout = setTimeout(() => {
|
|
156
|
-
const root = createRoot(loader);
|
|
157
|
-
root.render(/* @__PURE__ */ React.createElement(ThemeProvider, {
|
|
158
|
-
tx: defaultTx
|
|
159
|
-
}, /* @__PURE__ */ React.createElement(Status, {
|
|
160
|
-
indeterminate: true
|
|
161
|
-
})));
|
|
162
|
-
widget.appendChild(loader);
|
|
163
|
-
loaderAdded = true;
|
|
164
|
-
}, WAIT_UNTIL_LOADER);
|
|
165
|
-
void this._url.then((url) => {
|
|
166
|
-
clearTimeout(timeout);
|
|
167
|
-
const img = createImg(view, url);
|
|
168
|
-
loaderAdded && widget.removeChild(loader);
|
|
169
|
-
widget.appendChild(img);
|
|
170
|
-
});
|
|
171
|
-
return widget;
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// src/capabilities/markdown.ts
|
|
176
|
-
var markdown_default = (context) => contributes(MarkdownCapabilities.Extensions, [
|
|
177
|
-
({ document: document2 }) => {
|
|
178
|
-
const blockstore = context.getCapability(WnfsCapabilities.Blockstore);
|
|
179
|
-
const instances = context.getCapability(WnfsCapabilities.Instances);
|
|
180
|
-
if (document2) {
|
|
181
|
-
const space = getSpace(document2);
|
|
182
|
-
return space ? [
|
|
183
|
-
image({
|
|
184
|
-
blockstore,
|
|
185
|
-
instances,
|
|
186
|
-
space
|
|
187
|
-
})
|
|
188
|
-
] : [];
|
|
189
|
-
}
|
|
190
|
-
return [];
|
|
191
|
-
}
|
|
192
|
-
]);
|
|
193
|
-
export {
|
|
194
|
-
markdown_default as default
|
|
195
|
-
};
|
|
196
|
-
//# sourceMappingURL=markdown-6VH477GB.mjs.map
|
|
@@ -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,gB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L,MAAAA;AACxBI,WAAKE,OACH,sBAAA,cAACC,eAAAA;QAAcC,IAAIC;SACjB,sBAAA,cAACC,QAAAA;QAAOC,eAAAA;;AAGZ3B,aAAO4B,YAAYZ,MAAAA;AACnBC,oBAAc;IAChB,GAAGnG,iBAAAA;AAEH,SAAK,KAAK6F,KAAKkB,KAAK,CAACxG,QAAAA;AACnByG,mBAAaZ,OAAAA;AACb,YAAM3F,MAAM4E,UAAUC,MAAM/E,GAAAA;AAC5B4F,qBAAejB,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,88 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FileType,
|
|
3
|
-
WnfsAction
|
|
4
|
-
} from "./chunk-GVBV2QWA.mjs";
|
|
5
|
-
import {
|
|
6
|
-
WNFS_PLUGIN
|
|
7
|
-
} from "./chunk-VDDGZWAY.mjs";
|
|
8
|
-
|
|
9
|
-
// src/capabilities/react-surface.tsx
|
|
10
|
-
import React2, { useCallback as useCallback2 } from "react";
|
|
11
|
-
import { contributes, Capabilities, createSurface } from "@dxos/app-framework";
|
|
12
|
-
import { Obj } from "@dxos/echo";
|
|
13
|
-
import { findAnnotation as findAnnotation2 } from "@dxos/effect";
|
|
14
|
-
|
|
15
|
-
// src/components/index.ts
|
|
16
|
-
import { lazy } from "react";
|
|
17
|
-
|
|
18
|
-
// src/components/FileInput.tsx
|
|
19
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
20
|
-
import React, { useCallback } from "react";
|
|
21
|
-
import { useDropzone } from "react-dropzone";
|
|
22
|
-
import { findAnnotation } from "@dxos/effect";
|
|
23
|
-
import { useTranslation } from "@dxos/react-ui";
|
|
24
|
-
import { mx } from "@dxos/react-ui-theme";
|
|
25
|
-
var FileInput = ({ schema, onChange }) => {
|
|
26
|
-
var _effect = _useSignals();
|
|
27
|
-
try {
|
|
28
|
-
const { t } = useTranslation(WNFS_PLUGIN);
|
|
29
|
-
const accept = findAnnotation(schema.ast, WnfsAction.UploadAnnotationId);
|
|
30
|
-
const onDropAccepted = useCallback((files) => onChange?.(files[0]), [
|
|
31
|
-
onChange
|
|
32
|
-
]);
|
|
33
|
-
const { acceptedFiles, getRootProps, getInputProps, isFocused, isDragAccept, isDragReject } = useDropzone({
|
|
34
|
-
multiple: false,
|
|
35
|
-
accept,
|
|
36
|
-
onDropAccepted
|
|
37
|
-
});
|
|
38
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
39
|
-
...getRootProps(),
|
|
40
|
-
className: mx("flex flex-col items-center p-8 border border-separator", isFocused && "focus-ring", isDragAccept && "bg-attention", isDragReject && "border-error")
|
|
41
|
-
}, /* @__PURE__ */ React.createElement("input", getInputProps()), acceptedFiles[0] ? /* @__PURE__ */ React.createElement("p", null, acceptedFiles[0].name) : /* @__PURE__ */ React.createElement("p", null, t("file input placeholder")));
|
|
42
|
-
} finally {
|
|
43
|
-
_effect.f();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// src/components/index.ts
|
|
48
|
-
var FileContainer = lazy(() => import("./FileContainer-Q4GUPBVD.mjs"));
|
|
49
|
-
|
|
50
|
-
// src/capabilities/react-surface.tsx
|
|
51
|
-
var react_surface_default = () => contributes(Capabilities.ReactSurface, [
|
|
52
|
-
createSurface({
|
|
53
|
-
id: `${WNFS_PLUGIN}/article`,
|
|
54
|
-
role: [
|
|
55
|
-
"article",
|
|
56
|
-
"section",
|
|
57
|
-
"slide"
|
|
58
|
-
],
|
|
59
|
-
filter: (data) => Obj.instanceOf(FileType, data.subject),
|
|
60
|
-
component: ({ data, role }) => /* @__PURE__ */ React2.createElement(FileContainer, {
|
|
61
|
-
role,
|
|
62
|
-
file: data.subject
|
|
63
|
-
})
|
|
64
|
-
}),
|
|
65
|
-
createSurface({
|
|
66
|
-
id: `${WNFS_PLUGIN}/create-form`,
|
|
67
|
-
role: "form-input",
|
|
68
|
-
filter: (data) => {
|
|
69
|
-
const annotation = findAnnotation2(data.schema.ast, WnfsAction.UploadAnnotationId);
|
|
70
|
-
return !!annotation;
|
|
71
|
-
},
|
|
72
|
-
component: ({ data: { prop, schema }, ...props }) => {
|
|
73
|
-
const inputProps = props;
|
|
74
|
-
const handleChange = useCallback2((file) => inputProps.onValueChange?.("object", file), [
|
|
75
|
-
prop,
|
|
76
|
-
inputProps.onValueChange
|
|
77
|
-
]);
|
|
78
|
-
return /* @__PURE__ */ React2.createElement(FileInput, {
|
|
79
|
-
schema,
|
|
80
|
-
onChange: handleChange
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
]);
|
|
85
|
-
export {
|
|
86
|
-
react_surface_default as default
|
|
87
|
-
};
|
|
88
|
-
//# sourceMappingURL=react-surface-XAHVMWIH.mjs.map
|
|
@@ -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": ";;;;;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AQ,OAAA,cAACC,eAAAA;MAAcT;MAAYU,MAAMR,KAAKI;;EACvE,CAAA;EACAT,cAAc;IACZC,IAAI,GAAGC,WAAAA;IACPC,MAAM;IACNC,QAAQ,CAACC,SAAAA;AACP,YAAMS,aAAaC,gBAChBV,KAAKW,OAA6BC,KACnCC,WAAWC,kBAAkB;AAE/B,aAAO,CAAC,CAACL;IACX;IACAJ,WAAW,CAAC,EAAEL,MAAM,EAAEe,MAAMJ,OAAM,GAAI,GAAGK,MAAAA,MAAO;AAC9C,YAAMC,aAAaD;AACnB,YAAME,eAAeC,aACnB,CAACX,SAAeS,WAAWG,gBAAgB,UAAUZ,IAAAA,GACrD;QAACO;QAAME,WAAWG;OAAc;AAGlC,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
|
-
}
|