@dxos/app-framework 0.3.6 → 0.3.7-main.0bad7ea

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 (63) hide show
  1. package/dist/lib/browser/chunk-C2K6M6WC.mjs +27 -0
  2. package/dist/lib/browser/chunk-C2K6M6WC.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-CFZ5JAJF.mjs +18 -0
  4. package/dist/lib/browser/chunk-CFZ5JAJF.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-WDA7VA54.mjs +26 -0
  6. package/dist/lib/browser/chunk-WDA7VA54.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +142 -190
  8. package/dist/lib/browser/index.mjs.map +4 -4
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/plugin-CBPJO5NB.mjs +63 -0
  11. package/dist/lib/browser/plugin-CBPJO5NB.mjs.map +7 -0
  12. package/dist/lib/browser/plugin-XEJ5RYCP.mjs +39 -0
  13. package/dist/lib/browser/plugin-XEJ5RYCP.mjs.map +7 -0
  14. package/dist/lib/node/index.cjs +334 -188
  15. package/dist/lib/node/index.cjs.map +4 -4
  16. package/dist/lib/node/meta.json +1 -1
  17. package/dist/types/src/App.d.ts +13 -3
  18. package/dist/types/src/App.d.ts.map +1 -1
  19. package/dist/types/src/plugins/IntentPlugin/index.d.ts +1 -1
  20. package/dist/types/src/plugins/IntentPlugin/index.d.ts.map +1 -1
  21. package/dist/types/src/plugins/IntentPlugin/meta.d.ts +5 -0
  22. package/dist/types/src/plugins/IntentPlugin/meta.d.ts.map +1 -0
  23. package/dist/types/src/plugins/IntentPlugin/plugin.d.ts +9 -0
  24. package/dist/types/src/plugins/IntentPlugin/plugin.d.ts.map +1 -0
  25. package/dist/types/src/plugins/IntentPlugin/{IntentPlugin.d.ts → provides.d.ts} +2 -7
  26. package/dist/types/src/plugins/IntentPlugin/provides.d.ts.map +1 -0
  27. package/dist/types/src/plugins/PluginHost/PluginContext.d.ts +27 -3
  28. package/dist/types/src/plugins/PluginHost/PluginContext.d.ts.map +1 -1
  29. package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +7 -4
  30. package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +1 -1
  31. package/dist/types/src/plugins/PluginHost/plugin.d.ts +49 -1
  32. package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +1 -1
  33. package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts +9 -4
  34. package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts.map +1 -1
  35. package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts +8 -2
  36. package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts.map +1 -1
  37. package/dist/types/src/plugins/SurfacePlugin/index.d.ts +1 -1
  38. package/dist/types/src/plugins/SurfacePlugin/index.d.ts.map +1 -1
  39. package/dist/types/src/plugins/SurfacePlugin/meta.d.ts +5 -0
  40. package/dist/types/src/plugins/SurfacePlugin/meta.d.ts.map +1 -0
  41. package/dist/types/src/plugins/SurfacePlugin/plugin.d.ts +8 -0
  42. package/dist/types/src/plugins/SurfacePlugin/plugin.d.ts.map +1 -0
  43. package/dist/types/src/plugins/SurfacePlugin/{SurfacePlugin.d.ts → provides.d.ts} +2 -6
  44. package/dist/types/src/plugins/SurfacePlugin/provides.d.ts.map +1 -0
  45. package/package.json +8 -6
  46. package/src/App.tsx +24 -6
  47. package/src/plugins/IntentPlugin/index.ts +2 -1
  48. package/src/plugins/IntentPlugin/meta.ts +9 -0
  49. package/src/plugins/IntentPlugin/{IntentPlugin.tsx → plugin.tsx} +8 -22
  50. package/src/plugins/IntentPlugin/provides.ts +23 -0
  51. package/src/plugins/PluginHost/PluginContext.tsx +36 -5
  52. package/src/plugins/PluginHost/PluginHost.tsx +59 -98
  53. package/src/plugins/PluginHost/plugin.ts +31 -1
  54. package/src/plugins/SurfacePlugin/Surface.tsx +34 -27
  55. package/src/plugins/SurfacePlugin/SurfaceRootContext.tsx +11 -2
  56. package/src/plugins/SurfacePlugin/index.ts +2 -1
  57. package/src/plugins/SurfacePlugin/meta.ts +9 -0
  58. package/src/plugins/SurfacePlugin/plugin.tsx +36 -0
  59. package/src/plugins/SurfacePlugin/provides.ts +25 -0
  60. package/tsconfig.json +3 -0
  61. package/dist/types/src/plugins/IntentPlugin/IntentPlugin.d.ts.map +0 -1
  62. package/dist/types/src/plugins/SurfacePlugin/SurfacePlugin.d.ts.map +0 -1
  63. package/src/plugins/SurfacePlugin/SurfacePlugin.tsx +0 -53
@@ -2,7 +2,7 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import React, { type FC, type PropsWithChildren, type ReactNode } from 'react';
5
+ import React, { forwardRef, type FC, type ReactNode, Fragment, type ForwardedRef, type PropsWithChildren } from 'react';
6
6
  import { createContext, useContext } from 'react';
7
7
 
8
8
  import { ErrorBoundary } from './ErrorBoundary';
@@ -13,7 +13,7 @@ import { type SurfaceComponent, useSurface } from './SurfaceRootContext';
13
13
  */
14
14
  export type Direction = 'inline' | 'inline-reverse' | 'block' | 'block-reverse';
15
15
 
16
- export type SurfaceProps = {
16
+ export type SurfaceProps = PropsWithChildren<{
17
17
  /**
18
18
  * Role defines how the data should be rendered.
19
19
  */
@@ -56,35 +56,43 @@ export type SurfaceProps = {
56
56
  * NOTE: This is not yet implemented.
57
57
  */
58
58
  direction?: Direction;
59
- };
59
+
60
+ /**
61
+ * Additional props to pass to the component.
62
+ * These props are not used by Surface itself but may be used by components which resolve the surface.
63
+ */
64
+ [key: string]: unknown;
65
+ }>;
60
66
 
61
67
  /**
62
68
  * A surface is a named region of the screen that can be populated by plugins.
63
69
  */
64
- export const Surface = ({ role, name = role, fallback, ...rest }: SurfaceProps) => {
65
- const props = { role, name, fallback, ...rest };
66
- const context = useContext(SurfaceContext);
67
- const data = props.data ?? ((name && context?.surfaces?.[name]?.data) || {});
68
-
69
- return (
70
- <>
71
- {fallback ? (
72
- <ErrorBoundary data={data} fallback={fallback}>
73
- <SurfaceResolver {...props} />
74
- </ErrorBoundary>
75
- ) : (
76
- <SurfaceResolver {...props} />
77
- )}
78
- </>
79
- );
80
- };
70
+ export const Surface = forwardRef<HTMLElement, SurfaceProps>(
71
+ ({ role, name = role, fallback, ...rest }, forwardedRef) => {
72
+ const props = { role, name, fallback, ...rest };
73
+ const context = useContext(SurfaceContext);
74
+ const data = props.data ?? ((name && context?.surfaces?.[name]?.data) || {});
75
+
76
+ return (
77
+ <>
78
+ {fallback ? (
79
+ <ErrorBoundary data={data} fallback={fallback}>
80
+ <SurfaceResolver {...props} ref={forwardedRef} />
81
+ </ErrorBoundary>
82
+ ) : (
83
+ <SurfaceResolver {...props} ref={forwardedRef} />
84
+ )}
85
+ </>
86
+ );
87
+ },
88
+ );
81
89
 
82
90
  const SurfaceContext = createContext<SurfaceProps | null>(null);
83
91
 
84
- const SurfaceResolver = (props: SurfaceProps) => {
92
+ const SurfaceResolver = forwardRef<HTMLElement, SurfaceProps>((props, forwardedRef) => {
85
93
  const { components } = useSurface();
86
94
  const parent = useContext(SurfaceContext);
87
- const nodes = resolveNodes(components, props, parent);
95
+ const nodes = resolveNodes(components, props, parent, forwardedRef);
88
96
  const currentContext: SurfaceProps = {
89
97
  ...props,
90
98
  surfaces: {
@@ -98,12 +106,13 @@ const SurfaceResolver = (props: SurfaceProps) => {
98
106
  {nodes.length > 0 ? nodes : props.contentFallback ? <props.contentFallback /> : null}
99
107
  </SurfaceContext.Provider>
100
108
  );
101
- };
109
+ });
102
110
 
103
111
  const resolveNodes = (
104
112
  components: Record<string, SurfaceComponent>,
105
113
  props: SurfaceProps,
106
114
  context: SurfaceProps | null,
115
+ forwardedRef: ForwardedRef<HTMLElement>,
107
116
  ): ReactNode[] => {
108
117
  const data = {
109
118
  ...((props.name && context?.surfaces?.[props.name]?.data) || {}),
@@ -112,12 +121,10 @@ const resolveNodes = (
112
121
 
113
122
  const nodes = Object.entries(components)
114
123
  .map(([key, component]) => {
115
- const result = component(data, props.role);
116
- return result ? <Wrapper key={key}>{result}</Wrapper> : undefined;
124
+ const result = component({ ...props, data }, forwardedRef);
125
+ return result ? <Fragment key={key}>{result}</Fragment> : undefined;
117
126
  })
118
127
  .filter((Component): Component is JSX.Element => Boolean(Component));
119
128
 
120
129
  return props.limit ? nodes.slice(0, props.limit) : nodes;
121
130
  };
122
-
123
- const Wrapper = ({ children }: PropsWithChildren) => <>{children}</>;
@@ -2,14 +2,23 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { createContext, useContext, type Context, type Provider, type ReactNode } from 'react';
5
+ import { createContext, useContext, type Context, type Provider, type ReactNode, type ForwardedRef } from 'react';
6
+
7
+ import { type SurfaceProps } from './Surface';
8
+
9
+ // TODO(wittjosiah): Factor out.
10
+ type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
11
+ [Property in Key]-?: Type[Property];
12
+ };
13
+
14
+ type SurfaceComponentProps = WithRequiredProperty<SurfaceProps, 'data'>;
6
15
 
7
16
  /**
8
17
  * Function which resolves a Surface.
9
18
  *
10
19
  * If a null value is returned, the rendering is deferred to other plugins.
11
20
  */
12
- export type SurfaceComponent = (data: Record<string, unknown>, role?: string) => ReactNode;
21
+ export type SurfaceComponent = (props: SurfaceComponentProps, forwardedRef: ForwardedRef<HTMLElement>) => ReactNode;
13
22
 
14
23
  export type SurfaceRootContext = {
15
24
  components: Record<string, SurfaceComponent>;
@@ -2,7 +2,8 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ export * from './provides';
6
+
5
7
  export * from './ErrorBoundary';
6
8
  export * from './Surface';
7
- export * from './SurfacePlugin';
8
9
  export * from './SurfaceRootContext';
@@ -0,0 +1,9 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ const SurfaceMeta = {
6
+ id: 'dxos.org/plugin/surface',
7
+ };
8
+
9
+ export default SurfaceMeta;
@@ -0,0 +1,36 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { deepSignal, shallow } from 'deepsignal/react';
6
+ import React from 'react';
7
+
8
+ import { SurfaceProvider, type SurfaceRootContext } from './SurfaceRootContext';
9
+ import SurfaceMeta from './meta';
10
+ import { parseSurfacePlugin, type SurfacePluginProvides } from './provides';
11
+ import type { PluginDefinition } from '../PluginHost';
12
+ import { filterPlugins } from '../helpers';
13
+
14
+ /**
15
+ * Provides a registry of surface components.
16
+ */
17
+ const SurfacePlugin = (): PluginDefinition<SurfacePluginProvides> => {
18
+ const state = deepSignal<SurfaceRootContext>({ components: {} });
19
+
20
+ return {
21
+ meta: SurfaceMeta,
22
+ ready: async (plugins) => {
23
+ state.components = shallow(
24
+ filterPlugins(plugins, parseSurfacePlugin).reduce((acc, plugin) => {
25
+ return { ...acc, [plugin.meta.id]: plugin.provides.surface.component };
26
+ }, {}),
27
+ );
28
+ },
29
+ provides: {
30
+ surface: state,
31
+ context: ({ children }) => <SurfaceProvider value={state}>{children}</SurfaceProvider>,
32
+ },
33
+ };
34
+ };
35
+
36
+ export default SurfacePlugin;
@@ -0,0 +1,25 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { type SurfaceComponent, type SurfaceRootContext } from './SurfaceRootContext';
6
+ import { type Plugin } from '../PluginHost';
7
+
8
+ export type SurfaceProvides = {
9
+ surface: {
10
+ /**
11
+ * Used by the `Surface` resolver to find a component to render.
12
+ */
13
+ component: SurfaceComponent;
14
+ };
15
+ };
16
+
17
+ export type SurfacePluginProvides = {
18
+ surface: SurfaceRootContext;
19
+ };
20
+
21
+ export const parseRootSurfacePlugin = (plugin?: Plugin) =>
22
+ (plugin?.provides as any)?.surface?.components ? (plugin as Plugin<SurfacePluginProvides>) : undefined;
23
+
24
+ export const parseSurfacePlugin = (plugin?: Plugin) =>
25
+ (plugin?.provides as any)?.surface?.component ? (plugin as Plugin<SurfaceProvides>) : undefined;
package/tsconfig.json CHANGED
@@ -26,6 +26,9 @@
26
26
  {
27
27
  "path": "../../common/invariant"
28
28
  },
29
+ {
30
+ "path": "../../common/local-storage"
31
+ },
29
32
  {
30
33
  "path": "../../common/log"
31
34
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"IntentPlugin.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/IntentPlugin/IntentPlugin.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAGnE,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE;QACN,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,GAAG,CAAC;KACtD,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,iBAAiB,WAAY,MAAM,6CACkD,CAAC;AAEnG,eAAO,MAAM,yBAAyB,WAAY,MAAM,+CAC4C,CAAC;AAErG;;;GAGG;AACH,eAAO,MAAM,YAAY,QAAO,iBAAiB,oBAAoB,CAuCpE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"SurfacePlugin.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/SurfacePlugin/SurfacePlugin.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,gBAAgB,EAAmB,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACvG,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAG9D,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE;QACP;;WAEG;QACH,SAAS,EAAE,gBAAgB,CAAC;KAC7B,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,kBAAkB,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,sBAAsB,YAAa,MAAM,8CACkD,CAAC;AAEzG,eAAO,MAAM,kBAAkB,YAAa,MAAM,wCAC+C,CAAC;AAElG;;GAEG;AACH,eAAO,MAAM,aAAa,QAAO,iBAAiB,qBAAqB,CAmBtE,CAAC"}
@@ -1,53 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { deepSignal, shallow } from 'deepsignal/react';
6
- import React from 'react';
7
-
8
- import { type SurfaceComponent, SurfaceProvider, type SurfaceRootContext } from './SurfaceRootContext';
9
- import type { Plugin, PluginDefinition } from '../PluginHost';
10
- import { filterPlugins } from '../helpers';
11
-
12
- export type SurfaceProvides = {
13
- surface: {
14
- /**
15
- * Used by the `Surface` resolver to find a component to render.
16
- */
17
- component: SurfaceComponent;
18
- };
19
- };
20
-
21
- export type SurfacePluginProvides = {
22
- surface: SurfaceRootContext;
23
- };
24
-
25
- export const parseRootSurfacePlugin = (plugin?: Plugin) =>
26
- (plugin?.provides as any)?.surface?.components ? (plugin as Plugin<SurfacePluginProvides>) : undefined;
27
-
28
- export const parseSurfacePlugin = (plugin?: Plugin) =>
29
- (plugin?.provides as any)?.surface?.component ? (plugin as Plugin<SurfaceProvides>) : undefined;
30
-
31
- /**
32
- * Provides a registry of surface components.
33
- */
34
- export const SurfacePlugin = (): PluginDefinition<SurfacePluginProvides> => {
35
- const state = deepSignal<SurfaceRootContext>({ components: {} });
36
-
37
- return {
38
- meta: {
39
- id: 'dxos.org/plugin/surface',
40
- },
41
- ready: async (plugins) => {
42
- state.components = shallow(
43
- filterPlugins(plugins, parseSurfacePlugin).reduce((acc, plugin) => {
44
- return { ...acc, [plugin.meta.id]: plugin.provides.surface.component };
45
- }, {}),
46
- );
47
- },
48
- provides: {
49
- surface: state,
50
- context: ({ children }) => <SurfaceProvider value={state}>{children}</SurfaceProvider>,
51
- },
52
- };
53
- };