@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.
- package/README.md +1 -1
- package/dist/{MMenuItem-DiilFeDO.js → MMenuItem-BmPLAyv5.js} +64 -62
- package/dist/{MMenuItem-DiilFeDO.js.map → MMenuItem-BmPLAyv5.js.map} +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MChatBubble.vue.d.ts +4 -2
- package/dist/components/MCheckbox.vue.d.ts +2 -0
- package/dist/components/MDragDropList.vue.d.ts +19 -6
- package/dist/components/MFileUpload.vue.d.ts +16 -4
- package/dist/components/MKanban.vue.d.ts +15 -6
- package/dist/components/MTable.vue.d.ts +8 -0
- package/dist/components/MTransferList.vue.d.ts +9 -3
- package/dist/components/_MTransferPane.vue.d.ts +39 -0
- package/dist/composables/useLocale.d.ts +24 -0
- package/dist/locales/index.js +175 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +3600 -2696
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +2 -2
- package/dist/styles.css +1 -1
- package/dist/{useLocale-DbREg9Zn.js → useLocale-4afAzuuP.js} +26 -2
- package/dist/useLocale-4afAzuuP.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MChatBubble.test.ts +33 -0
- package/src/__tests__/MDragDropList.test.ts +194 -0
- package/src/__tests__/MFileUpload.test.ts +78 -0
- package/src/__tests__/MKanban.test.ts +150 -0
- package/src/__tests__/MMenu.test.ts +84 -0
- package/src/__tests__/MPullToRefresh.test.ts +67 -0
- package/src/__tests__/MRating.test.ts +72 -0
- package/src/__tests__/MTransferList.test.ts +76 -0
- package/src/components/MChatBubble.vue +107 -20
- package/src/components/MCheckbox.vue +3 -0
- package/src/components/MContextMenu.vue +10 -1
- package/src/components/MDragDropList.vue +485 -56
- package/src/components/MFileUpload.vue +56 -20
- package/src/components/MKanban.vue +720 -78
- package/src/components/MMenu.vue +10 -1
- package/src/components/MNavigationRail.vue +35 -23
- package/src/components/MPullToRefresh.vue +101 -35
- package/src/components/MRating.vue +163 -67
- package/src/components/MResult.vue +19 -9
- package/src/components/MTable.vue +10 -3
- package/src/components/MTransferList.vue +133 -130
- package/src/components/_MTransferPane.vue +182 -0
- package/src/composables/useLocale.ts +68 -0
- package/src/locales/de.ts +34 -0
- package/src/locales/es.ts +34 -0
- package/src/locales/fr.ts +34 -0
- package/src/locales/ja.ts +34 -0
- package/src/locales/ko.ts +34 -0
- package/src/locales/pt.ts +34 -0
- package/src/locales/zh.ts +34 -0
- package/dist/useLocale-DbREg9Zn.js.map +0 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MKanban from '../components/MKanban.vue'
|
|
5
|
+
import type { KanbanColumn } from '../components/MKanban.vue'
|
|
6
|
+
|
|
7
|
+
const board = (): KanbanColumn[] => [
|
|
8
|
+
{ id: 'todo', title: 'To do', cards: [{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }] },
|
|
9
|
+
{ id: 'doing', title: 'Doing', cards: [{ id: 'e' }], limit: 1 },
|
|
10
|
+
{ id: 'done', title: 'Done', cards: [] },
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
function rect(left: number, top: number, width: number, height: number) {
|
|
14
|
+
return { left, top, width, height, right: left + width, bottom: top + height, x: left, y: top, toJSON() {} } as DOMRect
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// happy-dom has no layout: columns 300px apart, card areas start at y=50, cards 56px + 8px gap.
|
|
18
|
+
function layout(w: ReturnType<typeof mount>) {
|
|
19
|
+
w.findAll('section').forEach((col, ci) => {
|
|
20
|
+
const left = ci * 300
|
|
21
|
+
col.element.getBoundingClientRect = () => rect(left, 0, 288, 600)
|
|
22
|
+
const area = col.find('[role="list"]').element as HTMLElement
|
|
23
|
+
area.getBoundingClientRect = () => rect(left, 50, 288, 500)
|
|
24
|
+
col.findAll('[role="listitem"]').forEach((card, i) => {
|
|
25
|
+
Object.defineProperty(card.element, 'offsetTop', { value: i * 64, configurable: true })
|
|
26
|
+
Object.defineProperty(card.element, 'offsetHeight', { value: 56, configurable: true })
|
|
27
|
+
card.element.getBoundingClientRect = () => rect(left + 12, 50 + i * 64, 264, 56)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function pointer(target: Element | Window, type: string, x: number, y: number) {
|
|
33
|
+
target.dispatchEvent(new PointerEvent(type, { bubbles: true, cancelable: true, button: 0, pointerId: 1, pointerType: 'mouse', clientX: x, clientY: y }))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function mountBoard() {
|
|
37
|
+
const w = mount(MKanban, {
|
|
38
|
+
props: { modelValue: board(), 'onUpdate:modelValue': (v: KanbanColumn[]) => w.setProps({ modelValue: v }) },
|
|
39
|
+
attachTo: document.body,
|
|
40
|
+
})
|
|
41
|
+
return w
|
|
42
|
+
}
|
|
43
|
+
const ids = (w: ReturnType<typeof mount>) =>
|
|
44
|
+
(w.props('modelValue') as KanbanColumn[]).map((c) => c.cards.map((x) => x.id).join(''))
|
|
45
|
+
const card = (w: ReturnType<typeof mount>, id: string) =>
|
|
46
|
+
w.findAll('[role="listitem"]').find((c) => c.text() === id)!
|
|
47
|
+
|
|
48
|
+
describe('MKanban', () => {
|
|
49
|
+
it('drags a card to another column', async () => {
|
|
50
|
+
const w = mountBoard()
|
|
51
|
+
layout(w)
|
|
52
|
+
pointer(card(w, 'a').element, 'pointerdown', 100, 70)
|
|
53
|
+
pointer(window, 'pointermove', 110, 70)
|
|
54
|
+
pointer(window, 'pointermove', 400, 70)
|
|
55
|
+
pointer(window, 'pointerup', 400, 70)
|
|
56
|
+
await nextTick()
|
|
57
|
+
expect(ids(w)).toEqual(['bcd', 'ae', ''])
|
|
58
|
+
expect(w.emitted('cardMove')![0]![0]).toEqual({ cardId: 'a', fromColumn: 'todo', toColumn: 'doing', toIndex: 0 })
|
|
59
|
+
w.unmount()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('reorders within a column without the old off-by-one', async () => {
|
|
63
|
+
const w = mountBoard()
|
|
64
|
+
layout(w)
|
|
65
|
+
// Drag "a" down so its center sits just above "c"'s middle: it should land between b and c.
|
|
66
|
+
pointer(card(w, 'a').element, 'pointerdown', 100, 70)
|
|
67
|
+
pointer(window, 'pointermove', 100, 80)
|
|
68
|
+
// The mock keeps b/c/d at their mount-time offsets (64/128/192, midpoints 92/156/220).
|
|
69
|
+
// A drag of +100px puts a's center at 128: past b's middle, before c's -> between b and c.
|
|
70
|
+
pointer(window, 'pointermove', 100, 170)
|
|
71
|
+
pointer(window, 'pointerup', 100, 170)
|
|
72
|
+
await nextTick()
|
|
73
|
+
expect(ids(w)[0]).toBe('bacd')
|
|
74
|
+
w.unmount()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('does not emit when a card is dropped where it was', async () => {
|
|
78
|
+
const w = mountBoard()
|
|
79
|
+
layout(w)
|
|
80
|
+
pointer(card(w, 'b').element, 'pointerdown', 100, 134)
|
|
81
|
+
pointer(window, 'pointermove', 100, 140)
|
|
82
|
+
pointer(window, 'pointerup', 100, 140)
|
|
83
|
+
await nextTick()
|
|
84
|
+
expect(w.emitted('cardMove')).toBeUndefined()
|
|
85
|
+
w.unmount()
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('moves cards with the keyboard and announces the column', async () => {
|
|
89
|
+
const w = mountBoard()
|
|
90
|
+
await card(w, 'a').trigger('keydown', { key: ' ' })
|
|
91
|
+
await card(w, 'a').trigger('keydown', { key: 'ArrowDown' })
|
|
92
|
+
expect(ids(w)[0]).toBe('bacd')
|
|
93
|
+
await card(w, 'a').trigger('keydown', { key: 'ArrowRight' })
|
|
94
|
+
expect(ids(w)).toEqual(['bcd', 'ea', ''])
|
|
95
|
+
expect(w.find('[aria-live]').text()).toBe('Moved to Doing, position 2 of 2.')
|
|
96
|
+
await card(w, 'a').trigger('keydown', { key: 'Escape' })
|
|
97
|
+
expect(ids(w)).toEqual(['abcd', 'e', ''])
|
|
98
|
+
w.unmount()
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('emits cardClick on click and Enter, but not after a drag', async () => {
|
|
102
|
+
const w = mountBoard()
|
|
103
|
+
layout(w)
|
|
104
|
+
await card(w, 'b').trigger('click')
|
|
105
|
+
await card(w, 'c').trigger('keydown', { key: 'Enter' })
|
|
106
|
+
expect(w.emitted('cardClick')!.map((e) => (e[0] as { card: { id: string } }).card.id)).toEqual(['b', 'c'])
|
|
107
|
+
const d = card(w, 'd').element
|
|
108
|
+
pointer(d, 'pointerdown', 100, 250)
|
|
109
|
+
pointer(window, 'pointermove', 100, 270)
|
|
110
|
+
pointer(window, 'pointerup', 100, 270)
|
|
111
|
+
d.dispatchEvent(new MouseEvent('click', { bubbles: true }))
|
|
112
|
+
expect(w.emitted('cardClick')).toHaveLength(2)
|
|
113
|
+
w.unmount()
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('shows the WIP limit and flags it when exceeded', async () => {
|
|
117
|
+
const w = mountBoard()
|
|
118
|
+
const doingHeader = () => w.findAll('section')[1]!.find('header')
|
|
119
|
+
expect(doingHeader().text()).toContain('1/1')
|
|
120
|
+
await card(w, 'a').trigger('keydown', { key: ' ' })
|
|
121
|
+
await card(w, 'a').trigger('keydown', { key: 'ArrowRight' })
|
|
122
|
+
expect(doingHeader().text()).toContain('2/1')
|
|
123
|
+
expect(doingHeader().find('.bg-error-container').exists()).toBe(true)
|
|
124
|
+
w.unmount()
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
describe('MKanban card actions', () => {
|
|
129
|
+
it('does not fire cardClick or start a drag from buttons or data-kanban-action areas', async () => {
|
|
130
|
+
const w = mount(MKanban, {
|
|
131
|
+
props: { modelValue: board() },
|
|
132
|
+
slots: {
|
|
133
|
+
card: `<template #card="{ card }"><span class="title">{{ card.id }}</span><button class="btn">menu</button><span class="act" data-kanban-action>copy</span></template>`,
|
|
134
|
+
},
|
|
135
|
+
attachTo: document.body,
|
|
136
|
+
})
|
|
137
|
+
layout(w)
|
|
138
|
+
const first = w.findAll('[role="listitem"]')[0]!
|
|
139
|
+
await first.find('.btn').trigger('click')
|
|
140
|
+
await first.find('.act').trigger('click')
|
|
141
|
+
expect(w.emitted('cardClick')).toBeUndefined()
|
|
142
|
+
await first.find('.title').trigger('click')
|
|
143
|
+
expect(w.emitted('cardClick')).toHaveLength(1)
|
|
144
|
+
pointer(first.find('.act').element, 'pointerdown', 100, 70)
|
|
145
|
+
pointer(window, 'pointermove', 400, 70)
|
|
146
|
+
pointer(window, 'pointerup', 400, 70)
|
|
147
|
+
expect(w.emitted('cardMove')).toBeUndefined()
|
|
148
|
+
w.unmount()
|
|
149
|
+
})
|
|
150
|
+
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest'
|
|
2
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
3
|
+
import { mount } from '@vue/test-utils'
|
|
4
|
+
import MMenu from '../components/MMenu.vue'
|
|
5
|
+
import MContextMenu from '../components/MContextMenu.vue'
|
|
6
|
+
|
|
7
|
+
const frame = () => new Promise<void>((r) => requestAnimationFrame(() => r()))
|
|
8
|
+
// Long enough for the open spring to finish, so the close has real distance to cover
|
|
9
|
+
const settle = () => new Promise<void>((r) => setTimeout(r, 400))
|
|
10
|
+
|
|
11
|
+
describe('MMenu', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
document.body.innerHTML = ''
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('removes its panel from <body> when unmounted mid-close', async () => {
|
|
17
|
+
// e.g. a "Log out" item: close() then router.push() unmounts the menu
|
|
18
|
+
// while its close animation is still playing
|
|
19
|
+
const show = ref(true)
|
|
20
|
+
const menuRef = ref<InstanceType<typeof MMenu> | null>(null)
|
|
21
|
+
mount(
|
|
22
|
+
defineComponent({
|
|
23
|
+
setup: () => () =>
|
|
24
|
+
show.value
|
|
25
|
+
? h(MMenu, { ref: menuRef }, {
|
|
26
|
+
trigger: () => h('button', { class: 'trigger' }, 'open'),
|
|
27
|
+
default: () => h('span', { class: 'item' }, 'Log out'),
|
|
28
|
+
})
|
|
29
|
+
: null,
|
|
30
|
+
}),
|
|
31
|
+
{ attachTo: document.body, global: { stubs: { transition: false } } },
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
document.querySelector<HTMLElement>('.trigger')!.click()
|
|
35
|
+
await nextTick()
|
|
36
|
+
expect(document.querySelector('.item')).not.toBeNull()
|
|
37
|
+
await settle()
|
|
38
|
+
|
|
39
|
+
menuRef.value!.close()
|
|
40
|
+
await nextTick()
|
|
41
|
+
await frame()
|
|
42
|
+
show.value = false
|
|
43
|
+
await nextTick()
|
|
44
|
+
|
|
45
|
+
expect(document.querySelector('.item')).toBeNull()
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
describe('MContextMenu', () => {
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
document.body.innerHTML = ''
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('removes its panel from <body> when unmounted mid-close', async () => {
|
|
55
|
+
const show = ref(true)
|
|
56
|
+
mount(
|
|
57
|
+
defineComponent({
|
|
58
|
+
setup: () => () =>
|
|
59
|
+
show.value
|
|
60
|
+
? h(MContextMenu, null, {
|
|
61
|
+
trigger: () => h('div', { class: 'area' }, 'right-click me'),
|
|
62
|
+
default: () => h('span', { class: 'item' }, 'Delete'),
|
|
63
|
+
})
|
|
64
|
+
: null,
|
|
65
|
+
}),
|
|
66
|
+
{ attachTo: document.body, global: { stubs: { transition: false } } },
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
document.querySelector('.area')!.dispatchEvent(
|
|
70
|
+
new MouseEvent('contextmenu', { bubbles: true, clientX: 10, clientY: 10 }),
|
|
71
|
+
)
|
|
72
|
+
await nextTick()
|
|
73
|
+
expect(document.querySelector('.item')).not.toBeNull()
|
|
74
|
+
await settle()
|
|
75
|
+
|
|
76
|
+
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
|
|
77
|
+
await nextTick()
|
|
78
|
+
await frame()
|
|
79
|
+
show.value = false
|
|
80
|
+
await nextTick()
|
|
81
|
+
|
|
82
|
+
expect(document.querySelector('.item')).toBeNull()
|
|
83
|
+
})
|
|
84
|
+
})
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MPullToRefresh from '../components/MPullToRefresh.vue'
|
|
4
|
+
|
|
5
|
+
function touch(el: Element, type: string, y: number) {
|
|
6
|
+
const t = { identifier: 1, clientY: y, clientX: 0, target: el }
|
|
7
|
+
const ev = new Event(type, { bubbles: true, cancelable: true }) as Event & Record<string, unknown>
|
|
8
|
+
Object.assign(ev, {
|
|
9
|
+
touches: type === 'touchend' ? [] : [t],
|
|
10
|
+
changedTouches: [t],
|
|
11
|
+
})
|
|
12
|
+
el.dispatchEvent(ev)
|
|
13
|
+
return ev
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function mountPtr() {
|
|
17
|
+
const wrapper = mount(MPullToRefresh, { slots: { default: '<div>list</div>' }, attachTo: document.body })
|
|
18
|
+
const scrollEl = wrapper.find('.overflow-y-auto').element
|
|
19
|
+
return { wrapper, scrollEl }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('MPullToRefresh (touch)', () => {
|
|
23
|
+
it('blocks native scroll and emits refresh on a downward pull past threshold', () => {
|
|
24
|
+
const { wrapper, scrollEl } = mountPtr()
|
|
25
|
+
touch(scrollEl, 'touchstart', 100)
|
|
26
|
+
const move1 = touch(scrollEl, 'touchmove', 120)
|
|
27
|
+
const move2 = touch(scrollEl, 'touchmove', 200)
|
|
28
|
+
touch(scrollEl, 'touchend', 200)
|
|
29
|
+
expect(move1.defaultPrevented).toBe(true)
|
|
30
|
+
expect(move2.defaultPrevented).toBe(true)
|
|
31
|
+
expect(wrapper.emitted('refresh')).toHaveLength(1)
|
|
32
|
+
wrapper.unmount()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('does not refresh on a short pull', () => {
|
|
36
|
+
const { wrapper, scrollEl } = mountPtr()
|
|
37
|
+
touch(scrollEl, 'touchstart', 100)
|
|
38
|
+
touch(scrollEl, 'touchmove', 130)
|
|
39
|
+
touch(scrollEl, 'touchend', 130)
|
|
40
|
+
expect(wrapper.emitted('refresh')).toBeUndefined()
|
|
41
|
+
wrapper.unmount()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('leaves an upward swipe to native scrolling', () => {
|
|
45
|
+
const { wrapper, scrollEl } = mountPtr()
|
|
46
|
+
touch(scrollEl, 'touchstart', 200)
|
|
47
|
+
const up = touch(scrollEl, 'touchmove', 150)
|
|
48
|
+
const down = touch(scrollEl, 'touchmove', 300)
|
|
49
|
+
touch(scrollEl, 'touchend', 300)
|
|
50
|
+
expect(up.defaultPrevented).toBe(false)
|
|
51
|
+
expect(down.defaultPrevented).toBe(false)
|
|
52
|
+
expect(wrapper.emitted('refresh')).toBeUndefined()
|
|
53
|
+
wrapper.unmount()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('ignores touches when the list is scrolled down', () => {
|
|
57
|
+
const { wrapper, scrollEl } = mountPtr()
|
|
58
|
+
;(scrollEl as HTMLElement).scrollTop = 50
|
|
59
|
+
Object.defineProperty(scrollEl, 'scrollTop', { value: 50, configurable: true })
|
|
60
|
+
touch(scrollEl, 'touchstart', 100)
|
|
61
|
+
const move = touch(scrollEl, 'touchmove', 250)
|
|
62
|
+
touch(scrollEl, 'touchend', 250)
|
|
63
|
+
expect(move.defaultPrevented).toBe(false)
|
|
64
|
+
expect(wrapper.emitted('refresh')).toBeUndefined()
|
|
65
|
+
wrapper.unmount()
|
|
66
|
+
})
|
|
67
|
+
})
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MRating from '../components/MRating.vue'
|
|
4
|
+
|
|
5
|
+
// Items are laid out as 32px-wide boxes (size 28 + 4) starting at x=0.
|
|
6
|
+
function mockLayout(wrapper: ReturnType<typeof mount>) {
|
|
7
|
+
const items = wrapper.findAll('[role="slider"] > span')
|
|
8
|
+
items.forEach((item, i) => {
|
|
9
|
+
const left = i * 32
|
|
10
|
+
item.element.getBoundingClientRect = () =>
|
|
11
|
+
({ left, right: left + 32, width: 32, top: 0, bottom: 32, height: 32, x: left, y: 0 }) as DOMRect
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function filledWidths(wrapper: ReturnType<typeof mount>) {
|
|
16
|
+
return wrapper.findAll('.start-0.overflow-hidden').map((el) => el.attributes('style'))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('MRating', () => {
|
|
20
|
+
it('renders the filled part of a half value', () => {
|
|
21
|
+
const wrapper = mount(MRating, { props: { modelValue: 2.5 } })
|
|
22
|
+
const widths = filledWidths(wrapper)
|
|
23
|
+
expect(widths[1]).toContain('width: 100%')
|
|
24
|
+
expect(widths[2]).toContain('width: 50%')
|
|
25
|
+
expect(widths[3]).toContain('width: 0%')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('renders arbitrary fractions exactly', () => {
|
|
29
|
+
const wrapper = mount(MRating, { props: { modelValue: 4.25, readonly: true } })
|
|
30
|
+
expect(filledWidths(wrapper)[4]).toContain('width: 25%')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('does not reset to 0 when clicking the current value again', async () => {
|
|
34
|
+
const wrapper = mount(MRating, { props: { modelValue: 3 } })
|
|
35
|
+
mockLayout(wrapper)
|
|
36
|
+
const root = wrapper.find('[role="slider"]')
|
|
37
|
+
root.element.setPointerCapture = () => {}
|
|
38
|
+
root.element.releasePointerCapture = () => {}
|
|
39
|
+
await root.trigger('pointerdown', { button: 0, clientX: 80, pointerId: 1 })
|
|
40
|
+
await root.trigger('pointerup', { pointerId: 1 })
|
|
41
|
+
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('picks a half value from the left half of an item', async () => {
|
|
45
|
+
const wrapper = mount(MRating, { props: { modelValue: 0, halfIncrements: true } })
|
|
46
|
+
mockLayout(wrapper)
|
|
47
|
+
const root = wrapper.find('[role="slider"]')
|
|
48
|
+
root.element.setPointerCapture = () => {}
|
|
49
|
+
await root.trigger('pointerdown', { button: 0, clientX: 70, pointerId: 1 })
|
|
50
|
+
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([2.5])
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('steps with the keyboard and clamps to range', async () => {
|
|
54
|
+
const wrapper = mount(MRating, { props: { modelValue: 1, halfIncrements: true } })
|
|
55
|
+
const root = wrapper.find('[role="slider"]')
|
|
56
|
+
await root.trigger('keydown', { key: 'ArrowRight' })
|
|
57
|
+
await root.trigger('keydown', { key: 'Home' })
|
|
58
|
+
await root.trigger('keydown', { key: 'End' })
|
|
59
|
+
expect(wrapper.emitted('update:modelValue')).toEqual([[1.5], [0], [5]])
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('ignores input when readonly or disabled', async () => {
|
|
63
|
+
const ro = mount(MRating, { props: { modelValue: 2, readonly: true } })
|
|
64
|
+
await ro.find('[role="img"]').trigger('keydown', { key: 'ArrowRight' })
|
|
65
|
+
expect(ro.emitted('update:modelValue')).toBeUndefined()
|
|
66
|
+
|
|
67
|
+
const dis = mount(MRating, { props: { modelValue: 2, disabled: true } })
|
|
68
|
+
expect(dis.find('[role="slider"]').attributes('tabindex')).toBeUndefined()
|
|
69
|
+
await dis.find('[role="slider"]').trigger('keydown', { key: 'ArrowRight' })
|
|
70
|
+
expect(dis.emitted('update:modelValue')).toBeUndefined()
|
|
71
|
+
})
|
|
72
|
+
})
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MTransferList from '../components/MTransferList.vue'
|
|
4
|
+
import type { TransferItem } from '../components/MTransferList.vue'
|
|
5
|
+
|
|
6
|
+
const items: TransferItem[] = [
|
|
7
|
+
{ value: 1, label: 'Ana', description: 'ana@acme.dev' },
|
|
8
|
+
{ value: 2, label: 'Luis', description: 'luis@acme.dev' },
|
|
9
|
+
{ value: 3, label: 'Marta', description: 'marta@acme.dev' },
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
function setup(modelValue: (string | number)[] = [], extra: Record<string, unknown> = {}) {
|
|
13
|
+
const w = mount(MTransferList, {
|
|
14
|
+
props: { modelValue, items, filterable: true, ...extra, 'onUpdate:modelValue': (v: (string | number)[]) => w.setProps({ modelValue: v }) },
|
|
15
|
+
attachTo: document.body,
|
|
16
|
+
})
|
|
17
|
+
return w
|
|
18
|
+
}
|
|
19
|
+
const panes = (w: ReturnType<typeof setup>) => w.findAll('section')
|
|
20
|
+
const rows = (w: ReturnType<typeof setup>, pane: number) => panes(w)[pane]!.findAll('li')
|
|
21
|
+
const btn = (w: ReturnType<typeof setup>, label: string) => w.findAll('button').find((b) => b.attributes('aria-label') === label)!
|
|
22
|
+
const lastValue = (w: ReturnType<typeof setup>) => w.emitted('update:modelValue')!.at(-1)![0]
|
|
23
|
+
|
|
24
|
+
describe('MTransferList', () => {
|
|
25
|
+
it('clicking a row checkbox checks it once (no double toggle)', async () => {
|
|
26
|
+
const w = setup()
|
|
27
|
+
await rows(w, 0)[0]!.find('input[type="checkbox"]').trigger('click')
|
|
28
|
+
expect(btn(w, 'Move selected right').attributes('disabled')).toBeUndefined()
|
|
29
|
+
await btn(w, 'Move selected right').trigger('click')
|
|
30
|
+
expect(lastValue(w)).toEqual([1])
|
|
31
|
+
w.unmount()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('clicking anywhere else on the row toggles it', async () => {
|
|
35
|
+
const w = setup()
|
|
36
|
+
await rows(w, 0)[1]!.trigger('click')
|
|
37
|
+
expect(rows(w, 0)[1]!.classes()).toContain('bg-secondary-container')
|
|
38
|
+
await rows(w, 0)[1]!.trigger('click')
|
|
39
|
+
expect(rows(w, 0)[1]!.classes()).not.toContain('bg-secondary-container')
|
|
40
|
+
w.unmount()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('select all checks every visible item and shows a count', async () => {
|
|
44
|
+
const w = setup()
|
|
45
|
+
await panes(w)[0]!.find('header input[type="checkbox"]').trigger('click')
|
|
46
|
+
expect(panes(w)[0]!.find('header').text()).toContain('3/3')
|
|
47
|
+
await btn(w, 'Move selected right').trigger('click')
|
|
48
|
+
expect(lastValue(w)).toEqual([1, 2, 3])
|
|
49
|
+
w.unmount()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('search matches the description too', async () => {
|
|
53
|
+
const w = setup()
|
|
54
|
+
await panes(w)[0]!.find('input[type="text"]').setValue('marta@')
|
|
55
|
+
expect(rows(w, 0)).toHaveLength(1)
|
|
56
|
+
expect(rows(w, 0)[0]!.text()).toContain('Marta')
|
|
57
|
+
w.unmount()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('double-click and Enter move a single item across', async () => {
|
|
61
|
+
const w = setup()
|
|
62
|
+
await rows(w, 0)[0]!.trigger('dblclick')
|
|
63
|
+
expect(lastValue(w)).toEqual([1])
|
|
64
|
+
await rows(w, 1)[0]!.trigger('keydown', { key: 'Enter' })
|
|
65
|
+
expect(lastValue(w)).toEqual([])
|
|
66
|
+
w.unmount()
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('keeps the custom empty slots', () => {
|
|
70
|
+
const w = mount(MTransferList, {
|
|
71
|
+
props: { modelValue: [], items },
|
|
72
|
+
slots: { 'target-empty': '<p class="custom-empty">Nobody yet</p>' },
|
|
73
|
+
})
|
|
74
|
+
expect(w.find('.custom-empty').text()).toBe('Nobody yet')
|
|
75
|
+
})
|
|
76
|
+
})
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { computed } from 'vue'
|
|
3
3
|
import MAvatar from './MAvatar.vue'
|
|
4
4
|
import MIcon from './MIcon.vue'
|
|
5
|
+
import { useLocale } from '../composables/useLocale'
|
|
5
6
|
|
|
6
7
|
const props = withDefaults(
|
|
7
8
|
defineProps<{
|
|
@@ -15,10 +16,14 @@ const props = withDefaults(
|
|
|
15
16
|
tail?: boolean
|
|
16
17
|
size?: 'small' | 'medium' | 'large'
|
|
17
18
|
maxWidth?: string
|
|
19
|
+
/** Shows a live indicator instead of the content: bouncing dots while the other person types, or a mic with a moving waveform while they record audio. */
|
|
20
|
+
typing?: 'text' | 'audio'
|
|
18
21
|
}>(),
|
|
19
22
|
{ side: 'left', color: 'primary', tail: true, size: 'medium', maxWidth: '320px' },
|
|
20
23
|
)
|
|
21
24
|
|
|
25
|
+
const t = useLocale()
|
|
26
|
+
|
|
22
27
|
const isRight = computed(() => props.side === 'right')
|
|
23
28
|
|
|
24
29
|
const sizeClass = computed(() => {
|
|
@@ -27,10 +32,27 @@ const sizeClass = computed(() => {
|
|
|
27
32
|
return 'text-body-medium'
|
|
28
33
|
})
|
|
29
34
|
|
|
30
|
-
const colorMap: Record<string, { bg: string; text: string; timeCls: string }> = {
|
|
31
|
-
primary: {
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
const colorMap: Record<string, { bg: string; text: string; timeCls: string; status: Record<'sent' | 'delivered' | 'read', string> }> = {
|
|
36
|
+
primary: {
|
|
37
|
+
bg: 'bg-primary', text: 'text-on-primary', timeCls: 'text-on-primary/60',
|
|
38
|
+
status: { sent: 'text-on-primary/40', delivered: 'text-on-primary/60', read: 'text-on-primary' },
|
|
39
|
+
},
|
|
40
|
+
secondary: {
|
|
41
|
+
bg: 'bg-secondary', text: 'text-on-secondary', timeCls: 'text-on-secondary/60',
|
|
42
|
+
status: { sent: 'text-on-secondary/40', delivered: 'text-on-secondary/60', read: 'text-on-secondary' },
|
|
43
|
+
},
|
|
44
|
+
tertiary: {
|
|
45
|
+
bg: 'bg-tertiary', text: 'text-on-tertiary', timeCls: 'text-on-tertiary/60',
|
|
46
|
+
status: { sent: 'text-on-tertiary/40', delivered: 'text-on-tertiary/60', read: 'text-on-tertiary' },
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Accent for the typing indicator's mic on the neutral (left) bubble; on the right
|
|
51
|
+
// bubble everything already uses the bubble's on-color.
|
|
52
|
+
const accentMap: Record<string, string> = {
|
|
53
|
+
primary: 'text-primary',
|
|
54
|
+
secondary: 'text-secondary',
|
|
55
|
+
tertiary: 'text-tertiary',
|
|
34
56
|
}
|
|
35
57
|
|
|
36
58
|
const bubbleClasses = computed(() => {
|
|
@@ -57,12 +79,12 @@ const statusIcon = computed(() => {
|
|
|
57
79
|
return props.status === 'sent' ? 'check' : 'done_all'
|
|
58
80
|
})
|
|
59
81
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
82
|
+
// Was hardcoded to on-primary, so the checks didn't match a secondary/tertiary bubble.
|
|
83
|
+
const statusClasses = computed(() => (props.status ? colorMap[props.color]!.status[props.status] : ''))
|
|
84
|
+
|
|
85
|
+
const micClass = computed(() => (isRight.value ? '' : accentMap[props.color]))
|
|
86
|
+
|
|
87
|
+
const typingLabel = computed(() => (props.typing === 'audio' ? t.chatRecordingAudio : t.chatTyping))
|
|
66
88
|
</script>
|
|
67
89
|
|
|
68
90
|
<template>
|
|
@@ -80,18 +102,83 @@ const statusClasses = computed(() => {
|
|
|
80
102
|
</p>
|
|
81
103
|
|
|
82
104
|
<div :class="bubbleClasses">
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
105
|
+
<!-- Typing / recording indicator -->
|
|
106
|
+
<div
|
|
107
|
+
v-if="typing"
|
|
108
|
+
role="status"
|
|
109
|
+
:aria-label="sender ? `${sender}: ${typingLabel}` : typingLabel"
|
|
110
|
+
class="flex h-5 items-center"
|
|
111
|
+
:class="typing === 'audio' ? 'gap-2' : 'gap-1 px-1'"
|
|
112
|
+
>
|
|
113
|
+
<template v-if="typing === 'text'">
|
|
114
|
+
<span v-for="i in 3" :key="i" class="m3-typing-dot h-2 w-2 rounded-full bg-current opacity-60" :style="{ animationDelay: `${(i - 1) * 160}ms` }" />
|
|
115
|
+
</template>
|
|
116
|
+
<template v-else>
|
|
117
|
+
<MIcon name="mic" :size="18" class="m3-typing-mic" :class="micClass" style="font-variation-settings: 'FILL' 1" />
|
|
118
|
+
<span class="flex h-4 items-center gap-[3px]" aria-hidden="true">
|
|
119
|
+
<span
|
|
120
|
+
v-for="i in 7"
|
|
121
|
+
:key="i"
|
|
122
|
+
class="m3-typing-bar h-full w-[3px] rounded-full bg-current opacity-70"
|
|
123
|
+
:style="{ animationDelay: `${[0, 320, 120, 480, 220, 400, 60][i - 1]}ms` }"
|
|
124
|
+
/>
|
|
125
|
+
</span>
|
|
126
|
+
</template>
|
|
93
127
|
</div>
|
|
128
|
+
|
|
129
|
+
<template v-else>
|
|
130
|
+
<!-- div, not p: the slot often holds block content (images, buttons, cards) -->
|
|
131
|
+
<div :class="sizeClass"><slot>{{ text }}</slot></div>
|
|
132
|
+
|
|
133
|
+
<div v-if="time || (status && isRight)" class="flex items-center justify-end gap-1 mt-0.5">
|
|
134
|
+
<span v-if="time" class="text-label-small" :class="timeClasses">{{ time }}</span>
|
|
135
|
+
<MIcon
|
|
136
|
+
v-if="status && isRight"
|
|
137
|
+
:name="statusIcon!"
|
|
138
|
+
:size="14"
|
|
139
|
+
:class="statusClasses"
|
|
140
|
+
/>
|
|
141
|
+
</div>
|
|
142
|
+
</template>
|
|
94
143
|
</div>
|
|
95
144
|
</div>
|
|
96
145
|
</div>
|
|
97
146
|
</template>
|
|
147
|
+
|
|
148
|
+
<style scoped>
|
|
149
|
+
.m3-typing-dot {
|
|
150
|
+
animation: m3-typing-dot 1.2s ease-in-out infinite;
|
|
151
|
+
}
|
|
152
|
+
@keyframes m3-typing-dot {
|
|
153
|
+
0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
|
|
154
|
+
30% { transform: translateY(-4px); opacity: 1; }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.m3-typing-mic {
|
|
158
|
+
animation: m3-typing-mic 1.4s ease-in-out infinite;
|
|
159
|
+
}
|
|
160
|
+
@keyframes m3-typing-mic {
|
|
161
|
+
0%, 100% { opacity: 1; transform: scale(1); }
|
|
162
|
+
50% { opacity: 0.55; transform: scale(0.9); }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.m3-typing-bar {
|
|
166
|
+
transform-origin: center;
|
|
167
|
+
animation: m3-typing-bar 0.9s ease-in-out infinite;
|
|
168
|
+
}
|
|
169
|
+
@keyframes m3-typing-bar {
|
|
170
|
+
0%, 100% { transform: scaleY(0.25); }
|
|
171
|
+
50% { transform: scaleY(1); }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@media (prefers-reduced-motion: reduce) {
|
|
175
|
+
.m3-typing-dot,
|
|
176
|
+
.m3-typing-mic,
|
|
177
|
+
.m3-typing-bar {
|
|
178
|
+
animation: none;
|
|
179
|
+
}
|
|
180
|
+
.m3-typing-bar {
|
|
181
|
+
transform: scaleY(0.6);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
</style>
|
|
@@ -8,6 +8,8 @@ withDefaults(
|
|
|
8
8
|
disabled?: boolean;
|
|
9
9
|
label?: string;
|
|
10
10
|
color?: "primary" | "secondary" | "tertiary" | "error";
|
|
11
|
+
/** Accessible name for the input when there's no visible label (e.g. a list row's checkbox). */
|
|
12
|
+
ariaLabel?: string;
|
|
11
13
|
}>(),
|
|
12
14
|
{ indeterminate: false, disabled: false, color: "primary" },
|
|
13
15
|
);
|
|
@@ -60,6 +62,7 @@ const checkedBgClasses: Record<string, string> = {
|
|
|
60
62
|
class="peer sr-only"
|
|
61
63
|
:checked="modelValue"
|
|
62
64
|
:disabled="disabled"
|
|
65
|
+
:aria-label="ariaLabel"
|
|
63
66
|
@change="emit('update:modelValue', !modelValue)"
|
|
64
67
|
/>
|
|
65
68
|
<!--
|
|
@@ -177,6 +177,12 @@ function openTrajectory() {
|
|
|
177
177
|
// frame) have to live outside this function to survive that interruption.
|
|
178
178
|
let currentIdx = 0
|
|
179
179
|
let cancelActive: (() => void) | null = null
|
|
180
|
+
// Set only while a close is playing: stops the loop *and* calls its `done()`.
|
|
181
|
+
// Used on unmount — a menu item that navigates away (e.g. "Log out" ->
|
|
182
|
+
// router.push) unmounts this component mid-close, and Vue only removes the
|
|
183
|
+
// Teleported panel from <body> inside the leave's `done()`, so merely
|
|
184
|
+
// cancelling the loop there left the half-closed panel stranded on screen.
|
|
185
|
+
let finishLeave: (() => void) | null = null
|
|
180
186
|
|
|
181
187
|
function playTrajectory(el: Element, done: () => void, opening: boolean) {
|
|
182
188
|
cancelActive?.()
|
|
@@ -203,6 +209,7 @@ function playTrajectory(el: Element, done: () => void, opening: boolean) {
|
|
|
203
209
|
apply(currentIdx)
|
|
204
210
|
if ((opening && currentIdx >= target) || (!opening && currentIdx <= target)) {
|
|
205
211
|
cancelActive = null
|
|
212
|
+
finishLeave = null
|
|
206
213
|
done()
|
|
207
214
|
return
|
|
208
215
|
}
|
|
@@ -210,6 +217,7 @@ function playTrajectory(el: Element, done: () => void, opening: boolean) {
|
|
|
210
217
|
}
|
|
211
218
|
|
|
212
219
|
cancelActive = () => { cancelled = true; cancelAnimationFrame(rafId) }
|
|
220
|
+
finishLeave = opening ? null : () => { cancelActive?.(); cancelActive = null; finishLeave = null; done() }
|
|
213
221
|
apply(currentIdx)
|
|
214
222
|
rafId = requestAnimationFrame(step)
|
|
215
223
|
}
|
|
@@ -323,7 +331,8 @@ onUnmounted(() => {
|
|
|
323
331
|
document.removeEventListener('mousedown', onDocMouseDown)
|
|
324
332
|
document.removeEventListener('keydown', onKeydown)
|
|
325
333
|
window.removeEventListener('scroll', onScroll, true)
|
|
326
|
-
|
|
334
|
+
if (finishLeave) finishLeave()
|
|
335
|
+
else cancelActive?.()
|
|
327
336
|
})
|
|
328
337
|
</script>
|
|
329
338
|
|