@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.
Files changed (236) hide show
  1. package/README.md +1 -1
  2. package/dist/API.md +579 -40
  3. package/dist/MMenuItem-DI351kIf.js +929 -0
  4. package/dist/MMenuItem-DI351kIf.js.map +1 -0
  5. package/dist/MSlider-BnEy5ieZ.js +1500 -0
  6. package/dist/MSlider-BnEy5ieZ.js.map +1 -0
  7. package/dist/MTextField-BBmkaIbO.js +633 -0
  8. package/dist/MTextField-BBmkaIbO.js.map +1 -0
  9. package/dist/api.json +1 -1
  10. package/dist/chart.js +83 -49
  11. package/dist/chart.js.map +1 -1
  12. package/dist/code-editor.js +1 -1
  13. package/dist/components/MAnimatedNumber.vue.d.ts +3 -1
  14. package/dist/components/MButton.vue.d.ts +9 -1
  15. package/dist/components/MButtonGroup.vue.d.ts +40 -31
  16. package/dist/components/MCarousel.vue.d.ts +2 -0
  17. package/dist/components/MChart.vue.d.ts +6 -0
  18. package/dist/components/MCircleProgressBar.vue.d.ts +5 -3
  19. package/dist/components/MContainerTransform.vue.d.ts +59 -0
  20. package/dist/components/MContextMenu.vue.d.ts +2 -2
  21. package/dist/components/MCopyButton.vue.d.ts +1 -1
  22. package/dist/components/MDialog.vue.d.ts +8 -5
  23. package/dist/components/MExportButton.vue.d.ts +1 -1
  24. package/dist/components/MFab.vue.d.ts +2 -2
  25. package/dist/components/MFabMenu.vue.d.ts +1 -1
  26. package/dist/components/MFlex.vue.d.ts +1 -1
  27. package/dist/components/MIconButton.vue.d.ts +15 -1
  28. package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
  29. package/dist/components/MListItem.vue.d.ts +5 -5
  30. package/dist/components/MMap.vue.d.ts +20 -2
  31. package/dist/components/MMapBaseLayers.vue.d.ts +3 -0
  32. package/dist/components/MMapFilter.vue.d.ts +3 -0
  33. package/dist/components/MMapLayers.vue.d.ts +3 -0
  34. package/dist/components/MMenu.vue.d.ts +2 -2
  35. package/dist/components/MMenuItem.vue.d.ts +7 -3
  36. package/dist/components/MNavigationDrawer.vue.d.ts +13 -2
  37. package/dist/components/MNavigationRail.vue.d.ts +1 -1
  38. package/dist/components/MOverlay.vue.d.ts +12 -1
  39. package/dist/components/MProgressBar.vue.d.ts +5 -3
  40. package/dist/components/MPullToRefresh.vue.d.ts +7 -2
  41. package/dist/components/MRichTextEditor.vue.d.ts +7 -1
  42. package/dist/components/MSearchField.vue.d.ts +58 -0
  43. package/dist/components/MSegmentedButton.vue.d.ts +31 -23
  44. package/dist/components/MSimpleCarousel.vue.d.ts +2 -0
  45. package/dist/components/MSkeleton.vue.d.ts +6 -3
  46. package/dist/components/MSplitter.vue.d.ts +1 -1
  47. package/dist/components/MStack.vue.d.ts +1 -1
  48. package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
  49. package/dist/components/MSwitch.vue.d.ts +1 -1
  50. package/dist/components/MTextField.vue.d.ts +5 -1
  51. package/dist/components/MTimeline.vue.d.ts +85 -22
  52. package/dist/components/MToolbar.vue.d.ts +32 -5
  53. package/dist/components/MTooltip.vue.d.ts +1 -1
  54. package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
  55. package/dist/components/_MToolbarFab.vue.d.ts +16 -0
  56. package/dist/composables/_containerTransform.d.ts +48 -0
  57. package/dist/composables/_mapStyle.d.ts +13 -0
  58. package/dist/composables/_themeTransition.d.ts +2 -0
  59. package/dist/composables/_tooltipTrigger.d.ts +22 -0
  60. package/dist/composables/_useMenuNav.d.ts +28 -0
  61. package/dist/composables/useAutoGrow.d.ts +21 -0
  62. package/dist/composables/useColorPalette.d.ts +1 -1
  63. package/dist/composables/useContainerTransform.d.ts +30 -0
  64. package/dist/composables/useLocale.d.ts +6 -0
  65. package/dist/composables/useMap.d.ts +19 -3
  66. package/dist/composables/useMapFilter.d.ts +4 -1
  67. package/dist/composables/useMapLayers.d.ts +5 -2
  68. package/dist/composables/useScrollReveal.d.ts +44 -0
  69. package/dist/composables/useThemeTokens.d.ts +21 -0
  70. package/dist/composables/viewportHints.d.ts +27 -0
  71. package/dist/directives/vClickOutside.d.ts +25 -0
  72. package/dist/directives/vFocusRing.d.ts +22 -0
  73. package/dist/directives/vLongPress.d.ts +27 -0
  74. package/dist/directives/vReveal.d.ts +10 -0
  75. package/dist/directives/vScrollElevation.d.ts +31 -0
  76. package/dist/directives/vSkeleton.d.ts +19 -0
  77. package/dist/directives/vStateLayer.d.ts +20 -0
  78. package/dist/directives/vSwipe.d.ts +45 -0
  79. package/dist/directives/vTooltip.d.ts +23 -0
  80. package/dist/index.d.ts +31 -1
  81. package/dist/locales/index.js +35 -7
  82. package/dist/locales/index.js.map +1 -1
  83. package/dist/m3ui-vue.css +1 -1
  84. package/dist/m3ui.js +7692 -6273
  85. package/dist/m3ui.js.map +1 -1
  86. package/dist/map.d.ts +1 -1
  87. package/dist/map.js +823 -793
  88. package/dist/map.js.map +1 -1
  89. package/dist/motion-DZiXG09o.js +150 -0
  90. package/dist/motion-DZiXG09o.js.map +1 -0
  91. package/dist/plugin.d.ts +24 -0
  92. package/dist/rich-text-editor.js +20 -16
  93. package/dist/rich-text-editor.js.map +1 -1
  94. package/dist/styles/theme.css +63 -0
  95. package/dist/styles.css +1 -1
  96. package/dist/{useLocale-SfQHnJfp.js → useLocale-JYxDDeXC.js} +6 -2
  97. package/dist/useLocale-JYxDDeXC.js.map +1 -0
  98. package/dist/useThemeTokens-Bv-Uv8eX.js +135 -0
  99. package/dist/useThemeTokens-Bv-Uv8eX.js.map +1 -0
  100. package/package.json +2 -1
  101. package/src/__tests__/MAnimatedNumber.test.ts +24 -2
  102. package/src/__tests__/MButton.test.ts +22 -0
  103. package/src/__tests__/MCarousel.test.ts +9 -0
  104. package/src/__tests__/MChart.test.ts +77 -5
  105. package/src/__tests__/MContainerTransform.test.ts +279 -0
  106. package/src/__tests__/MDialog.test.ts +27 -0
  107. package/src/__tests__/MIconButton.test.ts +33 -0
  108. package/src/__tests__/MListItemExpandable.test.ts +48 -0
  109. package/src/__tests__/MListItemShape.test.ts +9 -6
  110. package/src/__tests__/MListKeyboard.test.ts +90 -0
  111. package/src/__tests__/MMap.test.ts +53 -1
  112. package/src/__tests__/MMapLayers.test.ts +46 -2
  113. package/src/__tests__/MMapTools.test.ts +2 -1
  114. package/src/__tests__/MMenu.test.ts +104 -1
  115. package/src/__tests__/MMenuItem.test.ts +18 -0
  116. package/src/__tests__/MNavigationDrawer.test.ts +80 -0
  117. package/src/__tests__/MNavigationRail.test.ts +33 -0
  118. package/src/__tests__/MOverlay.test.ts +49 -0
  119. package/src/__tests__/MProgressBar.test.ts +41 -0
  120. package/src/__tests__/MPullToRefresh.test.ts +33 -0
  121. package/src/__tests__/MRichTextEditor.test.ts +22 -0
  122. package/src/__tests__/MSearchField.test.ts +71 -0
  123. package/src/__tests__/MSkeleton.test.ts +38 -0
  124. package/src/__tests__/MSlider.test.ts +161 -0
  125. package/src/__tests__/MTimeline.test.ts +238 -0
  126. package/src/__tests__/MToolbar.test.ts +157 -0
  127. package/src/__tests__/_fakeMaplibre.ts +3 -1
  128. package/src/__tests__/attrsFallthrough.test.ts +9 -0
  129. package/src/__tests__/escapeStack.test.ts +93 -0
  130. package/src/__tests__/hydration.test.ts +25 -0
  131. package/src/__tests__/ssr.test.ts +21 -2
  132. package/src/__tests__/useAutoGrow.test.ts +103 -0
  133. package/src/__tests__/useScrollReveal.test.ts +102 -0
  134. package/src/__tests__/useThemeTokens.test.ts +114 -0
  135. package/src/__tests__/vClickOutside.test.ts +82 -0
  136. package/src/__tests__/vFocusRing.test.ts +36 -0
  137. package/src/__tests__/vLongPress.test.ts +81 -0
  138. package/src/__tests__/vScrollElevation.test.ts +89 -0
  139. package/src/__tests__/vSkeleton.test.ts +48 -0
  140. package/src/__tests__/vStateLayer.test.ts +53 -0
  141. package/src/__tests__/vSwipe.test.ts +93 -0
  142. package/src/__tests__/vTooltip.test.ts +95 -0
  143. package/src/__tests__/viewportHints.test.ts +41 -0
  144. package/src/components/MAnimatedNumber.vue +32 -6
  145. package/src/components/MAutocomplete.vue +5 -0
  146. package/src/components/MBottomSheet.vue +4 -1
  147. package/src/components/MButton.vue +19 -3
  148. package/src/components/MButtonGroup.vue +22 -17
  149. package/src/components/MCarousel.vue +7 -1
  150. package/src/components/MChart.vue +74 -34
  151. package/src/components/MCircleProgressBar.vue +14 -9
  152. package/src/components/MCommandPalette.vue +3 -2
  153. package/src/components/MContainerTransform.vue +321 -0
  154. package/src/components/MContextMenu.vue +19 -60
  155. package/src/components/MDialog.vue +31 -6
  156. package/src/components/MDragDropList.vue +2 -0
  157. package/src/components/MFab.vue +10 -5
  158. package/src/components/MIconButton.vue +43 -2
  159. package/src/components/MKanban.vue +2 -0
  160. package/src/components/MLightbox.vue +7 -2
  161. package/src/components/MList.vue +26 -2
  162. package/src/components/MListItem.vue +138 -84
  163. package/src/components/MMap.vue +38 -5
  164. package/src/components/MMapBaseLayers.vue +7 -3
  165. package/src/components/MMapFilter.vue +7 -4
  166. package/src/components/MMapGeoJson.vue +1 -1
  167. package/src/components/MMapLayers.vue +6 -2
  168. package/src/components/MMapMeasure.vue +5 -2
  169. package/src/components/MMenu.vue +18 -59
  170. package/src/components/MMenuItem.vue +11 -2
  171. package/src/components/MMultiAutocomplete.vue +5 -0
  172. package/src/components/MNavigationDrawer.vue +96 -11
  173. package/src/components/MNavigationRail.vue +44 -25
  174. package/src/components/MOverlay.vue +32 -13
  175. package/src/components/MProgressBar.vue +25 -27
  176. package/src/components/MPullToRefresh.vue +20 -1
  177. package/src/components/MRichTextEditor.vue +19 -5
  178. package/src/components/MSearchBar.vue +5 -0
  179. package/src/components/MSearchField.vue +142 -0
  180. package/src/components/MSegmentedButton.vue +19 -17
  181. package/src/components/MSelect.vue +10 -1
  182. package/src/components/MSideSheet.vue +5 -2
  183. package/src/components/MSimpleCarousel.vue +10 -1
  184. package/src/components/MSkeleton.vue +30 -8
  185. package/src/components/MSlider.vue +161 -42
  186. package/src/components/MSpotlightSearch.vue +3 -2
  187. package/src/components/MTextField.vue +15 -2
  188. package/src/components/MTimeline.vue +370 -81
  189. package/src/components/MToolbar.vue +256 -15
  190. package/src/components/MTooltip.vue +20 -152
  191. package/src/components/_MDrawerItemList.vue +25 -6
  192. package/src/components/_MToolbarFab.vue +14 -0
  193. package/src/composables/_containerTransform.ts +179 -0
  194. package/src/composables/_mapStyle.ts +45 -0
  195. package/src/composables/_themeTransition.ts +2 -0
  196. package/src/composables/_tooltipTrigger.ts +184 -0
  197. package/src/composables/_useEscapeStack.ts +2 -0
  198. package/src/composables/_useMenuNav.ts +209 -0
  199. package/src/composables/useAutoGrow.ts +78 -0
  200. package/src/composables/useContainerTransform.ts +59 -0
  201. package/src/composables/useLocale.ts +10 -0
  202. package/src/composables/useMap.ts +43 -5
  203. package/src/composables/useMapFilter.ts +6 -5
  204. package/src/composables/useMapLayers.ts +7 -6
  205. package/src/composables/useScrollReveal.ts +151 -0
  206. package/src/composables/useThemeTokens.ts +116 -0
  207. package/src/composables/viewportHints.ts +80 -0
  208. package/src/directives/vClickOutside.ts +90 -0
  209. package/src/directives/vFocusRing.ts +60 -0
  210. package/src/directives/vLongPress.ts +134 -0
  211. package/src/directives/vReveal.ts +57 -0
  212. package/src/directives/vScrollElevation.ts +116 -0
  213. package/src/directives/vSkeleton.ts +87 -0
  214. package/src/directives/vStateLayer.ts +83 -0
  215. package/src/directives/vSwipe.ts +197 -0
  216. package/src/directives/vTooltip.ts +128 -0
  217. package/src/index.ts +31 -1
  218. package/src/locales/de.ts +4 -0
  219. package/src/locales/es.ts +4 -0
  220. package/src/locales/fr.ts +4 -0
  221. package/src/locales/ja.ts +4 -0
  222. package/src/locales/ko.ts +4 -0
  223. package/src/locales/pt.ts +4 -0
  224. package/src/locales/zh.ts +4 -0
  225. package/src/map.ts +1 -1
  226. package/src/plugin.ts +34 -0
  227. package/src/styles/theme.css +63 -0
  228. package/dist/MMenuItem-BckcR0nW.js +0 -809
  229. package/dist/MMenuItem-BckcR0nW.js.map +0 -1
  230. package/dist/MSlider-LyH_gy8D.js +0 -1411
  231. package/dist/MSlider-LyH_gy8D.js.map +0 -1
  232. package/dist/MTextField-FCPOTB0o.js +0 -672
  233. package/dist/MTextField-FCPOTB0o.js.map +0 -1
  234. package/dist/composables/_useThemeTokens.d.ts +0 -7
  235. package/dist/useLocale-SfQHnJfp.js.map +0 -1
  236. package/src/composables/_useThemeTokens.ts +0 -42
@@ -0,0 +1,161 @@
1
+ import { describe, it, expect, afterEach, beforeAll, afterAll } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import { nextTick } from 'vue'
4
+ import MSlider from '../components/MSlider.vue'
5
+
6
+ let wrapper: VueWrapper | undefined
7
+ afterEach(() => {
8
+ wrapper?.unmount()
9
+ wrapper = undefined
10
+ })
11
+
12
+ // happy-dom has no layout: the slider's track is 880px long (the docs' Volume slider in the bug report)
13
+ const offsetWidth = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetWidth')!
14
+ beforeAll(() => {
15
+ Object.defineProperty(HTMLElement.prototype, 'offsetWidth', {
16
+ configurable: true,
17
+ get(this: HTMLElement) { return this.classList.contains('touch-none') ? 880 : 0 },
18
+ })
19
+ })
20
+ afterAll(() => Object.defineProperty(HTMLElement.prototype, 'offsetWidth', offsetWidth))
21
+
22
+ // The track's pieces (inactive/active) and its end dots, in template order
23
+ const track = (w: VueWrapper) => w.find('.touch-none')
24
+ const bar = (w: VueWrapper) => track(w).element.firstElementChild as HTMLElement
25
+ const pieces = (w: VueWrapper) => [...bar(w).children].filter((c) => !c.classList.contains('rounded-full')) as HTMLElement[]
26
+ const endDot = (w: VueWrapper) => [...bar(w).children].filter((c) => c.classList.contains('rounded-full')).at(-1) as HTMLElement
27
+ const startDot = (w: VueWrapper) => [...bar(w).children].filter((c) => c.classList.contains('rounded-full'))[0] as HTMLElement
28
+
29
+ describe('MSlider', () => {
30
+ it('shows the end dot while there is room for it in the inactive piece', async () => {
31
+ wrapper = mount(MSlider, { props: { modelValue: 90 } })
32
+ await nextTick()
33
+ expect(endDot(wrapper).style.opacity).toBe('1')
34
+ expect(pieces(wrapper)[1]!.style.width).not.toBe('0px')
35
+ })
36
+
37
+ it('hides the end dot once it no longer fits in the inactive piece, instead of leaving it in the thumb gap', async () => {
38
+ // 98 of 880px: an 11.6px piece, shorter than the dot's 12px inset + its radius
39
+ wrapper = mount(MSlider, { props: { modelValue: 98 } })
40
+ await nextTick()
41
+ expect(endDot(wrapper).style.opacity).toBe('0')
42
+ // The piece itself is still longer than its corner, so it stays (Compose draws it too)
43
+ expect(pieces(wrapper)[1]!.style.width).not.toBe('0px')
44
+ })
45
+
46
+ it('drops the inactive piece once it is shorter than its corner, like Compose', async () => {
47
+ // 99: a 3.2px piece
48
+ wrapper = mount(MSlider, { props: { modelValue: 99 } })
49
+ await nextTick()
50
+ expect(pieces(wrapper)[1]!.style.width).toBe('0px')
51
+ expect(endDot(wrapper).style.opacity).toBe('0')
52
+ })
53
+
54
+ it('applies the same to both ends of a range slider', async () => {
55
+ wrapper = mount(MSlider, { props: { variant: 'range', modelValue: [1, 99] } })
56
+ await nextTick()
57
+ const [before, , after] = pieces(wrapper)
58
+ expect(before!.style.width).toBe('0px')
59
+ expect(after!.style.width).toBe('0px')
60
+ expect(startDot(wrapper).style.opacity).toBe('0')
61
+ expect(endDot(wrapper).style.opacity).toBe('0')
62
+ })
63
+
64
+ it('keeps both dots of a range slider away from the ends', async () => {
65
+ wrapper = mount(MSlider, { props: { variant: 'range', modelValue: [20, 80] } })
66
+ await nextTick()
67
+ expect(startDot(wrapper).style.opacity).toBe('1')
68
+ expect(endDot(wrapper).style.opacity).toBe('1')
69
+ })
70
+
71
+ describe('range', () => {
72
+ // The track is 100px long from 0 for the pointer
73
+ const press = async (w: VueWrapper, at: number, moves: number[] = []) => {
74
+ const el = track(w).element as HTMLElement
75
+ el.getBoundingClientRect = () => ({ left: 0, top: 0, width: 100, height: 46, right: 100, bottom: 46, x: 0, y: 0, toJSON() {} })
76
+ el.dispatchEvent(new PointerEvent('pointerdown', { clientX: at, bubbles: true }))
77
+ await nextTick()
78
+ for (const x of moves) {
79
+ window.dispatchEvent(new PointerEvent('pointermove', { clientX: x }))
80
+ await nextTick()
81
+ }
82
+ window.dispatchEvent(new PointerEvent('pointerup', { clientX: moves.at(-1) ?? at }))
83
+ }
84
+ // A v-model the component updates, as a parent would
85
+ const mountRange = (value: [number, number]) => {
86
+ const w = mount(MSlider, {
87
+ props: { variant: 'range', modelValue: value, 'onUpdate:modelValue': (v: unknown) => w.setProps({ modelValue: v as [number, number] }) },
88
+ attachTo: document.body,
89
+ })
90
+ return w
91
+ }
92
+ const last = (w: VueWrapper) => (w.emitted('update:modelValue') as unknown[][]).at(-1)![0]
93
+
94
+ it('moves the end thumb for a press past two overlapping thumbs, keeping the pair ordered', async () => {
95
+ wrapper = mountRange([50, 50])
96
+ await press(wrapper, 70)
97
+ expect(last(wrapper)).toEqual([50, 70])
98
+ await press(wrapper, 30)
99
+ expect(last(wrapper)).toEqual([30, 70])
100
+ })
101
+
102
+ it('picks the thumb by the drag direction on two overlapping thumbs', async () => {
103
+ wrapper = mountRange([50, 50])
104
+ await press(wrapper, 50, [40, 30])
105
+ expect(last(wrapper)).toEqual([30, 50])
106
+ await wrapper.setProps({ modelValue: [50, 50] })
107
+ await press(wrapper, 50, [60, 75])
108
+ expect(last(wrapper)).toEqual([50, 75])
109
+ })
110
+
111
+ it('never lets a dragged thumb pass the other one', async () => {
112
+ wrapper = mountRange([20, 60])
113
+ await press(wrapper, 22, [40, 90])
114
+ expect(last(wrapper)).toEqual([60, 60])
115
+ await wrapper.setProps({ modelValue: [20, 60] })
116
+ await press(wrapper, 58, [10])
117
+ expect(last(wrapper)).toEqual([20, 20])
118
+ })
119
+
120
+ it('makes each thumb a slider of its own, moved by its keys within the other', async () => {
121
+ wrapper = mountRange([20, 60])
122
+ const thumbs = wrapper.findAll('[role=slider]')
123
+ expect(thumbs).toHaveLength(2)
124
+ expect(thumbs.map((t) => t.attributes('aria-label'))).toEqual(['Range start', 'Range end'])
125
+ expect(thumbs[0]!.attributes('aria-valuemax')).toBe('60')
126
+ expect(thumbs[1]!.attributes('aria-valuemin')).toBe('20')
127
+ await thumbs[1]!.trigger('keydown', { key: 'ArrowRight' })
128
+ expect(last(wrapper)).toEqual([20, 61])
129
+ await thumbs[1]!.trigger('keydown', { key: 'Home' })
130
+ expect(last(wrapper)).toEqual([20, 20])
131
+ await thumbs[0]!.trigger('keydown', { key: 'ArrowRight' })
132
+ expect(last(wrapper)).toEqual([20, 20])
133
+ await thumbs[0]!.trigger('keydown', { key: 'Home' })
134
+ expect(last(wrapper)).toEqual([0, 20])
135
+ expect(wrapper.find('[role=group]').exists()).toBe(true)
136
+ })
137
+
138
+ it('rings a thumb focused from the keyboard, not one a press focuses', async () => {
139
+ wrapper = mountRange([20, 60])
140
+ await press(wrapper, 70)
141
+ await nextTick()
142
+ const thumbs = wrapper.findAll('[role=slider]')
143
+ expect(document.activeElement).toBe(thumbs[1]!.element)
144
+ expect(thumbs[1]!.classes()).not.toContain('ring-2')
145
+ // The keys after a press bring the ring back, as browsers do
146
+ await thumbs[1]!.trigger('keydown', { key: 'ArrowLeft' })
147
+ expect(thumbs[1]!.classes()).toContain('ring-2')
148
+ // Tabbing to the other thumb
149
+ ;(thumbs[0]!.element as HTMLElement).focus()
150
+ await nextTick()
151
+ expect(thumbs[0]!.classes()).toContain('ring-2')
152
+ expect(thumbs[1]!.classes()).not.toContain('ring-2')
153
+ })
154
+
155
+ it('rings a thumb in the slider\'s own color', () => {
156
+ wrapper = mount(MSlider, { props: { variant: 'range', modelValue: [20, 60], color: 'tertiary' } })
157
+ const ring = (wrapper.find('[role=slider]').element as HTMLElement).style.getPropertyValue('--tw-ring-color')
158
+ expect(ring).toBe('var(--color-tertiary)')
159
+ })
160
+ })
161
+ })
@@ -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
+ })
@@ -0,0 +1,157 @@
1
+ import { describe, it, expect, afterEach, vi } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import { h, nextTick } from 'vue'
4
+ import MToolbar from '../components/MToolbar.vue'
5
+ import MFab from '../components/MFab.vue'
6
+
7
+ let wrapper: VueWrapper | undefined
8
+ afterEach(() => {
9
+ wrapper?.unmount()
10
+ wrapper = undefined
11
+ vi.restoreAllMocks()
12
+ })
13
+
14
+ // happy-dom has no layout: give the unclipped content natural widths
15
+ function sizes(w: VueWrapper, widths: Record<string, number>) {
16
+ for (const [selector, width] of Object.entries(widths)) {
17
+ const el = w.find(selector).element
18
+ Object.defineProperty(el, 'offsetWidth', { configurable: true, get: () => width })
19
+ }
20
+ }
21
+ const reduceMotion = () =>
22
+ vi.spyOn(window, 'matchMedia').mockImplementation((q: string) => ({ matches: q.includes('reduce'), media: q, addEventListener() {}, removeEventListener() {} }) as unknown as MediaQueryList)
23
+ const button = (text: string) => () => h('button', text)
24
+
25
+ describe('MToolbar', () => {
26
+ it('collapses a floating toolbar without a FAB to its center, closing #leading and #trailing', async () => {
27
+ reduceMotion()
28
+ wrapper = mount(MToolbar, {
29
+ props: { variant: 'floating' },
30
+ slots: { leading: button('back'), default: button('add'), trailing: button('more') },
31
+ })
32
+ const [lead, , trail] = wrapper.findAll('.overflow-hidden, .gap-1.flex-row:not(.shrink-0)').map((x) => x.element as HTMLElement)
33
+ expect(wrapper.text()).toBe('backaddmore')
34
+ expect(lead!.style.width).toBe('')
35
+ await wrapper.setProps({ expanded: false })
36
+ expect(lead!.style.width).toBe('0px')
37
+ expect(trail!.style.width).toBe('0px')
38
+ expect(lead!.hasAttribute('inert')).toBe(true)
39
+ expect(trail!.hasAttribute('inert')).toBe(true)
40
+ // The center stays reachable
41
+ expect(wrapper.findAll('button').filter((b) => !b.element.closest('[inert]')).map((b) => b.text())).toEqual(['add'])
42
+ await wrapper.setProps({ expanded: true })
43
+ expect(lead!.style.width).toBe('')
44
+ expect(lead!.hasAttribute('inert')).toBe(false)
45
+ })
46
+
47
+ it('collapses into its FAB, keeping its footprint, while the FAB grows from 56 to 80px', async () => {
48
+ reduceMotion()
49
+ wrapper = mount(MToolbar, {
50
+ props: { variant: 'floating', fabPosition: 'end' },
51
+ slots: { default: button('add'), fab: () => h(MFab, { icon: 'edit', label: 'Edit' }) },
52
+ })
53
+ sizes(wrapper, { '.w-max': 200 })
54
+ const fabBox = wrapper.find('.absolute').element as HTMLElement
55
+ const body = wrapper.find('.rounded-full.overflow-hidden').element as HTMLElement
56
+ const region = body.parentElement!
57
+ expect(fabBox.style.width).toBe('56px')
58
+ await wrapper.setProps({ expanded: false })
59
+ expect(body.style.width).toBe('0px')
60
+ expect(region.style.width).toBe('200px')
61
+ expect(fabBox.style.width).toBe('80px')
62
+ expect(fabBox.style.height).toBe('80px')
63
+ expect(body.hasAttribute('inert')).toBe(true)
64
+ // The toolbar sizes the FAB, square even with a label (which names it), in the standard toolbar FAB's color
65
+ const fab = wrapper.findComponent(MFab).find('button')
66
+ expect(fab.classes()).toContain('w-full')
67
+ expect(fab.attributes('aria-label')).toBe('Edit')
68
+ expect(fab.text()).toBe('edit')
69
+ expect(fab.classes()).toContain('bg-primary-container')
70
+ await wrapper.setProps({ expanded: true })
71
+ expect(body.style.width).toBe('')
72
+ expect(region.style.width).toBe('')
73
+ expect(fabBox.style.width).toBe('56px')
74
+ })
75
+
76
+ it('gives the FAB of a colored toolbar the vibrant FAB color', () => {
77
+ wrapper = mount(MToolbar, {
78
+ props: { variant: 'floating', fabPosition: 'end', color: 'primary' },
79
+ slots: { default: button('add'), fab: () => h(MFab, { icon: 'edit', label: 'Edit' }) },
80
+ })
81
+ expect(wrapper.findComponent(MFab).find('button').classes()).toContain('bg-tertiary-container')
82
+ })
83
+
84
+ it('springs closed and settles', async () => {
85
+ wrapper = mount(MToolbar, {
86
+ props: { variant: 'floating' },
87
+ slots: { leading: button('back'), default: button('add') },
88
+ })
89
+ sizes(wrapper, { '.pe-1': 96 })
90
+ const lead = wrapper.find('.overflow-hidden').element as HTMLElement
91
+ await wrapper.setProps({ expanded: false })
92
+ await new Promise((r) => setTimeout(r, 120))
93
+ const mid = parseFloat(lead.style.width)
94
+ expect(mid).toBeGreaterThan(-1)
95
+ expect(mid).toBeLessThan(96)
96
+ await new Promise((r) => setTimeout(r, 900))
97
+ expect(lead.style.width).toBe('0px')
98
+ })
99
+
100
+ it('starts collapsed when rendered with expanded false', () => {
101
+ wrapper = mount(MToolbar, {
102
+ props: { variant: 'floating', expanded: false },
103
+ slots: { leading: button('back'), default: button('add') },
104
+ })
105
+ expect((wrapper.find('.overflow-hidden').element as HTMLElement).style.width).toBe('0px')
106
+ })
107
+
108
+ it('collapses on scroll down and expands on scroll up, 40px each way, when asked', async () => {
109
+ reduceMotion()
110
+ const list = document.createElement('div')
111
+ document.body.appendChild(list)
112
+ wrapper = mount(MToolbar, {
113
+ props: { variant: 'floating', collapseOnScroll: list, 'onUpdate:expanded': (v: boolean) => wrapper!.setProps({ expanded: v }) },
114
+ slots: { leading: button('back'), default: button('add') },
115
+ })
116
+ const scrollTo = async (top: number) => {
117
+ list.scrollTop = top
118
+ list.dispatchEvent(new Event('scroll'))
119
+ await nextTick()
120
+ }
121
+ await scrollTo(30)
122
+ expect(wrapper.props('expanded')).toBe(true)
123
+ await scrollTo(50)
124
+ expect(wrapper.props('expanded')).toBe(false)
125
+ // Back up less than 40px: stays collapsed
126
+ await scrollTo(20)
127
+ expect(wrapper.props('expanded')).toBe(false)
128
+ await scrollTo(5)
129
+ expect(wrapper.props('expanded')).toBe(true)
130
+ expect(wrapper.emitted('update:expanded')).toEqual([[false], [true]])
131
+ list.remove()
132
+ })
133
+
134
+ it('does not collapse on scroll unless asked', async () => {
135
+ wrapper = mount(MToolbar, { props: { variant: 'floating' }, slots: { leading: button('back'), default: button('add') } })
136
+ Object.defineProperty(window, 'scrollY', { configurable: true, value: 300 })
137
+ window.dispatchEvent(new Event('scroll'))
138
+ await nextTick()
139
+ expect(wrapper.emitted('update:expanded')).toBeUndefined()
140
+ })
141
+
142
+ it('never collapses a docked toolbar', async () => {
143
+ reduceMotion()
144
+ wrapper = mount(MToolbar, {
145
+ props: { variant: 'docked', expanded: false },
146
+ slots: { leading: button('back'), default: button('add'), trailing: button('more') },
147
+ })
148
+ const lead = wrapper.find('.overflow-hidden').element as HTMLElement
149
+ expect(lead.style.width).toBe('')
150
+ expect(lead.hasAttribute('inert')).toBe(false)
151
+ })
152
+
153
+ it('renders the items directly in the body without #leading or #trailing, as before', () => {
154
+ wrapper = mount(MToolbar, { slots: { default: () => [h('button', 'a'), h('button', 'b')] } })
155
+ expect(wrapper.find('.h-16').element.children).toHaveLength(2)
156
+ })
157
+ })
@@ -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
- setStyle(style: unknown) {
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
  }
@@ -15,6 +15,9 @@ import MSkeleton from '../components/MSkeleton.vue'
15
15
  import MStepper from '../components/MStepper.vue'
16
16
  import MTabs from '../components/MTabs.vue'
17
17
  import MTransferList from '../components/MTransferList.vue'
18
+ import MContainerTransform from '../components/MContainerTransform.vue'
19
+ import MDialog from '../components/MDialog.vue'
20
+ import MOverlay from '../components/MOverlay.vue'
18
21
 
19
22
  // These components render more than one root node (an element plus a Teleport, a v-if/v-show
20
23
  // pair, a comment before the root...), which makes Vue drop a consumer's class/attrs silently.
@@ -41,6 +44,12 @@ const cases: [name: string, component: Component, props: Record<string, unknown>
41
44
  ['MTabs', MTabs, { modelValue: 'a', tabs: [{ value: 'a', label: 'A' }] }, 'DIV'],
42
45
  ['MTabs (secondary)', MTabs, { modelValue: 'a', tabs: [{ value: 'a', label: 'A' }], variant: 'secondary' }, 'DIV'],
43
46
  ['MTransferList', MTransferList, { modelValue: [], items: [] }, 'DIV'],
47
+ ['MContainerTransform (the expanded view)', MContainerTransform, { open: true }, 'DIV'],
48
+ // A Teleport root: the attrs go on the dialog's surface
49
+ ['MDialog', MDialog, { modelValue: true, title: 'T' }, 'DIV'],
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'],
44
53
  ]
45
54
 
46
55
  describe('consumer attrs reach multi-root components', () => {