@ceed/ads 1.8.7 → 1.9.0

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.js CHANGED
@@ -1847,7 +1847,8 @@ import React23, {
1847
1847
  useImperativeHandle as useImperativeHandle2,
1848
1848
  createElement,
1849
1849
  memo,
1850
- useLayoutEffect
1850
+ useLayoutEffect,
1851
+ Fragment as Fragment2
1851
1852
  } from "react";
1852
1853
  import { useVirtualizer as useVirtualizer2 } from "@tanstack/react-virtual";
1853
1854
  import { styled as styled12, LinearProgress, Link, useTheme, buttonClasses, iconButtonClasses } from "@mui/joy";
@@ -2618,6 +2619,118 @@ function InfoSign(props) {
2618
2619
  var InfoSign_default = InfoSign;
2619
2620
 
2620
2621
  // src/components/DataTable/DataTable.tsx
2622
+ function extractFieldsFromGroupingModel(items) {
2623
+ const fields = /* @__PURE__ */ new Set();
2624
+ for (const item of items) {
2625
+ if ("groupId" in item) {
2626
+ const children = Array.isArray(item.children) ? item.children : [item.children];
2627
+ const childFields = extractFieldsFromGroupingModel(children);
2628
+ childFields.forEach((field) => fields.add(field));
2629
+ } else {
2630
+ fields.add(item.field);
2631
+ }
2632
+ }
2633
+ return fields;
2634
+ }
2635
+ function reorderColumnsByGroupingModel(columns, columnGroupingModel) {
2636
+ const fieldsInGroupingModel = extractFieldsFromGroupingModel(columnGroupingModel);
2637
+ const orderedFields = [];
2638
+ function collectFieldsInOrder(items) {
2639
+ for (const item of items) {
2640
+ if ("groupId" in item) {
2641
+ const children = Array.isArray(item.children) ? item.children : [item.children];
2642
+ collectFieldsInOrder(children);
2643
+ } else {
2644
+ if (!orderedFields.includes(item.field)) {
2645
+ orderedFields.push(item.field);
2646
+ }
2647
+ }
2648
+ }
2649
+ }
2650
+ collectFieldsInOrder(columnGroupingModel);
2651
+ const columnMap = new Map(columns.map((col) => [col.field, col]));
2652
+ const reorderedColumns = [];
2653
+ for (const field of orderedFields) {
2654
+ const column = columnMap.get(field);
2655
+ if (column) {
2656
+ reorderedColumns.push(column);
2657
+ }
2658
+ }
2659
+ for (const column of columns) {
2660
+ if (!fieldsInGroupingModel.has(column.field)) {
2661
+ reorderedColumns.push(column);
2662
+ }
2663
+ }
2664
+ return reorderedColumns;
2665
+ }
2666
+ function flattenColumnGroups(items, groupPath = [], columnIndex = { current: 0 }) {
2667
+ const result = [];
2668
+ for (const item of items) {
2669
+ if ("groupId" in item) {
2670
+ const newPath = [...groupPath, item.groupId];
2671
+ const children = Array.isArray(item.children) ? item.children : [item.children];
2672
+ result.push(...flattenColumnGroups(children, newPath, columnIndex));
2673
+ } else {
2674
+ result.push({
2675
+ ...item,
2676
+ groupPath,
2677
+ columnIndex: columnIndex.current++
2678
+ });
2679
+ }
2680
+ }
2681
+ return result;
2682
+ }
2683
+ function calculateColumnGroups(columnGroupingModel, columns) {
2684
+ const fieldsInGroupingModel = extractFieldsFromGroupingModel(columnGroupingModel);
2685
+ const flattenedColumns = flattenColumnGroups(columnGroupingModel);
2686
+ const columnIndexMap = new Map(flattenedColumns.map((col) => [col.field, col.columnIndex]));
2687
+ const processedGroups = /* @__PURE__ */ new Map();
2688
+ const groupsByLevel = [];
2689
+ let maxLevel = 0;
2690
+ function processGroup(items, level, parentGroupId) {
2691
+ let minIndex = Infinity;
2692
+ let maxIndex = -Infinity;
2693
+ for (const item of items) {
2694
+ if ("groupId" in item) {
2695
+ const groupKey = parentGroupId ? `${parentGroupId}.${item.groupId}` : item.groupId;
2696
+ if (!processedGroups.has(groupKey)) {
2697
+ const children = Array.isArray(item.children) ? item.children : [item.children];
2698
+ const { startIndex, colspan } = processGroup(children, level + 1, groupKey);
2699
+ const group = {
2700
+ groupId: item.groupId,
2701
+ headerName: item.headerName,
2702
+ colspan,
2703
+ level,
2704
+ startIndex
2705
+ };
2706
+ processedGroups.set(groupKey, group);
2707
+ if (!groupsByLevel[level]) {
2708
+ groupsByLevel[level] = [];
2709
+ }
2710
+ groupsByLevel[level].push(group);
2711
+ maxLevel = Math.max(maxLevel, level);
2712
+ minIndex = Math.min(minIndex, startIndex);
2713
+ maxIndex = Math.max(maxIndex, startIndex + colspan - 1);
2714
+ }
2715
+ } else {
2716
+ const columnIndex = columnIndexMap.get(item.field);
2717
+ if (columnIndex !== void 0) {
2718
+ minIndex = Math.min(minIndex, columnIndex);
2719
+ maxIndex = Math.max(maxIndex, columnIndex);
2720
+ }
2721
+ }
2722
+ }
2723
+ return {
2724
+ startIndex: minIndex === Infinity ? 0 : minIndex,
2725
+ colspan: maxIndex === -Infinity ? 0 : maxIndex - minIndex + 1
2726
+ };
2727
+ }
2728
+ processGroup(columnGroupingModel, 0);
2729
+ groupsByLevel.forEach((level) => {
2730
+ level.sort((a, b) => a.startIndex - b.startIndex);
2731
+ });
2732
+ return { groups: groupsByLevel, maxLevel, fieldsInGroupingModel };
2733
+ }
2621
2734
  function getTextAlign(props) {
2622
2735
  return !props.editMode && ["number", "date", "currency"].includes(props.type || "") ? "end" : "start";
2623
2736
  }
@@ -2688,7 +2801,7 @@ var OverlayWrapper = styled12("tr", {
2688
2801
  }
2689
2802
  });
2690
2803
  var numberFormatter = (value) => "Intl" in window ? new Intl.NumberFormat().format(value) : value;
2691
- var Resizer = (ref) => /* @__PURE__ */ React23.createElement(
2804
+ var Resizer = (ref, targetRef = ref) => /* @__PURE__ */ React23.createElement(
2692
2805
  Box_default,
2693
2806
  {
2694
2807
  sx: {
@@ -2706,6 +2819,7 @@ var Resizer = (ref) => /* @__PURE__ */ React23.createElement(
2706
2819
  const onMouseMove = (e2) => {
2707
2820
  if (initialWidth && initialX) {
2708
2821
  ref.current.style.width = `${initialWidth + (e2.clientX - initialX)}px`;
2822
+ targetRef.current.style.width = `${initialWidth + (e2.clientX - initialX)}px`;
2709
2823
  }
2710
2824
  };
2711
2825
  const onMouseUp = () => {
@@ -2816,17 +2930,19 @@ var HeadCell = (props) => {
2816
2930
  isPinned,
2817
2931
  pinnedStartPosition,
2818
2932
  pinnedEndPosition,
2819
- headerRef
2933
+ headerRef,
2934
+ tableColRef
2820
2935
  } = props;
2821
2936
  const theme = useTheme();
2822
2937
  const ref = headerRef;
2938
+ const colRef = tableColRef;
2823
2939
  const [isHovered, setIsHovered] = useState6(false);
2824
2940
  const sortable = type === "actions" ? false : _sortable;
2825
2941
  const headId = useMemo8(
2826
2942
  () => `${tableId}_header_${headerName ?? field}`.trim(),
2827
2943
  [tableId, headerName, field]
2828
2944
  );
2829
- const resizer = useMemo8(() => resizable ?? true ? Resizer(ref) : null, [resizable, ref]);
2945
+ const resizer = useMemo8(() => resizable ?? true ? Resizer(ref, colRef) : null, [resizable, ref, colRef]);
2830
2946
  const style = useMemo8(
2831
2947
  () => ({
2832
2948
  width,
@@ -3161,8 +3277,15 @@ function useDataTableRenderer({
3161
3277
  editMode,
3162
3278
  getId: _getId,
3163
3279
  isTotalSelected: _isTotalSelected,
3164
- isRowSelectable
3280
+ isRowSelectable,
3281
+ columnGroupingModel
3282
+ // Add this prop
3165
3283
  }) {
3284
+ if (pinnedColumns && columnGroupingModel) {
3285
+ throw new Error(
3286
+ "You cannot use both `pinnedColumns` and `columnGroupingModel` at the same time. Please choose one of them."
3287
+ );
3288
+ }
3166
3289
  const onSelectionModelChangeRef = useRef4(onSelectionModelChange);
3167
3290
  onSelectionModelChangeRef.current = onSelectionModelChange;
3168
3291
  const [focusedRowId, setFocusedRowId] = useState6(null);
@@ -3171,18 +3294,23 @@ function useDataTableRenderer({
3171
3294
  initialState?.sorting?.sortModel ?? [],
3172
3295
  useCallback9((sortModel2) => onSortModelChange?.(sortModel2), [onSortModelChange])
3173
3296
  );
3297
+ const reorderedColumns = useMemo8(() => {
3298
+ if (!columnGroupingModel) return columnsProp;
3299
+ return reorderColumnsByGroupingModel(columnsProp, columnGroupingModel);
3300
+ }, [columnsProp, columnGroupingModel]);
3174
3301
  const columnsByField = useMemo8(
3175
- () => columnsProp.reduce(
3302
+ () => reorderedColumns.reduce(
3176
3303
  (acc, curr) => ({
3177
3304
  ...acc,
3178
3305
  [curr.field]: {
3179
3306
  ...curr,
3180
- headerRef: React23.createRef()
3307
+ headerRef: React23.createRef(),
3308
+ tableColRef: React23.createRef()
3181
3309
  }
3182
3310
  }),
3183
3311
  {}
3184
3312
  ),
3185
- [columnsProp]
3313
+ [reorderedColumns]
3186
3314
  );
3187
3315
  const sortComparator = useCallback9(
3188
3316
  (rowA, rowB) => {
@@ -3262,11 +3390,17 @@ function useDataTableRenderer({
3262
3390
  columnsByField[f].minWidth ?? 0,
3263
3391
  [columnWidths, columnsByField]
3264
3392
  );
3393
+ const processedColumnGroups = useMemo8(() => {
3394
+ if (!columnGroupingModel) return null;
3395
+ return calculateColumnGroups(columnGroupingModel, reorderedColumns);
3396
+ }, [columnGroupingModel, reorderedColumns]);
3265
3397
  const columns = useMemo8(() => {
3266
- const baseColumns = columnsProp || // fallback
3267
- Object.keys(rows[0] || {}).map((key) => ({
3268
- field: key
3269
- }));
3398
+ const baseColumns = reorderedColumns.length > 0 ? reorderedColumns : (
3399
+ // fallback
3400
+ Object.keys(rows[0] || {}).map((key) => ({
3401
+ field: key
3402
+ }))
3403
+ );
3270
3404
  return baseColumns.map((column) => {
3271
3405
  const isLeftPinned = pinnedColumns?.left?.includes(column.field);
3272
3406
  const isRightPinned = pinnedColumns?.right?.includes(column.field);
@@ -3274,6 +3408,7 @@ function useDataTableRenderer({
3274
3408
  return {
3275
3409
  ...column,
3276
3410
  headerRef: columnsByField[column.field].headerRef,
3411
+ tableColRef: columnsByField[column.field].tableColRef,
3277
3412
  isCellEditable: editMode && (typeof column.isCellEditable === "function" ? column.isCellEditable : column.isCellEditable ?? true),
3278
3413
  sort: sortModel.find((sort) => sort.field === column.field)?.sort,
3279
3414
  sortOrder: columnsByField[column.field]?.sortOrder || sortOrder,
@@ -3286,7 +3421,7 @@ function useDataTableRenderer({
3286
3421
  };
3287
3422
  });
3288
3423
  }, [
3289
- columnsProp,
3424
+ reorderedColumns,
3290
3425
  rows,
3291
3426
  pinnedColumns?.left,
3292
3427
  pinnedColumns?.right,
@@ -3382,6 +3517,7 @@ function useDataTableRenderer({
3382
3517
  [selectionModel, onSelectionModelChange, selectedModelSet]
3383
3518
  ),
3384
3519
  columns,
3520
+ processedColumnGroups,
3385
3521
  onTotalSelect: useCallback9(() => {
3386
3522
  const selectableRows = rows.filter((row, i) => {
3387
3523
  if (!isRowSelectable) return true;
@@ -3424,6 +3560,8 @@ function Component(props, apiRef) {
3424
3560
  getId: ____________,
3425
3561
  // getId is used in useDataTableRenderer
3426
3562
  loading,
3563
+ columnGroupingModel: _________________,
3564
+ // columnGroupingModel is used in useDataTableRenderer
3427
3565
  slots: {
3428
3566
  checkbox: RenderCheckbox = Checkbox_default,
3429
3567
  toolbar: Toolbar,
@@ -3440,6 +3578,7 @@ function Component(props, apiRef) {
3440
3578
  const tableBodyRef = useRef4(null);
3441
3579
  const {
3442
3580
  columns,
3581
+ processedColumnGroups,
3443
3582
  isAllSelected,
3444
3583
  isSelectedRow,
3445
3584
  isRowSelectable: isRowSelectableCheck,
@@ -3547,7 +3686,8 @@ function Component(props, apiRef) {
3547
3686
  boxShadow: "sm",
3548
3687
  borderRadius: "sm",
3549
3688
  "--DataTableSheet-width": parentRef.current?.clientWidth + "px",
3550
- backgroundColor: "white"
3689
+ backgroundColor: "white",
3690
+ "--TableCell-cornerRadius": "0px"
3551
3691
  },
3552
3692
  className: [
3553
3693
  ...(parentRef.current?.scrollLeft || 0) > 0 ? ["ScrollableRight"] : [],
@@ -3556,12 +3696,30 @@ function Component(props, apiRef) {
3556
3696
  ref: parentRef,
3557
3697
  ...backgroundProps
3558
3698
  },
3559
- /* @__PURE__ */ React23.createElement(Table, { ...innerProps }, /* @__PURE__ */ React23.createElement("thead", null, /* @__PURE__ */ React23.createElement("tr", null, checkboxSelection && /* @__PURE__ */ React23.createElement(
3699
+ /* @__PURE__ */ React23.createElement(Table, { ...innerProps }, /* @__PURE__ */ React23.createElement("colgroup", null, checkboxSelection && /* @__PURE__ */ React23.createElement(
3700
+ "col",
3701
+ {
3702
+ style: {
3703
+ width: "40px"
3704
+ }
3705
+ }
3706
+ ), columns.map((c) => /* @__PURE__ */ React23.createElement(
3707
+ "col",
3708
+ {
3709
+ ref: c.tableColRef,
3710
+ key: `${c.field.toString()}_${c.width}`,
3711
+ style: {
3712
+ width: c.width
3713
+ }
3714
+ }
3715
+ ))), /* @__PURE__ */ React23.createElement("thead", null, processedColumnGroups && processedColumnGroups.groups.map((levelGroups, level) => /* @__PURE__ */ React23.createElement("tr", { key: `group-level-${level}` }, checkboxSelection && level === 0 && /* @__PURE__ */ React23.createElement(
3560
3716
  "th",
3561
3717
  {
3718
+ rowSpan: processedColumnGroups.maxLevel + 2,
3562
3719
  style: {
3563
3720
  width: "40px",
3564
- textAlign: "center"
3721
+ textAlign: "center",
3722
+ verticalAlign: "middle"
3565
3723
  }
3566
3724
  },
3567
3725
  /* @__PURE__ */ React23.createElement(
@@ -3574,16 +3732,52 @@ function Component(props, apiRef) {
3574
3732
  ...checkboxProps
3575
3733
  }
3576
3734
  )
3577
- ), columns.map((c, i) => /* @__PURE__ */ React23.createElement(
3578
- HeadCell2,
3735
+ ), level > 0 && Array.from({ length: levelGroups[0]?.startIndex || 0 }).map((_2, i) => /* @__PURE__ */ React23.createElement("th", { key: `empty-${level}-${i}` })), levelGroups.map((group, groupIndex) => {
3736
+ const nextGroup = levelGroups[groupIndex + 1];
3737
+ const emptyCells = nextGroup ? nextGroup.startIndex - (group.startIndex + group.colspan) : columns.length - (group.startIndex + group.colspan);
3738
+ return /* @__PURE__ */ React23.createElement(Fragment2, { key: group.groupId }, /* @__PURE__ */ React23.createElement(
3739
+ "th",
3740
+ {
3741
+ colSpan: group.colspan,
3742
+ style: {
3743
+ textAlign: "center",
3744
+ fontWeight: "bold",
3745
+ verticalAlign: "middle"
3746
+ }
3747
+ },
3748
+ group.headerName ?? group.groupId
3749
+ ), emptyCells > 0 && Array.from({ length: emptyCells }).map((_2, i) => /* @__PURE__ */ React23.createElement("th", { key: `empty-between-${level}-${groupIndex}-${i}`, colSpan: 1 })));
3750
+ }))), /* @__PURE__ */ React23.createElement("tr", null, !processedColumnGroups && checkboxSelection && /* @__PURE__ */ React23.createElement(
3751
+ "th",
3579
3752
  {
3580
- tableId,
3581
- key: `${c.field.toString()}_${i}`,
3582
- stickyHeader: props.stickyHeader,
3583
- editMode: !!c.isCellEditable,
3584
- onSortChange: handleSortChange,
3585
- ...c
3586
- }
3753
+ style: {
3754
+ width: "40px",
3755
+ textAlign: "center"
3756
+ }
3757
+ },
3758
+ /* @__PURE__ */ React23.createElement(
3759
+ RenderCheckbox,
3760
+ {
3761
+ onChange: onAllCheckboxChange,
3762
+ checked: isAllSelected,
3763
+ indeterminate: (selectionModel || []).length > 0 && !isAllSelected,
3764
+ disabled: dataInPage.length > 0 && !selectableRowCount,
3765
+ ...checkboxProps
3766
+ }
3767
+ )
3768
+ ), columns.map((c, i) => (
3769
+ // @ts-ignore
3770
+ /* @__PURE__ */ React23.createElement(
3771
+ HeadCell2,
3772
+ {
3773
+ tableId,
3774
+ key: `${c.field.toString()}_${i}`,
3775
+ stickyHeader: props.stickyHeader,
3776
+ editMode: !!c.isCellEditable,
3777
+ onSortChange: handleSortChange,
3778
+ ...c
3779
+ }
3780
+ )
3587
3781
  )))), /* @__PURE__ */ React23.createElement(
3588
3782
  VirtualizedTableBody,
3589
3783
  {