@sdxc/ui 2026.11.3 → 2026.11.4

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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Island that finishes a {@link DocsNav} in the browser: the sidebar opens scrolled to the
3
- * current page, and an optional field filters its pages by title. It renders only the field,
4
- * so the tree it acts on stays server HTML however many pages it holds.
3
+ * current page, and an optional field filters its pages by title as the reader types. It renders
4
+ * only the field, so the tree it acts on stays server HTML however many pages it holds.
5
5
  *
6
6
  * @author [Sergio Xalambrí](https://sergiodxa.com)
7
7
  * @copyright Sergio Xalambrí 2026
@@ -11,15 +11,21 @@ import type { EntryComponent } from "remix/component";
11
11
  export declare namespace DocsNavTools {
12
12
  /** Plain data only, since the props cross into the browser with the island. */
13
13
  type Props = {
14
- /** The title filter's accessible name and placeholder; unset draws no field. */
14
+ /**
15
+ * The title filter's accessible name, placeholder, the query parameter it submits as
16
+ * and the query the page was rendered for; unset draws no field.
17
+ */
15
18
  filter?: {
16
19
  label: string;
17
20
  placeholder: string;
21
+ name: string;
22
+ query: string;
18
23
  };
19
24
  };
20
25
  }
21
26
  /**
22
- * Renders the filter field, hidden until it loads, inside the nav it enhances. `DocsNav`
23
- * places it; load `@sdxc/ui/docs/docs-nav-tools` in the browser entry.
27
+ * Renders the filter field inside a `GET` form on the current address, so before or without
28
+ * script, Enter reloads the page filtered by the server. `DocsNav` places it; load
29
+ * `@sdxc/ui/docs/docs-nav-tools` in the browser entry to filter as the reader types.
24
30
  */
25
31
  export declare const DocsNavTools: EntryComponent<DocsNavTools.Props>;
@@ -3,12 +3,13 @@ import { clientEntry } from "remix/component";
3
3
  import { SearchField } from "../components/search-field.js";
4
4
  import { docsNavTools } from "./mixins/docs-nav-tools.js";
5
5
  /**
6
- * Renders the filter field, hidden until it loads, inside the nav it enhances. `DocsNav`
7
- * places it; load `@sdxc/ui/docs/docs-nav-tools` in the browser entry.
6
+ * Renders the filter field inside a `GET` form on the current address, so before or without
7
+ * script, Enter reloads the page filtered by the server. `DocsNav` places it; load
8
+ * `@sdxc/ui/docs/docs-nav-tools` in the browser entry to filter as the reader types.
8
9
  */
9
10
  export const DocsNavTools = clientEntry("@sdxc/ui/docs/docs-nav-tools#DocsNavTools", function DocsNavTools(handle) {
10
11
  return () => {
11
12
  let { filter } = handle.props;
12
- return (_jsx("div", { hidden: true, mix: [docsNavTools()], children: filter ? (_jsx(SearchField, { "aria-label": filter.label, children: _jsx(SearchField.Input, { placeholder: filter.placeholder, autocomplete: "off" }) })) : null }));
13
+ return (_jsx("form", { method: "get", mix: [docsNavTools()], children: filter ? (_jsx(SearchField, { "aria-label": filter.label, children: _jsx(SearchField.Input, { name: filter.name, defaultValue: filter.query, placeholder: filter.placeholder, autocomplete: "off" }) })) : null }));
13
14
  };
14
15
  });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * A docs sidebar drawn from a {@link DocsTree}: sections under plain labels, pages and
3
3
  * titled groups of pages, the current page marked and scrolled into view, an optional
4
- * title filter, and a footer for support links. The same tree feeds the pager.
4
+ * title filter that works with or without script, and a footer for support links.
5
5
  *
6
6
  * @author [Sergio Xalambrí](https://sergiodxa.com)
7
7
  * @copyright Sergio Xalambrí 2026
@@ -17,13 +17,16 @@ export declare namespace DocsNav {
17
17
  /** The path being read, which marks one link `aria-current="page"`. */
18
18
  activePath: string;
19
19
  /**
20
- * A field that filters pages by title, with the line shown when nothing matches.
21
- * It appears once the page's script loads.
20
+ * A field that filters pages by title, with the line shown when nothing matches. Without
21
+ * script it submits `name` (default `"filter"`) to the page; pass that parameter back as
22
+ * `query` and the tree renders filtered.
22
23
  */
23
24
  filter?: {
24
25
  label: string;
25
26
  placeholder: string;
26
27
  noResults: string;
28
+ name?: string;
29
+ query?: string;
27
30
  };
28
31
  /**
29
32
  * Drawn under the tree, such as "Contact support" or a status link, flush with the
@@ -11,6 +11,7 @@ import { rotate } from "@sdxc/u/transform";
11
11
  import { text, weight } from "@sdxc/u/typography";
12
12
  import { Sidebar } from "../components/sidebar.js";
13
13
  import { DocsNavTools } from "./docs-nav-tools.js";
14
+ import { matchDocsTree } from "./utils/docs-filter.js";
14
15
  /**
15
16
  * Renders the tree in reading order. A group whose `href` is set links its own page from
16
17
  * its summary, and every group is a native `<details>`, so folding needs no script. Load
@@ -24,12 +25,21 @@ import { DocsNavTools } from "./docs-nav-tools.js";
24
25
  export function DocsNav(handle) {
25
26
  return () => {
26
27
  let { tree, activePath, filter, footer, collapseGroups = false, prefetch = "intent", } = handle.props;
27
- let context = { activePath, collapseGroups, prefetch };
28
+ let query = filter?.query ?? "";
29
+ let matches = filter ? matchDocsTree(tree, query) : null;
30
+ let context = { activePath, collapseGroups, prefetch, matches };
28
31
  return (_jsxs("div", { "data-docs-nav": "", mix: [
29
32
  vstack({ gap: 4 }),
30
33
  minIs(0),
31
34
  when("& [hidden]", raw({ display: "none !important" })),
32
- ], children: [_jsx(DocsNavTools, { filter: filter ? { label: filter.label, placeholder: filter.placeholder } : undefined }), _jsxs(Sidebar.Nav, { "aria-label": tree.label, mix: [raw({ gap: "1.25rem" })], children: [tree.sections.map((section) => (_jsxs("div", { "data-docs-nav-section": "", mix: [vstack({ gap: 1 })], children: [_jsx("p", { mix: [m(0), p(1, 2.5), text("sm"), weight("semibold"), fg("neutral.emphasis")], children: section.title }), _jsx(Sidebar.Menu, { "data-docs-nav-list": "", mix: [m(0), p(0), listStyle("none")], children: section.items.map((item) => (_jsx(NavItem, { item: item, context: context, depth: 0 }, item.href ?? item.title))) })] }, section.title))), filter ? (_jsx("p", { "data-docs-nav-empty": "", hidden: true, mix: [m(0), p(2, 2.5), text("sm"), fg("neutral.muted")], children: filter.noResults })) : null] }), footer ? _jsx("div", { "data-docs-nav-footer": "", children: footer }) : null] }));
35
+ ], children: [_jsx(DocsNavTools, { filter: filter
36
+ ? {
37
+ label: filter.label,
38
+ placeholder: filter.placeholder,
39
+ name: filter.name ?? "filter",
40
+ query,
41
+ }
42
+ : undefined }), _jsxs(Sidebar.Nav, { "aria-label": tree.label, mix: [raw({ gap: "1.25rem" })], children: [tree.sections.map((section) => (_jsxs("div", { "data-docs-nav-section": "", hidden: matches ? !section.items.some((item) => matches.shown.has(item)) : undefined, mix: [vstack({ gap: 1 })], children: [_jsx("p", { mix: [m(0), p(1, 2.5), text("sm"), weight("semibold"), fg("neutral.emphasis")], children: section.title }), _jsx(Sidebar.Menu, { "data-docs-nav-list": "", mix: [m(0), p(0), listStyle("none")], children: section.items.map((item) => (_jsx(NavItem, { item: item, context: context, depth: 0 }, item.href ?? item.title))) })] }, section.title))), filter ? (_jsx("p", { "data-docs-nav-empty": "", hidden: !matches || matches.shown.size > 0, mix: [m(0), p(2, 2.5), text("sm"), fg("neutral.muted")], children: filter.noResults })) : null] }), footer ? _jsx("div", { "data-docs-nav-footer": "", children: footer }) : null] }));
33
43
  };
34
44
  }
35
45
  /** Whether `item` is, or holds, the page at `path`. */
@@ -40,18 +50,20 @@ function holds(item, path) {
40
50
  function NavItem(handle) {
41
51
  return () => {
42
52
  let { item, context, depth } = handle.props;
43
- let { activePath, collapseGroups, prefetch } = context;
53
+ let { activePath, collapseGroups, prefetch, matches } = context;
54
+ let filteredOut = matches ? !matches.shown.has(item) : undefined;
44
55
  let Row = depth === 0 ? Sidebar.MenuItem : Sidebar.MenuSubItem;
45
56
  let badge = item.badge ? _jsx(Sidebar.MenuBadge, { children: item.badge }) : null;
46
57
  if (!item.items || item.items.length === 0) {
47
58
  if (item.href === undefined)
48
59
  return null;
49
60
  let Link = depth === 0 ? Sidebar.MenuLink : Sidebar.MenuSubLink;
50
- return (_jsx(Row, { children: _jsxs(Link, { href: item.href, prefetch: prefetch, active: item.href === activePath, children: [_jsx("span", { children: item.title }), badge] }) }));
61
+ return (_jsx(Row, { hidden: filteredOut, children: _jsxs(Link, { href: item.href, prefetch: prefetch, active: item.href === activePath, children: [_jsx("span", { "data-docs-nav-title": "", children: item.title }), badge] }) }));
51
62
  }
52
- let open = !collapseGroups || holds(item, activePath);
63
+ let own = !collapseGroups || holds(item, activePath);
64
+ let opened = !own && (matches?.opened.has(item) ?? false);
53
65
  let current = item.href !== undefined && item.href === activePath;
54
- return (_jsx(Row, { children: _jsxs("details", { open: open, children: [_jsxs("summary", { mix: [
66
+ return (_jsx(Row, { hidden: filteredOut, children: _jsxs("details", { open: own || opened, "data-docs-nav-opened": opened ? "" : undefined, children: [_jsxs("summary", { mix: [
55
67
  hstack({ gap: 2, align: "center" }),
56
68
  minBs("2.25rem"),
57
69
  pi("0.625rem"),
@@ -65,7 +77,7 @@ function NavItem(handle) {
65
77
  fg("inherit"),
66
78
  raw({ textDecoration: "none" }),
67
79
  when('&[aria-current="page"]', [fg("neutral.emphasis"), weight("medium")]),
68
- ], children: item.title })) : (_jsx("span", { children: item.title })), badge, _jsx(ChevronRightIcon, { size: 14, "aria-hidden": "true", mix: [
80
+ ], children: _jsx("span", { "data-docs-nav-title": "", children: item.title }) })) : (_jsx("span", { "data-docs-nav-title": "", children: item.title })), badge, _jsx(ChevronRightIcon, { size: 14, "aria-hidden": "true", mix: [
69
81
  shrink(0),
70
82
  mis("auto"),
71
83
  transition("transform"),
@@ -12,11 +12,11 @@ import type { ElementProps, MixinFactory } from "remix/component";
12
12
  * `aria-current="page"`. When the host holds an `<input>`, typing hides every `li` whose
13
13
  * title misses the query, hides sections left empty, opens `<details>` groups holding a
14
14
  * match, and shows `[data-docs-nav-empty]` when nothing matches; clearing the field restores
15
- * every group's own open state. A page reload that resets the tree keeps the query applied.
16
- * The host is `hidden` until this runs, so a page without script never shows an inert field.
15
+ * every group's own open state. A page reload that resets the tree keeps the query applied,
16
+ * and the field's form stays on the page, which without script submits to the server instead.
17
17
  *
18
18
  * @example
19
- * <div data-docs-nav><div hidden mix={[docsNavTools()]}><input type="search" /></div><nav>…</nav></div>
19
+ * <div data-docs-nav><form mix={[docsNavTools()]}><input type="search" /></form><nav>…</nav></div>
20
20
  */
21
21
  export declare const docsNavTools: MixinFactory<HTMLElement, [], ElementProps>;
22
22
  /**
@@ -7,17 +7,18 @@
7
7
  * @copyright Sergio Xalambrí 2026
8
8
  */
9
9
  import { createMixin } from "remix/component";
10
+ import { filterWords, titleMatches } from "../utils/docs-filter.js";
10
11
  import { revealInScroller } from "../utils/reveal-in-scroller.js";
11
12
  /**
12
13
  * Works on the closest `[data-docs-nav]` around its host. The current link is the one with
13
14
  * `aria-current="page"`. When the host holds an `<input>`, typing hides every `li` whose
14
15
  * title misses the query, hides sections left empty, opens `<details>` groups holding a
15
16
  * match, and shows `[data-docs-nav-empty]` when nothing matches; clearing the field restores
16
- * every group's own open state. A page reload that resets the tree keeps the query applied.
17
- * The host is `hidden` until this runs, so a page without script never shows an inert field.
17
+ * every group's own open state. A page reload that resets the tree keeps the query applied,
18
+ * and the field's form stays on the page, which without script submits to the server instead.
18
19
  *
19
20
  * @example
20
- * <div data-docs-nav><div hidden mix={[docsNavTools()]}><input type="search" /></div><nav>…</nav></div>
21
+ * <div data-docs-nav><form mix={[docsNavTools()]}><input type="search" /></form><nav>…</nav></div>
21
22
  */
22
23
  export const docsNavTools = createMixin((handle) => {
23
24
  let controller;
@@ -46,10 +47,10 @@ function enhance(host, signal) {
46
47
  let input = host.querySelector("input");
47
48
  if (!input)
48
49
  return;
49
- host.hidden = false;
50
+ host.addEventListener("submit", (event) => event.preventDefault(), { signal });
50
51
  let ownState = new Map();
51
52
  let snapshot = () => {
52
- ownState = new Map([...nav.querySelectorAll("details")].map((group) => [group, group.open]));
53
+ ownState = new Map([...nav.querySelectorAll("details")].map((group) => [group, ownOpen(group)]));
53
54
  };
54
55
  snapshot();
55
56
  let observer = new MutationObserver((records) => {
@@ -69,6 +70,10 @@ function enhance(host, signal) {
69
70
  if (input.value)
70
71
  apply();
71
72
  }
73
+ /** Whether `group` is open on its own, discounting a server render that opened it for a match. */
74
+ function ownOpen(group) {
75
+ return group.open && !group.hasAttribute("data-docs-nav-opened");
76
+ }
72
77
  /**
73
78
  * Whether `record` is a page reload putting the server's markup back: pages added or
74
79
  * replaced, or a page the filter hid shown again. The filter's own writes only hide.
@@ -84,7 +89,7 @@ function isReset(record) {
84
89
  * its pages. An empty query restores the full tree and each group's own open state.
85
90
  */
86
91
  export function filterDocsNav(nav, query, ownState) {
87
- let words = normalize(query).split(/\s+/).filter(Boolean);
92
+ let words = filterWords(query);
88
93
  let empty = nav.querySelector("[data-docs-nav-empty]");
89
94
  let anyMatch = false;
90
95
  for (let section of nav.querySelectorAll("[data-docs-nav-section]")) {
@@ -103,8 +108,8 @@ export function filterDocsNav(nav, query, ownState) {
103
108
  }
104
109
  /** Shows or hides `item` and its nested pages for `words`; reports whether it stays shown. */
105
110
  function applyFilter(item, words) {
106
- let title = item.querySelector(":scope > a, :scope > details > summary");
107
- let own = words.every((word) => normalize(title?.textContent ?? "").includes(word));
111
+ let title = item.querySelector(":scope > a [data-docs-nav-title], :scope > details > summary [data-docs-nav-title]");
112
+ let own = titleMatches(title?.textContent ?? "", words);
108
113
  let children = item.querySelectorAll(":scope > details > ul > li, :scope > ul > li");
109
114
  let childShown = false;
110
115
  for (let child of children)
@@ -115,10 +120,3 @@ function applyFilter(item, words) {
115
120
  item.hidden = !(own || childShown);
116
121
  return !item.hidden;
117
122
  }
118
- /** Lower-cases `value` and strips diacritics, so "Configuracion" finds "Configuración". */
119
- function normalize(value) {
120
- return value
121
- .normalize("NFD")
122
- .replaceAll(/\p{Diacritic}/gu, "")
123
- .toLowerCase();
124
- }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * How a docs sidebar's title filter matches pages, shared by the server, which draws a
3
+ * filtered tree for a reader without script, and the browser, which filters as they type,
4
+ * so both keep exactly the same pages for the same query.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { DocsTree } from "./docs-tree.js";
10
+ /** What a query keeps of a tree: the items left shown and the groups opened around a match. */
11
+ export interface DocsTreeMatches {
12
+ shown: Set<DocsTree.Item>;
13
+ opened: Set<DocsTree.Item>;
14
+ }
15
+ /** Lower-cases `value` and strips diacritics, so "Configuracion" finds "Configuración". */
16
+ export declare function normalizeFilterText(value: string): string;
17
+ /** The normalized words of `query`; an empty list keeps every page. */
18
+ export declare function filterWords(query: string): string[];
19
+ /** Whether `title` holds every word, case- and accent-insensitive. */
20
+ export declare function titleMatches(title: string, words: string[]): boolean;
21
+ /**
22
+ * The items of `tree` whose title holds every word of `query`, with the groups that contain
23
+ * them; a group whose own title matches keeps all its pages. Returns `null` for a query with
24
+ * no words, which keeps the whole tree as drawn.
25
+ */
26
+ export declare function matchDocsTree(tree: DocsTree, query: string): DocsTreeMatches | null;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * How a docs sidebar's title filter matches pages, shared by the server, which draws a
3
+ * filtered tree for a reader without script, and the browser, which filters as they type,
4
+ * so both keep exactly the same pages for the same query.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ /** Lower-cases `value` and strips diacritics, so "Configuracion" finds "Configuración". */
10
+ export function normalizeFilterText(value) {
11
+ return value
12
+ .normalize("NFD")
13
+ .replaceAll(/\p{Diacritic}/gu, "")
14
+ .toLowerCase();
15
+ }
16
+ /** The normalized words of `query`; an empty list keeps every page. */
17
+ export function filterWords(query) {
18
+ return normalizeFilterText(query).split(/\s+/).filter(Boolean);
19
+ }
20
+ /** Whether `title` holds every word, case- and accent-insensitive. */
21
+ export function titleMatches(title, words) {
22
+ let normalized = normalizeFilterText(title);
23
+ return words.every((word) => normalized.includes(word));
24
+ }
25
+ /**
26
+ * The items of `tree` whose title holds every word of `query`, with the groups that contain
27
+ * them; a group whose own title matches keeps all its pages. Returns `null` for a query with
28
+ * no words, which keeps the whole tree as drawn.
29
+ */
30
+ export function matchDocsTree(tree, query) {
31
+ let words = filterWords(query);
32
+ if (words.length === 0)
33
+ return null;
34
+ let matches = { shown: new Set(), opened: new Set() };
35
+ for (let section of tree.sections) {
36
+ for (let item of section.items)
37
+ collect(item, words, matches);
38
+ }
39
+ return matches;
40
+ }
41
+ /** Adds `item` and its matching pages to `matches`; reports whether it stays shown. */
42
+ function collect(item, words, matches) {
43
+ let own = titleMatches(item.title, words);
44
+ let childShown = false;
45
+ for (let child of item.items ?? []) {
46
+ childShown = collect(child, own ? [] : words, matches) || childShown;
47
+ }
48
+ if (childShown && words.length > 0)
49
+ matches.opened.add(item);
50
+ if (own || childShown)
51
+ matches.shown.add(item);
52
+ return own || childShown;
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdxc/ui",
3
- "version": "2026.11.3",
3
+ "version": "2026.11.4",
4
4
  "description": "Styled, accessible remix/component components rendered as server HTML",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -37,7 +37,7 @@
37
37
  "peerDependencies": {
38
38
  "remix": "3.1.0"
39
39
  },
40
- "gitHead": "d1dd4030f8df68b8a170940a3f790ea8654d3676",
40
+ "gitHead": "f9b4adfc3d85b98a3d628b69cc2e1b9c0b7af2d8",
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },