@m3ui-vue/m3ui-vue 1.0.2 → 1.1.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 (157) hide show
  1. package/dist/API.md +666 -12
  2. package/dist/MMenuItem-BOkcVtEe.js +809 -0
  3. package/dist/MMenuItem-BOkcVtEe.js.map +1 -0
  4. package/dist/MSlider-BXsBv0ox.js +1402 -0
  5. package/dist/MSlider-BXsBv0ox.js.map +1 -0
  6. package/dist/MTextField-rML9jnXs.js +671 -0
  7. package/dist/MTextField-rML9jnXs.js.map +1 -0
  8. package/dist/api.json +1 -1
  9. package/dist/code-editor.js +1 -1
  10. package/dist/components/MBottomSheet.vue.d.ts +20 -1
  11. package/dist/components/MDialog.vue.d.ts +17 -8
  12. package/dist/components/MDragDropList.vue.d.ts +1 -1
  13. package/dist/components/MIconButton.vue.d.ts +1 -1
  14. package/dist/components/MMap.vue.d.ts +74 -0
  15. package/dist/components/MMapBaseLayers.vue.d.ts +15 -0
  16. package/dist/components/MMapControl.vue.d.ts +40 -0
  17. package/dist/components/MMapFeatureInfo.vue.d.ts +25 -0
  18. package/dist/components/MMapFilter.vue.d.ts +19 -0
  19. package/dist/components/MMapGeoJson.vue.d.ts +34 -0
  20. package/dist/components/MMapHover.vue.d.ts +17 -0
  21. package/dist/components/MMapIdentify.vue.d.ts +37 -0
  22. package/dist/components/MMapLayers.vue.d.ts +31 -0
  23. package/dist/components/MMapMarker.vue.d.ts +45 -0
  24. package/dist/components/MMapMeasure.vue.d.ts +43 -0
  25. package/dist/components/MMapPopup.vue.d.ts +45 -0
  26. package/dist/components/MMapSearch.vue.d.ts +28 -0
  27. package/dist/components/MMenuItem.vue.d.ts +2 -2
  28. package/dist/components/MSeekBar.vue.d.ts +122 -0
  29. package/dist/components/MSplitButton.vue.d.ts +2 -2
  30. package/dist/components/_MMapAttribution.vue.d.ts +7 -0
  31. package/dist/components/_MMapLayerItem.vue.d.ts +25 -0
  32. package/dist/composables/_mapGeometry.d.ts +13 -0
  33. package/dist/composables/_mapPin.d.ts +5 -0
  34. package/dist/composables/_popupPosition.d.ts +12 -0
  35. package/dist/composables/_ssrState.d.ts +30 -0
  36. package/dist/composables/_storageKeys.d.ts +3 -0
  37. package/dist/composables/_useCalendarMonth.d.ts +24 -0
  38. package/dist/composables/_useEscapeStack.d.ts +3 -0
  39. package/dist/composables/_useScrollLock.d.ts +8 -0
  40. package/dist/composables/_useSheetMotion.d.ts +16 -1
  41. package/dist/composables/_useThemeTokens.d.ts +7 -0
  42. package/dist/composables/mapAdapters.d.ts +111 -0
  43. package/dist/composables/mapSearch.d.ts +31 -0
  44. package/dist/composables/themeInitScript.d.ts +4 -3
  45. package/dist/composables/useColorPalette.d.ts +173 -7
  46. package/dist/composables/useLocale.d.ts +38 -0
  47. package/dist/composables/useMap.d.ts +47 -0
  48. package/dist/composables/useMapFilter.d.ts +10 -0
  49. package/dist/composables/useMapLayers.d.ts +30 -0
  50. package/dist/composables/useTheme.d.ts +2 -1
  51. package/dist/index.d.ts +4 -1
  52. package/dist/locales/index.js +273 -7
  53. package/dist/locales/index.js.map +1 -1
  54. package/dist/m3ui-vue.css +1 -1
  55. package/dist/m3ui.js +7913 -8625
  56. package/dist/m3ui.js.map +1 -1
  57. package/dist/map.d.ts +24 -0
  58. package/dist/map.js +2067 -0
  59. package/dist/map.js.map +1 -0
  60. package/dist/plugin.d.ts +18 -2
  61. package/dist/rich-text-editor.js +26 -25
  62. package/dist/rich-text-editor.js.map +1 -1
  63. package/dist/styles.css +1 -1
  64. package/dist/{useLocale-CuvWRZ1h.js → useLocale-CqQrhWFl.js} +40 -2
  65. package/dist/useLocale-CqQrhWFl.js.map +1 -0
  66. package/package.json +11 -2
  67. package/src/__tests__/MDialog.test.ts +30 -0
  68. package/src/__tests__/MFab.test.ts +52 -6
  69. package/src/__tests__/MMap.test.ts +422 -0
  70. package/src/__tests__/MMapLayers.test.ts +257 -0
  71. package/src/__tests__/MMapTools.test.ts +233 -0
  72. package/src/__tests__/MSeekBar.test.ts +170 -0
  73. package/src/__tests__/MTooltip.test.ts +110 -0
  74. package/src/__tests__/_fakeMaplibre.ts +161 -0
  75. package/src/__tests__/calendarMonth.test.ts +59 -0
  76. package/src/__tests__/hydration.test.ts +33 -0
  77. package/src/__tests__/pickerModals.test.ts +128 -0
  78. package/src/__tests__/popupPosition.test.ts +224 -0
  79. package/src/__tests__/scrollLock.test.ts +110 -0
  80. package/src/__tests__/sheets.test.ts +158 -0
  81. package/src/__tests__/ssr.test.ts +63 -1
  82. package/src/__tests__/ssrState.test.ts +155 -0
  83. package/src/__tests__/themeInitScript.test.ts +18 -0
  84. package/src/components/MAutocomplete.vue +2 -4
  85. package/src/components/MBottomSheet.vue +211 -13
  86. package/src/components/MCommandPalette.vue +4 -6
  87. package/src/components/MContextMenu.vue +19 -5
  88. package/src/components/MDatePicker.vue +29 -70
  89. package/src/components/MDatePickerModal.vue +116 -172
  90. package/src/components/MDateRangePicker.vue +29 -51
  91. package/src/components/MDateRangePickerModal.vue +84 -162
  92. package/src/components/MDialog.vue +87 -63
  93. package/src/components/MFab.vue +29 -7
  94. package/src/components/MIconButton.vue +1 -1
  95. package/src/components/MLightbox.vue +12 -5
  96. package/src/components/MMap.vue +568 -0
  97. package/src/components/MMapBaseLayers.vue +67 -0
  98. package/src/components/MMapControl.vue +175 -0
  99. package/src/components/MMapFeatureInfo.vue +41 -0
  100. package/src/components/MMapFilter.vue +80 -0
  101. package/src/components/MMapGeoJson.vue +136 -0
  102. package/src/components/MMapHover.vue +131 -0
  103. package/src/components/MMapIdentify.vue +104 -0
  104. package/src/components/MMapLayers.vue +111 -0
  105. package/src/components/MMapMarker.vue +109 -0
  106. package/src/components/MMapMeasure.vue +452 -0
  107. package/src/components/MMapPopup.vue +103 -0
  108. package/src/components/MMapSearch.vue +162 -0
  109. package/src/components/MMenu.vue +31 -12
  110. package/src/components/MMenuItem.vue +21 -4
  111. package/src/components/MMultiAutocomplete.vue +2 -4
  112. package/src/components/MMultiSelect.vue +2 -4
  113. package/src/components/MNavigationDrawer.vue +2 -8
  114. package/src/components/MNavigationRail.vue +2 -3
  115. package/src/components/MSearchBar.vue +2 -5
  116. package/src/components/MSeekBar.vue +593 -0
  117. package/src/components/MSelect.vue +2 -8
  118. package/src/components/MSplitButton.vue +23 -7
  119. package/src/components/MSpotlightSearch.vue +4 -6
  120. package/src/components/MTimePicker.vue +23 -6
  121. package/src/components/MTimePickerModal.vue +213 -226
  122. package/src/components/MTooltip.vue +99 -3
  123. package/src/components/_MMapAttribution.vue +81 -0
  124. package/src/components/_MMapLayerItem.vue +77 -0
  125. package/src/composables/_mapGeometry.ts +75 -0
  126. package/src/composables/_mapPin.ts +25 -0
  127. package/src/composables/_popupPosition.ts +39 -0
  128. package/src/composables/_ssrState.ts +80 -0
  129. package/src/composables/_storageKeys.ts +6 -0
  130. package/src/composables/_useCalendarMonth.ts +74 -0
  131. package/src/composables/_useEscapeStack.ts +33 -0
  132. package/src/composables/_useScrollLock.ts +41 -0
  133. package/src/composables/_useSheetMotion.ts +82 -20
  134. package/src/composables/_useThemeTokens.ts +42 -0
  135. package/src/composables/mapAdapters.ts +208 -0
  136. package/src/composables/mapSearch.ts +56 -0
  137. package/src/composables/themeInitScript.ts +6 -4
  138. package/src/composables/useColorPalette.ts +23 -9
  139. package/src/composables/useLocale.ts +78 -0
  140. package/src/composables/useMap.ts +98 -0
  141. package/src/composables/useMapFilter.ts +45 -0
  142. package/src/composables/useMapLayers.ts +124 -0
  143. package/src/composables/useTheme.ts +8 -3
  144. package/src/composables/useWindowSizeClass.ts +14 -5
  145. package/src/index.ts +4 -1
  146. package/src/locales/de.ts +39 -1
  147. package/src/locales/es.ts +39 -1
  148. package/src/locales/fr.ts +39 -1
  149. package/src/locales/ja.ts +39 -1
  150. package/src/locales/ko.ts +39 -1
  151. package/src/locales/pt.ts +39 -1
  152. package/src/locales/zh.ts +39 -1
  153. package/src/map.ts +32 -0
  154. package/src/plugin.ts +54 -3
  155. package/dist/MTextField-BPbFeI9M.js +0 -1368
  156. package/dist/MTextField-BPbFeI9M.js.map +0 -1
  157. package/dist/useLocale-CuvWRZ1h.js.map +0 -1
@@ -0,0 +1,162 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * A place search on an `MMap`: a search card in a corner. Enter searches through `provider` (OpenStreetMap's
4
+ * Nominatim by default, or any function returning places); picking a result flies there (or fits its extent) and
5
+ * marks it. Available from the `/map` entry point.
6
+ *
7
+ * @event select A result was picked
8
+ */
9
+ import { computed, onBeforeUnmount, ref, shallowRef } from 'vue'
10
+ import type * as Maplibre from 'maplibre-gl'
11
+ import MCard from './MCard.vue'
12
+ import MIcon from './MIcon.vue'
13
+ import MIconButton from './MIconButton.vue'
14
+ import MList from './MList.vue'
15
+ import MListItem from './MListItem.vue'
16
+ import MSpinner from './MSpinner.vue'
17
+ import MMapControl from './MMapControl.vue'
18
+ import MMapMarker from './MMapMarker.vue'
19
+ import { useLocale } from '../composables/useLocale'
20
+ import { useMap } from '../composables/useMap'
21
+ import { nominatimProvider, type MapSearchProvider, type MapSearchResult } from '../composables/mapSearch'
22
+ import type { MapControlPosition } from './MMap.vue'
23
+
24
+ const props = withDefaults(
25
+ defineProps<{
26
+ /** Where to search: `nominatimProvider(options)` by default, or your own function */
27
+ provider?: MapSearchProvider
28
+ /** The corner */
29
+ position?: MapControlPosition
30
+ /** The field's placeholder (the locale's "Search places" by default) */
31
+ placeholder?: string
32
+ /** The zoom to fly to for a result without an extent */
33
+ zoom?: number
34
+ /** Mark the picked result */
35
+ marker?: boolean
36
+ /** Search while typing (debounced), for providers that allow it; Nominatim's public server doesn't */
37
+ instant?: boolean
38
+ }>(),
39
+ { position: 'top-left', zoom: 17, marker: true, instant: false },
40
+ )
41
+
42
+ const emit = defineEmits<{ select: [result: MapSearchResult] }>()
43
+
44
+ const t = useLocale()
45
+ const { map } = useMap()
46
+ const provider = computed(() => props.provider ?? nominatimProvider())
47
+
48
+ const query = ref('')
49
+ const results = shallowRef<MapSearchResult[]>([])
50
+ const loading = ref(false)
51
+ const searched = ref(false)
52
+ const open = ref(false)
53
+ const picked = shallowRef<MapSearchResult | null>(null)
54
+ let controller: AbortController | undefined
55
+ let debounce: ReturnType<typeof setTimeout> | undefined
56
+
57
+ async function search() {
58
+ const q = query.value.trim()
59
+ if (!q) return
60
+ controller?.abort()
61
+ controller = new AbortController()
62
+ const mine = controller
63
+ loading.value = true
64
+ open.value = true
65
+ try {
66
+ results.value = await provider.value(q, mine.signal)
67
+ } catch {
68
+ if (mine.signal.aborted) return
69
+ results.value = []
70
+ } finally {
71
+ if (controller === mine) {
72
+ loading.value = false
73
+ searched.value = true
74
+ }
75
+ }
76
+ }
77
+
78
+ function onInput(value: string) {
79
+ query.value = value
80
+ if (!value) return clear()
81
+ if (props.instant) {
82
+ clearTimeout(debounce)
83
+ debounce = setTimeout(search, 350)
84
+ }
85
+ }
86
+
87
+ function select(result: MapSearchResult) {
88
+ picked.value = result
89
+ open.value = false
90
+ const m = map.value as Maplibre.Map | undefined
91
+ if (result.bbox && result.bbox[0] !== result.bbox[2]) m?.fitBounds([[result.bbox[0], result.bbox[1]], [result.bbox[2], result.bbox[3]]], { padding: 48, maxZoom: props.zoom })
92
+ else m?.flyTo({ center: result.lngLat, zoom: props.zoom })
93
+ emit('select', result)
94
+ }
95
+
96
+ function clear() {
97
+ controller?.abort()
98
+ clearTimeout(debounce)
99
+ query.value = ''
100
+ results.value = []
101
+ searched.value = false
102
+ loading.value = false
103
+ open.value = false
104
+ picked.value = null
105
+ }
106
+
107
+ onBeforeUnmount(() => {
108
+ controller?.abort()
109
+ clearTimeout(debounce)
110
+ })
111
+
112
+ const ICONS: Record<string, string> = {
113
+ city: 'location_city', town: 'location_city', village: 'holiday_village', hamlet: 'cottage', suburb: 'apartment',
114
+ neighbourhood: 'maps_home_work', road: 'road', residential: 'home', house: 'home', building: 'domain',
115
+ shop: 'storefront', park: 'park', water: 'water', river: 'water', lake: 'water', school: 'school',
116
+ university: 'school', hospital: 'local_hospital', restaurant: 'restaurant', cafe: 'local_cafe', hotel: 'hotel',
117
+ station: 'train', bus_stop: 'directions_bus', administrative: 'map', country: 'public', state: 'map',
118
+ }
119
+ const iconOf = (type?: string) => (type && ICONS[type]) || 'location_on'
120
+ </script>
121
+
122
+ <template>
123
+ <div class="hidden">
124
+ <MMapControl :position="position" :group="false">
125
+ <MCard variant="elevated" class="w-80 max-w-[calc(100vw-5rem)] overflow-hidden">
126
+ <form class="flex items-center gap-2 py-1 pr-1 pl-3" role="search" @submit.prevent="search">
127
+ <MIcon name="search" :size="20" class="shrink-0 text-on-surface-variant" />
128
+ <input
129
+ :value="query"
130
+ type="search"
131
+ enterkeyhint="search"
132
+ :placeholder="placeholder ?? t.mapSearchPlaces"
133
+ :aria-label="placeholder ?? t.mapSearchPlaces"
134
+ class="min-w-0 flex-1 bg-transparent py-2 text-body-medium text-on-surface outline-none placeholder:text-on-surface-variant [&::-webkit-search-cancel-button]:hidden"
135
+ @input="onInput(($event.target as HTMLInputElement).value)"
136
+ @focus="open = searched && !picked"
137
+ >
138
+ <MSpinner v-if="loading" :size="20" class="mr-2 shrink-0" />
139
+ <MIconButton v-else-if="query" icon="close" :label="t.clearSearch" size="sm" @click="clear" />
140
+ </form>
141
+ <div v-if="open && searched && !loading" class="border-t border-outline-variant">
142
+ <MList v-if="results.length" class="max-h-72 overflow-y-auto">
143
+ <MListItem
144
+ v-for="(r, i) in results"
145
+ :key="i"
146
+ :title="r.label"
147
+ :icon="iconOf(r.type)"
148
+ leading="icon"
149
+ clickable
150
+ @click="select(r)"
151
+ />
152
+ </MList>
153
+ <div v-else class="flex flex-col items-center gap-2 py-6">
154
+ <MIcon name="search_off" :size="28" class="text-on-surface-variant" />
155
+ <span class="text-body-small text-on-surface-variant">{{ t.noResults }}</span>
156
+ </div>
157
+ </div>
158
+ </MCard>
159
+ </MMapControl>
160
+ <MMapMarker v-if="marker && picked" :lng-lat="picked.lngLat" />
161
+ </div>
162
+ </template>
@@ -9,6 +9,7 @@
9
9
  import { computed, Fragment, inject, nextTick, onMounted, onUnmounted, provide, ref, useSlots, watch, type VNode } from 'vue'
10
10
  import MIcon from './MIcon.vue'
11
11
  import MMenuDivider from './MMenuDivider.vue'
12
+ import { POPUP_MARGIN, dropdownX } from '../composables/_popupPosition'
12
13
 
13
14
  defineOptions({ inheritAttrs: false })
14
15
 
@@ -221,6 +222,7 @@ function playTrajectory(el: Element, done: () => void, opening: boolean) {
221
222
  finishLeave = opening ? null : () => { cancelActive?.(); cancelActive = null; finishLeave = null; done() }
222
223
  }
223
224
  function panelEnter(el: Element, done: () => void) {
225
+ placeX(el as HTMLElement)
224
226
  playTrajectory(el, done, true)
225
227
  }
226
228
  function panelLeave(el: Element, done: () => void) {
@@ -275,31 +277,50 @@ onUnmounted(() => {
275
277
  const siblingGroup = inject<{ current: (() => void) | null } | null>('m-menu-sibling-group', null)
276
278
  provide('m-menu-sibling-group', { current: null })
277
279
 
280
+ // The vertical side and height from the trigger alone; the horizontal position needs the panel's width, so
281
+ // placeX() sets it once the panel is in the DOM (in its enter hook, before it paints). Until then it sits at the
282
+ // window's left edge, where nothing narrows it while it's measured.
283
+ let anchorRect: DOMRect | null = null
284
+ const openAbove = ref(false)
278
285
  function computePos() {
279
286
  if (!triggerEl.value) return
280
287
  const rect = triggerEl.value.getBoundingClientRect()
288
+ anchorRect = rect
281
289
  const spaceBelow = window.innerHeight - rect.bottom - 8
282
- const openAbove = spaceBelow < 200 && rect.top > spaceBelow
290
+ openAbove.value = spaceBelow < 200 && rect.top > spaceBelow
283
291
 
284
292
  const style: Record<string, string> = {
285
- maxHeight: `${Math.min(openAbove ? rect.top - 12 : spaceBelow, 400)}px`,
293
+ maxHeight: `${Math.min(openAbove.value ? rect.top - 12 : spaceBelow, 400)}px`,
294
+ maxWidth: `${window.innerWidth - 2 * POPUP_MARGIN}px`,
295
+ left: '0px',
286
296
  }
287
297
 
288
- if (openAbove) {
298
+ if (openAbove.value) {
289
299
  style.bottom = `${window.innerHeight - rect.top + 4}px`
290
300
  } else {
291
301
  style.top = `${rect.bottom + 4}px`
292
302
  }
293
303
 
294
- if (props.align === 'right') {
295
- style.right = `${window.innerWidth - rect.right}px`
296
- } else {
297
- style.left = `${rect.left}px`
298
- }
299
-
300
304
  dropStyle.value = style
301
305
  }
302
306
 
307
+ // Keeps the panel on screen (Compose's DropdownMenuPositionProvider, see _popupPosition.ts): aligned with the
308
+ // trigger's `align` edge if it fits there, else its other edge, else against the window edge on its side. The
309
+ // animation grows from the trigger, wherever the panel ended up.
310
+ const originX = ref(props.align === 'right' ? 'right' : 'left')
311
+ function placeX(el: HTMLElement) {
312
+ if (!anchorRect) return
313
+ const width = el.offsetWidth
314
+ const x = dropdownX(anchorRect, width, window.innerWidth, props.align === 'right' ? 'end' : 'start')
315
+ const pivot = Math.min(width, Math.max(0, (anchorRect.left + anchorRect.right) / 2 - x))
316
+ const fromEdge = Math.abs(x - anchorRect.left) < 1 ? 'left' : Math.abs(x + width - anchorRect.right) < 1 ? 'right' : `${pivot}px`
317
+ originX.value = fromEdge
318
+ dropStyle.value = { ...dropStyle.value, left: `${x}px` }
319
+ // Now, not on the next render: the enter animation starts this frame
320
+ el.style.left = `${x}px`
321
+ el.style.transformOrigin = `${fromEdge} ${openAbove.value ? 'bottom' : 'top'}`
322
+ }
323
+
303
324
  function focusableItems() {
304
325
  if (!dropdownEl.value) return []
305
326
  return Array.from(
@@ -392,9 +413,7 @@ onUnmounted(() => {
392
413
  else cancelActive?.()
393
414
  })
394
415
 
395
- const origin = computed(() =>
396
- props.align === 'right' ? 'top right' : 'top left',
397
- )
416
+ const origin = computed(() => `${originX.value} ${openAbove.value ? 'bottom' : 'top'}`)
398
417
  </script>
399
418
 
400
419
  <template>
@@ -16,6 +16,7 @@
16
16
  import { computed, inject, nextTick, onMounted, onUnmounted, ref, useSlots, watch } from 'vue'
17
17
  import MIcon from './MIcon.vue'
18
18
  import { FAST_EFFECTS, FAST_SPATIAL, useSpring } from '../composables/_useSpring'
19
+ import { POPUP_MARGIN, fitPopup } from '../composables/_popupPosition'
19
20
 
20
21
  const props = withDefaults(defineProps<{
21
22
  /** Material Symbol icon name */
@@ -123,20 +124,35 @@ const iconSlotEl = ref<HTMLElement>()
123
124
  const showSub = ref(false)
124
125
  const subStyle = ref<Record<string, string>>({})
125
126
 
127
+ // To the item's right, else its left, else clamped on screen (see _popupPosition.ts); placeSub() settles it once
128
+ // the submenu is in the DOM and its size is known, before it paints
126
129
  function positionSub() {
127
130
  if (!itemEl.value) return
128
131
  const rect = itemEl.value.getBoundingClientRect()
129
- const right = rect.right + 200 > window.innerWidth
130
132
  subStyle.value = {
131
133
  position: 'fixed',
132
134
  top: `${rect.top}px`,
133
- ...(right
134
- ? { right: `${window.innerWidth - rect.left}px` }
135
- : { left: `${rect.right}px` }),
135
+ left: `${rect.right}px`,
136
+ maxWidth: `${window.innerWidth - 2 * POPUP_MARGIN}px`,
136
137
  zIndex: '501',
137
138
  }
138
139
  }
139
140
 
141
+ function placeSub(el: Element) {
142
+ if (!itemEl.value) return
143
+ const sub = el as HTMLElement
144
+ const rect = itemEl.value.getBoundingClientRect()
145
+ // Measured at the window's left edge, where nothing narrows it
146
+ sub.style.left = '0px'
147
+ const w = sub.offsetWidth
148
+ const h = sub.offsetHeight
149
+ const left = fitPopup([rect.right, rect.left - w], w, window.innerWidth)
150
+ const top = fitPopup([rect.top, rect.bottom - h], h, window.innerHeight)
151
+ subStyle.value = { ...subStyle.value, left: `${left}px`, top: `${top}px` }
152
+ sub.style.left = `${left}px`
153
+ sub.style.top = `${top}px`
154
+ }
155
+
140
156
  function toggleSub() {
141
157
  if (showSub.value) {
142
158
  showSub.value = false
@@ -246,6 +262,7 @@ function onSubPointerLeave(e: PointerEvent) {
246
262
  enter-from-class="opacity-0"
247
263
  leave-active-class="transition-opacity duration-75"
248
264
  leave-to-class="opacity-0"
265
+ @enter="placeSub"
249
266
  >
250
267
  <div
251
268
  v-if="showSub"
@@ -13,6 +13,7 @@ import { useFieldBg } from '../composables/useFieldBg'
13
13
  import { useLocale } from '../composables/useLocale'
14
14
  import { useDebounce } from '../composables/useDebounce'
15
15
  import type { MultiSelectOption } from './MMultiSelect.vue'
16
+ import { useScrollLock } from '../composables/_useScrollLock'
16
17
 
17
18
  // Root is a fragment (field div + a sibling Teleport for the dropdown panel), so Vue can't
18
19
  // auto-apply a consumer's class/attrs to either one — forward them onto the field div below.
@@ -215,9 +216,7 @@ function closeDropdown() {
215
216
  highlightIndex.value = -1
216
217
  }
217
218
 
218
- watch(modalOpen, (v) => {
219
- document.body.style.overflow = v ? 'hidden' : ''
220
- })
219
+ useScrollLock(modalOpen)
221
220
 
222
221
  function onInputFocus() {
223
222
  openDropdown()
@@ -311,7 +310,6 @@ onMounted(() => {
311
310
  onUnmounted(() => {
312
311
  document.removeEventListener('mousedown', onOutsideClick)
313
312
  window.removeEventListener('scroll', onScroll, true)
314
- document.body.style.overflow = ''
315
313
  })
316
314
 
317
315
  watch(filteredOptions, () => {
@@ -11,6 +11,7 @@ import MIconButton from './MIconButton.vue'
11
11
  import MCheckbox from './MCheckbox.vue'
12
12
  import { useFieldBg } from '../composables/useFieldBg'
13
13
  import { useLocale } from '../composables/useLocale'
14
+ import { useScrollLock } from '../composables/_useScrollLock'
14
15
 
15
16
  const locale = useLocale()
16
17
 
@@ -195,9 +196,7 @@ const modalFilteredOptions = computed(() => {
195
196
  return opts.filter((o) => o.label.toLowerCase().includes(q))
196
197
  })
197
198
 
198
- watch(modalOpen, (v) => {
199
- document.body.style.overflow = v ? 'hidden' : ''
200
- })
199
+ useScrollLock(modalOpen)
201
200
 
202
201
  function onOutsideClick(e: MouseEvent) {
203
202
  if (modalOpen.value) return
@@ -218,7 +217,6 @@ onMounted(() => {
218
217
  onUnmounted(() => {
219
218
  document.removeEventListener('mousedown', onOutsideClick)
220
219
  window.removeEventListener('scroll', onScroll, true)
221
- document.body.style.overflow = ''
222
220
  })
223
221
 
224
222
  const triggerClasses = computed(() => {
@@ -19,6 +19,7 @@ import MIcon from "./MIcon.vue";
19
19
  import MDrawerItemList from "./_MDrawerItemList.vue";
20
20
  import { motionSprings, type SpringSpec } from "../composables/motion";
21
21
  import { sampleSpring, sampleAt, playSamples, prefersReducedMotion } from "../composables/_springAnimation";
22
+ import { useScrollLock } from '../composables/_useScrollLock'
22
23
 
23
24
  export interface DrawerItem {
24
25
  value: string | number;
@@ -153,14 +154,7 @@ function itemTag(item: DrawerItem) {
153
154
  return item.to && !item.disabled ? "RouterLink" : "button";
154
155
  }
155
156
 
156
- watch(
157
- () => props.modelValue,
158
- (open) => {
159
- if (props.modal) {
160
- document.body.style.overflow = open ? "hidden" : "";
161
- }
162
- },
163
- );
157
+ useScrollLock(() => props.modal && props.modelValue);
164
158
 
165
159
  // ── Modal: slide in/out + swipe to close ────────────────────────────────────────────────────
166
160
  // After ModalNavigationDrawer (NavigationDrawer.kt), which is left/right only; top/bottom add a bottom sheet's
@@ -13,6 +13,7 @@ import MIcon from './MIcon.vue'
13
13
  import MBadge from './MBadge.vue'
14
14
  import { useItemLink, type ItemLink } from '../composables/_useItemLink'
15
15
  import { sampleSpring, sampleAt, playSamples, prefersReducedMotion } from '../composables/_springAnimation'
16
+ import { useScrollLock } from '../composables/_useScrollLock'
16
17
 
17
18
  export interface NavRailItem {
18
19
  value: string | number
@@ -338,10 +339,8 @@ watch(
338
339
  (open) => {
339
340
  if (open) {
340
341
  document.addEventListener('keydown', onKeydown)
341
- document.body.style.overflow = 'hidden'
342
342
  } else {
343
343
  document.removeEventListener('keydown', onKeydown)
344
- document.body.style.overflow = ''
345
344
  }
346
345
  },
347
346
  )
@@ -350,8 +349,8 @@ onUnmounted(() => {
350
349
  slideAnim?.cancel()
351
350
  slideScrimAnim?.cancel()
352
351
  document.removeEventListener('keydown', onKeydown)
353
- if (props.modal && props.expanded) document.body.style.overflow = ''
354
352
  })
353
+ useScrollLock(() => props.modal && props.expanded)
355
354
  </script>
356
355
 
357
356
  <template>
@@ -19,6 +19,7 @@ import MIconButton from './MIconButton.vue'
19
19
  import MSpinner from './MSpinner.vue'
20
20
  import { useLocale } from '../composables/useLocale'
21
21
  import { searchAppBarKey } from '../composables/_searchAppBar'
22
+ import { useScrollLock } from '../composables/_useScrollLock'
22
23
 
23
24
  // Root is a fragment (bar div + a sibling Teleport for the expanded overlay panel), so Vue
24
25
  // can't auto-apply a consumer's class/attrs to either one — forward them onto the bar div below.
@@ -149,11 +150,7 @@ onUnmounted(() => {
149
150
  window.removeEventListener('scroll', onScroll, true)
150
151
  })
151
152
 
152
- watch(expanded, (v) => {
153
- if (v && fullscreen.value) document.body.style.overflow = 'hidden'
154
- else document.body.style.overflow = ''
155
- })
156
- onUnmounted(() => { document.body.style.overflow = '' })
153
+ useScrollLock(() => expanded.value && fullscreen.value)
157
154
  </script>
158
155
 
159
156
  <template>