domma-cms 1.35.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 (68) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/admin/js/api.js +1 -1
  3. package/admin/js/app.js +2 -2
  4. package/admin/js/lib/image-editor.js +1 -1
  5. package/admin/js/lib/media-arrange.js +1 -1
  6. package/admin/js/lib/media-picker.js +2 -2
  7. package/admin/js/lib/media-upload.js +1 -1
  8. package/admin/js/lib/seo-redirects.js +1 -1
  9. package/admin/js/templates/docs/usage-media.html +6 -0
  10. package/admin/js/templates/media.html +1 -0
  11. package/admin/js/views/media.js +3 -3
  12. package/bin/lib/left-free-tier.js +4 -1
  13. package/bin/update.js +4 -0
  14. package/docs/DommaFeatures.md +10 -5
  15. package/docs/plugin-development.md +2 -2
  16. package/package.json +1 -1
  17. package/plugins/docs/tests/plugin.test.js +2 -0
  18. package/plugins/free-tier.lock.json +2 -50
  19. package/server/routes/api/media.js +3 -1
  20. package/server/routes/api/sidebar.js +2 -2
  21. package/server/services/content.js +26 -2
  22. package/server/services/hooks.js +27 -4
  23. package/server/services/plugins.js +9 -3
  24. package/server/services/renderer.js +3 -1
  25. package/server/services/siteGitignore.js +1 -1
  26. package/plugins/booking/CLAUDE.md +0 -204
  27. package/plugins/booking/admin/css/index.css +0 -192
  28. package/plugins/booking/admin/lib/details.js +0 -58
  29. package/plugins/booking/admin/lib/diary-layout.js +0 -158
  30. package/plugins/booking/admin/lib/drafts.js +0 -139
  31. package/plugins/booking/admin/lib/email.js +0 -191
  32. package/plugins/booking/admin/lib/extension-sections.js +0 -160
  33. package/plugins/booking/admin/lib/kit.js +0 -471
  34. package/plugins/booking/admin/templates/booking.html +0 -1
  35. package/plugins/booking/admin/views/booking.js +0 -216
  36. package/plugins/booking/admin/views/bookings.js +0 -132
  37. package/plugins/booking/admin/views/diary.js +0 -382
  38. package/plugins/booking/admin/views/panels.js +0 -603
  39. package/plugins/booking/admin/views/people.js +0 -318
  40. package/plugins/booking/admin/views/services.js +0 -264
  41. package/plugins/booking/admin/views/settings.js +0 -222
  42. package/plugins/booking/collections/booking-bookables.json +0 -17
  43. package/plugins/booking/collections/booking-bookings.json +0 -18
  44. package/plugins/booking/collections/booking-services.json +0 -17
  45. package/plugins/booking/config.js +0 -36
  46. package/plugins/booking/docs/guide.md +0 -73
  47. package/plugins/booking/inject/body.html +0 -1
  48. package/plugins/booking/lib/call.js +0 -88
  49. package/plugins/booking/lib/extensions.js +0 -169
  50. package/plugins/booking/lib/mail.js +0 -113
  51. package/plugins/booking/lib/store.js +0 -392
  52. package/plugins/booking/plugin.js +0 -905
  53. package/plugins/booking/plugin.json +0 -81
  54. package/plugins/booking/plugin.public.js +0 -175
  55. package/plugins/booking/public/booking.css +0 -159
  56. package/plugins/booking/public/booking.js +0 -808
  57. package/plugins/booking/public/lib/clean.js +0 -141
  58. package/plugins/booking/public/lib/page-format.js +0 -121
  59. package/plugins/booking/public/lib/slots.js +0 -247
  60. package/plugins/booking/public/lib/time.js +0 -131
  61. package/plugins/booking/templates/booking.html +0 -5
  62. package/plugins/booking/tests/admin-diary.test.js +0 -81
  63. package/plugins/booking/tests/admin-drafts.test.js +0 -67
  64. package/plugins/booking/tests/api.test.js +0 -651
  65. package/plugins/booking/tests/email.test.js +0 -69
  66. package/plugins/booking/tests/public.test.js +0 -72
  67. package/plugins/booking/tests/pure.test.js +0 -189
  68. package/plugins/booking/tests/seo.test.js +0 -71
@@ -1,382 +0,0 @@
1
- /**
2
- * Booking › Diary.
3
- *
4
- * A day (one column per person or room) or a week (one column per day), in
5
- * the business's time zone. Opening hours are the light bands; outside them
6
- * is shaded. A booking is a block: click opens it, right-click / ⋮ /
7
- * Shift+F10 is its menu. Click an empty time to book it. The first time
8
- * round, a checklist says what to set up.
9
- *
10
- * domma-reactive throughout: the heads, the hour gutter and the columns (each
11
- * with its open bands and blocks) are keyed lists fed from one `draw` effect
12
- * that works the geometry out in JS (diary-layout.js); the markup only binds.
13
- */
14
-
15
- import {STATUS_LABEL, V, api, claim, copy, errText, esc, openPanel, store, wireRows} from '../lib/kit.js';
16
- import {columnItems, dayLabel, datesFor, gridHours, layoutColumn, mergeWindows, minuteAt, placeOf} from '../lib/diary-layout.js';
17
- import {withNames} from '../lib/details.js';
18
- import {addDays, atWallClock, fromMinutes, isDate, wallClock} from '/plugins/booking/public/lib/time.js';
19
- import {windowsOn} from '/plugins/booking/public/lib/slots.js';
20
-
21
- const PX_PER_MIN = 1; // an hour is 60px
22
- const VIEW_KEY = 'booking.diary-view';
23
- const CANCELLED_KEY = 'booking.diary-cancelled';
24
- const CHECKLIST_KEY = 'booking.checklist-hidden';
25
- const STATUS_NOTE = {completed: 'done', 'no-show': 'no-show', cancelled: 'cancelled', pending: 'pending'};
26
-
27
- // A first-run step. The two icon wrappers swap with `done` (I.scan replaces the icon span itself).
28
- const STEP = `
29
- <li data-bind-class="done && 'is-done'">
30
- <span class="bk-step-icon" data-bind-hidden="!done"><span data-icon="check-circle" data-icon-size="14"></span></span>
31
- <span class="bk-step-icon" data-bind-hidden="done"><span data-icon="circle" data-icon-size="14"></span></span>
32
- <button type="button" class="bk-link" data-on-click="$parent.step($data)" data-bind-text="text"></button>
33
- </li>`;
34
-
35
- // A column heading: a person or room (day view) or a day (week view, a link to it).
36
- const HEAD = `
37
- <div class="bk-col-head" data-bind-class="cls" data-bind-data-colour="colour" data-bind-data-date="date" data-bind-title="tip">
38
- <span class="bk-kind" data-bind-hidden="kind !== 'person'"><span data-icon="user" data-icon-size="13"></span></span>
39
- <span class="bk-kind" data-bind-hidden="kind !== 'resource'"><span data-icon="box" data-icon-size="13"></span></span>
40
- <span data-bind-text="title"></span>
41
- </div>`;
42
-
43
- const HOUR = `<span data-bind-style-top="top" data-bind-text="text"></span>`;
44
-
45
- // A column: its open bands, the now line and its blocks. Every measure is a CSS length worked out in draw().
46
- const COL = `
47
- <div class="bk-col" data-bind-data-date="date" data-bind-data-bookable="bookableId" title="Click an empty time to book it">
48
- {{#each windows key=id}}<div class="bk-open" data-bind-style-top="top" data-bind-style-background-position-y="bgY" data-bind-style-height="height"></div>{{/each}}
49
- <div class="bk-now" data-bind-hidden="!nowTop" data-bind-style-top="nowTop"></div>
50
- {{#each blocks key=id}}<div class="bk-block" data-bind-data-id="id" data-bind-class="cls" data-bind-data-colour="colour" data-bind-title="tip" tabindex="0" role="button"
51
- data-bind-style-top="top" data-bind-style-height="height" data-bind-style-left="left" data-bind-style-width="width">
52
- <button type="button" class="bk-kebab" aria-label="Actions" title="Actions">⋮</button>
53
- <strong data-bind-text="head"></strong><small data-bind-text="sub"></small>
54
- </div>{{/each}}
55
- </div>`;
56
-
57
- export async function mount(root, ctx) {
58
- const {kit, scope, here, boot} = ctx;
59
- const panels = await import(`/plugins/booking/admin/views/panels.js?v=${V}`);
60
- if (!here()) return undefined;
61
-
62
- const view = M.observable(store.get(VIEW_KEY) === 'week' ? 'week' : 'day');
63
- const date = M.observable(boot.today);
64
- const showCancelled = M.observable(store.get(CANCELLED_KEY) === true);
65
- const bookings = M.observable([]);
66
- /** Class sessions drawn as one block: key -> their bookings. */
67
- const sessions = new Map();
68
- const loading = M.observable(true);
69
- // Only the first load hides the grid behind a skeleton; moving a day or a week keeps it on screen.
70
- const firstLoad = M.observable(true);
71
- const error = M.observable('');
72
- const label = M.observable('');
73
- // What the grid shows, as rows for the keyed lists.
74
- const hasBookables = M.observable(boot.bookables.length > 0);
75
- const hasServices = M.observable(boot.services.length > 0);
76
- const heads = M.observable([]);
77
- const hours = M.observable([]);
78
- const cols = M.observable([]);
79
- const gridCols = M.observable('1');
80
- const gridH = M.observable('0px');
81
- const steps = M.observable([]);
82
- const checklistOn = M.observable(false);
83
- scope(M.effect(() => store.set(VIEW_KEY, view.value)));
84
- scope(M.effect(() => store.set(CANCELLED_KEY, showCancelled.value)));
85
-
86
- root.innerHTML = '';
87
- const card = document.createElement('div');
88
- card.className = 'bk-card bk-diary';
89
- card.innerHTML = `
90
- <div class="bk-checklist" data-bind-hidden="!checklistOn.value">
91
- <header><h3><span data-icon="clipboard-list" data-icon-size="15"></span> Getting started</h3>
92
- <button type="button" class="btn btn-xs btn-ghost" data-on-click="hideChecklist" title="Hide this list">Hide</button></header>
93
- <ol data-each="steps.value key=id">${STEP}</ol>
94
- </div>
95
- <div class="bk-bar">
96
- <div class="bk-seg" role="group" aria-label="View">
97
- <button type="button" data-view="day" data-bind-class="view.value === 'day' && 'is-on'">Day</button>
98
- <button type="button" data-view="week" data-bind-class="view.value === 'week' && 'is-on'">Week</button>
99
- </div>
100
- <div class="bk-seg" role="group" aria-label="Move">
101
- <button type="button" data-step="-1" title="Earlier" aria-label="Earlier"><span data-icon="chevron-left" data-icon-size="12"></span></button>
102
- <button type="button" data-step="0">Today</button>
103
- <button type="button" data-step="1" title="Later" aria-label="Later"><span data-icon="chevron-right" data-icon-size="12"></span></button>
104
- </div>
105
- <input type="date" class="form-input bk-date" aria-label="Go to date" data-part="date">
106
- <strong class="bk-when" data-bind-text="label.value"></strong>
107
- <span class="bk-spacer"></span>
108
- <label class="bk-check"><input type="checkbox" data-part="cancelled"> Show cancelled</label>
109
- <span data-help-title="The Diary" data-help="Bookings in your business's time zone (${esc(ctx.tz)}). Hatched times are outside opening hours. Click a booking to open it; right-click it (or ⋮, or Shift+F10) for Move, Done, No-show and Cancel. Click an empty time to book it. Keys: ← → earlier and later, T today, D day, W week."></span>
110
- </div>
111
- <p class="bk-note is-bad" data-bind-hidden="!error.value" data-bind-text="error.value"></p>
112
- <div class="bk-note bk-loading-slot dm-loading-slot" data-bind-hidden="!firstLoad.value || !hasBookables.value">Loading…</div>
113
- <div class="bk-diary-wrap" data-part="grid" tabindex="-1" data-bind-hidden="firstLoad.value && hasBookables.value">
114
- <div class="bk-empty" data-bind-hidden="hasBookables.value"><span data-icon="users" data-icon-size="28"></span>
115
- <p><strong>Add who or what can be booked.</strong><br>A person (for appointments) or a room or thing - each with their opening hours.</p>
116
- <button type="button" class="btn btn-sm btn-primary" data-on-click="addPerson"><span data-icon="plus" data-icon-size="13"></span> Add a person or room</button></div>
117
- <p class="bk-note" data-bind-hidden="!hasBookables.value || hasServices.value">Next: <button type="button" class="bk-link" data-on-click="addService">add a service</button> - what can be booked, for how long, and with whom.</p>
118
- <div class="bk-diary-grid" data-bind-hidden="!hasBookables.value" data-bind-class="'is-' + view.value"
119
- data-bind-style---bk-cols="gridCols.value" data-bind-style---bk-h="gridH.value" style="--bk-hour: ${60 * PX_PER_MIN}px">
120
- <div class="bk-diary-head" data-part="heads"><span></span><div class="bk-heads" data-each="heads.value key=key">${HEAD}</div></div>
121
- <div class="bk-diary-body">
122
- <div class="bk-gutter" data-each="hours.value key=id">${HOUR}</div>
123
- <div class="bk-cols" data-each="cols.value key=key">${COL}</div>
124
- </div>
125
- </div>
126
- </div>`;
127
- root.appendChild(card);
128
- const gridBox = card.querySelector('[data-part="grid"]');
129
- const dateIn = card.querySelector('[data-part="date"]');
130
- const cancelledBox = card.querySelector('[data-part="cancelled"]');
131
- scope(kit.helpPopovers(card, {position: 'bottom'}));
132
- const model = {
133
- view, label, error, firstLoad, hasBookables, hasServices, heads, hours, cols, gridCols, gridH, steps, checklistOn,
134
- hideChecklist() { store.set(CHECKLIST_KEY, true); checklistOn.value = false; },
135
- step(s) { s.go(); },
136
- addPerson: () => ctx.go('people', 'new'),
137
- addService: () => ctx.go('services', 'new')
138
- };
139
- const bindings = M.applyBindings(model, card);
140
- scope(() => bindings.dispose());
141
- I.scan(card);
142
- // Heads come and go with the view; their icons are drawn once the rows are in.
143
- scope(M.effect(() => { heads.value; steps.value; requestAnimationFrame(() => { if (card.isConnected) I.scan(card); }); }));
144
-
145
- cancelledBox.checked = showCancelled.peek();
146
- cancelledBox.addEventListener('change', () => { showCancelled.value = cancelledBox.checked; });
147
- dateIn.value = date.peek();
148
- dateIn.addEventListener('change', () => { if (isDate(dateIn.value)) date.value = dateIn.value; });
149
-
150
- const step = (n) => {
151
- if (n === 0) { date.value = boot.today; return; }
152
- date.value = addDays(date.peek(), n * (view.peek() === 'week' ? 7 : 1));
153
- };
154
- card.querySelector('.bk-bar').addEventListener('click', (e) => {
155
- const v = e.target.closest('[data-view]');
156
- if (v) view.value = v.dataset.view;
157
- const s = e.target.closest('[data-step]');
158
- if (s) step(Number(s.dataset.step));
159
- });
160
- // A week head is a link to its day.
161
- card.querySelector('[data-part="heads"]').addEventListener('click', (e) => {
162
- const h = e.target.closest('.bk-col-head[data-date]');
163
- if (h) { date.value = h.dataset.date; view.value = 'day'; }
164
- });
165
- const onKey = (e) => {
166
- if (e.defaultPrevented || e.ctrlKey || e.metaKey || e.altKey) return;
167
- if (e.target.closest('input, textarea, select, [contenteditable], .dm-slideover, [role="dialog"]')) return;
168
- if (!root.isConnected) return;
169
- const k = e.key.toLowerCase();
170
- if (e.key === 'ArrowLeft') step(-1);
171
- else if (e.key === 'ArrowRight') step(1);
172
- else if (k === 't') step(0);
173
- else if (k === 'd') view.value = 'day';
174
- else if (k === 'w') view.value = 'week';
175
- else return;
176
- e.preventDefault();
177
- };
178
- document.addEventListener('keydown', onKey);
179
- scope(() => document.removeEventListener('keydown', onKey));
180
-
181
- // ---- The first-run checklist --------------------------------------------------
182
-
183
- function drawChecklist() {
184
- const list = [
185
- {id: 'people', done: boot.bookables.length > 0, text: 'Add who or what can be booked - a person or a room', go: () => ctx.go('people', 'new')},
186
- {id: 'services', done: boot.services.length > 0, text: 'Add a service: what can be booked, for how long, and with whom', go: () => ctx.go('services', 'new')},
187
- {id: 'settings', done: store.get('booking.settings-seen') === true, text: boot.mailReady ? 'Check the settings: your booking page, notice rules and emails' : 'Check the settings - and set up outgoing mail, or no confirmation emails are sent',
188
- go: () => { store.set('booking.settings-seen', true); ctx.openSettings(); drawChecklist(); }},
189
- {id: 'share', done: store.get('booking.link-shared') === true, text: `Share your booking page: ${location.origin}${ctx.settings.bookingPath}`,
190
- go: () => { store.set('booking.link-shared', true); copy(`${location.origin}${ctx.settings.bookingPath}`, 'Booking page address copied'); drawChecklist(); }}
191
- ];
192
- steps.value = list;
193
- checklistOn.value = list.some(s => !s.done) && store.get(CHECKLIST_KEY) !== true;
194
- }
195
- drawChecklist();
196
-
197
- // ---- Loading ----------------------------------------------------------------
198
-
199
- const dates = () => datesFor(view.peek(), date.peek());
200
- let seq = 0;
201
- async function load() {
202
- const ds = dates();
203
- const my = ++seq;
204
- loading.value = true;
205
- try {
206
- const from = atWallClock(ds[0], 0, ctx.tz).toISOString();
207
- const to = atWallClock(addDays(ds[ds.length - 1], 1), 0, ctx.tz).toISOString();
208
- const slot = firstLoad.peek() && hasBookables.peek() ? card.querySelector('.bk-loading-slot') : null;
209
- const list = await (slot ? kit.whileLoading(slot, api.bookings.list({from, to}), kit.SHAPES.table) : api.bookings.list({from, to}));
210
- if (my !== seq || !here()) return;
211
- bookings.value = Array.isArray(list) ? list : [];
212
- error.value = '';
213
- } catch (err) {
214
- if (my === seq && here()) error.value = `The diary could not load: ${errText(err)}`;
215
- } finally {
216
- if (my === seq) { loading.value = false; firstLoad.value = false; }
217
- }
218
- }
219
- ctx.onBookingsChanged = () => { if (here()) load(); };
220
- scope(() => { ctx.onBookingsChanged = () => {}; });
221
- scope(M.effect(() => { view.value; date.value; dateIn.value = date.value; load(); }));
222
-
223
- // ---- Drawing ---------------------------------------------------------------
224
-
225
- function columns() {
226
- const ds = dates();
227
- const active = boot.bookables.filter(b => b.active !== false);
228
- if (view.peek() === 'week') {
229
- return ds.map(d => ({key: d, date: d, title: dayLabel(d), today: d === boot.today, windows: mergeWindows(active.flatMap(b => windowsOn(b, d, ctx.settings.closures)))}));
230
- }
231
- const d = ds[0];
232
- const used = new Set(bookings.peek().flatMap(b => (Array.isArray(b.holds) && b.holds.length ? b.holds : [b.bookableId])));
233
- const shown = boot.bookables.filter(b => b.active !== false || used.has(b.id));
234
- return shown.map(b => ({key: b.id, date: d, bookableId: b.id, title: b.name, colour: b.colour, kind: b.kind, today: d === boot.today,
235
- windows: windowsOn(b, d, ctx.settings.closures)}));
236
- }
237
-
238
- const px = (n) => `${n}px`;
239
-
240
- /** One block's row: where it sits and what it says. */
241
- function blockRow(p, {from, to, week, colours}) {
242
- const b = p.b;
243
- let id = b.id;
244
- if (p.session) { sessions.set(p.key, p.bookings); id = `session:${p.key}`; }
245
- const s = wallClock(b.startAt, ctx.tz).time;
246
- const e = wallClock(b.endAt, ctx.tz).time;
247
- const time = week ? s : `${s}-${e}`;
248
- const statusNote = b.status !== 'confirmed' ? ` · ${STATUS_NOTE[b.status] || b.status}` : '';
249
- let head;
250
- let sub;
251
- let tip;
252
- if (p.session) {
253
- // A class: one block for everyone in it.
254
- head = `${time} ${b.serviceName} · ${p.bookings.length} booked`;
255
- sub = `${p.companion ? `with ${b.bookableName}` : p.bookings.map(x => x.name).join(', ')}${week && b.bookableName ? ` · ${b.bookableName}` : ''}`;
256
- tip = `${s}-${e} ${b.serviceName}: ${p.bookings.length} booked${b.bookableName ? ` (with ${withNames(b)})` : ''}`;
257
- } else if (p.companion) {
258
- // Held along with someone else's booking (a court with the trainer).
259
- head = `${time} ${b.name}`;
260
- sub = `${b.serviceName} · with ${b.bookableName}${statusNote}`;
261
- tip = `${s}-${e} ${b.serviceName}: ${b.name} - held with ${b.bookableName}'s booking`;
262
- } else {
263
- head = `${time} ${b.name}`;
264
- sub = `${b.serviceName}${week && b.bookableName ? ` · ${withNames(b)}` : b.alsoNames?.length ? ` · with ${b.alsoNames.join(', ')}` : ''}${statusNote}`;
265
- tip = `${s}-${e} ${b.serviceName}: ${b.name}${withNames(b) ? ` (with ${withNames(b)})` : ''}`;
266
- }
267
- return {
268
- id, head, sub, tip,
269
- cls: `is-${b.status}${p.companion ? ' is-companion' : ''}${p.session ? ' is-session' : ''}`,
270
- colour: colours.get(b.bookableId) || 'grey',
271
- top: px((Math.max(p.startMin, from) - from) * PX_PER_MIN),
272
- height: px(Math.max(18, (Math.min(p.endMin, to) - Math.max(p.startMin, from)) * PX_PER_MIN - 2)),
273
- left: `calc(${(p.lane / p.lanes) * 100}% + 2px)`,
274
- width: `calc(${100 / p.lanes}% - 4px)`
275
- };
276
- }
277
-
278
- function draw() {
279
- const list = bookings.value.filter(b => showCancelled.value || b.status !== 'cancelled');
280
- const week = view.value === 'week';
281
- const ds = datesFor(view.value, date.value);
282
- label.value = week ? `${dayLabel(ds[0])} - ${dayLabel(ds[6])} ${ds[6].slice(0, 4)}` : `${dayLabel(ds[0])} ${ds[0].slice(0, 4)}`;
283
- hasBookables.value = boot.bookables.length > 0;
284
- hasServices.value = boot.services.length > 0;
285
- sessions.clear();
286
- if (!boot.bookables.length) { heads.value = []; hours.value = []; cols.value = []; return; }
287
- const defs = columns();
288
- const colours = new Map(boot.bookables.map(b => [b.id, b.colour || 'blue']));
289
- const placed = list.map(b => ({b, ...placeOf(b, ctx.tz)})).filter(p => ds.includes(p.date));
290
- const {from, to} = gridHours(boot.bookables.filter(b => b.active !== false), ds, placed);
291
- gridCols.value = String(defs.length);
292
- gridH.value = px((to - from) * PX_PER_MIN);
293
-
294
- heads.value = defs.map(c => ({
295
- key: c.key, title: c.title, kind: c.kind || '', colour: c.colour || false,
296
- cls: [c.today && week ? 'is-today' : '', week ? 'bk-link-head' : ''].filter(Boolean).join(' '),
297
- date: week ? c.date : false, tip: week ? 'Show this day' : false
298
- }));
299
- const gutter = [];
300
- for (let m = from; m < to; m += 60) gutter.push({id: m, top: px((m - from) * PX_PER_MIN), text: fromMinutes(m)});
301
- hours.value = gutter;
302
-
303
- const nowWall = wallClock(Date.now(), ctx.tz);
304
- cols.value = defs.map(c => {
305
- const windows = c.windows.map((w, i) => {
306
- // The band keeps its hour lines on the column's.
307
- const bandTop = (Math.max(w.from, from) - from) * PX_PER_MIN;
308
- return {id: `w${i}`, top: px(bandTop), bgY: px(-bandTop), height: px((Math.min(w.to, to) - Math.max(w.from, from)) * PX_PER_MIN)};
309
- });
310
- const nowTop = c.date === nowWall.date && nowWall.minutes >= from && nowWall.minutes <= to ? px((nowWall.minutes - from) * PX_PER_MIN) : '';
311
- const dayBookings = placed.filter(p => p.date === c.date).map(p => p.b);
312
- const items = columnItems(dayBookings, {bookableId: c.bookableId || ''}).map(it => ({...it, ...placeOf(it.b, ctx.tz)}));
313
- const blocks = layoutColumn(items).map(p => blockRow(p, {from, to, week, colours}));
314
- return {key: c.key, date: c.date, bookableId: c.bookableId || false, windows, nowTop, blocks};
315
- });
316
- }
317
- scope(M.effect(draw));
318
-
319
- // A click on an empty time books it.
320
- gridBox.addEventListener('click', (e) => {
321
- if (e.target.closest('.bk-block')) return;
322
- const col = e.target.closest('.bk-col');
323
- if (!col) return;
324
- const rect = col.getBoundingClientRect();
325
- const {from} = gridHours(boot.bookables.filter(b => b.active !== false), datesFor(view.peek(), date.peek()),
326
- bookings.peek().map(b => placeOf(b, ctx.tz)).filter(p => datesFor(view.peek(), date.peek()).includes(p.date)));
327
- const minute = minuteAt(e.clientY - rect.top, {from, pxPerMin: PX_PER_MIN});
328
- ctx.newBooking({date: col.dataset.date, time: fromMinutes(minute), bookableId: col.dataset.bookable || ''});
329
- });
330
-
331
- const byId = (id) => bookings.peek().find(b => b.id === id);
332
- const sessionOf = (id) => (id.startsWith('session:') ? sessions.get(id.slice(8)) || [] : null);
333
-
334
- /** A class: who is in it, each opening their booking. */
335
- async function openSession(list) {
336
- if (!list.length) return;
337
- const release = claim('session');
338
- if (!release) return;
339
- const first = list[0];
340
- const s = wallClock(first.startAt, ctx.tz);
341
- const e = wallClock(first.endAt, ctx.tz);
342
- let panel = null;
343
- panel = await openPanel({
344
- title: `${first.serviceName}, ${s.time}-${e.time}`,
345
- size: 'sm',
346
- ctx, release,
347
- html: `<div class="bk-form">
348
- <p class="bk-muted">${esc(dayLabel(s.date))}${first.bookableName ? ` · with ${esc(withNames(first))}` : ''} · ${list.length} booked</p>
349
- <div class="bk-list bk-session-list">${list.map(b => `<button type="button" class="bk-row" data-open="${esc(b.id)}">
350
- <span class="bk-main"><strong>${esc(b.name)}</strong><small>${esc([b.email, b.phone].filter(Boolean).join(' · '))}</small></span>
351
- <span class="bk-chip">${esc(STATUS_LABEL[b.status] || b.status)}</span></button>`).join('')}</div>
352
- </div>`,
353
- after: (el) => {
354
- el.addEventListener('click', (ev) => {
355
- const row = ev.target.closest('[data-open]');
356
- if (!row) return;
357
- panel?.close(true);
358
- ctx.openBooking(row.dataset.open);
359
- });
360
- setTimeout(() => el.querySelector('[data-open]')?.focus(), 60);
361
- }
362
- });
363
- }
364
-
365
- wireRows(gridBox, {
366
- match: '.bk-block',
367
- openMenuAt: kit.openMenuAt,
368
- scope,
369
- main: (id) => { const list = sessionOf(id); return list ? openSession(list) : ctx.openBooking(id); },
370
- items: (id) => {
371
- const list = sessionOf(id);
372
- if (!list) return panels.bookingMenu(ctx, byId(id));
373
- return [
374
- {label: `Everyone in it (${list.length})`, icon: 'users', action: () => openSession(list)},
375
- {type: 'divider'},
376
- ...list.map(b => ({label: `Open ${b.name}`, icon: 'external-link', action: () => ctx.openBooking(b.id)}))
377
- ];
378
- }
379
- });
380
-
381
- return () => {};
382
- }