@dxos/app-framework 0.7.4 → 0.7.5-main.937ce75
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-QG25ZU2N.mjs +320 -0
- package/dist/lib/browser/chunk-QG25ZU2N.mjs.map +7 -0
- package/dist/lib/browser/chunk-SPDTXTOV.mjs +163 -0
- package/dist/lib/browser/chunk-SPDTXTOV.mjs.map +7 -0
- package/dist/lib/browser/{chunk-653Y45CL.mjs → chunk-WBOXEHBE.mjs} +12 -2
- package/dist/lib/browser/chunk-WBOXEHBE.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +224 -109
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{plugin-intent-LU4KL2RO.mjs → plugin-intent-T7Y3MJ5C.mjs} +14 -4
- package/dist/lib/browser/{plugin-settings-OM3G2QFY.mjs → plugin-settings-5U2L2NRU.mjs} +6 -2
- package/dist/lib/browser/{plugin-surface-LECZMKSQ.mjs → plugin-surface-OKPF3EQI.mjs} +4 -4
- package/dist/lib/node/{chunk-SOVLKUWI.cjs → chunk-BW3RNEVI.cjs} +51 -102
- package/dist/lib/node/chunk-BW3RNEVI.cjs.map +7 -0
- package/dist/lib/node/{chunk-JZ2JVKRY.cjs → chunk-FCMHRU3M.cjs} +17 -5
- package/dist/lib/node/chunk-FCMHRU3M.cjs.map +7 -0
- package/dist/lib/node/chunk-VWHAALIN.cjs +344 -0
- package/dist/lib/node/chunk-VWHAALIN.cjs.map +7 -0
- package/dist/lib/node/index.cjs +232 -114
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/plugin-intent-F3TQZIUR.cjs +53 -0
- package/dist/lib/node/plugin-intent-F3TQZIUR.cjs.map +7 -0
- package/dist/lib/node/{plugin-settings-OZ6IKAE5.cjs → plugin-settings-W6UHMH5M.cjs} +12 -8
- package/dist/lib/node/plugin-settings-W6UHMH5M.cjs.map +7 -0
- package/dist/lib/node/{plugin-surface-YWDRXQTD.cjs → plugin-surface-CCSIONYW.cjs} +15 -15
- package/dist/lib/node/plugin-surface-CCSIONYW.cjs.map +7 -0
- package/dist/lib/node-esm/{chunk-YNU7FTGJ.mjs → chunk-3T5UIJY3.mjs} +12 -2
- package/dist/lib/node-esm/chunk-3T5UIJY3.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-4GX7V5ZE.mjs +164 -0
- package/dist/lib/node-esm/chunk-4GX7V5ZE.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CFOUYXQ6.mjs +321 -0
- package/dist/lib/node-esm/chunk-CFOUYXQ6.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +224 -109
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{plugin-intent-V7ER24Y6.mjs → plugin-intent-W2HQC6LC.mjs} +14 -4
- package/dist/lib/node-esm/{plugin-settings-37UVWF2V.mjs → plugin-settings-H5RHNFVC.mjs} +6 -2
- package/dist/lib/node-esm/{plugin-surface-TEU42XQN.mjs → plugin-surface-V3YET3UL.mjs} +4 -4
- package/dist/types/src/plugins/common/layout.d.ts +145 -171
- package/dist/types/src/plugins/common/layout.d.ts.map +1 -1
- package/dist/types/src/plugins/common/navigation.d.ts +77 -30
- package/dist/types/src/plugins/common/navigation.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-host/HostPlugin.d.ts +2 -7
- package/dist/types/src/plugins/plugin-host/HostPlugin.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-host/index.d.ts +2 -0
- package/dist/types/src/plugins/plugin-host/index.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-host/plugin.d.ts +7 -1
- package/dist/types/src/plugins/plugin-host/plugin.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-intent/IntentContext.d.ts +7 -20
- package/dist/types/src/plugins/plugin-intent/IntentContext.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-intent/IntentPlugin.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-intent/index.d.ts +1 -0
- package/dist/types/src/plugins/plugin-intent/index.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-intent/intent-dispatcher.d.ts +107 -0
- package/dist/types/src/plugins/plugin-intent/intent-dispatcher.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-intent/intent-dispatcher.test.d.ts +2 -0
- package/dist/types/src/plugins/plugin-intent/intent-dispatcher.test.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-intent/intent.d.ts +65 -58
- package/dist/types/src/plugins/plugin-intent/intent.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-intent/meta.d.ts +1 -0
- package/dist/types/src/plugins/plugin-intent/meta.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-intent/provides.d.ts +6 -10
- package/dist/types/src/plugins/plugin-intent/provides.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-settings/provides.d.ts +15 -2
- package/dist/types/src/plugins/plugin-settings/provides.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-surface/Surface.d.ts +2 -57
- package/dist/types/src/plugins/plugin-surface/Surface.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-surface/SurfaceContext.d.ts +85 -0
- package/dist/types/src/plugins/plugin-surface/SurfaceContext.d.ts.map +1 -0
- package/dist/types/src/plugins/plugin-surface/SurfacePlugin.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-surface/index.d.ts +1 -1
- package/dist/types/src/plugins/plugin-surface/index.d.ts.map +1 -1
- package/dist/types/src/plugins/plugin-surface/provides.d.ts +5 -4
- package/dist/types/src/plugins/plugin-surface/provides.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +14 -12
- package/src/plugins/common/layout.ts +125 -107
- package/src/plugins/common/navigation.ts +59 -30
- package/src/plugins/plugin-host/HostPlugin.tsx +2 -10
- package/src/plugins/plugin-host/PluginContainer.tsx +1 -1
- package/src/plugins/plugin-host/index.ts +4 -0
- package/src/plugins/plugin-host/plugin.ts +8 -1
- package/src/plugins/plugin-intent/IntentContext.tsx +13 -36
- package/src/plugins/plugin-intent/IntentPlugin.tsx +44 -120
- package/src/plugins/plugin-intent/index.ts +1 -0
- package/src/plugins/plugin-intent/intent-dispatcher.test.ts +279 -0
- package/src/plugins/plugin-intent/intent-dispatcher.ts +285 -0
- package/src/plugins/plugin-intent/intent.ts +126 -65
- package/src/plugins/plugin-intent/meta.ts +3 -1
- package/src/plugins/plugin-intent/provides.ts +8 -20
- package/src/plugins/plugin-settings/provides.ts +10 -5
- package/src/plugins/plugin-surface/Surface.tsx +25 -158
- package/src/plugins/plugin-surface/SurfaceContext.ts +112 -0
- package/src/plugins/plugin-surface/SurfacePlugin.tsx +19 -7
- package/src/plugins/plugin-surface/index.ts +1 -1
- package/src/plugins/plugin-surface/provides.ts +8 -7
- package/tsconfig.json +38 -1
- package/dist/lib/browser/chunk-653Y45CL.mjs.map +0 -7
- package/dist/lib/browser/chunk-FRXJ25VI.mjs +0 -214
- package/dist/lib/browser/chunk-FRXJ25VI.mjs.map +0 -7
- package/dist/lib/browser/chunk-YXM35XRE.mjs +0 -213
- package/dist/lib/browser/chunk-YXM35XRE.mjs.map +0 -7
- package/dist/lib/node/chunk-JZ2JVKRY.cjs.map +0 -7
- package/dist/lib/node/chunk-QSVP5HOW.cjs +0 -238
- package/dist/lib/node/chunk-QSVP5HOW.cjs.map +0 -7
- package/dist/lib/node/chunk-SOVLKUWI.cjs.map +0 -7
- package/dist/lib/node/plugin-intent-FVFR2LKB.cjs +0 -43
- package/dist/lib/node/plugin-intent-FVFR2LKB.cjs.map +0 -7
- package/dist/lib/node/plugin-settings-OZ6IKAE5.cjs.map +0 -7
- package/dist/lib/node/plugin-surface-YWDRXQTD.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-2R4GVK7O.mjs +0 -215
- package/dist/lib/node-esm/chunk-2R4GVK7O.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YFMFQBB4.mjs +0 -214
- package/dist/lib/node-esm/chunk-YFMFQBB4.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YNU7FTGJ.mjs.map +0 -7
- package/dist/types/src/plugins/plugin-intent/helpers.d.ts +0 -6
- package/dist/types/src/plugins/plugin-intent/helpers.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-surface/SurfaceRootContext.d.ts +0 -39
- package/dist/types/src/plugins/plugin-surface/SurfaceRootContext.d.ts.map +0 -1
- package/src/plugins/plugin-intent/helpers.ts +0 -11
- package/src/plugins/plugin-surface/SurfaceRootContext.tsx +0 -60
- /package/dist/lib/browser/{plugin-intent-LU4KL2RO.mjs.map → plugin-intent-T7Y3MJ5C.mjs.map} +0 -0
- /package/dist/lib/browser/{plugin-settings-OM3G2QFY.mjs.map → plugin-settings-5U2L2NRU.mjs.map} +0 -0
- /package/dist/lib/browser/{plugin-surface-LECZMKSQ.mjs.map → plugin-surface-OKPF3EQI.mjs.map} +0 -0
- /package/dist/lib/node-esm/{plugin-intent-V7ER24Y6.mjs.map → plugin-intent-W2HQC6LC.mjs.map} +0 -0
- /package/dist/lib/node-esm/{plugin-settings-37UVWF2V.mjs.map → plugin-settings-H5RHNFVC.mjs.map} +0 -0
- /package/dist/lib/node-esm/{plugin-surface-TEU42XQN.mjs.map → plugin-surface-V3YET3UL.mjs.map} +0 -0
|
@@ -26,20 +26,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_BW3RNEVI_exports = {};
|
|
30
|
+
__export(chunk_BW3RNEVI_exports, {
|
|
31
31
|
ErrorBoundary: () => ErrorBoundary,
|
|
32
32
|
Surface: () => Surface,
|
|
33
33
|
SurfaceProvider: () => SurfaceProvider,
|
|
34
|
+
createSurface: () => createSurface,
|
|
34
35
|
isObject: () => isObject,
|
|
35
36
|
meta_default: () => meta_default,
|
|
36
37
|
parseRootSurfacePlugin: () => parseRootSurfacePlugin,
|
|
37
38
|
parseSurfacePlugin: () => parseSurfacePlugin,
|
|
38
39
|
plugin_surface_default: () => plugin_surface_default,
|
|
39
|
-
useSurface: () => useSurface,
|
|
40
40
|
useSurfaceRoot: () => useSurfaceRoot
|
|
41
41
|
});
|
|
42
|
-
module.exports = __toCommonJS(
|
|
42
|
+
module.exports = __toCommonJS(chunk_BW3RNEVI_exports);
|
|
43
43
|
var import_chunk_QBM42OQ6 = require("./chunk-QBM42OQ6.cjs");
|
|
44
44
|
var import_react = __toESM(require("react"));
|
|
45
45
|
var import_live_object = require("@dxos/live-object");
|
|
@@ -47,31 +47,26 @@ var import_react2 = require("react");
|
|
|
47
47
|
var import_debug = require("@dxos/debug");
|
|
48
48
|
var import_react3 = __toESM(require("react"));
|
|
49
49
|
var import_react4 = __toESM(require("react"));
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var useSurfaceRoot = () => (0, import_react2.useContext)(
|
|
54
|
-
var SurfaceProvider =
|
|
50
|
+
var import_react_hooks = require("@dxos/react-hooks");
|
|
51
|
+
var createSurface = (definition) => definition;
|
|
52
|
+
var SurfaceContext = (0, import_react2.createContext)(void 0);
|
|
53
|
+
var useSurfaceRoot = () => (0, import_react2.useContext)(SurfaceContext) ?? (0, import_debug.raise)(new Error("Missing SurfaceContext"));
|
|
54
|
+
var SurfaceProvider = SurfaceContext.Provider;
|
|
55
55
|
var SurfaceMeta = {
|
|
56
56
|
id: "dxos.org/plugin/surface"
|
|
57
57
|
};
|
|
58
58
|
var meta_default = SurfaceMeta;
|
|
59
|
-
var parseRootSurfacePlugin = (plugin) => plugin?.provides?.surface?.
|
|
60
|
-
var parseSurfacePlugin = (plugin) => plugin?.provides?.surface?.
|
|
59
|
+
var parseRootSurfacePlugin = (plugin) => plugin?.provides?.surface?.surfaces ? plugin : void 0;
|
|
60
|
+
var parseSurfacePlugin = (plugin) => plugin?.provides?.surface?.definitions ? plugin : void 0;
|
|
61
61
|
var SurfacePlugin = () => {
|
|
62
62
|
const state = (0, import_live_object.create)({
|
|
63
|
-
|
|
63
|
+
surfaces: {},
|
|
64
64
|
debugInfo: /* @__PURE__ */ new Map()
|
|
65
65
|
});
|
|
66
66
|
return {
|
|
67
67
|
meta: meta_default,
|
|
68
|
-
ready: async (
|
|
69
|
-
state.
|
|
70
|
-
return {
|
|
71
|
-
...acc,
|
|
72
|
-
[plugin.meta.id]: plugin.provides.surface.component
|
|
73
|
-
};
|
|
74
|
-
}, {});
|
|
68
|
+
ready: async (context) => {
|
|
69
|
+
state.surfaces = (0, import_chunk_QBM42OQ6.filterPlugins)(context.plugins, parseSurfacePlugin).reduce((acc, plugin) => reduceSurfaces(plugin.provides.surface.definitions(context), acc), {});
|
|
75
70
|
},
|
|
76
71
|
provides: {
|
|
77
72
|
surface: state,
|
|
@@ -81,6 +76,15 @@ var SurfacePlugin = () => {
|
|
|
81
76
|
}
|
|
82
77
|
};
|
|
83
78
|
};
|
|
79
|
+
var reduceSurfaces = (definitions, surfaces = {}) => {
|
|
80
|
+
if (Array.isArray(definitions)) {
|
|
81
|
+
return definitions.reduce((acc, definition) => reduceSurfaces(definition, acc), surfaces);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
...surfaces,
|
|
85
|
+
[definitions.id]: definitions
|
|
86
|
+
};
|
|
87
|
+
};
|
|
84
88
|
var isObject = (data) => !!data && typeof data === "object";
|
|
85
89
|
var ErrorBoundary = class extends import_react3.Component {
|
|
86
90
|
constructor(props) {
|
|
@@ -115,22 +119,15 @@ var ErrorBoundary = class extends import_react3.Component {
|
|
|
115
119
|
});
|
|
116
120
|
}
|
|
117
121
|
};
|
|
118
|
-
var
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
name,
|
|
124
|
-
fallback,
|
|
125
|
-
...rest
|
|
126
|
-
};
|
|
127
|
-
const { debugInfo } = useSurfaceRoot();
|
|
128
|
-
const [id] = (0, import_react4.useState)(() => _id ?? `surface-${++count}`);
|
|
122
|
+
var Surface = /* @__PURE__ */ (0, import_react4.memo)(/* @__PURE__ */ (0, import_react4.forwardRef)(({ id: _id, role, data: _data, limit, fallback, placeholder, ...rest }, forwardedRef) => {
|
|
123
|
+
const { surfaces, debugInfo } = useSurfaceRoot();
|
|
124
|
+
const data = (0, import_react_hooks.useDefaultValue)(_data, () => ({}));
|
|
125
|
+
const reactId = (0, import_react4.useId)();
|
|
126
|
+
const id = _id ?? reactId;
|
|
129
127
|
(0, import_react4.useEffect)(() => {
|
|
130
128
|
debugInfo?.set(id, {
|
|
131
129
|
id,
|
|
132
130
|
created: Date.now(),
|
|
133
|
-
name,
|
|
134
131
|
role,
|
|
135
132
|
renderCount: 0
|
|
136
133
|
});
|
|
@@ -143,94 +140,46 @@ var Surface = /* @__PURE__ */ (0, import_react4.memo)(/* @__PURE__ */ (0, import
|
|
|
143
140
|
if (debugInfo?.get(id)) {
|
|
144
141
|
debugInfo.get(id).renderCount++;
|
|
145
142
|
}
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
143
|
+
const candidates = (0, import_react4.useMemo)(() => {
|
|
144
|
+
const definitions = Object.values(surfaces).filter((definition) => Array.isArray(definition.role) ? definition.role.includes(role) : definition.role === role).filter(({ filter }) => filter ? filter(data) : true).toSorted(({ disposition: a = "static" }, { disposition: b = "static" }) => {
|
|
145
|
+
return a === b ? 0 : a === "hoist" || b === "fallback" ? -1 : b === "hoist" || a === "fallback" ? 1 : 0;
|
|
146
|
+
});
|
|
147
|
+
return limit ? definitions.slice(0, limit) : definitions;
|
|
148
|
+
}, [
|
|
149
|
+
surfaces,
|
|
150
|
+
role,
|
|
151
|
+
data,
|
|
152
|
+
limit
|
|
153
|
+
]);
|
|
154
|
+
const nodes = candidates.map(({ component: Component2, id: id2 }) => /* @__PURE__ */ import_react4.default.createElement(Component2, {
|
|
155
|
+
ref: forwardedRef,
|
|
156
|
+
key: id2,
|
|
157
|
+
id: id2,
|
|
158
|
+
role,
|
|
159
|
+
data,
|
|
160
|
+
limit,
|
|
161
|
+
...rest
|
|
162
|
+
}));
|
|
153
163
|
const suspense = placeholder ? /* @__PURE__ */ import_react4.default.createElement(import_react4.Suspense, {
|
|
154
164
|
fallback: placeholder
|
|
155
|
-
},
|
|
165
|
+
}, nodes) : nodes;
|
|
156
166
|
return fallback ? /* @__PURE__ */ import_react4.default.createElement(ErrorBoundary, {
|
|
157
167
|
data,
|
|
158
168
|
fallback
|
|
159
169
|
}, suspense) : suspense;
|
|
160
170
|
}));
|
|
161
|
-
var SurfaceContext = /* @__PURE__ */ (0, import_react4.createContext)(void 0);
|
|
162
|
-
var useSurface = () => (0, import_react4.useContext)(SurfaceContext) ?? (0, import_debug2.raise)(new Error("Surface context not found"));
|
|
163
|
-
var SurfaceResolver = /* @__PURE__ */ (0, import_react4.forwardRef)((props, forwardedRef) => {
|
|
164
|
-
const { components } = useSurfaceRoot();
|
|
165
|
-
const parent = (0, import_react4.useContext)(SurfaceContext);
|
|
166
|
-
const nodes = resolveNodes(components, props, parent, forwardedRef);
|
|
167
|
-
const currentContext = {
|
|
168
|
-
...props,
|
|
169
|
-
surfaces: {
|
|
170
|
-
...props.name && parent?.surfaces?.[props.name]?.surfaces || {},
|
|
171
|
-
...props.surfaces
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
return /* @__PURE__ */ import_react4.default.createElement(SurfaceContext.Provider, {
|
|
175
|
-
value: currentContext
|
|
176
|
-
}, nodes);
|
|
177
|
-
});
|
|
178
|
-
var resolveNodes = (components, props, context, forwardedRef) => {
|
|
179
|
-
const data = {
|
|
180
|
-
...props.name && context?.surfaces?.[props.name]?.data || {},
|
|
181
|
-
...props.data
|
|
182
|
-
};
|
|
183
|
-
const candidates = Object.entries(components).map(([key, component]) => {
|
|
184
|
-
const result = component({
|
|
185
|
-
...props,
|
|
186
|
-
data
|
|
187
|
-
}, forwardedRef);
|
|
188
|
-
if (!result || typeof result !== "object") {
|
|
189
|
-
return void 0;
|
|
190
|
-
}
|
|
191
|
-
if ("node" in result) {
|
|
192
|
-
return [
|
|
193
|
-
key,
|
|
194
|
-
result
|
|
195
|
-
];
|
|
196
|
-
} else if (/* @__PURE__ */ (0, import_react4.isValidElement)(result)) {
|
|
197
|
-
return [
|
|
198
|
-
key,
|
|
199
|
-
{
|
|
200
|
-
node: result
|
|
201
|
-
}
|
|
202
|
-
];
|
|
203
|
-
} else {
|
|
204
|
-
import_log.log.warn("invalid result", {
|
|
205
|
-
result
|
|
206
|
-
}, {
|
|
207
|
-
F: __dxlog_file,
|
|
208
|
-
L: 183,
|
|
209
|
-
S: void 0,
|
|
210
|
-
C: (f, a) => f(...a)
|
|
211
|
-
});
|
|
212
|
-
return void 0;
|
|
213
|
-
}
|
|
214
|
-
}).filter((result) => Boolean(result)).sort(([, { disposition: a = "default" }], [, { disposition: b = "default" }]) => {
|
|
215
|
-
return a === b ? 0 : a === "hoist" || b === "fallback" ? -1 : b === "hoist" || a === "fallback" ? 1 : 0;
|
|
216
|
-
});
|
|
217
|
-
const nodes = candidates.map(([key, result]) => /* @__PURE__ */ import_react4.default.createElement(import_react4.Fragment, {
|
|
218
|
-
key
|
|
219
|
-
}, result.node));
|
|
220
|
-
return props.limit ? nodes.slice(0, props.limit) : nodes;
|
|
221
|
-
};
|
|
222
171
|
var plugin_surface_default = SurfacePlugin;
|
|
223
172
|
// Annotate the CommonJS export names for ESM import in node:
|
|
224
173
|
0 && (module.exports = {
|
|
225
174
|
ErrorBoundary,
|
|
226
175
|
Surface,
|
|
227
176
|
SurfaceProvider,
|
|
177
|
+
createSurface,
|
|
228
178
|
isObject,
|
|
229
179
|
meta_default,
|
|
230
180
|
parseRootSurfacePlugin,
|
|
231
181
|
parseSurfacePlugin,
|
|
232
182
|
plugin_surface_default,
|
|
233
|
-
useSurface,
|
|
234
183
|
useSurfaceRoot
|
|
235
184
|
});
|
|
236
|
-
//# sourceMappingURL=chunk-
|
|
185
|
+
//# sourceMappingURL=chunk-BW3RNEVI.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/plugin-surface/SurfacePlugin.tsx", "../../../src/plugins/plugin-surface/SurfaceContext.ts", "../../../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/live-object';\n\nimport { SurfaceProvider, type SurfaceContextValue } from './SurfaceContext';\nimport SurfaceMeta from './meta';\nimport { parseSurfacePlugin, type SurfacePluginProvides, type SurfaceDefinitions } 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<SurfaceContextValue>({ surfaces: {}, debugInfo: new Map() });\n\n return {\n meta: SurfaceMeta,\n ready: async (context) => {\n state.surfaces = filterPlugins(context.plugins, parseSurfacePlugin).reduce(\n (acc, plugin) => reduceSurfaces(plugin.provides.surface.definitions(context), acc),\n {},\n );\n },\n provides: {\n surface: state,\n context: ({ children }) => <SurfaceProvider value={state}>{children}</SurfaceProvider>,\n },\n };\n};\n\nconst reduceSurfaces = (\n definitions: SurfaceDefinitions,\n surfaces: SurfaceContextValue['surfaces'] = {},\n): SurfaceContextValue['surfaces'] => {\n if (Array.isArray(definitions)) {\n return definitions.reduce((acc, definition) => reduceSurfaces(definition, acc), surfaces);\n }\n\n return { ...surfaces, [definitions.id]: definitions };\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { createContext, useContext, type JSX, type ForwardedRef, type PropsWithChildren, type ReactNode } from 'react';\n\nimport { raise } from '@dxos/debug';\nimport { type GuardedType, type MakeOptional } from '@dxos/util';\n\nimport { type ErrorBoundary } from './ErrorBoundary';\n\n/**\n * SurfaceProps are the props that are passed to the Surface component.\n */\nexport type SurfaceProps<T extends Record<string, any> = Record<string, unknown>> = PropsWithChildren<{\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 MakeOptional<CoreSurfaceProps<T>, 'id' | 'data'> & {\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\n// NOTE: If `[key: string]: unknown` is included in shared types, when re-used other fields become unknown as well.\ntype CoreSurfaceProps<T extends Record<string, any> = Record<string, unknown>> = {\n /**\n * 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 * The data to be rendered by the surface.\n */\n data: T;\n\n /**\n * If more than one component is resolved, the limit determines how many are rendered.\n */\n limit?: number | undefined;\n};\n\ntype SurfaceComponentProps<T extends Record<string, any> = Record<string, unknown>> = PropsWithChildren<\n CoreSurfaceProps<T> & { [key: string]: unknown }\n>;\n\n/**\n * React component used to render a surface once is has matched.\n */\nexport type SurfaceComponent<T extends Record<string, any> = Record<string, unknown>> = (\n props: SurfaceComponentProps<T>,\n forwardedRef: ForwardedRef<HTMLElement>,\n) => JSX.Element | null;\n\n/**\n * Determines the priority of the surface when multiple components are resolved.\n *\n * - `static` - The component is rendered in the order it was resolved.\n * - `hoist` - The component is rendered before `static` components.\n * - `fallback` - The component is rendered after `static` components.\n */\nexport type SurfaceDisposition = 'static' | 'hoist' | 'fallback';\n\n/**\n * Definition of when a SurfaceComponent should be rendered.\n */\nexport type SurfaceDefinition<T extends Record<string, any> = any> = {\n id: string;\n role: string | string[];\n disposition?: SurfaceDisposition;\n filter?: (data: Record<string, unknown>) => data is T;\n component: SurfaceComponent<GuardedType<SurfaceDefinition<T>['filter']>>;\n};\n\nexport const createSurface = <T extends Record<string, any> = any>(definition: SurfaceDefinition<T>) => definition;\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'>;\n\nexport type SurfaceContextValue = {\n surfaces: Record<string, SurfaceDefinition>;\n debugInfo?: Map<string, DebugInfo>;\n};\n\nconst SurfaceContext = createContext<SurfaceContextValue | undefined>(undefined);\n\nexport const useSurfaceRoot = () => useContext(SurfaceContext) ?? raise(new Error('Missing SurfaceContext'));\n\nexport const SurfaceProvider = SurfaceContext.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 SurfaceDefinition, type SurfaceContextValue } from './SurfaceContext';\nimport { type HostContext, type Plugin } from '../plugin-host';\n\nexport type SurfaceDefinitions = SurfaceDefinition | SurfaceDefinition[] | SurfaceDefinitions[];\n\nexport type SurfaceProvides = {\n surface: {\n /**\n * Used by the `Surface` resolver to find a component to render.\n */\n definitions: (context: HostContext) => SurfaceDefinitions;\n };\n};\n\nexport type SurfacePluginProvides = {\n surface: SurfaceContextValue;\n};\n\nexport const parseRootSurfacePlugin = (plugin?: Plugin) =>\n (plugin?.provides as any)?.surface?.surfaces ? (plugin as Plugin<SurfacePluginProvides>) : undefined;\n\nexport const parseSurfacePlugin = (plugin?: Plugin) =>\n (plugin?.provides as any)?.surface?.definitions ? (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, { Suspense, forwardRef, memo, useEffect, useId, useMemo } from 'react';\n\nimport { useDefaultValue } from '@dxos/react-hooks';\n\nimport { ErrorBoundary } from './ErrorBoundary';\nimport { type SurfaceProps, useSurfaceRoot } from './SurfaceContext';\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, data: _data, limit, fallback, placeholder, ...rest }, forwardedRef) => {\n const { surfaces, debugInfo } = useSurfaceRoot();\n const data = useDefaultValue(_data, () => ({}));\n\n // Track debug info.\n const reactId = useId();\n const id = _id ?? reactId;\n useEffect(() => {\n debugInfo?.set(id, { id, created: Date.now(), 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 candidates = useMemo(() => {\n const definitions = Object.values(surfaces)\n .filter((definition) =>\n Array.isArray(definition.role) ? definition.role.includes(role) : definition.role === role,\n )\n .filter(({ filter }) => (filter ? filter(data) : true))\n .toSorted(({ disposition: a = 'static' }, { disposition: b = 'static' }) => {\n return a === b ? 0 : a === 'hoist' || b === 'fallback' ? -1 : b === 'hoist' || a === 'fallback' ? 1 : 0;\n });\n return limit ? definitions.slice(0, limit) : definitions;\n }, [surfaces, role, data, limit]);\n\n const nodes = candidates.map(({ component: Component, id }) => (\n <Component ref={forwardedRef} key={id} id={id} role={role} data={data} limit={limit} {...rest} />\n ));\n\n const suspense = placeholder ? <Suspense fallback={placeholder}>{nodes}</Suspense> : nodes;\n\n return fallback ? (\n <ErrorBoundary data={data} fallback={fallback}>\n {suspense}\n </ErrorBoundary>\n ) : (\n suspense\n );\n },\n ),\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 './SurfaceContext';\n\nexport default SurfacePlugin;\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["import_react", "createSurface", "definition", "SurfaceContext", "createContext", "undefined", "useSurfaceRoot", "useContext", "raise", "Error", "SurfaceProvider", "Provider", "SurfaceMeta", "id", "parseRootSurfacePlugin", "plugin", "provides", "surface", "surfaces", "parseSurfacePlugin", "definitions", "SurfacePlugin", "state", "create", "debugInfo", "Map", "meta", "ready", "context", "filterPlugins", "plugins", "reduce", "acc", "reduceSurfaces", "children", "React", "value", "Array", "isArray", "isObject", "data", "ErrorBoundary", "Component", "constructor", "props", "error", "getDerivedStateFromError", "componentDidUpdate", "prevProps", "resetError", "render", "this", "fallback", "reset", "setState", "Surface", "memo", "forwardRef", "_id", "role", "_data", "limit", "placeholder", "rest", "forwardedRef", "useDefaultValue", "reactId", "useId", "useEffect", "set", "created", "Date", "now", "renderCount", "delete", "get", "candidates", "useMemo", "Object", "values", "filter", "includes", "toSorted", "disposition", "a", "b", "slice", "nodes", "map", "component", "ref", "key", "suspense", "Suspense"]
|
|
7
|
+
}
|
|
@@ -16,15 +16,18 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_FCMHRU3M_exports = {};
|
|
20
|
+
__export(chunk_FCMHRU3M_exports, {
|
|
21
|
+
SETTINGS_ACTION: () => SETTINGS_ACTION,
|
|
22
|
+
SETTINGS_PLUGIN: () => SETTINGS_PLUGIN,
|
|
21
23
|
SettingsAction: () => SettingsAction,
|
|
22
24
|
meta_default: () => meta_default,
|
|
23
25
|
parseSettingsPlugin: () => parseSettingsPlugin,
|
|
24
26
|
plugin_settings_default: () => plugin_settings_default
|
|
25
27
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
28
|
+
module.exports = __toCommonJS(chunk_FCMHRU3M_exports);
|
|
27
29
|
var import_local_storage = require("@dxos/local-storage");
|
|
30
|
+
var import_echo_schema = require("@dxos/echo-schema");
|
|
28
31
|
var SettingsMeta = {
|
|
29
32
|
id: "dxos.org/plugin/settings"
|
|
30
33
|
};
|
|
@@ -45,14 +48,23 @@ var SETTINGS_PLUGIN = "dxos.org/plugin/settings";
|
|
|
45
48
|
var SETTINGS_ACTION = `${SETTINGS_PLUGIN}/action`;
|
|
46
49
|
var SettingsAction;
|
|
47
50
|
(function(SettingsAction2) {
|
|
48
|
-
|
|
51
|
+
class Open extends import_echo_schema.S.TaggedClass()(`${SETTINGS_ACTION}/open`, {
|
|
52
|
+
input: import_echo_schema.S.Struct({
|
|
53
|
+
plugin: import_echo_schema.S.optional(import_echo_schema.S.String)
|
|
54
|
+
}),
|
|
55
|
+
output: import_echo_schema.S.Void
|
|
56
|
+
}) {
|
|
57
|
+
}
|
|
58
|
+
SettingsAction2.Open = Open;
|
|
49
59
|
})(SettingsAction || (SettingsAction = {}));
|
|
50
60
|
var plugin_settings_default = SettingsPlugin;
|
|
51
61
|
// Annotate the CommonJS export names for ESM import in node:
|
|
52
62
|
0 && (module.exports = {
|
|
63
|
+
SETTINGS_ACTION,
|
|
64
|
+
SETTINGS_PLUGIN,
|
|
53
65
|
SettingsAction,
|
|
54
66
|
meta_default,
|
|
55
67
|
parseSettingsPlugin,
|
|
56
68
|
plugin_settings_default
|
|
57
69
|
});
|
|
58
|
-
//# sourceMappingURL=chunk-
|
|
70
|
+
//# sourceMappingURL=chunk-FCMHRU3M.cjs.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 { S } from '@dxos/echo-schema';\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\nexport const SETTINGS_PLUGIN = 'dxos.org/plugin/settings';\nexport const SETTINGS_ACTION = `${SETTINGS_PLUGIN}/action`;\n\nexport namespace SettingsAction {\n export class Open extends S.TaggedClass<Open>()(`${SETTINGS_ACTION}/open`, {\n input: S.Struct({\n plugin: S.optional(S.String),\n }),\n output: S.Void,\n }) {}\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,2BAAkC;AEAlC,yBAAkB;ADAlB,IAAMA,eAAe;EACnBC,IAAI;AACN;AAEA,IAAA,eAAeD;ADER,IAAME,iBAAiB,MAAA;AAG5B,QAAMC,gBAAgB,IAAIC,uCAAAA;AAE1B,SAAO;IACLC,MAAML;IACNM,UAAU;MACRH;IACF;EACF;AACF;AEJO,IAAMI,sBAAsB,CAACC,WAAAA;AAClC,SAAO,OAAQA,OAAOF,SAAiBH,kBAAkB,WACpDK,SACDC;AACN;AAEO,IAAMC,kBAAkB;AACxB,IAAMC,kBAAkB,GAAGD,eAAAA;;UAEjBE,iBAAAA;EACR,MAAMC,aAAaC,qBAAEC,YAAW,EAAS,GAAGJ,eAAAA,SAAwB;IACzEK,OAAOF,qBAAEG,OAAO;MACdT,QAAQM,qBAAEI,SAASJ,qBAAEK,MAAM;IAC7B,CAAA;IACAC,QAAQN,qBAAEO;EACZ,CAAA,EAAA;EAAI;kBALSR,OAAAA;AAMf,GAPiBD,mBAAAA,iBAAAA,CAAAA,EAAAA;AClBjB,IAAA,0BAAeV;",
|
|
6
|
+
"names": ["SettingsMeta", "id", "SettingsPlugin", "settingsStore", "RootSettingsStore", "meta", "provides", "parseSettingsPlugin", "plugin", "undefined", "SETTINGS_PLUGIN", "SETTINGS_ACTION", "SettingsAction", "Open", "S", "TaggedClass", "input", "Struct", "optional", "String", "output", "Void"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var chunk_VWHAALIN_exports = {};
|
|
30
|
+
__export(chunk_VWHAALIN_exports, {
|
|
31
|
+
INTENT_ACTION: () => INTENT_ACTION,
|
|
32
|
+
IntentAction: () => IntentAction,
|
|
33
|
+
IntentProvider: () => IntentProvider,
|
|
34
|
+
Label: () => Label,
|
|
35
|
+
chain: () => chain,
|
|
36
|
+
createDispatcher: () => createDispatcher,
|
|
37
|
+
createIntent: () => createIntent,
|
|
38
|
+
createResolver: () => createResolver,
|
|
39
|
+
meta_default: () => meta_default,
|
|
40
|
+
parseIntentPlugin: () => parseIntentPlugin,
|
|
41
|
+
parseIntentResolverPlugin: () => parseIntentResolverPlugin,
|
|
42
|
+
plugin_intent_default: () => plugin_intent_default,
|
|
43
|
+
useIntentDispatcher: () => useIntentDispatcher,
|
|
44
|
+
useIntentResolver: () => useIntentResolver
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(chunk_VWHAALIN_exports);
|
|
47
|
+
var import_chunk_QBM42OQ6 = require("./chunk-QBM42OQ6.cjs");
|
|
48
|
+
var import_effect = require("effect");
|
|
49
|
+
var import_react = __toESM(require("react"));
|
|
50
|
+
var import_live_object = require("@dxos/live-object");
|
|
51
|
+
var import_react2 = require("react");
|
|
52
|
+
var import_debug = require("@dxos/debug");
|
|
53
|
+
var import_util = require("@dxos/util");
|
|
54
|
+
var import_effect2 = require("effect");
|
|
55
|
+
var import_util2 = require("@dxos/util");
|
|
56
|
+
var import_echo_schema = require("@dxos/echo-schema");
|
|
57
|
+
var IntentContext = /* @__PURE__ */ (0, import_react2.createContext)(void 0);
|
|
58
|
+
var useIntentDispatcher = () => {
|
|
59
|
+
const context = (0, import_react2.useContext)(IntentContext) ?? (0, import_debug.raise)(new Error("IntentContext not found"));
|
|
60
|
+
return (0, import_util.pick)(context, [
|
|
61
|
+
"dispatch",
|
|
62
|
+
"dispatchPromise"
|
|
63
|
+
]);
|
|
64
|
+
};
|
|
65
|
+
var useIntentResolver = (pluginId, resolver) => {
|
|
66
|
+
const { registerResolver } = (0, import_react2.useContext)(IntentContext) ?? (0, import_debug.raise)(new Error("IntentContext not found"));
|
|
67
|
+
(0, import_react2.useEffect)(() => {
|
|
68
|
+
return registerResolver(pluginId, resolver);
|
|
69
|
+
}, [
|
|
70
|
+
pluginId,
|
|
71
|
+
resolver
|
|
72
|
+
]);
|
|
73
|
+
};
|
|
74
|
+
var IntentProvider = IntentContext.Provider;
|
|
75
|
+
var INTENT_PLUGIN = "dxos.org/plugin/intent";
|
|
76
|
+
var IntentMeta = {
|
|
77
|
+
id: INTENT_PLUGIN
|
|
78
|
+
};
|
|
79
|
+
var meta_default = IntentMeta;
|
|
80
|
+
var createIntent = (schema, data = {}, params = {}) => {
|
|
81
|
+
const _ = import_echo_schema.S.validateSync(schema.fields.input)(data);
|
|
82
|
+
const intent = {
|
|
83
|
+
...params,
|
|
84
|
+
_schema: schema,
|
|
85
|
+
action: schema._tag,
|
|
86
|
+
data
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
first: intent,
|
|
90
|
+
last: intent,
|
|
91
|
+
all: [
|
|
92
|
+
intent
|
|
93
|
+
]
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
var chain = (schema, data = {}, params = {}) => (intent) => {
|
|
97
|
+
const intents = "all" in intent ? intent.all : [
|
|
98
|
+
intent
|
|
99
|
+
];
|
|
100
|
+
const first = intents[0];
|
|
101
|
+
const last = {
|
|
102
|
+
...params,
|
|
103
|
+
_schema: schema,
|
|
104
|
+
action: schema._tag,
|
|
105
|
+
data
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
first,
|
|
109
|
+
last,
|
|
110
|
+
all: [
|
|
111
|
+
...intents,
|
|
112
|
+
last
|
|
113
|
+
]
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
var Label = import_echo_schema.S.Union(import_echo_schema.S.String, import_echo_schema.S.mutable(import_echo_schema.S.Tuple(import_echo_schema.S.String, import_echo_schema.S.mutable(import_echo_schema.S.Struct({
|
|
117
|
+
ns: import_echo_schema.S.String,
|
|
118
|
+
count: import_echo_schema.S.optional(import_echo_schema.S.Number)
|
|
119
|
+
})))));
|
|
120
|
+
var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
|
|
121
|
+
var IntentAction;
|
|
122
|
+
(function(IntentAction2) {
|
|
123
|
+
class ShowUndo extends import_echo_schema.S.TaggedClass()(`${INTENT_ACTION}/show-undo`, {
|
|
124
|
+
input: import_echo_schema.S.Struct({
|
|
125
|
+
message: Label
|
|
126
|
+
}),
|
|
127
|
+
output: import_echo_schema.S.Void
|
|
128
|
+
}) {
|
|
129
|
+
}
|
|
130
|
+
IntentAction2.ShowUndo = ShowUndo;
|
|
131
|
+
})(IntentAction || (IntentAction = {}));
|
|
132
|
+
var EXECUTION_LIMIT = 100;
|
|
133
|
+
var HISTORY_LIMIT = 100;
|
|
134
|
+
var createResolver = (schema, effect, params = {}) => ({
|
|
135
|
+
action: schema._tag,
|
|
136
|
+
effect,
|
|
137
|
+
...params
|
|
138
|
+
});
|
|
139
|
+
var isUndoable = (historyEntry) => historyEntry.length > 0 && historyEntry.every(({ undoable }) => !!undoable);
|
|
140
|
+
var createDispatcher = (resolvers, { executionLimit = EXECUTION_LIMIT, historyLimit = HISTORY_LIMIT } = {}) => {
|
|
141
|
+
const historyRef = import_effect2.Effect.runSync(import_effect2.Ref.make([]));
|
|
142
|
+
const handleIntent = (intent) => {
|
|
143
|
+
return import_effect2.Effect.gen(function* () {
|
|
144
|
+
const candidates = Object.entries(resolvers).filter(([id, _]) => intent.plugin ? id === intent.plugin : true).flatMap(([_, resolvers2]) => resolvers2).filter((r) => r.action === intent.action).filter((r) => !r.filter || r.filter(intent.data)).toSorted(({ disposition: a = "static" }, { disposition: b = "static" }) => {
|
|
145
|
+
return a === b ? 0 : a === "hoist" || b === "fallback" ? -1 : b === "hoist" || a === "fallback" ? 1 : 0;
|
|
146
|
+
});
|
|
147
|
+
if (candidates.length === 0) {
|
|
148
|
+
return {
|
|
149
|
+
_intent: intent,
|
|
150
|
+
error: new Error(`No resolver found for action: ${intent.action}`)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const effect = candidates[0].effect(intent.data, intent.undo ?? false);
|
|
154
|
+
const result = import_effect2.Effect.isEffect(effect) ? yield* effect : yield* import_effect2.Effect.promise(async () => effect);
|
|
155
|
+
return {
|
|
156
|
+
_intent: intent,
|
|
157
|
+
...result
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
const dispatch = (intentChain, depth = 0) => {
|
|
162
|
+
return import_effect2.Effect.gen(function* () {
|
|
163
|
+
if (depth > executionLimit) {
|
|
164
|
+
yield* import_effect2.Effect.fail(new Error("Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers."));
|
|
165
|
+
}
|
|
166
|
+
const resultsRef = yield* import_effect2.Ref.make([]);
|
|
167
|
+
for (const intent of intentChain.all) {
|
|
168
|
+
const { data: prev } = (yield* resultsRef.get)[0] ?? {};
|
|
169
|
+
const result2 = yield* handleIntent({
|
|
170
|
+
...intent,
|
|
171
|
+
data: {
|
|
172
|
+
...intent.data,
|
|
173
|
+
...prev
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
yield* import_effect2.Ref.update(resultsRef, (results2) => [
|
|
177
|
+
result2,
|
|
178
|
+
...results2
|
|
179
|
+
]);
|
|
180
|
+
if (result2.error) {
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
if (result2.intents) {
|
|
184
|
+
for (const intent2 of result2.intents) {
|
|
185
|
+
yield* dispatch(intent2, depth + 1);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const results = yield* resultsRef.get;
|
|
190
|
+
const result = results[0];
|
|
191
|
+
if (result) {
|
|
192
|
+
yield* import_effect2.Ref.update(historyRef, (history) => {
|
|
193
|
+
const next = [
|
|
194
|
+
...history,
|
|
195
|
+
results
|
|
196
|
+
];
|
|
197
|
+
if (next.length > historyLimit) {
|
|
198
|
+
next.splice(0, next.length - historyLimit);
|
|
199
|
+
}
|
|
200
|
+
return next;
|
|
201
|
+
});
|
|
202
|
+
if (result.undoable && isUndoable(results)) {
|
|
203
|
+
yield* dispatch(createIntent(IntentAction.ShowUndo, {
|
|
204
|
+
message: result.undoable.message
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
return (0, import_util2.pick)(result, [
|
|
208
|
+
"data",
|
|
209
|
+
"error"
|
|
210
|
+
]);
|
|
211
|
+
} else {
|
|
212
|
+
return {
|
|
213
|
+
data: {},
|
|
214
|
+
error: new Error("No results")
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
const dispatchPromise = (intentChain) => {
|
|
220
|
+
const program = dispatch(intentChain);
|
|
221
|
+
return import_effect2.Effect.runPromise(program);
|
|
222
|
+
};
|
|
223
|
+
const undo = () => {
|
|
224
|
+
return import_effect2.Effect.gen(function* () {
|
|
225
|
+
const history = yield* historyRef.get;
|
|
226
|
+
const last = history.findLastIndex(isUndoable);
|
|
227
|
+
const result = last !== -1 ? history[last] : void 0;
|
|
228
|
+
if (result) {
|
|
229
|
+
const all = result.map(({ _intent, undoable }) => {
|
|
230
|
+
const data = _intent.data;
|
|
231
|
+
const undoData = undoable?.data ?? {};
|
|
232
|
+
return {
|
|
233
|
+
..._intent,
|
|
234
|
+
data: {
|
|
235
|
+
...data,
|
|
236
|
+
...undoData
|
|
237
|
+
},
|
|
238
|
+
undo: true
|
|
239
|
+
};
|
|
240
|
+
});
|
|
241
|
+
const intent = {
|
|
242
|
+
first: all[0],
|
|
243
|
+
last: all.at(-1),
|
|
244
|
+
all
|
|
245
|
+
};
|
|
246
|
+
yield* import_effect2.Ref.update(historyRef, (h) => h.filter((_, index) => index !== last));
|
|
247
|
+
return yield* dispatch(intent);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
const undoPromise = () => {
|
|
252
|
+
const program = undo();
|
|
253
|
+
return import_effect2.Effect.runPromise(program);
|
|
254
|
+
};
|
|
255
|
+
const registerResolver = (id, resolver) => {
|
|
256
|
+
resolvers[id] = [
|
|
257
|
+
...resolvers[id] ?? [],
|
|
258
|
+
resolver
|
|
259
|
+
];
|
|
260
|
+
return () => {
|
|
261
|
+
resolvers[id] = resolvers[id].filter((r) => r !== resolver);
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
return {
|
|
265
|
+
dispatch,
|
|
266
|
+
dispatchPromise,
|
|
267
|
+
undo,
|
|
268
|
+
undoPromise,
|
|
269
|
+
registerResolver
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
var parseIntentPlugin = (plugin) => plugin.provides.intent?.dispatch ? plugin : void 0;
|
|
273
|
+
var parseIntentResolverPlugin = (plugin) => plugin.provides.intent?.resolvers ? plugin : void 0;
|
|
274
|
+
var defaultEffect = () => import_effect.Effect.fail(new Error("Intent runtime not ready"));
|
|
275
|
+
var defaultPromise = () => import_effect.Effect.runPromise(defaultEffect());
|
|
276
|
+
var IntentPlugin = () => {
|
|
277
|
+
const state = (0, import_live_object.create)({
|
|
278
|
+
dispatch: defaultEffect,
|
|
279
|
+
dispatchPromise: defaultPromise,
|
|
280
|
+
undo: defaultEffect,
|
|
281
|
+
undoPromise: defaultPromise,
|
|
282
|
+
registerResolver: () => () => {
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
return {
|
|
286
|
+
meta: meta_default,
|
|
287
|
+
ready: async ({ plugins }) => {
|
|
288
|
+
const resolvers = Object.fromEntries((0, import_chunk_QBM42OQ6.filterPlugins)(plugins, parseIntentResolverPlugin).map((plugin) => {
|
|
289
|
+
const resolvers2 = reduceResolvers(plugin.provides.intent.resolvers({
|
|
290
|
+
plugins,
|
|
291
|
+
dispatch: (intent) => state.dispatch(intent),
|
|
292
|
+
dispatchPromise: (intent) => state.dispatchPromise(intent),
|
|
293
|
+
undo: () => state.undo(),
|
|
294
|
+
undoPromise: () => state.undoPromise(),
|
|
295
|
+
registerResolver: (id, resolver) => state.registerResolver(id, resolver)
|
|
296
|
+
}));
|
|
297
|
+
return [
|
|
298
|
+
plugin.meta.id,
|
|
299
|
+
resolvers2
|
|
300
|
+
];
|
|
301
|
+
}));
|
|
302
|
+
const { dispatch, dispatchPromise, undo, undoPromise, registerResolver } = createDispatcher(resolvers);
|
|
303
|
+
state.dispatch = dispatch;
|
|
304
|
+
state.dispatchPromise = dispatchPromise;
|
|
305
|
+
state.undo = undo;
|
|
306
|
+
state.undoPromise = undoPromise;
|
|
307
|
+
state.registerResolver = registerResolver;
|
|
308
|
+
},
|
|
309
|
+
provides: {
|
|
310
|
+
intent: state,
|
|
311
|
+
context: ({ children }) => /* @__PURE__ */ import_react.default.createElement(IntentProvider, {
|
|
312
|
+
value: state
|
|
313
|
+
}, children)
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
};
|
|
317
|
+
var reduceResolvers = (definitions, resolvers = []) => {
|
|
318
|
+
if (Array.isArray(definitions)) {
|
|
319
|
+
return definitions.reduce((acc, definition) => reduceResolvers(definition, acc), resolvers);
|
|
320
|
+
}
|
|
321
|
+
return [
|
|
322
|
+
...resolvers,
|
|
323
|
+
definitions
|
|
324
|
+
];
|
|
325
|
+
};
|
|
326
|
+
var plugin_intent_default = IntentPlugin;
|
|
327
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
328
|
+
0 && (module.exports = {
|
|
329
|
+
INTENT_ACTION,
|
|
330
|
+
IntentAction,
|
|
331
|
+
IntentProvider,
|
|
332
|
+
Label,
|
|
333
|
+
chain,
|
|
334
|
+
createDispatcher,
|
|
335
|
+
createIntent,
|
|
336
|
+
createResolver,
|
|
337
|
+
meta_default,
|
|
338
|
+
parseIntentPlugin,
|
|
339
|
+
parseIntentResolverPlugin,
|
|
340
|
+
plugin_intent_default,
|
|
341
|
+
useIntentDispatcher,
|
|
342
|
+
useIntentResolver
|
|
343
|
+
});
|
|
344
|
+
//# sourceMappingURL=chunk-VWHAALIN.cjs.map
|