@gpa-gemstone/react-table 1.2.44 → 1.2.46
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 +20 -20
- package/lib/AdjustableTable/AdjustableColumn.js +99 -100
- package/lib/AdjustableTable/AdjustableTable.d.ts +102 -102
- package/lib/AdjustableTable/AdjustableTable.js +273 -273
- package/lib/AdjustableTable/Column.d.ts +67 -67
- package/lib/AdjustableTable/Column.js +124 -125
- package/lib/DynamicTable.d.ts +37 -37
- package/lib/DynamicTable.js +45 -46
- package/lib/Paging.d.ts +6 -7
- package/lib/Paging.js +66 -66
- package/lib/SearchableTable.d.ts +15 -16
- package/lib/SearchableTable.js +51 -52
- package/lib/SelectTable.d.ts +19 -19
- package/lib/SelectTable.js +121 -122
- package/lib/Table.d.ts +99 -99
- package/lib/Table.js +105 -106
- package/lib/index.d.ts +15 -15
- package/lib/index.js +47 -47
- package/package.json +6 -6
|
@@ -1,273 +1,273 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// ******************************************************************************************************
|
|
3
|
-
// Adjustable.tsx - Gbtc
|
|
4
|
-
//
|
|
5
|
-
// Copyright © 2023, 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
|
-
// 11/18/2023 - C. Lackner
|
|
21
|
-
// Generated original version of source code.
|
|
22
|
-
//
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
React.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
u
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
u
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
React.createElement(
|
|
160
|
-
props.
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function Rows(props) {
|
|
164
|
-
if (props.Data.length === 0)
|
|
165
|
-
return null;
|
|
166
|
-
var getWidth = React.useCallback(function (key, type) {
|
|
167
|
-
var _a;
|
|
168
|
-
if (type === 'fixed' && props.FixedWidth.has(key))
|
|
169
|
-
return props.FixedWidth.get(key);
|
|
170
|
-
if (type === 'adjustable' && props.AdjWidth.has(key))
|
|
171
|
-
return (_a = props.AdjWidth.get(key)) === null || _a === void 0 ? void 0 : _a.width;
|
|
172
|
-
return undefined;
|
|
173
|
-
}, [props.FixedWidth, props.AdjWidth]);
|
|
174
|
-
return (React.createElement("tbody", { style: props.BodyStyle, className: props.BodyClass }, props.Data.map(function (d, i) {
|
|
175
|
-
var style = (props.RowStyle !== undefined) ? __assign({}, props.RowStyle) : {};
|
|
176
|
-
if (style.cursor === undefined && (props.OnClick !== undefined || props.DragStart !== undefined))
|
|
177
|
-
style.cursor = 'pointer';
|
|
178
|
-
if (props.Selected !== undefined && props.Selected(d, i))
|
|
179
|
-
style.backgroundColor = 'yellow';
|
|
180
|
-
var key = props.KeySelector(d, i);
|
|
181
|
-
return React.createElement("tr", { key: key, style: __assign({ display: (props.FixedLayout ? 'block' : undefined) }, style) },
|
|
182
|
-
React.Children.map(props.children, function (element) {
|
|
183
|
-
if (!React.isValidElement(element))
|
|
184
|
-
return null;
|
|
185
|
-
if (element.type === AdjustableColumn_1.default)
|
|
186
|
-
return React.createElement(Column_1.ColumnDataWrapper, __assign({}, element.props, { width: getWidth(element.props.Key, 'adjustable'), item: d, index: i, key: element.key, fixedLayout: props.FixedLayout, onClick: props.OnClick, dragStart: props.DragStart, sel: true }));
|
|
187
|
-
return null;
|
|
188
|
-
}),
|
|
189
|
-
React.Children.map(props.children, function (element) {
|
|
190
|
-
if (!React.isValidElement(element))
|
|
191
|
-
return null;
|
|
192
|
-
if (element.type === Column_1.default)
|
|
193
|
-
return React.createElement(Column_1.ColumnDataWrapper, __assign({}, element.props, { width: getWidth(element.props.Key, 'fixed'), item: d, index: i, key: element.key, fixedLayout: props.FixedLayout, onClick: props.OnClick, dragStart: props.DragStart }));
|
|
194
|
-
return null;
|
|
195
|
-
}));
|
|
196
|
-
})));
|
|
197
|
-
}
|
|
198
|
-
function Header(props) {
|
|
199
|
-
var trRef = React.useRef(null);
|
|
200
|
-
var _a = React.useState(undefined), adjKeys = _a[0], setAdjKeys = _a[1];
|
|
201
|
-
var _b = React.useState(0), mouseDown = _b[0], setMouseDown = _b[1];
|
|
202
|
-
var _c = React.useState(0), deltaX = _c[0], setDeltaX = _c[1];
|
|
203
|
-
var finishAdjustment = function (e) {
|
|
204
|
-
var _a, _b;
|
|
205
|
-
var d = deltaX;
|
|
206
|
-
if (adjKeys === undefined)
|
|
207
|
-
return;
|
|
208
|
-
var w = limitMovement(adjKeys[0], adjKeys[1], d);
|
|
209
|
-
var leftWidth = (_a = props.GetWidth(adjKeys[0], 'adjustable')) !== null && _a !== void 0 ? _a : 100;
|
|
210
|
-
var rightWidth = (_b = props.GetWidth(adjKeys[1], 'adjustable')) !== null && _b !== void 0 ? _b : 100;
|
|
211
|
-
if (Math.abs(w) > 5) {
|
|
212
|
-
props.SetWidth(adjKeys[0], (leftWidth - w), 'adjustable');
|
|
213
|
-
props.SetWidth(adjKeys[1], (rightWidth + w), 'adjustable');
|
|
214
|
-
}
|
|
215
|
-
setMouseDown(0);
|
|
216
|
-
setAdjKeys(undefined);
|
|
217
|
-
setDeltaX(0);
|
|
218
|
-
};
|
|
219
|
-
var onMove = React.useCallback(function (e) {
|
|
220
|
-
if (adjKeys === undefined)
|
|
221
|
-
return;
|
|
222
|
-
var w = limitMovement(adjKeys[0], adjKeys[1], mouseDown - e.screenX);
|
|
223
|
-
setDeltaX(w);
|
|
224
|
-
}, [mouseDown, adjKeys]);
|
|
225
|
-
function limitMovement(leftKey, rightKey, delta) {
|
|
226
|
-
var w = delta;
|
|
227
|
-
var leftWidth = props.GetWidth(leftKey, 'adjustable');
|
|
228
|
-
var rightWidth = props.GetWidth(rightKey, 'adjustable');
|
|
229
|
-
var leftMin = props.GetMinWidth(leftKey);
|
|
230
|
-
var rightMin = props.GetMinWidth(rightKey);
|
|
231
|
-
if ((leftWidth !== null && leftWidth !== void 0 ? leftWidth : 100) - w < leftMin) {
|
|
232
|
-
w = (leftWidth !== null && leftWidth !== void 0 ? leftWidth : 100) - leftMin;
|
|
233
|
-
}
|
|
234
|
-
if ((rightWidth !== null && rightWidth !== void 0 ? rightWidth : 100) + w < rightMin) {
|
|
235
|
-
w = -(rightWidth !== null && rightWidth !== void 0 ? rightWidth : 100) - rightMin;
|
|
236
|
-
}
|
|
237
|
-
return w;
|
|
238
|
-
}
|
|
239
|
-
var adjustWidth = function (w, key) {
|
|
240
|
-
if (w === undefined)
|
|
241
|
-
return w;
|
|
242
|
-
if (adjKeys === undefined)
|
|
243
|
-
return w;
|
|
244
|
-
if (key === adjKeys[0])
|
|
245
|
-
return w - deltaX;
|
|
246
|
-
if (key === adjKeys[1])
|
|
247
|
-
return w + deltaX;
|
|
248
|
-
return w;
|
|
249
|
-
};
|
|
250
|
-
return (React.createElement("thead", { className: props.Class, style: props.Style, onMouseMove: function (e) { onMove(e.nativeEvent); e.stopPropagation(); }, onMouseUp: function (e) { finishAdjustment(e.nativeEvent); e.stopPropagation(); }, onMouseLeave: function (e) { finishAdjustment(e.nativeEvent); e.stopPropagation(); } },
|
|
251
|
-
React.createElement("tr", { ref: trRef },
|
|
252
|
-
React.Children.map(props.children, function (element) {
|
|
253
|
-
var _a;
|
|
254
|
-
if (!React.isValidElement(element))
|
|
255
|
-
return null;
|
|
256
|
-
if (element.type === AdjustableColumn_1.default)
|
|
257
|
-
return React.createElement(AdjustableColumn_1.AdjColumnHeaderWrapper, __assign({}, element.props, { setWidth: function (w, min) { return props.SetWidth(element.props.Key, Math.floor(w), 'adjustable', min); }, onSort: function (key, e, fld) { return props.OnSort({ colKey: key, colField: fld, ascending: props.Ascending }, e); }, sorted: props.SortKey === element.props.Key && ((_a = element.props.AllowSort) !== null && _a !== void 0 ? _a : true), asc: props.Ascending, width: adjustWidth(props.GetWidth(element.props.Key, 'adjustable'), element.props.Key), startAdjustment: function (e) {
|
|
258
|
-
if (props.GetLeftKey(element.props.Key) !== undefined)
|
|
259
|
-
setAdjKeys([props.GetLeftKey(element.props.Key), element.props.Key]);
|
|
260
|
-
setMouseDown(e.screenX);
|
|
261
|
-
}, fixedLayout: props.FixedLayout }));
|
|
262
|
-
return null;
|
|
263
|
-
}),
|
|
264
|
-
React.Children.map(props.children, function (element) {
|
|
265
|
-
var _a;
|
|
266
|
-
if (!React.isValidElement(element))
|
|
267
|
-
return null;
|
|
268
|
-
if (element.type === Column_1.default)
|
|
269
|
-
return React.createElement(Column_1.ColumnHeaderWrapper, __assign({}, element.props, { setWidth: function (w) { return props.SetWidth(element.props.Key, Math.floor(w), 'fixed'); }, onSort: function (key, e, fld) { return props.OnSort({ colKey: key, colField: fld, ascending: props.Ascending }, e); }, sorted: props.SortKey === element.props.Key && ((_a = element.props.AllowSort) !== null && _a !== void 0 ? _a : true), asc: props.Ascending, width: props.GetWidth(element.props.Key, 'fixed'), fixedLayout: props.FixedLayout }));
|
|
270
|
-
return null;
|
|
271
|
-
}),
|
|
272
|
-
React.createElement("th", { style: { width: 17, padding: 0 } }, props.LastColumn))));
|
|
273
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
// ******************************************************************************************************
|
|
3
|
+
// Adjustable.tsx - Gbtc
|
|
4
|
+
//
|
|
5
|
+
// Copyright © 2023, 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
|
+
// 11/18/2023 - C. Lackner
|
|
21
|
+
// Generated original version of source code.
|
|
22
|
+
//
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.default = AdjustableTable;
|
|
37
|
+
var React = require("react");
|
|
38
|
+
var _ = require("lodash");
|
|
39
|
+
var Column_1 = require("./Column");
|
|
40
|
+
var AdjustableColumn_1 = require("./AdjustableColumn");
|
|
41
|
+
function AdjustableTable(props) {
|
|
42
|
+
var _a, _b, _c, _d;
|
|
43
|
+
var tblref = React.useRef(null);
|
|
44
|
+
var _e = React.useState(false), fixLayout = _e[0], setFixLayout = _e[1];
|
|
45
|
+
var _f = React.useState(0), currentTableWidth = _f[0], setCurrentTableWidth = _f[1];
|
|
46
|
+
var _g = React.useState(new Map()), fixedWidths = _g[0], setFixedWidths = _g[1];
|
|
47
|
+
var _h = React.useState(new Map()), adjustedWidths = _h[0], setAdjustedWidths = _h[1];
|
|
48
|
+
var _j = React.useState((_b = (_a = React.Children.map(props.children, function (element) {
|
|
49
|
+
if (!React.isValidElement(element))
|
|
50
|
+
return undefined;
|
|
51
|
+
if (element.type === Column_1.default)
|
|
52
|
+
return element.props.Key;
|
|
53
|
+
return undefined;
|
|
54
|
+
})) === null || _a === void 0 ? void 0 : _a.filter(function (s) { return s !== undefined; })) !== null && _b !== void 0 ? _b : []), fixedkeys = _j[0], setFixedKeys = _j[1];
|
|
55
|
+
var _k = React.useState((_d = (_c = React.Children.map(props.children, function (element) {
|
|
56
|
+
if (!React.isValidElement(element))
|
|
57
|
+
return undefined;
|
|
58
|
+
if (element.type === AdjustableColumn_1.default)
|
|
59
|
+
return element.props.Key;
|
|
60
|
+
return undefined;
|
|
61
|
+
})) === null || _c === void 0 ? void 0 : _c.filter(function (d) { return d !== undefined; })) !== null && _d !== void 0 ? _d : []), adjKeys = _k[0], setAdjKeys = _k[1];
|
|
62
|
+
var setTableWidth = React.useCallback(_.debounce(function () { var _a, _b; setCurrentTableWidth((_b = (_a = tblref.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) !== null && _b !== void 0 ? _b : 0); }, 500), []);
|
|
63
|
+
React.useEffect(function () {
|
|
64
|
+
var element = tblref === null || tblref === void 0 ? void 0 : tblref.current;
|
|
65
|
+
if (element == null)
|
|
66
|
+
return;
|
|
67
|
+
var observer = new ResizeObserver(function () {
|
|
68
|
+
setTableWidth();
|
|
69
|
+
});
|
|
70
|
+
observer.observe(element);
|
|
71
|
+
return function () {
|
|
72
|
+
observer.disconnect();
|
|
73
|
+
};
|
|
74
|
+
}, []);
|
|
75
|
+
React.useEffect(function () {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
var keysFixed = (_b = (_a = React.Children.map(props.children, function (element) {
|
|
78
|
+
if (!React.isValidElement(element))
|
|
79
|
+
return undefined;
|
|
80
|
+
if (element.type === Column_1.default)
|
|
81
|
+
return element.props.Key;
|
|
82
|
+
return undefined;
|
|
83
|
+
})) === null || _a === void 0 ? void 0 : _a.filter(function (k) { return k !== undefined; })) !== null && _b !== void 0 ? _b : [];
|
|
84
|
+
var keysAdj = React.Children.map(props.children, function (element) {
|
|
85
|
+
if (!React.isValidElement(element))
|
|
86
|
+
return undefined;
|
|
87
|
+
if (element.type === AdjustableColumn_1.default)
|
|
88
|
+
return element.props.Key;
|
|
89
|
+
return undefined;
|
|
90
|
+
});
|
|
91
|
+
setFixedKeys(function (k) {
|
|
92
|
+
var _a;
|
|
93
|
+
var u = (_a = keysFixed === null || keysFixed === void 0 ? void 0 : keysFixed.filter(function (d) { return d !== undefined; })) !== null && _a !== void 0 ? _a : [];
|
|
94
|
+
if (_.isEqual(k, u))
|
|
95
|
+
return k;
|
|
96
|
+
return u;
|
|
97
|
+
});
|
|
98
|
+
setAdjKeys(function (k) {
|
|
99
|
+
var _a;
|
|
100
|
+
var u = (_a = keysAdj === null || keysAdj === void 0 ? void 0 : keysAdj.filter(function (d) { return d !== undefined; })) !== null && _a !== void 0 ? _a : [];
|
|
101
|
+
if (_.isEqual(k, u))
|
|
102
|
+
return k;
|
|
103
|
+
return u;
|
|
104
|
+
});
|
|
105
|
+
}, [props.children]);
|
|
106
|
+
React.useEffect(function () {
|
|
107
|
+
setFixLayout(false);
|
|
108
|
+
setFixedWidths(new Map());
|
|
109
|
+
setAdjustedWidths(new Map());
|
|
110
|
+
}, [fixedkeys.length, adjKeys.length, currentTableWidth]);
|
|
111
|
+
React.useEffect(function () {
|
|
112
|
+
var fixed = fixedkeys.length == fixedWidths.size;
|
|
113
|
+
var adj = adjKeys.length == adjustedWidths.size;
|
|
114
|
+
setFixLayout(fixed && adj);
|
|
115
|
+
}, [fixedkeys, adjKeys, fixedWidths, adjustedWidths]);
|
|
116
|
+
var handleSort = React.useCallback(function (data, event) {
|
|
117
|
+
if (data.colKey !== null)
|
|
118
|
+
props.OnSort(data, event);
|
|
119
|
+
}, [props.OnSort]);
|
|
120
|
+
var getWidth = React.useCallback(function (key, type) {
|
|
121
|
+
var _a;
|
|
122
|
+
if (type === 'fixed' && fixedWidths.has(key))
|
|
123
|
+
return fixedWidths.get(key);
|
|
124
|
+
if (type === 'adjustable' && adjustedWidths.has(key))
|
|
125
|
+
return (_a = adjustedWidths.get(key)) === null || _a === void 0 ? void 0 : _a.width;
|
|
126
|
+
return undefined;
|
|
127
|
+
}, [fixedWidths, adjustedWidths]);
|
|
128
|
+
var getMinWidth = React.useCallback(function (key) {
|
|
129
|
+
var _a, _b;
|
|
130
|
+
if (adjustedWidths.has(key))
|
|
131
|
+
return (_b = (_a = adjustedWidths.get(key)) === null || _a === void 0 ? void 0 : _a.minWidth) !== null && _b !== void 0 ? _b : 100;
|
|
132
|
+
return 100;
|
|
133
|
+
}, [fixedWidths, adjustedWidths]);
|
|
134
|
+
var getPrevKey = React.useCallback(function (key) {
|
|
135
|
+
var i = adjKeys.findIndex(function (a) { return a === key; });
|
|
136
|
+
if (i < 1)
|
|
137
|
+
return undefined;
|
|
138
|
+
return adjKeys[i - 1];
|
|
139
|
+
}, [adjKeys]);
|
|
140
|
+
var setWidth = React.useCallback(function (key, width, type, minWidth) {
|
|
141
|
+
var _a, _b;
|
|
142
|
+
if (type === 'fixed')
|
|
143
|
+
setFixedWidths(function (d) {
|
|
144
|
+
var u = new Map(d);
|
|
145
|
+
u.set(key, width);
|
|
146
|
+
return u;
|
|
147
|
+
});
|
|
148
|
+
if (type === 'adjustable') {
|
|
149
|
+
if (adjustedWidths.has(key))
|
|
150
|
+
minWidth = (_b = (_a = adjustedWidths.get(key)) === null || _a === void 0 ? void 0 : _a.minWidth) !== null && _b !== void 0 ? _b : 100;
|
|
151
|
+
setAdjustedWidths(function (d) {
|
|
152
|
+
var u = new Map(d);
|
|
153
|
+
u.set(key, { width: width, minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : 100 });
|
|
154
|
+
return u;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}, []);
|
|
158
|
+
return (React.createElement("table", { className: props.TableClass !== undefined ? props.TableClass : '', style: props.TableStyle, ref: tblref },
|
|
159
|
+
React.createElement(Header, { Class: props.TheadClass, Style: props.TheadStyle, SortKey: props.SortKey, Ascending: props.Ascending, OnSort: handleSort, SetWidth: setWidth, GetWidth: getWidth, GetMinWidth: getMinWidth, GetLeftKey: getPrevKey, LastColumn: props.LastColumn, FixedLayout: fixLayout }, props.children),
|
|
160
|
+
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, AdjWidth: adjustedWidths, FixedWidth: fixedWidths, FixedLayout: fixLayout }, props.children),
|
|
161
|
+
props.LastRow !== undefined ? React.createElement("tr", { style: (props.RowStyle !== undefined) ? __assign({}, props.RowStyle) : {}, key: -1 }, props.LastRow) : null));
|
|
162
|
+
}
|
|
163
|
+
function Rows(props) {
|
|
164
|
+
if (props.Data.length === 0)
|
|
165
|
+
return null;
|
|
166
|
+
var getWidth = React.useCallback(function (key, type) {
|
|
167
|
+
var _a;
|
|
168
|
+
if (type === 'fixed' && props.FixedWidth.has(key))
|
|
169
|
+
return props.FixedWidth.get(key);
|
|
170
|
+
if (type === 'adjustable' && props.AdjWidth.has(key))
|
|
171
|
+
return (_a = props.AdjWidth.get(key)) === null || _a === void 0 ? void 0 : _a.width;
|
|
172
|
+
return undefined;
|
|
173
|
+
}, [props.FixedWidth, props.AdjWidth]);
|
|
174
|
+
return (React.createElement("tbody", { style: props.BodyStyle, className: props.BodyClass }, props.Data.map(function (d, i) {
|
|
175
|
+
var style = (props.RowStyle !== undefined) ? __assign({}, props.RowStyle) : {};
|
|
176
|
+
if (style.cursor === undefined && (props.OnClick !== undefined || props.DragStart !== undefined))
|
|
177
|
+
style.cursor = 'pointer';
|
|
178
|
+
if (props.Selected !== undefined && props.Selected(d, i))
|
|
179
|
+
style.backgroundColor = 'yellow';
|
|
180
|
+
var key = props.KeySelector(d, i);
|
|
181
|
+
return React.createElement("tr", { key: key, style: __assign({ display: (props.FixedLayout ? 'block' : undefined) }, style) },
|
|
182
|
+
React.Children.map(props.children, function (element) {
|
|
183
|
+
if (!React.isValidElement(element))
|
|
184
|
+
return null;
|
|
185
|
+
if (element.type === AdjustableColumn_1.default)
|
|
186
|
+
return React.createElement(Column_1.ColumnDataWrapper, __assign({}, element.props, { width: getWidth(element.props.Key, 'adjustable'), item: d, index: i, key: element.key, fixedLayout: props.FixedLayout, onClick: props.OnClick, dragStart: props.DragStart, sel: true }));
|
|
187
|
+
return null;
|
|
188
|
+
}),
|
|
189
|
+
React.Children.map(props.children, function (element) {
|
|
190
|
+
if (!React.isValidElement(element))
|
|
191
|
+
return null;
|
|
192
|
+
if (element.type === Column_1.default)
|
|
193
|
+
return React.createElement(Column_1.ColumnDataWrapper, __assign({}, element.props, { width: getWidth(element.props.Key, 'fixed'), item: d, index: i, key: element.key, fixedLayout: props.FixedLayout, onClick: props.OnClick, dragStart: props.DragStart }));
|
|
194
|
+
return null;
|
|
195
|
+
}));
|
|
196
|
+
})));
|
|
197
|
+
}
|
|
198
|
+
function Header(props) {
|
|
199
|
+
var trRef = React.useRef(null);
|
|
200
|
+
var _a = React.useState(undefined), adjKeys = _a[0], setAdjKeys = _a[1];
|
|
201
|
+
var _b = React.useState(0), mouseDown = _b[0], setMouseDown = _b[1];
|
|
202
|
+
var _c = React.useState(0), deltaX = _c[0], setDeltaX = _c[1];
|
|
203
|
+
var finishAdjustment = function (e) {
|
|
204
|
+
var _a, _b;
|
|
205
|
+
var d = deltaX;
|
|
206
|
+
if (adjKeys === undefined)
|
|
207
|
+
return;
|
|
208
|
+
var w = limitMovement(adjKeys[0], adjKeys[1], d);
|
|
209
|
+
var leftWidth = (_a = props.GetWidth(adjKeys[0], 'adjustable')) !== null && _a !== void 0 ? _a : 100;
|
|
210
|
+
var rightWidth = (_b = props.GetWidth(adjKeys[1], 'adjustable')) !== null && _b !== void 0 ? _b : 100;
|
|
211
|
+
if (Math.abs(w) > 5) {
|
|
212
|
+
props.SetWidth(adjKeys[0], (leftWidth - w), 'adjustable');
|
|
213
|
+
props.SetWidth(adjKeys[1], (rightWidth + w), 'adjustable');
|
|
214
|
+
}
|
|
215
|
+
setMouseDown(0);
|
|
216
|
+
setAdjKeys(undefined);
|
|
217
|
+
setDeltaX(0);
|
|
218
|
+
};
|
|
219
|
+
var onMove = React.useCallback(function (e) {
|
|
220
|
+
if (adjKeys === undefined)
|
|
221
|
+
return;
|
|
222
|
+
var w = limitMovement(adjKeys[0], adjKeys[1], mouseDown - e.screenX);
|
|
223
|
+
setDeltaX(w);
|
|
224
|
+
}, [mouseDown, adjKeys]);
|
|
225
|
+
function limitMovement(leftKey, rightKey, delta) {
|
|
226
|
+
var w = delta;
|
|
227
|
+
var leftWidth = props.GetWidth(leftKey, 'adjustable');
|
|
228
|
+
var rightWidth = props.GetWidth(rightKey, 'adjustable');
|
|
229
|
+
var leftMin = props.GetMinWidth(leftKey);
|
|
230
|
+
var rightMin = props.GetMinWidth(rightKey);
|
|
231
|
+
if ((leftWidth !== null && leftWidth !== void 0 ? leftWidth : 100) - w < leftMin) {
|
|
232
|
+
w = (leftWidth !== null && leftWidth !== void 0 ? leftWidth : 100) - leftMin;
|
|
233
|
+
}
|
|
234
|
+
if ((rightWidth !== null && rightWidth !== void 0 ? rightWidth : 100) + w < rightMin) {
|
|
235
|
+
w = -(rightWidth !== null && rightWidth !== void 0 ? rightWidth : 100) - rightMin;
|
|
236
|
+
}
|
|
237
|
+
return w;
|
|
238
|
+
}
|
|
239
|
+
var adjustWidth = function (w, key) {
|
|
240
|
+
if (w === undefined)
|
|
241
|
+
return w;
|
|
242
|
+
if (adjKeys === undefined)
|
|
243
|
+
return w;
|
|
244
|
+
if (key === adjKeys[0])
|
|
245
|
+
return w - deltaX;
|
|
246
|
+
if (key === adjKeys[1])
|
|
247
|
+
return w + deltaX;
|
|
248
|
+
return w;
|
|
249
|
+
};
|
|
250
|
+
return (React.createElement("thead", { className: props.Class, style: props.Style, onMouseMove: function (e) { onMove(e.nativeEvent); e.stopPropagation(); }, onMouseUp: function (e) { finishAdjustment(e.nativeEvent); e.stopPropagation(); }, onMouseLeave: function (e) { finishAdjustment(e.nativeEvent); e.stopPropagation(); } },
|
|
251
|
+
React.createElement("tr", { ref: trRef },
|
|
252
|
+
React.Children.map(props.children, function (element) {
|
|
253
|
+
var _a;
|
|
254
|
+
if (!React.isValidElement(element))
|
|
255
|
+
return null;
|
|
256
|
+
if (element.type === AdjustableColumn_1.default)
|
|
257
|
+
return React.createElement(AdjustableColumn_1.AdjColumnHeaderWrapper, __assign({}, element.props, { setWidth: function (w, min) { return props.SetWidth(element.props.Key, Math.floor(w), 'adjustable', min); }, onSort: function (key, e, fld) { return props.OnSort({ colKey: key, colField: fld, ascending: props.Ascending }, e); }, sorted: props.SortKey === element.props.Key && ((_a = element.props.AllowSort) !== null && _a !== void 0 ? _a : true), asc: props.Ascending, width: adjustWidth(props.GetWidth(element.props.Key, 'adjustable'), element.props.Key), startAdjustment: function (e) {
|
|
258
|
+
if (props.GetLeftKey(element.props.Key) !== undefined)
|
|
259
|
+
setAdjKeys([props.GetLeftKey(element.props.Key), element.props.Key]);
|
|
260
|
+
setMouseDown(e.screenX);
|
|
261
|
+
}, fixedLayout: props.FixedLayout }));
|
|
262
|
+
return null;
|
|
263
|
+
}),
|
|
264
|
+
React.Children.map(props.children, function (element) {
|
|
265
|
+
var _a;
|
|
266
|
+
if (!React.isValidElement(element))
|
|
267
|
+
return null;
|
|
268
|
+
if (element.type === Column_1.default)
|
|
269
|
+
return React.createElement(Column_1.ColumnHeaderWrapper, __assign({}, element.props, { setWidth: function (w) { return props.SetWidth(element.props.Key, Math.floor(w), 'fixed'); }, onSort: function (key, e, fld) { return props.OnSort({ colKey: key, colField: fld, ascending: props.Ascending }, e); }, sorted: props.SortKey === element.props.Key && ((_a = element.props.AllowSort) !== null && _a !== void 0 ? _a : true), asc: props.Ascending, width: props.GetWidth(element.props.Key, 'fixed'), fixedLayout: props.FixedLayout }));
|
|
270
|
+
return null;
|
|
271
|
+
}),
|
|
272
|
+
React.createElement("th", { style: { width: 17, padding: 0 } }, props.LastColumn))));
|
|
273
|
+
}
|