@ceed/ads 1.41.3-next.6 → 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/index.cjs CHANGED
@@ -458,16 +458,25 @@ function useSlotRef(slotProp, ref) {
458
458
  const isFunctionForm = typeof slotProp === "function";
459
459
  const slotRef = isFunctionForm ? void 0 : slotProp?.ref;
460
460
  const mergedRef = useMergedRef(slotRef, ref);
461
+ const latestSlotRef = (0, import_react6.useRef)(null);
462
+ const stableMergedRef = (0, import_react6.useCallback)(
463
+ (value) => {
464
+ assignRef(latestSlotRef.current, value);
465
+ assignRef(ref, value);
466
+ },
467
+ [ref]
468
+ );
461
469
  return (0, import_react6.useMemo)(() => {
462
470
  if (isFunctionForm) {
463
471
  return ((ownerState) => {
464
472
  const resolved = slotProp(ownerState) ?? {};
465
- const merged = mergeRefs(resolved.ref, ref);
466
- return merged ? { ...resolved, ref: merged } : { ...resolved };
473
+ const resolvedRef = resolved.ref;
474
+ latestSlotRef.current = resolvedRef ?? null;
475
+ return resolvedRef || ref ? { ...resolved, ref: stableMergedRef } : { ...resolved };
467
476
  });
468
477
  }
469
478
  return mergedRef ? { ...slotProp, ref: mergedRef } : { ...slotProp };
470
- }, [isFunctionForm, slotProp, mergedRef, ref]);
479
+ }, [isFunctionForm, slotProp, mergedRef, ref, stableMergedRef]);
471
480
  }
472
481
 
473
482
  // src/components/Autocomplete/Autocomplete.tsx
@@ -2609,8 +2618,11 @@ function computeAutoFitWidth(params) {
2609
2618
  if (!isNaN(maxPx) && maxPx > 0) finalWidth = Math.min(finalWidth, maxPx);
2610
2619
  return finalWidth;
2611
2620
  }
2612
- function getHeaderCellId(tableId, columnId) {
2613
- return `${tableId}_header_${columnId}`.trim().replace(/\s+/g, "_");
2621
+ function getHeaderCellId(tableId, field) {
2622
+ return `${tableId}_header_${sanitizeColumnId(field)}`;
2623
+ }
2624
+ function sanitizeColumnId(field) {
2625
+ return String(field).trim().replace(/\s+/g, "_");
2614
2626
  }
2615
2627
 
2616
2628
  // src/components/DataTable/styled.tsx
@@ -3555,8 +3567,7 @@ var HeadCell = (props) => {
3555
3567
  tableColRef,
3556
3568
  headerClassName,
3557
3569
  headerLineClamp,
3558
- onAutoFit,
3559
- columnId
3570
+ onAutoFit
3560
3571
  } = props;
3561
3572
  const theme = (0, import_joy33.useTheme)();
3562
3573
  const ref = headerRef;
@@ -3567,7 +3578,7 @@ var HeadCell = (props) => {
3567
3578
  }, [ref]);
3568
3579
  const [isHovered, setIsHovered] = (0, import_react26.useState)(false);
3569
3580
  const sortable = type === "actions" ? false : _sortable;
3570
- const headId = (0, import_react26.useMemo)(() => getHeaderCellId(tableId, columnId), [tableId, columnId]);
3581
+ const headId = (0, import_react26.useMemo)(() => getHeaderCellId(tableId, field), [tableId, field]);
3571
3582
  const isResizingRef = (0, import_react26.useRef)(false);
3572
3583
  const resizer = (0, import_react26.useMemo)(
3573
3584
  () => resizable ?? true ? Resizer(
@@ -3576,9 +3587,9 @@ var HeadCell = (props) => {
3576
3587
  (isResizing) => {
3577
3588
  isResizingRef.current = isResizing;
3578
3589
  },
3579
- onAutoFit ? () => onAutoFit(columnId) : void 0
3590
+ onAutoFit ? () => onAutoFit(field) : void 0
3580
3591
  ) : null,
3581
- [resizable, ref, colRef, onAutoFit, columnId]
3592
+ [resizable, ref, colRef, onAutoFit, field]
3582
3593
  );
3583
3594
  const style = (0, import_react26.useMemo)(
3584
3595
  () => ({
@@ -3848,7 +3859,7 @@ var BodyCell = (props) => {
3848
3859
  {
3849
3860
  ref: cellRef,
3850
3861
  key: field,
3851
- headers: getHeaderCellId(tableId, props.columnId),
3862
+ headers: getHeaderCellId(tableId, field),
3852
3863
  sx: {
3853
3864
  textAlign: getTextAlign({ type }),
3854
3865
  verticalAlign: editMode ? "top" : "middle",
@@ -3914,7 +3925,7 @@ var VirtualizedTableRow = (0, import_react26.memo)(StyledTableRow2, (prevProps,
3914
3925
 
3915
3926
  // src/components/DataTable/hooks.ts
3916
3927
  var import_react27 = require("react");
3917
- function useColumnWidths(columnsById) {
3928
+ function useColumnWidths(columnsByField) {
3918
3929
  const [widths, setWidths] = (0, import_react27.useState)({});
3919
3930
  const roRef = (0, import_react27.useRef)();
3920
3931
  (0, import_react27.useLayoutEffect)(() => {
@@ -3924,11 +3935,11 @@ function useColumnWidths(columnsById) {
3924
3935
  let changed = false;
3925
3936
  const next = { ...prev };
3926
3937
  entries.forEach((entry) => {
3927
- const columnId = entry.target.dataset.hdsColumnId;
3938
+ const field = entry.target.dataset.field;
3928
3939
  const w = Math.round(entry.target.getBoundingClientRect().width);
3929
3940
  if (w === 0) return;
3930
- if (next[columnId] !== w) {
3931
- next[columnId] = w;
3941
+ if (next[field] !== w) {
3942
+ next[field] = w;
3932
3943
  changed = true;
3933
3944
  }
3934
3945
  });
@@ -3936,23 +3947,22 @@ function useColumnWidths(columnsById) {
3936
3947
  });
3937
3948
  });
3938
3949
  const measured = {};
3939
- Object.entries(columnsById).forEach(([columnId, def]) => {
3950
+ Object.entries(columnsByField).forEach(([field, def]) => {
3940
3951
  const el = def.headerRef.current;
3941
3952
  if (el) {
3942
- el.dataset.hdsColumnId = columnId;
3943
- el.dataset.field = String(def.field);
3953
+ el.dataset.field = field;
3944
3954
  const w = Math.round(el.getBoundingClientRect().width);
3945
- if (w > 0) measured[columnId] = w;
3955
+ if (w > 0) measured[field] = w;
3946
3956
  roRef.current.observe(el);
3947
3957
  }
3948
3958
  });
3949
3959
  setWidths((prev) => {
3950
3960
  const keys = Object.keys(measured);
3951
- const same = keys.length === Object.keys(prev).length && keys.every((key) => prev[key] === measured[key]);
3952
- return same ? prev : measured;
3961
+ const same = keys.every((key) => prev[key] === measured[key]);
3962
+ return same ? prev : { ...prev, ...measured };
3953
3963
  });
3954
3964
  return () => roRef.current?.disconnect();
3955
- }, [columnsById]);
3965
+ }, [columnsByField]);
3956
3966
  return widths;
3957
3967
  }
3958
3968
  function useDataTableRenderer({
@@ -3984,6 +3994,13 @@ function useDataTableRenderer({
3984
3994
  "You cannot use both `pinnedColumns` and `columnGroupingModel` at the same time. Please choose one of them."
3985
3995
  );
3986
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)}"`);
3987
4004
  const onSelectionModelChangeRef = (0, import_react27.useRef)(onSelectionModelChange);
3988
4005
  onSelectionModelChangeRef.current = onSelectionModelChange;
3989
4006
  const [focusedRowId, setFocusedRowId] = (0, import_react27.useState)(null);
@@ -4005,16 +4022,9 @@ function useDataTableRenderer({
4005
4022
  if (!columnGroupingModel) return columnsProp;
4006
4023
  return reorderColumnsByGroupingModel(columnsProp, columnGroupingModel);
4007
4024
  }, [columnsProp, columnGroupingModel]);
4008
- const visibleColumnIndexes = (0, import_react27.useMemo)(
4009
- () => reorderedColumns.reduce((acc, col, index) => {
4010
- if (visibilityModel[col.field] !== false) acc.push(index);
4011
- return acc;
4012
- }, []),
4013
- [reorderedColumns, visibilityModel]
4014
- );
4015
4025
  const visibleColumns = (0, import_react27.useMemo)(
4016
- () => visibleColumnIndexes.map((index) => reorderedColumns[index]),
4017
- [visibleColumnIndexes, reorderedColumns]
4026
+ () => reorderedColumns.filter((col) => visibilityModel[col.field] !== false),
4027
+ [reorderedColumns, visibilityModel]
4018
4028
  );
4019
4029
  const visibleFieldSet = (0, import_react27.useMemo)(() => new Set(visibleColumns.map((c) => c.field)), [visibleColumns]);
4020
4030
  const tableMinWidth = (0, import_react27.useMemo)(() => {
@@ -4035,29 +4045,10 @@ function useDataTableRenderer({
4035
4045
  ),
4036
4046
  [reorderedColumns]
4037
4047
  );
4038
- const allColumnIds = (0, import_react27.useMemo)(() => {
4039
- const taken = new Set(reorderedColumns.map((column) => String(column.field)));
4040
- const assigned = /* @__PURE__ */ new Set();
4041
- return reorderedColumns.map((column) => {
4042
- const field = String(column.field);
4043
- if (!assigned.has(field)) {
4044
- assigned.add(field);
4045
- return field;
4046
- }
4047
- let n = 2;
4048
- while (taken.has(`${field}__${n}`)) n += 1;
4049
- taken.add(`${field}__${n}`);
4050
- return `${field}__${n}`;
4051
- });
4052
- }, [reorderedColumns]);
4053
- const columnIds = (0, import_react27.useMemo)(
4054
- () => visibleColumnIndexes.map((index) => allColumnIds[index]),
4055
- [visibleColumnIndexes, allColumnIds]
4056
- );
4057
- const visibleColumnsById = (0, import_react27.useMemo)(
4048
+ const visibleColumnsByField = (0, import_react27.useMemo)(
4058
4049
  () => Object.fromEntries(
4059
- visibleColumns.map((column, index) => [
4060
- columnIds[index],
4050
+ visibleColumns.map((column) => [
4051
+ column.field,
4061
4052
  {
4062
4053
  ...column,
4063
4054
  headerRef: (0, import_react27.createRef)(),
@@ -4065,7 +4056,7 @@ function useDataTableRenderer({
4065
4056
  }
4066
4057
  ])
4067
4058
  ),
4068
- [visibleColumns, columnIds]
4059
+ [visibleColumns]
4069
4060
  );
4070
4061
  const sortComparator = (0, import_react27.useCallback)(
4071
4062
  (rowA, rowB) => {
@@ -4158,18 +4149,12 @@ function useDataTableRenderer({
4158
4149
  () => _isTotalSelected ?? (selectableRowCount > 0 && (selectionModel?.length || 0) === selectableRowCount),
4159
4150
  [_isTotalSelected, selectionModel, selectableRowCount]
4160
4151
  );
4161
- const columnWidths = useColumnWidths(visibleColumnsById);
4162
- const measuredWidthByField = (0, import_react27.useMemo)(
4163
- () => Object.fromEntries(
4164
- Object.entries(visibleColumnsById).map(([columnId, column]) => [column.field, columnWidths[columnId]])
4165
- ),
4166
- [visibleColumnsById, columnWidths]
4167
- );
4152
+ const columnWidths = useColumnWidths(visibleColumnsByField);
4168
4153
  const getWidth = (0, import_react27.useCallback)(
4169
4154
  // 반환값은 pinned offset으로 더해지므로 반드시 숫자여야 한다. width/minWidth는 '500px' 같은 문자열.
4170
- (f) => measuredWidthByField[f] ?? parsePxValue(allColumnsByField[f]?.width) ?? // Column prop 으로 지정된 width
4155
+ (f) => columnWidths[f] ?? parsePxValue(allColumnsByField[f]?.width) ?? // Column prop 으로 지정된 width
4171
4156
  parsePxValue(allColumnsByField[f]?.minWidth) ?? 0,
4172
- [measuredWidthByField, allColumnsByField]
4157
+ [columnWidths, allColumnsByField]
4173
4158
  );
4174
4159
  const processedColumnGroups = (0, import_react27.useMemo)(() => {
4175
4160
  if (!columnGroupingModel) return null;
@@ -4189,16 +4174,14 @@ function useDataTableRenderer({
4189
4174
  const baseColumns = visibleColumns.length > 0 ? visibleColumns : reorderedColumns.length > 0 ? [] : inferredFields.map((key) => ({
4190
4175
  field: key
4191
4176
  }));
4192
- return baseColumns.map((column, index) => {
4193
- const columnId = columnIds[index] ?? String(column.field);
4177
+ return baseColumns.map((column) => {
4194
4178
  const isLeftPinned = effectivePinnedLeft?.includes(column.field);
4195
4179
  const isRightPinned = effectivePinnedRight?.includes(column.field);
4196
4180
  const isPinned = isLeftPinned || isRightPinned;
4197
4181
  return {
4198
4182
  ...column,
4199
- columnId,
4200
- headerRef: visibleColumnsById[columnId]?.headerRef,
4201
- tableColRef: visibleColumnsById[columnId]?.tableColRef,
4183
+ headerRef: visibleColumnsByField[column.field]?.headerRef,
4184
+ tableColRef: visibleColumnsByField[column.field]?.tableColRef,
4202
4185
  isCellEditable: editMode && (typeof column.isCellEditable === "function" ? column.isCellEditable : column.isCellEditable ?? true),
4203
4186
  sort: sortModel.find((sort) => sort.field === column.field)?.sort,
4204
4187
  sortOrder: allColumnsByField[column.field]?.sortOrder || sortOrder,
@@ -4215,8 +4198,7 @@ function useDataTableRenderer({
4215
4198
  inferredFields,
4216
4199
  effectivePinnedLeft,
4217
4200
  effectivePinnedRight,
4218
- columnIds,
4219
- visibleColumnsById,
4201
+ visibleColumnsByField,
4220
4202
  allColumnsByField,
4221
4203
  editMode,
4222
4204
  sortModel,
@@ -4276,8 +4258,8 @@ function useDataTableRenderer({
4276
4258
  }
4277
4259
  }, [_rows]);
4278
4260
  const handleAutoFit = (0, import_react27.useCallback)(
4279
- (columnId) => {
4280
- const colDef = visibleColumnsById[columnId];
4261
+ (field) => {
4262
+ const colDef = visibleColumnsByField[field];
4281
4263
  if (!colDef?.headerRef.current) return;
4282
4264
  const columnType = "type" in colDef ? colDef.type : void 0;
4283
4265
  if (columnType === "actions") return;
@@ -4291,7 +4273,7 @@ function useDataTableRenderer({
4291
4273
  colDef.headerRef.current.style.width = widthPx;
4292
4274
  if (colDef.tableColRef.current) colDef.tableColRef.current.style.width = widthPx;
4293
4275
  },
4294
- [visibleColumnsById, dataInPage]
4276
+ [visibleColumnsByField, dataInPage]
4295
4277
  );
4296
4278
  return {
4297
4279
  rowCount,
@@ -4978,7 +4960,7 @@ function Component(props, apiRef) {
4978
4960
  "col",
4979
4961
  {
4980
4962
  ref: c.tableColRef,
4981
- key: c.columnId,
4963
+ key: c.field.toString(),
4982
4964
  style: {
4983
4965
  width: c.width,
4984
4966
  minWidth: c.minWidth ?? "50px"
@@ -5028,13 +5010,13 @@ function Component(props, apiRef) {
5028
5010
  }
5029
5011
  },
5030
5012
  headerCheckboxElement
5031
- ), columns.map((c, i) => (
5013
+ ), columns.map((c) => (
5032
5014
  // @ts-ignore
5033
5015
  /* @__PURE__ */ import_react30.default.createElement(
5034
5016
  HeadCell2,
5035
5017
  {
5036
5018
  tableId,
5037
- key: `${c.field.toString()}_${i}`,
5019
+ key: c.field.toString(),
5038
5020
  stickyHeader: props.stickyHeader,
5039
5021
  editMode: !!c.isCellEditable,
5040
5022
  onSortChange: handleSortChange,