@m3ui-vue/m3ui-vue 1.0.3 → 1.1.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.
- 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 +5276 -4718
- 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__/MShape.test.ts +20 -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/MShape.vue +22 -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
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* Internal (not exported): MMap's attribution, instead of MapLibre's AttributionControl. A round M3 icon button in a
|
|
4
|
+
* corner (surface, elevation 2) that opens into a pill with the credits of the style's sources, its size springing
|
|
5
|
+
* open and closed through MMapControl. The credits are collected like MapLibre's control does: the attribution of
|
|
6
|
+
* every source a layer uses (from its TileJSON once loaded, else the style), without repeats or ones contained in
|
|
7
|
+
* another. They're HTML from the style (links), as MapLibre renders them.
|
|
8
|
+
*/
|
|
9
|
+
import { computed, ref } from 'vue'
|
|
10
|
+
import type * as Maplibre from 'maplibre-gl'
|
|
11
|
+
import MIcon from './MIcon.vue'
|
|
12
|
+
import MMapControl from './MMapControl.vue'
|
|
13
|
+
import { useMap } from '../composables/useMap'
|
|
14
|
+
import { useLocale } from '../composables/useLocale'
|
|
15
|
+
import type { MapControlPosition } from './MMap.vue'
|
|
16
|
+
|
|
17
|
+
const props = defineProps<{ position: MapControlPosition }>()
|
|
18
|
+
|
|
19
|
+
const t = useLocale()
|
|
20
|
+
const { on, onReady } = useMap()
|
|
21
|
+
|
|
22
|
+
const credits = ref<string[]>([])
|
|
23
|
+
const open = ref(true)
|
|
24
|
+
// The text wraps against the map's width, not the control's while its size springs (it would reflow every frame)
|
|
25
|
+
const maxWidth = ref(0)
|
|
26
|
+
let map: Maplibre.Map | undefined
|
|
27
|
+
|
|
28
|
+
function collect() {
|
|
29
|
+
if (!map) return
|
|
30
|
+
const style = map.getStyle?.()
|
|
31
|
+
if (!style?.sources) return
|
|
32
|
+
const used = new Set(style.layers?.map((l) => (l as { source?: string }).source).filter(Boolean))
|
|
33
|
+
const found: string[] = []
|
|
34
|
+
for (const [id, spec] of Object.entries(style.sources)) {
|
|
35
|
+
if (used.size && !used.has(id)) continue
|
|
36
|
+
const text = (map.getSource(id) as { attribution?: string } | undefined)?.attribution ?? (spec as { attribution?: string }).attribution
|
|
37
|
+
if (text && !found.includes(text)) found.push(text)
|
|
38
|
+
}
|
|
39
|
+
const next = found.filter((a) => !found.some((b) => b !== a && b.includes(a)))
|
|
40
|
+
if (next.join('\n') !== credits.value.join('\n')) credits.value = next
|
|
41
|
+
maxWidth.value = Math.max(0, map.getContainer().clientWidth - 20)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onReady((m) => {
|
|
45
|
+
map = m
|
|
46
|
+
collect()
|
|
47
|
+
})
|
|
48
|
+
on('styledata', collect)
|
|
49
|
+
on('sourcedata', collect)
|
|
50
|
+
on('resize', collect)
|
|
51
|
+
// Open when the map loads, folded away once it's dragged, as MapLibre's compact attribution
|
|
52
|
+
on('dragstart', () => { open.value = false })
|
|
53
|
+
|
|
54
|
+
const html = computed(() => credits.value.join(' '))
|
|
55
|
+
// The button sits at the corner's outer edge, the text inward
|
|
56
|
+
const end = computed(() => props.position.endsWith('right'))
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<template>
|
|
60
|
+
<MMapControl
|
|
61
|
+
v-if="html"
|
|
62
|
+
:position="position"
|
|
63
|
+
:group="false"
|
|
64
|
+
class="m3-map-attrib"
|
|
65
|
+
:class="open ? 'm3-map-attrib-open' : ''"
|
|
66
|
+
>
|
|
67
|
+
<div class="m3-map-attrib-row" :class="end ? 'flex-row-reverse' : ''" :style="maxWidth ? { maxWidth: `${maxWidth}px` } : undefined">
|
|
68
|
+
<button
|
|
69
|
+
type="button"
|
|
70
|
+
class="m3-map-attrib-button"
|
|
71
|
+
:title="t.mapToggleAttribution"
|
|
72
|
+
:aria-label="t.mapToggleAttribution"
|
|
73
|
+
:aria-expanded="open"
|
|
74
|
+
@click="open = !open"
|
|
75
|
+
>
|
|
76
|
+
<MIcon name="info" :size="20" />
|
|
77
|
+
</button>
|
|
78
|
+
<div v-if="open" class="m3-map-attrib-text" :class="end ? 'pl-3.5' : 'pr-3.5'" v-html="html" />
|
|
79
|
+
</div>
|
|
80
|
+
</MMapControl>
|
|
81
|
+
</template>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Internal (not exported): MapLibre's default marker pin. Its SVG is 41px tall with the tip at the center of the
|
|
2
|
+
// shadow ellipse below it (y ≈ 34.8), so MapLibre places it by its center, offset [0, -14], and gives a popup it
|
|
3
|
+
// opens an offset per side (Marker.setPopup) so the popup meets the pin wherever it opens. Passing the pin an
|
|
4
|
+
// anchor of 'bottom' (plus that default offset) put the tip about 20px above its point.
|
|
5
|
+
import type * as Maplibre from 'maplibre-gl'
|
|
6
|
+
|
|
7
|
+
const HEIGHT = 41 - 5.8 / 2
|
|
8
|
+
const RADIUS = 13.5
|
|
9
|
+
const LINEAR = RADIUS / Math.SQRT2
|
|
10
|
+
|
|
11
|
+
/** The default pin's offset with its default (center) anchor */
|
|
12
|
+
export const PIN_OFFSET: [number, number] = [0, -14]
|
|
13
|
+
|
|
14
|
+
/** Offsets for a popup at a pin's point, per side, as MapLibre's Marker.setPopup gives them */
|
|
15
|
+
export const PIN_POPUP_OFFSET: Record<Maplibre.PositionAnchor, [number, number]> = {
|
|
16
|
+
center: [0, 0],
|
|
17
|
+
top: [0, 0],
|
|
18
|
+
'top-left': [0, 0],
|
|
19
|
+
'top-right': [0, 0],
|
|
20
|
+
bottom: [0, -HEIGHT],
|
|
21
|
+
'bottom-left': [LINEAR, (HEIGHT - RADIUS + LINEAR) * -1],
|
|
22
|
+
'bottom-right': [-LINEAR, (HEIGHT - RADIUS + LINEAR) * -1],
|
|
23
|
+
left: [RADIUS, (HEIGHT - RADIUS) * -1],
|
|
24
|
+
right: [-RADIUS, (HEIGHT - RADIUS) * -1],
|
|
25
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Internal (not exported from index.ts): keeps a popup on screen along one axis, after Compose's
|
|
3
|
+
* DropdownMenuPositionProvider (material3/internal/MenuPosition.kt). The candidates are tried in order and the
|
|
4
|
+
* first that fits inside the window, MARGIN in from its edges (MenuHorizontalMargin), wins; when none does, a
|
|
5
|
+
* popup wider than the window minus the margins is centered, anything else is clamped inside them.
|
|
6
|
+
*
|
|
7
|
+
* Measure the popup with nothing constraining its width (no `right`, no narrow `left`) before calling this:
|
|
8
|
+
* a fixed element anchored on its right shrinks to the space on its left, which is the very overflow to avoid.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Compose's MenuHorizontalMargin (8dp). */
|
|
12
|
+
export const POPUP_MARGIN = 8
|
|
13
|
+
|
|
14
|
+
/** The first candidate start position that keeps `size` inside `viewport`, else centered or clamped. */
|
|
15
|
+
export function fitPopup(candidates: number[], size: number, viewport: number, margin = POPUP_MARGIN): number {
|
|
16
|
+
for (const x of candidates) {
|
|
17
|
+
if (x >= margin && x + size <= viewport - margin) return x
|
|
18
|
+
}
|
|
19
|
+
if (size >= viewport - 2 * margin) return (viewport - size) / 2
|
|
20
|
+
const last = candidates[candidates.length - 1] ?? margin
|
|
21
|
+
return Math.min(viewport - margin - size, Math.max(margin, last))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A dropdown's left edge: aligned with the anchor's start or end edge (`align` picks which is tried first), else
|
|
26
|
+
* against the window edge on the anchor's side (MenuAnchorPosition.Below's xCandidates).
|
|
27
|
+
*/
|
|
28
|
+
export function dropdownX(
|
|
29
|
+
anchor: { left: number; right: number },
|
|
30
|
+
width: number,
|
|
31
|
+
viewport: number,
|
|
32
|
+
align: 'start' | 'end',
|
|
33
|
+
margin = POPUP_MARGIN,
|
|
34
|
+
): number {
|
|
35
|
+
const start = anchor.left
|
|
36
|
+
const end = anchor.right - width
|
|
37
|
+
const windowSide = (anchor.left + anchor.right) / 2 < viewport / 2 ? margin : viewport - margin - width
|
|
38
|
+
return fitPopup(align === 'start' ? [start, end, windowSide] : [end, start, windowSide], width, viewport, margin)
|
|
39
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { computed, type Ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Internal (not exported from index.ts): the month grid MDatePicker, MDatePickerModal, MDateRangePicker and
|
|
5
|
+
* MDateRangePickerModal each built by hand, line for line the same. Six weeks starting on Monday, the days of the
|
|
6
|
+
* months around it included, as ISO dates (YYYY-MM-DD) with whether min/max leave them out.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface CalendarDay {
|
|
10
|
+
/** Day of the month */
|
|
11
|
+
date: number
|
|
12
|
+
/** In the month shown (not the neighbors' days filling its first and last week) */
|
|
13
|
+
current: boolean
|
|
14
|
+
iso: string
|
|
15
|
+
disabled: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** YYYY-MM-DD for a year, a 0-based month and a day; months and days past their range roll over, as Date does */
|
|
19
|
+
export function isoDate(y: number, m: number, d: number) {
|
|
20
|
+
const dt = new Date(y, m, d)
|
|
21
|
+
return `${dt.getFullYear()}-${String(dt.getMonth() + 1).padStart(2, '0')}-${String(dt.getDate()).padStart(2, '0')}`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function useCalendarMonth(
|
|
25
|
+
viewDate: Ref<Date>,
|
|
26
|
+
opts: { locale: () => string; min: () => string | undefined; max: () => string | undefined },
|
|
27
|
+
) {
|
|
28
|
+
// Narrow weekday names, Monday first (1 Jan 2024 was a Monday)
|
|
29
|
+
const weekdays = computed(() => {
|
|
30
|
+
const f = new Intl.DateTimeFormat(opts.locale(), { weekday: 'narrow' })
|
|
31
|
+
return Array.from({ length: 7 }, (_, i) => f.format(new Date(2024, 0, i + 1)))
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const monthLabel = computed(() =>
|
|
35
|
+
new Intl.DateTimeFormat(opts.locale(), { month: 'long', year: 'numeric' }).format(viewDate.value),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
function isOutOfRange(iso: string) {
|
|
39
|
+
const min = opts.min()
|
|
40
|
+
const max = opts.max()
|
|
41
|
+
return (!!min && iso < min) || (!!max && iso > max)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const days = computed(() => {
|
|
45
|
+
const y = viewDate.value.getFullYear()
|
|
46
|
+
const m = viewDate.value.getMonth()
|
|
47
|
+
const startDay = (new Date(y, m, 1).getDay() + 6) % 7
|
|
48
|
+
const daysInMonth = new Date(y, m + 1, 0).getDate()
|
|
49
|
+
const out: CalendarDay[] = []
|
|
50
|
+
const day = (yy: number, mm: number, d: number, current: boolean) => {
|
|
51
|
+
const iso = isoDate(yy, mm, d)
|
|
52
|
+
out.push({ date: d, current, iso, disabled: isOutOfRange(iso) })
|
|
53
|
+
}
|
|
54
|
+
const prevDays = new Date(y, m, 0).getDate()
|
|
55
|
+
for (let i = startDay - 1; i >= 0; i--) day(y, m - 1, prevDays - i, false)
|
|
56
|
+
for (let d = 1; d <= daysInMonth; d++) day(y, m, d, true)
|
|
57
|
+
for (let d = 1; out.length < 42; d++) day(y, m + 1, d, false)
|
|
58
|
+
return out
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const isToday = (iso: string) => {
|
|
62
|
+
const now = new Date()
|
|
63
|
+
return iso === isoDate(now.getFullYear(), now.getMonth(), now.getDate())
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Through the 1st: setMonth(month ± 1) on the 31st rolled over (31 March + 1 month = 1 May, skipping April)
|
|
67
|
+
function shiftMonth(by: number) {
|
|
68
|
+
viewDate.value = new Date(viewDate.value.getFullYear(), viewDate.value.getMonth() + by, 1)
|
|
69
|
+
}
|
|
70
|
+
const prevMonth = () => shiftMonth(-1)
|
|
71
|
+
const nextMonth = () => shiftMonth(1)
|
|
72
|
+
|
|
73
|
+
return { weekdays, monthLabel, days, isOutOfRange, isToday, prevMonth, nextMonth }
|
|
74
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getCurrentInstance, onBeforeUnmount, watch, type WatchSource } from 'vue'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Internal (not exported from index.ts): Escape for stacked modal surfaces. Each MDialog used to listen on document
|
|
5
|
+
* itself, so with a dialog opened over another (a date picker over a form) one Escape closed them all. Open
|
|
6
|
+
* surfaces go on a stack, and one listener hands Escape to the top one only. A persistent dialog on top takes it and
|
|
7
|
+
* does nothing, so the one under it stays.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const stack: (() => void)[] = []
|
|
11
|
+
|
|
12
|
+
function onKeydown(e: KeyboardEvent) {
|
|
13
|
+
if (e.key !== 'Escape' || !stack.length) return
|
|
14
|
+
stack[stack.length - 1]!()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Calls `onEscape` on Escape while `active`, unless something opened later is on top of it. */
|
|
18
|
+
export function useEscapeStack(active: WatchSource<boolean>, onEscape: () => void) {
|
|
19
|
+
const entry = () => onEscape()
|
|
20
|
+
function set(on: boolean) {
|
|
21
|
+
if (typeof document === 'undefined') return
|
|
22
|
+
const i = stack.indexOf(entry)
|
|
23
|
+
if (on && i < 0) {
|
|
24
|
+
stack.push(entry)
|
|
25
|
+
if (stack.length === 1) document.addEventListener('keydown', onKeydown)
|
|
26
|
+
} else if (!on && i >= 0) {
|
|
27
|
+
stack.splice(i, 1)
|
|
28
|
+
if (!stack.length) document.removeEventListener('keydown', onKeydown)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
watch(active, (on) => set(!!on), { immediate: true })
|
|
32
|
+
if (getCurrentInstance()) onBeforeUnmount(() => set(false))
|
|
33
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getCurrentInstance, onBeforeUnmount, watch, type WatchSource } from 'vue'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Internal (not exported from index.ts): locks the page's scroll (body overflow hidden) while a modal surface is
|
|
5
|
+
* open, shared by every component that does it. Counted, so overlays stacked on each other (a select's modal or a
|
|
6
|
+
* date picker inside an MDialog) release it only when the last one closes: each component used to write
|
|
7
|
+
* `overflow = ''` on its own, so closing the inner one let the page under the outer one scroll again. Each
|
|
8
|
+
* instance also releases what it holds when it unmounts (a dialog removed while open left the page locked for good)
|
|
9
|
+
* and nothing when it holds nothing (a select unmounting inside an open dialog used to unlock it).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
let count = 0
|
|
13
|
+
let previous = ''
|
|
14
|
+
|
|
15
|
+
function lock() {
|
|
16
|
+
if (count++ === 0) {
|
|
17
|
+
previous = document.body.style.overflow
|
|
18
|
+
document.body.style.overflow = 'hidden'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function unlock() {
|
|
23
|
+
if (count > 0 && --count === 0) document.body.style.overflow = previous
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Locks the page's scroll while `active` is true (from the start too: a dialog mounted open locks it), and releases
|
|
28
|
+
* it when it turns false or the component unmounts. Without `active`, drive it with the returned `set`.
|
|
29
|
+
*/
|
|
30
|
+
export function useScrollLock(active?: WatchSource<boolean>) {
|
|
31
|
+
let held = false
|
|
32
|
+
function set(on: boolean) {
|
|
33
|
+
if (typeof document === 'undefined' || on === held) return
|
|
34
|
+
held = on
|
|
35
|
+
if (on) lock()
|
|
36
|
+
else unlock()
|
|
37
|
+
}
|
|
38
|
+
if (active) watch(active, (on) => set(!!on), { immediate: true })
|
|
39
|
+
if (getCurrentInstance()) onBeforeUnmount(() => set(false))
|
|
40
|
+
return { set }
|
|
41
|
+
}
|
|
@@ -18,17 +18,34 @@ import { sampleSpring, sampleAt, playSamples, prefersReducedMotion } from './_sp
|
|
|
18
18
|
*
|
|
19
19
|
* Wire it to a `<Transition :css="false" @enter @leave>` around a root holding
|
|
20
20
|
* `[data-sheet-panel]` and `[data-sheet-scrim]`.
|
|
21
|
+
*
|
|
22
|
+
* Resting offsets other than fully open (MBottomSheet's partially expanded state) come from
|
|
23
|
+
* `anchors`: a released drag goes to the next anchor its fling points at, or past
|
|
24
|
+
* DISMISS_DISTANCE (or halfway to the next anchor, if closer) to the anchor nearest where it was
|
|
25
|
+
* dropped on that side, else back to the one it started from; off-screen (1) is always the last
|
|
26
|
+
* one and dismisses.
|
|
21
27
|
*/
|
|
22
28
|
|
|
23
29
|
const DEFAULT_SPATIAL = motionSprings.standard.defaultSpatial
|
|
24
30
|
const FAST_EFFECTS = motionSprings.standard.fastEffects
|
|
25
31
|
const DEFAULT_EFFECTS = motionSprings.standard.defaultEffects
|
|
26
32
|
|
|
27
|
-
/** Past this many px, or this fast (px/s)
|
|
33
|
+
/** Past this many px, or this fast (px/s), a released drag leaves its anchor (off-screen = dismissed). */
|
|
28
34
|
const DISMISS_DISTANCE = 100
|
|
29
35
|
const DISMISS_VELOCITY = 1000
|
|
30
36
|
|
|
31
|
-
export
|
|
37
|
+
export interface SheetMotionOptions {
|
|
38
|
+
/** Resting offsets while open, as fractions of the panel's size (0 = fully open). Default [0]. */
|
|
39
|
+
anchors?: (panel: HTMLElement) => number[]
|
|
40
|
+
/** The anchor an open lands on. Default 0. */
|
|
41
|
+
openAt?: (panel: HTMLElement) => number
|
|
42
|
+
/** The sheet is heading for this resting anchor (on open, a drag release or snapTo). */
|
|
43
|
+
onAnchor?: (anchor: number, panel: HTMLElement | null) => void
|
|
44
|
+
/** A drag took over the panel (true) or let go (false). */
|
|
45
|
+
onDrag?: (active: boolean) => void
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function useSheetMotion(axis: 'x' | 'y', onDismiss: () => void, opts: SheetMotionOptions = {}) {
|
|
32
49
|
let panel: HTMLElement | null = null
|
|
33
50
|
let scrim: HTMLElement | null = null
|
|
34
51
|
// 0 = open, 1 = off-screen (a fraction of the panel's size); alpha is the scrim's opacity
|
|
@@ -43,7 +60,7 @@ export function useSheetMotion(axis: 'x' | 'y', onDismiss: () => void) {
|
|
|
43
60
|
let settled: (() => void) | null = null
|
|
44
61
|
|
|
45
62
|
let dragging = false
|
|
46
|
-
let
|
|
63
|
+
let dragStart0 = 0
|
|
47
64
|
let dragOrigin = 0
|
|
48
65
|
let size = 1
|
|
49
66
|
let lastMove = { at: 0, pos: 0 }
|
|
@@ -138,7 +155,9 @@ export function useSheetMotion(axis: 'x' | 'y', onDismiss: () => void) {
|
|
|
138
155
|
alphaTarget = 0
|
|
139
156
|
velocity = 0
|
|
140
157
|
write()
|
|
141
|
-
|
|
158
|
+
const to = panel && opts.openAt ? opts.openAt(panel) : 0
|
|
159
|
+
animate(to, DEFAULT_SPATIAL, 1, done)
|
|
160
|
+
opts.onAnchor?.(to, panel)
|
|
142
161
|
}
|
|
143
162
|
|
|
144
163
|
function onLeave(el: Element, done: () => void) {
|
|
@@ -147,48 +166,91 @@ export function useSheetMotion(axis: 'x' | 'y', onDismiss: () => void) {
|
|
|
147
166
|
animate(1, FAST_EFFECTS, 0, done)
|
|
148
167
|
}
|
|
149
168
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
169
|
+
// A drag along the axis, from any element in the panel; positions are clientX/clientY
|
|
170
|
+
function dragStart(from: Element, pos: number) {
|
|
171
|
+
// A sheet mounted already open never ran onEnter: find its elements from the target.
|
|
172
|
+
const root = from.closest('[data-sheet-panel]')?.parentElement
|
|
153
173
|
if (root) bind(root)
|
|
154
174
|
stopOffset()
|
|
155
175
|
dragging = true
|
|
156
176
|
size = (panel ? (axis === 'y' ? panel.offsetHeight : panel.offsetWidth) : 0) || 1
|
|
157
|
-
|
|
177
|
+
dragStart0 = pos
|
|
158
178
|
dragOrigin = offset * size
|
|
159
179
|
dragVelocity = 0
|
|
160
180
|
lastMove = { at: performance.now(), pos: dragOrigin }
|
|
161
|
-
|
|
181
|
+
opts.onDrag?.(true)
|
|
162
182
|
}
|
|
163
183
|
|
|
164
|
-
|
|
165
|
-
|
|
184
|
+
// Returns how far (px) the finger went past fully open, which the panel doesn't follow
|
|
185
|
+
function dragMove(pos: number): number {
|
|
186
|
+
if (!dragging) return 0
|
|
166
187
|
const now = performance.now()
|
|
167
|
-
const
|
|
188
|
+
const raw = dragOrigin + pos - dragStart0
|
|
189
|
+
const p = Math.max(0, raw)
|
|
168
190
|
const dt = (now - lastMove.at) / 1000
|
|
169
|
-
if (dt > 0) dragVelocity = (
|
|
170
|
-
lastMove = { at: now, pos }
|
|
171
|
-
offset =
|
|
191
|
+
if (dt > 0) dragVelocity = (p - lastMove.pos) / dt
|
|
192
|
+
lastMove = { at: now, pos: p }
|
|
193
|
+
offset = p / size
|
|
172
194
|
if (panel) panel.style.transform = translate(offset)
|
|
195
|
+
return Math.max(0, -raw)
|
|
173
196
|
}
|
|
174
197
|
|
|
175
|
-
function
|
|
198
|
+
function dragEnd() {
|
|
176
199
|
if (!dragging) return
|
|
177
200
|
dragging = false
|
|
201
|
+
opts.onDrag?.(false)
|
|
178
202
|
// A pause before lifting the finger means no fling.
|
|
179
203
|
if (performance.now() - lastMove.at > 100) dragVelocity = 0
|
|
180
204
|
velocity = dragVelocity / size
|
|
181
|
-
|
|
182
|
-
|
|
205
|
+
const stops = [...(panel && opts.anchors ? opts.anchors(panel) : [0]), 1].sort((a, b) => a - b)
|
|
206
|
+
const nearest = (list: number[], x: number) =>
|
|
207
|
+
list.reduce((best, s) => (Math.abs(s - x) < Math.abs(best - x) ? s : best), list[0]!)
|
|
208
|
+
const start = nearest(stops, dragOrigin / size)
|
|
209
|
+
let to = start
|
|
210
|
+
if (Math.abs(dragVelocity) > DISMISS_VELOCITY) {
|
|
211
|
+
const ahead = dragVelocity > 0
|
|
212
|
+
? stops.filter((s) => s > offset + 1e-3)
|
|
213
|
+
: stops.filter((s) => s < offset - 1e-3).reverse()
|
|
214
|
+
to = ahead[0] ?? (dragVelocity > 0 ? stops[stops.length - 1]! : stops[0]!)
|
|
183
215
|
} else {
|
|
184
|
-
|
|
216
|
+
// Past DISMISS_DISTANCE, or halfway to the next anchor when that's closer
|
|
217
|
+
const side = stops.filter((s) => (offset > start ? s > start : s < start))
|
|
218
|
+
const next = side.length ? nearest(side, start) : start
|
|
219
|
+
if (side.length && Math.abs(offset - start) > Math.min(DISMISS_DISTANCE / size, Math.abs(next - start) / 2)) {
|
|
220
|
+
to = nearest(side, offset)
|
|
221
|
+
}
|
|
185
222
|
}
|
|
223
|
+
if (to >= 1) return onDismiss()
|
|
224
|
+
animate(to, DEFAULT_SPATIAL, alphaTarget)
|
|
225
|
+
opts.onAnchor?.(to, panel)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function onDragStart(e: PointerEvent) {
|
|
229
|
+
const el = e.currentTarget as HTMLElement
|
|
230
|
+
dragStart(el, axis === 'y' ? e.clientY : e.clientX)
|
|
231
|
+
el.setPointerCapture(e.pointerId)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function onDragMove(e: PointerEvent) {
|
|
235
|
+
dragMove(axis === 'y' ? e.clientY : e.clientX)
|
|
186
236
|
}
|
|
187
237
|
|
|
238
|
+
const onDragEnd = dragEnd
|
|
239
|
+
|
|
240
|
+
/** Springs an open sheet to a resting anchor (not while a drag holds it). */
|
|
241
|
+
function snapTo(anchor: number) {
|
|
242
|
+
if (!panel || dragging || Math.abs(offset - anchor) < 1e-3) return
|
|
243
|
+
animate(anchor, DEFAULT_SPATIAL, alphaTarget)
|
|
244
|
+
opts.onAnchor?.(anchor, panel)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Where the panel is headed (or sits), as a fraction of its size. */
|
|
248
|
+
const target = () => offset
|
|
249
|
+
|
|
188
250
|
onBeforeUnmount(() => {
|
|
189
251
|
offsetAnim?.cancel()
|
|
190
252
|
alphaAnim?.cancel()
|
|
191
253
|
})
|
|
192
254
|
|
|
193
|
-
return { onEnter, onLeave, onDragStart, onDragMove, onDragEnd }
|
|
255
|
+
return { onEnter, onLeave, onDragStart, onDragMove, onDragEnd, dragStart, dragMove, dragEnd, snapTo, target }
|
|
194
256
|
}
|
|
@@ -38,6 +38,10 @@ export interface M3Locale {
|
|
|
38
38
|
|
|
39
39
|
// Pickers
|
|
40
40
|
selectDate: string
|
|
41
|
+
ok: string
|
|
42
|
+
dateToggleInput: string
|
|
43
|
+
dateToggleCalendar: string
|
|
44
|
+
dateInputLabel: string
|
|
41
45
|
selectTime: string
|
|
42
46
|
timeHourSelection: string
|
|
43
47
|
timeMinuteSelection: string
|
|
@@ -48,6 +52,10 @@ export interface M3Locale {
|
|
|
48
52
|
sheetExpand: string
|
|
49
53
|
sheetCollapse: string
|
|
50
54
|
sheetDismiss: string
|
|
55
|
+
seekBar: string
|
|
56
|
+
seekBarValue: string
|
|
57
|
+
seekBarShowRemaining: string
|
|
58
|
+
seekBarShowDuration: string
|
|
51
59
|
selectRange: string
|
|
52
60
|
pickStart: string
|
|
53
61
|
pickEnd: string
|
|
@@ -251,6 +259,10 @@ export const defaultLocale: M3Locale = {
|
|
|
251
259
|
remove: 'Remove',
|
|
252
260
|
|
|
253
261
|
selectDate: 'Select date',
|
|
262
|
+
ok: 'OK',
|
|
263
|
+
dateToggleInput: 'Switch to text input',
|
|
264
|
+
dateToggleCalendar: 'Switch to calendar',
|
|
265
|
+
dateInputLabel: 'Date',
|
|
254
266
|
selectTime: 'Select time',
|
|
255
267
|
timeHourSelection: 'Select hour',
|
|
256
268
|
timeMinuteSelection: 'Select minutes',
|
|
@@ -261,6 +273,10 @@ export const defaultLocale: M3Locale = {
|
|
|
261
273
|
sheetExpand: 'Expand bottom sheet',
|
|
262
274
|
sheetCollapse: 'Collapse bottom sheet',
|
|
263
275
|
sheetDismiss: 'Dismiss bottom sheet',
|
|
276
|
+
seekBar: 'Seek',
|
|
277
|
+
seekBarValue: '{position} of {duration}',
|
|
278
|
+
seekBarShowRemaining: 'Show remaining time',
|
|
279
|
+
seekBarShowDuration: 'Show total time',
|
|
264
280
|
selectRange: 'Select range',
|
|
265
281
|
pickStart: 'Select start',
|
|
266
282
|
pickEnd: 'Select end',
|
package/src/index.ts
CHANGED
|
@@ -147,6 +147,7 @@ export { default as MScheduler } from './components/MScheduler.vue'
|
|
|
147
147
|
export { default as MScrollable } from './components/MScrollable.vue'
|
|
148
148
|
export { default as MSearchBar } from './components/MSearchBar.vue'
|
|
149
149
|
export { default as MSection } from './components/MSection.vue'
|
|
150
|
+
export { default as MSeekBar } from './components/MSeekBar.vue'
|
|
150
151
|
export { default as MSegmentedButton } from './components/MSegmentedButton.vue'
|
|
151
152
|
export { default as MScrollField } from './components/MScrollField.vue'
|
|
152
153
|
export { default as MSelect } from './components/MSelect.vue'
|
|
@@ -219,6 +220,7 @@ export type { SpeedDialItem } from './components/MFab.vue'
|
|
|
219
220
|
export type { FabMenuItem } from './components/MFabMenu.vue'
|
|
220
221
|
export type { NavRailItem } from './components/MNavigationRail.vue'
|
|
221
222
|
export type { SchedulerEvent } from './components/MScheduler.vue'
|
|
223
|
+
export type { SeekBarChapter } from './components/MSeekBar.vue'
|
|
222
224
|
export type { SegmentedOption } from './components/MSegmentedButton.vue'
|
|
223
225
|
export type { SpotlightResult } from './components/MSpotlightSearch.vue'
|
|
224
226
|
export type { StepItem } from './components/MStepper.vue'
|
package/src/locales/de.ts
CHANGED
|
@@ -37,6 +37,10 @@ export const deLocale: M3Locale = {
|
|
|
37
37
|
|
|
38
38
|
// Pickers
|
|
39
39
|
selectDate: 'Datum auswählen',
|
|
40
|
+
ok: 'OK',
|
|
41
|
+
dateToggleInput: 'Zur Texteingabe wechseln',
|
|
42
|
+
dateToggleCalendar: 'Zum Kalender wechseln',
|
|
43
|
+
dateInputLabel: 'Datum',
|
|
40
44
|
selectTime: 'Uhrzeit auswählen',
|
|
41
45
|
timeHourSelection: 'Stunde auswählen',
|
|
42
46
|
timeMinuteSelection: 'Minuten auswählen',
|
|
@@ -47,6 +51,10 @@ export const deLocale: M3Locale = {
|
|
|
47
51
|
sheetExpand: 'Ansicht am unteren Rand maximieren',
|
|
48
52
|
sheetCollapse: 'Ansicht am unteren Rand minimieren',
|
|
49
53
|
sheetDismiss: 'Ansicht am unteren Rand schließen',
|
|
54
|
+
seekBar: 'Spulen',
|
|
55
|
+
seekBarValue: '{position} von {duration}',
|
|
56
|
+
seekBarShowRemaining: 'Verbleibende Zeit anzeigen',
|
|
57
|
+
seekBarShowDuration: 'Gesamtdauer anzeigen',
|
|
50
58
|
selectRange: 'Bereich auswählen',
|
|
51
59
|
pickStart: 'Anfang auswählen',
|
|
52
60
|
pickEnd: 'Ende auswählen',
|
package/src/locales/es.ts
CHANGED
|
@@ -37,6 +37,10 @@ export const esLocale: M3Locale = {
|
|
|
37
37
|
|
|
38
38
|
// Pickers
|
|
39
39
|
selectDate: 'Seleccionar fecha',
|
|
40
|
+
ok: 'Aceptar',
|
|
41
|
+
dateToggleInput: 'Cambiar a entrada de texto',
|
|
42
|
+
dateToggleCalendar: 'Cambiar a calendario',
|
|
43
|
+
dateInputLabel: 'Fecha',
|
|
40
44
|
selectTime: 'Seleccionar hora',
|
|
41
45
|
timeHourSelection: 'Seleccionar hora',
|
|
42
46
|
timeMinuteSelection: 'Seleccionar minutos',
|
|
@@ -47,6 +51,10 @@ export const esLocale: M3Locale = {
|
|
|
47
51
|
sheetExpand: 'Expandir hoja inferior',
|
|
48
52
|
sheetCollapse: 'Contraer hoja inferior',
|
|
49
53
|
sheetDismiss: 'Cerrar hoja inferior',
|
|
54
|
+
seekBar: 'Buscar posición',
|
|
55
|
+
seekBarValue: '{position} de {duration}',
|
|
56
|
+
seekBarShowRemaining: 'Mostrar tiempo restante',
|
|
57
|
+
seekBarShowDuration: 'Mostrar duración total',
|
|
50
58
|
selectRange: 'Seleccionar rango',
|
|
51
59
|
pickStart: 'Seleccionar inicio',
|
|
52
60
|
pickEnd: 'Seleccionar fin',
|
package/src/locales/fr.ts
CHANGED
|
@@ -37,6 +37,10 @@ export const frLocale: M3Locale = {
|
|
|
37
37
|
|
|
38
38
|
// Pickers
|
|
39
39
|
selectDate: 'Sélectionner la date',
|
|
40
|
+
ok: 'OK',
|
|
41
|
+
dateToggleInput: 'Passer à la saisie de texte',
|
|
42
|
+
dateToggleCalendar: 'Passer au calendrier',
|
|
43
|
+
dateInputLabel: 'Date',
|
|
40
44
|
selectTime: "Sélectionner l'heure",
|
|
41
45
|
timeHourSelection: "Sélectionner l'heure",
|
|
42
46
|
timeMinuteSelection: 'Sélectionner les minutes',
|
|
@@ -47,6 +51,10 @@ export const frLocale: M3Locale = {
|
|
|
47
51
|
sheetExpand: 'Développer la feuille inférieure',
|
|
48
52
|
sheetCollapse: 'Réduire la feuille inférieure',
|
|
49
53
|
sheetDismiss: 'Fermer la feuille inférieure',
|
|
54
|
+
seekBar: 'Rechercher',
|
|
55
|
+
seekBarValue: '{position} sur {duration}',
|
|
56
|
+
seekBarShowRemaining: 'Afficher le temps restant',
|
|
57
|
+
seekBarShowDuration: 'Afficher la durée totale',
|
|
50
58
|
selectRange: 'Sélectionner la plage',
|
|
51
59
|
pickStart: 'Sélectionner le début',
|
|
52
60
|
pickEnd: 'Sélectionner la fin',
|
package/src/locales/ja.ts
CHANGED
|
@@ -37,6 +37,10 @@ export const jaLocale: M3Locale = {
|
|
|
37
37
|
|
|
38
38
|
// Pickers
|
|
39
39
|
selectDate: '日付を選択',
|
|
40
|
+
ok: 'OK',
|
|
41
|
+
dateToggleInput: 'テキスト入力に切り替え',
|
|
42
|
+
dateToggleCalendar: 'カレンダーに切り替え',
|
|
43
|
+
dateInputLabel: '日付',
|
|
40
44
|
selectTime: '時刻を選択',
|
|
41
45
|
timeHourSelection: '時間を選択',
|
|
42
46
|
timeMinuteSelection: '分を選択',
|
|
@@ -47,6 +51,10 @@ export const jaLocale: M3Locale = {
|
|
|
47
51
|
sheetExpand: 'ボトムシートを開く',
|
|
48
52
|
sheetCollapse: 'ボトムシートを折りたたむ',
|
|
49
53
|
sheetDismiss: 'ボトムシートを閉じる',
|
|
54
|
+
seekBar: 'シーク',
|
|
55
|
+
seekBarValue: '{position} / {duration}',
|
|
56
|
+
seekBarShowRemaining: '残り時間を表示',
|
|
57
|
+
seekBarShowDuration: '合計時間を表示',
|
|
50
58
|
selectRange: '範囲を選択',
|
|
51
59
|
pickStart: '開始を選択',
|
|
52
60
|
pickEnd: '終了を選択',
|
package/src/locales/ko.ts
CHANGED
|
@@ -37,6 +37,10 @@ export const koLocale: M3Locale = {
|
|
|
37
37
|
|
|
38
38
|
// Pickers
|
|
39
39
|
selectDate: '날짜 선택',
|
|
40
|
+
ok: '확인',
|
|
41
|
+
dateToggleInput: '텍스트 입력으로 전환',
|
|
42
|
+
dateToggleCalendar: '달력으로 전환',
|
|
43
|
+
dateInputLabel: '날짜',
|
|
40
44
|
selectTime: '시간 선택',
|
|
41
45
|
timeHourSelection: '시간 선택',
|
|
42
46
|
timeMinuteSelection: '분 선택',
|
|
@@ -47,6 +51,10 @@ export const koLocale: M3Locale = {
|
|
|
47
51
|
sheetExpand: '하단 시트 펼치기',
|
|
48
52
|
sheetCollapse: '하단 시트 접기',
|
|
49
53
|
sheetDismiss: '하단 시트 닫기',
|
|
54
|
+
seekBar: '탐색',
|
|
55
|
+
seekBarValue: '{position} / {duration}',
|
|
56
|
+
seekBarShowRemaining: '남은 시간 표시',
|
|
57
|
+
seekBarShowDuration: '전체 시간 표시',
|
|
50
58
|
selectRange: '범위 선택',
|
|
51
59
|
pickStart: '시작 선택',
|
|
52
60
|
pickEnd: '종료 선택',
|
package/src/locales/pt.ts
CHANGED
|
@@ -37,6 +37,10 @@ export const ptLocale: M3Locale = {
|
|
|
37
37
|
|
|
38
38
|
// Pickers
|
|
39
39
|
selectDate: 'Selecionar data',
|
|
40
|
+
ok: 'OK',
|
|
41
|
+
dateToggleInput: 'Mudar para entrada de texto',
|
|
42
|
+
dateToggleCalendar: 'Mudar para calendário',
|
|
43
|
+
dateInputLabel: 'Data',
|
|
40
44
|
selectTime: 'Selecionar hora',
|
|
41
45
|
timeHourSelection: 'Selecionar hora',
|
|
42
46
|
timeMinuteSelection: 'Selecionar minutos',
|
|
@@ -47,6 +51,10 @@ export const ptLocale: M3Locale = {
|
|
|
47
51
|
sheetExpand: 'Expandir página inferior',
|
|
48
52
|
sheetCollapse: 'Recolher página inferior',
|
|
49
53
|
sheetDismiss: 'Dispensar página inferior',
|
|
54
|
+
seekBar: 'Procurar posição',
|
|
55
|
+
seekBarValue: '{position} de {duration}',
|
|
56
|
+
seekBarShowRemaining: 'Mostrar tempo restante',
|
|
57
|
+
seekBarShowDuration: 'Mostrar duração total',
|
|
50
58
|
selectRange: 'Selecionar intervalo',
|
|
51
59
|
pickStart: 'Selecionar início',
|
|
52
60
|
pickEnd: 'Selecionar fim',
|