@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
@@ -621,7 +621,9 @@ function onCardKeydown(e: KeyboardEvent, card: KanbanCard, column: KanbanColumn)
621
621
  toCol = next
622
622
  toIndex = Math.min(here.index, next.cards.length)
623
623
  } else if (e.key === 'Escape') {
624
+ // Cancelling the move uses the key: a dialog around the board stays open
624
625
  e.preventDefault()
626
+ e.stopPropagation()
625
627
  cancelKeyboard(card.id, here.column.id, here.index)
626
628
  return
627
629
  } else if (e.key === 'Enter') {
@@ -32,6 +32,7 @@ import MIconButton from './MIconButton.vue'
32
32
  import MSpinner from './MSpinner.vue'
33
33
  import { useLocale } from '../composables/useLocale'
34
34
  import { useScrollLock } from '../composables/_useScrollLock'
35
+ import { useEscapeStack } from '../composables/_useEscapeStack'
35
36
 
36
37
  export interface LightboxItem {
37
38
  src: string
@@ -288,6 +289,9 @@ function originTransform(): Origin | null {
288
289
 
289
290
  // The page doesn't scroll from when it opens until its close animation ends
290
291
  const scrollLock = useScrollLock()
292
+ // Escape closes it through the library's stack (a dialog opened over it takes it first); arrows and zoom keys stay ours
293
+ const escapeOn = ref(false)
294
+ useEscapeStack(escapeOn, () => close())
291
295
 
292
296
  async function show() {
293
297
  restoreFocus = document.activeElement as HTMLElement | null
@@ -300,6 +304,7 @@ async function show() {
300
304
  setNow(backdrop, 0)
301
305
  backdrop.k = 300
302
306
  document.addEventListener('keydown', onKeydown)
307
+ escapeOn.value = true
303
308
  scrollLock.set(true)
304
309
  await nextTick()
305
310
  measure()
@@ -319,6 +324,7 @@ async function show() {
319
324
 
320
325
  function hide() {
321
326
  document.removeEventListener('keydown', onKeydown)
327
+ escapeOn.value = false
322
328
  // The bars and the backdrop go with the image, not after it.
323
329
  chrome.value = false
324
330
  backdrop.k = 700
@@ -674,8 +680,7 @@ function onTap(e: PointerEvent) {
674
680
  // ── Keyboard and focus ────────────────────────────────────────────────────────────────────────
675
681
 
676
682
  function onKeydown(e: KeyboardEvent) {
677
- if (e.key === 'Escape') close()
678
- else if (e.key === 'ArrowRight') next()
683
+ if (e.key === 'ArrowRight') next()
679
684
  else if (e.key === 'ArrowLeft') prev()
680
685
  else if (props.zoom && (e.key === '+' || e.key === '=')) zoomTo(scale.target * 1.5, 0, 0)
681
686
  else if (props.zoom && e.key === '-') zoomTo(scale.target / 1.5, 0, 0)
@@ -7,7 +7,7 @@
7
7
  * @slot default MListItem / MListSubheader / MListGroup children
8
8
  * @event update:selected Fires when a selectable item is clicked (via v-model:selected)
9
9
  */
10
- import { computed, provide, ref } from 'vue'
10
+ import { computed, nextTick, onMounted, onUpdated, provide, ref } from 'vue'
11
11
  import { useSegmentRuns } from '../composables/_useSegmentRuns'
12
12
 
13
13
  const props = withDefaults(
@@ -51,6 +51,30 @@ provide('m-list', {
51
51
  select: (value: string | number) => emit('update:selected', value),
52
52
  })
53
53
 
54
+ // A selectable list is a listbox: its items are options, one Tab stop (the selected one, else the first), the
55
+ // arrows, Home and End move between them, Enter/Space select (MListItem)
56
+ const options = () => [...(listEl.value?.querySelectorAll<HTMLElement>('[role="option"]') ?? [])]
57
+ .filter((o) => o.getAttribute('aria-disabled') !== 'true')
58
+ function onKeydown(e: KeyboardEvent) {
59
+ if (!props.selectable) return
60
+ const all = options()
61
+ const i = all.indexOf(document.activeElement as HTMLElement)
62
+ if (i < 0) return
63
+ const next = e.key === 'ArrowDown' ? all[i + 1] : e.key === 'ArrowUp' ? all[i - 1] : e.key === 'Home' ? all[0] : e.key === 'End' ? all[all.length - 1] : undefined
64
+ if (!next) return
65
+ e.preventDefault()
66
+ next.focus()
67
+ }
68
+ // With nothing selected (or a selection not in the list), the first option takes the Tab stop. Bound tabindexes
69
+ // only patch when they change, so this one stays until the selection moves it.
70
+ function keepTabStop() {
71
+ if (!props.selectable) return
72
+ const all = options()
73
+ if (all.length && !all.some((o) => o.tabIndex === 0)) all[0]!.tabIndex = 0
74
+ }
75
+ onMounted(keepTabStop)
76
+ onUpdated(() => nextTick(keepTabStop))
77
+
54
78
  const classes = computed(() => [
55
79
  'flex flex-col',
56
80
  // ListTokens.SegmentedGap = 2dp
@@ -60,7 +84,7 @@ const classes = computed(() => [
60
84
  </script>
61
85
 
62
86
  <template>
63
- <ul ref="listEl" role="list" :class="classes">
87
+ <ul ref="listEl" :role="selectable ? 'listbox' : 'list'" :class="classes" @keydown="onKeydown">
64
88
  <slot />
65
89
  </ul>
66
90
  </template>
@@ -12,7 +12,7 @@
12
12
  * @event update:trailingValue Fires when a trailing switch/checkbox is toggled (trailing='switch' | 'checkbox')
13
13
  * @event update:expanded Fires when an expandable item is toggled open/closed
14
14
  */
15
- import { computed, inject, ref, useAttrs, watch } from 'vue'
15
+ import { computed, getCurrentInstance, h, inject, ref, useId, watch, type FunctionalComponent } from 'vue'
16
16
  import type { ComponentPublicInstance } from 'vue'
17
17
  import type { ComputedRef } from 'vue'
18
18
  import MIcon from './MIcon.vue'
@@ -82,7 +82,11 @@ const emit = defineEmits<{
82
82
  'update:expanded': [value: boolean]
83
83
  }>()
84
84
 
85
- const attrs = useAttrs()
85
+ // Root attrs go on the row (the element that looks like the item), which is wrapped in an <li> for links and buttons
86
+ defineOptions({ inheritAttrs: false })
87
+ // `click` is a declared emit, so a listener for it never shows up in attrs: read it off the vnode
88
+ const instance = getCurrentInstance()
89
+ const hasClickListener = () => !!instance?.vnode.props?.onClick
86
90
 
87
91
  const internalExpanded = ref(props.expanded ?? false)
88
92
  watch(() => props.expanded, (v) => { if (v !== undefined) internalExpanded.value = v })
@@ -109,9 +113,29 @@ const resolvedLines = computed(() => {
109
113
  })
110
114
 
111
115
  const isClickable = computed(() =>
112
- props.clickable || props.href || props.to || !!attrs.onClick || list?.selectable.value || props.expandable,
116
+ props.clickable || props.href || props.to || hasClickListener() || list?.selectable.value || props.expandable,
113
117
  )
114
118
 
119
+ // What the row is for assistive technology and the keyboard. In a selectable list, an option of its listbox
120
+ // (MList moves focus between them with the arrows); a link stays a link and a clickable row is a button, each
121
+ // inside an <li> since a list can only hold list items; anything else is a plain list item.
122
+ const isOption = computed(() => !!list?.selectable.value && props.value != null && !props.href && !props.to && !props.expandable)
123
+ const isLink = computed(() => !!(props.href || props.to))
124
+ const isButton = computed(() => !isOption.value && !isLink.value && !props.expandable && (props.clickable || hasClickListener()))
125
+ const wrapped = computed(() => isLink.value || isButton.value)
126
+ const rowRole = computed(() => (isOption.value ? 'option' : isButton.value ? 'button' : isLink.value ? undefined : 'listitem'))
127
+ const rowTabindex = computed(() => {
128
+ if (isOption.value) return isActive.value && !props.disabled ? 0 : -1
129
+ if (isButton.value) return props.disabled ? -1 : 0
130
+ return undefined
131
+ })
132
+ function onRowKeyDown(e: KeyboardEvent) {
133
+ if (!isOption.value && !isButton.value) return
134
+ if ((e.key !== 'Enter' && e.key !== ' ') || e.target !== e.currentTarget) return
135
+ e.preventDefault()
136
+ handleClick(e as unknown as MouseEvent)
137
+ }
138
+
115
139
  const isActive = computed(() => {
116
140
  if (props.active) return true
117
141
  if (list?.selectable.value && props.value != null) return list.selected.value === props.value
@@ -182,6 +206,12 @@ const containerClasses = computed(() => [
182
206
  // item of a run; the interaction shapes stay the same. Animated with MotionSchemeKeyTokens.FastSpatial.
183
207
  // Nav lists keep their pill (that's NavigationDrawerItem's shape, which doesn't morph).
184
208
  const rootEl = ref<Element | ComponentPublicInstance | null>(null)
209
+ // The <li> around a link or button row (the list's child, for segment runs); other rows are the <li> themselves
210
+ const wrapperEl = ref<Element | null>(null)
211
+ const RowWrapper: FunctionalComponent = (_, { slots }) =>
212
+ wrapped.value
213
+ ? h('li', { role: 'listitem', ref: (e) => { wrapperEl.value = e as Element | null } }, slots.default?.())
214
+ : slots.default?.()
185
215
  const shapeEl = ref<HTMLElement | null>(null)
186
216
  const el = (r: Element | ComponentPublicInstance | null) => (r && '$el' in r ? (r.$el as Element) : r)
187
217
  const hovered = ref(false)
@@ -192,7 +222,7 @@ const REST = 4
192
222
  const HOVERED = 8
193
223
  const LARGE = 16
194
224
 
195
- const segmentPosition = computed(() => (isSegmented.value ? list?.segmentPosition(el(rootEl.value)) : undefined))
225
+ const segmentPosition = computed(() => (isSegmented.value ? list?.segmentPosition(wrapped.value ? wrapperEl.value : el(rootEl.value)) : undefined))
196
226
 
197
227
  const expressiveRadii = computed<number[]>(() => {
198
228
  if (isNav.value) return []
@@ -227,7 +257,7 @@ function onBlur() { focused.value = false }
227
257
  const tag = computed(() => {
228
258
  if (props.href) return 'a'
229
259
  if (props.to) return 'router-link'
230
- if (props.expandable) return 'div'
260
+ if (isButton.value) return 'div'
231
261
  return 'li'
232
262
  })
233
263
 
@@ -237,6 +267,16 @@ const linkProps = computed(() => {
237
267
  return {}
238
268
  })
239
269
 
270
+ // An expandable item's header is a button (the row stays the list item): reachable and operable from the
271
+ // keyboard, telling assistive technology whether its children are shown
272
+ const childrenId = useId()
273
+ function onHeaderKeyDown(e: KeyboardEvent) {
274
+ if (e.key !== 'Enter' && e.key !== ' ') return
275
+ if (e.target !== e.currentTarget) return
276
+ e.preventDefault()
277
+ handleClick(e as unknown as MouseEvent)
278
+ }
279
+
240
280
  function toggleExpand(e: MouseEvent) {
241
281
  if (props.disabled) return
242
282
  internalExpanded.value = !internalExpanded.value
@@ -262,11 +302,20 @@ function handleTrailingToggle() {
262
302
  </script>
263
303
 
264
304
  <template>
265
- <li v-if="expandable" ref="rootEl" role="listitem">
305
+ <li v-if="expandable" ref="rootEl" v-bind="$attrs" role="listitem">
266
306
  <div
267
307
  ref="shapeEl"
308
+ role="button"
309
+ :tabindex="disabled ? -1 : 0"
310
+ :aria-expanded="isExpanded"
311
+ :aria-controls="childrenId"
312
+ :aria-disabled="disabled || undefined"
313
+ class="focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-secondary"
268
314
  :class="containerClasses"
269
315
  @click="handleClick"
316
+ @keydown="onHeaderKeyDown"
317
+ @focus="onFocus"
318
+ @blur="onBlur"
270
319
  @pointerenter="onPointerEnter"
271
320
  @pointerleave="onPointerLeave"
272
321
  @pointerdown="onPointerDown"
@@ -302,7 +351,7 @@ function handleTrailingToggle() {
302
351
 
303
352
  <!-- Children with collapse animation -->
304
353
  <Transition name="mli-expand">
305
- <div v-if="isExpanded" class="mli-expand-grid">
354
+ <div v-if="isExpanded" :id="childrenId" class="mli-expand-grid">
306
355
  <div class="mli-expand-body">
307
356
  <slot name="children" />
308
357
  </div>
@@ -310,85 +359,90 @@ function handleTrailingToggle() {
310
359
  </Transition>
311
360
  </li>
312
361
 
313
- <component
314
- v-else
315
- :is="tag"
316
- :class="containerClasses"
317
- ref="rootEl"
318
- v-bind="linkProps"
319
- role="listitem"
320
- @click="handleClick"
321
- @pointerenter="onPointerEnter"
322
- @pointerleave="onPointerLeave"
323
- @pointerdown="onPointerDown"
324
- @pointerup="onPointerUp"
325
- @pointercancel="onPointerUp"
326
- @focus="onFocus"
327
- @blur="onBlur"
328
- >
329
- <!-- Divider -->
330
- <div
331
- v-if="hasDivider"
332
- class="absolute top-0 right-0 h-px bg-outline-variant"
333
- :class="hasDivider === 'inset' ? 'left-16' : 'left-0'"
334
- />
335
-
336
- <!-- Leading -->
337
- <slot name="leading">
338
- <template v-if="resolvedLeading === 'icon'">
339
- <MIcon :name="icon!" :size="24" class="shrink-0" :class="activeIconClass" />
340
- </template>
341
- <template v-else-if="resolvedLeading === 'icon-container'">
342
- <div
343
- class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full"
344
- :class="iconContainerClasses[iconContainerColor || 'primary']"
345
- >
346
- <MIcon :name="icon!" :size="24" />
347
- </div>
348
- </template>
349
- <template v-else-if="resolvedLeading === 'avatar'">
350
- <MAvatar :name="avatarName!" :size="40" class="shrink-0" />
351
- </template>
352
- <template v-else-if="resolvedLeading === 'image'">
353
- <img :src="image" alt="" class="h-14 w-14 shrink-0 rounded-md object-cover">
354
- </template>
355
- <template v-else-if="resolvedLeading === 'checkbox'">
356
- <MCheckbox :model-value="isActive" class="shrink-0" />
357
- </template>
358
- </slot>
359
-
360
- <!-- Content -->
361
- <div class="min-w-0 flex-1">
362
- <slot name="overline">
363
- <p v-if="overline" class="truncate text-label-small" :class="activeIconClass">{{ overline }}</p>
364
- </slot>
365
- <slot>
366
- <p class="truncate text-body-large" :class="activeTextClass">{{ title }}</p>
367
- <p v-if="subtitle && resolvedLines >= 2" class="text-body-medium" :class="[activeIconClass, resolvedLines === 2 && 'truncate']">
368
- {{ subtitle }}
369
- </p>
370
- <p v-if="description && resolvedLines >= 3" class="line-clamp-2 text-body-small" :class="activeIconClass">
371
- {{ description }}
372
- </p>
362
+ <RowWrapper v-else>
363
+ <component
364
+ :is="tag"
365
+ :class="containerClasses"
366
+ ref="rootEl"
367
+ v-bind="{ ...linkProps, ...$attrs }"
368
+ :role="rowRole"
369
+ :tabindex="rowTabindex"
370
+ :aria-selected="isOption ? isActive : undefined"
371
+ :aria-disabled="(isOption || isButton) && disabled ? 'true' : undefined"
372
+ @click="handleClick"
373
+ @keydown="onRowKeyDown"
374
+ @pointerenter="onPointerEnter"
375
+ @pointerleave="onPointerLeave"
376
+ @pointerdown="onPointerDown"
377
+ @pointerup="onPointerUp"
378
+ @pointercancel="onPointerUp"
379
+ @focus="onFocus"
380
+ @blur="onBlur"
381
+ >
382
+ <!-- Divider -->
383
+ <div
384
+ v-if="hasDivider"
385
+ class="absolute top-0 right-0 h-px bg-outline-variant"
386
+ :class="hasDivider === 'inset' ? 'left-16' : 'left-0'"
387
+ />
388
+
389
+ <!-- Leading -->
390
+ <slot name="leading">
391
+ <template v-if="resolvedLeading === 'icon'">
392
+ <MIcon :name="icon!" :size="24" class="shrink-0" :class="activeIconClass" />
393
+ </template>
394
+ <template v-else-if="resolvedLeading === 'icon-container'">
395
+ <div
396
+ class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full"
397
+ :class="iconContainerClasses[iconContainerColor || 'primary']"
398
+ >
399
+ <MIcon :name="icon!" :size="24" />
400
+ </div>
401
+ </template>
402
+ <template v-else-if="resolvedLeading === 'avatar'">
403
+ <MAvatar :name="avatarName!" :size="40" class="shrink-0" />
404
+ </template>
405
+ <template v-else-if="resolvedLeading === 'image'">
406
+ <img :src="image" alt="" class="h-14 w-14 shrink-0 rounded-md object-cover">
407
+ </template>
408
+ <template v-else-if="resolvedLeading === 'checkbox'">
409
+ <MCheckbox :model-value="isActive" class="shrink-0" />
410
+ </template>
373
411
  </slot>
374
- </div>
375
412
 
376
- <!-- Trailing -->
377
- <slot name="trailing">
378
- <template v-if="resolvedTrailing === 'icon'">
379
- <MIcon :name="trailingIcon!" :size="24" class="shrink-0" :class="activeIconClass" />
380
- </template>
381
- <template v-else-if="resolvedTrailing === 'text'">
382
- <span class="shrink-0 text-label-small" :class="activeIconClass">{{ trailingText }}</span>
383
- </template>
384
- <template v-else-if="resolvedTrailing === 'switch'">
385
- <MSwitch :model-value="!!trailingValue" @update:model-value="handleTrailingToggle" />
386
- </template>
387
- <template v-else-if="resolvedTrailing === 'checkbox'">
388
- <MCheckbox :model-value="!!trailingValue" @update:model-value="handleTrailingToggle" />
389
- </template>
390
- </slot>
391
- </component>
413
+ <!-- Content -->
414
+ <div class="min-w-0 flex-1">
415
+ <slot name="overline">
416
+ <p v-if="overline" class="truncate text-label-small" :class="activeIconClass">{{ overline }}</p>
417
+ </slot>
418
+ <slot>
419
+ <p class="truncate text-body-large" :class="activeTextClass">{{ title }}</p>
420
+ <p v-if="subtitle && resolvedLines >= 2" class="text-body-medium" :class="[activeIconClass, resolvedLines === 2 && 'truncate']">
421
+ {{ subtitle }}
422
+ </p>
423
+ <p v-if="description && resolvedLines >= 3" class="line-clamp-2 text-body-small" :class="activeIconClass">
424
+ {{ description }}
425
+ </p>
426
+ </slot>
427
+ </div>
428
+
429
+ <!-- Trailing -->
430
+ <slot name="trailing">
431
+ <template v-if="resolvedTrailing === 'icon'">
432
+ <MIcon :name="trailingIcon!" :size="24" class="shrink-0" :class="activeIconClass" />
433
+ </template>
434
+ <template v-else-if="resolvedTrailing === 'text'">
435
+ <span class="shrink-0 text-label-small" :class="activeIconClass">{{ trailingText }}</span>
436
+ </template>
437
+ <template v-else-if="resolvedTrailing === 'switch'">
438
+ <MSwitch :model-value="!!trailingValue" @update:model-value="handleTrailingToggle" />
439
+ </template>
440
+ <template v-else-if="resolvedTrailing === 'checkbox'">
441
+ <MCheckbox :model-value="!!trailingValue" @update:model-value="handleTrailingToggle" />
442
+ </template>
443
+ </slot>
444
+ </component>
445
+ </RowWrapper>
392
446
  </template>
393
447
 
394
448
  <style>
@@ -21,16 +21,31 @@ import { markRaw, onBeforeUnmount, onMounted, onUnmounted, provide, ref, shallow
21
21
  import type * as Maplibre from 'maplibre-gl'
22
22
  import MMapAttribution from './_MMapAttribution.vue'
23
23
  import { useLocale } from '../composables/useLocale'
24
- import { MAP_KEY, type MaplibreModule } from '../composables/useMap'
24
+ import { MAP_KEY, type MapContext, type MaplibreModule } from '../composables/useMap'
25
25
  import { createLayerState, readLayerState } from '../composables/useMapLayers'
26
26
  import type { MapAdapter, MapLayerModel } from '../composables/mapAdapters'
27
+ import { carryRuntimeLayers, styleIds, type StyleIds } from '../composables/_mapStyle'
27
28
 
28
29
  export type MapControlPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
29
30
 
30
31
  const props = withDefaults(
31
32
  defineProps<{
32
- /** The map's style: a style JSON URL or a style object (MapLibre's `StyleSpecification`). Changing it reloads the style */
33
+ /**
34
+ * The map's style: a style JSON URL or a style object (MapLibre's `StyleSpecification`). Changing it reloads the
35
+ * style, keeping what was added at runtime (see `keepLayers`)
36
+ */
33
37
  mapStyle: string | Maplibre.StyleSpecification
38
+ /**
39
+ * What happens to the sources and layers added at runtime (with `useMap()`, or by `MMapGeoJson`, `MMapMeasure`…)
40
+ * when `mapStyle` changes: `true` carries them into the new style, on top of its layers; `false` drops them, as
41
+ * MapLibre does; a function picks the layers to carry (their sources come along)
42
+ */
43
+ keepLayers?: boolean | ((layer: Maplibre.LayerSpecification) => boolean)
44
+ /**
45
+ * MapLibre's `transformStyle` for a `mapStyle` change, run after `keepLayers`: edit the next style before it
46
+ * loads (copy a layer's paint over, add a sprite…)
47
+ */
48
+ transformStyle?: Maplibre.TransformStyleFunction
34
49
  /** `[lng, lat]` (v-model). When left out, the style's (or the remembered view's) */
35
50
  center?: [number, number]
36
51
  /** Zoom level (v-model) */
@@ -64,6 +79,7 @@ const props = withDefaults(
64
79
  }>(),
65
80
  {
66
81
  persist: false,
82
+ keepLayers: true,
67
83
  navigation: true,
68
84
  geolocate: false,
69
85
  fullscreen: false,
@@ -86,10 +102,13 @@ const container = ref<HTMLElement>()
86
102
  const map = shallowRef<Maplibre.Map>()
87
103
  const maplibre = shallowRef<MaplibreModule>()
88
104
  const styleVersion = ref(0)
105
+ // The sources and layers the current style came with (the rest were added at runtime: keepLayers)
106
+ let ownIds: StyleIds | undefined
89
107
  const model = shallowRef<MapLayerModel>()
90
108
  const layerState = createLayerState()
91
109
  const activeTool = ref<string | null>(null)
92
- provide(MAP_KEY, { map, maplibre, styleVersion, model, layerState, activeTool })
110
+ const context: MapContext = { map, maplibre, styleVersion, model, layerState, activeTool }
111
+ provide(MAP_KEY, context)
93
112
 
94
113
  /** The adapter's model of the current style, and the layers' visibility and opacity in it. */
95
114
  function readModel(m: Maplibre.Map) {
@@ -276,6 +295,8 @@ onMounted(async () => {
276
295
  maplibre.value = ml
277
296
 
278
297
  m.on('style.load', () => {
298
+ // The first style's own ids; a later style's are taken in transformStyle, before runtime layers join it
299
+ if (!ownIds) ownIds = styleIds(m.getStyle())
279
300
  readModel(m)
280
301
  styleVersion.value++
281
302
  })
@@ -327,12 +348,24 @@ watch(() => props.pitch, (pitch) => {
327
348
  if (map.value && pitch !== undefined && !near(map.value.getPitch(), pitch)) map.value.jumpTo({ pitch })
328
349
  })
329
350
  watch(() => props.adapter, () => { if (map.value) readModel(map.value) })
330
- // A full reload (no diff): style.load fires, and components re-add their sources and layers
331
- watch(() => props.mapStyle, (style) => map.value?.setStyle(style, { diff: false }))
351
+ // A full reload (no diff): style.load fires, and components re-add whatever didn't come along
352
+ watch(() => props.mapStyle, (style) => map.value?.setStyle(style, {
353
+ diff: false,
354
+ transformStyle: (previous, next) => {
355
+ const own = ownIds ?? styleIds(undefined)
356
+ ownIds = styleIds(next)
357
+ const keep = props.keepLayers
358
+ let result = keep === false ? next : carryRuntimeLayers(previous, next, own, typeof keep === 'function' ? keep : undefined)
359
+ if (props.transformStyle) result = props.transformStyle(previous, result)
360
+ return result
361
+ },
362
+ }))
332
363
 
333
364
  defineExpose({
334
365
  /** The MapLibre map, once loaded */
335
366
  map,
367
+ /** What the components inside it share: pass the `MMap` (or this) as `map` to `MMapLayers`, `useMap()`… outside it */
368
+ context,
336
369
  })
337
370
  </script>
338
371
 
@@ -2,13 +2,15 @@
2
2
  /**
3
3
  * The base layer switcher of an `MMap` with an `adapter`: a round thumbnail per base layer (the adapter's `image`,
4
4
  * after `imageBase`), one shown at a time, plus "no base layer". Only the thumbnails: put them in an `MMapControl`
5
- * (`:group="false"`), an `MFab`'s `#content` or a panel. Available from the `/map` entry point.
5
+ * (`:group="false"`), an `MFab`'s `#content` or a panel, inside the `MMap` or anywhere else with `map`. Available
6
+ * from the `/map` entry point.
6
7
  */
7
8
  import MIcon from './MIcon.vue'
8
9
  import { useLocale } from '../composables/useLocale'
9
10
  import { useMapLayers } from '../composables/useMapLayers'
11
+ import type { MapSource } from '../composables/useMap'
10
12
 
11
- withDefaults(
13
+ const props = withDefaults(
12
14
  defineProps<{
13
15
  /** Prefix for the thumbnails' paths (e.g. `/images/`); full URLs are used as they are */
14
16
  imageBase?: string
@@ -16,12 +18,14 @@ withDefaults(
16
18
  none?: boolean
17
19
  /** Lay them out in a column */
18
20
  vertical?: boolean
21
+ /** The map, when this is outside it (a side panel): the `MMap`'s template ref */
22
+ map?: MapSource
19
23
  }>(),
20
24
  { imageBase: '', none: true, vertical: false },
21
25
  )
22
26
 
23
27
  const t = useLocale()
24
- const { baseLayers, baseLayer, setBaseLayer } = useMapLayers()
28
+ const { baseLayers, baseLayer, setBaseLayer } = useMapLayers(() => props.map)
25
29
 
26
30
  const src = (image: string, base: string) => (/^(https?:|data:|\/\/)/.test(image) ? image : `${base}${image}`)
27
31
  </script>
@@ -3,11 +3,12 @@
3
3
  * A simple filter for one layer of an `MMap`: chips for the values of one of its properties; the layer shows only the
4
4
  * features with the selected ones (all of them with none selected). The values are `values`, or else the distinct
5
5
  * ones among the layer's features loaded in the map. The style's own filter on the layer stays. For anything more
6
- * involved, build your own on `useMapFilter()`. Available from the `/map` entry point.
6
+ * involved, build your own on `useMapFilter()`. Inside the `MMap`, or anywhere else with `map`. Available from the `/map`
7
+ * entry point.
7
8
  */
8
9
  import { computed, onBeforeUnmount, ref, watch } from 'vue'
9
10
  import MChip from './MChip.vue'
10
- import { useMap } from '../composables/useMap'
11
+ import { useMap, type MapSource } from '../composables/useMap'
11
12
  import { useMapFilter } from '../composables/useMapFilter'
12
13
 
13
14
  const props = defineProps<{
@@ -21,12 +22,14 @@ const props = defineProps<{
21
22
  labels?: Record<string, string>
22
23
  /** The selected values (v-model) */
23
24
  modelValue?: (string | number)[]
25
+ /** The map, when this is outside it (a side panel): the `MMap`'s template ref */
26
+ map?: MapSource
24
27
  }>()
25
28
 
26
29
  const emit = defineEmits<{ 'update:modelValue': [values: (string | number)[]] }>()
27
30
 
28
- const { onReady, styleVersion } = useMap()
29
- const { setFilter, valuesOf } = useMapFilter()
31
+ const { onReady, styleVersion } = useMap(() => props.map)
32
+ const { setFilter, valuesOf } = useMapFilter(() => props.map)
30
33
 
31
34
  const found = ref<(string | number)[]>([])
32
35
  const options = computed(() => props.values ?? found.value)
@@ -10,7 +10,7 @@
10
10
  import { computed, onBeforeUnmount, useId, watch } from 'vue'
11
11
  import type * as Maplibre from 'maplibre-gl'
12
12
  import { useMap } from '../composables/useMap'
13
- import { useThemeTokens } from '../composables/_useThemeTokens'
13
+ import { useThemeTokens } from '../composables/useThemeTokens'
14
14
 
15
15
  // Omit over each member of the union (a plain Omit keeps only what all layer types share, losing paint and layout)
16
16
  type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never
@@ -3,7 +3,8 @@
3
3
  * The layer list of an `MMap` with an `adapter`: a search field, the style's groups (collapsible, with a visibility
4
4
  * toggle for the whole group and a count) and its layers, each with a visibility toggle and, expanded, its
5
5
  * description, an opacity slider, its legend and a download link. Only the content: put it in an `MWindow`, an
6
- * `MSideSheet`, an `MBottomSheet` or an `MMapControl`. Available from the `/map` entry point.
6
+ * `MSideSheet`, an `MBottomSheet` or an `MMapControl`, inside the `MMap` or anywhere else with `map`. Available from the
7
+ * `/map` entry point.
7
8
  *
8
9
  * @slot actions Extra actions in an expanded layer (scope: `{ layer, visible }`)
9
10
  */
@@ -13,6 +14,7 @@ import MTextField from './MTextField.vue'
13
14
  import MMapLayerItem from './_MMapLayerItem.vue'
14
15
  import { useLocale } from '../composables/useLocale'
15
16
  import { useMapLayers } from '../composables/useMapLayers'
17
+ import type { MapSource } from '../composables/useMap'
16
18
  import type { MapLayerInfo } from '../composables/mapAdapters'
17
19
 
18
20
  const props = withDefaults(
@@ -21,12 +23,14 @@ const props = withDefaults(
21
23
  search?: boolean
22
24
  /** Groups start collapsed */
23
25
  collapsed?: boolean
26
+ /** The map, when this is outside it (a side panel): the `MMap`'s template ref */
27
+ map?: MapSource
24
28
  }>(),
25
29
  { search: true, collapsed: false },
26
30
  )
27
31
 
28
32
  const t = useLocale()
29
- const { model, layersOf, isVisible, groupState, setGroupVisible } = useMapLayers()
33
+ const { model, layersOf, isVisible, groupState, setGroupVisible } = useMapLayers(() => props.map)
30
34
 
31
35
  const query = ref('')
32
36
  const matches = (layer: MapLayerInfo) => !query.value || layer.title.toLowerCase().includes(query.value.toLowerCase())
@@ -17,7 +17,8 @@ import MMapControl from './MMapControl.vue'
17
17
  import MMapMarker from './MMapMarker.vue'
18
18
  import { useLocale } from '../composables/useLocale'
19
19
  import { useMap } from '../composables/useMap'
20
- import { useThemeTokens } from '../composables/_useThemeTokens'
20
+ import { useThemeTokens } from '../composables/useThemeTokens'
21
+ import { useEscapeStack } from '../composables/_useEscapeStack'
21
22
  import { centroid, closeRing, distance, midpoint, pathLength, ringArea, type LngLat } from '../composables/_mapGeometry'
22
23
  import type { MapControlPosition } from './MMap.vue'
23
24
 
@@ -216,9 +217,11 @@ function onDblClick(e: Maplibre.MapMouseEvent) {
216
217
  finish()
217
218
  }
218
219
 
220
+ // Enter finishes; Escape goes through the library's stack, so measuring on a map in a dialog doesn't close it too
219
221
  function onKey(e: KeyboardEvent) {
220
- if (e.key === 'Escape' || e.key === 'Enter') finish(e.key === 'Escape')
222
+ if (e.key === 'Enter') finish()
221
223
  }
224
+ useEscapeStack(() => !!mode.value, () => finish(true))
222
225
 
223
226
  // In fullscreen the browser keeps Escape to leave it, and the page never sees it. Keyboard Lock (Chromium) lets the
224
227
  // page have it while measuring, so Escape finishes the measurement (holding Escape still leaves fullscreen)