@dxos/plugin-navtree 0.7.5-labs.a279d8c → 0.7.5-labs.c0e040f
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/{app-graph-builder-OF4MMBLH.mjs → app-graph-builder-BL7LRXCM.mjs} +7 -5
- package/dist/lib/browser/{app-graph-builder-OF4MMBLH.mjs.map → app-graph-builder-BL7LRXCM.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-OI7AAA6Q.mjs → chunk-AOAGODQB.mjs} +1 -1
- package/dist/lib/browser/chunk-AOAGODQB.mjs.map +7 -0
- package/dist/lib/browser/chunk-SKZPY4LJ.mjs +1120 -0
- package/dist/lib/browser/chunk-SKZPY4LJ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +21 -26
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-U25VBFH3.mjs +47 -0
- package/dist/lib/browser/intent-resolver-U25VBFH3.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-OZDS36WN.mjs +57 -0
- package/dist/lib/browser/react-surface-OZDS36WN.mjs.map +7 -0
- package/dist/lib/browser/{state-HT65TAYL.mjs → state-IEFQTUPG.mjs} +7 -10
- package/dist/lib/browser/state-IEFQTUPG.mjs.map +7 -0
- package/dist/types/src/NavTreePlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +22 -22
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/capabilities.d.ts +3 -2
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +88 -32
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/state.d.ts +3 -3
- package/dist/types/src/capabilities/state.d.ts.map +1 -1
- package/dist/types/src/components/CommandsDialog.d.ts.map +1 -1
- package/dist/types/src/components/CommandsTrigger.d.ts.map +1 -1
- package/dist/types/src/components/L0Menu.d.ts +9 -0
- package/dist/types/src/components/L0Menu.d.ts.map +1 -0
- package/dist/types/src/components/L1Panels.d.ts +8 -0
- package/dist/types/src/components/L1Panels.d.ts.map +1 -0
- package/dist/types/src/components/NavTree.d.ts +3 -20
- package/dist/types/src/components/NavTree.d.ts.map +1 -1
- package/dist/types/src/components/NavTree.stories.d.ts +2 -2
- package/dist/types/src/components/NavTree.stories.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeContainer.d.ts +4 -3
- package/dist/types/src/components/NavTreeContainer.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeContext.d.ts +4 -0
- package/dist/types/src/components/NavTreeContext.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeItemAction.d.ts +1 -1
- package/dist/types/src/components/NavTreeItemAction.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeItemColumns.d.ts +4 -0
- package/dist/types/src/components/NavTreeItemColumns.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/types.d.ts +25 -0
- package/dist/types/src/components/types.d.ts.map +1 -0
- package/dist/types/src/hooks.d.ts +3 -0
- package/dist/types/src/hooks.d.ts.map +1 -0
- package/dist/types/src/stories/Graph.stories.d.ts +2 -2
- package/dist/types/src/stories/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/stories/StorybookNavTree.d.ts +4 -0
- package/dist/types/src/stories/StorybookNavTree.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +0 -6
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +2 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +9 -0
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -31
- package/src/NavTreePlugin.tsx +8 -10
- package/src/capabilities/app-graph-builder.ts +6 -4
- package/src/capabilities/capabilities.ts +3 -2
- package/src/capabilities/intent-resolver.ts +22 -16
- package/src/capabilities/react-surface.tsx +15 -41
- package/src/capabilities/state.ts +6 -9
- package/src/components/CommandsDialog.tsx +3 -4
- package/src/components/CommandsTrigger.tsx +7 -5
- package/src/components/L0Menu.tsx +218 -0
- package/src/components/L1Panels.tsx +100 -0
- package/src/components/NavTree.stories.tsx +6 -6
- package/src/components/NavTree.tsx +26 -116
- package/src/components/NavTreeContainer.tsx +106 -32
- package/src/components/NavTreeContext.tsx +13 -0
- package/src/components/NavTreeItemAction.tsx +12 -4
- package/src/components/NavTreeItemColumns.tsx +71 -0
- package/src/components/NotchStart.tsx +2 -2
- package/src/components/index.ts +2 -0
- package/src/components/types.ts +33 -0
- package/src/hooks.ts +21 -0
- package/src/stories/Graph.stories.tsx +6 -5
- package/src/stories/StorybookNavTree.tsx +63 -0
- package/src/translations.ts +0 -6
- package/src/types.ts +2 -1
- package/src/util.ts +56 -2
- package/dist/lib/browser/chunk-IMGT2LAL.mjs +0 -658
- package/dist/lib/browser/chunk-IMGT2LAL.mjs.map +0 -7
- package/dist/lib/browser/chunk-OI7AAA6Q.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-74JPWYBP.mjs +0 -42
- package/dist/lib/browser/intent-resolver-74JPWYBP.mjs.map +0 -7
- package/dist/lib/browser/react-surface-6QWXI53A.mjs +0 -189
- package/dist/lib/browser/react-surface-6QWXI53A.mjs.map +0 -7
- package/dist/lib/browser/state-HT65TAYL.mjs.map +0 -7
- package/dist/types/src/components/NavTreeFooter.d.ts +0 -6
- package/dist/types/src/components/NavTreeFooter.d.ts.map +0 -1
- package/src/components/NavTreeFooter.tsx +0 -161
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { type MouseEvent, useCallback, useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { createIntent, LayoutAction, useIntentDispatcher } from '@dxos/app-framework';
|
|
8
|
+
import { type Node } from '@dxos/app-graph';
|
|
9
|
+
import { Icon, toLocalizedString, Tooltip, useMediaQuery, useSidebars, useTranslation } from '@dxos/react-ui';
|
|
10
|
+
import { Tabs } from '@dxos/react-ui-tabs';
|
|
11
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
12
|
+
|
|
13
|
+
import { useNavTreeContext } from './NavTreeContext';
|
|
14
|
+
import { NotchStart } from './NotchStart';
|
|
15
|
+
import { useLoadDescendents } from '../hooks';
|
|
16
|
+
import { NAVTREE_PLUGIN } from '../meta';
|
|
17
|
+
import { getFirstTwoRenderableChars, l0ItemType } from '../util';
|
|
18
|
+
|
|
19
|
+
type L0ItemProps = {
|
|
20
|
+
item: Node<any>;
|
|
21
|
+
parent?: Node<any>;
|
|
22
|
+
path: string[];
|
|
23
|
+
pinned?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const useL0ItemClick = ({ item, parent, path }: L0ItemProps, type: string) => {
|
|
27
|
+
const { tab, onTabChange, onSelect, isCurrent } = useNavTreeContext();
|
|
28
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
29
|
+
const { navigationSidebarState } = useSidebars(NAVTREE_PLUGIN);
|
|
30
|
+
const [isLg] = useMediaQuery('lg', { ssr: false });
|
|
31
|
+
|
|
32
|
+
return useCallback(
|
|
33
|
+
(event: MouseEvent) => {
|
|
34
|
+
switch (type) {
|
|
35
|
+
case 'tab':
|
|
36
|
+
// TODO(thure): This dispatch should rightly be in `onTabChange`, but that callback wasn’t reacting to changes
|
|
37
|
+
// to its dependencies.
|
|
38
|
+
void dispatch(
|
|
39
|
+
createIntent(LayoutAction.UpdateSidebar, {
|
|
40
|
+
part: 'sidebar',
|
|
41
|
+
options: {
|
|
42
|
+
state:
|
|
43
|
+
item.id === tab
|
|
44
|
+
? navigationSidebarState === 'expanded'
|
|
45
|
+
? isLg
|
|
46
|
+
? 'collapsed'
|
|
47
|
+
: 'closed'
|
|
48
|
+
: 'expanded'
|
|
49
|
+
: 'expanded',
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
return onTabChange?.(item);
|
|
54
|
+
case 'link':
|
|
55
|
+
return onSelect?.({ item, path, current: !isCurrent(path, item), option: event.altKey });
|
|
56
|
+
case 'action': {
|
|
57
|
+
const {
|
|
58
|
+
data: invoke,
|
|
59
|
+
properties: { caller },
|
|
60
|
+
} = item;
|
|
61
|
+
return invoke?.(caller ? { node: parent, caller } : { node: parent });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
[item, type, onSelect, isCurrent, parent, tab, navigationSidebarState, isLg, dispatch],
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const l0Breakpoints: Record<string, string> = {
|
|
70
|
+
lg: 'hidden lg:grid',
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const L0Item = ({ item, parent, path, pinned }: L0ItemProps) => {
|
|
74
|
+
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
75
|
+
const type = l0ItemType(item);
|
|
76
|
+
const itemPath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
77
|
+
const { getProps } = useNavTreeContext();
|
|
78
|
+
const { id, testId } = getProps?.(item, path) ?? {};
|
|
79
|
+
const Root = type === 'collection' ? 'h2' : type === 'tab' ? Tabs.TabPrimitive : 'button';
|
|
80
|
+
const handleClick = useL0ItemClick({ item, path: itemPath, parent }, type);
|
|
81
|
+
const rootProps =
|
|
82
|
+
type === 'tab'
|
|
83
|
+
? { value: item.id, tabIndex: 0, onClick: handleClick, 'data-testid': testId, 'data-itemid': id }
|
|
84
|
+
: type !== 'collection'
|
|
85
|
+
? { onClick: handleClick, 'data-testid': testId, 'data-itemid': id }
|
|
86
|
+
: { onClick: handleClick };
|
|
87
|
+
const localizedString = toLocalizedString(item.properties.label, t);
|
|
88
|
+
const hue = item.properties.hue ?? null;
|
|
89
|
+
const avatarValue = useMemo(
|
|
90
|
+
() => (type === 'tab' ? getFirstTwoRenderableChars(localizedString).join('') : []),
|
|
91
|
+
[type, item.properties.label, t],
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<Tooltip.Root delayDuration={0}>
|
|
96
|
+
<Tooltip.Trigger asChild>
|
|
97
|
+
<Root
|
|
98
|
+
{...(rootProps as any)}
|
|
99
|
+
data-type={type}
|
|
100
|
+
className={mx(
|
|
101
|
+
'group/l0i dx-focus-ring-group grid overflow-hidden relative data[type!="collection"]:cursor-pointer app-no-drag',
|
|
102
|
+
l0Breakpoints[item.properties.l0Breakpoint],
|
|
103
|
+
)}
|
|
104
|
+
>
|
|
105
|
+
{type !== 'collection' && (
|
|
106
|
+
<div
|
|
107
|
+
role='none'
|
|
108
|
+
className={mx(
|
|
109
|
+
'absolute -z-[1] dx-focus-ring-group-indicator transition-colors',
|
|
110
|
+
type === 'tab' || pinned ? 'rounded' : 'rounded-full',
|
|
111
|
+
pinned
|
|
112
|
+
? 'bg-transparent group-hover/l0i:bg-groupSurface inset-inline-3 inset-block-0.5'
|
|
113
|
+
: 'bg-groupSurface inset-inline-3 inset-block-2',
|
|
114
|
+
)}
|
|
115
|
+
{...(hue && { style: { background: `var(--dx-${hue}Surface)` } })}
|
|
116
|
+
/>
|
|
117
|
+
)}
|
|
118
|
+
<div
|
|
119
|
+
role='none'
|
|
120
|
+
className='hidden group-aria-selected/l0i:block absolute inline-start-0 inset-block-4 is-1 bg-accentSurface rounded-ie'
|
|
121
|
+
/>
|
|
122
|
+
{type === 'tab' && item.properties.disposition !== 'pin-end' ? (
|
|
123
|
+
<span
|
|
124
|
+
role='img'
|
|
125
|
+
className='place-self-center text-3xl font-light'
|
|
126
|
+
{...(hue && { style: { color: `var(--dx-${hue}SurfaceText)` } })}
|
|
127
|
+
>
|
|
128
|
+
{avatarValue}
|
|
129
|
+
</span>
|
|
130
|
+
) : (
|
|
131
|
+
item.properties.icon && (
|
|
132
|
+
<Icon icon={item.properties.icon} size={pinned ? 5 : 7} classNames='place-self-center' />
|
|
133
|
+
)
|
|
134
|
+
)}
|
|
135
|
+
<span id={`${item.id}__label`} className='sr-only'>
|
|
136
|
+
{localizedString}
|
|
137
|
+
</span>
|
|
138
|
+
</Root>
|
|
139
|
+
</Tooltip.Trigger>
|
|
140
|
+
<Tooltip.Portal>
|
|
141
|
+
<Tooltip.Content side='right'>
|
|
142
|
+
{localizedString}
|
|
143
|
+
<Tooltip.Arrow />
|
|
144
|
+
</Tooltip.Content>
|
|
145
|
+
</Tooltip.Portal>
|
|
146
|
+
</Tooltip.Root>
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const L0Collection = ({ item, path, parent }: L0ItemProps) => {
|
|
151
|
+
const navTreeContext = useNavTreeContext();
|
|
152
|
+
useLoadDescendents(item);
|
|
153
|
+
const collectionItems = navTreeContext.getItems(item);
|
|
154
|
+
const groupPath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
155
|
+
const { id, testId } = navTreeContext.getProps?.(item, path) ?? {};
|
|
156
|
+
return (
|
|
157
|
+
<div
|
|
158
|
+
role='group'
|
|
159
|
+
className='contents group/l0c'
|
|
160
|
+
aria-labelledby={`${item.id}__label`}
|
|
161
|
+
data-itemid={id}
|
|
162
|
+
data-testid={testId}
|
|
163
|
+
>
|
|
164
|
+
{/* TODO(burdon): Option. */}
|
|
165
|
+
{/* <L0Item item={item} parent={parent} path={groupPath} /> */}
|
|
166
|
+
{collectionItems.map((collectionItem) => (
|
|
167
|
+
<L0Item key={collectionItem.id} item={collectionItem} parent={item} path={groupPath} />
|
|
168
|
+
))}
|
|
169
|
+
</div>
|
|
170
|
+
);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export const L0Menu = ({
|
|
174
|
+
topLevelItems,
|
|
175
|
+
pinnedItems,
|
|
176
|
+
parent,
|
|
177
|
+
path,
|
|
178
|
+
}: {
|
|
179
|
+
topLevelItems: Node<any>[];
|
|
180
|
+
pinnedItems: Node<any>[];
|
|
181
|
+
parent?: Node<any>;
|
|
182
|
+
path: string[];
|
|
183
|
+
}) => {
|
|
184
|
+
return (
|
|
185
|
+
<Tabs.Tablist classNames='group/l0 absolute z-[1] inset-block-0 inline-start-0 rounded-is-lg grid grid-cols-[var(--l0-size)] grid-rows-[1fr_min-content_var(--l0-size)] contain-layout !is-[--l0-size] bg-baseSurface border-ie border-separator app-drag'>
|
|
186
|
+
<div
|
|
187
|
+
role='none'
|
|
188
|
+
className='grid auto-rows-[calc(var(--l0-size)-.5rem)] min-bs-0 !overflow-y-auto plb-1 [body[data-platform="darwin"]_&]:pbs-[calc(30px+0.25rem)]'
|
|
189
|
+
>
|
|
190
|
+
{topLevelItems.map((item) => {
|
|
191
|
+
if (l0ItemType(item) === 'collection') {
|
|
192
|
+
return <L0Collection key={item.id} item={item} parent={parent} path={path} />;
|
|
193
|
+
} else {
|
|
194
|
+
return <L0Item key={item.id} item={item} parent={parent} path={path} />;
|
|
195
|
+
}
|
|
196
|
+
})}
|
|
197
|
+
</div>
|
|
198
|
+
<div role='none' className='grid grid-cols-1 auto-rows-[--rail-action] pbs-2'>
|
|
199
|
+
{pinnedItems
|
|
200
|
+
.filter((item) => l0ItemType(item) !== 'collection')
|
|
201
|
+
.map((item) => (
|
|
202
|
+
<L0Item key={item.id} item={item} parent={parent} path={path} pinned />
|
|
203
|
+
))}
|
|
204
|
+
</div>
|
|
205
|
+
<div role='none' className='grid p-2 app-no-drag'>
|
|
206
|
+
<NotchStart />
|
|
207
|
+
</div>
|
|
208
|
+
<div
|
|
209
|
+
role='none'
|
|
210
|
+
className='hidden [body[data-platform="darwin"]_&]:block absolute block-start-0 is-[calc(var(--l0-size)-1px)] bs-[calc(40px+0.25rem)]'
|
|
211
|
+
style={{
|
|
212
|
+
background:
|
|
213
|
+
'linear-gradient(to bottom, var(--dx-baseSurface) 0%, var(--dx-baseSurface) 70%, transparent 100%)',
|
|
214
|
+
}}
|
|
215
|
+
/>
|
|
216
|
+
</Tabs.Tablist>
|
|
217
|
+
);
|
|
218
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useLayout } from '@dxos/app-framework';
|
|
8
|
+
import { type Node } from '@dxos/app-graph';
|
|
9
|
+
import { toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
10
|
+
import { Tree } from '@dxos/react-ui-list';
|
|
11
|
+
import { Tabs } from '@dxos/react-ui-tabs';
|
|
12
|
+
|
|
13
|
+
import { useNavTreeContext } from './NavTreeContext';
|
|
14
|
+
import { NavTreeItemColumns } from './NavTreeItemColumns';
|
|
15
|
+
import { useLoadDescendents } from '../hooks';
|
|
16
|
+
import { NAVTREE_PLUGIN } from '../meta';
|
|
17
|
+
import { l0ItemType } from '../util';
|
|
18
|
+
|
|
19
|
+
type L1PanelProps = { item: Node<any>; path: string[]; currentItemId: string };
|
|
20
|
+
|
|
21
|
+
const L1Panel = ({ item, path, currentItemId }: L1PanelProps) => {
|
|
22
|
+
const layout = useLayout();
|
|
23
|
+
const navTreeContext = useNavTreeContext();
|
|
24
|
+
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
25
|
+
return (
|
|
26
|
+
<Tabs.Tabpanel
|
|
27
|
+
key={item.id}
|
|
28
|
+
value={item.id}
|
|
29
|
+
classNames={[
|
|
30
|
+
'absolute inset-block-0 inline-end-0 is-[calc(100%-var(--l0-size))] lg:is-[--l1-size] grid-cols-1 grid-rows-[var(--rail-size)_1fr]',
|
|
31
|
+
item.id === currentItemId && 'grid',
|
|
32
|
+
]}
|
|
33
|
+
tabIndex={-1}
|
|
34
|
+
{...(!layout.sidebarOpen && { inert: 'true' })}
|
|
35
|
+
>
|
|
36
|
+
{item.id === currentItemId && (
|
|
37
|
+
<>
|
|
38
|
+
<h2 className='flex items-center border-be border-separator pis-4 app-drag'>
|
|
39
|
+
<span className='flex-1 truncate cursor-default'>{toLocalizedString(item.properties.label, t)}</span>
|
|
40
|
+
<NavTreeItemColumns path={path} item={item} open />
|
|
41
|
+
</h2>
|
|
42
|
+
<div role='none' className='overflow-y-auto'>
|
|
43
|
+
<Tree
|
|
44
|
+
{...navTreeContext}
|
|
45
|
+
id={item.id}
|
|
46
|
+
root={item}
|
|
47
|
+
path={path}
|
|
48
|
+
levelOffset={5}
|
|
49
|
+
draggable
|
|
50
|
+
gridTemplateColumns='[tree-row-start] 1fr min-content min-content min-content [tree-row-end]'
|
|
51
|
+
renderColumns={NavTreeItemColumns}
|
|
52
|
+
/>
|
|
53
|
+
</div>
|
|
54
|
+
</>
|
|
55
|
+
)}
|
|
56
|
+
</Tabs.Tabpanel>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const L1PanelCollection = ({ item, path, currentItemId }: L1PanelProps) => {
|
|
61
|
+
const { getItems } = useNavTreeContext();
|
|
62
|
+
useLoadDescendents(item);
|
|
63
|
+
const collectionItems = getItems(item);
|
|
64
|
+
const groupPath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
{collectionItems
|
|
68
|
+
.filter((item) => l0ItemType(item) === 'tab')
|
|
69
|
+
.map((item) => (
|
|
70
|
+
<L1Panel key={item.id} item={item} path={groupPath} currentItemId={currentItemId} />
|
|
71
|
+
))}
|
|
72
|
+
</>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const L1Panels = ({
|
|
77
|
+
topLevelItems,
|
|
78
|
+
path,
|
|
79
|
+
currentItemId,
|
|
80
|
+
}: {
|
|
81
|
+
topLevelItems: Node<any>[];
|
|
82
|
+
path: string[];
|
|
83
|
+
currentItemId: string;
|
|
84
|
+
}) => {
|
|
85
|
+
return (
|
|
86
|
+
<>
|
|
87
|
+
{topLevelItems.map((item) => {
|
|
88
|
+
const type = l0ItemType(item);
|
|
89
|
+
switch (type) {
|
|
90
|
+
case 'collection':
|
|
91
|
+
return <L1PanelCollection key={item.id} item={item} path={path} currentItemId={currentItemId} />;
|
|
92
|
+
case 'tab':
|
|
93
|
+
return <L1Panel key={item.id} item={item} path={path} currentItemId={currentItemId} />;
|
|
94
|
+
default:
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
})}
|
|
98
|
+
</>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
@@ -13,10 +13,10 @@ import { isActionLike, type NodeArg } from '@dxos/app-graph';
|
|
|
13
13
|
import { create, type ReactiveObject } from '@dxos/live-object';
|
|
14
14
|
import { faker } from '@dxos/random';
|
|
15
15
|
import { isTreeData, type TreeData } from '@dxos/react-ui-list';
|
|
16
|
-
import { Path } from '@dxos/react-ui-
|
|
16
|
+
import { Path } from '@dxos/react-ui-list';
|
|
17
17
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import { StorybookNavTree } from '../stories/StorybookNavTree';
|
|
20
20
|
import { createTree, updateState } from '../testing';
|
|
21
21
|
|
|
22
22
|
faker.seed(1234);
|
|
@@ -24,9 +24,9 @@ faker.seed(1234);
|
|
|
24
24
|
const tree = create<NodeArg<any>>(createTree());
|
|
25
25
|
const state = new Map<string, ReactiveObject<{ open: boolean; current: boolean }>>();
|
|
26
26
|
|
|
27
|
-
const meta: Meta<typeof
|
|
27
|
+
const meta: Meta<typeof StorybookNavTree> = {
|
|
28
28
|
title: 'plugins/plugin-navtree/NavTree',
|
|
29
|
-
component:
|
|
29
|
+
component: StorybookNavTree,
|
|
30
30
|
decorators: [withTheme, withLayout({ tooltips: true })],
|
|
31
31
|
render: (args) => {
|
|
32
32
|
useEffect(() => {
|
|
@@ -52,7 +52,7 @@ const meta: Meta<typeof NavTree> = {
|
|
|
52
52
|
});
|
|
53
53
|
}, []);
|
|
54
54
|
|
|
55
|
-
return <
|
|
55
|
+
return <StorybookNavTree {...args} />;
|
|
56
56
|
},
|
|
57
57
|
args: {
|
|
58
58
|
id: tree.id,
|
|
@@ -60,7 +60,7 @@ const meta: Meta<typeof NavTree> = {
|
|
|
60
60
|
actions: arg.nodes?.filter((node) => isActionLike(node)) ?? [],
|
|
61
61
|
groupedActions: {},
|
|
62
62
|
}),
|
|
63
|
-
getItems: (testItem?:
|
|
63
|
+
getItems: (testItem?: any) => {
|
|
64
64
|
return testItem?.nodes ?? tree.nodes ?? [];
|
|
65
65
|
},
|
|
66
66
|
getProps: (testItem: NodeArg<any>) => ({
|
|
@@ -2,130 +2,40 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, {
|
|
5
|
+
import React, { useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { Tree, type TreeProps } from '@dxos/react-ui-list';
|
|
10
|
-
import { type MaybePromise } from '@dxos/util';
|
|
7
|
+
import { Tabs } from '@dxos/react-ui-tabs';
|
|
8
|
+
import { byPosition } from '@dxos/util';
|
|
11
9
|
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
10
|
+
import { L0Menu } from './L0Menu';
|
|
11
|
+
import { L1Panels } from './L1Panels';
|
|
12
|
+
import { useNavTreeContext } from './NavTreeContext';
|
|
13
|
+
import { type NavTreeProps } from './types';
|
|
14
|
+
import { useLoadDescendents } from '../hooks';
|
|
15
15
|
|
|
16
16
|
export const NAV_TREE_ITEM = 'NavTreeItem';
|
|
17
17
|
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<NavTreeColumns
|
|
29
|
-
path={path}
|
|
30
|
-
node={item}
|
|
31
|
-
getActions={getActions}
|
|
32
|
-
open={open}
|
|
33
|
-
loadDescendents={loadDescendents}
|
|
34
|
-
renderItemEnd={renderItemEnd}
|
|
35
|
-
popoverAnchorId={popoverAnchorId}
|
|
36
|
-
/>
|
|
37
|
-
);
|
|
38
|
-
},
|
|
39
|
-
[renderItemEnd, popoverAnchorId, loadDescendents],
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<Tree
|
|
44
|
-
{...props}
|
|
45
|
-
draggable
|
|
46
|
-
gridTemplateColumns='[tree-row-start] 1fr min-content min-content min-content [tree-row-end]'
|
|
47
|
-
renderColumns={renderColumns}
|
|
48
|
-
/>
|
|
18
|
+
export const NavTree = ({ id, root }: NavTreeProps) => {
|
|
19
|
+
const { getItems, tab } = useNavTreeContext();
|
|
20
|
+
const topLevelActions = getItems(root, 'item');
|
|
21
|
+
const topLevelCollections = getItems(root, 'collection');
|
|
22
|
+
const topLevelWorkspaces = getItems(root, 'workspace');
|
|
23
|
+
const topLevelNavigation = getItems(root, 'navigation');
|
|
24
|
+
const l0Items = useMemo(
|
|
25
|
+
() => [...topLevelActions, ...topLevelCollections, ...topLevelWorkspaces, ...topLevelNavigation],
|
|
26
|
+
[topLevelActions, topLevelCollections, topLevelWorkspaces, topLevelNavigation],
|
|
49
27
|
);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
type NavTreeColumnsProps = {
|
|
53
|
-
path: string[];
|
|
54
|
-
node: Node;
|
|
55
|
-
getActions: (node: Node) => FlattenedActions;
|
|
56
|
-
open: boolean;
|
|
57
|
-
loadDescendents?: (node: Node) => MaybePromise<void>;
|
|
58
|
-
renderItemEnd?: FC<{ node: Node; open: boolean }>;
|
|
59
|
-
popoverAnchorId?: string;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const NavTreeColumns = ({
|
|
63
|
-
path,
|
|
64
|
-
node,
|
|
65
|
-
getActions,
|
|
66
|
-
open,
|
|
67
|
-
loadDescendents,
|
|
68
|
-
renderItemEnd: ItemEnd,
|
|
69
|
-
popoverAnchorId,
|
|
70
|
-
}: NavTreeColumnsProps) => {
|
|
71
|
-
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
72
|
-
|
|
73
|
-
const level = path.length - 2;
|
|
74
|
-
|
|
75
|
-
const { actions: _actions, groupedActions } = getActions(node);
|
|
76
|
-
const [primaryAction, ...secondaryActions] = _actions.toSorted((a, b) =>
|
|
77
|
-
a.properties?.disposition === 'toolbar' ? -1 : 1,
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
const actions = (primaryAction?.properties?.disposition === 'toolbar' ? secondaryActions : _actions)
|
|
81
|
-
.flatMap((action) => (isAction(action) ? [action] : []))
|
|
82
|
-
.filter((action) => !action.properties?.hidden);
|
|
83
|
-
|
|
84
|
-
const ActionRoot = popoverAnchorId === `dxos.org/ui/${NAV_TREE_ITEM}/${node.id}` ? Popover.Anchor : Fragment;
|
|
28
|
+
const pinnedItems = getItems(root, 'pin-end').toSorted((a, b) => byPosition(a.properties, b.properties));
|
|
29
|
+
const topLevelItems = useMemo(() => [...l0Items, ...pinnedItems], [l0Items, pinnedItems]);
|
|
85
30
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const frame = requestAnimationFrame(() => {
|
|
89
|
-
void loadDescendents?.(node);
|
|
90
|
-
if (primaryAction && !isAction(primaryAction)) {
|
|
91
|
-
void loadDescendents?.(primaryAction);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
return () => cancelAnimationFrame(frame);
|
|
95
|
-
}, [primaryAction]);
|
|
31
|
+
useLoadDescendents(root);
|
|
32
|
+
const path = useMemo(() => [id], [id]);
|
|
96
33
|
|
|
97
34
|
return (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
icon={primaryAction.properties?.icon ?? 'ph--placeholder--regular'}
|
|
104
|
-
parent={node}
|
|
105
|
-
monolithic={isAction(primaryAction)}
|
|
106
|
-
menuActions={isAction(primaryAction) ? [primaryAction] : groupedActions[primaryAction.id]}
|
|
107
|
-
menuType={primaryAction.properties?.menuType}
|
|
108
|
-
caller={NAV_TREE_ITEM}
|
|
109
|
-
/>
|
|
110
|
-
) : (
|
|
111
|
-
<Treegrid.Cell />
|
|
112
|
-
)}
|
|
113
|
-
<ActionRoot>
|
|
114
|
-
{actions.length > 0 ? (
|
|
115
|
-
<NavTreeItemAction
|
|
116
|
-
testId={`navtree.treeItem.actionsLevel${level}`}
|
|
117
|
-
label={t('tree item actions label')}
|
|
118
|
-
icon='ph--dots-three-vertical--regular'
|
|
119
|
-
parent={node}
|
|
120
|
-
menuActions={actions}
|
|
121
|
-
menuType='dropdown'
|
|
122
|
-
caller={NAV_TREE_ITEM}
|
|
123
|
-
/>
|
|
124
|
-
) : (
|
|
125
|
-
<Treegrid.Cell />
|
|
126
|
-
)}
|
|
127
|
-
</ActionRoot>
|
|
128
|
-
{ItemEnd && <ItemEnd node={node} open={open} />}
|
|
129
|
-
</>
|
|
35
|
+
// NOTE(thure): 74px (rather than rem) is intentional in order to match the size of macOS windowing controls
|
|
36
|
+
<Tabs.Root value={tab} orientation='vertical' verticalVariant='stateless' classNames='relative'>
|
|
37
|
+
<L0Menu topLevelItems={l0Items} pinnedItems={pinnedItems} path={path} parent={root} />
|
|
38
|
+
<L1Panels topLevelItems={topLevelItems} path={path} currentItemId={tab} />
|
|
39
|
+
</Tabs.Root>
|
|
130
40
|
);
|
|
131
41
|
};
|