@dxos/app-framework 0.4.1-main.618f18c → 0.4.1-main.6957f82
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 +29 -20
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +29 -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 +25 -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 +30 -40
- package/src/plugins/common/navigation.ts +67 -0
|
@@ -14,7 +14,7 @@ import type { Plugin } from '../PluginHost';
|
|
|
14
14
|
/**
|
|
15
15
|
* Basic state provided by a layout plugin.
|
|
16
16
|
*/
|
|
17
|
-
// TODO(
|
|
17
|
+
// TODO(wittjosiah): Replace Zod w/ Effect Schema to align with ECHO.
|
|
18
18
|
export const Layout = z.object({
|
|
19
19
|
fullscreen: z.boolean(),
|
|
20
20
|
sidebarOpen: z.boolean(),
|
|
@@ -27,11 +27,6 @@ export const Layout = z.object({
|
|
|
27
27
|
popoverOpen: z.boolean(),
|
|
28
28
|
popoverContent: z.any().optional().describe('Data to be passed to the popover Surface.'),
|
|
29
29
|
popoverAnchorId: z.string().optional(),
|
|
30
|
-
|
|
31
|
-
// TODO(wittjosiah): Array?
|
|
32
|
-
active: z.string().optional().describe('Id of the currently active item.'),
|
|
33
|
-
// TODO(wittjosiah): History?
|
|
34
|
-
previous: z.string().optional(),
|
|
35
30
|
});
|
|
36
31
|
|
|
37
32
|
export type Layout = z.infer<typeof Layout>;
|
|
@@ -56,16 +51,12 @@ export const parseLayoutPlugin = (plugin: Plugin) => {
|
|
|
56
51
|
//
|
|
57
52
|
|
|
58
53
|
const LAYOUT_ACTION = 'dxos.org/plugin/layout';
|
|
59
|
-
// TODO(wittjosiah): Consider consolidating some action types (e.g. toggle).
|
|
60
54
|
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`,
|
|
55
|
+
SET_LAYOUT = `${LAYOUT_ACTION}/set-layout`,
|
|
56
|
+
|
|
57
|
+
/** @deprecated */
|
|
58
|
+
// TODO(wittjosiah): At minimum this should be renamed, "focus" means something very specific on a web page.
|
|
59
|
+
// Consider removing this action entirely, it's maybe not generic enough to live here.
|
|
69
60
|
FOCUS = `${LAYOUT_ACTION}/focus`,
|
|
70
61
|
}
|
|
71
62
|
|
|
@@ -73,34 +64,33 @@ export enum LayoutAction {
|
|
|
73
64
|
* Expected payload for layout actions.
|
|
74
65
|
*/
|
|
75
66
|
export namespace LayoutAction {
|
|
76
|
-
export type
|
|
67
|
+
export type SetLayout = IntentData<{
|
|
68
|
+
/**
|
|
69
|
+
* Element to set the state of.
|
|
70
|
+
*/
|
|
71
|
+
element: 'fullscreen' | 'sidebar' | 'complementary' | 'dialog' | 'popover' | 'toast';
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Whether the element is on or off.
|
|
75
|
+
*
|
|
76
|
+
* If omitted, the element's state will be toggled or set based on other provided data.
|
|
77
|
+
* For example, if `component` is provided, the state will be set to `true`.
|
|
78
|
+
*/
|
|
77
79
|
state?: boolean;
|
|
78
|
-
}>;
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
export type ToggleComplementarySidebar = IntentData<{
|
|
85
|
-
state?: boolean;
|
|
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
|
-
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Component to render in the dialog or popover.
|
|
83
|
+
*/
|
|
84
|
+
component?: string;
|
|
100
85
|
|
|
101
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Data to be passed to the dialog or popover Surface.
|
|
88
|
+
*/
|
|
89
|
+
subject?: any;
|
|
102
90
|
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Anchor ID for the popover.
|
|
93
|
+
*/
|
|
94
|
+
anchorId?: string;
|
|
105
95
|
}>;
|
|
106
96
|
}
|
|
@@ -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
|
+
}
|