@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,16 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
2
|
+
type CommandBehaviorHost = ReactiveElement & {
|
|
3
|
+
command?: string;
|
|
4
|
+
commandForElement: HTMLElement | null;
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
readOnly: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare class TypeCommandController<T extends CommandBehaviorHost> implements ReactiveController {
|
|
9
|
+
#private;
|
|
10
|
+
private host;
|
|
11
|
+
constructor(host: T);
|
|
12
|
+
hostUpdated(): void;
|
|
13
|
+
hostDisconnected(): void;
|
|
14
|
+
get target(): HTMLElement | null;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getFlattenedDOMTree as e } from "../utils.js";
|
|
2
|
+
//#region src/internal/controllers/type-command.controller.ts
|
|
3
|
+
var t = class {
|
|
4
|
+
constructor(e) {
|
|
5
|
+
this.host = e, this.host.addController(this);
|
|
6
|
+
}
|
|
7
|
+
hostUpdated() {
|
|
8
|
+
this.#e(), !this.host.readOnly && !this.host.disabled && this.host.addEventListener("click", this.#t);
|
|
9
|
+
}
|
|
10
|
+
hostDisconnected() {
|
|
11
|
+
this.#e();
|
|
12
|
+
}
|
|
13
|
+
#e() {
|
|
14
|
+
this.host.removeEventListener("click", this.#t);
|
|
15
|
+
}
|
|
16
|
+
#t = (e) => {
|
|
17
|
+
e.defaultPrevented || this.#n();
|
|
18
|
+
};
|
|
19
|
+
#n() {
|
|
20
|
+
if (this.host.readOnly || this.host.disabled || !this.host.command) return !1;
|
|
21
|
+
let e = this.target;
|
|
22
|
+
return e ? (e.dispatchEvent(new globalThis.CommandEvent("command", {
|
|
23
|
+
command: this.host.command,
|
|
24
|
+
source: this.host
|
|
25
|
+
})), !0) : (console.warn("commandForElement", this.host.commandForElement || this.host.getAttribute("commandfor"), "not found"), !1);
|
|
26
|
+
}
|
|
27
|
+
get target() {
|
|
28
|
+
if (this.host.commandForElement) return this.host.commandForElement;
|
|
29
|
+
let t = this.host.getAttribute("commandfor");
|
|
30
|
+
return t ? e(this.host.getRootNode()).find((e) => e.id === t) ?? null : null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { t as TypeCommandController };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=type-command.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-command.controller.js","names":["#removeCommandBehavior","#onCommandClick","#dispatchCommand"],"sources":["../../../src/internal/controllers/type-command.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getFlattenedDOMTree } from '../utils.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype CommandBehaviorHost = ReactiveElement & {\n command?: string;\n commandForElement: HTMLElement | null;\n disabled: boolean;\n readOnly: boolean;\n};\n\nexport class TypeCommandController<T extends CommandBehaviorHost> implements ReactiveController {\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n hostUpdated() {\n this.#removeCommandBehavior();\n if (!this.host.readOnly && !this.host.disabled) {\n this.host.addEventListener('click', this.#onCommandClick);\n }\n }\n\n hostDisconnected() {\n this.#removeCommandBehavior();\n }\n\n #removeCommandBehavior() {\n this.host.removeEventListener('click', this.#onCommandClick);\n }\n\n #onCommandClick = (event: Event) => {\n if (!event.defaultPrevented) {\n this.#dispatchCommand();\n }\n };\n\n #dispatchCommand() {\n if (this.host.readOnly || this.host.disabled || !this.host.command) {\n return false;\n }\n\n const target = this.target;\n if (!target) {\n console.warn(\n 'commandForElement',\n this.host.commandForElement || this.host.getAttribute('commandfor'),\n 'not found'\n );\n return false;\n }\n\n target.dispatchEvent(new globalThis.CommandEvent('command', { command: this.host.command, source: this.host }));\n return true;\n }\n\n get target(): HTMLElement | null {\n if (this.host.commandForElement) {\n return this.host.commandForElement;\n }\n\n const id = this.host.getAttribute('commandfor');\n if (!id) {\n return null;\n }\n\n return getFlattenedDOMTree(this.host.getRootNode() as HTMLElement).find(el => el.id === id) ?? null;\n }\n}\n"],"mappings":";;AAaA,IAAa,IAAb,MAAgG;CAC9F,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,cAAc;EAEZ,AADA,KAAKA,GAAuB,GACxB,CAAC,KAAK,KAAK,YAAY,CAAC,KAAK,KAAK,YACpC,KAAK,KAAK,iBAAiB,SAAS,KAAKC,EAAe;CAE5D;CAEA,mBAAmB;EACjB,KAAKD,GAAuB;CAC9B;CAEA,KAAyB;EACvB,KAAK,KAAK,oBAAoB,SAAS,KAAKC,EAAe;CAC7D;CAEA,MAAmB,MAAiB;EAClC,AAAK,EAAM,oBACT,KAAKC,GAAiB;CAE1B;CAEA,KAAmB;EACjB,IAAI,KAAK,KAAK,YAAY,KAAK,KAAK,YAAY,CAAC,KAAK,KAAK,SACzD,OAAO;EAGT,IAAM,IAAS,KAAK;EAWpB,OAVK,KASL,EAAO,cAAc,IAAI,WAAW,aAAa,WAAW;GAAE,SAAS,KAAK,KAAK;GAAS,QAAQ,KAAK;EAAK,CAAC,CAAC,GACvG,OATL,QAAQ,KACN,qBACA,KAAK,KAAK,qBAAqB,KAAK,KAAK,aAAa,YAAY,GAClE,WACF,GACO;CAKX;CAEA,IAAI,SAA6B;EAC/B,IAAI,KAAK,KAAK,mBACZ,OAAO,KAAK,KAAK;EAGnB,IAAM,IAAK,KAAK,KAAK,aAAa,YAAY;EAK9C,OAJK,IAIE,EAAoB,KAAK,KAAK,YAAY,CAAgB,EAAE,MAAK,MAAM,EAAG,OAAO,CAAE,KAAK,OAHtF;CAIX;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
2
|
+
type InterestInvokerHost = ReactiveElement & {
|
|
3
|
+
interestForElement: HTMLElement | null;
|
|
4
|
+
};
|
|
5
|
+
export declare class TypeInterestInvokerController<T extends InterestInvokerHost> implements ReactiveController {
|
|
6
|
+
#private;
|
|
7
|
+
private host;
|
|
8
|
+
constructor(host: T);
|
|
9
|
+
hostConnected(): void;
|
|
10
|
+
hostDisconnected(): void;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getFlattenedDOMTree as e } from "../utils.js";
|
|
2
|
+
//#region src/internal/controllers/type-interest-invoker.controller.ts
|
|
3
|
+
var t = class {
|
|
4
|
+
constructor(e) {
|
|
5
|
+
this.host = e, this.host.addController(this);
|
|
6
|
+
}
|
|
7
|
+
hostConnected() {
|
|
8
|
+
this.host.addEventListener("mouseenter", this.#e), this.host.addEventListener("mouseleave", this.#t), this.host.addEventListener("focus", this.#e), this.host.addEventListener("blur", this.#t);
|
|
9
|
+
}
|
|
10
|
+
hostDisconnected() {
|
|
11
|
+
this.host.removeEventListener("mouseenter", this.#e), this.host.removeEventListener("mouseleave", this.#t), this.host.removeEventListener("focus", this.#e), this.host.removeEventListener("blur", this.#t);
|
|
12
|
+
}
|
|
13
|
+
#e = () => {
|
|
14
|
+
if (this.#n(), this.host.interestForElement) {
|
|
15
|
+
let e = new Event("interest", { cancelable: !0 });
|
|
16
|
+
e.source = this.host, this.host.interestForElement.dispatchEvent(e);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
#t = () => {
|
|
20
|
+
if (this.#n(), this.host.interestForElement) {
|
|
21
|
+
let e = new Event("loseinterest", { cancelable: !0 });
|
|
22
|
+
e.source = this.host, this.host.interestForElement.dispatchEvent(e);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
#n() {
|
|
26
|
+
let t = this.host.getAttribute("interestfor");
|
|
27
|
+
t && !this.host.interestForElement && (this.host.interestForElement = e(this.host.getRootNode()).find((e) => e.id === t) ?? null);
|
|
28
|
+
let n = this.host.getAttribute("popovertarget");
|
|
29
|
+
if (n && !t) {
|
|
30
|
+
let t = e(this.host.getRootNode()).find((e) => e.id === n);
|
|
31
|
+
t && t.popover === "hint" && (this.host.interestForElement = t);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { t as TypeInterestInvokerController };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=type-interest-invoker.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-interest-invoker.controller.js","names":["#onInterest","#onLoseInterest","#updateInterestForElement"],"sources":["../../../src/internal/controllers/type-interest-invoker.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getFlattenedDOMTree } from '../utils.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype InterestEvent = Event & { source: HTMLElement };\n\ntype InterestInvokerHost = ReactiveElement & {\n interestForElement: HTMLElement | null;\n};\n\nexport class TypeInterestInvokerController<T extends InterestInvokerHost> implements ReactiveController {\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n hostConnected() {\n this.host.addEventListener('mouseenter', this.#onInterest);\n this.host.addEventListener('mouseleave', this.#onLoseInterest);\n this.host.addEventListener('focus', this.#onInterest);\n this.host.addEventListener('blur', this.#onLoseInterest);\n }\n\n hostDisconnected() {\n this.host.removeEventListener('mouseenter', this.#onInterest);\n this.host.removeEventListener('mouseleave', this.#onLoseInterest);\n this.host.removeEventListener('focus', this.#onInterest);\n this.host.removeEventListener('blur', this.#onLoseInterest);\n }\n\n #onInterest = () => {\n this.#updateInterestForElement();\n if (this.host.interestForElement) {\n const event = new Event('interest', { cancelable: true }) as InterestEvent;\n event.source = this.host;\n this.host.interestForElement.dispatchEvent(event);\n }\n };\n\n #onLoseInterest = () => {\n this.#updateInterestForElement();\n if (this.host.interestForElement) {\n const event = new Event('loseinterest', { cancelable: true }) as InterestEvent;\n event.source = this.host;\n this.host.interestForElement.dispatchEvent(event);\n }\n };\n\n #updateInterestForElement() {\n const interestForIdRef = this.host.getAttribute('interestfor');\n if (interestForIdRef && !this.host.interestForElement) {\n this.host.interestForElement =\n getFlattenedDOMTree(this.host.getRootNode()).find(element => element.id === interestForIdRef) ?? null;\n }\n\n const popoverTargetIdRef = this.host.getAttribute('popovertarget');\n if (popoverTargetIdRef && !interestForIdRef) {\n const target = getFlattenedDOMTree(this.host.getRootNode()).find(element => element.id === popoverTargetIdRef);\n if (target && target.popover === 'hint') {\n this.host.interestForElement = target;\n }\n }\n }\n}\n"],"mappings":";;AAYA,IAAa,IAAb,MAAwG;CACtG,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,gBAAgB;EAId,AAHA,KAAK,KAAK,iBAAiB,cAAc,KAAKA,EAAW,GACzD,KAAK,KAAK,iBAAiB,cAAc,KAAKC,EAAe,GAC7D,KAAK,KAAK,iBAAiB,SAAS,KAAKD,EAAW,GACpD,KAAK,KAAK,iBAAiB,QAAQ,KAAKC,EAAe;CACzD;CAEA,mBAAmB;EAIjB,AAHA,KAAK,KAAK,oBAAoB,cAAc,KAAKD,EAAW,GAC5D,KAAK,KAAK,oBAAoB,cAAc,KAAKC,EAAe,GAChE,KAAK,KAAK,oBAAoB,SAAS,KAAKD,EAAW,GACvD,KAAK,KAAK,oBAAoB,QAAQ,KAAKC,EAAe;CAC5D;CAEA,WAAoB;EAElB,IADA,KAAKC,GAA0B,GAC3B,KAAK,KAAK,oBAAoB;GAChC,IAAM,IAAQ,IAAI,MAAM,YAAY,EAAE,YAAY,GAAK,CAAC;GAExD,AADA,EAAM,SAAS,KAAK,MACpB,KAAK,KAAK,mBAAmB,cAAc,CAAK;EAClD;CACF;CAEA,WAAwB;EAEtB,IADA,KAAKA,GAA0B,GAC3B,KAAK,KAAK,oBAAoB;GAChC,IAAM,IAAQ,IAAI,MAAM,gBAAgB,EAAE,YAAY,GAAK,CAAC;GAE5D,AADA,EAAM,SAAS,KAAK,MACpB,KAAK,KAAK,mBAAmB,cAAc,CAAK;EAClD;CACF;CAEA,KAA4B;EAC1B,IAAM,IAAmB,KAAK,KAAK,aAAa,aAAa;EAC7D,AAAI,KAAoB,CAAC,KAAK,KAAK,uBACjC,KAAK,KAAK,qBACR,EAAoB,KAAK,KAAK,YAAY,CAAC,EAAE,MAAK,MAAW,EAAQ,OAAO,CAAgB,KAAK;EAGrG,IAAM,IAAqB,KAAK,KAAK,aAAa,eAAe;EACjE,IAAI,KAAsB,CAAC,GAAkB;GAC3C,IAAM,IAAS,EAAoB,KAAK,KAAK,YAAY,CAAC,EAAE,MAAK,MAAW,EAAQ,OAAO,CAAkB;GAC7G,AAAI,KAAU,EAAO,YAAY,WAC/B,KAAK,KAAK,qBAAqB;EAEnC;CACF;AACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ButtonType } from '../../mixins/button.types.js';
|
|
2
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
3
|
+
type NativeButtonBehaviorHost = ReactiveElement & {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
form: HTMLFormElement | null | string;
|
|
6
|
+
name?: string;
|
|
7
|
+
readOnly: boolean;
|
|
8
|
+
type?: ButtonType;
|
|
9
|
+
value?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare class TypeNativeButtonController<T extends NativeButtonBehaviorHost> implements ReactiveController {
|
|
12
|
+
#private;
|
|
13
|
+
private host;
|
|
14
|
+
constructor(host: T);
|
|
15
|
+
get defaultType(): ButtonType | undefined;
|
|
16
|
+
hostUpdated(): void;
|
|
17
|
+
hostDisconnected(): void;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { onKeys as e, stopEvent as t } from "../utils.js";
|
|
2
|
+
//#region src/internal/controllers/type-native-button.controller.ts
|
|
3
|
+
var n = class {
|
|
4
|
+
#e;
|
|
5
|
+
#t;
|
|
6
|
+
#n;
|
|
7
|
+
constructor(e) {
|
|
8
|
+
this.host = e, this.host.addController(this);
|
|
9
|
+
}
|
|
10
|
+
get defaultType() {
|
|
11
|
+
return this.#e;
|
|
12
|
+
}
|
|
13
|
+
hostUpdated() {
|
|
14
|
+
this.#r(), this.#i(), !this.host.readOnly && !this.host.disabled && (this.host.addEventListener("click", this.#o), this.host.addEventListener("keyup", this.#a));
|
|
15
|
+
}
|
|
16
|
+
hostDisconnected() {
|
|
17
|
+
this.#i(), this.#u();
|
|
18
|
+
}
|
|
19
|
+
#r() {
|
|
20
|
+
!this.host.type && !this.host.hasAttribute("type") && this.host.form instanceof HTMLFormElement && (this.#e = "submit");
|
|
21
|
+
}
|
|
22
|
+
#i() {
|
|
23
|
+
this.host.removeEventListener("click", this.#o), this.host.removeEventListener("keyup", this.#a);
|
|
24
|
+
}
|
|
25
|
+
#a = (t) => {
|
|
26
|
+
e(["Enter", "Space"], t, () => this.host.click());
|
|
27
|
+
};
|
|
28
|
+
#o = (e) => {
|
|
29
|
+
if (this.host.disabled) {
|
|
30
|
+
t(e);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this.host.type === "submit" && this.host.form instanceof HTMLFormElement ? this.#s(this.host.form) : this.host.type === "reset" && this.host.form instanceof HTMLFormElement && this.host.form.reset();
|
|
34
|
+
};
|
|
35
|
+
#s(e) {
|
|
36
|
+
this.#u(), this.#l(), this.#n = e, e.addEventListener("submit", this.#c, { once: !0 }), this.#t?.remove(), e.appendChild(this.#t), e.requestSubmit(this.#t);
|
|
37
|
+
}
|
|
38
|
+
#c = () => {
|
|
39
|
+
let e = this.#t;
|
|
40
|
+
this.#n = void 0, setTimeout(() => {
|
|
41
|
+
e?.remove(), this.#t === e && (this.#t = void 0);
|
|
42
|
+
}, 0);
|
|
43
|
+
};
|
|
44
|
+
#l() {
|
|
45
|
+
this.#t || (this.#t = globalThis.document.createElement("button"), this.#t.type = "submit", this.#t.style.display = "none"), this.#t.name = this.host.name ?? "", this.#t.value = this.host.value ?? "";
|
|
46
|
+
}
|
|
47
|
+
#u() {
|
|
48
|
+
this.#n?.removeEventListener("submit", this.#c), this.#n = void 0, this.#t?.remove(), this.#t = void 0;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { n as TypeNativeButtonController };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=type-native-button.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-native-button.controller.js","names":["#defaultType","#setButtonType","#removeNativeButtonBehavior","#onNativeButtonClick","#onNativeButtonKeyup","#removeSubmitter","#requestSubmit","#createSubmitter","#submitterForm","#onSubmit","#submitter"],"sources":["../../../src/internal/controllers/type-native-button.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { onKeys, stopEvent } from '../utils.js';\nimport type { ButtonType } from '../../mixins/button.types.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype NativeButtonBehaviorHost = ReactiveElement & {\n disabled: boolean;\n form: HTMLFormElement | null | string;\n name?: string;\n readOnly: boolean;\n type?: ButtonType;\n value?: string;\n};\n\nexport class TypeNativeButtonController<T extends NativeButtonBehaviorHost> implements ReactiveController {\n #defaultType: ButtonType | undefined;\n #submitter: HTMLButtonElement | undefined;\n #submitterForm: HTMLFormElement | undefined;\n\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n get defaultType() {\n return this.#defaultType;\n }\n\n hostUpdated() {\n this.#setButtonType();\n this.#removeNativeButtonBehavior();\n if (!this.host.readOnly && !this.host.disabled) {\n this.host.addEventListener('click', this.#onNativeButtonClick);\n this.host.addEventListener('keyup', this.#onNativeButtonKeyup);\n }\n }\n\n hostDisconnected() {\n this.#removeNativeButtonBehavior();\n this.#removeSubmitter();\n }\n\n #setButtonType() {\n if (!this.host.type && !this.host.hasAttribute('type') && this.host.form instanceof HTMLFormElement) {\n this.#defaultType = 'submit';\n }\n }\n\n #removeNativeButtonBehavior() {\n this.host.removeEventListener('click', this.#onNativeButtonClick);\n this.host.removeEventListener('keyup', this.#onNativeButtonKeyup);\n }\n\n #onNativeButtonKeyup = (event: KeyboardEvent) => {\n onKeys(['Enter', 'Space'], event, () => this.host.click());\n };\n\n #onNativeButtonClick = (event: Event) => {\n if (this.host.disabled) {\n stopEvent(event);\n return;\n }\n\n if (this.host.type === 'submit' && this.host.form instanceof HTMLFormElement) {\n this.#requestSubmit(this.host.form);\n } else if (this.host.type === 'reset' && this.host.form instanceof HTMLFormElement) {\n this.host.form.reset();\n }\n };\n\n #requestSubmit(form: HTMLFormElement) {\n this.#removeSubmitter();\n this.#createSubmitter();\n this.#submitterForm = form;\n form.addEventListener('submit', this.#onSubmit, { once: true });\n this.#submitter?.remove();\n form.appendChild(this.#submitter!);\n form.requestSubmit(this.#submitter);\n }\n\n #onSubmit = () => {\n const submitter = this.#submitter;\n this.#submitterForm = undefined;\n setTimeout(() => {\n submitter?.remove();\n if (this.#submitter === submitter) {\n this.#submitter = undefined;\n }\n }, 0);\n };\n\n #createSubmitter() {\n if (!this.#submitter) {\n this.#submitter = globalThis.document.createElement('button');\n this.#submitter.type = 'submit';\n this.#submitter.style.display = 'none';\n }\n\n this.#submitter.name = this.host.name ?? '';\n this.#submitter.value = this.host.value ?? '';\n }\n\n #removeSubmitter() {\n this.#submitterForm?.removeEventListener('submit', this.#onSubmit);\n this.#submitterForm = undefined;\n this.#submitter?.remove();\n this.#submitter = undefined;\n }\n}\n"],"mappings":";;AAgBA,IAAa,IAAb,MAA0G;CACxG;CACA;CACA;CAEA,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,IAAI,cAAc;EAChB,OAAO,KA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f,AADA,GAAW,OAAO,GACd,KAAKE,OAAe,MACtB,KAAKA,KAAa,KAAA;EAEtB,GAAG,CAAC;CACN;CAEA,KAAmB;EAQjB,AAPK,KAAKA,OACR,KAAKA,KAAa,WAAW,SAAS,cAAc,QAAQ,GAC5D,KAAKA,GAAW,OAAO,UACvB,KAAKA,GAAW,MAAM,UAAU,SAGlC,KAAKA,GAAW,OAAO,KAAK,KAAK,QAAQ,IACzC,KAAKA,GAAW,QAAQ,KAAK,KAAK,SAAS;CAC7C;CAEA,KAAmB;EAIjB,AAHA,KAAKF,IAAgB,oBAAoB,UAAU,KAAKC,EAAS,GACjE,KAAKD,KAAiB,KAAA,GACtB,KAAKE,IAAY,OAAO,GACxB,KAAKA,KAAa,KAAA;CACpB;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PopoverTargetAction } from '../../mixins/button.types.js';
|
|
2
|
+
import { ReactiveController, ReactiveElement } from './types.js';
|
|
3
|
+
type PopoverTriggerHost = ReactiveElement & {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
popoverTargetAction?: PopoverTargetAction;
|
|
6
|
+
popoverTargetElement: HTMLElement | null;
|
|
7
|
+
popovertarget?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class TypePopoverTriggerController<T extends PopoverTriggerHost> implements ReactiveController {
|
|
10
|
+
#private;
|
|
11
|
+
private host;
|
|
12
|
+
constructor(host: T);
|
|
13
|
+
hostConnected(): void;
|
|
14
|
+
hostDisconnected(): void;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getFlattenedDOMTree as e, getHostAnchor as t } from "../utils.js";
|
|
2
|
+
//#region src/internal/controllers/type-popover-trigger.controller.ts
|
|
3
|
+
var n = class {
|
|
4
|
+
constructor(e) {
|
|
5
|
+
this.host = e, this.host.addController(this);
|
|
6
|
+
}
|
|
7
|
+
hostConnected() {
|
|
8
|
+
this.host.addEventListener("click", this.#e);
|
|
9
|
+
}
|
|
10
|
+
hostDisconnected() {
|
|
11
|
+
this.host.removeEventListener("click", this.#e);
|
|
12
|
+
}
|
|
13
|
+
#e = () => {
|
|
14
|
+
let n = this.host, r = this.host.popoverTargetElement;
|
|
15
|
+
!r && this.host.popovertarget && (r = e(this.host.getRootNode()).find((e) => e.id === this.host.popovertarget) ?? null, this.host.popoverTargetElement = r), r?.anchor && (n = t(r)), !(!r || this.host.disabled) && (this.host.popoverTargetAction === "hide" ? r.hidePopover() : this.host.popoverTargetAction === "show" ? r.showPopover({ source: n }) : r.togglePopover({ source: n }));
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { n as TypePopoverTriggerController };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=type-popover-trigger.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-popover-trigger.controller.js","names":["#onClick"],"sources":["../../../src/internal/controllers/type-popover-trigger.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { PopoverTargetAction } from '../../mixins/button.types.js';\nimport { getFlattenedDOMTree, getHostAnchor } from '../utils.js';\nimport type { PopoverAnchorElement } from '../utils.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype PopoverTriggerHost = ReactiveElement & {\n disabled: boolean;\n popoverTargetAction?: PopoverTargetAction;\n popoverTargetElement: HTMLElement | null;\n popovertarget?: string;\n};\n\nexport class TypePopoverTriggerController<T extends PopoverTriggerHost> implements ReactiveController {\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n hostConnected() {\n this.host.addEventListener('click', this.#onClick);\n }\n\n hostDisconnected() {\n this.host.removeEventListener('click', this.#onClick);\n }\n\n #onClick = () => {\n let source = this.host as HTMLElement;\n let popoverTargetElement = this.host.popoverTargetElement;\n\n if (!popoverTargetElement && this.host.popovertarget) {\n popoverTargetElement =\n getFlattenedDOMTree(this.host.getRootNode()).find(element => element.id === this.host.popovertarget) ?? null;\n this.host.popoverTargetElement = popoverTargetElement;\n }\n\n if ((popoverTargetElement as PopoverAnchorElement)?.anchor) {\n source = getHostAnchor(popoverTargetElement as PopoverAnchorElement);\n }\n\n if (!popoverTargetElement || this.host.disabled) {\n return;\n }\n\n if (this.host.popoverTargetAction === 'hide') {\n popoverTargetElement.hidePopover();\n } else if (this.host.popoverTargetAction === 'show') {\n popoverTargetElement.showPopover({ source });\n } else {\n popoverTargetElement.togglePopover({ source });\n }\n };\n}\n"],"mappings":";;AAeA,IAAa,IAAb,MAAsG;CACpG,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,gBAAgB;EACd,KAAK,KAAK,iBAAiB,SAAS,KAAKA,EAAQ;CACnD;CAEA,mBAAmB;EACjB,KAAK,KAAK,oBAAoB,SAAS,KAAKA,EAAQ;CACtD;CAEA,WAAiB;EACf,IAAI,IAAS,KAAK,MACd,IAAuB,KAAK,KAAK;EAErC,AAAI,CAAC,KAAwB,KAAK,KAAK,kBACrC,IACE,EAAoB,KAAK,KAAK,YAAY,CAAC,EAAE,MAAK,MAAW,EAAQ,OAAO,KAAK,KAAK,aAAa,KAAK,MAC1G,KAAK,KAAK,uBAAuB,IAG9B,GAA+C,WAClD,IAAS,EAAc,CAA4C,IAGjE,GAAC,KAAwB,KAAK,KAAK,cAInC,KAAK,KAAK,wBAAwB,SACpC,EAAqB,YAAY,IACxB,KAAK,KAAK,wBAAwB,SAC3C,EAAqB,YAAY,EAAE,UAAO,CAAC,IAE3C,EAAqB,cAAc,EAAE,UAAO,CAAC;CAEjD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../../src/internal/errors.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nexport class FormControlError extends Error {\n constructor(formControlName: string, message: string) {\n super(`(${formControlName}): ${message}`);\n this.name = 'FormControlError';\n }\n}\n"],"mappings":";AAGA,IAAa,IAAb,cAAsC,MAAM;CAC1C,YAAY,GAAyB,GAAiB;EAEpD,AADA,MAAM,IAAI,EAAgB,KAAK,
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../../src/internal/errors.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nexport class FormControlError extends Error {\n constructor(formControlName: string, message: string) {\n super(`(${formControlName}): ${message}`);\n this.name = 'FormControlError';\n }\n}\n"],"mappings":";AAGA,IAAa,IAAb,cAAsC,MAAM;CAC1C,YAAY,GAAyB,GAAiB;EAEpD,AADA,MAAM,IAAI,EAAgB,KAAK,GAAS,GACxC,KAAK,OAAO;CACd;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../../src/internal/schema.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Schema } from './types.js';\nimport { FormControlError } from './errors.js';\n\nexport function parseValueSchema<T>(formControlName: string, value: string, schema: Schema): T {\n const parsedValue = parseControlValue(value, schema);\n if (parsedValue === undefined) {\n throw new FormControlError(formControlName, `unsupported value type ${typeof value}`);\n }\n return parsedValue as T;\n}\n\ntype ValidationResult = { validity: Partial<ValidityState>; message: string };\n\nconst VALID: ValidationResult = { validity: { valid: true }, message: '' };\n\nfunction invalid(validity: Partial<ValidityState>, message: string): ValidationResult {\n return { validity: { ...validity, valid: false }, message };\n}\n\nfunction validateString(schema: Schema & { type: 'string' }, value: unknown): ValidationResult {\n if (typeof value !== 'string') {\n return invalid({ typeMismatch: true }, `expected string, got ${typeof value}`);\n }\n if (schema.minLength !== undefined && value.length < schema.minLength) {\n return invalid({ tooShort: true }, `string length ${value.length} is less than minimum length ${schema.minLength}`);\n }\n if (schema.maxLength !== undefined && value.length > schema.maxLength) {\n return invalid(\n { tooLong: true },\n `string length ${value.length} is greater than maximum length ${schema.maxLength}`\n );\n }\n if (schema.pattern && !new RegExp(schema.pattern).test(value)) {\n return invalid({ patternMismatch: true }, `string does not match pattern ${schema.pattern}`);\n }\n return VALID;\n}\n\nfunction validateNumber(schema: Schema & { type: 'number' }, value: unknown): ValidationResult {\n if (typeof value !== 'number') {\n return invalid({ typeMismatch: true }, `expected type number, received type ${typeof value}`);\n }\n if (isNaN(value as unknown as number)) {\n return invalid({ typeMismatch: true }, `expected type number, received type NaN`);\n }\n if (schema.minimum !== undefined && value < schema.minimum) {\n return invalid({ rangeUnderflow: true }, `number ${value} is less than minimum ${schema.minimum}`);\n }\n if (schema.maximum !== undefined && value > schema.maximum) {\n return invalid({ rangeOverflow: true }, `number ${value} is greater than maximum ${schema.maximum}`);\n }\n return VALID;\n}\n\nfunction validateBoolean(value: unknown): ValidationResult {\n if (typeof value !== 'boolean') {\n return invalid({ typeMismatch: true }, `expected boolean, got ${typeof value}`);\n }\n return VALID;\n}\n\nfunction validateArray(schema: Schema & { type: 'array' }, value: unknown): ValidationResult {\n if (!Array.isArray(value)) {\n return invalid({ typeMismatch: true }, `expected type array, received type ${typeof value}`);\n }\n if (schema.minItems !== undefined && value.length < schema.minItems) {\n return invalid(\n { rangeUnderflow: true },\n `array length ${value.length} is less than minimum length ${schema.minItems}`\n );\n }\n if (schema.maxItems !== undefined && value.length > schema.maxItems) {\n return invalid(\n { rangeOverflow: true },\n `array length ${value.length} is greater than maximum length ${schema.maxItems}`\n );\n }\n for (const item of value) {\n const result = validateSchema(schema.items, item);\n if (!result.validity.valid) {\n return result;\n }\n }\n return VALID;\n}\n\nfunction validateObjectProperty(\n property: { name: string; schema: Schema },\n value: Record<string, unknown>,\n required?: string[]\n): ValidationResult {\n const { name, schema: propSchema } = property;\n const propValue = value[name];\n if (propValue === undefined) {\n if (required?.includes(name)) {\n return invalid({ valueMissing: true }, `missing required property: ${name}`);\n }\n return VALID;\n }\n return validateSchema(propSchema, propValue);\n}\n\nfunction validateObject(schema: Schema & { type: 'object' }, value: unknown): ValidationResult {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return invalid({ typeMismatch: true }, `expected type object, received type ${typeof value}`);\n }\n\n const valueProperties = Object.keys(value as object);\n const schemaProperties = Object.keys(schema.properties);\n\n const additionalProps = valueProperties.filter(prop => !schemaProperties.includes(prop));\n if (additionalProps.length > 0 && !schema.additionalProperties) {\n return invalid({ badInput: true }, `additional properties not allowed: ${additionalProps.join(', ')}`);\n }\n\n for (const [prop, propSchema] of Object.entries(schema.properties)) {\n const result = validateObjectProperty(\n { name: prop, schema: propSchema },\n value as Record<string, unknown>,\n schema.required\n );\n if (!result.validity.valid) {\n return result;\n }\n }\n return VALID;\n}\n\nfunction validateEnum(schema: Schema & { type: 'enum' }, value: unknown): ValidationResult {\n if (!schema.enum.includes(value as string | number)) {\n return invalid({ typeMismatch: true }, `value must be one of: ${schema.enum.join(', ')}`);\n }\n return VALID;\n}\n\nexport function validateSchema(schema: Schema, value: unknown): ValidationResult {\n if (!schema || typeof schema !== 'object') {\n return invalid({ badInput: true }, 'invalid schema, schema must be a non-null object');\n }\n\n if (!('type' in schema)) {\n return invalid({ badInput: true }, 'schema must have \"type\" property');\n }\n\n switch (schema.type) {\n case 'string':\n return validateString(schema, value);\n case 'number':\n return validateNumber(schema, value);\n case 'boolean':\n return validateBoolean(value);\n case 'array':\n return validateArray(schema, value);\n case 'object':\n return validateObject(schema, value);\n case 'enum':\n return validateEnum(schema, value);\n default:\n return invalid({ badInput: true }, `unsupported type: ${(schema as { type: string }).type}`);\n }\n}\n\nexport function parseControlValue<T>(value: string, schema: Schema): T | undefined {\n const schemaType = schema.type;\n\n switch (schemaType) {\n case 'string':\n return value as T;\n case 'number':\n return parseFloat(value) as T;\n case 'boolean':\n return (!!value || value === 'true') as T;\n case 'array':\n case 'object':\n return JSON.parse(value) as T;\n case 'enum':\n return (schema.enum.includes(value) ? value : undefined) as T;\n default: {\n const _exhaustiveCheck: never = schemaType;\n return undefined;\n }\n }\n}\n"],"mappings":";;AAMA,SAAgB,EAAoB,GAAyB,GAAe,GAAmB;CAC7F,IAAM,IAAc,EAAkB,GAAO,EAAO;CACpD,IAAI,MAAgB,KAAA,GAClB,MAAM,IAAI,EAAiB,GAAiB,0BAA0B,OAAO,IAAQ;CAEvF,OAAO;;AAKT,IAAM,IAA0B;CAAE,UAAU,EAAE,OAAO,IAAM;CAAE,SAAS;CAAI;AAE1E,SAAS,EAAQ,GAAkC,GAAmC;CACpF,OAAO;EAAE,UAAU;GAAE,GAAG;GAAU,OAAO;GAAO;EAAE;EAAS;;AAG7D,SAAS,EAAe,GAAqC,GAAkC;CAgB7F,OAfI,OAAO,KAAU,WAGjB,EAAO,cAAc,KAAA,KAAa,EAAM,SAAS,EAAO,YACnD,EAAQ,EAAE,UAAU,IAAM,EAAE,iBAAiB,EAAM,OAAO,+BAA+B,EAAO,YAAY,GAEjH,EAAO,cAAc,KAAA,KAAa,EAAM,SAAS,EAAO,YACnD,EACL,EAAE,SAAS,IAAM,EACjB,iBAAiB,EAAM,OAAO,kCAAkC,EAAO,YACxE,GAEC,EAAO,WAAW,CAAC,IAAI,OAAO,EAAO,QAAQ,CAAC,KAAK,EAAM,GACpD,EAAQ,EAAE,iBAAiB,IAAM,EAAE,iCAAiC,EAAO,UAAU,GAEvF,IAdE,EAAQ,EAAE,cAAc,IAAM,EAAE,wBAAwB,OAAO,IAAQ;;AAiBlF,SAAS,EAAe,GAAqC,GAAkC;CAa7F,OAZI,OAAO,KAAU,WAGjB,MAAM,EAA2B,GAC5B,EAAQ,EAAE,cAAc,IAAM,EAAE,0CAA0C,GAE/E,EAAO,YAAY,KAAA,KAAa,IAAQ,EAAO,UA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lG,SAAgB,EAAqB,GAAe,GAA+B;CAGjF,QAFmB,EAAO,MAE1B;EACE,KAAK,UACH,OAAO;EACT,KAAK,UACH,OAAO,WAAW,EAAM;EAC1B,KAAK,WACH,OAAQ,CAAC,CAAC,KAAS,MAAU;EAC/B,KAAK;EACL,KAAK,UACH,OAAO,KAAK,MAAM,EAAM;EAC1B,KAAK,QACH,OAAQ,EAAO,KAAK,SAAS,EAAM,GAAG,IAAQ,KAAA;EAChD,SAEE"}
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../src/internal/schema.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Schema } from './types.js';\nimport { FormControlError } from './errors.js';\n\nexport function parseValueSchema<T>(formControlName: string, value: string, schema: Schema): T {\n const parsedValue = parseControlValue(value, schema);\n if (parsedValue === undefined) {\n throw new FormControlError(formControlName, `unsupported value type ${typeof value}`);\n }\n return parsedValue as T;\n}\n\ntype ValidationResult = { validity: Partial<ValidityState>; message: string };\n\nconst VALID: ValidationResult = { validity: { valid: true }, message: '' };\n\nfunction invalid(validity: Partial<ValidityState>, message: string): ValidationResult {\n return { validity: { ...validity, valid: false }, message };\n}\n\nfunction validateString(schema: Schema & { type: 'string' }, value: unknown): ValidationResult {\n if (typeof value !== 'string') {\n return invalid({ typeMismatch: true }, `expected string, got ${typeof value}`);\n }\n if (schema.minLength !== undefined && value.length < schema.minLength) {\n return invalid({ tooShort: true }, `string length ${value.length} is less than minimum length ${schema.minLength}`);\n }\n if (schema.maxLength !== undefined && value.length > schema.maxLength) {\n return invalid(\n { tooLong: true },\n `string length ${value.length} is greater than maximum length ${schema.maxLength}`\n );\n }\n if (schema.pattern && !new RegExp(schema.pattern).test(value)) {\n return invalid({ patternMismatch: true }, `string does not match pattern ${schema.pattern}`);\n }\n return VALID;\n}\n\nfunction validateNumber(schema: Schema & { type: 'number' }, value: unknown): ValidationResult {\n if (typeof value !== 'number') {\n return invalid({ typeMismatch: true }, `expected type number, received type ${typeof value}`);\n }\n if (isNaN(value as unknown as number)) {\n return invalid({ typeMismatch: true }, `expected type number, received type NaN`);\n }\n if (schema.minimum !== undefined && value < schema.minimum) {\n return invalid({ rangeUnderflow: true }, `number ${value} is less than minimum ${schema.minimum}`);\n }\n if (schema.maximum !== undefined && value > schema.maximum) {\n return invalid({ rangeOverflow: true }, `number ${value} is greater than maximum ${schema.maximum}`);\n }\n return VALID;\n}\n\nfunction validateBoolean(value: unknown): ValidationResult {\n if (typeof value !== 'boolean') {\n return invalid({ typeMismatch: true }, `expected boolean, got ${typeof value}`);\n }\n return VALID;\n}\n\nfunction validateArray(schema: Schema & { type: 'array' }, value: unknown): ValidationResult {\n if (!Array.isArray(value)) {\n return invalid({ typeMismatch: true }, `expected type array, received type ${typeof value}`);\n }\n if (schema.minItems !== undefined && value.length < schema.minItems) {\n return invalid(\n { rangeUnderflow: true },\n `array length ${value.length} is less than minimum length ${schema.minItems}`\n );\n }\n if (schema.maxItems !== undefined && value.length > schema.maxItems) {\n return invalid(\n { rangeOverflow: true },\n `array length ${value.length} is greater than maximum length ${schema.maxItems}`\n );\n }\n for (const item of value) {\n const result = validateSchema(schema.items, item);\n if (!result.validity.valid) {\n return result;\n }\n }\n return VALID;\n}\n\nfunction validateObjectProperty(\n property: { name: string; schema: Schema },\n value: Record<string, unknown>,\n required?: string[]\n): ValidationResult {\n const { name, schema: propSchema } = property;\n const propValue = value[name];\n if (propValue === undefined) {\n if (required?.includes(name)) {\n return invalid({ valueMissing: true }, `missing required property: ${name}`);\n }\n return VALID;\n }\n return validateSchema(propSchema, propValue);\n}\n\nfunction validateObject(schema: Schema & { type: 'object' }, value: unknown): ValidationResult {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return invalid({ typeMismatch: true }, `expected type object, received type ${typeof value}`);\n }\n\n const valueProperties = Object.keys(value as object);\n const schemaProperties = Object.keys(schema.properties);\n\n const additionalProps = valueProperties.filter(prop => !schemaProperties.includes(prop));\n if (additionalProps.length > 0 && !schema.additionalProperties) {\n return invalid({ badInput: true }, `additional properties not allowed: ${additionalProps.join(', ')}`);\n }\n\n for (const [prop, propSchema] of Object.entries(schema.properties)) {\n const result = validateObjectProperty(\n { name: prop, schema: propSchema },\n value as Record<string, unknown>,\n schema.required\n );\n if (!result.validity.valid) {\n return result;\n }\n }\n return VALID;\n}\n\nfunction validateEnum(schema: Schema & { type: 'enum' }, value: unknown): ValidationResult {\n if (!schema.enum.includes(value as string | number)) {\n return invalid({ typeMismatch: true }, `value must be one of: ${schema.enum.join(', ')}`);\n }\n return VALID;\n}\n\nexport function validateSchema(schema: Schema, value: unknown): ValidationResult {\n if (!schema || typeof schema !== 'object') {\n return invalid({ badInput: true }, 'invalid schema, schema must be a non-null object');\n }\n\n if (!('type' in schema)) {\n return invalid({ badInput: true }, 'schema must have \"type\" property');\n }\n\n switch (schema.type) {\n case 'string':\n return validateString(schema, value);\n case 'number':\n return validateNumber(schema, value);\n case 'boolean':\n return validateBoolean(value);\n case 'array':\n return validateArray(schema, value);\n case 'object':\n return validateObject(schema, value);\n case 'enum':\n return validateEnum(schema, value);\n default:\n return invalid({ badInput: true }, `unsupported type: ${(schema as { type: string }).type}`);\n }\n}\n\nexport function parseControlValue<T>(value: string, schema: Schema): T | undefined {\n const schemaType = schema.type;\n\n switch (schemaType) {\n case 'string':\n return value as T;\n case 'number':\n return parseFloat(value) as T;\n case 'boolean':\n return (!!value || value === 'true') as T;\n case 'array':\n case 'object':\n return JSON.parse(value) as T;\n case 'enum':\n return (schema.enum.includes(value) ? value : undefined) as T;\n default: {\n const _exhaustiveCheck: never = schemaType;\n return undefined;\n }\n }\n}\n"],"mappings":";;AAMA,SAAgB,EAAoB,GAAyB,GAAe,GAAmB;CAC7F,IAAM,IAAc,EAAkB,GAAO,CAAM;CACnD,IAAI,MAAgB,KAAA,GAClB,MAAM,IAAI,EAAiB,GAAiB,0BAA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F"}
|
package/dist/internal/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type FormControlValue = string | number | File | File[] | null | object;
|
|
1
|
+
export type FormControlValue = string | number | boolean | File | File[] | FormData | null | object;
|
|
2
2
|
interface SchemaBase {
|
|
3
3
|
type: string;
|
|
4
4
|
description?: string;
|
|
@@ -44,17 +44,31 @@ export interface FormControlMetadata {
|
|
|
44
44
|
strict?: boolean;
|
|
45
45
|
}
|
|
46
46
|
interface FormControlInstance extends HTMLElement {
|
|
47
|
-
value:
|
|
47
|
+
value: FormControlValue | undefined;
|
|
48
|
+
defaultValue: string;
|
|
48
49
|
form: HTMLFormElement | null;
|
|
49
|
-
|
|
50
|
+
readOnly: boolean;
|
|
51
|
+
disabled: boolean;
|
|
50
52
|
name: string;
|
|
51
53
|
noValidate: boolean;
|
|
52
54
|
willValidate: boolean;
|
|
53
55
|
validity: ValidityState;
|
|
54
56
|
validationMessage: string;
|
|
55
|
-
required
|
|
57
|
+
required: boolean;
|
|
58
|
+
pattern: string;
|
|
59
|
+
min: number | null;
|
|
60
|
+
max: number | null;
|
|
61
|
+
step: number | null;
|
|
62
|
+
minLength: number;
|
|
63
|
+
maxLength: number;
|
|
64
|
+
labels: NodeList;
|
|
65
|
+
composedLabel: string;
|
|
66
|
+
valueAsString: string;
|
|
67
|
+
valueAsNumber: number;
|
|
56
68
|
checkValidity(): boolean;
|
|
57
69
|
reportValidity(): boolean;
|
|
70
|
+
reset(): void;
|
|
71
|
+
setCustomValidity(message: string): void;
|
|
58
72
|
}
|
|
59
73
|
/**
|
|
60
74
|
* @event input - Dispatched when the input value changes
|
package/dist/internal/utils.d.ts
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
1
|
export declare function isObjectLiteral(item: unknown): boolean;
|
|
2
|
+
export declare function attachInternals(element: HTMLElement & {
|
|
3
|
+
_internals?: ElementInternals;
|
|
4
|
+
}): ElementInternals;
|
|
5
|
+
export declare function toggleState(internals: ElementInternals, state: string, force: boolean): void;
|
|
6
|
+
export type PopoverAnchorElement = HTMLElement & {
|
|
7
|
+
anchor?: HTMLElement | string;
|
|
8
|
+
_activeTrigger?: HTMLElement;
|
|
9
|
+
};
|
|
10
|
+
export declare function getFlattenedDOMTree(node: Node, depth?: number): HTMLElement[];
|
|
11
|
+
export declare function getHostAnchor(host: PopoverAnchorElement): HTMLElement;
|
|
12
|
+
export declare function getStringValue(value: unknown): string | null;
|
|
13
|
+
export declare function hasAttributeValue(element: HTMLElement, attribute: string, value: string | null): boolean;
|
|
14
|
+
export declare function isFormElement(value: unknown): value is HTMLFormElement;
|
|
15
|
+
export declare function onKeys(events: string[], event: KeyboardEvent, callback: () => void): void;
|
|
16
|
+
export declare function removeEmptyTextNode(node: Node): void;
|
|
17
|
+
export declare function setAttributeValue(element: HTMLElement, attribute: string, value: string | null): void;
|
|
18
|
+
export declare function stopEvent(event: Event): void;
|
package/dist/internal/utils.js
CHANGED
|
@@ -4,7 +4,59 @@ function e(e) {
|
|
|
4
4
|
let t = Object.getPrototypeOf(e);
|
|
5
5
|
return t === null || t === Object.prototype;
|
|
6
6
|
}
|
|
7
|
+
function t(e) {
|
|
8
|
+
return e._internals === void 0 && (e._internals = e.attachInternals()), e._internals;
|
|
9
|
+
}
|
|
10
|
+
function n(e, t, n) {
|
|
11
|
+
n ? e.states.add(t) : e.states.delete(t);
|
|
12
|
+
}
|
|
13
|
+
function r(e, t = 10) {
|
|
14
|
+
return Array.from(f(e)).reduce((e, n) => [...e, [n, [...Array.from(f(n)).map((e) => [e, r(e, t)])]]], []).flat(t);
|
|
15
|
+
}
|
|
16
|
+
function i(e) {
|
|
17
|
+
let t = e.anchor ?? e._activeTrigger;
|
|
18
|
+
return typeof t == "string" && t.length ? e.parentNode ? r(e.parentNode).find((e) => e.id === t) ?? globalThis.document.body : globalThis.document.body : t instanceof HTMLElement && t !== globalThis.document.body ? t : globalThis.document.body;
|
|
19
|
+
}
|
|
20
|
+
function a(e) {
|
|
21
|
+
return typeof e == "string" && e.length ? e : e === "" ? "" : null;
|
|
22
|
+
}
|
|
23
|
+
function o(e, t, n) {
|
|
24
|
+
return n === null ? !e.hasAttribute(t) : e.getAttribute(t) === n;
|
|
25
|
+
}
|
|
26
|
+
function s(e) {
|
|
27
|
+
return typeof HTMLFormElement < "u" && e instanceof HTMLFormElement;
|
|
28
|
+
}
|
|
29
|
+
function c(e, t, n) {
|
|
30
|
+
e.includes(t.code) && n();
|
|
31
|
+
}
|
|
32
|
+
function l(e) {
|
|
33
|
+
e?.wholeText?.trim() === "" && e.parentNode?.removeChild(e);
|
|
34
|
+
}
|
|
35
|
+
function u(e, t, n) {
|
|
36
|
+
n === null ? e.removeAttribute(t) : e.setAttribute(t, n);
|
|
37
|
+
}
|
|
38
|
+
function d(e) {
|
|
39
|
+
e.preventDefault(), e.stopPropagation();
|
|
40
|
+
}
|
|
41
|
+
function f(e) {
|
|
42
|
+
if (p(e)) return Array.from(e.documentElement.children);
|
|
43
|
+
if (m(e)) return Array.from(e.shadowRoot.children);
|
|
44
|
+
if (h(e)) {
|
|
45
|
+
let t = e.assignedElements();
|
|
46
|
+
return t.length ? t : Array.from(e.children);
|
|
47
|
+
}
|
|
48
|
+
return Array.from(e.children ?? []);
|
|
49
|
+
}
|
|
50
|
+
function p(e) {
|
|
51
|
+
return typeof Document < "u" && e instanceof Document && !!e.documentElement;
|
|
52
|
+
}
|
|
53
|
+
function m(e) {
|
|
54
|
+
return typeof HTMLElement < "u" && e instanceof HTMLElement && !!e.shadowRoot;
|
|
55
|
+
}
|
|
56
|
+
function h(e) {
|
|
57
|
+
return typeof HTMLSlotElement < "u" && e instanceof HTMLSlotElement && !!e.assignedElements;
|
|
58
|
+
}
|
|
7
59
|
//#endregion
|
|
8
|
-
export { e as isObjectLiteral };
|
|
60
|
+
export { t as attachInternals, r as getFlattenedDOMTree, i as getHostAnchor, a as getStringValue, o as hasAttributeValue, s as isFormElement, e as isObjectLiteral, c as onKeys, l as removeEmptyTextNode, u as setAttributeValue, d as stopEvent, n as toggleState };
|
|
9
61
|
|
|
10
62
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../src/internal/utils.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nexport function isObjectLiteral(item: unknown) {\n if (!item || typeof item !== 'object' || Array.isArray(item)) {\n return false;\n }\n const proto = Object.getPrototypeOf(item);\n return proto === null || proto === Object.prototype;\n}\n"],"mappings":";AAGA,SAAgB,EAAgB,GAAe;CAC7C,IAAI,CAAC,KAAQ,OAAO,KAAS,YAAY,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/internal/utils.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nexport function isObjectLiteral(item: unknown) {\n if (!item || typeof item !== 'object' || Array.isArray(item)) {\n return false;\n }\n const proto = Object.getPrototypeOf(item);\n return proto === null || proto === Object.prototype;\n}\n\nexport function attachInternals(element: HTMLElement & { _internals?: ElementInternals }) {\n if (element._internals === undefined) {\n element._internals = element.attachInternals() as unknown as ElementInternals;\n }\n\n return element._internals;\n}\n\nexport function toggleState(internals: ElementInternals, state: string, force: boolean) {\n if (force) {\n internals.states.add(state);\n } else {\n internals.states.delete(state);\n }\n}\n\nexport type PopoverAnchorElement = HTMLElement & { anchor?: HTMLElement | string; _activeTrigger?: HTMLElement };\n\nexport function getFlattenedDOMTree(node: Node, depth = 10): HTMLElement[] {\n return (\n Array.from(getChildren(node)).reduce(\n (p: unknown[], n: Node) => [\n ...p,\n [n, [...Array.from(getChildren(n)).map(i => [i, getFlattenedDOMTree(i, depth)])]]\n ],\n []\n ) as unknown as HTMLElement[]\n ).flat(depth);\n}\n\nexport function getHostAnchor(host: PopoverAnchorElement) {\n const anchor = host.anchor ?? host._activeTrigger;\n\n if (typeof anchor === 'string' && anchor.length) {\n if (!host.parentNode) {\n return globalThis.document.body;\n }\n\n return (\n getFlattenedDOMTree(host.parentNode as Node).find(element => element.id === anchor) ?? globalThis.document.body\n );\n }\n\n if (anchor instanceof HTMLElement && anchor !== globalThis.document.body) {\n return anchor;\n }\n\n return globalThis.document.body;\n}\n\nexport function getStringValue(value: unknown) {\n if (typeof value === 'string' && value.length) {\n return value;\n }\n\n return value === '' ? '' : null;\n}\n\nexport function hasAttributeValue(element: HTMLElement, attribute: string, value: string | null) {\n return value === null ? !element.hasAttribute(attribute) : element.getAttribute(attribute) === value;\n}\n\nexport function isFormElement(value: unknown): value is HTMLFormElement {\n return typeof HTMLFormElement !== 'undefined' && value instanceof HTMLFormElement;\n}\n\nexport function onKeys(events: string[], event: KeyboardEvent, callback: () => void) {\n if (events.includes(event.code)) {\n callback();\n }\n}\n\nexport function removeEmptyTextNode(node: Node) {\n if ((node as Text)?.wholeText?.trim() === '') {\n node.parentNode?.removeChild(node);\n }\n}\n\nexport function setAttributeValue(element: HTMLElement, attribute: string, value: string | null) {\n if (value === null) {\n element.removeAttribute(attribute);\n } else {\n element.setAttribute(attribute, value);\n }\n}\n\nexport function stopEvent(event: Event) {\n event.preventDefault();\n event.stopPropagation();\n}\n\nfunction getChildren(node: Node): Element[] {\n if (isDocumentNode(node)) {\n return Array.from(node.documentElement.children);\n }\n\n if (isElementWithShadowRoot(node)) {\n return Array.from(node.shadowRoot.children);\n }\n\n if (isSlotElement(node)) {\n const slotted = node.assignedElements();\n return slotted.length ? slotted : Array.from(node.children);\n }\n\n return Array.from((node as HTMLElement).children ?? []);\n}\n\nfunction isDocumentNode(node: Node): node is Document {\n return typeof Document !== 'undefined' && node instanceof Document && Boolean(node.documentElement);\n}\n\nfunction isElementWithShadowRoot(node: Node): node is HTMLElement & { shadowRoot: ShadowRoot } {\n return typeof HTMLElement !== 'undefined' && node instanceof HTMLElement && Boolean(node.shadowRoot);\n}\n\nfunction isSlotElement(node: Node): node is HTMLSlotElement {\n return typeof HTMLSlotElement !== 'undefined' && node instanceof HTMLSlotElement && Boolean(node.assignedElements);\n}\n"],"mappings":";AAGA,SAAgB,EAAgB,GAAe;CAC7C,IAAI,CAAC,KAAQ,OAAO,KAAS,YAAY,MAAM,QAAQ,CAAI,GACzD,OAAO;CAET,IAAM,IAAQ,OAAO,eAAe,CAAI;CACxC,OAAO,MAAU,QAAQ,MAAU,OAAO;AAC5C;AAEA,SAAgB,EAAgB,GAA0D;CAKxF,OAJI,EAAQ,eAAe,KAAA,MACzB,EAAQ,aAAa,EAAQ,gBAAgB,IAGxC,EAAQ;AACjB;AAEA,SAAgB,EAAY,GAA6B,GAAe,GAAgB;CACtF,AAAI,IACF,EAAU,OAAO,IAAI,CAAK,IAE1B,EAAU,OAAO,OAAO,CAAK;AAEjC;AAIA,SAAgB,EAAoB,GAAY,IAAQ,IAAmB;CACzE,OACE,MAAM,KAAK,EAAY,CAAI,CAAC,EAAE,QAC3B,GAAc,MAAY,CACzB,GAAG,GACH,CAAC,GAAG,CAAC,GAAG,MAAM,KAAK,EAAY,CAAC,CAAC,EAAE,KAAI,MAAK,CAAC,GAAG,EAAoB,GAAG,CAAK,CAAC,CAAC,CAAC,CAAC,CAClF,GACA,CAAC,CACH,EACA,KAAK,CAAK;AACd;AAEA,SAAgB,EAAc,GAA4B;CACxD,IAAM,IAAS,EAAK,UAAU,EAAK;CAgBnC,OAdI,OAAO,KAAW,YAAY,EAAO,SAClC,EAAK,aAKR,EAAoB,EAAK,UAAkB,EAAE,MAAK,MAAW,EAAQ,OAAO,CAAM,KAAK,WAAW,SAAS,OAJpG,WAAW,SAAS,OAQ3B,aAAkB,eAAe,MAAW,WAAW,SAAS,OAC3D,IAGF,WAAW,SAAS;AAC7B;AAEA,SAAgB,EAAe,GAAgB;CAK7C,OAJI,OAAO,KAAU,YAAY,EAAM,SAC9B,IAGF,MAAU,KA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EAAK;AACnG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ButtonFormControlMixinInstance } from './button.types.js';
|
|
2
|
+
export type { ButtonFormControlMixinInstance, ButtonType, CurrentState, PopoverTargetAction } from './button.types.js';
|
|
3
|
+
interface ButtonFormControlHost {
|
|
4
|
+
connectedCallback?(): void;
|
|
5
|
+
disconnectedCallback?(): void;
|
|
6
|
+
attributeChangedCallback?(name: string, oldValue: string | null, newValue: string | null): void;
|
|
7
|
+
requestUpdate?(name?: string, oldValue?: unknown): void;
|
|
8
|
+
updateComplete?: Promise<unknown>;
|
|
9
|
+
}
|
|
10
|
+
type Constructor = (new (...args: any[]) => HTMLElement & ButtonFormControlHost) & {
|
|
11
|
+
observedAttributes?: string[];
|
|
12
|
+
};
|
|
13
|
+
type ButtonFormControlConstructor<TBase extends Constructor> = new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> & ButtonFormControlMixinInstance;
|
|
14
|
+
export type ButtonFormControlMixinReturn<TBase extends Constructor> = ButtonFormControlConstructor<TBase> & {
|
|
15
|
+
formAssociated: boolean;
|
|
16
|
+
observedAttributes: string[];
|
|
17
|
+
} & Omit<TBase, 'prototype'>;
|
|
18
|
+
/**
|
|
19
|
+
* @description A mixin that adds native button-style form, command, popover, and interaction behavior.
|
|
20
|
+
* @aria https://www.w3.org/WAI/ARIA/apg/patterns/button/
|
|
21
|
+
*/
|
|
22
|
+
export declare function ButtonFormControlMixin<TBase extends Constructor>(SuperClass: TBase): ButtonFormControlMixinReturn<TBase>;
|