react-magma-dom 4.11.0-next.16 → 4.11.0-next.18

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.
@@ -2,4 +2,8 @@ import * as React from 'react';
2
2
  import { UseTreeItemProps } from './useTreeItem';
3
3
  export interface TreeItemProps extends UseTreeItemProps {
4
4
  }
5
- export declare const TreeItem: React.ForwardRefExoticComponent<TreeItemProps & React.RefAttributes<HTMLLIElement>>;
5
+ /**
6
+ * Memoized TreeItem component
7
+ * Only re-renders when relevant props change, improving performance for large trees
8
+ */
9
+ export declare const TreeItem: React.MemoExoticComponent<React.ForwardRefExoticComponent<TreeItemProps & React.RefAttributes<HTMLLIElement>>>;
@@ -3,7 +3,6 @@ import { IndeterminateCheckboxStatus } from '../IndeterminateCheckbox';
3
3
  interface TreeItemContextInterface {
4
4
  itemId?: string;
5
5
  expanded: boolean;
6
- setExpanded: React.Dispatch<React.SetStateAction<boolean>>;
7
6
  checkedStatus: IndeterminateCheckboxStatus;
8
7
  checkboxChangeHandler: (event: React.ChangeEvent<HTMLInputElement>) => void;
9
8
  hasOwnTreeItems: boolean;
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Context for passing hierarchy information to TreeItems without cloneElement
4
+ * This reduces the overhead of React.cloneElement by providing depth and position
5
+ * information through context instead
6
+ */
7
+ interface TreeItemHierarchyContextInterface {
8
+ depth: number;
9
+ parentDepth: number;
10
+ isTopLevel: boolean;
11
+ index: number;
12
+ }
13
+ export declare const TreeItemHierarchyContext: React.Context<TreeItemHierarchyContextInterface>;
14
+ export {};
@@ -1,5 +1,20 @@
1
1
  import * as React from 'react';
2
2
  import { UseTreeViewProps } from './useTreeView';
3
3
  export interface TreeViewProps extends Omit<React.HTMLAttributes<HTMLUListElement>, 'children'>, UseTreeViewProps {
4
+ /**
5
+ * Enable virtualization for better performance with large trees.
6
+ * @default false
7
+ */
8
+ enableVirtualization?: boolean;
9
+ /**
10
+ * Estimated size of each tree item in pixels (used for virtualization).
11
+ * @default 40
12
+ */
13
+ estimateSize?: number;
14
+ /**
15
+ * Number of items to render above and below the visible area (overscan).
16
+ * @default 5
17
+ */
18
+ overscan?: number;
4
19
  }
5
20
  export declare const TreeView: React.ForwardRefExoticComponent<TreeViewProps & React.RefAttributes<HTMLUListElement>>;
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ import { TreeViewSelectable } from './types';
3
+ export interface ExpandIconInterface {
4
+ size?: number;
5
+ color?: string;
6
+ }
7
+ export interface TreeViewConfigContextInterface {
8
+ hasIcons: boolean;
9
+ selectable: TreeViewSelectable;
10
+ checkParents: boolean;
11
+ checkChildren: boolean;
12
+ isTopLevelSelectable?: boolean;
13
+ expandIconStyles?: ExpandIconInterface;
14
+ registerTreeItem: (itemRefArray: React.MutableRefObject<React.MutableRefObject<Element>[]>, itemRef: React.MutableRefObject<Element>) => void;
15
+ treeItemRefArray?: React.MutableRefObject<React.MutableRefObject<Element>[]>;
16
+ }
17
+ export declare const TreeViewConfigContext: React.Context<TreeViewConfigContextInterface>;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ export interface TreeViewExpansionContextInterface {
3
+ expandedSet: Set<string>;
4
+ handleExpandedChange: (event: React.SyntheticEvent, expandedItemId: string) => void;
5
+ onExpandedChange?: (event: React.SyntheticEvent, expandedItems: Array<string>) => void;
6
+ initialExpandedItems: Array<string>;
7
+ }
8
+ export declare const TreeViewExpansionContext: React.Context<TreeViewExpansionContextInterface>;
@@ -0,0 +1,25 @@
1
+ import * as React from 'react';
2
+ import { TreeViewSelectable } from './types';
3
+ import { IndeterminateCheckboxStatus } from '../IndeterminateCheckbox';
4
+ export interface TreeItemSelectedInterface {
5
+ itemId?: string;
6
+ checkedStatus: IndeterminateCheckboxStatus;
7
+ isDisabled?: boolean;
8
+ }
9
+ export interface TreeViewItemInterface {
10
+ itemId?: string;
11
+ parentId?: string | null;
12
+ icon?: React.ReactNode;
13
+ checkedStatus: IndeterminateCheckboxStatus;
14
+ hasOwnTreeItems: boolean;
15
+ isDisabled?: boolean;
16
+ }
17
+ export interface TreeViewSelectionContextInterface {
18
+ items: TreeViewItemInterface[];
19
+ selectedItems: Array<TreeItemSelectedInterface>;
20
+ selectItem: (data: Pick<TreeViewItemInterface, 'itemId' | 'checkedStatus'>) => void;
21
+ onSelectedItemChange?: (selectedItems: Array<TreeItemSelectedInterface>) => void;
22
+ selectable: TreeViewSelectable;
23
+ itemToFocus?: string;
24
+ }
25
+ export declare const TreeViewSelectionContext: React.Context<TreeViewSelectionContextInterface>;
@@ -5,3 +5,6 @@ export * from './useTreeView';
5
5
  export * from './utils';
6
6
  export * from './types';
7
7
  export { TreeItemSelectedInterface, TreeViewApi } from './useTreeView';
8
+ export * from './TreeViewSelectionContext';
9
+ export * from './TreeViewExpansionContext';
10
+ export * from './TreeViewConfigContext';
@@ -0,0 +1,94 @@
1
+ import { IndeterminateCheckboxStatus } from '../IndeterminateCheckbox';
2
+ import { TreeViewItemInterface } from './TreeViewContext';
3
+ /**
4
+ * TreeView State Shape
5
+ * Consolidates all state managed by the TreeView component
6
+ */
7
+ export interface TreeViewState {
8
+ /** Array of all tree items with their metadata */
9
+ items: TreeViewItemInterface[];
10
+ /** Set of expanded item IDs for O(1) lookup */
11
+ expandedSet: Set<string>;
12
+ /** Flag indicating if items need to be updated (for showAll functionality) */
13
+ itemsNeedUpdate: boolean | null;
14
+ }
15
+ /**
16
+ * TreeView Action Types
17
+ * Defines all possible state mutations
18
+ */
19
+ export declare type TreeViewAction = {
20
+ type: 'SELECT_ITEM';
21
+ payload: {
22
+ itemId: string;
23
+ checkedStatus?: IndeterminateCheckboxStatus;
24
+ selectable: string;
25
+ checkChildren: boolean;
26
+ checkParents: boolean;
27
+ isTopLevelSelectable: boolean;
28
+ };
29
+ } | {
30
+ type: 'SELECT_ALL';
31
+ payload: {
32
+ checkChildren: boolean;
33
+ checkParents: boolean;
34
+ isTopLevelSelectable: boolean;
35
+ };
36
+ } | {
37
+ type: 'CLEAR_ALL';
38
+ payload: {
39
+ checkChildren: boolean;
40
+ checkParents: boolean;
41
+ isTopLevelSelectable: boolean;
42
+ };
43
+ } | {
44
+ type: 'TOGGLE_EXPAND';
45
+ payload: {
46
+ itemId: string | string[];
47
+ };
48
+ } | {
49
+ type: 'EXPAND_ALL';
50
+ payload: {
51
+ expandableIds: string[];
52
+ };
53
+ } | {
54
+ type: 'COLLAPSE_ALL';
55
+ } | {
56
+ type: 'SET_ITEMS';
57
+ payload: {
58
+ items: TreeViewItemInterface[];
59
+ };
60
+ } | {
61
+ type: 'ADD_ITEM';
62
+ payload: {
63
+ newItem: TreeViewItemInterface;
64
+ checkParents: boolean;
65
+ selectable: string;
66
+ };
67
+ } | {
68
+ type: 'UPDATE_ITEMS_DISABLED_STATE';
69
+ payload: {
70
+ updatedItems: TreeViewItemInterface[];
71
+ };
72
+ } | {
73
+ type: 'TRIGGER_ITEMS_UPDATE';
74
+ } | {
75
+ type: 'COMPLETE_ITEMS_UPDATE';
76
+ };
77
+ /**
78
+ * TreeView Reducer
79
+ * Pure function that handles all state transitions
80
+ *
81
+ * State Transitions:
82
+ * - SELECT_ITEM: Updates item selection based on selectable mode (single/multi)
83
+ * - SELECT_ALL: Selects all items in multi-select mode
84
+ * - CLEAR_ALL: Clears all selections
85
+ * - TOGGLE_EXPAND: Toggles expansion state of one or more items
86
+ * - EXPAND_ALL: Expands all expandable items
87
+ * - COLLAPSE_ALL: Collapses all items
88
+ * - SET_ITEMS: Replaces entire items array (used for initialization and updates)
89
+ * - ADD_ITEM: Adds a new item to the tree
90
+ * - UPDATE_ITEMS_DISABLED_STATE: Updates disabled state of items
91
+ * - TRIGGER_ITEMS_UPDATE: Flags that items need updating (for showAll)
92
+ * - COMPLETE_ITEMS_UPDATE: Clears the update flag
93
+ */
94
+ export declare function treeViewReducer(state: TreeViewState, action: TreeViewAction): TreeViewState;
@@ -15,6 +15,12 @@ export interface UseTreeItemProps extends React.HTMLAttributes<HTMLLIElement> {
15
15
  * Icon for the tree item
16
16
  */
17
17
  icon?: React.ReactElement<IconProps>;
18
+ /**
19
+ * Custom height for this item when virtualization is enabled.
20
+ * If not specified, the TreeView's estimateSize will be used.
21
+ * @default undefined (uses TreeView's estimateSize)
22
+ */
23
+ itemSize?: number;
18
24
  /**
19
25
  * If true, element is disabled
20
26
  * @default false
@@ -74,8 +80,7 @@ export declare function useTreeItem(props: UseTreeItemProps, forwardedRef: any):
74
80
  itemId: string;
75
81
  parentDepth: number;
76
82
  ref: (node: any) => void;
77
- selectedItems: import("./TreeViewContext").TreeItemSelectedInterface[];
78
- setExpanded: React.Dispatch<React.SetStateAction<boolean>>;
83
+ selectedItems: import("./TreeViewSelectionContext").TreeItemSelectedInterface[];
79
84
  treeItemChildren: (string | number | {} | React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any>) | (new (props: any) => React.Component<any, any, any>)> | Iterable<React.ReactNode> | React.ReactPortal)[];
80
85
  isDisabled: boolean;
81
86
  };
@@ -112,24 +112,29 @@ interface ExpandIconStylesProps {
112
112
  color?: string;
113
113
  }
114
114
  export declare function useTreeView(props: UseTreeViewProps): {
115
- contextValue: {
116
- hasIcons: any;
117
- itemToFocus: any;
115
+ selectionContextValue: {
116
+ items: TreeViewItemInterface[];
117
+ selectedItems: TreeViewItemInterface[];
118
+ selectItem: ({ itemId, checkedStatus, }: Pick<TreeViewItemInterface, 'itemId'> & Partial<Pick<TreeViewItemInterface, 'checkedStatus'>>) => void;
118
119
  onSelectedItemChange: (selectedItems: TreeItemSelectedInterface[]) => void;
119
- onExpandedChange: (event: React.SyntheticEvent<Element, Event>, expandedItems: string[]) => void;
120
120
  selectable: TreeViewSelectable;
121
- selectedItems: any;
121
+ itemToFocus: string;
122
+ };
123
+ expansionContextValue: {
124
+ expandedSet: Set<string>;
125
+ handleExpandedChange: (event: React.SyntheticEvent, itemId: string | string[]) => void;
126
+ onExpandedChange: (event: React.SyntheticEvent<Element, Event>, expandedItems: string[]) => void;
122
127
  initialExpandedItems: any[];
123
- treeItemRefArray: React.MutableRefObject<React.MutableRefObject<Element>[]>;
124
- registerTreeItem: (refArray: React.MutableRefObject<React.MutableRefObject<Element>[]>, ref: React.MutableRefObject<Element>) => void;
125
- checkChildren: boolean;
128
+ };
129
+ configContextValue: {
130
+ hasIcons: any;
131
+ selectable: TreeViewSelectable;
126
132
  checkParents: boolean;
127
- items: any;
128
- selectItem: ({ itemId, checkedStatus, }: Pick<TreeViewItemInterface, 'itemId'> & Partial<Pick<TreeViewItemInterface, 'checkedStatus'>>) => void;
129
- handleExpandedChange: (event: React.SyntheticEvent, itemId: string | string[]) => void;
130
- expandedSet: Set<string>;
131
- expandIconStyles: ExpandIconStylesProps;
133
+ checkChildren: boolean;
132
134
  isTopLevelSelectable: boolean;
135
+ expandIconStyles: ExpandIconStylesProps;
136
+ registerTreeItem: (refArray: React.MutableRefObject<React.MutableRefObject<Element>[]>, ref: React.MutableRefObject<Element>) => void;
137
+ treeItemRefArray: React.MutableRefObject<React.MutableRefObject<Element>[]>;
133
138
  };
134
139
  };
135
140
  export declare type UseTreeViewReturn = ReturnType<typeof useTreeView>;
@@ -30,10 +30,11 @@ export declare function filterNullEntries(obj: any): {
30
30
  } | {
31
31
  current?: undefined;
32
32
  };
33
- export declare const getChildrenIds: ({ items, itemId, }: {
33
+ export declare const getChildrenIds: ({ items, itemId, parentChildMap, }: {
34
34
  items: TreeViewItemInterface[];
35
35
  itemId: TreeViewItemInterface['itemId'];
36
- }) => any;
36
+ parentChildMap?: Map<string, string[]>;
37
+ }) => string[];
37
38
  export declare const getInitialItems: ({ children, preselectedItems: rawPreselectedItems, checkParents, checkChildren, selectable, isDisabled: isTreeViewDisabled, isTopLevelSelectable, items, }: Pick<UseTreeViewProps, "isDisabled" | "checkChildren" | "selectable" | "preselectedItems" | "checkParents" | "children" | "isTopLevelSelectable"> & {
38
39
  items?: TreeViewItemInterface[];
39
40
  }) => any;
@@ -54,11 +55,11 @@ export declare const toggleMulti: ({ items, itemId, checkedStatus: rawCheckedSta
54
55
  itemId: TreeViewItemInterface['itemId'];
55
56
  checkedStatus: TreeViewItemInterface['checkedStatus'];
56
57
  forceCheckedStatus?: boolean;
57
- } & Pick<UseTreeViewProps, "checkChildren" | "checkParents" | "isTopLevelSelectable">) => any;
58
+ } & Pick<UseTreeViewProps, "checkChildren" | "checkParents" | "isTopLevelSelectable">) => TreeViewItemInterface[];
58
59
  export declare const toggleAllMulti: ({ items, checkedStatus, checkChildren, checkParents, isTopLevelSelectable, }: {
59
60
  items: TreeViewItemInterface[];
60
61
  checkedStatus: TreeViewItemInterface['checkedStatus'];
61
- } & Pick<UseTreeViewProps, "checkChildren" | "checkParents" | "isTopLevelSelectable">) => any;
62
+ } & Pick<UseTreeViewProps, "checkChildren" | "checkParents" | "isTopLevelSelectable">) => TreeViewItemInterface[];
62
63
  export declare const getInitialExpandedIds: ({ items, initialExpandedItems, }: {
63
64
  items: TreeViewItemInterface[];
64
65
  } & Pick<UseTreeViewProps, "initialExpandedItems">) => any[];