@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.
- package/dist/API.md +75 -11
- package/dist/MMenuItem-BOkcVtEe.js +809 -0
- package/dist/MMenuItem-BOkcVtEe.js.map +1 -0
- package/dist/{MSlider-CdNIH7jc.js → MSlider-BXsBv0ox.js} +208 -182
- package/dist/MSlider-BXsBv0ox.js.map +1 -0
- package/dist/{MTextField-B4X92vH_.js → MTextField-rML9jnXs.js} +2 -2
- package/dist/{MTextField-B4X92vH_.js.map → MTextField-rML9jnXs.js.map} +1 -1
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MBottomSheet.vue.d.ts +20 -1
- package/dist/components/MDialog.vue.d.ts +17 -8
- package/dist/components/MDragDropList.vue.d.ts +1 -1
- package/dist/components/MMap.vue.d.ts +4 -4
- package/dist/components/MMapControl.vue.d.ts +20 -3
- package/dist/components/MMapMarker.vue.d.ts +5 -2
- package/dist/components/MMapPopup.vue.d.ts +5 -3
- package/dist/components/MMenuItem.vue.d.ts +2 -2
- package/dist/components/MSeekBar.vue.d.ts +122 -0
- package/dist/components/MSplitButton.vue.d.ts +2 -2
- package/dist/components/_MMapAttribution.vue.d.ts +7 -0
- package/dist/composables/_mapPin.d.ts +5 -0
- package/dist/composables/_popupPosition.d.ts +12 -0
- package/dist/composables/_useCalendarMonth.d.ts +24 -0
- package/dist/composables/_useEscapeStack.d.ts +3 -0
- package/dist/composables/_useScrollLock.d.ts +8 -0
- package/dist/composables/_useSheetMotion.d.ts +16 -1
- package/dist/composables/useLocale.d.ts +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/locales/index.js +56 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +5269 -4714
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +777 -641
- package/dist/map.js.map +1 -1
- package/dist/rich-text-editor.js +8 -8
- package/dist/styles.css +1 -1
- package/dist/{useLocale-b5-hzsL3.js → useLocale-CqQrhWFl.js} +9 -1
- package/dist/useLocale-CqQrhWFl.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MDialog.test.ts +30 -0
- package/src/__tests__/MMap.test.ts +132 -2
- package/src/__tests__/MSeekBar.test.ts +170 -0
- package/src/__tests__/MTooltip.test.ts +110 -0
- package/src/__tests__/_fakeMaplibre.ts +3 -0
- package/src/__tests__/calendarMonth.test.ts +59 -0
- package/src/__tests__/pickerModals.test.ts +128 -0
- package/src/__tests__/popupPosition.test.ts +224 -0
- package/src/__tests__/scrollLock.test.ts +110 -0
- package/src/__tests__/sheets.test.ts +158 -0
- package/src/components/MAutocomplete.vue +2 -4
- package/src/components/MBottomSheet.vue +211 -13
- package/src/components/MCommandPalette.vue +4 -6
- package/src/components/MContextMenu.vue +19 -5
- package/src/components/MDatePicker.vue +29 -70
- package/src/components/MDatePickerModal.vue +116 -172
- package/src/components/MDateRangePicker.vue +29 -51
- package/src/components/MDateRangePickerModal.vue +84 -162
- package/src/components/MDialog.vue +87 -63
- package/src/components/MLightbox.vue +6 -3
- package/src/components/MMap.vue +74 -28
- package/src/components/MMapControl.vue +121 -7
- package/src/components/MMapIdentify.vue +2 -1
- package/src/components/MMapMarker.vue +14 -7
- package/src/components/MMapPopup.vue +8 -4
- package/src/components/MMenu.vue +31 -12
- package/src/components/MMenuItem.vue +21 -4
- package/src/components/MMultiAutocomplete.vue +2 -4
- package/src/components/MMultiSelect.vue +2 -4
- package/src/components/MNavigationDrawer.vue +2 -8
- package/src/components/MNavigationRail.vue +2 -3
- package/src/components/MSearchBar.vue +2 -5
- package/src/components/MSeekBar.vue +593 -0
- package/src/components/MSelect.vue +2 -8
- package/src/components/MSplitButton.vue +23 -7
- package/src/components/MSpotlightSearch.vue +4 -6
- package/src/components/MTimePicker.vue +23 -6
- package/src/components/MTimePickerModal.vue +213 -226
- package/src/components/MTooltip.vue +99 -3
- package/src/components/_MMapAttribution.vue +81 -0
- package/src/composables/_mapPin.ts +25 -0
- package/src/composables/_popupPosition.ts +39 -0
- package/src/composables/_useCalendarMonth.ts +74 -0
- package/src/composables/_useEscapeStack.ts +33 -0
- package/src/composables/_useScrollLock.ts +41 -0
- package/src/composables/_useSheetMotion.ts +82 -20
- package/src/composables/useLocale.ts +16 -0
- package/src/index.ts +2 -0
- package/src/locales/de.ts +8 -0
- package/src/locales/es.ts +8 -0
- package/src/locales/fr.ts +8 -0
- package/src/locales/ja.ts +8 -0
- package/src/locales/ko.ts +8 -0
- package/src/locales/pt.ts +8 -0
- package/src/locales/zh.ts +8 -0
- package/dist/MMenuItem-DFyXflk9.js +0 -707
- package/dist/MMenuItem-DFyXflk9.js.map +0 -1
- package/dist/MSlider-CdNIH7jc.js.map +0 -1
- package/dist/useLocale-b5-hzsL3.js.map +0 -1
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { computed, ref, watch } from 'vue'
|
|
10
10
|
import MButton from './MButton.vue'
|
|
11
|
+
import MDialog from './MDialog.vue'
|
|
11
12
|
import MIconButton from './MIconButton.vue'
|
|
12
13
|
import MIcon from './MIcon.vue'
|
|
13
14
|
import { useLocale } from '../composables/useLocale'
|
|
15
|
+
import { isoDate as fmt, useCalendarMonth } from '../composables/_useCalendarMonth'
|
|
14
16
|
|
|
15
17
|
const props = withDefaults(defineProps<{
|
|
16
18
|
/** Selected date in YYYY-MM-DD format (v-model) */
|
|
@@ -56,74 +58,19 @@ watch(() => props.show, (open) => {
|
|
|
56
58
|
viewDate.value = props.modelValue ? new Date(props.modelValue + 'T00:00:00') : new Date()
|
|
57
59
|
inputMode.value = 'calendar'
|
|
58
60
|
dateInput.value = props.modelValue ? isoToDisplay(props.modelValue) : ''
|
|
59
|
-
document.addEventListener('keydown', onKeydown)
|
|
60
|
-
document.body.style.overflow = 'hidden'
|
|
61
|
-
} else {
|
|
62
|
-
document.removeEventListener('keydown', onKeydown)
|
|
63
|
-
document.body.style.overflow = ''
|
|
64
61
|
}
|
|
65
62
|
})
|
|
66
63
|
|
|
67
64
|
// ── Calendar logic ─────────────────────────────────────────────────
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
// Weekday names, the month's title and its six-week grid, shared with the other date pickers
|
|
66
|
+
const { weekdays: WEEKDAYS, monthLabel, days: calendarDays, isOutOfRange: isOOR, prevMonth, nextMonth } = useCalendarMonth(viewDate, {
|
|
67
|
+
locale: () => resolvedLocale.value,
|
|
68
|
+
min: () => props.min,
|
|
69
|
+
max: () => props.max,
|
|
71
70
|
})
|
|
72
71
|
|
|
73
|
-
const monthLabel = computed(() =>
|
|
74
|
-
new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' }).format(viewDate.value),
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
const calendarDays = computed(() => {
|
|
78
|
-
const y = viewDate.value.getFullYear()
|
|
79
|
-
const m = viewDate.value.getMonth()
|
|
80
|
-
const first = new Date(y, m, 1)
|
|
81
|
-
const startDay = (first.getDay() + 6) % 7
|
|
82
|
-
const daysInMonth = new Date(y, m + 1, 0).getDate()
|
|
83
|
-
const days: { date: number; current: boolean; iso: string; disabled: boolean }[] = []
|
|
84
|
-
|
|
85
|
-
const prevDays = new Date(y, m, 0).getDate()
|
|
86
|
-
for (let i = startDay - 1; i >= 0; i--) {
|
|
87
|
-
const d = prevDays - i
|
|
88
|
-
const iso = fmt(y, m - 1, d)
|
|
89
|
-
days.push({ date: d, current: false, iso, disabled: isOOR(iso) })
|
|
90
|
-
}
|
|
91
|
-
for (let d = 1; d <= daysInMonth; d++) {
|
|
92
|
-
const iso = fmt(y, m, d)
|
|
93
|
-
days.push({ date: d, current: true, iso, disabled: isOOR(iso) })
|
|
94
|
-
}
|
|
95
|
-
const remaining = 42 - days.length
|
|
96
|
-
for (let d = 1; d <= remaining; d++) {
|
|
97
|
-
const iso = fmt(y, m + 1, d)
|
|
98
|
-
days.push({ date: d, current: false, iso, disabled: isOOR(iso) })
|
|
99
|
-
}
|
|
100
|
-
return days
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
function fmt(y: number, m: number, d: number) {
|
|
104
|
-
const dt = new Date(y, m, d)
|
|
105
|
-
return `${dt.getFullYear()}-${String(dt.getMonth() + 1).padStart(2, '0')}-${String(dt.getDate()).padStart(2, '0')}`
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function isOOR(iso: string) {
|
|
109
|
-
if (props.min && iso < props.min) return true
|
|
110
|
-
if (props.max && iso > props.max) return true
|
|
111
|
-
return false
|
|
112
|
-
}
|
|
113
|
-
|
|
114
72
|
const todayIso = fmt(new Date().getFullYear(), new Date().getMonth(), new Date().getDate())
|
|
115
73
|
|
|
116
|
-
function prevMonth() {
|
|
117
|
-
const d = new Date(viewDate.value)
|
|
118
|
-
d.setMonth(d.getMonth() - 1)
|
|
119
|
-
viewDate.value = d
|
|
120
|
-
}
|
|
121
|
-
function nextMonth() {
|
|
122
|
-
const d = new Date(viewDate.value)
|
|
123
|
-
d.setMonth(d.getMonth() + 1)
|
|
124
|
-
viewDate.value = d
|
|
125
|
-
}
|
|
126
|
-
|
|
127
74
|
function selectDay(day: typeof calendarDays.value[0]) {
|
|
128
75
|
if (day.disabled) return
|
|
129
76
|
selected.value = day.iso
|
|
@@ -137,15 +84,37 @@ const headerDate = computed(() => {
|
|
|
137
84
|
})
|
|
138
85
|
|
|
139
86
|
// ── Input mode ─────────────────────────────────────────────────────
|
|
87
|
+
// The text input follows the locale's numeric date: its order and separator, from Intl (DD/MM/YYYY in Spain,
|
|
88
|
+
// MM/DD/YYYY in the US, YYYY. MM. DD in Korea…). It was DD/MM/YYYY for every language.
|
|
89
|
+
const dateFormat = computed(() => {
|
|
90
|
+
const parts = new Intl.DateTimeFormat(resolvedLocale.value, { day: '2-digit', month: '2-digit', year: 'numeric' })
|
|
91
|
+
.formatToParts(new Date(2026, 5, 23))
|
|
92
|
+
const order = parts.map((p) => p.type).filter((t): t is 'day' | 'month' | 'year' => t === 'day' || t === 'month' || t === 'year')
|
|
93
|
+
const sep = parts.find((p) => p.type === 'literal')?.value ?? '/'
|
|
94
|
+
return { order: order.length === 3 ? order : (['day', 'month', 'year'] as const), sep }
|
|
95
|
+
})
|
|
96
|
+
// The placeholder: DD/MM/YYYY in the locale's order
|
|
97
|
+
const datePattern = computed(() =>
|
|
98
|
+
dateFormat.value.order.map((t) => (t === 'day' ? 'DD' : t === 'month' ? 'MM' : 'YYYY')).join(dateFormat.value.sep.trim() || '/'),
|
|
99
|
+
)
|
|
100
|
+
|
|
140
101
|
function isoToDisplay(iso: string) {
|
|
141
|
-
const [
|
|
142
|
-
|
|
102
|
+
const [year, month, day] = iso.split('-')
|
|
103
|
+
const parts: Record<string, string | undefined> = { year, month, day }
|
|
104
|
+
return dateFormat.value.order.map((t) => parts[t]).join(dateFormat.value.sep)
|
|
143
105
|
}
|
|
144
106
|
|
|
107
|
+
// Any separator is accepted; a day or month may have one digit. Not a real date (31/02): null
|
|
145
108
|
function displayToIso(display: string) {
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
148
|
-
|
|
109
|
+
const nums = display.trim().split(/\D+/).filter(Boolean)
|
|
110
|
+
if (nums.length !== 3) return null
|
|
111
|
+
const parts: Record<string, string> = {}
|
|
112
|
+
dateFormat.value.order.forEach((t, i) => { parts[t] = nums[i]! })
|
|
113
|
+
const { year, month, day } = parts as { year: string; month: string; day: string }
|
|
114
|
+
if (year.length !== 4 || month.length > 2 || day.length > 2) return null
|
|
115
|
+
const date = new Date(Number(year), Number(month) - 1, Number(day))
|
|
116
|
+
if (date.getMonth() !== Number(month) - 1 || date.getDate() !== Number(day)) return null
|
|
117
|
+
return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`
|
|
149
118
|
}
|
|
150
119
|
|
|
151
120
|
function applyInput() {
|
|
@@ -168,119 +137,94 @@ function confirm() {
|
|
|
168
137
|
}
|
|
169
138
|
}
|
|
170
139
|
|
|
171
|
-
|
|
140
|
+
// Escape or the scrim (MDialog) cancel, like the Cancel button
|
|
141
|
+
function onDialog(open: boolean) {
|
|
142
|
+
if (!open) cancel()
|
|
143
|
+
}
|
|
172
144
|
</script>
|
|
173
145
|
|
|
174
146
|
<template>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
>
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
:icon="inputMode === 'calendar' ? 'edit' : 'calendar_today'"
|
|
194
|
-
:label="inputMode === 'calendar' ? 'Switch to input' : 'Switch to calendar'"
|
|
195
|
-
@click="inputMode = inputMode === 'calendar' ? 'input' : 'calendar'"
|
|
196
|
-
/>
|
|
197
|
-
</div>
|
|
198
|
-
</div>
|
|
199
|
-
|
|
200
|
-
<div class="h-px bg-outline-variant" />
|
|
201
|
-
|
|
202
|
-
<!-- Calendar mode -->
|
|
203
|
-
<div v-if="inputMode === 'calendar'" class="px-4 pt-3 pb-2">
|
|
204
|
-
<!-- Month nav -->
|
|
205
|
-
<div class="mb-2 flex items-center justify-between">
|
|
206
|
-
<MIconButton icon="chevron_left" :label="locale.previousMonth" :size="36" @click="prevMonth" />
|
|
207
|
-
<span class="text-title-small font-medium capitalize text-on-surface">{{ monthLabel }}</span>
|
|
208
|
-
<MIconButton icon="chevron_right" :label="locale.nextMonth" :size="36" @click="nextMonth" />
|
|
209
|
-
</div>
|
|
147
|
+
<!-- MDialog's bare box: scrim, Escape, scroll lock, the open/close animation and dialog semantics -->
|
|
148
|
+
<MDialog :model-value="show" bare max-width="360px" :title="title || locale.selectDate" @update:model-value="onDialog">
|
|
149
|
+
<!-- Header -->
|
|
150
|
+
<div class="px-6 pt-6 pb-4">
|
|
151
|
+
<p class="mb-3 text-label-large text-on-surface-variant">
|
|
152
|
+
{{ title || locale.selectDate }}
|
|
153
|
+
</p>
|
|
154
|
+
<div class="flex items-center justify-between">
|
|
155
|
+
<span class="text-headline-large font-medium capitalize text-on-surface-variant">
|
|
156
|
+
{{ headerDate }}
|
|
157
|
+
</span>
|
|
158
|
+
<MIconButton
|
|
159
|
+
:icon="inputMode === 'calendar' ? 'edit' : 'calendar_today'"
|
|
160
|
+
:label="inputMode === 'calendar' ? locale.dateToggleInput : locale.dateToggleCalendar"
|
|
161
|
+
@click="inputMode = inputMode === 'calendar' ? 'input' : 'calendar'"
|
|
162
|
+
/>
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
210
165
|
|
|
211
|
-
|
|
212
|
-
<div class="mb-1 grid grid-cols-7 gap-0.5 text-center">
|
|
213
|
-
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-body-large font-medium text-on-surface">
|
|
214
|
-
{{ wd }}
|
|
215
|
-
</span>
|
|
216
|
-
</div>
|
|
166
|
+
<div class="h-px bg-outline-variant" />
|
|
217
167
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
day.disabled
|
|
227
|
-
? 'cursor-not-allowed text-on-surface/25'
|
|
228
|
-
: day.iso === selected
|
|
229
|
-
? 'bg-primary text-on-primary'
|
|
230
|
-
: day.iso === todayIso
|
|
231
|
-
? 'border border-primary text-primary cursor-pointer hover:bg-primary/8'
|
|
232
|
-
: day.current
|
|
233
|
-
? 'cursor-pointer text-on-surface hover:bg-on-surface/8'
|
|
234
|
-
: 'cursor-pointer text-on-surface-variant/50 hover:bg-on-surface/4',
|
|
235
|
-
]"
|
|
236
|
-
:disabled="day.disabled"
|
|
237
|
-
@click="selectDay(day)"
|
|
238
|
-
>
|
|
239
|
-
{{ day.date }}
|
|
240
|
-
</button>
|
|
241
|
-
</div>
|
|
242
|
-
</div>
|
|
168
|
+
<!-- Calendar mode -->
|
|
169
|
+
<div v-if="inputMode === 'calendar'" class="px-4 pt-3 pb-2">
|
|
170
|
+
<!-- Month nav -->
|
|
171
|
+
<div class="mb-2 flex items-center justify-between">
|
|
172
|
+
<MIconButton icon="chevron_left" :label="locale.previousMonth" :size="36" @click="prevMonth" />
|
|
173
|
+
<span class="text-title-small font-medium capitalize text-on-surface">{{ monthLabel }}</span>
|
|
174
|
+
<MIconButton icon="chevron_right" :label="locale.nextMonth" :size="36" @click="nextMonth" />
|
|
175
|
+
</div>
|
|
243
176
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
placeholder="23/06/2026"
|
|
251
|
-
maxlength="10"
|
|
252
|
-
class="h-14 w-full rounded-xs border border-outline bg-transparent px-4 text-body-large text-on-surface caret-primary outline-none transition-colors focus:border-2 focus:border-primary"
|
|
253
|
-
@keydown.enter="applyInput"
|
|
254
|
-
@blur="applyInput"
|
|
255
|
-
/>
|
|
256
|
-
</div>
|
|
177
|
+
<!-- Weekday headers -->
|
|
178
|
+
<div class="mb-1 grid grid-cols-7 gap-0.5 text-center">
|
|
179
|
+
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-body-large font-medium text-on-surface">
|
|
180
|
+
{{ wd }}
|
|
181
|
+
</span>
|
|
182
|
+
</div>
|
|
257
183
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
184
|
+
<!-- Days grid -->
|
|
185
|
+
<div class="grid grid-cols-7 gap-0.5">
|
|
186
|
+
<button
|
|
187
|
+
v-for="(day, i) in calendarDays"
|
|
188
|
+
:key="i"
|
|
189
|
+
type="button"
|
|
190
|
+
class="flex h-10 w-full items-center justify-center rounded-full text-body-medium transition-colors duration-100"
|
|
191
|
+
:class="[
|
|
192
|
+
day.disabled
|
|
193
|
+
? 'cursor-not-allowed text-on-surface/25'
|
|
194
|
+
: day.iso === selected
|
|
195
|
+
? 'bg-primary text-on-primary'
|
|
196
|
+
: day.iso === todayIso
|
|
197
|
+
? 'border border-primary text-primary cursor-pointer hover:bg-primary/8'
|
|
198
|
+
: day.current
|
|
199
|
+
? 'cursor-pointer text-on-surface hover:bg-on-surface/8'
|
|
200
|
+
: 'cursor-pointer text-on-surface-variant/50 hover:bg-on-surface/4',
|
|
201
|
+
]"
|
|
202
|
+
:disabled="day.disabled"
|
|
203
|
+
@click="selectDay(day)"
|
|
204
|
+
>
|
|
205
|
+
{{ day.date }}
|
|
206
|
+
</button>
|
|
264
207
|
</div>
|
|
265
|
-
</
|
|
266
|
-
|
|
208
|
+
</div>
|
|
209
|
+
|
|
210
|
+
<!-- Input mode -->
|
|
211
|
+
<div v-else class="px-6 py-6">
|
|
212
|
+
<label class="mb-2 block text-label-medium text-on-surface-variant">{{ locale.dateInputLabel }} ({{ datePattern }})</label>
|
|
213
|
+
<input
|
|
214
|
+
v-model="dateInput"
|
|
215
|
+
type="text"
|
|
216
|
+
:placeholder="datePattern"
|
|
217
|
+
maxlength="14"
|
|
218
|
+
class="h-14 w-full rounded-xs border border-outline bg-transparent px-4 text-body-large text-on-surface caret-primary outline-none transition-colors focus:border-2 focus:border-primary"
|
|
219
|
+
@keydown.enter="applyInput"
|
|
220
|
+
@blur="applyInput"
|
|
221
|
+
/>
|
|
222
|
+
</div>
|
|
223
|
+
|
|
224
|
+
<!-- Footer -->
|
|
225
|
+
<div class="flex justify-end gap-2 px-6 pb-4">
|
|
226
|
+
<MButton variant="text" @click="cancel">{{ locale.cancel }}</MButton>
|
|
227
|
+
<MButton variant="text" :disabled="!selected" @click="confirm">{{ locale.ok }}</MButton>
|
|
228
|
+
</div>
|
|
229
|
+
</MDialog>
|
|
267
230
|
</template>
|
|
268
|
-
|
|
269
|
-
<style scoped>
|
|
270
|
-
.m3-dp-modal-enter-active,
|
|
271
|
-
.m3-dp-modal-leave-active {
|
|
272
|
-
transition: opacity 0.15s ease;
|
|
273
|
-
}
|
|
274
|
-
.m3-dp-modal-enter-from,
|
|
275
|
-
.m3-dp-modal-leave-to {
|
|
276
|
-
opacity: 0;
|
|
277
|
-
}
|
|
278
|
-
.m3-dp-modal-enter-active .dp-box,
|
|
279
|
-
.m3-dp-modal-leave-active .dp-box {
|
|
280
|
-
transition: transform 0.15s ease;
|
|
281
|
-
}
|
|
282
|
-
.m3-dp-modal-enter-from .dp-box,
|
|
283
|
-
.m3-dp-modal-leave-to .dp-box {
|
|
284
|
-
transform: scale(0.95);
|
|
285
|
-
}
|
|
286
|
-
</style>
|
|
@@ -9,6 +9,8 @@ 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 { POPUP_MARGIN, dropdownX, fitPopup } from '../composables/_popupPosition'
|
|
13
|
+
import { isoDate as fmt, useCalendarMonth } from '../composables/_useCalendarMonth'
|
|
12
14
|
|
|
13
15
|
export interface DateRange {
|
|
14
16
|
start: string | null
|
|
@@ -65,7 +67,7 @@ const triggerEl = ref<HTMLElement | null>(null)
|
|
|
65
67
|
const panelEl = ref<HTMLElement | null>(null)
|
|
66
68
|
const picking = ref<'start' | 'end'>('start')
|
|
67
69
|
const hovered = ref<string | null>(null)
|
|
68
|
-
const dropPos = ref({ top: '0px', left: '0px' })
|
|
70
|
+
const dropPos = ref<Record<string, string>>({ top: '0px', left: '0px' })
|
|
69
71
|
const { resolvedFieldBg } = useFieldBg(triggerEl, () => props.fieldBg)
|
|
70
72
|
|
|
71
73
|
const viewDate = ref(
|
|
@@ -75,50 +77,13 @@ watch(() => props.modelValue.start, (v) => {
|
|
|
75
77
|
if (v) viewDate.value = new Date(v + 'T00:00:00')
|
|
76
78
|
})
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
// Weekday names, the month's title and its six-week grid, shared with the other date pickers
|
|
81
|
+
const { weekdays: WEEKDAYS, monthLabel, days: calendarDays, isOutOfRange: isOOR, prevMonth, nextMonth } = useCalendarMonth(viewDate, {
|
|
82
|
+
locale: () => resolvedLocale.value,
|
|
83
|
+
min: () => props.min,
|
|
84
|
+
max: () => props.max,
|
|
81
85
|
})
|
|
82
86
|
|
|
83
|
-
const monthLabel = computed(() =>
|
|
84
|
-
new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' }).format(viewDate.value)
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
const calendarDays = computed(() => {
|
|
88
|
-
const y = viewDate.value.getFullYear()
|
|
89
|
-
const m = viewDate.value.getMonth()
|
|
90
|
-
const first = new Date(y, m, 1)
|
|
91
|
-
const startDay = (first.getDay() + 6) % 7
|
|
92
|
-
const daysInMonth = new Date(y, m + 1, 0).getDate()
|
|
93
|
-
const days: { date: number; current: boolean; iso: string; disabled: boolean }[] = []
|
|
94
|
-
|
|
95
|
-
const prevMonth = new Date(y, m, 0).getDate()
|
|
96
|
-
for (let i = startDay - 1; i >= 0; i--) {
|
|
97
|
-
const d = prevMonth - i
|
|
98
|
-
const iso = fmt(y, m - 1, d)
|
|
99
|
-
days.push({ date: d, current: false, iso, disabled: isOOR(iso) })
|
|
100
|
-
}
|
|
101
|
-
for (let d = 1; d <= daysInMonth; d++) {
|
|
102
|
-
const iso = fmt(y, m, d)
|
|
103
|
-
days.push({ date: d, current: true, iso, disabled: isOOR(iso) })
|
|
104
|
-
}
|
|
105
|
-
const remaining = 42 - days.length
|
|
106
|
-
for (let d = 1; d <= remaining; d++) {
|
|
107
|
-
const iso = fmt(y, m + 1, d)
|
|
108
|
-
days.push({ date: d, current: false, iso, disabled: isOOR(iso) })
|
|
109
|
-
}
|
|
110
|
-
return days
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
function fmt(y: number, m: number, d: number) {
|
|
114
|
-
const dt = new Date(y, m, d)
|
|
115
|
-
return `${dt.getFullYear()}-${String(dt.getMonth() + 1).padStart(2, '0')}-${String(dt.getDate()).padStart(2, '0')}`
|
|
116
|
-
}
|
|
117
|
-
function isOOR(iso: string) {
|
|
118
|
-
if (props.min && iso < props.min) return true
|
|
119
|
-
if (props.max && iso > props.max) return true
|
|
120
|
-
return false
|
|
121
|
-
}
|
|
122
87
|
const todayIso = fmt(new Date().getFullYear(), new Date().getMonth(), new Date().getDate())
|
|
123
88
|
|
|
124
89
|
function selectDay(day: typeof calendarDays.value[0]) {
|
|
@@ -147,9 +112,6 @@ function isInRange(iso: string) {
|
|
|
147
112
|
return iso > lo && iso < hi
|
|
148
113
|
}
|
|
149
114
|
|
|
150
|
-
function prevMonth() { const d = new Date(viewDate.value); d.setMonth(d.getMonth() - 1); viewDate.value = d }
|
|
151
|
-
function nextMonth() { const d = new Date(viewDate.value); d.setMonth(d.getMonth() + 1); viewDate.value = d }
|
|
152
|
-
|
|
153
115
|
const displayValue = computed(() => {
|
|
154
116
|
const f = new Intl.DateTimeFormat(resolvedLocale.value, { day: 'numeric', month: 'short' })
|
|
155
117
|
const s = props.modelValue.start ? f.format(new Date(props.modelValue.start + 'T00:00:00')) : '—'
|
|
@@ -160,18 +122,33 @@ const displayValue = computed(() => {
|
|
|
160
122
|
|
|
161
123
|
function clear() { emit('update:modelValue', { start: null, end: null }); picking.value = 'start' }
|
|
162
124
|
|
|
125
|
+
// The panel's size isn't known until it's in the DOM: placeDrop() keeps it on screen once it is, before it paints
|
|
126
|
+
// (see _popupPosition.ts): under the field, aligned with its start edge, else its end edge or the window edge;
|
|
127
|
+
// above it when it doesn't fit below. Until then it waits at the window's left edge, where nothing narrows it.
|
|
128
|
+
let anchorRect: DOMRect | null = null
|
|
163
129
|
function computeDropPos() {
|
|
164
130
|
if (!triggerEl.value) return
|
|
165
131
|
const rect = triggerEl.value.getBoundingClientRect()
|
|
166
|
-
|
|
167
|
-
const spaceBelow = window.innerHeight - rect.bottom - 8
|
|
168
|
-
const above = spaceBelow < panelH && rect.top > panelH
|
|
132
|
+
anchorRect = rect
|
|
169
133
|
dropPos.value = {
|
|
170
|
-
top:
|
|
171
|
-
left:
|
|
134
|
+
top: `${rect.bottom + 4}px`,
|
|
135
|
+
left: '0px',
|
|
136
|
+
maxWidth: `${window.innerWidth - 2 * POPUP_MARGIN}px`,
|
|
172
137
|
}
|
|
173
138
|
}
|
|
174
139
|
|
|
140
|
+
function placeDrop(el: Element) {
|
|
141
|
+
if (!anchorRect) return
|
|
142
|
+
const panel = el as HTMLElement
|
|
143
|
+
const w = panel.offsetWidth
|
|
144
|
+
const h = panel.offsetHeight
|
|
145
|
+
const left = dropdownX(anchorRect, w, window.innerWidth, 'start')
|
|
146
|
+
const top = fitPopup([anchorRect.bottom + 4, anchorRect.top - 4 - h], h, window.innerHeight)
|
|
147
|
+
dropPos.value = { ...dropPos.value, left: `${left}px`, top: `${top}px` }
|
|
148
|
+
panel.style.left = `${left}px`
|
|
149
|
+
panel.style.top = `${top}px`
|
|
150
|
+
}
|
|
151
|
+
|
|
175
152
|
function onOut(e: MouseEvent) {
|
|
176
153
|
const t = e.target as Node
|
|
177
154
|
if (triggerEl.value?.contains(t)) return
|
|
@@ -245,6 +222,7 @@ onUnmounted(() => {
|
|
|
245
222
|
enter-from-class="opacity-0 -translate-y-1 scale-[0.98]"
|
|
246
223
|
leave-active-class="transition-[opacity,transform] duration-100"
|
|
247
224
|
leave-to-class="opacity-0 -translate-y-1 scale-[0.98]"
|
|
225
|
+
@enter="placeDrop"
|
|
248
226
|
>
|
|
249
227
|
<div
|
|
250
228
|
v-if="open"
|