@dxos/app-framework 0.3.8-next.f4e0086 → 0.3.9-main.27aafd0

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.
Files changed (38) hide show
  1. package/dist/lib/browser/{chunk-WDA7VA54.mjs → chunk-MNFAM2GF.mjs} +1 -1
  2. package/dist/lib/browser/{chunk-WDA7VA54.mjs.map → chunk-MNFAM2GF.mjs.map} +2 -2
  3. package/dist/lib/browser/index.mjs +33 -7
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/{plugin-XEJ5RYCP.mjs → plugin-JDIMDLDU.mjs} +2 -2
  7. package/dist/lib/node/chunk-BOQBLWMX.cjs +49 -0
  8. package/dist/lib/node/chunk-BOQBLWMX.cjs.map +7 -0
  9. package/dist/lib/node/chunk-DC3GU6QR.cjs +48 -0
  10. package/dist/lib/node/chunk-DC3GU6QR.cjs.map +7 -0
  11. package/dist/lib/node/chunk-VDKZ7AAF.cjs +43 -0
  12. package/dist/lib/node/chunk-VDKZ7AAF.cjs.map +7 -0
  13. package/dist/lib/node/index.cjs +90 -299
  14. package/dist/lib/node/index.cjs.map +4 -4
  15. package/dist/lib/node/meta.json +1 -1
  16. package/dist/lib/node/plugin-JGSJGRMS.cjs +61 -0
  17. package/dist/lib/node/plugin-JGSJGRMS.cjs.map +7 -0
  18. package/dist/lib/node/plugin-WDNRX2SR.cjs +84 -0
  19. package/dist/lib/node/plugin-WDNRX2SR.cjs.map +7 -0
  20. package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts +2 -0
  21. package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts.map +1 -1
  22. package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts +10 -2
  23. package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts.map +1 -1
  24. package/dist/types/src/plugins/SurfacePlugin/helpers.d.ts +21 -0
  25. package/dist/types/src/plugins/SurfacePlugin/helpers.d.ts.map +1 -0
  26. package/dist/types/src/plugins/SurfacePlugin/index.d.ts +1 -0
  27. package/dist/types/src/plugins/SurfacePlugin/index.d.ts.map +1 -1
  28. package/dist/types/src/plugins/common/graph.d.ts +2 -2
  29. package/dist/types/src/plugins/common/graph.d.ts.map +1 -1
  30. package/dist/types/src/plugins/common/layout.d.ts +6 -6
  31. package/package.json +8 -8
  32. package/project.json +5 -47
  33. package/src/plugins/SurfacePlugin/Surface.tsx +34 -5
  34. package/src/plugins/SurfacePlugin/SurfaceRootContext.tsx +15 -2
  35. package/src/plugins/SurfacePlugin/helpers.ts +22 -0
  36. package/src/plugins/SurfacePlugin/index.ts +1 -0
  37. package/src/plugins/common/graph.ts +2 -2
  38. /package/dist/lib/browser/{plugin-XEJ5RYCP.mjs.map → plugin-JDIMDLDU.mjs.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 GraphPluginProvides = {
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<GraphPluginProvides> | undefined;
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,mBAAmB,GAAG;IAChC,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,4CAC6C,CAAC;AAE7F;;GAEG;AACH,eAAO,MAAM,uBAAuB,WAAY,MAAM,6CAC0C,CAAC"}
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"}
@@ -15,27 +15,27 @@ export declare const Layout: z.ZodObject<{
15
15
  active: z.ZodOptional<z.ZodString>;
16
16
  previous: z.ZodOptional<z.ZodString>;
17
17
  }, "strip", z.ZodTypeAny, {
18
- dialogContent?: any;
19
- popoverAnchorId?: string | undefined;
20
- popoverContent?: any;
21
- active?: string | undefined;
22
- previous?: string | undefined;
23
18
  fullscreen: boolean;
24
19
  sidebarOpen: boolean;
25
20
  complementarySidebarOpen: boolean;
26
21
  dialogOpen: boolean;
27
22
  popoverOpen: boolean;
28
- }, {
29
23
  dialogContent?: any;
30
24
  popoverAnchorId?: string | undefined;
31
25
  popoverContent?: any;
32
26
  active?: string | undefined;
33
27
  previous?: string | undefined;
28
+ }, {
34
29
  fullscreen: boolean;
35
30
  sidebarOpen: boolean;
36
31
  complementarySidebarOpen: boolean;
37
32
  dialogOpen: boolean;
38
33
  popoverOpen: boolean;
34
+ dialogContent?: any;
35
+ popoverAnchorId?: string | undefined;
36
+ popoverContent?: any;
37
+ active?: string | undefined;
38
+ previous?: string | undefined;
39
39
  }>;
40
40
  export type Layout = z.infer<typeof Layout>;
41
41
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/app-framework",
3
- "version": "0.3.8-next.f4e0086",
3
+ "version": "0.3.9-main.27aafd0",
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",
@@ -15,13 +15,13 @@
15
15
  "@phosphor-icons/react": "^2.0.5",
16
16
  "@preact/signals-react": "^1.3.6",
17
17
  "deepsignal": "1.4.0-shallow.0",
18
- "zod": "^3.19.1",
19
- "@dxos/app-graph": "0.3.8-next.f4e0086",
20
- "@dxos/async": "0.3.8-next.f4e0086",
21
- "@dxos/debug": "0.3.8-next.f4e0086",
22
- "@dxos/invariant": "0.3.8-next.f4e0086",
23
- "@dxos/local-storage": "0.3.8-next.f4e0086",
24
- "@dxos/log": "0.3.8-next.f4e0086"
18
+ "zod": "^3.22.4",
19
+ "@dxos/app-graph": "0.3.9-main.27aafd0",
20
+ "@dxos/invariant": "0.3.9-main.27aafd0",
21
+ "@dxos/async": "0.3.9-main.27aafd0",
22
+ "@dxos/debug": "0.3.9-main.27aafd0",
23
+ "@dxos/local-storage": "0.3.9-main.27aafd0",
24
+ "@dxos/log": "0.3.9-main.27aafd0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/react": "^18.0.21",
package/project.json CHANGED
@@ -2,42 +2,15 @@
2
2
  "sourceRoot": "packages/sdk/app-framework/src",
3
3
  "projectType": "application",
4
4
  "targets": {
5
- "build": {
6
- "executor": "@nx/js:tsc",
7
- "options": {
8
- "main": "packages/sdk/app-framework/src/index.ts",
9
- "outputPath": "packages/sdk/app-framework/dist/types",
10
- "tsConfig": "packages/sdk/app-framework/tsconfig.json"
11
- },
12
- "outputs": [
13
- "{options.outputPath}"
14
- ]
15
- },
5
+ "build": {},
16
6
  "compile": {
17
- "executor": "@dxos/esbuild:build",
18
7
  "options": {
19
8
  "entryPoints": [
20
9
  "packages/sdk/app-framework/src/index.ts"
21
- ],
22
- "outputPath": "packages/sdk/app-framework/dist/lib"
23
- },
24
- "outputs": [
25
- "{options.outputPath}"
26
- ]
27
- },
28
- "lint": {
29
- "executor": "@nx/linter:eslint",
30
- "options": {
31
- "format": "unix",
32
- "lintFilePatterns": [
33
- "packages/sdk/app-framework/**/*.{ts,tsx,js,jsx}"
34
- ],
35
- "quiet": true
36
- },
37
- "outputs": [
38
- "{options.outputFile}"
39
- ]
10
+ ]
11
+ }
40
12
  },
13
+ "lint": {},
41
14
  "storybook": {
42
15
  "configurations": {
43
16
  "ci": {
@@ -50,26 +23,11 @@
50
23
  }
51
24
  },
52
25
  "test": {
53
- "executor": "@dxos/test:run",
54
26
  "options": {
55
27
  "ciEnvironments": [
56
28
  "nodejs"
57
- ],
58
- "coveragePath": "coverage/packages/sdk/app-framework",
59
- "outputPath": "tmp/mocha/packages/sdk/app-framework",
60
- "resultsPath": "test-results/packages/sdk/app-framework",
61
- "testPatterns": [
62
- "packages/sdk/app-framework/src/**/*.test.{ts,js}"
63
- ],
64
- "watchPatterns": [
65
- "packages/sdk/app-framework/src/**/*"
66
29
  ]
67
- },
68
- "outputs": [
69
- "{options.coveragePath}",
70
- "{options.outputPath}",
71
- "{options.resultsPath}"
72
- ]
30
+ }
73
31
  }
74
32
  },
75
33
  "implicitDependencies": [
@@ -2,11 +2,19 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import React, { forwardRef, type FC, type ReactNode, Fragment, type ForwardedRef, type PropsWithChildren } from '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
- return result ? <Fragment key={key}>{result}</Fragment> : undefined;
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
- .filter((Component): Component is JSX.Element => Boolean(Component));
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 ReactNode, type ForwardedRef } from 'react';
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 = (props: SurfaceComponentProps, forwardedRef: ForwardedRef<HTMLElement>) => ReactNode;
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';
@@ -2,6 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ export * from './helpers';
5
6
  export * from './provides';
6
7
 
7
8
  export * from './ErrorBoundary';
@@ -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 GraphPluginProvides = {
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<GraphPluginProvides>) : undefined;
27
+ (plugin.provides as any).graph?.root ? (plugin as Plugin<GraphProvides>) : undefined;
28
28
 
29
29
  /**
30
30
  * Type guard for graph builder plugins.