@snack-uikit/list 0.24.3 → 0.24.4-preview-704e8703.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.
- package/dist/cjs/components/Items/NextListItem/NextListItem.js +3 -1
- package/dist/cjs/components/Items/hooks.d.ts +1 -1
- package/dist/cjs/components/Items/hooks.js +72 -51
- package/dist/cjs/components/Lists/Droplist/DropList.js +1 -0
- package/dist/cjs/components/Lists/List/List.js +1 -0
- package/dist/cjs/components/Lists/contexts/NewListProvider.d.ts +1 -0
- package/dist/cjs/components/Lists/contexts/NewListProvider.js +4 -2
- package/dist/esm/components/Items/NextListItem/NextListItem.js +2 -2
- package/dist/esm/components/Items/hooks.d.ts +1 -1
- package/dist/esm/components/Items/hooks.js +35 -24
- package/dist/esm/components/Lists/Droplist/DropList.js +1 -1
- package/dist/esm/components/Lists/List/List.js +1 -1
- package/dist/esm/components/Lists/contexts/NewListProvider.d.ts +1 -0
- package/dist/esm/components/Lists/contexts/NewListProvider.js +2 -2
- package/package.json +4 -4
- package/src/components/Items/NextListItem/NextListItem.tsx +2 -1
- package/src/components/Items/hooks.tsx +65 -30
- package/src/components/Lists/Droplist/DropList.tsx +1 -0
- package/src/components/Lists/List/List.tsx +1 -0
- package/src/components/Lists/contexts/NewListProvider.tsx +3 -1
- package/dist/cjs/components/Items/GroupItem/GroupItem.d.ts +0 -6
- package/dist/cjs/components/Items/GroupItem/GroupItem.js +0 -27
- package/dist/cjs/components/Items/GroupItem/index.d.ts +0 -1
- package/dist/cjs/components/Items/GroupItem/index.js +0 -25
- package/dist/esm/components/Items/GroupItem/GroupItem.d.ts +0 -6
- package/dist/esm/components/Items/GroupItem/GroupItem.js +0 -7
- package/dist/esm/components/Items/GroupItem/index.d.ts +0 -1
- package/dist/esm/components/Items/GroupItem/index.js +0 -1
- package/src/components/Items/GroupItem/GroupItem.tsx +0 -17
- package/src/components/Items/GroupItem/index.ts +0 -1
|
@@ -40,7 +40,8 @@ function NextListItem(_a) {
|
|
|
40
40
|
option = __rest(_a, ["items", "placement", "id", "scroll", "scrollRef", "disabled", "onSublistOpenChanged", "allChildIds", "loading", "focusId", "untouchableScrollbars"]);
|
|
41
41
|
const {
|
|
42
42
|
flattenItems,
|
|
43
|
-
focusFlattenItems
|
|
43
|
+
focusFlattenItems,
|
|
44
|
+
virtualized
|
|
44
45
|
} = (0, contexts_1.useNewListContext)();
|
|
45
46
|
const {
|
|
46
47
|
value,
|
|
@@ -113,6 +114,7 @@ function NextListItem(_a) {
|
|
|
113
114
|
items: items,
|
|
114
115
|
nested: true,
|
|
115
116
|
scroll: scroll,
|
|
117
|
+
virtualized: virtualized,
|
|
116
118
|
tabIndex: 0,
|
|
117
119
|
ref: listRef,
|
|
118
120
|
onFocus: e => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
import { Flatten, FlattenBaseItem, ItemId } from './types';
|
|
3
|
-
export declare function useRenderItems(focusCloseChildIds?: ItemId[]):
|
|
3
|
+
export declare function useRenderItems(focusCloseChildIds?: ItemId[]): (JSX.Element | null)[];
|
|
4
4
|
type UseCreateBaseItemsProps = {
|
|
5
5
|
search?: boolean;
|
|
6
6
|
footerActiveElementsRefs?: RefObject<HTMLElement>[];
|
|
@@ -7,16 +7,77 @@ exports.useRenderItems = useRenderItems;
|
|
|
7
7
|
exports.useCreateBaseItems = useCreateBaseItems;
|
|
8
8
|
exports.useGroupItemSelection = useGroupItemSelection;
|
|
9
9
|
const react_1 = require("react");
|
|
10
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
10
11
|
const react_2 = require("react");
|
|
11
12
|
const constants_1 = require("../../constants");
|
|
13
|
+
const helperComponents_1 = require("../../helperComponents");
|
|
12
14
|
const utils_1 = require("../../utils");
|
|
13
15
|
const contexts_1 = require("../Lists/contexts");
|
|
14
16
|
const AccordionItem_1 = require("./AccordionItem");
|
|
15
17
|
const BaseItem_1 = require("./BaseItem");
|
|
16
|
-
const GroupItem_1 = require("./GroupItem");
|
|
17
18
|
const GroupSelectItem_1 = require("./GroupSelectItem");
|
|
18
19
|
const NextListItem_1 = require("./NextListItem");
|
|
19
20
|
const utils_2 = require("./utils");
|
|
21
|
+
function getRenderItems(_ref) {
|
|
22
|
+
let {
|
|
23
|
+
focusCloseChildIds,
|
|
24
|
+
focusFlattenItems,
|
|
25
|
+
flattenItems,
|
|
26
|
+
isSelectionMultiple
|
|
27
|
+
} = _ref;
|
|
28
|
+
if (!focusCloseChildIds) {
|
|
29
|
+
return [null];
|
|
30
|
+
}
|
|
31
|
+
return focusCloseChildIds.flatMap(id => {
|
|
32
|
+
const {
|
|
33
|
+
itemRef,
|
|
34
|
+
key,
|
|
35
|
+
originalId,
|
|
36
|
+
items
|
|
37
|
+
} = focusFlattenItems[id];
|
|
38
|
+
const flattenItem = flattenItems[originalId];
|
|
39
|
+
if ((0, utils_2.isGroupItem)(flattenItem) || !isSelectionMultiple && (0, utils_2.isGroupSelectItem)(flattenItem)) {
|
|
40
|
+
const innerItemsJSX = getRenderItems({
|
|
41
|
+
focusCloseChildIds: items,
|
|
42
|
+
focusFlattenItems,
|
|
43
|
+
flattenItems,
|
|
44
|
+
isSelectionMultiple
|
|
45
|
+
});
|
|
46
|
+
return [(0, jsx_runtime_1.jsx)(helperComponents_1.Separator, {
|
|
47
|
+
label: flattenItem.label,
|
|
48
|
+
truncate: flattenItem.truncate,
|
|
49
|
+
divider: flattenItem.divider,
|
|
50
|
+
mode: flattenItem.mode
|
|
51
|
+
}, key + '_separator'), ...innerItemsJSX];
|
|
52
|
+
}
|
|
53
|
+
if ((0, utils_2.isGroupSelectItem)(flattenItem)) {
|
|
54
|
+
return (0, react_1.createElement)(GroupSelectItem_1.GroupSelectItem, Object.assign({}, flattenItem, {
|
|
55
|
+
items: items,
|
|
56
|
+
itemRef: itemRef,
|
|
57
|
+
key: key
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
if ((0, utils_2.isAccordionItem)(flattenItem)) {
|
|
61
|
+
return (0, react_1.createElement)(AccordionItem_1.AccordionItem, Object.assign({}, flattenItem, {
|
|
62
|
+
items: items,
|
|
63
|
+
itemRef: itemRef,
|
|
64
|
+
key: key
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
if ((0, utils_2.isNextListItem)(flattenItem)) {
|
|
68
|
+
return (0, react_1.createElement)(NextListItem_1.NextListItem, Object.assign({}, flattenItem, {
|
|
69
|
+
focusId: id,
|
|
70
|
+
items: items,
|
|
71
|
+
itemRef: itemRef,
|
|
72
|
+
key: key
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
return (0, react_1.createElement)(BaseItem_1.BaseItem, Object.assign({}, flattenItem, {
|
|
76
|
+
itemRef: itemRef,
|
|
77
|
+
key: key
|
|
78
|
+
}));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
20
81
|
function useRenderItems(focusCloseChildIds) {
|
|
21
82
|
const {
|
|
22
83
|
focusFlattenItems,
|
|
@@ -25,57 +86,17 @@ function useRenderItems(focusCloseChildIds) {
|
|
|
25
86
|
const {
|
|
26
87
|
isSelectionMultiple
|
|
27
88
|
} = (0, contexts_1.useSelectionContext)();
|
|
28
|
-
return (0, react_2.useMemo)(() => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
itemRef,
|
|
35
|
-
key,
|
|
36
|
-
originalId,
|
|
37
|
-
items
|
|
38
|
-
} = focusFlattenItems[id];
|
|
39
|
-
const flattenItem = flattenItems[originalId];
|
|
40
|
-
if ((0, utils_2.isGroupItem)(flattenItem) || !isSelectionMultiple && (0, utils_2.isGroupSelectItem)(flattenItem)) {
|
|
41
|
-
return (0, react_1.createElement)(GroupItem_1.GroupItem, Object.assign({}, flattenItem, {
|
|
42
|
-
items: items,
|
|
43
|
-
key: key
|
|
44
|
-
}));
|
|
45
|
-
}
|
|
46
|
-
if ((0, utils_2.isGroupSelectItem)(flattenItem)) {
|
|
47
|
-
return (0, react_1.createElement)(GroupSelectItem_1.GroupSelectItem, Object.assign({}, flattenItem, {
|
|
48
|
-
items: items,
|
|
49
|
-
itemRef: itemRef,
|
|
50
|
-
key: key
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
if ((0, utils_2.isAccordionItem)(flattenItem)) {
|
|
54
|
-
return (0, react_1.createElement)(AccordionItem_1.AccordionItem, Object.assign({}, flattenItem, {
|
|
55
|
-
items: items,
|
|
56
|
-
itemRef: itemRef,
|
|
57
|
-
key: key
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
if ((0, utils_2.isNextListItem)(flattenItem)) {
|
|
61
|
-
return (0, react_1.createElement)(NextListItem_1.NextListItem, Object.assign({}, flattenItem, {
|
|
62
|
-
focusId: id,
|
|
63
|
-
items: items,
|
|
64
|
-
itemRef: itemRef,
|
|
65
|
-
key: key
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
return (0, react_1.createElement)(BaseItem_1.BaseItem, Object.assign({}, flattenItem, {
|
|
69
|
-
itemRef: itemRef,
|
|
70
|
-
key: key
|
|
71
|
-
}));
|
|
72
|
-
});
|
|
73
|
-
}, [flattenItems, focusCloseChildIds, focusFlattenItems, isSelectionMultiple]);
|
|
89
|
+
return (0, react_2.useMemo)(() => getRenderItems({
|
|
90
|
+
flattenItems,
|
|
91
|
+
focusFlattenItems,
|
|
92
|
+
focusCloseChildIds,
|
|
93
|
+
isSelectionMultiple
|
|
94
|
+
}), [flattenItems, focusCloseChildIds, focusFlattenItems, isSelectionMultiple]);
|
|
74
95
|
}
|
|
75
|
-
function useCreateBaseItems(
|
|
96
|
+
function useCreateBaseItems(_ref2) {
|
|
76
97
|
let {
|
|
77
98
|
footerActiveElementsRefs
|
|
78
|
-
} =
|
|
99
|
+
} = _ref2;
|
|
79
100
|
return (0, react_2.useMemo)(() => {
|
|
80
101
|
var _a;
|
|
81
102
|
return {
|
|
@@ -96,11 +117,11 @@ function useCreateBaseItems(_ref) {
|
|
|
96
117
|
};
|
|
97
118
|
}, [footerActiveElementsRefs]);
|
|
98
119
|
}
|
|
99
|
-
function useGroupItemSelection(
|
|
120
|
+
function useGroupItemSelection(_ref3) {
|
|
100
121
|
let {
|
|
101
122
|
id,
|
|
102
123
|
allChildIds
|
|
103
|
-
} =
|
|
124
|
+
} = _ref3;
|
|
104
125
|
const {
|
|
105
126
|
value,
|
|
106
127
|
setValue,
|
|
@@ -209,6 +209,7 @@ function Droplist(_a) {
|
|
|
209
209
|
size: size,
|
|
210
210
|
marker: marker,
|
|
211
211
|
firstItemId: firstItemId,
|
|
212
|
+
virtualized: virtualized,
|
|
212
213
|
children: (0, jsx_runtime_1.jsx)(contexts_1.SelectionProvider, Object.assign({}, selection, {
|
|
213
214
|
children: (0, jsx_runtime_1.jsx)(contexts_1.CollapseContext.Provider, {
|
|
214
215
|
value: {
|
|
@@ -168,6 +168,7 @@ exports.List = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
168
168
|
size: size,
|
|
169
169
|
marker: marker,
|
|
170
170
|
firstItemId: firstItemId,
|
|
171
|
+
virtualized: props.virtualized,
|
|
171
172
|
children: (0, jsx_runtime_1.jsx)(contexts_1.SelectionProvider, Object.assign({}, selection, {
|
|
172
173
|
children: (0, jsx_runtime_1.jsx)(contexts_1.CollapseContext.Provider, {
|
|
173
174
|
value: {
|
|
@@ -15,6 +15,7 @@ export type PublicListContextType = {
|
|
|
15
15
|
* Рендер функция основного контента айтема
|
|
16
16
|
*/
|
|
17
17
|
contentRender?(props: ContentRenderProps): ReactNode;
|
|
18
|
+
virtualized?: boolean;
|
|
18
19
|
};
|
|
19
20
|
export type PrivateListContextType = {
|
|
20
21
|
flattenItems: Record<string, FlattenItem>;
|
|
@@ -32,7 +32,8 @@ function extractListProps(_ref) {
|
|
|
32
32
|
flattenItems,
|
|
33
33
|
focusFlattenItems,
|
|
34
34
|
contentRender,
|
|
35
|
-
firstItemId
|
|
35
|
+
firstItemId,
|
|
36
|
+
virtualized
|
|
36
37
|
} = _ref;
|
|
37
38
|
return {
|
|
38
39
|
size,
|
|
@@ -40,7 +41,8 @@ function extractListProps(_ref) {
|
|
|
40
41
|
contentRender,
|
|
41
42
|
flattenItems,
|
|
42
43
|
focusFlattenItems,
|
|
43
|
-
firstItemId
|
|
44
|
+
firstItemId,
|
|
45
|
+
virtualized
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
48
|
function NewListContextProvider(_a) {
|
|
@@ -22,7 +22,7 @@ import { extractActiveItems, isNextListItem } from '../utils';
|
|
|
22
22
|
import { FALLBACK_PLACEMENTS } from './constants';
|
|
23
23
|
export function NextListItem(_a) {
|
|
24
24
|
var { items, placement = 'right-start', id, scroll, scrollRef, disabled, onSublistOpenChanged, allChildIds, loading = false, focusId = id, untouchableScrollbars = false } = _a, option = __rest(_a, ["items", "placement", "id", "scroll", "scrollRef", "disabled", "onSublistOpenChanged", "allChildIds", "loading", "focusId", "untouchableScrollbars"]);
|
|
25
|
-
const { flattenItems, focusFlattenItems } = useNewListContext();
|
|
25
|
+
const { flattenItems, focusFlattenItems, virtualized } = useNewListContext();
|
|
26
26
|
const { value, isSelectionSingle, isSelectionMultiple } = useSelectionContext();
|
|
27
27
|
const { openCollapseItems = [] } = useCollapseContext();
|
|
28
28
|
const item = flattenItems[id];
|
|
@@ -64,7 +64,7 @@ export function NextListItem(_a) {
|
|
|
64
64
|
setOpen(open => open && isOpen);
|
|
65
65
|
}, [id, isOpen]);
|
|
66
66
|
const listRef = useRef(null);
|
|
67
|
-
return (_jsx(Dropdown, { outsideClick: handleOutsideClick, fallbackPlacements: FALLBACK_PLACEMENTS, content: _jsx(ListPrivate, { onKeyDown: handleListKeyDown, items: items, nested: true, scroll: scroll, tabIndex: 0, ref: listRef, onFocus: e => {
|
|
67
|
+
return (_jsx(Dropdown, { outsideClick: handleOutsideClick, fallbackPlacements: FALLBACK_PLACEMENTS, content: _jsx(ListPrivate, { onKeyDown: handleListKeyDown, items: items, nested: true, scroll: scroll, virtualized: virtualized, tabIndex: 0, ref: listRef, onFocus: e => {
|
|
68
68
|
e.stopPropagation();
|
|
69
69
|
forceUpdateActiveItemId === null || forceUpdateActiveItemId === void 0 ? void 0 : forceUpdateActiveItemId(ids[0]);
|
|
70
70
|
}, scrollRef: scrollRef, limitedScrollHeight: true, untouchableScrollbars: untouchableScrollbars, loading: loading }), trigger: 'hover', open: isOpen || open, onOpenChange: value => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
import { Flatten, FlattenBaseItem, ItemId } from './types';
|
|
3
|
-
export declare function useRenderItems(focusCloseChildIds?: ItemId[]):
|
|
3
|
+
export declare function useRenderItems(focusCloseChildIds?: ItemId[]): (JSX.Element | null)[];
|
|
4
4
|
type UseCreateBaseItemsProps = {
|
|
5
5
|
search?: boolean;
|
|
6
6
|
footerActiveElementsRefs?: RefObject<HTMLElement>[];
|
|
@@ -1,40 +1,51 @@
|
|
|
1
1
|
import { createElement as _createElement } from "react";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import { createRef, useMemo } from 'react';
|
|
3
4
|
import { ITEM_PREFIXES } from '../../constants';
|
|
5
|
+
import { Separator } from '../../helperComponents';
|
|
4
6
|
import { getFooterItemId } from '../../utils';
|
|
5
7
|
import { useNewListContext, useSelectionContext } from '../Lists/contexts';
|
|
6
8
|
import { AccordionItem } from './AccordionItem';
|
|
7
9
|
import { BaseItem } from './BaseItem';
|
|
8
|
-
import { GroupItem } from './GroupItem';
|
|
9
10
|
import { GroupSelectItem } from './GroupSelectItem';
|
|
10
11
|
import { NextListItem } from './NextListItem';
|
|
11
12
|
import { isAccordionItem, isGroupItem, isGroupSelectItem, isNextListItem } from './utils';
|
|
13
|
+
function getRenderItems({ focusCloseChildIds, focusFlattenItems, flattenItems, isSelectionMultiple, }) {
|
|
14
|
+
if (!focusCloseChildIds) {
|
|
15
|
+
return [null];
|
|
16
|
+
}
|
|
17
|
+
return focusCloseChildIds.flatMap(id => {
|
|
18
|
+
const { itemRef, key, originalId, items } = focusFlattenItems[id];
|
|
19
|
+
const flattenItem = flattenItems[originalId];
|
|
20
|
+
if (isGroupItem(flattenItem) ||
|
|
21
|
+
(!isSelectionMultiple && isGroupSelectItem(flattenItem))) {
|
|
22
|
+
const innerItemsJSX = getRenderItems({
|
|
23
|
+
focusCloseChildIds: items,
|
|
24
|
+
focusFlattenItems,
|
|
25
|
+
flattenItems,
|
|
26
|
+
isSelectionMultiple,
|
|
27
|
+
});
|
|
28
|
+
return [
|
|
29
|
+
_jsx(Separator, { label: flattenItem.label, truncate: flattenItem.truncate, divider: flattenItem.divider, mode: flattenItem.mode }, key + '_separator'),
|
|
30
|
+
...innerItemsJSX,
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
if (isGroupSelectItem(flattenItem)) {
|
|
34
|
+
return _createElement(GroupSelectItem, Object.assign({}, flattenItem, { items: items, itemRef: itemRef, key: key }));
|
|
35
|
+
}
|
|
36
|
+
if (isAccordionItem(flattenItem)) {
|
|
37
|
+
return _createElement(AccordionItem, Object.assign({}, flattenItem, { items: items, itemRef: itemRef, key: key }));
|
|
38
|
+
}
|
|
39
|
+
if (isNextListItem(flattenItem)) {
|
|
40
|
+
return _createElement(NextListItem, Object.assign({}, flattenItem, { focusId: id, items: items, itemRef: itemRef, key: key }));
|
|
41
|
+
}
|
|
42
|
+
return _createElement(BaseItem, Object.assign({}, flattenItem, { itemRef: itemRef, key: key }));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
12
45
|
export function useRenderItems(focusCloseChildIds) {
|
|
13
46
|
const { focusFlattenItems, flattenItems } = useNewListContext();
|
|
14
47
|
const { isSelectionMultiple } = useSelectionContext();
|
|
15
|
-
return useMemo(() => {
|
|
16
|
-
if (!focusCloseChildIds) {
|
|
17
|
-
return [null];
|
|
18
|
-
}
|
|
19
|
-
return focusCloseChildIds.map(id => {
|
|
20
|
-
const { itemRef, key, originalId, items } = focusFlattenItems[id];
|
|
21
|
-
const flattenItem = flattenItems[originalId];
|
|
22
|
-
if (isGroupItem(flattenItem) ||
|
|
23
|
-
(!isSelectionMultiple && isGroupSelectItem(flattenItem))) {
|
|
24
|
-
return _createElement(GroupItem, Object.assign({}, flattenItem, { items: items, key: key }));
|
|
25
|
-
}
|
|
26
|
-
if (isGroupSelectItem(flattenItem)) {
|
|
27
|
-
return _createElement(GroupSelectItem, Object.assign({}, flattenItem, { items: items, itemRef: itemRef, key: key }));
|
|
28
|
-
}
|
|
29
|
-
if (isAccordionItem(flattenItem)) {
|
|
30
|
-
return _createElement(AccordionItem, Object.assign({}, flattenItem, { items: items, itemRef: itemRef, key: key }));
|
|
31
|
-
}
|
|
32
|
-
if (isNextListItem(flattenItem)) {
|
|
33
|
-
return _createElement(NextListItem, Object.assign({}, flattenItem, { focusId: id, items: items, itemRef: itemRef, key: key }));
|
|
34
|
-
}
|
|
35
|
-
return _createElement(BaseItem, Object.assign({}, flattenItem, { itemRef: itemRef, key: key }));
|
|
36
|
-
});
|
|
37
|
-
}, [flattenItems, focusCloseChildIds, focusFlattenItems, isSelectionMultiple]);
|
|
48
|
+
return useMemo(() => getRenderItems({ flattenItems, focusFlattenItems, focusCloseChildIds, isSelectionMultiple }), [flattenItems, focusCloseChildIds, focusFlattenItems, isSelectionMultiple]);
|
|
38
49
|
}
|
|
39
50
|
export function useCreateBaseItems({ footerActiveElementsRefs }) {
|
|
40
51
|
return useMemo(() => {
|
|
@@ -128,7 +128,7 @@ export function Droplist(_a) {
|
|
|
128
128
|
}
|
|
129
129
|
return children;
|
|
130
130
|
}, [onKeyDown, children]);
|
|
131
|
-
return (_jsx(NewListContextProvider, { flattenItems: flattenItems, focusFlattenItems: focusFlattenItems, contentRender: contentRender, size: size, marker: marker, firstItemId: firstItemId, children: _jsx(SelectionProvider, Object.assign({}, selection, { children: _jsx(CollapseContext.Provider, { value: {
|
|
131
|
+
return (_jsx(NewListContextProvider, { flattenItems: flattenItems, focusFlattenItems: focusFlattenItems, contentRender: contentRender, size: size, marker: marker, firstItemId: firstItemId, virtualized: virtualized, children: _jsx(SelectionProvider, Object.assign({}, selection, { children: _jsx(CollapseContext.Provider, { value: {
|
|
132
132
|
openCollapseItems,
|
|
133
133
|
toggleOpenCollapseItem,
|
|
134
134
|
}, children: _jsx(FocusListContext.Provider, { value: {
|
|
@@ -99,7 +99,7 @@ export const List = forwardRef((_a, ref) => {
|
|
|
99
99
|
const handleOnFocus = () => {
|
|
100
100
|
resetActiveItemId();
|
|
101
101
|
};
|
|
102
|
-
return (_jsx(NewListContextProvider, { flattenItems: flattenItems, focusFlattenItems: focusFlattenItems, contentRender: contentRender, size: size, marker: marker, firstItemId: firstItemId, children: _jsx(SelectionProvider, Object.assign({}, selection, { children: _jsx(CollapseContext.Provider, { value: {
|
|
102
|
+
return (_jsx(NewListContextProvider, { flattenItems: flattenItems, focusFlattenItems: focusFlattenItems, contentRender: contentRender, size: size, marker: marker, firstItemId: firstItemId, virtualized: props.virtualized, children: _jsx(SelectionProvider, Object.assign({}, selection, { children: _jsx(CollapseContext.Provider, { value: {
|
|
103
103
|
openCollapseItems,
|
|
104
104
|
toggleOpenCollapseItem,
|
|
105
105
|
}, children: _jsx(FocusListContext.Provider, { value: {
|
|
@@ -15,6 +15,7 @@ export type PublicListContextType = {
|
|
|
15
15
|
* Рендер функция основного контента айтема
|
|
16
16
|
*/
|
|
17
17
|
contentRender?(props: ContentRenderProps): ReactNode;
|
|
18
|
+
virtualized?: boolean;
|
|
18
19
|
};
|
|
19
20
|
export type PrivateListContextType = {
|
|
20
21
|
flattenItems: Record<string, FlattenItem>;
|
|
@@ -20,8 +20,8 @@ export const ListContext = createContext({
|
|
|
20
20
|
export function useNewListContext() {
|
|
21
21
|
return useContext(ListContext);
|
|
22
22
|
}
|
|
23
|
-
function extractListProps({ size, marker, flattenItems, focusFlattenItems, contentRender, firstItemId, }) {
|
|
24
|
-
return { size, marker, contentRender, flattenItems, focusFlattenItems, firstItemId };
|
|
23
|
+
function extractListProps({ size, marker, flattenItems, focusFlattenItems, contentRender, firstItemId, virtualized, }) {
|
|
24
|
+
return { size, marker, contentRender, flattenItems, focusFlattenItems, firstItemId, virtualized };
|
|
25
25
|
}
|
|
26
26
|
export function NewListContextProvider(_a) {
|
|
27
27
|
var { children } = _a, props = __rest(_a, ["children"]);
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "List",
|
|
7
|
-
"version": "0.24.
|
|
7
|
+
"version": "0.24.4-preview-704e8703.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"license": "Apache-2.0",
|
|
37
37
|
"scripts": {},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@snack-uikit/button": "0.19.
|
|
39
|
+
"@snack-uikit/button": "0.19.8-preview-704e8703.0",
|
|
40
40
|
"@snack-uikit/divider": "3.2.3",
|
|
41
41
|
"@snack-uikit/dropdown": "0.4.4",
|
|
42
42
|
"@snack-uikit/icons": "0.24.2",
|
|
43
|
-
"@snack-uikit/info-block": "0.6.
|
|
43
|
+
"@snack-uikit/info-block": "0.6.13-preview-704e8703.0",
|
|
44
44
|
"@snack-uikit/loaders": "0.9.1",
|
|
45
45
|
"@snack-uikit/scroll": "0.9.3",
|
|
46
46
|
"@snack-uikit/search-private": "0.4.9",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@snack-uikit/locale": "*"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "4cc887cec09a84912a1c15e5ad676c47513b07c7"
|
|
58
58
|
}
|
|
@@ -28,7 +28,7 @@ export function NextListItem({
|
|
|
28
28
|
untouchableScrollbars = false,
|
|
29
29
|
...option
|
|
30
30
|
}: NextListItemProps) {
|
|
31
|
-
const { flattenItems, focusFlattenItems } = useNewListContext();
|
|
31
|
+
const { flattenItems, focusFlattenItems, virtualized } = useNewListContext();
|
|
32
32
|
const { value, isSelectionSingle, isSelectionMultiple } = useSelectionContext();
|
|
33
33
|
const { openCollapseItems = [] } = useCollapseContext();
|
|
34
34
|
|
|
@@ -107,6 +107,7 @@ export function NextListItem({
|
|
|
107
107
|
items={items}
|
|
108
108
|
nested
|
|
109
109
|
scroll={scroll}
|
|
110
|
+
virtualized={virtualized}
|
|
110
111
|
tabIndex={0}
|
|
111
112
|
ref={listRef}
|
|
112
113
|
onFocus={e => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createRef, RefObject, useMemo } from 'react';
|
|
2
2
|
|
|
3
3
|
import { ITEM_PREFIXES } from '../../constants';
|
|
4
|
+
import { Separator } from '../../helperComponents';
|
|
4
5
|
import { getFooterItemId } from '../../utils';
|
|
5
6
|
import { useNewListContext, useSelectionContext } from '../Lists/contexts';
|
|
6
7
|
import { AccordionItem } from './AccordionItem';
|
|
7
8
|
import { BaseItem } from './BaseItem';
|
|
8
|
-
import { GroupItem } from './GroupItem';
|
|
9
9
|
import { GroupSelectItem } from './GroupSelectItem';
|
|
10
10
|
import { NextListItem } from './NextListItem';
|
|
11
11
|
import {
|
|
@@ -13,44 +13,79 @@ import {
|
|
|
13
13
|
FlattenAccordionItem,
|
|
14
14
|
FlattenBaseItem,
|
|
15
15
|
FlattenGroupSelectListItem,
|
|
16
|
+
FlattenItem,
|
|
16
17
|
FlattenNextListItem,
|
|
18
|
+
FocusFlattenItem,
|
|
17
19
|
ItemId,
|
|
18
20
|
} from './types';
|
|
19
21
|
import { isAccordionItem, isGroupItem, isGroupSelectItem, isNextListItem } from './utils';
|
|
20
22
|
|
|
23
|
+
type GetRenderItemsProps = {
|
|
24
|
+
focusCloseChildIds?: ItemId[];
|
|
25
|
+
flattenItems: Record<string, FlattenItem>;
|
|
26
|
+
focusFlattenItems: Record<string, FocusFlattenItem>;
|
|
27
|
+
isSelectionMultiple?: boolean;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function getRenderItems({
|
|
31
|
+
focusCloseChildIds,
|
|
32
|
+
focusFlattenItems,
|
|
33
|
+
flattenItems,
|
|
34
|
+
isSelectionMultiple,
|
|
35
|
+
}: GetRenderItemsProps): (JSX.Element | null)[] {
|
|
36
|
+
if (!focusCloseChildIds) {
|
|
37
|
+
return [null];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return focusCloseChildIds.flatMap(id => {
|
|
41
|
+
const { itemRef, key, originalId, items } = focusFlattenItems[id];
|
|
42
|
+
|
|
43
|
+
const flattenItem = flattenItems[originalId];
|
|
44
|
+
|
|
45
|
+
if (
|
|
46
|
+
isGroupItem(flattenItem) ||
|
|
47
|
+
(!isSelectionMultiple && isGroupSelectItem<FlattenGroupSelectListItem>(flattenItem))
|
|
48
|
+
) {
|
|
49
|
+
const innerItemsJSX = getRenderItems({
|
|
50
|
+
focusCloseChildIds: items,
|
|
51
|
+
focusFlattenItems,
|
|
52
|
+
flattenItems,
|
|
53
|
+
isSelectionMultiple,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return [
|
|
57
|
+
<Separator
|
|
58
|
+
label={flattenItem.label}
|
|
59
|
+
truncate={flattenItem.truncate}
|
|
60
|
+
divider={flattenItem.divider}
|
|
61
|
+
mode={flattenItem.mode}
|
|
62
|
+
key={key + '_separator'}
|
|
63
|
+
/>,
|
|
64
|
+
...innerItemsJSX,
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
if (isGroupSelectItem<FlattenGroupSelectListItem>(flattenItem)) {
|
|
68
|
+
return <GroupSelectItem {...flattenItem} items={items} itemRef={itemRef} key={key} />;
|
|
69
|
+
}
|
|
70
|
+
if (isAccordionItem<FlattenAccordionItem>(flattenItem)) {
|
|
71
|
+
return <AccordionItem {...flattenItem} items={items} itemRef={itemRef} key={key} />;
|
|
72
|
+
}
|
|
73
|
+
if (isNextListItem<FlattenNextListItem>(flattenItem)) {
|
|
74
|
+
return <NextListItem {...flattenItem} focusId={id} items={items} itemRef={itemRef} key={key} />;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return <BaseItem {...flattenItem} itemRef={itemRef} key={key} />;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
21
81
|
export function useRenderItems(focusCloseChildIds?: ItemId[]) {
|
|
22
82
|
const { focusFlattenItems, flattenItems } = useNewListContext();
|
|
23
83
|
const { isSelectionMultiple } = useSelectionContext();
|
|
24
84
|
|
|
25
|
-
return useMemo(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return focusCloseChildIds.map(id => {
|
|
31
|
-
const { itemRef, key, originalId, items } = focusFlattenItems[id];
|
|
32
|
-
|
|
33
|
-
const flattenItem = flattenItems[originalId];
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
isGroupItem(flattenItem) ||
|
|
37
|
-
(!isSelectionMultiple && isGroupSelectItem<FlattenGroupSelectListItem>(flattenItem))
|
|
38
|
-
) {
|
|
39
|
-
return <GroupItem {...flattenItem} items={items} key={key} />;
|
|
40
|
-
}
|
|
41
|
-
if (isGroupSelectItem<FlattenGroupSelectListItem>(flattenItem)) {
|
|
42
|
-
return <GroupSelectItem {...flattenItem} items={items} itemRef={itemRef} key={key} />;
|
|
43
|
-
}
|
|
44
|
-
if (isAccordionItem<FlattenAccordionItem>(flattenItem)) {
|
|
45
|
-
return <AccordionItem {...flattenItem} items={items} itemRef={itemRef} key={key} />;
|
|
46
|
-
}
|
|
47
|
-
if (isNextListItem<FlattenNextListItem>(flattenItem)) {
|
|
48
|
-
return <NextListItem {...flattenItem} focusId={id} items={items} itemRef={itemRef} key={key} />;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return <BaseItem {...flattenItem} itemRef={itemRef} key={key} />;
|
|
52
|
-
});
|
|
53
|
-
}, [flattenItems, focusCloseChildIds, focusFlattenItems, isSelectionMultiple]);
|
|
85
|
+
return useMemo(
|
|
86
|
+
() => getRenderItems({ flattenItems, focusFlattenItems, focusCloseChildIds, isSelectionMultiple }),
|
|
87
|
+
[flattenItems, focusCloseChildIds, focusFlattenItems, isSelectionMultiple],
|
|
88
|
+
);
|
|
54
89
|
}
|
|
55
90
|
|
|
56
91
|
type UseCreateBaseItemsProps = {
|
|
@@ -19,6 +19,7 @@ export type PublicListContextType = {
|
|
|
19
19
|
* Рендер функция основного контента айтема
|
|
20
20
|
*/
|
|
21
21
|
contentRender?(props: ContentRenderProps): ReactNode;
|
|
22
|
+
virtualized?: boolean;
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
export type PrivateListContextType = {
|
|
@@ -50,8 +51,9 @@ function extractListProps<T extends ListContextType>({
|
|
|
50
51
|
focusFlattenItems,
|
|
51
52
|
contentRender,
|
|
52
53
|
firstItemId,
|
|
54
|
+
virtualized,
|
|
53
55
|
}: T) {
|
|
54
|
-
return { size, marker, contentRender, flattenItems, focusFlattenItems, firstItemId };
|
|
56
|
+
return { size, marker, contentRender, flattenItems, focusFlattenItems, firstItemId, virtualized };
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
export function NewListContextProvider({ children, ...props }: ListContextType & Child) {
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { FlattenGroupListItem, ItemId } from '../types';
|
|
2
|
-
type GroupItemProps = Omit<FlattenGroupListItem, 'type'> & {
|
|
3
|
-
items: ItemId[];
|
|
4
|
-
};
|
|
5
|
-
export declare function GroupItem({ label, truncate, divider, items, mode }: GroupItemProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
-
export {};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.GroupItem = GroupItem;
|
|
7
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
const helperComponents_1 = require("../../../helperComponents");
|
|
9
|
-
const hooks_1 = require("../hooks");
|
|
10
|
-
function GroupItem(_ref) {
|
|
11
|
-
let {
|
|
12
|
-
label,
|
|
13
|
-
truncate,
|
|
14
|
-
divider,
|
|
15
|
-
items,
|
|
16
|
-
mode
|
|
17
|
-
} = _ref;
|
|
18
|
-
const itemsJSX = (0, hooks_1.useRenderItems)(items);
|
|
19
|
-
return (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, {
|
|
20
|
-
children: [(0, jsx_runtime_1.jsx)(helperComponents_1.Separator, {
|
|
21
|
-
label: label,
|
|
22
|
-
truncate: truncate,
|
|
23
|
-
divider: divider,
|
|
24
|
-
mode: mode
|
|
25
|
-
}), itemsJSX]
|
|
26
|
-
});
|
|
27
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './GroupItem';
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return m[k];
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
} : function (o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
});
|
|
19
|
-
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
});
|
|
25
|
-
__exportStar(require("./GroupItem"), exports);
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { FlattenGroupListItem, ItemId } from '../types';
|
|
2
|
-
type GroupItemProps = Omit<FlattenGroupListItem, 'type'> & {
|
|
3
|
-
items: ItemId[];
|
|
4
|
-
};
|
|
5
|
-
export declare function GroupItem({ label, truncate, divider, items, mode }: GroupItemProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Separator } from '../../../helperComponents';
|
|
3
|
-
import { useRenderItems } from '../hooks';
|
|
4
|
-
export function GroupItem({ label, truncate, divider, items, mode }) {
|
|
5
|
-
const itemsJSX = useRenderItems(items);
|
|
6
|
-
return (_jsxs(_Fragment, { children: [_jsx(Separator, { label: label, truncate: truncate, divider: divider, mode: mode }), itemsJSX] }));
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './GroupItem';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './GroupItem';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Separator } from '../../../helperComponents';
|
|
2
|
-
import { useRenderItems } from '../hooks';
|
|
3
|
-
import { FlattenGroupListItem, ItemId } from '../types';
|
|
4
|
-
|
|
5
|
-
type GroupItemProps = Omit<FlattenGroupListItem, 'type'> & { items: ItemId[] };
|
|
6
|
-
|
|
7
|
-
export function GroupItem({ label, truncate, divider, items, mode }: GroupItemProps) {
|
|
8
|
-
const itemsJSX = useRenderItems(items);
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<>
|
|
12
|
-
<Separator label={label} truncate={truncate} divider={divider} mode={mode} />
|
|
13
|
-
|
|
14
|
-
{itemsJSX}
|
|
15
|
-
</>
|
|
16
|
-
);
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './GroupItem';
|