@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
package/src/components/MMap.vue
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { markRaw, onBeforeUnmount, onMounted, onUnmounted, provide, ref, shallowRef, watch } from 'vue'
|
|
21
21
|
import type * as Maplibre from 'maplibre-gl'
|
|
22
|
+
import MMapAttribution from './_MMapAttribution.vue'
|
|
22
23
|
import { useLocale } from '../composables/useLocale'
|
|
23
24
|
import { MAP_KEY, type MaplibreModule } from '../composables/useMap'
|
|
24
25
|
import { createLayerState, readLayerState } from '../composables/useMapLayers'
|
|
@@ -51,7 +52,7 @@ const props = withDefaults(
|
|
|
51
52
|
fullscreen?: boolean | MapControlPosition
|
|
52
53
|
/** A metric scale bar: `false`, or a corner (`true` is bottom-left) */
|
|
53
54
|
scale?: boolean | MapControlPosition
|
|
54
|
-
/** The style's
|
|
55
|
+
/** The credits of the style's sources, an info button that opens into a pill: `false`, or a corner (`true` is bottom-right). Most tile providers require it */
|
|
55
56
|
attribution?: boolean | MapControlPosition
|
|
56
57
|
/** Anything else for MapLibre's `Map` constructor (`maxZoom`, `maxBounds`, `cooperativeGestures`…) */
|
|
57
58
|
options?: Partial<Omit<Maplibre.MapOptions, 'container' | 'style'>>
|
|
@@ -123,7 +124,8 @@ function currentView(m: Maplibre.Map): View {
|
|
|
123
124
|
|
|
124
125
|
// ── Controls ───────────────────────────────────────────────────────────────────────────────────
|
|
125
126
|
|
|
126
|
-
|
|
127
|
+
// The attribution is a component of ours (_MMapAttribution, in the template), not MapLibre's control
|
|
128
|
+
type ControlName = 'navigation' | 'geolocate' | 'fullscreen' | 'scale'
|
|
127
129
|
const CONTROLS: Record<ControlName, { corner: MapControlPosition; create: (ml: MaplibreModule) => Maplibre.IControl }> = {
|
|
128
130
|
navigation: { corner: 'top-right', create: (ml) => new ml.NavigationControl() },
|
|
129
131
|
geolocate: {
|
|
@@ -132,7 +134,6 @@ const CONTROLS: Record<ControlName, { corner: MapControlPosition; create: (ml: M
|
|
|
132
134
|
},
|
|
133
135
|
fullscreen: { corner: 'top-right', create: (ml) => new ml.FullscreenControl({ container: root.value }) },
|
|
134
136
|
scale: { corner: 'bottom-left', create: (ml) => new ml.ScaleControl({ maxWidth: 100, unit: 'metric' }) },
|
|
135
|
-
attribution: { corner: 'bottom-right', create: (ml) => new ml.AttributionControl({ compact: true }) },
|
|
136
137
|
}
|
|
137
138
|
const added = new Map<ControlName, Maplibre.IControl>()
|
|
138
139
|
|
|
@@ -347,6 +348,8 @@ defineExpose({
|
|
|
347
348
|
>
|
|
348
349
|
<!-- Sized, not positioned: MapLibre's CSS makes it position: relative (.maplibregl-map), which would undo absolute -->
|
|
349
350
|
<div ref="container" class="h-full w-full" />
|
|
351
|
+
<!-- Before the slot: added to its corner first, so it stays at the corner's edge -->
|
|
352
|
+
<MMapAttribution v-if="map && attribution" :position="attribution === true ? 'bottom-right' : attribution" />
|
|
350
353
|
<slot v-if="map" />
|
|
351
354
|
<Transition
|
|
352
355
|
enter-active-class="transition-opacity duration-150"
|
|
@@ -384,6 +387,25 @@ defineExpose({
|
|
|
384
387
|
.m3-map .maplibregl-ctrl-group:not(:empty) {
|
|
385
388
|
box-shadow: var(--shadow-elevation-2);
|
|
386
389
|
}
|
|
390
|
+
/* MMapControl: switching group on or off, or expanding into its panel, fades the surface instead of snapping */
|
|
391
|
+
.m3-map .m3-map-control {
|
|
392
|
+
transition: background-color 200ms, box-shadow 200ms, border-radius 200ms;
|
|
393
|
+
}
|
|
394
|
+
.m3-map .m3-map-control-panel {
|
|
395
|
+
background: var(--color-surface-container-high);
|
|
396
|
+
color: var(--color-on-surface);
|
|
397
|
+
border-radius: 16px;
|
|
398
|
+
box-shadow: var(--shadow-elevation-2);
|
|
399
|
+
}
|
|
400
|
+
.m3-map .m3-map-control-panel-in {
|
|
401
|
+
animation: m3-map-control-in 200ms 60ms both;
|
|
402
|
+
}
|
|
403
|
+
@keyframes m3-map-control-in {
|
|
404
|
+
from { opacity: 0; }
|
|
405
|
+
}
|
|
406
|
+
@media (prefers-reduced-motion: reduce) {
|
|
407
|
+
.m3-map .m3-map-control-panel-in { animation: none; }
|
|
408
|
+
}
|
|
387
409
|
.m3-map .maplibregl-ctrl-group button {
|
|
388
410
|
width: 40px;
|
|
389
411
|
height: 40px;
|
|
@@ -392,20 +414,20 @@ defineExpose({
|
|
|
392
414
|
.m3-map .maplibregl-ctrl-group button + button {
|
|
393
415
|
border-top: 1px solid var(--color-outline-variant);
|
|
394
416
|
}
|
|
395
|
-
.m3-map .maplibregl-ctrl button:not(:disabled):hover {
|
|
417
|
+
.m3-map .maplibregl-ctrl:not(.m3-map-control-panel) button:not(:disabled):hover {
|
|
396
418
|
background-color: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
|
|
397
419
|
}
|
|
398
|
-
.m3-map .maplibregl-ctrl button:not(:disabled):active {
|
|
420
|
+
.m3-map .maplibregl-ctrl:not(.m3-map-control-panel) button:not(:disabled):active {
|
|
399
421
|
background-color: color-mix(in srgb, var(--color-on-surface) 12%, transparent);
|
|
400
422
|
}
|
|
401
423
|
.m3-map .maplibregl-ctrl-group button[aria-pressed='true'] {
|
|
402
424
|
background-color: var(--color-primary-container);
|
|
403
425
|
color: var(--color-on-primary-container);
|
|
404
426
|
}
|
|
405
|
-
.m3-map .maplibregl-ctrl button:focus-visible {
|
|
427
|
+
.m3-map .maplibregl-ctrl:not(.m3-map-control-panel) button:focus-visible {
|
|
406
428
|
box-shadow: inset 0 0 0 2px var(--color-secondary);
|
|
407
429
|
}
|
|
408
|
-
.m3-map .maplibregl-ctrl button:disabled {
|
|
430
|
+
.m3-map .maplibregl-ctrl:not(.m3-map-control-panel) button:disabled {
|
|
409
431
|
color: color-mix(in srgb, var(--color-on-surface) 38%, transparent);
|
|
410
432
|
}
|
|
411
433
|
.m3-map .maplibregl-ctrl button .maplibregl-ctrl-icon {
|
|
@@ -414,8 +436,7 @@ defineExpose({
|
|
|
414
436
|
justify-content: center;
|
|
415
437
|
background-image: none !important;
|
|
416
438
|
}
|
|
417
|
-
.m3-map .maplibregl-ctrl button .maplibregl-ctrl-icon::before
|
|
418
|
-
.m3-map .maplibregl-ctrl-attrib-button::before {
|
|
439
|
+
.m3-map .maplibregl-ctrl button .maplibregl-ctrl-icon::before {
|
|
419
440
|
font-family: 'Material Symbols Outlined';
|
|
420
441
|
font-size: 20px;
|
|
421
442
|
line-height: 1;
|
|
@@ -440,31 +461,56 @@ defineExpose({
|
|
|
440
461
|
.m3-map .maplibregl-ctrl-fullscreen .maplibregl-ctrl-icon::before { content: 'fullscreen'; }
|
|
441
462
|
.m3-map .maplibregl-ctrl-shrink .maplibregl-ctrl-icon::before { content: 'fullscreen_exit'; }
|
|
442
463
|
|
|
443
|
-
/*
|
|
444
|
-
|
|
445
|
-
|
|
464
|
+
/* Attribution (_MMapAttribution): a round icon button that opens into a pill with the credits. The surface is the
|
|
465
|
+
control itself, so MMapControl's size spring reveals the text; the row keeps its own width (max-content, capped at
|
|
466
|
+
the map's) so the text doesn't reflow while the control's size animates. */
|
|
467
|
+
.m3-map .m3-map-attrib {
|
|
468
|
+
border-radius: 16px;
|
|
469
|
+
background: var(--color-surface-container-high);
|
|
470
|
+
box-shadow: var(--shadow-elevation-2);
|
|
446
471
|
color: var(--color-on-surface-variant);
|
|
447
472
|
}
|
|
448
|
-
.m3-map .
|
|
449
|
-
color: inherit;
|
|
450
|
-
}
|
|
451
|
-
.m3-map .maplibregl-ctrl-attrib.maplibregl-compact {
|
|
452
|
-
min-height: 28px;
|
|
453
|
-
border-radius: 14px;
|
|
454
|
-
}
|
|
455
|
-
.m3-map .maplibregl-ctrl-attrib-button {
|
|
473
|
+
.m3-map .m3-map-attrib-row {
|
|
456
474
|
display: flex;
|
|
457
475
|
align-items: center;
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
476
|
+
width: max-content;
|
|
477
|
+
}
|
|
478
|
+
.m3-map .m3-map-attrib-button {
|
|
479
|
+
flex: none;
|
|
480
|
+
display: grid;
|
|
481
|
+
place-items: center;
|
|
482
|
+
width: 32px;
|
|
483
|
+
height: 32px;
|
|
484
|
+
border-radius: 16px;
|
|
463
485
|
color: var(--color-on-surface-variant);
|
|
486
|
+
cursor: pointer;
|
|
487
|
+
transition: background-color 150ms, color 150ms;
|
|
464
488
|
}
|
|
465
|
-
.m3-map .
|
|
466
|
-
|
|
467
|
-
|
|
489
|
+
.m3-map .m3-map-attrib-button:hover {
|
|
490
|
+
background-color: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
|
|
491
|
+
}
|
|
492
|
+
.m3-map .m3-map-attrib-button:focus-visible {
|
|
493
|
+
outline: none;
|
|
494
|
+
box-shadow: inset 0 0 0 2px var(--color-secondary);
|
|
495
|
+
}
|
|
496
|
+
.m3-map .m3-map-attrib-open .m3-map-attrib-button {
|
|
497
|
+
color: var(--color-primary);
|
|
498
|
+
}
|
|
499
|
+
.m3-map .m3-map-attrib-text {
|
|
500
|
+
min-width: 0;
|
|
501
|
+
padding-block: 8px;
|
|
502
|
+
font-size: 12px;
|
|
503
|
+
line-height: 16px;
|
|
504
|
+
letter-spacing: 0.4px;
|
|
505
|
+
animation: m3-map-control-in 200ms 60ms both;
|
|
506
|
+
}
|
|
507
|
+
.m3-map .m3-map-attrib-text a {
|
|
508
|
+
color: var(--color-on-surface);
|
|
509
|
+
text-decoration: none;
|
|
510
|
+
}
|
|
511
|
+
.m3-map .m3-map-attrib-text a:hover {
|
|
512
|
+
text-decoration: underline;
|
|
513
|
+
text-underline-offset: 2px;
|
|
468
514
|
}
|
|
469
515
|
.m3-map .maplibregl-ctrl-scale {
|
|
470
516
|
background: color-mix(in srgb, var(--color-surface-container-high) 85%, transparent);
|
|
@@ -2,14 +2,20 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Your own control in a corner of an `MMap`, stacked with MapLibre's (zoom, geolocate…) in that corner. With `group`
|
|
4
4
|
* (the default) it's a control group like the zoom buttons: put `<button>`s with a Material Symbols icon in it and
|
|
5
|
-
* they get the same M3 look. Without it, anything goes (an `MFab`, an `MSearchBar`, a card).
|
|
6
|
-
*
|
|
5
|
+
* they get the same M3 look. Without it, anything goes (an `MFab`, an `MSearchBar`, a card). With a `#panel` slot it
|
|
6
|
+
* expands in place: a button in it calls `toggle` and the control grows into a panel with your content (a layer
|
|
7
|
+
* picker, filters, a legend), and back. Its size springs whenever its content changes size, so the other controls in
|
|
8
|
+
* the corner move along instead of jumping. Available from the `/map` entry point.
|
|
7
9
|
*
|
|
8
|
-
* @slot default The control's content
|
|
10
|
+
* @slot default The control's content; `{ expanded, toggle }` when it has a `#panel`
|
|
11
|
+
* @slot panel What the control expands into (`v-model:expanded`); `{ close }`. Escape or a press outside it closes it
|
|
12
|
+
* @event update:expanded Emitted when the panel opens or closes — powers v-model:expanded
|
|
9
13
|
*/
|
|
10
|
-
import { onBeforeUnmount, ref, watch } from 'vue'
|
|
14
|
+
import { computed, onBeforeUnmount, onMounted, ref, useSlots, watch } from 'vue'
|
|
11
15
|
import type * as Maplibre from 'maplibre-gl'
|
|
12
16
|
import { useMap } from '../composables/useMap'
|
|
17
|
+
import { motionSprings } from '../composables/motion'
|
|
18
|
+
import { playSamples, prefersReducedMotion, sampleAt, sampleSpring } from '../composables/_springAnimation'
|
|
13
19
|
import type { MapControlPosition } from './MMap.vue'
|
|
14
20
|
|
|
15
21
|
// Attributes (class, style…) go on what's shown on the map, not on the hidden wrapper it's rendered in
|
|
@@ -21,13 +27,102 @@ const props = withDefaults(
|
|
|
21
27
|
position?: MapControlPosition
|
|
22
28
|
/** Draw it as a control group (a surface with dividers between buttons), like MapLibre's zoom buttons */
|
|
23
29
|
group?: boolean
|
|
30
|
+
/** Expanded into its `#panel` (v-model:expanded) */
|
|
31
|
+
expanded?: boolean
|
|
32
|
+
/** Springs the control's size when its content changes size (expanding, or anything else) */
|
|
33
|
+
animate?: boolean
|
|
24
34
|
}>(),
|
|
25
|
-
{ position: 'top-right', group: true },
|
|
35
|
+
{ position: 'top-right', group: true, expanded: false, animate: true },
|
|
26
36
|
)
|
|
27
37
|
|
|
38
|
+
const emit = defineEmits<{ 'update:expanded': [boolean] }>()
|
|
39
|
+
const slots = useSlots()
|
|
40
|
+
|
|
28
41
|
const el = ref<HTMLElement>()
|
|
29
42
|
const { onReady } = useMap()
|
|
30
43
|
|
|
44
|
+
// ── Expanding into the panel ────────────────────────────────────────────────────────────────────────────
|
|
45
|
+
const open = ref(props.expanded)
|
|
46
|
+
watch(() => props.expanded, (v) => { open.value = v })
|
|
47
|
+
const showPanel = computed(() => open.value && !!slots.panel)
|
|
48
|
+
function setOpen(v: boolean) {
|
|
49
|
+
if (v === open.value) return
|
|
50
|
+
open.value = v
|
|
51
|
+
emit('update:expanded', v)
|
|
52
|
+
}
|
|
53
|
+
const toggle = () => setOpen(!open.value)
|
|
54
|
+
const close = () => setOpen(false)
|
|
55
|
+
|
|
56
|
+
function onOutside(e: PointerEvent) {
|
|
57
|
+
if (showPanel.value && !el.value?.contains(e.target as Node)) close()
|
|
58
|
+
}
|
|
59
|
+
function onKeyDown(e: KeyboardEvent) {
|
|
60
|
+
if (e.key === 'Escape' && showPanel.value) {
|
|
61
|
+
close()
|
|
62
|
+
e.stopPropagation()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ── Size: a spring between the old and the new size whenever the content resizes (Standard DefaultSpatial).
|
|
67
|
+
// The new layout is already there when the ResizeObserver reports it, before it paints, so the animation starts
|
|
68
|
+
// from the old size without a flash; the content is clipped while it runs. Width/height can't run on the
|
|
69
|
+
// compositor, but a control is small. ──────────────────────────────────────────────────────────────────────
|
|
70
|
+
let size: { w: number; h: number } | null = null
|
|
71
|
+
let anim: Animation | null = null
|
|
72
|
+
let samples: number[] = []
|
|
73
|
+
let from = { w: 0, h: 0 }
|
|
74
|
+
let to = { w: 0, h: 0 }
|
|
75
|
+
let observer: ResizeObserver | null = null
|
|
76
|
+
|
|
77
|
+
function measure(): { w: number; h: number } {
|
|
78
|
+
return { w: el.value!.offsetWidth, h: el.value!.offsetHeight }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function onResize() {
|
|
82
|
+
const node = el.value
|
|
83
|
+
if (!node || anim) return
|
|
84
|
+
const next = measure()
|
|
85
|
+
if (size && (next.w !== size.w || next.h !== size.h) && props.animate && !prefersReducedMotion()) grow(node, size, next)
|
|
86
|
+
size = next
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function grow(node: HTMLElement, a: { w: number; h: number }, b: { w: number; h: number }) {
|
|
90
|
+
from = a
|
|
91
|
+
to = b
|
|
92
|
+
samples = sampleSpring(0, 1, 0, motionSprings.standard.defaultSpatial, 0.002)
|
|
93
|
+
node.style.overflow = 'hidden'
|
|
94
|
+
const lerp = (p: number) => ({ width: `${a.w + (b.w - a.w) * p}px`, height: `${a.h + (b.h - a.h) * p}px` })
|
|
95
|
+
anim = playSamples(node, samples, lerp)
|
|
96
|
+
if (!anim) return finish(node)
|
|
97
|
+
anim.onfinish = () => finish(node)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function finish(node: HTMLElement) {
|
|
101
|
+
anim?.cancel()
|
|
102
|
+
anim = null
|
|
103
|
+
node.style.overflow = ''
|
|
104
|
+
// The content may have changed size again while it ran
|
|
105
|
+
const now = measure()
|
|
106
|
+
if (now.w !== to.w || now.h !== to.h) {
|
|
107
|
+
size = to
|
|
108
|
+
onResize()
|
|
109
|
+
} else size = now
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// A size change while it runs (closed mid-opening) starts from where it is, not from the old size
|
|
113
|
+
function retarget() {
|
|
114
|
+
const node = el.value
|
|
115
|
+
if (!node || !anim) return
|
|
116
|
+
const p = sampleAt(samples, anim.currentTime)
|
|
117
|
+
const at = { w: from.w + (to.w - from.w) * p, h: from.h + (to.h - from.h) * p }
|
|
118
|
+
anim.onfinish = null
|
|
119
|
+
anim.cancel()
|
|
120
|
+
anim = null
|
|
121
|
+
size = at
|
|
122
|
+
onResize()
|
|
123
|
+
}
|
|
124
|
+
watch(showPanel, retarget, { flush: 'post' })
|
|
125
|
+
|
|
31
126
|
let map: Maplibre.Map | undefined
|
|
32
127
|
// MapLibre's IControl: the element it places in the corner
|
|
33
128
|
const control: Maplibre.IControl = {
|
|
@@ -46,7 +141,17 @@ watch(() => props.position, (position) => {
|
|
|
46
141
|
map.addControl(control, position)
|
|
47
142
|
})
|
|
48
143
|
|
|
144
|
+
onMounted(() => {
|
|
145
|
+
document.addEventListener('pointerdown', onOutside, true)
|
|
146
|
+
if (typeof ResizeObserver === 'undefined' || !el.value) return
|
|
147
|
+
observer = new ResizeObserver(onResize)
|
|
148
|
+
observer.observe(el.value)
|
|
149
|
+
})
|
|
150
|
+
|
|
49
151
|
onBeforeUnmount(() => {
|
|
152
|
+
document.removeEventListener('pointerdown', onOutside, true)
|
|
153
|
+
observer?.disconnect()
|
|
154
|
+
anim?.cancel()
|
|
50
155
|
if (map?.hasControl(control)) map.removeControl(control)
|
|
51
156
|
})
|
|
52
157
|
</script>
|
|
@@ -54,8 +159,17 @@ onBeforeUnmount(() => {
|
|
|
54
159
|
<template>
|
|
55
160
|
<!-- Moved into the map's corner by MapLibre -->
|
|
56
161
|
<div class="hidden">
|
|
57
|
-
<div
|
|
58
|
-
|
|
162
|
+
<div
|
|
163
|
+
ref="el"
|
|
164
|
+
class="maplibregl-ctrl m3-map-control"
|
|
165
|
+
:class="showPanel ? 'm3-map-control-panel' : group ? 'maplibregl-ctrl-group' : ''"
|
|
166
|
+
v-bind="$attrs"
|
|
167
|
+
@keydown="onKeyDown"
|
|
168
|
+
>
|
|
169
|
+
<div v-if="showPanel" class="m3-map-control-panel-in">
|
|
170
|
+
<slot name="panel" :close="close" />
|
|
171
|
+
</div>
|
|
172
|
+
<slot v-else :expanded="open" :toggle="toggle" />
|
|
59
173
|
</div>
|
|
60
174
|
</div>
|
|
61
175
|
</template>
|
|
@@ -16,6 +16,7 @@ import MMapFeatureInfo from './MMapFeatureInfo.vue'
|
|
|
16
16
|
import { useMap } from '../composables/useMap'
|
|
17
17
|
import { useMapLayers } from '../composables/useMapLayers'
|
|
18
18
|
import { identifyFeatures, type MapIdentifyResult } from '../composables/mapAdapters'
|
|
19
|
+
import { PIN_POPUP_OFFSET } from '../composables/_mapPin'
|
|
19
20
|
|
|
20
21
|
// Attributes (class, style…) go on the popup's content
|
|
21
22
|
defineOptions({ inheritAttrs: false })
|
|
@@ -92,7 +93,7 @@ defineExpose({ close })
|
|
|
92
93
|
<!-- One root (the marker and the popup move their content into the map) -->
|
|
93
94
|
<div class="hidden">
|
|
94
95
|
<MMapMarker v-if="marker && open" :lng-lat="lngLat" />
|
|
95
|
-
<MMapPopup v-if="popup && results.length" v-model:open="open" :lng-lat="lngLat" max-width="360px" :offset="marker ?
|
|
96
|
+
<MMapPopup v-if="popup && results.length" v-model:open="open" :lng-lat="lngLat" max-width="360px" :offset="marker ? PIN_POPUP_OFFSET : undefined">
|
|
96
97
|
<div class="max-h-80 overflow-y-auto" v-bind="$attrs">
|
|
97
98
|
<slot :results="results" :lng-lat="lngLat" :close="close">
|
|
98
99
|
<MMapFeatureInfo :results="results" />
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { onBeforeUnmount, ref, useSlots, watch } from 'vue'
|
|
13
13
|
import type * as Maplibre from 'maplibre-gl'
|
|
14
14
|
import { useMap } from '../composables/useMap'
|
|
15
|
+
import { PIN_OFFSET } from '../composables/_mapPin'
|
|
15
16
|
|
|
16
17
|
// Attributes (class, style…) go on what's shown on the map, not on the hidden wrapper it's rendered in
|
|
17
18
|
defineOptions({ inheritAttrs: false })
|
|
@@ -24,9 +25,12 @@ const props = withDefaults(
|
|
|
24
25
|
color?: string
|
|
25
26
|
/** Let the user drag it */
|
|
26
27
|
draggable?: boolean
|
|
27
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Which part of the marker sits on `lngLat`. By default the pin's tip (MapLibre's placement: its center, offset
|
|
30
|
+
* `[0, -14]`), and the center of custom content
|
|
31
|
+
*/
|
|
28
32
|
anchor?: Maplibre.PositionAnchor
|
|
29
|
-
/** Offset in pixels, `[x, y]` */
|
|
33
|
+
/** Offset in pixels, `[x, y]`. The pin's default is MapLibre's `[0, -14]`, which puts its tip on `lngLat` */
|
|
30
34
|
offset?: [number, number]
|
|
31
35
|
/** Rotation in degrees */
|
|
32
36
|
rotation?: number
|
|
@@ -45,14 +49,16 @@ const popupContent = ref<HTMLElement>()
|
|
|
45
49
|
const { onReady } = useMap()
|
|
46
50
|
|
|
47
51
|
let marker: Maplibre.Marker | undefined
|
|
52
|
+
let custom = false
|
|
48
53
|
|
|
49
54
|
onReady((map, ml) => {
|
|
50
|
-
|
|
55
|
+
custom = !!slots.default && !!content.value
|
|
51
56
|
marker = new ml.Marker({
|
|
52
57
|
...(custom ? { element: content.value } : { color: props.color ?? 'currentColor' }),
|
|
53
58
|
draggable: props.draggable,
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
// Left out for the pin unless given: MapLibre's own placement puts its tip on the point (see _mapPin.ts)
|
|
60
|
+
...(props.anchor ? { anchor: props.anchor } : custom ? { anchor: 'center' as const } : {}),
|
|
61
|
+
...(props.offset ? { offset: props.offset } : {}),
|
|
56
62
|
rotation: props.rotation,
|
|
57
63
|
})
|
|
58
64
|
if (!custom && !props.color) marker.getElement().classList.add('m3-map-marker--default')
|
|
@@ -63,7 +69,8 @@ onReady((map, ml) => {
|
|
|
63
69
|
emit('update:lngLat', [lng, lat])
|
|
64
70
|
})
|
|
65
71
|
if (slots.popup && popupContent.value) {
|
|
66
|
-
|
|
72
|
+
// The pin's popup gets MapLibre's per-side offsets, which it only applies when `offset` isn't set at all
|
|
73
|
+
marker.setPopup(new ml.Popup({ ...(custom ? { offset: 16 } : {}), maxWidth: '320px' }).setDOMContent(popupContent.value))
|
|
67
74
|
}
|
|
68
75
|
})
|
|
69
76
|
|
|
@@ -75,7 +82,7 @@ function onClick(e: MouseEvent) {
|
|
|
75
82
|
watch(() => props.lngLat.join(','), () => marker?.setLngLat(props.lngLat))
|
|
76
83
|
watch(() => props.draggable, (draggable) => marker?.setDraggable(draggable))
|
|
77
84
|
watch(() => props.rotation, (rotation) => marker?.setRotation(rotation))
|
|
78
|
-
watch(() => props.offset?.join(','), () => marker?.setOffset(props.offset ?? [0, 0]))
|
|
85
|
+
watch(() => props.offset?.join(','), () => marker?.setOffset(props.offset ?? (custom ? [0, 0] : PIN_OFFSET)))
|
|
79
86
|
|
|
80
87
|
onBeforeUnmount(() => {
|
|
81
88
|
marker?.getElement().removeEventListener('click', onClick)
|
|
@@ -26,12 +26,15 @@ const props = withDefaults(
|
|
|
26
26
|
closeOnClick?: boolean
|
|
27
27
|
/** Where the popup sits relative to `lngLat`. By default MapLibre picks the side with room */
|
|
28
28
|
anchor?: Maplibre.PositionAnchor
|
|
29
|
-
/**
|
|
30
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Offset from `lngLat`: pixels, `[x, y]`, or one per side (`{ bottom: [0, -38], … }`, MapLibre's `Offset`).
|
|
31
|
+
* By default none: its tip touches the point
|
|
32
|
+
*/
|
|
33
|
+
offset?: Maplibre.Offset
|
|
31
34
|
/** Maximum width (CSS) */
|
|
32
35
|
maxWidth?: string
|
|
33
36
|
}>(),
|
|
34
|
-
{ open: true, closeButton: true, closeOnClick: true,
|
|
37
|
+
{ open: true, closeButton: true, closeOnClick: true, maxWidth: '320px' },
|
|
35
38
|
)
|
|
36
39
|
|
|
37
40
|
const emit = defineEmits<{ 'update:open': [open: boolean] }>()
|
|
@@ -56,7 +59,7 @@ onReady((m, ml) => {
|
|
|
56
59
|
closeOnClick: props.closeOnClick,
|
|
57
60
|
closeOnMove: false,
|
|
58
61
|
anchor: props.anchor,
|
|
59
|
-
offset: props.offset,
|
|
62
|
+
...(props.offset !== undefined ? { offset: props.offset } : {}),
|
|
60
63
|
maxWidth: props.maxWidth,
|
|
61
64
|
focusAfterOpen: false,
|
|
62
65
|
})
|
|
@@ -77,6 +80,7 @@ watch(() => props.open, (open) => {
|
|
|
77
80
|
})
|
|
78
81
|
watch(() => props.lngLat.join(','), () => popup?.setLngLat(props.lngLat))
|
|
79
82
|
watch(() => props.maxWidth, (w) => popup?.setMaxWidth(w))
|
|
83
|
+
watch(() => props.offset, (offset) => popup?.setOffset(offset ?? 0))
|
|
80
84
|
|
|
81
85
|
onBeforeUnmount(() => {
|
|
82
86
|
closingFromProp = true
|
package/src/components/MMenu.vue
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { computed, Fragment, inject, nextTick, onMounted, onUnmounted, provide, ref, useSlots, watch, type VNode } from 'vue'
|
|
10
10
|
import MIcon from './MIcon.vue'
|
|
11
11
|
import MMenuDivider from './MMenuDivider.vue'
|
|
12
|
+
import { POPUP_MARGIN, dropdownX } from '../composables/_popupPosition'
|
|
12
13
|
|
|
13
14
|
defineOptions({ inheritAttrs: false })
|
|
14
15
|
|
|
@@ -221,6 +222,7 @@ function playTrajectory(el: Element, done: () => void, opening: boolean) {
|
|
|
221
222
|
finishLeave = opening ? null : () => { cancelActive?.(); cancelActive = null; finishLeave = null; done() }
|
|
222
223
|
}
|
|
223
224
|
function panelEnter(el: Element, done: () => void) {
|
|
225
|
+
placeX(el as HTMLElement)
|
|
224
226
|
playTrajectory(el, done, true)
|
|
225
227
|
}
|
|
226
228
|
function panelLeave(el: Element, done: () => void) {
|
|
@@ -275,31 +277,50 @@ onUnmounted(() => {
|
|
|
275
277
|
const siblingGroup = inject<{ current: (() => void) | null } | null>('m-menu-sibling-group', null)
|
|
276
278
|
provide('m-menu-sibling-group', { current: null })
|
|
277
279
|
|
|
280
|
+
// The vertical side and height from the trigger alone; the horizontal position needs the panel's width, so
|
|
281
|
+
// placeX() sets it once the panel is in the DOM (in its enter hook, before it paints). Until then it sits at the
|
|
282
|
+
// window's left edge, where nothing narrows it while it's measured.
|
|
283
|
+
let anchorRect: DOMRect | null = null
|
|
284
|
+
const openAbove = ref(false)
|
|
278
285
|
function computePos() {
|
|
279
286
|
if (!triggerEl.value) return
|
|
280
287
|
const rect = triggerEl.value.getBoundingClientRect()
|
|
288
|
+
anchorRect = rect
|
|
281
289
|
const spaceBelow = window.innerHeight - rect.bottom - 8
|
|
282
|
-
|
|
290
|
+
openAbove.value = spaceBelow < 200 && rect.top > spaceBelow
|
|
283
291
|
|
|
284
292
|
const style: Record<string, string> = {
|
|
285
|
-
maxHeight: `${Math.min(openAbove ? rect.top - 12 : spaceBelow, 400)}px`,
|
|
293
|
+
maxHeight: `${Math.min(openAbove.value ? rect.top - 12 : spaceBelow, 400)}px`,
|
|
294
|
+
maxWidth: `${window.innerWidth - 2 * POPUP_MARGIN}px`,
|
|
295
|
+
left: '0px',
|
|
286
296
|
}
|
|
287
297
|
|
|
288
|
-
if (openAbove) {
|
|
298
|
+
if (openAbove.value) {
|
|
289
299
|
style.bottom = `${window.innerHeight - rect.top + 4}px`
|
|
290
300
|
} else {
|
|
291
301
|
style.top = `${rect.bottom + 4}px`
|
|
292
302
|
}
|
|
293
303
|
|
|
294
|
-
if (props.align === 'right') {
|
|
295
|
-
style.right = `${window.innerWidth - rect.right}px`
|
|
296
|
-
} else {
|
|
297
|
-
style.left = `${rect.left}px`
|
|
298
|
-
}
|
|
299
|
-
|
|
300
304
|
dropStyle.value = style
|
|
301
305
|
}
|
|
302
306
|
|
|
307
|
+
// Keeps the panel on screen (Compose's DropdownMenuPositionProvider, see _popupPosition.ts): aligned with the
|
|
308
|
+
// trigger's `align` edge if it fits there, else its other edge, else against the window edge on its side. The
|
|
309
|
+
// animation grows from the trigger, wherever the panel ended up.
|
|
310
|
+
const originX = ref(props.align === 'right' ? 'right' : 'left')
|
|
311
|
+
function placeX(el: HTMLElement) {
|
|
312
|
+
if (!anchorRect) return
|
|
313
|
+
const width = el.offsetWidth
|
|
314
|
+
const x = dropdownX(anchorRect, width, window.innerWidth, props.align === 'right' ? 'end' : 'start')
|
|
315
|
+
const pivot = Math.min(width, Math.max(0, (anchorRect.left + anchorRect.right) / 2 - x))
|
|
316
|
+
const fromEdge = Math.abs(x - anchorRect.left) < 1 ? 'left' : Math.abs(x + width - anchorRect.right) < 1 ? 'right' : `${pivot}px`
|
|
317
|
+
originX.value = fromEdge
|
|
318
|
+
dropStyle.value = { ...dropStyle.value, left: `${x}px` }
|
|
319
|
+
// Now, not on the next render: the enter animation starts this frame
|
|
320
|
+
el.style.left = `${x}px`
|
|
321
|
+
el.style.transformOrigin = `${fromEdge} ${openAbove.value ? 'bottom' : 'top'}`
|
|
322
|
+
}
|
|
323
|
+
|
|
303
324
|
function focusableItems() {
|
|
304
325
|
if (!dropdownEl.value) return []
|
|
305
326
|
return Array.from(
|
|
@@ -392,9 +413,7 @@ onUnmounted(() => {
|
|
|
392
413
|
else cancelActive?.()
|
|
393
414
|
})
|
|
394
415
|
|
|
395
|
-
const origin = computed(() =>
|
|
396
|
-
props.align === 'right' ? 'top right' : 'top left',
|
|
397
|
-
)
|
|
416
|
+
const origin = computed(() => `${originX.value} ${openAbove.value ? 'bottom' : 'top'}`)
|
|
398
417
|
</script>
|
|
399
418
|
|
|
400
419
|
<template>
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { computed, inject, nextTick, onMounted, onUnmounted, ref, useSlots, watch } from 'vue'
|
|
17
17
|
import MIcon from './MIcon.vue'
|
|
18
18
|
import { FAST_EFFECTS, FAST_SPATIAL, useSpring } from '../composables/_useSpring'
|
|
19
|
+
import { POPUP_MARGIN, fitPopup } from '../composables/_popupPosition'
|
|
19
20
|
|
|
20
21
|
const props = withDefaults(defineProps<{
|
|
21
22
|
/** Material Symbol icon name */
|
|
@@ -123,20 +124,35 @@ const iconSlotEl = ref<HTMLElement>()
|
|
|
123
124
|
const showSub = ref(false)
|
|
124
125
|
const subStyle = ref<Record<string, string>>({})
|
|
125
126
|
|
|
127
|
+
// To the item's right, else its left, else clamped on screen (see _popupPosition.ts); placeSub() settles it once
|
|
128
|
+
// the submenu is in the DOM and its size is known, before it paints
|
|
126
129
|
function positionSub() {
|
|
127
130
|
if (!itemEl.value) return
|
|
128
131
|
const rect = itemEl.value.getBoundingClientRect()
|
|
129
|
-
const right = rect.right + 200 > window.innerWidth
|
|
130
132
|
subStyle.value = {
|
|
131
133
|
position: 'fixed',
|
|
132
134
|
top: `${rect.top}px`,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
: { left: `${rect.right}px` }),
|
|
135
|
+
left: `${rect.right}px`,
|
|
136
|
+
maxWidth: `${window.innerWidth - 2 * POPUP_MARGIN}px`,
|
|
136
137
|
zIndex: '501',
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
|
|
141
|
+
function placeSub(el: Element) {
|
|
142
|
+
if (!itemEl.value) return
|
|
143
|
+
const sub = el as HTMLElement
|
|
144
|
+
const rect = itemEl.value.getBoundingClientRect()
|
|
145
|
+
// Measured at the window's left edge, where nothing narrows it
|
|
146
|
+
sub.style.left = '0px'
|
|
147
|
+
const w = sub.offsetWidth
|
|
148
|
+
const h = sub.offsetHeight
|
|
149
|
+
const left = fitPopup([rect.right, rect.left - w], w, window.innerWidth)
|
|
150
|
+
const top = fitPopup([rect.top, rect.bottom - h], h, window.innerHeight)
|
|
151
|
+
subStyle.value = { ...subStyle.value, left: `${left}px`, top: `${top}px` }
|
|
152
|
+
sub.style.left = `${left}px`
|
|
153
|
+
sub.style.top = `${top}px`
|
|
154
|
+
}
|
|
155
|
+
|
|
140
156
|
function toggleSub() {
|
|
141
157
|
if (showSub.value) {
|
|
142
158
|
showSub.value = false
|
|
@@ -246,6 +262,7 @@ function onSubPointerLeave(e: PointerEvent) {
|
|
|
246
262
|
enter-from-class="opacity-0"
|
|
247
263
|
leave-active-class="transition-opacity duration-75"
|
|
248
264
|
leave-to-class="opacity-0"
|
|
265
|
+
@enter="placeSub"
|
|
249
266
|
>
|
|
250
267
|
<div
|
|
251
268
|
v-if="showSub"
|
|
@@ -13,6 +13,7 @@ import { useFieldBg } from '../composables/useFieldBg'
|
|
|
13
13
|
import { useLocale } from '../composables/useLocale'
|
|
14
14
|
import { useDebounce } from '../composables/useDebounce'
|
|
15
15
|
import type { MultiSelectOption } from './MMultiSelect.vue'
|
|
16
|
+
import { useScrollLock } from '../composables/_useScrollLock'
|
|
16
17
|
|
|
17
18
|
// Root is a fragment (field div + a sibling Teleport for the dropdown panel), so Vue can't
|
|
18
19
|
// auto-apply a consumer's class/attrs to either one — forward them onto the field div below.
|
|
@@ -215,9 +216,7 @@ function closeDropdown() {
|
|
|
215
216
|
highlightIndex.value = -1
|
|
216
217
|
}
|
|
217
218
|
|
|
218
|
-
|
|
219
|
-
document.body.style.overflow = v ? 'hidden' : ''
|
|
220
|
-
})
|
|
219
|
+
useScrollLock(modalOpen)
|
|
221
220
|
|
|
222
221
|
function onInputFocus() {
|
|
223
222
|
openDropdown()
|
|
@@ -311,7 +310,6 @@ onMounted(() => {
|
|
|
311
310
|
onUnmounted(() => {
|
|
312
311
|
document.removeEventListener('mousedown', onOutsideClick)
|
|
313
312
|
window.removeEventListener('scroll', onScroll, true)
|
|
314
|
-
document.body.style.overflow = ''
|
|
315
313
|
})
|
|
316
314
|
|
|
317
315
|
watch(filteredOptions, () => {
|
|
@@ -11,6 +11,7 @@ import MIconButton from './MIconButton.vue'
|
|
|
11
11
|
import MCheckbox from './MCheckbox.vue'
|
|
12
12
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
13
13
|
import { useLocale } from '../composables/useLocale'
|
|
14
|
+
import { useScrollLock } from '../composables/_useScrollLock'
|
|
14
15
|
|
|
15
16
|
const locale = useLocale()
|
|
16
17
|
|
|
@@ -195,9 +196,7 @@ const modalFilteredOptions = computed(() => {
|
|
|
195
196
|
return opts.filter((o) => o.label.toLowerCase().includes(q))
|
|
196
197
|
})
|
|
197
198
|
|
|
198
|
-
|
|
199
|
-
document.body.style.overflow = v ? 'hidden' : ''
|
|
200
|
-
})
|
|
199
|
+
useScrollLock(modalOpen)
|
|
201
200
|
|
|
202
201
|
function onOutsideClick(e: MouseEvent) {
|
|
203
202
|
if (modalOpen.value) return
|
|
@@ -218,7 +217,6 @@ onMounted(() => {
|
|
|
218
217
|
onUnmounted(() => {
|
|
219
218
|
document.removeEventListener('mousedown', onOutsideClick)
|
|
220
219
|
window.removeEventListener('scroll', onScroll, true)
|
|
221
|
-
document.body.style.overflow = ''
|
|
222
220
|
})
|
|
223
221
|
|
|
224
222
|
const triggerClasses = computed(() => {
|