@birdycom/omniaui 0.16.1 → 0.17.0

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.
Files changed (85) hide show
  1. package/bin/lib/copy-js.mjs +8 -0
  2. package/bin/lib/webicons-builtin.json +1 -0
  3. package/bin/lib/webicons.mjs +4 -0
  4. package/dist/back-link.d.ts +6 -0
  5. package/dist/back-link.js +54 -0
  6. package/dist/barcode.d.ts +5 -1
  7. package/dist/barcode.js +29 -8
  8. package/dist/calendar.d.ts +17 -0
  9. package/dist/calendar.js +190 -0
  10. package/dist/code-block.css +3 -0
  11. package/dist/combobox.d.ts +27 -4
  12. package/dist/combobox.js +231 -33
  13. package/dist/components-extra.css +33 -2
  14. package/dist/components.css +2112 -166
  15. package/dist/components.min.css +1 -1
  16. package/dist/countdown.d.ts +11 -0
  17. package/dist/countdown.js +76 -0
  18. package/dist/data-table.d.ts +28 -0
  19. package/dist/data-table.js +186 -18
  20. package/dist/docs-ui.css +11 -1
  21. package/dist/glass-lens.d.ts +41 -0
  22. package/dist/glass-lens.js +307 -0
  23. package/dist/input-mask.d.ts +31 -0
  24. package/dist/input-mask.js +228 -0
  25. package/dist/nav-overflow.d.ts +11 -0
  26. package/dist/nav-overflow.js +151 -0
  27. package/dist/oc-theme.css +1 -1
  28. package/dist/parts/app-0160-apps.css +6 -0
  29. package/dist/parts/app-compound-overlays.css +68 -0
  30. package/dist/parts/app-countdown.css +66 -0
  31. package/dist/parts/app-data-table-footer.css +6 -3
  32. package/dist/parts/app-data-table-server.css +47 -0
  33. package/dist/parts/app-data-table.css +27 -1
  34. package/dist/parts/app-header-settings.css +9 -0
  35. package/dist/parts/app-mode-badge.css +12 -0
  36. package/dist/parts/app-module-color.css +152 -0
  37. package/dist/parts/app-name-card.css +5 -0
  38. package/dist/parts/app-page-header.css +1 -1
  39. package/dist/parts/app-recovery-codes-extras.css +13 -0
  40. package/dist/parts/app-sidebar-meta.css +14 -3
  41. package/dist/parts/app-sidebar-provider.css +98 -0
  42. package/dist/parts/app-table-actions.css +16 -0
  43. package/dist/parts/app-top-progress.css +3 -0
  44. package/dist/parts/app-tree.css +6 -0
  45. package/dist/parts/app-type-picker.css +272 -0
  46. package/dist/parts/data-dl-numbered.css +17 -0
  47. package/dist/parts/data-graph.css +12 -4
  48. package/dist/parts/forms-combobox-catalog.css +142 -0
  49. package/dist/parts/forms-combobox-icons.css +40 -2
  50. package/dist/parts/forms-copy-field-extras.css +47 -0
  51. package/dist/parts/forms-field-extras.css +55 -0
  52. package/dist/parts/forms-form-section.css +39 -1
  53. package/dist/parts/forms-ledger.css +98 -0
  54. package/dist/parts/media-aspect-flush.css +6 -0
  55. package/dist/parts/media-barcode.css +25 -4
  56. package/dist/parts/media-doc-viewer.css +2 -0
  57. package/dist/parts/media-entity-card.css +5 -0
  58. package/dist/parts/media-glass-liquid.css +10 -5
  59. package/dist/parts/media-glass-options.css +37 -5
  60. package/dist/parts/media-glass.css +85 -35
  61. package/dist/parts/media-scrim.css +51 -0
  62. package/dist/parts/nav-topbar-variants.css +12 -4
  63. package/dist/parts/site-header-variants.css +40 -4
  64. package/dist/parts/site-hero-media.css +88 -0
  65. package/dist/parts/site-price-card.css +3 -1
  66. package/dist/parts/site-split-reverse.css +11 -0
  67. package/dist/parts/site-tint-card.css +5 -4
  68. package/dist/parts/utility-hover.css +6 -3
  69. package/dist/showcase.css +73 -31
  70. package/dist/sidebar.d.ts +22 -0
  71. package/dist/sidebar.js +161 -0
  72. package/dist/tabs.d.ts +9 -0
  73. package/dist/tabs.js +104 -0
  74. package/dist/theme.js +20 -4
  75. package/manifest.json +24 -0
  76. package/package.json +10 -2
  77. package/snippets/accordion-accent.html +1 -1
  78. package/snippets/copy-field.html +44 -6
  79. package/snippets/countdown.html +12 -0
  80. package/snippets/dropdown-menu.html +2 -0
  81. package/snippets/glass.html +3 -3
  82. package/snippets/hero-media.html +20 -0
  83. package/snippets/page-header.html +1 -1
  84. package/snippets/recovery-codes.html +55 -6
  85. package/snippets/scrim.html +19 -0
@@ -0,0 +1,11 @@
1
+ // File: packages/ui/src/countdown.d.ts
2
+ // Types for the countdown behaviour of the CSS countdown (.oc-countdown).
3
+
4
+ /** 90 -> "1:30", 3725 -> "1:02:05"; never below 0. */
5
+ export function formatCountdown(seconds: number): string;
6
+ /** Seconds left, the part of the total that is left (0..1) and "low" | "done" | "". */
7
+ export function countdownState(left: number, total: number, low?: number): { left: number; fraction: number; state: "" | "low" | "done" };
8
+ /** Starts one [data-oc-countdown] element; returns a function that stops it. Event: oc-countdown-end. */
9
+ export function bindCountdown(el: HTMLElement): () => void;
10
+ /** Starts every [data-oc-countdown] in scope. */
11
+ export function initCountdown(scope?: ParentNode): Array<() => void>;
@@ -0,0 +1,76 @@
1
+ // File: packages/ui/src/countdown.js
2
+ // Map: format seconds -> state of a moment (left, fraction, low, done) -> bind one [data-oc-countdown] (tick, write,
3
+ // end event) -> init every one -> boot
4
+ // Behaviour for the CSS countdown (.oc-countdown) in plain HTML and Blade. The element carries the end time
5
+ // (data-oc-countdown-end="2026-11-17T20:00:00", an ISO date or a timestamp in ms) or a duration from now
6
+ // (data-oc-countdown-seconds="90"); data-oc-countdown-total is the full time in seconds for the bar (default: the
7
+ // starting time), data-oc-countdown-low the seconds from which it turns orange (default 20% of the total, at most 60).
8
+ // The script writes the time into .oc-countdown-time, --oc-countdown-left and data-state (low, done).
9
+ // Event on the element: oc-countdown-end, once, when the time is up.
10
+
11
+ /** 90 -> "1:30", 3725 -> "1:02:05", never below 0. */
12
+ export function formatCountdown(seconds) {
13
+ const s = Math.max(0, Math.ceil(seconds));
14
+ const h = Math.floor(s / 3600);
15
+ const m = Math.floor((s % 3600) / 60);
16
+ const sec = s % 60;
17
+ const two = (n) => String(n).padStart(2, "0");
18
+ return h ? `${h}:${two(m)}:${two(sec)}` : `${m}:${two(sec)}`;
19
+ }
20
+
21
+ /** The state at one moment: seconds left, the part of the total that is left (0..1), and "low" / "done" / "". */
22
+ export function countdownState(left, total, low) {
23
+ const l = Math.max(0, left);
24
+ const t = total > 0 ? total : l || 1;
25
+ const lowAt = low ?? Math.min(60, t * 0.2);
26
+ return { left: l, fraction: Math.min(1, l / t), state: l <= 0 ? "done" : l <= lowAt ? "low" : "" };
27
+ }
28
+
29
+ /** Starts one countdown element. Returns a function that stops it. */
30
+ export function bindCountdown(el) {
31
+ if (el.dataset.ocBound != null) return () => {};
32
+ el.dataset.ocBound = "";
33
+ const d = el.dataset;
34
+ const now = Date.now();
35
+ const rawEnd = d.ocCountdownEnd;
36
+ const end = rawEnd ? (/^\d+$/.test(rawEnd) ? Number(rawEnd) : Date.parse(rawEnd)) : now + Number(d.ocCountdownSeconds || 0) * 1000;
37
+ const total = Number(d.ocCountdownTotal) || Math.max(1, (end - now) / 1000);
38
+ const low = d.ocCountdownLow != null ? Number(d.ocCountdownLow) : undefined;
39
+ const time = el.querySelector(".oc-countdown-time");
40
+ let ended = false;
41
+ const tick = () => {
42
+ const s = countdownState((end - Date.now()) / 1000, total, low);
43
+ if (time) time.textContent = formatCountdown(s.left);
44
+ el.style.setProperty("--oc-countdown-left", String(s.fraction));
45
+ if (s.state) el.dataset.state = s.state;
46
+ else delete el.dataset.state;
47
+ if (s.state === "done" && !ended) {
48
+ ended = true;
49
+ clearInterval(timer);
50
+ el.dispatchEvent(new CustomEvent("oc-countdown-end", { bubbles: true }));
51
+ }
52
+ };
53
+ const timer = setInterval(tick, 250);
54
+ tick();
55
+ return () => { clearInterval(timer); delete el.dataset.ocBound; };
56
+ }
57
+
58
+ /** Starts every [data-oc-countdown] under `scope`. */
59
+ export function initCountdown(scope = document) {
60
+ return [...scope.querySelectorAll("[data-oc-countdown]")].map(bindCountdown);
61
+ }
62
+
63
+ // Starts on its own as /js/oc-countdown.js (`npx omniaui copy-js countdown`), with ?auto in the URL or data-oc-auto on
64
+ // the tag.
65
+ function autoStart() {
66
+ if (typeof document === "undefined") return false;
67
+ const url = String(import.meta.url);
68
+ if (url.includes("oc-countdown") || /[?&]auto(=|&|$)/.test(url)) return true;
69
+ const file = url.split(/[?#]/)[0];
70
+ return [...document.querySelectorAll("script[data-oc-auto][src]")].some((s) => s.src.split(/[?#]/)[0] === file);
71
+ }
72
+ if (autoStart()) {
73
+ const boot = () => initCountdown(document);
74
+ if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", boot);
75
+ else boot();
76
+ }
@@ -7,3 +7,31 @@ export function toCsv(headers: string[], rows: string[][]): string;
7
7
  export function rowPasses(status: string | undefined, filter: string, text: string, query: string): boolean;
8
8
  export function bindDataTable(root: HTMLElement): void;
9
9
  export function initDataTables(scope?: ParentNode): void;
10
+
11
+ /** Server mode (0.17.0): detail of oc-datatable-query. page is 1-based. */
12
+ export interface DataTableQuery {
13
+ reason: "sort" | "page" | "pageSize" | "search" | "trashed" | "filter";
14
+ sort: string | null;
15
+ dir: "asc" | "desc";
16
+ page: number;
17
+ pageSize: number;
18
+ search: string;
19
+ trashed: string;
20
+ filters: Record<string, string>;
21
+ }
22
+
23
+ /** Server mode (0.17.0): the state the server answered, for plain HTML / Blade. */
24
+ export interface DataTableServerState {
25
+ total?: number;
26
+ /** 1-based. */
27
+ page?: number;
28
+ sort?: string | null;
29
+ dir?: "asc" | "desc";
30
+ trashed?: "active" | "all" | "deleted" | "archived";
31
+ loading?: boolean;
32
+ selected?: string[];
33
+ }
34
+
35
+ export function updateDataTable(root: HTMLElement, state?: DataTableServerState): void;
36
+ export function getDataTableSelection(root: HTMLElement): string[];
37
+ export function setDataTableSelection(root: HTMLElement, keys: Iterable<string>): void;
@@ -1,9 +1,17 @@
1
1
  // File: packages/ui/src/data-table.js
2
2
  // Map: page numbers -> compare -> csv -> row filter -> bind one table (search, column filters, sort, pages, columns, trash,
3
- // bulk, cards) -> boot. Column width and row drag are OmniaUI Pro (data-table-pro.js).
3
+ // bulk, cards) -> server mode (state from the DOM, oc-datatable-query) -> updateDataTable / setDataTableSelection -> boot.
4
+ // Column width and row drag are OmniaUI Pro (data-table-pro.js).
4
5
  // The list table for business apps. Markup stays plain HTML.
5
6
  // This script adds the behaviour. Excel, PDF and the real delete API stay in the app:
6
7
  // listen for oc-datatable-bulk, oc-datatable-row, oc-datatable-search and oc-datatable-import.
8
+ // Server mode (0.17.0): data-oc-server="true" on the root. The rows in the page ARE the current page: the script does not
9
+ // filter, sort or slice them. It keeps the controls (sort headers, trash pills, search, pager, rows per page, column
10
+ // filters) and fires oc-datatable-query { reason, sort, dir, page, pageSize, search, trashed, filters } on every change;
11
+ // the app fetches and puts the new rows in, with data-oc-total (all matches) and data-oc-current-page (1-based) on the root, and
12
+ // calls updateDataTable(root, state) or bindDataTable(root) again. aria-busy="true" on the root = loading (no empty text).
13
+ // Selection is kept by key over pages: oc-datatable-selection { keys } on every change.
14
+ // Column chooser: checkboxes [data-oc-visible-col="key"] fire oc-datatable-columns { visible } (the app renders the columns).
7
15
 
8
16
  /** Page numbers with ellipses, a window around the current page (current and last are 1-based). */
9
17
  export function pageItems(current, last) {
@@ -107,6 +115,13 @@ export function bindDataTable(root) {
107
115
  const sortSummary = root.querySelector("[data-oc-sort-summary]");
108
116
  const frame = root.querySelector(".oc-data-table-frame") || table.parentElement;
109
117
  const live = root.dataset.ocLive === "true";
118
+ // Texts the script writes itself (pager, selection count, sort line), translated with data-oc-labels on the root:
119
+ // data-oc-labels='{"nextPage":"Volgende pagina","selected":"{n} geselecteerd"}' (0.17.0). Missing keys stay English.
120
+ let T = {};
121
+ try { T = JSON.parse(root.dataset.ocLabels || "{}"); } catch { T = {}; }
122
+ const t = (key, fallback, vars = {}) => String(T[key] ?? fallback).replace(/\{(\w+)\}/g, (m, k) => (k in vars ? String(vars[k]) : m));
123
+ // data-oc-no-grid: no card view (the table only), also not from a stored choice.
124
+ const noGrid = root.hasAttribute("data-oc-no-grid");
110
125
 
111
126
  let query = "";
112
127
  let filter = root.querySelector("[data-oc-filter][aria-current='true']")?.dataset.ocFilter
@@ -123,15 +138,25 @@ export function bindDataTable(root) {
123
138
  let page = 0;
124
139
  let pageSize = Number(pageSelect?.value || root.dataset.pageSize || 15);
125
140
  const selected = new Set();
141
+ // Server mode is read live, so a wrapper can switch it on later. The page attribute only wins when it changed: a click
142
+ // on the pager moves at once and the app confirms it with the next data-oc-current-page.
143
+ const server = () => root.dataset.ocServer === "true";
144
+ let pageAttr;
145
+ let searchTimer = 0;
146
+ const searchDelay = () => {
147
+ const n = Number(root.dataset.ocSearchDelay);
148
+ return Number.isFinite(n) && n >= 0 ? n : 300;
149
+ };
126
150
 
127
151
  // Remembered choices from the last visit: page size, density, view, hidden columns.
128
152
  const savedSize = readStore(id, "pageSize");
129
- if (savedSize && pageSelect?.querySelector(`option[value="${savedSize}"]`)) {
153
+ // Server mode: the app owns the page size (it fetched that many rows), so no stored size.
154
+ if (!server() && savedSize && pageSelect?.querySelector(`option[value="${savedSize}"]`)) {
130
155
  pageSelect.value = String(savedSize);
131
156
  pageSize = Number(savedSize);
132
157
  }
133
158
  if (readStore(id, "density") === "compact") root.classList.add("oc-data-table--compact");
134
- if (readStore(id, "view") === "grid") root.classList.add("oc-data-table--grid");
159
+ if (!noGrid && readStore(id, "view") === "grid") root.classList.add("oc-data-table--grid");
135
160
  const savedCols = readStore(id, "cols") || {};
136
161
  root.querySelectorAll("[data-col]").forEach((box) => {
137
162
  if (!box.disabled && savedCols[box.dataset.col] != null) box.checked = savedCols[box.dataset.col];
@@ -165,7 +190,68 @@ export function bindDataTable(root) {
165
190
  return td ? (td.dataset.ocValue || td.textContent.trim()) : "";
166
191
  };
167
192
  const passesColumns = (row) => [...colFilters].every(([key, want]) => !want || valueOf(row, key) === want);
168
- const matched = () => rows().filter((row) => rowPasses(row.dataset.ocStatus, filter, textOf(row), query) && passesColumns(row));
193
+ // Server mode: every row in the page is a match (the server filtered them).
194
+ const matched = () => (server() ? rows() : rows().filter((row) => rowPasses(row.dataset.ocStatus, filter, textOf(row), query) && passesColumns(row)));
195
+
196
+ function emit(name, detail) {
197
+ root.dispatchEvent(new CustomEvent(name, { bubbles: true, detail }));
198
+ }
199
+ const emitSelection = () => emit("oc-datatable-selection", { keys: [...selected] });
200
+
201
+ /** Server mode: the state the app asked for, read from the markup (sort header, trash pill, page, rows per page). */
202
+ function readServerState() {
203
+ const sortedHead = [...table.tHead.rows[0].cells].find((th) => th.dataset.ocCol && th.hasAttribute("aria-sort") && th.getAttribute("aria-sort") !== "none");
204
+ sortKey = sortedHead ? sortedHead.dataset.ocCol : "";
205
+ sortDir = sortedHead?.getAttribute("aria-sort") === "descending" ? "desc" : "asc";
206
+ const pill = root.querySelector("[data-oc-filter][aria-current='true']");
207
+ if (pill) filter = pill.dataset.ocFilter;
208
+ if (root.dataset.ocCurrentPage !== pageAttr) {
209
+ pageAttr = root.dataset.ocCurrentPage;
210
+ if (pageAttr != null) page = Math.max(0, (Number(pageAttr) || 1) - 1);
211
+ }
212
+ if (pageSelect && Number(pageSelect.value)) pageSize = Number(pageSelect.value);
213
+ }
214
+
215
+ /** Server mode: tell the app what to fetch. */
216
+ function emitQuery(reason) {
217
+ emit("oc-datatable-query", {
218
+ reason,
219
+ sort: sortKey || null,
220
+ dir: sortDir,
221
+ page: page + 1,
222
+ pageSize,
223
+ search: search ? search.value.trim() : "",
224
+ trashed: filter,
225
+ filters: Object.fromEntries(colFilters),
226
+ });
227
+ }
228
+
229
+ /** Server mode: the rows stay as they are; only the summary, pager, empty text, cards and checks follow the state. */
230
+ function applyServer() {
231
+ readServerState();
232
+ const all = rows();
233
+ for (const row of all) {
234
+ if (row.hidden) queueMicrotask(() => redrawIcons(row));
235
+ row.hidden = false;
236
+ }
237
+ const busy = root.getAttribute("aria-busy") === "true";
238
+ const total = Math.max(0, Number(root.dataset.ocTotal ?? all.length) || 0);
239
+ const last = pageSize > 0 ? Math.max(1, Math.ceil(total / pageSize)) : 1;
240
+ const start = pageSize > 0 ? page * pageSize : 0;
241
+ if (empty) empty.hidden = busy || all.length !== 0;
242
+ if (summary) {
243
+ const template = summary.dataset.ocSummary || t("summary", "Showing {from}–{to} of {total}");
244
+ const values = { from: all.length ? start + 1 : 0, to: Math.min(total, start + all.length), total };
245
+ summary.textContent = template.replace(/\{(from|to|total)\}/g, (_, key) => String(values[key]));
246
+ }
247
+ if (sortSummary) {
248
+ const label = sortKey ? table.querySelector(`th[data-oc-col="${sortKey}"] .oc-table-sort`)?.textContent?.trim() : "";
249
+ sortSummary.textContent = label ? t("sortedBy", "Sorted by {label}, {dir}", { label, dir: sortDir === "asc" ? t("ascending", "ascending") : t("descending", "descending") }) : "";
250
+ }
251
+ renderPager(Math.min(page + 1, last), total === 0 ? 1 : last);
252
+ syncGrid(all);
253
+ paintChecks();
254
+ }
169
255
 
170
256
  function paintChecks() {
171
257
  for (const row of rows()) {
@@ -180,7 +266,7 @@ export function bindDataTable(root) {
180
266
  selectAll.checked = keys.length > 0 && picked === keys.length;
181
267
  selectAll.indeterminate = picked > 0 && picked < keys.length;
182
268
  }
183
- if (count) count.textContent = selected.size === 1 ? "1 selected" : `${selected.size} selected`;
269
+ if (count) count.textContent = t("selected", "{n} selected", { n: selected.size });
184
270
  if (bulk) bulk.hidden = selected.size === 0;
185
271
  }
186
272
 
@@ -199,8 +285,8 @@ export function bindDataTable(root) {
199
285
  if (extra?.label) button.setAttribute("aria-label", extra.label);
200
286
  pager.append(button);
201
287
  };
202
- add("«", 1, { disabled: current === 1, label: "First page" });
203
- add("‹", current - 1, { disabled: current === 1, label: "Previous page" });
288
+ add("«", 1, { disabled: current === 1, label: t("firstPage", "First page") });
289
+ add("‹", current - 1, { disabled: current === 1, label: t("previousPage", "Previous page") });
204
290
  for (const item of pageItems(current, last)) {
205
291
  if (item === "…") {
206
292
  const span = document.createElement("span");
@@ -209,11 +295,12 @@ export function bindDataTable(root) {
209
295
  pager.append(span);
210
296
  } else add(String(item), item, { current: item === current });
211
297
  }
212
- add("›", current + 1, { disabled: current === last, label: "Next page" });
213
- add("»", last, { disabled: current === last, label: "Last page" });
298
+ add("›", current + 1, { disabled: current === last, label: t("nextPage", "Next page") });
299
+ add("»", last, { disabled: current === last, label: t("lastPage", "Last page") });
214
300
  }
215
301
 
216
302
  function syncGrid(list) {
303
+ if (noGrid) return;
217
304
  let grid = root.querySelector(".oc-data-table-grid");
218
305
  if (!grid && frame) {
219
306
  grid = document.createElement("div");
@@ -272,6 +359,10 @@ export function bindDataTable(root) {
272
359
  }
273
360
 
274
361
  function apply() {
362
+ if (server()) {
363
+ applyServer();
364
+ return;
365
+ }
275
366
  const all = rows();
276
367
  const list = matched();
277
368
  if (sortKey) {
@@ -294,13 +385,13 @@ export function bindDataTable(root) {
294
385
  if (empty) empty.hidden = list.length !== 0;
295
386
  if (summary) {
296
387
  // data-oc-summary="Toont {from} t/m {to} van {total} resultaten" translates the line; empty = English.
297
- const template = summary.dataset.ocSummary || "Showing {from}–{to} of {total}";
388
+ const template = summary.dataset.ocSummary || t("summary", "Showing {from}–{to} of {total}");
298
389
  const values = { from: list.length ? start + 1 : 0, to: start + visible.size, total: list.length };
299
390
  summary.textContent = template.replace(/\{(from|to|total)\}/g, (_, key) => String(values[key]));
300
391
  }
301
392
  if (sortSummary) {
302
393
  const label = sortKey ? table.querySelector(`th[data-oc-col="${sortKey}"] .oc-table-sort`)?.textContent?.trim() : "";
303
- sortSummary.textContent = label ? `Sorted by ${label}, ${sortDir === "asc" ? "ascending" : "descending"}` : "";
394
+ sortSummary.textContent = label ? t("sortedBy", "Sorted by {label}, {dir}", { label, dir: sortDir === "asc" ? t("ascending", "ascending") : t("descending", "descending") }) : "";
304
395
  }
305
396
  renderPager(page + 1, list.length === 0 ? 1 : last);
306
397
  syncGrid([...visible]);
@@ -319,10 +410,6 @@ export function bindDataTable(root) {
319
410
  download(`${id}.csv`, toCsv(heads.map((th) => th.textContent.trim()), body));
320
411
  }
321
412
 
322
- function emit(name, detail) {
323
- root.dispatchEvent(new CustomEvent(name, { bubbles: true, detail }));
324
- }
325
-
326
413
  // Live mode (the docs demo) changes the rows in the page. An app listens and updates its own data.
327
414
  function liveAction(action) {
328
415
  if (!live) return false;
@@ -340,6 +427,7 @@ export function bindDataTable(root) {
340
427
  }
341
428
  selected.clear();
342
429
  apply();
430
+ emitSelection();
343
431
  return true;
344
432
  }
345
433
 
@@ -348,6 +436,12 @@ export function bindDataTable(root) {
348
436
  if (target === search) {
349
437
  query = target.value.trim().toLowerCase();
350
438
  page = 0;
439
+ if (server()) {
440
+ // Wait until the typing stops (data-oc-search-delay, default 300 ms), then ask the app once.
441
+ clearTimeout(searchTimer);
442
+ searchTimer = setTimeout(() => { page = 0; emitQuery("search"); apply(); }, searchDelay());
443
+ return;
444
+ }
351
445
  apply();
352
446
  }
353
447
  });
@@ -358,13 +452,20 @@ export function bindDataTable(root) {
358
452
  pageSize = Number(target.value) || 0;
359
453
  page = 0;
360
454
  writeStore(id, "pageSize", pageSize);
455
+ if (server()) emitQuery("pageSize");
361
456
  apply();
362
457
  }
363
458
  if (target.matches?.("select[data-oc-col-filter]")) {
364
459
  colFilters.set(target.dataset.ocColFilter, target.value);
365
460
  page = 0;
461
+ if (server()) emitQuery("filter");
366
462
  apply();
367
463
  }
464
+ if (target.matches?.("[data-oc-visible-col]")) {
465
+ // Column chooser: the app shows the columns (React/Vue/Livewire render only the visible ones).
466
+ const visible = [...root.querySelectorAll("[data-oc-visible-col]")].filter((box) => box.checked).map((box) => box.dataset.ocVisibleCol);
467
+ emit("oc-datatable-columns", { visible, key: target.dataset.ocVisibleCol, checked: target.checked });
468
+ }
368
469
  if (target.matches?.("[data-col]")) {
369
470
  const cols = {};
370
471
  root.querySelectorAll("[data-col]").forEach((box) => { cols[box.dataset.col] = box.checked; });
@@ -376,6 +477,7 @@ export function bindDataTable(root) {
376
477
  if (target.checked) selected.add(row.dataset.ocKey);
377
478
  else selected.delete(row.dataset.ocKey);
378
479
  paintChecks();
480
+ emitSelection();
379
481
  }
380
482
  if (target === selectAll) {
381
483
  for (const row of matched()) {
@@ -384,6 +486,7 @@ export function bindDataTable(root) {
384
486
  else selected.delete(row.dataset.ocKey);
385
487
  }
386
488
  paintChecks();
489
+ emitSelection();
387
490
  }
388
491
  if (target.matches?.("[data-oc-file]")) {
389
492
  const file = target.files?.[0];
@@ -395,6 +498,14 @@ export function bindDataTable(root) {
395
498
  root.addEventListener("keydown", (event) => {
396
499
  if (event.key === "Enter" && event.target === search) {
397
500
  emit("oc-datatable-search", { query: search.value });
501
+ // Server mode: Enter does not wait for the typing delay.
502
+ if (server() && searchTimer) {
503
+ clearTimeout(searchTimer);
504
+ searchTimer = 0;
505
+ page = 0;
506
+ emitQuery("search");
507
+ apply();
508
+ }
398
509
  }
399
510
  });
400
511
 
@@ -412,6 +523,7 @@ export function bindDataTable(root) {
412
523
  for (const head of table.tHead.rows[0].cells) head.removeAttribute("aria-sort");
413
524
  th.setAttribute("aria-sort", sortDir === "asc" ? "ascending" : "descending");
414
525
  page = 0;
526
+ if (server()) emitQuery("sort");
415
527
  apply();
416
528
  return;
417
529
  }
@@ -423,6 +535,7 @@ export function bindDataTable(root) {
423
535
  if (btn === filterBtn) btn.setAttribute("aria-current", "true");
424
536
  else btn.removeAttribute("aria-current");
425
537
  });
538
+ if (server()) emitQuery("trashed");
426
539
  apply();
427
540
  return;
428
541
  }
@@ -457,6 +570,7 @@ export function bindDataTable(root) {
457
570
  tab.setAttribute("aria-selected", tab === colTab ? "true" : "false");
458
571
  });
459
572
  page = 0;
573
+ if (server()) emitQuery("filter");
460
574
  apply();
461
575
  return;
462
576
  }
@@ -477,9 +591,10 @@ export function bindDataTable(root) {
477
591
  writeStore(id, "density", compact ? "compact" : "comfortable");
478
592
  return;
479
593
  }
480
- const pageBtn = event.target.closest("[data-oc-page]");
594
+ const pageBtn = event.target.closest("button[data-oc-page]");
481
595
  if (pageBtn && root.contains(pageBtn) && !pageBtn.disabled) {
482
596
  page = Number(pageBtn.dataset.ocPage) - 1;
597
+ if (server()) emitQuery("page");
483
598
  apply();
484
599
  return;
485
600
  }
@@ -496,7 +611,7 @@ export function bindDataTable(root) {
496
611
  const action = bulkBtn.dataset.ocBulk;
497
612
  // Snapshot first: live mode clears the selection while it updates the rows.
498
613
  const keys = [...selected];
499
- if (action === "clear") { selected.clear(); paintChecks(); return; }
614
+ if (action === "clear") { selected.clear(); paintChecks(); emitSelection(); return; }
500
615
  if (action === "export") { exportCsv(selected); return; }
501
616
  liveAction(action);
502
617
  emit("oc-datatable-bulk", { action, keys });
@@ -526,7 +641,60 @@ export function bindDataTable(root) {
526
641
  });
527
642
 
528
643
  apply();
529
- controls.set(root, { apply });
644
+ controls.set(root, {
645
+ apply,
646
+ // Replace the selection (a controlled selectedKeys); no event, the caller already knows.
647
+ setSelection(keys) {
648
+ selected.clear();
649
+ for (const key of keys || []) selected.add(String(key));
650
+ paintChecks();
651
+ },
652
+ getSelection: () => [...selected],
653
+ });
654
+ }
655
+
656
+ /** The selected row keys of a wired table (kept over pages and filters). */
657
+ export function getDataTableSelection(root) {
658
+ return controls.get(root)?.getSelection() ?? [];
659
+ }
660
+
661
+ /** Set the selected row keys of a wired table (selection over pages: keys that are not on this page stay selected). */
662
+ export function setDataTableSelection(root, keys) {
663
+ if (!root) return;
664
+ if (!controls.get(root)) bindDataTable(root);
665
+ controls.get(root)?.setSelection(keys);
666
+ }
667
+
668
+ /**
669
+ * Server mode helper for plain HTML / Blade: put the state the server answered on the table and show it again.
670
+ * state: { total, page (1-based), sort (column key or null), dir ("asc" | "desc"), trashed, loading, selected }.
671
+ * Replace the <tbody> rows yourself first (each tr[data-oc-row][data-oc-key]).
672
+ */
673
+ export function updateDataTable(root, state = {}) {
674
+ if (!root) return;
675
+ root.dataset.ocServer = root.dataset.ocServer || "true";
676
+ if (state.total != null) root.dataset.ocTotal = String(state.total);
677
+ if (state.page != null) root.dataset.ocCurrentPage = String(state.page);
678
+ if (state.loading != null) {
679
+ if (state.loading) root.setAttribute("aria-busy", "true");
680
+ else root.removeAttribute("aria-busy");
681
+ }
682
+ const head = root.querySelector("table")?.tHead?.rows[0];
683
+ if (head && "sort" in state) {
684
+ for (const th of head.cells) {
685
+ if (!th.dataset.ocCol) continue;
686
+ if (state.sort && th.dataset.ocCol === state.sort) th.setAttribute("aria-sort", state.dir === "desc" ? "descending" : "ascending");
687
+ else th.removeAttribute("aria-sort");
688
+ }
689
+ }
690
+ if (state.trashed) {
691
+ root.querySelectorAll("[data-oc-filter]").forEach((btn) => {
692
+ if (btn.dataset.ocFilter === state.trashed) btn.setAttribute("aria-current", "true");
693
+ else btn.removeAttribute("aria-current");
694
+ });
695
+ }
696
+ bindDataTable(root);
697
+ if (state.selected) setDataTableSelection(root, state.selected);
530
698
  }
531
699
 
532
700
  /** Wire every table under scope that is not wired yet (also the data table block: [data-oc-data-table]). */
package/dist/docs-ui.css CHANGED
@@ -148,10 +148,20 @@
148
148
  .oc-topbar-toggle:focus-visible + .oc-topbar-burger { outline: 2px solid var(--oc-ring); outline-offset: 2px; }
149
149
  @media (max-width: 760px) {
150
150
  .oc-topbar { padding-block: 8px; }
151
- .oc-topbar--collapsible .oc-topbar-burger { display: inline-flex; }
151
+ .oc-topbar--collapsible .oc-topbar-burger { display: inline-flex; order: 2; }
152
+ .oc-topbar--collapsible .oc-topbar-actions { margin-inline-start: auto; }
152
153
  .oc-topbar--collapsible .oc-topbar-nav { display: none; order: 3; inline-size: 100%; }
153
154
  .oc-topbar--collapsible:has(.oc-topbar-toggle:checked) .oc-topbar-nav { display: block; }
154
155
  }
156
+ /* The collapsible header also folds when its own box is narrower than 47.5rem (a sidebar layout, a content column,
157
+ a demo preview), not only on a narrow screen: brand, burger and actions then stay on one row. */
158
+ .oc-topbar--collapsible { container: oc-topbar / inline-size; }
159
+ @container oc-topbar (max-width: 47.5rem) {
160
+ .oc-topbar--collapsible .oc-topbar-burger { display: inline-flex; order: 2; }
161
+ .oc-topbar--collapsible .oc-topbar-actions { margin-inline-start: auto; }
162
+ .oc-topbar--collapsible .oc-topbar-nav { display: none; order: 3; inline-size: 100%; grid-column: 1 / -1; }
163
+ .oc-topbar--collapsible:has(.oc-topbar-toggle:checked) .oc-topbar-nav { display: block; }
164
+ }
155
165
 
156
166
  /* ---- Site footer bar: .oc-footerbar ------------------------------------------------------------- */
157
167
  .oc-footerbar {
@@ -0,0 +1,41 @@
1
+ // File: packages/ui/src/glass-lens.d.ts
2
+ // Types for the lens of the glass (.oc-glass, .oc-glass-bar): Chromium bends the backdrop at the edge. Plus the optional
3
+ // drag: data-oc-glass-drag moves a sheet over its backdrop.
4
+
5
+ /** Default displacement scale (-80): a bigger number bends more, the minus sign turns the direction. */
6
+ export const LENS_SCALE: number;
7
+ /** The sheets initGlassLens and the auto-start give a lens. */
8
+ export const LENS_SELECTOR: string;
9
+ /** True in Chromium browsers (Chrome, Edge, Opera, Electron), the only ones that apply url() in backdrop-filter. */
10
+ export function supportsGlassLens(nav?: Navigator): boolean;
11
+ /** The displacement map for a sheet of w x h px (SVG data URI). */
12
+ export function lensMap(w: number, h: number, radius?: number): string;
13
+ /** The scale used on a sheet of w x h: full from a short side of 160px, proportionally less below. */
14
+ export function lensScale(w: number, h: number, scale?: number): number;
15
+ /** Filter id for a size and scale: "oc-lens-320x180". */
16
+ export function lensId(w: number, h: number, scale?: number): string;
17
+ /** Makes or reuses the filter for w x h (one per size) and counts a user; returns its id. */
18
+ export function acquireLens(doc: Document, w: number, h: number, scale?: number, radius?: number): string;
19
+ /** One user less; the filter goes away when nobody uses it. */
20
+ export function releaseLens(doc: Document, id: string): void;
21
+ /** Number of lens filters on the page. */
22
+ export function lensCount(): number;
23
+ /** Gives one sheet the lens (--oc-glass-lens, data-oc-lens) and follows its size; returns a function that removes it.
24
+ * Outside Chromium it only adds html.oc-no-lens (frosted glass). `force` skips the browser check (tests). */
25
+ export function bindGlassLens(el: HTMLElement, options?: { force?: boolean }): () => void;
26
+ /** Gives every glass sheet in scope the lens. */
27
+ export function initGlassLens(scope?: ParentNode, options?: { force?: boolean }): Array<() => void>;
28
+
29
+ /** The sheets initGlassDrag and the auto-start make draggable: "[data-oc-glass-drag]". */
30
+ export const DRAG_SELECTOR: string;
31
+ /** Keyboard step in px for the arrow keys (Shift: four times as far). */
32
+ export const DRAG_STEP: number;
33
+ /** x/y clamped so the sheet stays inside its area (closest [data-oc-glass-drag-area], else the parent). */
34
+ export function clampGlassDrag(el: HTMLElement, x: number, y: number, state?: { x: number; y: number }): [number, number];
35
+ /** Moves a draggable sheet to x/y px from its place in the layout (clamped); fires "oc-glass-move" with { x, y }. */
36
+ export function moveGlass(el: HTMLElement, x: number, y: number): void;
37
+ /** Makes one sheet draggable with mouse, touch and keyboard (focusable, arrows, Home); returns a function that undoes it.
38
+ * `label` is the aria-label when the sheet has none (default "Drag to move"). */
39
+ export function bindGlassDrag(el: HTMLElement, options?: { label?: string }): () => void;
40
+ /** Makes every [data-oc-glass-drag] in scope draggable. */
41
+ export function initGlassDrag(scope?: ParentNode): Array<() => void>;