@m3ui-vue/m3ui-vue 1.1.4 → 1.2.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/dist/API.md +511 -34
- package/dist/MMenuItem-DI351kIf.js +929 -0
- package/dist/MMenuItem-DI351kIf.js.map +1 -0
- package/dist/{MSlider-JflHJ70q.js → MSlider-BnEy5ieZ.js} +295 -320
- package/dist/MSlider-BnEy5ieZ.js.map +1 -0
- package/dist/MTextField-BBmkaIbO.js +633 -0
- package/dist/MTextField-BBmkaIbO.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +83 -49
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MButton.vue.d.ts +7 -1
- package/dist/components/MButtonGroup.vue.d.ts +40 -31
- package/dist/components/MCarousel.vue.d.ts +2 -0
- package/dist/components/MChart.vue.d.ts +6 -0
- package/dist/components/MCircleProgressBar.vue.d.ts +5 -3
- package/dist/components/MContextMenu.vue.d.ts +2 -2
- package/dist/components/MCopyButton.vue.d.ts +1 -1
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +1 -1
- package/dist/components/MIconButton.vue.d.ts +13 -1
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MMap.vue.d.ts +20 -2
- package/dist/components/MMapBaseLayers.vue.d.ts +3 -0
- package/dist/components/MMapFilter.vue.d.ts +3 -0
- package/dist/components/MMapLayers.vue.d.ts +3 -0
- package/dist/components/MMenu.vue.d.ts +2 -2
- package/dist/components/MMenuItem.vue.d.ts +7 -3
- package/dist/components/MNavigationDrawer.vue.d.ts +13 -2
- package/dist/components/MOverlay.vue.d.ts +12 -1
- package/dist/components/MProgressBar.vue.d.ts +5 -3
- package/dist/components/MPullToRefresh.vue.d.ts +7 -2
- package/dist/components/MRichTextEditor.vue.d.ts +7 -1
- package/dist/components/MSearchField.vue.d.ts +58 -0
- package/dist/components/MSegmentedButton.vue.d.ts +31 -23
- package/dist/components/MSimpleCarousel.vue.d.ts +2 -0
- package/dist/components/MSkeleton.vue.d.ts +6 -3
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTextField.vue.d.ts +5 -1
- package/dist/components/MTimeline.vue.d.ts +85 -22
- package/dist/components/MTooltip.vue.d.ts +1 -1
- package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
- package/dist/composables/_mapStyle.d.ts +13 -0
- package/dist/composables/_themeTransition.d.ts +2 -0
- package/dist/composables/_tooltipTrigger.d.ts +22 -0
- package/dist/composables/_useMenuNav.d.ts +28 -0
- package/dist/composables/useAutoGrow.d.ts +21 -0
- package/dist/composables/useColorPalette.d.ts +1 -1
- package/dist/composables/useLocale.d.ts +3 -0
- package/dist/composables/useMap.d.ts +19 -3
- package/dist/composables/useMapFilter.d.ts +4 -1
- package/dist/composables/useMapLayers.d.ts +5 -2
- package/dist/composables/useScrollReveal.d.ts +44 -0
- package/dist/composables/useThemeTokens.d.ts +21 -0
- package/dist/composables/viewportHints.d.ts +27 -0
- package/dist/directives/vClickOutside.d.ts +25 -0
- package/dist/directives/vFocusRing.d.ts +22 -0
- package/dist/directives/vLongPress.d.ts +27 -0
- package/dist/directives/vReveal.d.ts +10 -0
- package/dist/directives/vScrollElevation.d.ts +31 -0
- package/dist/directives/vSkeleton.d.ts +19 -0
- package/dist/directives/vStateLayer.d.ts +20 -0
- package/dist/directives/vSwipe.d.ts +45 -0
- package/dist/directives/vTooltip.d.ts +23 -0
- package/dist/index.d.ts +28 -1
- package/dist/locales/index.js +21 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7131 -6216
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +1 -1
- package/dist/map.js +821 -791
- package/dist/map.js.map +1 -1
- package/dist/motion-DZiXG09o.js +150 -0
- package/dist/motion-DZiXG09o.js.map +1 -0
- package/dist/plugin.d.ts +24 -0
- package/dist/rich-text-editor.js +13 -9
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles/theme.css +63 -0
- package/dist/styles.css +1 -1
- package/dist/{useLocale-CXibICQA.js → useLocale-JYxDDeXC.js} +4 -2
- package/dist/useLocale-JYxDDeXC.js.map +1 -0
- package/dist/useThemeTokens-Bv-Uv8eX.js +135 -0
- package/dist/useThemeTokens-Bv-Uv8eX.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MButton.test.ts +22 -0
- package/src/__tests__/MCarousel.test.ts +9 -0
- package/src/__tests__/MChart.test.ts +77 -5
- package/src/__tests__/MIconButton.test.ts +33 -0
- package/src/__tests__/MMap.test.ts +53 -1
- package/src/__tests__/MMapLayers.test.ts +46 -2
- package/src/__tests__/MMenu.test.ts +104 -1
- package/src/__tests__/MMenuItem.test.ts +18 -0
- package/src/__tests__/MNavigationDrawer.test.ts +80 -0
- package/src/__tests__/MOverlay.test.ts +49 -0
- package/src/__tests__/MProgressBar.test.ts +41 -0
- package/src/__tests__/MPullToRefresh.test.ts +33 -0
- package/src/__tests__/MRichTextEditor.test.ts +22 -0
- package/src/__tests__/MSearchField.test.ts +71 -0
- package/src/__tests__/MSkeleton.test.ts +38 -0
- package/src/__tests__/MTimeline.test.ts +238 -0
- package/src/__tests__/_fakeMaplibre.ts +3 -1
- package/src/__tests__/attrsFallthrough.test.ts +3 -0
- package/src/__tests__/escapeStack.test.ts +93 -0
- package/src/__tests__/ssr.test.ts +21 -2
- package/src/__tests__/useAutoGrow.test.ts +103 -0
- package/src/__tests__/useScrollReveal.test.ts +102 -0
- package/src/__tests__/useThemeTokens.test.ts +114 -0
- package/src/__tests__/vClickOutside.test.ts +82 -0
- package/src/__tests__/vFocusRing.test.ts +36 -0
- package/src/__tests__/vLongPress.test.ts +81 -0
- package/src/__tests__/vScrollElevation.test.ts +89 -0
- package/src/__tests__/vSkeleton.test.ts +48 -0
- package/src/__tests__/vStateLayer.test.ts +53 -0
- package/src/__tests__/vSwipe.test.ts +93 -0
- package/src/__tests__/vTooltip.test.ts +95 -0
- package/src/__tests__/viewportHints.test.ts +41 -0
- package/src/components/MAutocomplete.vue +5 -0
- package/src/components/MBottomSheet.vue +4 -1
- package/src/components/MButton.vue +15 -1
- package/src/components/MButtonGroup.vue +22 -17
- package/src/components/MCarousel.vue +7 -1
- package/src/components/MChart.vue +74 -34
- package/src/components/MCircleProgressBar.vue +14 -9
- package/src/components/MCommandPalette.vue +3 -2
- package/src/components/MContextMenu.vue +19 -60
- package/src/components/MDragDropList.vue +2 -0
- package/src/components/MIconButton.vue +40 -1
- package/src/components/MKanban.vue +2 -0
- package/src/components/MLightbox.vue +7 -2
- package/src/components/MMap.vue +38 -5
- package/src/components/MMapBaseLayers.vue +7 -3
- package/src/components/MMapFilter.vue +7 -4
- package/src/components/MMapGeoJson.vue +1 -1
- package/src/components/MMapLayers.vue +6 -2
- package/src/components/MMapMeasure.vue +5 -2
- package/src/components/MMenu.vue +18 -59
- package/src/components/MMenuItem.vue +11 -2
- package/src/components/MMultiAutocomplete.vue +5 -0
- package/src/components/MNavigationDrawer.vue +96 -11
- package/src/components/MNavigationRail.vue +4 -15
- package/src/components/MOverlay.vue +32 -13
- package/src/components/MProgressBar.vue +25 -27
- package/src/components/MPullToRefresh.vue +20 -1
- package/src/components/MRichTextEditor.vue +19 -5
- package/src/components/MSearchBar.vue +5 -0
- package/src/components/MSearchField.vue +142 -0
- package/src/components/MSegmentedButton.vue +19 -17
- package/src/components/MSelect.vue +10 -1
- package/src/components/MSideSheet.vue +5 -2
- package/src/components/MSimpleCarousel.vue +10 -1
- package/src/components/MSkeleton.vue +30 -8
- package/src/components/MSpotlightSearch.vue +3 -2
- package/src/components/MTextField.vue +15 -2
- package/src/components/MTimeline.vue +370 -81
- package/src/components/MTooltip.vue +20 -152
- package/src/components/_MDrawerItemList.vue +25 -6
- package/src/composables/_mapStyle.ts +45 -0
- package/src/composables/_themeTransition.ts +2 -0
- package/src/composables/_tooltipTrigger.ts +184 -0
- package/src/composables/_useMenuNav.ts +209 -0
- package/src/composables/useAutoGrow.ts +78 -0
- package/src/composables/useLocale.ts +5 -0
- package/src/composables/useMap.ts +43 -5
- package/src/composables/useMapFilter.ts +6 -5
- package/src/composables/useMapLayers.ts +7 -6
- package/src/composables/useScrollReveal.ts +151 -0
- package/src/composables/useThemeTokens.ts +116 -0
- package/src/composables/viewportHints.ts +80 -0
- package/src/directives/vClickOutside.ts +90 -0
- package/src/directives/vFocusRing.ts +60 -0
- package/src/directives/vLongPress.ts +134 -0
- package/src/directives/vReveal.ts +57 -0
- package/src/directives/vScrollElevation.ts +116 -0
- package/src/directives/vSkeleton.ts +87 -0
- package/src/directives/vStateLayer.ts +83 -0
- package/src/directives/vSwipe.ts +197 -0
- package/src/directives/vTooltip.ts +128 -0
- package/src/index.ts +28 -1
- package/src/locales/de.ts +2 -0
- package/src/locales/es.ts +2 -0
- package/src/locales/fr.ts +2 -0
- package/src/locales/ja.ts +2 -0
- package/src/locales/ko.ts +2 -0
- package/src/locales/pt.ts +2 -0
- package/src/locales/zh.ts +2 -0
- package/src/map.ts +1 -1
- package/src/plugin.ts +34 -0
- package/src/styles/theme.css +63 -0
- package/dist/MMenuItem-BfjqwcYP.js +0 -830
- package/dist/MMenuItem-BfjqwcYP.js.map +0 -1
- package/dist/MSlider-JflHJ70q.js.map +0 -1
- package/dist/MTextField-NaIB6RbM.js +0 -673
- package/dist/MTextField-NaIB6RbM.js.map +0 -1
- package/dist/composables/_useThemeTokens.d.ts +0 -7
- package/dist/useLocale-CXibICQA.js.map +0 -1
- package/src/composables/_useThemeTokens.ts +0 -42
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { h } from 'vue'
|
|
4
|
+
import MTimeline from '../components/MTimeline.vue'
|
|
5
|
+
|
|
6
|
+
const items = [
|
|
7
|
+
{ title: 'Ordered', date: 'Mon', color: 'secondary' as const },
|
|
8
|
+
{ title: 'Shipped', date: 'Tue', color: 'tertiary' as const, description: 'On its way' },
|
|
9
|
+
{ title: 'Delivered', date: 'Wed', color: 'success' as const },
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
describe('MTimeline', () => {
|
|
13
|
+
it('is an ordered list of entries', () => {
|
|
14
|
+
const w = mount(MTimeline, { props: { items } })
|
|
15
|
+
expect(w.element.tagName).toBe('OL')
|
|
16
|
+
expect(w.findAll('li')).toHaveLength(3)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('draws each line in its entry color as a literal class (secondary, tertiary… were invisible)', () => {
|
|
20
|
+
const html = mount(MTimeline, { props: { items } }).html()
|
|
21
|
+
expect(html).toContain('bg-secondary/30')
|
|
22
|
+
expect(html).toContain('bg-tertiary/30')
|
|
23
|
+
expect(html).not.toContain('bg-success/30') // the last entry has no line
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('#item gets each entry, and item-{index} still wins for its own entry', () => {
|
|
27
|
+
const w = mount(MTimeline, {
|
|
28
|
+
props: { items },
|
|
29
|
+
slots: {
|
|
30
|
+
item: ({ item, index }: any) => h('i', { class: 'generic' }, `${index}:${item.title}`),
|
|
31
|
+
'item-1': () => h('b', { class: 'specific' }, 'only shipped'),
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
expect(w.findAll('.generic').map((e) => e.text())).toEqual(['0:Ordered', '2:Delivered'])
|
|
35
|
+
expect(w.find('li:nth-child(2) .specific').exists()).toBe(true)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('#title, #dot and #opposite replace or add their parts', () => {
|
|
39
|
+
const w = mount(MTimeline, {
|
|
40
|
+
props: { items },
|
|
41
|
+
slots: {
|
|
42
|
+
title: ({ item }: any) => h('h4', item.title.toUpperCase()),
|
|
43
|
+
dot: () => h('span', { class: 'my-dot' }),
|
|
44
|
+
opposite: ({ item }: any) => h('time', item.date),
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
expect(w.findAll('h4').map((e) => e.text())).toEqual(['ORDERED', 'SHIPPED', 'DELIVERED'])
|
|
48
|
+
expect(w.findAll('.my-dot')).toHaveLength(3)
|
|
49
|
+
expect(w.findAll('time').map((e) => e.text())).toEqual(['Mon', 'Tue', 'Wed'])
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('bare leaves the content to #item', () => {
|
|
53
|
+
const w = mount(MTimeline, { props: { items, bare: true }, slots: { item: ({ item }: any) => h('div', { class: 'card' }, item.title) } })
|
|
54
|
+
expect(w.findAll('.card')).toHaveLength(3)
|
|
55
|
+
expect(w.text()).not.toContain('On its way')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('alternating takes the slots too, with #opposite on the empty side', () => {
|
|
59
|
+
const w = mount(MTimeline, {
|
|
60
|
+
props: { items, alternating: true },
|
|
61
|
+
slots: { item: () => h('i', { class: 'extra' }), opposite: ({ item }: any) => h('time', item.date) },
|
|
62
|
+
})
|
|
63
|
+
expect(w.findAll('.extra')).toHaveLength(3)
|
|
64
|
+
expect(w.findAll('time')).toHaveLength(3)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('lays entries side by side when horizontal', () => {
|
|
68
|
+
const w = mount(MTimeline, { props: { items, orientation: 'horizontal' } })
|
|
69
|
+
expect(w.classes()).toContain('overflow-x-auto')
|
|
70
|
+
expect(w.findAll('li')).toHaveLength(3)
|
|
71
|
+
expect(w.html()).toContain('bg-tertiary/30')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('keys entries by their key when given', async () => {
|
|
75
|
+
const w = mount(MTimeline, { props: { items: [{ key: 'a', title: 'A' }, { key: 'b', title: 'B' }] } })
|
|
76
|
+
const second = w.findAll('li')[1]!.element
|
|
77
|
+
await w.setProps({ items: [{ key: 'z', title: 'Z' }, { key: 'a', title: 'A' }, { key: 'b', title: 'B' }] })
|
|
78
|
+
expect(w.findAll('li')[2]!.element).toBe(second)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
describe('progress', () => {
|
|
82
|
+
const steps = [
|
|
83
|
+
{ title: 'Ordered', icon: 'receipt' },
|
|
84
|
+
{ title: 'Preparing', icon: 'skillet' },
|
|
85
|
+
{ title: 'On the way', icon: 'two_wheeler' },
|
|
86
|
+
{ title: 'Delivered', icon: 'home' },
|
|
87
|
+
]
|
|
88
|
+
const parts = (layout: Record<string, unknown> = {}) => {
|
|
89
|
+
const w = mount(MTimeline, { props: { items: steps, current: 1, ...layout } })
|
|
90
|
+
const lis = w.findAll('li')
|
|
91
|
+
return {
|
|
92
|
+
lis,
|
|
93
|
+
dot: (i: number) => lis[i]!.find('.rounded-full'),
|
|
94
|
+
line: (i: number) => lis[i]!.findAll('span').filter((s) => s.classes().includes('flex-1')).at(-1)!,
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
it('fills done steps with a solid line, pulses the current one, outlines the rest', () => {
|
|
99
|
+
const { lis, dot, line } = parts()
|
|
100
|
+
expect(dot(0).classes()).toContain('bg-primary')
|
|
101
|
+
expect(line(0).classes()).toContain('bg-primary')
|
|
102
|
+
expect(line(0).classes()).not.toContain('bg-primary/30')
|
|
103
|
+
expect(lis[1]!.attributes('aria-current')).toBe('step')
|
|
104
|
+
expect(lis[1]!.find('.motion-safe\\:animate-ping').exists()).toBe(true)
|
|
105
|
+
expect(line(1).classes()).toContain('border-dashed')
|
|
106
|
+
expect(dot(2).classes()).toContain('border-outline-variant')
|
|
107
|
+
expect(dot(2).classes()).not.toContain('bg-primary')
|
|
108
|
+
expect(lis[2]!.find('p').classes()).toContain('text-on-surface-variant')
|
|
109
|
+
expect(lis[0]!.attributes('aria-current')).toBeUndefined()
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('lets an item\'s status win, and works in every layout', () => {
|
|
113
|
+
const w = mount(MTimeline, { props: { items: [steps[0]!, { ...steps[1]!, status: 'pending' as const }], current: 2 } })
|
|
114
|
+
expect(w.findAll('li')[1]!.find('.rounded-full').classes()).toContain('border-outline-variant')
|
|
115
|
+
for (const layout of [{ alternating: true }, { orientation: 'horizontal' }]) {
|
|
116
|
+
const { lis, line } = parts(layout)
|
|
117
|
+
expect(lis[1]!.attributes('aria-current')).toBe('step')
|
|
118
|
+
expect(line(1).classes()).toContain('border-dashed')
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('keeps the plain look without current or status', () => {
|
|
123
|
+
const html = mount(MTimeline, { props: { items: steps } }).html()
|
|
124
|
+
expect(html).not.toContain('border-dashed')
|
|
125
|
+
expect(html).not.toContain('aria-current')
|
|
126
|
+
expect(html).toContain('bg-primary/30')
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('folds the alternating layout into a column on a narrow container, unless responsive is off', () => {
|
|
131
|
+
const w = mount(MTimeline, { props: { items, alternating: true } })
|
|
132
|
+
expect(w.classes()).toContain('@container')
|
|
133
|
+
const li = w.findAll('li')[1]!
|
|
134
|
+
// Narrow: a grid, line first; from @lg on, the row alternates as before
|
|
135
|
+
expect(li.classes()).toEqual(expect.arrayContaining(['grid', '@lg:flex', '@lg:flex-row-reverse']))
|
|
136
|
+
const [content, , opposite] = li.element.children
|
|
137
|
+
expect(content!.className).toContain('col-start-2 row-start-1')
|
|
138
|
+
expect(opposite!.className).toContain('row-start-2')
|
|
139
|
+
|
|
140
|
+
const fixed = mount(MTimeline, { props: { items, alternating: true, responsive: false } })
|
|
141
|
+
expect(fixed.classes()).not.toContain('@container')
|
|
142
|
+
expect(fixed.findAll('li')[1]!.classes()).toEqual(expect.arrayContaining(['flex', 'flex-row-reverse']))
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
describe('groups', () => {
|
|
146
|
+
const days = [
|
|
147
|
+
{ title: 'Coffee', group: 'Today' },
|
|
148
|
+
{ title: 'Gym', group: 'Today' },
|
|
149
|
+
{ title: 'Dinner', group: 'Yesterday' },
|
|
150
|
+
{ title: 'Cinema', group: 'Yesterday' },
|
|
151
|
+
]
|
|
152
|
+
const lineOf = (li: ReturnType<ReturnType<typeof mount>['find']>) =>
|
|
153
|
+
li.findAll('span').filter((s) => s.classes().includes('flex-1') && !s.classes().includes('min-w-0'))
|
|
154
|
+
|
|
155
|
+
it('puts a header before each run, and ends the line with it', () => {
|
|
156
|
+
const w = mount(MTimeline, { props: { items: days } })
|
|
157
|
+
const lis = w.findAll('li')
|
|
158
|
+
expect(lis.map((l) => l.text())).toEqual(['Today', 'Coffee', 'Gym', 'Yesterday', 'Dinner', 'Cinema'])
|
|
159
|
+
expect(lineOf(lis[1]!)).toHaveLength(1) // Coffee → Gym
|
|
160
|
+
expect(lineOf(lis[2]!)).toHaveLength(0) // Gym ends Today
|
|
161
|
+
expect(lineOf(lis[4]!)).toHaveLength(1)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('takes a #group slot with the run, in the alternating and horizontal layouts too', () => {
|
|
165
|
+
for (const layout of [{}, { alternating: true }, { orientation: 'horizontal' }]) {
|
|
166
|
+
const w = mount(MTimeline, {
|
|
167
|
+
props: { items: days, ...layout },
|
|
168
|
+
slots: { group: ({ group, items }: { group: string, items: unknown[] }) => h('b', `${group} (${items.length})`) },
|
|
169
|
+
})
|
|
170
|
+
expect(w.findAll('b').map((b) => b.text())).toEqual(['Today (2)', 'Yesterday (2)'])
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
describe('MTimeline animate', () => {
|
|
177
|
+
const at = (top: number) => ({ top, left: 0, width: 100, height: 40, right: 100, bottom: top + 40, x: 0, y: top, toJSON() {} }) as DOMRect
|
|
178
|
+
// happy-dom has no layout: each row reports its place from its position among its siblings when asked
|
|
179
|
+
function layout(el: Element) {
|
|
180
|
+
el.querySelectorAll<HTMLElement>('[data-timeline-row]').forEach((row) => {
|
|
181
|
+
row.getBoundingClientRect = () => at(Array.from(row.parentElement!.children).indexOf(row) * 40)
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
const running = (el: Element) => el.getAnimations().filter((a) => a.playState === 'running').length
|
|
185
|
+
|
|
186
|
+
it('slides new entries in and springs the others to their new places', async () => {
|
|
187
|
+
const items = [{ key: 'b', title: 'B' }, { key: 'c', title: 'C' }]
|
|
188
|
+
const w = mount(MTimeline, { props: { items }, attachTo: document.body })
|
|
189
|
+
layout(w.element)
|
|
190
|
+
await w.setProps({ items: [{ key: 'a', title: 'A' }, ...items] })
|
|
191
|
+
const rows = () => w.findAll('[data-timeline-row]').map((r) => r.element as HTMLElement)
|
|
192
|
+
expect(rows().map((r) => r.dataset.timelineRow)).toEqual(['a', 'b', 'c'])
|
|
193
|
+
expect(running(rows()[0]!)).toBe(1) // entered
|
|
194
|
+
expect(running(rows()[1]!)).toBe(1) // moved down a row
|
|
195
|
+
expect(running(rows()[2]!)).toBe(1)
|
|
196
|
+
w.unmount()
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
it('does nothing with animate off, nor on the first render', async () => {
|
|
200
|
+
const items = [{ key: 'b', title: 'B' }]
|
|
201
|
+
const w = mount(MTimeline, { props: { items, animate: false }, attachTo: document.body })
|
|
202
|
+
expect(w.element.getAnimations?.().length ?? 0).toBe(0)
|
|
203
|
+
await w.setProps({ items: [{ key: 'a', title: 'A' }, ...items] })
|
|
204
|
+
expect(running(w.find('[data-timeline-row="a"]').element)).toBe(0)
|
|
205
|
+
w.unmount()
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
describe('MTimeline limit', () => {
|
|
210
|
+
const many = Array.from({ length: 7 }, (_, i) => ({ key: i, title: `Entry ${i}` }))
|
|
211
|
+
|
|
212
|
+
it('shows the first entries and a button for the rest, toggling both ways', async () => {
|
|
213
|
+
const w = mount(MTimeline, { props: { items: many, limit: 3, animate: false } })
|
|
214
|
+
const entries = () => w.findAll('li').filter((li) => li.text().startsWith('Entry'))
|
|
215
|
+
expect(entries()).toHaveLength(3)
|
|
216
|
+
const button = () => w.find('button[aria-expanded]')
|
|
217
|
+
expect(button().text()).toContain('Show 4 more')
|
|
218
|
+
expect(button().attributes('aria-expanded')).toBe('false')
|
|
219
|
+
await button().trigger('click')
|
|
220
|
+
expect(entries()).toHaveLength(7)
|
|
221
|
+
expect(button().text()).toContain('Show less')
|
|
222
|
+
expect(w.emitted('update:expanded')).toEqual([[true]])
|
|
223
|
+
await button().trigger('click')
|
|
224
|
+
expect(entries()).toHaveLength(3)
|
|
225
|
+
expect(w.emitted('update:expanded')).toEqual([[true], [false]])
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it('ends the line at the last entry shown, follows v-model:expanded, and has no button when everything fits', async () => {
|
|
229
|
+
const w = mount(MTimeline, { props: { items: many, limit: 3, expanded: true, animate: false } })
|
|
230
|
+
expect(w.findAll('li').filter((li) => li.text().startsWith('Entry'))).toHaveLength(7)
|
|
231
|
+
await w.setProps({ expanded: false })
|
|
232
|
+
const third = w.findAll('li')[2]!
|
|
233
|
+
expect(third.findAll('span').filter((s) => s.classes().includes('flex-1'))).toHaveLength(0)
|
|
234
|
+
|
|
235
|
+
const fits = mount(MTimeline, { props: { items: many.slice(0, 3), limit: 3 } })
|
|
236
|
+
expect(fits.find('button').exists()).toBe(false)
|
|
237
|
+
})
|
|
238
|
+
})
|
|
@@ -56,8 +56,10 @@ export class FakeMap extends Evented {
|
|
|
56
56
|
}
|
|
57
57
|
removeControl(control: unknown) { this.controls = this.controls.filter((c) => c.control !== control); return this }
|
|
58
58
|
hasControl(control: unknown) { return this.controls.some((c) => c.control === control) }
|
|
59
|
-
|
|
59
|
+
styleOptions: { transformStyle?: (previous: unknown, next: unknown) => unknown }[] = []
|
|
60
|
+
setStyle(style: unknown, options: FakeMap['styleOptions'][number] = {}) {
|
|
60
61
|
this.styles.push(style)
|
|
62
|
+
this.styleOptions.push(options)
|
|
61
63
|
this.sources.clear()
|
|
62
64
|
this.layers = []
|
|
63
65
|
}
|
|
@@ -17,6 +17,7 @@ import MTabs from '../components/MTabs.vue'
|
|
|
17
17
|
import MTransferList from '../components/MTransferList.vue'
|
|
18
18
|
import MContainerTransform from '../components/MContainerTransform.vue'
|
|
19
19
|
import MDialog from '../components/MDialog.vue'
|
|
20
|
+
import MOverlay from '../components/MOverlay.vue'
|
|
20
21
|
|
|
21
22
|
// These components render more than one root node (an element plus a Teleport, a v-if/v-show
|
|
22
23
|
// pair, a comment before the root...), which makes Vue drop a consumer's class/attrs silently.
|
|
@@ -47,6 +48,8 @@ const cases: [name: string, component: Component, props: Record<string, unknown>
|
|
|
47
48
|
// A Teleport root: the attrs go on the dialog's surface
|
|
48
49
|
['MDialog', MDialog, { modelValue: true, title: 'T' }, 'DIV'],
|
|
49
50
|
['MDialog (fullscreen)', MDialog, { modelValue: true, title: 'T', fullscreen: true }, 'DIV'],
|
|
51
|
+
// A Teleport root: the attrs go on the content layer, over the scrim
|
|
52
|
+
['MOverlay', MOverlay, { modelValue: true }, 'DIV'],
|
|
50
53
|
]
|
|
51
54
|
|
|
52
55
|
describe('consumer attrs reach multi-root components', () => {
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, type Component } from 'vue'
|
|
4
|
+
import MDialog from '../components/MDialog.vue'
|
|
5
|
+
import MSelect from '../components/MSelect.vue'
|
|
6
|
+
import MAutocomplete from '../components/MAutocomplete.vue'
|
|
7
|
+
import MSearchBar from '../components/MSearchBar.vue'
|
|
8
|
+
import MBottomSheet from '../components/MBottomSheet.vue'
|
|
9
|
+
import MSideSheet from '../components/MSideSheet.vue'
|
|
10
|
+
import MCommandPalette from '../components/MCommandPalette.vue'
|
|
11
|
+
import MSpotlightSearch from '../components/MSpotlightSearch.vue'
|
|
12
|
+
import MNavigationRail from '../components/MNavigationRail.vue'
|
|
13
|
+
|
|
14
|
+
// Every case: the component sits in (or opens over) an open MDialog. One Escape closes the component alone; the
|
|
15
|
+
// next one closes the dialog. Before, both went at once (each component listened to Escape on its own, outside the
|
|
16
|
+
// library's escape stack MDialog uses).
|
|
17
|
+
|
|
18
|
+
let wrappers: VueWrapper[] = []
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
wrappers.forEach((w) => w.unmount())
|
|
21
|
+
wrappers = []
|
|
22
|
+
document.body.innerHTML = ''
|
|
23
|
+
document.body.style.overflow = ''
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
function inDialog(child: () => unknown) {
|
|
27
|
+
const w = mount(MDialog, { props: { modelValue: true, title: 'T' }, slots: { default: child }, attachTo: document.body })
|
|
28
|
+
wrappers.push(w)
|
|
29
|
+
return w
|
|
30
|
+
}
|
|
31
|
+
const press = (target: EventTarget = document) =>
|
|
32
|
+
target.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true }))
|
|
33
|
+
const dialogClosed = (w: VueWrapper) => (w.emitted('update:modelValue') ?? []).some((e) => e[0] === false)
|
|
34
|
+
|
|
35
|
+
describe('Escape closes the topmost surface only', () => {
|
|
36
|
+
it('MSelect: an open list closes first', async () => {
|
|
37
|
+
const d = inDialog(() => h(MSelect, { modelValue: 'a', label: 'L', options: [{ value: 'a', label: 'A' }, { value: 'b', label: 'B' }] }))
|
|
38
|
+
const trigger = document.querySelector<HTMLElement>('[role=combobox]')!
|
|
39
|
+
trigger.click()
|
|
40
|
+
await nextTick()
|
|
41
|
+
expect(trigger.getAttribute('aria-expanded')).toBe('true')
|
|
42
|
+
press(trigger)
|
|
43
|
+
await nextTick()
|
|
44
|
+
expect(trigger.getAttribute('aria-expanded')).toBe('false')
|
|
45
|
+
expect(dialogClosed(d)).toBe(false)
|
|
46
|
+
press(trigger)
|
|
47
|
+
expect(dialogClosed(d)).toBe(true)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('MAutocomplete: an open list closes first', async () => {
|
|
51
|
+
const d = inDialog(() => h(MAutocomplete, { modelValue: null, label: 'L', options: [{ value: 'a', label: 'Apple' }] }))
|
|
52
|
+
const input = document.querySelector<HTMLInputElement>('input')!
|
|
53
|
+
input.focus()
|
|
54
|
+
input.dispatchEvent(new Event('focus'))
|
|
55
|
+
input.value = 'a'
|
|
56
|
+
input.dispatchEvent(new Event('input', { bubbles: true }))
|
|
57
|
+
await nextTick()
|
|
58
|
+
const expanded = () => document.querySelector('[aria-expanded]')?.getAttribute('aria-expanded')
|
|
59
|
+
expect(expanded()).toBe('true')
|
|
60
|
+
press(input)
|
|
61
|
+
await nextTick()
|
|
62
|
+
expect(expanded()).toBe('false')
|
|
63
|
+
expect(dialogClosed(d)).toBe(false)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('MSearchBar: an expanded bar collapses first', async () => {
|
|
67
|
+
const bar = defineComponent({ setup: () => () => h(MSearchBar, { modelValue: '', expanded: true }) })
|
|
68
|
+
const d = inDialog(() => h(bar))
|
|
69
|
+
await nextTick()
|
|
70
|
+
const s = d.findComponent(MSearchBar)
|
|
71
|
+
press()
|
|
72
|
+
await nextTick()
|
|
73
|
+
expect(s.emitted('update:expanded')).toEqual([[false]])
|
|
74
|
+
expect(dialogClosed(d)).toBe(false)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const overDialog: [string, Component, Record<string, unknown>, string][] = [
|
|
78
|
+
['MBottomSheet', MBottomSheet, { modelValue: true, title: 'S' }, 'update:modelValue'],
|
|
79
|
+
['MSideSheet', MSideSheet, { modelValue: true, title: 'S' }, 'update:modelValue'],
|
|
80
|
+
['MCommandPalette', MCommandPalette, { modelValue: true, items: [] }, 'update:modelValue'],
|
|
81
|
+
['MSpotlightSearch', MSpotlightSearch, { modelValue: true, results: [] }, 'update:modelValue'],
|
|
82
|
+
['MNavigationRail (modal)', MNavigationRail, { modelValue: 'a', items: [{ value: 'a', label: 'A', icon: 'home' }], modal: true, expanded: true }, 'update:expanded'],
|
|
83
|
+
]
|
|
84
|
+
it.each(overDialog)('%s opened over a dialog closes alone', async (_n, component, props, event) => {
|
|
85
|
+
const d = inDialog(() => 'Dialog content')
|
|
86
|
+
const top = mount(component, { props, attachTo: document.body, global: { stubs: { transition: false } } })
|
|
87
|
+
wrappers.push(top)
|
|
88
|
+
await nextTick()
|
|
89
|
+
press()
|
|
90
|
+
expect(top.emitted(event)?.[0]).toEqual([false])
|
|
91
|
+
expect(dialogClosed(d)).toBe(false)
|
|
92
|
+
})
|
|
93
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @vitest-environment node
|
|
2
2
|
import { beforeAll, describe, expect, it, vi } from 'vitest'
|
|
3
|
-
import { createSSRApp, h, type Component } from 'vue'
|
|
3
|
+
import { createSSRApp, h, resolveDirective, withDirectives, type Component, type Directive } from 'vue'
|
|
4
4
|
import { renderToString } from 'vue/server-renderer'
|
|
5
5
|
|
|
6
6
|
// What Nuxt's server sees: no window, no document, no localStorage. The import itself has to work, since
|
|
@@ -13,7 +13,9 @@ beforeAll(async () => {
|
|
|
13
13
|
expect(typeof window).toBe('undefined')
|
|
14
14
|
expect(typeof document).toBe('undefined')
|
|
15
15
|
lib = await import('../index')
|
|
16
|
-
|
|
16
|
+
// Importing the whole library cold (every component through the transform) can pass the default 10s on a busy
|
|
17
|
+
// machine
|
|
18
|
+
}, 60_000)
|
|
17
19
|
|
|
18
20
|
const items = [{ src: 'a.jpg', alt: 'a' }, { src: 'b.jpg', alt: 'b' }]
|
|
19
21
|
|
|
@@ -169,4 +171,21 @@ describe('SSR', () => {
|
|
|
169
171
|
await expect(renderToString(app)).resolves.toBe('<div></div>')
|
|
170
172
|
},
|
|
171
173
|
)
|
|
174
|
+
|
|
175
|
+
it('renders every directive, with the markers the CSS needs already in the HTML', async () => {
|
|
176
|
+
const d = (name: string) => resolveDirective(name) as Directive
|
|
177
|
+
const app = createSSRApp({
|
|
178
|
+
render: () => h('div', [
|
|
179
|
+
withDirectives(h('p', { id: 'skeleton' }, 'Ada'), [[d('skeleton'), true]]),
|
|
180
|
+
withDirectives(h('p', { id: 'ring' }), [[d('focus-ring'), { within: true }]]),
|
|
181
|
+
withDirectives(h('p', { id: 'layer' }), [[d('state-layer'), { dragged: true }]]),
|
|
182
|
+
withDirectives(h('p'), [[d('ripple')], [d('reveal')], [d('tooltip'), 'Hi'], [d('scroll-elevation')], [d('long-press'), () => {}], [d('swipe'), () => {}], [d('click-outside'), () => {}]]),
|
|
183
|
+
]),
|
|
184
|
+
})
|
|
185
|
+
app.use(lib.createM3UI())
|
|
186
|
+
const html = await renderToString(app)
|
|
187
|
+
expect(html).toContain('<p id="skeleton" data-m3-skeleton="pulse" aria-busy="true">Ada</p>')
|
|
188
|
+
expect(html).toContain('data-m3-focus-ring="within"')
|
|
189
|
+
expect(html).toContain('data-m3-state-layer="dragged"')
|
|
190
|
+
})
|
|
172
191
|
})
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
4
|
+
import { useAutoGrow } from '../composables/useAutoGrow'
|
|
5
|
+
import MTextField from '../components/MTextField.vue'
|
|
6
|
+
|
|
7
|
+
// happy-dom has no layout: give the textarea a 20px line height, 8px vertical padding (border-box) and a
|
|
8
|
+
// scrollHeight of 20px per line of text plus the padding
|
|
9
|
+
function fakeLayout(el: HTMLTextAreaElement) {
|
|
10
|
+
el.style.lineHeight = '20px'
|
|
11
|
+
el.style.padding = '4px 0'
|
|
12
|
+
el.style.boxSizing = 'border-box'
|
|
13
|
+
Object.defineProperty(el, 'scrollHeight', { configurable: true, get: () => el.value.split('\n').length * 20 + 8 })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let unmount: (() => void) | undefined
|
|
17
|
+
afterEach(() => unmount?.())
|
|
18
|
+
|
|
19
|
+
function mountArea(options: { minRows?: number; maxRows?: number }, initial = '') {
|
|
20
|
+
const text = ref(initial)
|
|
21
|
+
const area = ref<HTMLTextAreaElement>()
|
|
22
|
+
const w = mount(
|
|
23
|
+
defineComponent({
|
|
24
|
+
setup() {
|
|
25
|
+
useAutoGrow(area, { ...options, value: text })
|
|
26
|
+
return () => h('textarea', { ref: (e: unknown) => {
|
|
27
|
+
if (e && !area.value) fakeLayout(e as HTMLTextAreaElement)
|
|
28
|
+
area.value = e as HTMLTextAreaElement
|
|
29
|
+
}, value: text.value })
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
{ attachTo: document.body },
|
|
33
|
+
)
|
|
34
|
+
unmount = () => w.unmount()
|
|
35
|
+
return { text, el: () => area.value! }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('useAutoGrow', () => {
|
|
39
|
+
it('starts at minRows', async () => {
|
|
40
|
+
const { el } = mountArea({ minRows: 2 })
|
|
41
|
+
await nextTick()
|
|
42
|
+
expect(el().style.height).toBe('48px') // 2 × 20 + 8
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('grows with the text up to maxRows, then scrolls', async () => {
|
|
46
|
+
const { text, el } = mountArea({ maxRows: 3 })
|
|
47
|
+
text.value = 'a\nb'
|
|
48
|
+
await nextTick()
|
|
49
|
+
expect(el().style.height).toBe('48px')
|
|
50
|
+
expect(el().style.overflowY).toBe('hidden')
|
|
51
|
+
text.value = 'a\nb\nc\nd\ne'
|
|
52
|
+
await nextTick()
|
|
53
|
+
expect(el().style.height).toBe('68px') // capped at 3 × 20 + 8
|
|
54
|
+
expect(el().style.overflowY).toBe('auto')
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('shrinks back when the text is cleared from code', async () => {
|
|
58
|
+
const { text, el } = mountArea({}, 'a\nb\nc')
|
|
59
|
+
await nextTick()
|
|
60
|
+
expect(el().style.height).toBe('68px')
|
|
61
|
+
text.value = ''
|
|
62
|
+
await nextTick()
|
|
63
|
+
expect(el().style.height).toBe('28px')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('follows typing without a value source', async () => {
|
|
67
|
+
const area = ref<HTMLTextAreaElement>()
|
|
68
|
+
const w = mount(defineComponent({
|
|
69
|
+
setup() {
|
|
70
|
+
useAutoGrow(area)
|
|
71
|
+
return () => h('textarea', { ref: (e: unknown) => {
|
|
72
|
+
if (e && !area.value) fakeLayout(e as HTMLTextAreaElement)
|
|
73
|
+
area.value = e as HTMLTextAreaElement
|
|
74
|
+
} })
|
|
75
|
+
},
|
|
76
|
+
}))
|
|
77
|
+
unmount = () => w.unmount()
|
|
78
|
+
await nextTick()
|
|
79
|
+
area.value!.value = 'a\nb\nc\nd'
|
|
80
|
+
area.value!.dispatchEvent(new Event('input'))
|
|
81
|
+
expect(area.value!.style.height).toBe('88px')
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
describe('MTextField autoGrow', () => {
|
|
86
|
+
it('drops the drag handle and sizes the textarea itself', async () => {
|
|
87
|
+
const w = mount(MTextField, { props: { modelValue: '', label: 'Notes', multiline: true, autoGrow: true, rows: 1, maxRows: 4 } })
|
|
88
|
+
unmount = () => w.unmount()
|
|
89
|
+
await nextTick()
|
|
90
|
+
const ta = w.find('textarea')
|
|
91
|
+
expect(ta.classes()).toContain('resize-none')
|
|
92
|
+
expect(ta.element.style.height).not.toBe('')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('keeps the fixed, resizable textarea without autoGrow', async () => {
|
|
96
|
+
const w = mount(MTextField, { props: { modelValue: '', label: 'Notes', multiline: true } })
|
|
97
|
+
unmount = () => w.unmount()
|
|
98
|
+
await nextTick()
|
|
99
|
+
const ta = w.find('textarea')
|
|
100
|
+
expect(ta.classes()).toContain('resize-y')
|
|
101
|
+
expect(ta.element.style.height).toBe('')
|
|
102
|
+
})
|
|
103
|
+
})
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref, withDirectives } from 'vue'
|
|
4
|
+
import { useScrollReveal } from '../composables/useScrollReveal'
|
|
5
|
+
import { vReveal } from '../directives/vReveal'
|
|
6
|
+
|
|
7
|
+
// A controllable IntersectionObserver: tests decide which elements enter or leave
|
|
8
|
+
const observers: FakeIO[] = []
|
|
9
|
+
class FakeIO {
|
|
10
|
+
targets = new Set<Element>()
|
|
11
|
+
constructor(public cb: IntersectionObserverCallback, public opts?: IntersectionObserverInit) { observers.push(this) }
|
|
12
|
+
observe(el: Element) { this.targets.add(el) }
|
|
13
|
+
unobserve(el: Element) { this.targets.delete(el) }
|
|
14
|
+
disconnect() { this.targets.clear() }
|
|
15
|
+
fire(els: Element[], isIntersecting = true) {
|
|
16
|
+
this.cb(els.map((target) => ({ target, isIntersecting }) as IntersectionObserverEntry), this as unknown as IntersectionObserver)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const delays: number[] = []
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
observers.length = 0
|
|
22
|
+
delays.length = 0
|
|
23
|
+
vi.stubGlobal('IntersectionObserver', FakeIO)
|
|
24
|
+
// Record each reveal's delay (happy-dom's animate() runs but we only need what was asked)
|
|
25
|
+
const real = HTMLElement.prototype.animate
|
|
26
|
+
vi.spyOn(HTMLElement.prototype, 'animate').mockImplementation(function (this: HTMLElement, k, o) {
|
|
27
|
+
delays.push(typeof o === 'object' ? (o.delay ?? 0) : 0)
|
|
28
|
+
return real.call(this, k, o)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
vi.unstubAllGlobals()
|
|
33
|
+
vi.restoreAllMocks()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
function list(n: number, options = {}) {
|
|
37
|
+
const els = ref<HTMLElement[]>([])
|
|
38
|
+
const w = mount(defineComponent({
|
|
39
|
+
setup() {
|
|
40
|
+
useScrollReveal(els, options)
|
|
41
|
+
return () => h('ul', Array.from({ length: n }, (_, i) => h('li', { ref: (e: any) => { if (e) els.value[i] = e } }, `#${i}`)))
|
|
42
|
+
},
|
|
43
|
+
}), { attachTo: document.body })
|
|
44
|
+
return { w, items: () => w.findAll('li').map((l) => l.element as HTMLElement) }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe('useScrollReveal', () => {
|
|
48
|
+
it('hides the elements until they enter, then plays them in, cascading', async () => {
|
|
49
|
+
const { w, items } = list(3, { stagger: 50 })
|
|
50
|
+
await nextTick()
|
|
51
|
+
expect(items().every((el) => el.style.opacity === '0')).toBe(true)
|
|
52
|
+
observers[0]!.fire(items())
|
|
53
|
+
expect(items().every((el) => el.style.opacity === '')).toBe(true)
|
|
54
|
+
expect(delays).toEqual([0, 50, 100])
|
|
55
|
+
w.unmount()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('stops watching an element once revealed, unless once is false', async () => {
|
|
59
|
+
const { w, items } = list(1)
|
|
60
|
+
await nextTick()
|
|
61
|
+
observers[0]!.fire(items())
|
|
62
|
+
expect(observers[0]!.targets.size).toBe(0)
|
|
63
|
+
w.unmount()
|
|
64
|
+
|
|
65
|
+
const again = list(1, { once: false })
|
|
66
|
+
await nextTick()
|
|
67
|
+
const io = observers[1]!
|
|
68
|
+
io.fire(again.items())
|
|
69
|
+
io.fire(again.items(), false)
|
|
70
|
+
expect(again.items()[0]!.style.opacity).toBe('0')
|
|
71
|
+
again.w.unmount()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('leaves everything visible with reduced motion', async () => {
|
|
75
|
+
vi.stubGlobal('matchMedia', (q: string) => ({ matches: q.includes('reduce'), addEventListener() {}, removeEventListener() {} }))
|
|
76
|
+
const { w, items } = list(2)
|
|
77
|
+
await nextTick()
|
|
78
|
+
expect(items().every((el) => el.style.opacity === '')).toBe(true)
|
|
79
|
+
expect(observers).toHaveLength(0)
|
|
80
|
+
w.unmount()
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
describe('v-reveal', () => {
|
|
85
|
+
it('reveals the items of a list together, sharing one observer per options', () => {
|
|
86
|
+
const app = mount(defineComponent({
|
|
87
|
+
setup: () => () => h('div', [1, 2, 3].map((i) => withDirectives(h('p', { key: i }, String(i)), [[vReveal, { effect: 'scale', stagger: 40 }]]))),
|
|
88
|
+
}), { attachTo: document.body })
|
|
89
|
+
const ps = app.findAll('p').map((p) => p.element as HTMLElement)
|
|
90
|
+
expect(observers).toHaveLength(1)
|
|
91
|
+
expect(ps.every((p) => p.style.opacity === '0')).toBe(true)
|
|
92
|
+
observers[0]!.fire(ps)
|
|
93
|
+
expect(delays).toEqual([0, 40, 80])
|
|
94
|
+
app.unmount()
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('does nothing with false', () => {
|
|
98
|
+
const app = mount(defineComponent({ setup: () => () => withDirectives(h('p', 'x'), [[vReveal, false]]) }))
|
|
99
|
+
expect((app.element as HTMLElement).style.opacity).toBe('')
|
|
100
|
+
app.unmount()
|
|
101
|
+
})
|
|
102
|
+
})
|