@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,93 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import { defineComponent, h, nextTick, type Component } from 'vue'
4
+ import MDialog from '../components/MDialog.vue'
5
+ import MSelect from '../components/MSelect.vue'
6
+ import MAutocomplete from '../components/MAutocomplete.vue'
7
+ import MSearchBar from '../components/MSearchBar.vue'
8
+ import MBottomSheet from '../components/MBottomSheet.vue'
9
+ import MSideSheet from '../components/MSideSheet.vue'
10
+ import MCommandPalette from '../components/MCommandPalette.vue'
11
+ import MSpotlightSearch from '../components/MSpotlightSearch.vue'
12
+ import MNavigationRail from '../components/MNavigationRail.vue'
13
+
14
+ // Every case: the component sits in (or opens over) an open MDialog. One Escape closes the component alone; the
15
+ // next one closes the dialog. Before, both went at once (each component listened to Escape on its own, outside the
16
+ // library's escape stack MDialog uses).
17
+
18
+ let wrappers: VueWrapper[] = []
19
+ afterEach(() => {
20
+ wrappers.forEach((w) => w.unmount())
21
+ wrappers = []
22
+ document.body.innerHTML = ''
23
+ document.body.style.overflow = ''
24
+ })
25
+
26
+ function inDialog(child: () => unknown) {
27
+ const w = mount(MDialog, { props: { modelValue: true, title: 'T' }, slots: { default: child }, attachTo: document.body })
28
+ wrappers.push(w)
29
+ return w
30
+ }
31
+ const press = (target: EventTarget = document) =>
32
+ target.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true }))
33
+ const dialogClosed = (w: VueWrapper) => (w.emitted('update:modelValue') ?? []).some((e) => e[0] === false)
34
+
35
+ describe('Escape closes the topmost surface only', () => {
36
+ it('MSelect: an open list closes first', async () => {
37
+ const d = inDialog(() => h(MSelect, { modelValue: 'a', label: 'L', options: [{ value: 'a', label: 'A' }, { value: 'b', label: 'B' }] }))
38
+ const trigger = document.querySelector<HTMLElement>('[role=combobox]')!
39
+ trigger.click()
40
+ await nextTick()
41
+ expect(trigger.getAttribute('aria-expanded')).toBe('true')
42
+ press(trigger)
43
+ await nextTick()
44
+ expect(trigger.getAttribute('aria-expanded')).toBe('false')
45
+ expect(dialogClosed(d)).toBe(false)
46
+ press(trigger)
47
+ expect(dialogClosed(d)).toBe(true)
48
+ })
49
+
50
+ it('MAutocomplete: an open list closes first', async () => {
51
+ const d = inDialog(() => h(MAutocomplete, { modelValue: null, label: 'L', options: [{ value: 'a', label: 'Apple' }] }))
52
+ const input = document.querySelector<HTMLInputElement>('input')!
53
+ input.focus()
54
+ input.dispatchEvent(new Event('focus'))
55
+ input.value = 'a'
56
+ input.dispatchEvent(new Event('input', { bubbles: true }))
57
+ await nextTick()
58
+ const expanded = () => document.querySelector('[aria-expanded]')?.getAttribute('aria-expanded')
59
+ expect(expanded()).toBe('true')
60
+ press(input)
61
+ await nextTick()
62
+ expect(expanded()).toBe('false')
63
+ expect(dialogClosed(d)).toBe(false)
64
+ })
65
+
66
+ it('MSearchBar: an expanded bar collapses first', async () => {
67
+ const bar = defineComponent({ setup: () => () => h(MSearchBar, { modelValue: '', expanded: true }) })
68
+ const d = inDialog(() => h(bar))
69
+ await nextTick()
70
+ const s = d.findComponent(MSearchBar)
71
+ press()
72
+ await nextTick()
73
+ expect(s.emitted('update:expanded')).toEqual([[false]])
74
+ expect(dialogClosed(d)).toBe(false)
75
+ })
76
+
77
+ const overDialog: [string, Component, Record<string, unknown>, string][] = [
78
+ ['MBottomSheet', MBottomSheet, { modelValue: true, title: 'S' }, 'update:modelValue'],
79
+ ['MSideSheet', MSideSheet, { modelValue: true, title: 'S' }, 'update:modelValue'],
80
+ ['MCommandPalette', MCommandPalette, { modelValue: true, items: [] }, 'update:modelValue'],
81
+ ['MSpotlightSearch', MSpotlightSearch, { modelValue: true, results: [] }, 'update:modelValue'],
82
+ ['MNavigationRail (modal)', MNavigationRail, { modelValue: 'a', items: [{ value: 'a', label: 'A', icon: 'home' }], modal: true, expanded: true }, 'update:expanded'],
83
+ ]
84
+ it.each(overDialog)('%s opened over a dialog closes alone', async (_n, component, props, event) => {
85
+ const d = inDialog(() => 'Dialog content')
86
+ const top = mount(component, { props, attachTo: document.body, global: { stubs: { transition: false } } })
87
+ wrappers.push(top)
88
+ await nextTick()
89
+ press()
90
+ expect(top.emitted(event)?.[0]).toEqual([false])
91
+ expect(dialogClosed(d)).toBe(false)
92
+ })
93
+ })
@@ -117,3 +117,28 @@ describe('hydrating server-rendered adaptive layouts', () => {
117
117
  expect(first).toBe(1024)
118
118
  })
119
119
  })
120
+
121
+ describe('hydrating MContainerTransform', () => {
122
+ it('renders the element on the server and the expanded view only in the browser, open from the start', async () => {
123
+ vi.resetModules()
124
+ const MContainerTransform = (await import('../components/MContainerTransform.vue')).default
125
+ const slots = { default: () => h('button', { class: 'card' }, 'Card'), expanded: () => h('p', 'Detail') }
126
+ const render = () => h(MContainerTransform, { open: true }, slots)
127
+ const ctx: { teleports?: Record<string, string> } = {}
128
+ const html = await renderToString(createSSRApp({ render }), ctx)
129
+ expect(html).toContain('Card')
130
+ expect(html + JSON.stringify(ctx.teleports)).not.toContain('Detail')
131
+
132
+ // As Nuxt does: the page, then what was teleported to <body> at its end
133
+ const container = document.createElement('div')
134
+ container.innerHTML = html
135
+ document.body.appendChild(container)
136
+ document.body.insertAdjacentHTML('beforeend', ctx.teleports?.body ?? '')
137
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
138
+ createSSRApp({ render }).mount(container)
139
+ await nextTick()
140
+ await nextTick()
141
+ expect(warn.mock.calls.map((c) => String(c[0])).filter((m) => m.includes('Hydration'))).toEqual([])
142
+ expect(document.body.querySelector('[role=dialog]')?.textContent).toBe('Detail')
143
+ })
144
+ })
@@ -1,6 +1,6 @@
1
1
  // @vitest-environment node
2
2
  import { beforeAll, describe, expect, it, vi } from 'vitest'
3
- import { createSSRApp, h, type Component } from 'vue'
3
+ import { createSSRApp, h, resolveDirective, withDirectives, type Component, type Directive } from 'vue'
4
4
  import { renderToString } from 'vue/server-renderer'
5
5
 
6
6
  // What Nuxt's server sees: no window, no document, no localStorage. The import itself has to work, since
@@ -13,7 +13,9 @@ beforeAll(async () => {
13
13
  expect(typeof window).toBe('undefined')
14
14
  expect(typeof document).toBe('undefined')
15
15
  lib = await import('../index')
16
- })
16
+ // Importing the whole library cold (every component through the transform) can pass the default 10s on a busy
17
+ // machine
18
+ }, 60_000)
17
19
 
18
20
  const items = [{ src: 'a.jpg', alt: 'a' }, { src: 'b.jpg', alt: 'b' }]
19
21
 
@@ -169,4 +171,21 @@ describe('SSR', () => {
169
171
  await expect(renderToString(app)).resolves.toBe('<div></div>')
170
172
  },
171
173
  )
174
+
175
+ it('renders every directive, with the markers the CSS needs already in the HTML', async () => {
176
+ const d = (name: string) => resolveDirective(name) as Directive
177
+ const app = createSSRApp({
178
+ render: () => h('div', [
179
+ withDirectives(h('p', { id: 'skeleton' }, 'Ada'), [[d('skeleton'), true]]),
180
+ withDirectives(h('p', { id: 'ring' }), [[d('focus-ring'), { within: true }]]),
181
+ withDirectives(h('p', { id: 'layer' }), [[d('state-layer'), { dragged: true }]]),
182
+ withDirectives(h('p'), [[d('ripple')], [d('reveal')], [d('tooltip'), 'Hi'], [d('scroll-elevation')], [d('long-press'), () => {}], [d('swipe'), () => {}], [d('click-outside'), () => {}]]),
183
+ ]),
184
+ })
185
+ app.use(lib.createM3UI())
186
+ const html = await renderToString(app)
187
+ expect(html).toContain('<p id="skeleton" data-m3-skeleton="pulse" aria-busy="true">Ada</p>')
188
+ expect(html).toContain('data-m3-focus-ring="within"')
189
+ expect(html).toContain('data-m3-state-layer="dragged"')
190
+ })
172
191
  })
@@ -0,0 +1,103 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { defineComponent, h, nextTick, ref } from 'vue'
4
+ import { useAutoGrow } from '../composables/useAutoGrow'
5
+ import MTextField from '../components/MTextField.vue'
6
+
7
+ // happy-dom has no layout: give the textarea a 20px line height, 8px vertical padding (border-box) and a
8
+ // scrollHeight of 20px per line of text plus the padding
9
+ function fakeLayout(el: HTMLTextAreaElement) {
10
+ el.style.lineHeight = '20px'
11
+ el.style.padding = '4px 0'
12
+ el.style.boxSizing = 'border-box'
13
+ Object.defineProperty(el, 'scrollHeight', { configurable: true, get: () => el.value.split('\n').length * 20 + 8 })
14
+ }
15
+
16
+ let unmount: (() => void) | undefined
17
+ afterEach(() => unmount?.())
18
+
19
+ function mountArea(options: { minRows?: number; maxRows?: number }, initial = '') {
20
+ const text = ref(initial)
21
+ const area = ref<HTMLTextAreaElement>()
22
+ const w = mount(
23
+ defineComponent({
24
+ setup() {
25
+ useAutoGrow(area, { ...options, value: text })
26
+ return () => h('textarea', { ref: (e: unknown) => {
27
+ if (e && !area.value) fakeLayout(e as HTMLTextAreaElement)
28
+ area.value = e as HTMLTextAreaElement
29
+ }, value: text.value })
30
+ },
31
+ }),
32
+ { attachTo: document.body },
33
+ )
34
+ unmount = () => w.unmount()
35
+ return { text, el: () => area.value! }
36
+ }
37
+
38
+ describe('useAutoGrow', () => {
39
+ it('starts at minRows', async () => {
40
+ const { el } = mountArea({ minRows: 2 })
41
+ await nextTick()
42
+ expect(el().style.height).toBe('48px') // 2 × 20 + 8
43
+ })
44
+
45
+ it('grows with the text up to maxRows, then scrolls', async () => {
46
+ const { text, el } = mountArea({ maxRows: 3 })
47
+ text.value = 'a\nb'
48
+ await nextTick()
49
+ expect(el().style.height).toBe('48px')
50
+ expect(el().style.overflowY).toBe('hidden')
51
+ text.value = 'a\nb\nc\nd\ne'
52
+ await nextTick()
53
+ expect(el().style.height).toBe('68px') // capped at 3 × 20 + 8
54
+ expect(el().style.overflowY).toBe('auto')
55
+ })
56
+
57
+ it('shrinks back when the text is cleared from code', async () => {
58
+ const { text, el } = mountArea({}, 'a\nb\nc')
59
+ await nextTick()
60
+ expect(el().style.height).toBe('68px')
61
+ text.value = ''
62
+ await nextTick()
63
+ expect(el().style.height).toBe('28px')
64
+ })
65
+
66
+ it('follows typing without a value source', async () => {
67
+ const area = ref<HTMLTextAreaElement>()
68
+ const w = mount(defineComponent({
69
+ setup() {
70
+ useAutoGrow(area)
71
+ return () => h('textarea', { ref: (e: unknown) => {
72
+ if (e && !area.value) fakeLayout(e as HTMLTextAreaElement)
73
+ area.value = e as HTMLTextAreaElement
74
+ } })
75
+ },
76
+ }))
77
+ unmount = () => w.unmount()
78
+ await nextTick()
79
+ area.value!.value = 'a\nb\nc\nd'
80
+ area.value!.dispatchEvent(new Event('input'))
81
+ expect(area.value!.style.height).toBe('88px')
82
+ })
83
+ })
84
+
85
+ describe('MTextField autoGrow', () => {
86
+ it('drops the drag handle and sizes the textarea itself', async () => {
87
+ const w = mount(MTextField, { props: { modelValue: '', label: 'Notes', multiline: true, autoGrow: true, rows: 1, maxRows: 4 } })
88
+ unmount = () => w.unmount()
89
+ await nextTick()
90
+ const ta = w.find('textarea')
91
+ expect(ta.classes()).toContain('resize-none')
92
+ expect(ta.element.style.height).not.toBe('')
93
+ })
94
+
95
+ it('keeps the fixed, resizable textarea without autoGrow', async () => {
96
+ const w = mount(MTextField, { props: { modelValue: '', label: 'Notes', multiline: true } })
97
+ unmount = () => w.unmount()
98
+ await nextTick()
99
+ const ta = w.find('textarea')
100
+ expect(ta.classes()).toContain('resize-y')
101
+ expect(ta.element.style.height).toBe('')
102
+ })
103
+ })
@@ -0,0 +1,102 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { defineComponent, h, nextTick, ref, withDirectives } from 'vue'
4
+ import { useScrollReveal } from '../composables/useScrollReveal'
5
+ import { vReveal } from '../directives/vReveal'
6
+
7
+ // A controllable IntersectionObserver: tests decide which elements enter or leave
8
+ const observers: FakeIO[] = []
9
+ class FakeIO {
10
+ targets = new Set<Element>()
11
+ constructor(public cb: IntersectionObserverCallback, public opts?: IntersectionObserverInit) { observers.push(this) }
12
+ observe(el: Element) { this.targets.add(el) }
13
+ unobserve(el: Element) { this.targets.delete(el) }
14
+ disconnect() { this.targets.clear() }
15
+ fire(els: Element[], isIntersecting = true) {
16
+ this.cb(els.map((target) => ({ target, isIntersecting }) as IntersectionObserverEntry), this as unknown as IntersectionObserver)
17
+ }
18
+ }
19
+ const delays: number[] = []
20
+ beforeEach(() => {
21
+ observers.length = 0
22
+ delays.length = 0
23
+ vi.stubGlobal('IntersectionObserver', FakeIO)
24
+ // Record each reveal's delay (happy-dom's animate() runs but we only need what was asked)
25
+ const real = HTMLElement.prototype.animate
26
+ vi.spyOn(HTMLElement.prototype, 'animate').mockImplementation(function (this: HTMLElement, k, o) {
27
+ delays.push(typeof o === 'object' ? (o.delay ?? 0) : 0)
28
+ return real.call(this, k, o)
29
+ })
30
+ })
31
+ afterEach(() => {
32
+ vi.unstubAllGlobals()
33
+ vi.restoreAllMocks()
34
+ })
35
+
36
+ function list(n: number, options = {}) {
37
+ const els = ref<HTMLElement[]>([])
38
+ const w = mount(defineComponent({
39
+ setup() {
40
+ useScrollReveal(els, options)
41
+ return () => h('ul', Array.from({ length: n }, (_, i) => h('li', { ref: (e: any) => { if (e) els.value[i] = e } }, `#${i}`)))
42
+ },
43
+ }), { attachTo: document.body })
44
+ return { w, items: () => w.findAll('li').map((l) => l.element as HTMLElement) }
45
+ }
46
+
47
+ describe('useScrollReveal', () => {
48
+ it('hides the elements until they enter, then plays them in, cascading', async () => {
49
+ const { w, items } = list(3, { stagger: 50 })
50
+ await nextTick()
51
+ expect(items().every((el) => el.style.opacity === '0')).toBe(true)
52
+ observers[0]!.fire(items())
53
+ expect(items().every((el) => el.style.opacity === '')).toBe(true)
54
+ expect(delays).toEqual([0, 50, 100])
55
+ w.unmount()
56
+ })
57
+
58
+ it('stops watching an element once revealed, unless once is false', async () => {
59
+ const { w, items } = list(1)
60
+ await nextTick()
61
+ observers[0]!.fire(items())
62
+ expect(observers[0]!.targets.size).toBe(0)
63
+ w.unmount()
64
+
65
+ const again = list(1, { once: false })
66
+ await nextTick()
67
+ const io = observers[1]!
68
+ io.fire(again.items())
69
+ io.fire(again.items(), false)
70
+ expect(again.items()[0]!.style.opacity).toBe('0')
71
+ again.w.unmount()
72
+ })
73
+
74
+ it('leaves everything visible with reduced motion', async () => {
75
+ vi.stubGlobal('matchMedia', (q: string) => ({ matches: q.includes('reduce'), addEventListener() {}, removeEventListener() {} }))
76
+ const { w, items } = list(2)
77
+ await nextTick()
78
+ expect(items().every((el) => el.style.opacity === '')).toBe(true)
79
+ expect(observers).toHaveLength(0)
80
+ w.unmount()
81
+ })
82
+ })
83
+
84
+ describe('v-reveal', () => {
85
+ it('reveals the items of a list together, sharing one observer per options', () => {
86
+ const app = mount(defineComponent({
87
+ setup: () => () => h('div', [1, 2, 3].map((i) => withDirectives(h('p', { key: i }, String(i)), [[vReveal, { effect: 'scale', stagger: 40 }]]))),
88
+ }), { attachTo: document.body })
89
+ const ps = app.findAll('p').map((p) => p.element as HTMLElement)
90
+ expect(observers).toHaveLength(1)
91
+ expect(ps.every((p) => p.style.opacity === '0')).toBe(true)
92
+ observers[0]!.fire(ps)
93
+ expect(delays).toEqual([0, 40, 80])
94
+ app.unmount()
95
+ })
96
+
97
+ it('does nothing with false', () => {
98
+ const app = mount(defineComponent({ setup: () => () => withDirectives(h('p', 'x'), [[vReveal, false]]) }))
99
+ expect((app.element as HTMLElement).style.opacity).toBe('')
100
+ app.unmount()
101
+ })
102
+ })
@@ -0,0 +1,114 @@
1
+ import { describe, it, expect, afterEach, vi } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { defineComponent, h, nextTick, type Ref } from 'vue'
4
+ import { useThemeTokens } from '../composables/useThemeTokens'
5
+
6
+ const root = document.documentElement
7
+ afterEach(() => {
8
+ root.style.removeProperty('--color-primary')
9
+ root.className = ''
10
+ vi.useRealTimers()
11
+ })
12
+
13
+ function use(live = false) {
14
+ let tokens!: Ref<Record<'primary', string>>
15
+ const w = mount(defineComponent({ setup: () => { tokens = useThemeTokens(['primary'] as const, { live }); return () => h('div') } }))
16
+ return { tokens: () => tokens.value, w }
17
+ }
18
+ const flush = () => new Promise((r) => setTimeout(r, 0))
19
+
20
+ describe('useThemeTokens', () => {
21
+ it('reads the tokens from <html>', () => {
22
+ root.style.setProperty('--color-primary', '#6750a4')
23
+ const { tokens, w } = use()
24
+ expect(tokens().primary).toBe('#6750a4')
25
+ w.unmount()
26
+ })
27
+
28
+ it('re-reads on a theme change, and again once the transition settles', async () => {
29
+ root.style.setProperty('--color-primary', '#6750a4')
30
+ const { tokens, w } = use()
31
+ await nextTick()
32
+ root.style.setProperty('--color-primary', '#d0bcff')
33
+ root.classList.add('dark')
34
+ await flush()
35
+ expect(tokens().primary).toBe('#d0bcff')
36
+
37
+ vi.useFakeTimers()
38
+ root.style.setProperty('--color-primary', '#ffffff')
39
+ root.classList.remove('dark')
40
+ await vi.advanceTimersByTimeAsync(0)
41
+ root.style.setProperty('--color-primary', '#000000') // the value the transition lands on
42
+ await vi.advanceTimersByTimeAsync(300)
43
+ expect(tokens().primary).toBe('#000000')
44
+ w.unmount()
45
+ })
46
+
47
+ describe('live', () => {
48
+ // A fake clock drives both performance.now() and requestAnimationFrame (16ms frames)
49
+ const frames = (ms: number) => vi.advanceTimersByTimeAsync(ms)
50
+
51
+ it('replays the fade from the old colors when the tokens jump (Firefox\'s theme-transitioning)', async () => {
52
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'requestAnimationFrame', 'cancelAnimationFrame', 'performance'] })
53
+ root.style.setProperty('--color-primary', '#000000')
54
+ const { tokens, w } = use(true)
55
+ await nextTick()
56
+ root.classList.add('theme-transitioning')
57
+ root.style.setProperty('--color-primary', '#ffffff')
58
+ await frames(0)
59
+ expect(tokens().primary).toBe('#000000')
60
+ await frames(130)
61
+ const mid = /^rgba\((\d+), (\d+), (\d+), 1\)$/.exec(tokens().primary)
62
+ expect(mid).not.toBeNull()
63
+ expect(Number(mid![1])).toBeGreaterThan(60)
64
+ expect(Number(mid![1])).toBeLessThan(250)
65
+ await frames(200)
66
+ expect(tokens().primary).toBe('#ffffff')
67
+ w.unmount()
68
+ })
69
+
70
+ // A token animating through @property changes its computed value with no DOM mutation: a stylesheet outside
71
+ // <head> (which isn't observed) stands in for that
72
+ function animatedToken() {
73
+ const sheet = document.createElement('style')
74
+ document.body.appendChild(sheet)
75
+ return { to: (v: string) => { sheet.textContent = `:root { --color-primary: ${v} }` }, remove: () => sheet.remove() }
76
+ }
77
+
78
+ it('reads the tokens every frame while they animate themselves (Chromium\'s theme-switching)', async () => {
79
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'requestAnimationFrame', 'cancelAnimationFrame', 'performance'] })
80
+ const token = animatedToken()
81
+ token.to('#000000')
82
+ const { tokens, w } = use(true)
83
+ await nextTick()
84
+ root.classList.add('theme-switching')
85
+ await frames(0)
86
+ token.to('rgb(40, 40, 40)')
87
+ await frames(50)
88
+ expect(tokens().primary).toBe('rgb(40, 40, 40)')
89
+ token.to('rgb(90, 90, 90)')
90
+ await frames(50)
91
+ expect(tokens().primary).toBe('rgb(90, 90, 90)')
92
+ w.unmount()
93
+ token.remove()
94
+ })
95
+
96
+ it('without live, waits for the switch to settle', async () => {
97
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'requestAnimationFrame', 'cancelAnimationFrame', 'performance'] })
98
+ const token = animatedToken()
99
+ token.to('#000000')
100
+ const { tokens, w } = use(false)
101
+ await nextTick()
102
+ root.classList.add('theme-switching')
103
+ await frames(0)
104
+ token.to('rgb(40, 40, 40)')
105
+ await frames(100)
106
+ expect(tokens().primary).toBe('#000000')
107
+ token.to('#ffffff')
108
+ await frames(300)
109
+ expect(tokens().primary).toBe('#ffffff')
110
+ w.unmount()
111
+ token.remove()
112
+ })
113
+ })
114
+ })
@@ -0,0 +1,82 @@
1
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { defineComponent, h, nextTick, ref, withDirectives } from 'vue'
4
+ import { vClickOutside, type ClickOutsideValue } from '../directives/vClickOutside'
5
+
6
+ const press = (target: EventTarget, type = 'pointerdown', button = 0) =>
7
+ target.dispatchEvent(new PointerEvent(type, { button, bubbles: true, composed: true }))
8
+
9
+ describe('vClickOutside', () => {
10
+ let outside: HTMLElement
11
+ beforeEach(() => {
12
+ vi.useFakeTimers()
13
+ document.body.innerHTML = ''
14
+ outside = document.createElement('div')
15
+ outside.className = 'outside'
16
+ document.body.appendChild(outside)
17
+ })
18
+ afterEach(() => vi.useRealTimers())
19
+
20
+ function host(value: () => ClickOutsideValue) {
21
+ const w = mount(defineComponent({
22
+ setup: () => () => withDirectives(h('div', { class: 'panel' }, [h('button', { class: 'inner' })]), [[vClickOutside, value()]]),
23
+ }), { attachTo: document.body })
24
+ vi.advanceTimersByTime(0)
25
+ return { w, el: w.element as HTMLElement }
26
+ }
27
+
28
+ it('calls the handler for a press outside, not inside or with another button', () => {
29
+ const handler = vi.fn()
30
+ const { el } = host(() => handler)
31
+ press(el.querySelector('.inner')!)
32
+ expect(handler).not.toHaveBeenCalled()
33
+ press(outside, 'pointerdown', 2)
34
+ expect(handler).not.toHaveBeenCalled()
35
+ press(outside)
36
+ expect(handler).toHaveBeenCalledTimes(1)
37
+ })
38
+
39
+ it('ignores the event that mounted it', () => {
40
+ const handler = vi.fn()
41
+ mount(defineComponent({
42
+ setup: () => () => withDirectives(h('div'), [[vClickOutside, handler]]),
43
+ }), { attachTo: document.body })
44
+ press(outside)
45
+ expect(handler).not.toHaveBeenCalled()
46
+ vi.advanceTimersByTime(0)
47
+ press(outside)
48
+ expect(handler).toHaveBeenCalledTimes(1)
49
+ })
50
+
51
+ it('treats excluded elements and selectors as inside, and can wait for the click', () => {
52
+ const handler = vi.fn()
53
+ const toggle = document.createElement('button')
54
+ document.body.appendChild(toggle)
55
+ const popup = document.createElement('div')
56
+ popup.className = 'popup'
57
+ popup.appendChild(document.createElement('span'))
58
+ document.body.appendChild(popup)
59
+ host(() => ({ handler, exclude: [toggle, '.popup'], event: 'click' }))
60
+ press(toggle, 'click')
61
+ press(popup.firstElementChild!, 'click')
62
+ press(outside, 'pointerdown')
63
+ expect(handler).not.toHaveBeenCalled()
64
+ press(outside, 'click')
65
+ expect(handler).toHaveBeenCalledTimes(1)
66
+ })
67
+
68
+ it('stops while disabled and after unmount', async () => {
69
+ const handler = vi.fn()
70
+ const disabled = ref(true)
71
+ const { w } = host(() => ({ handler, disabled: disabled.value }))
72
+ press(outside)
73
+ disabled.value = false
74
+ await nextTick()
75
+ vi.advanceTimersByTime(0)
76
+ press(outside)
77
+ expect(handler).toHaveBeenCalledTimes(1)
78
+ w.unmount()
79
+ press(outside)
80
+ expect(handler).toHaveBeenCalledTimes(1)
81
+ })
82
+ })
@@ -0,0 +1,36 @@
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 { vFocusRing, type FocusRingValue } from '../directives/vFocusRing'
5
+
6
+ function host(value: () => FocusRingValue) {
7
+ return mount(defineComponent({
8
+ setup: () => () => withDirectives(h('div', { tabindex: 0 }), [[vFocusRing, value()]]),
9
+ }))
10
+ }
11
+
12
+ describe('vFocusRing', () => {
13
+ it('marks the element for the ring, with no color or offset of its own by default', () => {
14
+ const el = host(() => undefined).element as HTMLElement
15
+ expect(el.dataset.m3FocusRing).toBe('')
16
+ expect(el.style.getPropertyValue('--m3-focus-ring-color')).toBe('')
17
+ expect(el.style.getPropertyValue('--m3-focus-ring-offset')).toBe('')
18
+ })
19
+
20
+ it('follows its value: a color, inset, within, off', async () => {
21
+ const value = ref<FocusRingValue>('#e91e63')
22
+ const w = host(() => value.value)
23
+ const el = w.element as HTMLElement
24
+ expect(el.style.getPropertyValue('--m3-focus-ring-color')).toBe('#e91e63')
25
+ value.value = { inset: true, within: true }
26
+ await nextTick()
27
+ expect(el.dataset.m3FocusRing).toBe('within')
28
+ expect(el.style.getPropertyValue('--m3-focus-ring-color')).toBe('')
29
+ expect(el.style.getPropertyValue('--m3-focus-ring-offset')).toBe('-3px')
30
+ value.value = false
31
+ await nextTick()
32
+ expect(el.dataset.m3FocusRing).toBe('off')
33
+ w.unmount()
34
+ expect(el.dataset.m3FocusRing).toBeUndefined()
35
+ })
36
+ })