@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,279 @@
1
+ import { describe, it, expect, afterEach, vi } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import { defineComponent, h, nextTick } from 'vue'
4
+ import MContainerTransform from '../components/MContainerTransform.vue'
5
+ import { useContainerTransform } from '../composables/useContainerTransform'
6
+ import { containerFrame, emphasized } from '../composables/_containerTransform'
7
+
8
+ let wrapper: VueWrapper | undefined
9
+ const boundingRect = HTMLElement.prototype.getBoundingClientRect
10
+ afterEach(() => {
11
+ HTMLElement.prototype.getBoundingClientRect = boundingRect
12
+ wrapper?.unmount()
13
+ wrapper = undefined
14
+ document.body.style.overflow = ''
15
+ })
16
+
17
+ const card = { left: 20, top: 300, width: 160, height: 200 }
18
+ const page = { left: 0, top: 0, width: 400, height: 800 }
19
+
20
+ const flush = async () => { await nextTick(); await nextTick() }
21
+ const panel = () => document.body.querySelector('[role=dialog]') as HTMLElement | null
22
+ const animations = () => [...document.body.querySelectorAll('*')].flatMap((el) => (el as HTMLElement).getAnimations?.() ?? [])
23
+ const running = () => animations().filter((a) => a.playState === 'running')
24
+ const finishAll = async () => { animations().forEach((a) => a.playState !== 'finished' && a.finish()); await new Promise((r) => setTimeout(r)); await flush() }
25
+
26
+ describe('container transform engine', () => {
27
+ it('starts on the source box and ends on the destination box', () => {
28
+ const first = containerFrame(0, card, page, 12, 0, true)
29
+ expect(first.clip).toEqual(card)
30
+ expect(first.radius).toBe(12)
31
+ expect(first.end.opacity).toBe(0)
32
+ expect(first.scrim).toBe(0)
33
+ const last = containerFrame(1, card, page, 12, 0, true)
34
+ expect(last.clip).toEqual(page)
35
+ expect(last.radius).toBe(0)
36
+ expect(last.end).toEqual({ x: 0, y: 0, scale: 1, opacity: 1 })
37
+ })
38
+
39
+ it('scales both views uniformly to the same width (fit to width), so nothing stretches', () => {
40
+ const f = containerFrame(0.5, card, page, 12, 0, true)
41
+ expect(card.width * f.start.scale).toBeCloseTo(page.width * f.end.scale)
42
+ })
43
+
44
+ it('fades the detail in over the first quarter opening, out late closing (Android thresholds)', () => {
45
+ expect(containerFrame(0.25, card, page, 12, 0, true).end.opacity).toBe(1)
46
+ expect(containerFrame(0.125, card, page, 12, 0, true).end.opacity).toBeCloseTo(0.5)
47
+ expect(containerFrame(0.5, page, card, 0, 12, false).start.opacity).toBe(1)
48
+ expect(containerFrame(0.75, page, card, 0, 12, false).start.opacity).toBeCloseTo(0.5)
49
+ expect(containerFrame(0.95, page, card, 0, 12, false).start.opacity).toBe(0)
50
+ })
51
+
52
+ it('follows Android\'s emphasized path through its control points', () => {
53
+ expect(emphasized(0)).toBe(0)
54
+ expect(emphasized(0.166666)).toBeCloseTo(0.4, 3)
55
+ expect(emphasized(1)).toBe(1)
56
+ })
57
+ })
58
+
59
+ describe('MContainerTransform', () => {
60
+ const mountCard = (props: Record<string, unknown> = {}) =>
61
+ mount(MContainerTransform, {
62
+ props,
63
+ slots: {
64
+ default: ({ open }: { open: () => void }) => h('button', { class: 'card', onClick: open }, 'Card'),
65
+ expanded: ({ close }: { close: () => void }) => h('div', [h('p', 'Detail'), h('button', { class: 'back', onClick: close }, 'Back')]),
66
+ },
67
+ attachTo: document.body,
68
+ })
69
+
70
+ it('grows the element into the expanded view and shrinks it back', async () => {
71
+ wrapper = mountCard()
72
+ const source = wrapper.find('.card').element as HTMLElement
73
+ // The card has its box, everything else (the panel) fills the screen
74
+ HTMLElement.prototype.getBoundingClientRect = function (this: HTMLElement) {
75
+ const b = this === source ? card : page
76
+ return { ...b, right: b.left + b.width, bottom: b.top + b.height, x: b.left, y: b.top, toJSON() {} } as DOMRect
77
+ }
78
+ await wrapper.find('.card').trigger('click')
79
+ await flush()
80
+ expect(panel()?.textContent).toContain('Detail')
81
+ expect(wrapper.emitted('update:open')).toEqual([[true]])
82
+ // The element hides while its clone plays the transition, then the clone goes
83
+ expect(source.style.visibility).toBe('hidden')
84
+ expect(document.body.querySelector('[aria-hidden=true].card')).not.toBeNull()
85
+ expect(running().length).toBeGreaterThan(0)
86
+ expect(document.body.style.overflow).toBe('hidden')
87
+ await finishAll()
88
+ expect(document.body.querySelector('[aria-hidden=true].card')).toBeNull()
89
+
90
+ ;(document.body.querySelector('.back') as HTMLElement).click()
91
+ await flush()
92
+ expect(panel()).not.toBeNull()
93
+ await finishAll()
94
+ expect(panel()).toBeNull()
95
+ expect(source.style.visibility).toBe('')
96
+ expect(document.activeElement).toBe(source)
97
+ expect(document.body.style.overflow).toBe('')
98
+ expect(wrapper.emitted('update:open')).toEqual([[true], [false]])
99
+ })
100
+
101
+ it('survives rapid opening and closing, ending in the last state asked', async () => {
102
+ wrapper = mountCard({ 'onUpdate:open': (v: boolean) => wrapper!.setProps({ open: v }) })
103
+ const source = wrapper.find('.card').element as HTMLElement
104
+ HTMLElement.prototype.getBoundingClientRect = function (this: HTMLElement) {
105
+ const b = this === source ? card : page
106
+ return { ...b, right: b.left + b.width, bottom: b.top + b.height, x: b.left, y: b.top, toJSON() {} } as DOMRect
107
+ }
108
+ // Open and close over and over without letting a transition finish
109
+ for (let i = 0; i < 4; i++) {
110
+ await wrapper.setProps({ open: true })
111
+ await flush()
112
+ await wrapper.setProps({ open: false })
113
+ await flush()
114
+ }
115
+ await wrapper.setProps({ open: true })
116
+ await flush()
117
+ await finishAll()
118
+ expect(panel()).not.toBeNull()
119
+ expect(running()).toHaveLength(0)
120
+ // And it still closes
121
+ await wrapper.setProps({ open: false })
122
+ await flush()
123
+ await finishAll()
124
+ expect(panel()).toBeNull()
125
+ expect(source.style.visibility).toBe('')
126
+ })
127
+
128
+ it('closes when closed mid-opening, instead of jumping open and staying there', async () => {
129
+ wrapper = mountCard({ 'onUpdate:open': (v: boolean) => wrapper!.setProps({ open: v }) })
130
+ const source = wrapper.find('.card').element as HTMLElement
131
+ HTMLElement.prototype.getBoundingClientRect = function (this: HTMLElement) {
132
+ const b = this === source ? card : page
133
+ return { ...b, right: b.left + b.width, bottom: b.top + b.height, x: b.left, y: b.top, toJSON() {} } as DOMRect
134
+ }
135
+ await wrapper.find('.card').trigger('click')
136
+ await flush()
137
+ expect(running().length).toBeGreaterThan(0)
138
+ // The back button inside, before the opening ends: the run turns around
139
+ ;(document.body.querySelector('.back') as HTMLElement).click()
140
+ await flush()
141
+ await finishAll()
142
+ expect(panel()).toBeNull()
143
+ expect(source.style.visibility).toBe('')
144
+ // And it opens again normally
145
+ await wrapper.find('.card').trigger('click')
146
+ await flush()
147
+ await finishAll()
148
+ expect(panel()).not.toBeNull()
149
+ })
150
+
151
+ it('closes on Escape', async () => {
152
+ wrapper = mountCard({ open: true })
153
+ await flush()
154
+ expect(panel()).not.toBeNull()
155
+ document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
156
+ await finishAll()
157
+ expect(panel()).toBeNull()
158
+ })
159
+
160
+ it('closes on a scrim click in dialog mode, unless persistent', async () => {
161
+ wrapper = mountCard({ open: true, mode: 'dialog', 'onUpdate:open': (v: boolean) => wrapper!.setProps({ open: v }) })
162
+ await flush()
163
+ ;(document.body.querySelector('.bg-black') as HTMLElement).click()
164
+ await finishAll()
165
+ expect(panel()).toBeNull()
166
+ await wrapper.setProps({ open: true, persistent: true })
167
+ await flush()
168
+ ;(document.body.querySelector('.bg-black') as HTMLElement).click()
169
+ await finishAll()
170
+ expect(panel()).not.toBeNull()
171
+ })
172
+
173
+ it('leaves placing the expanded view to the consumer\'s classes in custom mode', async () => {
174
+ wrapper = mount(MContainerTransform, {
175
+ props: { open: true, mode: 'custom' },
176
+ attrs: { class: 'bottom-4 right-4 w-80 bg-primary-container' },
177
+ slots: { default: () => h('button', 'Card'), expanded: () => h('p', 'Chat') },
178
+ attachTo: document.body,
179
+ })
180
+ await flush()
181
+ const cls = panel()!.className
182
+ expect(cls).toContain('bottom-4 right-4 w-80 bg-primary-container')
183
+ expect(cls).not.toContain('inset-0')
184
+ // Its default look is in the base layer (a class of its own), so the consumer's bg-* wins
185
+ expect(cls).toContain('m3-ct-panel')
186
+ expect(cls).not.toMatch(/(^|\s)bg-surface/)
187
+ })
188
+
189
+ it('without a scrim, leaves the page usable and closes on a press outside, unless persistent', async () => {
190
+ const outside = document.createElement('button')
191
+ document.body.appendChild(outside)
192
+ wrapper = mountCard({ open: true, mode: 'custom', scrim: false, 'onUpdate:open': (v: boolean) => wrapper!.setProps({ open: v }) })
193
+ await flush()
194
+ expect(panel()!.hasAttribute('aria-modal')).toBe(false)
195
+ expect(document.body.style.overflow).toBe('')
196
+ // A press inside stays open
197
+ panel()!.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
198
+ await flush()
199
+ expect(panel()).not.toBeNull()
200
+ outside.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
201
+ await finishAll()
202
+ expect(panel()).toBeNull()
203
+ await wrapper.setProps({ open: true, persistent: true })
204
+ await flush()
205
+ outside.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
206
+ await finishAll()
207
+ expect(panel()).not.toBeNull()
208
+ outside.remove()
209
+ })
210
+
211
+ describe('Android\'s back', () => {
212
+ // The platform's close requests (CloseWatcher, Chrome/Edge): a fake one we can fire
213
+ class FakeWatcher {
214
+ static all: FakeWatcher[] = []
215
+ onclose: (() => void) | null = null
216
+ destroyed = false
217
+ constructor() { FakeWatcher.all.push(this) }
218
+ destroy() { this.destroyed = true }
219
+ requestClose() { if (!this.destroyed) this.onclose?.() }
220
+ }
221
+ afterEach(() => {
222
+ FakeWatcher.all = []
223
+ delete (window as { CloseWatcher?: unknown }).CloseWatcher
224
+ })
225
+
226
+ it('closes it through a CloseWatcher, without touching the history', async () => {
227
+ ;(window as { CloseWatcher?: unknown }).CloseWatcher = FakeWatcher
228
+ const push = vi.spyOn(history, 'pushState')
229
+ const back = vi.spyOn(history, 'back')
230
+ wrapper = mountCard({ 'onUpdate:open': (v: boolean) => wrapper!.setProps({ open: v }) })
231
+ await wrapper.find('.card').trigger('click')
232
+ await flush()
233
+ expect(FakeWatcher.all).toHaveLength(1)
234
+ FakeWatcher.all[0]!.requestClose()
235
+ await finishAll()
236
+ expect(panel()).toBeNull()
237
+ expect(push).not.toHaveBeenCalled()
238
+ expect(back).not.toHaveBeenCalled()
239
+ push.mockRestore()
240
+ back.mockRestore()
241
+ })
242
+
243
+ it('lets go of its watcher when closed some other way', async () => {
244
+ ;(window as { CloseWatcher?: unknown }).CloseWatcher = FakeWatcher
245
+ wrapper = mountCard({ 'onUpdate:open': (v: boolean) => wrapper!.setProps({ open: v }) })
246
+ await wrapper.find('.card').trigger('click')
247
+ await flush()
248
+ document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
249
+ await finishAll()
250
+ expect(FakeWatcher.all[0]!.destroyed).toBe(true)
251
+ })
252
+
253
+ it('makes no watcher with closeOnBack off', async () => {
254
+ ;(window as { CloseWatcher?: unknown }).CloseWatcher = FakeWatcher
255
+ wrapper = mountCard({ closeOnBack: false })
256
+ await wrapper.find('.card').trigger('click')
257
+ await flush()
258
+ expect(FakeWatcher.all).toHaveLength(0)
259
+ })
260
+ })
261
+
262
+ it('opens from elements elsewhere through a controller, with their item', async () => {
263
+ const Page = defineComponent({
264
+ setup() {
265
+ const detail = useContainerTransform<{ name: string }>()
266
+ return () => [
267
+ h('button', { class: 'a', onClick: (e: Event) => detail.open(e, { name: 'Alpha' }) }, 'A'),
268
+ h('button', { class: 'b', onClick: (e: Event) => detail.open(e, { name: 'Beta' }) }, 'B'),
269
+ h(MContainerTransform, { controller: detail }, { expanded: ({ item }: { item?: { name: string } }) => h('p', item?.name) }),
270
+ ]
271
+ },
272
+ })
273
+ wrapper = mount(Page, { attachTo: document.body })
274
+ await wrapper.find('.b').trigger('click')
275
+ await flush()
276
+ expect(panel()?.textContent).toBe('Beta')
277
+ expect((wrapper.find('.b').element as HTMLElement).style.visibility).toBe('hidden')
278
+ })
279
+ })
@@ -103,4 +103,31 @@ describe('MDialog', () => {
103
103
  expect(w.emitted('update:modelValue')?.[0]).toEqual([false])
104
104
  w.unmount()
105
105
  })
106
+
107
+ it('bare with fullscreen: the content fills the screen and draws its own top bar', () => {
108
+ const w = mount(MDialog, {
109
+ props: { modelValue: true, bare: true, fullscreen: true, title: 'Edit event' },
110
+ slots: { default: '<header class="mine">My bar</header>' },
111
+ attachTo: document.body,
112
+ })
113
+ const screen = document.body.querySelector('.dialog-fs') as HTMLElement
114
+ expect(screen.querySelector('.mine')).not.toBeNull()
115
+ expect(screen.querySelector('h2')).toBeNull()
116
+ expect(screen.querySelector('button')).toBeNull()
117
+ expect(screen.getAttribute('aria-label')).toBe('Edit event')
118
+ w.unmount()
119
+ })
120
+
121
+ it('puts the consumer\'s classes on its surface, over the default background', () => {
122
+ const w = mount(MDialog, {
123
+ props: { modelValue: true, title: 'T', fullscreen: true },
124
+ attrs: { class: 'bg-tertiary-container' },
125
+ attachTo: document.body,
126
+ })
127
+ const screen = document.body.querySelector('.dialog-fs') as HTMLElement
128
+ expect(screen.classList.contains('bg-tertiary-container')).toBe(true)
129
+ // The default is a base-layer class, not a competing bg-* utility
130
+ expect([...screen.classList].filter((c) => c.startsWith('bg-'))).toEqual(['bg-tertiary-container'])
131
+ w.unmount()
132
+ })
106
133
  })
@@ -57,4 +57,37 @@ describe('MIconButton', () => {
57
57
  const square = mount(MIconButton, { props: { icon: 'x', checked: true, shape: 'squared' } })
58
58
  expect((square.element as HTMLElement).style.borderRadius).toBe('20px')
59
59
  })
60
+
61
+ describe('color', () => {
62
+ const style = (props: Record<string, unknown>) => (mount(MIconButton, { props: { icon: 'close', ...props } }).element as HTMLElement).style
63
+
64
+ it('colors the icon of standard and outlined buttons', () => {
65
+ expect(style({ color: '#fff' }).color).toBe('#fff')
66
+ expect(style({ color: 'primary', variant: 'outlined' }).color).toBe('var(--color-primary)')
67
+ })
68
+
69
+ it('fills a filled button with the color, white or the on-role on it', () => {
70
+ const s = style({ color: 'rgb(0 0 0 / 0.3)', variant: 'filled' })
71
+ expect(s.backgroundColor).toBe('rgb(0 0 0 / 0.3)')
72
+ expect(s.color).toBe('#fff')
73
+ expect(style({ color: 'tertiary', variant: 'filled' }).color).toBe('var(--color-on-tertiary)')
74
+ })
75
+
76
+ it('gives a tonal button a container of the color', () => {
77
+ expect(style({ color: 'error', variant: 'tonal' }).backgroundColor).toBe('var(--color-error-container)')
78
+ // (happy-dom drops color-mix() backgrounds, so only the content color is checked for a CSS color)
79
+ expect(style({ color: '#e8590c', variant: 'tonal' }).color).toBe('#e8590c')
80
+ })
81
+
82
+ it('contentColor recolors the icon over color', () => {
83
+ const s = style({ color: '#fff', variant: 'filled', contentColor: '#000' })
84
+ expect(s.color).toBe('#000')
85
+ expect(style({ contentColor: 'on-surface' }).color).toBe('var(--color-on-surface)')
86
+ })
87
+
88
+ it('leaves disabled buttons and toggles to their own colors', () => {
89
+ expect(style({ color: 'primary', disabled: true }).color).toBe('')
90
+ expect(style({ color: 'primary', checked: false }).color).toBe('')
91
+ })
92
+ })
60
93
  })
@@ -0,0 +1,48 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import { h } from 'vue'
4
+ import MListItem from '../components/MListItem.vue'
5
+
6
+ let wrapper: VueWrapper | undefined
7
+ afterEach(() => {
8
+ wrapper?.unmount()
9
+ wrapper = undefined
10
+ })
11
+
12
+ const mountExpandable = (props: Record<string, unknown> = {}) =>
13
+ mount(MListItem, {
14
+ props: { title: 'Settings', expandable: true, ...props },
15
+ slots: { children: () => h('p', 'Wi-Fi') },
16
+ global: { stubs: { transition: false } },
17
+ })
18
+
19
+ describe('MListItem expandable', () => {
20
+ it('makes its header a button that says whether its children are shown', async () => {
21
+ wrapper = mountExpandable()
22
+ const header = wrapper.find('[role=button]')
23
+ expect(header.attributes('tabindex')).toBe('0')
24
+ expect(header.attributes('aria-expanded')).toBe('false')
25
+ await header.trigger('click')
26
+ expect(header.attributes('aria-expanded')).toBe('true')
27
+ expect(wrapper.find(`#${header.attributes('aria-controls')}`).text()).toBe('Wi-Fi')
28
+ })
29
+
30
+ it('toggles from the keyboard with Enter and Space', async () => {
31
+ wrapper = mountExpandable()
32
+ const header = wrapper.find('[role=button]')
33
+ await header.trigger('keydown', { key: 'Enter' })
34
+ expect(wrapper.emitted('update:expanded')).toEqual([[true]])
35
+ expect(wrapper.text()).toContain('Wi-Fi')
36
+ await header.trigger('keydown', { key: ' ' })
37
+ expect(wrapper.emitted('update:expanded')).toEqual([[true], [false]])
38
+ await header.trigger('keydown', { key: 'a' })
39
+ expect(wrapper.emitted('update:expanded')).toHaveLength(2)
40
+ })
41
+
42
+ it('is out of the tab order while disabled', () => {
43
+ wrapper = mountExpandable({ disabled: true })
44
+ const header = wrapper.find('[role=button]')
45
+ expect(header.attributes('tabindex')).toBe('-1')
46
+ expect(header.attributes('aria-disabled')).toBe('true')
47
+ })
48
+ })
@@ -20,7 +20,8 @@ const radius = (el: Element) => (el as HTMLElement).style.borderRadius
20
20
  describe('MListItem shape morph', () => {
21
21
  it('rests at 4px and grows on hover and press when clickable', async () => {
22
22
  wrapper = mount(MListItem, { props: { title: 'A', clickable: true }, attachTo: document.body })
23
- const row = wrapper.element
23
+ // A clickable row is a button inside its <li>
24
+ const row = wrapper.find('[role="button"]').element
24
25
  await settle()
25
26
  expect(radius(row)).toBe('4px')
26
27
  row.dispatchEvent(new PointerEvent('pointerenter', { pointerType: 'mouse' }))
@@ -33,12 +34,13 @@ describe('MListItem shape morph', () => {
33
34
 
34
35
  it('ignores hover when not interactive, but morphs when selected', async () => {
35
36
  wrapper = mount(MListItem, { props: { title: 'A' }, attachTo: document.body })
36
- wrapper.element.dispatchEvent(new PointerEvent('pointerenter', { pointerType: 'mouse' }))
37
+ const row = wrapper.find('.mli-row').element
38
+ row.dispatchEvent(new PointerEvent('pointerenter', { pointerType: 'mouse' }))
37
39
  await settle()
38
- expect(radius(wrapper.element)).toBe('4px')
40
+ expect(radius(row)).toBe('4px')
39
41
  await wrapper.setProps({ active: true })
40
42
  await settle()
41
- expect(radius(wrapper.element)).toBe('16px')
43
+ expect(radius(row)).toBe('16px')
42
44
  })
43
45
 
44
46
  it('rounds the outer corners of each segmented run', async () => {
@@ -92,7 +94,8 @@ describe('MListItem shape morph', () => {
92
94
  const group = wrapper.find('ul ul')
93
95
  const title = wrapper.find(`#${group.attributes('aria-labelledby')}`)
94
96
  expect(title.text()).toBe('Privacy')
95
- const rows = wrapper.findAll('[role="listitem"]')
97
+ // A selectable list is a listbox of options
98
+ const rows = wrapper.findAll('[role="option"]')
96
99
  expect(rows[1]!.classes()).toContain('bg-secondary-container')
97
100
  await rows[0]!.trigger('click')
98
101
  expect(wrapper.emitted('update:selected')?.[0]).toEqual(['a'])
@@ -105,6 +108,6 @@ describe('MListItem shape morph', () => {
105
108
  attachTo: document.body,
106
109
  })
107
110
  await settle()
108
- expect(radius(wrapper.find('[role="listitem"]').element)).toBe('')
111
+ expect(radius(wrapper.find('.mli-row').element)).toBe('')
109
112
  })
110
113
  })
@@ -0,0 +1,90 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import { h, nextTick } from 'vue'
4
+ import MList from '../components/MList.vue'
5
+ import MListItem from '../components/MListItem.vue'
6
+
7
+ let wrapper: VueWrapper | undefined
8
+ afterEach(() => {
9
+ wrapper?.unmount()
10
+ wrapper = undefined
11
+ document.body.innerHTML = ''
12
+ })
13
+
14
+ describe('MList and MListItem from the keyboard', () => {
15
+ const selectableList = (selected: string | null) =>
16
+ mount(MList, {
17
+ props: { selectable: true, selected, 'onUpdate:selected': (v: string) => wrapper!.setProps({ selected: v }) },
18
+ slots: { default: () => ['a', 'b', 'c'].map((v) => h(MListItem, { title: v.toUpperCase(), value: v, disabled: v === 'c' })) },
19
+ attachTo: document.body,
20
+ })
21
+
22
+ it('makes a selectable list a listbox of options with one Tab stop, the selected one', async () => {
23
+ wrapper = selectableList('b')
24
+ await nextTick()
25
+ expect(wrapper.find('ul').attributes('role')).toBe('listbox')
26
+ const options = wrapper.findAll('[role="option"]')
27
+ expect(options.map((o) => o.attributes('aria-selected'))).toEqual(['false', 'true', 'false'])
28
+ expect(options.map((o) => o.attributes('tabindex'))).toEqual(['-1', '0', '-1'])
29
+ expect(options[2]!.attributes('aria-disabled')).toBe('true')
30
+ })
31
+
32
+ it('gives the Tab stop to the first option when nothing is selected', async () => {
33
+ wrapper = selectableList(null)
34
+ await nextTick()
35
+ expect((wrapper.findAll('[role="option"]')[0]!.element as HTMLElement).tabIndex).toBe(0)
36
+ })
37
+
38
+ it('moves between options with the arrows (skipping disabled ones) and selects with Enter and Space', async () => {
39
+ wrapper = selectableList('a')
40
+ await nextTick()
41
+ const options = wrapper.findAll('[role="option"]').map((o) => o.element as HTMLElement)
42
+ options[0]!.focus()
43
+ options[0]!.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }))
44
+ expect(document.activeElement).toBe(options[1])
45
+ // c is disabled: nowhere further down
46
+ options[1]!.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }))
47
+ expect(document.activeElement).toBe(options[1])
48
+ options[1]!.dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true }))
49
+ expect(wrapper.emitted('update:selected')?.[0]).toEqual(['b'])
50
+ options[1]!.dispatchEvent(new KeyboardEvent('keydown', { key: 'Home', bubbles: true }))
51
+ expect(document.activeElement).toBe(options[0])
52
+ options[0]!.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))
53
+ expect(wrapper.emitted('update:selected')?.[1]).toEqual(['a'])
54
+ })
55
+
56
+ it('makes a clickable row a button inside its list item, operable from the keyboard', async () => {
57
+ let clicks = 0
58
+ wrapper = mount(MList, { slots: { default: () => h(MListItem, { title: 'Open', onClick: () => clicks++ }) }, attachTo: document.body })
59
+ const li = wrapper.find('ul > li')
60
+ expect(li.attributes('role')).toBe('listitem')
61
+ const row = li.find('[role="button"]')
62
+ expect(row.attributes('tabindex')).toBe('0')
63
+ // @click alone makes it interactive (hover and press styles)
64
+ expect(row.classes()).toContain('cursor-pointer')
65
+ await row.trigger('keydown', { key: 'Enter' })
66
+ await row.trigger('keydown', { key: ' ' })
67
+ expect(clicks).toBe(2)
68
+ })
69
+
70
+ it('keeps a link a link, inside its list item', () => {
71
+ wrapper = mount(MList, { slots: { default: () => h(MListItem, { title: 'Docs', href: '/docs' }) }, attachTo: document.body })
72
+ const a = wrapper.find('ul > li[role="listitem"] > a')
73
+ expect(a.attributes('href')).toBe('/docs')
74
+ expect(a.attributes('role')).toBeUndefined()
75
+ })
76
+
77
+ it('leaves a plain row a plain list item, out of the tab order', () => {
78
+ wrapper = mount(MList, { slots: { default: () => h(MListItem, { title: 'Info' }) }, attachTo: document.body })
79
+ const li = wrapper.find('ul > li')
80
+ expect(li.attributes('role')).toBe('listitem')
81
+ expect(li.attributes('tabindex')).toBeUndefined()
82
+ expect(li.classes()).toContain('mli-row')
83
+ })
84
+
85
+ it('puts the consumer\'s classes on the row', () => {
86
+ wrapper = mount(MList, { slots: { default: () => h(MListItem, { title: 'Open', onClick: () => {}, class: 'mine' }) }, attachTo: document.body })
87
+ expect(wrapper.find('[role="button"]').classes()).toContain('mine')
88
+ expect(wrapper.find('ul > li').classes()).not.toContain('mine')
89
+ })
90
+ })
@@ -19,10 +19,12 @@ beforeEach(() => {
19
19
  afterEach(() => { document.body.innerHTML = '' })
20
20
 
21
21
  /** Mounts an MMap, waits for MapLibre to "load" and the slot to render. */
22
- async function mountMap(props: Record<string, unknown> = {}, slot?: () => unknown) {
22
+ async function mountMap(props: Record<string, unknown> = {}, slot?: () => unknown, style?: FakeMap['style']) {
23
23
  const wrapper = mount(MMap, { props: { mapStyle: 'https://tiles.test/style.json', ...props }, slots: slot ? { default: slot } : {}, attachTo: document.body })
24
24
  await flushPromises()
25
25
  const map = created.maps.at(-1)!
26
+ // What getStyle() returns once the first style loads
27
+ if (style) map.style = style
26
28
  map.load()
27
29
  await nextTick()
28
30
  await nextTick()
@@ -420,3 +422,53 @@ describe('useMap', () => {
420
422
  expect(() => mount(defineComponent({ setup() { useMap(); return () => null } }))).toThrow(/inside <MMap>/)
421
423
  })
422
424
  })
425
+
426
+ describe('keepLayers', () => {
427
+ type Style = import('maplibre-gl').StyleSpecification
428
+ const base = (name: string): Style => ({
429
+ version: 8,
430
+ sources: { [`${name}-tiles`]: { type: 'vector', url: `https://tiles.test/${name}` } },
431
+ layers: [{ id: `${name}-bg`, type: 'background' }],
432
+ })
433
+ // The light style as it is after runtime additions: its own plus a zones source/layer and a measure layer
434
+ const runtime = (): Style => {
435
+ const s = base('light')
436
+ return {
437
+ ...s,
438
+ sources: { ...s.sources, zones: { type: 'geojson', data: { type: 'FeatureCollection', features: [] } } },
439
+ layers: [...s.layers, { id: 'zones-fill', type: 'fill', source: 'zones' }, { id: 'measure-line', type: 'line', source: 'zones' }],
440
+ }
441
+ }
442
+
443
+ async function switchStyle(props: Record<string, unknown> = {}) {
444
+ const { wrapper, map } = await mountMap({ mapStyle: 'light', ...props }, undefined, base('light') as never)
445
+ await wrapper.setProps({ mapStyle: 'dark' })
446
+ const transform = map.styleOptions.at(-1)!.transformStyle!
447
+ return { wrapper, map, result: transform(runtime(), base('dark')) as Style, transform }
448
+ }
449
+
450
+ it('carries runtime sources and layers into the new style, on top', async () => {
451
+ const { result } = await switchStyle()
452
+ expect(result.layers.map((l) => l.id)).toEqual(['dark-bg', 'zones-fill', 'measure-line'])
453
+ expect(Object.keys(result.sources)).toEqual(['dark-tiles', 'zones'])
454
+ })
455
+
456
+ it('picks layers with a function, drops them with false, and runs transformStyle after', async () => {
457
+ const picked = await switchStyle({ keepLayers: (l: { id: string }) => l.id.startsWith('zones') })
458
+ expect(picked.result.layers.map((l) => l.id)).toEqual(['dark-bg', 'zones-fill'])
459
+
460
+ const dropped = await switchStyle({ keepLayers: false })
461
+ expect(dropped.result.layers.map((l) => l.id)).toEqual(['dark-bg'])
462
+
463
+ const custom = await switchStyle({ transformStyle: (_p: unknown, next: Style) => ({ ...next, name: 'tweaked' }) })
464
+ expect(custom.result.name).toBe('tweaked')
465
+ expect(custom.result.layers.map((l) => l.id)).toContain('zones-fill')
466
+ })
467
+
468
+ it('counts a carried layer as runtime again on the next switch', async () => {
469
+ const { wrapper, map, result } = await switchStyle()
470
+ await wrapper.setProps({ mapStyle: 'light' })
471
+ const back = map.styleOptions.at(-1)!.transformStyle!(result, base('light')) as Style
472
+ expect(back.layers.map((l) => l.id)).toEqual(['light-bg', 'zones-fill', 'measure-line'])
473
+ })
474
+ })
@@ -1,12 +1,12 @@
1
1
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
2
  import { flushPromises, mount } from '@vue/test-utils'
3
- import { defineComponent, h, nextTick } from 'vue'
3
+ import { defineComponent, h, nextTick, ref } from 'vue'
4
4
  import type { StyleSpecification } from 'maplibre-gl'
5
5
  import { created, type FakeMap } from './_fakeMaplibre'
6
6
 
7
7
  vi.mock('maplibre-gl', async () => (await import('./_fakeMaplibre')).fakeModule)
8
8
 
9
- const { MMap, MMapLayers, MMapBaseLayers, MMapIdentify, MMapHover, useMapLayers, orvianAdapter, genericAdapter, formatFieldValue, identifyFeatures } = await import('../map')
9
+ const { MMap, MMapLayers, MMapBaseLayers, MMapIdentify, MMapHover, MMapFilter, useMap, useMapLayers, orvianAdapter, genericAdapter, formatFieldValue, identifyFeatures } = await import('../map')
10
10
 
11
11
  // A style the way the Orvian viewers write it (served by mvt-rs)
12
12
  const STYLE_URL = 'https://tiles.test/services/styles/public:city'
@@ -189,6 +189,50 @@ describe('MMapBaseLayers', () => {
189
189
  })
190
190
  })
191
191
 
192
+ describe('outside the map', () => {
193
+ // A side panel next to the map: the MMap's template ref reaches the panels through their `map` prop
194
+ async function mountBeside() {
195
+ const mapRef = ref()
196
+ let api!: ReturnType<typeof useMap>
197
+ const Own = defineComponent({ props: { map: Object }, setup(props) { api = useMap(() => props.map as never); return () => null } })
198
+ const wrapper = mount(defineComponent({
199
+ setup: () => () => h('div', [
200
+ h('aside', [
201
+ h(MMapLayers, { map: mapRef.value, search: false }),
202
+ h(MMapBaseLayers, { map: mapRef.value }),
203
+ h(MMapFilter, { map: mapRef.value, layer: 'poi', property: 'kind', values: ['cafe', 'park'] }),
204
+ h(Own, { map: mapRef.value }),
205
+ ]),
206
+ h(MMap, { ref: mapRef, mapStyle: STYLE_URL, adapter: orvianAdapter() }),
207
+ ]),
208
+ }), { attachTo: document.body })
209
+ await flushPromises()
210
+ const map = created.maps.at(-1)! as FakeMap
211
+ map.style = orvianStyle() as never
212
+ map.load()
213
+ await nextTick()
214
+ await nextTick()
215
+ return { wrapper, map, api: () => api }
216
+ }
217
+
218
+ it('MMapLayers, MMapBaseLayers and MMapFilter work from a panel beside the map', async () => {
219
+ const { wrapper, map } = await mountBeside()
220
+ const panel = wrapper.find('aside')
221
+ expect(panel.text()).toContain('Parcels')
222
+ await panel.find('button[aria-label="Hide layer"]').trigger('click')
223
+ expect(map.getLayoutProperty('parcels', 'visibility')).toBe('none')
224
+ await panel.find('button[aria-label="Satellite"]').trigger('click')
225
+ expect(map.getLayoutProperty('sat', 'visibility')).toBe('visible')
226
+ await panel.findAll('button').find((b) => b.text().includes('cafe'))!.trigger('click')
227
+ expect(map.getFilter('poi')).toEqual(['in', ['get', 'kind'], ['literal', ['cafe']]])
228
+ })
229
+
230
+ it('useMap() takes the map too, empty until it mounts', async () => {
231
+ const { map, api } = await mountBeside()
232
+ expect(api().map.value).toBe(map)
233
+ })
234
+ })
235
+
192
236
  describe('identify', () => {
193
237
  it('lists the identify layers\' features under a point, formatted, minus hidden and excluded properties', async () => {
194
238
  const { map } = await mountWithLayers()