actual-css 0.16.0 → 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 (79) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/README.md +8 -4
  3. package/components.json +21 -5
  4. package/dist/actual.full.css +410 -75
  5. package/dist/actual.full.js +2 -1
  6. package/dist/actual.full.min.css +1 -1
  7. package/docs/design-notes/app-ui.md +37 -3
  8. package/docs/design-notes/enhancement-contract.md +3 -1
  9. package/docs/design-notes/tokens.md +2 -0
  10. package/docs/navigation.json +14 -1
  11. package/docs/pages/components/accordion.md +5 -0
  12. package/docs/pages/components/alert.md +45 -17
  13. package/docs/pages/components/button.md +3 -0
  14. package/docs/pages/components/chat.md +20 -0
  15. package/docs/pages/components/dialog.md +36 -0
  16. package/docs/pages/components/drawer.md +52 -8
  17. package/docs/pages/components/navbar.md +26 -2
  18. package/docs/pages/components/rating.md +111 -12
  19. package/docs/pages/components/segmented.md +36 -1
  20. package/docs/pages/components/spinner.md +2 -0
  21. package/docs/pages/components/table.md +77 -0
  22. package/docs/pages/components/timeline.md +3 -1
  23. package/docs/pages/enhancements/flyout.md +83 -14
  24. package/docs/pages/enhancements/status-bar.md +1 -0
  25. package/docs/pages/enhancements/tabs.md +5 -0
  26. package/docs/pages/examples/overview.md +7 -1
  27. package/docs/pages/forms/ajax.md +101 -0
  28. package/docs/pages/forms/color-swatches.md +31 -2
  29. package/docs/pages/forms/date-picker.md +6 -0
  30. package/docs/pages/forms/joined-controls.md +8 -3
  31. package/docs/pages/forms/overview.md +2 -2
  32. package/docs/pages/forms/sticky-actions.md +2 -0
  33. package/docs/pages/forms/unsaved-changes.md +198 -0
  34. package/docs/pages/foundations/philosophy.md +2 -1
  35. package/docs/pages/foundations/theming.md +21 -4
  36. package/docs/pages/foundations/tokens.md +1 -1
  37. package/docs/pages/guides/introduction.md +1 -1
  38. package/docs/pages/guides/progressive-enhancement.md +30 -49
  39. package/docs/pages/guides/upgrading.md +16 -3
  40. package/docs/pages/layout/choosing.md +5 -0
  41. package/docs/pages/layout/column-layout.md +22 -8
  42. package/docs/pages/layout/scroll-snap.md +69 -2
  43. package/docs/pages/layout/sidebar-shell.md +68 -0
  44. package/docs/pages/patterns/empty-state.md +74 -0
  45. package/docs/pages/patterns/hierarchical-nav.md +40 -19
  46. package/docs/pages/patterns/navigation-list.md +3 -60
  47. package/docs/pages/patterns/stat.md +61 -0
  48. package/docs/pages/utilities/accessibility.md +32 -10
  49. package/package.json +4 -1
  50. package/reserved-classes.json +2 -0
  51. package/src/css/components/busy.css +25 -0
  52. package/src/css/components/button.css +3 -0
  53. package/src/css/components/chat.css +5 -1
  54. package/src/css/components/drawer.css +37 -3
  55. package/src/css/components/flyout.css +37 -0
  56. package/src/css/components/modal.css +3 -0
  57. package/src/css/components/navbar.css +99 -38
  58. package/src/css/components/rating.css +50 -5
  59. package/src/css/components/segmented.css +25 -2
  60. package/src/css/components/status-bar.css +4 -2
  61. package/src/css/forms/choice-card.css +5 -2
  62. package/src/css/forms/color-swatch.css +38 -19
  63. package/src/css/forms/custom-select.css +5 -0
  64. package/src/css/forms/form.css +3 -1
  65. package/src/css/layout/index.css +2 -0
  66. package/src/css/layout/sidebar-shell.css +67 -0
  67. package/src/js/ajax.js +148 -0
  68. package/src/js/dialog.js +59 -2
  69. package/src/js/dirty.js +140 -0
  70. package/src/js/dismiss.js +25 -0
  71. package/src/js/events.js +17 -0
  72. package/src/js/focus.js +12 -0
  73. package/src/js/form-submission.js +34 -0
  74. package/src/js/full.js +2 -0
  75. package/src/js/selectors.js +10 -2
  76. package/src/js/status.js +71 -10
  77. package/src/js/tab.js +16 -2
  78. package/src/js/validation.js +12 -4
  79. package/src/tooling/theme-contrast.js +3 -2
package/src/js/ajax.js ADDED
@@ -0,0 +1,148 @@
1
+ /*
2
+ * Ajax — optional fetch transport for HTML forms.
3
+ *
4
+ * Opt in with data-enhance="ajax". A submission the module can reproduce
5
+ * faithfully is sent with fetch; anything else is left to the browser:
6
+ * method="dialog", enctype="text/plain", a target other than the page itself,
7
+ * or a cross-origin action. Refusing beats approximating, and the native path
8
+ * always works.
9
+ *
10
+ * Transport: one request at a time per form, aria-busy on the form and the
11
+ * submitter, the request aborted when the form leaves the page, redirects
12
+ * followed by navigation like a native submission.
13
+ *
14
+ * Display, kept apart: with data-ajax-target, an HTML response (2xx or 422)
15
+ * replaces the target's content. Everything else only reaches the events.
16
+ * The module never decides that a response means "saved".
17
+ */
18
+
19
+ import { registerEnhancement } from "./enhance.js";
20
+ import { EVENTS } from "./events.js";
21
+ import { submissionSetting, submissionTarget } from "./form-submission.js";
22
+
23
+ const BUSY = "aria-busy";
24
+ const ENCODINGS = new Set(["application/x-www-form-urlencoded", "multipart/form-data"]);
25
+
26
+ function isFormElement(el) {
27
+ return typeof HTMLFormElement !== "undefined" && el instanceof HTMLFormElement;
28
+ }
29
+
30
+ // URL encoding as a native submission does it: CRLF newlines, and a file
31
+ // sent as its name. URLSearchParams alone would send "[object File]".
32
+ function urlEncoded(data) {
33
+ const params = new URLSearchParams();
34
+ const crlf = (value) => value.replace(/\r\n?|\n/g, "\r\n");
35
+ for (const [name, value] of data) {
36
+ params.append(crlf(name), crlf(typeof value === "string" ? value : value.name));
37
+ }
38
+ return params;
39
+ }
40
+
41
+ /** Builds the request, or returns null for a submission left to the browser. */
42
+ function requestFor(form, submitter) {
43
+ const method = submissionSetting(form, submitter, "method");
44
+ const enctype = submissionSetting(form, submitter, "enctype");
45
+ const target = submissionTarget(form, submitter).toLowerCase();
46
+ if (method !== "get" && method !== "post") return null;
47
+ if (target !== "" && target !== "_self") return null;
48
+ if (method === "post" && !ENCODINGS.has(enctype)) return null;
49
+ const url = new URL(submissionSetting(form, submitter, "action"));
50
+ // Cross-origin would need CORS and send no cookies: the native submission
51
+ // works where fetch would fail. (file: pages compare "null" to "null".)
52
+ if (url.origin !== form.ownerDocument.location.origin) return null;
53
+
54
+ const data = new FormData(form, submitter);
55
+ // De facto marker servers use to answer with a fragment instead of a page.
56
+ const init = { method, headers: { Accept: "text/html", "X-Requested-With": "XMLHttpRequest" } };
57
+ if (method === "get") url.search = urlEncoded(data).toString();
58
+ else init.body = enctype === "multipart/form-data" ? data : urlEncoded(data);
59
+ return { url, init };
60
+ }
61
+
62
+ function targetElement(root, selector) {
63
+ try {
64
+ return root.querySelector(selector);
65
+ } catch {
66
+ // A configuration error, not a failed request: keep it out of ajax-error.
67
+ console.warn(`data-ajax-target is not a valid selector: "${selector}"`);
68
+ return null;
69
+ }
70
+ }
71
+
72
+ function display(form, root, response) {
73
+ const selector = form.dataset.ajaxTarget;
74
+ if (!selector || !(response.ok || response.status === 422)) return null;
75
+ const type = response.headers.get("Content-Type")?.toLowerCase() ?? "";
76
+ if (!type.includes("text/html")) return null;
77
+ const target = targetElement(root, selector);
78
+ if (!target) return null;
79
+ // The clone leaves the original body readable by event listeners.
80
+ return response
81
+ .clone()
82
+ .text()
83
+ .then((html) => {
84
+ target.innerHTML = html;
85
+ });
86
+ }
87
+
88
+ function connectForm(form) {
89
+ const root = form.getRootNode();
90
+ const lifetime = new AbortController();
91
+ let pending = false;
92
+
93
+ // A target that contains the form (the server re-renders the whole form)
94
+ // detaches it; the root still reaches document listeners.
95
+ const emit = (name, detail) => {
96
+ const origin = form.isConnected ? form : root;
97
+ origin.dispatchEvent(new CustomEvent(name, { bubbles: true, detail: { form, ...detail } }));
98
+ };
99
+
100
+ const send = async (submitter, { url, init }) => {
101
+ pending = true;
102
+ // Restored afterwards, not removed: an authored aria-busy="false" is what
103
+ // keeps a last-child .spinner hidden at rest (busy.css).
104
+ const busy = [form, submitter].filter(Boolean).map((el) => [el, el.getAttribute(BUSY)]);
105
+ for (const [el] of busy) el.setAttribute(BUSY, "true");
106
+ emit(EVENTS.ajaxStart, { submitter });
107
+ try {
108
+ const response = await fetch(url, { ...init, signal: lifetime.signal });
109
+ if (response.redirected) {
110
+ emit(EVENTS.ajaxResponse, { submitter, response });
111
+ location.assign(response.url);
112
+ return;
113
+ }
114
+ await display(form, root, response);
115
+ emit(EVENTS.ajaxResponse, { submitter, response });
116
+ } catch (error) {
117
+ // An abort means the form left the page: nobody is listening.
118
+ if (!lifetime.signal.aborted) emit(EVENTS.ajaxError, { submitter, error });
119
+ } finally {
120
+ pending = false;
121
+ for (const [el, rest] of busy) {
122
+ if (rest === null) el.removeAttribute(BUSY);
123
+ else el.setAttribute(BUSY, rest);
124
+ }
125
+ }
126
+ };
127
+
128
+ // Listen on the root, after the form's own listeners: validation (or the
129
+ // application) cancels or stops an invalid submission before it gets here,
130
+ // whatever order the enhancers started in.
131
+ root.addEventListener(
132
+ "submit",
133
+ (event) => {
134
+ if (event.target !== form || event.defaultPrevented) return;
135
+ // Decide first: a submission left to the browser (a dialog's Cancel)
136
+ // goes through even while a request runs.
137
+ const request = requestFor(form, event.submitter);
138
+ if (!request) return;
139
+ event.preventDefault();
140
+ if (!pending) send(event.submitter, request); // one request at a time
141
+ },
142
+ { signal: lifetime.signal },
143
+ );
144
+
145
+ return () => lifetime.abort();
146
+ }
147
+
148
+ registerEnhancement("ajax", (el) => (isFormElement(el) ? connectForm(el) : undefined));
package/src/js/dialog.js CHANGED
@@ -15,6 +15,8 @@
15
15
  * indicator on backdrop click. Escape and explicit close requests always
16
16
  * close, unless an application cancels the actual:dialog-cancel event, and
17
17
  * closedby="none" keeps its native meaning (no Escape, no backdrop close).
18
+ * data-dialog-open opens the dialog once the document is parsed, in its
19
+ * data-dialog-modal mode; with `open` it upgrades the no-JS rendering.
18
20
  *
19
21
  * View transitions (opt-in via data-dialog-view-transition):
20
22
  * When the browser supports document.startViewTransition and the user allows
@@ -30,9 +32,12 @@
30
32
  import { registerCommands, targetFor } from "./command.js";
31
33
  import enhance, { registerEnhancement } from "./enhance.js";
32
34
  import { EVENTS } from "./events.js";
35
+ import { submissionSetting } from "./form-submission.js";
36
+ import { afterParse } from "./parsed.js";
33
37
  import { CLASSES } from "./selectors.js";
34
38
 
35
39
  const dialogMap = new WeakMap();
40
+ const autoOpened = new WeakSet();
36
41
  const wiredDialogs = new Set();
37
42
  const delegatedDialogs = new WeakSet();
38
43
  // HTML has no non-modal dialog keyword, so non-modal opening is the custom
@@ -400,7 +405,9 @@ function handleDialogSubmit(event) {
400
405
  const form = event.target;
401
406
 
402
407
  if (!(form instanceof HTMLFormElement)) return;
403
- if (form.method.toLowerCase() !== "dialog") return;
408
+ // formmethod on the submitter wins, as natively: a Save posting from a
409
+ // method="dialog" form must not close the dialog.
410
+ if (submissionSetting(form, event.submitter, "method") !== "dialog") return;
404
411
  if (!canViewTransition(dialog, dialogMap.get(dialog)?.restoreFocusTo)) return;
405
412
 
406
413
  event.preventDefault();
@@ -440,6 +447,9 @@ function handleDialogCancel(event) {
440
447
 
441
448
  function handleDialogClose(event) {
442
449
  const dialog = event.currentTarget;
450
+ // close is queued as a task: a dialog closed then reopened in the same task
451
+ // receives it while open again, and the cleanup would undo the new opening.
452
+ if (dialog.open) return;
443
453
  const state = dialogMap.get(dialog);
444
454
 
445
455
  clearVtName(dialog);
@@ -508,9 +518,56 @@ function ensureDialogWired(dialog) {
508
518
  return state;
509
519
  }
510
520
 
521
+ /* The close() that precedes an upgrade queues a close event for a dialog
522
+ nobody closed. Window capture stops it before downstream listeners, even
523
+ though close does not bubble; earlier window capture listeners still see it. */
524
+ function swallowNextClose(dialog) {
525
+ const view = dialog.ownerDocument.defaultView;
526
+ if (!view) return;
527
+ const { controller } = ensureDialogWired(dialog);
528
+ const swallow = (event) => {
529
+ if (event.target !== dialog) return;
530
+ view.removeEventListener("close", swallow, true);
531
+ if (dialog.open) event.stopImmediatePropagation();
532
+ };
533
+ // A detached dialog's queued event no longer passes through the window.
534
+ view.addEventListener("close", swallow, { capture: true, signal: controller.signal });
535
+ }
536
+
537
+ /* data-dialog-open: open once per element, for a page the server rendered
538
+ with the dialog showing. A dialog that also carries `open` is already shown
539
+ without JavaScript, non-modally; the runtime upgrades it to its modal mode.
540
+ A reinserted node does not reopen; a new node does. */
541
+ function autoOpen(dialog) {
542
+ if (!boolData(dialog, "data-dialog-open") || autoOpened.has(dialog)) return;
543
+ if (dialog.open) {
544
+ // Already modal (a command came first), or meant to stay non-modal.
545
+ if (isModalOpen(dialog) || !isModal(dialog)) {
546
+ autoOpened.add(dialog);
547
+ return;
548
+ }
549
+ // showModal() throws on a dialog that is open non-modally.
550
+ swallowNextClose(dialog);
551
+ dialog.close();
552
+ }
553
+ openDialog(dialog);
554
+ if (dialog.open) {
555
+ // No trigger owns this opening: leave focus restoration to the browser,
556
+ // and do not morph the closing dialog into the previously active element.
557
+ dialogMap.get(dialog).restoreFocusTo = null;
558
+ autoOpened.add(dialog);
559
+ }
560
+ }
561
+
511
562
  function connectDialog(dialog) {
512
563
  ensureDialogWired(dialog);
513
- return () => disconnectDialog(dialog);
564
+ // Once parsed: the title that labels the dialog and the control that takes
565
+ // initial focus may not exist yet when its start tag connects.
566
+ const cancelOpen = afterParse(dialog, () => autoOpen(dialog));
567
+ return () => {
568
+ cancelOpen();
569
+ disconnectDialog(dialog);
570
+ };
514
571
  }
515
572
 
516
573
  function ensureDelegatedDialog(dialog) {
@@ -0,0 +1,140 @@
1
+ /*
2
+ * Dirty — optional unsaved-changes tracking for forms.
3
+ *
4
+ * Opt in with data-enhance="dirty". The form carries data-dirty while the
5
+ * data it would submit differs from its baseline, and dispatches
6
+ * actual:dirty-change ({ form, dirty }) after each transition. The event
7
+ * reports state; it cannot veto it.
8
+ *
9
+ * The module observes, it never submits and never guards navigation: the
10
+ * transport (native, fetch, htmx, a library) decides when data is saved and
11
+ * tells the module through FormDirty.markClean().
12
+ *
13
+ * Comparison runs on FormData, so it covers exactly what would be submitted:
14
+ * disabled and unnamed controls do not count, form-associated controls
15
+ * outside the <form> do. Controls marked data-dirty-ignore are left out by
16
+ * name (CSRF tokens, computed fields).
17
+ */
18
+
19
+ import { registerEnhancement } from "./enhance.js";
20
+ import { EVENTS } from "./events.js";
21
+
22
+ const ATTR = "data-dirty";
23
+ const IGNORE_ATTR = "data-dirty-ignore";
24
+
25
+ // Baselines outlive the enhancer instance on purpose: a form removed and
26
+ // reinserted keeps its baseline, so moving or re-parenting it does not
27
+ // silently mark unsaved edits as clean.
28
+ const baselines = new WeakMap();
29
+ const connected = new WeakSet();
30
+
31
+ function isFormElement(el) {
32
+ return typeof HTMLFormElement !== "undefined" && el instanceof HTMLFormElement;
33
+ }
34
+
35
+ function ignoredNames(form) {
36
+ const names = new Set();
37
+ for (const el of form.elements) {
38
+ if (el.hasAttribute(IGNORE_ATTR) && el.name) names.add(el.name);
39
+ }
40
+ return names;
41
+ }
42
+
43
+ // A file is compared by identity hints, not content: two different files with
44
+ // the same name, size and timestamp read as unchanged. An empty file input
45
+ // still yields an entry, whose lastModified is "now" — normalized so an
46
+ // untouched input stays clean.
47
+ function fileKey(file) {
48
+ if (file.name === "" && file.size === 0) return [];
49
+ return [file.name, file.size, file.lastModified];
50
+ }
51
+
52
+ /**
53
+ * Serializes the data the form would submit, in submission order.
54
+ * new FormData(form) fires the form's formdata event, so an entry a listener
55
+ * adds there counts too; a volatile one (a nonce) keeps the form dirty unless
56
+ * it shares a name with a data-dirty-ignore control.
57
+ */
58
+ function capture(form) {
59
+ if (!isFormElement(form)) throw new TypeError("FormDirty expects an HTMLFormElement.");
60
+ const ignored = ignoredNames(form);
61
+ const entries = [];
62
+ for (const [name, value] of new FormData(form)) {
63
+ if (ignored.has(name)) continue;
64
+ entries.push([name, typeof value === "string" ? value : fileKey(value)]);
65
+ }
66
+ // JSON keeps names and values unambiguous: no separator a value can forge.
67
+ return JSON.stringify(entries);
68
+ }
69
+
70
+ function refresh(form) {
71
+ if (!connected.has(form)) return;
72
+ const dirty = capture(form) !== baselines.get(form);
73
+ if (dirty === form.hasAttribute(ATTR)) return;
74
+ form.toggleAttribute(ATTR, dirty);
75
+ form.dispatchEvent(
76
+ new CustomEvent(EVENTS.dirtyChange, { bubbles: true, detail: { form, dirty } }),
77
+ );
78
+ }
79
+
80
+ function connectForm(form) {
81
+ if (!baselines.has(form)) baselines.set(form, capture(form));
82
+ connected.add(form);
83
+
84
+ const controller = new AbortController();
85
+ const options = { signal: controller.signal };
86
+ const update = () => refresh(form);
87
+ const onEdit = ({ target }) => {
88
+ // A form-associated custom element exposes no .form on its host, but it
89
+ // is listed in form.elements like any native control.
90
+ if (target.form === form || Array.prototype.includes.call(form.elements, target)) update();
91
+ };
92
+
93
+ // Listen on the root: a control associated through form="…" sits outside
94
+ // the <form>, so its events never bubble through it.
95
+ const root = form.getRootNode();
96
+ root.addEventListener("input", onEdit, options);
97
+ root.addEventListener("change", onEdit, options);
98
+ // The reset event fires before the controls revert, and microtasks would
99
+ // run between listeners of a user-initiated reset — still too early. A task
100
+ // runs after the reset algorithm completes.
101
+ form.addEventListener("reset", () => setTimeout(update), options);
102
+
103
+ refresh(form);
104
+
105
+ // Release listeners only: data-dirty and the baseline stay, like validation
106
+ // state, so a reinserted form resumes where it was.
107
+ return () => {
108
+ controller.abort();
109
+ connected.delete(form);
110
+ };
111
+ }
112
+
113
+ // biome-ignore lint/complexity/noStaticOnlyClass: Stable public namespace, like FormValidator.
114
+ export class FormDirty {
115
+ /**
116
+ * Opaque snapshot of what the form would submit. Take it at submit time
117
+ * and pass it to markClean() once that submission is saved, so edits
118
+ * made during the request stay dirty.
119
+ */
120
+ static capture(form) {
121
+ return capture(form);
122
+ }
123
+
124
+ /**
125
+ * Makes `snapshot` (default: current data) the new baseline. Also valid
126
+ * before the form is enhanced: connection keeps an existing baseline.
127
+ */
128
+ static markClean(form, snapshot) {
129
+ if (!isFormElement(form)) return;
130
+ baselines.set(form, snapshot ?? capture(form));
131
+ refresh(form);
132
+ }
133
+
134
+ /** Re-evaluates an enhanced form after programmatic edits or added controls. */
135
+ static refresh(form) {
136
+ if (isFormElement(form)) refresh(form);
137
+ }
138
+ }
139
+
140
+ registerEnhancement("dirty", (el) => (isFormElement(el) ? connectForm(el) : undefined));
package/src/js/dismiss.js CHANGED
@@ -1,13 +1,32 @@
1
1
  /*
2
2
  * Dismiss command — the generic `--dismiss` action. Hides the resolved target
3
3
  * and emits the bubbling `actual:dismiss` event.
4
+ *
5
+ * Focus contract: when focus is inside the target (the usual case, a close
6
+ * button in an alert), it moves to the next tab stop after the target, else to
7
+ * the nearest ancestor with an explicit tabindex; with neither, the browser's
8
+ * focus fixup applies. Focus outside the target is left alone, and so is focus
9
+ * a listener of `actual:dismiss` placed itself (a surface restores its opener).
4
10
  */
5
11
 
6
12
  import { registerCommands } from "./command.js";
7
13
  import { EVENTS } from "./events.js";
14
+ import { isElementVisible, nextTabStop } from "./focus.js";
15
+
16
+ function focusSuccessor(target) {
17
+ const next = nextTabStop(target);
18
+ if (next) return next;
19
+ const region = target.parentElement?.closest("[tabindex]");
20
+ return region && isElementVisible(region) && !region.closest("[inert]") ? region : null;
21
+ }
8
22
 
9
23
  registerCommands("--dismiss", {
10
24
  handle(_event, trigger, target) {
25
+ const doc = target.ownerDocument;
26
+ // Resolved before hiding: a browser may move focus as soon as the focused
27
+ // element is hidden, so a check made afterwards would miss it, and the
28
+ // successor search needs the target's descendants still visible to skip.
29
+ const successor = target.contains(doc.activeElement) ? focusSuccessor(target) : null;
11
30
  target.hidden = true;
12
31
  target.dispatchEvent(
13
32
  new CustomEvent(EVENTS.dismiss, {
@@ -15,5 +34,11 @@ registerCommands("--dismiss", {
15
34
  detail: { trigger },
16
35
  }),
17
36
  );
37
+ // Only when focus is still stranded: in the hidden target, or dropped to
38
+ // <body> by the browser. No scroll: the next Tab scrolls to the successor.
39
+ const active = doc.activeElement;
40
+ if (successor && (!active || active === doc.body || target.contains(active))) {
41
+ successor.focus({ preventScroll: true });
42
+ }
18
43
  },
19
44
  });
package/src/js/events.js CHANGED
@@ -13,6 +13,23 @@ export const EVENTS = {
13
13
  // Dispatched by a form after validation blocks submission.
14
14
  // detail: { form, firstInvalid, message }
15
15
  invalid: `${ACTUAL_EVENT_PREFIX}:invalid`,
16
+ // Dispatched by a dirty-tracked form after data-dirty flips.
17
+ // detail: { form, dirty }
18
+ dirtyChange: `${ACTUAL_EVENT_PREFIX}:dirty-change`,
19
+ // Dispatched by an ajax form when its request starts.
20
+ // detail: { form, submitter }
21
+ ajaxStart: `${ACTUAL_EVENT_PREFIX}:ajax-start`,
22
+ // Dispatched by an ajax form with any HTTP response: after display, or
23
+ // before navigating to a redirect. From the root when display replaced the
24
+ // form.
25
+ // detail: { form, submitter, response }
26
+ ajaxResponse: `${ACTUAL_EVENT_PREFIX}:ajax-response`,
27
+ // Dispatched by an ajax form when the request fails (network, CORS).
28
+ // detail: { form, submitter, error }
29
+ ajaxError: `${ACTUAL_EVENT_PREFIX}:ajax-error`,
30
+ // Dispatched by a tablist after its selection changed, never at connect.
31
+ // detail: { tab, panel, previousTab }
32
+ tabChange: `${ACTUAL_EVENT_PREFIX}:tab-change`,
16
33
  // Cancelable: dispatched by dialog.js before handling native cancel close.
17
34
  // detail: { dialog, sourceEvent }
18
35
  dialogCancel: `${ACTUAL_EVENT_PREFIX}:dialog-cancel`,
package/src/js/focus.js CHANGED
@@ -59,6 +59,18 @@ function isRadioTabStop(el) {
59
59
  );
60
60
  }
61
61
 
62
+ /* The first tab stop after `node` in document order, outside `node` itself.
63
+ Document order, not tabindex order: positive tabindex is not a supported
64
+ pattern here. */
65
+ export function nextTabStop(node) {
66
+ return getFocusable(node.ownerDocument)
67
+ .filter(isRadioTabStop)
68
+ .find(
69
+ (el) =>
70
+ !node.contains(el) && node.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING,
71
+ );
72
+ }
73
+
62
74
  export function focusFirstDescendant(root) {
63
75
  const target = getFocusable(root).filter(isRadioTabStop)[0];
64
76
  target?.focus();
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Form submission settings as the browser resolves them.
3
+ *
4
+ * A control named "action", "method", "enctype" or "target" shadows the
5
+ * form's own property (form.action returns the <input>), so the values are
6
+ * read through the HTMLFormElement prototype, never as form[name].
7
+ */
8
+
9
+ function formProperty(form, name) {
10
+ return Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, name).get.call(form);
11
+ }
12
+
13
+ /**
14
+ * Reads action, method, enctype or target: a submitter's form* attribute
15
+ * overrides the form's own, as natively. Reflected values, so method and
16
+ * enctype come back lowercase and action as an absolute URL.
17
+ */
18
+ export function submissionSetting(form, submitter, name) {
19
+ return submitter?.hasAttribute(`form${name}`)
20
+ ? submitter[`form${name[0].toUpperCase()}${name.slice(1)}`]
21
+ : formProperty(form, name);
22
+ }
23
+
24
+ /**
25
+ * The browsing context name the submission goes to, "" for the page itself.
26
+ * Without a target attribute the form falls back to <base target>; an empty
27
+ * formtarget="" is still an attribute and means the page itself.
28
+ */
29
+ export function submissionTarget(form, submitter) {
30
+ if (submitter?.hasAttribute("formtarget") || form.hasAttribute("target")) {
31
+ return submissionSetting(form, submitter, "target");
32
+ }
33
+ return form.ownerDocument.querySelector("base[target]")?.target ?? "";
34
+ }
package/src/js/full.js CHANGED
@@ -25,6 +25,8 @@ import "./mask.js";
25
25
  import "./password.js";
26
26
  import "./range.js";
27
27
  import "./validation.js";
28
+ import "./dirty.js";
29
+ import "./ajax.js";
28
30
  import "./status.js";
29
31
  import "./index.js";
30
32
 
@@ -2,8 +2,9 @@
2
2
  * Selectors — the state-class vocabulary the runtime writes.
3
3
  *
4
4
  * The file lists the class names modules write as state (is-open,
5
- * was-validated, …) and validation's two read-side presentation adapters
6
- * (field, fieldError). Behavior discovery is not listed here: it uses
5
+ * was-validated, …) and the classes they only read as presentation adapters:
6
+ * validation's field and fieldError, status's formActions + sticky pair.
7
+ * Behavior discovery is not listed here: it uses
7
8
  * data-enhance tokens. To run this runtime against a different CSS
8
9
  * framework, edit this file (or alias it in a bundler).
9
10
  *
@@ -24,6 +25,13 @@ export const CLASSES = {
24
25
  // validation.js — read-side presentation adapter: ancestor container
25
26
  // for aria-invalid/danger state. Optional — degrades to no-op.
26
27
  field: "field",
28
+ // status.js — read-side presentation adapter, first half of the compound
29
+ // .form-actions.sticky: the docked action bar the status bar rises above
30
+ // instead of covering its submit button.
31
+ formActions: "form-actions",
32
+ // status.js — read-side presentation adapter, second half of the same
33
+ // compound. Read only, never written: the runtime sets no sticky state.
34
+ sticky: "sticky",
27
35
  // surface.js — state class on the open flyout/menu/dialog surface.
28
36
  // status.js writes the same class on the status bar while a message shows.
29
37
  open: "is-open",
package/src/js/status.js CHANGED
@@ -58,6 +58,7 @@ import { waitForTransitions } from "./transition.js";
58
58
  const STATUS_SELECTOR = '[data-status][role="status"]';
59
59
  const STATUS_CLASSES_ATTR = "statusClasses";
60
60
  const VIEWPORT_OFFSET_PROPERTY = "--status-viewport-offset";
61
+ const DOCKED_ACTIONS_SELECTOR = `.${CLASSES.formActions}.${CLASSES.sticky}`;
61
62
  const DEFAULT_DURATION_MS = 3000;
62
63
 
63
64
  let statusTimer;
@@ -116,34 +117,94 @@ function mountStatusTarget(target, source) {
116
117
  mountedStatusTarget = target;
117
118
  }
118
119
 
120
+ function dockedActionsBars(target) {
121
+ const root = target.closest("dialog[open]") ?? target.ownerDocument;
122
+ return root.querySelectorAll(DOCKED_ACTIONS_SELECTOR);
123
+ }
124
+
125
+ // A sticky action bar docks to the same bottom edge as the status bar. The
126
+ // validation docs pair the two, so an invalid submit would otherwise show its
127
+ // message on top of the submit button it is about. Any message is lifted, not
128
+ // only one from that form: the bar must not hide the page's primary actions
129
+ // whatever it says. A bar counts as docked when its bottom sits at its sticky
130
+ // offset from the visible bottom edge (above a bottom navigation, for one); a
131
+ // bar at rest higher up the page is not in the way. Detection assumes the
132
+ // bar's scrollport reaches the viewport bottom: a bar docked in a scroll
133
+ // container that ends higher (.app-main above an .app-nav row) is not seen.
134
+ function dockedActionsBand(target, view, visibleBottom) {
135
+ let band = 0;
136
+ for (const actions of dockedActionsBars(target)) {
137
+ const rect = actions.getBoundingClientRect();
138
+ const offset = Number.parseFloat(view.getComputedStyle(actions).bottom) || 0;
139
+ if (rect.height > 0 && rect.top < visibleBottom && rect.bottom >= visibleBottom - offset - 1) {
140
+ band = Math.max(band, visibleBottom - rect.top);
141
+ }
142
+ }
143
+ return band;
144
+ }
145
+
119
146
  // The bar is fixed to the layout viewport, so the mobile software keyboard
120
- // covers it. visualViewport reports the occluded band; the CSS adds it to the
121
- // bottom inset. Tracking runs only while a message is on screen.
147
+ // covers it, and a docked sticky action bar sits where it would show.
148
+ // visualViewport reports the keyboard band; the docked bar's height is added on
149
+ // top; the CSS adds the sum to the bottom inset. Tracking runs only while a
150
+ // message is on screen.
122
151
  function trackViewport(target) {
123
152
  if (viewportTracker?.target === target) return;
124
153
  releaseViewport();
125
154
 
126
155
  const view = target.ownerDocument?.defaultView;
127
- const viewport = view?.visualViewport;
128
- if (!viewport) return;
156
+ if (!view) return;
157
+ const viewport = view.visualViewport;
129
158
 
130
159
  const controller = new AbortController();
160
+ let frame = 0;
161
+ let written = null;
131
162
  const update = () => {
163
+ frame = 0;
132
164
  // Self-heal: an app that drops the bar while a message is up never reaches
133
165
  // the clear() path, so the tracker would outlive its element.
134
166
  if (!target.isConnected) {
135
167
  releaseViewport();
136
168
  return;
137
169
  }
138
- const occluded = Math.max(0, view.innerHeight - viewport.height - viewport.offsetTop);
139
- target.style.setProperty(VIEWPORT_OFFSET_PROPERTY, `${occluded}px`);
170
+ const keyboard = viewport
171
+ ? Math.max(0, view.innerHeight - viewport.height - viewport.offsetTop)
172
+ : 0;
173
+ const docked = dockedActionsBand(target, view, view.innerHeight - keyboard);
174
+ const value = `${keyboard + docked}px`;
175
+ if (value === written) return;
176
+ written = value;
177
+ target.style.setProperty(VIEWPORT_OFFSET_PROPERTY, value);
178
+ };
179
+ // Scroll fires per frame and per scroll container; one layout read per frame
180
+ // is enough.
181
+ const schedule = () => {
182
+ if (!frame) frame = view.requestAnimationFrame(update);
140
183
  };
141
184
 
142
- viewport.addEventListener("resize", update, { signal: controller.signal });
143
- viewport.addEventListener("scroll", update, { signal: controller.signal });
144
- update();
185
+ // Installed before the first update, so a target already detached there is
186
+ // released instead of leaving a tracker behind.
187
+ const observer = view.ResizeObserver ? new view.ResizeObserver(schedule) : null;
188
+ viewportTracker = {
189
+ target,
190
+ stop: () => {
191
+ controller.abort();
192
+ observer?.disconnect();
193
+ if (frame) view.cancelAnimationFrame(frame);
194
+ },
195
+ };
145
196
 
146
- viewportTracker = { target, stop: () => controller.abort() };
197
+ const options = { signal: controller.signal, passive: true };
198
+ viewport?.addEventListener("resize", schedule, options);
199
+ viewport?.addEventListener("scroll", schedule, options);
200
+ // Scrolling docks and releases the action bar. Capture also hears the scroll
201
+ // containers (.app-main) whose scroll events do not bubble.
202
+ view.addEventListener("scroll", schedule, { ...options, capture: true });
203
+ view.addEventListener("resize", schedule, options);
204
+ // A docked bar can change height without any scroll: a wrapping button, a
205
+ // spinner, an error line above the actions.
206
+ for (const actions of dockedActionsBars(target)) observer?.observe(actions);
207
+ update();
147
208
  }
148
209
 
149
210
  function releaseViewport() {