@gecko-ui-kit/vue 0.0.0-stage → 0.3.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.
package/src/data.js ADDED
@@ -0,0 +1,718 @@
1
+ /* Data display from @gecko-ui-kit/components as Vue components: Accordion, Carousel, BeforeAfter, Tree,
2
+ DataGrid, VirtualList, Timeline, Calendar, SwipeItem + SwipeActions, Kanban, Notifications, Activity,
3
+ Pagination, Breadcrumbs, Skeleton, Alert.
4
+ Most are mounted pieces: the vanilla code builds and animates them inside one element. Where the content is
5
+ the app's own (accordion panels, slides, pictures, kanban cards, list rows, the alert message, what a
6
+ skeleton covers) it comes from your slots and is drawn by Vue with <Teleport> into the elements the vanilla
7
+ piece made (only in the browser, after mount, so the server HTML and hydration always match).
8
+ Data changes (rows, events, cards, items…) are applied in place with the piece's own methods, so its
9
+ motion plays (a new card grows in, a removed one folds away) instead of the whole thing being drawn again. */
10
+ import { defineComponent, ref, shallowRef, watch, onMounted, onBeforeUnmount, Teleport, Fragment, Comment, Text, isVNode } from 'vue';
11
+ import * as C from '@gecko-ui-kit/components';
12
+ import { h, B, ANY, anyProps, iconNode, mounted, changedOnly, same, modelProps } from './core.js';
13
+
14
+ /* ---------------- shared helpers ---------------- */
15
+
16
+ /** Per-handle notes (quiet flag, extra elements) without touching the vanilla handle. */
17
+ const notes = new WeakMap();
18
+ const note = (handle) => { let n = notes.get(handle); if (!n) notes.set(handle, n = {}); return n; };
19
+ /** Run fn with the piece's own callbacks muted (a prop change is not a user change). */
20
+ const quietly = (handle, fn) => { const n = note(handle); n.quiet = true; try { return fn(); } finally { n.quiet = false; } };
21
+ const isQuiet = (handle) => !!(handle && notes.get(handle)?.quiet);
22
+ /** Drop our own (Vue-only) keys before options reach the vanilla code. */
23
+ const without = (o, keys) => { const r = { ...o }; keys.forEach((k) => delete r[k]); return r; };
24
+ /** A prop that is true / false or a word ('auto', 'view'); `<Activity intro>` still gives true. */
25
+ const BS = { type: [Boolean, String], default: undefined };
26
+
27
+ /* Holders: elements inside a mounted piece that Vue draws slot content into (<Teleport>).
28
+ The inner (mounted) component reports Map<key, { el, item?, index? }> after each mount or in-place change;
29
+ the outer one renders one Teleport per entry. */
30
+ const sameMap = (a, b) => {
31
+ if (a === b) return true;
32
+ if (!a || !b || a.size !== b.size) return false;
33
+ for (const [k, v] of a) { const w = b.get(k); if (!w || w.el !== v.el || w.item !== v.item || w.index !== v.index) return false; }
34
+ return true;
35
+ };
36
+ /** Map of key → { el } from elements found in a root. */
37
+ const slotMap = (pairs) => new Map(pairs.filter(([, el]) => el).map(([k, el]) => [k, { el }]));
38
+ /** One Teleport per holder: draw(key, entry) → nodes (or nothing). */
39
+ const teleports = (map, draw) => (map ? [...map].map(([k, s]) => {
40
+ const n = draw(k, s);
41
+ return n == null || n === false || n === '' ? null : h(Teleport, { key: k, to: s.el }, Array.isArray(n) ? n : [n]);
42
+ }) : []);
43
+ /** A template ref that forwards to another component's template ref (the inner piece's handle). */
44
+ const forward = (r) => new Proxy({}, {
45
+ get(t, k) { if (k in t) return t[k]; const x = r.value; return x == null ? undefined : x[k]; },
46
+ has(t, k) { if (k in t) return true; const x = r.value; return x != null && k in x; },
47
+ });
48
+ /** Slot content as a flat list: v-for fragments opened up, comments and blank text dropped. */
49
+ const flatNodes = (nodes) => (nodes == null ? [] : Array.isArray(nodes) ? nodes : [nodes]).flatMap((n) => {
50
+ if (!isVNode(n)) return n == null || n === false || n === '' ? [] : [n];
51
+ if (n.type === Fragment) return flatNodes(n.children);
52
+ if (n.type === Comment) return [];
53
+ if (n.type === Text && !String(n.children).trim()) return [];
54
+ return [n];
55
+ });
56
+
57
+ /**
58
+ * An outer component around a mounted piece (Inner) whose holders get slot content:
59
+ * render(props, slots, state) → { props: extra props for Inner, draw(key, entry) → nodes for that holder }
60
+ * setup(props, innerRef, mapRef) → state (optional, once per instance)
61
+ * Every prop Inner knows and every attribute is passed on to Inner (class, style… land on the piece's element), and a
62
+ * template ref on the outer component is Inner's handle.
63
+ */
64
+ function slotted(name, Inner, props, render, setup) {
65
+ return defineComponent({
66
+ name,
67
+ inheritAttrs: false,
68
+ props,
69
+ setup(p, { slots, attrs, expose }) {
70
+ const inner = shallowRef(null), map = shallowRef(null);
71
+ const report = (m) => { if (!sameMap(map.value, m)) map.value = m; };
72
+ expose(forward(inner));
73
+ const state = setup?.(p, inner, map);
74
+ return () => {
75
+ const r = render(p, slots, state);
76
+ const pass = {};
77
+ for (const k in p) if (k in Inner.props) pass[k] = p[k];
78
+ return [h(Inner, { ...attrs, ...pass, ...r.props, report, ref: inner }), ...teleports(map.value, r.draw)];
79
+ };
80
+ },
81
+ });
82
+ }
83
+
84
+ /* ---------------- Accordion ---------------- */
85
+
86
+ const ACC_PROPS = { ...anyProps('look', 'marker', 'level'), multiple: B, collapsible: B, onToggle: Function };
87
+ const AccordionInner = mounted('Accordion', (el, o) => {
88
+ const open = new Set([].concat(o.value ?? o.defaultValue ?? []).map(String));
89
+ const useValue = o.value !== undefined || o.defaultValue !== undefined;
90
+ const items = (o.items || []).map((it, i) => ({ ...it, id: String(it.id ?? i + 1), open: useValue ? open.has(String(it.id ?? i + 1)) : it.open }));
91
+ let pending = false;
92
+ const acc = C.accordion(el, {
93
+ ...without(o, ['report', 'value', 'defaultValue', 'onChange', 'nodeTitles']), items,
94
+ onToggle: (id, isOpen, a) => {
95
+ if (isQuiet(a)) return;
96
+ o.onToggle?.(id, isOpen, a);
97
+ if (!pending) { pending = true; queueMicrotask(() => { pending = false; if (notes.has(a) && !note(a).dead) o.onChange?.(a.value, a); }); }
98
+ },
99
+ });
100
+ note(acc);
101
+ o.report?.(slotMap(acc?.root ? [...acc.root.querySelectorAll(':scope > .gk-acc__item')].flatMap((it) => [
102
+ [`b:${it.dataset.id}`, it.querySelector('.gk-acc__body')],
103
+ ...(o.nodeTitles?.includes(it.dataset.id) ? [[`t:${it.dataset.id}`, it.querySelector('.gk-acc__title')]] : []),
104
+ ]) : []));
105
+ const destroy = acc.destroy;
106
+ return Object.assign(acc, { destroy() { note(acc).dead = true; destroy(); } });
107
+ }, {
108
+ props: { ...ACC_PROPS, ...anyProps('items', 'nodeTitles'), report: Function },
109
+ model: { event: 'onChange' },
110
+ update(acc, next, prev) {
111
+ if (changedOnly(next, prev, ['defaultValue'])) return true;
112
+ if (changedOnly(next, prev, ['value', 'defaultValue'])) {
113
+ const want = new Set([].concat(next.value ?? []).map(String));
114
+ quietly(acc, () => {
115
+ acc.value.filter((id) => !want.has(id)).forEach((id) => acc.close(id));
116
+ want.forEach((id) => { if (!acc.isOpen(id)) acc.open(id); });
117
+ });
118
+ return true;
119
+ }
120
+ return false;
121
+ },
122
+ });
123
+
124
+ /**
125
+ * <Accordion v-model="open" :items="[{ id: 'pay', title: 'Payment', sub: 'Cash or card' }, …]">
126
+ * <template #content="{ item }"><PaymentForm v-if="item.id === 'pay'" /></template>
127
+ * </Accordion>
128
+ * Same as accordion(el, options). Each panel shows the #content slot (or the item's `content` text);
129
+ * a #title slot draws every heading instead of the `title` text. Both get { item, index }.
130
+ * v-model (or default-value): the open ids. @change(openIds, acc) · @toggle(id, open, acc).
131
+ * ref → the handle (open, close, closeAll, filter…).
132
+ */
133
+ export const Accordion = slotted('Accordion', AccordionInner, {
134
+ ...ACC_PROPS, items: { type: Array, default: () => [] }, ...modelProps(), onChange: Function,
135
+ }, (p, slots) => {
136
+ const items = p.items || [];
137
+ const ids = items.map((it, i) => String(it.id ?? i + 1));
138
+ const data = items.map(({ content, title, ...it }, i) => ({ ...it, id: ids[i], title: slots.title || title == null ? '' : String(title) }));
139
+ return {
140
+ props: { items: data, nodeTitles: slots.title ? ids : [] },
141
+ draw: (k) => {
142
+ const i = ids.indexOf(k.slice(2));
143
+ if (i < 0) return null;
144
+ const scope = { item: items[i], index: i };
145
+ if (k[0] === 't') return slots.title?.(scope);
146
+ return slots.content ? slots.content(scope) : items[i].content ?? null;
147
+ },
148
+ };
149
+ });
150
+
151
+ /* ---------------- Carousel ---------------- */
152
+
153
+ const CR_PROPS = { ...anyProps('perView', 'gap', 'peek', 'autoplay', 'label', 'words', 'start'), focus: B, rewind: B, arrows: B, dots: B };
154
+ const CarouselInner = mounted('Carousel', (el, o) => {
155
+ const c = C.carousel(el, {
156
+ ...without(o, ['report', 'count', 'value', 'defaultValue']),
157
+ slides: Array.from({ length: o.count }, () => ''),
158
+ start: o.value ?? o.defaultValue ?? o.start ?? 0,
159
+ onChange: (i, h2) => { if (!isQuiet(h2)) o.onChange?.(i, h2); },
160
+ });
161
+ note(c);
162
+ o.report?.(slotMap(c ? [...c.root.querySelectorAll('.gk-cr__slide')].map((s, i) => [String(i), s]) : []));
163
+ return c;
164
+ }, {
165
+ props: { ...CR_PROPS, count: ANY, report: Function },
166
+ model: { event: 'onChange' },
167
+ update(c, next, prev) {
168
+ if (changedOnly(next, prev, ['defaultValue'])) return true;
169
+ if (changedOnly(next, prev, ['value', 'defaultValue'])) { if (next.value != null && next.value !== c.index) quietly(c, () => c.go(next.value)); return true; }
170
+ return false;
171
+ },
172
+ });
173
+
174
+ /**
175
+ * <Carousel v-model="slide" :per-view="{ 0: 1, 640: 2 }" :peek="40" label="Bikes">
176
+ * <BikeCard v-for="b in bikes" :key="b.id" :bike="b" />
177
+ * </Carousel>
178
+ * Same as carousel(el, options); each child of the default slot is one slide. v-model (or default-value): the
179
+ * slide index. @change(index, c). ref → { index, count, go(i), next(), prev(), play(), pause(), update(), el }.
180
+ */
181
+ export const Carousel = slotted('Carousel', CarouselInner, { ...CR_PROPS, ...modelProps(), onChange: Function }, (p, slots) => {
182
+ const kids = flatNodes(slots.default?.());
183
+ return { props: { count: kids.length }, draw: (k) => kids[+k] ?? null };
184
+ });
185
+
186
+ /* ---------------- BeforeAfter ---------------- */
187
+
188
+ const BA_PROPS = { ...anyProps('ratio', 'step', 'words', 'start'), hover: B, hint: B, labels: B };
189
+ const BeforeAfterInner = mounted('BeforeAfter', (el, o) => {
190
+ const ba = C.beforeAfter(el, { ...without(o, ['report', 'value', 'defaultValue']), before: '', after: '', start: o.value ?? o.defaultValue ?? o.start ?? 50 });
191
+ o.report?.(slotMap(ba ? [['before', ba.root.querySelector('.gk-ba__before')], ['after', ba.root.querySelector('.gk-ba__after')]] : []));
192
+ return ba;
193
+ }, {
194
+ props: { ...BA_PROPS, report: Function },
195
+ model: { event: 'onChange' },
196
+ update(ba, next, prev) {
197
+ if (changedOnly(next, prev, ['defaultValue'])) return true;
198
+ if (changedOnly(next, prev, ['value', 'defaultValue'])) { if (next.value != null && Math.round(next.value) !== ba.value) ba.set(next.value); return true; }
199
+ return false;
200
+ },
201
+ });
202
+
203
+ /**
204
+ * <BeforeAfter hint>
205
+ * <template #before><img src="/repairs/42-before.jpg" alt="Before repair" /></template>
206
+ * <template #after><img src="/repairs/42-after.jpg" alt="After repair" /></template>
207
+ * </BeforeAfter>
208
+ * Same as beforeAfter(el, options) with your content on each side (#before / #after slots, or `before` /
209
+ * `after` text). v-model (or default-value): 0–100 (vanilla `start`). @change(value, ba) while it moves.
210
+ * ref → { value, set(v, animate), el }.
211
+ */
212
+ export const BeforeAfter = slotted('BeforeAfter', BeforeAfterInner, { ...BA_PROPS, before: ANY, after: ANY, ...modelProps(), onChange: Function }, (p, slots) => ({
213
+ props: {},
214
+ draw: (k) => (k === 'before' ? (slots.before ? slots.before() : p.before) : (slots.after ? slots.after() : p.after)),
215
+ }));
216
+
217
+ /* ---------------- Tree ---------------- */
218
+
219
+ /**
220
+ * <Tree v-model="picked" v-model:checked="ticked" :items="folders" checkable label="Files" @activate="openFile" />
221
+ * Same as tree(el, options). v-model (or default-value): the selected ids, applied in place with select();
222
+ * v-model:checked: the ticked ids, applied in place with check(). Other changes (items…) draw it again.
223
+ * @select(ids, item, t) · @check(ids, t) · @toggle(id, open, t) · @activate(item, t). ref → the handle.
224
+ */
225
+ export const Tree = mounted('Tree', (el, o) => {
226
+ const t = C.tree(el, {
227
+ ...without(o, ['defaultValue', 'onUpdate:checked']), value: o.value ?? o.defaultValue ?? null,
228
+ onSelect: (...a) => { if (!isQuiet(a[a.length - 1])) o.onSelect?.(...a); },
229
+ onCheck: (...a) => { if (isQuiet(a[a.length - 1])) return; o['onUpdate:checked']?.(a[0]); o.onCheck?.(...a); },
230
+ });
231
+ note(t);
232
+ return t;
233
+ }, {
234
+ props: {
235
+ ...anyProps('items', 'select', 'indent', 'checked', 'load', 'label', 'words'), checkable: B, lines: B, icons: B, openOnClick: B,
236
+ onCheck: Function, onToggle: Function, onActivate: Function, 'onUpdate:checked': Function,
237
+ },
238
+ model: { event: 'onSelect' },
239
+ update(t, next, prev) {
240
+ if (changedOnly(next, prev, ['value', 'defaultValue', 'checked'])) {
241
+ if (!same(next.value, prev.value) && next.value !== undefined && !same([].concat(next.value ?? []).map(String), t.value)) quietly(t, () => t.select(next.value));
242
+ if (!same(next.checked, prev.checked) && next.checked != null) {
243
+ const want = new Set([].concat(next.checked).map(String)), now = new Set(t.checked);
244
+ quietly(t, () => {
245
+ now.forEach((id) => { if (!want.has(id) && t.get(id)?.checked === true) t.check(id, false); });
246
+ want.forEach((id) => { if (t.get(id)?.checked !== true) t.check(id, true); });
247
+ });
248
+ }
249
+ return true;
250
+ }
251
+ return false;
252
+ },
253
+ });
254
+
255
+ /* ---------------- DataGrid ---------------- */
256
+
257
+ /**
258
+ * <DataGrid :columns="[{ key: 'plate', label: 'Plate' }, { key: 'rate', label: 'Rate / day', type: 'number', edit: true }]"
259
+ * :rows="bikes" @change="(row, key, value) => save(row.id, key, value)" />
260
+ * Same as grid(el, options). A new `rows` is applied in place with setRows() (skipped when it already matches
261
+ * the grid). row-key: the id field (vanilla `id`, default 'id'; a plain `id` attribute goes on the element).
262
+ * columns[].render(value, row) returns trusted HTML: escape app text yourself (esc from components), or use format.
263
+ * ref → { rows(), visible(), setRows, search, filter, sort, page, reset, add, remove, selected(), el }.
264
+ */
265
+ export const DataGrid = mounted('DataGrid', (el, o) => C.grid(el, o), {
266
+ props: {
267
+ ...anyProps('columns', 'rows', 'rowKey', 'searchPlaceholder', 'pageSize', 'addLabel', 'density', 'newRow', 'emptyText'),
268
+ search: B, select: B, add: B, remove: B, stripes: B, onChange: Function, onAdd: Function, onRemove: Function, onView: Function,
269
+ },
270
+ options: (o) => { const r = without(o, ['rowKey']); if (o.rowKey !== undefined) r.id = o.rowKey; return r; },
271
+ update(g, next, prev) {
272
+ if (changedOnly(next, prev, ['rows'])) { if (!same(next.rows ?? [], g.rows())) g.setRows(next.rows || []); return true; }
273
+ return false;
274
+ },
275
+ });
276
+
277
+ /* ---------------- VirtualList ---------------- */
278
+
279
+ const vlKey = (o, item, i) => {
280
+ if (o.itemKey) return o.itemKey(item, i);
281
+ if (item != null && typeof item === 'object') return item.id ?? item.key ?? i;
282
+ return typeof o.items === 'number' ? i : item;
283
+ };
284
+
285
+ const VL_PROPS = { ...anyProps('items', 'render', 'rowHeight', 'estimate', 'height', 'overscan', 'itemKey', 'label', 'words'), selectable: B, onSelect: Function, onRange: Function };
286
+ const VirtualListInner = mounted('VirtualList', (el, o) => {
287
+ let list = null;
288
+ const opts = without(o, ['report', 'teleport', 'itemKey', 'modelValue', 'defaultValue', 'onUpdate:modelValue']);
289
+ if (o.itemKey) opts.key = o.itemKey;
290
+ opts.value = o.modelValue !== undefined ? o.modelValue : o.defaultValue;
291
+ opts.onSelect = (item, index, l) => { if (isQuiet(l)) return; o['onUpdate:modelValue']?.(vlKey(o, item, index)); o.onSelect?.(item, index, l); };
292
+ if (o.teleport) {
293
+ /* Each row gets a holder (kept per key, so refresh() hands back the same one); Vue draws the #item slot
294
+ into the holders that are on screen. */
295
+ const boxes = new Map();
296
+ let queued = false;
297
+ const flush = () => {
298
+ queued = false;
299
+ if (!list || note(list).dead) return;
300
+ const m = new Map();
301
+ boxes.forEach((b, k) => { if (b.el.isConnected) m.set(String(k), b); else boxes.delete(k); });
302
+ o.report?.(m);
303
+ };
304
+ opts.render = (item, index) => {
305
+ const k = vlKey(o, item, index);
306
+ let b = boxes.get(k);
307
+ if (!b) { const d = document.createElement('div'); d.className = 'gk-vl__r'; d.style.display = 'contents'; b = { el: d }; }
308
+ boxes.set(k, { el: b.el, item, index });
309
+ if (!queued) { queued = true; queueMicrotask(flush); }
310
+ return b.el;
311
+ };
312
+ }
313
+ list = C.virtualList(el, opts);
314
+ note(list);
315
+ const destroy = list.destroy;
316
+ return Object.assign(list, { destroy() { note(list).dead = true; destroy(); } });
317
+ }, {
318
+ props: { ...VL_PROPS, ...modelProps(), teleport: B, report: Function },
319
+ update(l, next, prev) {
320
+ if (changedOnly(next, prev, ['items', 'modelValue', 'defaultValue'])) {
321
+ if (!same(next.items, prev.items)) l.update(next.items);
322
+ if (next.modelValue !== undefined && !same(next.modelValue, prev.modelValue)) {
323
+ const items = typeof next.items === 'number' ? null : next.items || [];
324
+ const n = items ? items.length : next.items;
325
+ for (let i = 0; i < n; i++) if (same(vlKey(next, items ? items[i] : i, i), next.modelValue)) { quietly(l, () => l.select(i, { scroll: false })); break; }
326
+ }
327
+ return true;
328
+ }
329
+ return false;
330
+ },
331
+ });
332
+
333
+ /**
334
+ * <VirtualList v-model="picked" :items="riders" :row-height="56" :height="420" selectable @select="openRider">
335
+ * <template #item="{ item }"><RiderRow :rider="item" /></template>
336
+ * </VirtualList>
337
+ * Same as virtualList(el, options): only the rows in view are in the page. Draw rows with the #item slot
338
+ * ({ item, index }) or with render(item, index) → trusted HTML / a Node. A new `items` is applied in place with
339
+ * update(). v-model (or default-value): the key of the picked row (selectable); item-key: (item, index) → key
340
+ * (vanilla `key`). ref → { update, scrollTo, select, refresh, range, count, el }.
341
+ */
342
+ export const VirtualList = slotted('VirtualList', VirtualListInner, { ...VL_PROPS, ...modelProps() }, (p, slots) => ({
343
+ props: { teleport: !!slots.item },
344
+ draw: (k, s) => slots.item?.({ item: s.item, index: s.index }),
345
+ }), (p, inner, map) => {
346
+ // rows measured as they show ('auto') are measured again once Vue has drawn their content
347
+ watch(map, () => { if (p.rowHeight === 'auto') inner.value?.refresh?.(); }, { flush: 'post' });
348
+ });
349
+
350
+ /* ---------------- Timeline (bookings) ---------------- */
351
+
352
+ /**
353
+ * <Timeline title="Fleet" :rows="bikes" :items="bookings" from="2026-12-01" :days="14" @change="(b) => saveBooking(b)" />
354
+ * Same as timeline(el, options). A new `items` is applied in place (add / update / remove, so bars glide and grow);
355
+ * nothing happens when it already matches what is on screen (e.g. after you store a drag from @change).
356
+ * @change(item, before) · @open(item, bar) · @add({ row, start }) · @clash(item, other). ref → the handle (undo(), go()…).
357
+ */
358
+ export const Timeline = mounted('Timeline', (el, o) => C.timeline(el, o), {
359
+ props: {
360
+ from: ANY, ...anyProps('rows', 'items', 'days', 'locale', 'title', 'today', 'minDays', 'dayWidth', 'rowHeight', 'labelWidth', 'sub', 'words'),
361
+ edit: B, overlap: B, now: B, late: B, onChange: Function, onOpen: Function, onAdd: Function, onClash: Function,
362
+ },
363
+ update(tl, next, prev) {
364
+ if (!changedOnly(next, prev, ['items'])) return false;
365
+ const now = new Map(tl.items().map((x) => [String(x.id), x]));
366
+ const want = next.items || [];
367
+ const ids = new Set(want.map((x) => String(x.id)));
368
+ now.forEach((x, id) => { if (!ids.has(id)) tl.remove(x.id); });
369
+ want.forEach((x) => {
370
+ const cur = now.get(String(x.id));
371
+ if (!cur) { tl.add(x); return; }
372
+ const patch = {};
373
+ Object.keys(x).forEach((k) => {
374
+ if (k === 'id') return;
375
+ const a = x[k], b = cur[k];
376
+ const differs = k === 'start' || k === 'end' ? String(a instanceof Date ? a.toISOString() : a) !== String(b) : !same(a, b);
377
+ if (differs) patch[k] = a;
378
+ });
379
+ if (Object.keys(patch).length) tl.update(x.id, patch);
380
+ });
381
+ return true;
382
+ },
383
+ });
384
+
385
+ /* ---------------- Calendar ---------------- */
386
+
387
+ const dayKey = (d) => { if (d == null || d === '') return null; if (d instanceof Date) return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`; const [y, m, dd] = String(d).slice(0, 10).split('-').map(Number); return `${y}-${m - 1}-${dd}`; };
388
+ const monthKey = (d) => { const k = dayKey(d); return k && k.split('-').slice(0, 2).join('-'); };
389
+ /**
390
+ * <Calendar v-model="day" v-model:month="month" :events="bookings" draggable @move="(ev, start, end) => move(ev.id, start, end)" />
391
+ * Same as calendar(el, options). v-model (or default-value): the picked day, applied in place with select();
392
+ * month (v-model:month): the month on show, applied with go(); a new `events` is applied with setEvents()
393
+ * (skipped when it already matches, e.g. after storing a move).
394
+ * @month(date, cal) · @day(date, events, cal) · @event(event, cal) · @move(event, start, end, cal) (return false to put it back).
395
+ */
396
+ export const Calendar = mounted('Calendar', (el, o) => C.calendar(el, {
397
+ ...without(o, ['defaultValue', 'onUpdate:month']), value: o.value ?? o.defaultValue ?? null,
398
+ onMonth: (d, cal) => { o['onUpdate:month']?.(d); return o.onMonth?.(d, cal); },
399
+ }), {
400
+ props: {
401
+ ...anyProps('events', 'month', 'weekStart', 'locale', 'today', 'maxPerDay', 'size', 'label', 'words'), selectable: B, draggable: B,
402
+ onMonth: Function, onEvent: Function, onMove: Function, 'onUpdate:month': Function,
403
+ },
404
+ model: { event: 'onDay' },
405
+ update(cal, next, prev) {
406
+ if (!changedOnly(next, prev, ['events', 'value', 'defaultValue', 'month'])) return false;
407
+ if (!same(next.events, prev.events) && !same(next.events || [], cal.events)) cal.setEvents(next.events || []);
408
+ if (!same(next.value, prev.value) && next.value !== undefined && dayKey(next.value) !== dayKey(cal.value)) cal.select(next.value);
409
+ if (!same(next.month, prev.month) && next.month != null && monthKey(next.month) !== monthKey(cal.month)) cal.go(next.month);
410
+ return true;
411
+ },
412
+ });
413
+
414
+ /* ---------------- Swipe actions ---------------- */
415
+
416
+ const SWIPE_TONES = new Set(['good', 'bad', 'warn', 'accent', 'neutral']);
417
+ const swipeAct = (a) => h('button', {
418
+ key: a.id, type: 'button', class: `gk-swp__act gk-swp__act--${SWIPE_TONES.has(a.tone) ? a.tone : 'neutral'}`,
419
+ 'data-act': a.id, 'data-remove': a.remove ? '' : undefined, tabindex: -1,
420
+ }, [h('span', { class: 'gk-swp__in' }, [iconNode(a.icon), h('span', { class: 'gk-swp__lb' }, a.label ?? a.id)])]);
421
+
422
+ /**
423
+ * <SwipeItem :id="b.id" :end="[{ id: 'cancel', label: 'Cancel', icon: 'trash', tone: 'bad', remove: true }]">…your row…</SwipeItem>
424
+ * Same markup as swipeItem({ body, start, end, id, look, label }); the default slot is the row. Put the rows in a
425
+ * <SwipeActions>. start: actions shown when the row is pulled right, end: when pulled left (from the edge inward).
426
+ */
427
+ export const SwipeItem = defineComponent({
428
+ name: 'SwipeItem',
429
+ props: { id: ANY, start: { type: Array, default: () => [] }, end: { type: Array, default: () => [] }, look: { type: String, default: 'both' }, label: String },
430
+ setup(props, { slots }) {
431
+ return () => h('div', {
432
+ 'data-id': props.id != null && props.id !== '' ? String(props.id) : undefined,
433
+ class: ['gk-swp', (props.look === 'icons' || props.look === 'labels') && 'gk-swp--' + props.look],
434
+ }, [
435
+ h('div', { class: 'gk-swp__main', tabindex: 0, 'aria-label': props.label || undefined, 'aria-keyshortcuts': 'ArrowLeft ArrowRight' }, slots.default?.()),
436
+ h('div', { class: 'gk-swp__acts gk-swp__acts--start' }, (props.start || []).map(swipeAct)),
437
+ h('div', { class: 'gk-swp__acts gk-swp__acts--end' }, [...(props.end || [])].reverse().map(swipeAct)),
438
+ ]);
439
+ },
440
+ });
441
+
442
+ const SWIPE_OPTS = ['full', 'fullAt', 'single', 'haptic', 'keepRows'];
443
+ const SWIPE_FNS = ['onAction', 'onOpen', 'onClose'];
444
+ /**
445
+ * <SwipeActions class="gk-card gk-card--flush" @action="(action, ctx) => …">
446
+ * <SwipeItem v-for="r in rows" :key="r.id" :id="r.id" :end="…">…</SwipeItem>
447
+ * </SwipeActions>
448
+ * Same as swipeActions(list, options) on the element it renders (`as` changes it, default div). A row whose action
449
+ * has remove: true slides off and is hidden (Vue still owns it: drop it from your list when you are done, or call
450
+ * ctx.undo() to bring it back). @action(action, ctx, sw) — ctx: { row, id, action, undo() }; return false to keep
451
+ * the row. @open(row, side, sw) · @close(row, sw). ref → { open(row, side), close(row), peek(row, side), openRow, el }.
452
+ */
453
+ export const SwipeActions = defineComponent({
454
+ name: 'SwipeActions',
455
+ props: { as: String, full: B, fullAt: Number, single: B, haptic: B, keepRows: { type: Boolean, default: true }, onAction: Function, onOpen: Function, onClose: Function },
456
+ setup(props, { slots, expose }) {
457
+ const el = ref(null);
458
+ let sw = null;
459
+ const plain = () => { const o = {}; SWIPE_OPTS.forEach((k) => { if (props[k] !== undefined) o[k] = props[k]; }); return o; };
460
+ expose({
461
+ open: (row, side) => sw?.open(row, side),
462
+ close: (row) => sw?.close(row),
463
+ peek: (row, side) => sw?.peek(row, side),
464
+ get openRow() { return sw?.openRow ?? null; },
465
+ get el() { return el.value; },
466
+ });
467
+ onMounted(() => {
468
+ const live = plain();
469
+ SWIPE_FNS.forEach((k) => { live[k] = (...a) => props[k]?.(...a); });
470
+ sw = C.swipeActions(el.value, live);
471
+ watch(plain, (o) => { if (sw) Object.keys(o).forEach((k) => { if (sw.opts[k] !== o[k]) sw.opts[k] = o[k]; }); });
472
+ });
473
+ onBeforeUnmount(() => { sw?.destroy(); sw = null; });
474
+ return () => h(props.as || 'div', { ref: el }, slots.default?.());
475
+ },
476
+ });
477
+
478
+ /* ---------------- Kanban ---------------- */
479
+
480
+ const KB_PROPS = { ...anyProps('columns', 'cards', 'render', 'canDrop', 'words'), strictLimit: B, onMove: Function, onOpen: Function, onAdd: Function };
481
+ const KanbanInner = mounted('Kanban', (el, o) => {
482
+ const opts = without(o, ['report', 'teleport']);
483
+ if (o.teleport) opts.render = (c) => `<div class="gk-kb__r" data-kb-r="${C.esc(String(c.id))}" style="display:contents"></div>`;
484
+ const kb = C.kanban(el, opts);
485
+ note(kb).scan = () => o.report?.(slotMap([...kb.el.querySelectorAll('[data-kb-r]')].map((x) => [x.dataset.kbR, x])));
486
+ if (o.teleport) note(kb).scan();
487
+ return kb;
488
+ }, {
489
+ props: { ...KB_PROPS, teleport: B, report: Function },
490
+ update(kb, next, prev) {
491
+ if (!changedOnly(next, prev, ['cards'])) return false;
492
+ const want = next.cards || [];
493
+ const strip = (c) => { const { column, ...r } = c; return r; };
494
+ const nowById = () => new Map(kb.cards().map((c) => [String(c.id), c]));
495
+ let now = nowById();
496
+ const ids = new Set(want.map((c) => String(c.id)));
497
+ now.forEach((c, id) => { if (!ids.has(id)) kb.remove(c.id); });
498
+ (next.columns || []).forEach((col) => {
499
+ want.filter((c) => String(c.column) === String(col.id)).forEach((c, i) => {
500
+ const had = now.get(String(c.id));
501
+ if (!had) { kb.add(c, i); now = nowById(); return; }
502
+ const fields = strip(c), was = strip(had);
503
+ if (!same(fields, Object.fromEntries(Object.keys(fields).map((k) => [k, was[k]])))) kb.update(c.id, fields);
504
+ const list = kb.cards().filter((x) => String(x.column) === String(col.id) && ids.has(String(x.id)));
505
+ const at = list.findIndex((x) => String(x.id) === String(c.id));
506
+ if (String(had.column) !== String(col.id) || at !== i) { kb.move(c.id, col.id, i); now = nowById(); }
507
+ });
508
+ });
509
+ note(kb).scan?.();
510
+ return true;
511
+ },
512
+ });
513
+
514
+ /**
515
+ * <Kanban :columns="[{ id: 'todo', title: 'To do' }, { id: 'done', title: 'Done', limit: 5 }]" :cards="tasks"
516
+ * @move="(card, { to, index }) => moveTask(card.id, to, index)">
517
+ * <template #card="{ card }"><TaskCard :task="card" /></template>
518
+ * </Kanban>
519
+ * Same as kanban(el, options). The #card slot ({ card }) draws each card (or leave it out for the built-in card:
520
+ * tags, title, text; `meta` is trusted HTML). A new `cards` is applied in place: added cards grow in, removed ones
521
+ * fold away, moved ones slide. @move(card, { from, to, index, fromIndex }, kb) (return false to put it back) ·
522
+ * @open(card, el, kb) · @add(columnId, kb). ref → { cards(), add, update, remove, move, setCards, el }.
523
+ */
524
+ export const Kanban = slotted('Kanban', KanbanInner, KB_PROPS, (p, slots, seen) => {
525
+ // cards stay drawn while they fold away, after they left `cards`
526
+ (p.cards || []).forEach((c) => seen.set(String(c.id), c));
527
+ return {
528
+ props: { teleport: !!slots.card },
529
+ draw: (k) => { const c = seen.get(k); return c ? slots.card?.({ card: c }) : null; },
530
+ };
531
+ }, () => new Map());
532
+
533
+ /* ---------------- Notifications ---------------- */
534
+
535
+ /**
536
+ * <Notifications :items="notes" :height="420" @open="(n) => markRead(n.id)" @action="(n, id) => api.answer(n.id, id)" />
537
+ * Same as notifications(el, options). A new `items` is applied in place: new ones slide in at the top, removed
538
+ * ones fold away, changed ones are drawn again (read / unread lets the dot go). filter: 'all' | 'unread' in place.
539
+ * @open(item, nf) · @action(item, actionId, nf) → Promise<string | false | void> · @dismiss(item, nf) · @change(unreadCount, nf).
540
+ */
541
+ export const Notifications = mounted('Notifications', (el, o) => C.notifications(el, o), {
542
+ props: {
543
+ ...anyProps('items', 'filter', 'height', 'locale', 'when', 'emptyIcon', 'words'), group: B, header: B, tabs: B, markAll: B, dismissible: B, plain: B,
544
+ onOpen: Function, onAction: Function, onDismiss: Function, onChange: Function,
545
+ },
546
+ update(nf, next, prev) {
547
+ if (!changedOnly(next, prev, ['items', 'filter'])) return false;
548
+ if (next.filter !== prev.filter && next.filter && nf.filter !== next.filter) nf.setFilter(next.filter);
549
+ if (same(next.items, prev.items)) return true;
550
+ const now = new Map(nf.items.map((x) => [x.id, x]));
551
+ const want = next.items || [];
552
+ const ids = new Set(want.map((x) => String(x.id)));
553
+ now.forEach((x, id) => { if (!ids.has(id)) nf.remove(id); });
554
+ const fresh = want.filter((x) => x.id == null || !now.has(String(x.id)));
555
+ want.forEach((x) => {
556
+ const cur = x.id != null && now.get(String(x.id)); if (!cur) return;
557
+ const patch = {};
558
+ Object.keys(x).forEach((k) => { if (k !== 'id' && k !== 'read' && !same(x[k], cur[k])) patch[k] = x[k]; });
559
+ if (Object.keys(patch).length) nf.update(x.id, patch);
560
+ if (!!x.read !== !!cur.read) nf.read(x.id, !!x.read);
561
+ });
562
+ if (fresh.length) nf.add(fresh);
563
+ return true;
564
+ },
565
+ });
566
+
567
+ /* ---------------- Activity ---------------- */
568
+
569
+ /**
570
+ * <Activity :items="events" marks="auto" locale="th" />
571
+ * Same as activity(el, options). Events newer than the ones on screen are added at the top with the push-down
572
+ * motion; removed ones fold away; any other change sets the list again. ref → { items, add, remove, set, play(), el }.
573
+ */
574
+ export const Activity = mounted('Activity', (el, o) => C.activity(el, o), {
575
+ props: { ...anyProps('items', 'marks', 'max', 'locale', 'format', 'refresh', 'label', 'words'), intro: BS, latest: B },
576
+ update(a, next, prev) {
577
+ if (!changedOnly(next, prev, ['items'])) return false;
578
+ const now = a.items, want = next.items || [];
579
+ const nowIds = new Set(now.map((x) => x.id)), ids = new Set(want.map((x) => String(x.id)));
580
+ if (want.some((x) => x.id == null)) { a.set(want); return true; }
581
+ now.forEach((x) => { if (!ids.has(x.id)) a.remove(x.id); });
582
+ const kept = want.filter((x) => nowIds.has(String(x.id)));
583
+ const fresh = want.filter((x) => !nowIds.has(String(x.id)));
584
+ const changed = kept.some((x) => { const c = now.find((y) => y.id === String(x.id)); return Object.keys(x).some((k) => k !== 'id' && !same(x[k], c[k])); });
585
+ const topOnly = want.slice(0, fresh.length).every((x) => !nowIds.has(String(x.id)));
586
+ if (changed || !topOnly) { a.set(want); return true; }
587
+ if (fresh.length) a.add(fresh);
588
+ return true;
589
+ },
590
+ });
591
+
592
+ /* ---------------- Pagination ---------------- */
593
+
594
+ /**
595
+ * <Pagination v-model="page" v-model:page-size="size" :total="240" />
596
+ * Same as pagination(el, options). v-model (or default-value): the page (vanilla `page`), applied in place with go();
597
+ * v-model:page-size follows the size list; a new `total` is applied with setTotal() (a page that no longer exists
598
+ * is reported). @change(page, pageSize, p). ref → { page, pageSize, pages, total, go, next, prev, setTotal, el }.
599
+ */
600
+ export const Pagination = mounted('Pagination', (el, o) => {
601
+ let size = +o.pageSize || 10;
602
+ const p = C.pagination(el, {
603
+ ...without(o, ['value', 'defaultValue', 'onUpdate:pageSize']), page: o.value ?? o.defaultValue ?? o.page ?? 1,
604
+ onChange: (page, sz, x) => {
605
+ if (isQuiet(x)) return;
606
+ if (sz !== size) { size = sz; o['onUpdate:pageSize']?.(sz); }
607
+ o.onChange?.(page, sz, x);
608
+ },
609
+ });
610
+ note(p);
611
+ return p;
612
+ }, {
613
+ props: {
614
+ ...anyProps('total', 'pageSize', 'siblings', 'boundaries', 'sizes', 'look', 'compactAt', 'words'), info: B, compact: BS,
615
+ 'onUpdate:pageSize': Function,
616
+ },
617
+ model: { event: 'onChange' },
618
+ update(p, next, prev) {
619
+ if (!changedOnly(next, prev, ['value', 'defaultValue', 'total', 'pageSize'])) return false;
620
+ if (!same(next.pageSize, prev.pageSize) && +next.pageSize !== p.pageSize) return false;
621
+ if (next.total !== prev.total) p.setTotal(next.total); // a page that no longer exists is reported
622
+ if (next.value != null && next.value !== p.page) quietly(p, () => p.go(next.value));
623
+ return true;
624
+ },
625
+ });
626
+
627
+ /* ---------------- Breadcrumbs ---------------- */
628
+
629
+ /**
630
+ * <Breadcrumbs :items="[{ label: 'Fleet', href: '/fleet' }, { label: 'Honda Click' }]"
631
+ * @navigate="(it, i, e) => { e.preventDefault(); router.push(it.href) }" />
632
+ * Same as breadcrumbs(el, options). A new `items` is set in place like a route change (shared steps stay, new
633
+ * ones slide in). @navigate(item, index, event). ref → { items, set(items), expand(), el }.
634
+ */
635
+ export const Breadcrumbs = mounted('Breadcrumbs', (el, o) => C.breadcrumbs(el, o), {
636
+ props: { ...anyProps('items', 'max', 'separator', 'size', 'words'), onNavigate: Function },
637
+ update(bc, next, prev) {
638
+ if (changedOnly(next, prev, ['items'])) { bc.set(next.items || []); return true; }
639
+ return false;
640
+ },
641
+ });
642
+
643
+ /* ---------------- Skeleton ---------------- */
644
+
645
+ const SK_PROPS = { ...anyProps('look', 'rows', 'lines', 'cols', 'label', 'words'), avatar: B, media: B, shimmer: B };
646
+ const SkeletonInner = mounted('Skeleton', (el, o) => {
647
+ const sk = C.skeleton(el, without(o, ['report', 'loading']));
648
+ o.report?.(slotMap(sk ? [['content', sk.content]] : []));
649
+ if (sk && o.loading === false) sk.reveal(undefined, { stagger: false });
650
+ return sk;
651
+ }, {
652
+ props: { ...SK_PROPS, loading: B, report: Function },
653
+ update(sk, next, prev) {
654
+ if (!changedOnly(next, prev, ['loading'])) return false;
655
+ if (next.loading === false) sk.reveal(); else sk.loading(true);
656
+ return true;
657
+ },
658
+ });
659
+
660
+ /**
661
+ * <Skeleton look="list" :rows="4" :loading="!riders"><RiderList v-if="riders" :riders="riders" /></Skeleton>
662
+ * Same as skeleton(el, options): grey placeholders in the shape of what is loading. The default slot is the real
663
+ * content; when `loading` turns false the placeholders fade row by row while the content rises into place
664
+ * (and back with true). ref → { busy, reveal(), loading(on), content, el }.
665
+ */
666
+ export const Skeleton = slotted('Skeleton', SkeletonInner, { ...SK_PROPS, loading: { type: Boolean, default: true } }, (p, slots) => ({
667
+ props: { loading: p.loading !== false },
668
+ draw: () => slots.default?.() ?? null,
669
+ }));
670
+
671
+ /* ---------------- Alert ---------------- */
672
+
673
+ const AL_PROPS = { ...anyProps('tone', 'title', 'icon', 'look', 'actions', 'words'), dismissible: B, open: B, onClose: Function, 'onUpdate:open': Function };
674
+ const AlertInner = mounted('Alert', (el, o) => {
675
+ const box = document.createElement('div');
676
+ box.className = 'gk-al__node'; box.style.display = 'contents';
677
+ let a = null;
678
+ a = C.alert(el, {
679
+ ...without(o, ['report', 'hasBody', 'onUpdate:open']), body: o.hasBody ? box : '',
680
+ onClose: (x) => {
681
+ const n = note(x);
682
+ if (n.byProp) { n.byProp = false; return; } // closed because the app set open to false
683
+ o['onUpdate:open']?.(false); o.onClose?.(x);
684
+ },
685
+ });
686
+ note(a).box = box;
687
+ o.report?.(slotMap([['body', box]]));
688
+ return a;
689
+ }, {
690
+ props: { ...AL_PROPS, hasBody: B, report: Function },
691
+ update(a, next, prev) {
692
+ if (!changedOnly(next, prev, ['tone', 'title', 'icon', 'actions', 'open', 'hasBody'])) return false;
693
+ const patch = {};
694
+ ['tone', 'icon', 'actions'].forEach((k) => { if (!same(next[k], prev[k])) patch[k] = next[k]; });
695
+ if (next.title !== prev.title) patch.title = next.title ?? '';
696
+ if (next.hasBody !== prev.hasBody) patch.body = next.hasBody ? note(a).box : '';
697
+ if (Object.keys(patch).length) a.update(patch);
698
+ if (next.open !== prev.open) {
699
+ if (next.open === false) { if (a.open) { note(a).byProp = true; a.close(); } }
700
+ else if (!a.open) a.show();
701
+ }
702
+ return true;
703
+ },
704
+ });
705
+
706
+ /**
707
+ * <Alert v-model:open="show" tone="bad" title="Couldn't save the booking" dismissible
708
+ * :actions="[{ label: 'Try again', primary: true, run: () => save() }]">The bike is already booked on those days.</Alert>
709
+ * Same as alert(el, options); the default slot is the message (vanilla `body`). tone, title, icon and actions change
710
+ * in place with update() (colours cross-fade, the icon spins, the text slides). open: false folds it away, true grows
711
+ * it back. Closing from inside (✕ or Esc) sets v-model:open to false, then calls @close(a).
712
+ * ref → { open, tone, update, close, show, shake, el }.
713
+ */
714
+ export const Alert = slotted('Alert', AlertInner, AL_PROPS, (p, slots) => {
715
+ const body = slots.default?.();
716
+ const hasBody = flatNodes(body).length > 0;
717
+ return { props: { hasBody }, draw: () => (hasBody ? body : null) };
718
+ });