@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,812 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvDatePickerCalendar=void 0,require("./gv-date-picker-cell");const t=require("date-fns"),e=require("lit/directives/class-map"),i=require("../lib/events"),s=require("../lib/i18n"),a=require("lit"),o=require("lit/directives/until");class r extends a.LitElement{static get properties(){return{dateFrom:{type:Number},dateTo:{type:Number},disabledDates:{type:Array},hoveredDate:{type:Number},locale:{type:Object},max:{type:Number},min:{type:Number},month:{type:String},monthMode:{type:Boolean},next:{type:Boolean},prev:{type:Boolean},range:{type:Boolean},time:{type:Boolean},small:{type:Boolean,reflect:!0},strict:{type:Boolean},year:{type:String},yearMode:{type:Boolean},_dayNamesOfWeek:{type:Array,attribute:!1},_dimensions:{type:Array,attribute:!1},_hasGoToday:{type:Boolean,attribute:!1},_hour:{type:Number,attribute:!1},_minute:{type:Number,attribute:!1},_second:{type:Number,attribute:!1},_monthsList:{type:Array,attribute:!1},_locale:{type:Object,attribute:!1},_from:{type:Number,attribute:!1},_to:{type:Number,attribute:!1}}}static get styles(){return[a.css`:host{display:block}:host>div{overflow:hidden}.foot,.nav,.nav-times{display:flex;padding:.5rem;height:30px}.foot,.nav .current{flex:1;display:flex;justify-content:center}.day,.monthName{text-transform:capitalize}.foot-time{justify-content:flex-end}.calendar-grid{display:grid;grid-template-columns:repeat(7,1fr);padding:.5rem .5rem 0 .5rem}.calendar-grid-large{grid-template-columns:repeat(3,1fr)}.content,.header{display:grid;grid-template-columns:repeat(2,auto)}gv-date-picker-cell{height:32px}.calendar-grid-large gv-date-picker-cell{height:48px}.calendar-grid,.foot,.time{border-top:1px solid var(--gv-theme-neutral-color-dark)}.nav-times{justify-content:center;align-items:center}.nav-times,.time{border-left:1px solid var(--gv-theme-neutral-color-dark)}.day{height:32px;width:33px;margin:0;padding:0;display:flex;justify-content:center;align-items:center;font-size:12px}:host([small]) .day{height:25px;width:26px}.box-col,.times{display:flex}.box-col{flex-direction:column}.box-col:first-of-type{width:260px}:host([small]) .box-col:first-of-type{width:195px}.box{display:flex}.times{max-height:235px;flex-direction:row}.time{scroll-behavior:smooth;overflow-x:auto;min-width:50px;width:100%}.time>div{height:32px;display:flex;justify-content:center;align-items:center}:host([small]) .time>div{height:25px}.time>div:hover{background:var(--gv-date-picker-hover--bgc,var(--gv-theme-color-light,#86c3d0));color:var(--gv-date-picker-hover--c,var(--gv-theme-font-color-dark,#262626))}.time>div.selected{background:var(--gv-date-picker-selected--bgc,var(--gv-theme-color,#5a7684));color:var(--gv-date-picker-selected--c,var(--gv-theme-font-color-light,#fff))}.time>div.disabled{opacity:.4}`]}constructor(){super(),this._dayNamesOfWeek=[],this._monthsList=["01","02","03","04","05","06","07","08","09","10","11","12"],this.range=!1,this.currentDate=parseInt((0,t.format)((0,t.startOfDay)(Date.now()),"t"),10),this._hasGoToday=!0,this._hours=this.computeArrayOfTime(24),this._minutes=this.computeArrayOfTime(60),this._seconds=this.computeArrayOfTime(60)}set dateFrom(e){if(this._from=e,this.time&&this._from){const e=new Date(1e3*this._from);this._hour=(0,t.format)(e,"HH"),this._minute=(0,t.format)(e,"mm"),this.isStrictTime()&&(this._second=(0,t.format)(e,"ss"))}}set dateTo(t){this._to=t}computeArrayOfTime(t){return new Array(t).fill("").map(((t,e)=>{let i=e.toString();return 1===i.length&&(i=`0${i}`),i}))}_renderPreviousNav(){return this.prev||this.monthMode||this.yearMode?a.html`<gv-button link icon="navigation:angle-double-left" @click="${this._onPrevYear}" ?small="${this.small}"></gv-button>${this.monthMode||this.yearMode?"":a.html`<gv-button link icon="navigation:angle-left" ?small="${this.small}" @click="${this._onPrevMonth}"></gv-button>`}`:""}_renderCurrentNav(){return a.html`<div class="current">${this.yearMode?"":a.html`<gv-button link @click="${this._onSelectMonth}" ?small="${this.small}"><span class="monthName">${(0,o.until)(this.computeName(this.month,this.year))}</span></gv-button>`}<gv-button ?small="${this.small}" link @click="${this._onSelectYear}">${this.computeCurrentYearName()}</gv-button></div>`}_renderNextNav(){if(this.next||this.monthMode||this.yearMode)return a.html`${this.monthMode||this.yearMode?"":a.html`<gv-button link icon="navigation:angle-right" ?small="${this.small}" @click="${this._onNextMonth}"></gv-button>`}<gv-button ?small="${this.small}" link icon="navigation:angle-double-right" @click="${this._onNextYear}"></gv-button>`}_renderDays(){return a.html`${this._dayNamesOfWeek&&this._dayNamesOfWeek.map((t=>a.html`<div class="day">${t}</div>`))} ${this._dimensions&&this._dimensions.map((t=>a.html`${t&&t.map((t=>a.html`<div>${t?a.html`<gv-date-picker-cell .disabledDates="${this.disabledDates}" .min="${this.monthMode||this.yearMode?null:this.min}" .max="${this.monthMode||this.yearMode?null:this.max}" .month="${this.month}" .hoveredDate="${this.hoveredDate}" .dateTo="${this._to}" .dateFrom="${this._from}" .data="${t}" .time="${this.time}" ?isCurrent="${this.isCurrentDate(t)}" @gv-date-picker-cell:hover="${this._onHover}" @gv-date-picker-cell:select="${this._onSelect}"></gv-date-picker-cell>`:null}</div>`))}`))}`}isStrictTime(){return!0===this.time&&!0===this.strict}render(){const t={"calendar-grid":!0,"calendar-grid-large":this.monthMode||this.yearMode};return a.html`<div class="box">${this.isStrictTime()?"":a.html`<div class="box-col"><div class="nav">${this._renderPreviousNav()} ${this._renderCurrentNav()} ${this._renderNextNav()}</div><div class="${(0,e.classMap)(t)}">${this._renderDays()}</div></div>`} ${!this.time||this.monthMode||this.yearMode?"":a.html`<div class="box-col">${this.isStrictTime()?"":a.html`<div class="nav-times">${this.getTime()}</div>`}<div class="times"><div class="time">${this._hours&&this._hours.map((t=>a.html`<div @click="${this._onSelectHour.bind(this,t)}" class="${(0,e.classMap)({hour:!0,selected:this._hour===t,disabled:this.isHoursDisabled(t)})}">${t}</div>`))}</div><div class="time">${this._minutes&&this._minutes.map((t=>a.html`<div @click="${this._onSelectMinute.bind(this,t)}" class="${(0,e.classMap)({minute:!0,selected:this._minute===t,disabled:this.isMinutesDisabled(t)})}">${t}</div>`))}</div>${this.isStrictTime()?a.html`<div class="time">${this._seconds&&this._seconds.map((t=>a.html`<div @click="${this._onSelectSecond.bind(this,t)}" class="${(0,e.classMap)({second:!0,selected:this._second===t,disabled:this.isSecondsDisabled(t)})}">${t}</div>`))}</div>`:""}</div></div>`}</div>${this.hasGoToday()?a.html`<div class="foot"><gv-button link @click="${this.goToday}">${(0,s.i18n)("gv-date-picker.today")}</gv-button></div>`:""} ${!this.time||this.monthMode||this.yearMode?"":a.html`<div class="foot foot-time"><gv-button primary outlined small @click="${this._onNow}">${this.isStrictTime()?(0,s.i18n)("gv-date-picker.currentTime"):(0,s.i18n)("gv-date-picker.now")}</gv-button><gv-button primary small @click="${this._onDateTimeSelected}" .disabled="${!0===this.disableValidation}">${(0,s.i18n)("gv-date-picker.ok")}</gv-button></div>`}`}isMinutesDisabled(e){if(this._from&&null!=this._hour){const i=new Date(1e3*this._from);if(i.setHours(parseInt(this._hour,10),parseInt(e,10),0,0),this.min){const e=new Date(1e3*this.min);if((0,t.isBefore)(i,e))return!0}if(this.max){const e=new Date(1e3*this.max);if((0,t.isAfter)(i,e))return!0}}return!1}isSecondsDisabled(e){if(this._from&&null!=this._hour){const i=new Date(1e3*this._from);if(i.setHours(parseInt(this._hour,10),parseInt(e,10),0,0),this.min){const e=new Date(1e3*this.min);if((0,t.isBefore)(i,e))return!0}if(this.max){const e=new Date(1e3*this.max);if((0,t.isAfter)(i,e))return!0}}return!1}isHoursDisabled(t){if(this._from){const e=new Date(1e3*this._from);if(e.setHours(parseInt(t,10)),this.min){const t=new Date(1e3*this.min);if(t.setMinutes(0,0,0),e.getTime()<t.getTime())return!0}if(this.max){const t=new Date(1e3*this.max);if(e.getTime()>t.getTime())return!0}}return!1}_updateTime(){setTimeout((()=>{if(!this._hour||this.isHoursDisabled(this._hour)){const t=this.shadowRoot.querySelector(".hour:not(.disabled)");t&&(this._hour=t.textContent)}}),0),setTimeout((()=>{if(!this._minute||this.isMinutesDisabled(this._minute)){const t=this.shadowRoot.querySelector(".minute:not(.disabled)");t&&(this._minute=t.textContent)}}),0),this.isStrictTime()&&setTimeout((()=>{if(!this._second||this.isSecondsDisabled(this._second)){const t=this.shadowRoot.querySelector(".second:not(.disabled)");t&&(this._second=t.textContent)}}),0)}getTime(){return this._hour&&this._minute?`${this._hour}:${this._minute}`:""}isCurrentDate(e){return this.yearMode?(0,t.getYear)(1e3*e.date)===(0,t.getYear)(1e3*this.currentDate):this.monthMode?(0,t.getMonth)(1e3*e.date)===(0,t.getMonth)(1e3*this.currentDate):e.date===this.currentDate}updated(t){t.has("year")&&this.dispatchEvent(new CustomEvent("year-changed",{detail:{value:this.year}})),(t.has("locale")||t.has("year")||t.has("month")||t.has("monthMode")||t.has("yearMode"))&&this.yearAndMonthChanged(this.year,this.month),(t.has("_hour")||t.has("_minute"))&&this.shadowRoot.querySelectorAll(".selected").forEach((t=>{t.parentNode.scrollTop=t.offsetTop-t.parentNode.offsetTop}))}_updateDays(){const t=[];for(let e=0;e<7;e+=1)t.push(this.locale.localize.day(e,{width:"short"}));const e=this.locale.options.weekStartsOn,i=t.slice().splice(0,e);this._dayNamesOfWeek=t.slice().splice(e,t.length).concat(i)}yearAndMonthChanged(e,i){if(e&&i&&this.locale)if(this.yearMode){this._dayNamesOfWeek=[];const s=[null],{start:a,end:o}=this.getYearInterval(e);for(let e=a;e<o;e++){const a=`01/${i}/${e}`,o=(0,t.parse)(a,"dd/MM/yyyy",new Date,{awareOfUnicodeTokens:!0});s.push({hover:!1,date:parseInt((0,t.format)(o,"t"),10),title:this.computeName(i,e,"yyyy")})}s.push(null),this._dimensions=[s]}else if(this.monthMode)this._dayNamesOfWeek=[],this._dimensions=[this._monthsList.map((i=>{const s=`01/${i}/${e}`,a=(0,t.parse)(s,"dd/MM/yyyy",new Date,{awareOfUnicodeTokens:!0});return{hover:!1,date:parseInt((0,t.format)(a,"t"),10),title:this.computeName(i,this.year,"MMM")}}))];else{this._updateDays();let s=i;s=s.substring(s.length-2);let a=`01/${s}/${e}`,o=(0,t.parse)(a,"dd/MM/yyyy",new Date,{awareOfUnicodeTokens:!0});const r=(0,t.endOfMonth)(o),h=(0,t.format)(r,"dd/MM/yyyy",{awareOfUnicodeTokens:!0}),n=this.locale.options.weekStartsOn,d=[];let l=[];const m=6;for(;a!==h;){let e=(0,t.getDay)(o)-n;e<0&&(e=6);const i={hover:!1,date:parseInt((0,t.format)(o,"t"),10),title:parseInt((0,t.format)(o,"d",{awareOfUnicodeTokens:!0}),10)};if(l.push(i),e===m){for(let t=l.length;t<m+1;t+=1)l.unshift(0);d.push(l.slice()),l=[]}if(o=(0,t.addDays)(o,1),a=(0,t.format)(o,"dd/MM/yyyy",{awareOfUnicodeTokens:!0}),a===h){const e={hover:!1,date:parseInt((0,t.format)(o,"t"),10),title:parseInt((0,t.format)(o,"d",{awareOfUnicodeTokens:!0}),10)};l.push(e);for(let t=l.length;t<=m;t+=1)l.push(0);d.push(l.slice()),l=[]}}this._dimensions=d}}getYearInterval(t=this.year){let e=parseInt(t,10);for(;e%10!=0;)e--;return{start:e,end:e+10}}computeName(e,i,s="MMMM"){if(e&&i){const a=(0,t.parse)(`${e}/${i}`,"MM/yyyy",new Date);return(0,t.format)(a,s,{locale:this.locale})}return""}computeCurrentYearName(){if(this.yearMode){const{start:t,end:e}=this.getYearInterval();return`${t}-${e-1}`}return this.year}_onSelectHour(t){this._hour=t,this._updateTime()}_onSelectMinute(t){this._minute=t,this._updateTime()}_onSelectSecond(t){this._second=t,this._updateTime()}_onSelectMonth(){this.monthMode?this._from=this._dateFrom:(this._dateFrom=this._from,this._from=null),this.yearMode=!1,this.monthMode=!this.monthMode,this.yearAndMonthChanged(this.year,this.month),(0,i.dispatchCustomEvent)(this,"month-mode",{mode:this.monthMode,month:this.month,year:this.year})}_onSelectYear(){this.yearMode?this._from=this._dateFrom:(this._dateFrom=this._from,this._from=null),this.monthMode=!1,this.yearMode=!this.yearMode,this.yearAndMonthChanged(this.year,this.month),(0,i.dispatchCustomEvent)(this,"year-mode",{mode:this.yearMode,month:this.month,year:this.year})}get datetimeSelected(){this.isStrictTime()&&null==this._from&&(this._from=(new Date).valueOf()/1e3);let e=new Date(1e3*this._from);return e=(0,t.setHours)(e,parseInt(this._hour?this._hour:0,10)),e=(0,t.setMinutes)(e,parseInt(this._minute?this._minute:0,10)),e.getTime()/1e3}_onDateTimeSelected(){this.value=this.datetimeSelected,this.dispatchEvent(new CustomEvent("date-from-changed",{detail:{value:this.value}}))}_onNow(){const e=new Date;this.isStrictTime()||e.setSeconds(0,0),this._from=e.getTime()/1e3,this.month=(0,t.format)(e,"MM"),this.year=(0,t.format)(e,"yyyy"),this._hour=(0,t.format)(e,"HH"),this._minute=(0,t.format)(e,"mm"),this.isStrictTime()&&(this._second=(0,t.format)(e,"mm")),this.dispatchEvent(new CustomEvent("date-from-changed",{detail:{value:this._from}}))}get disableValidation(){const t=this.datetimeSelected;if(t){if(this.min&&t<this.min)return!0;if(this.max&&t>this.max)return!0}return!1}_onSelect({detail:e}){const{date:s}=e;if(this.yearMode){this.yearMode=!1,this.monthMode=!0,this._from=this._dateFrom;const e=new Date(1e3*s);this.year=(0,t.format)(e,"yyyy"),(0,i.dispatchCustomEvent)(this,"year-changed",{year:this.year})}else if(this.monthMode){this.monthMode=!1,this._from=this._dateFrom;const e=new Date(1e3*s);this.month=(0,t.format)(e,"MM"),this.year=(0,t.format)(e,"yyyy"),(0,i.dispatchCustomEvent)(this,"month-changed",{month:this.month,year:this.year})}else this.time?(this._from=s,this._updateTime()):this.range?(this._from&&this._to?(this._from=s,this._to=null,this.hoveredDate=void 0,this.dispatchEvent(new CustomEvent("hovered-date-changed",{detail:{value:this.hoveredDate}}))):!this._from||this._from&&s<this._from?this._from=s:(!this._to||this._to&&s>this._to)&&(this._to=s),this.dispatchEvent(new CustomEvent("date-from-changed",{detail:{value:this._from}})),this.dispatchEvent(new CustomEvent("date-to-changed",{detail:{value:this._to}}))):(this._from=s,this.dispatchEvent(new CustomEvent("date-from-changed",{detail:{value:this._from}})))}_onHover(t){this.range&&(this.hoveredDate=t.detail.date,this.dispatchEvent(new CustomEvent("hovered-date-changed",{detail:{value:this.hoveredDate}})))}_onNextMonth(){const e=(0,t.parse)(this.month,"MM",new Date),i=(0,t.addMonths)(e,1),s=(0,t.format)(i,"MM",{locale:this.locale});if(this.month=s,"01"===this.month){const e=(0,t.parse)(this.year,"yyyy",new Date),i=(0,t.addYears)(e,1),s=(0,t.format)(i,"yyyy",{locale:this.locale});this.year=s}}_onPrevMonth(){const e=(0,t.parse)(this.month,"MM",new Date),i=(0,t.subMonths)(e,1),s=(0,t.format)(i,"MM",{locale:this.locale});if(this.month=s,"12"===this.month){const e=(0,t.parse)(this.year,"yyyy",new Date),i=(0,t.subYears)(e,1),s=(0,t.format)(i,"yyyy",{locale:this.locale});this.year=s}}_onNextYear(){this.yearMode&&(this.year=parseInt(this.year,10)+10);const e=(0,t.parse)(this.year,"yyyy",new Date),i=(0,t.addYears)(e,1),s=(0,t.format)(i,"yyyy",{locale:this.locale});this.year=s}_onPrevYear(){this.yearMode&&(this.year=parseInt(this.year,10)-10);const e=(0,t.parse)(this.year,"yyyy",new Date),i=(0,t.subYears)(e,1),s=(0,t.format)(i,"yyyy",{locale:this.locale});this.year=s}goToday(){this.month=`0${(0,t.getMonth)(new Date)+1}`.slice(-2),this.year=(0,t.getYear)(new Date),this._onSelect({detail:{date:(new Date).getTime()/1e3}})}hasGoToday(){return!this.range&&!this.time&&!this.monthMode&&!this.yearMode&&this._hasGoToday}}exports.GvDatePickerCalendar=r,window.customElements.define("gv-date-picker-calendar",r);
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-cell';
17
+ import { addDays, addMonths, addYears, endOfMonth, format, getDay, getMonth, getYear, isAfter, isBefore, parse, setHours, setMinutes, startOfDay, subMonths, subYears, } from 'date-fns';
18
+ import { classMap } from 'lit/directives/class-map';
19
+ import { dispatchCustomEvent } from '../lib/events';
20
+ import { i18n } from '../lib/i18n';
21
+ import { LitElement, css, html } from 'lit';
22
+ import { until } from 'lit/directives/until';
23
+ /**
24
+ * Date Picker Calendar
25
+ *
26
+ * ## Details
27
+ * * has @theme facet
28
+ *
29
+ * @fires gv-date-picker-cell:select - Custom event when user select cell
30
+ * @fires gv-date-picker-cell:hover - Custom event when user hover cell
31
+ *
32
+ * @attr {Number} dateFrom - unix date form
33
+ * @attr {Number} dateTo - unix date to
34
+ * @attr {Array} disabledDates - array of disabled date
35
+ * @attr {Number} hoveredDate - unix hovered date
36
+ * @attr {Number} min - unix min date
37
+ * @attr {Number} max - unix max date
38
+ * @attr {Object} locale - date-fns locale object
39
+ *
40
+ * @cssprop {Color} [--gv-date-picker-hover--bgc=var(--gv-theme-color-light, #86c3d0)] - Hover background color
41
+ * @cssprop {Color} [--gv-date-picker-hover--c=var(--gv-theme-font-color-dark, #262626)] - Hover color
42
+ * @cssprop {Color} [--gv-date-picker-selected--bgc=var(--gv-theme-color, #5a7684)] - Selected background color
43
+ * @cssprop {Color} [--gv-date-picker-selected--c=var(--gv-theme-font-color-light, #ffffff)] - Selected color
44
+ */
45
+ export class GvDatePickerCalendar extends LitElement {
46
+ static get properties() {
47
+ return {
48
+ dateFrom: { type: Number },
49
+ dateTo: { type: Number },
50
+ disabledDates: { type: Array },
51
+ hoveredDate: { type: Number },
52
+ locale: { type: Object },
53
+ max: { type: Number },
54
+ min: { type: Number },
55
+ month: { type: String },
56
+ monthMode: { type: Boolean },
57
+ next: { type: Boolean },
58
+ prev: { type: Boolean },
59
+ range: { type: Boolean },
60
+ time: { type: Boolean },
61
+ small: { type: Boolean, reflect: true },
62
+ strict: { type: Boolean },
63
+ year: { type: String },
64
+ yearMode: { type: Boolean },
65
+ _dayNamesOfWeek: { type: Array, attribute: false },
66
+ _dimensions: { type: Array, attribute: false },
67
+ _hasGoToday: { type: Boolean, attribute: false },
68
+ _hour: { type: Number, attribute: false },
69
+ _minute: { type: Number, attribute: false },
70
+ _second: { type: Number, attribute: false },
71
+ _monthsList: { type: Array, attribute: false },
72
+ _locale: { type: Object, attribute: false },
73
+ _from: { type: Number, attribute: false },
74
+ _to: { type: Number, attribute: false },
75
+ };
76
+ }
77
+ static get styles() {
78
+ return [
79
+ // language=CSS
80
+ css `
81
+ :host {
82
+ display: block;
83
+ }
84
+
85
+ :host > div {
86
+ overflow: hidden;
87
+ }
88
+
89
+ .nav,
90
+ .foot,
91
+ .nav-times {
92
+ display: flex;
93
+ padding: 0.5rem;
94
+ height: 30px;
95
+ }
96
+
97
+ .nav .current,
98
+ .foot {
99
+ flex: 1;
100
+ display: flex;
101
+ justify-content: center;
102
+ }
103
+
104
+ .monthName,
105
+ .day {
106
+ text-transform: capitalize;
107
+ }
108
+
109
+ .foot-time {
110
+ justify-content: flex-end;
111
+ }
112
+
113
+ .calendar-grid {
114
+ display: grid;
115
+ grid-template-columns: repeat(7, 1fr);
116
+ padding: 0.5rem 0.5rem 0 0.5rem;
117
+ }
118
+
119
+ .calendar-grid-large {
120
+ grid-template-columns: repeat(3, 1fr);
121
+ }
122
+
123
+ .header,
124
+ .content {
125
+ display: grid;
126
+ grid-template-columns: repeat(2, auto);
127
+ }
128
+
129
+ gv-date-picker-cell {
130
+ height: 32px;
131
+ }
132
+
133
+ .calendar-grid-large gv-date-picker-cell {
134
+ height: 48px;
135
+ }
136
+
137
+ .calendar-grid,
138
+ .foot,
139
+ .time {
140
+ border-top: 1px solid var(--gv-theme-neutral-color-dark);
141
+ }
142
+
143
+ .nav-times {
144
+ justify-content: center;
145
+ align-items: center;
146
+ }
147
+
148
+ .nav-times,
149
+ .time {
150
+ border-left: 1px solid var(--gv-theme-neutral-color-dark);
151
+ }
152
+
153
+ .day {
154
+ height: 32px;
155
+ width: 33px;
156
+ margin: 0;
157
+ padding: 0;
158
+ display: flex;
159
+ justify-content: center;
160
+ align-items: center;
161
+ font-size: 12px;
162
+ }
163
+
164
+ :host([small]) .day {
165
+ height: 25px;
166
+ width: 26px;
167
+ }
168
+
169
+ .box-col,
170
+ .times {
171
+ display: flex;
172
+ }
173
+
174
+ .box-col {
175
+ flex-direction: column;
176
+ }
177
+
178
+ .box-col:first-of-type {
179
+ width: 260px;
180
+ }
181
+
182
+ :host([small]) .box-col:first-of-type {
183
+ width: 195px;
184
+ }
185
+
186
+ .box {
187
+ display: flex;
188
+ }
189
+
190
+ .times {
191
+ max-height: 235px;
192
+ flex-direction: row;
193
+ }
194
+
195
+ .time {
196
+ scroll-behavior: smooth;
197
+ overflow-x: auto;
198
+ min-width: 50px;
199
+ width: 100%;
200
+ }
201
+
202
+ .time > div {
203
+ height: 32px;
204
+ display: flex;
205
+ justify-content: center;
206
+ align-items: center;
207
+ }
208
+
209
+ :host([small]) .time > div {
210
+ height: 25px;
211
+ }
212
+
213
+ .time > div:hover {
214
+ background: var(--gv-date-picker-hover--bgc, var(--gv-theme-color-light, #86c3d0));
215
+ color: var(--gv-date-picker-hover--c, var(--gv-theme-font-color-dark, #262626));
216
+ }
217
+
218
+ .time > div.selected {
219
+ background: var(--gv-date-picker-selected--bgc, var(--gv-theme-color, #5a7684));
220
+ color: var(--gv-date-picker-selected--c, var(--gv-theme-font-color-light, #ffffff));
221
+ }
222
+
223
+ .time > div.disabled {
224
+ opacity: 0.4;
225
+ }
226
+ `,
227
+ ];
228
+ }
229
+ constructor() {
230
+ super();
231
+ this._dayNamesOfWeek = [];
232
+ this._monthsList = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
233
+ this.range = false;
234
+ this.currentDate = parseInt(format(startOfDay(Date.now()), 't'), 10);
235
+ this._hasGoToday = true;
236
+ this._hours = this.computeArrayOfTime(24);
237
+ this._minutes = this.computeArrayOfTime(60);
238
+ this._seconds = this.computeArrayOfTime(60);
239
+ }
240
+ set dateFrom(value) {
241
+ this._from = value;
242
+ if (this.time && this._from) {
243
+ const date = new Date(this._from * 1000);
244
+ this._hour = format(date, 'HH');
245
+ this._minute = format(date, 'mm');
246
+ if (this.isStrictTime()) {
247
+ this._second = format(date, 'ss');
248
+ }
249
+ }
250
+ }
251
+ set dateTo(value) {
252
+ this._to = value;
253
+ }
254
+ computeArrayOfTime(size) {
255
+ return new Array(size).fill('').map((a, i) => {
256
+ let time = i.toString();
257
+ if (time.length === 1) {
258
+ time = `0${time}`;
259
+ }
260
+ return time;
261
+ });
262
+ }
263
+ _renderPreviousNav() {
264
+ if (this.prev || this.monthMode || this.yearMode) {
265
+ return html `
266
+ <gv-button link icon="navigation:angle-double-left" @click="${this._onPrevYear}" ?small="${this.small}"></gv-button>
267
+ ${this.monthMode || this.yearMode
268
+ ? ''
269
+ : html `<gv-button link icon="navigation:angle-left" ?small="${this.small}" @click="${this._onPrevMonth}"></gv-button>`}
270
+ `;
271
+ }
272
+ return '';
273
+ }
274
+ _renderCurrentNav() {
275
+ return html `
276
+ <div class="current">
277
+ ${this.yearMode
278
+ ? ''
279
+ : html `<gv-button link @click="${this._onSelectMonth}" ?small="${this.small}"
280
+ ><span class="monthName">${until(this.computeName(this.month, this.year))}</span></gv-button
281
+ >`}
282
+ <gv-button ?small="${this.small}" link @click="${this._onSelectYear}">${this.computeCurrentYearName()}</gv-button>
283
+ </div>
284
+ `;
285
+ }
286
+ _renderNextNav() {
287
+ if (this.next || this.monthMode || this.yearMode) {
288
+ return html `
289
+ ${this.monthMode || this.yearMode
290
+ ? ''
291
+ : html `<gv-button link icon="navigation:angle-right" ?small="${this.small}" @click="${this._onNextMonth}"></gv-button>`}
292
+ <gv-button ?small="${this.small}" link icon="navigation:angle-double-right" @click="${this._onNextYear}"></gv-button>
293
+ `;
294
+ }
295
+ }
296
+ _renderDays() {
297
+ return html ` ${this._dayNamesOfWeek && this._dayNamesOfWeek.map((dayNameOfWeek) => html `<div class="day">${dayNameOfWeek}</div>`)}
298
+ ${this._dimensions &&
299
+ this._dimensions.map((dimension) => html `${dimension &&
300
+ dimension.map((data) => html ` <div>
301
+ ${data
302
+ ? html `
303
+ <gv-date-picker-cell
304
+ .disabledDates="${this.disabledDates}"
305
+ .min="${this.monthMode || this.yearMode ? null : this.min}"
306
+ .max="${this.monthMode || this.yearMode ? null : this.max}"
307
+ .month="${this.month}"
308
+ .hoveredDate="${this.hoveredDate}"
309
+ .dateTo="${this._to}"
310
+ .dateFrom="${this._from}"
311
+ .data="${data}"
312
+ .time="${this.time}"
313
+ ?isCurrent="${this.isCurrentDate(data)}"
314
+ @gv-date-picker-cell:hover="${this._onHover}"
315
+ @gv-date-picker-cell:select="${this._onSelect}"
316
+ ></gv-date-picker-cell>
317
+ `
318
+ : null}
319
+ </div>`)}`)}`;
320
+ }
321
+ isStrictTime() {
322
+ return this.time === true && this.strict === true;
323
+ }
324
+ render() {
325
+ const classes = {
326
+ 'calendar-grid': true,
327
+ 'calendar-grid-large': this.monthMode || this.yearMode,
328
+ };
329
+ return html `
330
+ <div class="box">
331
+ ${this.isStrictTime()
332
+ ? ''
333
+ : html `<div class="box-col">
334
+ <div class="nav">${this._renderPreviousNav()} ${this._renderCurrentNav()} ${this._renderNextNav()}</div>
335
+ <div class="${classMap(classes)}">${this._renderDays()}</div>
336
+ </div>`}
337
+ ${this.time && !this.monthMode && !this.yearMode
338
+ ? html `<div class="box-col">
339
+ ${this.isStrictTime() ? '' : html `<div class="nav-times">${this.getTime()}</div>`}
340
+ <div class="times">
341
+ <div class="time">
342
+ ${this._hours &&
343
+ this._hours.map((val) => html `<div
344
+ @click="${this._onSelectHour.bind(this, val)}"
345
+ class="${classMap({
346
+ hour: true,
347
+ selected: this._hour === val,
348
+ disabled: this.isHoursDisabled(val),
349
+ })}"
350
+ >
351
+ ${val}
352
+ </div>`)}
353
+ </div>
354
+ <div class="time">
355
+ ${this._minutes &&
356
+ this._minutes.map((val) => html `<div
357
+ @click="${this._onSelectMinute.bind(this, val)}"
358
+ class="${classMap({
359
+ minute: true,
360
+ selected: this._minute === val,
361
+ disabled: this.isMinutesDisabled(val),
362
+ })}"
363
+ >
364
+ ${val}
365
+ </div>`)}
366
+ </div>
367
+
368
+ ${this.isStrictTime()
369
+ ? html `<div class="time">
370
+ ${this._seconds &&
371
+ this._seconds.map((val) => html `<div
372
+ @click="${this._onSelectSecond.bind(this, val)}"
373
+ class="${classMap({
374
+ second: true,
375
+ selected: this._second === val,
376
+ disabled: this.isSecondsDisabled(val),
377
+ })}"
378
+ >
379
+ ${val}
380
+ </div>`)}
381
+ </div>`
382
+ : ''}
383
+ </div>
384
+ </div>`
385
+ : ''}
386
+ </div>
387
+ ${this.hasGoToday()
388
+ ? html ` <div class="foot">
389
+ <gv-button link @click=${this.goToday}>${i18n('gv-date-picker.today')}</gv-button>
390
+ </div>`
391
+ : ''}
392
+ ${this.time && !this.monthMode && !this.yearMode
393
+ ? html ` <div class="foot foot-time">
394
+ <gv-button primary outlined small @click=${this._onNow}
395
+ >${this.isStrictTime() ? i18n('gv-date-picker.currentTime') : i18n('gv-date-picker.now')}</gv-button
396
+ >
397
+ <gv-button primary small @click=${this._onDateTimeSelected} .disabled="${this.disableValidation === true}"
398
+ >${i18n('gv-date-picker.ok')}</gv-button
399
+ >
400
+ </div>`
401
+ : ''}
402
+ `;
403
+ }
404
+ isMinutesDisabled(value) {
405
+ if (this._from && this._hour != null) {
406
+ const selectedDate = new Date(this._from * 1000);
407
+ selectedDate.setHours(parseInt(this._hour, 10), parseInt(value, 10), 0, 0);
408
+ if (this.min) {
409
+ const minDate = new Date(this.min * 1000);
410
+ if (isBefore(selectedDate, minDate)) {
411
+ return true;
412
+ }
413
+ }
414
+ if (this.max) {
415
+ const maxDate = new Date(this.max * 1000);
416
+ if (isAfter(selectedDate, maxDate)) {
417
+ return true;
418
+ }
419
+ }
420
+ }
421
+ return false;
422
+ }
423
+ isSecondsDisabled(value) {
424
+ if (this._from && this._hour != null) {
425
+ const selectedDate = new Date(this._from * 1000);
426
+ selectedDate.setHours(parseInt(this._hour, 10), parseInt(value, 10), 0, 0);
427
+ if (this.min) {
428
+ const minDate = new Date(this.min * 1000);
429
+ if (isBefore(selectedDate, minDate)) {
430
+ return true;
431
+ }
432
+ }
433
+ if (this.max) {
434
+ const maxDate = new Date(this.max * 1000);
435
+ if (isAfter(selectedDate, maxDate)) {
436
+ return true;
437
+ }
438
+ }
439
+ }
440
+ return false;
441
+ }
442
+ isHoursDisabled(value) {
443
+ if (this._from) {
444
+ const selectedDate = new Date(this._from * 1000);
445
+ selectedDate.setHours(parseInt(value, 10));
446
+ if (this.min) {
447
+ const minDate = new Date(this.min * 1000);
448
+ minDate.setMinutes(0, 0, 0);
449
+ if (selectedDate.getTime() < minDate.getTime()) {
450
+ return true;
451
+ }
452
+ }
453
+ if (this.max) {
454
+ const maxDate = new Date(this.max * 1000);
455
+ if (selectedDate.getTime() > maxDate.getTime()) {
456
+ return true;
457
+ }
458
+ }
459
+ }
460
+ return false;
461
+ }
462
+ _updateTime() {
463
+ setTimeout(() => {
464
+ if (!this._hour || this.isHoursDisabled(this._hour)) {
465
+ const hour = this.shadowRoot.querySelector('.hour:not(.disabled)');
466
+ if (hour) {
467
+ this._hour = hour.textContent;
468
+ }
469
+ }
470
+ }, 0);
471
+ setTimeout(() => {
472
+ if (!this._minute || this.isMinutesDisabled(this._minute)) {
473
+ const minute = this.shadowRoot.querySelector('.minute:not(.disabled)');
474
+ if (minute) {
475
+ this._minute = minute.textContent;
476
+ }
477
+ }
478
+ }, 0);
479
+ if (this.isStrictTime()) {
480
+ setTimeout(() => {
481
+ if (!this._second || this.isSecondsDisabled(this._second)) {
482
+ const second = this.shadowRoot.querySelector('.second:not(.disabled)');
483
+ if (second) {
484
+ this._second = second.textContent;
485
+ }
486
+ }
487
+ }, 0);
488
+ }
489
+ }
490
+ getTime() {
491
+ if (this._hour && this._minute) {
492
+ return `${this._hour}:${this._minute}`;
493
+ }
494
+ return '';
495
+ }
496
+ isCurrentDate(data) {
497
+ if (this.yearMode) {
498
+ return getYear(data.date * 1000) === getYear(this.currentDate * 1000);
499
+ }
500
+ else if (this.monthMode) {
501
+ return getMonth(data.date * 1000) === getMonth(this.currentDate * 1000);
502
+ }
503
+ return data.date === this.currentDate;
504
+ }
505
+ updated(properties) {
506
+ if (properties.has('year')) {
507
+ this.dispatchEvent(new CustomEvent('year-changed', { detail: { value: this.year } }));
508
+ }
509
+ if (properties.has('locale') ||
510
+ properties.has('year') ||
511
+ properties.has('month') ||
512
+ properties.has('monthMode') ||
513
+ properties.has('yearMode')) {
514
+ this.yearAndMonthChanged(this.year, this.month);
515
+ }
516
+ if (properties.has('_hour') || properties.has('_minute')) {
517
+ this.shadowRoot.querySelectorAll('.selected').forEach((time) => {
518
+ time.parentNode.scrollTop = time.offsetTop - time.parentNode.offsetTop;
519
+ });
520
+ }
521
+ }
522
+ _updateDays() {
523
+ const dayNames = [];
524
+ for (let i = 0; i < 7; i += 1) {
525
+ dayNames.push(this.locale.localize.day(i, { width: 'short' }));
526
+ }
527
+ const firstDayOfWeek = this.locale.options.weekStartsOn;
528
+ const tmp = dayNames.slice().splice(0, firstDayOfWeek);
529
+ this._dayNamesOfWeek = dayNames.slice().splice(firstDayOfWeek, dayNames.length).concat(tmp);
530
+ }
531
+ yearAndMonthChanged(year, month) {
532
+ if (year && month && this.locale) {
533
+ if (this.yearMode) {
534
+ this._dayNamesOfWeek = [];
535
+ const cols = [null];
536
+ const { start, end } = this.getYearInterval(year);
537
+ for (let c = start; c < end; c++) {
538
+ const startDateString = `01/${month}/${c}`;
539
+ const startDateFn = parse(startDateString, 'dd/MM/yyyy', new Date(), { awareOfUnicodeTokens: true });
540
+ cols.push({
541
+ hover: false,
542
+ date: parseInt(format(startDateFn, 't'), 10),
543
+ title: this.computeName(month, c, 'yyyy'),
544
+ });
545
+ }
546
+ cols.push(null);
547
+ this._dimensions = [cols];
548
+ }
549
+ else if (this.monthMode) {
550
+ this._dayNamesOfWeek = [];
551
+ this._dimensions = [
552
+ this._monthsList.map((month) => {
553
+ const startDateString = `01/${month}/${year}`;
554
+ const startDateFn = parse(startDateString, 'dd/MM/yyyy', new Date(), { awareOfUnicodeTokens: true });
555
+ return {
556
+ hover: false,
557
+ date: parseInt(format(startDateFn, 't'), 10),
558
+ title: this.computeName(month, this.year, 'MMM'),
559
+ };
560
+ }),
561
+ ];
562
+ }
563
+ else {
564
+ this._updateDays();
565
+ let monthMinus = month;
566
+ monthMinus = monthMinus.substring(monthMinus.length - 2);
567
+ let startDateString = `01/${monthMinus}/${year}`;
568
+ let startDateFn = parse(startDateString, 'dd/MM/yyyy', new Date(), { awareOfUnicodeTokens: true });
569
+ const endDateFn = endOfMonth(startDateFn);
570
+ const endDateString = format(endDateFn, 'dd/MM/yyyy', { awareOfUnicodeTokens: true });
571
+ const firstDayOfWeek = this.locale.options.weekStartsOn;
572
+ const rows = [];
573
+ let columns = [];
574
+ const lastDayOfWeek = 6;
575
+ while (startDateString !== endDateString) {
576
+ let dayNumberFn = getDay(startDateFn) - firstDayOfWeek;
577
+ if (dayNumberFn < 0) {
578
+ dayNumberFn = 6;
579
+ }
580
+ const columnFn = {
581
+ hover: false,
582
+ date: parseInt(format(startDateFn, 't'), 10),
583
+ title: parseInt(format(startDateFn, 'd', { awareOfUnicodeTokens: true }), 10),
584
+ };
585
+ columns.push(columnFn);
586
+ if (dayNumberFn === lastDayOfWeek) {
587
+ for (let i = columns.length; i < lastDayOfWeek + 1; i += 1) {
588
+ columns.unshift(0);
589
+ }
590
+ rows.push(columns.slice());
591
+ columns = [];
592
+ }
593
+ startDateFn = addDays(startDateFn, 1);
594
+ startDateString = format(startDateFn, 'dd/MM/yyyy', { awareOfUnicodeTokens: true });
595
+ if (startDateString === endDateString) {
596
+ const endColumnFn = {
597
+ hover: false,
598
+ date: parseInt(format(startDateFn, 't'), 10),
599
+ title: parseInt(format(startDateFn, 'd', { awareOfUnicodeTokens: true }), 10),
600
+ };
601
+ columns.push(endColumnFn);
602
+ for (let i = columns.length; i <= lastDayOfWeek; i += 1) {
603
+ columns.push(0);
604
+ }
605
+ rows.push(columns.slice());
606
+ columns = [];
607
+ }
608
+ }
609
+ this._dimensions = rows;
610
+ }
611
+ }
612
+ }
613
+ getYearInterval(year = this.year) {
614
+ let start = parseInt(year, 10);
615
+ while (start % 10 !== 0) {
616
+ start--;
617
+ }
618
+ return { start, end: start + 10 };
619
+ }
620
+ computeName(month, year, _format = 'MMMM') {
621
+ if (month && year) {
622
+ const dateFn = parse(`${month}/${year}`, 'MM/yyyy', new Date());
623
+ return format(dateFn, _format, { locale: this.locale });
624
+ }
625
+ return '';
626
+ }
627
+ computeCurrentYearName() {
628
+ if (this.yearMode) {
629
+ const { start, end } = this.getYearInterval();
630
+ return `${start}-${end - 1}`;
631
+ }
632
+ return this.year;
633
+ }
634
+ _onSelectHour(value) {
635
+ this._hour = value;
636
+ this._updateTime();
637
+ }
638
+ _onSelectMinute(value) {
639
+ this._minute = value;
640
+ this._updateTime();
641
+ }
642
+ _onSelectSecond(value) {
643
+ this._second = value;
644
+ this._updateTime();
645
+ }
646
+ _onSelectMonth() {
647
+ if (this.monthMode) {
648
+ this._from = this._dateFrom;
649
+ }
650
+ else {
651
+ this._dateFrom = this._from;
652
+ this._from = null;
653
+ }
654
+ this.yearMode = false;
655
+ this.monthMode = !this.monthMode;
656
+ this.yearAndMonthChanged(this.year, this.month);
657
+ dispatchCustomEvent(this, 'month-mode', { mode: this.monthMode, month: this.month, year: this.year });
658
+ }
659
+ _onSelectYear() {
660
+ if (this.yearMode) {
661
+ this._from = this._dateFrom;
662
+ }
663
+ else {
664
+ this._dateFrom = this._from;
665
+ this._from = null;
666
+ }
667
+ this.monthMode = false;
668
+ this.yearMode = !this.yearMode;
669
+ this.yearAndMonthChanged(this.year, this.month);
670
+ dispatchCustomEvent(this, 'year-mode', { mode: this.yearMode, month: this.month, year: this.year });
671
+ }
672
+ get datetimeSelected() {
673
+ if (this.isStrictTime() && this._from == null) {
674
+ this._from = new Date().valueOf() / 1000;
675
+ }
676
+ let selectedDate = new Date(this._from * 1000);
677
+ selectedDate = setHours(selectedDate, parseInt(this._hour ? this._hour : 0, 10));
678
+ selectedDate = setMinutes(selectedDate, parseInt(this._minute ? this._minute : 0, 10));
679
+ return selectedDate.getTime() / 1000;
680
+ }
681
+ _onDateTimeSelected() {
682
+ this.value = this.datetimeSelected;
683
+ this.dispatchEvent(new CustomEvent('date-from-changed', { detail: { value: this.value } }));
684
+ }
685
+ _onNow() {
686
+ const now = new Date();
687
+ if (!this.isStrictTime()) {
688
+ now.setSeconds(0, 0);
689
+ }
690
+ this._from = now.getTime() / 1000;
691
+ this.month = format(now, 'MM');
692
+ this.year = format(now, 'yyyy');
693
+ this._hour = format(now, 'HH');
694
+ this._minute = format(now, 'mm');
695
+ if (this.isStrictTime()) {
696
+ this._second = format(now, 'mm');
697
+ }
698
+ this.dispatchEvent(new CustomEvent('date-from-changed', { detail: { value: this._from } }));
699
+ }
700
+ get disableValidation() {
701
+ const date = this.datetimeSelected;
702
+ if (date) {
703
+ if (this.min && date < this.min) {
704
+ return true;
705
+ }
706
+ if (this.max && date > this.max) {
707
+ return true;
708
+ }
709
+ }
710
+ return false;
711
+ }
712
+ _onSelect({ detail }) {
713
+ const { date } = detail;
714
+ if (this.yearMode) {
715
+ this.yearMode = false;
716
+ this.monthMode = true;
717
+ this._from = this._dateFrom;
718
+ const selectedDate = new Date(date * 1000);
719
+ this.year = format(selectedDate, 'yyyy');
720
+ dispatchCustomEvent(this, 'year-changed', { year: this.year });
721
+ }
722
+ else if (this.monthMode) {
723
+ this.monthMode = false;
724
+ this._from = this._dateFrom;
725
+ const selectedDate = new Date(date * 1000);
726
+ this.month = format(selectedDate, 'MM');
727
+ this.year = format(selectedDate, 'yyyy');
728
+ dispatchCustomEvent(this, 'month-changed', { month: this.month, year: this.year });
729
+ }
730
+ else if (this.time) {
731
+ this._from = date;
732
+ this._updateTime();
733
+ }
734
+ else if (this.range) {
735
+ if (this._from && this._to) {
736
+ this._from = date;
737
+ this._to = null;
738
+ this.hoveredDate = undefined;
739
+ this.dispatchEvent(new CustomEvent('hovered-date-changed', { detail: { value: this.hoveredDate } }));
740
+ }
741
+ else if (!this._from || (this._from && date < this._from)) {
742
+ this._from = date;
743
+ }
744
+ else if (!this._to || (this._to && date > this._to)) {
745
+ this._to = date;
746
+ }
747
+ this.dispatchEvent(new CustomEvent('date-from-changed', { detail: { value: this._from } }));
748
+ this.dispatchEvent(new CustomEvent('date-to-changed', { detail: { value: this._to } }));
749
+ }
750
+ else {
751
+ this._from = date;
752
+ this.dispatchEvent(new CustomEvent('date-from-changed', { detail: { value: this._from } }));
753
+ }
754
+ }
755
+ _onHover(event) {
756
+ if (this.range) {
757
+ this.hoveredDate = event.detail.date;
758
+ this.dispatchEvent(new CustomEvent('hovered-date-changed', { detail: { value: this.hoveredDate } }));
759
+ }
760
+ }
761
+ _onNextMonth() {
762
+ const month = parse(this.month, 'MM', new Date());
763
+ const monthPlusDate = addMonths(month, 1);
764
+ const monthPlusString = format(monthPlusDate, 'MM', { locale: this.locale });
765
+ this.month = monthPlusString;
766
+ if (this.month === '01') {
767
+ const year = parse(this.year, 'yyyy', new Date());
768
+ const yearPlusDate = addYears(year, 1);
769
+ const yearPlusString = format(yearPlusDate, 'yyyy', { locale: this.locale });
770
+ this.year = yearPlusString;
771
+ }
772
+ }
773
+ _onPrevMonth() {
774
+ const month = parse(this.month, 'MM', new Date());
775
+ const monthMinusDate = subMonths(month, 1);
776
+ const monthMinusString = format(monthMinusDate, 'MM', { locale: this.locale });
777
+ this.month = monthMinusString;
778
+ if (this.month === '12') {
779
+ const year = parse(this.year, 'yyyy', new Date());
780
+ const yearMinusDate = subYears(year, 1);
781
+ const yearMinusString = format(yearMinusDate, 'yyyy', { locale: this.locale });
782
+ this.year = yearMinusString;
783
+ }
784
+ }
785
+ _onNextYear() {
786
+ if (this.yearMode) {
787
+ this.year = parseInt(this.year, 10) + 10;
788
+ }
789
+ const year = parse(this.year, 'yyyy', new Date());
790
+ const yearPlusDate = addYears(year, 1);
791
+ const yearPlusString = format(yearPlusDate, 'yyyy', { locale: this.locale });
792
+ this.year = yearPlusString;
793
+ }
794
+ _onPrevYear() {
795
+ if (this.yearMode) {
796
+ this.year = parseInt(this.year, 10) - 10;
797
+ }
798
+ const year = parse(this.year, 'yyyy', new Date());
799
+ const yearMinusDate = subYears(year, 1);
800
+ const yearMinusString = format(yearMinusDate, 'yyyy', { locale: this.locale });
801
+ this.year = yearMinusString;
802
+ }
803
+ goToday() {
804
+ this.month = `0${getMonth(new Date()) + 1}`.slice(-2);
805
+ this.year = getYear(new Date());
806
+ this._onSelect({ detail: { date: new Date().getTime() / 1000 } });
807
+ }
808
+ hasGoToday() {
809
+ return !this.range && !this.time && !this.monthMode && !this.yearMode && this._hasGoToday;
810
+ }
811
+ }
812
+ window.customElements.define('gv-date-picker-calendar', GvDatePickerCalendar);