@gpa-gemstone/react-table 1.2.50 → 1.2.52
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/lib/AdjustableTable/AdjustableColumn.d.ts +14 -16
- package/lib/AdjustableTable/AdjustableColumn.js +141 -52
- package/lib/AdjustableTable/Column.d.ts +23 -31
- package/lib/AdjustableTable/Column.js +53 -78
- package/lib/AdjustableTable/Table.d.ts +107 -0
- package/lib/AdjustableTable/Table.js +474 -0
- package/lib/DynamicTable.js +9 -10
- package/lib/Paging.js +25 -15
- package/lib/SearchableTable.js +8 -19
- package/lib/SelectTable.js +37 -56
- package/lib/Table.js +17 -28
- package/lib/index.d.ts +3 -3
- package/lib/index.js +11 -11
- package/package.json +3 -3
- package/lib/AdjustableTable/AdjustableTable.d.ts +0 -102
- package/lib/AdjustableTable/AdjustableTable.js +0 -273
|
@@ -0,0 +1,474 @@
|
|
|
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 tblref = 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 [extraWidthPerRow, setExtraWidthPerRow] = React.useState(0);
|
|
51
|
+
const setTableWidth = React.useCallback(_.debounce(() => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
setCurrentTableWidth((_b = (_a = tblref.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) !== null && _b !== void 0 ? _b : 0);
|
|
54
|
+
}, 500), []);
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
const element = tblref === null || tblref === void 0 ? void 0 : tblref.current;
|
|
57
|
+
if (element == null)
|
|
58
|
+
return;
|
|
59
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
60
|
+
setTableWidth();
|
|
61
|
+
});
|
|
62
|
+
resizeObserver.observe(element);
|
|
63
|
+
return () => {
|
|
64
|
+
resizeObserver.disconnect();
|
|
65
|
+
};
|
|
66
|
+
}, []);
|
|
67
|
+
React.useEffect(() => {
|
|
68
|
+
autoWidth.current = new Map();
|
|
69
|
+
setAutoWidthVersion(0);
|
|
70
|
+
}, [currentTableWidth]);
|
|
71
|
+
React.useEffect(() => {
|
|
72
|
+
var _a;
|
|
73
|
+
let t = 0;
|
|
74
|
+
autoWidth.current.forEach((v) => {
|
|
75
|
+
t = t + v.maxColWidth;
|
|
76
|
+
});
|
|
77
|
+
if (t > currentTableWidth - 17 && currentTableWidth > 0) {
|
|
78
|
+
const hideKeys = [];
|
|
79
|
+
const showKeys = [];
|
|
80
|
+
let t = 0;
|
|
81
|
+
let colW = 0;
|
|
82
|
+
autoWidth.current.forEach((v, k) => {
|
|
83
|
+
t = t + v.maxColWidth;
|
|
84
|
+
if (t < currentTableWidth - 17) {
|
|
85
|
+
showKeys.push(k);
|
|
86
|
+
colW += v.maxColWidth;
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
hideKeys.push(k);
|
|
90
|
+
});
|
|
91
|
+
const numEnabledColumns = showKeys.length;
|
|
92
|
+
if (Array.from(autoWidth.current.values()).filter(autoWidth => !autoWidth.enabled).length == hideKeys.length) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (colCountRef.current !== null)
|
|
96
|
+
clearTimeout(colCountRef.current);
|
|
97
|
+
colCountRef.current = setTimeout(() => {
|
|
98
|
+
var _a;
|
|
99
|
+
hideKeys.forEach((k) => (autoWidth.current.get(k).enabled = false));
|
|
100
|
+
showKeys.forEach((k) => (autoWidth.current.get(k).enabled = true));
|
|
101
|
+
const numOfColsWithAutoCSS = Array.from(autoWidth.current.values()).filter(autoWidth => autoWidth.isAuto && autoWidth.enabled).length;
|
|
102
|
+
const numOfColsWithUndefinedCSS = Array.from(autoWidth.current.values()).filter(autoWidth => autoWidth.isUndefined && autoWidth.enabled).length;
|
|
103
|
+
let colsToDivideBy = numEnabledColumns; // Split the extra across all cols
|
|
104
|
+
if (numOfColsWithAutoCSS > 0) { // Split only on the css auto-cols and no css undefined cols
|
|
105
|
+
colsToDivideBy = numOfColsWithAutoCSS;
|
|
106
|
+
}
|
|
107
|
+
if (numOfColsWithUndefinedCSS > 0 && numOfColsWithAutoCSS == 0) { // Split only on the css undefined if there are no auto-cols
|
|
108
|
+
colsToDivideBy = numOfColsWithUndefinedCSS;
|
|
109
|
+
}
|
|
110
|
+
const extraSpace = (currentTableWidth - 17 - colW - numEnabledColumns) / colsToDivideBy;
|
|
111
|
+
setExtraWidthPerRow(extraSpace);
|
|
112
|
+
(_a = props.ReduceWidthCallback) === null || _a === void 0 ? void 0 : _a.call(props, hideKeys);
|
|
113
|
+
setAutoWidthVersion((v) => v + 1);
|
|
114
|
+
}, 500);
|
|
115
|
+
}
|
|
116
|
+
else if (currentTableWidth > 0) {
|
|
117
|
+
const numEnabledColumns = Array.from(autoWidth.current.values()).filter(autoWidth => autoWidth.enabled).length;
|
|
118
|
+
const numOfColsWithAutoCSS = Array.from(autoWidth.current.values()).filter(autoWidth => autoWidth.isAuto && autoWidth.enabled).length;
|
|
119
|
+
const colsToDivideBy = (numOfColsWithAutoCSS > 0) ? numOfColsWithAutoCSS : numEnabledColumns;
|
|
120
|
+
const extraSpace = (currentTableWidth - 17 - t - numEnabledColumns) / colsToDivideBy;
|
|
121
|
+
setExtraWidthPerRow(extraSpace);
|
|
122
|
+
(_a = props.ReduceWidthCallback) === null || _a === void 0 ? void 0 : _a.call(props, []);
|
|
123
|
+
}
|
|
124
|
+
}, [autoWidthVersion]);
|
|
125
|
+
React.useEffect(() => {
|
|
126
|
+
// if there are keys in the map not present in children, map is old
|
|
127
|
+
const children = React.Children.toArray(props.children);
|
|
128
|
+
const childKeys = [];
|
|
129
|
+
const mapKeys = autoWidth.current.keys();
|
|
130
|
+
children.forEach(child => {
|
|
131
|
+
if (!React.isValidElement(child))
|
|
132
|
+
return;
|
|
133
|
+
if (child.type === Column_1.default ||
|
|
134
|
+
child.type === AdjustableColumn_1.default)
|
|
135
|
+
childKeys.push(child.props.Key);
|
|
136
|
+
});
|
|
137
|
+
for (const key of mapKeys) {
|
|
138
|
+
if (childKeys.includes(key)) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
autoWidth.current.clear();
|
|
143
|
+
setAutoWidthVersion(0);
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}, [props.children]);
|
|
148
|
+
const handleSort = React.useCallback((data, event) => {
|
|
149
|
+
if (data.colKey !== null)
|
|
150
|
+
props.OnSort(data, event);
|
|
151
|
+
}, [props.OnSort]);
|
|
152
|
+
const setWidth = React.useCallback((colKey, key, width, isAuto, isUndefined) => {
|
|
153
|
+
var _a, _b, _c, _d, _e, _f;
|
|
154
|
+
if (!autoWidth.current.has(colKey)) { // does the column exist
|
|
155
|
+
autoWidth.current.set(colKey, {
|
|
156
|
+
maxColWidth: width,
|
|
157
|
+
width: new Map([[key, width]]),
|
|
158
|
+
enabled: true,
|
|
159
|
+
adjustement: 0,
|
|
160
|
+
isAuto: isAuto,
|
|
161
|
+
isUndefined: isUndefined
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
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
|
|
165
|
+
(_c = autoWidth.current.get(colKey)) === null || _c === void 0 ? void 0 : _c.width.set(key, width); // add the width for this key
|
|
166
|
+
autoWidth.current.get(colKey).isAuto = isAuto;
|
|
167
|
+
if (width > ((_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
|
|
168
|
+
autoWidth.current.get(colKey).maxColWidth = width; // set max to width
|
|
169
|
+
}
|
|
170
|
+
else if (autoWidth.current.get(colKey).width.get(key) == width) { // width == newW
|
|
171
|
+
autoWidth.current.get(colKey).isAuto = isAuto;
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
autoWidth.current.get(colKey).width.set(key, width); // otherwise, it exists, just set the width
|
|
176
|
+
autoWidth.current.get(colKey).isAuto = isAuto;
|
|
177
|
+
if (width == ((_f = autoWidth.current.get(colKey)) === null || _f === void 0 ? void 0 : _f.maxColWidth)) // check against max
|
|
178
|
+
autoWidth.current.get(colKey).maxColWidth = Math.max(...autoWidth.current.get(colKey).width.values());
|
|
179
|
+
}
|
|
180
|
+
//cancel ref
|
|
181
|
+
//Add a Timer - runs within 10 ms from when the Timer started to avoid React thinking this is an indinfinte loop....
|
|
182
|
+
if (throtleRef.current !== null)
|
|
183
|
+
clearTimeout(throtleRef.current);
|
|
184
|
+
throtleRef.current = setTimeout(() => {
|
|
185
|
+
setAutoWidthVersion((v) => v + 1);
|
|
186
|
+
}, 10);
|
|
187
|
+
}, []);
|
|
188
|
+
const setAdjustment = React.useCallback((colKey, w) => {
|
|
189
|
+
if (!autoWidth.current.has(colKey) || autoWidth.current.get(colKey) == undefined) { // doesnt exist/is undefined
|
|
190
|
+
autoWidth.current.set(colKey, {
|
|
191
|
+
maxColWidth: 0,
|
|
192
|
+
width: new Map(),
|
|
193
|
+
enabled: true,
|
|
194
|
+
adjustement: w,
|
|
195
|
+
isAuto: false,
|
|
196
|
+
isUndefined: false
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
const x = autoWidth.current.get(colKey);
|
|
201
|
+
if ((x === null || x === void 0 ? void 0 : x.adjustement) != undefined)
|
|
202
|
+
x.adjustement += w;
|
|
203
|
+
}
|
|
204
|
+
//cancel ref
|
|
205
|
+
//Add a Timer - runs within 10 ms from when the Timer started to avoid React thinking this is an indinfinte loop....
|
|
206
|
+
if (throtleRef.current !== null)
|
|
207
|
+
clearTimeout(throtleRef.current);
|
|
208
|
+
throtleRef.current = setTimeout(() => {
|
|
209
|
+
setAutoWidthVersion((v) => v + 1);
|
|
210
|
+
}, 10);
|
|
211
|
+
}, []);
|
|
212
|
+
const setMinWidth = React.useCallback((colKey, w) => {
|
|
213
|
+
var _a;
|
|
214
|
+
if (!autoWidth.current.has(colKey))
|
|
215
|
+
autoWidth.current.set(colKey, {
|
|
216
|
+
maxColWidth: 0,
|
|
217
|
+
width: new Map(),
|
|
218
|
+
enabled: true,
|
|
219
|
+
adjustement: 0,
|
|
220
|
+
minWidth: w,
|
|
221
|
+
isAuto: false,
|
|
222
|
+
isUndefined: false
|
|
223
|
+
});
|
|
224
|
+
else if (((_a = autoWidth.current.get(colKey)) === null || _a === void 0 ? void 0 : _a.minWidth) == w)
|
|
225
|
+
return;
|
|
226
|
+
autoWidth.current.get(colKey).minWidth = w;
|
|
227
|
+
//cancel ref
|
|
228
|
+
//Add a Timer - runs within 10 ms from when the Timer started to avoid React thinking this is an indinfinte loop....
|
|
229
|
+
if (throtleRef.current !== null)
|
|
230
|
+
clearTimeout(throtleRef.current);
|
|
231
|
+
throtleRef.current = setTimeout(() => {
|
|
232
|
+
setAutoWidthVersion((v) => v + 1);
|
|
233
|
+
}, 10);
|
|
234
|
+
}, []);
|
|
235
|
+
const setMaxWidth = React.useCallback((colKey, w) => {
|
|
236
|
+
var _a;
|
|
237
|
+
if (!autoWidth.current.has(colKey))
|
|
238
|
+
autoWidth.current.set(colKey, {
|
|
239
|
+
maxColWidth: 0,
|
|
240
|
+
width: new Map(),
|
|
241
|
+
enabled: true,
|
|
242
|
+
adjustement: 0,
|
|
243
|
+
maxWidth: w,
|
|
244
|
+
isAuto: false,
|
|
245
|
+
isUndefined: false
|
|
246
|
+
});
|
|
247
|
+
else if (((_a = autoWidth.current.get(colKey)) === null || _a === void 0 ? void 0 : _a.maxWidth) == w)
|
|
248
|
+
return;
|
|
249
|
+
autoWidth.current.get(colKey).maxWidth = w;
|
|
250
|
+
//cancel ref
|
|
251
|
+
//Add a Timer - runs within 10 ms from when the Timer started to avoid React thinking this is an indinfinte loop....
|
|
252
|
+
if (throtleRef.current !== null)
|
|
253
|
+
clearTimeout(throtleRef.current);
|
|
254
|
+
throtleRef.current = setTimeout(() => {
|
|
255
|
+
setAutoWidthVersion((v) => v + 1);
|
|
256
|
+
}, 10);
|
|
257
|
+
}, []);
|
|
258
|
+
return (React.createElement("table", { className: props.TableClass !== undefined ? props.TableClass : 'table table-hover', style: (_a = props.TableStyle) !== null && _a !== void 0 ? _a : defaultTableStyle, ref: tblref },
|
|
259
|
+
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),
|
|
260
|
+
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 }, props.children),
|
|
261
|
+
props.LastRow !== undefined ? (React.createElement("tr", { style: props.RowStyle !== undefined ? Object.assign({}, props.RowStyle) : {}, key: -1 }, props.LastRow)) : null));
|
|
262
|
+
}
|
|
263
|
+
function Rows(props) {
|
|
264
|
+
if (props.Data.length === 0)
|
|
265
|
+
return null;
|
|
266
|
+
const onClick = React.useCallback((e, item, index) => {
|
|
267
|
+
if (props.OnClick !== undefined)
|
|
268
|
+
props.OnClick({
|
|
269
|
+
colKey: undefined,
|
|
270
|
+
colField: undefined,
|
|
271
|
+
row: item,
|
|
272
|
+
data: null,
|
|
273
|
+
index: index,
|
|
274
|
+
}, e);
|
|
275
|
+
}, [props.OnClick]);
|
|
276
|
+
return (React.createElement("tbody", { style: props.BodyStyle, className: props.BodyClass }, props.Data.map((d, i) => {
|
|
277
|
+
const style = props.RowStyle !== undefined ? Object.assign({}, props.RowStyle) : {};
|
|
278
|
+
if (style.cursor === undefined && (props.OnClick !== undefined || props.DragStart !== undefined))
|
|
279
|
+
style.cursor = 'pointer';
|
|
280
|
+
if (props.Selected !== undefined && props.Selected(d, i))
|
|
281
|
+
style.backgroundColor = 'yellow';
|
|
282
|
+
const key = props.KeySelector(d, i);
|
|
283
|
+
return (React.createElement("tr", { key: key, style: style, onClick: (e) => onClick(e, d, i) }, React.Children.map(props.children, (element) => {
|
|
284
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
285
|
+
if (!React.isValidElement(element))
|
|
286
|
+
return null;
|
|
287
|
+
if (element.type === Column_1.default)
|
|
288
|
+
if ((_b = (_a = props.AutoWidth.current.get(element.props.Key)) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true)
|
|
289
|
+
return (React.createElement(Column_1.ColumnDataWrapper, { key: element.key, extraWidth: props.ExtraWidth, onClick: (props.OnClick !== undefined && props.OnClick !== null) ? (e) => props.OnClick({
|
|
290
|
+
colKey: element.props.Key,
|
|
291
|
+
colField: element.props.Field,
|
|
292
|
+
row: d,
|
|
293
|
+
data: d[element.props.Field],
|
|
294
|
+
index: i,
|
|
295
|
+
}, e) : undefined, dragStart: (props.DragStart !== undefined && props.DragStart !== null) ? (e) => props.DragStart({
|
|
296
|
+
colKey: element.props.Key,
|
|
297
|
+
colField: element.props.Field,
|
|
298
|
+
row: d,
|
|
299
|
+
data: d[element.props.Field],
|
|
300
|
+
index: i,
|
|
301
|
+
}, e) : undefined, setWidth: (w, a, u) => props.SetWidth(element.props.Key, key, Math.floor(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)
|
|
302
|
+
? (_e = props.AutoWidth.current.get(element.props.Key)) === null || _e === void 0 ? void 0 : _e.maxColWidth // if not auto <-
|
|
303
|
+
: undefined // otherwise get the extrawidth
|
|
304
|
+
, 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
|
|
305
|
+
? element.props.Content({
|
|
306
|
+
item: d,
|
|
307
|
+
key: element.props.Key,
|
|
308
|
+
field: element.props.Field,
|
|
309
|
+
style: style,
|
|
310
|
+
index: i,
|
|
311
|
+
})
|
|
312
|
+
: element.props.Field !== undefined
|
|
313
|
+
? d[element.props.Field]
|
|
314
|
+
: null));
|
|
315
|
+
if (element.type === AdjustableColumn_1.default)
|
|
316
|
+
if ((_j = (_h = props.AutoWidth.current.get(element.props.Key)) === null || _h === void 0 ? void 0 : _h.enabled) !== null && _j !== void 0 ? _j : true)
|
|
317
|
+
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({
|
|
318
|
+
colKey: element.props.Key,
|
|
319
|
+
colField: element.props.Field,
|
|
320
|
+
row: d,
|
|
321
|
+
data: d[element.props.Field],
|
|
322
|
+
index: i,
|
|
323
|
+
}, e) : undefined, dragStart: (props.DragStart !== undefined && props.DragStart !== null) ? (e) => props.DragStart({
|
|
324
|
+
colKey: element.props.Key,
|
|
325
|
+
colField: element.props.Field,
|
|
326
|
+
row: d,
|
|
327
|
+
data: d[element.props.Field],
|
|
328
|
+
index: i,
|
|
329
|
+
}, e) : undefined, setWidth: (w, a, u) => props.SetWidth(element.props.Key, key, Math.floor(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)
|
|
330
|
+
? (_o = props.AutoWidth.current.get(element.props.Key)) === null || _o === void 0 ? void 0 : _o.maxColWidth
|
|
331
|
+
: 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 },
|
|
332
|
+
' ',
|
|
333
|
+
element.props.Content !== undefined
|
|
334
|
+
? element.props.Content({
|
|
335
|
+
item: d,
|
|
336
|
+
key: element.props.Key,
|
|
337
|
+
field: element.props.Field,
|
|
338
|
+
style: style,
|
|
339
|
+
index: i,
|
|
340
|
+
})
|
|
341
|
+
: element.props.Field !== undefined
|
|
342
|
+
? d[element.props.Field]
|
|
343
|
+
: null));
|
|
344
|
+
return null;
|
|
345
|
+
})));
|
|
346
|
+
})));
|
|
347
|
+
}
|
|
348
|
+
function Header(props) {
|
|
349
|
+
const trRef = React.useRef(null);
|
|
350
|
+
const [mouseDown, setMouseDown] = React.useState(0);
|
|
351
|
+
const [currentKeys, setCurrentKeys] = React.useState(undefined);
|
|
352
|
+
const [deltaW, setDeltaW] = React.useState(0);
|
|
353
|
+
const [tentativeLimits, setTentativeLimits] = React.useState({ min: -Infinity, max: Infinity });
|
|
354
|
+
const calculateDeltaLimits = React.useCallback((mapKeys, autoWidthRef) => {
|
|
355
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
356
|
+
if (mapKeys === undefined)
|
|
357
|
+
return ({ min: -Infinity, max: Infinity });
|
|
358
|
+
const maxLeftAdjustment = ((_b = (_a = autoWidthRef.current.get(mapKeys[0])) === null || _a === void 0 ? void 0 : _a.maxColWidth) !== null && _b !== void 0 ? _b : 0) +
|
|
359
|
+
((_d = (_c = autoWidthRef.current.get(mapKeys[0])) === null || _c === void 0 ? void 0 : _c.adjustement) !== null && _d !== void 0 ? _d : 0);
|
|
360
|
+
const minWidthLeftAdjusted = ((_f = (_e = autoWidthRef.current.get(mapKeys[0])) === null || _e === void 0 ? void 0 : _e.minWidth) !== null && _f !== void 0 ? _f : 100) - maxLeftAdjustment;
|
|
361
|
+
const maxWidthLeftAdjusted = ((_h = (_g = autoWidthRef.current.get(mapKeys[0])) === null || _g === void 0 ? void 0 : _g.maxWidth) !== null && _h !== void 0 ? _h : 9e10) - maxLeftAdjustment;
|
|
362
|
+
const maxRightAdjustment = ((_k = (_j = autoWidthRef.current.get(mapKeys[1])) === null || _j === void 0 ? void 0 : _j.maxColWidth) !== null && _k !== void 0 ? _k : 0) +
|
|
363
|
+
((_m = (_l = autoWidthRef.current.get(mapKeys[1])) === null || _l === void 0 ? void 0 : _l.adjustement) !== null && _m !== void 0 ? _m : 0);
|
|
364
|
+
const minWidthRightAdjusted = ((_p = (_o = autoWidthRef.current.get(mapKeys[1])) === null || _o === void 0 ? void 0 : _o.minWidth) !== null && _p !== void 0 ? _p : 100) - maxRightAdjustment;
|
|
365
|
+
const maxWidthRightAdjusted = ((_r = (_q = autoWidthRef.current.get(mapKeys[1])) === null || _q === void 0 ? void 0 : _q.maxWidth) !== null && _r !== void 0 ? _r : 9e10) - maxRightAdjustment;
|
|
366
|
+
// Recall that a right movement is the result of a negative value on deltaW
|
|
367
|
+
const minDeltaW = Math.abs(minWidthLeftAdjusted) < Math.abs(maxWidthRightAdjusted) ? minWidthLeftAdjusted : -maxWidthRightAdjusted;
|
|
368
|
+
const maxDeltaW = Math.abs(minWidthRightAdjusted) < Math.abs(maxWidthLeftAdjusted) ? -minWidthRightAdjusted : maxWidthLeftAdjusted;
|
|
369
|
+
return ({ min: minDeltaW, max: maxDeltaW });
|
|
370
|
+
}, []);
|
|
371
|
+
const calculateAdjustment = (key) => {
|
|
372
|
+
var _a, _b;
|
|
373
|
+
let adj = 0;
|
|
374
|
+
let delta;
|
|
375
|
+
if (deltaW > tentativeLimits.max)
|
|
376
|
+
delta = tentativeLimits.max;
|
|
377
|
+
else if (deltaW < tentativeLimits.min)
|
|
378
|
+
delta = tentativeLimits.min;
|
|
379
|
+
else
|
|
380
|
+
delta = deltaW;
|
|
381
|
+
if (currentKeys !== undefined && currentKeys[0] == key)
|
|
382
|
+
adj = delta;
|
|
383
|
+
else if (currentKeys !== undefined && currentKeys[1] == key)
|
|
384
|
+
adj = -delta;
|
|
385
|
+
console.log(tentativeLimits);
|
|
386
|
+
console.log(delta);
|
|
387
|
+
return ((_b = (_a = props.AutoWidth.current.get(key)) === null || _a === void 0 ? void 0 : _a.adjustement) !== null && _b !== void 0 ? _b : 0) + adj;
|
|
388
|
+
};
|
|
389
|
+
const finishAdjustment = () => {
|
|
390
|
+
if (currentKeys === undefined)
|
|
391
|
+
return;
|
|
392
|
+
if (Math.abs(deltaW) > 5) {
|
|
393
|
+
const deltaLimits = calculateDeltaLimits(currentKeys, props.AutoWidth);
|
|
394
|
+
let delta;
|
|
395
|
+
if (deltaW > deltaLimits.max)
|
|
396
|
+
delta = deltaLimits.max;
|
|
397
|
+
else if (deltaW < deltaLimits.min)
|
|
398
|
+
delta = deltaLimits.min;
|
|
399
|
+
else
|
|
400
|
+
delta = deltaW;
|
|
401
|
+
props.SetAdjustment(currentKeys[0], delta);
|
|
402
|
+
props.SetAdjustment(currentKeys[1], -delta);
|
|
403
|
+
}
|
|
404
|
+
setMouseDown(0);
|
|
405
|
+
setTentativeLimits({ min: -Infinity, max: Infinity });
|
|
406
|
+
setCurrentKeys(undefined);
|
|
407
|
+
setDeltaW(0);
|
|
408
|
+
};
|
|
409
|
+
const getLeftKey = React.useCallback((key) => {
|
|
410
|
+
var _a;
|
|
411
|
+
const keys = React.Children.map((_a = props.children) !== null && _a !== void 0 ? _a : [], (element) => {
|
|
412
|
+
var _a;
|
|
413
|
+
if (!React.isValidElement(element)) {
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
if ((_a = !(props.AutoWidth.current.get(element.props.Key).enabled)) !== null && _a !== void 0 ? _a : true) {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
if (element.type === AdjustableColumn_1.default) {
|
|
420
|
+
return element.props.Key;
|
|
421
|
+
}
|
|
422
|
+
return null;
|
|
423
|
+
}).filter((item) => item !== null);
|
|
424
|
+
const index = keys.indexOf(key);
|
|
425
|
+
if (index < 1)
|
|
426
|
+
return undefined;
|
|
427
|
+
return keys[index - 1];
|
|
428
|
+
}, [props.children]);
|
|
429
|
+
const onMove = React.useCallback((e) => {
|
|
430
|
+
if (currentKeys === undefined)
|
|
431
|
+
return;
|
|
432
|
+
const w = e.screenX - mouseDown;
|
|
433
|
+
setDeltaW(w);
|
|
434
|
+
}, [mouseDown, currentKeys]);
|
|
435
|
+
return (React.createElement("thead", { className: props.Class, style: props.Style, onMouseMove: (e) => {
|
|
436
|
+
onMove(e.nativeEvent);
|
|
437
|
+
e.stopPropagation();
|
|
438
|
+
}, onMouseUp: (e) => {
|
|
439
|
+
finishAdjustment();
|
|
440
|
+
e.stopPropagation();
|
|
441
|
+
}, onMouseLeave: (e) => {
|
|
442
|
+
finishAdjustment();
|
|
443
|
+
e.stopPropagation();
|
|
444
|
+
} },
|
|
445
|
+
React.createElement("tr", { ref: trRef },
|
|
446
|
+
React.Children.map(props.children, (element) => {
|
|
447
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
448
|
+
if (!React.isValidElement(element))
|
|
449
|
+
return null;
|
|
450
|
+
if (element.type === Column_1.default)
|
|
451
|
+
if ((_b = (_a = props.AutoWidth.current.get(element.props.Key)) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true)
|
|
452
|
+
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, Math.floor(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)
|
|
453
|
+
? (_h = props.AutoWidth.current.get(element.props.Key)) === null || _h === void 0 ? void 0 : _h.maxColWidth
|
|
454
|
+
: undefined, style: (_j = element.props.HeaderStyle) !== null && _j !== void 0 ? _j : element.props.RowStyle, extraWidth: props.ExtraWidth },
|
|
455
|
+
' ', (_k = element.props.children) !== null && _k !== void 0 ? _k : element.props.Key,
|
|
456
|
+
' '));
|
|
457
|
+
if (element.type === AdjustableColumn_1.default)
|
|
458
|
+
if ((_m = (_l = props.AutoWidth.current.get(element.props.Key)) === null || _l === void 0 ? void 0 : _l.enabled) !== null && _m !== void 0 ? _m : true)
|
|
459
|
+
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)
|
|
460
|
+
? (_v = props.AutoWidth.current.get(element.props.Key)) === null || _v === void 0 ? void 0 : _v.maxColWidth
|
|
461
|
+
: undefined, startAdjustment: (e) => {
|
|
462
|
+
let newCurrentKeys;
|
|
463
|
+
if (getLeftKey(element.props.Key) !== undefined)
|
|
464
|
+
newCurrentKeys = [getLeftKey(element.props.Key), element.props.Key];
|
|
465
|
+
setCurrentKeys(newCurrentKeys);
|
|
466
|
+
setMouseDown(e.screenX);
|
|
467
|
+
setTentativeLimits(calculateDeltaLimits(newCurrentKeys, props.AutoWidth));
|
|
468
|
+
setDeltaW(0);
|
|
469
|
+
}, adjustment: calculateAdjustment(element.props.Key), style: (_w = element.props.HeaderStyle) !== null && _w !== void 0 ? _w : element.props.RowStyle },
|
|
470
|
+
' ', (_x = element.props.children) !== null && _x !== void 0 ? _x : element.props.Key));
|
|
471
|
+
return null;
|
|
472
|
+
}),
|
|
473
|
+
React.createElement("th", { style: { width: 17, padding: 0 } }, props.LastColumn))));
|
|
474
|
+
}
|
package/lib/DynamicTable.js
CHANGED
|
@@ -23,21 +23,20 @@
|
|
|
23
23
|
// ******************************************************************************************************
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.DynamicTable = DynamicTable;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
for (
|
|
35
|
-
|
|
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:
|
|
40
|
-
React.createElement(Table_1.Rows, { Data: props.data, Cols: cols, RowStyle: props.rowStyle, BodyStyle: props.tbodyStyle, BodyClass: props.tbodyClass, Click:
|
|
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,15 +23,25 @@ exports.default = default_1;
|
|
|
23
23
|
// Generated original version of source code.
|
|
24
24
|
//
|
|
25
25
|
// ******************************************************************************************************
|
|
26
|
-
|
|
26
|
+
const React = require("react");
|
|
27
27
|
function default_1(props) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
const [pages, setPages] = React.useState([]);
|
|
29
|
+
const nPages = 7;
|
|
30
|
+
const minPg = React.useMemo(() => {
|
|
31
|
+
const min = Math.min(...pages);
|
|
32
|
+
if (isFinite(min) && !isNaN(min))
|
|
33
|
+
return min;
|
|
34
|
+
return 0;
|
|
35
|
+
}, [pages]);
|
|
36
|
+
const maxPg = React.useMemo(() => {
|
|
37
|
+
const max = Math.max(...pages);
|
|
38
|
+
if (isFinite(max) && !isNaN(max))
|
|
39
|
+
return max;
|
|
40
|
+
return 0;
|
|
41
|
+
}, [pages]);
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
const display = [];
|
|
44
|
+
let p = Math.max(props.Current - Math.floor(nPages / 2), 1);
|
|
35
45
|
if (props.Total - p < nPages)
|
|
36
46
|
p = Math.max(props.Total - nPages + 1, 1);
|
|
37
47
|
while (p <= props.Total && display.length < nPages) {
|
|
@@ -41,25 +51,25 @@ function default_1(props) {
|
|
|
41
51
|
setPages(display);
|
|
42
52
|
}, [props.Total, props.Current]);
|
|
43
53
|
return React.createElement("ul", { className: "pagination justify-content-center" },
|
|
44
|
-
React.createElement("li", { className: "page-item" + (minPg
|
|
45
|
-
React.createElement("a", { className: "page-link", onClick:
|
|
54
|
+
React.createElement("li", { className: "page-item" + (minPg <= 1 ? ' disabled' : ""), key: "previous" },
|
|
55
|
+
React.createElement("a", { className: "page-link", onClick: () => {
|
|
46
56
|
if (minPg > 1)
|
|
47
57
|
props.SetPage(Math.max(props.Current - nPages, 1));
|
|
48
58
|
} }, "Previous")),
|
|
49
59
|
minPg > 2 ? React.createElement(React.Fragment, null,
|
|
50
60
|
React.createElement("li", { className: "page-item", key: "1" },
|
|
51
|
-
React.createElement("a", { className: "page-link", onClick:
|
|
61
|
+
React.createElement("a", { className: "page-link", onClick: () => props.SetPage(1) }, "1")),
|
|
52
62
|
React.createElement("li", { className: "page-item disabled", key: "skip-1" },
|
|
53
63
|
React.createElement("a", { className: "page-link" }, "..."))) : null,
|
|
54
|
-
pages.map(
|
|
55
|
-
React.createElement("a", { className: "page-link", onClick:
|
|
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))),
|
|
56
66
|
maxPg + 2 <= props.Total ? React.createElement(React.Fragment, null,
|
|
57
67
|
React.createElement("li", { className: "page-item disabled", key: "skip-2" },
|
|
58
68
|
React.createElement("a", { className: "page-link" }, "...")),
|
|
59
69
|
React.createElement("li", { className: "page-item", key: props.Total },
|
|
60
|
-
React.createElement("a", { className: "page-link", onClick:
|
|
70
|
+
React.createElement("a", { className: "page-link", onClick: () => props.SetPage(props.Total) }, props.Total))) : null,
|
|
61
71
|
React.createElement("li", { className: "page-item" + (maxPg == props.Total ? ' disabled' : ""), key: 'next' },
|
|
62
|
-
React.createElement("a", { className: "page-link", onClick:
|
|
72
|
+
React.createElement("a", { className: "page-link", onClick: () => {
|
|
63
73
|
if (maxPg < props.Total)
|
|
64
74
|
props.SetPage(Math.min(props.Current + nPages, props.Total));
|
|
65
75
|
} }, "Next")));
|
package/lib/SearchableTable.js
CHANGED
|
@@ -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
|
-
|
|
38
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
React.useEffect(
|
|
46
|
-
setData(props.data.filter(
|
|
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:
|
|
50
|
-
React.createElement(Table_1.default,
|
|
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
|
}
|