@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 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="currentColor"><path d="m8.02 10.54 3.96-4.4a.583.583 0 0 0-.433-.973h-7.88a.583.583 0 0 0-.434.973l3.94 4.378c.216.24.585.26.824.044l.022-.021Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="17" fill="currentColor"><path d="M9.037 1.98a.5.5 0 1 1 .707.707l-5.87 5.87 5.774 5.774a.5.5 0 1 1-.707.707L2.813 8.911a.5.5 0 0 1 .051-.752.505.505 0 0 1 .045-.051L9.037 1.98ZM13.037 1.98a.5.5 0 0 1 .707.707l-5.87 5.87 5.774 5.774a.5.5 0 1 1-.707.707L6.813 8.911a.5.5 0 0 1 .051-.752.505.505 0 0 1 .045-.051l6.128-6.128Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="17" fill="currentColor"><path d="M11.687 1.703a.5.5 0 0 0-.707 0L4.852 7.83a.505.505 0 0 0-.045.05.5.5 0 0 0-.051.752l6.128 6.128a.5.5 0 0 0 .707-.707L5.817 8.28l5.87-5.87a.5.5 0 0 0 0-.707Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" fill="currentColor"><path d="M7.963 1.703a.5.5 0 0 0-.707.707l5.87 5.87-5.774 5.774a.5.5 0 0 0 .707.707l6.128-6.128a.5.5 0 0 0-.051-.751.493.493 0 0 0-.045-.051L7.963 1.703ZM3.963 1.703a.5.5 0 0 0-.707.707l5.87 5.87-5.774 5.774a.5.5 0 0 0 .707.707l6.128-6.128a.5.5 0 0 0-.051-.751.493.493 0 0 0-.045-.051L3.963 1.703Z"/></svg>
@@ -0,0 +1 @@
1
+ <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>
@@ -0,0 +1 @@
1
+ <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>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="14" height="15" fill="currentColor"><path d="M7.4335 4.241a.4376.4376 0 0 0-.871.0594v3.783l.0044.0622a.4375.4375 0 0 0 .1921.3029L8.9242 9.877l.0566.0317a.4376.4376 0 0 0 .5495-.1559l.0317-.0566a.4376.4376 0 0 0-.1559-.5495L7.4375 7.8471V4.3004l-.004-.0593ZM7 1.6667c-3.2217 0-5.8333 2.6116-5.8333 5.8333 0 3.2217 2.6116 5.8333 5.8333 5.8333 3.2217 0 5.8333-2.6116 5.8333-5.8333 0-3.2217-2.6116-5.8333-5.8333-5.8333Zm0 .814c2.7721 0 5.0194 2.2472 5.0194 5.0193 0 2.7721-2.2473 5.0194-5.0194 5.0194S1.9806 10.2721 1.9806 7.5 4.228 2.4806 7 2.4806Z"/></svg>
@@ -0,0 +1,108 @@
1
+ :host {
2
+ --gap: var(--calendar-item-gap, 10px 0);
3
+ --item-size: var(--calendar-item-size, 30px);
4
+ --color-disabled-text: var(--calendar-item-disabled-text, #aaa);
5
+ --color-active-bg: var(--calendar-item-active-bg, #002BE7);
6
+ --color-active-text: var(--calendar-item-active-text, #fff);
7
+ --color-in-range-bg: var(--calendar-item-in-range-bg, #002BE726);
8
+ --color-in-range-text: var(--calendar-item-in-range-text, #002BE7);
9
+ --color-hover-bg: var(--calendar-item-hover-bg, #0000000D);
10
+ --color-hover-text: var(--calendar-item-hover-text, #000);
11
+ }
12
+
13
+ .wrapper {
14
+ display: grid;
15
+ grid-template-columns: repeat(7, 1fr);
16
+ gap: var(--gap);
17
+ width: 100%;
18
+ height: 100%;
19
+ justify-content: space-between;
20
+ text-align: center;
21
+ }
22
+
23
+ .week {
24
+ min-width: var(--item-size);
25
+ }
26
+
27
+ .item {
28
+ min-width: var(--item-size);
29
+ line-height: var(--item-size);
30
+ height: var(--item-size);
31
+ position: relative;
32
+ --half-period-bg-w: calc(50% + var(--item-size) / 2);
33
+ }
34
+ .item span {
35
+ position: relative;
36
+ z-index: 2;
37
+ }
38
+ .item:not(.disabled) {
39
+ cursor: pointer;
40
+ }
41
+ :host([show-other-month]) .item.prev.disabled, :host([show-other-month]) .item.next.disabled, .item.disabled:not(.prev, .next) {
42
+ cursor: not-allowed;
43
+ color: var(--color-disabled-text);
44
+ }
45
+ .item:hover {
46
+ color: var(--color-hover-text);
47
+ }
48
+ .item.in-range {
49
+ color: var(--color-in-range-text);
50
+ }
51
+ .item:not(.disabled) .highlight {
52
+ display: block;
53
+ border-radius: 50%;
54
+ position: absolute;
55
+ top: 50%;
56
+ left: 50%;
57
+ width: var(--item-size);
58
+ height: var(--item-size);
59
+ transform: translate(-50%, -50%);
60
+ }
61
+ .item.start, .item.end {
62
+ color: var(--color-active-text);
63
+ }
64
+ .item.start .highlight, .item.end .highlight {
65
+ background-color: var(--color-active-bg);
66
+ }
67
+ .item:hover .highlight {
68
+ background-color: var(--color-hover-bg);
69
+ }
70
+ .item.in-range .bg {
71
+ display: block;
72
+ position: absolute;
73
+ top: 0;
74
+ left: 0;
75
+ width: 100%;
76
+ height: 100%;
77
+ background-color: rgba(0, 43, 231, 0.1490196078);
78
+ }
79
+ .item:nth-of-type(7n + 1) .bg {
80
+ border-radius: var(--item-size) 0 0 var(--item-size);
81
+ width: var(--half-period-bg-w);
82
+ left: calc(50% - var(--item-size) / 2);
83
+ }
84
+ .item:nth-of-type(7n) .bg {
85
+ border-radius: 0 var(--item-size) var(--item-size) 0;
86
+ width: var(--half-period-bg-w);
87
+ }
88
+ .item:nth-of-type(7n).range-start .bg {
89
+ width: var(--item-size);
90
+ left: calc(50% - var(--item-size) / 2);
91
+ }
92
+ .item.range-start .bg {
93
+ border-top-left-radius: var(--item-size);
94
+ border-bottom-left-radius: var(--item-size);
95
+ width: var(--half-period-bg-w);
96
+ left: calc(50% - var(--item-size) / 2);
97
+ }
98
+ .item.range-end .bg {
99
+ border-top-right-radius: var(--item-size);
100
+ border-bottom-right-radius: var(--item-size);
101
+ width: var(--half-period-bg-w);
102
+ }
103
+ .item.range-start.range-end .bg {
104
+ width: var(--item-size);
105
+ }
106
+ .item:nth-of-type(7n).range-start .bg, .item:nth-of-type(7n + 1).range-end .bg {
107
+ width: var(--item-size);
108
+ }
@@ -0,0 +1,84 @@
1
+ import { type BaseAttrs, type Emit2EventMap, UiBase } from '../web-component-base';
2
+ export type Weeks = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';
3
+ export declare const weekKey: Weeks[];
4
+ export declare const getWeekInOrder: (startAt?: Weeks | null) => Weeks[];
5
+ export interface Attrs extends BaseAttrs {
6
+ /**
7
+ * The showing time, used to determine the month to show on calendar.
8
+ * @type {`string | number`} A value that can be passed to the Date constructor.
9
+ * @default Date.now()
10
+ */
11
+ 'showing-time'?: string | number;
12
+ /**
13
+ * The start time of the calendar display range.
14
+ * @type {`string | number`} A value that can be passed to the Date constructor.
15
+ * @default 'current-time'
16
+ */
17
+ 'time-start'?: string | number;
18
+ /**
19
+ * The end time of the calendar display range.
20
+ * @type {`string | number`} A value that can be passed to the Date constructor.
21
+ * @default 'time-start'
22
+ */
23
+ 'time-end'?: string | number;
24
+ /**
25
+ * The minimum time of the calendar display range.
26
+ * @type {`string | number`} A value that can be passed to the Date constructor.
27
+ */
28
+ 'min-time'?: string | number;
29
+ /**
30
+ * The maximum time of the calendar display range.
31
+ * @type {`string | number`} A value that can be passed to the Date constructor.
32
+ */
33
+ 'max-time'?: string | number;
34
+ /**
35
+ * Set which day of the week is the first day.
36
+ * @type `'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat'`
37
+ * @default 'sun'
38
+ */
39
+ 'week-start-at'?: Weeks;
40
+ /**
41
+ * Whether to show the days of the previous and next months in the current month's calendar.
42
+ * @type {boolean}
43
+ * @default false
44
+ */
45
+ 'show-other-month'?: boolean;
46
+ }
47
+ export interface Emits {
48
+ 'select-time': Date;
49
+ 'hover-item': Date;
50
+ }
51
+ export type EventMap = Emit2EventMap<Emits>;
52
+ /**
53
+ * 基础的日历显示组件。仅显示星期和数字。
54
+ */
55
+ export declare class Ele extends UiBase<Attrs, Emits> {
56
+ static tagName: "dt-calendar-base";
57
+ static get observedAttributes(): string[];
58
+ get showingTime(): number | string | Date;
59
+ get timeStart(): number | string | Date;
60
+ get timeEnd(): number | string | Date;
61
+ get minTime(): number | string | Date;
62
+ get maxTime(): number | string | Date;
63
+ private _setTimeAttr;
64
+ set showingTime(val: number | string | Date);
65
+ set timeStart(val: number | string | Date);
66
+ set timeEnd(val: number | string | Date);
67
+ set minTime(val: number | string | Date);
68
+ set maxTime(val: number | string | Date);
69
+ get weekStartAt(): Weeks;
70
+ set weekStartAt(val: Weeks);
71
+ get showOtherMonth(): boolean;
72
+ set showOtherMonth(val: boolean);
73
+ protected _style: string;
74
+ protected _template: string;
75
+ constructor();
76
+ connectedCallback(): void;
77
+ disconnectedCallback(): void;
78
+ protected _onAttrChanged(name: string, oldValue: string, newValue: string): void;
79
+ private _onWeekStartAtChange;
80
+ private _onTimeChange;
81
+ private _onClick;
82
+ private _onPointerOver;
83
+ formatter: (i: number) => string;
84
+ }
@@ -0,0 +1,238 @@
1
+ var __freeze = Object.freeze;
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
6
+ var _a, _b, _c, _d;
7
+ import { closestByEvent, css, debounce, html } from "../../utils.mjs";
8
+ import { Ele as I18nEle } from "../i18n/index.mjs";
9
+ I18nEle.define();
10
+ import {
11
+ UiBase
12
+ } from "../web-component-base/index.mjs";
13
+ const styleStr = css(_a || (_a = __template(["\n:host {\n --gap: var(--calendar-item-gap, 10px 0);\n --item-size: var(--calendar-item-size, 30px);\n --color-disabled-text: var(--calendar-item-disabled-text, #aaa);\n --color-active-bg: var(--calendar-item-active-bg, #002BE7);\n --color-active-text: var(--calendar-item-active-text, #fff);\n --color-in-range-bg: var(--calendar-item-in-range-bg, #002BE726);\n --color-in-range-text: var(--calendar-item-in-range-text, #002BE7);\n --color-hover-bg: var(--calendar-item-hover-bg, #0000000D);\n --color-hover-text: var(--calendar-item-hover-text, #000);\n}\n\n.wrapper {\n display: grid;\n grid-template-columns: repeat(7, 1fr);\n gap: var(--gap);\n width: 100%;\n height: 100%;\n justify-content: space-between;\n text-align: center;\n}\n\n.week {\n min-width: var(--item-size);\n}\n\n.item {\n min-width: var(--item-size);\n line-height: var(--item-size);\n height: var(--item-size);\n position: relative;\n --half-period-bg-w: calc(50% + var(--item-size) / 2);\n}\n.item span {\n position: relative;\n z-index: 2;\n}\n.item:not(.disabled) {\n cursor: pointer;\n}\n:host([show-other-month]) .item.prev.disabled, :host([show-other-month]) .item.next.disabled, .item.disabled:not(.prev, .next) {\n cursor: not-allowed;\n color: var(--color-disabled-text);\n}\n.item:hover {\n color: var(--color-hover-text);\n}\n.item.in-range {\n color: var(--color-in-range-text);\n}\n.item:not(.disabled) .highlight {\n display: block;\n border-radius: 50%;\n position: absolute;\n top: 50%;\n left: 50%;\n width: var(--item-size);\n height: var(--item-size);\n transform: translate(-50%, -50%);\n}\n.item.start, .item.end {\n color: var(--color-active-text);\n}\n.item.start .highlight, .item.end .highlight {\n background-color: var(--color-active-bg);\n}\n.item:hover .highlight {\n background-color: var(--color-hover-bg);\n}\n.item.in-range .bg {\n display: block;\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgba(0, 43, 231, 0.1490196078);\n}\n.item:nth-of-type(7n + 1) .bg {\n border-radius: var(--item-size) 0 0 var(--item-size);\n width: var(--half-period-bg-w);\n left: calc(50% - var(--item-size) / 2);\n}\n.item:nth-of-type(7n) .bg {\n border-radius: 0 var(--item-size) var(--item-size) 0;\n width: var(--half-period-bg-w);\n}\n.item:nth-of-type(7n).range-start .bg {\n width: var(--item-size);\n left: calc(50% - var(--item-size) / 2);\n}\n.item.range-start .bg {\n border-top-left-radius: var(--item-size);\n border-bottom-left-radius: var(--item-size);\n width: var(--half-period-bg-w);\n left: calc(50% - var(--item-size) / 2);\n}\n.item.range-end .bg {\n border-top-right-radius: var(--item-size);\n border-bottom-right-radius: var(--item-size);\n width: var(--half-period-bg-w);\n}\n.item.range-start.range-end .bg {\n width: var(--item-size);\n}\n.item:nth-of-type(7n).range-start .bg, .item:nth-of-type(7n + 1).range-end .bg {\n width: var(--item-size);\n}\n"])));
14
+ export const weekKey = [
15
+ "sun",
16
+ "mon",
17
+ "tue",
18
+ "wed",
19
+ "thu",
20
+ "fri",
21
+ "sat"
22
+ ];
23
+ export const getWeekInOrder = (startAt) => {
24
+ if (!startAt) startAt = "sun";
25
+ const index = weekKey.indexOf(startAt);
26
+ if (index === -1) return weekKey;
27
+ return [...weekKey.slice(index), ...weekKey.slice(0, index)];
28
+ };
29
+ export class Ele extends UiBase {
30
+ constructor() {
31
+ super();
32
+ __publicField(this, "_style", styleStr);
33
+ __publicField(this, "_template", html(_d || (_d = __template(['\n<div class="wrapper">', "</div>"])), weekKey.map(
34
+ (key) => html(_b || (_b = __template(['<dt-i18n class="week" i18n-key="date.', '" part="week"></dt-i18n>'])), key)
35
+ ).join("") + [...Array(7 * 6)].map(
36
+ (_, i) => html(_c || (_c = __template(['<div class="item" part="item"><i class="bg"></i><i class="highlight"></i><span>', "</span></div>"])), i % 31 + 1)
37
+ ).join("")));
38
+ __publicField(this, "_onWeekStartAtChange", debounce(() => {
39
+ if (!this.isConnected) return;
40
+ const weekOrder = getWeekInOrder(this.weekStartAt);
41
+ this.shadowRoot.querySelectorAll(".week").forEach((ele, i) => {
42
+ ele.setAttribute("i18n-key", "date.".concat(weekOrder[i]));
43
+ });
44
+ this._onTimeChange();
45
+ }, 0));
46
+ __publicField(this, "_onTimeChange", debounce(() => {
47
+ if (!this.isConnected) return;
48
+ const currentTime = this.showingTime;
49
+ let timeStart = this.timeStart;
50
+ let timeEnd = this.timeEnd;
51
+ currentTime.setHours(0, 0, 0, 0);
52
+ timeStart.setHours(0, 0, 0, 0);
53
+ timeEnd.setHours(0, 0, 0, 0);
54
+ if (Number.isNaN(+currentTime) || Number.isNaN(+timeStart) || Number.isNaN(+timeEnd)) {
55
+ console.warn("Invalid date attribute(s) on <".concat(this.tagName, ">"));
56
+ return;
57
+ }
58
+ if (timeStart > timeEnd) {
59
+ [timeStart, timeEnd] = [timeEnd, timeStart];
60
+ }
61
+ const minTime = new Date(this._getAttr("min-time") || "");
62
+ const maxTime = new Date(this._getAttr("max-time") || "");
63
+ minTime.setHours(0, 0, 0, 0);
64
+ maxTime.setHours(0, 0, 0, 0);
65
+ if (maxTime < timeEnd) timeEnd = maxTime;
66
+ if (timeStart < minTime) timeStart = minTime;
67
+ const weekStartAt = this.weekStartAt;
68
+ const year = currentTime.getFullYear();
69
+ const month = currentTime.getMonth();
70
+ const days = new Date(year, month + 1, 0).getDate();
71
+ const daysPrev = new Date(year, month, 0).getDate();
72
+ const firstWeekOfCurMonth = new Date(year, month, 1).getDay();
73
+ const weekStartOffset = weekKey.indexOf(weekStartAt);
74
+ const adjustedFirstWeek = (firstWeekOfCurMonth - weekStartOffset + 7) % 7;
75
+ let itemIdx = 0;
76
+ const items = this.shadowRoot.querySelectorAll(".item");
77
+ const changeItemText = (item, text) => {
78
+ item.querySelector("span").textContent = text;
79
+ };
80
+ items.forEach((ele) => {
81
+ ele.className = "item disabled";
82
+ ele.removeAttribute("data-time");
83
+ ele.setAttribute("part", "item disabled");
84
+ changeItemText(ele, " ");
85
+ });
86
+ for (let i = daysPrev - adjustedFirstWeek + 1; i <= daysPrev; ++i) {
87
+ const ele = items[itemIdx++];
88
+ ele.classList.add("prev");
89
+ ele.part.add("prev");
90
+ changeItemText(ele, this.showOtherMonth ? this.formatter(i) : " ");
91
+ }
92
+ for (let i = 1; i <= days; ++i) {
93
+ const ele = items[itemIdx++];
94
+ const time = new Date(year, month, i);
95
+ ele.classList.toggle("month-start", i === 1);
96
+ ele.classList.toggle("month-end", i === days);
97
+ ele.classList.toggle("disabled", time < minTime || time > maxTime);
98
+ ele.classList.toggle("start", +time === +timeStart);
99
+ ele.classList.toggle(
100
+ "in-range",
101
+ +time >= +timeStart && +time <= +timeEnd
102
+ );
103
+ ele.classList.toggle("end", +time === +timeEnd);
104
+ ele.setAttribute("part", ele.className);
105
+ ele.dataset.time = time.toISOString();
106
+ changeItemText(ele, this.formatter(i));
107
+ }
108
+ const inRangeItem = Array.from(
109
+ this.shadowRoot.querySelectorAll(".item.in-range")
110
+ );
111
+ if (inRangeItem.length) {
112
+ inRangeItem[0].classList.add("range-start");
113
+ inRangeItem[0].part.add("range-start");
114
+ inRangeItem[inRangeItem.length - 1].classList.add("range-end");
115
+ inRangeItem[inRangeItem.length - 1].part.add("range-end");
116
+ }
117
+ for (let i = 1; itemIdx < items.length; ++i) {
118
+ const ele = items[itemIdx++];
119
+ ele.classList.add("next");
120
+ ele.part.add("next");
121
+ changeItemText(ele, this.showOtherMonth ? this.formatter(i) : " ");
122
+ }
123
+ }, 0));
124
+ __publicField(this, "_onClick", (e) => {
125
+ const item = closestByEvent(e, ".item[data-time]:not(.disabled)", this);
126
+ if (!item) return;
127
+ const time = new Date(item.dataset.time);
128
+ super.dispatchEvent("select-time", time, true);
129
+ });
130
+ __publicField(this, "_onPointerOver", (e) => {
131
+ const item = closestByEvent(e, ".item[data-time]:not(.disabled)", this);
132
+ if (!item) return;
133
+ const time = new Date(item.dataset.time);
134
+ super.dispatchEvent("hover-item", time, true);
135
+ });
136
+ __publicField(this, "formatter", (i) => "" + i);
137
+ this._applyTemplate();
138
+ }
139
+ static get observedAttributes() {
140
+ return [
141
+ ...super.observedAttributes,
142
+ "showing-time",
143
+ "time-start",
144
+ "time-end",
145
+ "min-time",
146
+ "max-time",
147
+ "week-start-at"
148
+ ];
149
+ }
150
+ get showingTime() {
151
+ const v = this._getAttr("showing-time", "" + Date.now());
152
+ return new Date(Number.isNaN(+v) ? v : +v);
153
+ }
154
+ get timeStart() {
155
+ const v = this._getAttr("time-start", "" + this.showingTime);
156
+ return new Date(Number.isNaN(+v) ? v : +v);
157
+ }
158
+ get timeEnd() {
159
+ const v = this._getAttr("time-end", "" + this.timeStart);
160
+ return new Date(Number.isNaN(+v) ? v : +v);
161
+ }
162
+ get minTime() {
163
+ const v = this._getAttr("min-time", "");
164
+ return new Date(Number.isNaN(+v) ? v : +v);
165
+ }
166
+ get maxTime() {
167
+ const v = this._getAttr("max-time", "");
168
+ return new Date(Number.isNaN(+v) ? v : +v);
169
+ }
170
+ _setTimeAttr(name, value) {
171
+ const v = new Date(value);
172
+ if (Number.isNaN(+v)) return;
173
+ this.setAttribute(name, +v + "");
174
+ }
175
+ set showingTime(val) {
176
+ this._setTimeAttr("showing-time", val);
177
+ }
178
+ set timeStart(val) {
179
+ this._setTimeAttr("time-start", val);
180
+ }
181
+ set timeEnd(val) {
182
+ this._setTimeAttr("time-end", val);
183
+ }
184
+ set minTime(val) {
185
+ this._setTimeAttr("min-time", val);
186
+ }
187
+ set maxTime(val) {
188
+ this._setTimeAttr("max-time", val);
189
+ }
190
+ get weekStartAt() {
191
+ return this._getAttr("week-start-at", "sun");
192
+ }
193
+ set weekStartAt(val) {
194
+ if (weekKey.includes(val)) return;
195
+ this.setAttribute("week-start-at", val);
196
+ }
197
+ get showOtherMonth() {
198
+ return this.hasAttribute("show-other-month");
199
+ }
200
+ set showOtherMonth(val) {
201
+ this.setAttribute("show-other-month", "" + val);
202
+ }
203
+ connectedCallback() {
204
+ if (!super.connectedCallback()) return;
205
+ this._onWeekStartAtChange();
206
+ this._onTimeChange();
207
+ this.addEventListener("click", this._onClick);
208
+ this.shadowRoot.querySelector(".wrapper").addEventListener(
209
+ "pointerover",
210
+ this._onPointerOver
211
+ );
212
+ }
213
+ disconnectedCallback() {
214
+ if (!super.disconnectedCallback()) return;
215
+ this.removeEventListener("click", this._onClick);
216
+ this.shadowRoot.querySelector(".wrapper").removeEventListener(
217
+ "pointerover",
218
+ this._onPointerOver
219
+ );
220
+ }
221
+ _onAttrChanged(name, oldValue, newValue) {
222
+ super._onAttrChanged(name, oldValue, newValue);
223
+ if (name === "week-start-at") {
224
+ this._onWeekStartAtChange();
225
+ }
226
+ if ([
227
+ "showing-time",
228
+ "time-start",
229
+ "time-end",
230
+ "min-time",
231
+ "max-time"
232
+ ].includes(name)) {
233
+ this._onTimeChange();
234
+ }
235
+ }
236
+ }
237
+ __publicField(Ele, "tagName", "dt-calendar-base");
238
+ Ele.define();
@@ -0,0 +1,60 @@
1
+ :host {
2
+ display: flex;
3
+ flex-direction: column;
4
+ overflow: hidden;
5
+ gap: 15px;
6
+ }
7
+
8
+ .cols {
9
+ flex: 1;
10
+ display: flex;
11
+ flex-direction: row;
12
+ height: 0;
13
+ justify-content: space-between;
14
+ gap: 2px;
15
+ }
16
+
17
+ .col {
18
+ flex: 1;
19
+ display: flex;
20
+ flex-direction: column;
21
+ gap: 10px;
22
+ }
23
+
24
+ .col > span {
25
+ text-align: center;
26
+ display: inline-block;
27
+ line-height: 27px;
28
+ }
29
+
30
+ dt-num-list {
31
+ flex: 1;
32
+ }
33
+
34
+ .ms-input {
35
+ width: 100%;
36
+ box-sizing: border-box;
37
+ border: 1px solid rgba(0, 0, 0, 0.2);
38
+ border-radius: 6px;
39
+ padding: 4px;
40
+ cursor: text;
41
+ }
42
+
43
+ label > span {
44
+ display: inline-block;
45
+ line-height: 1;
46
+ font-size: 14px;
47
+ margin-bottom: 2px;
48
+ }
49
+
50
+ input {
51
+ width: 100%;
52
+ box-sizing: border-box;
53
+ padding: 0;
54
+ border: none;
55
+ outline: none;
56
+ }
57
+
58
+ input::placeholder {
59
+ color: #999;
60
+ }
@@ -0,0 +1,54 @@
1
+ import { type BaseAttrs, type Emit2EventMap, UiBase } from '../web-component-base';
2
+ export interface Attrs extends BaseAttrs {
3
+ millisecond: number;
4
+ /**
5
+ * 选择器的粒度,表示最大可选的时间单位。默认为 hour。
6
+ * 例如设置为 'minute',则表示最大只能选择到分钟,小时将被忽略。
7
+ */
8
+ 'max-granularity'?: 'hour' | 'minute' | 'second' | 'millisecond';
9
+ /**
10
+ * 选择器的粒度,表示最小可选的时间单位。默认为 millisecond。
11
+ * 例如设置为 'minute',则表示只能选择到分钟,秒和毫秒将被忽略。
12
+ */
13
+ 'min-granularity'?: 'hour' | 'minute' | 'second' | 'millisecond';
14
+ 'col-order'?: 'hms' | 'hsm' | 'mhs' | 'msh' | 'shm' | 'smh';
15
+ }
16
+ export interface Emits {
17
+ change: {
18
+ oldMs: number;
19
+ newMs: number;
20
+ };
21
+ }
22
+ export type EventMap = Emit2EventMap<Emits>;
23
+ /**
24
+ * 时分秒毫秒选择器
25
+ */
26
+ export declare class Ele extends UiBase<Attrs, Emits> {
27
+ static readonly tagName: "dt-hhmmss-ms-list-grp";
28
+ static get observedAttributes(): string[];
29
+ protected _style: string;
30
+ protected _template: string;
31
+ constructor();
32
+ private get _colsHourEle();
33
+ private get _colsMinuteEle();
34
+ private get _colsSecondEle();
35
+ private get _msInputEle();
36
+ get millisecond(): number;
37
+ set millisecond(v: number);
38
+ get maxGranularity(): "hour" | "minute" | "second" | "millisecond";
39
+ set maxGranularity(v: 'hour' | 'minute' | 'second' | 'millisecond');
40
+ get minGranularity(): "hour" | "minute" | "second" | "millisecond";
41
+ set minGranularity(v: 'hour' | 'minute' | 'second' | 'millisecond');
42
+ get colOrder(): "hms" | "hsm" | "mhs" | "msh" | "shm" | "smh";
43
+ set colOrder(v: 'hms' | 'hsm' | 'mhs' | 'msh' | 'shm' | 'smh');
44
+ scrollToCurrentItem(): void;
45
+ connectedCallback(): void;
46
+ disconnectedCallback(): void;
47
+ protected _onAttrChanged(name: string, oldValue: string, newValue: string): void;
48
+ private _renderCols;
49
+ private _updateGranularity;
50
+ private _updateColsValue;
51
+ private _getMsFromEle;
52
+ private _onMsInput;
53
+ private _onColsSelect;
54
+ }