domma-cms 1.36.0 → 1.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/bin/lib/left-free-tier.js +4 -1
  3. package/bin/update.js +4 -0
  4. package/docs/DommaFeatures.md +8 -6
  5. package/docs/plugin-development.md +2 -2
  6. package/package.json +1 -1
  7. package/plugins/docs/tests/plugin.test.js +2 -0
  8. package/plugins/free-tier.lock.json +2 -50
  9. package/server/services/siteGitignore.js +1 -1
  10. package/plugins/booking/CLAUDE.md +0 -204
  11. package/plugins/booking/admin/css/index.css +0 -192
  12. package/plugins/booking/admin/lib/details.js +0 -58
  13. package/plugins/booking/admin/lib/diary-layout.js +0 -158
  14. package/plugins/booking/admin/lib/drafts.js +0 -139
  15. package/plugins/booking/admin/lib/email.js +0 -191
  16. package/plugins/booking/admin/lib/extension-sections.js +0 -160
  17. package/plugins/booking/admin/lib/kit.js +0 -471
  18. package/plugins/booking/admin/templates/booking.html +0 -1
  19. package/plugins/booking/admin/views/booking.js +0 -216
  20. package/plugins/booking/admin/views/bookings.js +0 -132
  21. package/plugins/booking/admin/views/diary.js +0 -382
  22. package/plugins/booking/admin/views/panels.js +0 -603
  23. package/plugins/booking/admin/views/people.js +0 -318
  24. package/plugins/booking/admin/views/services.js +0 -264
  25. package/plugins/booking/admin/views/settings.js +0 -222
  26. package/plugins/booking/collections/booking-bookables.json +0 -17
  27. package/plugins/booking/collections/booking-bookings.json +0 -18
  28. package/plugins/booking/collections/booking-services.json +0 -17
  29. package/plugins/booking/config.js +0 -36
  30. package/plugins/booking/docs/guide.md +0 -73
  31. package/plugins/booking/inject/body.html +0 -1
  32. package/plugins/booking/lib/call.js +0 -88
  33. package/plugins/booking/lib/extensions.js +0 -169
  34. package/plugins/booking/lib/mail.js +0 -113
  35. package/plugins/booking/lib/store.js +0 -392
  36. package/plugins/booking/plugin.js +0 -905
  37. package/plugins/booking/plugin.json +0 -81
  38. package/plugins/booking/plugin.public.js +0 -175
  39. package/plugins/booking/public/booking.css +0 -159
  40. package/plugins/booking/public/booking.js +0 -808
  41. package/plugins/booking/public/lib/clean.js +0 -141
  42. package/plugins/booking/public/lib/page-format.js +0 -121
  43. package/plugins/booking/public/lib/slots.js +0 -247
  44. package/plugins/booking/public/lib/time.js +0 -131
  45. package/plugins/booking/templates/booking.html +0 -5
  46. package/plugins/booking/tests/admin-diary.test.js +0 -81
  47. package/plugins/booking/tests/admin-drafts.test.js +0 -67
  48. package/plugins/booking/tests/api.test.js +0 -651
  49. package/plugins/booking/tests/email.test.js +0 -69
  50. package/plugins/booking/tests/public.test.js +0 -72
  51. package/plugins/booking/tests/pure.test.js +0 -189
  52. package/plugins/booking/tests/seo.test.js +0 -71
@@ -1,471 +0,0 @@
1
- /**
2
- * Booking admin - what every screen shares: the admin's helpers (loaded at
3
- * run time; a plugin never imports admin/ statically - the updater replaces
4
- * it), the API, escaping, slideover forms, rows with a right-click / ⋮ /
5
- * Shift+F10 menu, and the words and colours for statuses.
6
- *
7
- * @module booking/admin/lib/kit
8
- */
9
-
10
- import {fmtDate, fmtDateTime} from '/plugins/_lib/admin/ui/dates.js';
11
- import {draftsWith, draftsWithout, restorePlan, restoreText, staleDraftKeys, usableDraft} from './drafts.js';
12
-
13
- export {fmtDate, fmtDateTime};
14
-
15
- export const SIDEBAR_URL = '#/plugins/booking';
16
- export const BASE = '/api/plugins/booking';
17
- export const V = '1.4.0';
18
-
19
- let kit = null;
20
-
21
- /** tool-kit, plugin-chrome, help-popover and loading, once, with stand-ins for an older admin. */
22
- export function loadKit() {
23
- if (!kit) {
24
- kit = Promise.all([
25
- import('/admin/js/lib/tool-kit.js').catch(() => ({})),
26
- import('/admin/js/lib/plugin-chrome.js').catch(() => ({})),
27
- import('/admin/js/lib/help-popover.js').catch(() => ({})),
28
- import('/admin/js/lib/loading.js').catch(() => ({}))
29
- ]).then(([tk, chrome, help, loading]) => ({
30
- onceClosed: tk.onceClosed || ((so, fn) => { const c = so.close.bind(so); so.close = (...a) => { const r = c(...a); fn?.(); return r; }; }),
31
- openMenuAt: tk.openMenuAt || ((el) => {
32
- const r = el.getBoundingClientRect();
33
- el.dispatchEvent(new MouseEvent('contextmenu', {bubbles: true, cancelable: true, clientX: r.left, clientY: r.bottom, view: window}));
34
- }),
35
- viewLifetime: tk.viewLifetime || (() => ({add() {}, reset() {}})),
36
- addBannerAction: chrome.addBannerAction || (() => null),
37
- helpPopovers: help.helpPopovers || (() => () => {}),
38
- // A skeleton in a loading slot while the first load runs (core 1.x); without it the slot's own
39
- // "Loading…" text shows, as before.
40
- whileLoading: loading.whileLoading || ((slot, p) => (typeof p === 'function' ? p() : p)),
41
- SHAPES: loading.SHAPES || {}
42
- }));
43
- }
44
- return kit;
45
- }
46
-
47
- /**
48
- * Booking's API, through the admin's apiRequest (imported at run time): it
49
- * attaches the token, refreshes it on a 401, and - unlike H - keeps the
50
- * status and the whole answer on an error (`err.status`, `err.body.errors`),
51
- * which a clash (409) and per-field messages need. H is the stand-in.
52
- */
53
- let requester = null;
54
- export function request(method, path, body) {
55
- requester ??= import('/admin/js/api.js').then(m => m.apiRequest).catch(() => null);
56
- return requester.then(fn => {
57
- if (fn) return fn(path, {method, ...(body !== undefined ? {body: JSON.stringify(body)} : {})});
58
- const url = `/api${path}`;
59
- return method === 'GET' ? H.get(url) : method === 'DELETE' ? H.delete(url) : H[method.toLowerCase()](url, body);
60
- });
61
- }
62
- const P = '/plugins/booking';
63
- const seg = (id) => encodeURIComponent(String(id));
64
- const qs = (o) => Object.entries(o).filter(([, v]) => v !== undefined && v !== null && v !== '').map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join('&');
65
- export const api = {
66
- bootstrap: () => request('GET', `${P}/bootstrap`),
67
- bookings: {
68
- list: (q = {}) => request('GET', `${P}/bookings?${qs(q)}`),
69
- get: (id) => request('GET', `${P}/bookings/${seg(id)}`),
70
- callChat: (id) => request('GET', `${P}/bookings/${seg(id)}/call-chat`),
71
- create: (d) => request('POST', `${P}/bookings`, d),
72
- update: (id, d) => request('PUT', `${P}/bookings/${seg(id)}`, d),
73
- move: (id, d) => request('PUT', `${P}/bookings/${seg(id)}/move`, d),
74
- remove: (id) => request('DELETE', `${P}/bookings/${seg(id)}`)
75
- },
76
- slots: (q) => request('GET', `${P}/slots?${qs(q)}`),
77
- services: {
78
- list: () => request('GET', `${P}/services`),
79
- create: (d) => request('POST', `${P}/services`, d),
80
- update: (id, d) => request('PUT', `${P}/services/${seg(id)}`, d),
81
- remove: (id) => request('DELETE', `${P}/services/${seg(id)}`)
82
- },
83
- bookables: {
84
- list: () => request('GET', `${P}/bookables`),
85
- create: (d) => request('POST', `${P}/bookables`, d),
86
- update: (id, d) => request('PUT', `${P}/bookables/${seg(id)}`, d),
87
- remove: (id) => request('DELETE', `${P}/bookables/${seg(id)}`)
88
- },
89
- settings: {
90
- get: () => request('GET', `${P}/settings`),
91
- save: (d) => request('PUT', `${P}/settings`, d)
92
- },
93
- contact: (id) => request('GET', `${P}/contact/${seg(id)}`),
94
- contactByEmail: (email) => request('GET', `${P}/contact?email=${encodeURIComponent(email)}`)
95
- };
96
-
97
- /**
98
- * A failed request, for a person to read. H throws with the server's message
99
- * but not always its status, so a clash is recognised by status OR wording.
100
- */
101
- export const errText = (err) => err?.message || String(err);
102
- export const isClash = (err) => err?.status === 409 && (err?.body?.code === 'slot-taken' || /clash|taken|no longer free/i.test(errText(err)));
103
-
104
- /** E.confirm / titles render HTML: user text goes in escaped. */
105
- export const esc = (s) => String(s ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
106
-
107
- /** A small DOM tree from an HTML string that holds NO unescaped user data. */
108
- export function fragment(html) {
109
- const t = document.createElement('template');
110
- t.innerHTML = html.trim();
111
- return t.content.firstElementChild;
112
- }
113
-
114
- export const store = {
115
- get(k) { try { return S.get(k); } catch { return null; } },
116
- set(k, v) { try { S.set(k, v); } catch { /* a convenience */ } }
117
- };
118
-
119
- /** The sidebar re-asks Booking's badge. */
120
- export function refreshBadge() {
121
- try { window.dispatchEvent(new CustomEvent('dm:sidebar-count', {detail: {url: SIDEBAR_URL}})); } catch { /* no sidebar */ }
122
- }
123
-
124
- // ---- Words and colours ----------------------------------------------------------
125
-
126
- export const STATUS_LABEL = {pending: 'Pending', confirmed: 'Booked', completed: 'Done', 'no-show': 'No-show', cancelled: 'Cancelled'};
127
- export const STATUS_TONE = {pending: 'warning', confirmed: 'primary', completed: 'success', 'no-show': 'danger', cancelled: 'muted'};
128
- export const COLOUR_LABEL = {blue: 'Blue', green: 'Green', teal: 'Teal', purple: 'Purple', pink: 'Pink', orange: 'Orange', red: 'Red', grey: 'Grey'};
129
- export const KIND_LABEL = {person: 'Person', resource: 'Room or thing'};
130
-
131
- /** "1 h 30 min", "45 min". */
132
- export function minutesLabel(n) {
133
- const m = Math.round(Number(n) || 0);
134
- if (m < 60) return `${m} min`;
135
- const h = Math.floor(m / 60);
136
- return m % 60 ? `${h} h ${m % 60} min` : `${h} h`;
137
- }
138
-
139
- /** "Tue 15/07/2031" from a 'YYYY-MM-DD'. */
140
- export function dateLabel(date) {
141
- const [y, m, d] = String(date).split('-');
142
- const wd = new Date(Date.UTC(Number(y), Number(m) - 1, Number(d))).getUTCDay();
143
- return `${['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][wd]} ${d}/${m}/${y}`;
144
- }
145
-
146
- /** "3 min ago", "26/09/2026". */
147
- export function when(iso) {
148
- const t = new Date(iso).getTime();
149
- if (!Number.isFinite(t)) return '';
150
- const s = (Date.now() - t) / 1000;
151
- if (s < 60) return 'just now';
152
- if (s < 3600) return `${Math.round(s / 60)} min ago`;
153
- if (s < 86400) return `${Math.round(s / 3600)} h ago`;
154
- if (s < 86400 * 6) return `${Math.round(s / 86400)} d ago`;
155
- return fmtDate(t);
156
- }
157
-
158
- // ---- Slideovers ---------------------------------------------------------------------
159
-
160
- /** Panels open (or opening) now, by key - so a double click opens one, not two. */
161
- const claimed = new Set();
162
-
163
- /**
164
- * Take `key` for a panel about to open. Null when it is already open or on its
165
- * way (the caller does nothing); else the release, which openPanel's `release`
166
- * option calls when the panel closes - call it yourself if the panel never opens.
167
- *
168
- * @returns {(() => void)|null}
169
- */
170
- export function claim(key) {
171
- if (claimed.has(key)) return null;
172
- claimed.add(key);
173
- let done = false;
174
- return () => { if (!done) { done = true; claimed.delete(key); } };
175
- }
176
-
177
- /**
178
- * E.confirm that goes when the screen does: leaving while it is open answers
179
- * it "no" (its Cancel is pressed) instead of leaving it over another screen.
180
- * Callers check the screen (or panel) is still there before acting on a "no".
181
- */
182
- export function ask(message, options = {}, ctx = null) {
183
- const answer = Promise.resolve(E.confirm(message, options));
184
- const overlay = [...document.querySelectorAll('.dm-dialog-overlay')].at(-1);
185
- const unhold = ctx?.hold?.(() => { try { overlay?.querySelector('.dm-dialog-cancel')?.click(); } catch { /* gone */ } });
186
- answer.finally(() => unhold?.()).catch(() => {});
187
- return answer;
188
- }
189
-
190
- // ---- Drafts (the stored side; the decisions are lib/drafts.js) -----------------------
191
-
192
- /** One stored map per signed-in person: a shared browser never offers one person's work to another. */
193
- function draftsKey() {
194
- let user = '';
195
- try { user = S.get('auth_user')?.id || ''; } catch { /* storage blocked */ }
196
- return `booking.drafts.${user || 'anyone'}`;
197
- }
198
- function readDrafts() {
199
- const map = store.get(draftsKey());
200
- return map && typeof map === 'object' && !Array.isArray(map) ? map : {};
201
- }
202
- export function getDraft(key) { return usableDraft(readDrafts()[key]); }
203
- export function allDrafts() { return readDrafts(); }
204
- export function putDraft(key, draft) {
205
- let map = readDrafts();
206
- for (const k of staleDraftKeys(map)) map = draftsWithout(map, k);
207
- store.set(draftsKey(), draftsWith(map, key, draft));
208
- }
209
- export function dropDraft(key) {
210
- const map = readDrafts();
211
- if (key in map) store.set(draftsKey(), draftsWithout(map, key));
212
- }
213
-
214
- /**
215
- * Open a slideover holding `html`, bound to `model`. Closing with something
216
- * changed asks first (once). Everything is disposed and removed on close.
217
- *
218
- * - `ctx` (the screen's): the panel goes when the screen does (`ctx.hold`),
219
- * keeping its draft, and it does not open at all if the screen went while
220
- * it was getting ready (`ctx.here`).
221
- * - `release` (from claim()) is called when it closes.
222
- * - `methods.save` is wrapped: the form is locked (inert) while it runs, so
223
- * nothing typed during a save that then closes the panel is lost; it is
224
- * unlocked - focus back where it was - when the panel stays open.
225
- * - `draft: {key, label, kind, values(), apply(values, panel), was, prefilled, initial}`
226
- * keeps what was typed (on every change, and when the tab closes) while the
227
- * panel is dirty, and offers it back the next time this form opens - put
228
- * back with a toast when the record is as it was, asked about when it was
229
- * saved since (`was` differs) or the form was opened for something specific
230
- * (`prefilled`). A draft is removed after a save, a discard, a "no" to the
231
- * question - never while the question is open, and never written again
232
- * once the panel has closed. A restored draft keeps its own `was`.
233
- * `label` (text, or a function) names it in the question; `kind` ("a new booking") is for 'prefilled'.
234
- * `initial`: a draft to put back straight away (one of a deleted record,
235
- * started again as new - its old key is the caller's to drop).
236
- *
237
- * @returns {Promise<{so, panel, close: (force?: boolean) => void}|null>} null when the screen went first
238
- */
239
- export async function openPanel({title, size = 'md', html, model = {}, methods = {}, dirty, cleanup = () => {}, before, after,
240
- ctx = null, release = () => {}, draft = null}) {
241
- const {onceClosed, helpPopovers} = await loadKit();
242
- if (ctx?.here && !ctx.here()) { release(); return null; }
243
-
244
- let so = null;
245
- let panel = null;
246
- let handle = null;
247
- let disposeHelp = null;
248
- let up = false; // onceClosed is wired: closing tidies (and releases) from here on
249
- let closed = false;
250
- let saving = false;
251
- // Drafts are written only once any stored one has been dealt with (restored, or answered).
252
- let drafting = false;
253
- let draftWas = draft?.was || '';
254
- const keepDraft = () => {
255
- if (!draft || !drafting || closed) return;
256
- if (dirty?.()) {
257
- const label = typeof draft.label === 'function' ? draft.label() : draft.label;
258
- putDraft(draft.key, {values: draft.values(), at: new Date().toISOString(), was: draftWas, label: label || ''});
259
- } else dropDraft(draft.key);
260
- };
261
- const queueKeep = () => queueMicrotask(keepDraft); // data-model handles the same event first
262
- const onUnload = () => keepDraft();
263
- let unhold = null;
264
-
265
- const wrapped = {...methods};
266
- if (methods.save) {
267
- wrapped.save = async (...args) => {
268
- if (saving || closed) return undefined;
269
- saving = true;
270
- const focus = document.activeElement;
271
- panel.inert = true;
272
- try {
273
- return await methods.save(...args);
274
- } finally {
275
- saving = false;
276
- if (!closed) {
277
- panel.inert = false;
278
- if (focus && panel.contains(focus)) { try { focus.focus(); } catch { /* gone */ } }
279
- queueKeep(); // saved and still open (the staff note): the draft goes with the changes
280
- }
281
- }
282
- };
283
- }
284
-
285
- // Anything that throws while the panel is built must not keep the claim, or leave a half-built
286
- // slideover: it is undone and released, and the error goes on to the caller.
287
- try {
288
- so = E.slideover({title: esc(title), size, position: 'right'});
289
- panel = fragment(html);
290
- so.element.appendChild(panel);
291
- before?.(panel);
292
- disposeHelp = helpPopovers(panel);
293
- handle = M.applyBindings(model, panel, {methods: wrapped});
294
- after?.(panel);
295
- onceClosed(so, () => {
296
- cleanup(); handle.dispose(); disposeHelp(); release();
297
- window.removeEventListener('beforeunload', onUnload);
298
- unhold?.();
299
- });
300
- up = true;
301
- } catch (err) {
302
- closed = true;
303
- try { handle?.dispose(); } catch { /* half built */ }
304
- try { disposeHelp?.(); } catch { /* half built */ }
305
- try { cleanup(); } catch { /* half built */ }
306
- try { so?.destroy?.(); } catch { /* gone */ }
307
- try { so?.element?.remove(); } catch { /* gone */ }
308
- release();
309
- throw err;
310
- }
311
-
312
- const close = so.close.bind(so);
313
- let asking = false;
314
- so.close = async (force) => {
315
- if (closed) return close();
316
- if (force !== true && saving) return undefined;
317
- if (force !== true && dirty?.()) {
318
- if (asking) return undefined;
319
- asking = true;
320
- const ok = await ask('Discard your changes?', {}, ctx);
321
- asking = false;
322
- if (!ok || closed) return undefined;
323
- }
324
- if (draft && drafting) dropDraft(draft.key);
325
- closed = true;
326
- return close();
327
- };
328
- try {
329
- // The screen going (another tab, another Tool, a remount): keep the draft, take the panel away.
330
- if (ctx?.hold) {
331
- unhold = ctx.hold(() => {
332
- if (closed) return;
333
- keepDraft();
334
- closed = true;
335
- close();
336
- });
337
- }
338
- panel.addEventListener('keydown', (e) => {
339
- if ((e.ctrlKey || e.metaKey) && (e.key === 'Enter' || e.key === 's') && wrapped.save) { e.preventDefault(); e.stopPropagation(); wrapped.save(); }
340
- });
341
- if (draft) {
342
- panel.addEventListener('input', queueKeep);
343
- panel.addEventListener('change', queueKeep);
344
- panel.addEventListener('click', queueKeep); // rows added or removed, slot buttons
345
- window.addEventListener('beforeunload', onUnload);
346
- }
347
- I.scan(panel);
348
- so.open();
349
- if (draft) offerDraft();
350
- } catch (err) {
351
- // Up, but failing: close it (onceClosed tidies and releases) - any stored draft is left alone.
352
- if (up && !closed) { closed = true; try { close(); } catch { /* gone */ } }
353
- throw err;
354
- }
355
- return {
356
- so, panel,
357
- close(force) {
358
- // A save that was running when the screen went has now succeeded (saves close with force):
359
- // the draft kept on leaving is saved work, so it goes.
360
- if (closed && force === true && saving && draft) { dropDraft(draft.key); return undefined; }
361
- return so.close(force);
362
- },
363
- /** The record was saved from this panel and it stays open (the staff note): drafts now start from `was`. */
364
- rebase(was) { draftWas = was || ''; }
365
- };
366
-
367
- function offerDraft() {
368
- // `asNew`: a deleted record's draft started again as a new one - nothing to compare it with now.
369
- const restore = (d, asNew = false) => {
370
- try { draft.apply(d.values, panel); } catch (err) { console.warn('[booking] draft not restored:', err); }
371
- draftWas = asNew ? (draft.was || '') : (d.was || '');
372
- // Rows the draft added (hours, closed days) carry icons: drawn once they have rendered.
373
- M.flushSync?.();
374
- I.scan(panel);
375
- requestAnimationFrame(() => { if (panel.isConnected) I.scan(panel); });
376
- };
377
- if (draft.initial) {
378
- restore(draft.initial, true);
379
- drafting = true;
380
- keepDraft();
381
- E.toast(restoreText('auto', {label: draft.initial.label, at: draft.initial.at, kind: draft.kind}), {type: 'info'});
382
- return;
383
- }
384
- const stored = getDraft(draft.key);
385
- const plan = restorePlan({draft: stored, was: draft.was || '', opening: draft.values(), prefilled: draft.prefilled});
386
- if (plan === 'none') {
387
- if (stored) dropDraft(draft.key);
388
- drafting = true;
389
- return;
390
- }
391
- if (plan === 'auto') {
392
- restore(stored);
393
- drafting = true;
394
- keepDraft();
395
- E.toast(restoreText('auto', {label: stored.label, at: stored.at, kind: draft.kind}), {type: 'info'});
396
- return;
397
- }
398
- // Discard is the confirm button; Cancel - which Escape and leaving also press - keeps the work.
399
- ask(esc(restoreText(plan, {label: stored.label, at: stored.at, kind: draft.kind})),
400
- {title: 'Unsaved changes', confirmText: plan === 'prefilled' ? 'Discard it' : 'Discard them', cancelText: plan === 'prefilled' ? 'Carry on with it' : 'Keep them'}, ctx)
401
- .then((discard) => {
402
- // Gone while asked (the screen changed): the draft stays for next time.
403
- if (closed) return;
404
- if (discard) dropDraft(draft.key); else restore(stored);
405
- drafting = true;
406
- keepDraft();
407
- });
408
- }
409
- }
410
-
411
- /**
412
- * Rows: click (or Enter) = the main action; right-click, ⋮ or Shift+F10 = the
413
- * menu. `scope` receives the teardown.
414
- */
415
- export function wireRows(list, {items, main, openMenuAt, scope, match = '.bk-row'}) {
416
- const menu = E.contextMenu(list, {cursor: 'glyph', match, inherit: false, density: 'compact',
417
- items: (row) => items(row.dataset.id, row)});
418
- const onClick = (e) => {
419
- const row = e.target.closest(match);
420
- if (!row) return;
421
- if (e.target.closest('[data-stop]')) return;
422
- const kebab = e.target.closest('.bk-kebab');
423
- if (kebab) { e.stopPropagation(); openMenuAt(row); return; }
424
- main(row.dataset.id, row);
425
- };
426
- const onKey = (e) => {
427
- const row = e.target.closest(match);
428
- if (!row) return;
429
- // Not the ContextMenu key: Chrome on Windows opens its own menu on that key's key-up, so the menu
430
- // appeared twice. That key's own contextmenu event reaches E.contextMenu anyway.
431
- if (e.key === 'F10' && e.shiftKey) { e.preventDefault(); openMenuAt(row); }
432
- else if ((e.key === 'Enter' || e.key === ' ') && e.target === row) { e.preventDefault(); main(row.dataset.id, row); }
433
- else if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && e.target === row) {
434
- e.preventDefault();
435
- const rows = [...list.querySelectorAll(match)].filter(r => r.offsetParent);
436
- rows[rows.indexOf(row) + (e.key === 'ArrowDown' ? 1 : -1)]?.focus();
437
- }
438
- };
439
- list.addEventListener('click', onClick);
440
- list.addEventListener('keydown', onKey);
441
- scope(() => { list.removeEventListener('click', onClick); list.removeEventListener('keydown', onKey); menu?.destroy?.(); });
442
- }
443
-
444
- /** Copy text, and say so. */
445
- export function copy(text, what = 'Copied') {
446
- navigator.clipboard?.writeText(text).then(() => E.toast(`${what}.`, {type: 'success'}), () => E.toast(text));
447
- }
448
-
449
- /** Checkboxes are set after render and listened to (data-model on a checkbox is unreliable). */
450
- export function wireChecks(el, obs) {
451
- for (const box of el.querySelectorAll('[data-bool]')) {
452
- const o = obs[box.dataset.bool];
453
- if (!o) continue;
454
- box.checked = Boolean(o.peek());
455
- box.addEventListener('change', () => { o.value = box.checked; });
456
- }
457
- }
458
-
459
- /** Show the server's per-field errors beside their inputs ([data-err="field"]). */
460
- export function showErrors(el, errors = {}) {
461
- for (const box of el.querySelectorAll('[data-err]')) {
462
- const msg = errors[box.dataset.err] || '';
463
- box.textContent = msg;
464
- box.hidden = !msg;
465
- }
466
- }
467
-
468
- /** H's error, with the server's `errors` map when it carried one. */
469
- export function errorsOf(err) {
470
- return err?.body?.errors || {};
471
- }
@@ -1 +0,0 @@
1
- <div class="bk" data-booking-admin></div>