@gravitee/ui-components 3.25.3-typescript-8a53edf → 3.25.3-typescript-9a4271f

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