@hh.ru/magritte-ui-tree-selector 3.1.2 → 4.0.0

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,19 +1,23 @@
1
1
  import './index.css';
2
- import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
3
- import { forwardRef, useRef, useState, useMemo, useEffect, useImperativeHandle, Fragment as Fragment$1 } from 'react';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import { forwardRef, useRef, useState, useMemo, useEffect, useImperativeHandle, useCallback } from 'react';
4
+ import { useVirtualizer } from '@tanstack/react-virtual';
5
+ import classnames from 'classnames';
4
6
  import { Cell, CellText } from '@hh.ru/magritte-ui-cell';
5
7
  import { CheckableCardElement } from '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
6
8
  import { Action } from './Action.js';
7
9
  import { MobileDelimiter } from './MobileDelimiter.js';
8
10
  import { MobileItem } from './MobileItem.js';
9
11
  import { MobileParentItem } from './MobileParentItem.js';
12
+ import { s as styles } from './tree-selector-item-B5TWpXFy.js';
10
13
  import '@hh.ru/magritte-ui-checkbox-radio';
11
14
  import '@hh.ru/magritte-ui-card';
12
15
  import '@hh.ru/magritte-ui-typography';
13
16
  import './TreeSelectorItemBase.js';
14
17
 
18
+ const DEFAULT_ITEM_HEIGHT = 56;
15
19
  const MobileItemsListComponent = (props, ref) => {
16
- const { collection, selected, disabled, leavesOnly, singleChoice, onChange, checkSelectable, getMobileSearchItemOrder, setInputValue, handleChangeInput, isSearch, renderMobileDelimiter, renderItem, contentFilterQuery, getSelectAllParentTrl, onMobileNavigationChange, } = props;
20
+ const { collection, selected, disabled, leavesOnly, singleChoice, onChange, checkSelectable, getMobileSearchItemOrder, setInputValue, handleChangeInput, isSearch, renderMobileDelimiter, renderItem, contentFilterQuery, getSelectAllParentTrl, renderContentBefore, onMobileNavigationChange, } = props;
17
21
  const navigationChangeCallback = useRef(onMobileNavigationChange);
18
22
  navigationChangeCallback.current = onMobileNavigationChange;
19
23
  const prevParentIds = useRef([]);
@@ -21,18 +25,40 @@ const MobileItemsListComponent = (props, ref) => {
21
25
  const currentQuery = useRef(contentFilterQuery);
22
26
  const [currentParentId, setCurrentParentId] = useState();
23
27
  const items = useMemo(() => (currentParentId ? collection.getChildren(currentParentId) : collection.getTopLevel()), [currentParentId, collection]);
24
- const { itemsByOrder, sortedOrders } = useMemo(() => {
25
- const orders = new Set();
26
- const itemsByOrder = items.reduce((acc, item) => {
27
- const modelOrder = isSearch && !currentParentId ? getMobileSearchItemOrder(item) : 0;
28
- orders.add(modelOrder);
29
- acc[modelOrder] = acc[modelOrder] || [];
30
- acc[modelOrder].push(item);
28
+ const orderHashMap = useMemo(() => {
29
+ return items.reduce((acc, item) => {
30
+ acc[item.id] = isSearch && !currentParentId ? getMobileSearchItemOrder(item) : 0;
31
31
  return acc;
32
32
  }, {});
33
- return { itemsByOrder, sortedOrders: [...orders].sort((a, b) => a - b) };
34
33
  }, [items, isSearch, currentParentId, getMobileSearchItemOrder]);
34
+ const sortedItems = useMemo(() => {
35
+ return items.sort((itemA, itemB) => {
36
+ return orderHashMap[itemA.id] - orderHashMap[itemB.id];
37
+ });
38
+ }, [items, orderHashMap]);
35
39
  const isSelectable = currentParentId && !leavesOnly && checkSelectable?.(currentParentId, collection);
40
+ const withContentBefore = !!renderContentBefore;
41
+ const count = items.length + (isSelectable ? 1 : 0) + (withContentBefore ? 1 : 0);
42
+ const parentRef = useRef(null);
43
+ const getItemKey = (index) => {
44
+ if (withContentBefore && index === 0) {
45
+ return 'promo';
46
+ }
47
+ const isSelectAllItem = isSelectable && ((index === 0 && !withContentBefore) || (index === 1 && withContentBefore));
48
+ if (isSelectAllItem) {
49
+ return `current${currentParentId}`;
50
+ }
51
+ const itemIndex = index - (isSelectable ? 1 : 0) - (withContentBefore ? 1 : 0);
52
+ const item = sortedItems[itemIndex];
53
+ return currentParentId ? `${currentParentId}${item.id}` : `${item.id}`;
54
+ };
55
+ const virtualizer = useVirtualizer({
56
+ count,
57
+ getScrollElement: () => parentRef.current,
58
+ estimateSize: () => DEFAULT_ITEM_HEIGHT,
59
+ getItemKey,
60
+ });
61
+ const itemsVirtualizer = virtualizer.getVirtualItems();
36
62
  useEffect(() => {
37
63
  setCurrentParentId(undefined);
38
64
  prevParentIds.current = [];
@@ -42,40 +68,68 @@ const MobileItemsListComponent = (props, ref) => {
42
68
  }, [contentFilterQuery]);
43
69
  useImperativeHandle(ref, () => ({
44
70
  back: () => {
45
- const prevParentId = prevParentIds.current.pop();
46
- setCurrentParentId(prevParentId);
47
- navigationChangeCallback.current?.(prevParentId);
48
- if (prevQueries.current.length) {
49
- const prevInputValue = prevQueries.current.pop();
50
- setInputValue(prevInputValue);
51
- currentQuery.current = prevInputValue;
52
- }
53
- else {
54
- handleChangeInput('');
71
+ if (!virtualizer.isScrolling) {
72
+ const prevParentId = prevParentIds.current.pop();
73
+ setCurrentParentId(prevParentId);
74
+ navigationChangeCallback.current?.(prevParentId);
75
+ if (prevQueries.current.length) {
76
+ const prevInputValue = prevQueries.current.pop();
77
+ setInputValue(prevInputValue);
78
+ currentQuery.current = prevInputValue;
79
+ }
80
+ else {
81
+ handleChangeInput('');
82
+ }
55
83
  }
56
84
  },
57
- }), [handleChangeInput, setInputValue]);
58
- return (jsxs(Fragment, { children: [isSelectable && (jsx(CheckableCardElement, { padding: 16, borderRadius: 12, Element: "label", checked: selected.includes(currentParentId), "data-qa": `tree-selector-select-all-${currentParentId}`, children: jsx(Cell, { Element: 'div', disabled: disabled.includes(currentParentId), right: jsx(Action, { selected: selected.includes(currentParentId), onChange: onChange, id: currentParentId, singleChoice: singleChoice }), children: jsx(CellText, { children: getSelectAllParentTrl(currentParentId) }) }) })), sortedOrders.map((order) => {
59
- return itemsByOrder[order].map((item, index) => {
60
- const hasChildren = collection.hasChildren(item.id);
61
- const hasLetter = item.additional?.char && !isSearch;
62
- const delimiterContent = renderMobileDelimiter?.({
63
- item,
64
- order,
65
- isSearch,
66
- index,
67
- isTopLevel: !currentParentId,
68
- });
69
- return (jsxs(Fragment$1, { children: [hasLetter && jsx(MobileDelimiter, { children: item.additional?.char }), delimiterContent && jsx(MobileDelimiter, { children: delimiterContent }), hasChildren ? (jsx(MobileParentItem, { collection: collection, item: item, selected: selected, onClick: () => {
70
- prevParentIds.current.push(currentParentId);
71
- prevQueries.current.push(currentQuery.current);
72
- setCurrentParentId(item.id);
73
- setInputValue('');
74
- currentQuery.current = '';
75
- navigationChangeCallback.current?.(item.id);
76
- }, isSearch: isSearch, renderItem: renderItem })) : (jsx(MobileItem, { item: item, singleChoice: singleChoice, isSelectable: checkSelectable?.(item.id, collection), isSelected: selected.includes(item.id), isDisabled: disabled.includes(item.id), onChange: onChange, isSearch: isSearch, renderItem: renderItem }, item.id))] }, item.id));
77
- });
78
- })] }));
85
+ }), [handleChangeInput, setInputValue, virtualizer]);
86
+ const refCallback = useCallback((node) => {
87
+ parentRef.current = node ? node.parentElement : null;
88
+ }, []);
89
+ useEffect(() => {
90
+ virtualizer.scrollToOffset(0);
91
+ }, [currentParentId, sortedItems, virtualizer]);
92
+ return (jsx("div", { ref: refCallback, className: styles.virtualizedList, style: {
93
+ height: `${virtualizer.getTotalSize()}px`,
94
+ }, children: itemsVirtualizer.map((virtualItem) => {
95
+ const isContentBeforeItem = withContentBefore && virtualItem.index === 0;
96
+ const isSelectAllItem = isSelectable &&
97
+ ((virtualItem.index === 0 && !withContentBefore) || (virtualItem.index === 1 && withContentBefore));
98
+ if (isContentBeforeItem) {
99
+ return (jsx("div", { ref: virtualizer.measureElement, "data-index": virtualItem.index, className: styles.virtualizedItem, style: {
100
+ transform: `translateY(${virtualItem.start}px)`,
101
+ }, children: renderContentBefore(isSearch) }, virtualItem.key));
102
+ }
103
+ if (isSelectAllItem) {
104
+ return (jsx("div", { ref: virtualizer.measureElement, "data-index": virtualItem.index, className: styles.virtualizedItem, style: {
105
+ transform: `translateY(${virtualItem.start}px)`,
106
+ }, children: jsx("div", { className: styles.mobileItem, children: jsx(CheckableCardElement, { padding: 16, flexible: true, borderRadius: 12, Element: "label", checked: selected.includes(currentParentId), "data-qa": `tree-selector-select-all-${currentParentId}`, children: jsx(Cell, { Element: 'div', disabled: disabled.includes(currentParentId), right: jsx(Action, { selected: selected.includes(currentParentId), onChange: onChange, id: currentParentId, singleChoice: singleChoice }), children: jsx(CellText, { children: getSelectAllParentTrl(currentParentId) }) }) }) }) }, virtualItem.key));
107
+ }
108
+ const itemIndex = virtualItem.index - (isSelectable ? 1 : 0) - (withContentBefore ? 1 : 0);
109
+ const item = sortedItems[itemIndex];
110
+ const hasChildren = collection.hasChildren(item.id);
111
+ const hasLetter = item.additional?.char && !isSearch;
112
+ const delimiterContent = renderMobileDelimiter?.({
113
+ item,
114
+ order: orderHashMap[item.id],
115
+ isSearch,
116
+ index: itemIndex,
117
+ isTopLevel: !currentParentId,
118
+ });
119
+ const withGap = (!!withContentBefore && virtualItem.index !== 1) || (!withContentBefore && virtualItem.index !== 0);
120
+ return (jsx("div", { ref: virtualizer.measureElement, "data-index": virtualItem.index, style: {
121
+ transform: `translateY(${virtualItem.start}px)`,
122
+ }, className: classnames(styles.virtualizedItem, {
123
+ [styles.withGap]: withGap,
124
+ }), children: jsxs("div", { className: styles.mobileItem, children: [hasLetter && jsx(MobileDelimiter, { children: item.additional?.char }), delimiterContent && jsx(MobileDelimiter, { children: delimiterContent }), hasChildren ? (jsx(MobileParentItem, { collection: collection, item: item, selected: selected, onClick: () => {
125
+ prevParentIds.current.push(currentParentId);
126
+ prevQueries.current.push(currentQuery.current);
127
+ setCurrentParentId(item.id);
128
+ setInputValue('');
129
+ currentQuery.current = '';
130
+ navigationChangeCallback.current?.(item.id);
131
+ }, isSearch: isSearch, renderItem: renderItem })) : (jsx(MobileItem, { item: item, singleChoice: singleChoice, isSelectable: checkSelectable?.(item.id, collection), isSelected: selected.includes(item.id), isDisabled: disabled.includes(item.id), onChange: onChange, isSearch: isSearch, renderItem: renderItem }))] }) }, virtualItem.key));
132
+ }) }));
79
133
  };
80
134
  const MobileItemsList = forwardRef(MobileItemsListComponent);
81
135
 
@@ -1 +1 @@
1
- {"version":3,"file":"MobileItemsList.js","sources":["../src/MobileItemsList.tsx"],"sourcesContent":["import {\n ReactElement,\n Fragment,\n useMemo,\n useState,\n useImperativeHandle,\n forwardRef,\n ForwardedRef,\n useRef,\n useEffect,\n} from 'react';\n\nimport { Cell, CellText } from '@hh.ru/magritte-ui-cell';\nimport { CheckableCardElement } from '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';\nimport { Action } from '@hh.ru/magritte-ui-tree-selector/Action';\nimport { MobileDelimiter } from '@hh.ru/magritte-ui-tree-selector/MobileDelimiter';\nimport { MobileItem } from '@hh.ru/magritte-ui-tree-selector/MobileItem';\nimport { MobileParentItem } from '@hh.ru/magritte-ui-tree-selector/MobileParentItem';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { ListControls, TreeSelectorDummyProps } from '@hh.ru/magritte-ui-tree-selector/types';\n\ntype MobileItemsListProps<Additional extends AdditionalDefault> = {\n selected: string[];\n disabled: string[];\n getMobileSearchItemOrder: (model: TreeModel<Additional>) => number;\n setInputValue: (newValue: string) => void;\n handleChangeInput: (newValue: string) => void;\n contentFilterQuery: string;\n isSearch: boolean;\n} & Pick<\n TreeSelectorDummyProps<Additional>,\n | 'collection'\n | 'leavesOnly'\n | 'singleChoice'\n | 'checkSelectable'\n | 'onChange'\n | 'renderItem'\n | 'renderMobileDelimiter'\n | 'onMobileNavigationChange'\n | 'getSelectAllParentTrl'\n>;\n\nconst MobileItemsListComponent = <Additional extends AdditionalDefault>(\n props: MobileItemsListProps<Additional>,\n ref: ForwardedRef<ListControls>\n): ReactElement => {\n const {\n collection,\n selected,\n disabled,\n leavesOnly,\n singleChoice,\n onChange,\n checkSelectable,\n getMobileSearchItemOrder,\n setInputValue,\n handleChangeInput,\n isSearch,\n renderMobileDelimiter,\n renderItem,\n contentFilterQuery,\n getSelectAllParentTrl,\n onMobileNavigationChange,\n } = props;\n const navigationChangeCallback = useRef(onMobileNavigationChange);\n navigationChangeCallback.current = onMobileNavigationChange;\n const prevParentIds = useRef<(string | undefined)[]>([]);\n const prevQueries = useRef<string[]>([]);\n const currentQuery = useRef(contentFilterQuery);\n const [currentParentId, setCurrentParentId] = useState<string | undefined>();\n const items = useMemo(\n () => (currentParentId ? collection.getChildren(currentParentId) : collection.getTopLevel()),\n [currentParentId, collection]\n );\n const { itemsByOrder, sortedOrders } = useMemo(() => {\n const orders = new Set<number>();\n const itemsByOrder = items.reduce<Record<number, TreeModel<Additional>[]>>((acc, item) => {\n const modelOrder = isSearch && !currentParentId ? getMobileSearchItemOrder(item) : 0;\n orders.add(modelOrder);\n acc[modelOrder] = acc[modelOrder] || [];\n acc[modelOrder].push(item);\n return acc;\n }, {});\n return { itemsByOrder, sortedOrders: [...orders].sort((a, b) => a - b) };\n }, [items, isSearch, currentParentId, getMobileSearchItemOrder]);\n\n const isSelectable = currentParentId && !leavesOnly && checkSelectable?.(currentParentId, collection);\n\n useEffect(() => {\n setCurrentParentId(undefined);\n prevParentIds.current = [];\n prevQueries.current = [];\n navigationChangeCallback.current?.(undefined);\n currentQuery.current = contentFilterQuery;\n }, [contentFilterQuery]);\n\n useImperativeHandle(\n ref,\n () => ({\n back: () => {\n const prevParentId = prevParentIds.current.pop();\n setCurrentParentId(prevParentId);\n navigationChangeCallback.current?.(prevParentId);\n if (prevQueries.current.length) {\n const prevInputValue = prevQueries.current.pop() as string;\n setInputValue(prevInputValue);\n currentQuery.current = prevInputValue;\n } else {\n handleChangeInput('');\n }\n },\n }),\n [handleChangeInput, setInputValue]\n );\n return (\n <>\n {isSelectable && (\n <CheckableCardElement\n padding={16}\n borderRadius={12}\n Element=\"label\"\n checked={selected.includes(currentParentId)}\n data-qa={`tree-selector-select-all-${currentParentId}`}\n >\n <Cell\n Element={'div'}\n disabled={disabled.includes(currentParentId)}\n right={\n <Action\n selected={selected.includes(currentParentId)}\n onChange={onChange}\n id={currentParentId}\n singleChoice={singleChoice}\n />\n }\n >\n <CellText>{getSelectAllParentTrl(currentParentId)}</CellText>\n </Cell>\n </CheckableCardElement>\n )}\n {sortedOrders.map((order) => {\n return itemsByOrder[order].map((item, index) => {\n const hasChildren = collection.hasChildren(item.id);\n const hasLetter = item.additional?.char && !isSearch;\n const delimiterContent = renderMobileDelimiter?.({\n item,\n order,\n isSearch,\n index,\n isTopLevel: !currentParentId,\n });\n return (\n <Fragment key={item.id}>\n {hasLetter && <MobileDelimiter>{item.additional?.char}</MobileDelimiter>}\n {delimiterContent && <MobileDelimiter>{delimiterContent}</MobileDelimiter>}\n {hasChildren ? (\n <MobileParentItem\n collection={collection}\n item={item}\n selected={selected}\n onClick={() => {\n prevParentIds.current.push(currentParentId);\n prevQueries.current.push(currentQuery.current);\n setCurrentParentId(item.id);\n setInputValue('');\n currentQuery.current = '';\n navigationChangeCallback.current?.(item.id);\n }}\n isSearch={isSearch}\n renderItem={renderItem}\n />\n ) : (\n <MobileItem\n key={item.id}\n item={item}\n singleChoice={singleChoice}\n isSelectable={checkSelectable?.(item.id, collection)}\n isSelected={selected.includes(item.id)}\n isDisabled={disabled.includes(item.id)}\n onChange={onChange}\n isSearch={isSearch}\n renderItem={renderItem}\n />\n )}\n </Fragment>\n );\n });\n })}\n </>\n );\n};\n\nexport const MobileItemsList = forwardRef(MobileItemsListComponent) as <Additional extends AdditionalDefault>(\n props: MobileItemsListProps<Additional> & { ref?: ForwardedRef<ListControls> }\n) => ReactElement;\n"],"names":["_jsxs","_jsx","Fragment"],"mappings":";;;;;;;;;;;;;AA0CA,MAAM,wBAAwB,GAAG,CAC7B,KAAuC,EACvC,GAA+B,KACjB;AACd,IAAA,MAAM,EACF,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,wBAAwB,EACxB,aAAa,EACb,iBAAiB,EACjB,QAAQ,EACR,qBAAqB,EACrB,U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import {\n ReactElement,\n useMemo,\n useState,\n useImperativeHandle,\n forwardRef,\n ForwardedRef,\n useRef,\n useEffect,\n RefCallback,\n useCallback,\n} from 'react';\nimport { useVirtualizer } from '@tanstack/react-virtual';\nimport classnames from 'classnames';\n\nimport { Cell, CellText } from '@hh.ru/magritte-ui-cell';\nimport { CheckableCardElement } from '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';\nimport { Action } from '@hh.ru/magritte-ui-tree-selector/Action';\nimport { MobileDelimiter } from '@hh.ru/magritte-ui-tree-selector/MobileDelimiter';\nimport { MobileItem } from '@hh.ru/magritte-ui-tree-selector/MobileItem';\nimport { MobileParentItem } from '@hh.ru/magritte-ui-tree-selector/MobileParentItem';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { ListControls, TreeSelectorDummyProps } from '@hh.ru/magritte-ui-tree-selector/types';\n\nimport styles from './tree-selector-item.less';\n\nconst DEFAULT_ITEM_HEIGHT = 56;\n\ntype MobileItemsListProps<Additional extends AdditionalDefault> = {\n selected: string[];\n disabled: string[];\n getMobileSearchItemOrder: (model: TreeModel<Additional>) => number;\n setInputValue: (newValue: string) => void;\n handleChangeInput: (newValue: string) => void;\n contentFilterQuery: string;\n isSearch: boolean;\n} & Pick<\n TreeSelectorDummyProps<Additional>,\n | 'collection'\n | 'leavesOnly'\n | 'singleChoice'\n | 'checkSelectable'\n | 'onChange'\n | 'renderItem'\n | 'renderMobileDelimiter'\n | 'onMobileNavigationChange'\n | 'getSelectAllParentTrl'\n | 'renderContentBefore'\n>;\n\nconst MobileItemsListComponent = <Additional extends AdditionalDefault>(\n props: MobileItemsListProps<Additional>,\n ref: ForwardedRef<ListControls>\n): ReactElement => {\n const {\n collection,\n selected,\n disabled,\n leavesOnly,\n singleChoice,\n onChange,\n checkSelectable,\n getMobileSearchItemOrder,\n setInputValue,\n handleChangeInput,\n isSearch,\n renderMobileDelimiter,\n renderItem,\n contentFilterQuery,\n getSelectAllParentTrl,\n renderContentBefore,\n onMobileNavigationChange,\n } = props;\n const navigationChangeCallback = useRef(onMobileNavigationChange);\n navigationChangeCallback.current = onMobileNavigationChange;\n const prevParentIds = useRef<(string | undefined)[]>([]);\n const prevQueries = useRef<string[]>([]);\n const currentQuery = useRef(contentFilterQuery);\n const [currentParentId, setCurrentParentId] = useState<string | undefined>();\n const items = useMemo(\n () => (currentParentId ? collection.getChildren(currentParentId) : collection.getTopLevel()),\n [currentParentId, collection]\n );\n const orderHashMap = useMemo(() => {\n return items.reduce<Record<TreeModel<Additional>['id'], number>>((acc, item) => {\n acc[item.id] = isSearch && !currentParentId ? getMobileSearchItemOrder(item) : 0;\n return acc;\n }, {});\n }, [items, isSearch, currentParentId, getMobileSearchItemOrder]);\n\n const sortedItems = useMemo(() => {\n return items.sort((itemA, itemB) => {\n return orderHashMap[itemA.id] - orderHashMap[itemB.id];\n });\n }, [items, orderHashMap]);\n\n const isSelectable = currentParentId && !leavesOnly && checkSelectable?.(currentParentId, collection);\n const withContentBefore = !!renderContentBefore;\n const count = items.length + (isSelectable ? 1 : 0) + (withContentBefore ? 1 : 0);\n const parentRef = useRef<HTMLElement | null>(null);\n\n const getItemKey = (index: number) => {\n if (withContentBefore && index === 0) {\n return 'promo';\n }\n\n const isSelectAllItem =\n isSelectable && ((index === 0 && !withContentBefore) || (index === 1 && withContentBefore));\n\n if (isSelectAllItem) {\n return `current${currentParentId}`;\n }\n\n const itemIndex = index - (isSelectable ? 1 : 0) - (withContentBefore ? 1 : 0);\n const item = sortedItems[itemIndex];\n\n return currentParentId ? `${currentParentId}${item.id}` : `${item.id}`;\n };\n\n const virtualizer = useVirtualizer({\n count,\n getScrollElement: () => parentRef.current,\n estimateSize: () => DEFAULT_ITEM_HEIGHT,\n getItemKey,\n });\n\n const itemsVirtualizer = virtualizer.getVirtualItems();\n\n useEffect(() => {\n setCurrentParentId(undefined);\n prevParentIds.current = [];\n prevQueries.current = [];\n navigationChangeCallback.current?.(undefined);\n currentQuery.current = contentFilterQuery;\n }, [contentFilterQuery]);\n\n useImperativeHandle(\n ref,\n () => ({\n back: () => {\n if (!virtualizer.isScrolling) {\n const prevParentId = prevParentIds.current.pop();\n setCurrentParentId(prevParentId);\n navigationChangeCallback.current?.(prevParentId);\n if (prevQueries.current.length) {\n const prevInputValue = prevQueries.current.pop() as string;\n setInputValue(prevInputValue);\n currentQuery.current = prevInputValue;\n } else {\n handleChangeInput('');\n }\n }\n },\n }),\n [handleChangeInput, setInputValue, virtualizer]\n );\n\n const refCallback: RefCallback<HTMLDivElement> = useCallback((node) => {\n parentRef.current = node ? node.parentElement : null;\n }, []);\n\n useEffect(() => {\n virtualizer.scrollToOffset(0);\n }, [currentParentId, sortedItems, virtualizer]);\n\n return (\n <div\n ref={refCallback}\n className={styles.virtualizedList}\n style={{\n height: `${virtualizer.getTotalSize()}px`,\n }}\n >\n {itemsVirtualizer.map((virtualItem) => {\n const isContentBeforeItem = withContentBefore && virtualItem.index === 0;\n const isSelectAllItem =\n isSelectable &&\n ((virtualItem.index === 0 && !withContentBefore) || (virtualItem.index === 1 && withContentBefore));\n\n if (isContentBeforeItem) {\n return (\n <div\n key={virtualItem.key}\n ref={virtualizer.measureElement}\n data-index={virtualItem.index}\n className={styles.virtualizedItem}\n style={{\n transform: `translateY(${virtualItem.start}px)`,\n }}\n >\n {renderContentBefore(isSearch)}\n </div>\n );\n }\n if (isSelectAllItem) {\n return (\n <div\n key={virtualItem.key}\n ref={virtualizer.measureElement}\n data-index={virtualItem.index}\n className={styles.virtualizedItem}\n style={{\n transform: `translateY(${virtualItem.start}px)`,\n }}\n >\n <div className={styles.mobileItem}>\n <CheckableCardElement\n padding={16}\n flexible\n borderRadius={12}\n Element=\"label\"\n checked={selected.includes(currentParentId)}\n data-qa={`tree-selector-select-all-${currentParentId}`}\n >\n <Cell\n Element={'div'}\n disabled={disabled.includes(currentParentId)}\n right={\n <Action\n selected={selected.includes(currentParentId)}\n onChange={onChange}\n id={currentParentId}\n singleChoice={singleChoice}\n />\n }\n >\n <CellText>{getSelectAllParentTrl(currentParentId)}</CellText>\n </Cell>\n </CheckableCardElement>\n </div>\n </div>\n );\n }\n const itemIndex = virtualItem.index - (isSelectable ? 1 : 0) - (withContentBefore ? 1 : 0);\n const item = sortedItems[itemIndex];\n const hasChildren = collection.hasChildren(item.id);\n const hasLetter = item.additional?.char && !isSearch;\n const delimiterContent = renderMobileDelimiter?.({\n item,\n order: orderHashMap[item.id],\n isSearch,\n index: itemIndex,\n isTopLevel: !currentParentId,\n });\n const withGap =\n (!!withContentBefore && virtualItem.index !== 1) || (!withContentBefore && virtualItem.index !== 0);\n return (\n <div\n key={virtualItem.key}\n ref={virtualizer.measureElement}\n data-index={virtualItem.index}\n style={{\n transform: `translateY(${virtualItem.start}px)`,\n }}\n className={classnames(styles.virtualizedItem, {\n [styles.withGap]: withGap,\n })}\n >\n <div className={styles.mobileItem}>\n {hasLetter && <MobileDelimiter>{item.additional?.char}</MobileDelimiter>}\n {delimiterContent && <MobileDelimiter>{delimiterContent}</MobileDelimiter>}\n {hasChildren ? (\n <MobileParentItem\n collection={collection}\n item={item}\n selected={selected}\n onClick={() => {\n prevParentIds.current.push(currentParentId);\n prevQueries.current.push(currentQuery.current);\n setCurrentParentId(item.id);\n setInputValue('');\n currentQuery.current = '';\n navigationChangeCallback.current?.(item.id);\n }}\n isSearch={isSearch}\n renderItem={renderItem}\n />\n ) : (\n <MobileItem\n item={item}\n singleChoice={singleChoice}\n isSelectable={checkSelectable?.(item.id, collection)}\n isSelected={selected.includes(item.id)}\n isDisabled={disabled.includes(item.id)}\n onChange={onChange}\n isSearch={isSearch}\n renderItem={renderItem}\n />\n )}\n </div>\n </div>\n );\n })}\n </div>\n );\n};\n\nexport const MobileItemsList = forwardRef(MobileItemsListComponent) as <Additional extends AdditionalDefault>(\n props: MobileItemsListProps<Additional> & { ref?: ForwardedRef<ListControls> }\n) => ReactElement;\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;;;;;;;AA0BA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ParentItem = ({ collection, item, selected, onClick, isSearch, rende
16
16
  return count;
17
17
  }, [collection, selected, item.id]);
18
18
  const labelRight = jsx(LabelRight, { badge: childrenSelectedCount ? childrenSelectedCount.toString() : undefined });
19
- return (jsx(Card, { padding: 16, borderRadius: 12, showBorder: true, actionCard: true, onClick: onClick, "data-qa": `tree-selector-item-${item.id}`, children: renderItem({ item, labelRight, childrenSelectedCount, isSearch, isXS: true, isParent: true }) }));
19
+ return (jsx(Card, { padding: 16, borderRadius: 12, showBorder: true, actionCard: true, stretched: true, onClick: onClick, "data-qa": `tree-selector-item-${item.id}`, children: renderItem({ item, labelRight, childrenSelectedCount, isSearch, isXS: true, isParent: true }) }));
20
20
  };
21
21
 
22
22
  export { MobileParentItem };
@@ -1 +1 @@
1
- {"version":3,"file":"MobileParentItem.js","sources":["../src/MobileParentItem.tsx"],"sourcesContent":["import { ReactElement, useMemo } from 'react';\n\nimport { Card } from '@hh.ru/magritte-ui-card';\nimport { LabelRight } from '@hh.ru/magritte-ui-cell';\nimport { TreeSelectorItemBase } from '@hh.ru/magritte-ui-tree-selector/TreeSelectorItemBase';\nimport TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';\n\ninterface MobileParentItemProps<Additional extends AdditionalDefault> {\n collection: TreeCollection<Additional>;\n item: TreeModel<Additional>;\n selected: string[];\n onClick: () => void;\n renderItem?: RenderItem<Additional>;\n isSearch: boolean;\n}\n\nexport const MobileParentItem = <Additional extends AdditionalDefault>({\n collection,\n item,\n selected,\n onClick,\n isSearch,\n renderItem = TreeSelectorItemBase,\n}: MobileParentItemProps<Additional>): ReactElement => {\n const childrenSelectedCount = useMemo(() => {\n let count = 0;\n collection.walkChildren(item.id, (model) => {\n if (selected.includes(model.id)) {\n count += 1;\n }\n });\n\n return count;\n }, [collection, selected, item.id]);\n\n const labelRight = <LabelRight badge={childrenSelectedCount ? childrenSelectedCount.toString() : undefined} />;\n\n return (\n <Card\n padding={16}\n borderRadius={12}\n showBorder\n actionCard\n onClick={onClick}\n data-qa={`tree-selector-item-${item.id}`}\n >\n {renderItem({ item, labelRight, childrenSelectedCount, isSearch, isXS: true, isParent: true })}\n </Card>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;MAkBa,gBAAgB,GAAG,CAAuC,EACnE,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,UAAU,GAAG,oBAAoB,GACD,KAAkB;AAClD,IAAA,MAAM,qBAAqB,GAAG,OAAO,CAAC,MAAK;QACvC,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,KAAK,KAAI;YACvC,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE;gBAC7B,KAAK,IAAI,CAAC,CAAC;AACd,aAAA;AACL,SAAC,CAAC,CAAC;AAEH,QAAA,OAAO,KAAK,CAAC;KAChB,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAEpC,MAAM,UAAU,GAAGA,GAAC,CAAA,UAAU,IAAC,KAAK,EAAE,qBAAqB,GAAG,qBAAqB,CAAC,QAAQ,EAAE,GAAG,SAAS,GAAI,CAAC;IAE/G,QACIA,IAAC,IAAI,EAAA,EACD,OAAO,EAAE,EAAE,EACX,YAAY,EAAE,EAAE,EAChB,UAAU,EAAA,IAAA,EACV,UAAU,EACV,IAAA,EAAA,OAAO,EAAE,OAAO,EAAA,SAAA,EACP,CAAsB,mBAAA,EAAA,IAAI,CAAC,EAAE,EAAE,EAEvC,QAAA,EAAA,UAAU,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,qBAAqB,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAC3F,CAAA,EACT;AACN;;;;"}
1
+ {"version":3,"file":"MobileParentItem.js","sources":["../src/MobileParentItem.tsx"],"sourcesContent":["import { ReactElement, useMemo } from 'react';\n\nimport { Card } from '@hh.ru/magritte-ui-card';\nimport { LabelRight } from '@hh.ru/magritte-ui-cell';\nimport { TreeSelectorItemBase } from '@hh.ru/magritte-ui-tree-selector/TreeSelectorItemBase';\nimport TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';\n\ninterface MobileParentItemProps<Additional extends AdditionalDefault> {\n collection: TreeCollection<Additional>;\n item: TreeModel<Additional>;\n selected: string[];\n onClick: () => void;\n renderItem?: RenderItem<Additional>;\n isSearch: boolean;\n}\n\nexport const MobileParentItem = <Additional extends AdditionalDefault>({\n collection,\n item,\n selected,\n onClick,\n isSearch,\n renderItem = TreeSelectorItemBase,\n}: MobileParentItemProps<Additional>): ReactElement => {\n const childrenSelectedCount = useMemo(() => {\n let count = 0;\n collection.walkChildren(item.id, (model) => {\n if (selected.includes(model.id)) {\n count += 1;\n }\n });\n\n return count;\n }, [collection, selected, item.id]);\n\n const labelRight = <LabelRight badge={childrenSelectedCount ? childrenSelectedCount.toString() : undefined} />;\n\n return (\n <Card\n padding={16}\n borderRadius={12}\n showBorder\n actionCard\n stretched\n onClick={onClick}\n data-qa={`tree-selector-item-${item.id}`}\n >\n {renderItem({ item, labelRight, childrenSelectedCount, isSearch, isXS: true, isParent: true })}\n </Card>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;MAkBa,gBAAgB,GAAG,CAAuC,EACnE,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,UAAU,GAAG,oBAAoB,GACD,KAAkB;AAClD,IAAA,MAAM,qBAAqB,GAAG,OAAO,CAAC,MAAK;QACvC,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,KAAK,KAAI;YACvC,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE;gBAC7B,KAAK,IAAI,CAAC,CAAC;AACd,aAAA;AACL,SAAC,CAAC,CAAC;AAEH,QAAA,OAAO,KAAK,CAAC;KAChB,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAEpC,MAAM,UAAU,GAAGA,GAAC,CAAA,UAAU,IAAC,KAAK,EAAE,qBAAqB,GAAG,qBAAqB,CAAC,QAAQ,EAAE,GAAG,SAAS,GAAI,CAAC;IAE/G,QACIA,IAAC,IAAI,EAAA,EACD,OAAO,EAAE,EAAE,EACX,YAAY,EAAE,EAAE,EAChB,UAAU,EAAA,IAAA,EACV,UAAU,EAAA,IAAA,EACV,SAAS,EAAA,IAAA,EACT,OAAO,EAAE,OAAO,EACP,SAAA,EAAA,CAAA,mBAAA,EAAsB,IAAI,CAAC,EAAE,CAAE,CAAA,EAAA,QAAA,EAEvC,UAAU,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,qBAAqB,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAC3F,CAAA,EACT;AACN;;;;"}
package/TreeSelector.js CHANGED
@@ -7,12 +7,11 @@ import { useDisabled } from './useDisabled.js';
7
7
  import { useSelected } from './useSelected.js';
8
8
  import '@hh.ru/magritte-common-fuzzy-search';
9
9
  import '@hh.ru/magritte-ui-breakpoint';
10
- import '@hh.ru/magritte-ui-spacing';
11
10
  import './ItemsList.js';
11
+ import '@tanstack/react-virtual';
12
12
  import './Item.js';
13
- import 'react-transition-group';
13
+ import './ItemContent.js';
14
14
  import 'classnames';
15
- import './ItemContent-DQStXvKp.js';
16
15
  import '@hh.ru/magritte-common-keyboard';
17
16
  import '@hh.ru/magritte-ui-icon/icon';
18
17
  import './Action.js';
@@ -20,21 +19,27 @@ import '@hh.ru/magritte-ui-checkbox-radio';
20
19
  import './TreeSelectorItemBase.js';
21
20
  import '@hh.ru/magritte-ui-cell';
22
21
  import '@hh.ru/magritte-ui-typography';
22
+ import './tree-selector-item-B5TWpXFy.js';
23
23
  import './MobileItemsList.js';
24
24
  import '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
25
25
  import './MobileDelimiter.js';
26
26
  import '@hh.ru/magritte-ui-card';
27
27
  import './MobileItem.js';
28
28
  import './MobileParentItem.js';
29
+ import './TreeSelectorWrapper.js';
30
+ import '@hh.ru/magritte-common-resize';
31
+ import '@hh.ru/magritte-common-use-multiple-refs';
32
+ import '@hh.ru/magritte-internal-custom-scroll';
33
+ import '@hh.ru/magritte-ui-bottom-sheet';
34
+ import '@hh.ru/magritte-ui-modal';
29
35
  import './collection/treeCollectionHelper.js';
30
36
  import './collection/treeCollection.js';
31
- import './useAnimationTimeout.js';
32
37
  import './useExpanded.js';
33
38
  import './useIndeterminate.js';
34
39
  import './useRenderInput.js';
35
40
  import '@hh.ru/magritte-common-func-utils';
36
- import '@hh.ru/magritte-common-use-multiple-refs';
37
41
  import '@hh.ru/magritte-ui-input';
42
+ import './useAnimationTimeout.js';
38
43
  import './strategy/selectionStrategy.js';
39
44
  import './strategy/createSingleValueToggler.js';
40
45
  import './strategy/createTreeCollectionToggler.js';
@@ -1 +1 @@
1
- {"version":3,"file":"TreeSelector.js","sources":["../src/TreeSelector.tsx"],"sourcesContent":["import { ForwardedRef, forwardRef, ReactElement, useMemo } from 'react';\n\nimport { TreeSelectorDummy } from '@hh.ru/magritte-ui-tree-selector/TreeSelectorDummy';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport ImmutableSelectionStrategy from '@hh.ru/magritte-ui-tree-selector/strategy/immutableSelectionStrategy';\nimport { TreeSelectorProps, ListControls } from '@hh.ru/magritte-ui-tree-selector/types';\nimport { useDisabled } from '@hh.ru/magritte-ui-tree-selector/useDisabled';\nimport { useSelected } from '@hh.ru/magritte-ui-tree-selector/useSelected';\n\nconst TreeSelectorComponent = <Additional extends AdditionalDefault>(\n props: TreeSelectorProps<Additional>,\n ref: ForwardedRef<ListControls>\n): ReactElement => {\n const {\n value,\n collection,\n singleChoice,\n leavesOnly,\n collapseToParentId,\n checkSelectable,\n onChange,\n disabled,\n maxSelected,\n ...rest\n } = props;\n const strategy = useMemo(\n () =>\n new ImmutableSelectionStrategy(collection, {\n singleChoice,\n leavesOnly,\n checkSelectable,\n }),\n [collection, singleChoice, leavesOnly, checkSelectable]\n );\n\n if (maxSelected && !collapseToParentId && !leavesOnly) {\n throw new Error(\n `Magritte component TreeSelector: maxSelected can be used only with collapseToParentId or leavesOnly`\n );\n }\n\n const { selected, setSelected } = useSelected({\n value,\n strategy,\n collection,\n onChange,\n maxSelected,\n collapseToParentId,\n });\n\n const currentDisabled = useDisabled({ selected, disabled, collection, maxSelected });\n\n return (\n <TreeSelectorDummy\n {...rest}\n value={selected}\n disabled={currentDisabled}\n collection={collection}\n singleChoice={singleChoice}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n onChange={setSelected}\n ref={ref}\n />\n );\n};\n\nexport const TreeSelector = forwardRef(TreeSelectorComponent) as <Additional extends AdditionalDefault>(\n props: TreeSelectorProps<Additional> & { ref?: ForwardedRef<ListControls> }\n) => ReactElement;\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,qBAAqB,GAAG,CAC1B,KAAoC,EACpC,GAA+B,KACjB;IACd,MAAM,EACF,KAAK,EACL,UAAU,EACV,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,GAAG,IAAI,EACV,GAAG,KAAK,CAAC;IACV,MAAM,QAAQ,GAAG,OAAO,CACpB,MACI,IAAI,0BAA0B,CAAC,UAAU,EAAE;QACvC,YAAY;QACZ,UAAU;QACV,eAAe;KAClB,CAAC,EACN,CAAC,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,CAAC,CAC1D,CAAC;AAEF,IAAA,IAAI,WAAW,IAAI,CAAC,kBAAkB,IAAI,CAAC,UAAU,EAAE;AACnD,QAAA,MAAM,IAAI,KAAK,CACX,CAAA,mGAAA,CAAqG,CACxG,CAAC;AACL,KAAA;AAED,IAAA,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,WAAW,CAAC;QAC1C,KAAK;QACL,QAAQ;QACR,UAAU;QACV,QAAQ;QACR,WAAW;QACX,kBAAkB;AACrB,KAAA,CAAC,CAAC;AAEH,IAAA,MAAM,eAAe,GAAG,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;AAErF,IAAA,QACIA,GAAC,CAAA,iBAAiB,EACV,EAAA,GAAA,IAAI,EACR,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,eAAe,EACzB,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,eAAe,EAChC,QAAQ,EAAE,WAAW,EACrB,GAAG,EAAE,GAAG,EAAA,CACV,EACJ;AACN,CAAC,CAAC;MAEW,YAAY,GAAG,UAAU,CAAC,qBAAqB;;;;"}
1
+ {"version":3,"file":"TreeSelector.js","sources":["../src/TreeSelector.tsx"],"sourcesContent":["import { ForwardedRef, forwardRef, ReactElement, useMemo } from 'react';\n\nimport { TreeSelectorDummy } from '@hh.ru/magritte-ui-tree-selector/TreeSelectorDummy';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport ImmutableSelectionStrategy from '@hh.ru/magritte-ui-tree-selector/strategy/immutableSelectionStrategy';\nimport { TreeSelectorProps, ListControls } from '@hh.ru/magritte-ui-tree-selector/types';\nimport { useDisabled } from '@hh.ru/magritte-ui-tree-selector/useDisabled';\nimport { useSelected } from '@hh.ru/magritte-ui-tree-selector/useSelected';\n\nconst TreeSelectorComponent = <Additional extends AdditionalDefault>(\n props: TreeSelectorProps<Additional>,\n ref: ForwardedRef<ListControls>\n): ReactElement => {\n const {\n value,\n collection,\n singleChoice,\n leavesOnly,\n collapseToParentId,\n checkSelectable,\n onChange,\n disabled,\n maxSelected,\n ...rest\n } = props;\n const strategy = useMemo(\n () =>\n new ImmutableSelectionStrategy(collection, {\n singleChoice,\n leavesOnly,\n checkSelectable,\n }),\n [collection, singleChoice, leavesOnly, checkSelectable]\n );\n\n if (maxSelected && !collapseToParentId && !leavesOnly) {\n throw new Error(\n `Magritte component TreeSelector: maxSelected can be used only with collapseToParentId or leavesOnly`\n );\n }\n\n const { selected, setSelected } = useSelected({\n value,\n strategy,\n collection,\n onChange,\n maxSelected,\n collapseToParentId,\n });\n\n const currentDisabled = useDisabled({ selected, disabled, collection, maxSelected });\n\n return (\n <TreeSelectorDummy\n {...rest}\n value={selected}\n disabled={currentDisabled}\n collection={collection}\n singleChoice={singleChoice}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n onChange={setSelected}\n ref={ref}\n />\n );\n};\n\nexport const TreeSelector = forwardRef(TreeSelectorComponent) as <Additional extends AdditionalDefault>(\n props: TreeSelectorProps<Additional> & { ref?: ForwardedRef<ListControls> }\n) => ReactElement;\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,qBAAqB,GAAG,CAC1B,KAAoC,EACpC,GAA+B,KACjB;IACd,MAAM,EACF,KAAK,EACL,UAAU,EACV,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,GAAG,IAAI,EACV,GAAG,KAAK,CAAC;IACV,MAAM,QAAQ,GAAG,OAAO,CACpB,MACI,IAAI,0BAA0B,CAAC,UAAU,EAAE;QACvC,YAAY;QACZ,UAAU;QACV,eAAe;KAClB,CAAC,EACN,CAAC,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,CAAC,CAC1D,CAAC;AAEF,IAAA,IAAI,WAAW,IAAI,CAAC,kBAAkB,IAAI,CAAC,UAAU,EAAE;AACnD,QAAA,MAAM,IAAI,KAAK,CACX,CAAA,mGAAA,CAAqG,CACxG,CAAC;AACL,KAAA;AAED,IAAA,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,WAAW,CAAC;QAC1C,KAAK;QACL,QAAQ;QACR,UAAU;QACV,QAAQ;QACR,WAAW;QACX,kBAAkB;AACrB,KAAA,CAAC,CAAC;AAEH,IAAA,MAAM,eAAe,GAAG,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;AAErF,IAAA,QACIA,GAAC,CAAA,iBAAiB,EACV,EAAA,GAAA,IAAI,EACR,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,eAAe,EACzB,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,eAAe,EAChC,QAAQ,EAAE,WAAW,EACrB,GAAG,EAAE,GAAG,EAAA,CACV,EACJ;AACN,CAAC,CAAC;MAEW,YAAY,GAAG,UAAU,CAAC,qBAAqB;;;;"}
@@ -1,7 +1,7 @@
1
1
  import { ReactElement, ForwardedRef } from 'react';
2
2
  import { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';
3
3
  import { ListControls, TreeSelectorDummyProps } from '@hh.ru/magritte-ui-tree-selector/types';
4
- export declare const TreeSelectorDummyComponent: <Additional extends AdditionalDefault>({ collection: initialCollection, checkSelectable, initialExpanded, value: selected, leavesOnly, singleChoice, disabled, treeFilter, suggestedNotFound, constantlySuggested, renderItemForDesktop, renderItem, renderMobileDelimiter, onExpand, onChange, onChangeFilterQuery, contentNotFound, onMobileNavigationChange, getMobileSearchItemOrder, expandTreeOnSelected, getSelectAllParentTrl, children, }: TreeSelectorDummyProps<Additional>, ref: ForwardedRef<ListControls>) => ReactElement;
4
+ export declare const TreeSelectorDummyComponent: <Additional extends AdditionalDefault>({ collection: initialCollection, checkSelectable, initialExpanded, value: selected, leavesOnly, singleChoice, disabled, treeFilter, suggestedNotFound, constantlySuggested, renderItemForDesktop, renderItem, renderMobileDelimiter, onExpand, onChange, onChangeFilterQuery, contentNotFound, onMobileNavigationChange, getMobileSearchItemOrder, expandTreeOnSelected, getSelectAllParentTrl, renderContentBefore, children, }: TreeSelectorDummyProps<Additional>, ref: ForwardedRef<ListControls>) => ReactElement;
5
5
  export declare const TreeSelectorDummy: <Additional extends AdditionalDefault>(props: import("@hh.ru/magritte-ui-tree-selector/types").BaseTreeSelectorProps<Additional> & import("@hh.ru/magritte-ui-tree-selector/types").DummyProps & {
6
6
  ref?: ForwardedRef<ListControls> | undefined;
7
7
  }) => ReactElement;
@@ -3,18 +3,17 @@ import { jsx, Fragment } from 'react/jsx-runtime';
3
3
  import { forwardRef, useState, useRef, useCallback, useEffect } from 'react';
4
4
  import { match } from '@hh.ru/magritte-common-fuzzy-search';
5
5
  import { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';
6
- import { VSpacingContainer } from '@hh.ru/magritte-ui-spacing';
7
6
  import { ItemsList } from './ItemsList.js';
8
7
  import { MobileItemsList } from './MobileItemsList.js';
8
+ import { TreeSelectorWrapper } from './TreeSelectorWrapper.js';
9
9
  import { filterWithParents } from './collection/treeCollectionHelper.js';
10
- import { useAnimationTimeout } from './useAnimationTimeout.js';
11
10
  import { useExpanded } from './useExpanded.js';
12
11
  import { useIndeterminate } from './useIndeterminate.js';
13
12
  import { useRenderInput } from './useRenderInput.js';
13
+ import '@tanstack/react-virtual';
14
14
  import './Item.js';
15
- import 'react-transition-group';
15
+ import './ItemContent.js';
16
16
  import 'classnames';
17
- import './ItemContent-DQStXvKp.js';
18
17
  import '@hh.ru/magritte-common-keyboard';
19
18
  import '@hh.ru/magritte-ui-icon/icon';
20
19
  import './Action.js';
@@ -22,29 +21,34 @@ import '@hh.ru/magritte-ui-checkbox-radio';
22
21
  import './TreeSelectorItemBase.js';
23
22
  import '@hh.ru/magritte-ui-cell';
24
23
  import '@hh.ru/magritte-ui-typography';
24
+ import './tree-selector-item-B5TWpXFy.js';
25
25
  import '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
26
26
  import './MobileDelimiter.js';
27
27
  import '@hh.ru/magritte-ui-card';
28
28
  import './MobileItem.js';
29
29
  import './MobileParentItem.js';
30
+ import '@hh.ru/magritte-common-resize';
31
+ import '@hh.ru/magritte-common-use-multiple-refs';
32
+ import '@hh.ru/magritte-internal-custom-scroll';
33
+ import '@hh.ru/magritte-ui-bottom-sheet';
34
+ import '@hh.ru/magritte-ui-modal';
30
35
  import './collection/treeCollection.js';
31
36
  import '@hh.ru/magritte-common-func-utils';
32
- import '@hh.ru/magritte-common-use-multiple-refs';
33
37
  import '@hh.ru/magritte-ui-input';
38
+ import './useAnimationTimeout.js';
34
39
 
35
40
  const defaultCheckSelectable = () => true;
36
41
  const defaultArray = [];
37
42
  const needToApply = (query) => {
38
43
  return !!(query && query.length);
39
44
  };
40
- const TreeSelectorDummyComponent = ({ collection: initialCollection, checkSelectable = defaultCheckSelectable, initialExpanded = defaultArray, value: selected, leavesOnly, singleChoice, disabled = defaultArray, treeFilter = filterWithParents, suggestedNotFound = defaultArray, constantlySuggested = defaultArray, renderItemForDesktop, renderItem, renderMobileDelimiter, onExpand, onChange, onChangeFilterQuery, contentNotFound, onMobileNavigationChange, getMobileSearchItemOrder, expandTreeOnSelected = true, getSelectAllParentTrl, children, }, ref) => {
45
+ const TreeSelectorDummyComponent = ({ collection: initialCollection, checkSelectable = defaultCheckSelectable, initialExpanded = defaultArray, value: selected, leavesOnly, singleChoice, disabled = defaultArray, treeFilter = filterWithParents, suggestedNotFound = defaultArray, constantlySuggested = defaultArray, renderItemForDesktop, renderItem, renderMobileDelimiter, onExpand, onChange, onChangeFilterQuery, contentNotFound, onMobileNavigationChange, getMobileSearchItemOrder, expandTreeOnSelected = true, getSelectAllParentTrl, renderContentBefore, children, }, ref) => {
41
46
  const [collection, setCollection] = useState(initialCollection);
42
47
  const [isSearch, setIsSearch] = useState(false);
43
48
  const currentQuery = useRef('');
44
49
  const inputRef = useRef(null);
45
50
  const suggestedNotFoundModels = useRef(initialCollection.getExistModels(suggestedNotFound));
46
51
  const constantlySuggestedModels = useRef(initialCollection.getExistModels(constantlySuggested));
47
- const { animationTimeout } = useAnimationTimeout();
48
52
  const getSearchItemOrderDefault = useCallback((model) => {
49
53
  return initialCollection.getModelLevel(model.id);
50
54
  }, [initialCollection]);
@@ -131,7 +135,7 @@ const TreeSelectorDummyComponent = ({ collection: initialCollection, checkSelect
131
135
  ]);
132
136
  const renderTreeSelector = useCallback(() => {
133
137
  const hasModels = collection.getTopLevel().length;
134
- return (jsx("div", { ref: treeRefCallback, children: hasModels ? (jsx(VSpacingContainer, { default: 12, gteM: 0, children: isMobile ? (jsx(MobileItemsList, { getMobileSearchItemOrder: getMobileSearchItemOrder || getSearchItemOrderDefault, collection: collection, selected: selected, disabled: disabled, onChange: onChange, leavesOnly: leavesOnly, checkSelectable: checkSelectable, singleChoice: singleChoice, ref: ref, setInputValue: setInputValue, renderItem: renderItem, renderMobileDelimiter: renderMobileDelimiter, handleChangeInput: handleChangeInput, contentFilterQuery: contentFilterQuery.trim(), onMobileNavigationChange: onMobileNavigationChange, isSearch: isSearch, getSelectAllParentTrl: getSelectAllParentTrl })) : (jsx(ItemsList, { collection: collection, items: collection.getTopLevel(), leavesOnly: leavesOnly, checkSelectable: checkSelectable, expanded: currentExpanded, onExpansion: handleExpansion, selected: selected, onChange: onChange, disabled: disabled, singleChoice: singleChoice, indeterminate: indeterminate, isSearch: isSearch, renderItemForDesktop: renderItemForDesktop, animationTimeout: animationTimeout })) })) : (jsx(Fragment, { children: contentNotFound })) }));
138
+ return (jsx(TreeSelectorWrapper, { ref: treeRefCallback, children: hasModels ? (jsx(Fragment, { children: isMobile ? (jsx(MobileItemsList, { getMobileSearchItemOrder: getMobileSearchItemOrder || getSearchItemOrderDefault, collection: collection, selected: selected, disabled: disabled, onChange: onChange, leavesOnly: leavesOnly, checkSelectable: checkSelectable, singleChoice: singleChoice, ref: ref, setInputValue: setInputValue, renderItem: renderItem, renderMobileDelimiter: renderMobileDelimiter, handleChangeInput: handleChangeInput, contentFilterQuery: contentFilterQuery.trim(), onMobileNavigationChange: onMobileNavigationChange, isSearch: isSearch, getSelectAllParentTrl: getSelectAllParentTrl, renderContentBefore: renderContentBefore })) : (jsx(ItemsList, { collection: collection, leavesOnly: leavesOnly, checkSelectable: checkSelectable, expanded: currentExpanded, onExpansion: handleExpansion, selected: selected, onChange: onChange, disabled: disabled, singleChoice: singleChoice, indeterminate: indeterminate, isSearch: isSearch, renderItemForDesktop: renderItemForDesktop, renderContentBefore: renderContentBefore })) })) : (jsx(Fragment, { children: contentNotFound })) }));
135
139
  }, [
136
140
  collection,
137
141
  treeRefCallback,
@@ -150,14 +154,14 @@ const TreeSelectorDummyComponent = ({ collection: initialCollection, checkSelect
150
154
  renderMobileDelimiter,
151
155
  handleChangeInput,
152
156
  contentFilterQuery,
153
- getSelectAllParentTrl,
154
157
  onMobileNavigationChange,
155
158
  isSearch,
159
+ getSelectAllParentTrl,
160
+ renderContentBefore,
156
161
  currentExpanded,
157
162
  handleExpansion,
158
163
  indeterminate,
159
164
  renderItemForDesktop,
160
- animationTimeout,
161
165
  contentNotFound,
162
166
  ]);
163
167
  return jsx(Fragment, { children: children({ renderTreeSelector, renderInput }) });
@@ -1 +1 @@
1
- {"version":3,"file":"TreeSelectorDummy.js","sources":["../src/TreeSelectorDummy.tsx"],"sourcesContent":["import { ReactElement, forwardRef, ForwardedRef, useCallback, useEffect, useRef, useState, RefCallback } from 'react';\n\nimport { match } from '@hh.ru/magritte-common-fuzzy-search';\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { VSpacingContainer } from '@hh.ru/magritte-ui-spacing';\nimport { ItemsList } from '@hh.ru/magritte-ui-tree-selector/ItemsList';\nimport { MobileItemsList } from '@hh.ru/magritte-ui-tree-selector/MobileItemsList';\nimport { filterWithParents } from '@hh.ru/magritte-ui-tree-selector/collection/treeCollectionHelper';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { ListControls, TreeSelectorDummyProps } from '@hh.ru/magritte-ui-tree-selector/types';\nimport { useAnimationTimeout } from '@hh.ru/magritte-ui-tree-selector/useAnimationTimeout';\nimport { useExpanded } from '@hh.ru/magritte-ui-tree-selector/useExpanded';\nimport { useIndeterminate } from '@hh.ru/magritte-ui-tree-selector/useIndeterminate';\nimport { useRenderInput } from '@hh.ru/magritte-ui-tree-selector/useRenderInput';\n\nconst defaultCheckSelectable = () => true;\nconst defaultArray: string[] = [];\n\nconst needToApply = (query: string): boolean => {\n return !!(query && query.length);\n};\n\nexport const TreeSelectorDummyComponent = <Additional extends AdditionalDefault>(\n {\n collection: initialCollection,\n checkSelectable = defaultCheckSelectable,\n initialExpanded = defaultArray,\n value: selected,\n leavesOnly,\n singleChoice,\n disabled = defaultArray,\n treeFilter = filterWithParents,\n suggestedNotFound = defaultArray,\n constantlySuggested = defaultArray,\n renderItemForDesktop,\n renderItem,\n renderMobileDelimiter,\n onExpand,\n onChange,\n onChangeFilterQuery,\n contentNotFound,\n onMobileNavigationChange,\n getMobileSearchItemOrder,\n expandTreeOnSelected = true,\n getSelectAllParentTrl,\n children,\n }: TreeSelectorDummyProps<Additional>,\n ref: ForwardedRef<ListControls>\n): ReactElement => {\n const [collection, setCollection] = useState(initialCollection);\n const [isSearch, setIsSearch] = useState(false);\n const currentQuery = useRef('');\n const inputRef = useRef<HTMLInputElement>(null);\n const suggestedNotFoundModels = useRef(initialCollection.getExistModels(suggestedNotFound));\n const constantlySuggestedModels = useRef(initialCollection.getExistModels(constantlySuggested));\n const { animationTimeout } = useAnimationTimeout();\n const getSearchItemOrderDefault = useCallback(\n (model: TreeModel<Additional>) => {\n return initialCollection.getModelLevel(model.id);\n },\n [initialCollection]\n );\n\n const { indeterminate } = useIndeterminate({ collection: initialCollection, selected });\n\n const {\n expanded: currentExpanded,\n setExpanded,\n handleExpansion,\n handleResetExpanded,\n } = useExpanded({\n initialValue: initialExpanded?.slice(),\n selected,\n expandTreeOnSelected,\n collection: initialCollection,\n onExpand,\n });\n const { isMobile } = useBreakpoint();\n\n const { contentFilterQuery, setInputValue, handleChangeInput, renderInput } = useRenderInput(inputRef);\n\n const treeRefCallback: RefCallback<HTMLDivElement> = useCallback(\n (node) => {\n if (!node) {\n handleResetExpanded();\n }\n },\n [handleResetExpanded]\n );\n\n useEffect(() => {\n const contentFilterQueryTrimmed = contentFilterQuery.trim();\n const queryWasChanged = contentFilterQueryTrimmed !== currentQuery.current.trim();\n\n if (queryWasChanged && needToApply(contentFilterQueryTrimmed)) {\n const newExpanded: string[] = [];\n const newCollection = treeFilter(\n initialCollection,\n (item) => match(contentFilterQueryTrimmed, item.text),\n isMobile\n );\n newCollection.toList().forEach((item) => {\n if (newCollection.hasChildren(item.id)) {\n // Если есть в отфильтрованной коллекции есть дочерние элементы,\n // значит они заматчились, и нужно открыть родителя.\n newExpanded.push(item.id);\n } else {\n // Если заматчился только сам родитель, показываем его\n // схлопнутым => нужно добавить его ветку в коллекцию.\n initialCollection.walkChildren(item.id, (child, parents) => {\n newCollection.addModel({ ...child }, parents[0].id);\n });\n }\n });\n\n const filteredIds = newCollection.toList().map((model) => model.id);\n\n // Если в отфильтрованной коллекции нет моделей, но заданы предложенные,\n // то показываем их\n // Если в отфильтрованной коллекции модели есть, то пробуем добавить к ним\n // всегда показывающиеся модели, если их ещё нет в коллекции\n if (!filteredIds.length && suggestedNotFoundModels.current.length) {\n suggestedNotFoundModels.current.forEach((model) => newCollection.addModel({ ...model }));\n } else {\n constantlySuggestedModels.current.forEach((model) => {\n if (!filteredIds.includes(model.id)) {\n newCollection.addModel({ ...model });\n }\n });\n }\n\n setCollection(newCollection);\n currentQuery.current = contentFilterQuery;\n onChangeFilterQuery?.(filteredIds, contentFilterQueryTrimmed);\n setExpanded(newExpanded);\n setIsSearch(true);\n } else if (queryWasChanged) {\n // Запрос не годится для поиска.\n const newExpanded = initialExpanded.slice();\n setCollection(initialCollection);\n\n onChangeFilterQuery?.(\n initialCollection.toList().map((model) => model.id),\n contentFilterQueryTrimmed\n );\n currentQuery.current = contentFilterQuery;\n if (inputRef.current) {\n setExpanded(newExpanded);\n } else {\n handleResetExpanded();\n }\n\n setIsSearch(false);\n }\n }, [\n initialCollection,\n contentFilterQuery,\n treeFilter,\n selected,\n setExpanded,\n isMobile,\n onChangeFilterQuery,\n handleResetExpanded,\n initialExpanded,\n ]);\n\n const renderTreeSelector = useCallback(() => {\n const hasModels = collection.getTopLevel().length;\n return (\n <div ref={treeRefCallback}>\n {hasModels ? (\n <VSpacingContainer default={12} gteM={0}>\n {isMobile ? (\n <MobileItemsList\n getMobileSearchItemOrder={getMobileSearchItemOrder || getSearchItemOrderDefault}\n collection={collection}\n selected={selected}\n disabled={disabled}\n onChange={onChange}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n singleChoice={singleChoice}\n ref={ref}\n setInputValue={setInputValue}\n renderItem={renderItem}\n renderMobileDelimiter={renderMobileDelimiter}\n handleChangeInput={handleChangeInput}\n contentFilterQuery={contentFilterQuery.trim()}\n onMobileNavigationChange={onMobileNavigationChange}\n isSearch={isSearch}\n getSelectAllParentTrl={getSelectAllParentTrl}\n />\n ) : (\n <ItemsList\n collection={collection}\n items={collection.getTopLevel()}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n expanded={currentExpanded}\n onExpansion={handleExpansion}\n selected={selected}\n onChange={onChange}\n disabled={disabled}\n singleChoice={singleChoice}\n indeterminate={indeterminate}\n isSearch={isSearch}\n renderItemForDesktop={renderItemForDesktop}\n animationTimeout={animationTimeout}\n />\n )}\n </VSpacingContainer>\n ) : (\n <>{contentNotFound}</>\n )}\n </div>\n );\n }, [\n collection,\n treeRefCallback,\n isMobile,\n getMobileSearchItemOrder,\n getSearchItemOrderDefault,\n selected,\n disabled,\n onChange,\n leavesOnly,\n checkSelectable,\n singleChoice,\n ref,\n setInputValue,\n renderItem,\n renderMobileDelimiter,\n handleChangeInput,\n contentFilterQuery,\n getSelectAllParentTrl,\n onMobileNavigationChange,\n isSearch,\n currentExpanded,\n handleExpansion,\n indeterminate,\n renderItemForDesktop,\n animationTimeout,\n contentNotFound,\n ]);\n\n return <>{children({ renderTreeSelector, renderInput })}</>;\n};\n\nexport const TreeSelectorDummy = forwardRef(TreeSelectorDummyComponent) as <Additional extends AdditionalDefault>(\n props: TreeSelectorDummyProps<Additional> & { ref?: ForwardedRef<ListControls> }\n) => ReactElement;\n"],"names":["_jsx","_Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,sBAAsB,GAAG,MAAM,IAAI,CAAC;AAC1C,MAAM,YAAY,GAAa,EAAE,CAAC;AAElC,MAAM,WAAW,GAAG,CAAC,KAAa,KAAa;IAC3C,OAAO,CAAC,EAAE,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC,CAAC;AAEK,MAAM,0BAA0B,GAAG,CACtC,EACI,UAAU,EAAE,iBAAiB,EAC7B,eAAe,GAAG,sBAAsB,EACxC,eAAe,GAAG,YAAY,EAC9B,KAAK,EAAE,QAAQ,EACf,UAAU,EACV,YAAY,EACZ,QAAQ,GAAG,YAAY,EACvB,UAAU,GAAG,iBAAiB,EAC9B,iBAAiB,GAAG,YAAY,EAChC,mBAAmB,GAAG,YAAY,EAClC,oBAAoB,EACpB,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,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,EACzB,WAAW,EAAE,eAAe,EAC5B,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,QAAQ,EAClB,oBAAoB,EAAE,oBAAoB,EAC1C,gBAAgB,EAAE,gBAAgB,EAAA,CACpC,CACL,EACe,CAAA,KAEpBA,GAAG,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAA,eAAe,GAAI,CACzB,EAAA,CACC,EACR;AACN,KAAC,EAAE;QACC,UAAU;QACV,eAAe;QACf,QAAQ;QACR,wBAAwB;QACxB,yBAAyB;QACzB,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,UAAU;QACV,eAAe;QACf,YAAY;QACZ,GAAG;QACH,aAAa;QACb,UAAU;QACV,qBAAqB;QACrB,iBAAiB;QACjB,kBAAkB;QAClB,qBAAqB;QACrB,wBAAwB;QACxB,QAAQ;QACR,eAAe;QACf,eAAe;QACf,aAAa;QACb,oBAAoB;QACpB,gBAAgB;QAChB,eAAe;AAClB,KAAA,CAAC,CAAC;IAEH,OAAOD,GAAA,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAG,QAAQ,CAAC,EAAE,kBAAkB,EAAE,WAAW,EAAE,CAAC,EAAA,CAAI,CAAC;AAChE,EAAE;MAEW,iBAAiB,GAAG,UAAU,CAAC,0BAA0B;;;;"}
1
+ {"version":3,"file":"TreeSelectorDummy.js","sources":["../src/TreeSelectorDummy.tsx"],"sourcesContent":["import { ReactElement, forwardRef, ForwardedRef, useCallback, useEffect, useRef, useState, RefCallback } from 'react';\n\nimport { match } from '@hh.ru/magritte-common-fuzzy-search';\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { ItemsList } from '@hh.ru/magritte-ui-tree-selector/ItemsList';\nimport { MobileItemsList } from '@hh.ru/magritte-ui-tree-selector/MobileItemsList';\nimport { TreeSelectorWrapper } from '@hh.ru/magritte-ui-tree-selector/TreeSelectorWrapper';\nimport { filterWithParents } from '@hh.ru/magritte-ui-tree-selector/collection/treeCollectionHelper';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { ListControls, TreeSelectorDummyProps } from '@hh.ru/magritte-ui-tree-selector/types';\nimport { useExpanded } from '@hh.ru/magritte-ui-tree-selector/useExpanded';\nimport { useIndeterminate } from '@hh.ru/magritte-ui-tree-selector/useIndeterminate';\nimport { useRenderInput } from '@hh.ru/magritte-ui-tree-selector/useRenderInput';\n\nconst defaultCheckSelectable = () => true;\nconst defaultArray: string[] = [];\n\nconst needToApply = (query: string): boolean => {\n return !!(query && query.length);\n};\n\nexport const TreeSelectorDummyComponent = <Additional extends AdditionalDefault>(\n {\n collection: initialCollection,\n checkSelectable = defaultCheckSelectable,\n initialExpanded = defaultArray,\n value: selected,\n leavesOnly,\n singleChoice,\n disabled = defaultArray,\n treeFilter = filterWithParents,\n suggestedNotFound = defaultArray,\n constantlySuggested = defaultArray,\n renderItemForDesktop,\n renderItem,\n renderMobileDelimiter,\n onExpand,\n onChange,\n onChangeFilterQuery,\n contentNotFound,\n onMobileNavigationChange,\n getMobileSearchItemOrder,\n expandTreeOnSelected = true,\n getSelectAllParentTrl,\n renderContentBefore,\n children,\n }: TreeSelectorDummyProps<Additional>,\n ref: ForwardedRef<ListControls>\n): ReactElement => {\n const [collection, setCollection] = useState(initialCollection);\n const [isSearch, setIsSearch] = useState(false);\n const currentQuery = useRef('');\n const inputRef = useRef<HTMLInputElement>(null);\n const suggestedNotFoundModels = useRef(initialCollection.getExistModels(suggestedNotFound));\n const constantlySuggestedModels = useRef(initialCollection.getExistModels(constantlySuggested));\n const getSearchItemOrderDefault = useCallback(\n (model: TreeModel<Additional>) => {\n return initialCollection.getModelLevel(model.id);\n },\n [initialCollection]\n );\n\n const { indeterminate } = useIndeterminate({ collection: initialCollection, selected });\n\n const {\n expanded: currentExpanded,\n setExpanded,\n handleExpansion,\n handleResetExpanded,\n } = useExpanded({\n initialValue: initialExpanded?.slice(),\n selected,\n expandTreeOnSelected,\n collection: initialCollection,\n onExpand,\n });\n const { isMobile } = useBreakpoint();\n\n const { contentFilterQuery, setInputValue, handleChangeInput, renderInput } = useRenderInput(inputRef);\n\n const treeRefCallback: RefCallback<HTMLDivElement> = useCallback(\n (node) => {\n if (!node) {\n handleResetExpanded();\n }\n },\n [handleResetExpanded]\n );\n\n useEffect(() => {\n const contentFilterQueryTrimmed = contentFilterQuery.trim();\n const queryWasChanged = contentFilterQueryTrimmed !== currentQuery.current.trim();\n\n if (queryWasChanged && needToApply(contentFilterQueryTrimmed)) {\n const newExpanded: string[] = [];\n const newCollection = treeFilter(\n initialCollection,\n (item) => match(contentFilterQueryTrimmed, item.text),\n isMobile\n );\n newCollection.toList().forEach((item) => {\n if (newCollection.hasChildren(item.id)) {\n // Если есть в отфильтрованной коллекции есть дочерние элементы,\n // значит они заматчились, и нужно открыть родителя.\n newExpanded.push(item.id);\n } else {\n // Если заматчился только сам родитель, показываем его\n // схлопнутым => нужно добавить его ветку в коллекцию.\n initialCollection.walkChildren(item.id, (child, parents) => {\n newCollection.addModel({ ...child }, parents[0].id);\n });\n }\n });\n\n const filteredIds = newCollection.toList().map((model) => model.id);\n\n // Если в отфильтрованной коллекции нет моделей, но заданы предложенные,\n // то показываем их\n // Если в отфильтрованной коллекции модели есть, то пробуем добавить к ним\n // всегда показывающиеся модели, если их ещё нет в коллекции\n if (!filteredIds.length && suggestedNotFoundModels.current.length) {\n suggestedNotFoundModels.current.forEach((model) => newCollection.addModel({ ...model }));\n } else {\n constantlySuggestedModels.current.forEach((model) => {\n if (!filteredIds.includes(model.id)) {\n newCollection.addModel({ ...model });\n }\n });\n }\n\n setCollection(newCollection);\n currentQuery.current = contentFilterQuery;\n onChangeFilterQuery?.(filteredIds, contentFilterQueryTrimmed);\n setExpanded(newExpanded);\n setIsSearch(true);\n } else if (queryWasChanged) {\n // Запрос не годится для поиска.\n const newExpanded = initialExpanded.slice();\n setCollection(initialCollection);\n\n onChangeFilterQuery?.(\n initialCollection.toList().map((model) => model.id),\n contentFilterQueryTrimmed\n );\n currentQuery.current = contentFilterQuery;\n if (inputRef.current) {\n setExpanded(newExpanded);\n } else {\n handleResetExpanded();\n }\n\n setIsSearch(false);\n }\n }, [\n initialCollection,\n contentFilterQuery,\n treeFilter,\n selected,\n setExpanded,\n isMobile,\n onChangeFilterQuery,\n handleResetExpanded,\n initialExpanded,\n ]);\n\n const renderTreeSelector = useCallback(() => {\n const hasModels = collection.getTopLevel().length;\n return (\n <TreeSelectorWrapper ref={treeRefCallback}>\n {hasModels ? (\n <>\n {isMobile ? (\n <MobileItemsList\n getMobileSearchItemOrder={getMobileSearchItemOrder || getSearchItemOrderDefault}\n collection={collection}\n selected={selected}\n disabled={disabled}\n onChange={onChange}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n singleChoice={singleChoice}\n ref={ref}\n setInputValue={setInputValue}\n renderItem={renderItem}\n renderMobileDelimiter={renderMobileDelimiter}\n handleChangeInput={handleChangeInput}\n contentFilterQuery={contentFilterQuery.trim()}\n onMobileNavigationChange={onMobileNavigationChange}\n isSearch={isSearch}\n getSelectAllParentTrl={getSelectAllParentTrl}\n renderContentBefore={renderContentBefore}\n />\n ) : (\n <ItemsList\n collection={collection}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n expanded={currentExpanded}\n onExpansion={handleExpansion}\n selected={selected}\n onChange={onChange}\n disabled={disabled}\n singleChoice={singleChoice}\n indeterminate={indeterminate}\n isSearch={isSearch}\n renderItemForDesktop={renderItemForDesktop}\n renderContentBefore={renderContentBefore}\n />\n )}\n </>\n ) : (\n <>{contentNotFound}</>\n )}\n </TreeSelectorWrapper>\n );\n }, [\n collection,\n treeRefCallback,\n isMobile,\n getMobileSearchItemOrder,\n getSearchItemOrderDefault,\n selected,\n disabled,\n onChange,\n leavesOnly,\n checkSelectable,\n singleChoice,\n ref,\n setInputValue,\n renderItem,\n renderMobileDelimiter,\n handleChangeInput,\n contentFilterQuery,\n onMobileNavigationChange,\n isSearch,\n getSelectAllParentTrl,\n renderContentBefore,\n currentExpanded,\n handleExpansion,\n indeterminate,\n renderItemForDesktop,\n contentNotFound,\n ]);\n\n return <>{children({ renderTreeSelector, renderInput })}</>;\n};\n\nexport const TreeSelectorDummy = forwardRef(TreeSelectorDummyComponent) as <Additional extends AdditionalDefault>(\n props: TreeSelectorDummyProps<Additional> & { ref?: ForwardedRef<ListControls> }\n) => ReactElement;\n"],"names":["_jsx","_Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAM,sBAAsB,GAAG,MAAM,IAAI,CAAC;AAC1C,MAAM,YAAY,GAAa,EAAE,CAAC;AAElC,MAAM,WAAW,GAAG,CAAC,KAAa,KAAa;IAC3C,OAAO,CAAC,EAAE,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC,CAAC;AAEK,MAAM,0BAA0B,GAAG,CACtC,EACI,UAAU,EAAE,iBAAiB,EAC7B,eAAe,GAAG,sBAAsB,EACxC,eAAe,GAAG,YAAY,EAC9B,KAAK,EAAE,QAAQ,EACf,UAAU,EACV,YAAY,EACZ,QAAQ,GAAG,YAAY,EACvB,UAAU,GAAG,iBAAiB,EAC9B,iBAAiB,GAAG,YAAY,EAChC,mBAAmB,GAAG,YAAY,EAClC,oBAAoB,EACpB,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,GAAG,IAAI,EAC3B,qBAAqB,EACrB,mBAAmB,EACnB,QAAQ,GACyB,EACrC,GAA+B,KACjB;IACd,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IAChE,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,Q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AA,eAAe,GAAI,CACzB,EAAA,CACiB,EACxB;AACN,KAAC,EAAE;QACC,UAAU;QACV,eAAe;QACf,QAAQ;QACR,wBAAwB;QACxB,yBAAyB;QACzB,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,UAAU;QACV,eAAe;QACf,YAAY;QACZ,GAAG;QACH,aAAa;QACb,UAAU;QACV,qBAAqB;QACrB,iBAAiB;QACjB,kBAAkB;QAClB,wBAAwB;QACxB,QAAQ;QACR,qBAAqB;QACrB,mBAAmB;QACnB,eAAe;QACf,eAAe;QACf,aAAa;QACb,oBAAoB;QACpB,eAAe;AAClB,KAAA,CAAC,CAAC;IAEH,OAAOD,GAAA,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAG,QAAQ,CAAC,EAAE,kBAAkB,EAAE,WAAW,EAAE,CAAC,EAAA,CAAI,CAAC;AAChE,EAAE;MAEW,iBAAiB,GAAG,UAAU,CAAC,0BAA0B;;;;"}
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare const TreeSelectorWrapper: import("react").ForwardRefExoticComponent<{
3
+ children?: import("react").ReactNode;
4
+ } & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,44 @@
1
+ import './index.css';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { forwardRef, useState, useRef, useContext, useCallback, useLayoutEffect, useEffect } from 'react';
4
+ import { useResize } from '@hh.ru/magritte-common-resize';
5
+ import { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';
6
+ import { CustomScrollContext } from '@hh.ru/magritte-internal-custom-scroll';
7
+ import { BottomSheetFullScreenContent } from '@hh.ru/magritte-ui-bottom-sheet';
8
+ import { ModalContentFullHeight } from '@hh.ru/magritte-ui-modal';
9
+
10
+ const TreeSelectorWrapper = forwardRef((props, ref) => {
11
+ const [height, setHeight] = useState(0);
12
+ const wrapperRef = useRef(null);
13
+ const wrapperMultiRef = useMultipleRefs(wrapperRef, ref);
14
+ const scrollContext = useContext(CustomScrollContext);
15
+ const calcHeight = useCallback(() => {
16
+ if (wrapperRef.current?.parentElement) {
17
+ const style = window.getComputedStyle(wrapperRef.current.parentElement) || {};
18
+ const paddingTop = parseFloat(style.paddingTop || '0');
19
+ const paddingBottom = parseFloat(style.paddingBottom || '0');
20
+ const height = wrapperRef.current.parentElement.offsetHeight - paddingTop - paddingBottom;
21
+ setHeight(height);
22
+ }
23
+ }, []);
24
+ useLayoutEffect(() => {
25
+ calcHeight();
26
+ }, [calcHeight]);
27
+ useEffect(() => {
28
+ const wrapperElement = wrapperRef.current;
29
+ if (!wrapperElement || !scrollContext) {
30
+ return void 0;
31
+ }
32
+ const handleTouchMove = (event) => {
33
+ event.stopPropagation();
34
+ };
35
+ wrapperElement.addEventListener('touchmove', handleTouchMove);
36
+ return () => wrapperElement.removeEventListener('touchmove', handleTouchMove);
37
+ }, [scrollContext]);
38
+ useResize(calcHeight);
39
+ return scrollContext ? (jsx(BottomSheetFullScreenContent, { style: { height, overflow: 'auto' }, ref: wrapperMultiRef, ...props })) : (jsx(ModalContentFullHeight, { style: { height, overflow: 'auto' }, ref: wrapperMultiRef, ...props }));
40
+ });
41
+ TreeSelectorWrapper.displayName = 'TreeSelectorWrapper';
42
+
43
+ export { TreeSelectorWrapper };
44
+ //# sourceMappingURL=TreeSelectorWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TreeSelectorWrapper.js","sources":["../src/TreeSelectorWrapper.tsx"],"sourcesContent":["import {\n forwardRef,\n PropsWithChildren,\n useRef,\n useState,\n useLayoutEffect,\n useCallback,\n useEffect,\n useContext,\n} from 'react';\n\nimport { useResize } from '@hh.ru/magritte-common-resize';\nimport { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';\nimport { CustomScrollContext } from '@hh.ru/magritte-internal-custom-scroll';\nimport { BottomSheetFullScreenContent } from '@hh.ru/magritte-ui-bottom-sheet';\nimport { ModalContentFullHeight } from '@hh.ru/magritte-ui-modal';\n\nexport const TreeSelectorWrapper = forwardRef<HTMLDivElement, PropsWithChildren>((props, ref) => {\n const [height, setHeight] = useState(0);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const wrapperMultiRef = useMultipleRefs(wrapperRef, ref);\n const scrollContext = useContext(CustomScrollContext);\n\n const calcHeight = useCallback(() => {\n if (wrapperRef.current?.parentElement) {\n const style = window.getComputedStyle(wrapperRef.current.parentElement) || {};\n const paddingTop = parseFloat(style.paddingTop || '0');\n const paddingBottom = parseFloat(style.paddingBottom || '0');\n const height = wrapperRef.current.parentElement.offsetHeight - paddingTop - paddingBottom;\n setHeight(height);\n }\n }, []);\n\n useLayoutEffect(() => {\n calcHeight();\n }, [calcHeight]);\n\n useEffect(() => {\n const wrapperElement = wrapperRef.current;\n if (!wrapperElement || !scrollContext) {\n return void 0;\n }\n\n const handleTouchMove = (event: TouchEvent) => {\n event.stopPropagation();\n };\n\n wrapperElement.addEventListener('touchmove', handleTouchMove);\n return () => wrapperElement.removeEventListener('touchmove', handleTouchMove);\n }, [scrollContext]);\n\n useResize(calcHeight);\n\n return scrollContext ? (\n <BottomSheetFullScreenContent style={{ height, overflow: 'auto' }} ref={wrapperMultiRef} {...props} />\n ) : (\n <ModalContentFullHeight style={{ height, overflow: 'auto' }} ref={wrapperMultiRef} {...props} />\n );\n});\n\nTreeSelectorWrapper.displayName = 'TreeSelectorWrapper';\n"],"names":["_jsx"],"mappings":";;;;;;;;AAiBa,MAAA,mBAAmB,GAAG,UAAU,CAAoC,CAAC,KAAK,EAAE,GAAG,KAAI;IAC5F,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;AACxC,IAAA,MAAM,UAAU,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAChD,MAAM,eAAe,GAAG,eAAe,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;AACzD,IAAA,MAAM,aAAa,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;AAEtD,IAAA,MAAM,UAA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