@alaarab/ogrid-core 2.1.13 → 2.1.15

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
@@ -524,23 +524,39 @@ function processClientSideData(data, columns, filters, sortBy, sortDirection) {
524
524
  const trimmed = val.value.trim();
525
525
  if (trimmed) {
526
526
  const lower = trimmed.toLowerCase();
527
- predicates.push((r) => String(getCellValue(r, col) ?? "").toLowerCase().includes(lower));
527
+ const textCache = /* @__PURE__ */ new Map();
528
+ for (let j = 0; j < data.length; j++) {
529
+ textCache.set(data[j], String(getCellValue(data[j], col) ?? "").toLowerCase());
530
+ }
531
+ predicates.push((r) => (textCache.get(r) ?? "").includes(lower));
528
532
  }
529
533
  break;
530
534
  }
531
535
  case "people": {
532
536
  const email = val.value.email.toLowerCase();
533
- predicates.push((r) => String(getCellValue(r, col) ?? "").toLowerCase() === email);
537
+ const peopleCache = /* @__PURE__ */ new Map();
538
+ for (let j = 0; j < data.length; j++) {
539
+ peopleCache.set(data[j], String(getCellValue(data[j], col) ?? "").toLowerCase());
540
+ }
541
+ predicates.push((r) => (peopleCache.get(r) ?? "") === email);
534
542
  break;
535
543
  }
536
544
  case "date": {
537
545
  const dv = val.value;
538
546
  const fromTs = dv.from ? (/* @__PURE__ */ new Date(dv.from + "T00:00:00")).getTime() : NaN;
539
547
  const toTs = dv.to ? (/* @__PURE__ */ new Date(dv.to + "T23:59:59.999")).getTime() : NaN;
548
+ const dateCache = /* @__PURE__ */ new Map();
549
+ for (let j = 0; j < data.length; j++) {
550
+ const cellVal = getCellValue(data[j], col);
551
+ if (cellVal == null) {
552
+ dateCache.set(data[j], NaN);
553
+ } else {
554
+ const t = new Date(String(cellVal)).getTime();
555
+ dateCache.set(data[j], Number.isNaN(t) ? NaN : t);
556
+ }
557
+ }
540
558
  predicates.push((r) => {
541
- const cellVal = getCellValue(r, col);
542
- if (cellVal == null) return false;
543
- const cellTs = new Date(String(cellVal)).getTime();
559
+ const cellTs = dateCache.get(r) ?? NaN;
544
560
  if (Number.isNaN(cellTs)) return false;
545
561
  if (!Number.isNaN(fromTs) && cellTs < fromTs) return false;
546
562
  if (!Number.isNaN(toTs) && cellTs > toTs) return false;
@@ -1058,23 +1074,94 @@ var CELL_PADDING = 16;
1058
1074
  var GRID_BORDER_RADIUS = 6;
1059
1075
 
1060
1076
  // src/utils/columnAutosize.ts
1061
- var AUTOSIZE_EXTRA_PX = 28;
1077
+ var AUTOSIZE_EXTRA_PX = 16;
1062
1078
  var AUTOSIZE_MAX_PX = 520;
1079
+ function measureHeaderWidth(th) {
1080
+ const cs = getComputedStyle(th);
1081
+ const thPadding = (parseFloat(cs.paddingLeft) || 0) + (parseFloat(cs.paddingRight) || 0);
1082
+ let resizeHandleWidth = 0;
1083
+ for (let i = 0; i < th.children.length; i++) {
1084
+ const child = th.children[i];
1085
+ const cls = child.className || "";
1086
+ if (cls.includes("resizeHandle") || cls.includes("resize-handle") || cls.includes("ogrid-resize-handle")) {
1087
+ resizeHandleWidth = child.offsetWidth;
1088
+ break;
1089
+ }
1090
+ }
1091
+ const contentContainer = th.firstElementChild;
1092
+ if (!contentContainer) return th.offsetWidth;
1093
+ const modified = [];
1094
+ const expandDescendants = (parent) => {
1095
+ for (let i = 0; i < parent.children.length; i++) {
1096
+ const child = parent.children[i];
1097
+ const style = getComputedStyle(child);
1098
+ if (style.overflow === "hidden" || style.flexShrink !== "0") {
1099
+ modified.push({
1100
+ el: child,
1101
+ overflow: child.style.overflow,
1102
+ flexShrink: child.style.flexShrink,
1103
+ width: child.style.width,
1104
+ minWidth: child.style.minWidth
1105
+ });
1106
+ child.style.overflow = "visible";
1107
+ child.style.flexShrink = "0";
1108
+ child.style.width = "max-content";
1109
+ child.style.minWidth = "max-content";
1110
+ }
1111
+ expandDescendants(child);
1112
+ }
1113
+ };
1114
+ const origPos = contentContainer.style.position;
1115
+ const origWidth = contentContainer.style.width;
1116
+ contentContainer.style.position = "absolute";
1117
+ contentContainer.style.width = "max-content";
1118
+ expandDescendants(contentContainer);
1119
+ const expandedWidth = contentContainer.offsetWidth;
1120
+ contentContainer.style.position = origPos;
1121
+ contentContainer.style.width = origWidth;
1122
+ for (const m of modified) {
1123
+ m.el.style.overflow = m.overflow;
1124
+ m.el.style.flexShrink = m.flexShrink;
1125
+ m.el.style.width = m.width;
1126
+ m.el.style.minWidth = m.minWidth;
1127
+ }
1128
+ return expandedWidth + resizeHandleWidth + thPadding;
1129
+ }
1063
1130
  function measureColumnContentWidth(columnId, minWidth, container) {
1064
1131
  const minW = minWidth ?? DEFAULT_MIN_COLUMN_WIDTH;
1065
1132
  const root = container ?? document;
1066
1133
  const cells = root.querySelectorAll(`[data-column-id="${columnId}"]`);
1067
1134
  if (cells.length === 0) return minW;
1068
1135
  let maxWidth = minW;
1136
+ const contentEls = [];
1137
+ const origPositions = [];
1138
+ const origWidths = [];
1069
1139
  cells.forEach((cell) => {
1070
1140
  const el = cell;
1071
- const label = el.querySelector?.("[data-header-label]");
1072
- if (label) {
1073
- maxWidth = Math.max(maxWidth, label.scrollWidth + AUTOSIZE_EXTRA_PX);
1141
+ const isHeader = !!el.querySelector?.("[data-header-label]");
1142
+ if (isHeader) {
1143
+ maxWidth = Math.max(maxWidth, measureHeaderWidth(el));
1074
1144
  } else {
1075
- maxWidth = Math.max(maxWidth, el.scrollWidth);
1145
+ const content = el.firstElementChild ?? el;
1146
+ contentEls.push(content);
1076
1147
  }
1077
1148
  });
1149
+ if (contentEls.length > 0) {
1150
+ for (let i = 0; i < contentEls.length; i++) {
1151
+ const el = contentEls[i];
1152
+ origPositions.push(el.style.position);
1153
+ origWidths.push(el.style.width);
1154
+ el.style.position = "absolute";
1155
+ el.style.width = "max-content";
1156
+ }
1157
+ for (let i = 0; i < contentEls.length; i++) {
1158
+ maxWidth = Math.max(maxWidth, contentEls[i].offsetWidth + AUTOSIZE_EXTRA_PX);
1159
+ }
1160
+ for (let i = 0; i < contentEls.length; i++) {
1161
+ contentEls[i].style.position = origPositions[i];
1162
+ contentEls[i].style.width = origWidths[i];
1163
+ }
1164
+ }
1078
1165
  return Math.min(AUTOSIZE_MAX_PX, Math.max(minW, Math.ceil(maxWidth)));
1079
1166
  }
1080
1167
 
@@ -1240,7 +1327,7 @@ function computeRowSelectionState(selectedIds, items, getRowId) {
1240
1327
  if (selectedIds.size === 0 || items.length === 0) {
1241
1328
  return { allSelected: false, someSelected: false };
1242
1329
  }
1243
- const allSelected = items.every((item) => selectedIds.has(getRowId(item)));
1330
+ const allSelected = selectedIds.size >= items.length && items.every((item) => selectedIds.has(getRowId(item)));
1244
1331
  const someSelected = !allSelected && selectedIds.size > 0;
1245
1332
  return { allSelected, someSelected };
1246
1333
  }
@@ -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.15",
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",