/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.0.0-beta.82 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-5c65e149.js'); const dom = require('./dom-9ac0341c.js'); const label = require('./label-165fc611.js'); const form = require('./form-11926121.js'); const locale = require('./locale-f2ebe4fa.js'); const number = require('./number-364babbc.js'); const math = require('./math-9d6de52c.js'); const observers = require('./observers-d9fdf006.js'); const interactive = require('./interactive-e294111f.js'); require('./guid-8b6d6cb4.js'); const CSS = { loader: "loader", clearButton: "clear-button", editingEnabled: "editing-enabled", inlineChild: "inline-child", inputIcon: "icon", prefix: "prefix", suffix: "suffix", numberButtonWrapper: "number-button-wrapper", buttonItemHorizontal: "number-button-item--horizontal", wrapper: "element-wrapper", inputWrapper: "wrapper", actionWrapper: "action-wrapper", resizeIconWrapper: "resize-icon-wrapper", numberButtonItem: "number-button-item" }; const INPUT_TYPE_ICONS = { tel: "phone", password: "lock", email: "email-address", date: "calendar", time: "clock", search: "search" }; const SLOTS = { action: "action" }; const TEXT = { clear: "Clear value" }; const inputCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:block}:host([scale=s]) input,:host([scale=s]) .prefix,:host([scale=s]) .suffix{height:1.5rem;padding:0.5rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=s]) textarea{height:1.5rem;min-height:1.5rem}:host([scale=s]) .number-button-wrapper,:host([scale=s]) .action-wrapper calcite-button,:host([scale=s]) .action-wrapper calcite-button button{height:1.5rem}:host([scale=s]) input[type=file]{height:1.5rem}:host([scale=s]) .clear-button{min-height:1.5rem;min-width:1.5rem}:host([scale=s]) textarea{height:auto;padding-top:0.25rem;padding-bottom:0.25rem;padding-left:0.5rem;padding-right:0.5rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=m]) input,:host([scale=m]) .prefix,:host([scale=m]) .suffix{height:2rem;padding:0.75rem;font-size:var(--calcite-font-size--1);line-height:1rem}:host([scale=m]) textarea{min-height:2rem}:host([scale=m]) .number-button-wrapper,:host([scale=m]) .action-wrapper calcite-button,:host([scale=m]) .action-wrapper calcite-button button{height:2rem}:host([scale=m]) input[type=file]{height:2rem}:host([scale=m]) .clear-button{min-height:2rem;min-width:2rem}:host([scale=m]) textarea{height:auto;padding-top:0.5rem;padding-bottom:0.5rem;padding-left:0.75rem;padding-right:0.75rem;font-size:var(--calcite-font-size--1);line-height:1rem}:host([scale=l]) input,:host([scale=l]) .prefix,:host([scale=l]) .suffix{height:2.75rem;padding:1rem;font-size:var(--calcite-font-size-0);line-height:1.25rem}:host([scale=l]) textarea{min-height:2.75rem}:host([scale=l]) .number-button-wrapper,:host([scale=l]) .action-wrapper calcite-button,:host([scale=l]) .action-wrapper calcite-button button{height:2.75rem}:host([scale=l]) input[type=file]{height:2.75rem}:host([scale=l]) .clear-button{min-height:2.75rem;min-width:2.75rem}:host([scale=l]) textarea{height:auto;padding-top:0.75rem;padding-bottom:0.75rem;padding-left:1rem;padding-right:1rem;font-size:var(--calcite-font-size-0);line-height:1.25rem}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) textarea{resize:none}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}:host textarea,:host input{-webkit-transition:var(--calcite-animation-timing), height 0s;transition:var(--calcite-animation-timing), height 0s;-webkit-appearance:none;position:relative;margin:0px;-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;max-height:100%;width:100%;max-width:100%;-ms-flex:1 1 0%;flex:1 1 0%;border-radius:0px;background-color:var(--calcite-ui-foreground-1);font-family:inherit;font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-1)}:host input[type=search]::-webkit-search-decoration{-webkit-appearance:none}:host input,:host textarea{border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-input);color:var(--calcite-ui-text-1)}:host input:-ms-input-placeholder,:host textarea:-ms-input-placeholder{font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-3)}:host input::-ms-input-placeholder,:host textarea::-ms-input-placeholder{font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-3)}:host input::placeholder,:host input:-ms-input-placeholder,:host input::-ms-input-placeholder,:host textarea::placeholder,:host textarea:-ms-input-placeholder,:host textarea::-ms-input-placeholder{font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-3)}:host input:focus,:host textarea:focus{border-color:var(--calcite-ui-brand);color:var(--calcite-ui-text-1)}:host input[readonly],:host textarea[readonly]{background-color:var(--calcite-ui-background);font-weight:var(--calcite-font-weight-medium)}:host input[readonly]:focus,:host textarea[readonly]:focus{color:var(--calcite-ui-text-1)}:host calcite-icon{color:var(--calcite-ui-text-3)}:host textarea,:host input{outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out}:host textarea:focus,:host input:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}:host([status=invalid]) input,:host([status=invalid]) textarea{border-color:var(--calcite-ui-danger)}:host([status=invalid]) input:focus,:host([status=invalid]) textarea:focus{outline:2px solid var(--calcite-ui-danger);outline-offset:-2px}:host([scale=s]) .icon{inset-inline-start:0.5rem}:host([scale=m]) .icon{inset-inline-start:0.75rem}:host([scale=l]) .icon{inset-inline-start:1rem}:host([icon][scale=s]) input{-webkit-padding-start:2rem;padding-inline-start:2rem}:host([icon][scale=m]) input{-webkit-padding-start:2.5rem;padding-inline-start:2.5rem}:host([icon][scale=l]) input{-webkit-padding-start:3rem;padding-inline-start:3rem}.element-wrapper{position:relative;-ms-flex-order:3;order:3;display:-ms-inline-flexbox;display:inline-flex;-ms-flex:1 1 0%;flex:1 1 0%;-ms-flex-align:center;align-items:center}.icon{pointer-events:none;position:absolute;z-index:10;display:block;-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:var(--calcite-animation-timing);transition-duration:var(--calcite-animation-timing);-webkit-transition-timing-function:ease-in-out;transition-timing-function:ease-in-out;-webkit-transition-delay:0s;transition-delay:0s}input[type=text]::-ms-clear,input[type=text]::-ms-reveal{display:none;height:0px;width:0px}input[type=search]::-webkit-search-decoration,input[type=search]::-webkit-search-cancel-button,input[type=search]::-webkit-search-results-button,input[type=search]::-webkit-search-results-decoration,input[type=date]::-webkit-clear-button,input[type=time]::-webkit-clear-button{display:none}.clear-button{pointer-events:initial;-ms-flex-order:4;order:4;margin:0px;-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;min-height:100%;cursor:pointer;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;-ms-flex-item-align:stretch;align-self:stretch;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-input);background-color:var(--calcite-ui-foreground-1);outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;border-inline-start-width:0px}.clear-button:hover{background-color:var(--calcite-ui-foreground-2);-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:var(--calcite-animation-timing);transition-duration:var(--calcite-animation-timing);-webkit-transition-timing-function:ease-in-out;transition-timing-function:ease-in-out;-webkit-transition-delay:0s;transition-delay:0s}.clear-button:hover calcite-icon{color:var(--calcite-ui-text-1);-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:var(--calcite-animation-timing);transition-duration:var(--calcite-animation-timing);-webkit-transition-timing-function:ease-in-out;transition-timing-function:ease-in-out;-webkit-transition-delay:0s;transition-delay:0s}.clear-button:active{background-color:var(--calcite-ui-foreground-3)}.clear-button:active calcite-icon{color:var(--calcite-ui-text-1)}.clear-button:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.clear-button:disabled{opacity:var(--calcite-ui-opacity-disabled)}.loader{top:1px;left:1px;right:1px;pointer-events:none;position:absolute;display:block}.action-wrapper{-ms-flex-order:7;order:7;display:-ms-flexbox;display:flex}.prefix,.suffix{-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;height:auto;min-height:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-ms-flex-line-pack:center;align-content:center;-ms-flex-align:center;align-items:center;overflow-wrap:break-word;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-input);background-color:var(--calcite-ui-background);font-weight:var(--calcite-font-weight-medium);line-height:1;color:var(--calcite-ui-text-2)}.prefix{-ms-flex-order:2;order:2;border-inline-end-width:0px}.suffix{-ms-flex-order:5;order:5;border-inline-start-width:0px}:host([alignment=start]) textarea,:host([alignment=start]) input{text-align:start}:host([alignment=end]) textarea,:host([alignment=end]) input{text-align:end}:host input[type=number]{-moz-appearance:textfield}:host input[type=number]::-webkit-inner-spin-button,:host input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none;-moz-appearance:textfield;margin:0px}.number-button-wrapper{pointer-events:none;-ms-flex-order:6;order:6;-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:var(--calcite-animation-timing);transition-duration:var(--calcite-animation-timing);-webkit-transition-timing-function:ease-in-out;transition-timing-function:ease-in-out;-webkit-transition-delay:0s;transition-delay:0s}:host([number-button-type=vertical]) .wrapper{-ms-flex-direction:row;flex-direction:row;display:-ms-flexbox;display:flex}:host([number-button-type=vertical]) input,:host([number-button-type=vertical]) textarea{-ms-flex-order:2;order:2}:host([number-button-type=horizontal]) .calcite--rtl .number-button-item[data-adjustment=down] calcite-icon{-webkit-transform:rotate(-90deg);transform:rotate(-90deg)}:host([number-button-type=horizontal]) .calcite--rtl .number-button-item[data-adjustment=up] calcite-icon{-webkit-transform:rotate(-90deg);transform:rotate(-90deg)}.number-button-item.number-button-item--horizontal[data-adjustment=down],.number-button-item.number-button-item--horizontal[data-adjustment=up]{-ms-flex-order:1;order:1;max-height:100%;min-height:100%;-ms-flex-item-align:stretch;align-self:stretch}.number-button-item.number-button-item--horizontal[data-adjustment=down] calcite-icon,.number-button-item.number-button-item--horizontal[data-adjustment=up] calcite-icon{-webkit-transform:rotate(90deg);transform:rotate(90deg)}.number-button-item.number-button-item--horizontal[data-adjustment=down]{border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-input);border-inline-end-width:0px}.number-button-item.number-button-item--horizontal[data-adjustment=down]:hover{background-color:var(--calcite-ui-foreground-2)}.number-button-item.number-button-item--horizontal[data-adjustment=down]:hover calcite-icon{color:var(--calcite-ui-text-1)}.number-button-item.number-button-item--horizontal[data-adjustment=up]{-ms-flex-order:5;order:5}.number-button-item.number-button-item--horizontal[data-adjustment=up]:hover{background-color:var(--calcite-ui-foreground-2)}.number-button-item.number-button-item--horizontal[data-adjustment=up]:hover calcite-icon{color:var(--calcite-ui-text-1)}:host([number-button-type=vertical]) .number-button-item[data-adjustment=down]:hover{background-color:var(--calcite-ui-foreground-2)}:host([number-button-type=vertical]) .number-button-item[data-adjustment=down]:hover calcite-icon{color:var(--calcite-ui-text-1)}:host([number-button-type=vertical]) .number-button-item[data-adjustment=up]:hover{background-color:var(--calcite-ui-foreground-2)}:host([number-button-type=vertical]) .number-button-item[data-adjustment=up]:hover calcite-icon{color:var(--calcite-ui-text-1)}:host([number-button-type=vertical]) .number-button-item[data-adjustment=down]{border-top-width:0px}.number-button-item{max-height:50%;min-height:50%;pointer-events:initial;margin:0px;-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;cursor:pointer;-ms-flex-align:center;align-items:center;-ms-flex-item-align:center;align-self:center;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-input);background-color:var(--calcite-ui-foreground-1);padding-top:0px;padding-bottom:0px;padding-left:0.5rem;padding-right:0.5rem;-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:var(--calcite-animation-timing);transition-duration:var(--calcite-animation-timing);-webkit-transition-timing-function:ease-in-out;transition-timing-function:ease-in-out;-webkit-transition-delay:0s;transition-delay:0s;border-inline-start-width:0px}.number-button-item calcite-icon{pointer-events:none;-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:var(--calcite-animation-timing);transition-duration:var(--calcite-animation-timing);-webkit-transition-timing-function:ease-in-out;transition-timing-function:ease-in-out;-webkit-transition-delay:0s;transition-delay:0s}.number-button-item:focus{background-color:var(--calcite-ui-foreground-2)}.number-button-item:focus calcite-icon{color:var(--calcite-ui-text-1)}.number-button-item:active{background-color:var(--calcite-ui-foreground-3)}.wrapper{position:relative;display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-align:center;align-items:center}:host input::-webkit-calendar-picker-indicator{display:none}:host input[type=date]::-webkit-input-placeholder{visibility:hidden !important}:host textarea::-webkit-resizer{position:absolute;bottom:0px;-webkit-box-sizing:border-box;box-sizing:border-box;padding-top:0px;padding-bottom:0px;padding-left:0.25rem;padding-right:0.25rem;inset-inline-end:0}.resize-icon-wrapper{bottom:2px;inset-inline-end:2px;pointer-events:none;position:absolute;z-index:10;height:0.75rem;width:0.75rem;background-color:var(--calcite-ui-foreground-1);color:var(--calcite-ui-text-3)}.resize-icon-wrapper calcite-icon{bottom:0.25rem;inset-inline-end:0.25rem;-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}.calcite--rtl .resize-icon-wrapper calcite-icon{-webkit-transform:rotate(45deg);transform:rotate(45deg)}:host([type=color]) input{padding:0.25rem}:host([type=file]) input{cursor:pointer;border-width:1px;border-style:dashed;border-color:var(--calcite-ui-border-input);background-color:var(--calcite-ui-foreground-1);text-align:center}:host([type=file][scale=s]) input{padding-top:1px;padding-bottom:1px;padding-left:0.5rem;padding-right:0.5rem}:host([type=file][scale=m]) input{padding-top:0.25rem;padding-bottom:0.25rem;padding-left:0.75rem;padding-right:0.75rem}:host([type=file][scale=l]) input{padding-top:0.5rem;padding-bottom:0.5rem;padding-left:1rem;padding-right:1rem}:host(.no-bottom-border) input{border-bottom-width:0px}:host(.border-top-color-one) input{border-top-color:var(--calcite-ui-border-1)}:host .inline-child{background-color:transparent;-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:var(--calcite-animation-timing);transition-duration:var(--calcite-animation-timing);-webkit-transition-timing-function:ease-in-out;transition-timing-function:ease-in-out;-webkit-transition-delay:0s;transition-delay:0s}:host .inline-child .editing-enabled{background-color:inherit}:host .inline-child:not(.editing-enabled){display:-ms-flexbox;display:flex;cursor:pointer;border-color:transparent;-webkit-padding-start:0;padding-inline-start:0}::slotted(input[slot=hidden-form-input]){bottom:0 !important;left:0 !important;margin:0 !important;opacity:0 !important;outline:none !important;padding:0 !important;position:absolute !important;right:0 !important;top:0 !important;-webkit-transform:none !important;transform:none !important;-webkit-appearance:none !important;z-index:-1 !important}"; const Input = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteInputFocus = index.createEvent(this, "calciteInputFocus", 7); this.calciteInputBlur = index.createEvent(this, "calciteInputBlur", 7); this.calciteInputInput = index.createEvent(this, "calciteInputInput", 7); this.calciteInputChange = index.createEvent(this, "calciteInputChange", 7); //-------------------------------------------------------------------------- // // Properties // //-------------------------------------------------------------------------- /** specify the alignment of the value of the input */ this.alignment = "start"; /** should the input autofocus */ this.autofocus = false; /** optionally display a clear button that displays when field has a value * shows by default for search, time, date * will not display for type="textarea" */ this.clearable = false; /** is the input disabled */ this.disabled = false; /** for number values, displays the locale's group separator */ this.groupSeparator = false; /** when true, the component will not be visible */ this.hidden = false; /** * string to override English loading text * @default "Loading" */ this.intlLoading = dom.TEXT.loading; /** flip the icon in rtl */ this.iconFlipRtl = false; /** specify if the input is in loading state */ this.loading = false; /** BCP 47 language tag for desired language and country format */ this.locale = document.documentElement.lang || "en"; /** * Toggles locale formatting for numbers. * @internal */ this.localeFormat = false; /** specify the placement of the number buttons */ this.numberButtonType = "vertical"; /** When true, a field cannot be modified. */ this.readOnly = false; /** is the input required */ this.required = false; /** specify the scale of the input, defaults to m */ this.scale = "m"; /** specify the status of the input field, determines message and icons */ this.status = "idle"; /** @internal adds inline styles for text input when slotted in calcite-inline-editable */ this.editingEnabled = false; /** * specify the input type * * Note that the following types add type-specific icons by default: `date`, `email`, `password`, `search`, `tel`, `time` */ this.type = "text"; /** input value */ this.value = ""; /** keep track of the rendered child type */ this.childElType = "input"; this.previousValueOrigin = "initial"; this.mutationObserver = observers.createObserver("mutation", () => this.setDisabledAction()); this.userChangedValue = false; //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- this.keyDownHandler = (event) => { if (this.readOnly || this.disabled) { return; } if (this.isClearable && event.key === "Escape") { this.clearInputValue(event); event.preventDefault(); } if (event.key === "Enter" && !event.defaultPrevented) { form.submitForm(this); } }; this.clearInputValue = (nativeEvent) => { this.setValue({ committing: true, nativeEvent, origin: "user", value: "" }); }; this.emitChangeIfUserModified = () => { if (this.previousValueOrigin === "user" && this.value !== this.previousEmittedValue) { this.calciteInputChange.emit(); } this.previousEmittedValue = this.value; }; this.inputBlurHandler = () => { this.calciteInputBlur.emit({ element: this.childEl, value: this.value }); this.emitChangeIfUserModified(); }; this.inputFocusHandler = (event) => { const slottedActionEl = dom.getSlotted(this.el, "action"); if (event.target !== slottedActionEl) { this.setFocus(); } this.calciteInputFocus.emit({ element: this.childEl, value: this.value }); }; this.inputInputHandler = (nativeEvent) => { if (this.disabled || this.readOnly) { return; } this.setValue({ nativeEvent, origin: "user", value: nativeEvent.target.value }); }; this.inputKeyDownHandler = (event) => { if (this.disabled || this.readOnly) { return; } if (event.key === "Enter") { this.emitChangeIfUserModified(); } }; this.inputNumberInputHandler = (nativeEvent) => { if (this.disabled || this.readOnly) { return; } const value = nativeEvent.target.value; const delocalizedValue = locale.delocalizeNumberString(value, this.locale); if (nativeEvent.inputType === "insertFromPaste") { if (!number.isValidNumber(delocalizedValue)) { nativeEvent.preventDefault(); } this.setValue({ nativeEvent, origin: "user", value: number.parseNumberString(delocalizedValue) }); this.childNumberEl.value = this.localizedValue; } else { this.setValue({ nativeEvent, origin: "user", value: delocalizedValue }); } }; this.inputNumberKeyDownHandler = (event) => { if (this.type !== "number" || this.disabled || this.readOnly) { return; } if (event.key === "ArrowUp") { /* prevent default behavior of moving cursor to the beginning of the input when holding down ArrowUp */ event.preventDefault(); this.nudgeNumberValue("up", event); return; } if (event.key === "ArrowDown") { this.nudgeNumberValue("down", event); return; } const supportedKeys = [ ...number.numberKeys, "ArrowLeft", "ArrowRight", "Backspace", "Delete", "Enter", "Escape", "Tab" ]; if (event.altKey || event.ctrlKey || event.metaKey) { return; } const isShiftTabEvent = event.shiftKey && event.key === "Tab"; if (supportedKeys.includes(event.key) && (!event.shiftKey || isShiftTabEvent)) { if (event.key === "Enter") { this.emitChangeIfUserModified(); } return; } const decimalSeparator = locale.getDecimalSeparator(this.locale); if (event.key === decimalSeparator) { if (!this.value && !this.childNumberEl.value) { return; } if (this.value && this.childNumberEl.value.indexOf(decimalSeparator) === -1) { return; } } if (/[eE]/.test(event.key)) { if (!this.value && !this.childNumberEl.value) { return; } if (this.value && !/[eE]/.test(this.childNumberEl.value)) { return; } } if (event.key === "-") { if (!this.value && !this.childNumberEl.value) { return; } if (this.value && this.childNumberEl.value.split("-").length <= 2) { return; } } event.preventDefault(); }; this.nudgeNumberValue = (direction, nativeEvent) => { if ((nativeEvent instanceof KeyboardEvent && nativeEvent.repeat) || this.type !== "number") { return; } const inputMax = this.maxString ? parseFloat(this.maxString) : null; const inputMin = this.minString ? parseFloat(this.minString) : null; const valueNudgeDelayInMs = 100; this.incrementOrDecrementNumberValue(direction, inputMax, inputMin, nativeEvent); if (this.nudgeNumberValueIntervalId) { window.clearInterval(this.nudgeNumberValueIntervalId); } let firstValueNudge = true; this.nudgeNumberValueIntervalId = window.setInterval(() => { if (firstValueNudge) { firstValueNudge = false; return; } this.incrementOrDecrementNumberValue(direction, inputMax, inputMin, nativeEvent); }, valueNudgeDelayInMs); }; this.numberButtonMouseUpAndMouseOutHandler = () => { window.clearInterval(this.nudgeNumberValueIntervalId); }; this.numberButtonMouseDownHandler = (event) => { event.preventDefault(); const direction = event.target.dataset.adjustment; this.nudgeNumberValue(direction, event); }; this.setChildElRef = (el) => { this.childEl = el; }; this.setChildNumberElRef = (el) => { this.childNumberEl = el; }; this.setInputValue = (newInputValue) => { if (this.type === "text" && !this.childEl) { return; } if (this.type === "number" && !this.childNumberEl) { return; } this[`child${this.type === "number" ? "Number" : ""}El`].value = newInputValue; }; this.setPreviousEmittedValue = (newPreviousEmittedValue) => { this.previousEmittedValue = this.type === "number" ? number.isValidNumber(newPreviousEmittedValue) ? newPreviousEmittedValue : "" : newPreviousEmittedValue; }; this.setPreviousValue = (newPreviousValue) => { this.previousValue = this.type === "number" ? number.isValidNumber(newPreviousValue) ? newPreviousValue : "" : newPreviousValue; }; this.setValue = ({ committing = false, nativeEvent, origin, previousValue, value }) => { const previousLocalizedValue = this.type === "number" ? locale.localizeNumberString(this.previousValue, this.locale, this.groupSeparator) : ""; const sanitizedValue = this.type === "number" ? number.sanitizeNumberString(value) : value; const newValue = this.type === "number" && value && !sanitizedValue ? number.isValidNumber(this.previousValue) ? this.previousValue : "" : sanitizedValue; const newLocalizedValue = this.type === "number" ? locale.localizeNumberString(newValue, this.locale, this.groupSeparator) : ""; this.setPreviousValue(previousValue || this.value); this.previousValueOrigin = origin; this.userChangedValue = origin === "user" && this.value !== newValue; this.value = newValue; if (this.type === "number") { this.localizedValue = newLocalizedValue; } if (origin === "direct") { this.setInputValue(this.type === "number" ? newLocalizedValue : newValue); } if (nativeEvent) { const calciteInputInputEvent = this.calciteInputInput.emit({ element: this.childEl, nativeEvent, value: this.value }); if (calciteInputInputEvent.defaultPrevented) { this.value = this.previousValue; this.localizedValue = previousLocalizedValue; } else if (committing) { this.emitChangeIfUserModified(); } } }; this.inputKeyUpHandler = () => { window.clearInterval(this.nudgeNumberValueIntervalId); }; } disabledWatcher() { this.setDisabledAction(); } /** watcher to update number-to-string for max */ maxWatcher() { var _a; this.maxString = ((_a = this.max) === null || _a === void 0 ? void 0 : _a.toString()) || null; } /** watcher to update number-to-string for min */ minWatcher() { var _a; this.minString = ((_a = this.min) === null || _a === void 0 ? void 0 : _a.toString()) || null; } valueWatcher(newValue, previousValue) { if (!this.userChangedValue) { this.setValue({ origin: "direct", previousValue, value: newValue == null || newValue == "" ? "" : this.type === "number" ? number.isValidNumber(newValue) ? newValue : this.previousValue || "" : newValue }); this.warnAboutInvalidNumberValue(newValue); } this.userChangedValue = false; } updateRequestedIcon() { this.requestedIcon = dom.setRequestedIcon(INPUT_TYPE_ICONS, this.icon, this.type); } get isClearable() { return !this.isTextarea && (this.clearable || this.type === "search") && this.value.length > 0; } get isTextarea() { return this.childElType === "textarea"; } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- connectedCallback() { var _a; this.scale = dom.getElementProp(this.el, "scale", this.scale); this.status = dom.getElementProp(this.el, "status", this.status); this.inlineEditableEl = this.el.closest("calcite-inline-editable"); if (this.inlineEditableEl) { this.editingEnabled = this.inlineEditableEl.editingEnabled || false; } this.setPreviousEmittedValue(this.value); this.setPreviousValue(this.value); if (this.type === "number") { this.warnAboutInvalidNumberValue(this.value); this.setValue({ origin: "connected", value: number.isValidNumber(this.value) ? this.value : "" }); } label.connectLabel(this); form.connectForm(this); (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true }); this.setDisabledAction(); } disconnectedCallback() { var _a; label.disconnectLabel(this); form.disconnectForm(this); (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect(); } componentWillLoad() { var _a, _b; this.childElType = this.type === "textarea" ? "textarea" : "input"; this.maxString = (_a = this.max) === null || _a === void 0 ? void 0 : _a.toString(); this.minString = (_b = this.min) === null || _b === void 0 ? void 0 : _b.toString(); this.requestedIcon = dom.setRequestedIcon(INPUT_TYPE_ICONS, this.icon, this.type); } componentShouldUpdate(newValue, oldValue, property) { if (this.type === "number" && property === "value" && newValue && !number.isValidNumber(newValue)) { this.setValue({ origin: "reset", value: oldValue }); return false; } return true; } componentDidRender() { interactive.updateHostInteraction(this); } //-------------------------------------------------------------------------- // // Public Methods // //-------------------------------------------------------------------------- /** Sets focus on the component. */ async setFocus() { var _a, _b; if (this.type === "number") { (_a = this.childNumberEl) === null || _a === void 0 ? void 0 : _a.focus(); } else { (_b = this.childEl) === null || _b === void 0 ? void 0 : _b.focus(); } } onLabelClick() { this.setFocus(); } incrementOrDecrementNumberValue(direction, inputMax, inputMin, nativeEvent) { const { value } = this; const inputStep = this.step === "any" ? 1 : Math.abs(this.step || 1); const inputVal = value && value !== "" ? parseFloat(value) : 0; const adjustment = direction === "up" ? 1 : -1; const nudgedValue = inputVal + inputStep * adjustment; const finalValue = (typeof inputMin === "number" && !isNaN(inputMin) && nudgedValue < inputMin) || (typeof inputMax === "number" && !isNaN(inputMax) && nudgedValue > inputMax) ? inputVal : nudgedValue; const inputValPlaces = math.decimalPlaces(inputVal); const inputStepPlaces = math.decimalPlaces(inputStep); this.setValue({ committing: true, nativeEvent, origin: "user", value: finalValue.toFixed(Math.max(inputValPlaces, inputStepPlaces)) }); } onFormReset() { this.setValue({ origin: "reset", value: this.defaultValue }); } syncHiddenFormInput(input) { var _a, _b, _c, _d; if (this.type === "number") { input.type = "number"; input.min = (_b = (_a = this.min) === null || _a === void 0 ? void 0 : _a.toString(10)) !== null && _b !== void 0 ? _b : ""; input.max = (_d = (_c = this.max) === null || _c === void 0 ? void 0 : _c.toString(10)) !== null && _d !== void 0 ? _d : ""; } else if (this.type === "text") { input.type = "text"; if (this.minLength != null) { input.minLength = this.minLength; } if (this.maxLength != null) { input.maxLength = this.maxLength; } } else if (this.type === "password") { input.type = "password"; } } setDisabledAction() { const slottedActionEl = dom.getSlotted(this.el, "action"); if (!slottedActionEl) { return; } this.disabled ? slottedActionEl.setAttribute("disabled", "") : slottedActionEl.removeAttribute("disabled"); } warnAboutInvalidNumberValue(value) { if (this.type === "number" && value && !number.isValidNumber(value)) { console.warn(`The specified value "${value}" cannot be parsed, or is out of range.`); } } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- render() { const dir = dom.getElementDir(this.el); const loader = (index.h("div", { class: CSS.loader }, index.h("calcite-progress", { label: this.intlLoading, type: "indeterminate" }))); const inputClearButton = (index.h("button", { "aria-label": this.intlClear || TEXT.clear, class: CSS.clearButton, disabled: this.disabled || this.readOnly, onClick: this.clearInputValue, tabIndex: this.disabled ? -1 : 0, type: "button" }, index.h("calcite-icon", { icon: "x", scale: "s" }))); const iconEl = (index.h("calcite-icon", { class: CSS.inputIcon, flipRtl: this.iconFlipRtl, icon: this.requestedIcon, scale: "s" })); const isHorizontalNumberButton = this.numberButtonType === "horizontal"; const numberButtonsHorizontalUp = (index.h("button", { class: { [CSS.numberButtonItem]: true, [CSS.buttonItemHorizontal]: isHorizontalNumberButton }, "data-adjustment": "up", disabled: this.disabled || this.readOnly, onMouseDown: this.numberButtonMouseDownHandler, onMouseOut: this.numberButtonMouseUpAndMouseOutHandler, onMouseUp: this.numberButtonMouseUpAndMouseOutHandler, tabIndex: -1, type: "button" }, index.h("calcite-icon", { icon: "chevron-up", scale: "s" }))); const numberButtonsHorizontalDown = (index.h("button", { class: { [CSS.numberButtonItem]: true, [CSS.buttonItemHorizontal]: isHorizontalNumberButton }, "data-adjustment": "down", disabled: this.disabled || this.readOnly, onMouseDown: this.numberButtonMouseDownHandler, onMouseOut: this.numberButtonMouseUpAndMouseOutHandler, onMouseUp: this.numberButtonMouseUpAndMouseOutHandler, tabIndex: -1, type: "button" }, index.h("calcite-icon", { icon: "chevron-down", scale: "s" }))); const numberButtonsVertical = (index.h("div", { class: CSS.numberButtonWrapper }, numberButtonsHorizontalUp, numberButtonsHorizontalDown)); const prefixText = index.h("div", { class: CSS.prefix }, this.prefixText); const suffixText = index.h("div", { class: CSS.suffix }, this.suffixText); const localeNumberInput = this.type === "number" ? (index.h("input", { "aria-label": label.getLabelText(this), autofocus: this.autofocus ? true : null, defaultValue: this.defaultValue, disabled: this.disabled ? true : null, enterKeyHint: this.el.enterKeyHint, inputMode: this.el.inputMode, key: "localized-input", maxLength: this.maxLength, minLength: this.minLength, name: undefined, onBlur: this.inputBlurHandler, onFocus: this.inputFocusHandler, onInput: this.inputNumberInputHandler, onKeyDown: this.inputNumberKeyDownHandler, onKeyUp: this.inputKeyUpHandler, placeholder: this.placeholder || "", readOnly: this.readOnly, ref: this.setChildNumberElRef, type: "text", value: this.localizedValue })) : null; const childEl = this.type !== "number" ? [ index.h(this.childElType, { "aria-label": label.getLabelText(this), autofocus: this.autofocus ? true : null, class: { [CSS.editingEnabled]: this.editingEnabled, [CSS.inlineChild]: !!this.inlineEditableEl }, defaultValue: this.defaultValue, disabled: this.disabled ? true : null, enterKeyHint: this.el.enterKeyHint, inputMode: this.el.inputMode, max: this.maxString, maxLength: this.maxLength, min: this.minString, minLength: this.minLength, name: this.name, onBlur: this.inputBlurHandler, onFocus: this.inputFocusHandler, onInput: this.inputInputHandler, onKeyDown: this.inputKeyDownHandler, onKeyUp: this.inputKeyUpHandler, placeholder: this.placeholder || "", readOnly: this.readOnly, ref: this.setChildElRef, required: this.required ? true : null, step: this.step, tabIndex: this.disabled || (this.inlineEditableEl && !this.editingEnabled) ? -1 : null, type: this.type, value: this.value }), this.isTextarea ? (index.h("div", { class: CSS.resizeIconWrapper }, index.h("calcite-icon", { icon: "chevron-down", scale: "s" }))) : null ] : null; return (index.h(index.Host, { onClick: this.inputFocusHandler, onKeyDown: this.keyDownHandler }, index.h("div", { class: { [CSS.inputWrapper]: true, [dom.CSS_UTILITY.rtl]: dir === "rtl" } }, this.type === "number" && this.numberButtonType === "horizontal" && !this.readOnly ? numberButtonsHorizontalDown : null, this.prefixText ? prefixText : null, index.h("div", { class: CSS.wrapper }, localeNumberInput, childEl, this.isClearable ? inputClearButton : null, this.requestedIcon ? iconEl : null, this.loading ? loader : null), index.h("div", { class: CSS.actionWrapper }, index.h("slot", { name: SLOTS.action })), this.type === "number" && this.numberButtonType === "vertical" && !this.readOnly ? numberButtonsVertical : null, this.suffixText ? suffixText : null, this.type === "number" && this.numberButtonType === "horizontal" && !this.readOnly ? numberButtonsHorizontalUp : null, index.h(form.HiddenFormInputSlot, { component: this })))); } get el() { return index.getElement(this); } static get watchers() { return { "disabled": ["disabledWatcher"], "max": ["maxWatcher"], "min": ["minWatcher"], "value": ["valueWatcher"], "icon": ["updateRequestedIcon"], "type": ["updateRequestedIcon"] }; } }; Input.style = inputCss; exports.calcite_input = Input;