@dxos/app-framework 0.4.1-main.2495eb8 → 0.4.1-main.31058a6
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/index.mjs +42 -20
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +43 -19
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/plugins/common/index.d.ts +1 -0
- package/dist/types/src/plugins/common/index.d.ts.map +1 -1
- package/dist/types/src/plugins/common/layout.d.ts +114 -35
- package/dist/types/src/plugins/common/layout.d.ts.map +1 -1
- package/dist/types/src/plugins/common/navigation.d.ts +47 -0
- package/dist/types/src/plugins/common/navigation.d.ts.map +1 -0
- package/package.json +8 -8
- package/src/plugins/common/index.ts +1 -0
- package/src/plugins/common/layout.ts +50 -40
- package/src/plugins/common/navigation.ts +67 -0
|
@@ -1,8 +1,44 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { type IntentData } from '../IntentPlugin';
|
|
3
3
|
import type { Plugin } from '../PluginHost';
|
|
4
|
+
export declare const Toast: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
title: z.ZodOptional<z.ZodString>;
|
|
7
|
+
description: z.ZodOptional<z.ZodString>;
|
|
8
|
+
icon: z.ZodOptional<z.ZodAny>;
|
|
9
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
closeLabel: z.ZodOptional<z.ZodString>;
|
|
11
|
+
actionLabel: z.ZodOptional<z.ZodString>;
|
|
12
|
+
actionAlt: z.ZodOptional<z.ZodString>;
|
|
13
|
+
onAction: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
id: string;
|
|
16
|
+
title?: string | undefined;
|
|
17
|
+
description?: string | undefined;
|
|
18
|
+
icon?: any;
|
|
19
|
+
duration?: number | undefined;
|
|
20
|
+
closeLabel?: string | undefined;
|
|
21
|
+
actionLabel?: string | undefined;
|
|
22
|
+
actionAlt?: string | undefined;
|
|
23
|
+
onAction?: ((...args: unknown[]) => unknown) | undefined;
|
|
24
|
+
}, {
|
|
25
|
+
id: string;
|
|
26
|
+
title?: string | undefined;
|
|
27
|
+
description?: string | undefined;
|
|
28
|
+
icon?: any;
|
|
29
|
+
duration?: number | undefined;
|
|
30
|
+
closeLabel?: string | undefined;
|
|
31
|
+
actionLabel?: string | undefined;
|
|
32
|
+
actionAlt?: string | undefined;
|
|
33
|
+
onAction?: ((...args: unknown[]) => unknown) | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
export type Toast = z.infer<typeof Toast>;
|
|
4
36
|
/**
|
|
5
37
|
* Basic state provided by a layout plugin.
|
|
38
|
+
*
|
|
39
|
+
* Layout provides the state of global UI landmarks, such as the sidebar, dialog, and popover.
|
|
40
|
+
* Generally only one dialog or popover should be open at a time, a layout plugin should manage this.
|
|
41
|
+
* For other landmarks, such as toasts, rendering them in the layout prevents them from unmounting when navigating.
|
|
6
42
|
*/
|
|
7
43
|
export declare const Layout: z.ZodObject<{
|
|
8
44
|
fullscreen: z.ZodBoolean;
|
|
@@ -13,30 +49,77 @@ export declare const Layout: z.ZodObject<{
|
|
|
13
49
|
popoverOpen: z.ZodBoolean;
|
|
14
50
|
popoverContent: z.ZodOptional<z.ZodAny>;
|
|
15
51
|
popoverAnchorId: z.ZodOptional<z.ZodString>;
|
|
16
|
-
|
|
17
|
-
|
|
52
|
+
toasts: z.ZodArray<z.ZodObject<{
|
|
53
|
+
id: z.ZodString;
|
|
54
|
+
title: z.ZodOptional<z.ZodString>;
|
|
55
|
+
description: z.ZodOptional<z.ZodString>;
|
|
56
|
+
icon: z.ZodOptional<z.ZodAny>;
|
|
57
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
58
|
+
closeLabel: z.ZodOptional<z.ZodString>;
|
|
59
|
+
actionLabel: z.ZodOptional<z.ZodString>;
|
|
60
|
+
actionAlt: z.ZodOptional<z.ZodString>;
|
|
61
|
+
onAction: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
id: string;
|
|
64
|
+
title?: string | undefined;
|
|
65
|
+
description?: string | undefined;
|
|
66
|
+
icon?: any;
|
|
67
|
+
duration?: number | undefined;
|
|
68
|
+
closeLabel?: string | undefined;
|
|
69
|
+
actionLabel?: string | undefined;
|
|
70
|
+
actionAlt?: string | undefined;
|
|
71
|
+
onAction?: ((...args: unknown[]) => unknown) | undefined;
|
|
72
|
+
}, {
|
|
73
|
+
id: string;
|
|
74
|
+
title?: string | undefined;
|
|
75
|
+
description?: string | undefined;
|
|
76
|
+
icon?: any;
|
|
77
|
+
duration?: number | undefined;
|
|
78
|
+
closeLabel?: string | undefined;
|
|
79
|
+
actionLabel?: string | undefined;
|
|
80
|
+
actionAlt?: string | undefined;
|
|
81
|
+
onAction?: ((...args: unknown[]) => unknown) | undefined;
|
|
82
|
+
}>, "many">;
|
|
18
83
|
}, "strip", z.ZodTypeAny, {
|
|
19
84
|
fullscreen: boolean;
|
|
20
85
|
sidebarOpen: boolean;
|
|
21
86
|
complementarySidebarOpen: boolean;
|
|
22
87
|
dialogOpen: boolean;
|
|
23
88
|
popoverOpen: boolean;
|
|
89
|
+
toasts: {
|
|
90
|
+
id: string;
|
|
91
|
+
title?: string | undefined;
|
|
92
|
+
description?: string | undefined;
|
|
93
|
+
icon?: any;
|
|
94
|
+
duration?: number | undefined;
|
|
95
|
+
closeLabel?: string | undefined;
|
|
96
|
+
actionLabel?: string | undefined;
|
|
97
|
+
actionAlt?: string | undefined;
|
|
98
|
+
onAction?: ((...args: unknown[]) => unknown) | undefined;
|
|
99
|
+
}[];
|
|
24
100
|
dialogContent?: any;
|
|
25
101
|
popoverContent?: any;
|
|
26
102
|
popoverAnchorId?: string | undefined;
|
|
27
|
-
active?: string | undefined;
|
|
28
|
-
previous?: string | undefined;
|
|
29
103
|
}, {
|
|
30
104
|
fullscreen: boolean;
|
|
31
105
|
sidebarOpen: boolean;
|
|
32
106
|
complementarySidebarOpen: boolean;
|
|
33
107
|
dialogOpen: boolean;
|
|
34
108
|
popoverOpen: boolean;
|
|
109
|
+
toasts: {
|
|
110
|
+
id: string;
|
|
111
|
+
title?: string | undefined;
|
|
112
|
+
description?: string | undefined;
|
|
113
|
+
icon?: any;
|
|
114
|
+
duration?: number | undefined;
|
|
115
|
+
closeLabel?: string | undefined;
|
|
116
|
+
actionLabel?: string | undefined;
|
|
117
|
+
actionAlt?: string | undefined;
|
|
118
|
+
onAction?: ((...args: unknown[]) => unknown) | undefined;
|
|
119
|
+
}[];
|
|
35
120
|
dialogContent?: any;
|
|
36
121
|
popoverContent?: any;
|
|
37
122
|
popoverAnchorId?: string | undefined;
|
|
38
|
-
active?: string | undefined;
|
|
39
|
-
previous?: string | undefined;
|
|
40
123
|
}>;
|
|
41
124
|
export type Layout = z.infer<typeof Layout>;
|
|
42
125
|
/**
|
|
@@ -50,42 +133,38 @@ export type LayoutProvides = {
|
|
|
50
133
|
*/
|
|
51
134
|
export declare const parseLayoutPlugin: (plugin: Plugin) => Plugin<LayoutProvides> | undefined;
|
|
52
135
|
export declare enum LayoutAction {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
TOGGLE_COMPLEMENTARY_SIDEBAR = "dxos.org/plugin/layout/toggle-complementary-sidebar",
|
|
56
|
-
OPEN_DIALOG = "dxos.org/plugin/layout/open-dialog",
|
|
57
|
-
CLOSE_DIALOG = "dxos.org/plugin/layout/close-dialog",
|
|
58
|
-
OPEN_POPOVER = "dxos.org/plugin/layout/open-popover",
|
|
59
|
-
CLOSE_POPOVER = "dxos.org/plugin/layout/close-popover",
|
|
60
|
-
ACTIVATE = "dxos.org/plugin/layout/activate",
|
|
136
|
+
SET_LAYOUT = "dxos.org/plugin/layout/set-layout",
|
|
137
|
+
/** @deprecated */
|
|
61
138
|
FOCUS = "dxos.org/plugin/layout/focus"
|
|
62
139
|
}
|
|
63
140
|
/**
|
|
64
141
|
* Expected payload for layout actions.
|
|
65
142
|
*/
|
|
66
143
|
export declare namespace LayoutAction {
|
|
67
|
-
type
|
|
144
|
+
type SetLayout = IntentData<{
|
|
145
|
+
/**
|
|
146
|
+
* Element to set the state of.
|
|
147
|
+
*/
|
|
148
|
+
element: 'fullscreen' | 'sidebar' | 'complementary' | 'dialog' | 'popover' | 'toast';
|
|
149
|
+
/**
|
|
150
|
+
* Whether the element is on or off.
|
|
151
|
+
*
|
|
152
|
+
* If omitted, the element's state will be toggled or set based on other provided data.
|
|
153
|
+
* For example, if `component` is provided, the state will be set to `true`.
|
|
154
|
+
*/
|
|
68
155
|
state?: boolean;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
type OpenPopover = IntentData<{
|
|
82
|
-
anchorId: string;
|
|
83
|
-
component: string;
|
|
84
|
-
subject: any;
|
|
85
|
-
}>;
|
|
86
|
-
type ClosePopover = IntentData<{}>;
|
|
87
|
-
type Activate = IntentData<{
|
|
88
|
-
id: string;
|
|
156
|
+
/**
|
|
157
|
+
* Component to render in the dialog or popover.
|
|
158
|
+
*/
|
|
159
|
+
component?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Data to be passed to the dialog or popover Surface.
|
|
162
|
+
*/
|
|
163
|
+
subject?: any;
|
|
164
|
+
/**
|
|
165
|
+
* Anchor ID for the popover.
|
|
166
|
+
*/
|
|
167
|
+
anchorId?: string;
|
|
89
168
|
}>;
|
|
90
169
|
}
|
|
91
170
|
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/common/layout.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAM5C
|
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/common/layout.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAM5C,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWhB,CAAC;AAEH,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,CAAC;AAE1C;;;;;;GAMG;AAEH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAajB,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,WAAY,MAAM,uCAG/C,CAAC;AAOF,oBAAY,YAAY;IACtB,UAAU,sCAAgC;IAE1C,kBAAkB;IAGlB,KAAK,iCAA2B;CACjC;AAED;;GAEG;AACH,yBAAiB,YAAY,CAAC;IAC5B,KAAY,SAAS,GAAG,UAAU,CAAC;QACjC;;WAEG;QACH,OAAO,EAAE,YAAY,GAAG,SAAS,GAAG,eAAe,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC;QAErF;;;;;WAKG;QACH,KAAK,CAAC,EAAE,OAAO,CAAC;QAEhB;;WAEG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;QAEnB;;WAEG;QACH,OAAO,CAAC,EAAE,GAAG,CAAC;QAEd;;WAEG;QACH,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;CACJ"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { IntentData } from '../IntentPlugin';
|
|
3
|
+
import type { Plugin } from '../PluginHost';
|
|
4
|
+
/**
|
|
5
|
+
* Basic state provided by a navigation plugin.
|
|
6
|
+
*/
|
|
7
|
+
export declare const Location: z.ZodObject<{
|
|
8
|
+
active: z.ZodOptional<z.ZodString>;
|
|
9
|
+
previous: z.ZodOptional<z.ZodString>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
active?: string | undefined;
|
|
12
|
+
previous?: string | undefined;
|
|
13
|
+
}, {
|
|
14
|
+
active?: string | undefined;
|
|
15
|
+
previous?: string | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
export type Location = z.infer<typeof Location>;
|
|
18
|
+
/**
|
|
19
|
+
* Provides for a plugin that can manage the app navigation.
|
|
20
|
+
*/
|
|
21
|
+
export type LocationProvides = {
|
|
22
|
+
location: Readonly<Location>;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Type guard for layout plugins.
|
|
26
|
+
*/
|
|
27
|
+
export declare const parseNavigationPlugin: (plugin: Plugin) => Plugin<LocationProvides> | undefined;
|
|
28
|
+
export declare enum NavigationAction {
|
|
29
|
+
ACTIVATE = "dxos.org/plugin/navigation/activate"
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Expected payload for navigation actions.
|
|
33
|
+
*/
|
|
34
|
+
export declare namespace NavigationAction {
|
|
35
|
+
type Activate = IntentData<{
|
|
36
|
+
/**
|
|
37
|
+
* Id to set as active.
|
|
38
|
+
*/
|
|
39
|
+
id: string;
|
|
40
|
+
/**
|
|
41
|
+
* Location of the active item.
|
|
42
|
+
* Defaults to 'main'.
|
|
43
|
+
*/
|
|
44
|
+
key?: string;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=navigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/common/navigation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAM5C;;GAEG;AAGH,eAAO,MAAM,QAAQ;;;;;;;;;EAInB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;CAC9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,WAAY,MAAM,yCAGnD,CAAC;AAOF,oBAAY,gBAAgB;IAC1B,QAAQ,wCAAkC;CAC3C;AAED;;GAEG;AACH,yBAAiB,gBAAgB,CAAC;IAChC,KAAY,QAAQ,GAAG,UAAU,CAAC;QAChC;;WAEG;QACH,EAAE,EAAE,MAAM,CAAC;QAEX;;;WAGG;QACH,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/app-framework",
|
|
3
|
-
"version": "0.4.1-main.
|
|
3
|
+
"version": "0.4.1-main.31058a6",
|
|
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,13 +16,13 @@
|
|
|
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.4.1-main.
|
|
20
|
-
"@dxos/
|
|
21
|
-
"@dxos/
|
|
22
|
-
"@dxos/invariant": "0.4.1-main.
|
|
23
|
-
"@dxos/
|
|
24
|
-
"@dxos/
|
|
25
|
-
"@dxos/
|
|
19
|
+
"@dxos/app-graph": "0.4.1-main.31058a6",
|
|
20
|
+
"@dxos/debug": "0.4.1-main.31058a6",
|
|
21
|
+
"@dxos/local-storage": "0.4.1-main.31058a6",
|
|
22
|
+
"@dxos/invariant": "0.4.1-main.31058a6",
|
|
23
|
+
"@dxos/log": "0.4.1-main.31058a6",
|
|
24
|
+
"@dxos/util": "0.4.1-main.31058a6",
|
|
25
|
+
"@dxos/async": "0.4.1-main.31058a6"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/react": "^18.0.21",
|
|
@@ -11,16 +11,34 @@ import type { Plugin } from '../PluginHost';
|
|
|
11
11
|
// Provides
|
|
12
12
|
//
|
|
13
13
|
|
|
14
|
+
export const Toast = z.object({
|
|
15
|
+
id: z.string(),
|
|
16
|
+
title: z.string().optional(),
|
|
17
|
+
description: z.string().optional(),
|
|
18
|
+
// TODO(wittjosiah): `icon` should be string to be parsed by an `Icon` component.
|
|
19
|
+
icon: z.any().optional(),
|
|
20
|
+
duration: z.number().optional(),
|
|
21
|
+
closeLabel: z.string().optional(),
|
|
22
|
+
actionLabel: z.string().optional(),
|
|
23
|
+
actionAlt: z.string().optional(),
|
|
24
|
+
onAction: z.function().optional(),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export type Toast = z.infer<typeof Toast>;
|
|
28
|
+
|
|
14
29
|
/**
|
|
15
30
|
* Basic state provided by a layout plugin.
|
|
31
|
+
*
|
|
32
|
+
* Layout provides the state of global UI landmarks, such as the sidebar, dialog, and popover.
|
|
33
|
+
* Generally only one dialog or popover should be open at a time, a layout plugin should manage this.
|
|
34
|
+
* For other landmarks, such as toasts, rendering them in the layout prevents them from unmounting when navigating.
|
|
16
35
|
*/
|
|
17
|
-
// TODO(
|
|
36
|
+
// TODO(wittjosiah): Replace Zod w/ Effect Schema to align with ECHO.
|
|
18
37
|
export const Layout = z.object({
|
|
19
38
|
fullscreen: z.boolean(),
|
|
20
39
|
sidebarOpen: z.boolean(),
|
|
21
40
|
complementarySidebarOpen: z.boolean(),
|
|
22
41
|
|
|
23
|
-
// TODO(burdon): Why do we have a single root?
|
|
24
42
|
dialogOpen: z.boolean(),
|
|
25
43
|
dialogContent: z.any().optional().describe('Data to be passed to the dialog Surface.'),
|
|
26
44
|
|
|
@@ -28,10 +46,7 @@ export const Layout = z.object({
|
|
|
28
46
|
popoverContent: z.any().optional().describe('Data to be passed to the popover Surface.'),
|
|
29
47
|
popoverAnchorId: z.string().optional(),
|
|
30
48
|
|
|
31
|
-
|
|
32
|
-
active: z.string().optional().describe('Id of the currently active item.'),
|
|
33
|
-
// TODO(wittjosiah): History?
|
|
34
|
-
previous: z.string().optional(),
|
|
49
|
+
toasts: z.array(Toast),
|
|
35
50
|
});
|
|
36
51
|
|
|
37
52
|
export type Layout = z.infer<typeof Layout>;
|
|
@@ -56,16 +71,12 @@ export const parseLayoutPlugin = (plugin: Plugin) => {
|
|
|
56
71
|
//
|
|
57
72
|
|
|
58
73
|
const LAYOUT_ACTION = 'dxos.org/plugin/layout';
|
|
59
|
-
// TODO(wittjosiah): Consider consolidating some action types (e.g. toggle).
|
|
60
74
|
export enum LayoutAction {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
OPEN_POPOVER = `${LAYOUT_ACTION}/open-popover`,
|
|
67
|
-
CLOSE_POPOVER = `${LAYOUT_ACTION}/close-popover`,
|
|
68
|
-
ACTIVATE = `${LAYOUT_ACTION}/activate`,
|
|
75
|
+
SET_LAYOUT = `${LAYOUT_ACTION}/set-layout`,
|
|
76
|
+
|
|
77
|
+
/** @deprecated */
|
|
78
|
+
// TODO(wittjosiah): At minimum this should be renamed, "focus" means something very specific on a web page.
|
|
79
|
+
// Consider removing this action entirely, it's maybe not generic enough to live here.
|
|
69
80
|
FOCUS = `${LAYOUT_ACTION}/focus`,
|
|
70
81
|
}
|
|
71
82
|
|
|
@@ -73,34 +84,33 @@ export enum LayoutAction {
|
|
|
73
84
|
* Expected payload for layout actions.
|
|
74
85
|
*/
|
|
75
86
|
export namespace LayoutAction {
|
|
76
|
-
export type
|
|
87
|
+
export type SetLayout = IntentData<{
|
|
88
|
+
/**
|
|
89
|
+
* Element to set the state of.
|
|
90
|
+
*/
|
|
91
|
+
element: 'fullscreen' | 'sidebar' | 'complementary' | 'dialog' | 'popover' | 'toast';
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Whether the element is on or off.
|
|
95
|
+
*
|
|
96
|
+
* If omitted, the element's state will be toggled or set based on other provided data.
|
|
97
|
+
* For example, if `component` is provided, the state will be set to `true`.
|
|
98
|
+
*/
|
|
77
99
|
state?: boolean;
|
|
78
|
-
}>;
|
|
79
|
-
|
|
80
|
-
export type ToggleSidebar = IntentData<{
|
|
81
|
-
state?: boolean;
|
|
82
|
-
}>;
|
|
83
100
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
export type OpenDialog = IntentData<{
|
|
89
|
-
component: string;
|
|
90
|
-
subject: any;
|
|
91
|
-
}>;
|
|
92
|
-
|
|
93
|
-
export type CloseDialog = IntentData<{}>;
|
|
94
|
-
|
|
95
|
-
export type OpenPopover = IntentData<{
|
|
96
|
-
anchorId: string;
|
|
97
|
-
component: string;
|
|
98
|
-
subject: any;
|
|
99
|
-
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Component to render in the dialog or popover.
|
|
103
|
+
*/
|
|
104
|
+
component?: string;
|
|
100
105
|
|
|
101
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Data to be passed to the dialog or popover Surface.
|
|
108
|
+
*/
|
|
109
|
+
subject?: any;
|
|
102
110
|
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Anchor ID for the popover.
|
|
113
|
+
*/
|
|
114
|
+
anchorId?: string;
|
|
105
115
|
}>;
|
|
106
116
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
import type { IntentData } from '../IntentPlugin';
|
|
8
|
+
import type { Plugin } from '../PluginHost';
|
|
9
|
+
|
|
10
|
+
//
|
|
11
|
+
// Provides
|
|
12
|
+
//
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Basic state provided by a navigation plugin.
|
|
16
|
+
*/
|
|
17
|
+
// TODO(wittjosiah): Replace Zod w/ Effect Schema to align with ECHO.
|
|
18
|
+
// TODO(wittjosiah): We should align this more with `window.location` along the lines of what React Router does.
|
|
19
|
+
export const Location = z.object({
|
|
20
|
+
active: z.string().optional().describe('Id of the currently active item.'),
|
|
21
|
+
// TODO(wittjosiah): History?
|
|
22
|
+
previous: z.string().optional(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export type Location = z.infer<typeof Location>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Provides for a plugin that can manage the app navigation.
|
|
29
|
+
*/
|
|
30
|
+
export type LocationProvides = {
|
|
31
|
+
location: Readonly<Location>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Type guard for layout plugins.
|
|
36
|
+
*/
|
|
37
|
+
export const parseNavigationPlugin = (plugin: Plugin) => {
|
|
38
|
+
const { success } = Location.safeParse((plugin.provides as any).location);
|
|
39
|
+
return success ? (plugin as Plugin<LocationProvides>) : undefined;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//
|
|
43
|
+
// Intents
|
|
44
|
+
//
|
|
45
|
+
|
|
46
|
+
const NAVIGATION_ACTION = 'dxos.org/plugin/navigation';
|
|
47
|
+
export enum NavigationAction {
|
|
48
|
+
ACTIVATE = `${NAVIGATION_ACTION}/activate`,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Expected payload for navigation actions.
|
|
53
|
+
*/
|
|
54
|
+
export namespace NavigationAction {
|
|
55
|
+
export type Activate = IntentData<{
|
|
56
|
+
/**
|
|
57
|
+
* Id to set as active.
|
|
58
|
+
*/
|
|
59
|
+
id: string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Location of the active item.
|
|
63
|
+
* Defaults to 'main'.
|
|
64
|
+
*/
|
|
65
|
+
key?: string;
|
|
66
|
+
}>;
|
|
67
|
+
}
|