@xeplr/ui-table 1.1.3 → 1.1.5

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
@@ -88,7 +88,8 @@ Level N+1's `key` is the array property on each level-N row. `header` titles a c
88
88
  | field | |
89
89
  |---|---|
90
90
  | `accessor` | row property — required on a leaf column |
91
- | `header` | title; defaults to `accessor` |
91
+ | `header` | title; defaults to `accessor`. May be an element or a function (rendered by `flexRender`, e.g. an icon before the label) |
92
+ | `headerText` | the header's text, for measuring the column's width when `header` is not text; else the accessor is measured |
92
93
  | `dataType` | `'string'`, `'number'`, `'date'` or `'boolean'` — skips detection |
93
94
  | `render` | `{ type, …config }`, or the renderer name as a string |
94
95
  | `cell` | TanStack cell function `(ctx) => node`; wins over `render` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/ui-table",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
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",
@@ -107,6 +107,19 @@ function pinnedWidth(overrides, index) {
107
107
  * in the width of "York"; a 60-character URL cannot be narrowed at all, which
108
108
  * is why the caller caps this (see maxFloor).
109
109
  */
110
+ /**
111
+ * The text a column's header is measured by. A header may be an element or a
112
+ * function (drawn by flexRender: an icon before the label), which has no
113
+ * width of its own to measure — so `headerText` when the column gives it, else
114
+ * the header when it is text, else the accessor.
115
+ */
116
+ export function headerTextOf(column) {
117
+ if (!column) return '';
118
+ if (typeof column.headerText === 'string') return column.headerText;
119
+ if (typeof column.header === 'string' || typeof column.header === 'number') return String(column.header);
120
+ return column.accessor == null ? '' : String(column.accessor);
121
+ }
122
+
110
123
  export function longestToken(text) {
111
124
  if (!text) return '';
112
125
  var parts = String(text).split(/\s+/);
@@ -23,6 +23,12 @@ import { createPortal } from 'react-dom';
23
23
  * @param {React.ReactNode} props.children - Filter UI content
24
24
  * @param {Function} props.onClear - Called when user clears the filter
25
25
  */
26
+ /** Where the panel is put: the nearest themed ancestor (class xeplr-theme-…), else <body>. */
27
+ function themeRoot(el) {
28
+ var themed = el && el.closest ? el.closest('[class*="xeplr-theme-"]') : null;
29
+ return themed || document.body;
30
+ }
31
+
26
32
  export default function FilterWrapper({ isActive, children, onClear }) {
27
33
  var [open, setOpen] = useState(false);
28
34
  var [rect, setRect] = useState(null);
@@ -94,7 +100,10 @@ export default function FilterWrapper({ isActive, children, onClear }) {
94
100
  </button>
95
101
  </div>
96
102
  </div>,
97
- document.body
103
+ // Inside the app's theme (@xeplr/ui-account's .xeplr-theme-* wrapper), not
104
+ // bare in <body>: there its --xeplr-* colours are not set and the panel
105
+ // fell back to this package's dark palette on a light page.
106
+ themeRoot(wrapperRef.current)
98
107
  ) : null;
99
108
 
100
109
  return (
@@ -1,5 +1,6 @@
1
1
  import React, { useState, useMemo } from 'react';
2
2
  import FilterWrapper from './FilterWrapper.jsx';
3
+ import { NONE, toggleSelection, passesString } from './stringSelection.js';
3
4
 
4
5
  /**
5
6
  * Excel-like string filter: searchable multi-select of unique values + null checks.
@@ -36,14 +37,9 @@ export default function StringFilter({ column }) {
36
37
  var selectedSet = new Set(currentFilter.selected);
37
38
  var isActive = currentFilter.selected.length > 0 || currentFilter.isNull !== null;
38
39
 
40
+ // As the boxes read: untick one of all to hide it; after Clear All, tick to show (stringSelection).
39
41
  function toggleValue(val) {
40
- var next = new Set(selectedSet);
41
- if (next.has(val)) {
42
- next.delete(val);
43
- } else {
44
- next.add(val);
45
- }
46
- column.setFilterValue({ selected: Array.from(next), isNull: currentFilter.isNull });
42
+ column.setFilterValue({ selected: toggleSelection(currentFilter.selected, val, uniqueValues), isNull: currentFilter.isNull });
47
43
  }
48
44
 
49
45
  function selectAll() {
@@ -53,7 +49,7 @@ export default function StringFilter({ column }) {
53
49
  function selectNone() {
54
50
  // Selecting "none" means selecting all visible as the filter — i.e. show nothing
55
51
  // Actually, set selected to a sentinel empty-but-active state
56
- column.setFilterValue({ selected: ['__xeplr_none__'], isNull: currentFilter.isNull });
52
+ column.setFilterValue({ selected: [NONE], isNull: currentFilter.isNull });
57
53
  }
58
54
 
59
55
  function setNullMode(mode) {
@@ -126,17 +122,5 @@ export default function StringFilter({ column }) {
126
122
  * Custom filter function for string columns.
127
123
  */
128
124
  export function stringFilterFn(row, columnId, filterValue) {
129
- if (!filterValue) return true;
130
-
131
- var val = row.getValue(columnId);
132
- var isNullish = val === null || val === undefined || val === '';
133
-
134
- // Null mode check
135
- if (filterValue.isNull === true) return isNullish;
136
- if (filterValue.isNull === false && isNullish) return false;
137
-
138
- // Selected values check
139
- if (filterValue.selected.length === 0) return true; // no selection = show all
140
- if (filterValue.selected[0] === '__xeplr_none__') return false;
141
- return filterValue.selected.includes(String(val));
125
+ return passesString(row.getValue(columnId), filterValue);
142
126
  }
@@ -0,0 +1,39 @@
1
+ // WHAT A STRING FILTER'S TICKS MEAN — pure, so it can be tested.
2
+ //
3
+ // The filter value is { selected: string[], isNull: true|false|null }:
4
+ // selected [] nothing chosen: every row shows (all ticked)
5
+ // selected ['__xeplr_none__'] "Clear All": no row shows (none ticked)
6
+ // selected [a, b] only rows whose value is a or b
7
+ export var NONE = '__xeplr_none__';
8
+
9
+ /**
10
+ * The selection after one value's tick is toggled — as the boxes read. With
11
+ * everything ticked, unticking one leaves all the others; after Clear All,
12
+ * ticking one shows that one; ticking the last one back is "all" again.
13
+ * @param {string[]} selected the current selection
14
+ * @param {string} value the value toggled
15
+ * @param {string[]} all every value the column has
16
+ * @returns {string[]}
17
+ */
18
+ export function toggleSelection(selected, value, all) {
19
+ var current = (selected || []).filter(function(v) { return v !== NONE; });
20
+ var everything = !selected || selected.length === 0;
21
+ var ticked = new Set(everything ? all : current);
22
+ if (ticked.has(value)) ticked.delete(value); else ticked.add(value);
23
+ if (ticked.size === 0) return [NONE];
24
+ var allTicked = all.length > 0 && all.every(function(v) { return ticked.has(v); });
25
+ return allTicked ? [] : Array.from(ticked);
26
+ }
27
+
28
+ /** Whether a row's value passes a string filter. */
29
+ export function passesString(val, filterValue) {
30
+ if (!filterValue) return true;
31
+ var isNullish = val === null || val === undefined || val === '';
32
+ if (filterValue.isNull === true) return isNullish;
33
+ if (filterValue.isNull === false && isNullish) return false;
34
+ var selected = filterValue.selected || [];
35
+ if (selected.length === 0) return true;
36
+ var chosen = selected.filter(function(v) { return v !== NONE; });
37
+ if (!chosen.length) return false;
38
+ return chosen.includes(String(val));
39
+ }
@@ -1,5 +1,5 @@
1
1
  import { useState, useRef, useLayoutEffect, useCallback } from 'react';
2
- import { measureColumnDemand, allocateColumnWidths, resolvePercentWidths } from './columnWidths.js';
2
+ import { measureColumnDemand, allocateColumnWidths, resolvePercentWidths, headerTextOf } from './columnWidths.js';
3
3
 
4
4
  /**
5
5
  * Content-based column widths — the DOM half. See columnWidths.js for the
@@ -250,7 +250,7 @@ export default function useColumnWidths(opts) {
250
250
  columns: columns,
251
251
  rows: rows,
252
252
  textOf: textOf,
253
- headerOf: function(column) { return column.header || column.accessor; },
253
+ headerOf: headerTextOf,
254
254
  keyOf: function(column) { return column.accessor; },
255
255
  measure: measureWidest,
256
256
  bodyFont: BODY_FONTS,
@@ -286,6 +286,8 @@
286
286
  max-height: 60vh;
287
287
  overflow: auto;
288
288
  background: var(--xeplr-bg-tertiary, #1e1e38);
289
+ /* Its own text colour: it is not inside the table, so it inherits none. */
290
+ color: var(--xeplr-text-primary, #e0e0e0);
289
291
  border: 1px solid var(--xeplr-border-primary, #3a3a5a);
290
292
  border-radius: 6px;
291
293
  box-shadow: var(--xeplr-shadow-lg, 0 8px 24px rgba(0, 0, 0, 0.4));