123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 |
- /*!
- * 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.97
- */
- import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client/index.js';
- import { g as guid } from './guid.js';
- import { l as localizeTimeString, f as formatTimeString, i as isValidTime, d as defineCustomElement$2 } from './time-picker.js';
- import { c as connectLabel, d as disconnectLabel, g as getLabelText } from './label2.js';
- import { s as submitForm, c as connectForm, d as disconnectForm, H as HiddenFormInputSlot } from './form.js';
- import { u as updateHostInteraction } from './interactive.js';
- import { n as numberStringFormatter, u as updateEffectiveLocale, c as connectLocalized, d as disconnectLocalized } from './locale.js';
- import { n as numberKeys } from './key.js';
- import { d as defineCustomElement$8 } from './action.js';
- import { d as defineCustomElement$7 } from './icon.js';
- import { d as defineCustomElement$6 } from './input.js';
- import { d as defineCustomElement$5 } from './loader.js';
- import { d as defineCustomElement$4 } from './popover.js';
- import { d as defineCustomElement$3 } from './progress.js';
- const inputTimePickerCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity: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;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{display:inline-block;-webkit-user-select:none;user-select:none}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}::slotted(input[slot=hidden-form-input]){margin:0 !important;opacity:0 !important;outline:none !important;padding:0 !important;position:absolute !important;inset:0 !important;transform:none !important;-webkit-appearance:none !important;z-index:-1 !important}";
- const InputTimePicker = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
- constructor() {
- super();
- this.__registerHost();
- this.__attachShadow();
- this.calciteInputTimePickerChange = createEvent(this, "calciteInputTimePickerChange", 7);
- //--------------------------------------------------------------------------
- //
- // Properties
- //
- //--------------------------------------------------------------------------
- /**
- * When `true`, the component is active.
- *
- * @deprecated Use `open` instead.
- */
- this.active = false;
- /** When `true`, displays the `calcite-time-picker` component. */
- this.open = false;
- /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
- this.disabled = false;
- /**
- * When `true`, the component's value can be read, but controls are not accessible and the value cannot be modified.
- *
- * @mdn [readOnly](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly)
- */
- this.readOnly = false;
- /**
- * When `true`, the component must have a value in order for the form to submit.
- *
- * @internal
- */
- this.required = false;
- /** Specifies the size of the component. */
- this.scale = "m";
- /**
- * Determines the type of positioning to use for the overlaid content.
- *
- * Using `"absolute"` will work for most cases. The component will be positioned inside of overflowing parent containers and will affect the container's layout.
- *
- * `"fixed"` should be used to escape an overflowing parent container, or when the reference element's `position` CSS property is `"fixed"`.
- *
- */
- this.overlayPositioning = "absolute";
- /**
- * Determines where the popover will be positioned relative to the input.
- *
- * @see [LogicalPlacement](https://github.com/Esri/calcite-components/blob/master/src/utils/floating-ui.ts#L25)
- */
- this.placement = "auto";
- /** Specifies the granularity the component's `value` must adhere to (in seconds). */
- this.step = 60;
- /** The component's value in UTC (always 24-hour format). */
- this.value = null;
- /** whether the value of the input was changed as a result of user typing or not */
- this.internalValueChange = false;
- this.previousValidValue = null;
- this.referenceElementId = `input-time-picker-${guid()}`;
- //--------------------------------------------------------------------------
- //
- // State
- //
- //--------------------------------------------------------------------------
- this.effectiveLocale = "";
- //--------------------------------------------------------------------------
- //
- // Event Listeners
- //
- //--------------------------------------------------------------------------
- this.calciteInternalInputBlurHandler = () => {
- this.open = false;
- const shouldIncludeSeconds = this.shouldIncludeSeconds();
- const { effectiveLocale: locale, numberingSystem, value, calciteInputEl } = this;
- numberStringFormatter.numberFormatOptions = {
- locale,
- numberingSystem,
- useGrouping: false
- };
- const delocalizedValue = numberStringFormatter.delocalize(calciteInputEl.value);
- const localizedInputValue = localizeTimeString({
- value: delocalizedValue,
- includeSeconds: shouldIncludeSeconds,
- locale,
- numberingSystem
- });
- this.setInputValue(localizedInputValue ||
- localizeTimeString({ value, locale, numberingSystem, includeSeconds: shouldIncludeSeconds }));
- };
- this.calciteInternalInputFocusHandler = (event) => {
- if (!this.readOnly) {
- this.open = true;
- event.stopPropagation();
- }
- };
- this.calciteInputInputHandler = (event) => {
- const target = event.target;
- numberStringFormatter.numberFormatOptions = {
- locale: this.effectiveLocale,
- numberingSystem: this.numberingSystem,
- useGrouping: false
- };
- const delocalizedValue = numberStringFormatter.delocalize(target.value);
- this.setValue({ value: delocalizedValue });
- // only translate the numerals until blur
- const localizedValue = delocalizedValue
- .split("")
- .map((char) => numberKeys.includes(char)
- ? numberStringFormatter.numberFormatter.format(Number(char))
- : char)
- .join("");
- this.setInputValue(localizedValue);
- };
- this.timePickerChangeHandler = (event) => {
- event.stopPropagation();
- const target = event.target;
- const value = target.value;
- this.setValue({ value, origin: "time-picker" });
- };
- // --------------------------------------------------------------------------
- //
- // Private Methods
- //
- // --------------------------------------------------------------------------
- this.keyDownHandler = (event) => {
- const { defaultPrevented, key } = event;
- if (defaultPrevented) {
- return;
- }
- if (key === "Enter") {
- if (submitForm(this)) {
- event.preventDefault();
- }
- }
- if (key === "Escape" && this.open) {
- this.open = false;
- event.preventDefault();
- }
- };
- this.setCalcitePopoverEl = (el) => {
- this.popoverEl = el;
- };
- this.setCalciteInputEl = (el) => {
- this.calciteInputEl = el;
- };
- this.setCalciteTimePickerEl = (el) => {
- this.calciteTimePickerEl = el;
- };
- this.setInputValue = (newInputValue) => {
- if (!this.calciteInputEl) {
- return;
- }
- this.calciteInputEl.value = newInputValue;
- };
- this.setValue = ({ value, origin = "input" }) => {
- const previousValue = this.value;
- const newValue = formatTimeString(value);
- const newLocalizedValue = localizeTimeString({
- value: newValue,
- locale: this.effectiveLocale,
- numberingSystem: this.numberingSystem,
- includeSeconds: this.shouldIncludeSeconds()
- });
- this.internalValueChange = origin !== "external" && origin !== "loading";
- const shouldEmit = origin !== "loading" &&
- origin !== "external" &&
- ((value !== this.previousValidValue && !value) ||
- !!(!this.previousValidValue && newValue) ||
- (newValue !== this.previousValidValue && newValue));
- if (value) {
- if (shouldEmit) {
- this.previousValidValue = newValue;
- }
- if (newValue && newValue !== this.value) {
- this.value = newValue;
- }
- this.localizedValue = newLocalizedValue;
- }
- else {
- this.value = value;
- this.localizedValue = null;
- }
- if (origin === "time-picker" || origin === "external") {
- this.setInputValue(newLocalizedValue);
- }
- if (shouldEmit) {
- const changeEvent = this.calciteInputTimePickerChange.emit();
- if (changeEvent.defaultPrevented) {
- this.internalValueChange = false;
- this.value = previousValue;
- this.setInputValue(previousValue);
- this.previousValidValue = previousValue;
- }
- else {
- this.previousValidValue = newValue;
- }
- }
- };
- }
- activeHandler(value) {
- this.open = value;
- }
- openHandler(value) {
- this.active = value;
- if (this.disabled || this.readOnly) {
- this.open = false;
- return;
- }
- if (value) {
- this.reposition(true);
- }
- }
- handleDisabledAndReadOnlyChange(value) {
- if (!value) {
- this.open = false;
- }
- }
- localeChanged() {
- updateEffectiveLocale(this);
- }
- valueWatcher(newValue) {
- if (!this.internalValueChange) {
- this.setValue({ value: newValue, origin: "external" });
- }
- this.internalValueChange = false;
- }
- effectiveLocaleWatcher() {
- this.setInputValue(localizeTimeString({
- value: this.value,
- locale: this.effectiveLocale,
- numberingSystem: this.numberingSystem,
- includeSeconds: this.shouldIncludeSeconds()
- }));
- }
- clickHandler(event) {
- if (event.composedPath().includes(this.calciteTimePickerEl)) {
- return;
- }
- this.setFocus();
- }
- timePickerBlurHandler(event) {
- event.preventDefault();
- event.stopPropagation();
- this.open = false;
- }
- timePickerFocusHandler(event) {
- event.preventDefault();
- event.stopPropagation();
- if (!this.readOnly) {
- this.open = true;
- }
- }
- // --------------------------------------------------------------------------
- //
- // Public Methods
- //
- // --------------------------------------------------------------------------
- /** Sets focus on the component. */
- async setFocus() {
- var _a;
- (_a = this.calciteInputEl) === null || _a === void 0 ? void 0 : _a.setFocus();
- }
- /**
- * Updates the position of the component.
- *
- * @param delayed
- */
- async reposition(delayed = false) {
- var _a;
- (_a = this.popoverEl) === null || _a === void 0 ? void 0 : _a.reposition(delayed);
- }
- onLabelClick() {
- this.setFocus();
- }
- shouldIncludeSeconds() {
- return this.step < 60;
- }
- //--------------------------------------------------------------------------
- //
- // Lifecycle
- //
- //--------------------------------------------------------------------------
- connectedCallback() {
- connectLocalized(this);
- const { active, open } = this;
- if (this.value) {
- this.setValue({ value: isValidTime(this.value) ? this.value : undefined, origin: "loading" });
- }
- connectLabel(this);
- connectForm(this);
- if (open) {
- this.active = open;
- }
- else if (active) {
- this.open = active;
- }
- }
- componentDidLoad() {
- this.setInputValue(this.localizedValue);
- }
- disconnectedCallback() {
- disconnectLabel(this);
- disconnectForm(this);
- disconnectLocalized(this);
- }
- componentDidRender() {
- updateHostInteraction(this);
- }
- // --------------------------------------------------------------------------
- //
- // Render Methods
- //
- // --------------------------------------------------------------------------
- render() {
- const popoverId = `${this.referenceElementId}-popover`;
- return (h(Host, { onKeyDown: this.keyDownHandler }, h("div", { "aria-controls": popoverId, "aria-haspopup": "dialog", "aria-label": this.name, "aria-owns": popoverId, id: this.referenceElementId, role: "combobox" }, h("calcite-input", { disabled: this.disabled, icon: "clock", label: getLabelText(this), onCalciteInputInput: this.calciteInputInputHandler, onCalciteInternalInputBlur: this.calciteInternalInputBlurHandler, onCalciteInternalInputFocus: this.calciteInternalInputFocusHandler, readOnly: this.readOnly, ref: this.setCalciteInputEl, scale: this.scale, step: this.step })), h("calcite-popover", { id: popoverId, label: "Time Picker", open: this.open, overlayPositioning: this.overlayPositioning, placement: this.placement, ref: this.setCalcitePopoverEl, referenceElement: this.referenceElementId, triggerDisabled: true }, h("calcite-time-picker", { intlHour: this.intlHour, intlHourDown: this.intlHourDown, intlHourUp: this.intlHourUp, intlMeridiem: this.intlMeridiem, intlMeridiemDown: this.intlMeridiemDown, intlMeridiemUp: this.intlMeridiemUp, intlMinute: this.intlMinute, intlMinuteDown: this.intlMinuteDown, intlMinuteUp: this.intlMinuteUp, intlSecond: this.intlSecond, intlSecondDown: this.intlSecondDown, intlSecondUp: this.intlSecondUp, lang: this.effectiveLocale, numberingSystem: this.numberingSystem, onCalciteInternalTimePickerChange: this.timePickerChangeHandler, ref: this.setCalciteTimePickerEl, scale: this.scale, step: this.step, value: this.value })), h(HiddenFormInputSlot, { component: this })));
- }
- get el() { return this; }
- static get watchers() { return {
- "active": ["activeHandler"],
- "open": ["openHandler"],
- "disabled": ["handleDisabledAndReadOnlyChange"],
- "readOnly": ["handleDisabledAndReadOnlyChange"],
- "locale": ["localeChanged"],
- "value": ["valueWatcher"],
- "effectiveLocale": ["effectiveLocaleWatcher"]
- }; }
- static get style() { return inputTimePickerCss; }
- }, [1, "calcite-input-time-picker", {
- "active": [1540],
- "open": [1540],
- "disabled": [516],
- "readOnly": [516, "read-only"],
- "intlHour": [1, "intl-hour"],
- "intlHourDown": [1, "intl-hour-down"],
- "intlHourUp": [1, "intl-hour-up"],
- "intlMeridiem": [1, "intl-meridiem"],
- "intlMeridiemDown": [1, "intl-meridiem-down"],
- "intlMeridiemUp": [1, "intl-meridiem-up"],
- "intlMinute": [1, "intl-minute"],
- "intlMinuteDown": [1, "intl-minute-down"],
- "intlMinuteUp": [1, "intl-minute-up"],
- "intlSecond": [1, "intl-second"],
- "intlSecondDown": [1, "intl-second-down"],
- "intlSecondUp": [1, "intl-second-up"],
- "locale": [1025],
- "name": [1],
- "numberingSystem": [1, "numbering-system"],
- "required": [516],
- "scale": [513],
- "overlayPositioning": [1, "overlay-positioning"],
- "placement": [513],
- "step": [2],
- "value": [1025],
- "effectiveLocale": [32],
- "localizedValue": [32],
- "setFocus": [64],
- "reposition": [64]
- }, [[0, "click", "clickHandler"], [0, "calciteInternalTimePickerBlur", "timePickerBlurHandler"], [0, "calciteInternalTimePickerFocus", "timePickerFocusHandler"]]]);
- function defineCustomElement$1() {
- if (typeof customElements === "undefined") {
- return;
- }
- const components = ["calcite-input-time-picker", "calcite-action", "calcite-icon", "calcite-input", "calcite-loader", "calcite-popover", "calcite-progress", "calcite-time-picker"];
- components.forEach(tagName => { switch (tagName) {
- case "calcite-input-time-picker":
- if (!customElements.get(tagName)) {
- customElements.define(tagName, InputTimePicker);
- }
- break;
- case "calcite-action":
- if (!customElements.get(tagName)) {
- defineCustomElement$8();
- }
- break;
- case "calcite-icon":
- if (!customElements.get(tagName)) {
- defineCustomElement$7();
- }
- break;
- case "calcite-input":
- if (!customElements.get(tagName)) {
- defineCustomElement$6();
- }
- break;
- case "calcite-loader":
- if (!customElements.get(tagName)) {
- defineCustomElement$5();
- }
- break;
- case "calcite-popover":
- if (!customElements.get(tagName)) {
- defineCustomElement$4();
- }
- break;
- case "calcite-progress":
- if (!customElements.get(tagName)) {
- defineCustomElement$3();
- }
- break;
- case "calcite-time-picker":
- if (!customElements.get(tagName)) {
- defineCustomElement$2();
- }
- break;
- } });
- }
- defineCustomElement$1();
- const CalciteInputTimePicker = InputTimePicker;
- const defineCustomElement = defineCustomElement$1;
- export { CalciteInputTimePicker, defineCustomElement };
|