@dxos/plugin-wnfs 0.8.4-main.937b3ca → 0.8.4-main.9be5663bfe

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.
Files changed (149) hide show
  1. package/dist/lib/browser/chunk-BM3MEFES.mjs +69 -0
  2. package/dist/lib/browser/chunk-BM3MEFES.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-NCTUASHL.mjs → chunk-N6Y4QPNF.mjs} +15 -32
  4. package/dist/lib/browser/chunk-N6Y4QPNF.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-VXUCZHVZ.mjs +69 -0
  6. package/dist/lib/browser/chunk-VXUCZHVZ.mjs.map +7 -0
  7. package/dist/lib/browser/create-NOHKWE67.mjs +24 -0
  8. package/dist/lib/browser/create-NOHKWE67.mjs.map +7 -0
  9. package/dist/lib/browser/create-file-N7ADCFOF.mjs +49 -0
  10. package/dist/lib/browser/create-file-N7ADCFOF.mjs.map +7 -0
  11. package/dist/lib/browser/index.mjs +71 -70
  12. package/dist/lib/browser/index.mjs.map +4 -4
  13. package/dist/lib/browser/meta.json +1 -1
  14. package/dist/lib/browser/operations/index.mjs +13 -0
  15. package/dist/lib/browser/operations/index.mjs.map +7 -0
  16. package/dist/lib/browser/types/index.mjs +3 -5
  17. package/dist/lib/browser/upload-DA7GBOXF.mjs +42 -0
  18. package/dist/lib/browser/upload-DA7GBOXF.mjs.map +7 -0
  19. package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
  20. package/dist/types/src/capabilities/blockstore.d.ts +5 -0
  21. package/dist/types/src/capabilities/blockstore.d.ts.map +1 -0
  22. package/dist/types/src/capabilities/file-uploader.d.ts +6 -0
  23. package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -0
  24. package/dist/types/src/capabilities/index.d.ts +7 -5
  25. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  26. package/dist/types/src/capabilities/markdown.d.ts +5 -0
  27. package/dist/types/src/capabilities/markdown.d.ts.map +1 -0
  28. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  29. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  30. package/dist/types/src/capabilities/react-surface.d.ts +5 -0
  31. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  32. package/dist/types/src/components/FileInput/FileInput.d.ts.map +1 -0
  33. package/dist/types/src/components/FileInput/index.d.ts +2 -0
  34. package/dist/types/src/components/FileInput/index.d.ts.map +1 -0
  35. package/dist/types/src/components/FilePreview/FilePreview.d.ts +12 -0
  36. package/dist/types/src/components/FilePreview/FilePreview.d.ts.map +1 -0
  37. package/dist/types/src/components/FilePreview/index.d.ts +2 -0
  38. package/dist/types/src/components/FilePreview/index.d.ts.map +1 -0
  39. package/dist/types/src/components/index.d.ts +1 -1
  40. package/dist/types/src/components/index.d.ts.map +1 -1
  41. package/dist/types/src/containers/FileContainer/FileContainer.d.ts +7 -0
  42. package/dist/types/src/containers/FileContainer/FileContainer.d.ts.map +1 -0
  43. package/dist/types/src/containers/FileContainer/index.d.ts +2 -0
  44. package/dist/types/src/containers/FileContainer/index.d.ts.map +1 -0
  45. package/dist/types/src/containers/index.d.ts +3 -0
  46. package/dist/types/src/containers/index.d.ts.map +1 -0
  47. package/dist/types/src/extensions/image.d.ts +1 -1
  48. package/dist/types/src/extensions/image.d.ts.map +1 -1
  49. package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
  50. package/dist/types/src/helpers/load.d.ts +1 -1
  51. package/dist/types/src/helpers/load.d.ts.map +1 -1
  52. package/dist/types/src/helpers/upload.d.ts +1 -1
  53. package/dist/types/src/helpers/upload.d.ts.map +1 -1
  54. package/dist/types/src/operations/create-file.d.ts +5 -0
  55. package/dist/types/src/operations/create-file.d.ts.map +1 -0
  56. package/dist/types/src/operations/create.d.ts +5 -0
  57. package/dist/types/src/operations/create.d.ts.map +1 -0
  58. package/dist/types/src/operations/definitions.d.ts +38 -0
  59. package/dist/types/src/operations/definitions.d.ts.map +1 -0
  60. package/dist/types/src/operations/index.d.ts +4 -0
  61. package/dist/types/src/operations/index.d.ts.map +1 -0
  62. package/dist/types/src/operations/upload.d.ts +5 -0
  63. package/dist/types/src/operations/upload.d.ts.map +1 -0
  64. package/dist/types/src/translations.d.ts +13 -12
  65. package/dist/types/src/translations.d.ts.map +1 -1
  66. package/dist/types/src/types/File.d.ts +1 -1
  67. package/dist/types/src/types/File.d.ts.map +1 -1
  68. package/dist/types/src/types/types.d.ts +1 -104
  69. package/dist/types/src/types/types.d.ts.map +1 -1
  70. package/dist/types/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +47 -30
  72. package/src/WnfsPlugin.tsx +36 -36
  73. package/src/blockstore.ts +1 -1
  74. package/src/capabilities/{blockstore/blockstore.ts → blockstore.ts} +4 -3
  75. package/src/capabilities/{file-uploader/file-uploader.ts → file-uploader.ts} +6 -5
  76. package/src/capabilities/index.ts +11 -5
  77. package/src/capabilities/{markdown/markdown.ts → markdown.ts} +3 -2
  78. package/src/capabilities/operation-handler.ts +16 -0
  79. package/src/capabilities/{react-surface/react-surface.tsx → react-surface.tsx} +13 -11
  80. package/src/components/{FileInput.tsx → FileInput/FileInput.tsx} +5 -5
  81. package/src/components/FileInput/index.ts +5 -0
  82. package/src/components/FilePreview/FilePreview.tsx +43 -0
  83. package/src/components/FilePreview/index.ts +5 -0
  84. package/src/components/index.ts +1 -4
  85. package/src/{components → containers/FileContainer}/FileContainer.tsx +12 -11
  86. package/src/containers/FileContainer/index.ts +5 -0
  87. package/src/containers/index.ts +7 -0
  88. package/src/extensions/image.stories.tsx +9 -10
  89. package/src/extensions/image.tsx +2 -1
  90. package/src/helpers/load.ts +6 -6
  91. package/src/helpers/upload.ts +3 -3
  92. package/src/meta.ts +1 -1
  93. package/src/operations/create-file.ts +31 -0
  94. package/src/operations/create.ts +22 -0
  95. package/src/operations/definitions.ts +41 -0
  96. package/src/operations/index.ts +13 -0
  97. package/src/operations/upload.ts +29 -0
  98. package/src/translations.ts +13 -12
  99. package/src/types/File.ts +6 -2
  100. package/src/types/capabilities.ts +3 -3
  101. package/src/types/types.ts +3 -59
  102. package/dist/lib/browser/FileContainer-O5YFSIWV.mjs +0 -91
  103. package/dist/lib/browser/FileContainer-O5YFSIWV.mjs.map +0 -7
  104. package/dist/lib/browser/blockstore-KKFOALUH.mjs +0 -191
  105. package/dist/lib/browser/blockstore-KKFOALUH.mjs.map +0 -7
  106. package/dist/lib/browser/chunk-GXXEH7H6.mjs +0 -154
  107. package/dist/lib/browser/chunk-GXXEH7H6.mjs.map +0 -7
  108. package/dist/lib/browser/chunk-NCTUASHL.mjs.map +0 -7
  109. package/dist/lib/browser/file-uploader-BUHAXRSV.mjs +0 -34
  110. package/dist/lib/browser/file-uploader-BUHAXRSV.mjs.map +0 -7
  111. package/dist/lib/browser/markdown-BRT2MN6C.mjs +0 -201
  112. package/dist/lib/browser/markdown-BRT2MN6C.mjs.map +0 -7
  113. package/dist/lib/browser/operation-resolver-F6GUL54A.mjs +0 -99
  114. package/dist/lib/browser/operation-resolver-F6GUL54A.mjs.map +0 -7
  115. package/dist/lib/browser/react-surface-UNAYSIAC.mjs +0 -81
  116. package/dist/lib/browser/react-surface-UNAYSIAC.mjs.map +0 -7
  117. package/dist/types/src/capabilities/blockstore/blockstore.d.ts +0 -5
  118. package/dist/types/src/capabilities/blockstore/blockstore.d.ts.map +0 -1
  119. package/dist/types/src/capabilities/blockstore/index.d.ts +0 -3
  120. package/dist/types/src/capabilities/blockstore/index.d.ts.map +0 -1
  121. package/dist/types/src/capabilities/file-uploader/file-uploader.d.ts +0 -5
  122. package/dist/types/src/capabilities/file-uploader/file-uploader.d.ts.map +0 -1
  123. package/dist/types/src/capabilities/file-uploader/index.d.ts +0 -3
  124. package/dist/types/src/capabilities/file-uploader/index.d.ts.map +0 -1
  125. package/dist/types/src/capabilities/markdown/index.d.ts +0 -3
  126. package/dist/types/src/capabilities/markdown/index.d.ts.map +0 -1
  127. package/dist/types/src/capabilities/markdown/markdown.d.ts +0 -5
  128. package/dist/types/src/capabilities/markdown/markdown.d.ts.map +0 -1
  129. package/dist/types/src/capabilities/operation-resolver/index.d.ts +0 -3
  130. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +0 -1
  131. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +0 -5
  132. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +0 -1
  133. package/dist/types/src/capabilities/react-surface/index.d.ts +0 -3
  134. package/dist/types/src/capabilities/react-surface/index.d.ts.map +0 -1
  135. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +0 -5
  136. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +0 -1
  137. package/dist/types/src/components/FileContainer.d.ts +0 -7
  138. package/dist/types/src/components/FileContainer.d.ts.map +0 -1
  139. package/dist/types/src/components/FileInput.d.ts.map +0 -1
  140. package/dist/types/src/components/FilePreview.d.ts +0 -11
  141. package/dist/types/src/components/FilePreview.d.ts.map +0 -1
  142. package/src/capabilities/blockstore/index.ts +0 -7
  143. package/src/capabilities/file-uploader/index.ts +0 -7
  144. package/src/capabilities/markdown/index.ts +0 -7
  145. package/src/capabilities/operation-resolver/index.ts +0 -7
  146. package/src/capabilities/operation-resolver/operation-resolver.ts +0 -62
  147. package/src/capabilities/react-surface/index.ts +0 -7
  148. package/src/components/FilePreview.tsx +0 -23
  149. /package/dist/types/src/components/{FileInput.d.ts → FileInput/FileInput.d.ts} +0 -0
@@ -1,154 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // src/types/capabilities.ts
8
- import { Capability } from "@dxos/app-framework";
9
-
10
- // src/meta.ts
11
- import { trim } from "@dxos/util";
12
- var meta = {
13
- id: "dxos.org/plugin/wnfs",
14
- name: "WNFS",
15
- description: trim`
16
- Decentralized file storage using the Web Native File System protocol.
17
- Store and sync files with end-to-end encryption across devices without central servers.
18
- `,
19
- icon: "ph--file-cloud--regular",
20
- iconHue: "teal",
21
- source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs"
22
- };
23
-
24
- // src/types/capabilities.ts
25
- (function(WnfsCapabilities2) {
26
- WnfsCapabilities2.Blockstore = Capability.make(`${meta.id}/capability/blockstore`);
27
- WnfsCapabilities2.Instances = Capability.make(`${meta.id}/capability/instances`);
28
- })(WnfsCapabilities || (WnfsCapabilities = {}));
29
- var WnfsCapabilities;
30
-
31
- // src/types/File.ts
32
- var File_exports = {};
33
- __export(File_exports, {
34
- File: () => File,
35
- make: () => make
36
- });
37
- import * as Schema from "effect/Schema";
38
- import { Obj, Type } from "@dxos/echo";
39
- import { FormInputAnnotation } from "@dxos/echo/internal";
40
- var File = Schema.Struct({
41
- name: Schema.String.pipe(Schema.optional),
42
- type: Schema.String.pipe(FormInputAnnotation.set(false)),
43
- cid: Schema.String.pipe(FormInputAnnotation.set(false)),
44
- timestamp: Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional)
45
- }).pipe(Type.object({
46
- typename: "dxos.org/type/File",
47
- version: "0.1.0"
48
- }));
49
- var make = (props) => Obj.make(File, props);
50
-
51
- // src/types/types.ts
52
- import * as Schema2 from "effect/Schema";
53
- import { Capability as Capability2, Common } from "@dxos/app-framework";
54
- import { Database } from "@dxos/echo";
55
- import { Operation } from "@dxos/operation";
56
- import { SpaceSchema } from "@dxos/react-client/echo";
57
- import { Collection } from "@dxos/schema";
58
- (function(WnfsAction2) {
59
- WnfsAction2.UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);
60
- WnfsAction2.UploadFileSchema = Schema2.Struct({
61
- file: Schema2.instanceOf(File).annotations({
62
- [WnfsAction2.UploadAnnotationId]: {
63
- // Accept file types.
64
- "image/*": [
65
- ".jpg",
66
- ".jpeg",
67
- ".png",
68
- ".gif"
69
- ],
70
- "application/pdf": [
71
- ".pdf"
72
- ]
73
- }
74
- })
75
- });
76
- })(WnfsAction || (WnfsAction = {}));
77
- var WNFS_OPERATION = `${meta.id}/operation`;
78
- (function(WnfsOperation2) {
79
- WnfsOperation2.OnCreateSpace = Operation.make({
80
- meta: {
81
- key: `${WNFS_OPERATION}/on-create-space`,
82
- name: "On Create Space"
83
- },
84
- services: [
85
- Capability2.Service
86
- ],
87
- schema: {
88
- input: Schema2.Struct({
89
- space: SpaceSchema,
90
- rootCollection: Collection.Collection,
91
- isDefault: Schema2.optional(Schema2.Boolean)
92
- }),
93
- output: Schema2.Void
94
- }
95
- });
96
- WnfsOperation2.Create = Operation.make({
97
- meta: {
98
- key: `${WNFS_OPERATION}/create`,
99
- name: "Create WNFS File"
100
- },
101
- services: [
102
- Capability2.Service
103
- ],
104
- schema: {
105
- input: Common.FileInfoSchema.pick("name", "type", "cid").pipe(Schema2.required),
106
- output: Schema2.Struct({
107
- object: File
108
- })
109
- }
110
- });
111
- WnfsOperation2.Upload = Operation.make({
112
- meta: {
113
- key: `${WNFS_OPERATION}/upload`,
114
- name: "Upload File"
115
- },
116
- services: [
117
- Capability2.Service
118
- ],
119
- schema: {
120
- input: Schema2.extend(WnfsAction.UploadFileSchema, Schema2.Struct({
121
- db: Database.Database
122
- })),
123
- output: Schema2.required(Common.FileInfoSchema)
124
- }
125
- });
126
- WnfsOperation2.CreateFile = Operation.make({
127
- meta: {
128
- key: `${WNFS_OPERATION}/create-file`,
129
- name: "Create File"
130
- },
131
- services: [
132
- Capability2.Service
133
- ],
134
- schema: {
135
- input: Schema2.extend(WnfsAction.UploadFileSchema, Schema2.Struct({
136
- db: Database.Database
137
- })),
138
- output: Schema2.Struct({
139
- object: File
140
- })
141
- }
142
- });
143
- })(WnfsOperation || (WnfsOperation = {}));
144
- var WnfsAction;
145
- var WnfsOperation;
146
-
147
- export {
148
- meta,
149
- WnfsCapabilities,
150
- File_exports,
151
- WnfsAction,
152
- WnfsOperation
153
- };
154
- //# sourceMappingURL=chunk-GXXEH7H6.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 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, Common } from '@dxos/app-framework';\nimport { Database } from '@dxos/echo';\nimport { Operation } from '@dxos/operation';\nimport { SpaceSchema } from '@dxos/react-client/echo';\nimport { Collection } from '@dxos/schema';\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: Common.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(Common.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,kBA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"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", "Common", "Database", "Operation", "SpaceSchema", "Collection", "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", "Common", "FileInfoSchema", "pick", "pipe", "required", "object", "Upload", "extend", "db", "Database", "CreateFile"]
7
- }
@@ -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, 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", "//\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: wn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AA;AAC5E,QAAMI,YAAYC,MAAMP,UAAAA;AAExB,QAAMQ,QAAQ,IAAIC,WAAW,MAAMV,KAAKW,YAAW,CAAA;AACnD,QAAMC,OAAO,MAAMC,QAAOC,OAAOL,KAAAA;AACjC,QAAMM,MAAMC,KAAIC,OAAO,GAAOC,UAAMN,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", "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", "CID", "Raw", "sha256", "Obj", "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", "Obj", "change", "properties", "p", "wnfs", "privateForestCid", "decode", "info", "name", "type", "url", "wnfsUrl", "log"]
7
- }
@@ -1,34 +0,0 @@
1
- import {
2
- WnfsOperation
3
- } from "./chunk-GXXEH7H6.mjs";
4
-
5
- // src/capabilities/file-uploader/file-uploader.ts
6
- import * as Effect from "effect/Effect";
7
- import { Capability, Common } from "@dxos/app-framework";
8
- import { runAndForwardErrors } from "@dxos/effect";
9
- import { SpaceOperation } from "@dxos/plugin-space/types";
10
- var file_uploader_default = Capability.makeModule(Effect.fnUntraced(function* () {
11
- const capabilities = yield* Capability.Service;
12
- return Capability.contributes(Common.Capability.FileUploader, (db, file) => {
13
- const { invoke } = capabilities.get(Common.Capability.OperationInvoker);
14
- const program = Effect.gen(function* () {
15
- const fileInfo = yield* invoke(WnfsOperation.Upload, {
16
- db,
17
- file
18
- });
19
- const createResult = yield* invoke(WnfsOperation.Create, fileInfo);
20
- if (createResult?.object) {
21
- yield* invoke(SpaceOperation.AddObject, {
22
- target: db,
23
- object: createResult.object
24
- });
25
- }
26
- return fileInfo;
27
- });
28
- return runAndForwardErrors(program);
29
- });
30
- }));
31
- export {
32
- file_uploader_default as default
33
- };
34
- //# sourceMappingURL=file-uploader-BUHAXRSV.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/capabilities/file-uploader/file-uploader.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { Capability, Common } from '@dxos/app-framework';\nimport { runAndForwardErrors } from '@dxos/effect';\nimport { SpaceOperation } from '@dxos/plugin-space/types';\n\nimport { WnfsOperation } from '../../types';\n\nexport default Capability.makeModule(\n Effect.fnUntraced(function* () {\n // Get context for lazy capability access in callbacks.\n const capabilities = yield* Capability.Service;\n\n return Capability.contributes(Common.Capability.FileUploader, (db, file) => {\n const { invoke } = capabilities.get(Common.Capability.OperationInvoker);\n const program = Effect.gen(function* () {\n const fileInfo = yield* invoke(WnfsOperation.Upload, { db, file });\n const createResult = yield* invoke(WnfsOperation.Create, fileInfo);\n if (createResult?.object) {\n yield* invoke(SpaceOperation.AddObject, { target: db, object: createResult.object });\n }\n\n return fileInfo;\n });\n\n return runAndForwardErrors(program);\n });\n }),\n);\n"],
5
- "mappings": ";;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,YAAYC,cAAc;AACnC,SAASC,2BAA2B;AACpC,SAASC,sBAAsB;AAI/B,IAAA,wBAAeC,WAAWC,WACjBC,kBAAW,aAAA;AAEhB,QAAMC,eAAe,OAAOH,WAAWI;AAEvC,SAAOJ,WAAWK,YAAYC,OAAON,WAAWO,cAAc,CAACC,IAAIC,SAAAA;AACjE,UAAM,EAAEC,OAAM,IAAKP,aAAaQ,IAAIL,OAAON,WAAWY,gBAAgB;AACtE,UAAMC,UAAiBC,WAAI,aAAA;AACzB,YAAMC,WAAW,OAAOL,OAAOM,cAAcC,QAAQ;QAAET;QAAIC;MAAK,CAAA;AAChE,YAAMS,eAAe,OAAOR,OAAOM,cAAcG,QAAQJ,QAAAA;AACzD,UAAIG,cAAcE,QAAQ;AACxB,eAAOV,OAAOW,eAAeC,WAAW;UAAEC,QAAQf;UAAIY,QAAQF,aAAaE;QAAO,CAAA;MACpF;AAEA,aAAOL;IACT,CAAA;AAEA,WAAOS,oBAAoBX,OAAAA;EAC7B,CAAA;AACF,CAAA,CAAA;",
6
- "names": ["Effect", "Capability", "Common", "runAndForwardErrors", "SpaceOperation", "Capability", "makeModule", "fnUntraced", "capabilities", "Service", "contributes", "Common", "FileUploader", "db", "file", "invoke", "get", "OperationInvoker", "program", "gen", "fileInfo", "WnfsOperation", "Upload", "createResult", "Create", "object", "SpaceOperation", "AddObject", "target", "runAndForwardErrors"]
7
- }
@@ -1,201 +0,0 @@
1
- import {
2
- getBlobUrl,
3
- getPathFromUrl,
4
- loadWnfs
5
- } from "./chunk-NCTUASHL.mjs";
6
- import {
7
- WnfsCapabilities
8
- } from "./chunk-GXXEH7H6.mjs";
9
-
10
- // src/capabilities/markdown/markdown.ts
11
- import * as Effect from "effect/Effect";
12
- import { Capability } 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/ui-editor";
24
- import { defaultTx } from "@dxos/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 = ({ state, from, to, 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
- _wnfsUrl;
141
- _url;
142
- constructor(_wnfsUrl, _url) {
143
- super(), this._wnfsUrl = _wnfsUrl, this._url = _url;
144
- }
145
- eq(other) {
146
- return this._wnfsUrl === other._wnfsUrl;
147
- }
148
- toDOM(view) {
149
- if (typeof this._url === "string") {
150
- return createImg(view, this._url);
151
- }
152
- const widget = document.createElement("div");
153
- widget.className = "cm-image-wrapper";
154
- const loader = document.createElement("div");
155
- loader.className = "mx-auto transition-opacity";
156
- let loaderAdded = false;
157
- const timeout = setTimeout(() => {
158
- const root = createRoot(loader);
159
- root.render(/* @__PURE__ */ React.createElement(ThemeProvider, {
160
- tx: defaultTx
161
- }, /* @__PURE__ */ React.createElement(Status, {
162
- indeterminate: true
163
- })));
164
- widget.appendChild(loader);
165
- loaderAdded = true;
166
- }, WAIT_UNTIL_LOADER);
167
- void this._url.then((url) => {
168
- clearTimeout(timeout);
169
- const img = createImg(view, url);
170
- loaderAdded && widget.removeChild(loader);
171
- widget.appendChild(img);
172
- });
173
- return widget;
174
- }
175
- };
176
-
177
- // src/capabilities/markdown/markdown.ts
178
- var markdown_default = Capability.makeModule(Effect.fnUntraced(function* () {
179
- const capabilities = yield* Capability.Service;
180
- return Capability.contributes(MarkdownCapabilities.Extensions, [
181
- ({ document: document2 }) => {
182
- const blockstore = capabilities.get(WnfsCapabilities.Blockstore);
183
- const instances = capabilities.get(WnfsCapabilities.Instances);
184
- if (document2) {
185
- const space = getSpace(document2);
186
- return space ? [
187
- image({
188
- blockstore,
189
- instances,
190
- space
191
- })
192
- ] : [];
193
- }
194
- return [];
195
- }
196
- ]);
197
- }));
198
- export {
199
- markdown_default as default
200
- };
201
- //# sourceMappingURL=markdown-BRT2MN6C.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/capabilities/markdown/markdown.ts", "../../../src/extensions/image.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { Capability } from '@dxos/app-framework';\nimport { MarkdownCapabilities } from '@dxos/plugin-markdown';\nimport { getSpace } from '@dxos/react-client/echo';\n\nimport { image } from '../../extensions';\nimport { WnfsCapabilities } from '../../types';\n\nexport default Capability.makeModule(\n Effect.fnUntraced(function* () {\n // Get context for lazy capability access in callbacks.\n const capabilities = yield* Capability.Service;\n\n return Capability.contributes(MarkdownCapabilities.Extensions, [\n ({ document }: { document?: any }) => {\n const blockstore = capabilities.get(WnfsCapabilities.Blockstore);\n const instances = capabilities.get(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);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { syntaxTree } from '@codemirror/language';\nimport { type EditorState, type Extension, type Range, StateField } 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/ui-editor';\nimport { defaultTx } from '@dxos/ui-theme';\nimport { type MaybePromise } from '@dxos/util';\n\nimport { getBlobUrl, getPathFromUrl, loadWnfs } from '../helpers';\nimport { type WnfsCapabilities } from '../types';\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 state,\n from,\n to,\n blobUrlCache,\n preload,\n options: { blockstore, instances, space },\n}: {\n state: EditorState;\n from: number;\n to: number;\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) {\n return this._wnfsUrl === other._wnfsUrl;\n }\n\n override toDOM(view: EditorView) {\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.appendCh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AAMC,SAASxF,SAASC,cAAc,KAAA;AACtCuF,WAAOD,YAAY;AACnB,QAAIE,cAAc;AAElB,UAAMC,UAAUC,WAAW,MAAA;AACzB,YAAMC,OAAOC,WAAWL,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;;;AD7LA,IAAA,mBAAegC,WAAWC,WACjBC,kBAAW,aAAA;AAEhB,QAAMC,eAAe,OAAOH,WAAWI;AAEvC,SAAOJ,WAAWK,YAAYC,qBAAqBC,YAAY;IAC7D,CAAC,EAAEC,UAAAA,UAAQ,MAAsB;AAC/B,YAAMC,aAAaN,aAAaO,IAAIC,iBAAiBC,UAAU;AAC/D,YAAMC,YAAYV,aAAaO,IAAIC,iBAAiBG,SAAS;AAE7D,UAAIN,WAAU;AACZ,cAAMO,QAAQC,SAASR,SAAAA;AACvB,eAAOO,QAAQ;UAACE,MAAM;YAAER;YAAYI;YAAWE;UAAM,CAAA;YAAM,CAAA;MAC7D;AAEA,aAAO,CAAA;IACT;GACD;AACH,CAAA,CAAA;",
6
- "names": ["Effect", "Capability", "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", "Capability", "makeModule", "fnUntraced", "capabilities", "Service", "contributes", "MarkdownCapabilities", "Extensions", "document", "blockstore", "get", "WnfsCapabilities", "Blockstore", "instances", "Instances", "space", "getSpace", "image"]
7
- }
@@ -1,99 +0,0 @@
1
- import {
2
- upload
3
- } from "./chunk-NCTUASHL.mjs";
4
- import {
5
- File_exports,
6
- WnfsCapabilities,
7
- WnfsOperation
8
- } from "./chunk-GXXEH7H6.mjs";
9
-
10
- // src/capabilities/operation-resolver/operation-resolver.ts
11
- import * as Effect from "effect/Effect";
12
- import { Capability, Common } from "@dxos/app-framework";
13
- import { Obj, Ref, Type } from "@dxos/echo";
14
- import { invariant } from "@dxos/invariant";
15
- import { OperationResolver } from "@dxos/operation";
16
- import { ClientCapabilities } from "@dxos/plugin-client";
17
- import { Collection } from "@dxos/schema";
18
- var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/capabilities/operation-resolver/operation-resolver.ts";
19
- var operation_resolver_default = Capability.makeModule(Effect.fnUntraced(function* () {
20
- return Capability.contributes(Common.Capability.OperationResolver, [
21
- OperationResolver.make({
22
- operation: WnfsOperation.OnCreateSpace,
23
- handler: Effect.fnUntraced(function* ({ rootCollection }) {
24
- const collection = Collection.makeManaged({
25
- key: Type.getTypename(File_exports.File)
26
- });
27
- Obj.change(rootCollection, (c) => {
28
- c.objects.push(Ref.make(collection));
29
- });
30
- })
31
- }),
32
- OperationResolver.make({
33
- operation: WnfsOperation.Create,
34
- handler: ({ name, type, cid }) => Effect.succeed({
35
- object: File_exports.make({
36
- name,
37
- type,
38
- cid
39
- })
40
- })
41
- }),
42
- OperationResolver.make({
43
- operation: WnfsOperation.Upload,
44
- handler: Effect.fnUntraced(function* ({ file, db }) {
45
- const client = yield* Capability.get(ClientCapabilities.Client);
46
- const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
47
- const space = client.spaces.get(db.spaceId);
48
- invariant(space, "Space not found", {
49
- F: __dxlog_file,
50
- L: 42,
51
- S: this,
52
- A: [
53
- "space",
54
- "'Space not found'"
55
- ]
56
- });
57
- const info = yield* Effect.promise(() => upload({
58
- file,
59
- blockstore,
60
- space
61
- }));
62
- return info;
63
- })
64
- }),
65
- OperationResolver.make({
66
- operation: WnfsOperation.CreateFile,
67
- handler: Effect.fnUntraced(function* ({ file, db }) {
68
- const client = yield* Capability.get(ClientCapabilities.Client);
69
- const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
70
- const space = client.spaces.get(db.spaceId);
71
- invariant(space, "Space not found", {
72
- F: __dxlog_file,
73
- L: 53,
74
- S: this,
75
- A: [
76
- "space",
77
- "'Space not found'"
78
- ]
79
- });
80
- const info = yield* Effect.promise(() => upload({
81
- file,
82
- blockstore,
83
- space
84
- }));
85
- return {
86
- object: File_exports.make({
87
- name: info.name,
88
- type: info.type,
89
- cid: info.cid
90
- })
91
- };
92
- })
93
- })
94
- ]);
95
- }));
96
- export {
97
- operation_resolver_default as default
98
- };
99
- //# sourceMappingURL=operation-resolver-F6GUL54A.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/capabilities/operation-resolver/operation-resolver.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { Capability, Common } from '@dxos/app-framework';\nimport { Obj, Ref, Type } from '@dxos/echo';\nimport { invariant } from '@dxos/invariant';\nimport { OperationResolver } from '@dxos/operation';\nimport { ClientCapabilities } from '@dxos/plugin-client';\nimport { Collection } from '@dxos/schema';\n\nimport { upload } from '../../helpers';\nimport { WnfsCapabilities, WnfsFile, WnfsOperation } from '../../types';\n\nexport default Capability.makeModule(\n Effect.fnUntraced(function* () {\n return Capability.contributes(Common.Capability.OperationResolver, [\n OperationResolver.make({\n operation: WnfsOperation.OnCreateSpace,\n handler: Effect.fnUntraced(function* ({ rootCollection }) {\n const collection = Collection.makeManaged({ key: Type.getTypename(WnfsFile.File) });\n Obj.change(rootCollection, (c) => {\n c.objects.push(Ref.make(collection));\n });\n }),\n }),\n OperationResolver.make({\n operation: WnfsOperation.Create,\n handler: ({ name, type, cid }) =>\n Effect.succeed({\n object: WnfsFile.make({ name, type, cid }),\n }),\n }),\n OperationResolver.make({\n operation: WnfsOperation.Upload,\n handler: Effect.fnUntraced(function* ({ file, db }) {\n const client = yield* Capability.get(ClientCapabilities.Client);\n const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);\n const space = client.spaces.get(db.spaceId);\n invariant(space, 'Space not found');\n const info = yield* Effect.promise(() => upload({ file, blockstore, space }));\n return info;\n }),\n }),\n OperationResolver.make({\n operation: WnfsOperation.CreateFile,\n handler: Effect.fnUntraced(function* ({ file, db }) {\n const client = yield* Capability.get(ClientCapabilities.Client);\n const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);\n const space = client.spaces.get(db.spaceId);\n invariant(space, 'Space not found');\n const info = yield* Effect.promise(() => upload({ file, blockstore, space }));\n return {\n object: WnfsFile.make({ name: info.name, type: info.type, cid: info.cid }),\n };\n }),\n }),\n ]);\n }),\n);\n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,CAAA;IACAzC,kBAAkBC,KAAK;MACrBC,WAAWC,cAAcyC;MACzBvC,SAAgBR,kBAAW,WAAW,EAAE+B,MAAMC,GAAE,GAAE;AAChD,cAAMC,SAAS,OAAOnC,WAAWoC,IAAIC,mBAAmBC,MAAM;AAC9D,cAAMC,aAAa,OAAOvC,WAAWoC,IAAII,iBAAiBC,UAAU;AACpE,cAAMC,QAAQP,OAAOQ,OAAOP,IAAIF,GAAGU,OAAO;AAC1CC,kBAAUH,OAAO,mBAAA;;;;;;;;;AACjB,cAAMI,OAAO,OAAcC,eAAQ,MAAMC,OAAO;UAAEf;UAAMM;UAAYG;QAAM,CAAA,CAAA;AAC1E,eAAO;UACLX,QAAQb,aAASZ,KAAK;YAAEqB,MAAMmB,KAAKnB;YAAMC,MAAMkB,KAAKlB;YAAMC,KAAKiB,KAAKjB;UAAI,CAAA;QAC1E;MACF,CAAA;IACF,CAAA;GACD;AACH,CAAA,CAAA;",
6
- "names": ["Effect", "Capability", "Common", "Obj", "Ref", "Type", "invariant", "OperationResolver", "ClientCapabilities", "Collection", "Capability", "makeModule", "fnUntraced", "contributes", "Common", "OperationResolver", "make", "operation", "WnfsOperation", "OnCreateSpace", "handler", "rootCollection", "collection", "Collection", "makeManaged", "key", "Type", "getTypename", "WnfsFile", "File", "Obj", "change", "c", "objects", "push", "Ref", "Create", "name", "type", "cid", "succeed", "object", "Upload", "file", "db", "client", "get", "ClientCapabilities", "Client", "blockstore", "WnfsCapabilities", "Blockstore", "space", "spaces", "spaceId", "invariant", "info", "promise", "upload", "CreateFile"]
7
- }