@dxos/plugin-navtree 0.8.2-staging.7ac8446 → 0.8.2
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-26D3MUCA.mjs → app-graph-builder-P7AY3K72.mjs} +7 -6
- package/dist/lib/browser/app-graph-builder-P7AY3K72.mjs.map +7 -0
- package/dist/lib/browser/{chunk-4RQJXI4D.mjs → chunk-33VLL4IJ.mjs} +2 -2
- package/dist/lib/browser/chunk-33VLL4IJ.mjs.map +7 -0
- package/dist/lib/browser/chunk-MFAWMFJC.mjs +1418 -0
- package/dist/lib/browser/chunk-MFAWMFJC.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +6 -11
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-BZMUS24C.mjs → intent-resolver-NAYKKAOP.mjs} +7 -7
- package/dist/lib/browser/intent-resolver-NAYKKAOP.mjs.map +7 -0
- package/dist/lib/browser/keyboard-DDFATRUG.mjs +51 -0
- package/dist/lib/browser/keyboard-DDFATRUG.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-3HCM3SHJ.mjs → react-surface-HGA3TAQU.mjs} +3 -3
- package/dist/lib/browser/{state-M5UJ3MHL.mjs → state-R2UMYAHN.mjs} +18 -12
- package/dist/lib/browser/state-R2UMYAHN.mjs.map +7 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts +2 -179
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/capabilities.d.ts +7 -4
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +38 -183
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +2 -2
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/keyboard.d.ts +2 -2
- package/dist/types/src/capabilities/keyboard.d.ts.map +1 -1
- package/dist/types/src/capabilities/state.d.ts +9 -6
- package/dist/types/src/capabilities/state.d.ts.map +1 -1
- package/dist/types/src/components/CommandsDialog/CommandsDialog.d.ts.map +1 -0
- package/dist/types/src/components/CommandsDialog/CommandsTrigger.d.ts.map +1 -0
- package/dist/types/src/components/CommandsDialog/index.d.ts +3 -0
- package/dist/types/src/components/CommandsDialog/index.d.ts.map +1 -0
- package/dist/types/src/components/NavTree/NavTree.d.ts +8 -0
- package/dist/types/src/components/NavTree/NavTree.d.ts.map +1 -0
- package/dist/types/src/components/NavTree/NavTree.stories.d.ts +8 -0
- package/dist/types/src/components/NavTree/NavTree.stories.d.ts.map +1 -0
- package/dist/types/src/components/NavTree/index.d.ts +2 -0
- package/dist/types/src/components/NavTree/index.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeContainer.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeContext.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeDocumentTitle.d.ts.map +1 -1
- package/dist/types/src/components/{NavTreeItemAction.d.ts → NavTreeItem/NavTreeItemAction.d.ts} +3 -5
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.stories.d.ts +8 -0
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.stories.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeItem/NavTreeItemColumns.d.ts +4 -0
- package/dist/types/src/components/NavTreeItem/NavTreeItemColumns.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeItem/index.d.ts +3 -0
- package/dist/types/src/components/NavTreeItem/index.d.ts.map +1 -0
- package/dist/types/src/components/Sidebar/L0Menu.d.ts +13 -0
- package/dist/types/src/components/Sidebar/L0Menu.d.ts.map +1 -0
- package/dist/types/src/components/Sidebar/L1Panel.d.ts +15 -0
- package/dist/types/src/components/Sidebar/L1Panel.d.ts.map +1 -0
- package/dist/types/src/components/Sidebar/index.d.ts +3 -0
- package/dist/types/src/components/Sidebar/index.d.ts.map +1 -0
- package/dist/types/src/components/{UserAccountAvatar.d.ts → UserAccountAvatar/UserAccountAvatar.d.ts} +1 -1
- package/dist/types/src/components/UserAccountAvatar/UserAccountAvatar.d.ts.map +1 -0
- package/dist/types/src/components/{UserAccountAvatar.stories.d.ts → UserAccountAvatar/UserAccountAvatar.stories.d.ts} +1 -2
- package/dist/types/src/components/UserAccountAvatar/UserAccountAvatar.stories.d.ts.map +1 -0
- package/dist/types/src/components/UserAccountAvatar/index.d.ts +2 -0
- package/dist/types/src/components/UserAccountAvatar/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +0 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/types.d.ts +20 -14
- package/dist/types/src/components/types.d.ts.map +1 -1
- package/dist/types/src/experimental/Tree.d.ts.map +1 -1
- package/dist/types/src/hooks.d.ts.map +1 -1
- package/dist/types/src/testing/app-graph-builder.d.ts +3 -0
- package/dist/types/src/testing/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/testing/generator.d.ts +7 -6
- package/dist/types/src/testing/generator.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/update-state.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +1 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +7 -10
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +42 -32
- package/src/NavTreePlugin.tsx +2 -2
- package/src/capabilities/app-graph-builder.ts +38 -28
- package/src/capabilities/capabilities.ts +5 -4
- package/src/capabilities/intent-resolver.ts +8 -7
- package/src/capabilities/keyboard.ts +37 -32
- package/src/capabilities/state.ts +23 -17
- package/src/components/{CommandsDialog.tsx → CommandsDialog/CommandsDialog.tsx} +8 -7
- package/src/components/{CommandsTrigger.tsx → CommandsDialog/CommandsTrigger.tsx} +1 -1
- package/src/components/CommandsDialog/index.ts +6 -0
- package/src/components/NavTree/NavTree.stories.tsx +159 -0
- package/src/components/NavTree/NavTree.tsx +62 -0
- package/src/components/NavTree/index.ts +5 -0
- package/src/components/NavTreeContainer.tsx +85 -67
- package/src/components/NavTreeContext.tsx +1 -1
- package/src/components/{NavTreeItemAction.stories.tsx → NavTreeItem/NavTreeItemAction.stories.tsx} +12 -6
- package/src/components/{NavTreeItemAction.tsx → NavTreeItem/NavTreeItemAction.tsx} +19 -22
- package/src/components/NavTreeItem/NavTreeItemColumns.tsx +73 -0
- package/src/components/NavTreeItem/index.ts +6 -0
- package/src/components/{L0Menu.tsx → Sidebar/L0Menu.tsx} +186 -131
- package/src/components/Sidebar/L1Panel.tsx +175 -0
- package/src/components/Sidebar/index.ts +6 -0
- package/src/components/{UserAccountAvatar.stories.tsx → UserAccountAvatar/UserAccountAvatar.stories.tsx} +5 -5
- package/src/components/{UserAccountAvatar.tsx → UserAccountAvatar/UserAccountAvatar.tsx} +7 -7
- package/src/components/UserAccountAvatar/index.ts +5 -0
- package/src/components/index.ts +0 -1
- package/src/components/types.ts +20 -15
- package/src/testing/app-graph-builder.ts +224 -0
- package/src/testing/generator.ts +15 -12
- package/src/testing/index.ts +1 -0
- package/src/translations.ts +1 -0
- package/src/util.ts +10 -32
- package/dist/lib/browser/app-graph-builder-26D3MUCA.mjs.map +0 -7
- package/dist/lib/browser/chunk-4RQJXI4D.mjs.map +0 -7
- package/dist/lib/browser/chunk-DN43QXSX.mjs +0 -1222
- package/dist/lib/browser/chunk-DN43QXSX.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-BZMUS24C.mjs.map +0 -7
- package/dist/lib/browser/keyboard-IQXHKUWM.mjs +0 -46
- package/dist/lib/browser/keyboard-IQXHKUWM.mjs.map +0 -7
- package/dist/lib/browser/state-M5UJ3MHL.mjs.map +0 -7
- package/dist/types/src/components/CommandsDialog.d.ts.map +0 -1
- package/dist/types/src/components/CommandsTrigger.d.ts.map +0 -1
- package/dist/types/src/components/L0Menu.d.ts +0 -10
- package/dist/types/src/components/L0Menu.d.ts.map +0 -1
- package/dist/types/src/components/L1Panels.d.ts +0 -14
- package/dist/types/src/components/L1Panels.d.ts.map +0 -1
- package/dist/types/src/components/NavTree.d.ts +0 -5
- package/dist/types/src/components/NavTree.d.ts.map +0 -1
- package/dist/types/src/components/NavTree.stories.d.ts +0 -7
- package/dist/types/src/components/NavTree.stories.d.ts.map +0 -1
- package/dist/types/src/components/NavTreeItemAction.d.ts.map +0 -1
- package/dist/types/src/components/NavTreeItemAction.stories.d.ts +0 -41
- package/dist/types/src/components/NavTreeItemAction.stories.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/UserAccountAvatar.d.ts.map +0 -1
- package/dist/types/src/components/UserAccountAvatar.stories.d.ts.map +0 -1
- package/dist/types/src/stories/Graph.stories.d.ts +0 -7
- package/dist/types/src/stories/Graph.stories.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/L1Panels.tsx +0 -115
- package/src/components/NavTree.stories.tsx +0 -107
- package/src/components/NavTree.tsx +0 -51
- package/src/components/NavTreeItemColumns.tsx +0 -71
- package/src/stories/Graph.stories.tsx +0 -130
- package/src/stories/StorybookNavTree.tsx +0 -63
- /package/dist/lib/browser/{react-surface-3HCM3SHJ.mjs.map → react-surface-HGA3TAQU.mjs.map} +0 -0
- /package/dist/types/src/components/{CommandsDialog.d.ts → CommandsDialog/CommandsDialog.d.ts} +0 -0
- /package/dist/types/src/components/{CommandsTrigger.d.ts → CommandsDialog/CommandsTrigger.d.ts} +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
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 { DensityProvider, Popover, toLocalizedString, Treegrid, useTranslation } from '@dxos/react-ui';
|
|
9
|
+
|
|
10
|
+
import { NavTreeItemAction } from './NavTreeItemAction';
|
|
11
|
+
import { useLoadDescendents } from '../../hooks';
|
|
12
|
+
import { NAVTREE_PLUGIN } from '../../meta';
|
|
13
|
+
import { NAV_TREE_ITEM } from '../NavTree';
|
|
14
|
+
import { useNavTreeContext } from '../NavTreeContext';
|
|
15
|
+
import type { NavTreeItemColumnsProps } from '../types';
|
|
16
|
+
|
|
17
|
+
export const NavTreeItemColumns = memo(({ path, item, open, density = 'fine' }: 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 === 'list-item-primary' ? -1 : 1,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const actions = (primaryAction?.properties?.disposition === 'list-item-primary' ? 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
|
+
<DensityProvider density={density}>
|
|
39
|
+
<div role='none' className='contents app-no-drag'>
|
|
40
|
+
{primaryAction?.properties?.disposition === 'list-item-primary' && !primaryAction?.properties?.disabled ? (
|
|
41
|
+
<NavTreeItemAction
|
|
42
|
+
testId={primaryAction.properties?.testId}
|
|
43
|
+
label={toLocalizedString(primaryAction.properties?.label, t)}
|
|
44
|
+
icon={primaryAction.properties?.icon ?? 'ph--placeholder--regular'}
|
|
45
|
+
parent={item}
|
|
46
|
+
monolithic={isAction(primaryAction)}
|
|
47
|
+
menuActions={isAction(primaryAction) ? [primaryAction] : groupedActions[primaryAction.id]}
|
|
48
|
+
menuType={primaryAction.properties?.menuType}
|
|
49
|
+
caller={NAV_TREE_ITEM}
|
|
50
|
+
/>
|
|
51
|
+
) : (
|
|
52
|
+
<Treegrid.Cell />
|
|
53
|
+
)}
|
|
54
|
+
<ActionRoot>
|
|
55
|
+
{actions.length > 0 ? (
|
|
56
|
+
<NavTreeItemAction
|
|
57
|
+
testId={`navtree.treeItem.actionsLevel${level}`}
|
|
58
|
+
label={t('tree item actions label')}
|
|
59
|
+
icon='ph--dots-three-vertical--regular'
|
|
60
|
+
parent={item}
|
|
61
|
+
menuActions={actions}
|
|
62
|
+
menuType='dropdown'
|
|
63
|
+
caller={NAV_TREE_ITEM}
|
|
64
|
+
/>
|
|
65
|
+
) : (
|
|
66
|
+
<Treegrid.Cell />
|
|
67
|
+
)}
|
|
68
|
+
</ActionRoot>
|
|
69
|
+
{ItemEnd && <ItemEnd node={item} open={open} />}
|
|
70
|
+
</div>
|
|
71
|
+
</DensityProvider>
|
|
72
|
+
);
|
|
73
|
+
});
|
|
@@ -7,88 +7,92 @@ import { draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-d
|
|
|
7
7
|
import { preserveOffsetOnSource } from '@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source';
|
|
8
8
|
import { scrollJustEnoughIntoView } from '@atlaskit/pragmatic-drag-and-drop/element/scroll-just-enough-into-view';
|
|
9
9
|
import {
|
|
10
|
-
attachClosestEdge,
|
|
11
10
|
type Edge,
|
|
11
|
+
attachClosestEdge,
|
|
12
12
|
extractClosestEdge,
|
|
13
13
|
} from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
|
|
14
|
-
import React, {
|
|
14
|
+
import React, {
|
|
15
|
+
forwardRef,
|
|
16
|
+
type MouseEvent,
|
|
17
|
+
type PropsWithChildren,
|
|
18
|
+
useCallback,
|
|
19
|
+
useLayoutEffect,
|
|
20
|
+
useMemo,
|
|
21
|
+
useRef,
|
|
22
|
+
useState,
|
|
23
|
+
} from 'react';
|
|
15
24
|
|
|
16
|
-
import { createIntent, LayoutAction, useIntentDispatcher } from '@dxos/app-framework';
|
|
17
25
|
import { type Node } from '@dxos/app-graph';
|
|
18
26
|
import { invariant } from '@dxos/invariant';
|
|
19
27
|
import {
|
|
20
|
-
|
|
28
|
+
Icon,
|
|
29
|
+
IconButton,
|
|
30
|
+
ListItem,
|
|
21
31
|
ScrollArea,
|
|
22
|
-
toLocalizedString,
|
|
23
32
|
Tooltip,
|
|
33
|
+
toLocalizedString,
|
|
24
34
|
useMediaQuery,
|
|
25
|
-
useSidebars,
|
|
26
35
|
useTranslation,
|
|
27
|
-
ListItem,
|
|
28
|
-
Icon,
|
|
29
36
|
} from '@dxos/react-ui';
|
|
37
|
+
import { MenuProvider, DropdownMenu, type MenuItem } from '@dxos/react-ui-menu';
|
|
30
38
|
import type { StackItemRearrangeHandler } from '@dxos/react-ui-stack';
|
|
31
39
|
import { Tabs } from '@dxos/react-ui-tabs';
|
|
32
40
|
import { mx } from '@dxos/react-ui-theme';
|
|
33
41
|
import { arrayMove, getFirstTwoRenderableChars } from '@dxos/util';
|
|
34
42
|
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
43
|
+
import { useLoadDescendents } from '../../hooks';
|
|
44
|
+
import { NAVTREE_PLUGIN } from '../../meta';
|
|
45
|
+
import { l0ItemType } from '../../util';
|
|
46
|
+
import { useNavTreeContext } from '../NavTreeContext';
|
|
47
|
+
import { UserAccountAvatar } from '../UserAccountAvatar';
|
|
48
|
+
|
|
49
|
+
//
|
|
50
|
+
// L0Item
|
|
51
|
+
//
|
|
52
|
+
|
|
53
|
+
type L0ItemData = {
|
|
54
|
+
id: L0ItemProps['item']['id'];
|
|
55
|
+
type: 'l0Item';
|
|
56
|
+
};
|
|
40
57
|
|
|
41
|
-
type
|
|
58
|
+
type L0ItemRootProps = {
|
|
59
|
+
item: Node<any>;
|
|
60
|
+
parent?: Node<any>;
|
|
61
|
+
path: string[];
|
|
62
|
+
};
|
|
42
63
|
|
|
43
|
-
type L0ItemProps = {
|
|
64
|
+
type L0ItemProps = L0ItemRootProps & {
|
|
44
65
|
item: Node<any>;
|
|
45
66
|
parent?: Node<any>;
|
|
46
67
|
path: string[];
|
|
47
68
|
pinned?: boolean;
|
|
48
|
-
userAccount?: boolean;
|
|
49
69
|
onRearrange?: StackItemRearrangeHandler<L0ItemData>;
|
|
50
70
|
};
|
|
51
71
|
|
|
52
72
|
const useL0ItemClick = ({ item, parent, path }: L0ItemProps, type: string) => {
|
|
53
|
-
const { tab,
|
|
54
|
-
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
55
|
-
const { navigationSidebarState } = useSidebars(NAVTREE_PLUGIN);
|
|
73
|
+
const { tab, isCurrent, onSelect, onTabChange } = useNavTreeContext();
|
|
56
74
|
const [isLg] = useMediaQuery('lg', { ssr: false });
|
|
57
75
|
|
|
58
76
|
return useCallback(
|
|
59
77
|
(event: MouseEvent) => {
|
|
60
78
|
switch (type) {
|
|
61
|
-
case 'tab':
|
|
62
|
-
// TODO(thure): This dispatch should rightly be in `onTabChange`, but that callback wasn’t reacting to changes
|
|
63
|
-
// to its dependencies.
|
|
64
|
-
void dispatch(
|
|
65
|
-
createIntent(LayoutAction.UpdateSidebar, {
|
|
66
|
-
part: 'sidebar',
|
|
67
|
-
options: {
|
|
68
|
-
state:
|
|
69
|
-
item.id === tab
|
|
70
|
-
? navigationSidebarState === 'expanded'
|
|
71
|
-
? isLg
|
|
72
|
-
? 'collapsed'
|
|
73
|
-
: 'closed'
|
|
74
|
-
: 'expanded'
|
|
75
|
-
: 'expanded',
|
|
76
|
-
},
|
|
77
|
-
}),
|
|
78
|
-
);
|
|
79
|
-
return onTabChange?.(item);
|
|
80
|
-
case 'link':
|
|
81
|
-
return onSelect?.({ item, path, current: !isCurrent(path, item), option: event.altKey });
|
|
82
79
|
case 'action': {
|
|
83
80
|
const {
|
|
84
81
|
data: invoke,
|
|
85
82
|
properties: { caller },
|
|
86
83
|
} = item;
|
|
84
|
+
|
|
87
85
|
return invoke?.(caller ? { node: parent, caller } : { node: parent });
|
|
88
86
|
}
|
|
87
|
+
|
|
88
|
+
case 'tab':
|
|
89
|
+
return onTabChange?.(item);
|
|
90
|
+
|
|
91
|
+
case 'link':
|
|
92
|
+
return onSelect?.({ item, path, current: !isCurrent(path, item), option: event.altKey });
|
|
89
93
|
}
|
|
90
94
|
},
|
|
91
|
-
[item, type,
|
|
95
|
+
[item, parent, type, tab, isCurrent, onSelect, onTabChange, isLg],
|
|
92
96
|
);
|
|
93
97
|
};
|
|
94
98
|
|
|
@@ -96,28 +100,70 @@ const l0Breakpoints: Record<string, string> = {
|
|
|
96
100
|
lg: 'hidden lg:grid',
|
|
97
101
|
};
|
|
98
102
|
|
|
99
|
-
const
|
|
103
|
+
const L0ItemRoot = forwardRef<HTMLElement, PropsWithChildren<L0ItemRootProps>>(
|
|
104
|
+
({ item, parent, path, children }, forwardedRef) => {
|
|
105
|
+
const { getProps } = useNavTreeContext();
|
|
106
|
+
const { id, testId } = getProps?.(item, path) ?? {};
|
|
107
|
+
const type = l0ItemType(item);
|
|
108
|
+
const itemPath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
109
|
+
|
|
110
|
+
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
111
|
+
const localizedString = toLocalizedString(item.properties.label, t);
|
|
112
|
+
|
|
113
|
+
const handleClick = useL0ItemClick({ item, parent, path: itemPath }, type);
|
|
114
|
+
const rootProps =
|
|
115
|
+
type === 'tab'
|
|
116
|
+
? { value: item.id, tabIndex: 0, onClick: handleClick, 'data-testid': testId, 'data-itemid': id }
|
|
117
|
+
: type !== 'collection'
|
|
118
|
+
? { onClick: handleClick, 'data-testid': testId, 'data-itemid': id }
|
|
119
|
+
: { onClick: handleClick };
|
|
120
|
+
|
|
121
|
+
const Root = type === 'collection' ? 'h2' : type === 'tab' ? Tabs.TabPrimitive : 'button';
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<Tooltip.Trigger asChild delayDuration={0} side='right' content={localizedString}>
|
|
125
|
+
<Root
|
|
126
|
+
{...(rootProps as any)}
|
|
127
|
+
data-type={type}
|
|
128
|
+
className={mx(
|
|
129
|
+
'group/l0item flex w-full justify-center items-center relative data[type!="collection"]:cursor-pointer app-no-drag dx-focus-ring-group',
|
|
130
|
+
l0Breakpoints[item.properties.l0Breakpoint],
|
|
131
|
+
)}
|
|
132
|
+
ref={forwardedRef}
|
|
133
|
+
>
|
|
134
|
+
{children}
|
|
135
|
+
</Root>
|
|
136
|
+
</Tooltip.Trigger>
|
|
137
|
+
);
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const L0Avator = ({ item }: Pick<L0ItemProps, 'item'>) => {
|
|
100
142
|
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
101
|
-
const itemElement = useRef<HTMLElement | null>(null);
|
|
102
|
-
const [closestEdge, setEdge] = useState<Edge | null>(null);
|
|
103
143
|
const type = l0ItemType(item);
|
|
104
|
-
const itemPath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
105
|
-
const { getProps, popoverAnchorId } = useNavTreeContext();
|
|
106
|
-
const { id, testId } = getProps?.(item, path) ?? {};
|
|
107
|
-
const Root = type === 'collection' ? 'h2' : type === 'tab' ? Tabs.TabPrimitive : 'button';
|
|
108
|
-
const handleClick = useL0ItemClick({ item, path: itemPath, parent }, type);
|
|
109
|
-
const rootProps =
|
|
110
|
-
type === 'tab'
|
|
111
|
-
? { value: item.id, tabIndex: 0, onClick: handleClick, 'data-testid': testId, 'data-itemid': id }
|
|
112
|
-
: type !== 'collection'
|
|
113
|
-
? { onClick: handleClick, 'data-testid': testId, 'data-itemid': id }
|
|
114
|
-
: { onClick: handleClick };
|
|
115
|
-
const localizedString = toLocalizedString(item.properties.label, t);
|
|
116
144
|
const hue = item.properties.hue ?? null;
|
|
145
|
+
const hueFgStyle = hue && { style: { color: `var(--dx-${hue}SurfaceText)` } };
|
|
146
|
+
const localizedString = toLocalizedString(item.properties.label, t);
|
|
117
147
|
const avatarValue = useMemo(
|
|
118
148
|
() => (type === 'tab' ? getFirstTwoRenderableChars(localizedString).join('').toUpperCase() : []),
|
|
119
149
|
[type, item.properties.label, t],
|
|
120
150
|
);
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<span role='img' className='place-self-center text-xl font-light' {...hueFgStyle}>
|
|
154
|
+
{avatarValue}
|
|
155
|
+
</span>
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// TODO(burdon): Factor out pinned (non-draggable) items.
|
|
160
|
+
const L0Item = ({ item, parent, path, pinned, onRearrange }: L0ItemProps) => {
|
|
161
|
+
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
162
|
+
const itemElement = useRef<HTMLElement | null>(null);
|
|
163
|
+
const [closestEdge, setEdge] = useState<Edge | null>(null);
|
|
164
|
+
const type = l0ItemType(item);
|
|
165
|
+
const localizedString = toLocalizedString(item.properties.label, t);
|
|
166
|
+
const hue = item.properties.hue ?? null;
|
|
121
167
|
const hueFgStyle = hue && { style: { color: `var(--dx-${hue}SurfaceText)` } };
|
|
122
168
|
|
|
123
169
|
useLayoutEffect(() => {
|
|
@@ -125,6 +171,7 @@ const L0Item = ({ item, parent, path, pinned, userAccount, onRearrange }: L0Item
|
|
|
125
171
|
if (!itemElement.current || !onRearrange) {
|
|
126
172
|
return;
|
|
127
173
|
}
|
|
174
|
+
|
|
128
175
|
return combine(
|
|
129
176
|
draggable({
|
|
130
177
|
element: itemElement.current,
|
|
@@ -175,80 +222,43 @@ const L0Item = ({ item, parent, path, pinned, userAccount, onRearrange }: L0Item
|
|
|
175
222
|
);
|
|
176
223
|
}, [item, onRearrange]);
|
|
177
224
|
|
|
178
|
-
|
|
179
|
-
<
|
|
180
|
-
{...(rootProps as any)}
|
|
181
|
-
data-type={type}
|
|
182
|
-
className={mx(
|
|
183
|
-
'group/l0i dx-focus-ring-group grid relative data[type!="collection"]:cursor-pointer app-no-drag',
|
|
184
|
-
l0Breakpoints[item.properties.l0Breakpoint],
|
|
185
|
-
)}
|
|
186
|
-
ref={itemElement}
|
|
187
|
-
>
|
|
188
|
-
{userAccount ? (
|
|
189
|
-
<UserAccountAvatar
|
|
190
|
-
userId={item.properties.userId}
|
|
191
|
-
hue={item.properties.hue}
|
|
192
|
-
emoji={item.properties.emoji}
|
|
193
|
-
status={item.properties.status}
|
|
194
|
-
/>
|
|
195
|
-
) : (
|
|
196
|
-
<div
|
|
197
|
-
role='none'
|
|
198
|
-
data-frame={true}
|
|
199
|
-
className={mx(
|
|
200
|
-
'absolute grid dx-focus-ring-group-indicator transition-colors',
|
|
201
|
-
type === 'tab' || pinned ? 'rounded' : 'rounded-full',
|
|
202
|
-
pinned
|
|
203
|
-
? 'bg-transparent group-hover/l0i:bg-groupSurface inset-inline-3 inset-block-0.5'
|
|
204
|
-
: 'bg-groupSurface inset-inline-3 inset-block-2',
|
|
205
|
-
)}
|
|
206
|
-
{...(hue && { style: { background: `var(--dx-${hue}Surface)` } })}
|
|
207
|
-
>
|
|
208
|
-
{(item.properties.icon && (
|
|
209
|
-
<Icon icon={item.properties.icon} size={pinned ? 5 : 7} classNames='place-self-center' {...hueFgStyle} />
|
|
210
|
-
)) ||
|
|
211
|
-
(type === 'tab' && item.properties.disposition !== 'pin-end' ? (
|
|
212
|
-
<span role='img' className='place-self-center text-3xl font-light' {...hueFgStyle}>
|
|
213
|
-
{avatarValue}
|
|
214
|
-
</span>
|
|
215
|
-
) : (
|
|
216
|
-
item.properties.icon && (
|
|
217
|
-
<Icon icon='ph--planet--regular' size={pinned ? 5 : 7} classNames='place-self-center' {...hueFgStyle} />
|
|
218
|
-
)
|
|
219
|
-
))}
|
|
220
|
-
</div>
|
|
221
|
-
)}
|
|
225
|
+
return (
|
|
226
|
+
<L0ItemRoot ref={itemElement} item={item} parent={parent} path={path}>
|
|
222
227
|
<div
|
|
223
228
|
role='none'
|
|
224
|
-
|
|
229
|
+
data-frame={true}
|
|
230
|
+
className={mx(
|
|
231
|
+
'flex justify-center items-center dx-focus-ring-group-indicator transition-colors rounded',
|
|
232
|
+
// TODO(burdon): Create reusable button/component and/or create var for size.
|
|
233
|
+
pinned
|
|
234
|
+
? 'bg-transparent w-[50px] p-2 group-hover/l0item:bg-activeSurface'
|
|
235
|
+
: 'bg-activeSurface w-[50px] h-[50px]',
|
|
236
|
+
)}
|
|
237
|
+
{...(hue && { style: { background: `var(--dx-${hue}Surface)` } })}
|
|
238
|
+
>
|
|
239
|
+
{(item.properties.icon && <Icon icon={item.properties.icon} size={pinned ? 5 : 6} {...hueFgStyle} />) ||
|
|
240
|
+
(type === 'tab' && item.properties.disposition !== 'pin-end' && <L0Avator item={item} />)}
|
|
241
|
+
</div>
|
|
242
|
+
<div
|
|
243
|
+
role='none'
|
|
244
|
+
className='hidden group-aria-selected/l0item:block absolute inline-start-0 inset-block-4 is-1 bg-accentSurface rounded-ie'
|
|
225
245
|
/>
|
|
226
246
|
<span id={`${item.id}__label`} className='sr-only'>
|
|
227
247
|
{localizedString}
|
|
228
248
|
</span>
|
|
229
249
|
{onRearrange && closestEdge && <ListItem.DropIndicator edge={closestEdge} />}
|
|
230
|
-
</
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
return popoverAnchorId === id ? (
|
|
234
|
-
<Popover.Anchor asChild>{l0ItemTrigger}</Popover.Anchor>
|
|
235
|
-
) : (
|
|
236
|
-
<Tooltip.Root delayDuration={0}>
|
|
237
|
-
<Tooltip.Trigger asChild>{l0ItemTrigger}</Tooltip.Trigger>
|
|
238
|
-
<Tooltip.Portal>
|
|
239
|
-
<Tooltip.Content side='right'>
|
|
240
|
-
{localizedString}
|
|
241
|
-
<Tooltip.Arrow />
|
|
242
|
-
</Tooltip.Content>
|
|
243
|
-
</Tooltip.Portal>
|
|
244
|
-
</Tooltip.Root>
|
|
250
|
+
</L0ItemRoot>
|
|
245
251
|
);
|
|
246
252
|
};
|
|
247
253
|
|
|
248
|
-
|
|
254
|
+
//
|
|
255
|
+
// L0Collection
|
|
256
|
+
//
|
|
257
|
+
|
|
258
|
+
const L0Collection = ({ item, path }: L0ItemProps) => {
|
|
249
259
|
const navTreeContext = useNavTreeContext();
|
|
250
260
|
useLoadDescendents(item);
|
|
251
|
-
const collectionItems = navTreeContext.
|
|
261
|
+
const collectionItems = navTreeContext.useItems(item);
|
|
252
262
|
const groupPath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
253
263
|
const { id, testId } = navTreeContext.getProps?.(item, path) ?? {};
|
|
254
264
|
const handleRearrange = useCallback<StackItemRearrangeHandler<L0ItemData>>(
|
|
@@ -266,6 +276,7 @@ const L0Collection = ({ item, path, parent }: L0ItemProps) => {
|
|
|
266
276
|
},
|
|
267
277
|
[collectionItems, item.properties.onRearrangeChildren],
|
|
268
278
|
);
|
|
279
|
+
|
|
269
280
|
return (
|
|
270
281
|
<div
|
|
271
282
|
role='group'
|
|
@@ -287,26 +298,59 @@ const L0Collection = ({ item, path, parent }: L0ItemProps) => {
|
|
|
287
298
|
);
|
|
288
299
|
};
|
|
289
300
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}: {
|
|
301
|
+
//
|
|
302
|
+
// L0Menu
|
|
303
|
+
//
|
|
304
|
+
|
|
305
|
+
export type L0MenuProps = {
|
|
306
|
+
menuActions: MenuItem[];
|
|
297
307
|
topLevelItems: Node<any>[];
|
|
298
308
|
pinnedItems: Node<any>[];
|
|
299
309
|
userAccountItem: Node<any>;
|
|
300
310
|
parent?: Node<any>;
|
|
301
311
|
path: string[];
|
|
302
|
-
}
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
export const L0Menu = ({ menuActions, topLevelItems, pinnedItems, userAccountItem, parent, path }: L0MenuProps) => {
|
|
315
|
+
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
316
|
+
|
|
303
317
|
return (
|
|
304
|
-
<Tabs.Tablist
|
|
318
|
+
<Tabs.Tablist
|
|
319
|
+
classNames={[
|
|
320
|
+
'group/l0 absolute z-[1] inset-block-0 inline-start-0 rounded-is-lg',
|
|
321
|
+
'grid grid-cols-[var(--l0-size)] grid-rows-[var(--rail-size)_1fr_min-content_var(--l0-size)] gap-1 contain-layout',
|
|
322
|
+
'!is-[--l0-size] bg-baseSurface border-ie border-subduedSeparator app-drag pbe-[env(safe-area-inset-bottom)]',
|
|
323
|
+
]}
|
|
324
|
+
>
|
|
325
|
+
<div role='none' className='flex justify-center p-1'>
|
|
326
|
+
<MenuProvider>
|
|
327
|
+
<DropdownMenu.Root group={parent} items={menuActions}>
|
|
328
|
+
<DropdownMenu.Trigger asChild>
|
|
329
|
+
{/* TODO(wittjosiah): Use L0Item trigger. */}
|
|
330
|
+
{/* TODO(burdon): Replace with Sigil. */}
|
|
331
|
+
<IconButton
|
|
332
|
+
iconOnly
|
|
333
|
+
icon='ph--dots-three--regular'
|
|
334
|
+
size={5}
|
|
335
|
+
label={t('app menu label')}
|
|
336
|
+
tooltipSide='right'
|
|
337
|
+
classNames='w-[50px] _bg-primary-500'
|
|
338
|
+
data-testid='spacePlugin.addSpace'
|
|
339
|
+
/>
|
|
340
|
+
</DropdownMenu.Trigger>
|
|
341
|
+
</DropdownMenu.Root>
|
|
342
|
+
</MenuProvider>
|
|
343
|
+
</div>
|
|
344
|
+
|
|
305
345
|
<ScrollArea.Root>
|
|
306
346
|
<ScrollArea.Viewport>
|
|
307
347
|
<div
|
|
308
348
|
role='none'
|
|
309
|
-
className=
|
|
349
|
+
className={mx([
|
|
350
|
+
'flex flex-col gap-2 pbs-1',
|
|
351
|
+
'[body[data-platform="darwin"]_&]:pbs-[calc(30px+0.25rem)]',
|
|
352
|
+
'[body[data-platform="ios"]_&]:pbs-[max(env(safe-area-inset-top),0.25rem)]',
|
|
353
|
+
])}
|
|
310
354
|
>
|
|
311
355
|
{topLevelItems.map((item) => {
|
|
312
356
|
if (l0ItemType(item) === 'collection') {
|
|
@@ -321,6 +365,7 @@ export const L0Menu = ({
|
|
|
321
365
|
</ScrollArea.Scrollbar>
|
|
322
366
|
</ScrollArea.Viewport>
|
|
323
367
|
</ScrollArea.Root>
|
|
368
|
+
|
|
324
369
|
<div role='none' className='grid grid-cols-1 auto-rows-[--rail-action] pbs-2'>
|
|
325
370
|
{pinnedItems
|
|
326
371
|
.filter((item) => l0ItemType(item) !== 'collection')
|
|
@@ -328,17 +373,27 @@ export const L0Menu = ({
|
|
|
328
373
|
<L0Item key={item.id} item={item} parent={parent} path={path} pinned />
|
|
329
374
|
))}
|
|
330
375
|
</div>
|
|
376
|
+
|
|
331
377
|
{userAccountItem && (
|
|
332
|
-
<div role='none' className='grid
|
|
333
|
-
<
|
|
378
|
+
<div role='none' className='grid app-no-drag'>
|
|
379
|
+
<L0ItemRoot key={userAccountItem.id} item={userAccountItem} parent={parent} path={path}>
|
|
380
|
+
<UserAccountAvatar
|
|
381
|
+
userId={userAccountItem.properties.userId}
|
|
382
|
+
hue={userAccountItem.properties.hue}
|
|
383
|
+
emoji={userAccountItem.properties.emoji}
|
|
384
|
+
status={userAccountItem.properties.status}
|
|
385
|
+
size={11}
|
|
386
|
+
/>
|
|
387
|
+
</L0ItemRoot>
|
|
334
388
|
</div>
|
|
335
389
|
)}
|
|
390
|
+
|
|
336
391
|
<div
|
|
337
392
|
role='none'
|
|
338
393
|
className='hidden [body[data-platform="darwin"]_&]:block absolute block-start-0 is-[calc(var(--l0-size)-1px)] bs-[calc(40px+0.25rem)]'
|
|
339
394
|
style={{
|
|
340
395
|
background:
|
|
341
|
-
'linear-gradient(to bottom, var(--dx-
|
|
396
|
+
'linear-gradient(to bottom, var(--dx-sidebarSurface) 0%, var(--dx-sidebarSurface) 70%, transparent 100%)',
|
|
342
397
|
}}
|
|
343
398
|
/>
|
|
344
399
|
</Tabs.Tablist>
|