@antscorp/antsomi-ui 2.0.84 → 2.0.86-text-editor-beta.1
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/es/assets/css/main.scss +4 -2
- package/es/components/index.scss +2 -0
- package/es/components/molecules/EmojiPopover/EmojiPopover.js +5 -1
- package/es/components/molecules/FontSizeInput/FontSizeInput.d.ts +3 -0
- package/es/components/molecules/FontSizeInput/FontSizeInput.js +128 -0
- package/es/components/molecules/FontSizeInput/components/FontSizeControl.d.ts +8 -0
- package/es/components/molecules/FontSizeInput/components/FontSizeControl.js +14 -0
- package/es/components/molecules/FontSizeInput/components/FontSizeDropdown.d.ts +20 -0
- package/es/components/molecules/FontSizeInput/components/FontSizeDropdown.js +17 -0
- package/es/components/molecules/FontSizeInput/constants.d.ts +2 -0
- package/es/components/molecules/FontSizeInput/constants.js +5 -0
- package/es/components/molecules/FontSizeInput/index.d.ts +2 -0
- package/es/components/molecules/FontSizeInput/index.js +1 -0
- package/es/components/molecules/FontSizeInput/styled.d.ts +3 -0
- package/es/components/molecules/FontSizeInput/styled.js +22 -0
- package/es/components/molecules/FontSizeInput/styles.scss +15 -0
- package/es/components/molecules/FontSizeInput/types.d.ts +24 -0
- package/es/components/molecules/FontSizeInput/types.js +1 -0
- package/es/components/molecules/FontSizeInput/utils.d.ts +7 -0
- package/es/components/molecules/FontSizeInput/utils.js +9 -0
- package/es/components/molecules/TagifyInput/TagifyInput.js +20 -14
- package/es/components/molecules/TagifyInput/utils.d.ts +10 -1
- package/es/components/molecules/TagifyInput/utils.js +64 -6
- package/es/components/molecules/VirtualizedMenu/VirtualizedMenu.d.ts +6 -3
- package/es/components/molecules/VirtualizedMenu/__mocks__/index.js +2550 -938
- package/es/components/molecules/VirtualizedMenu/components/Item/Item.d.ts +13 -3
- package/es/components/molecules/VirtualizedMenu/components/Item/Item.js +53 -25
- package/es/components/molecules/VirtualizedMenu/components/Item/index.d.ts +1 -1
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.d.ts +8 -5
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.js +289 -46
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.js +1 -0
- package/es/components/molecules/VirtualizedMenu/styled.d.ts +1 -1
- package/es/components/molecules/VirtualizedMenu/styled.js +23 -4
- package/es/components/molecules/VirtualizedMenu/types.d.ts +6 -9
- package/es/components/molecules/VirtualizedMenu/utils.d.ts +8 -5
- package/es/components/molecules/VirtualizedMenu/utils.js +13 -18
- package/es/components/molecules/index.d.ts +1 -0
- package/es/components/molecules/index.js +1 -0
- package/es/components/molecules/index.scss +1 -0
- package/es/components/organism/ActivityTimeline/__mocks__/event_tracking.json +1290 -0
- package/es/components/organism/ActivityTimeline/__mocks__/timeline.json +3059 -0
- package/es/components/organism/TextEditor/TextEditor.d.ts +3 -0
- package/es/components/organism/TextEditor/TextEditor.js +251 -0
- package/es/components/organism/TextEditor/__mocks__/text-block.settings.json +320 -0
- package/es/components/organism/TextEditor/__mocks__/text-contennt.d.ts +1 -0
- package/es/components/organism/TextEditor/__mocks__/text-contennt.js +38 -0
- package/es/components/organism/TextEditor/constants.d.ts +135 -0
- package/es/components/organism/TextEditor/constants.js +280 -0
- package/es/components/organism/TextEditor/extensions/BackgroundColor.d.ts +25 -0
- package/es/components/organism/TextEditor/extensions/BackgroundColor.js +46 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.d.ts +130 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.js +247 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.d.ts +15 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.js +31 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/index.d.ts +2 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/index.js +2 -0
- package/es/components/organism/TextEditor/extensions/Color.d.ts +6 -0
- package/es/components/organism/TextEditor/extensions/Color.js +41 -0
- package/es/components/organism/TextEditor/extensions/Emoji.d.ts +57 -0
- package/es/components/organism/TextEditor/extensions/Emoji.js +184 -0
- package/es/components/organism/TextEditor/extensions/FontFamily.d.ts +6 -0
- package/es/components/organism/TextEditor/extensions/FontFamily.js +43 -0
- package/es/components/organism/TextEditor/extensions/FontSize.d.ts +32 -0
- package/es/components/organism/TextEditor/extensions/FontSize.js +47 -0
- package/es/components/organism/TextEditor/extensions/FontWeight.d.ts +23 -0
- package/es/components/organism/TextEditor/extensions/FontWeight.js +41 -0
- package/es/components/organism/TextEditor/extensions/Highlight.d.ts +1 -0
- package/es/components/organism/TextEditor/extensions/Highlight.js +14 -0
- package/es/components/organism/TextEditor/extensions/Indent.d.ts +28 -0
- package/es/components/organism/TextEditor/extensions/Indent.js +68 -0
- package/es/components/organism/TextEditor/extensions/LineHeight.d.ts +20 -0
- package/es/components/organism/TextEditor/extensions/LineHeight.js +36 -0
- package/es/components/organism/TextEditor/extensions/Link.d.ts +15 -0
- package/es/components/organism/TextEditor/extensions/Link.js +50 -0
- package/es/components/organism/TextEditor/extensions/ListItemMarker.d.ts +13 -0
- package/es/components/organism/TextEditor/extensions/ListItemMarker.js +174 -0
- package/es/components/organism/TextEditor/extensions/Selection.d.ts +6 -0
- package/es/components/organism/TextEditor/extensions/Selection.js +40 -0
- package/es/components/organism/TextEditor/extensions/SmartTag.d.ts +39 -0
- package/es/components/organism/TextEditor/extensions/SmartTag.js +167 -0
- package/es/components/organism/TextEditor/extensions/StyleMemory.d.ts +36 -0
- package/es/components/organism/TextEditor/extensions/StyleMemory.js +163 -0
- package/es/components/organism/TextEditor/extensions/TextTransform.d.ts +31 -0
- package/es/components/organism/TextEditor/extensions/TextTransform.js +37 -0
- package/es/components/organism/TextEditor/hooks/index.d.ts +6 -0
- package/es/components/organism/TextEditor/hooks/index.js +6 -0
- package/es/components/organism/TextEditor/hooks/useDocumentState.d.ts +18 -0
- package/es/components/organism/TextEditor/hooks/useDocumentState.js +42 -0
- package/es/components/organism/TextEditor/hooks/useLinkHandler.d.ts +10 -0
- package/es/components/organism/TextEditor/hooks/useLinkHandler.js +223 -0
- package/es/components/organism/TextEditor/hooks/useMarkTracking.d.ts +26 -0
- package/es/components/organism/TextEditor/hooks/useMarkTracking.js +68 -0
- package/es/components/organism/TextEditor/hooks/usePersistence.d.ts +31 -0
- package/es/components/organism/TextEditor/hooks/usePersistence.js +169 -0
- package/es/components/organism/TextEditor/hooks/useStyleMemory.d.ts +6 -0
- package/es/components/organism/TextEditor/hooks/useStyleMemory.js +42 -0
- package/es/components/organism/TextEditor/hooks/useStylePresets.d.ts +34 -0
- package/es/components/organism/TextEditor/hooks/useStylePresets.js +83 -0
- package/es/components/organism/TextEditor/index.d.ts +14 -0
- package/es/components/organism/TextEditor/index.js +6 -0
- package/es/components/organism/TextEditor/index.scss +61 -0
- package/es/components/organism/TextEditor/provider.d.ts +10 -0
- package/es/components/organism/TextEditor/provider.js +20 -0
- package/es/components/organism/TextEditor/store.d.ts +11 -0
- package/es/components/organism/TextEditor/store.js +12 -0
- package/es/components/organism/TextEditor/styled.d.ts +8 -0
- package/es/components/organism/TextEditor/styled.js +90 -0
- package/es/components/organism/TextEditor/types.d.ts +92 -0
- package/es/components/organism/TextEditor/types.js +1 -0
- package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.js +78 -0
- package/es/components/organism/TextEditor/ui/BubbleMenu/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/BubbleMenu/index.js +1 -0
- package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.d.ts +43 -0
- package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.js +120 -0
- package/es/components/organism/TextEditor/ui/ColorPicker/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/ColorPicker/index.js +1 -0
- package/es/components/organism/TextEditor/ui/Emoji/EmojiList.d.ts +11 -0
- package/es/components/organism/TextEditor/ui/Emoji/EmojiList.js +66 -0
- package/es/components/organism/TextEditor/ui/Emoji/index.d.ts +2 -0
- package/es/components/organism/TextEditor/ui/Emoji/index.js +2 -0
- package/es/components/organism/TextEditor/ui/Emoji/suggestion.d.ts +4 -0
- package/es/components/organism/TextEditor/ui/Emoji/suggestion.js +71 -0
- package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.d.ts +12 -0
- package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.js +69 -0
- package/es/components/organism/TextEditor/ui/FontPopover/styled.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/FontPopover/styled.js +20 -0
- package/es/components/organism/TextEditor/ui/Popover/Popover.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/Popover/Popover.js +7 -0
- package/es/components/organism/TextEditor/ui/Popover/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/Popover/index.js +1 -0
- package/es/components/organism/TextEditor/ui/Select/Select.d.ts +4 -0
- package/es/components/organism/TextEditor/ui/Select/Select.js +7 -0
- package/es/components/organism/TextEditor/ui/Select/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/Select/index.js +1 -0
- package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.d.ts +30 -0
- package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.js +49 -0
- package/es/components/organism/TextEditor/ui/TextAlignSelect/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/TextAlignSelect/index.js +1 -0
- package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.d.ts +14 -0
- package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.js +42 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.js +18 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.d.ts +4 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.js +13 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.d.ts +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.js +18 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.d.ts +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.js +37 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.js +4 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.d.ts +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.js +9 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.d.ts +9 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.js +22 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.js +13 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.js +13 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.js +3 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.d.ts +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.js +19 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.d.ts +15 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.js +14 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.js +30 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.js +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.js +10 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/index.d.ts +20 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/index.js +20 -0
- package/es/components/organism/TextEditor/ui/Toolbar/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/Toolbar/index.js +1 -0
- package/es/components/organism/TextEditor/utils/documentState.d.ts +57 -0
- package/es/components/organism/TextEditor/utils/documentState.js +100 -0
- package/es/components/organism/TextEditor/utils/font.d.ts +84 -0
- package/es/components/organism/TextEditor/utils/font.js +175 -0
- package/es/components/organism/TextEditor/utils/htmlProcessing.d.ts +63 -0
- package/es/components/organism/TextEditor/utils/htmlProcessing.js +321 -0
- package/es/components/organism/TextEditor/utils/index.d.ts +8 -0
- package/es/components/organism/TextEditor/utils/index.js +16 -0
- package/es/components/organism/TextEditor/utils/link.d.ts +100 -0
- package/es/components/organism/TextEditor/utils/link.js +149 -0
- package/es/components/organism/TextEditor/utils/menu.d.ts +134 -0
- package/es/components/organism/TextEditor/utils/menu.js +317 -0
- package/es/components/organism/TextEditor/utils/selection.d.ts +25 -0
- package/es/components/organism/TextEditor/utils/selection.js +57 -0
- package/es/components/organism/TextEditor/utils/smartTag.d.ts +49 -0
- package/es/components/organism/TextEditor/utils/smartTag.js +89 -0
- package/es/components/organism/TextEditor/utils/style.d.ts +78 -0
- package/es/components/organism/TextEditor/utils/style.js +193 -0
- package/es/components/organism/index.d.ts +1 -0
- package/es/components/organism/index.js +1 -0
- package/es/components/organism/index.scss +1 -0
- package/es/config/index.d.ts +1 -0
- package/es/config/index.js +1 -0
- package/es/constants/api.d.ts +10 -0
- package/es/constants/api.js +10 -0
- package/es/hooks/index.d.ts +1 -0
- package/es/hooks/index.js +1 -0
- package/es/hooks/useBroadcastedLocalStorage.d.ts +5 -0
- package/es/hooks/useBroadcastedLocalStorage.js +71 -0
- package/es/hooks/useElementSize.d.ts +7 -0
- package/es/hooks/useElementSize.js +56 -0
- package/es/utils/common.d.ts +6 -9
- package/es/utils/common.js +44 -23
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +1 -0
- package/es/utils/tree.d.ts +225 -0
- package/es/utils/tree.js +469 -0
- package/es/utils/web.d.ts +4 -0
- package/es/utils/web.js +25 -0
- package/package.json +29 -3
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ItemType, MenuInlineProps
|
|
2
|
+
import { ItemType, MenuInlineProps } from '../../types';
|
|
3
3
|
import { ListChildComponentProps } from 'react-window';
|
|
4
|
+
import { NormalizedNode } from '@antscorp/antsomi-ui/es/utils/tree';
|
|
4
5
|
export type MemoryData = {
|
|
5
6
|
itemSpacing: number;
|
|
6
7
|
inlineIndent: number;
|
|
7
8
|
inlinePadding: number;
|
|
8
|
-
items: SerializedItemType[];
|
|
9
9
|
selectedKeys: Set<string>;
|
|
10
10
|
expandedKeys: Set<string>;
|
|
11
|
+
items: NormalizedNode<ItemType & {
|
|
12
|
+
ref: (el: HTMLLIElement) => void;
|
|
13
|
+
}>[];
|
|
14
|
+
normalizeTreeItems: Map<string, NormalizedNode<ItemType>>;
|
|
11
15
|
action: MenuInlineProps['action'];
|
|
12
|
-
|
|
16
|
+
focusId: string | null;
|
|
17
|
+
onClick: (args: {
|
|
18
|
+
item: NormalizedNode<ItemType>;
|
|
19
|
+
index: number;
|
|
20
|
+
elKey: 'item' | 'item-expand-el';
|
|
21
|
+
domEvent: React.MouseEvent;
|
|
22
|
+
}) => void;
|
|
13
23
|
};
|
|
14
24
|
export declare const Item: React.MemoExoticComponent<(props: ListChildComponentProps<MemoryData>) => import("react/jsx-runtime").JSX.Element>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { memo } from 'react';
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useMemo, useRef, useEffect, useCallback } from 'react';
|
|
3
3
|
import { Typography } from '../../../../atoms/Typography';
|
|
4
4
|
import { MenuItemRoot } from '../../styled';
|
|
5
5
|
import clsx from 'clsx';
|
|
@@ -8,11 +8,18 @@ import { isEmpty } from 'lodash';
|
|
|
8
8
|
import { CLS } from '../../utils';
|
|
9
9
|
import { ExpandMoreIcon } from '@antscorp/antsomi-ui/es/components/icons';
|
|
10
10
|
import { globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
11
|
+
import { isDescendant } from '@antscorp/antsomi-ui/es/utils/tree';
|
|
11
12
|
export const Item = memo((props) => {
|
|
12
13
|
const { style = {}, data, index = 0 } = props;
|
|
13
|
-
const { inlineIndent, itemSpacing, inlinePadding, items, selectedKeys, expandedKeys, action, onClick, } = data || {};
|
|
14
|
+
const { inlineIndent, itemSpacing, inlinePadding, items, selectedKeys, expandedKeys, normalizeTreeItems, action, focusId, onClick, } = data || {};
|
|
15
|
+
const itemRef = useRef(null);
|
|
14
16
|
const item = items[index];
|
|
15
|
-
const
|
|
17
|
+
const hasChildren = !isEmpty(item.data.children);
|
|
18
|
+
const isFocused = item.id === focusId;
|
|
19
|
+
const expanded = hasChildren && expandedKeys.has(item.data.key);
|
|
20
|
+
const selected = selectedKeys.has(item.data.key);
|
|
21
|
+
const disabled = item.data?.disabled;
|
|
22
|
+
const indentSize = item.level * inlineIndent;
|
|
16
23
|
const itemStyle = {
|
|
17
24
|
...style,
|
|
18
25
|
paddingLeft: indentSize + inlinePadding,
|
|
@@ -21,29 +28,50 @@ export const Item = memo((props) => {
|
|
|
21
28
|
height: index === 0 ? Number(style.height) : Number(style.height) - itemSpacing,
|
|
22
29
|
};
|
|
23
30
|
const itemClassName = clsx(CLS.Item.default, {
|
|
24
|
-
[CLS.Item.selected]:
|
|
25
|
-
[CLS.Item.expanded]:
|
|
26
|
-
[CLS.Item.disabled]:
|
|
27
|
-
}, item.className);
|
|
28
|
-
const
|
|
29
|
-
if (!
|
|
31
|
+
[CLS.Item.selected]: selected,
|
|
32
|
+
[CLS.Item.expanded]: expanded,
|
|
33
|
+
[CLS.Item.disabled]: disabled,
|
|
34
|
+
}, item.data.className);
|
|
35
|
+
const handleItemRef = useCallback((el) => {
|
|
36
|
+
if (!el)
|
|
30
37
|
return;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
itemRef.current = el;
|
|
39
|
+
item.data.ref(el);
|
|
40
|
+
}, [item.data]);
|
|
41
|
+
const handleOnClick = (event, elKey) => {
|
|
42
|
+
if (!onClick || disabled)
|
|
43
|
+
return;
|
|
44
|
+
onClick({ item, index, elKey, domEvent: event });
|
|
38
45
|
};
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
const labelContent = typeof item.data?.label === 'string' ? (_jsx(Typography.Text, { ellipsis: {
|
|
47
|
+
tooltip: {
|
|
48
|
+
destroyTooltipOnHide: true,
|
|
49
|
+
},
|
|
50
|
+
}, children: item.data.label })) : (item.data?.label);
|
|
51
|
+
const expandEl = (_jsx(ExpandMoreIcon, { size: 20, "aria-hidden": "true", color: globalToken?.colorIcon, className: CLS.IconExpand.default, onClick: e => {
|
|
52
|
+
e.stopPropagation();
|
|
53
|
+
handleOnClick(e, 'item-expand-el');
|
|
54
|
+
} }));
|
|
55
|
+
let actionContent = hasChildren ? _jsx("div", { className: CLS.ItemAction.default, children: expandEl }) : null;
|
|
56
|
+
if (action) {
|
|
57
|
+
actionContent = (_jsx("div", { className: CLS.ItemAction.default, children: typeof action === 'function' ? (action(item.data, { expandEl })) : (_jsxs(_Fragment, { children: [expandEl, action] })) }));
|
|
58
|
+
}
|
|
59
|
+
const isSelectedDescendant = useMemo(() => {
|
|
60
|
+
let result = false;
|
|
61
|
+
for (const selectedKey of selectedKeys) {
|
|
62
|
+
if (result)
|
|
63
|
+
break;
|
|
64
|
+
result = isDescendant(item.id, selectedKey, normalizeTreeItems);
|
|
42
65
|
}
|
|
43
|
-
|
|
44
|
-
|
|
66
|
+
return result;
|
|
67
|
+
}, [item.id, normalizeTreeItems, selectedKeys]);
|
|
68
|
+
const className = clsx(itemClassName, {
|
|
69
|
+
[CLS.Item.selectedDescendant]: isSelectedDescendant,
|
|
70
|
+
});
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (isFocused) {
|
|
73
|
+
itemRef.current?.focus({ preventScroll: true });
|
|
45
74
|
}
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
return (_jsxs(MenuItemRoot, { className: itemClassName, style: itemStyle, onClick: handleOnClick, children: [_jsx("div", { className: CLS.ItemLabel.default, children: renderLabel() }), renderAction()] }));
|
|
75
|
+
}, [isFocused]);
|
|
76
|
+
return (_jsxs(MenuItemRoot, { ref: handleItemRef, role: "treeitem", tabIndex: isFocused ? 0 : -1, "aria-selected": selected, "aria-disabled": disabled, "aria-expanded": expanded, "aria-level": item.level, "aria-posinset": index + 1, "aria-setsize": items.length, className: className, style: itemStyle, onClick: e => handleOnClick(e, 'item'), children: [_jsx("div", { className: CLS.ItemLabel.default, children: labelContent }), actionContent] }));
|
|
49
77
|
}, areEqual);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Item } from './Item';
|
|
1
|
+
export { Item, type MemoryData } from './Item';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ItemType } from '../../types';
|
|
3
|
-
export declare const MenuInline: React.ForwardRefExoticComponent<Partial<{
|
|
3
|
+
export declare const MenuInline: React.MemoExoticComponent<React.ForwardRefExoticComponent<Partial<{
|
|
4
4
|
items: ItemType[];
|
|
5
5
|
inlineIndent: number;
|
|
6
6
|
inlinePadding: number;
|
|
@@ -8,13 +8,16 @@ export declare const MenuInline: React.ForwardRefExoticComponent<Partial<{
|
|
|
8
8
|
selectable: boolean;
|
|
9
9
|
className: string;
|
|
10
10
|
itemSize: number;
|
|
11
|
-
selected: string[];
|
|
11
|
+
selected: string | string[];
|
|
12
12
|
expanded: string[];
|
|
13
13
|
onClick: (args: {
|
|
14
14
|
item: ItemType;
|
|
15
|
-
|
|
15
|
+
domEvent?: React.MouseEvent<Element, MouseEvent> | undefined;
|
|
16
|
+
elKey: "item" | "item-expand-el";
|
|
16
17
|
}) => void;
|
|
17
|
-
action: React.ReactNode | ((item: ItemType
|
|
18
|
+
action: React.ReactNode | ((item: ItemType, others: {
|
|
19
|
+
expandEl: React.ReactNode;
|
|
20
|
+
}) => React.ReactNode);
|
|
18
21
|
}> & {
|
|
19
22
|
mode?: "inline" | undefined;
|
|
20
|
-
} & React.RefAttributes<import("../../types").VirtualizedMenuBaseHandle
|
|
23
|
+
} & React.RefAttributes<import("../../types").VirtualizedMenuBaseHandle>>>;
|
|
@@ -1,17 +1,121 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import { forwardRef, useEffect, useImperativeHandle, useMemo, useState, useCallback, useRef, memo, } from 'react';
|
|
3
3
|
import { StyledAutoSizer, VirtualizedMenuContainer } from '../../styled';
|
|
4
4
|
import { INLINE_INDENT, INLINE_PADDING, ITEM_SIZE, ITEM_SPACING } from '../../config';
|
|
5
|
-
import { CLS,
|
|
5
|
+
import { CLS, serializeItems, getItemSize } from '../../utils';
|
|
6
6
|
import { Item } from '../Item';
|
|
7
7
|
import { useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
9
|
+
import { findNodes, getChildrenRecursively, getPathToNode, } from '@antscorp/antsomi-ui/es/utils/tree';
|
|
10
|
+
const innerElementType = forwardRef(({ style, ...rest }, ref) => (_jsx("ul", { role: "tree", "aria-label": "Virtualized Menu", ref: ref, style: style, ...rest })));
|
|
11
|
+
/**
|
|
12
|
+
* Optimized function to compute visible items using breadth-first traversal
|
|
13
|
+
* instead of filtering all items
|
|
14
|
+
*/
|
|
15
|
+
const computeVisibleItemsOptimized = (normalizeTreeItems, rootItemIds, expandedKeys) => {
|
|
16
|
+
const visibleItems = [];
|
|
17
|
+
const queue = Array.from(rootItemIds);
|
|
18
|
+
// Process queue in breadth-first manner
|
|
19
|
+
let index = 0;
|
|
20
|
+
while (index < queue.length) {
|
|
21
|
+
const itemId = queue[index++];
|
|
22
|
+
const item = normalizeTreeItems.get(itemId);
|
|
23
|
+
if (!item)
|
|
24
|
+
continue;
|
|
25
|
+
visibleItems.push(item);
|
|
26
|
+
// Add children to queue only if this item is expanded
|
|
27
|
+
if (expandedKeys.has(item.id) && item.childIds.length > 0) {
|
|
28
|
+
queue.push(...item.childIds);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return visibleItems;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Alternative: Path-based optimization with memoization
|
|
35
|
+
* Caches path calculations to avoid redundant work
|
|
36
|
+
*/
|
|
37
|
+
const computeVisibleItemsWithPathCache = (normalizeTreeItems, expandedKeys, pathCache) => {
|
|
38
|
+
const visibleItems = [];
|
|
39
|
+
for (const item of normalizeTreeItems.values()) {
|
|
40
|
+
const isRootItem = item.level === 0;
|
|
41
|
+
if (isRootItem) {
|
|
42
|
+
visibleItems.push(item);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (!item.parentId)
|
|
46
|
+
continue;
|
|
47
|
+
// Use cached path or compute and cache
|
|
48
|
+
let pathToParent = pathCache.get(item.parentId);
|
|
49
|
+
if (!pathToParent) {
|
|
50
|
+
pathToParent = getPathToNode(item.parentId, normalizeTreeItems);
|
|
51
|
+
pathCache.set(item.parentId, pathToParent);
|
|
52
|
+
}
|
|
53
|
+
// Check if all parents are expanded
|
|
54
|
+
const allParentExpanded = pathToParent.every(parent => expandedKeys.has(parent.id));
|
|
55
|
+
if (allParentExpanded) {
|
|
56
|
+
visibleItems.push(item);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return visibleItems;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Level-based optimization: Process items level by level
|
|
63
|
+
* More efficient for deep trees with many collapsed branches
|
|
64
|
+
*/
|
|
65
|
+
const computeVisibleItemsByLevel = (normalizeTreeItems, rootItemIds, expandedKeys) => {
|
|
66
|
+
const visibleItems = [];
|
|
67
|
+
const expandedParents = new Set();
|
|
68
|
+
// Add root items and track expanded ones
|
|
69
|
+
for (const rootId of rootItemIds) {
|
|
70
|
+
const rootItem = normalizeTreeItems.get(rootId);
|
|
71
|
+
if (rootItem) {
|
|
72
|
+
visibleItems.push(rootItem);
|
|
73
|
+
if (expandedKeys.has(rootId)) {
|
|
74
|
+
expandedParents.add(rootId);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Process each level
|
|
79
|
+
let currentLevelParents = expandedParents;
|
|
80
|
+
let currentLevel = 1;
|
|
81
|
+
while (currentLevelParents.size > 0) {
|
|
82
|
+
const nextLevelParents = new Set();
|
|
83
|
+
// Process all items at current level
|
|
84
|
+
for (const parentId of currentLevelParents) {
|
|
85
|
+
const parent = normalizeTreeItems.get(parentId);
|
|
86
|
+
if (!parent)
|
|
87
|
+
continue;
|
|
88
|
+
// Add all children of this expanded parent
|
|
89
|
+
for (const childId of parent.childIds) {
|
|
90
|
+
const child = normalizeTreeItems.get(childId);
|
|
91
|
+
if (child && child.level === currentLevel) {
|
|
92
|
+
visibleItems.push(child);
|
|
93
|
+
// Track if this child is expanded for next level
|
|
94
|
+
if (expandedKeys.has(childId)) {
|
|
95
|
+
nextLevelParents.add(childId);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
currentLevelParents = nextLevelParents;
|
|
101
|
+
currentLevel++;
|
|
102
|
+
}
|
|
103
|
+
return visibleItems;
|
|
104
|
+
};
|
|
105
|
+
const MenuInlineInner = forwardRef((props, ref) => {
|
|
106
|
+
const { items: itemsProp = [], expanded: expandedProp = [], selected: selectedProp = [], inlineIndent = INLINE_INDENT, inlinePadding = INLINE_PADDING, itemSize = ITEM_SIZE, itemSpacing = ITEM_SPACING, selectable = false, action, className, onClick, } = props;
|
|
107
|
+
const [focusId, setFocusId] = useState(null);
|
|
12
108
|
const [expandedKeys, setExpandedKeys] = useState(new Set());
|
|
13
109
|
const [selectedKeys, setSelectedKeys] = useState(new Set());
|
|
14
|
-
const
|
|
110
|
+
const listRef = useRef(null);
|
|
111
|
+
const itemRefs = useRef(new Map());
|
|
112
|
+
const [{ items: normalizeTreeItems, rootItemIds }, setTreeState] = useState({
|
|
113
|
+
items: new Map(),
|
|
114
|
+
rootItemIds: new Set(),
|
|
115
|
+
});
|
|
116
|
+
// Cache for path calculations to avoid redundant work
|
|
117
|
+
const pathCache = useMemo(() => new Map(), []);
|
|
118
|
+
const rootNodes = useMemo(() => findNodes(node => rootItemIds.has(node.id), normalizeTreeItems), [normalizeTreeItems, rootItemIds]);
|
|
15
119
|
useDeepCompareEffect(() => {
|
|
16
120
|
setSelectedKeys(new Set(selectedProp));
|
|
17
121
|
}, [selectedProp]);
|
|
@@ -19,54 +123,185 @@ const MenuInlineInner = (props, ref) => {
|
|
|
19
123
|
setExpandedKeys(new Set(expandedProp));
|
|
20
124
|
}, [expandedProp]);
|
|
21
125
|
useEffect(() => {
|
|
22
|
-
|
|
126
|
+
setTreeState(serializeItems({
|
|
127
|
+
items: itemsProp,
|
|
128
|
+
}));
|
|
23
129
|
}, [itemsProp]);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
130
|
+
// Clear path cache when tree structure changes
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
pathCache.clear();
|
|
133
|
+
}, [normalizeTreeItems, pathCache]);
|
|
134
|
+
// Optimized visible items calculation
|
|
135
|
+
const visibleItems = useMemo(() => {
|
|
136
|
+
if (normalizeTreeItems.size === 0)
|
|
137
|
+
return [];
|
|
138
|
+
// Choose optimization strategy based on tree characteristics
|
|
139
|
+
const treeDepth = Math.max(...Array.from(normalizeTreeItems.values()).map(item => item.level));
|
|
140
|
+
const totalItems = normalizeTreeItems.size;
|
|
141
|
+
const expandedCount = expandedKeys.size;
|
|
142
|
+
// Strategy selection heuristics:
|
|
143
|
+
// - For shallow trees with many expanded items: use breadth-first
|
|
144
|
+
// - For deep trees with few expanded items: use level-based
|
|
145
|
+
// - For medium trees: use path-cache optimization
|
|
146
|
+
if (treeDepth <= 3 && expandedCount > totalItems * 0.3) {
|
|
147
|
+
// Shallow tree with many expanded items
|
|
148
|
+
return computeVisibleItemsOptimized(normalizeTreeItems, rootItemIds, expandedKeys);
|
|
149
|
+
}
|
|
150
|
+
if (treeDepth > 5 && expandedCount < totalItems * 0.2) {
|
|
151
|
+
// Deep tree with few expanded items
|
|
152
|
+
return computeVisibleItemsByLevel(normalizeTreeItems, rootItemIds, expandedKeys);
|
|
153
|
+
}
|
|
154
|
+
// Medium complexity - use cached path approach
|
|
155
|
+
return computeVisibleItemsWithPathCache(normalizeTreeItems, expandedKeys, pathCache);
|
|
156
|
+
}, [expandedKeys, normalizeTreeItems, rootItemIds, pathCache]);
|
|
157
|
+
const handleCollapseItems = useCallback((items) => {
|
|
158
|
+
setExpandedKeys(prev => {
|
|
159
|
+
const newOpenKeys = new Set(prev);
|
|
160
|
+
items.forEach(({ data }) => {
|
|
161
|
+
if (prev.has(data.key)) {
|
|
162
|
+
newOpenKeys.delete(data.key);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
return newOpenKeys;
|
|
36
166
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
167
|
+
}, []);
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (focusId && listRef.current) {
|
|
170
|
+
const index = visibleItems.findIndex(item => item.id === focusId);
|
|
171
|
+
if (index !== -1) {
|
|
172
|
+
listRef.current.scrollToItem(index, 'auto');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}, [focusId, visibleItems]);
|
|
176
|
+
const handleExpandItems = useCallback((items, deep = 0) => {
|
|
177
|
+
setExpandedKeys(prev => {
|
|
178
|
+
const updatedExpandedKeys = new Set(prev);
|
|
179
|
+
items.forEach(item => {
|
|
180
|
+
const normalizeItem = normalizeTreeItems.get(item.data.key);
|
|
181
|
+
if (normalizeItem) {
|
|
182
|
+
updatedExpandedKeys.add(normalizeItem.id);
|
|
183
|
+
if (deep > 0) {
|
|
184
|
+
getChildrenRecursively(normalizeItem.id, normalizeTreeItems, normalizeItem.level + deep).forEach(v => updatedExpandedKeys.add(v.id));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
return updatedExpandedKeys;
|
|
45
189
|
});
|
|
46
|
-
|
|
47
|
-
};
|
|
190
|
+
}, [normalizeTreeItems]);
|
|
48
191
|
useImperativeHandle(ref, () => ({
|
|
49
192
|
expandAll: () => {
|
|
50
|
-
handleExpandItems(
|
|
193
|
+
handleExpandItems(rootNodes, Infinity);
|
|
51
194
|
},
|
|
52
195
|
}));
|
|
53
|
-
const
|
|
54
|
-
const { key } = item;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
196
|
+
const handleSelectItem = useCallback((item) => {
|
|
197
|
+
const { key } = item.data;
|
|
198
|
+
if (!selectable || selectedKeys.has(key))
|
|
199
|
+
return;
|
|
200
|
+
setSelectedKeys(new Set([key]));
|
|
201
|
+
}, [selectable, selectedKeys]);
|
|
202
|
+
const handleToggleExpandItem = useCallback((item) => {
|
|
203
|
+
const { key } = item.data;
|
|
204
|
+
const isExpanded = expandedKeys.has(key);
|
|
205
|
+
if (isExpanded) {
|
|
58
206
|
handleCollapseItems([item]);
|
|
59
207
|
}
|
|
60
|
-
|
|
208
|
+
else {
|
|
61
209
|
handleExpandItems([item]);
|
|
62
210
|
}
|
|
63
|
-
|
|
64
|
-
|
|
211
|
+
}, [expandedKeys, handleCollapseItems, handleExpandItems]);
|
|
212
|
+
const handleClickItem = useCallback((args) => {
|
|
213
|
+
const { item, elKey, domEvent } = args;
|
|
214
|
+
const node = normalizeTreeItems.get(item.id);
|
|
215
|
+
if (!node)
|
|
216
|
+
return;
|
|
217
|
+
const hasChilren = node.childIds.length > 0;
|
|
218
|
+
handleSelectItem(node);
|
|
219
|
+
if (hasChilren) {
|
|
220
|
+
handleToggleExpandItem(node);
|
|
221
|
+
}
|
|
222
|
+
setFocusId(node.id);
|
|
223
|
+
onClick?.({ item: node.data, elKey, domEvent });
|
|
224
|
+
}, [normalizeTreeItems, handleSelectItem, handleToggleExpandItem, onClick]);
|
|
225
|
+
const handleKeyDown = useCallback((e) => {
|
|
226
|
+
if (visibleItems.length === 0)
|
|
227
|
+
return;
|
|
228
|
+
e.preventDefault();
|
|
229
|
+
const currentFocusIndex = visibleItems.findIndex(item => item.id === focusId);
|
|
230
|
+
if (currentFocusIndex === -1) {
|
|
231
|
+
setFocusId(visibleItems[0]?.id ?? null);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const currentFocusItem = visibleItems[currentFocusIndex];
|
|
235
|
+
switch (e.key) {
|
|
236
|
+
case 'ArrowDown': {
|
|
237
|
+
const nextFocusIndex = Math.min(visibleItems.length - 1, currentFocusIndex + 1);
|
|
238
|
+
setFocusId(visibleItems[nextFocusIndex].id);
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case 'ArrowUp': {
|
|
242
|
+
const nextFocusIndex = Math.max(0, currentFocusIndex - 1);
|
|
243
|
+
setFocusId(visibleItems[nextFocusIndex].id);
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
case 'ArrowRight': {
|
|
247
|
+
if (currentFocusItem.childIds.length > 0 && !expandedKeys.has(currentFocusItem.id)) {
|
|
248
|
+
handleExpandItems([currentFocusItem]);
|
|
249
|
+
}
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
case 'ArrowLeft': {
|
|
253
|
+
if (currentFocusItem.childIds.length > 0 && expandedKeys.has(currentFocusItem.id)) {
|
|
254
|
+
handleCollapseItems([currentFocusItem]);
|
|
255
|
+
}
|
|
256
|
+
else if (currentFocusItem?.parentId) {
|
|
257
|
+
setFocusId(currentFocusItem.parentId);
|
|
258
|
+
}
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case 'Home': {
|
|
262
|
+
setFocusId(visibleItems[0].id);
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
case 'End': {
|
|
266
|
+
setFocusId(visibleItems[visibleItems.length - 1].id);
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
case 'Enter': {
|
|
270
|
+
if (currentFocusItem) {
|
|
271
|
+
handleSelectItem(currentFocusItem);
|
|
272
|
+
if (currentFocusItem.childIds.length > 0) {
|
|
273
|
+
handleToggleExpandItem(currentFocusItem);
|
|
274
|
+
}
|
|
275
|
+
onClick?.({
|
|
276
|
+
item: currentFocusItem.data,
|
|
277
|
+
elKey: 'item',
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
default:
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}, [
|
|
286
|
+
visibleItems,
|
|
287
|
+
focusId,
|
|
288
|
+
expandedKeys,
|
|
289
|
+
onClick,
|
|
290
|
+
handleExpandItems,
|
|
291
|
+
handleCollapseItems,
|
|
292
|
+
handleSelectItem,
|
|
293
|
+
handleToggleExpandItem,
|
|
294
|
+
]);
|
|
295
|
+
const handleFocus = (e) => {
|
|
296
|
+
let isClickFont = false;
|
|
297
|
+
for (const itemEl of itemRefs.current.values()) {
|
|
298
|
+
if (isClickFont)
|
|
299
|
+
break;
|
|
300
|
+
isClickFont = itemEl.isSameNode(e.target) || itemEl.contains(e.target);
|
|
301
|
+
}
|
|
302
|
+
if (!isClickFont && !focusId && visibleItems.length > 0) {
|
|
303
|
+
setFocusId(visibleItems.at(0)?.id || null);
|
|
65
304
|
}
|
|
66
|
-
onClick?.({
|
|
67
|
-
item,
|
|
68
|
-
pathKey: visibleItems[idx].pathKey,
|
|
69
|
-
});
|
|
70
305
|
};
|
|
71
306
|
const itemData = {
|
|
72
307
|
itemSpacing,
|
|
@@ -75,9 +310,17 @@ const MenuInlineInner = (props, ref) => {
|
|
|
75
310
|
selectedKeys,
|
|
76
311
|
expandedKeys,
|
|
77
312
|
action,
|
|
78
|
-
|
|
313
|
+
focusId,
|
|
314
|
+
normalizeTreeItems,
|
|
315
|
+
items: visibleItems.map(item => ({
|
|
316
|
+
...item,
|
|
317
|
+
data: {
|
|
318
|
+
...item.data,
|
|
319
|
+
ref: el => itemRefs.current.set(item.id, el),
|
|
320
|
+
},
|
|
321
|
+
})),
|
|
79
322
|
onClick: handleClickItem,
|
|
80
323
|
};
|
|
81
|
-
return (_jsx(StyledAutoSizer, { className: clsx(CLS.Root.default, className), children: autoSize => (_jsx(VirtualizedMenuContainer, { className: clsx(CLS.MenuInline.default), itemSize: getItemSize(itemSize, itemSpacing), itemCount: visibleItems.length, height: autoSize.height, width: autoSize.width, innerElementType: innerElementType, itemData: itemData, useIsScrolling: true, children: Item })) }));
|
|
82
|
-
};
|
|
83
|
-
export const MenuInline =
|
|
324
|
+
return (_jsx(StyledAutoSizer, { className: clsx(CLS.Root.default, className), tabIndex: 0, onFocus: handleFocus, onKeyDown: handleKeyDown, children: autoSize => (_jsx(VirtualizedMenuContainer, { ref: listRef, className: clsx(CLS.MenuInline.default), itemSize: getItemSize(itemSize, itemSpacing), itemCount: visibleItems.length, height: autoSize.height, width: autoSize.width, innerElementType: innerElementType, itemData: itemData, useIsScrolling: true, children: Item })) }));
|
|
325
|
+
});
|
|
326
|
+
export const MenuInline = memo(MenuInlineInner);
|
|
@@ -3,7 +3,7 @@ import { VariableSizeList } from 'react-window';
|
|
|
3
3
|
import { MemoryData } from './components/Item/Item';
|
|
4
4
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
|
5
5
|
export declare const MenuItemWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
6
|
-
export declare const MenuItemRoot: import("styled-components").StyledComponent<"
|
|
6
|
+
export declare const MenuItemRoot: import("styled-components").StyledComponent<"li", any, {}, never>;
|
|
7
7
|
export declare const VirtualizedMenuContainer: import("styled-components").StyledComponent<{
|
|
8
8
|
new (props: import("react-window").VariableSizeListProps<MemoryData>): VariableSizeList<MemoryData>;
|
|
9
9
|
new (props: import("react-window").VariableSizeListProps<MemoryData>, context: any): VariableSizeList<MemoryData>;
|
|
@@ -3,6 +3,7 @@ import { VariableSizeList } from 'react-window';
|
|
|
3
3
|
import { THEME, globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
4
4
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
|
5
5
|
import { CLS } from './utils';
|
|
6
|
+
import tinycolor from 'tinycolor2';
|
|
6
7
|
export const MenuItemWrapper = styled.div `
|
|
7
8
|
width: 100%;
|
|
8
9
|
height: 100%;
|
|
@@ -15,7 +16,7 @@ export const MenuItemWrapper = styled.div `
|
|
|
15
16
|
|
|
16
17
|
.icon-expand {
|
|
17
18
|
font-size: 14px;
|
|
18
|
-
flex-
|
|
19
|
+
flex-shrink: 0;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
.title-wrapper {
|
|
@@ -24,17 +25,23 @@ export const MenuItemWrapper = styled.div `
|
|
|
24
25
|
white-space: nowrap;
|
|
25
26
|
}
|
|
26
27
|
`;
|
|
27
|
-
export const MenuItemRoot = styled.
|
|
28
|
+
export const MenuItemRoot = styled.li `
|
|
28
29
|
&.${CLS.Item.default} {
|
|
29
30
|
cursor: pointer;
|
|
30
31
|
display: flex;
|
|
31
32
|
align-items: center;
|
|
32
33
|
overflow: hidden;
|
|
33
|
-
|
|
34
|
+
|
|
35
|
+
&:focus {
|
|
36
|
+
outline: none;
|
|
37
|
+
}
|
|
34
38
|
|
|
35
39
|
> .${CLS.ItemLabel.default} {
|
|
40
|
+
display: flex;
|
|
36
41
|
flex: 1;
|
|
37
42
|
overflow: hidden;
|
|
43
|
+
align-self: stretch;
|
|
44
|
+
align-items: center;
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
> .${CLS.ItemAction.default} {
|
|
@@ -61,7 +68,14 @@ export const MenuItemRoot = styled.div `
|
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
70
|
|
|
64
|
-
|
|
71
|
+
&.${CLS.Item.selectedDescendant} {
|
|
72
|
+
background-color: ${tinycolor(THEME.components?.Menu?.itemActiveBg)
|
|
73
|
+
.lighten(4)
|
|
74
|
+
.toString('rgb')};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&:focus:not(.${CLS.Item.disabled}, .${CLS.Item.selected}, .${CLS.Item.selectedDescendant}),
|
|
78
|
+
&:hover:not(.${CLS.Item.disabled}, .${CLS.Item.selected}, .${CLS.Item.selectedDescendant}) {
|
|
65
79
|
background-color: ${THEME.components?.Menu?.itemHoverBg};
|
|
66
80
|
}
|
|
67
81
|
}
|
|
@@ -69,6 +83,11 @@ export const MenuItemRoot = styled.div `
|
|
|
69
83
|
export const VirtualizedMenuContainer = styled((VariableSizeList)) `
|
|
70
84
|
font-size: ${globalToken?.fontSize}px;
|
|
71
85
|
scrollbar-gutter: stable;
|
|
86
|
+
|
|
87
|
+
ul {
|
|
88
|
+
padding: 0;
|
|
89
|
+
margin: 0;
|
|
90
|
+
}
|
|
72
91
|
`;
|
|
73
92
|
export const StyledAutoSizer = styled(AutoSizer) `
|
|
74
93
|
flex: 1;
|
|
@@ -11,11 +11,6 @@ export type ItemType = {
|
|
|
11
11
|
errorMessage?: string | undefined;
|
|
12
12
|
disabled?: boolean;
|
|
13
13
|
};
|
|
14
|
-
export type SerializedItemType = ItemType & {
|
|
15
|
-
level: number;
|
|
16
|
-
pathKey: PathKey;
|
|
17
|
-
parent: ItemType | null;
|
|
18
|
-
};
|
|
19
14
|
type VirtualizedMenuBaseProps = Partial<{
|
|
20
15
|
items: ItemType[];
|
|
21
16
|
inlineIndent: number;
|
|
@@ -24,18 +19,20 @@ type VirtualizedMenuBaseProps = Partial<{
|
|
|
24
19
|
selectable: boolean;
|
|
25
20
|
className: string;
|
|
26
21
|
itemSize: number;
|
|
27
|
-
selected: string[];
|
|
22
|
+
selected: string | string[];
|
|
28
23
|
expanded: string[];
|
|
29
24
|
onClick: (args: {
|
|
30
25
|
item: ItemType;
|
|
31
|
-
|
|
26
|
+
domEvent?: React.MouseEvent;
|
|
27
|
+
elKey: 'item' | 'item-expand-el';
|
|
32
28
|
}) => void;
|
|
33
|
-
action: React.ReactNode | ((item: ItemType
|
|
29
|
+
action: React.ReactNode | ((item: ItemType, others: {
|
|
30
|
+
expandEl: React.ReactNode;
|
|
31
|
+
}) => React.ReactNode);
|
|
34
32
|
}>;
|
|
35
33
|
export type VirtualizedMenuBaseHandle = {
|
|
36
34
|
expandAll: () => void;
|
|
37
35
|
};
|
|
38
|
-
export type PathKey = (string | number)[];
|
|
39
36
|
export type MenuInlineHandle = VirtualizedMenuBaseHandle;
|
|
40
37
|
export type MenuInlineProps = VirtualizedMenuBaseProps & {
|
|
41
38
|
mode?: typeof MODE.Inline;
|