@nvidia-elements/forms 0.0.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -1
- package/NOTICE.md +1 -39
- package/dist/custom-elements.json +1293 -254
- package/dist/examples/csv.examples.js.map +1 -1
- package/dist/examples/light.examples.js.map +1 -1
- package/dist/examples/simple.examples.js.map +1 -1
- package/dist/examples/visualization.examples.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/controllers/state-active.controller.d.ts +13 -0
- package/dist/internal/controllers/state-active.controller.js +26 -0
- package/dist/internal/controllers/state-active.controller.js.map +1 -0
- package/dist/internal/controllers/state-current.controller.d.ts +15 -0
- package/dist/internal/controllers/state-current.controller.js +34 -0
- package/dist/internal/controllers/state-current.controller.js.map +1 -0
- package/dist/internal/controllers/state-disabled.controller.d.ts +18 -0
- package/dist/internal/controllers/state-disabled.controller.js +17 -0
- package/dist/internal/controllers/state-disabled.controller.js.map +1 -0
- package/dist/internal/controllers/state-expanded.controller.d.ts +12 -0
- package/dist/internal/controllers/state-expanded.controller.js +17 -0
- package/dist/internal/controllers/state-expanded.controller.js.map +1 -0
- package/dist/internal/controllers/state-pressed.controller.d.ts +12 -0
- package/dist/internal/controllers/state-pressed.controller.js +17 -0
- package/dist/internal/controllers/state-pressed.controller.js.map +1 -0
- package/dist/internal/controllers/state-readonly.controller.d.ts +12 -0
- package/dist/internal/controllers/state-readonly.controller.js +17 -0
- package/dist/internal/controllers/state-readonly.controller.js.map +1 -0
- package/dist/internal/controllers/state-selected.controller.d.ts +15 -0
- package/dist/internal/controllers/state-selected.controller.js +34 -0
- package/dist/internal/controllers/state-selected.controller.js.map +1 -0
- package/dist/internal/controllers/type-anchor.controller.d.ts +15 -0
- package/dist/internal/controllers/type-anchor.controller.js +51 -0
- package/dist/internal/controllers/type-anchor.controller.js.map +1 -0
- package/dist/internal/controllers/type-button.controller.d.ts +14 -0
- package/dist/internal/controllers/type-button.controller.js +22 -0
- package/dist/internal/controllers/type-button.controller.js.map +1 -0
- package/dist/internal/controllers/type-command.controller.d.ts +16 -0
- package/dist/internal/controllers/type-command.controller.js +36 -0
- package/dist/internal/controllers/type-command.controller.js.map +1 -0
- package/dist/internal/controllers/type-interest-invoker.controller.d.ts +12 -0
- package/dist/internal/controllers/type-interest-invoker.controller.js +38 -0
- package/dist/internal/controllers/type-interest-invoker.controller.js.map +1 -0
- package/dist/internal/controllers/type-native-button.controller.d.ts +19 -0
- package/dist/internal/controllers/type-native-button.controller.js +54 -0
- package/dist/internal/controllers/type-native-button.controller.js.map +1 -0
- package/dist/internal/controllers/type-popover-trigger.controller.d.ts +16 -0
- package/dist/internal/controllers/type-popover-trigger.controller.js +21 -0
- package/dist/internal/controllers/type-popover-trigger.controller.js.map +1 -0
- package/dist/internal/controllers/types.d.ts +8 -0
- package/dist/internal/errors.js.map +1 -1
- package/dist/internal/schema.js.map +1 -1
- package/dist/internal/types.d.ts +18 -4
- package/dist/internal/utils.d.ts +17 -0
- package/dist/internal/utils.js +53 -1
- package/dist/internal/utils.js.map +1 -1
- package/dist/mixins/button.d.ts +22 -0
- package/dist/mixins/button.js +344 -0
- package/dist/mixins/button.js.map +1 -0
- package/dist/mixins/button.types.d.ts +116 -0
- package/dist/mixins/checkbox.d.ts +41 -0
- package/dist/mixins/checkbox.js +109 -0
- package/dist/mixins/checkbox.js.map +1 -0
- package/dist/mixins/control.d.ts +189 -0
- package/dist/mixins/control.js +358 -0
- package/dist/mixins/control.js.map +1 -0
- package/dist/mixins/index.d.ts +5 -0
- package/dist/mixins/index.js +6 -0
- package/dist/mixins/select.d.ts +49 -0
- package/dist/mixins/select.js +80 -0
- package/dist/mixins/select.js.map +1 -0
- package/dist/mixins/slider.d.ts +62 -0
- package/dist/mixins/slider.js +175 -0
- package/dist/mixins/slider.js.map +1 -0
- package/dist/validators/index.js.map +1 -1
- package/package.json +25 -19
- package/dist/mixin/index.d.ts +0 -460
- package/dist/mixin/index.js +0 -188
- package/dist/mixin/index.js.map +0 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FormControlMixin as e } from "./control.js";
|
|
2
|
+
import { ButtonFormControlMixin as t } from "./button.js";
|
|
3
|
+
import { CheckboxFormControlMixin as n } from "./checkbox.js";
|
|
4
|
+
import { SelectFormControlMixin as r } from "./select.js";
|
|
5
|
+
import { SliderFormControlMixin as i } from "./slider.js";
|
|
6
|
+
export { t as ButtonFormControlMixin, n as CheckboxFormControlMixin, e as FormControlMixin, r as SelectFormControlMixin, i as SliderFormControlMixin };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { FormControlValue } from '../internal/types.js';
|
|
2
|
+
import { FormControlMixinInstance } from './index.js';
|
|
3
|
+
type Constructor = (new (...args: any[]) => HTMLElement & {
|
|
4
|
+
connectedCallback?(): void;
|
|
5
|
+
attributeChangedCallback?(name: string, oldValue: string | null, newValue: string | null): void;
|
|
6
|
+
requestUpdate?(name?: string, oldValue?: unknown): void;
|
|
7
|
+
}) & {
|
|
8
|
+
observedAttributes?: string[];
|
|
9
|
+
};
|
|
10
|
+
export type SelectFormControlValue = Extract<FormControlValue, string>;
|
|
11
|
+
export interface SelectFormControlMixinInstance extends FormControlMixinInstance<SelectFormControlValue> {
|
|
12
|
+
/**
|
|
13
|
+
* The number of options available in the select.
|
|
14
|
+
*/
|
|
15
|
+
length: number;
|
|
16
|
+
/**
|
|
17
|
+
* The options available in the select.
|
|
18
|
+
*/
|
|
19
|
+
options: HTMLOptionElement[];
|
|
20
|
+
/**
|
|
21
|
+
* The index of the selected option.
|
|
22
|
+
*/
|
|
23
|
+
selectedIndex: number;
|
|
24
|
+
/**
|
|
25
|
+
* The selected options.
|
|
26
|
+
*/
|
|
27
|
+
selectedOptions: HTMLOptionElement[];
|
|
28
|
+
/**
|
|
29
|
+
* The select control type.
|
|
30
|
+
*/
|
|
31
|
+
type: 'select-one';
|
|
32
|
+
/**
|
|
33
|
+
* The selected value.
|
|
34
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#value
|
|
35
|
+
* @attr value
|
|
36
|
+
* @reflect
|
|
37
|
+
*/
|
|
38
|
+
value: SelectFormControlValue;
|
|
39
|
+
updateSelectState(): void;
|
|
40
|
+
}
|
|
41
|
+
export type SelectFormControlMixinReturn<TBase extends Constructor> = (new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> & SelectFormControlMixinInstance) & {
|
|
42
|
+
formAssociated: boolean;
|
|
43
|
+
observedAttributes: string[];
|
|
44
|
+
} & Omit<TBase, 'prototype'>;
|
|
45
|
+
/**
|
|
46
|
+
* @description A mixin that adds native single-select form control behavior.
|
|
47
|
+
*/
|
|
48
|
+
export declare function SelectFormControlMixin<TBase extends Constructor>(SuperClass: TBase): SelectFormControlMixinReturn<TBase>;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { FormControlMixin as e } from "./control.js";
|
|
2
|
+
//#region src/mixins/select.ts
|
|
3
|
+
var t = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
function n(n) {
|
|
5
|
+
let i = e(n);
|
|
6
|
+
return class extends i {
|
|
7
|
+
#e;
|
|
8
|
+
get disabled() {
|
|
9
|
+
return super.disabled;
|
|
10
|
+
}
|
|
11
|
+
set disabled(e) {
|
|
12
|
+
super.disabled = !!e, this.updateSelectState();
|
|
13
|
+
}
|
|
14
|
+
get length() {
|
|
15
|
+
return this.options.length;
|
|
16
|
+
}
|
|
17
|
+
get options() {
|
|
18
|
+
return Array.from(this.#a?.options ?? []);
|
|
19
|
+
}
|
|
20
|
+
get selectedIndex() {
|
|
21
|
+
return this.#a?.selectedIndex ?? this.options.findIndex((e) => e.selected);
|
|
22
|
+
}
|
|
23
|
+
set selectedIndex(e) {
|
|
24
|
+
let t = this.options[e];
|
|
25
|
+
this.value = t?.value ?? "";
|
|
26
|
+
}
|
|
27
|
+
get selectedOptions() {
|
|
28
|
+
return Array.from(this.#a?.selectedOptions ?? this.options.filter((e) => e.selected));
|
|
29
|
+
}
|
|
30
|
+
get type() {
|
|
31
|
+
return "select-one";
|
|
32
|
+
}
|
|
33
|
+
set type(e) {}
|
|
34
|
+
get value() {
|
|
35
|
+
return t.get(this) ?? "";
|
|
36
|
+
}
|
|
37
|
+
set value(e) {
|
|
38
|
+
this.#t(r(e), !0);
|
|
39
|
+
}
|
|
40
|
+
connectedCallback() {
|
|
41
|
+
super.connectedCallback(), this.#e ??= this.value, this.updateSelectState();
|
|
42
|
+
}
|
|
43
|
+
formResetCallback() {
|
|
44
|
+
this.value = this.#e ?? this.#r(), this.updateSelectState();
|
|
45
|
+
}
|
|
46
|
+
formStateRestoreCallback(e, t) {
|
|
47
|
+
this.value = e ?? this.#e ?? this.#r(), this.updateSelectState();
|
|
48
|
+
}
|
|
49
|
+
_updateFormState() {
|
|
50
|
+
this.updateSelectState();
|
|
51
|
+
}
|
|
52
|
+
updateSelectState() {
|
|
53
|
+
let e = this.#n(this.value);
|
|
54
|
+
Object.is(this.value, e) || t.set(this, e), this.#i(e), this._internals.setFormValue(!this.disabled && this.name && this.selectedIndex >= 0 ? e : null);
|
|
55
|
+
}
|
|
56
|
+
#t(e, n) {
|
|
57
|
+
let r = this.value;
|
|
58
|
+
Object.is(r, e) || (t.set(this, e), n && this.setAttribute("value", e), this.updateSelectState(), this.checkValidity(), this.requestUpdate?.("value", r));
|
|
59
|
+
}
|
|
60
|
+
#n(e) {
|
|
61
|
+
return this.options.length > 0 && !this.options.some((t) => t.value === e) ? "" : e;
|
|
62
|
+
}
|
|
63
|
+
#r() {
|
|
64
|
+
return this.options[0]?.value ?? "";
|
|
65
|
+
}
|
|
66
|
+
#i(e) {
|
|
67
|
+
this.#a && this.#a.value !== e && (this.#a.value = e);
|
|
68
|
+
}
|
|
69
|
+
get #a() {
|
|
70
|
+
return this.shadowRoot?.querySelector("select") ?? null;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function r(e) {
|
|
75
|
+
return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? `${e}` : "";
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { n as SelectFormControlMixin };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","names":["#selectElement","#setValue","#initialValue","#getDefaultValue","#getSelectValue","#syncNativeSelect"],"sources":["../../src/mixins/select.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { FormControlValue } from '../internal/types.js';\nimport { FormControlMixin, type FormControlMixinInstance } from './index.js';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor = (new (...args: any[]) => HTMLElement & {\n connectedCallback?(): void;\n attributeChangedCallback?(name: string, oldValue: string | null, newValue: string | null): void;\n requestUpdate?(name?: string, oldValue?: unknown): void;\n}) & {\n observedAttributes?: string[];\n};\n\nexport type SelectFormControlValue = Extract<FormControlValue, string>;\n\nexport interface SelectFormControlMixinInstance extends FormControlMixinInstance<SelectFormControlValue> {\n /**\n * The number of options available in the select.\n */\n length: number;\n\n /**\n * The options available in the select.\n */\n options: HTMLOptionElement[];\n\n /**\n * The index of the selected option.\n */\n selectedIndex: number;\n\n /**\n * The selected options.\n */\n selectedOptions: HTMLOptionElement[];\n\n /**\n * The select control type.\n */\n type: 'select-one';\n\n /**\n * The selected value.\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#value\n * @attr value\n * @reflect\n */\n value: SelectFormControlValue;\n\n updateSelectState(): void;\n}\n\nexport type SelectFormControlMixinReturn<TBase extends Constructor> = (new (\n ...args: ConstructorParameters<TBase>\n) => InstanceType<TBase> & SelectFormControlMixinInstance) & {\n formAssociated: boolean;\n observedAttributes: string[];\n} & Omit<TBase, 'prototype'>;\n\ninterface SelectBaseInstance extends HTMLElement, FormControlMixinInstance<SelectFormControlValue> {\n connectedCallback(): void;\n attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;\n requestUpdate?(name?: string, oldValue?: unknown): void;\n}\n\ntype SelectBaseConstructor<TBase extends Constructor> = (new (\n ...args: ConstructorParameters<TBase>\n) => SelectBaseInstance) & {\n formAssociated: boolean;\n observedAttributes: string[];\n};\n\nconst selectValues = new WeakMap<object, SelectFormControlValue>();\n\n/**\n * @description A mixin that adds native single-select form control behavior.\n */\nexport function SelectFormControlMixin<TBase extends Constructor>(\n SuperClass: TBase\n): SelectFormControlMixinReturn<TBase> {\n const Base = FormControlMixin<TBase, SelectFormControlValue>(SuperClass) as SelectBaseConstructor<TBase>;\n\n return class SelectFormControlBase extends Base {\n #initialValue: SelectFormControlValue | undefined;\n\n override get disabled(): boolean {\n return super.disabled;\n }\n\n override set disabled(value: boolean) {\n super.disabled = Boolean(value);\n this.updateSelectState();\n }\n\n get length() {\n return this.options.length;\n }\n\n get options(): HTMLOptionElement[] {\n return Array.from(this.#selectElement?.options ?? []);\n }\n\n get selectedIndex() {\n return this.#selectElement?.selectedIndex ?? this.options.findIndex(option => option.selected);\n }\n\n set selectedIndex(value: number) {\n const option = this.options[value];\n this.value = option?.value ?? '';\n }\n\n get selectedOptions(): HTMLOptionElement[] {\n return Array.from(this.#selectElement?.selectedOptions ?? this.options.filter(option => option.selected));\n }\n\n override get type(): 'select-one' {\n return 'select-one';\n }\n\n override set type(_value: string) {}\n\n override get value(): SelectFormControlValue {\n return selectValues.get(this) ?? '';\n }\n\n override set value(value: FormControlValue | undefined) {\n this.#setValue(getSelectValue(value), true);\n }\n\n override connectedCallback() {\n super.connectedCallback();\n this.#initialValue ??= this.value;\n this.updateSelectState();\n }\n\n override formResetCallback() {\n this.value = this.#initialValue ?? this.#getDefaultValue();\n this.updateSelectState();\n }\n\n override formStateRestoreCallback(state: SelectFormControlValue | null, _reason?: string) {\n this.value = state ?? this.#initialValue ?? this.#getDefaultValue();\n this.updateSelectState();\n }\n\n override _updateFormState() {\n this.updateSelectState();\n }\n\n updateSelectState() {\n const value = this.#getSelectValue(this.value);\n if (!Object.is(this.value, value)) {\n selectValues.set(this, value);\n }\n this.#syncNativeSelect(value);\n this._internals.setFormValue(!this.disabled && this.name && this.selectedIndex >= 0 ? value : null);\n }\n\n #setValue(value: SelectFormControlValue, reflect: boolean) {\n const previousValue = this.value;\n if (Object.is(previousValue, value)) {\n return;\n }\n\n selectValues.set(this, value);\n if (reflect) {\n this.setAttribute('value', value);\n }\n this.updateSelectState();\n this.checkValidity();\n this.requestUpdate?.('value', previousValue);\n }\n\n #getSelectValue(value: SelectFormControlValue) {\n return this.options.length > 0 && !this.options.some(option => option.value === value) ? '' : value;\n }\n\n #getDefaultValue() {\n return this.options[0]?.value ?? '';\n }\n\n #syncNativeSelect(value: SelectFormControlValue) {\n if (this.#selectElement && this.#selectElement.value !== value) {\n this.#selectElement.value = value;\n }\n }\n\n get #selectElement() {\n return this.shadowRoot?.querySelector('select') ?? null;\n }\n } as unknown as SelectFormControlMixinReturn<TBase>;\n}\n\nfunction getSelectValue(value: FormControlValue | undefined) {\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return `${value}`;\n }\n\n return '';\n}\n"],"mappings":";;AA0EA,IAAM,oBAAe,IAAI,QAAwC;AAKjE,SAAgB,EACd,GACqC;CACrC,IAAM,IAAO,EAAgD,CAAU;CAEvE,OAAO,cAAoC,EAAK;EAC9C;EAEA,IAAa,WAAoB;GAC/B,OAAO,MAAM;EACf;EAEA,IAAa,SAAS,GAAgB;GAEpC,AADA,MAAM,WAAW,EAAQ,GACzB,KAAK,kBAAkB;EACzB;EAEA,IAAI,SAAS;GACX,OAAO,KAAK,QAAQ;EACtB;EAEA,IAAI,UAA+B;GACjC,OAAO,MAAM,KAAK,KAAKA,IAAgB,WAAW,CAAC,CAAC;EACtD;EAEA,IAAI,gBAAgB;GAClB,OAAO,KAAKA,IAAgB,iBAAiB,KAAK,QAAQ,WAAU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AAK,cAAc,GACnB,KAAK,gBAAgB,SAAS,CAAa;EAC7C;EAEA,GAAgB,GAA+B;GAC7C,OAAO,KAAK,QAAQ,SAAS,KAAK,CAAC,KAAK,QAAQ,MAAK,MAAU,EAAO,UAAU,CAAK,IAAI,KAAK;EAChG;EAEA,KAAmB;GACjB,OAAO,KAAK,QAAQ,IAAI,SAAS;EACnC;EAEA,GAAkB,GAA+B;GAC/C,AAAI,KAAKL,MAAkB,KAAKA,GAAe,UAAU,MACvD,KAAKA,GAAe,QAAQ;EAEhC;EAEA,IAAIA,KAAiB;GACnB,OAAO,KAAK,YAAY,cAAc,QAAQ,KAAK;EACrD;CACF;AACF;AAEA,SAAS,EAAe,GAAqC;CAK3D,OAJI,OAAO,KAAU,YAAY,OAAO,KAAU,YAAY,OAAO,KAAU,YACtE,GAAG,MAGL;AACT"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { FormControlValue } from '../internal/types.js';
|
|
2
|
+
import { FormControlMixinInstance } from './index.js';
|
|
3
|
+
type Constructor = (new (...args: any[]) => HTMLElement & {
|
|
4
|
+
connectedCallback?(): void;
|
|
5
|
+
attributeChangedCallback?(name: string, oldValue: string | null, newValue: string | null): void;
|
|
6
|
+
requestUpdate?(name?: string, oldValue?: unknown): void;
|
|
7
|
+
}) & {
|
|
8
|
+
observedAttributes?: string[];
|
|
9
|
+
};
|
|
10
|
+
export type SliderFormControlValue = Extract<FormControlValue, number>;
|
|
11
|
+
export interface SliderFormControlMixinInstance extends FormControlMixinInstance<SliderFormControlValue> {
|
|
12
|
+
/**
|
|
13
|
+
* Defines the maximum slider value.
|
|
14
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range#max
|
|
15
|
+
* @attr max
|
|
16
|
+
* @reflect
|
|
17
|
+
*/
|
|
18
|
+
max: number;
|
|
19
|
+
/**
|
|
20
|
+
* Defines the minimum slider value.
|
|
21
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range#min
|
|
22
|
+
* @attr min
|
|
23
|
+
* @reflect
|
|
24
|
+
*/
|
|
25
|
+
min: number;
|
|
26
|
+
/**
|
|
27
|
+
* Defines the slider value granularity.
|
|
28
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range#step
|
|
29
|
+
* @attr step
|
|
30
|
+
* @reflect
|
|
31
|
+
*/
|
|
32
|
+
step: number;
|
|
33
|
+
/**
|
|
34
|
+
* The current slider value.
|
|
35
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range#value
|
|
36
|
+
* @attr value
|
|
37
|
+
* @reflect
|
|
38
|
+
*/
|
|
39
|
+
value: number;
|
|
40
|
+
/**
|
|
41
|
+
* The current slider value as a number.
|
|
42
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/valueAsNumber
|
|
43
|
+
*/
|
|
44
|
+
valueAsNumber: number;
|
|
45
|
+
updateSliderState(): void;
|
|
46
|
+
}
|
|
47
|
+
export interface SliderFormControlDefaults {
|
|
48
|
+
max?: number;
|
|
49
|
+
min?: number;
|
|
50
|
+
step?: number;
|
|
51
|
+
value?: number;
|
|
52
|
+
}
|
|
53
|
+
export type SliderFormControlMixinReturn<TBase extends Constructor> = (new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> & SliderFormControlMixinInstance) & {
|
|
54
|
+
formAssociated: boolean;
|
|
55
|
+
observedAttributes: string[];
|
|
56
|
+
sliderDefaults: SliderFormControlDefaults;
|
|
57
|
+
} & Omit<TBase, 'prototype'>;
|
|
58
|
+
/**
|
|
59
|
+
* @description A mixin that adds native range input-style form control behavior.
|
|
60
|
+
*/
|
|
61
|
+
export declare function SliderFormControlMixin<TBase extends Constructor>(SuperClass: TBase): SliderFormControlMixinReturn<TBase>;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { toggleState as e } from "../internal/utils.js";
|
|
2
|
+
import { FormControlMixin as t } from "./control.js";
|
|
3
|
+
//#region src/mixins/slider.ts
|
|
4
|
+
var n = /* @__PURE__ */ new WeakMap(), r = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
function o(o) {
|
|
6
|
+
let u = t(o);
|
|
7
|
+
return class extends u {
|
|
8
|
+
#e = "";
|
|
9
|
+
#t;
|
|
10
|
+
static {
|
|
11
|
+
this.sliderDefaults = {};
|
|
12
|
+
}
|
|
13
|
+
static get observedAttributes() {
|
|
14
|
+
return super.observedAttributes;
|
|
15
|
+
}
|
|
16
|
+
get max() {
|
|
17
|
+
return n.get(this) ?? l(this).max ?? 100;
|
|
18
|
+
}
|
|
19
|
+
set max(e) {
|
|
20
|
+
this.#a(e, !0);
|
|
21
|
+
}
|
|
22
|
+
get min() {
|
|
23
|
+
return r.get(this) ?? l(this).min ?? 0;
|
|
24
|
+
}
|
|
25
|
+
set min(e) {
|
|
26
|
+
this.#i(e, !0);
|
|
27
|
+
}
|
|
28
|
+
get step() {
|
|
29
|
+
return a.get(this) ?? l(this).step ?? 1;
|
|
30
|
+
}
|
|
31
|
+
set step(e) {
|
|
32
|
+
this.#o(e, !0);
|
|
33
|
+
}
|
|
34
|
+
get type() {
|
|
35
|
+
return "range";
|
|
36
|
+
}
|
|
37
|
+
set type(e) {}
|
|
38
|
+
get value() {
|
|
39
|
+
return i.get(this) ?? l(this).value ?? 0;
|
|
40
|
+
}
|
|
41
|
+
set value(e) {
|
|
42
|
+
this.#r(c(e, this.#d)), this.setAttribute("value", `${this.value}`);
|
|
43
|
+
}
|
|
44
|
+
get valueAsNumber() {
|
|
45
|
+
return this.value;
|
|
46
|
+
}
|
|
47
|
+
set valueAsNumber(e) {
|
|
48
|
+
this.#r(e), Number.isFinite(e) && this.setAttribute("value", `${this.value}`);
|
|
49
|
+
}
|
|
50
|
+
connectedCallback() {
|
|
51
|
+
super.connectedCallback(), this.#t ??= this.value, this.updateSliderState();
|
|
52
|
+
}
|
|
53
|
+
attributeChangedCallback(e, t, n) {
|
|
54
|
+
t !== n && (this.#n(e, n) || super.attributeChangedCallback?.(e, t, n));
|
|
55
|
+
}
|
|
56
|
+
formResetCallback() {
|
|
57
|
+
this.valueAsNumber = this.#t ?? this.min, this.updateSliderState();
|
|
58
|
+
}
|
|
59
|
+
formStateRestoreCallback(e, t) {
|
|
60
|
+
this.valueAsNumber = e === null ? this.#t ?? this.min : c(e, this.min), this.updateSliderState();
|
|
61
|
+
}
|
|
62
|
+
reportValidity() {
|
|
63
|
+
return this.updateSliderState(), this._internals.reportValidity();
|
|
64
|
+
}
|
|
65
|
+
checkValidity() {
|
|
66
|
+
return this.updateSliderState(), this._internals.checkValidity();
|
|
67
|
+
}
|
|
68
|
+
setCustomValidity(e) {
|
|
69
|
+
this.#e = e, this.updateSliderState();
|
|
70
|
+
}
|
|
71
|
+
_updateFormState() {
|
|
72
|
+
this.updateSliderState();
|
|
73
|
+
}
|
|
74
|
+
updateSliderState() {
|
|
75
|
+
this._internals.setFormValue(!this.disabled && Number.isFinite(this.value) ? `${this.value}` : null), this._internals.ariaValueMax = `${this.max}`, this._internals.ariaValueMin = `${this.min}`, this._internals.ariaValueNow = Number.isFinite(this.value) ? `${this.value}` : null, e(this._internals, "max", !0), e(this._internals, "min", !0), e(this._internals, "step", !0), this.#f();
|
|
76
|
+
}
|
|
77
|
+
#n(e, t) {
|
|
78
|
+
return e === "value" ? (this.#r(c(t, this.#d)), !0) : e === "min" ? (this.#i(t, !1), !0) : e === "max" ? (this.#a(t, !1), !0) : e === "step" ? (this.#o(t, !1), !0) : !1;
|
|
79
|
+
}
|
|
80
|
+
#r(e) {
|
|
81
|
+
let t = this.value;
|
|
82
|
+
Object.is(t, e) || (i.set(this, e), this.updateSliderState(), this.requestUpdate?.("value", t));
|
|
83
|
+
}
|
|
84
|
+
#i(e, t) {
|
|
85
|
+
let n = this.min, i = c(e, this.#l);
|
|
86
|
+
Object.is(n, i) || (r.set(this, i), this.#s({
|
|
87
|
+
name: "min",
|
|
88
|
+
nextValue: i,
|
|
89
|
+
reflect: t,
|
|
90
|
+
value: e
|
|
91
|
+
}), this.updateSliderState(), this.requestUpdate?.("min", n));
|
|
92
|
+
}
|
|
93
|
+
#a(e, t) {
|
|
94
|
+
let r = this.max, i = c(e, this.#c);
|
|
95
|
+
Object.is(r, i) || (n.set(this, i), this.#s({
|
|
96
|
+
name: "max",
|
|
97
|
+
nextValue: i,
|
|
98
|
+
reflect: t,
|
|
99
|
+
value: e
|
|
100
|
+
}), this.updateSliderState(), this.requestUpdate?.("max", r));
|
|
101
|
+
}
|
|
102
|
+
#o(e, t) {
|
|
103
|
+
let n = this.step, r = c(e, this.#u);
|
|
104
|
+
Object.is(n, r) || (a.set(this, r), this.#s({
|
|
105
|
+
name: "step",
|
|
106
|
+
nextValue: r,
|
|
107
|
+
reflect: t,
|
|
108
|
+
value: e
|
|
109
|
+
}), this.updateSliderState(), this.requestUpdate?.("step", n));
|
|
110
|
+
}
|
|
111
|
+
#s({ name: e, nextValue: t, reflect: n, value: r }) {
|
|
112
|
+
n && (r === null ? this.removeAttribute(e) : this.setAttribute(e, `${t}`));
|
|
113
|
+
}
|
|
114
|
+
get #c() {
|
|
115
|
+
return l(this).max ?? 100;
|
|
116
|
+
}
|
|
117
|
+
get #l() {
|
|
118
|
+
return l(this).min ?? 0;
|
|
119
|
+
}
|
|
120
|
+
get #u() {
|
|
121
|
+
return l(this).step ?? 1;
|
|
122
|
+
}
|
|
123
|
+
get #d() {
|
|
124
|
+
return l(this).value ?? 0;
|
|
125
|
+
}
|
|
126
|
+
#f() {
|
|
127
|
+
if (this.noValidate) {
|
|
128
|
+
this.setValidity({});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (this.#e) {
|
|
132
|
+
this.setValidity({ customError: !0 }, this.#e);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
let e = s({
|
|
136
|
+
max: this.max,
|
|
137
|
+
min: this.min,
|
|
138
|
+
step: this.step,
|
|
139
|
+
value: this.value
|
|
140
|
+
});
|
|
141
|
+
this.setValidity(e.validity, e.message);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function s({ max: e, min: t, step: n, value: r }) {
|
|
146
|
+
return Number.isFinite(r) ? r < t ? d({ rangeUnderflow: !0 }, `Value must be greater than or equal to ${t}.`) : r > e ? d({ rangeOverflow: !0 }, `Value must be less than or equal to ${e}.`) : u(r, t, n) ? d({ stepMismatch: !0 }, `Value must match the step ${n}.`) : {
|
|
147
|
+
validity: {},
|
|
148
|
+
message: ""
|
|
149
|
+
} : d({ valueMissing: !0 }, "Enter a value.");
|
|
150
|
+
}
|
|
151
|
+
function c(e, t) {
|
|
152
|
+
let n = typeof e == "number" ? e : Number(e ?? t);
|
|
153
|
+
return Number.isNaN(n) ? t : n;
|
|
154
|
+
}
|
|
155
|
+
function l(e) {
|
|
156
|
+
return e.constructor.sliderDefaults ?? {};
|
|
157
|
+
}
|
|
158
|
+
function u(e, t, n) {
|
|
159
|
+
if (!Number.isFinite(n) || n <= 0 || !Number.isFinite(e)) return !1;
|
|
160
|
+
let r = (e - t) / n;
|
|
161
|
+
return Math.abs(r - Math.round(r)) > 2 ** -52 * 100;
|
|
162
|
+
}
|
|
163
|
+
function d(e, t) {
|
|
164
|
+
return {
|
|
165
|
+
validity: {
|
|
166
|
+
...e,
|
|
167
|
+
valid: !1
|
|
168
|
+
},
|
|
169
|
+
message: t
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
export { o as SliderFormControlMixin };
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=slider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slider.js","names":["#setMax","#setMin","#setStep","#setValue","#defaultValue","#initialValue","#handleSliderAttributeChange","#customValidityMessage","#updateValidity","#defaultMin","#reflectNumberAttribute","#defaultMax","#defaultStep"],"sources":["../../src/mixins/slider.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { FormControlValue, ValidatorResult } from '../internal/types.js';\nimport { toggleState } from '../internal/utils.js';\nimport { FormControlMixin, type FormControlMixinInstance } from './index.js';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor = (new (...args: any[]) => HTMLElement & {\n connectedCallback?(): void;\n attributeChangedCallback?(name: string, oldValue: string | null, newValue: string | null): void;\n requestUpdate?(name?: string, oldValue?: unknown): void;\n}) & {\n observedAttributes?: string[];\n};\n\nexport type SliderFormControlValue = Extract<FormControlValue, number>;\n\nexport interface SliderFormControlMixinInstance extends FormControlMixinInstance<SliderFormControlValue> {\n /**\n * Defines the maximum slider value.\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range#max\n * @attr max\n * @reflect\n */\n max: number;\n\n /**\n * Defines the minimum slider value.\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range#min\n * @attr min\n * @reflect\n */\n min: number;\n\n /**\n * Defines the slider value granularity.\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range#step\n * @attr step\n * @reflect\n */\n step: number;\n\n /**\n * The current slider value.\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range#value\n * @attr value\n * @reflect\n */\n value: number;\n\n /**\n * The current slider value as a number.\n * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/valueAsNumber\n */\n valueAsNumber: number;\n\n updateSliderState(): void;\n}\n\nexport interface SliderFormControlDefaults {\n max?: number;\n min?: number;\n step?: number;\n value?: number;\n}\n\nexport type SliderFormControlMixinReturn<TBase extends Constructor> = (new (\n ...args: ConstructorParameters<TBase>\n) => InstanceType<TBase> & SliderFormControlMixinInstance) & {\n formAssociated: boolean;\n observedAttributes: string[];\n sliderDefaults: SliderFormControlDefaults;\n} & Omit<TBase, 'prototype'>;\n\ninterface SliderBaseInstance extends HTMLElement, FormControlMixinInstance<SliderFormControlValue> {\n connectedCallback(): void;\n attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;\n requestUpdate?(name?: string, oldValue?: unknown): void;\n}\n\ntype SliderBaseConstructor<TBase extends Constructor> = (new (\n ...args: ConstructorParameters<TBase>\n) => SliderBaseInstance) & {\n formAssociated: boolean;\n observedAttributes: string[];\n};\n\nconst maxValues = new WeakMap<object, number>();\nconst minValues = new WeakMap<object, number>();\nconst sliderValues = new WeakMap<object, number>();\nconst stepValues = new WeakMap<object, number>();\n\n/**\n * @description A mixin that adds native range input-style form control behavior.\n */\nexport function SliderFormControlMixin<TBase extends Constructor>(\n SuperClass: TBase\n): SliderFormControlMixinReturn<TBase> {\n const Base = FormControlMixin<TBase, SliderFormControlValue>(SuperClass) as SliderBaseConstructor<TBase>;\n\n return class SliderFormControlBase extends Base {\n #customValidityMessage = '';\n\n #initialValue: number | undefined;\n\n static readonly sliderDefaults: SliderFormControlDefaults = {};\n\n static get observedAttributes() {\n return super.observedAttributes;\n }\n\n override get max(): number {\n return maxValues.get(this) ?? getSliderDefaults(this).max ?? 100;\n }\n\n override set max(value: number | null) {\n this.#setMax(value, true);\n }\n\n override get min(): number {\n return minValues.get(this) ?? getSliderDefaults(this).min ?? 0;\n }\n\n override set min(value: number | null) {\n this.#setMin(value, true);\n }\n\n override get step(): number {\n return stepValues.get(this) ?? getSliderDefaults(this).step ?? 1;\n }\n\n override set step(value: number | null) {\n this.#setStep(value, true);\n }\n\n override get type(): string {\n return 'range';\n }\n\n override set type(_value: string) {}\n\n override get value(): number {\n return sliderValues.get(this) ?? getSliderDefaults(this).value ?? 0;\n }\n\n override set value(value: number | string) {\n this.#setValue(getNumberValue(value, this.#defaultValue));\n this.setAttribute('value', `${this.value}`);\n }\n\n override get valueAsNumber(): number {\n return this.value;\n }\n\n override set valueAsNumber(value: number) {\n this.#setValue(value);\n if (Number.isFinite(value)) {\n this.setAttribute('value', `${this.value}`);\n }\n }\n\n override connectedCallback() {\n super.connectedCallback();\n this.#initialValue ??= this.value;\n this.updateSliderState();\n }\n\n override attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {\n if (oldValue === newValue) {\n return;\n }\n\n if (this.#handleSliderAttributeChange(name, newValue)) {\n return;\n }\n\n super.attributeChangedCallback?.(name, oldValue, newValue);\n }\n\n override formResetCallback() {\n this.valueAsNumber = this.#initialValue ?? this.min;\n this.updateSliderState();\n }\n\n override formStateRestoreCallback(state: number | string | null, _reason?: string) {\n this.valueAsNumber = state === null ? (this.#initialValue ?? this.min) : getNumberValue(state, this.min);\n this.updateSliderState();\n }\n\n override reportValidity() {\n this.updateSliderState();\n return this._internals.reportValidity();\n }\n\n override checkValidity() {\n this.updateSliderState();\n return this._internals.checkValidity();\n }\n\n override setCustomValidity(message: string) {\n this.#customValidityMessage = message;\n this.updateSliderState();\n }\n\n override _updateFormState() {\n this.updateSliderState();\n }\n\n updateSliderState() {\n this._internals.setFormValue(!this.disabled && Number.isFinite(this.value) ? `${this.value}` : null);\n this._internals.ariaValueMax = `${this.max}`;\n this._internals.ariaValueMin = `${this.min}`;\n this._internals.ariaValueNow = Number.isFinite(this.value) ? `${this.value}` : null;\n toggleState(this._internals, 'max', true);\n toggleState(this._internals, 'min', true);\n toggleState(this._internals, 'step', true);\n this.#updateValidity();\n }\n\n #handleSliderAttributeChange(name: string, newValue: string | null) {\n if (name === 'value') {\n this.#setValue(getNumberValue(newValue, this.#defaultValue));\n return true;\n }\n\n if (name === 'min') {\n this.#setMin(newValue, false);\n return true;\n }\n\n if (name === 'max') {\n this.#setMax(newValue, false);\n return true;\n }\n\n if (name === 'step') {\n this.#setStep(newValue, false);\n return true;\n }\n\n return false;\n }\n\n #setValue(value: number) {\n const previousValue = this.value;\n if (Object.is(previousValue, value)) {\n return;\n }\n\n sliderValues.set(this, value);\n this.updateSliderState();\n this.requestUpdate?.('value', previousValue);\n }\n\n #setMin(value: number | string | null, reflect: boolean) {\n const previousValue = this.min;\n const nextValue = getNumberValue(value, this.#defaultMin);\n if (Object.is(previousValue, nextValue)) {\n return;\n }\n\n minValues.set(this, nextValue);\n this.#reflectNumberAttribute({ name: 'min', nextValue, reflect, value });\n this.updateSliderState();\n this.requestUpdate?.('min', previousValue);\n }\n\n #setMax(value: number | string | null, reflect: boolean) {\n const previousValue = this.max;\n const nextValue = getNumberValue(value, this.#defaultMax);\n if (Object.is(previousValue, nextValue)) {\n return;\n }\n\n maxValues.set(this, nextValue);\n this.#reflectNumberAttribute({ name: 'max', nextValue, reflect, value });\n this.updateSliderState();\n this.requestUpdate?.('max', previousValue);\n }\n\n #setStep(value: number | string | null, reflect: boolean) {\n const previousValue = this.step;\n const nextValue = getNumberValue(value, this.#defaultStep);\n if (Object.is(previousValue, nextValue)) {\n return;\n }\n\n stepValues.set(this, nextValue);\n this.#reflectNumberAttribute({ name: 'step', nextValue, reflect, value });\n this.updateSliderState();\n this.requestUpdate?.('step', previousValue);\n }\n\n #reflectNumberAttribute({ name, nextValue, reflect, value }: ReflectNumberAttributeOptions) {\n if (!reflect) {\n return;\n }\n\n if (value === null) {\n this.removeAttribute(name);\n } else {\n this.setAttribute(name, `${nextValue}`);\n }\n }\n\n get #defaultMax() {\n return getSliderDefaults(this).max ?? 100;\n }\n\n get #defaultMin() {\n return getSliderDefaults(this).min ?? 0;\n }\n\n get #defaultStep() {\n return getSliderDefaults(this).step ?? 1;\n }\n\n get #defaultValue() {\n return getSliderDefaults(this).value ?? 0;\n }\n\n #updateValidity() {\n if (this.noValidate) {\n this.setValidity({});\n return;\n }\n\n if (this.#customValidityMessage) {\n this.setValidity({ customError: true }, this.#customValidityMessage);\n return;\n }\n\n const result = getSliderValidity({\n max: this.max,\n min: this.min,\n step: this.step,\n value: this.value\n });\n this.setValidity(result.validity, result.message);\n }\n } as unknown as SliderFormControlMixinReturn<TBase>;\n}\n\ninterface SliderValidityOptions {\n max: number;\n min: number;\n step: number;\n value: number;\n}\n\ninterface ReflectNumberAttributeOptions {\n name: string;\n nextValue: number;\n reflect: boolean;\n value: number | string | null;\n}\n\nfunction getSliderValidity({ max, min, step, value }: SliderValidityOptions): ValidatorResult {\n if (!Number.isFinite(value)) {\n return invalid({ valueMissing: true }, 'Enter a value.');\n }\n\n if (value < min) {\n return invalid({ rangeUnderflow: true }, `Value must be greater than or equal to ${min}.`);\n }\n\n if (value > max) {\n return invalid({ rangeOverflow: true }, `Value must be less than or equal to ${max}.`);\n }\n\n if (hasStepMismatch(value, min, step)) {\n return invalid({ stepMismatch: true }, `Value must match the step ${step}.`);\n }\n\n return { validity: {}, message: '' };\n}\n\nfunction getNumberValue(value: number | string | null, fallback: number) {\n const parsedValue = typeof value === 'number' ? value : Number(value ?? fallback);\n return Number.isNaN(parsedValue) ? fallback : parsedValue;\n}\n\nfunction getSliderDefaults(element: object): SliderFormControlDefaults {\n return (element.constructor as { sliderDefaults?: SliderFormControlDefaults }).sliderDefaults ?? {};\n}\n\nfunction hasStepMismatch(value: number, min: number, step: number) {\n if (!Number.isFinite(step) || step <= 0 || !Number.isFinite(value)) {\n return false;\n }\n\n const steps = (value - min) / step;\n return Math.abs(steps - Math.round(steps)) > Number.EPSILON * 100;\n}\n\nfunction invalid(validity: Partial<ValidityState>, message: string): ValidatorResult {\n return { validity: { ...validity, valid: false }, message };\n}\n"],"mappings":";;;AAwFA,IAAM,oBAAY,IAAI,QAAwB,GACxC,oBAAY,IAAI,QAAwB,GACxC,oBAAe,IAAI,QAAwB,GAC3C,oBAAa,IAAI,QAAwB;AAK/C,SAAgB,EACd,GACqC;CACrC,IAAM,IAAO,EAAgD,CAAU;CAEvE,OAAO,cAAoC,EAAK;EAC9C,KAAyB;EAEzB;;yBAE4D,CAAC;;EAE7D,WAAW,qBAAqB;GAC9B,OAAO,MAAM;EACf;EAEA,IAAa,MAAc;GACzB,OAAO,EAAU,IAAI,IAAI,KAAK,EAAkB,IAAI,EAAE,OAAO;EAC/D;EAEA,IAAa,IAAI,GAAsB;GACrC,KAAKA,GAAQ,GAAO,EAAI;EAC1B;EAEA,IAAa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right (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { validateSchema } from '../internal/schema.js';\nimport type { FormControl, ValidatorResult } from '../internal/types.js';\n\n/**\n * Given a json schema, check the value against the schema\n * JSON Schema follows the OpenAI JSON Schema for structured outputs\n * https://platform.openai.com/docs/guides/structured-outputs\n *\n * - All fields or function parameters must specify required\n * - Require additionalProperties: false on all objects\n * - Structured Outputs support the following types:\n * - String\n * - Number\n * - Boolean\n * - Object\n * - Array\n * - Enum\n */\nexport function valueSchemaValidator(value: unknown, element: FormControl): ValidatorResult {\n const metadata = (element as any).constructor.metadata; // eslint-disable-line @typescript-eslint/no-explicit-any\n return validateSchema(metadata.valueSchema, value);\n}\n\nexport function requiredValidator(value: unknown, element: FormControl): ValidatorResult {\n if (\n (element as unknown as { required: boolean }).required &&\n (value === undefined || value === null || value === '')\n ) {\n return { validity: { valueMissing: true, valid: false }, message: 'This field is required' };\n }\n return { validity: { valid: true }, message: '' };\n}\n"],"mappings":";;AAqBA,SAAgB,EAAqB,GAAgB,GAAuC;CAC1F,IAAM,IAAY,EAAgB,YAAY;CAC9C,OAAO,EAAe,EAAS,aAAa,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/validators/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { validateSchema } from '../internal/schema.js';\nimport type { FormControl, ValidatorResult } from '../internal/types.js';\n\n/**\n * Given a json schema, check the value against the schema\n * JSON Schema follows the OpenAI JSON Schema for structured outputs\n * https://platform.openai.com/docs/guides/structured-outputs\n *\n * - All fields or function parameters must specify required\n * - Require additionalProperties: false on all objects\n * - Structured Outputs support the following types:\n * - String\n * - Number\n * - Boolean\n * - Object\n * - Array\n * - Enum\n */\nexport function valueSchemaValidator(value: unknown, element: FormControl): ValidatorResult {\n const metadata = (element as any).constructor.metadata; // eslint-disable-line @typescript-eslint/no-explicit-any\n return validateSchema(metadata.valueSchema, value);\n}\n\nexport function requiredValidator(value: unknown, element: FormControl): ValidatorResult {\n if (\n (element as unknown as { required: boolean }).required &&\n (value === undefined || value === null || value === '')\n ) {\n return { validity: { valueMissing: true, valid: false }, message: 'This field is required' };\n }\n return { validity: { valid: true }, message: '' };\n}\n"],"mappings":";;AAqBA,SAAgB,EAAqB,GAAgB,GAAuC;CAC1F,IAAM,IAAY,EAAgB,YAAY;CAC9C,OAAO,EAAe,EAAS,aAAa,CAAK;AACnD;AAEA,SAAgB,EAAkB,GAAgB,GAAuC;CAOvF,OALG,EAA6C,aAC7C,KAAiC,QAAQ,MAAU,MAE7C;EAAE,UAAU;GAAE,cAAc;GAAM,OAAO;EAAM;EAAG,SAAS;CAAyB,IAEtF;EAAE,UAAU,EAAE,OAAO,GAAK;EAAG,SAAS;CAAG;AAClD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nvidia-elements/forms",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"release": {
|
|
5
5
|
"extends": "../../release.config.js"
|
|
6
6
|
},
|
|
@@ -51,12 +51,20 @@
|
|
|
51
51
|
"default": "./dist/index.js"
|
|
52
52
|
},
|
|
53
53
|
"./mixin": {
|
|
54
|
-
"types": "./dist/
|
|
55
|
-
"default": "./dist/
|
|
54
|
+
"types": "./dist/mixins/index.d.ts",
|
|
55
|
+
"default": "./dist/mixins/index.js"
|
|
56
56
|
},
|
|
57
57
|
"./mixin/index.js": {
|
|
58
|
-
"types": "./dist/
|
|
59
|
-
"default": "./dist/
|
|
58
|
+
"types": "./dist/mixins/index.d.ts",
|
|
59
|
+
"default": "./dist/mixins/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./mixins": {
|
|
62
|
+
"types": "./dist/mixins/index.d.ts",
|
|
63
|
+
"default": "./dist/mixins/index.js"
|
|
64
|
+
},
|
|
65
|
+
"./mixins/index.js": {
|
|
66
|
+
"types": "./dist/mixins/index.d.ts",
|
|
67
|
+
"default": "./dist/mixins/index.js"
|
|
60
68
|
},
|
|
61
69
|
"./validators": {
|
|
62
70
|
"types": "./dist/validators/index.d.ts",
|
|
@@ -68,25 +76,23 @@
|
|
|
68
76
|
}
|
|
69
77
|
},
|
|
70
78
|
"sideEffects": [],
|
|
71
|
-
"dependencies": {
|
|
72
|
-
"lit": "^3.3.2"
|
|
73
|
-
},
|
|
74
79
|
"devDependencies": {
|
|
75
80
|
"@eslint/js": "10.0.1",
|
|
76
|
-
"@
|
|
77
|
-
"@vitest/
|
|
81
|
+
"@typescript/lib-dom": "npm:@types/web@0.0.312",
|
|
82
|
+
"@vitest/browser": "4.1.7",
|
|
83
|
+
"@vitest/coverage-istanbul": "4.1.7",
|
|
78
84
|
"axe-core": "4.11.0",
|
|
79
|
-
"eslint": "10.
|
|
80
|
-
"lit": "3.3.
|
|
81
|
-
"publint": "0.3.
|
|
85
|
+
"eslint": "10.4.0",
|
|
86
|
+
"lit": "3.3.3",
|
|
87
|
+
"publint": "0.3.21",
|
|
82
88
|
"typescript": "6.0.3",
|
|
83
|
-
"vite": "8.0.
|
|
84
|
-
"vitest": "4.1.
|
|
85
|
-
"@nvidia-elements/styles": "0.0.8",
|
|
86
|
-
"@internals/testing": "0.0.0",
|
|
89
|
+
"vite": "8.0.14",
|
|
90
|
+
"vitest": "4.1.7",
|
|
87
91
|
"@internals/eslint": "0.0.0",
|
|
88
|
-
"@
|
|
89
|
-
"@internals/
|
|
92
|
+
"@internals/vite": "0.0.0",
|
|
93
|
+
"@internals/testing": "0.0.0",
|
|
94
|
+
"@nvidia-elements/styles": "0.0.10",
|
|
95
|
+
"@nvidia-elements/lint": "0.4.0"
|
|
90
96
|
},
|
|
91
97
|
"wireit": {
|
|
92
98
|
"dev": {
|