odant-work 1.0.72 → 1.0.73

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.
@@ -1,296 +1,482 @@
1
- export default {
2
- }
3
-
4
- const pad = n => String(n).padStart(2, '0');
5
-
6
- function allDayBounds(start, end) {
7
- const s = new Date(start);
8
- const t = new Date(end);
9
- s.setHours(0, 0, 0, 0);
10
- t.setHours(0, 0, 0, 0);
11
- if (t <= s)
12
- t.setDate(s.getDate() + 1);
13
- return {
14
- start: s.toISOTimezoneString(),
15
- end: t.toISOTimezoneString()
16
- };
17
- }
18
-
19
- function applyAllDayTimes(ev) {
20
- const s = new Date(ev.start);
21
- if (ev.allDay) {
22
- const bounds = allDayBounds(ev.start, ev.end);
23
- ev.start = bounds.start;
24
- ev.end = bounds.end;
25
- return;
26
- }
27
- if (s.getHours() === 0 && s.getMinutes() === 0) {
28
- s.setHours(9, 0, 0, 0);
29
- ev.start = s.toISOTimezoneString();
30
- ev.end = new Date(s.getTime() + 30 * 60 * 1000).toISOTimezoneString();
31
- }
32
- }
33
-
34
- ODA({
35
- is: 'calendar-form',
36
- imports: 'oda//checkbox',
37
- template: /* html */`
38
- <style>
39
- :host {
40
- @apply --vertical;
41
- padding: 8px;
42
- gap: 8px;
43
- min-width: 320px;
44
- overflow: auto;
45
- }
46
- fieldset {
47
- border: 1px solid var(--subtle-border);
48
- border-radius: var(--radius-s);
49
- padding: 2px 8px;
50
- margin: 0px;
51
- min-width: 0px;
52
- }
53
- legend {
54
- font-size: small;
55
- padding: 0px 4px;
56
- color: var(--muted-color);
57
- }
58
- input, textarea {
59
- border: none;
60
- outline: none;
61
- background-color: transparent;
62
- color: inherit;
63
- font-family: inherit;
64
- font-size: inherit;
65
- width: 100%;
66
- padding: 4px 0px;
67
- box-sizing: border-box;
68
- }
69
- textarea {
70
- resize: vertical;
71
- min-height: 60px;
72
- }
73
- .row {
74
- @apply --horizontal;
75
- gap: 8px;
76
- }
77
- .row > fieldset {
78
- @apply --flex;
79
- }
80
- .box {
81
- padding: 4px;
82
- border: 1px solid var(--subtle-border);
83
- }
84
- .all-day-toggle {
85
- align-items: center;
86
- gap: 4px;
87
- }
88
- </style>
89
- <div ~for="events" class="box" light>
90
- <fieldset>
91
- <legend>Название</legend>
92
- <input id="summary" :value="$for.item.summary || ''" autofocus @input="(e) => on_input(e, $for.index)">
93
- </fieldset>
94
- <label class="all-day-toggle" horizontal>
95
- <oda-checkbox :value="$for.item.allDay" @value-changed="(e) => on_all_day(e, $for.index)"></oda-checkbox>
96
- <span>Весь день</span>
97
- </label>
98
- <div class="row">
99
- <fieldset>
100
- <legend>Начало</legend>
101
- <input id="start" type="datetime-local" :value="toDatetimeLocalInput($for.item.start)" @input="(e) => on_input(e, $for.index)">
102
- </fieldset>
103
- <fieldset>
104
- <legend>Окончание</legend>
105
- <input id="end" type="datetime-local" :value="toDatetimeLocalInput($for.item.end)" @input="(e) => on_input(e, $for.index)">
106
- </fieldset>
107
- </div>
108
- <fieldset>
109
- <legend>Место</legend>
110
- <input id="location" :value="$for.item.location || ''" @input="(e) => on_input(e, $for.index)">
111
- </fieldset>
112
- <fieldset>
113
- <legend>Описание</legend>
114
- <textarea id="description" :value="$for.item.description || ''" @input="(e) => on_input(e, $for.index)"></textarea>
115
- </fieldset>
116
- </div>
117
- <label ~if="canCancel" class="all-day-toggle" horizontal>
118
- <oda-checkbox ::value="cancelled"></oda-checkbox>
119
- <span>Отменить встречу</span>
120
- </label>
121
- `,
122
- /** Offset-ISO / Date → value for datetime-local input (no zone) */
123
- toDatetimeLocalInput(date) {
124
- const d = date instanceof Date ? date : new Date(date);
125
- if (isNaN(d))
126
- return '';
127
- return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
128
- + `T${pad(d.getHours())}:${pad(d.getMinutes())}`;
129
- },
130
- /** Persist shape from form event (start/end already offset-ISO) */
131
- eventToPersist(ev) {
132
- let start = ev.start || (ev.startStr ? new Date(ev.startStr).toISOTimezoneString() : '');
133
- let end = ev.end || (ev.endStr ? new Date(ev.endStr).toISOTimezoneString() : '');
134
- const allDay = !!ev.allDay;
135
- if (allDay && start && end) {
136
- const bounds = allDayBounds(start, end);
137
- start = bounds.start;
138
- end = bounds.end;
139
- }
140
- const result = {
141
- summary: ev.summary ?? '',
142
- location: ev.location ?? '',
143
- description: ev.description ?? '',
144
- start,
145
- end,
146
- allDay
147
- };
148
- // служебные поля встречи не теряем при правке
149
- for (const key of ['uid', 'status', 'time'])
150
- if (ev[key] != null)
151
- result[key] = ev[key];
152
- return result;
153
- },
154
- on_input(e, i) {
155
- e.stopPropagation();
156
- const id = e.target.id;
157
- if (id === 'start' || id === 'end')
158
- this.events[i][id] = new Date(e.target.value).toISOTimezoneString();
159
- else
160
- this.events[i][id] = e.target.value;
161
- this.commitEvents();
162
- },
163
- on_all_day(e, i) {
164
- e.stopPropagation();
165
- const ev = this.events[i];
166
- const checked = !!e.detail.value;
167
- if (!!ev.allDay === checked)
168
- return;
169
- ev.allDay = checked;
170
- applyAllDayTimes(ev);
171
- this.events = [...this.events];
172
- this.commitEvents();
173
- },
174
- commitEvents() {
175
- const body = JSON.stringify(
176
- this.events.length === 1
177
- ? this.eventToPersist(this.events[0])
178
- : this.events.map(ev => this.eventToPersist(ev))
179
- );
180
- if (this.$item && (!this.$item.body || (this.$item.body !== body))) {
181
- this.$item.body = body;
182
- this.$item.isChanged = true;
183
- }
184
- },
185
- events: undefined,
186
- /** Показать флажок отмены (только правка существующей встречи из календаря) */
187
- canCancel: false,
188
- cancelled: false,
189
- // body: {
190
- // $def: '',
191
- // set(n) {
192
- // if (n)
193
- // this.events = this.parseICSSimple(n);
194
- // }
195
- // },
196
- set $item(n) {
197
- if (n) {
198
- this.async(async () => {
199
- let content = await n.load();
200
- if (typeof content === 'string')
201
- content = JSON.parse(content);
202
- this.cancelled = content?.status === 'cancelled';
203
- this.events = [content];
204
- })
205
- }
206
- },
207
- hydrateEvent(raw) {
208
- const ev = {
209
- summary: raw.summary ?? '',
210
- location: raw.location ?? '',
211
- description: raw.description ?? '',
212
- allDay: !!raw.allDay,
213
- start: '',
214
- end: ''
215
- };
216
- if (raw.start)
217
- ev.start = /[Zz]|[+-]\d{2}:\d{2}$/.test(raw.start) ? raw.start : new Date(raw.start).toISOTimezoneString();
218
- else if (raw.startStr)
219
- ev.start = new Date(raw.startStr).toISOTimezoneString();
220
- if (raw.end)
221
- ev.end = /[Zz]|[+-]\d{2}:\d{2}$/.test(raw.end) ? raw.end : new Date(raw.end).toISOTimezoneString();
222
- else if (raw.endStr)
223
- ev.end = new Date(raw.endStr).toISOTimezoneString();
224
- return ev;
225
- },
226
- /** ICS DTSTART/DTEND → offset-ISO. Floating = local; Z = UTC instant. */
227
- parseICSDate(dateStr) {
228
- if (!dateStr)
229
- return '';
230
- dateStr = dateStr.replace(/\\/g, '');
231
- if (dateStr.includes('-') && dateStr.includes('T'))
232
- return new Date(dateStr).toISOTimezoneString();
233
- const utc = /Z$/i.test(dateStr);
234
- const compact = dateStr.replace(/Z$/i, '');
235
- if (!/^\d{8}(T\d{6})?$/.test(compact))
236
- return new Date(dateStr);
237
- const year = parseInt(compact.substring(0, 4), 10);
238
- const month = parseInt(compact.substring(4, 6), 10) - 1;
239
- const day = parseInt(compact.substring(6, 8), 10);
240
- const hour = parseInt(compact.substring(9, 11) || '0', 10);
241
- const minute = parseInt(compact.substring(11, 13) || '0', 10);
242
- const second = parseInt(compact.substring(13, 15) || '0', 10);
243
- const date = utc
244
- ? new Date(Date.UTC(year, month, day, hour, minute, second))
245
- : new Date(year, month, day, hour, minute, second);
246
- return date.toISOTimezoneString();
247
- },
248
- parseICSSimple(icsContent) {
249
- const lines = icsContent.split(/\r?\n/);
250
- if (lines[0].startsWith('[')) {
251
- const arr = JSON.parse(icsContent);
252
- return arr.map(this.hydrateEvent);
253
- }
254
- if (lines[0].startsWith('{'))
255
- return [this.hydrateEvent(JSON.parse(icsContent))];
256
-
257
- const events = [];
258
- let currentEvent = null;
259
-
260
- for (const line of lines) {
261
- if (line.startsWith('BEGIN:VEVENT')) {
262
- currentEvent = {
263
- summary: '',
264
- location: '',
265
- description: '',
266
- allDay: false,
267
- start: '',
268
- end: ''
269
- };
270
- continue;
271
- }
272
-
273
- if (line.startsWith('END:VEVENT') && currentEvent) {
274
- events.push(currentEvent);
275
- currentEvent = null;
276
- continue;
277
- }
278
-
279
- if (!currentEvent) continue;
280
-
281
- const colonIndex = line.indexOf(':');
282
- if (colonIndex === -1) continue;
283
-
284
- const key = line.substring(0, colonIndex).split(';')[0];
285
- const value = line.substring(colonIndex + 1);
286
-
287
- if (key === 'SUMMARY') currentEvent.summary = value;
288
- else if (key === 'LOCATION') currentEvent.location = value;
289
- else if (key === 'DESCRIPTION') currentEvent.description = value;
290
- else if (key === 'DTSTART') currentEvent.start = this.parseICSDate(value);
291
- else if (key === 'DTEND') currentEvent.end = this.parseICSDate(value);
292
- }
293
-
294
- return events;
295
- }
296
- })
1
+ export default {
2
+ }
3
+
4
+ const pad = n => String(n).padStart(2, '0');
5
+
6
+ function allDayBounds(start, end) {
7
+ const s = new Date(start);
8
+ const t = new Date(end);
9
+ s.setHours(0, 0, 0, 0);
10
+ t.setHours(0, 0, 0, 0);
11
+ if (t <= s)
12
+ t.setDate(s.getDate() + 1);
13
+ return {
14
+ start: s.toISOTimezoneString(),
15
+ end: t.toISOTimezoneString()
16
+ };
17
+ }
18
+
19
+ function applyAllDayTimes(ev) {
20
+ const s = new Date(ev.start);
21
+ if (ev.allDay) {
22
+ const bounds = allDayBounds(ev.start, ev.end);
23
+ ev.start = bounds.start;
24
+ ev.end = bounds.end;
25
+ return;
26
+ }
27
+ if (s.getHours() === 0 && s.getMinutes() === 0) {
28
+ s.setHours(9, 0, 0, 0);
29
+ ev.start = s.toISOTimezoneString();
30
+ ev.end = new Date(s.getTime() + 60 * 60 * 1000).toISOTimezoneString();
31
+ }
32
+ }
33
+
34
+ const CATEGORIES = [
35
+ { id: 'meeting', label: 'Встреча', color: '#2563eb' },
36
+ { id: 'important', label: 'Важное', color: '#dc2626' },
37
+ { id: 'personal', label: 'Личное', color: '#7c3aed' },
38
+ { id: 'client', label: 'Клиент', color: '#059669' },
39
+ ];
40
+
41
+ ODA({
42
+ is: 'calendar-form',
43
+ imports: 'oda//checkbox, oda//icon, oda//button',
44
+ template: /* html */`
45
+ <style>
46
+ :host {
47
+ @apply --vertical;
48
+ padding: 10px 14px;
49
+ gap: 10px;
50
+ min-width: 420px;
51
+ max-width: 560px;
52
+ max-height: 75vh;
53
+ overflow-y: auto;
54
+ font-size: 13px;
55
+ color: var(--content-color);
56
+ }
57
+ fieldset {
58
+ border: 1px solid var(--subtle-border, #cbd5e1);
59
+ border-radius: 8px;
60
+ padding: 3px 10px 6px;
61
+ margin: 0;
62
+ min-width: 0;
63
+ background: var(--content-background);
64
+ }
65
+ legend {
66
+ font-size: 11.5px;
67
+ padding: 0 4px;
68
+ color: var(--muted-color);
69
+ }
70
+ input, textarea, select {
71
+ border: none;
72
+ outline: none;
73
+ background-color: transparent;
74
+ color: inherit;
75
+ font-family: inherit;
76
+ font-size: 13px;
77
+ width: 100%;
78
+ padding: 3px 0;
79
+ box-sizing: border-box;
80
+ }
81
+ textarea {
82
+ resize: vertical;
83
+ min-height: 64px;
84
+ }
85
+ .row {
86
+ @apply --horizontal;
87
+ gap: 10px;
88
+ align-items: stretch;
89
+ }
90
+ .row > fieldset {
91
+ @apply --flex;
92
+ }
93
+ .box {
94
+ @apply --vertical;
95
+ gap: 10px;
96
+ }
97
+ .all-day-toggle {
98
+ @apply --horizontal;
99
+ align-items: center;
100
+ gap: 6px;
101
+ cursor: pointer;
102
+ font-size: 13px;
103
+ }
104
+ .cats {
105
+ @apply --horizontal;
106
+ gap: 6px;
107
+ flex-wrap: wrap;
108
+ padding-top: 2px;
109
+ }
110
+ .cat-chip {
111
+ @apply --horizontal;
112
+ align-items: center;
113
+ gap: 5px;
114
+ padding: 4px 10px;
115
+ border-radius: 999px;
116
+ border: 1px solid var(--subtle-border, #cbd5e1);
117
+ cursor: pointer;
118
+ font-size: 12px;
119
+ background: var(--subtle-background, #f8fafc);
120
+ user-select: none;
121
+ }
122
+ .cat-chip.active {
123
+ border-color: var(--accent-color, #2563eb);
124
+ background: color-mix(in srgb, var(--accent-color, #2563eb) 10%, var(--content-background, #fff));
125
+ font-weight: 600;
126
+ }
127
+ .cat-dot {
128
+ width: 8px;
129
+ height: 8px;
130
+ border-radius: 50%;
131
+ }
132
+ .att-list {
133
+ display: flex;
134
+ flex-wrap: wrap;
135
+ gap: 5px;
136
+ max-height: 112px;
137
+ overflow-y: auto;
138
+ padding: 4px 0 2px;
139
+ }
140
+ .att-chip {
141
+ @apply --horizontal;
142
+ align-items: center;
143
+ gap: 4px;
144
+ padding: 3px 8px;
145
+ border-radius: 999px;
146
+ border: 1px solid var(--subtle-border, #cbd5e1);
147
+ font-size: 12px;
148
+ cursor: pointer;
149
+ background: var(--subtle-background, #f8fafc);
150
+ }
151
+ .att-chip.selected {
152
+ border-color: var(--accent-color, #2563eb);
153
+ background: color-mix(in srgb, var(--accent-color, #2563eb) 14%, var(--content-background, #fff));
154
+ color: var(--accent-color, #2563eb);
155
+ font-weight: 600;
156
+ }
157
+ .att-search {
158
+ border-bottom: 1px solid var(--subtle-border, #e2e8f0) !important;
159
+ margin-bottom: 4px;
160
+ font-size: 12.5px;
161
+ }
162
+ .cancel-row {
163
+ @apply --horizontal;
164
+ align-items: center;
165
+ gap: 6px;
166
+ padding: 6px 8px;
167
+ border-radius: 8px;
168
+ border: 1px solid color-mix(in srgb, #dc2626 30%, transparent);
169
+ background: color-mix(in srgb, #dc2626 6%, transparent);
170
+ color: #b91c1c;
171
+ cursor: pointer;
172
+ }
173
+ </style>
174
+ <div ~for="events" class="box">
175
+ <fieldset>
176
+ <legend>Название</legend>
177
+ <input id="summary" placeholder="Например: Планёрка отдела" :value="$for.item.summary || ''" autofocus @input="(e) => on_input(e, $for.index)">
178
+ </fieldset>
179
+
180
+ <div class="row" style="align-items: center; justify-content: space-between;">
181
+ <label class="all-day-toggle">
182
+ <oda-checkbox :value="$for.item.allDay" @value-changed="(e) => on_all_day(e, $for.index)"></oda-checkbox>
183
+ <span>Весь день</span>
184
+ </label>
185
+ <div class="cats">
186
+ <span ~for="categories" class="cat-chip"
187
+ ~class="{ active: ($for.$for.item.category || 'meeting') === $for.item.id }"
188
+ @tap="setCategory($for.$for.index, $for.item.id)">
189
+ <span class="cat-dot" :style="'background:' + $for.item.color"></span>
190
+ <span>{{$for.item.label}}</span>
191
+ </span>
192
+ </div>
193
+ </div>
194
+
195
+ <div class="row">
196
+ <fieldset>
197
+ <legend>Начало</legend>
198
+ <input id="start" :type="$for.item.allDay ? 'date' : 'datetime-local'" :value="$for.item.allDay ? toDateInput($for.item.start) : toDatetimeLocalInput($for.item.start)" @input="(e) => on_input(e, $for.index)">
199
+ </fieldset>
200
+ <fieldset>
201
+ <legend>Окончание</legend>
202
+ <input id="end" :type="$for.item.allDay ? 'date' : 'datetime-local'" :value="$for.item.allDay ? toDateInput($for.item.end, true) : toDatetimeLocalInput($for.item.end)" @input="(e) => on_input(e, $for.index)">
203
+ </fieldset>
204
+ </div>
205
+
206
+ <div class="row">
207
+ <fieldset>
208
+ <legend>Повтор</legend>
209
+ <select id="recurrence" :value="$for.item.recurrence || 'none'" @change="(e) => on_input(e, $for.index)">
210
+ <option value="none">Не повторяется</option>
211
+ <option value="daily">Каждый день</option>
212
+ <option value="weekly">Каждую неделю</option>
213
+ <option value="monthly">Каждый месяц</option>
214
+ <option value="yearly">Каждый год</option>
215
+ </select>
216
+ </fieldset>
217
+ <fieldset>
218
+ <legend>Напоминание</legend>
219
+ <select id="reminderMin" :value="String($for.item.reminderMin || 0)" @change="(e) => on_input(e, $for.index)">
220
+ <option value="0">Без напоминания</option>
221
+ <option value="15">За 15 минут</option>
222
+ <option value="60">За 1 час</option>
223
+ <option value="1440">За 1 день</option>
224
+ </select>
225
+ </fieldset>
226
+ </div>
227
+
228
+ <fieldset>
229
+ <legend>Место или ссылка на созвон</legend>
230
+ <input id="location" placeholder="Переговорная / ссылка на встречу" :value="$for.item.location || ''" @input="(e) => on_input(e, $for.index)">
231
+ </fieldset>
232
+
233
+ <fieldset ~if="contacts.length">
234
+ <legend>Участники из команды ({{($for.item.attendees || []).length}})</legend>
235
+ <input class="att-search" type="search" placeholder="Фильтр коллег…" :value="attFilter" @input="attFilter = $event.target.value">
236
+ <div class="att-list">
237
+ <span ~for="filteredContacts" class="att-chip"
238
+ ~class="{ selected: ($for.$for.item.attendees || []).includes($for.item.id) }"
239
+ @tap="toggleAttendee($for.$for.index, $for.item.id)">
240
+ <span>{{$for.item.label || $for.item.id}}</span>
241
+ </span>
242
+ </div>
243
+ </fieldset>
244
+
245
+ <fieldset>
246
+ <legend>Внешние email участников (через запятую)</legend>
247
+ <input id="externalEmails" placeholder="partner@company.ru" :value="($for.item.externalEmails || []).join(', ')" @input="(e) => on_external(e, $for.index)">
248
+ </fieldset>
249
+
250
+ <fieldset>
251
+ <legend>Описание и повестка</legend>
252
+ <textarea id="description" placeholder="Вопросы для обсуждения, ссылки, заметки…" :value="$for.item.description || ''" @input="(e) => on_input(e, $for.index)"></textarea>
253
+ </fieldset>
254
+ </div>
255
+
256
+ <label ~if="canCancel" class="cancel-row">
257
+ <oda-checkbox ::value="cancelled"></oda-checkbox>
258
+ <span>Отменить эту встречу (удалится из сетки календаря)</span>
259
+ </label>
260
+ `,
261
+ categories: CATEGORIES,
262
+ contacts: [],
263
+ attFilter: '',
264
+ get filteredContacts() {
265
+ const q = String(this.attFilter || '').trim().toLowerCase();
266
+ if (!q)
267
+ return this.contacts;
268
+ return this.contacts.filter(c => String(c.label || c.id || '').toLowerCase().includes(q));
269
+ },
270
+ async attached() {
271
+ if (!this.contacts?.length && typeof globalThis.WORK?.visible_contacts === 'function') {
272
+ try {
273
+ const list = await globalThis.WORK.visible_contacts();
274
+ if (Array.isArray(list))
275
+ this.contacts = list.filter(c => c && c.id && !c.external);
276
+ }
277
+ catch { /* ignore */ }
278
+ }
279
+ },
280
+ toDatetimeLocalInput(date) {
281
+ const d = date instanceof Date ? date : new Date(date);
282
+ if (isNaN(d))
283
+ return '';
284
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
285
+ + `T${pad(d.getHours())}:${pad(d.getMinutes())}`;
286
+ },
287
+ toDateInput(date, inclusiveEnd = false) {
288
+ const d = date instanceof Date ? new Date(date.getTime()) : new Date(date);
289
+ if (isNaN(d))
290
+ return '';
291
+ if (inclusiveEnd && d.getHours() === 0 && d.getMinutes() === 0)
292
+ d.setDate(d.getDate() - 1);
293
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
294
+ },
295
+ eventToPersist(ev) {
296
+ let start = ev.start || (ev.startStr ? new Date(ev.startStr).toISOTimezoneString() : '');
297
+ let end = ev.end || (ev.endStr ? new Date(ev.endStr).toISOTimezoneString() : '');
298
+ const allDay = !!ev.allDay;
299
+ if (allDay && start && end) {
300
+ const bounds = allDayBounds(start, end);
301
+ start = bounds.start;
302
+ end = bounds.end;
303
+ }
304
+ const result = {
305
+ summary: ev.summary ?? '',
306
+ location: ev.location ?? '',
307
+ description: ev.description ?? '',
308
+ start,
309
+ end,
310
+ allDay,
311
+ attendees: Array.isArray(ev.attendees) ? ev.attendees : [],
312
+ externalEmails: Array.isArray(ev.externalEmails) ? ev.externalEmails : [],
313
+ recurrence: ev.recurrence || 'none',
314
+ reminderMin: Number(ev.reminderMin) || 0,
315
+ category: ev.category || 'meeting',
316
+ };
317
+ for (const key of ['uid', 'status', 'time', 'organizer', 'sourceNodePath'])
318
+ if (ev[key] != null)
319
+ result[key] = ev[key];
320
+ return result;
321
+ },
322
+ setCategory(i, catId) {
323
+ if (!this.events?.[i])
324
+ return;
325
+ this.events[i].category = catId;
326
+ this.events = [...this.events];
327
+ this.commitEvents();
328
+ },
329
+ toggleAttendee(i, uid) {
330
+ if (!this.events?.[i] || !uid)
331
+ return;
332
+ const cur = Array.isArray(this.events[i].attendees) ? [...this.events[i].attendees] : [];
333
+ const idx = cur.indexOf(uid);
334
+ if (idx >= 0) cur.splice(idx, 1);
335
+ else cur.push(uid);
336
+ this.events[i].attendees = cur;
337
+ this.events = [...this.events];
338
+ this.commitEvents();
339
+ },
340
+ on_external(e, i) {
341
+ e.stopPropagation();
342
+ const arr = String(e.target.value || '').split(/[,;]/).map(s => s.trim()).filter(Boolean);
343
+ this.events[i].externalEmails = arr;
344
+ this.commitEvents();
345
+ },
346
+ on_input(e, i) {
347
+ e.stopPropagation();
348
+ const id = e.target.id;
349
+ if (id === 'start' || id === 'end') {
350
+ if (this.events[i].allDay) {
351
+ const d = new Date(`${e.target.value}T00:00:00`);
352
+ if (id === 'end')
353
+ d.setDate(d.getDate() + 1);
354
+ this.events[i][id] = d.toISOTimezoneString();
355
+ }
356
+ else {
357
+ this.events[i][id] = new Date(e.target.value).toISOTimezoneString();
358
+ }
359
+ }
360
+ else if (id === 'reminderMin') {
361
+ this.events[i].reminderMin = Number(e.target.value) || 0;
362
+ }
363
+ else {
364
+ this.events[i][id] = e.target.value;
365
+ }
366
+ this.commitEvents();
367
+ },
368
+ on_all_day(e, i) {
369
+ e.stopPropagation();
370
+ const ev = this.events[i];
371
+ const checked = !!e.detail.value;
372
+ if (!!ev.allDay === checked)
373
+ return;
374
+ ev.allDay = checked;
375
+ applyAllDayTimes(ev);
376
+ this.events = [...this.events];
377
+ this.commitEvents();
378
+ },
379
+ commitEvents() {
380
+ const body = JSON.stringify(
381
+ this.events.length === 1
382
+ ? this.eventToPersist(this.events[0])
383
+ : this.events.map(ev => this.eventToPersist(ev))
384
+ );
385
+ if (this.$item && (!this.$item.body || (this.$item.body !== body))) {
386
+ this.$item.body = body;
387
+ this.$item.isChanged = true;
388
+ }
389
+ },
390
+ events: undefined,
391
+ canCancel: false,
392
+ cancelled: false,
393
+ set $item(n) {
394
+ if (n) {
395
+ this.async(async () => {
396
+ let content = await n.load();
397
+ if (typeof content === 'string')
398
+ content = JSON.parse(content);
399
+ this.cancelled = content?.status === 'cancelled';
400
+ this.events = [content];
401
+ })
402
+ }
403
+ },
404
+ hydrateEvent(raw) {
405
+ const ev = {
406
+ summary: raw.summary ?? '',
407
+ location: raw.location ?? '',
408
+ description: raw.description ?? '',
409
+ allDay: !!raw.allDay,
410
+ attendees: Array.isArray(raw.attendees) ? raw.attendees : [],
411
+ externalEmails: Array.isArray(raw.externalEmails) ? raw.externalEmails : [],
412
+ recurrence: raw.recurrence || 'none',
413
+ reminderMin: Number(raw.reminderMin) || 0,
414
+ category: raw.category || 'meeting',
415
+ start: '',
416
+ end: ''
417
+ };
418
+ if (raw.start)
419
+ ev.start = /[Zz]|[+-]\d{2}:\d{2}$/.test(raw.start) ? raw.start : new Date(raw.start).toISOTimezoneString();
420
+ else if (raw.startStr)
421
+ ev.start = new Date(raw.startStr).toISOTimezoneString();
422
+ if (raw.end)
423
+ ev.end = /[Zz]|[+-]\d{2}:\d{2}$/.test(raw.end) ? raw.end : new Date(raw.end).toISOTimezoneString();
424
+ else if (raw.endStr)
425
+ ev.end = new Date(raw.endStr).toISOTimezoneString();
426
+ return ev;
427
+ },
428
+ parseICSDate(dateStr) {
429
+ if (!dateStr)
430
+ return '';
431
+ dateStr = dateStr.replace(/\\/g, '');
432
+ if (dateStr.includes('-') && dateStr.includes('T'))
433
+ return new Date(dateStr).toISOTimezoneString();
434
+ const utc = /Z$/i.test(dateStr);
435
+ const compact = dateStr.replace(/Z$/i, '');
436
+ if (!/^\d{8}(T\d{6})?$/.test(compact))
437
+ return new Date(dateStr);
438
+ const year = parseInt(compact.substring(0, 4), 10);
439
+ const month = parseInt(compact.substring(4, 6), 10) - 1;
440
+ const day = parseInt(compact.substring(6, 8), 10);
441
+ const hasTime = compact.length > 8;
442
+ const hours = hasTime ? parseInt(compact.substring(9, 11), 10) : 0;
443
+ const minutes = hasTime ? parseInt(compact.substring(11, 13), 10) : 0;
444
+ const seconds = hasTime ? parseInt(compact.substring(13, 15), 10) : 0;
445
+ const d = utc
446
+ ? new Date(Date.UTC(year, month, day, hours, minutes, seconds))
447
+ : new Date(year, month, day, hours, minutes, seconds);
448
+ return d.toISOTimezoneString();
449
+ },
450
+ parseICSSimple(icsText) {
451
+ const events = [];
452
+ const lines = icsText.split(/\r\n|\n|\r/);
453
+ let currentEvent = null;
454
+ for (const line of lines) {
455
+ if (line.startsWith('BEGIN:VEVENT')) {
456
+ currentEvent = {};
457
+ } else if (line.startsWith('END:VEVENT')) {
458
+ if (currentEvent)
459
+ events.push(this.hydrateEvent(currentEvent));
460
+ currentEvent = null;
461
+ } else if (currentEvent) {
462
+ const colonIdx = line.indexOf(':');
463
+ if (colonIdx === -1)
464
+ continue;
465
+ const key = line.slice(0, colonIdx).split(';')[0].trim();
466
+ const value = line.slice(colonIdx + 1).trim();
467
+ if (key === 'SUMMARY') currentEvent.summary = value;
468
+ else if (key === 'LOCATION') currentEvent.location = value;
469
+ else if (key === 'DESCRIPTION') currentEvent.description = value.replace(/\\n/g, '\n');
470
+ else if (key === 'DTSTART') {
471
+ currentEvent.start = this.parseICSDate(value);
472
+ if (/^\d{8}$/.test(value.replace(/\\/g, '')))
473
+ currentEvent.allDay = true;
474
+ }
475
+ else if (key === 'DTEND') {
476
+ currentEvent.end = this.parseICSDate(value);
477
+ }
478
+ }
479
+ }
480
+ return events;
481
+ }
482
+ });