@m3ui-vue/m3ui-vue 0.8.0 → 0.8.1

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 (59) hide show
  1. package/README.md +9 -1
  2. package/dist/{MMenuItem-vSLbJGqe.js → MMenuItem-CDWfeU4F.js} +48 -36
  3. package/dist/MMenuItem-CDWfeU4F.js.map +1 -0
  4. package/dist/code-editor.js +1 -1
  5. package/dist/code-editor.js.map +1 -1
  6. package/dist/components/MButton.vue.d.ts +7 -0
  7. package/dist/components/MCalendar.vue.d.ts +0 -1
  8. package/dist/components/MCarousel.vue.d.ts +12 -14
  9. package/dist/components/MDatePicker.vue.d.ts +1 -3
  10. package/dist/components/MDatePickerModal.vue.d.ts +0 -1
  11. package/dist/components/MDateRangePicker.vue.d.ts +1 -3
  12. package/dist/components/MDateRangePickerModal.vue.d.ts +0 -1
  13. package/dist/components/MKanban.vue.d.ts +1 -0
  14. package/dist/components/MScheduler.vue.d.ts +0 -1
  15. package/dist/components/MShape.vue.d.ts +51 -0
  16. package/dist/components/MShortNavigationBar.vue.d.ts +34 -0
  17. package/dist/components/MSimpleCarousel.vue.d.ts +45 -0
  18. package/dist/components/MToggleButton.vue.d.ts +29 -0
  19. package/dist/components/MTree.vue.d.ts +0 -1
  20. package/dist/components/MTreeTable.vue.d.ts +1 -0
  21. package/dist/index.d.ts +8 -1
  22. package/dist/m3ui-vue.css +1 -1
  23. package/dist/m3ui.js +3773 -2277
  24. package/dist/m3ui.js.map +1 -1
  25. package/dist/rich-text-editor.js +1 -1
  26. package/dist/styles/palettes.css +22 -22
  27. package/dist/styles.css +1 -1
  28. package/package.json +4 -1
  29. package/src/__tests__/MCarousel.test.ts +33 -0
  30. package/src/__tests__/MShape.test.ts +36 -0
  31. package/src/__tests__/MToggleButton.test.ts +27 -0
  32. package/src/components/MAutocomplete.vue +5 -1
  33. package/src/components/MButton.vue +15 -2
  34. package/src/components/MCalendar.vue +9 -5
  35. package/src/components/MCarousel.vue +123 -173
  36. package/src/components/MCodeEditor.vue +6 -1
  37. package/src/components/MContextMenu.vue +4 -4
  38. package/src/components/MDatePicker.vue +12 -9
  39. package/src/components/MDatePickerModal.vue +9 -4
  40. package/src/components/MDateRangePicker.vue +12 -9
  41. package/src/components/MDateRangePickerModal.vue +9 -4
  42. package/src/components/MKanban.vue +5 -1
  43. package/src/components/MMenu.vue +4 -4
  44. package/src/components/MMultiAutocomplete.vue +5 -1
  45. package/src/components/MMultiSelect.vue +5 -1
  46. package/src/components/MScheduler.vue +10 -6
  47. package/src/components/MSearchBar.vue +5 -1
  48. package/src/components/MSelect.vue +5 -1
  49. package/src/components/MShape.vue +107 -0
  50. package/src/components/MShortNavigationBar.vue +113 -0
  51. package/src/components/MSimpleCarousel.vue +325 -0
  52. package/src/components/MToggleButton.vue +188 -0
  53. package/src/components/MTopAppBar.vue +6 -2
  54. package/src/components/MTree.vue +4 -2
  55. package/src/components/MTreeTable.vue +5 -1
  56. package/src/composables/useColorPalette.ts +1 -1
  57. package/src/index.ts +8 -1
  58. package/src/styles/palettes.css +22 -22
  59. package/dist/MMenuItem-vSLbJGqe.js.map +0 -1
@@ -1,129 +1,124 @@
1
1
  <script setup lang="ts">
2
- import { ref, computed, onMounted, onBeforeUnmount, watch, nextTick } from 'vue'
2
+ import { ref, computed, onMounted, onBeforeUnmount, nextTick } from 'vue'
3
3
  import MIcon from './MIcon.vue'
4
4
 
5
5
  export interface CarouselItem {
6
6
  src: string
7
7
  alt?: string
8
8
  label?: string
9
- supportingText?: string
10
- ratio?: number
11
9
  }
12
10
 
11
+ /*
12
+ * Ported from the real M3 `HorizontalMultiBrowseCarousel` (Carousel.kt/Keylines.kt), not the
13
+ * "flat fixed-width items" look this library's old MCarousel had (now MSimpleCarousel). The real
14
+ * spec's signature behavior: one large "focal" item at rest, with neighbors progressively masked
15
+ * down toward a small "peek" size the further they are from the focal position — items grow/shrink
16
+ * continuously as you scroll, they're not just fixed-size slides.
17
+ *
18
+ * Real defaults ported exactly: minSmallItemWidth = MinSmallItemSize = 40dp, maxSmallItemWidth =
19
+ * MaxSmallItemSize = 56dp, itemSpacing = 0dp, targetSmallSize = clamp(largeSize/3, min, max), and
20
+ * the left-aligned focal convention (createLeftAlignedKeylineList — the focal item sits at the
21
+ * scroll container's left edge, not centered).
22
+ *
23
+ * Deliberately NOT ported: the real `Arrangement.findLowestCostArrangement` combinatorial search
24
+ * that decides exactly how many large/medium/small items fit a given width to the pixel. That's a
25
+ * large amount of code for a difference only visible at unusual width/item-count combinations —
26
+ * this uses a direct triangular falloff from the focal position instead, which converges to the
27
+ * same large-focal-item-with-shrinking-neighbors look for realistic carousels.
28
+ */
13
29
  const props = withDefaults(
14
30
  defineProps<{
15
31
  items: CarouselItem[]
16
- layout?: 'hero' | 'multi-browse' | 'uncontained'
32
+ /** Target width of the large, fully-visible focal item, in px (preferredItemWidth). */
33
+ itemWidth?: number
34
+ /** Spacing between item slots, in px. Real default (CarouselDefaults.ItemSpacing) is 0. */
35
+ itemSpacing?: number
36
+ /** Real default (CarouselDefaults.MinSmallItemSize) is 40. */
37
+ minSmallItemWidth?: number
38
+ /** Real default (CarouselDefaults.MaxSmallItemSize) is 56. */
39
+ maxSmallItemWidth?: number
17
40
  height?: string
18
41
  showArrows?: boolean
19
- showIndicators?: boolean
20
42
  autoplay?: boolean
21
43
  interval?: number
22
- gap?: number
23
- visibleItems?: number
24
- animated?: boolean
25
44
  }>(),
26
45
  {
27
- layout: 'hero',
28
- height: '320px',
46
+ itemWidth: 280,
47
+ itemSpacing: 0,
48
+ minSmallItemWidth: 40,
49
+ maxSmallItemWidth: 56,
50
+ height: '220px',
29
51
  showArrows: true,
30
- showIndicators: true,
31
52
  autoplay: false,
32
53
  interval: 5000,
33
- gap: 8,
34
- visibleItems: 3,
35
- animated: false,
36
54
  },
37
55
  )
38
56
 
39
57
  const emit = defineEmits<{ change: [index: number] }>()
40
58
 
41
- const trackEl = ref<HTMLElement>()
42
- const itemEls = ref<HTMLElement[]>([])
59
+ const trackEl = ref<HTMLElement | null>(null)
60
+ const itemEls = ref<(HTMLElement | null)[]>([])
61
+ const containerWidth = ref(0)
43
62
  const activeIndex = ref(0)
44
- const scrollPos = ref(0)
45
- const isPageBased = computed(() => props.layout === 'multi-browse' || props.layout === 'uncontained')
46
63
 
47
- const totalPages = computed(() => {
48
- if (!isPageBased.value) return props.items.length
49
- if (!trackEl.value) return 1
50
- const track = trackEl.value
51
- return Math.max(1, Math.ceil(track.scrollWidth / track.clientWidth))
52
- })
64
+ function setItemRef(el: unknown, i: number) {
65
+ itemEls.value[i] = (el as HTMLElement) ?? null
66
+ }
53
67
 
54
- const activePage = computed(() => {
55
- if (!isPageBased.value) return activeIndex.value
56
- if (!trackEl.value) return 0
57
- const track = trackEl.value
58
- if (track.scrollWidth <= track.clientWidth) return 0
59
- const _ = scrollPos.value
60
- return Math.round(track.scrollLeft / track.clientWidth)
68
+ const targetLarge = computed(() => Math.min(props.itemWidth, containerWidth.value || props.itemWidth))
69
+ const targetSmall = computed(() => {
70
+ const raw = targetLarge.value / 3
71
+ return Math.min(Math.max(raw, props.minSmallItemWidth), props.maxSmallItemWidth)
61
72
  })
62
- const itemTransforms = ref<string[]>([])
63
- const imageTransforms = ref<string[]>([])
64
- let autoTimer: ReturnType<typeof setInterval> | null = null
65
- let rafId = 0
66
- let scrollTimeout: ReturnType<typeof setTimeout> | null = null
67
73
 
68
- function setItemRef(el: any, i: number) {
69
- if (el) itemEls.value[i] = el as HTMLElement
70
- }
74
+ const maskWidths = ref<number[]>([])
75
+ const imgOffsets = ref<number[]>([])
76
+ let rafId = 0
71
77
 
72
- // ── Scroll handling (only transforms, never layout) ────────────
73
78
  function onScroll() {
74
79
  if (rafId) return
75
80
  rafId = requestAnimationFrame(() => {
76
81
  rafId = 0
77
- updateTransforms()
82
+ updateMasks()
78
83
  })
79
-
80
- if (scrollTimeout) clearTimeout(scrollTimeout)
81
84
  }
82
85
 
83
- function updateTransforms() {
86
+ function updateMasks() {
84
87
  if (!trackEl.value) return
85
- const track = trackEl.value
86
- scrollPos.value = track.scrollLeft
87
- const trackRect = track.getBoundingClientRect()
88
- const trackW = trackRect.width
89
- const centerX = trackRect.left + trackW / 2
90
- const transforms: string[] = []
91
- const imgTransforms: string[] = []
88
+ const trackLeft = trackEl.value.getBoundingClientRect().left
89
+ const large = targetLarge.value
90
+ const small = targetSmall.value
91
+ const widths: number[] = []
92
+ const offsets: number[] = []
92
93
  let closest = 0
93
94
  let closestDist = Infinity
94
95
 
95
- const refX = props.layout === 'multi-browse' ? trackRect.left : centerX
96
-
97
96
  for (let i = 0; i < itemEls.value.length; i++) {
98
97
  const el = itemEls.value[i]
99
- if (!el) { transforms.push(''); imgTransforms.push(''); continue }
100
- const rect = el.getBoundingClientRect()
101
- const itemCenterX = rect.left + rect.width / 2
102
- const dist = props.layout === 'multi-browse'
103
- ? Math.abs(rect.left - refX)
104
- : Math.abs(itemCenterX - centerX)
105
- const norm = Math.min(dist / (trackW * 0.5), 1)
106
-
107
- if (props.layout === 'hero') {
108
- imgTransforms.push(`translateX(${(itemCenterX - centerX) * -0.08}px) scale(1.1)`)
109
- transforms.push('')
110
- } else if (props.layout === 'uncontained' && props.animated) {
111
- const s = 1 - norm * 0.12
112
- transforms.push(`scale(${s})`)
113
- imgTransforms.push('')
98
+ if (!el) { widths.push(large); offsets.push(0); continue }
99
+ const offset = el.getBoundingClientRect().left - trackLeft
100
+
101
+ let width: number
102
+ let imgOffset: number
103
+ if (offset <= 0) {
104
+ // Exiting (or resting) on the left: mask grows in from the left, keep the right portion
105
+ // of the image visible (matches the real maskStart clipping from the item's start edge).
106
+ width = Math.max(large + offset, small)
107
+ imgOffset = -(large - width)
114
108
  } else {
115
- transforms.push('')
116
- imgTransforms.push('')
109
+ // Upcoming on the right: mask shrinks from the right, keep the left portion visible.
110
+ width = Math.max(large - offset, small)
111
+ imgOffset = 0
117
112
  }
113
+ widths.push(width)
114
+ offsets.push(imgOffset)
118
115
 
119
- if (dist < closestDist) {
120
- closestDist = dist
121
- closest = i
122
- }
116
+ const dist = Math.abs(offset)
117
+ if (dist < closestDist) { closestDist = dist; closest = i }
123
118
  }
124
119
 
125
- itemTransforms.value = transforms
126
- imageTransforms.value = imgTransforms
120
+ maskWidths.value = widths
121
+ imgOffsets.value = offsets
127
122
 
128
123
  if (closest !== activeIndex.value) {
129
124
  activeIndex.value = closest
@@ -131,107 +126,83 @@ function updateTransforms() {
131
126
  }
132
127
  }
133
128
 
134
- // ── Fixed item widths (never change during scroll) ─────────────
135
- function itemWidth(i: number) {
136
- switch (props.layout) {
137
- case 'hero':
138
- return `calc(100% - 48px)`
139
- case 'multi-browse':
140
- return `calc(${100 / props.visibleItems}% - ${props.gap * (props.visibleItems - 1) / props.visibleItems}px)`
141
- case 'uncontained':
142
- return `${(props.items[i]?.ratio ?? 1) * 260}px`
143
- default:
144
- return '80%'
145
- }
146
- }
147
-
129
+ // The item element's own width IS the animated mask width — not a fixed-width outer "slot"
130
+ // with a shrinking element inside it. That was the first cut of this component, and it was
131
+ // wrong: shrinking an inner element while its outer flex-item stayed at the full large width
132
+ // just left dead space where the flex item used to be, instead of letting flex naturally close
133
+ // the gap by reflowing the next item up against it (exactly what the real component's keyline
134
+ // masking achieves, just via a different mechanism — Compose positions items directly from
135
+ // keyline offsets rather than relying on flow layout, but the visual result needs to be the same:
136
+ // no gaps between items regardless of their current mask size).
148
137
  function itemStyle(i: number) {
149
- const style: Record<string, string> = {
138
+ return {
139
+ width: `${maskWidths.value[i] ?? targetLarge.value}px`,
140
+ height: '100%',
150
141
  flexShrink: '0',
151
- width: itemWidth(i),
152
- }
153
- const t = itemTransforms.value[i]
154
- if (t) {
155
- style.transform = t
156
- style.transition = 'transform 120ms ease-out'
142
+ overflow: 'hidden',
143
+ position: 'relative' as const,
157
144
  }
158
- return style
159
145
  }
160
146
 
161
147
  function imgStyle(i: number) {
162
- const t = imageTransforms.value[i]
163
- if (!t) return {}
164
- return { transform: t }
148
+ return {
149
+ width: `${targetLarge.value}px`,
150
+ height: '100%',
151
+ position: 'absolute' as const,
152
+ left: `${imgOffsets.value[i] ?? 0}px`,
153
+ top: '0',
154
+ }
165
155
  }
166
156
 
167
- // ── Navigation ─────────────────────────────────────────────────
168
157
  function scrollToItem(index: number) {
169
158
  const el = itemEls.value[index]
170
159
  if (!el || !trackEl.value) return
171
- const track = trackEl.value
172
- const scrollLeft = el.offsetLeft - (track.clientWidth - el.offsetWidth) / 2
173
- track.scrollTo({ left: scrollLeft, behavior: 'smooth' })
174
- }
175
-
176
- function scrollToPage(page: number) {
177
- if (!trackEl.value) return
178
- const track = trackEl.value
179
- track.scrollTo({ left: page * track.clientWidth, behavior: 'smooth' })
160
+ trackEl.value.scrollTo({ left: el.offsetLeft, behavior: 'smooth' })
180
161
  }
181
162
 
182
163
  function next() {
183
- if (isPageBased.value) {
184
- if (!trackEl.value) return
185
- trackEl.value.scrollBy({ left: trackEl.value.clientWidth, behavior: 'smooth' })
186
- } else {
187
- const i = activeIndex.value < props.items.length - 1 ? activeIndex.value + 1 : 0
188
- scrollToItem(i)
189
- }
164
+ const i = activeIndex.value < props.items.length - 1 ? activeIndex.value + 1 : 0
165
+ scrollToItem(i)
190
166
  }
191
-
192
167
  function prev() {
193
- if (isPageBased.value) {
194
- if (!trackEl.value) return
195
- trackEl.value.scrollBy({ left: -trackEl.value.clientWidth, behavior: 'smooth' })
196
- } else {
197
- const i = activeIndex.value > 0 ? activeIndex.value - 1 : props.items.length - 1
198
- scrollToItem(i)
199
- }
168
+ const i = activeIndex.value > 0 ? activeIndex.value - 1 : props.items.length - 1
169
+ scrollToItem(i)
200
170
  }
201
171
 
172
+ function onKeydown(e: KeyboardEvent) {
173
+ if (e.key === 'ArrowRight') next()
174
+ else if (e.key === 'ArrowLeft') prev()
175
+ }
176
+
177
+ let autoTimer: ReturnType<typeof setInterval> | null = null
202
178
  function startAutoplay() {
203
179
  stopAutoplay()
204
- if (props.autoplay && props.items.length > 1) {
205
- autoTimer = setInterval(next, props.interval)
206
- }
180
+ if (props.autoplay && props.items.length > 1) autoTimer = setInterval(next, props.interval)
207
181
  }
208
-
209
182
  function stopAutoplay() {
210
183
  if (autoTimer) { clearInterval(autoTimer); autoTimer = null }
211
184
  }
212
185
 
213
- function onKeydown(e: KeyboardEvent) {
214
- if (e.key === 'ArrowRight') next()
215
- else if (e.key === 'ArrowLeft') prev()
216
- }
217
-
218
- const trackPadding = computed(() => {
219
- if (props.layout === 'hero') return '0 24px'
220
- if (props.layout === 'uncontained') return '0 24px'
221
- return '0'
222
- })
223
-
224
- watch(() => props.autoplay, startAutoplay)
186
+ let resizeObserver: ResizeObserver | null = null
225
187
  onMounted(() => {
188
+ if (trackEl.value) {
189
+ containerWidth.value = trackEl.value.clientWidth
190
+ resizeObserver = new ResizeObserver(() => {
191
+ if (trackEl.value) containerWidth.value = trackEl.value.clientWidth
192
+ updateMasks()
193
+ })
194
+ resizeObserver.observe(trackEl.value)
195
+ }
196
+ nextTick(updateMasks)
226
197
  startAutoplay()
227
- nextTick(() => updateTransforms())
228
198
  })
229
199
  onBeforeUnmount(() => {
230
200
  stopAutoplay()
231
201
  if (rafId) cancelAnimationFrame(rafId)
202
+ resizeObserver?.disconnect()
232
203
  })
233
204
 
234
- defineExpose({ next, prev, scrollToItem, scrollToPage })
205
+ defineExpose({ next, prev, scrollToItem })
235
206
  </script>
236
207
 
237
208
  <template>
@@ -245,30 +216,27 @@ defineExpose({ next, prev, scrollToItem, scrollToPage })
245
216
  <div
246
217
  ref="trackEl"
247
218
  class="carousel-track flex overflow-x-auto"
248
- :class="layout === 'multi-browse' ? 'snap-start' : 'snap-center'"
249
- :style="{ height, gap: `${gap}px`, padding: trackPadding }"
219
+ :style="{ height, gap: `${itemSpacing}px` }"
250
220
  @scroll.passive="onScroll"
251
221
  >
252
222
  <div
253
223
  v-for="(item, i) in items"
254
224
  :key="i"
255
225
  :ref="(el) => setItemRef(el, i)"
256
- class="relative overflow-hidden rounded-2xl"
226
+ class="rounded-2xl"
257
227
  :style="itemStyle(i)"
258
228
  >
259
229
  <img
260
230
  :src="item.src"
261
231
  :alt="item.alt ?? item.label ?? ''"
262
- class="pointer-events-none h-full w-full object-cover"
232
+ class="pointer-events-none object-cover"
263
233
  :style="imgStyle(i)"
264
234
  />
265
-
266
235
  <div
267
- v-if="item.label || item.supportingText"
268
- class="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/70 via-black/30 to-transparent px-5 pb-4 pt-12"
236
+ v-if="item.label"
237
+ class="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/70 via-black/30 to-transparent px-4 pb-3 pt-8"
269
238
  >
270
- <p v-if="item.label" class="text-title-medium font-medium text-white">{{ item.label }}</p>
271
- <p v-if="item.supportingText" class="mt-0.5 text-body-small text-white/80">{{ item.supportingText }}</p>
239
+ <p class="text-title-medium font-medium text-white">{{ item.label }}</p>
272
240
  </div>
273
241
  </div>
274
242
  </div>
@@ -289,22 +257,7 @@ defineExpose({ next, prev, scrollToItem, scrollToPage })
289
257
  <MIcon name="chevron_right" :size="24" />
290
258
  </button>
291
259
  </template>
292
-
293
- </div>
294
-
295
- <div
296
- v-if="showIndicators && totalPages > 1"
297
- class="flex justify-center gap-1.5 pt-3"
298
- >
299
- <button
300
- v-for="p in totalPages"
301
- :key="p"
302
- type="button"
303
- class="h-2 cursor-pointer rounded-full transition-all duration-300"
304
- :class="(p - 1) === activePage ? 'w-5 bg-on-surface' : 'w-2 bg-on-surface/30 hover:bg-on-surface/50'"
305
- @click="isPageBased ? scrollToPage(p - 1) : scrollToItem(p - 1)"
306
- />
307
- </div>
260
+ </div>
308
261
  </template>
309
262
 
310
263
  <style scoped>
@@ -316,10 +269,7 @@ defineExpose({ next, prev, scrollToItem, scrollToPage })
316
269
  .carousel-track::-webkit-scrollbar {
317
270
  display: none;
318
271
  }
319
- .snap-center > * {
320
- scroll-snap-align: center;
321
- }
322
- .snap-start > * {
272
+ .carousel-track > * {
323
273
  scroll-snap-align: start;
324
274
  }
325
275
  </style>
@@ -307,7 +307,12 @@ onBeforeUnmount(() => view?.destroy())
307
307
  }
308
308
 
309
309
  .code-editor-container :deep(.cm-activeLine) {
310
- background: var(--color-surface-container-lowest);
310
+ /* CodeMirror renders the selection highlight on a layer with z-index: -1
311
+ (@codemirror/view's selectionLayer has `above: false` by design, so it always
312
+ sits behind the line content). An opaque active-line background would paint
313
+ straight over it and hide the selection on the current line — this needs to
314
+ stay a translucent tint so a selection underneath still shows through. */
315
+ background: color-mix(in srgb, var(--color-on-surface) 5%, transparent);
311
316
  }
312
317
 
313
318
  .code-editor-container :deep(.cm-selectionBackground) {
@@ -86,12 +86,12 @@ onUnmounted(() => {
86
86
 
87
87
  <Teleport to="body">
88
88
  <Transition
89
- enter-active-class="transition-[opacity,transform] duration-100 ease-out"
90
- enter-from-class="opacity-0 scale-95"
89
+ enter-active-class="transition-[opacity,transform] duration-150 ease-[cubic-bezier(0.05,0.7,0.1,1)]"
90
+ enter-from-class="opacity-0 scale-[0.8]"
91
91
  enter-to-class="opacity-100 scale-100"
92
- leave-active-class="transition-[opacity,transform] duration-75 ease-in"
92
+ leave-active-class="transition-[opacity,transform] duration-150 ease-[cubic-bezier(0.3,0,0.8,0.15)]"
93
93
  leave-from-class="opacity-100 scale-100"
94
- leave-to-class="opacity-0 scale-95"
94
+ leave-to-class="opacity-0 scale-[0.8]"
95
95
  >
96
96
  <div
97
97
  v-if="visible"
@@ -5,7 +5,7 @@ import MIconButton from './MIconButton.vue'
5
5
  import { useFieldBg } from '../composables/useFieldBg'
6
6
  import { useLocale } from '../composables/useLocale'
7
7
 
8
- const props = withDefaults(defineProps<{
8
+ const props = defineProps<{
9
9
  modelValue: string | null
10
10
  label?: string
11
11
  placeholder?: string
@@ -19,12 +19,15 @@ const props = withDefaults(defineProps<{
19
19
  fieldBg?: string
20
20
  prevMonthLabel?: string
21
21
  nextMonthLabel?: string
22
- }>(), {
23
- locale: 'es-ES',
24
- })
22
+ }>()
25
23
 
26
24
  const localeStrings = useLocale()
27
25
 
26
+ // Falls back to the app's own configured locale (via createM3UI/useLocale) rather than a
27
+ // fixed default, matching the pattern MRelativeTime already uses — previously this defaulted
28
+ // to a hardcoded 'es-ES' regardless of what locale the app actually provided.
29
+ const resolvedLocale = computed(() => props.locale ?? localeStrings.lang)
30
+
28
31
  const emit = defineEmits<{ 'update:modelValue': [string | null] }>()
29
32
 
30
33
  const open = ref(false)
@@ -38,16 +41,16 @@ watch(() => props.modelValue, (v) => {
38
41
  if (v) viewDate.value = new Date(v + 'T00:00:00')
39
42
  })
40
43
 
41
- const WEEKDAYS = (() => {
42
- const f = new Intl.DateTimeFormat(props.locale, { weekday: 'narrow' })
44
+ const WEEKDAYS = computed(() => {
45
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'narrow' })
43
46
  return Array.from({ length: 7 }, (_, i) => {
44
47
  const d = new Date(2024, 0, i + 1) // Mon=1 Jan 2024
45
48
  return f.format(d)
46
49
  })
47
- })()
50
+ })
48
51
 
49
52
  const monthLabel = computed(() => {
50
- const f = new Intl.DateTimeFormat(props.locale, { month: 'long', year: 'numeric' })
53
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' })
51
54
  return f.format(viewDate.value)
52
55
  })
53
56
 
@@ -117,7 +120,7 @@ function clear() {
117
120
  const displayValue = computed(() => {
118
121
  if (!props.modelValue) return ''
119
122
  const d = new Date(props.modelValue + 'T00:00:00')
120
- return new Intl.DateTimeFormat(props.locale, { day: 'numeric', month: 'short', year: 'numeric' }).format(d)
123
+ return new Intl.DateTimeFormat(resolvedLocale.value, { day: 'numeric', month: 'short', year: 'numeric' }).format(d)
121
124
  })
122
125
 
123
126
  function computeDropPos() {
@@ -15,10 +15,15 @@ const props = withDefaults(defineProps<{
15
15
  }>(), {
16
16
  modelValue: null,
17
17
  show: false,
18
- locale: 'es-ES',
19
18
  })
20
19
 
21
20
  const locale = useLocale()
21
+
22
+ // Falls back to the app's own configured locale (via createM3UI/useLocale) rather than a
23
+ // fixed default, matching the pattern MRelativeTime already uses — previously this defaulted
24
+ // to a hardcoded 'es-ES' regardless of what locale the app actually provided.
25
+ const resolvedLocale = computed(() => props.locale ?? locale.lang)
26
+
22
27
  const emit = defineEmits<{
23
28
  'update:modelValue': [string | null]
24
29
  'update:show': [boolean]
@@ -45,12 +50,12 @@ watch(() => props.show, (open) => {
45
50
 
46
51
  // ── Calendar logic ─────────────────────────────────────────────────
47
52
  const WEEKDAYS = computed(() => {
48
- const f = new Intl.DateTimeFormat(props.locale, { weekday: 'narrow' })
53
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'narrow' })
49
54
  return Array.from({ length: 7 }, (_, i) => f.format(new Date(2024, 0, i + 1)))
50
55
  })
51
56
 
52
57
  const monthLabel = computed(() =>
53
- new Intl.DateTimeFormat(props.locale, { month: 'long', year: 'numeric' }).format(viewDate.value),
58
+ new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' }).format(viewDate.value),
54
59
  )
55
60
 
56
61
  const calendarDays = computed(() => {
@@ -112,7 +117,7 @@ function selectDay(day: typeof calendarDays.value[0]) {
112
117
  const headerDate = computed(() => {
113
118
  if (!selected.value) return '—'
114
119
  const d = new Date(selected.value + 'T00:00:00')
115
- return new Intl.DateTimeFormat(props.locale, { weekday: 'short', month: 'short', day: 'numeric' }).format(d)
120
+ return new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'short', month: 'short', day: 'numeric' }).format(d)
116
121
  })
117
122
 
118
123
  // ── Input mode ─────────────────────────────────────────────────────
@@ -10,7 +10,7 @@ export interface DateRange {
10
10
  end: string | null
11
11
  }
12
12
 
13
- const props = withDefaults(defineProps<{
13
+ const props = defineProps<{
14
14
  modelValue: DateRange
15
15
  label?: string
16
16
  placeholder?: string
@@ -26,12 +26,15 @@ const props = withDefaults(defineProps<{
26
26
  nextMonthLabel?: string
27
27
  pickStartText?: string
28
28
  pickEndText?: string
29
- }>(), {
30
- locale: 'es-ES',
31
- })
29
+ }>()
32
30
 
33
31
  const localeStrings = useLocale()
34
32
 
33
+ // Falls back to the app's own configured locale (via createM3UI/useLocale) rather than a
34
+ // fixed default, matching the pattern MRelativeTime already uses — previously this defaulted
35
+ // to a hardcoded 'es-ES' regardless of what locale the app actually provided.
36
+ const resolvedLocale = computed(() => props.locale ?? localeStrings.lang)
37
+
35
38
  const emit = defineEmits<{ 'update:modelValue': [DateRange] }>()
36
39
 
37
40
  const open = ref(false)
@@ -49,13 +52,13 @@ watch(() => props.modelValue.start, (v) => {
49
52
  if (v) viewDate.value = new Date(v + 'T00:00:00')
50
53
  })
51
54
 
52
- const WEEKDAYS = (() => {
53
- const f = new Intl.DateTimeFormat(props.locale, { weekday: 'narrow' })
55
+ const WEEKDAYS = computed(() => {
56
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'narrow' })
54
57
  return Array.from({ length: 7 }, (_, i) => f.format(new Date(2024, 0, i + 1)))
55
- })()
58
+ })
56
59
 
57
60
  const monthLabel = computed(() =>
58
- new Intl.DateTimeFormat(props.locale, { month: 'long', year: 'numeric' }).format(viewDate.value)
61
+ new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' }).format(viewDate.value)
59
62
  )
60
63
 
61
64
  const calendarDays = computed(() => {
@@ -125,7 +128,7 @@ function prevMonth() { const d = new Date(viewDate.value); d.setMonth(d.getMonth
125
128
  function nextMonth() { const d = new Date(viewDate.value); d.setMonth(d.getMonth() + 1); viewDate.value = d }
126
129
 
127
130
  const displayValue = computed(() => {
128
- const f = new Intl.DateTimeFormat(props.locale, { day: 'numeric', month: 'short' })
131
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { day: 'numeric', month: 'short' })
129
132
  const s = props.modelValue.start ? f.format(new Date(props.modelValue.start + 'T00:00:00')) : '—'
130
133
  const e = props.modelValue.end ? f.format(new Date(props.modelValue.end + 'T00:00:00')) : '—'
131
134
  if (!props.modelValue.start && !props.modelValue.end) return ''
@@ -18,10 +18,15 @@ const props = withDefaults(defineProps<{
18
18
  title?: string
19
19
  }>(), {
20
20
  show: false,
21
- locale: 'es-ES',
22
21
  })
23
22
 
24
23
  const locale = useLocale()
24
+
25
+ // Falls back to the app's own configured locale (via createM3UI/useLocale) rather than a
26
+ // fixed default, matching the pattern MRelativeTime already uses — previously this defaulted
27
+ // to a hardcoded 'es-ES' regardless of what locale the app actually provided.
28
+ const resolvedLocale = computed(() => props.locale ?? locale.lang)
29
+
25
30
  const emit = defineEmits<{
26
31
  'update:modelValue': [DateRange]
27
32
  'update:show': [boolean]
@@ -51,12 +56,12 @@ watch(() => props.show, (open) => {
51
56
 
52
57
  // ── Calendar logic ─────────────────────────────────────────────────
53
58
  const WEEKDAYS = computed(() => {
54
- const f = new Intl.DateTimeFormat(props.locale, { weekday: 'narrow' })
59
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'narrow' })
55
60
  return Array.from({ length: 7 }, (_, i) => f.format(new Date(2024, 0, i + 1)))
56
61
  })
57
62
 
58
63
  const monthLabel = computed(() =>
59
- new Intl.DateTimeFormat(props.locale, { month: 'long', year: 'numeric' }).format(viewDate.value),
64
+ new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' }).format(viewDate.value),
60
65
  )
61
66
 
62
67
  const calendarDays = computed(() => {
@@ -138,7 +143,7 @@ function isInRange(iso: string) {
138
143
  const fmtDisplay = (iso: string | null) => {
139
144
  if (!iso) return '—'
140
145
  const d = new Date(iso + 'T00:00:00')
141
- return new Intl.DateTimeFormat(props.locale, { month: 'short', day: 'numeric' }).format(d)
146
+ return new Intl.DateTimeFormat(resolvedLocale.value, { month: 'short', day: 'numeric' }).format(d)
142
147
  }
143
148
 
144
149
  // ── Actions ────────────────────────────────────────────────────────