@pdg/react-table 1.0.102 → 1.0.104

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 (54) hide show
  1. package/dist/@types/index.d.ts +1 -1
  2. package/dist/@types/types.d.ts +11 -11
  3. package/dist/InfoTable/InfoTable.d.ts +7 -7
  4. package/dist/InfoTable/InfoTable.types.d.ts +78 -79
  5. package/dist/InfoTable/index.d.ts +4 -4
  6. package/dist/SearchTable/SearchTable.d.ts +8 -8
  7. package/dist/SearchTable/SearchTable.types.d.ts +33 -34
  8. package/dist/SearchTable/index.d.ts +4 -4
  9. package/dist/Table/Table.d.ts +8 -8
  10. package/dist/Table/Table.types.d.ts +129 -130
  11. package/dist/Table/index.d.ts +4 -4
  12. package/dist/TableBodyCell/TableBodyCell.d.ts +4 -4
  13. package/dist/TableBodyCell/TableBodyCell.types.d.ts +18 -18
  14. package/dist/TableBodyCell/index.d.ts +4 -4
  15. package/dist/TableBodyRow/TableBodyRow.d.ts +7 -7
  16. package/dist/TableBodyRow/TableBodyRow.types.d.ts +18 -19
  17. package/dist/TableBodyRow/index.d.ts +4 -4
  18. package/dist/TableButton/TableButton.d.ts +4 -4
  19. package/dist/TableButton/TableButton.types.d.ts +3 -4
  20. package/dist/TableButton/index.d.ts +4 -4
  21. package/dist/TableCommonCell/TableCommonCell.d.ts +4 -4
  22. package/dist/TableCommonCell/TableCommonCell.types.d.ts +11 -11
  23. package/dist/TableCommonCell/index.d.ts +4 -4
  24. package/dist/TableContext/TableContext.d.ts +4 -4
  25. package/dist/TableContext/TableContext.types.d.ts +14 -14
  26. package/dist/TableContext/index.d.ts +5 -5
  27. package/dist/TableContext/useTableState.d.ts +2 -2
  28. package/dist/TableContextProvider/TableContextProvider.d.ts +4 -4
  29. package/dist/TableContextProvider/TableContextProvider.types.d.ts +6 -6
  30. package/dist/TableContextProvider/index.d.ts +4 -4
  31. package/dist/TableFooterCell/TableFooterCell.d.ts +4 -4
  32. package/dist/TableFooterCell/TableFooterCell.types.d.ts +5 -5
  33. package/dist/TableFooterCell/index.d.ts +4 -4
  34. package/dist/TableHeadCell/TableHeadCell.d.ts +4 -4
  35. package/dist/TableHeadCell/TableHeadCell.types.d.ts +11 -11
  36. package/dist/TableHeadCell/index.d.ts +4 -4
  37. package/dist/TableMenuButton/TableMenuButton.d.ts +4 -4
  38. package/dist/TableMenuButton/TableMenuButton.types.d.ts +9 -10
  39. package/dist/TableMenuButton/index.d.ts +4 -4
  40. package/dist/TablePagination/TablePagination.d.ts +4 -4
  41. package/dist/TablePagination/TablePagination.types.d.ts +13 -13
  42. package/dist/TablePagination/index.d.ts +4 -4
  43. package/dist/TableTopHead/TableTopHead.d.ts +4 -4
  44. package/dist/TableTopHead/TableTopHead.types.d.ts +17 -18
  45. package/dist/TableTopHead/index.d.ts +4 -4
  46. package/dist/index.d.ts +7 -7
  47. package/dist/index.esm.js +1974 -2006
  48. package/dist/index.js +1974 -2006
  49. package/package.json +18 -18
  50. package/dist/@util/index.d.ts +0 -1
  51. package/dist/@util/table.d.ts +0 -8
  52. package/dist/InfoTable/InfoTable.style.d.ts +0 -14
  53. package/dist/Table/Table.styles.d.ts +0 -5
  54. package/dist/TableTopHead/TableTopHead.style.d.ts +0 -4
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  if ( ref === void 0 ) ref = {};
3
3
  var insertAt = ref.insertAt;
4
4
 
5
- if (!css || typeof document === 'undefined') { return; }
5
+ if (typeof document === 'undefined') { return; }
6
6
 
7
7
  var head = document.head || document.getElementsByTagName('head')[0];
8
8
  var style = document.createElement('style');
@@ -71,23 +71,19 @@ function __makeTemplateObject(cooked, raw) {
71
71
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
72
72
  var e = new Error(message);
73
73
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
74
- };var TableDefaultProps = {
75
- defaultAlign: 'left',
76
- pagingAlign: 'center',
77
- cellPadding: 13,
78
- };var StyledBodyRow$1 = material.styled(material.TableRow)(function (_a) {
79
- var theme = _a.theme;
80
- return ({
81
- '&.odd-color:nth-of-type(odd):not(:hover)': {
82
- backgroundColor: material.lighten(theme.palette.action.hover, 0.4),
83
- },
84
- '&.even-color:nth-of-type(even):not(:hover)': {
85
- backgroundColor: material.lighten(theme.palette.action.hover, 0.4),
86
- },
87
- });
88
- });
89
- var StyledNoDataDiv = material.styled('div')(templateObject_1$4 || (templateObject_1$4 = __makeTemplateObject(["\n text-align: center;\n padding: 30px 0;\n font-weight: 500;\n font-size: 13px;\n color: #94a0b2;\n opacity: 0.8;\n\n .material-icons {\n font-size: 40px;\n margin-bottom: 5px;\n }\n"], ["\n text-align: center;\n padding: 30px 0;\n font-weight: 500;\n font-size: 13px;\n color: #94a0b2;\n opacity: 0.8;\n\n .material-icons {\n font-size: 40px;\n margin-bottom: 5px;\n }\n"])));
90
- var templateObject_1$4;var TableBodyRowDefaultProps = {};const CSS = /*#__PURE__*/Object.freeze({
74
+ };var StyledBodyRow$1 = material.styled(material.TableRow)(function (_a) {
75
+ var theme = _a.theme;
76
+ return ({
77
+ '&.odd-color:nth-of-type(odd):not(:hover)': {
78
+ backgroundColor: material.lighten(theme.palette.action.hover, 0.4),
79
+ },
80
+ '&.even-color:nth-of-type(even):not(:hover)': {
81
+ backgroundColor: material.lighten(theme.palette.action.hover, 0.4),
82
+ },
83
+ });
84
+ });
85
+ var StyledNoDataDiv = material.styled('div')(templateObject_1$4 || (templateObject_1$4 = __makeTemplateObject(["\n text-align: center;\n padding: 30px 0;\n font-weight: 500;\n font-size: 13px;\n color: #94a0b2;\n opacity: 0.8;\n\n .material-icons {\n font-size: 40px;\n margin-bottom: 5px;\n }\n"], ["\n text-align: center;\n padding: 30px 0;\n font-weight: 500;\n font-size: 13px;\n color: #94a0b2;\n opacity: 0.8;\n\n .material-icons {\n font-size: 40px;\n margin-bottom: 5px;\n }\n"])));
86
+ var templateObject_1$4;const CSS = /*#__PURE__*/Object.freeze({
91
87
  Translate: {
92
88
  toString(transform) {
93
89
  if (!transform) {
@@ -137,1991 +133,1963 @@ var templateObject_1$4;var TableBodyRowDefaultProps = {};const CSS = /*#__PURE__
137
133
  }
138
134
 
139
135
  }
140
- });function getTableColumnAlign(column, defaultAlign) {
141
- switch (column.type) {
142
- case 'number':
143
- return column.align ? column.align : 'right';
144
- default:
145
- return column.align || defaultAlign;
146
- }
147
- }
148
- function combineSx() {
149
- var sx = [];
150
- for (var _i = 0; _i < arguments.length; _i++) {
151
- sx[_i] = arguments[_i];
152
- }
153
- var finalSx = [];
154
- if (Array.isArray(finalSx)) {
155
- sx.forEach(function (v) { return v && finalSx.push.apply(finalSx, (Array.isArray(v) ? v : [v])); });
156
- }
157
- return finalSx;
158
- }
159
- function typographyColorToSxColor(color) {
160
- if (typeof color === 'string') {
161
- if (['primary', 'secondary', 'info', 'warning', 'error'].includes(color)) {
162
- return "".concat(color, ".main");
163
- }
164
- else if (color === 'text') {
165
- return 'text.primary';
166
- }
167
- else {
168
- return color;
169
- }
170
- }
171
- else {
172
- return color;
173
- }
174
- }var TableContextDefaultValue = {
175
- menuOpen: false,
176
- openMenuId: undefined,
177
- setMenuOpen: function () { },
178
- setItemColumnChecked: function () { },
179
- setItemColumnCheckDisabled: function () { },
180
- setItemColumnCommands: function () { },
181
- setHeadColumnChecked: function () { },
182
- setHeadColumnCommands: function () { },
183
- };var TableContext = React.createContext(TableContextDefaultValue);function useTableState() {
184
- var value = React.useContext(TableContext);
185
- if (value === undefined) {
186
- throw new Error('useFormState should be used within TableContext.Provider');
187
- }
188
- return value;
189
- }var StyledTableCell = material.styled(material.TableCell)(templateObject_1$3 || (templateObject_1$3 = __makeTemplateObject(["\n &.ellipsis {\n position: relative;\n max-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n"], ["\n &.ellipsis {\n position: relative;\n max-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n"])));
190
- var TableCommonCell = function (_a) {
191
- /********************************************************************************************************************
192
- * Use
193
- * ******************************************************************************************************************/
194
- var children = _a.children, initClassName = _a.className, initStyle = _a.style, initSx = _a.sx, type = _a.type, column = _a.column, defaultAlign = _a.defaultAlign, initDefaultEllipsis = _a.defaultEllipsis, index = _a.index, item = _a.item, onClick = _a.onClick;
195
- var menuOpen = useTableState().menuOpen;
196
- /********************************************************************************************************************
197
- * Memo
198
- * ******************************************************************************************************************/
199
- var align = React.useMemo(function () { return getTableColumnAlign(column, defaultAlign); }, [column, defaultAlign]);
200
- var ellipsis = React.useMemo(function () {
201
- return type !== 'head' &&
202
- (column.ellipsis ||
203
- (column.type !== 'img' &&
204
- column.type !== 'button' &&
205
- column.type !== 'buttons' &&
206
- (column.ellipsis == null ? !!initDefaultEllipsis : false)));
207
- }, [type, column, initDefaultEllipsis]);
208
- var className = React.useMemo(function () {
209
- var _a, _b, _c, _d, _e, _f;
210
- var className;
211
- var getClassName;
212
- switch (type) {
213
- case 'head':
214
- className = (_a = column.head) === null || _a === void 0 ? void 0 : _a.className;
215
- getClassName = ((_b = column.head) === null || _b === void 0 ? void 0 : _b.onGetClassName) ? (_c = column.head) === null || _c === void 0 ? void 0 : _c.onGetClassName() : undefined;
216
- break;
217
- case 'body':
218
- className = column.className;
219
- if (item != null && index != null) {
220
- getClassName = column.onGetClassName ? column.onGetClassName(item, index) : undefined;
221
- }
222
- break;
223
- case 'footer':
224
- className = (_d = column.footer) === null || _d === void 0 ? void 0 : _d.className;
225
- getClassName = ((_e = column.footer) === null || _e === void 0 ? void 0 : _e.onGetClassName) ? (_f = column.footer) === null || _f === void 0 ? void 0 : _f.onGetClassName() : undefined;
226
- break;
227
- }
228
- if (className || getClassName) {
229
- return classNames(initClassName, className, getClassName);
230
- }
231
- else {
232
- return initClassName;
233
- }
234
- }, [column, index, initClassName, item, type]);
235
- var style = React.useMemo(function () {
236
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
237
- var style;
238
- var getStyle;
239
- switch (type) {
240
- case 'head':
241
- style = ((_a = column.head) === null || _a === void 0 ? void 0 : _a.backgroundColor)
242
- ? __assign(__assign({}, (_b = column.head) === null || _b === void 0 ? void 0 : _b.style), { backgroundColor: column.head.backgroundColor }) : (_c = column.head) === null || _c === void 0 ? void 0 : _c.style;
243
- getStyle = ((_d = column.head) === null || _d === void 0 ? void 0 : _d.onGetStyle) ? (_e = column.head) === null || _e === void 0 ? void 0 : _e.onGetStyle() : undefined;
244
- break;
245
- case 'body':
246
- style = column.backgroundColor ? __assign(__assign({}, column.style), { backgroundColor: column.backgroundColor }) : column.style;
247
- if (item != null && index != null) {
248
- getStyle = column.onGetStyle ? column.onGetStyle(item, index) : undefined;
249
- }
250
- break;
251
- case 'footer':
252
- style = ((_f = column.footer) === null || _f === void 0 ? void 0 : _f.backgroundColor)
253
- ? __assign(__assign({}, (_g = column.footer) === null || _g === void 0 ? void 0 : _g.style), { backgroundColor: column.footer.backgroundColor }) : (_h = column.footer) === null || _h === void 0 ? void 0 : _h.style;
254
- getStyle = ((_j = column.footer) === null || _j === void 0 ? void 0 : _j.onGetStyle) ? (_k = column.footer) === null || _k === void 0 ? void 0 : _k.onGetStyle() : undefined;
255
- break;
256
- }
257
- return __assign(__assign(__assign(__assign({}, initStyle), { width: column.width, minWidth: column.minWidth, cursor: type === 'body' && (column.onClick || onClick) ? 'pointer' : undefined, paddingLeft: column.paddingLeft, paddingRight: column.paddingRight }), style), getStyle);
258
- }, [column, index, initStyle, item, onClick, type]);
259
- var sx = React.useMemo(function () {
260
- var _a, _b, _c, _d, _e, _f;
261
- var sx;
262
- var getSx;
263
- var displaySx;
264
- switch (type) {
265
- case 'head':
266
- sx = (_a = column.head) === null || _a === void 0 ? void 0 : _a.sx;
267
- getSx = ((_b = column.head) === null || _b === void 0 ? void 0 : _b.onGetSx) ? (_c = column.head) === null || _c === void 0 ? void 0 : _c.onGetSx() : undefined;
268
- break;
269
- case 'body':
270
- sx = column.sx;
271
- if (item != null && index != null) {
272
- getSx = column.onGetSx ? column.onGetSx(item, index) : undefined;
273
- }
274
- break;
275
- case 'footer':
276
- sx = (_d = column.footer) === null || _d === void 0 ? void 0 : _d.sx;
277
- getSx = ((_e = column.footer) === null || _e === void 0 ? void 0 : _e.onGetSx) ? (_f = column.footer) === null || _f === void 0 ? void 0 : _f.onGetSx() : undefined;
278
- break;
279
- }
280
- if (column.display) {
281
- var display = {};
282
- if (column.display.xs !== undefined)
283
- display.xs = column.display.xs ? 'table-cell' : 'none';
284
- if (column.display.sm !== undefined)
285
- display.sm = column.display.sm ? 'table-cell' : 'none';
286
- if (column.display.md !== undefined)
287
- display.md = column.display.md ? 'table-cell' : 'none';
288
- if (column.display.lg !== undefined)
289
- display.lg = column.display.lg ? 'table-cell' : 'none';
290
- if (column.display.xl !== undefined)
291
- display.xl = column.display.xl ? 'table-cell' : 'none';
292
- displaySx = { display: display };
293
- }
294
- var sxList = [];
295
- if (getSx)
296
- sxList.push(getSx);
297
- if (sx)
298
- sxList.push(sx);
299
- if (initSx)
300
- sxList.push(initSx);
301
- if (displaySx)
302
- sxList.push(displaySx);
303
- if (sxList.length > 0) {
304
- if (sxList.length === 1) {
305
- return sxList[0];
306
- }
307
- else {
308
- if (!sxList.find(function (sx) { return typeof sx !== 'object'; })) {
309
- return sxList.reduce(function (res, sx) {
310
- res = __assign(__assign({}, res), sx);
311
- return res;
312
- }, {});
313
- }
314
- }
315
- }
316
- }, [column, index, initSx, item, type]);
317
- /********************************************************************************************************************
318
- * Event Handler
319
- * ******************************************************************************************************************/
320
- var handleClick = React.useCallback(function (e) {
321
- if (!menuOpen &&
322
- column.type !== 'check' &&
323
- column.type !== 'button' &&
324
- column.type !== 'buttons' &&
325
- column.type !== 'img') {
326
- e.stopPropagation();
327
- if (type === 'body') {
328
- if (item != null && index != null) {
329
- if (column.onClick) {
330
- column.onClick(item, index);
331
- }
332
- else {
333
- if (onClick)
334
- onClick(item, index);
335
- }
336
- }
337
- }
338
- }
339
- }, [menuOpen, type, item, index, column, onClick]);
340
- /********************************************************************************************************************
341
- * Render
342
- * ******************************************************************************************************************/
343
- return (React.createElement(StyledTableCell, { align: align, className: classNames(className, 'TableCommonCell', ellipsis && 'ellipsis', column.type ? "column-type-".concat(column.type) : false), style: style, sx: sx, onClick: type === 'body' ? handleClick : undefined }, children));
344
- };
345
- var templateObject_1$3;var StyledButtonsBox = material.styled(material.Box)(templateObject_1$2 || (templateObject_1$2 = __makeTemplateObject(["\n display: flex;\n flex-wrap: wrap;\n gap: 5px;\n"], ["\n display: flex;\n flex-wrap: wrap;\n gap: 5px;\n"])));
346
- var TableBodyCell = function (_a) {
347
- /********************************************************************************************************************
348
- * Use
349
- * ******************************************************************************************************************/
350
- var className = _a.className, style = _a.style, sx = _a.sx, item = _a.item, index = _a.index, column = _a.column, defaultAlign = _a.defaultAlign, defaultEllipsis = _a.defaultEllipsis, onClick = _a.onClick, onCheckChange = _a.onCheckChange;
351
- var _b = useTableState(), menuOpen = _b.menuOpen, setItemColumnChecked = _b.setItemColumnChecked, setItemColumnCheckDisabled = _b.setItemColumnCheckDisabled, setItemColumnCommands = _b.setItemColumnCommands;
352
- /********************************************************************************************************************
353
- * State
354
- * ******************************************************************************************************************/
355
- var _c = React.useState(false), checked = _c[0], setChecked = _c[1];
356
- var _d = React.useState(false), checkDisabled = _d[0], setCheckDisabled = _d[1];
357
- /********************************************************************************************************************
358
- * Effect
359
- * ******************************************************************************************************************/
360
- React.useEffect(function () {
361
- if (column.type === 'check') {
362
- setChecked(column.onInitChecked ? column.onInitChecked(item) : false);
363
- setCheckDisabled(column.onCheckDisabled ? column.onCheckDisabled(item) : false);
364
- }
365
- setItemColumnCommands(item, column, {
366
- setChecked: function (checked) {
367
- if (column.type === 'check') {
368
- setChecked(checked);
369
- }
370
- },
371
- setCheckDisabled: function (disabled) {
372
- if (column.type === 'check') {
373
- setCheckDisabled(disabled);
374
- }
375
- },
376
- });
377
- }, [column, item, setItemColumnCommands]);
378
- React.useEffect(function () {
379
- if (column.type === 'check') {
380
- setItemColumnChecked(item, column, checked);
381
- }
382
- // eslint-disable-next-line react-hooks/exhaustive-deps
383
- }, [checked]);
384
- React.useEffect(function () {
385
- if (column.type === 'check') {
386
- setItemColumnCheckDisabled(item, column, checkDisabled);
387
- column.onCheckDisabledChange && column.onCheckDisabledChange(item, checkDisabled);
388
- }
389
- // eslint-disable-next-line react-hooks/exhaustive-deps
390
- }, [checkDisabled]);
391
- /********************************************************************************************************************
392
- * Memo
393
- * ******************************************************************************************************************/
394
- var isHidden = React.useMemo(function () { return (column.onHide ? column.onHide(item, index) : false); }, [column, index, item]);
395
- var buttonsBoxJustifyContent = React.useMemo(function () {
396
- switch (getTableColumnAlign(column, defaultAlign)) {
397
- case 'center':
398
- return 'center';
399
- case 'right':
400
- return 'end';
401
- default:
402
- return 'start';
403
- }
404
- }, [column, defaultAlign]);
405
- var data = React.useMemo(function () {
406
- var _a, _b;
407
- var data;
408
- if (column.type !== 'check') {
409
- if (column.onRender) {
410
- data = column.onRender(item, index);
411
- }
412
- else if (column.name) {
413
- data = item[column.name];
414
- }
415
- else {
416
- data = undefined;
417
- }
418
- }
419
- switch (column.type) {
420
- case 'number':
421
- if (typeof data === 'string' || typeof data === 'number') {
422
- data = util.numberFormat(data);
423
- }
424
- if (column.numberPrefix) {
425
- data = (React.createElement(React.Fragment, null,
426
- React.createElement("span", { style: { opacity: 0.5, marginRight: 2 } }, column.numberPrefix),
427
- data));
428
- }
429
- if (column.numberSuffix) {
430
- data = (React.createElement(React.Fragment, null,
431
- data,
432
- React.createElement("span", { style: { opacity: 0.5, marginLeft: 2 } }, column.numberSuffix)));
433
- }
434
- break;
435
- case 'tel':
436
- if (typeof data === 'string') {
437
- data = util.telNoAutoDash(data);
438
- }
439
- break;
440
- case 'company_no':
441
- if (typeof data === 'string') {
442
- data = util.companyNoAutoDash(data);
443
- }
444
- break;
445
- case 'personal_no':
446
- if (typeof data === 'string') {
447
- data = util.personalNoAutoDash(data);
448
- }
449
- break;
450
- case 'check':
451
- data = (React.createElement(material.Box, { className: 'TableBoxyCell-check-box', onClick: menuOpen ? undefined : function (e) { return e.stopPropagation(); } },
452
- React.createElement(material.Checkbox, { checked: checked, disabled: checkDisabled, onChange: function (e, newChecked) {
453
- setChecked(newChecked);
454
- column.onCheckChange && column.onCheckChange(item, newChecked);
455
- onCheckChange && onCheckChange(item, column, newChecked);
456
- } })));
457
- break;
458
- case 'button':
459
- data = (React.createElement(material.Box, { className: 'TableBoxyCell-button-box', onClick: menuOpen ? undefined : function (e) { return e.stopPropagation(); } }, data));
460
- break;
461
- case 'buttons':
462
- data = (React.createElement(StyledButtonsBox, { className: 'TableBodyCell-buttons-box', justifyContent: buttonsBoxJustifyContent, onClick: menuOpen ? undefined : function (e) { return e.stopPropagation(); } }, data));
463
- break;
464
- case 'img':
465
- {
466
- var img = React.createElement("img", { src: data, style: { maxWidth: '100%', verticalAlign: 'middle' }, alt: '' });
467
- var placement = ((_a = column.tooltipProps) === null || _a === void 0 ? void 0 : _a.placement) ? (_b = column.tooltipProps) === null || _b === void 0 ? void 0 : _b.placement : 'left';
468
- data = (React.createElement("a", { href: data, target: '_blank', onClick: menuOpen
469
- ? undefined
470
- : function (e) {
471
- e.stopPropagation();
472
- } },
473
- React.createElement(material.Tooltip, __assign({ className: 'TableBodyCell-tooltip', title: React.createElement("div", { style: { paddingTop: 3, paddingBottom: 3 } }, img) }, column.tooltipProps, { placement: placement }), img)));
474
- }
475
- break;
476
- case 'date':
477
- if (data) {
478
- data = dayjs(data, column.dateFormat).format('YYYY-MM-DD');
479
- }
480
- break;
481
- case 'datetime':
482
- if (data) {
483
- var dt = dayjs(data, column.dateFormat);
484
- data = (React.createElement(React.Fragment, null,
485
- React.createElement("span", null, dt.format('YYYY-MM-DD')),
486
- column.dateTwoLine ? React.createElement("br", null) : ' ',
487
- React.createElement("span", { style: { opacity: 0.5 } }, dt.format('HH:mm:ss'))));
488
- }
489
- break;
490
- case 'date-hour':
491
- if (data) {
492
- var dt = dayjs(data, column.dateFormat);
493
- data = (React.createElement(React.Fragment, null,
494
- React.createElement("span", null, dt.format('YYYY-MM-DD')),
495
- column.dateTwoLine ? React.createElement("br", null) : ' ',
496
- React.createElement("span", { style: { opacity: 0.5 } }, dt.format('HH시'))));
497
- }
498
- break;
499
- case 'date-minute':
500
- if (data) {
501
- var dt = dayjs(data, column.dateFormat);
502
- data = (React.createElement(React.Fragment, null,
503
- React.createElement("span", null, dt.format('YYYY-MM-DD')),
504
- column.dateTwoLine ? React.createElement("br", null) : ' ',
505
- React.createElement("span", { style: { opacity: 0.5 } }, dt.format('HH시 MM분'))));
506
- }
507
- break;
508
- }
509
- if (column.type !== 'img') {
510
- var tooltip = void 0;
511
- if (column.onGetTooltip) {
512
- tooltip = column.onGetTooltip(item, index);
513
- }
514
- if (tooltip) {
515
- data = (React.createElement(material.Tooltip, __assign({ className: 'TableBodyCell-tooltip', title: tooltip }, column.tooltipProps), React.isValidElement(data) ? (data.type === React.Fragment ? (React.createElement("span", null, data)) : (data)) : (React.createElement("span", null, data))));
516
- }
517
- }
518
- return data;
519
- }, [column, item, index, menuOpen, checked, checkDisabled, buttonsBoxJustifyContent, onCheckChange]);
520
- /********************************************************************************************************************
521
- * Event Handler
522
- * ******************************************************************************************************************/
523
- var handleClick = React.useCallback(function (item, index) {
524
- if (column.onClick) {
525
- column.onClick(item, index);
526
- }
527
- else {
528
- if (onClick)
529
- onClick(item, index);
530
- }
531
- }, [column, onClick]);
532
- /********************************************************************************************************************
533
- * Render
534
- * ******************************************************************************************************************/
535
- return (React.createElement(TableCommonCell, { type: 'body', className: classNames('TableBodyCell', className), style: style, sx: sx, column: column, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, item: item, index: index, onClick: column.onClick || onClick ? handleClick : undefined }, !isHidden && data));
536
- };
537
- var templateObject_1$2;var StyledBodyRow = material.styled(material.TableRow)(function (_a) {
538
- var theme = _a.theme;
539
- return ({
540
- '&.odd-color:nth-of-type(odd):not(:hover)': {
541
- backgroundColor: material.lighten(theme.palette.action.hover, 0.4),
542
- },
543
- '&.even-color:nth-of-type(even):not(:hover)': {
544
- backgroundColor: material.lighten(theme.palette.action.hover, 0.4),
545
- },
546
- });
547
- });
548
- var TableBodyRow = function (_a) {
549
- /********************************************************************************************************************
550
- * Use
551
- * ******************************************************************************************************************/
552
- var className = _a.className, style = _a.style, id = _a.id, index = _a.index, defaultAlign = _a.defaultAlign, defaultEllipsis = _a.defaultEllipsis, sortable$1 = _a.sortable, columns = _a.columns, item = _a.item, onClick = _a.onClick, onCheckChange = _a.onCheckChange, onGetColumnClassName = _a.onGetColumnClassName, onGetColumnStyle = _a.onGetColumnStyle, onGetColumnSx = _a.onGetColumnSx, props = __rest(_a, ["className", "style", "id", "index", "defaultAlign", "defaultEllipsis", "sortable", "columns", "item", "onClick", "onCheckChange", "onGetColumnClassName", "onGetColumnStyle", "onGetColumnSx"]);
553
- var _b = sortable.useSortable({ id: id }), attributes = _b.attributes, listeners = _b.listeners, setNodeRef = _b.setNodeRef, transform = _b.transform, transition = _b.transition;
554
- /********************************************************************************************************************
555
- * Memo
556
- * ******************************************************************************************************************/
557
- var finalStyle = React.useMemo(function () {
558
- return sortable$1
559
- ? __assign(__assign({}, style), { transform: CSS.Transform.toString(transform), transition: transition }) : style;
560
- }, [sortable$1, style, transform, transition]);
561
- var sortableProps = React.useMemo(function () {
562
- return sortable$1
563
- ? __assign(__assign({ ref: setNodeRef }, attributes), listeners) : {};
564
- }, [attributes, listeners, setNodeRef, sortable$1]);
565
- /********************************************************************************************************************
566
- * Render
567
- * ******************************************************************************************************************/
568
- return (React.createElement(StyledBodyRow, __assign({ className: classNames('TableBodyRow', className), style: finalStyle }, props, sortableProps), columns.map(function (column, columnIdx) { return (React.createElement(TableBodyCell, { className: onGetColumnClassName ? onGetColumnClassName(column, item, index) : undefined, sx: onGetColumnSx ? onGetColumnSx(column, item, index) : undefined, style: onGetColumnStyle ? onGetColumnStyle(column, item, index) : undefined, key: columnIdx, index: index, item: item, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, column: column, onClick: onClick, onCheckChange: onCheckChange })); })));
569
- };
570
- TableBodyRow.displayName = 'TableBodyRow';
571
- TableBodyRow.defaultProps = TableBodyRowDefaultProps;var TableFooterCell = function (_a) {
572
- /********************************************************************************************************************
573
- * Memo
574
- * ******************************************************************************************************************/
575
- var column = _a.column, defaultAlign = _a.defaultAlign;
576
- var data = React.useMemo(function () {
577
- var _a, _b, _c;
578
- if ((_a = column.footer) === null || _a === void 0 ? void 0 : _a.onRender) {
579
- return (_b = column.footer) === null || _b === void 0 ? void 0 : _b.onRender();
580
- }
581
- else {
582
- return (_c = column.footer) === null || _c === void 0 ? void 0 : _c.value;
583
- }
584
- }, [column]);
585
- /********************************************************************************************************************
586
- * Render
587
- * ******************************************************************************************************************/
588
- return (React.createElement(TableCommonCell, { type: 'head', className: 'TableFooterCell', column: column, defaultAlign: defaultAlign }, data));
589
- };var TablePagination = function (_a) {
590
- var className = _a.className, style = _a.style, sx = _a.sx, paging = _a.paging, align = _a.align, onChange = _a.onChange;
591
- return (React.createElement(material.Stack, { alignItems: align },
592
- React.createElement(material.Pagination, { count: paging.last_page, page: paging.current_page, color: 'primary', className: classNames('TablePagination', className), style: style, sx: sx, onChange: function (e, page) {
593
- if (onChange)
594
- onChange(page);
595
- } })));
596
- };var TableContextProvider = function (_a) {
597
- var children = _a.children, value = _a.value;
598
- return React.createElement(TableContext.Provider, { value: value }, children);
599
- };var TableTopHeadDefaultProps = {};var TableTopHeadCaptionRow = material.styled(material.TableRow)(function (_a) {
600
- var theme = _a.theme;
601
- return ({
602
- '> th': {
603
- backgroundColor: theme.palette.grey.A100,
604
- textAlign: 'center',
605
- fontWeight: 700,
606
- },
607
- });
608
- });var TableHeadCell = function (_a) {
609
- /********************************************************************************************************************
610
- * Use
611
- * ******************************************************************************************************************/
612
- var column = _a.column, defaultAlign = _a.defaultAlign, top = _a.top, onCheckChange = _a.onCheckChange;
613
- var _b = useTableState(), setHeadColumnChecked = _b.setHeadColumnChecked, setHeadColumnCommands = _b.setHeadColumnCommands;
614
- /********************************************************************************************************************
615
- * State
616
- * ******************************************************************************************************************/
617
- var _c = React.useState(false), checked = _c[0], setChecked = _c[1];
618
- var _d = React.useState(false), checkDisabled = _d[0], setCheckDisabled = _d[1];
619
- /********************************************************************************************************************
620
- * Effect
621
- * ******************************************************************************************************************/
622
- React.useEffect(function () {
623
- if (column.type === 'check') {
624
- setHeadColumnChecked(column, checked);
625
- }
626
- }, [column, checked, setHeadColumnChecked]);
627
- React.useEffect(function () {
628
- setHeadColumnCommands(column, {
629
- setChecked: function (checked) {
630
- if (column.type === 'check') {
631
- setChecked(checked);
632
- }
633
- },
634
- setCheckDisabled: function (checkDisabled) {
635
- if (column.type === 'check') {
636
- setCheckDisabled(checkDisabled);
637
- }
638
- },
639
- });
640
- }, [setHeadColumnCommands, column]);
641
- /********************************************************************************************************************
642
- * Memo
643
- * ******************************************************************************************************************/
644
- var style = React.useMemo(function () { return (top !== undefined ? { top: top } : undefined); }, [top]);
645
- var data = React.useMemo(function () {
646
- var _a, _b;
647
- if (column.type === 'check') {
648
- return column.hideAllCheck ? null : (React.createElement(material.Checkbox, { checked: checked, disabled: checkDisabled, onChange: function (e, newChecked) {
649
- setChecked(newChecked);
650
- onCheckChange && onCheckChange(column, newChecked);
651
- } }));
652
- }
653
- else {
654
- if ((_a = column.head) === null || _a === void 0 ? void 0 : _a.onRender) {
655
- return (_b = column.head) === null || _b === void 0 ? void 0 : _b.onRender();
656
- }
657
- else {
658
- if (typeof column.label === 'string') {
659
- return React.createElement("div", { dangerouslySetInnerHTML: { __html: column.label } });
660
- }
661
- else {
662
- return column.label;
663
- }
664
- }
665
- }
666
- }, [checkDisabled, checked, column, onCheckChange]);
667
- /********************************************************************************************************************
668
- * Render
669
- * ******************************************************************************************************************/
670
- return (React.createElement(TableCommonCell, { type: 'head', className: 'TableHeadCell', style: style, column: column, defaultAlign: defaultAlign }, data));
671
- };var BottomLine = material.styled('div')(templateObject_1$1 || (templateObject_1$1 = __makeTemplateObject(["\n height: 1px;\n position: absolute;\n left: 3px;\n right: 3px;\n bottom: 0;\n"], ["\n height: 1px;\n position: absolute;\n left: 3px;\n right: 3px;\n bottom: 0;\n"])));
672
- var TableTopHead = function (_a) {
673
- /********************************************************************************************************************
674
- * Use
675
- * ******************************************************************************************************************/
676
- var columns = _a.columns, rows = _a.rows, caption = _a.caption, defaultAlign = _a.defaultAlign, onCheckChange = _a.onCheckChange;
677
- var theme = material.useTheme();
678
- /********************************************************************************************************************
679
- * Ref
680
- * ******************************************************************************************************************/
681
- var captionRef = React.useRef(null);
682
- var row1Ref = React.useRef(null);
683
- var row2Ref = React.useRef(null);
684
- var row3Ref = React.useRef(null);
685
- /********************************************************************************************************************
686
- * ResizeDetector
687
- * ******************************************************************************************************************/
688
- var captionHeight = reactResizeDetector.useResizeDetector({
689
- targetRef: captionRef,
690
- handleWidth: false,
691
- handleHeight: true,
692
- }).height;
693
- var row1Height = reactResizeDetector.useResizeDetector({ targetRef: row1Ref, handleWidth: false, handleHeight: true }).height;
694
- var row2Height = reactResizeDetector.useResizeDetector({ targetRef: row2Ref, handleWidth: false, handleHeight: true }).height;
695
- var row3Height = reactResizeDetector.useResizeDetector({ targetRef: row3Ref, handleWidth: false, handleHeight: true }).height;
696
- /********************************************************************************************************************
697
- * Function
698
- * ******************************************************************************************************************/
699
- var captionRow = React.useMemo(function () {
700
- return !!caption && (React.createElement(TableTopHeadCaptionRow, { ref: captionRef, className: 'TableTopHeadCaptionRow' },
701
- React.createElement(material.TableCell, { colSpan: columns.length }, caption)));
702
- }, [caption, columns]);
703
- var makeRowCells = React.useCallback(function (row, top) {
704
- var totalColumns = 0;
705
- var cells = row
706
- .map(function (info, idx) {
707
- if (info) {
708
- totalColumns += info.colSpan || 1;
709
- return (React.createElement(material.TableCell, { key: idx, colSpan: info.colSpan, align: info.align, style: {
710
- top: top,
711
- borderBottom: 0,
712
- } },
713
- info.label,
714
- info.label != null && React.createElement(BottomLine, { style: { backgroundColor: theme.palette.divider } })));
715
- }
716
- })
717
- .filter(function (cell) { return !!cell; });
718
- if (totalColumns < columns.length) {
719
- cells.push(React.createElement(material.TableCell, { key: columns.length, colSpan: columns.length - cells.length, style: { top: top, borderBottom: 0 } }));
720
- }
721
- return cells;
722
- }, [columns, theme.palette.divider]);
723
- var columnRow = React.useMemo(function () {
724
- var top = (captionHeight || 0) + (row1Height || 0) + (row2Height || 0) + (row3Height || 0);
725
- return (React.createElement(material.TableRow, null, columns.map(function (column, idx) { return (React.createElement(TableHeadCell, { key: idx, column: column, defaultAlign: defaultAlign, top: top, onCheckChange: onCheckChange })); })));
726
- }, [captionHeight, columns, defaultAlign, onCheckChange, row1Height, row2Height, row3Height]);
727
- /********************************************************************************************************************
728
- * Render
729
- * ******************************************************************************************************************/
730
- if (rows) {
731
- if (Array.isArray(rows[0])) {
732
- return (React.createElement(material.TableHead, { className: 'TableHead' },
733
- captionRow,
734
- rows.map(function (row, idx) {
735
- var ref = undefined;
736
- var top = undefined;
737
- switch (idx) {
738
- case 0:
739
- ref = row1Ref;
740
- top = captionHeight;
741
- break;
742
- case 1:
743
- ref = row2Ref;
744
- top = (captionHeight || 0) + (row1Height || 0);
745
- break;
746
- case 2:
747
- ref = row3Ref;
748
- top = (captionHeight || 0) + (row1Height || 0) + (row2Height || 0);
749
- break;
750
- case 3:
751
- top = (captionHeight || 0) + (row1Height || 0) + (row2Height || 0) + (row3Height || 0);
752
- }
753
- return (React.createElement(material.TableRow, { key: idx, ref: ref, className: 'TableHeadRow' }, makeRowCells(row, top)));
754
- })));
755
- }
756
- else {
757
- return (React.createElement(material.TableHead, { className: 'TableHead' },
758
- captionRow,
759
- React.createElement(material.TableRow, { ref: row1Ref, className: 'TableHeadRow' }, makeRowCells(rows, captionHeight)),
760
- columnRow));
761
- }
762
- }
763
- else {
764
- return (React.createElement(material.TableHead, { className: 'TableHead' },
765
- captionRow,
766
- columnRow));
767
- }
768
- };
769
- TableTopHead.displayName = 'TableTopHead';
770
- TableTopHead.defaultProps = TableTopHeadDefaultProps;
771
- var templateObject_1$1;function columnFilter(v) {
772
- return v !== undefined && v !== null && v !== false;
773
- }
774
- var _columnId = 0;
775
- var Table = React.forwardRef(function (_a, ref) {
776
- /********************************************************************************************************************
777
- * Ref
778
- * ******************************************************************************************************************/
779
- var className = _a.className, initStyle = _a.style, sx = _a.sx, caption = _a.caption, topHeadRows = _a.topHeadRows, initColumns = _a.columns, initItems = _a.items, initPaging = _a.paging, pagingAlign = _a.pagingAlign, defaultAlign = _a.defaultAlign, defaultEllipsis = _a.defaultEllipsis, initStickyHeader = _a.stickyHeader, height = _a.height, minHeight = _a.minHeight, maxHeight = _a.maxHeight, fullHeight = _a.fullHeight, showOddColor = _a.showOddColor, showEvenColor = _a.showEvenColor, cellPadding = _a.cellPadding, footer = _a.footer, noData = _a.noData, pagination = _a.pagination, sortable$1 = _a.sortable, onClick = _a.onClick, onGetBodyRowClassName = _a.onGetBodyRowClassName, onGetBodyRowStyle = _a.onGetBodyRowStyle, onGetBodyRowSx = _a.onGetBodyRowSx, onGetBodyColumnClassName = _a.onGetBodyColumnClassName, onGetBodyColumnStyle = _a.onGetBodyColumnStyle, onGetBodyColumnSx = _a.onGetBodyColumnSx, onPageChange = _a.onPageChange, onSortChange = _a.onSortChange, onCheckChange = _a.onCheckChange;
780
- var localHeaderDataRef = React.useRef({});
781
- var localBodyDataRef = React.useRef({});
782
- var updateHeadCheckTimer = React.useRef();
783
- var fireOnCheckChangeTimer = React.useRef({});
784
- var simpleBarRef = React.useRef(null);
785
- var finalColumnsIdRef = React.useRef([]);
786
- /********************************************************************************************************************
787
- * sortable
788
- * ******************************************************************************************************************/
789
- var sensors = core.useSensors(core.useSensor(core.MouseSensor, {
790
- // Require the mouse to move by 10 pixels before activating
791
- activationConstraint: {
792
- distance: 10,
793
- },
794
- }), core.useSensor(core.TouchSensor, {
795
- // Press delay of 250ms, with tolerance of 5px of movement
796
- activationConstraint: {
797
- delay: 250,
798
- tolerance: 5,
799
- },
800
- }), core.useSensor(core.KeyboardSensor, {
801
- coordinateGetter: sortable.sortableKeyboardCoordinates,
802
- }));
803
- /********************************************************************************************************************
804
- * State
805
- * ******************************************************************************************************************/
806
- var _b = React.useState(false), menuOpen = _b[0], setMenuOpen = _b[1];
807
- var _c = React.useState(undefined), openMenuId = _c[0], setOpenMenuId = _c[1];
808
- var _d = reactHook.useAutoUpdateLayoutState(initColumns), columns = _d[0], setColumns = _d[1];
809
- var _e = React.useState(), finalColumns = _e[0], setFinalColumns = _e[1];
810
- var _f = reactHook.useAutoUpdateLayoutState(initItems), items = _f[0], setItems = _f[1];
811
- var _g = React.useState(), sortableItems = _g[0], setSortableItems = _g[1];
812
- var _h = reactHook.useAutoUpdateLayoutState(initPaging), paging = _h[0], setPaging = _h[1];
813
- /********************************************************************************************************************
814
- * containerHeight
815
- * ******************************************************************************************************************/
816
- var _j = React.useState(), containerHeight = _j[0], setContainerHeight = _j[1];
817
- var containerHeightDetector = reactResizeDetector.useResizeDetector({
818
- handleHeight: true,
819
- handleWidth: false,
820
- onResize: function () {
821
- if (containerHeightDetector.current) {
822
- setContainerHeight(containerHeightDetector.current.getBoundingClientRect().height);
823
- }
824
- else {
825
- setContainerHeight(undefined);
826
- }
827
- },
828
- }).ref;
829
- /********************************************************************************************************************
830
- * footerHeight
831
- * ******************************************************************************************************************/
832
- var _k = React.useState(), pagingHeight = _k[0], setPagingHeight = _k[1];
833
- var pagingHeightResizeDetector = reactResizeDetector.useResizeDetector({
834
- handleHeight: true,
835
- handleWidth: false,
836
- onResize: function () {
837
- if (pagingHeightResizeDetector.current) {
838
- setPagingHeight(pagingHeightResizeDetector.current.getBoundingClientRect().height);
839
- }
840
- else {
841
- setPagingHeight(undefined);
842
- }
843
- },
844
- }).ref;
845
- /********************************************************************************************************************
846
- * Memo
847
- * ******************************************************************************************************************/
848
- var tableSx = React.useMemo(function () {
849
- var sx = {
850
- padding: typeof cellPadding === 'number' ? "".concat(cellPadding, "px") : cellPadding,
851
- };
852
- return {
853
- '> .MuiTableHead-root > .MuiTableRow-root > .MuiTableCell-root ': sx,
854
- '> .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root ': sx,
855
- '> .MuiTableFooter-root > .MuiTableRow-root > .MuiTableCell-root ': sx,
856
- };
857
- }, [cellPadding]);
858
- /********************************************************************************************************************
859
- * Function
860
- * ******************************************************************************************************************/
861
- var makeSortableItems = React.useCallback(function (items) {
862
- return items === null || items === void 0 ? void 0 : items.map(function (_a, index) {
863
- var id = _a.id, item = __rest(_a, ["id"]);
864
- return __assign({ id: id == null ? "".concat(uuid.v4(), "_").concat(index) : id }, item);
865
- });
866
- }, []);
867
- var getFinalColumnId = React.useCallback(function (column) {
868
- if (finalColumns && finalColumnsIdRef.current) {
869
- var idx = finalColumns.indexOf(column);
870
- return finalColumnsIdRef.current[idx];
871
- }
872
- else {
873
- return '';
874
- }
875
- }, [finalColumns]);
876
- var updateHeadCheck = React.useCallback(function (column) {
877
- if (updateHeadCheckTimer.current) {
878
- clearTimeout(updateHeadCheckTimer.current);
879
- updateHeadCheckTimer.current = undefined;
880
- }
881
- var columnId = getFinalColumnId(column);
882
- var headColumnData = localHeaderDataRef.current[columnId];
883
- if (headColumnData) {
884
- updateHeadCheckTimer.current = setTimeout(function () {
885
- var _a, _b;
886
- updateHeadCheckTimer.current = undefined;
887
- var enabledCheckExists = !!Object.keys(localBodyDataRef.current).find(function (key) {
888
- var columnData = localBodyDataRef.current[key].columns[columnId];
889
- if (columnData) {
890
- if (!columnData.checkDisabled) {
891
- return true;
892
- }
893
- }
894
- });
895
- var allChecked = enabledCheckExists &&
896
- !Object.keys(localBodyDataRef.current).find(function (key) {
897
- var columnData = localBodyDataRef.current[key].columns[columnId];
898
- if (columnData) {
899
- if (!columnData.checkDisabled) {
900
- return !columnData.checked;
901
- }
902
- }
903
- });
904
- (_a = headColumnData.commands) === null || _a === void 0 ? void 0 : _a.setCheckDisabled(!enabledCheckExists);
905
- (_b = headColumnData.commands) === null || _b === void 0 ? void 0 : _b.setChecked(allChecked);
906
- }, 100);
907
- }
908
- }, [getFinalColumnId]);
909
- var getCheckedItems = React.useCallback(function (columnId) {
910
- var checkedItems = [];
911
- Object.keys(localBodyDataRef.current).forEach(function (key) {
912
- var itemData = localBodyDataRef.current[key];
913
- var columnData = itemData.columns[columnId];
914
- if (columnData) {
915
- if (columnData.checked) {
916
- checkedItems.push(itemData.item);
917
- }
918
- }
919
- });
920
- return checkedItems;
921
- }, []);
922
- var stopHeadCheckTimer = React.useCallback(function () {
923
- if (updateHeadCheckTimer.current) {
924
- clearTimeout(updateHeadCheckTimer.current);
925
- updateHeadCheckTimer.current = undefined;
926
- }
927
- }, []);
928
- var clearFireOnCheckChangeTimer = React.useCallback(function () {
929
- Object.keys(fireOnCheckChangeTimer.current).forEach(function (key) {
930
- if (fireOnCheckChangeTimer.current[key]) {
931
- clearTimeout(fireOnCheckChangeTimer.current[key]);
932
- }
933
- });
934
- fireOnCheckChangeTimer.current = {};
935
- }, []);
936
- var fireOnCheckChange = React.useCallback(function (columnId) {
937
- if (fireOnCheckChangeTimer.current[columnId]) {
938
- clearTimeout(fireOnCheckChangeTimer.current[columnId]);
939
- fireOnCheckChangeTimer.current[columnId] = undefined;
940
- }
941
- if (onCheckChange) {
942
- fireOnCheckChangeTimer.current[columnId] = setTimeout(function () {
943
- fireOnCheckChangeTimer.current[columnId] = undefined;
944
- onCheckChange && onCheckChange(columnId, getCheckedItems(columnId));
945
- }, 100);
946
- }
947
- }, [getCheckedItems, onCheckChange]);
948
- var simpleBarScrollToTop = React.useCallback(function () {
949
- var _a, _b;
950
- (_b = (_a = simpleBarRef.current) === null || _a === void 0 ? void 0 : _a.getScrollElement()) === null || _b === void 0 ? void 0 : _b.scrollTo({ top: 0 });
951
- }, []);
952
- /********************************************************************************************************************
953
- * Effect
954
- * ******************************************************************************************************************/
955
- React.useEffect(function () {
956
- return function () {
957
- stopHeadCheckTimer();
958
- clearFireOnCheckChangeTimer();
959
- };
960
- // eslint-disable-next-line react-hooks/exhaustive-deps
961
- }, []);
962
- React.useEffect(function () {
963
- stopHeadCheckTimer();
964
- clearFireOnCheckChangeTimer();
965
- Object.keys(localHeaderDataRef.current).forEach(function (key) {
966
- var _a;
967
- if (localHeaderDataRef.current[key].column.type === 'check') {
968
- (_a = localHeaderDataRef.current[key].commands) === null || _a === void 0 ? void 0 : _a.setChecked(false);
969
- }
970
- });
971
- Object.keys(localBodyDataRef.current).forEach(function (key) {
972
- Object.keys(localBodyDataRef.current[key].columns).forEach(function (cKey) {
973
- var _a;
974
- (_a = localBodyDataRef.current[key].columns[cKey].commands) === null || _a === void 0 ? void 0 : _a.setChecked(false);
975
- });
976
- });
977
- setSortableItems(makeSortableItems(items));
978
- // eslint-disable-next-line react-hooks/exhaustive-deps
979
- }, [items]);
980
- React.useEffect(function () {
981
- stopHeadCheckTimer();
982
- clearFireOnCheckChangeTimer();
983
- var newFinalColumns = columns === null || columns === void 0 ? void 0 : columns.filter(columnFilter);
984
- setFinalColumns(newFinalColumns);
985
- finalColumnsIdRef.current = newFinalColumns === null || newFinalColumns === void 0 ? void 0 : newFinalColumns.map(function (col) {
986
- if (col.id) {
987
- return col.id;
988
- }
989
- else {
990
- _columnId += 1;
991
- return "$c$".concat(_columnId, "$");
992
- }
993
- });
994
- // eslint-disable-next-line react-hooks/exhaustive-deps
995
- }, [columns]);
996
- React.useLayoutEffect(function () {
997
- clearFireOnCheckChangeTimer();
998
- if (sortableItems) {
999
- localBodyDataRef.current = sortableItems.reduce(function (res, item) {
1000
- res[item.id] = {
1001
- item: item,
1002
- columns: {},
1003
- };
1004
- if (finalColumns) {
1005
- finalColumns.forEach(function (c) {
1006
- var _a;
1007
- var columnId = getFinalColumnId(c);
1008
- if ((_a = localBodyDataRef.current[item.id]) === null || _a === void 0 ? void 0 : _a.columns[columnId]) {
1009
- res[item.id].columns[columnId] = localBodyDataRef.current[item.id].columns[columnId];
1010
- }
1011
- else {
1012
- res[item.id].columns[columnId] = {
1013
- column: c,
1014
- checked: false,
1015
- checkDisabled: false,
1016
- };
1017
- }
1018
- });
1019
- }
1020
- return res;
1021
- }, {});
1022
- }
1023
- else {
1024
- localBodyDataRef.current = {};
1025
- }
1026
- }, [sortableItems, finalColumns, clearFireOnCheckChangeTimer, getFinalColumnId]);
1027
- React.useLayoutEffect(function () {
1028
- if (finalColumns) {
1029
- localHeaderDataRef.current = finalColumns.reduce(function (res, c) {
1030
- res[getFinalColumnId(c)] = { column: c, checked: false };
1031
- return res;
1032
- }, {});
1033
- }
1034
- else {
1035
- localHeaderDataRef.current = {};
1036
- }
1037
- }, [finalColumns, getFinalColumnId]);
1038
- /********************************************************************************************************************
1039
- * Commands
1040
- * ******************************************************************************************************************/
1041
- React.useLayoutEffect(function () {
1042
- if (ref) {
1043
- var lastColumns_1 = columns;
1044
- var lastItems_1 = items;
1045
- var lastPaging_1 = paging;
1046
- var commands = {
1047
- getColumns: function () { return lastColumns_1; },
1048
- setColumns: function (columns) {
1049
- lastColumns_1 = columns;
1050
- setColumns(lastColumns_1);
1051
- },
1052
- getItems: function () { return lastItems_1; },
1053
- setItems: function (items) {
1054
- lastItems_1 = items;
1055
- setItems(items);
1056
- },
1057
- getPaging: function () { return lastPaging_1; },
1058
- setItemsPaging: function (items, paging) {
1059
- lastItems_1 = items;
1060
- lastPaging_1 = paging;
1061
- setItems(lastItems_1);
1062
- setPaging(lastPaging_1);
1063
- },
1064
- resetSort: function () {
1065
- setSortableItems(makeSortableItems(lastItems_1));
1066
- },
1067
- getCheckedItems: getCheckedItems,
1068
- scrollToTop: simpleBarScrollToTop,
1069
- };
1070
- if (typeof ref === 'function') {
1071
- ref(commands);
1072
- }
1073
- else {
1074
- ref.current = commands;
1075
- }
1076
- }
1077
- }, [
1078
- ref,
1079
- columns,
1080
- items,
1081
- paging,
1082
- makeSortableItems,
1083
- setColumns,
1084
- setItems,
1085
- setPaging,
1086
- getCheckedItems,
1087
- simpleBarScrollToTop,
1088
- ]);
1089
- /********************************************************************************************************************
1090
- * Event Handler
1091
- * ******************************************************************************************************************/
1092
- var handleDragEnd = React.useCallback(function (event) {
1093
- var active = event.active, over = event.over;
1094
- if (active && over) {
1095
- setSortableItems(function (items) {
1096
- if (items) {
1097
- var oldIndex_1 = null;
1098
- var newIndex_1 = null;
1099
- items.find(function (item, idx) {
1100
- if (item.id === active.id) {
1101
- oldIndex_1 = idx;
1102
- }
1103
- else if (item.id === over.id) {
1104
- newIndex_1 = idx;
1105
- }
1106
- return oldIndex_1 != null && newIndex_1 != null;
1107
- });
1108
- if (oldIndex_1 != null && newIndex_1 != null) {
1109
- var finalItems = sortable.arrayMove(items, oldIndex_1, newIndex_1);
1110
- onSortChange && onSortChange(finalItems);
1111
- return finalItems;
1112
- }
1113
- else {
1114
- return items;
1115
- }
1116
- }
1117
- else {
1118
- return items;
1119
- }
1120
- });
1121
- }
1122
- }, [onSortChange]);
1123
- var handleHeadCheckChange = React.useCallback(function (column, checked) {
1124
- Object.keys(localBodyDataRef.current).forEach(function (key) {
1125
- var _a;
1126
- var data = localBodyDataRef.current[key].columns[getFinalColumnId(column)];
1127
- if (data) {
1128
- if (!data.checkDisabled) {
1129
- (_a = data.commands) === null || _a === void 0 ? void 0 : _a.setChecked(checked);
1130
- }
1131
- }
1132
- });
1133
- }, [getFinalColumnId]);
1134
- var handleBodyCheckChange = React.useCallback(function (item, column) {
1135
- updateHeadCheck(column);
1136
- }, [updateHeadCheck]);
1137
- var handlePageChange = React.useCallback(function (page) {
1138
- simpleBarScrollToTop();
1139
- onPageChange && onPageChange(page);
1140
- }, [onPageChange, simpleBarScrollToTop]);
1141
- /********************************************************************************************************************
1142
- * TableContext Function
1143
- * ******************************************************************************************************************/
1144
- var TableContextSetMenuOpen = React.useCallback(function (newMenuOpen, newOpenMenuId) {
1145
- if (newMenuOpen) {
1146
- setMenuOpen(newMenuOpen);
1147
- setOpenMenuId(newOpenMenuId);
1148
- }
1149
- else {
1150
- if (openMenuId === newOpenMenuId) {
1151
- setMenuOpen(false);
1152
- setOpenMenuId(undefined);
1153
- }
1154
- }
1155
- }, [openMenuId]);
1156
- var TableContextSetItemColumnChecked = React.useCallback(function (item, column, checked) {
1157
- var _a;
1158
- var columnId = getFinalColumnId(column);
1159
- var data = (_a = localBodyDataRef.current[item.id]) === null || _a === void 0 ? void 0 : _a.columns[columnId];
1160
- if (data) {
1161
- data.checked = checked;
1162
- fireOnCheckChange(columnId);
1163
- }
1164
- }, [fireOnCheckChange, getFinalColumnId]);
1165
- var TableContextSetItemColumnCheckDisabled = React.useCallback(function (item, column, disabled) {
1166
- var _a;
1167
- var data = (_a = localBodyDataRef.current[item.id]) === null || _a === void 0 ? void 0 : _a.columns[getFinalColumnId(column)];
1168
- if (data) {
1169
- data.checkDisabled = disabled;
1170
- updateHeadCheck(column);
1171
- }
1172
- }, [getFinalColumnId, updateHeadCheck]);
1173
- var TableContextSetItemColumnCommands = React.useCallback(function (item, column, commands) {
1174
- var _a;
1175
- var data = (_a = localBodyDataRef.current[item.id]) === null || _a === void 0 ? void 0 : _a.columns[getFinalColumnId(column)];
1176
- if (data) {
1177
- data.commands = commands;
1178
- }
1179
- }, [getFinalColumnId]);
1180
- var TableContextSetHeadColumnChecked = React.useCallback(function (column, checked) {
1181
- var data = localHeaderDataRef.current[getFinalColumnId(column)];
1182
- if (data) {
1183
- data.checked = checked;
1184
- }
1185
- }, [getFinalColumnId]);
1186
- var TableContextSetHeadColumnCommands = React.useCallback(function (column, commands) {
1187
- var data = localHeaderDataRef.current[getFinalColumnId(column)];
1188
- if (data) {
1189
- data.commands = commands;
1190
- }
1191
- }, [getFinalColumnId]);
1192
- /********************************************************************************************************************
1193
- * Memo
1194
- * ******************************************************************************************************************/
1195
- var tableContextValue = React.useMemo(function () { return ({
1196
- menuOpen: menuOpen,
1197
- openMenuId: openMenuId,
1198
- setMenuOpen: TableContextSetMenuOpen,
1199
- setItemColumnChecked: TableContextSetItemColumnChecked,
1200
- setItemColumnCheckDisabled: TableContextSetItemColumnCheckDisabled,
1201
- setItemColumnCommands: TableContextSetItemColumnCommands,
1202
- setHeadColumnChecked: TableContextSetHeadColumnChecked,
1203
- setHeadColumnCommands: TableContextSetHeadColumnCommands,
1204
- }); }, [
1205
- TableContextSetHeadColumnChecked,
1206
- TableContextSetHeadColumnCommands,
1207
- TableContextSetItemColumnCheckDisabled,
1208
- TableContextSetItemColumnChecked,
1209
- TableContextSetItemColumnCommands,
1210
- TableContextSetMenuOpen,
1211
- menuOpen,
1212
- openMenuId,
1213
- ]);
1214
- var isNoData = React.useMemo(function () { return !!sortableItems && sortableItems.length <= 0; }, [sortableItems]);
1215
- var finalPagingHeight = React.useMemo(function () { return (paging && paging.total > 0 ? pagingHeight || 0 : 0); }, [paging, pagingHeight]);
1216
- var stickyHeader = React.useMemo(function () { return !isNoData && initStickyHeader; }, [initStickyHeader, isNoData]);
1217
- var style = React.useMemo(function () {
1218
- if (fullHeight) {
1219
- return __assign(__assign({ width: '100%' }, initStyle), { flex: 1, justifyContent: 'flex-end', height: '100%', display: 'flex', flexDirection: 'column', position: 'relative' });
1220
- }
1221
- else {
1222
- return __assign({ width: '100%' }, initStyle);
1223
- }
1224
- }, [initStyle, fullHeight]);
1225
- var simpleBarStyle = React.useMemo(function () {
1226
- if (fullHeight) {
1227
- return {
1228
- height: (containerHeight || 0) - (finalPagingHeight || 0) - 1,
1229
- flex: 1,
1230
- position: 'absolute',
1231
- top: 0,
1232
- left: 0,
1233
- right: 0,
1234
- marginBottom: finalPagingHeight || 0,
1235
- };
1236
- }
1237
- else {
1238
- return { height: height, minHeight: minHeight, maxHeight: maxHeight, marginBottom: -1 };
1239
- }
1240
- }, [fullHeight, containerHeight, finalPagingHeight, height, minHeight, maxHeight]);
1241
- var tableStyle = React.useMemo(function () {
1242
- if (fullHeight && isNoData) {
1243
- return { flex: 1, height: (containerHeight || 0) - finalPagingHeight - 2 };
1244
- }
1245
- }, [fullHeight, isNoData, containerHeight, finalPagingHeight]);
1246
- var pagingStyle = React.useMemo(function () {
1247
- var style = { padding: '13px 0', borderTop: '1px solid rgba(224, 224, 224, 1)' };
1248
- if (fullHeight) {
1249
- return __assign({ position: 'sticky' }, style);
1250
- }
1251
- return style;
1252
- }, [fullHeight]);
1253
- var tableTopHead = React.useMemo(function () {
1254
- return finalColumns && (React.createElement(TableTopHead, { caption: caption, rows: topHeadRows, columns: finalColumns, defaultAlign: defaultAlign, onCheckChange: handleHeadCheckChange }));
1255
- }, [caption, defaultAlign, finalColumns, handleHeadCheckChange, topHeadRows]);
1256
- var tableBody = React.useMemo(function () {
1257
- return finalColumns && (React.createElement(material.TableBody, null, sortableItems ? (sortableItems.length > 0 ? (React.createElement(sortable.SortableContext, { items: sortableItems, strategy: sortable.verticalListSortingStrategy }, sortableItems.map(function (item, idx) { return (React.createElement(TableBodyRow, { key: item.id, className: classNames(!!showOddColor && 'odd-color', !!showEvenColor && 'even-color', onGetBodyRowClassName ? onGetBodyRowClassName(item, idx) : undefined), style: onGetBodyRowStyle ? onGetBodyRowStyle(item, idx) : undefined, sx: onGetBodyRowSx ? onGetBodyRowSx(item, idx) : undefined, onGetColumnClassName: onGetBodyColumnClassName, onGetColumnStyle: onGetBodyColumnStyle, onGetColumnSx: onGetBodyColumnSx, hover: true, id: item.id, index: idx, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, sortable: sortable$1, columns: finalColumns, item: item, onClick: onClick, onCheckChange: handleBodyCheckChange })); }))) : (React.createElement(StyledBodyRow$1, null,
1258
- React.createElement(material.TableCell, { colSpan: finalColumns.length, style: { flex: 1 } }, noData ? (noData) : (React.createElement(StyledNoDataDiv, null,
1259
- React.createElement("div", null,
1260
- React.createElement(material.Icon, null, "error")),
1261
- React.createElement("div", null, "\uAC80\uC0C9\uB41C \uC815\uBCF4\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."))))))) : undefined));
1262
- }, [
1263
- defaultAlign,
1264
- defaultEllipsis,
1265
- finalColumns,
1266
- handleBodyCheckChange,
1267
- noData,
1268
- onClick,
1269
- onGetBodyColumnClassName,
1270
- onGetBodyColumnStyle,
1271
- onGetBodyColumnSx,
1272
- onGetBodyRowClassName,
1273
- onGetBodyRowStyle,
1274
- onGetBodyRowSx,
1275
- showEvenColor,
1276
- showOddColor,
1277
- sortable$1,
1278
- sortableItems,
1279
- ]);
1280
- var tableFooter = React.useMemo(function () {
1281
- return finalColumns &&
1282
- !isNoData &&
1283
- footer && (React.createElement(material.TableFooter, null,
1284
- React.createElement(material.TableRow, null, finalColumns.map(function (column, idx) { return (React.createElement(TableFooterCell, { key: idx, column: column, defaultAlign: defaultAlign })); }))));
1285
- }, [defaultAlign, finalColumns, footer, isNoData]);
1286
- var tablePaging = React.useMemo(function () {
1287
- return finalColumns &&
1288
- paging &&
1289
- paging.total > 0 && (React.createElement(material.Stack, { ref: fullHeight ? pagingHeightResizeDetector : undefined, alignItems: pagingAlign, style: pagingStyle },
1290
- React.createElement(TablePagination, { className: pagination === null || pagination === void 0 ? void 0 : pagination.className, style: pagination === null || pagination === void 0 ? void 0 : pagination.style, sx: pagination === null || pagination === void 0 ? void 0 : pagination.sx, paging: paging, align: pagingAlign, onChange: handlePageChange })));
1291
- }, [
1292
- finalColumns,
1293
- fullHeight,
1294
- handlePageChange,
1295
- pagination === null || pagination === void 0 ? void 0 : pagination.className,
1296
- pagination === null || pagination === void 0 ? void 0 : pagination.style,
1297
- pagination === null || pagination === void 0 ? void 0 : pagination.sx,
1298
- paging,
1299
- pagingAlign,
1300
- pagingHeightResizeDetector,
1301
- pagingStyle,
1302
- ]);
1303
- /********************************************************************************************************************
1304
- * Render
1305
- * ******************************************************************************************************************/
1306
- return finalColumns ? (React.createElement(TableContextProvider, { value: tableContextValue },
1307
- React.createElement(material.Paper, { ref: fullHeight ? containerHeightDetector : undefined, className: classNames('Table', className, !!stickyHeader && 'sticky-header', !!fullHeight && 'full-height', !!showOddColor && 'odd-color', !!showEvenColor && 'even-color', !!sortable$1 && 'sortable'), variant: 'outlined', style: style, sx: sx },
1308
- React.createElement(SimpleBar, { ref: simpleBarRef, style: simpleBarStyle },
1309
- React.createElement(core.DndContext, { sensors: sensors, collisionDetection: core.closestCenter, onDragEnd: handleDragEnd },
1310
- React.createElement(material.Table, { stickyHeader: stickyHeader, sx: tableSx, style: tableStyle },
1311
- tableTopHead,
1312
- tableBody,
1313
- tableFooter))),
1314
- tablePaging))) : null;
1315
- });
1316
- Table.displayName = 'Table';
1317
- Table.defaultProps = TableDefaultProps;var SearchTableDefaultProps = {};var SearchTable = React.forwardRef(function (_a, ref) {
1318
- /********************************************************************************************************************
1319
- * Ref
1320
- * ******************************************************************************************************************/
1321
- var _b, _c;
1322
- var className = _a.className, initStyle = _a.style, sx = _a.sx, color = _a.color, hash = _a.hash, stickyHeader = _a.stickyHeader, fullHeight = _a.fullHeight, search = _a.search, table = _a.table, betweenSearchTableComponent = _a.betweenSearchTableComponent, onGetData = _a.onGetData, onRequestHashChange = _a.onRequestHashChange;
1323
- var searchRef = React.useRef();
1324
- var tableRef = React.useRef();
1325
- var lastGetDataDataRef = React.useRef({});
1326
- /********************************************************************************************************************
1327
- * Function
1328
- * ******************************************************************************************************************/
1329
- var getSearchInfo = React.useCallback(function (search) {
1330
- var searchInfo = {};
1331
- if (search) {
1332
- var ref_1 = search.ref, searchGroups = search.searchGroups, props = __rest(search, ["ref", "searchGroups"]);
1333
- searchInfo.ref = ref_1;
1334
- searchInfo.searchGroups = searchGroups;
1335
- searchInfo.props = props;
1336
- }
1337
- return searchInfo;
1338
- }, []);
1339
- var getTableInfo = React.useCallback(function (table) {
1340
- var tableInfo = {};
1341
- if (table) {
1342
- var ref_2 = table.ref, props = __rest(table, ["ref"]);
1343
- tableInfo.ref = ref_2;
1344
- tableInfo.props = props;
1345
- }
1346
- return tableInfo;
1347
- }, []);
1348
- /********************************************************************************************************************
1349
- * State
1350
- * ******************************************************************************************************************/
1351
- var _d = React.useState(true), isFirstSearchSubmit = _d[0], setIsFirstSearchSubmit = _d[1];
1352
- var _e = React.useState(), tableData = _e[0], setTableData = _e[1];
1353
- /********************************************************************************************************************
1354
- * searchInfo
1355
- * ******************************************************************************************************************/
1356
- var searchInfoFirstUseEffect = React.useRef(true);
1357
- var _f = React.useState(function () { return getSearchInfo(search); }), searchInfo = _f[0], setSearchInfo = _f[1];
1358
- React.useEffect(function () {
1359
- if (searchInfoFirstUseEffect.current) {
1360
- searchInfoFirstUseEffect.current = false;
1361
- }
1362
- else {
1363
- setSearchInfo(getSearchInfo(search));
1364
- }
1365
- // eslint-disable-next-line react-hooks/exhaustive-deps
1366
- }, [search]);
1367
- /********************************************************************************************************************
1368
- * tableInfo
1369
- * ******************************************************************************************************************/
1370
- var tableInfoFirstUseEffect = React.useRef(true);
1371
- var _g = React.useState(function () { return getTableInfo(table); }), tableInfo = _g[0], setTableInfo = _g[1];
1372
- React.useEffect(function () {
1373
- if (tableInfoFirstUseEffect.current) {
1374
- tableInfoFirstUseEffect.current = false;
1375
- }
1376
- else {
1377
- setTableInfo(getTableInfo(table));
1378
- }
1379
- // eslint-disable-next-line react-hooks/exhaustive-deps
1380
- }, [table]);
1381
- /********************************************************************************************************************
1382
- * Function
1383
- * ******************************************************************************************************************/
1384
- var getData = React.useCallback(function (data) {
1385
- lastGetDataDataRef.current = data;
1386
- if (onGetData) {
1387
- onGetData(data).then(setTableData);
1388
- }
1389
- }, [onGetData]);
1390
- var deHash = React.useCallback(function () {
1391
- var values = {};
1392
- var hash = window.location.hash.substring(1);
1393
- hash.replace(/([^=&]+)=([^&]*)/g, function (substring, key, value) {
1394
- values[decodeURIComponent(key)] = decodeURIComponent(value);
1395
- return substring;
1396
- });
1397
- return values;
1398
- }, []);
1399
- var hashToSearchValue = React.useCallback(function () {
1400
- var commands = searchRef.current;
1401
- if (commands) {
1402
- commands.resetAll();
1403
- var hashValues_1 = deHash();
1404
- Object.keys(hashValues_1).forEach(function (name) {
1405
- var _a, _b;
1406
- var value = hashValues_1[name];
1407
- if (name === 'page') {
1408
- commands.setValue(name, Number(value) || 1);
1409
- }
1410
- else {
1411
- var itemCommands = commands.getItem(name);
1412
- if (itemCommands) {
1413
- switch (itemCommands.getType()) {
1414
- case 'FormCheckbox':
1415
- if (util.notEmpty(value)) {
1416
- var checkCommands = itemCommands;
1417
- if (value.toString() === ((_a = itemCommands.getValue()) === null || _a === void 0 ? void 0 : _a.toString())) {
1418
- checkCommands.setChecked(true);
1419
- }
1420
- else if (value.toString() === ((_b = checkCommands.getUncheckedValue()) === null || _b === void 0 ? void 0 : _b.toString())) {
1421
- checkCommands.setChecked(false);
1422
- }
1423
- }
1424
- break;
1425
- case 'FormDatePicker':
1426
- case 'FormDateTimePicker':
1427
- case 'FormTimePicker':
1428
- {
1429
- if (util.notEmpty(value)) {
1430
- var dateCommands = itemCommands;
1431
- var format = dateCommands.getFormValueFormat();
1432
- var itemValue = dayjs(value, format);
1433
- itemCommands.setValue(itemValue.isValid() ? itemValue : null);
1434
- }
1435
- else {
1436
- itemCommands.setValue(null);
1437
- }
1438
- }
1439
- break;
1440
- case 'FormDateRangePicker':
1441
- {
1442
- var dateRangePickerCommands = itemCommands;
1443
- var fromName = dateRangePickerCommands.getFormValueFromName();
1444
- var toName = dateRangePickerCommands.getFormValueToName();
1445
- var format = dateRangePickerCommands.getFormValueFormat();
1446
- if (name === fromName) {
1447
- if (util.notEmpty(value)) {
1448
- var startValue = dayjs(value, format);
1449
- dateRangePickerCommands.setFromValue(startValue.isValid() ? startValue : null);
1450
- }
1451
- else {
1452
- dateRangePickerCommands.setFromValue(null);
1453
- }
1454
- }
1455
- else if (name === toName) {
1456
- if (util.notEmpty(value)) {
1457
- var endValue = dayjs(value, format);
1458
- dateRangePickerCommands.setToValue(endValue.isValid() ? endValue : null);
1459
- }
1460
- else {
1461
- dateRangePickerCommands.setToValue(null);
1462
- }
1463
- }
1464
- }
1465
- break;
1466
- case 'FormYearRangePicker':
1467
- {
1468
- var dateRangePickerCommands = itemCommands;
1469
- var fromName = dateRangePickerCommands.getFormValueFromName();
1470
- var toName = dateRangePickerCommands.getFormValueToName();
1471
- if (name === fromName) {
1472
- dateRangePickerCommands.setFromValue(util.notEmpty(value) ? Number(value) : null);
1473
- }
1474
- else if (name === toName) {
1475
- dateRangePickerCommands.setToValue(util.notEmpty(value) ? Number(value) : null);
1476
- }
1477
- }
1478
- break;
1479
- case 'FormMonthPicker':
1480
- {
1481
- var monthCommands = itemCommands;
1482
- var yearName = monthCommands.getFormValueYearName();
1483
- var monthName = monthCommands.getFormValueMonthName();
1484
- if (name === yearName) {
1485
- monthCommands.setYear(util.notEmpty(value) ? Number(value) : null);
1486
- }
1487
- else if (name === monthName) {
1488
- monthCommands.setMonth(util.notEmpty(value) ? Number(value) : null);
1489
- }
1490
- }
1491
- break;
1492
- case 'FormMonthRangePicker':
1493
- {
1494
- var monthRangeCommands = itemCommands;
1495
- var fromYearName = monthRangeCommands.getFormValueFromYearName();
1496
- var fromMonthName = monthRangeCommands.getFormValueFromMonthName();
1497
- var toYearName = monthRangeCommands.getFormValueToYearName();
1498
- var toMonthName = monthRangeCommands.getFormValueToMonthName();
1499
- if (name === fromYearName) {
1500
- monthRangeCommands.setFromYear(util.notEmpty(value) ? Number(value) : null);
1501
- }
1502
- else if (name === fromMonthName) {
1503
- monthRangeCommands.setFromMonth(util.notEmpty(value) ? Number(value) : null);
1504
- }
1505
- else if (name === toYearName) {
1506
- monthRangeCommands.setToYear(util.notEmpty(value) ? Number(value) : null);
1507
- }
1508
- else if (name === toMonthName) {
1509
- monthRangeCommands.setToMonth(util.notEmpty(value) ? Number(value) : null);
1510
- }
1511
- }
1512
- break;
1513
- default:
1514
- commands.setValue(name, value);
1515
- break;
1516
- }
1517
- }
1518
- }
1519
- });
1520
- return commands.getAllFormValue();
1521
- }
1522
- }, [searchRef, deHash]);
1523
- /********************************************************************************************************************
1524
- * Commands
1525
- * ******************************************************************************************************************/
1526
- React.useLayoutEffect(function () {
1527
- if (ref) {
1528
- var commands = {
1529
- reload: function (page) {
1530
- var _a, _b, _c, _d;
1531
- if (page != null) {
1532
- (_a = tableRef.current) === null || _a === void 0 ? void 0 : _a.scrollToTop();
1533
- }
1534
- var finalData;
1535
- if (lastGetDataDataRef.current) {
1536
- finalData = __assign({}, lastGetDataDataRef.current);
1537
- if (page != null) {
1538
- (_b = searchRef.current) === null || _b === void 0 ? void 0 : _b.setValue('page', page);
1539
- finalData.page = page;
1540
- }
1541
- }
1542
- else {
1543
- if (hash) {
1544
- hashToSearchValue();
1545
- }
1546
- if (page != null) {
1547
- (_c = searchRef.current) === null || _c === void 0 ? void 0 : _c.setValue('page', page);
1548
- }
1549
- finalData = ((_d = searchRef.current) === null || _d === void 0 ? void 0 : _d.getAllFormValue()) || {};
1550
- }
1551
- getData(finalData);
1552
- },
1553
- getLastLoadData: function () { return lastGetDataDataRef.current || {}; },
1554
- getSearch: function () { return searchRef.current; },
1555
- getTable: function () { return tableRef.current; },
1556
- };
1557
- if (typeof ref === 'function') {
1558
- ref(commands);
1559
- }
1560
- else {
1561
- ref.current = commands;
1562
- }
1563
- }
1564
- }, [ref, hash, lastGetDataDataRef, searchRef, tableRef, getData, hashToSearchValue]);
1565
- /********************************************************************************************************************
1566
- * hash
1567
- * ******************************************************************************************************************/
1568
- React.useEffect(function () {
1569
- if (hash) {
1570
- var data = hashToSearchValue();
1571
- if (data)
1572
- getData(data);
1573
- }
1574
- // eslint-disable-next-line react-hooks/exhaustive-deps
1575
- }, [window.location.hash]);
1576
- var hashChange = React.useCallback(function (params) {
1577
- if (onRequestHashChange) {
1578
- var hashes_1 = [];
1579
- Object.keys(params).forEach(function (name) {
1580
- var value = params[name];
1581
- if (name === 'page') {
1582
- if (Number(value) > 1) {
1583
- hashes_1.push("".concat(name, "=").concat(value));
1584
- }
1585
- }
1586
- else {
1587
- if (searchRef.current) {
1588
- var itemCommands = searchRef.current.getItem(name);
1589
- if (itemCommands) {
1590
- var resetValue = null;
1591
- switch (itemCommands.getType()) {
1592
- case 'FormDateRangePicker':
1593
- case 'FormYearRangePicker':
1594
- {
1595
- var commands = itemCommands;
1596
- var itemName = itemCommands.getName();
1597
- var fromName = commands.getFormValueFromName();
1598
- var fromSuffix = commands.getFormValueFromNameSuffix();
1599
- var toName = commands.getFormValueToName();
1600
- var toSuffix = commands.getFormValueToNameSuffix();
1601
- if (name === fromName) {
1602
- resetValue = searchRef.current.getFormReset(itemName, fromSuffix);
1603
- }
1604
- else if (name === toName) {
1605
- resetValue = searchRef.current.getFormReset(itemName, toSuffix);
1606
- }
1607
- }
1608
- break;
1609
- case 'FormMonthPicker':
1610
- {
1611
- var commands = itemCommands;
1612
- var itemName = commands.getName();
1613
- var yearName = commands.getFormValueYearName();
1614
- var yearSuffix = commands.getFormValueYearNameSuffix();
1615
- var monthName = commands.getFormValueMonthName();
1616
- var monthSuffix = commands.getFormValueMonthNameSuffix();
1617
- if (name === yearName) {
1618
- resetValue = searchRef.current.getFormReset(itemName, yearSuffix);
1619
- }
1620
- else if (name === monthName) {
1621
- resetValue = searchRef.current.getFormReset(itemName, monthSuffix);
1622
- }
1623
- }
1624
- break;
1625
- case 'FormMonthRangePicker':
1626
- {
1627
- var commands = itemCommands;
1628
- var itemName = commands.getName();
1629
- var fromYearName = commands.getFormValueFromYearName();
1630
- var fromYearSuffix = commands.getFormValueFromYearNameSuffix();
1631
- var fromMonthName = commands.getFormValueFromMonthName();
1632
- var fromMonthSuffix = commands.getFormValueFromMonthNameSuffix();
1633
- var toYearName = commands.getFormValueToYearName();
1634
- var toYearSuffix = commands.getFormValueToYearNameSuffix();
1635
- var toMonthName = commands.getFormValueToMonthName();
1636
- var toMonthSuffix = commands.getFormValueToMonthNameSuffix();
1637
- if (name === fromYearName) {
1638
- resetValue = searchRef.current.getFormReset(itemName, fromYearSuffix);
1639
- }
1640
- else if (name === fromMonthName) {
1641
- resetValue = searchRef.current.getFormReset(itemName, fromMonthSuffix);
1642
- }
1643
- else if (name === toYearName) {
1644
- resetValue = searchRef.current.getFormReset(itemName, toYearSuffix);
1645
- }
1646
- else if (name === toMonthName) {
1647
- resetValue = searchRef.current.getFormReset(itemName, toMonthSuffix);
1648
- }
1649
- }
1650
- break;
1651
- default:
1652
- resetValue = searchRef.current.getFormReset(name);
1653
- break;
1654
- }
1655
- if (resetValue != null && !util.equal(resetValue, value) && typeof value !== 'object') {
1656
- hashes_1.push("".concat(name, "=").concat(encodeURIComponent(value)));
1657
- }
1658
- }
1659
- }
1660
- }
1661
- });
1662
- var finalHash = hashes_1.join('&');
1663
- if (window.location.hash.substring(1) === finalHash) {
1664
- getData(params);
1665
- }
1666
- else {
1667
- onRequestHashChange(hashes_1.join('&'));
1668
- }
1669
- }
1670
- }, [onRequestHashChange, getData]);
1671
- /********************************************************************************************************************
1672
- * Event Handler
1673
- * ******************************************************************************************************************/
1674
- var handlePageChange = React.useCallback(function (page) {
1675
- var _a, _b;
1676
- (_a = searchRef.current) === null || _a === void 0 ? void 0 : _a.setValue('page', page);
1677
- var finalData;
1678
- if (lastGetDataDataRef.current) {
1679
- finalData = __assign({}, lastGetDataDataRef.current);
1680
- finalData.page = page;
1681
- }
1682
- else {
1683
- finalData = (_b = searchRef.current) === null || _b === void 0 ? void 0 : _b.getAllFormValue();
1684
- }
1685
- if (hash) {
1686
- hashChange(finalData || {});
1687
- }
1688
- else {
1689
- getData(finalData || {});
1690
- }
1691
- }, [searchRef, hash, hashChange, getData]);
1692
- var handleSearchSubmit = React.useCallback(function (data) {
1693
- var _a, _b;
1694
- (_a = tableRef.current) === null || _a === void 0 ? void 0 : _a.scrollToTop();
1695
- if (isFirstSearchSubmit) {
1696
- setIsFirstSearchSubmit(false);
1697
- if (!hash) {
1698
- getData(data);
1699
- }
1700
- }
1701
- else {
1702
- (_b = searchRef.current) === null || _b === void 0 ? void 0 : _b.setValue('page', 1);
1703
- var finalData = __assign(__assign({}, data), { page: 1 });
1704
- if (hash) {
1705
- hashChange(finalData);
1706
- }
1707
- else {
1708
- getData(finalData);
1709
- }
1710
- }
1711
- }, [searchRef, hash, hashChange, getData, isFirstSearchSubmit]);
1712
- /********************************************************************************************************************
1713
- * Memo
1714
- * ******************************************************************************************************************/
1715
- var styles = React.useMemo(function () {
1716
- return fullHeight
1717
- ? {
1718
- containerStyle: __assign(__assign({}, initStyle), { flex: 1, display: 'flex' }),
1719
- tableContainerStyle: { flex: 1, display: 'flex', flexDirection: 'column' },
1720
- }
1721
- : { containerStyle: initStyle };
1722
- }, [initStyle, fullHeight]);
1723
- /********************************************************************************************************************
1724
- * Render
1725
- * ******************************************************************************************************************/
1726
- return (React.createElement(material.Grid, { container: true, direction: 'column', spacing: 1, className: classNames('SearchTable', className), style: styles.containerStyle, sx: sx },
1727
- React.createElement(material.Grid, { item: true, sx: { display: searchInfo.searchGroups ? undefined : 'none' } },
1728
- React.createElement(reactForm.Search, __assign({ color: color }, searchInfo.props, { ref: function (commands) {
1729
- if (searchInfo.ref) {
1730
- if (typeof searchInfo.ref === 'function') {
1731
- searchInfo.ref(commands);
1732
- }
1733
- else {
1734
- searchInfo.ref.current = commands;
1735
- }
1736
- }
1737
- searchRef.current = commands || undefined;
1738
- }, autoSubmit: true, onSubmit: handleSearchSubmit }),
1739
- React.createElement(reactForm.SearchGroup, { hidden: true },
1740
- React.createElement(reactForm.FormHidden, { name: 'page', value: 1 })),
1741
- searchInfo.searchGroups)),
1742
- betweenSearchTableComponent && React.createElement(material.Grid, { item: true }, betweenSearchTableComponent),
1743
- React.createElement(material.Grid, { item: true, style: styles.tableContainerStyle },
1744
- React.createElement(Table, __assign({}, tableInfo.props, { stickyHeader: stickyHeader || ((_b = tableInfo.props) === null || _b === void 0 ? void 0 : _b.stickyHeader), fullHeight: fullHeight || ((_c = tableInfo.props) === null || _c === void 0 ? void 0 : _c.fullHeight), ref: function (commands) {
1745
- if (tableInfo.ref) {
1746
- if (typeof tableInfo.ref === 'function') {
1747
- tableInfo.ref(commands);
1748
- }
1749
- else {
1750
- tableInfo.ref.current = commands;
1751
- }
1752
- }
1753
- tableRef.current = commands || undefined;
1754
- }, items: tableData === null || tableData === void 0 ? void 0 : tableData.items, paging: tableData === null || tableData === void 0 ? void 0 : tableData.paging, onPageChange: handlePageChange })))));
1755
- });
1756
- SearchTable.displayName = 'SearchTable';
1757
- SearchTable.defaultProps = SearchTableDefaultProps;var TableButtonDefaultProps = {
1758
- variant: 'outlined',
1759
- color: 'primary',
1760
- };var TableButton = React.forwardRef(function (_a, ref) {
1761
- /********************************************************************************************************************
1762
- * Memo
1763
- * ******************************************************************************************************************/
1764
- var children = _a.children, className = _a.className, initSx = _a.sx, color = _a.color, onClick = _a.onClick, props = __rest(_a, ["children", "className", "sx", "color", "onClick"]);
1765
- var sx = React.useMemo(function () { return (__assign({ minWidth: 0, px: '5px !important' }, initSx)); }, [initSx]);
1766
- /********************************************************************************************************************
1767
- * Render
1768
- * ******************************************************************************************************************/
1769
- return (React.createElement(reactComponent.PdgButton, __assign({ ref: ref, className: classNames(className, 'TableButton'), type: 'button', size: 'small', sx: sx, color: color, onClick: onClick }, props), children));
1770
- });
1771
- TableButton.displayName = 'TableButton';
1772
- TableButton.defaultProps = TableButtonDefaultProps;var TableMenuButtonDefaultProps = {
1773
- variant: 'text',
1774
- color: 'primary',
1775
- placement: 'bottom',
1776
- };var TableMenuButton = React.forwardRef(function (_a, ref) {
1777
- /********************************************************************************************************************
1778
- * ID
1779
- * ******************************************************************************************************************/
1780
- var children = _a.children, className = _a.className, initSx = _a.sx, color = _a.color, variant = _a.variant, startIcon = _a.startIcon, placement = _a.placement, inModal = _a.inModal, zIndex = _a.zIndex, menuList = _a.menuList, props = __rest(_a, ["children", "className", "sx", "color", "variant", "startIcon", "placement", "inModal", "zIndex", "menuList"]);
1781
- var buttonId = React.useId();
1782
- var menuId = React.useId();
1783
- /********************************************************************************************************************
1784
- * Use
1785
- * ******************************************************************************************************************/
1786
- var _b = useTableState(), menuOpen = _b.menuOpen, openMenuId = _b.openMenuId, setMenuOpen = _b.setMenuOpen;
1787
- /********************************************************************************************************************
1788
- * Ref
1789
- * ******************************************************************************************************************/
1790
- var anchorRef = React.useRef();
1791
- /********************************************************************************************************************
1792
- * State
1793
- * ******************************************************************************************************************/
1794
- var _c = React.useState(false), open = _c[0], setOpen = _c[1];
1795
- /********************************************************************************************************************
1796
- * Memo
1797
- * ******************************************************************************************************************/
1798
- var icon = React.useMemo(function () { return (!startIcon && !children ? 'MoreVert' : undefined); }, [startIcon, children]);
1799
- var sx = React.useMemo(function () { return (__assign({ minWidth: 0, pl: !children ? 0.7 : icon || startIcon ? 0.7 : variant === 'text' ? 1.2 : 0.7 }, initSx)); }, [children, icon, initSx, startIcon, variant]);
1800
- /********************************************************************************************************************
1801
- * Effect
1802
- * ******************************************************************************************************************/
1803
- React.useEffect(function () {
1804
- if (open && menuOpen && openMenuId !== menuId) {
1805
- setOpen(false);
1806
- }
1807
- }, [menuId, menuOpen, open, openMenuId]);
1808
- /********************************************************************************************************************
1809
- * Event Handler
1810
- * ******************************************************************************************************************/
1811
- var handleClick = React.useCallback(function () {
1812
- setOpen(function (old) { return !old; });
1813
- if (!open) {
1814
- setMenuOpen(true, menuId);
1815
- }
1816
- else {
1817
- setMenuOpen(false, menuId);
1818
- }
1819
- }, [menuId, open, setMenuOpen]);
1820
- var handleClose = React.useCallback(function () {
1821
- if (open) {
1822
- setOpen(false);
1823
- setMenuOpen(false, menuId);
1824
- }
1825
- }, [menuId, open, setMenuOpen]);
1826
- var handleListKeyDown = React.useCallback(function (event) {
1827
- if (event.key === 'Tab') {
1828
- event.preventDefault();
1829
- if (open) {
1830
- setOpen(false);
1831
- setMenuOpen(false, menuId);
1832
- }
1833
- }
1834
- else if (event.key === 'Escape') {
1835
- if (open) {
1836
- setOpen(false);
1837
- setMenuOpen(false, menuId);
1838
- }
1839
- }
1840
- }, [menuId, open, setMenuOpen]);
1841
- /********************************************************************************************************************
1842
- * Memo
1843
- * ******************************************************************************************************************/
1844
- var finalMenuList = React.useMemo(function () {
1845
- return React.cloneElement(menuList, {
1846
- autoFocusItem: open,
1847
- id: menuId,
1848
- 'aria-labelledby': buttonId,
1849
- onKeyDown: handleListKeyDown,
1850
- onClick: handleClose,
1851
- });
1852
- }, [buttonId, handleClose, handleListKeyDown, menuId, menuList, open]);
1853
- /********************************************************************************************************************
1854
- * Render
1855
- * ******************************************************************************************************************/
1856
- return (React.createElement("span", null,
1857
- React.createElement(reactComponent.PdgButton, __assign({ ref: function (r) {
1858
- if (ref) {
1859
- if (typeof ref === 'function') {
1860
- ref(r);
1861
- }
1862
- else {
1863
- ref.current = r;
1864
- }
1865
- }
1866
- anchorRef.current = r;
1867
- }, id: buttonId, variant: variant, "aria-controls": open ? menuId : undefined, "aria-expanded": open ? 'true' : undefined, "aria-haspopup": 'true', className: classNames(className, 'TableMenuButton'), type: 'button', size: 'small', sx: sx, color: color, startIcon: icon, onClick: handleClick }, props), children),
1868
- React.createElement(material.Popper, { className: 'TableMenuButton-Popper', open: open, anchorEl: anchorRef.current, role: undefined, placement: placement, transition: true, style: { zIndex: inModal ? (zIndex === undefined ? 1301 : zIndex) : zIndex } }, function (_a) {
1869
- var TransitionProps = _a.TransitionProps, placement = _a.placement;
1870
- var placements = placement.split('-');
1871
- var transformOrigin = '';
1872
- if (placements[0] === 'left') {
1873
- transformOrigin = 'right';
1874
- // if (placements.length > 1) {
1875
- // if (placements[1] === 'start') {
1876
- // transformOrigin += ' top';
1877
- // } else if (placements[1] === 'end') {
1878
- // transformOrigin += ' bottom';
1879
- // }
1880
- // }
1881
- }
1882
- else if (placements[0] === 'right') {
1883
- transformOrigin = 'left';
1884
- // if (placements.length > 1) {
1885
- // if (placements[1] === 'start') {
1886
- // transformOrigin += ' top';
1887
- // } else if (placements[1] === 'end') {
1888
- // transformOrigin += ' bottom';
1889
- // }
1890
- // }
1891
- }
1892
- else if (placements[0] === 'top') {
1893
- transformOrigin = 'bottom';
1894
- // if (placements.length > 1) {
1895
- // if (placements[1] === 'start') {
1896
- // transformOrigin += ' left';
1897
- // } else if (placements[1] === 'end') {
1898
- // transformOrigin += ' right';
1899
- // }
1900
- // }
1901
- }
1902
- else if (placements[0] === 'bottom') {
1903
- transformOrigin = 'top';
1904
- // if (placements.length > 1) {
1905
- // if (placements[1] === 'start') {
1906
- // transformOrigin += ' left';
1907
- // } else if (placements[1] === 'end') {
1908
- // transformOrigin += ' right';
1909
- // }
1910
- // }
1911
- }
1912
- else {
1913
- transformOrigin = 'top';
1914
- }
1915
- return (React.createElement(material.Grow, __assign({}, TransitionProps, { style: {
1916
- transformOrigin: transformOrigin,
1917
- } }),
1918
- React.createElement(material.Paper, null,
1919
- React.createElement(material.ClickAwayListener, { onClickAway: handleClose }, finalMenuList))));
1920
- })));
1921
- });
1922
- TableMenuButton.displayName = 'TableMenuButton';
1923
- TableMenuButton.defaultProps = TableMenuButtonDefaultProps;var InfoTableDefaultProps = {
1924
- spacing: 2,
1925
- rowSpacing: 3,
1926
- labelColor: 'primary',
1927
- dividerColor: 'gray',
1928
- };var Label = material.styled(material.Box)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n font-size: 12px;\n font-weight: bold;\n"], ["\n font-size: 12px;\n font-weight: bold;\n"])));
1929
- var ValueWrap = material.styled(material.Box)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n margin-top: 3px;\n position: relative;\n display: flex;\n flex-direction: row;\n"], ["\n margin-top: 3px;\n position: relative;\n display: flex;\n flex-direction: row;\n"])));
1930
- var Value = material.styled('div')(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n flex: 1;\n"], ["\n flex: 1;\n"])));
1931
- var ValueEllipsis = material.styled('div')(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n flex: 1;\n position: relative;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n"], ["\n flex: 1;\n position: relative;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n"])));
1932
- var ValueClipboard = material.styled('div')(templateObject_5 || (templateObject_5 = __makeTemplateObject([""], [""])));
1933
- var ClipboardIconButton = material.styled(material.IconButton)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n margin-top: -10px;\n margin-bottom: -10px;\n"], ["\n margin-top: -10px;\n margin-bottom: -10px;\n"])));
1934
- var Line = material.styled('div')(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n border-top: 1px solid #efefef;\n height: 1px;\n flex: 1;\n"], ["\n border-top: 1px solid #efefef;\n height: 1px;\n flex: 1;\n"])));
1935
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;var InfoTable = function (_a) {
1936
- /********************************************************************************************************************
1937
- * Memo
1938
- * ******************************************************************************************************************/
1939
- var cols = _a.cols, spacing = _a.spacing, columnSpacing = _a.columnSpacing, rowSpacing = _a.rowSpacing, className = _a.className, style = _a.style, sx = _a.sx, labelClassName = _a.labelClassName, labelColor = _a.labelColor, labelStyle = _a.labelStyle, labelSx = _a.labelSx, dividerColor = _a.dividerColor, valueClassName = _a.valueClassName, valueStyle = _a.valueStyle, valueSx = _a.valueSx, ellipsis = _a.ellipsis, valueUnderline = _a.valueUnderline, info = _a.info, items = _a.items, onCopyToClipboard = _a.onCopyToClipboard;
1940
- var renderItems = React.useMemo(function () {
1941
- return items.filter(function (item) { return !!item && (!item.onHide || !item.onHide(info)); }).map(function (item) {
1942
- /** data */
1943
- var data = undefined;
1944
- if (item.name !== undefined) {
1945
- if (info[item.name] !== undefined) {
1946
- if (info[item.name] instanceof Date) {
1947
- data = dayjs(info[item.name]).format('YYYY-MM-DD HH:mm:ss');
1948
- }
1949
- else if (info[item.name] instanceof dayjs) {
1950
- data = info[item.name].format('YYYY-MM-DD HH:mm:ss');
1951
- }
1952
- else {
1953
- data = info[item.name];
1954
- }
1955
- }
1956
- }
1957
- if (item.onRender) {
1958
- data = item.onRender(info);
1959
- }
1960
- else if (util.notEmpty(data)) {
1961
- switch (item.type) {
1962
- case 'number':
1963
- if (typeof data === 'string' || typeof data === 'number') {
1964
- data = util.numberFormat(data);
1965
- if (item.numberPrefix) {
1966
- data = (React.createElement(React.Fragment, null,
1967
- React.createElement("span", { style: { opacity: 0.5, marginRight: 2 } }, item.numberPrefix),
1968
- data));
1969
- }
1970
- if (item.numberSuffix) {
1971
- data = (React.createElement(React.Fragment, null,
1972
- data,
1973
- React.createElement("span", { style: { opacity: 0.5, marginLeft: 2 } }, item.numberSuffix)));
1974
- }
1975
- }
1976
- break;
1977
- case 'tel':
1978
- if (typeof data === 'string') {
1979
- data = util.telNoAutoDash(data);
1980
- }
1981
- break;
1982
- case 'email':
1983
- if (typeof data === 'string') {
1984
- data = (React.createElement(React.Fragment, null,
1985
- React.createElement("a", { href: "mailto:".concat(data) }, data)));
1986
- }
1987
- break;
1988
- case 'url':
1989
- if (typeof data === 'string' && data.toLowerCase().startsWith('http')) {
1990
- data = (React.createElement(React.Fragment, null,
1991
- React.createElement("a", { href: data, target: '_blank' }, data)));
1992
- }
1993
- break;
1994
- case 'company_no':
1995
- if (typeof data === 'string') {
1996
- data = util.companyNoAutoDash(data);
1997
- }
1998
- break;
1999
- case 'personal_no':
2000
- if (typeof data === 'string') {
2001
- data = util.personalNoAutoDash(data);
2002
- }
2003
- break;
2004
- case 'date':
2005
- if (typeof data === 'string' || typeof data === 'number') {
2006
- data = dayjs(data, item.dateFormat).format('YYYY-MM-DD');
2007
- }
2008
- break;
2009
- case 'datetime':
2010
- if (typeof data === 'string' || typeof data === 'number') {
2011
- var dt = dayjs(data, item.dateFormat);
2012
- data = (React.createElement(React.Fragment, null,
2013
- React.createElement("span", null, dt.format('YYYY-MM-DD')),
2014
- item.dateTwoLine ? React.createElement("br", null) : ' ',
2015
- React.createElement("span", { style: { opacity: 0.5 } }, dt.format('HH:mm:ss'))));
2016
- }
2017
- break;
2018
- case 'date-hour':
2019
- if (typeof data === 'string' || typeof data === 'number') {
2020
- var dt = dayjs(data, item.dateFormat);
2021
- data = (React.createElement(React.Fragment, null,
2022
- React.createElement("span", null, dt.format('YYYY-MM-DD')),
2023
- item.dateTwoLine ? React.createElement("br", null) : ' ',
2024
- React.createElement("span", { style: { opacity: 0.5 } }, dt.format('HH시'))));
2025
- }
2026
- break;
2027
- case 'date-minute':
2028
- if (typeof data === 'string' || typeof data === 'number') {
2029
- var dt = dayjs(data, item.dateFormat);
2030
- data = (React.createElement(React.Fragment, null,
2031
- React.createElement("span", null, dt.format('YYYY-MM-DD')),
2032
- item.dateTwoLine ? React.createElement("br", null) : ' ',
2033
- React.createElement("span", { style: { opacity: 0.5 } }, dt.format('HH시 MM분'))));
2034
- }
2035
- break;
2036
- }
2037
- }
2038
- if (util.empty(data))
2039
- data = item.onRenderEmpty ? item.onRenderEmpty(info) : React.createElement(React.Fragment, null, "\u00A0");
2040
- /** copyToClipboardText */
2041
- var copyToClipboardText = item.clipboardText || (typeof data === 'string' ? data : typeof data === 'number' ? data.toString() : '');
2042
- /** sizeProps */
2043
- var sizeProps = {};
2044
- if (typeof cols === 'number') {
2045
- sizeProps.xs = 12 / cols;
2046
- }
2047
- else {
2048
- if (cols.xs)
2049
- sizeProps.xs = 12 / cols.xs;
2050
- if (cols.sm)
2051
- sizeProps.sm = 12 / cols.sm;
2052
- if (cols.md)
2053
- sizeProps.md = 12 / cols.md;
2054
- if (cols.lg)
2055
- sizeProps.lg = 12 / cols.lg;
2056
- if (cols.xl)
2057
- sizeProps.xl = 12 / cols.xl;
2058
- }
2059
- if (item.xs)
2060
- sizeProps.xs = item.xs;
2061
- if (item.sm)
2062
- sizeProps.sm = item.sm;
2063
- if (item.md)
2064
- sizeProps.md = item.md;
2065
- if (item.lg)
2066
- sizeProps.lg = item.lg;
2067
- if (item.xl)
2068
- sizeProps.xl = item.xl;
2069
- if (item.onXs)
2070
- sizeProps.xs = item.onXs(info);
2071
- if (item.onSm)
2072
- sizeProps.sm = item.onSm(info);
2073
- if (item.onMd)
2074
- sizeProps.md = item.onMd(info);
2075
- if (item.onLg)
2076
- sizeProps.lg = item.onLg(info);
2077
- if (item.onXl)
2078
- sizeProps.xl = item.onXl(info);
2079
- return { item: item, data: data, copyToClipboardText: copyToClipboardText, sizeProps: sizeProps };
2080
- });
2081
- }, [info, items, cols]);
2082
- var content = React.useMemo(function () {
2083
- return renderItems.map(function (_a, idx) {
2084
- var item = _a.item, data = _a.data, copyToClipboardText = _a.copyToClipboardText, sizeProps = _a.sizeProps;
2085
- var finalLabelColor = typographyColorToSxColor(item.type === 'divider' ? item.dividerColor || dividerColor : item.labelColor || labelColor);
2086
- var finalLabelSx = combineSx(labelSx, item.labelSx, !!finalLabelColor && { color: finalLabelColor });
2087
- var finalValueSx = combineSx(valueSx, item.valueSx);
2088
- var valueUnderlineStyle = valueUnderline
2089
- ? { borderBottom: '1px solid #efefef', paddingBottom: 5 }
2090
- : undefined;
2091
- return item.type === 'divider' ? (React.createElement(material.Grid, { key: idx, item: true, xs: 12 },
2092
- React.createElement(material.Stack, { direction: 'row', spacing: 0.5, alignItems: 'center' },
2093
- item.icon && (React.createElement(reactComponent.PdgIcon, { sx: { color: item.dividerColor || dividerColor }, size: 'small' }, item.icon)),
2094
- item.label && (React.createElement(Label, { className: classNames(labelClassName, item.labelClassName), style: __assign(__assign({}, item.labelStyle), labelStyle), sx: finalLabelSx }, item.label)),
2095
- item.dividerLine && (React.createElement(React.Fragment, null, item.icon || item.label ? (React.createElement("div", { style: { flex: 1, paddingLeft: 5 } },
2096
- React.createElement(Line, null))) : (React.createElement(Line, null))))))) : (React.createElement(material.Grid, __assign({ key: idx, item: true }, sizeProps, { className: item.className, style: item.style, sx: item.sx }),
2097
- React.createElement(material.Stack, { direction: 'row', spacing: 0.5, alignItems: 'center' },
2098
- item.icon && (React.createElement(reactComponent.PdgIcon, { sx: { color: finalLabelColor }, size: 'small' }, "CalendarMonth")),
2099
- React.createElement(Label, { className: classNames(labelClassName, item.labelClassName), style: __assign(__assign({}, item.labelStyle), labelStyle), sx: finalLabelSx }, item.label)),
2100
- React.createElement(ValueWrap, { className: classNames(valueClassName, item.valueClassName), style: __assign(__assign(__assign({}, valueStyle), item.valueStyle), valueUnderlineStyle), sx: finalValueSx },
2101
- item.ellipsis || ellipsis ? React.createElement(ValueEllipsis, null, data) : React.createElement(Value, null, data),
2102
- item.clipboard && util.notEmpty(copyToClipboardText) && (React.createElement(ValueClipboard, null,
2103
- React.createElement(reactCopyToClipboard.CopyToClipboard, { text: copyToClipboardText, onCopy: onCopyToClipboard ? function () { return onCopyToClipboard(item, copyToClipboardText); } : undefined },
2104
- React.createElement(ClipboardIconButton, __assign({ size: 'small', color: 'primary' }, item.clipboardProps),
2105
- React.createElement(reactComponent.PdgIcon, null, item.clipboardIcon || 'ContentPaste'))))))));
2106
- });
2107
- }, [
2108
- dividerColor,
2109
- ellipsis,
2110
- labelClassName,
2111
- labelColor,
2112
- labelStyle,
2113
- labelSx,
2114
- onCopyToClipboard,
2115
- renderItems,
2116
- valueClassName,
2117
- valueStyle,
2118
- valueSx,
2119
- valueUnderline,
2120
- ]);
2121
- /********************************************************************************************************************
2122
- * Render
2123
- * ******************************************************************************************************************/
2124
- return (React.createElement(material.Grid, { container: true, spacing: spacing, columnSpacing: columnSpacing, rowSpacing: rowSpacing, className: classNames('InfoTable', className), style: style, sx: sx }, content));
2125
- };
2126
- InfoTable.displayName = 'InfoTable';
2127
- InfoTable.defaultProps = InfoTableDefaultProps;exports.InfoTable=InfoTable;exports.InfoTableDefaultProps=InfoTableDefaultProps;exports.SearchTable=SearchTable;exports.SearchTableDefaultProps=SearchTableDefaultProps;exports.Table=Table;exports.TableButton=TableButton;exports.TableButtonDefaultProps=TableButtonDefaultProps;exports.TableDefaultProps=TableDefaultProps;exports.TableMenuButton=TableMenuButton;exports.TableMenuButtonDefaultProps=TableMenuButtonDefaultProps;
136
+ });function getTableColumnAlign(column, defaultAlign) {
137
+ switch (column.type) {
138
+ case 'number':
139
+ return column.align ? column.align : 'right';
140
+ default:
141
+ return column.align || defaultAlign;
142
+ }
143
+ }
144
+ function combineSx() {
145
+ var sx = [];
146
+ for (var _i = 0; _i < arguments.length; _i++) {
147
+ sx[_i] = arguments[_i];
148
+ }
149
+ var finalSx = [];
150
+ if (Array.isArray(finalSx)) {
151
+ sx.forEach(function (v) { return v && finalSx.push.apply(finalSx, (Array.isArray(v) ? v : [v])); });
152
+ }
153
+ return finalSx;
154
+ }
155
+ function typographyColorToSxColor(color) {
156
+ if (typeof color === 'string') {
157
+ if (['primary', 'secondary', 'info', 'warning', 'error'].includes(color)) {
158
+ return "".concat(color, ".main");
159
+ }
160
+ else if (color === 'text') {
161
+ return 'text.primary';
162
+ }
163
+ else {
164
+ return color;
165
+ }
166
+ }
167
+ else {
168
+ return color;
169
+ }
170
+ }var TableContextDefaultValue = {
171
+ menuOpen: false,
172
+ openMenuId: undefined,
173
+ setMenuOpen: function () { },
174
+ setItemColumnChecked: function () { },
175
+ setItemColumnCheckDisabled: function () { },
176
+ setItemColumnCommands: function () { },
177
+ setHeadColumnChecked: function () { },
178
+ setHeadColumnCommands: function () { },
179
+ };var TableContext = React.createContext(TableContextDefaultValue);function useTableState() {
180
+ var value = React.useContext(TableContext);
181
+ if (value === undefined) {
182
+ throw new Error('useFormState should be used within TableContext.Provider');
183
+ }
184
+ return value;
185
+ }var StyledTableCell = material.styled(material.TableCell)(templateObject_1$3 || (templateObject_1$3 = __makeTemplateObject(["\n &.ellipsis {\n position: relative;\n max-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n"], ["\n &.ellipsis {\n position: relative;\n max-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n"])));
186
+ var TableCommonCell = function (_a) {
187
+ /********************************************************************************************************************
188
+ * Use
189
+ * ******************************************************************************************************************/
190
+ var children = _a.children, initClassName = _a.className, initStyle = _a.style, initSx = _a.sx, type = _a.type, column = _a.column, defaultAlign = _a.defaultAlign, initDefaultEllipsis = _a.defaultEllipsis, index = _a.index, item = _a.item, onClick = _a.onClick;
191
+ var menuOpen = useTableState().menuOpen;
192
+ /********************************************************************************************************************
193
+ * Memo
194
+ * ******************************************************************************************************************/
195
+ var align = React.useMemo(function () { return getTableColumnAlign(column, defaultAlign); }, [column, defaultAlign]);
196
+ var ellipsis = React.useMemo(function () {
197
+ return type !== 'head' &&
198
+ (column.ellipsis ||
199
+ (column.type !== 'img' &&
200
+ column.type !== 'button' &&
201
+ column.type !== 'buttons' &&
202
+ (column.ellipsis == null ? !!initDefaultEllipsis : false)));
203
+ }, [type, column, initDefaultEllipsis]);
204
+ var className = React.useMemo(function () {
205
+ var _a, _b, _c, _d, _e, _f;
206
+ var className;
207
+ var getClassName;
208
+ switch (type) {
209
+ case 'head':
210
+ className = (_a = column.head) === null || _a === void 0 ? void 0 : _a.className;
211
+ getClassName = ((_b = column.head) === null || _b === void 0 ? void 0 : _b.onGetClassName) ? (_c = column.head) === null || _c === void 0 ? void 0 : _c.onGetClassName() : undefined;
212
+ break;
213
+ case 'body':
214
+ className = column.className;
215
+ if (item != null && index != null) {
216
+ getClassName = column.onGetClassName ? column.onGetClassName(item, index) : undefined;
217
+ }
218
+ break;
219
+ case 'footer':
220
+ className = (_d = column.footer) === null || _d === void 0 ? void 0 : _d.className;
221
+ getClassName = ((_e = column.footer) === null || _e === void 0 ? void 0 : _e.onGetClassName) ? (_f = column.footer) === null || _f === void 0 ? void 0 : _f.onGetClassName() : undefined;
222
+ break;
223
+ }
224
+ if (className || getClassName) {
225
+ return classNames(initClassName, className, getClassName);
226
+ }
227
+ else {
228
+ return initClassName;
229
+ }
230
+ }, [column, index, initClassName, item, type]);
231
+ var style = React.useMemo(function () {
232
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
233
+ var style;
234
+ var getStyle;
235
+ switch (type) {
236
+ case 'head':
237
+ style = ((_a = column.head) === null || _a === void 0 ? void 0 : _a.backgroundColor)
238
+ ? __assign(__assign({}, (_b = column.head) === null || _b === void 0 ? void 0 : _b.style), { backgroundColor: column.head.backgroundColor }) : (_c = column.head) === null || _c === void 0 ? void 0 : _c.style;
239
+ getStyle = ((_d = column.head) === null || _d === void 0 ? void 0 : _d.onGetStyle) ? (_e = column.head) === null || _e === void 0 ? void 0 : _e.onGetStyle() : undefined;
240
+ break;
241
+ case 'body':
242
+ style = column.backgroundColor ? __assign(__assign({}, column.style), { backgroundColor: column.backgroundColor }) : column.style;
243
+ if (item != null && index != null) {
244
+ getStyle = column.onGetStyle ? column.onGetStyle(item, index) : undefined;
245
+ }
246
+ break;
247
+ case 'footer':
248
+ style = ((_f = column.footer) === null || _f === void 0 ? void 0 : _f.backgroundColor)
249
+ ? __assign(__assign({}, (_g = column.footer) === null || _g === void 0 ? void 0 : _g.style), { backgroundColor: column.footer.backgroundColor }) : (_h = column.footer) === null || _h === void 0 ? void 0 : _h.style;
250
+ getStyle = ((_j = column.footer) === null || _j === void 0 ? void 0 : _j.onGetStyle) ? (_k = column.footer) === null || _k === void 0 ? void 0 : _k.onGetStyle() : undefined;
251
+ break;
252
+ }
253
+ return __assign(__assign(__assign(__assign({}, initStyle), { width: column.width, minWidth: column.minWidth, cursor: type === 'body' && (column.onClick || onClick) ? 'pointer' : undefined, paddingLeft: column.paddingLeft, paddingRight: column.paddingRight }), style), getStyle);
254
+ }, [column, index, initStyle, item, onClick, type]);
255
+ var sx = React.useMemo(function () {
256
+ var _a, _b, _c, _d, _e, _f;
257
+ var sx;
258
+ var getSx;
259
+ var displaySx;
260
+ switch (type) {
261
+ case 'head':
262
+ sx = (_a = column.head) === null || _a === void 0 ? void 0 : _a.sx;
263
+ getSx = ((_b = column.head) === null || _b === void 0 ? void 0 : _b.onGetSx) ? (_c = column.head) === null || _c === void 0 ? void 0 : _c.onGetSx() : undefined;
264
+ break;
265
+ case 'body':
266
+ sx = column.sx;
267
+ if (item != null && index != null) {
268
+ getSx = column.onGetSx ? column.onGetSx(item, index) : undefined;
269
+ }
270
+ break;
271
+ case 'footer':
272
+ sx = (_d = column.footer) === null || _d === void 0 ? void 0 : _d.sx;
273
+ getSx = ((_e = column.footer) === null || _e === void 0 ? void 0 : _e.onGetSx) ? (_f = column.footer) === null || _f === void 0 ? void 0 : _f.onGetSx() : undefined;
274
+ break;
275
+ }
276
+ if (column.display) {
277
+ var display = {};
278
+ if (column.display.xs !== undefined)
279
+ display.xs = column.display.xs ? 'table-cell' : 'none';
280
+ if (column.display.sm !== undefined)
281
+ display.sm = column.display.sm ? 'table-cell' : 'none';
282
+ if (column.display.md !== undefined)
283
+ display.md = column.display.md ? 'table-cell' : 'none';
284
+ if (column.display.lg !== undefined)
285
+ display.lg = column.display.lg ? 'table-cell' : 'none';
286
+ if (column.display.xl !== undefined)
287
+ display.xl = column.display.xl ? 'table-cell' : 'none';
288
+ displaySx = { display: display };
289
+ }
290
+ var sxList = [];
291
+ if (getSx)
292
+ sxList.push(getSx);
293
+ if (sx)
294
+ sxList.push(sx);
295
+ if (initSx)
296
+ sxList.push(initSx);
297
+ if (displaySx)
298
+ sxList.push(displaySx);
299
+ if (sxList.length > 0) {
300
+ if (sxList.length === 1) {
301
+ return sxList[0];
302
+ }
303
+ else {
304
+ if (!sxList.find(function (sx) { return typeof sx !== 'object'; })) {
305
+ return sxList.reduce(function (res, sx) {
306
+ res = __assign(__assign({}, res), sx);
307
+ return res;
308
+ }, {});
309
+ }
310
+ }
311
+ }
312
+ }, [column, index, initSx, item, type]);
313
+ /********************************************************************************************************************
314
+ * Event Handler
315
+ * ******************************************************************************************************************/
316
+ var handleClick = React.useCallback(function (e) {
317
+ if (!menuOpen &&
318
+ column.type !== 'check' &&
319
+ column.type !== 'button' &&
320
+ column.type !== 'buttons' &&
321
+ column.type !== 'img') {
322
+ e.stopPropagation();
323
+ if (type === 'body') {
324
+ if (item != null && index != null) {
325
+ if (column.onClick) {
326
+ column.onClick(item, index);
327
+ }
328
+ else {
329
+ if (onClick)
330
+ onClick(item, index);
331
+ }
332
+ }
333
+ }
334
+ }
335
+ }, [menuOpen, type, item, index, column, onClick]);
336
+ /********************************************************************************************************************
337
+ * Render
338
+ * ******************************************************************************************************************/
339
+ return (React.createElement(StyledTableCell, { align: align, className: classNames(className, 'TableCommonCell', ellipsis && 'ellipsis', column.type ? "column-type-".concat(column.type) : false), style: style, sx: sx, onClick: type === 'body' ? handleClick : undefined }, children));
340
+ };
341
+ var templateObject_1$3;var StyledButtonsBox = material.styled(material.Box)(templateObject_1$2 || (templateObject_1$2 = __makeTemplateObject(["\n display: flex;\n flex-wrap: wrap;\n gap: 5px;\n"], ["\n display: flex;\n flex-wrap: wrap;\n gap: 5px;\n"])));
342
+ var TableBodyCell = function (_a) {
343
+ /********************************************************************************************************************
344
+ * Use
345
+ * ******************************************************************************************************************/
346
+ var className = _a.className, style = _a.style, sx = _a.sx, item = _a.item, index = _a.index, column = _a.column, defaultAlign = _a.defaultAlign, defaultEllipsis = _a.defaultEllipsis, onClick = _a.onClick, onCheckChange = _a.onCheckChange;
347
+ var _b = useTableState(), menuOpen = _b.menuOpen, setItemColumnChecked = _b.setItemColumnChecked, setItemColumnCheckDisabled = _b.setItemColumnCheckDisabled, setItemColumnCommands = _b.setItemColumnCommands;
348
+ /********************************************************************************************************************
349
+ * State
350
+ * ******************************************************************************************************************/
351
+ var _c = React.useState(false), checked = _c[0], setChecked = _c[1];
352
+ var _d = React.useState(false), checkDisabled = _d[0], setCheckDisabled = _d[1];
353
+ /********************************************************************************************************************
354
+ * Effect
355
+ * ******************************************************************************************************************/
356
+ React.useEffect(function () {
357
+ if (column.type === 'check') {
358
+ setChecked(column.onInitChecked ? column.onInitChecked(item) : false);
359
+ setCheckDisabled(column.onCheckDisabled ? column.onCheckDisabled(item) : false);
360
+ }
361
+ setItemColumnCommands(item, column, {
362
+ setChecked: function (checked) {
363
+ if (column.type === 'check') {
364
+ setChecked(checked);
365
+ }
366
+ },
367
+ setCheckDisabled: function (disabled) {
368
+ if (column.type === 'check') {
369
+ setCheckDisabled(disabled);
370
+ }
371
+ },
372
+ });
373
+ }, [column, item, setItemColumnCommands]);
374
+ React.useEffect(function () {
375
+ if (column.type === 'check') {
376
+ setItemColumnChecked(item, column, checked);
377
+ }
378
+ // eslint-disable-next-line react-hooks/exhaustive-deps
379
+ }, [checked]);
380
+ React.useEffect(function () {
381
+ if (column.type === 'check') {
382
+ setItemColumnCheckDisabled(item, column, checkDisabled);
383
+ column.onCheckDisabledChange && column.onCheckDisabledChange(item, checkDisabled);
384
+ }
385
+ // eslint-disable-next-line react-hooks/exhaustive-deps
386
+ }, [checkDisabled]);
387
+ /********************************************************************************************************************
388
+ * Memo
389
+ * ******************************************************************************************************************/
390
+ var isHidden = React.useMemo(function () { return (column.onHide ? column.onHide(item, index) : false); }, [column, index, item]);
391
+ var buttonsBoxJustifyContent = React.useMemo(function () {
392
+ switch (getTableColumnAlign(column, defaultAlign)) {
393
+ case 'center':
394
+ return 'center';
395
+ case 'right':
396
+ return 'end';
397
+ default:
398
+ return 'start';
399
+ }
400
+ }, [column, defaultAlign]);
401
+ var data = React.useMemo(function () {
402
+ var _a, _b;
403
+ var data;
404
+ if (column.type !== 'check') {
405
+ if (column.onRender) {
406
+ data = column.onRender(item, index);
407
+ }
408
+ else if (column.name) {
409
+ data = item[column.name];
410
+ }
411
+ else {
412
+ data = undefined;
413
+ }
414
+ }
415
+ switch (column.type) {
416
+ case 'number':
417
+ if (typeof data === 'string' || typeof data === 'number') {
418
+ data = util.numberFormat(data);
419
+ }
420
+ if (column.numberPrefix) {
421
+ data = (React.createElement(React.Fragment, null,
422
+ React.createElement("span", { style: { opacity: 0.5, marginRight: 2 } }, column.numberPrefix),
423
+ data));
424
+ }
425
+ if (column.numberSuffix) {
426
+ data = (React.createElement(React.Fragment, null,
427
+ data,
428
+ React.createElement("span", { style: { opacity: 0.5, marginLeft: 2 } }, column.numberSuffix)));
429
+ }
430
+ break;
431
+ case 'tel':
432
+ if (typeof data === 'string') {
433
+ data = util.telNoAutoDash(data);
434
+ }
435
+ break;
436
+ case 'company_no':
437
+ if (typeof data === 'string') {
438
+ data = util.companyNoAutoDash(data);
439
+ }
440
+ break;
441
+ case 'personal_no':
442
+ if (typeof data === 'string') {
443
+ data = util.personalNoAutoDash(data);
444
+ }
445
+ break;
446
+ case 'check':
447
+ data = (React.createElement(material.Box, { className: 'TableBoxyCell-check-box', onClick: menuOpen ? undefined : function (e) { return e.stopPropagation(); } },
448
+ React.createElement(material.Checkbox, { checked: checked, disabled: checkDisabled, onChange: function (e, newChecked) {
449
+ setChecked(newChecked);
450
+ column.onCheckChange && column.onCheckChange(item, newChecked);
451
+ onCheckChange && onCheckChange(item, column, newChecked);
452
+ } })));
453
+ break;
454
+ case 'button':
455
+ data = (React.createElement(material.Box, { className: 'TableBoxyCell-button-box', onClick: menuOpen ? undefined : function (e) { return e.stopPropagation(); } }, data));
456
+ break;
457
+ case 'buttons':
458
+ data = (React.createElement(StyledButtonsBox, { className: 'TableBodyCell-buttons-box', justifyContent: buttonsBoxJustifyContent, onClick: menuOpen ? undefined : function (e) { return e.stopPropagation(); } }, data));
459
+ break;
460
+ case 'img':
461
+ {
462
+ var img = React.createElement("img", { src: data, style: { maxWidth: '100%', verticalAlign: 'middle' }, alt: '' });
463
+ var placement = ((_a = column.tooltipProps) === null || _a === void 0 ? void 0 : _a.placement) ? (_b = column.tooltipProps) === null || _b === void 0 ? void 0 : _b.placement : 'left';
464
+ data = (React.createElement("a", { href: data, target: '_blank', onClick: menuOpen
465
+ ? undefined
466
+ : function (e) {
467
+ e.stopPropagation();
468
+ } },
469
+ React.createElement(material.Tooltip, __assign({ className: 'TableBodyCell-tooltip', title: React.createElement("div", { style: { paddingTop: 3, paddingBottom: 3 } }, img) }, column.tooltipProps, { placement: placement }), img)));
470
+ }
471
+ break;
472
+ case 'date':
473
+ if (data) {
474
+ data = dayjs(data, column.dateFormat).format('YYYY-MM-DD');
475
+ }
476
+ break;
477
+ case 'datetime':
478
+ if (data) {
479
+ var dt = dayjs(data, column.dateFormat);
480
+ data = (React.createElement(React.Fragment, null,
481
+ React.createElement("span", null, dt.format('YYYY-MM-DD')),
482
+ column.dateTwoLine ? React.createElement("br", null) : ' ',
483
+ React.createElement("span", { style: { opacity: 0.5 } }, dt.format('HH:mm:ss'))));
484
+ }
485
+ break;
486
+ case 'date-hour':
487
+ if (data) {
488
+ var dt = dayjs(data, column.dateFormat);
489
+ data = (React.createElement(React.Fragment, null,
490
+ React.createElement("span", null, dt.format('YYYY-MM-DD')),
491
+ column.dateTwoLine ? React.createElement("br", null) : ' ',
492
+ React.createElement("span", { style: { opacity: 0.5 } }, dt.format('HH시'))));
493
+ }
494
+ break;
495
+ case 'date-minute':
496
+ if (data) {
497
+ var dt = dayjs(data, column.dateFormat);
498
+ data = (React.createElement(React.Fragment, null,
499
+ React.createElement("span", null, dt.format('YYYY-MM-DD')),
500
+ column.dateTwoLine ? React.createElement("br", null) : ' ',
501
+ React.createElement("span", { style: { opacity: 0.5 } }, dt.format('HH시 MM분'))));
502
+ }
503
+ break;
504
+ }
505
+ if (column.type !== 'img') {
506
+ var tooltip = void 0;
507
+ if (column.onGetTooltip) {
508
+ tooltip = column.onGetTooltip(item, index);
509
+ }
510
+ if (tooltip) {
511
+ data = (React.createElement(material.Tooltip, __assign({ className: 'TableBodyCell-tooltip', title: tooltip }, column.tooltipProps), React.isValidElement(data) ? (data.type === React.Fragment ? (React.createElement("span", null, data)) : (data)) : (React.createElement("span", null, data))));
512
+ }
513
+ }
514
+ return data;
515
+ }, [column, item, index, menuOpen, checked, checkDisabled, buttonsBoxJustifyContent, onCheckChange]);
516
+ /********************************************************************************************************************
517
+ * Event Handler
518
+ * ******************************************************************************************************************/
519
+ var handleClick = React.useCallback(function (item, index) {
520
+ if (column.onClick) {
521
+ column.onClick(item, index);
522
+ }
523
+ else {
524
+ if (onClick)
525
+ onClick(item, index);
526
+ }
527
+ }, [column, onClick]);
528
+ /********************************************************************************************************************
529
+ * Render
530
+ * ******************************************************************************************************************/
531
+ return (React.createElement(TableCommonCell, { type: 'body', className: classNames('TableBodyCell', className), style: style, sx: sx, column: column, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, item: item, index: index, onClick: column.onClick || onClick ? handleClick : undefined }, !isHidden && data));
532
+ };
533
+ var templateObject_1$2;var StyledBodyRow = material.styled(material.TableRow)(function (_a) {
534
+ var theme = _a.theme;
535
+ return ({
536
+ '&.odd-color:nth-of-type(odd):not(:hover)': {
537
+ backgroundColor: material.lighten(theme.palette.action.hover, 0.4),
538
+ },
539
+ '&.even-color:nth-of-type(even):not(:hover)': {
540
+ backgroundColor: material.lighten(theme.palette.action.hover, 0.4),
541
+ },
542
+ });
543
+ });
544
+ var TableBodyRow = function (_a) {
545
+ /********************************************************************************************************************
546
+ * Use
547
+ * ******************************************************************************************************************/
548
+ var className = _a.className, style = _a.style, id = _a.id, index = _a.index, defaultAlign = _a.defaultAlign, defaultEllipsis = _a.defaultEllipsis, sortable$1 = _a.sortable, columns = _a.columns, item = _a.item, onClick = _a.onClick, onCheckChange = _a.onCheckChange, onGetColumnClassName = _a.onGetColumnClassName, onGetColumnStyle = _a.onGetColumnStyle, onGetColumnSx = _a.onGetColumnSx, props = __rest(_a, ["className", "style", "id", "index", "defaultAlign", "defaultEllipsis", "sortable", "columns", "item", "onClick", "onCheckChange", "onGetColumnClassName", "onGetColumnStyle", "onGetColumnSx"]);
549
+ var _b = sortable.useSortable({ id: id }), attributes = _b.attributes, listeners = _b.listeners, setNodeRef = _b.setNodeRef, transform = _b.transform, transition = _b.transition;
550
+ /********************************************************************************************************************
551
+ * Memo
552
+ * ******************************************************************************************************************/
553
+ var finalStyle = React.useMemo(function () {
554
+ return sortable$1
555
+ ? __assign(__assign({}, style), { transform: CSS.Transform.toString(transform), transition: transition }) : style;
556
+ }, [sortable$1, style, transform, transition]);
557
+ var sortableProps = React.useMemo(function () {
558
+ return sortable$1
559
+ ? __assign(__assign({ ref: setNodeRef }, attributes), listeners) : {};
560
+ }, [attributes, listeners, setNodeRef, sortable$1]);
561
+ /********************************************************************************************************************
562
+ * Render
563
+ * ******************************************************************************************************************/
564
+ return (React.createElement(StyledBodyRow, __assign({ className: classNames('TableBodyRow', className), style: finalStyle }, props, sortableProps), columns.map(function (column, columnIdx) { return (React.createElement(TableBodyCell, { className: onGetColumnClassName ? onGetColumnClassName(column, item, index) : undefined, sx: onGetColumnSx ? onGetColumnSx(column, item, index) : undefined, style: onGetColumnStyle ? onGetColumnStyle(column, item, index) : undefined, key: columnIdx, index: index, item: item, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, column: column, onClick: onClick, onCheckChange: onCheckChange })); })));
565
+ };var TableFooterCell = function (_a) {
566
+ /********************************************************************************************************************
567
+ * Memo
568
+ * ******************************************************************************************************************/
569
+ var column = _a.column, defaultAlign = _a.defaultAlign;
570
+ var data = React.useMemo(function () {
571
+ var _a, _b, _c;
572
+ if ((_a = column.footer) === null || _a === void 0 ? void 0 : _a.onRender) {
573
+ return (_b = column.footer) === null || _b === void 0 ? void 0 : _b.onRender();
574
+ }
575
+ else {
576
+ return (_c = column.footer) === null || _c === void 0 ? void 0 : _c.value;
577
+ }
578
+ }, [column]);
579
+ /********************************************************************************************************************
580
+ * Render
581
+ * ******************************************************************************************************************/
582
+ return (React.createElement(TableCommonCell, { type: 'head', className: 'TableFooterCell', column: column, defaultAlign: defaultAlign }, data));
583
+ };var TablePagination = function (_a) {
584
+ var className = _a.className, style = _a.style, sx = _a.sx, paging = _a.paging, align = _a.align, onChange = _a.onChange;
585
+ return (React.createElement(material.Stack, { alignItems: align },
586
+ React.createElement(material.Pagination, { count: paging.last_page, page: paging.current_page, color: 'primary', className: classNames('TablePagination', className), style: style, sx: sx, onChange: function (e, page) {
587
+ if (onChange)
588
+ onChange(page);
589
+ } })));
590
+ };var TableContextProvider = function (_a) {
591
+ var children = _a.children, value = _a.value;
592
+ return React.createElement(TableContext.Provider, { value: value }, children);
593
+ };var TableTopHeadCaptionRow = material.styled(material.TableRow)(function (_a) {
594
+ var theme = _a.theme;
595
+ return ({
596
+ '> th': {
597
+ backgroundColor: theme.palette.grey.A100,
598
+ textAlign: 'center',
599
+ fontWeight: 700,
600
+ },
601
+ });
602
+ });var TableHeadCell = function (_a) {
603
+ /********************************************************************************************************************
604
+ * Use
605
+ * ******************************************************************************************************************/
606
+ var column = _a.column, defaultAlign = _a.defaultAlign, top = _a.top, onCheckChange = _a.onCheckChange;
607
+ var _b = useTableState(), setHeadColumnChecked = _b.setHeadColumnChecked, setHeadColumnCommands = _b.setHeadColumnCommands;
608
+ /********************************************************************************************************************
609
+ * State
610
+ * ******************************************************************************************************************/
611
+ var _c = React.useState(false), checked = _c[0], setChecked = _c[1];
612
+ var _d = React.useState(false), checkDisabled = _d[0], setCheckDisabled = _d[1];
613
+ /********************************************************************************************************************
614
+ * Effect
615
+ * ******************************************************************************************************************/
616
+ React.useEffect(function () {
617
+ if (column.type === 'check') {
618
+ setHeadColumnChecked(column, checked);
619
+ }
620
+ }, [column, checked, setHeadColumnChecked]);
621
+ React.useEffect(function () {
622
+ setHeadColumnCommands(column, {
623
+ setChecked: function (checked) {
624
+ if (column.type === 'check') {
625
+ setChecked(checked);
626
+ }
627
+ },
628
+ setCheckDisabled: function (checkDisabled) {
629
+ if (column.type === 'check') {
630
+ setCheckDisabled(checkDisabled);
631
+ }
632
+ },
633
+ });
634
+ }, [setHeadColumnCommands, column]);
635
+ /********************************************************************************************************************
636
+ * Memo
637
+ * ******************************************************************************************************************/
638
+ var style = React.useMemo(function () { return (top !== undefined ? { top: top } : undefined); }, [top]);
639
+ var data = React.useMemo(function () {
640
+ var _a, _b;
641
+ if (column.type === 'check') {
642
+ return column.hideAllCheck ? null : (React.createElement(material.Checkbox, { checked: checked, disabled: checkDisabled, onChange: function (e, newChecked) {
643
+ setChecked(newChecked);
644
+ onCheckChange && onCheckChange(column, newChecked);
645
+ } }));
646
+ }
647
+ else {
648
+ if ((_a = column.head) === null || _a === void 0 ? void 0 : _a.onRender) {
649
+ return (_b = column.head) === null || _b === void 0 ? void 0 : _b.onRender();
650
+ }
651
+ else {
652
+ if (typeof column.label === 'string') {
653
+ return React.createElement("div", { dangerouslySetInnerHTML: { __html: column.label } });
654
+ }
655
+ else {
656
+ return column.label;
657
+ }
658
+ }
659
+ }
660
+ }, [checkDisabled, checked, column, onCheckChange]);
661
+ /********************************************************************************************************************
662
+ * Render
663
+ * ******************************************************************************************************************/
664
+ return (React.createElement(TableCommonCell, { type: 'head', className: 'TableHeadCell', style: style, column: column, defaultAlign: defaultAlign }, data));
665
+ };var BottomLine = material.styled('div')(templateObject_1$1 || (templateObject_1$1 = __makeTemplateObject(["\n height: 1px;\n position: absolute;\n left: 3px;\n right: 3px;\n bottom: 0;\n"], ["\n height: 1px;\n position: absolute;\n left: 3px;\n right: 3px;\n bottom: 0;\n"])));
666
+ var TableTopHead = function (_a) {
667
+ /********************************************************************************************************************
668
+ * Use
669
+ * ******************************************************************************************************************/
670
+ var columns = _a.columns, rows = _a.rows, caption = _a.caption, defaultAlign = _a.defaultAlign, onCheckChange = _a.onCheckChange;
671
+ var theme = material.useTheme();
672
+ /********************************************************************************************************************
673
+ * Ref
674
+ * ******************************************************************************************************************/
675
+ var captionRef = React.useRef(null);
676
+ var row1Ref = React.useRef(null);
677
+ var row2Ref = React.useRef(null);
678
+ var row3Ref = React.useRef(null);
679
+ /********************************************************************************************************************
680
+ * ResizeDetector
681
+ * ******************************************************************************************************************/
682
+ var captionHeight = reactResizeDetector.useResizeDetector({
683
+ targetRef: captionRef,
684
+ handleWidth: false,
685
+ handleHeight: true,
686
+ }).height;
687
+ var row1Height = reactResizeDetector.useResizeDetector({ targetRef: row1Ref, handleWidth: false, handleHeight: true }).height;
688
+ var row2Height = reactResizeDetector.useResizeDetector({ targetRef: row2Ref, handleWidth: false, handleHeight: true }).height;
689
+ var row3Height = reactResizeDetector.useResizeDetector({ targetRef: row3Ref, handleWidth: false, handleHeight: true }).height;
690
+ /********************************************************************************************************************
691
+ * Function
692
+ * ******************************************************************************************************************/
693
+ var captionRow = React.useMemo(function () {
694
+ return !!caption && (React.createElement(TableTopHeadCaptionRow, { ref: captionRef, className: 'TableTopHeadCaptionRow' },
695
+ React.createElement(material.TableCell, { colSpan: columns.length }, caption)));
696
+ }, [caption, columns]);
697
+ var makeRowCells = React.useCallback(function (row, top) {
698
+ var totalColumns = 0;
699
+ var cells = row
700
+ .map(function (info, idx) {
701
+ if (info) {
702
+ totalColumns += info.colSpan || 1;
703
+ return (React.createElement(material.TableCell, { key: idx, colSpan: info.colSpan, align: info.align, style: {
704
+ top: top,
705
+ borderBottom: 0,
706
+ } },
707
+ info.label,
708
+ info.label != null && React.createElement(BottomLine, { style: { backgroundColor: theme.palette.divider } })));
709
+ }
710
+ })
711
+ .filter(function (cell) { return !!cell; });
712
+ if (totalColumns < columns.length) {
713
+ cells.push(React.createElement(material.TableCell, { key: columns.length, colSpan: columns.length - cells.length, style: { top: top, borderBottom: 0 } }));
714
+ }
715
+ return cells;
716
+ }, [columns, theme.palette.divider]);
717
+ var columnRow = React.useMemo(function () {
718
+ var top = (captionHeight || 0) + (row1Height || 0) + (row2Height || 0) + (row3Height || 0);
719
+ return (React.createElement(material.TableRow, null, columns.map(function (column, idx) { return (React.createElement(TableHeadCell, { key: idx, column: column, defaultAlign: defaultAlign, top: top, onCheckChange: onCheckChange })); })));
720
+ }, [captionHeight, columns, defaultAlign, onCheckChange, row1Height, row2Height, row3Height]);
721
+ /********************************************************************************************************************
722
+ * Render
723
+ * ******************************************************************************************************************/
724
+ if (rows) {
725
+ if (Array.isArray(rows[0])) {
726
+ return (React.createElement(material.TableHead, { className: 'TableHead' },
727
+ captionRow,
728
+ rows.map(function (row, idx) {
729
+ var ref = undefined;
730
+ var top = undefined;
731
+ switch (idx) {
732
+ case 0:
733
+ ref = row1Ref;
734
+ top = captionHeight;
735
+ break;
736
+ case 1:
737
+ ref = row2Ref;
738
+ top = (captionHeight || 0) + (row1Height || 0);
739
+ break;
740
+ case 2:
741
+ ref = row3Ref;
742
+ top = (captionHeight || 0) + (row1Height || 0) + (row2Height || 0);
743
+ break;
744
+ case 3:
745
+ top = (captionHeight || 0) + (row1Height || 0) + (row2Height || 0) + (row3Height || 0);
746
+ }
747
+ return (React.createElement(material.TableRow, { key: idx, ref: ref, className: 'TableHeadRow' }, makeRowCells(row, top)));
748
+ })));
749
+ }
750
+ else {
751
+ return (React.createElement(material.TableHead, { className: 'TableHead' },
752
+ captionRow,
753
+ React.createElement(material.TableRow, { ref: row1Ref, className: 'TableHeadRow' }, makeRowCells(rows, captionHeight)),
754
+ columnRow));
755
+ }
756
+ }
757
+ else {
758
+ return (React.createElement(material.TableHead, { className: 'TableHead' },
759
+ captionRow,
760
+ columnRow));
761
+ }
762
+ };
763
+ var templateObject_1$1;function columnFilter(v) {
764
+ return v !== undefined && v !== null && v !== false;
765
+ }
766
+ var _columnId = 0;
767
+ var Table = React.forwardRef(function (_a, ref) {
768
+ /********************************************************************************************************************
769
+ * Ref
770
+ * ******************************************************************************************************************/
771
+ var className = _a.className, initStyle = _a.style, sx = _a.sx, caption = _a.caption, topHeadRows = _a.topHeadRows, initColumns = _a.columns, initItems = _a.items, initPaging = _a.paging, _b = _a.pagingAlign, pagingAlign = _b === void 0 ? 'center' : _b, _c = _a.defaultAlign, defaultAlign = _c === void 0 ? 'left' : _c, defaultEllipsis = _a.defaultEllipsis, initStickyHeader = _a.stickyHeader, height = _a.height, minHeight = _a.minHeight, maxHeight = _a.maxHeight, fullHeight = _a.fullHeight, showOddColor = _a.showOddColor, showEvenColor = _a.showEvenColor, _d = _a.cellPadding, cellPadding = _d === void 0 ? 13 : _d, footer = _a.footer, noData = _a.noData, pagination = _a.pagination, sortable$1 = _a.sortable, onClick = _a.onClick, onGetBodyRowClassName = _a.onGetBodyRowClassName, onGetBodyRowStyle = _a.onGetBodyRowStyle, onGetBodyRowSx = _a.onGetBodyRowSx, onGetBodyColumnClassName = _a.onGetBodyColumnClassName, onGetBodyColumnStyle = _a.onGetBodyColumnStyle, onGetBodyColumnSx = _a.onGetBodyColumnSx, onPageChange = _a.onPageChange, onSortChange = _a.onSortChange, onCheckChange = _a.onCheckChange;
772
+ var localHeaderDataRef = React.useRef({});
773
+ var localBodyDataRef = React.useRef({});
774
+ var updateHeadCheckTimer = React.useRef();
775
+ var fireOnCheckChangeTimer = React.useRef({});
776
+ var simpleBarRef = React.useRef(null);
777
+ var finalColumnsIdRef = React.useRef([]);
778
+ /********************************************************************************************************************
779
+ * sortable
780
+ * ******************************************************************************************************************/
781
+ var sensors = core.useSensors(core.useSensor(core.MouseSensor, {
782
+ // Require the mouse to move by 10 pixels before activating
783
+ activationConstraint: {
784
+ distance: 10,
785
+ },
786
+ }), core.useSensor(core.TouchSensor, {
787
+ // Press delay of 250ms, with tolerance of 5px of movement
788
+ activationConstraint: {
789
+ delay: 250,
790
+ tolerance: 5,
791
+ },
792
+ }), core.useSensor(core.KeyboardSensor, {
793
+ coordinateGetter: sortable.sortableKeyboardCoordinates,
794
+ }));
795
+ /********************************************************************************************************************
796
+ * State
797
+ * ******************************************************************************************************************/
798
+ var _e = React.useState(false), menuOpen = _e[0], setMenuOpen = _e[1];
799
+ var _f = React.useState(undefined), openMenuId = _f[0], setOpenMenuId = _f[1];
800
+ var _g = reactHook.useAutoUpdateLayoutState(initColumns), columns = _g[0], setColumns = _g[1];
801
+ var _h = React.useState(), finalColumns = _h[0], setFinalColumns = _h[1];
802
+ var _j = reactHook.useAutoUpdateLayoutState(initItems), items = _j[0], setItems = _j[1];
803
+ var _k = React.useState(), sortableItems = _k[0], setSortableItems = _k[1];
804
+ var _l = reactHook.useAutoUpdateLayoutState(initPaging), paging = _l[0], setPaging = _l[1];
805
+ /********************************************************************************************************************
806
+ * containerHeight
807
+ * ******************************************************************************************************************/
808
+ var _m = React.useState(), containerHeight = _m[0], setContainerHeight = _m[1];
809
+ var containerHeightDetector = reactResizeDetector.useResizeDetector({
810
+ handleHeight: true,
811
+ handleWidth: false,
812
+ onResize: function () {
813
+ if (containerHeightDetector.current) {
814
+ setContainerHeight(containerHeightDetector.current.getBoundingClientRect().height);
815
+ }
816
+ else {
817
+ setContainerHeight(undefined);
818
+ }
819
+ },
820
+ }).ref;
821
+ /********************************************************************************************************************
822
+ * footerHeight
823
+ * ******************************************************************************************************************/
824
+ var _o = React.useState(), pagingHeight = _o[0], setPagingHeight = _o[1];
825
+ var pagingHeightResizeDetector = reactResizeDetector.useResizeDetector({
826
+ handleHeight: true,
827
+ handleWidth: false,
828
+ onResize: function () {
829
+ if (pagingHeightResizeDetector.current) {
830
+ setPagingHeight(pagingHeightResizeDetector.current.getBoundingClientRect().height);
831
+ }
832
+ else {
833
+ setPagingHeight(undefined);
834
+ }
835
+ },
836
+ }).ref;
837
+ /********************************************************************************************************************
838
+ * Memo
839
+ * ******************************************************************************************************************/
840
+ var tableSx = React.useMemo(function () {
841
+ var sx = {
842
+ padding: typeof cellPadding === 'number' ? "".concat(cellPadding, "px") : cellPadding,
843
+ };
844
+ return {
845
+ '> .MuiTableHead-root > .MuiTableRow-root > .MuiTableCell-root ': sx,
846
+ '> .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root ': sx,
847
+ '> .MuiTableFooter-root > .MuiTableRow-root > .MuiTableCell-root ': sx,
848
+ };
849
+ }, [cellPadding]);
850
+ /********************************************************************************************************************
851
+ * Function
852
+ * ******************************************************************************************************************/
853
+ var makeSortableItems = React.useCallback(function (items) {
854
+ return items === null || items === void 0 ? void 0 : items.map(function (_a, index) {
855
+ var id = _a.id, item = __rest(_a, ["id"]);
856
+ return __assign({ id: id == null ? "".concat(uuid.v4(), "_").concat(index) : id }, item);
857
+ });
858
+ }, []);
859
+ var getFinalColumnId = React.useCallback(function (column) {
860
+ if (finalColumns && finalColumnsIdRef.current) {
861
+ var idx = finalColumns.indexOf(column);
862
+ return finalColumnsIdRef.current[idx];
863
+ }
864
+ else {
865
+ return '';
866
+ }
867
+ }, [finalColumns]);
868
+ var updateHeadCheck = React.useCallback(function (column) {
869
+ if (updateHeadCheckTimer.current) {
870
+ clearTimeout(updateHeadCheckTimer.current);
871
+ updateHeadCheckTimer.current = undefined;
872
+ }
873
+ var columnId = getFinalColumnId(column);
874
+ var headColumnData = localHeaderDataRef.current[columnId];
875
+ if (headColumnData) {
876
+ updateHeadCheckTimer.current = setTimeout(function () {
877
+ var _a, _b;
878
+ updateHeadCheckTimer.current = undefined;
879
+ var enabledCheckExists = !!Object.keys(localBodyDataRef.current).find(function (key) {
880
+ var columnData = localBodyDataRef.current[key].columns[columnId];
881
+ if (columnData) {
882
+ if (!columnData.checkDisabled) {
883
+ return true;
884
+ }
885
+ }
886
+ });
887
+ var allChecked = enabledCheckExists &&
888
+ !Object.keys(localBodyDataRef.current).find(function (key) {
889
+ var columnData = localBodyDataRef.current[key].columns[columnId];
890
+ if (columnData) {
891
+ if (!columnData.checkDisabled) {
892
+ return !columnData.checked;
893
+ }
894
+ }
895
+ });
896
+ (_a = headColumnData.commands) === null || _a === void 0 ? void 0 : _a.setCheckDisabled(!enabledCheckExists);
897
+ (_b = headColumnData.commands) === null || _b === void 0 ? void 0 : _b.setChecked(allChecked);
898
+ }, 100);
899
+ }
900
+ }, [getFinalColumnId]);
901
+ var getCheckedItems = React.useCallback(function (columnId) {
902
+ var checkedItems = [];
903
+ Object.keys(localBodyDataRef.current).forEach(function (key) {
904
+ var itemData = localBodyDataRef.current[key];
905
+ var columnData = itemData.columns[columnId];
906
+ if (columnData) {
907
+ if (columnData.checked) {
908
+ checkedItems.push(itemData.item);
909
+ }
910
+ }
911
+ });
912
+ return checkedItems;
913
+ }, []);
914
+ var stopHeadCheckTimer = React.useCallback(function () {
915
+ if (updateHeadCheckTimer.current) {
916
+ clearTimeout(updateHeadCheckTimer.current);
917
+ updateHeadCheckTimer.current = undefined;
918
+ }
919
+ }, []);
920
+ var clearFireOnCheckChangeTimer = React.useCallback(function () {
921
+ Object.keys(fireOnCheckChangeTimer.current).forEach(function (key) {
922
+ if (fireOnCheckChangeTimer.current[key]) {
923
+ clearTimeout(fireOnCheckChangeTimer.current[key]);
924
+ }
925
+ });
926
+ fireOnCheckChangeTimer.current = {};
927
+ }, []);
928
+ var fireOnCheckChange = React.useCallback(function (columnId) {
929
+ if (fireOnCheckChangeTimer.current[columnId]) {
930
+ clearTimeout(fireOnCheckChangeTimer.current[columnId]);
931
+ fireOnCheckChangeTimer.current[columnId] = undefined;
932
+ }
933
+ if (onCheckChange) {
934
+ fireOnCheckChangeTimer.current[columnId] = setTimeout(function () {
935
+ fireOnCheckChangeTimer.current[columnId] = undefined;
936
+ onCheckChange && onCheckChange(columnId, getCheckedItems(columnId));
937
+ }, 100);
938
+ }
939
+ }, [getCheckedItems, onCheckChange]);
940
+ var simpleBarScrollToTop = React.useCallback(function () {
941
+ var _a, _b;
942
+ (_b = (_a = simpleBarRef.current) === null || _a === void 0 ? void 0 : _a.getScrollElement()) === null || _b === void 0 ? void 0 : _b.scrollTo({ top: 0 });
943
+ }, []);
944
+ /********************************************************************************************************************
945
+ * Effect
946
+ * ******************************************************************************************************************/
947
+ React.useEffect(function () {
948
+ return function () {
949
+ stopHeadCheckTimer();
950
+ clearFireOnCheckChangeTimer();
951
+ };
952
+ // eslint-disable-next-line react-hooks/exhaustive-deps
953
+ }, []);
954
+ React.useEffect(function () {
955
+ stopHeadCheckTimer();
956
+ clearFireOnCheckChangeTimer();
957
+ Object.keys(localHeaderDataRef.current).forEach(function (key) {
958
+ var _a;
959
+ if (localHeaderDataRef.current[key].column.type === 'check') {
960
+ (_a = localHeaderDataRef.current[key].commands) === null || _a === void 0 ? void 0 : _a.setChecked(false);
961
+ }
962
+ });
963
+ Object.keys(localBodyDataRef.current).forEach(function (key) {
964
+ Object.keys(localBodyDataRef.current[key].columns).forEach(function (cKey) {
965
+ var _a;
966
+ (_a = localBodyDataRef.current[key].columns[cKey].commands) === null || _a === void 0 ? void 0 : _a.setChecked(false);
967
+ });
968
+ });
969
+ setSortableItems(makeSortableItems(items));
970
+ // eslint-disable-next-line react-hooks/exhaustive-deps
971
+ }, [items]);
972
+ React.useEffect(function () {
973
+ stopHeadCheckTimer();
974
+ clearFireOnCheckChangeTimer();
975
+ var newFinalColumns = columns === null || columns === void 0 ? void 0 : columns.filter(columnFilter);
976
+ setFinalColumns(newFinalColumns);
977
+ finalColumnsIdRef.current = newFinalColumns === null || newFinalColumns === void 0 ? void 0 : newFinalColumns.map(function (col) {
978
+ if (col.id) {
979
+ return col.id;
980
+ }
981
+ else {
982
+ _columnId += 1;
983
+ return "$c$".concat(_columnId, "$");
984
+ }
985
+ });
986
+ // eslint-disable-next-line react-hooks/exhaustive-deps
987
+ }, [columns]);
988
+ React.useLayoutEffect(function () {
989
+ clearFireOnCheckChangeTimer();
990
+ if (sortableItems) {
991
+ localBodyDataRef.current = sortableItems.reduce(function (res, item) {
992
+ res[item.id] = {
993
+ item: item,
994
+ columns: {},
995
+ };
996
+ if (finalColumns) {
997
+ finalColumns.forEach(function (c) {
998
+ var _a;
999
+ var columnId = getFinalColumnId(c);
1000
+ if ((_a = localBodyDataRef.current[item.id]) === null || _a === void 0 ? void 0 : _a.columns[columnId]) {
1001
+ res[item.id].columns[columnId] = localBodyDataRef.current[item.id].columns[columnId];
1002
+ }
1003
+ else {
1004
+ res[item.id].columns[columnId] = {
1005
+ column: c,
1006
+ checked: false,
1007
+ checkDisabled: false,
1008
+ };
1009
+ }
1010
+ });
1011
+ }
1012
+ return res;
1013
+ }, {});
1014
+ }
1015
+ else {
1016
+ localBodyDataRef.current = {};
1017
+ }
1018
+ }, [sortableItems, finalColumns, clearFireOnCheckChangeTimer, getFinalColumnId]);
1019
+ React.useLayoutEffect(function () {
1020
+ if (finalColumns) {
1021
+ localHeaderDataRef.current = finalColumns.reduce(function (res, c) {
1022
+ res[getFinalColumnId(c)] = { column: c, checked: false };
1023
+ return res;
1024
+ }, {});
1025
+ }
1026
+ else {
1027
+ localHeaderDataRef.current = {};
1028
+ }
1029
+ }, [finalColumns, getFinalColumnId]);
1030
+ /********************************************************************************************************************
1031
+ * Commands
1032
+ * ******************************************************************************************************************/
1033
+ React.useLayoutEffect(function () {
1034
+ if (ref) {
1035
+ var lastColumns_1 = columns;
1036
+ var lastItems_1 = items;
1037
+ var lastPaging_1 = paging;
1038
+ var commands = {
1039
+ getColumns: function () { return lastColumns_1; },
1040
+ setColumns: function (columns) {
1041
+ lastColumns_1 = columns;
1042
+ setColumns(lastColumns_1);
1043
+ },
1044
+ getItems: function () { return lastItems_1; },
1045
+ setItems: function (items) {
1046
+ lastItems_1 = items;
1047
+ setItems(items);
1048
+ },
1049
+ getPaging: function () { return lastPaging_1; },
1050
+ setItemsPaging: function (items, paging) {
1051
+ lastItems_1 = items;
1052
+ lastPaging_1 = paging;
1053
+ setItems(lastItems_1);
1054
+ setPaging(lastPaging_1);
1055
+ },
1056
+ resetSort: function () {
1057
+ setSortableItems(makeSortableItems(lastItems_1));
1058
+ },
1059
+ getCheckedItems: getCheckedItems,
1060
+ scrollToTop: simpleBarScrollToTop,
1061
+ };
1062
+ if (typeof ref === 'function') {
1063
+ ref(commands);
1064
+ }
1065
+ else {
1066
+ ref.current = commands;
1067
+ }
1068
+ }
1069
+ }, [
1070
+ ref,
1071
+ columns,
1072
+ items,
1073
+ paging,
1074
+ makeSortableItems,
1075
+ setColumns,
1076
+ setItems,
1077
+ setPaging,
1078
+ getCheckedItems,
1079
+ simpleBarScrollToTop,
1080
+ ]);
1081
+ /********************************************************************************************************************
1082
+ * Event Handler
1083
+ * ******************************************************************************************************************/
1084
+ var handleDragEnd = React.useCallback(function (event) {
1085
+ var active = event.active, over = event.over;
1086
+ if (active && over) {
1087
+ setSortableItems(function (items) {
1088
+ if (items) {
1089
+ var oldIndex_1 = null;
1090
+ var newIndex_1 = null;
1091
+ items.find(function (item, idx) {
1092
+ if (item.id === active.id) {
1093
+ oldIndex_1 = idx;
1094
+ }
1095
+ else if (item.id === over.id) {
1096
+ newIndex_1 = idx;
1097
+ }
1098
+ return oldIndex_1 != null && newIndex_1 != null;
1099
+ });
1100
+ if (oldIndex_1 != null && newIndex_1 != null) {
1101
+ var finalItems = sortable.arrayMove(items, oldIndex_1, newIndex_1);
1102
+ onSortChange && onSortChange(finalItems);
1103
+ return finalItems;
1104
+ }
1105
+ else {
1106
+ return items;
1107
+ }
1108
+ }
1109
+ else {
1110
+ return items;
1111
+ }
1112
+ });
1113
+ }
1114
+ }, [onSortChange]);
1115
+ var handleHeadCheckChange = React.useCallback(function (column, checked) {
1116
+ Object.keys(localBodyDataRef.current).forEach(function (key) {
1117
+ var _a;
1118
+ var data = localBodyDataRef.current[key].columns[getFinalColumnId(column)];
1119
+ if (data) {
1120
+ if (!data.checkDisabled) {
1121
+ (_a = data.commands) === null || _a === void 0 ? void 0 : _a.setChecked(checked);
1122
+ }
1123
+ }
1124
+ });
1125
+ }, [getFinalColumnId]);
1126
+ var handleBodyCheckChange = React.useCallback(function (item, column) {
1127
+ updateHeadCheck(column);
1128
+ }, [updateHeadCheck]);
1129
+ var handlePageChange = React.useCallback(function (page) {
1130
+ simpleBarScrollToTop();
1131
+ onPageChange && onPageChange(page);
1132
+ }, [onPageChange, simpleBarScrollToTop]);
1133
+ /********************************************************************************************************************
1134
+ * TableContext Function
1135
+ * ******************************************************************************************************************/
1136
+ var TableContextSetMenuOpen = React.useCallback(function (newMenuOpen, newOpenMenuId) {
1137
+ if (newMenuOpen) {
1138
+ setMenuOpen(newMenuOpen);
1139
+ setOpenMenuId(newOpenMenuId);
1140
+ }
1141
+ else {
1142
+ if (openMenuId === newOpenMenuId) {
1143
+ setMenuOpen(false);
1144
+ setOpenMenuId(undefined);
1145
+ }
1146
+ }
1147
+ }, [openMenuId]);
1148
+ var TableContextSetItemColumnChecked = React.useCallback(function (item, column, checked) {
1149
+ var _a;
1150
+ var columnId = getFinalColumnId(column);
1151
+ var data = (_a = localBodyDataRef.current[item.id]) === null || _a === void 0 ? void 0 : _a.columns[columnId];
1152
+ if (data) {
1153
+ data.checked = checked;
1154
+ fireOnCheckChange(columnId);
1155
+ }
1156
+ }, [fireOnCheckChange, getFinalColumnId]);
1157
+ var TableContextSetItemColumnCheckDisabled = React.useCallback(function (item, column, disabled) {
1158
+ var _a;
1159
+ var data = (_a = localBodyDataRef.current[item.id]) === null || _a === void 0 ? void 0 : _a.columns[getFinalColumnId(column)];
1160
+ if (data) {
1161
+ data.checkDisabled = disabled;
1162
+ updateHeadCheck(column);
1163
+ }
1164
+ }, [getFinalColumnId, updateHeadCheck]);
1165
+ var TableContextSetItemColumnCommands = React.useCallback(function (item, column, commands) {
1166
+ var _a;
1167
+ var data = (_a = localBodyDataRef.current[item.id]) === null || _a === void 0 ? void 0 : _a.columns[getFinalColumnId(column)];
1168
+ if (data) {
1169
+ data.commands = commands;
1170
+ }
1171
+ }, [getFinalColumnId]);
1172
+ var TableContextSetHeadColumnChecked = React.useCallback(function (column, checked) {
1173
+ var data = localHeaderDataRef.current[getFinalColumnId(column)];
1174
+ if (data) {
1175
+ data.checked = checked;
1176
+ }
1177
+ }, [getFinalColumnId]);
1178
+ var TableContextSetHeadColumnCommands = React.useCallback(function (column, commands) {
1179
+ var data = localHeaderDataRef.current[getFinalColumnId(column)];
1180
+ if (data) {
1181
+ data.commands = commands;
1182
+ }
1183
+ }, [getFinalColumnId]);
1184
+ /********************************************************************************************************************
1185
+ * Memo
1186
+ * ******************************************************************************************************************/
1187
+ var tableContextValue = React.useMemo(function () { return ({
1188
+ menuOpen: menuOpen,
1189
+ openMenuId: openMenuId,
1190
+ setMenuOpen: TableContextSetMenuOpen,
1191
+ setItemColumnChecked: TableContextSetItemColumnChecked,
1192
+ setItemColumnCheckDisabled: TableContextSetItemColumnCheckDisabled,
1193
+ setItemColumnCommands: TableContextSetItemColumnCommands,
1194
+ setHeadColumnChecked: TableContextSetHeadColumnChecked,
1195
+ setHeadColumnCommands: TableContextSetHeadColumnCommands,
1196
+ }); }, [
1197
+ TableContextSetHeadColumnChecked,
1198
+ TableContextSetHeadColumnCommands,
1199
+ TableContextSetItemColumnCheckDisabled,
1200
+ TableContextSetItemColumnChecked,
1201
+ TableContextSetItemColumnCommands,
1202
+ TableContextSetMenuOpen,
1203
+ menuOpen,
1204
+ openMenuId,
1205
+ ]);
1206
+ var isNoData = React.useMemo(function () { return !!sortableItems && sortableItems.length <= 0; }, [sortableItems]);
1207
+ var finalPagingHeight = React.useMemo(function () { return (paging && paging.total > 0 ? pagingHeight || 0 : 0); }, [paging, pagingHeight]);
1208
+ var stickyHeader = React.useMemo(function () { return !isNoData && initStickyHeader; }, [initStickyHeader, isNoData]);
1209
+ var style = React.useMemo(function () {
1210
+ if (fullHeight) {
1211
+ return __assign(__assign({ width: '100%' }, initStyle), { flex: 1, justifyContent: 'flex-end', height: '100%', display: 'flex', flexDirection: 'column', position: 'relative' });
1212
+ }
1213
+ else {
1214
+ return __assign({ width: '100%' }, initStyle);
1215
+ }
1216
+ }, [initStyle, fullHeight]);
1217
+ var simpleBarStyle = React.useMemo(function () {
1218
+ if (fullHeight) {
1219
+ return {
1220
+ height: (containerHeight || 0) - (finalPagingHeight || 0) - 1,
1221
+ flex: 1,
1222
+ position: 'absolute',
1223
+ top: 0,
1224
+ left: 0,
1225
+ right: 0,
1226
+ marginBottom: finalPagingHeight || 0,
1227
+ };
1228
+ }
1229
+ else {
1230
+ return { height: height, minHeight: minHeight, maxHeight: maxHeight, marginBottom: -1 };
1231
+ }
1232
+ }, [fullHeight, containerHeight, finalPagingHeight, height, minHeight, maxHeight]);
1233
+ var tableStyle = React.useMemo(function () {
1234
+ if (fullHeight && isNoData) {
1235
+ return { flex: 1, height: (containerHeight || 0) - finalPagingHeight - 2 };
1236
+ }
1237
+ }, [fullHeight, isNoData, containerHeight, finalPagingHeight]);
1238
+ var pagingStyle = React.useMemo(function () {
1239
+ var style = { padding: '13px 0', borderTop: '1px solid rgba(224, 224, 224, 1)' };
1240
+ if (fullHeight) {
1241
+ return __assign({ position: 'sticky' }, style);
1242
+ }
1243
+ return style;
1244
+ }, [fullHeight]);
1245
+ var tableTopHead = React.useMemo(function () {
1246
+ return finalColumns && (React.createElement(TableTopHead, { caption: caption, rows: topHeadRows, columns: finalColumns, defaultAlign: defaultAlign, onCheckChange: handleHeadCheckChange }));
1247
+ }, [caption, defaultAlign, finalColumns, handleHeadCheckChange, topHeadRows]);
1248
+ var tableBody = React.useMemo(function () {
1249
+ return finalColumns && (React.createElement(material.TableBody, null, sortableItems ? (sortableItems.length > 0 ? (React.createElement(sortable.SortableContext, { items: sortableItems, strategy: sortable.verticalListSortingStrategy }, sortableItems.map(function (item, idx) { return (React.createElement(TableBodyRow, { key: item.id, className: classNames(!!showOddColor && 'odd-color', !!showEvenColor && 'even-color', onGetBodyRowClassName ? onGetBodyRowClassName(item, idx) : undefined), style: onGetBodyRowStyle ? onGetBodyRowStyle(item, idx) : undefined, sx: onGetBodyRowSx ? onGetBodyRowSx(item, idx) : undefined, onGetColumnClassName: onGetBodyColumnClassName, onGetColumnStyle: onGetBodyColumnStyle, onGetColumnSx: onGetBodyColumnSx, hover: true, id: item.id, index: idx, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, sortable: sortable$1, columns: finalColumns, item: item, onClick: onClick, onCheckChange: handleBodyCheckChange })); }))) : (React.createElement(StyledBodyRow$1, null,
1250
+ React.createElement(material.TableCell, { colSpan: finalColumns.length, style: { flex: 1 } }, noData ? (noData) : (React.createElement(StyledNoDataDiv, null,
1251
+ React.createElement("div", null,
1252
+ React.createElement(material.Icon, null, "error")),
1253
+ React.createElement("div", null, "\uAC80\uC0C9\uB41C \uC815\uBCF4\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."))))))) : undefined));
1254
+ }, [
1255
+ defaultAlign,
1256
+ defaultEllipsis,
1257
+ finalColumns,
1258
+ handleBodyCheckChange,
1259
+ noData,
1260
+ onClick,
1261
+ onGetBodyColumnClassName,
1262
+ onGetBodyColumnStyle,
1263
+ onGetBodyColumnSx,
1264
+ onGetBodyRowClassName,
1265
+ onGetBodyRowStyle,
1266
+ onGetBodyRowSx,
1267
+ showEvenColor,
1268
+ showOddColor,
1269
+ sortable$1,
1270
+ sortableItems,
1271
+ ]);
1272
+ var tableFooter = React.useMemo(function () {
1273
+ return finalColumns &&
1274
+ !isNoData &&
1275
+ footer && (React.createElement(material.TableFooter, null,
1276
+ React.createElement(material.TableRow, null, finalColumns.map(function (column, idx) { return (React.createElement(TableFooterCell, { key: idx, column: column, defaultAlign: defaultAlign })); }))));
1277
+ }, [defaultAlign, finalColumns, footer, isNoData]);
1278
+ var tablePaging = React.useMemo(function () {
1279
+ return finalColumns &&
1280
+ paging &&
1281
+ paging.total > 0 && (React.createElement(material.Stack, { ref: fullHeight ? pagingHeightResizeDetector : undefined, alignItems: pagingAlign, style: pagingStyle },
1282
+ React.createElement(TablePagination, { className: pagination === null || pagination === void 0 ? void 0 : pagination.className, style: pagination === null || pagination === void 0 ? void 0 : pagination.style, sx: pagination === null || pagination === void 0 ? void 0 : pagination.sx, paging: paging, align: pagingAlign, onChange: handlePageChange })));
1283
+ }, [
1284
+ finalColumns,
1285
+ fullHeight,
1286
+ handlePageChange,
1287
+ pagination === null || pagination === void 0 ? void 0 : pagination.className,
1288
+ pagination === null || pagination === void 0 ? void 0 : pagination.style,
1289
+ pagination === null || pagination === void 0 ? void 0 : pagination.sx,
1290
+ paging,
1291
+ pagingAlign,
1292
+ pagingHeightResizeDetector,
1293
+ pagingStyle,
1294
+ ]);
1295
+ /********************************************************************************************************************
1296
+ * Render
1297
+ * ******************************************************************************************************************/
1298
+ return finalColumns ? (React.createElement(TableContextProvider, { value: tableContextValue },
1299
+ React.createElement(material.Paper, { ref: fullHeight ? containerHeightDetector : undefined, className: classNames('Table', className, !!stickyHeader && 'sticky-header', !!fullHeight && 'full-height', !!showOddColor && 'odd-color', !!showEvenColor && 'even-color', !!sortable$1 && 'sortable'), variant: 'outlined', style: style, sx: sx },
1300
+ React.createElement(SimpleBar, { ref: simpleBarRef, style: simpleBarStyle },
1301
+ React.createElement(core.DndContext, { sensors: sensors, collisionDetection: core.closestCenter, onDragEnd: handleDragEnd },
1302
+ React.createElement(material.Table, { stickyHeader: stickyHeader, sx: tableSx, style: tableStyle },
1303
+ tableTopHead,
1304
+ tableBody,
1305
+ tableFooter))),
1306
+ tablePaging))) : null;
1307
+ });var SearchTable = React.forwardRef(function (_a, ref) {
1308
+ /********************************************************************************************************************
1309
+ * Ref
1310
+ * ******************************************************************************************************************/
1311
+ var _b, _c;
1312
+ var className = _a.className, initStyle = _a.style, sx = _a.sx, color = _a.color, hash = _a.hash, stickyHeader = _a.stickyHeader, fullHeight = _a.fullHeight, search = _a.search, table = _a.table, betweenSearchTableComponent = _a.betweenSearchTableComponent, onGetData = _a.onGetData, onRequestHashChange = _a.onRequestHashChange;
1313
+ var searchRef = React.useRef();
1314
+ var tableRef = React.useRef();
1315
+ var lastGetDataDataRef = React.useRef({});
1316
+ /********************************************************************************************************************
1317
+ * Function
1318
+ * ******************************************************************************************************************/
1319
+ var getSearchInfo = React.useCallback(function (search) {
1320
+ var searchInfo = {};
1321
+ if (search) {
1322
+ var ref_1 = search.ref, searchGroups = search.searchGroups, props = __rest(search, ["ref", "searchGroups"]);
1323
+ searchInfo.ref = ref_1;
1324
+ searchInfo.searchGroups = searchGroups;
1325
+ searchInfo.props = props;
1326
+ }
1327
+ return searchInfo;
1328
+ }, []);
1329
+ var getTableInfo = React.useCallback(function (table) {
1330
+ var tableInfo = {};
1331
+ if (table) {
1332
+ var ref_2 = table.ref, props = __rest(table, ["ref"]);
1333
+ tableInfo.ref = ref_2;
1334
+ tableInfo.props = props;
1335
+ }
1336
+ return tableInfo;
1337
+ }, []);
1338
+ /********************************************************************************************************************
1339
+ * State
1340
+ * ******************************************************************************************************************/
1341
+ var _d = React.useState(true), isFirstSearchSubmit = _d[0], setIsFirstSearchSubmit = _d[1];
1342
+ var _e = React.useState(), tableData = _e[0], setTableData = _e[1];
1343
+ /********************************************************************************************************************
1344
+ * searchInfo
1345
+ * ******************************************************************************************************************/
1346
+ var searchInfoFirstUseEffect = React.useRef(true);
1347
+ var _f = React.useState(function () { return getSearchInfo(search); }), searchInfo = _f[0], setSearchInfo = _f[1];
1348
+ React.useEffect(function () {
1349
+ if (searchInfoFirstUseEffect.current) {
1350
+ searchInfoFirstUseEffect.current = false;
1351
+ }
1352
+ else {
1353
+ setSearchInfo(getSearchInfo(search));
1354
+ }
1355
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1356
+ }, [search]);
1357
+ /********************************************************************************************************************
1358
+ * tableInfo
1359
+ * ******************************************************************************************************************/
1360
+ var tableInfoFirstUseEffect = React.useRef(true);
1361
+ var _g = React.useState(function () { return getTableInfo(table); }), tableInfo = _g[0], setTableInfo = _g[1];
1362
+ React.useEffect(function () {
1363
+ if (tableInfoFirstUseEffect.current) {
1364
+ tableInfoFirstUseEffect.current = false;
1365
+ }
1366
+ else {
1367
+ setTableInfo(getTableInfo(table));
1368
+ }
1369
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1370
+ }, [table]);
1371
+ /********************************************************************************************************************
1372
+ * Function
1373
+ * ******************************************************************************************************************/
1374
+ var getData = React.useCallback(function (data) {
1375
+ lastGetDataDataRef.current = data;
1376
+ if (onGetData) {
1377
+ onGetData(data).then(setTableData);
1378
+ }
1379
+ }, [onGetData]);
1380
+ var deHash = React.useCallback(function () {
1381
+ var values = {};
1382
+ var hash = window.location.hash.substring(1);
1383
+ hash.replace(/([^=&]+)=([^&]*)/g, function (substring, key, value) {
1384
+ values[decodeURIComponent(key)] = decodeURIComponent(value);
1385
+ return substring;
1386
+ });
1387
+ return values;
1388
+ }, []);
1389
+ var hashToSearchValue = React.useCallback(function () {
1390
+ var commands = searchRef.current;
1391
+ if (commands) {
1392
+ commands.resetAll();
1393
+ var hashValues_1 = deHash();
1394
+ Object.keys(hashValues_1).forEach(function (name) {
1395
+ var _a, _b;
1396
+ var value = hashValues_1[name];
1397
+ if (name === 'page') {
1398
+ commands.setValue(name, Number(value) || 1);
1399
+ }
1400
+ else {
1401
+ var itemCommands = commands.getItem(name);
1402
+ if (itemCommands) {
1403
+ switch (itemCommands.getType()) {
1404
+ case 'FormCheckbox':
1405
+ if (util.notEmpty(value)) {
1406
+ var checkCommands = itemCommands;
1407
+ if (value.toString() === ((_a = itemCommands.getValue()) === null || _a === void 0 ? void 0 : _a.toString())) {
1408
+ checkCommands.setChecked(true);
1409
+ }
1410
+ else if (value.toString() === ((_b = checkCommands.getUncheckedValue()) === null || _b === void 0 ? void 0 : _b.toString())) {
1411
+ checkCommands.setChecked(false);
1412
+ }
1413
+ }
1414
+ break;
1415
+ case 'FormDatePicker':
1416
+ case 'FormDateTimePicker':
1417
+ case 'FormTimePicker':
1418
+ {
1419
+ if (util.notEmpty(value)) {
1420
+ var dateCommands = itemCommands;
1421
+ var format = dateCommands.getFormValueFormat();
1422
+ var itemValue = dayjs(value, format);
1423
+ itemCommands.setValue(itemValue.isValid() ? itemValue : null);
1424
+ }
1425
+ else {
1426
+ itemCommands.setValue(null);
1427
+ }
1428
+ }
1429
+ break;
1430
+ case 'FormDateRangePicker':
1431
+ {
1432
+ var dateRangePickerCommands = itemCommands;
1433
+ var fromName = dateRangePickerCommands.getFormValueFromName();
1434
+ var toName = dateRangePickerCommands.getFormValueToName();
1435
+ var format = dateRangePickerCommands.getFormValueFormat();
1436
+ if (name === fromName) {
1437
+ if (util.notEmpty(value)) {
1438
+ var startValue = dayjs(value, format);
1439
+ dateRangePickerCommands.setFromValue(startValue.isValid() ? startValue : null);
1440
+ }
1441
+ else {
1442
+ dateRangePickerCommands.setFromValue(null);
1443
+ }
1444
+ }
1445
+ else if (name === toName) {
1446
+ if (util.notEmpty(value)) {
1447
+ var endValue = dayjs(value, format);
1448
+ dateRangePickerCommands.setToValue(endValue.isValid() ? endValue : null);
1449
+ }
1450
+ else {
1451
+ dateRangePickerCommands.setToValue(null);
1452
+ }
1453
+ }
1454
+ }
1455
+ break;
1456
+ case 'FormYearRangePicker':
1457
+ {
1458
+ var dateRangePickerCommands = itemCommands;
1459
+ var fromName = dateRangePickerCommands.getFormValueFromName();
1460
+ var toName = dateRangePickerCommands.getFormValueToName();
1461
+ if (name === fromName) {
1462
+ dateRangePickerCommands.setFromValue(util.notEmpty(value) ? Number(value) : null);
1463
+ }
1464
+ else if (name === toName) {
1465
+ dateRangePickerCommands.setToValue(util.notEmpty(value) ? Number(value) : null);
1466
+ }
1467
+ }
1468
+ break;
1469
+ case 'FormMonthPicker':
1470
+ {
1471
+ var monthCommands = itemCommands;
1472
+ var yearName = monthCommands.getFormValueYearName();
1473
+ var monthName = monthCommands.getFormValueMonthName();
1474
+ if (name === yearName) {
1475
+ monthCommands.setYear(util.notEmpty(value) ? Number(value) : null);
1476
+ }
1477
+ else if (name === monthName) {
1478
+ monthCommands.setMonth(util.notEmpty(value) ? Number(value) : null);
1479
+ }
1480
+ }
1481
+ break;
1482
+ case 'FormMonthRangePicker':
1483
+ {
1484
+ var monthRangeCommands = itemCommands;
1485
+ var fromYearName = monthRangeCommands.getFormValueFromYearName();
1486
+ var fromMonthName = monthRangeCommands.getFormValueFromMonthName();
1487
+ var toYearName = monthRangeCommands.getFormValueToYearName();
1488
+ var toMonthName = monthRangeCommands.getFormValueToMonthName();
1489
+ if (name === fromYearName) {
1490
+ monthRangeCommands.setFromYear(util.notEmpty(value) ? Number(value) : null);
1491
+ }
1492
+ else if (name === fromMonthName) {
1493
+ monthRangeCommands.setFromMonth(util.notEmpty(value) ? Number(value) : null);
1494
+ }
1495
+ else if (name === toYearName) {
1496
+ monthRangeCommands.setToYear(util.notEmpty(value) ? Number(value) : null);
1497
+ }
1498
+ else if (name === toMonthName) {
1499
+ monthRangeCommands.setToMonth(util.notEmpty(value) ? Number(value) : null);
1500
+ }
1501
+ }
1502
+ break;
1503
+ default:
1504
+ commands.setValue(name, value);
1505
+ break;
1506
+ }
1507
+ }
1508
+ }
1509
+ });
1510
+ return commands.getAllFormValue();
1511
+ }
1512
+ }, [searchRef, deHash]);
1513
+ /********************************************************************************************************************
1514
+ * Commands
1515
+ * ******************************************************************************************************************/
1516
+ React.useLayoutEffect(function () {
1517
+ if (ref) {
1518
+ var commands = {
1519
+ reload: function (page) {
1520
+ var _a, _b, _c, _d;
1521
+ if (page != null) {
1522
+ (_a = tableRef.current) === null || _a === void 0 ? void 0 : _a.scrollToTop();
1523
+ }
1524
+ var finalData;
1525
+ if (lastGetDataDataRef.current) {
1526
+ finalData = __assign({}, lastGetDataDataRef.current);
1527
+ if (page != null) {
1528
+ (_b = searchRef.current) === null || _b === void 0 ? void 0 : _b.setValue('page', page);
1529
+ finalData.page = page;
1530
+ }
1531
+ }
1532
+ else {
1533
+ if (hash) {
1534
+ hashToSearchValue();
1535
+ }
1536
+ if (page != null) {
1537
+ (_c = searchRef.current) === null || _c === void 0 ? void 0 : _c.setValue('page', page);
1538
+ }
1539
+ finalData = ((_d = searchRef.current) === null || _d === void 0 ? void 0 : _d.getAllFormValue()) || {};
1540
+ }
1541
+ getData(finalData);
1542
+ },
1543
+ getLastLoadData: function () { return lastGetDataDataRef.current || {}; },
1544
+ getSearch: function () { return searchRef.current; },
1545
+ getTable: function () { return tableRef.current; },
1546
+ };
1547
+ if (typeof ref === 'function') {
1548
+ ref(commands);
1549
+ }
1550
+ else {
1551
+ ref.current = commands;
1552
+ }
1553
+ }
1554
+ }, [ref, hash, lastGetDataDataRef, searchRef, tableRef, getData, hashToSearchValue]);
1555
+ /********************************************************************************************************************
1556
+ * hash
1557
+ * ******************************************************************************************************************/
1558
+ React.useEffect(function () {
1559
+ if (hash) {
1560
+ var data = hashToSearchValue();
1561
+ if (data)
1562
+ getData(data);
1563
+ }
1564
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1565
+ }, [window.location.hash]);
1566
+ var hashChange = React.useCallback(function (params) {
1567
+ if (onRequestHashChange) {
1568
+ var hashes_1 = [];
1569
+ Object.keys(params).forEach(function (name) {
1570
+ var value = params[name];
1571
+ if (name === 'page') {
1572
+ if (Number(value) > 1) {
1573
+ hashes_1.push("".concat(name, "=").concat(value));
1574
+ }
1575
+ }
1576
+ else {
1577
+ if (searchRef.current) {
1578
+ var itemCommands = searchRef.current.getItem(name);
1579
+ if (itemCommands) {
1580
+ var resetValue = null;
1581
+ switch (itemCommands.getType()) {
1582
+ case 'FormDateRangePicker':
1583
+ case 'FormYearRangePicker':
1584
+ {
1585
+ var commands = itemCommands;
1586
+ var itemName = itemCommands.getName();
1587
+ var fromName = commands.getFormValueFromName();
1588
+ var fromSuffix = commands.getFormValueFromNameSuffix();
1589
+ var toName = commands.getFormValueToName();
1590
+ var toSuffix = commands.getFormValueToNameSuffix();
1591
+ if (name === fromName) {
1592
+ resetValue = searchRef.current.getFormReset(itemName, fromSuffix);
1593
+ }
1594
+ else if (name === toName) {
1595
+ resetValue = searchRef.current.getFormReset(itemName, toSuffix);
1596
+ }
1597
+ }
1598
+ break;
1599
+ case 'FormMonthPicker':
1600
+ {
1601
+ var commands = itemCommands;
1602
+ var itemName = commands.getName();
1603
+ var yearName = commands.getFormValueYearName();
1604
+ var yearSuffix = commands.getFormValueYearNameSuffix();
1605
+ var monthName = commands.getFormValueMonthName();
1606
+ var monthSuffix = commands.getFormValueMonthNameSuffix();
1607
+ if (name === yearName) {
1608
+ resetValue = searchRef.current.getFormReset(itemName, yearSuffix);
1609
+ }
1610
+ else if (name === monthName) {
1611
+ resetValue = searchRef.current.getFormReset(itemName, monthSuffix);
1612
+ }
1613
+ }
1614
+ break;
1615
+ case 'FormMonthRangePicker':
1616
+ {
1617
+ var commands = itemCommands;
1618
+ var itemName = commands.getName();
1619
+ var fromYearName = commands.getFormValueFromYearName();
1620
+ var fromYearSuffix = commands.getFormValueFromYearNameSuffix();
1621
+ var fromMonthName = commands.getFormValueFromMonthName();
1622
+ var fromMonthSuffix = commands.getFormValueFromMonthNameSuffix();
1623
+ var toYearName = commands.getFormValueToYearName();
1624
+ var toYearSuffix = commands.getFormValueToYearNameSuffix();
1625
+ var toMonthName = commands.getFormValueToMonthName();
1626
+ var toMonthSuffix = commands.getFormValueToMonthNameSuffix();
1627
+ if (name === fromYearName) {
1628
+ resetValue = searchRef.current.getFormReset(itemName, fromYearSuffix);
1629
+ }
1630
+ else if (name === fromMonthName) {
1631
+ resetValue = searchRef.current.getFormReset(itemName, fromMonthSuffix);
1632
+ }
1633
+ else if (name === toYearName) {
1634
+ resetValue = searchRef.current.getFormReset(itemName, toYearSuffix);
1635
+ }
1636
+ else if (name === toMonthName) {
1637
+ resetValue = searchRef.current.getFormReset(itemName, toMonthSuffix);
1638
+ }
1639
+ }
1640
+ break;
1641
+ default:
1642
+ resetValue = searchRef.current.getFormReset(name);
1643
+ break;
1644
+ }
1645
+ if (resetValue != null && !util.equal(resetValue, value) && typeof value !== 'object') {
1646
+ hashes_1.push("".concat(name, "=").concat(encodeURIComponent(value)));
1647
+ }
1648
+ }
1649
+ }
1650
+ }
1651
+ });
1652
+ var finalHash = hashes_1.join('&');
1653
+ if (window.location.hash.substring(1) === finalHash) {
1654
+ getData(params);
1655
+ }
1656
+ else {
1657
+ onRequestHashChange(hashes_1.join('&'));
1658
+ }
1659
+ }
1660
+ }, [onRequestHashChange, getData]);
1661
+ /********************************************************************************************************************
1662
+ * Event Handler
1663
+ * ******************************************************************************************************************/
1664
+ var handlePageChange = React.useCallback(function (page) {
1665
+ var _a, _b;
1666
+ (_a = searchRef.current) === null || _a === void 0 ? void 0 : _a.setValue('page', page);
1667
+ var finalData;
1668
+ if (lastGetDataDataRef.current) {
1669
+ finalData = __assign({}, lastGetDataDataRef.current);
1670
+ finalData.page = page;
1671
+ }
1672
+ else {
1673
+ finalData = (_b = searchRef.current) === null || _b === void 0 ? void 0 : _b.getAllFormValue();
1674
+ }
1675
+ if (hash) {
1676
+ hashChange(finalData || {});
1677
+ }
1678
+ else {
1679
+ getData(finalData || {});
1680
+ }
1681
+ }, [searchRef, hash, hashChange, getData]);
1682
+ var handleSearchSubmit = React.useCallback(function (data) {
1683
+ var _a, _b;
1684
+ (_a = tableRef.current) === null || _a === void 0 ? void 0 : _a.scrollToTop();
1685
+ if (isFirstSearchSubmit) {
1686
+ setIsFirstSearchSubmit(false);
1687
+ if (!hash) {
1688
+ getData(data);
1689
+ }
1690
+ }
1691
+ else {
1692
+ (_b = searchRef.current) === null || _b === void 0 ? void 0 : _b.setValue('page', 1);
1693
+ var finalData = __assign(__assign({}, data), { page: 1 });
1694
+ if (hash) {
1695
+ hashChange(finalData);
1696
+ }
1697
+ else {
1698
+ getData(finalData);
1699
+ }
1700
+ }
1701
+ }, [searchRef, hash, hashChange, getData, isFirstSearchSubmit]);
1702
+ /********************************************************************************************************************
1703
+ * Memo
1704
+ * ******************************************************************************************************************/
1705
+ var styles = React.useMemo(function () {
1706
+ return fullHeight
1707
+ ? {
1708
+ containerStyle: __assign(__assign({}, initStyle), { flex: 1, display: 'flex' }),
1709
+ tableContainerStyle: { flex: 1, display: 'flex', flexDirection: 'column' },
1710
+ }
1711
+ : { containerStyle: initStyle };
1712
+ }, [initStyle, fullHeight]);
1713
+ /********************************************************************************************************************
1714
+ * Render
1715
+ * ******************************************************************************************************************/
1716
+ return (React.createElement(material.Grid, { container: true, direction: 'column', spacing: 1, className: classNames('SearchTable', className), style: styles.containerStyle, sx: sx },
1717
+ React.createElement(material.Grid, { item: true, sx: { display: searchInfo.searchGroups ? undefined : 'none' } },
1718
+ React.createElement(reactForm.Search, __assign({ color: color }, searchInfo.props, { ref: function (commands) {
1719
+ if (searchInfo.ref) {
1720
+ if (typeof searchInfo.ref === 'function') {
1721
+ searchInfo.ref(commands);
1722
+ }
1723
+ else {
1724
+ searchInfo.ref.current = commands;
1725
+ }
1726
+ }
1727
+ searchRef.current = commands || undefined;
1728
+ }, autoSubmit: true, onSubmit: handleSearchSubmit }),
1729
+ React.createElement(reactForm.SearchGroup, { hidden: true },
1730
+ React.createElement(reactForm.FormHidden, { name: 'page', value: 1 })),
1731
+ searchInfo.searchGroups)),
1732
+ betweenSearchTableComponent && React.createElement(material.Grid, { item: true }, betweenSearchTableComponent),
1733
+ React.createElement(material.Grid, { item: true, style: styles.tableContainerStyle },
1734
+ React.createElement(Table, __assign({}, tableInfo.props, { stickyHeader: stickyHeader || ((_b = tableInfo.props) === null || _b === void 0 ? void 0 : _b.stickyHeader), fullHeight: fullHeight || ((_c = tableInfo.props) === null || _c === void 0 ? void 0 : _c.fullHeight), ref: function (commands) {
1735
+ if (tableInfo.ref) {
1736
+ if (typeof tableInfo.ref === 'function') {
1737
+ tableInfo.ref(commands);
1738
+ }
1739
+ else {
1740
+ tableInfo.ref.current = commands;
1741
+ }
1742
+ }
1743
+ tableRef.current = commands || undefined;
1744
+ }, items: tableData === null || tableData === void 0 ? void 0 : tableData.items, paging: tableData === null || tableData === void 0 ? void 0 : tableData.paging, onPageChange: handlePageChange })))));
1745
+ });var TableButton = React.forwardRef(function (_a, ref) {
1746
+ var children = _a.children, className = _a.className, initSx = _a.sx, _b = _a.variant, variant = _b === void 0 ? 'outlined' : _b, _c = _a.color, color = _c === void 0 ? 'primary' : _c, startIcon = _a.startIcon, endIcon = _a.endIcon, onClick = _a.onClick, props = __rest(_a, ["children", "className", "sx", "variant", "color", "startIcon", "endIcon", "onClick"]);
1747
+ return (React.createElement(reactComponent.PdgButton, __assign({ ref: ref, className: classNames(className, 'TableButton'), variant: variant, type: 'button', size: 'small', sx: __assign({ minWidth: 0, px: util.empty(startIcon) && util.empty(endIcon)
1748
+ ? '7px !important'
1749
+ : util.empty(children)
1750
+ ? '5px !important'
1751
+ : '7px !important' }, initSx), color: color, startIcon: startIcon, endIcon: endIcon, onClick: onClick }, props), children));
1752
+ });
1753
+ var TableButton$1 = React.memo(TableButton);var TableMenuButton = React.forwardRef(function (_a, ref) {
1754
+ /********************************************************************************************************************
1755
+ * ID
1756
+ * ******************************************************************************************************************/
1757
+ var children = _a.children, className = _a.className, initSx = _a.sx, _b = _a.color, color = _b === void 0 ? 'primary' : _b, _c = _a.variant, variant = _c === void 0 ? 'text' : _c, startIcon = _a.startIcon, _d = _a.placement, placement = _d === void 0 ? 'bottom' : _d, inModal = _a.inModal, zIndex = _a.zIndex, menuList = _a.menuList, props = __rest(_a, ["children", "className", "sx", "color", "variant", "startIcon", "placement", "inModal", "zIndex", "menuList"]);
1758
+ var buttonId = React.useId();
1759
+ var menuId = React.useId();
1760
+ /********************************************************************************************************************
1761
+ * Use
1762
+ * ******************************************************************************************************************/
1763
+ var _e = useTableState(), menuOpen = _e.menuOpen, openMenuId = _e.openMenuId, setMenuOpen = _e.setMenuOpen;
1764
+ /********************************************************************************************************************
1765
+ * Ref
1766
+ * ******************************************************************************************************************/
1767
+ var anchorRef = React.useRef();
1768
+ /********************************************************************************************************************
1769
+ * State
1770
+ * ******************************************************************************************************************/
1771
+ var _f = React.useState(false), open = _f[0], setOpen = _f[1];
1772
+ /********************************************************************************************************************
1773
+ * Memo
1774
+ * ******************************************************************************************************************/
1775
+ var icon = React.useMemo(function () { return (!startIcon && !children ? 'MoreVert' : undefined); }, [startIcon, children]);
1776
+ var sx = React.useMemo(function () { return (__assign({ minWidth: 0, pl: !children ? 0.7 : icon || startIcon ? 0.7 : variant === 'text' ? 1.2 : 0.7 }, initSx)); }, [children, icon, initSx, startIcon, variant]);
1777
+ /********************************************************************************************************************
1778
+ * Effect
1779
+ * ******************************************************************************************************************/
1780
+ React.useEffect(function () {
1781
+ if (open && menuOpen && openMenuId !== menuId) {
1782
+ setOpen(false);
1783
+ }
1784
+ }, [menuId, menuOpen, open, openMenuId]);
1785
+ /********************************************************************************************************************
1786
+ * Event Handler
1787
+ * ******************************************************************************************************************/
1788
+ var handleClick = React.useCallback(function () {
1789
+ setOpen(function (old) { return !old; });
1790
+ if (!open) {
1791
+ setMenuOpen(true, menuId);
1792
+ }
1793
+ else {
1794
+ setMenuOpen(false, menuId);
1795
+ }
1796
+ }, [menuId, open, setMenuOpen]);
1797
+ var handleClose = React.useCallback(function () {
1798
+ if (open) {
1799
+ setOpen(false);
1800
+ setMenuOpen(false, menuId);
1801
+ }
1802
+ }, [menuId, open, setMenuOpen]);
1803
+ var handleListKeyDown = React.useCallback(function (event) {
1804
+ if (event.key === 'Tab') {
1805
+ event.preventDefault();
1806
+ if (open) {
1807
+ setOpen(false);
1808
+ setMenuOpen(false, menuId);
1809
+ }
1810
+ }
1811
+ else if (event.key === 'Escape') {
1812
+ if (open) {
1813
+ setOpen(false);
1814
+ setMenuOpen(false, menuId);
1815
+ }
1816
+ }
1817
+ }, [menuId, open, setMenuOpen]);
1818
+ /********************************************************************************************************************
1819
+ * Memo
1820
+ * ******************************************************************************************************************/
1821
+ var finalMenuList = React.useMemo(function () {
1822
+ return React.cloneElement(menuList, {
1823
+ autoFocusItem: open,
1824
+ id: menuId,
1825
+ 'aria-labelledby': buttonId,
1826
+ onKeyDown: handleListKeyDown,
1827
+ onClick: handleClose,
1828
+ });
1829
+ }, [buttonId, handleClose, handleListKeyDown, menuId, menuList, open]);
1830
+ /********************************************************************************************************************
1831
+ * Render
1832
+ * ******************************************************************************************************************/
1833
+ return (React.createElement("span", null,
1834
+ React.createElement(reactComponent.PdgButton, __assign({ ref: function (r) {
1835
+ if (ref) {
1836
+ if (typeof ref === 'function') {
1837
+ ref(r);
1838
+ }
1839
+ else {
1840
+ ref.current = r;
1841
+ }
1842
+ }
1843
+ anchorRef.current = r;
1844
+ }, id: buttonId, variant: variant, "aria-controls": open ? menuId : undefined, "aria-expanded": open ? 'true' : undefined, "aria-haspopup": 'true', className: classNames(className, 'TableMenuButton'), type: 'button', size: 'small', sx: sx, color: color, startIcon: icon, onClick: handleClick }, props), children),
1845
+ React.createElement(material.Popper, { className: 'TableMenuButton-Popper', open: open, anchorEl: anchorRef.current, role: undefined, placement: placement, transition: true, style: { zIndex: inModal ? (zIndex === undefined ? 1301 : zIndex) : zIndex } }, function (_a) {
1846
+ var TransitionProps = _a.TransitionProps, placement = _a.placement;
1847
+ var placements = placement.split('-');
1848
+ var transformOrigin = '';
1849
+ if (placements[0] === 'left') {
1850
+ transformOrigin = 'right';
1851
+ // if (placements.length > 1) {
1852
+ // if (placements[1] === 'start') {
1853
+ // transformOrigin += ' top';
1854
+ // } else if (placements[1] === 'end') {
1855
+ // transformOrigin += ' bottom';
1856
+ // }
1857
+ // }
1858
+ }
1859
+ else if (placements[0] === 'right') {
1860
+ transformOrigin = 'left';
1861
+ // if (placements.length > 1) {
1862
+ // if (placements[1] === 'start') {
1863
+ // transformOrigin += ' top';
1864
+ // } else if (placements[1] === 'end') {
1865
+ // transformOrigin += ' bottom';
1866
+ // }
1867
+ // }
1868
+ }
1869
+ else if (placements[0] === 'top') {
1870
+ transformOrigin = 'bottom';
1871
+ // if (placements.length > 1) {
1872
+ // if (placements[1] === 'start') {
1873
+ // transformOrigin += ' left';
1874
+ // } else if (placements[1] === 'end') {
1875
+ // transformOrigin += ' right';
1876
+ // }
1877
+ // }
1878
+ }
1879
+ else if (placements[0] === 'bottom') {
1880
+ transformOrigin = 'top';
1881
+ // if (placements.length > 1) {
1882
+ // if (placements[1] === 'start') {
1883
+ // transformOrigin += ' left';
1884
+ // } else if (placements[1] === 'end') {
1885
+ // transformOrigin += ' right';
1886
+ // }
1887
+ // }
1888
+ }
1889
+ else {
1890
+ transformOrigin = 'top';
1891
+ }
1892
+ return (React.createElement(material.Grow, __assign({}, TransitionProps, { style: {
1893
+ transformOrigin: transformOrigin,
1894
+ } }),
1895
+ React.createElement(material.Paper, null,
1896
+ React.createElement(material.ClickAwayListener, { onClickAway: handleClose }, finalMenuList))));
1897
+ })));
1898
+ });var Label = material.styled(material.Box)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n font-size: 12px;\n font-weight: bold;\n"], ["\n font-size: 12px;\n font-weight: bold;\n"])));
1899
+ var ValueWrap = material.styled(material.Box)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n margin-top: 3px;\n position: relative;\n display: flex;\n flex-direction: row;\n"], ["\n margin-top: 3px;\n position: relative;\n display: flex;\n flex-direction: row;\n"])));
1900
+ var Value = material.styled('div')(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n flex: 1;\n"], ["\n flex: 1;\n"])));
1901
+ var ValueEllipsis = material.styled('div')(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n flex: 1;\n position: relative;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n"], ["\n flex: 1;\n position: relative;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n"])));
1902
+ var ValueClipboard = material.styled('div')(templateObject_5 || (templateObject_5 = __makeTemplateObject([""], [""])));
1903
+ var ClipboardIconButton = material.styled(material.IconButton)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n margin-top: -10px;\n margin-bottom: -10px;\n"], ["\n margin-top: -10px;\n margin-bottom: -10px;\n"])));
1904
+ var Line = material.styled('div')(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n border-top: 1px solid #efefef;\n height: 1px;\n flex: 1;\n"], ["\n border-top: 1px solid #efefef;\n height: 1px;\n flex: 1;\n"])));
1905
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;var InfoTable = function (_a) {
1906
+ /********************************************************************************************************************
1907
+ * Memo
1908
+ * ******************************************************************************************************************/
1909
+ var cols = _a.cols, _b = _a.spacing, spacing = _b === void 0 ? 2 : _b, columnSpacing = _a.columnSpacing, _c = _a.rowSpacing, rowSpacing = _c === void 0 ? 3 : _c, className = _a.className, style = _a.style, sx = _a.sx, labelClassName = _a.labelClassName, _d = _a.labelColor, labelColor = _d === void 0 ? 'primary' : _d, labelStyle = _a.labelStyle, labelSx = _a.labelSx, _e = _a.dividerColor, dividerColor = _e === void 0 ? 'gray' : _e, valueClassName = _a.valueClassName, valueStyle = _a.valueStyle, valueSx = _a.valueSx, ellipsis = _a.ellipsis, valueUnderline = _a.valueUnderline, info = _a.info, items = _a.items, onCopyToClipboard = _a.onCopyToClipboard;
1910
+ var renderItems = React.useMemo(function () {
1911
+ return items.filter(function (item) { return !!item && (!item.onHide || !item.onHide(info)); }).map(function (item) {
1912
+ /** data */
1913
+ var data = undefined;
1914
+ if (item.name !== undefined) {
1915
+ if (info[item.name] !== undefined) {
1916
+ if (info[item.name] instanceof Date) {
1917
+ data = dayjs(info[item.name]).format('YYYY-MM-DD HH:mm:ss');
1918
+ }
1919
+ else if (info[item.name] instanceof dayjs) {
1920
+ data = info[item.name].format('YYYY-MM-DD HH:mm:ss');
1921
+ }
1922
+ else {
1923
+ data = info[item.name];
1924
+ }
1925
+ }
1926
+ }
1927
+ if (item.onRender) {
1928
+ data = item.onRender(info);
1929
+ }
1930
+ else if (util.notEmpty(data)) {
1931
+ switch (item.type) {
1932
+ case 'number':
1933
+ if (typeof data === 'string' || typeof data === 'number') {
1934
+ data = util.numberFormat(data);
1935
+ if (item.numberPrefix) {
1936
+ data = (React.createElement(React.Fragment, null,
1937
+ React.createElement("span", { style: { opacity: 0.5, marginRight: 2 } }, item.numberPrefix),
1938
+ data));
1939
+ }
1940
+ if (item.numberSuffix) {
1941
+ data = (React.createElement(React.Fragment, null,
1942
+ data,
1943
+ React.createElement("span", { style: { opacity: 0.5, marginLeft: 2 } }, item.numberSuffix)));
1944
+ }
1945
+ }
1946
+ break;
1947
+ case 'tel':
1948
+ if (typeof data === 'string') {
1949
+ data = util.telNoAutoDash(data);
1950
+ }
1951
+ break;
1952
+ case 'email':
1953
+ if (typeof data === 'string') {
1954
+ data = (React.createElement(React.Fragment, null,
1955
+ React.createElement("a", { href: "mailto:".concat(data) }, data)));
1956
+ }
1957
+ break;
1958
+ case 'url':
1959
+ if (typeof data === 'string' && data.toLowerCase().startsWith('http')) {
1960
+ data = (React.createElement(React.Fragment, null,
1961
+ React.createElement("a", { href: data, target: '_blank' }, data)));
1962
+ }
1963
+ break;
1964
+ case 'company_no':
1965
+ if (typeof data === 'string') {
1966
+ data = util.companyNoAutoDash(data);
1967
+ }
1968
+ break;
1969
+ case 'personal_no':
1970
+ if (typeof data === 'string') {
1971
+ data = util.personalNoAutoDash(data);
1972
+ }
1973
+ break;
1974
+ case 'date':
1975
+ if (typeof data === 'string' || typeof data === 'number') {
1976
+ data = dayjs(data, item.dateFormat).format('YYYY-MM-DD');
1977
+ }
1978
+ break;
1979
+ case 'datetime':
1980
+ if (typeof data === 'string' || typeof data === 'number') {
1981
+ var dt = dayjs(data, item.dateFormat);
1982
+ data = (React.createElement(React.Fragment, null,
1983
+ React.createElement("span", null, dt.format('YYYY-MM-DD')),
1984
+ item.dateTwoLine ? React.createElement("br", null) : ' ',
1985
+ React.createElement("span", { style: { opacity: 0.5 } }, dt.format('HH:mm:ss'))));
1986
+ }
1987
+ break;
1988
+ case 'date-hour':
1989
+ if (typeof data === 'string' || typeof data === 'number') {
1990
+ var dt = dayjs(data, item.dateFormat);
1991
+ data = (React.createElement(React.Fragment, null,
1992
+ React.createElement("span", null, dt.format('YYYY-MM-DD')),
1993
+ item.dateTwoLine ? React.createElement("br", null) : ' ',
1994
+ React.createElement("span", { style: { opacity: 0.5 } }, dt.format('HH시'))));
1995
+ }
1996
+ break;
1997
+ case 'date-minute':
1998
+ if (typeof data === 'string' || typeof data === 'number') {
1999
+ var dt = dayjs(data, item.dateFormat);
2000
+ data = (React.createElement(React.Fragment, null,
2001
+ React.createElement("span", null, dt.format('YYYY-MM-DD')),
2002
+ item.dateTwoLine ? React.createElement("br", null) : ' ',
2003
+ React.createElement("span", { style: { opacity: 0.5 } }, dt.format('HH시 MM분'))));
2004
+ }
2005
+ break;
2006
+ }
2007
+ }
2008
+ if (util.empty(data))
2009
+ data = item.onRenderEmpty ? item.onRenderEmpty(info) : React.createElement(React.Fragment, null, "\u00A0");
2010
+ /** copyToClipboardText */
2011
+ var copyToClipboardText = item.clipboardText || (typeof data === 'string' ? data : typeof data === 'number' ? data.toString() : '');
2012
+ /** sizeProps */
2013
+ var sizeProps = {};
2014
+ if (typeof cols === 'number') {
2015
+ sizeProps.xs = 12 / cols;
2016
+ }
2017
+ else {
2018
+ if (cols.xs)
2019
+ sizeProps.xs = 12 / cols.xs;
2020
+ if (cols.sm)
2021
+ sizeProps.sm = 12 / cols.sm;
2022
+ if (cols.md)
2023
+ sizeProps.md = 12 / cols.md;
2024
+ if (cols.lg)
2025
+ sizeProps.lg = 12 / cols.lg;
2026
+ if (cols.xl)
2027
+ sizeProps.xl = 12 / cols.xl;
2028
+ }
2029
+ if (item.xs)
2030
+ sizeProps.xs = item.xs;
2031
+ if (item.sm)
2032
+ sizeProps.sm = item.sm;
2033
+ if (item.md)
2034
+ sizeProps.md = item.md;
2035
+ if (item.lg)
2036
+ sizeProps.lg = item.lg;
2037
+ if (item.xl)
2038
+ sizeProps.xl = item.xl;
2039
+ if (item.onXs)
2040
+ sizeProps.xs = item.onXs(info);
2041
+ if (item.onSm)
2042
+ sizeProps.sm = item.onSm(info);
2043
+ if (item.onMd)
2044
+ sizeProps.md = item.onMd(info);
2045
+ if (item.onLg)
2046
+ sizeProps.lg = item.onLg(info);
2047
+ if (item.onXl)
2048
+ sizeProps.xl = item.onXl(info);
2049
+ return { item: item, data: data, copyToClipboardText: copyToClipboardText, sizeProps: sizeProps };
2050
+ });
2051
+ }, [info, items, cols]);
2052
+ var content = React.useMemo(function () {
2053
+ return renderItems.map(function (_a, idx) {
2054
+ var item = _a.item, data = _a.data, copyToClipboardText = _a.copyToClipboardText, sizeProps = _a.sizeProps;
2055
+ var finalLabelColor = typographyColorToSxColor(item.type === 'divider' ? item.dividerColor || dividerColor : item.labelColor || labelColor);
2056
+ var finalLabelSx = combineSx(labelSx, item.labelSx, !!finalLabelColor && { color: finalLabelColor });
2057
+ var finalValueSx = combineSx(valueSx, item.valueSx);
2058
+ var valueUnderlineStyle = valueUnderline
2059
+ ? { borderBottom: '1px solid #efefef', paddingBottom: 5 }
2060
+ : undefined;
2061
+ return item.type === 'divider' ? (React.createElement(material.Grid, { key: idx, item: true, xs: 12 },
2062
+ React.createElement(material.Stack, { direction: 'row', spacing: 0.5, alignItems: 'center' },
2063
+ item.icon && (React.createElement(reactComponent.PdgIcon, { sx: { color: item.dividerColor || dividerColor }, size: 'small' }, item.icon)),
2064
+ item.label && (React.createElement(Label, { className: classNames(labelClassName, item.labelClassName), style: __assign(__assign({}, item.labelStyle), labelStyle), sx: finalLabelSx }, item.label)),
2065
+ item.dividerLine && (React.createElement(React.Fragment, null, item.icon || item.label ? (React.createElement("div", { style: { flex: 1, paddingLeft: 5 } },
2066
+ React.createElement(Line, null))) : (React.createElement(Line, null))))))) : (React.createElement(material.Grid, __assign({ key: idx, item: true }, sizeProps, { className: item.className, style: item.style, sx: item.sx }),
2067
+ React.createElement(material.Stack, { direction: 'row', spacing: 0.5, alignItems: 'center' },
2068
+ item.icon && (React.createElement(reactComponent.PdgIcon, { sx: { color: finalLabelColor }, size: 'small' }, "CalendarMonth")),
2069
+ React.createElement(Label, { className: classNames(labelClassName, item.labelClassName), style: __assign(__assign({}, item.labelStyle), labelStyle), sx: finalLabelSx }, item.label)),
2070
+ React.createElement(ValueWrap, { className: classNames(valueClassName, item.valueClassName), style: __assign(__assign(__assign({}, valueStyle), item.valueStyle), valueUnderlineStyle), sx: finalValueSx },
2071
+ item.ellipsis || ellipsis ? React.createElement(ValueEllipsis, null, data) : React.createElement(Value, null, data),
2072
+ item.clipboard && util.notEmpty(copyToClipboardText) && (React.createElement(ValueClipboard, null,
2073
+ React.createElement(reactCopyToClipboard.CopyToClipboard, { text: copyToClipboardText, onCopy: onCopyToClipboard ? function () { return onCopyToClipboard(item, copyToClipboardText); } : undefined },
2074
+ React.createElement(ClipboardIconButton, __assign({ size: 'small', color: 'primary' }, item.clipboardProps),
2075
+ React.createElement(reactComponent.PdgIcon, null, item.clipboardIcon || 'ContentPaste'))))))));
2076
+ });
2077
+ }, [
2078
+ dividerColor,
2079
+ ellipsis,
2080
+ labelClassName,
2081
+ labelColor,
2082
+ labelStyle,
2083
+ labelSx,
2084
+ onCopyToClipboard,
2085
+ renderItems,
2086
+ valueClassName,
2087
+ valueStyle,
2088
+ valueSx,
2089
+ valueUnderline,
2090
+ ]);
2091
+ /********************************************************************************************************************
2092
+ * Render
2093
+ * ******************************************************************************************************************/
2094
+ return (React.createElement(material.Grid, { container: true, spacing: spacing, columnSpacing: columnSpacing, rowSpacing: rowSpacing, className: classNames('InfoTable', className), style: style, sx: sx }, content));
2095
+ };exports.InfoTable=InfoTable;exports.SearchTable=SearchTable;exports.Table=Table;exports.TableButton=TableButton$1;exports.TableMenuButton=TableMenuButton;