@m3ui-vue/m3ui-vue 1.1.3 → 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/README.md +1 -1
- package/dist/API.md +579 -40
- package/dist/MMenuItem-DI351kIf.js +929 -0
- package/dist/MMenuItem-DI351kIf.js.map +1 -0
- package/dist/MSlider-BnEy5ieZ.js +1500 -0
- 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/MAnimatedNumber.vue.d.ts +3 -1
- package/dist/components/MButton.vue.d.ts +9 -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/MContainerTransform.vue.d.ts +59 -0
- package/dist/components/MContextMenu.vue.d.ts +2 -2
- package/dist/components/MCopyButton.vue.d.ts +1 -1
- package/dist/components/MDialog.vue.d.ts +8 -5
- 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/MFlex.vue.d.ts +1 -1
- package/dist/components/MIconButton.vue.d.ts +15 -1
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MListItem.vue.d.ts +5 -5
- 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/MNavigationRail.vue.d.ts +1 -1
- 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/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +1 -1
- 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/MToolbar.vue.d.ts +32 -5
- package/dist/components/MTooltip.vue.d.ts +1 -1
- package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
- package/dist/components/_MToolbarFab.vue.d.ts +16 -0
- package/dist/composables/_containerTransform.d.ts +48 -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/useContainerTransform.d.ts +30 -0
- package/dist/composables/useLocale.d.ts +6 -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 +31 -1
- package/dist/locales/index.js +35 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7692 -6273
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +1 -1
- package/dist/map.js +823 -793
- 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 +20 -16
- 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-SfQHnJfp.js → useLocale-JYxDDeXC.js} +6 -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 +2 -1
- package/src/__tests__/MAnimatedNumber.test.ts +24 -2
- 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__/MContainerTransform.test.ts +279 -0
- package/src/__tests__/MDialog.test.ts +27 -0
- package/src/__tests__/MIconButton.test.ts +33 -0
- package/src/__tests__/MListItemExpandable.test.ts +48 -0
- package/src/__tests__/MListItemShape.test.ts +9 -6
- package/src/__tests__/MListKeyboard.test.ts +90 -0
- package/src/__tests__/MMap.test.ts +53 -1
- package/src/__tests__/MMapLayers.test.ts +46 -2
- package/src/__tests__/MMapTools.test.ts +2 -1
- 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__/MNavigationRail.test.ts +33 -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__/MSlider.test.ts +161 -0
- package/src/__tests__/MTimeline.test.ts +238 -0
- package/src/__tests__/MToolbar.test.ts +157 -0
- package/src/__tests__/_fakeMaplibre.ts +3 -1
- package/src/__tests__/attrsFallthrough.test.ts +9 -0
- package/src/__tests__/escapeStack.test.ts +93 -0
- package/src/__tests__/hydration.test.ts +25 -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/MAnimatedNumber.vue +32 -6
- package/src/components/MAutocomplete.vue +5 -0
- package/src/components/MBottomSheet.vue +4 -1
- package/src/components/MButton.vue +19 -3
- 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/MContainerTransform.vue +321 -0
- package/src/components/MContextMenu.vue +19 -60
- package/src/components/MDialog.vue +31 -6
- package/src/components/MDragDropList.vue +2 -0
- package/src/components/MFab.vue +10 -5
- package/src/components/MIconButton.vue +43 -2
- package/src/components/MKanban.vue +2 -0
- package/src/components/MLightbox.vue +7 -2
- package/src/components/MList.vue +26 -2
- package/src/components/MListItem.vue +138 -84
- 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 +44 -25
- 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/MSlider.vue +161 -42
- package/src/components/MSpotlightSearch.vue +3 -2
- package/src/components/MTextField.vue +15 -2
- package/src/components/MTimeline.vue +370 -81
- package/src/components/MToolbar.vue +256 -15
- package/src/components/MTooltip.vue +20 -152
- package/src/components/_MDrawerItemList.vue +25 -6
- package/src/components/_MToolbarFab.vue +14 -0
- package/src/composables/_containerTransform.ts +179 -0
- package/src/composables/_mapStyle.ts +45 -0
- package/src/composables/_themeTransition.ts +2 -0
- package/src/composables/_tooltipTrigger.ts +184 -0
- package/src/composables/_useEscapeStack.ts +2 -0
- package/src/composables/_useMenuNav.ts +209 -0
- package/src/composables/useAutoGrow.ts +78 -0
- package/src/composables/useContainerTransform.ts +59 -0
- package/src/composables/useLocale.ts +10 -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 +31 -1
- package/src/locales/de.ts +4 -0
- package/src/locales/es.ts +4 -0
- package/src/locales/fr.ts +4 -0
- package/src/locales/ja.ts +4 -0
- package/src/locales/ko.ts +4 -0
- package/src/locales/pt.ts +4 -0
- package/src/locales/zh.ts +4 -0
- package/src/map.ts +1 -1
- package/src/plugin.ts +34 -0
- package/src/styles/theme.css +63 -0
- package/dist/MMenuItem-BckcR0nW.js +0 -809
- package/dist/MMenuItem-BckcR0nW.js.map +0 -1
- package/dist/MSlider-LyH_gy8D.js +0 -1411
- package/dist/MSlider-LyH_gy8D.js.map +0 -1
- package/dist/MTextField-FCPOTB0o.js +0 -672
- package/dist/MTextField-FCPOTB0o.js.map +0 -1
- package/dist/composables/_useThemeTokens.d.ts +0 -7
- package/dist/useLocale-SfQHnJfp.js.map +0 -1
- package/src/composables/_useThemeTokens.ts +0 -42
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, withDirectives } from 'vue'
|
|
4
|
+
import { vLongPress, type LongPressValue } from '../directives/vLongPress'
|
|
5
|
+
|
|
6
|
+
const pointer = (type: string, pointerType = 'touch', x = 10, y = 10) =>
|
|
7
|
+
new PointerEvent(type, { pointerType, pointerId: 1, button: 0, clientX: x, clientY: y, bubbles: true })
|
|
8
|
+
|
|
9
|
+
function host(value: LongPressValue, onClick = vi.fn()) {
|
|
10
|
+
const w = mount(defineComponent({
|
|
11
|
+
setup: () => () => withDirectives(h('button', { onClick }, 'Hold'), [[vLongPress, value]]),
|
|
12
|
+
}), { attachTo: document.body })
|
|
13
|
+
return { w, el: w.element as HTMLElement, onClick }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('vLongPress', () => {
|
|
17
|
+
beforeEach(() => vi.useFakeTimers())
|
|
18
|
+
afterEach(() => vi.useRealTimers())
|
|
19
|
+
|
|
20
|
+
it('fires after the duration, marks the press while held, and swallows the click it ends in', () => {
|
|
21
|
+
const handler = vi.fn()
|
|
22
|
+
const { el, onClick } = host(handler)
|
|
23
|
+
el.dispatchEvent(pointer('pointerdown'))
|
|
24
|
+
expect(el.dataset.longPressing).toBe('')
|
|
25
|
+
vi.advanceTimersByTime(499)
|
|
26
|
+
expect(handler).not.toHaveBeenCalled()
|
|
27
|
+
vi.advanceTimersByTime(1)
|
|
28
|
+
expect(handler).toHaveBeenCalledTimes(1)
|
|
29
|
+
expect(handler.mock.calls[0]![0]).toBeInstanceOf(PointerEvent)
|
|
30
|
+
expect(el.dataset.longPressing).toBeUndefined()
|
|
31
|
+
window.dispatchEvent(pointer('pointerup'))
|
|
32
|
+
el.click()
|
|
33
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('a short press is a plain click, and moving past the tolerance cancels it', () => {
|
|
37
|
+
const handler = vi.fn()
|
|
38
|
+
const { el, onClick } = host({ handler, duration: 300 })
|
|
39
|
+
el.dispatchEvent(pointer('pointerdown'))
|
|
40
|
+
vi.advanceTimersByTime(100)
|
|
41
|
+
window.dispatchEvent(pointer('pointerup'))
|
|
42
|
+
el.click()
|
|
43
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
44
|
+
|
|
45
|
+
el.dispatchEvent(pointer('pointerdown'))
|
|
46
|
+
window.dispatchEvent(pointer('pointermove', 'touch', 10, 25))
|
|
47
|
+
vi.advanceTimersByTime(300)
|
|
48
|
+
expect(handler).not.toHaveBeenCalled()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('leaves the mouse alone with mouse: false, and does nothing when disabled', () => {
|
|
52
|
+
const handler = vi.fn()
|
|
53
|
+
const { el } = host({ handler, mouse: false })
|
|
54
|
+
el.dispatchEvent(pointer('pointerdown', 'mouse'))
|
|
55
|
+
vi.advanceTimersByTime(600)
|
|
56
|
+
expect(handler).not.toHaveBeenCalled()
|
|
57
|
+
|
|
58
|
+
const off = host({ handler, disabled: true })
|
|
59
|
+
off.el.dispatchEvent(pointer('pointerdown'))
|
|
60
|
+
vi.advanceTimersByTime(600)
|
|
61
|
+
expect(handler).not.toHaveBeenCalled()
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('stops swallowing clicks a moment after a press that ended in none', () => {
|
|
65
|
+
const { el, onClick } = host(vi.fn())
|
|
66
|
+
el.dispatchEvent(pointer('pointerdown'))
|
|
67
|
+
vi.advanceTimersByTime(500)
|
|
68
|
+
window.dispatchEvent(pointer('pointerup'))
|
|
69
|
+
vi.advanceTimersByTime(400)
|
|
70
|
+
el.click()
|
|
71
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('blocks the browser\'s long-press menu while pressing', () => {
|
|
75
|
+
const { el } = host(vi.fn())
|
|
76
|
+
el.dispatchEvent(pointer('pointerdown'))
|
|
77
|
+
const menu = new Event('contextmenu', { cancelable: true })
|
|
78
|
+
el.dispatchEvent(menu)
|
|
79
|
+
expect(menu.defaultPrevented).toBe(true)
|
|
80
|
+
})
|
|
81
|
+
})
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref, withDirectives } from 'vue'
|
|
4
|
+
import { vScrollElevation, type ScrollElevationValue } from '../directives/vScrollElevation'
|
|
5
|
+
|
|
6
|
+
function scroller(top = 0) {
|
|
7
|
+
const el = document.createElement('div')
|
|
8
|
+
el.scrollTop = top
|
|
9
|
+
document.body.appendChild(el)
|
|
10
|
+
return {
|
|
11
|
+
el,
|
|
12
|
+
scrollTo(y: number) {
|
|
13
|
+
el.scrollTop = y
|
|
14
|
+
el.dispatchEvent(new Event('scroll'))
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function host(value: () => ScrollElevationValue) {
|
|
20
|
+
return mount(defineComponent({
|
|
21
|
+
setup: () => () => withDirectives(h('header'), [[vScrollElevation, value()]]),
|
|
22
|
+
}))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('vScrollElevation', () => {
|
|
26
|
+
it('takes the scrolled color and data-scrolled once its target scrolls, and gives them back at the top', () => {
|
|
27
|
+
const list = scroller()
|
|
28
|
+
const onChange = vi.fn()
|
|
29
|
+
const w = host(() => ({ target: list.el, onChange }))
|
|
30
|
+
const el = w.element as HTMLElement
|
|
31
|
+
expect(el.dataset.scrolled).toBeUndefined()
|
|
32
|
+
list.scrollTo(30)
|
|
33
|
+
expect(el.dataset.scrolled).toBe('')
|
|
34
|
+
expect(el.style.backgroundColor).toBe('var(--color-surface-container)')
|
|
35
|
+
list.scrollTo(0)
|
|
36
|
+
expect(el.dataset.scrolled).toBeUndefined()
|
|
37
|
+
expect(el.style.backgroundColor).toBe('')
|
|
38
|
+
expect(onChange.mock.calls).toEqual([[true], [false]])
|
|
39
|
+
w.unmount()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('takes a selector, a threshold, its own color or none', async () => {
|
|
43
|
+
const list = scroller()
|
|
44
|
+
list.el.id = 'feed'
|
|
45
|
+
const color = ref<string | false>('#123456')
|
|
46
|
+
const w = host(() => ({ target: '#feed', threshold: 50, color: color.value }))
|
|
47
|
+
const el = w.element as HTMLElement
|
|
48
|
+
list.scrollTo(40)
|
|
49
|
+
expect(el.dataset.scrolled).toBeUndefined()
|
|
50
|
+
list.scrollTo(60)
|
|
51
|
+
expect(el.style.backgroundColor).toMatch(/#123456|rgb\(18, 52, 86\)/)
|
|
52
|
+
color.value = false
|
|
53
|
+
await nextTick()
|
|
54
|
+
expect(el.dataset.scrolled).toBe('')
|
|
55
|
+
expect(el.style.backgroundColor).toBe('')
|
|
56
|
+
w.unmount()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('starts scrolled if its target already is, and stops following when disabled or unmounted', async () => {
|
|
60
|
+
const list = scroller(100)
|
|
61
|
+
const disabled = ref(false)
|
|
62
|
+
const w = host(() => ({ target: list.el, disabled: disabled.value }))
|
|
63
|
+
const el = w.element as HTMLElement
|
|
64
|
+
expect(el.dataset.scrolled).toBe('')
|
|
65
|
+
disabled.value = true
|
|
66
|
+
await nextTick()
|
|
67
|
+
expect(el.dataset.scrolled).toBeUndefined()
|
|
68
|
+
list.scrollTo(200)
|
|
69
|
+
expect(el.dataset.scrolled).toBeUndefined()
|
|
70
|
+
w.unmount()
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
describe('vScrollElevation target ref', () => {
|
|
75
|
+
it('waits for a template ref that is still empty instead of following the window', async () => {
|
|
76
|
+
const target = ref<HTMLElement | null>(null)
|
|
77
|
+
const w = host(() => ({ target: target.value }))
|
|
78
|
+
const el = w.element as HTMLElement
|
|
79
|
+
Object.defineProperty(window, 'scrollY', { value: 500, configurable: true })
|
|
80
|
+
window.dispatchEvent(new Event('scroll'))
|
|
81
|
+
expect(el.dataset.scrolled).toBeUndefined()
|
|
82
|
+
const list = scroller(80)
|
|
83
|
+
target.value = list.el
|
|
84
|
+
await nextTick()
|
|
85
|
+
expect(el.dataset.scrolled).toBe('')
|
|
86
|
+
Object.defineProperty(window, 'scrollY', { value: 0, configurable: true })
|
|
87
|
+
w.unmount()
|
|
88
|
+
})
|
|
89
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref, withDirectives } from 'vue'
|
|
4
|
+
import { vSkeleton, type SkeletonValue } from '../directives/vSkeleton'
|
|
5
|
+
|
|
6
|
+
function host(value: () => SkeletonValue) {
|
|
7
|
+
return mount(defineComponent({
|
|
8
|
+
setup: () => () => withDirectives(h('div', [h('p', 'Ada Lovelace')]), [[vSkeleton, value()]]),
|
|
9
|
+
}), { attachTo: document.body })
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('vSkeleton', () => {
|
|
13
|
+
it('marks the element as a busy placeholder while loading, and clears it after', async () => {
|
|
14
|
+
const loading = ref(true)
|
|
15
|
+
const w = host(() => loading.value)
|
|
16
|
+
const el = w.element as HTMLElement
|
|
17
|
+
expect(el.dataset.m3Skeleton).toBe('pulse')
|
|
18
|
+
expect(el.getAttribute('aria-busy')).toBe('true')
|
|
19
|
+
loading.value = false
|
|
20
|
+
await nextTick()
|
|
21
|
+
expect(el.dataset.m3Skeleton).toBeUndefined()
|
|
22
|
+
expect(el.hasAttribute('aria-busy')).toBe(false)
|
|
23
|
+
w.unmount()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('wave adds a shimmer layer (and positions a static element); switching away removes both', async () => {
|
|
27
|
+
const value = ref<SkeletonValue>({ loading: true, animation: 'wave' })
|
|
28
|
+
const w = host(() => value.value)
|
|
29
|
+
const el = w.element as HTMLElement
|
|
30
|
+
expect(el.dataset.m3Skeleton).toBe('wave')
|
|
31
|
+
expect(el.querySelectorAll('.m3-skeleton-shimmer')).toHaveLength(1)
|
|
32
|
+
expect(el.style.position).toBe('relative')
|
|
33
|
+
value.value = { loading: true, animation: 'none' }
|
|
34
|
+
await nextTick()
|
|
35
|
+
expect(el.dataset.m3Skeleton).toBe('none')
|
|
36
|
+
expect(el.querySelector('.m3-skeleton-shimmer')).toBeNull()
|
|
37
|
+
value.value = false
|
|
38
|
+
await nextTick()
|
|
39
|
+
expect(el.style.position).toBe('')
|
|
40
|
+
w.unmount()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('keeps the content in the DOM (it sizes the placeholder)', () => {
|
|
44
|
+
const w = host(() => true)
|
|
45
|
+
expect(w.text()).toContain('Ada Lovelace')
|
|
46
|
+
w.unmount()
|
|
47
|
+
})
|
|
48
|
+
})
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref, withDirectives } from 'vue'
|
|
4
|
+
import { vStateLayer, type StateLayerValue } from '../directives/vStateLayer'
|
|
5
|
+
|
|
6
|
+
function host(value: () => StateLayerValue, children?: () => unknown) {
|
|
7
|
+
return mount(defineComponent({
|
|
8
|
+
setup() {
|
|
9
|
+
return () => withDirectives(h('div', { class: 'host' }, children?.() as never), [[vStateLayer, value()]])
|
|
10
|
+
},
|
|
11
|
+
}), { attachTo: document.body })
|
|
12
|
+
}
|
|
13
|
+
const layerOf = (el: Element) => el.querySelector<HTMLElement>(':scope > .m3-state-layer')
|
|
14
|
+
|
|
15
|
+
describe('vStateLayer', () => {
|
|
16
|
+
it('adds a hidden layer and makes a static host positioned', () => {
|
|
17
|
+
const w = host(() => undefined)
|
|
18
|
+
const el = w.element as HTMLElement
|
|
19
|
+
expect(layerOf(el)).not.toBeNull()
|
|
20
|
+
expect(layerOf(el)!.getAttribute('aria-hidden')).toBe('true')
|
|
21
|
+
expect(el.dataset.m3StateLayer).toBe('')
|
|
22
|
+
expect(el.style.position).toBe('relative')
|
|
23
|
+
w.unmount()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('follows its value: off, a color, dragged', async () => {
|
|
27
|
+
const value = ref<StateLayerValue>(false)
|
|
28
|
+
const w = host(() => value.value)
|
|
29
|
+
const el = w.element as HTMLElement
|
|
30
|
+
expect(el.dataset.m3StateLayer).toBe('off')
|
|
31
|
+
value.value = '#e91e63'
|
|
32
|
+
await nextTick()
|
|
33
|
+
expect(el.dataset.m3StateLayer).toBe('')
|
|
34
|
+
expect(layerOf(el)!.style.background).toContain('#e91e63')
|
|
35
|
+
value.value = { dragged: true }
|
|
36
|
+
await nextTick()
|
|
37
|
+
expect(el.dataset.m3StateLayer).toBe('dragged')
|
|
38
|
+
expect(layerOf(el)!.style.background).toBe('')
|
|
39
|
+
w.unmount()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('keeps one layer across re-renders of its children, and removes it on unmount', async () => {
|
|
43
|
+
const items = ref(['a'])
|
|
44
|
+
const w = host(() => true, () => items.value.map((t) => h('span', { key: t }, t)))
|
|
45
|
+
const el = w.element as HTMLElement
|
|
46
|
+
items.value = ['a', 'b', 'c']
|
|
47
|
+
await nextTick()
|
|
48
|
+
expect(el.querySelectorAll('.m3-state-layer')).toHaveLength(1)
|
|
49
|
+
w.unmount()
|
|
50
|
+
expect(el.querySelector('.m3-state-layer')).toBeNull()
|
|
51
|
+
expect(el.dataset.m3StateLayer).toBeUndefined()
|
|
52
|
+
})
|
|
53
|
+
})
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref, withDirectives } from 'vue'
|
|
4
|
+
import { vSwipe, type SwipeValue } from '../directives/vSwipe'
|
|
5
|
+
|
|
6
|
+
function host(value: () => SwipeValue, onClick = vi.fn()) {
|
|
7
|
+
const w = mount(defineComponent({
|
|
8
|
+
setup: () => () => withDirectives(h('div', { onClick }), [[vSwipe, value()]]),
|
|
9
|
+
}), { attachTo: document.body })
|
|
10
|
+
return { w, el: w.element as HTMLElement, onClick }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Moves from (sx, sy) by (dx, dy) in `steps` events `msPerStep` apart, then lifts
|
|
14
|
+
function drag(el: HTMLElement, dx: number, dy: number, { steps = 5, msPerStep = 16, pointerType = 'touch', sx = 100, sy = 100 } = {}) {
|
|
15
|
+
let t = 1000
|
|
16
|
+
// happy-dom stamps events with its own clock: pin timeStamp so the speed is what the test says
|
|
17
|
+
const ev = (type: string, x: number, y: number) => {
|
|
18
|
+
const e = new PointerEvent(type, { pointerId: 1, pointerType, button: 0, clientX: x, clientY: y, bubbles: true })
|
|
19
|
+
Object.defineProperty(e, 'timeStamp', { value: t })
|
|
20
|
+
return e
|
|
21
|
+
}
|
|
22
|
+
el.dispatchEvent(ev('pointerdown', sx, sy))
|
|
23
|
+
for (let i = 1; i <= steps; i++) {
|
|
24
|
+
t += msPerStep
|
|
25
|
+
window.dispatchEvent(ev('pointermove', sx + (dx * i) / steps, sy + (dy * i) / steps))
|
|
26
|
+
}
|
|
27
|
+
window.dispatchEvent(ev('pointerup', sx + dx, sy + dy))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('vSwipe', () => {
|
|
31
|
+
it('calls the handler of the direction swiped, with the distance', () => {
|
|
32
|
+
const left = vi.fn()
|
|
33
|
+
const right = vi.fn()
|
|
34
|
+
const { el } = host(() => ({ left, right }))
|
|
35
|
+
drag(el, -80, 5)
|
|
36
|
+
expect(left).toHaveBeenCalledTimes(1)
|
|
37
|
+
expect(left.mock.calls[0]![0]).toMatchObject({ direction: 'left', dx: -80, dy: 5 })
|
|
38
|
+
drag(el, 80, 0)
|
|
39
|
+
expect(right).toHaveBeenCalledTimes(1)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('counts a short flick but not a short slow drag', () => {
|
|
43
|
+
const handler = vi.fn()
|
|
44
|
+
const { el } = host(() => handler)
|
|
45
|
+
drag(el, 0, -30, { steps: 3, msPerStep: 200 })
|
|
46
|
+
expect(handler).not.toHaveBeenCalled()
|
|
47
|
+
drag(el, 0, -30, { steps: 3, msPerStep: 10 })
|
|
48
|
+
expect(handler).toHaveBeenCalledTimes(1)
|
|
49
|
+
expect(handler.mock.calls[0]![0].direction).toBe('up')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('sets touch-action from the directions listened to', async () => {
|
|
53
|
+
const value = ref<SwipeValue>({ left: () => {} })
|
|
54
|
+
const { el } = host(() => value.value)
|
|
55
|
+
expect(el.style.touchAction).toBe('pan-y')
|
|
56
|
+
value.value = { down: () => {} }
|
|
57
|
+
await nextTick()
|
|
58
|
+
expect(el.style.touchAction).toBe('pan-x')
|
|
59
|
+
value.value = () => {}
|
|
60
|
+
await nextTick()
|
|
61
|
+
expect(el.style.touchAction).toBe('none')
|
|
62
|
+
value.value = { left: () => {}, disabled: true }
|
|
63
|
+
await nextTick()
|
|
64
|
+
expect(el.style.touchAction).toBe('')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('ignores a drag along an axis nobody listens to, and the mouse unless asked', () => {
|
|
68
|
+
const left = vi.fn()
|
|
69
|
+
const onMove = vi.fn()
|
|
70
|
+
const { el } = host(() => ({ left, onMove }))
|
|
71
|
+
drag(el, -10, -120)
|
|
72
|
+
expect(left).not.toHaveBeenCalled()
|
|
73
|
+
expect(onMove).not.toHaveBeenCalled()
|
|
74
|
+
drag(el, -120, 0, { pointerType: 'mouse' })
|
|
75
|
+
expect(left).not.toHaveBeenCalled()
|
|
76
|
+
const withMouse = host(() => ({ left, mouse: true }))
|
|
77
|
+
drag(withMouse.el, -120, 0, { pointerType: 'mouse' })
|
|
78
|
+
expect(left).toHaveBeenCalledTimes(1)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('reports moves and the end, and swallows the click a swipe ends in', () => {
|
|
82
|
+
const onMove = vi.fn()
|
|
83
|
+
const onEnd = vi.fn()
|
|
84
|
+
const { el, onClick } = host(() => ({ right: () => {}, onMove, onEnd }), vi.fn())
|
|
85
|
+
drag(el, 30, 0, { msPerStep: 200 })
|
|
86
|
+
expect(onMove).toHaveBeenLastCalledWith(30, 0, expect.any(PointerEvent))
|
|
87
|
+
expect(onEnd).toHaveBeenCalledWith(false)
|
|
88
|
+
el.click()
|
|
89
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
90
|
+
el.click()
|
|
91
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
92
|
+
})
|
|
93
|
+
})
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
|
+
import { defineComponent, h, nextTick, ref, withDirectives } from 'vue'
|
|
3
|
+
import { mount } from '@vue/test-utils'
|
|
4
|
+
import { vTooltip, type TooltipValue } from '../directives/vTooltip'
|
|
5
|
+
|
|
6
|
+
// A closing tooltip fades out before it's removed: the open one is the one the element points to
|
|
7
|
+
const shown = (el: Element) => {
|
|
8
|
+
const id = el.getAttribute('aria-describedby')
|
|
9
|
+
return id ? document.getElementById(id) : null
|
|
10
|
+
}
|
|
11
|
+
const pointer = (type: string, pointerType: string, x = 10) =>
|
|
12
|
+
new PointerEvent(type, { pointerType, pointerId: 1, clientX: x, clientY: 10, bubbles: true })
|
|
13
|
+
|
|
14
|
+
describe('vTooltip', () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
document.body.innerHTML = ''
|
|
17
|
+
vi.useFakeTimers()
|
|
18
|
+
})
|
|
19
|
+
afterEach(() => vi.useRealTimers())
|
|
20
|
+
|
|
21
|
+
function host(value: () => TooltipValue, onClick = vi.fn()) {
|
|
22
|
+
const w = mount(defineComponent({
|
|
23
|
+
setup: () => () => withDirectives(h('button', { class: 'btn', onClick }, 'Save'), [[vTooltip, value()]]),
|
|
24
|
+
}), { attachTo: document.body })
|
|
25
|
+
return { w, el: w.element as HTMLElement, onClick }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
it('shows the text on hover after the delay, described by it, and hides on leave', () => {
|
|
29
|
+
const { el } = host(() => 'Save changes')
|
|
30
|
+
el.dispatchEvent(pointer('pointerenter', 'mouse'))
|
|
31
|
+
vi.advanceTimersByTime(599)
|
|
32
|
+
expect(shown(el)).toBeNull()
|
|
33
|
+
vi.advanceTimersByTime(1)
|
|
34
|
+
const tip = shown(el)!
|
|
35
|
+
expect(tip.getAttribute('role')).toBe('tooltip')
|
|
36
|
+
expect(tip.textContent).toBe('Save changes')
|
|
37
|
+
el.dispatchEvent(pointer('pointerleave', 'mouse'))
|
|
38
|
+
expect(el.hasAttribute('aria-describedby')).toBe(false)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('takes options, and shows nothing when disabled or empty', () => {
|
|
42
|
+
const { el } = host(() => ({ text: 'Later', delay: 100, placement: 'bottom' }))
|
|
43
|
+
el.dispatchEvent(pointer('pointerenter', 'mouse'))
|
|
44
|
+
vi.advanceTimersByTime(100)
|
|
45
|
+
expect(shown(el)?.textContent).toBe('Later')
|
|
46
|
+
|
|
47
|
+
const off = host(() => ({ text: 'Nope', disabled: true }))
|
|
48
|
+
off.el.dispatchEvent(pointer('pointerenter', 'mouse'))
|
|
49
|
+
vi.advanceTimersByTime(600)
|
|
50
|
+
expect(shown(off.el)).toBeNull()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('a long press shows it and swallows its click; a tap clicks', async () => {
|
|
54
|
+
const { el, onClick } = host(() => 'Save')
|
|
55
|
+
el.dispatchEvent(pointer('pointerdown', 'touch'))
|
|
56
|
+
window.dispatchEvent(pointer('pointerup', 'touch'))
|
|
57
|
+
el.click()
|
|
58
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
59
|
+
expect(shown(el)).toBeNull()
|
|
60
|
+
|
|
61
|
+
el.dispatchEvent(pointer('pointerdown', 'touch'))
|
|
62
|
+
vi.advanceTimersByTime(500)
|
|
63
|
+
expect(shown(el)?.textContent).toBe('Save')
|
|
64
|
+
window.dispatchEvent(pointer('pointerup', 'touch'))
|
|
65
|
+
el.click()
|
|
66
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
67
|
+
vi.advanceTimersByTime(1500)
|
|
68
|
+
expect(shown(el)).toBeNull()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('follows a new text while shown, hides when it empties, and cleans up on unmount', async () => {
|
|
72
|
+
const text = ref('One')
|
|
73
|
+
const { w, el } = host(() => text.value)
|
|
74
|
+
el.dispatchEvent(pointer('pointerenter', 'mouse'))
|
|
75
|
+
vi.advanceTimersByTime(600)
|
|
76
|
+
text.value = 'Two'
|
|
77
|
+
await nextTick()
|
|
78
|
+
expect(shown(el)?.textContent).toBe('Two')
|
|
79
|
+
text.value = ''
|
|
80
|
+
await nextTick()
|
|
81
|
+
expect(shown(el)).toBeNull()
|
|
82
|
+
el.dispatchEvent(pointer('pointerenter', 'mouse'))
|
|
83
|
+
vi.advanceTimersByTime(600)
|
|
84
|
+
w.unmount()
|
|
85
|
+
expect(document.querySelector('[role="tooltip"]')).toBeNull()
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('Escape hides it', () => {
|
|
89
|
+
const { el } = host(() => 'Save')
|
|
90
|
+
el.dispatchEvent(pointer('pointerenter', 'mouse'))
|
|
91
|
+
vi.advanceTimersByTime(600)
|
|
92
|
+
el.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
|
|
93
|
+
expect(shown(el)).toBeNull()
|
|
94
|
+
})
|
|
95
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { describe, it, expect } from 'vitest'
|
|
3
|
+
import { viewportFromHeaders, VIEWPORT_HINTS } from '../composables/viewportHints'
|
|
4
|
+
|
|
5
|
+
const IPHONE = 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1'
|
|
6
|
+
const ANDROID_PHONE = 'Mozilla/5.0 (Linux; Android 15; Pixel 9) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0 Mobile Safari/537.36'
|
|
7
|
+
const ANDROID_TABLET = 'Mozilla/5.0 (Linux; Android 15; SM-X910) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0 Safari/537.36'
|
|
8
|
+
const FIREFOX_DESKTOP = 'Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0'
|
|
9
|
+
|
|
10
|
+
describe('viewportFromHeaders', () => {
|
|
11
|
+
it('prefers the cookie, then the viewport hints', () => {
|
|
12
|
+
expect(viewportFromHeaders({ cookie: 'a=1; m3-viewport=1440x900', 'sec-ch-viewport-width': '390', 'user-agent': IPHONE }))
|
|
13
|
+
.toEqual({ width: 1440, height: 900 })
|
|
14
|
+
expect(viewportFromHeaders({ 'sec-ch-viewport-width': '390', 'sec-ch-viewport-height': '844', 'user-agent': FIREFOX_DESKTOP }))
|
|
15
|
+
.toEqual({ width: 390, height: 844 })
|
|
16
|
+
// Only the width (older Chromium): a height in proportion
|
|
17
|
+
expect(viewportFromHeaders({ 'Sec-CH-Viewport-Width': '1600' })).toEqual({ width: 1600, height: 1000 })
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('guesses the kind of device on a first visit', () => {
|
|
21
|
+
expect(viewportFromHeaders({ 'user-agent': IPHONE })!.width).toBeLessThan(600)
|
|
22
|
+
expect(viewportFromHeaders({ 'user-agent': ANDROID_PHONE })!.width).toBeLessThan(600)
|
|
23
|
+
const tablet = viewportFromHeaders({ 'user-agent': ANDROID_TABLET })!.width
|
|
24
|
+
expect(tablet).toBeGreaterThanOrEqual(600)
|
|
25
|
+
expect(tablet).toBeLessThan(840)
|
|
26
|
+
expect(viewportFromHeaders({ 'user-agent': FIREFOX_DESKTOP })!.width).toBeGreaterThanOrEqual(1200)
|
|
27
|
+
// Chromium's mobile hint, with a user agent that doesn't say
|
|
28
|
+
expect(viewportFromHeaders({ 'sec-ch-ua-mobile': '?1', 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K)' })!.width).toBeLessThan(600)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('takes a Headers object, ignores bad values, and can skip the guess', () => {
|
|
32
|
+
expect(viewportFromHeaders(new Headers({ cookie: 'm3-viewport=800x600' }))).toEqual({ width: 800, height: 600 })
|
|
33
|
+
expect(viewportFromHeaders({ cookie: 'm3-viewport=wide', 'user-agent': FIREFOX_DESKTOP })!.width).toBe(1280)
|
|
34
|
+
expect(viewportFromHeaders({ 'user-agent': IPHONE }, { guess: false })).toBeUndefined()
|
|
35
|
+
expect(viewportFromHeaders({})).toBeUndefined()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('names the hints for Accept-CH', () => {
|
|
39
|
+
expect(VIEWPORT_HINTS).toBe('Sec-CH-Viewport-Width, Sec-CH-Viewport-Height')
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -22,7 +22,9 @@ const props = withDefaults(
|
|
|
22
22
|
/**
|
|
23
23
|
* Intl options for the type: `{ style: 'currency', currency: 'EUR' }`, `{ style: 'percent' }`,
|
|
24
24
|
* `{ style: 'unit', unit: 'kilometer-per-hour' }`, `{ notation: 'compact' }` for numbers; `{ timeStyle: 'medium' }`
|
|
25
|
-
* (the default), `{ hour: '2-digit', minute: '2-digit' }`, `{ dateStyle: 'short' }` for times. Unused for durations
|
|
25
|
+
* (the default), `{ hour: '2-digit', minute: '2-digit' }`, `{ dateStyle: 'short' }` for times. Unused for durations.
|
|
26
|
+
* Dollar-sign currencies show their country (`AR$`, `MX$`, `US$`) in any language; set `currencyDisplay` for
|
|
27
|
+
* Intl's own output (`'symbol'` gives the local peso as a plain `$`)
|
|
26
28
|
*/
|
|
27
29
|
format?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions
|
|
28
30
|
/** BCP-47 language for the format (`es-AR` for Argentine pesos and separators); defaults to the app's locale */
|
|
@@ -64,7 +66,18 @@ const parts = computed<Part[]>(() => {
|
|
|
64
66
|
const options = (props.format as Intl.DateTimeFormatOptions | undefined) ?? { timeStyle: 'medium' }
|
|
65
67
|
return new Intl.DateTimeFormat(lang.value, options).formatToParts(numeric.value)
|
|
66
68
|
}
|
|
67
|
-
|
|
69
|
+
const format = props.format as Intl.NumberFormatOptions | undefined
|
|
70
|
+
const out = new Intl.NumberFormat(lang.value, format).formatToParts(numeric.value)
|
|
71
|
+
if (format?.style !== 'currency' || format.currencyDisplay || !format.currency) return out
|
|
72
|
+
// Intl writes a plain "$" (the local peso, US dollars in the US) or a code (MXN in Argentina) for many currencies:
|
|
73
|
+
// give the dollar-sign ones their country instead (AR$, MX$, US$), with the language's spacing for a symbol.
|
|
74
|
+
// Symbols that already say which currency they are (US$, MX$, €, R$, ¥) stay as Intl writes them.
|
|
75
|
+
const code = format.currency.toUpperCase()
|
|
76
|
+
const symbol = out.find((p) => p.type === 'currency')?.value
|
|
77
|
+
if (symbol !== '$' && symbol !== code) return out
|
|
78
|
+
const narrow = new Intl.NumberFormat(lang.value, { ...format, currencyDisplay: 'narrowSymbol' }).formatToParts(numeric.value)
|
|
79
|
+
for (const p of narrow) if (p.type === 'currency' && p.value === '$') p.value = code === 'TWD' ? 'NT$' : `${code.slice(0, 2)}$`
|
|
80
|
+
return narrow
|
|
68
81
|
})
|
|
69
82
|
const text = computed(() => parts.value.map((p) => p.value).join(''))
|
|
70
83
|
|
|
@@ -117,7 +130,7 @@ const cells = computed<Cell[]>(() => {
|
|
|
117
130
|
})
|
|
118
131
|
|
|
119
132
|
// ── Rolling: one spring per digit column, stepped in a rAF loop and written to its strip's transform ─────────
|
|
120
|
-
interface Column { pos: number; vel: number; target: number; base: number; el?: HTMLElement }
|
|
133
|
+
interface Column { pos: number; vel: number; target: number; base: number; el?: HTMLElement; rolling?: boolean }
|
|
121
134
|
const columns = new Map<string, Column>()
|
|
122
135
|
let mounted = false
|
|
123
136
|
let raf = 0
|
|
@@ -129,8 +142,13 @@ const mod = (n: number, base: number) => ((n % base) + base) % base
|
|
|
129
142
|
const write = (c: Column) => {
|
|
130
143
|
if (!c.el) return
|
|
131
144
|
c.el.style.transform = `translateY(${-mod(c.pos, c.base)}lh)`
|
|
132
|
-
// Unmasked a little before landing, so the mask eases out with the last of the roll
|
|
133
|
-
|
|
145
|
+
// Unmasked a little before landing, so the mask eases out with the last of the roll. Only touched when it changes:
|
|
146
|
+
// an attribute write every frame restyles the column every frame
|
|
147
|
+
const rolling = Math.abs(c.pos - c.target) > 0.15
|
|
148
|
+
if (rolling !== c.rolling) {
|
|
149
|
+
c.rolling = rolling
|
|
150
|
+
c.el.parentElement?.toggleAttribute('data-rolling', rolling)
|
|
151
|
+
}
|
|
134
152
|
}
|
|
135
153
|
|
|
136
154
|
// The strip's starting transform, set once per column, so the server renders the right digits. Vue may write it
|
|
@@ -149,7 +167,11 @@ function initialStyle(cell: Cell) {
|
|
|
149
167
|
}
|
|
150
168
|
const setStrip = (key: string) => (el: unknown) => {
|
|
151
169
|
const c = columns.get(key)
|
|
152
|
-
if (c)
|
|
170
|
+
if (!c) return
|
|
171
|
+
const next = (el as HTMLElement | null) ?? undefined
|
|
172
|
+
// A new element doesn't carry the old one's data-rolling
|
|
173
|
+
if (next !== c.el) c.rolling = undefined
|
|
174
|
+
c.el = next
|
|
153
175
|
}
|
|
154
176
|
// Two runs of the column's digits, so a digit rolling past the last shows the first coming in below it seamlessly
|
|
155
177
|
const strip = (base: number) => Array.from({ length: base * 2 }, (_, i) => i % base)
|
|
@@ -275,6 +297,10 @@ onUnmounted(() => cancelAnimationFrame(raf))
|
|
|
275
297
|
mask-size: 100% 100%;
|
|
276
298
|
transition-duration: 120ms;
|
|
277
299
|
}
|
|
300
|
+
/* Its own layer while it rolls, so moving it doesn't repaint the column */
|
|
301
|
+
.m3-anum-digit[data-rolling] > .m3-anum-strip {
|
|
302
|
+
will-change: transform;
|
|
303
|
+
}
|
|
278
304
|
.m3-anum-strip {
|
|
279
305
|
display: flex;
|
|
280
306
|
flex-direction: column;
|
|
@@ -13,6 +13,7 @@ import { useLocale } from '../composables/useLocale'
|
|
|
13
13
|
import { useDebounce } from '../composables/useDebounce'
|
|
14
14
|
import type { SelectOption } from './MSelect.vue'
|
|
15
15
|
import { useScrollLock } from '../composables/_useScrollLock'
|
|
16
|
+
import { useEscapeStack } from '../composables/_useEscapeStack'
|
|
16
17
|
|
|
17
18
|
// Root is a fragment (field div + a sibling Teleport for the dropdown panel), so Vue can't
|
|
18
19
|
// auto-apply a consumer's class/attrs to either one — forward them onto the field div below.
|
|
@@ -174,6 +175,7 @@ function select(opt: SelectOption) {
|
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
useScrollLock(modalOpen)
|
|
178
|
+
useEscapeStack(modalOpen, closeDropdown)
|
|
177
179
|
|
|
178
180
|
function onInputFocus() {
|
|
179
181
|
search.value = ''
|
|
@@ -208,6 +210,9 @@ function onScroll(e: Event) {
|
|
|
208
210
|
|
|
209
211
|
function onKeydown(e: KeyboardEvent) {
|
|
210
212
|
if (e.key === 'Escape') {
|
|
213
|
+
// Closing the list uses the key: keep it from also closing a dialog around the field. With nothing open it
|
|
214
|
+
// only leaves the field and passes on
|
|
215
|
+
if (open.value || modalOpen.value) e.stopPropagation()
|
|
211
216
|
closeDropdown()
|
|
212
217
|
inputEl.value?.blur()
|
|
213
218
|
return
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @slot default Sheet body content (scrollable)
|
|
9
9
|
* @slot actions Footer action buttons, shown in a bordered strip below the content
|
|
10
|
-
* @event update:modelValue Emitted when the sheet closes (scrim click, drag-to-dismiss, or the close button) —
|
|
10
|
+
* @event update:modelValue Emitted when the sheet closes (scrim click, drag-to-dismiss, Escape, or the close button) —
|
|
11
11
|
* powers v-model
|
|
12
12
|
* @event update:expanded Emitted when the sheet moves between partially and fully expanded (or closes) —
|
|
13
13
|
* powers v-model:expanded
|
|
@@ -16,6 +16,7 @@ import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
|
16
16
|
import MIcon from './MIcon.vue'
|
|
17
17
|
import { useLocale } from '../composables/useLocale'
|
|
18
18
|
import { useSheetMotion } from '../composables/_useSheetMotion'
|
|
19
|
+
import { useEscapeStack } from '../composables/_useEscapeStack'
|
|
19
20
|
|
|
20
21
|
const props = withDefaults(defineProps<{
|
|
21
22
|
/** Open/closed state (v-model) */
|
|
@@ -42,6 +43,8 @@ const props = withDefaults(defineProps<{
|
|
|
42
43
|
|
|
43
44
|
const emit = defineEmits<{ 'update:modelValue': [boolean]; 'update:expanded': [boolean] }>()
|
|
44
45
|
const close = () => emit('update:modelValue', false)
|
|
46
|
+
// Modal: Escape closes it, through the library's stack (a dialog or menu over it takes it first)
|
|
47
|
+
useEscapeStack(() => props.modelValue, close)
|
|
45
48
|
const locale = useLocale()
|
|
46
49
|
|
|
47
50
|
// Only the safe area is kept clear at the top, like the status bar inset in Compose
|