@gez/date-time-kit 1.1.3 → 2.0.0-alpha.0

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 (77) hide show
  1. package/dist/assets/arrow-down.svg +1 -0
  2. package/dist/assets/arrow-left-double.svg +1 -0
  3. package/dist/assets/arrow-left.svg +1 -0
  4. package/dist/assets/arrow-right-double.svg +1 -0
  5. package/dist/assets/arrow-right.svg +1 -0
  6. package/dist/assets/back-arrow.svg +1 -0
  7. package/dist/assets/time.svg +1 -0
  8. package/dist/components/calendar/index.css +108 -0
  9. package/dist/components/calendar/index.d.ts +84 -0
  10. package/dist/components/calendar/index.mjs +238 -0
  11. package/dist/components/hhmmss-ms-list-grp/index.css +60 -0
  12. package/dist/components/hhmmss-ms-list-grp/index.d.ts +54 -0
  13. package/dist/components/hhmmss-ms-list-grp/index.mjs +226 -0
  14. package/dist/components/i18n/index.d.ts +13 -0
  15. package/dist/components/i18n/index.mjs +42 -0
  16. package/dist/components/num-list/index.css +35 -0
  17. package/dist/components/num-list/index.d.ts +68 -0
  18. package/dist/components/num-list/index.mjs +259 -0
  19. package/dist/components/period-selector/date-nav.css +92 -0
  20. package/dist/components/period-selector/date-nav.d.ts +64 -0
  21. package/dist/components/period-selector/date-nav.mjs +161 -0
  22. package/dist/components/period-selector/index.css +152 -0
  23. package/dist/components/period-selector/index.d.ts +68 -0
  24. package/dist/components/period-selector/index.mjs +312 -0
  25. package/dist/components/popover/index.d.ts +34 -0
  26. package/dist/components/popover/index.mjs +104 -0
  27. package/dist/components/quick-selector/index.css +167 -0
  28. package/dist/components/quick-selector/index.d.ts +74 -0
  29. package/dist/components/quick-selector/index.mjs +347 -0
  30. package/dist/components/web-component-base/index.css +9 -0
  31. package/dist/components/web-component-base/index.d.ts +46 -0
  32. package/dist/components/web-component-base/index.mjs +118 -0
  33. package/dist/components/web-component-base/scrollbar.css +25 -0
  34. package/dist/components/yyyymmdd-list-grp/index.css +32 -0
  35. package/dist/components/yyyymmdd-list-grp/index.d.ts +52 -0
  36. package/dist/components/yyyymmdd-list-grp/index.mjs +181 -0
  37. package/dist/i18n.d.ts +36 -0
  38. package/dist/i18n.mjs +368 -0
  39. package/dist/index.d.ts +7 -0
  40. package/dist/index.mjs +15 -0
  41. package/dist/utils.d.ts +12 -0
  42. package/dist/utils.mjs +21 -0
  43. package/package.json +37 -63
  44. package/src/assets/arrow-down.svg +1 -0
  45. package/src/assets/arrow-left-double.svg +1 -0
  46. package/src/assets/arrow-left.svg +1 -0
  47. package/src/assets/arrow-right-double.svg +1 -0
  48. package/src/assets/arrow-right.svg +1 -0
  49. package/src/assets/back-arrow.svg +1 -0
  50. package/src/assets/time.svg +1 -0
  51. package/src/components/calendar/index.scss +128 -0
  52. package/src/components/calendar/index.ts +453 -0
  53. package/src/components/hhmmss-ms-list-grp/index.scss +61 -0
  54. package/src/components/hhmmss-ms-list-grp/index.ts +387 -0
  55. package/src/components/i18n/index.ts +48 -0
  56. package/src/components/num-list/index.scss +38 -0
  57. package/src/components/num-list/index.ts +357 -0
  58. package/src/components/period-selector/date-nav.scss +108 -0
  59. package/src/components/period-selector/date-nav.ts +322 -0
  60. package/src/components/period-selector/index.scss +160 -0
  61. package/src/components/period-selector/index.ts +552 -0
  62. package/src/components/popover/index.ts +127 -0
  63. package/src/components/quick-selector/index.scss +183 -0
  64. package/src/components/quick-selector/index.ts +611 -0
  65. package/src/components/web-component-base/index.scss +11 -0
  66. package/src/components/web-component-base/index.ts +235 -0
  67. package/src/components/web-component-base/scrollbar.scss +30 -0
  68. package/src/components/yyyymmdd-list-grp/index.scss +33 -0
  69. package/src/components/yyyymmdd-list-grp/index.ts +257 -0
  70. package/src/i18n.ts +415 -0
  71. package/src/index.ts +12 -0
  72. package/src/utils.ts +36 -0
  73. package/README.md +0 -152
  74. package/dist/index.css +0 -1
  75. package/dist/index.html +0 -85
  76. package/dist/index.js +0 -145
  77. package/type.d.ts +0 -164
@@ -0,0 +1,611 @@
1
+ import type { DataLimit } from '../../i18n';
2
+ import { css, debounce, html } from '../../utils';
3
+ import { Ele as PeriodSelectorEle } from '../period-selector';
4
+ import {
5
+ type BaseAttrs,
6
+ type Emit2EventMap,
7
+ UiBase
8
+ } from '../web-component-base';
9
+ PeriodSelectorEle.define();
10
+ import { Ele as I18nEle } from '../i18n';
11
+ I18nEle.define();
12
+ import { type Weeks, weekKey } from '../calendar';
13
+ // import styleStr from './index.scss?inline';
14
+ const styleStr = css`
15
+ :host {
16
+ width: fit-content;
17
+ display: block;
18
+ }
19
+
20
+ .menu {
21
+ display: flex;
22
+ flex-direction: column;
23
+ align-items: center;
24
+ padding: 10px 5px;
25
+ font-size: 14px;
26
+ gap: 10px;
27
+ border-radius: 6px;
28
+ border: 1px solid #eee;
29
+ box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
30
+ background-color: #fff;
31
+ }
32
+ .menu > * {
33
+ width: 100%;
34
+ box-sizing: border-box;
35
+ }
36
+
37
+ .radio-grp {
38
+ display: flex;
39
+ flex-direction: column;
40
+ gap: 5px;
41
+ width: 100%;
42
+ }
43
+ .radio-grp > label {
44
+ display: flex;
45
+ align-items: center;
46
+ gap: 10px;
47
+ cursor: pointer;
48
+ padding: 5px;
49
+ }
50
+ .radio-grp > label:hover {
51
+ background-color: #f5f5f5;
52
+ }
53
+ .radio-grp dt-i18n {
54
+ flex: 1;
55
+ }
56
+ .radio-grp input {
57
+ margin: 0;
58
+ width: 24px;
59
+ height: 24px;
60
+ cursor: pointer;
61
+ }
62
+
63
+ .arrow-right-icon {
64
+ display: inline-block;
65
+ width: 15px;
66
+ height: 15px;
67
+ background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='17' height='17' fill='currentColor'%3E%3Cpath d='M5.256 1.703a.5.5 0 0 1 .707 0l6.128 6.128a.493.493 0 0 1 .045.05.5.5 0 0 1 .051.752l-6.128 6.128a.5.5 0 0 1-.707-.707l5.774-5.774-5.87-5.87a.5.5 0 0 1 0-.707Z'/%3E%3C/svg%3E") no-repeat center center;
68
+ cursor: pointer;
69
+ }
70
+
71
+ .dividing-line {
72
+ display: block;
73
+ height: 1px;
74
+ width: 100%;
75
+ background-color: #eee;
76
+ }
77
+
78
+ .tz-trigger {
79
+ display: flex;
80
+ align-items: center;
81
+ justify-content: space-between;
82
+ padding: 5px;
83
+ gap: 10px;
84
+ cursor: pointer;
85
+ white-space: nowrap;
86
+ }
87
+ .tz-trigger:hover {
88
+ background-color: #f5f5f5;
89
+ }
90
+ .tz-trigger bdo {
91
+ direction: ltr;
92
+ }
93
+
94
+ .title {
95
+ display: flex;
96
+ align-items: center;
97
+ padding: 5px;
98
+ gap: 10px;
99
+ font-weight: 700;
100
+ font-size: 18px;
101
+ box-sizing: border-box;
102
+ }
103
+ .title svg {
104
+ border: 5px solid transparent;
105
+ border-radius: 50%;
106
+ margin: -5px;
107
+ cursor: pointer;
108
+ }
109
+ .title svg:hover {
110
+ background-color: #eee;
111
+ border-color: #eee;
112
+ }
113
+
114
+ .menu.tz {
115
+ min-width: 180px;
116
+ max-height: 293px;
117
+ overflow: hidden auto;
118
+ }
119
+ .menu.tz fieldset {
120
+ width: 100%;
121
+ border: none;
122
+ border-top: 1px solid #eee;
123
+ margin: 0;
124
+ padding: 0;
125
+ display: flex;
126
+ flex-direction: column;
127
+ gap: 5px;
128
+ }
129
+ .menu.tz fieldset legend {
130
+ padding: 0 5px;
131
+ margin-bottom: 5px;
132
+ font-size: 12px;
133
+ line-height: 24px;
134
+ color: #666;
135
+ }
136
+ .menu.tz label {
137
+ display: flex;
138
+ align-items: center;
139
+ gap: 10px;
140
+ cursor: pointer;
141
+ padding: 5px;
142
+ }
143
+ .menu.tz label:hover {
144
+ background-color: #f5f5f5;
145
+ }
146
+ .menu.tz input {
147
+ margin: 0;
148
+ width: 24px;
149
+ height: 24px;
150
+ cursor: pointer;
151
+ }
152
+
153
+ button {
154
+ border: none;
155
+ min-height: 40px;
156
+ border-radius: 6px;
157
+ padding: 5px 15px;
158
+ font-size: 16px;
159
+ line-height: 1;
160
+ background-color: #18181B;
161
+ color: #fff;
162
+ font-weight: 500;
163
+ cursor: pointer;
164
+ }
165
+
166
+ .menu.custom {
167
+ padding: 14px;
168
+ gap: 15px;
169
+ }
170
+ .menu.custom dt-period-selector {
171
+ width: 590px;
172
+ }
173
+ .menu.custom .btns {
174
+ display: flex;
175
+ justify-content: flex-end;
176
+ gap: 10px;
177
+ }
178
+ .menu.custom #reset {
179
+ background-color: #E5E7E8;
180
+ color: #333;
181
+ }
182
+ `;
183
+ // import backArrowSvg from '../../assets/back-arrow.svg?raw';
184
+ // import ArrowRightSvg from '../../assets/arrow-right.svg?raw';
185
+ const backArrowSvg = html`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor"><path d="M9.894 5.106a.75.75 0 0 1 0 1.06L4.811 11.25 21 11.25a.75.75 0 0 1 0 1.5l-16.191-.001 5.085 5.085a.75.75 0 0 1-1.06 1.06L2.47 12.53a.75.75 0 0 1 0-1.06l6.364-6.364a.75.75 0 0 1 1.06 0Z"/></svg>`;
186
+ const ArrowRightSvg = html`<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" fill="currentColor"><path d="M5.256 1.703a.5.5 0 0 1 .707 0l6.128 6.128a.493.493 0 0 1 .045.05.5.5 0 0 1 .051.752l-6.128 6.128a.5.5 0 0 1-.707-.707l5.774-5.774-5.87-5.87a.5.5 0 0 1 0-.707Z"/></svg>`;
187
+
188
+ export type QuickKey = DataLimit | 'custom';
189
+
190
+ export interface Attrs extends BaseAttrs {
191
+ /**
192
+ * Timezone in minutes. For example: UTC+05:45 => `345`, UTC-01:00 => `-60`.
193
+ *
194
+ * @default
195
+ * -new Date().getTimezoneOffset() // local timezone in minutes
196
+ */
197
+ 'time-zone'?: number;
198
+ /**
199
+ * Set which day of the week is the first day.
200
+ * @type `'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat'`
201
+ * @default 'sun'
202
+ */
203
+ 'week-start-at'?: Weeks;
204
+ /**
205
+ * Quick selection key.
206
+ *
207
+ * @default 'all'
208
+ */
209
+ 'quick-key'?: QuickKey;
210
+ /**
211
+ * Start time of the quick selection. Only works in custom mode.
212
+ */
213
+ 'start-time'?: Date | null | 'null';
214
+ /**
215
+ * End time of the quick selection. Only works in custom mode.
216
+ */
217
+ 'end-time'?: Date | null | 'null';
218
+ }
219
+
220
+ export interface Emits {
221
+ 'time-changed':
222
+ | {
223
+ type: 'all';
224
+ start?: null;
225
+ end?: null;
226
+ }
227
+ | {
228
+ type: QuickKey;
229
+ start: Date;
230
+ end: Date;
231
+ };
232
+ }
233
+ export type EventMap = Emit2EventMap<Emits>;
234
+
235
+ const getCurrentTz = () => -new Date().getTimezoneOffset();
236
+
237
+ const utcText = (tz: number = getCurrentTz()) =>
238
+ tz >= 0
239
+ ? (`UTC+${(~~(tz / 60) + '').padStart(2, '0')}:${((tz % 60) + '').padStart(2, '0')}` as const)
240
+ : (`UTC-${(~~-(tz / 60) + '').padStart(2, '0')}:${((-tz % 60) + '').padStart(2, '0')}` as const);
241
+
242
+ const genTzRadio = (tz: number) =>
243
+ html`<label><input type="radio" name="tz" value="${tz}"/><span>${utcText(tz)}</span></label>`;
244
+
245
+ const genDateWithHours = (
246
+ isStart: boolean,
247
+ fn = (_t: Date) => {},
248
+ t = new Date()
249
+ ) => {
250
+ if (isStart) t.setHours(0, 0, 0, 0);
251
+ else t.setHours(23, 59, 59, 999);
252
+ fn(t);
253
+ return t;
254
+ };
255
+ const genStartDate = (fn?: (_t: Date) => void, t?: Date) =>
256
+ genDateWithHours(true, fn, t);
257
+ const genEndDate = (fn?: (_t: Date) => void, t?: Date) =>
258
+ genDateWithHours(false, fn, t);
259
+ const quickPeriodTimes = (weekOffset = 0) =>
260
+ ({
261
+ all: null,
262
+ today: {
263
+ start: genStartDate(),
264
+ end: genEndDate()
265
+ },
266
+ yesterday: {
267
+ start: genStartDate((t) => t.setDate(t.getDate() - 1)),
268
+ end: genEndDate((t) => t.setDate(t.getDate() - 1))
269
+ },
270
+ week: {
271
+ start: genStartDate((t) =>
272
+ t.setDate(t.getDate() - t.getDay() + weekOffset)
273
+ ),
274
+ end: genEndDate((t) =>
275
+ t.setDate(t.getDate() - t.getDay() + weekOffset + 6)
276
+ )
277
+ },
278
+ lastWeek: {
279
+ start: genStartDate((t) =>
280
+ t.setDate(t.getDate() - t.getDay() + weekOffset - 7)
281
+ ),
282
+ end: genEndDate((t) =>
283
+ t.setDate(t.getDate() - t.getDay() + weekOffset - 1)
284
+ )
285
+ },
286
+ last7Days: {
287
+ start: genStartDate((t) => t.setDate(t.getDate() - 6)),
288
+ end: genEndDate()
289
+ },
290
+ month: {
291
+ start: genStartDate((t) => t.setDate(1)),
292
+ end: genEndDate((t) => t.setMonth(t.getMonth() + 1, 0))
293
+ },
294
+ last30Days: {
295
+ start: genStartDate((t) => t.setDate(t.getDate() - 29)),
296
+ end: genEndDate()
297
+ },
298
+ last180Days: {
299
+ start: genStartDate((t) => t.setDate(t.getDate() - 179)),
300
+ end: genEndDate()
301
+ },
302
+ last6Month: {
303
+ start: genStartDate((t) => t.setMonth(t.getMonth() - 5, 1)),
304
+ end: genEndDate((t) => t.setMonth(t.getMonth() + 1, 0))
305
+ },
306
+ year: {
307
+ start: genStartDate((t) => t.setMonth(0, 1)),
308
+ end: genEndDate((t) => t.setFullYear(t.getFullYear() + 1, 0, 0))
309
+ }
310
+ }) as const;
311
+
312
+ /**
313
+ * 快速选择下拉选项
314
+ */
315
+ export class Ele extends UiBase<Attrs, Emits> {
316
+ public static readonly tagName = 'dt-quick-selector' as const;
317
+ static get observedAttributes(): string[] {
318
+ return [
319
+ ...(super.observedAttributes as (keyof BaseAttrs)[]),
320
+ 'time-zone',
321
+ 'week-start-at',
322
+ 'quick-key',
323
+ 'start-time',
324
+ 'end-time'
325
+ ] satisfies (keyof Attrs)[];
326
+ }
327
+
328
+ public get timezone() {
329
+ return +this._getAttr('time-zone', '' + getCurrentTz());
330
+ }
331
+ public set timezone(v: number) {
332
+ if (!Number.isSafeInteger(v)) return;
333
+ this.setAttribute('time-zone', '' + v);
334
+ }
335
+ public get quickKey() {
336
+ return this._getAttr('quick-key', 'all');
337
+ }
338
+ public set quickKey(val: QuickKey) {
339
+ if (
340
+ ![
341
+ 'all',
342
+ 'today',
343
+ 'yesterday',
344
+ 'week',
345
+ 'lastWeek',
346
+ 'last7Days',
347
+ 'month',
348
+ 'last30Days',
349
+ 'last180Days',
350
+ 'last6Month',
351
+ 'year',
352
+ 'custom'
353
+ ].includes(val)
354
+ ) {
355
+ return;
356
+ }
357
+ this.setAttribute('quick-key', val);
358
+ }
359
+ public get weekStartAt() {
360
+ return this._getAttr('week-start-at', 'sun');
361
+ }
362
+ public set weekStartAt(val: Weeks) {
363
+ if (weekKey.includes(val)) return;
364
+ this.setAttribute('week-start-at', val);
365
+ }
366
+
367
+ protected _style = styleStr;
368
+ protected _template = html`
369
+ <div class="menu top" part="menu top"
370
+ ><div class="radio-grp">${(
371
+ [
372
+ 'all',
373
+ 'today',
374
+ 'yesterday',
375
+ 'week',
376
+ 'lastWeek',
377
+ 'last7Days',
378
+ 'month',
379
+ 'last30Days',
380
+ 'last180Days',
381
+ 'last6Month',
382
+ 'year'
383
+ ] as QuickKey[]
384
+ )
385
+ .map(
386
+ (k) =>
387
+ html`<label
388
+ ><input type="radio" name="radio" value="${k}"
389
+ /><dt-i18n i18n-key="quick.${k}">${k}</dt-i18n
390
+ ></label>`
391
+ )
392
+ .join('')}<label class="custom-trigger"
393
+ ><input type="radio" name="radio" value="custom"
394
+ /><dt-i18n i18n-key="quick.custom">Custom</dt-i18n
395
+ >${ArrowRightSvg}</label
396
+ ></div
397
+ ><i class="dividing-line"></i
398
+ ><div class="tz-trigger"
399
+ ><span
400
+ ><dt-i18n i18n-key="quick.timezone"></dt-i18n
401
+ ><bdo>${utcText()}</bdo
402
+ ></span
403
+ >${ArrowRightSvg}</div
404
+ ></div
405
+ ><div class="menu tz" part="menu tz" style="display:none"
406
+ ><div class="title"
407
+ >${backArrowSvg}<span>Time Zone</span
408
+ ></div
409
+ ><fieldset class="subtitle"
410
+ ><legend><dt-i18n i18n-key="quick.recommend"></dt-i18n></legend
411
+ >${[...new Set([getCurrentTz(), 120])].map(genTzRadio).join('')}</fieldset
412
+ ><fieldset class="subtitle"
413
+ ><legend><dt-i18n i18n-key="quick.timezoneList"></dt-i18n></legend
414
+ >${[
415
+ -12, -11, -10, -9.5, -9, -8, -7, -6, -5, -4, -3, -3.5, -2, -1, 0, 1,
416
+ 2, 3, 3.5, 4, 4.5, 5, 5.5, 5.75, 6, 6.5, 7, 8, 8.75, 9, 9.5, 10,
417
+ 10.5, 11, 12, 12.45, 13, 14
418
+ ]
419
+ .map((tz) =>
420
+ tz === 2 || tz * 60 === getCurrentTz()
421
+ ? ''
422
+ : genTzRadio(tz * 60)
423
+ )
424
+ .join('')}</fieldset
425
+ ></div
426
+ ><div class="menu custom" part="menu custom" style="display:none"
427
+ ><div class="title"
428
+ >${backArrowSvg}<span>Custom</span
429
+ ></div
430
+ ><dt-period-selector></dt-period-selector
431
+ ><div class="btns"
432
+ ><button id="reset">Reset</button
433
+ ><button id="done">Done</button
434
+ ></div
435
+ ></div>`;
436
+
437
+ private get _periodSelector() {
438
+ return this.shadowRoot!.querySelector(
439
+ 'dt-period-selector'
440
+ ) as PeriodSelectorEle;
441
+ }
442
+
443
+ constructor() {
444
+ super();
445
+ this._applyTemplate();
446
+ }
447
+
448
+ public connectedCallback() {
449
+ if (!super.connectedCallback()) return;
450
+ this._renderTz();
451
+ this._updateRadio();
452
+ this.shadowRoot!.querySelector('.tz-trigger')?.addEventListener(
453
+ 'click',
454
+ this._onTzTriggerClick
455
+ );
456
+ this.shadowRoot!.querySelector('.custom-trigger')?.addEventListener(
457
+ 'click',
458
+ this._onCustomTriggerClick
459
+ );
460
+ this.shadowRoot!.querySelector('.menu.tz .title svg')?.addEventListener(
461
+ 'click',
462
+ this._onBackBtnClick
463
+ );
464
+ this.shadowRoot!.querySelector(
465
+ '.menu.custom .title svg'
466
+ )?.addEventListener('click', this._onBackBtnClick);
467
+ this.shadowRoot!.querySelectorAll('.menu').forEach((menu) => {
468
+ menu.addEventListener('change', this._onRadioChange);
469
+ });
470
+ this.shadowRoot!.querySelector('#reset')?.addEventListener(
471
+ 'click',
472
+ this._updatePeriodSelector
473
+ );
474
+ this.shadowRoot!.querySelector('#done')?.addEventListener(
475
+ 'click',
476
+ this._onDoneBtnClick
477
+ );
478
+ }
479
+ public disconnectedCallback() {
480
+ if (!super.disconnectedCallback()) return;
481
+ this.shadowRoot!.querySelector('.tz-trigger')?.removeEventListener(
482
+ 'click',
483
+ this._onTzTriggerClick
484
+ );
485
+ this.shadowRoot!.querySelector('.custom-trigger')?.removeEventListener(
486
+ 'click',
487
+ this._onCustomTriggerClick
488
+ );
489
+ this.shadowRoot!.querySelector(
490
+ '.menu.tz .title svg'
491
+ )?.removeEventListener('click', this._onBackBtnClick);
492
+ this.shadowRoot!.querySelector(
493
+ '.menu.custom .title svg'
494
+ )?.removeEventListener('click', this._onBackBtnClick);
495
+ this.shadowRoot!.querySelectorAll('.menu').forEach((menu) => {
496
+ menu.removeEventListener('change', this._onRadioChange);
497
+ });
498
+ this.shadowRoot!.querySelector('#reset')?.removeEventListener(
499
+ 'click',
500
+ this._updatePeriodSelector
501
+ );
502
+ this.shadowRoot!.querySelector('#done')?.removeEventListener(
503
+ 'click',
504
+ this._onDoneBtnClick
505
+ );
506
+ }
507
+
508
+ protected _onAttrChanged(name: string, oldValue: string, newValue: string) {
509
+ super._onAttrChanged(name, oldValue, newValue);
510
+ if (name === 'time-zone') {
511
+ this._renderTz();
512
+ }
513
+ if (name === 'quick-key') {
514
+ this._updateRadio();
515
+ }
516
+ }
517
+
518
+ private _updatePeriodSelector = debounce(() => {
519
+ if (
520
+ this.shadowRoot?.querySelector<HTMLElement>('.menu.custom')?.style
521
+ .display === 'none'
522
+ ) {
523
+ return;
524
+ }
525
+ const defaultPeriod = quickPeriodTimes().last30Days;
526
+ const ele = this._periodSelector;
527
+ ele.timeStart = defaultPeriod.start;
528
+ ele.timeEnd = defaultPeriod.end;
529
+ ele.showCalendarDatePoint();
530
+ }, 0);
531
+
532
+ private _renderTz = debounce(() => {
533
+ const tz = this.timezone;
534
+ const tzRadios =
535
+ this.shadowRoot!.querySelectorAll<HTMLInputElement>(
536
+ 'input[name="tz"]'
537
+ );
538
+ tzRadios!.forEach((radio) => {
539
+ radio.checked = +radio.value === tz;
540
+ });
541
+ this.shadowRoot!.querySelector('.tz-trigger bdo')!.textContent =
542
+ utcText(tz);
543
+ }, 0);
544
+ private _updateRadio = debounce(() => {
545
+ const quickKey = this.quickKey;
546
+ const radio = this.shadowRoot!.querySelector<HTMLInputElement>(
547
+ `input[name="radio"][value="${quickKey}"]`
548
+ );
549
+ radio!.checked = true;
550
+ }, 0);
551
+
552
+ private _showMenu(type: 'top' | 'tz' | 'custom') {
553
+ const menus = this.shadowRoot?.querySelectorAll<HTMLElement>('.menu');
554
+ menus?.forEach(
555
+ (menu) =>
556
+ (menu.style.display = menu.classList.contains(type)
557
+ ? ''
558
+ : 'none')
559
+ );
560
+ if (type === 'custom') {
561
+ this._updatePeriodSelector();
562
+ }
563
+ }
564
+ private _onTzTriggerClick = () => this._showMenu('tz');
565
+ private _onCustomTriggerClick = (e: Event) => {
566
+ e.preventDefault();
567
+ this._showMenu('custom');
568
+ };
569
+ private _onBackBtnClick = () => this._showMenu('top');
570
+
571
+ private _onRadioChange = (e: Event) => {
572
+ if (!(e.target instanceof HTMLInputElement)) return;
573
+ if (e.target.type !== 'radio') return;
574
+ const { name, value } = e.target;
575
+ if (name === 'radio') {
576
+ const v = value as QuickKey;
577
+ if (v === 'custom') return;
578
+ const t = quickPeriodTimes()[v];
579
+ this.dispatchEvent(
580
+ 'time-changed',
581
+ !t
582
+ ? { type: 'all' }
583
+ : {
584
+ ...t,
585
+ type: v
586
+ },
587
+ true
588
+ );
589
+ } else if (name === 'tz') {
590
+ this.timezone = +value;
591
+ }
592
+ };
593
+ private _onDoneBtnClick = (_e: Event) => {
594
+ const selector = this._periodSelector;
595
+ this._showMenu('top');
596
+ this.shadowRoot!.querySelector<HTMLInputElement>(
597
+ 'input[name="radio"][value="custom"]'
598
+ )!.checked = true;
599
+ this.dispatchEvent(
600
+ 'time-changed',
601
+ {
602
+ start: selector.timeStart as Date,
603
+ end: selector.timeEnd as Date,
604
+ type: 'custom'
605
+ },
606
+ true
607
+ );
608
+ };
609
+ }
610
+
611
+ Ele.define();
@@ -0,0 +1,11 @@
1
+
2
+ // firefox only:
3
+ @-moz-document url-prefix() {
4
+ :host, * {
5
+ scrollbar-width: thin;
6
+ scrollbar-color: var(--scrollbar-thumb-color, #4444) transparent;
7
+ &:hover {
8
+ scrollbar-color: var(--scrollbar-thumb-color-hover, var(--scrollbar-thumb-color, #8888)) transparent;
9
+ }
10
+ }
11
+ }