@dxos/plugin-navtree 0.7.5-labs.e27f9b9 → 0.7.5-main.2567c87
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-BL7LRXCM.mjs → app-graph-builder-OF4MMBLH.mjs} +5 -7
- package/dist/lib/browser/{app-graph-builder-BL7LRXCM.mjs.map → app-graph-builder-OF4MMBLH.mjs.map} +3 -3
- package/dist/lib/browser/chunk-IMGT2LAL.mjs +658 -0
- package/dist/lib/browser/chunk-IMGT2LAL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-AOAGODQB.mjs → chunk-OI7AAA6Q.mjs} +1 -1
- package/dist/lib/browser/chunk-OI7AAA6Q.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +26 -21
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-74JPWYBP.mjs +42 -0
- package/dist/lib/browser/intent-resolver-74JPWYBP.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-6QWXI53A.mjs +189 -0
- package/dist/lib/browser/react-surface-6QWXI53A.mjs.map +7 -0
- package/dist/lib/browser/{state-65TQKYX7.mjs → state-HT65TAYL.mjs} +9 -6
- package/dist/lib/browser/state-HT65TAYL.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 +2 -3
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +32 -88
- 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/NavTree.d.ts +20 -3
- 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 +3 -4
- package/dist/types/src/components/NavTreeContainer.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeFooter.d.ts +6 -0
- package/dist/types/src/components/NavTreeFooter.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/index.d.ts +0 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- 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/translations.d.ts +6 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +1 -2
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +0 -9
- package/dist/types/src/util.d.ts.map +1 -1
- package/package.json +31 -33
- package/src/NavTreePlugin.tsx +10 -8
- package/src/capabilities/app-graph-builder.ts +4 -6
- package/src/capabilities/capabilities.ts +2 -3
- package/src/capabilities/intent-resolver.ts +16 -22
- package/src/capabilities/react-surface.tsx +41 -15
- package/src/capabilities/state.ts +8 -5
- package/src/components/CommandsDialog.tsx +4 -3
- package/src/components/CommandsTrigger.tsx +5 -7
- package/src/components/NavTree.stories.tsx +5 -5
- package/src/components/NavTree.tsx +116 -26
- package/src/components/NavTreeContainer.tsx +32 -106
- package/src/components/NavTreeFooter.tsx +161 -0
- package/src/components/NavTreeItemAction.tsx +4 -12
- package/src/components/NotchStart.tsx +2 -2
- package/src/components/index.ts +0 -2
- package/src/stories/Graph.stories.tsx +4 -5
- package/src/translations.ts +6 -0
- package/src/types.ts +1 -2
- package/src/util.ts +0 -54
- package/dist/lib/browser/chunk-54MPRXMH.mjs +0 -1109
- package/dist/lib/browser/chunk-54MPRXMH.mjs.map +0 -7
- package/dist/lib/browser/chunk-AOAGODQB.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-U25VBFH3.mjs +0 -47
- package/dist/lib/browser/intent-resolver-U25VBFH3.mjs.map +0 -7
- package/dist/lib/browser/react-surface-LNRTNSM6.mjs +0 -57
- package/dist/lib/browser/react-surface-LNRTNSM6.mjs.map +0 -7
- package/dist/lib/browser/state-65TQKYX7.mjs.map +0 -7
- package/dist/types/src/components/L0Menu.d.ts +0 -9
- package/dist/types/src/components/L0Menu.d.ts.map +0 -1
- package/dist/types/src/components/L1Panels.d.ts +0 -8
- package/dist/types/src/components/L1Panels.d.ts.map +0 -1
- package/dist/types/src/components/NavTreeContext.d.ts +0 -4
- package/dist/types/src/components/NavTreeContext.d.ts.map +0 -1
- package/dist/types/src/components/NavTreeItemColumns.d.ts +0 -4
- package/dist/types/src/components/NavTreeItemColumns.d.ts.map +0 -1
- package/dist/types/src/components/types.d.ts +0 -25
- package/dist/types/src/components/types.d.ts.map +0 -1
- package/dist/types/src/hooks.d.ts +0 -3
- package/dist/types/src/hooks.d.ts.map +0 -1
- package/dist/types/src/stories/StorybookNavTree.d.ts +0 -4
- package/dist/types/src/stories/StorybookNavTree.d.ts.map +0 -1
- package/src/components/L0Menu.tsx +0 -210
- package/src/components/L1Panels.tsx +0 -100
- package/src/components/NavTreeContext.tsx +0 -13
- package/src/components/NavTreeItemColumns.tsx +0 -71
- package/src/components/types.ts +0 -33
- package/src/hooks.ts +0 -21
- package/src/stories/StorybookNavTree.tsx +0 -63
|
@@ -1,210 +0,0 @@
|
|
|
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 avatarValue = useMemo(
|
|
89
|
-
() => (type === 'tab' ? getFirstTwoRenderableChars(localizedString).join('') : []),
|
|
90
|
-
[type, item.properties.label, t],
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
return (
|
|
94
|
-
<Tooltip.Root delayDuration={0}>
|
|
95
|
-
<Tooltip.Trigger asChild>
|
|
96
|
-
<Root
|
|
97
|
-
{...(rootProps as any)}
|
|
98
|
-
data-type={type}
|
|
99
|
-
className={mx(
|
|
100
|
-
'group/l0i dx-focus-ring-group grid overflow-hidden relative data[type!="collection"]:cursor-pointer app-no-drag',
|
|
101
|
-
l0Breakpoints[item.properties.l0Breakpoint],
|
|
102
|
-
)}
|
|
103
|
-
>
|
|
104
|
-
{type !== 'collection' && (
|
|
105
|
-
<div
|
|
106
|
-
role='none'
|
|
107
|
-
className={mx(
|
|
108
|
-
'absolute -z-[1] group-hover/l0i:bg-input dx-focus-ring-group-indicator transition-colors',
|
|
109
|
-
type === 'tab' || pinned ? 'rounded' : 'rounded-full',
|
|
110
|
-
pinned ? 'bg-transparent inset-inline-3 inset-block-0' : 'bg-input inset-inline-3 inset-block-2',
|
|
111
|
-
)}
|
|
112
|
-
/>
|
|
113
|
-
)}
|
|
114
|
-
<div
|
|
115
|
-
role='none'
|
|
116
|
-
className='hidden group-aria-selected/l0i:block absolute inline-start-0 inset-block-4 is-1 bg-accentSurface rounded-ie'
|
|
117
|
-
/>
|
|
118
|
-
{type === 'tab' && item.properties.disposition !== 'pin-end' ? (
|
|
119
|
-
<span role='img' className='place-self-center text-3xl font-light'>
|
|
120
|
-
{avatarValue}
|
|
121
|
-
</span>
|
|
122
|
-
) : (
|
|
123
|
-
item.properties.icon && (
|
|
124
|
-
<Icon icon={item.properties.icon} size={pinned ? 5 : 7} classNames='place-self-center' />
|
|
125
|
-
)
|
|
126
|
-
)}
|
|
127
|
-
<span id={`${item.id}__label`} className='sr-only'>
|
|
128
|
-
{localizedString}
|
|
129
|
-
</span>
|
|
130
|
-
</Root>
|
|
131
|
-
</Tooltip.Trigger>
|
|
132
|
-
<Tooltip.Portal>
|
|
133
|
-
<Tooltip.Content side='right'>
|
|
134
|
-
{localizedString}
|
|
135
|
-
<Tooltip.Arrow />
|
|
136
|
-
</Tooltip.Content>
|
|
137
|
-
</Tooltip.Portal>
|
|
138
|
-
</Tooltip.Root>
|
|
139
|
-
);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const L0Collection = ({ item, path, parent }: L0ItemProps) => {
|
|
143
|
-
const navTreeContext = useNavTreeContext();
|
|
144
|
-
useLoadDescendents(item);
|
|
145
|
-
const collectionItems = navTreeContext.getItems(item);
|
|
146
|
-
const groupPath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
147
|
-
const { id, testId } = navTreeContext.getProps?.(item, path) ?? {};
|
|
148
|
-
return (
|
|
149
|
-
<div
|
|
150
|
-
role='group'
|
|
151
|
-
className='contents group/l0c'
|
|
152
|
-
aria-labelledby={`${item.id}__label`}
|
|
153
|
-
data-itemid={id}
|
|
154
|
-
data-testid={testId}
|
|
155
|
-
>
|
|
156
|
-
{/* TODO(burdon): Option. */}
|
|
157
|
-
{/* <L0Item item={item} parent={parent} path={groupPath} /> */}
|
|
158
|
-
{collectionItems.map((collectionItem) => (
|
|
159
|
-
<L0Item key={collectionItem.id} item={collectionItem} parent={item} path={groupPath} />
|
|
160
|
-
))}
|
|
161
|
-
</div>
|
|
162
|
-
);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
export const L0Menu = ({
|
|
166
|
-
topLevelItems,
|
|
167
|
-
pinnedItems,
|
|
168
|
-
parent,
|
|
169
|
-
path,
|
|
170
|
-
}: {
|
|
171
|
-
topLevelItems: Node<any>[];
|
|
172
|
-
pinnedItems: Node<any>[];
|
|
173
|
-
parent?: Node<any>;
|
|
174
|
-
path: string[];
|
|
175
|
-
}) => {
|
|
176
|
-
return (
|
|
177
|
-
<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'>
|
|
178
|
-
<div
|
|
179
|
-
role='none'
|
|
180
|
-
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)]'
|
|
181
|
-
>
|
|
182
|
-
{topLevelItems.map((item) => {
|
|
183
|
-
if (l0ItemType(item) === 'collection') {
|
|
184
|
-
return <L0Collection key={item.id} item={item} parent={parent} path={path} />;
|
|
185
|
-
} else {
|
|
186
|
-
return <L0Item key={item.id} item={item} parent={parent} path={path} />;
|
|
187
|
-
}
|
|
188
|
-
})}
|
|
189
|
-
</div>
|
|
190
|
-
<div role='none' className='grid grid-cols-1 auto-rows-[--rail-action] pbs-2'>
|
|
191
|
-
{pinnedItems
|
|
192
|
-
.filter((item) => l0ItemType(item) !== 'collection')
|
|
193
|
-
.map((item) => (
|
|
194
|
-
<L0Item key={item.id} item={item} parent={parent} path={path} pinned />
|
|
195
|
-
))}
|
|
196
|
-
</div>
|
|
197
|
-
<div role='none' className='grid p-2 app-no-drag'>
|
|
198
|
-
<NotchStart />
|
|
199
|
-
</div>
|
|
200
|
-
<div
|
|
201
|
-
role='none'
|
|
202
|
-
className='hidden [body[data-platform="darwin"]_&]:block absolute block-start-0 is-[calc(var(--l0-size)-1px)] bs-[calc(40px+0.25rem)]'
|
|
203
|
-
style={{
|
|
204
|
-
background:
|
|
205
|
-
'linear-gradient(to bottom, var(--dx-baseSurface) 0%, var(--dx-baseSurface) 70%, transparent 100%)',
|
|
206
|
-
}}
|
|
207
|
-
/>
|
|
208
|
-
</Tabs.Tablist>
|
|
209
|
-
);
|
|
210
|
-
};
|
|
@@ -1,100 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { createContext, useContext } from 'react';
|
|
6
|
-
|
|
7
|
-
import { raise } from '@dxos/debug';
|
|
8
|
-
|
|
9
|
-
import { type NavTreeContextValue } from './types';
|
|
10
|
-
|
|
11
|
-
export const NavTreeContext = createContext<NavTreeContextValue | null>(null);
|
|
12
|
-
|
|
13
|
-
export const useNavTreeContext = () => useContext(NavTreeContext) ?? raise(new Error('NavTreeContext not found'));
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { Fragment, memo } from 'react';
|
|
6
|
-
|
|
7
|
-
import { isAction } from '@dxos/app-graph';
|
|
8
|
-
import { Popover, toLocalizedString, Treegrid, useTranslation } from '@dxos/react-ui';
|
|
9
|
-
|
|
10
|
-
import { NAV_TREE_ITEM } from './NavTree';
|
|
11
|
-
import { useNavTreeContext } from './NavTreeContext';
|
|
12
|
-
import { NavTreeItemAction } from './NavTreeItemAction';
|
|
13
|
-
import type { NavTreeItemColumnsProps } from './types';
|
|
14
|
-
import { useLoadDescendents } from '../hooks';
|
|
15
|
-
import { NAVTREE_PLUGIN } from '../meta';
|
|
16
|
-
|
|
17
|
-
export const NavTreeItemColumns = memo(({ path, item, open }: NavTreeItemColumnsProps) => {
|
|
18
|
-
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
19
|
-
const { getActions, renderItemEnd: ItemEnd, popoverAnchorId } = useNavTreeContext();
|
|
20
|
-
|
|
21
|
-
const level = path.length - 2;
|
|
22
|
-
|
|
23
|
-
const { actions: _actions, groupedActions } = getActions(item);
|
|
24
|
-
const [primaryAction, ...secondaryActions] = _actions.toSorted((a, b) =>
|
|
25
|
-
a.properties?.disposition === 'toolbar' ? -1 : 1,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
const actions = (primaryAction?.properties?.disposition === 'toolbar' ? secondaryActions : _actions)
|
|
29
|
-
.flatMap((action) => (isAction(action) ? [action] : []))
|
|
30
|
-
.filter((action) => !action.properties?.hidden);
|
|
31
|
-
|
|
32
|
-
const ActionRoot = popoverAnchorId === `dxos.org/ui/${NAV_TREE_ITEM}/${item.id}` ? Popover.Anchor : Fragment;
|
|
33
|
-
|
|
34
|
-
useLoadDescendents(item);
|
|
35
|
-
useLoadDescendents(primaryAction && !isAction(primaryAction) ? primaryAction : undefined);
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div role='none' className='contents app-no-drag'>
|
|
39
|
-
{primaryAction?.properties?.disposition === 'toolbar' && !primaryAction?.properties?.disabled ? (
|
|
40
|
-
<NavTreeItemAction
|
|
41
|
-
testId={primaryAction.properties?.testId}
|
|
42
|
-
label={toLocalizedString(primaryAction.properties?.label, t)}
|
|
43
|
-
icon={primaryAction.properties?.icon ?? 'ph--placeholder--regular'}
|
|
44
|
-
parent={item}
|
|
45
|
-
monolithic={isAction(primaryAction)}
|
|
46
|
-
menuActions={isAction(primaryAction) ? [primaryAction] : groupedActions[primaryAction.id]}
|
|
47
|
-
menuType={primaryAction.properties?.menuType}
|
|
48
|
-
caller={NAV_TREE_ITEM}
|
|
49
|
-
/>
|
|
50
|
-
) : (
|
|
51
|
-
<Treegrid.Cell />
|
|
52
|
-
)}
|
|
53
|
-
<ActionRoot>
|
|
54
|
-
{actions.length > 0 ? (
|
|
55
|
-
<NavTreeItemAction
|
|
56
|
-
testId={`navtree.treeItem.actionsLevel${level}`}
|
|
57
|
-
label={t('tree item actions label')}
|
|
58
|
-
icon='ph--dots-three-vertical--regular'
|
|
59
|
-
parent={item}
|
|
60
|
-
menuActions={actions}
|
|
61
|
-
menuType='dropdown'
|
|
62
|
-
caller={NAV_TREE_ITEM}
|
|
63
|
-
/>
|
|
64
|
-
) : (
|
|
65
|
-
<Treegrid.Cell />
|
|
66
|
-
)}
|
|
67
|
-
</ActionRoot>
|
|
68
|
-
{ItemEnd && <ItemEnd node={item} open={open} />}
|
|
69
|
-
</div>
|
|
70
|
-
);
|
|
71
|
-
});
|
package/src/components/types.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type { FC } from 'react';
|
|
6
|
-
|
|
7
|
-
import type { Node } from '@dxos/app-graph';
|
|
8
|
-
import type { TreeProps } from '@dxos/react-ui-list';
|
|
9
|
-
import type { MaybePromise } from '@dxos/util';
|
|
10
|
-
|
|
11
|
-
import type { FlattenedActions, NavTreeItemGraphNode } from '../types';
|
|
12
|
-
|
|
13
|
-
export type NavTreeItemColumnsProps = {
|
|
14
|
-
path: string[];
|
|
15
|
-
item: Node;
|
|
16
|
-
open: boolean;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type NavTreeProps = Pick<TreeProps<NavTreeItemGraphNode>, 'id' | 'root'>;
|
|
20
|
-
|
|
21
|
-
export type NavTreeContextValue = Pick<
|
|
22
|
-
TreeProps<NavTreeItemGraphNode>,
|
|
23
|
-
'getProps' | 'isCurrent' | 'isOpen' | 'onOpenChange' | 'canDrop' | 'onSelect'
|
|
24
|
-
> & {
|
|
25
|
-
tab: string;
|
|
26
|
-
onTabChange?: (node: NavTreeItemGraphNode) => void;
|
|
27
|
-
getItems: (node?: NavTreeItemGraphNode, disposition?: string) => NavTreeItemGraphNode[];
|
|
28
|
-
getActions: (node: Node) => FlattenedActions;
|
|
29
|
-
loadDescendents?: (node: Node) => MaybePromise<void>;
|
|
30
|
-
renderItemEnd?: FC<{ node: Node; open: boolean }>;
|
|
31
|
-
popoverAnchorId?: string;
|
|
32
|
-
topbar?: boolean;
|
|
33
|
-
};
|
package/src/hooks.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { useEffect } from 'react';
|
|
6
|
-
|
|
7
|
-
import { type Node } from '@dxos/app-graph';
|
|
8
|
-
|
|
9
|
-
import { useNavTreeContext } from './components/NavTreeContext';
|
|
10
|
-
|
|
11
|
-
export const useLoadDescendents = (root?: Node) => {
|
|
12
|
-
const { loadDescendents } = useNavTreeContext();
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
const frame = requestAnimationFrame(() => {
|
|
15
|
-
if (root) {
|
|
16
|
-
void loadDescendents?.(root);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return () => cancelAnimationFrame(frame);
|
|
20
|
-
}, [root]);
|
|
21
|
-
};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useMemo, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { NavTree, NavTreeContext, type NavTreeContextValue, type NavTreeProps } from '../components';
|
|
8
|
-
import { type NavTreeItemGraphNode } from '../types';
|
|
9
|
-
|
|
10
|
-
export const StorybookNavTree = ({
|
|
11
|
-
getActions,
|
|
12
|
-
loadDescendents,
|
|
13
|
-
renderItemEnd,
|
|
14
|
-
popoverAnchorId,
|
|
15
|
-
getItems,
|
|
16
|
-
getProps,
|
|
17
|
-
isCurrent,
|
|
18
|
-
canDrop,
|
|
19
|
-
onSelect,
|
|
20
|
-
isOpen,
|
|
21
|
-
onOpenChange,
|
|
22
|
-
...props
|
|
23
|
-
}: NavTreeProps & NavTreeContextValue) => {
|
|
24
|
-
const [tab, setTab] = useState('never');
|
|
25
|
-
|
|
26
|
-
const contextValue = useMemo(
|
|
27
|
-
() => ({
|
|
28
|
-
tab,
|
|
29
|
-
onTabChange: (node: NavTreeItemGraphNode) => setTab(node.id),
|
|
30
|
-
getActions,
|
|
31
|
-
loadDescendents,
|
|
32
|
-
renderItemEnd,
|
|
33
|
-
popoverAnchorId,
|
|
34
|
-
getItems,
|
|
35
|
-
getProps,
|
|
36
|
-
isCurrent,
|
|
37
|
-
isOpen,
|
|
38
|
-
onOpenChange,
|
|
39
|
-
canDrop,
|
|
40
|
-
onSelect,
|
|
41
|
-
}),
|
|
42
|
-
[
|
|
43
|
-
tab,
|
|
44
|
-
setTab,
|
|
45
|
-
getActions,
|
|
46
|
-
loadDescendents,
|
|
47
|
-
renderItemEnd,
|
|
48
|
-
popoverAnchorId,
|
|
49
|
-
getItems,
|
|
50
|
-
getProps,
|
|
51
|
-
isCurrent,
|
|
52
|
-
isOpen,
|
|
53
|
-
onOpenChange,
|
|
54
|
-
canDrop,
|
|
55
|
-
onSelect,
|
|
56
|
-
],
|
|
57
|
-
);
|
|
58
|
-
return (
|
|
59
|
-
<NavTreeContext.Provider value={contextValue}>
|
|
60
|
-
<NavTree {...props} />
|
|
61
|
-
</NavTreeContext.Provider>
|
|
62
|
-
);
|
|
63
|
-
};
|