@dxos/app-framework 0.6.13 → 0.6.14-main.1366248
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-3E7RY3CE.mjs +72 -0
- package/dist/lib/browser/chunk-3E7RY3CE.mjs.map +7 -0
- package/dist/lib/browser/chunk-653Y45CL.mjs +41 -0
- package/dist/lib/browser/chunk-653Y45CL.mjs.map +7 -0
- package/dist/lib/browser/{plugin-MM66VRCO.mjs → chunk-CDLQO5K2.mjs} +66 -20
- package/dist/lib/browser/chunk-CDLQO5K2.mjs.map +7 -0
- package/dist/lib/browser/chunk-EQTQGGE6.mjs +214 -0
- package/dist/lib/browser/chunk-EQTQGGE6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +183 -293
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/plugin-intent-Q5KFPKFA.mjs +22 -0
- package/dist/lib/browser/plugin-intent-Q5KFPKFA.mjs.map +7 -0
- package/dist/lib/browser/plugin-settings-OM3G2QFY.mjs +11 -0
- package/dist/lib/browser/plugin-settings-OM3G2QFY.mjs.map +7 -0
- package/dist/lib/browser/plugin-surface-ZQXFAL46.mjs +24 -0
- package/dist/lib/browser/plugin-surface-ZQXFAL46.mjs.map +7 -0
- package/dist/lib/node/chunk-EF67TRWJ.cjs +236 -0
- package/dist/lib/node/chunk-EF67TRWJ.cjs.map +7 -0
- package/dist/lib/node/chunk-JZ2JVKRY.cjs +58 -0
- package/dist/lib/node/chunk-JZ2JVKRY.cjs.map +7 -0
- package/dist/lib/node/{chunk-62W6CMGM.cjs → chunk-QBM42OQ6.cjs} +56 -5
- package/dist/lib/node/chunk-QBM42OQ6.cjs.map +7 -0
- package/dist/lib/node/{plugin-QV7ESETI.cjs → chunk-VOKMWTKO.cjs} +74 -20
- package/dist/lib/node/chunk-VOKMWTKO.cjs.map +7 -0
- package/dist/lib/node/index.cjs +195 -310
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/plugin-intent-FMC4SDI3.cjs +43 -0
- package/dist/lib/node/plugin-intent-FMC4SDI3.cjs.map +7 -0
- package/dist/lib/node/plugin-settings-OZ6IKAE5.cjs +32 -0
- package/dist/lib/node/plugin-settings-OZ6IKAE5.cjs.map +7 -0
- package/dist/lib/node/{chunk-P5GRB4XF.cjs → plugin-surface-B5NHOBSW.cjs} +19 -22
- package/dist/lib/node/plugin-surface-B5NHOBSW.cjs.map +7 -0
- package/dist/lib/node-esm/chunk-3FCLBEOX.mjs +215 -0
- package/dist/lib/node-esm/chunk-3FCLBEOX.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-EYCTSFEJ.mjs +74 -0
- package/dist/lib/node-esm/chunk-EYCTSFEJ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-MYNXI5VG.mjs +214 -0
- package/dist/lib/node-esm/chunk-MYNXI5VG.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-YNU7FTGJ.mjs +43 -0
- package/dist/lib/node-esm/chunk-YNU7FTGJ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +567 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/plugin-intent-KETLP7UL.mjs +23 -0
- package/dist/lib/node-esm/plugin-intent-KETLP7UL.mjs.map +7 -0
- package/dist/lib/node-esm/plugin-settings-37UVWF2V.mjs +12 -0
- package/dist/lib/node-esm/plugin-settings-37UVWF2V.mjs.map +7 -0
- package/dist/lib/node-esm/plugin-surface-QXQRR534.mjs +25 -0
- package/dist/lib/node-esm/plugin-surface-QXQRR534.mjs.map +7 -0
- package/dist/types/src/App.d.ts +5 -5
- package/dist/types/src/App.d.ts.map +1 -1
- package/dist/types/src/plugins/common/file.d.ts +1 -1
- package/dist/types/src/plugins/common/file.d.ts.map +1 -1
- package/dist/types/src/plugins/common/graph.d.ts +1 -1
- package/dist/types/src/plugins/common/graph.d.ts.map +1 -1
- package/dist/types/src/plugins/common/index.d.ts +0 -1
- package/dist/types/src/plugins/common/index.d.ts.map +1 -1
- package/dist/types/src/plugins/common/layout.d.ts +6 -6
- package/dist/types/src/plugins/common/layout.d.ts.map +1 -1
- package/dist/types/src/plugins/common/metadata.d.ts +1 -1
- package/dist/types/src/plugins/common/metadata.d.ts.map +1 -1
- package/dist/types/src/plugins/common/navigation.d.ts +9 -20
- package/dist/types/src/plugins/common/navigation.d.ts.map +1 -1
- package/dist/types/src/plugins/common/translations.d.ts +1 -1
- package/dist/types/src/plugins/common/translations.d.ts.map +1 -1
- package/dist/types/src/plugins/helpers.d.ts +20 -5
- package/dist/types/src/plugins/helpers.d.ts.map +1 -1
- package/dist/types/src/plugins/index.d.ts +4 -3
- package/dist/types/src/plugins/index.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-host/HostPlugin.d.ts +21 -0
- package/dist/types/src/plugins/plugin-host/HostPlugin.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-host/PluginContainer.d.ts +14 -0
- package/dist/types/src/plugins/plugin-host/PluginContainer.d.ts.map +1 -0
- package/dist/types/src/plugins/{PluginHost → plugin-host}/PluginContext.d.ts +4 -4
- package/dist/types/src/plugins/plugin-host/PluginContext.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-host/index.d.ts +4 -0
- package/dist/types/src/plugins/plugin-host/index.d.ts.map +1 -0
- package/dist/types/src/plugins/{PluginHost → plugin-host}/plugin.d.ts +41 -83
- package/dist/types/src/plugins/plugin-host/plugin.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-host/plugin.test.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-intent/IntentContext.d.ts.map +1 -0
- package/dist/types/src/plugins/{IntentPlugin/plugin.d.ts → plugin-intent/IntentPlugin.d.ts} +3 -4
- package/dist/types/src/plugins/plugin-intent/IntentPlugin.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-intent/helpers.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-intent/index.d.ts +6 -0
- package/dist/types/src/plugins/plugin-intent/index.d.ts.map +1 -0
- package/dist/types/src/plugins/{IntentPlugin → plugin-intent}/intent.d.ts +1 -1
- package/dist/types/src/plugins/plugin-intent/intent.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-intent/meta.d.ts.map +1 -0
- package/dist/types/src/plugins/{IntentPlugin → plugin-intent}/provides.d.ts +2 -2
- package/dist/types/src/plugins/plugin-intent/provides.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-settings/SettingsPlugin.d.ts +4 -0
- package/dist/types/src/plugins/plugin-settings/SettingsPlugin.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-settings/index.d.ts +4 -0
- package/dist/types/src/plugins/plugin-settings/index.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-settings/meta.d.ts +5 -0
- package/dist/types/src/plugins/plugin-settings/meta.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-settings/provides.d.ts +13 -0
- package/dist/types/src/plugins/plugin-settings/provides.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-surface/ErrorBoundary.d.ts.map +1 -0
- package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/Surface.d.ts +6 -2
- package/dist/types/src/plugins/plugin-surface/Surface.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-surface/SurfacePlugin.d.ts +7 -0
- package/dist/types/src/plugins/plugin-surface/SurfacePlugin.d.ts.map +1 -0
- package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/SurfaceRootContext.d.ts +15 -2
- package/dist/types/src/plugins/plugin-surface/SurfaceRootContext.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-surface/helpers.d.ts.map +1 -0
- package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/index.d.ts +2 -0
- package/dist/types/src/plugins/plugin-surface/index.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-surface/meta.d.ts.map +1 -0
- package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/provides.d.ts +1 -1
- package/dist/types/src/plugins/plugin-surface/provides.d.ts.map +1 -0
- package/package.json +16 -14
- package/project.json +3 -8
- package/src/App.tsx +18 -16
- package/src/plugins/common/file.ts +1 -1
- package/src/plugins/common/graph.ts +1 -1
- package/src/plugins/common/index.ts +0 -1
- package/src/plugins/common/layout.ts +6 -3
- package/src/plugins/common/metadata.ts +1 -1
- package/src/plugins/common/navigation.ts +10 -15
- package/src/plugins/common/translations.ts +2 -8
- package/src/plugins/helpers.ts +55 -11
- package/src/plugins/index.ts +4 -3
- package/src/plugins/plugin-host/HostPlugin.tsx +96 -0
- package/src/plugins/plugin-host/PluginContainer.tsx +120 -0
- package/src/plugins/{PluginHost → plugin-host}/PluginContext.tsx +9 -14
- package/src/plugins/{PluginHost → plugin-host}/index.ts +2 -1
- package/src/plugins/{PluginHost → plugin-host}/plugin.test.ts +1 -2
- package/src/plugins/{PluginHost → plugin-host}/plugin.ts +50 -52
- package/src/plugins/{IntentPlugin/plugin.tsx → plugin-intent/IntentPlugin.tsx} +3 -6
- package/src/plugins/{IntentPlugin → plugin-intent}/index.ts +4 -0
- package/src/plugins/{IntentPlugin → plugin-intent}/intent.ts +1 -1
- package/src/plugins/{IntentPlugin → plugin-intent}/provides.ts +5 -2
- package/src/plugins/plugin-settings/SettingsPlugin.tsx +22 -0
- package/src/plugins/plugin-settings/index.ts +9 -0
- package/src/plugins/plugin-settings/meta.ts +9 -0
- package/src/plugins/plugin-settings/provides.ts +29 -0
- package/src/plugins/{SurfacePlugin → plugin-surface}/Surface.tsx +74 -40
- package/src/plugins/{SurfacePlugin/plugin.tsx → plugin-surface/SurfacePlugin.tsx} +3 -5
- package/src/plugins/{SurfacePlugin → plugin-surface}/SurfaceRootContext.tsx +21 -4
- package/src/plugins/{SurfacePlugin → plugin-surface}/index.ts +4 -0
- package/src/plugins/{SurfacePlugin → plugin-surface}/provides.ts +2 -1
- package/tsconfig.json +2 -30
- package/vitest.config.ts +9 -0
- package/dist/lib/browser/chunk-J45KR4DI.mjs +0 -52
- package/dist/lib/browser/chunk-J45KR4DI.mjs.map +0 -7
- package/dist/lib/browser/chunk-S5CI6EUQ.mjs +0 -20
- package/dist/lib/browser/chunk-S5CI6EUQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-YYV26N3W.mjs +0 -26
- package/dist/lib/browser/chunk-YYV26N3W.mjs.map +0 -7
- package/dist/lib/browser/plugin-K3KCPCTJ.mjs +0 -39
- package/dist/lib/browser/plugin-K3KCPCTJ.mjs.map +0 -7
- package/dist/lib/browser/plugin-MM66VRCO.mjs.map +0 -7
- package/dist/lib/node/chunk-62W6CMGM.cjs.map +0 -7
- package/dist/lib/node/chunk-DFST5IG5.cjs +0 -77
- package/dist/lib/node/chunk-DFST5IG5.cjs.map +0 -7
- package/dist/lib/node/chunk-P5GRB4XF.cjs.map +0 -7
- package/dist/lib/node/plugin-QV7ESETI.cjs.map +0 -7
- package/dist/lib/node/plugin-RUJ5PEXB.cjs +0 -61
- package/dist/lib/node/plugin-RUJ5PEXB.cjs.map +0 -7
- package/dist/types/src/plugins/IntentPlugin/IntentContext.d.ts.map +0 -1
- package/dist/types/src/plugins/IntentPlugin/helpers.d.ts.map +0 -1
- package/dist/types/src/plugins/IntentPlugin/index.d.ts +0 -4
- package/dist/types/src/plugins/IntentPlugin/index.d.ts.map +0 -1
- package/dist/types/src/plugins/IntentPlugin/intent.d.ts.map +0 -1
- package/dist/types/src/plugins/IntentPlugin/meta.d.ts.map +0 -1
- package/dist/types/src/plugins/IntentPlugin/plugin.d.ts.map +0 -1
- package/dist/types/src/plugins/IntentPlugin/provides.d.ts.map +0 -1
- package/dist/types/src/plugins/PluginHost/PluginContext.d.ts.map +0 -1
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +0 -25
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +0 -1
- package/dist/types/src/plugins/PluginHost/index.d.ts +0 -4
- package/dist/types/src/plugins/PluginHost/index.d.ts.map +0 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +0 -1
- package/dist/types/src/plugins/PluginHost/plugin.test.d.ts.map +0 -1
- package/dist/types/src/plugins/SurfacePlugin/ErrorBoundary.d.ts.map +0 -1
- package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts.map +0 -1
- package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts.map +0 -1
- package/dist/types/src/plugins/SurfacePlugin/helpers.d.ts.map +0 -1
- package/dist/types/src/plugins/SurfacePlugin/index.d.ts.map +0 -1
- package/dist/types/src/plugins/SurfacePlugin/meta.d.ts.map +0 -1
- package/dist/types/src/plugins/SurfacePlugin/plugin.d.ts +0 -8
- package/dist/types/src/plugins/SurfacePlugin/plugin.d.ts.map +0 -1
- package/dist/types/src/plugins/SurfacePlugin/provides.d.ts.map +0 -1
- package/dist/types/src/plugins/common/settings.d.ts +0 -9
- package/dist/types/src/plugins/common/settings.d.ts.map +0 -1
- package/src/plugins/PluginHost/PluginHost.tsx +0 -198
- package/src/plugins/common/settings.ts +0 -22
- /package/dist/types/src/plugins/{PluginHost → plugin-host}/plugin.test.d.ts +0 -0
- /package/dist/types/src/plugins/{IntentPlugin → plugin-intent}/IntentContext.d.ts +0 -0
- /package/dist/types/src/plugins/{IntentPlugin → plugin-intent}/helpers.d.ts +0 -0
- /package/dist/types/src/plugins/{IntentPlugin → plugin-intent}/meta.d.ts +0 -0
- /package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/ErrorBoundary.d.ts +0 -0
- /package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/helpers.d.ts +0 -0
- /package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/meta.d.ts +0 -0
- /package/src/plugins/{IntentPlugin → plugin-intent}/IntentContext.tsx +0 -0
- /package/src/plugins/{IntentPlugin → plugin-intent}/helpers.ts +0 -0
- /package/src/plugins/{IntentPlugin → plugin-intent}/meta.ts +0 -0
- /package/src/plugins/{SurfacePlugin → plugin-surface}/ErrorBoundary.tsx +0 -0
- /package/src/plugins/{SurfacePlugin → plugin-surface}/helpers.ts +0 -0
- /package/src/plugins/{SurfacePlugin → plugin-surface}/meta.ts +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// packages/sdk/app-framework/src/plugins/helpers.ts
|
|
2
|
+
import { Context } from "@dxos/context";
|
|
3
|
+
import { raise } from "@dxos/debug";
|
|
4
|
+
import { invariant } from "@dxos/invariant";
|
|
5
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/helpers.ts";
|
|
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
|
+
var PluginContext = class {
|
|
15
|
+
constructor() {
|
|
16
|
+
// TODO(burdon): Use Resource (@dima)?
|
|
17
|
+
this.ctx = new Context(void 0, {
|
|
18
|
+
F: __dxlog_file,
|
|
19
|
+
L: 50
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
init(plugins) {
|
|
23
|
+
this._plugins = plugins;
|
|
24
|
+
}
|
|
25
|
+
getPlugin(id) {
|
|
26
|
+
invariant(this._plugins, void 0, {
|
|
27
|
+
F: __dxlog_file,
|
|
28
|
+
L: 59,
|
|
29
|
+
S: this,
|
|
30
|
+
A: [
|
|
31
|
+
"this._plugins",
|
|
32
|
+
""
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
return getPlugin(this._plugins, id);
|
|
36
|
+
}
|
|
37
|
+
resolvePlugin(resolver, required = false) {
|
|
38
|
+
invariant(this._plugins, "context not initialized", {
|
|
39
|
+
F: __dxlog_file,
|
|
40
|
+
L: 65,
|
|
41
|
+
S: this,
|
|
42
|
+
A: [
|
|
43
|
+
"this._plugins",
|
|
44
|
+
"'context not initialized'"
|
|
45
|
+
]
|
|
46
|
+
});
|
|
47
|
+
const plugin = resolvePlugin(this._plugins, resolver);
|
|
48
|
+
if (required && !plugin) {
|
|
49
|
+
throw new Error("Plugin not found.");
|
|
50
|
+
}
|
|
51
|
+
return plugin;
|
|
52
|
+
}
|
|
53
|
+
onDispose(cb) {
|
|
54
|
+
this.ctx.onDispose(cb);
|
|
55
|
+
}
|
|
56
|
+
dispose() {
|
|
57
|
+
void this.ctx.dispose();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var definePlugin = (cb) => {
|
|
61
|
+
const context = new PluginContext();
|
|
62
|
+
return () => cb(context);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
findPlugin,
|
|
67
|
+
getPlugin,
|
|
68
|
+
filterPlugins,
|
|
69
|
+
resolvePlugin,
|
|
70
|
+
definePlugin
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=chunk-3E7RY3CE.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/helpers.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Context, type DisposeCallback } from '@dxos/context';\nimport { raise } from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\n\nimport { type Plugin, type PluginDefinition } from './plugin-host';\n\n/**\n * Resolvers allow different instances of plugins to provide a particular capability.\n */\nexport type PluginResolver<T> = (plugin: Plugin) => Plugin<T> | undefined;\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>(plugins: Plugin[], predicate: PluginResolver<T>): Plugin<T>[] =>\n 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>(plugins: Plugin[], predicate: PluginResolver<T>): Plugin<T> | undefined =>\n filterPlugins(plugins, predicate)[0];\n\nclass PluginContext {\n // TODO(burdon): Use Resource (@dima)?\n public readonly ctx = new Context();\n\n private _plugins?: Plugin[];\n\n init(plugins: Plugin[]) {\n this._plugins = plugins;\n }\n\n getPlugin<T>(id: string): Plugin<T> {\n invariant(this._plugins);\n return getPlugin(this._plugins, id);\n }\n\n resolvePlugin<T>(resolver: PluginResolver<T>): Plugin<T>;\n resolvePlugin<T>(resolver: PluginResolver<T>, required = false): Plugin<T> | undefined {\n invariant(this._plugins, 'context not initialized');\n const plugin = resolvePlugin(this._plugins, resolver);\n if (required && !plugin) {\n // TODO(burdon): Resolver should have a name.\n throw new Error('Plugin not found.');\n }\n\n return plugin;\n }\n\n onDispose(cb: DisposeCallback) {\n this.ctx.onDispose(cb);\n }\n\n dispose() {\n void this.ctx.dispose();\n }\n}\n\n/**\n * Plugin helper with dependency injection and life-cycle support.\n */\nexport const definePlugin = <Provides>(\n cb: (context: PluginContext) => PluginDefinition<Provides>,\n): (() => PluginDefinition<Provides>) => {\n const context = new PluginContext();\n return () => cb(context);\n};\n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1BF,OAAAA;AAEA,QAAMG,UAAU,IAAIV,cAAAA;AACpB,SAAO,MAAMO,GAAGG,OAAAA;AAClB;",
|
|
6
|
+
"names": ["Context", "raise", "invariant", "findPlugin", "plugins", "id", "find", "plugin", "meta", "shortId", "getPlugin", "Error", "filterPlugins", "predicate", "map", "filter", "resolvePlugin", "PluginContext", "ctx", "init", "_plugins", "resolver", "required", "onDispose", "cb", "dispose", "definePlugin", "context"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// packages/sdk/app-framework/src/plugins/plugin-settings/SettingsPlugin.tsx
|
|
2
|
+
import { RootSettingsStore } from "@dxos/local-storage";
|
|
3
|
+
|
|
4
|
+
// packages/sdk/app-framework/src/plugins/plugin-settings/meta.ts
|
|
5
|
+
var SettingsMeta = {
|
|
6
|
+
id: "dxos.org/plugin/settings"
|
|
7
|
+
};
|
|
8
|
+
var meta_default = SettingsMeta;
|
|
9
|
+
|
|
10
|
+
// packages/sdk/app-framework/src/plugins/plugin-settings/SettingsPlugin.tsx
|
|
11
|
+
var SettingsPlugin = () => {
|
|
12
|
+
const settingsStore = new RootSettingsStore();
|
|
13
|
+
return {
|
|
14
|
+
meta: meta_default,
|
|
15
|
+
provides: {
|
|
16
|
+
settingsStore
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// packages/sdk/app-framework/src/plugins/plugin-settings/provides.ts
|
|
22
|
+
var parseSettingsPlugin = (plugin) => {
|
|
23
|
+
return typeof plugin.provides.settingsStore === "object" ? plugin : void 0;
|
|
24
|
+
};
|
|
25
|
+
var SETTINGS_PLUGIN = "dxos.org/plugin/settings";
|
|
26
|
+
var SETTINGS_ACTION = `${SETTINGS_PLUGIN}/action`;
|
|
27
|
+
var SettingsAction;
|
|
28
|
+
(function(SettingsAction2) {
|
|
29
|
+
SettingsAction2[SettingsAction2["OPEN"] = `${SETTINGS_ACTION}/open`] = "OPEN";
|
|
30
|
+
})(SettingsAction || (SettingsAction = {}));
|
|
31
|
+
|
|
32
|
+
// packages/sdk/app-framework/src/plugins/plugin-settings/index.ts
|
|
33
|
+
var plugin_settings_default = SettingsPlugin;
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
meta_default,
|
|
37
|
+
parseSettingsPlugin,
|
|
38
|
+
SettingsAction,
|
|
39
|
+
plugin_settings_default
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=chunk-653Y45CL.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/plugin-settings/SettingsPlugin.tsx", "../../../src/plugins/plugin-settings/meta.ts", "../../../src/plugins/plugin-settings/provides.ts", "../../../src/plugins/plugin-settings/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { RootSettingsStore } from '@dxos/local-storage';\n\nimport SettingsMeta from './meta';\nimport { type SettingsPluginProvides } from './provides';\nimport { type PluginDefinition } from '../plugin-host';\n\nexport const SettingsPlugin = (): PluginDefinition<SettingsPluginProvides> => {\n // Global settings singleton.\n // TODO(burdon): Make settings storage extensible so that other plugins can decide the persistence of them.\n const settingsStore = new RootSettingsStore();\n\n return {\n meta: SettingsMeta,\n provides: {\n settingsStore,\n },\n };\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst SettingsMeta = {\n id: 'dxos.org/plugin/settings',\n};\n\nexport default SettingsMeta;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type SettingsStoreFactory, type SettingsValue } from '@dxos/local-storage';\n\nimport { type Plugin } from '../plugin-host';\n\nexport type SettingsProvides<T extends SettingsValue> = {\n settings: T;\n};\n\nexport type SettingsPluginProvides = {\n settingsStore: SettingsStoreFactory;\n};\n\nexport const parseSettingsPlugin = (plugin: Plugin) => {\n return typeof (plugin.provides as any).settingsStore === 'object'\n ? (plugin as Plugin<SettingsPluginProvides>)\n : undefined;\n};\n\nconst SETTINGS_PLUGIN = 'dxos.org/plugin/settings';\n\nconst SETTINGS_ACTION = `${SETTINGS_PLUGIN}/action`;\n\nexport enum SettingsAction {\n OPEN = `${SETTINGS_ACTION}/open`,\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { SettingsPlugin } from './SettingsPlugin';\n\nexport * from './provides';\n\nexport default SettingsPlugin;\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,yBAAyB;;;ACAlC,IAAMC,eAAe;EACnBC,IAAI;AACN;AAEA,IAAA,eAAeD;;;ADER,IAAME,iBAAiB,MAAA;AAG5B,QAAMC,gBAAgB,IAAIC,kBAAAA;AAE1B,SAAO;IACLC,MAAMC;IACNC,UAAU;MACRJ;IACF;EACF;AACF;;;AELO,IAAMK,sBAAsB,CAACC,WAAAA;AAClC,SAAO,OAAQA,OAAOC,SAAiBC,kBAAkB,WACpDF,SACDG;AACN;AAEA,IAAMC,kBAAkB;AAExB,IAAMC,kBAAkB,GAAGD,eAAAA;;UAEfE,iBAAAA;4CACH,GAAGD,eAAAA,OAAsB,IAAA;GADtBC,mBAAAA,iBAAAA,CAAAA,EAAAA;;;AClBZ,IAAA,0BAAeC;",
|
|
6
|
+
"names": ["RootSettingsStore", "SettingsMeta", "id", "SettingsPlugin", "settingsStore", "RootSettingsStore", "meta", "SettingsMeta", "provides", "parseSettingsPlugin", "plugin", "provides", "settingsStore", "undefined", "SETTINGS_PLUGIN", "SETTINGS_ACTION", "SettingsAction", "SettingsPlugin"]
|
|
7
|
+
}
|
|
@@ -1,24 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IntentAction,
|
|
3
|
-
IntentProvider,
|
|
4
|
-
meta_default,
|
|
5
|
-
parseIntentResolverPlugin
|
|
6
|
-
} from "./chunk-J45KR4DI.mjs";
|
|
7
1
|
import {
|
|
8
2
|
filterPlugins,
|
|
9
3
|
findPlugin
|
|
10
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-3E7RY3CE.mjs";
|
|
11
5
|
|
|
12
|
-
// packages/sdk/app-framework/src/plugins/IntentPlugin
|
|
6
|
+
// packages/sdk/app-framework/src/plugins/plugin-intent/IntentPlugin.tsx
|
|
13
7
|
import React from "react";
|
|
14
8
|
import { create } from "@dxos/echo-schema";
|
|
15
9
|
import { log } from "@dxos/log";
|
|
16
10
|
|
|
17
|
-
// packages/sdk/app-framework/src/plugins/
|
|
11
|
+
// packages/sdk/app-framework/src/plugins/plugin-intent/IntentContext.tsx
|
|
12
|
+
import { createContext, useContext } from "react";
|
|
13
|
+
import { useEffect } from "react";
|
|
14
|
+
var IntentContext = /* @__PURE__ */ createContext({
|
|
15
|
+
dispatch: async () => ({}),
|
|
16
|
+
undo: async () => ({}),
|
|
17
|
+
history: [],
|
|
18
|
+
registerResolver: () => () => {
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
var useIntent = () => useContext(IntentContext);
|
|
22
|
+
var useIntentDispatcher = () => {
|
|
23
|
+
const { dispatch } = useIntent();
|
|
24
|
+
return dispatch;
|
|
25
|
+
};
|
|
26
|
+
var useIntentResolver = (plugin, resolver) => {
|
|
27
|
+
const { registerResolver } = useIntent();
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
return registerResolver(plugin, resolver);
|
|
30
|
+
}, [
|
|
31
|
+
plugin,
|
|
32
|
+
resolver
|
|
33
|
+
]);
|
|
34
|
+
};
|
|
35
|
+
var IntentProvider = IntentContext.Provider;
|
|
36
|
+
|
|
37
|
+
// packages/sdk/app-framework/src/plugins/plugin-intent/helpers.ts
|
|
18
38
|
var isUndoable = (chain) => chain.length > 0 && chain.every(({ result }) => result.undoable);
|
|
19
39
|
|
|
20
|
-
// packages/sdk/app-framework/src/plugins/
|
|
21
|
-
var
|
|
40
|
+
// packages/sdk/app-framework/src/plugins/plugin-intent/meta.ts
|
|
41
|
+
var IntentMeta = {
|
|
42
|
+
id: "dxos.org/plugin/intent"
|
|
43
|
+
};
|
|
44
|
+
var meta_default = IntentMeta;
|
|
45
|
+
|
|
46
|
+
// packages/sdk/app-framework/src/plugins/plugin-intent/provides.ts
|
|
47
|
+
var parseIntentPlugin = (plugin) => plugin.provides.intent?.dispatch ? plugin : void 0;
|
|
48
|
+
var parseIntentResolverPlugin = (plugin) => plugin.provides.intent?.resolver ? plugin : void 0;
|
|
49
|
+
var INTENT_PLUGIN = "dxos.org/plugin/intent";
|
|
50
|
+
var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
|
|
51
|
+
var IntentAction;
|
|
52
|
+
(function(IntentAction2) {
|
|
53
|
+
IntentAction2[IntentAction2["SHOW_UNDO"] = `${INTENT_ACTION}/show-undo`] = "SHOW_UNDO";
|
|
54
|
+
})(IntentAction || (IntentAction = {}));
|
|
55
|
+
|
|
56
|
+
// packages/sdk/app-framework/src/plugins/plugin-intent/IntentPlugin.tsx
|
|
57
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/plugin-intent/IntentPlugin.tsx";
|
|
22
58
|
var EXECUTION_LIMIT = 1e3;
|
|
23
59
|
var HISTORY_LIMIT = 100;
|
|
24
60
|
var IntentPlugin = () => {
|
|
@@ -46,15 +82,14 @@ var IntentPlugin = () => {
|
|
|
46
82
|
if (intent.plugin) {
|
|
47
83
|
for (const entry of dynamicResolvers) {
|
|
48
84
|
if (entry.plugin === intent.plugin) {
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
return
|
|
85
|
+
const result = await entry.resolver(intent, plugins);
|
|
86
|
+
if (result) {
|
|
87
|
+
return result;
|
|
52
88
|
}
|
|
53
89
|
}
|
|
54
90
|
}
|
|
55
91
|
const plugin = findPlugin(plugins, intent.plugin);
|
|
56
|
-
|
|
57
|
-
return result;
|
|
92
|
+
return plugin?.provides.intent.resolver(intent, plugins);
|
|
58
93
|
}
|
|
59
94
|
for (const entry of dynamicResolvers) {
|
|
60
95
|
const result = await entry.resolver(intent, plugins);
|
|
@@ -71,7 +106,7 @@ var IntentPlugin = () => {
|
|
|
71
106
|
if (import.meta?.env?.DEV) {
|
|
72
107
|
log.warn("No plugin found to handle intent", intent, {
|
|
73
108
|
F: __dxlog_file,
|
|
74
|
-
L:
|
|
109
|
+
L: 78,
|
|
75
110
|
S: void 0,
|
|
76
111
|
C: (f, a) => f(...a)
|
|
77
112
|
});
|
|
@@ -160,8 +195,19 @@ var IntentPlugin = () => {
|
|
|
160
195
|
}
|
|
161
196
|
};
|
|
162
197
|
};
|
|
163
|
-
|
|
198
|
+
|
|
199
|
+
// packages/sdk/app-framework/src/plugins/plugin-intent/index.ts
|
|
200
|
+
var plugin_intent_default = IntentPlugin;
|
|
201
|
+
|
|
164
202
|
export {
|
|
165
|
-
|
|
203
|
+
useIntent,
|
|
204
|
+
useIntentDispatcher,
|
|
205
|
+
useIntentResolver,
|
|
206
|
+
IntentProvider,
|
|
207
|
+
meta_default,
|
|
208
|
+
parseIntentPlugin,
|
|
209
|
+
parseIntentResolverPlugin,
|
|
210
|
+
IntentAction,
|
|
211
|
+
plugin_intent_default
|
|
166
212
|
};
|
|
167
|
-
//# sourceMappingURL=
|
|
213
|
+
//# sourceMappingURL=chunk-CDLQO5K2.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/plugin-intent/IntentPlugin.tsx", "../../../src/plugins/plugin-intent/IntentContext.tsx", "../../../src/plugins/plugin-intent/helpers.ts", "../../../src/plugins/plugin-intent/meta.ts", "../../../src/plugins/plugin-intent/provides.ts", "../../../src/plugins/plugin-intent/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { create } from '@dxos/echo-schema';\nimport { log } from '@dxos/log';\n\nimport { type IntentContext, IntentProvider, type IntentExecution } from './IntentContext';\nimport { isUndoable } from './helpers';\nimport type { Intent, IntentResolver } from './intent';\nimport IntentMeta from './meta';\nimport {\n type IntentPluginProvides,\n type IntentResolverProvides,\n parseIntentResolverPlugin,\n IntentAction,\n} from './provides';\nimport { filterPlugins, findPlugin } from '../helpers';\nimport { type PluginDefinition } from '../plugin-host';\n\nconst EXECUTION_LIMIT = 1000;\nconst HISTORY_LIMIT = 100;\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 */\nexport const IntentPlugin = (): PluginDefinition<IntentPluginProvides> => {\n const state = create<IntentContext>({\n dispatch: async () => ({}),\n undo: async () => ({}),\n history: [],\n registerResolver: () => () => {},\n });\n\n const dynamicResolvers = new Set<{ plugin: string; resolver: IntentResolver }>();\n\n return {\n meta: IntentMeta,\n ready: async (plugins) => {\n // Dispatch intent to associated plugin.\n const dispatch = async (intent: Intent) => {\n log('dispatch', { action: intent.action, intent });\n if (intent.plugin) {\n for (const entry of dynamicResolvers) {\n if (entry.plugin === intent.plugin) {\n const result = await entry.resolver(intent, plugins);\n if (result) {\n return result;\n }\n }\n }\n\n const plugin = findPlugin<IntentResolverProvides>(plugins, intent.plugin);\n return plugin?.provides.intent.resolver(intent, plugins);\n }\n\n for (const entry of dynamicResolvers) {\n const result = await entry.resolver(intent, plugins);\n if (result) {\n return result;\n }\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 // https://vitejs.dev/guide/env-and-mode#env-variables\n // TODO(wittjosiah): How to handle this more generically?\n if (import.meta?.env?.DEV) {\n log.warn('No plugin found to handle intent', intent);\n }\n };\n\n // Sequentially dispatch array of invents.\n const dispatchChain = async (intentOrArray: Intent | Intent[], depth = 0) => {\n if (depth > EXECUTION_LIMIT) {\n return {\n error: new Error(\n `Intent execution limit exceeded (${EXECUTION_LIMIT} iterations). This is likely due to an infinite loop within intent resolvers.`,\n ),\n };\n }\n\n const executionResults: IntentExecution[] = [];\n const chain = Array.isArray(intentOrArray) ? intentOrArray : [intentOrArray];\n for (const intent of chain) {\n const { result: prevResult } = executionResults.at(-1) ?? {};\n const data = intent.data ? { result: prevResult?.data, ...intent.data } : prevResult?.data;\n const result = await dispatch({ ...intent, data });\n\n if (!result || result?.error) {\n break;\n }\n\n executionResults.push({ intent, result });\n\n // TODO(wittjosiah): How does undo work with returned intents?\n result?.intents?.forEach((intents) => {\n void dispatchChain(intents, depth + 1);\n });\n }\n\n state.history.push(executionResults);\n if (state.history.length > HISTORY_LIMIT) {\n state.history.splice(0, state.history.length - HISTORY_LIMIT);\n }\n\n if (isUndoable(executionResults)) {\n void dispatch({ action: IntentAction.SHOW_UNDO, data: { results: executionResults } });\n }\n\n return executionResults.at(-1)?.result;\n };\n\n const undo = async () => {\n const last = state.history.findLastIndex(isUndoable);\n const chain =\n last !== -1 &&\n state.history[last]?.map(({ intent, result }): Intent => {\n const data = result.undoable?.data ? { ...intent.data, ...result.undoable.data } : intent.data;\n return { ...intent, data, undo: true };\n });\n if (chain) {\n const result = await dispatchChain(chain);\n state.history = state.history.filter((_, index) => index !== last);\n return result;\n }\n };\n\n state.dispatch = dispatchChain;\n state.undo = undo;\n state.registerResolver = (plugin, resolver) => {\n const entry = { plugin, resolver };\n dynamicResolvers.add(entry);\n return () => dynamicResolvers.delete(entry);\n };\n },\n provides: {\n intent: state,\n context: ({ children }) => <IntentProvider value={state}>{children}</IntentProvider>,\n },\n };\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 2024 DXOS.org\n//\n\nimport { type IntentExecution } from './IntentContext';\n\n/**\n * Check if the chain of intents is undoable.\n */\nexport const isUndoable = (chain: IntentExecution[]): boolean =>\n chain.length > 0 && chain.every(({ result }) => result.undoable);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst IntentMeta = {\n id: 'dxos.org/plugin/intent',\n};\n\nexport default IntentMeta;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type IntentContext } from './IntentContext';\nimport { type IntentResolver } from './intent';\nimport { type Plugin } from '../plugin-host';\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_PLUGIN = 'dxos.org/plugin/intent';\n\nconst INTENT_ACTION = `${INTENT_PLUGIN}/action`;\n\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 { IntentPlugin } from './IntentPlugin';\n\nexport * from './intent';\nexport * from './provides';\n\nexport * from './IntentContext';\n\nexport default IntentPlugin;\n"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,OAAOA,WAAW;AAElB,SAASC,cAAc;AACvB,SAASC,WAAW;;;ACHpB,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;;;ACvC9D,IAAMC,aAAa,CAACC,UACzBA,MAAMC,SAAS,KAAKD,MAAME,MAAM,CAAC,EAAEC,OAAM,MAAOA,OAAOC,QAAQ;;;ACNjE,IAAMC,aAAa;EACjBC,IAAI;AACN;AAEA,IAAA,eAAeD;;;ACUR,IAAME,oBAAoB,CAACC,WAC/BA,OAAOC,SAAiBC,QAAQC,WAAYH,SAA0CI;AAElF,IAAMC,4BAA4B,CAACL,WACvCA,OAAOC,SAAiBC,QAAQI,WAAYN,SAA4CI;AAM3F,IAAMG,gBAAgB;AAEtB,IAAMC,gBAAgB,GAAGD,aAAAA;;UAEbE,eAAAA;AAGT,EAAAA,cAAAA,cAAA,WAAA,IACW,GAAGD,aAAAA,YAAyB,IAAA;GAJ9BC,iBAAAA,eAAAA,CAAAA,EAA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b;UAAK,IAAIzB,OAAOyB;AAC1F,iBAAO;YAAE,GAAGzB;YAAQyB;YAAMlC,MAAM;UAAK;QACvC,CAAA;AACF,YAAI6B,OAAO;AACT,gBAAMf,SAAS,MAAMS,cAAcM,KAAAA;AACnChC,gBAAMI,UAAUJ,MAAMI,QAAQ+C,OAAO,CAACC,GAAGC,UAAUA,UAAUN,IAAAA;AAC7D,iBAAO9B;QACT;MACF;AAEAjB,YAAME,WAAWwB;AACjB1B,YAAMG,OAAOA;AACbH,YAAMK,mBAAmB,CAACU,QAAQG,aAAAA;AAChC,cAAMF,QAAQ;UAAED;UAAQG;QAAS;AACjCZ,yBAAiBgD,IAAItC,KAAAA;AACrB,eAAO,MAAMV,iBAAiBiD,OAAOvC,KAAAA;MACvC;IACF;IACAI,UAAU;MACRR,QAAQZ;MACRwD,SAAS,CAAC,EAAEC,SAAQ,MAAO,sBAAA,cAACC,gBAAAA;QAAeC,OAAO3D;SAAQyD,QAAAA;IAC5D;EACF;AACF;;;AK3IA,IAAA,wBAAeG;",
|
|
6
|
+
"names": ["React", "create", "log", "createContext", "useContext", "useEffect", "IntentContext", "createContext", "dispatch", "undo", "history", "registerResolver", "useIntent", "useContext", "useIntentDispatcher", "useIntentResolver", "plugin", "resolver", "useEffect", "IntentProvider", "Provider", "isUndoable", "chain", "length", "every", "result", "undoable", "IntentMeta", "id", "parseIntentPlugin", "plugin", "provides", "intent", "dispatch", "undefined", "parseIntentResolverPlugin", "resolver", "INTENT_PLUGIN", "INTENT_ACTION", "IntentAction", "EXECUTION_LIMIT", "HISTORY_LIMIT", "IntentPlugin", "state", "create", "dispatch", "undo", "history", "registerResolver", "dynamicResolvers", "Set", "meta", "IntentMeta", "ready", "plugins", "intent", "log", "action", "plugin", "entry", "result", "resolver", "findPlugin", "provides", "filterPlugins", "parseIntentResolverPlugin", "env", "DEV", "warn", "dispatchChain", "intentOrArray", "depth", "error", "Error", "executionResults", "chain", "Array", "isArray", "prevResult", "at", "data", "push", "intents", "forEach", "length", "splice", "isUndoable", "IntentAction", "SHOW_UNDO", "results", "last", "findLastIndex", "map", "undoable", "filter", "_", "index", "add", "delete", "context", "children", "IntentProvider", "value", "IntentPlugin"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import {
|
|
2
|
+
filterPlugins
|
|
3
|
+
} from "./chunk-3E7RY3CE.mjs";
|
|
4
|
+
|
|
5
|
+
// packages/sdk/app-framework/src/plugins/plugin-surface/SurfacePlugin.tsx
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { create } from "@dxos/echo-schema";
|
|
8
|
+
|
|
9
|
+
// packages/sdk/app-framework/src/plugins/plugin-surface/SurfaceRootContext.tsx
|
|
10
|
+
import { createContext, useContext } from "react";
|
|
11
|
+
import { raise } from "@dxos/debug";
|
|
12
|
+
var SurfaceRootContext = /* @__PURE__ */ createContext(void 0);
|
|
13
|
+
var useSurfaceRoot = () => useContext(SurfaceRootContext) ?? raise(new Error("Missing SurfaceRootContext"));
|
|
14
|
+
var SurfaceProvider = SurfaceRootContext.Provider;
|
|
15
|
+
|
|
16
|
+
// packages/sdk/app-framework/src/plugins/plugin-surface/meta.ts
|
|
17
|
+
var SurfaceMeta = {
|
|
18
|
+
id: "dxos.org/plugin/surface"
|
|
19
|
+
};
|
|
20
|
+
var meta_default = SurfaceMeta;
|
|
21
|
+
|
|
22
|
+
// packages/sdk/app-framework/src/plugins/plugin-surface/provides.ts
|
|
23
|
+
var parseRootSurfacePlugin = (plugin) => plugin?.provides?.surface?.components ? plugin : void 0;
|
|
24
|
+
var parseSurfacePlugin = (plugin) => plugin?.provides?.surface?.component ? plugin : void 0;
|
|
25
|
+
|
|
26
|
+
// packages/sdk/app-framework/src/plugins/plugin-surface/SurfacePlugin.tsx
|
|
27
|
+
var SurfacePlugin = () => {
|
|
28
|
+
const state = create({
|
|
29
|
+
components: {},
|
|
30
|
+
debugInfo: /* @__PURE__ */ new Map()
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
meta: meta_default,
|
|
34
|
+
ready: async (plugins) => {
|
|
35
|
+
state.components = filterPlugins(plugins, parseSurfacePlugin).reduce((acc, plugin) => {
|
|
36
|
+
return {
|
|
37
|
+
...acc,
|
|
38
|
+
[plugin.meta.id]: plugin.provides.surface.component
|
|
39
|
+
};
|
|
40
|
+
}, {});
|
|
41
|
+
},
|
|
42
|
+
provides: {
|
|
43
|
+
surface: state,
|
|
44
|
+
context: ({ children }) => /* @__PURE__ */ React.createElement(SurfaceProvider, {
|
|
45
|
+
value: state
|
|
46
|
+
}, children)
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// packages/sdk/app-framework/src/plugins/plugin-surface/helpers.ts
|
|
52
|
+
var isObject = (data) => !!data && typeof data === "object";
|
|
53
|
+
|
|
54
|
+
// packages/sdk/app-framework/src/plugins/plugin-surface/ErrorBoundary.tsx
|
|
55
|
+
import React2, { Component } from "react";
|
|
56
|
+
var ErrorBoundary = class extends Component {
|
|
57
|
+
constructor(props) {
|
|
58
|
+
super(props);
|
|
59
|
+
this.state = {
|
|
60
|
+
error: void 0
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
static getDerivedStateFromError(error) {
|
|
64
|
+
return {
|
|
65
|
+
error
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
componentDidUpdate(prevProps) {
|
|
69
|
+
if (prevProps.data !== this.props.data) {
|
|
70
|
+
this.resetError();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
render() {
|
|
74
|
+
if (this.state.error) {
|
|
75
|
+
return /* @__PURE__ */ React2.createElement(this.props.fallback, {
|
|
76
|
+
data: this.props.data,
|
|
77
|
+
error: this.state.error,
|
|
78
|
+
reset: this.resetError
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return this.props.children;
|
|
82
|
+
}
|
|
83
|
+
resetError() {
|
|
84
|
+
this.setState({
|
|
85
|
+
error: void 0
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// packages/sdk/app-framework/src/plugins/plugin-surface/Surface.tsx
|
|
91
|
+
import React3, { Fragment, Suspense, createContext as createContext2, forwardRef, isValidElement, memo, useContext as useContext2, useEffect, useState } from "react";
|
|
92
|
+
import { raise as raise2 } from "@dxos/debug";
|
|
93
|
+
import { log } from "@dxos/log";
|
|
94
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/plugin-surface/Surface.tsx";
|
|
95
|
+
var count = 0;
|
|
96
|
+
var Surface = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef(({ id: _id, role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
|
|
97
|
+
const props = {
|
|
98
|
+
role,
|
|
99
|
+
name,
|
|
100
|
+
fallback,
|
|
101
|
+
...rest
|
|
102
|
+
};
|
|
103
|
+
const { debugInfo } = useSurfaceRoot();
|
|
104
|
+
const [id] = useState(() => _id ?? `surface-${++count}`);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
debugInfo?.set(id, {
|
|
107
|
+
id,
|
|
108
|
+
created: Date.now(),
|
|
109
|
+
name,
|
|
110
|
+
role,
|
|
111
|
+
renderCount: 0
|
|
112
|
+
});
|
|
113
|
+
return () => {
|
|
114
|
+
debugInfo?.delete(id);
|
|
115
|
+
};
|
|
116
|
+
}, [
|
|
117
|
+
id
|
|
118
|
+
]);
|
|
119
|
+
if (debugInfo?.get(id)) {
|
|
120
|
+
debugInfo.get(id).renderCount++;
|
|
121
|
+
}
|
|
122
|
+
const context = useContext2(SurfaceContext);
|
|
123
|
+
const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
|
|
124
|
+
const resolver = /* @__PURE__ */ React3.createElement(SurfaceResolver, {
|
|
125
|
+
...props,
|
|
126
|
+
id,
|
|
127
|
+
ref: forwardedRef
|
|
128
|
+
});
|
|
129
|
+
const suspense = placeholder ? /* @__PURE__ */ React3.createElement(Suspense, {
|
|
130
|
+
fallback: placeholder
|
|
131
|
+
}, resolver) : resolver;
|
|
132
|
+
return fallback ? /* @__PURE__ */ React3.createElement(ErrorBoundary, {
|
|
133
|
+
data,
|
|
134
|
+
fallback
|
|
135
|
+
}, suspense) : suspense;
|
|
136
|
+
}));
|
|
137
|
+
var SurfaceContext = /* @__PURE__ */ createContext2(void 0);
|
|
138
|
+
var useSurface = () => useContext2(SurfaceContext) ?? raise2(new Error("Surface context not found"));
|
|
139
|
+
var SurfaceResolver = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
140
|
+
const { components } = useSurfaceRoot();
|
|
141
|
+
const parent = useContext2(SurfaceContext);
|
|
142
|
+
const nodes = resolveNodes(components, props, parent, forwardedRef);
|
|
143
|
+
const currentContext = {
|
|
144
|
+
...props,
|
|
145
|
+
surfaces: {
|
|
146
|
+
...props.name && parent?.surfaces?.[props.name]?.surfaces || {},
|
|
147
|
+
...props.surfaces
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
return /* @__PURE__ */ React3.createElement(SurfaceContext.Provider, {
|
|
151
|
+
value: currentContext
|
|
152
|
+
}, nodes);
|
|
153
|
+
});
|
|
154
|
+
var resolveNodes = (components, props, context, forwardedRef) => {
|
|
155
|
+
const data = {
|
|
156
|
+
...props.name && context?.surfaces?.[props.name]?.data || {},
|
|
157
|
+
...props.data
|
|
158
|
+
};
|
|
159
|
+
const candidates = Object.entries(components).map(([key, component]) => {
|
|
160
|
+
const result = component({
|
|
161
|
+
...props,
|
|
162
|
+
data
|
|
163
|
+
}, forwardedRef);
|
|
164
|
+
if (!result || typeof result !== "object") {
|
|
165
|
+
return void 0;
|
|
166
|
+
}
|
|
167
|
+
if ("node" in result) {
|
|
168
|
+
return [
|
|
169
|
+
key,
|
|
170
|
+
result
|
|
171
|
+
];
|
|
172
|
+
} else if (/* @__PURE__ */ isValidElement(result)) {
|
|
173
|
+
return [
|
|
174
|
+
key,
|
|
175
|
+
{
|
|
176
|
+
node: result
|
|
177
|
+
}
|
|
178
|
+
];
|
|
179
|
+
} else {
|
|
180
|
+
log.warn("invalid result", {
|
|
181
|
+
result
|
|
182
|
+
}, {
|
|
183
|
+
F: __dxlog_file,
|
|
184
|
+
L: 183,
|
|
185
|
+
S: void 0,
|
|
186
|
+
C: (f, a) => f(...a)
|
|
187
|
+
});
|
|
188
|
+
return void 0;
|
|
189
|
+
}
|
|
190
|
+
}).filter((result) => Boolean(result)).sort(([, { disposition: a = "default" }], [, { disposition: b = "default" }]) => {
|
|
191
|
+
return a === b ? 0 : a === "hoist" || b === "fallback" ? -1 : b === "hoist" || a === "fallback" ? 1 : 0;
|
|
192
|
+
});
|
|
193
|
+
const nodes = candidates.map(([key, result]) => /* @__PURE__ */ React3.createElement(Fragment, {
|
|
194
|
+
key
|
|
195
|
+
}, result.node));
|
|
196
|
+
return props.limit ? nodes.slice(0, props.limit) : nodes;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// packages/sdk/app-framework/src/plugins/plugin-surface/index.ts
|
|
200
|
+
var plugin_surface_default = SurfacePlugin;
|
|
201
|
+
|
|
202
|
+
export {
|
|
203
|
+
useSurfaceRoot,
|
|
204
|
+
SurfaceProvider,
|
|
205
|
+
meta_default,
|
|
206
|
+
parseRootSurfacePlugin,
|
|
207
|
+
parseSurfacePlugin,
|
|
208
|
+
isObject,
|
|
209
|
+
ErrorBoundary,
|
|
210
|
+
Surface,
|
|
211
|
+
useSurface,
|
|
212
|
+
plugin_surface_default
|
|
213
|
+
};
|
|
214
|
+
//# sourceMappingURL=chunk-EQTQGGE6.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/plugin-surface/SurfacePlugin.tsx", "../../../src/plugins/plugin-surface/SurfaceRootContext.tsx", "../../../src/plugins/plugin-surface/meta.ts", "../../../src/plugins/plugin-surface/provides.ts", "../../../src/plugins/plugin-surface/helpers.ts", "../../../src/plugins/plugin-surface/ErrorBoundary.tsx", "../../../src/plugins/plugin-surface/Surface.tsx", "../../../src/plugins/plugin-surface/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { create } from '@dxos/echo-schema';\n\nimport { SurfaceProvider, type SurfaceRootContext } from './SurfaceRootContext';\nimport SurfaceMeta from './meta';\nimport { parseSurfacePlugin, type SurfacePluginProvides } from './provides';\nimport { filterPlugins } from '../helpers';\nimport { type PluginDefinition } from '../plugin-host';\n\n/**\n * Provides a registry of surface components.\n */\nexport const SurfacePlugin = (): PluginDefinition<SurfacePluginProvides> => {\n const state = create<SurfaceRootContext>({ components: {}, debugInfo: new Map() });\n\n return {\n meta: SurfaceMeta,\n ready: async (plugins) => {\n state.components = filterPlugins(plugins, parseSurfacePlugin).reduce((acc, plugin) => {\n return { ...acc, [plugin.meta.id]: plugin.provides.surface.component };\n }, {});\n },\n provides: {\n surface: state,\n context: ({ children }) => <SurfaceProvider value={state}>{children}</SurfaceProvider>,\n },\n };\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { createContext, useContext, type JSX, type ForwardedRef } from 'react';\n\nimport { raise } from '@dxos/debug';\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\n/**\n * Surface debug info.\n * NOTE: Short-term measure to track perf issues.\n */\nexport type DebugInfo = {\n id: string;\n created: number;\n renderCount: number;\n} & Pick<SurfaceProps, 'role' | 'name'>;\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 /**\n * Debug info.\n */\n debugInfo?: Map<string, DebugInfo>;\n};\n\nconst SurfaceRootContext = createContext<SurfaceRootContext | undefined>(undefined);\n\nexport const useSurfaceRoot = () => useContext(SurfaceRootContext) ?? raise(new Error('Missing SurfaceRootContext'));\n\nexport const SurfaceProvider = SurfaceRootContext.Provider;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst SurfaceMeta = {\n id: 'dxos.org/plugin/surface',\n};\n\nexport default SurfaceMeta;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type SurfaceComponent, type SurfaceRootContext } from './SurfaceRootContext';\nimport { type Plugin } from '../plugin-host';\n\n// TODO(burdon): Predicate based providers?\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\n/**\n * Checks if the given data is an object and not null.\n *\n * Useful inside surface component resolvers as a type guard.\n *\n * @example\n * ```ts\n * const old =\n * data.content &&\n * typeof data.content === 'object' &&\n * 'id' in data.content &&\n * typeof data.content.id === 'string';\n *\n * // becomes\n * const new = isObject(data.content) && typeof data.content.id === 'string';\n * ```\n */\nexport const isObject = (data: unknown): data is { [key: string]: unknown } => !!data && typeof data === 'object';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { Component, type FC, type PropsWithChildren } from 'react';\n\ntype Props = PropsWithChildren<{ data?: any; fallback: FC<{ data?: any; error: Error; reset: () => void }> }>;\ntype State = { error: Error | undefined };\n\n/**\n * Surface error boundary.\n *\n * For basic usage prefer providing a fallback component to `Surface`.\n *\n * For more information on error boundaries, see:\n * https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary\n */\nexport class ErrorBoundary extends Component<Props, State> {\n constructor(props: Props) {\n super(props);\n this.state = { error: undefined };\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n override componentDidUpdate(prevProps: Props): void {\n if (prevProps.data !== this.props.data) {\n this.resetError();\n }\n }\n\n override render() {\n if (this.state.error) {\n return <this.props.fallback data={this.props.data} error={this.state.error} reset={this.resetError} />;\n }\n\n return this.props.children;\n }\n\n private resetError() {\n this.setState({ error: undefined });\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport React, {\n Fragment,\n type ForwardedRef,\n type PropsWithChildren,\n type ReactNode,\n Suspense,\n createContext,\n forwardRef,\n isValidElement,\n memo,\n useContext,\n useEffect,\n useState,\n} from 'react';\n\nimport { raise } from '@dxos/debug';\nimport { log } from '@dxos/log';\n\nimport { ErrorBoundary } from './ErrorBoundary';\nimport { type SurfaceComponent, type SurfaceResult, useSurfaceRoot } from './SurfaceRootContext';\n\n/**\n * Direction determines how multiple components are laid out.\n */\nexport type Direction = 'inline' | 'inline-reverse' | 'block' | 'block-reverse';\n\n/**\n * SurfaceProps are the props that are passed to the Surface component.\n */\nexport type SurfaceProps = PropsWithChildren<{\n /**\n * Optional ID for debugging.\n */\n id?: string;\n\n /**\n * Role defines how the data should be rendered.\n */\n role?: string;\n\n /**\n * Names allow nested surfaces to be specified in the parent context, similar to a slot.\n * Defaults to the value of `role` if not specified.\n */\n name?: string;\n\n /**\n * The data to be rendered by the surface.\n */\n data?: Record<string, unknown>;\n\n /**\n * Configure nested surfaces (indexed by the surface's `name`).\n */\n surfaces?: Record<string, Pick<SurfaceProps, 'data' | 'surfaces'>>;\n\n /**\n * If specified, the Surface will be wrapped in an error boundary.\n * The fallback component will be rendered if an error occurs.\n */\n fallback?: ErrorBoundary['props']['fallback'];\n\n /**\n * If specified, the Surface will be wrapped in a suspense boundary.\n * The placeholder component will be rendered while the surface component is loading.\n */\n placeholder?: ReactNode;\n\n /**\n * If more than one component is resolved, the limit determines how many are rendered.\n */\n limit?: number | undefined;\n\n /**\n * If more than one component is resolved, the direction determines how they are laid out.\n * NOTE: This is not yet implemented.\n */\n direction?: Direction;\n\n /**\n * Additional props to pass to the component.\n * These props are not used by Surface itself but may be used by components which resolve the surface.\n */\n [key: string]: unknown;\n}>;\n\nlet count = 0;\n\n/**\n * A surface is a named region of the screen that can be populated by plugins.\n */\nexport const Surface = memo(\n forwardRef<HTMLElement, SurfaceProps>(\n ({ id: _id, role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {\n const props = { role, name, fallback, ...rest };\n const { debugInfo } = useSurfaceRoot();\n\n // Track debug info.\n const [id] = useState<string>(() => _id ?? `surface-${++count}`);\n useEffect(() => {\n debugInfo?.set(id, { id, created: Date.now(), name, role, renderCount: 0 });\n return () => {\n debugInfo?.delete(id);\n };\n }, [id]);\n\n if (debugInfo?.get(id)) {\n debugInfo.get(id)!.renderCount++;\n }\n\n const context = useContext(SurfaceContext);\n const data = props.data ?? ((name && context?.surfaces?.[name]?.data) || {});\n\n const resolver = <SurfaceResolver {...props} id={id} ref={forwardedRef} />;\n const suspense = placeholder ? <Suspense fallback={placeholder}>{resolver}</Suspense> : resolver;\n\n return fallback ? (\n <ErrorBoundary data={data} fallback={fallback}>\n {suspense}\n </ErrorBoundary>\n ) : (\n suspense\n );\n },\n ),\n);\n\nconst SurfaceContext = createContext<SurfaceProps | undefined>(undefined);\n\nexport const useSurface = (): SurfaceProps =>\n useContext(SurfaceContext) ?? raise(new Error('Surface context not found'));\n\n/**\n * Root surface component.\n */\nconst SurfaceResolver = forwardRef<HTMLElement, SurfaceProps>((props, forwardedRef) => {\n const { components } = useSurfaceRoot();\n const parent = useContext(SurfaceContext);\n const nodes = resolveNodes(components, props, parent, forwardedRef);\n const currentContext: SurfaceProps = {\n ...props,\n surfaces: {\n ...((props.name && parent?.surfaces?.[props.name]?.surfaces) || {}),\n ...props.surfaces,\n },\n };\n\n return <SurfaceContext.Provider value={currentContext}>{nodes}</SurfaceContext.Provider>;\n});\n\n/**\n * Resolve surface nodes from across all component.\n */\nconst resolveNodes = (\n components: Record<string, SurfaceComponent>,\n props: SurfaceProps,\n context: SurfaceProps | undefined,\n forwardedRef: ForwardedRef<HTMLElement>,\n): ReactNode[] => {\n const data = {\n ...((props.name && context?.surfaces?.[props.name]?.data) || {}),\n ...props.data,\n };\n\n const candidates = Object.entries(components)\n .map(([key, component]): [string, SurfaceResult] | undefined => {\n // TODO(burdon): Avoid variable return types in plugin contract.\n const result = component({ ...props, data }, forwardedRef);\n if (!result || typeof result !== 'object') {\n return undefined;\n }\n\n // Normalize tuple.\n if ('node' in result) {\n return [key, result];\n } else if (isValidElement(result)) {\n return [key, { node: result }];\n } else {\n log.warn('invalid result', { result });\n return undefined;\n }\n })\n .filter((result): result is [string, SurfaceResult] => Boolean(result))\n .sort(([, { disposition: a = 'default' }], [, { disposition: b = 'default' }]) => {\n return a === b ? 0 : a === 'hoist' || b === 'fallback' ? -1 : b === 'hoist' || a === 'fallback' ? 1 : 0;\n });\n\n // TODO(burdon): Does this prematurely process the node?\n const nodes = candidates.map(([key, result]) => <Fragment key={key}>{result.node}</Fragment>);\n return props.limit ? nodes.slice(0, props.limit) : nodes;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { SurfacePlugin } from './SurfacePlugin';\n\nexport * from './helpers';\nexport * from './provides';\n\nexport * from './ErrorBoundary';\nexport * from './Surface';\nexport * from './SurfaceRootContext';\n\nexport default SurfacePlugin;\n"],
|
|
5
|
+
"mappings": ";;;;;AAIA,OAAOA,WAAW;AAElB,SAASC,cAAc;;;ACFvB,SAASC,eAAeC,kBAA+C;AAEvE,SAASC,aAA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T;AAGA,QAAI,UAAUiB,QAAQ;AACpB,aAAO;QAACF;QAAKE;;IACf,WAAWC,+BAAeD,MAAAA,GAAS;AACjC,aAAO;QAACF;QAAK;UAAEI,MAAMF;QAAO;;IAC9B,OAAO;AACLG,UAAIC,KAAK,kBAAkB;QAAEJ;MAAO,GAAA;;;;;;AACpC,aAAOjB;IACT;EACF,CAAA,EACCsB,OAAO,CAACL,WAA8CM,QAAQN,MAAAA,CAAAA,EAC9DO,KAAK,CAAC,CAAA,EAAG,EAAEC,aAAaC,IAAI,UAAS,CAAE,GAAG,CAAA,EAAG,EAAED,aAAaE,IAAI,UAAS,CAAE,MAAC;AAC3E,WAAOD,MAAMC,IAAI,IAAID,MAAM,WAAWC,MAAM,aAAa,KAAKA,MAAM,WAAWD,MAAM,aAAa,IAAI;EACxG,CAAA;AAGF,QAAMpB,QAAQK,WAAWG,IAAI,CAAC,CAACC,KAAKE,MAAAA,MAAY,gBAAAxB,OAAA,cAACmC,UAAAA;IAASb;KAAWE,OAAOE,IAAI,CAAA;AAChF,SAAO5C,MAAMsD,QAAQvB,MAAMwB,MAAM,GAAGvD,MAAMsD,KAAK,IAAIvB;AACrD;;;ACrLA,IAAA,yBAAeyB;",
|
|
6
|
+
"names": ["React", "create", "createContext", "useContext", "raise", "SurfaceRootContext", "createContext", "undefined", "useSurfaceRoot", "useContext", "raise", "Error", "SurfaceProvider", "Provider", "SurfaceMeta", "id", "parseRootSurfacePlugin", "plugin", "provides", "surface", "components", "undefined", "parseSurfacePlugin", "component", "SurfacePlugin", "state", "create", "components", "debugInfo", "Map", "meta", "SurfaceMeta", "ready", "plugins", "filterPlugins", "parseSurfacePlugin", "reduce", "acc", "plugin", "id", "provides", "surface", "component", "context", "children", "SurfaceProvider", "value", "isObject", "data", "React", "Component", "ErrorBoundary", "Component", "constructor", "props", "state", "error", "undefined", "getDerivedStateFromError", "componentDidUpdate", "prevProps", "data", "resetError", "render", "React", "this", "fallback", "reset", "children", "setState", "React", "Fragment", "Suspense", "createContext", "forwardRef", "isValidElement", "memo", "useContext", "useEffect", "useState", "raise", "log", "count", "Surface", "memo", "forwardRef", "id", "_id", "role", "name", "fallback", "placeholder", "rest", "forwardedRef", "props", "debugInfo", "useSurfaceRoot", "useState", "useEffect", "set", "created", "Date", "now", "renderCount", "delete", "get", "context", "useContext", "SurfaceContext", "data", "surfaces", "resolver", "React", "SurfaceResolver", "ref", "suspense", "Suspense", "ErrorBoundary", "createContext", "undefined", "useSurface", "raise", "Error", "components", "parent", "nodes", "resolveNodes", "currentContext", "Provider", "value", "candidates", "Object", "entries", "map", "key", "component", "result", "isValidElement", "node", "log", "warn", "filter", "Boolean", "sort", "disposition", "a", "b", "Fragment", "limit", "slice", "SurfacePlugin"]
|
|
7
|
+
}
|