@dxos/app-framework 0.3.6 → 0.3.7-main.4df0bc8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/chunk-C2K6M6WC.mjs +27 -0
- package/dist/lib/browser/chunk-C2K6M6WC.mjs.map +7 -0
- package/dist/lib/browser/chunk-CFZ5JAJF.mjs +18 -0
- package/dist/lib/browser/chunk-CFZ5JAJF.mjs.map +7 -0
- package/dist/lib/browser/chunk-WDA7VA54.mjs +26 -0
- package/dist/lib/browser/chunk-WDA7VA54.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +142 -190
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/plugin-CBPJO5NB.mjs +63 -0
- package/dist/lib/browser/plugin-CBPJO5NB.mjs.map +7 -0
- package/dist/lib/browser/plugin-XEJ5RYCP.mjs +39 -0
- package/dist/lib/browser/plugin-XEJ5RYCP.mjs.map +7 -0
- package/dist/lib/node/index.cjs +334 -188
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/App.d.ts +13 -3
- package/dist/types/src/App.d.ts.map +1 -1
- package/dist/types/src/plugins/IntentPlugin/index.d.ts +1 -1
- package/dist/types/src/plugins/IntentPlugin/index.d.ts.map +1 -1
- package/dist/types/src/plugins/IntentPlugin/meta.d.ts +5 -0
- package/dist/types/src/plugins/IntentPlugin/meta.d.ts.map +1 -0
- package/dist/types/src/plugins/IntentPlugin/plugin.d.ts +9 -0
- package/dist/types/src/plugins/IntentPlugin/plugin.d.ts.map +1 -0
- package/dist/types/src/plugins/IntentPlugin/{IntentPlugin.d.ts → provides.d.ts} +2 -7
- package/dist/types/src/plugins/IntentPlugin/provides.d.ts.map +1 -0
- package/dist/types/src/plugins/PluginHost/PluginContext.d.ts +27 -3
- package/dist/types/src/plugins/PluginHost/PluginContext.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +7 -4
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts +49 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts +9 -4
- package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts +8 -2
- package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/index.d.ts +1 -1
- package/dist/types/src/plugins/SurfacePlugin/index.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/meta.d.ts +5 -0
- package/dist/types/src/plugins/SurfacePlugin/meta.d.ts.map +1 -0
- package/dist/types/src/plugins/SurfacePlugin/plugin.d.ts +8 -0
- package/dist/types/src/plugins/SurfacePlugin/plugin.d.ts.map +1 -0
- package/dist/types/src/plugins/SurfacePlugin/{SurfacePlugin.d.ts → provides.d.ts} +2 -6
- package/dist/types/src/plugins/SurfacePlugin/provides.d.ts.map +1 -0
- package/package.json +8 -6
- package/src/App.tsx +24 -6
- package/src/plugins/IntentPlugin/index.ts +2 -1
- package/src/plugins/IntentPlugin/meta.ts +9 -0
- package/src/plugins/IntentPlugin/{IntentPlugin.tsx → plugin.tsx} +8 -22
- package/src/plugins/IntentPlugin/provides.ts +23 -0
- package/src/plugins/PluginHost/PluginContext.tsx +36 -5
- package/src/plugins/PluginHost/PluginHost.tsx +59 -98
- package/src/plugins/PluginHost/plugin.ts +31 -1
- package/src/plugins/SurfacePlugin/Surface.tsx +34 -27
- package/src/plugins/SurfacePlugin/SurfaceRootContext.tsx +11 -2
- package/src/plugins/SurfacePlugin/index.ts +2 -1
- package/src/plugins/SurfacePlugin/meta.ts +9 -0
- package/src/plugins/SurfacePlugin/plugin.tsx +36 -0
- package/src/plugins/SurfacePlugin/provides.ts +25 -0
- package/tsconfig.json +3 -0
- package/dist/types/src/plugins/IntentPlugin/IntentPlugin.d.ts.map +0 -1
- package/dist/types/src/plugins/SurfacePlugin/SurfacePlugin.d.ts.map +0 -1
- package/src/plugins/SurfacePlugin/SurfacePlugin.tsx +0 -53
package/dist/lib/node/index.cjs
CHANGED
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -27,21 +30,215 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
30
|
));
|
|
28
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
32
|
|
|
33
|
+
// packages/sdk/app-framework/src/plugins/helpers.ts
|
|
34
|
+
var import_debug, findPlugin, getPlugin, filterPlugins, resolvePlugin;
|
|
35
|
+
var init_helpers = __esm({
|
|
36
|
+
"packages/sdk/app-framework/src/plugins/helpers.ts"() {
|
|
37
|
+
"use strict";
|
|
38
|
+
import_debug = require("@dxos/debug");
|
|
39
|
+
findPlugin = (plugins, id) => {
|
|
40
|
+
return plugins.find((plugin) => plugin.meta.id === id || typeof plugin.meta.shortId === "string" && plugin.meta.shortId === id);
|
|
41
|
+
};
|
|
42
|
+
getPlugin = (plugins, id) => {
|
|
43
|
+
return findPlugin(plugins, id) ?? (0, import_debug.raise)(new Error(`Plugin not found: ${id}`));
|
|
44
|
+
};
|
|
45
|
+
filterPlugins = (plugins, predicate) => plugins.map((plugin) => predicate(plugin)).filter((plugin) => !!plugin);
|
|
46
|
+
resolvePlugin = (plugins, predicate) => filterPlugins(plugins, predicate)[0];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// packages/sdk/app-framework/src/plugins/IntentPlugin/provides.ts
|
|
51
|
+
var parseIntentPlugin, parseIntentResolverPlugin;
|
|
52
|
+
var init_provides = __esm({
|
|
53
|
+
"packages/sdk/app-framework/src/plugins/IntentPlugin/provides.ts"() {
|
|
54
|
+
"use strict";
|
|
55
|
+
parseIntentPlugin = (plugin) => plugin.provides.intent?.dispatch ? plugin : void 0;
|
|
56
|
+
parseIntentResolverPlugin = (plugin) => plugin.provides.intent?.resolver ? plugin : void 0;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// packages/sdk/app-framework/src/plugins/IntentPlugin/IntentContext.tsx
|
|
61
|
+
var import_react, IntentContext, useIntent, IntentProvider;
|
|
62
|
+
var init_IntentContext = __esm({
|
|
63
|
+
"packages/sdk/app-framework/src/plugins/IntentPlugin/IntentContext.tsx"() {
|
|
64
|
+
"use strict";
|
|
65
|
+
import_react = require("react");
|
|
66
|
+
IntentContext = /* @__PURE__ */ (0, import_react.createContext)({
|
|
67
|
+
dispatch: async () => {
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
useIntent = () => (0, import_react.useContext)(IntentContext);
|
|
71
|
+
IntentProvider = IntentContext.Provider;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// packages/sdk/app-framework/src/plugins/SurfacePlugin/provides.ts
|
|
76
|
+
var parseRootSurfacePlugin, parseSurfacePlugin;
|
|
77
|
+
var init_provides2 = __esm({
|
|
78
|
+
"packages/sdk/app-framework/src/plugins/SurfacePlugin/provides.ts"() {
|
|
79
|
+
"use strict";
|
|
80
|
+
parseRootSurfacePlugin = (plugin) => plugin?.provides?.surface?.components ? plugin : void 0;
|
|
81
|
+
parseSurfacePlugin = (plugin) => plugin?.provides?.surface?.component ? plugin : void 0;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// packages/sdk/app-framework/src/plugins/SurfacePlugin/SurfaceRootContext.tsx
|
|
86
|
+
var import_react6, SurfaceRootContext, useSurface, SurfaceProvider;
|
|
87
|
+
var init_SurfaceRootContext = __esm({
|
|
88
|
+
"packages/sdk/app-framework/src/plugins/SurfacePlugin/SurfaceRootContext.tsx"() {
|
|
89
|
+
"use strict";
|
|
90
|
+
import_react6 = require("react");
|
|
91
|
+
SurfaceRootContext = /* @__PURE__ */ (0, import_react6.createContext)({
|
|
92
|
+
components: {}
|
|
93
|
+
});
|
|
94
|
+
useSurface = () => (0, import_react6.useContext)(SurfaceRootContext);
|
|
95
|
+
SurfaceProvider = SurfaceRootContext.Provider;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// packages/sdk/app-framework/src/plugins/IntentPlugin/meta.ts
|
|
100
|
+
var IntentMeta, meta_default;
|
|
101
|
+
var init_meta = __esm({
|
|
102
|
+
"packages/sdk/app-framework/src/plugins/IntentPlugin/meta.ts"() {
|
|
103
|
+
"use strict";
|
|
104
|
+
IntentMeta = {
|
|
105
|
+
id: "dxos.org/plugin/intent"
|
|
106
|
+
};
|
|
107
|
+
meta_default = IntentMeta;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// packages/sdk/app-framework/src/plugins/SurfacePlugin/meta.ts
|
|
112
|
+
var SurfaceMeta, meta_default2;
|
|
113
|
+
var init_meta2 = __esm({
|
|
114
|
+
"packages/sdk/app-framework/src/plugins/SurfacePlugin/meta.ts"() {
|
|
115
|
+
"use strict";
|
|
116
|
+
SurfaceMeta = {
|
|
117
|
+
id: "dxos.org/plugin/surface"
|
|
118
|
+
};
|
|
119
|
+
meta_default2 = SurfaceMeta;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// packages/sdk/app-framework/src/plugins/SurfacePlugin/plugin.tsx
|
|
124
|
+
var plugin_exports = {};
|
|
125
|
+
__export(plugin_exports, {
|
|
126
|
+
default: () => plugin_default
|
|
127
|
+
});
|
|
128
|
+
var import_react9, import_react10, SurfacePlugin, plugin_default;
|
|
129
|
+
var init_plugin = __esm({
|
|
130
|
+
"packages/sdk/app-framework/src/plugins/SurfacePlugin/plugin.tsx"() {
|
|
131
|
+
"use strict";
|
|
132
|
+
import_react9 = require("deepsignal/react");
|
|
133
|
+
import_react10 = __toESM(require("react"));
|
|
134
|
+
init_SurfaceRootContext();
|
|
135
|
+
init_meta2();
|
|
136
|
+
init_provides2();
|
|
137
|
+
init_helpers();
|
|
138
|
+
SurfacePlugin = () => {
|
|
139
|
+
const state = (0, import_react9.deepSignal)({
|
|
140
|
+
components: {}
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
meta: meta_default2,
|
|
144
|
+
ready: async (plugins) => {
|
|
145
|
+
state.components = (0, import_react9.shallow)(filterPlugins(plugins, parseSurfacePlugin).reduce((acc, plugin) => {
|
|
146
|
+
return {
|
|
147
|
+
...acc,
|
|
148
|
+
[plugin.meta.id]: plugin.provides.surface.component
|
|
149
|
+
};
|
|
150
|
+
}, {}));
|
|
151
|
+
},
|
|
152
|
+
provides: {
|
|
153
|
+
surface: state,
|
|
154
|
+
context: ({ children }) => /* @__PURE__ */ import_react10.default.createElement(SurfaceProvider, {
|
|
155
|
+
value: state
|
|
156
|
+
}, children)
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
plugin_default = SurfacePlugin;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// packages/sdk/app-framework/src/plugins/IntentPlugin/plugin.tsx
|
|
165
|
+
var plugin_exports2 = {};
|
|
166
|
+
__export(plugin_exports2, {
|
|
167
|
+
default: () => plugin_default2
|
|
168
|
+
});
|
|
169
|
+
var import_react11, import_react12, IntentPlugin, plugin_default2;
|
|
170
|
+
var init_plugin2 = __esm({
|
|
171
|
+
"packages/sdk/app-framework/src/plugins/IntentPlugin/plugin.tsx"() {
|
|
172
|
+
"use strict";
|
|
173
|
+
import_react11 = require("deepsignal/react");
|
|
174
|
+
import_react12 = __toESM(require("react"));
|
|
175
|
+
init_IntentContext();
|
|
176
|
+
init_meta();
|
|
177
|
+
init_provides();
|
|
178
|
+
init_helpers();
|
|
179
|
+
IntentPlugin = () => {
|
|
180
|
+
const state = (0, import_react11.deepSignal)({
|
|
181
|
+
dispatch: async () => {
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
meta: meta_default,
|
|
186
|
+
ready: async (plugins) => {
|
|
187
|
+
const dispatch = async (intent) => {
|
|
188
|
+
if (intent.plugin) {
|
|
189
|
+
const plugin = findPlugin(plugins, intent.plugin);
|
|
190
|
+
return plugin?.provides.intent.resolver(intent, plugins);
|
|
191
|
+
}
|
|
192
|
+
for (const plugin of filterPlugins(plugins, parseIntentResolverPlugin)) {
|
|
193
|
+
const result = await plugin.provides.intent.resolver(intent, plugins);
|
|
194
|
+
if (result) {
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
state.dispatch = async (intentOrArray) => {
|
|
200
|
+
let result = null;
|
|
201
|
+
for (const intent of Array.isArray(intentOrArray) ? intentOrArray : [
|
|
202
|
+
intentOrArray
|
|
203
|
+
]) {
|
|
204
|
+
const data = intent.data ? {
|
|
205
|
+
...result,
|
|
206
|
+
...intent.data
|
|
207
|
+
} : result;
|
|
208
|
+
result = await dispatch({
|
|
209
|
+
...intent,
|
|
210
|
+
data
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
};
|
|
215
|
+
},
|
|
216
|
+
provides: {
|
|
217
|
+
intent: state,
|
|
218
|
+
context: ({ children }) => /* @__PURE__ */ import_react12.default.createElement(IntentProvider, {
|
|
219
|
+
value: state
|
|
220
|
+
}, children)
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
plugin_default2 = IntentPlugin;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
30
228
|
// packages/sdk/app-framework/src/index.ts
|
|
31
229
|
var src_exports = {};
|
|
32
230
|
__export(src_exports, {
|
|
33
231
|
ErrorBoundary: () => ErrorBoundary,
|
|
34
|
-
IntentPlugin: () => IntentPlugin,
|
|
35
232
|
IntentProvider: () => IntentProvider,
|
|
36
233
|
Layout: () => Layout,
|
|
37
234
|
LayoutAction: () => LayoutAction,
|
|
235
|
+
Plugin: () => Plugin,
|
|
38
236
|
PluginHost: () => PluginHost,
|
|
39
237
|
PluginProvider: () => PluginProvider,
|
|
40
238
|
Resource: () => Resource,
|
|
41
239
|
ResourceKey: () => ResourceKey,
|
|
42
240
|
ResourceLanguage: () => ResourceLanguage,
|
|
43
241
|
Surface: () => Surface,
|
|
44
|
-
SurfacePlugin: () => SurfacePlugin,
|
|
45
242
|
SurfaceProvider: () => SurfaceProvider,
|
|
46
243
|
createApp: () => createApp,
|
|
47
244
|
filterPlugins: () => filterPlugins,
|
|
@@ -59,6 +256,7 @@ __export(src_exports, {
|
|
|
59
256
|
parseRootSurfacePlugin: () => parseRootSurfacePlugin,
|
|
60
257
|
parseSurfacePlugin: () => parseSurfacePlugin,
|
|
61
258
|
parseTranslationsPlugin: () => parseTranslationsPlugin,
|
|
259
|
+
pluginMeta: () => pluginMeta,
|
|
62
260
|
resolvePlugin: () => resolvePlugin,
|
|
63
261
|
useIntent: () => useIntent,
|
|
64
262
|
usePlugin: () => usePlugin,
|
|
@@ -126,88 +324,38 @@ var parseTranslationsPlugin = (plugin) => {
|
|
|
126
324
|
return success ? plugin : void 0;
|
|
127
325
|
};
|
|
128
326
|
|
|
129
|
-
// packages/sdk/app-framework/src/plugins/
|
|
130
|
-
|
|
131
|
-
var findPlugin = (plugins, id) => {
|
|
132
|
-
return plugins.find((plugin) => plugin.meta.id === id || typeof plugin.meta.shortId === "string" && plugin.meta.shortId === id);
|
|
133
|
-
};
|
|
134
|
-
var getPlugin = (plugins, id) => {
|
|
135
|
-
return findPlugin(plugins, id) ?? (0, import_debug.raise)(new Error(`Plugin not found: ${id}`));
|
|
136
|
-
};
|
|
137
|
-
var filterPlugins = (plugins, predicate) => plugins.map((plugin) => predicate(plugin)).filter((plugin) => !!plugin);
|
|
138
|
-
var resolvePlugin = (plugins, predicate) => filterPlugins(plugins, predicate)[0];
|
|
327
|
+
// packages/sdk/app-framework/src/plugins/index.ts
|
|
328
|
+
init_helpers();
|
|
139
329
|
|
|
140
|
-
// packages/sdk/app-framework/src/plugins/IntentPlugin/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
dispatch: async () => {
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
var useIntent = () => (0, import_react.useContext)(IntentContext);
|
|
147
|
-
var IntentProvider = IntentContext.Provider;
|
|
330
|
+
// packages/sdk/app-framework/src/plugins/IntentPlugin/index.ts
|
|
331
|
+
init_provides();
|
|
332
|
+
init_IntentContext();
|
|
148
333
|
|
|
149
|
-
// packages/sdk/app-framework/src/plugins/
|
|
150
|
-
var
|
|
151
|
-
var
|
|
152
|
-
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
return {
|
|
160
|
-
meta: {
|
|
161
|
-
id: "dxos.org/plugin/intent"
|
|
162
|
-
},
|
|
163
|
-
ready: async (plugins) => {
|
|
164
|
-
const dispatch = async (intent) => {
|
|
165
|
-
if (intent.plugin) {
|
|
166
|
-
const plugin = findPlugin(plugins, intent.plugin);
|
|
167
|
-
return plugin?.provides.intent.resolver(intent, plugins);
|
|
168
|
-
}
|
|
169
|
-
for (const plugin of filterPlugins(plugins, parseIntentResolverPlugin)) {
|
|
170
|
-
const result = await plugin.provides.intent.resolver(intent, plugins);
|
|
171
|
-
if (result) {
|
|
172
|
-
return result;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
state.dispatch = async (intentOrArray) => {
|
|
177
|
-
let result = null;
|
|
178
|
-
for (const intent of Array.isArray(intentOrArray) ? intentOrArray : [
|
|
179
|
-
intentOrArray
|
|
180
|
-
]) {
|
|
181
|
-
const data = intent.data ? {
|
|
182
|
-
...result,
|
|
183
|
-
...intent.data
|
|
184
|
-
} : result;
|
|
185
|
-
result = await dispatch({
|
|
186
|
-
...intent,
|
|
187
|
-
data
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
return result;
|
|
191
|
-
};
|
|
192
|
-
},
|
|
193
|
-
provides: {
|
|
194
|
-
intent: state,
|
|
195
|
-
context: ({ children }) => /* @__PURE__ */ import_react3.default.createElement(IntentProvider, {
|
|
196
|
-
value: state
|
|
197
|
-
}, children)
|
|
198
|
-
}
|
|
334
|
+
// packages/sdk/app-framework/src/plugins/PluginHost/plugin.ts
|
|
335
|
+
var pluginMeta = (meta) => meta;
|
|
336
|
+
var Plugin;
|
|
337
|
+
(function(Plugin2) {
|
|
338
|
+
var lazy = Plugin2.lazy = (p, props) => {
|
|
339
|
+
return () => p().then(({ default: definition }) => {
|
|
340
|
+
return definition(props);
|
|
341
|
+
});
|
|
199
342
|
};
|
|
200
|
-
};
|
|
343
|
+
})(Plugin || (Plugin = {}));
|
|
201
344
|
|
|
202
345
|
// packages/sdk/app-framework/src/plugins/PluginHost/PluginContext.tsx
|
|
203
|
-
var
|
|
204
|
-
|
|
346
|
+
var import_react2 = require("react");
|
|
347
|
+
init_helpers();
|
|
348
|
+
var PluginContext = /* @__PURE__ */ (0, import_react2.createContext)({
|
|
205
349
|
ready: false,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
350
|
+
enabled: [],
|
|
351
|
+
plugins: [],
|
|
352
|
+
available: [],
|
|
353
|
+
enablePlugin: () => {
|
|
354
|
+
},
|
|
355
|
+
disablePlugin: () => {
|
|
356
|
+
}
|
|
209
357
|
});
|
|
210
|
-
var usePlugins = () => (0,
|
|
358
|
+
var usePlugins = () => (0, import_react2.useContext)(PluginContext);
|
|
211
359
|
var usePlugin = (id) => {
|
|
212
360
|
const { plugins } = usePlugins();
|
|
213
361
|
return findPlugin(plugins, id);
|
|
@@ -219,90 +367,101 @@ var useResolvePlugin = (predicate) => {
|
|
|
219
367
|
var PluginProvider = PluginContext.Provider;
|
|
220
368
|
|
|
221
369
|
// packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx
|
|
222
|
-
var
|
|
223
|
-
var
|
|
370
|
+
var import_react3 = require("deepsignal/react");
|
|
371
|
+
var import_react4 = __toESM(require("react"));
|
|
372
|
+
var import_local_storage = require("@dxos/local-storage");
|
|
224
373
|
var import_log = require("@dxos/log");
|
|
225
|
-
var __dxlog_file = "/home/
|
|
374
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx";
|
|
226
375
|
var parsePluginHost = (plugin) => plugin.provides.plugins ? plugin : void 0;
|
|
227
|
-
var
|
|
228
|
-
|
|
376
|
+
var PLUGIN_HOST = "dxos.org/plugin/host";
|
|
377
|
+
var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallback = null }) => {
|
|
378
|
+
const state = new import_local_storage.LocalStorageStore(PLUGIN_HOST, {
|
|
229
379
|
ready: false,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
380
|
+
enabled: [
|
|
381
|
+
...defaults
|
|
382
|
+
],
|
|
383
|
+
plugins: [],
|
|
384
|
+
available: order.filter(({ id }) => !core.includes(id)),
|
|
385
|
+
enablePlugin: (id) => {
|
|
386
|
+
state.values.enabled = [
|
|
387
|
+
...state.values.enabled,
|
|
388
|
+
id
|
|
389
|
+
];
|
|
390
|
+
},
|
|
391
|
+
disablePlugin: (id) => {
|
|
392
|
+
state.values.enabled = state.values.enabled.filter((enabled) => enabled !== id);
|
|
393
|
+
}
|
|
233
394
|
});
|
|
395
|
+
state.prop(state.values.$enabled, "enabled", import_local_storage.LocalStorageStore.json);
|
|
234
396
|
return {
|
|
235
397
|
meta: {
|
|
236
|
-
id:
|
|
398
|
+
id: PLUGIN_HOST,
|
|
399
|
+
name: "Plugin host"
|
|
237
400
|
},
|
|
238
401
|
provides: {
|
|
239
|
-
plugins: state,
|
|
240
|
-
context: ({ children }) => /* @__PURE__ */
|
|
241
|
-
value: state
|
|
402
|
+
plugins: state.values,
|
|
403
|
+
context: ({ children }) => /* @__PURE__ */ import_react4.default.createElement(PluginProvider, {
|
|
404
|
+
value: state.values
|
|
242
405
|
}, children),
|
|
243
406
|
root: () => {
|
|
244
|
-
(0,
|
|
407
|
+
(0, import_react4.useEffect)(() => {
|
|
245
408
|
(0, import_log.log)("initializing plugins", {
|
|
246
|
-
|
|
409
|
+
enabled: state.values.enabled
|
|
247
410
|
}, {
|
|
248
411
|
F: __dxlog_file,
|
|
249
|
-
L:
|
|
412
|
+
L: 66,
|
|
250
413
|
S: void 0,
|
|
251
414
|
C: (f, a) => f(...a)
|
|
252
415
|
});
|
|
253
416
|
const timeout = setTimeout(async () => {
|
|
254
|
-
|
|
255
|
-
|
|
417
|
+
const enabledIds = [
|
|
418
|
+
...core,
|
|
419
|
+
...state.values.enabled
|
|
420
|
+
].sort((a, b) => {
|
|
421
|
+
const indexA = order.findIndex(({ id }) => id === a);
|
|
422
|
+
const indexB = order.findIndex(({ id }) => id === b);
|
|
423
|
+
return indexA - indexB;
|
|
424
|
+
});
|
|
425
|
+
const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
|
|
426
|
+
const plugins = await Promise.all(enabled.map(async (definition) => {
|
|
256
427
|
const plugin = await initializePlugin(definition).catch((err) => {
|
|
257
428
|
console.error("Failed to initialize plugin:", definition.meta.id, err);
|
|
258
429
|
return void 0;
|
|
259
430
|
});
|
|
260
|
-
state.initializing = (0, import_react5.shallow)(state.initializing.filter((plugin2) => plugin2 !== definition));
|
|
261
431
|
return plugin;
|
|
262
432
|
})).then((plugins2) => plugins2.filter((plugin) => Boolean(plugin)));
|
|
263
433
|
(0, import_log.log)("plugins initialized", {
|
|
264
434
|
plugins
|
|
265
435
|
}, {
|
|
266
436
|
F: __dxlog_file,
|
|
267
|
-
L:
|
|
437
|
+
L: 91,
|
|
268
438
|
S: void 0,
|
|
269
439
|
C: (f, a) => f(...a)
|
|
270
440
|
});
|
|
271
|
-
|
|
272
|
-
await Promise.all(definitions.map(async (pluginDefinition) => {
|
|
441
|
+
await Promise.all(enabled.map(async (pluginDefinition) => {
|
|
273
442
|
await pluginDefinition.ready?.(plugins);
|
|
274
|
-
state.loading = (0, import_react5.shallow)(state.loading.filter((plugin) => plugin !== pluginDefinition));
|
|
275
443
|
}));
|
|
276
444
|
(0, import_log.log)("plugins ready", {
|
|
277
445
|
plugins
|
|
278
446
|
}, {
|
|
279
447
|
F: __dxlog_file,
|
|
280
|
-
L:
|
|
448
|
+
L: 98,
|
|
281
449
|
S: void 0,
|
|
282
450
|
C: (f, a) => f(...a)
|
|
283
451
|
});
|
|
284
|
-
state.plugins = (0,
|
|
285
|
-
state.ready = true;
|
|
452
|
+
state.values.plugins = (0, import_react3.shallow)(plugins);
|
|
453
|
+
state.values.ready = true;
|
|
286
454
|
});
|
|
287
455
|
return () => {
|
|
288
456
|
clearTimeout(timeout);
|
|
289
|
-
state.ready = false;
|
|
290
|
-
void Promise.all(definitions.map((definition) => definition.unload?.()));
|
|
457
|
+
state.values.ready = false;
|
|
291
458
|
};
|
|
292
459
|
}, []);
|
|
293
|
-
if (!state.ready) {
|
|
294
|
-
|
|
295
|
-
const FallbackComponent = fallback;
|
|
296
|
-
return /* @__PURE__ */ import_react6.default.createElement(FallbackComponent, {
|
|
297
|
-
initializing: state.initializing,
|
|
298
|
-
loading: state.loading,
|
|
299
|
-
plugins: state.plugins
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
return /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, fallback ?? null);
|
|
460
|
+
if (!state.values.ready) {
|
|
461
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, fallback);
|
|
303
462
|
}
|
|
304
|
-
const ComposedContext = composeContext(state.plugins);
|
|
305
|
-
return /* @__PURE__ */
|
|
463
|
+
const ComposedContext = composeContext(state.values.plugins);
|
|
464
|
+
return /* @__PURE__ */ import_react4.default.createElement(ComposedContext, null, rootComponents(state.values.plugins));
|
|
306
465
|
}
|
|
307
466
|
}
|
|
308
467
|
};
|
|
@@ -321,7 +480,7 @@ var rootComponents = (plugins) => {
|
|
|
321
480
|
return plugins.map((plugin) => {
|
|
322
481
|
const Component2 = plugin.provides.root;
|
|
323
482
|
if (Component2) {
|
|
324
|
-
return /* @__PURE__ */
|
|
483
|
+
return /* @__PURE__ */ import_react4.default.createElement(Component2, {
|
|
325
484
|
key: plugin.meta.id
|
|
326
485
|
});
|
|
327
486
|
} else {
|
|
@@ -335,12 +494,15 @@ var composeContext = (plugins) => {
|
|
|
335
494
|
var compose = (contexts) => {
|
|
336
495
|
return [
|
|
337
496
|
...contexts
|
|
338
|
-
].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */
|
|
497
|
+
].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ import_react4.default.createElement(Acc, null, /* @__PURE__ */ import_react4.default.createElement(Next, null, children)));
|
|
339
498
|
};
|
|
340
499
|
|
|
500
|
+
// packages/sdk/app-framework/src/plugins/SurfacePlugin/index.ts
|
|
501
|
+
init_provides2();
|
|
502
|
+
|
|
341
503
|
// packages/sdk/app-framework/src/plugins/SurfacePlugin/ErrorBoundary.tsx
|
|
342
|
-
var
|
|
343
|
-
var ErrorBoundary = class extends
|
|
504
|
+
var import_react5 = __toESM(require("react"));
|
|
505
|
+
var ErrorBoundary = class extends import_react5.Component {
|
|
344
506
|
constructor(props) {
|
|
345
507
|
super(props);
|
|
346
508
|
this.state = {
|
|
@@ -359,7 +521,7 @@ var ErrorBoundary = class extends import_react7.Component {
|
|
|
359
521
|
}
|
|
360
522
|
render() {
|
|
361
523
|
if (this.state.error) {
|
|
362
|
-
return /* @__PURE__ */
|
|
524
|
+
return /* @__PURE__ */ import_react5.default.createElement(this.props.fallback, {
|
|
363
525
|
error: this.state.error,
|
|
364
526
|
reset: this.resetError
|
|
365
527
|
});
|
|
@@ -374,37 +536,34 @@ var ErrorBoundary = class extends import_react7.Component {
|
|
|
374
536
|
};
|
|
375
537
|
|
|
376
538
|
// packages/sdk/app-framework/src/plugins/SurfacePlugin/Surface.tsx
|
|
377
|
-
var
|
|
378
|
-
var import_react10 = require("react");
|
|
379
|
-
|
|
380
|
-
// packages/sdk/app-framework/src/plugins/SurfacePlugin/SurfaceRootContext.tsx
|
|
539
|
+
var import_react7 = __toESM(require("react"));
|
|
381
540
|
var import_react8 = require("react");
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
});
|
|
385
|
-
var useSurface = () => (0, import_react8.useContext)(SurfaceRootContext);
|
|
386
|
-
var SurfaceProvider = SurfaceRootContext.Provider;
|
|
387
|
-
|
|
388
|
-
// packages/sdk/app-framework/src/plugins/SurfacePlugin/Surface.tsx
|
|
389
|
-
var Surface = ({ role, name = role, fallback, ...rest }) => {
|
|
541
|
+
init_SurfaceRootContext();
|
|
542
|
+
var Surface = /* @__PURE__ */ (0, import_react7.forwardRef)(({ role, name = role, fallback, ...rest }, forwardedRef) => {
|
|
390
543
|
const props = {
|
|
391
544
|
role,
|
|
392
545
|
name,
|
|
393
546
|
fallback,
|
|
394
547
|
...rest
|
|
395
548
|
};
|
|
396
|
-
const context = (0,
|
|
549
|
+
const context = (0, import_react8.useContext)(SurfaceContext);
|
|
397
550
|
const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
|
|
398
|
-
return /* @__PURE__ */
|
|
551
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react7.default.Fragment, null, fallback ? /* @__PURE__ */ import_react7.default.createElement(ErrorBoundary, {
|
|
399
552
|
data,
|
|
400
553
|
fallback
|
|
401
|
-
}, /* @__PURE__ */
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
554
|
+
}, /* @__PURE__ */ import_react7.default.createElement(SurfaceResolver, {
|
|
555
|
+
...props,
|
|
556
|
+
ref: forwardedRef
|
|
557
|
+
})) : /* @__PURE__ */ import_react7.default.createElement(SurfaceResolver, {
|
|
558
|
+
...props,
|
|
559
|
+
ref: forwardedRef
|
|
560
|
+
}));
|
|
561
|
+
});
|
|
562
|
+
var SurfaceContext = /* @__PURE__ */ (0, import_react8.createContext)(null);
|
|
563
|
+
var SurfaceResolver = /* @__PURE__ */ (0, import_react7.forwardRef)((props, forwardedRef) => {
|
|
405
564
|
const { components } = useSurface();
|
|
406
|
-
const parent = (0,
|
|
407
|
-
const nodes = resolveNodes(components, props, parent);
|
|
565
|
+
const parent = (0, import_react8.useContext)(SurfaceContext);
|
|
566
|
+
const nodes = resolveNodes(components, props, parent, forwardedRef);
|
|
408
567
|
const currentContext = {
|
|
409
568
|
...props,
|
|
410
569
|
surfaces: {
|
|
@@ -412,71 +571,58 @@ var SurfaceResolver = (props) => {
|
|
|
412
571
|
...props.surfaces
|
|
413
572
|
}
|
|
414
573
|
};
|
|
415
|
-
return /* @__PURE__ */
|
|
574
|
+
return /* @__PURE__ */ import_react7.default.createElement(SurfaceContext.Provider, {
|
|
416
575
|
value: currentContext
|
|
417
|
-
}, nodes.length > 0 ? nodes : props.contentFallback ? /* @__PURE__ */
|
|
418
|
-
};
|
|
419
|
-
var resolveNodes = (components, props, context) => {
|
|
576
|
+
}, nodes.length > 0 ? nodes : props.contentFallback ? /* @__PURE__ */ import_react7.default.createElement(props.contentFallback, null) : null);
|
|
577
|
+
});
|
|
578
|
+
var resolveNodes = (components, props, context, forwardedRef) => {
|
|
420
579
|
const data = {
|
|
421
580
|
...props.name && context?.surfaces?.[props.name]?.data || {},
|
|
422
581
|
...props.data
|
|
423
582
|
};
|
|
424
583
|
const nodes = Object.entries(components).map(([key, component]) => {
|
|
425
|
-
const result = component(
|
|
426
|
-
|
|
584
|
+
const result = component({
|
|
585
|
+
...props,
|
|
586
|
+
data
|
|
587
|
+
}, forwardedRef);
|
|
588
|
+
return result ? /* @__PURE__ */ import_react7.default.createElement(import_react7.Fragment, {
|
|
427
589
|
key
|
|
428
590
|
}, result) : void 0;
|
|
429
591
|
}).filter((Component2) => Boolean(Component2));
|
|
430
592
|
return props.limit ? nodes.slice(0, props.limit) : nodes;
|
|
431
593
|
};
|
|
432
|
-
var Wrapper = ({ children }) => /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null, children);
|
|
433
594
|
|
|
434
|
-
// packages/sdk/app-framework/src/plugins/SurfacePlugin/
|
|
435
|
-
|
|
436
|
-
var import_react12 = __toESM(require("react"));
|
|
437
|
-
var parseRootSurfacePlugin = (plugin) => plugin?.provides?.surface?.components ? plugin : void 0;
|
|
438
|
-
var parseSurfacePlugin = (plugin) => plugin?.provides?.surface?.component ? plugin : void 0;
|
|
439
|
-
var SurfacePlugin = () => {
|
|
440
|
-
const state = (0, import_react11.deepSignal)({
|
|
441
|
-
components: {}
|
|
442
|
-
});
|
|
443
|
-
return {
|
|
444
|
-
meta: {
|
|
445
|
-
id: "dxos.org/plugin/surface"
|
|
446
|
-
},
|
|
447
|
-
ready: async (plugins) => {
|
|
448
|
-
state.components = (0, import_react11.shallow)(filterPlugins(plugins, parseSurfacePlugin).reduce((acc, plugin) => {
|
|
449
|
-
return {
|
|
450
|
-
...acc,
|
|
451
|
-
[plugin.meta.id]: plugin.provides.surface.component
|
|
452
|
-
};
|
|
453
|
-
}, {}));
|
|
454
|
-
},
|
|
455
|
-
provides: {
|
|
456
|
-
surface: state,
|
|
457
|
-
context: ({ children }) => /* @__PURE__ */ import_react12.default.createElement(SurfaceProvider, {
|
|
458
|
-
value: state
|
|
459
|
-
}, children)
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
};
|
|
595
|
+
// packages/sdk/app-framework/src/plugins/SurfacePlugin/index.ts
|
|
596
|
+
init_SurfaceRootContext();
|
|
463
597
|
|
|
464
598
|
// packages/sdk/app-framework/src/App.tsx
|
|
465
599
|
var import_react13 = __toESM(require("react"));
|
|
466
600
|
var import_invariant = require("@dxos/invariant");
|
|
467
|
-
|
|
468
|
-
|
|
601
|
+
init_meta();
|
|
602
|
+
init_meta2();
|
|
603
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/App.tsx";
|
|
604
|
+
var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }) => {
|
|
469
605
|
const host = PluginHost({
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
...
|
|
606
|
+
order: [
|
|
607
|
+
meta_default2,
|
|
608
|
+
meta_default,
|
|
609
|
+
...order
|
|
474
610
|
],
|
|
475
|
-
|
|
611
|
+
plugins: {
|
|
612
|
+
...plugins,
|
|
613
|
+
[meta_default2.id]: Plugin.lazy(() => Promise.resolve().then(() => (init_plugin(), plugin_exports))),
|
|
614
|
+
[meta_default.id]: Plugin.lazy(() => Promise.resolve().then(() => (init_plugin2(), plugin_exports2)))
|
|
615
|
+
},
|
|
616
|
+
core: [
|
|
617
|
+
meta_default2.id,
|
|
618
|
+
meta_default.id,
|
|
619
|
+
...core
|
|
620
|
+
],
|
|
621
|
+
...params
|
|
476
622
|
});
|
|
477
623
|
(0, import_invariant.invariant)(host.provides?.context, void 0, {
|
|
478
624
|
F: __dxlog_file2,
|
|
479
|
-
L:
|
|
625
|
+
L: 51,
|
|
480
626
|
S: void 0,
|
|
481
627
|
A: [
|
|
482
628
|
"host.provides?.context",
|
|
@@ -485,7 +631,7 @@ var createApp = ({ plugins, fallback }) => {
|
|
|
485
631
|
});
|
|
486
632
|
(0, import_invariant.invariant)(host.provides?.root, void 0, {
|
|
487
633
|
F: __dxlog_file2,
|
|
488
|
-
L:
|
|
634
|
+
L: 52,
|
|
489
635
|
S: void 0,
|
|
490
636
|
A: [
|
|
491
637
|
"host.provides?.root",
|
|
@@ -499,17 +645,16 @@ var createApp = ({ plugins, fallback }) => {
|
|
|
499
645
|
// Annotate the CommonJS export names for ESM import in node:
|
|
500
646
|
0 && (module.exports = {
|
|
501
647
|
ErrorBoundary,
|
|
502
|
-
IntentPlugin,
|
|
503
648
|
IntentProvider,
|
|
504
649
|
Layout,
|
|
505
650
|
LayoutAction,
|
|
651
|
+
Plugin,
|
|
506
652
|
PluginHost,
|
|
507
653
|
PluginProvider,
|
|
508
654
|
Resource,
|
|
509
655
|
ResourceKey,
|
|
510
656
|
ResourceLanguage,
|
|
511
657
|
Surface,
|
|
512
|
-
SurfacePlugin,
|
|
513
658
|
SurfaceProvider,
|
|
514
659
|
createApp,
|
|
515
660
|
filterPlugins,
|
|
@@ -527,6 +672,7 @@ var createApp = ({ plugins, fallback }) => {
|
|
|
527
672
|
parseRootSurfacePlugin,
|
|
528
673
|
parseSurfacePlugin,
|
|
529
674
|
parseTranslationsPlugin,
|
|
675
|
+
pluginMeta,
|
|
530
676
|
resolvePlugin,
|
|
531
677
|
useIntent,
|
|
532
678
|
usePlugin,
|