@dxos/app-framework 0.3.11-main.f5e7551 → 0.3.11-main.f7c1031
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/{chunk-C2K6M6WC.mjs → chunk-7MQ2DVDI.mjs} +19 -2
- package/dist/lib/browser/chunk-7MQ2DVDI.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +186 -148
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/plugin-PGPBA2JO.mjs +111 -0
- package/dist/lib/browser/plugin-PGPBA2JO.mjs.map +7 -0
- package/dist/lib/node/{chunk-BOQBLWMX.cjs → chunk-FETX4EGX.cjs} +26 -7
- package/dist/lib/node/chunk-FETX4EGX.cjs.map +7 -0
- package/dist/lib/node/index.cjs +183 -147
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{plugin-WDNRX2SR.cjs → plugin-HLGHD6N5.cjs} +63 -14
- package/dist/lib/node/plugin-HLGHD6N5.cjs.map +7 -0
- package/dist/types/src/plugins/IntentPlugin/IntentContext.d.ts +10 -2
- package/dist/types/src/plugins/IntentPlugin/IntentContext.d.ts.map +1 -1
- package/dist/types/src/plugins/IntentPlugin/intent.d.ts +34 -1
- package/dist/types/src/plugins/IntentPlugin/intent.d.ts.map +1 -1
- package/dist/types/src/plugins/IntentPlugin/plugin.d.ts.map +1 -1
- package/dist/types/src/plugins/IntentPlugin/provides.d.ts +2 -2
- package/dist/types/src/plugins/IntentPlugin/provides.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +4 -2
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts +4 -5
- package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts.map +1 -1
- package/dist/types/src/plugins/common/layout.d.ts +17 -15
- package/dist/types/src/plugins/common/layout.d.ts.map +1 -1
- package/package.json +8 -7
- package/project.json +3 -1
- package/src/plugins/IntentPlugin/IntentContext.tsx +27 -3
- package/src/plugins/IntentPlugin/intent.ts +41 -1
- package/src/plugins/IntentPlugin/plugin.tsx +60 -7
- package/src/plugins/IntentPlugin/provides.ts +2 -2
- package/src/plugins/PluginHost/PluginHost.tsx +92 -57
- package/src/plugins/PluginHost/plugin.ts +2 -1
- package/src/plugins/SurfacePlugin/Surface.tsx +15 -21
- package/src/plugins/common/layout.ts +16 -14
- package/src/vite-env.d.ts +5 -0
- package/tsconfig.json +3 -0
- package/dist/lib/browser/chunk-C2K6M6WC.mjs.map +0 -7
- package/dist/lib/browser/plugin-CBPJO5NB.mjs +0 -63
- package/dist/lib/browser/plugin-CBPJO5NB.mjs.map +0 -7
- package/dist/lib/node/chunk-BOQBLWMX.cjs.map +0 -7
- package/dist/lib/node/plugin-WDNRX2SR.cjs.map +0 -7
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import React, {
|
|
6
6
|
forwardRef,
|
|
7
|
-
type FC,
|
|
8
7
|
type ReactNode,
|
|
9
8
|
Fragment,
|
|
10
9
|
type ForwardedRef,
|
|
11
10
|
type PropsWithChildren,
|
|
12
11
|
isValidElement,
|
|
12
|
+
Suspense,
|
|
13
13
|
} from 'react';
|
|
14
14
|
import { createContext, useContext } from 'react';
|
|
15
15
|
|
|
@@ -50,11 +50,10 @@ export type SurfaceProps = PropsWithChildren<{
|
|
|
50
50
|
fallback?: ErrorBoundary['props']['fallback'];
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* If specified,
|
|
54
|
-
*
|
|
55
|
-
* @deprecated Provide a component with `disposition: 'fallback'` instead.
|
|
53
|
+
* If specified, the Surface will be wrapped in a suspense boundary.
|
|
54
|
+
* The placeholder component will be rendered while the surface component is loading.
|
|
56
55
|
*/
|
|
57
|
-
|
|
56
|
+
placeholder?: ReactNode;
|
|
58
57
|
|
|
59
58
|
/**
|
|
60
59
|
* If more than one component is resolved, the limit determines how many are rendered.
|
|
@@ -78,21 +77,20 @@ export type SurfaceProps = PropsWithChildren<{
|
|
|
78
77
|
* A surface is a named region of the screen that can be populated by plugins.
|
|
79
78
|
*/
|
|
80
79
|
export const Surface = forwardRef<HTMLElement, SurfaceProps>(
|
|
81
|
-
({ role, name = role, fallback, ...rest }, forwardedRef) => {
|
|
80
|
+
({ role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
|
|
82
81
|
const props = { role, name, fallback, ...rest };
|
|
83
82
|
const context = useContext(SurfaceContext);
|
|
84
83
|
const data = props.data ?? ((name && context?.surfaces?.[name]?.data) || {});
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
</>
|
|
85
|
+
const resolver = <SurfaceResolver {...props} ref={forwardedRef} />;
|
|
86
|
+
const suspense = placeholder ? <Suspense fallback={placeholder}>{resolver}</Suspense> : resolver;
|
|
87
|
+
|
|
88
|
+
return fallback ? (
|
|
89
|
+
<ErrorBoundary data={data} fallback={fallback}>
|
|
90
|
+
{suspense}
|
|
91
|
+
</ErrorBoundary>
|
|
92
|
+
) : (
|
|
93
|
+
suspense
|
|
96
94
|
);
|
|
97
95
|
},
|
|
98
96
|
);
|
|
@@ -111,11 +109,7 @@ const SurfaceResolver = forwardRef<HTMLElement, SurfaceProps>((props, forwardedR
|
|
|
111
109
|
},
|
|
112
110
|
};
|
|
113
111
|
|
|
114
|
-
return
|
|
115
|
-
<SurfaceContext.Provider value={currentContext}>
|
|
116
|
-
{nodes.length > 0 ? nodes : props.contentFallback ? <props.contentFallback /> : null}
|
|
117
|
-
</SurfaceContext.Provider>
|
|
118
|
-
);
|
|
112
|
+
return <SurfaceContext.Provider value={currentContext}>{nodes}</SurfaceContext.Provider>;
|
|
119
113
|
});
|
|
120
114
|
|
|
121
115
|
const resolveNodes = (
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
|
|
7
|
+
import { type IntentData } from '../IntentPlugin';
|
|
7
8
|
import type { Plugin } from '../PluginHost';
|
|
8
9
|
|
|
9
10
|
//
|
|
@@ -65,40 +66,41 @@ export enum LayoutAction {
|
|
|
65
66
|
OPEN_POPOVER = `${LAYOUT_ACTION}/open-popover`,
|
|
66
67
|
CLOSE_POPOVER = `${LAYOUT_ACTION}/close-popover`,
|
|
67
68
|
ACTIVATE = `${LAYOUT_ACTION}/activate`,
|
|
69
|
+
FOCUS = `${LAYOUT_ACTION}/focus`,
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
/**
|
|
71
73
|
* Expected payload for layout actions.
|
|
72
74
|
*/
|
|
73
75
|
export namespace LayoutAction {
|
|
74
|
-
export type ToggleFullscreen = {
|
|
76
|
+
export type ToggleFullscreen = IntentData<{
|
|
75
77
|
state?: boolean;
|
|
76
|
-
}
|
|
78
|
+
}>;
|
|
77
79
|
|
|
78
|
-
export type ToggleSidebar = {
|
|
80
|
+
export type ToggleSidebar = IntentData<{
|
|
79
81
|
state?: boolean;
|
|
80
|
-
}
|
|
82
|
+
}>;
|
|
81
83
|
|
|
82
|
-
export type ToggleComplementarySidebar = {
|
|
84
|
+
export type ToggleComplementarySidebar = IntentData<{
|
|
83
85
|
state?: boolean;
|
|
84
|
-
}
|
|
86
|
+
}>;
|
|
85
87
|
|
|
86
|
-
export type OpenDialog = {
|
|
88
|
+
export type OpenDialog = IntentData<{
|
|
87
89
|
component: string;
|
|
88
90
|
subject: any;
|
|
89
|
-
}
|
|
91
|
+
}>;
|
|
90
92
|
|
|
91
|
-
export type CloseDialog = {}
|
|
93
|
+
export type CloseDialog = IntentData<{}>;
|
|
92
94
|
|
|
93
|
-
export type OpenPopover = {
|
|
95
|
+
export type OpenPopover = IntentData<{
|
|
94
96
|
anchorId: string;
|
|
95
97
|
component: string;
|
|
96
98
|
subject: any;
|
|
97
|
-
}
|
|
99
|
+
}>;
|
|
98
100
|
|
|
99
|
-
export type ClosePopover = {}
|
|
101
|
+
export type ClosePopover = IntentData<{}>;
|
|
100
102
|
|
|
101
|
-
export type Activate = {
|
|
103
|
+
export type Activate = IntentData<{
|
|
102
104
|
id: string;
|
|
103
|
-
}
|
|
105
|
+
}>;
|
|
104
106
|
}
|
package/tsconfig.json
CHANGED
|
@@ -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 Intent } from './intent';\nimport { type Plugin } from '../PluginHost';\n\nexport type IntentResolverProvides = {\n intent: {\n resolver: (intent: Intent, plugins: Plugin[]) => any;\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// Copyright 2023 DXOS.org\n//\n\nimport { type Context, createContext, useContext, type Provider } from 'react';\n\nimport { type DispatchIntent } from './intent';\n\nexport type IntentContext = {\n dispatch: DispatchIntent;\n};\n\nconst IntentContext: Context<IntentContext> = createContext<IntentContext>({ dispatch: async () => {} });\n\nexport const useIntent = () => useContext(IntentContext);\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;;;AClB3F,SAAuBG,eAAeC,kBAAiC;AAQvE,IAAMC,gBAAwCC,8BAA6B;EAAEC,UAAU,YAAA;EAAa;AAAE,CAAA;AAE/F,IAAMC,YAAY,MAAMC,WAAWJ,aAAAA;AAEnC,IAAMK,iBAA0CL,cAAcM;;;ACZrE,IAAMC,aAAa;EACjBC,IAAI;AACN;AAEA,IAAA,eAAeD;",
|
|
6
|
-
"names": ["parseIntentPlugin", "plugin", "provides", "intent", "dispatch", "undefined", "parseIntentResolverPlugin", "resolver", "createContext", "useContext", "IntentContext", "createContext", "dispatch", "useIntent", "useContext", "IntentProvider", "Provider", "IntentMeta", "id"]
|
|
7
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IntentProvider,
|
|
3
|
-
meta_default,
|
|
4
|
-
parseIntentResolverPlugin
|
|
5
|
-
} from "./chunk-C2K6M6WC.mjs";
|
|
6
|
-
import {
|
|
7
|
-
filterPlugins,
|
|
8
|
-
findPlugin
|
|
9
|
-
} from "./chunk-CFZ5JAJF.mjs";
|
|
10
|
-
|
|
11
|
-
// packages/sdk/app-framework/src/plugins/IntentPlugin/plugin.tsx
|
|
12
|
-
import { deepSignal } from "deepsignal/react";
|
|
13
|
-
import React from "react";
|
|
14
|
-
var IntentPlugin = () => {
|
|
15
|
-
const state = deepSignal({
|
|
16
|
-
dispatch: async () => {
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return {
|
|
20
|
-
meta: meta_default,
|
|
21
|
-
ready: async (plugins) => {
|
|
22
|
-
const dispatch = async (intent) => {
|
|
23
|
-
if (intent.plugin) {
|
|
24
|
-
const plugin = findPlugin(plugins, intent.plugin);
|
|
25
|
-
return plugin?.provides.intent.resolver(intent, plugins);
|
|
26
|
-
}
|
|
27
|
-
for (const plugin of filterPlugins(plugins, parseIntentResolverPlugin)) {
|
|
28
|
-
const result = await plugin.provides.intent.resolver(intent, plugins);
|
|
29
|
-
if (result) {
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
state.dispatch = async (intentOrArray) => {
|
|
35
|
-
let result = null;
|
|
36
|
-
for (const intent of Array.isArray(intentOrArray) ? intentOrArray : [
|
|
37
|
-
intentOrArray
|
|
38
|
-
]) {
|
|
39
|
-
const data = intent.data ? {
|
|
40
|
-
...result,
|
|
41
|
-
...intent.data
|
|
42
|
-
} : result;
|
|
43
|
-
result = await dispatch({
|
|
44
|
-
...intent,
|
|
45
|
-
data
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
provides: {
|
|
52
|
-
intent: state,
|
|
53
|
-
context: ({ children }) => /* @__PURE__ */ React.createElement(IntentProvider, {
|
|
54
|
-
value: state
|
|
55
|
-
}, children)
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
var plugin_default = IntentPlugin;
|
|
60
|
-
export {
|
|
61
|
-
plugin_default as default
|
|
62
|
-
};
|
|
63
|
-
//# sourceMappingURL=plugin-CBPJO5NB.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugins/IntentPlugin/plugin.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { deepSignal } from 'deepsignal/react';\nimport React from 'react';\n\nimport { type IntentContext, IntentProvider } from './IntentContext';\nimport type { Intent } from './intent';\nimport IntentMeta from './meta';\nimport { type IntentPluginProvides, type IntentResolverProvides, parseIntentResolverPlugin } from './provides';\nimport type { PluginDefinition } from '../PluginHost';\nimport { filterPlugins, findPlugin } from '../helpers';\n\n/**\n * Allows plugins to register intent handlers and routes sent intents to the appropriate plugin.\n * Inspired by https://developer.android.com/reference/android/content/Intent.\n */\nconst IntentPlugin = (): PluginDefinition<IntentPluginProvides> => {\n const state = deepSignal<IntentContext>({ dispatch: async () => {} });\n\n return {\n meta: IntentMeta,\n ready: async (plugins) => {\n // Dispatch intent to associated plugin.\n const dispatch = async (intent: Intent) => {\n if (intent.plugin) {\n const plugin = findPlugin<IntentResolverProvides>(plugins, intent.plugin);\n return plugin?.provides.intent.resolver(intent, plugins);\n }\n\n // Return resolved value from first plugin that handles the intent.\n for (const plugin of filterPlugins(plugins, parseIntentResolverPlugin)) {\n const result = await plugin.provides.intent.resolver(intent, plugins);\n if (result) {\n return result;\n }\n }\n };\n\n // Sequentially dispatch array of invents.\n state.dispatch = async (intentOrArray) => {\n let result: any = null;\n for (const intent of Array.isArray(intentOrArray) ? intentOrArray : [intentOrArray]) {\n const data = intent.data ? { ...result, ...intent.data } : result;\n result = await dispatch({ ...intent, data });\n }\n return result;\n };\n },\n provides: {\n intent: state,\n context: ({ children }) => <IntentProvider value={state}>{children}</IntentProvider>,\n },\n };\n};\n\nexport default IntentPlugin;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;AAIA,SAASA,kBAAkB;AAC3B,OAAOC,WAAW;AAalB,IAAMC,eAAe,MAAA;AACnB,QAAMC,QAAQC,WAA0B;IAAEC,UAAU,YAAA;IAAa;EAAE,CAAA;AAEnE,SAAO;IACLC,MAAMC;IACNC,OAAO,OAAOC,YAAAA;AAEZ,YAAMJ,WAAW,OAAOK,WAAAA;AACtB,YAAIA,OAAOC,QAAQ;AACjB,gBAAMA,SAASC,WAAmCH,SAASC,OAAOC,MAAM;AACxE,iBAAOA,QAAQE,SAASH,OAAOI,SAASJ,QAAQD,OAAAA;QAClD;AAGA,mBAAWE,UAAUI,cAAcN,SAASO,yBAAAA,GAA4B;AACtE,gBAAMC,SAAS,MAAMN,OAAOE,SAASH,OAAOI,SAASJ,QAAQD,OAAAA;AAC7D,cAAIQ,QAAQ;AACV,mBAAOA;UACT;QACF;MACF;AAGAd,YAAME,WAAW,OAAOa,kBAAAA;AACtB,YAAID,SAAc;AAClB,mBAAWP,UAAUS,MAAMC,QAAQF,aAAAA,IAAiBA,gBAAgB;UAACA;WAAgB;AACnF,gBAAMG,OAAOX,OAAOW,OAAO;YAAE,GAAGJ;YAAQ,GAAGP,OAAOW;UAAK,IAAIJ;AAC3DA,mBAAS,MAAMZ,SAAS;YAAE,GAAGK;YAAQW;UAAK,CAAA;QAC5C;AACA,eAAOJ;MACT;IACF;IACAJ,UAAU;MACRH,QAAQP;MACRmB,SAAS,CAAC,EAAEC,SAAQ,MAAO,sBAAA,cAACC,gBAAAA;QAAeC,OAAOtB;SAAQoB,QAAAA;IAC5D;EACF;AACF;AAEA,IAAA,iBAAerB;",
|
|
6
|
-
"names": ["deepSignal", "React", "IntentPlugin", "state", "deepSignal", "dispatch", "meta", "IntentMeta", "ready", "plugins", "intent", "plugin", "findPlugin", "provides", "resolver", "filterPlugins", "parseIntentResolverPlugin", "result", "intentOrArray", "Array", "isArray", "data", "context", "children", "IntentProvider", "value"]
|
|
7
|
-
}
|
|
@@ -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 Intent } from './intent';\nimport { type Plugin } from '../PluginHost';\n\nexport type IntentResolverProvides = {\n intent: {\n resolver: (intent: Intent, plugins: Plugin[]) => any;\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// Copyright 2023 DXOS.org\n//\n\nimport { type Context, createContext, useContext, type Provider } from 'react';\n\nimport { type DispatchIntent } from './intent';\n\nexport type IntentContext = {\n dispatch: DispatchIntent;\n};\n\nconst IntentContext: Context<IntentContext> = createContext<IntentContext>({ dispatch: async () => {} });\n\nexport const useIntent = () => useContext(IntentContext);\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;ACIA,mBAAuE;ADchE,IAAMA,oBAAoB,CAACC,WAC/BA,OAAOC,SAAiBC,QAAQC,WAAYH,SAA0CI;AAElF,IAAMC,4BAA4B,CAACL,WACvCA,OAAOC,SAAiBC,QAAQI,WAAYN,SAA4CI;ACV3F,IAAMG,gBAAwCC,gDAA6B;EAAEL,UAAU,YAAA;EAAa;AAAE,CAAA;AAE/F,IAAMM,YAAY,UAAMC,yBAAWH,aAAAA;AAEnC,IAAMI,iBAA0CJ,cAAcK;ACZrE,IAAMC,aAAa;EACjBC,IAAI;AACN;AAEA,IAAA,eAAeD;",
|
|
6
|
-
"names": ["parseIntentPlugin", "plugin", "provides", "intent", "dispatch", "undefined", "parseIntentResolverPlugin", "resolver", "IntentContext", "createContext", "useIntent", "useContext", "IntentProvider", "Provider", "IntentMeta", "id"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugins/IntentPlugin/plugin.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { deepSignal } from 'deepsignal/react';\nimport React from 'react';\n\nimport { type IntentContext, IntentProvider } from './IntentContext';\nimport type { Intent } from './intent';\nimport IntentMeta from './meta';\nimport { type IntentPluginProvides, type IntentResolverProvides, parseIntentResolverPlugin } from './provides';\nimport type { PluginDefinition } from '../PluginHost';\nimport { filterPlugins, findPlugin } from '../helpers';\n\n/**\n * Allows plugins to register intent handlers and routes sent intents to the appropriate plugin.\n * Inspired by https://developer.android.com/reference/android/content/Intent.\n */\nconst IntentPlugin = (): PluginDefinition<IntentPluginProvides> => {\n const state = deepSignal<IntentContext>({ dispatch: async () => {} });\n\n return {\n meta: IntentMeta,\n ready: async (plugins) => {\n // Dispatch intent to associated plugin.\n const dispatch = async (intent: Intent) => {\n if (intent.plugin) {\n const plugin = findPlugin<IntentResolverProvides>(plugins, intent.plugin);\n return plugin?.provides.intent.resolver(intent, plugins);\n }\n\n // Return resolved value from first plugin that handles the intent.\n for (const plugin of filterPlugins(plugins, parseIntentResolverPlugin)) {\n const result = await plugin.provides.intent.resolver(intent, plugins);\n if (result) {\n return result;\n }\n }\n };\n\n // Sequentially dispatch array of invents.\n state.dispatch = async (intentOrArray) => {\n let result: any = null;\n for (const intent of Array.isArray(intentOrArray) ? intentOrArray : [intentOrArray]) {\n const data = intent.data ? { ...result, ...intent.data } : result;\n result = await dispatch({ ...intent, data });\n }\n return result;\n };\n },\n provides: {\n intent: state,\n context: ({ children }) => <IntentProvider value={state}>{children}</IntentProvider>,\n },\n };\n};\n\nexport default IntentPlugin;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAA2B;AAC3B,IAAAA,gBAAkB;AAalB,IAAMC,eAAe,MAAA;AACnB,QAAMC,YAAQC,yBAA0B;IAAEC,UAAU,YAAA;IAAa;EAAE,CAAA;AAEnE,SAAO;IACLC,MAAMC;IACNC,OAAO,OAAOC,YAAAA;AAEZ,YAAMJ,WAAW,OAAOK,WAAAA;AACtB,YAAIA,OAAOC,QAAQ;AACjB,gBAAMA,aAASC,kCAAmCH,SAASC,OAAOC,MAAM;AACxE,iBAAOA,QAAQE,SAASH,OAAOI,SAASJ,QAAQD,OAAAA;QAClD;AAGA,mBAAWE,cAAUI,qCAAcN,SAASO,+CAAAA,GAA4B;AACtE,gBAAMC,SAAS,MAAMN,OAAOE,SAASH,OAAOI,SAASJ,QAAQD,OAAAA;AAC7D,cAAIQ,QAAQ;AACV,mBAAOA;UACT;QACF;MACF;AAGAd,YAAME,WAAW,OAAOa,kBAAAA;AACtB,YAAID,SAAc;AAClB,mBAAWP,UAAUS,MAAMC,QAAQF,aAAAA,IAAiBA,gBAAgB;UAACA;WAAgB;AACnF,gBAAMG,OAAOX,OAAOW,OAAO;YAAE,GAAGJ;YAAQ,GAAGP,OAAOW;UAAK,IAAIJ;AAC3DA,mBAAS,MAAMZ,SAAS;YAAE,GAAGK;YAAQW;UAAK,CAAA;QAC5C;AACA,eAAOJ;MACT;IACF;IACAJ,UAAU;MACRH,QAAQP;MACRmB,SAAS,CAAC,EAAEC,SAAQ,MAAO,8BAAAC,QAAA,cAACC,sCAAAA;QAAeC,OAAOvB;SAAQoB,QAAAA;IAC5D;EACF;AACF;AAEA,IAAA,iBAAerB;",
|
|
6
|
-
"names": ["import_react", "IntentPlugin", "state", "deepSignal", "dispatch", "meta", "IntentMeta", "ready", "plugins", "intent", "plugin", "findPlugin", "provides", "resolver", "filterPlugins", "parseIntentResolverPlugin", "result", "intentOrArray", "Array", "isArray", "data", "context", "children", "React", "IntentProvider", "value"]
|
|
7
|
-
}
|