@antscorp/antsomi-ui 1.3.5-beta.815 → 1.3.5-beta.816

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.
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { PayloadInfo } from '@antscorp/antsomi-ui/es/types';
2
3
  export type TDisplayFormat = 'number' | 'percentage' | 'currency' | 'datetime';
3
4
  type DisplayFormatProps = {
@@ -1,3 +1,19 @@
1
1
  import React from 'react';
2
- import { VirtualizedMenuProps } from './types';
3
- export declare const VirtualizedMenu: (props: VirtualizedMenuProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
2
+ export declare const VirtualizedMenu: React.ForwardRefExoticComponent<Partial<{
3
+ items: import("./types").ItemType[];
4
+ inlineIndent: number;
5
+ expandIcon: React.ReactNode;
6
+ inlinePadding: number;
7
+ itemSpacing: number;
8
+ selectable: boolean;
9
+ className: string;
10
+ itemSize: number;
11
+ selected: string[];
12
+ expanded: string[];
13
+ onClick: (args: {
14
+ item: import("./types").ItemType;
15
+ pathKey: import("./types").PathKey;
16
+ }) => void;
17
+ }> & Partial<{
18
+ mode: "inline";
19
+ }> & React.RefAttributes<import("./types").VirtualizedMenuBaseHandle>>;
@@ -1,16 +1,17 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from 'react';
2
3
  import { MODE } from './config';
3
4
  import { MenuInline } from './components';
4
- export const VirtualizedMenu = (props) => {
5
+ export const VirtualizedMenu = forwardRef((props, ref) => {
5
6
  const { mode = MODE.Inline } = props;
6
7
  let content = null;
7
8
  switch (mode) {
8
9
  case MODE.Inline: {
9
- content = _jsx(MenuInline, { ...props });
10
+ content = _jsx(MenuInline, { ...props, ref: ref });
10
11
  break;
11
12
  }
12
13
  default:
13
14
  break;
14
15
  }
15
16
  return content;
16
- };
17
+ });
@@ -1,2 +1,20 @@
1
- import { MenuInlineProps } from '../../types';
2
- export declare const MenuInline: (props: MenuInlineProps) => import("react/jsx-runtime").JSX.Element;
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
+ expandIcon: React.ReactNode;
7
+ inlinePadding: number;
8
+ itemSpacing: number;
9
+ selectable: boolean;
10
+ className: string;
11
+ itemSize: number;
12
+ selected: string[];
13
+ expanded: string[];
14
+ onClick: (args: {
15
+ item: ItemType;
16
+ pathKey: import("../../types").PathKey;
17
+ }) => void;
18
+ }> & Partial<{
19
+ mode: "inline";
20
+ }> & React.RefAttributes<import("../../types").VirtualizedMenuBaseHandle>>;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef, useCallback, useMemo, useState } from 'react';
2
+ import { forwardRef, useCallback, useImperativeHandle, useMemo, useState, } from 'react';
3
3
  import clsx from 'clsx';
4
4
  import AutoSizer from 'react-virtualized-auto-sizer';
5
5
  import { VirtualizedMenuContainer } from '../../styled';
@@ -8,74 +8,79 @@ import { getFlattenItems } from '../../utils';
8
8
  import { Item } from '../Item';
9
9
  import { useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks';
10
10
  const innerElementType = forwardRef(({ style, ...rest }, ref) => _jsx("div", { ref: ref, style: style, ...rest }));
11
- export const MenuInline = (props) => {
12
- const { items = [], inlineIndent = INLINE_INDENT, inlinePadding = INLINE_PADDING, itemSize = ITEM_SIZE, itemSpacing = ITEM_SPACING, openKeys: openKeysProp = [], onClick, selectable = false, className, } = props;
13
- const [openKeys, setOpenKeys] = useState(new Set());
11
+ export const MenuInline = forwardRef((props, ref) => {
12
+ const { items = [], inlineIndent = INLINE_INDENT, inlinePadding = INLINE_PADDING, itemSize = ITEM_SIZE, itemSpacing = ITEM_SPACING, onClick, selectable = false, className, expanded: expandedProp = [], selected: selectedProp = [], } = props;
13
+ const [expandedKeys, setExpandedKeys] = useState(new Set());
14
14
  const [selectedKeys, setSelectedKeys] = useState(new Set());
15
15
  useDeepCompareEffect(() => {
16
- if (!openKeysProp)
16
+ if (!selectedProp)
17
17
  return;
18
- setOpenKeys(new Set(openKeysProp));
19
- }, [openKeysProp]);
20
- const flattenItems = useMemo(() => {
21
- const result = getFlattenItems({ items });
22
- return result.filter(item => {
23
- const isRootItem = item.level === 1;
24
- const isParentExpand = item.parent && openKeys.has(String(item.parent.key));
25
- return isRootItem || isParentExpand;
26
- });
27
- }, [items, openKeys]);
28
- const handleCollapseItem = useCallback((item) => {
29
- if (!item.children?.length)
30
- return;
31
- const newOpenKeys = new Set(openKeys);
32
- newOpenKeys.delete(item.key);
33
- if (item.children) {
34
- getFlattenItems({ items: item.children }).forEach(childrenItem => {
35
- const childrenKey = childrenItem.key;
36
- if (newOpenKeys.has(childrenKey)) {
37
- newOpenKeys.delete(childrenKey);
38
- }
39
- });
40
- }
41
- setOpenKeys(newOpenKeys);
42
- }, [openKeys]);
43
- const handleExpandItem = useCallback((item) => {
44
- if (!item.children?.length)
18
+ setSelectedKeys(new Set(selectedProp));
19
+ }, [selectedProp]);
20
+ useDeepCompareEffect(() => {
21
+ if (!expandedProp)
45
22
  return;
46
- const itemKey = item.key;
47
- const newOpenKeys = new Set(openKeys);
48
- newOpenKeys.add(itemKey);
49
- setOpenKeys(newOpenKeys);
50
- }, [openKeys]);
23
+ setExpandedKeys(new Set(expandedProp));
24
+ }, [expandedProp]);
25
+ const flattenItems = useMemo(() => getFlattenItems({ items }), [items]);
26
+ const visibleItems = useMemo(() => flattenItems.filter(item => {
27
+ const isRootItem = item.level === 1;
28
+ const isParentExpand = item.parent && expandedKeys.has(String(item.parent.key));
29
+ return isRootItem || isParentExpand;
30
+ }), [flattenItems, expandedKeys]);
31
+ const handleCollapseItems = useCallback((items) => {
32
+ const newOpenKeys = new Set(expandedKeys);
33
+ getFlattenItems({ items }).forEach(i => {
34
+ const { key } = i;
35
+ if (expandedKeys.has(key)) {
36
+ newOpenKeys.delete(key);
37
+ }
38
+ });
39
+ setExpandedKeys(newOpenKeys);
40
+ }, [expandedKeys]);
41
+ const handleExpandItems = useCallback((items) => {
42
+ const updatedExpandedKeys = new Set(expandedKeys);
43
+ items.forEach(item => {
44
+ if (!item.children?.length)
45
+ return;
46
+ updatedExpandedKeys.add(item.key);
47
+ });
48
+ setExpandedKeys(updatedExpandedKeys);
49
+ }, [expandedKeys]);
50
+ useImperativeHandle(ref, () => ({
51
+ expandAll: () => {
52
+ handleExpandItems(flattenItems);
53
+ },
54
+ }));
51
55
  const handleClickItem = useCallback((item, idx) => () => {
52
56
  const { key } = item;
53
- const isOpen = openKeys.has(key);
57
+ const isOpen = expandedKeys.has(key);
54
58
  const hasChilren = !!item.children?.length;
55
59
  if (hasChilren && isOpen) {
56
- handleCollapseItem(item);
60
+ handleCollapseItems([item]);
57
61
  }
58
62
  if (hasChilren && !isOpen) {
59
- handleExpandItem(item);
63
+ handleExpandItems([item]);
60
64
  }
61
65
  if (selectable && !hasChilren && !selectedKeys.has(key)) {
62
66
  setSelectedKeys(new Set([item.key]));
63
67
  }
64
- if (onClick) {
65
- onClick({ item, pathKey: flattenItems[idx].pathKey });
66
- }
68
+ onClick?.({
69
+ item,
70
+ pathKey: visibleItems[idx].pathKey,
71
+ });
67
72
  }, [
73
+ expandedKeys,
68
74
  selectable,
69
- flattenItems,
70
- handleCollapseItem,
71
- handleExpandItem,
72
- onClick,
73
- openKeys,
75
+ visibleItems,
74
76
  selectedKeys,
77
+ onClick,
78
+ handleCollapseItems,
79
+ handleExpandItems,
75
80
  ]);
76
81
  const renderItem = useCallback((args) => {
77
82
  const { index, style } = args;
78
- const item = flattenItems[index];
83
+ const item = visibleItems[index];
79
84
  const indentSize = ((item.level || 0) - 1) * inlineIndent;
80
85
  const itemStyle = {
81
86
  ...style,
@@ -86,17 +91,16 @@ export const MenuInline = (props) => {
86
91
  };
87
92
  return (_jsx(Item, { className: clsx({
88
93
  'item-selected': selectedKeys.has(item.key),
89
- 'item-expanded': openKeys.has(item.key),
94
+ 'item-expanded': expandedKeys.has(item.key),
90
95
  }, item.className), onClick: handleClickItem(item, index), style: itemStyle, item: item }));
91
96
  }, [
92
- flattenItems,
93
- handleClickItem,
97
+ visibleItems,
94
98
  inlinePadding,
95
99
  inlineIndent,
96
100
  itemSpacing,
97
101
  selectedKeys,
98
- openKeys,
102
+ expandedKeys,
103
+ handleClickItem,
99
104
  ]);
100
- // console.log('render');
101
- return (_jsx(AutoSizer, { children: autoSize => (_jsx(VirtualizedMenuContainer, { className: clsx(`menu-${MODE.Inline}`, className), itemSize: () => itemSize + itemSpacing, itemCount: flattenItems.length, height: autoSize.height, width: autoSize.width, innerElementType: innerElementType, useIsScrolling: true, children: renderItem })) }));
102
- };
105
+ return (_jsx(AutoSizer, { children: autoSize => (_jsx(VirtualizedMenuContainer, { className: clsx(`menu-${MODE.Inline}`, className), itemSize: () => itemSize + itemSpacing, itemCount: visibleItems.length, height: autoSize.height, width: autoSize.width, innerElementType: innerElementType, useIsScrolling: true, children: renderItem })) }));
106
+ });
@@ -1,29 +1,40 @@
1
- import { ComponentPropsWithoutRef, ReactNode } from 'react';
1
+ import { ReactNode } from 'react';
2
2
  import { MODE } from './config';
3
+ export type Mode = (typeof MODE)[keyof typeof MODE];
4
+ export type ItemKey = string;
3
5
  export type ItemType = {
4
- key: string;
6
+ key: ItemKey;
5
7
  } & Partial<{
8
+ className: string;
6
9
  scrollingLabel: string;
7
10
  label: ReactNode;
8
11
  children: ItemType[];
9
12
  disabled: boolean;
10
- }> & Pick<ComponentPropsWithoutRef<'div'>, 'className'>;
11
- export type VirtualizedMenuProps = Partial<{
13
+ }>;
14
+ type VirtualizedMenuBaseProps = Partial<{
12
15
  items: ItemType[];
13
- mode: (typeof MODE)[keyof typeof MODE];
14
- expandIcon: ReactNode;
15
16
  inlineIndent: number;
17
+ expandIcon: ReactNode;
16
18
  inlinePadding: number;
17
19
  itemSpacing: number;
20
+ selectable: boolean;
21
+ className: string;
18
22
  itemSize: number;
19
- openKeys: string[];
20
- selectedKeys: string[];
23
+ selected: string[];
24
+ expanded: string[];
21
25
  onClick: (args: {
22
26
  item: ItemType;
23
27
  pathKey: PathKey;
24
28
  }) => void;
25
- className: string;
26
- selectable: boolean;
27
29
  }>;
30
+ export type VirtualizedMenuBaseHandle = {
31
+ expandAll: () => void;
32
+ };
28
33
  export type PathKey = (string | number)[];
29
- export type MenuInlineProps = Omit<VirtualizedMenuProps, 'mode'>;
34
+ export type MenuInlineHandle = VirtualizedMenuBaseHandle;
35
+ export type MenuInlineProps = VirtualizedMenuBaseProps & Partial<{
36
+ mode: typeof MODE.Inline;
37
+ }>;
38
+ export type VirtualizedMenuHandle = MenuInlineHandle;
39
+ export type VirtualizedMenuProps = MenuInlineProps;
40
+ export {};
@@ -5,11 +5,12 @@ export declare const getFlattenItems: (args: {
5
5
  }) => ({
6
6
  key: string;
7
7
  } & Partial<{
8
+ className: string;
8
9
  scrollingLabel: string;
9
10
  label: import("react").ReactNode;
10
11
  children: ItemType[];
11
12
  disabled: boolean;
12
- }> & Pick<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {
13
+ }> & {
13
14
  level: number;
14
15
  pathKey: PathKey;
15
16
  parent: ItemType | null;
@@ -3,4 +3,5 @@
3
3
  * Asynchronously loads the component for TemplateListing
4
4
  *
5
5
  */
6
+ /// <reference types="react" />
6
7
  export declare const TemplateListing: (props: import("./types").TemplateListingProps<{}>) => JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.815",
3
+ "version": "1.3.5-beta.816",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",