@gpa-gemstone/react-table 1.2.57 → 1.2.59

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.
Files changed (36) hide show
  1. package/lib/ConfigurableTable/ConfigurableColumn.d.ts +11 -0
  2. package/lib/{SearchableTable.js → ConfigurableTable/ConfigurableColumn.js} +7 -16
  3. package/lib/ConfigurableTable/ConfigurableTable.d.ts +25 -0
  4. package/lib/ConfigurableTable/ConfigurableTable.js +189 -0
  5. package/lib/Filters/BooleanFilter.d.ts +26 -0
  6. package/lib/Filters/BooleanFilter.js +68 -0
  7. package/lib/Filters/DateTimeFilters.d.ts +10 -0
  8. package/lib/Filters/DateTimeFilters.js +321 -0
  9. package/lib/Filters/EnumFilter.d.ts +37 -0
  10. package/lib/Filters/EnumFilter.js +89 -0
  11. package/lib/Filters/NumberFilter.d.ts +19 -0
  12. package/lib/Filters/NumberFilter.js +160 -0
  13. package/lib/Filters/TextFilter.d.ts +14 -0
  14. package/lib/Filters/TextFilter.js +78 -0
  15. package/lib/Table/Column.d.ts +19 -0
  16. package/lib/Table/Column.js +73 -0
  17. package/lib/Table/FilterableColumn.d.ts +20 -0
  18. package/lib/Table/FilterableColumn.js +74 -0
  19. package/lib/Table/Table.d.ts +3 -0
  20. package/lib/Table/Table.js +498 -0
  21. package/lib/{AdjustableTable/Table.d.ts → Table/Types.d.ts} +72 -4
  22. package/lib/{DynamicTable.js → Table/Types.js} +3 -23
  23. package/lib/index.d.ts +7 -14
  24. package/lib/index.js +13 -19
  25. package/package.json +8 -4
  26. package/lib/AdjustableTable/AdjustableColumn.d.ts +0 -18
  27. package/lib/AdjustableTable/AdjustableColumn.js +0 -187
  28. package/lib/AdjustableTable/Column.d.ts +0 -59
  29. package/lib/AdjustableTable/Column.js +0 -98
  30. package/lib/AdjustableTable/Table.js +0 -488
  31. package/lib/DynamicTable.d.ts +0 -37
  32. package/lib/SearchableTable.d.ts +0 -15
  33. package/lib/SelectTable.d.ts +0 -19
  34. package/lib/SelectTable.js +0 -102
  35. package/lib/Table.d.ts +0 -99
  36. package/lib/Table.js +0 -94
@@ -1,488 +0,0 @@
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) / colsToDivideBy;
126
- setExtraWidthPerRow(Math.floor(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
- const onClick = React.useCallback((e, item, index) => {
282
- if (props.OnClick !== undefined)
283
- props.OnClick({
284
- colKey: undefined,
285
- colField: undefined,
286
- row: item,
287
- data: null,
288
- index: index,
289
- }, e);
290
- }, [props.OnClick]);
291
- const bodyStyle = React.useMemo(() => (Object.assign(Object.assign({}, props.BodyStyle), { paddingRight: (props.BodyScrolled ? 0 : 17), display: "block" })), [props.BodyStyle, props.BodyScrolled]);
292
- return (React.createElement("tbody", { style: bodyStyle, className: props.BodyClass, ref: props.BodyRef }, props.Data.map((d, i) => {
293
- const style = props.RowStyle !== undefined ? Object.assign({}, props.RowStyle) : {};
294
- if (style.cursor === undefined && (props.OnClick !== undefined || props.DragStart !== undefined))
295
- style.cursor = 'pointer';
296
- if (props.Selected !== undefined && props.Selected(d, i))
297
- style.backgroundColor = 'var(--warning)';
298
- const key = props.KeySelector(d, i);
299
- return (React.createElement("tr", { key: key, style: style, onClick: (e) => onClick(e, d, i) }, React.Children.map(props.children, (element) => {
300
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
301
- if (!React.isValidElement(element))
302
- return null;
303
- if (element.type === Column_1.default)
304
- if ((_b = (_a = props.AutoWidth.current.get(element.props.Key)) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true)
305
- return (React.createElement(Column_1.ColumnDataWrapper, { key: element.key, extraWidth: props.ExtraWidth, onClick: (props.OnClick !== undefined && props.OnClick !== null) ? (e) => props.OnClick({
306
- colKey: element.props.Key,
307
- colField: element.props.Field,
308
- row: d,
309
- data: d[element.props.Field],
310
- index: i,
311
- }, e) : undefined, dragStart: (props.DragStart !== undefined && props.DragStart !== null) ? (e) => props.DragStart({
312
- colKey: element.props.Key,
313
- colField: element.props.Field,
314
- row: d,
315
- data: d[element.props.Field],
316
- index: i,
317
- }, 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)
318
- ? (_e = props.AutoWidth.current.get(element.props.Key)) === null || _e === void 0 ? void 0 : _e.maxColWidth // if not auto <-
319
- : undefined // otherwise get the extrawidth
320
- , 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
321
- ? element.props.Content({
322
- item: d,
323
- key: element.props.Key,
324
- field: element.props.Field,
325
- style: style,
326
- index: i,
327
- })
328
- : element.props.Field !== undefined
329
- ? d[element.props.Field]
330
- : null));
331
- if (element.type === AdjustableColumn_1.default)
332
- if ((_j = (_h = props.AutoWidth.current.get(element.props.Key)) === null || _h === void 0 ? void 0 : _h.enabled) !== null && _j !== void 0 ? _j : true)
333
- 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({
334
- colKey: element.props.Key,
335
- colField: element.props.Field,
336
- row: d,
337
- data: d[element.props.Field],
338
- index: i,
339
- }, e) : undefined, dragStart: (props.DragStart !== undefined && props.DragStart !== null) ? (e) => props.DragStart({
340
- colKey: element.props.Key,
341
- colField: element.props.Field,
342
- row: d,
343
- data: d[element.props.Field],
344
- index: i,
345
- }, 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)
346
- ? (_o = props.AutoWidth.current.get(element.props.Key)) === null || _o === void 0 ? void 0 : _o.maxColWidth
347
- : 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 },
348
- ' ',
349
- element.props.Content !== undefined
350
- ? element.props.Content({
351
- item: d,
352
- key: element.props.Key,
353
- field: element.props.Field,
354
- style: style,
355
- index: i,
356
- })
357
- : element.props.Field !== undefined
358
- ? d[element.props.Field]
359
- : null));
360
- return null;
361
- })));
362
- })));
363
- }
364
- function Header(props) {
365
- const trRef = React.useRef(null);
366
- const [mouseDown, setMouseDown] = React.useState(0);
367
- const [currentKeys, setCurrentKeys] = React.useState(undefined);
368
- const [deltaW, setDeltaW] = React.useState(0);
369
- const [tentativeLimits, setTentativeLimits] = React.useState({ min: -Infinity, max: Infinity });
370
- const calculateDeltaLimits = React.useCallback((mapKeys, autoWidthRef) => {
371
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
372
- if (mapKeys === undefined)
373
- return ({ min: -Infinity, max: Infinity });
374
- const maxLeftAdjustment = ((_b = (_a = autoWidthRef.current.get(mapKeys[0])) === null || _a === void 0 ? void 0 : _a.maxColWidth) !== null && _b !== void 0 ? _b : 0) +
375
- ((_d = (_c = autoWidthRef.current.get(mapKeys[0])) === null || _c === void 0 ? void 0 : _c.adjustement) !== null && _d !== void 0 ? _d : 0);
376
- const minWidthLeftAdjusted = ((_f = (_e = autoWidthRef.current.get(mapKeys[0])) === null || _e === void 0 ? void 0 : _e.minWidth) !== null && _f !== void 0 ? _f : 100) - maxLeftAdjustment;
377
- const maxWidthLeftAdjusted = ((_h = (_g = autoWidthRef.current.get(mapKeys[0])) === null || _g === void 0 ? void 0 : _g.maxWidth) !== null && _h !== void 0 ? _h : 9e10) - maxLeftAdjustment;
378
- const maxRightAdjustment = ((_k = (_j = autoWidthRef.current.get(mapKeys[1])) === null || _j === void 0 ? void 0 : _j.maxColWidth) !== null && _k !== void 0 ? _k : 0) +
379
- ((_m = (_l = autoWidthRef.current.get(mapKeys[1])) === null || _l === void 0 ? void 0 : _l.adjustement) !== null && _m !== void 0 ? _m : 0);
380
- const minWidthRightAdjusted = ((_p = (_o = autoWidthRef.current.get(mapKeys[1])) === null || _o === void 0 ? void 0 : _o.minWidth) !== null && _p !== void 0 ? _p : 100) - maxRightAdjustment;
381
- const maxWidthRightAdjusted = ((_r = (_q = autoWidthRef.current.get(mapKeys[1])) === null || _q === void 0 ? void 0 : _q.maxWidth) !== null && _r !== void 0 ? _r : 9e10) - maxRightAdjustment;
382
- // Recall that a right movement is the result of a negative value on deltaW
383
- const minDeltaW = Math.abs(minWidthLeftAdjusted) < Math.abs(maxWidthRightAdjusted) ? minWidthLeftAdjusted : -maxWidthRightAdjusted;
384
- const maxDeltaW = Math.abs(minWidthRightAdjusted) < Math.abs(maxWidthLeftAdjusted) ? -minWidthRightAdjusted : maxWidthLeftAdjusted;
385
- return ({ min: minDeltaW, max: maxDeltaW });
386
- }, []);
387
- const calculateAdjustment = (key) => {
388
- var _a, _b;
389
- let adj = 0;
390
- let delta;
391
- if (deltaW > tentativeLimits.max)
392
- delta = tentativeLimits.max;
393
- else if (deltaW < tentativeLimits.min)
394
- delta = tentativeLimits.min;
395
- else
396
- delta = deltaW;
397
- if (currentKeys !== undefined && currentKeys[0] == key)
398
- adj = delta;
399
- else if (currentKeys !== undefined && currentKeys[1] == key)
400
- adj = -delta;
401
- return ((_b = (_a = props.AutoWidth.current.get(key)) === null || _a === void 0 ? void 0 : _a.adjustement) !== null && _b !== void 0 ? _b : 0) + adj;
402
- };
403
- const finishAdjustment = () => {
404
- if (currentKeys === undefined)
405
- return;
406
- if (Math.abs(deltaW) > 5) {
407
- const deltaLimits = calculateDeltaLimits(currentKeys, props.AutoWidth);
408
- let delta;
409
- if (deltaW > deltaLimits.max)
410
- delta = deltaLimits.max;
411
- else if (deltaW < deltaLimits.min)
412
- delta = deltaLimits.min;
413
- else
414
- delta = deltaW;
415
- props.SetAdjustment(currentKeys[0], delta);
416
- props.SetAdjustment(currentKeys[1], -delta);
417
- }
418
- setMouseDown(0);
419
- setTentativeLimits({ min: -Infinity, max: Infinity });
420
- setCurrentKeys(undefined);
421
- setDeltaW(0);
422
- };
423
- const getLeftKey = React.useCallback((key) => {
424
- var _a;
425
- const keys = React.Children.map((_a = props.children) !== null && _a !== void 0 ? _a : [], (element) => {
426
- var _a;
427
- if (!React.isValidElement(element)) {
428
- return null;
429
- }
430
- if ((_a = !(props.AutoWidth.current.get(element.props.Key).enabled)) !== null && _a !== void 0 ? _a : true) {
431
- return null;
432
- }
433
- if (element.type === AdjustableColumn_1.default) {
434
- return element.props.Key;
435
- }
436
- return null;
437
- }).filter((item) => item !== null);
438
- const index = keys.indexOf(key);
439
- if (index < 1)
440
- return undefined;
441
- return keys[index - 1];
442
- }, [props.children]);
443
- const onMove = React.useCallback((e) => {
444
- if (currentKeys === undefined)
445
- return;
446
- const w = e.screenX - mouseDown;
447
- setDeltaW(w);
448
- }, [mouseDown, currentKeys]);
449
- return (React.createElement("thead", { className: props.Class, style: props.Style, onMouseMove: (e) => {
450
- onMove(e.nativeEvent);
451
- e.stopPropagation();
452
- }, onMouseUp: (e) => {
453
- finishAdjustment();
454
- e.stopPropagation();
455
- }, onMouseLeave: (e) => {
456
- finishAdjustment();
457
- e.stopPropagation();
458
- } },
459
- React.createElement("tr", { ref: trRef },
460
- React.Children.map(props.children, (element) => {
461
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
462
- if (!React.isValidElement(element))
463
- return null;
464
- if (element.type === Column_1.default)
465
- if ((_b = (_a = props.AutoWidth.current.get(element.props.Key)) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true)
466
- 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)
467
- ? (_h = props.AutoWidth.current.get(element.props.Key)) === null || _h === void 0 ? void 0 : _h.maxColWidth
468
- : undefined, style: (_j = element.props.HeaderStyle) !== null && _j !== void 0 ? _j : element.props.RowStyle, extraWidth: props.ExtraWidth },
469
- ' ', (_k = element.props.children) !== null && _k !== void 0 ? _k : element.props.Key,
470
- ' '));
471
- if (element.type === AdjustableColumn_1.default)
472
- if ((_m = (_l = props.AutoWidth.current.get(element.props.Key)) === null || _l === void 0 ? void 0 : _l.enabled) !== null && _m !== void 0 ? _m : true)
473
- 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)
474
- ? (_v = props.AutoWidth.current.get(element.props.Key)) === null || _v === void 0 ? void 0 : _v.maxColWidth
475
- : undefined, startAdjustment: (e) => {
476
- let newCurrentKeys;
477
- if (getLeftKey(element.props.Key) !== undefined)
478
- newCurrentKeys = [getLeftKey(element.props.Key), element.props.Key];
479
- setCurrentKeys(newCurrentKeys);
480
- setMouseDown(e.screenX);
481
- setTentativeLimits(calculateDeltaLimits(newCurrentKeys, props.AutoWidth));
482
- setDeltaW(0);
483
- }, adjustment: calculateAdjustment(element.props.Key), style: (_w = element.props.HeaderStyle) !== null && _w !== void 0 ? _w : element.props.RowStyle },
484
- ' ', (_x = element.props.children) !== null && _x !== void 0 ? _x : element.props.Key));
485
- return null;
486
- }),
487
- React.createElement("th", { style: { width: 17, padding: 0 } }, props.LastColumn))));
488
- }
@@ -1,37 +0,0 @@
1
- import * as React from 'react';
2
- export interface DynamicTableProps<T extends object> {
3
- /**
4
- * List of T objects used to generate rows
5
- */
6
- data: T[];
7
- onClick: (data: {
8
- colKey: string;
9
- colField?: keyof T;
10
- row: T;
11
- data: T[keyof T] | null;
12
- index: number;
13
- }, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
14
- /**
15
- * Key of the collumn to sort by
16
- */
17
- sortKey: string;
18
- /**
19
- * Boolen to indicate whether the sort is ascending or descending
20
- */
21
- ascending: boolean;
22
- onSort(data: {
23
- colKey: string;
24
- colField?: keyof T;
25
- ascending: boolean;
26
- }): void;
27
- tableClass?: string;
28
- tableStyle?: React.CSSProperties;
29
- theadStyle?: React.CSSProperties;
30
- theadClass?: string;
31
- tbodyStyle?: React.CSSProperties;
32
- tbodyClass?: string;
33
- selected?(data: T): boolean;
34
- rowStyle?: React.CSSProperties;
35
- keySelector?: (data: T) => string;
36
- }
37
- export declare function DynamicTable<T extends object>(props: DynamicTableProps<T>): JSX.Element | null;
@@ -1,15 +0,0 @@
1
- import { TableProps } from './Table';
2
- interface ISearchableTableProps<T> extends TableProps<T> {
3
- /**
4
- * Function used to filter data
5
- * @param item: The T to be matched
6
- * @param search: The string to search by
7
- * @returns: true if the item should be shown in the Table
8
- */
9
- matchSearch: (item: T, search: string) => boolean;
10
- }
11
- /**
12
- * A Table with an input Field to search on top
13
- */
14
- export declare function SearchableTable<T>(props: ISearchableTableProps<T>): JSX.Element;
15
- export {};
@@ -1,19 +0,0 @@
1
- import * as React from 'react';
2
- import { Column } from './Table';
3
- export interface ISelectTableProps<T> {
4
- cols: Column<T>[];
5
- data: T[];
6
- sortKey: string;
7
- ascending: boolean;
8
- tableClass?: string;
9
- tableStyle?: React.CSSProperties;
10
- theadStyle?: React.CSSProperties;
11
- theadClass?: string;
12
- tbodyStyle?: React.CSSProperties;
13
- tbodyClass?: string;
14
- rowStyle?: React.CSSProperties;
15
- onSelection: (selected: T[]) => void;
16
- KeyField: keyof T;
17
- selectAllCounter?: number;
18
- }
19
- export declare function SelectTable<T>(props: ISelectTableProps<T>): JSX.Element;
@@ -1,102 +0,0 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // SelectTable.tsx - Gbtc
4
- //
5
- // Copyright © 2021, Grid Protection Alliance. All Rights Reserved.
6
- //
7
- // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
8
- // the NOTICE file distributed with this work for additional information regarding copyright ownership.
9
- // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
10
- // file except in compliance with the License. You may obtain a copy of the License at:
11
- //
12
- // http://opensource.org/licenses/MIT
13
- //
14
- // Unless agreed to in writing, the subject software distributed under the License is distributed on an
15
- // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
16
- // License for the specific language governing permissions and limitations.
17
- //
18
- // Code Modification History:
19
- // ----------------------------------------------------------------------------------------------------
20
- // 01/22/2021 - C. Lackner
21
- // Generated original version of source code.
22
- //
23
- // ******************************************************************************************************
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.SelectTable = SelectTable;
26
- const React = require("react");
27
- const _ = require("lodash");
28
- const Table_1 = require("./Table");
29
- function SelectTable(props) {
30
- const didMountRef = React.useRef(false);
31
- const [data, setData] = React.useState(props.data);
32
- const [selected, setSelected] = React.useState([]);
33
- const [sortKey, setSortKey] = React.useState(props.sortKey);
34
- const [ascending, setAscending] = React.useState(props.ascending);
35
- React.useEffect(() => {
36
- if (didMountRef.current)
37
- selectAll();
38
- else
39
- didMountRef.current = true;
40
- }, [props.selectAllCounter]);
41
- React.useEffect(() => {
42
- if (props.data.length !== data.length)
43
- setData(props.data);
44
- }, [props.data]);
45
- React.useEffect(() => {
46
- setSelected((d) => d.filter(keyItem => data.findIndex(item => item[props.KeyField] === keyItem) > -1));
47
- }, [data]);
48
- React.useEffect(() => {
49
- const sortColumn = props.cols.filter(col => col.key === sortKey)[0];
50
- if (sortColumn === undefined || sortColumn.field === undefined)
51
- return;
52
- const sortField = sortColumn.field;
53
- setData((lst) => (_.orderBy(lst, [sortField], [(ascending ? "asc" : "desc")])));
54
- }, [ascending, sortKey]);
55
- React.useEffect(() => {
56
- props.onSelection(data.filter(item => selected.findIndex(key => key === item[props.KeyField]) > -1));
57
- }, [selected]);
58
- function handleClick(d) {
59
- const sIndex = selected.findIndex(item => item === d.row[props.KeyField]);
60
- if (sIndex === -1)
61
- setSelected((od) => [...od, d.row[props.KeyField]]);
62
- else
63
- setSelected((od) => od.filter(item => item !== d.row[props.KeyField]));
64
- }
65
- function selectAll() {
66
- setSelected((d) => { if (d.length === data.length)
67
- return [];
68
- else
69
- return data.map(row => row[props.KeyField]); });
70
- }
71
- function handleSort(d) {
72
- if (d.colKey === sortKey)
73
- setAscending(!ascending);
74
- else
75
- setSortKey(d.colKey);
76
- }
77
- const tableProps = {
78
- cols: [
79
- { key: 'gemstone-checkbox', field: props.KeyField, label: '', headerStyle: { width: '4em' }, rowStyle: { width: '4em' }, content: (item) => {
80
- const index = selected.findIndex(i => i === item[props.KeyField]);
81
- const iconClass = index > -1 ? 'fa-check-square-o' : 'fa-square-o';
82
- return React.createElement("div", { style: { textAlign: 'center', verticalAlign: 'middle' } },
83
- React.createElement("i", { className: `fa ${iconClass} fa-3x` }));
84
- } },
85
- ...props.cols
86
- ],
87
- data,
88
- onClick: handleClick,
89
- sortKey,
90
- ascending,
91
- onSort: handleSort,
92
- tableClass: props.tableClass,
93
- tableStyle: props.tableStyle,
94
- theadStyle: props.theadStyle,
95
- theadClass: props.theadClass,
96
- tbodyStyle: props.tbodyStyle,
97
- tbodyClass: props.tbodyClass,
98
- selected: (d) => false,
99
- rowStyle: props.rowStyle
100
- };
101
- return React.createElement(Table_1.default, Object.assign({}, tableProps));
102
- }