@dxos/app-framework 0.6.11 → 0.6.12-main.5cc132e
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/node-esm/chunk-J45KR4DI.mjs +52 -0
- package/dist/lib/node-esm/chunk-J45KR4DI.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-S5CI6EUQ.mjs +20 -0
- package/dist/lib/node-esm/chunk-S5CI6EUQ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-YYV26N3W.mjs +26 -0
- package/dist/lib/node-esm/chunk-YYV26N3W.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +676 -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-K3KCPCTJ.mjs +39 -0
- package/dist/lib/node-esm/plugin-K3KCPCTJ.mjs.map +7 -0
- package/dist/lib/node-esm/plugin-MM66VRCO.mjs +167 -0
- package/dist/lib/node-esm/plugin-MM66VRCO.mjs.map +7 -0
- package/dist/types/src/plugins/PluginHost/plugin.test.d.ts.map +1 -1
- package/package.json +12 -11
- package/project.json +2 -8
- package/src/plugins/PluginHost/plugin.test.ts +1 -2
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SurfaceProvider,
|
|
3
|
+
meta_default as meta_default2,
|
|
4
|
+
parseRootSurfacePlugin,
|
|
5
|
+
parseSurfacePlugin,
|
|
6
|
+
useSurfaceRoot
|
|
7
|
+
} from "./chunk-YYV26N3W.mjs";
|
|
8
|
+
import {
|
|
9
|
+
IntentAction,
|
|
10
|
+
IntentProvider,
|
|
11
|
+
meta_default,
|
|
12
|
+
parseIntentPlugin,
|
|
13
|
+
parseIntentResolverPlugin,
|
|
14
|
+
useIntent,
|
|
15
|
+
useIntentDispatcher,
|
|
16
|
+
useIntentResolver
|
|
17
|
+
} from "./chunk-J45KR4DI.mjs";
|
|
18
|
+
import {
|
|
19
|
+
definePlugin,
|
|
20
|
+
filterPlugins,
|
|
21
|
+
findPlugin,
|
|
22
|
+
getPlugin,
|
|
23
|
+
resolvePlugin
|
|
24
|
+
} from "./chunk-S5CI6EUQ.mjs";
|
|
25
|
+
|
|
26
|
+
// packages/sdk/app-framework/src/plugins/common/file.ts
|
|
27
|
+
var defaultFileTypes = {
|
|
28
|
+
images: [
|
|
29
|
+
"png",
|
|
30
|
+
"jpg",
|
|
31
|
+
"jpeg",
|
|
32
|
+
"gif"
|
|
33
|
+
],
|
|
34
|
+
media: [
|
|
35
|
+
"mp3",
|
|
36
|
+
"mp4",
|
|
37
|
+
"mov",
|
|
38
|
+
"avi"
|
|
39
|
+
],
|
|
40
|
+
text: [
|
|
41
|
+
"pdf",
|
|
42
|
+
"txt",
|
|
43
|
+
"md"
|
|
44
|
+
]
|
|
45
|
+
};
|
|
46
|
+
var parseFileManagerPlugin = (plugin) => {
|
|
47
|
+
return plugin.provides.file ? plugin : void 0;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// packages/sdk/app-framework/src/plugins/common/graph.ts
|
|
51
|
+
var parseGraphPlugin = (plugin) => plugin.provides.graph?.root ? plugin : void 0;
|
|
52
|
+
var parseGraphBuilderPlugin = (plugin) => plugin.provides.graph?.builder ? plugin : void 0;
|
|
53
|
+
var parseGraphSerializerPlugin = (plugin) => plugin.provides.graph?.serializer ? plugin : void 0;
|
|
54
|
+
|
|
55
|
+
// packages/sdk/app-framework/src/plugins/common/layout.ts
|
|
56
|
+
import { z } from "zod";
|
|
57
|
+
var Toast = z.object({
|
|
58
|
+
id: z.string(),
|
|
59
|
+
title: z.string().optional(),
|
|
60
|
+
description: z.string().optional(),
|
|
61
|
+
// TODO(wittjosiah): `icon` should be string to be parsed by an `Icon` component.
|
|
62
|
+
icon: z.any().optional(),
|
|
63
|
+
duration: z.number().optional(),
|
|
64
|
+
closeLabel: z.string().optional(),
|
|
65
|
+
actionLabel: z.string().optional(),
|
|
66
|
+
actionAlt: z.string().optional(),
|
|
67
|
+
onAction: z.function().optional()
|
|
68
|
+
});
|
|
69
|
+
var LayoutMode = z.union([
|
|
70
|
+
z.literal("deck"),
|
|
71
|
+
z.literal("solo"),
|
|
72
|
+
z.literal("fullscreen")
|
|
73
|
+
]);
|
|
74
|
+
var isLayoutMode = (value) => LayoutMode.safeParse(value).success;
|
|
75
|
+
var Layout = z.object({
|
|
76
|
+
layoutMode: z.union([
|
|
77
|
+
z.literal("deck"),
|
|
78
|
+
z.literal("solo"),
|
|
79
|
+
z.literal("fullscreen")
|
|
80
|
+
]),
|
|
81
|
+
sidebarOpen: z.boolean(),
|
|
82
|
+
complementarySidebarOpen: z.boolean(),
|
|
83
|
+
/**
|
|
84
|
+
* @deprecated
|
|
85
|
+
*/
|
|
86
|
+
complementarySidebarContent: z.any().optional().describe("DEPRECATED. Data to be passed to the complementary sidebar Surface."),
|
|
87
|
+
dialogOpen: z.boolean(),
|
|
88
|
+
dialogContent: z.any().optional().describe("Data to be passed to the dialog Surface."),
|
|
89
|
+
// TODO(wittjosiah): Custom properties?
|
|
90
|
+
dialogBlockAlign: z.union([
|
|
91
|
+
z.literal("start"),
|
|
92
|
+
z.literal("center")
|
|
93
|
+
]).optional(),
|
|
94
|
+
popoverOpen: z.boolean(),
|
|
95
|
+
popoverContent: z.any().optional().describe("Data to be passed to the popover Surface."),
|
|
96
|
+
popoverAnchorId: z.string().optional(),
|
|
97
|
+
toasts: z.array(Toast),
|
|
98
|
+
scrollIntoView: z.string().optional().describe("The identifier of a component to scroll into view when it is mounted.")
|
|
99
|
+
});
|
|
100
|
+
var parseLayoutPlugin = (plugin) => {
|
|
101
|
+
const { success } = Layout.safeParse(plugin.provides.layout);
|
|
102
|
+
return success ? plugin : void 0;
|
|
103
|
+
};
|
|
104
|
+
var LAYOUT_ACTION = "dxos.org/plugin/layout";
|
|
105
|
+
var LayoutAction;
|
|
106
|
+
(function(LayoutAction2) {
|
|
107
|
+
LayoutAction2[LayoutAction2["SET_LAYOUT"] = `${LAYOUT_ACTION}/set-layout`] = "SET_LAYOUT";
|
|
108
|
+
LayoutAction2[LayoutAction2["SET_LAYOUT_MODE"] = `${LAYOUT_ACTION}/set-layout-mode`] = "SET_LAYOUT_MODE";
|
|
109
|
+
LayoutAction2[LayoutAction2["SCROLL_INTO_VIEW"] = `${LAYOUT_ACTION}/scroll-into-view`] = "SCROLL_INTO_VIEW";
|
|
110
|
+
LayoutAction2[LayoutAction2["UPDATE_PLANK_SIZE"] = `${LAYOUT_ACTION}/update-plank-size`] = "UPDATE_PLANK_SIZE";
|
|
111
|
+
})(LayoutAction || (LayoutAction = {}));
|
|
112
|
+
|
|
113
|
+
// packages/sdk/app-framework/src/plugins/common/metadata.ts
|
|
114
|
+
var parseMetadataRecordsPlugin = (plugin) => {
|
|
115
|
+
return plugin.provides.metadata?.records ? plugin : void 0;
|
|
116
|
+
};
|
|
117
|
+
var parseMetadataResolverPlugin = (plugin) => {
|
|
118
|
+
return plugin.provides.metadata?.resolver ? plugin : void 0;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// packages/sdk/app-framework/src/plugins/common/navigation.ts
|
|
122
|
+
import { z as z2 } from "zod";
|
|
123
|
+
import { S } from "@dxos/echo-schema";
|
|
124
|
+
var SLUG_LIST_SEPARATOR = "+";
|
|
125
|
+
var SLUG_ENTRY_SEPARATOR = "_";
|
|
126
|
+
var SLUG_KEY_VALUE_SEPARATOR = "-";
|
|
127
|
+
var SLUG_PATH_SEPARATOR = "~";
|
|
128
|
+
var SLUG_COLLECTION_INDICATOR = "";
|
|
129
|
+
var LayoutEntrySchema = S.mutable(S.Struct({
|
|
130
|
+
id: S.String,
|
|
131
|
+
path: S.optional(S.String)
|
|
132
|
+
}));
|
|
133
|
+
var LayoutPartSchema = S.Union(S.Literal("sidebar"), S.Literal("main"), S.Literal("solo"), S.Literal("complementary"), S.Literal("fullScreen"));
|
|
134
|
+
var LayoutPartsSchema = S.partial(S.mutable(S.Record(LayoutPartSchema, S.mutable(S.Array(LayoutEntrySchema)))));
|
|
135
|
+
var LayoutCoordinateSchema = S.mutable(S.Struct({
|
|
136
|
+
part: LayoutPartSchema,
|
|
137
|
+
entryId: S.String
|
|
138
|
+
}));
|
|
139
|
+
var PartAdjustmentSchema = S.Union(S.Literal("increment-start"), S.Literal("increment-end"), S.Literal("solo"));
|
|
140
|
+
var LayoutAdjustmentSchema = S.mutable(S.Struct({
|
|
141
|
+
layoutCoordinate: LayoutCoordinateSchema,
|
|
142
|
+
type: PartAdjustmentSchema
|
|
143
|
+
}));
|
|
144
|
+
var ActiveParts = z2.record(z2.string(), z2.union([
|
|
145
|
+
z2.string(),
|
|
146
|
+
z2.array(z2.string())
|
|
147
|
+
]));
|
|
148
|
+
var Attention = z2.object({
|
|
149
|
+
attended: z2.set(z2.string()).optional().describe("Ids of items which have focus.")
|
|
150
|
+
});
|
|
151
|
+
var LocationProvidesSchema = S.mutable(S.Struct({
|
|
152
|
+
location: S.Struct({
|
|
153
|
+
active: LayoutPartsSchema,
|
|
154
|
+
closed: S.Array(S.String)
|
|
155
|
+
})
|
|
156
|
+
}));
|
|
157
|
+
var isLayoutParts = (value) => {
|
|
158
|
+
return S.is(LayoutPartsSchema)(value);
|
|
159
|
+
};
|
|
160
|
+
var isLayoutAdjustment = (value) => {
|
|
161
|
+
return S.is(LayoutAdjustmentSchema)(value);
|
|
162
|
+
};
|
|
163
|
+
var parseNavigationPlugin = (plugin) => {
|
|
164
|
+
const location = plugin.provides?.location;
|
|
165
|
+
if (!location) {
|
|
166
|
+
return void 0;
|
|
167
|
+
}
|
|
168
|
+
if (S.is(LocationProvidesSchema)({
|
|
169
|
+
location
|
|
170
|
+
})) {
|
|
171
|
+
return plugin;
|
|
172
|
+
}
|
|
173
|
+
return void 0;
|
|
174
|
+
};
|
|
175
|
+
var openIds = (layout) => {
|
|
176
|
+
return Object.values(layout).flatMap((part) => part?.map((entry) => entry.id) ?? []).filter((id) => id !== void 0);
|
|
177
|
+
};
|
|
178
|
+
var firstIdInPart = (layout, part) => {
|
|
179
|
+
if (!layout) {
|
|
180
|
+
return void 0;
|
|
181
|
+
}
|
|
182
|
+
return layout[part]?.at(0)?.id;
|
|
183
|
+
};
|
|
184
|
+
var indexInPart = (layout, layoutCoordinate) => {
|
|
185
|
+
if (!layout || !layoutCoordinate) {
|
|
186
|
+
return void 0;
|
|
187
|
+
}
|
|
188
|
+
const { part, entryId } = layoutCoordinate;
|
|
189
|
+
return layout[part]?.findIndex((entry) => entry.id === entryId);
|
|
190
|
+
};
|
|
191
|
+
var partLength = (layout, part) => {
|
|
192
|
+
if (!layout || !part) {
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
return layout[part]?.length ?? 0;
|
|
196
|
+
};
|
|
197
|
+
var NAVIGATION_ACTION = "dxos.org/plugin/navigation";
|
|
198
|
+
var NavigationAction;
|
|
199
|
+
(function(NavigationAction2) {
|
|
200
|
+
NavigationAction2[NavigationAction2["OPEN"] = `${NAVIGATION_ACTION}/open`] = "OPEN";
|
|
201
|
+
NavigationAction2[NavigationAction2["ADD_TO_ACTIVE"] = `${NAVIGATION_ACTION}/add-to-active`] = "ADD_TO_ACTIVE";
|
|
202
|
+
NavigationAction2[NavigationAction2["SET"] = `${NAVIGATION_ACTION}/set`] = "SET";
|
|
203
|
+
NavigationAction2[NavigationAction2["ADJUST"] = `${NAVIGATION_ACTION}/adjust`] = "ADJUST";
|
|
204
|
+
NavigationAction2[NavigationAction2["CLOSE"] = `${NAVIGATION_ACTION}/close`] = "CLOSE";
|
|
205
|
+
NavigationAction2[NavigationAction2["EXPOSE"] = `${NAVIGATION_ACTION}/expose`] = "EXPOSE";
|
|
206
|
+
})(NavigationAction || (NavigationAction = {}));
|
|
207
|
+
|
|
208
|
+
// packages/sdk/app-framework/src/plugins/common/settings.ts
|
|
209
|
+
var parseSettingsPlugin = (plugin) => {
|
|
210
|
+
return typeof plugin.provides.settings === "object" ? plugin : void 0;
|
|
211
|
+
};
|
|
212
|
+
var SETTINGS_ACTION = "dxos.org/plugin/settings";
|
|
213
|
+
var SettingsAction;
|
|
214
|
+
(function(SettingsAction2) {
|
|
215
|
+
SettingsAction2[SettingsAction2["OPEN"] = `${SETTINGS_ACTION}/open`] = "OPEN";
|
|
216
|
+
})(SettingsAction || (SettingsAction = {}));
|
|
217
|
+
|
|
218
|
+
// packages/sdk/app-framework/src/plugins/common/translations.ts
|
|
219
|
+
import { z as z3 } from "zod";
|
|
220
|
+
var ResourceKey = z3.union([
|
|
221
|
+
z3.string(),
|
|
222
|
+
z3.record(z3.any())
|
|
223
|
+
]);
|
|
224
|
+
var ResourceLanguage = z3.record(ResourceKey);
|
|
225
|
+
var Resource = z3.record(ResourceLanguage);
|
|
226
|
+
var parseTranslationsPlugin = (plugin) => {
|
|
227
|
+
const { success } = z3.array(Resource).safeParse(plugin.provides.translations);
|
|
228
|
+
return success ? plugin : void 0;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// packages/sdk/app-framework/src/plugins/PluginHost/plugin.ts
|
|
232
|
+
var pluginMeta = (meta) => meta;
|
|
233
|
+
var Plugin;
|
|
234
|
+
(function(Plugin2) {
|
|
235
|
+
Plugin2.lazy = (p, props) => {
|
|
236
|
+
return () => p().then(({ default: definition }) => {
|
|
237
|
+
return definition(props);
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
})(Plugin || (Plugin = {}));
|
|
241
|
+
|
|
242
|
+
// packages/sdk/app-framework/src/plugins/PluginHost/PluginContext.tsx
|
|
243
|
+
import { createContext, useContext, useMemo } from "react";
|
|
244
|
+
import { nonNullable } from "@dxos/util";
|
|
245
|
+
var PluginContext = /* @__PURE__ */ createContext({
|
|
246
|
+
ready: false,
|
|
247
|
+
core: [],
|
|
248
|
+
enabled: [],
|
|
249
|
+
plugins: [],
|
|
250
|
+
available: [],
|
|
251
|
+
setPlugin: () => {
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
var usePlugins = () => useContext(PluginContext);
|
|
255
|
+
var usePlugin = (id) => {
|
|
256
|
+
const { plugins } = usePlugins();
|
|
257
|
+
return findPlugin(plugins, id);
|
|
258
|
+
};
|
|
259
|
+
var useResolvePlugin = (predicate) => {
|
|
260
|
+
const { plugins } = usePlugins();
|
|
261
|
+
return resolvePlugin(plugins, predicate);
|
|
262
|
+
};
|
|
263
|
+
var useResolvePlugins = (predicate) => {
|
|
264
|
+
const { plugins } = usePlugins();
|
|
265
|
+
return useMemo(() => plugins.map(predicate).filter(nonNullable), [
|
|
266
|
+
plugins,
|
|
267
|
+
predicate
|
|
268
|
+
]);
|
|
269
|
+
};
|
|
270
|
+
var PluginProvider = PluginContext.Provider;
|
|
271
|
+
|
|
272
|
+
// packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx
|
|
273
|
+
import React3, { useEffect, useState } from "react";
|
|
274
|
+
import { LocalStorageStore } from "@dxos/local-storage";
|
|
275
|
+
import { log } from "@dxos/log";
|
|
276
|
+
|
|
277
|
+
// packages/sdk/app-framework/src/plugins/SurfacePlugin/helpers.ts
|
|
278
|
+
var isObject = (data) => !!data && typeof data === "object";
|
|
279
|
+
|
|
280
|
+
// packages/sdk/app-framework/src/plugins/SurfacePlugin/ErrorBoundary.tsx
|
|
281
|
+
import React, { Component } from "react";
|
|
282
|
+
var ErrorBoundary = class extends Component {
|
|
283
|
+
constructor(props) {
|
|
284
|
+
super(props);
|
|
285
|
+
this.state = {
|
|
286
|
+
error: void 0
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
static getDerivedStateFromError(error) {
|
|
290
|
+
return {
|
|
291
|
+
error
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
componentDidUpdate(prevProps) {
|
|
295
|
+
if (prevProps.data !== this.props.data) {
|
|
296
|
+
this.resetError();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
render() {
|
|
300
|
+
if (this.state.error) {
|
|
301
|
+
return /* @__PURE__ */ React.createElement(this.props.fallback, {
|
|
302
|
+
data: this.props.data,
|
|
303
|
+
error: this.state.error,
|
|
304
|
+
reset: this.resetError
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
return this.props.children;
|
|
308
|
+
}
|
|
309
|
+
resetError() {
|
|
310
|
+
this.setState({
|
|
311
|
+
error: void 0
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// packages/sdk/app-framework/src/plugins/SurfacePlugin/Surface.tsx
|
|
317
|
+
import React2, { forwardRef, Fragment, isValidElement, Suspense } from "react";
|
|
318
|
+
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
319
|
+
import { raise } from "@dxos/debug";
|
|
320
|
+
var Surface = /* @__PURE__ */ forwardRef(({ role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
|
|
321
|
+
const props = {
|
|
322
|
+
role,
|
|
323
|
+
name,
|
|
324
|
+
fallback,
|
|
325
|
+
...rest
|
|
326
|
+
};
|
|
327
|
+
const context = useContext2(SurfaceContext);
|
|
328
|
+
const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
|
|
329
|
+
const resolver = /* @__PURE__ */ React2.createElement(SurfaceResolver, {
|
|
330
|
+
...props,
|
|
331
|
+
ref: forwardedRef
|
|
332
|
+
});
|
|
333
|
+
const suspense = placeholder ? /* @__PURE__ */ React2.createElement(Suspense, {
|
|
334
|
+
fallback: placeholder
|
|
335
|
+
}, resolver) : resolver;
|
|
336
|
+
return fallback ? /* @__PURE__ */ React2.createElement(ErrorBoundary, {
|
|
337
|
+
data,
|
|
338
|
+
fallback
|
|
339
|
+
}, suspense) : suspense;
|
|
340
|
+
});
|
|
341
|
+
var SurfaceContext = /* @__PURE__ */ createContext2(null);
|
|
342
|
+
var useSurface = () => useContext2(SurfaceContext) ?? raise(new Error("Surface context not found"));
|
|
343
|
+
var SurfaceResolver = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
344
|
+
const { components } = useSurfaceRoot();
|
|
345
|
+
const parent = useContext2(SurfaceContext);
|
|
346
|
+
const nodes = resolveNodes(components, props, parent, forwardedRef);
|
|
347
|
+
const currentContext = {
|
|
348
|
+
...props,
|
|
349
|
+
surfaces: {
|
|
350
|
+
...props.name && parent?.surfaces?.[props.name]?.surfaces || {},
|
|
351
|
+
...props.surfaces
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
return /* @__PURE__ */ React2.createElement(SurfaceContext.Provider, {
|
|
355
|
+
value: currentContext
|
|
356
|
+
}, nodes);
|
|
357
|
+
});
|
|
358
|
+
var resolveNodes = (components, props, context, forwardedRef) => {
|
|
359
|
+
const data = {
|
|
360
|
+
...props.name && context?.surfaces?.[props.name]?.data || {},
|
|
361
|
+
...props.data
|
|
362
|
+
};
|
|
363
|
+
const nodes = Object.entries(components).map(([key, component]) => {
|
|
364
|
+
const result = component({
|
|
365
|
+
...props,
|
|
366
|
+
data
|
|
367
|
+
}, forwardedRef);
|
|
368
|
+
if (!result || typeof result !== "object") {
|
|
369
|
+
return void 0;
|
|
370
|
+
}
|
|
371
|
+
return "node" in result ? [
|
|
372
|
+
key,
|
|
373
|
+
result
|
|
374
|
+
] : /* @__PURE__ */ isValidElement(result) ? [
|
|
375
|
+
key,
|
|
376
|
+
{
|
|
377
|
+
node: result
|
|
378
|
+
}
|
|
379
|
+
] : void 0;
|
|
380
|
+
}).filter((result) => Boolean(result)).sort(([, a], [, b]) => {
|
|
381
|
+
const aDisposition = a.disposition ?? "default";
|
|
382
|
+
const bDisposition = b.disposition ?? "default";
|
|
383
|
+
if (aDisposition === bDisposition) {
|
|
384
|
+
return 0;
|
|
385
|
+
} else if (aDisposition === "hoist" || bDisposition === "fallback") {
|
|
386
|
+
return -1;
|
|
387
|
+
} else if (bDisposition === "hoist" || aDisposition === "fallback") {
|
|
388
|
+
return 1;
|
|
389
|
+
}
|
|
390
|
+
return 0;
|
|
391
|
+
}).map(([key, result]) => /* @__PURE__ */ React2.createElement(Fragment, {
|
|
392
|
+
key
|
|
393
|
+
}, result.node));
|
|
394
|
+
return props.limit ? nodes.slice(0, props.limit) : nodes;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
// packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx
|
|
398
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx";
|
|
399
|
+
var parsePluginHost = (plugin) => plugin.provides.plugins ? plugin : void 0;
|
|
400
|
+
var PLUGIN_HOST = "dxos.org/plugin/host";
|
|
401
|
+
var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallback = DefaultFallback, placeholder = null }) => {
|
|
402
|
+
const state = new LocalStorageStore(PLUGIN_HOST, {
|
|
403
|
+
ready: false,
|
|
404
|
+
core,
|
|
405
|
+
enabled: [
|
|
406
|
+
...defaults
|
|
407
|
+
],
|
|
408
|
+
plugins: [],
|
|
409
|
+
available: order.filter(({ id }) => !core.includes(id)),
|
|
410
|
+
setPlugin: (id, enabled) => {
|
|
411
|
+
if (enabled) {
|
|
412
|
+
state.values.enabled.push(id);
|
|
413
|
+
} else {
|
|
414
|
+
const index = state.values.enabled.findIndex((enabled2) => enabled2 === id);
|
|
415
|
+
index !== -1 && state.values.enabled.splice(index, 1);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
state.prop({
|
|
420
|
+
key: "enabled",
|
|
421
|
+
type: LocalStorageStore.json()
|
|
422
|
+
});
|
|
423
|
+
return {
|
|
424
|
+
meta: {
|
|
425
|
+
id: PLUGIN_HOST,
|
|
426
|
+
name: "Plugin host"
|
|
427
|
+
},
|
|
428
|
+
provides: {
|
|
429
|
+
plugins: state.values,
|
|
430
|
+
context: ({ children }) => /* @__PURE__ */ React3.createElement(PluginProvider, {
|
|
431
|
+
value: state.values
|
|
432
|
+
}, children),
|
|
433
|
+
root: () => {
|
|
434
|
+
return /* @__PURE__ */ React3.createElement(ErrorBoundary, {
|
|
435
|
+
fallback
|
|
436
|
+
}, /* @__PURE__ */ React3.createElement(Root, {
|
|
437
|
+
order,
|
|
438
|
+
core,
|
|
439
|
+
definitions,
|
|
440
|
+
state: state.values,
|
|
441
|
+
placeholder
|
|
442
|
+
}));
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
};
|
|
447
|
+
var DefaultFallback = ({ error }) => {
|
|
448
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
449
|
+
style: {
|
|
450
|
+
padding: "1rem"
|
|
451
|
+
}
|
|
452
|
+
}, /* @__PURE__ */ React3.createElement("h1", {
|
|
453
|
+
style: {
|
|
454
|
+
fontSize: "1.2rem",
|
|
455
|
+
fontWeight: 700,
|
|
456
|
+
margin: "0.5rem 0"
|
|
457
|
+
}
|
|
458
|
+
}, error.message), /* @__PURE__ */ React3.createElement("pre", null, error.stack));
|
|
459
|
+
};
|
|
460
|
+
var Root = ({ order, core: corePluginIds, definitions, state, placeholder }) => {
|
|
461
|
+
const [error, setError] = useState();
|
|
462
|
+
useEffect(() => {
|
|
463
|
+
log("initializing plugins", {
|
|
464
|
+
enabled: state.enabled
|
|
465
|
+
}, {
|
|
466
|
+
F: __dxlog_file,
|
|
467
|
+
L: 102,
|
|
468
|
+
S: void 0,
|
|
469
|
+
C: (f, a) => f(...a)
|
|
470
|
+
});
|
|
471
|
+
const timeout = setTimeout(async () => {
|
|
472
|
+
try {
|
|
473
|
+
const enabledIds = [
|
|
474
|
+
...corePluginIds,
|
|
475
|
+
...state.enabled
|
|
476
|
+
].sort((a, b) => {
|
|
477
|
+
const indexA = order.findIndex(({ id }) => id === a);
|
|
478
|
+
const indexB = order.findIndex(({ id }) => id === b);
|
|
479
|
+
return indexA - indexB;
|
|
480
|
+
});
|
|
481
|
+
const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
|
|
482
|
+
const plugins = await Promise.all(enabled.map(async (definition) => {
|
|
483
|
+
const plugin = await initializePlugin(definition).catch((err) => {
|
|
484
|
+
log.error("Failed to initialize plugin:", {
|
|
485
|
+
id: definition.meta.id,
|
|
486
|
+
err
|
|
487
|
+
}, {
|
|
488
|
+
F: __dxlog_file,
|
|
489
|
+
L: 122,
|
|
490
|
+
S: void 0,
|
|
491
|
+
C: (f, a) => f(...a)
|
|
492
|
+
});
|
|
493
|
+
return void 0;
|
|
494
|
+
});
|
|
495
|
+
return plugin;
|
|
496
|
+
})).then((plugins2) => plugins2.filter((plugin) => Boolean(plugin)));
|
|
497
|
+
log("plugins initialized", {
|
|
498
|
+
plugins
|
|
499
|
+
}, {
|
|
500
|
+
F: __dxlog_file,
|
|
501
|
+
L: 128,
|
|
502
|
+
S: void 0,
|
|
503
|
+
C: (f, a) => f(...a)
|
|
504
|
+
});
|
|
505
|
+
await Promise.all(enabled.map((pluginDefinition) => pluginDefinition.ready?.(plugins)));
|
|
506
|
+
log("plugins ready", {
|
|
507
|
+
plugins
|
|
508
|
+
}, {
|
|
509
|
+
F: __dxlog_file,
|
|
510
|
+
L: 131,
|
|
511
|
+
S: void 0,
|
|
512
|
+
C: (f, a) => f(...a)
|
|
513
|
+
});
|
|
514
|
+
state.plugins = plugins;
|
|
515
|
+
state.ready = true;
|
|
516
|
+
} catch (err) {
|
|
517
|
+
setError(err);
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
return () => {
|
|
521
|
+
clearTimeout(timeout);
|
|
522
|
+
state.ready = false;
|
|
523
|
+
};
|
|
524
|
+
}, []);
|
|
525
|
+
if (error) {
|
|
526
|
+
throw error;
|
|
527
|
+
}
|
|
528
|
+
if (!state.ready) {
|
|
529
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, placeholder);
|
|
530
|
+
}
|
|
531
|
+
const ComposedContext = composeContext(state.plugins);
|
|
532
|
+
return /* @__PURE__ */ React3.createElement(ComposedContext, null, rootComponents(state.plugins));
|
|
533
|
+
};
|
|
534
|
+
var initializePlugin = async (pluginDefinition) => {
|
|
535
|
+
const provides = await pluginDefinition.initialize?.();
|
|
536
|
+
return {
|
|
537
|
+
...pluginDefinition,
|
|
538
|
+
provides: {
|
|
539
|
+
...pluginDefinition.provides,
|
|
540
|
+
...provides
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
};
|
|
544
|
+
var rootComponents = (plugins) => {
|
|
545
|
+
return plugins.map((plugin) => {
|
|
546
|
+
const Component2 = plugin.provides.root;
|
|
547
|
+
if (Component2) {
|
|
548
|
+
return /* @__PURE__ */ React3.createElement(Component2, {
|
|
549
|
+
key: plugin.meta.id
|
|
550
|
+
});
|
|
551
|
+
} else {
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
}).filter((node) => Boolean(node));
|
|
555
|
+
};
|
|
556
|
+
var composeContext = (plugins) => {
|
|
557
|
+
return compose(plugins.map((p) => p.provides.context).filter(Boolean));
|
|
558
|
+
};
|
|
559
|
+
var compose = (contexts) => {
|
|
560
|
+
return [
|
|
561
|
+
...contexts
|
|
562
|
+
].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ React3.createElement(Acc, null, /* @__PURE__ */ React3.createElement(Next, null, children)));
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
// packages/sdk/app-framework/src/App.tsx
|
|
566
|
+
import React4 from "react";
|
|
567
|
+
import { invariant } from "@dxos/invariant";
|
|
568
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/App.tsx";
|
|
569
|
+
var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }) => {
|
|
570
|
+
const host = PluginHost({
|
|
571
|
+
order: [
|
|
572
|
+
meta_default2,
|
|
573
|
+
meta_default,
|
|
574
|
+
...order
|
|
575
|
+
],
|
|
576
|
+
plugins: {
|
|
577
|
+
...plugins,
|
|
578
|
+
[meta_default2.id]: Plugin.lazy(() => import("./plugin-K3KCPCTJ.mjs")),
|
|
579
|
+
[meta_default.id]: Plugin.lazy(() => import("./plugin-MM66VRCO.mjs"))
|
|
580
|
+
},
|
|
581
|
+
core: [
|
|
582
|
+
meta_default2.id,
|
|
583
|
+
meta_default.id,
|
|
584
|
+
...core
|
|
585
|
+
],
|
|
586
|
+
...params
|
|
587
|
+
});
|
|
588
|
+
invariant(host.provides?.context, void 0, {
|
|
589
|
+
F: __dxlog_file2,
|
|
590
|
+
L: 51,
|
|
591
|
+
S: void 0,
|
|
592
|
+
A: [
|
|
593
|
+
"host.provides?.context",
|
|
594
|
+
""
|
|
595
|
+
]
|
|
596
|
+
});
|
|
597
|
+
invariant(host.provides?.root, void 0, {
|
|
598
|
+
F: __dxlog_file2,
|
|
599
|
+
L: 52,
|
|
600
|
+
S: void 0,
|
|
601
|
+
A: [
|
|
602
|
+
"host.provides?.root",
|
|
603
|
+
""
|
|
604
|
+
]
|
|
605
|
+
});
|
|
606
|
+
const Context = host.provides.context;
|
|
607
|
+
const Root2 = host.provides.root;
|
|
608
|
+
return () => /* @__PURE__ */ React4.createElement(Context, null, /* @__PURE__ */ React4.createElement(Root2, null));
|
|
609
|
+
};
|
|
610
|
+
export {
|
|
611
|
+
ActiveParts,
|
|
612
|
+
Attention,
|
|
613
|
+
ErrorBoundary,
|
|
614
|
+
IntentAction,
|
|
615
|
+
IntentProvider,
|
|
616
|
+
Layout,
|
|
617
|
+
LayoutAction,
|
|
618
|
+
NavigationAction,
|
|
619
|
+
Plugin,
|
|
620
|
+
PluginHost,
|
|
621
|
+
PluginProvider,
|
|
622
|
+
Resource,
|
|
623
|
+
ResourceKey,
|
|
624
|
+
ResourceLanguage,
|
|
625
|
+
SLUG_COLLECTION_INDICATOR,
|
|
626
|
+
SLUG_ENTRY_SEPARATOR,
|
|
627
|
+
SLUG_KEY_VALUE_SEPARATOR,
|
|
628
|
+
SLUG_LIST_SEPARATOR,
|
|
629
|
+
SLUG_PATH_SEPARATOR,
|
|
630
|
+
SettingsAction,
|
|
631
|
+
Surface,
|
|
632
|
+
SurfaceProvider,
|
|
633
|
+
Toast,
|
|
634
|
+
createApp,
|
|
635
|
+
defaultFileTypes,
|
|
636
|
+
definePlugin,
|
|
637
|
+
filterPlugins,
|
|
638
|
+
findPlugin,
|
|
639
|
+
firstIdInPart,
|
|
640
|
+
getPlugin,
|
|
641
|
+
indexInPart,
|
|
642
|
+
initializePlugin,
|
|
643
|
+
isLayoutAdjustment,
|
|
644
|
+
isLayoutMode,
|
|
645
|
+
isLayoutParts,
|
|
646
|
+
isObject,
|
|
647
|
+
openIds,
|
|
648
|
+
parseFileManagerPlugin,
|
|
649
|
+
parseGraphBuilderPlugin,
|
|
650
|
+
parseGraphPlugin,
|
|
651
|
+
parseGraphSerializerPlugin,
|
|
652
|
+
parseIntentPlugin,
|
|
653
|
+
parseIntentResolverPlugin,
|
|
654
|
+
parseLayoutPlugin,
|
|
655
|
+
parseMetadataRecordsPlugin,
|
|
656
|
+
parseMetadataResolverPlugin,
|
|
657
|
+
parseNavigationPlugin,
|
|
658
|
+
parsePluginHost,
|
|
659
|
+
parseRootSurfacePlugin,
|
|
660
|
+
parseSettingsPlugin,
|
|
661
|
+
parseSurfacePlugin,
|
|
662
|
+
parseTranslationsPlugin,
|
|
663
|
+
partLength,
|
|
664
|
+
pluginMeta,
|
|
665
|
+
resolvePlugin,
|
|
666
|
+
useIntent,
|
|
667
|
+
useIntentDispatcher,
|
|
668
|
+
useIntentResolver,
|
|
669
|
+
usePlugin,
|
|
670
|
+
usePlugins,
|
|
671
|
+
useResolvePlugin,
|
|
672
|
+
useResolvePlugins,
|
|
673
|
+
useSurface,
|
|
674
|
+
useSurfaceRoot
|
|
675
|
+
};
|
|
676
|
+
//# sourceMappingURL=index.mjs.map
|