menhir 0.1.13 → 0.1.15

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 (48) hide show
  1. package/README.md +1 -1
  2. package/dist/autocomplete/input/AutocompleteInput.js +5 -2
  3. package/dist/checkbox-group/root/CheckboxGroupRoot.js +3 -8
  4. package/dist/combobox/input/ComboboxInput.js +6 -2
  5. package/dist/combobox/input/createComboboxInput.js +2 -17
  6. package/dist/core/formReset.js +70 -0
  7. package/dist/core/hiddenInput.js +9 -12
  8. package/dist/field/root/FieldRoot.js +4 -6
  9. package/dist/form/Form.js +5 -7
  10. package/dist/input/root/InputRoot.js +14 -23
  11. package/dist/number-field/root/NumberFieldRoot.js +7 -17
  12. package/dist/select/trigger/SelectTrigger.js +7 -10
  13. package/dist/slider/index.js +2 -0
  14. package/dist/slider/index.parts.js +5 -0
  15. package/dist/slider/root/SliderRoot.js +113 -0
  16. package/dist/slider/root/SliderRootContext.js +10 -0
  17. package/dist/slider/thumb/SliderThumb.js +119 -0
  18. package/dist/slider/track/SliderTrack.js +65 -0
  19. package/dist/slider/value/SliderValue.js +24 -0
  20. package/dist/source/autocomplete/input/AutocompleteInput.jsx +9 -2
  21. package/dist/source/checkbox-group/root/CheckboxGroupRoot.jsx +3 -9
  22. package/dist/source/combobox/input/ComboboxInput.jsx +10 -2
  23. package/dist/source/combobox/input/createComboboxInput.d.ts +0 -8
  24. package/dist/source/combobox/input/createComboboxInput.js +1 -17
  25. package/dist/source/core/formReset.d.ts +42 -0
  26. package/dist/source/core/formReset.js +74 -0
  27. package/dist/source/core/hiddenInput.d.ts +2 -2
  28. package/dist/source/core/hiddenInput.jsx +11 -16
  29. package/dist/source/field/root/FieldRoot.jsx +10 -12
  30. package/dist/source/form/Form.jsx +9 -10
  31. package/dist/source/input/root/InputRoot.jsx +19 -33
  32. package/dist/source/number-field/root/NumberFieldRoot.jsx +9 -25
  33. package/dist/source/select/trigger/SelectTrigger.jsx +9 -13
  34. package/dist/source/slider/index.d.ts +1 -0
  35. package/dist/source/slider/index.js +1 -0
  36. package/dist/source/slider/index.parts.d.ts +4 -0
  37. package/dist/source/slider/index.parts.js +4 -0
  38. package/dist/source/slider/root/SliderRoot.d.ts +55 -0
  39. package/dist/source/slider/root/SliderRoot.jsx +136 -0
  40. package/dist/source/slider/root/SliderRootContext.d.ts +51 -0
  41. package/dist/source/slider/root/SliderRootContext.js +13 -0
  42. package/dist/source/slider/thumb/SliderThumb.d.ts +13 -0
  43. package/dist/source/slider/thumb/SliderThumb.jsx +91 -0
  44. package/dist/source/slider/track/SliderTrack.d.ts +11 -0
  45. package/dist/source/slider/track/SliderTrack.jsx +79 -0
  46. package/dist/source/slider/value/SliderValue.d.ts +11 -0
  47. package/dist/source/slider/value/SliderValue.jsx +18 -0
  48. package/package.json +6 -1
@@ -0,0 +1,119 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { useSliderRootContext } from "../root/SliderRootContext.js";
4
+ import { delegateEvents, effect, heldRead, ref, setAttribute, spread, template } from "@solidjs/web";
5
+ import { merge, omit } from "solid-js";
6
+ // src/slider/thumb/SliderThumb.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<input type=range style=position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;pointer-events:none>`);
8
+ var _tmpl$2 = /* @__PURE__ */ template(`<div>`);
9
+ /**
10
+ * The thumb: a `<div>` the consumer places with `--slider`, with the
11
+ * slider's control inside it, a visually hidden `<input type="range">`.
12
+ * Its `aria-label`, `aria-labelledby` and `aria-describedby` go on the
13
+ * input. Place it inside `Slider.Track`.
14
+ */
15
+ function SliderThumb(props) {
16
+ const root = useSliderRootContext();
17
+ let held = false;
18
+ const hold = () => {
19
+ if (!held) root.begin();
20
+ held = true;
21
+ };
22
+ const release = () => {
23
+ if (!held) return;
24
+ held = false;
25
+ root.end();
26
+ };
27
+ const onKeyDown = (event) => {
28
+ if (event.ctrlKey || event.altKey || event.metaKey) return;
29
+ const step = root.stepSize();
30
+ const large = root.props.largeStep ?? step * 10;
31
+ const right = getComputedStyle(event.currentTarget).direction === "rtl" ? -step : step;
32
+ const amount = {
33
+ __proto__: null,
34
+ ArrowRight: right,
35
+ ArrowLeft: -right,
36
+ ArrowUp: step,
37
+ ArrowDown: -step,
38
+ PageUp: large,
39
+ PageDown: -large,
40
+ Home: -Infinity,
41
+ End: Infinity
42
+ }[event.key];
43
+ if (!amount) return;
44
+ hold();
45
+ root.step(amount);
46
+ event.preventDefault();
47
+ };
48
+ var _el$ = _tmpl$();
49
+ _el$.addEventListener("change", release);
50
+ _el$._$$input = (event) => {
51
+ const number = Number(event.currentTarget.value);
52
+ if (number === root.requested()) return;
53
+ hold();
54
+ root.change(number);
55
+ };
56
+ _el$.addEventListener("blur", release);
57
+ _el$._$$keyup = release;
58
+ _el$._$$keydown = onKeyDown;
59
+ ref(() => {
60
+ return (element) => {
61
+ root.input = element;
62
+ };
63
+ }, _el$);
64
+ effect(() => {
65
+ return {
66
+ e: root.props.id,
67
+ t: root.props.name,
68
+ a: root.props.form,
69
+ o: root.props.min,
70
+ i: root.props.max,
71
+ n: root.props.step,
72
+ s: String(root.value()),
73
+ h: root.props.disabled,
74
+ r: root.text(),
75
+ d: root.props.orientation === "vertical" ? "vertical" : void 0,
76
+ l: props["aria-label"],
77
+ u: props["aria-labelledby"],
78
+ c: props["aria-describedby"] ?? root.props["aria-describedby"],
79
+ w: root.props["aria-invalid"],
80
+ m: heldRead()
81
+ };
82
+ }, ({ e, t, a, o, i, n, s, h, r, d, l, u, c, w, m }, _p$) => {
83
+ e !== _p$?.e && setAttribute(_el$, "id", e);
84
+ t !== _p$?.t && setAttribute(_el$, "name", t);
85
+ a !== _p$?.a && setAttribute(_el$, "form", a);
86
+ o !== _p$?.o && setAttribute(_el$, "min", o);
87
+ i !== _p$?.i && setAttribute(_el$, "max", i);
88
+ n !== _p$?.n && setAttribute(_el$, "step", n);
89
+ (s !== _p$?.s || !m) && (_el$.value = s ?? "");
90
+ h !== _p$?.h && setAttribute(_el$, "disabled", h);
91
+ r !== _p$?.r && setAttribute(_el$, "aria-valuetext", r);
92
+ d !== _p$?.d && setAttribute(_el$, "aria-orientation", d);
93
+ l !== _p$?.l && setAttribute(_el$, "aria-label", l);
94
+ u !== _p$?.u && setAttribute(_el$, "aria-labelledby", u);
95
+ c !== _p$?.c && setAttribute(_el$, "aria-describedby", c);
96
+ w !== _p$?.w && setAttribute(_el$, "aria-invalid", w);
97
+ });
98
+ const input = _el$;
99
+ const ownProps = merge(root.attributes, {
100
+ get children() {
101
+ return [input, props.children];
102
+ },
103
+ ref: (element) => {
104
+ root.thumb = element;
105
+ }
106
+ });
107
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "children", "aria-label", "aria-labelledby", "aria-describedby"));
108
+ return renderElement(props, elementProps, (p) => (() => {
109
+ var _el$2 = _tmpl$2();
110
+ spread(_el$2, p, false);
111
+ return _el$2;
112
+ })());
113
+ }
114
+ delegateEvents([
115
+ "keydown",
116
+ "keyup",
117
+ "input"
118
+ ]);
119
+ export { SliderThumb };
@@ -0,0 +1,65 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { useSliderRootContext } from "../root/SliderRootContext.js";
4
+ import { spread, template } from "@solidjs/web";
5
+ import { merge, omit } from "solid-js";
6
+ // src/slider/track/SliderTrack.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
8
+ /**
9
+ * The track: a `<div>`, the area where a press moves the thumb and a drag
10
+ * follows the pointer. Place the Thumb inside it, inside `Slider.Root`.
11
+ */
12
+ function SliderTrack(props) {
13
+ const root = useSliderRootContext();
14
+ let track;
15
+ let pointer;
16
+ let offset = 0;
17
+ const along = (x, y) => {
18
+ const rect = track.getBoundingClientRect();
19
+ return root.props.orientation === "vertical" ? rect.bottom - y : getComputedStyle(track).direction === "rtl" ? rect.right - x : x - rect.left;
20
+ };
21
+ const move = (event) => {
22
+ const rect = track.getBoundingClientRect();
23
+ const length = root.props.orientation === "vertical" ? rect.height : rect.width;
24
+ root.change(root.min() + (along(event.clientX, event.clientY) - offset) / length * (root.max() - root.min()));
25
+ };
26
+ const end = (event) => {
27
+ if (event.pointerId !== pointer) return;
28
+ pointer = void 0;
29
+ root.end();
30
+ };
31
+ const ownProps = merge(root.attributes, {
32
+ style: { "touch-action": "none" },
33
+ onPointerDown: (event) => {
34
+ if (event.button !== 0 || pointer !== void 0 || root.props.disabled) return;
35
+ event.preventDefault();
36
+ root.input?.focus({ focusVisible: false });
37
+ pointer = event.pointerId;
38
+ track.setPointerCapture(pointer);
39
+ const thumb = root.thumb;
40
+ offset = 0;
41
+ if (thumb?.contains(event.target)) {
42
+ const { left, top, width, height } = thumb.getBoundingClientRect();
43
+ offset = along(event.clientX, event.clientY) - along(left + width / 2, top + height / 2);
44
+ }
45
+ root.begin();
46
+ move(event);
47
+ },
48
+ onPointerMove: (event) => {
49
+ if (event.pointerId === pointer) move(event);
50
+ },
51
+ onPointerUp: end,
52
+ onPointerCancel: end,
53
+ onLostPointerCapture: end,
54
+ ref: (element) => {
55
+ track = element;
56
+ }
57
+ });
58
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
59
+ return renderElement(props, elementProps, (p) => (() => {
60
+ var _el$ = _tmpl$();
61
+ spread(_el$, p, false);
62
+ return _el$;
63
+ })());
64
+ }
65
+ export { SliderTrack };
@@ -0,0 +1,24 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { useSliderRootContext } from "../root/SliderRootContext.js";
4
+ import { spread, template } from "@solidjs/web";
5
+ import { merge, omit } from "solid-js";
6
+ // src/slider/value/SliderValue.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<span>`);
8
+ /**
9
+ * The value as text: a `<span>` with the Root's `aria-valuetext`, the value
10
+ * in its `format` and `locale`. Place it inside `Slider.Root`.
11
+ */
12
+ function SliderValue(props) {
13
+ const root = useSliderRootContext();
14
+ const ownProps = merge(root.attributes, { get children() {
15
+ return root.text();
16
+ } });
17
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
18
+ return renderElement(props, elementProps, (p) => (() => {
19
+ var _el$ = _tmpl$();
20
+ spread(_el$, p, false);
21
+ return _el$;
22
+ })());
23
+ }
24
+ export { SliderValue };
@@ -1,7 +1,8 @@
1
1
  import { merge, omit, onFlush } from "solid-js";
2
+ import { onFormReset } from "../../core/formReset.js";
2
3
  import { mergeElementProps } from "../../core/mergeElementProps.js";
3
4
  import { renderElement } from "../../core/renderElement.jsx";
4
- import { createComboboxInput, onFormReset, } from "../../combobox/input/createComboboxInput.js";
5
+ import { createComboboxInput } from "../../combobox/input/createComboboxInput.js";
5
6
  import { useComboboxContext } from "../../combobox/root/ComboboxContext.js";
6
7
  /**
7
8
  * The autocomplete itself, and the form's control: an `<input type="text"
@@ -14,12 +15,18 @@ import { useComboboxContext } from "../../combobox/root/ComboboxContext.js";
14
15
  export function AutocompleteInput(props) {
15
16
  const autocomplete = useComboboxContext("Autocomplete");
16
17
  const input = createComboboxInput(autocomplete);
17
- onFormReset(() => autocomplete.input, (event) => {
18
+ // A form reset puts a control back to its default, and so it does an
19
+ // autocomplete: through its setter, so that a controlled one asks.
20
+ onFormReset(() => autocomplete.input?.form, (event) => {
18
21
  autocomplete.setInputValue(autocomplete.props.defaultValue ?? "", {
19
22
  reason: "reset",
20
23
  event,
21
24
  });
22
25
  onFlush(input.syncText);
26
+ },
27
+ // Held through the browser's reset (`onFormReset`).
28
+ () => {
29
+ autocomplete.input.defaultValue = autocomplete.input.value;
23
30
  });
24
31
  const ownProps = merge(input.props, {
25
32
  get name() {
@@ -1,5 +1,6 @@
1
- import { createUniqueId, omit, onSettled } from "solid-js";
1
+ import { createUniqueId, omit } from "solid-js";
2
2
  import { createControllableSignal } from "../../core/createControllableSignal.js";
3
+ import { onFormReset } from "../../core/formReset.js";
3
4
  import { mergeElementProps } from "../../core/mergeElementProps.js";
4
5
  import { renderElement } from "../../core/renderElement.jsx";
5
6
  import { CheckboxGroupRootContext } from "./CheckboxGroupRootContext.js";
@@ -32,14 +33,7 @@ export function CheckboxGroupRoot(props) {
32
33
  // A form reset puts the list back to its default, once, through the
33
34
  // setter, so that a controlled group asks once. Each Item's Checkbox asks
34
35
  // for nothing itself (CheckboxGroupItem).
35
- onSettled(() => {
36
- const form = input?.form;
37
- if (!form)
38
- return;
39
- const onReset = () => setValue(props.defaultValue ?? []);
40
- form.addEventListener("reset", onReset);
41
- return () => form.removeEventListener("reset", onReset);
42
- });
36
+ onFormReset(() => input?.form, () => setValue(props.defaultValue ?? []));
43
37
  const ownProps = {
44
38
  get disabled() {
45
39
  return props.disabled;
@@ -1,8 +1,9 @@
1
1
  import { omit, onFlush, untrack } from "solid-js";
2
+ import { onFormReset } from "../../core/formReset.js";
2
3
  import { mergeElementProps } from "../../core/mergeElementProps.js";
3
4
  import { renderElement } from "../../core/renderElement.jsx";
4
5
  import { useComboboxContext } from "../root/ComboboxContext.js";
5
- import { createComboboxInput, onFormReset } from "./createComboboxInput.js";
6
+ import { createComboboxInput } from "./createComboboxInput.js";
6
7
  /**
7
8
  * The combobox itself: an `<input type="text" role="combobox"
8
9
  * aria-autocomplete="list">` with `aria-expanded`, naming the List in
@@ -26,7 +27,9 @@ export function ComboboxInput(props) {
26
27
  if (hiddenInput)
27
28
  hiddenInput.value = untrack(combobox.value) ?? "";
28
29
  };
29
- onFormReset(() => hiddenInput, (event) => {
30
+ // A form reset puts a control back to its default, and so it does a
31
+ // combobox: through its setters, so that a controlled one asks.
32
+ onFormReset(() => hiddenInput?.form, (event) => {
30
33
  const value = combobox.props.defaultValue ?? null;
31
34
  combobox.setValue(value);
32
35
  combobox.setInputValue(combobox.props.defaultInputValue ?? combobox.labelOfValue(value) ?? "", { reason: "reset", event });
@@ -34,6 +37,11 @@ export function ComboboxInput(props) {
34
37
  syncHidden();
35
38
  input.syncText();
36
39
  });
40
+ },
41
+ // Both held through the browser's reset (`onFormReset`).
42
+ () => {
43
+ combobox.input.defaultValue = combobox.input.value;
44
+ hiddenInput.defaultValue = hiddenInput.value;
37
45
  });
38
46
  const elementProps = mergeElementProps(input.props, omit(props, "render"));
39
47
  return (<>
@@ -20,11 +20,3 @@ export declare function createComboboxInput(combobox: ComboboxBase, onFocusOut?:
20
20
  props: ComboboxInputElementProps;
21
21
  syncText(): void;
22
22
  };
23
- /**
24
- * Calls `reset` when the form of `input()` is reset, from the time the
25
- * part has settled: a form reset puts a control back to its default, and
26
- * so it does a combobox, through its setters, so that a controlled one
27
- * asks. The browser resets the form's inputs after the event, to their
28
- * `value` attributes; an `onFlush` in `reset` runs after that.
29
- */
30
- export declare function onFormReset(input: () => HTMLInputElement | undefined, reset: (event: Event) => void): void;
@@ -1,4 +1,4 @@
1
- import { createSignal, merge, onFlush, onSettled, untrack } from "solid-js";
1
+ import { createSignal, merge, onFlush, untrack } from "solid-js";
2
2
  /**
3
3
  * The input of a combobox, the code `Combobox.Input` and
4
4
  * `Autocomplete.Input` share: its attributes, typing, the keys, focus
@@ -122,19 +122,3 @@ export function createComboboxInput(combobox, onFocusOut) {
122
122
  });
123
123
  return { props, syncText };
124
124
  }
125
- /**
126
- * Calls `reset` when the form of `input()` is reset, from the time the
127
- * part has settled: a form reset puts a control back to its default, and
128
- * so it does a combobox, through its setters, so that a controlled one
129
- * asks. The browser resets the form's inputs after the event, to their
130
- * `value` attributes; an `onFlush` in `reset` runs after that.
131
- */
132
- export function onFormReset(input, reset) {
133
- onSettled(() => {
134
- const form = input()?.form;
135
- if (!form)
136
- return;
137
- form.addEventListener("reset", reset);
138
- return () => form.removeEventListener("reset", reset);
139
- });
140
- }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A form reset puts a native control back to its default, and so it does a
3
+ * part: `reset` asks for the part's default, through its setters, so that a
4
+ * controlled part asks. Listens to `form()`, read once the part has settled.
5
+ *
6
+ * ```ts
7
+ * onFormReset(
8
+ * () => input?.form,
9
+ * () => {
10
+ * setChecked(props.defaultChecked ?? false);
11
+ * onFlush(sync);
12
+ * },
13
+ * () => {
14
+ * input!.defaultChecked = input!.checked;
15
+ * },
16
+ * );
17
+ * ```
18
+ *
19
+ * - `hold` runs during the event, before the browser resets the controls,
20
+ * and what it returns is `reset`'s second argument. A part whose state
21
+ * is its own, not the element's, makes each element's state there the
22
+ * attribute the browser resets it to (`defaultChecked`, `defaultValue`),
23
+ * so the reset leaves it as it is: it never shows a state the part does
24
+ * not hold, and a binding that re-runs before `reset`, such as a Field's
25
+ * `data-touched` as the touched state clears, does not write its value
26
+ * back over the reset element (`UNCOMMITTED_INPUT_OVERWRITTEN`). Each
27
+ * part writes its own, a line, so no part pays for another's.
28
+ * - `reset` runs in a task after the event, not in `onFlush`: when the user
29
+ * presses a reset button, the browser runs microtasks as each listener
30
+ * returns, before it resets the controls and before later listeners
31
+ * could cancel the reset (src/input/README.md, "A form reset asks").
32
+ * Every part's `reset` runs in the same task, in the order the parts
33
+ * listened, so a set equal to one made before it in the task
34
+ * does nothing (`createControllableSignal`), and a Field, which listens
35
+ * before the controls inside it, reads them in an `onFlush` after theirs.
36
+ * - A reset the app cancels asks for nothing: the reset is the event's
37
+ * default action, so its `defaultPrevented` is the app saying no.
38
+ * - A part the reset removes before the task, such as a row of a list
39
+ * going back to its default length, asks for nothing, so it does not
40
+ * write its row back.
41
+ */
42
+ export declare function onFormReset<T = void>(form: () => HTMLFormElement | null | undefined, reset: (event: Event, held: T) => void, hold?: () => T): void;
@@ -0,0 +1,74 @@
1
+ import { onSettled } from "solid-js";
2
+ // The answers to the resets under way, run together in one task, in the
3
+ // order the parts listened: a part's `onFlush` then runs after those of the
4
+ // parts before it, as when each answered during the event.
5
+ let answers;
6
+ /**
7
+ * A form reset puts a native control back to its default, and so it does a
8
+ * part: `reset` asks for the part's default, through its setters, so that a
9
+ * controlled part asks. Listens to `form()`, read once the part has settled.
10
+ *
11
+ * ```ts
12
+ * onFormReset(
13
+ * () => input?.form,
14
+ * () => {
15
+ * setChecked(props.defaultChecked ?? false);
16
+ * onFlush(sync);
17
+ * },
18
+ * () => {
19
+ * input!.defaultChecked = input!.checked;
20
+ * },
21
+ * );
22
+ * ```
23
+ *
24
+ * - `hold` runs during the event, before the browser resets the controls,
25
+ * and what it returns is `reset`'s second argument. A part whose state
26
+ * is its own, not the element's, makes each element's state there the
27
+ * attribute the browser resets it to (`defaultChecked`, `defaultValue`),
28
+ * so the reset leaves it as it is: it never shows a state the part does
29
+ * not hold, and a binding that re-runs before `reset`, such as a Field's
30
+ * `data-touched` as the touched state clears, does not write its value
31
+ * back over the reset element (`UNCOMMITTED_INPUT_OVERWRITTEN`). Each
32
+ * part writes its own, a line, so no part pays for another's.
33
+ * - `reset` runs in a task after the event, not in `onFlush`: when the user
34
+ * presses a reset button, the browser runs microtasks as each listener
35
+ * returns, before it resets the controls and before later listeners
36
+ * could cancel the reset (src/input/README.md, "A form reset asks").
37
+ * Every part's `reset` runs in the same task, in the order the parts
38
+ * listened, so a set equal to one made before it in the task
39
+ * does nothing (`createControllableSignal`), and a Field, which listens
40
+ * before the controls inside it, reads them in an `onFlush` after theirs.
41
+ * - A reset the app cancels asks for nothing: the reset is the event's
42
+ * default action, so its `defaultPrevented` is the app saying no.
43
+ * - A part the reset removes before the task, such as a row of a list
44
+ * going back to its default length, asks for nothing, so it does not
45
+ * write its row back.
46
+ */
47
+ export function onFormReset(form, reset, hold) {
48
+ onSettled(() => {
49
+ const target = form();
50
+ if (!target)
51
+ return;
52
+ let disposed = false;
53
+ const onReset = (event) => {
54
+ const held = hold?.();
55
+ if (!answers) {
56
+ const queue = (answers = []);
57
+ setTimeout(() => {
58
+ answers = undefined;
59
+ for (const answer of queue)
60
+ answer();
61
+ });
62
+ }
63
+ answers.push(() => {
64
+ if (!disposed && !event.defaultPrevented)
65
+ reset(event, held);
66
+ });
67
+ };
68
+ target.addEventListener("reset", onReset);
69
+ return () => {
70
+ disposed = true;
71
+ target.removeEventListener("reset", onReset);
72
+ };
73
+ });
74
+ }
@@ -34,8 +34,8 @@ export interface HiddenInputProps {
34
34
  * - `button` is where focus goes when the browser focuses the input, as it
35
35
  * does when it blocks a submission.
36
36
  * - `reset` asks for the control's default on a form reset, through the
37
- * setter, so that a controlled control asks. A Radio's Items each ask
38
- * the group, which asks once.
37
+ * setter, so that a controlled control asks (`onFormReset`). A Radio's
38
+ * Items each ask the group, which asks once.
39
39
  *
40
40
  * A plain function with positional parameters, not a component with props:
41
41
  * a component would wrap each prop in a getter, and an options object
@@ -1,4 +1,5 @@
1
- import { onFlush, onSettled, untrack } from "solid-js";
1
+ import { onFlush, untrack } from "solid-js";
2
+ import { onFormReset } from "./formReset.js";
2
3
  /**
3
4
  * The form's view of a control whose element is a native button (PLAN.md
4
5
  * section 8, "The hidden input is the form's view of the control"): a
@@ -25,8 +26,8 @@ import { onFlush, onSettled, untrack } from "solid-js";
25
26
  * - `button` is where focus goes when the browser focuses the input, as it
26
27
  * does when it blocks a submission.
27
28
  * - `reset` asks for the control's default on a form reset, through the
28
- * setter, so that a controlled control asks. A Radio's Items each ask
29
- * the group, which asks once.
29
+ * setter, so that a controlled control asks (`onFormReset`). A Radio's
30
+ * Items each ask the group, which asks once.
30
31
  *
31
32
  * A plain function with positional parameters, not a component with props:
32
33
  * a component would wrap each prop in a getter, and an options object
@@ -54,19 +55,13 @@ export function createHiddenInput(type, props, checked, setChecked, button, rese
54
55
  };
55
56
  // A form reset puts a native control back to its default, and so it does
56
57
  // this one: through the setter, so that a controlled control asks.
57
- onSettled(() => {
58
- const form = input?.form;
59
- if (!form)
60
- return;
61
- const onReset = () => {
62
- reset();
63
- // The browser resets the input after this event, to its `checked`
64
- // attribute, which the binding does not set. `onFlush` runs after
65
- // that, as the event has finished by then.
66
- onFlush(sync);
67
- };
68
- form.addEventListener("reset", onReset);
69
- return () => form.removeEventListener("reset", onReset);
58
+ onFormReset(() => input?.form, () => {
59
+ reset();
60
+ onFlush(sync);
61
+ },
62
+ // Held through the browser's reset (`onFormReset`).
63
+ () => {
64
+ input.defaultChecked = input.checked;
70
65
  });
71
66
  return (
72
67
  // The element, for the button to click. On the server it is the HTML,
@@ -1,5 +1,6 @@
1
1
  import { createSignal, createUniqueId, merge, omit, onFlush, onSettled, useContext, } from "solid-js";
2
2
  import { FormContext } from "../../core/formContext.js";
3
+ import { onFormReset } from "../../core/formReset.js";
3
4
  import { mergeElementProps } from "../../core/mergeElementProps.js";
4
5
  import { renderElement } from "../../core/renderElement.jsx";
5
6
  import { FieldRootContext } from "./FieldRootContext.js";
@@ -46,7 +47,6 @@ export function FieldRoot(props) {
46
47
  // Reads the controls' validity again, and sets touched if given. The
47
48
  // Field's own state is written after the event's flush, so async work the
48
49
  // event starts does not hold it (PLAN.md section 8, "API conventions").
49
- // By then a form reset has reset the controls too.
50
50
  const update = (touch) => onFlush(() => {
51
51
  setInvalidControl(readValidity());
52
52
  if (touch !== undefined)
@@ -104,29 +104,27 @@ export function FieldRoot(props) {
104
104
  // A submission attempt, or a control found invalid: `invalid` does not
105
105
  // bubble, so the Root and the form listen in the capture phase.
106
106
  const touch = () => update(true);
107
+ const findForm = () => root?.querySelector(controlSelector)?.form ??
108
+ root?.closest("form");
107
109
  onSettled(() => {
108
110
  setSettled(true);
109
111
  // A submission attempt touches every Field of the form, by its submit
110
- // event or an `invalid` event of any control in it, and a reset clears
111
- // it.
112
- const form = root?.querySelector(controlSelector)?.form ??
113
- root?.closest("form");
112
+ // event or an `invalid` event of any control in it.
113
+ const form = findForm();
114
114
  if (!form)
115
115
  return;
116
- // A reset the app cancels, after this listener, keeps it touched.
117
- const onReset = (event) => onFlush(() => {
118
- if (!event.defaultPrevented)
119
- update(false);
120
- });
121
116
  form.addEventListener("submit", touch);
122
117
  form.addEventListener("invalid", touch, true);
123
- form.addEventListener("reset", onReset);
124
118
  return () => {
125
119
  form.removeEventListener("submit", touch);
126
120
  form.removeEventListener("invalid", touch, true);
127
- form.removeEventListener("reset", onReset);
128
121
  };
129
122
  });
123
+ // A form reset clears touched, unless the app cancels it, and the Root
124
+ // reads the validity of the reset controls once they have put their
125
+ // inputs back: the Root listens before the controls inside it, so its
126
+ // `onFlush` comes after theirs only from inside one (`onFormReset`).
127
+ onFormReset(findForm, () => onFlush(() => update(false)));
130
128
  const ownProps = merge(attributes, {
131
129
  onFocusOut: (event) => {
132
130
  const to = event.relatedTarget;
@@ -1,5 +1,6 @@
1
1
  import { createMemo, createSignal, omit, onFlush, onSettled, untrack, } from "solid-js";
2
2
  import { FormContext } from "../core/formContext.js";
3
+ import { onFormReset } from "../core/formReset.js";
3
4
  import { callHandler, mergeElementProps } from "../core/mergeElementProps.js";
4
5
  import { renderElement } from "../core/renderElement.jsx";
5
6
  /**
@@ -35,14 +36,11 @@ export function Form(props) {
35
36
  // Hides errors once the event's flush has run, as Field writes its own
36
37
  // state, and only the `errors` the event met: a new object passed in the
37
38
  // same update is the answer to a later submission.
38
- const hide = (update) => {
39
- const met = untrack(errors);
40
- onFlush(() => {
41
- if (untrack(errors) === met) {
42
- setHidden((names) => (names === true ? names : update(names)));
43
- }
44
- });
45
- };
39
+ const hide = (update, met = untrack(errors)) => onFlush(() => {
40
+ if (untrack(errors) === met) {
41
+ setHidden((names) => (names === true ? names : update(names)));
42
+ }
43
+ });
46
44
  // An edit makes the error of that control's name stale.
47
45
  const hideError = (event) => {
48
46
  const name = event.target.name;
@@ -56,11 +54,12 @@ export function Form(props) {
56
54
  if (form)
57
55
  form.noValidate = true;
58
56
  });
57
+ // A reset hides every error, unless the app cancels it: in a task after
58
+ // the event, with the errors the event met (`onFormReset`).
59
+ onFormReset(() => form, (_, met) => hide(() => true, met), () => untrack(errors));
59
60
  const ownProps = {
60
61
  onInput: hideError,
61
62
  onChange: hideError,
62
- // A reset the app cancels, by its own handler, keeps the errors.
63
- onReset: (event) => hide((names) => (event.defaultPrevented ? names : true)),
64
63
  onSubmit: (event) => {
65
64
  const submitter = event.submitter;
66
65
  // `checkValidity()` fires `invalid` at each invalid control, which