@m3ui-vue/m3ui-vue 0.8.4 → 0.8.6

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 (54) hide show
  1. package/README.md +1 -1
  2. package/dist/{MMenuItem-DiilFeDO.js → MMenuItem-BmPLAyv5.js} +64 -62
  3. package/dist/{MMenuItem-DiilFeDO.js.map → MMenuItem-BmPLAyv5.js.map} +1 -1
  4. package/dist/code-editor.js +1 -1
  5. package/dist/components/MChatBubble.vue.d.ts +4 -2
  6. package/dist/components/MCheckbox.vue.d.ts +2 -0
  7. package/dist/components/MDragDropList.vue.d.ts +19 -6
  8. package/dist/components/MFileUpload.vue.d.ts +16 -4
  9. package/dist/components/MKanban.vue.d.ts +15 -6
  10. package/dist/components/MTable.vue.d.ts +8 -0
  11. package/dist/components/MTransferList.vue.d.ts +9 -3
  12. package/dist/components/_MTransferPane.vue.d.ts +39 -0
  13. package/dist/composables/useLocale.d.ts +24 -0
  14. package/dist/locales/index.js +175 -7
  15. package/dist/locales/index.js.map +1 -1
  16. package/dist/m3ui-vue.css +1 -1
  17. package/dist/m3ui.js +3600 -2696
  18. package/dist/m3ui.js.map +1 -1
  19. package/dist/rich-text-editor.js +2 -2
  20. package/dist/styles.css +1 -1
  21. package/dist/{useLocale-DbREg9Zn.js → useLocale-4afAzuuP.js} +26 -2
  22. package/dist/useLocale-4afAzuuP.js.map +1 -0
  23. package/package.json +1 -1
  24. package/src/__tests__/MChatBubble.test.ts +33 -0
  25. package/src/__tests__/MDragDropList.test.ts +194 -0
  26. package/src/__tests__/MFileUpload.test.ts +78 -0
  27. package/src/__tests__/MKanban.test.ts +150 -0
  28. package/src/__tests__/MMenu.test.ts +84 -0
  29. package/src/__tests__/MPullToRefresh.test.ts +67 -0
  30. package/src/__tests__/MRating.test.ts +72 -0
  31. package/src/__tests__/MTransferList.test.ts +76 -0
  32. package/src/components/MChatBubble.vue +107 -20
  33. package/src/components/MCheckbox.vue +3 -0
  34. package/src/components/MContextMenu.vue +10 -1
  35. package/src/components/MDragDropList.vue +485 -56
  36. package/src/components/MFileUpload.vue +56 -20
  37. package/src/components/MKanban.vue +720 -78
  38. package/src/components/MMenu.vue +10 -1
  39. package/src/components/MNavigationRail.vue +35 -23
  40. package/src/components/MPullToRefresh.vue +101 -35
  41. package/src/components/MRating.vue +163 -67
  42. package/src/components/MResult.vue +19 -9
  43. package/src/components/MTable.vue +10 -3
  44. package/src/components/MTransferList.vue +133 -130
  45. package/src/components/_MTransferPane.vue +182 -0
  46. package/src/composables/useLocale.ts +68 -0
  47. package/src/locales/de.ts +34 -0
  48. package/src/locales/es.ts +34 -0
  49. package/src/locales/fr.ts +34 -0
  50. package/src/locales/ja.ts +34 -0
  51. package/src/locales/ko.ts +34 -0
  52. package/src/locales/pt.ts +34 -0
  53. package/src/locales/zh.ts +34 -0
  54. package/dist/useLocale-DbREg9Zn.js.map +0 -1
@@ -1,7 +1,6 @@
1
1
  <script setup lang="ts">
2
- import { ref } from 'vue'
2
+ import { ref, onBeforeUpdate, onUpdated, onMounted, onBeforeUnmount } from 'vue'
3
3
  import MIcon from './MIcon.vue'
4
- import MIconButton from './MIconButton.vue'
5
4
  import { useLocale } from '../composables/useLocale'
6
5
 
7
6
  export interface KanbanCard {
@@ -14,6 +13,8 @@ export interface KanbanColumn {
14
13
  title: string
15
14
  cards: KanbanCard[]
16
15
  color?: 'primary' | 'secondary' | 'tertiary' | 'error' | 'success'
16
+ /** Optional WIP limit: the header shows count/limit and turns error-colored when exceeded. */
17
+ limit?: number
17
18
  }
18
19
 
19
20
  const props = defineProps<{
@@ -29,123 +30,764 @@ const emit = defineEmits<{
29
30
  cardClick: [{ card: KanbanCard; columnId: string | number }]
30
31
  }>()
31
32
 
32
- const dragCard = ref<{ cardId: string | number; columnId: string | number } | null>(null)
33
- const overColumn = ref<string | number | null>(null)
34
- const overCardIndex = ref<number | null>(null)
33
+ defineSlots<{
34
+ card?: (props: { card: KanbanCard; column: KanbanColumn; dragging: boolean }) => unknown
35
+ 'column-header'?: (props: { column: KanbanColumn; count: number }) => unknown
36
+ 'column-footer'?: (props: { column: KanbanColumn }) => unknown
37
+ }>()
35
38
 
36
- const colorMap: Record<string, string> = {
37
- primary: 'bg-primary',
38
- secondary: 'bg-secondary',
39
- tertiary: 'bg-tertiary',
40
- error: 'bg-error',
41
- success: 'bg-success',
39
+ /*
40
+ * Pointer Events, not native HTML5 drag-and-drop (no touch support on mobile, an unstylable
41
+ * ghost image, and no way to animate the other cards) — same approach as MDragDropList.
42
+ *
43
+ * While dragging, the card is switched to `position: fixed` at its own on-screen rect, so it
44
+ * can travel across columns without being clipped by the board's horizontal scroll container;
45
+ * its column closes up behind it. Every card's offset is a 2D spring stepped in one rAF loop
46
+ * and written straight to `style.transform` (library convention, see CLAUDE.md): Standard
47
+ * `DefaultSpatial`, dampingRatio 0.9 / stiffness 700. Any change to the rendered order —
48
+ * a pointer drop, a keyboard move, or the parent editing the columns — animates with FLIP:
49
+ * capture every card's on-screen rect before the DOM update, then spring each card from its
50
+ * old spot to its new one (including across columns, where Vue recreates the element).
51
+ *
52
+ * M3 values: ElevatedCardTokens — ContainerShape CornerMedium (12dp), elevation Level1 at
53
+ * rest, HoverContainerElevation Level2, DraggedContainerElevation Level4.
54
+ */
55
+ const DAMPING = 0.9
56
+ const STIFFNESS = 700
57
+ const LIFT_ROTATE = 2.5 // deg
58
+ const LIFT_SCALE = 0.03
59
+
60
+ type Id = string | number
61
+ type Spring2 = { x: number; y: number; vx: number; vy: number; tx: number; ty: number }
62
+ type Spring1 = { p: number; v: number; t: number }
63
+
64
+ const boardEl = ref<HTMLElement | null>(null)
65
+ const cardEls = new Map<Id, HTMLElement>()
66
+ const columnEls = new Map<Id, HTMLElement>()
67
+ const areaEls = new Map<Id, HTMLElement>()
68
+ const placeholderEls = new Map<Id, HTMLElement>()
69
+ const springs = new Map<Id, Spring2>()
70
+
71
+ function setRef(map: Map<Id, HTMLElement>, id: Id, el: unknown) {
72
+ if (el) map.set(id, el as HTMLElement)
73
+ else map.delete(id)
74
+ }
75
+ function setCardEl(id: Id, el: unknown) {
76
+ setRef(cardEls, id, el)
77
+ if (!el) springs.delete(id)
42
78
  }
43
79
 
44
- function onCardDragStart(e: DragEvent, card: KanbanCard, columnId: string | number) {
45
- dragCard.value = { cardId: card.id, columnId }
46
- if (e.dataTransfer) {
47
- e.dataTransfer.effectAllowed = 'move'
48
- e.dataTransfer.setData('text/plain', String(card.id))
80
+ function springOf(id: Id): Spring2 {
81
+ let s = springs.get(id)
82
+ if (!s) {
83
+ s = { x: 0, y: 0, vx: 0, vy: 0, tx: 0, ty: 0 }
84
+ springs.set(id, s)
49
85
  }
86
+ return s
50
87
  }
51
88
 
52
- function onColumnDragOver(e: DragEvent, columnId: string | number) {
53
- e.preventDefault()
54
- if (e.dataTransfer) e.dataTransfer.dropEffect = 'move'
55
- overColumn.value = columnId
89
+ // Lift (tilt + slight scale) of the card being dragged / settling, 0..1.
90
+ let liftId: Id | null = null
91
+ const lift: Spring1 = { p: 0, v: 0, t: 0 }
92
+
93
+ function write(id: Id) {
94
+ const el = cardEls.get(id)
95
+ const s = springs.get(id)
96
+ if (!el || !s) return
97
+ let tf = Math.abs(s.x) < 0.01 && Math.abs(s.y) < 0.01 ? '' : `translate(${s.x}px, ${s.y}px)`
98
+ if (id === liftId && lift.p > 0.001) tf += ` rotate(${LIFT_ROTATE * lift.p}deg) scale(${1 + LIFT_SCALE * lift.p})`
99
+ el.style.transform = tf
56
100
  }
57
101
 
58
- function onCardDragOver(e: DragEvent, _card: KanbanCard, index: number, columnId: string | number) {
59
- e.preventDefault()
60
- e.stopPropagation()
61
- if (e.dataTransfer) e.dataTransfer.dropEffect = 'move'
62
- overColumn.value = columnId
63
- overCardIndex.value = index
102
+ // Placeholder: dashed slot in the target column showing where the card will land.
103
+ const ph: Spring1 = { p: 0, v: 0, t: 0 }
104
+ let phColumn: Id | null = null
105
+
106
+ // Reactive only for classes.
107
+ const draggingId = ref<Id | null>(null)
108
+ const settlingId = ref<Id | null>(null)
109
+ const grabbedId = ref<Id | null>(null)
110
+ const targetColumn = ref<Id | null>(null)
111
+ const announcement = ref('')
112
+
113
+ interface DragState {
114
+ id: Id
115
+ fromColumn: Id
116
+ fromIndex: number
117
+ pointerId: number
118
+ startX: number
119
+ startY: number
120
+ lastX: number
121
+ lastY: number
122
+ active: boolean
123
+ longPress?: ReturnType<typeof setTimeout>
124
+ rect: DOMRect | null
125
+ height: number
126
+ toColumn: Id
127
+ toIndex: number
64
128
  }
129
+ let drag: DragState | null = null
130
+ let suppressClick = false
65
131
 
66
- function onDrop(e: DragEvent, toColumnId: string | number) {
67
- e.preventDefault()
68
- if (!dragCard.value) return
132
+ function cardGap(area: HTMLElement) {
133
+ return parseFloat(getComputedStyle(area).rowGap) || 0
134
+ }
135
+ let basePadBottom = ''
69
136
 
70
- const { cardId, columnId: fromColumnId } = dragCard.value
71
- if (fromColumnId === toColumnId && overCardIndex.value === null) {
72
- reset()
137
+ // ---------- Animation loop ----------
138
+
139
+ let raf = 0
140
+ let last = 0
141
+ function kick() {
142
+ if (raf) return
143
+ last = performance.now()
144
+ raf = requestAnimationFrame(step)
145
+ }
146
+ function stepSpring1(s: Spring1, dt: number) {
147
+ const a = -STIFFNESS * (s.p - s.t) - 2 * DAMPING * Math.sqrt(STIFFNESS) * s.v
148
+ s.v += a * dt
149
+ s.p += s.v * dt
150
+ if (Math.abs(s.p - s.t) < 0.002 && Math.abs(s.v) < 0.01) {
151
+ s.p = s.t
152
+ s.v = 0
153
+ return false
154
+ }
155
+ return true
156
+ }
157
+ function step(now: number) {
158
+ raf = 0
159
+ const dt = Math.min((now - last) / 1000, 1 / 30)
160
+ last = now
161
+ let moving = false
162
+
163
+ if (drag?.active) autoScroll(dt)
164
+
165
+ for (const [id, s] of springs) {
166
+ if (drag?.active && id === drag.id) continue // follows the pointer, set in update()
167
+ const k = 2 * DAMPING * Math.sqrt(STIFFNESS)
168
+ s.vx += (-STIFFNESS * (s.x - s.tx) - k * s.vx) * dt
169
+ s.vy += (-STIFFNESS * (s.y - s.ty) - k * s.vy) * dt
170
+ s.x += s.vx * dt
171
+ s.y += s.vy * dt
172
+ if (Math.abs(s.x - s.tx) < 0.5 && Math.abs(s.y - s.ty) < 0.5 && Math.abs(s.vx) < 5 && Math.abs(s.vy) < 5) {
173
+ s.x = s.tx
174
+ s.y = s.ty
175
+ s.vx = s.vy = 0
176
+ } else {
177
+ moving = true
178
+ }
179
+ write(id)
180
+ }
181
+ if (stepSpring1(lift, dt)) moving = true
182
+ if (liftId !== null) write(liftId)
183
+ if (stepSpring1(ph, dt)) moving = true
184
+ if (phColumn !== null) {
185
+ const el = placeholderEls.get(phColumn)
186
+ if (el) el.style.transform = `translateY(${ph.p}px)`
187
+ }
188
+
189
+ if (moving || drag?.active) {
190
+ last = now
191
+ raf = requestAnimationFrame(step)
192
+ } else {
193
+ settlingId.value = null
194
+ if (lift.p === 0) liftId = null
195
+ }
196
+ }
197
+
198
+ // ---------- Pointer dragging ----------
199
+
200
+ // Inside a card, these never start a drag and never fire cardClick: native controls, plus
201
+ // any element the consumer marks with `data-kanban-action` (e.g. a clickable badge that
202
+ // opens its own menu, or a "copy key" span) so it can do something else instead.
203
+ const INTERACTIVE = 'input, textarea, select, button, a, label, [contenteditable], [data-kanban-action]'
204
+ let prevUserSelect = ''
205
+ let prevSnap = ''
206
+
207
+ function onPointerDown(e: PointerEvent, card: KanbanCard, columnId: Id, index: number) {
208
+ if (drag || e.button !== 0 || grabbedId.value !== null) return
209
+ if ((e.target as Element).closest(INTERACTIVE)) return
210
+ drag = {
211
+ id: card.id,
212
+ fromColumn: columnId,
213
+ fromIndex: index,
214
+ pointerId: e.pointerId,
215
+ startX: e.clientX,
216
+ startY: e.clientY,
217
+ lastX: e.clientX,
218
+ lastY: e.clientY,
219
+ active: false,
220
+ rect: null,
221
+ height: 0,
222
+ toColumn: columnId,
223
+ toIndex: index,
224
+ }
225
+ // Touch needs a long press, so swiping still scrolls the board / page.
226
+ if (e.pointerType === 'touch') drag.longPress = setTimeout(activate, 350)
227
+ window.addEventListener('pointermove', onPointerMove)
228
+ window.addEventListener('pointerup', onPointerUp)
229
+ window.addEventListener('pointercancel', onPointerCancel)
230
+ }
231
+
232
+ function activate() {
233
+ if (!drag || drag.active) return
234
+ clearTimeout(drag.longPress)
235
+ drag.longPress = undefined
236
+ const el = cardEls.get(drag.id)
237
+ if (!el) return cancelPress()
238
+
239
+ // Remember where every card is, take the dragged one out of the flow, then spring the
240
+ // cards below it up into the gap from where they were.
241
+ const before = captureRects()
242
+ const rect = el.getBoundingClientRect()
243
+ drag.rect = rect
244
+ drag.height = rect.height
245
+ drag.active = true
246
+ draggingId.value = drag.id
247
+ liftId = drag.id
248
+ lift.t = 1
249
+
250
+ Object.assign(el.style, {
251
+ position: 'fixed',
252
+ left: `${rect.left}px`,
253
+ top: `${rect.top}px`,
254
+ width: `${rect.width}px`,
255
+ height: `${rect.height}px`,
256
+ margin: '0',
257
+ zIndex: '60',
258
+ pointerEvents: 'none',
259
+ })
260
+ const s = springOf(drag.id)
261
+ s.x = s.y = s.vx = s.vy = 0
262
+ settleFrom(before, drag.id)
263
+
264
+ prevUserSelect = document.body.style.userSelect
265
+ document.body.style.userSelect = 'none'
266
+ window.getSelection()?.removeAllRanges()
267
+ if (boardEl.value) {
268
+ prevSnap = boardEl.value.style.scrollSnapType
269
+ boardEl.value.style.scrollSnapType = 'none'
270
+ }
271
+ const firstArea = areaEls.values().next().value
272
+ if (firstArea) basePadBottom = getComputedStyle(firstArea).paddingBottom
273
+ update(drag.lastX, drag.lastY)
274
+ kick()
275
+ }
276
+
277
+ function onPointerMove(e: PointerEvent) {
278
+ if (!drag || e.pointerId !== drag.pointerId) return
279
+ drag.lastX = e.clientX
280
+ drag.lastY = e.clientY
281
+ if (!drag.active) {
282
+ const dist = Math.hypot(e.clientX - drag.startX, e.clientY - drag.startY)
283
+ if (drag.longPress !== undefined) {
284
+ if (dist > 8) cancelPress()
285
+ return
286
+ }
287
+ if (dist < 4) return
288
+ activate()
73
289
  return
74
290
  }
291
+ update(e.clientX, e.clientY)
292
+ }
293
+
294
+ function columnAt(x: number): Id | null {
295
+ let best: Id | null = null
296
+ let bestDist = Infinity
297
+ for (const col of props.modelValue) {
298
+ const el = columnEls.get(col.id)
299
+ if (!el) continue
300
+ const r = el.getBoundingClientRect()
301
+ if (x >= r.left && x <= r.right) return col.id
302
+ const d = Math.min(Math.abs(x - r.left), Math.abs(x - r.right))
303
+ if (d < bestDist) {
304
+ bestDist = d
305
+ best = col.id
306
+ }
307
+ }
308
+ return best
309
+ }
75
310
 
76
- const columns = props.modelValue.map((col) => ({ ...col, cards: [...col.cards] }))
77
- const fromCol = columns.find((c) => c.id === fromColumnId)
78
- const toCol = columns.find((c) => c.id === toColumnId)
79
- if (!fromCol || !toCol) { reset(); return }
311
+ function update(x: number, y: number) {
312
+ if (!drag?.active || !drag.rect) return
313
+ const dragged = springOf(drag.id)
314
+ dragged.x = x - drag.startX
315
+ dragged.y = y - drag.startY
316
+ write(drag.id)
317
+
318
+ const colId = columnAt(x)
319
+ if (colId === null) return
320
+ const area = areaEls.get(colId)
321
+ const column = props.modelValue.find((c) => c.id === colId)
322
+ if (!area || !column) return
323
+
324
+ // Insertion index from the dragged card's center against the column's (closed-up) cards.
325
+ const areaRect = area.getBoundingClientRect()
326
+ const center = drag.rect.top + dragged.y + drag.height / 2 - areaRect.top
327
+ const others = column.cards.filter((c) => c.id !== drag!.id)
328
+ const els = others.map((c) => cardEls.get(c.id)).filter((el): el is HTMLElement => !!el)
329
+ let index = 0
330
+ for (const el of els) if (el.offsetTop + el.offsetHeight / 2 < center) index++
331
+
332
+ const gap = cardGap(area)
333
+ const shift = drag.height + gap
334
+ drag.toColumn = colId
335
+ drag.toIndex = index
336
+
337
+ for (const col of props.modelValue) {
338
+ col.cards.forEach((c) => {
339
+ if (c.id === drag!.id) return
340
+ const s = springOf(c.id)
341
+ s.tx = 0
342
+ s.ty = 0
343
+ })
344
+ }
345
+ others.forEach((c, i) => {
346
+ if (i >= index) springOf(c.id).ty = shift
347
+ })
348
+
349
+ // Placeholder slot + room for it at the bottom of the column.
350
+ const padTop = parseFloat(getComputedStyle(area).paddingTop) || 0
351
+ const slotTop = index < els.length
352
+ ? els[index]!.offsetTop
353
+ : els.length
354
+ ? els[els.length - 1]!.offsetTop + els[els.length - 1]!.offsetHeight + gap
355
+ : padTop
356
+ if (phColumn !== colId) {
357
+ if (phColumn !== null) {
358
+ const old = placeholderEls.get(phColumn)
359
+ if (old) old.style.opacity = '0'
360
+ const oldArea = areaEls.get(phColumn)
361
+ if (oldArea) oldArea.style.paddingBottom = ''
362
+ }
363
+ phColumn = colId
364
+ ph.p = slotTop
365
+ ph.v = 0
366
+ }
367
+ ph.t = slotTop
368
+ const phEl = placeholderEls.get(colId)
369
+ if (phEl) {
370
+ phEl.style.height = `${drag.height}px`
371
+ phEl.style.opacity = '1'
372
+ }
373
+ area.style.paddingBottom = `calc(${basePadBottom || '0px'} + ${shift}px)`
374
+ targetColumn.value = colId
375
+ kick()
376
+ }
377
+
378
+ const EDGE = 56
379
+ const MAX_SPEED = 900 // px/s
380
+ function autoScroll(dt: number) {
381
+ const board = boardEl.value
382
+ if (!board || !drag) return
383
+ const r = board.getBoundingClientRect()
384
+ let v = 0
385
+ if (drag.lastX < r.left + EDGE) v = -MAX_SPEED * (1 - Math.max(0, drag.lastX - r.left) / EDGE)
386
+ else if (drag.lastX > r.right - EDGE) v = MAX_SPEED * (1 - Math.max(0, r.right - drag.lastX) / EDGE)
387
+ if (!v) return
388
+ const before = board.scrollLeft
389
+ board.scrollLeft += v * dt
390
+ if (board.scrollLeft !== before) update(drag.lastX, drag.lastY)
391
+ }
392
+
393
+ function removeListeners() {
394
+ window.removeEventListener('pointermove', onPointerMove)
395
+ window.removeEventListener('pointerup', onPointerUp)
396
+ window.removeEventListener('pointercancel', onPointerCancel)
397
+ }
398
+
399
+ function cancelPress() {
400
+ if (drag) clearTimeout(drag.longPress)
401
+ drag = null
402
+ removeListeners()
403
+ }
404
+
405
+ function onPointerUp(e: PointerEvent) {
406
+ if (!drag || e.pointerId !== drag.pointerId) return
407
+ if (!drag.active) return cancelPress()
408
+ finishDrag(true)
409
+ }
410
+ function onPointerCancel(e: PointerEvent) {
411
+ if (!drag || e.pointerId !== drag.pointerId) return
412
+ if (!drag.active) return cancelPress()
413
+ finishDrag(false)
414
+ }
80
415
 
81
- const cardIndex = fromCol.cards.findIndex((c) => c.id === cardId)
82
- if (cardIndex === -1) { reset(); return }
416
+ function clearDragChrome() {
417
+ for (const area of areaEls.values()) area.style.paddingBottom = ''
418
+ for (const el of placeholderEls.values()) el.style.opacity = '0'
419
+ phColumn = null
420
+ targetColumn.value = null
421
+ }
83
422
 
84
- const removed = fromCol.cards.splice(cardIndex, 1)
85
- const toIndex = overCardIndex.value ?? toCol.cards.length
86
- toCol.cards.splice(toIndex, 0, removed[0]!)
423
+ function unfix(el: HTMLElement) {
424
+ Object.assign(el.style, { position: '', left: '', top: '', width: '', height: '', margin: '', zIndex: '', pointerEvents: '' })
425
+ }
87
426
 
427
+ function finishDrag(commitMove: boolean) {
428
+ if (!drag) return
429
+ const d = drag
430
+ drag = null
431
+ removeListeners()
432
+ document.body.style.userSelect = prevUserSelect
433
+ if (boardEl.value) boardEl.value.style.scrollSnapType = prevSnap
434
+ // The pointerup's click lands on the card; don't treat a drag as a cardClick.
435
+ suppressClick = true
436
+ setTimeout(() => (suppressClick = false), 0)
437
+ draggingId.value = null
438
+ settlingId.value = d.id
439
+ lift.t = 0
440
+
441
+ const moved = commitMove && (d.toColumn !== d.fromColumn || d.toIndex !== d.fromIndex)
442
+ if (moved) {
443
+ // onBeforeUpdate captures the fixed card's on-screen rect and un-fixes it; onUpdated
444
+ // springs it (and everyone else) into place.
445
+ pendingUnfix = d.id
446
+ commit(d.id, d.fromColumn, d.toColumn, d.toIndex)
447
+ // If the parent doesn't apply the update, fall back to animating home.
448
+ queueMicrotask(() => {
449
+ if (pendingUnfix === d.id) setTimeout(() => pendingUnfix === d.id && returnHome(d.id), 0)
450
+ })
451
+ } else {
452
+ returnHome(d.id)
453
+ }
454
+ kick()
455
+ }
456
+
457
+ function returnHome(id: Id) {
458
+ pendingUnfix = null
459
+ const before = captureRects()
460
+ const el = cardEls.get(id)
461
+ if (el) unfix(el)
462
+ clearDragChrome()
463
+ settleFrom(before)
464
+ }
465
+
466
+ function commit(cardId: Id, fromColumn: Id, toColumn: Id, toIndex: number) {
467
+ const columns = props.modelValue.map((col) => ({ ...col, cards: [...col.cards] }))
468
+ const from = columns.find((c) => c.id === fromColumn)
469
+ const to = columns.find((c) => c.id === toColumn)
470
+ if (!from || !to) return
471
+ const i = from.cards.findIndex((c) => c.id === cardId)
472
+ if (i === -1) return
473
+ const [card] = from.cards.splice(i, 1)
474
+ to.cards.splice(Math.min(toIndex, to.cards.length), 0, card!)
88
475
  emit('update:modelValue', columns)
89
- emit('cardMove', { cardId, fromColumn: fromColumnId, toColumn: toColumnId, toIndex })
90
- reset()
476
+ emit('cardMove', { cardId, fromColumn, toColumn, toIndex })
477
+ }
478
+
479
+ // While a card is actually being dragged, stop the page/board from scrolling under the finger.
480
+ function onTouchMove(e: TouchEvent) {
481
+ if (drag?.active && e.cancelable) e.preventDefault()
482
+ }
483
+ function onContextMenu(e: Event) {
484
+ if (drag) e.preventDefault()
485
+ }
486
+
487
+ // ---------- FLIP ----------
488
+
489
+ function captureRects() {
490
+ const m = new Map<Id, DOMRect>()
491
+ for (const [id, el] of cardEls) m.set(id, el.getBoundingClientRect())
492
+ return m
493
+ }
494
+
495
+ // Spring every card from its previous on-screen rect to wherever it is now.
496
+ function settleFrom(before: Map<Id, DOMRect>, skip?: Id) {
497
+ const ids: Id[] = []
498
+ for (const [id, el] of cardEls) {
499
+ if (id === skip || !before.has(id)) continue
500
+ const s = springOf(id)
501
+ s.x = s.y = 0
502
+ el.style.transform = ''
503
+ ids.push(id)
504
+ }
505
+ let changed = false
506
+ for (const id of ids) {
507
+ const el = cardEls.get(id)!
508
+ const b = before.get(id)!
509
+ const a = el.getBoundingClientRect()
510
+ const s = springOf(id)
511
+ s.x = b.left - a.left
512
+ s.y = b.top - a.top
513
+ s.tx = 0
514
+ s.ty = 0
515
+ if (Math.abs(s.x) > 0.5 || Math.abs(s.y) > 0.5) changed = true
516
+ write(id)
517
+ }
518
+ if (changed || lift.p !== lift.t) kick()
519
+ }
520
+
521
+ let pendingUnfix: Id | null = null
522
+ let beforeUpdate: Map<Id, DOMRect> | null = null
523
+ onBeforeUpdate(() => {
524
+ if (drag?.active) return
525
+ beforeUpdate = captureRects()
526
+ if (pendingUnfix !== null) {
527
+ const el = cardEls.get(pendingUnfix)
528
+ if (el) unfix(el)
529
+ clearDragChrome()
530
+ pendingUnfix = null
531
+ }
532
+ })
533
+ onUpdated(() => {
534
+ const before = beforeUpdate
535
+ beforeUpdate = null
536
+ if (before) settleFrom(before)
537
+ if (grabbedId.value !== null) focusCard(grabbedId.value)
538
+ })
539
+
540
+ // ---------- Keyboard ----------
541
+
542
+ let grabOrigin: KanbanColumn[] | null = null
543
+ let grabFrom: { column: Id; index: number } | null = null
544
+
545
+ function locate(cardId: Id) {
546
+ for (const col of props.modelValue) {
547
+ const index = col.cards.findIndex((c) => c.id === cardId)
548
+ if (index !== -1) return { column: col, index }
549
+ }
550
+ return null
551
+ }
552
+
553
+ function say(template: string, columnTitle: string, index: number, total: number) {
554
+ announcement.value = template
555
+ .replace('{column}', columnTitle)
556
+ .replace('{pos}', String(index + 1))
557
+ .replace('{total}', String(total))
558
+ }
559
+
560
+ function focusCard(id: Id) {
561
+ const el = cardEls.get(id)
562
+ if (el && document.activeElement !== el) el.focus({ preventScroll: false })
563
+ }
564
+
565
+ function onCardKeydown(e: KeyboardEvent, card: KanbanCard, column: KanbanColumn) {
566
+ if (e.target !== e.currentTarget) return
567
+ const here = locate(card.id)
568
+ if (!here) return
569
+ const grabbed = grabbedId.value === card.id
570
+
571
+ if (e.key === ' ') {
572
+ e.preventDefault()
573
+ if (!grabbed) {
574
+ grabbedId.value = card.id
575
+ liftId = card.id
576
+ lift.t = 1
577
+ grabOrigin = props.modelValue.map((c) => ({ ...c, cards: [...c.cards] }))
578
+ grabFrom = { column: column.id, index: here.index }
579
+ say(locale.reorderGrabbed, column.title, here.index, column.cards.length)
580
+ } else {
581
+ dropKeyboard(card.id)
582
+ say(locale.reorderDropped, column.title, here.index, column.cards.length)
583
+ }
584
+ kick()
585
+ return
586
+ }
587
+ if (!grabbed) {
588
+ if (e.key === 'Enter') {
589
+ e.preventDefault()
590
+ emit('cardClick', { card, columnId: column.id })
591
+ }
592
+ return
593
+ }
594
+ const cols = props.modelValue
595
+ const ci = cols.findIndex((c) => c.id === here.column.id)
596
+ let toCol = here.column
597
+ let toIndex = here.index
598
+ if (e.key === 'ArrowUp') toIndex = here.index - 1
599
+ else if (e.key === 'ArrowDown') toIndex = here.index + 1
600
+ else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
601
+ const next = cols[ci + (e.key === 'ArrowLeft' ? -1 : 1)]
602
+ if (!next) return e.preventDefault()
603
+ toCol = next
604
+ toIndex = Math.min(here.index, next.cards.length)
605
+ } else if (e.key === 'Escape') {
606
+ e.preventDefault()
607
+ cancelKeyboard(card.id, here.column.id, here.index)
608
+ return
609
+ } else if (e.key === 'Enter') {
610
+ e.preventDefault()
611
+ dropKeyboard(card.id)
612
+ say(locale.reorderDropped, column.title, here.index, column.cards.length)
613
+ return
614
+ } else {
615
+ return
616
+ }
617
+ e.preventDefault()
618
+ const total = toCol === here.column ? toCol.cards.length : toCol.cards.length + 1
619
+ if (toIndex < 0 || toIndex >= total) return
620
+ commit(card.id, here.column.id, toCol.id, toIndex)
621
+ say(locale.kanbanMoved, toCol.title, toIndex, total)
622
+ }
623
+
624
+ function dropKeyboard(id: Id) {
625
+ grabbedId.value = null
626
+ grabOrigin = null
627
+ grabFrom = null
628
+ settlingId.value = id
629
+ lift.t = 0
630
+ kick()
631
+ }
632
+
633
+ function cancelKeyboard(id: Id, currentColumn: Id, currentIndex: number) {
634
+ const origin = grabOrigin
635
+ const from = grabFrom
636
+ dropKeyboard(id)
637
+ if (origin && from && (from.column !== currentColumn || from.index !== currentIndex)) {
638
+ emit('update:modelValue', origin)
639
+ emit('cardMove', { cardId: id, fromColumn: currentColumn, toColumn: from.column, toIndex: from.index })
640
+ }
641
+ announcement.value = locale.reorderCancelled
642
+ }
643
+
644
+ function onCardBlur(card: KanbanCard) {
645
+ if (grabbedId.value !== card.id) return
646
+ // Moving a card to another column recreates its element, which blurs it; onUpdated
647
+ // refocuses it. Only a real tab-away drops the grab.
648
+ requestAnimationFrame(() => {
649
+ const el = cardEls.get(card.id)
650
+ if (grabbedId.value === card.id && el && document.activeElement !== el) dropKeyboard(card.id)
651
+ })
652
+ }
653
+
654
+ function onCardClick(e: MouseEvent, card: KanbanCard, columnId: Id) {
655
+ if (suppressClick) return
656
+ const hit = (e.target as Element).closest(INTERACTIVE)
657
+ if (hit && hit !== e.currentTarget && (e.currentTarget as Element).contains(hit)) return
658
+ emit('cardClick', { card, columnId })
91
659
  }
92
660
 
93
- function reset() {
94
- dragCard.value = null
95
- overColumn.value = null
96
- overCardIndex.value = null
661
+ // ---------- Presentation ----------
662
+
663
+ const dotColor: Record<string, string> = {
664
+ primary: 'bg-primary',
665
+ secondary: 'bg-secondary',
666
+ tertiary: 'bg-tertiary',
667
+ error: 'bg-error',
668
+ success: 'bg-success',
97
669
  }
670
+
671
+ const isLifted = (id: Id) => draggingId.value === id || settlingId.value === id || grabbedId.value === id
672
+ const overLimit = (col: KanbanColumn) => col.limit != null && col.cards.length > col.limit
673
+ const atLimit = (col: KanbanColumn) => col.limit != null && col.cards.length === col.limit
674
+
675
+ onMounted(() => {
676
+ boardEl.value?.addEventListener('touchmove', onTouchMove, { passive: false })
677
+ })
678
+ onBeforeUnmount(() => {
679
+ boardEl.value?.removeEventListener('touchmove', onTouchMove)
680
+ cancelAnimationFrame(raf)
681
+ raf = 0
682
+ if (drag) {
683
+ clearTimeout(drag.longPress)
684
+ if (drag.active) document.body.style.userSelect = prevUserSelect
685
+ }
686
+ drag = null
687
+ removeListeners()
688
+ })
98
689
  </script>
99
690
 
100
691
  <template>
101
- <div class="flex gap-4 overflow-x-auto pb-2">
102
- <div
692
+ <div
693
+ ref="boardEl"
694
+ class="flex snap-x snap-proximity items-start gap-3 overflow-x-auto pb-3 [scrollbar-width:thin]"
695
+ @contextmenu="onContextMenu"
696
+ >
697
+ <section
103
698
  v-for="column in modelValue"
104
699
  :key="column.id"
105
- class="flex w-72 shrink-0 flex-col rounded-xl bg-surface-container-low"
106
- :class="overColumn === column.id && dragCard ? 'ring-2 ring-primary ring-inset' : ''"
107
- @dragover="onColumnDragOver($event, column.id)"
108
- @dragleave="overColumn = null"
109
- @drop="onDrop($event, column.id)"
700
+ :ref="(el) => setRef(columnEls, column.id, el)"
701
+ class="relative flex w-72 shrink-0 snap-start flex-col rounded-lg bg-surface-container"
110
702
  >
111
- <!-- Column header -->
112
- <div class="flex items-center gap-2 px-4 py-3">
113
- <div v-if="column.color" class="h-2.5 w-2.5 rounded-full" :class="colorMap[column.color] ?? 'bg-primary'" />
114
- <h3 class="flex-1 text-title-small font-medium text-on-surface">{{ column.title }}</h3>
115
- <span class="rounded-full bg-surface-container-high px-2 py-0.5 text-label-small text-on-surface-variant">
116
- {{ column.cards.length }}
117
- </span>
118
- </div>
703
+ <!-- Drop-target tint -->
704
+ <span
705
+ aria-hidden="true"
706
+ class="pointer-events-none absolute inset-0 rounded-[inherit] bg-primary transition-opacity duration-200"
707
+ :class="targetColumn === column.id ? 'opacity-[0.06]' : 'opacity-0'"
708
+ />
709
+
710
+ <!-- Header -->
711
+ <header class="relative flex items-center gap-2 px-4 pt-4 pb-2">
712
+ <slot name="column-header" :column="column" :count="column.cards.length">
713
+ <span v-if="column.color" class="h-2.5 w-2.5 shrink-0 rounded-full" :class="dotColor[column.color] ?? 'bg-primary'" />
714
+ <h3 class="min-w-0 flex-1 truncate text-title-medium text-on-surface">{{ column.title }}</h3>
715
+ <span
716
+ class="shrink-0 rounded-full px-2 py-0.5 text-label-medium tabular-nums transition-colors duration-200"
717
+ :class="
718
+ overLimit(column)
719
+ ? 'bg-error-container text-on-error-container'
720
+ : atLimit(column)
721
+ ? 'bg-tertiary-container text-on-tertiary-container'
722
+ : 'bg-surface-container-highest text-on-surface-variant'
723
+ "
724
+ >
725
+ {{ column.cards.length }}<template v-if="column.limit != null">/{{ column.limit }}</template>
726
+ </span>
727
+ </slot>
728
+ </header>
729
+
730
+ <!-- Cards -->
731
+ <div
732
+ :ref="(el) => setRef(areaEls, column.id, el)"
733
+ class="relative flex min-h-24 flex-1 flex-col gap-2 px-3 pt-1 pb-3 transition-[padding] duration-200"
734
+ role="list"
735
+ :aria-label="column.title"
736
+ >
737
+ <div
738
+ :ref="(el) => setRef(placeholderEls, column.id, el)"
739
+ aria-hidden="true"
740
+ class="pointer-events-none absolute inset-x-3 top-0 rounded-md border-2 border-dashed border-primary/50 bg-primary/8 opacity-0 transition-opacity duration-150"
741
+ />
119
742
 
120
- <!-- Cards area -->
121
- <div class="flex min-h-[60px] flex-1 flex-col gap-2 px-3 pb-3">
122
743
  <div
123
744
  v-for="(card, index) in column.cards"
124
745
  :key="card.id"
125
- draggable="true"
126
- class="cursor-grab rounded-lg bg-surface p-3 shadow-elevation-1 transition-all duration-150 active:cursor-grabbing"
746
+ :ref="(el) => setCardEl(card.id, el)"
747
+ role="listitem"
748
+ tabindex="0"
749
+ :aria-grabbed="grabbedId === card.id"
750
+ class="group relative cursor-grab touch-manipulation select-none rounded-md bg-surface-container-low p-4 outline-none [-webkit-touch-callout:none] transition-shadow duration-150 focus-visible:ring-2 focus-visible:ring-secondary"
127
751
  :class="[
128
- dragCard?.cardId === card.id ? 'opacity-30' : 'hover:shadow-elevation-2',
129
- overCardIndex === index && overColumn === column.id && dragCard ? 'border-t-2 border-primary' : '',
752
+ isLifted(card.id) ? 'shadow-elevation-4' : 'shadow-elevation-1 hover:shadow-elevation-2',
753
+ draggingId === card.id ? 'cursor-grabbing' : '',
130
754
  ]"
131
- @dragstart="onCardDragStart($event, card, column.id)"
132
- @dragover="onCardDragOver($event, card, index, column.id)"
133
- @dragend="reset"
134
- @click="emit('cardClick', { card, columnId: column.id })"
755
+ @pointerdown="onPointerDown($event, card, column.id, index)"
756
+ @click="onCardClick($event, card, column.id)"
757
+ @keydown="onCardKeydown($event, card, column)"
758
+ @blur="onCardBlur(card)"
135
759
  >
136
- <slot name="card" :card="card" :column="column">
137
- <p class="text-body-medium text-on-surface">{{ card.id }}</p>
138
- </slot>
760
+ <!-- State layer: 8% hover, 16% while dragged -->
761
+ <span
762
+ aria-hidden="true"
763
+ class="pointer-events-none absolute inset-0 rounded-[inherit] bg-on-surface transition-opacity duration-150"
764
+ :class="isLifted(card.id) ? 'opacity-[0.08]' : 'opacity-0 group-hover:opacity-[0.04]'"
765
+ />
766
+ <div class="relative">
767
+ <slot name="card" :card="card" :column="column" :dragging="isLifted(card.id)">
768
+ <p class="text-body-medium text-on-surface">{{ card.id }}</p>
769
+ </slot>
770
+ </div>
139
771
  </div>
140
772
 
141
773
  <!-- Empty state -->
142
774
  <div
143
775
  v-if="column.cards.length === 0"
144
- class="flex flex-1 items-center justify-center rounded-lg border border-dashed border-outline-variant/50 p-4"
776
+ class="flex min-h-24 flex-1 flex-col items-center justify-center gap-1 rounded-md border-2 border-dashed p-4 text-center transition-colors duration-200"
777
+ :class="targetColumn === column.id ? 'border-transparent' : 'border-outline-variant'"
145
778
  >
146
- <p class="text-body-small text-on-surface-variant/60">{{ emptyText ?? locale.noItems }}</p>
779
+ <template v-if="targetColumn !== column.id">
780
+ <MIcon name="inbox" :size="24" class="text-on-surface-variant/60" />
781
+ <p class="text-body-small text-on-surface-variant">{{ emptyText ?? locale.noItems }}</p>
782
+ </template>
147
783
  </div>
148
784
  </div>
149
- </div>
785
+
786
+ <footer v-if="$slots['column-footer']" class="relative px-3 pb-3">
787
+ <slot name="column-footer" :column="column" />
788
+ </footer>
789
+ </section>
790
+
791
+ <div class="sr-only" aria-live="assertive" aria-atomic="true">{{ announcement }}</div>
150
792
  </div>
151
793
  </template>