@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
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { computed, ref, watch } from 'vue'
|
|
11
11
|
import MButton from './MButton.vue'
|
|
12
|
+
import MDialog from './MDialog.vue'
|
|
12
13
|
import MIconButton from './MIconButton.vue'
|
|
13
14
|
import MTimeScroll from './MTimeScroll.vue'
|
|
14
15
|
import { useLocale } from '../composables/useLocale'
|
|
@@ -70,11 +71,6 @@ watch(() => props.show, (open) => {
|
|
|
70
71
|
selectedMinute.value = props.mode === 'scroll' ? Math.floor(m / props.minuteStep) * props.minuteStep : m
|
|
71
72
|
step.value = 'hour'
|
|
72
73
|
inputMode.value = props.mode
|
|
73
|
-
document.addEventListener('keydown', onKeydown)
|
|
74
|
-
document.body.style.overflow = 'hidden'
|
|
75
|
-
} else {
|
|
76
|
-
document.removeEventListener('keydown', onKeydown)
|
|
77
|
-
document.body.style.overflow = ''
|
|
78
74
|
}
|
|
79
75
|
})
|
|
80
76
|
|
|
@@ -228,6 +224,20 @@ const scrollTime = computed({
|
|
|
228
224
|
const toggleIcon = computed(() =>
|
|
229
225
|
inputMode.value !== 'input' ? 'keyboard' : props.mode === 'scroll' ? 'swipe_vertical' : 'schedule',
|
|
230
226
|
)
|
|
227
|
+
// AM/PM in the app's language, from Intl, as MTimeScroll (the values stay 'AM'/'PM')
|
|
228
|
+
const periods = computed(() => {
|
|
229
|
+
const label = (h: number) => {
|
|
230
|
+
try {
|
|
231
|
+
return new Intl.DateTimeFormat(locale.lang, { hour: 'numeric', hour12: true })
|
|
232
|
+
.formatToParts(new Date(2000, 0, 1, h))
|
|
233
|
+
.find((p) => p.type === 'dayPeriod')?.value ?? (h < 12 ? 'AM' : 'PM')
|
|
234
|
+
} catch {
|
|
235
|
+
return h < 12 ? 'AM' : 'PM'
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return [label(9), label(21)] as const
|
|
239
|
+
})
|
|
240
|
+
|
|
231
241
|
const toggleLabel = computed(() =>
|
|
232
242
|
inputMode.value !== 'input'
|
|
233
243
|
? locale.timeToggleKeyboard
|
|
@@ -276,235 +286,212 @@ function confirm() {
|
|
|
276
286
|
emit('update:show', false)
|
|
277
287
|
}
|
|
278
288
|
|
|
279
|
-
|
|
289
|
+
// Escape or the scrim (MDialog) cancel, like the Cancel button
|
|
290
|
+
function onDialog(open: boolean) {
|
|
291
|
+
if (!open) cancel()
|
|
292
|
+
}
|
|
280
293
|
</script>
|
|
281
294
|
|
|
282
295
|
<template>
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
>
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
? 'bg-tertiary-container text-on-tertiary-container'
|
|
350
|
-
: 'text-on-surface-variant hover:bg-on-surface/8'
|
|
351
|
-
"
|
|
352
|
-
@click="period = 'PM'"
|
|
353
|
-
>PM</button>
|
|
354
|
-
</div>
|
|
355
|
-
</div>
|
|
356
|
-
|
|
357
|
-
<!-- Clock dial -->
|
|
358
|
-
<div
|
|
359
|
-
ref="dialEl"
|
|
360
|
-
class="relative mx-auto h-[256px] w-[256px] select-none"
|
|
361
|
-
@mousedown="onDialDown"
|
|
362
|
-
@touchstart.prevent="onDialTouch"
|
|
363
|
-
>
|
|
364
|
-
<div class="absolute inset-0 rounded-full bg-surface-container-highest" />
|
|
365
|
-
|
|
366
|
-
<svg class="pointer-events-none absolute inset-0" viewBox="0 0 256 256">
|
|
367
|
-
<line
|
|
368
|
-
:x1="CX" :y1="CX"
|
|
369
|
-
:x2="handEnd.x" :y2="handEnd.y"
|
|
370
|
-
stroke="var(--color-primary)" stroke-width="2"
|
|
371
|
-
/>
|
|
372
|
-
<circle :cx="CX" :cy="CX" r="4" fill="var(--color-primary)" />
|
|
373
|
-
<circle :cx="handEnd.x" :cy="handEnd.y" :r="NUM_R" fill="var(--color-primary)" />
|
|
374
|
-
</svg>
|
|
375
|
-
|
|
376
|
-
<template v-if="step === 'hour'">
|
|
377
|
-
<button
|
|
378
|
-
v-for="item in hourItems"
|
|
379
|
-
:key="'h' + item.value"
|
|
380
|
-
type="button"
|
|
381
|
-
class="pointer-events-auto absolute flex h-10 w-10 items-center justify-center rounded-full text-body-large transition-colors"
|
|
382
|
-
:class="
|
|
383
|
-
item.value === selectedHour
|
|
384
|
-
? 'text-on-primary font-medium'
|
|
385
|
-
: 'text-on-surface cursor-pointer'
|
|
386
|
-
"
|
|
387
|
-
:style="{
|
|
388
|
-
left: `${item.x}px`,
|
|
389
|
-
top: `${item.y}px`,
|
|
390
|
-
transform: 'translate(-50%, -50%)',
|
|
391
|
-
}"
|
|
392
|
-
@click.stop="selectHour(item.value)"
|
|
393
|
-
>
|
|
394
|
-
{{ item.label }}
|
|
395
|
-
</button>
|
|
396
|
-
</template>
|
|
397
|
-
|
|
398
|
-
<template v-else>
|
|
399
|
-
<button
|
|
400
|
-
v-for="item in minuteItems"
|
|
401
|
-
:key="'m' + item.value"
|
|
402
|
-
type="button"
|
|
403
|
-
class="pointer-events-auto absolute flex h-10 w-10 items-center justify-center rounded-full text-body-large transition-colors"
|
|
404
|
-
:class="
|
|
405
|
-
item.value === selectedMinute
|
|
406
|
-
? 'text-on-primary font-medium'
|
|
407
|
-
: 'text-on-surface cursor-pointer'
|
|
408
|
-
"
|
|
409
|
-
:style="{
|
|
410
|
-
left: `${item.x}px`,
|
|
411
|
-
top: `${item.y}px`,
|
|
412
|
-
transform: 'translate(-50%, -50%)',
|
|
413
|
-
}"
|
|
414
|
-
@click.stop="selectedMinute = item.value"
|
|
415
|
-
>
|
|
416
|
-
{{ item.label }}
|
|
417
|
-
</button>
|
|
418
|
-
</template>
|
|
419
|
-
</div>
|
|
420
|
-
</template>
|
|
421
|
-
|
|
422
|
-
<!-- ── Scroll mode ─────────────────────────────────── -->
|
|
423
|
-
<div v-else-if="inputMode === 'scroll'" class="flex justify-center pb-4">
|
|
424
|
-
<MTimeScroll v-model="scrollTime" :use24h="use24h" :minute-step="minuteStep" />
|
|
296
|
+
<!-- MDialog's bare box: scrim, Escape, scroll lock, the open/close animation and dialog semantics -->
|
|
297
|
+
<MDialog :model-value="show" bare max-width="328px" :title="title || locale.selectTime" @update:model-value="onDialog">
|
|
298
|
+
<div class="px-6 pt-6 pb-4">
|
|
299
|
+
<!-- Title -->
|
|
300
|
+
<p class="mb-5 text-label-medium text-on-surface-variant">
|
|
301
|
+
{{ title || locale.selectTime }}
|
|
302
|
+
</p>
|
|
303
|
+
|
|
304
|
+
<!-- ── Dial mode ───────────────────────────────────── -->
|
|
305
|
+
<template v-if="inputMode === 'dial'">
|
|
306
|
+
<!-- Time display + AM/PM -->
|
|
307
|
+
<div class="mb-5 flex items-center justify-center gap-2">
|
|
308
|
+
<button
|
|
309
|
+
type="button"
|
|
310
|
+
class="flex h-20 min-w-[96px] items-center justify-center rounded-sm text-display-large transition-colors"
|
|
311
|
+
:class="
|
|
312
|
+
step === 'hour'
|
|
313
|
+
? 'bg-primary-container text-on-primary-container'
|
|
314
|
+
: 'bg-surface-container-highest text-on-surface cursor-pointer hover:bg-on-surface/8'
|
|
315
|
+
"
|
|
316
|
+
@click="step = 'hour'"
|
|
317
|
+
>
|
|
318
|
+
{{ pad(selectedHour) }}
|
|
319
|
+
</button>
|
|
320
|
+
|
|
321
|
+
<span class="text-display-large text-on-surface">:</span>
|
|
322
|
+
|
|
323
|
+
<button
|
|
324
|
+
type="button"
|
|
325
|
+
class="flex h-20 min-w-[96px] items-center justify-center rounded-sm text-display-large transition-colors"
|
|
326
|
+
:class="
|
|
327
|
+
step === 'minute'
|
|
328
|
+
? 'bg-primary-container text-on-primary-container'
|
|
329
|
+
: 'bg-surface-container-highest text-on-surface cursor-pointer hover:bg-on-surface/8'
|
|
330
|
+
"
|
|
331
|
+
@click="step = 'minute'"
|
|
332
|
+
>
|
|
333
|
+
{{ pad(selectedMinute) }}
|
|
334
|
+
</button>
|
|
335
|
+
|
|
336
|
+
<!-- AM / PM toggle -->
|
|
337
|
+
<div
|
|
338
|
+
v-if="!use24h"
|
|
339
|
+
class="ml-2 flex h-20 flex-col overflow-hidden rounded-sm border border-outline"
|
|
340
|
+
>
|
|
341
|
+
<button
|
|
342
|
+
type="button"
|
|
343
|
+
class="flex flex-1 items-center justify-center px-3 text-title-medium transition-colors"
|
|
344
|
+
:class="
|
|
345
|
+
period === 'AM'
|
|
346
|
+
? 'bg-tertiary-container text-on-tertiary-container'
|
|
347
|
+
: 'text-on-surface-variant hover:bg-on-surface/8'
|
|
348
|
+
"
|
|
349
|
+
@click="period = 'AM'"
|
|
350
|
+
>{{ periods[0] }}</button>
|
|
351
|
+
<div class="h-px bg-outline" />
|
|
352
|
+
<button
|
|
353
|
+
type="button"
|
|
354
|
+
class="flex flex-1 items-center justify-center px-3 text-title-medium transition-colors"
|
|
355
|
+
:class="
|
|
356
|
+
period === 'PM'
|
|
357
|
+
? 'bg-tertiary-container text-on-tertiary-container'
|
|
358
|
+
: 'text-on-surface-variant hover:bg-on-surface/8'
|
|
359
|
+
"
|
|
360
|
+
@click="period = 'PM'"
|
|
361
|
+
>{{ periods[1] }}</button>
|
|
425
362
|
</div>
|
|
363
|
+
</div>
|
|
426
364
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
365
|
+
<!-- Clock dial -->
|
|
366
|
+
<div
|
|
367
|
+
ref="dialEl"
|
|
368
|
+
class="relative mx-auto h-[256px] w-[256px] select-none"
|
|
369
|
+
@mousedown="onDialDown"
|
|
370
|
+
@touchstart.prevent="onDialTouch"
|
|
371
|
+
>
|
|
372
|
+
<div class="absolute inset-0 rounded-full bg-surface-container-highest" />
|
|
373
|
+
|
|
374
|
+
<svg class="pointer-events-none absolute inset-0" viewBox="0 0 256 256">
|
|
375
|
+
<line
|
|
376
|
+
:x1="CX" :y1="CX"
|
|
377
|
+
:x2="handEnd.x" :y2="handEnd.y"
|
|
378
|
+
stroke="var(--color-primary)" stroke-width="2"
|
|
436
379
|
/>
|
|
437
|
-
<
|
|
438
|
-
<
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
380
|
+
<circle :cx="CX" :cy="CX" r="4" fill="var(--color-primary)" />
|
|
381
|
+
<circle :cx="handEnd.x" :cy="handEnd.y" :r="NUM_R" fill="var(--color-primary)" />
|
|
382
|
+
</svg>
|
|
383
|
+
|
|
384
|
+
<template v-if="step === 'hour'">
|
|
385
|
+
<button
|
|
386
|
+
v-for="item in hourItems"
|
|
387
|
+
:key="'h' + item.value"
|
|
388
|
+
type="button"
|
|
389
|
+
class="pointer-events-auto absolute flex h-10 w-10 items-center justify-center rounded-full text-body-large transition-colors"
|
|
390
|
+
:class="
|
|
391
|
+
item.value === selectedHour
|
|
392
|
+
? 'text-on-primary font-medium'
|
|
393
|
+
: 'text-on-surface cursor-pointer'
|
|
394
|
+
"
|
|
395
|
+
:style="{
|
|
396
|
+
left: `${item.x}px`,
|
|
397
|
+
top: `${item.y}px`,
|
|
398
|
+
transform: 'translate(-50%, -50%)',
|
|
399
|
+
}"
|
|
400
|
+
@click.stop="selectHour(item.value)"
|
|
450
401
|
>
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
:class="
|
|
455
|
-
period === 'AM'
|
|
456
|
-
? 'bg-tertiary-container text-on-tertiary-container'
|
|
457
|
-
: 'text-on-surface-variant hover:bg-on-surface/8'
|
|
458
|
-
"
|
|
459
|
-
@click="period = 'AM'"
|
|
460
|
-
>AM</button>
|
|
461
|
-
<div class="h-px bg-outline" />
|
|
462
|
-
<button
|
|
463
|
-
type="button"
|
|
464
|
-
class="flex flex-1 items-center justify-center px-3 text-title-medium transition-colors"
|
|
465
|
-
:class="
|
|
466
|
-
period === 'PM'
|
|
467
|
-
? 'bg-tertiary-container text-on-tertiary-container'
|
|
468
|
-
: 'text-on-surface-variant hover:bg-on-surface/8'
|
|
469
|
-
"
|
|
470
|
-
@click="period = 'PM'"
|
|
471
|
-
>PM</button>
|
|
472
|
-
</div>
|
|
473
|
-
</div>
|
|
402
|
+
{{ item.label }}
|
|
403
|
+
</button>
|
|
404
|
+
</template>
|
|
474
405
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
:
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
406
|
+
<template v-else>
|
|
407
|
+
<button
|
|
408
|
+
v-for="item in minuteItems"
|
|
409
|
+
:key="'m' + item.value"
|
|
410
|
+
type="button"
|
|
411
|
+
class="pointer-events-auto absolute flex h-10 w-10 items-center justify-center rounded-full text-body-large transition-colors"
|
|
412
|
+
:class="
|
|
413
|
+
item.value === selectedMinute
|
|
414
|
+
? 'text-on-primary font-medium'
|
|
415
|
+
: 'text-on-surface cursor-pointer'
|
|
416
|
+
"
|
|
417
|
+
:style="{
|
|
418
|
+
left: `${item.x}px`,
|
|
419
|
+
top: `${item.y}px`,
|
|
420
|
+
transform: 'translate(-50%, -50%)',
|
|
421
|
+
}"
|
|
422
|
+
@click.stop="selectedMinute = item.value"
|
|
423
|
+
>
|
|
424
|
+
{{ item.label }}
|
|
425
|
+
</button>
|
|
426
|
+
</template>
|
|
487
427
|
</div>
|
|
428
|
+
</template>
|
|
429
|
+
|
|
430
|
+
<!-- ── Scroll mode ─────────────────────────────────── -->
|
|
431
|
+
<div v-else-if="inputMode === 'scroll'" class="flex justify-center pb-4">
|
|
432
|
+
<MTimeScroll v-model="scrollTime" :use24h="use24h" :minute-step="minuteStep" />
|
|
488
433
|
</div>
|
|
489
|
-
</Transition>
|
|
490
|
-
</Teleport>
|
|
491
|
-
</template>
|
|
492
434
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
435
|
+
<!-- ── Input mode ──────────────────────────────────── -->
|
|
436
|
+
<div v-else class="mx-auto flex items-center justify-center gap-2 py-8">
|
|
437
|
+
<input
|
|
438
|
+
ref="inputHourEl"
|
|
439
|
+
v-model="inputHour"
|
|
440
|
+
type="text"
|
|
441
|
+
maxlength="2"
|
|
442
|
+
class="h-20 w-[96px] rounded-sm border border-outline bg-surface-container-highest text-center text-display-large text-on-surface outline-none transition-colors focus:border-2 focus:border-primary"
|
|
443
|
+
@blur="clampInput"
|
|
444
|
+
/>
|
|
445
|
+
<span class="text-display-large text-on-surface">:</span>
|
|
446
|
+
<input
|
|
447
|
+
ref="inputMinuteEl"
|
|
448
|
+
v-model="inputMinute"
|
|
449
|
+
type="text"
|
|
450
|
+
maxlength="2"
|
|
451
|
+
class="h-20 w-[96px] rounded-sm border border-outline bg-surface-container-highest text-center text-display-large text-on-surface outline-none transition-colors focus:border-2 focus:border-primary"
|
|
452
|
+
@blur="clampInput"
|
|
453
|
+
/>
|
|
454
|
+
<!-- AM / PM toggle -->
|
|
455
|
+
<div
|
|
456
|
+
v-if="!use24h"
|
|
457
|
+
class="ml-2 flex h-20 flex-col overflow-hidden rounded-sm border border-outline"
|
|
458
|
+
>
|
|
459
|
+
<button
|
|
460
|
+
type="button"
|
|
461
|
+
class="flex flex-1 items-center justify-center px-3 text-title-medium transition-colors"
|
|
462
|
+
:class="
|
|
463
|
+
period === 'AM'
|
|
464
|
+
? 'bg-tertiary-container text-on-tertiary-container'
|
|
465
|
+
: 'text-on-surface-variant hover:bg-on-surface/8'
|
|
466
|
+
"
|
|
467
|
+
@click="period = 'AM'"
|
|
468
|
+
>{{ periods[0] }}</button>
|
|
469
|
+
<div class="h-px bg-outline" />
|
|
470
|
+
<button
|
|
471
|
+
type="button"
|
|
472
|
+
class="flex flex-1 items-center justify-center px-3 text-title-medium transition-colors"
|
|
473
|
+
:class="
|
|
474
|
+
period === 'PM'
|
|
475
|
+
? 'bg-tertiary-container text-on-tertiary-container'
|
|
476
|
+
: 'text-on-surface-variant hover:bg-on-surface/8'
|
|
477
|
+
"
|
|
478
|
+
@click="period = 'PM'"
|
|
479
|
+
>{{ periods[1] }}</button>
|
|
480
|
+
</div>
|
|
481
|
+
</div>
|
|
482
|
+
|
|
483
|
+
<!-- Footer -->
|
|
484
|
+
<div class="mt-2 flex items-center justify-between">
|
|
485
|
+
<MIconButton
|
|
486
|
+
:icon="toggleIcon"
|
|
487
|
+
:label="toggleLabel"
|
|
488
|
+
@click="inputMode = inputMode === 'input' ? mode : 'input'"
|
|
489
|
+
/>
|
|
490
|
+
<div class="flex gap-2">
|
|
491
|
+
<MButton variant="text" @click="cancel">{{ locale.cancel }}</MButton>
|
|
492
|
+
<MButton variant="text" @click="confirm">{{ locale.ok }}</MButton>
|
|
493
|
+
</div>
|
|
494
|
+
</div>
|
|
495
|
+
</div>
|
|
496
|
+
</MDialog>
|
|
497
|
+
</template>
|
|
@@ -66,6 +66,96 @@ function onTipLeave() {
|
|
|
66
66
|
visible.value = false
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
// Input as Compose's BasicTooltip: a mouse shows it on hover; touch and pen on a long press, which also swallows
|
|
70
|
+
// the click it would end in (a long-pressed button doesn't fire) and hides it TOUCH_DURATION after the finger
|
|
71
|
+
// lifts (BasicTooltipDefaults.TooltipDuration); focus only from the keyboard. Before, the mouse events a browser
|
|
72
|
+
// emulates for a tap (and the focus a tap gives a button) showed it on every tap, and it stuck around.
|
|
73
|
+
const LONG_PRESS = 500
|
|
74
|
+
const TOUCH_DURATION = 1500
|
|
75
|
+
let press: { id: number; x: number; y: number; timer: ReturnType<typeof setTimeout> } | null = null
|
|
76
|
+
let longPressed = false
|
|
77
|
+
|
|
78
|
+
function onPointerEnter(e: PointerEvent) {
|
|
79
|
+
if (e.pointerType === 'mouse') show()
|
|
80
|
+
}
|
|
81
|
+
function onPointerLeave(e: PointerEvent) {
|
|
82
|
+
if (e.pointerType === 'mouse') hide()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function endPress() {
|
|
86
|
+
if (press) clearTimeout(press.timer)
|
|
87
|
+
press = null
|
|
88
|
+
window.removeEventListener('pointermove', onPressMove)
|
|
89
|
+
window.removeEventListener('pointerup', onPressUp)
|
|
90
|
+
window.removeEventListener('pointercancel', onPressCancel)
|
|
91
|
+
}
|
|
92
|
+
function onPointerDown(e: PointerEvent) {
|
|
93
|
+
if (e.pointerType === 'mouse') return
|
|
94
|
+
endPress()
|
|
95
|
+
longPressed = false
|
|
96
|
+
press = {
|
|
97
|
+
id: e.pointerId,
|
|
98
|
+
x: e.clientX,
|
|
99
|
+
y: e.clientY,
|
|
100
|
+
timer: setTimeout(async () => {
|
|
101
|
+
longPressed = true
|
|
102
|
+
cancelTimers()
|
|
103
|
+
visible.value = true
|
|
104
|
+
await nextTick()
|
|
105
|
+
reposition()
|
|
106
|
+
}, LONG_PRESS),
|
|
107
|
+
}
|
|
108
|
+
window.addEventListener('pointermove', onPressMove)
|
|
109
|
+
window.addEventListener('pointerup', onPressUp)
|
|
110
|
+
window.addEventListener('pointercancel', onPressCancel)
|
|
111
|
+
}
|
|
112
|
+
function onPressMove(e: PointerEvent) {
|
|
113
|
+
if (press && e.pointerId === press.id && Math.hypot(e.clientX - press.x, e.clientY - press.y) > 10) endPress()
|
|
114
|
+
}
|
|
115
|
+
function onPressUp(e: PointerEvent) {
|
|
116
|
+
if (!press || e.pointerId !== press.id) return
|
|
117
|
+
endPress()
|
|
118
|
+
if (!longPressed) return
|
|
119
|
+
cancelTimers()
|
|
120
|
+
// A rich tooltip may hold actions to tap: it stays until a touch outside it (Compose's persistent tooltips)
|
|
121
|
+
if (props.rich) document.addEventListener('pointerdown', onOutsideTouch, true)
|
|
122
|
+
else hideTimer = setTimeout(() => { visible.value = false }, TOUCH_DURATION)
|
|
123
|
+
}
|
|
124
|
+
function onOutsideTouch(e: PointerEvent) {
|
|
125
|
+
const t = e.target as Node
|
|
126
|
+
if (tipEl.value?.contains(t) || triggerEl.value?.contains(t)) return
|
|
127
|
+
document.removeEventListener('pointerdown', onOutsideTouch, true)
|
|
128
|
+
visible.value = false
|
|
129
|
+
}
|
|
130
|
+
// The browser took the touch (a scroll)
|
|
131
|
+
function onPressCancel(e: PointerEvent) {
|
|
132
|
+
if (!press || e.pointerId !== press.id) return
|
|
133
|
+
endPress()
|
|
134
|
+
if (longPressed) hide()
|
|
135
|
+
}
|
|
136
|
+
// The click a long press ends in, and the context menu it may open, belong to the tooltip
|
|
137
|
+
function onClickCapture(e: MouseEvent) {
|
|
138
|
+
if (!longPressed) return
|
|
139
|
+
longPressed = false
|
|
140
|
+
e.preventDefault()
|
|
141
|
+
e.stopPropagation()
|
|
142
|
+
}
|
|
143
|
+
function onContextMenu(e: Event) {
|
|
144
|
+
if (press || longPressed) e.preventDefault()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function onFocusIn(e: FocusEvent) {
|
|
148
|
+
let keyboard = true
|
|
149
|
+
try { keyboard = (e.target as Element).matches(':focus-visible') } catch { /* no :focus-visible: show */ }
|
|
150
|
+
if (keyboard) show()
|
|
151
|
+
}
|
|
152
|
+
function onKeyDown(e: KeyboardEvent) {
|
|
153
|
+
if (e.key === 'Escape' && visible.value) {
|
|
154
|
+
cancelTimers()
|
|
155
|
+
visible.value = false
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
69
159
|
function onScroll() {
|
|
70
160
|
if (visible.value) {
|
|
71
161
|
cancelTimers()
|
|
@@ -96,6 +186,8 @@ onMounted(() => window.addEventListener('scroll', onScroll, true))
|
|
|
96
186
|
onUnmounted(() => {
|
|
97
187
|
window.removeEventListener('scroll', onScroll, true)
|
|
98
188
|
cancelTimers()
|
|
189
|
+
endPress()
|
|
190
|
+
document.removeEventListener('pointerdown', onOutsideTouch, true)
|
|
99
191
|
})
|
|
100
192
|
</script>
|
|
101
193
|
|
|
@@ -104,10 +196,14 @@ onUnmounted(() => {
|
|
|
104
196
|
ref="triggerEl"
|
|
105
197
|
v-bind="$attrs"
|
|
106
198
|
class="inline-flex"
|
|
107
|
-
@
|
|
108
|
-
@
|
|
109
|
-
@
|
|
199
|
+
@pointerenter="onPointerEnter"
|
|
200
|
+
@pointerleave="onPointerLeave"
|
|
201
|
+
@pointerdown="onPointerDown"
|
|
202
|
+
@click.capture="onClickCapture"
|
|
203
|
+
@contextmenu="onContextMenu"
|
|
204
|
+
@focusin="onFocusIn"
|
|
110
205
|
@focusout="hide"
|
|
206
|
+
@keydown="onKeyDown"
|
|
111
207
|
>
|
|
112
208
|
<slot />
|
|
113
209
|
</span>
|