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.
- package/README.md +1 -1
- 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/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/number-field/root/NumberFieldRoot.js +7 -17
- package/dist/select/trigger/SelectTrigger.js +7 -10
- package/dist/slider/index.js +2 -0
- package/dist/slider/index.parts.js +5 -0
- package/dist/slider/root/SliderRoot.js +113 -0
- package/dist/slider/root/SliderRootContext.js +10 -0
- package/dist/slider/thumb/SliderThumb.js +119 -0
- package/dist/slider/track/SliderTrack.js +65 -0
- package/dist/slider/value/SliderValue.js +24 -0
- 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/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/number-field/root/NumberFieldRoot.jsx +9 -25
- package/dist/source/select/trigger/SelectTrigger.jsx +9 -13
- package/dist/source/slider/index.d.ts +1 -0
- package/dist/source/slider/index.js +1 -0
- package/dist/source/slider/index.parts.d.ts +4 -0
- package/dist/source/slider/index.parts.js +4 -0
- package/dist/source/slider/root/SliderRoot.d.ts +55 -0
- package/dist/source/slider/root/SliderRoot.jsx +136 -0
- package/dist/source/slider/root/SliderRootContext.d.ts +51 -0
- package/dist/source/slider/root/SliderRootContext.js +13 -0
- package/dist/source/slider/thumb/SliderThumb.d.ts +13 -0
- package/dist/source/slider/thumb/SliderThumb.jsx +91 -0
- package/dist/source/slider/track/SliderTrack.d.ts +11 -0
- package/dist/source/slider/track/SliderTrack.jsx +79 -0
- package/dist/source/slider/value/SliderValue.d.ts +11 -0
- package/dist/source/slider/value/SliderValue.jsx +18 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ For everything else, go to the docs:
|
|
|
62
62
|
|
|
63
63
|
Early 0.x versions: the API may change between minor versions. The form components come next; the plan and roadmap are in the [repository](https://github.com/j13n/menhir). Built so far:
|
|
64
64
|
|
|
65
|
-
- Components: Accordion, Alert Dialog, Autocomplete, Checkbox, Checkbox Group, Collapsible, Combobox, Context Menu, Dialog, Field, Form, Input, Menu, Menubar, Meter, Navigation Menu, Number Field, Popover, Progress, Radio, Select, Separator, Switch, Tabs, Toggle, Toggle Group and Tooltip.
|
|
65
|
+
- Components: Accordion, Alert Dialog, Autocomplete, Checkbox, Checkbox Group, Collapsible, Combobox, Context Menu, Dialog, Field, Form, Input, Menu, Menubar, Meter, Navigation Menu, Number Field, Popover, Progress, Radio, Select, Separator, Slider, Switch, Tabs, Toggle, Toggle Group and Tooltip.
|
|
66
66
|
- Utilities: color scheme and theme, each with local-storage and cookie storage.
|
|
67
67
|
|
|
68
68
|
## Licence
|
|
@@ -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 };
|
|
@@ -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) => {
|
|
@@ -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(() => {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SliderRoot } from "./root/SliderRoot.js";
|
|
2
|
+
import { SliderTrack } from "./track/SliderTrack.js";
|
|
3
|
+
import { SliderThumb } from "./thumb/SliderThumb.js";
|
|
4
|
+
import { SliderValue } from "./value/SliderValue.js";
|
|
5
|
+
export { SliderRoot as Root, SliderThumb as Thumb, SliderTrack as Track, SliderValue as Value };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
3
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
4
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
5
|
+
import { SliderRootContext } from "./SliderRootContext.js";
|
|
6
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
7
|
+
import { createMemo, merge, omit, onFlush, untrack } from "solid-js";
|
|
8
|
+
// src/slider/root/SliderRoot.tsx
|
|
9
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
10
|
+
var places = (number) => (String(number).split(".")[1] ?? "").length;
|
|
11
|
+
/**
|
|
12
|
+
* The slider: a `<div>` around its parts, which holds the value and sets
|
|
13
|
+
* `--slider` to its percentage of the range. Its `id`, `aria-describedby`
|
|
14
|
+
* and `aria-invalid` go on the Thumb's input, so it joins a Field as
|
|
15
|
+
* `Field.Control`'s `render`.
|
|
16
|
+
*/
|
|
17
|
+
function SliderRoot(props) {
|
|
18
|
+
const min = () => props.min ?? 0;
|
|
19
|
+
const max = () => props.max ?? 100;
|
|
20
|
+
const stepSize = () => props.step ?? 1;
|
|
21
|
+
const snap = (number, round) => {
|
|
22
|
+
const step = stepSize();
|
|
23
|
+
const steps = Math.min(Math.max(round((number - min()) / step), 0), Math.floor((max() - min()) / step + 1e-9));
|
|
24
|
+
return Number((min() + steps * step).toFixed(Math.max(places(step), places(min()))));
|
|
25
|
+
};
|
|
26
|
+
const defaultValue = () => props.defaultValue ?? snap((min() + max()) / 2, Math.round);
|
|
27
|
+
const [value, setValue, requested] = createControllableSignal({
|
|
28
|
+
get value() {
|
|
29
|
+
return props.value;
|
|
30
|
+
},
|
|
31
|
+
get defaultValue() {
|
|
32
|
+
return defaultValue();
|
|
33
|
+
},
|
|
34
|
+
onChange: (next) => props.onValueChange?.(next)
|
|
35
|
+
});
|
|
36
|
+
const formatText = createMemo(() => {
|
|
37
|
+
const format = props.format;
|
|
38
|
+
if (typeof format === "function") return format;
|
|
39
|
+
const formatter = new Intl.NumberFormat(props.locale, format);
|
|
40
|
+
return (number) => formatter.format(number);
|
|
41
|
+
});
|
|
42
|
+
const sync = () => {
|
|
43
|
+
if (context.input) context.input.value = String(untrack(value));
|
|
44
|
+
};
|
|
45
|
+
const fire = (type) => context.input?.dispatchEvent(new Event(type, { bubbles: true }));
|
|
46
|
+
let start = 0;
|
|
47
|
+
let holds = 0;
|
|
48
|
+
const context = {
|
|
49
|
+
props,
|
|
50
|
+
value,
|
|
51
|
+
requested,
|
|
52
|
+
min,
|
|
53
|
+
max,
|
|
54
|
+
stepSize,
|
|
55
|
+
text: () => formatText()(value()),
|
|
56
|
+
attributes: {
|
|
57
|
+
get "data-disabled"() {
|
|
58
|
+
return props.disabled ? "" : void 0;
|
|
59
|
+
},
|
|
60
|
+
get "data-horizontal"() {
|
|
61
|
+
return props.orientation === "vertical" ? void 0 : "";
|
|
62
|
+
},
|
|
63
|
+
get "data-vertical"() {
|
|
64
|
+
return props.orientation === "vertical" ? "" : void 0;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
change: (number, round = Math.round) => {
|
|
68
|
+
const next = snap(number, round);
|
|
69
|
+
if (next === requested()) return;
|
|
70
|
+
if (context.input) context.input.value = String(next);
|
|
71
|
+
setValue(next);
|
|
72
|
+
fire("input");
|
|
73
|
+
onFlush(sync);
|
|
74
|
+
},
|
|
75
|
+
step: (amount) => context.change(requested() + amount, amount > 0 ? (steps) => Math.floor(steps + 1e-9) : (steps) => Math.ceil(steps - 1e-9)),
|
|
76
|
+
begin: () => {
|
|
77
|
+
if (!holds++) start = requested();
|
|
78
|
+
},
|
|
79
|
+
end: () => {
|
|
80
|
+
if (--holds) return;
|
|
81
|
+
const current = requested();
|
|
82
|
+
if (current === start) return;
|
|
83
|
+
fire("change");
|
|
84
|
+
props.onValueCommit?.(current);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
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;
|
|
97
|
+
});
|
|
98
|
+
const ownProps = merge(context.attributes, { get style() {
|
|
99
|
+
return { "--slider": `${(Math.min(Math.max(value(), min()), max()) - min()) / (max() - min()) * 100}%` };
|
|
100
|
+
} });
|
|
101
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "defaultValue", "onValueChange", "onValueCommit", "min", "max", "step", "largeStep", "orientation", "format", "locale", "name", "form", "disabled", "id", "aria-describedby", "aria-invalid"));
|
|
102
|
+
return createComponent(SliderRootContext, {
|
|
103
|
+
value: context,
|
|
104
|
+
get children() {
|
|
105
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
106
|
+
var _el$ = _tmpl$();
|
|
107
|
+
spread(_el$, p, false);
|
|
108
|
+
return _el$;
|
|
109
|
+
})());
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
export { SliderRoot };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/slider/root/SliderRootContext.ts
|
|
4
|
+
var SliderRootContext = createContext(null);
|
|
5
|
+
function useSliderRootContext() {
|
|
6
|
+
const context = useContext(SliderRootContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Slider parts must be placed within <Slider.Root>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { SliderRootContext, useSliderRootContext };
|