schummar-table 0.3.2 → 0.5.0-beta-1
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/assets/tableTheme.0eb513b0.js +215 -0
- package/dist/assets/tableTheme.0eb513b0.js.map +1 -0
- package/dist/assets/tableTheme.65fea986.js +214 -0
- package/dist/assets/tableTheme.65fea986.js.map +1 -0
- package/dist/assets/vendor.a5ec605d.js +2475 -0
- package/dist/assets/vendor.a5ec605d.js.map +1 -0
- package/dist/assets/vendor.c9c3328b.js +2464 -0
- package/dist/assets/vendor.c9c3328b.js.map +1 -0
- package/dist/cjs/mui4Theme.js +7 -0
- package/dist/cjs/mui4Theme.js.map +1 -0
- package/dist/cjs/mui5Theme.js +7 -0
- package/dist/cjs/mui5Theme.js.map +1 -0
- package/dist/cjs/schummar-table.js +1042 -0
- package/dist/cjs/schummar-table.js.map +1 -0
- package/dist/esm/mui4Theme.js +6 -0
- package/dist/esm/mui4Theme.js.map +1 -0
- package/dist/esm/mui5Theme.js +6 -0
- package/dist/esm/mui5Theme.js.map +1 -0
- package/dist/esm/schummar-table.js +1041 -0
- package/dist/esm/schummar-table.js.map +1 -0
- package/dist/{cjs → types}/components/cell.d.ts +1 -1
- package/dist/types/components/columnHeader.d.ts +7 -0
- package/dist/{cjs → types}/components/columnSelection.d.ts +0 -0
- package/dist/types/components/dateFilter.d.ts +8 -0
- package/dist/types/components/datePicker.d.ts +16 -0
- package/dist/types/components/expandControl.d.ts +6 -0
- package/dist/{cjs → types}/components/export.d.ts +0 -0
- package/dist/types/components/filterControl.d.ts +2 -0
- package/dist/types/components/formControlLabel.d.ts +5 -0
- package/dist/types/components/resizeHandle.d.ts +1 -0
- package/dist/{cjs → types}/components/row.d.ts +1 -1
- package/dist/{cjs → types}/components/selectComponent.d.ts +0 -0
- package/dist/types/components/selectFilter.d.ts +8 -0
- package/dist/{cjs → types}/components/sortComponent.d.ts +0 -0
- package/dist/types/components/spinnner.d.ts +3 -0
- package/dist/{cjs → types/components}/table.d.ts +1 -1
- package/dist/types/components/textFilter.d.ts +5 -0
- package/dist/{cjs → types}/components/virtualized.d.ts +0 -0
- package/dist/types/hooks/useFilter.d.ts +5 -0
- package/dist/types/hooks/useTheme.d.ts +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/{cjs → types}/internalState/calcItems.d.ts +0 -0
- package/dist/{cjs → types}/internalState/calcProps.d.ts +0 -0
- package/dist/{cjs → types}/internalState/cleanupState.d.ts +0 -0
- package/dist/{cjs → types}/internalState/filterColumns.d.ts +0 -0
- package/dist/{cjs → types}/internalState/syncSelections.d.ts +0 -0
- package/dist/types/internalState/tableStateStorage.d.ts +11 -0
- package/dist/{cjs → types}/internalState/useTableState.d.ts +0 -0
- package/dist/{cjs → types}/misc/csvExport.d.ts +0 -0
- package/dist/types/misc/debounce.d.ts +4 -0
- package/dist/types/misc/deepPartial.d.ts +3 -0
- package/dist/{cjs → types}/misc/helpers.d.ts +2 -1
- package/dist/types/misc/queue.d.ts +6 -0
- package/dist/{cjs → types}/misc/textMatch.d.ts +0 -0
- package/dist/types/misc/throttle.d.ts +4 -0
- package/dist/types/theme/defaultClasses.d.ts +15 -0
- package/dist/types/theme/defaultColors.d.ts +2 -0
- package/dist/types/theme/defaultIcons.d.ts +2 -0
- package/dist/types/theme/defaultTexts.d.ts +2 -0
- package/dist/types/theme/defaultTheme/badge.d.ts +2 -0
- package/dist/types/theme/defaultTheme/button.d.ts +2 -0
- package/dist/types/theme/defaultTheme/checkbox.d.ts +2 -0
- package/dist/types/theme/defaultTheme/iconButton.d.ts +2 -0
- package/dist/types/theme/defaultTheme/index.d.ts +2 -0
- package/dist/types/theme/defaultTheme/popover.d.ts +4 -0
- package/dist/types/theme/defaultTheme/textField.d.ts +2 -0
- package/dist/types/theme/mui4Theme/index.d.ts +8 -0
- package/dist/types/theme/mui5Theme/index.d.ts +8 -0
- package/dist/types/theme/tableTheme.d.ts +11 -0
- package/dist/types/theme/useCssVariables.d.ts +9 -0
- package/dist/types/types.d.ts +285 -0
- package/package.json +78 -38
- package/dist/cjs/components/cell.js +0 -31
- package/dist/cjs/components/columnSelection.js +0 -37
- package/dist/cjs/components/defaultFilterComponent.d.ts +0 -22
- package/dist/cjs/components/defaultFilterComponent.js +0 -91
- package/dist/cjs/components/expandComponent.d.ts +0 -5
- package/dist/cjs/components/expandComponent.js +0 -38
- package/dist/cjs/components/export.js +0 -48
- package/dist/cjs/components/filterComponent.d.ts +0 -5
- package/dist/cjs/components/filterComponent.js +0 -25
- package/dist/cjs/components/row.js +0 -48
- package/dist/cjs/components/selectComponent.js +0 -61
- package/dist/cjs/components/sortComponent.js +0 -52
- package/dist/cjs/components/textFilterComponent.d.ts +0 -11
- package/dist/cjs/components/textFilterComponent.js +0 -70
- package/dist/cjs/components/useCommonClasses.d.ts +0 -1
- package/dist/cjs/components/useCommonClasses.js +0 -49
- package/dist/cjs/components/virtualized.js +0 -98
- package/dist/cjs/index.d.ts +0 -6
- package/dist/cjs/index.js +0 -18
- package/dist/cjs/internalState/calcItems.js +0 -85
- package/dist/cjs/internalState/calcProps.js +0 -89
- package/dist/cjs/internalState/cleanupState.js +0 -43
- package/dist/cjs/internalState/filterColumns.js +0 -10
- package/dist/cjs/internalState/syncSelections.js +0 -22
- package/dist/cjs/internalState/useTableState.js +0 -62
- package/dist/cjs/misc/csvExport.js +0 -15
- package/dist/cjs/misc/helpers.js +0 -91
- package/dist/cjs/misc/textMatch.js +0 -23
- package/dist/cjs/misc/throttle.d.ts +0 -1
- package/dist/cjs/misc/throttle.js +0 -30
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/table.js +0 -69
- package/dist/cjs/types.d.ts +0 -134
- package/dist/cjs/types.js +0 -2
- package/dist/esm/components/cell.d.ts +0 -6
- package/dist/esm/components/cell.js +0 -28
- package/dist/esm/components/columnSelection.d.ts +0 -2
- package/dist/esm/components/columnSelection.js +0 -33
- package/dist/esm/components/defaultFilterComponent.d.ts +0 -22
- package/dist/esm/components/defaultFilterComponent.js +0 -86
- package/dist/esm/components/expandComponent.d.ts +0 -5
- package/dist/esm/components/expandComponent.js +0 -34
- package/dist/esm/components/export.d.ts +0 -2
- package/dist/esm/components/export.js +0 -44
- package/dist/esm/components/filterComponent.d.ts +0 -5
- package/dist/esm/components/filterComponent.js +0 -21
- package/dist/esm/components/row.d.ts +0 -7
- package/dist/esm/components/row.js +0 -44
- package/dist/esm/components/selectComponent.d.ts +0 -5
- package/dist/esm/components/selectComponent.js +0 -57
- package/dist/esm/components/sortComponent.d.ts +0 -4
- package/dist/esm/components/sortComponent.js +0 -48
- package/dist/esm/components/textFilterComponent.d.ts +0 -11
- package/dist/esm/components/textFilterComponent.js +0 -65
- package/dist/esm/components/useCommonClasses.d.ts +0 -1
- package/dist/esm/components/useCommonClasses.js +0 -46
- package/dist/esm/components/virtualized.d.ts +0 -6
- package/dist/esm/components/virtualized.js +0 -94
- package/dist/esm/index.d.ts +0 -6
- package/dist/esm/index.js +0 -4
- package/dist/esm/internalState/calcItems.d.ts +0 -3
- package/dist/esm/internalState/calcItems.js +0 -81
- package/dist/esm/internalState/calcProps.d.ts +0 -2
- package/dist/esm/internalState/calcProps.js +0 -85
- package/dist/esm/internalState/cleanupState.d.ts +0 -3
- package/dist/esm/internalState/cleanupState.js +0 -39
- package/dist/esm/internalState/filterColumns.d.ts +0 -3
- package/dist/esm/internalState/filterColumns.js +0 -6
- package/dist/esm/internalState/syncSelections.d.ts +0 -3
- package/dist/esm/internalState/syncSelections.js +0 -18
- package/dist/esm/internalState/useTableState.d.ts +0 -3
- package/dist/esm/internalState/useTableState.js +0 -58
- package/dist/esm/misc/csvExport.d.ts +0 -7
- package/dist/esm/misc/csvExport.js +0 -11
- package/dist/esm/misc/helpers.d.ts +0 -14
- package/dist/esm/misc/helpers.js +0 -77
- package/dist/esm/misc/textMatch.d.ts +0 -2
- package/dist/esm/misc/textMatch.js +0 -18
- package/dist/esm/misc/throttle.d.ts +0 -1
- package/dist/esm/misc/throttle.js +0 -26
- package/dist/esm/table.d.ts +0 -8
- package/dist/esm/table.js +0 -63
- package/dist/esm/types.d.ts +0 -134
- package/dist/esm/types.js +0 -1
|
@@ -0,0 +1,1042 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
var require$$0 = require("react");
|
|
34
|
+
var vendor = require("../assets/vendor.a5ec605d.js");
|
|
35
|
+
var tableTheme = require("../assets/tableTheme.0eb513b0.js");
|
|
36
|
+
require("react-dom");
|
|
37
|
+
function useCssVariables() {
|
|
38
|
+
const table = useTableContext();
|
|
39
|
+
return table.useState((state) => ({
|
|
40
|
+
"--spacing": state.theme.spacing,
|
|
41
|
+
"--primaryMain": state.theme.colors.primary.main,
|
|
42
|
+
"--primaryLight": state.theme.colors.primary.light,
|
|
43
|
+
"--primaryContrastText": state.theme.colors.primary.contrastText,
|
|
44
|
+
"--secondaryMain": state.theme.colors.secondary.main,
|
|
45
|
+
"--secondaryLight": state.theme.colors.secondary.light,
|
|
46
|
+
"--secondaryContrastText": state.theme.colors.secondary.contrastText
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
const getAncestors = (activeItemsById, ...items) => {
|
|
50
|
+
const result = /* @__PURE__ */ new Set();
|
|
51
|
+
const find = ({ parentId }) => {
|
|
52
|
+
const parent = parentId ? activeItemsById.get(parentId) : void 0;
|
|
53
|
+
if (parent && !result.has(parent.id)) {
|
|
54
|
+
result.add(parent.id);
|
|
55
|
+
find(parent);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
items.forEach(find);
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
const getDescendants = (...items) => {
|
|
62
|
+
const result = /* @__PURE__ */ new Set();
|
|
63
|
+
const find = (item) => {
|
|
64
|
+
for (const child of item.children) {
|
|
65
|
+
if (!result.has(child.id)) {
|
|
66
|
+
result.add(child.id);
|
|
67
|
+
find(child);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
items.forEach(find);
|
|
72
|
+
return result;
|
|
73
|
+
};
|
|
74
|
+
function FormControlLabel({
|
|
75
|
+
control,
|
|
76
|
+
label
|
|
77
|
+
}) {
|
|
78
|
+
return vendor.jsxs("label", {
|
|
79
|
+
css: {
|
|
80
|
+
display: "flex",
|
|
81
|
+
alignItems: "center",
|
|
82
|
+
cursor: "pointer",
|
|
83
|
+
userSelect: "none",
|
|
84
|
+
"& > *": {
|
|
85
|
+
cursor: "pointer"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
children: [control, vendor.jsx("span", {
|
|
89
|
+
css: {
|
|
90
|
+
marginLeft: "var(--spacing)"
|
|
91
|
+
},
|
|
92
|
+
children: label
|
|
93
|
+
})]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const ColumnHeaderContext = new vendor.StoreScope({
|
|
97
|
+
items: /* @__PURE__ */ new Map()
|
|
98
|
+
});
|
|
99
|
+
function ColumnHeader(props) {
|
|
100
|
+
const ref = require$$0.useRef(null);
|
|
101
|
+
const columnId = useColumnContext();
|
|
102
|
+
const table = useTableContext();
|
|
103
|
+
const enabled = table.useState("props.enableColumnReorder");
|
|
104
|
+
const store = ColumnHeaderContext.useStore();
|
|
105
|
+
const draggingStart = require$$0.useRef();
|
|
106
|
+
const clone = require$$0.useRef();
|
|
107
|
+
require$$0.useEffect(() => {
|
|
108
|
+
const div = ref.current;
|
|
109
|
+
if (!div)
|
|
110
|
+
return;
|
|
111
|
+
store.update((state) => {
|
|
112
|
+
state.items.set(columnId, vendor.K(div));
|
|
113
|
+
});
|
|
114
|
+
return () => {
|
|
115
|
+
store.update((state) => {
|
|
116
|
+
state.items.delete(columnId);
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
}, [ref.current, store, columnId]);
|
|
120
|
+
function calcTargetIndex(offsetLeft) {
|
|
121
|
+
var _a, _b, _c;
|
|
122
|
+
const cols = table.getState().columnOrder.map((id) => ({
|
|
123
|
+
id,
|
|
124
|
+
div: store.getState().items.get(id)
|
|
125
|
+
}));
|
|
126
|
+
const otherCols = cols.filter((col) => col.id !== columnId);
|
|
127
|
+
const firstOffsetleft = (_c = (_b = (_a = cols.find((col) => col.div)) == null ? void 0 : _a.div) == null ? void 0 : _b.offsetLeft) != null ? _c : 0;
|
|
128
|
+
let sum = 0;
|
|
129
|
+
const targetIndex = otherCols.findIndex((col) => {
|
|
130
|
+
var _a2, _b2;
|
|
131
|
+
const width = (_b2 = (_a2 = col.div) == null ? void 0 : _a2.offsetWidth) != null ? _b2 : 0;
|
|
132
|
+
if (sum + width / 2 > offsetLeft - firstOffsetleft)
|
|
133
|
+
return true;
|
|
134
|
+
sum += width;
|
|
135
|
+
return false;
|
|
136
|
+
});
|
|
137
|
+
return targetIndex === -1 ? otherCols.length : targetIndex;
|
|
138
|
+
}
|
|
139
|
+
function onPointerDown(e) {
|
|
140
|
+
const div = ref.current;
|
|
141
|
+
if (!div)
|
|
142
|
+
return;
|
|
143
|
+
draggingStart.current = {
|
|
144
|
+
mouseX: e.clientX,
|
|
145
|
+
bounds: div.getBoundingClientRect()
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function onPointerMove(e) {
|
|
149
|
+
table.update((state) => {
|
|
150
|
+
const div = ref.current;
|
|
151
|
+
if (!div || draggingStart.current === void 0 || Math.abs(e.clientX - draggingStart.current.mouseX) < 5)
|
|
152
|
+
return;
|
|
153
|
+
e.stopPropagation();
|
|
154
|
+
div.setPointerCapture(e.pointerId);
|
|
155
|
+
if (!clone.current) {
|
|
156
|
+
clone.current = div.cloneNode(true);
|
|
157
|
+
document.body.append(clone.current);
|
|
158
|
+
for (const [key, value] of Object.entries(getComputedStyle(div))) {
|
|
159
|
+
try {
|
|
160
|
+
clone.current.style[key] = value;
|
|
161
|
+
} catch {
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
Object.assign(clone.current.style, {
|
|
165
|
+
pointerEvents: "none",
|
|
166
|
+
position: "fixed",
|
|
167
|
+
boxShadow: "0px 5px 5px -3px rgb(0 0 0 / 20%), 0px 8px 10px 1px rgb(0 0 0 / 14%), 0px 3px 14px 2px rgb(0 0 0 / 12%)",
|
|
168
|
+
left: `${draggingStart.current.bounds.left}px`,
|
|
169
|
+
top: `${draggingStart.current.bounds.top}px`
|
|
170
|
+
});
|
|
171
|
+
div.style.color = "rgba(0, 0, 0, 0.2)";
|
|
172
|
+
}
|
|
173
|
+
clone.current.style.left = `${draggingStart.current.bounds.left + e.clientX - draggingStart.current.mouseX}px`;
|
|
174
|
+
const index = state.columnOrder.indexOf(columnId);
|
|
175
|
+
const targetIndex = calcTargetIndex(div.offsetLeft + e.clientX - draggingStart.current.mouseX);
|
|
176
|
+
const columns = table.getState().columnOrder.map((id, index2) => {
|
|
177
|
+
var _a, _b;
|
|
178
|
+
return {
|
|
179
|
+
id,
|
|
180
|
+
index: index2,
|
|
181
|
+
width: (_b = (_a = store.getState().items.get(id)) == null ? void 0 : _a.offsetWidth) != null ? _b : 0
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
state.columnOrder.forEach((id, i) => {
|
|
185
|
+
let offset = 0;
|
|
186
|
+
if (i === index) {
|
|
187
|
+
if (targetIndex > index) {
|
|
188
|
+
offset = columns.slice(index + 1, targetIndex + 1).reduce((sum, col) => sum + col.width, 0);
|
|
189
|
+
} else if (targetIndex < index) {
|
|
190
|
+
offset = -columns.slice(targetIndex, index).reduce((sum, col) => sum + col.width, 0);
|
|
191
|
+
}
|
|
192
|
+
} else if (i >= targetIndex && i < index) {
|
|
193
|
+
offset = div.offsetWidth;
|
|
194
|
+
} else if (i > index && i <= targetIndex) {
|
|
195
|
+
offset = -div.offsetWidth;
|
|
196
|
+
}
|
|
197
|
+
state.columnStyleOverride.set(id, {
|
|
198
|
+
transition: "transform 500ms",
|
|
199
|
+
transform: `translate3d(${offset}px, 0, 0)`,
|
|
200
|
+
zIndex: i === index ? 1 : void 0
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function onPointerUp(e) {
|
|
206
|
+
table.update((state) => {
|
|
207
|
+
var _a;
|
|
208
|
+
const div = ref.current;
|
|
209
|
+
if (!div || draggingStart.current === void 0)
|
|
210
|
+
return;
|
|
211
|
+
const index = state.columnOrder.indexOf(columnId);
|
|
212
|
+
const targetIndex = calcTargetIndex(div.offsetLeft + e.clientX - draggingStart.current.mouseX);
|
|
213
|
+
state.columnOrder.splice(index, 1);
|
|
214
|
+
state.columnOrder.splice(targetIndex, 0, columnId);
|
|
215
|
+
(_a = clone.current) == null ? void 0 : _a.remove();
|
|
216
|
+
div.style.color = "";
|
|
217
|
+
state.columnStyleOverride.clear();
|
|
218
|
+
draggingStart.current = void 0;
|
|
219
|
+
clone.current = void 0;
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
return vendor.jsx("div", __spreadProps(__spreadValues({}, props), {
|
|
223
|
+
css: {
|
|
224
|
+
position: "relative",
|
|
225
|
+
userSelect: "none"
|
|
226
|
+
},
|
|
227
|
+
ref,
|
|
228
|
+
onPointerDown: enabled ? onPointerDown : void 0,
|
|
229
|
+
onPointerMove: enabled ? onPointerMove : void 0,
|
|
230
|
+
onPointerUp: enabled ? onPointerUp : void 0,
|
|
231
|
+
children: props.children
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
function ColumnSelection() {
|
|
235
|
+
const {
|
|
236
|
+
components: {
|
|
237
|
+
IconButton,
|
|
238
|
+
Popover,
|
|
239
|
+
Checkbox
|
|
240
|
+
},
|
|
241
|
+
icons: {
|
|
242
|
+
Settings
|
|
243
|
+
},
|
|
244
|
+
text
|
|
245
|
+
} = useTheme();
|
|
246
|
+
const cssVariables = useCssVariables();
|
|
247
|
+
const table = useTableContext();
|
|
248
|
+
const columns = table.useState("props.columns");
|
|
249
|
+
const hiddenColumns = table.useState("hiddenColumns");
|
|
250
|
+
const [anchorEl, setAnchorEl] = require$$0.useState(null);
|
|
251
|
+
const toggle = (column) => {
|
|
252
|
+
const {
|
|
253
|
+
props: {
|
|
254
|
+
hiddenColumns: controlledHiddenColumns,
|
|
255
|
+
onHiddenColumnsChange
|
|
256
|
+
}
|
|
257
|
+
} = table.getState();
|
|
258
|
+
const newValue = new Set(hiddenColumns);
|
|
259
|
+
if (hiddenColumns.has(column.id))
|
|
260
|
+
newValue.delete(column.id);
|
|
261
|
+
else
|
|
262
|
+
newValue.add(column.id);
|
|
263
|
+
if (!controlledHiddenColumns) {
|
|
264
|
+
table.update((state) => {
|
|
265
|
+
state.hiddenColumns = newValue;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
onHiddenColumnsChange == null ? void 0 : onHiddenColumnsChange(newValue);
|
|
269
|
+
};
|
|
270
|
+
return vendor.jsxs(vendor.Fragment, {
|
|
271
|
+
children: [vendor.jsx(IconButton, {
|
|
272
|
+
onClick: (e) => setAnchorEl(anchorEl ? null : e.currentTarget),
|
|
273
|
+
children: vendor.jsx(Settings, {})
|
|
274
|
+
}), vendor.jsx(Popover, {
|
|
275
|
+
anchorEl,
|
|
276
|
+
open: !!anchorEl,
|
|
277
|
+
onClose: () => setAnchorEl(null),
|
|
278
|
+
css: cssVariables,
|
|
279
|
+
children: vendor.jsxs("div", {
|
|
280
|
+
css: {
|
|
281
|
+
padding: `calc(var(--spacing) * 2)`,
|
|
282
|
+
display: "grid"
|
|
283
|
+
},
|
|
284
|
+
children: [vendor.jsx("div", {
|
|
285
|
+
css: {
|
|
286
|
+
marginBottom: "var(--spacing)"
|
|
287
|
+
},
|
|
288
|
+
children: text.selectColumns
|
|
289
|
+
}), columns.map((column) => vendor.jsx(FormControlLabel, {
|
|
290
|
+
control: vendor.jsx(Checkbox, {
|
|
291
|
+
checked: !hiddenColumns.has(column.id),
|
|
292
|
+
onChange: () => toggle(column),
|
|
293
|
+
disabled: column.cannotHide
|
|
294
|
+
}),
|
|
295
|
+
label: column.header
|
|
296
|
+
}, column.id))]
|
|
297
|
+
})
|
|
298
|
+
})]
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function csvExport(data, { sepPrefix, separator = ",", quote = '"', eol = "\n" } = {}) {
|
|
302
|
+
const cells = data.map((line) => line.map((value) => {
|
|
303
|
+
if (typeof value === "number")
|
|
304
|
+
return String(value);
|
|
305
|
+
if (![separator, quote, eol].some((c) => value.includes(c)))
|
|
306
|
+
return value;
|
|
307
|
+
const clean = value.replace(new RegExp(quote, "g"), `${quote}${quote}`);
|
|
308
|
+
return `${quote}${clean}${quote}`;
|
|
309
|
+
}));
|
|
310
|
+
return (sepPrefix ? `SEP=${separator}
|
|
311
|
+
` : "") + cells.map((line) => line.join(separator)).join(eol);
|
|
312
|
+
}
|
|
313
|
+
function Export() {
|
|
314
|
+
const table = useTableContext();
|
|
315
|
+
const {
|
|
316
|
+
components: {
|
|
317
|
+
Button,
|
|
318
|
+
IconButton,
|
|
319
|
+
Popover
|
|
320
|
+
},
|
|
321
|
+
icons: {
|
|
322
|
+
Export: Export2,
|
|
323
|
+
Clipboard
|
|
324
|
+
},
|
|
325
|
+
text
|
|
326
|
+
} = useTheme();
|
|
327
|
+
const cssVariables = useCssVariables();
|
|
328
|
+
const [anchor, setAnchor] = require$$0.useState(null);
|
|
329
|
+
const generate = (options) => {
|
|
330
|
+
const {
|
|
331
|
+
activeColumns,
|
|
332
|
+
activeItems
|
|
333
|
+
} = table.getState();
|
|
334
|
+
const data = [activeColumns.map((column) => String(column.id)), ...activeItems.map((item) => activeColumns.map((column) => column.exportCell(column.value(item), item)))];
|
|
335
|
+
return csvExport(data, options);
|
|
336
|
+
};
|
|
337
|
+
const copy = () => {
|
|
338
|
+
navigator.clipboard.writeText(generate(table.getState().props.enableExport.copy));
|
|
339
|
+
};
|
|
340
|
+
const download = () => {
|
|
341
|
+
const a = document.createElement("a");
|
|
342
|
+
a.href = "data:text/csv;charset=utf-8," + encodeURIComponent(generate(table.getState().props.enableExport.download));
|
|
343
|
+
a.download = "export.csv";
|
|
344
|
+
document.body.appendChild(a);
|
|
345
|
+
a.click();
|
|
346
|
+
document.body.removeChild(a);
|
|
347
|
+
};
|
|
348
|
+
return vendor.jsxs(vendor.Fragment, {
|
|
349
|
+
children: [vendor.jsx(IconButton, {
|
|
350
|
+
onClick: (e) => setAnchor(anchor ? null : e.currentTarget),
|
|
351
|
+
children: vendor.jsx(Export2, {})
|
|
352
|
+
}), vendor.jsx(Popover, {
|
|
353
|
+
open: !!anchor,
|
|
354
|
+
onClose: () => setAnchor(null),
|
|
355
|
+
anchorEl: anchor,
|
|
356
|
+
css: cssVariables,
|
|
357
|
+
children: vendor.jsxs("div", {
|
|
358
|
+
css: {
|
|
359
|
+
padding: `calc(var(--spacing) * 2)`,
|
|
360
|
+
display: "grid",
|
|
361
|
+
justifyItems: "stretch",
|
|
362
|
+
gap: "var(--spacing)",
|
|
363
|
+
"& > *": {
|
|
364
|
+
justifyContent: "start"
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
children: [vendor.jsx("div", {
|
|
368
|
+
css: {
|
|
369
|
+
marginBottom: "var(--spacing)"
|
|
370
|
+
},
|
|
371
|
+
children: text.exportTitle
|
|
372
|
+
}), vendor.jsx(Button, {
|
|
373
|
+
startIcon: vendor.jsx(Clipboard, {}),
|
|
374
|
+
onClick: copy,
|
|
375
|
+
children: text.exportCopy
|
|
376
|
+
}), vendor.jsx(Button, {
|
|
377
|
+
startIcon: vendor.jsx(Export2, {}),
|
|
378
|
+
onClick: download,
|
|
379
|
+
children: text.exportDownload
|
|
380
|
+
})]
|
|
381
|
+
})
|
|
382
|
+
})]
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
function useTheme() {
|
|
386
|
+
const table = useTableContext();
|
|
387
|
+
return table.useState("theme");
|
|
388
|
+
}
|
|
389
|
+
function FilterControl() {
|
|
390
|
+
const table = useTableContext();
|
|
391
|
+
const columnId = useColumnContext();
|
|
392
|
+
const {
|
|
393
|
+
components: {
|
|
394
|
+
IconButton,
|
|
395
|
+
Popover
|
|
396
|
+
},
|
|
397
|
+
icons: {
|
|
398
|
+
FilterList,
|
|
399
|
+
ArrowDropDown
|
|
400
|
+
}
|
|
401
|
+
} = useTheme();
|
|
402
|
+
const cssVariables = useCssVariables();
|
|
403
|
+
const [anchor, setAnchor] = require$$0.useState(null);
|
|
404
|
+
const isActive = table.useState((state) => {
|
|
405
|
+
const filter2 = state.filters.get(columnId);
|
|
406
|
+
const filterValue = state.filterValues.get(columnId);
|
|
407
|
+
return filter2 !== void 0 && filterValue !== void 0 && filter2.isActive(filterValue);
|
|
408
|
+
});
|
|
409
|
+
const filter = table.useState((state) => {
|
|
410
|
+
var _a;
|
|
411
|
+
return (_a = state.activeColumns.find((column) => column.id === columnId)) == null ? void 0 : _a.filter;
|
|
412
|
+
});
|
|
413
|
+
if (!filter)
|
|
414
|
+
return null;
|
|
415
|
+
return vendor.jsxs(vendor.Fragment, {
|
|
416
|
+
children: [vendor.jsx(IconButton, {
|
|
417
|
+
onClick: (e) => setAnchor(e.currentTarget),
|
|
418
|
+
css: [isActive && {
|
|
419
|
+
color: "white !important",
|
|
420
|
+
backgroundColor: "var(--primaryMain) !important"
|
|
421
|
+
}],
|
|
422
|
+
children: isActive ? vendor.jsx(FilterList, {}) : vendor.jsx(ArrowDropDown, {})
|
|
423
|
+
}), vendor.jsx("div", {
|
|
424
|
+
onPointerDown: (e) => {
|
|
425
|
+
e.stopPropagation();
|
|
426
|
+
},
|
|
427
|
+
onPointerMove: (e) => {
|
|
428
|
+
e.stopPropagation();
|
|
429
|
+
},
|
|
430
|
+
children: vendor.jsx(Popover, {
|
|
431
|
+
open: true,
|
|
432
|
+
hidden: !anchor,
|
|
433
|
+
onClose: () => setAnchor(null),
|
|
434
|
+
anchorEl: anchor != null ? anchor : document.body,
|
|
435
|
+
css: cssVariables,
|
|
436
|
+
children: filter
|
|
437
|
+
})
|
|
438
|
+
})]
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
function ResizeHandle() {
|
|
442
|
+
const table = useTableContext();
|
|
443
|
+
const columnId = useColumnContext();
|
|
444
|
+
const enabled = table.useState("props.enableColumnResize");
|
|
445
|
+
function onPointerDown(e) {
|
|
446
|
+
e.stopPropagation();
|
|
447
|
+
const div = e.target;
|
|
448
|
+
div.setPointerCapture(e.pointerId);
|
|
449
|
+
}
|
|
450
|
+
function onPointerMove(e) {
|
|
451
|
+
e.stopPropagation();
|
|
452
|
+
const div = e.target;
|
|
453
|
+
if (!div.hasPointerCapture(e.pointerId))
|
|
454
|
+
return;
|
|
455
|
+
const parent = div.parentElement;
|
|
456
|
+
const width = Math.max(e.clientX - parent.getBoundingClientRect().left + 5, 50);
|
|
457
|
+
table.update((state) => {
|
|
458
|
+
state.columnWidths.set(columnId, `${width}px`);
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
function onPointerUp(e) {
|
|
462
|
+
e.stopPropagation();
|
|
463
|
+
const div = e.target;
|
|
464
|
+
div.releasePointerCapture(e.pointerId);
|
|
465
|
+
}
|
|
466
|
+
function onDoubleClick(e) {
|
|
467
|
+
table.update((state) => {
|
|
468
|
+
if (e.getModifierState("Control")) {
|
|
469
|
+
state.columnWidths.delete(columnId);
|
|
470
|
+
} else {
|
|
471
|
+
state.columnWidths.set(columnId, "max-content");
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
return vendor.jsx("div", {
|
|
476
|
+
css: {
|
|
477
|
+
alignSelf: "stretch",
|
|
478
|
+
padding: "0 5px",
|
|
479
|
+
cursor: enabled ? "col-resize" : "initial",
|
|
480
|
+
display: "flex",
|
|
481
|
+
alignItems: "center",
|
|
482
|
+
"&:after": {
|
|
483
|
+
content: '""',
|
|
484
|
+
width: 1,
|
|
485
|
+
height: "1.2em",
|
|
486
|
+
background: "currentColor",
|
|
487
|
+
transition: "transform 300ms"
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
onPointerDown: enabled ? onPointerDown : void 0,
|
|
491
|
+
onPointerMove: enabled ? onPointerMove : void 0,
|
|
492
|
+
onPointerUp: enabled ? onPointerUp : void 0,
|
|
493
|
+
onDoubleClick: enabled ? onDoubleClick : void 0
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
const Cell = require$$0.memo(function Cell2({
|
|
497
|
+
itemId,
|
|
498
|
+
rowIndex
|
|
499
|
+
}) {
|
|
500
|
+
var _a, _b;
|
|
501
|
+
const table = useTableContext();
|
|
502
|
+
const columnId = useColumnContext();
|
|
503
|
+
const {
|
|
504
|
+
css
|
|
505
|
+
} = useTheme();
|
|
506
|
+
const column = table.useState((state) => state.activeColumns.find((column2) => column2.id === columnId));
|
|
507
|
+
const item = table.useState((state) => state.activeItemsById.get(itemId));
|
|
508
|
+
const columnStyleOverride = table.useState((state) => state.columnStyleOverride.get(columnId), {
|
|
509
|
+
throttle: 16
|
|
510
|
+
});
|
|
511
|
+
if (!column || !item)
|
|
512
|
+
return null;
|
|
513
|
+
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render cell", itemId, columnId);
|
|
514
|
+
const classNames = [...calcClassNames(css, item, rowIndex), ...calcClassNames(column == null ? void 0 : column.css, item, rowIndex)];
|
|
515
|
+
const content = column.renderCell(column.value(item), item);
|
|
516
|
+
return vendor.jsx("div", {
|
|
517
|
+
css: [tableTheme.defaultClasses.cell, classNames, columnStyleOverride],
|
|
518
|
+
children: typeof content === "string" ? vendor.jsx("span", {
|
|
519
|
+
css: tableTheme.defaultClasses.text,
|
|
520
|
+
children: content
|
|
521
|
+
}) : content
|
|
522
|
+
});
|
|
523
|
+
});
|
|
524
|
+
function ExpandControl({
|
|
525
|
+
itemId,
|
|
526
|
+
hasDeferredChildren
|
|
527
|
+
}) {
|
|
528
|
+
const {
|
|
529
|
+
components: {
|
|
530
|
+
IconButton,
|
|
531
|
+
Spinner
|
|
532
|
+
},
|
|
533
|
+
icons: {
|
|
534
|
+
ChevronRight
|
|
535
|
+
}
|
|
536
|
+
} = useTheme();
|
|
537
|
+
const table = useTableContext();
|
|
538
|
+
const isExpanded = table.useState((state) => state.expanded.has(itemId));
|
|
539
|
+
const hasChildren = table.useState((state) => {
|
|
540
|
+
var _a;
|
|
541
|
+
return !!((_a = state.activeItemsById.get(itemId)) == null ? void 0 : _a.children.length);
|
|
542
|
+
});
|
|
543
|
+
function toggle() {
|
|
544
|
+
const {
|
|
545
|
+
props: {
|
|
546
|
+
expanded: controlledExpanded,
|
|
547
|
+
expandOnlyOne,
|
|
548
|
+
onExpandedChange
|
|
549
|
+
},
|
|
550
|
+
expanded,
|
|
551
|
+
activeItemsById
|
|
552
|
+
} = table.getState();
|
|
553
|
+
const newExpanded = new Set(expanded);
|
|
554
|
+
if (expandOnlyOne)
|
|
555
|
+
newExpanded.clear();
|
|
556
|
+
if (isExpanded)
|
|
557
|
+
newExpanded.delete(itemId);
|
|
558
|
+
else {
|
|
559
|
+
newExpanded.add(itemId);
|
|
560
|
+
const item = activeItemsById.get(itemId);
|
|
561
|
+
for (const ancestor of item ? getAncestors(activeItemsById, item) : []) {
|
|
562
|
+
newExpanded.add(ancestor);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
onExpandedChange == null ? void 0 : onExpandedChange(newExpanded);
|
|
566
|
+
if (!controlledExpanded) {
|
|
567
|
+
table.update((state) => {
|
|
568
|
+
state.expanded = newExpanded;
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (isExpanded && hasDeferredChildren && !hasChildren) {
|
|
573
|
+
return vendor.jsx(Spinner, {
|
|
574
|
+
css: {
|
|
575
|
+
margin: "0 var(--spacing)"
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
return vendor.jsx(IconButton, {
|
|
580
|
+
onClick: toggle,
|
|
581
|
+
children: vendor.jsx("span", {
|
|
582
|
+
css: {
|
|
583
|
+
display: "inline-flex",
|
|
584
|
+
transition: "all 300ms",
|
|
585
|
+
transform: isExpanded ? "rotate3d(0, 0, 1, 90deg)" : "rotate3d(0, 0, 1, 0deg)"
|
|
586
|
+
},
|
|
587
|
+
children: vendor.jsx(ChevronRight, {})
|
|
588
|
+
})
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
function SelectComponent({
|
|
592
|
+
itemId
|
|
593
|
+
}) {
|
|
594
|
+
const table = useTableContext();
|
|
595
|
+
const {
|
|
596
|
+
components: {
|
|
597
|
+
Checkbox
|
|
598
|
+
}
|
|
599
|
+
} = useTheme();
|
|
600
|
+
const isSelected = table.useState((state) => {
|
|
601
|
+
const itemIds = itemId ? [itemId] : [...state.activeItemsById.keys()];
|
|
602
|
+
return state.activeItemsById.size > 0 && itemIds.every((itemId2) => state.selection.has(itemId2));
|
|
603
|
+
});
|
|
604
|
+
function toggle(e) {
|
|
605
|
+
const mouseEvent = e.nativeEvent;
|
|
606
|
+
const {
|
|
607
|
+
activeItems,
|
|
608
|
+
activeItemsById,
|
|
609
|
+
lastSelectedId,
|
|
610
|
+
selection,
|
|
611
|
+
props: {
|
|
612
|
+
selectSyncChildren,
|
|
613
|
+
selection: controlledSelection,
|
|
614
|
+
onSelectionChange
|
|
615
|
+
}
|
|
616
|
+
} = table.getState();
|
|
617
|
+
let range;
|
|
618
|
+
if (mouseEvent.shiftKey && itemId) {
|
|
619
|
+
const a = lastSelectedId ? activeItems.findIndex((i) => lastSelectedId === i.id) : 0;
|
|
620
|
+
const b = activeItems.findIndex((item) => item.id === itemId);
|
|
621
|
+
range = activeItems.slice(Math.min(a, b), Math.max(a, b) + 1);
|
|
622
|
+
} else {
|
|
623
|
+
const item = itemId ? activeItemsById.get(itemId) : void 0;
|
|
624
|
+
range = item ? [item] : activeItems;
|
|
625
|
+
}
|
|
626
|
+
const newSelection = new Set(selection);
|
|
627
|
+
for (const item of range) {
|
|
628
|
+
if (isSelected)
|
|
629
|
+
newSelection.delete(item.id);
|
|
630
|
+
else
|
|
631
|
+
newSelection.add(item.id);
|
|
632
|
+
}
|
|
633
|
+
if (selectSyncChildren && isSelected) {
|
|
634
|
+
for (const ancestor of getAncestors(activeItemsById, ...range)) {
|
|
635
|
+
newSelection.delete(ancestor);
|
|
636
|
+
}
|
|
637
|
+
for (const descendant of getDescendants(...range)) {
|
|
638
|
+
newSelection.delete(descendant);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
onSelectionChange == null ? void 0 : onSelectionChange(newSelection);
|
|
642
|
+
if (!controlledSelection) {
|
|
643
|
+
table.update((state) => {
|
|
644
|
+
state.selection = newSelection;
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
table.update((state) => {
|
|
648
|
+
state.lastSelectedId = itemId;
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
return vendor.jsx(Checkbox, {
|
|
652
|
+
css: {
|
|
653
|
+
justifySelf: "start",
|
|
654
|
+
color: "inherit"
|
|
655
|
+
},
|
|
656
|
+
checked: isSelected,
|
|
657
|
+
onChange: toggle
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
function calcClassNames(css, item, index) {
|
|
661
|
+
return [(css == null ? void 0 : css.cell) instanceof Function ? css.cell(item, index) : css == null ? void 0 : css.cell, index % 2 === 0 && (css == null ? void 0 : css.evenCell), index % 2 === 1 && (css == null ? void 0 : css.oddCell)];
|
|
662
|
+
}
|
|
663
|
+
const Row = require$$0.memo(function Row2({
|
|
664
|
+
itemId,
|
|
665
|
+
rowIndex
|
|
666
|
+
}) {
|
|
667
|
+
var _a, _b;
|
|
668
|
+
const table = useTableContext();
|
|
669
|
+
const divRef = require$$0.useRef(null);
|
|
670
|
+
const {
|
|
671
|
+
className,
|
|
672
|
+
indent,
|
|
673
|
+
hasChildren,
|
|
674
|
+
hasDeferredChildren,
|
|
675
|
+
columnIds,
|
|
676
|
+
enableSelection,
|
|
677
|
+
rowAction
|
|
678
|
+
} = table.useState((state) => {
|
|
679
|
+
var _a2, _b2;
|
|
680
|
+
const item = state.activeItemsById.get(itemId);
|
|
681
|
+
const index = !item ? -1 : state.activeItems.indexOf(item);
|
|
682
|
+
return {
|
|
683
|
+
className: calcClassNames(state.props.css, item, index),
|
|
684
|
+
indent: item ? getAncestors(state.activeItemsById, item).size : 0,
|
|
685
|
+
hasChildren: !!(item == null ? void 0 : item.children.length),
|
|
686
|
+
hasDeferredChildren: item && ((_b2 = (_a2 = state.props).hasDeferredChildren) == null ? void 0 : _b2.call(_a2, item)),
|
|
687
|
+
columnIds: state.activeColumns.map((column) => column.id),
|
|
688
|
+
enableSelection: state.props.enableSelection,
|
|
689
|
+
rowAction: state.props.rowAction instanceof Function ? item ? state.props.rowAction(item, index) : null : state.props.rowAction
|
|
690
|
+
};
|
|
691
|
+
});
|
|
692
|
+
require$$0.useEffect(() => {
|
|
693
|
+
const div = divRef.current;
|
|
694
|
+
if (!div)
|
|
695
|
+
return;
|
|
696
|
+
const o = new ResizeObserver(() => {
|
|
697
|
+
if (!document.contains(div))
|
|
698
|
+
return;
|
|
699
|
+
table.update((state) => {
|
|
700
|
+
state.rowHeights.set(itemId, div.offsetHeight);
|
|
701
|
+
});
|
|
702
|
+
});
|
|
703
|
+
o.observe(div);
|
|
704
|
+
return () => o.disconnect();
|
|
705
|
+
}, [divRef.current]);
|
|
706
|
+
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render row", itemId);
|
|
707
|
+
return vendor.jsxs(vendor.Fragment, {
|
|
708
|
+
children: [vendor.jsx("div", {
|
|
709
|
+
css: [tableTheme.defaultClasses.cellFill, className],
|
|
710
|
+
ref: divRef
|
|
711
|
+
}), vendor.jsxs("div", {
|
|
712
|
+
css: [tableTheme.defaultClasses.cell, tableTheme.defaultClasses.firstCell, className],
|
|
713
|
+
children: [vendor.jsx("div", {
|
|
714
|
+
css: {
|
|
715
|
+
width: indent * 20
|
|
716
|
+
}
|
|
717
|
+
}), enableSelection && vendor.jsx(SelectComponent, {
|
|
718
|
+
itemId
|
|
719
|
+
}), (hasChildren || hasDeferredChildren) && vendor.jsx(ExpandControl, {
|
|
720
|
+
itemId,
|
|
721
|
+
hasDeferredChildren
|
|
722
|
+
}), rowAction]
|
|
723
|
+
}), columnIds.map((columnId) => vendor.jsx(ColumnContext.Provider, {
|
|
724
|
+
value: columnId,
|
|
725
|
+
children: vendor.jsx(Cell, {
|
|
726
|
+
itemId,
|
|
727
|
+
rowIndex
|
|
728
|
+
})
|
|
729
|
+
}, columnId)), vendor.jsx("div", {
|
|
730
|
+
css: [tableTheme.defaultClasses.cellFill, className]
|
|
731
|
+
})]
|
|
732
|
+
});
|
|
733
|
+
});
|
|
734
|
+
function SortComponent({
|
|
735
|
+
children
|
|
736
|
+
}) {
|
|
737
|
+
const table = useTableContext();
|
|
738
|
+
const columnId = useColumnContext();
|
|
739
|
+
const {
|
|
740
|
+
components: {
|
|
741
|
+
Badge
|
|
742
|
+
},
|
|
743
|
+
icons: {
|
|
744
|
+
ArrowUpward
|
|
745
|
+
}
|
|
746
|
+
} = useTheme();
|
|
747
|
+
const {
|
|
748
|
+
direction,
|
|
749
|
+
index
|
|
750
|
+
} = table.useState((state) => {
|
|
751
|
+
var _a, _b;
|
|
752
|
+
const index2 = (_a = state.sort.findIndex((s) => s.columnId === columnId)) != null ? _a : -1;
|
|
753
|
+
return {
|
|
754
|
+
direction: (_b = state.sort[index2]) == null ? void 0 : _b.direction,
|
|
755
|
+
index: index2 >= 0 && state.sort.length > 1 ? index2 + 1 : void 0
|
|
756
|
+
};
|
|
757
|
+
});
|
|
758
|
+
function toggle(e) {
|
|
759
|
+
const {
|
|
760
|
+
props: {
|
|
761
|
+
sort: controlledSort,
|
|
762
|
+
onSortChange
|
|
763
|
+
}
|
|
764
|
+
} = table.getState();
|
|
765
|
+
const newDirection = direction === "asc" ? "desc" : "asc";
|
|
766
|
+
const newSort = (e.getModifierState("Control") ? table.getState().sort.filter((s) => s.columnId !== columnId) : []).concat({
|
|
767
|
+
columnId,
|
|
768
|
+
direction: newDirection
|
|
769
|
+
});
|
|
770
|
+
onSortChange == null ? void 0 : onSortChange(newSort);
|
|
771
|
+
if (!controlledSort) {
|
|
772
|
+
table.update((state) => {
|
|
773
|
+
state.sort = newSort;
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
return vendor.jsxs("div", {
|
|
778
|
+
css: {
|
|
779
|
+
userSelect: "none",
|
|
780
|
+
display: "grid",
|
|
781
|
+
gridTemplateColumns: "minmax(0, 1fr) max-content",
|
|
782
|
+
alignItems: "center",
|
|
783
|
+
cursor: "pointer",
|
|
784
|
+
"& > div": {
|
|
785
|
+
overflow: "hidden",
|
|
786
|
+
textOverflow: "ellipsis"
|
|
787
|
+
}
|
|
788
|
+
},
|
|
789
|
+
onClick: toggle,
|
|
790
|
+
children: [vendor.jsx("div", {
|
|
791
|
+
children
|
|
792
|
+
}), vendor.jsx(Badge, {
|
|
793
|
+
badgeContent: index,
|
|
794
|
+
children: vendor.jsx("span", {
|
|
795
|
+
css: [{
|
|
796
|
+
transition: "all 300ms",
|
|
797
|
+
fontSize: "0.8em"
|
|
798
|
+
}, !direction && {
|
|
799
|
+
opacity: 0
|
|
800
|
+
}, direction === "desc" && {
|
|
801
|
+
transform: "rotate3d(0, 0, 1, 180deg)"
|
|
802
|
+
}],
|
|
803
|
+
children: vendor.jsx(ArrowUpward, {})
|
|
804
|
+
})
|
|
805
|
+
})]
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
function throttle(fn, ms) {
|
|
809
|
+
let last = 0;
|
|
810
|
+
let lastArgs;
|
|
811
|
+
let timeout;
|
|
812
|
+
function run() {
|
|
813
|
+
const args = lastArgs;
|
|
814
|
+
last = Date.now();
|
|
815
|
+
lastArgs = void 0;
|
|
816
|
+
timeout = void 0;
|
|
817
|
+
fn(...args);
|
|
818
|
+
}
|
|
819
|
+
return Object.assign(function(...args) {
|
|
820
|
+
const now = Date.now();
|
|
821
|
+
lastArgs = args;
|
|
822
|
+
if (timeout)
|
|
823
|
+
;
|
|
824
|
+
else if (now < last + ms) {
|
|
825
|
+
timeout = setTimeout(run, last + ms - now);
|
|
826
|
+
} else {
|
|
827
|
+
run();
|
|
828
|
+
}
|
|
829
|
+
}, {
|
|
830
|
+
flush() {
|
|
831
|
+
if (lastArgs) {
|
|
832
|
+
run();
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
const onAncestorScroll = (x, onScroll) => {
|
|
838
|
+
const find = (x2) => x2.parentElement ? [x2.parentElement, ...find(x2.parentElement)] : [document];
|
|
839
|
+
const ancestors = find(x);
|
|
840
|
+
for (const ancestor of ancestors) {
|
|
841
|
+
ancestor.addEventListener("scroll", onScroll);
|
|
842
|
+
}
|
|
843
|
+
return () => {
|
|
844
|
+
for (const ancestor of ancestors) {
|
|
845
|
+
ancestor.removeEventListener("scroll", onScroll);
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
};
|
|
849
|
+
const findScrollRoot = (x) => {
|
|
850
|
+
const parent = x.parentElement;
|
|
851
|
+
if (!parent)
|
|
852
|
+
return document.documentElement;
|
|
853
|
+
if (parent.scrollHeight > parent.clientHeight)
|
|
854
|
+
return parent;
|
|
855
|
+
return findScrollRoot(parent);
|
|
856
|
+
};
|
|
857
|
+
const relativeOffset = (x, y) => {
|
|
858
|
+
if (x.offsetParent === y.offsetParent || !x.offsetParent)
|
|
859
|
+
return x.offsetTop - y.offsetTop;
|
|
860
|
+
if (x.offsetParent instanceof HTMLElement)
|
|
861
|
+
return relativeOffset(x.offsetParent, y) + x.offsetTop;
|
|
862
|
+
return 0;
|
|
863
|
+
};
|
|
864
|
+
function Virtualized(_a) {
|
|
865
|
+
var _b = _a, {
|
|
866
|
+
header,
|
|
867
|
+
children
|
|
868
|
+
} = _b, props = __objRest(_b, [
|
|
869
|
+
"header",
|
|
870
|
+
"children"
|
|
871
|
+
]);
|
|
872
|
+
var _a2, _b2, _c, _d;
|
|
873
|
+
const table = useTableContext();
|
|
874
|
+
const virtual = table.useState("props.virtual");
|
|
875
|
+
const probeRef = require$$0.useRef(null);
|
|
876
|
+
const [, setCounter] = require$$0.useState(0);
|
|
877
|
+
const {
|
|
878
|
+
itemIds = [],
|
|
879
|
+
from = 0,
|
|
880
|
+
to,
|
|
881
|
+
before = 0,
|
|
882
|
+
after = 0
|
|
883
|
+
} = table.useState((state) => {
|
|
884
|
+
var _a3;
|
|
885
|
+
const itemIds2 = state.activeItems.map((item) => item.id);
|
|
886
|
+
const root = probeRef.current && findScrollRoot(probeRef.current);
|
|
887
|
+
if (!state.props.virtual)
|
|
888
|
+
return {
|
|
889
|
+
itemIds: itemIds2
|
|
890
|
+
};
|
|
891
|
+
if (!probeRef.current || !root || !document.contains(root))
|
|
892
|
+
return {};
|
|
893
|
+
const {
|
|
894
|
+
rowHeight,
|
|
895
|
+
initalRowHeight,
|
|
896
|
+
overscan = 200,
|
|
897
|
+
overscanTop,
|
|
898
|
+
overscanBottom
|
|
899
|
+
} = (_a3 = state.props.virtual instanceof Object ? state.props.virtual : void 0) != null ? _a3 : {};
|
|
900
|
+
let totalHeight = 0;
|
|
901
|
+
const rowHeights = itemIds2.map((itemId, index) => {
|
|
902
|
+
var _a4, _b3;
|
|
903
|
+
const h = (_b3 = (_a4 = rowHeight != null ? rowHeight : state.rowHeights.get(itemId)) != null ? _a4 : initalRowHeight) != null ? _b3 : index === 0 ? 100 : totalHeight / index;
|
|
904
|
+
totalHeight += h;
|
|
905
|
+
return h;
|
|
906
|
+
});
|
|
907
|
+
const probeOffset = relativeOffset(probeRef.current, root);
|
|
908
|
+
const headerHeight = probeRef.current.offsetTop;
|
|
909
|
+
const topOfTable = root.scrollTop - probeOffset + headerHeight;
|
|
910
|
+
const bottomOfTable = topOfTable + root.clientHeight - headerHeight;
|
|
911
|
+
let from2 = 0, to2 = itemIds2.length, before2 = 0, after2 = 0;
|
|
912
|
+
for (const h of rowHeights) {
|
|
913
|
+
if (before2 + h > topOfTable - (overscanTop != null ? overscanTop : overscan))
|
|
914
|
+
break;
|
|
915
|
+
from2++;
|
|
916
|
+
before2 += h;
|
|
917
|
+
}
|
|
918
|
+
for (const h of rowHeights.reverse()) {
|
|
919
|
+
if (after2 + h > totalHeight - bottomOfTable - (overscanBottom != null ? overscanBottom : overscan))
|
|
920
|
+
break;
|
|
921
|
+
to2--;
|
|
922
|
+
after2 += h;
|
|
923
|
+
}
|
|
924
|
+
return {
|
|
925
|
+
itemIds: itemIds2.slice(from2, to2),
|
|
926
|
+
from: from2,
|
|
927
|
+
to: to2,
|
|
928
|
+
before: before2,
|
|
929
|
+
after: after2
|
|
930
|
+
};
|
|
931
|
+
});
|
|
932
|
+
const throttleScroll = (_b2 = (_a2 = typeof virtual === "boolean" ? void 0 : virtual) == null ? void 0 : _a2.throttleScroll) != null ? _b2 : 500;
|
|
933
|
+
const incCounter = require$$0.useMemo(() => throttle(() => setCounter((c) => c + 1), throttleScroll), [throttleScroll]);
|
|
934
|
+
require$$0.useEffect(() => {
|
|
935
|
+
if (!virtual || !probeRef.current)
|
|
936
|
+
return;
|
|
937
|
+
return onAncestorScroll(probeRef.current, incCounter);
|
|
938
|
+
}, [probeRef.current, incCounter]);
|
|
939
|
+
(_d = (_c = table.getState().props).debugRender) == null ? void 0 : _d.call(_c, `Virtualalized render ${from} to ${to}`);
|
|
940
|
+
return vendor.jsxs("div", __spreadProps(__spreadValues({}, props), {
|
|
941
|
+
children: [header, virtual && vendor.jsx("div", {
|
|
942
|
+
style: {
|
|
943
|
+
gridColumn: "1 / -1",
|
|
944
|
+
height: before
|
|
945
|
+
},
|
|
946
|
+
ref: probeRef
|
|
947
|
+
}), children(itemIds, from), virtual && vendor.jsx("div", {
|
|
948
|
+
style: {
|
|
949
|
+
gridColumn: "1 / -1",
|
|
950
|
+
height: after
|
|
951
|
+
}
|
|
952
|
+
})]
|
|
953
|
+
}));
|
|
954
|
+
}
|
|
955
|
+
const TableContext = require$$0.createContext(null);
|
|
956
|
+
const ColumnContext = require$$0.createContext(null);
|
|
957
|
+
function useTableContext() {
|
|
958
|
+
const value = require$$0.useContext(TableContext);
|
|
959
|
+
if (!value)
|
|
960
|
+
throw Error("No table context available");
|
|
961
|
+
return value;
|
|
962
|
+
}
|
|
963
|
+
function useColumnContext() {
|
|
964
|
+
const value = require$$0.useContext(ColumnContext);
|
|
965
|
+
if (value === null)
|
|
966
|
+
throw Error("No column context available");
|
|
967
|
+
return value;
|
|
968
|
+
}
|
|
969
|
+
require$$0.memo(function TableInner2({
|
|
970
|
+
hidden
|
|
971
|
+
}) {
|
|
972
|
+
var _a, _b;
|
|
973
|
+
const table = useTableContext();
|
|
974
|
+
const fullWidth = table.useState("props.fullWidth");
|
|
975
|
+
const activeColumns = table.useState((state) => state.activeColumns.map((column) => ({
|
|
976
|
+
id: column.id,
|
|
977
|
+
width: column.width,
|
|
978
|
+
css: column.css,
|
|
979
|
+
header: column.header
|
|
980
|
+
})));
|
|
981
|
+
const columnWidths = table.useState("columnWidths", {
|
|
982
|
+
throttle: 16
|
|
983
|
+
});
|
|
984
|
+
const columnStyleOverride = table.useState("columnStyleOverride", {
|
|
985
|
+
throttle: 16
|
|
986
|
+
});
|
|
987
|
+
const defaultWidth = table.useState("props.defaultWidth");
|
|
988
|
+
const css = table.useState("props.css");
|
|
989
|
+
const stickyHeader = table.useState("props.stickyHeader");
|
|
990
|
+
const enableSelection = table.useState("props.enableSelection");
|
|
991
|
+
const enableColumnSelection = table.useState("props.enableColumnSelection");
|
|
992
|
+
const enableExport = table.useState((state) => !!state.props.enableExport.copy || !!state.props.enableExport.download);
|
|
993
|
+
const cssVariables = useCssVariables();
|
|
994
|
+
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table inner");
|
|
995
|
+
return vendor.jsx(Virtualized, {
|
|
996
|
+
css: [cssVariables, tableTheme.defaultClasses.table, css == null ? void 0 : css.table, {
|
|
997
|
+
gridTemplateColumns: [
|
|
998
|
+
fullWidth === "right" || fullWidth === true ? "auto" : "0",
|
|
999
|
+
"max-content",
|
|
1000
|
+
...activeColumns.map((column) => {
|
|
1001
|
+
var _a2, _b2, _c;
|
|
1002
|
+
return (_c = (_b2 = (_a2 = columnWidths.get(column.id)) != null ? _a2 : column.width) != null ? _b2 : defaultWidth) != null ? _c : "max-content";
|
|
1003
|
+
}),
|
|
1004
|
+
fullWidth === "left" || fullWidth === true ? "auto" : "0"
|
|
1005
|
+
].join(" ")
|
|
1006
|
+
}, hidden && {
|
|
1007
|
+
visibility: "hidden"
|
|
1008
|
+
}],
|
|
1009
|
+
header: vendor.jsxs(vendor.Fragment, {
|
|
1010
|
+
children: [vendor.jsx("div", {
|
|
1011
|
+
css: [tableTheme.defaultClasses.headerFill, stickyHeader && tableTheme.defaultClasses.sticky, css == null ? void 0 : css.headerCell]
|
|
1012
|
+
}), vendor.jsxs("div", {
|
|
1013
|
+
css: [tableTheme.defaultClasses.headerCell, stickyHeader && tableTheme.defaultClasses.sticky, css == null ? void 0 : css.headerCell],
|
|
1014
|
+
children: [enableSelection && vendor.jsx(SelectComponent, {}), enableColumnSelection && vendor.jsx(ColumnSelection, {}), enableExport && vendor.jsx(Export, {})]
|
|
1015
|
+
}), vendor.jsx(ColumnHeaderContext.Provider, {
|
|
1016
|
+
children: activeColumns.map((column) => {
|
|
1017
|
+
var _a2;
|
|
1018
|
+
return vendor.jsx(ColumnContext.Provider, {
|
|
1019
|
+
value: column.id,
|
|
1020
|
+
children: vendor.jsxs(ColumnHeader, {
|
|
1021
|
+
css: [tableTheme.defaultClasses.headerCell, css == null ? void 0 : css.headerCell, (_a2 = column.css) == null ? void 0 : _a2.headerCell, columnStyleOverride.get(column.id), stickyHeader && tableTheme.defaultClasses.sticky],
|
|
1022
|
+
children: [vendor.jsx(FilterControl, {}), vendor.jsx(SortComponent, {
|
|
1023
|
+
children: column.header
|
|
1024
|
+
}), vendor.jsx("div", {
|
|
1025
|
+
css: {
|
|
1026
|
+
flex: 1
|
|
1027
|
+
}
|
|
1028
|
+
}), vendor.jsx(ResizeHandle, {})]
|
|
1029
|
+
}, column.id)
|
|
1030
|
+
}, column.id);
|
|
1031
|
+
})
|
|
1032
|
+
}), vendor.jsx("div", {
|
|
1033
|
+
css: [tableTheme.defaultClasses.headerFill, stickyHeader && tableTheme.defaultClasses.sticky, css == null ? void 0 : css.headerCell]
|
|
1034
|
+
})]
|
|
1035
|
+
}),
|
|
1036
|
+
children: (itemIds, startIndex) => itemIds.map((itemId, index) => vendor.jsx(Row, {
|
|
1037
|
+
itemId,
|
|
1038
|
+
rowIndex: startIndex + index
|
|
1039
|
+
}, itemId))
|
|
1040
|
+
});
|
|
1041
|
+
});
|
|
1042
|
+
//# sourceMappingURL=schummar-table.js.map
|