@calenderjs/calendar 0.3.0 → 0.3.1
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/README.md +2 -2
- package/dist/index.cjs +346 -1023
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +346 -1023
- package/dist/index.mjs.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/state-date.d.ts +37 -0
- package/dist/utils/state-date.d.ts.map +1 -0
- package/dist/utils/upgrade-property.d.ts +12 -0
- package/dist/utils/upgrade-property.d.ts.map +1 -0
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -1,761 +1,13 @@
|
|
|
1
1
|
import { autoRegister, WebComponent, jsx } from "@wsxjs/wsx-core";
|
|
2
2
|
import { parseEventDSL, EventDSLCompiler } from "@calenderjs/event-dsl";
|
|
3
|
+
import { isSameDay, formatDateKey, getDayHours, getTimeString, getMonthDates, isSameMonth, getWeekDates } from "@calenderjs/date-time";
|
|
4
|
+
import { EventRuntime } from "@calenderjs/event-runtime";
|
|
3
5
|
export * from "@calenderjs/core";
|
|
4
|
-
const l = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
5
|
-
function i(t) {
|
|
6
|
-
if (t instanceof Date) {
|
|
7
|
-
if (isNaN(t.getTime()))
|
|
8
|
-
throw new Error(`Invalid date: ${t}`);
|
|
9
|
-
return t;
|
|
10
|
-
}
|
|
11
|
-
if (typeof t == "string") {
|
|
12
|
-
const e = l.exec(t);
|
|
13
|
-
if (e) {
|
|
14
|
-
const r = Number(e[1]), o = Number(e[2]), s = Number(e[3]);
|
|
15
|
-
return new Date(r, o - 1, s);
|
|
16
|
-
}
|
|
17
|
-
const n = new Date(t);
|
|
18
|
-
if (isNaN(n.getTime()))
|
|
19
|
-
throw new Error(`Invalid date: ${t}`);
|
|
20
|
-
return n;
|
|
21
|
-
}
|
|
22
|
-
throw new Error(
|
|
23
|
-
`Invalid date type: expected Date or string, got ${typeof t}`
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
function m(t) {
|
|
27
|
-
const e = i(t);
|
|
28
|
-
return new Date(e.getFullYear(), e.getMonth(), 1);
|
|
29
|
-
}
|
|
30
|
-
function h(t) {
|
|
31
|
-
const e = i(t);
|
|
32
|
-
return new Date(e.getFullYear(), e.getMonth() + 1, 0);
|
|
33
|
-
}
|
|
34
|
-
function d(t, e = 1) {
|
|
35
|
-
const n = i(t), r = n.getDay();
|
|
36
|
-
let o;
|
|
37
|
-
e === 0 ? o = n.getDate() - r : o = n.getDate() - r + (r === 0 ? -6 : 1);
|
|
38
|
-
const s = new Date(n);
|
|
39
|
-
return s.setDate(o), s.setHours(0, 0, 0, 0), s;
|
|
40
|
-
}
|
|
41
|
-
function w(t, e = 1) {
|
|
42
|
-
const n = d(t, e), r = new Date(n);
|
|
43
|
-
return r.setDate(r.getDate() + 6), r.setHours(0, 0, 0, 0), r;
|
|
44
|
-
}
|
|
45
|
-
function S(t, e = 1) {
|
|
46
|
-
const n = d(t, e), r = [];
|
|
47
|
-
for (let o = 0; o < 7; o++) {
|
|
48
|
-
const s = new Date(n);
|
|
49
|
-
s.setDate(s.getDate() + o), s.setHours(0, 0, 0, 0), r.push(s);
|
|
50
|
-
}
|
|
51
|
-
return r;
|
|
52
|
-
}
|
|
53
|
-
function p(t, e = 1) {
|
|
54
|
-
const n = m(t), r = h(t), o = d(n, e), s = w(r, e), c = [], a = new Date(o);
|
|
55
|
-
for (; a <= s; ) {
|
|
56
|
-
const u = new Date(a);
|
|
57
|
-
u.setHours(0, 0, 0, 0), c.push(u), a.setDate(a.getDate() + 1);
|
|
58
|
-
}
|
|
59
|
-
return c;
|
|
60
|
-
}
|
|
61
|
-
function y(t, e) {
|
|
62
|
-
const n = i(t), r = i(e);
|
|
63
|
-
return n.getFullYear() === r.getFullYear() && n.getMonth() === r.getMonth() && n.getDate() === r.getDate();
|
|
64
|
-
}
|
|
65
|
-
function $(t, e) {
|
|
66
|
-
const n = i(t), r = i(e);
|
|
67
|
-
return n.getFullYear() === r.getFullYear() && n.getMonth() === r.getMonth();
|
|
68
|
-
}
|
|
69
|
-
function x() {
|
|
70
|
-
return Array.from({ length: 24 }, (t, e) => e);
|
|
71
|
-
}
|
|
72
|
-
function D(t) {
|
|
73
|
-
if (t instanceof Date) {
|
|
74
|
-
if (isNaN(t.getTime()))
|
|
75
|
-
throw new Error(`Invalid date: ${t}`);
|
|
76
|
-
return t;
|
|
77
|
-
}
|
|
78
|
-
if (typeof t == "string") {
|
|
79
|
-
const e = new Date(t);
|
|
80
|
-
if (isNaN(e.getTime()))
|
|
81
|
-
throw new Error(`Invalid date: ${t}`);
|
|
82
|
-
return e;
|
|
83
|
-
}
|
|
84
|
-
throw new Error(
|
|
85
|
-
`Invalid date type: expected Date or string, got ${typeof t}`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
function b$1(t) {
|
|
89
|
-
const e = D(t), n = e.getFullYear(), r = String(e.getMonth() + 1).padStart(2, "0"), o = String(e.getDate()).padStart(2, "0");
|
|
90
|
-
return `${n}-${r}-${o}`;
|
|
91
|
-
}
|
|
92
|
-
function W(t) {
|
|
93
|
-
const e = D(t), n = String(e.getHours()).padStart(2, "0"), r = String(e.getMinutes()).padStart(2, "0");
|
|
94
|
-
return `${n}:${r}`;
|
|
95
|
-
}
|
|
96
6
|
const styles$3 = '/* Calendar Component Styles - Google Calendar Inspired */\n\n:host {\n display: block;\n width: 100%;\n height: 100%;\n font-family: var(\n --calender-font-family,\n "Google Sans",\n Roboto,\n Arial,\n sans-serif\n );\n font-size: var(--calender-font-size, 14px);\n color: var(--calender-text-color, #202124);\n background: var(--calender-bg-color, #fff);\n}\n\n.calendar {\n display: flex;\n flex-direction: column;\n height: 100%;\n width: 100%;\n background: var(--calender-bg-color, #fff);\n}\n\n/* Toolbar Styles */\n.calendar-toolbar {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: var(--calender-toolbar-padding, 8px 16px);\n border-bottom: 1px solid var(--calender-border-color, #dadce0);\n background: var(--calender-bg-color, #fff);\n min-height: var(--calender-toolbar-min-height, 48px);\n}\n\n.calendar-toolbar-left {\n display: flex;\n align-items: center;\n gap: var(--calender-toolbar-gap, 8px);\n}\n\n.calendar-toolbar-right {\n display: flex;\n align-items: center;\n gap: var(--calender-toolbar-gap, 8px);\n}\n\n.calendar-nav-button {\n display: flex;\n align-items: center;\n justify-content: center;\n width: var(--calender-nav-button-size, 40px);\n height: var(--calender-nav-button-size, 40px);\n border: none;\n background: transparent;\n border-radius: 50%;\n cursor: pointer;\n color: var(--calender-text-secondary-color, #5f6368);\n transition: background-color var(--calender-transition-duration, 0.2s);\n}\n\n.calendar-nav-button:hover {\n background-color: var(--calender-hover-bg-color, #f1f3f4);\n}\n\n.calendar-nav-button:active {\n background-color: var(--calender-active-bg-color, #e8eaed);\n}\n\n.calendar-nav-button svg {\n width: var(--calender-icon-size, 24px);\n height: var(--calender-icon-size, 24px);\n fill: currentColor;\n}\n\n.calendar-today-button {\n padding: var(--calender-button-padding, 8px 16px);\n border: 1px solid var(--calender-border-color, #dadce0);\n border-radius: var(--calender-border-radius, 4px);\n background: var(--calender-bg-color, #fff);\n color: var(--calender-text-color, #202124);\n font-size: var(--calender-font-size, 14px);\n font-weight: var(--calender-button-font-weight, 500);\n cursor: pointer;\n transition:\n background-color var(--calender-transition-duration, 0.2s),\n border-color var(--calender-transition-duration, 0.2s);\n}\n\n.calendar-today-button:hover {\n background-color: var(--calender-hover-bg-color-light, #f8f9fa);\n border-color: var(--calender-border-hover-color, #c4c7c5);\n}\n\n.calendar-today-button:active {\n background-color: var(--calender-active-bg-color, #f1f3f4);\n}\n\n.calendar-toolbar-date {\n font-size: var(--calender-toolbar-date-font-size, 22px);\n font-weight: var(--calender-toolbar-date-font-weight, 400);\n color: var(--calender-text-color, #202124);\n margin-left: var(--calender-toolbar-gap, 8px);\n min-width: var(--calender-toolbar-date-min-width, 200px);\n}\n\n.calendar-view-buttons {\n display: flex;\n gap: 0;\n border: 1px solid var(--calender-border-color, #dadce0);\n border-radius: var(--calender-border-radius, 4px);\n overflow: hidden;\n}\n\n.calendar-view-button {\n padding: var(--calender-button-padding, 8px 16px);\n border: none;\n background: var(--calender-bg-color, #fff);\n color: var(--calender-text-secondary-color, #5f6368);\n font-size: var(--calender-font-size, 14px);\n font-weight: var(--calender-button-font-weight, 500);\n cursor: pointer;\n transition:\n background-color var(--calender-transition-duration, 0.2s),\n color var(--calender-transition-duration, 0.2s);\n border-right: 1px solid var(--calender-border-color, #dadce0);\n}\n\n.calendar-view-button:last-child {\n border-right: none;\n}\n\n.calendar-view-button:hover {\n background-color: var(--calender-hover-bg-color-light, #f8f9fa);\n}\n\n.calendar-view-button.active {\n background-color: var(--calender-primary-color, #1a73e8);\n color: var(--calender-primary-text-color, #fff);\n}\n\n.calendar-view-button.active:hover {\n background-color: var(--calender-primary-hover-color, #1765cc);\n}\n';
|
|
97
|
-
class b {
|
|
98
|
-
constructor(t) {
|
|
99
|
-
this.dataModel = t;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* 获取 Data Model(只读)
|
|
103
|
-
*/
|
|
104
|
-
getDataModel() {
|
|
105
|
-
return this.dataModel;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* 验证事件
|
|
109
|
-
*
|
|
110
|
-
* **验证流程**:
|
|
111
|
-
* 1. DSL 文本定义验证规则(在 `validate:` 部分)
|
|
112
|
-
* 2. DSL 解析器将验证规则解析为 AST(`this.ast.validate: ValidationRule[]`)
|
|
113
|
-
* 3. 运行时**使用** AST 中的验证规则,**验证** Event 数据模型的数据
|
|
114
|
-
* - 使用:`this.ast.validate`(AST 中的验证规则)
|
|
115
|
-
* - 验证:`event: Event`(Event 数据模型的数据,来自 @calenderjs/event-model)
|
|
116
|
-
*
|
|
117
|
-
* **验证内容**(基于 DSL 中定义的验证规则,业务规则,需要运行时数据):
|
|
118
|
-
* 1. **Between 规则**:字段值在范围内
|
|
119
|
-
* - DSL:`attendees.count between 1 and 50`
|
|
120
|
-
* - 验证:`event.data.attendees.length` 是否在 1-50 之间
|
|
121
|
-
*
|
|
122
|
-
* 2. **Comparison 规则**:比较表达式
|
|
123
|
-
* - DSL:`startTime.hour >= 9`、`duration < 2 hours`
|
|
124
|
-
* - 验证:字段值与常量或表达式的比较
|
|
125
|
-
*
|
|
126
|
-
* 3. **NoConflict 规则**:检查时间冲突
|
|
127
|
-
* - DSL:`no conflict with other events`
|
|
128
|
-
* - 验证:事件时间是否与其他事件冲突(需要 context.events)
|
|
129
|
-
*
|
|
130
|
-
* 4. **Conflict 规则**:检查是否有冲突(与 NoConflict 相反)
|
|
131
|
-
* - DSL:`conflict with other events`
|
|
132
|
-
* - 验证:事件时间是否与其他事件冲突
|
|
133
|
-
*
|
|
134
|
-
* 5. **When 规则**:条件满足时执行子规则
|
|
135
|
-
* - DSL:`when priority is high: attendees.count >= 5`
|
|
136
|
-
* - 验证:条件满足时执行子规则验证
|
|
137
|
-
*
|
|
138
|
-
* **重要**:
|
|
139
|
-
* - 运行时**使用** AST 中的验证规则(`this.ast.validate`)
|
|
140
|
-
* - 运行时**验证** Event 数据模型的数据(`event: Event`,来自 @calenderjs/event-model)
|
|
141
|
-
* - 这些验证需要运行时数据(event.data.attendees.length)
|
|
142
|
-
* - 这些验证需要上下文信息(context.events, context.now, context.user)
|
|
143
|
-
* - 这些验证无法在编译时验证(数据是动态的)
|
|
144
|
-
* - 这些验证无法通过 JSON Schema 验证(JSON Schema 只能验证结构)
|
|
145
|
-
*
|
|
146
|
-
* @param event 要验证的 Event 对象(来自 @calenderjs/event-model,Event 数据模型)
|
|
147
|
-
* @param context 验证上下文(包含 events, now, user 等信息)
|
|
148
|
-
* @returns 验证结果
|
|
149
|
-
*/
|
|
150
|
-
validate(t, i2) {
|
|
151
|
-
const s = [], e = this.validateBaseTimeRules(t, i2);
|
|
152
|
-
e.length > 0 && s.push(...e);
|
|
153
|
-
const n = this.dataModel.validationRules || [];
|
|
154
|
-
for (const r of n) {
|
|
155
|
-
const a = this.evaluateValidationRule(r, t, i2);
|
|
156
|
-
a.valid || s.push(...a.errors || []);
|
|
157
|
-
}
|
|
158
|
-
return {
|
|
159
|
-
valid: s.length === 0,
|
|
160
|
-
errors: s.length > 0 ? s : void 0
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* 验证基础时间规则(自动应用)
|
|
165
|
-
*
|
|
166
|
-
* 这些规则基于 constraints 中的约束值自动验证
|
|
167
|
-
*/
|
|
168
|
-
validateBaseTimeRules(t, i2) {
|
|
169
|
-
const s = [], e = this.dataModel.constraints || [], n = (u) => e.find((d2) => d2.name === u)?.value, r = t.startTime instanceof Date ? t.startTime : new Date(t.startTime), a = t.endTime instanceof Date ? t.endTime : new Date(t.endTime);
|
|
170
|
-
r >= a && s.push("开始时间必须早于结束时间");
|
|
171
|
-
const o = n("minDuration");
|
|
172
|
-
if (o) {
|
|
173
|
-
const u = this.durationToMinutes(o), l2 = this.getFieldValue(
|
|
174
|
-
{ type: "FieldAccess", path: ["duration"] },
|
|
175
|
-
t,
|
|
176
|
-
i2
|
|
177
|
-
);
|
|
178
|
-
l2 !== void 0 && l2 < u && s.push(`持续时间必须至少 ${this.formatDuration(u)}`);
|
|
179
|
-
}
|
|
180
|
-
const c = n("maxDuration");
|
|
181
|
-
if (c) {
|
|
182
|
-
const u = this.durationToMinutes(c), l2 = this.getFieldValue(
|
|
183
|
-
{ type: "FieldAccess", path: ["duration"] },
|
|
184
|
-
t,
|
|
185
|
-
i2
|
|
186
|
-
);
|
|
187
|
-
l2 !== void 0 && l2 > u && s.push(`持续时间不能超过 ${this.formatDuration(u)}`);
|
|
188
|
-
}
|
|
189
|
-
const f = n("timePrecision");
|
|
190
|
-
if (f) {
|
|
191
|
-
const u = this.durationToMinutes(f);
|
|
192
|
-
r.getUTCMinutes() % u !== 0 && s.push(`开始时间的分钟数必须是 ${u} 的倍数`), a.getUTCMinutes() % u !== 0 && s.push(`结束时间的分钟数必须是 ${u} 的倍数`);
|
|
193
|
-
}
|
|
194
|
-
const T = n("minAdvanceTime");
|
|
195
|
-
if (T && i2.now) {
|
|
196
|
-
const u = this.durationToMinutes(T), l2 = i2.now instanceof Date ? i2.now : new Date(i2.now), d2 = new Date(l2.getTime() + u * 60 * 1e3);
|
|
197
|
-
r < d2 && s.push(
|
|
198
|
-
`开始时间必须至少提前 ${this.formatDuration(u)} 创建`
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
const D2 = n("maxAdvanceTime");
|
|
202
|
-
if (D2 && i2.now) {
|
|
203
|
-
const u = this.durationToMinutes(D2), l2 = i2.now instanceof Date ? i2.now : new Date(i2.now), d2 = new Date(l2.getTime() + u * 60 * 1e3);
|
|
204
|
-
r > d2 && s.push(
|
|
205
|
-
`开始时间不能超过 ${this.formatDuration(u)} 后创建`
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
const m2 = n("timeZone");
|
|
209
|
-
m2 && t.timeZone && t.timeZone !== m2 && s.push(`事件时区必须是 ${m2}`);
|
|
210
|
-
const h2 = n("allowedTimeZones");
|
|
211
|
-
if (h2 && Array.isArray(h2) && t.timeZone && (h2.includes(t.timeZone) || s.push(`事件时区必须是以下之一: ${h2.join(", ")}`)), t.allDay === true) {
|
|
212
|
-
const u = r.getUTCHours(), l2 = r.getUTCMinutes(), d2 = r.getUTCSeconds(), w2 = r.getUTCMilliseconds();
|
|
213
|
-
(u !== 0 || l2 !== 0 || d2 !== 0 || w2 !== 0) && s.push("全天事件的开始时间应该是当天的 00:00:00");
|
|
214
|
-
const p2 = a.getUTCHours(), g = a.getUTCMinutes(), y2 = a.getUTCSeconds(), V = a.getUTCMilliseconds();
|
|
215
|
-
if (!(p2 === 23 && g === 59 && y2 === 59 || p2 === 0 && g === 0 && y2 === 0 && V === 0)) {
|
|
216
|
-
const C = r.toISOString().split("T")[0];
|
|
217
|
-
a.toISOString().split("T")[0] !== C && p2 === 0 && g === 0 && y2 === 0 && V === 0 || s.push(
|
|
218
|
-
"全天事件的结束时间应该是当天的 23:59:59 或次日的 00:00:00"
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
} else if (n("allowCrossDay") === false) {
|
|
222
|
-
const l2 = r.toISOString().split("T")[0], d2 = a.toISOString().split("T")[0];
|
|
223
|
-
l2 !== d2 && s.push("不允许跨天事件");
|
|
224
|
-
}
|
|
225
|
-
const M = n("maxCrossDayDuration");
|
|
226
|
-
if (M) {
|
|
227
|
-
const u = this.durationToDays(M), l2 = new Date(r.toISOString().split("T")[0]), d2 = new Date(a.toISOString().split("T")[0]);
|
|
228
|
-
Math.ceil(
|
|
229
|
-
(d2.getTime() - l2.getTime()) / (1e3 * 60 * 60 * 24)
|
|
230
|
-
) > u && s.push(`跨天时长不能超过 ${u} 天`);
|
|
231
|
-
}
|
|
232
|
-
const v = this.validateRecurringRules(t, i2);
|
|
233
|
-
return v.length > 0 && s.push(...v), s;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* 验证重复事件规则
|
|
237
|
-
*/
|
|
238
|
-
validateRecurringRules(t, i2) {
|
|
239
|
-
const s = [];
|
|
240
|
-
if (!t.recurring)
|
|
241
|
-
return s;
|
|
242
|
-
const e = t.recurring, n = t.startTime instanceof Date ? t.startTime : new Date(t.startTime);
|
|
243
|
-
if (!e.endDate && (!e.count || e.count <= 0) && s.push("重复事件必须设置 endDate 或 count > 0"), e.endDate && (e.endDate instanceof Date ? e.endDate : new Date(e.endDate)) <= n && s.push("重复事件的结束日期必须晚于开始时间"), e.frequency === "weekly")
|
|
244
|
-
if (!e.daysOfWeek || !Array.isArray(e.daysOfWeek) || e.daysOfWeek.length === 0)
|
|
245
|
-
s.push("weekly 频率的重复事件必须设置 daysOfWeek");
|
|
246
|
-
else {
|
|
247
|
-
const r = e.daysOfWeek.filter(
|
|
248
|
-
(a) => a < 0 || a > 6
|
|
249
|
-
);
|
|
250
|
-
r.length > 0 && s.push(
|
|
251
|
-
`daysOfWeek 值必须在 0-6 之间(0=周日,6=周六),无效值: ${r.join(
|
|
252
|
-
", "
|
|
253
|
-
)}`
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
if (e.frequency === "monthly" && (e.dayOfMonth === void 0 || e.dayOfMonth === null ? s.push("monthly 频率的重复事件必须设置 dayOfMonth") : (e.dayOfMonth < 1 || e.dayOfMonth > 31) && s.push("dayOfMonth 必须在 1-31 之间")), e.frequency === "yearly" && e.dayOfMonth !== void 0 && e.dayOfMonth !== null && (e.dayOfMonth < 1 || e.dayOfMonth > 31) && s.push("dayOfMonth 必须在 1-31 之间"), (e.interval === void 0 || e.interval <= 0) && s.push("重复事件的 interval 必须大于 0"), e.count !== void 0 && e.count <= 0 && s.push("重复事件的 count 必须大于 0"), e.excludeDates && Array.isArray(e.excludeDates)) {
|
|
257
|
-
const r = e.excludeDates.filter((a) => {
|
|
258
|
-
const o = a instanceof Date ? a : new Date(a);
|
|
259
|
-
return isNaN(o.getTime());
|
|
260
|
-
});
|
|
261
|
-
r.length > 0 && s.push(
|
|
262
|
-
`excludeDates 包含无效的日期格式: ${r.length} 个`
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
return s;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* 将 Duration 转换为分钟数
|
|
269
|
-
*/
|
|
270
|
-
durationToMinutes(t) {
|
|
271
|
-
if (typeof t == "number")
|
|
272
|
-
return t;
|
|
273
|
-
if (t?.type === "Duration") {
|
|
274
|
-
const i2 = t.value;
|
|
275
|
-
switch (t.unit) {
|
|
276
|
-
case "minutes":
|
|
277
|
-
return i2;
|
|
278
|
-
case "hours":
|
|
279
|
-
return i2 * 60;
|
|
280
|
-
case "days":
|
|
281
|
-
return i2 * 24 * 60;
|
|
282
|
-
case "weeks":
|
|
283
|
-
return i2 * 7 * 24 * 60;
|
|
284
|
-
default:
|
|
285
|
-
return i2;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return 0;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* 将 Duration 转换为天数
|
|
292
|
-
*/
|
|
293
|
-
durationToDays(t) {
|
|
294
|
-
if (typeof t == "number")
|
|
295
|
-
return t;
|
|
296
|
-
if (t?.type === "Duration") {
|
|
297
|
-
const i2 = t.value;
|
|
298
|
-
switch (t.unit) {
|
|
299
|
-
case "days":
|
|
300
|
-
return i2;
|
|
301
|
-
case "weeks":
|
|
302
|
-
return i2 * 7;
|
|
303
|
-
case "hours":
|
|
304
|
-
return i2 / 24;
|
|
305
|
-
case "minutes":
|
|
306
|
-
return i2 / 1440;
|
|
307
|
-
default:
|
|
308
|
-
return i2;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return 0;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* 格式化持续时间为可读字符串
|
|
315
|
-
*/
|
|
316
|
-
formatDuration(t) {
|
|
317
|
-
if (t < 60)
|
|
318
|
-
return `${t} 分钟`;
|
|
319
|
-
if (t < 1440) {
|
|
320
|
-
const i2 = Math.floor(t / 60), s = t % 60;
|
|
321
|
-
return s > 0 ? `${i2} 小时 ${s} 分钟` : `${i2} 小时`;
|
|
322
|
-
} else {
|
|
323
|
-
const i2 = Math.floor(t / 1440), s = Math.floor(t % 1440 / 60);
|
|
324
|
-
return s > 0 ? `${i2} 天 ${s} 小时` : `${i2} 天`;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* 渲染事件
|
|
329
|
-
*/
|
|
330
|
-
render(t, i2) {
|
|
331
|
-
const s = {
|
|
332
|
-
title: t.title,
|
|
333
|
-
color: "#4285f4",
|
|
334
|
-
description: ""
|
|
335
|
-
}, e = this.dataModel.displayRules || [];
|
|
336
|
-
for (const n of e) {
|
|
337
|
-
const r = this.evaluateDisplayValue(n.value, t, i2);
|
|
338
|
-
switch (n.name) {
|
|
339
|
-
case "color":
|
|
340
|
-
s.color = typeof r == "string" ? r : String(r);
|
|
341
|
-
break;
|
|
342
|
-
case "icon":
|
|
343
|
-
s.icon = r;
|
|
344
|
-
break;
|
|
345
|
-
case "title":
|
|
346
|
-
s.title = typeof r == "string" ? r : String(r);
|
|
347
|
-
break;
|
|
348
|
-
case "description":
|
|
349
|
-
s.description = typeof r == "string" ? r : String(r);
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
return t.allDay !== void 0 && (s.allDay = t.allDay), s;
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* 检查是否可以执行某个操作
|
|
357
|
-
*/
|
|
358
|
-
canPerform(t, i2, s) {
|
|
359
|
-
const n = (this.dataModel.behaviorRules || []).find(
|
|
360
|
-
(r) => r.name === t
|
|
361
|
-
);
|
|
362
|
-
return n ? typeof n.value == "boolean" ? n.value : this.evaluateExpression(n.value, i2, { user: s }) : false;
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* 评估验证规则
|
|
366
|
-
*/
|
|
367
|
-
evaluateValidationRule(t, i2, s) {
|
|
368
|
-
if (!t)
|
|
369
|
-
return { valid: true };
|
|
370
|
-
if (t.type === "When") {
|
|
371
|
-
if (this.evaluateExpression(
|
|
372
|
-
t.condition,
|
|
373
|
-
i2,
|
|
374
|
-
s
|
|
375
|
-
)) {
|
|
376
|
-
const n = [];
|
|
377
|
-
for (const r of t.rules || []) {
|
|
378
|
-
const a = this.evaluateValidationRule(r, i2, s);
|
|
379
|
-
a.valid || n.push(...a.errors || []);
|
|
380
|
-
}
|
|
381
|
-
return {
|
|
382
|
-
valid: n.length === 0,
|
|
383
|
-
errors: n.length > 0 ? n : void 0
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
return { valid: true, errors: [] };
|
|
387
|
-
}
|
|
388
|
-
if (t.type === "Between") {
|
|
389
|
-
const e = this.getFieldValue(t.field, i2, s), n = this.getLiteralValue(t.min), r = this.getLiteralValue(t.max);
|
|
390
|
-
if (e == null)
|
|
391
|
-
return {
|
|
392
|
-
valid: false,
|
|
393
|
-
errors: [`字段 ${t.field.path.join(".")} 未定义`]
|
|
394
|
-
};
|
|
395
|
-
const a = typeof e == "number" ? e : Number(e), o = typeof n == "number" ? n : Number(n), c = typeof r == "number" ? r : Number(r);
|
|
396
|
-
if (isNaN(a) || isNaN(o) || isNaN(c))
|
|
397
|
-
return {
|
|
398
|
-
valid: false,
|
|
399
|
-
errors: [`字段 ${t.field.path.join(".")} 无法进行数值比较`]
|
|
400
|
-
};
|
|
401
|
-
const f = a >= o && a <= c;
|
|
402
|
-
return {
|
|
403
|
-
valid: f,
|
|
404
|
-
errors: f ? void 0 : [`字段 ${t.field.path.join(".")} 必须在 ${n} 和 ${r} 之间`]
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
if (t.type === "In") {
|
|
408
|
-
const e = this.getFieldValue(t.field, i2, s);
|
|
409
|
-
if (e == null)
|
|
410
|
-
return {
|
|
411
|
-
valid: false,
|
|
412
|
-
errors: [`字段 ${t.field.path.join(".")} 未定义`]
|
|
413
|
-
};
|
|
414
|
-
const r = (t.values || []).some((a) => {
|
|
415
|
-
const o = this.getLiteralValue(a);
|
|
416
|
-
return this.compareValues(e, o, "equals");
|
|
417
|
-
});
|
|
418
|
-
return {
|
|
419
|
-
valid: r,
|
|
420
|
-
errors: r ? void 0 : [`字段 ${t.field.path.join(".")} 不在允许的值列表中`]
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
if (t.type === "ModComparison") {
|
|
424
|
-
const e = this.getFieldValue(t.left, i2, s), n = this.getLiteralValue(t.modValue), r = this.getLiteralValue(t.right);
|
|
425
|
-
if (e == null)
|
|
426
|
-
return {
|
|
427
|
-
valid: false,
|
|
428
|
-
errors: [`字段 ${t.left.path.join(".")} 未定义`]
|
|
429
|
-
};
|
|
430
|
-
const a = Number(e), o = Number(n);
|
|
431
|
-
if (isNaN(a) || isNaN(o) || o === 0)
|
|
432
|
-
return {
|
|
433
|
-
valid: false,
|
|
434
|
-
errors: [`字段 ${t.left.path.join(".")} 无法进行模运算`]
|
|
435
|
-
};
|
|
436
|
-
const c = a % o, f = this.compareValues(c, r, t.operator);
|
|
437
|
-
return {
|
|
438
|
-
valid: f,
|
|
439
|
-
errors: f ? void 0 : [
|
|
440
|
-
`验证失败: ${t.left.path.join(".")} mod ${n} ${t.operator} ${r} 不满足`
|
|
441
|
-
]
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
if (t.type === "Comparison") {
|
|
445
|
-
const e = this.getExpressionValue(t.left, i2, s), n = this.getLiteralValue(t.right), r = this.compareValues(e, n, t.operator);
|
|
446
|
-
return {
|
|
447
|
-
valid: r,
|
|
448
|
-
errors: r ? void 0 : [`验证失败: ${t.operator} 比较不满足`]
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
if (t.type === "NoConflict") {
|
|
452
|
-
const e = this.checkTimeConflict(i2, s.events || []);
|
|
453
|
-
return {
|
|
454
|
-
valid: !e,
|
|
455
|
-
errors: e ? ["事件时间与其他事件冲突"] : void 0
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
if (t.type === "Conflict") {
|
|
459
|
-
const e = this.checkTimeConflict(i2, s.events || []);
|
|
460
|
-
return {
|
|
461
|
-
valid: e,
|
|
462
|
-
errors: e ? void 0 : ["事件时间未与其他事件冲突"]
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
if (t.type === "BinaryExpression") {
|
|
466
|
-
const e = this.evaluateExpression(t.left, i2, s), n = this.evaluateExpression(t.right, i2, s);
|
|
467
|
-
if (t.operator === "and")
|
|
468
|
-
return { valid: e && n };
|
|
469
|
-
if (t.operator === "or")
|
|
470
|
-
return { valid: e || n };
|
|
471
|
-
}
|
|
472
|
-
return t.type === "UnaryExpression" && t.operator === "not" ? { valid: !this.evaluateExpression(t.argument, i2, s) } : { valid: true };
|
|
473
|
-
}
|
|
474
|
-
/**
|
|
475
|
-
* 评估显示值
|
|
476
|
-
*/
|
|
477
|
-
evaluateDisplayValue(t, i2, s) {
|
|
478
|
-
return typeof t == "string" ? t : t?.type === "Conditional" ? this.evaluateExpression(
|
|
479
|
-
t.condition,
|
|
480
|
-
i2,
|
|
481
|
-
s
|
|
482
|
-
) ? this.evaluateDisplayValue(t.consequent, i2, s) : t.alternate ? this.evaluateDisplayValue(t.alternate, i2, s) : "" : t?.type === "Template" ? this.evaluateTemplate(t, i2, s) : t;
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* 评估表达式
|
|
486
|
-
*/
|
|
487
|
-
evaluateExpression(t, i2, s) {
|
|
488
|
-
if (!t)
|
|
489
|
-
return false;
|
|
490
|
-
if (t.type === "FieldAccess")
|
|
491
|
-
return !!this.getFieldValue(t, i2, s);
|
|
492
|
-
if (t.type === "Comparison") {
|
|
493
|
-
const e = this.getExpressionValue(t.left, i2, s), n = this.getLiteralValue(t.right);
|
|
494
|
-
return this.compareValues(e, n, t.operator);
|
|
495
|
-
}
|
|
496
|
-
if (t.type === "BinaryExpression") {
|
|
497
|
-
const e = this.evaluateExpression(t.left, i2, s), n = this.evaluateExpression(t.right, i2, s);
|
|
498
|
-
if (t.operator === "and")
|
|
499
|
-
return e && n;
|
|
500
|
-
if (t.operator === "or")
|
|
501
|
-
return e || n;
|
|
502
|
-
}
|
|
503
|
-
return t.type === "UnaryExpression" && t.operator === "not" ? !this.evaluateExpression(t.argument, i2, s) : false;
|
|
504
|
-
}
|
|
505
|
-
/**
|
|
506
|
-
* 评估模板
|
|
507
|
-
*/
|
|
508
|
-
evaluateTemplate(t, i2, s) {
|
|
509
|
-
return !t || t.type !== "Template" || !Array.isArray(t.parts) ? "" : t.parts.map((e) => {
|
|
510
|
-
if (typeof e == "string")
|
|
511
|
-
return e;
|
|
512
|
-
if (e && e.type === "FieldAccess") {
|
|
513
|
-
const n = this.getFieldValue(e, i2, s);
|
|
514
|
-
return n != null ? String(n) : "";
|
|
515
|
-
}
|
|
516
|
-
return "";
|
|
517
|
-
}).join("");
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* 获取字段值
|
|
521
|
-
*/
|
|
522
|
-
getFieldValue(t, i2, s) {
|
|
523
|
-
if (!t || t.type !== "FieldAccess" || !Array.isArray(t.path))
|
|
524
|
-
return;
|
|
525
|
-
const e = t.path;
|
|
526
|
-
if (e.length !== 0) {
|
|
527
|
-
if (e[0] === "user" && s?.user) {
|
|
528
|
-
let n = s.user;
|
|
529
|
-
for (let r = 1; r < e.length; r++) {
|
|
530
|
-
if (n == null)
|
|
531
|
-
return;
|
|
532
|
-
n = n[e[r]];
|
|
533
|
-
}
|
|
534
|
-
return n;
|
|
535
|
-
}
|
|
536
|
-
if (e.length >= 1) {
|
|
537
|
-
const n = e[0];
|
|
538
|
-
if (n === "startTime" || n === "endTime") {
|
|
539
|
-
const r = n === "startTime" ? i2.startTime : i2.endTime;
|
|
540
|
-
if (e.length === 1)
|
|
541
|
-
return r;
|
|
542
|
-
if (e.length === 2) {
|
|
543
|
-
const a = e[1], o = r instanceof Date ? r : new Date(r);
|
|
544
|
-
switch (a) {
|
|
545
|
-
case "hour":
|
|
546
|
-
return o.getUTCHours();
|
|
547
|
-
case "minute":
|
|
548
|
-
return o.getUTCMinutes();
|
|
549
|
-
case "second":
|
|
550
|
-
return o.getUTCSeconds();
|
|
551
|
-
case "day":
|
|
552
|
-
return o.getUTCDate();
|
|
553
|
-
case "month":
|
|
554
|
-
return o.getUTCMonth() + 1;
|
|
555
|
-
case "year":
|
|
556
|
-
return o.getUTCFullYear();
|
|
557
|
-
case "date":
|
|
558
|
-
return o.toISOString().split("T")[0];
|
|
559
|
-
case "dayOfWeek":
|
|
560
|
-
return o.getUTCDay();
|
|
561
|
-
case "timeZone":
|
|
562
|
-
return i2.timeZone || i2.recurring?.timeZone || void 0;
|
|
563
|
-
default:
|
|
564
|
-
return;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
return;
|
|
568
|
-
}
|
|
569
|
-
if (e.length === 1) {
|
|
570
|
-
if (n === "title")
|
|
571
|
-
return i2.title;
|
|
572
|
-
if (n === "type")
|
|
573
|
-
return i2.type;
|
|
574
|
-
if (n === "id")
|
|
575
|
-
return i2.id;
|
|
576
|
-
if (n === "duration") {
|
|
577
|
-
if (i2.data?.duration !== void 0)
|
|
578
|
-
return i2.data.duration;
|
|
579
|
-
const r = i2.startTime instanceof Date ? i2.startTime : new Date(i2.startTime), a = i2.endTime instanceof Date ? i2.endTime : new Date(i2.endTime);
|
|
580
|
-
return Math.round((a.getTime() - r.getTime()) / (1e3 * 60));
|
|
581
|
-
}
|
|
582
|
-
if (n === "now")
|
|
583
|
-
return s?.now || /* @__PURE__ */ new Date();
|
|
584
|
-
if (n === "created")
|
|
585
|
-
return i2.metadata?.createdAt || void 0;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
if (e[0] === "data") {
|
|
589
|
-
let n = i2.data;
|
|
590
|
-
for (let r = 1; r < e.length; r++) {
|
|
591
|
-
if (n == null)
|
|
592
|
-
return;
|
|
593
|
-
if (Array.isArray(n) && e[r] === "count")
|
|
594
|
-
return n.length;
|
|
595
|
-
n = n[e[r]];
|
|
596
|
-
}
|
|
597
|
-
return n;
|
|
598
|
-
}
|
|
599
|
-
if (e.length > 1) {
|
|
600
|
-
let n = i2.data;
|
|
601
|
-
for (let r = 0; r < e.length; r++) {
|
|
602
|
-
if (n == null)
|
|
603
|
-
return;
|
|
604
|
-
if (Array.isArray(n) && e[r] === "count")
|
|
605
|
-
return n.length;
|
|
606
|
-
n = n[e[r]];
|
|
607
|
-
}
|
|
608
|
-
return n;
|
|
609
|
-
}
|
|
610
|
-
if (e.length === 1 && i2.data)
|
|
611
|
-
return i2.data[e[0]];
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* 获取表达式值
|
|
616
|
-
*/
|
|
617
|
-
getExpressionValue(t, i2, s) {
|
|
618
|
-
return t?.type === "FieldAccess" ? this.getFieldValue(t, i2, s) : t;
|
|
619
|
-
}
|
|
620
|
-
/**
|
|
621
|
-
* 获取字面量值
|
|
622
|
-
*/
|
|
623
|
-
getLiteralValue(t) {
|
|
624
|
-
if (t == null)
|
|
625
|
-
return t;
|
|
626
|
-
if (t?.type === "Duration") {
|
|
627
|
-
const i2 = t.value || 0, s = t.unit || "minutes";
|
|
628
|
-
return i2 * ({
|
|
629
|
-
minutes: 1,
|
|
630
|
-
hours: 60,
|
|
631
|
-
days: 1440,
|
|
632
|
-
weeks: 10080
|
|
633
|
-
}[s] || 1);
|
|
634
|
-
}
|
|
635
|
-
return t;
|
|
636
|
-
}
|
|
637
|
-
/**
|
|
638
|
-
* 比较两个值
|
|
639
|
-
* 支持日期字符串(YYYY-MM-DD)和时间字符串(HH:mm 或 HH:mm:ss)比较
|
|
640
|
-
*/
|
|
641
|
-
compareValues(t, i2, s) {
|
|
642
|
-
const e = this.parseDateString(t), n = this.parseDateString(i2);
|
|
643
|
-
if (e !== null && n !== null)
|
|
644
|
-
return this.compareDates(e, n, s);
|
|
645
|
-
const r = this.parseTimeString(t), a = this.parseTimeString(i2);
|
|
646
|
-
if (r !== null && a !== null)
|
|
647
|
-
return this.compareTimes(r, a, s);
|
|
648
|
-
const o = t instanceof Date ? t.getTime() : t, c = i2 instanceof Date ? i2.getTime() : i2;
|
|
649
|
-
switch (s) {
|
|
650
|
-
case "is":
|
|
651
|
-
case "equals":
|
|
652
|
-
return o === c;
|
|
653
|
-
case "is not":
|
|
654
|
-
case "not equals":
|
|
655
|
-
return o !== c;
|
|
656
|
-
case ">":
|
|
657
|
-
return Number(o) > Number(c);
|
|
658
|
-
case ">=":
|
|
659
|
-
return Number(o) >= Number(c);
|
|
660
|
-
case "<":
|
|
661
|
-
return Number(o) < Number(c);
|
|
662
|
-
case "<=":
|
|
663
|
-
return Number(o) <= Number(c);
|
|
664
|
-
default:
|
|
665
|
-
return false;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
/**
|
|
669
|
-
* 解析日期字符串(YYYY-MM-DD)
|
|
670
|
-
* 返回 Date 对象或 null
|
|
671
|
-
*/
|
|
672
|
-
parseDateString(t) {
|
|
673
|
-
if (typeof t != "string")
|
|
674
|
-
return null;
|
|
675
|
-
const i2 = /^(\d{4})-(\d{2})-(\d{2})$/, s = t.match(i2);
|
|
676
|
-
if (!s)
|
|
677
|
-
return null;
|
|
678
|
-
const e = parseInt(s[1], 10), n = parseInt(s[2], 10) - 1, r = parseInt(s[3], 10), a = new Date(Date.UTC(e, n, r));
|
|
679
|
-
return a.getUTCFullYear() === e && a.getUTCMonth() === n && a.getUTCDate() === r ? a : null;
|
|
680
|
-
}
|
|
681
|
-
/**
|
|
682
|
-
* 解析时间字符串(HH:mm 或 HH:mm:ss)
|
|
683
|
-
* 返回分钟数(从午夜开始)或 null
|
|
684
|
-
*/
|
|
685
|
-
parseTimeString(t) {
|
|
686
|
-
if (typeof t != "string")
|
|
687
|
-
return null;
|
|
688
|
-
const i2 = /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/, s = t.match(i2);
|
|
689
|
-
if (!s)
|
|
690
|
-
return null;
|
|
691
|
-
const e = parseInt(s[1], 10), n = parseInt(s[2], 10);
|
|
692
|
-
return e < 0 || e > 23 || n < 0 || n > 59 ? null : e * 60 + n;
|
|
693
|
-
}
|
|
694
|
-
/**
|
|
695
|
-
* 比较日期(Date 对象)
|
|
696
|
-
*/
|
|
697
|
-
compareDates(t, i2, s) {
|
|
698
|
-
const e = t.getTime(), n = i2.getTime();
|
|
699
|
-
switch (s) {
|
|
700
|
-
case "is":
|
|
701
|
-
case "equals":
|
|
702
|
-
return e === n;
|
|
703
|
-
case "is not":
|
|
704
|
-
case "not equals":
|
|
705
|
-
return e !== n;
|
|
706
|
-
case ">":
|
|
707
|
-
return e > n;
|
|
708
|
-
case ">=":
|
|
709
|
-
return e >= n;
|
|
710
|
-
case "<":
|
|
711
|
-
return e < n;
|
|
712
|
-
case "<=":
|
|
713
|
-
return e <= n;
|
|
714
|
-
default:
|
|
715
|
-
return false;
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
/**
|
|
719
|
-
* 比较时间(分钟数)
|
|
720
|
-
*/
|
|
721
|
-
compareTimes(t, i2, s) {
|
|
722
|
-
switch (s) {
|
|
723
|
-
case "is":
|
|
724
|
-
case "equals":
|
|
725
|
-
return t === i2;
|
|
726
|
-
case "is not":
|
|
727
|
-
case "not equals":
|
|
728
|
-
return t !== i2;
|
|
729
|
-
case ">":
|
|
730
|
-
return t > i2;
|
|
731
|
-
case ">=":
|
|
732
|
-
return t >= i2;
|
|
733
|
-
case "<":
|
|
734
|
-
return t < i2;
|
|
735
|
-
case "<=":
|
|
736
|
-
return t <= i2;
|
|
737
|
-
default:
|
|
738
|
-
return false;
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
/**
|
|
742
|
-
* 检查时间冲突
|
|
743
|
-
*/
|
|
744
|
-
checkTimeConflict(t, i2) {
|
|
745
|
-
for (const s of i2) {
|
|
746
|
-
if (s.id === t.id)
|
|
747
|
-
continue;
|
|
748
|
-
const e = t.startTime.getTime(), n = t.endTime.getTime(), r = s.startTime.getTime(), a = s.endTime.getTime();
|
|
749
|
-
if (e < a && n > r)
|
|
750
|
-
return true;
|
|
751
|
-
}
|
|
752
|
-
return false;
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
7
|
function createRuntimeMap(dataModel) {
|
|
756
8
|
const map = /* @__PURE__ */ new Map();
|
|
757
9
|
for (const typeModel of dataModel.types) {
|
|
758
|
-
map.set(typeModel.id, new
|
|
10
|
+
map.set(typeModel.id, new EventRuntime(typeModel));
|
|
759
11
|
}
|
|
760
12
|
return map;
|
|
761
13
|
}
|
|
@@ -807,10 +59,70 @@ function canPerformEventAction(action, event, runtimeByType, user) {
|
|
|
807
59
|
}
|
|
808
60
|
return runtime.canPerform(action, event, user);
|
|
809
61
|
}
|
|
62
|
+
const INVALID_STATE_DATE = "Invalid date for WSX @state";
|
|
63
|
+
const UNSELECTED_DATE_ISO = (/* @__PURE__ */ new Date(0)).toISOString();
|
|
64
|
+
function toStateIso(value) {
|
|
65
|
+
if (typeof value === "string") {
|
|
66
|
+
const parsed = new Date(value);
|
|
67
|
+
if (Number.isNaN(parsed.getTime())) {
|
|
68
|
+
throw new Error(`${INVALID_STATE_DATE}: ${value}`);
|
|
69
|
+
}
|
|
70
|
+
return parsed.toISOString();
|
|
71
|
+
}
|
|
72
|
+
const time = value.getTime();
|
|
73
|
+
if (Number.isNaN(time)) {
|
|
74
|
+
throw new Error(INVALID_STATE_DATE);
|
|
75
|
+
}
|
|
76
|
+
return new Date(time).toISOString();
|
|
77
|
+
}
|
|
78
|
+
function fromStateIso(iso) {
|
|
79
|
+
return new Date(iso);
|
|
80
|
+
}
|
|
81
|
+
function toStateIsoOrUnselected(value) {
|
|
82
|
+
if (value === null || value === void 0) {
|
|
83
|
+
return UNSELECTED_DATE_ISO;
|
|
84
|
+
}
|
|
85
|
+
if (typeof value === "string") {
|
|
86
|
+
const parsed = new Date(value);
|
|
87
|
+
if (Number.isNaN(parsed.getTime())) {
|
|
88
|
+
return UNSELECTED_DATE_ISO;
|
|
89
|
+
}
|
|
90
|
+
return parsed.toISOString();
|
|
91
|
+
}
|
|
92
|
+
return toStateIso(value);
|
|
93
|
+
}
|
|
94
|
+
function normalizeEventForState(event) {
|
|
95
|
+
return {
|
|
96
|
+
...event,
|
|
97
|
+
startTime: toStateIso(event.startTime),
|
|
98
|
+
endTime: toStateIso(event.endTime)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function normalizeEventsForState(events) {
|
|
102
|
+
return events.map((event) => normalizeEventForState(event));
|
|
103
|
+
}
|
|
104
|
+
function upgradeProperty(target, prop) {
|
|
105
|
+
if (!Object.prototype.hasOwnProperty.call(target, prop)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, prop);
|
|
109
|
+
if (!descriptor || descriptor.get || descriptor.set) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const record = target;
|
|
113
|
+
const value = record[prop];
|
|
114
|
+
delete record[prop];
|
|
115
|
+
record[prop] = value;
|
|
116
|
+
}
|
|
117
|
+
function upgradeProperties(target, props) {
|
|
118
|
+
for (const prop of props) {
|
|
119
|
+
upgradeProperty(target, prop);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
810
122
|
function groupEventsByDate(events) {
|
|
811
123
|
const grouped = /* @__PURE__ */ new Map();
|
|
812
124
|
for (const event of events) {
|
|
813
|
-
const dateKey =
|
|
125
|
+
const dateKey = formatDateKey(event.startTime);
|
|
814
126
|
if (!grouped.has(dateKey)) {
|
|
815
127
|
grouped.set(dateKey, []);
|
|
816
128
|
}
|
|
@@ -821,18 +133,18 @@ function groupEventsByDate(events) {
|
|
|
821
133
|
function getEventsForDate(events, date) {
|
|
822
134
|
return events.filter((event) => {
|
|
823
135
|
const eventDate = event.startTime instanceof Date ? event.startTime : new Date(event.startTime);
|
|
824
|
-
return
|
|
136
|
+
return isSameDay(eventDate, date);
|
|
825
137
|
});
|
|
826
138
|
}
|
|
827
139
|
function sortEventsByTime(events) {
|
|
828
|
-
return [...events].sort((a,
|
|
140
|
+
return [...events].sort((a, b) => {
|
|
829
141
|
const timeA = (a.startTime instanceof Date ? a.startTime : new Date(a.startTime)).getTime();
|
|
830
|
-
const timeB = (
|
|
142
|
+
const timeB = (b.startTime instanceof Date ? b.startTime : new Date(b.startTime)).getTime();
|
|
831
143
|
if (timeA !== timeB) {
|
|
832
144
|
return timeA - timeB;
|
|
833
145
|
}
|
|
834
146
|
const endTimeA = (a.endTime instanceof Date ? a.endTime : new Date(a.endTime)).getTime();
|
|
835
|
-
const endTimeB = (
|
|
147
|
+
const endTimeB = (b.endTime instanceof Date ? b.endTime : new Date(b.endTime)).getTime();
|
|
836
148
|
return endTimeA - endTimeB;
|
|
837
149
|
});
|
|
838
150
|
}
|
|
@@ -857,7 +169,7 @@ function _defineProperty$3(e, r, t) {
|
|
|
857
169
|
return (r = _toPropertyKey$3(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
|
|
858
170
|
}
|
|
859
171
|
function _applyDecs$3(e, t, r, n, o, a) {
|
|
860
|
-
function
|
|
172
|
+
function i(e2, t2, r2) {
|
|
861
173
|
return function(n2, o2) {
|
|
862
174
|
return r2 && r2(n2), e2[t2].call(n2, o2);
|
|
863
175
|
};
|
|
@@ -870,93 +182,93 @@ function _applyDecs$3(e, t, r, n, o, a) {
|
|
|
870
182
|
if ("function" != typeof e2 && (n2 || void 0 !== e2)) throw new TypeError(t2 + " must " + (r2 || "be") + " a function" + (n2 ? "" : " or undefined"));
|
|
871
183
|
return e2;
|
|
872
184
|
}
|
|
873
|
-
function applyDec(e2, t2, r2, n2, o2, a2, c2, u2,
|
|
874
|
-
function
|
|
875
|
-
if (!
|
|
185
|
+
function applyDec(e2, t2, r2, n2, o2, a2, c2, u2, l2, f2, p2, d, h) {
|
|
186
|
+
function m(e3) {
|
|
187
|
+
if (!h(e3)) throw new TypeError("Attempted to access private element on non-instance");
|
|
876
188
|
}
|
|
877
|
-
var
|
|
878
|
-
if (!
|
|
189
|
+
var y, v = t2[0], g = t2[3], b = !u2;
|
|
190
|
+
if (!b) {
|
|
879
191
|
r2 || Array.isArray(v) || (v = [v]);
|
|
880
|
-
var
|
|
881
|
-
f2 ? (
|
|
192
|
+
var w = {}, S = [], A = 3 === o2 ? "get" : 4 === o2 || d ? "set" : "value";
|
|
193
|
+
f2 ? (p2 || d ? w = { get: _setFunctionName$3(function() {
|
|
882
194
|
return g(this);
|
|
883
195
|
}, n2, "get"), set: function(e3) {
|
|
884
196
|
t2[4](this, e3);
|
|
885
|
-
} } :
|
|
197
|
+
} } : w[A] = g, p2 || _setFunctionName$3(w[A], n2, 2 === o2 ? "" : A)) : p2 || (w = Object.getOwnPropertyDescriptor(e2, n2));
|
|
886
198
|
}
|
|
887
199
|
for (var P = e2, j = v.length - 1; j >= 0; j -= r2 ? 2 : 1) {
|
|
888
|
-
var
|
|
200
|
+
var D = v[j], E = r2 ? v[j - 1] : void 0, I = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][o2], name: n2, metadata: a2, addInitializer: (function(e3, t3) {
|
|
889
201
|
if (e3.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
890
202
|
s(t3, "An initializer", "be", true), c2.push(t3);
|
|
891
203
|
}).bind(null, I) };
|
|
892
204
|
try {
|
|
893
|
-
if (
|
|
205
|
+
if (b) (y = s(D.call(E, P, O), "class decorators", "return")) && (P = y);
|
|
894
206
|
else {
|
|
895
207
|
var k, F;
|
|
896
|
-
O.static =
|
|
897
|
-
return
|
|
898
|
-
} : (o2 < 4 && (k =
|
|
208
|
+
O.static = l2, O.private = f2, f2 ? 2 === o2 ? k = function(e3) {
|
|
209
|
+
return m(e3), w.value;
|
|
210
|
+
} : (o2 < 4 && (k = i(w, "get", m)), 3 !== o2 && (F = i(w, "set", m))) : (k = function(e3) {
|
|
899
211
|
return e3[n2];
|
|
900
212
|
}, (o2 < 2 || 4 === o2) && (F = function(e3, t3) {
|
|
901
213
|
e3[n2] = t3;
|
|
902
214
|
}));
|
|
903
|
-
var N = O.access = { has: f2 ?
|
|
215
|
+
var N = O.access = { has: f2 ? h.bind() : function(e3) {
|
|
904
216
|
return n2 in e3;
|
|
905
217
|
} };
|
|
906
|
-
if (k && (N.get = k), F && (N.set = F), P =
|
|
907
|
-
if ("object" == typeof P && P) (
|
|
218
|
+
if (k && (N.get = k), F && (N.set = F), P = D.call(E, d ? { get: w.get, set: w.set } : w[A], O), d) {
|
|
219
|
+
if ("object" == typeof P && P) (y = s(P.get, "accessor.get")) && (w.get = y), (y = s(P.set, "accessor.set")) && (w.set = y), (y = s(P.init, "accessor.init")) && S.push(y);
|
|
908
220
|
else if (void 0 !== P) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
909
|
-
} else s(P, (
|
|
221
|
+
} else s(P, (p2 ? "field" : "method") + " decorators", "return") && (p2 ? S.push(P) : w[A] = P);
|
|
910
222
|
}
|
|
911
223
|
} finally {
|
|
912
224
|
I.v = true;
|
|
913
225
|
}
|
|
914
226
|
}
|
|
915
|
-
return (
|
|
916
|
-
for (var r3 =
|
|
227
|
+
return (p2 || d) && u2.push(function(e3, t3) {
|
|
228
|
+
for (var r3 = S.length - 1; r3 >= 0; r3--) t3 = S[r3].call(e3, t3);
|
|
917
229
|
return t3;
|
|
918
|
-
}),
|
|
230
|
+
}), p2 || b || (f2 ? d ? u2.push(i(w, "get"), i(w, "set")) : u2.push(2 === o2 ? w[A] : i.call.bind(w[A])) : Object.defineProperty(e2, n2, w)), P;
|
|
919
231
|
}
|
|
920
232
|
function u(e2, t2) {
|
|
921
233
|
return Object.defineProperty(e2, Symbol.metadata || /* @__PURE__ */ Symbol.for("Symbol.metadata"), { configurable: true, enumerable: true, value: t2 });
|
|
922
234
|
}
|
|
923
|
-
if (arguments.length >= 6) var
|
|
924
|
-
var f = Object.create(null ==
|
|
925
|
-
var o2, a2,
|
|
235
|
+
if (arguments.length >= 6) var l = a[Symbol.metadata || /* @__PURE__ */ Symbol.for("Symbol.metadata")];
|
|
236
|
+
var f = Object.create(null == l ? null : l), p = (function(e2, t2, r2, n2) {
|
|
237
|
+
var o2, a2, i2 = [], s2 = function(t3) {
|
|
926
238
|
return _checkInRHS$3(t3) === e2;
|
|
927
239
|
}, u2 = /* @__PURE__ */ new Map();
|
|
928
|
-
function
|
|
929
|
-
e3 &&
|
|
240
|
+
function l2(e3) {
|
|
241
|
+
e3 && i2.push(c.bind(null, e3));
|
|
930
242
|
}
|
|
931
243
|
for (var f2 = 0; f2 < t2.length; f2++) {
|
|
932
|
-
var
|
|
933
|
-
if (Array.isArray(
|
|
934
|
-
var
|
|
935
|
-
if (!g && !
|
|
936
|
-
var
|
|
937
|
-
if (true ===
|
|
938
|
-
u2.set(
|
|
244
|
+
var p2 = t2[f2];
|
|
245
|
+
if (Array.isArray(p2)) {
|
|
246
|
+
var d = p2[1], h = p2[2], m = p2.length > 3, y = 16 & d, v = !!(8 & d), g = 0 == (d &= 7), b = h + "/" + v;
|
|
247
|
+
if (!g && !m) {
|
|
248
|
+
var w = u2.get(b);
|
|
249
|
+
if (true === w || 3 === w && 4 !== d || 4 === w && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h);
|
|
250
|
+
u2.set(b, !(d > 2) || d);
|
|
939
251
|
}
|
|
940
|
-
applyDec(v ? e2 : e2.prototype,
|
|
252
|
+
applyDec(v ? e2 : e2.prototype, p2, y, m ? "#" + h : _toPropertyKey$3(h), d, n2, v ? a2 = a2 || [] : o2 = o2 || [], i2, v, m, g, 1 === d, v && m ? s2 : r2);
|
|
941
253
|
}
|
|
942
254
|
}
|
|
943
|
-
return
|
|
255
|
+
return l2(o2), l2(a2), i2;
|
|
944
256
|
})(e, t, o, f);
|
|
945
|
-
return r.length || u(e, f), { e:
|
|
257
|
+
return r.length || u(e, f), { e: p, get c() {
|
|
946
258
|
var t2 = [];
|
|
947
259
|
return r.length && [u(applyDec(e, [r], n, e.name, 5, f, t2), f), c.bind(null, t2, e)];
|
|
948
260
|
} };
|
|
949
261
|
}
|
|
950
262
|
function _toPropertyKey$3(t) {
|
|
951
|
-
var
|
|
952
|
-
return "symbol" == typeof
|
|
263
|
+
var i = _toPrimitive$3(t, "string");
|
|
264
|
+
return "symbol" == typeof i ? i : i + "";
|
|
953
265
|
}
|
|
954
266
|
function _toPrimitive$3(t, r) {
|
|
955
267
|
if ("object" != typeof t || !t) return t;
|
|
956
268
|
var e = t[Symbol.toPrimitive];
|
|
957
269
|
if (void 0 !== e) {
|
|
958
|
-
var
|
|
959
|
-
if ("object" != typeof
|
|
270
|
+
var i = e.call(t, r);
|
|
271
|
+
if ("object" != typeof i) return i;
|
|
960
272
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
961
273
|
}
|
|
962
274
|
return String(t);
|
|
@@ -973,6 +285,7 @@ function _checkInRHS$3(e) {
|
|
|
973
285
|
if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null"));
|
|
974
286
|
return e;
|
|
975
287
|
}
|
|
288
|
+
const UPGRADABLE_PROPS$3 = ["viewDate", "events", "user"];
|
|
976
289
|
_classDecs$3 = [autoRegister({
|
|
977
290
|
tagName: "wsx-day-view"
|
|
978
291
|
})];
|
|
@@ -983,18 +296,15 @@ class DayView extends WebComponent {
|
|
|
983
296
|
return ["view-date", "events", "user"];
|
|
984
297
|
}
|
|
985
298
|
// ========== 内部状态 ==========
|
|
299
|
+
// 日期存 ISO:避免 WSX reactive Proxy 破坏 Date
|
|
986
300
|
// ========== Property 访问器(WSX 组件之间使用) ==========
|
|
987
301
|
get viewDate() {
|
|
988
|
-
return this.
|
|
302
|
+
return fromStateIso(this._viewDateIso);
|
|
989
303
|
}
|
|
990
304
|
set viewDate(value) {
|
|
991
|
-
|
|
992
|
-
this.
|
|
993
|
-
}
|
|
994
|
-
const date = new Date(value);
|
|
995
|
-
if (!isNaN(date.getTime())) {
|
|
996
|
-
this._viewDate = date;
|
|
997
|
-
}
|
|
305
|
+
try {
|
|
306
|
+
this._viewDateIso = toStateIso(value);
|
|
307
|
+
} catch {
|
|
998
308
|
}
|
|
999
309
|
}
|
|
1000
310
|
get events() {
|
|
@@ -1002,10 +312,11 @@ class DayView extends WebComponent {
|
|
|
1002
312
|
}
|
|
1003
313
|
set events(value) {
|
|
1004
314
|
if (Array.isArray(value)) {
|
|
1005
|
-
this._events = value;
|
|
315
|
+
this._events = normalizeEventsForState(value);
|
|
1006
316
|
} else if (typeof value === "string") {
|
|
1007
317
|
try {
|
|
1008
|
-
|
|
318
|
+
const parsed = JSON.parse(value);
|
|
319
|
+
this._events = Array.isArray(parsed) ? normalizeEventsForState(parsed) : [];
|
|
1009
320
|
} catch (e) {
|
|
1010
321
|
console.error("Invalid events JSON:", value);
|
|
1011
322
|
this._events = [];
|
|
@@ -1035,7 +346,7 @@ class DayView extends WebComponent {
|
|
|
1035
346
|
styleName: "wsx-day-view"
|
|
1036
347
|
});
|
|
1037
348
|
_defineProperty$3(this, "_autoStyles", styles$2);
|
|
1038
|
-
_defineProperty$3(this, "
|
|
349
|
+
_defineProperty$3(this, "_viewDateIso", void 0);
|
|
1039
350
|
_defineProperty$3(this, "_events", void 0);
|
|
1040
351
|
_defineProperty$3(this, "_user", void 0);
|
|
1041
352
|
_defineProperty$3(this, "_today", void 0);
|
|
@@ -1054,10 +365,10 @@ class DayView extends WebComponent {
|
|
|
1054
365
|
const today = /* @__PURE__ */ new Date();
|
|
1055
366
|
today.setHours(0, 0, 0, 0);
|
|
1056
367
|
this._today = today;
|
|
1057
|
-
const [
|
|
1058
|
-
Object.defineProperty(this, "
|
|
1059
|
-
get:
|
|
1060
|
-
set:
|
|
368
|
+
const [_get_viewDateIso, _set_viewDateIso] = this.useState("_viewDateIso", (/* @__PURE__ */ new Date()).toISOString());
|
|
369
|
+
Object.defineProperty(this, "_viewDateIso", {
|
|
370
|
+
get: _get_viewDateIso,
|
|
371
|
+
set: _set_viewDateIso,
|
|
1061
372
|
enumerable: true,
|
|
1062
373
|
configurable: true
|
|
1063
374
|
});
|
|
@@ -1089,6 +400,7 @@ class DayView extends WebComponent {
|
|
|
1089
400
|
// ========== 生命周期 ==========
|
|
1090
401
|
onConnected() {
|
|
1091
402
|
super.onConnected?.();
|
|
403
|
+
upgradeProperties(this, UPGRADABLE_PROPS$3);
|
|
1092
404
|
this.initializeFromAttributes();
|
|
1093
405
|
}
|
|
1094
406
|
onAttributeChanged(name, oldValue, newValue) {
|
|
@@ -1133,7 +445,7 @@ class DayView extends WebComponent {
|
|
|
1133
445
|
return sortEventsByTime(getEventsForDate(this.events, this.viewDate));
|
|
1134
446
|
}
|
|
1135
447
|
get hours() {
|
|
1136
|
-
return
|
|
448
|
+
return getDayHours();
|
|
1137
449
|
}
|
|
1138
450
|
get dayStart() {
|
|
1139
451
|
const dayStart = new Date(this.viewDate);
|
|
@@ -1147,7 +459,7 @@ class DayView extends WebComponent {
|
|
|
1147
459
|
}
|
|
1148
460
|
// ========== 渲染 ==========
|
|
1149
461
|
render() {
|
|
1150
|
-
return /* @__PURE__ */ jsx("div", { class: "day-view" }, /* @__PURE__ */ jsx("div", { class: "day-view-header" }, /* @__PURE__ */ jsx("div", { class: `day-view-date ${
|
|
462
|
+
return /* @__PURE__ */ jsx("div", { class: "day-view" }, /* @__PURE__ */ jsx("div", { class: "day-view-header" }, /* @__PURE__ */ jsx("div", { class: `day-view-date ${isSameDay(this.viewDate, this._today) ? "today" : ""}` }, this.viewDate.getFullYear(), "年", this.viewDate.getMonth() + 1, "月", this.viewDate.getDate(), "日"), /* @__PURE__ */ jsx("div", { class: "day-view-events-count" }, this.dayEvents.length, " 个事件")), /* @__PURE__ */ jsx("div", { class: "day-view-body" }, /* @__PURE__ */ jsx("div", { class: "day-view-time-column" }, this.hours.map((hour) => {
|
|
1151
463
|
const hourStr = hour < 10 ? `0${hour}` : `${hour}`;
|
|
1152
464
|
const timeStr = `${hourStr}:00`;
|
|
1153
465
|
return /* @__PURE__ */ jsx("div", { class: "day-view-hour-label", key: `left-hour-${hour}` }, timeStr);
|
|
@@ -1157,7 +469,7 @@ class DayView extends WebComponent {
|
|
|
1157
469
|
const position = calculateEventPosition(event, this.dayStart, this.dayEnd);
|
|
1158
470
|
const eventColor = event.color || "#4285f4";
|
|
1159
471
|
const eventDescription = event.data?.description;
|
|
1160
|
-
return /* @__PURE__ */ jsx("div", { class: "day-view-event", key: event.id, style: `top: ${position.top}%; height: ${position.height}%; background-color: ${eventColor}`, onClick: () => this.handleEventClick(event), title: event.title }, /* @__PURE__ */ jsx("div", { class: "day-view-event-time" },
|
|
472
|
+
return /* @__PURE__ */ jsx("div", { class: "day-view-event", key: event.id, style: `top: ${position.top}%; height: ${position.height}%; background-color: ${eventColor}`, onClick: () => this.handleEventClick(event), title: event.title }, /* @__PURE__ */ jsx("div", { class: "day-view-event-time" }, getTimeString(event.startTime), " -", " ", getTimeString(event.endTime)), /* @__PURE__ */ jsx("div", { class: "day-view-event-title" }, event.title), eventDescription && /* @__PURE__ */ jsx("div", { class: "day-view-event-description" }, eventDescription));
|
|
1161
473
|
}))));
|
|
1162
474
|
}
|
|
1163
475
|
}
|
|
@@ -1171,7 +483,7 @@ function _defineProperty$2(e, r, t) {
|
|
|
1171
483
|
return (r = _toPropertyKey$2(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
|
|
1172
484
|
}
|
|
1173
485
|
function _applyDecs$2(e, t, r, n, o, a) {
|
|
1174
|
-
function
|
|
486
|
+
function i(e2, t2, r2) {
|
|
1175
487
|
return function(n2, o2) {
|
|
1176
488
|
return r2 && r2(n2), e2[t2].call(n2, o2);
|
|
1177
489
|
};
|
|
@@ -1184,93 +496,93 @@ function _applyDecs$2(e, t, r, n, o, a) {
|
|
|
1184
496
|
if ("function" != typeof e2 && (n2 || void 0 !== e2)) throw new TypeError(t2 + " must " + (r2 || "be") + " a function" + (n2 ? "" : " or undefined"));
|
|
1185
497
|
return e2;
|
|
1186
498
|
}
|
|
1187
|
-
function applyDec(e2, t2, r2, n2, o2, a2, c2, u2,
|
|
1188
|
-
function
|
|
1189
|
-
if (!
|
|
499
|
+
function applyDec(e2, t2, r2, n2, o2, a2, c2, u2, l2, f2, p2, d, h) {
|
|
500
|
+
function m(e3) {
|
|
501
|
+
if (!h(e3)) throw new TypeError("Attempted to access private element on non-instance");
|
|
1190
502
|
}
|
|
1191
|
-
var
|
|
1192
|
-
if (!
|
|
503
|
+
var y, v = t2[0], g = t2[3], b = !u2;
|
|
504
|
+
if (!b) {
|
|
1193
505
|
r2 || Array.isArray(v) || (v = [v]);
|
|
1194
|
-
var
|
|
1195
|
-
f2 ? (
|
|
506
|
+
var w = {}, S = [], A = 3 === o2 ? "get" : 4 === o2 || d ? "set" : "value";
|
|
507
|
+
f2 ? (p2 || d ? w = { get: _setFunctionName$2(function() {
|
|
1196
508
|
return g(this);
|
|
1197
509
|
}, n2, "get"), set: function(e3) {
|
|
1198
510
|
t2[4](this, e3);
|
|
1199
|
-
} } :
|
|
511
|
+
} } : w[A] = g, p2 || _setFunctionName$2(w[A], n2, 2 === o2 ? "" : A)) : p2 || (w = Object.getOwnPropertyDescriptor(e2, n2));
|
|
1200
512
|
}
|
|
1201
513
|
for (var P = e2, j = v.length - 1; j >= 0; j -= r2 ? 2 : 1) {
|
|
1202
|
-
var
|
|
514
|
+
var D = v[j], E = r2 ? v[j - 1] : void 0, I = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][o2], name: n2, metadata: a2, addInitializer: (function(e3, t3) {
|
|
1203
515
|
if (e3.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
1204
516
|
s(t3, "An initializer", "be", true), c2.push(t3);
|
|
1205
517
|
}).bind(null, I) };
|
|
1206
518
|
try {
|
|
1207
|
-
if (
|
|
519
|
+
if (b) (y = s(D.call(E, P, O), "class decorators", "return")) && (P = y);
|
|
1208
520
|
else {
|
|
1209
521
|
var k, F;
|
|
1210
|
-
O.static =
|
|
1211
|
-
return
|
|
1212
|
-
} : (o2 < 4 && (k =
|
|
522
|
+
O.static = l2, O.private = f2, f2 ? 2 === o2 ? k = function(e3) {
|
|
523
|
+
return m(e3), w.value;
|
|
524
|
+
} : (o2 < 4 && (k = i(w, "get", m)), 3 !== o2 && (F = i(w, "set", m))) : (k = function(e3) {
|
|
1213
525
|
return e3[n2];
|
|
1214
526
|
}, (o2 < 2 || 4 === o2) && (F = function(e3, t3) {
|
|
1215
527
|
e3[n2] = t3;
|
|
1216
528
|
}));
|
|
1217
|
-
var N = O.access = { has: f2 ?
|
|
529
|
+
var N = O.access = { has: f2 ? h.bind() : function(e3) {
|
|
1218
530
|
return n2 in e3;
|
|
1219
531
|
} };
|
|
1220
|
-
if (k && (N.get = k), F && (N.set = F), P =
|
|
1221
|
-
if ("object" == typeof P && P) (
|
|
532
|
+
if (k && (N.get = k), F && (N.set = F), P = D.call(E, d ? { get: w.get, set: w.set } : w[A], O), d) {
|
|
533
|
+
if ("object" == typeof P && P) (y = s(P.get, "accessor.get")) && (w.get = y), (y = s(P.set, "accessor.set")) && (w.set = y), (y = s(P.init, "accessor.init")) && S.push(y);
|
|
1222
534
|
else if (void 0 !== P) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
1223
|
-
} else s(P, (
|
|
535
|
+
} else s(P, (p2 ? "field" : "method") + " decorators", "return") && (p2 ? S.push(P) : w[A] = P);
|
|
1224
536
|
}
|
|
1225
537
|
} finally {
|
|
1226
538
|
I.v = true;
|
|
1227
539
|
}
|
|
1228
540
|
}
|
|
1229
|
-
return (
|
|
1230
|
-
for (var r3 =
|
|
541
|
+
return (p2 || d) && u2.push(function(e3, t3) {
|
|
542
|
+
for (var r3 = S.length - 1; r3 >= 0; r3--) t3 = S[r3].call(e3, t3);
|
|
1231
543
|
return t3;
|
|
1232
|
-
}),
|
|
544
|
+
}), p2 || b || (f2 ? d ? u2.push(i(w, "get"), i(w, "set")) : u2.push(2 === o2 ? w[A] : i.call.bind(w[A])) : Object.defineProperty(e2, n2, w)), P;
|
|
1233
545
|
}
|
|
1234
546
|
function u(e2, t2) {
|
|
1235
547
|
return Object.defineProperty(e2, Symbol.metadata || /* @__PURE__ */ Symbol.for("Symbol.metadata"), { configurable: true, enumerable: true, value: t2 });
|
|
1236
548
|
}
|
|
1237
|
-
if (arguments.length >= 6) var
|
|
1238
|
-
var f = Object.create(null ==
|
|
1239
|
-
var o2, a2,
|
|
549
|
+
if (arguments.length >= 6) var l = a[Symbol.metadata || /* @__PURE__ */ Symbol.for("Symbol.metadata")];
|
|
550
|
+
var f = Object.create(null == l ? null : l), p = (function(e2, t2, r2, n2) {
|
|
551
|
+
var o2, a2, i2 = [], s2 = function(t3) {
|
|
1240
552
|
return _checkInRHS$2(t3) === e2;
|
|
1241
553
|
}, u2 = /* @__PURE__ */ new Map();
|
|
1242
|
-
function
|
|
1243
|
-
e3 &&
|
|
554
|
+
function l2(e3) {
|
|
555
|
+
e3 && i2.push(c.bind(null, e3));
|
|
1244
556
|
}
|
|
1245
557
|
for (var f2 = 0; f2 < t2.length; f2++) {
|
|
1246
|
-
var
|
|
1247
|
-
if (Array.isArray(
|
|
1248
|
-
var
|
|
1249
|
-
if (!g && !
|
|
1250
|
-
var
|
|
1251
|
-
if (true ===
|
|
1252
|
-
u2.set(
|
|
558
|
+
var p2 = t2[f2];
|
|
559
|
+
if (Array.isArray(p2)) {
|
|
560
|
+
var d = p2[1], h = p2[2], m = p2.length > 3, y = 16 & d, v = !!(8 & d), g = 0 == (d &= 7), b = h + "/" + v;
|
|
561
|
+
if (!g && !m) {
|
|
562
|
+
var w = u2.get(b);
|
|
563
|
+
if (true === w || 3 === w && 4 !== d || 4 === w && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h);
|
|
564
|
+
u2.set(b, !(d > 2) || d);
|
|
1253
565
|
}
|
|
1254
|
-
applyDec(v ? e2 : e2.prototype,
|
|
566
|
+
applyDec(v ? e2 : e2.prototype, p2, y, m ? "#" + h : _toPropertyKey$2(h), d, n2, v ? a2 = a2 || [] : o2 = o2 || [], i2, v, m, g, 1 === d, v && m ? s2 : r2);
|
|
1255
567
|
}
|
|
1256
568
|
}
|
|
1257
|
-
return
|
|
569
|
+
return l2(o2), l2(a2), i2;
|
|
1258
570
|
})(e, t, o, f);
|
|
1259
|
-
return r.length || u(e, f), { e:
|
|
571
|
+
return r.length || u(e, f), { e: p, get c() {
|
|
1260
572
|
var t2 = [];
|
|
1261
573
|
return r.length && [u(applyDec(e, [r], n, e.name, 5, f, t2), f), c.bind(null, t2, e)];
|
|
1262
574
|
} };
|
|
1263
575
|
}
|
|
1264
576
|
function _toPropertyKey$2(t) {
|
|
1265
|
-
var
|
|
1266
|
-
return "symbol" == typeof
|
|
577
|
+
var i = _toPrimitive$2(t, "string");
|
|
578
|
+
return "symbol" == typeof i ? i : i + "";
|
|
1267
579
|
}
|
|
1268
580
|
function _toPrimitive$2(t, r) {
|
|
1269
581
|
if ("object" != typeof t || !t) return t;
|
|
1270
582
|
var e = t[Symbol.toPrimitive];
|
|
1271
583
|
if (void 0 !== e) {
|
|
1272
|
-
var
|
|
1273
|
-
if ("object" != typeof
|
|
584
|
+
var i = e.call(t, r);
|
|
585
|
+
if ("object" != typeof i) return i;
|
|
1274
586
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1275
587
|
}
|
|
1276
588
|
return String(t);
|
|
@@ -1287,6 +599,7 @@ function _checkInRHS$2(e) {
|
|
|
1287
599
|
if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null"));
|
|
1288
600
|
return e;
|
|
1289
601
|
}
|
|
602
|
+
const UPGRADABLE_PROPS$2 = ["viewDate", "events", "selectedDate", "user"];
|
|
1290
603
|
_classDecs$2 = [autoRegister({
|
|
1291
604
|
tagName: "wsx-month-view"
|
|
1292
605
|
})];
|
|
@@ -1297,18 +610,15 @@ class MonthView extends WebComponent {
|
|
|
1297
610
|
return ["view-date", "events", "selected-date", "user"];
|
|
1298
611
|
}
|
|
1299
612
|
// ========== 内部状态 ==========
|
|
613
|
+
// 日期存 ISO:避免 WSX reactive Proxy 破坏 Date
|
|
1300
614
|
// ========== Property 访问器(WSX 组件之间使用) ==========
|
|
1301
615
|
get viewDate() {
|
|
1302
|
-
return this.
|
|
616
|
+
return fromStateIso(this._viewDateIso);
|
|
1303
617
|
}
|
|
1304
618
|
set viewDate(value) {
|
|
1305
|
-
|
|
1306
|
-
this.
|
|
1307
|
-
}
|
|
1308
|
-
const date = new Date(value);
|
|
1309
|
-
if (!isNaN(date.getTime())) {
|
|
1310
|
-
this._viewDate = date;
|
|
1311
|
-
}
|
|
619
|
+
try {
|
|
620
|
+
this._viewDateIso = toStateIso(value);
|
|
621
|
+
} catch {
|
|
1312
622
|
}
|
|
1313
623
|
}
|
|
1314
624
|
get events() {
|
|
@@ -1316,10 +626,11 @@ class MonthView extends WebComponent {
|
|
|
1316
626
|
}
|
|
1317
627
|
set events(value) {
|
|
1318
628
|
if (Array.isArray(value)) {
|
|
1319
|
-
this._events = value;
|
|
629
|
+
this._events = normalizeEventsForState(value);
|
|
1320
630
|
} else if (typeof value === "string") {
|
|
1321
631
|
try {
|
|
1322
|
-
|
|
632
|
+
const parsed = JSON.parse(value);
|
|
633
|
+
this._events = Array.isArray(parsed) ? normalizeEventsForState(parsed) : [];
|
|
1323
634
|
} catch (e) {
|
|
1324
635
|
console.error("Invalid events JSON:", value);
|
|
1325
636
|
this._events = [];
|
|
@@ -1329,21 +640,10 @@ class MonthView extends WebComponent {
|
|
|
1329
640
|
}
|
|
1330
641
|
}
|
|
1331
642
|
get selectedDate() {
|
|
1332
|
-
return this.
|
|
643
|
+
return fromStateIso(this._selectedDateIso);
|
|
1333
644
|
}
|
|
1334
645
|
set selectedDate(value) {
|
|
1335
|
-
|
|
1336
|
-
this._selectedDate = value;
|
|
1337
|
-
} else if (typeof value === "string") {
|
|
1338
|
-
const date = new Date(value);
|
|
1339
|
-
if (!isNaN(date.getTime())) {
|
|
1340
|
-
this._selectedDate = date;
|
|
1341
|
-
} else {
|
|
1342
|
-
this._selectedDate = /* @__PURE__ */ new Date(0);
|
|
1343
|
-
}
|
|
1344
|
-
} else if (value === void 0 || value === null) {
|
|
1345
|
-
this._selectedDate = /* @__PURE__ */ new Date(0);
|
|
1346
|
-
}
|
|
646
|
+
this._selectedDateIso = toStateIsoOrUnselected(value);
|
|
1347
647
|
}
|
|
1348
648
|
get user() {
|
|
1349
649
|
return this._user;
|
|
@@ -1366,9 +666,9 @@ class MonthView extends WebComponent {
|
|
|
1366
666
|
styleName: "wsx-month-view"
|
|
1367
667
|
});
|
|
1368
668
|
_defineProperty$2(this, "_autoStyles", styles$1);
|
|
1369
|
-
_defineProperty$2(this, "
|
|
669
|
+
_defineProperty$2(this, "_viewDateIso", void 0);
|
|
1370
670
|
_defineProperty$2(this, "_events", void 0);
|
|
1371
|
-
_defineProperty$2(this, "
|
|
671
|
+
_defineProperty$2(this, "_selectedDateIso", void 0);
|
|
1372
672
|
_defineProperty$2(this, "_user", void 0);
|
|
1373
673
|
_defineProperty$2(this, "_today", void 0);
|
|
1374
674
|
_defineProperty$2(this, "onDateClick", void 0);
|
|
@@ -1428,10 +728,10 @@ class MonthView extends WebComponent {
|
|
|
1428
728
|
const today = /* @__PURE__ */ new Date();
|
|
1429
729
|
today.setHours(0, 0, 0, 0);
|
|
1430
730
|
this._today = today;
|
|
1431
|
-
const [
|
|
1432
|
-
Object.defineProperty(this, "
|
|
1433
|
-
get:
|
|
1434
|
-
set:
|
|
731
|
+
const [_get_viewDateIso, _set_viewDateIso] = this.useState("_viewDateIso", (/* @__PURE__ */ new Date()).toISOString());
|
|
732
|
+
Object.defineProperty(this, "_viewDateIso", {
|
|
733
|
+
get: _get_viewDateIso,
|
|
734
|
+
set: _set_viewDateIso,
|
|
1435
735
|
enumerable: true,
|
|
1436
736
|
configurable: true
|
|
1437
737
|
});
|
|
@@ -1445,10 +745,10 @@ class MonthView extends WebComponent {
|
|
|
1445
745
|
enumerable: true,
|
|
1446
746
|
configurable: true
|
|
1447
747
|
});
|
|
1448
|
-
const [
|
|
1449
|
-
Object.defineProperty(this, "
|
|
1450
|
-
get:
|
|
1451
|
-
set:
|
|
748
|
+
const [_get_selectedDateIso, _set_selectedDateIso] = this.useState("_selectedDateIso", UNSELECTED_DATE_ISO);
|
|
749
|
+
Object.defineProperty(this, "_selectedDateIso", {
|
|
750
|
+
get: _get_selectedDateIso,
|
|
751
|
+
set: _set_selectedDateIso,
|
|
1452
752
|
enumerable: true,
|
|
1453
753
|
configurable: true
|
|
1454
754
|
});
|
|
@@ -1470,6 +770,7 @@ class MonthView extends WebComponent {
|
|
|
1470
770
|
// ========== 生命周期 ==========
|
|
1471
771
|
onConnected() {
|
|
1472
772
|
super.onConnected?.();
|
|
773
|
+
upgradeProperties(this, UPGRADABLE_PROPS$2);
|
|
1473
774
|
this.initializeFromAttributes();
|
|
1474
775
|
}
|
|
1475
776
|
onAttributeChanged(name, oldValue, newValue) {
|
|
@@ -1524,11 +825,13 @@ class MonthView extends WebComponent {
|
|
|
1524
825
|
}
|
|
1525
826
|
// ========== Getters ==========
|
|
1526
827
|
get monthDates() {
|
|
1527
|
-
|
|
1528
|
-
|
|
828
|
+
let viewDate = this.viewDate;
|
|
829
|
+
if (Number.isNaN(viewDate.getTime())) {
|
|
830
|
+
this._viewDateIso = toStateIso(/* @__PURE__ */ new Date());
|
|
831
|
+
viewDate = this.viewDate;
|
|
1529
832
|
}
|
|
1530
833
|
try {
|
|
1531
|
-
return
|
|
834
|
+
return getMonthDates(viewDate, 0);
|
|
1532
835
|
} catch (e) {
|
|
1533
836
|
console.error("Error getting month dates:", e);
|
|
1534
837
|
return [];
|
|
@@ -1550,14 +853,14 @@ class MonthView extends WebComponent {
|
|
|
1550
853
|
}
|
|
1551
854
|
const normalizedDate = new Date(date);
|
|
1552
855
|
normalizedDate.setHours(0, 0, 0, 0);
|
|
1553
|
-
const dateKey =
|
|
856
|
+
const dateKey = formatDateKey(normalizedDate);
|
|
1554
857
|
const dayEvents = sortEventsByTime(this.eventsByDate.get(dateKey) || []);
|
|
1555
|
-
const isCurrentMonth =
|
|
1556
|
-
this.
|
|
1557
|
-
const isToday =
|
|
858
|
+
const isCurrentMonth = !Number.isNaN(this.viewDate.getTime()) ? isSameMonth(normalizedDate, this.viewDate) : false;
|
|
859
|
+
this.selectedDate.getTime() !== 0 && isSameDay(normalizedDate, this.selectedDate);
|
|
860
|
+
const isToday = isSameDay(normalizedDate, this._today);
|
|
1558
861
|
return /* @__PURE__ */ jsx("div", { key: dateKey, class: `month-view-cell ${!isCurrentMonth ? "other-month" : ""} ${isToday && isCurrentMonth ? "today" : ""}`, onClick: () => this.handleDateClick(normalizedDate), onDblClick: () => this.handleDateDoubleClick(normalizedDate) }, /* @__PURE__ */ jsx("div", { class: "month-view-cell-date" }, normalizedDate.getDate()), /* @__PURE__ */ jsx("div", { class: "month-view-cell-events" }, dayEvents.slice(0, 3).map((event) => {
|
|
1559
862
|
const eventColor = event.color || "#4285f4";
|
|
1560
|
-
return /* @__PURE__ */ jsx("div", { class: "month-view-event", key: event.id, style: `background-color: ${eventColor}`, onClick: (evt) => this.handleEventClick(event, evt) }, /* @__PURE__ */ jsx("span", { class: "month-view-event-title" }, event.title), this.onEventDelete && /* @__PURE__ */ jsx("button", { class: "month-view-event-delete", onClick: (evt) => this.handleEventDelete(event, evt)
|
|
863
|
+
return /* @__PURE__ */ jsx("div", { class: "month-view-event", key: event.id, style: `background-color: ${eventColor}`, onClick: (evt) => this.handleEventClick(event, evt) }, /* @__PURE__ */ jsx("span", { class: "month-view-event-title" }, event.title), this.onEventDelete && /* @__PURE__ */ jsx("button", { class: "month-view-event-delete", onClick: (evt) => this.handleEventDelete(event, evt) }, "×"));
|
|
1561
864
|
}), dayEvents.length > 3 && /* @__PURE__ */ jsx("div", { class: "month-view-more" }, "+", dayEvents.length - 3, " 更多")));
|
|
1562
865
|
})));
|
|
1563
866
|
}
|
|
@@ -1572,7 +875,7 @@ function _defineProperty$1(e, r, t) {
|
|
|
1572
875
|
return (r = _toPropertyKey$1(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
|
|
1573
876
|
}
|
|
1574
877
|
function _applyDecs$1(e, t, r, n, o, a) {
|
|
1575
|
-
function
|
|
878
|
+
function i(e2, t2, r2) {
|
|
1576
879
|
return function(n2, o2) {
|
|
1577
880
|
return r2 && r2(n2), e2[t2].call(n2, o2);
|
|
1578
881
|
};
|
|
@@ -1585,93 +888,93 @@ function _applyDecs$1(e, t, r, n, o, a) {
|
|
|
1585
888
|
if ("function" != typeof e2 && (n2 || void 0 !== e2)) throw new TypeError(t2 + " must " + (r2 || "be") + " a function" + (n2 ? "" : " or undefined"));
|
|
1586
889
|
return e2;
|
|
1587
890
|
}
|
|
1588
|
-
function applyDec(e2, t2, r2, n2, o2, a2, c2, u2,
|
|
1589
|
-
function
|
|
1590
|
-
if (!
|
|
891
|
+
function applyDec(e2, t2, r2, n2, o2, a2, c2, u2, l2, f2, p2, d, h) {
|
|
892
|
+
function m(e3) {
|
|
893
|
+
if (!h(e3)) throw new TypeError("Attempted to access private element on non-instance");
|
|
1591
894
|
}
|
|
1592
|
-
var
|
|
1593
|
-
if (!
|
|
895
|
+
var y, v = t2[0], g = t2[3], b = !u2;
|
|
896
|
+
if (!b) {
|
|
1594
897
|
r2 || Array.isArray(v) || (v = [v]);
|
|
1595
|
-
var
|
|
1596
|
-
f2 ? (
|
|
898
|
+
var w = {}, S = [], A = 3 === o2 ? "get" : 4 === o2 || d ? "set" : "value";
|
|
899
|
+
f2 ? (p2 || d ? w = { get: _setFunctionName$1(function() {
|
|
1597
900
|
return g(this);
|
|
1598
901
|
}, n2, "get"), set: function(e3) {
|
|
1599
902
|
t2[4](this, e3);
|
|
1600
|
-
} } :
|
|
903
|
+
} } : w[A] = g, p2 || _setFunctionName$1(w[A], n2, 2 === o2 ? "" : A)) : p2 || (w = Object.getOwnPropertyDescriptor(e2, n2));
|
|
1601
904
|
}
|
|
1602
905
|
for (var P = e2, j = v.length - 1; j >= 0; j -= r2 ? 2 : 1) {
|
|
1603
|
-
var
|
|
906
|
+
var D = v[j], E = r2 ? v[j - 1] : void 0, I = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][o2], name: n2, metadata: a2, addInitializer: (function(e3, t3) {
|
|
1604
907
|
if (e3.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
1605
908
|
s(t3, "An initializer", "be", true), c2.push(t3);
|
|
1606
909
|
}).bind(null, I) };
|
|
1607
910
|
try {
|
|
1608
|
-
if (
|
|
911
|
+
if (b) (y = s(D.call(E, P, O), "class decorators", "return")) && (P = y);
|
|
1609
912
|
else {
|
|
1610
913
|
var k, F;
|
|
1611
|
-
O.static =
|
|
1612
|
-
return
|
|
1613
|
-
} : (o2 < 4 && (k =
|
|
914
|
+
O.static = l2, O.private = f2, f2 ? 2 === o2 ? k = function(e3) {
|
|
915
|
+
return m(e3), w.value;
|
|
916
|
+
} : (o2 < 4 && (k = i(w, "get", m)), 3 !== o2 && (F = i(w, "set", m))) : (k = function(e3) {
|
|
1614
917
|
return e3[n2];
|
|
1615
918
|
}, (o2 < 2 || 4 === o2) && (F = function(e3, t3) {
|
|
1616
919
|
e3[n2] = t3;
|
|
1617
920
|
}));
|
|
1618
|
-
var N = O.access = { has: f2 ?
|
|
921
|
+
var N = O.access = { has: f2 ? h.bind() : function(e3) {
|
|
1619
922
|
return n2 in e3;
|
|
1620
923
|
} };
|
|
1621
|
-
if (k && (N.get = k), F && (N.set = F), P =
|
|
1622
|
-
if ("object" == typeof P && P) (
|
|
924
|
+
if (k && (N.get = k), F && (N.set = F), P = D.call(E, d ? { get: w.get, set: w.set } : w[A], O), d) {
|
|
925
|
+
if ("object" == typeof P && P) (y = s(P.get, "accessor.get")) && (w.get = y), (y = s(P.set, "accessor.set")) && (w.set = y), (y = s(P.init, "accessor.init")) && S.push(y);
|
|
1623
926
|
else if (void 0 !== P) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
1624
|
-
} else s(P, (
|
|
927
|
+
} else s(P, (p2 ? "field" : "method") + " decorators", "return") && (p2 ? S.push(P) : w[A] = P);
|
|
1625
928
|
}
|
|
1626
929
|
} finally {
|
|
1627
930
|
I.v = true;
|
|
1628
931
|
}
|
|
1629
932
|
}
|
|
1630
|
-
return (
|
|
1631
|
-
for (var r3 =
|
|
933
|
+
return (p2 || d) && u2.push(function(e3, t3) {
|
|
934
|
+
for (var r3 = S.length - 1; r3 >= 0; r3--) t3 = S[r3].call(e3, t3);
|
|
1632
935
|
return t3;
|
|
1633
|
-
}),
|
|
936
|
+
}), p2 || b || (f2 ? d ? u2.push(i(w, "get"), i(w, "set")) : u2.push(2 === o2 ? w[A] : i.call.bind(w[A])) : Object.defineProperty(e2, n2, w)), P;
|
|
1634
937
|
}
|
|
1635
938
|
function u(e2, t2) {
|
|
1636
939
|
return Object.defineProperty(e2, Symbol.metadata || /* @__PURE__ */ Symbol.for("Symbol.metadata"), { configurable: true, enumerable: true, value: t2 });
|
|
1637
940
|
}
|
|
1638
|
-
if (arguments.length >= 6) var
|
|
1639
|
-
var f = Object.create(null ==
|
|
1640
|
-
var o2, a2,
|
|
941
|
+
if (arguments.length >= 6) var l = a[Symbol.metadata || /* @__PURE__ */ Symbol.for("Symbol.metadata")];
|
|
942
|
+
var f = Object.create(null == l ? null : l), p = (function(e2, t2, r2, n2) {
|
|
943
|
+
var o2, a2, i2 = [], s2 = function(t3) {
|
|
1641
944
|
return _checkInRHS$1(t3) === e2;
|
|
1642
945
|
}, u2 = /* @__PURE__ */ new Map();
|
|
1643
|
-
function
|
|
1644
|
-
e3 &&
|
|
946
|
+
function l2(e3) {
|
|
947
|
+
e3 && i2.push(c.bind(null, e3));
|
|
1645
948
|
}
|
|
1646
949
|
for (var f2 = 0; f2 < t2.length; f2++) {
|
|
1647
|
-
var
|
|
1648
|
-
if (Array.isArray(
|
|
1649
|
-
var
|
|
1650
|
-
if (!g && !
|
|
1651
|
-
var
|
|
1652
|
-
if (true ===
|
|
1653
|
-
u2.set(
|
|
950
|
+
var p2 = t2[f2];
|
|
951
|
+
if (Array.isArray(p2)) {
|
|
952
|
+
var d = p2[1], h = p2[2], m = p2.length > 3, y = 16 & d, v = !!(8 & d), g = 0 == (d &= 7), b = h + "/" + v;
|
|
953
|
+
if (!g && !m) {
|
|
954
|
+
var w = u2.get(b);
|
|
955
|
+
if (true === w || 3 === w && 4 !== d || 4 === w && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h);
|
|
956
|
+
u2.set(b, !(d > 2) || d);
|
|
1654
957
|
}
|
|
1655
|
-
applyDec(v ? e2 : e2.prototype,
|
|
958
|
+
applyDec(v ? e2 : e2.prototype, p2, y, m ? "#" + h : _toPropertyKey$1(h), d, n2, v ? a2 = a2 || [] : o2 = o2 || [], i2, v, m, g, 1 === d, v && m ? s2 : r2);
|
|
1656
959
|
}
|
|
1657
960
|
}
|
|
1658
|
-
return
|
|
961
|
+
return l2(o2), l2(a2), i2;
|
|
1659
962
|
})(e, t, o, f);
|
|
1660
|
-
return r.length || u(e, f), { e:
|
|
963
|
+
return r.length || u(e, f), { e: p, get c() {
|
|
1661
964
|
var t2 = [];
|
|
1662
965
|
return r.length && [u(applyDec(e, [r], n, e.name, 5, f, t2), f), c.bind(null, t2, e)];
|
|
1663
966
|
} };
|
|
1664
967
|
}
|
|
1665
968
|
function _toPropertyKey$1(t) {
|
|
1666
|
-
var
|
|
1667
|
-
return "symbol" == typeof
|
|
969
|
+
var i = _toPrimitive$1(t, "string");
|
|
970
|
+
return "symbol" == typeof i ? i : i + "";
|
|
1668
971
|
}
|
|
1669
972
|
function _toPrimitive$1(t, r) {
|
|
1670
973
|
if ("object" != typeof t || !t) return t;
|
|
1671
974
|
var e = t[Symbol.toPrimitive];
|
|
1672
975
|
if (void 0 !== e) {
|
|
1673
|
-
var
|
|
1674
|
-
if ("object" != typeof
|
|
976
|
+
var i = e.call(t, r);
|
|
977
|
+
if ("object" != typeof i) return i;
|
|
1675
978
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1676
979
|
}
|
|
1677
980
|
return String(t);
|
|
@@ -1688,6 +991,7 @@ function _checkInRHS$1(e) {
|
|
|
1688
991
|
if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null"));
|
|
1689
992
|
return e;
|
|
1690
993
|
}
|
|
994
|
+
const UPGRADABLE_PROPS$1 = ["viewDate", "events", "selectedDate", "user"];
|
|
1691
995
|
_classDecs$1 = [autoRegister({
|
|
1692
996
|
tagName: "wsx-week-view"
|
|
1693
997
|
})];
|
|
@@ -1698,18 +1002,15 @@ class WeekView extends WebComponent {
|
|
|
1698
1002
|
return ["view-date", "events", "selected-date", "user"];
|
|
1699
1003
|
}
|
|
1700
1004
|
// ========== 内部状态 ==========
|
|
1005
|
+
// 日期存 ISO:避免 WSX reactive Proxy 破坏 Date
|
|
1701
1006
|
// ========== Property 访问器(WSX 组件之间使用) ==========
|
|
1702
1007
|
get viewDate() {
|
|
1703
|
-
return this.
|
|
1008
|
+
return fromStateIso(this._viewDateIso);
|
|
1704
1009
|
}
|
|
1705
1010
|
set viewDate(value) {
|
|
1706
|
-
|
|
1707
|
-
this.
|
|
1708
|
-
}
|
|
1709
|
-
const date = new Date(value);
|
|
1710
|
-
if (!isNaN(date.getTime())) {
|
|
1711
|
-
this._viewDate = date;
|
|
1712
|
-
}
|
|
1011
|
+
try {
|
|
1012
|
+
this._viewDateIso = toStateIso(value);
|
|
1013
|
+
} catch {
|
|
1713
1014
|
}
|
|
1714
1015
|
}
|
|
1715
1016
|
get events() {
|
|
@@ -1717,10 +1018,11 @@ class WeekView extends WebComponent {
|
|
|
1717
1018
|
}
|
|
1718
1019
|
set events(value) {
|
|
1719
1020
|
if (Array.isArray(value)) {
|
|
1720
|
-
this._events = value;
|
|
1021
|
+
this._events = normalizeEventsForState(value);
|
|
1721
1022
|
} else if (typeof value === "string") {
|
|
1722
1023
|
try {
|
|
1723
|
-
|
|
1024
|
+
const parsed = JSON.parse(value);
|
|
1025
|
+
this._events = Array.isArray(parsed) ? normalizeEventsForState(parsed) : [];
|
|
1724
1026
|
} catch (e) {
|
|
1725
1027
|
console.error("Invalid events JSON:", value);
|
|
1726
1028
|
this._events = [];
|
|
@@ -1730,21 +1032,10 @@ class WeekView extends WebComponent {
|
|
|
1730
1032
|
}
|
|
1731
1033
|
}
|
|
1732
1034
|
get selectedDate() {
|
|
1733
|
-
return this.
|
|
1035
|
+
return fromStateIso(this._selectedDateIso);
|
|
1734
1036
|
}
|
|
1735
1037
|
set selectedDate(value) {
|
|
1736
|
-
|
|
1737
|
-
this._selectedDate = value;
|
|
1738
|
-
} else if (typeof value === "string") {
|
|
1739
|
-
const date = new Date(value);
|
|
1740
|
-
if (!isNaN(date.getTime())) {
|
|
1741
|
-
this._selectedDate = date;
|
|
1742
|
-
} else {
|
|
1743
|
-
this._selectedDate = /* @__PURE__ */ new Date(0);
|
|
1744
|
-
}
|
|
1745
|
-
} else if (value === void 0 || value === null) {
|
|
1746
|
-
this._selectedDate = /* @__PURE__ */ new Date(0);
|
|
1747
|
-
}
|
|
1038
|
+
this._selectedDateIso = toStateIsoOrUnselected(value);
|
|
1748
1039
|
}
|
|
1749
1040
|
get user() {
|
|
1750
1041
|
return this._user;
|
|
@@ -1767,9 +1058,9 @@ class WeekView extends WebComponent {
|
|
|
1767
1058
|
styleName: "wsx-week-view"
|
|
1768
1059
|
});
|
|
1769
1060
|
_defineProperty$1(this, "_autoStyles", styles);
|
|
1770
|
-
_defineProperty$1(this, "
|
|
1061
|
+
_defineProperty$1(this, "_viewDateIso", void 0);
|
|
1771
1062
|
_defineProperty$1(this, "_events", void 0);
|
|
1772
|
-
_defineProperty$1(this, "
|
|
1063
|
+
_defineProperty$1(this, "_selectedDateIso", void 0);
|
|
1773
1064
|
_defineProperty$1(this, "_user", void 0);
|
|
1774
1065
|
_defineProperty$1(this, "_today", void 0);
|
|
1775
1066
|
_defineProperty$1(this, "onDateClick", void 0);
|
|
@@ -1812,10 +1103,10 @@ class WeekView extends WebComponent {
|
|
|
1812
1103
|
const today = /* @__PURE__ */ new Date();
|
|
1813
1104
|
today.setHours(0, 0, 0, 0);
|
|
1814
1105
|
this._today = today;
|
|
1815
|
-
const [
|
|
1816
|
-
Object.defineProperty(this, "
|
|
1817
|
-
get:
|
|
1818
|
-
set:
|
|
1106
|
+
const [_get_viewDateIso, _set_viewDateIso] = this.useState("_viewDateIso", (/* @__PURE__ */ new Date()).toISOString());
|
|
1107
|
+
Object.defineProperty(this, "_viewDateIso", {
|
|
1108
|
+
get: _get_viewDateIso,
|
|
1109
|
+
set: _set_viewDateIso,
|
|
1819
1110
|
enumerable: true,
|
|
1820
1111
|
configurable: true
|
|
1821
1112
|
});
|
|
@@ -1829,10 +1120,10 @@ class WeekView extends WebComponent {
|
|
|
1829
1120
|
enumerable: true,
|
|
1830
1121
|
configurable: true
|
|
1831
1122
|
});
|
|
1832
|
-
const [
|
|
1833
|
-
Object.defineProperty(this, "
|
|
1834
|
-
get:
|
|
1835
|
-
set:
|
|
1123
|
+
const [_get_selectedDateIso, _set_selectedDateIso] = this.useState("_selectedDateIso", UNSELECTED_DATE_ISO);
|
|
1124
|
+
Object.defineProperty(this, "_selectedDateIso", {
|
|
1125
|
+
get: _get_selectedDateIso,
|
|
1126
|
+
set: _set_selectedDateIso,
|
|
1836
1127
|
enumerable: true,
|
|
1837
1128
|
configurable: true
|
|
1838
1129
|
});
|
|
@@ -1854,6 +1145,7 @@ class WeekView extends WebComponent {
|
|
|
1854
1145
|
// ========== 生命周期 ==========
|
|
1855
1146
|
onConnected() {
|
|
1856
1147
|
super.onConnected?.();
|
|
1148
|
+
upgradeProperties(this, UPGRADABLE_PROPS$1);
|
|
1857
1149
|
this.initializeFromAttributes();
|
|
1858
1150
|
}
|
|
1859
1151
|
onAttributeChanged(name, oldValue, newValue) {
|
|
@@ -1908,20 +1200,20 @@ class WeekView extends WebComponent {
|
|
|
1908
1200
|
}
|
|
1909
1201
|
// ========== Getters ==========
|
|
1910
1202
|
get weekDates() {
|
|
1911
|
-
return
|
|
1203
|
+
return getWeekDates(this.viewDate, 0);
|
|
1912
1204
|
}
|
|
1913
1205
|
get hours() {
|
|
1914
1206
|
return Array.from({
|
|
1915
1207
|
length: 24
|
|
1916
|
-
}, (_,
|
|
1208
|
+
}, (_, i) => i);
|
|
1917
1209
|
}
|
|
1918
1210
|
// ========== 渲染 ==========
|
|
1919
1211
|
render() {
|
|
1920
1212
|
return /* @__PURE__ */ jsx("div", { class: "week-view" }, /* @__PURE__ */ jsx("div", { class: "week-view-header" }, /* @__PURE__ */ jsx("div", { class: "week-view-time-gutter" }), this.weekDates.map((date) => {
|
|
1921
1213
|
const normalizedDate = new Date(date);
|
|
1922
1214
|
normalizedDate.setHours(0, 0, 0, 0);
|
|
1923
|
-
this.selectedDate.getTime() !== 0 &&
|
|
1924
|
-
const isToday =
|
|
1215
|
+
this.selectedDate.getTime() !== 0 && isSameDay(normalizedDate, this.selectedDate);
|
|
1216
|
+
const isToday = isSameDay(normalizedDate, this._today);
|
|
1925
1217
|
const dayEvents = sortEventsByTime(getEventsForDate(this.events, normalizedDate));
|
|
1926
1218
|
return /* @__PURE__ */ jsx("div", { class: `week-view-day-header ${isToday ? "today" : ""}`, onClick: () => this.handleDateClick(normalizedDate) }, /* @__PURE__ */ jsx("div", { class: "week-view-day-name" }, ["日", "一", "二", "三", "四", "五", "六"][normalizedDate.getDay()]), /* @__PURE__ */ jsx("div", { class: "week-view-day-date" }, normalizedDate.getDate()), /* @__PURE__ */ jsx("div", { class: "week-view-day-events-count" }, dayEvents.length, " 个事件"));
|
|
1927
1219
|
})), /* @__PURE__ */ jsx("div", { class: "week-view-body" }, /* @__PURE__ */ jsx("div", { class: "week-view-time-gutter" }, this.hours.map((hour) => {
|
|
@@ -1942,7 +1234,7 @@ class WeekView extends WebComponent {
|
|
|
1942
1234
|
const position = calculateEventPosition(event, dayStart, dayEnd);
|
|
1943
1235
|
const eventColor = event.color || "#4285f4";
|
|
1944
1236
|
const eventDescription = event.data?.description;
|
|
1945
|
-
return /* @__PURE__ */ jsx("div", { class: "week-view-event", key: "time-slot-event-" + event.id, style: `top: ${position.top}%; height: ${position.height}%; background-color: ${eventColor}`, onClick: () => this.handleEventClick(event) }, /* @__PURE__ */ jsx("div", { class: "week-view-event-time" },
|
|
1237
|
+
return /* @__PURE__ */ jsx("div", { class: "week-view-event", key: "time-slot-event-" + event.id, style: `top: ${position.top}%; height: ${position.height}%; background-color: ${eventColor}`, onClick: () => this.handleEventClick(event) }, /* @__PURE__ */ jsx("div", { class: "week-view-event-time" }, getTimeString(event.startTime), " ", "-", " ", getTimeString(event.endTime)), /* @__PURE__ */ jsx("div", { class: "week-view-event-title" }, event.title), eventDescription && /* @__PURE__ */ jsx("div", { class: "week-view-event-description" }, eventDescription));
|
|
1946
1238
|
}));
|
|
1947
1239
|
}))));
|
|
1948
1240
|
}
|
|
@@ -1956,7 +1248,7 @@ function _defineProperty(e, r, t) {
|
|
|
1956
1248
|
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
|
|
1957
1249
|
}
|
|
1958
1250
|
function _applyDecs(e, t, r, n, o, a) {
|
|
1959
|
-
function
|
|
1251
|
+
function i(e2, t2, r2) {
|
|
1960
1252
|
return function(n2, o2) {
|
|
1961
1253
|
return r2 && r2(n2), e2[t2].call(n2, o2);
|
|
1962
1254
|
};
|
|
@@ -1969,93 +1261,93 @@ function _applyDecs(e, t, r, n, o, a) {
|
|
|
1969
1261
|
if ("function" != typeof e2 && (n2 || void 0 !== e2)) throw new TypeError(t2 + " must " + (r2 || "be") + " a function" + (n2 ? "" : " or undefined"));
|
|
1970
1262
|
return e2;
|
|
1971
1263
|
}
|
|
1972
|
-
function applyDec(e2, t2, r2, n2, o2, a2, c2, u2,
|
|
1973
|
-
function
|
|
1974
|
-
if (!
|
|
1264
|
+
function applyDec(e2, t2, r2, n2, o2, a2, c2, u2, l2, f2, p2, d, h) {
|
|
1265
|
+
function m(e3) {
|
|
1266
|
+
if (!h(e3)) throw new TypeError("Attempted to access private element on non-instance");
|
|
1975
1267
|
}
|
|
1976
|
-
var
|
|
1977
|
-
if (!
|
|
1268
|
+
var y, v = t2[0], g = t2[3], b = !u2;
|
|
1269
|
+
if (!b) {
|
|
1978
1270
|
r2 || Array.isArray(v) || (v = [v]);
|
|
1979
|
-
var
|
|
1980
|
-
f2 ? (
|
|
1271
|
+
var w = {}, S = [], A = 3 === o2 ? "get" : 4 === o2 || d ? "set" : "value";
|
|
1272
|
+
f2 ? (p2 || d ? w = { get: _setFunctionName(function() {
|
|
1981
1273
|
return g(this);
|
|
1982
1274
|
}, n2, "get"), set: function(e3) {
|
|
1983
1275
|
t2[4](this, e3);
|
|
1984
|
-
} } :
|
|
1276
|
+
} } : w[A] = g, p2 || _setFunctionName(w[A], n2, 2 === o2 ? "" : A)) : p2 || (w = Object.getOwnPropertyDescriptor(e2, n2));
|
|
1985
1277
|
}
|
|
1986
1278
|
for (var P = e2, j = v.length - 1; j >= 0; j -= r2 ? 2 : 1) {
|
|
1987
|
-
var
|
|
1279
|
+
var D = v[j], E = r2 ? v[j - 1] : void 0, I = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][o2], name: n2, metadata: a2, addInitializer: (function(e3, t3) {
|
|
1988
1280
|
if (e3.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
1989
1281
|
s(t3, "An initializer", "be", true), c2.push(t3);
|
|
1990
1282
|
}).bind(null, I) };
|
|
1991
1283
|
try {
|
|
1992
|
-
if (
|
|
1284
|
+
if (b) (y = s(D.call(E, P, O), "class decorators", "return")) && (P = y);
|
|
1993
1285
|
else {
|
|
1994
1286
|
var k, F;
|
|
1995
|
-
O.static =
|
|
1996
|
-
return
|
|
1997
|
-
} : (o2 < 4 && (k =
|
|
1287
|
+
O.static = l2, O.private = f2, f2 ? 2 === o2 ? k = function(e3) {
|
|
1288
|
+
return m(e3), w.value;
|
|
1289
|
+
} : (o2 < 4 && (k = i(w, "get", m)), 3 !== o2 && (F = i(w, "set", m))) : (k = function(e3) {
|
|
1998
1290
|
return e3[n2];
|
|
1999
1291
|
}, (o2 < 2 || 4 === o2) && (F = function(e3, t3) {
|
|
2000
1292
|
e3[n2] = t3;
|
|
2001
1293
|
}));
|
|
2002
|
-
var N = O.access = { has: f2 ?
|
|
1294
|
+
var N = O.access = { has: f2 ? h.bind() : function(e3) {
|
|
2003
1295
|
return n2 in e3;
|
|
2004
1296
|
} };
|
|
2005
|
-
if (k && (N.get = k), F && (N.set = F), P =
|
|
2006
|
-
if ("object" == typeof P && P) (
|
|
1297
|
+
if (k && (N.get = k), F && (N.set = F), P = D.call(E, d ? { get: w.get, set: w.set } : w[A], O), d) {
|
|
1298
|
+
if ("object" == typeof P && P) (y = s(P.get, "accessor.get")) && (w.get = y), (y = s(P.set, "accessor.set")) && (w.set = y), (y = s(P.init, "accessor.init")) && S.push(y);
|
|
2007
1299
|
else if (void 0 !== P) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
2008
|
-
} else s(P, (
|
|
1300
|
+
} else s(P, (p2 ? "field" : "method") + " decorators", "return") && (p2 ? S.push(P) : w[A] = P);
|
|
2009
1301
|
}
|
|
2010
1302
|
} finally {
|
|
2011
1303
|
I.v = true;
|
|
2012
1304
|
}
|
|
2013
1305
|
}
|
|
2014
|
-
return (
|
|
2015
|
-
for (var r3 =
|
|
1306
|
+
return (p2 || d) && u2.push(function(e3, t3) {
|
|
1307
|
+
for (var r3 = S.length - 1; r3 >= 0; r3--) t3 = S[r3].call(e3, t3);
|
|
2016
1308
|
return t3;
|
|
2017
|
-
}),
|
|
1309
|
+
}), p2 || b || (f2 ? d ? u2.push(i(w, "get"), i(w, "set")) : u2.push(2 === o2 ? w[A] : i.call.bind(w[A])) : Object.defineProperty(e2, n2, w)), P;
|
|
2018
1310
|
}
|
|
2019
1311
|
function u(e2, t2) {
|
|
2020
1312
|
return Object.defineProperty(e2, Symbol.metadata || /* @__PURE__ */ Symbol.for("Symbol.metadata"), { configurable: true, enumerable: true, value: t2 });
|
|
2021
1313
|
}
|
|
2022
|
-
if (arguments.length >= 6) var
|
|
2023
|
-
var f = Object.create(null ==
|
|
2024
|
-
var o2, a2,
|
|
1314
|
+
if (arguments.length >= 6) var l = a[Symbol.metadata || /* @__PURE__ */ Symbol.for("Symbol.metadata")];
|
|
1315
|
+
var f = Object.create(null == l ? null : l), p = (function(e2, t2, r2, n2) {
|
|
1316
|
+
var o2, a2, i2 = [], s2 = function(t3) {
|
|
2025
1317
|
return _checkInRHS(t3) === e2;
|
|
2026
1318
|
}, u2 = /* @__PURE__ */ new Map();
|
|
2027
|
-
function
|
|
2028
|
-
e3 &&
|
|
1319
|
+
function l2(e3) {
|
|
1320
|
+
e3 && i2.push(c.bind(null, e3));
|
|
2029
1321
|
}
|
|
2030
1322
|
for (var f2 = 0; f2 < t2.length; f2++) {
|
|
2031
|
-
var
|
|
2032
|
-
if (Array.isArray(
|
|
2033
|
-
var
|
|
2034
|
-
if (!g && !
|
|
2035
|
-
var
|
|
2036
|
-
if (true ===
|
|
2037
|
-
u2.set(
|
|
1323
|
+
var p2 = t2[f2];
|
|
1324
|
+
if (Array.isArray(p2)) {
|
|
1325
|
+
var d = p2[1], h = p2[2], m = p2.length > 3, y = 16 & d, v = !!(8 & d), g = 0 == (d &= 7), b = h + "/" + v;
|
|
1326
|
+
if (!g && !m) {
|
|
1327
|
+
var w = u2.get(b);
|
|
1328
|
+
if (true === w || 3 === w && 4 !== d || 4 === w && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h);
|
|
1329
|
+
u2.set(b, !(d > 2) || d);
|
|
2038
1330
|
}
|
|
2039
|
-
applyDec(v ? e2 : e2.prototype,
|
|
1331
|
+
applyDec(v ? e2 : e2.prototype, p2, y, m ? "#" + h : _toPropertyKey(h), d, n2, v ? a2 = a2 || [] : o2 = o2 || [], i2, v, m, g, 1 === d, v && m ? s2 : r2);
|
|
2040
1332
|
}
|
|
2041
1333
|
}
|
|
2042
|
-
return
|
|
1334
|
+
return l2(o2), l2(a2), i2;
|
|
2043
1335
|
})(e, t, o, f);
|
|
2044
|
-
return r.length || u(e, f), { e:
|
|
1336
|
+
return r.length || u(e, f), { e: p, get c() {
|
|
2045
1337
|
var t2 = [];
|
|
2046
1338
|
return r.length && [u(applyDec(e, [r], n, e.name, 5, f, t2), f), c.bind(null, t2, e)];
|
|
2047
1339
|
} };
|
|
2048
1340
|
}
|
|
2049
1341
|
function _toPropertyKey(t) {
|
|
2050
|
-
var
|
|
2051
|
-
return "symbol" == typeof
|
|
1342
|
+
var i = _toPrimitive(t, "string");
|
|
1343
|
+
return "symbol" == typeof i ? i : i + "";
|
|
2052
1344
|
}
|
|
2053
1345
|
function _toPrimitive(t, r) {
|
|
2054
1346
|
if ("object" != typeof t || !t) return t;
|
|
2055
1347
|
var e = t[Symbol.toPrimitive];
|
|
2056
1348
|
if (void 0 !== e) {
|
|
2057
|
-
var
|
|
2058
|
-
if ("object" != typeof
|
|
1349
|
+
var i = e.call(t, r);
|
|
1350
|
+
if ("object" != typeof i) return i;
|
|
2059
1351
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
2060
1352
|
}
|
|
2061
1353
|
return String(t);
|
|
@@ -2072,6 +1364,8 @@ function _checkInRHS(e) {
|
|
|
2072
1364
|
if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null"));
|
|
2073
1365
|
return e;
|
|
2074
1366
|
}
|
|
1367
|
+
const UPGRADABLE_PROPS = ["view", "date", "defaultView", "events", "user", "eventDSL", "eventRuntime"];
|
|
1368
|
+
const VALID_VIEWS = ["month", "week", "day"];
|
|
2075
1369
|
_classDecs = [autoRegister({
|
|
2076
1370
|
tagName: "wsx-calendar"
|
|
2077
1371
|
})];
|
|
@@ -2082,13 +1376,40 @@ class Calendar extends WebComponent {
|
|
|
2082
1376
|
return ["view", "date", "events", "user"];
|
|
2083
1377
|
}
|
|
2084
1378
|
// ========== 内部状态(@state 装饰器) ==========
|
|
1379
|
+
// 日期存 ISO:WSX reactive Proxy 会破坏 Date 品牌方法
|
|
2085
1380
|
// ========== 属性访问器(支持 property 和 attribute 两种设置方式) ==========
|
|
1381
|
+
get currentDate() {
|
|
1382
|
+
return fromStateIso(this._currentDateIso);
|
|
1383
|
+
}
|
|
1384
|
+
set currentDate(value) {
|
|
1385
|
+
this._currentDateIso = toStateIso(value);
|
|
1386
|
+
}
|
|
2086
1387
|
get defaultView() {
|
|
2087
1388
|
return this.currentView;
|
|
2088
1389
|
}
|
|
2089
1390
|
set defaultView(value) {
|
|
2090
1391
|
this.currentView = value;
|
|
2091
1392
|
}
|
|
1393
|
+
/** 与 observedAttributes 的 "view" 对应的 property(框架包装器使用) */
|
|
1394
|
+
get view() {
|
|
1395
|
+
return this.currentView;
|
|
1396
|
+
}
|
|
1397
|
+
set view(value) {
|
|
1398
|
+
if (VALID_VIEWS.includes(value)) {
|
|
1399
|
+
this.currentView = value;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
/** 与 observedAttributes 的 "date" 对应的 property(框架包装器使用) */
|
|
1403
|
+
get date() {
|
|
1404
|
+
return this.currentDate;
|
|
1405
|
+
}
|
|
1406
|
+
set date(value) {
|
|
1407
|
+
try {
|
|
1408
|
+
this.currentDate = value;
|
|
1409
|
+
} catch {
|
|
1410
|
+
console.error("Invalid date value:", value);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
2092
1413
|
get eventDSL() {
|
|
2093
1414
|
return this._eventDSL;
|
|
2094
1415
|
}
|
|
@@ -2117,10 +1438,11 @@ class Calendar extends WebComponent {
|
|
|
2117
1438
|
}
|
|
2118
1439
|
set events(value) {
|
|
2119
1440
|
if (Array.isArray(value)) {
|
|
2120
|
-
this._events = value;
|
|
1441
|
+
this._events = normalizeEventsForState(value);
|
|
2121
1442
|
} else if (typeof value === "string") {
|
|
2122
1443
|
try {
|
|
2123
|
-
|
|
1444
|
+
const parsed = JSON.parse(value);
|
|
1445
|
+
this._events = Array.isArray(parsed) ? normalizeEventsForState(parsed) : [];
|
|
2124
1446
|
} catch (e) {
|
|
2125
1447
|
console.error("Invalid events JSON:", value);
|
|
2126
1448
|
this._events = [];
|
|
@@ -2150,7 +1472,7 @@ class Calendar extends WebComponent {
|
|
|
2150
1472
|
});
|
|
2151
1473
|
_defineProperty(this, "_autoStyles", styles$3);
|
|
2152
1474
|
_defineProperty(this, "currentView", void 0);
|
|
2153
|
-
_defineProperty(this, "
|
|
1475
|
+
_defineProperty(this, "_currentDateIso", void 0);
|
|
2154
1476
|
_defineProperty(this, "_events", void 0);
|
|
2155
1477
|
_defineProperty(this, "_user", void 0);
|
|
2156
1478
|
_defineProperty(this, "_eventDSL", void 0);
|
|
@@ -2186,10 +1508,10 @@ class Calendar extends WebComponent {
|
|
|
2186
1508
|
enumerable: true,
|
|
2187
1509
|
configurable: true
|
|
2188
1510
|
});
|
|
2189
|
-
const [
|
|
2190
|
-
Object.defineProperty(this, "
|
|
2191
|
-
get:
|
|
2192
|
-
set:
|
|
1511
|
+
const [_get_currentDateIso, _set_currentDateIso] = this.useState("_currentDateIso", (/* @__PURE__ */ new Date()).toISOString());
|
|
1512
|
+
Object.defineProperty(this, "_currentDateIso", {
|
|
1513
|
+
get: _get_currentDateIso,
|
|
1514
|
+
set: _set_currentDateIso,
|
|
2193
1515
|
enumerable: true,
|
|
2194
1516
|
configurable: true
|
|
2195
1517
|
});
|
|
@@ -2228,6 +1550,7 @@ class Calendar extends WebComponent {
|
|
|
2228
1550
|
// ========== Web Components 生命周期 ==========
|
|
2229
1551
|
onConnected() {
|
|
2230
1552
|
super.onConnected?.();
|
|
1553
|
+
upgradeProperties(this, UPGRADABLE_PROPS);
|
|
2231
1554
|
this.setupEventListeners();
|
|
2232
1555
|
}
|
|
2233
1556
|
onDisconnected() {
|
|
@@ -2298,7 +1621,7 @@ class Calendar extends WebComponent {
|
|
|
2298
1621
|
return /* @__PURE__ */ jsx("div", { class: "calendar" }, this.renderToolbar(), this.renderView());
|
|
2299
1622
|
}
|
|
2300
1623
|
renderToolbar() {
|
|
2301
|
-
return /* @__PURE__ */ jsx("div", { class: "calendar-toolbar" }, /* @__PURE__ */ jsx("div", { class: "calendar-toolbar-left" }, /* @__PURE__ */ jsx("button", { class: "calendar-nav-button", onClick: () => this.handleNavigate(-1), "aria-label": "上一页"
|
|
1624
|
+
return /* @__PURE__ */ jsx("div", { class: "calendar-toolbar" }, /* @__PURE__ */ jsx("div", { class: "calendar-toolbar-left" }, /* @__PURE__ */ jsx("button", { class: "calendar-nav-button", onClick: () => this.handleNavigate(-1), "aria-label": "上一页" }, /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24" }, /* @__PURE__ */ jsx("path", { d: "M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" }))), /* @__PURE__ */ jsx("button", { class: "calendar-nav-button", onClick: () => this.handleNavigate(1), "aria-label": "下一页" }, /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24" }, /* @__PURE__ */ jsx("path", { d: "M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" }))), /* @__PURE__ */ jsx("button", { class: "calendar-today-button", onClick: () => this.handleToday() }, "今天"), /* @__PURE__ */ jsx("div", { class: "calendar-toolbar-date" }, this.formatViewDate())), /* @__PURE__ */ jsx("div", { class: "calendar-toolbar-right" }, /* @__PURE__ */ jsx("div", { class: "calendar-view-buttons" }, /* @__PURE__ */ jsx("button", { class: `calendar-view-button ${this.currentView === "month" ? "active" : ""}`, onClick: () => this.handleViewChange("month") }, "月"), /* @__PURE__ */ jsx("button", { class: `calendar-view-button ${this.currentView === "week" ? "active" : ""}`, onClick: () => this.handleViewChange("week") }, "周"), /* @__PURE__ */ jsx("button", { class: `calendar-view-button ${this.currentView === "day" ? "active" : ""}`, onClick: () => this.handleViewChange("day") }, "日"))));
|
|
2302
1625
|
}
|
|
2303
1626
|
renderView() {
|
|
2304
1627
|
const view = this.currentView || "month";
|
|
@@ -2334,8 +1657,8 @@ class Calendar extends WebComponent {
|
|
|
2334
1657
|
case "month":
|
|
2335
1658
|
return `${date.getFullYear()}年${date.getMonth() + 1}月`;
|
|
2336
1659
|
case "week":
|
|
2337
|
-
const weekStart =
|
|
2338
|
-
const weekEnd =
|
|
1660
|
+
const weekStart = getWeekDates(date)[0];
|
|
1661
|
+
const weekEnd = getWeekDates(date)[6];
|
|
2339
1662
|
return `${weekStart.getMonth() + 1}/${weekStart.getDate()} - ${weekEnd.getMonth() + 1}/${weekEnd.getDate()}`;
|
|
2340
1663
|
case "day":
|
|
2341
1664
|
return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`;
|