schummar-table 0.10.4 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +19 -17
- package/dist/cjs/index.js +0 -2959
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/mui4Theme.js +0 -98
- package/dist/cjs/mui4Theme.js.map +0 -1
- package/dist/cjs/mui5Theme.js +0 -102
- package/dist/cjs/mui5Theme.js.map +0 -1
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/tableTheme.js +0 -248
- package/dist/cjs/tableTheme.js.map +0 -1
- package/dist/es/index.js +0 -2937
- package/dist/es/index.js.map +0 -1
- package/dist/es/mui4Theme.js +0 -94
- package/dist/es/mui4Theme.js.map +0 -1
- package/dist/es/mui5Theme.js +0 -98
- package/dist/es/mui5Theme.js.map +0 -1
- package/dist/es/tableTheme.js +0 -238
- package/dist/es/tableTheme.js.map +0 -1
- package/dist/types/components/autoFocusTextField.d.ts +0 -5
- package/dist/types/components/cell.d.ts +0 -6
- package/dist/types/components/clearFiltersButton.d.ts +0 -1
- package/dist/types/components/columnFooter.d.ts +0 -1
- package/dist/types/components/columnHeader.d.ts +0 -6
- package/dist/types/components/columnSelection.d.ts +0 -2
- package/dist/types/components/dateFilter.d.ts +0 -11
- package/dist/types/components/dateInput.d.ts +0 -5
- package/dist/types/components/datePicker.d.ts +0 -25
- package/dist/types/components/expandControl.d.ts +0 -6
- package/dist/types/components/export.d.ts +0 -2
- package/dist/types/components/filterControl.d.ts +0 -3
- package/dist/types/components/formControlLabel.d.ts +0 -6
- package/dist/types/components/resizeHandle.d.ts +0 -5
- package/dist/types/components/row.d.ts +0 -7
- package/dist/types/components/selectComponent.d.ts +0 -5
- package/dist/types/components/selectFilter.d.ts +0 -12
- package/dist/types/components/sortComponent.d.ts +0 -4
- package/dist/types/components/spinnner.d.ts +0 -3
- package/dist/types/components/table.d.ts +0 -8
- package/dist/types/components/textFilter.d.ts +0 -8
- package/dist/types/components/virtualized.d.ts +0 -7
- package/dist/types/hooks/useFilter.d.ts +0 -7
- package/dist/types/hooks/useMemoMap.d.ts +0 -2
- package/dist/types/hooks/useTableMemo.d.ts +0 -6
- package/dist/types/hooks/useTheme.d.ts +0 -2
- package/dist/types/index.d.ts +0 -13
- package/dist/types/internalState/calcItems.d.ts +0 -3
- package/dist/types/internalState/calcProps.d.ts +0 -2
- package/dist/types/internalState/cleanupState.d.ts +0 -3
- package/dist/types/internalState/filterColumns.d.ts +0 -3
- package/dist/types/internalState/normalizeExpanded.d.ts +0 -3
- package/dist/types/internalState/syncSelections.d.ts +0 -3
- package/dist/types/internalState/tableStateStorage.d.ts +0 -11
- package/dist/types/internalState/useTableState.d.ts +0 -3
- package/dist/types/misc/csvExport.d.ts +0 -7
- package/dist/types/misc/debounce.d.ts +0 -4
- package/dist/types/misc/helpers.d.ts +0 -16
- package/dist/types/misc/queue.d.ts +0 -6
- package/dist/types/misc/textMatch.d.ts +0 -2
- package/dist/types/misc/throttle.d.ts +0 -5
- package/dist/types/theme/defaultTheme/badge.d.ts +0 -2
- package/dist/types/theme/defaultTheme/button.d.ts +0 -2
- package/dist/types/theme/defaultTheme/checkbox.d.ts +0 -2
- package/dist/types/theme/defaultTheme/defaultClasses.d.ts +0 -19
- package/dist/types/theme/defaultTheme/defaultColors.d.ts +0 -2
- package/dist/types/theme/defaultTheme/defaultComponents.d.ts +0 -2
- package/dist/types/theme/defaultTheme/defaultIcons.d.ts +0 -2
- package/dist/types/theme/defaultTheme/defaultTexts.d.ts +0 -2
- package/dist/types/theme/defaultTheme/iconButton.d.ts +0 -2
- package/dist/types/theme/defaultTheme/index.d.ts +0 -2
- package/dist/types/theme/defaultTheme/popover.d.ts +0 -7
- package/dist/types/theme/defaultTheme/textField.d.ts +0 -2
- package/dist/types/theme/mui4Theme/index.d.ts +0 -7
- package/dist/types/theme/mui5Theme/index.d.ts +0 -7
- package/dist/types/theme/tableTheme.d.ts +0 -10
- package/dist/types/theme/useCssVariables.d.ts +0 -9
- package/dist/types/types.d.ts +0 -329
package/dist/cjs/index.js
DELETED
|
@@ -1,2959 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports[Symbol.toStringTag] = "Module";
|
|
35
|
-
var react = require("react");
|
|
36
|
-
var react$1 = require("schummar-state/react");
|
|
37
|
-
var tableTheme = require("./tableTheme.js");
|
|
38
|
-
var jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
39
|
-
var dayzed = require("dayzed");
|
|
40
|
-
var immer = require("immer");
|
|
41
|
-
var react$2 = require("@emotion/react");
|
|
42
|
-
require("react-dom");
|
|
43
|
-
const TableMemoContext = react.createContext(/* @__PURE__ */ new Map());
|
|
44
|
-
function TableMemoContextProvider({
|
|
45
|
-
children
|
|
46
|
-
}) {
|
|
47
|
-
return /* @__PURE__ */ jsxRuntime.jsx(TableMemoContext.Provider, {
|
|
48
|
-
value: react.useMemo(() => /* @__PURE__ */ new Map(), []),
|
|
49
|
-
children
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function useTableMemo() {
|
|
53
|
-
const memoCache = react.useContext(TableMemoContext);
|
|
54
|
-
return (key, fn) => {
|
|
55
|
-
let deps;
|
|
56
|
-
if (Array.isArray(fn)) {
|
|
57
|
-
deps = fn.slice(1);
|
|
58
|
-
fn = fn[0];
|
|
59
|
-
} else {
|
|
60
|
-
deps = [fn.toString()];
|
|
61
|
-
}
|
|
62
|
-
let cachedValue = memoCache.get(key);
|
|
63
|
-
const hit = cachedValue && cachedValue[1].length === deps.length && cachedValue[1].every((x, i) => x === deps[i]);
|
|
64
|
-
if (!cachedValue || !hit) {
|
|
65
|
-
cachedValue = [fn, deps];
|
|
66
|
-
memoCache.set(key, cachedValue);
|
|
67
|
-
}
|
|
68
|
-
return cachedValue[0];
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
class Queue {
|
|
72
|
-
constructor() {
|
|
73
|
-
this.q = new Array();
|
|
74
|
-
this.isRunning = false;
|
|
75
|
-
}
|
|
76
|
-
run(job, replace) {
|
|
77
|
-
return new Promise((resolve, reject) => {
|
|
78
|
-
if (replace) {
|
|
79
|
-
this.q = [];
|
|
80
|
-
}
|
|
81
|
-
this.q.push({ job, resolve, reject });
|
|
82
|
-
if (!this.isRunning)
|
|
83
|
-
this.start();
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
async start() {
|
|
87
|
-
this.isRunning = true;
|
|
88
|
-
let next;
|
|
89
|
-
while (next = this.q.shift()) {
|
|
90
|
-
try {
|
|
91
|
-
const result = await next.job();
|
|
92
|
-
next.resolve(result);
|
|
93
|
-
} catch (e) {
|
|
94
|
-
next.reject(e);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
this.isRunning = false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const KEYS = ["sort", "selection", "expanded", "hiddenColumns", "filterValues", "columnWidths", "columnOrder"];
|
|
101
|
-
const storageName = (id) => `schummar-table_state-v1_${id}`;
|
|
102
|
-
function stringify(value) {
|
|
103
|
-
function prepare(value2) {
|
|
104
|
-
if (value2 instanceof Date) {
|
|
105
|
-
return { __date: value2.toJSON() };
|
|
106
|
-
}
|
|
107
|
-
if (value2 instanceof Set) {
|
|
108
|
-
return { __set: Array.from(value2).map(prepare) };
|
|
109
|
-
}
|
|
110
|
-
if (value2 instanceof Map) {
|
|
111
|
-
return { __map: Array.from(value2.entries()).map((entry) => entry.map(prepare)) };
|
|
112
|
-
}
|
|
113
|
-
if (value2 instanceof Array) {
|
|
114
|
-
return value2.map(prepare);
|
|
115
|
-
}
|
|
116
|
-
if (value2 instanceof Object) {
|
|
117
|
-
return Object.fromEntries(Object.entries(value2).map(([k, v]) => [k, prepare(v)]));
|
|
118
|
-
}
|
|
119
|
-
return value2;
|
|
120
|
-
}
|
|
121
|
-
return JSON.stringify(prepare(value));
|
|
122
|
-
}
|
|
123
|
-
function parse(value) {
|
|
124
|
-
return JSON.parse(value, (_key, value2) => {
|
|
125
|
-
if (value2 instanceof Object && "__date" in value2) {
|
|
126
|
-
return new Date(value2.__date);
|
|
127
|
-
}
|
|
128
|
-
if (value2 instanceof Object && "__set" in value2) {
|
|
129
|
-
return new Set(value2.__set);
|
|
130
|
-
}
|
|
131
|
-
if (value2 instanceof Object && "__map" in value2) {
|
|
132
|
-
return new Map(value2.__map);
|
|
133
|
-
}
|
|
134
|
-
return value2;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
function useTableStateStorage() {
|
|
138
|
-
const table = useTableContext();
|
|
139
|
-
const [isHydrated, setIsHydrated] = react.useState(false);
|
|
140
|
-
react.useEffect(() => {
|
|
141
|
-
const { persist } = table.getState().props;
|
|
142
|
-
if (!persist) {
|
|
143
|
-
setIsHydrated(true);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
let isCanceled = false;
|
|
147
|
-
(async () => {
|
|
148
|
-
var _a, _b;
|
|
149
|
-
try {
|
|
150
|
-
const { storage, id, include, exclude } = persist;
|
|
151
|
-
const json = await storage.getItem(storageName(id));
|
|
152
|
-
if (isCanceled || !json)
|
|
153
|
-
return;
|
|
154
|
-
const data = parse(json);
|
|
155
|
-
(_b = (_a = table.getState().props).debug) == null ? void 0 : _b.call(_a, "load", json, data);
|
|
156
|
-
table.update((state) => {
|
|
157
|
-
var _a2, _b2, _c, _d;
|
|
158
|
-
for (const key of KEYS) {
|
|
159
|
-
if ((!include || include.includes(key)) && !(exclude == null ? void 0 : exclude.includes(key)) && key in data) {
|
|
160
|
-
if (key === "filterValues") {
|
|
161
|
-
for (const [id2, value] of data[key]) {
|
|
162
|
-
if ((_b2 = (_a2 = state.filters.get(id2)) == null ? void 0 : _a2.persist) != null ? _b2 : true) {
|
|
163
|
-
state.filterValues.set(id2, value);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
state[key] = data[key];
|
|
168
|
-
if (key === "expanded" || key === "hiddenColumns" || key === "selection" || key === "sort") {
|
|
169
|
-
(_d = (_c = state.props)[`on${key.slice(0, 1).toUpperCase() + key.slice(1)}Change`]) == null ? void 0 : _d.call(_c, data[key]);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
} catch (e) {
|
|
176
|
-
console.error("Failed to load table state:", e);
|
|
177
|
-
} finally {
|
|
178
|
-
setIsHydrated(true);
|
|
179
|
-
}
|
|
180
|
-
})();
|
|
181
|
-
return () => {
|
|
182
|
-
isCanceled = true;
|
|
183
|
-
};
|
|
184
|
-
}, []);
|
|
185
|
-
react.useEffect(() => {
|
|
186
|
-
if (!isHydrated)
|
|
187
|
-
return;
|
|
188
|
-
const q = new Queue();
|
|
189
|
-
return table.subscribe((state) => {
|
|
190
|
-
var _a, _b;
|
|
191
|
-
if (!state.props.persist)
|
|
192
|
-
return;
|
|
193
|
-
const { storage, id, include, exclude } = state.props.persist;
|
|
194
|
-
const data = {};
|
|
195
|
-
for (const key of KEYS) {
|
|
196
|
-
if ((!include || include.includes(key)) && !(exclude == null ? void 0 : exclude.includes(key))) {
|
|
197
|
-
if (key === "filterValues") {
|
|
198
|
-
data[key] = /* @__PURE__ */ new Map();
|
|
199
|
-
for (const [id2, value] of state.filterValues) {
|
|
200
|
-
if ((_b = (_a = state.filters.get(id2)) == null ? void 0 : _a.persist) != null ? _b : true) {
|
|
201
|
-
data.filterValues.set(id2, value);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
} else {
|
|
205
|
-
data[key] = state[key];
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return { storage, id, data };
|
|
210
|
-
}, (props) => {
|
|
211
|
-
var _a, _b;
|
|
212
|
-
if (!props)
|
|
213
|
-
return;
|
|
214
|
-
const { storage, id, data } = props;
|
|
215
|
-
(_b = (_a = table.getState().props).debug) == null ? void 0 : _b.call(_a, "save", data, stringify(data));
|
|
216
|
-
q.run(async () => {
|
|
217
|
-
await storage.setItem(storageName(id), stringify(data));
|
|
218
|
-
}, true);
|
|
219
|
-
}, { throttle: 1e3 });
|
|
220
|
-
}, [isHydrated]);
|
|
221
|
-
return isHydrated;
|
|
222
|
-
}
|
|
223
|
-
const flatMap = (arr, flatMap2) => {
|
|
224
|
-
return [...arr].reduce((out, cur) => out.concat(flatMap2(cur)), []);
|
|
225
|
-
};
|
|
226
|
-
const orderBy = (arr, selectors = [], direction = []) => {
|
|
227
|
-
if (selectors.length === 0)
|
|
228
|
-
selectors = [(t) => t];
|
|
229
|
-
return [...arr].sort((a, b) => {
|
|
230
|
-
var _a, _b;
|
|
231
|
-
for (let i = 0; i < selectors.length; i++) {
|
|
232
|
-
const _a2 = (_a = selectors[i]) == null ? void 0 : _a.call(selectors, a);
|
|
233
|
-
const _b2 = (_b = selectors[i]) == null ? void 0 : _b.call(selectors, b);
|
|
234
|
-
const dir = direction[i] === "desc" ? -1 : 1;
|
|
235
|
-
if (_a2 > _b2)
|
|
236
|
-
return dir;
|
|
237
|
-
if (_a2 < _b2)
|
|
238
|
-
return -dir;
|
|
239
|
-
}
|
|
240
|
-
return 0;
|
|
241
|
-
});
|
|
242
|
-
};
|
|
243
|
-
const uniq = (arr) => {
|
|
244
|
-
const set = /* @__PURE__ */ new Set();
|
|
245
|
-
for (const t of arr)
|
|
246
|
-
set.add(t);
|
|
247
|
-
return Array.from(set);
|
|
248
|
-
};
|
|
249
|
-
const intersect = (a, b) => {
|
|
250
|
-
const result = /* @__PURE__ */ new Set();
|
|
251
|
-
for (const x of a)
|
|
252
|
-
if (b.has(x))
|
|
253
|
-
result.add(x);
|
|
254
|
-
return result;
|
|
255
|
-
};
|
|
256
|
-
const getAncestors = (activeItemsById, ...items) => {
|
|
257
|
-
const result = /* @__PURE__ */ new Set();
|
|
258
|
-
const find = ({ parentId }) => {
|
|
259
|
-
const parent = parentId ? activeItemsById.get(parentId) : void 0;
|
|
260
|
-
if (parent && !result.has(parent.id)) {
|
|
261
|
-
result.add(parent.id);
|
|
262
|
-
find(parent);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
items.forEach(find);
|
|
266
|
-
return result;
|
|
267
|
-
};
|
|
268
|
-
const getDescendants = (...items) => {
|
|
269
|
-
const result = /* @__PURE__ */ new Set();
|
|
270
|
-
const find = (item) => {
|
|
271
|
-
for (const child of item.children) {
|
|
272
|
-
if (!result.has(child.id)) {
|
|
273
|
-
result.add(child.id);
|
|
274
|
-
find(child);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
items.forEach(find);
|
|
279
|
-
return result;
|
|
280
|
-
};
|
|
281
|
-
const asString = (x) => {
|
|
282
|
-
if (x instanceof Array)
|
|
283
|
-
return x.map(asString).join(", ");
|
|
284
|
-
if (x instanceof Object)
|
|
285
|
-
return JSON.stringify(x);
|
|
286
|
-
return String(x != null ? x : "");
|
|
287
|
-
};
|
|
288
|
-
const asStringOrArray = (x) => {
|
|
289
|
-
if (x instanceof Array)
|
|
290
|
-
return x.map(asString);
|
|
291
|
-
return asString(x);
|
|
292
|
-
};
|
|
293
|
-
const castArray = (a) => a instanceof Array ? a : [a];
|
|
294
|
-
const cx = (...classNames) => classNames.flatMap((entry) => {
|
|
295
|
-
if (!entry)
|
|
296
|
-
return [];
|
|
297
|
-
if (typeof entry === "string")
|
|
298
|
-
return [entry];
|
|
299
|
-
return Object.entries(entry).filter(([, predicate]) => predicate).map(([className2]) => className2);
|
|
300
|
-
}).join(" ");
|
|
301
|
-
function calcItems(state) {
|
|
302
|
-
react.useEffect(() => state.addReaction((state2) => [
|
|
303
|
-
state2.props.items,
|
|
304
|
-
state2.props.id,
|
|
305
|
-
state2.props.parentId,
|
|
306
|
-
state2.props.revealFiltered,
|
|
307
|
-
state2.sort,
|
|
308
|
-
state2.filters,
|
|
309
|
-
state2.filterValues,
|
|
310
|
-
state2.activeColumns,
|
|
311
|
-
state2.expanded
|
|
312
|
-
], ([items = [], id, parentId, revealFiltered, sort, filters, filterValues, activeColumns], draft) => {
|
|
313
|
-
const tableItems = items.map((item) => ({
|
|
314
|
-
id: id(item),
|
|
315
|
-
parentId: parentId == null ? void 0 : parentId(item),
|
|
316
|
-
children: [],
|
|
317
|
-
value: item
|
|
318
|
-
}));
|
|
319
|
-
let sorted;
|
|
320
|
-
if (sort.length === 0) {
|
|
321
|
-
sorted = tableItems;
|
|
322
|
-
} else {
|
|
323
|
-
const selectors = flatMap(sort, (sort2) => {
|
|
324
|
-
const column = activeColumns.find((column2) => column2.id === sort2.columnId);
|
|
325
|
-
if (!column)
|
|
326
|
-
return [];
|
|
327
|
-
return column.sortBy.map((sortBy) => ({
|
|
328
|
-
selector: (item) => sortBy(column.value(item), item),
|
|
329
|
-
direction: sort2.direction
|
|
330
|
-
}));
|
|
331
|
-
}).filter(Boolean);
|
|
332
|
-
sorted = orderBy(tableItems, selectors.map((x) => (item) => x.selector(item.value)), selectors.map((x) => x.direction));
|
|
333
|
-
}
|
|
334
|
-
const lookup = /* @__PURE__ */ new Map();
|
|
335
|
-
for (const item of sorted) {
|
|
336
|
-
lookup.set(item.id, item);
|
|
337
|
-
}
|
|
338
|
-
for (const item of sorted) {
|
|
339
|
-
const parent = item.parentId !== void 0 ? lookup.get(item.parentId) : void 0;
|
|
340
|
-
parent == null ? void 0 : parent.children.push(item);
|
|
341
|
-
}
|
|
342
|
-
const allItems = new Array();
|
|
343
|
-
const allItemsById = /* @__PURE__ */ new Map();
|
|
344
|
-
const traverse = (items2) => {
|
|
345
|
-
for (const item of items2) {
|
|
346
|
-
allItems.push(item);
|
|
347
|
-
allItemsById.set(item.id, item);
|
|
348
|
-
traverse(item.children);
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
traverse(sorted.filter((item) => item.parentId === void 0));
|
|
352
|
-
let expandedChanged = false;
|
|
353
|
-
const activeItemsById = /* @__PURE__ */ new Map();
|
|
354
|
-
const activeSet = /* @__PURE__ */ new Set();
|
|
355
|
-
const activeItems = [...allItems].reverse().filter((item) => {
|
|
356
|
-
let isActive = activeSet.has(item.id);
|
|
357
|
-
isActive || (isActive = activeColumns.every((column) => {
|
|
358
|
-
var _a;
|
|
359
|
-
const filter = filters.get(column.id);
|
|
360
|
-
if (!filter)
|
|
361
|
-
return true;
|
|
362
|
-
const filterValue = filterValues.get(column.id);
|
|
363
|
-
if (filterValue === void 0 || !filter.isActive(filterValue))
|
|
364
|
-
return true;
|
|
365
|
-
const filterBy = (_a = filter.filterBy) != null ? _a : (x) => x;
|
|
366
|
-
const value = filterBy(column.value(item.value), item.value);
|
|
367
|
-
return castArray(value).some((value2) => filter.test(filterValue, value2));
|
|
368
|
-
}));
|
|
369
|
-
if (isActive && item.parentId !== void 0) {
|
|
370
|
-
if (revealFiltered && Array.from(filters.entries()).some(([id2, filter]) => {
|
|
371
|
-
const filterValue = filterValues.get(id2);
|
|
372
|
-
return !!filter && filterValue !== void 0 && filter.isActive(filterValue);
|
|
373
|
-
})) {
|
|
374
|
-
expandedChanged || (expandedChanged = !draft.expanded.has(item.parentId));
|
|
375
|
-
draft.expanded.add(item.parentId);
|
|
376
|
-
} else if (!draft.expanded.has(item.parentId)) {
|
|
377
|
-
isActive = false;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
if (isActive && item.parentId !== void 0) {
|
|
381
|
-
activeSet.add(item.parentId);
|
|
382
|
-
}
|
|
383
|
-
if (isActive) {
|
|
384
|
-
activeItemsById.set(item.id, item);
|
|
385
|
-
}
|
|
386
|
-
return isActive;
|
|
387
|
-
}).reverse();
|
|
388
|
-
draft.items = immer.castDraft(allItems);
|
|
389
|
-
draft.itemsById = immer.castDraft(allItemsById);
|
|
390
|
-
draft.activeItems = immer.castDraft(activeItems);
|
|
391
|
-
draft.activeItemsById = immer.castDraft(activeItemsById);
|
|
392
|
-
if (expandedChanged) {
|
|
393
|
-
setTimeout(() => {
|
|
394
|
-
var _a, _b;
|
|
395
|
-
(_b = (_a = state.getState().props).onExpandedChange) == null ? void 0 : _b.call(_a, state.getState().expanded);
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
}, { runNow: true }), [state]);
|
|
399
|
-
}
|
|
400
|
-
const noopParentId = () => void 0;
|
|
401
|
-
function calcProps(props) {
|
|
402
|
-
const cache = useTableMemo();
|
|
403
|
-
return react.useMemo(() => {
|
|
404
|
-
var _f, _g, _h, _i, _j, _k, _l, _m;
|
|
405
|
-
let id;
|
|
406
|
-
if (props.id instanceof Function || Array.isArray(props.id)) {
|
|
407
|
-
id = cache("id", props.id);
|
|
408
|
-
} else {
|
|
409
|
-
id = cache("id", [(item) => item[props.id], props.id]);
|
|
410
|
-
}
|
|
411
|
-
let parentId;
|
|
412
|
-
if (props.parentId instanceof Function || Array.isArray(props.parentId)) {
|
|
413
|
-
parentId = cache("parentId", props.parentId);
|
|
414
|
-
} else if (props.parentId !== void 0) {
|
|
415
|
-
parentId = cache("parentId", [(item) => item[props.parentId], props.parentId]);
|
|
416
|
-
} else {
|
|
417
|
-
parentId = noopParentId;
|
|
418
|
-
}
|
|
419
|
-
let inputColumns;
|
|
420
|
-
if (props.columns instanceof Function) {
|
|
421
|
-
inputColumns = props.columns((value, column) => __spreadProps(__spreadValues({}, column), { value }));
|
|
422
|
-
} else {
|
|
423
|
-
inputColumns = props.columns.map((column) => __spreadProps(__spreadValues({}, column), { dependecies: void 0 }));
|
|
424
|
-
}
|
|
425
|
-
const defCol = props.defaultColumnProps;
|
|
426
|
-
const mapColumn = ({
|
|
427
|
-
id: _id,
|
|
428
|
-
header = ((_a) => (_a = defCol == null ? void 0 : defCol.header) != null ? _a : null)(),
|
|
429
|
-
footer = ((_b) => (_b = defCol == null ? void 0 : defCol.footer) != null ? _b : null)(),
|
|
430
|
-
value,
|
|
431
|
-
renderCell = ((_c) => (_c = defCol == null ? void 0 : defCol.renderCell) != null ? _c : asString)(),
|
|
432
|
-
exportCell = ((_d) => (_d = defCol == null ? void 0 : defCol.exportCell) != null ? _d : asString)(),
|
|
433
|
-
sortBy = ((_e) => (_e = defCol == null ? void 0 : defCol.sortBy) != null ? _e : [(v) => typeof v === "number" || v instanceof Date ? v : String(v)])(),
|
|
434
|
-
cannotHide = defCol == null ? void 0 : defCol.cannotHide,
|
|
435
|
-
classes = defCol == null ? void 0 : defCol.classes,
|
|
436
|
-
filter = defCol == null ? void 0 : defCol.filter,
|
|
437
|
-
width = defCol == null ? void 0 : defCol.width
|
|
438
|
-
}, index) => {
|
|
439
|
-
const id2 = _id != null ? _id : index;
|
|
440
|
-
const cacheKey = typeof id2 === "string" ? `s${id2}` : `n${id2}`;
|
|
441
|
-
return {
|
|
442
|
-
id: id2,
|
|
443
|
-
header: header instanceof Function ? cache(`columns.${cacheKey}.header`, header) : header,
|
|
444
|
-
footer: footer instanceof Function ? cache(`columns.${cacheKey}.footer`, footer) : footer,
|
|
445
|
-
value: cache(`columns.${cacheKey}.value`, value),
|
|
446
|
-
renderCell: cache(`columns.${cacheKey}.renderCell`, renderCell),
|
|
447
|
-
exportCell,
|
|
448
|
-
sortBy: sortBy.map((fn, i) => cache(`columns.${cacheKey}.sortBy.${i}`, fn)),
|
|
449
|
-
cannotHide,
|
|
450
|
-
classes,
|
|
451
|
-
filter,
|
|
452
|
-
width
|
|
453
|
-
};
|
|
454
|
-
};
|
|
455
|
-
const columns = inputColumns.map(mapColumn);
|
|
456
|
-
const wrapCell = props.wrapCell && cache("wrapCell", props.wrapCell);
|
|
457
|
-
const rowAction = props.rowAction instanceof Function || Array.isArray(props.rowAction) ? cache("rowAction", props.rowAction) : props.rowAction;
|
|
458
|
-
let copy;
|
|
459
|
-
if (props.enableExport === true || props.enableExport instanceof Object && props.enableExport.copy === true) {
|
|
460
|
-
copy = { separator: " " };
|
|
461
|
-
} else if (props.enableExport && props.enableExport.copy instanceof Object) {
|
|
462
|
-
copy = props.enableExport.copy;
|
|
463
|
-
}
|
|
464
|
-
let download;
|
|
465
|
-
if (props.enableExport === true || props.enableExport instanceof Object && props.enableExport.download === true) {
|
|
466
|
-
download = { sepPrefix: true };
|
|
467
|
-
} else if (props.enableExport && props.enableExport.download instanceof Object) {
|
|
468
|
-
download = props.enableExport.download;
|
|
469
|
-
}
|
|
470
|
-
const enableExport = { copy, download };
|
|
471
|
-
return __spreadProps(__spreadValues({}, props), {
|
|
472
|
-
id,
|
|
473
|
-
parentId,
|
|
474
|
-
columns,
|
|
475
|
-
wrapCell,
|
|
476
|
-
rowAction,
|
|
477
|
-
enableSelection: (_f = props.enableSelection) != null ? _f : true,
|
|
478
|
-
selectSyncChildren: (_g = props.selectSyncChildren) != null ? _g : true,
|
|
479
|
-
stickyHeader: (_h = props.stickyHeader) != null ? _h : true,
|
|
480
|
-
stickyFooter: (_i = props.stickyFooter) != null ? _i : true,
|
|
481
|
-
enableExport,
|
|
482
|
-
enableColumnSelection: (_j = props.enableColumnSelection) != null ? _j : true,
|
|
483
|
-
enableClearFiltersButton: (_k = props.enableClearFiltersButton) != null ? _k : false,
|
|
484
|
-
enableColumnResize: (_l = props.enableColumnResize) != null ? _l : true,
|
|
485
|
-
enableColumnReorder: (_m = props.enableColumnReorder) != null ? _m : true
|
|
486
|
-
});
|
|
487
|
-
}, [props]);
|
|
488
|
-
}
|
|
489
|
-
function cleanupState(state) {
|
|
490
|
-
react.useEffect(() => state.addReaction((state2) => [state2.props.columns, state2.itemsById, state2.activeItemsById, state2.activeColumns], ([columns, itemsById, activeItemsById, activeColumns], draft) => {
|
|
491
|
-
const columnIds = new Set(columns.map((column) => column.id));
|
|
492
|
-
const activeColumnIds = new Set(activeColumns.map((column) => column.id));
|
|
493
|
-
const newSort = draft.sort.filter((s) => activeColumnIds.has(s.columnId));
|
|
494
|
-
if (newSort.length < draft.sort.length) {
|
|
495
|
-
draft.sort = newSort;
|
|
496
|
-
setTimeout(() => {
|
|
497
|
-
var _a, _b;
|
|
498
|
-
(_b = (_a = state.getState().props).onSortChange) == null ? void 0 : _b.call(_a, newSort);
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
for (const id of draft.filters.keys()) {
|
|
502
|
-
if (!activeColumnIds.has(id))
|
|
503
|
-
draft.filters.delete(id);
|
|
504
|
-
}
|
|
505
|
-
for (const id of draft.filterValues.keys()) {
|
|
506
|
-
if (!activeColumnIds.has(id))
|
|
507
|
-
draft.filterValues.delete(id);
|
|
508
|
-
}
|
|
509
|
-
for (const id of draft.hiddenColumns.keys()) {
|
|
510
|
-
if (!columnIds.has(id))
|
|
511
|
-
draft.hiddenColumns.delete(id);
|
|
512
|
-
}
|
|
513
|
-
for (const id of draft.columnWidths.keys()) {
|
|
514
|
-
if (!columnIds.has(id))
|
|
515
|
-
draft.columnWidths.delete(id);
|
|
516
|
-
}
|
|
517
|
-
for (const id of draft.columnOrder) {
|
|
518
|
-
if (!columnIds.has(id))
|
|
519
|
-
draft.columnOrder = draft.columnOrder.filter((x) => x !== id);
|
|
520
|
-
}
|
|
521
|
-
if (draft.props.items) {
|
|
522
|
-
const newSelection = intersect(draft.selection, activeItemsById);
|
|
523
|
-
if (newSelection.size !== draft.selection.size) {
|
|
524
|
-
draft.selection = newSelection;
|
|
525
|
-
setTimeout(() => {
|
|
526
|
-
var _a, _b;
|
|
527
|
-
(_b = (_a = state.getState().props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
const newExpanded = intersect(draft.expanded, itemsById);
|
|
531
|
-
if (newExpanded.size < draft.expanded.size) {
|
|
532
|
-
draft.expanded = newExpanded;
|
|
533
|
-
setTimeout(() => {
|
|
534
|
-
var _a, _b;
|
|
535
|
-
(_b = (_a = state.getState().props).onExpandedChange) == null ? void 0 : _b.call(_a, newExpanded);
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}, { runNow: true }), [state]);
|
|
540
|
-
}
|
|
541
|
-
function filterColumns(state) {
|
|
542
|
-
react.useEffect(() => state.addReaction((state2) => [state2.props.columns, state2.hiddenColumns, state2.columnOrder], ([columns, hiddenColumns, columnOrder], draft) => {
|
|
543
|
-
draft.activeColumns = orderBy(columns.filter((column) => !hiddenColumns.has(column.id)), [(column) => columnOrder.indexOf(column.id)]);
|
|
544
|
-
}, { runNow: true }), [state]);
|
|
545
|
-
}
|
|
546
|
-
function normalizeExpanded(table) {
|
|
547
|
-
react.useEffect(() => table.addReaction((state) => [state.props.expandOnlyOne, state.expanded, state.itemsById], ([expandOnlyOne, , itemsById], state) => {
|
|
548
|
-
var _a, _b;
|
|
549
|
-
let expanded = state.expanded;
|
|
550
|
-
let last, lastItem;
|
|
551
|
-
let hasChanged = false;
|
|
552
|
-
if (expandOnlyOne && (last = [...expanded][expanded.size - 1]) && (lastItem = itemsById.get(last))) {
|
|
553
|
-
const ancestors = getAncestors(itemsById, lastItem);
|
|
554
|
-
if ([...expanded].slice(0, -1).some((id) => !ancestors.has(id))) {
|
|
555
|
-
expanded = state.expanded = new Set([...ancestors].concat(last));
|
|
556
|
-
hasChanged = true;
|
|
557
|
-
}
|
|
558
|
-
} else {
|
|
559
|
-
for (const id of expanded) {
|
|
560
|
-
const item = itemsById.get(id);
|
|
561
|
-
const ancestors = item && getAncestors(itemsById, item);
|
|
562
|
-
for (const ancestor of ancestors != null ? ancestors : []) {
|
|
563
|
-
if (!expanded.has(ancestor)) {
|
|
564
|
-
expanded.add(ancestor);
|
|
565
|
-
hasChanged = true;
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
if (hasChanged) {
|
|
571
|
-
(_b = (_a = state.props).onExpandedChange) == null ? void 0 : _b.call(_a, new Set(expanded));
|
|
572
|
-
}
|
|
573
|
-
}, { runNow: true }), [table]);
|
|
574
|
-
}
|
|
575
|
-
function syncSelections(table) {
|
|
576
|
-
react.useEffect(() => table.addReaction((state) => [state.props.selectSyncChildren, state.selection, state.activeItems], ([selectSyncChildren, selection, activeItems], state) => {
|
|
577
|
-
if (!selectSyncChildren)
|
|
578
|
-
return;
|
|
579
|
-
const newSelection = new Set(selection);
|
|
580
|
-
for (const item of activeItems) {
|
|
581
|
-
if (item.parentId !== void 0 && newSelection.has(item.parentId)) {
|
|
582
|
-
newSelection.add(item.id);
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
if (newSelection.size !== selection.size) {
|
|
586
|
-
state.selection = newSelection;
|
|
587
|
-
setTimeout(() => {
|
|
588
|
-
var _a, _b;
|
|
589
|
-
(_b = (_a = table.getState().props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
}, { runNow: true }), [table]);
|
|
593
|
-
}
|
|
594
|
-
function useTableState(_props) {
|
|
595
|
-
const props = calcProps(_props);
|
|
596
|
-
const state = react.useMemo(() => {
|
|
597
|
-
var _a, _b, _c, _d;
|
|
598
|
-
return new react$1.Store({
|
|
599
|
-
props,
|
|
600
|
-
sort: (_a = props.defaultSort) != null ? _a : [],
|
|
601
|
-
selection: (_b = props.defaultSelection) != null ? _b : /* @__PURE__ */ new Set(),
|
|
602
|
-
expanded: (_c = props.defaultExpanded) != null ? _c : /* @__PURE__ */ new Set(),
|
|
603
|
-
rowHeights: /* @__PURE__ */ new Map(),
|
|
604
|
-
filters: /* @__PURE__ */ new Map(),
|
|
605
|
-
filterValues: /* @__PURE__ */ new Map(),
|
|
606
|
-
hiddenColumns: (_d = props.defaultHiddenColumns) != null ? _d : /* @__PURE__ */ new Set(),
|
|
607
|
-
columnWidths: /* @__PURE__ */ new Map(),
|
|
608
|
-
columnOrder: props.columns.map((column) => column.id),
|
|
609
|
-
columnStyleOverride: /* @__PURE__ */ new Map(),
|
|
610
|
-
activeColumns: [],
|
|
611
|
-
items: [],
|
|
612
|
-
itemsById: /* @__PURE__ */ new Map(),
|
|
613
|
-
activeItems: [],
|
|
614
|
-
activeItemsById: /* @__PURE__ */ new Map(),
|
|
615
|
-
lastSelectedId: void 0
|
|
616
|
-
});
|
|
617
|
-
}, []);
|
|
618
|
-
filterColumns(state);
|
|
619
|
-
normalizeExpanded(state);
|
|
620
|
-
calcItems(state);
|
|
621
|
-
syncSelections(state);
|
|
622
|
-
cleanupState(state);
|
|
623
|
-
react.useEffect(() => {
|
|
624
|
-
state.update((state2) => {
|
|
625
|
-
state2.props = immer.castDraft(props);
|
|
626
|
-
if (props.sort)
|
|
627
|
-
state2.sort = props.sort;
|
|
628
|
-
if (props.selection)
|
|
629
|
-
state2.selection = props.selection;
|
|
630
|
-
if (props.expanded)
|
|
631
|
-
state2.expanded = props.expanded;
|
|
632
|
-
if (props.hiddenColumns)
|
|
633
|
-
state2.hiddenColumns = props.hiddenColumns;
|
|
634
|
-
for (const column of props.columns) {
|
|
635
|
-
if (!state2.columnOrder.includes(column.id)) {
|
|
636
|
-
const index = props.columns.indexOf(column);
|
|
637
|
-
state2.columnOrder.splice(index, 0, column.id);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
}, [state, props]);
|
|
642
|
-
return state;
|
|
643
|
-
}
|
|
644
|
-
function useCssVariables() {
|
|
645
|
-
return useTheme(({ spacing, colors }) => ({
|
|
646
|
-
"--spacing": spacing,
|
|
647
|
-
"--primaryMain": colors.primary.main,
|
|
648
|
-
"--primaryLight": colors.primary.light,
|
|
649
|
-
"--primaryContrastText": colors.primary.contrastText,
|
|
650
|
-
"--secondaryMain": colors.secondary.main,
|
|
651
|
-
"--secondaryLight": colors.secondary.light,
|
|
652
|
-
"--secondaryContrastText": colors.secondary.contrastText
|
|
653
|
-
}));
|
|
654
|
-
}
|
|
655
|
-
function ClearFiltersButton() {
|
|
656
|
-
const Button2 = useTheme((t) => t.components.Button);
|
|
657
|
-
const textClearFilters = useTheme((t) => t.text.clearFilters);
|
|
658
|
-
const table = useTableContext();
|
|
659
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
660
|
-
css: tableTheme.defaultClasses.clearFiltersButton,
|
|
661
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(Button2, {
|
|
662
|
-
variant: "outlined",
|
|
663
|
-
onClick: () => {
|
|
664
|
-
table.update((state) => {
|
|
665
|
-
state.activeColumns.forEach((column) => {
|
|
666
|
-
state.filterValues.delete(column.id);
|
|
667
|
-
});
|
|
668
|
-
});
|
|
669
|
-
},
|
|
670
|
-
children: textClearFilters
|
|
671
|
-
})
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
function ColumnFooter() {
|
|
675
|
-
const table = useTableContext();
|
|
676
|
-
const columnId = useColumnContext();
|
|
677
|
-
const stickyFooter = table.useState("props.stickyFooter");
|
|
678
|
-
const columnStyleOverride = table.useState((state) => state.columnStyleOverride.get(columnId), {
|
|
679
|
-
throttle: 16
|
|
680
|
-
});
|
|
681
|
-
const columnClasses = table.useState((state) => {
|
|
682
|
-
var _a;
|
|
683
|
-
return (_a = state.activeColumns.find((column) => column.id === columnId)) == null ? void 0 : _a.classes;
|
|
684
|
-
});
|
|
685
|
-
const classes = useTheme((theme) => theme.classes);
|
|
686
|
-
const content = table.useState((state) => {
|
|
687
|
-
const column = state.activeColumns.find((column2) => column2.id === columnId);
|
|
688
|
-
if ((column == null ? void 0 : column.footer) instanceof Function) {
|
|
689
|
-
const items = state.activeItems;
|
|
690
|
-
const values = items.map((item) => column == null ? void 0 : column.value(item.value));
|
|
691
|
-
return column == null ? void 0 : column.footer(values, items);
|
|
692
|
-
}
|
|
693
|
-
return column == null ? void 0 : column.footer;
|
|
694
|
-
});
|
|
695
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
696
|
-
className: cx(classes == null ? void 0 : classes.footerCell, columnClasses == null ? void 0 : columnClasses.footerCell),
|
|
697
|
-
css: [tableTheme.defaultClasses.footerCell, columnStyleOverride, stickyFooter && tableTheme.defaultClasses.stickyBottom, stickyFooter instanceof Object && stickyFooter],
|
|
698
|
-
children: content
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
const FilterControlContext = react.createContext(() => void 0);
|
|
702
|
-
function FilterControl() {
|
|
703
|
-
const table = useTableContext();
|
|
704
|
-
const columnId = useColumnContext();
|
|
705
|
-
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
706
|
-
const Popover = useTheme((t) => t.components.Popover);
|
|
707
|
-
const FilterList2 = useTheme((t) => t.icons.FilterList);
|
|
708
|
-
const ArrowDropDown2 = useTheme((t) => t.icons.ArrowDropDown);
|
|
709
|
-
const cssVariables = useCssVariables();
|
|
710
|
-
const [anchor, setAnchor] = react.useState(null);
|
|
711
|
-
const isActive = table.useState((state) => {
|
|
712
|
-
const filter2 = state.filters.get(columnId);
|
|
713
|
-
const filterValue = state.filterValues.get(columnId);
|
|
714
|
-
return filter2 !== void 0 && filterValue !== void 0 && filter2.isActive(filterValue);
|
|
715
|
-
});
|
|
716
|
-
const filter = table.useState((state) => {
|
|
717
|
-
var _a;
|
|
718
|
-
return (_a = state.activeColumns.find((column) => column.id === columnId)) == null ? void 0 : _a.filter;
|
|
719
|
-
});
|
|
720
|
-
function reset() {
|
|
721
|
-
table.update((state) => {
|
|
722
|
-
state.filterValues.delete(columnId);
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
const close = react.useCallback(function() {
|
|
726
|
-
setAnchor(null);
|
|
727
|
-
}, []);
|
|
728
|
-
if (!filter)
|
|
729
|
-
return null;
|
|
730
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(FilterControlContext.Provider, {
|
|
731
|
-
value: close,
|
|
732
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
733
|
-
onClick: (e) => setAnchor(e.currentTarget),
|
|
734
|
-
onContextMenu: (e) => {
|
|
735
|
-
reset();
|
|
736
|
-
e.preventDefault();
|
|
737
|
-
return false;
|
|
738
|
-
},
|
|
739
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(IconButton2, {
|
|
740
|
-
css: [{
|
|
741
|
-
color: "#b0bac9"
|
|
742
|
-
}, isActive && {
|
|
743
|
-
color: "var(--primaryMain) !important"
|
|
744
|
-
}],
|
|
745
|
-
children: isActive ? /* @__PURE__ */ jsxRuntime.jsx(FilterList2, {}) : /* @__PURE__ */ jsxRuntime.jsx(ArrowDropDown2, {})
|
|
746
|
-
})
|
|
747
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
748
|
-
onPointerDown: (e) => {
|
|
749
|
-
e.stopPropagation();
|
|
750
|
-
},
|
|
751
|
-
onPointerMove: (e) => {
|
|
752
|
-
e.stopPropagation();
|
|
753
|
-
},
|
|
754
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(Popover, {
|
|
755
|
-
open: true,
|
|
756
|
-
hidden: !anchor,
|
|
757
|
-
onClose: () => setAnchor(null),
|
|
758
|
-
anchorEl: anchor != null ? anchor : document.body,
|
|
759
|
-
css: cssVariables,
|
|
760
|
-
children: filter
|
|
761
|
-
})
|
|
762
|
-
})]
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
function ResizeHandle() {
|
|
766
|
-
const table = useTableContext();
|
|
767
|
-
const columnId = useColumnContext();
|
|
768
|
-
const enabled = table.useState("props.enableColumnResize");
|
|
769
|
-
function onPointerDown(e) {
|
|
770
|
-
e.stopPropagation();
|
|
771
|
-
const div = e.target;
|
|
772
|
-
div.setPointerCapture(e.pointerId);
|
|
773
|
-
}
|
|
774
|
-
function onPointerMove(e) {
|
|
775
|
-
e.stopPropagation();
|
|
776
|
-
const div = e.target;
|
|
777
|
-
if (!div.hasPointerCapture(e.pointerId))
|
|
778
|
-
return;
|
|
779
|
-
const parent = div.parentElement;
|
|
780
|
-
const width = Math.max(e.clientX - parent.getBoundingClientRect().left + 5, 50);
|
|
781
|
-
table.update((state) => {
|
|
782
|
-
state.columnWidths.set(columnId, `${width}px`);
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
function onPointerUp(e) {
|
|
786
|
-
e.stopPropagation();
|
|
787
|
-
const div = e.target;
|
|
788
|
-
div.releasePointerCapture(e.pointerId);
|
|
789
|
-
}
|
|
790
|
-
function onDoubleClick(e) {
|
|
791
|
-
table.update((state) => {
|
|
792
|
-
if (e.getModifierState("Control")) {
|
|
793
|
-
state.columnWidths.delete(columnId);
|
|
794
|
-
} else {
|
|
795
|
-
state.columnWidths.set(columnId, "max-content");
|
|
796
|
-
}
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ResizeHandleView, {
|
|
800
|
-
enabled,
|
|
801
|
-
onPointerDown: enabled ? onPointerDown : void 0,
|
|
802
|
-
onPointerMove: enabled ? onPointerMove : void 0,
|
|
803
|
-
onPointerUp: enabled ? onPointerUp : void 0,
|
|
804
|
-
onDoubleClick: enabled ? onDoubleClick : void 0
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
function ResizeHandleView(_a) {
|
|
808
|
-
var _b = _a, {
|
|
809
|
-
enabled
|
|
810
|
-
} = _b, props = __objRest(_b, [
|
|
811
|
-
"enabled"
|
|
812
|
-
]);
|
|
813
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", __spreadValues({
|
|
814
|
-
css: {
|
|
815
|
-
alignSelf: "stretch",
|
|
816
|
-
padding: "0 5px",
|
|
817
|
-
cursor: enabled ? "col-resize" : "initial",
|
|
818
|
-
display: "flex",
|
|
819
|
-
alignItems: "center",
|
|
820
|
-
"&:after": {
|
|
821
|
-
content: '""',
|
|
822
|
-
width: 1,
|
|
823
|
-
height: "1.5em",
|
|
824
|
-
background: "#c9cfda",
|
|
825
|
-
transition: "transform 300ms"
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
}, props));
|
|
829
|
-
}
|
|
830
|
-
function SortComponent({
|
|
831
|
-
children
|
|
832
|
-
}) {
|
|
833
|
-
const table = useTableContext();
|
|
834
|
-
const columnId = useColumnContext();
|
|
835
|
-
const Badge2 = useTheme((t) => t.components.Badge);
|
|
836
|
-
const ArrowUpward2 = useTheme((t) => t.icons.ArrowUpward);
|
|
837
|
-
const {
|
|
838
|
-
direction,
|
|
839
|
-
index
|
|
840
|
-
} = table.useState((state) => {
|
|
841
|
-
var _a, _b;
|
|
842
|
-
const index2 = (_a = state.sort.findIndex((s) => s.columnId === columnId)) != null ? _a : -1;
|
|
843
|
-
return {
|
|
844
|
-
direction: (_b = state.sort[index2]) == null ? void 0 : _b.direction,
|
|
845
|
-
index: index2 >= 0 && state.sort.length > 1 ? index2 + 1 : void 0
|
|
846
|
-
};
|
|
847
|
-
});
|
|
848
|
-
function toggle2(e, off) {
|
|
849
|
-
const {
|
|
850
|
-
props: {
|
|
851
|
-
sort: controlledSort,
|
|
852
|
-
onSortChange
|
|
853
|
-
}
|
|
854
|
-
} = table.getState();
|
|
855
|
-
const newDirection = direction === "asc" ? "desc" : "asc";
|
|
856
|
-
const newSort = e.getModifierState("Control") || off ? table.getState().sort.filter((s) => s.columnId !== columnId) : [];
|
|
857
|
-
if (!off) {
|
|
858
|
-
newSort.push({
|
|
859
|
-
columnId,
|
|
860
|
-
direction: newDirection
|
|
861
|
-
});
|
|
862
|
-
}
|
|
863
|
-
onSortChange == null ? void 0 : onSortChange(newSort);
|
|
864
|
-
if (!controlledSort) {
|
|
865
|
-
table.update((state) => {
|
|
866
|
-
state.sort = newSort;
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
e.preventDefault();
|
|
870
|
-
return false;
|
|
871
|
-
}
|
|
872
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
873
|
-
css: {
|
|
874
|
-
userSelect: "none",
|
|
875
|
-
display: "grid",
|
|
876
|
-
gridTemplateColumns: "minmax(0, 1fr) max-content",
|
|
877
|
-
alignItems: "center",
|
|
878
|
-
cursor: "pointer",
|
|
879
|
-
"& > div": {
|
|
880
|
-
overflow: "hidden",
|
|
881
|
-
textOverflow: "ellipsis"
|
|
882
|
-
}
|
|
883
|
-
},
|
|
884
|
-
onClick: (e) => toggle2(e),
|
|
885
|
-
onContextMenu: (e) => toggle2(e, true),
|
|
886
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
887
|
-
children
|
|
888
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(Badge2, {
|
|
889
|
-
badgeContent: index,
|
|
890
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
891
|
-
css: [{
|
|
892
|
-
transition: "all 300ms",
|
|
893
|
-
fontSize: "0.8em"
|
|
894
|
-
}, !direction && {
|
|
895
|
-
opacity: 0
|
|
896
|
-
}, direction === "desc" && {
|
|
897
|
-
transform: "rotate3d(0, 0, 1, 180deg)"
|
|
898
|
-
}],
|
|
899
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ArrowUpward2, {})
|
|
900
|
-
})
|
|
901
|
-
})]
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
const ColumnHeaderContext = new react$1.StoreScope({
|
|
905
|
-
items: /* @__PURE__ */ new Map()
|
|
906
|
-
});
|
|
907
|
-
function ColumnHeader() {
|
|
908
|
-
const ref = react.useRef(null);
|
|
909
|
-
const columnId = useColumnContext();
|
|
910
|
-
const table = useTableContext();
|
|
911
|
-
const enabled = table.useState("props.enableColumnReorder");
|
|
912
|
-
const columnStyleOverride = table.useState((state) => state.columnStyleOverride.get(columnId), {
|
|
913
|
-
throttle: 16
|
|
914
|
-
});
|
|
915
|
-
const stickyHeader = table.useState("props.stickyHeader");
|
|
916
|
-
const classes = useTheme((theme) => theme.classes);
|
|
917
|
-
const {
|
|
918
|
-
header,
|
|
919
|
-
columnClasses
|
|
920
|
-
} = table.useState((state) => {
|
|
921
|
-
const column = state.activeColumns.find((column2) => column2.id === columnId);
|
|
922
|
-
return {
|
|
923
|
-
header: column == null ? void 0 : column.header,
|
|
924
|
-
columnClasses: column == null ? void 0 : column.classes
|
|
925
|
-
};
|
|
926
|
-
});
|
|
927
|
-
const store = ColumnHeaderContext.useStore();
|
|
928
|
-
const draggingStart = react.useRef();
|
|
929
|
-
const clone = react.useRef();
|
|
930
|
-
react.useEffect(() => {
|
|
931
|
-
const div = ref.current;
|
|
932
|
-
if (!div)
|
|
933
|
-
return;
|
|
934
|
-
store.update((state) => {
|
|
935
|
-
state.items.set(columnId, immer.castDraft(div));
|
|
936
|
-
});
|
|
937
|
-
return () => {
|
|
938
|
-
store.update((state) => {
|
|
939
|
-
state.items.delete(columnId);
|
|
940
|
-
});
|
|
941
|
-
};
|
|
942
|
-
}, [ref.current, store, columnId]);
|
|
943
|
-
function calcTargetIndex(offsetLeft) {
|
|
944
|
-
var _a, _b, _c;
|
|
945
|
-
const cols = table.getState().columnOrder.map((id) => ({
|
|
946
|
-
id,
|
|
947
|
-
div: store.getState().items.get(id)
|
|
948
|
-
}));
|
|
949
|
-
const otherCols = cols.filter((col) => col.id !== columnId);
|
|
950
|
-
const firstOffsetleft = (_c = (_b = (_a = cols.find((col) => col.div)) == null ? void 0 : _a.div) == null ? void 0 : _b.offsetLeft) != null ? _c : 0;
|
|
951
|
-
let sum = 0;
|
|
952
|
-
const targetIndex = otherCols.findIndex((col) => {
|
|
953
|
-
var _a2, _b2;
|
|
954
|
-
const width = (_b2 = (_a2 = col.div) == null ? void 0 : _a2.offsetWidth) != null ? _b2 : 0;
|
|
955
|
-
if (sum + width / 2 > offsetLeft - firstOffsetleft)
|
|
956
|
-
return true;
|
|
957
|
-
sum += width;
|
|
958
|
-
return false;
|
|
959
|
-
});
|
|
960
|
-
return targetIndex === -1 ? otherCols.length : targetIndex;
|
|
961
|
-
}
|
|
962
|
-
function onPointerDown(e) {
|
|
963
|
-
const div = ref.current;
|
|
964
|
-
if (!div)
|
|
965
|
-
return;
|
|
966
|
-
draggingStart.current = {
|
|
967
|
-
mouseX: e.clientX,
|
|
968
|
-
bounds: div.getBoundingClientRect()
|
|
969
|
-
};
|
|
970
|
-
}
|
|
971
|
-
function onPointerMove(e) {
|
|
972
|
-
table.update((state) => {
|
|
973
|
-
const div = ref.current;
|
|
974
|
-
if (!div || draggingStart.current === void 0 || Math.abs(e.clientX - draggingStart.current.mouseX) < 5)
|
|
975
|
-
return;
|
|
976
|
-
e.stopPropagation();
|
|
977
|
-
div.setPointerCapture(e.pointerId);
|
|
978
|
-
if (!clone.current) {
|
|
979
|
-
clone.current = div.cloneNode(true);
|
|
980
|
-
document.body.append(clone.current);
|
|
981
|
-
for (const [key, value] of Object.entries(getComputedStyle(div))) {
|
|
982
|
-
try {
|
|
983
|
-
clone.current.style[key] = value;
|
|
984
|
-
} catch {
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
Object.assign(clone.current.style, {
|
|
988
|
-
pointerEvents: "none",
|
|
989
|
-
position: "fixed",
|
|
990
|
-
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%)",
|
|
991
|
-
left: `${draggingStart.current.bounds.left}px`,
|
|
992
|
-
top: `${draggingStart.current.bounds.top}px`
|
|
993
|
-
});
|
|
994
|
-
div.style.color = "rgba(0, 0, 0, 0.2)";
|
|
995
|
-
}
|
|
996
|
-
clone.current.style.left = `${draggingStart.current.bounds.left + e.clientX - draggingStart.current.mouseX}px`;
|
|
997
|
-
const index = state.columnOrder.indexOf(columnId);
|
|
998
|
-
const targetIndex = calcTargetIndex(div.offsetLeft + e.clientX - draggingStart.current.mouseX);
|
|
999
|
-
const columns = table.getState().columnOrder.map((id, index2) => {
|
|
1000
|
-
var _a, _b;
|
|
1001
|
-
return {
|
|
1002
|
-
id,
|
|
1003
|
-
index: index2,
|
|
1004
|
-
width: (_b = (_a = store.getState().items.get(id)) == null ? void 0 : _a.offsetWidth) != null ? _b : 0
|
|
1005
|
-
};
|
|
1006
|
-
});
|
|
1007
|
-
state.columnOrder.forEach((id, i) => {
|
|
1008
|
-
let offset = 0;
|
|
1009
|
-
if (i === index) {
|
|
1010
|
-
if (targetIndex > index) {
|
|
1011
|
-
offset = columns.slice(index + 1, targetIndex + 1).reduce((sum, col) => sum + col.width, 0);
|
|
1012
|
-
} else if (targetIndex < index) {
|
|
1013
|
-
offset = -columns.slice(targetIndex, index).reduce((sum, col) => sum + col.width, 0);
|
|
1014
|
-
}
|
|
1015
|
-
} else if (i >= targetIndex && i < index) {
|
|
1016
|
-
offset = div.offsetWidth;
|
|
1017
|
-
} else if (i > index && i <= targetIndex) {
|
|
1018
|
-
offset = -div.offsetWidth;
|
|
1019
|
-
}
|
|
1020
|
-
state.columnStyleOverride.set(id, {
|
|
1021
|
-
transition: "transform 500ms",
|
|
1022
|
-
transform: `translate3d(${offset}px, 0, 0)`,
|
|
1023
|
-
zIndex: i === index ? 1 : void 0
|
|
1024
|
-
});
|
|
1025
|
-
});
|
|
1026
|
-
});
|
|
1027
|
-
}
|
|
1028
|
-
function onPointerUp(e) {
|
|
1029
|
-
table.update((state) => {
|
|
1030
|
-
var _a;
|
|
1031
|
-
const div = ref.current;
|
|
1032
|
-
if (!div || draggingStart.current === void 0)
|
|
1033
|
-
return;
|
|
1034
|
-
const index = state.columnOrder.indexOf(columnId);
|
|
1035
|
-
const targetIndex = calcTargetIndex(div.offsetLeft + e.clientX - draggingStart.current.mouseX);
|
|
1036
|
-
state.columnOrder.splice(index, 1);
|
|
1037
|
-
state.columnOrder.splice(targetIndex, 0, columnId);
|
|
1038
|
-
(_a = clone.current) == null ? void 0 : _a.remove();
|
|
1039
|
-
div.style.color = "";
|
|
1040
|
-
state.columnStyleOverride.clear();
|
|
1041
|
-
draggingStart.current = void 0;
|
|
1042
|
-
clone.current = void 0;
|
|
1043
|
-
});
|
|
1044
|
-
}
|
|
1045
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
1046
|
-
ref,
|
|
1047
|
-
className: cx(classes == null ? void 0 : classes.headerCell, columnClasses == null ? void 0 : columnClasses.headerCell),
|
|
1048
|
-
css: [{
|
|
1049
|
-
position: "relative",
|
|
1050
|
-
userSelect: "none"
|
|
1051
|
-
}, tableTheme.defaultClasses.headerCell, columnStyleOverride, stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
|
|
1052
|
-
onPointerDown: enabled ? onPointerDown : void 0,
|
|
1053
|
-
onPointerMove: enabled ? onPointerMove : void 0,
|
|
1054
|
-
onPointerUp: enabled ? onPointerUp : void 0,
|
|
1055
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx(SortComponent, {
|
|
1056
|
-
children: header
|
|
1057
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1058
|
-
css: {
|
|
1059
|
-
flex: 1
|
|
1060
|
-
}
|
|
1061
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(FilterControl, {}), /* @__PURE__ */ jsxRuntime.jsx(ResizeHandle, {})]
|
|
1062
|
-
});
|
|
1063
|
-
}
|
|
1064
|
-
function FormControlLabel({
|
|
1065
|
-
control,
|
|
1066
|
-
label,
|
|
1067
|
-
disabled
|
|
1068
|
-
}) {
|
|
1069
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("label", {
|
|
1070
|
-
css: [{
|
|
1071
|
-
display: "flex",
|
|
1072
|
-
alignItems: "center",
|
|
1073
|
-
cursor: "pointer",
|
|
1074
|
-
userSelect: "none",
|
|
1075
|
-
"& > *": {
|
|
1076
|
-
cursor: "pointer"
|
|
1077
|
-
}
|
|
1078
|
-
}, disabled && {
|
|
1079
|
-
color: "rgba(0, 0, 0, 0.26)"
|
|
1080
|
-
}],
|
|
1081
|
-
children: [control, /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
1082
|
-
css: {
|
|
1083
|
-
marginLeft: "var(--spacing)"
|
|
1084
|
-
},
|
|
1085
|
-
children: label
|
|
1086
|
-
})]
|
|
1087
|
-
});
|
|
1088
|
-
}
|
|
1089
|
-
function ColumnSelection() {
|
|
1090
|
-
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
1091
|
-
const Popover = useTheme((t) => t.components.Popover);
|
|
1092
|
-
const Checkbox2 = useTheme((t) => t.components.Checkbox);
|
|
1093
|
-
const Settings2 = useTheme((t) => t.icons.Settings);
|
|
1094
|
-
const selectColumns = useTheme((t) => t.text.selectColumns);
|
|
1095
|
-
const cssVariables = useCssVariables();
|
|
1096
|
-
const table = useTableContext();
|
|
1097
|
-
const columns = table.useState("props.columns");
|
|
1098
|
-
const hiddenColumns = table.useState("hiddenColumns");
|
|
1099
|
-
const [anchorEl, setAnchorEl] = react.useState(null);
|
|
1100
|
-
const toggle2 = (column) => {
|
|
1101
|
-
const {
|
|
1102
|
-
props: {
|
|
1103
|
-
hiddenColumns: controlledHiddenColumns,
|
|
1104
|
-
onHiddenColumnsChange
|
|
1105
|
-
}
|
|
1106
|
-
} = table.getState();
|
|
1107
|
-
const newValue = new Set(hiddenColumns);
|
|
1108
|
-
if (hiddenColumns.has(column.id))
|
|
1109
|
-
newValue.delete(column.id);
|
|
1110
|
-
else
|
|
1111
|
-
newValue.add(column.id);
|
|
1112
|
-
if (!controlledHiddenColumns) {
|
|
1113
|
-
table.update((state) => {
|
|
1114
|
-
state.hiddenColumns = newValue;
|
|
1115
|
-
});
|
|
1116
|
-
}
|
|
1117
|
-
onHiddenColumnsChange == null ? void 0 : onHiddenColumnsChange(newValue);
|
|
1118
|
-
};
|
|
1119
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1120
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx(IconButton2, {
|
|
1121
|
-
onClick: (e) => setAnchorEl(anchorEl ? null : e.currentTarget),
|
|
1122
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(Settings2, {})
|
|
1123
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(Popover, {
|
|
1124
|
-
anchorEl,
|
|
1125
|
-
open: !!anchorEl,
|
|
1126
|
-
onClose: () => setAnchorEl(null),
|
|
1127
|
-
css: cssVariables,
|
|
1128
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
1129
|
-
css: {
|
|
1130
|
-
padding: `calc(var(--spacing) * 2)`,
|
|
1131
|
-
display: "grid"
|
|
1132
|
-
},
|
|
1133
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1134
|
-
css: {
|
|
1135
|
-
marginBottom: "var(--spacing)"
|
|
1136
|
-
},
|
|
1137
|
-
children: selectColumns
|
|
1138
|
-
}), columns.map((column) => /* @__PURE__ */ jsxRuntime.jsx(FormControlLabel, {
|
|
1139
|
-
control: /* @__PURE__ */ jsxRuntime.jsx(Checkbox2, {
|
|
1140
|
-
checked: !hiddenColumns.has(column.id),
|
|
1141
|
-
onChange: () => toggle2(column),
|
|
1142
|
-
disabled: column.cannotHide
|
|
1143
|
-
}),
|
|
1144
|
-
label: column.header
|
|
1145
|
-
}, column.id))]
|
|
1146
|
-
})
|
|
1147
|
-
})]
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
function csvExport(data, { sepPrefix, separator = ",", quote = '"', eol = "\n" } = {}) {
|
|
1151
|
-
const cells = data.map((line) => line.map((value) => {
|
|
1152
|
-
if (typeof value === "number")
|
|
1153
|
-
return String(value);
|
|
1154
|
-
if (![separator, quote, eol].some((c) => value.includes(c)))
|
|
1155
|
-
return value;
|
|
1156
|
-
const clean = value.replace(new RegExp(quote, "g"), `${quote}${quote}`);
|
|
1157
|
-
return `${quote}${clean}${quote}`;
|
|
1158
|
-
}));
|
|
1159
|
-
return (sepPrefix ? `SEP=${separator}
|
|
1160
|
-
` : "") + cells.map((line) => line.join(separator)).join(eol);
|
|
1161
|
-
}
|
|
1162
|
-
function Export$1() {
|
|
1163
|
-
const table = useTableContext();
|
|
1164
|
-
const Button2 = useTheme((t) => t.components.Button);
|
|
1165
|
-
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
1166
|
-
const Popover = useTheme((t) => t.components.Popover);
|
|
1167
|
-
const Export2 = useTheme((t) => t.icons.Export);
|
|
1168
|
-
const Clipboard2 = useTheme((t) => t.icons.Clipboard);
|
|
1169
|
-
const exportTitle = useTheme((t) => t.text.exportTitle);
|
|
1170
|
-
const exportCopy = useTheme((t) => t.text.exportCopy);
|
|
1171
|
-
const exportDownload = useTheme((t) => t.text.exportDownload);
|
|
1172
|
-
const cssVariables = useCssVariables();
|
|
1173
|
-
const [anchor, setAnchor] = react.useState(null);
|
|
1174
|
-
const generate = (options) => {
|
|
1175
|
-
const {
|
|
1176
|
-
activeColumns,
|
|
1177
|
-
activeItems
|
|
1178
|
-
} = table.getState();
|
|
1179
|
-
const data = [activeColumns.map((column) => String(column.id)), ...activeItems.map((item) => activeColumns.map((column) => column.exportCell(column.value(item.value), item.value)))];
|
|
1180
|
-
return csvExport(data, options);
|
|
1181
|
-
};
|
|
1182
|
-
const copy = () => {
|
|
1183
|
-
navigator.clipboard.writeText(generate(table.getState().props.enableExport.copy));
|
|
1184
|
-
};
|
|
1185
|
-
const download = () => {
|
|
1186
|
-
const a = document.createElement("a");
|
|
1187
|
-
a.href = "data:text/csv;charset=utf-8," + encodeURIComponent(generate(table.getState().props.enableExport.download));
|
|
1188
|
-
a.download = "export.csv";
|
|
1189
|
-
document.body.appendChild(a);
|
|
1190
|
-
a.click();
|
|
1191
|
-
document.body.removeChild(a);
|
|
1192
|
-
};
|
|
1193
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1194
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx(IconButton2, {
|
|
1195
|
-
onClick: (e) => setAnchor(anchor ? null : e.currentTarget),
|
|
1196
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(Export2, {
|
|
1197
|
-
css: !!anchor && {
|
|
1198
|
-
color: "var(--primaryMain)"
|
|
1199
|
-
}
|
|
1200
|
-
})
|
|
1201
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(Popover, {
|
|
1202
|
-
open: !!anchor,
|
|
1203
|
-
onClose: () => setAnchor(null),
|
|
1204
|
-
anchorEl: anchor,
|
|
1205
|
-
css: cssVariables,
|
|
1206
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
1207
|
-
css: {
|
|
1208
|
-
padding: `calc(var(--spacing) * 2)`,
|
|
1209
|
-
display: "grid",
|
|
1210
|
-
justifyItems: "stretch",
|
|
1211
|
-
gap: "var(--spacing)",
|
|
1212
|
-
"& > *": {
|
|
1213
|
-
justifyContent: "start"
|
|
1214
|
-
}
|
|
1215
|
-
},
|
|
1216
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1217
|
-
css: {
|
|
1218
|
-
marginBottom: "var(--spacing)"
|
|
1219
|
-
},
|
|
1220
|
-
children: exportTitle
|
|
1221
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(Button2, {
|
|
1222
|
-
startIcon: /* @__PURE__ */ jsxRuntime.jsx(Clipboard2, {}),
|
|
1223
|
-
onClick: copy,
|
|
1224
|
-
children: exportCopy
|
|
1225
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(Button2, {
|
|
1226
|
-
startIcon: /* @__PURE__ */ jsxRuntime.jsx(Export2, {}),
|
|
1227
|
-
onClick: download,
|
|
1228
|
-
children: exportDownload
|
|
1229
|
-
})]
|
|
1230
|
-
})
|
|
1231
|
-
})]
|
|
1232
|
-
});
|
|
1233
|
-
}
|
|
1234
|
-
const defaultWrapCell = (content) => {
|
|
1235
|
-
if (typeof content === "string") {
|
|
1236
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
1237
|
-
css: tableTheme.defaultClasses.text,
|
|
1238
|
-
title: content,
|
|
1239
|
-
children: content
|
|
1240
|
-
});
|
|
1241
|
-
}
|
|
1242
|
-
return content;
|
|
1243
|
-
};
|
|
1244
|
-
const Cell = react.memo(function Cell2({
|
|
1245
|
-
itemId,
|
|
1246
|
-
rowIndex
|
|
1247
|
-
}) {
|
|
1248
|
-
var _a;
|
|
1249
|
-
const table = useTableContext();
|
|
1250
|
-
const columnId = useColumnContext();
|
|
1251
|
-
const column = table.useState((state) => {
|
|
1252
|
-
const col = state.activeColumns.find((column2) => column2.id === columnId);
|
|
1253
|
-
return col && {
|
|
1254
|
-
value: col.value,
|
|
1255
|
-
renderCell: col.renderCell
|
|
1256
|
-
};
|
|
1257
|
-
});
|
|
1258
|
-
const wrapCell = (_a = table.useState((state) => state.props.wrapCell)) != null ? _a : defaultWrapCell;
|
|
1259
|
-
const item = table.useState((state) => state.activeItemsById.get(itemId));
|
|
1260
|
-
const columnStyleOverride = table.useState((state) => state.columnStyleOverride.get(columnId), {
|
|
1261
|
-
throttle: 16
|
|
1262
|
-
});
|
|
1263
|
-
react.useLayoutEffect(() => {
|
|
1264
|
-
var _a2, _b;
|
|
1265
|
-
return (_b = (_a2 = table.getState().props).debugRender) == null ? void 0 : _b.call(_a2, "render cell", itemId, columnId);
|
|
1266
|
-
});
|
|
1267
|
-
const className2 = useTheme((t) => cx(...calcClassNames(t.classes, item, rowIndex)));
|
|
1268
|
-
if (!column || !item)
|
|
1269
|
-
return null;
|
|
1270
|
-
const content = column.renderCell(column.value(item.value), item.value);
|
|
1271
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1272
|
-
className: className2,
|
|
1273
|
-
css: [tableTheme.defaultClasses.cell, columnStyleOverride],
|
|
1274
|
-
children: wrapCell(content, column.value(item.value), item.value, rowIndex)
|
|
1275
|
-
});
|
|
1276
|
-
});
|
|
1277
|
-
function ExpandControl({
|
|
1278
|
-
itemId,
|
|
1279
|
-
hasDeferredChildren
|
|
1280
|
-
}) {
|
|
1281
|
-
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
1282
|
-
const Spinner2 = useTheme((t) => t.components.Spinner);
|
|
1283
|
-
const ChevronRight2 = useTheme((t) => t.icons.ChevronRight);
|
|
1284
|
-
const table = useTableContext();
|
|
1285
|
-
const isExpanded = table.useState((state) => state.expanded.has(itemId));
|
|
1286
|
-
const hasChildren = table.useState((state) => {
|
|
1287
|
-
var _a;
|
|
1288
|
-
return !!((_a = state.activeItemsById.get(itemId)) == null ? void 0 : _a.children.length);
|
|
1289
|
-
});
|
|
1290
|
-
function toggle2() {
|
|
1291
|
-
const {
|
|
1292
|
-
props: {
|
|
1293
|
-
expanded: controlledExpanded,
|
|
1294
|
-
expandOnlyOne,
|
|
1295
|
-
onExpandedChange
|
|
1296
|
-
},
|
|
1297
|
-
expanded,
|
|
1298
|
-
activeItemsById
|
|
1299
|
-
} = table.getState();
|
|
1300
|
-
const newExpanded = new Set(expanded);
|
|
1301
|
-
if (expandOnlyOne) {
|
|
1302
|
-
newExpanded.clear();
|
|
1303
|
-
const item = activeItemsById.get(itemId);
|
|
1304
|
-
for (const ancestor of item ? getAncestors(activeItemsById, item) : []) {
|
|
1305
|
-
newExpanded.add(ancestor);
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
if (isExpanded) {
|
|
1309
|
-
newExpanded.delete(itemId);
|
|
1310
|
-
} else {
|
|
1311
|
-
newExpanded.add(itemId);
|
|
1312
|
-
}
|
|
1313
|
-
onExpandedChange == null ? void 0 : onExpandedChange(newExpanded);
|
|
1314
|
-
if (!controlledExpanded) {
|
|
1315
|
-
table.update((state) => {
|
|
1316
|
-
state.expanded = newExpanded;
|
|
1317
|
-
});
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
if (isExpanded && hasDeferredChildren && !hasChildren) {
|
|
1321
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Spinner2, {
|
|
1322
|
-
css: {
|
|
1323
|
-
margin: "0 var(--spacing)"
|
|
1324
|
-
}
|
|
1325
|
-
});
|
|
1326
|
-
}
|
|
1327
|
-
return /* @__PURE__ */ jsxRuntime.jsx(IconButton2, {
|
|
1328
|
-
onClick: toggle2,
|
|
1329
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
1330
|
-
css: {
|
|
1331
|
-
display: "inline-flex",
|
|
1332
|
-
transition: "all 300ms",
|
|
1333
|
-
transform: isExpanded ? "rotate3d(0, 0, 1, 90deg)" : "rotate3d(0, 0, 1, 0deg)"
|
|
1334
|
-
},
|
|
1335
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ChevronRight2, {})
|
|
1336
|
-
})
|
|
1337
|
-
});
|
|
1338
|
-
}
|
|
1339
|
-
function SelectComponent({
|
|
1340
|
-
itemId
|
|
1341
|
-
}) {
|
|
1342
|
-
const table = useTableContext();
|
|
1343
|
-
const Checkbox2 = useTheme((t) => t.components.Checkbox);
|
|
1344
|
-
const isSelected = table.useState((state) => {
|
|
1345
|
-
const itemIds = itemId ? [itemId] : Array.from(state.activeItemsById.keys());
|
|
1346
|
-
return state.activeItemsById.size > 0 && itemIds.every((itemId2) => state.selection.has(itemId2));
|
|
1347
|
-
});
|
|
1348
|
-
function toggle2(e) {
|
|
1349
|
-
const mouseEvent = e.nativeEvent;
|
|
1350
|
-
const {
|
|
1351
|
-
activeItems,
|
|
1352
|
-
activeItemsById,
|
|
1353
|
-
lastSelectedId,
|
|
1354
|
-
selection,
|
|
1355
|
-
props: {
|
|
1356
|
-
selectSyncChildren,
|
|
1357
|
-
selection: controlledSelection,
|
|
1358
|
-
onSelectionChange
|
|
1359
|
-
}
|
|
1360
|
-
} = table.getState();
|
|
1361
|
-
let range;
|
|
1362
|
-
if (mouseEvent.shiftKey && itemId) {
|
|
1363
|
-
const a = lastSelectedId ? activeItems.findIndex((i) => lastSelectedId === i.id) : 0;
|
|
1364
|
-
const b = activeItems.findIndex((item) => item.id === itemId);
|
|
1365
|
-
range = activeItems.slice(Math.min(a, b), Math.max(a, b) + 1);
|
|
1366
|
-
} else {
|
|
1367
|
-
const item = itemId ? activeItemsById.get(itemId) : void 0;
|
|
1368
|
-
range = item ? [item] : activeItems;
|
|
1369
|
-
}
|
|
1370
|
-
const newSelection = new Set(selection);
|
|
1371
|
-
for (const item of range) {
|
|
1372
|
-
if (isSelected)
|
|
1373
|
-
newSelection.delete(item.id);
|
|
1374
|
-
else
|
|
1375
|
-
newSelection.add(item.id);
|
|
1376
|
-
}
|
|
1377
|
-
if (selectSyncChildren && isSelected) {
|
|
1378
|
-
for (const ancestor of getAncestors(activeItemsById, ...range)) {
|
|
1379
|
-
newSelection.delete(ancestor);
|
|
1380
|
-
}
|
|
1381
|
-
for (const descendant of getDescendants(...range)) {
|
|
1382
|
-
newSelection.delete(descendant);
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
onSelectionChange == null ? void 0 : onSelectionChange(newSelection);
|
|
1386
|
-
if (!controlledSelection) {
|
|
1387
|
-
table.update((state) => {
|
|
1388
|
-
state.selection = newSelection;
|
|
1389
|
-
});
|
|
1390
|
-
}
|
|
1391
|
-
table.update((state) => {
|
|
1392
|
-
state.lastSelectedId = itemId;
|
|
1393
|
-
});
|
|
1394
|
-
}
|
|
1395
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Checkbox2, {
|
|
1396
|
-
css: {
|
|
1397
|
-
justifySelf: "start",
|
|
1398
|
-
color: "#c9cfda"
|
|
1399
|
-
},
|
|
1400
|
-
checked: isSelected,
|
|
1401
|
-
onChange: toggle2
|
|
1402
|
-
});
|
|
1403
|
-
}
|
|
1404
|
-
function calcClassNames(classes, item, index) {
|
|
1405
|
-
return [(classes == null ? void 0 : classes.cell) instanceof Function ? classes.cell(item, index) : classes == null ? void 0 : classes.cell, index % 2 === 0 && (classes == null ? void 0 : classes.evenCell), index % 2 === 1 && (classes == null ? void 0 : classes.oddCell)];
|
|
1406
|
-
}
|
|
1407
|
-
const Row = react.memo(function Row2({
|
|
1408
|
-
itemId,
|
|
1409
|
-
rowIndex
|
|
1410
|
-
}) {
|
|
1411
|
-
const table = useTableContext();
|
|
1412
|
-
const divRef = react.useRef(null);
|
|
1413
|
-
const classes = useTheme((t) => t.classes);
|
|
1414
|
-
const {
|
|
1415
|
-
className: className2,
|
|
1416
|
-
indent,
|
|
1417
|
-
hasChildren,
|
|
1418
|
-
hasDeferredChildren,
|
|
1419
|
-
columnIds,
|
|
1420
|
-
enableSelection,
|
|
1421
|
-
rowAction
|
|
1422
|
-
} = table.useState((state) => {
|
|
1423
|
-
var _a, _b;
|
|
1424
|
-
const item = state.activeItemsById.get(itemId);
|
|
1425
|
-
return {
|
|
1426
|
-
className: cx(...calcClassNames(classes, item, rowIndex)),
|
|
1427
|
-
indent: item ? getAncestors(state.activeItemsById, item).size : 0,
|
|
1428
|
-
hasChildren: !!(item == null ? void 0 : item.children.length),
|
|
1429
|
-
hasDeferredChildren: item && ((_b = (_a = state.props).hasDeferredChildren) == null ? void 0 : _b.call(_a, item.value)),
|
|
1430
|
-
columnIds: state.activeColumns.map((column) => column.id),
|
|
1431
|
-
enableSelection: state.props.enableSelection,
|
|
1432
|
-
rowAction: state.props.rowAction instanceof Function ? item ? state.props.rowAction(item.value, rowIndex) : null : state.props.rowAction
|
|
1433
|
-
};
|
|
1434
|
-
});
|
|
1435
|
-
react.useEffect(() => {
|
|
1436
|
-
const div = divRef.current;
|
|
1437
|
-
if (!div)
|
|
1438
|
-
return;
|
|
1439
|
-
const o = new ResizeObserver(() => {
|
|
1440
|
-
if (!document.contains(div))
|
|
1441
|
-
return;
|
|
1442
|
-
table.update((state) => {
|
|
1443
|
-
state.rowHeights.set(itemId, div.offsetHeight);
|
|
1444
|
-
});
|
|
1445
|
-
});
|
|
1446
|
-
o.observe(div);
|
|
1447
|
-
return () => o.disconnect();
|
|
1448
|
-
}, [divRef.current]);
|
|
1449
|
-
react.useLayoutEffect(() => {
|
|
1450
|
-
var _a, _b;
|
|
1451
|
-
return (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render row", itemId);
|
|
1452
|
-
});
|
|
1453
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1454
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1455
|
-
className: className2,
|
|
1456
|
-
css: [tableTheme.defaultClasses.cellFill],
|
|
1457
|
-
ref: divRef
|
|
1458
|
-
}), /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
1459
|
-
className: className2,
|
|
1460
|
-
css: [tableTheme.defaultClasses.cell, tableTheme.defaultClasses.firstCell],
|
|
1461
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1462
|
-
css: {
|
|
1463
|
-
width: indent * 20
|
|
1464
|
-
}
|
|
1465
|
-
}), enableSelection && /* @__PURE__ */ jsxRuntime.jsx(SelectComponent, {
|
|
1466
|
-
itemId
|
|
1467
|
-
}), (hasChildren || hasDeferredChildren) && /* @__PURE__ */ jsxRuntime.jsx(ExpandControl, {
|
|
1468
|
-
itemId,
|
|
1469
|
-
hasDeferredChildren
|
|
1470
|
-
}), rowAction]
|
|
1471
|
-
}), columnIds.map((columnId) => /* @__PURE__ */ jsxRuntime.jsx(ColumnContext.Provider, {
|
|
1472
|
-
value: columnId,
|
|
1473
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(Cell, {
|
|
1474
|
-
itemId,
|
|
1475
|
-
rowIndex
|
|
1476
|
-
})
|
|
1477
|
-
}, columnId)), /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1478
|
-
className: className2,
|
|
1479
|
-
css: [tableTheme.defaultClasses.cellFill]
|
|
1480
|
-
})]
|
|
1481
|
-
});
|
|
1482
|
-
});
|
|
1483
|
-
function throttle(fn, ms) {
|
|
1484
|
-
let last = 0;
|
|
1485
|
-
let lastArgs;
|
|
1486
|
-
let timeout;
|
|
1487
|
-
function run() {
|
|
1488
|
-
const args = lastArgs;
|
|
1489
|
-
last = Date.now();
|
|
1490
|
-
lastArgs = void 0;
|
|
1491
|
-
timeout = void 0;
|
|
1492
|
-
fn(...args);
|
|
1493
|
-
}
|
|
1494
|
-
return Object.assign(function(...args) {
|
|
1495
|
-
const now = Date.now();
|
|
1496
|
-
lastArgs = args;
|
|
1497
|
-
if (timeout)
|
|
1498
|
-
;
|
|
1499
|
-
else if (now < last + ms) {
|
|
1500
|
-
timeout = setTimeout(run, last + ms - now);
|
|
1501
|
-
} else {
|
|
1502
|
-
run();
|
|
1503
|
-
}
|
|
1504
|
-
}, {
|
|
1505
|
-
flush() {
|
|
1506
|
-
if (lastArgs) {
|
|
1507
|
-
run();
|
|
1508
|
-
}
|
|
1509
|
-
},
|
|
1510
|
-
cancel() {
|
|
1511
|
-
if (timeout) {
|
|
1512
|
-
clearTimeout(timeout);
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
});
|
|
1516
|
-
}
|
|
1517
|
-
const findScrollRoot = (x) => {
|
|
1518
|
-
const parent = x.parentElement;
|
|
1519
|
-
if (!parent)
|
|
1520
|
-
return document.documentElement;
|
|
1521
|
-
if (parent.scrollHeight > parent.clientHeight && getComputedStyle(parent).overflowY !== "visible")
|
|
1522
|
-
return parent;
|
|
1523
|
-
return findScrollRoot(parent);
|
|
1524
|
-
};
|
|
1525
|
-
const relativeOffset = (x, y) => {
|
|
1526
|
-
if (x.offsetParent === y.offsetParent || !x.offsetParent)
|
|
1527
|
-
return x.offsetTop - y.offsetTop;
|
|
1528
|
-
if (x.offsetParent instanceof HTMLElement)
|
|
1529
|
-
return relativeOffset(x.offsetParent, y) + x.offsetTop;
|
|
1530
|
-
return 0;
|
|
1531
|
-
};
|
|
1532
|
-
function Virtualized(_c) {
|
|
1533
|
-
var _d = _c, {
|
|
1534
|
-
header,
|
|
1535
|
-
footer,
|
|
1536
|
-
children
|
|
1537
|
-
} = _d, props = __objRest(_d, [
|
|
1538
|
-
"header",
|
|
1539
|
-
"footer",
|
|
1540
|
-
"children"
|
|
1541
|
-
]);
|
|
1542
|
-
var _a, _b;
|
|
1543
|
-
const table = useTableContext();
|
|
1544
|
-
const virtual = table.useState("props.virtual");
|
|
1545
|
-
const probeRef = react.useRef(null);
|
|
1546
|
-
const [, setCounter] = react.useState(0);
|
|
1547
|
-
const {
|
|
1548
|
-
itemIds = [],
|
|
1549
|
-
from = 0,
|
|
1550
|
-
to,
|
|
1551
|
-
before = 0,
|
|
1552
|
-
after = 0
|
|
1553
|
-
} = table.useState((state) => {
|
|
1554
|
-
var _a2;
|
|
1555
|
-
const itemIds2 = state.activeItems.map((item) => item.id);
|
|
1556
|
-
const root = probeRef.current && findScrollRoot(probeRef.current);
|
|
1557
|
-
if (!state.props.virtual)
|
|
1558
|
-
return {
|
|
1559
|
-
itemIds: itemIds2
|
|
1560
|
-
};
|
|
1561
|
-
if (!probeRef.current || !root || !document.contains(root))
|
|
1562
|
-
return {};
|
|
1563
|
-
const {
|
|
1564
|
-
rowHeight,
|
|
1565
|
-
initalRowHeight,
|
|
1566
|
-
overscan = 100,
|
|
1567
|
-
overscanTop,
|
|
1568
|
-
overscanBottom
|
|
1569
|
-
} = (_a2 = state.props.virtual instanceof Object ? state.props.virtual : void 0) != null ? _a2 : {};
|
|
1570
|
-
let totalHeight = 0;
|
|
1571
|
-
const rowHeights = itemIds2.map((itemId, index) => {
|
|
1572
|
-
var _a3, _b2;
|
|
1573
|
-
const h = (_b2 = (_a3 = rowHeight != null ? rowHeight : state.rowHeights.get(itemId)) != null ? _a3 : initalRowHeight) != null ? _b2 : index === 0 ? 100 : totalHeight / index;
|
|
1574
|
-
totalHeight += h;
|
|
1575
|
-
return h;
|
|
1576
|
-
});
|
|
1577
|
-
const probeOffset = relativeOffset(probeRef.current, root);
|
|
1578
|
-
const headerHeight = probeRef.current.offsetTop;
|
|
1579
|
-
const topOfTable = root.scrollTop - probeOffset + headerHeight;
|
|
1580
|
-
const bottomOfTable = topOfTable + root.clientHeight - headerHeight;
|
|
1581
|
-
let from2 = 0, to2 = itemIds2.length, before2 = 0, after2 = 0;
|
|
1582
|
-
for (const h of rowHeights) {
|
|
1583
|
-
if (before2 + h > topOfTable - (overscanTop != null ? overscanTop : overscan))
|
|
1584
|
-
break;
|
|
1585
|
-
from2++;
|
|
1586
|
-
before2 += h;
|
|
1587
|
-
}
|
|
1588
|
-
for (const h of rowHeights.reverse()) {
|
|
1589
|
-
if (after2 + h > totalHeight - bottomOfTable - (overscanBottom != null ? overscanBottom : overscan))
|
|
1590
|
-
break;
|
|
1591
|
-
to2--;
|
|
1592
|
-
after2 += h;
|
|
1593
|
-
}
|
|
1594
|
-
return {
|
|
1595
|
-
itemIds: itemIds2.slice(from2, to2),
|
|
1596
|
-
from: from2,
|
|
1597
|
-
to: to2,
|
|
1598
|
-
before: before2,
|
|
1599
|
-
after: after2
|
|
1600
|
-
};
|
|
1601
|
-
}, {
|
|
1602
|
-
throttle: 16
|
|
1603
|
-
});
|
|
1604
|
-
const throttleScroll = (_b = (_a = typeof virtual === "boolean" ? void 0 : virtual) == null ? void 0 : _a.throttleScroll) != null ? _b : 16;
|
|
1605
|
-
const incCounter = react.useMemo(() => throttle(() => setCounter((c) => c + 1), throttleScroll), [throttleScroll]);
|
|
1606
|
-
react.useEffect(() => {
|
|
1607
|
-
if (!virtual || !probeRef.current)
|
|
1608
|
-
return;
|
|
1609
|
-
window.addEventListener("scroll", incCounter, true);
|
|
1610
|
-
window.addEventListener("resize", incCounter, true);
|
|
1611
|
-
return () => {
|
|
1612
|
-
window.removeEventListener("scroll", incCounter, true);
|
|
1613
|
-
window.removeEventListener("resize", incCounter, true);
|
|
1614
|
-
};
|
|
1615
|
-
}, [probeRef.current, incCounter]);
|
|
1616
|
-
react.useEffect(() => incCounter.cancel, [incCounter]);
|
|
1617
|
-
react.useLayoutEffect(() => {
|
|
1618
|
-
var _a2, _b2;
|
|
1619
|
-
return (_b2 = (_a2 = table.getState().props).debugRender) == null ? void 0 : _b2.call(_a2, `Virtualalized render ${from} to ${to}`);
|
|
1620
|
-
});
|
|
1621
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", __spreadProps(__spreadValues({}, props), {
|
|
1622
|
-
children: [header, virtual && /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1623
|
-
style: {
|
|
1624
|
-
gridColumn: "1 / -1",
|
|
1625
|
-
height: before
|
|
1626
|
-
},
|
|
1627
|
-
ref: probeRef
|
|
1628
|
-
}), children(itemIds, from), virtual && /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1629
|
-
style: {
|
|
1630
|
-
gridColumn: "1 / -1",
|
|
1631
|
-
height: after
|
|
1632
|
-
}
|
|
1633
|
-
}), footer]
|
|
1634
|
-
}));
|
|
1635
|
-
}
|
|
1636
|
-
const TableContext = react.createContext(null);
|
|
1637
|
-
const ColumnContext = react.createContext(null);
|
|
1638
|
-
function useTableContext() {
|
|
1639
|
-
const value = react.useContext(TableContext);
|
|
1640
|
-
if (!value)
|
|
1641
|
-
throw Error("No table context available");
|
|
1642
|
-
return value;
|
|
1643
|
-
}
|
|
1644
|
-
function useColumnContext() {
|
|
1645
|
-
const value = react.useContext(ColumnContext);
|
|
1646
|
-
if (value === null)
|
|
1647
|
-
throw Error("No column context available");
|
|
1648
|
-
return value;
|
|
1649
|
-
}
|
|
1650
|
-
function Table(props) {
|
|
1651
|
-
const table = useTableState(props);
|
|
1652
|
-
react.useLayoutEffect(() => {
|
|
1653
|
-
var _a, _b;
|
|
1654
|
-
return (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table");
|
|
1655
|
-
});
|
|
1656
|
-
return /* @__PURE__ */ jsxRuntime.jsx(TableContext.Provider, {
|
|
1657
|
-
value: table,
|
|
1658
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(TableMemoContextProvider, {
|
|
1659
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(TableLoadingState, {})
|
|
1660
|
-
})
|
|
1661
|
-
});
|
|
1662
|
-
}
|
|
1663
|
-
function TableLoadingState() {
|
|
1664
|
-
const loadingText = useTheme((t) => t.text.loading);
|
|
1665
|
-
const isHydrated = useTableStateStorage();
|
|
1666
|
-
const [showLoading, setShowLoading] = react.useState(false);
|
|
1667
|
-
react.useEffect(() => {
|
|
1668
|
-
const handle = setTimeout(() => setShowLoading(true), 500);
|
|
1669
|
-
return () => clearTimeout(handle);
|
|
1670
|
-
});
|
|
1671
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1672
|
-
children: [!isHydrated && showLoading && /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1673
|
-
children: loadingText
|
|
1674
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(TableInner, {
|
|
1675
|
-
hidden: !isHydrated
|
|
1676
|
-
})]
|
|
1677
|
-
});
|
|
1678
|
-
}
|
|
1679
|
-
const TableInner = react.memo(function TableInner2({
|
|
1680
|
-
hidden
|
|
1681
|
-
}) {
|
|
1682
|
-
const table = useTableContext();
|
|
1683
|
-
const fullWidth = table.useState("props.fullWidth");
|
|
1684
|
-
const activeColumns = table.useState((state) => state.activeColumns.map((column) => ({
|
|
1685
|
-
id: column.id,
|
|
1686
|
-
width: column.width,
|
|
1687
|
-
classes: column.classes
|
|
1688
|
-
})));
|
|
1689
|
-
const hasActiveFilters = table.useState((state) => {
|
|
1690
|
-
return state.activeColumns.some((column) => {
|
|
1691
|
-
const filter = state.filters.get(column.id);
|
|
1692
|
-
const filterValue = state.filterValues.get(column.id);
|
|
1693
|
-
return filter !== void 0 && filterValue !== void 0 && filter.isActive(filterValue);
|
|
1694
|
-
});
|
|
1695
|
-
});
|
|
1696
|
-
const columnWidths = table.useState("columnWidths", {
|
|
1697
|
-
throttle: 16
|
|
1698
|
-
});
|
|
1699
|
-
const hasFooter = table.useState((state) => state.activeColumns.some((column) => column.footer));
|
|
1700
|
-
const classes = useTheme((theme) => theme.classes);
|
|
1701
|
-
const stickyHeader = table.useState("props.stickyHeader");
|
|
1702
|
-
const stickyFooter = table.useState("props.stickyFooter");
|
|
1703
|
-
const enableSelection = table.useState("props.enableSelection");
|
|
1704
|
-
const enableColumnSelection = table.useState("props.enableColumnSelection");
|
|
1705
|
-
const enableExport = table.useState((state) => !!state.props.enableExport.copy || !!state.props.enableExport.download);
|
|
1706
|
-
const cssVariables = useCssVariables();
|
|
1707
|
-
const enableClearFiltersButton = table.useState("props.enableClearFiltersButton");
|
|
1708
|
-
react.useLayoutEffect(() => {
|
|
1709
|
-
var _a, _b;
|
|
1710
|
-
return (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table inner");
|
|
1711
|
-
});
|
|
1712
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Virtualized, {
|
|
1713
|
-
className: classes == null ? void 0 : classes.table,
|
|
1714
|
-
css: [cssVariables, tableTheme.defaultClasses.table, {
|
|
1715
|
-
gridTemplateColumns: [
|
|
1716
|
-
fullWidth === "right" || fullWidth === true ? "auto" : "0",
|
|
1717
|
-
"max-content",
|
|
1718
|
-
...activeColumns.map((column) => {
|
|
1719
|
-
var _a, _b;
|
|
1720
|
-
return (_b = (_a = columnWidths.get(column.id)) != null ? _a : column.width) != null ? _b : "max-content";
|
|
1721
|
-
}),
|
|
1722
|
-
fullWidth === "left" || fullWidth === true ? "auto" : "0"
|
|
1723
|
-
].join(" ")
|
|
1724
|
-
}, hidden && {
|
|
1725
|
-
visibility: "hidden"
|
|
1726
|
-
}],
|
|
1727
|
-
header: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1728
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1729
|
-
className: classes == null ? void 0 : classes.headerCell,
|
|
1730
|
-
css: [tableTheme.defaultClasses.headerFill, stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
|
|
1731
|
-
}), /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
1732
|
-
className: classes == null ? void 0 : classes.headerCell,
|
|
1733
|
-
css: [tableTheme.defaultClasses.headerCell, stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
|
|
1734
|
-
children: [enableSelection && /* @__PURE__ */ jsxRuntime.jsx(SelectComponent, {}), enableColumnSelection && /* @__PURE__ */ jsxRuntime.jsx(ColumnSelection, {}), enableExport && /* @__PURE__ */ jsxRuntime.jsx(Export$1, {}), /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1735
|
-
css: {
|
|
1736
|
-
flex: 1
|
|
1737
|
-
}
|
|
1738
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(ResizeHandleView, {})]
|
|
1739
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(ColumnHeaderContext.Provider, {
|
|
1740
|
-
children: activeColumns.map((column) => /* @__PURE__ */ jsxRuntime.jsx(ColumnContext.Provider, {
|
|
1741
|
-
value: column.id,
|
|
1742
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ColumnHeader, {})
|
|
1743
|
-
}, column.id))
|
|
1744
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1745
|
-
className: classes == null ? void 0 : classes.headerCell,
|
|
1746
|
-
css: [tableTheme.defaultClasses.headerFill, stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
|
|
1747
|
-
})]
|
|
1748
|
-
}),
|
|
1749
|
-
footer: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1750
|
-
children: [enableClearFiltersButton && hasActiveFilters && /* @__PURE__ */ jsxRuntime.jsx(ClearFiltersButton, {}), hasFooter && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1751
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1752
|
-
className: classes == null ? void 0 : classes.footerCell,
|
|
1753
|
-
css: [tableTheme.defaultClasses.footerFill, stickyFooter && tableTheme.defaultClasses.stickyBottom, stickyFooter instanceof Object && stickyFooter]
|
|
1754
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1755
|
-
className: classes == null ? void 0 : classes.footerCell,
|
|
1756
|
-
css: [tableTheme.defaultClasses.footerFill, stickyFooter && tableTheme.defaultClasses.stickyBottom, stickyFooter instanceof Object && stickyFooter]
|
|
1757
|
-
}), activeColumns.map((column) => /* @__PURE__ */ jsxRuntime.jsx(ColumnContext.Provider, {
|
|
1758
|
-
value: column.id,
|
|
1759
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ColumnFooter, {})
|
|
1760
|
-
}, column.id)), /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
1761
|
-
className: classes == null ? void 0 : classes.footerCell,
|
|
1762
|
-
css: [tableTheme.defaultClasses.footerFill, stickyFooter && tableTheme.defaultClasses.stickyBottom, stickyFooter instanceof Object && stickyFooter]
|
|
1763
|
-
})]
|
|
1764
|
-
})]
|
|
1765
|
-
}),
|
|
1766
|
-
children: (itemIds, startIndex) => itemIds.map((itemId, index) => /* @__PURE__ */ jsxRuntime.jsx(Row, {
|
|
1767
|
-
itemId,
|
|
1768
|
-
rowIndex: startIndex + index
|
|
1769
|
-
}, itemId))
|
|
1770
|
-
});
|
|
1771
|
-
});
|
|
1772
|
-
const defaultColors = {
|
|
1773
|
-
primary: { main: "#1976d2", light: "#42a5f5", contrastText: "#fff" },
|
|
1774
|
-
secondary: { main: "#9c27b0", light: "#ba68c8", contrastText: "#fff" }
|
|
1775
|
-
};
|
|
1776
|
-
function Spinner({
|
|
1777
|
-
className: className2
|
|
1778
|
-
}) {
|
|
1779
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
1780
|
-
className: className2,
|
|
1781
|
-
css: react$2.css`
|
|
1782
|
-
display: inline-block;
|
|
1783
|
-
position: relative;
|
|
1784
|
-
width: 1em;
|
|
1785
|
-
height: 1em;
|
|
1786
|
-
|
|
1787
|
-
div {
|
|
1788
|
-
box-sizing: border-box;
|
|
1789
|
-
display: block;
|
|
1790
|
-
position: absolute;
|
|
1791
|
-
width: 0.8em;
|
|
1792
|
-
height: 0.8em;
|
|
1793
|
-
margin: 0.1em;
|
|
1794
|
-
border: 0.1em solid #fff;
|
|
1795
|
-
border-radius: 50%;
|
|
1796
|
-
animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
|
|
1797
|
-
border-color: currentColor transparent transparent transparent;
|
|
1798
|
-
}
|
|
1799
|
-
div:nth-of-type(1) {
|
|
1800
|
-
animation-delay: -0.45s;
|
|
1801
|
-
}
|
|
1802
|
-
div:nth-of-type(2) {
|
|
1803
|
-
animation-delay: -0.3s;
|
|
1804
|
-
}
|
|
1805
|
-
div:nth-of-type(3) {
|
|
1806
|
-
animation-delay: -0.15s;
|
|
1807
|
-
}
|
|
1808
|
-
@keyframes lds-ring {
|
|
1809
|
-
0% {
|
|
1810
|
-
transform: rotate(0deg);
|
|
1811
|
-
}
|
|
1812
|
-
100% {
|
|
1813
|
-
transform: rotate(360deg);
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
`,
|
|
1817
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("div", {}), /* @__PURE__ */ jsxRuntime.jsx("div", {}), /* @__PURE__ */ jsxRuntime.jsx("div", {})]
|
|
1818
|
-
});
|
|
1819
|
-
}
|
|
1820
|
-
const Badge = ({
|
|
1821
|
-
badgeContent,
|
|
1822
|
-
children
|
|
1823
|
-
}) => {
|
|
1824
|
-
if (!open)
|
|
1825
|
-
return null;
|
|
1826
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("span", {
|
|
1827
|
-
css: {
|
|
1828
|
-
display: "inline-flex",
|
|
1829
|
-
position: "relative",
|
|
1830
|
-
flexShrink: 0,
|
|
1831
|
-
verticalAlign: "middle"
|
|
1832
|
-
},
|
|
1833
|
-
children: [children, /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
1834
|
-
css: [{
|
|
1835
|
-
top: 0,
|
|
1836
|
-
right: 0,
|
|
1837
|
-
transform: "scale(1) translate(50%, -50%)",
|
|
1838
|
-
transformOrigin: "100% 0%",
|
|
1839
|
-
height: 20,
|
|
1840
|
-
display: "flex",
|
|
1841
|
-
padding: "0 6px",
|
|
1842
|
-
zIndex: 1,
|
|
1843
|
-
position: "absolute",
|
|
1844
|
-
flexWrap: "wrap",
|
|
1845
|
-
minWidth: 20,
|
|
1846
|
-
transition: "transform 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
|
|
1847
|
-
alignItems: "center",
|
|
1848
|
-
lineHeight: 1,
|
|
1849
|
-
alignContent: "center",
|
|
1850
|
-
borderRadius: 10,
|
|
1851
|
-
justifyContent: "center",
|
|
1852
|
-
fontSize: "0.8em"
|
|
1853
|
-
}, !badgeContent && {
|
|
1854
|
-
transform: "scale(0) translate(50%, -50%)",
|
|
1855
|
-
transition: "transform 195ms cubic-bezier(0.4, 0, 0.2, 1) 0ms"
|
|
1856
|
-
}],
|
|
1857
|
-
children: badgeContent
|
|
1858
|
-
})]
|
|
1859
|
-
});
|
|
1860
|
-
};
|
|
1861
|
-
const Button = (_e) => {
|
|
1862
|
-
var _f = _e, {
|
|
1863
|
-
startIcon,
|
|
1864
|
-
children,
|
|
1865
|
-
variant = "text"
|
|
1866
|
-
} = _f, props = __objRest(_f, [
|
|
1867
|
-
"startIcon",
|
|
1868
|
-
"children",
|
|
1869
|
-
"variant"
|
|
1870
|
-
]);
|
|
1871
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("button", __spreadProps(__spreadValues({
|
|
1872
|
-
css: [{
|
|
1873
|
-
padding: `var(--spacing) calc(var(--spacing) * 2)`,
|
|
1874
|
-
display: "inline-flex",
|
|
1875
|
-
alignItems: "center",
|
|
1876
|
-
transition: "background-color 150ms",
|
|
1877
|
-
border: "none",
|
|
1878
|
-
cursor: "pointer",
|
|
1879
|
-
background: "transparent",
|
|
1880
|
-
borderRadius: 4,
|
|
1881
|
-
"&:active:not(:disabled)": {
|
|
1882
|
-
transform: "scale3d(0.95, 0.95, 1)"
|
|
1883
|
-
}
|
|
1884
|
-
}, variant === "text" && {
|
|
1885
|
-
"&:hover": {
|
|
1886
|
-
background: "rgba(0, 0, 0, 0.1)"
|
|
1887
|
-
}
|
|
1888
|
-
}, variant === "outlined" && {
|
|
1889
|
-
border: `1px solid ${tableTheme.darkGray}`,
|
|
1890
|
-
"&:disabled": {
|
|
1891
|
-
borderColor: tableTheme.lightGray
|
|
1892
|
-
}
|
|
1893
|
-
}, variant === "contained" && {
|
|
1894
|
-
color: "var(--primaryContrastText)",
|
|
1895
|
-
backgroundColor: "var(--primaryMain)",
|
|
1896
|
-
boxShadow: "0px 3px 1px -2px rgb(0 0 0 / 20%), 0px 2px 2px 0px rgb(0 0 0 / 14%), 0px 1px 5px 0px rgb(0 0 0 / 12%)",
|
|
1897
|
-
"&:hover": {
|
|
1898
|
-
filter: "brightness(0.9)"
|
|
1899
|
-
},
|
|
1900
|
-
"&:disabled": {
|
|
1901
|
-
filter: "grayscale()",
|
|
1902
|
-
opacity: 0.5
|
|
1903
|
-
}
|
|
1904
|
-
}]
|
|
1905
|
-
}, props), {
|
|
1906
|
-
children: [startIcon && /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
1907
|
-
css: {
|
|
1908
|
-
marginRight: `calc(var(--spacing) * 2)`
|
|
1909
|
-
},
|
|
1910
|
-
children: startIcon
|
|
1911
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
1912
|
-
children
|
|
1913
|
-
})]
|
|
1914
|
-
}));
|
|
1915
|
-
};
|
|
1916
|
-
const Checkbox = (_g) => {
|
|
1917
|
-
var _h = _g, {
|
|
1918
|
-
className: className2
|
|
1919
|
-
} = _h, props = __objRest(_h, [
|
|
1920
|
-
"className"
|
|
1921
|
-
]);
|
|
1922
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("label", {
|
|
1923
|
-
css: [{
|
|
1924
|
-
padding: "calc(var(--spacing) * 1.8)",
|
|
1925
|
-
display: "flex",
|
|
1926
|
-
color: "currentcolor",
|
|
1927
|
-
userSelect: "none",
|
|
1928
|
-
"& input": {
|
|
1929
|
-
appearance: "none",
|
|
1930
|
-
margin: 0
|
|
1931
|
-
}
|
|
1932
|
-
}, props.disabled && {
|
|
1933
|
-
color: "rgba(0, 0, 0, 0.26)"
|
|
1934
|
-
}],
|
|
1935
|
-
className: className2,
|
|
1936
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("input", __spreadValues({
|
|
1937
|
-
type: "checkbox"
|
|
1938
|
-
}, props)), props.checked ? /* @__PURE__ */ jsxRuntime.jsx("svg", {
|
|
1939
|
-
css: {
|
|
1940
|
-
fontSize: "1.25rem",
|
|
1941
|
-
width: "1em",
|
|
1942
|
-
height: "1em",
|
|
1943
|
-
fill: "var(--primaryMain)"
|
|
1944
|
-
},
|
|
1945
|
-
focusable: "false",
|
|
1946
|
-
viewBox: "0 0 24 24",
|
|
1947
|
-
"aria-hidden": "true",
|
|
1948
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
1949
|
-
d: "M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
|
|
1950
|
-
})
|
|
1951
|
-
}) : /* @__PURE__ */ jsxRuntime.jsx("svg", {
|
|
1952
|
-
css: {
|
|
1953
|
-
fontSize: "1.25rem",
|
|
1954
|
-
width: "1em",
|
|
1955
|
-
height: "1em",
|
|
1956
|
-
fill: "currentColor"
|
|
1957
|
-
},
|
|
1958
|
-
focusable: "false",
|
|
1959
|
-
viewBox: "0 0 24 24",
|
|
1960
|
-
"aria-hidden": "true",
|
|
1961
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
1962
|
-
d: "M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"
|
|
1963
|
-
})
|
|
1964
|
-
})]
|
|
1965
|
-
});
|
|
1966
|
-
};
|
|
1967
|
-
const IconButton = (props) => {
|
|
1968
|
-
return /* @__PURE__ */ jsxRuntime.jsx("button", __spreadValues({
|
|
1969
|
-
css: {
|
|
1970
|
-
padding: "var(--spacing)",
|
|
1971
|
-
borderRadius: "50%",
|
|
1972
|
-
display: "inline-flex",
|
|
1973
|
-
justifyContent: "center",
|
|
1974
|
-
alignItems: "center",
|
|
1975
|
-
transition: "background-color 150ms",
|
|
1976
|
-
border: "none",
|
|
1977
|
-
cursor: "pointer",
|
|
1978
|
-
color: "inherit",
|
|
1979
|
-
background: "transparent",
|
|
1980
|
-
"&:hover": {
|
|
1981
|
-
backgroundColor: "rgba(0, 0, 0, 0.04)"
|
|
1982
|
-
},
|
|
1983
|
-
"&:active": {
|
|
1984
|
-
transformColor: "scale3d(0.95, 0.95, 1)"
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
}, props));
|
|
1988
|
-
};
|
|
1989
|
-
const TextField = (_i) => {
|
|
1990
|
-
var _j = _i, {
|
|
1991
|
-
endIcon,
|
|
1992
|
-
className: className2,
|
|
1993
|
-
inputRef
|
|
1994
|
-
} = _j, props = __objRest(_j, [
|
|
1995
|
-
"endIcon",
|
|
1996
|
-
"className",
|
|
1997
|
-
"inputRef"
|
|
1998
|
-
]);
|
|
1999
|
-
var _a;
|
|
2000
|
-
const [focus, setFocus] = react.useState(false);
|
|
2001
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
2002
|
-
className: className2,
|
|
2003
|
-
css: {
|
|
2004
|
-
display: "flex"
|
|
2005
|
-
},
|
|
2006
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("span", {
|
|
2007
|
-
css: [{
|
|
2008
|
-
flex: 1,
|
|
2009
|
-
display: "flex",
|
|
2010
|
-
alignItems: "center",
|
|
2011
|
-
border: `1px solid ${tableTheme.darkGray}`,
|
|
2012
|
-
borderRadius: 4
|
|
2013
|
-
}, focus && {
|
|
2014
|
-
border: "2px solid var(--primaryMain)",
|
|
2015
|
-
margin: -1
|
|
2016
|
-
}],
|
|
2017
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("input", __spreadProps(__spreadValues({
|
|
2018
|
-
ref: inputRef
|
|
2019
|
-
}, props), {
|
|
2020
|
-
value: (_a = props.value) != null ? _a : "",
|
|
2021
|
-
onFocus: () => setFocus(true),
|
|
2022
|
-
onBlur: () => setFocus(false),
|
|
2023
|
-
css: {
|
|
2024
|
-
flex: 1,
|
|
2025
|
-
border: "none",
|
|
2026
|
-
outline: "none",
|
|
2027
|
-
borderRadius: 4,
|
|
2028
|
-
padding: "calc(var(--spacing) * 2)",
|
|
2029
|
-
paddingRight: 0,
|
|
2030
|
-
transition: "outline 500ms"
|
|
2031
|
-
}
|
|
2032
|
-
})), endIcon]
|
|
2033
|
-
})
|
|
2034
|
-
});
|
|
2035
|
-
};
|
|
2036
|
-
const defaultComponents = {
|
|
2037
|
-
IconButton,
|
|
2038
|
-
Checkbox,
|
|
2039
|
-
Popover: tableTheme.Popover,
|
|
2040
|
-
Button,
|
|
2041
|
-
Badge,
|
|
2042
|
-
TextField,
|
|
2043
|
-
Spinner
|
|
2044
|
-
};
|
|
2045
|
-
const IconDefaultStyle = react$2.css({
|
|
2046
|
-
width: "1.5em",
|
|
2047
|
-
height: "1.5em",
|
|
2048
|
-
color: "inherit"
|
|
2049
|
-
});
|
|
2050
|
-
function Icon(svg) {
|
|
2051
|
-
return (props) => /* @__PURE__ */ jsxRuntime.jsx(react$2.ClassNames, {
|
|
2052
|
-
children: ({
|
|
2053
|
-
css: css2
|
|
2054
|
-
}) => react.cloneElement(svg, __spreadProps(__spreadValues({}, props), {
|
|
2055
|
-
className: css2(IconDefaultStyle, props.className)
|
|
2056
|
-
}))
|
|
2057
|
-
});
|
|
2058
|
-
}
|
|
2059
|
-
const Settings = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
|
|
2060
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2061
|
-
height: "24px",
|
|
2062
|
-
viewBox: "0 0 24 24",
|
|
2063
|
-
width: "24px",
|
|
2064
|
-
fill: "currentColor",
|
|
2065
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2066
|
-
d: "M0 0h24v24H0V0z",
|
|
2067
|
-
fill: "none"
|
|
2068
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2069
|
-
d: "M3 17v2h6v-2H3zM3 5v2h10V5H3zm10 16v-2h8v-2h-8v-2h-2v6h2zM7 9v2H3v2h4v2h2V9H7zm14 4v-2H11v2h10zm-6-4h2V7h4V5h-4V3h-2v6z"
|
|
2070
|
-
})]
|
|
2071
|
-
}));
|
|
2072
|
-
const Export = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
|
|
2073
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2074
|
-
enableBackground: "new 0 0 24 24",
|
|
2075
|
-
height: "24px",
|
|
2076
|
-
viewBox: "0 0 24 24",
|
|
2077
|
-
width: "24px",
|
|
2078
|
-
fill: "currentColor",
|
|
2079
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("g", {
|
|
2080
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("rect", {
|
|
2081
|
-
fill: "none",
|
|
2082
|
-
height: "24",
|
|
2083
|
-
width: "24"
|
|
2084
|
-
})
|
|
2085
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("g", {
|
|
2086
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2087
|
-
d: "M18,15v3H6v-3H4v3c0,1.1,0.9,2,2,2h12c1.1,0,2-0.9,2-2v-3H18z M17,11l-1.41-1.41L13,12.17V4h-2v8.17L8.41,9.59L7,11l5,5 L17,11z"
|
|
2088
|
-
})
|
|
2089
|
-
})]
|
|
2090
|
-
}));
|
|
2091
|
-
const Clipboard = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
|
|
2092
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2093
|
-
height: "24px",
|
|
2094
|
-
viewBox: "0 0 24 24",
|
|
2095
|
-
width: "24px",
|
|
2096
|
-
fill: "currentColor",
|
|
2097
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2098
|
-
d: "M0 0h24v24H0V0z",
|
|
2099
|
-
fill: "none"
|
|
2100
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2101
|
-
d: "M19 2h-4.18C14.4.84 13.3 0 12 0S9.6.84 9.18 2H5c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm7 18H5V4h2v3h10V4h2v16z"
|
|
2102
|
-
})]
|
|
2103
|
-
}));
|
|
2104
|
-
const ChevronRight = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
|
|
2105
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2106
|
-
height: "24px",
|
|
2107
|
-
viewBox: "0 0 24 24",
|
|
2108
|
-
width: "24px",
|
|
2109
|
-
fill: "currentColor",
|
|
2110
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2111
|
-
d: "M0 0h24v24H0V0z",
|
|
2112
|
-
fill: "none"
|
|
2113
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2114
|
-
d: "M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6-6-6z"
|
|
2115
|
-
})]
|
|
2116
|
-
}));
|
|
2117
|
-
const Search = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
|
|
2118
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2119
|
-
height: "24px",
|
|
2120
|
-
viewBox: "0 0 24 24",
|
|
2121
|
-
width: "24px",
|
|
2122
|
-
fill: "currentColor",
|
|
2123
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2124
|
-
d: "M0 0h24v24H0V0z",
|
|
2125
|
-
fill: "none"
|
|
2126
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2127
|
-
d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"
|
|
2128
|
-
})]
|
|
2129
|
-
}));
|
|
2130
|
-
const Clear = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
|
|
2131
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2132
|
-
height: "24px",
|
|
2133
|
-
viewBox: "0 0 24 24",
|
|
2134
|
-
width: "24px",
|
|
2135
|
-
fill: "currentColor",
|
|
2136
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2137
|
-
d: "M0 0h24v24H0V0z",
|
|
2138
|
-
fill: "none"
|
|
2139
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2140
|
-
d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"
|
|
2141
|
-
})]
|
|
2142
|
-
}));
|
|
2143
|
-
const ArrowDropDown = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
|
|
2144
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2145
|
-
height: "24px",
|
|
2146
|
-
viewBox: "0 0 24 24",
|
|
2147
|
-
width: "24px",
|
|
2148
|
-
fill: "currentColor",
|
|
2149
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2150
|
-
d: "M0 0h24v24H0V0z",
|
|
2151
|
-
fill: "none"
|
|
2152
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2153
|
-
d: "M7 10l5 5 5-5H7z"
|
|
2154
|
-
})]
|
|
2155
|
-
}));
|
|
2156
|
-
const FilterList = Icon(/* @__PURE__ */ jsxRuntime.jsx("svg", {
|
|
2157
|
-
viewBox: "0 0 24 24",
|
|
2158
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2159
|
-
fill: "currentColor",
|
|
2160
|
-
d: "M14,12V19.88C14.04,20.18 13.94,20.5 13.71,20.71C13.32,21.1 12.69,21.1 12.3,20.71L10.29,18.7C10.06,18.47 9.96,18.16 10,17.87V12H9.97L4.21,4.62C3.87,4.19 3.95,3.56 4.38,3.22C4.57,3.08 4.78,3 5,3V3H19V3C19.22,3 19.43,3.08 19.62,3.22C20.05,3.56 20.13,4.19 19.79,4.62L14.03,12H14Z"
|
|
2161
|
-
})
|
|
2162
|
-
}));
|
|
2163
|
-
const ArrowUpward = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
|
|
2164
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2165
|
-
height: "24px",
|
|
2166
|
-
viewBox: "0 0 24 24",
|
|
2167
|
-
width: "24px",
|
|
2168
|
-
fill: "currentColor",
|
|
2169
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2170
|
-
d: "M0 0h24v24H0V0z",
|
|
2171
|
-
fill: "none"
|
|
2172
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("path", {
|
|
2173
|
-
d: "M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"
|
|
2174
|
-
})]
|
|
2175
|
-
}));
|
|
2176
|
-
const defaultIcons = {
|
|
2177
|
-
Settings,
|
|
2178
|
-
Export,
|
|
2179
|
-
Clipboard,
|
|
2180
|
-
ChevronRight,
|
|
2181
|
-
Search,
|
|
2182
|
-
Clear,
|
|
2183
|
-
ArrowDropDown,
|
|
2184
|
-
FilterList,
|
|
2185
|
-
ArrowUpward
|
|
2186
|
-
};
|
|
2187
|
-
const defaultTexts = {
|
|
2188
|
-
selectColumns: "Select visible columns",
|
|
2189
|
-
noResults: "No results",
|
|
2190
|
-
exportTitle: "Export",
|
|
2191
|
-
exportCopy: "To clipboard",
|
|
2192
|
-
exportDownload: "Download",
|
|
2193
|
-
today: "Today",
|
|
2194
|
-
thisWeek: "This week",
|
|
2195
|
-
clearFilters: "Clear all filters",
|
|
2196
|
-
reset: "Reset",
|
|
2197
|
-
loading: "Loading",
|
|
2198
|
-
deselectAll: "Deselect all"
|
|
2199
|
-
};
|
|
2200
|
-
const defaultTableTheme = {
|
|
2201
|
-
text: defaultTexts,
|
|
2202
|
-
components: defaultComponents,
|
|
2203
|
-
icons: defaultIcons,
|
|
2204
|
-
colors: defaultColors,
|
|
2205
|
-
spacing: "5px"
|
|
2206
|
-
};
|
|
2207
|
-
const emptyStore = new react$1.Store(void 0);
|
|
2208
|
-
function useTheme(selector) {
|
|
2209
|
-
var _a, _b;
|
|
2210
|
-
const contextTableTheme = react.useContext(tableTheme.TableThemeContext);
|
|
2211
|
-
const table = react.useContext(TableContext);
|
|
2212
|
-
const columnId = react.useContext(ColumnContext);
|
|
2213
|
-
const memo = useTableMemo();
|
|
2214
|
-
const process = (t) => {
|
|
2215
|
-
var _a2;
|
|
2216
|
-
const cell = (_a2 = t.classes) == null ? void 0 : _a2.cell;
|
|
2217
|
-
return __spreadProps(__spreadValues({}, t), {
|
|
2218
|
-
classes: __spreadProps(__spreadValues({}, t.classes), {
|
|
2219
|
-
cell: cell instanceof Function || Array.isArray(cell) ? memo("theme.classes.cell", cell) : cell
|
|
2220
|
-
}),
|
|
2221
|
-
text: __spreadValues({}, t.text)
|
|
2222
|
-
});
|
|
2223
|
-
};
|
|
2224
|
-
const theme = (_b = (_a = table == null ? void 0 : table.useState((state) => {
|
|
2225
|
-
const localTheme = {
|
|
2226
|
-
text: state.props.text,
|
|
2227
|
-
classes: state.props.classes,
|
|
2228
|
-
components: state.props.components,
|
|
2229
|
-
icons: state.props.icons,
|
|
2230
|
-
colors: state.props.colors,
|
|
2231
|
-
spacing: state.props.spacing
|
|
2232
|
-
};
|
|
2233
|
-
const column = state.activeColumns.find((column2) => column2.id === columnId);
|
|
2234
|
-
const columnsTheme = {
|
|
2235
|
-
classes: column == null ? void 0 : column.classes
|
|
2236
|
-
};
|
|
2237
|
-
const theme2 = tableTheme.mergeThemes(defaultTableTheme, tableTheme.globalTableTheme, contextTableTheme, localTheme, columnsTheme);
|
|
2238
|
-
return selector(process(theme2));
|
|
2239
|
-
})) != null ? _a : emptyStore.useState()) != null ? _b : selector(process(tableTheme.mergeThemes(defaultTableTheme, tableTheme.globalTableTheme, contextTableTheme)));
|
|
2240
|
-
return theme;
|
|
2241
|
-
}
|
|
2242
|
-
function AutoFocusTextField(props) {
|
|
2243
|
-
const TextField2 = useTheme((t) => t.components.TextField);
|
|
2244
|
-
const ref = react.useRef(null);
|
|
2245
|
-
const {
|
|
2246
|
-
visible
|
|
2247
|
-
} = react.useContext(tableTheme.PopoverContext);
|
|
2248
|
-
react.useLayoutEffect(() => {
|
|
2249
|
-
if (visible && ref.current) {
|
|
2250
|
-
ref.current.focus();
|
|
2251
|
-
}
|
|
2252
|
-
}, [visible]);
|
|
2253
|
-
return /* @__PURE__ */ jsxRuntime.jsx(TextField2, __spreadProps(__spreadValues({}, props), {
|
|
2254
|
-
inputRef: ref
|
|
2255
|
-
}));
|
|
2256
|
-
}
|
|
2257
|
-
const className = "schummar-table-date-input";
|
|
2258
|
-
const defaultDate = new Date(1970, 0, 1);
|
|
2259
|
-
const isIncludedType = (type) => type === "day" || type === "month" || type === "year";
|
|
2260
|
-
const defaultLengths = {
|
|
2261
|
-
day: 2,
|
|
2262
|
-
month: 2,
|
|
2263
|
-
year: 4
|
|
2264
|
-
};
|
|
2265
|
-
const maxLengths = {
|
|
2266
|
-
day: 2,
|
|
2267
|
-
month: 2,
|
|
2268
|
-
year: Infinity
|
|
2269
|
-
};
|
|
2270
|
-
const length = (type, value) => Math.max(value.length, defaultLengths[type]);
|
|
2271
|
-
const tabNext = (e) => {
|
|
2272
|
-
const all = Array.from(document.querySelectorAll(`.${className}`));
|
|
2273
|
-
const index = all.indexOf(e);
|
|
2274
|
-
const next = all[(index + 1) % all.length];
|
|
2275
|
-
if (next instanceof HTMLElement) {
|
|
2276
|
-
next.focus();
|
|
2277
|
-
}
|
|
2278
|
-
};
|
|
2279
|
-
function DateInput({
|
|
2280
|
-
value,
|
|
2281
|
-
onChange,
|
|
2282
|
-
locale
|
|
2283
|
-
}) {
|
|
2284
|
-
const [override, setOverride] = react.useState();
|
|
2285
|
-
const commit = () => {
|
|
2286
|
-
if (!override) {
|
|
2287
|
-
return;
|
|
2288
|
-
}
|
|
2289
|
-
setOverride(void 0);
|
|
2290
|
-
if (!override.value) {
|
|
2291
|
-
onChange(null);
|
|
2292
|
-
return;
|
|
2293
|
-
}
|
|
2294
|
-
const newValue = value ? new Date(value) : new Date();
|
|
2295
|
-
if (override.type === "day") {
|
|
2296
|
-
newValue.setDate(Number(override.value));
|
|
2297
|
-
} else if (override.type === "month") {
|
|
2298
|
-
newValue.setMonth(Number(override.value) - 1);
|
|
2299
|
-
} else if (override.type === "year") {
|
|
2300
|
-
newValue.setFullYear(Number(override.value));
|
|
2301
|
-
}
|
|
2302
|
-
onChange(newValue);
|
|
2303
|
-
};
|
|
2304
|
-
const format = react.useMemo(() => new Intl.DateTimeFormat(locale, {
|
|
2305
|
-
day: "2-digit",
|
|
2306
|
-
month: "2-digit",
|
|
2307
|
-
year: "numeric"
|
|
2308
|
-
}), [locale]);
|
|
2309
|
-
const parts = format.formatToParts(value != null ? value : defaultDate);
|
|
2310
|
-
const isEmpty = !value;
|
|
2311
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
2312
|
-
css: {
|
|
2313
|
-
display: "flex",
|
|
2314
|
-
alignItems: "baseline"
|
|
2315
|
-
},
|
|
2316
|
-
children: parts.map(({
|
|
2317
|
-
type,
|
|
2318
|
-
value: value2
|
|
2319
|
-
}, index) => /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, {
|
|
2320
|
-
children: isIncludedType(type) ? /* @__PURE__ */ jsxRuntime.jsx("input", {
|
|
2321
|
-
className,
|
|
2322
|
-
css: {
|
|
2323
|
-
width: `${length(type, value2)}ch`,
|
|
2324
|
-
boxSizing: "content-box",
|
|
2325
|
-
overflow: "visible",
|
|
2326
|
-
border: "none",
|
|
2327
|
-
borderBottom: "2px solid transparent",
|
|
2328
|
-
outline: "none",
|
|
2329
|
-
fontSize: "inherit",
|
|
2330
|
-
"&:focus": {
|
|
2331
|
-
borderBottom: "2px solid var(--primaryMain)"
|
|
2332
|
-
}
|
|
2333
|
-
},
|
|
2334
|
-
placeholder: "".padEnd(length(type, value2), "0"),
|
|
2335
|
-
value: (override == null ? void 0 : override.type) === type ? override.value : !isEmpty ? value2 : "",
|
|
2336
|
-
onChange: (e) => {
|
|
2337
|
-
setOverride({
|
|
2338
|
-
type,
|
|
2339
|
-
value: e.target.value
|
|
2340
|
-
});
|
|
2341
|
-
if (e.target.value.length >= maxLengths[type]) {
|
|
2342
|
-
setTimeout(() => tabNext(e.target));
|
|
2343
|
-
}
|
|
2344
|
-
},
|
|
2345
|
-
onFocus: (e) => e.target.select(),
|
|
2346
|
-
onBlur: commit
|
|
2347
|
-
}) : type === "literal" ? /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
2348
|
-
children: value2
|
|
2349
|
-
}) : null
|
|
2350
|
-
}, index))
|
|
2351
|
-
});
|
|
2352
|
-
}
|
|
2353
|
-
const weekDays = [0, 1, 2, 3, 4, 5, 6];
|
|
2354
|
-
const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
2355
|
-
const endOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1, 0, 0, 0, -1);
|
|
2356
|
-
const today = () => {
|
|
2357
|
-
const today2 = startOfDay(new Date());
|
|
2358
|
-
return {
|
|
2359
|
-
min: today2,
|
|
2360
|
-
max: today2
|
|
2361
|
-
};
|
|
2362
|
-
};
|
|
2363
|
-
const thisWeek = (firstDayOfWeek = 0) => {
|
|
2364
|
-
const now = new Date();
|
|
2365
|
-
const min = new Date(now);
|
|
2366
|
-
let diff = min.getDay() - firstDayOfWeek;
|
|
2367
|
-
if (diff < 0) {
|
|
2368
|
-
diff += 7;
|
|
2369
|
-
}
|
|
2370
|
-
min.setDate(min.getDate() - diff);
|
|
2371
|
-
const max = new Date(min);
|
|
2372
|
-
max.setDate(max.getDate() + 6);
|
|
2373
|
-
return {
|
|
2374
|
-
min: startOfDay(min),
|
|
2375
|
-
max: endOfDay(max)
|
|
2376
|
-
};
|
|
2377
|
-
};
|
|
2378
|
-
function dateIntersect(a, b) {
|
|
2379
|
-
if (a instanceof Date) {
|
|
2380
|
-
a = {
|
|
2381
|
-
min: a,
|
|
2382
|
-
max: a
|
|
2383
|
-
};
|
|
2384
|
-
}
|
|
2385
|
-
if (b instanceof Date) {
|
|
2386
|
-
b = {
|
|
2387
|
-
min: b,
|
|
2388
|
-
max: b
|
|
2389
|
-
};
|
|
2390
|
-
}
|
|
2391
|
-
if (!(a == null ? void 0 : a.min) || !a.max || !(b == null ? void 0 : b.min) || !b.max) {
|
|
2392
|
-
return false;
|
|
2393
|
-
}
|
|
2394
|
-
return !(endOfDay(a.max) < startOfDay(b.min) || startOfDay(a.min) > endOfDay(b.max));
|
|
2395
|
-
}
|
|
2396
|
-
function DatePicker({
|
|
2397
|
-
value,
|
|
2398
|
-
onChange,
|
|
2399
|
-
rangeSelect,
|
|
2400
|
-
locale,
|
|
2401
|
-
firstDayOfWeek = 0
|
|
2402
|
-
}) {
|
|
2403
|
-
const Button2 = useTheme((t) => t.components.Button);
|
|
2404
|
-
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
2405
|
-
const ChevronRight2 = useTheme((t) => t.icons.ChevronRight);
|
|
2406
|
-
const textToday = useTheme((t) => t.text.today);
|
|
2407
|
-
const textThisWeek = useTheme((t) => t.text.thisWeek);
|
|
2408
|
-
const textReset = useTheme((t) => t.text.reset);
|
|
2409
|
-
const cssVariables = useCssVariables();
|
|
2410
|
-
const [baseDate] = react.useState(new Date());
|
|
2411
|
-
const [dateInView, setDateInView] = react.useState(baseDate);
|
|
2412
|
-
const [dirty, setDirty] = react.useState();
|
|
2413
|
-
const [hovered, setHovered] = react.useState();
|
|
2414
|
-
const min = dirty ? dirty.min : value instanceof Date ? value : value == null ? void 0 : value.min;
|
|
2415
|
-
const max = dirty ? dirty.max : value instanceof Date ? value : value == null ? void 0 : value.max;
|
|
2416
|
-
const {
|
|
2417
|
-
calendars,
|
|
2418
|
-
getBackProps,
|
|
2419
|
-
getForwardProps,
|
|
2420
|
-
getDateProps
|
|
2421
|
-
} = dayzed.useDayzed({
|
|
2422
|
-
onDateSelected: () => void 0,
|
|
2423
|
-
firstDayOfWeek,
|
|
2424
|
-
showOutsideDays: true,
|
|
2425
|
-
date: dateInView,
|
|
2426
|
-
onOffsetChanged: (offset) => setDateInView(new Date(dateInView.getFullYear(), dateInView.getMonth() + offset)),
|
|
2427
|
-
offset: 0
|
|
2428
|
-
});
|
|
2429
|
-
const formatWeekday = react.useMemo(() => {
|
|
2430
|
-
const {
|
|
2431
|
-
format
|
|
2432
|
-
} = new Intl.DateTimeFormat(locale, {
|
|
2433
|
-
weekday: "short"
|
|
2434
|
-
});
|
|
2435
|
-
return (weekDay) => format(new Date(Date.UTC(2021, 5, weekDay)));
|
|
2436
|
-
}, [locale]);
|
|
2437
|
-
react.useEffect(() => setDateInView(value === null ? new Date() : value instanceof Date ? value : value.max), [value]);
|
|
2438
|
-
react.useEffect(() => {
|
|
2439
|
-
if (!rangeSelect) {
|
|
2440
|
-
setDirty(void 0);
|
|
2441
|
-
}
|
|
2442
|
-
}, [rangeSelect]);
|
|
2443
|
-
function set(min2, max2, edit) {
|
|
2444
|
-
if (!rangeSelect) {
|
|
2445
|
-
onChange(min2 != null ? min2 : null);
|
|
2446
|
-
return;
|
|
2447
|
-
}
|
|
2448
|
-
if (min2 && max2 && min2 > max2) {
|
|
2449
|
-
if (edit === "min") {
|
|
2450
|
-
max2 = min2;
|
|
2451
|
-
} else if (edit === "max") {
|
|
2452
|
-
min2 = max2;
|
|
2453
|
-
} else {
|
|
2454
|
-
[min2, max2] = [max2, min2];
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
if (!min2 === !max2) {
|
|
2458
|
-
setDirty(void 0);
|
|
2459
|
-
onChange(min2 && max2 ? {
|
|
2460
|
-
min: min2,
|
|
2461
|
-
max: max2
|
|
2462
|
-
} : null);
|
|
2463
|
-
} else {
|
|
2464
|
-
setDirty({
|
|
2465
|
-
min: min2,
|
|
2466
|
-
max: max2
|
|
2467
|
-
});
|
|
2468
|
-
}
|
|
2469
|
-
}
|
|
2470
|
-
const formatMonth = react.useMemo(() => {
|
|
2471
|
-
const {
|
|
2472
|
-
format
|
|
2473
|
-
} = new Intl.DateTimeFormat(locale, {
|
|
2474
|
-
month: "long"
|
|
2475
|
-
});
|
|
2476
|
-
return (month) => format(new Date(2021, month));
|
|
2477
|
-
}, [locale]);
|
|
2478
|
-
const formatYear = react.useMemo(() => {
|
|
2479
|
-
const {
|
|
2480
|
-
format
|
|
2481
|
-
} = new Intl.DateTimeFormat(locale, {
|
|
2482
|
-
year: "numeric"
|
|
2483
|
-
});
|
|
2484
|
-
return (year) => format(new Date(year, 0, 1));
|
|
2485
|
-
}, [locale]);
|
|
2486
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
2487
|
-
css: cssVariables,
|
|
2488
|
-
children: [/* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
2489
|
-
css: {
|
|
2490
|
-
display: "grid",
|
|
2491
|
-
gridAutoFlow: "column",
|
|
2492
|
-
justifyContent: "center",
|
|
2493
|
-
alignItems: "baseline",
|
|
2494
|
-
gap: "var(--spacing)"
|
|
2495
|
-
},
|
|
2496
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx(DateInput, {
|
|
2497
|
-
value: min != null ? min : null,
|
|
2498
|
-
onChange: (date) => set(date != null ? date : void 0, max, "min"),
|
|
2499
|
-
locale
|
|
2500
|
-
}), rangeSelect && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
2501
|
-
children: [" - ", /* @__PURE__ */ jsxRuntime.jsx(DateInput, {
|
|
2502
|
-
value: max != null ? max : null,
|
|
2503
|
-
onChange: (date) => set(min, date != null ? date : void 0, "max"),
|
|
2504
|
-
locale
|
|
2505
|
-
})]
|
|
2506
|
-
})]
|
|
2507
|
-
}), calendars.map(({
|
|
2508
|
-
month,
|
|
2509
|
-
year,
|
|
2510
|
-
weeks
|
|
2511
|
-
}) => /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
2512
|
-
css: {
|
|
2513
|
-
display: "grid"
|
|
2514
|
-
},
|
|
2515
|
-
children: [/* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
2516
|
-
css: {
|
|
2517
|
-
margin: "calc(var(--spacing) * 4) 0",
|
|
2518
|
-
display: "grid",
|
|
2519
|
-
gridAutoFlow: "column",
|
|
2520
|
-
justifyContent: "space-between",
|
|
2521
|
-
alignItems: "center"
|
|
2522
|
-
},
|
|
2523
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx(IconButton2, __spreadProps(__spreadValues({}, getBackProps({
|
|
2524
|
-
calendars
|
|
2525
|
-
})), {
|
|
2526
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ChevronRight2, {
|
|
2527
|
-
css: {
|
|
2528
|
-
transform: "rotate3d(0, 0, 1, 180deg)"
|
|
2529
|
-
}
|
|
2530
|
-
})
|
|
2531
|
-
})), /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
2532
|
-
css: {
|
|
2533
|
-
display: "flex"
|
|
2534
|
-
},
|
|
2535
|
-
children: [formatMonth(month), " ", formatYear(year)]
|
|
2536
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(IconButton2, __spreadProps(__spreadValues({}, getForwardProps({
|
|
2537
|
-
calendars
|
|
2538
|
-
})), {
|
|
2539
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ChevronRight2, {})
|
|
2540
|
-
}))]
|
|
2541
|
-
}), /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
2542
|
-
css: {
|
|
2543
|
-
justifySelf: "center",
|
|
2544
|
-
display: "grid",
|
|
2545
|
-
gridTemplateColumns: "repeat(7, max-content)",
|
|
2546
|
-
fontWeight: "bold"
|
|
2547
|
-
},
|
|
2548
|
-
children: [weekDays.map((_v, weekDay) => /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
2549
|
-
css: {
|
|
2550
|
-
justifySelf: "center",
|
|
2551
|
-
marginBottom: "var(--spacing)"
|
|
2552
|
-
},
|
|
2553
|
-
children: formatWeekday(weekDay)
|
|
2554
|
-
}, weekDay)), weeks.map((week, index) => week.map((dateObj, dayIndex) => {
|
|
2555
|
-
if (!dateObj) {
|
|
2556
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", {});
|
|
2557
|
-
}
|
|
2558
|
-
const {
|
|
2559
|
-
prevMonth,
|
|
2560
|
-
nextMonth,
|
|
2561
|
-
date,
|
|
2562
|
-
today: today2
|
|
2563
|
-
} = dateObj;
|
|
2564
|
-
const selected = date.getTime() === (min == null ? void 0 : min.getTime()) || min && max && dateIntersect(date, {
|
|
2565
|
-
min,
|
|
2566
|
-
max
|
|
2567
|
-
});
|
|
2568
|
-
const preSelected = !selected && (date.getTime() === (hovered == null ? void 0 : hovered.getTime()) || min && !max && hovered && dateIntersect(date, min <= hovered ? {
|
|
2569
|
-
min,
|
|
2570
|
-
max: hovered
|
|
2571
|
-
} : {
|
|
2572
|
-
min: hovered,
|
|
2573
|
-
max: min
|
|
2574
|
-
}));
|
|
2575
|
-
return /* @__PURE__ */ jsxRuntime.jsx("button", __spreadProps(__spreadValues({
|
|
2576
|
-
css: [{
|
|
2577
|
-
padding: 10,
|
|
2578
|
-
border: "1px solid transparent",
|
|
2579
|
-
background: "transparent",
|
|
2580
|
-
cursor: "pointer"
|
|
2581
|
-
}, (prevMonth || nextMonth) && {
|
|
2582
|
-
color: tableTheme.gray
|
|
2583
|
-
}, today2 && {
|
|
2584
|
-
border: "1px solid var(--secondaryMain)"
|
|
2585
|
-
}, selected && {
|
|
2586
|
-
background: "var(--primaryMain)",
|
|
2587
|
-
color: "var(--primaryContrastText)"
|
|
2588
|
-
}, preSelected && {
|
|
2589
|
-
background: "var(--primaryLight)",
|
|
2590
|
-
color: "var(--primaryContrastText)"
|
|
2591
|
-
}]
|
|
2592
|
-
}, getDateProps({
|
|
2593
|
-
dateObj
|
|
2594
|
-
})), {
|
|
2595
|
-
onClick: () => {
|
|
2596
|
-
if (dirty) {
|
|
2597
|
-
if (min)
|
|
2598
|
-
set(min, date);
|
|
2599
|
-
else
|
|
2600
|
-
set(date, max);
|
|
2601
|
-
} else {
|
|
2602
|
-
set(date);
|
|
2603
|
-
}
|
|
2604
|
-
},
|
|
2605
|
-
onPointerOver: () => setHovered(date),
|
|
2606
|
-
onPointerOut: () => setHovered(void 0),
|
|
2607
|
-
children: date.getDate()
|
|
2608
|
-
}), `${index}-${dayIndex}`);
|
|
2609
|
-
}))]
|
|
2610
|
-
})]
|
|
2611
|
-
}, `${month}${year}`)), /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
2612
|
-
css: {
|
|
2613
|
-
marginTop: "var(--spacing)",
|
|
2614
|
-
display: "grid",
|
|
2615
|
-
gridAutoFlow: "column",
|
|
2616
|
-
justifyContent: "center"
|
|
2617
|
-
},
|
|
2618
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx(Button2, {
|
|
2619
|
-
variant: "text",
|
|
2620
|
-
onClick: () => {
|
|
2621
|
-
setDirty(void 0);
|
|
2622
|
-
onChange(today());
|
|
2623
|
-
},
|
|
2624
|
-
children: textToday
|
|
2625
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(Button2, {
|
|
2626
|
-
variant: "text",
|
|
2627
|
-
onClick: () => {
|
|
2628
|
-
setDirty(void 0);
|
|
2629
|
-
onChange(thisWeek(firstDayOfWeek));
|
|
2630
|
-
},
|
|
2631
|
-
children: textThisWeek
|
|
2632
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(Button2, {
|
|
2633
|
-
variant: "text",
|
|
2634
|
-
onClick: () => {
|
|
2635
|
-
setDirty(void 0);
|
|
2636
|
-
onChange(null);
|
|
2637
|
-
},
|
|
2638
|
-
children: textReset
|
|
2639
|
-
})]
|
|
2640
|
-
})]
|
|
2641
|
-
});
|
|
2642
|
-
}
|
|
2643
|
-
function convertDate(x) {
|
|
2644
|
-
if (x instanceof Date)
|
|
2645
|
-
return x;
|
|
2646
|
-
if (typeof x === "number" || typeof x === "string")
|
|
2647
|
-
return new Date(x);
|
|
2648
|
-
return null;
|
|
2649
|
-
}
|
|
2650
|
-
function convertDateOrRange(x) {
|
|
2651
|
-
if (x instanceof Object && "min" in x && "max" in x) {
|
|
2652
|
-
const range = {
|
|
2653
|
-
min: convertDate(x.min),
|
|
2654
|
-
max: convertDate(x.max)
|
|
2655
|
-
};
|
|
2656
|
-
return range.min && range.max ? range : null;
|
|
2657
|
-
}
|
|
2658
|
-
return convertDate(x);
|
|
2659
|
-
}
|
|
2660
|
-
function convertDateOrArray(x) {
|
|
2661
|
-
if (x instanceof Array)
|
|
2662
|
-
return x.map(convertDateOrRange).filter(Boolean);
|
|
2663
|
-
return convertDateOrRange(x);
|
|
2664
|
-
}
|
|
2665
|
-
function DateFilter(_k) {
|
|
2666
|
-
var _l = _k, {
|
|
2667
|
-
locale,
|
|
2668
|
-
firstDayOfWeek,
|
|
2669
|
-
singleSelect,
|
|
2670
|
-
filterBy = convertDateOrArray
|
|
2671
|
-
} = _l, props = __objRest(_l, [
|
|
2672
|
-
"locale",
|
|
2673
|
-
"firstDayOfWeek",
|
|
2674
|
-
"singleSelect",
|
|
2675
|
-
"filterBy"
|
|
2676
|
-
]);
|
|
2677
|
-
const {
|
|
2678
|
-
value = null,
|
|
2679
|
-
onChange
|
|
2680
|
-
} = useFilter(__spreadProps(__spreadValues({}, props), {
|
|
2681
|
-
filterBy,
|
|
2682
|
-
id: "dateFilter",
|
|
2683
|
-
isActive(filterValue) {
|
|
2684
|
-
return !!filterValue;
|
|
2685
|
-
},
|
|
2686
|
-
test(filterValue, value2) {
|
|
2687
|
-
return dateIntersect(filterValue, value2);
|
|
2688
|
-
}
|
|
2689
|
-
}));
|
|
2690
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
2691
|
-
css: {
|
|
2692
|
-
padding: "calc(var(--spacing) * 2)",
|
|
2693
|
-
display: "grid"
|
|
2694
|
-
},
|
|
2695
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(DatePicker, {
|
|
2696
|
-
rangeSelect: !singleSelect,
|
|
2697
|
-
value,
|
|
2698
|
-
onChange,
|
|
2699
|
-
locale,
|
|
2700
|
-
firstDayOfWeek
|
|
2701
|
-
})
|
|
2702
|
-
});
|
|
2703
|
-
}
|
|
2704
|
-
function toggle(set, value, singleSelect) {
|
|
2705
|
-
const newSet = new Set(singleSelect ? [] : set);
|
|
2706
|
-
if (set.has(value)) {
|
|
2707
|
-
newSet.delete(value);
|
|
2708
|
-
} else {
|
|
2709
|
-
newSet.add(value);
|
|
2710
|
-
}
|
|
2711
|
-
return newSet;
|
|
2712
|
-
}
|
|
2713
|
-
function SelectFilter(_m) {
|
|
2714
|
-
var _n = _m, {
|
|
2715
|
-
options: providedOptions,
|
|
2716
|
-
stringValue = asString,
|
|
2717
|
-
render = stringValue,
|
|
2718
|
-
singleSelect
|
|
2719
|
-
} = _n, props = __objRest(_n, [
|
|
2720
|
-
"options",
|
|
2721
|
-
"stringValue",
|
|
2722
|
-
"render",
|
|
2723
|
-
"singleSelect"
|
|
2724
|
-
]);
|
|
2725
|
-
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
2726
|
-
const Checkbox2 = useTheme((t) => t.components.Checkbox);
|
|
2727
|
-
const Search2 = useTheme((t) => t.icons.Search);
|
|
2728
|
-
const Clear2 = useTheme((t) => t.icons.Clear);
|
|
2729
|
-
const deselectAll = useTheme((t) => t.text.deselectAll);
|
|
2730
|
-
const noResults = useTheme((t) => t.text.noResults);
|
|
2731
|
-
const table = useTableContext();
|
|
2732
|
-
const columnId = useColumnContext();
|
|
2733
|
-
const {
|
|
2734
|
-
value = /* @__PURE__ */ new Set(),
|
|
2735
|
-
onChange,
|
|
2736
|
-
filterBy
|
|
2737
|
-
} = useFilter(__spreadProps(__spreadValues({}, props), {
|
|
2738
|
-
id: "selectFilter",
|
|
2739
|
-
isActive(filterValue) {
|
|
2740
|
-
return filterValue.size > 0;
|
|
2741
|
-
},
|
|
2742
|
-
test(filterValue, value2) {
|
|
2743
|
-
return filterValue.has(value2);
|
|
2744
|
-
}
|
|
2745
|
-
}));
|
|
2746
|
-
const options = table.useState((state) => {
|
|
2747
|
-
if (providedOptions)
|
|
2748
|
-
return uniq(providedOptions);
|
|
2749
|
-
const column = state.activeColumns.find((column2) => column2.id === columnId);
|
|
2750
|
-
if (!column)
|
|
2751
|
-
return [];
|
|
2752
|
-
return uniq(flatMap(state.items, (item) => castArray(filterBy(column.value(item.value), item.value))));
|
|
2753
|
-
});
|
|
2754
|
-
const [query, setQuery] = react.useState("");
|
|
2755
|
-
const filtered = options.filter((option) => !query || stringValue(option).toLowerCase().includes(query.toLowerCase()));
|
|
2756
|
-
const Button2 = useTheme((t) => t.components.Button);
|
|
2757
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
2758
|
-
css: {
|
|
2759
|
-
padding: "calc(var(--spacing) * 2)",
|
|
2760
|
-
display: "grid",
|
|
2761
|
-
gap: "var(--spacing)"
|
|
2762
|
-
},
|
|
2763
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx(AutoFocusTextField, {
|
|
2764
|
-
value: query,
|
|
2765
|
-
onChange: (e) => setQuery(e.target.value),
|
|
2766
|
-
endIcon: /* @__PURE__ */ jsxRuntime.jsx(IconButton2, {
|
|
2767
|
-
onClick: () => setQuery(""),
|
|
2768
|
-
children: !query ? /* @__PURE__ */ jsxRuntime.jsx(Search2, {}) : /* @__PURE__ */ jsxRuntime.jsx(Clear2, {})
|
|
2769
|
-
}),
|
|
2770
|
-
css: {
|
|
2771
|
-
marginBottom: "var(--spacing)"
|
|
2772
|
-
}
|
|
2773
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(Button2, {
|
|
2774
|
-
disabled: !(value.size > 0),
|
|
2775
|
-
onClick: () => onChange(/* @__PURE__ */ new Set()),
|
|
2776
|
-
variant: "outlined",
|
|
2777
|
-
css: {
|
|
2778
|
-
justifyContent: "center",
|
|
2779
|
-
width: "100%",
|
|
2780
|
-
marginBottom: "var(--spacing)"
|
|
2781
|
-
},
|
|
2782
|
-
children: deselectAll
|
|
2783
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
2784
|
-
css: {
|
|
2785
|
-
maxHeight: "20em",
|
|
2786
|
-
overflowY: "auto"
|
|
2787
|
-
},
|
|
2788
|
-
children: filtered.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(FormControlLabel, {
|
|
2789
|
-
control: /* @__PURE__ */ jsxRuntime.jsx(Checkbox2, {
|
|
2790
|
-
checked: value.has(option),
|
|
2791
|
-
onChange: () => onChange(toggle(value, option, singleSelect))
|
|
2792
|
-
}),
|
|
2793
|
-
label: render(option)
|
|
2794
|
-
}, index))
|
|
2795
|
-
}), filtered.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
2796
|
-
css: {
|
|
2797
|
-
textAlign: "center"
|
|
2798
|
-
},
|
|
2799
|
-
children: noResults
|
|
2800
|
-
})]
|
|
2801
|
-
});
|
|
2802
|
-
}
|
|
2803
|
-
function debounce(fn, ms) {
|
|
2804
|
-
let lastArgs;
|
|
2805
|
-
let timeout;
|
|
2806
|
-
function run() {
|
|
2807
|
-
const args = lastArgs;
|
|
2808
|
-
lastArgs = void 0;
|
|
2809
|
-
timeout = void 0;
|
|
2810
|
-
fn(...args);
|
|
2811
|
-
}
|
|
2812
|
-
return Object.assign(function(...args) {
|
|
2813
|
-
lastArgs = args;
|
|
2814
|
-
if (timeout) {
|
|
2815
|
-
clearTimeout(timeout);
|
|
2816
|
-
}
|
|
2817
|
-
timeout = setTimeout(run, ms);
|
|
2818
|
-
}, {
|
|
2819
|
-
flush() {
|
|
2820
|
-
if (timeout) {
|
|
2821
|
-
clearTimeout(timeout);
|
|
2822
|
-
run();
|
|
2823
|
-
}
|
|
2824
|
-
}
|
|
2825
|
-
});
|
|
2826
|
-
}
|
|
2827
|
-
function useFilter(impl) {
|
|
2828
|
-
const table = useTableContext();
|
|
2829
|
-
const columnId = useColumnContext();
|
|
2830
|
-
const cache = useTableMemo();
|
|
2831
|
-
const filterBy = impl.filterBy && cache("", impl.filterBy);
|
|
2832
|
-
react.useEffect(() => {
|
|
2833
|
-
table.update((state) => {
|
|
2834
|
-
if (impl.defaultValue !== void 0) {
|
|
2835
|
-
state.filterValues.set(columnId, impl.defaultValue);
|
|
2836
|
-
}
|
|
2837
|
-
});
|
|
2838
|
-
}, []);
|
|
2839
|
-
react.useEffect(() => {
|
|
2840
|
-
table.update((state) => {
|
|
2841
|
-
state.filters.set(columnId, immer.castDraft(__spreadProps(__spreadValues({}, impl), { filterBy })));
|
|
2842
|
-
if (impl.value !== void 0) {
|
|
2843
|
-
state.filterValues.set(columnId, impl.value);
|
|
2844
|
-
}
|
|
2845
|
-
});
|
|
2846
|
-
return () => {
|
|
2847
|
-
table.update((state) => {
|
|
2848
|
-
state.filters.delete(columnId);
|
|
2849
|
-
});
|
|
2850
|
-
};
|
|
2851
|
-
}, [table, columnId, impl]);
|
|
2852
|
-
const value = table.useState((state) => state.filterValues.get(columnId));
|
|
2853
|
-
const [dirtyValue, setDirtyValue] = react.useState();
|
|
2854
|
-
const implRef = react.useRef(impl);
|
|
2855
|
-
react.useLayoutEffect(() => {
|
|
2856
|
-
implRef.current = impl;
|
|
2857
|
-
});
|
|
2858
|
-
const delayedUpdate = react.useMemo(() => debounce((value2) => {
|
|
2859
|
-
const { value: controlledValue, onChange: onChange2 } = implRef.current;
|
|
2860
|
-
if (controlledValue === void 0) {
|
|
2861
|
-
table.update((state) => {
|
|
2862
|
-
state.filterValues.set(columnId, value2);
|
|
2863
|
-
});
|
|
2864
|
-
}
|
|
2865
|
-
onChange2 == null ? void 0 : onChange2(value2);
|
|
2866
|
-
setDirtyValue(void 0);
|
|
2867
|
-
}, 500), [table]);
|
|
2868
|
-
function onChange(value2) {
|
|
2869
|
-
setDirtyValue(value2);
|
|
2870
|
-
delayedUpdate(value2);
|
|
2871
|
-
}
|
|
2872
|
-
react.useEffect(() => delayedUpdate.flush(), [delayedUpdate]);
|
|
2873
|
-
return {
|
|
2874
|
-
value: dirtyValue != null ? dirtyValue : value,
|
|
2875
|
-
onChange,
|
|
2876
|
-
close: react.useContext(FilterControlContext),
|
|
2877
|
-
filterBy: filterBy != null ? filterBy : (x) => x
|
|
2878
|
-
};
|
|
2879
|
-
}
|
|
2880
|
-
const textMatch = (text, query) => {
|
|
2881
|
-
text = text.toLowerCase();
|
|
2882
|
-
query = query.toLowerCase();
|
|
2883
|
-
return query.split(/\s+/).every((part) => termMatch(text, part));
|
|
2884
|
-
};
|
|
2885
|
-
const termMatch = (text, query) => {
|
|
2886
|
-
let i = 0;
|
|
2887
|
-
outer:
|
|
2888
|
-
for (const char of query) {
|
|
2889
|
-
for (; i < text.length; i++) {
|
|
2890
|
-
if (text[i] === char) {
|
|
2891
|
-
i++;
|
|
2892
|
-
continue outer;
|
|
2893
|
-
}
|
|
2894
|
-
}
|
|
2895
|
-
return false;
|
|
2896
|
-
}
|
|
2897
|
-
return true;
|
|
2898
|
-
};
|
|
2899
|
-
function TextFilter(_o) {
|
|
2900
|
-
var _p = _o, {
|
|
2901
|
-
compare = textMatch,
|
|
2902
|
-
filterBy = asStringOrArray
|
|
2903
|
-
} = _p, props = __objRest(_p, [
|
|
2904
|
-
"compare",
|
|
2905
|
-
"filterBy"
|
|
2906
|
-
]);
|
|
2907
|
-
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
2908
|
-
const Search2 = useTheme((t) => t.icons.Search);
|
|
2909
|
-
const Clear2 = useTheme((t) => t.icons.Clear);
|
|
2910
|
-
const {
|
|
2911
|
-
value = "",
|
|
2912
|
-
onChange
|
|
2913
|
-
} = useFilter(__spreadProps(__spreadValues({}, props), {
|
|
2914
|
-
filterBy,
|
|
2915
|
-
id: "textFilter",
|
|
2916
|
-
isActive(filterValue) {
|
|
2917
|
-
return !!filterValue;
|
|
2918
|
-
},
|
|
2919
|
-
test(filterValue, value2) {
|
|
2920
|
-
return compare(value2, filterValue);
|
|
2921
|
-
}
|
|
2922
|
-
}));
|
|
2923
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
2924
|
-
css: {
|
|
2925
|
-
padding: `calc(var(--spacing) * 2)`,
|
|
2926
|
-
display: "grid"
|
|
2927
|
-
},
|
|
2928
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(AutoFocusTextField, {
|
|
2929
|
-
value,
|
|
2930
|
-
onChange: (e) => onChange(e.target.value),
|
|
2931
|
-
endIcon: /* @__PURE__ */ jsxRuntime.jsx(IconButton2, {
|
|
2932
|
-
onClick: () => onChange(""),
|
|
2933
|
-
children: !value ? /* @__PURE__ */ jsxRuntime.jsx(Search2, {}) : /* @__PURE__ */ jsxRuntime.jsx(Clear2, {})
|
|
2934
|
-
})
|
|
2935
|
-
})
|
|
2936
|
-
});
|
|
2937
|
-
}
|
|
2938
|
-
exports.TableThemeContext = tableTheme.TableThemeContext;
|
|
2939
|
-
exports.TableThemeProvider = tableTheme.TableThemeProvider;
|
|
2940
|
-
exports.configureTableTheme = tableTheme.configureTableTheme;
|
|
2941
|
-
exports.mergeThemes = tableTheme.mergeThemes;
|
|
2942
|
-
exports.AutoFocusTextField = AutoFocusTextField;
|
|
2943
|
-
exports.ColumnContext = ColumnContext;
|
|
2944
|
-
exports.DateFilter = DateFilter;
|
|
2945
|
-
exports.DatePicker = DatePicker;
|
|
2946
|
-
exports.SelectFilter = SelectFilter;
|
|
2947
|
-
exports.Table = Table;
|
|
2948
|
-
exports.TableContext = TableContext;
|
|
2949
|
-
exports.TextFilter = TextFilter;
|
|
2950
|
-
exports.dateIntersect = dateIntersect;
|
|
2951
|
-
exports.endOfDay = endOfDay;
|
|
2952
|
-
exports.startOfDay = startOfDay;
|
|
2953
|
-
exports.termMatch = termMatch;
|
|
2954
|
-
exports.textMatch = textMatch;
|
|
2955
|
-
exports.useColumnContext = useColumnContext;
|
|
2956
|
-
exports.useFilter = useFilter;
|
|
2957
|
-
exports.useTableContext = useTableContext;
|
|
2958
|
-
exports.useTheme = useTheme;
|
|
2959
|
-
//# sourceMappingURL=index.js.map
|