UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

3 lines (2 loc) • 11.3 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */ import{g as K}from"./3GV45XL7.js";import{k as G}from"./ZTSGKD2X.js";import{a as $}from"./S4QXLRJT.js";import{a as j}from"./PS3Y5JIN.js";import{c as A,d as W}from"./UIUDRBYG.js";import{a as q}from"./IJ3XVWSG.js";import{a as E}from"./H5BLSEZ3.js";import"./YGX7CUXN.js";import{a as N}from"./LHBACKJ5.js";import{a as V}from"./D7Q3AXKP.js";import"./RH6ZIP65.js";import"./YJF4NBEX.js";import"./TQRVWHPS.js";import"./KDWR7M23.js";import"./OAOQ5BXS.js";import{E as R,F as z,G as M,H as U,L as _,S as k,g as P,h as T,l as y,p as b}from"./C4ZX7VYR.js";var Y={offset:"offset"},ee={labelContent:"label-content"},te=60;function O(t){return t.replace(":15",".25").replace(":30",".5").replace(":45",".75").replace("\u2212","-")}function oe(t,e){let o=L(t,"en-US",e).replace("GMT","");return o===""?0:Number(O(o))*te}function se(){return new Date().getTimezoneOffset()*-1}function ae(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}async function ie(t){if(t==="offset")return o=>o;let{normalize:e}=await import("./23WLJ7R6.js");return e}async function ne(t,e,o,s,a){if(o==="name"){let{groupByName:n}=await import("./T2BI2MTE.js");return(await n()).map(({label:l})=>({label:l,value:l,metadata:{filterValue:l}})).filter(l=>!!l).sort()}let i=a==="user"?t:a==="utc"?"fr":"en-GB",c=s.getTime();if(o==="region"){let[{groupByRegion:n},{getCountry:m,global:l}]=await Promise.all([import("./OYOVXEMY.js"),import("./SFAEGOT3.js")]);return(await n()).map(({label:u,tzs:d})=>(d.sort((h,f)=>{let v=I(h,e),x=I(f,e),p="Etc/GMT";if(h.startsWith(p)&&f.startsWith(p)){let g=h.substring(p.length),F=f.substring(p.length),X=g===""?0:parseInt(g);return(F===""?0:parseInt(F))-X}return v.localeCompare(x)}),{label:S(e,u),items:d.map(h=>{let f=O(L(h,i,c)),v=I(h,e),x=u===l?`${I(l,e)} Etc`:H(h),p=m(h),g=S(e,p);return{label:v,value:h,metadata:{country:g===v?void 0:g,filterValue:x,offset:f}}})})).sort((u,d)=>u.label===l?-1:d.label===l?1:u.label.localeCompare(d.label))}let[{groupByOffset:C},{DateEngine:Z}]=await Promise.all([import("./I3YJL43S.js"),import("./GW3OENJK.js")]),B=await C({dateEngine:new Z,groupDateRange:1,startDate:new Date(c).toISOString()}),Q=new Intl.ListFormat(t,{style:"long",type:"conjunction"}),D=["Factory","Etc/UTC"];return B.forEach(n=>{let m=[],l=0;n.tzs.forEach((r,u)=>{D.includes(r)&&l++,m[u]=l}),n.tzs=n.tzs.filter(r=>!D.includes(r)),n.labelTzIdx=n.labelTzIdx.map(r=>r-m[r]).filter(r=>r>=0&&r<n.tzs.length)}),B.map(({labelTzIdx:n,tzs:m})=>{let l=m[0],r=O(L(l,i,c)),u=oe(l,c),d=n.map(f=>I(m[f],e));return{label:ce(e,r,Q.format(d)),value:u,metadata:{filterValue:m.map(f=>H(f))}}}).filter(n=>!!n).sort((n,m)=>n.value-m.value)}function I(t,e){return e[t]||re(t)}function le(t,e,o){return o.timeZoneRegionLabel.replace("{city}",t).replace("{country}",S(o,e))}function S(t,e){return t[e]||e}function re(t){return t.split("/").pop()}function H(t){return t.replace(/_/g," ")}function ce(t,e,o){return t.timeZoneLabel.replace("{offset}",e).replace("{cities}",o)}function L(t,e,o=Date.now()){return t==="Factory"&&(t="Etc/GMT"),G(e,{timeZone:t,timeZoneName:"shortOffset"}).formatToParts(o).find(({type:i})=>i==="timeZoneName").value}function me(t){return t[0].items!==void 0}function ue(t){return me(t)?t.flatMap(e=>e.items):t}function J(t,e,o){return o==null?null:ue(t).find(s=>s[e]==o)}var he=P`:host([disabled]){cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-opacity-disabled)}:host([disabled]) *,:host([disabled]) ::slotted(*){pointer-events:none}:host{display:block}.offset{white-space:nowrap}:host([hidden]){display:none}[hidden]{display:none}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.interaction-container{display:contents}::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}`,w=class extends M{constructor(){super(...arguments),this.comboboxRef=R(),this.formSupport=j({inputType:"text"})(this),this.messages=N({blocking:!0}),this.focusSetter=V()(this),this.interactiveContainer=q(this),this.#e=null,this.clearable=!1,this.disabled=!1,this.maxItems=0,this.mode="offset",this.offsetStyle="user",this.open=!1,this.overlayPositioning="absolute",this.readOnly=!1,this.required=!1,this.scale="m",this.status="idle",this.topLayerDisabled=!1,this.validity={valid:!1,badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valueMissing:!1},this.calciteInputTimeZoneBeforeClose=b({cancelable:!1}),this.calciteInputTimeZoneBeforeOpen=b({cancelable:!1}),this.calciteInputTimeZoneChange=b({cancelable:!1}),this.calciteInputTimeZoneClose=b({cancelable:!1}),this.calciteInputTimeZoneOpen=b({cancelable:!1})}static{this.properties={clearable:[7,{},{reflect:!0,type:Boolean}],disabled:[7,{},{reflect:!0,type:Boolean}],form:[3,{},{reflect:!0}],labelText:1,maxItems:[11,{},{reflect:!0,type:Number}],messageOverrides:[0,{},{attribute:!1}],mode:[3,{},{reflect:!0}],name:[3,{},{reflect:!0}],offsetStyle:[3,{},{reflect:!0}],open:[7,{},{reflect:!0,type:Boolean}],overlayPositioning:[3,{},{reflect:!0}],readOnly:[7,{},{reflect:!0,type:Boolean}],referenceDate:1,required:[7,{},{reflect:!0,type:Boolean}],scale:[3,{},{reflect:!0}],status:[3,{},{reflect:!0}],topLayerDisabled:[7,{},{reflect:!0,type:Boolean}],validationIcon:[3,{converter:_,type:String},{reflect:!0}],validationMessage:1,validity:[0,{},{attribute:!1}],value:1}}static{this.formAssociated=!0}static{this.shadowRootOptions={mode:"open",delegatesFocus:!0}}static{this.styles=he}#e;get value(){return this._value}set value(e){this.#e="internal",this._value=e}async setFocus(e){return this.focusSetter(()=>this.comboboxRef.value,e)}connectedCallback(){super.connectedCallback(),A(this)}async load(){this.normalizer=await ie(this.mode),await this.updateTimeZoneItems();let e=this.value,o=this.normalizeValue(e);this.value=o||(e===""?o:void 0),this.updateTimeZoneSelection();let s=this.selectedTimeZoneItem?`${this.selectedTimeZoneItem.value}`:"";this.value=s}willUpdate(e){e.has("value")&&this.hasUpdated&&this.handleValueChange(this.value,e.get("value")),(e.has("messages")||e.has("mode")&&(this.hasUpdated||this.mode!=="offset")||e.has("referenceDate"))&&this.handleTimeZoneItemPropsChange(),e.has("open")&&(this.hasUpdated||this.open!==!1)&&this.openChanged()}loaded(){this.openChanged()}disconnectedCallback(){super.disconnectedCallback(),W(this)}async handleTimeZoneItemPropsChange(){!this.timeZoneItems||!this.hasUpdated||(await this.updateTimeZoneItems(),this.updateTimeZoneSelection())}openChanged(){this.comboboxRef.value&&(this.comboboxRef.value.open=this.open)}async handleValueChange(e,o){let s=this.#e==="user";if(this.#e=null,s)return;let a=this.normalizeValue(e);if(!a){if(this.clearable){this._value=a,this.selectedTimeZoneItem=null;return}this._value=o,this.selectedTimeZoneItem=this.findTimeZoneItem(o);return}let i=this.findTimeZoneItem(a);if(!i){this._value=o;return}this._value=a,this.selectedTimeZoneItem=i}onLabelClick(){this.setFocus()}overrideSelectedLabelForRegion(e){this.mode!=="region"||!this.selectedTimeZoneItem||(this.comboboxRef.value.selectedItems[0].heading=this.getItemLabel(this.selectedTimeZoneItem,e))}onComboboxBeforeClose(e){e.stopPropagation(),this.overrideSelectedLabelForRegion(!1),this.calciteInputTimeZoneBeforeClose.emit()}onComboboxBeforeOpen(e){e.stopPropagation(),this.overrideSelectedLabelForRegion(!0),this.calciteInputTimeZoneBeforeOpen.emit()}onComboboxChange(e){e.stopPropagation();let s=e.target.selectedItems[0],a=this._value;if(!s){this._value="",this.requestUpdate("value",a),this.selectedTimeZoneItem=null,this.calciteInputTimeZoneChange.emit();return}let i=this.findTimeZoneItemByLabel(s.getAttribute("data-label")),c=`${i.value}`;this.value===c&&i.label===this.selectedTimeZoneItem.label||(this._value=c,this.requestUpdate("value",a),this.selectedTimeZoneItem=i,this.#e="user",this.calciteInputTimeZoneChange.emit())}onComboboxClose(e){e.stopPropagation(),this.open=!1,this.calciteInputTimeZoneClose.emit()}onComboboxOpen(e){this.open=!0,e.stopPropagation(),this.calciteInputTimeZoneOpen.emit()}findTimeZoneItem(e){return J(this.timeZoneItems,"value",e)}findTimeZoneItemByLabel(e){return J(this.timeZoneItems,"label",e)}async updateTimeZoneItems(){this.timeZoneItems=await this.createTimeZoneItems()}updateTimeZoneSelection(){if(this.value===""&&this.clearable){this.selectedTimeZoneItem=null;return}let e=this.mode==="offset"?se():ae(),o=this.value===""||!this.value?e:this.value;this.selectedTimeZoneItem=this.findTimeZoneItem(o)||this.findTimeZoneItem(e)}async createTimeZoneItems(){return!this.messages._lang||!this.messages?[]:ne(this.messages._lang,this.messages,this.mode,this.referenceDate instanceof Date?this.referenceDate:new Date(this.referenceDate??Date.now()),this.offsetStyle)}normalizeValue(e){return e=e===void 0?"":e,e&&this.normalizer(e)}getItemLabel(e,o=this.open){let s=this.selectedTimeZoneItem===e,{label:a,metadata:i}=e;return!i.country||o||!s?a:le(a,i.country,this.messages)}render(){return this.interactiveContainer({disabled:this.disabled,children:T`<calcite-combobox .clearDisabled=${!this.clearable} .disabled=${this.disabled} .label=${this.messages.chooseTimeZone} .labelText=${this.labelText} lang=${this.messages._lang??y} .maxItems=${this.maxItems} @calciteComboboxBeforeClose=${this.onComboboxBeforeClose} @calciteComboboxBeforeOpen=${this.onComboboxBeforeOpen} @calciteComboboxChange=${this.onComboboxChange} @calciteComboboxClose=${this.onComboboxClose} @calciteComboboxOpen=${this.onComboboxOpen} .overlayPositioning=${this.overlayPositioning} .placeholder=${this.mode==="name"?this.messages.namePlaceholder:this.mode==="offset"?this.messages.offsetPlaceholder:this.messages.regionPlaceholder} placeholder-icon=search .readOnly=${this.readOnly} .required=${this.required} .scale=${this.scale} .selectionMode=${this.clearable?"single":"single-persist"} .status=${this.status} .topLayerDisabled=${this.topLayerDisabled} .validationIcon=${this.validationIcon} .validationMessage=${this.validationMessage} ${z(this.comboboxRef)}>${this.renderItems()}<slot name=${ee.labelContent} slot=${K.labelContent}></slot></calcite-combobox>`})}renderItems(){return this.mode==="region"?this.renderRegionItems():$(this.timeZoneItems,({label:e})=>e,e=>{let o=this.selectedTimeZoneItem===e,{label:s,metadata:a,value:i}=e;return T`<calcite-combobox-item data-label=${s??y} .heading=${s} .metadata=${a} .selected=${o} .value=${i}></calcite-combobox-item>`})}renderRegionItems(){return this.timeZoneItems.flatMap(({label:e,items:o})=>E(e,T`<calcite-combobox-item-group .label=${e}>${$(o,({label:s})=>s,s=>{let a=this.selectedTimeZoneItem===s,{label:i,metadata:c,value:C}=s,Z=this.getItemLabel(s);return T`<calcite-combobox-item data-label=${i??y} .description=${c.country} .heading=${Z} .metadata=${c} .selected=${a} .value=${C}><span class=${U(Y.offset)} slot=content-end>${c.offset}</span></calcite-combobox-item>`})}</calcite-combobox-item-group>`))}};k("calcite-input-time-zone",w);export{w as InputTimeZone};