@dxos/plugin-navtree 0.8.2-main.2f9c567 → 0.8.2-main.30e4dbb
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-FBQKXPOR.mjs → chunk-ZULGSU3L.mjs} +239 -204
- package/dist/lib/browser/chunk-ZULGSU3L.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +2 -2
- package/dist/lib/browser/index.mjs.map +2 -2
- package/dist/lib/browser/{keyboard-IQXHKUWM.mjs → keyboard-2KXRP22I.mjs} +2 -2
- package/dist/lib/browser/{keyboard-IQXHKUWM.mjs.map → keyboard-2KXRP22I.mjs.map} +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-FQEYRV4Q.mjs → react-surface-BVZN7664.mjs} +2 -2
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- 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/keyboard.d.ts.map +1 -1
- 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} +2 -3
- 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/{NavTreeItemColumns.d.ts → NavTreeItem/NavTreeItemColumns.d.ts} +1 -1
- 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 +14 -15
- 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 +11 -0
- package/dist/types/src/testing/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/testing/generator.d.ts +1 -0
- 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 -1
- package/dist/types/src/util.d.ts +1 -1
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -31
- package/src/capabilities/keyboard.ts +1 -1
- package/src/components/{CommandsDialog.tsx → CommandsDialog/CommandsDialog.tsx} +2 -2
- 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 +87 -0
- package/src/components/{NavTree.tsx → NavTree/NavTree.tsx} +24 -11
- package/src/components/NavTree/index.ts +5 -0
- package/src/components/NavTreeContainer.tsx +35 -16
- 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} +13 -14
- package/src/components/{NavTreeItemColumns.tsx → NavTreeItem/NavTreeItemColumns.tsx} +5 -5
- package/src/components/NavTreeItem/index.ts +6 -0
- package/src/components/{L0Menu.tsx → Sidebar/L0Menu.tsx} +182 -129
- package/src/components/{L1Panels.tsx → Sidebar/L1Panel.tsx} +29 -48
- 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} +6 -6
- package/src/components/UserAccountAvatar/index.ts +5 -0
- package/src/components/index.ts +0 -1
- package/src/components/types.ts +13 -15
- package/src/testing/app-graph-builder.ts +158 -0
- package/src/testing/generator.ts +2 -1
- package/src/testing/index.ts +1 -0
- package/src/translations.ts +1 -1
- package/dist/lib/browser/chunk-FBQKXPOR.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.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/NavTree.stories.tsx +0 -107
- package/src/stories/Graph.stories.tsx +0 -130
- package/src/stories/StorybookNavTree.tsx +0 -63
- /package/dist/lib/browser/{react-surface-FQEYRV4Q.mjs.map → react-surface-BVZN7664.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
|
@@ -9,8 +9,8 @@ import { useTranslation, toLocalizedString, IconButton, useDensityContext } from
|
|
|
9
9
|
import { DropdownMenu, MenuProvider, type MenuItem } from '@dxos/react-ui-menu';
|
|
10
10
|
import { hoverableControlItem, hoverableOpenControlItem, mx } from '@dxos/react-ui-theme';
|
|
11
11
|
|
|
12
|
-
import { NAVTREE_PLUGIN } from '
|
|
13
|
-
import { type ActionProperties } from '
|
|
12
|
+
import { NAVTREE_PLUGIN } from '../../meta';
|
|
13
|
+
import { type ActionProperties } from '../../types';
|
|
14
14
|
|
|
15
15
|
export type NavTreeItemActionMenuProps = ActionProperties & {
|
|
16
16
|
parent: Node;
|
|
@@ -18,7 +18,6 @@ export type NavTreeItemActionMenuProps = ActionProperties & {
|
|
|
18
18
|
monolithic?: boolean;
|
|
19
19
|
menuActions?: Action[];
|
|
20
20
|
suppressNextTooltip?: MutableRefObject<boolean>;
|
|
21
|
-
onAction?: (action: Action) => void;
|
|
22
21
|
};
|
|
23
22
|
|
|
24
23
|
const fallbackIcon = 'ph--placeholder--regular';
|
|
@@ -33,18 +32,24 @@ const coarseActionButtonProps = {
|
|
|
33
32
|
};
|
|
34
33
|
|
|
35
34
|
export const NavTreeItemActionDropdownMenu = ({
|
|
35
|
+
parent,
|
|
36
36
|
label,
|
|
37
37
|
icon,
|
|
38
38
|
testId,
|
|
39
39
|
menuActions,
|
|
40
|
-
|
|
40
|
+
caller,
|
|
41
41
|
}: NavTreeItemActionMenuProps) => {
|
|
42
42
|
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
43
43
|
const suppressNextTooltip = useRef<boolean>(false);
|
|
44
44
|
const density = useDensityContext();
|
|
45
45
|
return (
|
|
46
|
-
<MenuProvider
|
|
47
|
-
<DropdownMenu.Root
|
|
46
|
+
<MenuProvider>
|
|
47
|
+
<DropdownMenu.Root
|
|
48
|
+
group={parent}
|
|
49
|
+
items={menuActions as MenuItem[]}
|
|
50
|
+
caller={caller}
|
|
51
|
+
suppressNextTooltip={suppressNextTooltip}
|
|
52
|
+
>
|
|
48
53
|
<DropdownMenu.Trigger asChild>
|
|
49
54
|
<IconButton
|
|
50
55
|
{...(density === 'coarse' ? coarseActionButtonProps : fineActionButtonProps)}
|
|
@@ -88,7 +93,7 @@ export const NavTreeItemMonolithicAction = ({
|
|
|
88
93
|
return;
|
|
89
94
|
}
|
|
90
95
|
event.stopPropagation();
|
|
91
|
-
void invoke?.(caller ? {
|
|
96
|
+
void invoke?.(caller ? { parent, caller } : { parent });
|
|
92
97
|
}}
|
|
93
98
|
data-testid={testId}
|
|
94
99
|
/>
|
|
@@ -104,12 +109,6 @@ export const NavTreeItemAction = ({ monolithic, menuActions, parent: node, ...pr
|
|
|
104
109
|
return monolithic && menuActions?.length === 1 ? (
|
|
105
110
|
<NavTreeItemMonolithicAction baseLabel={baseLabel} parent={node} {...menuActions[0]} />
|
|
106
111
|
) : (
|
|
107
|
-
<NavTreeItemActionDropdownMenu
|
|
108
|
-
{...props}
|
|
109
|
-
label={baseLabel}
|
|
110
|
-
parent={node}
|
|
111
|
-
menuActions={menuActions}
|
|
112
|
-
onAction={(action) => action.data?.(props.caller ? { node, caller: props.caller } : { node })}
|
|
113
|
-
/>
|
|
112
|
+
<NavTreeItemActionDropdownMenu {...props} label={baseLabel} parent={node} menuActions={menuActions} />
|
|
114
113
|
);
|
|
115
114
|
};
|
|
@@ -7,12 +7,12 @@ import React, { Fragment, memo } from 'react';
|
|
|
7
7
|
import { isAction } from '@dxos/app-graph';
|
|
8
8
|
import { DensityProvider, Popover, toLocalizedString, Treegrid, useTranslation } from '@dxos/react-ui';
|
|
9
9
|
|
|
10
|
-
import { NAV_TREE_ITEM } from './NavTree';
|
|
11
|
-
import { useNavTreeContext } from './NavTreeContext';
|
|
12
10
|
import { NavTreeItemAction } from './NavTreeItemAction';
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
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
16
|
|
|
17
17
|
export const NavTreeItemColumns = memo(({ path, item, open, density = 'fine' }: NavTreeItemColumnsProps) => {
|
|
18
18
|
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
@@ -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,77 +222,40 @@ 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-groupSurface'
|
|
235
|
+
: 'bg-groupSurface 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
261
|
const collectionItems = navTreeContext.getItems(item);
|
|
@@ -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,57 @@ 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-separator 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
|
+
classNames='w-[50px] _bg-primary-500'
|
|
337
|
+
/>
|
|
338
|
+
</DropdownMenu.Trigger>
|
|
339
|
+
</DropdownMenu.Root>
|
|
340
|
+
</MenuProvider>
|
|
341
|
+
</div>
|
|
342
|
+
|
|
305
343
|
<ScrollArea.Root>
|
|
306
344
|
<ScrollArea.Viewport>
|
|
307
345
|
<div
|
|
308
346
|
role='none'
|
|
309
|
-
className=
|
|
347
|
+
className={mx([
|
|
348
|
+
'flex flex-col gap-2',
|
|
349
|
+
'[body[data-platform="darwin"]_&]:pbs-[calc(30px+0.25rem)]',
|
|
350
|
+
'[body[data-platform="ios"]_&]:pbs-[max(env(safe-area-inset-top),0.25rem)]',
|
|
351
|
+
])}
|
|
310
352
|
>
|
|
311
353
|
{topLevelItems.map((item) => {
|
|
312
354
|
if (l0ItemType(item) === 'collection') {
|
|
@@ -321,6 +363,7 @@ export const L0Menu = ({
|
|
|
321
363
|
</ScrollArea.Scrollbar>
|
|
322
364
|
</ScrollArea.Viewport>
|
|
323
365
|
</ScrollArea.Root>
|
|
366
|
+
|
|
324
367
|
<div role='none' className='grid grid-cols-1 auto-rows-[--rail-action] pbs-2'>
|
|
325
368
|
{pinnedItems
|
|
326
369
|
.filter((item) => l0ItemType(item) !== 'collection')
|
|
@@ -328,11 +371,21 @@ export const L0Menu = ({
|
|
|
328
371
|
<L0Item key={item.id} item={item} parent={parent} path={path} pinned />
|
|
329
372
|
))}
|
|
330
373
|
</div>
|
|
374
|
+
|
|
331
375
|
{userAccountItem && (
|
|
332
|
-
<div role='none' className='grid
|
|
333
|
-
<
|
|
376
|
+
<div role='none' className='grid app-no-drag'>
|
|
377
|
+
<L0ItemRoot key={userAccountItem.id} item={userAccountItem} parent={parent} path={path}>
|
|
378
|
+
<UserAccountAvatar
|
|
379
|
+
userId={userAccountItem.properties.userId}
|
|
380
|
+
hue={userAccountItem.properties.hue}
|
|
381
|
+
emoji={userAccountItem.properties.emoji}
|
|
382
|
+
status={userAccountItem.properties.status}
|
|
383
|
+
size={11}
|
|
384
|
+
/>
|
|
385
|
+
</L0ItemRoot>
|
|
334
386
|
</div>
|
|
335
387
|
)}
|
|
388
|
+
|
|
336
389
|
<div
|
|
337
390
|
role='none'
|
|
338
391
|
className='hidden [body[data-platform="darwin"]_&]:block absolute block-start-0 is-[calc(var(--l0-size)-1px)] bs-[calc(40px+0.25rem)]'
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useCallback, useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import { useLayout } from '@dxos/app-framework';
|
|
8
7
|
import { type Node } from '@dxos/app-graph';
|
|
9
8
|
import { Button, type ButtonProps, Icon, IconButton, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
10
9
|
import { Tree } from '@dxos/react-ui-list';
|
|
@@ -12,24 +11,16 @@ import { Tabs } from '@dxos/react-ui-tabs';
|
|
|
12
11
|
import { hoverableControlItem, hoverableOpenControlItem, mx } from '@dxos/react-ui-theme';
|
|
13
12
|
import { byPosition } from '@dxos/util';
|
|
14
13
|
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
14
|
+
import { useLoadDescendents } from '../../hooks';
|
|
15
|
+
import { NAVTREE_PLUGIN } from '../../meta';
|
|
16
|
+
import { l0ItemType } from '../../util';
|
|
17
|
+
import { useNavTreeContext } from '../NavTreeContext';
|
|
18
|
+
import { NavTreeItemColumns } from '../NavTreeItem';
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
item: Node<any>;
|
|
23
|
-
path: string[];
|
|
24
|
-
currentItemId: string;
|
|
25
|
-
onBack?: () => void;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const headingBackButtonLabel =
|
|
29
|
-
'absolute inset-0 min-is-0 truncate flex items-center pis-6 transition-[transform,opacity] ease-in-out duration-200';
|
|
20
|
+
const headingBackButtonLabel = 'absolute inset-0 min-is-0 truncate flex items-center pis-6';
|
|
30
21
|
|
|
22
|
+
// TODO(burdon): Figure out better L1 back navigation.
|
|
31
23
|
const HeadingBackButton = ({ title, onClick }: { title: string } & Pick<ButtonProps, 'onClick'>) => {
|
|
32
|
-
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
33
24
|
return (
|
|
34
25
|
<Button
|
|
35
26
|
variant='ghost'
|
|
@@ -37,28 +28,20 @@ const HeadingBackButton = ({ title, onClick }: { title: string } & Pick<ButtonPr
|
|
|
37
28
|
onClick={onClick}
|
|
38
29
|
>
|
|
39
30
|
<Icon icon='ph--caret-left--bold' size={3} />
|
|
40
|
-
<span
|
|
41
|
-
className={mx(
|
|
42
|
-
headingBackButtonLabel,
|
|
43
|
-
'translate-y-2 opacity-0 group-hover:translate-y-0 group-hover:opacity-100 group-focus:translate-y-0 group-focus:opacity-100',
|
|
44
|
-
)}
|
|
45
|
-
>
|
|
46
|
-
{t('back label')}
|
|
47
|
-
</span>
|
|
48
|
-
<span
|
|
49
|
-
className={mx(
|
|
50
|
-
headingBackButtonLabel,
|
|
51
|
-
'translate-y-0 opacity-100 group-hover:-translate-y-2 group-hover:opacity-0 group-focus:-translate-y-2 group-focus:opacity-0',
|
|
52
|
-
)}
|
|
53
|
-
>
|
|
54
|
-
{title}
|
|
55
|
-
</span>
|
|
31
|
+
<span className={mx(headingBackButtonLabel)}>{title}</span>
|
|
56
32
|
</Button>
|
|
57
33
|
);
|
|
58
34
|
};
|
|
59
35
|
|
|
60
|
-
|
|
61
|
-
|
|
36
|
+
export type L1PanelProps = {
|
|
37
|
+
open?: boolean;
|
|
38
|
+
item: Node<any>;
|
|
39
|
+
path: string[];
|
|
40
|
+
currentItemId: string;
|
|
41
|
+
onBack?: () => void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const L1Panel = ({ open, item, path, currentItemId, onBack }: L1PanelProps) => {
|
|
62
45
|
const { isAlternateTree, setAlternateTree, ...navTreeContext } = useNavTreeContext();
|
|
63
46
|
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
64
47
|
|
|
@@ -95,12 +78,14 @@ const L1Panel = ({ item, path, currentItemId, onBack }: L1PanelProps) => {
|
|
|
95
78
|
key={item.id}
|
|
96
79
|
value={item.id}
|
|
97
80
|
classNames={[
|
|
98
|
-
'absolute inset-block-0 inline-end-0
|
|
81
|
+
'absolute inset-block-0 inline-end-0',
|
|
82
|
+
'is-[calc(100%-var(--l0-size))] lg:is-[--l1-size] grid-cols-1 grid-rows-[var(--rail-size)_1fr]',
|
|
83
|
+
'pbs-[env(safe-area-inset-top)]',
|
|
99
84
|
item.id === currentItemId && 'grid',
|
|
100
85
|
]}
|
|
101
86
|
tabIndex={-1}
|
|
102
87
|
aria-label={title}
|
|
103
|
-
{...(!
|
|
88
|
+
{...(!open && { inert: 'true' })}
|
|
104
89
|
>
|
|
105
90
|
{item.id === currentItemId && (
|
|
106
91
|
<>
|
|
@@ -156,7 +141,7 @@ const L1Panel = ({ item, path, currentItemId, onBack }: L1PanelProps) => {
|
|
|
156
141
|
);
|
|
157
142
|
};
|
|
158
143
|
|
|
159
|
-
const L1PanelCollection = ({ item, path,
|
|
144
|
+
const L1PanelCollection = ({ item, path, ...props }: L1PanelProps) => {
|
|
160
145
|
const { getItems } = useNavTreeContext();
|
|
161
146
|
useLoadDescendents(item);
|
|
162
147
|
const collectionItems = getItems(item);
|
|
@@ -166,31 +151,27 @@ const L1PanelCollection = ({ item, path, currentItemId }: L1PanelProps) => {
|
|
|
166
151
|
{collectionItems
|
|
167
152
|
.filter((item) => l0ItemType(item) === 'tab')
|
|
168
153
|
.map((item) => (
|
|
169
|
-
<L1Panel key={item.id} item={item} path={groupPath}
|
|
154
|
+
<L1Panel key={item.id} item={item} path={groupPath} {...props} />
|
|
170
155
|
))}
|
|
171
156
|
</>
|
|
172
157
|
);
|
|
173
158
|
};
|
|
174
159
|
|
|
175
|
-
export
|
|
176
|
-
topLevelItems,
|
|
177
|
-
path,
|
|
178
|
-
currentItemId,
|
|
179
|
-
onBack,
|
|
180
|
-
}: Pick<L1PanelProps, 'onBack'> & {
|
|
160
|
+
export type L1PanelsProps = Pick<L1PanelProps, 'open' | 'currentItemId' | 'onBack'> & {
|
|
181
161
|
topLevelItems: Node<any>[];
|
|
182
162
|
path: string[];
|
|
183
|
-
|
|
184
|
-
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export const L1Panels = ({ topLevelItems, onBack, ...props }: L1PanelsProps) => {
|
|
185
166
|
return (
|
|
186
167
|
<>
|
|
187
168
|
{topLevelItems.map((item) => {
|
|
188
169
|
const type = l0ItemType(item);
|
|
189
170
|
switch (type) {
|
|
190
171
|
case 'collection':
|
|
191
|
-
return <L1PanelCollection key={item.id} item={item}
|
|
172
|
+
return <L1PanelCollection key={item.id} item={item} {...props} />;
|
|
192
173
|
case 'tab':
|
|
193
|
-
return <L1Panel key={item.id} item={item}
|
|
174
|
+
return <L1Panel key={item.id} item={item} {...props} onBack={onBack} />;
|
|
194
175
|
default:
|
|
195
176
|
return null;
|
|
196
177
|
}
|