@m3ui-vue/m3ui-vue 1.0.2 → 1.1.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 +666 -12
- package/dist/MMenuItem-BOkcVtEe.js +809 -0
- package/dist/MMenuItem-BOkcVtEe.js.map +1 -0
- package/dist/MSlider-BXsBv0ox.js +1402 -0
- package/dist/MSlider-BXsBv0ox.js.map +1 -0
- package/dist/MTextField-rML9jnXs.js +671 -0
- package/dist/MTextField-rML9jnXs.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MBottomSheet.vue.d.ts +20 -1
- package/dist/components/MDialog.vue.d.ts +17 -8
- package/dist/components/MDragDropList.vue.d.ts +1 -1
- package/dist/components/MIconButton.vue.d.ts +1 -1
- package/dist/components/MMap.vue.d.ts +74 -0
- package/dist/components/MMapBaseLayers.vue.d.ts +15 -0
- package/dist/components/MMapControl.vue.d.ts +40 -0
- package/dist/components/MMapFeatureInfo.vue.d.ts +25 -0
- package/dist/components/MMapFilter.vue.d.ts +19 -0
- package/dist/components/MMapGeoJson.vue.d.ts +34 -0
- package/dist/components/MMapHover.vue.d.ts +17 -0
- package/dist/components/MMapIdentify.vue.d.ts +37 -0
- package/dist/components/MMapLayers.vue.d.ts +31 -0
- package/dist/components/MMapMarker.vue.d.ts +45 -0
- package/dist/components/MMapMeasure.vue.d.ts +43 -0
- package/dist/components/MMapPopup.vue.d.ts +45 -0
- package/dist/components/MMapSearch.vue.d.ts +28 -0
- package/dist/components/MMenuItem.vue.d.ts +2 -2
- package/dist/components/MSeekBar.vue.d.ts +122 -0
- package/dist/components/MSplitButton.vue.d.ts +2 -2
- package/dist/components/_MMapAttribution.vue.d.ts +7 -0
- package/dist/components/_MMapLayerItem.vue.d.ts +25 -0
- package/dist/composables/_mapGeometry.d.ts +13 -0
- package/dist/composables/_mapPin.d.ts +5 -0
- package/dist/composables/_popupPosition.d.ts +12 -0
- package/dist/composables/_ssrState.d.ts +30 -0
- package/dist/composables/_storageKeys.d.ts +3 -0
- package/dist/composables/_useCalendarMonth.d.ts +24 -0
- package/dist/composables/_useEscapeStack.d.ts +3 -0
- package/dist/composables/_useScrollLock.d.ts +8 -0
- package/dist/composables/_useSheetMotion.d.ts +16 -1
- package/dist/composables/_useThemeTokens.d.ts +7 -0
- package/dist/composables/mapAdapters.d.ts +111 -0
- package/dist/composables/mapSearch.d.ts +31 -0
- package/dist/composables/themeInitScript.d.ts +4 -3
- package/dist/composables/useColorPalette.d.ts +173 -7
- package/dist/composables/useLocale.d.ts +38 -0
- package/dist/composables/useMap.d.ts +47 -0
- package/dist/composables/useMapFilter.d.ts +10 -0
- package/dist/composables/useMapLayers.d.ts +30 -0
- package/dist/composables/useTheme.d.ts +2 -1
- package/dist/index.d.ts +4 -1
- package/dist/locales/index.js +273 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7913 -8625
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +24 -0
- package/dist/map.js +2067 -0
- package/dist/map.js.map +1 -0
- package/dist/plugin.d.ts +18 -2
- package/dist/rich-text-editor.js +26 -25
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-CuvWRZ1h.js → useLocale-CqQrhWFl.js} +40 -2
- package/dist/useLocale-CqQrhWFl.js.map +1 -0
- package/package.json +11 -2
- package/src/__tests__/MDialog.test.ts +30 -0
- package/src/__tests__/MFab.test.ts +52 -6
- package/src/__tests__/MMap.test.ts +422 -0
- package/src/__tests__/MMapLayers.test.ts +257 -0
- package/src/__tests__/MMapTools.test.ts +233 -0
- package/src/__tests__/MSeekBar.test.ts +170 -0
- package/src/__tests__/MTooltip.test.ts +110 -0
- package/src/__tests__/_fakeMaplibre.ts +161 -0
- package/src/__tests__/calendarMonth.test.ts +59 -0
- package/src/__tests__/hydration.test.ts +33 -0
- package/src/__tests__/pickerModals.test.ts +128 -0
- package/src/__tests__/popupPosition.test.ts +224 -0
- package/src/__tests__/scrollLock.test.ts +110 -0
- package/src/__tests__/sheets.test.ts +158 -0
- package/src/__tests__/ssr.test.ts +63 -1
- package/src/__tests__/ssrState.test.ts +155 -0
- package/src/__tests__/themeInitScript.test.ts +18 -0
- package/src/components/MAutocomplete.vue +2 -4
- package/src/components/MBottomSheet.vue +211 -13
- package/src/components/MCommandPalette.vue +4 -6
- package/src/components/MContextMenu.vue +19 -5
- package/src/components/MDatePicker.vue +29 -70
- package/src/components/MDatePickerModal.vue +116 -172
- package/src/components/MDateRangePicker.vue +29 -51
- package/src/components/MDateRangePickerModal.vue +84 -162
- package/src/components/MDialog.vue +87 -63
- package/src/components/MFab.vue +29 -7
- package/src/components/MIconButton.vue +1 -1
- package/src/components/MLightbox.vue +12 -5
- package/src/components/MMap.vue +568 -0
- package/src/components/MMapBaseLayers.vue +67 -0
- package/src/components/MMapControl.vue +175 -0
- package/src/components/MMapFeatureInfo.vue +41 -0
- package/src/components/MMapFilter.vue +80 -0
- package/src/components/MMapGeoJson.vue +136 -0
- package/src/components/MMapHover.vue +131 -0
- package/src/components/MMapIdentify.vue +104 -0
- package/src/components/MMapLayers.vue +111 -0
- package/src/components/MMapMarker.vue +109 -0
- package/src/components/MMapMeasure.vue +452 -0
- package/src/components/MMapPopup.vue +103 -0
- package/src/components/MMapSearch.vue +162 -0
- package/src/components/MMenu.vue +31 -12
- package/src/components/MMenuItem.vue +21 -4
- package/src/components/MMultiAutocomplete.vue +2 -4
- package/src/components/MMultiSelect.vue +2 -4
- package/src/components/MNavigationDrawer.vue +2 -8
- package/src/components/MNavigationRail.vue +2 -3
- package/src/components/MSearchBar.vue +2 -5
- package/src/components/MSeekBar.vue +593 -0
- package/src/components/MSelect.vue +2 -8
- package/src/components/MSplitButton.vue +23 -7
- package/src/components/MSpotlightSearch.vue +4 -6
- package/src/components/MTimePicker.vue +23 -6
- package/src/components/MTimePickerModal.vue +213 -226
- package/src/components/MTooltip.vue +99 -3
- package/src/components/_MMapAttribution.vue +81 -0
- package/src/components/_MMapLayerItem.vue +77 -0
- package/src/composables/_mapGeometry.ts +75 -0
- package/src/composables/_mapPin.ts +25 -0
- package/src/composables/_popupPosition.ts +39 -0
- package/src/composables/_ssrState.ts +80 -0
- package/src/composables/_storageKeys.ts +6 -0
- package/src/composables/_useCalendarMonth.ts +74 -0
- package/src/composables/_useEscapeStack.ts +33 -0
- package/src/composables/_useScrollLock.ts +41 -0
- package/src/composables/_useSheetMotion.ts +82 -20
- package/src/composables/_useThemeTokens.ts +42 -0
- package/src/composables/mapAdapters.ts +208 -0
- package/src/composables/mapSearch.ts +56 -0
- package/src/composables/themeInitScript.ts +6 -4
- package/src/composables/useColorPalette.ts +23 -9
- package/src/composables/useLocale.ts +78 -0
- package/src/composables/useMap.ts +98 -0
- package/src/composables/useMapFilter.ts +45 -0
- package/src/composables/useMapLayers.ts +124 -0
- package/src/composables/useTheme.ts +8 -3
- package/src/composables/useWindowSizeClass.ts +14 -5
- package/src/index.ts +4 -1
- package/src/locales/de.ts +39 -1
- package/src/locales/es.ts +39 -1
- package/src/locales/fr.ts +39 -1
- package/src/locales/ja.ts +39 -1
- package/src/locales/ko.ts +39 -1
- package/src/locales/pt.ts +39 -1
- package/src/locales/zh.ts +39 -1
- package/src/map.ts +32 -0
- package/src/plugin.ts +54 -3
- package/dist/MTextField-BPbFeI9M.js +0 -1368
- package/dist/MTextField-BPbFeI9M.js.map +0 -1
- package/dist/useLocale-CuvWRZ1h.js.map +0 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
|
+
import { defineComponent, h, nextTick } from 'vue'
|
|
3
|
+
import { mount } from '@vue/test-utils'
|
|
4
|
+
import MMenu from '../components/MMenu.vue'
|
|
5
|
+
import MMenuItem from '../components/MMenuItem.vue'
|
|
6
|
+
import MContextMenu from '../components/MContextMenu.vue'
|
|
7
|
+
import MSplitButton from '../components/MSplitButton.vue'
|
|
8
|
+
import MDatePicker from '../components/MDatePicker.vue'
|
|
9
|
+
import MDateRangePicker from '../components/MDateRangePicker.vue'
|
|
10
|
+
import MTimePicker from '../components/MTimePicker.vue'
|
|
11
|
+
import { dropdownX, fitPopup } from '../composables/_popupPosition'
|
|
12
|
+
|
|
13
|
+
const rect = (left: number, top: number, width: number, height: number) =>
|
|
14
|
+
({ left, top, right: left + width, bottom: top + height, width, height, x: left, y: top, toJSON: () => ({}) }) as DOMRect
|
|
15
|
+
|
|
16
|
+
describe('dropdownX (Compose DropdownMenuPositionProvider)', () => {
|
|
17
|
+
const anchor = { left: 300, right: 340 }
|
|
18
|
+
it('aligns with the asked edge when it fits, else the other, else the window edge on the anchor\'s side', () => {
|
|
19
|
+
expect(dropdownX(anchor, 100, 1000, 'start')).toBe(300)
|
|
20
|
+
expect(dropdownX(anchor, 100, 1000, 'end')).toBe(240)
|
|
21
|
+
// Near the left edge: the end edge would overflow, so the start one
|
|
22
|
+
expect(dropdownX({ left: 10, right: 40 }, 200, 360, 'end')).toBe(10)
|
|
23
|
+
// Near the right edge: the start edge would overflow, so the end one
|
|
24
|
+
expect(dropdownX({ left: 320, right: 350 }, 200, 360, 'start')).toBe(150)
|
|
25
|
+
// Neither: against the window edge on the anchor's side
|
|
26
|
+
expect(dropdownX({ left: 150, right: 180 }, 300, 360, 'start')).toBe(8)
|
|
27
|
+
expect(dropdownX({ left: 200, right: 230 }, 300, 360, 'start')).toBe(52)
|
|
28
|
+
})
|
|
29
|
+
it('centers a popup wider than the window minus its margins', () => {
|
|
30
|
+
expect(fitPopup([0, 10], 400, 360)).toBe(-20)
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('MMenu stays on screen', () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
document.body.innerHTML = ''
|
|
37
|
+
vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(360)
|
|
38
|
+
vi.spyOn(window, 'innerHeight', 'get').mockReturnValue(700)
|
|
39
|
+
// Every panel measures 200 × 150
|
|
40
|
+
vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(200)
|
|
41
|
+
vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(150)
|
|
42
|
+
})
|
|
43
|
+
afterEach(() => vi.restoreAllMocks())
|
|
44
|
+
|
|
45
|
+
const open = async (trigger: DOMRect, align?: 'left' | 'right') => {
|
|
46
|
+
mount(
|
|
47
|
+
defineComponent({
|
|
48
|
+
setup: () => () =>
|
|
49
|
+
h(MMenu, { align }, {
|
|
50
|
+
trigger: () => h('button', { class: 'trigger' }, 'open'),
|
|
51
|
+
default: () => [
|
|
52
|
+
h(MMenuItem, null, () => 'Story'),
|
|
53
|
+
h(MMenuItem, null, { default: () => 'More', children: () => h(MMenuItem, null, () => 'Nested') }),
|
|
54
|
+
],
|
|
55
|
+
}),
|
|
56
|
+
}),
|
|
57
|
+
{ attachTo: document.body, global: { stubs: { transition: false } } },
|
|
58
|
+
)
|
|
59
|
+
const t = document.querySelector<HTMLElement>('.trigger')!
|
|
60
|
+
t.parentElement!.getBoundingClientRect = () => trigger
|
|
61
|
+
t.click()
|
|
62
|
+
await nextTick()
|
|
63
|
+
await nextTick()
|
|
64
|
+
return document.querySelector<HTMLElement>('.fixed.z-500')!
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
it('a right-aligned menu on a trigger near the left edge opens rightwards instead of off screen', async () => {
|
|
68
|
+
// The issue tracker's type button: right-aligned by default, 10px from the left edge of a phone
|
|
69
|
+
const panel = await open(rect(10, 100, 30, 30))
|
|
70
|
+
expect(panel.style.left).toBe('10px')
|
|
71
|
+
expect(panel.style.right).toBe('')
|
|
72
|
+
expect(panel.style.transformOrigin).toBe('left top')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('a left-aligned menu near the right edge flips to the trigger\'s right edge', async () => {
|
|
76
|
+
const panel = await open(rect(320, 100, 30, 30), 'left')
|
|
77
|
+
expect(panel.style.left).toBe('150px')
|
|
78
|
+
expect(panel.style.transformOrigin).toBe('right top')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('caps its width at the window minus the margins', async () => {
|
|
82
|
+
const panel = await open(rect(10, 100, 30, 30))
|
|
83
|
+
expect(panel.style.maxWidth).toBe('344px')
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('opening above grows from the bottom', async () => {
|
|
87
|
+
const panel = await open(rect(10, 650, 30, 30))
|
|
88
|
+
expect(panel.style.bottom).toBe('54px')
|
|
89
|
+
expect(panel.style.transformOrigin).toBe('left bottom')
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('a flyout submenu that fits on neither side of its item is clamped on screen', async () => {
|
|
93
|
+
const panel = await open(rect(150, 100, 30, 30))
|
|
94
|
+
const more = [...panel.querySelectorAll<HTMLElement>('button')].find((b) => b.textContent?.includes('More'))!
|
|
95
|
+
// The item spans 150–350
|
|
96
|
+
more.closest<HTMLElement>('div')!.getBoundingClientRect = () => rect(150, 140, 200, 40)
|
|
97
|
+
more.click()
|
|
98
|
+
await nextTick()
|
|
99
|
+
await nextTick()
|
|
100
|
+
const sub = document.querySelector<HTMLElement>('.m3-submenu')!
|
|
101
|
+
// Right of it (350) overflows a 360px window; its left (150 - 200 = -50) too: clamped to the margin
|
|
102
|
+
expect(sub.style.left).toBe('8px')
|
|
103
|
+
expect(sub.style.top).toBe('140px')
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
describe('MSplitButton\'s menu stays on screen', () => {
|
|
108
|
+
beforeEach(() => {
|
|
109
|
+
document.body.innerHTML = ''
|
|
110
|
+
vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(360)
|
|
111
|
+
vi.spyOn(window, 'innerHeight', 'get').mockReturnValue(700)
|
|
112
|
+
vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(200)
|
|
113
|
+
vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(150)
|
|
114
|
+
})
|
|
115
|
+
afterEach(() => vi.restoreAllMocks())
|
|
116
|
+
|
|
117
|
+
const open = async (button: DOMRect, slots?: Record<string, () => unknown>) => {
|
|
118
|
+
const w = mount(MSplitButton, {
|
|
119
|
+
props: { label: 'Save', items: slots ? undefined : [{ label: 'Save as draft' }, { label: 'Save and close' }] },
|
|
120
|
+
slots,
|
|
121
|
+
attachTo: document.body,
|
|
122
|
+
global: { stubs: { transition: false } },
|
|
123
|
+
})
|
|
124
|
+
// Two roots (the button and its Teleport): the button's container is the toggle's parent
|
|
125
|
+
w.find('.toggle-btn').element.parentElement!.getBoundingClientRect = () => button
|
|
126
|
+
await w.find('.toggle-btn').trigger('click')
|
|
127
|
+
await nextTick()
|
|
128
|
+
return w
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
it('near the right edge, it aligns with the button\'s end instead of running off', async () => {
|
|
132
|
+
// A 120px split button 8px from the right edge of a phone
|
|
133
|
+
await open(rect(232, 100, 120, 40))
|
|
134
|
+
const menu = document.querySelector<HTMLElement>('.rounded-xl.bg-surface-container')!
|
|
135
|
+
expect(menu.style.left).toBe('152px')
|
|
136
|
+
expect(menu.style.top).toBe('144px')
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('a custom menu that doesn\'t fit below opens above, measured rather than guessed', async () => {
|
|
140
|
+
await open(rect(20, 600, 120, 40), { menu: () => h('div', { class: 'custom' }, 'Custom') })
|
|
141
|
+
const menu = document.querySelector<HTMLElement>('.custom')!.parentElement!
|
|
142
|
+
expect(menu.style.top).toBe('446px')
|
|
143
|
+
expect(menu.style.left).toBe('20px')
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
describe.each([
|
|
148
|
+
['MDatePicker', MDatePicker, null],
|
|
149
|
+
['MDateRangePicker', MDateRangePicker, { start: null, end: null }],
|
|
150
|
+
['MTimePicker', MTimePicker, null],
|
|
151
|
+
] as const)('%s\'s dropdown stays on screen', (_, Comp, value) => {
|
|
152
|
+
beforeEach(() => {
|
|
153
|
+
document.body.innerHTML = ''
|
|
154
|
+
vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(360)
|
|
155
|
+
vi.spyOn(window, 'innerHeight', 'get').mockReturnValue(700)
|
|
156
|
+
// The panel's real size, whatever its content
|
|
157
|
+
vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(300)
|
|
158
|
+
vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(380)
|
|
159
|
+
})
|
|
160
|
+
afterEach(() => vi.restoreAllMocks())
|
|
161
|
+
|
|
162
|
+
const open = async (field: DOMRect) => {
|
|
163
|
+
const w = mount(Comp as any, { props: { modelValue: value }, attachTo: document.body, global: { stubs: { transition: false } } })
|
|
164
|
+
const button = w.find('button')
|
|
165
|
+
button.element.parentElement!.getBoundingClientRect = () => field
|
|
166
|
+
await button.trigger('click')
|
|
167
|
+
await nextTick()
|
|
168
|
+
return document.querySelector<HTMLElement>('.fixed.z-500')!
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
it('a field on the right half aligns the panel with its end edge', async () => {
|
|
172
|
+
const panel = await open(rect(200, 100, 152, 56))
|
|
173
|
+
expect(panel.style.left).toBe('52px')
|
|
174
|
+
expect(panel.style.top).toBe('160px')
|
|
175
|
+
expect(panel.style.maxWidth).toBe('344px')
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
it('opens above when the measured panel doesn\'t fit below', async () => {
|
|
179
|
+
const panel = await open(rect(20, 500, 300, 56))
|
|
180
|
+
expect(panel.style.top).toBe('116px')
|
|
181
|
+
expect(panel.style.left).toBe('20px')
|
|
182
|
+
})
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
describe('MContextMenu stays on screen', () => {
|
|
186
|
+
beforeEach(() => {
|
|
187
|
+
document.body.innerHTML = ''
|
|
188
|
+
vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(360)
|
|
189
|
+
vi.spyOn(window, 'innerHeight', 'get').mockReturnValue(700)
|
|
190
|
+
vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(200)
|
|
191
|
+
vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(150)
|
|
192
|
+
})
|
|
193
|
+
afterEach(() => vi.restoreAllMocks())
|
|
194
|
+
|
|
195
|
+
const openAt = async (x: number, y: number) => {
|
|
196
|
+
const w = mount(MContextMenu, {
|
|
197
|
+
slots: { trigger: () => h('div', 'area'), default: () => h(MMenuItem, null, () => 'Copy') },
|
|
198
|
+
attachTo: document.body,
|
|
199
|
+
global: { stubs: { transition: false } },
|
|
200
|
+
})
|
|
201
|
+
await (w.vm as unknown as { showAt: (x: number, y: number) => Promise<void> }).showAt(x, y)
|
|
202
|
+
await nextTick()
|
|
203
|
+
return document.querySelector<HTMLElement>('.fixed.z-\\[500\\]')!
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
it('opens right of and below the point when it fits', async () => {
|
|
207
|
+
const panel = await openAt(40, 100)
|
|
208
|
+
expect(panel.style.left).toBe('40px')
|
|
209
|
+
expect(panel.style.top).toBe('100px')
|
|
210
|
+
expect(panel.style.transformOrigin).toBe('left top')
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
it('near the right edge it flips to the left of the point, instead of sliding under the finger', async () => {
|
|
214
|
+
const panel = await openAt(350, 100)
|
|
215
|
+
expect(panel.style.left).toBe('150px')
|
|
216
|
+
expect(panel.style.transformOrigin).toBe('right top')
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it('near the bottom it flips above the point', async () => {
|
|
220
|
+
const panel = await openAt(40, 650)
|
|
221
|
+
expect(panel.style.top).toBe('500px')
|
|
222
|
+
expect(panel.style.transformOrigin).toBe('left bottom')
|
|
223
|
+
})
|
|
224
|
+
})
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
3
|
+
import { mount } from '@vue/test-utils'
|
|
4
|
+
import MDialog from '../components/MDialog.vue'
|
|
5
|
+
import MSelect from '../components/MSelect.vue'
|
|
6
|
+
|
|
7
|
+
const locked = () => document.body.style.overflow === 'hidden'
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
document.body.style.overflow = ''
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('the page scroll lock shared by modal surfaces', () => {
|
|
15
|
+
it('stacked dialogs: closing the inner one keeps the page locked under the outer one', async () => {
|
|
16
|
+
const outer = ref(true)
|
|
17
|
+
const inner = ref(true)
|
|
18
|
+
const w = mount(defineComponent({
|
|
19
|
+
setup: () => () => [
|
|
20
|
+
h(MDialog, { modelValue: outer.value, title: 'Outer' }, () => 'outer'),
|
|
21
|
+
h(MDialog, { modelValue: inner.value, title: 'Inner' }, () => 'inner'),
|
|
22
|
+
],
|
|
23
|
+
}), { attachTo: document.body })
|
|
24
|
+
await nextTick()
|
|
25
|
+
expect(locked()).toBe(true)
|
|
26
|
+
inner.value = false
|
|
27
|
+
await nextTick()
|
|
28
|
+
expect(locked()).toBe(true)
|
|
29
|
+
outer.value = false
|
|
30
|
+
await nextTick()
|
|
31
|
+
expect(locked()).toBe(false)
|
|
32
|
+
w.unmount()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('a dialog removed while open releases the page', async () => {
|
|
36
|
+
const show = ref(true)
|
|
37
|
+
const w = mount(defineComponent({
|
|
38
|
+
setup: () => () => (show.value ? h(MDialog, { modelValue: true }, () => 'content') : null),
|
|
39
|
+
}), { attachTo: document.body })
|
|
40
|
+
await nextTick()
|
|
41
|
+
expect(locked()).toBe(true)
|
|
42
|
+
show.value = false
|
|
43
|
+
await nextTick()
|
|
44
|
+
expect(locked()).toBe(false)
|
|
45
|
+
w.unmount()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('a select unmounting inside an open dialog leaves it locked', async () => {
|
|
49
|
+
const field = ref(true)
|
|
50
|
+
const w = mount(defineComponent({
|
|
51
|
+
setup: () => () => h(MDialog, { modelValue: true }, () =>
|
|
52
|
+
field.value ? h(MSelect, { modelValue: null, options: [{ value: 1, label: 'One' }] }) : 'gone'),
|
|
53
|
+
}), { attachTo: document.body })
|
|
54
|
+
await nextTick()
|
|
55
|
+
expect(locked()).toBe(true)
|
|
56
|
+
field.value = false
|
|
57
|
+
await nextTick()
|
|
58
|
+
expect(locked()).toBe(true)
|
|
59
|
+
w.unmount()
|
|
60
|
+
expect(locked()).toBe(false)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('keeps an overflow the app had set before', async () => {
|
|
64
|
+
document.body.style.overflow = 'clip'
|
|
65
|
+
const open = ref(true)
|
|
66
|
+
const w = mount(defineComponent({ setup: () => () => h(MDialog, { modelValue: open.value }, () => 'x') }), { attachTo: document.body })
|
|
67
|
+
await nextTick()
|
|
68
|
+
expect(locked()).toBe(true)
|
|
69
|
+
open.value = false
|
|
70
|
+
await nextTick()
|
|
71
|
+
expect(document.body.style.overflow).toBe('clip')
|
|
72
|
+
w.unmount()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe('Escape with stacked dialogs', () => {
|
|
77
|
+
const esc = () => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
|
|
78
|
+
const stacked = (innerProps: Record<string, unknown> = {}) => {
|
|
79
|
+
const outer = ref(true)
|
|
80
|
+
const inner = ref(true)
|
|
81
|
+
const w = mount(defineComponent({
|
|
82
|
+
setup: () => () => [
|
|
83
|
+
h(MDialog, { modelValue: outer.value, 'onUpdate:modelValue': (v: boolean) => (outer.value = v) }, () => 'outer'),
|
|
84
|
+
h(MDialog, { modelValue: inner.value, 'onUpdate:modelValue': (v: boolean) => (inner.value = v), ...innerProps }, () => 'inner'),
|
|
85
|
+
],
|
|
86
|
+
}), { attachTo: document.body })
|
|
87
|
+
return { w, outer, inner }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
it('closes the one on top only, then the next', async () => {
|
|
91
|
+
const { w, outer, inner } = stacked()
|
|
92
|
+
await nextTick()
|
|
93
|
+
esc()
|
|
94
|
+
await nextTick()
|
|
95
|
+
expect([outer.value, inner.value]).toEqual([true, false])
|
|
96
|
+
esc()
|
|
97
|
+
await nextTick()
|
|
98
|
+
expect(outer.value).toBe(false)
|
|
99
|
+
w.unmount()
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('a persistent dialog on top keeps the one under it open', async () => {
|
|
103
|
+
const { w, outer, inner } = stacked({ persistent: true })
|
|
104
|
+
await nextTick()
|
|
105
|
+
esc()
|
|
106
|
+
await nextTick()
|
|
107
|
+
expect([outer.value, inner.value]).toEqual([true, true])
|
|
108
|
+
w.unmount()
|
|
109
|
+
})
|
|
110
|
+
})
|
|
@@ -78,3 +78,161 @@ describe.each([
|
|
|
78
78
|
w.unmount()
|
|
79
79
|
})
|
|
80
80
|
})
|
|
81
|
+
|
|
82
|
+
describe('MBottomSheet partial / maxHeight', () => {
|
|
83
|
+
const open = (props: Record<string, unknown>) => {
|
|
84
|
+
const w = mount(MBottomSheet, {
|
|
85
|
+
props: { modelValue: true, ...props },
|
|
86
|
+
slots: { default: '<div class="body">content</div>' },
|
|
87
|
+
attachTo: document.body,
|
|
88
|
+
global: { stubs: { transition: false } },
|
|
89
|
+
})
|
|
90
|
+
return w
|
|
91
|
+
}
|
|
92
|
+
const settle = async () => {
|
|
93
|
+
await nextTick()
|
|
94
|
+
panel()!.getAnimations().forEach((a) => a.finish())
|
|
95
|
+
scrim()?.getAnimations().forEach((a) => a.finish())
|
|
96
|
+
}
|
|
97
|
+
const handle = () => panel()!.querySelector<HTMLElement>('[data-sheet-handle]')!
|
|
98
|
+
const drag = (dy: number, wait = 200) => {
|
|
99
|
+
const h = handle()
|
|
100
|
+
h.setPointerCapture = () => {}
|
|
101
|
+
h.dispatchEvent(new PointerEvent('pointerdown', { clientY: 300, pointerId: 1 }))
|
|
102
|
+
vi.advanceTimersByTime(16)
|
|
103
|
+
h.dispatchEvent(new PointerEvent('pointermove', { clientY: 300 + dy, pointerId: 1 }))
|
|
104
|
+
vi.advanceTimersByTime(wait)
|
|
105
|
+
h.dispatchEvent(new PointerEvent('pointerup', { clientY: 300 + dy, pointerId: 1 }))
|
|
106
|
+
}
|
|
107
|
+
const touch = (el: Element, type: string, y: number) => {
|
|
108
|
+
const t = { identifier: 7, clientX: 0, clientY: y, target: el } as unknown as Touch
|
|
109
|
+
const e = new Event(type, { bubbles: true, cancelable: true }) as TouchEvent
|
|
110
|
+
Object.defineProperty(e, 'touches', { value: type === 'touchend' ? [] : [t] })
|
|
111
|
+
Object.defineProperty(e, 'changedTouches', { value: [t] })
|
|
112
|
+
el.dispatchEvent(e)
|
|
113
|
+
return e
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
beforeEach(() => { vi.spyOn(window, 'innerHeight', 'get').mockReturnValue(600) })
|
|
117
|
+
|
|
118
|
+
it('caps the height: 60vh by default, 92vh with fullHeight, or maxHeight', async () => {
|
|
119
|
+
let w = open({})
|
|
120
|
+
expect(panel()!.style.maxHeight).toBe('60vh')
|
|
121
|
+
w.unmount()
|
|
122
|
+
w = open({ fullHeight: true })
|
|
123
|
+
expect(panel()!.style.maxHeight).toBe('92vh')
|
|
124
|
+
w.unmount()
|
|
125
|
+
w = open({ maxHeight: '480px', partial: true })
|
|
126
|
+
expect(panel()!.style.maxHeight).toBe('480px')
|
|
127
|
+
w.unmount()
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('opens partially expanded and the handle toggles it', async () => {
|
|
131
|
+
// 400px panel on a 600px screen: half the screen shows, so the partial offset is 100/400
|
|
132
|
+
const w = open({ partial: true })
|
|
133
|
+
await settle()
|
|
134
|
+
expect(panel()!.style.transform).toBe('translateY(25%)')
|
|
135
|
+
expect(handle().getAttribute('role')).toBe('button')
|
|
136
|
+
handle().dispatchEvent(new MouseEvent('click', { clientY: 0 }))
|
|
137
|
+
expect(panel()!.style.transform).toBe('translateY(0%)')
|
|
138
|
+
expect(w.emitted('update:expanded')!.at(-1)).toEqual([true])
|
|
139
|
+
handle().dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter' }))
|
|
140
|
+
expect(panel()!.style.transform).toBe('translateY(25%)')
|
|
141
|
+
expect(w.emitted('update:expanded')!.at(-1)).toEqual([false])
|
|
142
|
+
w.unmount()
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('opens fully expanded when the sheet is no taller than the partial share', async () => {
|
|
146
|
+
vi.spyOn(window, 'innerHeight', 'get').mockReturnValue(1000)
|
|
147
|
+
const w = open({ partial: true })
|
|
148
|
+
await settle()
|
|
149
|
+
expect(panel()!.style.transform).toBe('translateY(0%)')
|
|
150
|
+
expect(handle().getAttribute('role')).toBeNull()
|
|
151
|
+
w.unmount()
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('drags between partial, expanded and dismissed', async () => {
|
|
155
|
+
const w = open({ partial: true })
|
|
156
|
+
await settle()
|
|
157
|
+
drag(-150)
|
|
158
|
+
expect(panel()!.style.transform).toBe('translateY(0%)')
|
|
159
|
+
// From expanded, 150px down lands nearer the partial anchor than off-screen
|
|
160
|
+
drag(150)
|
|
161
|
+
expect(panel()!.style.transform).toBe('translateY(25%)')
|
|
162
|
+
expect(w.emitted('update:modelValue')).toBeUndefined()
|
|
163
|
+
drag(150)
|
|
164
|
+
expect(w.emitted('update:modelValue')![0]).toEqual([false])
|
|
165
|
+
w.unmount()
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('a flick goes to the next anchor that way', async () => {
|
|
169
|
+
const w = open({ partial: true, expanded: true })
|
|
170
|
+
await settle()
|
|
171
|
+
expect(panel()!.style.transform).toBe('translateY(0%)')
|
|
172
|
+
drag(40, 16)
|
|
173
|
+
expect(panel()!.style.transform).toBe('translateY(25%)')
|
|
174
|
+
expect(w.emitted('update:modelValue')).toBeUndefined()
|
|
175
|
+
w.unmount()
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
it('the content drags a partially expanded sheet up, and only scrolls once expanded', async () => {
|
|
179
|
+
const w = open({ partial: true })
|
|
180
|
+
await settle()
|
|
181
|
+
const body = panel()!.querySelector('.body')!
|
|
182
|
+
touch(body, 'touchstart', 400)
|
|
183
|
+
vi.advanceTimersByTime(16)
|
|
184
|
+
const move = touch(body, 'touchmove', 250)
|
|
185
|
+
expect(move.defaultPrevented).toBe(true)
|
|
186
|
+
expect(panel()!.style.transform).toBe('translateY(0%)')
|
|
187
|
+
vi.advanceTimersByTime(200)
|
|
188
|
+
touch(body, 'touchend', 250)
|
|
189
|
+
expect(w.emitted('update:expanded')!.at(-1)).toEqual([true])
|
|
190
|
+
|
|
191
|
+
// Expanded: a drag up is the content's scroll, not the sheet's
|
|
192
|
+
touch(body, 'touchstart', 400)
|
|
193
|
+
const up = touch(body, 'touchmove', 300)
|
|
194
|
+
expect(up.defaultPrevented).toBe(false)
|
|
195
|
+
touch(body, 'touchend', 300)
|
|
196
|
+
|
|
197
|
+
// Scrolled down, a drag down scrolls back; at the top it collapses the sheet
|
|
198
|
+
const content = body.parentElement!
|
|
199
|
+
content.scrollTop = 50
|
|
200
|
+
Object.defineProperty(content, 'scrollTop', { value: 50, configurable: true })
|
|
201
|
+
touch(body, 'touchstart', 300)
|
|
202
|
+
expect(touch(body, 'touchmove', 400).defaultPrevented).toBe(false)
|
|
203
|
+
touch(body, 'touchend', 400)
|
|
204
|
+
Object.defineProperty(content, 'scrollTop', { value: 0, configurable: true })
|
|
205
|
+
touch(body, 'touchstart', 300)
|
|
206
|
+
vi.advanceTimersByTime(16)
|
|
207
|
+
expect(touch(body, 'touchmove', 450).defaultPrevented).toBe(true)
|
|
208
|
+
vi.advanceTimersByTime(200)
|
|
209
|
+
touch(body, 'touchend', 450)
|
|
210
|
+
expect(panel()!.style.transform).toBe('translateY(25%)')
|
|
211
|
+
w.unmount()
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
it('without partial, the content never drags the sheet', async () => {
|
|
215
|
+
const w = open({})
|
|
216
|
+
await settle()
|
|
217
|
+
const body = panel()!.querySelector('.body')!
|
|
218
|
+
touch(body, 'touchstart', 400)
|
|
219
|
+
expect(touch(body, 'touchmove', 500).defaultPrevented).toBe(false)
|
|
220
|
+
expect(panel()!.style.transform).toBe('translateY(0%)')
|
|
221
|
+
w.unmount()
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
it('squares the corners only when asked and the expanded sheet fills the screen', async () => {
|
|
225
|
+
vi.spyOn(window, 'innerHeight', 'get').mockReturnValue(400)
|
|
226
|
+
let w = open({ partial: true, expanded: true })
|
|
227
|
+
await settle()
|
|
228
|
+
expect(panel()!.classList.contains('rounded-t-[28px]')).toBe(true)
|
|
229
|
+
w.unmount()
|
|
230
|
+
w = open({ partial: true, expanded: true, squareCornersWhenFull: true })
|
|
231
|
+
await settle()
|
|
232
|
+
expect(panel()!.classList.contains('rounded-t-none')).toBe(true)
|
|
233
|
+
handle().dispatchEvent(new MouseEvent('click', { clientY: 0 }))
|
|
234
|
+
await nextTick()
|
|
235
|
+
expect(panel()!.classList.contains('rounded-t-[28px]')).toBe(true)
|
|
236
|
+
w.unmount()
|
|
237
|
+
})
|
|
238
|
+
})
|
|
@@ -73,6 +73,8 @@ describe('SSR', () => {
|
|
|
73
73
|
['terminal', 'MTerminal', {}],
|
|
74
74
|
['qrcode', 'MQRCode', { value: 'x' }],
|
|
75
75
|
['barcode', 'MBarcode', { value: '123456' }],
|
|
76
|
+
// The empty container: MapLibre only loads in the browser
|
|
77
|
+
['map', 'MMap', { mapStyle: 'https://tiles.test/style.json' }],
|
|
76
78
|
] as const)('renders %s/%s', async (entry, name, componentProps) => {
|
|
77
79
|
const mod = await import(`../${entry}.ts`)
|
|
78
80
|
await expect(render(mod[name], componentProps)).resolves.toBeTypeOf('string')
|
|
@@ -95,7 +97,67 @@ describe('SSR', () => {
|
|
|
95
97
|
expect(await render(lib.MPagination, { modelValue: 1, total: 50 }, { locale: lib.defaultLocale })).toBeTruthy()
|
|
96
98
|
})
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
describe('initialState', () => {
|
|
101
|
+
// What a component renders from the composables, server-side
|
|
102
|
+
async function state(options: object) {
|
|
103
|
+
const app = createSSRApp({
|
|
104
|
+
setup() {
|
|
105
|
+
const { theme } = lib.useTheme()
|
|
106
|
+
const { palette, contrast, activeContrast } = lib.useColorPalette()
|
|
107
|
+
return () => h('p', `${theme.value} ${palette.value} ${contrast.value} ${activeContrast.value}`)
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
app.use(lib.createM3UI(options))
|
|
111
|
+
return (await renderToString(app)).replace(/<\/?p>/g, '')
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
it('reports the user\'s choice on the server', async () => {
|
|
115
|
+
expect(await state({ initialState: { theme: 'dark', palette: 'blue', contrast: 'high' } })).toBe('dark blue high high')
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('falls back to the plugin\'s defaults, like a first visit', async () => {
|
|
119
|
+
expect(await state({ palette: 'red', contrast: 'medium', initialState: {} })).toBe('system red medium medium')
|
|
120
|
+
expect(await state({ seed: '#6750a4', initialState: {} })).toBe('system seed standard standard')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('resolves system contrast to standard (the server can\'t know the OS preference)', async () => {
|
|
124
|
+
expect(await state({ initialState: { contrast: 'system' } })).toBe('system purple system standard')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('lets persistPalette: false win over the stored choice', async () => {
|
|
128
|
+
expect(await state({ palette: 'red', contrast: 'high', persistPalette: false, initialState: { palette: 'blue', contrast: 'medium' } }))
|
|
129
|
+
.toBe('system red high high')
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('ignores invalid values (cookies are user input)', async () => {
|
|
133
|
+
expect(await state({ initialState: { theme: 'pink', contrast: 'max' } as object })).toBe('system purple standard standard')
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('renders the adaptive layouts for the given viewport', async () => {
|
|
137
|
+
const suite = (options: object) => render(lib.MNavigationSuite, { modelValue: 'a', items: [{ value: 'a', label: 'A', icon: 'home' }] }, options)
|
|
138
|
+
// A desktop window: a rail beside the content (a row); none known: compact, a bar under it (a column)
|
|
139
|
+
expect(await suite({ initialState: { viewport: { width: 1280, height: 800 } } })).toMatch(/^<div class="[^"]*flex-row/)
|
|
140
|
+
expect(await suite({ initialState: {} })).toMatch(/^<div class="[^"]*flex-col/)
|
|
141
|
+
expect(await suite({ initialState: { viewport: { width: -1, height: 800 } } })).toMatch(/^<div class="[^"]*flex-col/)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it('reports the viewport through useWindowSizeClass()', async () => {
|
|
145
|
+
const app = createSSRApp({
|
|
146
|
+
setup() {
|
|
147
|
+
const { widthClass, heightClass } = lib.useWindowSizeClass()
|
|
148
|
+
return () => h('p', `${widthClass.value} ${heightClass.value}`)
|
|
149
|
+
},
|
|
150
|
+
})
|
|
151
|
+
app.use(lib.createM3UI({ initialState: { viewport: { width: 1280, height: 800 } } }))
|
|
152
|
+
expect(await renderToString(app)).toBe('<p>large medium</p>')
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('without it, keeps reporting the module defaults', async () => {
|
|
156
|
+
expect(await state({ palette: 'red' })).toBe('system purple standard standard')
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it.each(['useTheme','useColorPalette', 'useDevice', 'useLocale', 'useWindowSizeClass', 'useToast', 'useNotification'] as const)(
|
|
99
161
|
'%s() works in setup', async (name) => {
|
|
100
162
|
const app = createSSRApp({
|
|
101
163
|
setup() {
|