1 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6 | };
|
7 | var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
8 | if (kind === "m") throw new TypeError("Private method is not writable");
|
9 | if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
10 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
11 | return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
12 | };
|
13 | var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
14 | if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
15 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
16 | return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
17 | };
|
18 | var _DuoyunCalendarElement_isHighlight, _DuoyunCalendarElement_dates;
|
19 | var DuoyunCalendarElement_1;
|
20 | import { adoptedStyle, customElement, emitter, property, boolattribute, part, } from '@mantou/gem/lib/decorators';
|
21 | import { GemElement, html } from '@mantou/gem/lib/element';
|
22 | import { createCSSSheet, css, classMap, partMap } from '@mantou/gem/lib/utils';
|
23 | import { isNotNullish } from '../lib/types';
|
24 | import { Time } from '../lib/time';
|
25 | import { theme } from '../lib/theme';
|
26 | import { commonHandle } from '../lib/hotkeys';
|
27 | import { focusStyle } from '../lib/styles';
|
28 | const style = createCSSSheet(css `
|
29 | :host(:where(:not([hidden]))) {
|
30 | font-size: 0.875em;
|
31 | display: grid;
|
32 | gap: 1px;
|
33 | grid-template-columns: repeat(7, minmax(0, 1fr));
|
34 | border-radius: ${theme.normalRound};
|
35 | border-color: ${theme.borderColor};
|
36 | }
|
37 | .day,
|
38 | .head {
|
39 | aspect-ratio: 1 / 1;
|
40 | display: flex;
|
41 | flex-direction: column;
|
42 | align-items: center;
|
43 | justify-content: center;
|
44 | margin: -1px;
|
45 | border: 1px solid;
|
46 | border-color: inherit;
|
47 | }
|
48 | .head {
|
49 | border-block-end-color: ${theme.lightBackgroundColor};
|
50 | }
|
51 | .head:first-of-type {
|
52 | border-start-start-radius: inherit;
|
53 | }
|
54 | .head:nth-of-type(7) {
|
55 | border-start-end-radius: inherit;
|
56 | }
|
57 | .day {
|
58 | position: relative;
|
59 | z-index: 1;
|
60 | }
|
61 | .day:where(:hover) {
|
62 | background: ${theme.hoverBackgroundColor};
|
63 | }
|
64 | .leftbottom {
|
65 | border-end-start-radius: inherit;
|
66 | }
|
67 | .day:last-of-type {
|
68 | border-end-end-radius: inherit;
|
69 | }
|
70 | .other {
|
71 | z-index: 0;
|
72 | color: ${theme.disabledColor};
|
73 | }
|
74 | .other:where(:hover) {
|
75 | background: ${theme.lightBackgroundColor};
|
76 | }
|
77 | .today {
|
78 | z-index: 2;
|
79 | }
|
80 | .today::before,
|
81 | .today::after {
|
82 | content: '';
|
83 | position: absolute;
|
84 | border-radius: inherit;
|
85 | margin: -1px;
|
86 | border: 1px solid ${theme.backgroundColor};
|
87 | }
|
88 | .today::before {
|
89 | inset: 2px;
|
90 | }
|
91 | .today::after {
|
92 | border-color: ${theme.primaryColor};
|
93 | inset: 0;
|
94 | }
|
95 | .highlight {
|
96 | z-index: 2;
|
97 | background: ${theme.primaryColor};
|
98 | color: ${theme.backgroundColor};
|
99 | }
|
100 | .start {
|
101 | border-start-start-radius: ${theme.smallRound};
|
102 | border-end-start-radius: ${theme.smallRound};
|
103 | }
|
104 | .stop {
|
105 | border-start-end-radius: ${theme.smallRound};
|
106 | border-end-end-radius: ${theme.smallRound};
|
107 | }
|
108 | :host([borderless]) {
|
109 | border: none;
|
110 | padding: 1px;
|
111 | border-radius: 0;
|
112 | border-color: transparent;
|
113 | }
|
114 | `);
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 | let DuoyunCalendarElement = DuoyunCalendarElement_1 = class DuoyunCalendarElement extends GemElement {
|
121 | constructor() {
|
122 | super({ delegatesFocus: true });
|
123 | _DuoyunCalendarElement_isHighlight.set(this, (date) => {
|
124 | var _a;
|
125 | const t = date.valueOf();
|
126 | return !!((_a = this.highlights) === null || _a === void 0 ? void 0 : _a.some(([start, stop]) => t >= start && t <= stop));
|
127 | });
|
128 | _DuoyunCalendarElement_dates.set(this, void 0);
|
129 | this.willMount = () => {
|
130 | this.memo(() => {
|
131 | const today = new Time();
|
132 | const startTime = isNotNullish(this.position) ? new Time(this.position) : today;
|
133 | const start = new Time(startTime).startOf('M');
|
134 | const startDay = start.getDay();
|
135 | const stop = new Time(startTime).endOf('M');
|
136 | const stopDay = stop.getDay();
|
137 | const dates = [];
|
138 | for (let i = 0; i < startDay; i++) {
|
139 | dates.push({ date: new Time(start).subtract(startDay - i, 'd') });
|
140 | }
|
141 | let s = start;
|
142 | while (s.valueOf() < stop.valueOf()) {
|
143 | dates.push({ date: new Time(s), isThisMonth: true, isToday: today.isSome(s, 'd') });
|
144 | s = new Time(s).add(1, 'd');
|
145 | }
|
146 | for (let i = 1; i < 7 - stopDay; i++) {
|
147 | dates.push({ date: new Time(stop).add(i, 'd') });
|
148 | }
|
149 | __classPrivateFieldSet(this, _DuoyunCalendarElement_dates, dates, "f");
|
150 | }, () => [this.position]);
|
151 | };
|
152 | this.render = () => {
|
153 | return html `
|
154 | ${__classPrivateFieldGet(this, _DuoyunCalendarElement_dates, "f").slice(0, 7).map(({ date }, index) => html `
|
155 | <div
|
156 | class="head"
|
157 | part=${partMap({
|
158 | [DuoyunCalendarElement_1.headerRow]: true,
|
159 | [DuoyunCalendarElement_1.headerLeftCell]: index === 0,
|
160 | [DuoyunCalendarElement_1.headerRightCell]: index === 6,
|
161 | })}
|
162 | >
|
163 | ${date.format({ weekday: 'narrow' })}
|
164 | </div>
|
165 | `)}
|
166 | ${__classPrivateFieldGet(this, _DuoyunCalendarElement_dates, "f").map(({ date, isThisMonth, isToday }, index, arr) => {
|
167 | var _a, _b, _c;
|
168 | return html `
|
169 | <div
|
170 | tabindex="0"
|
171 | role="button"
|
172 | part=${partMap({
|
173 | [DuoyunCalendarElement_1.dayCell]: true,
|
174 | [DuoyunCalendarElement_1.todayCell]: !!isToday,
|
175 | [DuoyunCalendarElement_1.otherDayCell]: !isThisMonth,
|
176 | [DuoyunCalendarElement_1.leftTopCell]: index === 0,
|
177 | [DuoyunCalendarElement_1.rightTopCell]: index === 6,
|
178 | [DuoyunCalendarElement_1.leftBottomCell]: index === arr.length - 7,
|
179 | [DuoyunCalendarElement_1.rightBottomCell]: index === arr.length - 1,
|
180 | })}
|
181 | class=${classMap({
|
182 | day: true,
|
183 | leftbottom: index === arr.length - 7,
|
184 | ...(isThisMonth
|
185 | ? {
|
186 | today: this.today && !!isToday,
|
187 | start: !!((_a = this.highlights) === null || _a === void 0 ? void 0 : _a.some(([d]) => date.isSome(d, 'd'))),
|
188 | stop: !!((_b = this.highlights) === null || _b === void 0 ? void 0 : _b.some((ds) => date.isSome(ds[ds.length - 1], 'd'))),
|
189 | highlight: __classPrivateFieldGet(this, _DuoyunCalendarElement_isHighlight, "f").call(this, date),
|
190 | }
|
191 | : {
|
192 | other: true,
|
193 | }),
|
194 | })}
|
195 | @click=${() => this.dateclick(date.valueOf())}
|
196 | @mouseover=${() => this.datehover(date.valueOf())}
|
197 | @keydown=${commonHandle}
|
198 | >
|
199 | <span part=${partMap({ date: true, todaydate: !!isToday })}>${date.getDate()}</span>
|
200 | ${(_c = this.renderDate) === null || _c === void 0 ? void 0 : _c.call(this, date)}
|
201 | </div>
|
202 | `;
|
203 | })}
|
204 | `;
|
205 | };
|
206 | }
|
207 | };
|
208 | _DuoyunCalendarElement_isHighlight = new WeakMap(), _DuoyunCalendarElement_dates = new WeakMap();
|
209 | __decorate([
|
210 | emitter
|
211 | ], DuoyunCalendarElement.prototype, "datehover", void 0);
|
212 | __decorate([
|
213 | emitter
|
214 | ], DuoyunCalendarElement.prototype, "dateclick", void 0);
|
215 | __decorate([
|
216 | boolattribute
|
217 | ], DuoyunCalendarElement.prototype, "borderless", void 0);
|
218 | __decorate([
|
219 | boolattribute
|
220 | ], DuoyunCalendarElement.prototype, "today", void 0);
|
221 | __decorate([
|
222 | property
|
223 | ], DuoyunCalendarElement.prototype, "position", void 0);
|
224 | __decorate([
|
225 | property
|
226 | ], DuoyunCalendarElement.prototype, "highlights", void 0);
|
227 | __decorate([
|
228 | property
|
229 | ], DuoyunCalendarElement.prototype, "renderDate", void 0);
|
230 | __decorate([
|
231 | part
|
232 | ], DuoyunCalendarElement, "headerRow", void 0);
|
233 | __decorate([
|
234 | part
|
235 | ], DuoyunCalendarElement, "headerLeftCell", void 0);
|
236 | __decorate([
|
237 | part
|
238 | ], DuoyunCalendarElement, "headerRightCell", void 0);
|
239 | __decorate([
|
240 | part
|
241 | ], DuoyunCalendarElement, "dayCell", void 0);
|
242 | __decorate([
|
243 | part
|
244 | ], DuoyunCalendarElement, "todayCell", void 0);
|
245 | __decorate([
|
246 | part
|
247 | ], DuoyunCalendarElement, "otherDayCell", void 0);
|
248 | __decorate([
|
249 | part
|
250 | ], DuoyunCalendarElement, "leftTopCell", void 0);
|
251 | __decorate([
|
252 | part
|
253 | ], DuoyunCalendarElement, "rightTopCell", void 0);
|
254 | __decorate([
|
255 | part
|
256 | ], DuoyunCalendarElement, "leftBottomCell", void 0);
|
257 | __decorate([
|
258 | part
|
259 | ], DuoyunCalendarElement, "rightBottomCell", void 0);
|
260 | DuoyunCalendarElement = DuoyunCalendarElement_1 = __decorate([
|
261 | customElement('dy-calendar'),
|
262 | adoptedStyle(style),
|
263 | adoptedStyle(focusStyle)
|
264 | ], DuoyunCalendarElement);
|
265 | export { DuoyunCalendarElement };
|
266 |
|
\ | No newline at end of file |