@gpa-gemstone/react-table 1.2.51 → 1.2.53

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.
@@ -0,0 +1,490 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = AdjustableTable;
4
+ // ******************************************************************************************************
5
+ // Table.tsx - Gbtc
6
+ //
7
+ // Copyright © 2023, Grid Protection Alliance. All Rights Reserved.
8
+ //
9
+ // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
10
+ // the NOTICE file distributed with this work for additional information regarding copyright ownership.
11
+ // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
12
+ // file except in compliance with the License. You may obtain a copy of the License at:
13
+ //
14
+ // http://opensource.org/licenses/MIT
15
+ //
16
+ // Unless agreed to in writing, the subject software distributed under the License is distributed on an
17
+ // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
18
+ // License for the specific language governing permissions and limitations.
19
+ //
20
+ // Code Modification History:
21
+ // ----------------------------------------------------------------------------------------------------
22
+ // 11/18/2023 - C. Lackner
23
+ // Generated original version of source code.
24
+ // 05/31/2024 - C. Lackner
25
+ // Refactored to fix sizing issues.
26
+ //
27
+ // ******************************************************************************************************
28
+ const React = require("react");
29
+ const _ = require("lodash");
30
+ const Column_1 = require("./Column");
31
+ const AdjustableColumn_1 = require("./AdjustableColumn");
32
+ const defaultTableStyle = {
33
+ padding: 0,
34
+ width: '100%',
35
+ height: '100%',
36
+ tableLayout: 'fixed',
37
+ overflow: 'hidden',
38
+ display: 'flex',
39
+ flexDirection: 'column',
40
+ marginBottom: 0,
41
+ };
42
+ function AdjustableTable(props) {
43
+ var _a;
44
+ const bodyRef = React.useRef(null);
45
+ const throtleRef = React.useRef(null);
46
+ const colCountRef = React.useRef(null);
47
+ const autoWidth = React.useRef(new Map());
48
+ const [autoWidthVersion, setAutoWidthVersion] = React.useState(0);
49
+ const [currentTableWidth, setCurrentTableWidth] = React.useState(0);
50
+ const [scrolled, setScrolled] = React.useState(false);
51
+ const [extraWidthPerRow, setExtraWidthPerRow] = React.useState(0);
52
+ const setTableWidth = React.useCallback(_.debounce(() => {
53
+ var _a, _b, _c, _d;
54
+ if (bodyRef.current == null)
55
+ return;
56
+ // Note: certain body classes may break this check if they set overflow to scroll
57
+ let newScroll = false;
58
+ if (((_a = props.TbodyStyle) === null || _a === void 0 ? void 0 : _a.overflowY) === 'scroll' || ((_b = props.TbodyStyle) === null || _b === void 0 ? void 0 : _b.overflow) === 'scroll')
59
+ newScroll = true;
60
+ else
61
+ newScroll = bodyRef.current.clientHeight < bodyRef.current.scrollHeight;
62
+ setScrolled(newScroll);
63
+ setCurrentTableWidth(((_d = (_c = bodyRef.current) === null || _c === void 0 ? void 0 : _c.clientWidth) !== null && _d !== void 0 ? _d : 17) - (newScroll ? 0 : 17));
64
+ }, 100), []);
65
+ React.useEffect(() => {
66
+ let resizeObserver;
67
+ const intervalHandle = setInterval(() => {
68
+ if ((bodyRef === null || bodyRef === void 0 ? void 0 : bodyRef.current) == null)
69
+ return;
70
+ resizeObserver = new ResizeObserver(() => {
71
+ setTableWidth();
72
+ });
73
+ resizeObserver.observe(bodyRef.current);
74
+ clearInterval(intervalHandle);
75
+ }, 10);
76
+ return () => {
77
+ clearInterval(intervalHandle);
78
+ if (resizeObserver != null && resizeObserver.disconnect != null)
79
+ resizeObserver.disconnect();
80
+ };
81
+ }, []);
82
+ React.useEffect(() => {
83
+ autoWidth.current = new Map();
84
+ setAutoWidthVersion(0);
85
+ }, [currentTableWidth]);
86
+ React.useEffect(() => {
87
+ var _a;
88
+ let totalMaxWidth = 0;
89
+ autoWidth.current.forEach((v) => {
90
+ totalMaxWidth += v.maxColWidth;
91
+ });
92
+ if (totalMaxWidth > currentTableWidth && currentTableWidth > 0) {
93
+ const hideKeys = [];
94
+ const showKeys = [];
95
+ let t = 0;
96
+ let colW = 0;
97
+ autoWidth.current.forEach((v, k) => {
98
+ t = t + v.maxColWidth;
99
+ if (t < currentTableWidth) {
100
+ showKeys.push(k);
101
+ colW += v.maxColWidth;
102
+ }
103
+ else
104
+ hideKeys.push(k);
105
+ });
106
+ const numEnabledColumns = showKeys.length;
107
+ if (Array.from(autoWidth.current.values()).filter(autoWidth => !autoWidth.enabled).length == hideKeys.length) {
108
+ return;
109
+ }
110
+ if (colCountRef.current !== null)
111
+ clearTimeout(colCountRef.current);
112
+ colCountRef.current = setTimeout(() => {
113
+ var _a;
114
+ hideKeys.forEach((k) => (autoWidth.current.get(k).enabled = false));
115
+ showKeys.forEach((k) => (autoWidth.current.get(k).enabled = true));
116
+ const numOfColsWithAutoCSS = Array.from(autoWidth.current.values()).filter(autoWidth => autoWidth.isAuto && autoWidth.enabled).length;
117
+ const numOfColsWithUndefinedCSS = Array.from(autoWidth.current.values()).filter(autoWidth => autoWidth.isUndefined && autoWidth.enabled).length;
118
+ let colsToDivideBy = numEnabledColumns; // Split the extra across all cols
119
+ if (numOfColsWithAutoCSS > 0) { // Split only on the css auto-cols and no css undefined cols
120
+ colsToDivideBy = numOfColsWithAutoCSS;
121
+ }
122
+ if (numOfColsWithUndefinedCSS > 0 && numOfColsWithAutoCSS == 0) { // Split only on the css undefined if there are no auto-cols
123
+ colsToDivideBy = numOfColsWithUndefinedCSS;
124
+ }
125
+ const extraSpace = (currentTableWidth - colW - numEnabledColumns) / colsToDivideBy;
126
+ setExtraWidthPerRow(extraSpace);
127
+ (_a = props.ReduceWidthCallback) === null || _a === void 0 ? void 0 : _a.call(props, hideKeys);
128
+ setAutoWidthVersion((v) => v + 1);
129
+ }, 500);
130
+ }
131
+ else if (currentTableWidth > 0) {
132
+ const numEnabledColumns = Array.from(autoWidth.current.values()).filter(autoWidth => autoWidth.enabled).length;
133
+ const numOfColsWithAutoCSS = Array.from(autoWidth.current.values()).filter(autoWidth => autoWidth.isAuto && autoWidth.enabled).length;
134
+ const colsToDivideBy = (numOfColsWithAutoCSS > 0) ? numOfColsWithAutoCSS : numEnabledColumns;
135
+ const extraSpace = (currentTableWidth - totalMaxWidth - numEnabledColumns) / colsToDivideBy;
136
+ setExtraWidthPerRow(extraSpace);
137
+ (_a = props.ReduceWidthCallback) === null || _a === void 0 ? void 0 : _a.call(props, []);
138
+ }
139
+ }, [autoWidthVersion]);
140
+ React.useEffect(() => {
141
+ // if there are keys in the map not present in children, map is old
142
+ const children = React.Children.toArray(props.children);
143
+ const childKeys = [];
144
+ const mapKeys = autoWidth.current.keys();
145
+ children.forEach(child => {
146
+ if (!React.isValidElement(child))
147
+ return;
148
+ if (child.type === Column_1.default ||
149
+ child.type === AdjustableColumn_1.default)
150
+ childKeys.push(child.props.Key);
151
+ });
152
+ for (const key of mapKeys) {
153
+ if (childKeys.includes(key)) {
154
+ continue;
155
+ }
156
+ else {
157
+ autoWidth.current.clear();
158
+ setAutoWidthVersion(0);
159
+ break;
160
+ }
161
+ }
162
+ }, [props.children]);
163
+ const handleSort = React.useCallback((data, event) => {
164
+ if (data.colKey !== null)
165
+ props.OnSort(data, event);
166
+ }, [props.OnSort]);
167
+ const setWidth = React.useCallback((colKey, key, width, isAuto, isUndefined) => {
168
+ var _a, _b, _c, _d, _e, _f;
169
+ const flooredWidth = Math.floor(width);
170
+ if (!autoWidth.current.has(colKey)) { // does the column exist
171
+ autoWidth.current.set(colKey, {
172
+ maxColWidth: flooredWidth,
173
+ width: new Map([[key, flooredWidth]]),
174
+ enabled: true,
175
+ adjustement: 0,
176
+ isAuto: isAuto,
177
+ isUndefined: isUndefined
178
+ });
179
+ }
180
+ else if (!((_b = (_a = autoWidth.current.get(colKey)) === null || _a === void 0 ? void 0 : _a.width.has(key)) !== null && _b !== void 0 ? _b : false)) { // it exists but the key does not
181
+ (_c = autoWidth.current.get(colKey)) === null || _c === void 0 ? void 0 : _c.width.set(key, flooredWidth); // add the width for this key
182
+ autoWidth.current.get(colKey).isAuto = isAuto;
183
+ if (flooredWidth > ((_e = (_d = autoWidth.current.get(colKey)) === null || _d === void 0 ? void 0 : _d.maxColWidth) !== null && _e !== void 0 ? _e : 9e10)) // if width is > to max col
184
+ autoWidth.current.get(colKey).maxColWidth = flooredWidth; // set max to width
185
+ }
186
+ else if (autoWidth.current.get(colKey).width.get(key) == flooredWidth) { // width == newW
187
+ autoWidth.current.get(colKey).isAuto = isAuto;
188
+ return;
189
+ }
190
+ else {
191
+ autoWidth.current.get(colKey).width.set(key, flooredWidth); // otherwise, it exists, just set the width
192
+ autoWidth.current.get(colKey).isAuto = isAuto;
193
+ if (flooredWidth == ((_f = autoWidth.current.get(colKey)) === null || _f === void 0 ? void 0 : _f.maxColWidth)) // check against max
194
+ autoWidth.current.get(colKey).maxColWidth = Math.max(...autoWidth.current.get(colKey).width.values());
195
+ }
196
+ //cancel ref
197
+ //Add a Timer - runs within 10 ms from when the Timer started to avoid React thinking this is an indinfinte loop....
198
+ if (throtleRef.current !== null)
199
+ clearTimeout(throtleRef.current);
200
+ throtleRef.current = setTimeout(() => {
201
+ setAutoWidthVersion((v) => v + 1);
202
+ }, 10);
203
+ }, []);
204
+ const setAdjustment = React.useCallback((colKey, w) => {
205
+ if (!autoWidth.current.has(colKey) || autoWidth.current.get(colKey) == undefined) { // doesnt exist/is undefined
206
+ autoWidth.current.set(colKey, {
207
+ maxColWidth: 0,
208
+ width: new Map(),
209
+ enabled: true,
210
+ adjustement: w,
211
+ isAuto: false,
212
+ isUndefined: false
213
+ });
214
+ }
215
+ else {
216
+ const x = autoWidth.current.get(colKey);
217
+ if ((x === null || x === void 0 ? void 0 : x.adjustement) != undefined)
218
+ x.adjustement += w;
219
+ }
220
+ //cancel ref
221
+ //Add a Timer - runs within 10 ms from when the Timer started to avoid React thinking this is an indinfinte loop....
222
+ if (throtleRef.current !== null)
223
+ clearTimeout(throtleRef.current);
224
+ throtleRef.current = setTimeout(() => {
225
+ setAutoWidthVersion((v) => v + 1);
226
+ }, 10);
227
+ }, []);
228
+ const setMinWidth = React.useCallback((colKey, w) => {
229
+ var _a;
230
+ if (!autoWidth.current.has(colKey))
231
+ autoWidth.current.set(colKey, {
232
+ maxColWidth: 0,
233
+ width: new Map(),
234
+ enabled: true,
235
+ adjustement: 0,
236
+ minWidth: w,
237
+ isAuto: false,
238
+ isUndefined: false
239
+ });
240
+ else if (((_a = autoWidth.current.get(colKey)) === null || _a === void 0 ? void 0 : _a.minWidth) == w)
241
+ return;
242
+ autoWidth.current.get(colKey).minWidth = w;
243
+ //cancel ref
244
+ //Add a Timer - runs within 10 ms from when the Timer started to avoid React thinking this is an indinfinte loop....
245
+ if (throtleRef.current !== null)
246
+ clearTimeout(throtleRef.current);
247
+ throtleRef.current = setTimeout(() => {
248
+ setAutoWidthVersion((v) => v + 1);
249
+ }, 10);
250
+ }, []);
251
+ const setMaxWidth = React.useCallback((colKey, w) => {
252
+ var _a;
253
+ if (!autoWidth.current.has(colKey))
254
+ autoWidth.current.set(colKey, {
255
+ maxColWidth: 0,
256
+ width: new Map(),
257
+ enabled: true,
258
+ adjustement: 0,
259
+ maxWidth: w,
260
+ isAuto: false,
261
+ isUndefined: false
262
+ });
263
+ else if (((_a = autoWidth.current.get(colKey)) === null || _a === void 0 ? void 0 : _a.maxWidth) == w)
264
+ return;
265
+ autoWidth.current.get(colKey).maxWidth = w;
266
+ //cancel ref
267
+ //Add a Timer - runs within 10 ms from when the Timer started to avoid React thinking this is an indinfinte loop....
268
+ if (throtleRef.current !== null)
269
+ clearTimeout(throtleRef.current);
270
+ throtleRef.current = setTimeout(() => {
271
+ setAutoWidthVersion((v) => v + 1);
272
+ }, 10);
273
+ }, []);
274
+ return (React.createElement("table", { className: props.TableClass !== undefined ? props.TableClass : 'table table-hover', style: (_a = props.TableStyle) !== null && _a !== void 0 ? _a : defaultTableStyle },
275
+ React.createElement(Header, { Class: props.TheadClass, Style: props.TheadStyle, SortKey: props.SortKey, Ascending: props.Ascending, OnSort: handleSort, SetWidth: (k, w, a, u) => setWidth(k, -1, w, a, u), SetMaxWidth: setMaxWidth, SetMinWidth: setMinWidth, AutoWidth: autoWidth, AutoWidthVersion: autoWidthVersion, LastColumn: props.LastColumn, SetAdjustment: setAdjustment, ExtraWidth: extraWidthPerRow }, props.children),
276
+ React.createElement(Rows, { DragStart: props.OnDragStart, Data: props.Data, RowStyle: props.RowStyle, BodyStyle: props.TbodyStyle, BodyClass: props.TbodyClass, OnClick: props.OnClick, Selected: props.Selected, KeySelector: props.KeySelector, AutoWidth: autoWidth, AutoWidthVersion: autoWidthVersion, SetWidth: setWidth, ExtraWidth: extraWidthPerRow, BodyRef: bodyRef, BodyScrolled: scrolled }, props.children),
277
+ props.LastRow !== undefined ? (React.createElement("tfoot", { style: props.TfootStyle, className: props.TfootClass },
278
+ React.createElement("tr", { style: props.RowStyle !== undefined ? Object.assign({}, props.RowStyle) : {} }, props.LastRow))) : null));
279
+ }
280
+ function Rows(props) {
281
+ if (props.Data.length === 0)
282
+ return null;
283
+ const onClick = React.useCallback((e, item, index) => {
284
+ if (props.OnClick !== undefined)
285
+ props.OnClick({
286
+ colKey: undefined,
287
+ colField: undefined,
288
+ row: item,
289
+ data: null,
290
+ index: index,
291
+ }, e);
292
+ }, [props.OnClick]);
293
+ const bodyStyle = React.useMemo(() => (Object.assign(Object.assign({}, props.BodyStyle), { paddingRight: (props.BodyScrolled ? 0 : 17) })), [props.BodyStyle, props.BodyScrolled]);
294
+ return (React.createElement("tbody", { style: bodyStyle, className: props.BodyClass, ref: props.BodyRef }, props.Data.map((d, i) => {
295
+ const style = props.RowStyle !== undefined ? Object.assign({}, props.RowStyle) : {};
296
+ if (style.cursor === undefined && (props.OnClick !== undefined || props.DragStart !== undefined))
297
+ style.cursor = 'pointer';
298
+ if (props.Selected !== undefined && props.Selected(d, i))
299
+ style.backgroundColor = 'yellow';
300
+ const key = props.KeySelector(d, i);
301
+ return (React.createElement("tr", { key: key, style: style, onClick: (e) => onClick(e, d, i) }, React.Children.map(props.children, (element) => {
302
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
303
+ if (!React.isValidElement(element))
304
+ return null;
305
+ if (element.type === Column_1.default)
306
+ if ((_b = (_a = props.AutoWidth.current.get(element.props.Key)) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true)
307
+ return (React.createElement(Column_1.ColumnDataWrapper, { key: element.key, extraWidth: props.ExtraWidth, onClick: (props.OnClick !== undefined && props.OnClick !== null) ? (e) => props.OnClick({
308
+ colKey: element.props.Key,
309
+ colField: element.props.Field,
310
+ row: d,
311
+ data: d[element.props.Field],
312
+ index: i,
313
+ }, e) : undefined, dragStart: (props.DragStart !== undefined && props.DragStart !== null) ? (e) => props.DragStart({
314
+ colKey: element.props.Key,
315
+ colField: element.props.Field,
316
+ row: d,
317
+ data: d[element.props.Field],
318
+ index: i,
319
+ }, e) : undefined, setWidth: (w, a, u) => props.SetWidth(element.props.Key, key, w, a, u), style: element.props.RowStyle, width: ((_d = (_c = props.AutoWidth.current.get(element.props.Key)) === null || _c === void 0 ? void 0 : _c.width.has(key)) !== null && _d !== void 0 ? _d : false)
320
+ ? (_e = props.AutoWidth.current.get(element.props.Key)) === null || _e === void 0 ? void 0 : _e.maxColWidth // if not auto <-
321
+ : undefined // otherwise get the extrawidth
322
+ , enabled: (_g = (_f = props.AutoWidth.current.get(element.props.Key)) === null || _f === void 0 ? void 0 : _f.enabled) !== null && _g !== void 0 ? _g : true }, element.props.Content !== undefined
323
+ ? element.props.Content({
324
+ item: d,
325
+ key: element.props.Key,
326
+ field: element.props.Field,
327
+ style: style,
328
+ index: i,
329
+ })
330
+ : element.props.Field !== undefined
331
+ ? d[element.props.Field]
332
+ : null));
333
+ if (element.type === AdjustableColumn_1.default)
334
+ if ((_j = (_h = props.AutoWidth.current.get(element.props.Key)) === null || _h === void 0 ? void 0 : _h.enabled) !== null && _j !== void 0 ? _j : true)
335
+ return (React.createElement(AdjustableColumn_1.AdjustableColumnDataWrapper, { adjustment: (_k = props.AutoWidth.current.get(element.props.Key)) === null || _k === void 0 ? void 0 : _k.adjustement, key: element.key, onClick: (props.OnClick !== undefined && props.OnClick !== null) ? (e) => props.OnClick({
336
+ colKey: element.props.Key,
337
+ colField: element.props.Field,
338
+ row: d,
339
+ data: d[element.props.Field],
340
+ index: i,
341
+ }, e) : undefined, dragStart: (props.DragStart !== undefined && props.DragStart !== null) ? (e) => props.DragStart({
342
+ colKey: element.props.Key,
343
+ colField: element.props.Field,
344
+ row: d,
345
+ data: d[element.props.Field],
346
+ index: i,
347
+ }, e) : undefined, setWidth: (w, a, u) => props.SetWidth(element.props.Key, key, w, a, u), style: element.props.RowStyle, width: ((_m = (_l = props.AutoWidth.current.get(element.props.Key)) === null || _l === void 0 ? void 0 : _l.width.has(key)) !== null && _m !== void 0 ? _m : false)
348
+ ? (_o = props.AutoWidth.current.get(element.props.Key)) === null || _o === void 0 ? void 0 : _o.maxColWidth
349
+ : undefined, enabled: (_q = (_p = props.AutoWidth.current.get(element.props.Key)) === null || _p === void 0 ? void 0 : _p.enabled) !== null && _q !== void 0 ? _q : true, extraWidth: props.ExtraWidth },
350
+ ' ',
351
+ element.props.Content !== undefined
352
+ ? element.props.Content({
353
+ item: d,
354
+ key: element.props.Key,
355
+ field: element.props.Field,
356
+ style: style,
357
+ index: i,
358
+ })
359
+ : element.props.Field !== undefined
360
+ ? d[element.props.Field]
361
+ : null));
362
+ return null;
363
+ })));
364
+ })));
365
+ }
366
+ function Header(props) {
367
+ const trRef = React.useRef(null);
368
+ const [mouseDown, setMouseDown] = React.useState(0);
369
+ const [currentKeys, setCurrentKeys] = React.useState(undefined);
370
+ const [deltaW, setDeltaW] = React.useState(0);
371
+ const [tentativeLimits, setTentativeLimits] = React.useState({ min: -Infinity, max: Infinity });
372
+ const calculateDeltaLimits = React.useCallback((mapKeys, autoWidthRef) => {
373
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
374
+ if (mapKeys === undefined)
375
+ return ({ min: -Infinity, max: Infinity });
376
+ const maxLeftAdjustment = ((_b = (_a = autoWidthRef.current.get(mapKeys[0])) === null || _a === void 0 ? void 0 : _a.maxColWidth) !== null && _b !== void 0 ? _b : 0) +
377
+ ((_d = (_c = autoWidthRef.current.get(mapKeys[0])) === null || _c === void 0 ? void 0 : _c.adjustement) !== null && _d !== void 0 ? _d : 0);
378
+ const minWidthLeftAdjusted = ((_f = (_e = autoWidthRef.current.get(mapKeys[0])) === null || _e === void 0 ? void 0 : _e.minWidth) !== null && _f !== void 0 ? _f : 100) - maxLeftAdjustment;
379
+ const maxWidthLeftAdjusted = ((_h = (_g = autoWidthRef.current.get(mapKeys[0])) === null || _g === void 0 ? void 0 : _g.maxWidth) !== null && _h !== void 0 ? _h : 9e10) - maxLeftAdjustment;
380
+ const maxRightAdjustment = ((_k = (_j = autoWidthRef.current.get(mapKeys[1])) === null || _j === void 0 ? void 0 : _j.maxColWidth) !== null && _k !== void 0 ? _k : 0) +
381
+ ((_m = (_l = autoWidthRef.current.get(mapKeys[1])) === null || _l === void 0 ? void 0 : _l.adjustement) !== null && _m !== void 0 ? _m : 0);
382
+ const minWidthRightAdjusted = ((_p = (_o = autoWidthRef.current.get(mapKeys[1])) === null || _o === void 0 ? void 0 : _o.minWidth) !== null && _p !== void 0 ? _p : 100) - maxRightAdjustment;
383
+ const maxWidthRightAdjusted = ((_r = (_q = autoWidthRef.current.get(mapKeys[1])) === null || _q === void 0 ? void 0 : _q.maxWidth) !== null && _r !== void 0 ? _r : 9e10) - maxRightAdjustment;
384
+ // Recall that a right movement is the result of a negative value on deltaW
385
+ const minDeltaW = Math.abs(minWidthLeftAdjusted) < Math.abs(maxWidthRightAdjusted) ? minWidthLeftAdjusted : -maxWidthRightAdjusted;
386
+ const maxDeltaW = Math.abs(minWidthRightAdjusted) < Math.abs(maxWidthLeftAdjusted) ? -minWidthRightAdjusted : maxWidthLeftAdjusted;
387
+ return ({ min: minDeltaW, max: maxDeltaW });
388
+ }, []);
389
+ const calculateAdjustment = (key) => {
390
+ var _a, _b;
391
+ let adj = 0;
392
+ let delta;
393
+ if (deltaW > tentativeLimits.max)
394
+ delta = tentativeLimits.max;
395
+ else if (deltaW < tentativeLimits.min)
396
+ delta = tentativeLimits.min;
397
+ else
398
+ delta = deltaW;
399
+ if (currentKeys !== undefined && currentKeys[0] == key)
400
+ adj = delta;
401
+ else if (currentKeys !== undefined && currentKeys[1] == key)
402
+ adj = -delta;
403
+ return ((_b = (_a = props.AutoWidth.current.get(key)) === null || _a === void 0 ? void 0 : _a.adjustement) !== null && _b !== void 0 ? _b : 0) + adj;
404
+ };
405
+ const finishAdjustment = () => {
406
+ if (currentKeys === undefined)
407
+ return;
408
+ if (Math.abs(deltaW) > 5) {
409
+ const deltaLimits = calculateDeltaLimits(currentKeys, props.AutoWidth);
410
+ let delta;
411
+ if (deltaW > deltaLimits.max)
412
+ delta = deltaLimits.max;
413
+ else if (deltaW < deltaLimits.min)
414
+ delta = deltaLimits.min;
415
+ else
416
+ delta = deltaW;
417
+ props.SetAdjustment(currentKeys[0], delta);
418
+ props.SetAdjustment(currentKeys[1], -delta);
419
+ }
420
+ setMouseDown(0);
421
+ setTentativeLimits({ min: -Infinity, max: Infinity });
422
+ setCurrentKeys(undefined);
423
+ setDeltaW(0);
424
+ };
425
+ const getLeftKey = React.useCallback((key) => {
426
+ var _a;
427
+ const keys = React.Children.map((_a = props.children) !== null && _a !== void 0 ? _a : [], (element) => {
428
+ var _a;
429
+ if (!React.isValidElement(element)) {
430
+ return null;
431
+ }
432
+ if ((_a = !(props.AutoWidth.current.get(element.props.Key).enabled)) !== null && _a !== void 0 ? _a : true) {
433
+ return null;
434
+ }
435
+ if (element.type === AdjustableColumn_1.default) {
436
+ return element.props.Key;
437
+ }
438
+ return null;
439
+ }).filter((item) => item !== null);
440
+ const index = keys.indexOf(key);
441
+ if (index < 1)
442
+ return undefined;
443
+ return keys[index - 1];
444
+ }, [props.children]);
445
+ const onMove = React.useCallback((e) => {
446
+ if (currentKeys === undefined)
447
+ return;
448
+ const w = e.screenX - mouseDown;
449
+ setDeltaW(w);
450
+ }, [mouseDown, currentKeys]);
451
+ return (React.createElement("thead", { className: props.Class, style: props.Style, onMouseMove: (e) => {
452
+ onMove(e.nativeEvent);
453
+ e.stopPropagation();
454
+ }, onMouseUp: (e) => {
455
+ finishAdjustment();
456
+ e.stopPropagation();
457
+ }, onMouseLeave: (e) => {
458
+ finishAdjustment();
459
+ e.stopPropagation();
460
+ } },
461
+ React.createElement("tr", { ref: trRef },
462
+ React.Children.map(props.children, (element) => {
463
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
464
+ if (!React.isValidElement(element))
465
+ return null;
466
+ if (element.type === Column_1.default)
467
+ if ((_b = (_a = props.AutoWidth.current.get(element.props.Key)) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true)
468
+ return (React.createElement(Column_1.ColumnHeaderWrapper, { enabled: (_d = (_c = props.AutoWidth.current.get(element.props.Key)) === null || _c === void 0 ? void 0 : _c.enabled) !== null && _d !== void 0 ? _d : true, setWidth: (w, a, u) => props.SetWidth(element.props.Key, w, a, u), onSort: (e) => props.OnSort({ colKey: element.props.Key, colField: element.props.Field, ascending: props.Ascending }, e), sorted: props.SortKey === element.props.Key && ((_e = element.props.AllowSort) !== null && _e !== void 0 ? _e : true), asc: props.Ascending, colKey: element.props.Key, key: element.props.Key, allowSort: element.props.AllowSort, width: ((_g = (_f = props.AutoWidth.current.get(element.props.Key)) === null || _f === void 0 ? void 0 : _f.width.has(-1)) !== null && _g !== void 0 ? _g : false)
469
+ ? (_h = props.AutoWidth.current.get(element.props.Key)) === null || _h === void 0 ? void 0 : _h.maxColWidth
470
+ : undefined, style: (_j = element.props.HeaderStyle) !== null && _j !== void 0 ? _j : element.props.RowStyle, extraWidth: props.ExtraWidth },
471
+ ' ', (_k = element.props.children) !== null && _k !== void 0 ? _k : element.props.Key,
472
+ ' '));
473
+ if (element.type === AdjustableColumn_1.default)
474
+ if ((_m = (_l = props.AutoWidth.current.get(element.props.Key)) === null || _l === void 0 ? void 0 : _l.enabled) !== null && _m !== void 0 ? _m : true)
475
+ return (React.createElement(AdjustableColumn_1.AdjustableColumnHeaderWrapper, { enabled: (_p = (_o = props.AutoWidth.current.get(element.props.Key)) === null || _o === void 0 ? void 0 : _o.enabled) !== null && _p !== void 0 ? _p : true, setWidth: (w, a, u) => props.SetWidth(element.props.Key, w, a, u), setMinWidth: (w) => props.SetMinWidth(element.props.Key, Math.round(w)), minWidth: (_q = props.AutoWidth.current.get(element.props.Key)) === null || _q === void 0 ? void 0 : _q.minWidth, setMaxWidth: (w) => props.SetMaxWidth(element.props.Key, Math.round(w)), maxWidth: (_r = props.AutoWidth.current.get(element.props.Key)) === null || _r === void 0 ? void 0 : _r.maxWidth, extraWidth: props.ExtraWidth, onSort: (e) => props.OnSort({ colKey: element.props.Key, colField: element.props.Field, ascending: props.Ascending }, e), sorted: props.SortKey === element.props.Key && ((_s = element.props.AllowSort) !== null && _s !== void 0 ? _s : true), key: element.props.Key, colKey: element.props.Key, asc: props.Ascending, allowSort: element.props.AllowSort, width: ((_u = (_t = props.AutoWidth.current.get(element.props.Key)) === null || _t === void 0 ? void 0 : _t.width.has(-1)) !== null && _u !== void 0 ? _u : false)
476
+ ? (_v = props.AutoWidth.current.get(element.props.Key)) === null || _v === void 0 ? void 0 : _v.maxColWidth
477
+ : undefined, startAdjustment: (e) => {
478
+ let newCurrentKeys;
479
+ if (getLeftKey(element.props.Key) !== undefined)
480
+ newCurrentKeys = [getLeftKey(element.props.Key), element.props.Key];
481
+ setCurrentKeys(newCurrentKeys);
482
+ setMouseDown(e.screenX);
483
+ setTentativeLimits(calculateDeltaLimits(newCurrentKeys, props.AutoWidth));
484
+ setDeltaW(0);
485
+ }, adjustment: calculateAdjustment(element.props.Key), style: (_w = element.props.HeaderStyle) !== null && _w !== void 0 ? _w : element.props.RowStyle },
486
+ ' ', (_x = element.props.children) !== null && _x !== void 0 ? _x : element.props.Key));
487
+ return null;
488
+ }),
489
+ React.createElement("th", { style: { width: 17, padding: 0 } }, props.LastColumn))));
490
+ }
@@ -23,21 +23,20 @@
23
23
  // ******************************************************************************************************
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.DynamicTable = DynamicTable;
26
- var React = require("react");
27
- var Table_1 = require("./Table");
28
- var empty = new Map();
26
+ const React = require("react");
27
+ const Table_1 = require("./Table");
28
+ const empty = new Map();
29
29
  function DynamicTable(props) {
30
30
  if (props.data.length <= 0)
31
31
  return null;
32
- var cols = [];
33
- var keys = Object.keys(props.data[0]);
34
- for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
35
- var key = keys_1[_i];
36
- cols.push({ key: key, label: key, field: key });
32
+ const cols = [];
33
+ const keys = Object.keys(props.data[0]);
34
+ for (const key of keys) {
35
+ cols.push({ key, label: key, field: key });
37
36
  }
38
37
  return (React.createElement("table", { className: props.tableClass !== undefined ? props.tableClass : '', style: props.tableStyle },
39
- React.createElement(Table_1.Header, { Class: props.theadClass, Style: props.theadStyle, Cols: cols, SortKey: props.sortKey, Ascending: props.ascending, Click: function (d) { return handleSort(d); } }),
40
- React.createElement(Table_1.Rows, { Data: props.data, Cols: cols, RowStyle: props.rowStyle, BodyStyle: props.tbodyStyle, BodyClass: props.tbodyClass, Click: function (data, e) { return props.onClick(data, e); }, Selected: props.selected, KeySelector: props.keySelector })));
38
+ React.createElement(Table_1.Header, { Class: props.theadClass, Style: props.theadStyle, Cols: cols, SortKey: props.sortKey, Ascending: props.ascending, Click: (d) => handleSort(d) }),
39
+ React.createElement(Table_1.Rows, { Data: props.data, Cols: cols, RowStyle: props.rowStyle, BodyStyle: props.tbodyStyle, BodyClass: props.tbodyClass, Click: (data, e) => props.onClick(data, e), Selected: props.selected, KeySelector: props.keySelector })));
41
40
  function handleSort(data) {
42
41
  if (data.colKey !== null)
43
42
  props.onSort(data);
package/lib/Paging.js CHANGED
@@ -23,25 +23,25 @@ exports.default = default_1;
23
23
  // Generated original version of source code.
24
24
  //
25
25
  // ******************************************************************************************************
26
- var React = require("react");
26
+ const React = require("react");
27
27
  function default_1(props) {
28
- var _a = React.useState([]), pages = _a[0], setPages = _a[1];
29
- var nPages = 7;
30
- var minPg = React.useMemo(function () {
31
- var min = Math.min.apply(Math, pages);
28
+ const [pages, setPages] = React.useState([]);
29
+ const nPages = 7;
30
+ const minPg = React.useMemo(() => {
31
+ const min = Math.min(...pages);
32
32
  if (isFinite(min) && !isNaN(min))
33
33
  return min;
34
34
  return 0;
35
35
  }, [pages]);
36
- var maxPg = React.useMemo(function () {
37
- var max = Math.max.apply(Math, pages);
36
+ const maxPg = React.useMemo(() => {
37
+ const max = Math.max(...pages);
38
38
  if (isFinite(max) && !isNaN(max))
39
39
  return max;
40
40
  return 0;
41
41
  }, [pages]);
42
- React.useEffect(function () {
43
- var display = [];
44
- var p = Math.max(props.Current - Math.floor(nPages / 2), 1);
42
+ React.useEffect(() => {
43
+ const display = [];
44
+ let p = Math.max(props.Current - Math.floor(nPages / 2), 1);
45
45
  if (props.Total - p < nPages)
46
46
  p = Math.max(props.Total - nPages + 1, 1);
47
47
  while (p <= props.Total && display.length < nPages) {
@@ -52,24 +52,24 @@ function default_1(props) {
52
52
  }, [props.Total, props.Current]);
53
53
  return React.createElement("ul", { className: "pagination justify-content-center" },
54
54
  React.createElement("li", { className: "page-item" + (minPg <= 1 ? ' disabled' : ""), key: "previous" },
55
- React.createElement("a", { className: "page-link", onClick: function () {
55
+ React.createElement("a", { className: "page-link", onClick: () => {
56
56
  if (minPg > 1)
57
57
  props.SetPage(Math.max(props.Current - nPages, 1));
58
58
  } }, "Previous")),
59
59
  minPg > 2 ? React.createElement(React.Fragment, null,
60
60
  React.createElement("li", { className: "page-item", key: "1" },
61
- React.createElement("a", { className: "page-link", onClick: function () { return props.SetPage(1); } }, "1")),
61
+ React.createElement("a", { className: "page-link", onClick: () => props.SetPage(1) }, "1")),
62
62
  React.createElement("li", { className: "page-item disabled", key: "skip-1" },
63
63
  React.createElement("a", { className: "page-link" }, "..."))) : null,
64
- pages.map(function (p) { return React.createElement("li", { className: "page-item" + (p == props.Current ? " active" : ""), key: p },
65
- React.createElement("a", { className: "page-link", onClick: function () { return props.SetPage(p); } }, p)); }),
64
+ pages.map((p) => React.createElement("li", { className: "page-item" + (p == props.Current ? " active" : ""), key: p },
65
+ React.createElement("a", { className: "page-link", onClick: () => props.SetPage(p) }, p))),
66
66
  maxPg + 2 <= props.Total ? React.createElement(React.Fragment, null,
67
67
  React.createElement("li", { className: "page-item disabled", key: "skip-2" },
68
68
  React.createElement("a", { className: "page-link" }, "...")),
69
69
  React.createElement("li", { className: "page-item", key: props.Total },
70
- React.createElement("a", { className: "page-link", onClick: function () { return props.SetPage(props.Total); } }, props.Total))) : null,
70
+ React.createElement("a", { className: "page-link", onClick: () => props.SetPage(props.Total) }, props.Total))) : null,
71
71
  React.createElement("li", { className: "page-item" + (maxPg == props.Total ? ' disabled' : ""), key: 'next' },
72
- React.createElement("a", { className: "page-link", onClick: function () {
72
+ React.createElement("a", { className: "page-link", onClick: () => {
73
73
  if (maxPg < props.Total)
74
74
  props.SetPage(Math.min(props.Current + nPages, props.Total));
75
75
  } }, "Next")));
@@ -21,31 +21,20 @@
21
21
  // Generated original version of source code.
22
22
  //
23
23
  // ******************************************************************************************************
24
- var __assign = (this && this.__assign) || function () {
25
- __assign = Object.assign || function(t) {
26
- for (var s, i = 1, n = arguments.length; i < n; i++) {
27
- s = arguments[i];
28
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29
- t[p] = s[p];
30
- }
31
- return t;
32
- };
33
- return __assign.apply(this, arguments);
34
- };
35
24
  Object.defineProperty(exports, "__esModule", { value: true });
36
25
  exports.SearchableTable = SearchableTable;
37
- var React = require("react");
38
- var Table_1 = require("./Table");
26
+ const React = require("react");
27
+ const Table_1 = require("./Table");
39
28
  /**
40
29
  * A Table with an input Field to search on top
41
30
  */
42
31
  function SearchableTable(props) {
43
- var _a = React.useState(props.data), data = _a[0], setData = _a[1];
44
- var _b = React.useState(''), searchTextAS = _b[0], setSearchTextAS = _b[1];
45
- React.useEffect(function () {
46
- setData(props.data.filter(function (s) { return props.matchSearch(s, searchTextAS); }));
32
+ const [data, setData] = React.useState(props.data);
33
+ const [searchTextAS, setSearchTextAS] = React.useState('');
34
+ React.useEffect(() => {
35
+ setData(props.data.filter(s => props.matchSearch(s, searchTextAS)));
47
36
  }, [props.data, searchTextAS]);
48
37
  return React.createElement(React.Fragment, null,
49
- React.createElement("input", { className: "form-control", placeholder: "Search filter for select box ...", value: searchTextAS, onChange: function (e) { return setSearchTextAS(e.target.value); } }),
50
- React.createElement(Table_1.default, __assign({}, props, { data: data })));
38
+ React.createElement("input", { className: "form-control", placeholder: "Search filter for select box ...", value: searchTextAS, onChange: (e) => setSearchTextAS(e.target.value) }),
39
+ React.createElement(Table_1.default, Object.assign({}, props, { data: data })));
51
40
  }