@alaarab/ogrid-core 2.1.13 → 2.1.14

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/esm/index.js CHANGED
@@ -1058,23 +1058,94 @@ var CELL_PADDING = 16;
1058
1058
  var GRID_BORDER_RADIUS = 6;
1059
1059
 
1060
1060
  // src/utils/columnAutosize.ts
1061
- var AUTOSIZE_EXTRA_PX = 28;
1061
+ var AUTOSIZE_EXTRA_PX = 16;
1062
1062
  var AUTOSIZE_MAX_PX = 520;
1063
+ function measureHeaderWidth(th) {
1064
+ const cs = getComputedStyle(th);
1065
+ const thPadding = (parseFloat(cs.paddingLeft) || 0) + (parseFloat(cs.paddingRight) || 0);
1066
+ let resizeHandleWidth = 0;
1067
+ for (let i = 0; i < th.children.length; i++) {
1068
+ const child = th.children[i];
1069
+ const cls = child.className || "";
1070
+ if (cls.includes("resizeHandle") || cls.includes("resize-handle") || cls.includes("ogrid-resize-handle")) {
1071
+ resizeHandleWidth = child.offsetWidth;
1072
+ break;
1073
+ }
1074
+ }
1075
+ const contentContainer = th.firstElementChild;
1076
+ if (!contentContainer) return th.offsetWidth;
1077
+ const modified = [];
1078
+ const expandDescendants = (parent) => {
1079
+ for (let i = 0; i < parent.children.length; i++) {
1080
+ const child = parent.children[i];
1081
+ const style = getComputedStyle(child);
1082
+ if (style.overflow === "hidden" || style.flexShrink !== "0") {
1083
+ modified.push({
1084
+ el: child,
1085
+ overflow: child.style.overflow,
1086
+ flexShrink: child.style.flexShrink,
1087
+ width: child.style.width,
1088
+ minWidth: child.style.minWidth
1089
+ });
1090
+ child.style.overflow = "visible";
1091
+ child.style.flexShrink = "0";
1092
+ child.style.width = "max-content";
1093
+ child.style.minWidth = "max-content";
1094
+ }
1095
+ expandDescendants(child);
1096
+ }
1097
+ };
1098
+ const origPos = contentContainer.style.position;
1099
+ const origWidth = contentContainer.style.width;
1100
+ contentContainer.style.position = "absolute";
1101
+ contentContainer.style.width = "max-content";
1102
+ expandDescendants(contentContainer);
1103
+ const expandedWidth = contentContainer.offsetWidth;
1104
+ contentContainer.style.position = origPos;
1105
+ contentContainer.style.width = origWidth;
1106
+ for (const m of modified) {
1107
+ m.el.style.overflow = m.overflow;
1108
+ m.el.style.flexShrink = m.flexShrink;
1109
+ m.el.style.width = m.width;
1110
+ m.el.style.minWidth = m.minWidth;
1111
+ }
1112
+ return expandedWidth + resizeHandleWidth + thPadding;
1113
+ }
1063
1114
  function measureColumnContentWidth(columnId, minWidth, container) {
1064
1115
  const minW = minWidth ?? DEFAULT_MIN_COLUMN_WIDTH;
1065
1116
  const root = container ?? document;
1066
1117
  const cells = root.querySelectorAll(`[data-column-id="${columnId}"]`);
1067
1118
  if (cells.length === 0) return minW;
1068
1119
  let maxWidth = minW;
1120
+ const contentEls = [];
1121
+ const origPositions = [];
1122
+ const origWidths = [];
1069
1123
  cells.forEach((cell) => {
1070
1124
  const el = cell;
1071
- const label = el.querySelector?.("[data-header-label]");
1072
- if (label) {
1073
- maxWidth = Math.max(maxWidth, label.scrollWidth + AUTOSIZE_EXTRA_PX);
1125
+ const isHeader = !!el.querySelector?.("[data-header-label]");
1126
+ if (isHeader) {
1127
+ maxWidth = Math.max(maxWidth, measureHeaderWidth(el));
1074
1128
  } else {
1075
- maxWidth = Math.max(maxWidth, el.scrollWidth);
1129
+ const content = el.firstElementChild ?? el;
1130
+ contentEls.push(content);
1076
1131
  }
1077
1132
  });
1133
+ if (contentEls.length > 0) {
1134
+ for (let i = 0; i < contentEls.length; i++) {
1135
+ const el = contentEls[i];
1136
+ origPositions.push(el.style.position);
1137
+ origWidths.push(el.style.width);
1138
+ el.style.position = "absolute";
1139
+ el.style.width = "max-content";
1140
+ }
1141
+ for (let i = 0; i < contentEls.length; i++) {
1142
+ maxWidth = Math.max(maxWidth, contentEls[i].offsetWidth + AUTOSIZE_EXTRA_PX);
1143
+ }
1144
+ for (let i = 0; i < contentEls.length; i++) {
1145
+ contentEls[i].style.position = origPositions[i];
1146
+ contentEls[i].style.width = origWidths[i];
1147
+ }
1148
+ }
1078
1149
  return Math.min(AUTOSIZE_MAX_PX, Math.max(minW, Math.ceil(maxWidth)));
1079
1150
  }
1080
1151
 
@@ -1,15 +1,16 @@
1
1
  /**
2
2
  * Column autosize DOM measurement utilities shared across all frameworks.
3
3
  */
4
- /** Extra pixels added to header label width to account for filter icon + padding. */
5
- export declare const AUTOSIZE_EXTRA_PX = 28;
4
+ /** Extra pixels added after body content measurement for padding. */
5
+ export declare const AUTOSIZE_EXTRA_PX = 16;
6
6
  /** Maximum column width from autosize. */
7
7
  export declare const AUTOSIZE_MAX_PX = 520;
8
8
  /**
9
9
  * Measure the ideal width for a column by scanning all DOM cells with
10
- * `[data-column-id="<columnId>"]` and computing the maximum scrollWidth.
10
+ * `[data-column-id="<columnId>"]` and computing the maximum content width.
11
11
  *
12
- * Header cells with a `[data-header-label]` child get extra padding for icons.
12
+ * Header cells: temporarily unconstrained to measure true content width.
13
+ * Body cells: measured via `position: absolute; width: max-content`.
13
14
  *
14
15
  * @param columnId - Column to measure
15
16
  * @param minWidth - Minimum width (defaults to DEFAULT_MIN_COLUMN_WIDTH)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alaarab/ogrid-core",
3
- "version": "2.1.13",
3
+ "version": "2.1.14",
4
4
  "description": "OGrid core – framework-agnostic types, algorithms, and utilities for OGrid data grids.",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",