@nvidia-elements/forms 2.0.5 → 2.0.6
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
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
+
## <small>2.0.6 (2026-08-07)</small>
|
|
2
|
+
|
|
3
|
+
* chore(ci): add github dependabot skill ([4cb37a7](https://github.com/NVIDIA/elements/commit/4cb37a7))
|
|
4
|
+
* chore(ci): enhance ci performance profiling and add new scripts ([ef0a912](https://github.com/NVIDIA/elements/commit/ef0a912))
|
|
5
|
+
* chore(ci): update dependencies ([4601239](https://github.com/NVIDIA/elements/commit/4601239))
|
|
6
|
+
* chore(ci): update hugo starter to use mise defined binary ([29211a7](https://github.com/NVIDIA/elements/commit/29211a7))
|
|
7
|
+
* chore(ci): update lighthouse ([73584d2](https://github.com/NVIDIA/elements/commit/73584d2))
|
|
8
|
+
* chore(ci): update metadata ([b7120bf](https://github.com/NVIDIA/elements/commit/b7120bf))
|
|
9
|
+
* chore(ci): update metadata and test coverage report ([216a7a9](https://github.com/NVIDIA/elements/commit/216a7a9))
|
|
10
|
+
* chore(docs): add component preview to card list ([c7e16a5](https://github.com/NVIDIA/elements/commit/c7e16a5))
|
|
11
|
+
* chore(docs): add design md file ([5c63566](https://github.com/NVIDIA/elements/commit/5c63566))
|
|
12
|
+
* chore(docs): feed title ([e7f3717](https://github.com/NVIDIA/elements/commit/e7f3717))
|
|
13
|
+
* chore(docs): fix sitemap ([7c9f059](https://github.com/NVIDIA/elements/commit/7c9f059))
|
|
14
|
+
* chore(docs): july update ([59d3f83](https://github.com/NVIDIA/elements/commit/59d3f83))
|
|
15
|
+
* chore(docs): whats new page and skill ([9c6f1b2](https://github.com/NVIDIA/elements/commit/9c6f1b2))
|
|
16
|
+
* chore(release): @nvidia-elements/cli-v2.1.7 [skip ci] ([3fcca0d](https://github.com/NVIDIA/elements/commit/3fcca0d))
|
|
17
|
+
* chore(release): @nvidia-elements/cli-v2.1.8 [skip ci] ([1521595](https://github.com/NVIDIA/elements/commit/1521595))
|
|
18
|
+
* chore(release): @nvidia-elements/cli-v2.1.9 [skip ci] ([651abf3](https://github.com/NVIDIA/elements/commit/651abf3))
|
|
19
|
+
* chore(release): @nvidia-elements/core-v2.2.0 [skip ci] ([6cf3292](https://github.com/NVIDIA/elements/commit/6cf3292))
|
|
20
|
+
* chore(release): @nvidia-elements/core-v2.2.1 [skip ci] ([730a2ec](https://github.com/NVIDIA/elements/commit/730a2ec))
|
|
21
|
+
* chore(release): @nvidia-elements/core-v2.2.2 [skip ci] ([f9f1e27](https://github.com/NVIDIA/elements/commit/f9f1e27))
|
|
22
|
+
* chore(release): @nvidia-elements/core-v2.2.3 [skip ci] ([0b24dcc](https://github.com/NVIDIA/elements/commit/0b24dcc))
|
|
23
|
+
* chore(release): @nvidia-elements/lint-v2.2.0 [skip ci] ([0a6b54e](https://github.com/NVIDIA/elements/commit/0a6b54e))
|
|
24
|
+
* chore(release): @nvidia-elements/lint-v2.3.0 [skip ci] ([35bb729](https://github.com/NVIDIA/elements/commit/35bb729))
|
|
25
|
+
* chore(release): @nvidia-elements/markdown-v2.0.3 [skip ci] ([287e6c3](https://github.com/NVIDIA/elements/commit/287e6c3))
|
|
26
|
+
* chore(release): @nvidia-elements/styles-v2.1.1 [skip ci] ([d6ce1a6](https://github.com/NVIDIA/elements/commit/d6ce1a6))
|
|
27
|
+
* chore(release): @nvidia-elements/styles-v2.1.2 [skip ci] ([71fab6c](https://github.com/NVIDIA/elements/commit/71fab6c))
|
|
28
|
+
* feat(core): add media i18n values ([371692a](https://github.com/NVIDIA/elements/commit/371692a))
|
|
29
|
+
* feat(lint): add rule to limit excessive primary actions ([e67fa69](https://github.com/NVIDIA/elements/commit/e67fa69))
|
|
30
|
+
* feat(lint): add rule to restrict container="full" usage ([a634e39](https://github.com/NVIDIA/elements/commit/a634e39))
|
|
31
|
+
* feat(media): init ([859c8f9](https://github.com/NVIDIA/elements/commit/859c8f9))
|
|
32
|
+
* fix(cli): update mcp deps ([a7d5f7c](https://github.com/NVIDIA/elements/commit/a7d5f7c))
|
|
33
|
+
* fix(cli): update mcp sdk ([0640e11](https://github.com/NVIDIA/elements/commit/0640e11))
|
|
34
|
+
* fix(cli): workspace dependency ([5ecbd96](https://github.com/NVIDIA/elements/commit/5ecbd96))
|
|
35
|
+
* fix(core): drawer positioning ([f66cab0](https://github.com/NVIDIA/elements/commit/f66cab0))
|
|
36
|
+
* fix(core): improve api custom elements schema ([6b299e3](https://github.com/NVIDIA/elements/commit/6b299e3))
|
|
37
|
+
* fix(core): size height calculation ([204aa52](https://github.com/NVIDIA/elements/commit/204aa52))
|
|
38
|
+
* fix(core): update fit-text input to native field sizing ([cadc33c](https://github.com/NVIDIA/elements/commit/cadc33c))
|
|
39
|
+
* fix(core): update select size handling and improve layout ([6af535d](https://github.com/NVIDIA/elements/commit/6af535d))
|
|
40
|
+
* fix(forms): respect event default prevention ([5618862](https://github.com/NVIDIA/elements/commit/5618862))
|
|
41
|
+
* fix(styles): add width rule for row layout with space-between alignment ([61113ad](https://github.com/NVIDIA/elements/commit/61113ad))
|
|
42
|
+
* fix(styles): default line heights ([d13ea94](https://github.com/NVIDIA/elements/commit/d13ea94))
|
|
43
|
+
|
|
1
44
|
## <small>2.0.5 (2026-07-22)</small>
|
|
2
45
|
|
|
3
46
|
* chore(ci): disable no-missing-gap-space rule for specific test files ([47ae4ff](https://github.com/NVIDIA/elements/commit/47ae4ff))
|
package/dist/index.js
CHANGED
|
@@ -17,15 +17,15 @@ export interface ButtonFormControlMixinInstance {
|
|
|
17
17
|
*/
|
|
18
18
|
expanded: boolean;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Indicates whether the element is a noninteractive visual treatment instead of a button.
|
|
21
21
|
* https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly
|
|
22
22
|
* @attr readonly
|
|
23
23
|
* @reflect
|
|
24
24
|
*/
|
|
25
25
|
readOnly: boolean;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
27
|
+
* Associates the button with a form. Set the property to a form element or its ID. The HTML attribute accepts only
|
|
28
|
+
* the form ID. Reading the property returns the associated form element or `null`.
|
|
29
29
|
* https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/form
|
|
30
30
|
* @attr form
|
|
31
31
|
*/
|
|
@@ -28,7 +28,7 @@ export interface CheckboxFormControlMixinInstance extends FormControlMixinInstan
|
|
|
28
28
|
/**
|
|
29
29
|
* Toggles the checked state.
|
|
30
30
|
*/
|
|
31
|
-
toggle(): void;
|
|
31
|
+
toggle(event?: Event): void;
|
|
32
32
|
}
|
|
33
33
|
export type CheckboxFormControlMixinReturn<TBase extends Constructor> = (new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> & CheckboxFormControlMixinInstance) & {
|
|
34
34
|
formAssociated: boolean;
|
package/dist/mixins/checkbox.js
CHANGED
|
@@ -77,8 +77,8 @@ function i(i) {
|
|
|
77
77
|
updateCheckedState() {
|
|
78
78
|
this._internals.setFormValue(this.name && this.checked && !this.disabled ? this.value : null), e(this._internals, "checked", this.checked), e(this._internals, "indeterminate", this.indeterminate), this.checkValidity();
|
|
79
79
|
}
|
|
80
|
-
toggle() {
|
|
81
|
-
this.disabled || this.readOnly || (this.checked = !this.checked, this.indeterminate = !1, this.dispatchInputEvent(), this.dispatchChangeEvent());
|
|
80
|
+
toggle(e) {
|
|
81
|
+
this.disabled || this.readOnly || e?.defaultPrevented || (this.checked = !this.checked, this.indeterminate = !1, this.dispatchInputEvent(), this.dispatchChangeEvent());
|
|
82
82
|
}
|
|
83
83
|
#a() {
|
|
84
84
|
return this.noValidate ? (this.setValidity({}), !0) : this.#t ? (this.setValidity({ customError: !0 }, this.#t), !1) : this.required && !this.checked ? (this.setValidity({ valueMissing: !0 }, "Select this option"), !1) : super.checkValidity();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.js","names":["#checked","#setChecked","#reflectingChecked","#indeterminate","#setIndeterminate","#setValue","#initialChecked","#handleCheckboxAttributeChange","#checkCheckboxValidity","#customValidityMessage"],"sources":["../../src/mixins/checkbox.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 { 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 disconnectedCallback?(): 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 CheckboxFormControlValue = Extract<FormControlValue, string>;\n\nexport interface CheckboxFormControlMixinInstance extends FormControlMixinInstance<CheckboxFormControlValue> {\n /**\n * Shows whether the checkbox currently has a checked value.\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#checked\n * @attr checked\n * @reflect\n */\n checked: boolean;\n\n /**\n * Indicates whether the checkbox is visually indeterminate.\n * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/indeterminate\n * @attr indeterminate\n * @reflect\n */\n indeterminate: boolean;\n\n updateCheckedState(): void;\n\n /**\n * Toggles the checked state.\n */\n toggle(): void;\n}\n\nexport type CheckboxFormControlMixinReturn<TBase extends Constructor> = (new (\n ...args: ConstructorParameters<TBase>\n) => InstanceType<TBase> & CheckboxFormControlMixinInstance) & {\n formAssociated: boolean;\n observedAttributes: string[];\n} & Omit<TBase, 'prototype'>;\n\ninterface CheckboxBaseInstance extends HTMLElement, FormControlMixinInstance<CheckboxFormControlValue> {\n connectedCallback(): void;\n attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;\n requestUpdate?(name?: string, oldValue?: unknown): void;\n}\n\ntype CheckboxBaseConstructor<TBase extends Constructor> = (new (\n ...args: ConstructorParameters<TBase>\n) => CheckboxBaseInstance) & {\n formAssociated: boolean;\n observedAttributes: string[];\n};\n\nconst checkboxValues = new WeakMap<object, string>();\nconst constructedCheckboxes = new WeakSet();\n\n/**\n * @description A mixin that adds native checkbox-style form control behavior.\n */\nexport function CheckboxFormControlMixin<TBase extends Constructor>(\n SuperClass: TBase\n): CheckboxFormControlMixinReturn<TBase> {\n const Base = FormControlMixin<TBase, CheckboxFormControlValue>(SuperClass) as CheckboxBaseConstructor<TBase>;\n\n return class CheckboxFormControlBase extends Base {\n #checked = false;\n\n #customValidityMessage = '';\n\n #indeterminate = false;\n\n #initialChecked: boolean | undefined;\n\n #reflectingChecked = false;\n\n constructor(...args: ConstructorParameters<TBase>) {\n super(...args);\n constructedCheckboxes.add(this);\n }\n\n static get observedAttributes() {\n return super.observedAttributes.concat(['checked', 'indeterminate']);\n }\n\n get checked(): boolean {\n return this.#checked;\n }\n\n set checked(value: boolean) {\n this.#setChecked(Boolean(value));\n this.#reflectingChecked = true;\n this.toggleAttribute('checked', this.#checked);\n this.#reflectingChecked = false;\n }\n\n override get disabled(): boolean {\n return super.disabled;\n }\n\n override set disabled(value: boolean) {\n super.disabled = Boolean(value);\n if (constructedCheckboxes.has(this)) {\n this.updateCheckedState();\n }\n }\n\n get indeterminate(): boolean {\n return this.#indeterminate;\n }\n\n set indeterminate(value: boolean) {\n this.#setIndeterminate(Boolean(value));\n this.toggleAttribute('indeterminate', this.#indeterminate);\n }\n\n override get type(): string {\n return 'checkbox';\n }\n\n override set type(_value: string) {}\n\n override get value(): CheckboxFormControlValue {\n return checkboxValues.get(this) ?? 'on';\n }\n\n override set value(value: CheckboxFormControlValue | number | boolean) {\n this.#setValue(getCheckboxValue(value));\n this.setAttribute('value', this.value);\n }\n\n override connectedCallback() {\n super.connectedCallback();\n this.#initialChecked ??= this.checked;\n this.updateCheckedState();\n }\n\n override attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {\n if (oldValue === newValue) {\n return;\n }\n\n if (this.#handleCheckboxAttributeChange(name, newValue)) {\n if (name === 'checked' && !this.#reflectingChecked) {\n this.#initialChecked = this.checked;\n }\n return;\n }\n\n super.attributeChangedCallback?.(name, oldValue, newValue);\n }\n\n override formResetCallback() {\n this.checked = this.#initialChecked ?? false;\n this.indeterminate = false;\n this.updateCheckedState();\n }\n\n override formStateRestoreCallback(state: string | null, _reason?: string) {\n this.checked = state !== null;\n this.updateCheckedState();\n }\n\n override reportValidity() {\n this.#checkCheckboxValidity();\n return this._internals.reportValidity();\n }\n\n override checkValidity() {\n return this.#checkCheckboxValidity();\n }\n\n override setCustomValidity(message: string) {\n this.#customValidityMessage = message;\n this.checkValidity();\n }\n\n override _updateFormState() {\n this.updateCheckedState();\n }\n\n updateCheckedState() {\n this._internals.setFormValue(this.name && this.checked && !this.disabled ? this.value : null);\n toggleState(this._internals, 'checked', this.checked);\n toggleState(this._internals, 'indeterminate', this.indeterminate);\n this.checkValidity();\n }\n\n toggle() {\n if (this.disabled || this.readOnly) {\n return;\n }\n\n this.checked = !this.checked;\n this.indeterminate = false;\n this.dispatchInputEvent();\n this.dispatchChangeEvent();\n }\n\n #checkCheckboxValidity() {\n if (this.noValidate) {\n this.setValidity({});\n return true;\n }\n\n if (this.#customValidityMessage) {\n this.setValidity({ customError: true }, this.#customValidityMessage);\n return false;\n }\n\n if (this.required && !this.checked) {\n this.setValidity({ valueMissing: true }, 'Select this option');\n return false;\n }\n\n return super.checkValidity();\n }\n\n #handleCheckboxAttributeChange(name: string, newValue: string | null) {\n if (name === 'checked') {\n this.#setChecked(newValue !== null);\n return true;\n }\n\n if (name === 'indeterminate') {\n this.#setIndeterminate(newValue !== null);\n return true;\n }\n\n if (name === 'value') {\n this.#setValue(newValue ?? 'on');\n return true;\n }\n\n return false;\n }\n\n #setChecked(checked: boolean) {\n const previousValue = this.#checked;\n this.#checked = checked;\n this.updateCheckedState();\n this.requestUpdate?.('checked', previousValue);\n }\n\n #setIndeterminate(indeterminate: boolean) {\n const previousValue = this.#indeterminate;\n this.#indeterminate = indeterminate;\n toggleState(this._internals, 'indeterminate', indeterminate);\n this.requestUpdate?.('indeterminate', previousValue);\n }\n\n #setValue(value: string) {\n const previousValue = this.value;\n checkboxValues.set(this, value);\n this.updateCheckedState();\n this.requestUpdate?.('value', previousValue);\n }\n } as unknown as CheckboxFormControlMixinReturn<TBase>;\n}\n\nfunction getCheckboxValue(value: unknown) {\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return `${value}`;\n }\n\n return 'on';\n}\n"],"mappings":";;;AAgEA,IAAM,oBAAiB,IAAI,QAAwB,GAC7C,oBAAwB,IAAI,QAAQ;AAK1C,SAAgB,EACd,GACuC;CACvC,IAAM,IAAO,EAAkD,CAAU;CAEzE,OAAO,cAAsC,EAAK;EAChD,KAAW;EAEX,KAAyB;EAEzB,KAAiB;EAEjB;EAEA,KAAqB;EAErB,YAAY,GAAG,GAAoC;GAEjD,AADA,MAAM,GAAG,CAAI,GACb,EAAsB,IAAI,IAAI;EAChC;EAEA,WAAW,qBAAqB;GAC9B,OAAO,MAAM,mBAAmB,OAAO,CAAC,WAAW,eAAe,CAAC;EACrE;EAEA,IAAI,UAAmB;GACrB,OAAO,KAAKA;EACd;EAEA,IAAI,QAAQ,GAAgB;GAI1B,AAHA,KAAKC,GAAY,EAAQ,CAAM,GAC/B,KAAKC,KAAqB,IAC1B,KAAK,gBAAgB,WAAW,KAAKF,EAAQ,GAC7C,KAAKE,KAAqB;EAC5B;EAEA,IAAa,WAAoB;GAC/B,OAAO,MAAM;EACf;EAEA,IAAa,SAAS,GAAgB;GAEpC,AADA,MAAM,WAAW,EAAQ,GACrB,EAAsB,IAAI,IAAI,KAChC,KAAK,mBAAmB;EAE5B;EAEA,IAAI,gBAAyB;GAC3B,OAAO,KAAKC;EACd;EAEA,IAAI,cAAc,GAAgB;GAEhC,AADA,KAAKC,GAAkB,EAAQ,CAAM,GACr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ate","#setValue","#initialChecked","#handleCheckboxAttributeChange","#checkCheckboxValidity","#customValidityMessage"],"sources":["../../src/mixins/checkbox.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 { 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 disconnectedCallback?(): 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 CheckboxFormControlValue = Extract<FormControlValue, string>;\n\nexport interface CheckboxFormControlMixinInstance extends FormControlMixinInstance<CheckboxFormControlValue> {\n /**\n * Shows whether the checkbox currently has a checked value.\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#checked\n * @attr checked\n * @reflect\n */\n checked: boolean;\n\n /**\n * Indicates whether the checkbox is visually indeterminate.\n * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/indeterminate\n * @attr indeterminate\n * @reflect\n */\n indeterminate: boolean;\n\n updateCheckedState(): void;\n\n /**\n * Toggles the checked state.\n */\n toggle(event?: Event): void;\n}\n\nexport type CheckboxFormControlMixinReturn<TBase extends Constructor> = (new (\n ...args: ConstructorParameters<TBase>\n) => InstanceType<TBase> & CheckboxFormControlMixinInstance) & {\n formAssociated: boolean;\n observedAttributes: string[];\n} & Omit<TBase, 'prototype'>;\n\ninterface CheckboxBaseInstance extends HTMLElement, FormControlMixinInstance<CheckboxFormControlValue> {\n connectedCallback(): void;\n attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;\n requestUpdate?(name?: string, oldValue?: unknown): void;\n}\n\ntype CheckboxBaseConstructor<TBase extends Constructor> = (new (\n ...args: ConstructorParameters<TBase>\n) => CheckboxBaseInstance) & {\n formAssociated: boolean;\n observedAttributes: string[];\n};\n\nconst checkboxValues = new WeakMap<object, string>();\nconst constructedCheckboxes = new WeakSet();\n\n/**\n * @description A mixin that adds native checkbox-style form control behavior.\n */\nexport function CheckboxFormControlMixin<TBase extends Constructor>(\n SuperClass: TBase\n): CheckboxFormControlMixinReturn<TBase> {\n const Base = FormControlMixin<TBase, CheckboxFormControlValue>(SuperClass) as CheckboxBaseConstructor<TBase>;\n\n return class CheckboxFormControlBase extends Base {\n #checked = false;\n\n #customValidityMessage = '';\n\n #indeterminate = false;\n\n #initialChecked: boolean | undefined;\n\n #reflectingChecked = false;\n\n constructor(...args: ConstructorParameters<TBase>) {\n super(...args);\n constructedCheckboxes.add(this);\n }\n\n static get observedAttributes() {\n return super.observedAttributes.concat(['checked', 'indeterminate']);\n }\n\n get checked(): boolean {\n return this.#checked;\n }\n\n set checked(value: boolean) {\n this.#setChecked(Boolean(value));\n this.#reflectingChecked = true;\n this.toggleAttribute('checked', this.#checked);\n this.#reflectingChecked = false;\n }\n\n override get disabled(): boolean {\n return super.disabled;\n }\n\n override set disabled(value: boolean) {\n super.disabled = Boolean(value);\n if (constructedCheckboxes.has(this)) {\n this.updateCheckedState();\n }\n }\n\n get indeterminate(): boolean {\n return this.#indeterminate;\n }\n\n set indeterminate(value: boolean) {\n this.#setIndeterminate(Boolean(value));\n this.toggleAttribute('indeterminate', this.#indeterminate);\n }\n\n override get type(): string {\n return 'checkbox';\n }\n\n override set type(_value: string) {}\n\n override get value(): CheckboxFormControlValue {\n return checkboxValues.get(this) ?? 'on';\n }\n\n override set value(value: CheckboxFormControlValue | number | boolean) {\n this.#setValue(getCheckboxValue(value));\n this.setAttribute('value', this.value);\n }\n\n override connectedCallback() {\n super.connectedCallback();\n this.#initialChecked ??= this.checked;\n this.updateCheckedState();\n }\n\n override attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {\n if (oldValue === newValue) {\n return;\n }\n\n if (this.#handleCheckboxAttributeChange(name, newValue)) {\n if (name === 'checked' && !this.#reflectingChecked) {\n this.#initialChecked = this.checked;\n }\n return;\n }\n\n super.attributeChangedCallback?.(name, oldValue, newValue);\n }\n\n override formResetCallback() {\n this.checked = this.#initialChecked ?? false;\n this.indeterminate = false;\n this.updateCheckedState();\n }\n\n override formStateRestoreCallback(state: string | null, _reason?: string) {\n this.checked = state !== null;\n this.updateCheckedState();\n }\n\n override reportValidity() {\n this.#checkCheckboxValidity();\n return this._internals.reportValidity();\n }\n\n override checkValidity() {\n return this.#checkCheckboxValidity();\n }\n\n override setCustomValidity(message: string) {\n this.#customValidityMessage = message;\n this.checkValidity();\n }\n\n override _updateFormState() {\n this.updateCheckedState();\n }\n\n updateCheckedState() {\n this._internals.setFormValue(this.name && this.checked && !this.disabled ? this.value : null);\n toggleState(this._internals, 'checked', this.checked);\n toggleState(this._internals, 'indeterminate', this.indeterminate);\n this.checkValidity();\n }\n\n toggle(event?: Event) {\n if (this.disabled || this.readOnly || event?.defaultPrevented) {\n return;\n }\n\n this.checked = !this.checked;\n this.indeterminate = false;\n this.dispatchInputEvent();\n this.dispatchChangeEvent();\n }\n\n #checkCheckboxValidity() {\n if (this.noValidate) {\n this.setValidity({});\n return true;\n }\n\n if (this.#customValidityMessage) {\n this.setValidity({ customError: true }, this.#customValidityMessage);\n return false;\n }\n\n if (this.required && !this.checked) {\n this.setValidity({ valueMissing: true }, 'Select this option');\n return false;\n }\n\n return super.checkValidity();\n }\n\n #handleCheckboxAttributeChange(name: string, newValue: string | null) {\n if (name === 'checked') {\n this.#setChecked(newValue !== null);\n return true;\n }\n\n if (name === 'indeterminate') {\n this.#setIndeterminate(newValue !== null);\n return true;\n }\n\n if (name === 'value') {\n this.#setValue(newValue ?? 'on');\n return true;\n }\n\n return false;\n }\n\n #setChecked(checked: boolean) {\n const previousValue = this.#checked;\n this.#checked = checked;\n this.updateCheckedState();\n this.requestUpdate?.('checked', previousValue);\n }\n\n #setIndeterminate(indeterminate: boolean) {\n const previousValue = this.#indeterminate;\n this.#indeterminate = indeterminate;\n toggleState(this._internals, 'indeterminate', indeterminate);\n this.requestUpdate?.('indeterminate', previousValue);\n }\n\n #setValue(value: string) {\n const previousValue = this.value;\n checkboxValues.set(this, value);\n this.updateCheckedState();\n this.requestUpdate?.('value', previousValue);\n }\n } as unknown as CheckboxFormControlMixinReturn<TBase>;\n}\n\nfunction getCheckboxValue(value: unknown) {\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return `${value}`;\n }\n\n return 'on';\n}\n"],"mappings":";;;AAgEA,IAAM,oBAAiB,IAAI,QAAwB,GAC7C,oBAAwB,IAAI,QAAQ;AAK1C,SAAgB,EACd,GACuC;CACvC,IAAM,IAAO,EAAkD,CAAU;CAEzE,OAAO,cAAsC,EAAK;EAChD,KAAW;EAEX,KAAyB;EAEzB,KAAiB;EAEjB;EAEA,KAAqB;EAErB,YAAY,GAAG,GAAoC;GAEjD,AADA,MAAM,GAAG,CAAI,GACb,EAAsB,IAAI,IAAI;EAChC;EAEA,WAAW,qBAAqB;GAC9B,OAAO,MAAM,mBAAmB,OAAO,CAAC,WAAW,eAAe,CAAC;EACrE;EAEA,IAAI,UAAmB;GACrB,OAAO,KAAKA;EACd;EAEA,IAAI,QAAQ,GAAgB;GAI1B,AAHA,KAAKC,GAAY,EAAQ,CAAM,GAC/B,KAAKC,KAAqB,IAC1B,KAAK,gBAAgB,WAAW,KAAKF,EAAQ,GAC7C,KAAKE,KAAqB;EAC5B;EAEA,IAAa,WAAoB;GAC/B,OAAO,MAAM;EACf;EAEA,IAAa,SAAS,GAAgB;GAEpC,AADA,MAAM,WAAW,EAAQ,GACrB,EAAsB,IAAI,IAAI,KAChC,KAAK,mBAAmB;EAE5B;EAEA,IAAI,gBAAyB;GAC3B,OAAO,KAAKC;EACd;EAEA,IAAI,cAAc,GAAgB;GAEhC,AADA,KAAKC,GAAkB,EAAQ,CAAM,GACrC,KAAK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2
|
"name": "@nvidia-elements/forms",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"release": {
|
|
5
5
|
"extends": "../../release.config.js"
|
|
6
6
|
},
|
|
7
7
|
"description": "Form control utilities and validation providing mixins, validators, and schema-based validation. Includes form association, event handling, and support for complex data types.",
|
|
8
8
|
"keywords": [
|
|
9
|
+
"nvidia",
|
|
10
|
+
"web-components",
|
|
11
|
+
"custom-elements",
|
|
9
12
|
"forms",
|
|
10
|
-
"validation",
|
|
11
|
-
"
|
|
13
|
+
"form-validation",
|
|
14
|
+
"form-associated-custom-elements",
|
|
15
|
+
"lit"
|
|
12
16
|
],
|
|
13
17
|
"homepage": "https://NVIDIA.github.io/elements/",
|
|
14
18
|
"repository": {
|
|
@@ -91,11 +95,11 @@
|
|
|
91
95
|
"typescript": "6.0.3",
|
|
92
96
|
"vite": "8.1.4",
|
|
93
97
|
"vitest": "4.1.10",
|
|
94
|
-
"@nvidia-elements/styles": "2.1.
|
|
98
|
+
"@nvidia-elements/styles": "2.1.2",
|
|
95
99
|
"@internals/eslint": "0.0.0",
|
|
96
100
|
"@internals/testing": "0.0.0",
|
|
97
101
|
"@internals/vite": "0.0.0",
|
|
98
|
-
"@nvidia-elements/lint": "2.
|
|
102
|
+
"@nvidia-elements/lint": "2.3.0"
|
|
99
103
|
},
|
|
100
104
|
"wireit": {
|
|
101
105
|
"dev": {
|