import { input_styles_default } from "./chunk.53DWOBDF.js"; import { l } from "./chunk.MB643KRE.js"; import { defaultValue } from "./chunk.RQ7JZ4R7.js"; import { FormControlController } from "./chunk.NMS6LWK4.js"; import { LocalizeController } from "./chunk.NH3SRVOC.js"; import { o } from "./chunk.2URMUHDY.js"; import { HasSlotController } from "./chunk.NYIIDP5N.js"; import { e } from "./chunk.UZVKBFXH.js"; import { SlIcon } from "./chunk.UZYAV5H6.js"; import { watch } from "./chunk.FA5RT4K4.js"; import { ShoelaceElement, e as e2, n, r } from "./chunk.SEXBCYCU.js"; import { x } from "./chunk.CXZZ2LVK.js"; import { __decorateClass } from "./chunk.KIILAQWQ.js"; // src/components/input/input.component.ts var SlInput = class extends ShoelaceElement { constructor() { super(...arguments); this.formControlController = new FormControlController(this, { assumeInteractionOn: ["sl-blur", "sl-input"] }); this.hasSlotController = new HasSlotController(this, "help-text", "label"); this.localize = new LocalizeController(this); this.hasFocus = false; this.title = ""; // make reactive to pass through this.__numberInput = Object.assign(document.createElement("input"), { type: "number" }); this.__dateInput = Object.assign(document.createElement("input"), { type: "date" }); this.type = "text"; this.name = ""; this.value = ""; this.defaultValue = ""; this.size = "medium"; this.filled = false; this.pill = false; this.label = ""; this.helpText = ""; this.clearable = false; this.disabled = false; this.placeholder = ""; this.readonly = false; this.passwordToggle = false; this.passwordVisible = false; this.noSpinButtons = false; this.form = ""; this.required = false; this.spellcheck = true; } // // NOTE: We use an in-memory input for these getters/setters instead of the one in the template because the properties // can be set before the component is rendered. // /** * Gets or sets the current value as a `Date` object. Returns `null` if the value can't be converted. This will use the native `` implementation and may result in an error. */ get valueAsDate() { var _a; this.__dateInput.type = this.type; this.__dateInput.value = this.value; return ((_a = this.input) == null ? void 0 : _a.valueAsDate) || this.__dateInput.valueAsDate; } set valueAsDate(newValue) { this.__dateInput.type = this.type; this.__dateInput.valueAsDate = newValue; this.value = this.__dateInput.value; } /** Gets or sets the current value as a number. Returns `NaN` if the value can't be converted. */ get valueAsNumber() { var _a; this.__numberInput.value = this.value; return ((_a = this.input) == null ? void 0 : _a.valueAsNumber) || this.__numberInput.valueAsNumber; } set valueAsNumber(newValue) { this.__numberInput.valueAsNumber = newValue; this.value = this.__numberInput.value; } /** Gets the validity state object */ get validity() { return this.input.validity; } /** Gets the validation message */ get validationMessage() { return this.input.validationMessage; } firstUpdated() { this.formControlController.updateValidity(); } handleBlur() { this.hasFocus = false; this.emit("sl-blur"); } handleChange() { this.value = this.input.value; this.emit("sl-change"); } handleClearClick(event) { this.value = ""; this.emit("sl-clear"); this.emit("sl-input"); this.emit("sl-change"); this.input.focus(); event.stopPropagation(); } handleFocus() { this.hasFocus = true; this.emit("sl-focus"); } handleInput() { this.value = this.input.value; this.formControlController.updateValidity(); this.emit("sl-input"); } handleInvalid(event) { this.formControlController.setValidity(false); this.formControlController.emitInvalidEvent(event); } handleKeyDown(event) { const hasModifier = event.metaKey || event.ctrlKey || event.shiftKey || event.altKey; if (event.key === "Enter" && !hasModifier) { setTimeout(() => { if (!event.defaultPrevented && !event.isComposing) { this.formControlController.submit(); } }); } } handlePasswordToggle() { this.passwordVisible = !this.passwordVisible; } handleDisabledChange() { this.formControlController.setValidity(this.disabled); } handleStepChange() { this.input.step = String(this.step); this.formControlController.updateValidity(); } async handleValueChange() { await this.updateComplete; this.formControlController.updateValidity(); } /** Sets focus on the input. */ focus(options) { this.input.focus(options); } /** Removes focus from the input. */ blur() { this.input.blur(); } /** Selects all the text in the input. */ select() { this.input.select(); } /** Sets the start and end positions of the text selection (0-based). */ setSelectionRange(selectionStart, selectionEnd, selectionDirection = "none") { this.input.setSelectionRange(selectionStart, selectionEnd, selectionDirection); } /** Replaces a range of text with a new string. */ setRangeText(replacement, start, end, selectMode = "preserve") { const selectionStart = start != null ? start : this.input.selectionStart; const selectionEnd = end != null ? end : this.input.selectionEnd; this.input.setRangeText(replacement, selectionStart, selectionEnd, selectMode); if (this.value !== this.input.value) { this.value = this.input.value; } } /** Displays the browser picker for an input element (only works if the browser supports it for the input type). */ showPicker() { if ("showPicker" in HTMLInputElement.prototype) { this.input.showPicker(); } } /** Increments the value of a numeric input type by the value of the step attribute. */ stepUp() { this.input.stepUp(); if (this.value !== this.input.value) { this.value = this.input.value; } } /** Decrements the value of a numeric input type by the value of the step attribute. */ stepDown() { this.input.stepDown(); if (this.value !== this.input.value) { this.value = this.input.value; } } /** Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid. */ checkValidity() { return this.input.checkValidity(); } /** Gets the associated form, if one exists. */ getForm() { return this.formControlController.getForm(); } /** Checks for validity and shows the browser's validation message if the control is invalid. */ reportValidity() { return this.input.reportValidity(); } /** Sets a custom validation message. Pass an empty string to restore validity. */ setCustomValidity(message) { this.input.setCustomValidity(message); this.formControlController.updateValidity(); } render() { const hasLabelSlot = this.hasSlotController.test("label"); const hasHelpTextSlot = this.hasSlotController.test("help-text"); const hasLabel = this.label ? true : !!hasLabelSlot; const hasHelpText = this.helpText ? true : !!hasHelpTextSlot; const hasClearIcon = this.clearable && !this.disabled && !this.readonly; const isClearIconVisible = hasClearIcon && (typeof this.value === "number" || this.value.length > 0); return x`
${hasClearIcon ? x` ` : ""} ${this.passwordToggle && !this.disabled ? x` ` : ""}
${this.helpText}
`; } }; SlInput.styles = input_styles_default; SlInput.dependencies = { "sl-icon": SlIcon }; __decorateClass([ e2(".input__control") ], SlInput.prototype, "input", 2); __decorateClass([ r() ], SlInput.prototype, "hasFocus", 2); __decorateClass([ n() ], SlInput.prototype, "title", 2); __decorateClass([ n({ reflect: true }) ], SlInput.prototype, "type", 2); __decorateClass([ n() ], SlInput.prototype, "name", 2); __decorateClass([ n() ], SlInput.prototype, "value", 2); __decorateClass([ defaultValue() ], SlInput.prototype, "defaultValue", 2); __decorateClass([ n({ reflect: true }) ], SlInput.prototype, "size", 2); __decorateClass([ n({ type: Boolean, reflect: true }) ], SlInput.prototype, "filled", 2); __decorateClass([ n({ type: Boolean, reflect: true }) ], SlInput.prototype, "pill", 2); __decorateClass([ n() ], SlInput.prototype, "label", 2); __decorateClass([ n({ attribute: "help-text" }) ], SlInput.prototype, "helpText", 2); __decorateClass([ n({ type: Boolean }) ], SlInput.prototype, "clearable", 2); __decorateClass([ n({ type: Boolean, reflect: true }) ], SlInput.prototype, "disabled", 2); __decorateClass([ n() ], SlInput.prototype, "placeholder", 2); __decorateClass([ n({ type: Boolean, reflect: true }) ], SlInput.prototype, "readonly", 2); __decorateClass([ n({ attribute: "password-toggle", type: Boolean }) ], SlInput.prototype, "passwordToggle", 2); __decorateClass([ n({ attribute: "password-visible", type: Boolean }) ], SlInput.prototype, "passwordVisible", 2); __decorateClass([ n({ attribute: "no-spin-buttons", type: Boolean }) ], SlInput.prototype, "noSpinButtons", 2); __decorateClass([ n({ reflect: true }) ], SlInput.prototype, "form", 2); __decorateClass([ n({ type: Boolean, reflect: true }) ], SlInput.prototype, "required", 2); __decorateClass([ n() ], SlInput.prototype, "pattern", 2); __decorateClass([ n({ type: Number }) ], SlInput.prototype, "minlength", 2); __decorateClass([ n({ type: Number }) ], SlInput.prototype, "maxlength", 2); __decorateClass([ n() ], SlInput.prototype, "min", 2); __decorateClass([ n() ], SlInput.prototype, "max", 2); __decorateClass([ n() ], SlInput.prototype, "step", 2); __decorateClass([ n() ], SlInput.prototype, "autocapitalize", 2); __decorateClass([ n() ], SlInput.prototype, "autocorrect", 2); __decorateClass([ n() ], SlInput.prototype, "autocomplete", 2); __decorateClass([ n({ type: Boolean }) ], SlInput.prototype, "autofocus", 2); __decorateClass([ n() ], SlInput.prototype, "enterkeyhint", 2); __decorateClass([ n({ type: Boolean, converter: { // Allow "true|false" attribute values but keep the property boolean fromAttribute: (value) => !value || value === "false" ? false : true, toAttribute: (value) => value ? "true" : "false" } }) ], SlInput.prototype, "spellcheck", 2); __decorateClass([ n() ], SlInput.prototype, "inputmode", 2); __decorateClass([ watch("disabled", { waitUntilFirstUpdate: true }) ], SlInput.prototype, "handleDisabledChange", 1); __decorateClass([ watch("step", { waitUntilFirstUpdate: true }) ], SlInput.prototype, "handleStepChange", 1); __decorateClass([ watch("value", { waitUntilFirstUpdate: true }) ], SlInput.prototype, "handleValueChange", 1); export { SlInput };