@m3ui-vue/m3ui-vue 1.0.3 → 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 (99) hide show
  1. package/dist/API.md +75 -11
  2. package/dist/MMenuItem-BOkcVtEe.js +809 -0
  3. package/dist/MMenuItem-BOkcVtEe.js.map +1 -0
  4. package/dist/{MSlider-CdNIH7jc.js → MSlider-BXsBv0ox.js} +208 -182
  5. package/dist/MSlider-BXsBv0ox.js.map +1 -0
  6. package/dist/{MTextField-B4X92vH_.js → MTextField-rML9jnXs.js} +2 -2
  7. package/dist/{MTextField-B4X92vH_.js.map → MTextField-rML9jnXs.js.map} +1 -1
  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/MMap.vue.d.ts +4 -4
  14. package/dist/components/MMapControl.vue.d.ts +20 -3
  15. package/dist/components/MMapMarker.vue.d.ts +5 -2
  16. package/dist/components/MMapPopup.vue.d.ts +5 -3
  17. package/dist/components/MMenuItem.vue.d.ts +2 -2
  18. package/dist/components/MSeekBar.vue.d.ts +122 -0
  19. package/dist/components/MSplitButton.vue.d.ts +2 -2
  20. package/dist/components/_MMapAttribution.vue.d.ts +7 -0
  21. package/dist/composables/_mapPin.d.ts +5 -0
  22. package/dist/composables/_popupPosition.d.ts +12 -0
  23. package/dist/composables/_useCalendarMonth.d.ts +24 -0
  24. package/dist/composables/_useEscapeStack.d.ts +3 -0
  25. package/dist/composables/_useScrollLock.d.ts +8 -0
  26. package/dist/composables/_useSheetMotion.d.ts +16 -1
  27. package/dist/composables/useLocale.d.ts +8 -0
  28. package/dist/index.d.ts +2 -0
  29. package/dist/locales/index.js +56 -0
  30. package/dist/locales/index.js.map +1 -1
  31. package/dist/m3ui-vue.css +1 -1
  32. package/dist/m3ui.js +5269 -4714
  33. package/dist/m3ui.js.map +1 -1
  34. package/dist/map.js +777 -641
  35. package/dist/map.js.map +1 -1
  36. package/dist/rich-text-editor.js +8 -8
  37. package/dist/styles.css +1 -1
  38. package/dist/{useLocale-b5-hzsL3.js → useLocale-CqQrhWFl.js} +9 -1
  39. package/dist/useLocale-CqQrhWFl.js.map +1 -0
  40. package/package.json +1 -1
  41. package/src/__tests__/MDialog.test.ts +30 -0
  42. package/src/__tests__/MMap.test.ts +132 -2
  43. package/src/__tests__/MSeekBar.test.ts +170 -0
  44. package/src/__tests__/MTooltip.test.ts +110 -0
  45. package/src/__tests__/_fakeMaplibre.ts +3 -0
  46. package/src/__tests__/calendarMonth.test.ts +59 -0
  47. package/src/__tests__/pickerModals.test.ts +128 -0
  48. package/src/__tests__/popupPosition.test.ts +224 -0
  49. package/src/__tests__/scrollLock.test.ts +110 -0
  50. package/src/__tests__/sheets.test.ts +158 -0
  51. package/src/components/MAutocomplete.vue +2 -4
  52. package/src/components/MBottomSheet.vue +211 -13
  53. package/src/components/MCommandPalette.vue +4 -6
  54. package/src/components/MContextMenu.vue +19 -5
  55. package/src/components/MDatePicker.vue +29 -70
  56. package/src/components/MDatePickerModal.vue +116 -172
  57. package/src/components/MDateRangePicker.vue +29 -51
  58. package/src/components/MDateRangePickerModal.vue +84 -162
  59. package/src/components/MDialog.vue +87 -63
  60. package/src/components/MLightbox.vue +6 -3
  61. package/src/components/MMap.vue +74 -28
  62. package/src/components/MMapControl.vue +121 -7
  63. package/src/components/MMapIdentify.vue +2 -1
  64. package/src/components/MMapMarker.vue +14 -7
  65. package/src/components/MMapPopup.vue +8 -4
  66. package/src/components/MMenu.vue +31 -12
  67. package/src/components/MMenuItem.vue +21 -4
  68. package/src/components/MMultiAutocomplete.vue +2 -4
  69. package/src/components/MMultiSelect.vue +2 -4
  70. package/src/components/MNavigationDrawer.vue +2 -8
  71. package/src/components/MNavigationRail.vue +2 -3
  72. package/src/components/MSearchBar.vue +2 -5
  73. package/src/components/MSeekBar.vue +593 -0
  74. package/src/components/MSelect.vue +2 -8
  75. package/src/components/MSplitButton.vue +23 -7
  76. package/src/components/MSpotlightSearch.vue +4 -6
  77. package/src/components/MTimePicker.vue +23 -6
  78. package/src/components/MTimePickerModal.vue +213 -226
  79. package/src/components/MTooltip.vue +99 -3
  80. package/src/components/_MMapAttribution.vue +81 -0
  81. package/src/composables/_mapPin.ts +25 -0
  82. package/src/composables/_popupPosition.ts +39 -0
  83. package/src/composables/_useCalendarMonth.ts +74 -0
  84. package/src/composables/_useEscapeStack.ts +33 -0
  85. package/src/composables/_useScrollLock.ts +41 -0
  86. package/src/composables/_useSheetMotion.ts +82 -20
  87. package/src/composables/useLocale.ts +16 -0
  88. package/src/index.ts +2 -0
  89. package/src/locales/de.ts +8 -0
  90. package/src/locales/es.ts +8 -0
  91. package/src/locales/fr.ts +8 -0
  92. package/src/locales/ja.ts +8 -0
  93. package/src/locales/ko.ts +8 -0
  94. package/src/locales/pt.ts +8 -0
  95. package/src/locales/zh.ts +8 -0
  96. package/dist/MMenuItem-DFyXflk9.js +0 -707
  97. package/dist/MMenuItem-DFyXflk9.js.map +0 -1
  98. package/dist/MSlider-CdNIH7jc.js.map +0 -1
  99. package/dist/useLocale-b5-hzsL3.js.map +0 -1
@@ -9,6 +9,7 @@ import MIcon from './MIcon.vue'
9
9
  import MIconButton from './MIconButton.vue'
10
10
  import { useFieldBg } from '../composables/useFieldBg'
11
11
  import { useLocale } from '../composables/useLocale'
12
+ import { useScrollLock } from '../composables/_useScrollLock'
12
13
 
13
14
  export interface SelectOption {
14
15
  label: string
@@ -147,13 +148,7 @@ function onKeydown(e: KeyboardEvent) {
147
148
  }
148
149
  }
149
150
 
150
- watch(modalOpen, (v) => {
151
- if (v) {
152
- document.body.style.overflow = 'hidden'
153
- } else {
154
- document.body.style.overflow = ''
155
- }
156
- })
151
+ useScrollLock(modalOpen)
157
152
 
158
153
  function closeModal() { modalOpen.value = false }
159
154
 
@@ -164,7 +159,6 @@ onMounted(() => {
164
159
  onUnmounted(() => {
165
160
  document.removeEventListener('mousedown', onOutsideClick)
166
161
  window.removeEventListener('scroll', onScroll, true)
167
- document.body.style.overflow = ''
168
162
  })
169
163
 
170
164
  const triggerClasses = computed(() => {
@@ -9,6 +9,7 @@
9
9
  import { computed, onMounted, onUnmounted, ref } from 'vue'
10
10
  import MIcon from './MIcon.vue'
11
11
  import { vRipple } from '../directives/vRipple'
12
+ import { POPUP_MARGIN, dropdownX, fitPopup } from '../composables/_popupPosition'
12
13
 
13
14
  export interface SplitButtonItem {
14
15
  label: string
@@ -114,23 +115,36 @@ const buttonStateClasses = computed(() => {
114
115
  ]
115
116
  })
116
117
 
118
+ // At least as wide as the button, at the window's left edge until placeMenu() can measure it (once it's in the
119
+ // DOM, before it paints) and keep it on screen (see _popupPosition.ts): under the button, aligned with its start
120
+ // edge, else its end edge or the window edge; above it when it doesn't fit below
121
+ let anchorRect: DOMRect | null = null
117
122
  function computeMenuPos() {
118
123
  if (!containerEl.value) return
119
124
  const rect = containerEl.value.getBoundingClientRect()
120
- const menuH = (props.items?.length ?? 0) * 44 + 16
121
- const spaceBelow = window.innerHeight - rect.bottom - 8
122
- const above = spaceBelow < menuH && rect.top > menuH
125
+ anchorRect = rect
123
126
  menuStyle.value = {
124
127
  position: 'fixed',
125
128
  zIndex: '500',
126
- left: `${rect.left}px`,
129
+ left: '0px',
130
+ top: `${rect.bottom + 4}px`,
127
131
  minWidth: `${rect.width}px`,
128
- ...(above
129
- ? { bottom: `${window.innerHeight - rect.top + 4}px` }
130
- : { top: `${rect.bottom + 4}px` }),
132
+ maxWidth: `${window.innerWidth - 2 * POPUP_MARGIN}px`,
131
133
  }
132
134
  }
133
135
 
136
+ function placeMenu(el: Element) {
137
+ if (!anchorRect) return
138
+ const menu = el as HTMLElement
139
+ const w = menu.offsetWidth
140
+ const h = menu.offsetHeight
141
+ const left = dropdownX(anchorRect, w, window.innerWidth, 'start')
142
+ const top = fitPopup([anchorRect.bottom + 4, anchorRect.top - 4 - h], h, window.innerHeight)
143
+ menuStyle.value = { ...menuStyle.value, left: `${left}px`, top: `${top}px` }
144
+ menu.style.left = `${left}px`
145
+ menu.style.top = `${top}px`
146
+ }
147
+
134
148
  function toggleMenu() {
135
149
  if (props.disabled) return
136
150
  if (!open.value) computeMenuPos()
@@ -217,6 +231,7 @@ onUnmounted(() => {
217
231
  enter-from-class="opacity-0 -translate-y-1 scale-[0.98]"
218
232
  leave-active-class="transition-[opacity,transform] duration-100"
219
233
  leave-to-class="opacity-0 -translate-y-1 scale-[0.98]"
234
+ @enter="placeMenu"
220
235
  >
221
236
  <div
222
237
  v-if="open && items?.length"
@@ -245,6 +260,7 @@ onUnmounted(() => {
245
260
  enter-from-class="opacity-0 -translate-y-1 scale-[0.98]"
246
261
  leave-active-class="transition-[opacity,transform] duration-100"
247
262
  leave-to-class="opacity-0 -translate-y-1 scale-[0.98]"
263
+ @enter="placeMenu"
248
264
  >
249
265
  <div
250
266
  v-if="open && !items?.length && $slots.menu"
@@ -12,6 +12,7 @@ import { ref, computed, watch, nextTick, onMounted, onBeforeUnmount } from 'vue'
12
12
  import MIcon from './MIcon.vue'
13
13
  import MSpinner from './MSpinner.vue'
14
14
  import { useLocale } from '../composables/useLocale'
15
+ import { useScrollLock } from '../composables/_useScrollLock'
15
16
 
16
17
  const locale = useLocale()
17
18
 
@@ -148,15 +149,12 @@ function onGlobalKeydown(e: KeyboardEvent) {
148
149
  watch(
149
150
  () => props.modelValue,
150
151
  (open) => {
151
- if (open) {
152
- document.body.style.overflow = 'hidden'
153
- nextTick(() => inputRef.value?.focus())
154
- } else {
155
- document.body.style.overflow = ''
156
- }
152
+ if (open) nextTick(() => inputRef.value?.focus())
157
153
  },
158
154
  )
159
155
 
156
+ useScrollLock(() => props.modelValue)
157
+
160
158
  watch(query, () => {
161
159
  activeIndex.value = 0
162
160
  emitSearch()
@@ -8,6 +8,7 @@ import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
8
8
  import MIcon from './MIcon.vue'
9
9
  import { useFieldBg } from '../composables/useFieldBg'
10
10
  import { useLocale } from '../composables/useLocale'
11
+ import { POPUP_MARGIN, dropdownX, fitPopup } from '../composables/_popupPosition'
11
12
 
12
13
  const props = withDefaults(defineProps<{
13
14
  /** Selected time (HH:MM, v-model) */
@@ -40,7 +41,7 @@ const open = ref(false)
40
41
  const triggerEl = ref<HTMLElement | null>(null)
41
42
  const panelEl = ref<HTMLElement | null>(null)
42
43
  const mode = ref<'hour' | 'minute'>('hour')
43
- const dropPos = ref({ top: '0px', left: '0px' })
44
+ const dropPos = ref<Record<string, string>>({ top: '0px', left: '0px' })
44
45
  const { resolvedFieldBg } = useFieldBg(triggerEl, () => props.fieldBg)
45
46
 
46
47
  const parsed = computed(() => {
@@ -87,18 +88,33 @@ const displayValue = computed(() => {
87
88
  return `${pad(parsed.value.h)}:${pad(parsed.value.m)}`
88
89
  })
89
90
 
91
+ // The panel's size isn't known until it's in the DOM: placeDrop() keeps it on screen once it is, before it paints
92
+ // (see _popupPosition.ts): under the field, aligned with its start edge, else its end edge or the window edge;
93
+ // above it when it doesn't fit below. Until then it waits at the window's left edge, where nothing narrows it.
94
+ let anchorRect: DOMRect | null = null
90
95
  function computeDropPos() {
91
96
  if (!triggerEl.value) return
92
97
  const rect = triggerEl.value.getBoundingClientRect()
93
- const panelH = 320
94
- const spaceBelow = window.innerHeight - rect.bottom - 8
95
- const above = spaceBelow < panelH && rect.top > panelH
98
+ anchorRect = rect
96
99
  dropPos.value = {
97
- top: above ? `${rect.top - 4 - panelH}px` : `${rect.bottom + 4}px`,
98
- left: `${rect.left}px`,
100
+ top: `${rect.bottom + 4}px`,
101
+ left: '0px',
102
+ maxWidth: `${window.innerWidth - 2 * POPUP_MARGIN}px`,
99
103
  }
100
104
  }
101
105
 
106
+ function placeDrop(el: Element) {
107
+ if (!anchorRect) return
108
+ const panel = el as HTMLElement
109
+ const w = panel.offsetWidth
110
+ const h = panel.offsetHeight
111
+ const left = dropdownX(anchorRect, w, window.innerWidth, 'start')
112
+ const top = fitPopup([anchorRect.bottom + 4, anchorRect.top - 4 - h], h, window.innerHeight)
113
+ dropPos.value = { ...dropPos.value, left: `${left}px`, top: `${top}px` }
114
+ panel.style.left = `${left}px`
115
+ panel.style.top = `${top}px`
116
+ }
117
+
102
118
  function onOut(e: MouseEvent) {
103
119
  const t = e.target as Node
104
120
  if (triggerEl.value?.contains(t)) return
@@ -174,6 +190,7 @@ onUnmounted(() => {
174
190
  enter-from-class="opacity-0 -translate-y-1 scale-[0.98]"
175
191
  leave-active-class="transition-[opacity,transform] duration-100"
176
192
  leave-to-class="opacity-0 -translate-y-1 scale-[0.98]"
193
+ @enter="placeDrop"
177
194
  >
178
195
  <div
179
196
  v-if="open"