@gez/date-time-kit 2.0.0-alpha.0 → 2.0.0-alpha.2
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.
- package/dist/components/calendar/index.d.ts +1 -1
- package/dist/components/calendar/index.mjs +1 -1
- package/dist/components/date-time-selector/index.d.ts +61 -0
- package/dist/components/date-time-selector/index.mjs +212 -0
- package/dist/components/date-time-selector/styleStr.d.ts +1 -0
- package/dist/components/date-time-selector/styleStr.mjs +6 -0
- package/dist/components/hhmmss-ms-list-grp/index.d.ts +3 -3
- package/dist/components/hhmmss-ms-list-grp/index.mjs +35 -33
- package/dist/components/period-selector/index.css +2 -1
- package/dist/components/period-selector/index.d.ts +9 -0
- package/dist/components/period-selector/index.mjs +31 -12
- package/dist/components/quick-selector/index.d.ts +14 -2
- package/dist/components/quick-selector/index.mjs +89 -57
- package/dist/components/{period-selector/date-nav.d.ts → yyyymm-nav/index.d.ts} +4 -6
- package/dist/components/{period-selector/date-nav.mjs → yyyymm-nav/index.mjs} +9 -10
- package/dist/components/yyyymmdd-list-grp/index.mjs +6 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +2 -0
- package/package.json +2 -2
- package/src/components/calendar/index.ts +2 -2
- package/src/components/date-time-selector/index.ts +291 -0
- package/src/components/date-time-selector/styleStr.ts +125 -0
- package/src/components/hhmmss-ms-list-grp/index.ts +44 -54
- package/src/components/period-selector/index.scss +3 -2
- package/src/components/period-selector/index.ts +45 -16
- package/src/components/quick-selector/index.ts +102 -57
- package/src/components/{period-selector/date-nav.ts → yyyymm-nav/index.ts} +12 -15
- package/src/components/yyyymmdd-list-grp/index.ts +38 -17
- package/src/index.ts +1 -0
- /package/dist/components/{period-selector/date-nav.css → yyyymm-nav/index.css} +0 -0
- /package/src/components/{period-selector/date-nav.scss → yyyymm-nav/index.scss} +0 -0
|
@@ -48,7 +48,7 @@ const styleStr = css`
|
|
|
48
48
|
background-color: #eee;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
dt-
|
|
51
|
+
dt-yyyymm-nav::part(list-grp) {
|
|
52
52
|
height: 254px;
|
|
53
53
|
margin-top: 15px;
|
|
54
54
|
}
|
|
@@ -88,6 +88,7 @@ dt-popover {
|
|
|
88
88
|
border: 1px solid rgba(0, 0, 0, 0.0666666667);
|
|
89
89
|
box-sizing: border-box;
|
|
90
90
|
align-items: center;
|
|
91
|
+
cursor: pointer;
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
.time-selector {
|
|
@@ -155,11 +156,16 @@ dt-calendar-base::part(item) {
|
|
|
155
156
|
font-size: 14px;
|
|
156
157
|
}
|
|
157
158
|
`;
|
|
158
|
-
import {
|
|
159
|
-
|
|
159
|
+
import {
|
|
160
|
+
Ele as YyyyMmNavEle,
|
|
161
|
+
type EventMap as YyyyMmNavEvent
|
|
162
|
+
} from '../yyyymm-nav';
|
|
163
|
+
YyyyMmNavEle.define();
|
|
160
164
|
import {
|
|
161
165
|
Ele as CalendarBaseEle,
|
|
162
|
-
type EventMap as CalendarBaseEvent
|
|
166
|
+
type EventMap as CalendarBaseEvent,
|
|
167
|
+
type Weeks,
|
|
168
|
+
weekKey
|
|
163
169
|
} from '../calendar';
|
|
164
170
|
CalendarBaseEle.define();
|
|
165
171
|
import { Ele as HhMmSsMsListGrpEle } from '../hhmmss-ms-list-grp';
|
|
@@ -185,6 +191,12 @@ export interface Attrs extends BaseAttrs {
|
|
|
185
191
|
* 例如设置为 'minute',则表示只能选择到分钟,秒和毫秒将被忽略。
|
|
186
192
|
*/
|
|
187
193
|
'min-granularity'?: 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
|
|
194
|
+
/**
|
|
195
|
+
* Set which day of the week is the first day.
|
|
196
|
+
* @type `'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat'`
|
|
197
|
+
* @default 'sun'
|
|
198
|
+
*/
|
|
199
|
+
'week-start-at'?: Weeks;
|
|
188
200
|
}
|
|
189
201
|
|
|
190
202
|
export interface Emits {
|
|
@@ -218,7 +230,8 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
218
230
|
...(super.observedAttributes as (keyof BaseAttrs)[]),
|
|
219
231
|
'time-start',
|
|
220
232
|
'time-end',
|
|
221
|
-
'min-granularity'
|
|
233
|
+
'min-granularity',
|
|
234
|
+
'week-start-at'
|
|
222
235
|
] satisfies (keyof Attrs)[];
|
|
223
236
|
}
|
|
224
237
|
|
|
@@ -240,6 +253,13 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
240
253
|
if (Number.isNaN(+v)) return;
|
|
241
254
|
this.setAttribute('time-end', +v + '');
|
|
242
255
|
}
|
|
256
|
+
public get weekStartAt() {
|
|
257
|
+
return this._getAttr('week-start-at', 'sun');
|
|
258
|
+
}
|
|
259
|
+
public set weekStartAt(val: Weeks) {
|
|
260
|
+
if (!weekKey.includes(val)) return;
|
|
261
|
+
this.setAttribute('week-start-at', val);
|
|
262
|
+
}
|
|
243
263
|
|
|
244
264
|
protected _style = styleStr;
|
|
245
265
|
protected _template = html`
|
|
@@ -257,10 +277,10 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
257
277
|
.map(
|
|
258
278
|
(s) => html`
|
|
259
279
|
<div class="wrapper ${s}">
|
|
260
|
-
<dt-
|
|
280
|
+
<dt-yyyymm-nav
|
|
261
281
|
show-ctrl-btn-month-add
|
|
262
282
|
show-ctrl-btn-month-sub
|
|
263
|
-
></dt-
|
|
283
|
+
></dt-yyyymm-nav>
|
|
264
284
|
<dt-calendar-base data-type="${s}"></dt-calendar-base>
|
|
265
285
|
<dt-popover>
|
|
266
286
|
<div slot="trigger" class="time-echo-wrapper">
|
|
@@ -284,11 +304,13 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
284
304
|
|
|
285
305
|
private get _startNavEle() {
|
|
286
306
|
return this.shadowRoot?.querySelector(
|
|
287
|
-
'.start dt-
|
|
288
|
-
) as
|
|
307
|
+
'.start dt-yyyymm-nav'
|
|
308
|
+
) as YyyyMmNavEle;
|
|
289
309
|
}
|
|
290
310
|
private get _endNavEle() {
|
|
291
|
-
return this.shadowRoot?.querySelector(
|
|
311
|
+
return this.shadowRoot?.querySelector(
|
|
312
|
+
'.end dt-yyyymm-nav'
|
|
313
|
+
) as YyyyMmNavEle;
|
|
292
314
|
}
|
|
293
315
|
private get _startCalendar() {
|
|
294
316
|
return this.shadowRoot?.querySelector(
|
|
@@ -430,6 +452,8 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
430
452
|
let timeStart = this.timeStart as Date;
|
|
431
453
|
let timeEnd = this.timeEnd as Date;
|
|
432
454
|
if (timeStart > timeEnd) [timeStart, timeEnd] = [timeEnd, timeStart];
|
|
455
|
+
this._startCalendar.weekStartAt = this._endCalendar.weekStartAt =
|
|
456
|
+
this.weekStartAt;
|
|
433
457
|
const tz = new Date().getTimezoneOffset() * 60 * 1000;
|
|
434
458
|
this._startNavEle.millisecond =
|
|
435
459
|
this._startCalendar.showingTime =
|
|
@@ -478,6 +502,7 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
478
502
|
}
|
|
479
503
|
|
|
480
504
|
private _onCalendarSelect = (e: CalendarBaseEvent['select-time']) => {
|
|
505
|
+
e.stopPropagation();
|
|
481
506
|
if (this._selectedDate) {
|
|
482
507
|
this._selectedDate = null;
|
|
483
508
|
this.timeEnd = +e.detail + this._endTimeSelector.millisecond;
|
|
@@ -487,26 +512,30 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
487
512
|
}
|
|
488
513
|
};
|
|
489
514
|
private _onCalendarItemHover = (e: CalendarBaseEvent['hover-item']) => {
|
|
515
|
+
e.stopPropagation();
|
|
490
516
|
if (!this._selectedDate) return;
|
|
491
517
|
this.timeEnd = +e.detail + this._endTimeSelector.millisecond;
|
|
492
518
|
};
|
|
493
|
-
private _onNavChange = (e:
|
|
519
|
+
private _onNavChange = (e: YyyyMmNavEvent['change']) => {
|
|
520
|
+
e.stopPropagation();
|
|
494
521
|
const wrapper = closestByEvent(e, '.wrapper');
|
|
495
522
|
if (!wrapper) return;
|
|
496
|
-
const {
|
|
523
|
+
const { newTime } = e.detail;
|
|
497
524
|
if (wrapper.classList.contains('start')) {
|
|
498
|
-
this._startCalendar.showingTime = +
|
|
525
|
+
this._startCalendar.showingTime = +newTime;
|
|
499
526
|
} else {
|
|
500
|
-
this._endCalendar.showingTime = +
|
|
527
|
+
this._endCalendar.showingTime = +newTime;
|
|
501
528
|
}
|
|
502
529
|
this._updateNavCtrlBtn();
|
|
503
530
|
};
|
|
504
|
-
private _onNavOpenToggle = (e:
|
|
505
|
-
if (!(e.target instanceof
|
|
531
|
+
private _onNavOpenToggle = (e: YyyyMmNavEvent['popover-open-change']) => {
|
|
532
|
+
if (!(e.target instanceof YyyyMmNavEle)) return;
|
|
533
|
+
e.stopPropagation();
|
|
506
534
|
e.target.nextElementSibling?.classList.toggle('hide', e.detail);
|
|
507
535
|
};
|
|
508
536
|
private _onTimePopoverOpenChange = (e: PopoverEvent['open-change']) => {
|
|
509
537
|
if (!(e.target instanceof PopoverEle)) return;
|
|
538
|
+
e.stopPropagation();
|
|
510
539
|
if (!e.detail) return this._render(); // for reset time selector value
|
|
511
540
|
e.target
|
|
512
541
|
.querySelectorAll<HhMmSsMsListGrpEle>('dt-hhmmss-ms-list-grp')
|
|
@@ -210,11 +210,11 @@ export interface Attrs extends BaseAttrs {
|
|
|
210
210
|
/**
|
|
211
211
|
* Start time of the quick selection. Only works in custom mode.
|
|
212
212
|
*/
|
|
213
|
-
'start-time'?:
|
|
213
|
+
'start-time'?: string | number | '';
|
|
214
214
|
/**
|
|
215
215
|
* End time of the quick selection. Only works in custom mode.
|
|
216
216
|
*/
|
|
217
|
-
'end-time'?:
|
|
217
|
+
'end-time'?: string | number | '';
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
export interface Emits {
|
|
@@ -256,57 +256,52 @@ const genStartDate = (fn?: (_t: Date) => void, t?: Date) =>
|
|
|
256
256
|
genDateWithHours(true, fn, t);
|
|
257
257
|
const genEndDate = (fn?: (_t: Date) => void, t?: Date) =>
|
|
258
258
|
genDateWithHours(false, fn, t);
|
|
259
|
-
const
|
|
259
|
+
export const genPeriodTimes = (
|
|
260
|
+
startFn?: (_t: Date, weekOffset: number) => void,
|
|
261
|
+
endFn?: (_t: Date, weekOffset: number) => void,
|
|
262
|
+
t: Date = new Date(),
|
|
263
|
+
weekStartAt: Weeks = 'sun'
|
|
264
|
+
) => {
|
|
265
|
+
const weekOffset = weekKey.indexOf(weekStartAt);
|
|
266
|
+
return {
|
|
267
|
+
start: genStartDate((t) => startFn?.(t, weekOffset), new Date(t)),
|
|
268
|
+
end: genEndDate((t) => endFn?.(t, weekOffset), new Date(t))
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
const quickPeriodTimes = (weekStartAt: Weeks = 'sun') =>
|
|
260
272
|
({
|
|
261
273
|
all: null,
|
|
262
|
-
today:
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
week: {
|
|
271
|
-
start: genStartDate((t) =>
|
|
272
|
-
t.setDate(t.getDate() - t.getDay() + weekOffset)
|
|
273
|
-
),
|
|
274
|
-
end: genEndDate((t) =>
|
|
274
|
+
today: genPeriodTimes(),
|
|
275
|
+
yesterday: genPeriodTimes(
|
|
276
|
+
(t) => t.setDate(t.getDate() - 1),
|
|
277
|
+
(t) => t.setDate(t.getDate() - 1)
|
|
278
|
+
),
|
|
279
|
+
week: genPeriodTimes(
|
|
280
|
+
(t, weekOffset) => t.setDate(t.getDate() - t.getDay() + weekOffset),
|
|
281
|
+
(t, weekOffset) =>
|
|
275
282
|
t.setDate(t.getDate() - t.getDay() + weekOffset + 6)
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
),
|
|
282
|
-
end: genEndDate((t) =>
|
|
283
|
+
),
|
|
284
|
+
lastWeek: genPeriodTimes(
|
|
285
|
+
(t, weekOffset) =>
|
|
286
|
+
t.setDate(t.getDate() - t.getDay() + weekOffset - 7),
|
|
287
|
+
(t, weekOffset) =>
|
|
283
288
|
t.setDate(t.getDate() - t.getDay() + weekOffset - 1)
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
}
|
|
289
|
+
),
|
|
290
|
+
last7Days: genPeriodTimes((t) => t.setDate(t.getDate() - 6)),
|
|
291
|
+
month: genPeriodTimes(
|
|
292
|
+
(t) => t.setDate(1),
|
|
293
|
+
(t) => t.setMonth(t.getMonth() + 1, 0)
|
|
294
|
+
),
|
|
295
|
+
last30Days: genPeriodTimes((t) => t.setDate(t.getDate() - 29)),
|
|
296
|
+
last180Days: genPeriodTimes((t) => t.setDate(t.getDate() - 179)),
|
|
297
|
+
last6Month: genPeriodTimes(
|
|
298
|
+
(t) => t.setMonth(t.getMonth() - 5, 1),
|
|
299
|
+
(t) => t.setMonth(t.getMonth() + 1, 0)
|
|
300
|
+
),
|
|
301
|
+
year: genPeriodTimes(
|
|
302
|
+
(t) => t.setMonth(0, 1),
|
|
303
|
+
(t) => t.setFullYear(t.getFullYear() + 1, 0, 0)
|
|
304
|
+
)
|
|
310
305
|
}) as const;
|
|
311
306
|
|
|
312
307
|
/**
|
|
@@ -360,9 +355,37 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
360
355
|
return this._getAttr('week-start-at', 'sun');
|
|
361
356
|
}
|
|
362
357
|
public set weekStartAt(val: Weeks) {
|
|
363
|
-
if (weekKey.includes(val)) return;
|
|
358
|
+
if (!weekKey.includes(val)) return;
|
|
364
359
|
this.setAttribute('week-start-at', val);
|
|
365
360
|
}
|
|
361
|
+
public get startTime() {
|
|
362
|
+
const v = this._getAttr('start-time', '');
|
|
363
|
+
if (v === '') return '';
|
|
364
|
+
return new Date(Number.isNaN(+v) ? v : +v);
|
|
365
|
+
}
|
|
366
|
+
public set startTime(val: number | string | Date) {
|
|
367
|
+
if (val === '') {
|
|
368
|
+
this.removeAttribute('start-time');
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const v = new Date(val);
|
|
372
|
+
if (Number.isNaN(+v)) return;
|
|
373
|
+
this.setAttribute('time-start', +v + '');
|
|
374
|
+
}
|
|
375
|
+
public get endTime() {
|
|
376
|
+
const v = this._getAttr('end-time', '' + this.startTime);
|
|
377
|
+
if (v === '') return '';
|
|
378
|
+
return new Date(Number.isNaN(+v) ? v : +v);
|
|
379
|
+
}
|
|
380
|
+
public set endTime(val: number | string | Date) {
|
|
381
|
+
if (val === '') {
|
|
382
|
+
this.removeAttribute('end-time');
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const v = new Date(val);
|
|
386
|
+
if (Number.isNaN(+v)) return;
|
|
387
|
+
this.setAttribute('time-end', +v + '');
|
|
388
|
+
}
|
|
366
389
|
|
|
367
390
|
protected _style = styleStr;
|
|
368
391
|
protected _template = html`
|
|
@@ -449,6 +472,7 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
449
472
|
if (!super.connectedCallback()) return;
|
|
450
473
|
this._renderTz();
|
|
451
474
|
this._updateRadio();
|
|
475
|
+
this._updatePeriodSelector();
|
|
452
476
|
this.shadowRoot!.querySelector('.tz-trigger')?.addEventListener(
|
|
453
477
|
'click',
|
|
454
478
|
this._onTzTriggerClick
|
|
@@ -513,19 +537,34 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
513
537
|
if (name === 'quick-key') {
|
|
514
538
|
this._updateRadio();
|
|
515
539
|
}
|
|
540
|
+
if (name === 'week-start-at') {
|
|
541
|
+
this._updatePeriodSelector();
|
|
542
|
+
}
|
|
543
|
+
if (name === 'start-time' || name === 'end-time') {
|
|
544
|
+
if (this.quickKey !== 'custom') return;
|
|
545
|
+
this._updatePeriodSelector();
|
|
546
|
+
}
|
|
516
547
|
}
|
|
517
548
|
|
|
518
549
|
private _updatePeriodSelector = debounce(() => {
|
|
550
|
+
this._periodSelector.weekStartAt = this.weekStartAt;
|
|
519
551
|
if (
|
|
520
552
|
this.shadowRoot?.querySelector<HTMLElement>('.menu.custom')?.style
|
|
521
553
|
.display === 'none'
|
|
522
554
|
) {
|
|
523
555
|
return;
|
|
524
556
|
}
|
|
525
|
-
const defaultPeriod = quickPeriodTimes().last30Days;
|
|
526
557
|
const ele = this._periodSelector;
|
|
527
|
-
|
|
528
|
-
|
|
558
|
+
const startTime = this.startTime;
|
|
559
|
+
const endTime = this.endTime;
|
|
560
|
+
if (startTime !== '' && endTime !== '') {
|
|
561
|
+
ele.timeStart = startTime;
|
|
562
|
+
ele.timeEnd = endTime;
|
|
563
|
+
} else {
|
|
564
|
+
const defaultPeriod = quickPeriodTimes(this.weekStartAt).last30Days;
|
|
565
|
+
ele.timeStart = defaultPeriod.start;
|
|
566
|
+
ele.timeEnd = defaultPeriod.end;
|
|
567
|
+
}
|
|
529
568
|
ele.showCalendarDatePoint();
|
|
530
569
|
}, 0);
|
|
531
570
|
|
|
@@ -575,7 +614,7 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
575
614
|
if (name === 'radio') {
|
|
576
615
|
const v = value as QuickKey;
|
|
577
616
|
if (v === 'custom') return;
|
|
578
|
-
const t = quickPeriodTimes()[v];
|
|
617
|
+
const t = quickPeriodTimes(this.weekStartAt)[v];
|
|
579
618
|
this.dispatchEvent(
|
|
580
619
|
'time-changed',
|
|
581
620
|
!t
|
|
@@ -593,9 +632,7 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
593
632
|
private _onDoneBtnClick = (_e: Event) => {
|
|
594
633
|
const selector = this._periodSelector;
|
|
595
634
|
this._showMenu('top');
|
|
596
|
-
this.
|
|
597
|
-
'input[name="radio"][value="custom"]'
|
|
598
|
-
)!.checked = true;
|
|
635
|
+
this.quickKey = 'custom';
|
|
599
636
|
this.dispatchEvent(
|
|
600
637
|
'time-changed',
|
|
601
638
|
{
|
|
@@ -606,6 +643,14 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
606
643
|
true
|
|
607
644
|
);
|
|
608
645
|
};
|
|
646
|
+
|
|
647
|
+
public readonly genPeriodTimes = (
|
|
648
|
+
startFn?: (_t: Date, weekOffset: number) => void,
|
|
649
|
+
endFn?: (_t: Date, weekOffset: number) => void,
|
|
650
|
+
t: Date = new Date()
|
|
651
|
+
) => {
|
|
652
|
+
return genPeriodTimes(startFn, endFn, t, this.weekStartAt);
|
|
653
|
+
};
|
|
609
654
|
}
|
|
610
655
|
|
|
611
656
|
Ele.define();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { css, debounce, html } from '../../utils';
|
|
1
2
|
import {
|
|
2
3
|
type BaseAttrs,
|
|
3
4
|
type Emit2EventMap,
|
|
4
5
|
UiBase
|
|
5
|
-
} from '
|
|
6
|
-
import
|
|
7
|
-
// import styleStr from './date-nav.scss?inline';
|
|
6
|
+
} from '../web-component-base';
|
|
7
|
+
// import styleStr from './index.scss?inline';
|
|
8
8
|
const styleStr = css`
|
|
9
9
|
.wrapper {
|
|
10
10
|
display: block;
|
|
@@ -133,10 +133,8 @@ export interface Attrs extends BaseAttrs {
|
|
|
133
133
|
|
|
134
134
|
export interface Emits {
|
|
135
135
|
change: {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
newStartTime: Date;
|
|
139
|
-
newEndTime: Date;
|
|
136
|
+
oldTime: Date;
|
|
137
|
+
newTime: Date;
|
|
140
138
|
};
|
|
141
139
|
'popover-open-change': boolean;
|
|
142
140
|
}
|
|
@@ -148,7 +146,7 @@ export type EventMap = Emit2EventMap<Emits>;
|
|
|
148
146
|
* 存在一个 titleFormatter 方法,可以重写该方法以自定义年月标题的回显格式。
|
|
149
147
|
*/
|
|
150
148
|
export class Ele extends UiBase<Attrs, Emits> {
|
|
151
|
-
public static readonly tagName = 'dt-
|
|
149
|
+
public static readonly tagName = 'dt-yyyymm-nav' as const;
|
|
152
150
|
|
|
153
151
|
static get observedAttributes(): string[] {
|
|
154
152
|
return [
|
|
@@ -260,10 +258,8 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
260
258
|
this.dispatchEvent(
|
|
261
259
|
'change',
|
|
262
260
|
{
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
newStartTime: new Date(+newValue),
|
|
266
|
-
newEndTime: new Date(+newValue)
|
|
261
|
+
oldTime: new Date(+oldValue),
|
|
262
|
+
newTime: new Date(+newValue)
|
|
267
263
|
},
|
|
268
264
|
true
|
|
269
265
|
);
|
|
@@ -279,9 +275,9 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
279
275
|
root.querySelector('.title')!.textContent = this.titleFormatter(ms);
|
|
280
276
|
}, 0);
|
|
281
277
|
|
|
282
|
-
private _onTitleToggle = ({
|
|
283
|
-
|
|
284
|
-
|
|
278
|
+
private _onTitleToggle = (e: PopoverEvent['open-change']) => {
|
|
279
|
+
const isOpen = e.detail;
|
|
280
|
+
e.stopPropagation();
|
|
285
281
|
this.shadowRoot!.querySelector('.wrapper')!.classList.toggle(
|
|
286
282
|
'show-list',
|
|
287
283
|
isOpen
|
|
@@ -293,6 +289,7 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
293
289
|
};
|
|
294
290
|
private _onItemSelect = (e: YyyyMmDdListGrpEvent['change']) => {
|
|
295
291
|
if (!(e.target instanceof YyyyMmDdListGrpEle)) return;
|
|
292
|
+
e.stopPropagation();
|
|
296
293
|
this.millisecond = e.target.millisecond;
|
|
297
294
|
};
|
|
298
295
|
private _onBtnClick = (e: MouseEvent) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { debounce, html } from '../../utils';
|
|
1
|
+
import { css, debounce, html } from '../../utils';
|
|
2
2
|
import { Ele as NumListEle, type EventMap as NumListEvent } from '../num-list';
|
|
3
3
|
NumListEle.define();
|
|
4
4
|
import {
|
|
@@ -7,7 +7,40 @@ import {
|
|
|
7
7
|
UiBase
|
|
8
8
|
} from '../web-component-base';
|
|
9
9
|
// import styleStr from './index.scss?inline';
|
|
10
|
-
const styleStr =
|
|
10
|
+
const styleStr = css`
|
|
11
|
+
:host {
|
|
12
|
+
display: flex;
|
|
13
|
+
flex-direction: column;
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
gap: 15px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.cols {
|
|
19
|
+
flex: 1;
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-direction: row;
|
|
22
|
+
height: 0;
|
|
23
|
+
justify-content: space-between;
|
|
24
|
+
gap: 2px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.col {
|
|
28
|
+
flex: 1;
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
gap: 10px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.col > span {
|
|
35
|
+
text-align: center;
|
|
36
|
+
display: inline-block;
|
|
37
|
+
line-height: 27px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
dt-num-list {
|
|
41
|
+
flex: 1;
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
11
44
|
|
|
12
45
|
export interface Attrs extends BaseAttrs {
|
|
13
46
|
millisecond: number;
|
|
@@ -93,33 +126,21 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
93
126
|
this.setAttribute('millisecond', '' + Math.floor(v));
|
|
94
127
|
}
|
|
95
128
|
public get maxGranularity() {
|
|
96
|
-
return this._getAttr('max-granularity', 'year')
|
|
97
|
-
| 'year'
|
|
98
|
-
| 'month'
|
|
99
|
-
| 'day';
|
|
129
|
+
return this._getAttr('max-granularity', 'year');
|
|
100
130
|
}
|
|
101
131
|
public set maxGranularity(v: 'year' | 'month' | 'day') {
|
|
102
132
|
if (!['year', 'month', 'day'].includes(v)) return;
|
|
103
133
|
this.setAttribute('max-granularity', v);
|
|
104
134
|
}
|
|
105
135
|
public get minGranularity() {
|
|
106
|
-
return this._getAttr('min-granularity', 'day')
|
|
107
|
-
| 'year'
|
|
108
|
-
| 'month'
|
|
109
|
-
| 'day';
|
|
136
|
+
return this._getAttr('min-granularity', 'day');
|
|
110
137
|
}
|
|
111
138
|
public set minGranularity(v: 'year' | 'month' | 'day') {
|
|
112
139
|
if (!['year', 'month', 'day'].includes(v)) return;
|
|
113
140
|
this.setAttribute('min-granularity', v);
|
|
114
141
|
}
|
|
115
142
|
public get colOrder() {
|
|
116
|
-
return this._getAttr('col-order', 'dmy')
|
|
117
|
-
| 'ymd'
|
|
118
|
-
| 'ydm'
|
|
119
|
-
| 'myd'
|
|
120
|
-
| 'mdy'
|
|
121
|
-
| 'dym'
|
|
122
|
-
| 'dmy';
|
|
143
|
+
return this._getAttr('col-order', 'dmy');
|
|
123
144
|
}
|
|
124
145
|
public set colOrder(v: 'ymd' | 'ydm' | 'myd' | 'mdy' | 'dym' | 'dmy') {
|
|
125
146
|
if (!['ymd', 'ydm', 'myd', 'mdy', 'dym', 'dmy'].includes(v)) return;
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * as DtHhMmSsMsListGrp from './components/hhmmss-ms-list-grp';
|
|
|
4
4
|
export * as DtYyyyMmDdListGrp from './components/yyyymmdd-list-grp';
|
|
5
5
|
export * as DtQuickSelector from './components/quick-selector';
|
|
6
6
|
export * as DtPopover from './components/popover';
|
|
7
|
+
export * as DtDataTimeSelector from './components/date-time-selector';
|
|
7
8
|
|
|
8
9
|
export {
|
|
9
10
|
i18n as dtI18n,
|
|
File without changes
|
|
File without changes
|