@syware/jlib 0.18.0 → 0.19.1

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.
@@ -103,6 +103,7 @@ var JlCheckbox = class extends JlFormControl {
103
103
  }
104
104
  onConnect() {
105
105
  const native = this._refs.native;
106
+ this.on(native, "input", (event) => event.stopPropagation());
106
107
  this.on(native, "change", () => this.commit(native.checked));
107
108
  this.renderText();
108
109
  this.on(this._refs.slot, "slotchange", () => this.renderText());
@@ -97,6 +97,7 @@ var JlSelect = class extends JlFormControl {
97
97
  }
98
98
  onConnect() {
99
99
  const native = this._refs.native;
100
+ this.on(native, "input", (event) => event.stopPropagation());
100
101
  this.on(native, "change", () => {
101
102
  const value = asValue(native.value);
102
103
  this.value.set(value);
@@ -88,6 +88,7 @@ var JlSwitch = class extends JlFormControl {
88
88
  }
89
89
  onConnect() {
90
90
  const native = this._refs.native;
91
+ this.on(native, "input", (event) => event.stopPropagation());
91
92
  this.on(native, "change", () => this.commit(native.checked));
92
93
  this.renderText();
93
94
  this.on(this._refs.slot, "slotchange", () => this.renderText());
@@ -4,11 +4,13 @@ export declare const foldCharacter: (character: string) => string;
4
4
  /** A text as matching sees it: "Crème Brûlée" gives "creme brulee". */
5
5
  export declare const foldText: (text: string) => string;
6
6
  /**
7
- * Where a search first occurs in a text, ignoring case and accents, in the text's own indexes; null when it does
8
- * not, or when the search is empty.
7
+ * Where each word of a search occurs in a text, ignoring case and accents, in the text's own indexes: at the start of
8
+ * one of the text's words when it is there, else where it first occurs. In order, those that overlap or touch made
9
+ * one; empty when no word occurs, or the search has none. A page that finds options by words (`filter="none"`) gets
10
+ * each of them marked, wherever they are in the label.
9
11
  */
10
- export declare function findMatch(text: string, query: string): TextMatch | null;
11
- /** A text cut around its match, so the matched piece can be drawn highlighted. */
12
+ export declare function findMatches(text: string, query: string): TextMatch[];
13
+ /** A text cut around the words of a search it holds, so that they can be drawn highlighted. */
12
14
  export declare function matchParts(text: string, query: string): TextMatchPart[];
13
15
  /**
14
16
  * The options whose label contains the search, ignoring case and accents: those that start with it first, then
@@ -7,6 +7,7 @@ var RANK = {
7
7
  };
8
8
  var DIACRITICS = /\p{Diacritic}/gu;
9
9
  var WORD_CHARACTER = /[\p{L}\p{N}]/u;
10
+ var SPACES = /\s+/u;
10
11
  /** One character as matching sees it: lower case, without its accents ("É" gives "e"). */
11
12
  var foldCharacter = (character) => character.normalize("NFD").replace(DIACRITICS, "").toLowerCase();
12
13
  /** A text as matching sees it: "Crème Brûlée" gives "creme brulee". */
@@ -30,48 +31,77 @@ function foldPieces(text) {
30
31
  }
31
32
  return pieces;
32
33
  }
33
- /**
34
- * Where a search first occurs in a text, ignoring case and accents, in the text's own indexes; null when it does
35
- * not, or when the search is empty.
36
- */
37
- function findMatch(text, query) {
38
- const needle = foldText(query.trim());
39
- if (needle === "") return null;
40
- const at = foldText(text).indexOf(needle);
41
- if (at < 0) return null;
42
- const end = at + needle.length;
43
- const pieces = foldPieces(text);
44
- const first = pieces.find((piece) => piece.foldedEnd > at);
45
- const last = pieces.findLast((piece) => piece.foldedStart < end || piece.foldedEnd === end);
34
+ /** The search's words as matching sees them: what was typed, folded, cut at its spaces. */
35
+ var searchWords = (query) => foldText(query).split(SPACES).filter((word) => word !== "");
36
+ /** A range of a text's folded form in the text's own indexes; an accent written as a mark goes with its letter. */
37
+ function originalRange(pieces, foldedStart, foldedEnd) {
38
+ const first = pieces.find((piece) => piece.foldedEnd > foldedStart);
39
+ const last = pieces.findLast((piece) => piece.foldedStart < foldedEnd || piece.foldedEnd === foldedEnd);
46
40
  if (first === void 0 || last === void 0) return null;
47
41
  return {
48
42
  end: last.end,
49
43
  start: first.start
50
44
  };
51
45
  }
52
- /** A text cut around its match, so the matched piece can be drawn highlighted. */
46
+ /** Ranges in order, those that overlap or touch made one. */
47
+ function mergedRanges(ranges) {
48
+ const merged = [];
49
+ for (const range of [...ranges].sort((a, b) => a.start - b.start)) {
50
+ const last = merged.at(-1);
51
+ if (last !== void 0 && range.start <= last.end) {
52
+ merged[merged.length - 1] = {
53
+ end: Math.max(last.end, range.end),
54
+ start: last.start
55
+ };
56
+ continue;
57
+ }
58
+ merged.push(range);
59
+ }
60
+ return merged;
61
+ }
62
+ /**
63
+ * Where each word of a search occurs in a text, ignoring case and accents, in the text's own indexes: at the start of
64
+ * one of the text's words when it is there, else where it first occurs. In order, those that overlap or touch made
65
+ * one; empty when no word occurs, or the search has none. A page that finds options by words (`filter="none"`) gets
66
+ * each of them marked, wherever they are in the label.
67
+ */
68
+ function findMatches(text, query) {
69
+ const folded = foldText(text);
70
+ const pieces = foldPieces(text);
71
+ return mergedRanges(searchWords(query).flatMap((word) => {
72
+ const at = wordIndex(folded, word);
73
+ const range = at < 0 ? null : originalRange(pieces, at, at + word.length);
74
+ return range === null ? [] : [range];
75
+ }));
76
+ }
77
+ /** A text cut around the words of a search it holds, so that they can be drawn highlighted. */
53
78
  function matchParts(text, query) {
54
- const match = findMatch(text, query);
55
- if (match === null) return text === "" ? [] : [{
79
+ const matches = findMatches(text, query);
80
+ const parts = matches.flatMap((match, index) => [{
56
81
  matched: false,
57
- text
58
- }];
59
- return [
60
- {
61
- matched: false,
62
- text: text.slice(0, match.start)
63
- },
64
- {
65
- matched: true,
66
- text: text.slice(match.start, match.end)
67
- },
68
- {
69
- matched: false,
70
- text: text.slice(match.end)
71
- }
72
- ].filter((part) => part.text !== "");
82
+ text: text.slice(matches[index - 1]?.end ?? 0, match.start)
83
+ }, {
84
+ matched: true,
85
+ text: text.slice(match.start, match.end)
86
+ }]);
87
+ const rest = {
88
+ matched: false,
89
+ text: text.slice(matches.at(-1)?.end ?? 0)
90
+ };
91
+ return [...parts, rest].filter((part) => part.text !== "");
73
92
  }
74
93
  var startsAWord = (folded, index) => index === 0 || !WORD_CHARACTER.test(folded.charAt(index - 1));
94
+ /** Every place a folded word occurs in a folded text, in order. */
95
+ function occurrences(folded, word) {
96
+ const found = [];
97
+ for (let at = folded.indexOf(word); at >= 0; at = folded.indexOf(word, at + 1)) found.push(at);
98
+ return found;
99
+ }
100
+ /** Where a folded word occurs in a folded text: at the start of one of its words if it can, else first; -1 if not. */
101
+ function wordIndex(folded, word) {
102
+ const found = occurrences(folded, word);
103
+ return found.find((index) => startsAWord(folded, index)) ?? found[0] ?? -1;
104
+ }
75
105
  /** How well a label matches a folded search, or null when it does not contain it. */
76
106
  function rankOf(label, needle) {
77
107
  const folded = foldText(label);
@@ -105,4 +135,4 @@ function nextEnabledIndex(options, current, direction) {
105
135
  }
106
136
  /** The first (1) or last (-1) option that can be chosen; -1 when none can. */
107
137
  var edgeEnabledIndex = (options, from) => nextEnabledIndex(options, -1, from);
108
- export { edgeEnabledIndex, filterOptions, findMatch, foldCharacter, foldText, matchParts, nextEnabledIndex };
138
+ export { edgeEnabledIndex, filterOptions, findMatches, foldCharacter, foldText, matchParts, nextEnabledIndex };
@@ -1,2 +1,6 @@
1
1
  /** Whether a slot holds something to show: an element, or text that is not only white space. */
2
2
  export declare function hasSlotted(slot: HTMLSlotElement): boolean;
3
+ /** The elements a slot holds that the page shows: those it keeps `hidden` are left out. */
4
+ export declare function shownSlotted(slot: HTMLSlotElement): Element[];
5
+ /** Whether a slot holds something that shows: an element that is not `hidden`, or text that is not only white space. */
6
+ export declare function showsSlotted(slot: HTMLSlotElement): boolean;
package/dist/lib/slots.js CHANGED
@@ -1,6 +1,15 @@
1
1
  // src/lib/slots.ts
2
+ var holdsText = (node) => !(node instanceof Element) && (node.textContent ?? "").trim() !== "";
2
3
  /** Whether a slot holds something to show: an element, or text that is not only white space. */
3
4
  function hasSlotted(slot) {
4
- return slot.assignedNodes({ flatten: true }).some((node) => node instanceof Element || (node.textContent ?? "").trim() !== "");
5
+ return slot.assignedNodes({ flatten: true }).some((node) => node instanceof Element || holdsText(node));
5
6
  }
6
- export { hasSlotted };
7
+ /** The elements a slot holds that the page shows: those it keeps `hidden` are left out. */
8
+ function shownSlotted(slot) {
9
+ return slot.assignedElements({ flatten: true }).filter((element) => !element.hasAttribute("hidden"));
10
+ }
11
+ /** Whether a slot holds something that shows: an element that is not `hidden`, or text that is not only white space. */
12
+ function showsSlotted(slot) {
13
+ return shownSlotted(slot).length > 0 || slot.assignedNodes({ flatten: true }).some(holdsText);
14
+ }
15
+ export { hasSlotted, shownSlotted, showsSlotted };
@@ -7,5 +7,8 @@ export declare function accessibleTarget(element: Element): Element;
7
7
  export declare function setTriggerAria(element: Element, name: string, value: string | null): void;
8
8
  /** The element that has the focus within a document or a shadow root, looking inside nested shadow roots. */
9
9
  export declare function deepActiveElement(root: DocumentOrShadowRoot): Element | null;
10
- /** The first control people can focus among some elements and everything inside them, in document order. */
10
+ /**
11
+ * The first control people can focus among some elements and everything inside them, in the page's order: a
12
+ * component of the page whose fields are in its shadow root gives its first one.
13
+ */
11
14
  export declare function firstFocusable(elements: readonly Element[]): HTMLElement | null;
@@ -27,8 +27,18 @@ function deepActiveElement(root) {
27
27
  /** A form-associated custom element (jl-input, jl-button…) is a control: its own `focus()` reaches its inside. */
28
28
  var isFormComponent = (element) => element.constructor.formAssociated === true;
29
29
  var canFocus = (element) => element instanceof HTMLElement && (element.matches(NATIVE_FOCUSABLE) || isFormComponent(element)) && !element.matches(":disabled") && element.checkVisibility();
30
- /** The first control people can focus among some elements and everything inside them, in document order. */
30
+ /** What stands under an element in the page: a slot's assigned elements, a shadow root's, or else its children. */
31
+ function shownChildren(element) {
32
+ if (element instanceof HTMLSlotElement && element.assignedElements().length > 0) return element.assignedElements();
33
+ return [...(element.shadowRoot ?? element).children];
34
+ }
35
+ /** An element and everything under it as the page shows them, open shadow roots included, in the page's order. */
36
+ var shownTree = (element) => [element, ...shownChildren(element).flatMap(shownTree)];
37
+ /**
38
+ * The first control people can focus among some elements and everything inside them, in the page's order: a
39
+ * component of the page whose fields are in its shadow root gives its first one.
40
+ */
31
41
  function firstFocusable(elements) {
32
- return elements.flatMap((element) => [element, ...element.querySelectorAll("*")]).find(canFocus) ?? null;
42
+ return elements.flatMap(shownTree).find(canFocus) ?? null;
33
43
  }
34
44
  export { accessibleTarget, deepActiveElement, firstFocusable, setTriggerAria };
@@ -188,6 +188,7 @@ var JlFileDrop = class extends JlFormControl {
188
188
  this.on(zone, "dragover", (event) => this.onDragOver(event));
189
189
  this.on(zone, "dragleave", () => this.onDragLeave());
190
190
  this.on(zone, "drop", (event) => this.onDrop(event));
191
+ this.on(this._refs.picker, "input", (event) => event.stopPropagation());
191
192
  this.on(this._refs.picker, "change", () => this.onPicked());
192
193
  this.on(this._refs.files, "click", (event) => this.onFilesClick(event));
193
194
  }
@@ -8,7 +8,7 @@ import { JlButton } from "../atoms/jl-button.js";
8
8
  import { JlSkeleton } from "../atoms/jl-skeleton.js";
9
9
  import { JlEmpty } from "./jl-empty.js";
10
10
  import jl_load_state_default from "./jl-load-state.css.js";
11
- import { css } from "@jadis/core";
11
+ import { Jadis, css } from "@jadis/core";
12
12
  import { CircleAlert, RefreshCw } from "lucide";
13
13
  import { jsx, jsxs } from "@jadis/core/jsx-runtime";
14
14
  // src/molecules/jl-load-state.tsx
@@ -89,8 +89,6 @@ function leftLoading(state, signal) {
89
89
  }, { signal: listening.signal });
90
90
  });
91
91
  }
92
- /** Waits for the components connected meanwhile to run their `onConnect`, a task after connecting. */
93
- var nextTask = () => new Promise((resolve) => setTimeout(resolve));
94
92
  /** Runs a load's fetch. Only its failure is a load that failed: what `draw` throws afterwards is not caught here. */
95
93
  async function fetchOf(task) {
96
94
  try {
@@ -116,7 +114,7 @@ var JlLoadState = class JlLoadState extends JlElement {
116
114
  * it has its data waits for it (see `jl-page-outlet`).
117
115
  */
118
116
  static async whenSettled(root, signal = new AbortController().signal) {
119
- await nextTask();
117
+ await Jadis.settled();
120
118
  const waiting = loadStatesIn(root).filter(isWaiting);
121
119
  if (waiting.length === 0 || signal.aborted) return;
122
120
  await Promise.all(waiting.map((state) => leftLoading(state, signal)));
@@ -493,9 +493,10 @@ var JlSideNav = class extends JlElement {
493
493
  const opened = path.slice(0, -1).filter((id) => !this._state.open.has(id));
494
494
  for (const id of opened) this._state.open.add(id);
495
495
  if (opened.length > 0) this.renderOpen();
496
+ const current = this.isRail() ? path[0] : value;
496
497
  for (const row of this._refs.sections.querySelectorAll(ROW_SELECTOR)) {
497
498
  const id = row.dataset.id ?? "";
498
- const active = id === value || this.isRail() && row.dataset.target === value;
499
+ const active = id === current;
499
500
  setOrRemove(row, "aria-current", active ? "page" : "");
500
501
  row.classList.toggle("holds-active", !active && path.includes(id));
501
502
  }
@@ -142,6 +142,7 @@ export declare class JlTable<Row extends object = TableRow, Extra extends string
142
142
  }>>;
143
143
  private readonly _source;
144
144
  private readonly _pending;
145
+ private readonly _footWatch;
145
146
  private readonly _frozen;
146
147
  /**
147
148
  * The column chooser once drawn, its boxes by column key, changed in place so the focus stays on the box pressed,
@@ -170,7 +171,10 @@ export declare class JlTable<Row extends object = TableRow, Extra extends string
170
171
  private watchScrollbar;
171
172
  /** The scroller's width counts its scrollbar and its client width does not: the chooser moves left by the bar. */
172
173
  private placeChooser;
173
- /** The bar under the rows shows when the page put something in it; what stands there alone goes to its end. */
174
+ /**
175
+ * The bar under the rows shows when the page put something in it that shows; what stands there alone goes to its
176
+ * end. What the page keeps `hidden` (pages until there are several) is not there.
177
+ */
174
178
  private drawFoot;
175
179
  /** Draws on the next microtask: the inputs set while connecting give one drawing, not one each. */
176
180
  protected drawTexts(): void;
@@ -7,7 +7,7 @@ import { registerIcons } from "../lib/icons.js";
7
7
  import { columnAlign, columnChoices, columnWidth, fieldOf, formatCell, frozenCells, frozenCss, nextSortDirection, openRows, rowKeyOf, rowToggles, selectionState, shownColumns, sortBy, stickyOffsets, toggleAll, toggleKey, withRowOpen } from "../lib/table.js";
8
8
  import { JlIcon } from "../atoms/jl-icon.js";
9
9
  import { setOrRemove } from "../lib/dom.js";
10
- import { hasSlotted } from "../lib/slots.js";
10
+ import { shownSlotted, showsSlotted } from "../lib/slots.js";
11
11
  import { JlBadge } from "../atoms/jl-badge.js";
12
12
  import { JlButton } from "../atoms/jl-button.js";
13
13
  import { JlCheckbox } from "../atoms/jl-checkbox.js";
@@ -228,6 +228,9 @@ var JlTable = class extends JlElement {
228
228
  order: false,
229
229
  queued: false
230
230
  };
231
+ _footWatch = new MutationObserver((records) => {
232
+ if (records.some((record) => record.target.parentNode === this)) this.drawFoot();
233
+ });
231
234
  _frozen = { sizes: watchSizes(() => this.measureFrozen()) };
232
235
  /**
233
236
  * The column chooser once drawn, its boxes by column key, changed in place so the focus stays on the box pressed,
@@ -304,10 +307,17 @@ var JlTable = class extends JlElement {
304
307
  onConnect() {
305
308
  this.drawFoot();
306
309
  this.on(this._refs.footSlot, "slotchange", () => this.drawFoot());
310
+ this._footWatch.observe(this, {
311
+ attributeFilter: ["hidden"],
312
+ subtree: true
313
+ });
307
314
  this.on(this._refs.head, "click", (event) => {
308
315
  const key = event.target.closest("button.sort")?.dataset.key;
309
316
  if (key !== void 0) this.sortBy(key);
310
317
  });
318
+ this.on(this._refs.table, "input", (event) => {
319
+ if (isTableCheckbox(event.target)) event.stopPropagation();
320
+ });
311
321
  this.on(this._refs.table, "change", (event) => {
312
322
  if (isTableCheckbox(event.target)) this.changeSelection(event.target);
313
323
  });
@@ -316,6 +326,7 @@ var JlTable = class extends JlElement {
316
326
  this.watchFrozen();
317
327
  }
318
328
  onDisconnect() {
329
+ this._footWatch.disconnect();
319
330
  this._chooser.sizes.disconnect();
320
331
  this._frozen.sizes.disconnect();
321
332
  }
@@ -357,11 +368,14 @@ var JlTable = class extends JlElement {
357
368
  const scroll = this._refs.scroll;
358
369
  this.style.setProperty("--scrollbar", `${scroll.offsetWidth - scroll.clientWidth}px`);
359
370
  }
360
- /** The bar under the rows shows when the page put something in it; what stands there alone goes to its end. */
371
+ /**
372
+ * The bar under the rows shows when the page put something in it that shows; what stands there alone goes to its
373
+ * end. What the page keeps `hidden` (pages until there are several) is not there.
374
+ */
361
375
  drawFoot() {
362
376
  const foot = this._refs.foot;
363
- foot.hidden = !hasSlotted(this._refs.footSlot);
364
- foot.classList.toggle("alone", this._refs.footSlot.assignedElements({ flatten: true }).length === 1);
377
+ foot.hidden = !showsSlotted(this._refs.footSlot);
378
+ foot.classList.toggle("alone", shownSlotted(this._refs.footSlot).length === 1);
365
379
  }
366
380
  /** Draws on the next microtask: the inputs set while connecting give one drawing, not one each. */
367
381
  drawTexts() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syware/jlib",
3
- "version": "0.18.0",
3
+ "version": "0.19.1",
4
4
  "description": "A tree-shakeable component library on Jadis and native Web Components, organised in atomic design",
5
5
  "keywords": [
6
6
  "web-components",
@@ -88,7 +88,7 @@
88
88
  "version": "node scripts/plugin-version.mjs"
89
89
  },
90
90
  "peerDependencies": {
91
- "@jadis/core": "^1.9.0"
91
+ "@jadis/core": "^1.10.0"
92
92
  },
93
93
  "dependencies": {
94
94
  "lucide": "^1.61.0"
@@ -97,7 +97,7 @@
97
97
  "@biomejs/biome": "^2.6.3",
98
98
  "@fontsource-variable/jetbrains-mono": "^5.3.0",
99
99
  "@fontsource-variable/manrope": "^5.3.0",
100
- "@jadis/core": "^1.9.0",
100
+ "@jadis/core": "^1.10.0",
101
101
  "@types/node": "^24.13.3",
102
102
  "axe-core": "^4.14.0",
103
103
  "happy-dom": "^21.0.4",