@dxos/app-framework 0.6.13-main.548ca8d → 0.6.13-staging.1e988a3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +163 -169
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +182 -183
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/App.d.ts +4 -4
- package/dist/types/src/App.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/PluginContext.d.ts +4 -4
- package/dist/types/src/plugins/PluginHost/PluginContext.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +8 -4
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts +83 -37
- package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.test.d.ts.map +1 -1
- package/dist/types/src/plugins/common/navigation.d.ts +12 -1
- package/dist/types/src/plugins/common/navigation.d.ts.map +1 -1
- package/package.json +11 -14
- package/project.json +8 -3
- package/src/App.tsx +9 -10
- package/src/plugins/PluginHost/PluginContext.tsx +14 -8
- package/src/plugins/PluginHost/PluginHost.tsx +121 -18
- package/src/plugins/PluginHost/plugin.test.ts +2 -1
- package/src/plugins/PluginHost/plugin.ts +52 -45
- package/src/plugins/common/navigation.ts +12 -4
- package/tsconfig.json +29 -1
- package/dist/lib/node-esm/chunk-ERPIGFBI.mjs +0 -28
- package/dist/lib/node-esm/chunk-ERPIGFBI.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-IY7HCP4K.mjs +0 -22
- package/dist/lib/node-esm/chunk-IY7HCP4K.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-P2TQLXZR.mjs +0 -54
- package/dist/lib/node-esm/chunk-P2TQLXZR.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -683
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/plugin-24ZP3LDU.mjs +0 -40
- package/dist/lib/node-esm/plugin-24ZP3LDU.mjs.map +0 -7
- package/dist/lib/node-esm/plugin-5AAUGDB3.mjs +0 -168
- package/dist/lib/node-esm/plugin-5AAUGDB3.mjs.map +0 -7
- package/dist/types/src/plugins/PluginHost/PluginContainer.d.ts +0 -14
- package/dist/types/src/plugins/PluginHost/PluginContainer.d.ts.map +0 -1
- package/src/plugins/PluginHost/PluginContainer.tsx +0 -120
- package/vitest.config.ts +0 -9
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import type { IconProps } from '@phosphor-icons/react';
|
|
5
6
|
import type { FC, PropsWithChildren } from 'react';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -20,56 +21,60 @@ export type PluginProvides<TProvides> = TProvides & {
|
|
|
20
21
|
root?: FC<PropsWithChildren>;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
export type PluginMeta = {
|
|
24
|
-
/**
|
|
25
|
-
* Globally unique ID.
|
|
26
|
-
*
|
|
27
|
-
* Expected to be in the form of a valid URL.
|
|
28
|
-
*
|
|
29
|
-
* @example dxos.org/plugin/example
|
|
30
|
-
*/
|
|
31
|
-
id: string;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Short ID for use in URLs.
|
|
35
|
-
*
|
|
36
|
-
* NOTE: This is especially experimental and likely to change.
|
|
37
|
-
*/
|
|
38
|
-
// TODO(wittjosiah): How should these be managed?
|
|
39
|
-
shortId?: string;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Human-readable name.
|
|
43
|
-
*/
|
|
44
|
-
name?: string;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Short description of plugin functionality.
|
|
48
|
-
*/
|
|
49
|
-
description?: string;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* URL of home page.
|
|
53
|
-
*/
|
|
54
|
-
homePage?: string;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Tags to help categorize the plugin.
|
|
58
|
-
*/
|
|
59
|
-
tags?: string[];
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* A grep-able symbol string which can be resolved to an icon asset by @ch-ui/icons, via @ch-ui/vite-plugin-icons.
|
|
63
|
-
*/
|
|
64
|
-
icon?: string;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
24
|
/**
|
|
68
25
|
* A unit of containment of modular functionality that can be provided to an application.
|
|
69
26
|
* Plugins provide things like components, state, actions, etc. to the application.
|
|
70
27
|
*/
|
|
71
28
|
export type Plugin<TProvides = {}> = {
|
|
72
|
-
meta:
|
|
29
|
+
meta: {
|
|
30
|
+
/**
|
|
31
|
+
* Globally unique ID.
|
|
32
|
+
*
|
|
33
|
+
* Expected to be in the form of a valid URL.
|
|
34
|
+
*
|
|
35
|
+
* @example dxos.org/plugin/example
|
|
36
|
+
*/
|
|
37
|
+
id: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Short ID for use in URLs.
|
|
41
|
+
*
|
|
42
|
+
* NOTE: This is especially experimental and likely to change.
|
|
43
|
+
*/
|
|
44
|
+
// TODO(wittjosiah): How should these be managed?
|
|
45
|
+
shortId?: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Human-readable name.
|
|
49
|
+
*/
|
|
50
|
+
name?: string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Short description of plugin functionality.
|
|
54
|
+
*/
|
|
55
|
+
description?: string;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* URL of home page.
|
|
59
|
+
*/
|
|
60
|
+
homePage?: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Tags to help categorize the plugin.
|
|
64
|
+
*/
|
|
65
|
+
tags?: string[];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Component to render icon for the plugin when displayed in a list.
|
|
69
|
+
* @deprecated
|
|
70
|
+
*/
|
|
71
|
+
iconComponent?: FC<IconProps>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A grep-able symbol string which can be resolved to an icon asset by @ch-ui/icons, via @ch-ui/vite-plugin-icons.
|
|
75
|
+
*/
|
|
76
|
+
iconSymbol?: string;
|
|
77
|
+
};
|
|
73
78
|
|
|
74
79
|
/**
|
|
75
80
|
* Capabilities provided by the plugin.
|
|
@@ -109,6 +114,8 @@ export type PluginDefinition<TProvides = {}, TInitializeProvides = {}> = Omit<Pl
|
|
|
109
114
|
unload?: () => Promise<void>;
|
|
110
115
|
};
|
|
111
116
|
|
|
117
|
+
export const pluginMeta = (meta: Plugin['meta']) => meta;
|
|
118
|
+
|
|
112
119
|
type LazyPlugin<T> = () => Promise<{ default: (props: T) => PluginDefinition }>;
|
|
113
120
|
|
|
114
121
|
export namespace Plugin {
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema as S } from '@effect/schema';
|
|
6
5
|
import { z } from 'zod';
|
|
7
6
|
|
|
7
|
+
import { S } from '@dxos/echo-schema';
|
|
8
|
+
|
|
8
9
|
import type { IntentData } from '../IntentPlugin';
|
|
9
10
|
import type { Plugin } from '../PluginHost';
|
|
10
11
|
|
|
@@ -18,6 +19,7 @@ export const SLUG_COLLECTION_INDICATOR = '';
|
|
|
18
19
|
const LayoutEntrySchema = S.mutable(S.Struct({ id: S.String, path: S.optional(S.String) }));
|
|
19
20
|
export type LayoutEntry = S.Schema.Type<typeof LayoutEntrySchema>;
|
|
20
21
|
|
|
22
|
+
// TODO(Zan): Consider making solo it's own part. It's not really a function of the 'main' part?
|
|
21
23
|
// TODO(Zan): Consider renaming the 'main' part to 'deck' part now that we are throwing out the old layout plugin.
|
|
22
24
|
// TODO(Zan): Extend to all strings?
|
|
23
25
|
const LayoutPartSchema = S.Union(
|
|
@@ -29,9 +31,7 @@ const LayoutPartSchema = S.Union(
|
|
|
29
31
|
);
|
|
30
32
|
export type LayoutPart = S.Schema.Type<typeof LayoutPartSchema>;
|
|
31
33
|
|
|
32
|
-
const LayoutPartsSchema = S.partial(
|
|
33
|
-
S.mutable(S.Record({ key: LayoutPartSchema, value: S.mutable(S.Array(LayoutEntrySchema)) })),
|
|
34
|
-
);
|
|
34
|
+
const LayoutPartsSchema = S.partial(S.mutable(S.Record(LayoutPartSchema, S.mutable(S.Array(LayoutEntrySchema)))));
|
|
35
35
|
export type LayoutParts = S.Schema.Type<typeof LayoutPartsSchema>;
|
|
36
36
|
|
|
37
37
|
const LayoutCoordinateSchema = S.mutable(S.Struct({ part: LayoutPartSchema, entryId: S.String }));
|
|
@@ -52,6 +52,14 @@ export type ActiveParts = z.infer<typeof ActiveParts>;
|
|
|
52
52
|
// TODO(burdon): Where should this go?
|
|
53
53
|
export type LayoutContainerProps<T> = T & { role?: string; coordinate?: LayoutCoordinate };
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Basic state provided by a navigation plugin.
|
|
57
|
+
*/
|
|
58
|
+
export const Attention = z.object({
|
|
59
|
+
attended: z.set(z.string()).optional().describe('Ids of items which have focus.'),
|
|
60
|
+
});
|
|
61
|
+
export type Attention = z.infer<typeof Attention>;
|
|
62
|
+
|
|
55
63
|
/**
|
|
56
64
|
* Provides for a plugin that can manage the app navigation.
|
|
57
65
|
*/
|
package/tsconfig.json
CHANGED
|
@@ -16,7 +16,35 @@
|
|
|
16
16
|
"include": [
|
|
17
17
|
"src"
|
|
18
18
|
],
|
|
19
|
-
"references": [
|
|
19
|
+
"references": [
|
|
20
|
+
{
|
|
21
|
+
"path": "../../common/async"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../common/debug"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"path": "../../common/invariant"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "../../common/local-storage"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"path": "../../common/log"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "../../common/util"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"path": "../../core/echo/echo-schema"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "../app-graph"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"path": "../client-protocol"
|
|
46
|
+
}
|
|
47
|
+
],
|
|
20
48
|
"ts-node": {
|
|
21
49
|
"compilerOptions": {
|
|
22
50
|
"module": "CommonJS"
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// packages/sdk/app-framework/src/plugins/SurfacePlugin/provides.ts
|
|
4
|
-
var parseRootSurfacePlugin = (plugin) => plugin?.provides?.surface?.components ? plugin : void 0;
|
|
5
|
-
var parseSurfacePlugin = (plugin) => plugin?.provides?.surface?.component ? plugin : void 0;
|
|
6
|
-
|
|
7
|
-
// packages/sdk/app-framework/src/plugins/SurfacePlugin/SurfaceRootContext.tsx
|
|
8
|
-
import { createContext, useContext } from "react";
|
|
9
|
-
var SurfaceRootContext = /* @__PURE__ */ createContext({
|
|
10
|
-
components: {}
|
|
11
|
-
});
|
|
12
|
-
var useSurfaceRoot = () => useContext(SurfaceRootContext);
|
|
13
|
-
var SurfaceProvider = SurfaceRootContext.Provider;
|
|
14
|
-
|
|
15
|
-
// packages/sdk/app-framework/src/plugins/SurfacePlugin/meta.ts
|
|
16
|
-
var SurfaceMeta = {
|
|
17
|
-
id: "dxos.org/plugin/surface"
|
|
18
|
-
};
|
|
19
|
-
var meta_default = SurfaceMeta;
|
|
20
|
-
|
|
21
|
-
export {
|
|
22
|
-
parseRootSurfacePlugin,
|
|
23
|
-
parseSurfacePlugin,
|
|
24
|
-
useSurfaceRoot,
|
|
25
|
-
SurfaceProvider,
|
|
26
|
-
meta_default
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=chunk-ERPIGFBI.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugins/SurfacePlugin/provides.ts", "../../../src/plugins/SurfacePlugin/SurfaceRootContext.tsx", "../../../src/plugins/SurfacePlugin/meta.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type SurfaceComponent, type SurfaceRootContext } from './SurfaceRootContext';\nimport { type Plugin } from '../PluginHost';\n\nexport type SurfaceProvides = {\n surface: {\n /**\n * Used by the `Surface` resolver to find a component to render.\n */\n component: SurfaceComponent;\n };\n};\n\nexport type SurfacePluginProvides = {\n surface: SurfaceRootContext;\n};\n\nexport const parseRootSurfacePlugin = (plugin?: Plugin) =>\n (plugin?.provides as any)?.surface?.components ? (plugin as Plugin<SurfacePluginProvides>) : undefined;\n\nexport const parseSurfacePlugin = (plugin?: Plugin) =>\n (plugin?.provides as any)?.surface?.component ? (plugin as Plugin<SurfaceProvides>) : undefined;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { createContext, useContext, type Context, type JSX, type Provider, type ForwardedRef } from 'react';\n\nimport { type SurfaceProps } from './Surface';\n\n// TODO(wittjosiah): Factor out.\ntype WithRequiredProperty<Type, Key extends keyof Type> = Type & {\n [Property in Key]-?: Type[Property];\n};\n\ntype SurfaceComponentProps = WithRequiredProperty<SurfaceProps, 'data'>;\n\n/**\n * Determines the priority of the surface when multiple components are resolved.\n */\nexport type SurfaceDisposition = 'hoist' | 'fallback';\n\nexport type SurfaceResult = {\n node: JSX.Element;\n disposition?: SurfaceDisposition;\n};\n\n/**\n * Function which resolves a Surface.\n *\n * If a null value is returned, the rendering is deferred to other plugins.\n */\nexport type SurfaceComponent = (\n props: SurfaceComponentProps,\n forwardedRef: ForwardedRef<HTMLElement>,\n) => JSX.Element | SurfaceResult | null;\n\nexport type SurfaceRootContext = {\n components: Record<string, SurfaceComponent>;\n};\n\nconst SurfaceRootContext: Context<SurfaceRootContext> = createContext<SurfaceRootContext>({ components: {} });\n\nexport const useSurfaceRoot = () => useContext(SurfaceRootContext);\n\nexport const SurfaceProvider: Provider<SurfaceRootContext> = SurfaceRootContext.Provider;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst SurfaceMeta = {\n id: 'dxos.org/plugin/surface',\n};\n\nexport default SurfaceMeta;\n"],
|
|
5
|
-
"mappings": ";;;AAoBO,IAAMA,yBAAyB,CAACC,WACpCA,QAAQC,UAAkBC,SAASC,aAAcH,SAA2CI;AAExF,IAAMC,qBAAqB,CAACL,WAChCA,QAAQC,UAAkBC,SAASI,YAAaN,SAAqCI;;;ACpBxF,SAASG,eAAeC,kBAA4E;AAmCpG,IAAMC,qBAAkDC,8BAAkC;EAAEC,YAAY,CAAC;AAAE,CAAA;AAEpG,IAAMC,iBAAiB,MAAMC,WAAWJ,kBAAAA;AAExC,IAAMK,kBAAgDL,mBAAmBM;;;ACvChF,IAAMC,cAAc;EAClBC,IAAI;AACN;AAEA,IAAA,eAAeD;",
|
|
6
|
-
"names": ["parseRootSurfacePlugin", "plugin", "provides", "surface", "components", "undefined", "parseSurfacePlugin", "component", "createContext", "useContext", "SurfaceRootContext", "createContext", "components", "useSurfaceRoot", "useContext", "SurfaceProvider", "Provider", "SurfaceMeta", "id"]
|
|
7
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// packages/sdk/app-framework/src/plugins/helpers.ts
|
|
4
|
-
import { raise } from "@dxos/debug";
|
|
5
|
-
var definePlugin = (plugin) => plugin;
|
|
6
|
-
var findPlugin = (plugins, id) => {
|
|
7
|
-
return plugins.find((plugin) => plugin.meta.id === id || typeof plugin.meta.shortId === "string" && plugin.meta.shortId === id);
|
|
8
|
-
};
|
|
9
|
-
var getPlugin = (plugins, id) => {
|
|
10
|
-
return findPlugin(plugins, id) ?? raise(new Error(`Plugin not found: ${id}`));
|
|
11
|
-
};
|
|
12
|
-
var filterPlugins = (plugins, predicate) => plugins.map((plugin) => predicate(plugin)).filter((plugin) => !!plugin);
|
|
13
|
-
var resolvePlugin = (plugins, predicate) => filterPlugins(plugins, predicate)[0];
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
definePlugin,
|
|
17
|
-
findPlugin,
|
|
18
|
-
getPlugin,
|
|
19
|
-
filterPlugins,
|
|
20
|
-
resolvePlugin
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=chunk-IY7HCP4K.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugins/helpers.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { raise } from '@dxos/debug';\n\nimport { type Plugin } from './PluginHost';\n\n/**\n * Define a plugin\n */\nexport const definePlugin = <TProvides>(plugin: Plugin<TProvides>): Plugin<TProvides> => plugin;\n\n/**\n * Find a plugin by ID.\n */\nexport const findPlugin = <T>(plugins: Plugin[], id: string): Plugin<T> | undefined => {\n return plugins.find(\n (plugin) => plugin.meta.id === id || (typeof plugin.meta.shortId === 'string' && plugin.meta.shortId === id),\n ) as Plugin<T>;\n};\n\n/**\n * Find a plugin by ID, or raise an error if not found.\n */\nexport const getPlugin = <T>(plugins: Plugin[], id: string): Plugin<T> => {\n return findPlugin(plugins, id) ?? raise(new Error(`Plugin not found: ${id}`));\n};\n\n/**\n * Filter a list of plugins to only those that match a predicate.\n */\nexport const filterPlugins = <T>(\n plugins: Plugin[],\n predicate: (plugin: Plugin) => Plugin<T> | undefined,\n): Plugin<T>[] => plugins.map((plugin) => predicate(plugin)).filter((plugin): plugin is Plugin<T> => !!plugin);\n\n/**\n * Resolves a plugin by predicate.\n *\n * @example\n * import { parseIntentPlugin, resolvePlugin } from '@dxos/app-framework';\n * const intentPlugin = resolvePlugin(plugins, parseIntentPlugin);\n */\nexport const resolvePlugin = <T>(\n plugins: Plugin[],\n predicate: (plugin: Plugin) => Plugin<T> | undefined,\n): Plugin<T> | undefined => filterPlugins(plugins, predicate)[0];\n"],
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,aAAa;AAOf,IAAMC,eAAe,CAAYC,WAAiDA;AAKlF,IAAMC,aAAa,CAAIC,SAAmBC,OAAAA;AAC/C,SAAOD,QAAQE,KACb,CAACJ,WAAWA,OAAOK,KAAKF,OAAOA,MAAO,OAAOH,OAAOK,KAAKC,YAAY,YAAYN,OAAOK,KAAKC,YAAYH,EAAAA;AAE7G;AAKO,IAAMI,YAAY,CAAIL,SAAmBC,OAAAA;AAC9C,SAAOF,WAAWC,SAASC,EAAAA,KAAOK,MAAM,IAAIC,MAAM,qBAAqBN,EAAAA,EAAI,CAAA;AAC7E;AAKO,IAAMO,gBAAgB,CAC3BR,SACAS,cACgBT,QAAQU,IAAI,CAACZ,WAAWW,UAAUX,MAAAA,CAAAA,EAASa,OAAO,CAACb,WAAgC,CAAC,CAACA,MAAAA;AAShG,IAAMc,gBAAgB,CAC3BZ,SACAS,cAC0BD,cAAcR,SAASS,SAAAA,EAAW,CAAA;",
|
|
6
|
-
"names": ["raise", "definePlugin", "plugin", "findPlugin", "plugins", "id", "find", "meta", "shortId", "getPlugin", "raise", "Error", "filterPlugins", "predicate", "map", "filter", "resolvePlugin"]
|
|
7
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// packages/sdk/app-framework/src/plugins/IntentPlugin/provides.ts
|
|
4
|
-
var parseIntentPlugin = (plugin) => plugin.provides.intent?.dispatch ? plugin : void 0;
|
|
5
|
-
var parseIntentResolverPlugin = (plugin) => plugin.provides.intent?.resolver ? plugin : void 0;
|
|
6
|
-
var INTENT_ACTION = "dxos.org/plugin/intent";
|
|
7
|
-
var IntentAction;
|
|
8
|
-
(function(IntentAction2) {
|
|
9
|
-
IntentAction2[IntentAction2["SHOW_UNDO"] = `${INTENT_ACTION}/show-undo`] = "SHOW_UNDO";
|
|
10
|
-
})(IntentAction || (IntentAction = {}));
|
|
11
|
-
|
|
12
|
-
// packages/sdk/app-framework/src/plugins/IntentPlugin/IntentContext.tsx
|
|
13
|
-
import { createContext, useContext } from "react";
|
|
14
|
-
import { useEffect } from "react";
|
|
15
|
-
var IntentContext = /* @__PURE__ */ createContext({
|
|
16
|
-
dispatch: async () => ({}),
|
|
17
|
-
undo: async () => ({}),
|
|
18
|
-
history: [],
|
|
19
|
-
registerResolver: () => () => {
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
var useIntent = () => useContext(IntentContext);
|
|
23
|
-
var useIntentDispatcher = () => {
|
|
24
|
-
const { dispatch } = useIntent();
|
|
25
|
-
return dispatch;
|
|
26
|
-
};
|
|
27
|
-
var useIntentResolver = (plugin, resolver) => {
|
|
28
|
-
const { registerResolver } = useIntent();
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
return registerResolver(plugin, resolver);
|
|
31
|
-
}, [
|
|
32
|
-
plugin,
|
|
33
|
-
resolver
|
|
34
|
-
]);
|
|
35
|
-
};
|
|
36
|
-
var IntentProvider = IntentContext.Provider;
|
|
37
|
-
|
|
38
|
-
// packages/sdk/app-framework/src/plugins/IntentPlugin/meta.ts
|
|
39
|
-
var IntentMeta = {
|
|
40
|
-
id: "dxos.org/plugin/intent"
|
|
41
|
-
};
|
|
42
|
-
var meta_default = IntentMeta;
|
|
43
|
-
|
|
44
|
-
export {
|
|
45
|
-
parseIntentPlugin,
|
|
46
|
-
parseIntentResolverPlugin,
|
|
47
|
-
IntentAction,
|
|
48
|
-
useIntent,
|
|
49
|
-
useIntentDispatcher,
|
|
50
|
-
useIntentResolver,
|
|
51
|
-
IntentProvider,
|
|
52
|
-
meta_default
|
|
53
|
-
};
|
|
54
|
-
//# sourceMappingURL=chunk-P2TQLXZR.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugins/IntentPlugin/provides.ts", "../../../src/plugins/IntentPlugin/IntentContext.tsx", "../../../src/plugins/IntentPlugin/meta.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type IntentContext } from './IntentContext';\nimport { type IntentResolver } from './intent';\nimport { type Plugin } from '../PluginHost';\n\nexport type IntentResolverProvides = {\n intent: {\n resolver: IntentResolver;\n };\n};\n\nexport type IntentPluginProvides = {\n intent: IntentContext;\n};\n\nexport const parseIntentPlugin = (plugin: Plugin) =>\n (plugin.provides as any).intent?.dispatch ? (plugin as Plugin<IntentPluginProvides>) : undefined;\n\nexport const parseIntentResolverPlugin = (plugin: Plugin) =>\n (plugin.provides as any).intent?.resolver ? (plugin as Plugin<IntentResolverProvides>) : undefined;\n\n//\n// Intents\n//\n\nconst INTENT_ACTION = 'dxos.org/plugin/intent';\nexport enum IntentAction {\n /**\n * Fired after an intent is dispatched if the intent is undoable.\n */\n SHOW_UNDO = `${INTENT_ACTION}/show-undo`,\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Context, createContext, useContext, type Provider } from 'react';\nimport { useEffect } from 'react';\n\nimport type { UnsubscribeCallback } from '@dxos/async';\n\nimport type { Intent, IntentDispatcher, IntentResolver, IntentResult } from './intent';\n\nexport type IntentExecution = {\n intent: Intent;\n result: IntentResult;\n};\n\nexport type IntentContext = {\n dispatch: IntentDispatcher;\n undo: () => Promise<IntentResult | void>;\n history: IntentExecution[][];\n registerResolver: (pluginId: string, resolver: IntentResolver) => UnsubscribeCallback;\n};\n\nconst IntentContext: Context<IntentContext> = createContext<IntentContext>({\n dispatch: async () => ({}),\n undo: async () => ({}),\n history: [],\n registerResolver: () => () => {},\n});\n\n/**\n * @deprecated Prefer granular hooks.\n */\n// TODO(burdon): Remove. Use useIntentDispatcher.\nexport const useIntent = () => useContext(IntentContext);\n\nexport const useIntentDispatcher = (): IntentDispatcher => {\n const { dispatch } = useIntent();\n return dispatch;\n};\n\nexport const useIntentResolver = (plugin: string, resolver: IntentResolver) => {\n const { registerResolver } = useIntent();\n useEffect(() => {\n return registerResolver(plugin, resolver);\n }, [plugin, resolver]);\n};\n\nexport const IntentProvider: Provider<IntentContext> = IntentContext.Provider;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst IntentMeta = {\n id: 'dxos.org/plugin/intent',\n};\n\nexport default IntentMeta;\n"],
|
|
5
|
-
"mappings": ";;;AAkBO,IAAMA,oBAAoB,CAACC,WAC/BA,OAAOC,SAAiBC,QAAQC,WAAYH,SAA0CI;AAElF,IAAMC,4BAA4B,CAACL,WACvCA,OAAOC,SAAiBC,QAAQI,WAAYN,SAA4CI;AAM3F,IAAMG,gBAAgB;;UACVC,eAAAA;AAGT,EAAAA,cAAAA,cAAA,WAAA,IACW,GAAGD,aAAAA,YAAyB,IAAA;GAJ9BC,iBAAAA,eAAAA,CAAAA,EAAAA;;;ACzBZ,SAAuBC,eAAeC,kBAAiC;AACvE,SAASC,iBAAiB;AAkB1B,IAAMC,gBAAwCC,8BAA6B;EACzEC,UAAU,aAAa,CAAC;EACxBC,MAAM,aAAa,CAAC;EACpBC,SAAS,CAAA;EACTC,kBAAkB,MAAM,MAAA;EAAO;AACjC,CAAA;AAMO,IAAMC,YAAY,MAAMC,WAAWP,aAAAA;AAEnC,IAAMQ,sBAAsB,MAAA;AACjC,QAAM,EAAEN,SAAQ,IAAKI,UAAAA;AACrB,SAAOJ;AACT;AAEO,IAAMO,oBAAoB,CAACC,QAAgBC,aAAAA;AAChD,QAAM,EAAEN,iBAAgB,IAAKC,UAAAA;AAC7BM,YAAU,MAAA;AACR,WAAOP,iBAAiBK,QAAQC,QAAAA;EAClC,GAAG;IAACD;IAAQC;GAAS;AACvB;AAEO,IAAME,iBAA0Cb,cAAcc;;;AC5CrE,IAAMC,aAAa;EACjBC,IAAI;AACN;AAEA,IAAA,eAAeD;",
|
|
6
|
-
"names": ["parseIntentPlugin", "plugin", "provides", "intent", "dispatch", "undefined", "parseIntentResolverPlugin", "resolver", "INTENT_ACTION", "IntentAction", "createContext", "useContext", "useEffect", "IntentContext", "createContext", "dispatch", "undo", "history", "registerResolver", "useIntent", "useContext", "useIntentDispatcher", "useIntentResolver", "plugin", "resolver", "useEffect", "IntentProvider", "Provider", "IntentMeta", "id"]
|
|
7
|
-
}
|