@xeplr/ui-table 1.1.6 → 1.1.7

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/README.md CHANGED
@@ -253,6 +253,7 @@ The scrollbar, the scroll position and the layout are the full table's. Scrollin
253
253
  - Everything fits → each column gets its natural width; leftover space stays empty.
254
254
  - It does not fit → no empty space; every column drops to its floor (its longest word) and the remainder is shared in proportion to what each wanted.
255
255
  - Not even the floors fit → floors, and the table scrolls horizontally.
256
+ - **A header never breaks mid-word for want of a pixel.** Its room is its text plus everything else on its line, read off the real cells: the header cell's padding, the `<th>`'s own padding and borders, the gap, and the filter trigger (`headerChrome`). A sorted column is measured with its arrow (`sortedHeaderText`), and re-measured when the sort moves. Why: leaving the `<th>`'s 1px border out made every column 1px short of its header, so "Orders" broke as "Order / s".
256
257
 
257
258
  `columnWidths: { [leafIndex]: percent }` pins columns to a share of the width the columns divide (after checkbox, expand and actions columns). **By index**, because a pivot's column keys are data and change on refresh. `columnText(row, column)` supplies the displayed text when cells are formatted; `sizingKey` forces a re-measure (a font change cannot be observed); `onColumnSizing` receives each column's natural width, floor, assigned width and reason (`natural`, `shrunk`, `floor`, `pinned`).
258
259
 
@@ -291,7 +292,7 @@ There is no margin property: a `<td>` ignores margin.
291
292
 
292
293
  ## Exports
293
294
 
294
- `XeplrTable`, `CHILD_DISPLAY`, `useTableController`, `useActionsController`, `detectTypes`, `TYPES`, `StringFilter` / `stringFilterFn`, `NumberFilter` / `numberFilterFn`, `DateFilter` / `dateFilterFn`, `BooleanFilter` / `booleanFilterFn`, `FilterWrapper`, `ActionsCell`, `RecordModal`, `RecordDetail`, `ChildTable`, `CellZoom`, `buildChangeSet`, `resolveOperator`, `resolveString`, `resolveNumber`, `resolveDate`, `isNullish`, `resolveCellStyle`, `STYLE_GROUPS`, `STYLE_FIELDS`, `BORDER_SIDES`, `styleField`, `cssLength`, `flattenStyle`, `resolveStyle`, `toCssProperties`, `resolveCellCss`, `useColumnWidths`, `measureColumnDemand`, `allocateColumnWidths`, `resolvePercentWidths`, `longestToken`, `WIDTH_NATURAL`, `WIDTH_SHRUNK`, `WIDTH_FLOOR`, `renderers`, `avatarName`, `tags`, `currency`, `memberChips`, `twoLine`, `statusBadge`, `dateDisplay`, `link`.
295
+ `XeplrTable`, `CHILD_DISPLAY`, `useTableController`, `useActionsController`, `detectTypes`, `TYPES`, `StringFilter` / `stringFilterFn`, `NumberFilter` / `numberFilterFn`, `DateFilter` / `dateFilterFn`, `BooleanFilter` / `booleanFilterFn`, `FilterWrapper`, `ActionsCell`, `RecordModal`, `RecordDetail`, `ChildTable`, `CellZoom`, `buildChangeSet`, `resolveOperator`, `resolveString`, `resolveNumber`, `resolveDate`, `isNullish`, `resolveCellStyle`, `STYLE_GROUPS`, `STYLE_FIELDS`, `BORDER_SIDES`, `styleField`, `cssLength`, `flattenStyle`, `resolveStyle`, `toCssProperties`, `resolveCellCss`, `useColumnWidths`, `measureColumnDemand`, `allocateColumnWidths`, `resolvePercentWidths`, `longestToken`, `headerChrome`, `sortedHeaderText`, `WIDTH_NATURAL`, `WIDTH_SHRUNK`, `WIDTH_FLOOR`, `renderers`, `avatarName`, `tags`, `currency`, `memberChips`, `twoLine`, `statusBadge`, `dateDisplay`, `link`.
295
296
 
296
297
  ## Tests
297
298
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/ui-table",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "Controlled TanStack Table wrapper with auto-detected column types and smart filters",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -239,7 +239,14 @@ export default function XeplrTable(props) {
239
239
  // Content sizing measures the whole dataset's first N rows, not the current
240
240
  // page — otherwise every page turn would re-measure and the columns would
241
241
  // visibly jump.
242
+ // The columns whose header shows a sort arrow, by accessor: their header
243
+ // needs the arrow's room too, or "Revenue ▼" wraps its arrow.
244
+ var sortedAccessors = (table.getState().sorting || []).map(function(entry) {
245
+ var column = table.getColumn(entry.id);
246
+ return column && column.columnDef.accessorKey;
247
+ }).filter(Boolean);
242
248
  var widths = useColumnWidths({
249
+ sortedColumns: sortedAccessors,
243
250
  enabled: props.columnSizing === 'content',
244
251
  data: props.data,
245
252
  columns: columns,
@@ -99,6 +99,43 @@ function pinnedWidth(overrides, index) {
99
99
  return Math.ceil(width);
100
100
  }
101
101
 
102
+ /**
103
+ * The room a header's label does NOT get — everything else on its line.
104
+ *
105
+ * Every part counts, read off the real cells: the header cell's padding, the
106
+ * <th>'s own padding and borders (its 1px divider sits inside the column's
107
+ * width), the gap between the label and the filter trigger, and the trigger.
108
+ * Leaving the <th> border out made each column exactly 1px short of its
109
+ * header, so "Orders" broke as "Order / s".
110
+ *
111
+ * @param {object} box
112
+ * @param {number} box.cell - header cell padding + borders
113
+ * @param {number} box.th - the <th>'s padding + borders
114
+ * @param {number} box.gap - gap between the label and the trigger
115
+ * @param {number|null} box.trigger - the filter trigger's width; null when
116
+ * the table has none, and the sort caret's room is kept instead
117
+ */
118
+ export function headerChrome(box) {
119
+ var fixed = (box.cell || 0) + (box.th || 0);
120
+ if (box.trigger === null || box.trigger === undefined) return fixed + SORT_CARET_ROOM;
121
+ return fixed + (box.gap || 0) + box.trigger;
122
+ }
123
+
124
+ /** Room for the sort caret on a table without filter triggers. */
125
+ export var SORT_CARET_ROOM = 16;
126
+
127
+ /** The arrow a sorted column's header shows (XeplrTable's sort icon). */
128
+ export var SORT_ARROW = ' \u25BC';
129
+
130
+ /**
131
+ * A header's text as it is drawn: a sorted column's carries its arrow, so its
132
+ * width is measured with it — without, "Revenue ▼" wrapped its arrow.
133
+ */
134
+ export function sortedHeaderText(column, sortedColumns) {
135
+ var text = headerTextOf(column);
136
+ return column && sortedColumns && sortedColumns.indexOf(column.accessor) !== -1 ? text + SORT_ARROW : text;
137
+ }
138
+
102
139
  /**
103
140
  * The longest run of characters with no break opportunity in it.
104
141
  *
package/src/index.js CHANGED
@@ -41,7 +41,7 @@ export {
41
41
  // Content-based column widths
42
42
  export { default as useColumnWidths } from './useColumnWidths.js';
43
43
  export {
44
- measureColumnDemand, allocateColumnWidths, resolvePercentWidths, longestToken,
44
+ measureColumnDemand, allocateColumnWidths, resolvePercentWidths, longestToken, headerChrome, sortedHeaderText,
45
45
  WIDTH_NATURAL, WIDTH_SHRUNK, WIDTH_FLOOR
46
46
  } from './columnWidths.js';
47
47
 
@@ -1,5 +1,5 @@
1
1
  import { useState, useRef, useLayoutEffect, useCallback } from 'react';
2
- import { measureColumnDemand, allocateColumnWidths, resolvePercentWidths, headerTextOf } from './columnWidths.js';
2
+ import { measureColumnDemand, allocateColumnWidths, resolvePercentWidths, sortedHeaderText, headerChrome } from './columnWidths.js';
3
3
 
4
4
  /**
5
5
  * Content-based column widths — the DOM half. See columnWidths.js for the
@@ -117,6 +117,9 @@ export default function useColumnWidths(opts) {
117
117
  var data = opts.data;
118
118
  var columns = opts.columns;
119
119
  var sizingKey = opts.sizingKey;
120
+ // Sorted columns' headers carry an arrow; re-measured when the sort moves.
121
+ var sortedColumns = opts.sortedColumns || [];
122
+ var sortedSignature = sortedColumns.join('\u0001');
120
123
  var onSizing = opts.onSizing;
121
124
  var sampleRows = opts.sampleRows || DEFAULTS.sampleRows;
122
125
  var overrides = opts.columnWidths;
@@ -173,7 +176,7 @@ export default function useColumnWidths(opts) {
173
176
 
174
177
  // Cheap bail-out before the expensive part: measuring 200 rows across
175
178
  // every column on a render that changed nothing is pure waste.
176
- var signature = signatureOf(columns, containerWidth, sizingKey, overrides);
179
+ var signature = signatureOf(columns, containerWidth, sizingKey, overrides) + '\u0002' + sortedSignature;
177
180
  if (signature === signatureRef.current && data === dataRef.current && sizingRef.current) return;
178
181
  signatureRef.current = signature;
179
182
  dataRef.current = data;
@@ -213,10 +216,14 @@ export default function useColumnWidths(opts) {
213
216
 
214
217
  // Header chrome: the label shares its row with the sort caret and the
215
218
  // filter trigger, so the text needs less room than the cell does.
216
- var headerPadding = horizontalPadding(headCell);
217
219
  var trigger = table.querySelector('thead .xeplr-table-filter-trigger');
218
- if (trigger) headerPadding += trigger.offsetWidth + 4;
219
- else headerPadding += 16; // sort caret
220
+ var triggerBox = trigger && (trigger.closest('.xeplr-table-filter-wrapper') || trigger);
221
+ var headerPadding = headerChrome({
222
+ cell: horizontalPadding(headCell),
223
+ th: horizontalPadding(headCell && headCell.closest('th')),
224
+ gap: headCell ? parseFloat(window.getComputedStyle(headCell).columnGap) || 0 : 0,
225
+ trigger: triggerBox ? triggerBox.getBoundingClientRect().width : null
226
+ });
220
227
 
221
228
  // The table's own structural columns — expand arrow, select checkbox, row
222
229
  // actions — aren't content columns and don't compete for space. Their
@@ -250,7 +257,7 @@ export default function useColumnWidths(opts) {
250
257
  columns: columns,
251
258
  rows: rows,
252
259
  textOf: textOf,
253
- headerOf: headerTextOf,
260
+ headerOf: function(column) { return sortedHeaderText(column, sortedColumns); },
254
261
  keyOf: function(column) { return column.accessor; },
255
262
  measure: measureWidest,
256
263
  bodyFont: BODY_FONTS,
@@ -273,7 +280,7 @@ export default function useColumnWidths(opts) {
273
280
  if (onSizing) onSizing(next);
274
281
  // State is tracked through refs above, so it is deliberately absent here.
275
282
  // eslint-disable-next-line react-hooks/exhaustive-deps
276
- }, [enabled, containerWidth, data, columns, textOf, sampleRows, sizingKey, overrides,
283
+ }, [enabled, containerWidth, data, columns, textOf, sampleRows, sizingKey, sortedSignature, overrides,
277
284
  opts.minColumnWidth, opts.maxColumnWidth, opts.maxFloorWidth]);
278
285
 
279
286
  return { scrollRef: scrollRef, tableRef: tableRef, sizing: enabled ? sizing : null };