@dxos/plugin-simple-layout 0.8.4-main.9735255 → 0.8.4-main.c351d160a8
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/chunk-2YSUM2L4.mjs +1153 -0
- package/dist/lib/browser/chunk-2YSUM2L4.mjs.map +7 -0
- package/dist/lib/browser/{chunk-P77G4YTR.mjs → chunk-MRR7PXSM.mjs} +5 -5
- package/dist/lib/browser/chunk-MRR7PXSM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +20 -19
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{operation-resolver-775UYAC2.mjs → operation-resolver-LV5FK6MN.mjs} +39 -47
- package/dist/lib/browser/operation-resolver-LV5FK6MN.mjs.map +7 -0
- package/dist/lib/browser/{react-root-KM55OMGJ.mjs → react-root-JR6OENXV.mjs} +5 -5
- package/dist/lib/browser/react-root-JR6OENXV.mjs.map +7 -0
- package/dist/lib/browser/{react-surface-BABGAWGY.mjs → react-surface-5JOPIP5Z.mjs} +18 -13
- package/dist/lib/browser/react-surface-5JOPIP5Z.mjs.map +7 -0
- package/dist/lib/browser/{spotlight-dismiss-VSNOPETH.mjs → spotlight-dismiss-67PHYS5B.mjs} +3 -3
- package/dist/lib/browser/spotlight-dismiss-67PHYS5B.mjs.map +7 -0
- package/dist/lib/browser/{state-OUFTC2KV.mjs → state-TXSMUWYI.mjs} +5 -4
- package/dist/lib/browser/state-TXSMUWYI.mjs.map +7 -0
- package/dist/lib/browser/url-handler-RBRONH7S.mjs +151 -0
- package/dist/lib/browser/url-handler-RBRONH7S.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-RCQE6FR2.mjs +1154 -0
- package/dist/lib/node-esm/chunk-RCQE6FR2.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-F5TEKVJG.mjs → chunk-WMNTJ2MK.mjs} +5 -5
- package/dist/lib/node-esm/chunk-WMNTJ2MK.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +20 -19
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{operation-resolver-LDNYS3DI.mjs → operation-resolver-FD3EF2LX.mjs} +39 -47
- package/dist/lib/node-esm/operation-resolver-FD3EF2LX.mjs.map +7 -0
- package/dist/lib/node-esm/{react-root-36UYFEEB.mjs → react-root-CRTCNH3F.mjs} +5 -5
- package/dist/lib/node-esm/react-root-CRTCNH3F.mjs.map +7 -0
- package/dist/lib/node-esm/{react-surface-CGHFVWU3.mjs → react-surface-NRTDSGFB.mjs} +18 -13
- package/dist/lib/node-esm/react-surface-NRTDSGFB.mjs.map +7 -0
- package/dist/lib/node-esm/{spotlight-dismiss-L5PCWIJG.mjs → spotlight-dismiss-RMLRZUVY.mjs} +3 -3
- package/dist/lib/node-esm/spotlight-dismiss-RMLRZUVY.mjs.map +7 -0
- package/dist/lib/node-esm/{state-Q2ZA26W5.mjs → state-JMX6FAG4.mjs} +5 -4
- package/dist/lib/node-esm/state-JMX6FAG4.mjs.map +7 -0
- package/dist/lib/node-esm/url-handler-QSMCH3JB.mjs +152 -0
- package/dist/lib/node-esm/url-handler-QSMCH3JB.mjs.map +7 -0
- package/dist/types/src/SimpleLayoutPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +2 -2
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-root/react-root.d.ts +1 -1
- package/dist/types/src/capabilities/react-root/react-root.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +2 -2
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/spotlight-dismiss/index.d.ts +1 -1
- package/dist/types/src/capabilities/spotlight-dismiss/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts +1 -1
- package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts.map +1 -1
- package/dist/types/src/capabilities/state/index.d.ts +1 -1
- package/dist/types/src/capabilities/state/state.d.ts +1 -1
- package/dist/types/src/capabilities/state/state.d.ts.map +1 -1
- package/dist/types/src/capabilities/url-handler/url-handler.d.ts +5 -3
- package/dist/types/src/capabilities/url-handler/url-handler.d.ts.map +1 -1
- package/dist/types/src/components/ContentError.stories.d.ts +1 -3
- package/dist/types/src/components/ContentError.stories.d.ts.map +1 -1
- package/dist/types/src/components/ContentLoading/ContentLoading.d.ts.map +1 -0
- package/dist/types/src/components/ContentLoading/ContentLoading.stories.d.ts.map +1 -0
- package/dist/types/src/components/ContentLoading/index.d.ts +2 -0
- package/dist/types/src/components/ContentLoading/index.d.ts.map +1 -0
- package/dist/types/src/components/Home/Home.d.ts.map +1 -1
- 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 +26 -0
- package/dist/types/src/components/SimpleLayout/AppBar.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts +47 -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 +10 -3
- package/dist/types/src/components/SimpleLayout/NavBar.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts +4 -4
- 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.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 +2 -1
- 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/types/capabilities.d.ts +7 -6
- 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 +36 -30
- package/src/SimpleLayoutPlugin.ts +10 -9
- package/src/capabilities/operation-resolver/operation-resolver.ts +34 -46
- package/src/capabilities/react-root/react-root.tsx +2 -2
- package/src/capabilities/react-surface/react-surface.tsx +14 -11
- package/src/capabilities/spotlight-dismiss/spotlight-dismiss.ts +2 -2
- package/src/capabilities/state/state.tsx +4 -3
- package/src/capabilities/url-handler/url-handler.ts +98 -45
- package/src/components/ContentError.stories.tsx +8 -7
- package/src/components/{ContentLoading.stories.tsx → ContentLoading/ContentLoading.stories.tsx} +2 -2
- package/src/components/{ContentLoading.tsx → ContentLoading/ContentLoading.tsx} +1 -1
- package/src/components/ContentLoading/index.ts +5 -0
- package/src/components/Dialog/Dialog.tsx +5 -5
- package/src/components/Home/Home.tsx +44 -36
- package/src/components/MobileLayout/MobileLayout.stories.tsx +129 -0
- package/src/components/MobileLayout/MobileLayout.tsx +305 -0
- package/src/components/MobileLayout/index.ts +5 -0
- package/src/components/NavBranch/NavBranch.tsx +133 -0
- package/src/components/{Workspace → NavBranch}/index.ts +1 -1
- package/src/components/Popover/Popover.tsx +7 -7
- package/src/components/SimpleLayout/AppBar.stories.tsx +144 -0
- package/src/components/SimpleLayout/AppBar.tsx +94 -0
- package/src/components/SimpleLayout/Drawer.tsx +25 -80
- package/src/components/SimpleLayout/Main.tsx +40 -30
- package/src/components/SimpleLayout/NavBar.stories.tsx +131 -23
- package/src/components/SimpleLayout/NavBar.tsx +15 -48
- package/src/components/SimpleLayout/SimpleLayout.stories.tsx +20 -11
- package/src/components/SimpleLayout/SimpleLayout.tsx +38 -19
- package/src/components/SimpleLayout/index.ts +3 -0
- package/src/components/hooks.ts +9 -9
- package/src/components/index.ts +2 -1
- package/src/hooks/actions.ts +83 -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/types/capabilities.ts +11 -7
- 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.map +0 -7
- package/dist/lib/browser/operation-resolver-775UYAC2.mjs.map +0 -7
- package/dist/lib/browser/react-root-KM55OMGJ.mjs.map +0 -7
- package/dist/lib/browser/react-surface-BABGAWGY.mjs.map +0 -7
- package/dist/lib/browser/spotlight-dismiss-VSNOPETH.mjs.map +0 -7
- 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.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.map +0 -7
- package/dist/lib/node-esm/react-root-36UYFEEB.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-CGHFVWU3.mjs.map +0 -7
- package/dist/lib/node-esm/spotlight-dismiss-L5PCWIJG.mjs.map +0 -7
- 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/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.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/components/ContentError.tsx +0 -23
- package/src/components/SimpleLayout/Banner.tsx +0 -113
- package/src/components/Workspace/Workspace.tsx +0 -115
- /package/dist/types/src/components/{ContentLoading.d.ts → ContentLoading/ContentLoading.d.ts} +0 -0
- /package/dist/types/src/components/{ContentLoading.stories.d.ts → ContentLoading/ContentLoading.stories.d.ts} +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useOperationInvoker } from '@dxos/app-framework/ui';
|
|
8
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
9
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
10
|
+
import { type Node, useConnections } from '@dxos/plugin-graph';
|
|
11
|
+
import { Avatar, Icon, Panel, ScrollArea, Toolbar, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
12
|
+
import { Card } from '@dxos/react-ui';
|
|
13
|
+
import { Mosaic, type MosaicStackTileComponent } from '@dxos/react-ui-mosaic';
|
|
14
|
+
import { SearchList, useSearchListItem, useSearchListResults } from '@dxos/react-ui-searchlist';
|
|
15
|
+
import { mx } from '@dxos/ui-theme';
|
|
16
|
+
|
|
17
|
+
import { meta } from '../../meta';
|
|
18
|
+
import { useExpandPath } from '../hooks';
|
|
19
|
+
|
|
20
|
+
export type NavBranchProps = {
|
|
21
|
+
id: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Renders the children of a graph branch node as a searchable mosaic list.
|
|
26
|
+
* Used for any node with `role: 'branch'` or a workspace disposition, including
|
|
27
|
+
* spaces, collection sections, type sections, and schema nodes.
|
|
28
|
+
*/
|
|
29
|
+
export const NavBranch = ({ id }: NavBranchProps) => {
|
|
30
|
+
const { t } = useTranslation(meta.id);
|
|
31
|
+
const { graph } = useAppGraph();
|
|
32
|
+
|
|
33
|
+
useExpandPath(id);
|
|
34
|
+
|
|
35
|
+
const children = useConnections(graph, id, 'child');
|
|
36
|
+
|
|
37
|
+
// TODO(wittjosiah): Move alternate-tree nodes to a non-child relation so they don't need filtering.
|
|
38
|
+
const visibleChildren = useMemo(
|
|
39
|
+
() =>
|
|
40
|
+
children.filter(
|
|
41
|
+
(node) => node.properties.disposition !== 'alternate-tree' && node.properties.disposition !== 'hidden',
|
|
42
|
+
),
|
|
43
|
+
[children],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const { results, handleSearch } = useSearchListResults({
|
|
47
|
+
items: visibleChildren,
|
|
48
|
+
extract: (child) => toLocalizedString(child.properties.label, t),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<SearchList.Root onSearch={handleSearch}>
|
|
53
|
+
<Panel.Root>
|
|
54
|
+
<Panel.Toolbar asChild>
|
|
55
|
+
<Toolbar.Root>
|
|
56
|
+
{/* TODO(wittjosiah): Search should be pluggable. Must support searching via ECHO query inside a space. */}
|
|
57
|
+
<SearchList.Input placeholder={t('search placeholder')} autoFocus />
|
|
58
|
+
</Toolbar.Root>
|
|
59
|
+
</Panel.Toolbar>
|
|
60
|
+
<Panel.Content asChild>
|
|
61
|
+
<SearchList.Content>
|
|
62
|
+
<Mosaic.Container asChild>
|
|
63
|
+
<ScrollArea.Root orientation='vertical'>
|
|
64
|
+
<ScrollArea.Viewport classNames='p-2'>
|
|
65
|
+
<Mosaic.Stack items={results} getId={(child) => child.id} Tile={NavBranchTile} />
|
|
66
|
+
</ScrollArea.Viewport>
|
|
67
|
+
</ScrollArea.Root>
|
|
68
|
+
</Mosaic.Container>
|
|
69
|
+
</SearchList.Content>
|
|
70
|
+
</Panel.Content>
|
|
71
|
+
</Panel.Root>
|
|
72
|
+
</SearchList.Root>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const NavBranchTile: MosaicStackTileComponent<Node.Node> = (props) => {
|
|
77
|
+
const data = props.data;
|
|
78
|
+
const { t } = useTranslation(meta.id);
|
|
79
|
+
const { invokeSync } = useOperationInvoker();
|
|
80
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
81
|
+
const { selectedValue, registerItem, unregisterItem } = useSearchListItem();
|
|
82
|
+
const isSelected = selectedValue === data.id;
|
|
83
|
+
|
|
84
|
+
const name = toLocalizedString(data.properties.label, t);
|
|
85
|
+
|
|
86
|
+
const handleSelect = useCallback(
|
|
87
|
+
() => invokeSync(LayoutOperation.Open, { subject: [data.id] }),
|
|
88
|
+
[invokeSync, data.id],
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
// Register this item with the search context.
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (ref.current) {
|
|
94
|
+
registerItem(data.id, ref.current, handleSelect);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return () => unregisterItem(data.id);
|
|
98
|
+
}, [data.id, handleSelect, registerItem, unregisterItem]);
|
|
99
|
+
|
|
100
|
+
// Scroll into view when selected.
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (isSelected && ref.current) {
|
|
103
|
+
ref.current.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
|
104
|
+
}
|
|
105
|
+
}, [isSelected]);
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<Card.Root
|
|
109
|
+
ref={ref}
|
|
110
|
+
role='button'
|
|
111
|
+
fullWidth
|
|
112
|
+
tabIndex={-1} // TODO(burdon): Use Mosaic.Focus.
|
|
113
|
+
data-selected={isSelected}
|
|
114
|
+
classNames={mx('dx-focus-ring', isSelected && 'bg-hover-overlay')}
|
|
115
|
+
onClick={handleSelect}
|
|
116
|
+
>
|
|
117
|
+
<Card.Toolbar density='coarse'>
|
|
118
|
+
<Avatar.Root>
|
|
119
|
+
<Avatar.Content
|
|
120
|
+
hue={data.properties.hue}
|
|
121
|
+
icon={data.properties.icon}
|
|
122
|
+
hueVariant='transparent'
|
|
123
|
+
variant='square'
|
|
124
|
+
size={8}
|
|
125
|
+
fallback={name}
|
|
126
|
+
/>
|
|
127
|
+
<Avatar.Label>{name}</Avatar.Label>
|
|
128
|
+
<Icon icon='ph--caret-right--regular' />
|
|
129
|
+
</Avatar.Root>
|
|
130
|
+
</Card.Toolbar>
|
|
131
|
+
</Card.Root>
|
|
132
|
+
);
|
|
133
|
+
};
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
import { createContext } from '@radix-ui/react-context';
|
|
6
6
|
import React, { type PropsWithChildren, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import { Surface } from '@dxos/app-framework/
|
|
8
|
+
import { Surface } from '@dxos/app-framework/ui';
|
|
9
|
+
|
|
9
10
|
import { Popover, type PopoverContentInteractOutsideEvent, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
10
|
-
import { Card } from '@dxos/react-ui
|
|
11
|
+
import { Card } from '@dxos/react-ui';
|
|
11
12
|
|
|
12
13
|
import { useSimpleLayoutState } from '../../hooks';
|
|
13
14
|
import { meta } from '../../meta';
|
|
@@ -57,7 +58,6 @@ export const PopoverContent = () => {
|
|
|
57
58
|
const { t } = useTranslation(meta.id);
|
|
58
59
|
const { state, updateState } = useSimpleLayoutState();
|
|
59
60
|
const { setOpen } = useLayoutPopoverContext('PopoverContent');
|
|
60
|
-
|
|
61
61
|
const handleClose = useCallback(() => {
|
|
62
62
|
setOpen(false);
|
|
63
63
|
updateState((s) => ({
|
|
@@ -100,18 +100,18 @@ export const PopoverContent = () => {
|
|
|
100
100
|
onEscapeKeyDown={handleInteractOutside}
|
|
101
101
|
>
|
|
102
102
|
<Popover.Viewport>
|
|
103
|
+
{state.popoverKind === 'base' && <Surface.Surface role='popover' data={state.popoverContent} limit={1} />}
|
|
103
104
|
{state.popoverKind === 'card' && (
|
|
104
|
-
<Card.Root>
|
|
105
|
+
<Card.Root border={false} classNames='dx-card-popover'>
|
|
105
106
|
<Card.Toolbar>
|
|
106
107
|
{/* TODO(wittjosiah): Cleaner way to handle no drag handle in toolbar? */}
|
|
107
108
|
<span />
|
|
108
109
|
{state.popoverTitle ? <Card.Title>{toLocalizedString(state.popoverTitle, t)}</Card.Title> : <span />}
|
|
109
|
-
<Card.
|
|
110
|
+
<Card.CloseIconButton onClick={handleClose} />
|
|
110
111
|
</Card.Toolbar>
|
|
111
|
-
<Surface role='card--content' data={state.popoverContent} limit={1} />
|
|
112
|
+
<Surface.Surface role='card--content' data={state.popoverContent} limit={1} />
|
|
112
113
|
</Card.Root>
|
|
113
114
|
)}
|
|
114
|
-
{state.popoverKind === 'base' && <Surface role='popover' data={state.popoverContent} limit={1} />}
|
|
115
115
|
</Popover.Viewport>
|
|
116
116
|
<Popover.Arrow />
|
|
117
117
|
</Popover.Content>
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
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';
|
|
9
|
+
|
|
10
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
11
|
+
import { type ActionGraphProps, createMenuAction } from '@dxos/react-ui-menu';
|
|
12
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
13
|
+
|
|
14
|
+
import { translations } from '../../translations';
|
|
15
|
+
import { MobileLayout } from '../MobileLayout';
|
|
16
|
+
|
|
17
|
+
import { AppBar, type AppBarProps } from './AppBar';
|
|
18
|
+
|
|
19
|
+
const buildEmptyActions = (): ActionGraphProps => ({ nodes: [], edges: [] });
|
|
20
|
+
|
|
21
|
+
const buildDefaultActions = (): ActionGraphProps => {
|
|
22
|
+
const result: ActionGraphProps = { nodes: [], edges: [] };
|
|
23
|
+
const actions = [
|
|
24
|
+
createMenuAction('action-edit', () => console.log('Edit'), {
|
|
25
|
+
icon: 'ph--pencil--regular',
|
|
26
|
+
label: 'Edit',
|
|
27
|
+
}),
|
|
28
|
+
createMenuAction('action-share', () => console.log('Share'), {
|
|
29
|
+
icon: 'ph--share--regular',
|
|
30
|
+
label: 'Share',
|
|
31
|
+
}),
|
|
32
|
+
createMenuAction('action-delete', () => console.log('Delete'), {
|
|
33
|
+
icon: 'ph--trash--regular',
|
|
34
|
+
label: 'Delete',
|
|
35
|
+
}),
|
|
36
|
+
];
|
|
37
|
+
result.nodes.push(...actions);
|
|
38
|
+
result.edges.push(...actions.map((a) => ({ source: 'root', target: a.id, relation: 'child' })));
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type StoryProps = Omit<AppBarProps, 'actions'> & {
|
|
43
|
+
actions: ActionGraphProps;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const DefaultStory = ({ actions: actionsProp, ...props }: StoryProps) => {
|
|
47
|
+
const actions = useMemo(() => Atom.make(actionsProp).pipe(Atom.keepAlive), [actionsProp]);
|
|
48
|
+
return (
|
|
49
|
+
<MobileLayout.Root>
|
|
50
|
+
<AppBar {...props} actions={actions} />
|
|
51
|
+
</MobileLayout.Root>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const meta = {
|
|
56
|
+
title: 'plugins/plugin-simple-layout/components/AppBar',
|
|
57
|
+
render: DefaultStory,
|
|
58
|
+
decorators: [
|
|
59
|
+
withTheme(),
|
|
60
|
+
withLayout({
|
|
61
|
+
layout: 'column',
|
|
62
|
+
classNames: 'relative',
|
|
63
|
+
}),
|
|
64
|
+
withRegistry,
|
|
65
|
+
],
|
|
66
|
+
parameters: {
|
|
67
|
+
layout: 'fullscreen',
|
|
68
|
+
translations,
|
|
69
|
+
},
|
|
70
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
71
|
+
|
|
72
|
+
export default meta;
|
|
73
|
+
|
|
74
|
+
type Story = StoryObj<StoryProps>;
|
|
75
|
+
|
|
76
|
+
export const Default: Story = {
|
|
77
|
+
tags: ['test'],
|
|
78
|
+
args: {
|
|
79
|
+
actions: buildDefaultActions(),
|
|
80
|
+
title: 'Document Title',
|
|
81
|
+
showBackButton: true,
|
|
82
|
+
onAction: fn(),
|
|
83
|
+
onBack: fn(),
|
|
84
|
+
},
|
|
85
|
+
play: async ({ args, canvasElement }) => {
|
|
86
|
+
const canvas = within(canvasElement);
|
|
87
|
+
|
|
88
|
+
// Verify the banner renders with the correct title.
|
|
89
|
+
await expect(canvas.getByRole('banner')).toBeInTheDocument();
|
|
90
|
+
await expect(canvas.getByText('Document Title')).toBeInTheDocument();
|
|
91
|
+
|
|
92
|
+
// Test back button click.
|
|
93
|
+
const backButton = canvas.getByRole('button', { name: /back/i });
|
|
94
|
+
await expect(backButton).toBeInTheDocument();
|
|
95
|
+
await userEvent.click(backButton);
|
|
96
|
+
await expect(args.onBack).toHaveBeenCalledTimes(1);
|
|
97
|
+
|
|
98
|
+
// Test actions menu opens and action fires.
|
|
99
|
+
const menuTrigger = canvas.getByRole('button', { name: /actions/i });
|
|
100
|
+
await expect(menuTrigger).toBeInTheDocument();
|
|
101
|
+
await userEvent.click(menuTrigger);
|
|
102
|
+
|
|
103
|
+
// Wait for menu to open and click an action (menu items render in a portal).
|
|
104
|
+
const editAction = await screen.findByRole('menuitem', { name: /edit/i });
|
|
105
|
+
await userEvent.click(editAction);
|
|
106
|
+
await expect(args.onAction).toHaveBeenCalledTimes(1);
|
|
107
|
+
await expect((args.onAction as Mock).mock.calls[0][0]).toHaveProperty('id', 'action-edit');
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const NoBackButton: Story = {
|
|
112
|
+
args: {
|
|
113
|
+
actions: buildDefaultActions(),
|
|
114
|
+
title: 'Home',
|
|
115
|
+
showBackButton: false,
|
|
116
|
+
onAction: (action) => console.log('Action:', action.id),
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const LongTitle: Story = {
|
|
121
|
+
args: {
|
|
122
|
+
actions: buildDefaultActions(),
|
|
123
|
+
title: 'This is a very long document title that should be truncated when it exceeds the available space',
|
|
124
|
+
showBackButton: true,
|
|
125
|
+
onBack: () => console.log('Back clicked'),
|
|
126
|
+
onAction: (action) => console.log('Action:', action.id),
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const NoActions: Story = {
|
|
131
|
+
args: {
|
|
132
|
+
actions: buildEmptyActions(),
|
|
133
|
+
title: 'Empty Document',
|
|
134
|
+
showBackButton: true,
|
|
135
|
+
onBack: () => console.log('Back clicked'),
|
|
136
|
+
onAction: (action) => console.log('Action:', action.id),
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const Empty: Story = {
|
|
141
|
+
args: {
|
|
142
|
+
actions: buildEmptyActions(),
|
|
143
|
+
},
|
|
144
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Atom, useAtomValue } from '@effect-atom/atom-react';
|
|
6
|
+
import React, { Fragment } from 'react';
|
|
7
|
+
|
|
8
|
+
import { IconButton, Popover, type ThemedClassName, Toolbar, useTranslation } from '@dxos/react-ui';
|
|
9
|
+
import { type ActionExecutor, type ActionGraphProps, Menu, useMenuActions } from '@dxos/react-ui-menu';
|
|
10
|
+
import { mx, osTranslations } from '@dxos/ui-theme';
|
|
11
|
+
|
|
12
|
+
import { meta } from '../../meta';
|
|
13
|
+
import { useMobileLayout } from '../MobileLayout';
|
|
14
|
+
|
|
15
|
+
const APP_BAR_NAME = 'SimpleLayout.AppBar';
|
|
16
|
+
|
|
17
|
+
export type AppBarProps = ThemedClassName<{
|
|
18
|
+
/** Title/label to display in the banner. */
|
|
19
|
+
title?: string;
|
|
20
|
+
/** Action graph atom for the dropdown menu. */
|
|
21
|
+
actions: Atom.Atom<ActionGraphProps>;
|
|
22
|
+
/** Whether to show the back button. */
|
|
23
|
+
showBackButton?: boolean;
|
|
24
|
+
/** Popover anchor ID for the dropdown trigger. */
|
|
25
|
+
popoverAnchorId?: string;
|
|
26
|
+
/** Action executor callback. */
|
|
27
|
+
onAction?: ActionExecutor;
|
|
28
|
+
/** Callback when back button is clicked. */
|
|
29
|
+
onBack?: () => void;
|
|
30
|
+
}>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* AppBar component that renders a title, optional back button, and actions dropdown.
|
|
34
|
+
*/
|
|
35
|
+
export const AppBar = ({
|
|
36
|
+
classNames,
|
|
37
|
+
title,
|
|
38
|
+
actions,
|
|
39
|
+
showBackButton,
|
|
40
|
+
popoverAnchorId,
|
|
41
|
+
onAction,
|
|
42
|
+
onBack,
|
|
43
|
+
}: AppBarProps) => {
|
|
44
|
+
const { t } = useTranslation(meta.id);
|
|
45
|
+
const menu = useMenuActions(actions);
|
|
46
|
+
const actionsValue = useAtomValue(actions);
|
|
47
|
+
const hasActions = actionsValue.nodes.length > 0;
|
|
48
|
+
const { keyboardOpen } = useMobileLayout(APP_BAR_NAME);
|
|
49
|
+
|
|
50
|
+
// Fall back to app name if no title provided.
|
|
51
|
+
const displayTitle = title ?? t('current app name', { ns: osTranslations });
|
|
52
|
+
|
|
53
|
+
// Wrap the menu trigger with Popover.Anchor when the popoverAnchorId is set.
|
|
54
|
+
const AnchorRoot = popoverAnchorId ? Popover.Anchor : Fragment;
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Toolbar.Root
|
|
58
|
+
role='banner'
|
|
59
|
+
classNames={mx(
|
|
60
|
+
'grid grid-cols-[var(--dx-rail-size)_1fr_var(--dx-rail-size)] items-center',
|
|
61
|
+
'dx-density-fine',
|
|
62
|
+
classNames,
|
|
63
|
+
)}
|
|
64
|
+
>
|
|
65
|
+
{keyboardOpen ? (
|
|
66
|
+
<IconButton variant='ghost' icon='ph--x--regular' iconOnly label={t('done label')} />
|
|
67
|
+
) : showBackButton ? (
|
|
68
|
+
<IconButton variant='ghost' icon='ph--caret-left--regular' iconOnly label={t('back label')} onClick={onBack} />
|
|
69
|
+
) : (
|
|
70
|
+
<div />
|
|
71
|
+
)}
|
|
72
|
+
<h1 className='text-center truncate font-thin uppercase'>{displayTitle}</h1>
|
|
73
|
+
{hasActions ? (
|
|
74
|
+
<AnchorRoot>
|
|
75
|
+
<Menu.Root {...menu} caller={meta.id} onAction={onAction}>
|
|
76
|
+
<Menu.Trigger asChild>
|
|
77
|
+
<IconButton
|
|
78
|
+
variant='ghost'
|
|
79
|
+
icon='ph--dots-three-vertical--regular'
|
|
80
|
+
iconOnly
|
|
81
|
+
label={t('actions menu label')}
|
|
82
|
+
/>
|
|
83
|
+
</Menu.Trigger>
|
|
84
|
+
<Menu.Content />
|
|
85
|
+
</Menu.Root>
|
|
86
|
+
</AnchorRoot>
|
|
87
|
+
) : (
|
|
88
|
+
<span />
|
|
89
|
+
)}
|
|
90
|
+
</Toolbar.Root>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
AppBar.displayName = APP_BAR_NAME;
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, {
|
|
5
|
+
import React, { useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import { Surface
|
|
7
|
+
import { Surface } from '@dxos/app-framework/ui';
|
|
8
|
+
import { getCompanionVariant } from '@dxos/app-toolkit';
|
|
9
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
8
10
|
import { type Node, useNode } from '@dxos/plugin-graph';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
+
import { ErrorFallback, Panel } from '@dxos/react-ui';
|
|
12
|
+
import { Menu, useMenuActions } from '@dxos/react-ui-menu';
|
|
11
13
|
|
|
12
|
-
import { useCompanions, useSimpleLayoutState } from '../../hooks';
|
|
13
|
-
import { meta } from '../../meta';
|
|
14
|
-
import { ContentError } from '../ContentError';
|
|
14
|
+
import { useCompanions, useDrawerActions, useSimpleLayoutState } from '../../hooks';
|
|
15
15
|
import { ContentLoading } from '../ContentLoading';
|
|
16
16
|
|
|
17
17
|
const DRAWER_NAME = 'SimpleLayout.Drawer';
|
|
@@ -20,16 +20,15 @@ const DRAWER_NAME = 'SimpleLayout.Drawer';
|
|
|
20
20
|
* Companion drawer component.
|
|
21
21
|
*/
|
|
22
22
|
export const Drawer = () => {
|
|
23
|
-
const { t } = useTranslation(meta.id);
|
|
24
|
-
const { state, updateState } = useSimpleLayoutState();
|
|
25
23
|
const { graph } = useAppGraph();
|
|
24
|
+
const { state: layoutState } = useSimpleLayoutState();
|
|
26
25
|
|
|
27
26
|
const placeholder = useMemo(() => <ContentLoading />, []);
|
|
28
27
|
|
|
29
28
|
// Get all companions for the current active (primary) item.
|
|
30
|
-
const activeId =
|
|
29
|
+
const activeId = layoutState.active ?? layoutState.workspace;
|
|
31
30
|
const companions = useCompanions(activeId);
|
|
32
|
-
const { companionId, variant } = useSelectedCompanion(companions,
|
|
31
|
+
const { companionId, variant } = useSelectedCompanion(companions, layoutState.companionVariant);
|
|
33
32
|
|
|
34
33
|
// Get node for the selected companion.
|
|
35
34
|
const node = useNode(graph, companionId);
|
|
@@ -48,77 +47,26 @@ export const Drawer = () => {
|
|
|
48
47
|
);
|
|
49
48
|
}, [companionId, node, parentNode, variant]);
|
|
50
49
|
|
|
51
|
-
//
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const [, companionVariant] = companion.id.split(ATTENDABLE_PATH_SEPARATOR);
|
|
55
|
-
updateState((s) => ({ ...s, companionVariant }));
|
|
56
|
-
},
|
|
57
|
-
[updateState],
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
// Handle expand/collapse toggle.
|
|
61
|
-
const handleToggleExpand = useCallback(() => {
|
|
62
|
-
updateState((s) => ({
|
|
63
|
-
...s,
|
|
64
|
-
drawerState: s.drawerState === 'full' ? 'expanded' : 'full',
|
|
65
|
-
}));
|
|
66
|
-
}, [updateState]);
|
|
67
|
-
|
|
68
|
-
// Handle close.
|
|
69
|
-
const handleClose = useCallback(() => {
|
|
70
|
-
updateState((s) => ({ ...s, drawerState: 'closed' }));
|
|
71
|
-
}, [updateState]);
|
|
72
|
-
|
|
73
|
-
const drawerState = state.drawerState ?? 'closed';
|
|
74
|
-
if (drawerState === 'closed') {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const isFullyExpanded = drawerState === 'full';
|
|
50
|
+
// Get drawer actions (tabs + toolbar buttons).
|
|
51
|
+
const { actions, onAction } = useDrawerActions(DRAWER_NAME);
|
|
52
|
+
const menu = useMenuActions(actions);
|
|
79
53
|
|
|
80
54
|
return (
|
|
81
|
-
<
|
|
82
|
-
<Toolbar
|
|
83
|
-
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
icon={companion.properties.icon}
|
|
92
|
-
iconOnly
|
|
93
|
-
label={toLocalizedString(companion.properties.label, t)}
|
|
94
|
-
variant={companionId === companion.id ? 'primary' : 'ghost'}
|
|
95
|
-
onClick={() => handleTabClick(companion)}
|
|
96
|
-
/>
|
|
97
|
-
))}
|
|
98
|
-
</div>
|
|
99
|
-
<Toolbar.Separator variant='gap' />
|
|
100
|
-
<Toolbar.IconButton
|
|
101
|
-
icon={isFullyExpanded ? 'ph--arrow-down--regular' : 'ph--arrow-up--regular'}
|
|
102
|
-
iconOnly
|
|
103
|
-
label={isFullyExpanded ? t('collapse drawer label') : t('expand drawer label')}
|
|
104
|
-
onClick={handleToggleExpand}
|
|
105
|
-
/>
|
|
106
|
-
<Toolbar.IconButton icon='ph--x--regular' iconOnly label={t('close drawer label')} onClick={handleClose} />
|
|
107
|
-
</Toolbar.Root>
|
|
108
|
-
{/* TODO(burdon): Fix containment. */}
|
|
109
|
-
<Surface role='article' data={data} limit={1} fallback={ContentError} placeholder={placeholder} />
|
|
110
|
-
</NaturalMain.Drawer>
|
|
55
|
+
<Panel.Root>
|
|
56
|
+
<Panel.Toolbar>
|
|
57
|
+
<Menu.Root {...menu} alwaysActive onAction={onAction}>
|
|
58
|
+
<Menu.Toolbar />
|
|
59
|
+
</Menu.Root>
|
|
60
|
+
</Panel.Toolbar>
|
|
61
|
+
<Panel.Content asChild>
|
|
62
|
+
<Surface.Surface role='article' data={data} limit={1} fallback={ErrorFallback} placeholder={placeholder} />
|
|
63
|
+
</Panel.Content>
|
|
64
|
+
</Panel.Root>
|
|
111
65
|
);
|
|
112
66
|
};
|
|
113
67
|
|
|
114
68
|
Drawer.displayName = DRAWER_NAME;
|
|
115
69
|
|
|
116
|
-
/** Parse entry ID to extract primary ID and variant. */
|
|
117
|
-
const parseEntryId = (entryId: string) => {
|
|
118
|
-
const [id, variant] = entryId.split(ATTENDABLE_PATH_SEPARATOR);
|
|
119
|
-
return { id, variant };
|
|
120
|
-
};
|
|
121
|
-
|
|
122
70
|
/**
|
|
123
71
|
* Resolves which companion to show based on variant preference.
|
|
124
72
|
* Falls back to first available if preferred variant not available.
|
|
@@ -131,10 +79,7 @@ const useSelectedCompanion = (companions: Node.Node[], preferredVariant?: string
|
|
|
131
79
|
|
|
132
80
|
// Try to find companion matching the preferred variant.
|
|
133
81
|
if (preferredVariant) {
|
|
134
|
-
const preferred = companions.find((c) =>
|
|
135
|
-
const { variant } = parseEntryId(c.id);
|
|
136
|
-
return variant === preferredVariant;
|
|
137
|
-
});
|
|
82
|
+
const preferred = companions.find((c) => getCompanionVariant(c.id) === preferredVariant);
|
|
138
83
|
if (preferred) {
|
|
139
84
|
return preferred;
|
|
140
85
|
}
|
|
@@ -145,7 +90,7 @@ const useSelectedCompanion = (companions: Node.Node[], preferredVariant?: string
|
|
|
145
90
|
}, [companions, preferredVariant]);
|
|
146
91
|
|
|
147
92
|
const companionId = selectedCompanion?.id;
|
|
148
|
-
const
|
|
93
|
+
const variant = companionId ? getCompanionVariant(companionId) : undefined;
|
|
149
94
|
|
|
150
95
|
return { selectedCompanion, companionId, variant };
|
|
151
96
|
};
|