@solid-design-system/components 1.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.
Files changed (119) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +15 -0
  3. package/dist/components/es/button.js +125 -0
  4. package/dist/components/es/classix.js +1 -0
  5. package/dist/components/es/component.styles.js +1 -0
  6. package/dist/components/es/icon.js +17 -0
  7. package/dist/components/es/if-defined.js +11 -0
  8. package/dist/components/es/include.js +1 -0
  9. package/dist/components/es/include.styles.js +1 -0
  10. package/dist/components/es/library.js +1 -0
  11. package/dist/components/es/library.system.js +1 -0
  12. package/dist/components/es/link.js +1 -0
  13. package/dist/components/es/lit-element.js +23 -0
  14. package/dist/components/es/request.js +1 -0
  15. package/dist/components/es/request2.js +1 -0
  16. package/dist/components/es/solid-components.js +1 -0
  17. package/dist/components/es/solid-element.js +21 -0
  18. package/dist/components/es/spinner.js +1 -0
  19. package/dist/components/es/state.js +6 -0
  20. package/dist/components/es/watch.js +1 -0
  21. package/dist/components/umd/solid-components.js +200 -0
  22. package/dist/custom-elements.json +1 -0
  23. package/dist/package/components/button/button.d.ts +48 -0
  24. package/dist/package/components/button/button.js +391 -0
  25. package/dist/package/components/icon/icon.d.ts +22 -0
  26. package/dist/package/components/icon/icon.js +129 -0
  27. package/dist/package/components/icon/library.d.ts +16 -0
  28. package/dist/package/components/icon/library.js +17 -0
  29. package/dist/package/components/icon/library.system.d.ts +7 -0
  30. package/dist/package/components/icon/library.system.js +26 -0
  31. package/dist/package/components/icon/request.d.ts +11 -0
  32. package/dist/package/components/icon/request.js +24 -0
  33. package/dist/package/components/include/include.d.ts +16 -0
  34. package/dist/package/components/include/include.js +72 -0
  35. package/dist/package/components/include/include.styles.d.ts +2 -0
  36. package/dist/package/components/include/include.styles.js +6 -0
  37. package/dist/package/components/include/request.d.ts +7 -0
  38. package/dist/package/components/include/request.js +18 -0
  39. package/dist/package/components/link/link.d.ts +22 -0
  40. package/dist/package/components/link/link.js +107 -0
  41. package/dist/package/components/spinner/spinner.d.ts +12 -0
  42. package/dist/package/components/spinner/spinner.js +46 -0
  43. package/dist/package/internal/form.d.ts +35 -0
  44. package/dist/package/internal/form.js +212 -0
  45. package/dist/package/internal/slot.d.ts +14 -0
  46. package/dist/package/internal/slot.js +47 -0
  47. package/dist/package/internal/solid-element.d.ts +26 -0
  48. package/dist/package/internal/solid-element.js +38 -0
  49. package/dist/package/internal/watch.d.ts +11 -0
  50. package/dist/package/internal/watch.js +28 -0
  51. package/dist/package/node_modules/.pnpm/@shoelace-style_localize@3.1.0/node_modules/@shoelace-style/localize/dist/index.js +103 -0
  52. package/dist/package/solid-components.d.ts +6 -0
  53. package/dist/package/solid-components.js +14 -0
  54. package/dist/package/styles/component.styles.d.ts +2 -0
  55. package/dist/package/styles/component.styles.js +5 -0
  56. package/dist/package/styles/tailwind.css.js +4 -0
  57. package/dist/package/translations/en.d.ts +3 -0
  58. package/dist/package/translations/en.js +31 -0
  59. package/dist/package/utilities/localize.d.ts +25 -0
  60. package/dist/package/utilities/localize.js +7 -0
  61. package/dist/versioned-components/es/button.js +125 -0
  62. package/dist/versioned-components/es/classix.js +1 -0
  63. package/dist/versioned-components/es/component.styles.js +1 -0
  64. package/dist/versioned-components/es/icon.js +17 -0
  65. package/dist/versioned-components/es/if-defined.js +11 -0
  66. package/dist/versioned-components/es/include.js +1 -0
  67. package/dist/versioned-components/es/include.styles.js +1 -0
  68. package/dist/versioned-components/es/library.js +1 -0
  69. package/dist/versioned-components/es/library.system.js +1 -0
  70. package/dist/versioned-components/es/link.js +1 -0
  71. package/dist/versioned-components/es/lit-element.js +23 -0
  72. package/dist/versioned-components/es/request.js +1 -0
  73. package/dist/versioned-components/es/request2.js +1 -0
  74. package/dist/versioned-components/es/solid-components.js +1 -0
  75. package/dist/versioned-components/es/solid-element.js +21 -0
  76. package/dist/versioned-components/es/spinner.js +1 -0
  77. package/dist/versioned-components/es/state.js +6 -0
  78. package/dist/versioned-components/es/watch.js +1 -0
  79. package/dist/versioned-package/components/button/button.d.ts +48 -0
  80. package/dist/versioned-package/components/button/button.js +391 -0
  81. package/dist/versioned-package/components/icon/icon.d.ts +22 -0
  82. package/dist/versioned-package/components/icon/icon.js +129 -0
  83. package/dist/versioned-package/components/icon/library.d.ts +16 -0
  84. package/dist/versioned-package/components/icon/library.js +17 -0
  85. package/dist/versioned-package/components/icon/library.system.d.ts +7 -0
  86. package/dist/versioned-package/components/icon/library.system.js +26 -0
  87. package/dist/versioned-package/components/icon/request.d.ts +11 -0
  88. package/dist/versioned-package/components/icon/request.js +24 -0
  89. package/dist/versioned-package/components/include/include.d.ts +16 -0
  90. package/dist/versioned-package/components/include/include.js +72 -0
  91. package/dist/versioned-package/components/include/include.styles.d.ts +2 -0
  92. package/dist/versioned-package/components/include/include.styles.js +6 -0
  93. package/dist/versioned-package/components/include/request.d.ts +7 -0
  94. package/dist/versioned-package/components/include/request.js +18 -0
  95. package/dist/versioned-package/components/link/link.d.ts +22 -0
  96. package/dist/versioned-package/components/link/link.js +107 -0
  97. package/dist/versioned-package/components/spinner/spinner.d.ts +12 -0
  98. package/dist/versioned-package/components/spinner/spinner.js +46 -0
  99. package/dist/versioned-package/internal/form.d.ts +35 -0
  100. package/dist/versioned-package/internal/form.js +212 -0
  101. package/dist/versioned-package/internal/slot.d.ts +14 -0
  102. package/dist/versioned-package/internal/slot.js +47 -0
  103. package/dist/versioned-package/internal/solid-element.d.ts +26 -0
  104. package/dist/versioned-package/internal/solid-element.js +38 -0
  105. package/dist/versioned-package/internal/watch.d.ts +11 -0
  106. package/dist/versioned-package/internal/watch.js +28 -0
  107. package/dist/versioned-package/node_modules/.pnpm/@shoelace-style_localize@3.1.0/node_modules/@shoelace-style/localize/dist/index.js +103 -0
  108. package/dist/versioned-package/solid-components.d.ts +6 -0
  109. package/dist/versioned-package/solid-components.js +14 -0
  110. package/dist/versioned-package/styles/component.styles.d.ts +2 -0
  111. package/dist/versioned-package/styles/component.styles.js +5 -0
  112. package/dist/versioned-package/styles/tailwind.css.js +4 -0
  113. package/dist/versioned-package/translations/en.d.ts +3 -0
  114. package/dist/versioned-package/translations/en.js +31 -0
  115. package/dist/versioned-package/utilities/localize.d.ts +25 -0
  116. package/dist/versioned-package/utilities/localize.js +7 -0
  117. package/dist/vscode.html-custom-data.json +661 -0
  118. package/dist/web-types.json +1449 -0
  119. package/package.json +185 -0
@@ -0,0 +1,72 @@
1
+ import { property, customElement } from "lit/decorators.js";
2
+ import { html } from "lit";
3
+ import { requestInclude } from "./request.js";
4
+ import { watch } from "../../internal/watch.js";
5
+ import SolidElement from "../../internal/solid-element.js";
6
+ import styles from "./include.styles.js";
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __decorateClass = (decorators, target, key, kind) => {
10
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
11
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
12
+ if (decorator = decorators[i])
13
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
14
+ if (kind && result)
15
+ __defProp(target, key, result);
16
+ return result;
17
+ };
18
+ let SdInclude = class extends SolidElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.mode = "cors";
22
+ this.allowScripts = false;
23
+ }
24
+ executeScript(script) {
25
+ const newScript = document.createElement("script");
26
+ [...script.attributes].forEach((attr) => newScript.setAttribute(attr.name, attr.value));
27
+ newScript.textContent = script.textContent;
28
+ script.parentNode.replaceChild(newScript, script);
29
+ }
30
+ async handleSrcChange() {
31
+ try {
32
+ const src = this.src;
33
+ const file = await requestInclude(src, this.mode);
34
+ if (src !== this.src) {
35
+ return;
36
+ }
37
+ if (!file.ok) {
38
+ this.emit("sd-error", { detail: { status: file.status } });
39
+ return;
40
+ }
41
+ this.innerHTML = file.html;
42
+ if (this.allowScripts) {
43
+ [...this.querySelectorAll("script")].forEach((script) => this.executeScript(script));
44
+ }
45
+ this.emit("sd-load");
46
+ } catch {
47
+ this.emit("sd-error", { detail: { status: -1 } });
48
+ }
49
+ }
50
+ render() {
51
+ return html`<slot></slot>`;
52
+ }
53
+ };
54
+ SdInclude.styles = styles;
55
+ __decorateClass([
56
+ property()
57
+ ], SdInclude.prototype, "src", 2);
58
+ __decorateClass([
59
+ property()
60
+ ], SdInclude.prototype, "mode", 2);
61
+ __decorateClass([
62
+ property({ attribute: "allow-scripts", type: Boolean })
63
+ ], SdInclude.prototype, "allowScripts", 2);
64
+ __decorateClass([
65
+ watch("src")
66
+ ], SdInclude.prototype, "handleSrcChange", 1);
67
+ SdInclude = __decorateClass([
68
+ customElement("sd-include")
69
+ ], SdInclude);
70
+ export {
71
+ SdInclude as default
72
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("lit").CSSResult;
2
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import { css } from "lit";
2
+ import componentStyles from "../../styles/component.styles.js";
3
+ const styles = css`${componentStyles}:host{display:block}`;
4
+ export {
5
+ styles as default
6
+ };
@@ -0,0 +1,7 @@
1
+ interface IncludeFile {
2
+ ok: boolean;
3
+ status: number;
4
+ html: string;
5
+ }
6
+ export declare function requestInclude(src: string, mode?: 'cors' | 'no-cors' | 'same-origin'): Promise<IncludeFile>;
7
+ export {};
@@ -0,0 +1,18 @@
1
+ const includeFiles = /* @__PURE__ */ new Map();
2
+ function requestInclude(src, mode = "cors") {
3
+ if (includeFiles.has(src)) {
4
+ return includeFiles.get(src);
5
+ }
6
+ const fileDataPromise = fetch(src, { mode }).then(async (response) => {
7
+ return {
8
+ ok: response.ok,
9
+ status: response.status,
10
+ html: await response.text()
11
+ };
12
+ });
13
+ includeFiles.set(src, fileDataPromise);
14
+ return fileDataPromise;
15
+ }
16
+ export {
17
+ requestInclude
18
+ };
@@ -0,0 +1,22 @@
1
+ import SolidElement from '../../internal/solid-element';
2
+ export default class SdLink extends SolidElement {
3
+ private readonly hasSlotController;
4
+ button: HTMLButtonElement | HTMLLinkElement;
5
+ size: 'inherit' | 'lg' | 'sm';
6
+ inverted: boolean;
7
+ standalone: boolean;
8
+ href: string;
9
+ target: '_blank' | '_parent' | '_self' | '_top';
10
+ download?: string;
11
+ private handleBlur;
12
+ private handleFocus;
13
+ focus(options?: FocusOptions): void;
14
+ blur(): void;
15
+ render(): import("lit").TemplateResult<1>;
16
+ static styles: import("lit").CSSResultGroup[];
17
+ }
18
+ declare global {
19
+ interface HTMLElementTagNameMap {
20
+ 'sd-link': SdLink;
21
+ }
22
+ }
@@ -0,0 +1,107 @@
1
+ import { css, html } from "lit";
2
+ import { query, property, customElement } from "lit/decorators.js";
3
+ import { HasSlotController } from "../../internal/slot.js";
4
+ import { ifDefined } from "lit/directives/if-defined.js";
5
+ import cx from "classix";
6
+ import SolidElement from "../../internal/solid-element.js";
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __decorateClass = (decorators, target, key, kind) => {
10
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
11
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
12
+ if (decorator = decorators[i])
13
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
14
+ if (kind && result)
15
+ __defProp(target, key, result);
16
+ return result;
17
+ };
18
+ let SdLink = class extends SolidElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.hasSlotController = new HasSlotController(this, "[default]", "icon-left", "icon-right");
22
+ this.size = "inherit";
23
+ this.inverted = false;
24
+ this.standalone = false;
25
+ this.href = "";
26
+ }
27
+ handleBlur() {
28
+ this.emit("sd-blur");
29
+ }
30
+ handleFocus() {
31
+ this.emit("sd-focus");
32
+ }
33
+ /** Sets focus on the button. */
34
+ focus(options) {
35
+ this.button.focus(options);
36
+ }
37
+ /** Removes focus from the button. */
38
+ blur() {
39
+ this.button.blur();
40
+ }
41
+ render() {
42
+ const slots = {
43
+ label: this.hasSlotController.test("[default]"),
44
+ "icon-left": this.hasSlotController.test("icon-left"),
45
+ "icon-right": this.hasSlotController.test("icon-right")
46
+ };
47
+ return html`<a part="base" class="${cx(
48
+ "inline",
49
+ this.href ? "cursor-pointer" : "",
50
+ {
51
+ sm: "text-sm",
52
+ lg: "text-base",
53
+ inherit: ""
54
+ }[this.size],
55
+ {
56
+ disabled: !this.inverted ? "text-neutral-500" : "text-neutral-600",
57
+ enabled: !this.inverted ? ` text-primary hover:text-primary-500 active:text-primary-800 focus-visible:focus-outline` : `text-white hover:text-primary-200 active:text-primary-400 focus-visible:focus-outline-inverted`
58
+ }[this.href ? "enabled" : "disabled"],
59
+ this.standalone && "flex items-start"
60
+ )}" href="${ifDefined(this.href || void 0)}" target="${ifDefined(this.target || void 0)}" download="${ifDefined(this.download || void 0)}" rel="${ifDefined(this.target ? "noreferrer noopener" : void 0)}" aria-disabled="${!this.href ? "true" : "false"}" tabindex="${!this.href ? "-1" : "0"}" @blur="${this.handleBlur}" @focus="${this.handleFocus}"><slot name="icon-left" part="icon-left" class="${cx(
61
+ "inline",
62
+ slots["icon-left"] && (!this.standalone ? "mr-[0.25em]" : {
63
+ sm: "mr-1",
64
+ lg: "mr-2",
65
+ inherit: "mr-[0.5em]"
66
+ }[this.size])
67
+ )}"></slot><span part="label" class="inline underline underline-offset-2"><slot></slot></span><slot name="icon-right" part="icon-right" class="${cx(
68
+ "inline",
69
+ slots["icon-right"] && (!this.standalone ? "ml-[0.25em]" : {
70
+ sm: "ml-1",
71
+ lg: "ml-2",
72
+ inherit: "ml-[0.5em]"
73
+ }[this.size])
74
+ )}"></slot></a>`;
75
+ }
76
+ };
77
+ SdLink.styles = [
78
+ SolidElement.styles,
79
+ css`::slotted(sd-icon){font-size:1.25em;margin-bottom:-.25em}:host([size=sm][standalone]) ::slotted(sd-icon){font-size:1rem}:host([size=lg][standalone]) ::slotted(sd-icon){font-size:1.5rem}`
80
+ ];
81
+ __decorateClass([
82
+ query("a")
83
+ ], SdLink.prototype, "button", 2);
84
+ __decorateClass([
85
+ property({ reflect: true })
86
+ ], SdLink.prototype, "size", 2);
87
+ __decorateClass([
88
+ property({ type: Boolean, reflect: true })
89
+ ], SdLink.prototype, "inverted", 2);
90
+ __decorateClass([
91
+ property({ type: Boolean, reflect: true })
92
+ ], SdLink.prototype, "standalone", 2);
93
+ __decorateClass([
94
+ property()
95
+ ], SdLink.prototype, "href", 2);
96
+ __decorateClass([
97
+ property()
98
+ ], SdLink.prototype, "target", 2);
99
+ __decorateClass([
100
+ property()
101
+ ], SdLink.prototype, "download", 2);
102
+ SdLink = __decorateClass([
103
+ customElement("sd-link")
104
+ ], SdLink);
105
+ export {
106
+ SdLink as default
107
+ };
@@ -0,0 +1,12 @@
1
+ import SolidElement from '../../internal/solid-element';
2
+ export default class SdSpinner extends SolidElement {
3
+ color: 'primary' | 'white' | 'currentColor';
4
+ private readonly localize;
5
+ render(): import("lit").TemplateResult<1>;
6
+ static styles: import("lit").CSSResultGroup[];
7
+ }
8
+ declare global {
9
+ interface HTMLElementTagNameMap {
10
+ 'sd-spinner': SdSpinner;
11
+ }
12
+ }
@@ -0,0 +1,46 @@
1
+ import { css, html } from "lit";
2
+ import { property, customElement } from "lit/decorators.js";
3
+ import { LocalizeController } from "../../utilities/localize.js";
4
+ import cx from "classix";
5
+ import SolidElement from "../../internal/solid-element.js";
6
+ var __defProp = Object.defineProperty;
7
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __decorateClass = (decorators, target, key, kind) => {
9
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
10
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
11
+ if (decorator = decorators[i])
12
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
13
+ if (kind && result)
14
+ __defProp(target, key, result);
15
+ return result;
16
+ };
17
+ let SdSpinner = class extends SolidElement {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.color = "currentColor";
21
+ this.localize = new LocalizeController(this);
22
+ }
23
+ render() {
24
+ return html`<svg role="progressbar" viewBox="0 0 24 24" class="${cx(
25
+ "animate-spin",
26
+ {
27
+ primary: "text-primary",
28
+ white: "text-white",
29
+ currentColor: ""
30
+ }[this.color]
31
+ )}" aria-valuetext="${this.localize.term("loading")}"><path fill-rule="evenodd" clip-rule="evenodd" d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22ZM24 12C24 18.6274 18.6274 24 12 24C5.37258 24 0 18.6274 0 12C0 5.37258 5.37258 0 12 0C18.6274 0 24 5.37258 24 12Z" class="opacity-20" fill="currentColor"/><mask id="mask0_5273_25391" style="mask-type:alpha" maskUnits="userSpaceOnUse"><path d="M24 12C24 5.37258 18.6274 0 12 0V12H24Z" fill="currentColor"/></mask><g mask="url(#mask0_5273_25391)"><path fill-rule="evenodd" clip-rule="evenodd" d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22ZM24 12C24 18.6274 18.6274 24 12 24C5.37258 24 0 18.6274 0 12C0 5.37258 5.37258 0 12 0C18.6274 0 24 5.37258 24 12Z" fill="currentColor"/></g></svg>`;
32
+ }
33
+ };
34
+ SdSpinner.styles = [
35
+ SolidElement.styles,
36
+ css`:host{display:inline-block;width:1em;height:1em}`
37
+ ];
38
+ __decorateClass([
39
+ property({ reflect: true })
40
+ ], SdSpinner.prototype, "color", 2);
41
+ SdSpinner = __decorateClass([
42
+ customElement("sd-spinner")
43
+ ], SdSpinner);
44
+ export {
45
+ SdSpinner as default
46
+ };
@@ -0,0 +1,35 @@
1
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ import type { SolidFormControl } from '../internal/solid-element';
3
+ import type SdButton from '../components/button/button';
4
+ export declare const formCollections: WeakMap<HTMLFormElement, Set<SolidFormControl>>;
5
+ export interface FormControlControllerOptions {
6
+ form: (input: SolidFormControl) => HTMLFormElement | null;
7
+ name: (input: SolidFormControl) => string;
8
+ value: (input: SolidFormControl) => unknown | unknown[];
9
+ defaultValue: (input: SolidFormControl) => unknown | unknown[];
10
+ disabled: (input: SolidFormControl) => boolean;
11
+ reportValidity: (input: SolidFormControl) => boolean;
12
+ setValue: (input: SolidFormControl, value: unknown) => void;
13
+ }
14
+ export declare class FormControlController implements ReactiveController {
15
+ host: SolidFormControl & ReactiveControllerHost;
16
+ form?: HTMLFormElement | null;
17
+ options: FormControlControllerOptions;
18
+ constructor(host: ReactiveControllerHost & SolidFormControl, options?: Partial<FormControlControllerOptions>);
19
+ hostConnected(): void;
20
+ hostDisconnected(): void;
21
+ hostUpdated(): void;
22
+ private attachForm;
23
+ private detachForm;
24
+ private handleFormData;
25
+ private handleFormSubmit;
26
+ private handleFormReset;
27
+ private handleUserInput;
28
+ private reportFormValidity;
29
+ private setUserInteracted;
30
+ private doAction;
31
+ reset(invoker?: HTMLInputElement | SdButton): void;
32
+ submit(invoker?: HTMLInputElement | SdButton): void;
33
+ setValidity(isValid: boolean): void;
34
+ updateValidity(): void;
35
+ }
@@ -0,0 +1,212 @@
1
+ const formCollections = /* @__PURE__ */ new WeakMap();
2
+ const userInteractedControls = /* @__PURE__ */ new WeakMap();
3
+ const reportValidityOverloads = /* @__PURE__ */ new WeakMap();
4
+ class FormControlController {
5
+ constructor(host, options) {
6
+ (this.host = host).addController(this);
7
+ this.options = {
8
+ form: (input) => {
9
+ if (input.hasAttribute("form") && input.getAttribute("form") !== "") {
10
+ const root = input.getRootNode();
11
+ const formId = input.getAttribute("form");
12
+ if (formId) {
13
+ return root.getElementById(formId);
14
+ }
15
+ }
16
+ return input.closest("form");
17
+ },
18
+ name: (input) => input.name,
19
+ value: (input) => input.value,
20
+ defaultValue: (input) => input.defaultValue,
21
+ disabled: (input) => input.disabled ?? false,
22
+ reportValidity: (input) => typeof input.reportValidity === "function" ? input.reportValidity() : true,
23
+ setValue: (input, value) => input.value = value,
24
+ ...options
25
+ };
26
+ this.handleFormData = this.handleFormData.bind(this);
27
+ this.handleFormSubmit = this.handleFormSubmit.bind(this);
28
+ this.handleFormReset = this.handleFormReset.bind(this);
29
+ this.reportFormValidity = this.reportFormValidity.bind(this);
30
+ this.handleUserInput = this.handleUserInput.bind(this);
31
+ }
32
+ hostConnected() {
33
+ const form = this.options.form(this.host);
34
+ if (form) {
35
+ this.attachForm(form);
36
+ }
37
+ this.host.addEventListener("sd-input", this.handleUserInput);
38
+ }
39
+ hostDisconnected() {
40
+ this.detachForm();
41
+ this.host.removeEventListener("sd-input", this.handleUserInput);
42
+ }
43
+ hostUpdated() {
44
+ const form = this.options.form(this.host);
45
+ if (!form) {
46
+ this.detachForm();
47
+ }
48
+ if (form && this.form !== form) {
49
+ this.detachForm();
50
+ this.attachForm(form);
51
+ }
52
+ if (this.host.hasUpdated) {
53
+ this.setValidity(this.host.checkValidity());
54
+ }
55
+ }
56
+ attachForm(form) {
57
+ if (form) {
58
+ this.form = form;
59
+ if (formCollections.has(this.form)) {
60
+ formCollections.get(this.form).add(this.host);
61
+ } else {
62
+ formCollections.set(this.form, /* @__PURE__ */ new Set([this.host]));
63
+ }
64
+ this.form.addEventListener("formdata", this.handleFormData);
65
+ this.form.addEventListener("submit", this.handleFormSubmit);
66
+ this.form.addEventListener("reset", this.handleFormReset);
67
+ if (!reportValidityOverloads.has(this.form)) {
68
+ reportValidityOverloads.set(this.form, this.form.reportValidity);
69
+ this.form.reportValidity = () => this.reportFormValidity();
70
+ }
71
+ } else {
72
+ this.form = void 0;
73
+ }
74
+ }
75
+ detachForm() {
76
+ var _a;
77
+ if (this.form) {
78
+ (_a = formCollections.get(this.form)) == null ? void 0 : _a.delete(this.host);
79
+ this.form.removeEventListener("formdata", this.handleFormData);
80
+ this.form.removeEventListener("submit", this.handleFormSubmit);
81
+ this.form.removeEventListener("reset", this.handleFormReset);
82
+ if (reportValidityOverloads.has(this.form)) {
83
+ this.form.reportValidity = reportValidityOverloads.get(this.form);
84
+ reportValidityOverloads.delete(this.form);
85
+ }
86
+ }
87
+ this.form = void 0;
88
+ }
89
+ handleFormData(event) {
90
+ const disabled = this.options.disabled(this.host);
91
+ const name = this.options.name(this.host);
92
+ const value = this.options.value(this.host);
93
+ const isButton = this.host.tagName.toLowerCase() === "sd-button";
94
+ if (!disabled && !isButton && typeof name === "string" && name.length > 0 && typeof value !== "undefined") {
95
+ if (Array.isArray(value)) {
96
+ value.forEach((val) => {
97
+ event.formData.append(name, val.toString());
98
+ });
99
+ } else {
100
+ event.formData.append(name, value.toString());
101
+ }
102
+ }
103
+ }
104
+ handleFormSubmit(event) {
105
+ var _a;
106
+ const disabled = this.options.disabled(this.host);
107
+ const reportValidity = this.options.reportValidity;
108
+ if (this.form && !this.form.noValidate) {
109
+ (_a = formCollections.get(this.form)) == null ? void 0 : _a.forEach((control) => {
110
+ this.setUserInteracted(control, true);
111
+ });
112
+ }
113
+ if (this.form && !this.form.noValidate && !disabled && !reportValidity(this.host)) {
114
+ event.preventDefault();
115
+ event.stopImmediatePropagation();
116
+ }
117
+ }
118
+ handleFormReset() {
119
+ this.options.setValue(this.host, this.options.defaultValue(this.host));
120
+ this.setUserInteracted(this.host, false);
121
+ }
122
+ async handleUserInput() {
123
+ await this.host.updateComplete;
124
+ this.setUserInteracted(this.host, true);
125
+ }
126
+ reportFormValidity() {
127
+ if (this.form && !this.form.noValidate) {
128
+ const elements = this.form.querySelectorAll("*");
129
+ for (const element of elements) {
130
+ if (typeof element.reportValidity === "function") {
131
+ if (!element.reportValidity()) {
132
+ return false;
133
+ }
134
+ }
135
+ }
136
+ }
137
+ return true;
138
+ }
139
+ setUserInteracted(el, hasInteracted) {
140
+ userInteractedControls.set(el, hasInteracted);
141
+ el.requestUpdate();
142
+ }
143
+ doAction(type, invoker) {
144
+ if (this.form) {
145
+ const button = document.createElement("button");
146
+ button.type = type;
147
+ button.style.position = "absolute";
148
+ button.style.width = "0";
149
+ button.style.height = "0";
150
+ button.style.clipPath = "inset(50%)";
151
+ button.style.overflow = "hidden";
152
+ button.style.whiteSpace = "nowrap";
153
+ if (invoker) {
154
+ button.name = invoker.name;
155
+ button.value = invoker.value;
156
+ ["formaction", "formenctype", "formmethod", "formnovalidate", "formtarget"].forEach((attr) => {
157
+ if (invoker.hasAttribute(attr)) {
158
+ button.setAttribute(attr, invoker.getAttribute(attr));
159
+ }
160
+ });
161
+ }
162
+ this.form.append(button);
163
+ button.click();
164
+ button.remove();
165
+ }
166
+ }
167
+ /** Resets the form, restoring all the control to their default value */
168
+ reset(invoker) {
169
+ this.doAction("reset", invoker);
170
+ }
171
+ /** Submits the form, triggering validation and form data injection. */
172
+ submit(invoker) {
173
+ this.doAction("submit", invoker);
174
+ }
175
+ /**
176
+ * Synchronously sets the form control's validity. Call this when you know the future validity but need to update
177
+ * the host element immediately, i.e. before Lit updates the component in the next update.
178
+ */
179
+ setValidity(isValid) {
180
+ var _a;
181
+ const host = this.host;
182
+ const hasInteracted = Boolean(userInteractedControls.get(host));
183
+ const required = Boolean(host.required);
184
+ if ((_a = this.form) == null ? void 0 : _a.noValidate) {
185
+ host.removeAttribute("data-required");
186
+ host.removeAttribute("data-optional");
187
+ host.removeAttribute("data-invalid");
188
+ host.removeAttribute("data-valid");
189
+ host.removeAttribute("data-user-invalid");
190
+ host.removeAttribute("data-user-valid");
191
+ } else {
192
+ host.toggleAttribute("data-required", required);
193
+ host.toggleAttribute("data-optional", !required);
194
+ host.toggleAttribute("data-invalid", !isValid);
195
+ host.toggleAttribute("data-valid", isValid);
196
+ host.toggleAttribute("data-user-invalid", !isValid && hasInteracted);
197
+ host.toggleAttribute("data-user-valid", isValid && hasInteracted);
198
+ }
199
+ }
200
+ /**
201
+ * Updates the form control's validity based on the current value of `host.checkValidity()`. Call this when anything
202
+ * that affects constraint validation changes so the component receives the correct validity states.
203
+ */
204
+ updateValidity() {
205
+ const host = this.host;
206
+ this.setValidity(host.checkValidity());
207
+ }
208
+ }
209
+ export {
210
+ FormControlController,
211
+ formCollections
212
+ };
@@ -0,0 +1,14 @@
1
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ export declare class HasSlotController implements ReactiveController {
3
+ host: ReactiveControllerHost & Element;
4
+ slotNames: string[];
5
+ constructor(host: ReactiveControllerHost & Element, ...slotNames: string[]);
6
+ private hasDefaultSlot;
7
+ private hasNamedSlot;
8
+ test(slotName: string): boolean;
9
+ hostConnected(): void;
10
+ hostDisconnected(): void;
11
+ handleSlotChange(event: Event): void;
12
+ }
13
+ export declare function getInnerHTML(slot: HTMLSlotElement): string;
14
+ export declare function getTextContent(slot: HTMLSlotElement | undefined | null): string;
@@ -0,0 +1,47 @@
1
+ class HasSlotController {
2
+ constructor(host, ...slotNames) {
3
+ this.slotNames = [];
4
+ (this.host = host).addController(this);
5
+ this.slotNames = slotNames;
6
+ this.handleSlotChange = this.handleSlotChange.bind(this);
7
+ }
8
+ hasDefaultSlot() {
9
+ return [...this.host.childNodes].some((node) => {
10
+ if (node.nodeType === node.TEXT_NODE && node.textContent.trim() !== "") {
11
+ return true;
12
+ }
13
+ if (node.nodeType === node.ELEMENT_NODE) {
14
+ const el = node;
15
+ const tagName = el.tagName.toLowerCase();
16
+ if (tagName === "sd-visually-hidden") {
17
+ return false;
18
+ }
19
+ if (!el.hasAttribute("slot")) {
20
+ return true;
21
+ }
22
+ }
23
+ return false;
24
+ });
25
+ }
26
+ hasNamedSlot(name) {
27
+ return this.host.querySelector(`:scope > [slot="${name}"]`) !== null;
28
+ }
29
+ test(slotName) {
30
+ return slotName === "[default]" ? this.hasDefaultSlot() : this.hasNamedSlot(slotName);
31
+ }
32
+ hostConnected() {
33
+ this.host.shadowRoot.addEventListener("slotchange", this.handleSlotChange);
34
+ }
35
+ hostDisconnected() {
36
+ this.host.shadowRoot.removeEventListener("slotchange", this.handleSlotChange);
37
+ }
38
+ handleSlotChange(event) {
39
+ const slot = event.target;
40
+ if (this.slotNames.includes("[default]") && !slot.name || slot.name && this.slotNames.includes(slot.name)) {
41
+ this.host.requestUpdate();
42
+ }
43
+ }
44
+ }
45
+ export {
46
+ HasSlotController
47
+ };
@@ -0,0 +1,26 @@
1
+ import { LitElement } from 'lit';
2
+ import type { CSSResultGroup } from 'lit';
3
+ export default class SolidElement extends LitElement {
4
+ dir: string;
5
+ lang: string;
6
+ static styles: CSSResultGroup;
7
+ emit(name: string, options?: CustomEventInit): CustomEvent<any>;
8
+ }
9
+ export interface SolidFormControl extends SolidElement {
10
+ name: string;
11
+ value: unknown;
12
+ disabled?: boolean;
13
+ defaultValue?: unknown;
14
+ defaultChecked?: boolean;
15
+ form?: string;
16
+ pattern?: string;
17
+ min?: number | Date;
18
+ max?: number | Date;
19
+ step?: number | 'any';
20
+ required?: boolean;
21
+ minlength?: number;
22
+ maxlength?: number;
23
+ checkValidity: () => boolean;
24
+ reportValidity: () => boolean;
25
+ setCustomValidity: (message: string) => void;
26
+ }
@@ -0,0 +1,38 @@
1
+ import { unsafeCSS, LitElement } from "lit";
2
+ import { property } from "lit/decorators.js";
3
+ import tailwind from "../styles/tailwind.css.js";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __decorateClass = (decorators, target, key, kind) => {
7
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
8
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
9
+ if (decorator = decorators[i])
10
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
11
+ if (kind && result)
12
+ __defProp(target, key, result);
13
+ return result;
14
+ };
15
+ class SolidElement extends LitElement {
16
+ /** Emits a custom event with more convenient defaults. */
17
+ emit(name, options) {
18
+ const event = new CustomEvent(name, {
19
+ bubbles: true,
20
+ cancelable: false,
21
+ composed: true,
22
+ detail: {},
23
+ ...options
24
+ });
25
+ this.dispatchEvent(event);
26
+ return event;
27
+ }
28
+ }
29
+ SolidElement.styles = unsafeCSS(tailwind);
30
+ __decorateClass([
31
+ property()
32
+ ], SolidElement.prototype, "dir", 2);
33
+ __decorateClass([
34
+ property()
35
+ ], SolidElement.prototype, "lang", 2);
36
+ export {
37
+ SolidElement as default
38
+ };