@vuu-ui/vuu-data-local 0.0.26
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/LICENSE +201 -0
- package/README.md +0 -0
- package/cjs/array-data-source/aggregate-utils.js +243 -0
- package/cjs/array-data-source/aggregate-utils.js.map +1 -0
- package/cjs/array-data-source/array-data-source.js +539 -0
- package/cjs/array-data-source/array-data-source.js.map +1 -0
- package/cjs/array-data-source/array-data-utils.js +52 -0
- package/cjs/array-data-source/array-data-utils.js.map +1 -0
- package/cjs/array-data-source/group-utils.js +169 -0
- package/cjs/array-data-source/group-utils.js.map +1 -0
- package/cjs/array-data-source/sort-utils.js +54 -0
- package/cjs/array-data-source/sort-utils.js.map +1 -0
- package/cjs/index.js +10 -0
- package/cjs/index.js.map +1 -0
- package/cjs/json-data-source/json-data-source.js +388 -0
- package/cjs/json-data-source/json-data-source.js.map +1 -0
- package/esm/array-data-source/aggregate-utils.js +241 -0
- package/esm/array-data-source/aggregate-utils.js.map +1 -0
- package/esm/array-data-source/array-data-source.js +537 -0
- package/esm/array-data-source/array-data-source.js.map +1 -0
- package/esm/array-data-source/array-data-utils.js +49 -0
- package/esm/array-data-source/array-data-utils.js.map +1 -0
- package/esm/array-data-source/group-utils.js +165 -0
- package/esm/array-data-source/group-utils.js.map +1 -0
- package/esm/array-data-source/sort-utils.js +52 -0
- package/esm/array-data-source/sort-utils.js.map +1 -0
- package/esm/index.js +3 -0
- package/esm/index.js.map +1 -0
- package/esm/json-data-source/json-data-source.js +386 -0
- package/esm/json-data-source/json-data-source.js.map +1 -0
- package/package.json +34 -0
- package/types/array-data-source/aggregate-utils.d.ts +8 -0
- package/types/array-data-source/array-data-source.d.ts +81 -0
- package/types/array-data-source/array-data-utils.d.ts +4 -0
- package/types/array-data-source/group-utils.d.ts +10 -0
- package/types/array-data-source/sort-utils.d.ts +4 -0
- package/types/index.d.ts +2 -0
- package/types/json-data-source/json-data-source.d.ts +54 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { metadataKeys } from '@vuu-ui/vuu-utils';
|
|
2
|
+
|
|
3
|
+
const { DEPTH, IS_EXPANDED, KEY } = metadataKeys;
|
|
4
|
+
const collapseGroup = (key, groupedRows) => {
|
|
5
|
+
const rows = [];
|
|
6
|
+
for (let i = 0, idx = 0, collapsed = false, len = groupedRows.length; i < len; i++) {
|
|
7
|
+
const row = groupedRows[i];
|
|
8
|
+
const { [DEPTH]: depth, [KEY]: rowKey } = row;
|
|
9
|
+
if (rowKey === key) {
|
|
10
|
+
const collapsedRow = row.slice();
|
|
11
|
+
collapsedRow[IS_EXPANDED] = false;
|
|
12
|
+
rows.push(collapsedRow);
|
|
13
|
+
idx += 1;
|
|
14
|
+
collapsed = true;
|
|
15
|
+
while (i < len - 1 && groupedRows[i + 1][DEPTH] > depth) {
|
|
16
|
+
i += 1;
|
|
17
|
+
}
|
|
18
|
+
} else if (collapsed) {
|
|
19
|
+
const newRow = row.slice();
|
|
20
|
+
newRow[0] = idx;
|
|
21
|
+
newRow[1] = idx;
|
|
22
|
+
rows.push(newRow);
|
|
23
|
+
idx += 1;
|
|
24
|
+
} else {
|
|
25
|
+
rows.push(row);
|
|
26
|
+
idx += 1;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return rows;
|
|
30
|
+
};
|
|
31
|
+
const expandGroup = (keys, sourceRows, groupBy, columnMap, groupMap, processedData) => {
|
|
32
|
+
const groupIndices = groupBy.map((column) => columnMap[column]);
|
|
33
|
+
return dataRowsFromGroups2(
|
|
34
|
+
groupMap,
|
|
35
|
+
groupIndices,
|
|
36
|
+
keys,
|
|
37
|
+
sourceRows,
|
|
38
|
+
void 0,
|
|
39
|
+
void 0,
|
|
40
|
+
void 0,
|
|
41
|
+
processedData
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
const dataRowsFromGroups2 = (groupMap, groupIndices, openKeys, sourceRows = [], root = "$root", depth = 1, rows = [], processedData) => {
|
|
45
|
+
console.log(`dataRowsFromGroups2 1)`);
|
|
46
|
+
const keys = Object.keys(groupMap).sort();
|
|
47
|
+
for (const key of keys) {
|
|
48
|
+
const idx = rows.length;
|
|
49
|
+
const groupKey = `${root}|${key}`;
|
|
50
|
+
const row = [idx, idx, false, false, depth, 0, groupKey, 0];
|
|
51
|
+
row[groupIndices[depth - 1]] = key;
|
|
52
|
+
rows.push(row);
|
|
53
|
+
if (openKeys.includes(groupKey)) {
|
|
54
|
+
row[IS_EXPANDED] = true;
|
|
55
|
+
if (Array.isArray(groupMap[key])) {
|
|
56
|
+
pushChildren(
|
|
57
|
+
rows,
|
|
58
|
+
groupMap[key],
|
|
59
|
+
sourceRows,
|
|
60
|
+
groupKey,
|
|
61
|
+
depth + 1
|
|
62
|
+
);
|
|
63
|
+
} else {
|
|
64
|
+
dataRowsFromGroups2(
|
|
65
|
+
groupMap[key],
|
|
66
|
+
groupIndices,
|
|
67
|
+
openKeys,
|
|
68
|
+
sourceRows,
|
|
69
|
+
groupKey,
|
|
70
|
+
depth + 1,
|
|
71
|
+
rows,
|
|
72
|
+
processedData
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
console.log(`dataRowsFromGroups2 2)`);
|
|
78
|
+
for (const key in rows) {
|
|
79
|
+
for (const index in rows) {
|
|
80
|
+
if (rows[key][2] === false && processedData[index] != void 0) {
|
|
81
|
+
if (rows[key][groupIndices[0]] === processedData[index][groupIndices[0]]) {
|
|
82
|
+
rows[key] = rows[key].splice(0, 8).concat(
|
|
83
|
+
processedData[index].slice(
|
|
84
|
+
8,
|
|
85
|
+
// groupIndices[0] + 1,
|
|
86
|
+
processedData[index].length
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
console.log(`dataRowsFromGroups2 3)`);
|
|
95
|
+
return rows;
|
|
96
|
+
};
|
|
97
|
+
const pushChildren = (rows, tree, sourceRows, parentKey, depth) => {
|
|
98
|
+
for (const rowIdx of tree) {
|
|
99
|
+
const idx = rows.length;
|
|
100
|
+
const sourceRow = sourceRows[rowIdx].slice();
|
|
101
|
+
sourceRow[0] = idx;
|
|
102
|
+
sourceRow[1] = idx;
|
|
103
|
+
sourceRow[DEPTH] = depth;
|
|
104
|
+
sourceRow[KEY] = `${parentKey}|${sourceRow[KEY]}`;
|
|
105
|
+
rows.push(sourceRow);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const groupRows = (rows, groupBy, columnMap) => {
|
|
109
|
+
const groupIndices = groupBy.map((column) => columnMap[column]);
|
|
110
|
+
const groupTree = groupLeafRows(rows, groupIndices);
|
|
111
|
+
const groupedDataRows = dataRowsFromGroups(groupTree, groupIndices);
|
|
112
|
+
return [groupedDataRows, groupTree];
|
|
113
|
+
};
|
|
114
|
+
const dataRowsFromGroups = (groupTree, groupIndices) => {
|
|
115
|
+
const depth = 0;
|
|
116
|
+
const rows = [];
|
|
117
|
+
let idx = 0;
|
|
118
|
+
const keys = Object.keys(groupTree).sort();
|
|
119
|
+
for (const key of keys) {
|
|
120
|
+
const row = [
|
|
121
|
+
idx,
|
|
122
|
+
idx,
|
|
123
|
+
false,
|
|
124
|
+
false,
|
|
125
|
+
1,
|
|
126
|
+
0,
|
|
127
|
+
`$root|${key}`,
|
|
128
|
+
0
|
|
129
|
+
];
|
|
130
|
+
row[groupIndices[depth]] = key;
|
|
131
|
+
rows.push(row);
|
|
132
|
+
idx += 1;
|
|
133
|
+
}
|
|
134
|
+
return rows;
|
|
135
|
+
};
|
|
136
|
+
function groupLeafRows(leafRows, groupby) {
|
|
137
|
+
const groups = {};
|
|
138
|
+
const levels = groupby.length;
|
|
139
|
+
const lastLevel = levels - 1;
|
|
140
|
+
for (let i = 0, len = leafRows.length; i < len; i++) {
|
|
141
|
+
const leafRow = leafRows[i];
|
|
142
|
+
let target = groups;
|
|
143
|
+
let targetNode;
|
|
144
|
+
let key;
|
|
145
|
+
for (let level = 0; level < levels; level++) {
|
|
146
|
+
const colIdx = groupby[level];
|
|
147
|
+
key = leafRow[colIdx].toString();
|
|
148
|
+
targetNode = target[key];
|
|
149
|
+
if (targetNode && level === lastLevel) {
|
|
150
|
+
targetNode.push(i);
|
|
151
|
+
} else if (targetNode) {
|
|
152
|
+
target = targetNode;
|
|
153
|
+
} else if (!targetNode && level < lastLevel) {
|
|
154
|
+
target = target[key] = {};
|
|
155
|
+
} else if (!targetNode) {
|
|
156
|
+
target[key] = [i];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
console.log("!! groups", groups);
|
|
161
|
+
return groups;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export { collapseGroup, expandGroup, groupRows };
|
|
165
|
+
//# sourceMappingURL=group-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-utils.js","sources":["../../src/array-data-source/group-utils.ts"],"sourcesContent":["import type { DataSourceRow } from \"@vuu-ui/vuu-data-types\";\nimport type { VuuGroupBy } from \"@vuu-ui/vuu-protocol-types\";\nimport { ColumnMap, metadataKeys } from \"@vuu-ui/vuu-utils\";\n\nexport type KeyList = number[];\nexport type GroupMap = { [key: string]: GroupMap | KeyList };\n\nconst { DEPTH, IS_EXPANDED, KEY } = metadataKeys;\n\nexport const collapseGroup = (\n key: string,\n groupedRows: readonly DataSourceRow[]\n): DataSourceRow[] => {\n const rows: DataSourceRow[] = [];\n\n for (\n let i = 0, idx = 0, collapsed = false, len = groupedRows.length;\n i < len;\n i++\n ) {\n const row = groupedRows[i];\n const { [DEPTH]: depth, [KEY]: rowKey } = row;\n if (rowKey === key) {\n const collapsedRow = row.slice() as DataSourceRow;\n collapsedRow[IS_EXPANDED] = false;\n rows.push(collapsedRow);\n idx += 1;\n collapsed = true;\n while (i < len - 1 && groupedRows[i + 1][DEPTH] > depth) {\n i += 1;\n }\n } else if (collapsed) {\n const newRow = row.slice() as DataSourceRow;\n newRow[0] = idx;\n newRow[1] = idx;\n rows.push(newRow);\n idx += 1;\n } else {\n rows.push(row);\n idx += 1;\n }\n }\n\n return rows;\n};\n\nexport const expandGroup = (\n keys: string[],\n sourceRows: readonly DataSourceRow[],\n groupBy: VuuGroupBy,\n columnMap: ColumnMap,\n groupMap: GroupMap,\n processedData: readonly DataSourceRow[]\n): DataSourceRow[] => {\n const groupIndices = groupBy.map<number>((column) => columnMap[column]);\n return dataRowsFromGroups2(\n groupMap,\n groupIndices,\n keys,\n sourceRows,\n undefined,\n undefined,\n undefined,\n processedData\n );\n};\n\nconst dataRowsFromGroups2 = (\n groupMap: GroupMap,\n groupIndices: number[],\n openKeys: string[],\n sourceRows: readonly DataSourceRow[] = [],\n root = \"$root\",\n depth = 1,\n rows: DataSourceRow[] = [],\n processedData: readonly DataSourceRow[]\n) => {\n console.log(`dataRowsFromGroups2 1)`);\n const keys = Object.keys(groupMap).sort();\n for (const key of keys) {\n const idx = rows.length;\n const groupKey = `${root}|${key}`;\n const row: DataSourceRow = [idx, idx, false, false, depth, 0, groupKey, 0];\n // TODO whats this\n row[groupIndices[depth - 1]] = key;\n rows.push(row);\n\n if (openKeys.includes(groupKey)) {\n row[IS_EXPANDED] = true;\n if (Array.isArray(groupMap[key])) {\n pushChildren(\n rows,\n groupMap[key] as KeyList,\n sourceRows,\n groupKey,\n depth + 1\n );\n } else {\n dataRowsFromGroups2(\n groupMap[key] as GroupMap,\n groupIndices,\n openKeys,\n sourceRows,\n groupKey,\n depth + 1,\n rows,\n processedData\n );\n }\n }\n }\n console.log(`dataRowsFromGroups2 2)`);\n\n for (const key in rows) {\n for (const index in rows) {\n if (rows[key][2] === false && processedData[index] != undefined) {\n if (\n rows[key][groupIndices[0]] === processedData[index][groupIndices[0]]\n ) {\n rows[key] = rows[key].splice(0, 8).concat(\n processedData[index].slice(\n 8, // groupIndices[0] + 1,\n processedData[index].length\n )\n ) as DataSourceRow;\n break;\n }\n }\n }\n }\n console.log(`dataRowsFromGroups2 3)`);\n\n return rows;\n};\n\nconst pushChildren = (\n rows: DataSourceRow[],\n tree: KeyList,\n sourceRows: readonly DataSourceRow[],\n parentKey: string,\n depth: number\n) => {\n for (const rowIdx of tree) {\n const idx = rows.length;\n const sourceRow = sourceRows[rowIdx].slice() as DataSourceRow;\n sourceRow[0] = idx;\n sourceRow[1] = idx;\n sourceRow[DEPTH] = depth;\n sourceRow[KEY] = `${parentKey}|${sourceRow[KEY]}`;\n rows.push(sourceRow);\n }\n};\n\nexport const groupRows = (\n rows: readonly DataSourceRow[],\n groupBy: VuuGroupBy,\n columnMap: ColumnMap\n): [DataSourceRow[], GroupMap] => {\n const groupIndices = groupBy.map<number>((column) => columnMap[column]);\n const groupTree = groupLeafRows(rows, groupIndices);\n const groupedDataRows = dataRowsFromGroups(groupTree, groupIndices);\n // 2) collapse int groups\n\n return [groupedDataRows, groupTree];\n};\n\nconst dataRowsFromGroups = (groupTree: GroupMap, groupIndices: number[]) => {\n const depth = 0;\n const rows: DataSourceRow[] = [];\n let idx = 0;\n const keys = Object.keys(groupTree).sort();\n for (const key of keys) {\n const row: DataSourceRow = [\n idx,\n idx,\n false,\n false,\n 1,\n 0,\n `$root|${key}`,\n 0,\n ];\n row[groupIndices[depth]] = key;\n rows.push(row);\n idx += 1;\n }\n return rows;\n};\n\nfunction groupLeafRows(leafRows: readonly DataSourceRow[], groupby: number[]) {\n const groups: GroupMap = {};\n const levels = groupby.length;\n const lastLevel = levels - 1;\n for (let i = 0, len = leafRows.length; i < len; i++) {\n const leafRow = leafRows[i];\n let target: GroupMap | KeyList = groups;\n let targetNode;\n let key;\n for (let level = 0; level < levels; level++) {\n const colIdx = groupby[level];\n key = leafRow[colIdx].toString();\n targetNode = (target as GroupMap)[key];\n if (targetNode && level === lastLevel) {\n // we're at leaf level, targetNode can only be a KeyList\n (targetNode as KeyList).push(i);\n } else if (targetNode) {\n target = targetNode;\n } else if (!targetNode && level < lastLevel) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n target = target[key] = {};\n } else if (!targetNode) {\n (target as GroupMap)[key] = [i];\n }\n }\n }\n console.log(\"!! groups\", groups);\n return groups;\n}\n"],"names":[],"mappings":";;AAOA,MAAM,EAAE,KAAA,EAAO,WAAa,EAAA,GAAA,EAAQ,GAAA,YAAA,CAAA;AAEvB,MAAA,aAAA,GAAgB,CAC3B,GAAA,EACA,WACoB,KAAA;AACpB,EAAA,MAAM,OAAwB,EAAC,CAAA;AAE/B,EACM,KAAA,IAAA,CAAA,GAAI,CAAG,EAAA,GAAA,GAAM,CAAG,EAAA,SAAA,GAAY,KAAO,EAAA,GAAA,GAAM,WAAY,CAAA,MAAA,EACzD,CAAI,GAAA,GAAA,EACJ,CACA,EAAA,EAAA;AACA,IAAM,MAAA,GAAA,GAAM,YAAY,CAAC,CAAA,CAAA;AACzB,IAAM,MAAA,EAAE,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,GAAG,MAAA,EAAW,GAAA,GAAA,CAAA;AAC1C,IAAA,IAAI,WAAW,GAAK,EAAA;AAClB,MAAM,MAAA,YAAA,GAAe,IAAI,KAAM,EAAA,CAAA;AAC/B,MAAA,YAAA,CAAa,WAAW,CAAI,GAAA,KAAA,CAAA;AAC5B,MAAA,IAAA,CAAK,KAAK,YAAY,CAAA,CAAA;AACtB,MAAO,GAAA,IAAA,CAAA,CAAA;AACP,MAAY,SAAA,GAAA,IAAA,CAAA;AACZ,MAAO,OAAA,CAAA,GAAI,MAAM,CAAK,IAAA,WAAA,CAAY,IAAI,CAAC,CAAA,CAAE,KAAK,CAAA,GAAI,KAAO,EAAA;AACvD,QAAK,CAAA,IAAA,CAAA,CAAA;AAAA,OACP;AAAA,eACS,SAAW,EAAA;AACpB,MAAM,MAAA,MAAA,GAAS,IAAI,KAAM,EAAA,CAAA;AACzB,MAAA,MAAA,CAAO,CAAC,CAAI,GAAA,GAAA,CAAA;AACZ,MAAA,MAAA,CAAO,CAAC,CAAI,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A;AACjC,IAAI,IAAA,UAAA,CAAA;AACJ,IAAI,IAAA,GAAA,CAAA;AACJ,IAAA,KAAA,IAAS,KAAQ,GAAA,CAAA,EAAG,KAAQ,GAAA,MAAA,EAAQ,KAAS,EAAA,EAAA;AAC3C,MAAM,MAAA,MAAA,GAAS,QAAQ,KAAK,CAAA,CAAA;AAC5B,MAAM,GAAA,GAAA,OAAA,CAAQ,MAAM,CAAA,CAAE,QAAS,EAAA,CAAA;AAC/B,MAAA,UAAA,GAAc,OAAoB,GAAG,CAAA,CAAA;AACrC,MAAI,IAAA,UAAA,IAAc,UAAU,SAAW,EAAA;AAErC,QAAC,UAAA,CAAuB,KAAK,CAAC,CAAA,CAAA;AAAA,iBACrB,UAAY,EAAA;AACrB,QAAS,MAAA,GAAA,UAAA,CAAA;AAAA,OACA,MAAA,IAAA,CAAC,UAAc,IAAA,KAAA,GAAQ,SAAW,EAAA;AAG3C,QAAS,MAAA,GAAA,MAAA,CAAO,GAAG,CAAA,GAAI,EAAC,CAAA;AAAA,OAC1B,MAAA,IAAW,CAAC,UAAY,EAAA;AACtB,QAAC,MAAoB,CAAA,GAAG,CAAI,GAAA,CAAC,CAAC,CAAA,CAAA;AAAA,OAChC;AAAA,KACF;AAAA,GACF;AACA,EAAQ,OAAA,CAAA,GAAA,CAAI,aAAa,MAAM,CAAA,CAAA;AAC/B,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const defaultSortPredicate = (r1, r2, [i, direction]) => {
|
|
2
|
+
const val1 = direction === "D" ? r2[i] : r1[i];
|
|
3
|
+
const val2 = direction === "D" ? r1[i] : r2[i];
|
|
4
|
+
if (val1 === val2) {
|
|
5
|
+
return 0;
|
|
6
|
+
} else if (val2 === null || val1 > val2) {
|
|
7
|
+
return 1;
|
|
8
|
+
} else {
|
|
9
|
+
return -1;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const sortComparator = (sortDefs) => {
|
|
13
|
+
if (sortDefs.length === 1) {
|
|
14
|
+
return singleColComparator(sortDefs);
|
|
15
|
+
} else if (sortDefs.length === 2) {
|
|
16
|
+
return twoColComparator(sortDefs);
|
|
17
|
+
} else {
|
|
18
|
+
return multiColComparator(sortDefs);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const singleColComparator = ([[i, direction]]) => (r1, r2) => {
|
|
22
|
+
const v1 = direction === "D" ? r2[i] : r1[i];
|
|
23
|
+
const v2 = direction === "D" ? r1[i] : r2[i];
|
|
24
|
+
return v1 > v2 ? 1 : v2 > v1 ? -1 : 0;
|
|
25
|
+
};
|
|
26
|
+
const twoColComparator = ([[idx1, direction1], [idx2, direction2]]) => (r1, r2) => {
|
|
27
|
+
const v1 = direction1 === "D" ? r2[idx1] : r1[idx1];
|
|
28
|
+
const v2 = direction1 === "D" ? r1[idx1] : r2[idx1];
|
|
29
|
+
const v3 = direction2 === "D" ? r2[idx2] : r1[idx2];
|
|
30
|
+
const v4 = direction2 === "D" ? r1[idx2] : r2[idx2];
|
|
31
|
+
return v1 > v2 ? 1 : v2 > v1 ? -1 : v3 > v4 ? 1 : v4 > v3 ? -1 : 0;
|
|
32
|
+
};
|
|
33
|
+
const multiColComparator = (sortDefs, test = defaultSortPredicate) => (r1, r2) => {
|
|
34
|
+
for (const sortDef of sortDefs) {
|
|
35
|
+
const result = test(r1, r2, sortDef);
|
|
36
|
+
if (result !== 0) {
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return 0;
|
|
41
|
+
};
|
|
42
|
+
const sortRows = (rows, { sortDefs }, columnMap) => {
|
|
43
|
+
const indexedSortDefs = sortDefs.map(({ column, sortType }) => [
|
|
44
|
+
columnMap[column],
|
|
45
|
+
sortType
|
|
46
|
+
]);
|
|
47
|
+
const comparator = sortComparator(indexedSortDefs);
|
|
48
|
+
return rows.slice().sort(comparator);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { sortRows };
|
|
52
|
+
//# sourceMappingURL=sort-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort-utils.js","sources":["../../src/array-data-source/sort-utils.ts"],"sourcesContent":["import type { DataSourceRow } from \"@vuu-ui/vuu-data-types\";\nimport type { VuuSort, VuuSortType } from \"@vuu-ui/vuu-protocol-types\";\nimport { ColumnMap } from \"@vuu-ui/vuu-utils\";\n\ntype SortDef = [number, VuuSortType];\ntype SortPredicate = (\n r1: DataSourceRow,\n r2: DataSourceRow,\n sortDefDef: SortDef\n) => SortCompareResult;\ntype SortCompareResult = 0 | 1 | -1;\ntype RowSortComparatorFactory = (\n sortDefs: SortDef[],\n test?: SortPredicate\n) => RowSortComparator;\ntype RowSortComparator = (\n item1: DataSourceRow,\n item2: DataSourceRow\n) => SortCompareResult;\n\nconst defaultSortPredicate: SortPredicate = (r1, r2, [i, direction]) => {\n const val1 = direction === \"D\" ? r2[i] : r1[i];\n const val2 = direction === \"D\" ? r1[i] : r2[i];\n if (val1 === val2) {\n return 0;\n } else if (val2 === null || val1 > val2) {\n return 1;\n } else {\n return -1;\n }\n};\n\nconst sortComparator = (sortDefs: SortDef[]): RowSortComparator => {\n if (sortDefs.length === 1) {\n return singleColComparator(sortDefs);\n } else if (sortDefs.length === 2) {\n return twoColComparator(sortDefs);\n } else {\n return multiColComparator(sortDefs);\n }\n};\n\nconst singleColComparator: RowSortComparatorFactory =\n ([[i, direction]]) =>\n (r1, r2) => {\n const v1 = direction === \"D\" ? r2[i] : r1[i];\n const v2 = direction === \"D\" ? r1[i] : r2[i];\n return v1 > v2 ? 1 : v2 > v1 ? -1 : 0;\n };\n\nconst twoColComparator: RowSortComparatorFactory =\n ([[idx1, direction1], [idx2, direction2]]) =>\n (r1, r2) => {\n const v1 = direction1 === \"D\" ? r2[idx1] : r1[idx1];\n const v2 = direction1 === \"D\" ? r1[idx1] : r2[idx1];\n const v3 = direction2 === \"D\" ? r2[idx2] : r1[idx2];\n const v4 = direction2 === \"D\" ? r1[idx2] : r2[idx2];\n return v1 > v2 ? 1 : v2 > v1 ? -1 : v3 > v4 ? 1 : v4 > v3 ? -1 : 0;\n };\n\nconst multiColComparator: RowSortComparatorFactory =\n (sortDefs, test = defaultSortPredicate) =>\n (r1, r2) => {\n for (const sortDef of sortDefs) {\n const result = test(r1, r2, sortDef);\n if (result !== 0) {\n return result;\n }\n }\n return 0;\n };\n\nexport const sortRows = (\n rows: readonly DataSourceRow[],\n { sortDefs }: VuuSort,\n columnMap: ColumnMap\n) => {\n const indexedSortDefs = sortDefs.map<SortDef>(({ column, sortType }) => [\n columnMap[column],\n sortType,\n ]);\n const comparator = sortComparator(indexedSortDefs);\n return rows.slice().sort(comparator);\n};\n"],"names":[],"mappings":"AAoBA,MAAM,uBAAsC,CAAC,EAAA,EAAI,IAAI,CAAC,CAAA,EAAG,SAAS,CAAM,KAAA;AACtE,EAAA,MAAM,OAAO,SAAc,KAAA,GAAA,GAAM,GAAG,CAAC,CAAA,GAAI,GAAG,CAAC,CAAA,CAAA;AAC7C,EAAA,MAAM,OAAO,SAAc,KAAA,GAAA,GAAM,GAAG,CAAC,CAAA,GAAI,GAAG,CAAC,CAAA,CAAA;AAC7C,EAAA,IAAI,SAAS,IAAM,EAAA;AACjB,IAAO,OAAA,CAAA,CAAA;AAAA,GACE,MAAA,IAAA,IAAA,KAAS,IAAQ,IAAA,IAAA,GAAO,IAAM,EAAA;AACvC,IAAO,OAAA,CAAA,CAAA;AAAA,GACF,MAAA;AACL,IAAO,OAAA,CAAA,CAAA,CAAA;AAAA,GACT;AACF,CAAA,CAAA;AAEA,MAAM,cAAA,GAAiB,CAAC,QAA2C,KAAA;AACjE,EAAI,IAAA,QAAA,CAAS,WAAW,CAAG,EAAA;AACzB,IAAA,OAAO,oBAAoB,QAAQ,CAAA,CAAA;AAAA,GACrC,MAAA,IAAW,QAAS,CAAA,MAAA,KAAW,CAAG,EAAA;AAChC,IAAA,OAAO,iBAAiB,QAAQ,CAAA,CAAA;A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AAA;AAEF,MAAM,qBACJ,CAAC,QAAA,EAAU,OAAO,oBAClB,KAAA,CAAC,IAAI,EAAO,KAAA;AACV,EAAA,KAAA,MAAW,WAAW,QAAU,EAAA;AAC9B,IAAA,MAAM,MAAS,GAAA,IAAA,CAAK,EAAI,EAAA,EAAA,EAAI,OAAO,CAAA,CAAA;AACnC,IAAA,IAAI,WAAW,CAAG,EAAA;AAChB,MAAO,OAAA,MAAA,CAAA;AAAA,KACT;AAAA,GACF;AACA,EAAO,OAAA,CAAA,CAAA;AACT,CAAA,CAAA;AAEK,MAAM,WAAW,CACtB,IAAA,EACA,EAAE,QAAA,IACF,SACG,KAAA;AACH,EAAA,MAAM,kBAAkB,QAAS,CAAA,GAAA,CAAa,CAAC,EAAE,MAAA,EAAQ,UAAe,KAAA;AAAA,IACtE,UAAU,MAAM,CAAA;AAAA,IAChB,QAAA;AAAA,GACD,CAAA,CAAA;AACD,EAAM,MAAA,UAAA,GAAa,eAAe,eAAe,CAAA,CAAA;AACjD,EAAA,OAAO,IAAK,CAAA,KAAA,EAAQ,CAAA,IAAA,CAAK,UAAU,CAAA,CAAA;AACrC;;;;"}
|
package/esm/index.js
ADDED
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { EventEmitter, KeySet, jsonToDataSourceRows, uuid, isSelected, NO_CONFIG_CHANGES, metadataKeys, vanillaConfig } from '@vuu-ui/vuu-utils';
|
|
2
|
+
|
|
3
|
+
var __accessCheck = (obj, member, msg) => {
|
|
4
|
+
if (!member.has(obj))
|
|
5
|
+
throw TypeError("Cannot " + msg);
|
|
6
|
+
};
|
|
7
|
+
var __privateGet = (obj, member, getter) => {
|
|
8
|
+
__accessCheck(obj, member, "read from private field");
|
|
9
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
10
|
+
};
|
|
11
|
+
var __privateAdd = (obj, member, value) => {
|
|
12
|
+
if (member.has(obj))
|
|
13
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
14
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
15
|
+
};
|
|
16
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
17
|
+
__accessCheck(obj, member, "write to private field");
|
|
18
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
19
|
+
return value;
|
|
20
|
+
};
|
|
21
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
22
|
+
set _(value) {
|
|
23
|
+
__privateSet(obj, member, value, setter);
|
|
24
|
+
},
|
|
25
|
+
get _() {
|
|
26
|
+
return __privateGet(obj, member, getter);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
var _aggregations, _config, _data, _filter, _groupBy, _range, _selectedRowsCount, _size, _sort, _status, _title;
|
|
30
|
+
const NULL_SCHEMA = { columns: [], key: "", table: { module: "", table: "" } };
|
|
31
|
+
const { DEPTH, IDX, IS_EXPANDED, IS_LEAF, KEY, SELECTED } = metadataKeys;
|
|
32
|
+
const toClientRow = (row, keys) => {
|
|
33
|
+
const [rowIndex] = row;
|
|
34
|
+
const clientRow = row.slice();
|
|
35
|
+
clientRow[1] = keys.keyFor(rowIndex);
|
|
36
|
+
return clientRow;
|
|
37
|
+
};
|
|
38
|
+
class JsonDataSource extends EventEmitter {
|
|
39
|
+
constructor({
|
|
40
|
+
aggregations,
|
|
41
|
+
data,
|
|
42
|
+
filter,
|
|
43
|
+
groupBy,
|
|
44
|
+
sort,
|
|
45
|
+
title,
|
|
46
|
+
viewport
|
|
47
|
+
}) {
|
|
48
|
+
super();
|
|
49
|
+
this.expandedRows = /* @__PURE__ */ new Set();
|
|
50
|
+
this.visibleRows = [];
|
|
51
|
+
__privateAdd(this, _aggregations, []);
|
|
52
|
+
__privateAdd(this, _config, vanillaConfig);
|
|
53
|
+
__privateAdd(this, _data, void 0);
|
|
54
|
+
__privateAdd(this, _filter, { filter: "" });
|
|
55
|
+
__privateAdd(this, _groupBy, []);
|
|
56
|
+
__privateAdd(this, _range, { from: 0, to: 0 });
|
|
57
|
+
__privateAdd(this, _selectedRowsCount, 0);
|
|
58
|
+
__privateAdd(this, _size, 0);
|
|
59
|
+
__privateAdd(this, _sort, { sortDefs: [] });
|
|
60
|
+
__privateAdd(this, _status, "initialising");
|
|
61
|
+
__privateAdd(this, _title, void 0);
|
|
62
|
+
this.keys = new KeySet(__privateGet(this, _range));
|
|
63
|
+
if (!data) {
|
|
64
|
+
throw Error("JsonDataSource constructor called without data");
|
|
65
|
+
}
|
|
66
|
+
[this.columnDescriptors, __privateWrapper(this, _data)._] = jsonToDataSourceRows(data);
|
|
67
|
+
this.visibleRows = __privateGet(this, _data).filter((row) => row[DEPTH] === 0).map(
|
|
68
|
+
(row, index) => [index, index].concat(row.slice(2))
|
|
69
|
+
);
|
|
70
|
+
this.viewport = viewport || uuid();
|
|
71
|
+
if (aggregations) {
|
|
72
|
+
__privateSet(this, _aggregations, aggregations);
|
|
73
|
+
}
|
|
74
|
+
if (this.columnDescriptors) {
|
|
75
|
+
__privateSet(this, _config, {
|
|
76
|
+
...__privateGet(this, _config),
|
|
77
|
+
columns: this.columnDescriptors.map((c) => c.name)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (filter) {
|
|
81
|
+
__privateSet(this, _filter, filter);
|
|
82
|
+
}
|
|
83
|
+
if (groupBy) {
|
|
84
|
+
__privateSet(this, _groupBy, groupBy);
|
|
85
|
+
}
|
|
86
|
+
if (sort) {
|
|
87
|
+
__privateSet(this, _sort, sort);
|
|
88
|
+
}
|
|
89
|
+
__privateSet(this, _title, title);
|
|
90
|
+
}
|
|
91
|
+
async subscribe({
|
|
92
|
+
viewport = this.viewport ?? uuid(),
|
|
93
|
+
columns,
|
|
94
|
+
aggregations,
|
|
95
|
+
range,
|
|
96
|
+
sort,
|
|
97
|
+
groupBy,
|
|
98
|
+
filter
|
|
99
|
+
}, callback) {
|
|
100
|
+
this.clientCallback = callback;
|
|
101
|
+
if (aggregations) {
|
|
102
|
+
__privateSet(this, _aggregations, aggregations);
|
|
103
|
+
}
|
|
104
|
+
if (columns) {
|
|
105
|
+
__privateSet(this, _config, {
|
|
106
|
+
...__privateGet(this, _config),
|
|
107
|
+
columns
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (filter) {
|
|
111
|
+
__privateSet(this, _filter, filter);
|
|
112
|
+
}
|
|
113
|
+
if (groupBy) {
|
|
114
|
+
__privateSet(this, _groupBy, groupBy);
|
|
115
|
+
}
|
|
116
|
+
if (range) {
|
|
117
|
+
__privateSet(this, _range, range);
|
|
118
|
+
}
|
|
119
|
+
if (sort) {
|
|
120
|
+
__privateSet(this, _sort, sort);
|
|
121
|
+
}
|
|
122
|
+
if (__privateGet(this, _status) !== "initialising") {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.viewport = viewport;
|
|
126
|
+
__privateSet(this, _status, "subscribed");
|
|
127
|
+
this.clientCallback?.({
|
|
128
|
+
aggregations: __privateGet(this, _aggregations),
|
|
129
|
+
type: "subscribed",
|
|
130
|
+
clientViewportId: this.viewport,
|
|
131
|
+
columns: __privateGet(this, _config).columns,
|
|
132
|
+
filter: __privateGet(this, _filter),
|
|
133
|
+
groupBy: __privateGet(this, _groupBy),
|
|
134
|
+
range: __privateGet(this, _range),
|
|
135
|
+
sort: __privateGet(this, _sort),
|
|
136
|
+
tableSchema: NULL_SCHEMA
|
|
137
|
+
});
|
|
138
|
+
this.clientCallback({
|
|
139
|
+
clientViewportId: this.viewport,
|
|
140
|
+
mode: "size-only",
|
|
141
|
+
type: "viewport-update",
|
|
142
|
+
size: this.visibleRows.length
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
unsubscribe() {
|
|
146
|
+
console.log("noop");
|
|
147
|
+
}
|
|
148
|
+
suspend() {
|
|
149
|
+
console.log("noop");
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
resume() {
|
|
153
|
+
console.log("noop");
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
disable() {
|
|
157
|
+
console.log("noop");
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
enable() {
|
|
161
|
+
console.log("noop");
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
set data(data) {
|
|
165
|
+
console.log(`set JsonDataSource data`);
|
|
166
|
+
[this.columnDescriptors, __privateWrapper(this, _data)._] = jsonToDataSourceRows(data);
|
|
167
|
+
this.visibleRows = __privateGet(this, _data).filter((row) => row[DEPTH] === 0).map(
|
|
168
|
+
(row, index) => [index, index].concat(row.slice(2))
|
|
169
|
+
);
|
|
170
|
+
requestAnimationFrame(() => {
|
|
171
|
+
this.sendRowsToClient();
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
select(selected) {
|
|
175
|
+
const updatedRows = [];
|
|
176
|
+
for (const row of __privateGet(this, _data)) {
|
|
177
|
+
const { [IDX]: rowIndex, [SELECTED]: sel } = row;
|
|
178
|
+
const wasSelected = sel === 1;
|
|
179
|
+
const nowSelected = isSelected(selected, rowIndex);
|
|
180
|
+
if (nowSelected !== wasSelected) {
|
|
181
|
+
const selectedRow = row.slice();
|
|
182
|
+
selectedRow[SELECTED] = nowSelected ? 1 : 0;
|
|
183
|
+
__privateGet(this, _data)[rowIndex] = selectedRow;
|
|
184
|
+
updatedRows.push(selectedRow);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (updatedRows.length > 0) {
|
|
188
|
+
this.clientCallback?.({
|
|
189
|
+
clientViewportId: this.viewport,
|
|
190
|
+
mode: "update",
|
|
191
|
+
type: "viewport-update",
|
|
192
|
+
rows: updatedRows
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
openTreeNode(key) {
|
|
197
|
+
this.expandedRows.add(key);
|
|
198
|
+
this.visibleRows = getVisibleRows(__privateGet(this, _data), this.expandedRows);
|
|
199
|
+
const { from, to } = __privateGet(this, _range);
|
|
200
|
+
this.clientCallback?.({
|
|
201
|
+
clientViewportId: this.viewport,
|
|
202
|
+
mode: "batch",
|
|
203
|
+
rows: this.visibleRows.slice(from, to).map((row) => toClientRow(row, this.keys)),
|
|
204
|
+
size: this.visibleRows.length,
|
|
205
|
+
type: "viewport-update"
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
closeTreeNode(key, cascade = false) {
|
|
209
|
+
this.expandedRows.delete(key);
|
|
210
|
+
if (cascade) {
|
|
211
|
+
for (const rowKey of this.expandedRows.keys()) {
|
|
212
|
+
if (rowKey.startsWith(key)) {
|
|
213
|
+
this.expandedRows.delete(rowKey);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
this.visibleRows = getVisibleRows(__privateGet(this, _data), this.expandedRows);
|
|
218
|
+
this.sendRowsToClient();
|
|
219
|
+
}
|
|
220
|
+
get status() {
|
|
221
|
+
return __privateGet(this, _status);
|
|
222
|
+
}
|
|
223
|
+
get config() {
|
|
224
|
+
return __privateGet(this, _config);
|
|
225
|
+
}
|
|
226
|
+
applyConfig() {
|
|
227
|
+
return NO_CONFIG_CHANGES;
|
|
228
|
+
}
|
|
229
|
+
get selectedRowsCount() {
|
|
230
|
+
return __privateGet(this, _selectedRowsCount);
|
|
231
|
+
}
|
|
232
|
+
get size() {
|
|
233
|
+
return __privateGet(this, _size);
|
|
234
|
+
}
|
|
235
|
+
get range() {
|
|
236
|
+
return __privateGet(this, _range);
|
|
237
|
+
}
|
|
238
|
+
set range(range) {
|
|
239
|
+
__privateSet(this, _range, range);
|
|
240
|
+
this.keys.reset(range);
|
|
241
|
+
requestAnimationFrame(() => {
|
|
242
|
+
this.sendRowsToClient();
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
sendRowsToClient() {
|
|
246
|
+
const { from, to } = __privateGet(this, _range);
|
|
247
|
+
this.clientCallback?.({
|
|
248
|
+
clientViewportId: this.viewport,
|
|
249
|
+
mode: "batch",
|
|
250
|
+
rows: this.visibleRows.slice(from, to).map((row) => toClientRow(row, this.keys)),
|
|
251
|
+
size: this.visibleRows.length,
|
|
252
|
+
type: "viewport-update"
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
get columns() {
|
|
256
|
+
return __privateGet(this, _config).columns;
|
|
257
|
+
}
|
|
258
|
+
set columns(columns) {
|
|
259
|
+
__privateSet(this, _config, {
|
|
260
|
+
...__privateGet(this, _config),
|
|
261
|
+
columns
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
get aggregations() {
|
|
265
|
+
return __privateGet(this, _aggregations);
|
|
266
|
+
}
|
|
267
|
+
set aggregations(aggregations) {
|
|
268
|
+
__privateSet(this, _aggregations, aggregations);
|
|
269
|
+
}
|
|
270
|
+
get sort() {
|
|
271
|
+
return __privateGet(this, _sort);
|
|
272
|
+
}
|
|
273
|
+
set sort(sort) {
|
|
274
|
+
__privateSet(this, _sort, sort);
|
|
275
|
+
}
|
|
276
|
+
get filter() {
|
|
277
|
+
return __privateGet(this, _filter);
|
|
278
|
+
}
|
|
279
|
+
set filter(filter) {
|
|
280
|
+
__privateSet(this, _filter, filter);
|
|
281
|
+
}
|
|
282
|
+
get groupBy() {
|
|
283
|
+
return __privateGet(this, _groupBy);
|
|
284
|
+
}
|
|
285
|
+
set groupBy(groupBy) {
|
|
286
|
+
__privateSet(this, _groupBy, groupBy);
|
|
287
|
+
}
|
|
288
|
+
get title() {
|
|
289
|
+
return __privateGet(this, _title);
|
|
290
|
+
}
|
|
291
|
+
set title(title) {
|
|
292
|
+
__privateSet(this, _title, title);
|
|
293
|
+
}
|
|
294
|
+
createLink({
|
|
295
|
+
parentVpId,
|
|
296
|
+
link: { fromColumn, toColumn }
|
|
297
|
+
}) {
|
|
298
|
+
console.log("create link", {
|
|
299
|
+
parentVpId,
|
|
300
|
+
fromColumn,
|
|
301
|
+
toColumn
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
removeLink() {
|
|
305
|
+
console.log("remove link");
|
|
306
|
+
}
|
|
307
|
+
async menuRpcCall(rpcRequest) {
|
|
308
|
+
console.log("rmenuRpcCall", {
|
|
309
|
+
rpcRequest
|
|
310
|
+
});
|
|
311
|
+
return void 0;
|
|
312
|
+
}
|
|
313
|
+
applyEdit(row, columnName, value) {
|
|
314
|
+
console.log(
|
|
315
|
+
`ArrayDataSource applyEdit ${row.join(",")} ${columnName} ${value}`
|
|
316
|
+
);
|
|
317
|
+
return Promise.resolve(true);
|
|
318
|
+
}
|
|
319
|
+
getChildRows(rowKey) {
|
|
320
|
+
const parentRow = __privateGet(this, _data).find((row) => row[KEY] === rowKey);
|
|
321
|
+
if (parentRow) {
|
|
322
|
+
const { [IDX]: parentIdx, [DEPTH]: parentDepth } = parentRow;
|
|
323
|
+
let rowIdx = parentIdx + 1;
|
|
324
|
+
const childRows = [];
|
|
325
|
+
do {
|
|
326
|
+
const { [DEPTH]: depth } = __privateGet(this, _data)[rowIdx];
|
|
327
|
+
if (depth === parentDepth + 1) {
|
|
328
|
+
childRows.push(__privateGet(this, _data)[rowIdx]);
|
|
329
|
+
} else if (depth <= parentDepth) {
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
rowIdx += 1;
|
|
333
|
+
} while (rowIdx < __privateGet(this, _data).length);
|
|
334
|
+
return childRows;
|
|
335
|
+
} else {
|
|
336
|
+
console.warn(
|
|
337
|
+
`JsonDataSource getChildRows row not found for key ${rowKey}`
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
return [];
|
|
341
|
+
}
|
|
342
|
+
getRowsAtDepth(depth, visibleOnly = true) {
|
|
343
|
+
const rows = visibleOnly ? this.visibleRows : __privateGet(this, _data);
|
|
344
|
+
return rows.filter((row) => row[DEPTH] === depth);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
_aggregations = new WeakMap();
|
|
348
|
+
_config = new WeakMap();
|
|
349
|
+
_data = new WeakMap();
|
|
350
|
+
_filter = new WeakMap();
|
|
351
|
+
_groupBy = new WeakMap();
|
|
352
|
+
_range = new WeakMap();
|
|
353
|
+
_selectedRowsCount = new WeakMap();
|
|
354
|
+
_size = new WeakMap();
|
|
355
|
+
_sort = new WeakMap();
|
|
356
|
+
_status = new WeakMap();
|
|
357
|
+
_title = new WeakMap();
|
|
358
|
+
function getVisibleRows(rows, expandedKeys) {
|
|
359
|
+
const visibleRows = [];
|
|
360
|
+
const index = { value: 0 };
|
|
361
|
+
for (let i = 0; i < rows.length; i++) {
|
|
362
|
+
const row = rows[i];
|
|
363
|
+
const { [DEPTH]: depth, [KEY]: key, [IS_LEAF]: isLeaf } = row;
|
|
364
|
+
const isExpanded = expandedKeys.has(key);
|
|
365
|
+
visibleRows.push(cloneRow(row, index, isExpanded));
|
|
366
|
+
if (!isLeaf && !isExpanded) {
|
|
367
|
+
do {
|
|
368
|
+
i += 1;
|
|
369
|
+
} while (i < rows.length - 1 && rows[i + 1][DEPTH] > depth);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return visibleRows;
|
|
373
|
+
}
|
|
374
|
+
const cloneRow = (row, index, isExpanded) => {
|
|
375
|
+
const dolly = row.slice();
|
|
376
|
+
dolly[0] = index.value;
|
|
377
|
+
dolly[1] = index.value;
|
|
378
|
+
if (isExpanded) {
|
|
379
|
+
dolly[IS_EXPANDED] = true;
|
|
380
|
+
}
|
|
381
|
+
index.value += 1;
|
|
382
|
+
return dolly;
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
export { JsonDataSource };
|
|
386
|
+
//# sourceMappingURL=json-data-source.js.map
|