@react-x11/components 0.6.0 → 0.7.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 +49 -39
- package/dist/formula/node.d.ts.map +1 -1
- package/dist/formula/node.js +17 -6
- package/dist/formula/node.js.map +1 -1
- package/dist/html/dom.d.ts +8 -1
- package/dist/html/dom.d.ts.map +1 -1
- package/dist/html/dom.js +17 -2
- package/dist/html/dom.js.map +1 -1
- package/dist/html/index.d.ts +4 -0
- package/dist/html/index.d.ts.map +1 -1
- package/dist/html/index.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/richtext/node.d.ts.map +1 -1
- package/dist/richtext/node.js +7 -2
- package/dist/richtext/node.js.map +1 -1
- package/dist/table/index.d.ts +15 -0
- package/dist/table/index.d.ts.map +1 -1
- package/dist/table/index.js +95 -11
- package/dist/table/index.js.map +1 -1
- package/dist/tree/index.d.ts.map +1 -1
- package/dist/tree/index.js +77 -2
- package/dist/tree/index.js.map +1 -1
- package/package.json +3 -8
- package/src/formula/node.ts +22 -34
- package/src/html/dom.ts +17 -2
- package/src/html/index.ts +4 -0
- package/src/index.ts +0 -18
- package/src/richtext/node.ts +7 -2
- package/src/table/index.ts +114 -10
- package/src/tree/index.ts +77 -2
- package/dist/desktop-calendar/eds.d.ts +0 -102
- package/dist/desktop-calendar/eds.d.ts.map +0 -1
- package/dist/desktop-calendar/eds.js +0 -356
- package/dist/desktop-calendar/eds.js.map +0 -1
- package/dist/desktop-calendar/ical.d.ts +0 -63
- package/dist/desktop-calendar/ical.d.ts.map +0 -1
- package/dist/desktop-calendar/ical.js +0 -57
- package/dist/desktop-calendar/ical.js.map +0 -1
- package/dist/desktop-calendar/index.d.ts +0 -72
- package/dist/desktop-calendar/index.d.ts.map +0 -1
- package/dist/desktop-calendar/index.js +0 -213
- package/dist/desktop-calendar/index.js.map +0 -1
- package/src/desktop-calendar/eds.ts +0 -484
- package/src/desktop-calendar/ical.ts +0 -119
- package/src/desktop-calendar/index.ts +0 -287
|
@@ -1,484 +0,0 @@
|
|
|
1
|
-
// The user's desktop calendars, over D-Bus, through Evolution Data Server.
|
|
2
|
-
//
|
|
3
|
-
// EDS is the store every GNOME calendar UI reads from, and GNOME Online
|
|
4
|
-
// Accounts feeds Google/Microsoft/CalDAV into it — so anything the user
|
|
5
|
-
// connected in Settings shows up here with no OAuth work on our side, and no
|
|
6
|
-
// credentials ever touching this package.
|
|
7
|
-
//
|
|
8
|
-
// Two services are involved:
|
|
9
|
-
// Sources5 — the registry: which calendars exist, their names and colours
|
|
10
|
-
// Calendar8 — the store: open a calendar, query a time range, watch changes
|
|
11
|
-
//
|
|
12
|
-
// Recurring events come back as unexpanded masters, so occurrences are
|
|
13
|
-
// generated client-side with `ical.js` (an optional dependency — see
|
|
14
|
-
// `./ical.js`).
|
|
15
|
-
//
|
|
16
|
-
// **The connection is not ours.** It arrives from react-x11's shared bus, so
|
|
17
|
-
// the app's exported service, its tray, its menus and this all speak on one
|
|
18
|
-
// socket under one unique name. Dialling a second one would make the app look
|
|
19
|
-
// like two applications on the bus, and would leak a connection per mount.
|
|
20
|
-
import type { MessageBus } from 'react-x11';
|
|
21
|
-
|
|
22
|
-
import { loadIcal } from './ical.js';
|
|
23
|
-
import type { IcalComponent, IcalModule, IcalTime } from './ical.js';
|
|
24
|
-
|
|
25
|
-
const SOURCES_NAME = 'org.gnome.evolution.dataserver.Sources5';
|
|
26
|
-
const SOURCES_PATH = '/org/gnome/evolution/dataserver/SourceManager';
|
|
27
|
-
const OBJECT_MANAGER = 'org.freedesktop.DBus.ObjectManager';
|
|
28
|
-
const FACTORY_NAME = 'org.gnome.evolution.dataserver.Calendar8';
|
|
29
|
-
const FACTORY_PATH = '/org/gnome/evolution/dataserver/CalendarFactory';
|
|
30
|
-
const FACTORY_IFACE = 'org.gnome.evolution.dataserver.CalendarFactory';
|
|
31
|
-
const CAL_IFACE = 'org.gnome.evolution.dataserver.Calendar';
|
|
32
|
-
const VIEW_IFACE = 'org.gnome.evolution.dataserver.CalendarView';
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* `E_CAL_CLIENT_VIEW_FLAGS_NONE`. A view is created with
|
|
36
|
-
* `NOTIFY_INITIAL` instead, which makes `Start()` replay everything already
|
|
37
|
-
* matching the query as `ObjectsAdded` — the current contents, announced as
|
|
38
|
-
* if they had just changed.
|
|
39
|
-
*
|
|
40
|
-
* That is the wrong signal for a watcher whose answer to a change is to run
|
|
41
|
-
* the query again: the re-query tears the view down, starts a new one, and is
|
|
42
|
-
* told the same thing again, for as long as the app is open. Flags of NONE is
|
|
43
|
-
* the whole of "only tell me what changes from here".
|
|
44
|
-
*/
|
|
45
|
-
const VIEW_FLAGS_NONE = 0;
|
|
46
|
-
|
|
47
|
-
/** One calendar the desktop knows about. */
|
|
48
|
-
export interface DesktopCalendarInfo {
|
|
49
|
-
uid: string;
|
|
50
|
-
/** The name shown in the desktop's own calendar UI. */
|
|
51
|
-
name: string;
|
|
52
|
-
enabled: boolean;
|
|
53
|
-
/** The colour that UI draws it in — worth carrying into a day marker. */
|
|
54
|
-
color?: string;
|
|
55
|
-
/** `caldav`, `google`, `local`, `webcal`… */
|
|
56
|
-
backend?: string;
|
|
57
|
-
readOnly: boolean;
|
|
58
|
-
/** Set when the calendar came from an Online Accounts login. */
|
|
59
|
-
account?: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** One occurrence, already expanded out of any recurrence rule. */
|
|
63
|
-
export interface DesktopEvent {
|
|
64
|
-
uid: string;
|
|
65
|
-
summary: string;
|
|
66
|
-
location?: string;
|
|
67
|
-
description?: string;
|
|
68
|
-
start: Date;
|
|
69
|
-
end: Date;
|
|
70
|
-
allDay: boolean;
|
|
71
|
-
recurring: boolean;
|
|
72
|
-
calendar: { uid: string; name: string; color?: string };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** A calendar that would not answer. One broken backend is not a failure. */
|
|
76
|
-
export interface DesktopCalendarError {
|
|
77
|
-
calendar: DesktopCalendarInfo;
|
|
78
|
-
message: string;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface EventsResult {
|
|
82
|
-
events: DesktopEvent[];
|
|
83
|
-
errors: DesktopCalendarError[];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** What `watch` reports. Deliberately thin: re-query rather than patch. */
|
|
87
|
-
export interface CalendarChange {
|
|
88
|
-
calendar: DesktopCalendarInfo;
|
|
89
|
-
kind: 'ObjectsAdded' | 'ObjectsModified' | 'ObjectsRemoved';
|
|
90
|
-
count: number;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const pad = (n: number): string => String(n).padStart(2, '0');
|
|
94
|
-
|
|
95
|
-
/** `20260807T113000Z` — what the S-expression query wants. */
|
|
96
|
-
function icalStamp(d: Date): string {
|
|
97
|
-
return (
|
|
98
|
-
`${d.getUTCFullYear()}${pad(d.getUTCMonth() + 1)}${pad(d.getUTCDate())}T` +
|
|
99
|
-
`${pad(d.getUTCHours())}${pad(d.getUTCMinutes())}${pad(d.getUTCSeconds())}Z`
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** The query EDS understands for "anything happening between these two". */
|
|
104
|
-
function rangeQuery(from: Date, to: Date): string {
|
|
105
|
-
return `(occur-in-time-range? (make-time "${icalStamp(from)}") (make-time "${icalStamp(to)}"))`;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* A source's whole configuration is an ini-style keyfile carried in one D-Bus
|
|
110
|
-
* property, so it has to be parsed to find out whether a source is even a
|
|
111
|
-
* calendar (as opposed to an address book, a mail account or a task list).
|
|
112
|
-
*/
|
|
113
|
-
export function parseKeyFile(
|
|
114
|
-
text: string,
|
|
115
|
-
): Record<string, Record<string, string>> {
|
|
116
|
-
const out: Record<string, Record<string, string>> = {};
|
|
117
|
-
let section: string | null = null;
|
|
118
|
-
for (const raw of text.split('\n')) {
|
|
119
|
-
const line = raw.trim();
|
|
120
|
-
if (!line || line.startsWith('#')) continue;
|
|
121
|
-
if (line.startsWith('[') && line.endsWith(']')) {
|
|
122
|
-
section = line.slice(1, -1);
|
|
123
|
-
out[section] = out[section] ?? {};
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
if (!section) continue;
|
|
127
|
-
const eq = line.indexOf('=');
|
|
128
|
-
if (eq === -1) continue;
|
|
129
|
-
const key = line.slice(0, eq).trim();
|
|
130
|
-
if (key.includes('[')) continue; // a DisplayName[ru] translation
|
|
131
|
-
out[section][key] = line.slice(eq + 1).trim();
|
|
132
|
-
}
|
|
133
|
-
return out;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/** `dbus-native`'s proxies are built by introspection, so they are `any`
|
|
137
|
-
* shaped. These name only what is called. */
|
|
138
|
-
interface CalendarIface {
|
|
139
|
-
Open(): Promise<void>;
|
|
140
|
-
GetObjectList(query: string): Promise<string[]>;
|
|
141
|
-
GetTimezone(tzid: string): Promise<string>;
|
|
142
|
-
GetView(query: string): Promise<string>;
|
|
143
|
-
}
|
|
144
|
-
interface ViewIface {
|
|
145
|
-
$subscribe(signal: string, fn: (...args: unknown[]) => void): Promise<void>;
|
|
146
|
-
SetFlags(flags: number): Promise<void>;
|
|
147
|
-
Start(): Promise<void>;
|
|
148
|
-
Stop(): Promise<void>;
|
|
149
|
-
Dispose(): Promise<void>;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* The desktop's calendars, read over a bus someone else owns.
|
|
154
|
-
*
|
|
155
|
-
* ```ts
|
|
156
|
-
* const ref = await sessionBus();
|
|
157
|
-
* if (!ref) return; // no bus here; no calendars
|
|
158
|
-
* const desktop = new DesktopCalendar(ref.bus);
|
|
159
|
-
* const { events } = await desktop.eventsBetween(from, to);
|
|
160
|
-
* ```
|
|
161
|
-
*
|
|
162
|
-
* Nothing here closes the connection, because nothing here opened it. Call
|
|
163
|
-
* `dispose()` to drop the views this instance started, then release your own
|
|
164
|
-
* reference to the bus.
|
|
165
|
-
*/
|
|
166
|
-
export class DesktopCalendar {
|
|
167
|
-
#bus: MessageBus;
|
|
168
|
-
#open = new Map<string, { cal: CalendarIface; busName: string }>();
|
|
169
|
-
#views: ViewIface[] = [];
|
|
170
|
-
#timezones = new Set<string>();
|
|
171
|
-
|
|
172
|
-
constructor(bus: MessageBus) {
|
|
173
|
-
this.#bus = bus;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/** Every calendar the desktop knows about, colour included. */
|
|
177
|
-
async listCalendars(): Promise<DesktopCalendarInfo[]> {
|
|
178
|
-
const om = (await this.#bus
|
|
179
|
-
.getService(SOURCES_NAME)
|
|
180
|
-
.getInterface(SOURCES_PATH, OBJECT_MANAGER)) as {
|
|
181
|
-
GetManagedObjects(): Promise<
|
|
182
|
-
Record<string, Record<string, Record<string, unknown>>>
|
|
183
|
-
>;
|
|
184
|
-
};
|
|
185
|
-
const managed = await om.GetManagedObjects();
|
|
186
|
-
|
|
187
|
-
const calendars: DesktopCalendarInfo[] = [];
|
|
188
|
-
for (const interfaces of Object.values(managed)) {
|
|
189
|
-
const src = interfaces['org.gnome.evolution.dataserver.Source'];
|
|
190
|
-
if (!src) continue;
|
|
191
|
-
const cfg = parseKeyFile(String(src.Data ?? ''));
|
|
192
|
-
// no [Calendar] section means an address book, a task list or mail
|
|
193
|
-
if (!cfg.Calendar) continue;
|
|
194
|
-
const ds = cfg['Data Source'] ?? {};
|
|
195
|
-
calendars.push({
|
|
196
|
-
uid: String(src.UID ?? ''),
|
|
197
|
-
name: ds.DisplayName ?? '',
|
|
198
|
-
enabled: ds.Enabled !== 'false',
|
|
199
|
-
color: cfg.Calendar.Color,
|
|
200
|
-
backend: cfg.Calendar.BackendName,
|
|
201
|
-
readOnly: !interfaces['org.gnome.evolution.dataserver.Source.Writable'],
|
|
202
|
-
account: cfg['GNOME Online Accounts']?.Account,
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
return calendars;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
async #openCalendar(
|
|
209
|
-
uid: string,
|
|
210
|
-
): Promise<{ cal: CalendarIface; busName: string }> {
|
|
211
|
-
const existing = this.#open.get(uid);
|
|
212
|
-
if (existing) return existing;
|
|
213
|
-
|
|
214
|
-
const factory = (await this.#bus
|
|
215
|
-
.getService(FACTORY_NAME)
|
|
216
|
-
.getInterface(FACTORY_PATH, FACTORY_IFACE)) as {
|
|
217
|
-
OpenCalendar(uid: string): Promise<[string, string]>;
|
|
218
|
-
};
|
|
219
|
-
const [path, busName] = await factory.OpenCalendar(uid);
|
|
220
|
-
const cal = (await this.#bus
|
|
221
|
-
.getService(busName)
|
|
222
|
-
.getInterface(path, CAL_IFACE)) as CalendarIface;
|
|
223
|
-
await cal.Open();
|
|
224
|
-
|
|
225
|
-
const entry = { cal, busName };
|
|
226
|
-
this.#open.set(uid, entry);
|
|
227
|
-
return entry;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Events reference timezones by id, but the payload rarely carries the
|
|
232
|
-
* matching VTIMEZONE — so definitions are fetched on demand and registered
|
|
233
|
-
* with ical.js. A backend that has none leaves the time floating, which is
|
|
234
|
-
* ical.js's own fallback and better than refusing the event.
|
|
235
|
-
*/
|
|
236
|
-
async #ensureTimezone(
|
|
237
|
-
ICAL: IcalModule,
|
|
238
|
-
cal: CalendarIface,
|
|
239
|
-
tzid: string | undefined,
|
|
240
|
-
): Promise<void> {
|
|
241
|
-
if (!tzid || this.#timezones.has(tzid) || ICAL.TimezoneService.has(tzid)) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
this.#timezones.add(tzid);
|
|
245
|
-
try {
|
|
246
|
-
const vtz = await cal.GetTimezone(tzid);
|
|
247
|
-
const comp = new ICAL.Component(ICAL.parse(vtz));
|
|
248
|
-
const sub =
|
|
249
|
-
comp.name === 'vtimezone'
|
|
250
|
-
? comp
|
|
251
|
-
: comp.getFirstSubcomponent('vtimezone');
|
|
252
|
-
if (sub) ICAL.TimezoneService.register(tzid, new ICAL.Timezone(sub));
|
|
253
|
-
} catch {
|
|
254
|
-
/* no definition for it; ical.js falls back to floating time */
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Expanded occurrences between two `Date`s, across the calendars given (or
|
|
260
|
-
* every enabled one). Sorted by start.
|
|
261
|
-
*
|
|
262
|
-
* A backend that is offline or broken contributes an entry in `errors`
|
|
263
|
-
* rather than throwing: one unreachable CalDAV server must not blank a
|
|
264
|
-
* whole month of the user's own local calendar.
|
|
265
|
-
*/
|
|
266
|
-
async eventsBetween(
|
|
267
|
-
from: Date,
|
|
268
|
-
to: Date,
|
|
269
|
-
options: { calendars?: DesktopCalendarInfo[] } = {},
|
|
270
|
-
): Promise<EventsResult> {
|
|
271
|
-
const ICAL = await loadIcal();
|
|
272
|
-
const list =
|
|
273
|
-
options.calendars ??
|
|
274
|
-
(await this.listCalendars()).filter((c) => c.enabled);
|
|
275
|
-
const query = rangeQuery(from, to);
|
|
276
|
-
|
|
277
|
-
const perCalendar = await Promise.all(
|
|
278
|
-
list.map(async (meta) => {
|
|
279
|
-
try {
|
|
280
|
-
const { cal } = await this.#openCalendar(meta.uid);
|
|
281
|
-
const objects = await cal.GetObjectList(query);
|
|
282
|
-
return {
|
|
283
|
-
events: await this.#expand(ICAL, cal, objects, from, to, meta),
|
|
284
|
-
error: null,
|
|
285
|
-
};
|
|
286
|
-
} catch (err) {
|
|
287
|
-
return {
|
|
288
|
-
events: [],
|
|
289
|
-
error: {
|
|
290
|
-
calendar: meta,
|
|
291
|
-
message: err instanceof Error ? err.message : String(err),
|
|
292
|
-
},
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
}),
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
const events: DesktopEvent[] = [];
|
|
299
|
-
const errors: DesktopCalendarError[] = [];
|
|
300
|
-
for (const chunk of perCalendar) {
|
|
301
|
-
events.push(...chunk.events);
|
|
302
|
-
if (chunk.error) errors.push(chunk.error);
|
|
303
|
-
}
|
|
304
|
-
events.sort((a, b) => a.start.getTime() - b.start.getTime());
|
|
305
|
-
return { events, errors };
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
async #expand(
|
|
309
|
-
ICAL: IcalModule,
|
|
310
|
-
cal: CalendarIface,
|
|
311
|
-
objects: string[],
|
|
312
|
-
from: Date,
|
|
313
|
-
to: Date,
|
|
314
|
-
meta: DesktopCalendarInfo,
|
|
315
|
-
): Promise<DesktopEvent[]> {
|
|
316
|
-
const out: DesktopEvent[] = [];
|
|
317
|
-
for (const ics of objects) {
|
|
318
|
-
let comp: IcalComponent;
|
|
319
|
-
try {
|
|
320
|
-
comp = new ICAL.Component(ICAL.parse(ics));
|
|
321
|
-
} catch {
|
|
322
|
-
continue; // one unparseable object is not the range's problem
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// Register any VTIMEZONE shipped inline, then any referenced by id.
|
|
326
|
-
for (const vtz of comp.getAllSubcomponents('vtimezone')) {
|
|
327
|
-
const tz = new ICAL.Timezone(vtz);
|
|
328
|
-
if (!ICAL.TimezoneService.has(tz.tzid)) {
|
|
329
|
-
ICAL.TimezoneService.register(tz.tzid, tz);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
const vevents =
|
|
334
|
-
comp.name === 'vevent' ? [comp] : comp.getAllSubcomponents('vevent');
|
|
335
|
-
for (const ve of vevents) {
|
|
336
|
-
for (const prop of ['dtstart', 'dtend']) {
|
|
337
|
-
const p = ve.getFirstProperty(prop);
|
|
338
|
-
if (p) await this.#ensureTimezone(ICAL, cal, p.getParameter('tzid'));
|
|
339
|
-
}
|
|
340
|
-
const event = new ICAL.Event(ve);
|
|
341
|
-
// folded in by the recurrence iterator below
|
|
342
|
-
if (event.isRecurrenceException()) continue;
|
|
343
|
-
|
|
344
|
-
const push = (startTime: IcalTime, endTime: IcalTime | null): void => {
|
|
345
|
-
const start = startTime.toJSDate();
|
|
346
|
-
const end = endTime ? endTime.toJSDate() : start;
|
|
347
|
-
if (end < from || start >= to) return;
|
|
348
|
-
out.push({
|
|
349
|
-
uid: event.uid,
|
|
350
|
-
summary: event.summary || '',
|
|
351
|
-
location: event.location || undefined,
|
|
352
|
-
description: event.description || undefined,
|
|
353
|
-
start,
|
|
354
|
-
end,
|
|
355
|
-
allDay: event.startDate.isDate,
|
|
356
|
-
recurring: event.isRecurring(),
|
|
357
|
-
calendar: { uid: meta.uid, name: meta.name, color: meta.color },
|
|
358
|
-
});
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
if (!event.isRecurring()) {
|
|
362
|
-
push(event.startDate, event.endDate);
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
const duration = event.duration;
|
|
367
|
-
const it = event.iterator();
|
|
368
|
-
let next: IcalTime | null;
|
|
369
|
-
// A malformed RRULE with no UNTIL and a tiny interval can iterate
|
|
370
|
-
// forever; the range check below normally ends it, and this is the
|
|
371
|
-
// backstop for the case where it cannot.
|
|
372
|
-
let guard = 0;
|
|
373
|
-
while ((next = it.next()) && guard++ < 2000) {
|
|
374
|
-
if (next.toJSDate() >= to) break;
|
|
375
|
-
const end = next.clone();
|
|
376
|
-
end.addDuration(duration);
|
|
377
|
-
if (end.toJSDate() < from) continue;
|
|
378
|
-
const details = event.getOccurrenceDetails(next);
|
|
379
|
-
push(details.startDate, details.endDate);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
return out;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Live updates: `onChange` fires whenever anything in the range moves, so
|
|
388
|
-
* the caller can re-query. Returns an unsubscribe function.
|
|
389
|
-
*
|
|
390
|
-
* Deliberately a "something changed" signal rather than a patch — a
|
|
391
|
-
* recurrence master edited three months away can change what today looks
|
|
392
|
-
* like, and re-running the query is both simpler and correct.
|
|
393
|
-
*
|
|
394
|
-
* **Changes only.** What is in the range already is what `eventsBetween`
|
|
395
|
-
* answered; `onChange` fires for what happens after that. See
|
|
396
|
-
* {@link VIEW_FLAGS_NONE} for the loop that reporting the initial contents
|
|
397
|
-
* as a change costs a caller who re-queries on one.
|
|
398
|
-
*/
|
|
399
|
-
async watch(
|
|
400
|
-
from: Date,
|
|
401
|
-
to: Date,
|
|
402
|
-
onChange: (change: CalendarChange) => void,
|
|
403
|
-
options: { calendars?: DesktopCalendarInfo[] } = {},
|
|
404
|
-
): Promise<() => Promise<void>> {
|
|
405
|
-
const list =
|
|
406
|
-
options.calendars ??
|
|
407
|
-
(await this.listCalendars()).filter((c) => c.enabled);
|
|
408
|
-
const query = rangeQuery(from, to);
|
|
409
|
-
const started: ViewIface[] = [];
|
|
410
|
-
|
|
411
|
-
for (const meta of list) {
|
|
412
|
-
try {
|
|
413
|
-
const { cal, busName } = await this.#openCalendar(meta.uid);
|
|
414
|
-
const viewPath = await cal.GetView(query);
|
|
415
|
-
const view = (await this.#bus
|
|
416
|
-
.getService(busName)
|
|
417
|
-
.getInterface(viewPath, VIEW_IFACE)) as ViewIface;
|
|
418
|
-
|
|
419
|
-
// Belt to `VIEW_FLAGS_NONE`'s braces, for a backend that would not
|
|
420
|
-
// take the flags: `Complete` closes the initial delivery, so anything
|
|
421
|
-
// before it is the replay rather than a change. Only armed when
|
|
422
|
-
// `SetFlags` failed — a view that never reports `Complete` would
|
|
423
|
-
// otherwise be watched in silence, and losing live updates is the
|
|
424
|
-
// worse half of the trade.
|
|
425
|
-
let replaying = false;
|
|
426
|
-
try {
|
|
427
|
-
await view.SetFlags(VIEW_FLAGS_NONE);
|
|
428
|
-
} catch {
|
|
429
|
-
replaying = true;
|
|
430
|
-
}
|
|
431
|
-
await view.$subscribe('Complete', () => {
|
|
432
|
-
replaying = false;
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
for (const signal of [
|
|
436
|
-
'ObjectsAdded',
|
|
437
|
-
'ObjectsModified',
|
|
438
|
-
'ObjectsRemoved',
|
|
439
|
-
] as const) {
|
|
440
|
-
await view.$subscribe(signal, (objects) => {
|
|
441
|
-
if (replaying) return;
|
|
442
|
-
onChange({
|
|
443
|
-
calendar: meta,
|
|
444
|
-
kind: signal,
|
|
445
|
-
count: Array.isArray(objects) ? objects.length : 0,
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
await view.Start();
|
|
450
|
-
started.push(view);
|
|
451
|
-
this.#views.push(view);
|
|
452
|
-
} catch {
|
|
453
|
-
/* skip a calendar that will not open; the others still update */
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
return async () => {
|
|
458
|
-
for (const view of started) {
|
|
459
|
-
this.#views = this.#views.filter((v) => v !== view);
|
|
460
|
-
try {
|
|
461
|
-
await view.Stop();
|
|
462
|
-
await view.Dispose();
|
|
463
|
-
} catch {
|
|
464
|
-
/* already gone */
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
/** Stop every view this instance started. Does **not** touch the bus. */
|
|
471
|
-
async dispose(): Promise<void> {
|
|
472
|
-
const views = this.#views;
|
|
473
|
-
this.#views = [];
|
|
474
|
-
for (const view of views) {
|
|
475
|
-
try {
|
|
476
|
-
await view.Stop();
|
|
477
|
-
await view.Dispose();
|
|
478
|
-
} catch {
|
|
479
|
-
/* already gone */
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
this.#open.clear();
|
|
483
|
-
}
|
|
484
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// The slice of `ical.js` this package uses, and the loader that finds it.
|
|
2
|
-
//
|
|
3
|
-
// **`ical.js` is an `optionalDependency`, and these types are deliberately
|
|
4
|
-
// ours rather than the package's.** `import type … from 'ical.js'` would put
|
|
5
|
-
// the module in the type graph, and then an app that did not install it could
|
|
6
|
-
// not type-check against this package at all — which is the opposite of what
|
|
7
|
-
// "optional" means. So the surface is written out structurally, and the value
|
|
8
|
-
// arrives through a dynamic `import()` that is allowed to fail.
|
|
9
|
-
//
|
|
10
|
-
// react-x11 makes the same call with `dbus-native`, for the same reason.
|
|
11
|
-
|
|
12
|
-
/** An `ICAL.Time`. */
|
|
13
|
-
export interface IcalTime {
|
|
14
|
-
toJSDate(): Date;
|
|
15
|
-
clone(): IcalTime;
|
|
16
|
-
addDuration(duration: unknown): void;
|
|
17
|
-
/** True for a date without a time — an all-day event's start. */
|
|
18
|
-
isDate: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface IcalProperty {
|
|
22
|
-
getParameter(name: string): string | undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface IcalComponent {
|
|
26
|
-
name: string;
|
|
27
|
-
getFirstSubcomponent(name: string): IcalComponent | null;
|
|
28
|
-
getAllSubcomponents(name: string): IcalComponent[];
|
|
29
|
-
getFirstProperty(name: string): IcalProperty | null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface IcalRecurExpansion {
|
|
33
|
-
next(): IcalTime | null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface IcalEvent {
|
|
37
|
-
uid: string;
|
|
38
|
-
summary: string;
|
|
39
|
-
location: string;
|
|
40
|
-
description: string;
|
|
41
|
-
startDate: IcalTime;
|
|
42
|
-
endDate: IcalTime;
|
|
43
|
-
duration: unknown;
|
|
44
|
-
isRecurring(): boolean;
|
|
45
|
-
isRecurrenceException(): boolean;
|
|
46
|
-
iterator(): IcalRecurExpansion;
|
|
47
|
-
getOccurrenceDetails(time: IcalTime): {
|
|
48
|
-
startDate: IcalTime;
|
|
49
|
-
endDate: IcalTime;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface IcalTimezone {
|
|
54
|
-
tzid: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** What `import('ical.js')` gives back, as far as this package is concerned. */
|
|
58
|
-
export interface IcalModule {
|
|
59
|
-
parse(input: string): unknown;
|
|
60
|
-
Component: new (jcal: unknown) => IcalComponent;
|
|
61
|
-
Event: new (component: IcalComponent) => IcalEvent;
|
|
62
|
-
Timezone: new (component: IcalComponent) => IcalTimezone;
|
|
63
|
-
TimezoneService: {
|
|
64
|
-
has(tzid: string): boolean;
|
|
65
|
-
register(tzid: string, zone: IcalTimezone): void;
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Thrown when the calendar is asked for events and `ical.js` is not there. */
|
|
70
|
-
export class IcalUnavailableError extends Error {
|
|
71
|
-
constructor(cause?: unknown) {
|
|
72
|
-
super(
|
|
73
|
-
"@react-x11/components: reading desktop calendar events needs 'ical.js', " +
|
|
74
|
-
'which is an optional dependency and is not installed. ' +
|
|
75
|
-
'Run `npm install ical.js`. Listing calendars does not need it.',
|
|
76
|
-
{ cause },
|
|
77
|
-
);
|
|
78
|
-
this.name = 'IcalUnavailableError';
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let cached: Promise<IcalModule> | null = null;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Load `ical.js`, once.
|
|
86
|
-
*
|
|
87
|
-
* Deliberately **not** cached as a rejection: a failed load is almost always
|
|
88
|
-
* "not installed", but retrying costs nothing and a cached rejection would
|
|
89
|
-
* outlive an app that installed it and re-rendered.
|
|
90
|
-
*/
|
|
91
|
-
export async function loadIcal(): Promise<IcalModule> {
|
|
92
|
-
if (cached) return cached;
|
|
93
|
-
const attempt = (async (): Promise<IcalModule> => {
|
|
94
|
-
try {
|
|
95
|
-
// The specifier is built at run time so a bundler treats this as a
|
|
96
|
-
// genuinely optional import and does not fail the build resolving a
|
|
97
|
-
// package the app may well not have.
|
|
98
|
-
const name = 'ical.js';
|
|
99
|
-
const mod = (await import(/* @vite-ignore */ name)) as {
|
|
100
|
-
default?: IcalModule;
|
|
101
|
-
} & IcalModule;
|
|
102
|
-
// ical.js is CJS-with-a-default under some resolutions and a namespace
|
|
103
|
-
// under others; `parse` is on whichever one is real.
|
|
104
|
-
const resolved = typeof mod.parse === 'function' ? mod : mod.default;
|
|
105
|
-
if (!resolved || typeof resolved.parse !== 'function') {
|
|
106
|
-
throw new TypeError('ical.js did not export what was expected');
|
|
107
|
-
}
|
|
108
|
-
return resolved;
|
|
109
|
-
} catch (err) {
|
|
110
|
-
throw new IcalUnavailableError(err);
|
|
111
|
-
}
|
|
112
|
-
})();
|
|
113
|
-
// Only a successful load is remembered.
|
|
114
|
-
cached = attempt.catch((err: unknown) => {
|
|
115
|
-
cached = null;
|
|
116
|
-
throw err;
|
|
117
|
-
});
|
|
118
|
-
return cached;
|
|
119
|
-
}
|