@xeplr/ui-table 1.1.4 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/ui-table",
3
- "version": "1.1.4",
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",
@@ -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
+ }
@@ -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));