@dxos/app-framework 0.3.9-main.cea1d3b → 0.3.9-main.d5f3fd3
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/.storybook/preview-head.html +1 -0
- package/dist/lib/browser/{chunk-WDA7VA54.mjs → chunk-MNFAM2GF.mjs} +1 -1
- package/dist/lib/browser/{chunk-WDA7VA54.mjs.map → chunk-MNFAM2GF.mjs.map} +2 -2
- package/dist/lib/browser/index.mjs +33 -7
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{plugin-XEJ5RYCP.mjs → plugin-JDIMDLDU.mjs} +2 -2
- package/dist/lib/node/{chunk-YDKX45O3.cjs → chunk-DC3GU6QR.cjs} +4 -4
- package/dist/lib/node/chunk-DC3GU6QR.cjs.map +7 -0
- package/dist/lib/node/index.cjs +38 -13
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{plugin-RCAOZKNL.cjs → plugin-JGSJGRMS.cjs} +8 -8
- package/dist/types/src/plugins/PluginHost/plugin.d.ts +10 -2
- package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts +2 -0
- package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts +10 -2
- package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/helpers.d.ts +21 -0
- package/dist/types/src/plugins/SurfacePlugin/helpers.d.ts.map +1 -0
- package/dist/types/src/plugins/SurfacePlugin/index.d.ts +1 -0
- package/dist/types/src/plugins/SurfacePlugin/index.d.ts.map +1 -1
- package/dist/types/src/plugins/common/graph.d.ts +2 -2
- package/dist/types/src/plugins/common/graph.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/plugins/PluginHost/plugin.ts +6 -1
- package/src/plugins/SurfacePlugin/Surface.tsx +34 -5
- package/src/plugins/SurfacePlugin/SurfaceRootContext.tsx +15 -2
- package/src/plugins/SurfacePlugin/helpers.ts +22 -0
- package/src/plugins/SurfacePlugin/index.ts +1 -0
- package/src/plugins/common/graph.ts +2 -2
- package/dist/lib/node/chunk-YDKX45O3.cjs.map +0 -7
- /package/dist/lib/browser/{plugin-XEJ5RYCP.mjs.map → plugin-JDIMDLDU.mjs.map} +0 -0
- /package/dist/lib/node/{plugin-RCAOZKNL.cjs.map → plugin-JGSJGRMS.cjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/SurfacePlugin/index.ts"],"names":[],"mappings":"AAIA,cAAc,YAAY,CAAC;AAE3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/SurfacePlugin/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAE3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC"}
|
|
@@ -4,7 +4,7 @@ import type { Plugin } from '../PluginHost';
|
|
|
4
4
|
/**
|
|
5
5
|
* Provides for a plugin that exposes the application graph.
|
|
6
6
|
*/
|
|
7
|
-
export type
|
|
7
|
+
export type GraphProvides = {
|
|
8
8
|
graph: Graph;
|
|
9
9
|
};
|
|
10
10
|
export type GraphBuilderProvides = {
|
|
@@ -18,7 +18,7 @@ export type GraphBuilderProvides = {
|
|
|
18
18
|
/**
|
|
19
19
|
* Type guard for graph plugins.
|
|
20
20
|
*/
|
|
21
|
-
export declare const parseGraphPlugin: (plugin: Plugin) => Plugin<
|
|
21
|
+
export declare const parseGraphPlugin: (plugin: Plugin) => Plugin<GraphProvides> | undefined;
|
|
22
22
|
/**
|
|
23
23
|
* Type guard for graph builder plugins.
|
|
24
24
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/common/graph.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/common/graph.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE;QACL,OAAO,EAAE,CAAC,MAAM,EAAE;YAAE,MAAM,EAAE,IAAI,CAAC;YAAC,OAAO,EAAE,MAAM,EAAE,CAAA;SAAE,KAAK,mBAAmB,GAAG,IAAI,CAAC;KACtF,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,WAAY,MAAM,sCACuC,CAAC;AAEvF;;GAEG;AACH,eAAO,MAAM,uBAAuB,WAAY,MAAM,6CAC0C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/app-framework",
|
|
3
|
-
"version": "0.3.9-main.
|
|
3
|
+
"version": "0.3.9-main.d5f3fd3",
|
|
4
4
|
"description": "A framework for building applications from composible plugins.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"@preact/signals-react": "^1.3.6",
|
|
17
17
|
"deepsignal": "1.4.0-shallow.0",
|
|
18
18
|
"zod": "^3.22.4",
|
|
19
|
-
"@dxos/app-graph": "0.3.9-main.
|
|
20
|
-
"@dxos/
|
|
21
|
-
"@dxos/
|
|
22
|
-
"@dxos/invariant": "0.3.9-main.
|
|
23
|
-
"@dxos/log": "0.3.9-main.
|
|
24
|
-
"@dxos/
|
|
19
|
+
"@dxos/app-graph": "0.3.9-main.d5f3fd3",
|
|
20
|
+
"@dxos/debug": "0.3.9-main.d5f3fd3",
|
|
21
|
+
"@dxos/async": "0.3.9-main.d5f3fd3",
|
|
22
|
+
"@dxos/invariant": "0.3.9-main.d5f3fd3",
|
|
23
|
+
"@dxos/log": "0.3.9-main.d5f3fd3",
|
|
24
|
+
"@dxos/local-storage": "0.3.9-main.d5f3fd3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/react": "^18.0.21",
|
|
@@ -45,7 +45,7 @@ export type Plugin<TProvides = {}> = {
|
|
|
45
45
|
shortId?: string;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* Human
|
|
48
|
+
* Human-readable name.
|
|
49
49
|
*/
|
|
50
50
|
name?: string;
|
|
51
51
|
|
|
@@ -54,6 +54,11 @@ export type Plugin<TProvides = {}> = {
|
|
|
54
54
|
*/
|
|
55
55
|
description?: string;
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Tags to help categorize the plugin.
|
|
59
|
+
*/
|
|
60
|
+
tags?: string[];
|
|
61
|
+
|
|
57
62
|
/**
|
|
58
63
|
* Component to render icon for the plugin when displayed in a list.
|
|
59
64
|
*/
|
|
@@ -2,11 +2,19 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, {
|
|
5
|
+
import React, {
|
|
6
|
+
forwardRef,
|
|
7
|
+
type FC,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
Fragment,
|
|
10
|
+
type ForwardedRef,
|
|
11
|
+
type PropsWithChildren,
|
|
12
|
+
isValidElement,
|
|
13
|
+
} from 'react';
|
|
6
14
|
import { createContext, useContext } from 'react';
|
|
7
15
|
|
|
8
16
|
import { ErrorBoundary } from './ErrorBoundary';
|
|
9
|
-
import { type SurfaceComponent, useSurface } from './SurfaceRootContext';
|
|
17
|
+
import { type SurfaceComponent, useSurface, type SurfaceResult } from './SurfaceRootContext';
|
|
10
18
|
|
|
11
19
|
/**
|
|
12
20
|
* Direction determines how multiple components are laid out.
|
|
@@ -43,6 +51,8 @@ export type SurfaceProps = PropsWithChildren<{
|
|
|
43
51
|
|
|
44
52
|
/**
|
|
45
53
|
* If specified, this will render if no plugin can offer renderable content for the surface.
|
|
54
|
+
*
|
|
55
|
+
* @deprecated Provide a component with `disposition: 'fallback'` instead.
|
|
46
56
|
*/
|
|
47
57
|
contentFallback?: FC<{}>;
|
|
48
58
|
|
|
@@ -120,11 +130,30 @@ const resolveNodes = (
|
|
|
120
130
|
};
|
|
121
131
|
|
|
122
132
|
const nodes = Object.entries(components)
|
|
123
|
-
.map(([key, component]) => {
|
|
133
|
+
.map(([key, component]): [string, SurfaceResult] | undefined => {
|
|
124
134
|
const result = component({ ...props, data }, forwardedRef);
|
|
125
|
-
|
|
135
|
+
if (!result || typeof result !== 'object') {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return 'node' in result ? [key, result] : isValidElement(result) ? [key, { node: result }] : undefined;
|
|
140
|
+
})
|
|
141
|
+
.filter((result): result is [string, SurfaceResult] => Boolean(result))
|
|
142
|
+
.sort(([, a], [, b]) => {
|
|
143
|
+
const aDisposition = a.disposition ?? 'default';
|
|
144
|
+
const bDisposition = b.disposition ?? 'default';
|
|
145
|
+
|
|
146
|
+
if (aDisposition === bDisposition) {
|
|
147
|
+
return 0;
|
|
148
|
+
} else if (aDisposition === 'hoist' || bDisposition === 'fallback') {
|
|
149
|
+
return -1;
|
|
150
|
+
} else if (bDisposition === 'hoist' || aDisposition === 'fallback') {
|
|
151
|
+
return 1;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return 0;
|
|
126
155
|
})
|
|
127
|
-
.
|
|
156
|
+
.map(([key, result]) => <Fragment key={key}>{result.node}</Fragment>);
|
|
128
157
|
|
|
129
158
|
return props.limit ? nodes.slice(0, props.limit) : nodes;
|
|
130
159
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { createContext, useContext, type Context, type Provider, type
|
|
5
|
+
import { createContext, useContext, type Context, type Provider, type ForwardedRef } from 'react';
|
|
6
6
|
|
|
7
7
|
import { type SurfaceProps } from './Surface';
|
|
8
8
|
|
|
@@ -13,12 +13,25 @@ type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
|
|
|
13
13
|
|
|
14
14
|
type SurfaceComponentProps = WithRequiredProperty<SurfaceProps, 'data'>;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Determines the priority of the surface when multiple components are resolved.
|
|
18
|
+
*/
|
|
19
|
+
export type SurfaceDisposition = 'hoist' | 'fallback';
|
|
20
|
+
|
|
21
|
+
export type SurfaceResult = {
|
|
22
|
+
node: JSX.Element;
|
|
23
|
+
disposition?: SurfaceDisposition;
|
|
24
|
+
};
|
|
25
|
+
|
|
16
26
|
/**
|
|
17
27
|
* Function which resolves a Surface.
|
|
18
28
|
*
|
|
19
29
|
* If a null value is returned, the rendering is deferred to other plugins.
|
|
20
30
|
*/
|
|
21
|
-
export type SurfaceComponent = (
|
|
31
|
+
export type SurfaceComponent = (
|
|
32
|
+
props: SurfaceComponentProps,
|
|
33
|
+
forwardedRef: ForwardedRef<HTMLElement>,
|
|
34
|
+
) => JSX.Element | SurfaceResult | null;
|
|
22
35
|
|
|
23
36
|
export type SurfaceRootContext = {
|
|
24
37
|
components: Record<string, SurfaceComponent>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks if the given data is an object and not null.
|
|
7
|
+
*
|
|
8
|
+
* Useful inside surface component resolvers as a type guard.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const old =
|
|
13
|
+
* data.content &&
|
|
14
|
+
* typeof data.content === 'object' &&
|
|
15
|
+
* 'id' in data.content &&
|
|
16
|
+
* typeof data.content.id === 'string';
|
|
17
|
+
*
|
|
18
|
+
* // becomes
|
|
19
|
+
* const new = isObject(data.content) && typeof data.content.id === 'string';
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const isObject = (data: unknown): data is { [key: string]: unknown } => !!data && typeof data === 'object';
|
|
@@ -10,7 +10,7 @@ import type { Plugin } from '../PluginHost';
|
|
|
10
10
|
/**
|
|
11
11
|
* Provides for a plugin that exposes the application graph.
|
|
12
12
|
*/
|
|
13
|
-
export type
|
|
13
|
+
export type GraphProvides = {
|
|
14
14
|
graph: Graph;
|
|
15
15
|
};
|
|
16
16
|
|
|
@@ -24,7 +24,7 @@ export type GraphBuilderProvides = {
|
|
|
24
24
|
* Type guard for graph plugins.
|
|
25
25
|
*/
|
|
26
26
|
export const parseGraphPlugin = (plugin: Plugin) =>
|
|
27
|
-
(plugin.provides as any).graph?.root ? (plugin as Plugin<
|
|
27
|
+
(plugin.provides as any).graph?.root ? (plugin as Plugin<GraphProvides>) : undefined;
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Type guard for graph builder plugins.
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugins/SurfacePlugin/provides.ts", "../../../src/plugins/SurfacePlugin/SurfaceRootContext.tsx", "../../../src/plugins/SurfacePlugin/meta.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type SurfaceComponent, type SurfaceRootContext } from './SurfaceRootContext';\nimport { type Plugin } from '../PluginHost';\n\nexport type SurfaceProvides = {\n surface: {\n /**\n * Used by the `Surface` resolver to find a component to render.\n */\n component: SurfaceComponent;\n };\n};\n\nexport type SurfacePluginProvides = {\n surface: SurfaceRootContext;\n};\n\nexport const parseRootSurfacePlugin = (plugin?: Plugin) =>\n (plugin?.provides as any)?.surface?.components ? (plugin as Plugin<SurfacePluginProvides>) : undefined;\n\nexport const parseSurfacePlugin = (plugin?: Plugin) =>\n (plugin?.provides as any)?.surface?.component ? (plugin as Plugin<SurfaceProvides>) : undefined;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { createContext, useContext, type Context, type Provider, type ReactNode, type ForwardedRef } from 'react';\n\nimport { type SurfaceProps } from './Surface';\n\n// TODO(wittjosiah): Factor out.\ntype WithRequiredProperty<Type, Key extends keyof Type> = Type & {\n [Property in Key]-?: Type[Property];\n};\n\ntype SurfaceComponentProps = WithRequiredProperty<SurfaceProps, 'data'>;\n\n/**\n * Function which resolves a Surface.\n *\n * If a null value is returned, the rendering is deferred to other plugins.\n */\nexport type SurfaceComponent = (props: SurfaceComponentProps, forwardedRef: ForwardedRef<HTMLElement>) => ReactNode;\n\nexport type SurfaceRootContext = {\n components: Record<string, SurfaceComponent>;\n};\n\nconst SurfaceRootContext: Context<SurfaceRootContext> = createContext<SurfaceRootContext>({ components: {} });\n\nexport const useSurface = () => useContext(SurfaceRootContext);\n\nexport const SurfaceProvider: Provider<SurfaceRootContext> = SurfaceRootContext.Provider;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst SurfaceMeta = {\n id: 'dxos.org/plugin/surface',\n};\n\nexport default SurfaceMeta;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;ACIA,mBAA0G;ADgBnG,IAAMA,yBAAyB,CAACC,WACpCA,QAAQC,UAAkBC,SAASC,aAAcH,SAA2CI;AAExF,IAAMC,qBAAqB,CAACL,WAChCA,QAAQC,UAAkBC,SAASI,YAAaN,SAAqCI;ACExF,IAAMG,qBAAkDC,gDAAkC;EAAEL,YAAY,CAAC;AAAE,CAAA;AAEpG,IAAMM,aAAa,UAAMC,yBAAWH,kBAAAA;AAEpC,IAAMI,kBAAgDJ,mBAAmBK;AC1BhF,IAAMC,cAAc;EAClBC,IAAI;AACN;AAEA,IAAA,eAAeD;",
|
|
6
|
-
"names": ["parseRootSurfacePlugin", "plugin", "provides", "surface", "components", "undefined", "parseSurfacePlugin", "component", "SurfaceRootContext", "createContext", "useSurface", "useContext", "SurfaceProvider", "Provider", "SurfaceMeta", "id"]
|
|
7
|
-
}
|
|
File without changes
|
|
File without changes
|