@react-fabric/data 1.0.0-beta.4 → 1.0.0-beta.41
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/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
- package/css/styles.css +24 -0
- package/dist/cjs/checklist/CheckList.js +25 -16
- package/dist/cjs/histogram/Histogram.js +20 -10
- package/dist/cjs/hooks/usePagination.js +7 -4
- package/dist/cjs/json/JsonViewer.js +40 -27
- package/dist/cjs/table/BodyCell.js +38 -5
- package/dist/cjs/table/BodyRow.js +107 -0
- package/dist/cjs/table/CheckboxCell.js +1 -1
- package/dist/cjs/table/HeaderCell.js +29 -36
- package/dist/cjs/table/Table.js +105 -67
- package/dist/cjs/table/useResizer.js +4 -4
- package/dist/cjs/table/useVirtualTable.js +118 -17
- package/dist/cjs/tree/TreeNode.js +44 -24
- package/dist/cjs/tree/TreePanel.js +28 -10
- package/dist/cjs/tree/useTree.js +96 -14
- package/dist/cjs/tree/utils.js +20 -5
- package/dist/cjs/virtual/Gallery.js +43 -29
- package/dist/cjs/virtual/List.js +43 -31
- package/dist/esm/checklist/CheckList.js +27 -18
- package/dist/esm/histogram/Histogram.js +21 -11
- package/dist/esm/hooks/usePagination.js +7 -4
- package/dist/esm/json/JsonViewer.js +41 -28
- package/dist/esm/table/BodyCell.js +38 -5
- package/dist/esm/table/BodyRow.js +107 -0
- package/dist/esm/table/CheckboxCell.js +1 -1
- package/dist/esm/table/HeaderCell.js +30 -37
- package/dist/esm/table/Table.js +107 -69
- package/dist/esm/table/useResizer.js +4 -4
- package/dist/esm/table/useVirtualTable.js +120 -19
- package/dist/esm/tree/TreeNode.js +46 -26
- package/dist/esm/tree/TreePanel.js +28 -10
- package/dist/esm/tree/useTree.js +98 -16
- package/dist/esm/tree/utils.js +20 -5
- package/dist/esm/virtual/Gallery.js +43 -29
- package/dist/esm/virtual/List.js +43 -31
- package/dist/types/checklist/CheckList.d.ts +2 -2
- package/dist/types/histogram/Histogram.d.ts +3 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/table/AddColumn.d.ts +2 -2
- package/dist/types/table/BodyCell.d.ts +4 -3
- package/dist/types/table/BodyRow.d.ts +20 -0
- package/dist/types/table/EmptyCell.d.ts +2 -2
- package/dist/types/table/HeaderCell.d.ts +2 -2
- package/dist/types/table/Table.d.ts +1 -1
- package/dist/types/table/types.d.ts +17 -6
- package/dist/types/table/useTableColumns.d.ts +6 -6
- package/dist/types/table/useVirtualTable.d.ts +20 -5
- package/dist/types/tree/TreeNode.d.ts +1 -1
- package/dist/types/tree/TreePanel.d.ts +1 -1
- package/dist/types/tree/types.d.ts +25 -5
- package/dist/types/tree/useTree.d.ts +2 -9
- package/dist/types/tree/utils.d.ts +4 -1
- package/dist/types/virtual/Gallery.d.ts +12 -4
- package/dist/types/virtual/List.d.ts +7 -3
- package/package.json +10 -7
- package/src/checklist/CheckList.tsx +81 -77
- package/src/histogram/Histogram.tsx +17 -11
- package/src/hooks/usePagination.tsx +13 -7
- package/src/index.ts +1 -1
- package/src/json/JsonViewer.tsx +45 -35
- package/src/table/AddColumn.tsx +2 -2
- package/src/table/BodyCell.tsx +34 -5
- package/src/table/BodyRow.tsx +143 -0
- package/src/table/CheckboxCell.tsx +1 -1
- package/src/table/EmptyCell.tsx +2 -2
- package/src/table/HeaderCell.tsx +27 -13
- package/src/table/Table.tsx +141 -73
- package/src/table/types.ts +20 -5
- package/src/table/useResizer.ts +5 -3
- package/src/table/useTableColumns.ts +7 -7
- package/src/table/useVirtualTable.ts +143 -28
- package/src/tree/TreeNode.tsx +90 -56
- package/src/tree/TreePanel.tsx +23 -3
- package/src/tree/types.ts +32 -4
- package/src/tree/useTree.ts +102 -23
- package/src/tree/utils.ts +23 -8
- package/src/virtual/Gallery.tsx +46 -35
- package/src/virtual/List.tsx +40 -27
- package/dist/cjs/histogram/Histogram.module.css +0 -1
- package/dist/esm/histogram/Histogram.module.css +0 -1
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
4
|
var core = require('@react-fabric/core');
|
|
5
|
+
var utilities = require('@react-fabric/utilities');
|
|
5
6
|
var classNames = require('classnames');
|
|
6
7
|
var react = require('react');
|
|
8
|
+
var reactI18next = require('react-i18next');
|
|
7
9
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
10
|
|
|
9
11
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -17,26 +19,34 @@ var TreeNode = function TreeNode(_ref) {
|
|
|
17
19
|
defaultLeafIcon = _ref.defaultLeafIcon,
|
|
18
20
|
defaultNodeIcon = _ref.defaultNodeIcon,
|
|
19
21
|
onToggle = _ref.onToggle,
|
|
22
|
+
_onClick = _ref.onClick,
|
|
20
23
|
onSelect = _ref.onSelect,
|
|
21
24
|
onChecked = _ref.onChecked,
|
|
22
|
-
children = _ref.children
|
|
25
|
+
children = _ref.children,
|
|
26
|
+
leafClassName = _ref.leafClassName,
|
|
27
|
+
nodeClassName = _ref.nodeClassName;
|
|
28
|
+
var _useTranslation = reactI18next.useTranslation("data"),
|
|
29
|
+
t = _useTranslation.t;
|
|
23
30
|
var badgeProps = react.useMemo(function () {
|
|
24
31
|
return core.getBadgeProps(node.badge);
|
|
25
32
|
}, [node.badge]);
|
|
26
33
|
var filler = react.useMemo(function () {
|
|
27
|
-
return node.lines.slice(
|
|
28
|
-
return /*#__PURE__*/jsxRuntime.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
return node.lines.slice(1).map(function (line, idx) {
|
|
35
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
36
|
+
className: classNames("flex-initial self-stretch flex items-center w-6 relative", !noLines && line > 0 && "before:absolute before:top-0 before:start-[7px] before:bg-tint-200 before:min-h-[50%] before:w-[2px] before:scale-x-[.625]", !noLines && line !== 2 && "before:h-full"),
|
|
37
|
+
children: /*#__PURE__*/jsxRuntime.jsxs("svg", {
|
|
38
|
+
viewBox: "0 0 24 24",
|
|
39
|
+
className: "fill-tint-200 rtl:-scale-x-100",
|
|
40
|
+
children: [line === 0 && /*#__PURE__*/jsxRuntime.jsx("path", {
|
|
41
|
+
d: ""
|
|
42
|
+
}), !noLines && line === 1 && /*#__PURE__*/jsxRuntime.jsx("path", {
|
|
43
|
+
d: "M7.45 26.1v-28.2h1.1v28.2h-1.1z"
|
|
44
|
+
}), !noLines && line === 2 && /*#__PURE__*/jsxRuntime.jsx("path", {
|
|
45
|
+
d: "M14.989 12.389l0.161-0.389-0.161-0.389-0.389-0.161h-6.050v-13.55h-1.1v14.1l0.161 0.389 0.389 0.161h6.6z"
|
|
46
|
+
}), !noLines && line === 3 && /*#__PURE__*/jsxRuntime.jsx("path", {
|
|
47
|
+
d: "M8.55 12.55h6.050l0.389-0.161 0.161-0.389-0.161-0.389-0.389-0.161h-6.050v-13.55h-1.1v28.2h1.1z"
|
|
48
|
+
})]
|
|
49
|
+
})
|
|
40
50
|
}, idx);
|
|
41
51
|
});
|
|
42
52
|
}, [noLines, node.lines]);
|
|
@@ -53,10 +63,16 @@ var TreeNode = function TreeNode(_ref) {
|
|
|
53
63
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
54
64
|
role: "treeitem",
|
|
55
65
|
"aria-selected": node.selected,
|
|
56
|
-
className: "flex flex-nowrap",
|
|
66
|
+
className: classNames("flex flex-nowrap items-center", node.leaf ? leafClassName : nodeClassName),
|
|
57
67
|
"data-testid": node["data-testid"],
|
|
58
68
|
"data-test-value": node["data-test-value"],
|
|
59
|
-
children: [filler,
|
|
69
|
+
children: [filler, node.loading && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
70
|
+
className: "flex-initial w-6",
|
|
71
|
+
children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
72
|
+
icon: core.CoreIcons.spinner,
|
|
73
|
+
className: "animate-spin text-muted"
|
|
74
|
+
})
|
|
75
|
+
}), !node.leaf && !node.childFiltered && !node.loading && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
60
76
|
className: "flex-initial w-6",
|
|
61
77
|
children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
62
78
|
rtlFlip: true,
|
|
@@ -75,21 +91,22 @@ var TreeNode = function TreeNode(_ref) {
|
|
|
75
91
|
icon: node.checked === 2 ? core.CoreIcons.checkboxInt : node.checked === 1 ? core.CoreIcons.checkboxOn : core.CoreIcons.checkboxOff,
|
|
76
92
|
className: classNames(node.disabled ? "text-muted" : "text-primary-500 hover:text-primary-600")
|
|
77
93
|
})
|
|
78
|
-
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
94
|
+
}), !node.empty && /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
79
95
|
role: "none",
|
|
80
|
-
className: classNames("group data-[selected]:bg-primary-100 flex flex-nowrap flex-1
|
|
96
|
+
className: classNames("group/tool data-[selected]:bg-primary-100 flex flex-nowrap flex-1 overflow-hidden select-none", node.childSelected && "font-medium", (canSelect || _onClick) && "hover:bg-primary-50 cursor-pointer"),
|
|
81
97
|
"data-selected": node.selected,
|
|
82
98
|
onClick: function onClick() {
|
|
83
|
-
|
|
99
|
+
_onClick === null || _onClick === void 0 || _onClick(node.id, node.data);
|
|
100
|
+
canSelect ? onSelect(node.id) : canCheck ? onChecked(node.id) : onToggle(node.id);
|
|
84
101
|
},
|
|
85
|
-
children: [nodeIcon && /*#__PURE__*/jsxRuntime.
|
|
86
|
-
className: "flex-content w-6",
|
|
87
|
-
children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
102
|
+
children: [nodeIcon && /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
103
|
+
className: "flex-content w-6 self-center leading-none",
|
|
104
|
+
children: [/*#__PURE__*/react.isValidElement(nodeIcon) && nodeIcon, utilities.isString(nodeIcon) && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
88
105
|
icon: nodeIcon,
|
|
89
106
|
bg: node.iconBg,
|
|
90
107
|
color: node.iconColor,
|
|
91
108
|
rtlFlip: node.rtlFlip
|
|
92
|
-
})
|
|
109
|
+
})]
|
|
93
110
|
}), node.childSelected && !node.open && /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
94
111
|
className: " flex-content text-primary-500",
|
|
95
112
|
children: "\u2022"
|
|
@@ -97,9 +114,12 @@ var TreeNode = function TreeNode(_ref) {
|
|
|
97
114
|
role: "none",
|
|
98
115
|
className: "flex-1 truncate",
|
|
99
116
|
children: children
|
|
100
|
-
}), node.badge && /*#__PURE__*/jsxRuntime.jsx(core.Badge, _objectSpread(_objectSpread({}, badgeProps), {}, {
|
|
117
|
+
}), !utilities.isEmpty(node.badge) && /*#__PURE__*/jsxRuntime.jsx(core.Badge, _objectSpread(_objectSpread({}, badgeProps), {}, {
|
|
101
118
|
className: classNames("me-1 self-center flex-content bg-opacity-50", badgeProps.className)
|
|
102
119
|
}))]
|
|
120
|
+
}), node.empty && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
121
|
+
className: "text-muted text-sm select-none",
|
|
122
|
+
children: t("tree.noItems")
|
|
103
123
|
})]
|
|
104
124
|
});
|
|
105
125
|
};
|
|
@@ -11,7 +11,7 @@ var types = require('./types.js');
|
|
|
11
11
|
var useTree = require('./useTree.js');
|
|
12
12
|
var jsxRuntime = require('react/jsx-runtime');
|
|
13
13
|
|
|
14
|
-
var _excluded = ["ref", "items", "selected", "checked", "checkable", "noLines", "renderer", "searchable", "selectable", "matcher", "filterPlaceholder", "defaultLeafIcon", "defaultNodeIcon", "expander", "onChecked", "onLoad", "onSelect"];
|
|
14
|
+
var _excluded = ["ref", "items", "selected", "checked", "checkable", "noLines", "renderer", "searchable", "selectable", "matcher", "filterPlaceholder", "defaultLeafIcon", "defaultNodeIcon", "expander", "onChecked", "onLoad", "onQuery", "onSelect", "onClick", "sorter", "makeLabel", "makeIcon", "defaultExpanded", "onExpandToggle", "leafClassName", "nodeClassName"];
|
|
15
15
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
16
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
17
|
var TreePanel = function TreePanel(_ref) {
|
|
@@ -31,24 +31,38 @@ var TreePanel = function TreePanel(_ref) {
|
|
|
31
31
|
defaultNodeIcon = _ref.defaultNodeIcon,
|
|
32
32
|
_ref$expander = _ref.expander,
|
|
33
33
|
expander = _ref$expander === void 0 ? "box" : _ref$expander,
|
|
34
|
-
onChecked = _ref.onChecked
|
|
35
|
-
_ref.onLoad
|
|
36
|
-
|
|
34
|
+
onChecked = _ref.onChecked,
|
|
35
|
+
onLoad = _ref.onLoad,
|
|
36
|
+
onQuery = _ref.onQuery,
|
|
37
|
+
onSelect = _ref.onSelect,
|
|
38
|
+
onClick = _ref.onClick,
|
|
39
|
+
sorter = _ref.sorter,
|
|
40
|
+
makeLabel = _ref.makeLabel,
|
|
41
|
+
makeIcon = _ref.makeIcon,
|
|
42
|
+
defaultExpanded = _ref.defaultExpanded,
|
|
43
|
+
onExpandToggle = _ref.onExpandToggle,
|
|
44
|
+
leafClassName = _ref.leafClassName,
|
|
45
|
+
nodeClassName = _ref.nodeClassName,
|
|
37
46
|
aria = _objectWithoutProperties(_ref, _excluded);
|
|
38
47
|
var _useTree = useTree.useTree({
|
|
39
48
|
items: items,
|
|
40
49
|
checked: checked,
|
|
41
50
|
selected: selected,
|
|
42
51
|
matcher: matcher,
|
|
52
|
+
sorter: sorter,
|
|
53
|
+
onLoad: onLoad,
|
|
54
|
+
onQuery: onQuery,
|
|
43
55
|
onSelect: onSelect,
|
|
44
|
-
onChecked: onChecked
|
|
56
|
+
onChecked: onChecked,
|
|
57
|
+
defaultExpanded: defaultExpanded,
|
|
58
|
+
onExpandToggle: onExpandToggle
|
|
45
59
|
}),
|
|
46
60
|
tree = _useTree.tree,
|
|
47
61
|
toggleExpand = _useTree.toggleExpand,
|
|
48
62
|
toggleCheck = _useTree.toggleCheck,
|
|
49
63
|
expandAll = _useTree.expandAll,
|
|
50
64
|
collapseAll = _useTree.collapseAll,
|
|
51
|
-
|
|
65
|
+
_select = _useTree.select,
|
|
52
66
|
expand = _useTree.expand,
|
|
53
67
|
onFilter = _useTree.onFilter;
|
|
54
68
|
var scrollerRef = react.useRef(null);
|
|
@@ -74,7 +88,7 @@ var TreePanel = function TreePanel(_ref) {
|
|
|
74
88
|
return expand(id);
|
|
75
89
|
},
|
|
76
90
|
select: function select(id) {
|
|
77
|
-
return
|
|
91
|
+
return _select(id);
|
|
78
92
|
}
|
|
79
93
|
};
|
|
80
94
|
}, []);
|
|
@@ -120,6 +134,7 @@ var TreePanel = function TreePanel(_ref) {
|
|
|
120
134
|
height: (_virtualItems$ = virtualItems[0]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.start
|
|
121
135
|
}
|
|
122
136
|
}), virtualItems.map(function (_ref2) {
|
|
137
|
+
var _makeIcon, _ref3, _ref4;
|
|
123
138
|
var index = _ref2.index,
|
|
124
139
|
key = _ref2.key;
|
|
125
140
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
@@ -132,11 +147,14 @@ var TreePanel = function TreePanel(_ref) {
|
|
|
132
147
|
checkable: checkable,
|
|
133
148
|
selectable: selectable,
|
|
134
149
|
defaultLeafIcon: defaultLeafIcon,
|
|
135
|
-
defaultNodeIcon: defaultNodeIcon,
|
|
150
|
+
defaultNodeIcon: (_makeIcon = makeIcon === null || makeIcon === void 0 ? void 0 : makeIcon(tree[index].data)) !== null && _makeIcon !== void 0 ? _makeIcon : defaultNodeIcon,
|
|
136
151
|
onToggle: toggleExpand,
|
|
137
152
|
onChecked: toggleCheck,
|
|
138
|
-
onSelect:
|
|
139
|
-
|
|
153
|
+
onSelect: _select,
|
|
154
|
+
onClick: onClick,
|
|
155
|
+
leafClassName: leafClassName,
|
|
156
|
+
nodeClassName: nodeClassName,
|
|
157
|
+
children: (_ref3 = (_ref4 = tree[index].data && (renderer === null || renderer === void 0 ? void 0 : renderer(tree[index].data))) !== null && _ref4 !== void 0 ? _ref4 : makeLabel === null || makeLabel === void 0 ? void 0 : makeLabel(tree[index].data)) !== null && _ref3 !== void 0 ? _ref3 : tree[index].label
|
|
140
158
|
})
|
|
141
159
|
}, key);
|
|
142
160
|
})]
|
package/dist/cjs/tree/useTree.js
CHANGED
|
@@ -19,39 +19,110 @@ var useTree = function useTree(_ref) {
|
|
|
19
19
|
_ref$checked = _ref.checked,
|
|
20
20
|
checked = _ref$checked === void 0 ? utilities.EMPTY_ARRAY : _ref$checked,
|
|
21
21
|
selected = _ref.selected,
|
|
22
|
+
sorter = _ref.sorter,
|
|
22
23
|
matcher = _ref.matcher,
|
|
24
|
+
onLoad = _ref.onLoad,
|
|
25
|
+
onQuery = _ref.onQuery,
|
|
23
26
|
onSelect = _ref.onSelect,
|
|
24
|
-
onChecked = _ref.onChecked
|
|
27
|
+
onChecked = _ref.onChecked,
|
|
28
|
+
defaultExpanded = _ref.defaultExpanded,
|
|
29
|
+
onExpandToggle = _ref.onExpandToggle;
|
|
25
30
|
var componentEvents = react.useRef({
|
|
26
31
|
onSelect: onSelect,
|
|
27
32
|
onChecked: onChecked
|
|
28
33
|
});
|
|
34
|
+
var intialExpand = react.useRef(defaultExpanded !== null && defaultExpanded !== void 0 ? defaultExpanded : utilities.EMPTY_ARRAY);
|
|
29
35
|
var itemList = createItemList(items);
|
|
36
|
+
var fireExpandToggle = react.useCallback(function (itemMap) {
|
|
37
|
+
var expandedList = itemMap.filter(function (node) {
|
|
38
|
+
return node.open;
|
|
39
|
+
}).map(function (node) {
|
|
40
|
+
return node.id;
|
|
41
|
+
});
|
|
42
|
+
setTimeout(function () {
|
|
43
|
+
return onExpandToggle === null || onExpandToggle === void 0 ? void 0 : onExpandToggle(expandedList);
|
|
44
|
+
}, 100);
|
|
45
|
+
}, [onExpandToggle]);
|
|
46
|
+
var loadChildren = react.useCallback(function (node) {
|
|
47
|
+
var _node$children;
|
|
48
|
+
if (node.open && !node.leaf && !((_node$children = node.children) !== null && _node$children !== void 0 && _node$children.length)) {
|
|
49
|
+
node.loading = true;
|
|
50
|
+
void Promise.resolve(onLoad === null || onLoad === void 0 ? void 0 : onLoad(node.id)).then(function () {
|
|
51
|
+
var resp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : utilities.EMPTY_ARRAY;
|
|
52
|
+
node.children = utils.refactorTree(resp, {
|
|
53
|
+
sorter: sorter,
|
|
54
|
+
defaultExpanded: defaultExpanded
|
|
55
|
+
}, {
|
|
56
|
+
level: node.level + 1,
|
|
57
|
+
parent: node.id
|
|
58
|
+
});
|
|
59
|
+
})["finally"](function () {
|
|
60
|
+
var _intialExpand$current;
|
|
61
|
+
node.loading = false;
|
|
62
|
+
dispatch({
|
|
63
|
+
type: "loaded"
|
|
64
|
+
});
|
|
65
|
+
((_intialExpand$current = intialExpand.current) === null || _intialExpand$current === void 0 ? void 0 : _intialExpand$current.length) > 0 && dispatch({
|
|
66
|
+
type: "expand",
|
|
67
|
+
id: intialExpand.current.shift()
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
var _intialExpand$current2;
|
|
72
|
+
dispatch({
|
|
73
|
+
type: "loaded"
|
|
74
|
+
});
|
|
75
|
+
((_intialExpand$current2 = intialExpand.current) === null || _intialExpand$current2 === void 0 ? void 0 : _intialExpand$current2.length) > 0 && dispatch({
|
|
76
|
+
type: "expand",
|
|
77
|
+
id: intialExpand.current.shift()
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}, [onLoad]);
|
|
30
81
|
var _useReducer = react.useReducer(function (state, action) {
|
|
31
82
|
if (action.type === "load") {
|
|
32
|
-
state.items = utils.refactorTree(action.items
|
|
83
|
+
state.items = utils.refactorTree(action.items, {
|
|
84
|
+
sorter: sorter,
|
|
85
|
+
defaultExpanded: defaultExpanded
|
|
86
|
+
});
|
|
33
87
|
state.itemMap = utils.makeTreeMap(state.items);
|
|
34
88
|
state.tree = utils.flattenTree(state.items);
|
|
35
89
|
return _objectSpread({}, state);
|
|
36
90
|
}
|
|
37
91
|
if (action.type === "toggleExpand") {
|
|
38
92
|
var node = state.itemMap.get(action.id);
|
|
39
|
-
|
|
93
|
+
if (node && !node.leaf) {
|
|
94
|
+
node && (node.open = !node.open);
|
|
95
|
+
loadChildren(node);
|
|
96
|
+
return _objectSpread({}, state);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (action.type === "loaded") {
|
|
100
|
+
state.itemMap = utils.makeTreeMap(state.items);
|
|
101
|
+
fireExpandToggle(Array.from(state.itemMap.values()));
|
|
40
102
|
state.tree = utils.flattenTree(state.items);
|
|
103
|
+
state.selected && utils.updateSelection(state.itemMap, state.selected, true);
|
|
41
104
|
return _objectSpread({}, state);
|
|
42
105
|
}
|
|
43
106
|
if (action.type === "expand") {
|
|
44
|
-
// TODO: check if children available, if not call onLoad to fetch node children
|
|
45
107
|
var _node = state.itemMap.get(action.id);
|
|
46
|
-
_node &&
|
|
47
|
-
|
|
48
|
-
|
|
108
|
+
if (_node && !_node.leaf) {
|
|
109
|
+
_node.open = true;
|
|
110
|
+
var parentId = _node.parent;
|
|
111
|
+
while (parentId) {
|
|
112
|
+
var _node2 = state.itemMap.get(parentId);
|
|
113
|
+
_node2 && (_node2.open = true);
|
|
114
|
+
parentId = _node2 === null || _node2 === void 0 ? void 0 : _node2.parent;
|
|
115
|
+
}
|
|
116
|
+
loadChildren(_node);
|
|
117
|
+
return _objectSpread({}, state);
|
|
118
|
+
}
|
|
49
119
|
}
|
|
50
120
|
if (action.type === "expandAll") {
|
|
51
|
-
// TODO: prevent opening dynamic nodes that dont have children
|
|
52
121
|
state.itemMap.forEach(function (node) {
|
|
53
|
-
|
|
122
|
+
var _node$children2;
|
|
123
|
+
!node.leaf && ((_node$children2 = node.children) === null || _node$children2 === void 0 ? void 0 : _node$children2.length) && (node.open = true);
|
|
54
124
|
});
|
|
125
|
+
fireExpandToggle(Array.from(state.itemMap.values()));
|
|
55
126
|
state.tree = utils.flattenTree(state.items);
|
|
56
127
|
return _objectSpread({}, state);
|
|
57
128
|
}
|
|
@@ -59,22 +130,28 @@ var useTree = function useTree(_ref) {
|
|
|
59
130
|
state.itemMap.forEach(function (node) {
|
|
60
131
|
!node.leaf && (node.open = false);
|
|
61
132
|
});
|
|
133
|
+
fireExpandToggle([]);
|
|
62
134
|
state.tree = utils.flattenTree(state.items);
|
|
63
135
|
return _objectSpread({}, state);
|
|
64
136
|
}
|
|
65
137
|
if (action.type === "filter") {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
138
|
+
if (onQuery) {
|
|
139
|
+
var _action$query;
|
|
140
|
+
onQuery((_action$query = action.query) !== null && _action$query !== void 0 ? _action$query : "");
|
|
141
|
+
} else {
|
|
142
|
+
utils.filterTree(state.itemMap, action.query, matcher);
|
|
143
|
+
state.tree = utils.flattenTree(state.items);
|
|
144
|
+
return _objectSpread({}, state);
|
|
145
|
+
}
|
|
69
146
|
}
|
|
70
147
|
if (action.type === "select") {
|
|
71
|
-
var _componentEvents$curr, _componentEvents$curr2;
|
|
148
|
+
var _componentEvents$curr, _componentEvents$curr2, _state$itemMap$get;
|
|
72
149
|
if (state.selected) {
|
|
73
150
|
utils.updateSelection(state.itemMap, state.selected);
|
|
74
151
|
}
|
|
75
152
|
utils.updateSelection(state.itemMap, action.id, true);
|
|
76
153
|
state.tree = utils.flattenTree(state.items);
|
|
77
|
-
(_componentEvents$curr = (_componentEvents$curr2 = componentEvents.current).onSelect) === null || _componentEvents$curr === void 0 || _componentEvents$curr.call(_componentEvents$curr2, action.id);
|
|
154
|
+
(_componentEvents$curr = (_componentEvents$curr2 = componentEvents.current).onSelect) === null || _componentEvents$curr === void 0 || _componentEvents$curr.call(_componentEvents$curr2, action.id, (_state$itemMap$get = state.itemMap.get(action.id)) === null || _state$itemMap$get === void 0 ? void 0 : _state$itemMap$get.data);
|
|
78
155
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
79
156
|
selected: action.id
|
|
80
157
|
});
|
|
@@ -116,10 +193,15 @@ var useTree = function useTree(_ref) {
|
|
|
116
193
|
};
|
|
117
194
|
}, [onSelect, onChecked]);
|
|
118
195
|
react.useEffect(function () {
|
|
196
|
+
var _intialExpand$current3;
|
|
119
197
|
dispatch({
|
|
120
198
|
type: "load",
|
|
121
199
|
items: itemList
|
|
122
200
|
});
|
|
201
|
+
itemList.length && ((_intialExpand$current3 = intialExpand.current) === null || _intialExpand$current3 === void 0 ? void 0 : _intialExpand$current3.length) > 0 && dispatch({
|
|
202
|
+
type: "expand",
|
|
203
|
+
id: intialExpand.current.shift()
|
|
204
|
+
});
|
|
123
205
|
}, [itemList]);
|
|
124
206
|
react.useEffect(function () {
|
|
125
207
|
selected && dispatch({
|
package/dist/cjs/tree/utils.js
CHANGED
|
@@ -6,7 +6,7 @@ var utilities = require('@react-fabric/utilities');
|
|
|
6
6
|
|
|
7
7
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
8
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
-
var
|
|
9
|
+
var defaultSorter = function defaultSorter(a, b) {
|
|
10
10
|
if (!!a.leaf !== !!b.leaf) return a.leaf ? 1 : -1;
|
|
11
11
|
return utilities.compareValues()(a.label, b.label);
|
|
12
12
|
};
|
|
@@ -28,15 +28,21 @@ var getIntermediate = function getIntermediate() {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
// convert node item to internal node used by the tree
|
|
31
|
-
var refactorTree = function refactorTree(nodes) {
|
|
32
|
-
var
|
|
31
|
+
var refactorTree = function refactorTree(nodes, _ref) {
|
|
32
|
+
var _ref$sorter = _ref.sorter,
|
|
33
|
+
sorter = _ref$sorter === void 0 ? defaultSorter : _ref$sorter,
|
|
34
|
+
_ref$defaultExpanded = _ref.defaultExpanded,
|
|
35
|
+
defaultExpanded = _ref$defaultExpanded === void 0 ? [] : _ref$defaultExpanded;
|
|
36
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
33
37
|
level: 0,
|
|
34
38
|
parent: undefined
|
|
35
39
|
};
|
|
36
40
|
var list = [];
|
|
37
|
-
nodes.sort(sorter)
|
|
41
|
+
if (sorter !== false) nodes = nodes.sort(sorter);
|
|
42
|
+
nodes.forEach(function (node) {
|
|
43
|
+
var _node$children;
|
|
38
44
|
list.push(_objectSpread(_objectSpread({
|
|
39
|
-
open:
|
|
45
|
+
open: defaultExpanded.includes(node.id) && !!((_node$children = node.children) !== null && _node$children !== void 0 && _node$children.length),
|
|
40
46
|
level: options.level,
|
|
41
47
|
parent: options.parent,
|
|
42
48
|
checked: 0,
|
|
@@ -47,6 +53,9 @@ var refactorTree = function refactorTree(nodes) {
|
|
|
47
53
|
}, node), {}, {
|
|
48
54
|
leaf: !!node.leaf,
|
|
49
55
|
children: node.children && refactorTree(node.children, {
|
|
56
|
+
sorter: sorter,
|
|
57
|
+
defaultExpanded: defaultExpanded
|
|
58
|
+
}, {
|
|
50
59
|
level: options.level + 1,
|
|
51
60
|
parent: node.id
|
|
52
61
|
})
|
|
@@ -72,11 +81,17 @@ var flattenTree = function flattenTree(nodes) {
|
|
|
72
81
|
return !node.filtered;
|
|
73
82
|
});
|
|
74
83
|
filtered.forEach(function (node, idx) {
|
|
84
|
+
var _node$children2;
|
|
75
85
|
node.lines = [].concat(_toConsumableArray(lines), [idx === filtered.length - 1 ? 2 : 3]);
|
|
76
86
|
list.push(node);
|
|
77
87
|
(node.open || node.childFiltered) && node.children && list.push.apply(list, _toConsumableArray(flattenTree(node.children.filter(function (child) {
|
|
78
88
|
return !child.filtered;
|
|
79
89
|
}), [].concat(_toConsumableArray(lines), [idx === filtered.length - 1 ? 0 : 1]))));
|
|
90
|
+
node.open && ((_node$children2 = node.children) === null || _node$children2 === void 0 ? void 0 : _node$children2.length) === 0 && list.push({
|
|
91
|
+
empty: true,
|
|
92
|
+
leaf: true,
|
|
93
|
+
lines: [].concat(_toConsumableArray(lines), [idx === filtered.length - 1 ? 0 : 1, 2])
|
|
94
|
+
});
|
|
80
95
|
});
|
|
81
96
|
return list;
|
|
82
97
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
3
4
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
5
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
4
6
|
var core = require('@react-fabric/core');
|
|
5
7
|
var utilities = require('@react-fabric/utilities');
|
|
6
8
|
var reactVirtual = require('@tanstack/react-virtual');
|
|
@@ -10,6 +12,9 @@ var react = require('react');
|
|
|
10
12
|
var Scroller = require('./Scroller.js');
|
|
11
13
|
var jsxRuntime = require('react/jsx-runtime');
|
|
12
14
|
|
|
15
|
+
var _excluded = ["items", "children", "columns", "fullWidth", "maxWidth", "minWidth", "total", "padding", "defaultHeight", "defaultWidth", "hideScroller", "initialScroll", "loading", "onLoadMore", "onScroll", "galleryRef"];
|
|
16
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
18
|
var createItemList = memoizeOne(function (items) {
|
|
14
19
|
return items;
|
|
15
20
|
});
|
|
@@ -18,6 +23,11 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
18
23
|
var items = _ref.items,
|
|
19
24
|
children = _ref.children,
|
|
20
25
|
columns = _ref.columns,
|
|
26
|
+
fullWidth = _ref.fullWidth,
|
|
27
|
+
maxWidth = _ref.maxWidth,
|
|
28
|
+
minWidth = _ref.minWidth,
|
|
29
|
+
_ref$total = _ref.total,
|
|
30
|
+
total = _ref$total === void 0 ? 0 : _ref$total,
|
|
21
31
|
_ref$padding = _ref.padding,
|
|
22
32
|
padding = _ref$padding === void 0 ? "md" : _ref$padding,
|
|
23
33
|
_ref$defaultHeight = _ref.defaultHeight,
|
|
@@ -29,16 +39,17 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
29
39
|
loading = _ref.loading,
|
|
30
40
|
onLoadMore = _ref.onLoadMore,
|
|
31
41
|
onScroll = _ref.onScroll,
|
|
32
|
-
galleryRef = _ref.galleryRef
|
|
42
|
+
galleryRef = _ref.galleryRef,
|
|
43
|
+
aria = _objectWithoutProperties(_ref, _excluded);
|
|
33
44
|
var count = react.useDeferredValue(items.length);
|
|
34
45
|
var extraSize = react.useMemo(function () {
|
|
35
|
-
return onLoadMore ?
|
|
46
|
+
return onLoadMore ? 8 : 0;
|
|
36
47
|
}, [onLoadMore]);
|
|
37
|
-
var itemList = createItemList(items.map(function (item,
|
|
48
|
+
var itemList = createItemList(items.map(function (item, index) {
|
|
38
49
|
return {
|
|
39
|
-
index:
|
|
40
|
-
|
|
41
|
-
isLast:
|
|
50
|
+
index: index,
|
|
51
|
+
item: item,
|
|
52
|
+
isLast: index + 1 === items.length
|
|
42
53
|
};
|
|
43
54
|
}));
|
|
44
55
|
var scrollerRef = react.useRef(null);
|
|
@@ -112,26 +123,24 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
112
123
|
setScrollActive(calculateActiveScroll());
|
|
113
124
|
}, [count, calculateActiveScroll]);
|
|
114
125
|
react.useEffect(function () {
|
|
115
|
-
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
};
|
|
123
|
-
}, [onLoadMore, loading, itemList, virtualItems, count, columnCount]);
|
|
124
|
-
react.useEffect(function () {
|
|
125
|
-
var _virtualItems$2;
|
|
126
|
-
var firstItem = (_virtualItems$2 = virtualItems[0]) === null || _virtualItems$2 === void 0 ? void 0 : _virtualItems$2.index;
|
|
127
|
-
if (onLoadMore && firstItem !== undefined && items[firstItem * columnCount] === null) {
|
|
126
|
+
if (onLoadMore) {
|
|
127
|
+
var _virtualItems$2, _virtualItems$slice$p;
|
|
128
|
+
var firstItem = (_virtualItems$2 = virtualItems[0]) === null || _virtualItems$2 === void 0 ? void 0 : _virtualItems$2.index;
|
|
129
|
+
var lastItem = virtualItems === null || virtualItems === void 0 || (_virtualItems$slice$p = virtualItems.slice(-1).pop()) === null || _virtualItems$slice$p === void 0 ? void 0 : _virtualItems$slice$p.index;
|
|
130
|
+
var lastIndex = (lastItem !== null && lastItem !== void 0 ? lastItem : 0) * columnCount + columnCount;
|
|
131
|
+
var canLoadPrevPage = firstItem !== undefined && items[firstItem * columnCount] === null;
|
|
132
|
+
var canLoadNextPage = lastItem !== undefined && lastIndex >= count - 1 && count < total;
|
|
128
133
|
var db = utilities.debounce(onLoadMore);
|
|
129
|
-
|
|
134
|
+
if (canLoadPrevPage) {
|
|
135
|
+
db(firstItem);
|
|
136
|
+
} else if (!loading && canLoadNextPage) {
|
|
137
|
+
db(lastItem + 1);
|
|
138
|
+
}
|
|
130
139
|
return function () {
|
|
131
140
|
return db.cancel();
|
|
132
141
|
};
|
|
133
142
|
}
|
|
134
|
-
}, [onLoadMore,
|
|
143
|
+
}, [onLoadMore, virtualItems]);
|
|
135
144
|
react.useLayoutEffect(function () {
|
|
136
145
|
setTimeout(function () {
|
|
137
146
|
initialScroll && virtualizer.scrollToIndex(Math.floor(initialScroll / columnCount), {
|
|
@@ -143,14 +152,14 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
143
152
|
return {
|
|
144
153
|
scrollToItem: function scrollToItem(index) {
|
|
145
154
|
virtualizer.scrollToIndex(Math.floor(index / columnCount), {
|
|
146
|
-
align: "
|
|
155
|
+
align: "auto"
|
|
147
156
|
});
|
|
148
157
|
},
|
|
149
158
|
hilight: function hilight(index) {
|
|
150
159
|
var _scrollerRef$current2;
|
|
151
160
|
(_scrollerRef$current2 = scrollerRef.current) === null || _scrollerRef$current2 === void 0 || (_scrollerRef$current2 = _scrollerRef$current2.querySelector(".hilight")) === null || _scrollerRef$current2 === void 0 || _scrollerRef$current2.classList.remove("hilight", "ring-1");
|
|
152
161
|
virtualizer.scrollToIndex(Math.floor(index / columnCount), {
|
|
153
|
-
align: "
|
|
162
|
+
align: "auto"
|
|
154
163
|
});
|
|
155
164
|
setTimeout(function () {
|
|
156
165
|
var _scrollerRef$current3;
|
|
@@ -163,17 +172,22 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
163
172
|
}
|
|
164
173
|
};
|
|
165
174
|
}, [virtualizer, columnCount]);
|
|
166
|
-
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
175
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", _objectSpread(_objectSpread({
|
|
167
176
|
ref: scrollerRef,
|
|
168
177
|
onScroll: handleScroll,
|
|
169
|
-
className: classNames("area-content bg-base overflow-auto contain-strict")
|
|
178
|
+
className: classNames("area-content bg-base overflow-auto contain-strict")
|
|
179
|
+
}, aria), {}, {
|
|
170
180
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
171
181
|
className: classNames("inline-flex flex-nowrap gap-2 justify-center min-h-full min-w-full"),
|
|
172
182
|
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
173
|
-
className: classNames("box-content", padding === "sm" && "p-1", padding === "md" && "p-2", padding === "lg" && "p-4"),
|
|
183
|
+
className: classNames("box-content", fullWidth && "flex-1", padding === "sm" && "p-1", padding === "md" && "p-2", padding === "lg" && "p-4"),
|
|
184
|
+
style: {
|
|
185
|
+
minWidth: minWidth,
|
|
186
|
+
maxWidth: maxWidth
|
|
187
|
+
},
|
|
174
188
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
175
189
|
style: {
|
|
176
|
-
height: virtualizer.getTotalSize()
|
|
190
|
+
height: virtualizer.getTotalSize() + extraSize
|
|
177
191
|
},
|
|
178
192
|
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
179
193
|
style: {
|
|
@@ -184,7 +198,7 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
184
198
|
index = _ref3.index,
|
|
185
199
|
measureElement = _ref3.measureElement;
|
|
186
200
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
187
|
-
className: "flex",
|
|
201
|
+
className: "flex justify-start",
|
|
188
202
|
"data-index": index,
|
|
189
203
|
ref: measureElement,
|
|
190
204
|
children: columnMap.map(function (col) {
|
|
@@ -220,7 +234,7 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
220
234
|
})
|
|
221
235
|
})]
|
|
222
236
|
})
|
|
223
|
-
});
|
|
237
|
+
}));
|
|
224
238
|
};
|
|
225
239
|
_VirtualGallery.displayName = "VirtualGallery";
|
|
226
240
|
var GenericMemo = react.memo;
|