@m3ui-vue/m3ui-vue 1.1.4 → 1.2.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 +511 -34
- package/dist/MMenuItem-DI351kIf.js +929 -0
- package/dist/MMenuItem-DI351kIf.js.map +1 -0
- package/dist/{MSlider-JflHJ70q.js → MSlider-BnEy5ieZ.js} +295 -320
- package/dist/MSlider-BnEy5ieZ.js.map +1 -0
- package/dist/MTextField-BBmkaIbO.js +633 -0
- package/dist/MTextField-BBmkaIbO.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +83 -49
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MButton.vue.d.ts +7 -1
- package/dist/components/MButtonGroup.vue.d.ts +40 -31
- package/dist/components/MCarousel.vue.d.ts +2 -0
- package/dist/components/MChart.vue.d.ts +6 -0
- package/dist/components/MCircleProgressBar.vue.d.ts +5 -3
- package/dist/components/MContextMenu.vue.d.ts +2 -2
- package/dist/components/MCopyButton.vue.d.ts +1 -1
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +1 -1
- package/dist/components/MIconButton.vue.d.ts +13 -1
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MMap.vue.d.ts +20 -2
- package/dist/components/MMapBaseLayers.vue.d.ts +3 -0
- package/dist/components/MMapFilter.vue.d.ts +3 -0
- package/dist/components/MMapLayers.vue.d.ts +3 -0
- package/dist/components/MMenu.vue.d.ts +2 -2
- package/dist/components/MMenuItem.vue.d.ts +7 -3
- package/dist/components/MNavigationDrawer.vue.d.ts +13 -2
- package/dist/components/MOverlay.vue.d.ts +12 -1
- package/dist/components/MProgressBar.vue.d.ts +5 -3
- package/dist/components/MPullToRefresh.vue.d.ts +7 -2
- package/dist/components/MRichTextEditor.vue.d.ts +7 -1
- package/dist/components/MSearchField.vue.d.ts +58 -0
- package/dist/components/MSegmentedButton.vue.d.ts +31 -23
- package/dist/components/MSimpleCarousel.vue.d.ts +2 -0
- package/dist/components/MSkeleton.vue.d.ts +6 -3
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTextField.vue.d.ts +5 -1
- package/dist/components/MTimeline.vue.d.ts +85 -22
- package/dist/components/MTooltip.vue.d.ts +1 -1
- package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
- package/dist/composables/_mapStyle.d.ts +13 -0
- package/dist/composables/_themeTransition.d.ts +2 -0
- package/dist/composables/_tooltipTrigger.d.ts +22 -0
- package/dist/composables/_useMenuNav.d.ts +28 -0
- package/dist/composables/useAutoGrow.d.ts +21 -0
- package/dist/composables/useColorPalette.d.ts +1 -1
- package/dist/composables/useLocale.d.ts +3 -0
- package/dist/composables/useMap.d.ts +19 -3
- package/dist/composables/useMapFilter.d.ts +4 -1
- package/dist/composables/useMapLayers.d.ts +5 -2
- package/dist/composables/useScrollReveal.d.ts +44 -0
- package/dist/composables/useThemeTokens.d.ts +21 -0
- package/dist/composables/viewportHints.d.ts +27 -0
- package/dist/directives/vClickOutside.d.ts +25 -0
- package/dist/directives/vFocusRing.d.ts +22 -0
- package/dist/directives/vLongPress.d.ts +27 -0
- package/dist/directives/vReveal.d.ts +10 -0
- package/dist/directives/vScrollElevation.d.ts +31 -0
- package/dist/directives/vSkeleton.d.ts +19 -0
- package/dist/directives/vStateLayer.d.ts +20 -0
- package/dist/directives/vSwipe.d.ts +45 -0
- package/dist/directives/vTooltip.d.ts +23 -0
- package/dist/index.d.ts +28 -1
- package/dist/locales/index.js +21 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7131 -6216
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +1 -1
- package/dist/map.js +821 -791
- package/dist/map.js.map +1 -1
- package/dist/motion-DZiXG09o.js +150 -0
- package/dist/motion-DZiXG09o.js.map +1 -0
- package/dist/plugin.d.ts +24 -0
- package/dist/rich-text-editor.js +13 -9
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles/theme.css +63 -0
- package/dist/styles.css +1 -1
- package/dist/{useLocale-CXibICQA.js → useLocale-JYxDDeXC.js} +4 -2
- package/dist/useLocale-JYxDDeXC.js.map +1 -0
- package/dist/useThemeTokens-Bv-Uv8eX.js +135 -0
- package/dist/useThemeTokens-Bv-Uv8eX.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MButton.test.ts +22 -0
- package/src/__tests__/MCarousel.test.ts +9 -0
- package/src/__tests__/MChart.test.ts +77 -5
- package/src/__tests__/MIconButton.test.ts +33 -0
- package/src/__tests__/MMap.test.ts +53 -1
- package/src/__tests__/MMapLayers.test.ts +46 -2
- package/src/__tests__/MMenu.test.ts +104 -1
- package/src/__tests__/MMenuItem.test.ts +18 -0
- package/src/__tests__/MNavigationDrawer.test.ts +80 -0
- package/src/__tests__/MOverlay.test.ts +49 -0
- package/src/__tests__/MProgressBar.test.ts +41 -0
- package/src/__tests__/MPullToRefresh.test.ts +33 -0
- package/src/__tests__/MRichTextEditor.test.ts +22 -0
- package/src/__tests__/MSearchField.test.ts +71 -0
- package/src/__tests__/MSkeleton.test.ts +38 -0
- package/src/__tests__/MTimeline.test.ts +238 -0
- package/src/__tests__/_fakeMaplibre.ts +3 -1
- package/src/__tests__/attrsFallthrough.test.ts +3 -0
- package/src/__tests__/escapeStack.test.ts +93 -0
- package/src/__tests__/ssr.test.ts +21 -2
- package/src/__tests__/useAutoGrow.test.ts +103 -0
- package/src/__tests__/useScrollReveal.test.ts +102 -0
- package/src/__tests__/useThemeTokens.test.ts +114 -0
- package/src/__tests__/vClickOutside.test.ts +82 -0
- package/src/__tests__/vFocusRing.test.ts +36 -0
- package/src/__tests__/vLongPress.test.ts +81 -0
- package/src/__tests__/vScrollElevation.test.ts +89 -0
- package/src/__tests__/vSkeleton.test.ts +48 -0
- package/src/__tests__/vStateLayer.test.ts +53 -0
- package/src/__tests__/vSwipe.test.ts +93 -0
- package/src/__tests__/vTooltip.test.ts +95 -0
- package/src/__tests__/viewportHints.test.ts +41 -0
- package/src/components/MAutocomplete.vue +5 -0
- package/src/components/MBottomSheet.vue +4 -1
- package/src/components/MButton.vue +15 -1
- package/src/components/MButtonGroup.vue +22 -17
- package/src/components/MCarousel.vue +7 -1
- package/src/components/MChart.vue +74 -34
- package/src/components/MCircleProgressBar.vue +14 -9
- package/src/components/MCommandPalette.vue +3 -2
- package/src/components/MContextMenu.vue +19 -60
- package/src/components/MDragDropList.vue +2 -0
- package/src/components/MIconButton.vue +40 -1
- package/src/components/MKanban.vue +2 -0
- package/src/components/MLightbox.vue +7 -2
- package/src/components/MMap.vue +38 -5
- package/src/components/MMapBaseLayers.vue +7 -3
- package/src/components/MMapFilter.vue +7 -4
- package/src/components/MMapGeoJson.vue +1 -1
- package/src/components/MMapLayers.vue +6 -2
- package/src/components/MMapMeasure.vue +5 -2
- package/src/components/MMenu.vue +18 -59
- package/src/components/MMenuItem.vue +11 -2
- package/src/components/MMultiAutocomplete.vue +5 -0
- package/src/components/MNavigationDrawer.vue +96 -11
- package/src/components/MNavigationRail.vue +4 -15
- package/src/components/MOverlay.vue +32 -13
- package/src/components/MProgressBar.vue +25 -27
- package/src/components/MPullToRefresh.vue +20 -1
- package/src/components/MRichTextEditor.vue +19 -5
- package/src/components/MSearchBar.vue +5 -0
- package/src/components/MSearchField.vue +142 -0
- package/src/components/MSegmentedButton.vue +19 -17
- package/src/components/MSelect.vue +10 -1
- package/src/components/MSideSheet.vue +5 -2
- package/src/components/MSimpleCarousel.vue +10 -1
- package/src/components/MSkeleton.vue +30 -8
- package/src/components/MSpotlightSearch.vue +3 -2
- package/src/components/MTextField.vue +15 -2
- package/src/components/MTimeline.vue +370 -81
- package/src/components/MTooltip.vue +20 -152
- package/src/components/_MDrawerItemList.vue +25 -6
- package/src/composables/_mapStyle.ts +45 -0
- package/src/composables/_themeTransition.ts +2 -0
- package/src/composables/_tooltipTrigger.ts +184 -0
- package/src/composables/_useMenuNav.ts +209 -0
- package/src/composables/useAutoGrow.ts +78 -0
- package/src/composables/useLocale.ts +5 -0
- package/src/composables/useMap.ts +43 -5
- package/src/composables/useMapFilter.ts +6 -5
- package/src/composables/useMapLayers.ts +7 -6
- package/src/composables/useScrollReveal.ts +151 -0
- package/src/composables/useThemeTokens.ts +116 -0
- package/src/composables/viewportHints.ts +80 -0
- package/src/directives/vClickOutside.ts +90 -0
- package/src/directives/vFocusRing.ts +60 -0
- package/src/directives/vLongPress.ts +134 -0
- package/src/directives/vReveal.ts +57 -0
- package/src/directives/vScrollElevation.ts +116 -0
- package/src/directives/vSkeleton.ts +87 -0
- package/src/directives/vStateLayer.ts +83 -0
- package/src/directives/vSwipe.ts +197 -0
- package/src/directives/vTooltip.ts +128 -0
- package/src/index.ts +28 -1
- package/src/locales/de.ts +2 -0
- package/src/locales/es.ts +2 -0
- package/src/locales/fr.ts +2 -0
- package/src/locales/ja.ts +2 -0
- package/src/locales/ko.ts +2 -0
- package/src/locales/pt.ts +2 -0
- package/src/locales/zh.ts +2 -0
- package/src/map.ts +1 -1
- package/src/plugin.ts +34 -0
- package/src/styles/theme.css +63 -0
- package/dist/MMenuItem-BfjqwcYP.js +0 -830
- package/dist/MMenuItem-BfjqwcYP.js.map +0 -1
- package/dist/MSlider-JflHJ70q.js.map +0 -1
- package/dist/MTextField-NaIB6RbM.js +0 -673
- package/dist/MTextField-NaIB6RbM.js.map +0 -1
- package/dist/composables/_useThemeTokens.d.ts +0 -7
- package/dist/useLocale-CXibICQA.js.map +0 -1
- package/src/composables/_useThemeTokens.ts +0 -42
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @slot actions Rich-tooltip action buttons row (only used when rich is true)
|
|
9
9
|
*/
|
|
10
10
|
import { nextTick, onMounted, onUnmounted, ref } from 'vue'
|
|
11
|
+
import { createTooltipTrigger, placeTooltip } from '../composables/_tooltipTrigger'
|
|
11
12
|
|
|
12
13
|
defineOptions({ inheritAttrs: false })
|
|
13
14
|
|
|
@@ -29,166 +30,41 @@ const visible = ref(false)
|
|
|
29
30
|
const tipEl = ref<HTMLElement>()
|
|
30
31
|
const triggerEl = ref<HTMLElement>()
|
|
31
32
|
const tipStyle = ref<Record<string, string>>({})
|
|
32
|
-
let showTimer: ReturnType<typeof setTimeout> | null = null
|
|
33
|
-
let hideTimer: ReturnType<typeof setTimeout> | null = null
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (hideTimer) { clearTimeout(hideTimer); hideTimer = null }
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function show() {
|
|
41
|
-
cancelTimers()
|
|
42
|
-
showTimer = setTimeout(async () => {
|
|
43
|
-
visible.value = true
|
|
44
|
-
await nextTick()
|
|
45
|
-
reposition()
|
|
46
|
-
}, props.delay)
|
|
47
|
-
}
|
|
34
|
+
// Hover, long press, keyboard focus, Escape and scroll: see _tooltipTrigger.ts (shared with v-tooltip)
|
|
35
|
+
let trigger: ReturnType<typeof createTooltipTrigger> | undefined
|
|
48
36
|
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} else {
|
|
54
|
-
visible.value = false
|
|
55
|
-
}
|
|
37
|
+
async function open() {
|
|
38
|
+
visible.value = true
|
|
39
|
+
await nextTick()
|
|
40
|
+
reposition()
|
|
56
41
|
}
|
|
57
42
|
|
|
58
43
|
function onTipEnter() {
|
|
59
|
-
if (
|
|
60
|
-
cancelTimers()
|
|
44
|
+
if (props.rich) trigger?.cancel()
|
|
61
45
|
}
|
|
62
46
|
|
|
63
47
|
function onTipLeave() {
|
|
64
|
-
if (
|
|
65
|
-
cancelTimers()
|
|
66
|
-
visible.value = false
|
|
67
|
-
}
|
|
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
|
-
|
|
159
|
-
function onScroll() {
|
|
160
|
-
if (visible.value) {
|
|
161
|
-
cancelTimers()
|
|
162
|
-
visible.value = false
|
|
163
|
-
}
|
|
48
|
+
if (props.rich) trigger?.closeNow()
|
|
164
49
|
}
|
|
165
50
|
|
|
166
51
|
function reposition() {
|
|
167
52
|
if (!triggerEl.value || !tipEl.value) return
|
|
168
|
-
const
|
|
169
|
-
const tt = tipEl.value.getBoundingClientRect()
|
|
170
|
-
const GAP = 4
|
|
171
|
-
|
|
172
|
-
let top = 0, left = 0
|
|
173
|
-
switch (props.placement) {
|
|
174
|
-
case 'top': top = tr.top - tt.height - GAP; left = tr.left + (tr.width - tt.width) / 2; break
|
|
175
|
-
case 'bottom': top = tr.bottom + GAP; left = tr.left + (tr.width - tt.width) / 2; break
|
|
176
|
-
case 'left': top = tr.top + (tr.height - tt.height) / 2; left = tr.left - tt.width - GAP; break
|
|
177
|
-
case 'right': top = tr.top + (tr.height - tt.height) / 2; left = tr.right + GAP; break
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
top = Math.max(6, Math.min(top, window.innerHeight - tt.height - 6))
|
|
181
|
-
left = Math.max(6, Math.min(left, window.innerWidth - tt.width - 6))
|
|
53
|
+
const { top, left } = placeTooltip(triggerEl.value, tipEl.value, props.placement)
|
|
182
54
|
tipStyle.value = { top: `${top}px`, left: `${left}px` }
|
|
183
55
|
}
|
|
184
56
|
|
|
185
|
-
onMounted(() =>
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
57
|
+
onMounted(() => {
|
|
58
|
+
trigger = createTooltipTrigger(triggerEl.value!, {
|
|
59
|
+
delay: () => props.delay,
|
|
60
|
+
rich: () => props.rich,
|
|
61
|
+
visible: () => visible.value,
|
|
62
|
+
open,
|
|
63
|
+
close: () => { visible.value = false },
|
|
64
|
+
tip: () => tipEl.value,
|
|
65
|
+
})
|
|
191
66
|
})
|
|
67
|
+
onUnmounted(() => trigger?.destroy())
|
|
192
68
|
</script>
|
|
193
69
|
|
|
194
70
|
<template>
|
|
@@ -196,14 +72,6 @@ onUnmounted(() => {
|
|
|
196
72
|
ref="triggerEl"
|
|
197
73
|
v-bind="$attrs"
|
|
198
74
|
class="inline-flex"
|
|
199
|
-
@pointerenter="onPointerEnter"
|
|
200
|
-
@pointerleave="onPointerLeave"
|
|
201
|
-
@pointerdown="onPointerDown"
|
|
202
|
-
@click.capture="onClickCapture"
|
|
203
|
-
@contextmenu="onContextMenu"
|
|
204
|
-
@focusin="onFocusIn"
|
|
205
|
-
@focusout="hide"
|
|
206
|
-
@keydown="onKeyDown"
|
|
207
75
|
>
|
|
208
76
|
<slot />
|
|
209
77
|
</span>
|
|
@@ -16,7 +16,9 @@ export default defineComponent({
|
|
|
16
16
|
const toggleItem = inject<(item: DrawerItem) => void>('nd-toggle-item')!
|
|
17
17
|
const selectItem = inject<(item: DrawerItem) => void>('nd-select-item')!
|
|
18
18
|
const collapsed = inject<Ref<boolean>>('nd-collapsed')!
|
|
19
|
-
|
|
19
|
+
const rail = inject<Ref<boolean>>('nd-rail')!
|
|
20
|
+
const collapsedLabels = inject<Ref<boolean>>('nd-collapsed-labels')!
|
|
21
|
+
return { openItems, toggleItem, selectItem, collapsed, rail, collapsedLabels }
|
|
20
22
|
},
|
|
21
23
|
methods: {
|
|
22
24
|
itemTag(item: DrawerItem) {
|
|
@@ -28,6 +30,12 @@ export default defineComponent({
|
|
|
28
30
|
},
|
|
29
31
|
itemStyle(item: DrawerItem): Record<string, string> {
|
|
30
32
|
const transition = 'padding 300ms cubic-bezier(0.2, 0, 0, 1)'
|
|
33
|
+
if (this.rail) {
|
|
34
|
+
// Same 56px rail item as the top level: icon centered in the 56×32 pill, label below at 40px
|
|
35
|
+
const side = `${(56 - this.iSize(item)) / 2}px`
|
|
36
|
+
const top = (32 - this.iSize(item)) / 2 + 4
|
|
37
|
+
return { paddingLeft: side, paddingRight: side, paddingTop: `${top}px`, paddingBottom: `${56 - top - this.iSize(item)}px`, transition }
|
|
38
|
+
}
|
|
31
39
|
if (this.collapsed) {
|
|
32
40
|
const pad = `${(48 - this.iSize(item)) / 2}px`
|
|
33
41
|
return { paddingLeft: pad, paddingRight: pad, transition }
|
|
@@ -69,20 +77,26 @@ export default defineComponent({
|
|
|
69
77
|
:to="item.to && !item.disabled ? item.to : undefined"
|
|
70
78
|
:type="item.to ? undefined : 'button'"
|
|
71
79
|
:title="collapsed ? item.label : undefined"
|
|
72
|
-
class="flex w-full shrink-0 items-center gap-2.5 overflow-hidden whitespace-nowrap
|
|
80
|
+
class="relative flex w-full shrink-0 items-center gap-2.5 overflow-hidden whitespace-nowrap text-left transition-colors focus-visible:outline-none"
|
|
73
81
|
:class="[
|
|
74
|
-
item.py ?? 'py-1.5',
|
|
82
|
+
rail ? '' : ['rounded-full', item.py ?? 'py-1.5'],
|
|
75
83
|
item.disabled
|
|
76
84
|
? 'cursor-not-allowed opacity-[0.38]'
|
|
77
85
|
: item.value === selected
|
|
78
|
-
? 'bg-secondary-container text-on-secondary-container'
|
|
79
|
-
: 'cursor-pointer text-on-surface-variant hover:bg-on-surface/8',
|
|
86
|
+
? rail ? 'text-on-secondary-container' : 'bg-secondary-container text-on-secondary-container'
|
|
87
|
+
: rail ? 'group cursor-pointer text-on-surface-variant' : 'cursor-pointer text-on-surface-variant hover:bg-on-surface/8',
|
|
80
88
|
]"
|
|
81
89
|
:style="itemStyle(item)"
|
|
82
90
|
:disabled="item.disabled && !item.to"
|
|
83
91
|
@click="onClick(item)"
|
|
84
92
|
>
|
|
85
|
-
<
|
|
93
|
+
<span
|
|
94
|
+
v-if="rail"
|
|
95
|
+
aria-hidden="true"
|
|
96
|
+
class="pointer-events-none absolute left-0 top-1 h-8 w-14 rounded-full transition-colors"
|
|
97
|
+
:class="item.value === selected && !item.disabled ? 'bg-secondary-container' : 'group-hover:bg-on-surface/8'"
|
|
98
|
+
/>
|
|
99
|
+
<MIcon v-if="item.icon" :name="item.icon" :size="iSize(item)" class="relative shrink-0" />
|
|
86
100
|
<span class="nd-label min-w-0 flex-1" :class="lClass(item)">{{ item.label }}</span>
|
|
87
101
|
<MIcon
|
|
88
102
|
v-if="item.children?.length"
|
|
@@ -90,6 +104,11 @@ export default defineComponent({
|
|
|
90
104
|
:size="16"
|
|
91
105
|
class="nd-label shrink-0 text-on-surface-variant"
|
|
92
106
|
/>
|
|
107
|
+
<span
|
|
108
|
+
v-if="collapsedLabels"
|
|
109
|
+
class="nd-rail-label pointer-events-none absolute left-0 top-10 w-14 truncate text-center text-label-medium font-medium"
|
|
110
|
+
:class="item.value === selected ? 'text-secondary' : 'text-on-surface-variant'"
|
|
111
|
+
>{{ item.label }}</span>
|
|
93
112
|
</component>
|
|
94
113
|
|
|
95
114
|
<Transition :css="false" @enter="onEnter" @leave="onLeave">
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type * as Maplibre from 'maplibre-gl'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Internal (not exported from index.ts): what MMap carries over when `mapStyle` changes.
|
|
5
|
+
*
|
|
6
|
+
* MapLibre's setStyle() replaces everything, so sources and layers added at runtime (with useMap(), or the
|
|
7
|
+
* library's own MMapGeoJson / MMapMeasure) were gone after a switch, until whoever added them noticed. A
|
|
8
|
+
* `transformStyle` hook moves them into the next style instead: whatever wasn't part of the previous style as
|
|
9
|
+
* loaded (`own`) was added at runtime. The library's components re-add theirs only when missing, so they just find
|
|
10
|
+
* them there.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** The ids a style came with, before anything was added at runtime */
|
|
14
|
+
export interface StyleIds {
|
|
15
|
+
sources: Set<string>
|
|
16
|
+
layers: Set<string>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function styleIds(style: Pick<Maplibre.StyleSpecification, 'sources' | 'layers'> | undefined): StyleIds {
|
|
20
|
+
return {
|
|
21
|
+
sources: new Set(Object.keys(style?.sources ?? {})),
|
|
22
|
+
layers: new Set((style?.layers ?? []).map((l) => l.id)),
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `next` with the runtime sources and layers of `previous` added: layers on top, in their order, unless `keep`
|
|
28
|
+
* says no or the next style has the same id; sources unless the next style has one by that id (it wins, and
|
|
29
|
+
* carried layers use it).
|
|
30
|
+
*/
|
|
31
|
+
export function carryRuntimeLayers(
|
|
32
|
+
previous: Maplibre.StyleSpecification | undefined,
|
|
33
|
+
next: Maplibre.StyleSpecification,
|
|
34
|
+
own: StyleIds,
|
|
35
|
+
keep: (layer: Maplibre.LayerSpecification) => boolean = () => true,
|
|
36
|
+
): Maplibre.StyleSpecification {
|
|
37
|
+
if (!previous) return next
|
|
38
|
+
const nextLayers = new Set(next.layers.map((l) => l.id))
|
|
39
|
+
const layers = previous.layers.filter((l) => !own.layers.has(l.id) && !nextLayers.has(l.id) && keep(l))
|
|
40
|
+
const sources = { ...next.sources }
|
|
41
|
+
for (const [id, source] of Object.entries(previous.sources)) {
|
|
42
|
+
if (!own.sources.has(id) && !(id in sources)) sources[id] = source
|
|
43
|
+
}
|
|
44
|
+
return { ...next, sources, layers: [...next.layers, ...layers] }
|
|
45
|
+
}
|
|
@@ -19,6 +19,8 @@ const COLOR_TOKENS = [
|
|
|
19
19
|
].map((t) => `--color-${t}`)
|
|
20
20
|
|
|
21
21
|
const DURATION = 250
|
|
22
|
+
/** How long a theme switch's color transition takes, in ms (both paths) */
|
|
23
|
+
export const THEME_TRANSITION_MS = DURATION
|
|
22
24
|
const STYLE_ID = 'm3-theme-transition'
|
|
23
25
|
|
|
24
26
|
// Injected only while switching: a registered <color> computes to rgb(), and code reading a token with
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Internal (not exported from index.ts): what opens and closes a tooltip, shared by MTooltip and v-tooltip.
|
|
3
|
+
*
|
|
4
|
+
* Input as Compose's BasicTooltip: a mouse shows it on hover after `delay`; touch and pen on a long press, which
|
|
5
|
+
* also swallows the click it would end in (a long-pressed button doesn't fire) and hides it TOUCH_DURATION after
|
|
6
|
+
* the finger lifts (BasicTooltipDefaults.TooltipDuration); focus only from the keyboard. Escape hides it (and
|
|
7
|
+
* stops there, so a dialog around it stays open), and so does any scroll. A rich tooltip closes a moment after
|
|
8
|
+
* the pointer leaves (so it can move onto the tooltip), and after a long press stays until a touch outside it.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type TooltipPlacement = 'top' | 'bottom' | 'left' | 'right'
|
|
12
|
+
|
|
13
|
+
const LONG_PRESS = 500
|
|
14
|
+
const TOUCH_DURATION = 1500
|
|
15
|
+
const RICH_HIDE_DELAY = 120
|
|
16
|
+
const GAP = 4
|
|
17
|
+
const MARGIN = 6
|
|
18
|
+
|
|
19
|
+
/** Where `tip` goes next to `trigger`, kept 6px inside the window */
|
|
20
|
+
export function placeTooltip(trigger: HTMLElement, tip: HTMLElement, placement: TooltipPlacement) {
|
|
21
|
+
const tr = trigger.getBoundingClientRect()
|
|
22
|
+
const tt = tip.getBoundingClientRect()
|
|
23
|
+
let top = 0
|
|
24
|
+
let left = 0
|
|
25
|
+
switch (placement) {
|
|
26
|
+
case 'top': top = tr.top - tt.height - GAP; left = tr.left + (tr.width - tt.width) / 2; break
|
|
27
|
+
case 'bottom': top = tr.bottom + GAP; left = tr.left + (tr.width - tt.width) / 2; break
|
|
28
|
+
case 'left': top = tr.top + (tr.height - tt.height) / 2; left = tr.left - tt.width - GAP; break
|
|
29
|
+
case 'right': top = tr.top + (tr.height - tt.height) / 2; left = tr.right + GAP; break
|
|
30
|
+
}
|
|
31
|
+
top = Math.max(MARGIN, Math.min(top, window.innerHeight - tt.height - MARGIN))
|
|
32
|
+
left = Math.max(MARGIN, Math.min(left, window.innerWidth - tt.width - MARGIN))
|
|
33
|
+
return { top, left }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface TooltipTriggerOptions {
|
|
37
|
+
delay: () => number
|
|
38
|
+
rich?: () => boolean
|
|
39
|
+
visible: () => boolean
|
|
40
|
+
open: () => void
|
|
41
|
+
close: () => void
|
|
42
|
+
/** The tooltip's element while shown: a touch on it doesn't close a rich tooltip */
|
|
43
|
+
tip: () => HTMLElement | null | undefined
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function createTooltipTrigger(el: HTMLElement, o: TooltipTriggerOptions) {
|
|
47
|
+
let showTimer: ReturnType<typeof setTimeout> | undefined
|
|
48
|
+
let hideTimer: ReturnType<typeof setTimeout> | undefined
|
|
49
|
+
let press: { id: number, x: number, y: number, timer: ReturnType<typeof setTimeout> } | null = null
|
|
50
|
+
let longPressed = false
|
|
51
|
+
const rich = () => o.rich?.() ?? false
|
|
52
|
+
|
|
53
|
+
function cancel() {
|
|
54
|
+
clearTimeout(showTimer)
|
|
55
|
+
clearTimeout(hideTimer)
|
|
56
|
+
}
|
|
57
|
+
function show() {
|
|
58
|
+
cancel()
|
|
59
|
+
showTimer = setTimeout(o.open, o.delay())
|
|
60
|
+
}
|
|
61
|
+
function hide() {
|
|
62
|
+
cancel()
|
|
63
|
+
if (rich()) hideTimer = setTimeout(o.close, RICH_HIDE_DELAY)
|
|
64
|
+
else o.close()
|
|
65
|
+
}
|
|
66
|
+
function closeNow() {
|
|
67
|
+
cancel()
|
|
68
|
+
o.close()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function onPointerEnter(e: PointerEvent) {
|
|
72
|
+
if (e.pointerType === 'mouse') show()
|
|
73
|
+
}
|
|
74
|
+
function onPointerLeave(e: PointerEvent) {
|
|
75
|
+
if (e.pointerType === 'mouse') hide()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function endPress() {
|
|
79
|
+
if (press) clearTimeout(press.timer)
|
|
80
|
+
press = null
|
|
81
|
+
window.removeEventListener('pointermove', onPressMove)
|
|
82
|
+
window.removeEventListener('pointerup', onPressUp)
|
|
83
|
+
window.removeEventListener('pointercancel', onPressCancel)
|
|
84
|
+
}
|
|
85
|
+
function onPointerDown(e: PointerEvent) {
|
|
86
|
+
if (e.pointerType === 'mouse') return
|
|
87
|
+
endPress()
|
|
88
|
+
longPressed = false
|
|
89
|
+
press = {
|
|
90
|
+
id: e.pointerId,
|
|
91
|
+
x: e.clientX,
|
|
92
|
+
y: e.clientY,
|
|
93
|
+
timer: setTimeout(() => {
|
|
94
|
+
longPressed = true
|
|
95
|
+
cancel()
|
|
96
|
+
o.open()
|
|
97
|
+
}, LONG_PRESS),
|
|
98
|
+
}
|
|
99
|
+
window.addEventListener('pointermove', onPressMove)
|
|
100
|
+
window.addEventListener('pointerup', onPressUp)
|
|
101
|
+
window.addEventListener('pointercancel', onPressCancel)
|
|
102
|
+
}
|
|
103
|
+
function onPressMove(e: PointerEvent) {
|
|
104
|
+
if (press && e.pointerId === press.id && Math.hypot(e.clientX - press.x, e.clientY - press.y) > 10) endPress()
|
|
105
|
+
}
|
|
106
|
+
function onPressUp(e: PointerEvent) {
|
|
107
|
+
if (!press || e.pointerId !== press.id) return
|
|
108
|
+
endPress()
|
|
109
|
+
if (!longPressed) return
|
|
110
|
+
cancel()
|
|
111
|
+
// A rich tooltip may hold actions to tap: it stays until a touch outside it (Compose's persistent tooltips)
|
|
112
|
+
if (rich()) document.addEventListener('pointerdown', onOutsideTouch, true)
|
|
113
|
+
else hideTimer = setTimeout(o.close, TOUCH_DURATION)
|
|
114
|
+
}
|
|
115
|
+
function onOutsideTouch(e: PointerEvent) {
|
|
116
|
+
const t = e.target as Node
|
|
117
|
+
if (o.tip()?.contains(t) || el.contains(t)) return
|
|
118
|
+
document.removeEventListener('pointerdown', onOutsideTouch, true)
|
|
119
|
+
o.close()
|
|
120
|
+
}
|
|
121
|
+
// The browser took the touch (a scroll)
|
|
122
|
+
function onPressCancel(e: PointerEvent) {
|
|
123
|
+
if (!press || e.pointerId !== press.id) return
|
|
124
|
+
endPress()
|
|
125
|
+
if (longPressed) hide()
|
|
126
|
+
}
|
|
127
|
+
// The click a long press ends in, and the context menu it may open, belong to the tooltip
|
|
128
|
+
function onClickCapture(e: MouseEvent) {
|
|
129
|
+
if (!longPressed) return
|
|
130
|
+
longPressed = false
|
|
131
|
+
e.preventDefault()
|
|
132
|
+
e.stopPropagation()
|
|
133
|
+
}
|
|
134
|
+
function onContextMenu(e: Event) {
|
|
135
|
+
if (press || longPressed) e.preventDefault()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function onFocusIn(e: FocusEvent) {
|
|
139
|
+
let keyboard = true
|
|
140
|
+
try { keyboard = (e.target as Element).matches(':focus-visible') } catch { /* no :focus-visible: show */ }
|
|
141
|
+
if (keyboard) show()
|
|
142
|
+
}
|
|
143
|
+
function onKeyDown(e: KeyboardEvent) {
|
|
144
|
+
if (e.key === 'Escape' && o.visible()) {
|
|
145
|
+
// Hiding the tooltip uses the key: a dialog around it stays open
|
|
146
|
+
e.stopPropagation()
|
|
147
|
+
closeNow()
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function onScroll() {
|
|
151
|
+
if (o.visible()) closeNow()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
el.addEventListener('pointerenter', onPointerEnter)
|
|
155
|
+
el.addEventListener('pointerleave', onPointerLeave)
|
|
156
|
+
el.addEventListener('pointerdown', onPointerDown)
|
|
157
|
+
el.addEventListener('click', onClickCapture, true)
|
|
158
|
+
el.addEventListener('contextmenu', onContextMenu)
|
|
159
|
+
el.addEventListener('focusin', onFocusIn)
|
|
160
|
+
el.addEventListener('focusout', hide)
|
|
161
|
+
el.addEventListener('keydown', onKeyDown)
|
|
162
|
+
window.addEventListener('scroll', onScroll, true)
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
/** Keeps it open (the pointer moved onto a rich tooltip) */
|
|
166
|
+
cancel,
|
|
167
|
+
/** Closes it at once */
|
|
168
|
+
closeNow,
|
|
169
|
+
destroy() {
|
|
170
|
+
cancel()
|
|
171
|
+
endPress()
|
|
172
|
+
document.removeEventListener('pointerdown', onOutsideTouch, true)
|
|
173
|
+
el.removeEventListener('pointerenter', onPointerEnter)
|
|
174
|
+
el.removeEventListener('pointerleave', onPointerLeave)
|
|
175
|
+
el.removeEventListener('pointerdown', onPointerDown)
|
|
176
|
+
el.removeEventListener('click', onClickCapture, true)
|
|
177
|
+
el.removeEventListener('contextmenu', onContextMenu)
|
|
178
|
+
el.removeEventListener('focusin', onFocusIn)
|
|
179
|
+
el.removeEventListener('focusout', hide)
|
|
180
|
+
el.removeEventListener('keydown', onKeyDown)
|
|
181
|
+
window.removeEventListener('scroll', onScroll, true)
|
|
182
|
+
},
|
|
183
|
+
}
|
|
184
|
+
}
|