@antscorp/antsomi-ui 2.0.81 → 2.0.83-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 +1 -0
- package/es/components/molecules/AccountSelection/AccountListing.js +14 -3
- 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 +77 -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/types.d.ts +21 -0
- package/es/components/molecules/FontSizeInput/types.js +1 -0
- package/es/components/molecules/QuillEditor/QuillEditor.js +1 -1
- package/es/components/molecules/VirtualizedMenu/VirtualizedMenu.d.ts +1 -2
- package/es/components/molecules/VirtualizedMenu/__mocks__/index.js +2550 -938
- package/es/components/molecules/VirtualizedMenu/components/Item/Item.d.ts +4 -3
- package/es/components/molecules/VirtualizedMenu/components/Item/Item.js +24 -22
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.d.ts +1 -2
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.js +59 -31
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.optimized.d.ts +19 -0
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.optimized.js +233 -0
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.d.ts +1 -1
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.js +2 -1
- package/es/components/molecules/VirtualizedMenu/styled.d.ts +1 -1
- package/es/components/molecules/VirtualizedMenu/styled.js +11 -3
- package/es/components/molecules/VirtualizedMenu/types.d.ts +1 -8
- package/es/components/molecules/VirtualizedMenu/utils.d.ts +7 -5
- package/es/components/molecules/VirtualizedMenu/utils.js +12 -18
- package/es/components/molecules/index.d.ts +1 -0
- package/es/components/molecules/index.js +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 +239 -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 +41 -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 +19 -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 +66 -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 +3 -0
- package/es/components/organism/TextEditor/extensions/Link.js +47 -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 +33 -0
- package/es/components/organism/TextEditor/extensions/SmartTag.js +162 -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 +35 -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 +27 -0
- package/es/components/organism/TextEditor/hooks/useLinkHandler.js +279 -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 +5 -0
- package/es/components/organism/TextEditor/index.js +2 -0
- package/es/components/organism/TextEditor/index.scss +26 -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 +5 -0
- package/es/components/organism/TextEditor/styled.js +69 -0
- package/es/components/organism/TextEditor/types.d.ts +95 -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 +11 -0
- package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.js +72 -0
- package/es/components/organism/TextEditor/ui/FontPopover/styled.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/FontPopover/styled.js +51 -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 +6 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.js +42 -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 +28 -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 +62 -0
- package/es/components/organism/TextEditor/utils/htmlProcessing.js +304 -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/hooks/useBroadcastedLocalStorage.d.ts +5 -0
- package/es/hooks/useBroadcastedLocalStorage.js +71 -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,15 @@
|
|
|
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:
|
|
9
|
+
items: NormalizedNode<ItemType>[];
|
|
9
10
|
selectedKeys: Set<string>;
|
|
10
11
|
expandedKeys: Set<string>;
|
|
11
12
|
action: MenuInlineProps['action'];
|
|
12
|
-
onClick: (item: ItemType
|
|
13
|
+
onClick: (item: NormalizedNode<ItemType>, index: number) => void;
|
|
13
14
|
};
|
|
14
15
|
export declare const Item: React.MemoExoticComponent<(props: ListChildComponentProps<MemoryData>) => import("react/jsx-runtime").JSX.Element>;
|
|
@@ -12,7 +12,11 @@ export const Item = memo((props) => {
|
|
|
12
12
|
const { style = {}, data, index = 0 } = props;
|
|
13
13
|
const { inlineIndent, itemSpacing, inlinePadding, items, selectedKeys, expandedKeys, action, onClick, } = data || {};
|
|
14
14
|
const item = items[index];
|
|
15
|
-
const
|
|
15
|
+
const hasChildren = !isEmpty(item.data.children);
|
|
16
|
+
const expanded = hasChildren && expandedKeys.has(item.data.key);
|
|
17
|
+
const selected = selectedKeys.has(item.data.key);
|
|
18
|
+
const disabled = item.data?.disabled;
|
|
19
|
+
const indentSize = item.level * inlineIndent;
|
|
16
20
|
const itemStyle = {
|
|
17
21
|
...style,
|
|
18
22
|
paddingLeft: indentSize + inlinePadding,
|
|
@@ -21,29 +25,27 @@ export const Item = memo((props) => {
|
|
|
21
25
|
height: index === 0 ? Number(style.height) : Number(style.height) - itemSpacing,
|
|
22
26
|
};
|
|
23
27
|
const itemClassName = clsx(CLS.Item.default, {
|
|
24
|
-
[CLS.Item.selected]:
|
|
25
|
-
[CLS.Item.expanded]:
|
|
26
|
-
[CLS.Item.disabled]:
|
|
27
|
-
}, item.className);
|
|
28
|
+
[CLS.Item.selected]: selected,
|
|
29
|
+
[CLS.Item.expanded]: expanded,
|
|
30
|
+
[CLS.Item.disabled]: disabled,
|
|
31
|
+
}, item.data.className);
|
|
28
32
|
const handleOnClick = () => {
|
|
29
|
-
if (!onClick ||
|
|
33
|
+
if (!onClick || disabled)
|
|
30
34
|
return;
|
|
31
35
|
onClick(item, index);
|
|
32
36
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
return (_jsxs(MenuItemRoot, { className: itemClassName, style: itemStyle, onClick: handleOnClick, children: [_jsx("div", { className: CLS.ItemLabel.default, children: renderLabel() }), renderAction()] }));
|
|
37
|
+
let labelContent = item.data?.label;
|
|
38
|
+
let actionContent = null;
|
|
39
|
+
if (typeof item.data?.label === 'string') {
|
|
40
|
+
labelContent = (_jsx(Typography.Text, { ellipsis: {
|
|
41
|
+
tooltip: true,
|
|
42
|
+
}, children: item.data.label }));
|
|
43
|
+
}
|
|
44
|
+
if (action) {
|
|
45
|
+
actionContent = (_jsx("div", { className: CLS.ItemAction.default, children: typeof action === 'function' ? action(item.data) : action }));
|
|
46
|
+
}
|
|
47
|
+
if (hasChildren) {
|
|
48
|
+
actionContent = (_jsx("div", { className: CLS.ItemAction.default, children: _jsx(ExpandMoreIcon, { color: globalToken?.colorIcon, size: 20, className: CLS.IconExpand.default, "aria-hidden": "true" }) }));
|
|
49
|
+
}
|
|
50
|
+
return (_jsxs(MenuItemRoot, { role: "treeitem", "aria-selected": selected, "aria-disabled": disabled, "aria-expanded": expanded, "aria-level": item.level, "aria-posinset": index + 1, "aria-setsize": items.length, className: itemClassName, style: itemStyle, onClick: handleOnClick, children: [_jsx("div", { className: CLS.ItemLabel.default, children: labelContent }), actionContent] }));
|
|
49
51
|
}, areEqual);
|
|
@@ -8,11 +8,10 @@ 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
|
-
pathKey: import("../../types").PathKey;
|
|
16
15
|
}) => void;
|
|
17
16
|
action: React.ReactNode | ((item: ItemType) => React.ReactNode);
|
|
18
17
|
}> & {
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, { forwardRef, useEffect, useImperativeHandle, useState, } from 'react';
|
|
2
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useState, } 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
|
-
|
|
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 })));
|
|
10
11
|
const MenuInlineInner = (props, ref) => {
|
|
11
12
|
const { items: itemsProp = [], inlineIndent = INLINE_INDENT, inlinePadding = INLINE_PADDING, itemSize = ITEM_SIZE, itemSpacing = ITEM_SPACING, selectable = false, expanded: expandedProp = [], selected: selectedProp = [], action, className, onClick, } = props;
|
|
12
13
|
const [expandedKeys, setExpandedKeys] = useState(new Set());
|
|
13
14
|
const [selectedKeys, setSelectedKeys] = useState(new Set());
|
|
14
|
-
const [
|
|
15
|
+
const [{ items: normalizeTreeItems, rootItemIds }, setTreeState] = useState({
|
|
16
|
+
items: new Map(),
|
|
17
|
+
rootItemIds: new Set(),
|
|
18
|
+
});
|
|
19
|
+
const rootNodes = useMemo(() => findNodes(node => rootItemIds.has(node.id), normalizeTreeItems), [normalizeTreeItems, rootItemIds]);
|
|
20
|
+
// console.log({ selectedKeys, setSelectedKeys });
|
|
15
21
|
useDeepCompareEffect(() => {
|
|
16
22
|
setSelectedKeys(new Set(selectedProp));
|
|
17
23
|
}, [selectedProp]);
|
|
@@ -19,54 +25,76 @@ const MenuInlineInner = (props, ref) => {
|
|
|
19
25
|
setExpandedKeys(new Set(expandedProp));
|
|
20
26
|
}, [expandedProp]);
|
|
21
27
|
useEffect(() => {
|
|
22
|
-
|
|
28
|
+
setTreeState(serializeItems({
|
|
29
|
+
items: itemsProp,
|
|
30
|
+
}));
|
|
23
31
|
}, [itemsProp]);
|
|
24
|
-
const visibleItems =
|
|
25
|
-
const isRootItem = item.level ===
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
const visibleItems = useMemo(() => Array.from(normalizeTreeItems.values()).filter(item => {
|
|
33
|
+
const isRootItem = item.level === 0;
|
|
34
|
+
const allParentExpanded = item.parentId &&
|
|
35
|
+
getPathToNode(item.parentId, normalizeTreeItems).every(v => expandedKeys.has(v.id));
|
|
36
|
+
return isRootItem || allParentExpanded;
|
|
37
|
+
}), [expandedKeys, normalizeTreeItems]);
|
|
38
|
+
// console.log({
|
|
39
|
+
// normalizeTreeItems,
|
|
40
|
+
// rootItemIds,
|
|
41
|
+
// expandedKeys,
|
|
42
|
+
// selectedKeys,
|
|
43
|
+
// visibleItems,
|
|
44
|
+
// });
|
|
29
45
|
const handleCollapseItems = (items) => {
|
|
30
46
|
const newOpenKeys = new Set(expandedKeys);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
newOpenKeys.delete(key);
|
|
47
|
+
items.forEach(({ data }) => {
|
|
48
|
+
if (expandedKeys.has(data.key)) {
|
|
49
|
+
newOpenKeys.delete(data.key);
|
|
35
50
|
}
|
|
36
51
|
});
|
|
37
52
|
setExpandedKeys(newOpenKeys);
|
|
38
53
|
};
|
|
39
|
-
const handleExpandItems = (items) => {
|
|
54
|
+
const handleExpandItems = (items, deep = 0) => {
|
|
40
55
|
const updatedExpandedKeys = new Set(expandedKeys);
|
|
41
56
|
items.forEach(item => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
const normalizeItem = normalizeTreeItems.get(item.data.key);
|
|
58
|
+
if (normalizeItem) {
|
|
59
|
+
updatedExpandedKeys.add(normalizeItem.id);
|
|
60
|
+
if (deep > 0) {
|
|
61
|
+
getChildrenRecursively(normalizeItem.id, normalizeTreeItems, normalizeItem.level + deep).forEach(v => updatedExpandedKeys.add(v.id));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
45
64
|
});
|
|
46
65
|
setExpandedKeys(updatedExpandedKeys);
|
|
47
66
|
};
|
|
48
67
|
useImperativeHandle(ref, () => ({
|
|
49
68
|
expandAll: () => {
|
|
50
|
-
handleExpandItems(
|
|
69
|
+
handleExpandItems(rootNodes, Infinity);
|
|
51
70
|
},
|
|
52
71
|
}));
|
|
53
|
-
const
|
|
54
|
-
const { key } = item;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
72
|
+
const handleSelectItem = (item) => {
|
|
73
|
+
const { key } = item.data;
|
|
74
|
+
if (!selectable || selectedKeys.has(key))
|
|
75
|
+
return;
|
|
76
|
+
setSelectedKeys(new Set([key]));
|
|
77
|
+
};
|
|
78
|
+
const handleToggleExpandItem = (item) => {
|
|
79
|
+
const { key } = item.data;
|
|
80
|
+
const isExpanded = expandedKeys.has(key);
|
|
81
|
+
if (isExpanded) {
|
|
58
82
|
handleCollapseItems([item]);
|
|
59
83
|
}
|
|
60
|
-
|
|
84
|
+
else {
|
|
61
85
|
handleExpandItems([item]);
|
|
62
86
|
}
|
|
63
|
-
|
|
64
|
-
|
|
87
|
+
};
|
|
88
|
+
const handleClickItem = (item) => {
|
|
89
|
+
const node = normalizeTreeItems.get(item.id);
|
|
90
|
+
if (!node)
|
|
91
|
+
return;
|
|
92
|
+
const hasChilren = node.childIds.length > 0;
|
|
93
|
+
handleSelectItem(node);
|
|
94
|
+
if (hasChilren) {
|
|
95
|
+
handleToggleExpandItem(node);
|
|
65
96
|
}
|
|
66
|
-
onClick?.({
|
|
67
|
-
item,
|
|
68
|
-
pathKey: visibleItems[idx].pathKey,
|
|
69
|
-
});
|
|
97
|
+
onClick?.({ item: node.data });
|
|
70
98
|
};
|
|
71
99
|
const itemData = {
|
|
72
100
|
itemSpacing,
|
package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.optimized.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ItemType } from '../../types';
|
|
3
|
+
export declare const MenuInline: React.ForwardRefExoticComponent<Partial<{
|
|
4
|
+
items: ItemType[];
|
|
5
|
+
inlineIndent: number;
|
|
6
|
+
inlinePadding: number;
|
|
7
|
+
itemSpacing: number;
|
|
8
|
+
selectable: boolean;
|
|
9
|
+
className: string;
|
|
10
|
+
itemSize: number;
|
|
11
|
+
selected: string | string[];
|
|
12
|
+
expanded: string[];
|
|
13
|
+
onClick: (args: {
|
|
14
|
+
item: ItemType;
|
|
15
|
+
}) => void;
|
|
16
|
+
action: React.ReactNode | ((item: ItemType) => React.ReactNode);
|
|
17
|
+
}> & {
|
|
18
|
+
mode?: "inline" | undefined;
|
|
19
|
+
} & React.RefAttributes<import("../../types").VirtualizedMenuBaseHandle>>;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useState, useCallback, } from 'react';
|
|
3
|
+
import { StyledAutoSizer, VirtualizedMenuContainer } from '../../styled';
|
|
4
|
+
import { INLINE_INDENT, INLINE_PADDING, ITEM_SIZE, ITEM_SPACING } from '../../config';
|
|
5
|
+
import { CLS, serializeItems, getItemSize } from '../../utils';
|
|
6
|
+
import { Item } from '../Item';
|
|
7
|
+
import { useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks';
|
|
8
|
+
import clsx from 'clsx';
|
|
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 = (props, ref) => {
|
|
106
|
+
const { items: itemsProp = [], inlineIndent = INLINE_INDENT, inlinePadding = INLINE_PADDING, itemSize = ITEM_SIZE, itemSpacing = ITEM_SPACING, selectable = false, expanded: expandedProp = [], selected: selectedProp = [], action, className, onClick, } = props;
|
|
107
|
+
const [expandedKeys, setExpandedKeys] = useState(new Set());
|
|
108
|
+
const [selectedKeys, setSelectedKeys] = useState(new Set());
|
|
109
|
+
const [{ items: normalizeTreeItems, rootItemIds }, setTreeState] = useState({
|
|
110
|
+
items: new Map(),
|
|
111
|
+
rootItemIds: new Set(),
|
|
112
|
+
});
|
|
113
|
+
// Cache for path calculations to avoid redundant work
|
|
114
|
+
const pathCache = useMemo(() => new Map(), []);
|
|
115
|
+
const rootNodes = useMemo(() => findNodes(node => rootItemIds.has(node.id), normalizeTreeItems), [normalizeTreeItems, rootItemIds]);
|
|
116
|
+
useDeepCompareEffect(() => {
|
|
117
|
+
setSelectedKeys(new Set(selectedProp));
|
|
118
|
+
}, [selectedProp]);
|
|
119
|
+
useDeepCompareEffect(() => {
|
|
120
|
+
setExpandedKeys(new Set(expandedProp));
|
|
121
|
+
}, [expandedProp]);
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
setTreeState(serializeItems({
|
|
124
|
+
items: itemsProp,
|
|
125
|
+
}));
|
|
126
|
+
}, [itemsProp]);
|
|
127
|
+
// Clear path cache when tree structure changes
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
pathCache.clear();
|
|
130
|
+
}, [normalizeTreeItems, pathCache]);
|
|
131
|
+
// Optimized visible items calculation
|
|
132
|
+
const visibleItems = useMemo(() => {
|
|
133
|
+
if (normalizeTreeItems.size === 0)
|
|
134
|
+
return [];
|
|
135
|
+
// Choose optimization strategy based on tree characteristics
|
|
136
|
+
const treeDepth = Math.max(...Array.from(normalizeTreeItems.values()).map(item => item.level));
|
|
137
|
+
const totalItems = normalizeTreeItems.size;
|
|
138
|
+
const expandedCount = expandedKeys.size;
|
|
139
|
+
// Strategy selection heuristics:
|
|
140
|
+
// - For shallow trees with many expanded items: use breadth-first
|
|
141
|
+
// - For deep trees with few expanded items: use level-based
|
|
142
|
+
// - For medium trees: use path-cache optimization
|
|
143
|
+
if (treeDepth <= 3 && expandedCount > totalItems * 0.3) {
|
|
144
|
+
// Shallow tree with many expanded items
|
|
145
|
+
return computeVisibleItemsOptimized(normalizeTreeItems, rootItemIds, expandedKeys);
|
|
146
|
+
}
|
|
147
|
+
if (treeDepth > 5 && expandedCount < totalItems * 0.2) {
|
|
148
|
+
// Deep tree with few expanded items
|
|
149
|
+
return computeVisibleItemsByLevel(normalizeTreeItems, rootItemIds, expandedKeys);
|
|
150
|
+
}
|
|
151
|
+
// Medium complexity - use cached path approach
|
|
152
|
+
return computeVisibleItemsWithPathCache(normalizeTreeItems, expandedKeys, pathCache);
|
|
153
|
+
}, [expandedKeys, normalizeTreeItems, rootItemIds, pathCache]);
|
|
154
|
+
const handleCollapseItems = useCallback((items) => {
|
|
155
|
+
setExpandedKeys(prev => {
|
|
156
|
+
const newOpenKeys = new Set(prev);
|
|
157
|
+
items.forEach(({ data }) => {
|
|
158
|
+
if (prev.has(data.key)) {
|
|
159
|
+
newOpenKeys.delete(data.key);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return newOpenKeys;
|
|
163
|
+
});
|
|
164
|
+
}, []);
|
|
165
|
+
const handleExpandItems = useCallback((items, deep = 0) => {
|
|
166
|
+
setExpandedKeys(prev => {
|
|
167
|
+
const updatedExpandedKeys = new Set(prev);
|
|
168
|
+
items.forEach(item => {
|
|
169
|
+
const normalizeItem = normalizeTreeItems.get(item.data.key);
|
|
170
|
+
if (normalizeItem) {
|
|
171
|
+
updatedExpandedKeys.add(normalizeItem.id);
|
|
172
|
+
if (deep > 0) {
|
|
173
|
+
getChildrenRecursively(normalizeItem.id, normalizeTreeItems, normalizeItem.level + deep).forEach(v => updatedExpandedKeys.add(v.id));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return updatedExpandedKeys;
|
|
178
|
+
});
|
|
179
|
+
}, [normalizeTreeItems]);
|
|
180
|
+
useImperativeHandle(ref, () => ({
|
|
181
|
+
expandAll: () => {
|
|
182
|
+
handleExpandItems(rootNodes, Infinity);
|
|
183
|
+
},
|
|
184
|
+
}));
|
|
185
|
+
const handleSelectItem = useCallback((item) => {
|
|
186
|
+
const { key } = item.data;
|
|
187
|
+
if (!selectable || selectedKeys.has(key))
|
|
188
|
+
return;
|
|
189
|
+
setSelectedKeys(new Set([key]));
|
|
190
|
+
}, [selectable, selectedKeys]);
|
|
191
|
+
const handleToggleExpandItem = useCallback((item) => {
|
|
192
|
+
const { key } = item.data;
|
|
193
|
+
const isExpanded = expandedKeys.has(key);
|
|
194
|
+
if (isExpanded) {
|
|
195
|
+
handleCollapseItems([item]);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
handleExpandItems([item]);
|
|
199
|
+
}
|
|
200
|
+
}, [expandedKeys, handleCollapseItems, handleExpandItems]);
|
|
201
|
+
const handleClickItem = useCallback((item) => {
|
|
202
|
+
const node = normalizeTreeItems.get(item.id);
|
|
203
|
+
if (!node)
|
|
204
|
+
return;
|
|
205
|
+
const hasChilren = node.childIds.length > 0;
|
|
206
|
+
handleSelectItem(node);
|
|
207
|
+
if (hasChilren) {
|
|
208
|
+
handleToggleExpandItem(node);
|
|
209
|
+
}
|
|
210
|
+
onClick?.({ item: node.data });
|
|
211
|
+
}, [normalizeTreeItems, handleSelectItem, handleToggleExpandItem, onClick]);
|
|
212
|
+
const itemData = useMemo(() => ({
|
|
213
|
+
itemSpacing,
|
|
214
|
+
inlineIndent,
|
|
215
|
+
inlinePadding,
|
|
216
|
+
selectedKeys,
|
|
217
|
+
expandedKeys,
|
|
218
|
+
action,
|
|
219
|
+
items: visibleItems,
|
|
220
|
+
onClick: handleClickItem,
|
|
221
|
+
}), [
|
|
222
|
+
itemSpacing,
|
|
223
|
+
inlineIndent,
|
|
224
|
+
inlinePadding,
|
|
225
|
+
selectedKeys,
|
|
226
|
+
expandedKeys,
|
|
227
|
+
action,
|
|
228
|
+
visibleItems,
|
|
229
|
+
handleClickItem,
|
|
230
|
+
]);
|
|
231
|
+
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 })) }));
|
|
232
|
+
};
|
|
233
|
+
export const MenuInline = React.forwardRef(MenuInlineInner);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { MenuInline } from './MenuInline';
|
|
1
|
+
export { MenuInline } from './MenuInline.optimized';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { MenuInline } from './MenuInline';
|
|
1
|
+
// export { MenuInline } from './MenuInline';
|
|
2
|
+
export { MenuInline } from './MenuInline.optimized';
|
|
@@ -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>;
|
|
@@ -15,7 +15,7 @@ export const MenuItemWrapper = styled.div `
|
|
|
15
15
|
|
|
16
16
|
.icon-expand {
|
|
17
17
|
font-size: 14px;
|
|
18
|
-
flex-
|
|
18
|
+
flex-shrink: 0;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
.title-wrapper {
|
|
@@ -24,17 +24,20 @@ export const MenuItemWrapper = styled.div `
|
|
|
24
24
|
white-space: nowrap;
|
|
25
25
|
}
|
|
26
26
|
`;
|
|
27
|
-
export const MenuItemRoot = styled.
|
|
27
|
+
export const MenuItemRoot = styled.li `
|
|
28
28
|
&.${CLS.Item.default} {
|
|
29
29
|
cursor: pointer;
|
|
30
30
|
display: flex;
|
|
31
31
|
align-items: center;
|
|
32
32
|
overflow: hidden;
|
|
33
|
-
border-radius: ${THEME.components?.Menu?.itemBorderRadius}px;
|
|
33
|
+
// border-radius: ${THEME.components?.Menu?.itemBorderRadius}px;
|
|
34
34
|
|
|
35
35
|
> .${CLS.ItemLabel.default} {
|
|
36
|
+
display: flex;
|
|
36
37
|
flex: 1;
|
|
37
38
|
overflow: hidden;
|
|
39
|
+
align-self: stretch;
|
|
40
|
+
align-items: center;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
> .${CLS.ItemAction.default} {
|
|
@@ -69,6 +72,11 @@ export const MenuItemRoot = styled.div `
|
|
|
69
72
|
export const VirtualizedMenuContainer = styled((VariableSizeList)) `
|
|
70
73
|
font-size: ${globalToken?.fontSize}px;
|
|
71
74
|
scrollbar-gutter: stable;
|
|
75
|
+
|
|
76
|
+
ul {
|
|
77
|
+
padding: 0;
|
|
78
|
+
margin: 0;
|
|
79
|
+
}
|
|
72
80
|
`;
|
|
73
81
|
export const StyledAutoSizer = styled(AutoSizer) `
|
|
74
82
|
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,16 @@ 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
|
-
pathKey: PathKey;
|
|
32
26
|
}) => void;
|
|
33
27
|
action: React.ReactNode | ((item: ItemType) => React.ReactNode);
|
|
34
28
|
}>;
|
|
35
29
|
export type VirtualizedMenuBaseHandle = {
|
|
36
30
|
expandAll: () => void;
|
|
37
31
|
};
|
|
38
|
-
export type PathKey = (string | number)[];
|
|
39
32
|
export type MenuInlineHandle = VirtualizedMenuBaseHandle;
|
|
40
33
|
export type MenuInlineProps = VirtualizedMenuBaseProps & {
|
|
41
34
|
mode?: typeof MODE.Inline;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="lodash" />
|
|
2
|
-
import { ItemType
|
|
3
|
-
|
|
2
|
+
import { ItemType } from './types';
|
|
3
|
+
import { NormalizedTreeState } from '@antscorp/antsomi-ui/es/utils/tree';
|
|
4
|
+
export declare const itemToTreeNode: (item: ItemType) => any;
|
|
5
|
+
export declare const serializeItems: (args: {
|
|
4
6
|
items: ItemType[];
|
|
5
|
-
}) =>
|
|
7
|
+
}) => NormalizedTreeState<ItemType>;
|
|
6
8
|
export declare const CLS: {
|
|
7
9
|
readonly Root: {
|
|
8
10
|
readonly default: string;
|
|
@@ -29,5 +31,5 @@ export declare const CLS: {
|
|
|
29
31
|
readonly expanded: string;
|
|
30
32
|
};
|
|
31
33
|
};
|
|
32
|
-
export declare const getItemSize: ((itemSize
|
|
33
|
-
export declare const calInlineListSize: (itemLength: number, itemSize
|
|
34
|
+
export declare const getItemSize: ((itemSize?: number, itemSpacing?: number) => (index: number) => number) & import("lodash").MemoizedFunction;
|
|
35
|
+
export declare const calInlineListSize: (itemLength: number, itemSize?: number, itemSpacing?: number) => number;
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import { antsomiClsx } from '@antscorp/antsomi-ui/es/utils';
|
|
2
|
-
import { COMPONENT_NAME, MODE } from './config';
|
|
2
|
+
import { COMPONENT_NAME, ITEM_SIZE, ITEM_SPACING, MODE } from './config';
|
|
3
3
|
import { memoize } from 'lodash';
|
|
4
|
-
|
|
4
|
+
import { normalizeTreeData } from '@antscorp/antsomi-ui/es/utils/tree';
|
|
5
|
+
export const itemToTreeNode = (item) => ({
|
|
6
|
+
id: item.key,
|
|
7
|
+
data: item,
|
|
8
|
+
children: item.children?.map(itemToTreeNode),
|
|
9
|
+
});
|
|
10
|
+
export const serializeItems = (args) => {
|
|
5
11
|
const { items } = args;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
items.forEach((item, idx) => {
|
|
9
|
-
const currentPathKey = [...pathKey, idx, item.key.toString()];
|
|
10
|
-
result.push({ ...item, level, pathKey: currentPathKey, parent });
|
|
11
|
-
if (item.children && item.children.length > 0) {
|
|
12
|
-
recursively(item.children, level + 1, currentPathKey, item);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
if (items.length) {
|
|
17
|
-
recursively(items, 1, [], null);
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
12
|
+
const nodes = items.map(itemToTreeNode);
|
|
13
|
+
return normalizeTreeData(nodes);
|
|
20
14
|
};
|
|
21
15
|
const componentCls = antsomiClsx(COMPONENT_NAME);
|
|
22
16
|
export const CLS = {
|
|
@@ -45,13 +39,13 @@ export const CLS = {
|
|
|
45
39
|
expanded: componentCls('item-expanded'),
|
|
46
40
|
},
|
|
47
41
|
};
|
|
48
|
-
export const getItemSize = memoize((itemSize, itemSpacing) => (index) => {
|
|
42
|
+
export const getItemSize = memoize((itemSize = ITEM_SIZE, itemSpacing = ITEM_SPACING) => (index) => {
|
|
49
43
|
if (index === 0) {
|
|
50
44
|
return itemSize;
|
|
51
45
|
}
|
|
52
46
|
return itemSize + itemSpacing;
|
|
53
47
|
});
|
|
54
|
-
export const calInlineListSize = (itemLength, itemSize, itemSpacing) => {
|
|
48
|
+
export const calInlineListSize = (itemLength, itemSize = ITEM_SIZE, itemSpacing = ITEM_SPACING) => {
|
|
55
49
|
let result = 0;
|
|
56
50
|
const calItemSize = getItemSize(itemSize, itemSpacing);
|
|
57
51
|
for (let i = 0; i < itemLength; i++) {
|
|
@@ -67,6 +67,7 @@ export * from './EmojiCollections';
|
|
|
67
67
|
export * from './EmojiPopover';
|
|
68
68
|
export * from './DisplayFormat';
|
|
69
69
|
export * from './CodeStructure';
|
|
70
|
+
export * from './FontSizeInput';
|
|
70
71
|
export { EditorScript } from './EditorScript';
|
|
71
72
|
export { EditorTab } from './EditorTab';
|
|
72
73
|
export { SelectAccount } from './SelectAccount';
|