@gez/date-time-kit 2.0.0-alpha.10 → 2.0.0-alpha.12
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/quick-selector/index.d.ts +6 -13
- package/dist/components/quick-selector/index.mjs +12 -16
- package/dist/components/quick-selector/quick-key.d.ts +19 -13
- package/dist/components/quick-selector/quick-key.mjs +8 -18
- package/package.json +2 -2
- package/src/components/quick-selector/index.ts +22 -31
- package/src/components/quick-selector/quick-key.ts +40 -32
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Weeks } from '../calendar';
|
|
2
2
|
import { type BaseAttrs, type Emit2EventMap, UiBase } from '../web-component-base';
|
|
3
|
-
import { type DataLimit, type GenPeriodTimesOptions, type QuickKey, genPeriodTimes,
|
|
4
|
-
export { type QuickKey, type DataLimit, type GenPeriodTimesOptions, genPeriodTimes,
|
|
3
|
+
import { type DataLimit, type GenPeriodTimesOptions, type PeriodTimeInfo, type QuickGenPeriodTimesOptions, type QuickKey, genPeriodTimes, quickGenPeriodTime, quickGenPeriodTimeInfo, quickGenPeriodTimes } from './quick-key';
|
|
4
|
+
export { type QuickKey, type DataLimit, type GenPeriodTimesOptions, type QuickGenPeriodTimesOptions, type PeriodTimeInfo, type Weeks, genPeriodTimes, quickGenPeriodTime, quickGenPeriodTimes, quickGenPeriodTimeInfo };
|
|
5
5
|
export interface Attrs extends BaseAttrs {
|
|
6
6
|
/**
|
|
7
7
|
* Timezone in minutes. For example: UTC+05:45 => `345`, UTC-01:00 => `-60`.
|
|
@@ -32,15 +32,7 @@ export interface Attrs extends BaseAttrs {
|
|
|
32
32
|
'end-time'?: string | number | '';
|
|
33
33
|
}
|
|
34
34
|
export interface Emits {
|
|
35
|
-
'time-changed':
|
|
36
|
-
type: 'all';
|
|
37
|
-
start?: null;
|
|
38
|
-
end?: null;
|
|
39
|
-
} | {
|
|
40
|
-
type: QuickKey;
|
|
41
|
-
start: Date;
|
|
42
|
-
end: Date;
|
|
43
|
-
};
|
|
35
|
+
'time-changed': PeriodTimeInfo;
|
|
44
36
|
'open-change': boolean;
|
|
45
37
|
}
|
|
46
38
|
export type EventMap = Emit2EventMap<Emits>;
|
|
@@ -81,14 +73,15 @@ export declare class Ele extends UiBase<Attrs, Emits> {
|
|
|
81
73
|
start: Date;
|
|
82
74
|
end: Date;
|
|
83
75
|
};
|
|
84
|
-
readonly
|
|
76
|
+
readonly quickGenPeriodTimes: <T extends DataLimit = DataLimit>(periods: T[]) => Record<Exclude<T, "all">, {
|
|
85
77
|
start: Date;
|
|
86
78
|
end: Date;
|
|
87
79
|
}> & ("all" extends T ? {
|
|
88
80
|
all: null;
|
|
89
81
|
} : {});
|
|
90
|
-
readonly
|
|
82
|
+
readonly quickGenPeriodTime: <T extends DataLimit = DataLimit>(period: T) => T extends "all" ? null : {
|
|
91
83
|
start: Date;
|
|
92
84
|
end: Date;
|
|
93
85
|
};
|
|
86
|
+
readonly quickGenPeriodTimeInfo: <T extends DataLimit = DataLimit>(type: T) => PeriodTimeInfo<T, Date>;
|
|
94
87
|
}
|
|
@@ -11,13 +11,15 @@ import styleStr from "./index.css.mjs";
|
|
|
11
11
|
import html, { getCurrentTz, utcText } from "./index.html.mjs";
|
|
12
12
|
import {
|
|
13
13
|
genPeriodTimes,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
quickGenPeriodTime,
|
|
15
|
+
quickGenPeriodTimeInfo,
|
|
16
|
+
quickGenPeriodTimes
|
|
16
17
|
} from "./quick-key.mjs";
|
|
17
18
|
export {
|
|
18
19
|
genPeriodTimes,
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
quickGenPeriodTime,
|
|
21
|
+
quickGenPeriodTimes,
|
|
22
|
+
quickGenPeriodTimeInfo
|
|
21
23
|
};
|
|
22
24
|
export class Ele extends UiBase {
|
|
23
25
|
constructor() {
|
|
@@ -37,7 +39,7 @@ export class Ele extends UiBase {
|
|
|
37
39
|
ele.timeStart = startTime;
|
|
38
40
|
ele.timeEnd = endTime;
|
|
39
41
|
} else {
|
|
40
|
-
const defaultPeriod = this.
|
|
42
|
+
const defaultPeriod = this.quickGenPeriodTime("last30Days");
|
|
41
43
|
ele.timeStart = defaultPeriod.start;
|
|
42
44
|
ele.timeEnd = defaultPeriod.end;
|
|
43
45
|
}
|
|
@@ -79,15 +81,8 @@ export class Ele extends UiBase {
|
|
|
79
81
|
if (name === "radio") {
|
|
80
82
|
const v = value;
|
|
81
83
|
if (v === "custom") return;
|
|
82
|
-
const t = this.
|
|
83
|
-
this.dispatchEvent(
|
|
84
|
-
"time-changed",
|
|
85
|
-
!t ? { type: "all" } : {
|
|
86
|
-
...t,
|
|
87
|
-
type: v
|
|
88
|
-
},
|
|
89
|
-
true
|
|
90
|
-
);
|
|
84
|
+
const t = this.quickGenPeriodTimeInfo(v);
|
|
85
|
+
this.dispatchEvent("time-changed", t, true);
|
|
91
86
|
} else if (name === "tz") {
|
|
92
87
|
this.timezone = +value;
|
|
93
88
|
}
|
|
@@ -107,8 +102,9 @@ export class Ele extends UiBase {
|
|
|
107
102
|
);
|
|
108
103
|
});
|
|
109
104
|
__publicField(this, "genPeriodTimes", (options) => genPeriodTimes({ weekStartAt: this.weekStartAt, ...options }));
|
|
110
|
-
__publicField(this, "
|
|
111
|
-
__publicField(this, "
|
|
105
|
+
__publicField(this, "quickGenPeriodTimes", (periods) => quickGenPeriodTimes({ weekStartAt: this.weekStartAt, periods }));
|
|
106
|
+
__publicField(this, "quickGenPeriodTime", (period) => quickGenPeriodTime(period, { weekStartAt: this.weekStartAt }));
|
|
107
|
+
__publicField(this, "quickGenPeriodTimeInfo", (type) => quickGenPeriodTimeInfo(type, { weekStartAt: this.weekStartAt }));
|
|
112
108
|
this._applyTemplate();
|
|
113
109
|
}
|
|
114
110
|
static get observedAttributes() {
|
|
@@ -3,31 +3,37 @@ import { type Weeks } from '../calendar';
|
|
|
3
3
|
export type { DataLimit };
|
|
4
4
|
export type QuickKey = DataLimit | 'custom';
|
|
5
5
|
export declare const limitKeys: DataLimit[];
|
|
6
|
-
export
|
|
7
|
-
start?: (time: Date, weekOffset: number) => void;
|
|
8
|
-
end?: (time: Date, weekOffset: number) => void;
|
|
6
|
+
export interface QuickGenPeriodTimesOptions {
|
|
9
7
|
initTime?: Date;
|
|
10
8
|
weekStartAt?: Weeks;
|
|
11
|
-
}
|
|
9
|
+
}
|
|
10
|
+
export interface GenPeriodTimesOptions extends QuickGenPeriodTimesOptions {
|
|
11
|
+
start?: (time: Date, weekOffset: number) => void;
|
|
12
|
+
end?: (time: Date, weekOffset: number) => void;
|
|
13
|
+
}
|
|
12
14
|
export declare const genPeriodTimes: ({ start, end, initTime, weekStartAt }?: GenPeriodTimesOptions) => {
|
|
13
15
|
start: Date;
|
|
14
16
|
end: Date;
|
|
15
17
|
};
|
|
16
|
-
export declare const
|
|
17
|
-
weekStartAt?: Weeks;
|
|
18
|
+
export declare const quickGenPeriodTimes: <T extends DataLimit = DataLimit>({ periods, ...options }?: {
|
|
18
19
|
periods?: T[];
|
|
19
|
-
|
|
20
|
-
}) => Record<Exclude<T, "all">, {
|
|
20
|
+
} & QuickGenPeriodTimesOptions) => Record<Exclude<T, "all">, {
|
|
21
21
|
start: Date;
|
|
22
22
|
end: Date;
|
|
23
23
|
}> & ("all" extends T ? {
|
|
24
24
|
all: null;
|
|
25
25
|
} : {});
|
|
26
|
-
export declare const
|
|
27
|
-
period: T;
|
|
28
|
-
weekStartAt?: Weeks;
|
|
29
|
-
initTime?: Date;
|
|
30
|
-
}) => T extends "all" ? null : {
|
|
26
|
+
export declare const quickGenPeriodTime: <T extends DataLimit = DataLimit>(period: T, options?: QuickGenPeriodTimesOptions) => T extends "all" ? null : {
|
|
31
27
|
start: Date;
|
|
32
28
|
end: Date;
|
|
33
29
|
};
|
|
30
|
+
export type PeriodTimeInfo<T extends QuickKey = QuickKey, RT = Date> = T extends 'all' ? {
|
|
31
|
+
type: 'all';
|
|
32
|
+
start?: null;
|
|
33
|
+
end?: null;
|
|
34
|
+
} : {
|
|
35
|
+
type: Exclude<T, 'all'>;
|
|
36
|
+
start: RT;
|
|
37
|
+
end: RT;
|
|
38
|
+
};
|
|
39
|
+
export declare const quickGenPeriodTimeInfo: <T extends DataLimit = DataLimit>(type: T, options?: QuickGenPeriodTimesOptions) => PeriodTimeInfo<T>;
|
|
@@ -79,27 +79,17 @@ const presetPeriods = {
|
|
|
79
79
|
end: (t) => t.setFullYear(t.getFullYear() + 1, 0, 0)
|
|
80
80
|
})
|
|
81
81
|
};
|
|
82
|
-
export const
|
|
83
|
-
weekStartAt = "sun",
|
|
82
|
+
export const quickGenPeriodTimes = ({
|
|
84
83
|
periods = limitKeys,
|
|
85
|
-
|
|
84
|
+
...options
|
|
86
85
|
} = {}) => {
|
|
87
86
|
periods = [...new Set(periods)].filter((k) => k in presetPeriods);
|
|
88
87
|
return Object.fromEntries(
|
|
89
|
-
periods.map((k) => [
|
|
90
|
-
k,
|
|
91
|
-
presetPeriods[k]({
|
|
92
|
-
weekStartAt,
|
|
93
|
-
initTime
|
|
94
|
-
})
|
|
95
|
-
])
|
|
88
|
+
periods.map((k) => [k, presetPeriods[k](options)])
|
|
96
89
|
);
|
|
97
90
|
};
|
|
98
|
-
export const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
weekStartAt,
|
|
104
|
-
initTime
|
|
105
|
-
});
|
|
91
|
+
export const quickGenPeriodTime = (period, options = {}) => presetPeriods[period](options);
|
|
92
|
+
export const quickGenPeriodTimeInfo = (type, options = {}) => {
|
|
93
|
+
const t = quickGenPeriodTime(type, options);
|
|
94
|
+
return !t ? { type } : { type, ...t };
|
|
95
|
+
};
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"unbuild": "3.6.0",
|
|
18
18
|
"vitest": "3.2.4"
|
|
19
19
|
},
|
|
20
|
-
"version": "2.0.0-alpha.
|
|
20
|
+
"version": "2.0.0-alpha.12",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"private": false,
|
|
23
23
|
"exports": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"template",
|
|
37
37
|
"public"
|
|
38
38
|
],
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "3254b805ced5c33af1c998ed071fe63dc85c7dca"
|
|
40
40
|
}
|
|
@@ -12,19 +12,26 @@ import html, { getCurrentTz, utcText } from './index.html';
|
|
|
12
12
|
import {
|
|
13
13
|
type DataLimit,
|
|
14
14
|
type GenPeriodTimesOptions,
|
|
15
|
+
type PeriodTimeInfo,
|
|
16
|
+
type QuickGenPeriodTimesOptions,
|
|
15
17
|
type QuickKey,
|
|
16
18
|
genPeriodTimes,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
quickGenPeriodTime,
|
|
20
|
+
quickGenPeriodTimeInfo,
|
|
21
|
+
quickGenPeriodTimes
|
|
19
22
|
} from './quick-key';
|
|
20
23
|
|
|
21
24
|
export {
|
|
22
25
|
type QuickKey,
|
|
23
26
|
type DataLimit,
|
|
24
27
|
type GenPeriodTimesOptions,
|
|
28
|
+
type QuickGenPeriodTimesOptions,
|
|
29
|
+
type PeriodTimeInfo,
|
|
30
|
+
type Weeks,
|
|
25
31
|
genPeriodTimes,
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
quickGenPeriodTime,
|
|
33
|
+
quickGenPeriodTimes,
|
|
34
|
+
quickGenPeriodTimeInfo
|
|
28
35
|
};
|
|
29
36
|
|
|
30
37
|
export interface Attrs extends BaseAttrs {
|
|
@@ -58,17 +65,7 @@ export interface Attrs extends BaseAttrs {
|
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
export interface Emits {
|
|
61
|
-
'time-changed':
|
|
62
|
-
| {
|
|
63
|
-
type: 'all';
|
|
64
|
-
start?: null;
|
|
65
|
-
end?: null;
|
|
66
|
-
}
|
|
67
|
-
| {
|
|
68
|
-
type: QuickKey;
|
|
69
|
-
start: Date;
|
|
70
|
-
end: Date;
|
|
71
|
-
};
|
|
68
|
+
'time-changed': PeriodTimeInfo;
|
|
72
69
|
'open-change': boolean;
|
|
73
70
|
}
|
|
74
71
|
export type EventMap = Emit2EventMap<Emits>;
|
|
@@ -269,7 +266,7 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
269
266
|
ele.timeStart = startTime;
|
|
270
267
|
ele.timeEnd = endTime;
|
|
271
268
|
} else {
|
|
272
|
-
const defaultPeriod = this.
|
|
269
|
+
const defaultPeriod = this.quickGenPeriodTime('last30Days');
|
|
273
270
|
ele.timeStart = defaultPeriod.start;
|
|
274
271
|
ele.timeEnd = defaultPeriod.end;
|
|
275
272
|
}
|
|
@@ -327,17 +324,8 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
327
324
|
if (name === 'radio') {
|
|
328
325
|
const v = value as QuickKey;
|
|
329
326
|
if (v === 'custom') return;
|
|
330
|
-
const t = this.
|
|
331
|
-
this.dispatchEvent(
|
|
332
|
-
'time-changed',
|
|
333
|
-
!t
|
|
334
|
-
? { type: 'all' }
|
|
335
|
-
: {
|
|
336
|
-
...t,
|
|
337
|
-
type: v
|
|
338
|
-
},
|
|
339
|
-
true
|
|
340
|
-
);
|
|
327
|
+
const t = this.quickGenPeriodTimeInfo(v);
|
|
328
|
+
this.dispatchEvent('time-changed', t, true);
|
|
341
329
|
} else if (name === 'tz') {
|
|
342
330
|
this.timezone = +value;
|
|
343
331
|
}
|
|
@@ -359,12 +347,15 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
359
347
|
|
|
360
348
|
public readonly genPeriodTimes = (options: GenPeriodTimesOptions) =>
|
|
361
349
|
genPeriodTimes({ weekStartAt: this.weekStartAt, ...options });
|
|
362
|
-
public readonly
|
|
350
|
+
public readonly quickGenPeriodTimes = <T extends DataLimit = DataLimit>(
|
|
363
351
|
periods: T[]
|
|
364
|
-
) =>
|
|
365
|
-
public readonly
|
|
352
|
+
) => quickGenPeriodTimes({ weekStartAt: this.weekStartAt, periods });
|
|
353
|
+
public readonly quickGenPeriodTime = <T extends DataLimit = DataLimit>(
|
|
366
354
|
period: T
|
|
367
|
-
) =>
|
|
355
|
+
) => quickGenPeriodTime(period, { weekStartAt: this.weekStartAt });
|
|
356
|
+
public readonly quickGenPeriodTimeInfo = <T extends DataLimit = DataLimit>(
|
|
357
|
+
type: T
|
|
358
|
+
) => quickGenPeriodTimeInfo(type, { weekStartAt: this.weekStartAt });
|
|
368
359
|
}
|
|
369
360
|
|
|
370
361
|
Ele.define();
|
|
@@ -35,12 +35,14 @@ const genStartDate = (fn?: (_t: Date) => void, t?: Date) =>
|
|
|
35
35
|
const genEndDate = (fn?: (_t: Date) => void, t?: Date) =>
|
|
36
36
|
genDateWithHours(false, fn, t);
|
|
37
37
|
|
|
38
|
-
export
|
|
39
|
-
start?: (time: Date, weekOffset: number) => void;
|
|
40
|
-
end?: (time: Date, weekOffset: number) => void;
|
|
38
|
+
export interface QuickGenPeriodTimesOptions {
|
|
41
39
|
initTime?: Date;
|
|
42
40
|
weekStartAt?: Weeks;
|
|
43
|
-
}
|
|
41
|
+
}
|
|
42
|
+
export interface GenPeriodTimesOptions extends QuickGenPeriodTimesOptions {
|
|
43
|
+
start?: (time: Date, weekOffset: number) => void;
|
|
44
|
+
end?: (time: Date, weekOffset: number) => void;
|
|
45
|
+
}
|
|
44
46
|
|
|
45
47
|
export const genPeriodTimes = ({
|
|
46
48
|
start,
|
|
@@ -115,38 +117,44 @@ const presetPeriods = {
|
|
|
115
117
|
})
|
|
116
118
|
};
|
|
117
119
|
|
|
118
|
-
export const
|
|
119
|
-
weekStartAt = 'sun',
|
|
120
|
+
export const quickGenPeriodTimes = <T extends DataLimit = DataLimit>({
|
|
120
121
|
periods = limitKeys as T[],
|
|
121
|
-
|
|
122
|
-
}: {
|
|
123
|
-
weekStartAt?: Weeks;
|
|
124
|
-
periods?: T[];
|
|
125
|
-
initTime?: Date;
|
|
126
|
-
} = {}) => {
|
|
122
|
+
...options
|
|
123
|
+
}: { periods?: T[] } & QuickGenPeriodTimesOptions = {}) => {
|
|
127
124
|
periods = [...new Set(periods)].filter((k) => k in presetPeriods);
|
|
128
125
|
return Object.fromEntries(
|
|
129
|
-
periods.map((k) => [
|
|
130
|
-
k,
|
|
131
|
-
presetPeriods[k]({
|
|
132
|
-
weekStartAt,
|
|
133
|
-
initTime
|
|
134
|
-
})
|
|
135
|
-
])
|
|
126
|
+
periods.map((k) => [k, presetPeriods[k](options)])
|
|
136
127
|
) as Record<Exclude<T, 'all'>, { start: Date; end: Date }> &
|
|
137
128
|
('all' extends T ? { all: null } : {});
|
|
138
129
|
};
|
|
139
130
|
|
|
140
|
-
export const
|
|
141
|
-
period,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
131
|
+
export const quickGenPeriodTime = <T extends DataLimit = DataLimit>(
|
|
132
|
+
period: T,
|
|
133
|
+
options: QuickGenPeriodTimesOptions = {}
|
|
134
|
+
) =>
|
|
135
|
+
presetPeriods[period](options) as T extends 'all'
|
|
136
|
+
? null
|
|
137
|
+
: { start: Date; end: Date };
|
|
138
|
+
|
|
139
|
+
export type PeriodTimeInfo<
|
|
140
|
+
T extends QuickKey = QuickKey,
|
|
141
|
+
RT = Date
|
|
142
|
+
> = T extends 'all'
|
|
143
|
+
? {
|
|
144
|
+
type: 'all';
|
|
145
|
+
start?: null;
|
|
146
|
+
end?: null;
|
|
147
|
+
}
|
|
148
|
+
: {
|
|
149
|
+
type: Exclude<T, 'all'>;
|
|
150
|
+
start: RT;
|
|
151
|
+
end: RT;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export const quickGenPeriodTimeInfo = <T extends DataLimit = DataLimit>(
|
|
155
|
+
type: T,
|
|
156
|
+
options: QuickGenPeriodTimesOptions = {}
|
|
157
|
+
) => {
|
|
158
|
+
const t = quickGenPeriodTime(type, options);
|
|
159
|
+
return (!t ? { type } : { type, ...t }) as PeriodTimeInfo<T>;
|
|
160
|
+
};
|