menhir 0.1.14 → 0.1.16
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.
- package/dist/autocomplete/input/AutocompleteInput.js +5 -2
- package/dist/checkbox-group/root/CheckboxGroupRoot.js +3 -8
- package/dist/combobox/input/ComboboxInput.js +6 -2
- package/dist/combobox/input/createComboboxInput.js +2 -17
- package/dist/context-menu/root/ContextMenuContext.js +15 -3
- package/dist/context-menu/root/ContextMenuRoot.js +5 -7
- package/dist/context-menu/trigger/ContextMenuTrigger.js +2 -2
- package/dist/core/formReset.js +70 -0
- package/dist/core/hiddenInput.js +9 -12
- package/dist/field/root/FieldRoot.js +4 -6
- package/dist/form/Form.js +5 -7
- package/dist/input/root/InputRoot.js +14 -23
- package/dist/menu/popup/MenuPopup.js +2 -2
- package/dist/menu/root/MenuContext.js +2 -2
- package/dist/menu/submenu-trigger/MenuSubmenuTrigger.js +1 -1
- package/dist/number-field/root/NumberFieldRoot.js +7 -17
- package/dist/select/trigger/SelectTrigger.js +7 -10
- package/dist/slider/root/SliderRoot.js +12 -22
- package/dist/source/autocomplete/input/AutocompleteInput.jsx +9 -2
- package/dist/source/checkbox-group/root/CheckboxGroupRoot.jsx +3 -9
- package/dist/source/combobox/input/ComboboxInput.jsx +10 -2
- package/dist/source/combobox/input/createComboboxInput.d.ts +0 -8
- package/dist/source/combobox/input/createComboboxInput.js +1 -17
- package/dist/source/context-menu/root/ContextMenuContext.d.ts +6 -1
- package/dist/source/context-menu/root/ContextMenuContext.js +15 -2
- package/dist/source/context-menu/root/ContextMenuRoot.jsx +3 -8
- package/dist/source/context-menu/trigger/ContextMenuTrigger.jsx +4 -3
- package/dist/source/core/formReset.d.ts +42 -0
- package/dist/source/core/formReset.js +74 -0
- package/dist/source/core/hiddenInput.d.ts +2 -2
- package/dist/source/core/hiddenInput.jsx +11 -16
- package/dist/source/field/root/FieldRoot.jsx +10 -12
- package/dist/source/form/Form.jsx +9 -10
- package/dist/source/input/root/InputRoot.jsx +19 -33
- package/dist/source/menu/popup/MenuPopup.jsx +2 -2
- package/dist/source/menu/root/MenuContext.d.ts +12 -2
- package/dist/source/menu/root/MenuContext.js +2 -2
- package/dist/source/menu/submenu-trigger/MenuSubmenuTrigger.jsx +1 -1
- package/dist/source/number-field/root/NumberFieldRoot.jsx +9 -25
- package/dist/source/select/trigger/SelectTrigger.jsx +9 -13
- package/dist/source/slider/root/SliderRoot.jsx +16 -32
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
1
2
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
3
|
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
-
import { createComboboxInput
|
|
4
|
+
import { createComboboxInput } from "../../combobox/input/createComboboxInput.js";
|
|
4
5
|
import { useComboboxContext } from "../../combobox/root/ComboboxContext.js";
|
|
5
6
|
import { spread, template } from "@solidjs/web";
|
|
6
7
|
import { merge, omit, onFlush } from "solid-js";
|
|
@@ -17,12 +18,14 @@ var _tmpl$ = /* @__PURE__ */ template(`<input>`);
|
|
|
17
18
|
function AutocompleteInput(props) {
|
|
18
19
|
const autocomplete = useComboboxContext("Autocomplete");
|
|
19
20
|
const input = createComboboxInput(autocomplete);
|
|
20
|
-
onFormReset(() => autocomplete.input, (event) => {
|
|
21
|
+
onFormReset(() => autocomplete.input?.form, (event) => {
|
|
21
22
|
autocomplete.setInputValue(autocomplete.props.defaultValue ?? "", {
|
|
22
23
|
reason: "reset",
|
|
23
24
|
event
|
|
24
25
|
});
|
|
25
26
|
onFlush(input.syncText);
|
|
27
|
+
}, () => {
|
|
28
|
+
autocomplete.input.defaultValue = autocomplete.input.value;
|
|
26
29
|
});
|
|
27
30
|
const ownProps = merge(input.props, {
|
|
28
31
|
get name() {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.js";
|
|
4
5
|
import { CheckboxGroupRootContext } from "./CheckboxGroupRootContext.js";
|
|
5
6
|
import { createComponent, effect, memo, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
6
|
-
import { createUniqueId, omit
|
|
7
|
+
import { createUniqueId, omit } from "solid-js";
|
|
7
8
|
// src/checkbox-group/root/CheckboxGroupRoot.tsx
|
|
8
9
|
var _tmpl$ = /* @__PURE__ */ template(`<input type=radio aria-hidden=true tabindex=-1 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>`);
|
|
9
10
|
var _tmpl$2 = /* @__PURE__ */ template(`<fieldset>`);
|
|
@@ -32,13 +33,7 @@ function CheckboxGroupRoot(props) {
|
|
|
32
33
|
const validityName = createUniqueId();
|
|
33
34
|
let root;
|
|
34
35
|
let input;
|
|
35
|
-
|
|
36
|
-
const form = input?.form;
|
|
37
|
-
if (!form) return;
|
|
38
|
-
const onReset = () => setValue(props.defaultValue ?? []);
|
|
39
|
-
form.addEventListener("reset", onReset);
|
|
40
|
-
return () => form.removeEventListener("reset", onReset);
|
|
41
|
-
});
|
|
36
|
+
onFormReset(() => input?.form, () => setValue(props.defaultValue ?? []));
|
|
42
37
|
const elementProps = mergeElementProps({
|
|
43
38
|
get disabled() {
|
|
44
39
|
return props.disabled;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
1
2
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
3
|
import { renderElement } from "../../core/renderElement.js";
|
|
3
4
|
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
4
|
-
import { createComboboxInput
|
|
5
|
+
import { createComboboxInput } from "./createComboboxInput.js";
|
|
5
6
|
import { effect, heldRead, memo, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
6
7
|
import { omit, onFlush, untrack } from "solid-js";
|
|
7
8
|
// src/combobox/input/ComboboxInput.tsx
|
|
@@ -27,7 +28,7 @@ function ComboboxInput(props) {
|
|
|
27
28
|
const syncHidden = () => {
|
|
28
29
|
if (hiddenInput) hiddenInput.value = untrack(combobox.value) ?? "";
|
|
29
30
|
};
|
|
30
|
-
onFormReset(() => hiddenInput, (event) => {
|
|
31
|
+
onFormReset(() => hiddenInput?.form, (event) => {
|
|
31
32
|
const value = combobox.props.defaultValue ?? null;
|
|
32
33
|
combobox.setValue(value);
|
|
33
34
|
combobox.setInputValue(combobox.props.defaultInputValue ?? combobox.labelOfValue(value) ?? "", {
|
|
@@ -38,6 +39,9 @@ function ComboboxInput(props) {
|
|
|
38
39
|
syncHidden();
|
|
39
40
|
input.syncText();
|
|
40
41
|
});
|
|
42
|
+
}, () => {
|
|
43
|
+
combobox.input.defaultValue = combobox.input.value;
|
|
44
|
+
hiddenInput.defaultValue = hiddenInput.value;
|
|
41
45
|
});
|
|
42
46
|
const elementProps = mergeElementProps(input.props, omit(props, "render"));
|
|
43
47
|
return [memo(() => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createSignal, merge, onFlush,
|
|
1
|
+
import { createSignal, merge, onFlush, untrack } from "solid-js";
|
|
2
2
|
// src/combobox/input/createComboboxInput.ts
|
|
3
3
|
/**
|
|
4
4
|
* The input of a combobox, the code `Combobox.Input` and
|
|
@@ -94,19 +94,4 @@ function createComboboxInput(combobox, onFocusOut) {
|
|
|
94
94
|
syncText
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
* Calls `reset` when the form of `input()` is reset, from the time the
|
|
99
|
-
* part has settled: a form reset puts a control back to its default, and
|
|
100
|
-
* so it does a combobox, through its setters, so that a controlled one
|
|
101
|
-
* asks. The browser resets the form's inputs after the event, to their
|
|
102
|
-
* `value` attributes; an `onFlush` in `reset` runs after that.
|
|
103
|
-
*/
|
|
104
|
-
function onFormReset(input, reset) {
|
|
105
|
-
onSettled(() => {
|
|
106
|
-
const form = input()?.form;
|
|
107
|
-
if (!form) return;
|
|
108
|
-
form.addEventListener("reset", reset);
|
|
109
|
-
return () => form.removeEventListener("reset", reset);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
export { createComboboxInput, onFormReset };
|
|
97
|
+
export { createComboboxInput };
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import { MenuContext } from "../../menu/root/MenuContext.js";
|
|
1
|
+
import { MenuContext, createMenu } from "../../menu/root/MenuContext.js";
|
|
2
2
|
import { isDev } from "@solidjs/web";
|
|
3
|
-
import { useContext } from "solid-js";
|
|
3
|
+
import { createSignal, useContext } from "solid-js";
|
|
4
4
|
// src/context-menu/root/ContextMenuContext.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a context menu's state: Menu's, with where it was asked for and
|
|
7
|
+
* the area, which start unset.
|
|
8
|
+
*/
|
|
9
|
+
function createContextMenu(props) {
|
|
10
|
+
const [anchor, setAnchor] = createSignal();
|
|
11
|
+
const menu = createMenu(props);
|
|
12
|
+
menu.anchor = anchor;
|
|
13
|
+
menu.setAnchor = (value) => setAnchor(() => value);
|
|
14
|
+
menu.area = void 0;
|
|
15
|
+
return menu;
|
|
16
|
+
}
|
|
5
17
|
/** The Root's context menu, for its Trigger and its Popup. */
|
|
6
18
|
function useContextMenu() {
|
|
7
19
|
const context = useContext(MenuContext);
|
|
8
20
|
if (isDev && !context?.setAnchor) throw new Error("[menhir] Context Menu parts must be placed within <ContextMenu.Root>.");
|
|
9
21
|
return context;
|
|
10
22
|
}
|
|
11
|
-
export { useContextMenu };
|
|
23
|
+
export { createContextMenu, useContextMenu };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MenuContext
|
|
1
|
+
import { MenuContext } from "../../menu/root/MenuContext.js";
|
|
2
|
+
import { createContextMenu } from "./ContextMenuContext.js";
|
|
2
3
|
import { createComponent } from "@solidjs/web";
|
|
3
|
-
import { createSignal } from "solid-js";
|
|
4
4
|
// src/context-menu/root/ContextMenuRoot.tsx
|
|
5
5
|
/**
|
|
6
6
|
* A menu that an area opens with the `contextmenu` event: holds whether it
|
|
@@ -9,12 +9,10 @@ import { createSignal } from "solid-js";
|
|
|
9
9
|
* Renders no element of its own.
|
|
10
10
|
*/
|
|
11
11
|
function ContextMenuRoot(props) {
|
|
12
|
-
const [anchor, setAnchor] = createSignal();
|
|
13
|
-
const menu = createMenu(props);
|
|
14
|
-
menu.anchor = anchor;
|
|
15
|
-
menu.setAnchor = (value) => setAnchor(() => value);
|
|
16
12
|
return createComponent(MenuContext, {
|
|
17
|
-
value
|
|
13
|
+
get value() {
|
|
14
|
+
return createContextMenu(props);
|
|
15
|
+
},
|
|
18
16
|
get children() {
|
|
19
17
|
return props.children;
|
|
20
18
|
}
|
|
@@ -25,13 +25,13 @@ function ContextMenuTrigger(props) {
|
|
|
25
25
|
const { clientX, clientY } = event;
|
|
26
26
|
menu.setAnchor(pointerType === "" || event.button < 0 && pointerType === "mouse" ? event.target : { getBoundingClientRect: () => new DOMRect(clientX, clientY) });
|
|
27
27
|
const focused = document.activeElement;
|
|
28
|
-
menu.
|
|
28
|
+
menu.returnTo = focused === document.body ? void 0 : focused;
|
|
29
29
|
const details = {
|
|
30
30
|
reason: "trigger-press",
|
|
31
31
|
event
|
|
32
32
|
};
|
|
33
33
|
menu.closeSubmenus(details);
|
|
34
|
-
menu.
|
|
34
|
+
menu.openAtFirst(details);
|
|
35
35
|
},
|
|
36
36
|
ref: (element) => {
|
|
37
37
|
menu.area = element;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { onSettled } from "solid-js";
|
|
2
|
+
// src/core/formReset.ts
|
|
3
|
+
var answers;
|
|
4
|
+
/**
|
|
5
|
+
* A form reset puts a native control back to its default, and so it does a
|
|
6
|
+
* part: `reset` asks for the part's default, through its setters, so that a
|
|
7
|
+
* controlled part asks. Listens to `form()`, read once the part has settled.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* onFormReset(
|
|
11
|
+
* () => input?.form,
|
|
12
|
+
* () => {
|
|
13
|
+
* setChecked(props.defaultChecked ?? false);
|
|
14
|
+
* onFlush(sync);
|
|
15
|
+
* },
|
|
16
|
+
* () => {
|
|
17
|
+
* input!.defaultChecked = input!.checked;
|
|
18
|
+
* },
|
|
19
|
+
* );
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* - `hold` runs during the event, before the browser resets the controls,
|
|
23
|
+
* and what it returns is `reset`'s second argument. A part whose state
|
|
24
|
+
* is its own, not the element's, makes each element's state there the
|
|
25
|
+
* attribute the browser resets it to (`defaultChecked`, `defaultValue`),
|
|
26
|
+
* so the reset leaves it as it is: it never shows a state the part does
|
|
27
|
+
* not hold, and a binding that re-runs before `reset`, such as a Field's
|
|
28
|
+
* `data-touched` as the touched state clears, does not write its value
|
|
29
|
+
* back over the reset element (`UNCOMMITTED_INPUT_OVERWRITTEN`). Each
|
|
30
|
+
* part writes its own, a line, so no part pays for another's.
|
|
31
|
+
* - `reset` runs in a task after the event, not in `onFlush`: when the user
|
|
32
|
+
* presses a reset button, the browser runs microtasks as each listener
|
|
33
|
+
* returns, before it resets the controls and before later listeners
|
|
34
|
+
* could cancel the reset (src/input/README.md, "A form reset asks").
|
|
35
|
+
* Every part's `reset` runs in the same task, in the order the parts
|
|
36
|
+
* listened, so a set equal to one made before it in the task
|
|
37
|
+
* does nothing (`createControllableSignal`), and a Field, which listens
|
|
38
|
+
* before the controls inside it, reads them in an `onFlush` after theirs.
|
|
39
|
+
* - A reset the app cancels asks for nothing: the reset is the event's
|
|
40
|
+
* default action, so its `defaultPrevented` is the app saying no.
|
|
41
|
+
* - A part the reset removes before the task, such as a row of a list
|
|
42
|
+
* going back to its default length, asks for nothing, so it does not
|
|
43
|
+
* write its row back.
|
|
44
|
+
*/
|
|
45
|
+
function onFormReset(form, reset, hold) {
|
|
46
|
+
onSettled(() => {
|
|
47
|
+
const target = form();
|
|
48
|
+
if (!target) return;
|
|
49
|
+
let disposed = false;
|
|
50
|
+
const onReset = (event) => {
|
|
51
|
+
const held = hold?.();
|
|
52
|
+
if (!answers) {
|
|
53
|
+
const queue = answers = [];
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
answers = void 0;
|
|
56
|
+
for (const answer of queue) answer();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
answers.push(() => {
|
|
60
|
+
if (!disposed && !event.defaultPrevented) reset(event, held);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
target.addEventListener("reset", onReset);
|
|
64
|
+
return () => {
|
|
65
|
+
disposed = true;
|
|
66
|
+
target.removeEventListener("reset", onReset);
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export { onFormReset };
|
package/dist/core/hiddenInput.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { onFormReset } from "./formReset.js";
|
|
1
2
|
import { effect, heldRead, ref, setAttribute, setProperty, template } from "@solidjs/web";
|
|
2
|
-
import { onFlush,
|
|
3
|
+
import { onFlush, untrack } from "solid-js";
|
|
3
4
|
// src/core/hiddenInput.tsx
|
|
4
5
|
var _tmpl$ = /* @__PURE__ */ template(`<input aria-hidden=true tabindex=-1 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>`);
|
|
5
6
|
/**
|
|
@@ -28,8 +29,8 @@ var _tmpl$ = /* @__PURE__ */ template(`<input aria-hidden=true tabindex=-1 style
|
|
|
28
29
|
* - `button` is where focus goes when the browser focuses the input, as it
|
|
29
30
|
* does when it blocks a submission.
|
|
30
31
|
* - `reset` asks for the control's default on a form reset, through the
|
|
31
|
-
* setter, so that a controlled control asks. A Radio's
|
|
32
|
-
* the group, which asks once.
|
|
32
|
+
* setter, so that a controlled control asks (`onFormReset`). A Radio's
|
|
33
|
+
* Items each ask the group, which asks once.
|
|
33
34
|
*
|
|
34
35
|
* A plain function with positional parameters, not a component with props:
|
|
35
36
|
* a component would wrap each prop in a getter, and an options object
|
|
@@ -46,15 +47,11 @@ function createHiddenInput(type, props, checked, setChecked, button, reset) {
|
|
|
46
47
|
event.stopPropagation();
|
|
47
48
|
if (props.readOnly) event.preventDefault();
|
|
48
49
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
onFlush(sync);
|
|
55
|
-
};
|
|
56
|
-
form.addEventListener("reset", onReset);
|
|
57
|
-
return () => form.removeEventListener("reset", onReset);
|
|
50
|
+
onFormReset(() => input?.form, () => {
|
|
51
|
+
reset();
|
|
52
|
+
onFlush(sync);
|
|
53
|
+
}, () => {
|
|
54
|
+
input.defaultChecked = input.checked;
|
|
58
55
|
});
|
|
59
56
|
return (() => {
|
|
60
57
|
var _el$ = _tmpl$();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FormContext } from "../../core/formContext.js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.js";
|
|
4
5
|
import { FieldRootContext } from "./FieldRootContext.js";
|
|
@@ -79,22 +80,19 @@ function FieldRoot(props) {
|
|
|
79
80
|
attributes
|
|
80
81
|
};
|
|
81
82
|
const touch = () => update(true);
|
|
83
|
+
const findForm = () => root?.querySelector(controlSelector)?.form ?? root?.closest("form");
|
|
82
84
|
onSettled(() => {
|
|
83
85
|
setSettled(true);
|
|
84
|
-
const form =
|
|
86
|
+
const form = findForm();
|
|
85
87
|
if (!form) return;
|
|
86
|
-
const onReset = (event) => onFlush(() => {
|
|
87
|
-
if (!event.defaultPrevented) update(false);
|
|
88
|
-
});
|
|
89
88
|
form.addEventListener("submit", touch);
|
|
90
89
|
form.addEventListener("invalid", touch, true);
|
|
91
|
-
form.addEventListener("reset", onReset);
|
|
92
90
|
return () => {
|
|
93
91
|
form.removeEventListener("submit", touch);
|
|
94
92
|
form.removeEventListener("invalid", touch, true);
|
|
95
|
-
form.removeEventListener("reset", onReset);
|
|
96
93
|
};
|
|
97
94
|
});
|
|
95
|
+
onFormReset(findForm, () => onFlush(() => update(false)));
|
|
98
96
|
const ownProps = merge(attributes, {
|
|
99
97
|
onFocusOut: (event) => {
|
|
100
98
|
const to = event.relatedTarget;
|
package/dist/form/Form.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FormContext } from "../core/formContext.js";
|
|
2
|
+
import { onFormReset } from "../core/formReset.js";
|
|
2
3
|
import { callHandler, mergeElementProps } from "../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../core/renderElement.js";
|
|
4
5
|
import { createComponent, spread, template } from "@solidjs/web";
|
|
@@ -22,12 +23,9 @@ function Form(props) {
|
|
|
22
23
|
const names = hidden();
|
|
23
24
|
return current && names !== true && !names.has(name) && Object.hasOwn(current, name) ? current[name] : void 0;
|
|
24
25
|
} };
|
|
25
|
-
const hide = (update) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (untrack(errors) === met) setHidden((names) => names === true ? names : update(names));
|
|
29
|
-
});
|
|
30
|
-
};
|
|
26
|
+
const hide = (update, met = untrack(errors)) => onFlush(() => {
|
|
27
|
+
if (untrack(errors) === met) setHidden((names) => names === true ? names : update(names));
|
|
28
|
+
});
|
|
31
29
|
const hideError = (event) => {
|
|
32
30
|
const name = event.target.name;
|
|
33
31
|
if (name) hide((names) => new Set(names).add(name));
|
|
@@ -36,10 +34,10 @@ function Form(props) {
|
|
|
36
34
|
onSettled(() => {
|
|
37
35
|
if (form) form.noValidate = true;
|
|
38
36
|
});
|
|
37
|
+
onFormReset(() => form, (_, met) => hide(() => true, met), () => untrack(errors));
|
|
39
38
|
const ownProps = {
|
|
40
39
|
onInput: hideError,
|
|
41
40
|
onChange: hideError,
|
|
42
|
-
onReset: (event) => hide((names) => event.defaultPrevented ? names : true),
|
|
43
41
|
onSubmit: (event) => {
|
|
44
42
|
if (!event.submitter?.formNoValidate && !form.checkValidity()) {
|
|
45
43
|
event.preventDefault();
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
1
2
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
3
|
import { renderElement } from "../../core/renderElement.js";
|
|
3
4
|
import { spread, template } from "@solidjs/web";
|
|
4
|
-
import { merge, omit, onFlush,
|
|
5
|
+
import { merge, omit, onFlush, untrack } from "solid-js";
|
|
5
6
|
// src/input/root/InputRoot.tsx
|
|
6
7
|
var _tmpl$ = /* @__PURE__ */ template(`<input>`);
|
|
7
8
|
/**
|
|
@@ -14,28 +15,18 @@ function InputRoot(props) {
|
|
|
14
15
|
const value = untrack(() => props.value);
|
|
15
16
|
if (element && value !== void 0 && element.value !== value) element.value = value;
|
|
16
17
|
};
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
event
|
|
30
|
-
});
|
|
31
|
-
onFlush(restoreValue);
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
form.addEventListener("reset", onReset);
|
|
35
|
-
return () => {
|
|
36
|
-
disposed = true;
|
|
37
|
-
form.removeEventListener("reset", onReset);
|
|
38
|
-
};
|
|
18
|
+
onFormReset(() => element?.form, (event, text) => {
|
|
19
|
+
const defaultText = untrack(() => props.defaultValue) ?? "";
|
|
20
|
+
if (text === defaultText) return;
|
|
21
|
+
props.onValueChange?.(defaultText, {
|
|
22
|
+
reason: "reset",
|
|
23
|
+
event
|
|
24
|
+
});
|
|
25
|
+
onFlush(restoreValue);
|
|
26
|
+
}, () => {
|
|
27
|
+
const text = element.value;
|
|
28
|
+
if (untrack(() => props.value) !== void 0) element.defaultValue = text;
|
|
29
|
+
return text;
|
|
39
30
|
});
|
|
40
31
|
const elementProps = merge(mergeElementProps({
|
|
41
32
|
onInput: (event) => {
|
|
@@ -36,7 +36,7 @@ function MenuPopup(props) {
|
|
|
36
36
|
},
|
|
37
37
|
onDismiss: (details) => menu.close(details),
|
|
38
38
|
get returnFocus() {
|
|
39
|
-
return props.returnFocus ?? ((focused) => focused ?? (focusInside ? menu.trigger : void 0));
|
|
39
|
+
return props.returnFocus ?? ((focused) => focused ?? (focusInside ? menu.returnTo ?? menu.trigger : void 0));
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
createPresence(options);
|
|
@@ -106,7 +106,7 @@ function MenuPopup(props) {
|
|
|
106
106
|
reason: "focus-out",
|
|
107
107
|
event
|
|
108
108
|
});
|
|
109
|
-
if (popup.contains(event.relatedTarget)) menu.trigger?.focus();
|
|
109
|
+
if (popup.contains(event.relatedTarget)) (menu.returnTo ?? menu.trigger)?.focus();
|
|
110
110
|
},
|
|
111
111
|
ref: (element) => {
|
|
112
112
|
popup = element;
|
|
@@ -27,7 +27,7 @@ function createMenu(props, parent) {
|
|
|
27
27
|
onArrowIn: (item, event) => {
|
|
28
28
|
event.preventDefault();
|
|
29
29
|
if (item.submenu) {
|
|
30
|
-
if (!item.disabled) item.submenu.
|
|
30
|
+
if (!item.disabled) item.submenu.openAtFirst({
|
|
31
31
|
reason: "arrow-key",
|
|
32
32
|
event
|
|
33
33
|
});
|
|
@@ -62,7 +62,7 @@ function createMenu(props, parent) {
|
|
|
62
62
|
for (const submenu of submenus) submenu.close(details);
|
|
63
63
|
},
|
|
64
64
|
closeAll: (details) => parent ? parent.closeAll(details) : menu.close(details),
|
|
65
|
-
|
|
65
|
+
openAtFirst: (details) => {
|
|
66
66
|
setOpen(true, details);
|
|
67
67
|
list.move(list.items()[0]);
|
|
68
68
|
},
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.js";
|
|
4
5
|
import { parseNumber } from "../parse.js";
|
|
5
6
|
import { NumberFieldRootContext } from "./NumberFieldRootContext.js";
|
|
6
7
|
import { createComponent, effect, heldRead, memo, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
7
|
-
import { createMemo, createUniqueId, omit, onFlush,
|
|
8
|
+
import { createMemo, createUniqueId, omit, onFlush, untrack } from "solid-js";
|
|
8
9
|
// src/number-field/root/NumberFieldRoot.tsx
|
|
9
10
|
var _tmpl$ = /* @__PURE__ */ template(`<input type=number aria-hidden=true tabindex=-1 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>`);
|
|
10
11
|
var _tmpl$2 = /* @__PURE__ */ template(`<div>`);
|
|
@@ -102,22 +103,11 @@ function NumberFieldRoot(props) {
|
|
|
102
103
|
change(roundAndClamp(parsed, options.maximumFractionDigits + (options.style === "percent" ? 2 : 0)));
|
|
103
104
|
}
|
|
104
105
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
setTimeout(() => {
|
|
111
|
-
if (disposed || event.defaultPrevented) return;
|
|
112
|
-
setValue(props.defaultValue ?? null);
|
|
113
|
-
onFlush(sync);
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
form.addEventListener("reset", onReset);
|
|
117
|
-
return () => {
|
|
118
|
-
disposed = true;
|
|
119
|
-
form.removeEventListener("reset", onReset);
|
|
120
|
-
};
|
|
106
|
+
onFormReset(() => hidden?.form, () => {
|
|
107
|
+
setValue(props.defaultValue ?? null);
|
|
108
|
+
onFlush(sync);
|
|
109
|
+
}, () => {
|
|
110
|
+
hidden.defaultValue = hidden.value;
|
|
121
111
|
});
|
|
122
112
|
const elementProps = mergeElementProps(context.attributes, omit(props, "render", "value", "defaultValue", "onValueChange", "min", "max", "step", "largeStep", "format", "locale", "name", "form", "required", "disabled", "readOnly", "id", "aria-describedby", "aria-invalid"));
|
|
123
113
|
return createComponent(NumberFieldRootContext, {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { warnUnlessButton } from "../../core/button.js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.js";
|
|
4
5
|
import { useSelectContext } from "../root/SelectContext.js";
|
|
5
6
|
import { effect, heldRead, isDev, memo, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
6
|
-
import { createUniqueId, merge, omit, onFlush,
|
|
7
|
+
import { createUniqueId, merge, omit, onFlush, untrack } from "solid-js";
|
|
7
8
|
// src/select/trigger/SelectTrigger.tsx
|
|
8
9
|
var _tmpl$ = /* @__PURE__ */ template(`<input aria-hidden=true tabindex=-1 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>`);
|
|
9
10
|
var _tmpl$2 = /* @__PURE__ */ template(`<button>`);
|
|
@@ -112,15 +113,11 @@ function SelectTrigger(props) {
|
|
|
112
113
|
else if (!filled) select.setValue(null);
|
|
113
114
|
onFlush(syncInput);
|
|
114
115
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
onFlush(syncInput);
|
|
121
|
-
};
|
|
122
|
-
form.addEventListener("reset", onReset);
|
|
123
|
-
return () => form.removeEventListener("reset", onReset);
|
|
116
|
+
onFormReset(() => input?.form, () => {
|
|
117
|
+
select.setValue(select.props.defaultValue ?? null);
|
|
118
|
+
onFlush(syncInput);
|
|
119
|
+
}, () => {
|
|
120
|
+
input.defaultValue = input.value;
|
|
124
121
|
});
|
|
125
122
|
const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
|
|
126
123
|
return [memo(() => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.js";
|
|
4
5
|
import { SliderRootContext } from "./SliderRootContext.js";
|
|
5
6
|
import { createComponent, spread, template } from "@solidjs/web";
|
|
6
|
-
import { createMemo, merge, omit, onFlush,
|
|
7
|
+
import { createMemo, merge, omit, onFlush, untrack } from "solid-js";
|
|
7
8
|
// src/slider/root/SliderRoot.tsx
|
|
8
9
|
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
9
10
|
var places = (number) => (String(number).split(".")[1] ?? "").length;
|
|
@@ -83,27 +84,16 @@ function SliderRoot(props) {
|
|
|
83
84
|
props.onValueCommit?.(current);
|
|
84
85
|
}
|
|
85
86
|
};
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
sync();
|
|
97
|
-
const current = untrack(value);
|
|
98
|
-
if (current !== before) props.onValueCommit?.(current);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
form.addEventListener("reset", onReset);
|
|
103
|
-
return () => {
|
|
104
|
-
disposed = true;
|
|
105
|
-
form.removeEventListener("reset", onReset);
|
|
106
|
-
};
|
|
87
|
+
onFormReset(() => context.input?.form, () => {
|
|
88
|
+
const before = requested();
|
|
89
|
+
setValue(defaultValue());
|
|
90
|
+
onFlush(() => {
|
|
91
|
+
sync();
|
|
92
|
+
const current = untrack(value);
|
|
93
|
+
if (current !== before) props.onValueCommit?.(current);
|
|
94
|
+
});
|
|
95
|
+
}, () => {
|
|
96
|
+
context.input.defaultValue = context.input.value;
|
|
107
97
|
});
|
|
108
98
|
const ownProps = merge(context.attributes, { get style() {
|
|
109
99
|
return { "--slider": `${(Math.min(Math.max(value(), min()), max()) - min()) / (max() - min()) * 100}%` };
|
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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;
|