@ceed/ads 1.41.3-next.7 → 1.41.3-next.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DataTable/components.d.ts +5 -5
- package/dist/components/DataTable/hooks.d.ts +7 -8
- package/dist/components/DataTable/types.d.ts +1 -9
- package/dist/components/DataTable/utils.d.ts +4 -4
- package/dist/components/data-display/DataTable.md +25 -27
- package/dist/index.browser.js +2 -2
- package/dist/index.browser.js.map +3 -3
- package/dist/index.cjs +40 -70
- package/dist/index.js +40 -70
- package/framer/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2618,8 +2618,8 @@ function computeAutoFitWidth(params) {
|
|
|
2618
2618
|
if (!isNaN(maxPx) && maxPx > 0) finalWidth = Math.min(finalWidth, maxPx);
|
|
2619
2619
|
return finalWidth;
|
|
2620
2620
|
}
|
|
2621
|
-
function getHeaderCellId(tableId,
|
|
2622
|
-
return `${tableId}_header_${
|
|
2621
|
+
function getHeaderCellId(tableId, field) {
|
|
2622
|
+
return `${tableId}_header_${sanitizeColumnId(field)}`;
|
|
2623
2623
|
}
|
|
2624
2624
|
function sanitizeColumnId(field) {
|
|
2625
2625
|
return String(field).trim().replace(/\s+/g, "_");
|
|
@@ -3567,8 +3567,7 @@ var HeadCell = (props) => {
|
|
|
3567
3567
|
tableColRef,
|
|
3568
3568
|
headerClassName,
|
|
3569
3569
|
headerLineClamp,
|
|
3570
|
-
onAutoFit
|
|
3571
|
-
columnId
|
|
3570
|
+
onAutoFit
|
|
3572
3571
|
} = props;
|
|
3573
3572
|
const theme = (0, import_joy33.useTheme)();
|
|
3574
3573
|
const ref = headerRef;
|
|
@@ -3579,7 +3578,7 @@ var HeadCell = (props) => {
|
|
|
3579
3578
|
}, [ref]);
|
|
3580
3579
|
const [isHovered, setIsHovered] = (0, import_react26.useState)(false);
|
|
3581
3580
|
const sortable = type === "actions" ? false : _sortable;
|
|
3582
|
-
const headId = (0, import_react26.useMemo)(() => getHeaderCellId(tableId,
|
|
3581
|
+
const headId = (0, import_react26.useMemo)(() => getHeaderCellId(tableId, field), [tableId, field]);
|
|
3583
3582
|
const isResizingRef = (0, import_react26.useRef)(false);
|
|
3584
3583
|
const resizer = (0, import_react26.useMemo)(
|
|
3585
3584
|
() => resizable ?? true ? Resizer(
|
|
@@ -3588,9 +3587,9 @@ var HeadCell = (props) => {
|
|
|
3588
3587
|
(isResizing) => {
|
|
3589
3588
|
isResizingRef.current = isResizing;
|
|
3590
3589
|
},
|
|
3591
|
-
onAutoFit ? () => onAutoFit(
|
|
3590
|
+
onAutoFit ? () => onAutoFit(field) : void 0
|
|
3592
3591
|
) : null,
|
|
3593
|
-
[resizable, ref, colRef, onAutoFit,
|
|
3592
|
+
[resizable, ref, colRef, onAutoFit, field]
|
|
3594
3593
|
);
|
|
3595
3594
|
const style = (0, import_react26.useMemo)(
|
|
3596
3595
|
() => ({
|
|
@@ -3860,7 +3859,7 @@ var BodyCell = (props) => {
|
|
|
3860
3859
|
{
|
|
3861
3860
|
ref: cellRef,
|
|
3862
3861
|
key: field,
|
|
3863
|
-
headers: getHeaderCellId(tableId,
|
|
3862
|
+
headers: getHeaderCellId(tableId, field),
|
|
3864
3863
|
sx: {
|
|
3865
3864
|
textAlign: getTextAlign({ type }),
|
|
3866
3865
|
verticalAlign: editMode ? "top" : "middle",
|
|
@@ -3926,7 +3925,7 @@ var VirtualizedTableRow = (0, import_react26.memo)(StyledTableRow2, (prevProps,
|
|
|
3926
3925
|
|
|
3927
3926
|
// src/components/DataTable/hooks.ts
|
|
3928
3927
|
var import_react27 = require("react");
|
|
3929
|
-
function useColumnWidths(
|
|
3928
|
+
function useColumnWidths(columnsByField) {
|
|
3930
3929
|
const [widths, setWidths] = (0, import_react27.useState)({});
|
|
3931
3930
|
const roRef = (0, import_react27.useRef)();
|
|
3932
3931
|
(0, import_react27.useLayoutEffect)(() => {
|
|
@@ -3936,11 +3935,11 @@ function useColumnWidths(columnsById) {
|
|
|
3936
3935
|
let changed = false;
|
|
3937
3936
|
const next = { ...prev };
|
|
3938
3937
|
entries.forEach((entry) => {
|
|
3939
|
-
const
|
|
3938
|
+
const field = entry.target.dataset.field;
|
|
3940
3939
|
const w = Math.round(entry.target.getBoundingClientRect().width);
|
|
3941
3940
|
if (w === 0) return;
|
|
3942
|
-
if (next[
|
|
3943
|
-
next[
|
|
3941
|
+
if (next[field] !== w) {
|
|
3942
|
+
next[field] = w;
|
|
3944
3943
|
changed = true;
|
|
3945
3944
|
}
|
|
3946
3945
|
});
|
|
@@ -3948,13 +3947,12 @@ function useColumnWidths(columnsById) {
|
|
|
3948
3947
|
});
|
|
3949
3948
|
});
|
|
3950
3949
|
const measured = {};
|
|
3951
|
-
Object.entries(
|
|
3950
|
+
Object.entries(columnsByField).forEach(([field, def]) => {
|
|
3952
3951
|
const el = def.headerRef.current;
|
|
3953
3952
|
if (el) {
|
|
3954
|
-
el.dataset.
|
|
3955
|
-
el.dataset.field = String(def.field);
|
|
3953
|
+
el.dataset.field = field;
|
|
3956
3954
|
const w = Math.round(el.getBoundingClientRect().width);
|
|
3957
|
-
if (w > 0) measured[
|
|
3955
|
+
if (w > 0) measured[field] = w;
|
|
3958
3956
|
roRef.current.observe(el);
|
|
3959
3957
|
}
|
|
3960
3958
|
});
|
|
@@ -3964,7 +3962,7 @@ function useColumnWidths(columnsById) {
|
|
|
3964
3962
|
return same ? prev : { ...prev, ...measured };
|
|
3965
3963
|
});
|
|
3966
3964
|
return () => roRef.current?.disconnect();
|
|
3967
|
-
}, [
|
|
3965
|
+
}, [columnsByField]);
|
|
3968
3966
|
return widths;
|
|
3969
3967
|
}
|
|
3970
3968
|
function useDataTableRenderer({
|
|
@@ -3996,6 +3994,13 @@ function useDataTableRenderer({
|
|
|
3996
3994
|
"You cannot use both `pinnedColumns` and `columnGroupingModel` at the same time. Please choose one of them."
|
|
3997
3995
|
);
|
|
3998
3996
|
}
|
|
3997
|
+
const duplicatedField = (0, import_react27.useMemo)(() => {
|
|
3998
|
+
const ids = columnsProp.map((column) => sanitizeColumnId(column.field));
|
|
3999
|
+
const index = ids.findIndex((id, i) => ids.indexOf(id) !== i);
|
|
4000
|
+
return index === -1 ? void 0 : columnsProp[index].field;
|
|
4001
|
+
}, [columnsProp]);
|
|
4002
|
+
if (duplicatedField !== void 0)
|
|
4003
|
+
throw new Error(`DataTable: column \`field\` must be unique. Duplicated: "${String(duplicatedField)}"`);
|
|
3999
4004
|
const onSelectionModelChangeRef = (0, import_react27.useRef)(onSelectionModelChange);
|
|
4000
4005
|
onSelectionModelChangeRef.current = onSelectionModelChange;
|
|
4001
4006
|
const [focusedRowId, setFocusedRowId] = (0, import_react27.useState)(null);
|
|
@@ -4017,16 +4022,9 @@ function useDataTableRenderer({
|
|
|
4017
4022
|
if (!columnGroupingModel) return columnsProp;
|
|
4018
4023
|
return reorderColumnsByGroupingModel(columnsProp, columnGroupingModel);
|
|
4019
4024
|
}, [columnsProp, columnGroupingModel]);
|
|
4020
|
-
const visibleColumnIndexes = (0, import_react27.useMemo)(
|
|
4021
|
-
() => reorderedColumns.reduce((acc, col, index) => {
|
|
4022
|
-
if (visibilityModel[col.field] !== false) acc.push(index);
|
|
4023
|
-
return acc;
|
|
4024
|
-
}, []),
|
|
4025
|
-
[reorderedColumns, visibilityModel]
|
|
4026
|
-
);
|
|
4027
4025
|
const visibleColumns = (0, import_react27.useMemo)(
|
|
4028
|
-
() =>
|
|
4029
|
-
[
|
|
4026
|
+
() => reorderedColumns.filter((col) => visibilityModel[col.field] !== false),
|
|
4027
|
+
[reorderedColumns, visibilityModel]
|
|
4030
4028
|
);
|
|
4031
4029
|
const visibleFieldSet = (0, import_react27.useMemo)(() => new Set(visibleColumns.map((c) => c.field)), [visibleColumns]);
|
|
4032
4030
|
const tableMinWidth = (0, import_react27.useMemo)(() => {
|
|
@@ -4047,29 +4045,10 @@ function useDataTableRenderer({
|
|
|
4047
4045
|
),
|
|
4048
4046
|
[reorderedColumns]
|
|
4049
4047
|
);
|
|
4050
|
-
const
|
|
4051
|
-
const taken = new Set(reorderedColumns.map((column) => sanitizeColumnId(column.field)));
|
|
4052
|
-
const assigned = /* @__PURE__ */ new Set();
|
|
4053
|
-
return reorderedColumns.map((column) => {
|
|
4054
|
-
const field = sanitizeColumnId(column.field);
|
|
4055
|
-
if (!assigned.has(field)) {
|
|
4056
|
-
assigned.add(field);
|
|
4057
|
-
return field;
|
|
4058
|
-
}
|
|
4059
|
-
let n = 2;
|
|
4060
|
-
while (taken.has(`${field}__${n}`)) n += 1;
|
|
4061
|
-
taken.add(`${field}__${n}`);
|
|
4062
|
-
return `${field}__${n}`;
|
|
4063
|
-
});
|
|
4064
|
-
}, [reorderedColumns]);
|
|
4065
|
-
const columnIds = (0, import_react27.useMemo)(
|
|
4066
|
-
() => visibleColumnIndexes.map((index) => allColumnIds[index]),
|
|
4067
|
-
[visibleColumnIndexes, allColumnIds]
|
|
4068
|
-
);
|
|
4069
|
-
const visibleColumnsById = (0, import_react27.useMemo)(
|
|
4048
|
+
const visibleColumnsByField = (0, import_react27.useMemo)(
|
|
4070
4049
|
() => Object.fromEntries(
|
|
4071
|
-
visibleColumns.map((column
|
|
4072
|
-
|
|
4050
|
+
visibleColumns.map((column) => [
|
|
4051
|
+
column.field,
|
|
4073
4052
|
{
|
|
4074
4053
|
...column,
|
|
4075
4054
|
headerRef: (0, import_react27.createRef)(),
|
|
@@ -4077,7 +4056,7 @@ function useDataTableRenderer({
|
|
|
4077
4056
|
}
|
|
4078
4057
|
])
|
|
4079
4058
|
),
|
|
4080
|
-
[visibleColumns
|
|
4059
|
+
[visibleColumns]
|
|
4081
4060
|
);
|
|
4082
4061
|
const sortComparator = (0, import_react27.useCallback)(
|
|
4083
4062
|
(rowA, rowB) => {
|
|
@@ -4170,18 +4149,12 @@ function useDataTableRenderer({
|
|
|
4170
4149
|
() => _isTotalSelected ?? (selectableRowCount > 0 && (selectionModel?.length || 0) === selectableRowCount),
|
|
4171
4150
|
[_isTotalSelected, selectionModel, selectableRowCount]
|
|
4172
4151
|
);
|
|
4173
|
-
const columnWidths = useColumnWidths(
|
|
4174
|
-
const measuredWidthByField = (0, import_react27.useMemo)(
|
|
4175
|
-
() => Object.fromEntries(
|
|
4176
|
-
Object.entries(visibleColumnsById).map(([columnId, column]) => [column.field, columnWidths[columnId]])
|
|
4177
|
-
),
|
|
4178
|
-
[visibleColumnsById, columnWidths]
|
|
4179
|
-
);
|
|
4152
|
+
const columnWidths = useColumnWidths(visibleColumnsByField);
|
|
4180
4153
|
const getWidth = (0, import_react27.useCallback)(
|
|
4181
4154
|
// 반환값은 pinned offset으로 더해지므로 반드시 숫자여야 한다. width/minWidth는 '500px' 같은 문자열.
|
|
4182
|
-
(f) =>
|
|
4155
|
+
(f) => columnWidths[f] ?? parsePxValue(allColumnsByField[f]?.width) ?? // Column prop 으로 지정된 width
|
|
4183
4156
|
parsePxValue(allColumnsByField[f]?.minWidth) ?? 0,
|
|
4184
|
-
[
|
|
4157
|
+
[columnWidths, allColumnsByField]
|
|
4185
4158
|
);
|
|
4186
4159
|
const processedColumnGroups = (0, import_react27.useMemo)(() => {
|
|
4187
4160
|
if (!columnGroupingModel) return null;
|
|
@@ -4201,16 +4174,14 @@ function useDataTableRenderer({
|
|
|
4201
4174
|
const baseColumns = visibleColumns.length > 0 ? visibleColumns : reorderedColumns.length > 0 ? [] : inferredFields.map((key) => ({
|
|
4202
4175
|
field: key
|
|
4203
4176
|
}));
|
|
4204
|
-
return baseColumns.map((column
|
|
4205
|
-
const columnId = columnIds[index] ?? sanitizeColumnId(column.field);
|
|
4177
|
+
return baseColumns.map((column) => {
|
|
4206
4178
|
const isLeftPinned = effectivePinnedLeft?.includes(column.field);
|
|
4207
4179
|
const isRightPinned = effectivePinnedRight?.includes(column.field);
|
|
4208
4180
|
const isPinned = isLeftPinned || isRightPinned;
|
|
4209
4181
|
return {
|
|
4210
4182
|
...column,
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
tableColRef: visibleColumnsById[columnId]?.tableColRef,
|
|
4183
|
+
headerRef: visibleColumnsByField[column.field]?.headerRef,
|
|
4184
|
+
tableColRef: visibleColumnsByField[column.field]?.tableColRef,
|
|
4214
4185
|
isCellEditable: editMode && (typeof column.isCellEditable === "function" ? column.isCellEditable : column.isCellEditable ?? true),
|
|
4215
4186
|
sort: sortModel.find((sort) => sort.field === column.field)?.sort,
|
|
4216
4187
|
sortOrder: allColumnsByField[column.field]?.sortOrder || sortOrder,
|
|
@@ -4227,8 +4198,7 @@ function useDataTableRenderer({
|
|
|
4227
4198
|
inferredFields,
|
|
4228
4199
|
effectivePinnedLeft,
|
|
4229
4200
|
effectivePinnedRight,
|
|
4230
|
-
|
|
4231
|
-
visibleColumnsById,
|
|
4201
|
+
visibleColumnsByField,
|
|
4232
4202
|
allColumnsByField,
|
|
4233
4203
|
editMode,
|
|
4234
4204
|
sortModel,
|
|
@@ -4288,8 +4258,8 @@ function useDataTableRenderer({
|
|
|
4288
4258
|
}
|
|
4289
4259
|
}, [_rows]);
|
|
4290
4260
|
const handleAutoFit = (0, import_react27.useCallback)(
|
|
4291
|
-
(
|
|
4292
|
-
const colDef =
|
|
4261
|
+
(field) => {
|
|
4262
|
+
const colDef = visibleColumnsByField[field];
|
|
4293
4263
|
if (!colDef?.headerRef.current) return;
|
|
4294
4264
|
const columnType = "type" in colDef ? colDef.type : void 0;
|
|
4295
4265
|
if (columnType === "actions") return;
|
|
@@ -4303,7 +4273,7 @@ function useDataTableRenderer({
|
|
|
4303
4273
|
colDef.headerRef.current.style.width = widthPx;
|
|
4304
4274
|
if (colDef.tableColRef.current) colDef.tableColRef.current.style.width = widthPx;
|
|
4305
4275
|
},
|
|
4306
|
-
[
|
|
4276
|
+
[visibleColumnsByField, dataInPage]
|
|
4307
4277
|
);
|
|
4308
4278
|
return {
|
|
4309
4279
|
rowCount,
|
|
@@ -4990,7 +4960,7 @@ function Component(props, apiRef) {
|
|
|
4990
4960
|
"col",
|
|
4991
4961
|
{
|
|
4992
4962
|
ref: c.tableColRef,
|
|
4993
|
-
key: c.
|
|
4963
|
+
key: c.field.toString(),
|
|
4994
4964
|
style: {
|
|
4995
4965
|
width: c.width,
|
|
4996
4966
|
minWidth: c.minWidth ?? "50px"
|
|
@@ -5046,7 +5016,7 @@ function Component(props, apiRef) {
|
|
|
5046
5016
|
HeadCell2,
|
|
5047
5017
|
{
|
|
5048
5018
|
tableId,
|
|
5049
|
-
key: c.
|
|
5019
|
+
key: c.field.toString(),
|
|
5050
5020
|
stickyHeader: props.stickyHeader,
|
|
5051
5021
|
editMode: !!c.isCellEditable,
|
|
5052
5022
|
onSortChange: handleSortChange,
|
package/dist/index.js
CHANGED
|
@@ -2481,8 +2481,8 @@ function computeAutoFitWidth(params) {
|
|
|
2481
2481
|
if (!isNaN(maxPx) && maxPx > 0) finalWidth = Math.min(finalWidth, maxPx);
|
|
2482
2482
|
return finalWidth;
|
|
2483
2483
|
}
|
|
2484
|
-
function getHeaderCellId(tableId,
|
|
2485
|
-
return `${tableId}_header_${
|
|
2484
|
+
function getHeaderCellId(tableId, field) {
|
|
2485
|
+
return `${tableId}_header_${sanitizeColumnId(field)}`;
|
|
2486
2486
|
}
|
|
2487
2487
|
function sanitizeColumnId(field) {
|
|
2488
2488
|
return String(field).trim().replace(/\s+/g, "_");
|
|
@@ -3444,8 +3444,7 @@ var HeadCell = (props) => {
|
|
|
3444
3444
|
tableColRef,
|
|
3445
3445
|
headerClassName,
|
|
3446
3446
|
headerLineClamp,
|
|
3447
|
-
onAutoFit
|
|
3448
|
-
columnId
|
|
3447
|
+
onAutoFit
|
|
3449
3448
|
} = props;
|
|
3450
3449
|
const theme = useTheme();
|
|
3451
3450
|
const ref = headerRef;
|
|
@@ -3456,7 +3455,7 @@ var HeadCell = (props) => {
|
|
|
3456
3455
|
}, [ref]);
|
|
3457
3456
|
const [isHovered, setIsHovered] = useState8(false);
|
|
3458
3457
|
const sortable = type === "actions" ? false : _sortable;
|
|
3459
|
-
const headId = useMemo10(() => getHeaderCellId(tableId,
|
|
3458
|
+
const headId = useMemo10(() => getHeaderCellId(tableId, field), [tableId, field]);
|
|
3460
3459
|
const isResizingRef = useRef6(false);
|
|
3461
3460
|
const resizer = useMemo10(
|
|
3462
3461
|
() => resizable ?? true ? Resizer(
|
|
@@ -3465,9 +3464,9 @@ var HeadCell = (props) => {
|
|
|
3465
3464
|
(isResizing) => {
|
|
3466
3465
|
isResizingRef.current = isResizing;
|
|
3467
3466
|
},
|
|
3468
|
-
onAutoFit ? () => onAutoFit(
|
|
3467
|
+
onAutoFit ? () => onAutoFit(field) : void 0
|
|
3469
3468
|
) : null,
|
|
3470
|
-
[resizable, ref, colRef, onAutoFit,
|
|
3469
|
+
[resizable, ref, colRef, onAutoFit, field]
|
|
3471
3470
|
);
|
|
3472
3471
|
const style = useMemo10(
|
|
3473
3472
|
() => ({
|
|
@@ -3737,7 +3736,7 @@ var BodyCell = (props) => {
|
|
|
3737
3736
|
{
|
|
3738
3737
|
ref: cellRef,
|
|
3739
3738
|
key: field,
|
|
3740
|
-
headers: getHeaderCellId(tableId,
|
|
3739
|
+
headers: getHeaderCellId(tableId, field),
|
|
3741
3740
|
sx: {
|
|
3742
3741
|
textAlign: getTextAlign({ type }),
|
|
3743
3742
|
verticalAlign: editMode ? "top" : "middle",
|
|
@@ -3803,7 +3802,7 @@ var VirtualizedTableRow = memo(StyledTableRow2, (prevProps, nextProps) => {
|
|
|
3803
3802
|
|
|
3804
3803
|
// src/components/DataTable/hooks.ts
|
|
3805
3804
|
import { useState as useState9, useLayoutEffect as useLayoutEffect2, useRef as useRef7, useMemo as useMemo11, useCallback as useCallback12, useEffect as useEffect6, createRef } from "react";
|
|
3806
|
-
function useColumnWidths(
|
|
3805
|
+
function useColumnWidths(columnsByField) {
|
|
3807
3806
|
const [widths, setWidths] = useState9({});
|
|
3808
3807
|
const roRef = useRef7();
|
|
3809
3808
|
useLayoutEffect2(() => {
|
|
@@ -3813,11 +3812,11 @@ function useColumnWidths(columnsById) {
|
|
|
3813
3812
|
let changed = false;
|
|
3814
3813
|
const next = { ...prev };
|
|
3815
3814
|
entries.forEach((entry) => {
|
|
3816
|
-
const
|
|
3815
|
+
const field = entry.target.dataset.field;
|
|
3817
3816
|
const w = Math.round(entry.target.getBoundingClientRect().width);
|
|
3818
3817
|
if (w === 0) return;
|
|
3819
|
-
if (next[
|
|
3820
|
-
next[
|
|
3818
|
+
if (next[field] !== w) {
|
|
3819
|
+
next[field] = w;
|
|
3821
3820
|
changed = true;
|
|
3822
3821
|
}
|
|
3823
3822
|
});
|
|
@@ -3825,13 +3824,12 @@ function useColumnWidths(columnsById) {
|
|
|
3825
3824
|
});
|
|
3826
3825
|
});
|
|
3827
3826
|
const measured = {};
|
|
3828
|
-
Object.entries(
|
|
3827
|
+
Object.entries(columnsByField).forEach(([field, def]) => {
|
|
3829
3828
|
const el = def.headerRef.current;
|
|
3830
3829
|
if (el) {
|
|
3831
|
-
el.dataset.
|
|
3832
|
-
el.dataset.field = String(def.field);
|
|
3830
|
+
el.dataset.field = field;
|
|
3833
3831
|
const w = Math.round(el.getBoundingClientRect().width);
|
|
3834
|
-
if (w > 0) measured[
|
|
3832
|
+
if (w > 0) measured[field] = w;
|
|
3835
3833
|
roRef.current.observe(el);
|
|
3836
3834
|
}
|
|
3837
3835
|
});
|
|
@@ -3841,7 +3839,7 @@ function useColumnWidths(columnsById) {
|
|
|
3841
3839
|
return same ? prev : { ...prev, ...measured };
|
|
3842
3840
|
});
|
|
3843
3841
|
return () => roRef.current?.disconnect();
|
|
3844
|
-
}, [
|
|
3842
|
+
}, [columnsByField]);
|
|
3845
3843
|
return widths;
|
|
3846
3844
|
}
|
|
3847
3845
|
function useDataTableRenderer({
|
|
@@ -3873,6 +3871,13 @@ function useDataTableRenderer({
|
|
|
3873
3871
|
"You cannot use both `pinnedColumns` and `columnGroupingModel` at the same time. Please choose one of them."
|
|
3874
3872
|
);
|
|
3875
3873
|
}
|
|
3874
|
+
const duplicatedField = useMemo11(() => {
|
|
3875
|
+
const ids = columnsProp.map((column) => sanitizeColumnId(column.field));
|
|
3876
|
+
const index = ids.findIndex((id, i) => ids.indexOf(id) !== i);
|
|
3877
|
+
return index === -1 ? void 0 : columnsProp[index].field;
|
|
3878
|
+
}, [columnsProp]);
|
|
3879
|
+
if (duplicatedField !== void 0)
|
|
3880
|
+
throw new Error(`DataTable: column \`field\` must be unique. Duplicated: "${String(duplicatedField)}"`);
|
|
3876
3881
|
const onSelectionModelChangeRef = useRef7(onSelectionModelChange);
|
|
3877
3882
|
onSelectionModelChangeRef.current = onSelectionModelChange;
|
|
3878
3883
|
const [focusedRowId, setFocusedRowId] = useState9(null);
|
|
@@ -3894,16 +3899,9 @@ function useDataTableRenderer({
|
|
|
3894
3899
|
if (!columnGroupingModel) return columnsProp;
|
|
3895
3900
|
return reorderColumnsByGroupingModel(columnsProp, columnGroupingModel);
|
|
3896
3901
|
}, [columnsProp, columnGroupingModel]);
|
|
3897
|
-
const visibleColumnIndexes = useMemo11(
|
|
3898
|
-
() => reorderedColumns.reduce((acc, col, index) => {
|
|
3899
|
-
if (visibilityModel[col.field] !== false) acc.push(index);
|
|
3900
|
-
return acc;
|
|
3901
|
-
}, []),
|
|
3902
|
-
[reorderedColumns, visibilityModel]
|
|
3903
|
-
);
|
|
3904
3902
|
const visibleColumns = useMemo11(
|
|
3905
|
-
() =>
|
|
3906
|
-
[
|
|
3903
|
+
() => reorderedColumns.filter((col) => visibilityModel[col.field] !== false),
|
|
3904
|
+
[reorderedColumns, visibilityModel]
|
|
3907
3905
|
);
|
|
3908
3906
|
const visibleFieldSet = useMemo11(() => new Set(visibleColumns.map((c) => c.field)), [visibleColumns]);
|
|
3909
3907
|
const tableMinWidth = useMemo11(() => {
|
|
@@ -3924,29 +3922,10 @@ function useDataTableRenderer({
|
|
|
3924
3922
|
),
|
|
3925
3923
|
[reorderedColumns]
|
|
3926
3924
|
);
|
|
3927
|
-
const
|
|
3928
|
-
const taken = new Set(reorderedColumns.map((column) => sanitizeColumnId(column.field)));
|
|
3929
|
-
const assigned = /* @__PURE__ */ new Set();
|
|
3930
|
-
return reorderedColumns.map((column) => {
|
|
3931
|
-
const field = sanitizeColumnId(column.field);
|
|
3932
|
-
if (!assigned.has(field)) {
|
|
3933
|
-
assigned.add(field);
|
|
3934
|
-
return field;
|
|
3935
|
-
}
|
|
3936
|
-
let n = 2;
|
|
3937
|
-
while (taken.has(`${field}__${n}`)) n += 1;
|
|
3938
|
-
taken.add(`${field}__${n}`);
|
|
3939
|
-
return `${field}__${n}`;
|
|
3940
|
-
});
|
|
3941
|
-
}, [reorderedColumns]);
|
|
3942
|
-
const columnIds = useMemo11(
|
|
3943
|
-
() => visibleColumnIndexes.map((index) => allColumnIds[index]),
|
|
3944
|
-
[visibleColumnIndexes, allColumnIds]
|
|
3945
|
-
);
|
|
3946
|
-
const visibleColumnsById = useMemo11(
|
|
3925
|
+
const visibleColumnsByField = useMemo11(
|
|
3947
3926
|
() => Object.fromEntries(
|
|
3948
|
-
visibleColumns.map((column
|
|
3949
|
-
|
|
3927
|
+
visibleColumns.map((column) => [
|
|
3928
|
+
column.field,
|
|
3950
3929
|
{
|
|
3951
3930
|
...column,
|
|
3952
3931
|
headerRef: createRef(),
|
|
@@ -3954,7 +3933,7 @@ function useDataTableRenderer({
|
|
|
3954
3933
|
}
|
|
3955
3934
|
])
|
|
3956
3935
|
),
|
|
3957
|
-
[visibleColumns
|
|
3936
|
+
[visibleColumns]
|
|
3958
3937
|
);
|
|
3959
3938
|
const sortComparator = useCallback12(
|
|
3960
3939
|
(rowA, rowB) => {
|
|
@@ -4047,18 +4026,12 @@ function useDataTableRenderer({
|
|
|
4047
4026
|
() => _isTotalSelected ?? (selectableRowCount > 0 && (selectionModel?.length || 0) === selectableRowCount),
|
|
4048
4027
|
[_isTotalSelected, selectionModel, selectableRowCount]
|
|
4049
4028
|
);
|
|
4050
|
-
const columnWidths = useColumnWidths(
|
|
4051
|
-
const measuredWidthByField = useMemo11(
|
|
4052
|
-
() => Object.fromEntries(
|
|
4053
|
-
Object.entries(visibleColumnsById).map(([columnId, column]) => [column.field, columnWidths[columnId]])
|
|
4054
|
-
),
|
|
4055
|
-
[visibleColumnsById, columnWidths]
|
|
4056
|
-
);
|
|
4029
|
+
const columnWidths = useColumnWidths(visibleColumnsByField);
|
|
4057
4030
|
const getWidth = useCallback12(
|
|
4058
4031
|
// 반환값은 pinned offset으로 더해지므로 반드시 숫자여야 한다. width/minWidth는 '500px' 같은 문자열.
|
|
4059
|
-
(f) =>
|
|
4032
|
+
(f) => columnWidths[f] ?? parsePxValue(allColumnsByField[f]?.width) ?? // Column prop 으로 지정된 width
|
|
4060
4033
|
parsePxValue(allColumnsByField[f]?.minWidth) ?? 0,
|
|
4061
|
-
[
|
|
4034
|
+
[columnWidths, allColumnsByField]
|
|
4062
4035
|
);
|
|
4063
4036
|
const processedColumnGroups = useMemo11(() => {
|
|
4064
4037
|
if (!columnGroupingModel) return null;
|
|
@@ -4078,16 +4051,14 @@ function useDataTableRenderer({
|
|
|
4078
4051
|
const baseColumns = visibleColumns.length > 0 ? visibleColumns : reorderedColumns.length > 0 ? [] : inferredFields.map((key) => ({
|
|
4079
4052
|
field: key
|
|
4080
4053
|
}));
|
|
4081
|
-
return baseColumns.map((column
|
|
4082
|
-
const columnId = columnIds[index] ?? sanitizeColumnId(column.field);
|
|
4054
|
+
return baseColumns.map((column) => {
|
|
4083
4055
|
const isLeftPinned = effectivePinnedLeft?.includes(column.field);
|
|
4084
4056
|
const isRightPinned = effectivePinnedRight?.includes(column.field);
|
|
4085
4057
|
const isPinned = isLeftPinned || isRightPinned;
|
|
4086
4058
|
return {
|
|
4087
4059
|
...column,
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
tableColRef: visibleColumnsById[columnId]?.tableColRef,
|
|
4060
|
+
headerRef: visibleColumnsByField[column.field]?.headerRef,
|
|
4061
|
+
tableColRef: visibleColumnsByField[column.field]?.tableColRef,
|
|
4091
4062
|
isCellEditable: editMode && (typeof column.isCellEditable === "function" ? column.isCellEditable : column.isCellEditable ?? true),
|
|
4092
4063
|
sort: sortModel.find((sort) => sort.field === column.field)?.sort,
|
|
4093
4064
|
sortOrder: allColumnsByField[column.field]?.sortOrder || sortOrder,
|
|
@@ -4104,8 +4075,7 @@ function useDataTableRenderer({
|
|
|
4104
4075
|
inferredFields,
|
|
4105
4076
|
effectivePinnedLeft,
|
|
4106
4077
|
effectivePinnedRight,
|
|
4107
|
-
|
|
4108
|
-
visibleColumnsById,
|
|
4078
|
+
visibleColumnsByField,
|
|
4109
4079
|
allColumnsByField,
|
|
4110
4080
|
editMode,
|
|
4111
4081
|
sortModel,
|
|
@@ -4165,8 +4135,8 @@ function useDataTableRenderer({
|
|
|
4165
4135
|
}
|
|
4166
4136
|
}, [_rows]);
|
|
4167
4137
|
const handleAutoFit = useCallback12(
|
|
4168
|
-
(
|
|
4169
|
-
const colDef =
|
|
4138
|
+
(field) => {
|
|
4139
|
+
const colDef = visibleColumnsByField[field];
|
|
4170
4140
|
if (!colDef?.headerRef.current) return;
|
|
4171
4141
|
const columnType = "type" in colDef ? colDef.type : void 0;
|
|
4172
4142
|
if (columnType === "actions") return;
|
|
@@ -4180,7 +4150,7 @@ function useDataTableRenderer({
|
|
|
4180
4150
|
colDef.headerRef.current.style.width = widthPx;
|
|
4181
4151
|
if (colDef.tableColRef.current) colDef.tableColRef.current.style.width = widthPx;
|
|
4182
4152
|
},
|
|
4183
|
-
[
|
|
4153
|
+
[visibleColumnsByField, dataInPage]
|
|
4184
4154
|
);
|
|
4185
4155
|
return {
|
|
4186
4156
|
rowCount,
|
|
@@ -4867,7 +4837,7 @@ function Component(props, apiRef) {
|
|
|
4867
4837
|
"col",
|
|
4868
4838
|
{
|
|
4869
4839
|
ref: c.tableColRef,
|
|
4870
|
-
key: c.
|
|
4840
|
+
key: c.field.toString(),
|
|
4871
4841
|
style: {
|
|
4872
4842
|
width: c.width,
|
|
4873
4843
|
minWidth: c.minWidth ?? "50px"
|
|
@@ -4923,7 +4893,7 @@ function Component(props, apiRef) {
|
|
|
4923
4893
|
HeadCell2,
|
|
4924
4894
|
{
|
|
4925
4895
|
tableId,
|
|
4926
|
-
key: c.
|
|
4896
|
+
key: c.field.toString(),
|
|
4927
4897
|
stickyHeader: props.stickyHeader,
|
|
4928
4898
|
editMode: !!c.isCellEditable,
|
|
4929
4899
|
onSortChange: handleSortChange,
|