@gravitee/ui-components 3.25.3-typescript-50960c3 → 3.25.3-typescript-9d19b68

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 (183) hide show
  1. package/package.json +5 -13
  2. package/src/atoms/gv-autocomplete.js +422 -1
  3. package/src/atoms/gv-button.js +397 -1
  4. package/src/atoms/gv-checkbox.js +178 -1
  5. package/src/atoms/gv-date-picker-calendar.js +812 -1
  6. package/src/atoms/gv-date-picker-cell.js +174 -1
  7. package/src/atoms/gv-date-picker.js +638 -1
  8. package/src/atoms/gv-file-upload.js +348 -1
  9. package/src/atoms/gv-icon.js +93 -1
  10. package/src/atoms/gv-image.js +135 -1
  11. package/src/atoms/gv-input-message.js +78 -1
  12. package/src/atoms/gv-input.js +508 -1
  13. package/src/atoms/gv-link.js +204 -1
  14. package/src/atoms/gv-message.js +133 -1
  15. package/src/atoms/gv-metric.js +112 -1
  16. package/src/atoms/gv-relative-time.js +143 -1
  17. package/src/atoms/gv-select-native.js +363 -1
  18. package/src/atoms/gv-select.js +413 -1
  19. package/src/atoms/gv-spinner.js +54 -1
  20. package/src/atoms/gv-state.js +125 -1
  21. package/src/atoms/gv-switch.js +235 -1
  22. package/src/atoms/gv-tag.js +162 -1
  23. package/src/atoms/gv-text.js +160 -1
  24. package/src/charts/gv-chart-bar.js +101 -1
  25. package/src/charts/gv-chart-gauge.js +92 -1
  26. package/src/charts/gv-chart-histogram.js +78 -1
  27. package/src/charts/gv-chart-line.js +218 -1
  28. package/src/charts/gv-chart-map.js +111 -1
  29. package/src/charts/gv-chart-pie.js +89 -1
  30. package/src/index.js +77 -1
  31. package/src/lib/cron-expression.js +176 -1
  32. package/src/lib/date.js +43 -1
  33. package/src/lib/events.js +26 -1
  34. package/src/lib/http-client-schema-form.js +67 -1
  35. package/src/lib/http.js +237 -1
  36. package/src/lib/i18n.js +93 -1
  37. package/src/lib/item.js +110 -1
  38. package/src/lib/properties.js +171 -1
  39. package/src/lib/schema-form.js +39 -1
  40. package/src/lib/studio.js +144 -1
  41. package/src/lib/style.js +39 -1
  42. package/src/lib/text-format.js +65 -1
  43. package/src/lib/theme.js +60 -1
  44. package/src/lib/utils.js +106 -1
  45. package/src/mixins/chart-element.js +153 -1
  46. package/src/mixins/input-element.js +136 -1
  47. package/src/mixins/item-resource.js +102 -1
  48. package/src/mixins/keyboard-element.js +62 -1
  49. package/src/mixins/update-after-browser.js +30 -1
  50. package/src/mixins/with-resize-observer.js +62 -1
  51. package/src/mixins/with-skeleton-attribute.js +109 -1
  52. package/src/molecules/gv-card-full.js +209 -1
  53. package/src/molecules/gv-card-list.js +101 -1
  54. package/src/molecules/gv-card.js +130 -1
  55. package/src/molecules/gv-category-list.js +56 -1
  56. package/src/molecules/gv-category.js +163 -1
  57. package/src/molecules/gv-code.js +334 -1
  58. package/src/molecules/gv-confirm.js +175 -1
  59. package/src/molecules/gv-cron-editor.js +685 -1
  60. package/src/molecules/gv-dropdown-menu.js +108 -1
  61. package/src/molecules/gv-expandable.js +116 -1
  62. package/src/molecules/gv-expression-language.js +263 -1
  63. package/src/molecules/gv-identity-picture.js +139 -1
  64. package/src/molecules/gv-list.js +214 -1
  65. package/src/molecules/gv-metrics.js +147 -1
  66. package/src/molecules/gv-modal.js +203 -1
  67. package/src/molecules/gv-nav.js +180 -1
  68. package/src/molecules/gv-option.js +230 -1
  69. package/src/molecules/gv-plans.js +400 -1
  70. package/src/molecules/gv-popover.js +323 -1
  71. package/src/molecules/gv-promote.js +203 -1
  72. package/src/molecules/gv-rating-list.js +341 -1
  73. package/src/molecules/gv-rating.js +234 -1
  74. package/src/molecules/gv-row-expandable.js +42 -1
  75. package/src/molecules/gv-row.js +205 -1
  76. package/src/molecules/gv-stats.js +110 -1
  77. package/src/molecules/gv-stepper.js +274 -1
  78. package/src/molecules/gv-table.js +644 -1
  79. package/src/molecules/gv-tree.js +238 -1
  80. package/src/organisms/gv-documentation.js +205 -1
  81. package/src/organisms/gv-header.js +276 -1
  82. package/src/organisms/gv-http-client.js +258 -1
  83. package/src/organisms/gv-menu.js +258 -1
  84. package/src/organisms/gv-newsletter-subscription.js +258 -1
  85. package/src/organisms/gv-pagination.js +179 -1
  86. package/src/organisms/gv-properties.js +860 -1
  87. package/src/organisms/gv-resizable-views.js +371 -1
  88. package/src/organisms/gv-resources.js +496 -1
  89. package/src/organisms/gv-schema-form-array.js +237 -1
  90. package/src/organisms/gv-schema-form-control-object.js +141 -1
  91. package/src/organisms/gv-schema-form-control.js +419 -1
  92. package/src/organisms/gv-schema-form.js +700 -1
  93. package/src/organisms/gv-tabs.js +201 -1
  94. package/src/organisms/gv-user-menu.js +298 -1
  95. package/src/organisms/gv-vertical-menu.js +119 -1
  96. package/src/policy-studio/gv-flow-step.js +443 -1
  97. package/src/policy-studio/gv-flow.js +595 -1
  98. package/src/policy-studio/gv-policy-studio-menu.js +689 -1
  99. package/src/policy-studio/gv-policy-studio.js +1712 -1
  100. package/src/styles/empty.js +35 -1
  101. package/src/styles/input.js +262 -1
  102. package/src/styles/link.js +31 -1
  103. package/src/styles/shapes.js +17 -1
  104. package/src/styles/skeleton.js +52 -1
  105. package/src/styles/zoom.js +39 -1
  106. package/src/theme/gv-theme.js +197 -1
  107. package/wc/gv-autocomplete.js +1 -1
  108. package/wc/gv-button.js +1 -1
  109. package/wc/gv-card-full.js +1 -1
  110. package/wc/gv-card-list.js +1 -1
  111. package/wc/gv-card.js +1 -1
  112. package/wc/gv-category-list.js +1 -1
  113. package/wc/gv-category.js +1 -1
  114. package/wc/gv-chart-bar.js +1 -1
  115. package/wc/gv-chart-gauge.js +1 -1
  116. package/wc/gv-chart-histogram.js +1 -1
  117. package/wc/gv-chart-line.js +1 -1
  118. package/wc/gv-chart-map.js +1 -1
  119. package/wc/gv-chart-pie.js +1 -1
  120. package/wc/gv-checkbox.js +1 -1
  121. package/wc/gv-code.js +1 -1
  122. package/wc/gv-confirm.js +1 -1
  123. package/wc/gv-cron-editor.js +1 -1
  124. package/wc/gv-date-picker-calendar.js +1 -1
  125. package/wc/gv-date-picker-cell.js +1 -1
  126. package/wc/gv-date-picker.js +1 -1
  127. package/wc/gv-documentation.js +1 -1
  128. package/wc/gv-dropdown-menu.js +1 -1
  129. package/wc/gv-expandable.js +1 -1
  130. package/wc/gv-expression-language.js +1 -1
  131. package/wc/gv-file-upload.js +1 -1
  132. package/wc/gv-flow-step.js +1 -1
  133. package/wc/gv-flow.js +1 -1
  134. package/wc/gv-header.js +1 -1
  135. package/wc/gv-http-client.js +1 -1
  136. package/wc/gv-icon.js +1 -1
  137. package/wc/gv-identity-picture.js +1 -1
  138. package/wc/gv-image.js +1 -1
  139. package/wc/gv-input-message.js +1 -1
  140. package/wc/gv-input.js +1 -1
  141. package/wc/gv-link.js +1 -1
  142. package/wc/gv-list.js +1 -1
  143. package/wc/gv-menu.js +1 -1
  144. package/wc/gv-message.js +1 -1
  145. package/wc/gv-metric.js +1 -1
  146. package/wc/gv-metrics.js +1 -1
  147. package/wc/gv-modal.js +1 -1
  148. package/wc/gv-nav.js +1 -1
  149. package/wc/gv-newsletter-subscription.js +1 -1
  150. package/wc/gv-option.js +1 -1
  151. package/wc/gv-pagination.js +1 -1
  152. package/wc/gv-plans.js +1 -1
  153. package/wc/gv-policy-studio-menu.js +1 -1
  154. package/wc/gv-policy-studio.js +1 -1
  155. package/wc/gv-popover.js +1 -1
  156. package/wc/gv-promote.js +1 -1
  157. package/wc/gv-properties.js +1 -1
  158. package/wc/gv-rating-list.js +1 -1
  159. package/wc/gv-rating.js +1 -1
  160. package/wc/gv-relative-time.js +1 -1
  161. package/wc/gv-resizable-views.js +1 -1
  162. package/wc/gv-resources.js +1 -1
  163. package/wc/gv-row-expandable.js +1 -1
  164. package/wc/gv-row.js +1 -1
  165. package/wc/gv-schema-form-array.js +1 -1
  166. package/wc/gv-schema-form-control-object.js +1 -1
  167. package/wc/gv-schema-form-control.js +1 -1
  168. package/wc/gv-schema-form.js +1 -1
  169. package/wc/gv-select-native.js +1 -1
  170. package/wc/gv-select.js +1 -1
  171. package/wc/gv-spinner.js +1 -1
  172. package/wc/gv-state.js +1 -1
  173. package/wc/gv-stats.js +1 -1
  174. package/wc/gv-stepper.js +1 -1
  175. package/wc/gv-switch.js +1 -1
  176. package/wc/gv-table.js +1 -1
  177. package/wc/gv-tabs.js +1 -1
  178. package/wc/gv-tag.js +1 -1
  179. package/wc/gv-text.js +1 -1
  180. package/wc/gv-theme.js +1 -1
  181. package/wc/gv-tree.js +1 -1
  182. package/wc/gv-user-menu.js +1 -1
  183. package/wc/gv-vertical-menu.js +1 -1
@@ -1 +1,638 @@
1
- var t=Object.create?function(t,e,i,a){void 0===a&&(a=i),Object.defineProperty(t,a,{enumerable:!0,get:function(){return e[i]}})}:function(t,e,i,a){void 0===a&&(a=i),t[a]=e[i]},e=Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e},i=function(i){if(i&&i.__esModule)return i;var a={};if(null!=i)for(var s in i)"default"!==s&&Object.prototype.hasOwnProperty.call(i,s)&&t(a,i,s);return e(a,i),a},a=function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvDatePicker=void 0,require("./gv-date-picker-calendar");const s=a(require("date-fns/locale/en-US")),n=require("date-fns"),r=require("lit/directives/class-map"),o=require("lit"),h=require("../lib/i18n"),l=require("../lib/date"),d=require("lit/directives/until"),c=require("../lib/events"),m={en:s.default};class u extends o.LitElement{static get properties(){return{range:{type:Boolean},label:{type:String},name:{type:String},time:{type:Boolean},strict:{type:Boolean},small:{type:Boolean},value:{type:Array,reflect:!0},min:{type:Number},max:{type:Number},distanceFromNow:{type:Number},disabledDates:{type:Array},format:{type:String},invalid:{type:Boolean,reflect:!0},valid:{type:Boolean,reflect:!0},_hoveredDate:{type:String,attribute:!1},_open:{type:Boolean,attribute:!1},_month:{type:String,attribute:!1},_year:{type:String,attribute:!1},_monthPlus:{type:String,attribute:!1},_yearPlus:{type:Number,attribute:!1},_mode:{type:String,attribute:!1},_from:{type:Number,attribute:!1},_to:{type:Number,attribute:!1},_min:{type:Number,attribute:!1},_max:{type:Number,attribute:!1},_distance:{type:Number,attribute:!1}}}static get styles(){return[o.css`:host{box-sizing:border-box;display:inline-block;margin:.2rem;--gv-input-icon--bgc:transparent;--gv-icon--s:22px;--date-picker-hover--bgc:var(--gv-date-picker-hover--bgc, var(--gv-theme-color-light, #86c3d0));--date-picker-hover--c:var(--gv-date-picker-hover--c, var(--gv-theme-font-color-dark, #262626));--date-picker-selected--bgc:var(--gv-date-picker-selected--bgc, var(--gv-theme-color, #5a7684));--date-picker-selected--c:var(--gv-date-picker-selected--c, var(--gv-theme-font-color-light, #ffffff));font-size:var(--gv-theme-font-size-m,14px)}:host([small]){font-size:var(--gv-theme-font-size-s,12px)}.box{display:inline-block;width:100%}gv-input{width:160px;margin:0}.time gv-input{width:205px}:not(.range) gv-input{width:100%}.range gv-input{--gv-input--bds:none;--gv-input--bdw:0}.time .range-input gv-input{width:150px}.range-input gv-input{width:120px}.range.hasFrom.open .box-icon:first-of-type,.range.hasFrom.open gv-input:first-of-type{border-bottom:1px solid var(--gv-date-picker-selected--bgc,var(--gv-theme-color,#5a7684))}.range.hasTo.open .box-icon:not(.box-icon-calendar),.range.hasTo.open gv-input:last-of-type{border-bottom:1px solid var(--gv-date-picker-selected--bgc,var(--gv-theme-color,#5a7684))}.range-input{position:relative;z-index:10;border:var(--gv-input--bdw,1px) var(--gv-input--bds,solid) var(--gv-input--bdc,var(--gv-theme-neutral-color-dark,#d9d9d9));border-radius:4px;margin:.2rem;display:flex}.box-icon{display:flex;justify-content:center;align-items:center}.box-icon-calendar{padding:0 6px}.box-icon-clear{--gv-icon--s:16px;padding-right:6px;width:22px}.box-icon-clear gv-icon{cursor:pointer}.box.open .calendar{visibility:visible;opacity:1;-webkit-transform:-webkit-translateY(0);transform:translateY(0);z-index:100}.calendar{background-color:var(--gv-theme-neutral-color-lightest,#fff);color:var(--gv-theme-font-color,#262626);margin:.2rem;position:absolute;box-shadow:0 0 0 1px var(--gv-theme-neutral-color,#f5f5f5),0 1px 3px var(--gv-theme-neutral-color-dark,#bfbfbf);border-radius:2px;display:flex;cursor:pointer;visibility:hidden;opacity:0;-webkit-transform:-webkit-translateY(-2em);transform:translateY(-2em);-webkit-transition:-webkit-transform 150ms ease-in-out,opacity 150ms ease-in-out;-moz-transition:all 150ms ease-in-out;-ms-transition:all 150ms ease-in-out;-o-transition:all 150ms ease-in-out;overflow:auto;position:absolute}:host([invalid]) .range-input{border-left:5px solid #a94442;padding-left:0}:host([invalid]) .box-icon-calendar{padding-left:2px}`]}constructor(){super(),this._id="gv-id",this.strict=!1,this.range=!1,this.time=!1,this.format="dd/MM/yyyy";const t=(0,h.i18n)("gv-date-picker.format");"unknown"!==t&&(this.format=t),this.timeFormat="HH:mm",this.strictTimeFormat="HH:mm:ss",this.handleClick=this._onClick.bind(this),this.handleDocumentClick=this._onDocumentClick.bind(this),this.disabledDates=[]}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this.handleClick),document.addEventListener("click",this.handleDocumentClick),this.getLocale().then((t=>{this._year=(0,n.format)((new Date).getTime(),"yyyy",{locale:t}),this._month=(0,n.format)((new Date).getTime(),"MM",{locale:t})}))}disconnectedCallback(){clearInterval(this._distanceTimer),this.removeEventListener("click",this.handleClick),document.removeEventListener("click",this.handleDocumentClick),super.disconnectedCallback()}set min(t){this._min=parseInt(t/1e3,10)}set max(t){this._max=parseInt(t/1e3,10)}set distanceFromNow(t){this._distance=t,this._max=parseInt(Date.now()/1e3,10),this._min=parseInt((Date.now()-t)/1e3,10),this._from&&this._from<this._min&&(this._from=this._min)}_onClick(t){t.preventDefault(),t.stopPropagation()}_onDocumentClick(t){this._open=!1,this.performUpdate()}_onFocus(t){this._open=!0,this.time&&this.range&&(this._mode=t),this.performUpdate()}async getLocale(){const t=(0,h.getLanguage)();if(!t)return m.en;if(!m[t])try{const e=await Promise.resolve().then((()=>i(require(`date-fns/locale/${t}/index.js`))));m[t]=e.default}catch(e){console.error(`[Error] cannot load locale ${t}`,e)}return m[t]}get dateFromPlaceholder(){return this.range&&this.time&&this.strict?(0,h.i18n)("gv-date-picker.startTime"):this.range?(0,h.i18n)("gv-date-picker.startDate"):this.getFormat()}get dateToPlaceholder(){return this.range&&this.time&&this.strict?(0,h.i18n)("gv-date-picker.endTime"):this.range?(0,h.i18n)("gv-date-picker.endDate"):this.getFormat()}get icon(){return null!=this._from||null!=this._to?"code:error":"general:calendar"}get hasContent(){return null!=this._from||null!=this._to}_onClear(){this.invalid=!1,this.value=null,this.dispatchEvent(new Event("input",{bubbles:!0,cancelable:!0})),(0,c.dispatchCustomEvent)(this,"input",this.value)}render(){const t={box:!0,open:this._open,range:this.range,time:this.time,hasFrom:this.hasFrom(),hasTo:this.hasTo()};return o.html`<div class="${(0,r.classMap)(t)}">${this.range?o.html`${this.label?o.html`<label for="${this._id}" title="${this.label}">${this.label}</label>`:""}<div class="range-input"><div class="box-icon box-icon-calendar"><gv-icon shape="general:calendar"></gv-icon></div><gv-input id="${this._id}" ?small="${this.small}" ?disabled="${this.disabled}" @focus="${this._onFocus.bind(this,"from")}" @blur="${this._onBlurForm}" @gv-input:submit="${this._onBlurForm}" .value="${(0,d.until)(this.getFormattedDate(this._from))}" .placeholder="${this.dateFromPlaceholder}"></gv-input><div class="box-icon box-icon-arrow"><gv-icon shape="navigation:arrow-right"></gv-icon></div><gv-input .placeholder="${this.dateToPlaceholder}" ?small="${this.small}" ?disabled="${this.disabled}" @focus="${this._onFocus.bind(this,"to")}" @blur="${this._onBlurTo}" @gv-input:submit="${this._onBlurTo}" .value="${(0,d.until)(this.getFormattedDate(this._to))}"></gv-input><div class="box-icon box-icon-clear">${this.hasContent?o.html`<gv-icon class="link" @click="${this._onClear}" shape="code:error"></gv-icon>`:""}</div></div>`:o.html`<gv-input id="${this._id}" icon="${this.time&&this.strict?"home:timer":"general:calendar"}" ?small="${this.small}" ?disabled="${this.disabled}" clearable .label="${this.label}" @focus="${this._onFocus.bind(this,null)}" @blur="${this._onBlurForm}" ?invalid="${this.invalid}" @gv-input:submit="${this._onBlurForm}" @gv-input:clear="${this._onClear}" .placeholder="${this.dateToPlaceholder}" .value="${(0,d.until)(this.getFormattedDate(this._from))}"></gv-input>`} <span class="calendar">${this.range?o.html`${this.hasFrom()?o.html`<gv-date-picker-calendar .disabledDates="${this.disabledDates}" .min="${this._min}" .max="${this._max}" ?time="${this.time}" ?strict="${this.strict}" ?small="${this.small}" ?prev="${!0}" ?next="${this.time}" ?range="${this.range&&!this.time}" .month="${this._month}" .year="${this._year}" .hoveredDate="${this._hoveredDate}" .dateTo="${this._to}" .dateFrom="${this._from}" .locale="${(0,d.until)(this.getLocale())}" @gv-date-picker-calendar:month-mode="${this._onMonthMode}" @gv-date-picker-calendar:year-mode="${this._onYearMode}" @gv-date-picker-calendar:month-changed="${this._onMonthChanged}" @gv-date-picker-calendar:year-changed="${this._onYearChanged}" @hovered-date-changed="${this.hoveredDateChanged}" @date-to-changed="${this.dateToChanged}" @date-from-changed="${this.dateFromChanged}"></gv-date-picker-calendar>`:""} ${this.hasTo()?o.html`<gv-date-picker-calendar .disabledDates="${this.disabledDates}" .min="${this._min}" .max="${this._max}" ?time="${this.time}" ?strict="${this.strict}" ?small="${this.small}" ?prev="${this.time}" ?next="${!0}" ?range="${this.range&&!this.time}" .month="${this._monthPlus}" .year="${this._yearPlus}" .hoveredDate="${this._hoveredDate}" .dateTo="${this._to}" .dateFrom="${this._from}" .locale="${(0,d.until)(this.getLocale())}" @gv-date-picker-calendar:month-mode="${this._onMonthMode}" @gv-date-picker-calendar:year-mode="${this._onYearMode}" @gv-date-picker-calendar:month-changed="${this._onMonthChanged}" @gv-date-picker-calendar:year-changed="${this._onYearChanged}" @hovered-date-changed="${this.hoveredDateChanged}" @date-to-changed="${this.dateToChanged}" @date-from-changed="${this.dateFromChanged}"></gv-date-picker-calendar>`:""}`:o.html`<gv-date-picker-calendar .disabledDates="${this.disabledDates}" .min="${this._min}" .max="${this._max}" ?time="${this.time}" ?small="${this.small}" ?strict="${this.strict}" ?prev="${!0}" ?next="${!0}" ?range="${this.range}" .month="${this._month}" .year="${this._year}" .hoveredDate="${this._hoveredDate}" .dateTo="${this._to}" .dateFrom="${this._from}" .locale="${(0,d.until)(this.getLocale())}" @hovered-date-changed="${this.hoveredDateChanged}" @date-to-changed="${this.dateToChanged}" @date-from-changed="${this.dateFromChanged}"></gv-date-picker-calendar>`}</span></div>`}hasFrom(){return null==this._mode||"from"===this._mode}hasTo(){return null==this._mode||"to"===this._mode}firstUpdated(){this.time&&this.range&&(this._mode="from"),this._distance&&(this._distanceTimer=setInterval((()=>{this.distanceFromNow=this._distance}),3e4))}monthChanged(t,e){if(e&&t){const i=this.time&&this.range?0:1,a=`0${t%12+i}`;this._monthPlus=a.substring(a.length-2),"01"===this._monthPlus?this._yearPlus=parseInt(e,10)+i:this._yearPlus=parseInt(e,10)}}updated(t){(t.has("_month")||t.has("_year"))&&this.monthChanged(this._month,this._year),t.has("value")&&(null==this.value||this.value.filter&&0===this.value.filter((t=>null!=t)).length?(this._from=null,this._to=null):this.range?(this._from=this.value&&this.value.length>0?this.value[0]/1e3:null,this._to=this.value&&this.value.length>1?this.value[1]/1e3:null):this._from=this.value/1e3)}_onMonthChanged({detail:t}){this._month=t.month,this._year=t.year,this._hoveredDate=null,this.range&&this.time||(this._mode=null)}_onYearChanged({detail:t}){this._year=t.year}_onMonthMode({detail:t}){this.time&&this.range&&(this._month=t.month,this._year=t.year)}_onYearMode({detail:t}){this.time&&this.range&&(this._month=t.month,this._year=t.year)}_onBlurForm({target:t}){const e=t.value;if(e){const t=this.parseValue(e);t&&!isNaN(t)&&(this._month=((0,n.getMonth)(t)+1).toString(),this._year=(0,n.getYear)(t).toString(),this._from=t.getTime()/1e3,this.invalid=(0,l.isInvalid)(this._from,this._min,this._max,!this.time))}}_onBlurTo({target:t}){const e=t.value;if(e){const t=this.parseValue(e);t&&!isNaN(t)&&(this._month=((0,n.getMonth)(t)+1).toString(),this._year=(0,n.getYear)(t).toString(),this._to=t.getTime()/1e3,this.invalid=(0,l.isInvalid)(this._to,this._min,this._max,!this.time))}}hoveredDateChanged({detail:t}){this._hoveredDate=t.value}dateFromChanged({detail:t}){if(this.time&&this.range){if("from"===this._mode){this._from=t.value;const e=this.shadowRoot.querySelectorAll(".range-input gv-input");e[e.length-1].focus(),setTimeout((()=>this._mode="to"),0)}else if(this._to=t.value,this._open=!1,this._to<this._from){const t=this._to;this._to=this._from,this._from=t}}else this.range?this._from=t.value:(this._from=t.value,this._open=!1);this._distance&&(this.distanceFromNow=this._distance),this.range?(this.value=[1e3*this._from,1e3*this._to],this.invalid=(0,l.isInvalid)(this._to,this._min,this._max,!this.time)||(0,l.isInvalid)(this._from,this._min,this._max,!this.time)||this._to===this._form):(this.value=1e3*this._from,this.invalid=(0,l.isInvalid)(this._from,this._min,this._max,!this.time)),this.valid=!this.invalid,this.dispatchEvent(new Event("input",{bubbles:!0,cancelable:!0})),(0,c.dispatchCustomEvent)(this,"input",this.value)}dateToChanged({detail:t}){this._distance&&(this.distanceFromNow=this._distance),this._to=t.value,this._to&&(this._open=!1,this.value=[1e3*this._from,1e3*this._to],this.dispatchEvent(new Event("input",{bubbles:!0,cancelable:!0})),(0,c.dispatchCustomEvent)(this,"input",this.value))}getFormat(){return this.time&&this.strict?this.strictTimeFormat:this.time?`${this.format} ${this.timeFormat}`:this.format}async getFormattedDate(t){if(t){const e=await this.getLocale();return(0,n.format)(new Date(1e3*t),this.getFormat(),e)}return""}parseValue(t){return t?(0,n.parse)(t,this.getFormat(),new Date):""}}exports.GvDatePicker=u,window.customElements.define("gv-date-picker",u);
1
+ /*
2
+ * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import './gv-date-picker-calendar';
17
+ import enUS from 'date-fns/locale/en-US';
18
+ import { format, getMonth, getYear, parse } from 'date-fns';
19
+ import { classMap } from 'lit/directives/class-map';
20
+ import { css, LitElement, html } from 'lit';
21
+ import { getLanguage, i18n } from '../lib/i18n';
22
+ import { isInvalid } from '../lib/date';
23
+ import { until } from 'lit/directives/until';
24
+ import { dispatchCustomEvent } from '../lib/events';
25
+ const locales = { en: enUS };
26
+ /**
27
+ * Date Picker
28
+ *
29
+ * ## Details
30
+ * * has @theme facet
31
+ *
32
+ * @attr {Number|Array} value - if range picker, value is an array of timestamp else is a timestamp
33
+ * @attr {Boolean} range - if has range picker
34
+ * @attr {Boolean} time - if has time picker
35
+ * @attr {String} name - name of the input
36
+ * @attr {Boolean} strict - in completion of time if just have time picker
37
+ * @attr {Number} min - min timestamp
38
+ * @attr {Number} max - max timestamp
39
+ * @attr {Number} distanceFromNow - The distance timestamp relative to the current date. If configured, the min / max will be updated every minute.
40
+ * @attr {String} format - date format
41
+ * @attr {Boolean} valid - if value is valid
42
+ * @attr {Boolean} invalid - if value is invalid
43
+ * @attr {Boolean} small - for a small input
44
+ *
45
+ * @cssprop {Color} [--gv-date-picker-hover--bgc=var(--gv-theme-color-light, #86c3d0)] - Hover background color
46
+ * @cssprop {Color} [--gv-date-picker-hover--c=var(--gv-theme-font-color-dark, #262626)] - Hover color
47
+ * @cssprop {Color} [--gv-date-picker-selected--bgc=var(--gv-theme-color, #5a7684)] - Selected background color
48
+ * @cssprop {Color} [--gv-date-picker-selected--c=var(--gv-theme-font-color-light, #ffffff)] - Selected color
49
+ */
50
+ export class GvDatePicker extends LitElement {
51
+ static get properties() {
52
+ return {
53
+ range: { type: Boolean },
54
+ label: { type: String },
55
+ name: { type: String },
56
+ time: { type: Boolean },
57
+ strict: { type: Boolean },
58
+ small: { type: Boolean },
59
+ value: { type: Array, reflect: true },
60
+ min: { type: Number },
61
+ max: { type: Number },
62
+ distanceFromNow: { type: Number },
63
+ disabledDates: { type: Array },
64
+ format: { type: String },
65
+ invalid: { type: Boolean, reflect: true },
66
+ valid: { type: Boolean, reflect: true },
67
+ _hoveredDate: { type: String, attribute: false },
68
+ _open: { type: Boolean, attribute: false },
69
+ _month: { type: String, attribute: false },
70
+ _year: { type: String, attribute: false },
71
+ _monthPlus: { type: String, attribute: false },
72
+ _yearPlus: { type: Number, attribute: false },
73
+ _mode: { type: String, attribute: false },
74
+ _from: { type: Number, attribute: false },
75
+ _to: { type: Number, attribute: false },
76
+ _min: { type: Number, attribute: false },
77
+ _max: { type: Number, attribute: false },
78
+ _distance: { type: Number, attribute: false },
79
+ };
80
+ }
81
+ static get styles() {
82
+ return [
83
+ // language=CSS
84
+ css `
85
+ :host {
86
+ box-sizing: border-box;
87
+ display: inline-block;
88
+ margin: 0.2rem;
89
+ --gv-input-icon--bgc: transparent;
90
+ --gv-icon--s: 22px;
91
+ --date-picker-hover--bgc: var(--gv-date-picker-hover--bgc, var(--gv-theme-color-light, #86c3d0));
92
+ --date-picker-hover--c: var(--gv-date-picker-hover--c, var(--gv-theme-font-color-dark, #262626));
93
+ --date-picker-selected--bgc: var(--gv-date-picker-selected--bgc, var(--gv-theme-color, #5a7684));
94
+ --date-picker-selected--c: var(--gv-date-picker-selected--c, var(--gv-theme-font-color-light, #ffffff));
95
+ font-size: var(--gv-theme-font-size-m, 14px);
96
+ }
97
+
98
+ :host([small]) {
99
+ font-size: var(--gv-theme-font-size-s, 12px);
100
+ }
101
+
102
+ .box {
103
+ display: inline-block;
104
+ width: 100%;
105
+ }
106
+
107
+ gv-input {
108
+ width: 160px;
109
+ margin: 0;
110
+ }
111
+
112
+ .time gv-input {
113
+ width: 205px;
114
+ }
115
+
116
+ :not(.range) gv-input {
117
+ width: 100%;
118
+ }
119
+
120
+ .range gv-input {
121
+ --gv-input--bds: none;
122
+ --gv-input--bdw: 0;
123
+ }
124
+
125
+ .time .range-input gv-input {
126
+ width: 150px;
127
+ }
128
+
129
+ .range-input gv-input {
130
+ width: 120px;
131
+ }
132
+
133
+ .range.hasFrom.open gv-input:first-of-type,
134
+ .range.hasFrom.open .box-icon:first-of-type {
135
+ border-bottom: 1px solid var(--gv-date-picker-selected--bgc, var(--gv-theme-color, #5a7684));
136
+ }
137
+
138
+ .range.hasTo.open gv-input:last-of-type,
139
+ .range.hasTo.open .box-icon:not(.box-icon-calendar) {
140
+ border-bottom: 1px solid var(--gv-date-picker-selected--bgc, var(--gv-theme-color, #5a7684));
141
+ }
142
+
143
+ .range-input {
144
+ position: relative;
145
+ z-index: 10;
146
+ border: var(--gv-input--bdw, 1px) var(--gv-input--bds, solid) var(--gv-input--bdc, var(--gv-theme-neutral-color-dark, #d9d9d9));
147
+ border-radius: 4px;
148
+ margin: 0.2rem;
149
+ display: flex;
150
+ }
151
+
152
+ .box-icon {
153
+ display: flex;
154
+ justify-content: center;
155
+ align-items: center;
156
+ }
157
+
158
+ .box-icon-calendar {
159
+ padding: 0 6px;
160
+ }
161
+
162
+ .box-icon-arrow,
163
+ .box-icon-calendar {
164
+ }
165
+
166
+ .box-icon-clear {
167
+ --gv-icon--s: 16px;
168
+ padding-right: 6px;
169
+ width: 22px;
170
+ }
171
+
172
+ .box-icon-clear gv-icon {
173
+ cursor: pointer;
174
+ }
175
+
176
+ .box.open .calendar {
177
+ visibility: visible;
178
+ opacity: 1;
179
+ -webkit-transform: -webkit-translateY(0%);
180
+ transform: translateY(0%);
181
+ z-index: 100;
182
+ }
183
+
184
+ .calendar {
185
+ background-color: var(--gv-theme-neutral-color-lightest, #ffffff);
186
+ color: var(--gv-theme-font-color, #262626);
187
+ margin: 0.2rem;
188
+ position: absolute;
189
+ box-shadow: 0 0 0 1px var(--gv-theme-neutral-color, #f5f5f5), 0 1px 3px var(--gv-theme-neutral-color-dark, #bfbfbf);
190
+ border-radius: 2px;
191
+ display: flex;
192
+ cursor: pointer;
193
+ visibility: hidden;
194
+ opacity: 0;
195
+ -webkit-transform: -webkit-translateY(-2em);
196
+ transform: translateY(-2em);
197
+ -webkit-transition: -webkit-transform 150ms ease-in-out, opacity 150ms ease-in-out;
198
+ -moz-transition: all 150ms ease-in-out;
199
+ -ms-transition: all 150ms ease-in-out;
200
+ -o-transition: all 150ms ease-in-out;
201
+ overflow: auto;
202
+ position: absolute;
203
+ }
204
+
205
+ :host([invalid]) .range-input {
206
+ border-left: 5px solid #a94442;
207
+ padding-left: 0;
208
+ }
209
+
210
+ :host([invalid]) .box-icon-calendar {
211
+ padding-left: 2px;
212
+ }
213
+ `,
214
+ ];
215
+ }
216
+ constructor() {
217
+ super();
218
+ this._id = 'gv-id';
219
+ this.strict = false;
220
+ this.range = false;
221
+ this.time = false;
222
+ this.format = 'dd/MM/yyyy';
223
+ const format = i18n('gv-date-picker.format');
224
+ if (format !== 'unknown') {
225
+ this.format = format;
226
+ }
227
+ this.timeFormat = 'HH:mm';
228
+ this.strictTimeFormat = 'HH:mm:ss';
229
+ this.handleClick = this._onClick.bind(this);
230
+ this.handleDocumentClick = this._onDocumentClick.bind(this);
231
+ this.disabledDates = [];
232
+ }
233
+ connectedCallback() {
234
+ super.connectedCallback();
235
+ this.addEventListener('click', this.handleClick);
236
+ document.addEventListener('click', this.handleDocumentClick);
237
+ this.getLocale().then((locale) => {
238
+ this._year = format(new Date().getTime(), 'yyyy', { locale });
239
+ this._month = format(new Date().getTime(), 'MM', { locale });
240
+ });
241
+ }
242
+ disconnectedCallback() {
243
+ clearInterval(this._distanceTimer);
244
+ this.removeEventListener('click', this.handleClick);
245
+ document.removeEventListener('click', this.handleDocumentClick);
246
+ super.disconnectedCallback();
247
+ }
248
+ set min(value) {
249
+ this._min = parseInt(value / 1000, 10);
250
+ }
251
+ set max(value) {
252
+ this._max = parseInt(value / 1000, 10);
253
+ }
254
+ set distanceFromNow(value) {
255
+ this._distance = value;
256
+ this._max = parseInt(Date.now() / 1000, 10);
257
+ this._min = parseInt((Date.now() - value) / 1000, 10);
258
+ if (this._from && this._from < this._min) {
259
+ this._from = this._min;
260
+ }
261
+ }
262
+ _onClick(e) {
263
+ e.preventDefault();
264
+ e.stopPropagation();
265
+ }
266
+ _onDocumentClick(e) {
267
+ this._open = false;
268
+ this.performUpdate();
269
+ }
270
+ _onFocus(mode) {
271
+ this._open = true;
272
+ if (this.time && this.range) {
273
+ this._mode = mode;
274
+ }
275
+ this.performUpdate();
276
+ }
277
+ async getLocale() {
278
+ const lang = getLanguage();
279
+ if (!lang) {
280
+ return locales.en;
281
+ }
282
+ if (!locales[lang]) {
283
+ try {
284
+ const locale = await import(`date-fns/locale/${lang}/index.js`);
285
+ locales[lang] = locale.default;
286
+ }
287
+ catch (e) {
288
+ console.error(`[Error] cannot load locale ${lang}`, e);
289
+ }
290
+ }
291
+ return locales[lang];
292
+ }
293
+ get dateFromPlaceholder() {
294
+ if (this.range && this.time && this.strict) {
295
+ return i18n('gv-date-picker.startTime');
296
+ }
297
+ if (this.range) {
298
+ return i18n('gv-date-picker.startDate');
299
+ }
300
+ return this.getFormat();
301
+ }
302
+ get dateToPlaceholder() {
303
+ if (this.range && this.time && this.strict) {
304
+ return i18n('gv-date-picker.endTime');
305
+ }
306
+ if (this.range) {
307
+ return i18n('gv-date-picker.endDate');
308
+ }
309
+ return this.getFormat();
310
+ }
311
+ get icon() {
312
+ return this._from != null || this._to != null ? 'code:error' : 'general:calendar';
313
+ }
314
+ get hasContent() {
315
+ return this._from != null || this._to != null;
316
+ }
317
+ _onClear() {
318
+ this.invalid = false;
319
+ this.value = null;
320
+ this.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
321
+ dispatchCustomEvent(this, 'input', this.value);
322
+ }
323
+ render() {
324
+ const classes = {
325
+ box: true,
326
+ open: this._open,
327
+ range: this.range,
328
+ time: this.time,
329
+ hasFrom: this.hasFrom(),
330
+ hasTo: this.hasTo(),
331
+ };
332
+ return html ` <div class="${classMap(classes)}">
333
+ ${this.range
334
+ ? html `
335
+ ${this.label ? html `<label for=${this._id} title="${this.label}">${this.label}</label>` : ''}
336
+ <div class="range-input">
337
+ <div class="box-icon box-icon-calendar"><gv-icon shape="general:calendar"></gv-icon></div>
338
+ <gv-input
339
+ id="${this._id}"
340
+ ?small="${this.small}"
341
+ ?disabled="${this.disabled}"
342
+ @focus="${this._onFocus.bind(this, 'from')}"
343
+ @blur="${this._onBlurForm}"
344
+ @gv-input:submit="${this._onBlurForm}"
345
+ .value="${until(this.getFormattedDate(this._from))}"
346
+ .placeholder="${this.dateFromPlaceholder}"
347
+ ></gv-input>
348
+ <div class="box-icon box-icon-arrow"><gv-icon shape="navigation:arrow-right"></gv-icon></div>
349
+ <gv-input
350
+ .placeholder="${this.dateToPlaceholder}"
351
+ ?small="${this.small}"
352
+ ?disabled="${this.disabled}"
353
+ @focus="${this._onFocus.bind(this, 'to')}"
354
+ @blur="${this._onBlurTo}"
355
+ @gv-input:submit="${this._onBlurTo}"
356
+ .value="${until(this.getFormattedDate(this._to))}"
357
+ ></gv-input>
358
+ <div class="box-icon box-icon-clear">
359
+ ${this.hasContent ? html `<gv-icon class="link" @click=${this._onClear} shape="code:error"></gv-icon>` : ''}
360
+ </div>
361
+ </div>
362
+ `
363
+ : html `
364
+ <gv-input
365
+ id="${this._id}"
366
+ icon="${this.time && this.strict ? 'home:timer' : 'general:calendar'}"
367
+ ?small="${this.small}"
368
+ ?disabled="${this.disabled}"
369
+ clearable
370
+ .label="${this.label}"
371
+ @focus="${this._onFocus.bind(this, null)}"
372
+ @blur="${this._onBlurForm}"
373
+ ?invalid="${this.invalid}"
374
+ @gv-input:submit="${this._onBlurForm}"
375
+ @gv-input:clear="${this._onClear}"
376
+ .placeholder="${this.dateToPlaceholder}"
377
+ .value="${until(this.getFormattedDate(this._from))}"></gv-input></div>
378
+ `}
379
+
380
+ <span class="calendar">
381
+ ${this.range
382
+ ? html `
383
+ ${this.hasFrom()
384
+ ? html `<gv-date-picker-calendar
385
+ .disabledDates="${this.disabledDates}"
386
+ .min="${this._min}"
387
+ .max="${this._max}"
388
+ ?time="${this.time}"
389
+ ?strict="${this.strict}"
390
+ ?small="${this.small}"
391
+ ?prev="${true}"
392
+ ?next="${this.time}"
393
+ ?range="${this.range && !this.time}"
394
+ .month="${this._month}"
395
+ .year="${this._year}"
396
+ .hoveredDate="${this._hoveredDate}"
397
+ .dateTo="${this._to}"
398
+ .dateFrom="${this._from}"
399
+ .locale="${until(this.getLocale())}"
400
+ @gv-date-picker-calendar:month-mode="${this._onMonthMode}"
401
+ @gv-date-picker-calendar:year-mode="${this._onYearMode}"
402
+ @gv-date-picker-calendar:month-changed="${this._onMonthChanged}"
403
+ @gv-date-picker-calendar:year-changed="${this._onYearChanged}"
404
+ @hovered-date-changed="${this.hoveredDateChanged}"
405
+ @date-to-changed="${this.dateToChanged}"
406
+ @date-from-changed="${this.dateFromChanged}"
407
+ >
408
+ </gv-date-picker-calendar>`
409
+ : ''}
410
+ ${this.hasTo()
411
+ ? html `<gv-date-picker-calendar
412
+ .disabledDates="${this.disabledDates}"
413
+ .min="${this._min}"
414
+ .max="${this._max}"
415
+ ?time="${this.time}"
416
+ ?strict="${this.strict}"
417
+ ?small="${this.small}"
418
+ ?prev="${this.time}"
419
+ ?next="${true}"
420
+ ?range="${this.range && !this.time}"
421
+ .month="${this._monthPlus}"
422
+ .year="${this._yearPlus}"
423
+ .hoveredDate="${this._hoveredDate}"
424
+ .dateTo="${this._to}"
425
+ .dateFrom="${this._from}"
426
+ .locale="${until(this.getLocale())}"
427
+ @gv-date-picker-calendar:month-mode="${this._onMonthMode}"
428
+ @gv-date-picker-calendar:year-mode="${this._onYearMode}"
429
+ @gv-date-picker-calendar:month-changed="${this._onMonthChanged}"
430
+ @gv-date-picker-calendar:year-changed="${this._onYearChanged}"
431
+ @hovered-date-changed="${this.hoveredDateChanged}"
432
+ @date-to-changed="${this.dateToChanged}"
433
+ @date-from-changed="${this.dateFromChanged}"
434
+ >
435
+ </gv-date-picker-calendar>`
436
+ : ''}
437
+ `
438
+ : html `
439
+ <gv-date-picker-calendar
440
+ .disabledDates="${this.disabledDates}"
441
+ .min="${this._min}"
442
+ .max="${this._max}"
443
+ ?time="${this.time}"
444
+ ?small="${this.small}"
445
+ ?strict="${this.strict}"
446
+ ?prev="${true}"
447
+ ?next="${true}"
448
+ ?range="${this.range}"
449
+ .month="${this._month}"
450
+ .year="${this._year}"
451
+ .hoveredDate="${this._hoveredDate}"
452
+ .dateTo="${this._to}"
453
+ .dateFrom="${this._from}"
454
+ .locale="${until(this.getLocale())}"
455
+ @hovered-date-changed="${this.hoveredDateChanged}"
456
+ @date-to-changed="${this.dateToChanged}"
457
+ @date-from-changed="${this.dateFromChanged}"
458
+ >
459
+ </gv-date-picker-calendar>
460
+ `}
461
+ </span>
462
+ </div>`;
463
+ }
464
+ hasFrom() {
465
+ return this._mode == null || this._mode === 'from';
466
+ }
467
+ hasTo() {
468
+ return this._mode == null || this._mode === 'to';
469
+ }
470
+ firstUpdated() {
471
+ if (this.time && this.range) {
472
+ this._mode = 'from';
473
+ }
474
+ if (this._distance) {
475
+ this._distanceTimer = setInterval(() => {
476
+ this.distanceFromNow = this._distance;
477
+ }, 30000);
478
+ }
479
+ }
480
+ monthChanged(month, year) {
481
+ if (year && month) {
482
+ const add = this.time && this.range ? 0 : 1;
483
+ const monthPlus = `0${(month % 12) + add}`;
484
+ this._monthPlus = monthPlus.substring(monthPlus.length - 2);
485
+ if (this._monthPlus === '01') {
486
+ this._yearPlus = parseInt(year, 10) + add;
487
+ }
488
+ else {
489
+ this._yearPlus = parseInt(year, 10);
490
+ }
491
+ }
492
+ }
493
+ updated(properties) {
494
+ if (properties.has('_month') || properties.has('_year')) {
495
+ this.monthChanged(this._month, this._year);
496
+ }
497
+ if (properties.has('value')) {
498
+ if (this.value == null || (this.value.filter && this.value.filter((v) => v != null).length === 0)) {
499
+ this._from = null;
500
+ this._to = null;
501
+ }
502
+ else {
503
+ if (this.range) {
504
+ this._from = this.value && this.value.length > 0 ? this.value[0] / 1000 : null;
505
+ this._to = this.value && this.value.length > 1 ? this.value[1] / 1000 : null;
506
+ }
507
+ else {
508
+ this._from = this.value / 1000;
509
+ }
510
+ }
511
+ }
512
+ }
513
+ _onMonthChanged({ detail }) {
514
+ this._month = detail.month;
515
+ this._year = detail.year;
516
+ this._hoveredDate = null;
517
+ if (!(this.range && this.time)) {
518
+ this._mode = null;
519
+ }
520
+ }
521
+ _onYearChanged({ detail }) {
522
+ this._year = detail.year;
523
+ }
524
+ _onMonthMode({ detail }) {
525
+ if (this.time && this.range) {
526
+ this._month = detail.month;
527
+ this._year = detail.year;
528
+ }
529
+ }
530
+ _onYearMode({ detail }) {
531
+ if (this.time && this.range) {
532
+ this._month = detail.month;
533
+ this._year = detail.year;
534
+ }
535
+ }
536
+ _onBlurForm({ target }) {
537
+ const value = target.value;
538
+ if (value) {
539
+ const date = this.parseValue(value);
540
+ if (date && !isNaN(date)) {
541
+ this._month = (getMonth(date) + 1).toString();
542
+ this._year = getYear(date).toString();
543
+ this._from = date.getTime() / 1000;
544
+ this.invalid = isInvalid(this._from, this._min, this._max, !this.time);
545
+ }
546
+ }
547
+ }
548
+ _onBlurTo({ target }) {
549
+ const value = target.value;
550
+ if (value) {
551
+ const date = this.parseValue(value);
552
+ if (date && !isNaN(date)) {
553
+ this._month = (getMonth(date) + 1).toString();
554
+ this._year = getYear(date).toString();
555
+ this._to = date.getTime() / 1000;
556
+ this.invalid = isInvalid(this._to, this._min, this._max, !this.time);
557
+ }
558
+ }
559
+ }
560
+ hoveredDateChanged({ detail }) {
561
+ this._hoveredDate = detail.value;
562
+ }
563
+ dateFromChanged({ detail }) {
564
+ if (this.time && this.range) {
565
+ if (this._mode === 'from') {
566
+ this._from = detail.value;
567
+ const inputs = this.shadowRoot.querySelectorAll('.range-input gv-input');
568
+ inputs[inputs.length - 1].focus();
569
+ setTimeout(() => (this._mode = 'to'), 0);
570
+ }
571
+ else {
572
+ this._to = detail.value;
573
+ this._open = false;
574
+ if (this._to < this._from) {
575
+ const tmp = this._to;
576
+ this._to = this._from;
577
+ this._from = tmp;
578
+ }
579
+ }
580
+ }
581
+ else if (!this.range) {
582
+ this._from = detail.value;
583
+ this._open = false;
584
+ }
585
+ else {
586
+ this._from = detail.value;
587
+ }
588
+ if (this._distance) {
589
+ this.distanceFromNow = this._distance;
590
+ }
591
+ if (this.range) {
592
+ this.value = [this._from * 1000, this._to * 1000];
593
+ this.invalid =
594
+ isInvalid(this._to, this._min, this._max, !this.time) ||
595
+ isInvalid(this._from, this._min, this._max, !this.time) ||
596
+ this._to === this._form;
597
+ }
598
+ else {
599
+ this.value = this._from * 1000;
600
+ this.invalid = isInvalid(this._from, this._min, this._max, !this.time);
601
+ }
602
+ this.valid = !this.invalid;
603
+ this.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
604
+ dispatchCustomEvent(this, 'input', this.value);
605
+ }
606
+ dateToChanged({ detail }) {
607
+ if (this._distance) {
608
+ this.distanceFromNow = this._distance;
609
+ }
610
+ this._to = detail.value;
611
+ if (this._to) {
612
+ this._open = false;
613
+ this.value = [this._from * 1000, this._to * 1000];
614
+ this.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
615
+ dispatchCustomEvent(this, 'input', this.value);
616
+ }
617
+ }
618
+ getFormat() {
619
+ if (this.time && this.strict) {
620
+ return this.strictTimeFormat;
621
+ }
622
+ return this.time ? `${this.format} ${this.timeFormat}` : this.format;
623
+ }
624
+ async getFormattedDate(date) {
625
+ if (date) {
626
+ const locale = await this.getLocale();
627
+ return format(new Date(date * 1000), this.getFormat(), locale);
628
+ }
629
+ return '';
630
+ }
631
+ parseValue(value) {
632
+ if (value) {
633
+ return parse(value, this.getFormat(), new Date());
634
+ }
635
+ return '';
636
+ }
637
+ }
638
+ window.customElements.define('gv-date-picker', GvDatePicker);