@dxos/plugin-wnfs 0.8.4-main.e8ec1fe → 0.8.4-main.effb148878
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/LICENSE +102 -5
- package/README.md +2 -2
- package/dist/lib/neutral/WnfsPlugin.mjs +39 -0
- package/dist/lib/neutral/WnfsPlugin.mjs.map +7 -0
- package/dist/lib/neutral/WnfsPlugin.node.mjs +12 -0
- package/dist/lib/neutral/WnfsPlugin.node.mjs.map +7 -0
- package/dist/lib/neutral/WnfsPlugin.workerd.mjs +12 -0
- package/dist/lib/neutral/WnfsPlugin.workerd.mjs.map +7 -0
- package/dist/lib/neutral/backend-DHBQUTPC.mjs +47 -0
- package/dist/lib/neutral/backend-DHBQUTPC.mjs.map +7 -0
- package/dist/lib/{browser/blockstore-2JFU4NBU.mjs → neutral/blockstore-3NLSWC7Z.mjs} +12 -13
- package/dist/lib/neutral/blockstore-3NLSWC7Z.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +13 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/{browser/chunk-D6VTEQIE.mjs → neutral/chunk-7KFJ6LYH.mjs} +43 -18
- package/dist/lib/neutral/chunk-7KFJ6LYH.mjs.map +7 -0
- package/dist/lib/neutral/chunk-IY6VOJSQ.mjs +37 -0
- package/dist/lib/neutral/chunk-IY6VOJSQ.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-QODCKFTY.mjs +19 -0
- package/dist/lib/neutral/chunk-QODCKFTY.mjs.map +7 -0
- package/dist/lib/neutral/helpers/index.mjs +26 -0
- package/dist/lib/neutral/helpers/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +34 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +8 -0
- package/dist/lib/neutral/meta.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +12 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +17 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +8 -0
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/lib/neutral/url-resolver-UD3ZP77Y.mjs +47 -0
- package/dist/lib/neutral/url-resolver-UD3ZP77Y.mjs.map +7 -0
- package/dist/types/src/WnfsPlugin.d.ts +3 -1
- package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
- package/dist/types/src/WnfsPlugin.node.d.ts +4 -0
- package/dist/types/src/WnfsPlugin.node.d.ts.map +1 -0
- package/dist/types/src/WnfsPlugin.test.d.ts +2 -0
- package/dist/types/src/WnfsPlugin.test.d.ts.map +1 -0
- package/dist/types/src/WnfsPlugin.workerd.d.ts +4 -0
- package/dist/types/src/WnfsPlugin.workerd.d.ts.map +1 -0
- package/dist/types/src/blockstore.d.ts.map +1 -1
- package/dist/types/src/capabilities/backend.d.ts +7 -0
- package/dist/types/src/capabilities/backend.d.ts.map +1 -0
- 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/index.d.ts +5 -6
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/url-resolver.d.ts +7 -0
- package/dist/types/src/capabilities/url-resolver.d.ts.map +1 -0
- package/dist/types/src/helpers/common.d.ts.map +1 -1
- package/dist/types/src/helpers/load.d.ts +1 -1
- package/dist/types/src/helpers/load.d.ts.map +1 -1
- package/dist/types/src/helpers/upload.d.ts +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 +2 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/plugin.d.ts +3 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +2 -12
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/WnfsCapabilities.d.ts +11 -0
- package/dist/types/src/types/WnfsCapabilities.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -2
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +95 -48
- package/src/WnfsPlugin.node.ts +11 -0
- package/src/WnfsPlugin.test.ts +20 -0
- package/src/WnfsPlugin.tsx +27 -77
- package/src/WnfsPlugin.workerd.ts +11 -0
- package/src/blockstore.ts +1 -1
- package/src/capabilities/backend.ts +43 -0
- package/src/capabilities/blockstore.ts +14 -10
- package/src/capabilities/index.ts +12 -7
- package/src/capabilities/url-resolver.ts +44 -0
- package/src/helpers/load.ts +12 -7
- package/src/helpers/upload.ts +5 -2
- package/src/index.ts +2 -2
- package/src/meta.ts +20 -5
- package/src/plugin.ts +9 -0
- package/src/translations.ts +2 -11
- package/src/types/WnfsCapabilities.ts +18 -0
- package/src/types/index.ts +1 -2
- package/dist/lib/browser/FileContainer-LLNI7WXR.mjs +0 -103
- package/dist/lib/browser/FileContainer-LLNI7WXR.mjs.map +0 -7
- package/dist/lib/browser/blockstore-2JFU4NBU.mjs.map +0 -7
- package/dist/lib/browser/chunk-CWMKN2F6.mjs +0 -71
- package/dist/lib/browser/chunk-CWMKN2F6.mjs.map +0 -7
- package/dist/lib/browser/chunk-D6VTEQIE.mjs.map +0 -7
- package/dist/lib/browser/chunk-F4QHZWQD.mjs +0 -16
- package/dist/lib/browser/chunk-F4QHZWQD.mjs.map +0 -7
- package/dist/lib/browser/chunk-OGPGLJCV.mjs +0 -25
- package/dist/lib/browser/chunk-OGPGLJCV.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZFPJA5F4.mjs +0 -16
- package/dist/lib/browser/chunk-ZFPJA5F4.mjs.map +0 -7
- package/dist/lib/browser/file-uploader-W6TJLAAK.mjs +0 -30
- package/dist/lib/browser/file-uploader-W6TJLAAK.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -116
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs +0 -48
- package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs.map +0 -7
- package/dist/lib/browser/markdown-WYQDCVFQ.mjs +0 -198
- package/dist/lib/browser/markdown-WYQDCVFQ.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/react-surface-DMU47U3X.mjs +0 -88
- package/dist/lib/browser/react-surface-DMU47U3X.mjs.map +0 -7
- package/dist/lib/browser/types/index.mjs +0 -10
- package/dist/types/src/capabilities/capabilities.d.ts +0 -12
- package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
- package/dist/types/src/capabilities/file-uploader.d.ts +0 -4
- package/dist/types/src/capabilities/file-uploader.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/capabilities/markdown.d.ts +0 -4
- package/dist/types/src/capabilities/markdown.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.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 +0 -8
- 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/components/index.d.ts +0 -3
- package/dist/types/src/components/index.d.ts.map +0 -1
- package/dist/types/src/extensions/image.d.ts +0 -14
- package/dist/types/src/extensions/image.d.ts.map +0 -1
- package/dist/types/src/extensions/image.stories.d.ts +0 -11
- package/dist/types/src/extensions/image.stories.d.ts.map +0 -1
- package/dist/types/src/extensions/index.d.ts +0 -2
- package/dist/types/src/extensions/index.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/dist/types/src/types/types.d.ts +0 -55
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/src/capabilities/capabilities.ts +0 -18
- package/src/capabilities/file-uploader.ts +0 -27
- package/src/capabilities/intent-resolver.ts +0 -32
- package/src/capabilities/markdown.ts +0 -26
- package/src/capabilities/react-surface.tsx +0 -45
- package/src/components/FileContainer.tsx +0 -59
- package/src/components/FileInput.tsx +0 -47
- package/src/components/FilePreview.tsx +0 -23
- package/src/components/index.ts +0 -9
- package/src/extensions/image.stories.tsx +0 -104
- package/src/extensions/image.tsx +0 -203
- package/src/extensions/index.ts +0 -5
- package/src/types/File.ts +0 -24
- package/src/types/types.ts +0 -41
- /package/dist/lib/{browser/types/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type Extension } from '@codemirror/state';
|
|
2
|
-
import type { Blockstore } from 'interface-blockstore';
|
|
3
|
-
import { type Space } from '@dxos/react-client/echo';
|
|
4
|
-
import { type WnfsCapabilities } from '../capabilities';
|
|
5
|
-
export type ImageOptions = {
|
|
6
|
-
blockstore: Blockstore;
|
|
7
|
-
instances: WnfsCapabilities.Instances;
|
|
8
|
-
space: Space;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Create WNFS image decorations.
|
|
12
|
-
*/
|
|
13
|
-
export declare const image: (options: ImageOptions) => Extension[];
|
|
14
|
-
//# sourceMappingURL=image.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../../src/extensions/image.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAoB,KAAK,SAAS,EAA0B,MAAM,mBAAmB,CAAC;AAE7F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvD,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAMrD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKxD,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,gBAAgB,CAAC,SAAS,CAAC;IACtC,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,KAAK,GAAI,SAAS,YAAY,KAAG,SAAS,EAgDtD,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type StoryObj } from '@storybook/react-vite';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
declare const meta: {
|
|
4
|
-
title: string;
|
|
5
|
-
render: () => React.JSX.Element;
|
|
6
|
-
decorators: import("@storybook/react").Decorator[];
|
|
7
|
-
};
|
|
8
|
-
export default meta;
|
|
9
|
-
type Story = StoryObj<typeof meta>;
|
|
10
|
-
export declare const Default: Story;
|
|
11
|
-
//# sourceMappingURL=image.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"image.stories.d.ts","sourceRoot":"","sources":["../../../../src/extensions/image.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,KAAgD,MAAM,OAAO,CAAC;AAuFrE,QAAA,MAAM,IAAI;;;;CAI2B,CAAC;AAEtC,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/extensions/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as Schema from 'effect/Schema';
|
|
2
|
-
import { Obj, Type } from '@dxos/echo';
|
|
3
|
-
export declare const File: Type.obj<Schema.Struct<{
|
|
4
|
-
name: Schema.optional<typeof Schema.String>;
|
|
5
|
-
type: typeof Schema.String;
|
|
6
|
-
cid: typeof Schema.String;
|
|
7
|
-
timestamp: Schema.optional<typeof Schema.String>;
|
|
8
|
-
}>>;
|
|
9
|
-
export type File = Schema.Schema.Type<typeof File>;
|
|
10
|
-
export declare const make: (props: Obj.MakeProps<typeof File>) => import("@dxos/live-object").Live<Type.OfKind<import("@dxos/echo/internal").EntityKind.Object> & {
|
|
11
|
-
name?: string | undefined;
|
|
12
|
-
type: string;
|
|
13
|
-
cid: string;
|
|
14
|
-
timestamp?: string | undefined;
|
|
15
|
-
}>;
|
|
16
|
-
//# sourceMappingURL=File.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../../../src/types/File.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGvC,eAAO,MAAM,IAAI;;;;;GAUhB,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnD,eAAO,MAAM,IAAI,GAAI,OAAO,GAAG,CAAC,SAAS,CAAC,OAAO,IAAI,CAAC;;;;;EAA0B,CAAC"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import * as Schema from 'effect/Schema';
|
|
2
|
-
export declare namespace WnfsAction {
|
|
3
|
-
const Create_base: Schema.TaggedClass<Create, `${string}/action/create`, {
|
|
4
|
-
readonly _tag: Schema.tag<`${string}/action/create`>;
|
|
5
|
-
} & {
|
|
6
|
-
input: Schema.SchemaClass<{
|
|
7
|
-
readonly name: string;
|
|
8
|
-
readonly type: string;
|
|
9
|
-
readonly cid: string;
|
|
10
|
-
}, {
|
|
11
|
-
readonly name: string;
|
|
12
|
-
readonly type: string;
|
|
13
|
-
readonly cid: string;
|
|
14
|
-
}, never>;
|
|
15
|
-
output: Schema.Struct<{
|
|
16
|
-
object: import("@dxos/echo/Type").obj<Schema.Struct<{
|
|
17
|
-
name: Schema.optional<typeof Schema.String>;
|
|
18
|
-
type: typeof Schema.String;
|
|
19
|
-
cid: typeof Schema.String;
|
|
20
|
-
timestamp: Schema.optional<typeof Schema.String>;
|
|
21
|
-
}>>;
|
|
22
|
-
}>;
|
|
23
|
-
}>;
|
|
24
|
-
export class Create extends Create_base {
|
|
25
|
-
}
|
|
26
|
-
export const UploadAnnotationId: unique symbol;
|
|
27
|
-
export const UploadFileSchema: Schema.Struct<{
|
|
28
|
-
file: Schema.instanceOf<any>;
|
|
29
|
-
}>;
|
|
30
|
-
export type UploadFileForm = Schema.Schema.Type<typeof UploadFileSchema>;
|
|
31
|
-
const Upload_base: Schema.TaggedClass<Upload, `${string}/action/upload`, {
|
|
32
|
-
readonly _tag: Schema.tag<`${string}/action/upload`>;
|
|
33
|
-
} & {
|
|
34
|
-
input: Schema.extend<Schema.Struct<{
|
|
35
|
-
file: Schema.instanceOf<any>;
|
|
36
|
-
}>, Schema.Struct<{
|
|
37
|
-
space: Schema.Schema<import("@dxos/client-protocol").Space, import("@dxos/client-protocol").Space, never>;
|
|
38
|
-
}>>;
|
|
39
|
-
output: Schema.SchemaClass<{
|
|
40
|
-
readonly name: string;
|
|
41
|
-
readonly type: string;
|
|
42
|
-
readonly cid: string;
|
|
43
|
-
readonly url: string;
|
|
44
|
-
}, {
|
|
45
|
-
readonly name: string;
|
|
46
|
-
readonly type: string;
|
|
47
|
-
readonly cid: string;
|
|
48
|
-
readonly url: string;
|
|
49
|
-
}, never>;
|
|
50
|
-
}>;
|
|
51
|
-
export class Upload extends Upload_base {
|
|
52
|
-
}
|
|
53
|
-
export {};
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AASxC,yBAAiB,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;IAC1B,MAAM,OAAO,MAAO,SAAQ,WAK1B;KAAG;IAEL,MAAM,CAAC,MAAM,kBAAkB,eAA6C,CAAC;IAE7E,MAAM,CAAC,MAAM,gBAAgB;;MAS3B,CAAC;IAEH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,gBAAgB,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;IAEzE,MAAM,OAAO,MAAO,SAAQ,WAG1B;KAAG;;CACN"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Blockstore } from 'interface-blockstore';
|
|
6
|
-
import { type PrivateDirectory, type PrivateForest } from 'wnfs';
|
|
7
|
-
|
|
8
|
-
import { defineCapability } from '@dxos/app-framework';
|
|
9
|
-
import { type SpaceId } from '@dxos/keys';
|
|
10
|
-
|
|
11
|
-
import { meta } from '../meta';
|
|
12
|
-
|
|
13
|
-
export namespace WnfsCapabilities {
|
|
14
|
-
export const Blockstore = defineCapability<Blockstore>(`${meta.id}/capability/blockstore`);
|
|
15
|
-
|
|
16
|
-
export type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;
|
|
17
|
-
export const Instances = defineCapability<Instances>(`${meta.id}/capability/instances`);
|
|
18
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Effect from 'effect/Effect';
|
|
6
|
-
import * as Function from 'effect/Function';
|
|
7
|
-
|
|
8
|
-
import { Capabilities, type PluginContext, chain, contributes, createIntent } from '@dxos/app-framework';
|
|
9
|
-
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
10
|
-
|
|
11
|
-
import { WnfsAction } from '../types';
|
|
12
|
-
|
|
13
|
-
export default (context: PluginContext) => {
|
|
14
|
-
return contributes(Capabilities.FileUploader, (space, file) => {
|
|
15
|
-
const { dispatch } = context.getCapability(Capabilities.IntentDispatcher);
|
|
16
|
-
const program = Effect.gen(function* () {
|
|
17
|
-
const fileInfo = yield* dispatch(createIntent(WnfsAction.Upload, { space, file }));
|
|
18
|
-
yield* dispatch(
|
|
19
|
-
Function.pipe(createIntent(WnfsAction.Create, fileInfo), chain(SpaceAction.AddObject, { target: space })),
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
return fileInfo;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return Effect.runPromise(program);
|
|
26
|
-
});
|
|
27
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Capabilities, type PluginContext, contributes, createResolver } from '@dxos/app-framework';
|
|
6
|
-
|
|
7
|
-
import { upload } from '../helpers';
|
|
8
|
-
import { WnfsAction, WnfsFile } from '../types';
|
|
9
|
-
|
|
10
|
-
import { WnfsCapabilities } from './capabilities';
|
|
11
|
-
|
|
12
|
-
export default (context: PluginContext) =>
|
|
13
|
-
contributes(Capabilities.IntentResolver, [
|
|
14
|
-
// TODO(wittjosiah): Deleting the object doesn't delete the wnfs blob.
|
|
15
|
-
// Consider ways to trigger blob deletion based on object deletion and/or adding file system manager.
|
|
16
|
-
createResolver({
|
|
17
|
-
intent: WnfsAction.Create,
|
|
18
|
-
resolve: ({ name, type, cid }) => ({
|
|
19
|
-
data: {
|
|
20
|
-
object: WnfsFile.make({ name, type, cid }),
|
|
21
|
-
},
|
|
22
|
-
}),
|
|
23
|
-
}),
|
|
24
|
-
createResolver({
|
|
25
|
-
intent: WnfsAction.Upload,
|
|
26
|
-
resolve: async ({ file, space }) => {
|
|
27
|
-
const blockstore = context.getCapability(WnfsCapabilities.Blockstore);
|
|
28
|
-
const info = await upload({ file, blockstore, space });
|
|
29
|
-
return { data: info };
|
|
30
|
-
},
|
|
31
|
-
}),
|
|
32
|
-
]);
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type PluginContext, contributes } from '@dxos/app-framework';
|
|
6
|
-
import { MarkdownCapabilities } from '@dxos/plugin-markdown';
|
|
7
|
-
import { getSpace } from '@dxos/react-client/echo';
|
|
8
|
-
|
|
9
|
-
import { image } from '../extensions';
|
|
10
|
-
|
|
11
|
-
import { WnfsCapabilities } from './capabilities';
|
|
12
|
-
|
|
13
|
-
export default (context: PluginContext) =>
|
|
14
|
-
contributes(MarkdownCapabilities.Extensions, [
|
|
15
|
-
({ document }) => {
|
|
16
|
-
const blockstore = context.getCapability(WnfsCapabilities.Blockstore);
|
|
17
|
-
const instances = context.getCapability(WnfsCapabilities.Instances);
|
|
18
|
-
|
|
19
|
-
if (document) {
|
|
20
|
-
const space = getSpace(document);
|
|
21
|
-
return space ? [image({ blockstore, instances, space })] : [];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return [];
|
|
25
|
-
},
|
|
26
|
-
]);
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type * as Schema from 'effect/Schema';
|
|
6
|
-
import React, { useCallback } from 'react';
|
|
7
|
-
|
|
8
|
-
import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
|
|
9
|
-
import { Obj } from '@dxos/echo';
|
|
10
|
-
import { findAnnotation } from '@dxos/effect';
|
|
11
|
-
import { type InputProps } from '@dxos/react-ui-form';
|
|
12
|
-
|
|
13
|
-
import { FileContainer, FileInput } from '../components';
|
|
14
|
-
import { meta } from '../meta';
|
|
15
|
-
import { WnfsAction, WnfsFile } from '../types';
|
|
16
|
-
|
|
17
|
-
export default () =>
|
|
18
|
-
contributes(Capabilities.ReactSurface, [
|
|
19
|
-
createSurface({
|
|
20
|
-
id: `${meta.id}/article`,
|
|
21
|
-
role: ['article', 'section', 'slide'],
|
|
22
|
-
filter: (data): data is { subject: WnfsFile.File } => Obj.instanceOf(WnfsFile.File, data.subject),
|
|
23
|
-
component: ({ data, role }) => <FileContainer role={role} file={data.subject} />,
|
|
24
|
-
}),
|
|
25
|
-
createSurface({
|
|
26
|
-
id: `${meta.id}/create-form`,
|
|
27
|
-
role: 'form-input',
|
|
28
|
-
filter: (data): data is { prop: string; schema: Schema.Schema.Any } => {
|
|
29
|
-
const annotation = findAnnotation<boolean>(
|
|
30
|
-
(data.schema as Schema.Schema.All).ast,
|
|
31
|
-
WnfsAction.UploadAnnotationId,
|
|
32
|
-
);
|
|
33
|
-
return !!annotation;
|
|
34
|
-
},
|
|
35
|
-
component: ({ data: { prop, schema }, ...props }) => {
|
|
36
|
-
const inputProps = props as unknown as InputProps;
|
|
37
|
-
const handleChange = useCallback(
|
|
38
|
-
(file: File) => inputProps.onValueChange?.('object', file),
|
|
39
|
-
[prop, inputProps.onValueChange],
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
return <FileInput schema={schema} onChange={handleChange} />;
|
|
43
|
-
},
|
|
44
|
-
}),
|
|
45
|
-
]);
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { useCapability } from '@dxos/app-framework/react';
|
|
8
|
-
import { invariant } from '@dxos/invariant';
|
|
9
|
-
import { getSpace } from '@dxos/react-client/echo';
|
|
10
|
-
import { useAsyncEffect } from '@dxos/react-ui';
|
|
11
|
-
import { StackItem } from '@dxos/react-ui-stack';
|
|
12
|
-
|
|
13
|
-
import { WnfsCapabilities } from '../capabilities';
|
|
14
|
-
import { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../helpers';
|
|
15
|
-
import { type WnfsFile } from '../types';
|
|
16
|
-
|
|
17
|
-
import { FilePreview } from './FilePreview';
|
|
18
|
-
|
|
19
|
-
export type FileContainerProps = {
|
|
20
|
-
role: string;
|
|
21
|
-
file: WnfsFile.File;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const FileContainer = ({ file }: FileContainerProps) => {
|
|
25
|
-
const blockstore = useCapability(WnfsCapabilities.Blockstore);
|
|
26
|
-
const instances = useCapability(WnfsCapabilities.Instances);
|
|
27
|
-
const [blobUrl, setBlobUrl] = useState<string>();
|
|
28
|
-
|
|
29
|
-
useAsyncEffect(async () => {
|
|
30
|
-
const space = getSpace(file);
|
|
31
|
-
invariant(space);
|
|
32
|
-
const { directory, forest } = await loadWnfs({
|
|
33
|
-
blockstore,
|
|
34
|
-
instances,
|
|
35
|
-
space,
|
|
36
|
-
});
|
|
37
|
-
const path = filePath(file.cid.toString(), space);
|
|
38
|
-
const url = await getBlobUrl({
|
|
39
|
-
wnfsUrl: wnfsUrl(path),
|
|
40
|
-
blockstore,
|
|
41
|
-
directory,
|
|
42
|
-
forest,
|
|
43
|
-
type: file.type,
|
|
44
|
-
});
|
|
45
|
-
setBlobUrl(url);
|
|
46
|
-
}, [file]);
|
|
47
|
-
|
|
48
|
-
if (!blobUrl) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<StackItem.Content>
|
|
54
|
-
<FilePreview type={file.type} url={blobUrl} />
|
|
55
|
-
</StackItem.Content>
|
|
56
|
-
);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export default FileContainer;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type * as Schema from 'effect/Schema';
|
|
6
|
-
import React, { useCallback } from 'react';
|
|
7
|
-
import { useDropzone } from 'react-dropzone';
|
|
8
|
-
|
|
9
|
-
import { findAnnotation } from '@dxos/effect';
|
|
10
|
-
import { useTranslation } from '@dxos/react-ui';
|
|
11
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
12
|
-
|
|
13
|
-
import { meta } from '../meta';
|
|
14
|
-
import { WnfsAction } from '../types';
|
|
15
|
-
|
|
16
|
-
export type FileInputProps = {
|
|
17
|
-
schema: Schema.Schema.Any;
|
|
18
|
-
onChange: (file: File) => void;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const FileInput = ({ schema, onChange }: FileInputProps) => {
|
|
22
|
-
const { t } = useTranslation(meta.id);
|
|
23
|
-
const accept = findAnnotation<Record<string, string[]>>(schema.ast, WnfsAction.UploadAnnotationId);
|
|
24
|
-
|
|
25
|
-
const onDropAccepted = useCallback((files: File[]) => onChange?.(files[0]), [onChange]);
|
|
26
|
-
|
|
27
|
-
const { acceptedFiles, getRootProps, getInputProps, isFocused, isDragAccept, isDragReject } = useDropzone({
|
|
28
|
-
multiple: false,
|
|
29
|
-
accept,
|
|
30
|
-
onDropAccepted,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<div
|
|
35
|
-
{...getRootProps()}
|
|
36
|
-
className={mx(
|
|
37
|
-
'flex flex-col items-center p-8 border border-separator',
|
|
38
|
-
isFocused && 'focus-ring',
|
|
39
|
-
isDragAccept && 'bg-attention',
|
|
40
|
-
isDragReject && 'border-roseFill',
|
|
41
|
-
)}
|
|
42
|
-
>
|
|
43
|
-
<input {...getInputProps()} />
|
|
44
|
-
{acceptedFiles[0] ? <p>{acceptedFiles[0].name}</p> : <p>{t('file input placeholder')}</p>}
|
|
45
|
-
</div>
|
|
46
|
-
);
|
|
47
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React from 'react';
|
|
6
|
-
|
|
7
|
-
import { type ThemedClassName } from '@dxos/react-ui';
|
|
8
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
9
|
-
|
|
10
|
-
export type FilePreviewProps = ThemedClassName<{ type: string; url: string }>;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* File/content preview iframe.
|
|
14
|
-
*/
|
|
15
|
-
export const FilePreview = ({ type, url, classNames }: FilePreviewProps) => {
|
|
16
|
-
if (type.startsWith('image/')) {
|
|
17
|
-
return <img className={mx('is-full bs-full object-contain', classNames)} src={url} />;
|
|
18
|
-
} else if (type.startsWith('video/')) {
|
|
19
|
-
return <video className={mx('is-full bs-full object-contain', classNames)} src={url} controls />;
|
|
20
|
-
} else {
|
|
21
|
-
return <iframe className={mx('is-full bs-full overflow-auto', classNames)} src={url} />;
|
|
22
|
-
}
|
|
23
|
-
};
|
package/src/components/index.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import type { Blockstore } from 'interface-blockstore';
|
|
7
|
-
import React, { type ChangeEvent, useEffect, useState } from 'react';
|
|
8
|
-
|
|
9
|
-
import { faker } from '@dxos/random';
|
|
10
|
-
import { useSpace } from '@dxos/react-client/echo';
|
|
11
|
-
import { withClientProvider } from '@dxos/react-client/testing';
|
|
12
|
-
import { useThemeContext } from '@dxos/react-ui';
|
|
13
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
|
-
import {
|
|
15
|
-
createBasicExtensions,
|
|
16
|
-
createMarkdownExtensions,
|
|
17
|
-
createThemeExtensions,
|
|
18
|
-
decorateMarkdown,
|
|
19
|
-
processEditorPayload,
|
|
20
|
-
useTextEditor,
|
|
21
|
-
} from '@dxos/react-ui-editor';
|
|
22
|
-
|
|
23
|
-
import { create as createBlockstore } from '../blockstore';
|
|
24
|
-
import { upload } from '../helpers';
|
|
25
|
-
|
|
26
|
-
import { image } from './image';
|
|
27
|
-
|
|
28
|
-
faker.seed(1);
|
|
29
|
-
const initialValue = faker.lorem.paragraphs(100);
|
|
30
|
-
const instances = {};
|
|
31
|
-
|
|
32
|
-
const DefaultStory = () => {
|
|
33
|
-
const { themeMode } = useThemeContext();
|
|
34
|
-
const space = useSpace();
|
|
35
|
-
const [blockstore, setBlockstore] = useState<Blockstore>();
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
if (space) {
|
|
39
|
-
console.log('SPACE ID', space.id);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const create = async () => {
|
|
43
|
-
// NOTE: We don't pass in the URL of the Blob service, so we don't use it.
|
|
44
|
-
const bs = createBlockstore();
|
|
45
|
-
await bs.open();
|
|
46
|
-
setBlockstore(bs);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
create().catch(console.error);
|
|
50
|
-
}, [space]);
|
|
51
|
-
|
|
52
|
-
const { parentRef, view, focusAttributes } = useTextEditor(
|
|
53
|
-
() => ({
|
|
54
|
-
initialValue,
|
|
55
|
-
extensions: [
|
|
56
|
-
createBasicExtensions(),
|
|
57
|
-
createMarkdownExtensions(),
|
|
58
|
-
createThemeExtensions({ themeMode, syntaxHighlighting: true }),
|
|
59
|
-
blockstore && space ? [image({ blockstore, instances, space })] : [],
|
|
60
|
-
decorateMarkdown(),
|
|
61
|
-
],
|
|
62
|
-
}),
|
|
63
|
-
[themeMode, blockstore, space],
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const onFileChange = async (event: ChangeEvent<HTMLInputElement>) => {
|
|
67
|
-
const file = event.target.files?.[0];
|
|
68
|
-
if (file) {
|
|
69
|
-
if (blockstore) {
|
|
70
|
-
if (space) {
|
|
71
|
-
const info = await upload({ blockstore, file, space });
|
|
72
|
-
if (info && view) {
|
|
73
|
-
processEditorPayload(view, { type: 'image', data: info.url });
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
console.warn('Space is undefined.');
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
console.warn("Blockstore hasn't been initialised yet.");
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<>
|
|
86
|
-
<div className='mb-2'>
|
|
87
|
-
<input type='file' accept='image/*' onChange={onFileChange} />
|
|
88
|
-
</div>
|
|
89
|
-
<div className='is-[50rem]' ref={parentRef} {...focusAttributes} />
|
|
90
|
-
</>
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const meta = {
|
|
95
|
-
title: 'plugins/plugin-wnfs/image',
|
|
96
|
-
render: DefaultStory,
|
|
97
|
-
decorators: [withTheme, withClientProvider({ createIdentity: true, createSpace: true })],
|
|
98
|
-
} satisfies Meta<typeof DefaultStory>;
|
|
99
|
-
|
|
100
|
-
export default meta;
|
|
101
|
-
|
|
102
|
-
type Story = StoryObj<typeof meta>;
|
|
103
|
-
|
|
104
|
-
export const Default: Story = {};
|