1 | "use strict";
|
2 |
|
3 | var _typeof = require("@babel/runtime/helpers/typeof");
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports.default = useFlattenRecords;
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 | function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
10 | function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
11 |
|
12 | function fillRecords(list, record, indent, childrenColumnName, expandedKeys, getRowKey, index) {
|
13 | list.push({
|
14 | record: record,
|
15 | indent: indent,
|
16 | index: index
|
17 | });
|
18 | var key = getRowKey(record);
|
19 | var expanded = expandedKeys === null || expandedKeys === void 0 ? void 0 : expandedKeys.has(key);
|
20 | if (record && Array.isArray(record[childrenColumnName]) && expanded) {
|
21 |
|
22 | for (var i = 0; i < record[childrenColumnName].length; i += 1) {
|
23 | fillRecords(list, record[childrenColumnName][i], indent + 1, childrenColumnName, expandedKeys, getRowKey, i);
|
24 | }
|
25 | }
|
26 | }
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | function useFlattenRecords(data, childrenColumnName, expandedKeys, getRowKey) {
|
39 | var arr = React.useMemo(function () {
|
40 | if (expandedKeys !== null && expandedKeys !== void 0 && expandedKeys.size) {
|
41 | var list = [];
|
42 |
|
43 |
|
44 | for (var i = 0; i < (data === null || data === void 0 ? void 0 : data.length); i += 1) {
|
45 | var record = data[i];
|
46 |
|
47 |
|
48 | fillRecords(list, record, 0, childrenColumnName, expandedKeys, getRowKey, i);
|
49 | }
|
50 | return list;
|
51 | }
|
52 | return data === null || data === void 0 ? void 0 : data.map(function (item, index) {
|
53 | return {
|
54 | record: item,
|
55 | indent: 0,
|
56 | index: index
|
57 | };
|
58 | });
|
59 | }, [data, childrenColumnName, expandedKeys, getRowKey]);
|
60 | return arr;
|
61 | } |
\ | No newline at end of file |