@dxos/plugin-wnfs 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8

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 (162) hide show
  1. package/LICENSE +102 -5
  2. package/PLUGIN.mdl +371 -0
  3. package/README.md +2 -2
  4. package/dist/lib/neutral/WnfsPlugin.mjs +51 -0
  5. package/dist/lib/neutral/WnfsPlugin.mjs.map +7 -0
  6. package/dist/lib/neutral/WnfsPlugin.node.mjs +12 -0
  7. package/dist/lib/neutral/WnfsPlugin.node.mjs.map +7 -0
  8. package/dist/lib/neutral/WnfsPlugin.workerd.mjs +12 -0
  9. package/dist/lib/neutral/WnfsPlugin.workerd.mjs.map +7 -0
  10. package/dist/lib/neutral/backend-4HPTHS33.mjs +47 -0
  11. package/dist/lib/neutral/backend-4HPTHS33.mjs.map +7 -0
  12. package/dist/lib/{browser/blockstore-PSYZCC2O.mjs → neutral/blockstore-U6SPNL2C.mjs} +12 -13
  13. package/dist/lib/neutral/blockstore-U6SPNL2C.mjs.map +7 -0
  14. package/dist/lib/neutral/capabilities/index.mjs +13 -0
  15. package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
  16. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  17. package/dist/lib/neutral/chunk-KUQHRT52.mjs +39 -0
  18. package/dist/lib/neutral/chunk-KUQHRT52.mjs.map +7 -0
  19. package/dist/lib/{browser/chunk-D6VTEQIE.mjs → neutral/chunk-L33MOD23.mjs} +85 -25
  20. package/dist/lib/neutral/chunk-L33MOD23.mjs.map +7 -0
  21. package/dist/lib/neutral/chunk-QODCKFTY.mjs +19 -0
  22. package/dist/lib/neutral/chunk-QODCKFTY.mjs.map +7 -0
  23. package/dist/lib/neutral/helpers/index.mjs +26 -0
  24. package/dist/lib/neutral/helpers/index.mjs.map +7 -0
  25. package/dist/lib/neutral/index.mjs +36 -0
  26. package/dist/lib/neutral/index.mjs.map +7 -0
  27. package/dist/lib/neutral/meta.json +1 -0
  28. package/dist/lib/neutral/meta.mjs +8 -0
  29. package/dist/lib/neutral/meta.mjs.map +7 -0
  30. package/dist/lib/neutral/plugin.mjs +12 -0
  31. package/dist/lib/neutral/plugin.mjs.map +7 -0
  32. package/dist/lib/neutral/translations.mjs +17 -0
  33. package/dist/lib/neutral/translations.mjs.map +7 -0
  34. package/dist/lib/neutral/types/index.mjs +8 -0
  35. package/dist/lib/neutral/types/index.mjs.map +7 -0
  36. package/dist/lib/neutral/url-resolver-BIRH7WHL.mjs +47 -0
  37. package/dist/lib/neutral/url-resolver-BIRH7WHL.mjs.map +7 -0
  38. package/dist/types/src/WnfsPlugin.d.ts +3 -1
  39. package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
  40. package/dist/types/src/WnfsPlugin.node.d.ts +4 -0
  41. package/dist/types/src/WnfsPlugin.node.d.ts.map +1 -0
  42. package/dist/types/src/WnfsPlugin.test.d.ts +2 -0
  43. package/dist/types/src/WnfsPlugin.test.d.ts.map +1 -0
  44. package/dist/types/src/WnfsPlugin.workerd.d.ts +4 -0
  45. package/dist/types/src/WnfsPlugin.workerd.d.ts.map +1 -0
  46. package/dist/types/src/annotations.d.ts +7 -0
  47. package/dist/types/src/annotations.d.ts.map +1 -0
  48. package/dist/types/src/blockstore.d.ts.map +1 -1
  49. package/dist/types/src/capabilities/backend.d.ts +7 -0
  50. package/dist/types/src/capabilities/backend.d.ts.map +1 -0
  51. package/dist/types/src/capabilities/blockstore.d.ts +3 -2
  52. package/dist/types/src/capabilities/blockstore.d.ts.map +1 -1
  53. package/dist/types/src/capabilities/index.d.ts +5 -6
  54. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  55. package/dist/types/src/capabilities/url-resolver.d.ts +7 -0
  56. package/dist/types/src/capabilities/url-resolver.d.ts.map +1 -0
  57. package/dist/types/src/helpers/common.d.ts.map +1 -1
  58. package/dist/types/src/helpers/load.d.ts +1 -1
  59. package/dist/types/src/helpers/load.d.ts.map +1 -1
  60. package/dist/types/src/helpers/upload.d.ts +1 -1
  61. package/dist/types/src/helpers/upload.d.ts.map +1 -1
  62. package/dist/types/src/helpers/wnfs-url.d.ts.map +1 -1
  63. package/dist/types/src/index.d.ts +3 -2
  64. package/dist/types/src/index.d.ts.map +1 -1
  65. package/dist/types/src/meta.d.ts +2 -3
  66. package/dist/types/src/meta.d.ts.map +1 -1
  67. package/dist/types/src/plugin.d.ts +3 -0
  68. package/dist/types/src/plugin.d.ts.map +1 -0
  69. package/dist/types/src/translations.d.ts +2 -12
  70. package/dist/types/src/translations.d.ts.map +1 -1
  71. package/dist/types/src/types/WnfsCapabilities.d.ts +11 -0
  72. package/dist/types/src/types/WnfsCapabilities.d.ts.map +1 -0
  73. package/dist/types/src/types/index.d.ts +1 -2
  74. package/dist/types/src/types/index.d.ts.map +1 -1
  75. package/dist/types/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +86 -51
  77. package/src/WnfsPlugin.node.ts +11 -0
  78. package/src/WnfsPlugin.test.ts +20 -0
  79. package/src/WnfsPlugin.tsx +42 -84
  80. package/src/WnfsPlugin.workerd.ts +11 -0
  81. package/src/annotations.ts +16 -0
  82. package/src/blockstore.ts +1 -1
  83. package/src/capabilities/backend.ts +43 -0
  84. package/src/capabilities/blockstore.ts +14 -10
  85. package/src/capabilities/index.ts +12 -7
  86. package/src/capabilities/url-resolver.ts +44 -0
  87. package/src/helpers/load.ts +37 -18
  88. package/src/helpers/upload.ts +14 -2
  89. package/src/index.ts +3 -2
  90. package/src/meta.ts +26 -7
  91. package/src/plugin.ts +9 -0
  92. package/src/translations.ts +2 -11
  93. package/src/types/WnfsCapabilities.ts +18 -0
  94. package/src/types/index.ts +1 -2
  95. package/src/vite-env.d.ts +10 -0
  96. package/dist/lib/browser/FileContainer-LTKYOYSO.mjs +0 -105
  97. package/dist/lib/browser/FileContainer-LTKYOYSO.mjs.map +0 -7
  98. package/dist/lib/browser/blockstore-PSYZCC2O.mjs.map +0 -7
  99. package/dist/lib/browser/chunk-CW4BENRQ.mjs +0 -64
  100. package/dist/lib/browser/chunk-CW4BENRQ.mjs.map +0 -7
  101. package/dist/lib/browser/chunk-D6VTEQIE.mjs.map +0 -7
  102. package/dist/lib/browser/chunk-KZANQHJY.mjs +0 -16
  103. package/dist/lib/browser/chunk-KZANQHJY.mjs.map +0 -7
  104. package/dist/lib/browser/chunk-VDDGZWAY.mjs +0 -15
  105. package/dist/lib/browser/chunk-VDDGZWAY.mjs.map +0 -7
  106. package/dist/lib/browser/chunk-ZMH2OULB.mjs +0 -16
  107. package/dist/lib/browser/chunk-ZMH2OULB.mjs.map +0 -7
  108. package/dist/lib/browser/file-uploader-YRZPRETS.mjs +0 -29
  109. package/dist/lib/browser/file-uploader-YRZPRETS.mjs.map +0 -7
  110. package/dist/lib/browser/index.mjs +0 -118
  111. package/dist/lib/browser/index.mjs.map +0 -7
  112. package/dist/lib/browser/intent-resolver-CKGJNE6P.mjs +0 -49
  113. package/dist/lib/browser/intent-resolver-CKGJNE6P.mjs.map +0 -7
  114. package/dist/lib/browser/markdown-RAGCVYGE.mjs +0 -198
  115. package/dist/lib/browser/markdown-RAGCVYGE.mjs.map +0 -7
  116. package/dist/lib/browser/meta.json +0 -1
  117. package/dist/lib/browser/react-surface-HGWZDLP2.mjs +0 -88
  118. package/dist/lib/browser/react-surface-HGWZDLP2.mjs.map +0 -7
  119. package/dist/lib/browser/types/index.mjs +0 -10
  120. package/dist/types/src/capabilities/capabilities.d.ts +0 -12
  121. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  122. package/dist/types/src/capabilities/file-uploader.d.ts +0 -4
  123. package/dist/types/src/capabilities/file-uploader.d.ts.map +0 -1
  124. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  125. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  126. package/dist/types/src/capabilities/markdown.d.ts +0 -4
  127. package/dist/types/src/capabilities/markdown.d.ts.map +0 -1
  128. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  129. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  130. package/dist/types/src/components/FileContainer.d.ts +0 -9
  131. package/dist/types/src/components/FileContainer.d.ts.map +0 -1
  132. package/dist/types/src/components/FileInput.d.ts +0 -8
  133. package/dist/types/src/components/FileInput.d.ts.map +0 -1
  134. package/dist/types/src/components/FilePreview.d.ts +0 -11
  135. package/dist/types/src/components/FilePreview.d.ts.map +0 -1
  136. package/dist/types/src/components/index.d.ts +0 -3
  137. package/dist/types/src/components/index.d.ts.map +0 -1
  138. package/dist/types/src/extensions/image.d.ts +0 -14
  139. package/dist/types/src/extensions/image.d.ts.map +0 -1
  140. package/dist/types/src/extensions/image.stories.d.ts +0 -10
  141. package/dist/types/src/extensions/image.stories.d.ts.map +0 -1
  142. package/dist/types/src/extensions/index.d.ts +0 -2
  143. package/dist/types/src/extensions/index.d.ts.map +0 -1
  144. package/dist/types/src/types/file.d.ts +0 -16
  145. package/dist/types/src/types/file.d.ts.map +0 -1
  146. package/dist/types/src/types/types.d.ts +0 -51
  147. package/dist/types/src/types/types.d.ts.map +0 -1
  148. package/src/capabilities/capabilities.ts +0 -18
  149. package/src/capabilities/file-uploader.ts +0 -24
  150. package/src/capabilities/intent-resolver.ts +0 -33
  151. package/src/capabilities/markdown.ts +0 -26
  152. package/src/capabilities/react-surface.tsx +0 -45
  153. package/src/components/FileContainer.tsx +0 -52
  154. package/src/components/FileInput.tsx +0 -47
  155. package/src/components/FilePreview.tsx +0 -23
  156. package/src/components/index.ts +0 -9
  157. package/src/extensions/image.stories.tsx +0 -101
  158. package/src/extensions/image.tsx +0 -203
  159. package/src/extensions/index.ts +0 -5
  160. package/src/types/file.ts +0 -17
  161. package/src/types/types.ts +0 -41
  162. /package/dist/lib/{browser/types/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
@@ -1,203 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { syntaxTree } from '@codemirror/language';
6
- import { type EditorState, type Extension, type Range, StateField } from '@codemirror/state';
7
- import { Decoration, EditorView, WidgetType } from '@codemirror/view';
8
- import type { Blockstore } from 'interface-blockstore';
9
- import React from 'react';
10
- import { createRoot } from 'react-dom/client';
11
-
12
- import { type Space } from '@dxos/react-client/echo';
13
- import { Status, ThemeProvider } from '@dxos/react-ui';
14
- import { focusField } from '@dxos/react-ui-editor';
15
- import { defaultTx } from '@dxos/react-ui-theme';
16
- import { type MaybePromise } from '@dxos/util';
17
-
18
- import { type WnfsCapabilities } from '../capabilities';
19
- import { getBlobUrl, getPathFromUrl, loadWnfs } from '../helpers';
20
-
21
- const WAIT_UNTIL_LOADER = 1500;
22
-
23
- export type ImageOptions = {
24
- blockstore: Blockstore;
25
- instances: WnfsCapabilities.Instances;
26
- space: Space;
27
- };
28
-
29
- /**
30
- * Create WNFS image decorations.
31
- */
32
- export const image = (options: ImageOptions): Extension[] => {
33
- const blobUrlCache: Record<string, string> = {};
34
- const preloaded = new Set<string>();
35
-
36
- const preload = (url: string) => {
37
- if (!preloaded.has(url)) {
38
- const img = document.createElement('img');
39
- img.src = url;
40
- preloaded.add(url);
41
- }
42
- };
43
-
44
- return [
45
- StateField.define({
46
- create: (state) => {
47
- return Decoration.set(
48
- buildDecorations({ from: 0, to: state.doc.length, state, blobUrlCache, preload, options }),
49
- );
50
- },
51
- update: (value, tr) => {
52
- if (!tr.docChanged && !tr.selection) {
53
- return value;
54
- }
55
-
56
- // Find range of changes and cursor changes.
57
- const cursor = tr.state.selection.main.head;
58
- const oldCursor = tr.changes.mapPos(tr.startState.selection.main.head);
59
- let from = Math.min(cursor, oldCursor);
60
- let to = Math.max(cursor, oldCursor);
61
- tr.changes.iterChangedRanges((fromA, toA, fromB, toB) => {
62
- from = Math.min(from, fromB);
63
- to = Math.max(to, toB);
64
- });
65
-
66
- // Expand to cover lines.
67
- from = tr.state.doc.lineAt(from).from;
68
- to = tr.state.doc.lineAt(to).to;
69
-
70
- return value.map(tr.changes).update({
71
- filterFrom: from,
72
- filterTo: to,
73
- filter: () => false,
74
- add: buildDecorations({ from, to, state: tr.state, blobUrlCache, preload, options }),
75
- });
76
- },
77
- provide: (field) => EditorView.decorations.from(field),
78
- }),
79
- ];
80
- };
81
-
82
- const buildDecorations = ({
83
- from,
84
- to,
85
- state,
86
- blobUrlCache,
87
- preload,
88
- options: { blockstore, instances, space },
89
- }: {
90
- from: number;
91
- to: number;
92
- state: EditorState;
93
- blobUrlCache: Record<string, string>;
94
- preload: (url: string) => void;
95
- options: ImageOptions;
96
- }) => {
97
- const decorations: Range<Decoration>[] = [];
98
- const cursor = state.selection.main.head;
99
- syntaxTree(state).iterate({
100
- enter: (node) => {
101
- if (node.name !== 'Image') {
102
- return;
103
- }
104
-
105
- const urlNode = node.node.getChild('URL');
106
- if (!urlNode) {
107
- return;
108
- }
109
-
110
- const hide = state.readOnly || cursor < node.from || cursor > node.to;
111
- const wnfsUrl = state.sliceDoc(urlNode.from, urlNode.to);
112
- if (!wnfsUrl.startsWith('wnfs://')) {
113
- return;
114
- }
115
-
116
- const path = getPathFromUrl(wnfsUrl);
117
-
118
- // Cannot load images from other spaces
119
- const spaceId = path[1];
120
- if (spaceId !== space.id) {
121
- return;
122
- }
123
-
124
- // Load image contents into memory blob
125
- const blobUrlPromise = (async () => {
126
- const { directory, forest } = await loadWnfs({ blockstore, instances, space });
127
- const url = await getBlobUrl({ wnfsUrl, blockstore, directory, forest });
128
- blobUrlCache[path.join('/')] = url;
129
- preload(url);
130
- return url;
131
- })();
132
-
133
- decorations.push(
134
- Decoration.replace({
135
- block: true, // Prevent cursor from entering.
136
- widget: new WnfsImageWidget(wnfsUrl, blobUrlCache[path.join('/')] ?? blobUrlPromise),
137
- }).range(hide ? node.from : node.to, node.to),
138
- );
139
- },
140
- from,
141
- to,
142
- });
143
-
144
- return decorations;
145
- };
146
-
147
- const createImg = (view: EditorView, url: string) => {
148
- const img = document.createElement('img');
149
- img.setAttribute('src', url);
150
- img.setAttribute('class', 'cm-image-with-loader');
151
- // If focused, hide image until successfully loaded to avoid flickering effects.
152
- if (view.state.field(focusField)) {
153
- img.onload = () => img.classList.add('cm-loaded-image');
154
- } else {
155
- img.classList.add('cm-loaded-image');
156
- }
157
- return img;
158
- };
159
-
160
- class WnfsImageWidget extends WidgetType {
161
- constructor(
162
- readonly _wnfsUrl: string,
163
- readonly _url: MaybePromise<string>,
164
- ) {
165
- super();
166
- }
167
-
168
- override eq(other: this): boolean {
169
- return this._wnfsUrl === (other as any as WnfsImageWidget)._wnfsUrl;
170
- }
171
-
172
- override toDOM(view: EditorView): HTMLDivElement {
173
- if (typeof this._url === 'string') {
174
- return createImg(view, this._url);
175
- }
176
-
177
- const widget = document.createElement('div');
178
- widget.className = 'cm-image-wrapper';
179
- const loader = document.createElement('div');
180
- loader.className = 'mx-auto transition-opacity';
181
- let loaderAdded = false;
182
-
183
- const timeout = setTimeout(() => {
184
- const root = createRoot(loader);
185
- root.render(
186
- <ThemeProvider tx={defaultTx}>
187
- <Status indeterminate />
188
- </ThemeProvider>,
189
- );
190
- widget.appendChild(loader);
191
- loaderAdded = true;
192
- }, WAIT_UNTIL_LOADER);
193
-
194
- void this._url.then((url) => {
195
- clearTimeout(timeout);
196
- const img = createImg(view, url);
197
- loaderAdded && widget.removeChild(loader);
198
- widget.appendChild(img);
199
- });
200
-
201
- return widget;
202
- }
203
- }
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- export * from './image';
package/src/types/file.ts DELETED
@@ -1,17 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
-
7
- import { TypedObject } from '@dxos/echo-schema';
8
-
9
- export class FileType extends TypedObject({
10
- typename: 'dxos.org/type/File',
11
- version: '0.1.0',
12
- })({
13
- name: Schema.optional(Schema.String),
14
- type: Schema.String,
15
- cid: Schema.String,
16
- timestamp: Schema.optional(Schema.String),
17
- }) {}
@@ -1,41 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
-
7
- import { FileInfoSchema } from '@dxos/app-framework';
8
- import { SpaceSchema } from '@dxos/react-client/echo';
9
-
10
- import { WNFS_PLUGIN } from '../meta';
11
-
12
- import { FileType } from './file';
13
-
14
- export namespace WnfsAction {
15
- export class Create extends Schema.TaggedClass<Create>()(`${WNFS_PLUGIN}/action/create`, {
16
- input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
17
- output: Schema.Struct({
18
- object: FileType,
19
- }),
20
- }) {}
21
-
22
- export const UploadAnnotationId = Symbol.for(`${WNFS_PLUGIN}/annotation/upload`);
23
-
24
- export const UploadFileSchema = Schema.Struct({
25
- file: Schema.instanceOf(File).annotations({
26
- [UploadAnnotationId]: {
27
- // Accept file types.
28
- 'image/*': ['.jpg', '.jpeg', '.png', '.gif'],
29
- 'application/pdf': ['.pdf'],
30
- // TODO(wittjosiah): Add more file types.
31
- },
32
- }),
33
- });
34
-
35
- export type UploadFileForm = Schema.Schema.Type<typeof UploadFileSchema>;
36
-
37
- export class Upload extends Schema.TaggedClass<Upload>()(`${WNFS_PLUGIN}/action/upload`, {
38
- input: Schema.extend(UploadFileSchema, Schema.Struct({ space: SpaceSchema })),
39
- output: Schema.required(FileInfoSchema),
40
- }) {}
41
- }