@dxos/plugin-simple-layout 0.8.4-main.9735255 → 0.8.4-main.9be5663bfe
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 +44 -64
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +44 -63
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/SimpleLayoutPlugin.d.ts +1 -1
- package/dist/types/src/SimpleLayoutPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +6 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +21 -6
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/{react-root/react-root.d.ts → react-root.d.ts} +1 -1
- package/dist/types/src/capabilities/react-root.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/capabilities/{spotlight-dismiss/spotlight-dismiss.d.ts → spotlight-dismiss.d.ts} +1 -1
- package/dist/types/src/capabilities/spotlight-dismiss.d.ts.map +1 -0
- package/dist/types/src/capabilities/{state/state.d.ts → state.d.ts} +2 -2
- package/dist/types/src/capabilities/state.d.ts.map +1 -0
- package/dist/types/src/capabilities/url-handler.d.ts +12 -0
- package/dist/types/src/capabilities/url-handler.d.ts.map +1 -0
- package/dist/types/src/components/ContentError.stories.d.ts +26 -21
- package/dist/types/src/components/ContentError.stories.d.ts.map +1 -1
- package/dist/types/src/components/DebugOverlay/DebugOverlay.d.ts +19 -0
- package/dist/types/src/components/DebugOverlay/DebugOverlay.d.ts.map +1 -0
- package/dist/types/src/components/DebugOverlay/index.d.ts +2 -0
- package/dist/types/src/components/DebugOverlay/index.d.ts.map +1 -0
- package/dist/types/src/components/Home/Home.d.ts.map +1 -1
- package/dist/types/src/components/Loading/Loading.d.ts +3 -0
- package/dist/types/src/components/Loading/Loading.d.ts.map +1 -0
- package/dist/types/src/components/{ContentLoading.stories.d.ts → Loading/Loading.stories.d.ts} +1 -1
- package/dist/types/src/components/Loading/Loading.stories.d.ts.map +1 -0
- package/dist/types/src/components/Loading/index.d.ts +2 -0
- package/dist/types/src/components/Loading/index.d.ts.map +1 -0
- package/dist/types/src/components/MobileLayout/MobileLayout.d.ts +35 -0
- package/dist/types/src/components/MobileLayout/MobileLayout.d.ts.map +1 -0
- package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts +7 -0
- package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts.map +1 -0
- package/dist/types/src/components/MobileLayout/index.d.ts +2 -0
- package/dist/types/src/components/MobileLayout/index.d.ts.map +1 -0
- package/dist/types/src/components/NavBranch/NavBranch.d.ts +11 -0
- package/dist/types/src/components/NavBranch/NavBranch.d.ts.map +1 -0
- package/dist/types/src/components/NavBranch/index.d.ts +2 -0
- package/dist/types/src/components/NavBranch/index.d.ts.map +1 -0
- package/dist/types/src/components/Popover/Popover.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/AppBar.d.ts +24 -0
- package/dist/types/src/components/SimpleLayout/AppBar.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts +54 -0
- package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/Drawer.d.ts +1 -1
- package/dist/types/src/components/SimpleLayout/Drawer.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/Main.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/NavBar.d.ts +13 -8
- package/dist/types/src/components/SimpleLayout/NavBar.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts +31 -25
- package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/SimpleLayout.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts +26 -25
- package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/index.d.ts +3 -0
- package/dist/types/src/components/SimpleLayout/index.d.ts.map +1 -1
- package/dist/types/src/components/hooks.d.ts +4 -2
- package/dist/types/src/components/hooks.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +4 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/actions.d.ts +19 -0
- package/dist/types/src/hooks/actions.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +4 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useAppBarProps.d.ts +7 -0
- package/dist/types/src/hooks/useAppBarProps.d.ts.map +1 -0
- package/dist/types/src/hooks/useCompanions.d.ts +5 -1
- package/dist/types/src/hooks/useCompanions.d.ts.map +1 -1
- package/dist/types/src/hooks/useDrawerActions.d.ts +13 -0
- package/dist/types/src/hooks/useDrawerActions.d.ts.map +1 -0
- package/dist/types/src/hooks/useNavbarActions.d.ts +14 -0
- package/dist/types/src/hooks/useNavbarActions.d.ts.map +1 -0
- package/dist/types/src/hooks/useSimpleLayoutState.d.ts +3 -3
- package/dist/types/src/hooks/useSimpleLayoutState.d.ts.map +1 -1
- package/dist/types/src/operations/close.d.ts +5 -0
- package/dist/types/src/operations/close.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +3 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/open.d.ts +5 -0
- package/dist/types/src/operations/open.d.ts.map +1 -0
- package/dist/types/src/operations/revert-workspace.d.ts +5 -0
- package/dist/types/src/operations/revert-workspace.d.ts.map +1 -0
- package/dist/types/src/operations/set-layout-mode.d.ts +5 -0
- package/dist/types/src/operations/set-layout-mode.d.ts.map +1 -0
- package/dist/types/src/operations/set.d.ts +5 -0
- package/dist/types/src/operations/set.d.ts.map +1 -0
- package/dist/types/src/operations/state-access.d.ts +8 -0
- package/dist/types/src/operations/state-access.d.ts.map +1 -0
- package/dist/types/src/operations/switch-workspace.d.ts +5 -0
- package/dist/types/src/operations/switch-workspace.d.ts.map +1 -0
- package/dist/types/src/operations/update-complementary.d.ts +5 -0
- package/dist/types/src/operations/update-complementary.d.ts.map +1 -0
- package/dist/types/src/operations/update-dialog.d.ts +5 -0
- package/dist/types/src/operations/update-dialog.d.ts.map +1 -0
- package/dist/types/src/operations/update-popover.d.ts +5 -0
- package/dist/types/src/operations/update-popover.d.ts.map +1 -0
- package/dist/types/src/operations/update-sidebar.d.ts +5 -0
- package/dist/types/src/operations/update-sidebar.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +26 -19
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/capabilities.d.ts +17 -8
- package/dist/types/src/types/capabilities.d.ts.map +1 -1
- package/dist/types/src/types/events.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +46 -30
- package/src/SimpleLayoutPlugin.ts +24 -13
- package/src/capabilities/app-graph-builder.ts +21 -0
- package/src/capabilities/index.ts +13 -6
- package/src/capabilities/operation-handler.ts +14 -0
- package/src/capabilities/{react-root/react-root.tsx → react-root.tsx} +4 -4
- package/src/capabilities/react-surface.tsx +50 -0
- package/src/capabilities/{spotlight-dismiss/spotlight-dismiss.ts → spotlight-dismiss.ts} +2 -2
- package/src/capabilities/{state/state.tsx → state.tsx} +6 -5
- package/src/capabilities/url-handler.ts +161 -0
- package/src/components/ContentError.stories.tsx +8 -7
- package/src/components/DebugOverlay/DebugOverlay.tsx +96 -0
- package/src/components/DebugOverlay/index.ts +5 -0
- package/src/components/Dialog/Dialog.tsx +6 -6
- package/src/components/Home/Home.tsx +51 -43
- package/src/components/{ContentLoading.stories.tsx → Loading/Loading.stories.tsx} +5 -5
- package/src/components/{ContentLoading.tsx → Loading/Loading.tsx} +2 -2
- package/src/components/Loading/index.ts +5 -0
- package/src/components/MobileLayout/MobileLayout.stories.tsx +133 -0
- package/src/components/MobileLayout/MobileLayout.tsx +374 -0
- package/src/components/MobileLayout/index.ts +5 -0
- package/src/components/NavBranch/NavBranch.tsx +128 -0
- package/src/components/{Workspace → NavBranch}/index.ts +1 -1
- package/src/components/Popover/Popover.tsx +10 -9
- package/src/components/SimpleLayout/AppBar.stories.tsx +143 -0
- package/src/components/SimpleLayout/AppBar.tsx +94 -0
- package/src/components/SimpleLayout/Drawer.tsx +39 -92
- package/src/components/SimpleLayout/Main.tsx +40 -34
- package/src/components/SimpleLayout/NavBar.stories.tsx +131 -24
- package/src/components/SimpleLayout/NavBar.tsx +18 -51
- package/src/components/SimpleLayout/SimpleLayout.stories.tsx +45 -59
- package/src/components/SimpleLayout/SimpleLayout.tsx +41 -23
- package/src/components/SimpleLayout/index.ts +3 -0
- package/src/components/hooks.ts +9 -9
- package/src/components/index.ts +4 -2
- package/src/hooks/actions.ts +84 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useAppBarProps.ts +115 -0
- package/src/hooks/useCompanions.ts +8 -5
- package/src/hooks/useDrawerActions.ts +100 -0
- package/src/hooks/useNavbarActions.ts +87 -0
- package/src/hooks/useSimpleLayoutState.ts +5 -5
- package/src/meta.ts +1 -1
- package/src/operations/close.ts +34 -0
- package/src/operations/index.ts +16 -0
- package/src/operations/open.ts +63 -0
- package/src/operations/revert-workspace.ts +22 -0
- package/src/operations/set-layout-mode.ts +12 -0
- package/src/operations/set.ts +23 -0
- package/src/operations/state-access.ts +19 -0
- package/src/operations/switch-workspace.ts +26 -0
- package/src/operations/update-complementary.ts +35 -0
- package/src/operations/update-dialog.ts +28 -0
- package/src/operations/update-popover.ts +35 -0
- package/src/operations/update-sidebar.ts +12 -0
- package/src/translations.ts +21 -19
- package/src/types/capabilities.ts +14 -10
- package/src/types/events.ts +3 -2
- package/dist/lib/browser/chunk-LR3EE3VB.mjs +0 -789
- package/dist/lib/browser/chunk-LR3EE3VB.mjs.map +0 -7
- package/dist/lib/browser/chunk-P77G4YTR.mjs +0 -29
- package/dist/lib/browser/chunk-P77G4YTR.mjs.map +0 -7
- package/dist/lib/browser/operation-resolver-775UYAC2.mjs +0 -203
- package/dist/lib/browser/operation-resolver-775UYAC2.mjs.map +0 -7
- package/dist/lib/browser/react-root-KM55OMGJ.mjs +0 -21
- package/dist/lib/browser/react-root-KM55OMGJ.mjs.map +0 -7
- package/dist/lib/browser/react-surface-BABGAWGY.mjs +0 -39
- package/dist/lib/browser/react-surface-BABGAWGY.mjs.map +0 -7
- package/dist/lib/browser/spotlight-dismiss-VSNOPETH.mjs +0 -66
- package/dist/lib/browser/spotlight-dismiss-VSNOPETH.mjs.map +0 -7
- package/dist/lib/browser/state-OUFTC2KV.mjs +0 -47
- package/dist/lib/browser/state-OUFTC2KV.mjs.map +0 -7
- package/dist/lib/browser/url-handler-DOUFQIAC.mjs +0 -54
- package/dist/lib/browser/url-handler-DOUFQIAC.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-F5TEKVJG.mjs +0 -31
- package/dist/lib/node-esm/chunk-F5TEKVJG.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HB2B3LLG.mjs +0 -790
- package/dist/lib/node-esm/chunk-HB2B3LLG.mjs.map +0 -7
- package/dist/lib/node-esm/operation-resolver-LDNYS3DI.mjs +0 -204
- package/dist/lib/node-esm/operation-resolver-LDNYS3DI.mjs.map +0 -7
- package/dist/lib/node-esm/react-root-36UYFEEB.mjs +0 -22
- package/dist/lib/node-esm/react-root-36UYFEEB.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-CGHFVWU3.mjs +0 -40
- package/dist/lib/node-esm/react-surface-CGHFVWU3.mjs.map +0 -7
- package/dist/lib/node-esm/spotlight-dismiss-L5PCWIJG.mjs +0 -68
- package/dist/lib/node-esm/spotlight-dismiss-L5PCWIJG.mjs.map +0 -7
- package/dist/lib/node-esm/state-Q2ZA26W5.mjs +0 -48
- package/dist/lib/node-esm/state-Q2ZA26W5.mjs.map +0 -7
- package/dist/lib/node-esm/url-handler-DVAZZEUO.mjs +0 -55
- package/dist/lib/node-esm/url-handler-DVAZZEUO.mjs.map +0 -7
- package/dist/types/src/capabilities/operation-resolver/index.d.ts +0 -3
- package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +0 -5
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-root/index.d.ts +0 -6
- package/dist/types/src/capabilities/react-root/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-root/react-root.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts +0 -3
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +0 -5
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +0 -1
- package/dist/types/src/capabilities/spotlight-dismiss/index.d.ts +0 -3
- package/dist/types/src/capabilities/spotlight-dismiss/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts.map +0 -1
- package/dist/types/src/capabilities/state/index.d.ts +0 -13
- package/dist/types/src/capabilities/state/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/state/state.d.ts.map +0 -1
- package/dist/types/src/capabilities/url-handler/index.d.ts +0 -3
- package/dist/types/src/capabilities/url-handler/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/url-handler/url-handler.d.ts +0 -10
- package/dist/types/src/capabilities/url-handler/url-handler.d.ts.map +0 -1
- package/dist/types/src/components/ContentError.d.ts +0 -5
- package/dist/types/src/components/ContentError.d.ts.map +0 -1
- package/dist/types/src/components/ContentLoading.d.ts +0 -3
- package/dist/types/src/components/ContentLoading.d.ts.map +0 -1
- package/dist/types/src/components/ContentLoading.stories.d.ts.map +0 -1
- package/dist/types/src/components/SimpleLayout/Banner.d.ts +0 -8
- package/dist/types/src/components/SimpleLayout/Banner.d.ts.map +0 -1
- package/dist/types/src/components/Workspace/Workspace.d.ts +0 -9
- package/dist/types/src/components/Workspace/Workspace.d.ts.map +0 -1
- package/dist/types/src/components/Workspace/index.d.ts +0 -2
- package/dist/types/src/components/Workspace/index.d.ts.map +0 -1
- package/src/capabilities/operation-resolver/index.ts +0 -10
- package/src/capabilities/operation-resolver/operation-resolver.ts +0 -215
- package/src/capabilities/react-root/index.ts +0 -7
- package/src/capabilities/react-surface/index.ts +0 -7
- package/src/capabilities/react-surface/react-surface.tsx +0 -40
- package/src/capabilities/spotlight-dismiss/index.ts +0 -7
- package/src/capabilities/state/index.ts +0 -9
- package/src/capabilities/url-handler/index.ts +0 -7
- package/src/capabilities/url-handler/url-handler.ts +0 -80
- package/src/components/ContentError.tsx +0 -23
- package/src/components/SimpleLayout/Banner.tsx +0 -113
- package/src/components/Workspace/Workspace.tsx +0 -115
|
@@ -2,25 +2,96 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
5
6
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
|
+
import React, { useMemo } from 'react';
|
|
8
|
+
import { type Mock, expect, fn, screen, userEvent, within } from 'storybook/test';
|
|
6
9
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
+
import { type ActionGraphProps, createGapSeparator, createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';
|
|
11
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
12
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
10
13
|
|
|
11
14
|
import { translations } from '../../translations';
|
|
12
|
-
|
|
13
15
|
import { NavBar } from './NavBar';
|
|
14
16
|
|
|
17
|
+
const MAIN_MENU_GROUP_ID = 'navbar-main-menu';
|
|
18
|
+
|
|
19
|
+
const buildEmptyActions = (): ActionGraphProps => ({ nodes: [], edges: [] });
|
|
20
|
+
|
|
21
|
+
const buildCompanionOnlyActions = (): ActionGraphProps => {
|
|
22
|
+
const result: ActionGraphProps = { nodes: [], edges: [] };
|
|
23
|
+
const companions = [
|
|
24
|
+
createMenuAction('companion-browse', () => console.log('Browse'), {
|
|
25
|
+
icon: 'ph--house--regular',
|
|
26
|
+
label: 'Browse',
|
|
27
|
+
iconOnly: true,
|
|
28
|
+
}),
|
|
29
|
+
createMenuAction('companion-notifications', () => console.log('Notifications'), {
|
|
30
|
+
icon: 'ph--bell--regular',
|
|
31
|
+
label: 'Notifications',
|
|
32
|
+
iconOnly: true,
|
|
33
|
+
}),
|
|
34
|
+
createMenuAction('companion-profile', () => console.log('Profile'), {
|
|
35
|
+
icon: 'ph--user--regular',
|
|
36
|
+
label: 'Profile',
|
|
37
|
+
iconOnly: true,
|
|
38
|
+
}),
|
|
39
|
+
];
|
|
40
|
+
result.nodes.push(...companions);
|
|
41
|
+
result.edges.push(...companions.map((c) => ({ source: 'root', target: c.id, relation: 'child' })));
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const buildDefaultActions = (): ActionGraphProps => {
|
|
46
|
+
const result: ActionGraphProps = { nodes: [], edges: [] };
|
|
47
|
+
const gapSeparator = createGapSeparator('navbar-gap');
|
|
48
|
+
const mainMenuGroup = createMenuItemGroup(MAIN_MENU_GROUP_ID, {
|
|
49
|
+
variant: 'dropdownMenu',
|
|
50
|
+
icon: 'ph--plus--regular',
|
|
51
|
+
iconOnly: true,
|
|
52
|
+
label: 'Main menu',
|
|
53
|
+
testId: 'simpleLayoutPlugin.addSpace',
|
|
54
|
+
});
|
|
55
|
+
const companions = [
|
|
56
|
+
createMenuAction('companion-browse', () => console.log('Browse'), {
|
|
57
|
+
icon: 'ph--house--regular',
|
|
58
|
+
label: 'Browse',
|
|
59
|
+
iconOnly: true,
|
|
60
|
+
}),
|
|
61
|
+
createMenuAction('companion-notifications', () => console.log('Notifications'), {
|
|
62
|
+
icon: 'ph--bell--regular',
|
|
63
|
+
label: 'Notifications',
|
|
64
|
+
iconOnly: true,
|
|
65
|
+
}),
|
|
66
|
+
];
|
|
67
|
+
const menuActions = [
|
|
68
|
+
createMenuAction('action-create-space', () => console.log('Create space'), {
|
|
69
|
+
icon: 'ph--planet--regular',
|
|
70
|
+
label: 'Create space',
|
|
71
|
+
}),
|
|
72
|
+
createMenuAction('action-join-space', () => console.log('Join space'), {
|
|
73
|
+
icon: 'ph--sign-in--regular',
|
|
74
|
+
label: 'Join space',
|
|
75
|
+
}),
|
|
76
|
+
createMenuAction('action-settings', () => console.log('Settings'), {
|
|
77
|
+
icon: 'ph--gear--regular',
|
|
78
|
+
label: 'Settings',
|
|
79
|
+
}),
|
|
80
|
+
];
|
|
81
|
+
result.nodes.push(...companions, ...gapSeparator.nodes, mainMenuGroup, ...menuActions);
|
|
82
|
+
result.edges.push(
|
|
83
|
+
...companions.map((c) => ({ source: 'root', target: c.id, relation: 'child' })),
|
|
84
|
+
...gapSeparator.edges,
|
|
85
|
+
{ source: 'root', target: mainMenuGroup.id, relation: 'child' },
|
|
86
|
+
...menuActions.map((action) => ({ source: MAIN_MENU_GROUP_ID, target: action.id, relation: 'child' })),
|
|
87
|
+
);
|
|
88
|
+
return result;
|
|
89
|
+
};
|
|
90
|
+
|
|
15
91
|
const meta = {
|
|
16
|
-
title: 'plugins/plugin-simple-layout/NavBar',
|
|
92
|
+
title: 'plugins/plugin-simple-layout/components/NavBar',
|
|
17
93
|
component: NavBar,
|
|
18
|
-
decorators: [
|
|
19
|
-
withTheme,
|
|
20
|
-
withPluginManager({
|
|
21
|
-
plugins: [...corePlugins()],
|
|
22
|
-
}),
|
|
23
|
-
],
|
|
94
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' }), withRegistry],
|
|
24
95
|
parameters: {
|
|
25
96
|
layout: 'fullscreen',
|
|
26
97
|
translations,
|
|
@@ -31,26 +102,62 @@ export default meta;
|
|
|
31
102
|
|
|
32
103
|
type Story = StoryObj<typeof meta>;
|
|
33
104
|
|
|
105
|
+
const DefaultStory = ({ onAction }: { onAction: (action: { id: string }) => void }) => {
|
|
106
|
+
const actions = useMemo(() => Atom.make(buildDefaultActions()).pipe(Atom.keepAlive), []);
|
|
107
|
+
|
|
108
|
+
return <NavBar classNames='border-y border-separator' actions={actions} onAction={onAction} />;
|
|
109
|
+
};
|
|
110
|
+
|
|
34
111
|
export const Default: Story = {
|
|
112
|
+
tags: ['test'],
|
|
35
113
|
args: {
|
|
36
|
-
|
|
114
|
+
onAction: fn(),
|
|
115
|
+
} as any,
|
|
116
|
+
render: (args: any) => <DefaultStory onAction={args.onAction} />,
|
|
117
|
+
play: async ({ args, canvasElement }) => {
|
|
118
|
+
const canvas = within(canvasElement);
|
|
119
|
+
|
|
120
|
+
// Verify the navbar renders with the toolbar.
|
|
121
|
+
await expect(canvas.getByRole('toolbar')).toBeInTheDocument();
|
|
122
|
+
|
|
123
|
+
// Test companion action click (Browse button).
|
|
124
|
+
const browseButton = canvas.getByRole('button', { name: /browse/i });
|
|
125
|
+
await expect(browseButton).toBeInTheDocument();
|
|
126
|
+
await userEvent.click(browseButton);
|
|
127
|
+
await expect(args.onAction).toHaveBeenCalledTimes(1);
|
|
128
|
+
await expect((args.onAction as Mock).mock.calls[0][0]).toHaveProperty('id', 'companion-browse');
|
|
129
|
+
|
|
130
|
+
// Test dropdown menu opens and action fires.
|
|
131
|
+
const menuTrigger = canvas.getByRole('button', { name: /main menu/i });
|
|
132
|
+
await expect(menuTrigger).toBeInTheDocument();
|
|
133
|
+
await userEvent.click(menuTrigger);
|
|
134
|
+
|
|
135
|
+
// Wait for menu to open and click an action (menu items render in a portal).
|
|
136
|
+
const createSpaceAction = await screen.findByRole('menuitem', { name: /create space/i });
|
|
137
|
+
await userEvent.click(createSpaceAction);
|
|
138
|
+
await expect(args.onAction).toHaveBeenCalledTimes(2);
|
|
139
|
+
await expect((args.onAction as Mock).mock.calls[1][0]).toHaveProperty('id', 'action-create-space');
|
|
37
140
|
},
|
|
38
141
|
};
|
|
39
142
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
},
|
|
143
|
+
const CompanionsOnlyStory = () => {
|
|
144
|
+
const actions = useMemo(() => Atom.make(buildCompanionOnlyActions()).pipe(Atom.keepAlive), []);
|
|
145
|
+
|
|
146
|
+
return <NavBar actions={actions} onAction={(action) => console.log('Action:', action.id)} />;
|
|
44
147
|
};
|
|
45
148
|
|
|
46
|
-
export const
|
|
47
|
-
args: {
|
|
48
|
-
|
|
49
|
-
},
|
|
149
|
+
export const CompanionsOnly: Story = {
|
|
150
|
+
args: {} as any,
|
|
151
|
+
render: () => <CompanionsOnlyStory />,
|
|
50
152
|
};
|
|
51
153
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
},
|
|
154
|
+
const EmptyStory = () => {
|
|
155
|
+
const actions = useMemo(() => Atom.make(buildEmptyActions()).pipe(Atom.keepAlive), []);
|
|
156
|
+
|
|
157
|
+
return <NavBar actions={actions} onAction={(action) => console.log('Action:', action.id)} />;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const Empty: Story = {
|
|
161
|
+
args: {} as any,
|
|
162
|
+
render: () => <EmptyStory />,
|
|
56
163
|
};
|
|
@@ -2,65 +2,32 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Atom } from '@effect-atom/atom-react';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { Node, useActionRunner, useConnections } from '@dxos/plugin-graph';
|
|
10
|
-
import { IconButton, type ThemedClassName, Toolbar, Tooltip, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
11
|
-
import { DropdownMenu, MenuProvider } from '@dxos/react-ui-menu';
|
|
12
|
-
import { mx } from '@dxos/ui-theme';
|
|
13
|
-
|
|
14
|
-
import { useCompanions } from '../../hooks';
|
|
15
|
-
import { meta } from '../../meta';
|
|
8
|
+
import { type ActionExecutor, type ActionGraphProps, Menu, useMenuActions } from '@dxos/react-ui-menu';
|
|
9
|
+
import { composable, composableProps } from '@dxos/ui-theme';
|
|
16
10
|
|
|
17
11
|
const NAVBAR_NAME = 'SimpleLayout.NavBar';
|
|
18
12
|
|
|
19
|
-
export type NavBarProps =
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const { t } = useTranslation(meta.id);
|
|
26
|
-
const { graph } = useAppGraph();
|
|
27
|
-
const runAction = useActionRunner();
|
|
28
|
-
const { invokePromise } = useOperationInvoker();
|
|
29
|
-
|
|
30
|
-
const connections = useConnections(graph, Node.RootId);
|
|
31
|
-
const menuActions = connections.filter((node) => node.properties.disposition === 'menu');
|
|
13
|
+
export type NavBarProps = {
|
|
14
|
+
/** Action graph atom for the toolbar. */
|
|
15
|
+
actions: Atom.Atom<ActionGraphProps>;
|
|
16
|
+
/** Action executor callback. */
|
|
17
|
+
onAction?: ActionExecutor;
|
|
18
|
+
};
|
|
32
19
|
|
|
33
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Presentational navbar component that renders a toolbar from an action graph.
|
|
22
|
+
*/
|
|
23
|
+
export const NavBar = composable<HTMLDivElement, NavBarProps>(({ actions, onAction, ...props }, forwardedRef) => {
|
|
24
|
+
const menuActions = useMenuActions(actions);
|
|
34
25
|
|
|
35
26
|
return (
|
|
36
|
-
<
|
|
37
|
-
{
|
|
38
|
-
|
|
39
|
-
key={companion.id}
|
|
40
|
-
icon={companion.properties.icon ?? 'ph--placeholder--regular'}
|
|
41
|
-
iconOnly
|
|
42
|
-
label={toLocalizedString(companion.properties.label, t)}
|
|
43
|
-
onClick={() => {
|
|
44
|
-
void invokePromise(Common.LayoutOperation.Open, {
|
|
45
|
-
subject: [companion.id],
|
|
46
|
-
});
|
|
47
|
-
}}
|
|
48
|
-
/>
|
|
49
|
-
))}
|
|
50
|
-
|
|
51
|
-
<Toolbar.Separator variant='gap' />
|
|
52
|
-
|
|
53
|
-
<MenuProvider onAction={runAction}>
|
|
54
|
-
<DropdownMenu.Root items={menuActions}>
|
|
55
|
-
<Tooltip.Trigger asChild content={t('app menu label')}>
|
|
56
|
-
<DropdownMenu.Trigger asChild data-testid='simpleLayoutPlugin.addSpace'>
|
|
57
|
-
<IconButton icon='ph--plus--regular' iconOnly label={t('main menu label')} />
|
|
58
|
-
</DropdownMenu.Trigger>
|
|
59
|
-
</Tooltip.Trigger>
|
|
60
|
-
</DropdownMenu.Root>
|
|
61
|
-
</MenuProvider>
|
|
62
|
-
</Toolbar.Root>
|
|
27
|
+
<Menu.Root {...menuActions} alwaysActive onAction={onAction}>
|
|
28
|
+
<Menu.Toolbar {...composableProps(props)} ref={forwardedRef} />
|
|
29
|
+
</Menu.Root>
|
|
63
30
|
);
|
|
64
|
-
};
|
|
31
|
+
});
|
|
65
32
|
|
|
66
33
|
NavBar.displayName = NAVBAR_NAME;
|
|
@@ -5,81 +5,71 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import * as Effect from 'effect/Effect';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { ActivationEvents, Capability, Plugin } from '@dxos/app-framework';
|
|
9
9
|
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
10
|
-
import {
|
|
10
|
+
import { AppActivationEvents } from '@dxos/app-toolkit';
|
|
11
|
+
import { Collection } from '@dxos/echo';
|
|
12
|
+
import { ClientPlugin } from '@dxos/plugin-client';
|
|
11
13
|
import { SearchPlugin } from '@dxos/plugin-search';
|
|
12
14
|
import { SpacePlugin } from '@dxos/plugin-space';
|
|
13
|
-
import { SpaceOperation } from '@dxos/plugin-space/types';
|
|
14
15
|
import { corePlugins } from '@dxos/plugin-testing';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
16
|
+
import { translations as searchTranslation } from '@dxos/react-ui-search';
|
|
17
|
+
import { withLayout } from '@dxos/react-ui/testing';
|
|
18
|
+
|
|
19
|
+
import { ReactRoot, ReactSurface, State } from '#capabilities';
|
|
20
|
+
import { meta as pluginMeta } from '#meta';
|
|
21
|
+
import { SimpleLayoutEvents } from '#types';
|
|
18
22
|
|
|
19
|
-
import { OperationResolver, type SimpleLayoutStateOptions, State } from '../../capabilities';
|
|
20
|
-
import { meta as pluginMeta } from '../../meta';
|
|
21
23
|
import { type SimpleLayoutPluginOptions } from '../../SimpleLayoutPlugin';
|
|
22
24
|
import { translations } from '../../translations';
|
|
23
|
-
|
|
24
25
|
import { SimpleLayout } from './SimpleLayout';
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
-
Plugin.addModule(({ isPopover = false }) => ({
|
|
28
|
-
id: Capability.getModuleTag(State),
|
|
29
|
-
activatesOn: Common.ActivationEvent.Startup,
|
|
30
|
-
activatesAfter: [Common.ActivationEvent.LayoutReady],
|
|
31
|
-
activate: () => State({ initialState: { isPopover } } satisfies SimpleLayoutStateOptions),
|
|
32
|
-
})),
|
|
33
|
-
Common.Plugin.addOperationResolverModule({ activate: OperationResolver }),
|
|
34
|
-
Plugin.addModule({
|
|
35
|
-
id: 'setup',
|
|
36
|
-
activatesOn: Common.ActivationEvent.OperationInvokerReady,
|
|
37
|
-
activate: Effect.fnUntraced(function* () {
|
|
38
|
-
const { invoke } = yield* Capability.get(Common.Capability.OperationInvoker);
|
|
39
|
-
yield* invoke(ClientOperation.CreateIdentity, {});
|
|
40
|
-
const { space: work } = yield* invoke(SpaceOperation.Create, { name: 'Work Space' });
|
|
41
|
-
const { space: sharedProject } = yield* invoke(SpaceOperation.Create, { name: 'Shared Project' });
|
|
42
|
-
|
|
43
|
-
// Add collections to Work Space.
|
|
44
|
-
yield* invoke(SpaceOperation.AddObject, {
|
|
45
|
-
target: work.db,
|
|
46
|
-
object: Collection.make({ name: 'Projects', objects: [] }),
|
|
47
|
-
});
|
|
48
|
-
yield* invoke(SpaceOperation.AddObject, {
|
|
49
|
-
target: work.db,
|
|
50
|
-
object: Collection.make({ name: 'Documents', objects: [] }),
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// Add collections to Shared Project.
|
|
54
|
-
yield* invoke(SpaceOperation.AddObject, {
|
|
55
|
-
target: sharedProject.db,
|
|
56
|
-
object: Collection.make({ name: 'Tasks', objects: [] }),
|
|
57
|
-
});
|
|
58
|
-
yield* invoke(SpaceOperation.AddObject, {
|
|
59
|
-
target: sharedProject.db,
|
|
60
|
-
object: Collection.make({ name: 'Notes', objects: [] }),
|
|
61
|
-
});
|
|
62
|
-
}),
|
|
63
|
-
}),
|
|
64
|
-
Plugin.make,
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const createPluginManager = ({ isPopover }: { isPopover: boolean }) => {
|
|
27
|
+
const createPluginManager = ({ isPopover }: { isPopover?: boolean }) => {
|
|
68
28
|
return withPluginManager({
|
|
29
|
+
setupEvents: [AppActivationEvents.SetupSettings],
|
|
69
30
|
plugins: [
|
|
70
31
|
...corePlugins(),
|
|
71
32
|
ClientPlugin({
|
|
72
33
|
types: [Collection.Collection],
|
|
34
|
+
onClientInitialized: ({ client }) =>
|
|
35
|
+
Effect.gen(function* () {
|
|
36
|
+
yield* Effect.promise(() => client.halo.createIdentity());
|
|
37
|
+
}),
|
|
73
38
|
}),
|
|
39
|
+
|
|
74
40
|
SearchPlugin(),
|
|
75
41
|
SpacePlugin({}),
|
|
76
|
-
|
|
42
|
+
|
|
43
|
+
// TODO(burdon): This should be factored ouf from SimpleLayoutPlugin.
|
|
44
|
+
Plugin.define<SimpleLayoutPluginOptions>(pluginMeta).pipe(
|
|
45
|
+
Plugin.addModule(({ isPopover = false }) => ({
|
|
46
|
+
id: Capability.getModuleTag(State),
|
|
47
|
+
activatesOn: ActivationEvents.Startup,
|
|
48
|
+
activatesAfter: [SimpleLayoutEvents.StateReady, AppActivationEvents.LayoutReady],
|
|
49
|
+
activate: () => State({ initialState: { isPopover } }),
|
|
50
|
+
})),
|
|
51
|
+
Plugin.addModule({
|
|
52
|
+
id: Capability.getModuleTag(ReactRoot),
|
|
53
|
+
activatesOn: ActivationEvents.Startup,
|
|
54
|
+
activate: ReactRoot,
|
|
55
|
+
}),
|
|
56
|
+
Plugin.addModule({
|
|
57
|
+
id: Capability.getModuleTag(ReactSurface),
|
|
58
|
+
activatesOn: ActivationEvents.Startup,
|
|
59
|
+
activate: ReactSurface,
|
|
60
|
+
}),
|
|
61
|
+
Plugin.make,
|
|
62
|
+
)({ isPopover }),
|
|
77
63
|
],
|
|
78
64
|
});
|
|
79
65
|
};
|
|
80
66
|
|
|
67
|
+
/**
|
|
68
|
+
* NOTE: To expose to iphone on network:
|
|
69
|
+
* `moon run storybook-react:serve dev -H 0.0.0.0`
|
|
70
|
+
*/
|
|
81
71
|
const meta = {
|
|
82
|
-
title: 'plugins/plugin-simple-layout/SimpleLayout',
|
|
72
|
+
title: 'plugins/plugin-simple-layout/components/SimpleLayout',
|
|
83
73
|
component: SimpleLayout,
|
|
84
74
|
parameters: {
|
|
85
75
|
layout: 'fullscreen',
|
|
@@ -91,14 +81,10 @@ export default meta;
|
|
|
91
81
|
|
|
92
82
|
type Story = StoryObj<typeof meta>;
|
|
93
83
|
|
|
94
|
-
/**
|
|
95
|
-
* NOTE: To expose to iphone on network:
|
|
96
|
-
* `moon run storybook-react:serve dev -H 0.0.0.0`
|
|
97
|
-
*/
|
|
98
84
|
export const Default: Story = {
|
|
99
|
-
decorators: [
|
|
85
|
+
decorators: [withLayout({ layout: 'column', classNames: 'relative' }), createPluginManager({})],
|
|
100
86
|
};
|
|
101
87
|
|
|
102
88
|
export const Popover: Story = {
|
|
103
|
-
decorators: [
|
|
89
|
+
decorators: [withLayout({ layout: 'column', classNames: 'relative' }), createPluginManager({ isPopover: true })],
|
|
104
90
|
};
|
|
@@ -2,39 +2,57 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, {
|
|
5
|
+
import React, { useLayoutEffect, useRef, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { Splitter, type SplitterMode } from '@dxos/react-ui';
|
|
8
8
|
import { Mosaic } from '@dxos/react-ui-mosaic';
|
|
9
9
|
|
|
10
|
-
import { useSimpleLayoutState } from '
|
|
10
|
+
import { useSimpleLayoutState } from '#hooks';
|
|
11
|
+
|
|
12
|
+
import { DebugOverlay } from '../DebugOverlay';
|
|
11
13
|
import { Dialog } from '../Dialog';
|
|
14
|
+
import { MobileLayout } from '../MobileLayout';
|
|
12
15
|
import { PopoverContent, PopoverRoot } from '../Popover';
|
|
13
|
-
|
|
14
16
|
import { Drawer } from './Drawer';
|
|
15
17
|
import { Main } from './Main';
|
|
16
18
|
|
|
17
19
|
export const SimpleLayout = () => {
|
|
18
|
-
const { state
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
const { state } = useSimpleLayoutState();
|
|
21
|
+
const [keyboardOpen, setKeyboardOpen] = useState(false);
|
|
22
|
+
const [splitterMode, setSplitterMode] = useState<SplitterMode>('top');
|
|
23
|
+
|
|
24
|
+
const drawerRef = useRef<HTMLDivElement>(null);
|
|
25
|
+
|
|
26
|
+
// Restore Splitter mode when keyboard closes.
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
if (!keyboardOpen) {
|
|
29
|
+
setSplitterMode(state.drawerState === 'closed' ? 'top' : state.drawerState === 'open' ? 'split' : 'bottom');
|
|
30
|
+
}
|
|
31
|
+
}, [state.drawerState, keyboardOpen]);
|
|
27
32
|
|
|
28
33
|
return (
|
|
29
|
-
<
|
|
30
|
-
<
|
|
31
|
-
<
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
<DebugOverlay.Root enabled={false}>
|
|
35
|
+
<PopoverRoot>
|
|
36
|
+
<Mosaic.Root>
|
|
37
|
+
<MobileLayout.Root
|
|
38
|
+
classNames='dx-container grid relative bg-toolbar-surface'
|
|
39
|
+
onKeyboardOpenChange={(nextKeyboardOpen) => setKeyboardOpen(nextKeyboardOpen)}
|
|
40
|
+
>
|
|
41
|
+
<MobileLayout.Panel safe={{ top: true, bottom: splitterMode === 'top' }}>
|
|
42
|
+
<Splitter.Root mode={splitterMode} ratio={0.55}>
|
|
43
|
+
<Splitter.Panel position='top'>
|
|
44
|
+
<Main />
|
|
45
|
+
</Splitter.Panel>
|
|
46
|
+
<Splitter.Panel position='bottom' ref={drawerRef}>
|
|
47
|
+
<Drawer />
|
|
48
|
+
</Splitter.Panel>
|
|
49
|
+
</Splitter.Root>
|
|
50
|
+
<Dialog />
|
|
51
|
+
<PopoverContent />
|
|
52
|
+
</MobileLayout.Panel>
|
|
53
|
+
</MobileLayout.Root>
|
|
54
|
+
</Mosaic.Root>
|
|
55
|
+
</PopoverRoot>
|
|
56
|
+
</DebugOverlay.Root>
|
|
39
57
|
);
|
|
40
58
|
};
|
package/src/components/hooks.ts
CHANGED
|
@@ -4,23 +4,23 @@
|
|
|
4
4
|
|
|
5
5
|
import { useEffect } from 'react';
|
|
6
6
|
|
|
7
|
-
import { useAppGraph } from '@dxos/app-
|
|
7
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
8
8
|
import { Graph } from '@dxos/plugin-graph';
|
|
9
|
+
import { expandAttendableId } from '@dxos/react-ui-attention';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* Expand graph nodes along the full path from root to the given node ID.
|
|
13
|
+
* Walks each progressive prefix, ensuring ancestor nodes are materialized
|
|
14
|
+
* before attempting to access their children.
|
|
12
15
|
*/
|
|
13
|
-
export const
|
|
16
|
+
export const useExpandPath = (nodeId?: string) => {
|
|
14
17
|
const { graph } = useAppGraph();
|
|
15
18
|
|
|
16
19
|
useEffect(() => {
|
|
17
20
|
if (nodeId) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Graph.getConnections(graph, nodeId, 'outbound').forEach((child) => {
|
|
22
|
-
Graph.expand(graph, child.id, 'outbound');
|
|
23
|
-
});
|
|
21
|
+
for (const prefix of expandAttendableId(nodeId)) {
|
|
22
|
+
Graph.expand(graph, prefix, 'child');
|
|
23
|
+
}
|
|
24
24
|
}
|
|
25
25
|
}, [nodeId, graph]);
|
|
26
26
|
};
|
package/src/components/index.ts
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './DebugOverlay';
|
|
6
6
|
export * from './Home';
|
|
7
|
+
export * from './Loading';
|
|
8
|
+
export * from './MobileLayout';
|
|
7
9
|
export * from './Popover';
|
|
8
10
|
export * from './SimpleLayout';
|
|
9
|
-
export * from './
|
|
11
|
+
export * from './NavBranch';
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Atom } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
|
|
8
|
+
import { type AppCapabilities } from '@dxos/app-toolkit';
|
|
9
|
+
import { Node } from '@dxos/plugin-graph';
|
|
10
|
+
import { getLinkedVariant } from '@dxos/react-ui-attention';
|
|
11
|
+
import { type ActionGraphProps } from '@dxos/react-ui-menu';
|
|
12
|
+
import { byPosition } from '@dxos/util';
|
|
13
|
+
|
|
14
|
+
import { type SimpleLayoutState } from '#types';
|
|
15
|
+
|
|
16
|
+
// TODO(wittjosiah): Factor out to shared location with plugin-deck.
|
|
17
|
+
export const PLANK_COMPANION_TYPE = 'org.dxos.plugin.deck.plank-companion';
|
|
18
|
+
|
|
19
|
+
export type CompanionActionsConfig = {
|
|
20
|
+
/** Prefix for companion action IDs (e.g. 'navbar' or 'drawer') */
|
|
21
|
+
idPrefix: string;
|
|
22
|
+
/** Optional: highlight companion with this variant */
|
|
23
|
+
selectedVariant?: string;
|
|
24
|
+
/** State updater for toggling the drawer. */
|
|
25
|
+
updateState: (fn: (state: SimpleLayoutState) => SimpleLayoutState) => void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates action graph nodes and edges for companion actions.
|
|
30
|
+
* Shared logic between useNavbarActions and useDrawerActions.
|
|
31
|
+
*/
|
|
32
|
+
// TODO(burdon): Use builder pattern.
|
|
33
|
+
export const createCompanionActions = (
|
|
34
|
+
graph: AppCapabilities.AppGraph['graph'],
|
|
35
|
+
stateAtom: Atom.Atom<SimpleLayoutState>,
|
|
36
|
+
get: (atom: Atom.Atom<any>) => any,
|
|
37
|
+
config: CompanionActionsConfig,
|
|
38
|
+
): Pick<ActionGraphProps, 'nodes' | 'edges'> => {
|
|
39
|
+
const { idPrefix, selectedVariant, updateState } = config;
|
|
40
|
+
|
|
41
|
+
// Derive activeId from state atom.
|
|
42
|
+
const state = get(stateAtom);
|
|
43
|
+
const activeId = state.active ?? state.workspace;
|
|
44
|
+
|
|
45
|
+
// Get companions from graph connections for activeId.
|
|
46
|
+
const activeConnections = activeId ? get(graph.connections(activeId, 'child')) : [];
|
|
47
|
+
const companions = activeConnections
|
|
48
|
+
.filter((node: Node.Node) => node.type === PLANK_COMPANION_TYPE)
|
|
49
|
+
.toSorted((a: Node.Node, b: Node.Node) => byPosition(a.properties, b.properties));
|
|
50
|
+
|
|
51
|
+
const nodes: ActionGraphProps['nodes'] = [];
|
|
52
|
+
const edges: ActionGraphProps['edges'] = [];
|
|
53
|
+
|
|
54
|
+
companions.forEach((companion: Node.Node) => {
|
|
55
|
+
const companionVariant = getLinkedVariant(companion.id);
|
|
56
|
+
const companionAction = {
|
|
57
|
+
id: `${idPrefix}-companion-${companion.id}`,
|
|
58
|
+
type: Node.ActionType,
|
|
59
|
+
properties: {
|
|
60
|
+
icon: companion.properties.icon ?? 'ph--placeholder--regular',
|
|
61
|
+
label: companion.properties.label,
|
|
62
|
+
iconOnly: true,
|
|
63
|
+
...(selectedVariant !== undefined && {
|
|
64
|
+
variant: selectedVariant === companionVariant ? 'primary' : 'ghost',
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
data: () =>
|
|
68
|
+
Effect.sync(() =>
|
|
69
|
+
updateState((current) => {
|
|
70
|
+
const closing = current.companionVariant === companionVariant && current.drawerState !== 'closed';
|
|
71
|
+
return {
|
|
72
|
+
...current,
|
|
73
|
+
companionVariant: closing ? undefined : companionVariant,
|
|
74
|
+
drawerState: closing ? 'closed' : 'open',
|
|
75
|
+
};
|
|
76
|
+
}),
|
|
77
|
+
),
|
|
78
|
+
};
|
|
79
|
+
nodes.push(companionAction);
|
|
80
|
+
edges.push({ source: 'root', target: companionAction.id, relation: 'child' });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return { nodes, edges };
|
|
84
|
+
};
|
package/src/hooks/index.ts
CHANGED