@m3ui-vue/m3ui-vue 1.6.0 → 1.6.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 +940 -33
- package/dist/{MButton-CPghlKb0.js → MButton-OQ4wIERQ.js} +2 -2
- package/dist/{MButton-CPghlKb0.js.map → MButton-OQ4wIERQ.js.map} +1 -1
- package/dist/{MDialog-X50At1Gk.js → MDialog-DYMnaBlt.js} +3 -3
- package/dist/{MDialog-X50At1Gk.js.map → MDialog-DYMnaBlt.js.map} +1 -1
- package/dist/{MListItem-DVi1j1QI.js → MListItem-D2cNUyzP.js} +211 -168
- package/dist/MListItem-D2cNUyzP.js.map +1 -0
- package/dist/{MLoadingIndicator-vooA3110.js → MLoadingIndicator-DWUj0BAB.js} +2 -2
- package/dist/{MLoadingIndicator-vooA3110.js.map → MLoadingIndicator-DWUj0BAB.js.map} +1 -1
- package/dist/{MMenuItem-CRNZkVVr.js → MMenuItem-BuxYoASE.js} +133 -151
- package/dist/MMenuItem-BuxYoASE.js.map +1 -0
- package/dist/{MSeekBar-BL2W5_rD.js → MSeekBar-C4cn9RIF.js} +2 -2
- package/dist/{MSeekBar-BL2W5_rD.js.map → MSeekBar-C4cn9RIF.js.map} +1 -1
- package/dist/{MSlider-B9NcKTmZ.js → MSlider-BIkA6DiE.js} +2 -2
- package/dist/{MSlider-B9NcKTmZ.js.map → MSlider-BIkA6DiE.js.map} +1 -1
- package/dist/{MSpinner-_XpTRkAg.js → MSpinner-DZkXZJpc.js} +2 -2
- package/dist/{MSpinner-_XpTRkAg.js.map → MSpinner-DZkXZJpc.js.map} +1 -1
- package/dist/{MTextField-DpcPmR5B.js → MTextField-CNH-byir.js} +2 -2
- package/dist/{MTextField-DpcPmR5B.js.map → MTextField-CNH-byir.js.map} +1 -1
- package/dist/{MTooltip-BL3jPYPT.js → MTooltip-Dd5g2zhh.js} +4 -4
- package/dist/{MTooltip-BL3jPYPT.js.map → MTooltip-Dd5g2zhh.js.map} +1 -1
- package/dist/{_useEscapeStack-C5-BYr8y.js → _popupPosition-nL8SVKPK.js} +20 -2
- package/dist/_popupPosition-nL8SVKPK.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAddressField.vue.d.ts +54 -0
- package/dist/components/MAudioPlayer.vue.d.ts +1 -1
- package/dist/components/MAudioRecorder.vue.d.ts +51 -0
- package/dist/components/MAvailabilityCalendar.vue.d.ts +1 -1
- package/dist/components/MCameraCapture.vue.d.ts +51 -0
- package/dist/components/MCollapse.vue.d.ts +32 -0
- package/dist/components/MCountrySelect.vue.d.ts +41 -0
- package/dist/components/MCronField.vue.d.ts +26 -0
- package/dist/components/MDashboardGrid.vue.d.ts +65 -0
- package/dist/components/MDiffViewer.vue.d.ts +56 -0
- package/dist/components/MExpansionPanel.vue.d.ts +26 -3
- package/dist/components/MFilterBuilder.vue.d.ts +22 -0
- package/dist/components/MFlex.vue.d.ts +1 -1
- package/dist/components/MMapCluster.vue.d.ts +80 -0
- package/dist/components/MMapDraw.vue.d.ts +79 -0
- package/dist/components/MMentionField.vue.d.ts +102 -0
- package/dist/components/MNotificationCenter.vue.d.ts +57 -0
- package/dist/components/MQRScanner.vue.d.ts +52 -0
- package/dist/components/MQuiz.vue.d.ts +1 -1
- package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +1 -1
- package/dist/components/MTimezoneSelect.vue.d.ts +39 -0
- package/dist/components/MToolbar.vue.d.ts +1 -1
- package/dist/components/MVideoPlayer.vue.d.ts +1 -1
- package/dist/components/_MFilterGroup.vue.d.ts +17 -0
- package/dist/composables/_caretPosition.d.ts +6 -0
- package/dist/composables/_useCamera.d.ts +16 -0
- package/dist/composables/_useFollowAnchor.d.ts +15 -0
- package/dist/composables/cron.d.ts +29 -0
- package/dist/composables/dashboardLayout.d.ts +28 -0
- package/dist/composables/filterBuilder.d.ts +55 -0
- package/dist/composables/mapAdapters.d.ts +6 -1
- package/dist/composables/mapSearch.d.ts +1 -0
- package/dist/composables/textDiff.d.ts +24 -0
- package/dist/composables/useLocale.d.ts +108 -0
- package/dist/draw.js +3 -3
- package/dist/flow.js +1 -1
- package/dist/gantt.js +1 -1
- package/dist/index.d.ts +25 -0
- package/dist/locales/index.js +749 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +9888 -6940
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +5 -0
- package/dist/map.js +1462 -576
- package/dist/map.js.map +1 -1
- package/dist/media.js +5 -5
- package/dist/pdf.js +5 -5
- package/dist/rich-text-editor.js +5 -5
- package/dist/styles.css +1 -1
- package/dist/{useLocale-COav9m8C.js → useLocale-DaVSTdm0.js} +108 -1
- package/dist/useLocale-DaVSTdm0.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MAddressField.test.ts +149 -0
- package/src/__tests__/MAudioRecorder.test.ts +125 -0
- package/src/__tests__/MCameraCapture.test.ts +154 -0
- package/src/__tests__/MCountrySelect.test.ts +67 -0
- package/src/__tests__/MCronField.test.ts +100 -0
- package/src/__tests__/MDashboardGrid.test.ts +122 -0
- package/src/__tests__/MDiffViewer.test.ts +68 -0
- package/src/__tests__/MExpansionPanel.test.ts +107 -0
- package/src/__tests__/MFilterBuilder.test.ts +130 -0
- package/src/__tests__/MMapCluster.test.ts +127 -0
- package/src/__tests__/MMapDraw.test.ts +188 -0
- package/src/__tests__/MMapLayers.test.ts +56 -0
- package/src/__tests__/MMentionField.test.ts +163 -0
- package/src/__tests__/MNotificationCenter.test.ts +94 -0
- package/src/__tests__/_fakeMaplibre.ts +14 -3
- package/src/__tests__/attrsFallthrough.test.ts +4 -0
- package/src/__tests__/cron.test.ts +68 -0
- package/src/__tests__/dashboardLayout.test.ts +45 -0
- package/src/__tests__/filterBuilder.test.ts +91 -0
- package/src/__tests__/followAnchor.test.ts +162 -0
- package/src/__tests__/ssr.test.ts +3 -0
- package/src/__tests__/textDiff.test.ts +37 -0
- package/src/components/MAddressField.vue +301 -0
- package/src/components/MAudioRecorder.vue +334 -0
- package/src/components/MAutocomplete.vue +3 -7
- package/src/components/MCameraCapture.vue +156 -0
- package/src/components/MCollapse.vue +91 -0
- package/src/components/MColorPicker.vue +4 -8
- package/src/components/MCountrySelect.vue +89 -0
- package/src/components/MCronField.vue +251 -0
- package/src/components/MDashboardGrid.vue +382 -0
- package/src/components/MDatePicker.vue +10 -7
- package/src/components/MDateRangePicker.vue +10 -7
- package/src/components/MDiffViewer.vue +234 -0
- package/src/components/MExpansionPanel.vue +56 -48
- package/src/components/MFilterBuilder.vue +47 -0
- package/src/components/MMapCluster.vue +295 -0
- package/src/components/MMapDraw.vue +601 -0
- package/src/components/MMapSearch.vue +1 -9
- package/src/components/MMentionField.vue +373 -0
- package/src/components/MMultiAutocomplete.vue +3 -7
- package/src/components/MMultiSelect.vue +3 -7
- package/src/components/MNotificationCenter.vue +252 -0
- package/src/components/MPhoneInput.vue +3 -10
- package/src/components/MQRScanner.vue +177 -0
- package/src/components/MSelect.vue +3 -7
- package/src/components/MTimePicker.vue +10 -7
- package/src/components/MTimezoneSelect.vue +116 -0
- package/src/components/_MFilterGroup.vue +210 -0
- package/src/composables/_caretPosition.ts +44 -0
- package/src/composables/_useCamera.ts +66 -0
- package/src/composables/_useFollowAnchor.ts +109 -0
- package/src/composables/cron.ts +179 -0
- package/src/composables/dashboardLayout.ts +94 -0
- package/src/composables/filterBuilder.ts +195 -0
- package/src/composables/mapAdapters.ts +29 -15
- package/src/composables/mapSearch.ts +10 -0
- package/src/composables/textDiff.ts +106 -0
- package/src/composables/useLocale.ts +215 -0
- package/src/index.ts +25 -0
- package/src/locales/de.ts +107 -0
- package/src/locales/es.ts +107 -0
- package/src/locales/fr.ts +107 -0
- package/src/locales/ja.ts +107 -0
- package/src/locales/ko.ts +107 -0
- package/src/locales/pt.ts +107 -0
- package/src/locales/zh.ts +107 -0
- package/src/map.ts +5 -0
- package/dist/MListItem-DVi1j1QI.js.map +0 -1
- package/dist/MMenuItem-CRNZkVVr.js.map +0 -1
- package/dist/_useEscapeStack-C5-BYr8y.js.map +0 -1
- package/dist/useLocale-COav9m8C.js.map +0 -1
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Clustered points on an `MMap`: GeoJSON points (an object, or a URL) grouped by MapLibre's clustering into M3 count
|
|
4
|
+
* bubbles that grow with their count; a click or Enter on one zooms in until it splits. The points left on their own
|
|
5
|
+
* are drawn as circles in the same color (or with `pointLayers`). The bubbles are HTML (buttons you can tab to, the
|
|
6
|
+
* theme's type scale, no glyphs needed in the style); `#cluster` replaces their content. Replace `data` (a new object)
|
|
7
|
+
* to update it. It's added again after a style change. Available from the `/map` entry point.
|
|
8
|
+
*
|
|
9
|
+
* @slot cluster A bubble's content instead of the default one: `{ id, count, label, lngLat, zoomIn, leaves }`
|
|
10
|
+
* @event click A click on one of its single points (MapLibre's `MapLayerMouseEvent`: `e.features` holds them)
|
|
11
|
+
* @event cluster-click A click on a bubble: `{ id, count, lngLat, zoomIn, leaves }` (it zooms in by itself unless `zoomOnClick` is false)
|
|
12
|
+
*/
|
|
13
|
+
import { computed, onBeforeUnmount, shallowRef, useId, watch } from 'vue'
|
|
14
|
+
import type * as Maplibre from 'maplibre-gl'
|
|
15
|
+
import { useMap } from '../composables/useMap'
|
|
16
|
+
import { useLocale } from '../composables/useLocale'
|
|
17
|
+
import { useThemeTokens } from '../composables/useThemeTokens'
|
|
18
|
+
import type { MapGeoJsonLayer } from './MMapGeoJson.vue'
|
|
19
|
+
|
|
20
|
+
/** One of the points in a cluster (a GeoJSON feature). */
|
|
21
|
+
export type MapClusterLeaf = Awaited<ReturnType<Maplibre.GeoJSONSource['getClusterLeaves']>>[number]
|
|
22
|
+
|
|
23
|
+
/** A bubble, as `#cluster` and `cluster-click` get it. */
|
|
24
|
+
export interface MapCluster {
|
|
25
|
+
/** MapLibre's cluster id */
|
|
26
|
+
id: number
|
|
27
|
+
/** How many points it holds */
|
|
28
|
+
count: number
|
|
29
|
+
/** Where it sits, `[lng, lat]` */
|
|
30
|
+
lngLat: [number, number]
|
|
31
|
+
/** Zooms in until it splits */
|
|
32
|
+
zoomIn: () => Promise<void>
|
|
33
|
+
/** Its points (all of them by default, or the first `limit`) */
|
|
34
|
+
leaves: (limit?: number) => Promise<MapClusterLeaf[]>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// It renders nothing in place: no element for attributes to land on
|
|
38
|
+
defineOptions({ inheritAttrs: false })
|
|
39
|
+
|
|
40
|
+
const props = withDefaults(
|
|
41
|
+
defineProps<{
|
|
42
|
+
/** A GeoJSON object (a FeatureCollection of points), or the URL of one */
|
|
43
|
+
data: Maplibre.GeoJSONSourceSpecification['data']
|
|
44
|
+
/** The source's id (and the prefix of its layers' ids). Unique on the map; generated when left out */
|
|
45
|
+
id?: string
|
|
46
|
+
/** The theme color of the bubbles and the single points */
|
|
47
|
+
color?: 'primary' | 'secondary' | 'tertiary'
|
|
48
|
+
/** How close points must be to be grouped, in pixels (MapLibre's `clusterRadius`) */
|
|
49
|
+
radius?: number
|
|
50
|
+
/** Above this zoom nothing is grouped (MapLibre's `clusterMaxZoom`) */
|
|
51
|
+
maxZoom?: number
|
|
52
|
+
/** Zoom in on a bubble when it's clicked */
|
|
53
|
+
zoomOnClick?: boolean
|
|
54
|
+
/** How to draw the single points: MapLibre layers without `source` (filter out clusters yourself: `['!', ['has', 'point_count']]`). Defaults to a circle */
|
|
55
|
+
pointLayers?: MapGeoJsonLayer[]
|
|
56
|
+
/** Insert the point layers below this layer id */
|
|
57
|
+
before?: string
|
|
58
|
+
/** Show a pointer over the single points (set it when you handle `click`) */
|
|
59
|
+
interactive?: boolean
|
|
60
|
+
/** More options for the GeoJSON source (`clusterProperties`, `clusterMinPoints`, `promoteId`…) */
|
|
61
|
+
sourceOptions?: Partial<Omit<Maplibre.GeoJSONSourceSpecification, 'type' | 'data' | 'cluster' | 'clusterRadius' | 'clusterMaxZoom'>>
|
|
62
|
+
}>(),
|
|
63
|
+
{ color: 'primary', radius: 50, maxZoom: 14, zoomOnClick: true, interactive: false },
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
const emit = defineEmits<{
|
|
67
|
+
click: [event: Maplibre.MapLayerMouseEvent]
|
|
68
|
+
'cluster-click': [cluster: MapCluster]
|
|
69
|
+
}>()
|
|
70
|
+
|
|
71
|
+
const sourceId = props.id ?? `m3-cluster-${useId()}`
|
|
72
|
+
const locale = useLocale()
|
|
73
|
+
const { onReady, styleVersion } = useMap()
|
|
74
|
+
const theme = useThemeTokens(['primary', 'secondary', 'tertiary', 'surface'] as const)
|
|
75
|
+
|
|
76
|
+
const SINGLE: Maplibre.FilterSpecification = ['!', ['has', 'point_count']]
|
|
77
|
+
|
|
78
|
+
const layers = computed(() => {
|
|
79
|
+
const color = theme.value[props.color]
|
|
80
|
+
const list: MapGeoJsonLayer[] = props.pointLayers ?? [{
|
|
81
|
+
type: 'circle',
|
|
82
|
+
filter: SINGLE,
|
|
83
|
+
paint: { 'circle-color': color, 'circle-radius': 6, 'circle-stroke-color': theme.value.surface, 'circle-stroke-width': 2 },
|
|
84
|
+
}]
|
|
85
|
+
return list.map((l, i) => ({ ...l, id: l.id ?? `${sourceId}-point-${i}`, source: sourceId }) as Maplibre.LayerSpecification)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
// Static class strings, so Tailwind finds them
|
|
89
|
+
const COLORS = {
|
|
90
|
+
primary: 'bg-primary text-on-primary after:bg-on-primary',
|
|
91
|
+
secondary: 'bg-secondary text-on-secondary after:bg-on-secondary',
|
|
92
|
+
tertiary: 'bg-tertiary text-on-tertiary after:bg-on-tertiary',
|
|
93
|
+
} as const
|
|
94
|
+
|
|
95
|
+
/** The bubble's diameter: bigger for more points. */
|
|
96
|
+
function sizeOf(count: number) {
|
|
97
|
+
return count < 10 ? 32 : count < 100 ? 40 : count < 1000 ? 48 : 56
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const compact = computed(() => {
|
|
101
|
+
const lang = typeof document !== 'undefined' ? document.documentElement.lang || undefined : undefined
|
|
102
|
+
return new Intl.NumberFormat(lang, { notation: 'compact', maximumFractionDigits: 1 })
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
interface Bubble extends MapCluster {
|
|
106
|
+
el: HTMLElement
|
|
107
|
+
marker: Maplibre.Marker
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let map: Maplibre.Map | undefined
|
|
111
|
+
let ml: typeof import('maplibre-gl') | undefined
|
|
112
|
+
let added: string[] = []
|
|
113
|
+
const bubbles = new Map<number, Bubble>()
|
|
114
|
+
const shown = shallowRef<Bubble[]>([])
|
|
115
|
+
|
|
116
|
+
const source = () => map?.getSource(sourceId) as Maplibre.GeoJSONSource | undefined
|
|
117
|
+
|
|
118
|
+
function makeCluster(id: number, count: number, lngLat: [number, number]): MapCluster {
|
|
119
|
+
return {
|
|
120
|
+
id,
|
|
121
|
+
count,
|
|
122
|
+
lngLat,
|
|
123
|
+
zoomIn: async () => {
|
|
124
|
+
const zoom = await source()?.getClusterExpansionZoom(id)
|
|
125
|
+
if (zoom === undefined || !map) return
|
|
126
|
+
map.easeTo({ center: lngLat, zoom: Math.min(zoom, map.getMaxZoom()) })
|
|
127
|
+
},
|
|
128
|
+
leaves: async (limit = Infinity) => (await source()?.getClusterLeaves(id, limit, 0)) ?? [],
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Matches the bubbles to the clusters MapLibre has now. */
|
|
133
|
+
function update() {
|
|
134
|
+
frame = 0
|
|
135
|
+
if (!map || !ml || !map.getSource(sourceId)) return
|
|
136
|
+
const seen = new Set<number>()
|
|
137
|
+
for (const f of map.querySourceFeatures(sourceId, { filter: ['has', 'point_count'] })) {
|
|
138
|
+
const p = f.properties as { cluster_id: number; point_count: number }
|
|
139
|
+
const id = p.cluster_id
|
|
140
|
+
if (seen.has(id)) continue // a cluster crossing tiles comes back once per tile
|
|
141
|
+
seen.add(id)
|
|
142
|
+
const [lng, lat] = (f.geometry as { coordinates: number[] }).coordinates as [number, number]
|
|
143
|
+
const old = bubbles.get(id)
|
|
144
|
+
if (old && old.count === p.point_count) {
|
|
145
|
+
old.marker.setLngLat([lng, lat])
|
|
146
|
+
continue
|
|
147
|
+
}
|
|
148
|
+
old?.marker.remove()
|
|
149
|
+
const el = old?.el ?? document.createElement('div')
|
|
150
|
+
el.className = 'm3-map-cluster'
|
|
151
|
+
const marker = new ml.Marker({ element: el, anchor: 'center' }).setLngLat([lng, lat]).addTo(map)
|
|
152
|
+
bubbles.set(id, { ...makeCluster(id, p.point_count, [lng, lat]), el, marker })
|
|
153
|
+
}
|
|
154
|
+
for (const [id, b] of bubbles) {
|
|
155
|
+
if (seen.has(id)) continue
|
|
156
|
+
b.marker.remove()
|
|
157
|
+
bubbles.delete(id)
|
|
158
|
+
}
|
|
159
|
+
shown.value = [...bubbles.values()]
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let frame = 0
|
|
163
|
+
function schedule() {
|
|
164
|
+
if (!frame) frame = requestAnimationFrame(update)
|
|
165
|
+
}
|
|
166
|
+
const onSourceData = (e: Maplibre.MapSourceDataEvent) => {
|
|
167
|
+
if (e.sourceId === sourceId) schedule()
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const onClick = (e: Maplibre.MapLayerMouseEvent) => emit('click', e)
|
|
171
|
+
const onEnter = () => { if (props.interactive && map) map.getCanvas().style.cursor = 'pointer' }
|
|
172
|
+
const onLeave = () => { if (props.interactive && map) map.getCanvas().style.cursor = '' }
|
|
173
|
+
|
|
174
|
+
function removeLayers() {
|
|
175
|
+
if (!map) return
|
|
176
|
+
for (const id of added) {
|
|
177
|
+
map.off('click', id, onClick)
|
|
178
|
+
map.off('mouseenter', id, onEnter)
|
|
179
|
+
map.off('mouseleave', id, onLeave)
|
|
180
|
+
if (map.getLayer(id)) map.removeLayer(id)
|
|
181
|
+
}
|
|
182
|
+
added = []
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function addLayers() {
|
|
186
|
+
if (!map) return
|
|
187
|
+
removeLayers()
|
|
188
|
+
for (const layer of layers.value) {
|
|
189
|
+
map.addLayer(layer, props.before && map.getLayer(props.before) ? props.before : undefined)
|
|
190
|
+
map.on('click', layer.id, onClick)
|
|
191
|
+
map.on('mouseenter', layer.id, onEnter)
|
|
192
|
+
map.on('mouseleave', layer.id, onLeave)
|
|
193
|
+
added.push(layer.id)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function sourceSpec(): Maplibre.GeoJSONSourceSpecification {
|
|
198
|
+
return { type: 'geojson', data: props.data, ...props.sourceOptions, cluster: true, clusterRadius: props.radius, clusterMaxZoom: props.maxZoom }
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** The source and its layers, unless they're there already (a style change drops them). */
|
|
202
|
+
function add() {
|
|
203
|
+
if (!map) return
|
|
204
|
+
if (!map.getSource(sourceId)) {
|
|
205
|
+
map.addSource(sourceId, sourceSpec())
|
|
206
|
+
added = []
|
|
207
|
+
}
|
|
208
|
+
if (!added.length || !map.getLayer(added[0]!)) addLayers()
|
|
209
|
+
schedule()
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Clustering options can't change on a live source: add it again. */
|
|
213
|
+
function rebuild() {
|
|
214
|
+
if (!map) return
|
|
215
|
+
removeLayers()
|
|
216
|
+
if (map.getSource(sourceId)) map.removeSource(sourceId)
|
|
217
|
+
add()
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
onReady((m, lib) => {
|
|
221
|
+
map = m
|
|
222
|
+
ml = lib
|
|
223
|
+
add()
|
|
224
|
+
map.on('sourcedata', onSourceData)
|
|
225
|
+
map.on('move', schedule)
|
|
226
|
+
map.on('moveend', schedule)
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
watch(styleVersion, () => add())
|
|
230
|
+
watch(() => props.data, (data) => {
|
|
231
|
+
source()?.setData(data)
|
|
232
|
+
schedule()
|
|
233
|
+
})
|
|
234
|
+
watch(() => [props.radius, props.maxZoom, JSON.stringify(props.sourceOptions)].join('|'), rebuild)
|
|
235
|
+
// Layers by value: an inline `:point-layers="[...]"` is a new array on every parent render
|
|
236
|
+
watch(() => JSON.stringify(layers.value), () => addLayers())
|
|
237
|
+
watch(() => props.before, () => addLayers())
|
|
238
|
+
|
|
239
|
+
function onBubbleClick(b: Bubble) {
|
|
240
|
+
const cluster: MapCluster = { id: b.id, count: b.count, lngLat: b.lngLat, zoomIn: b.zoomIn, leaves: b.leaves }
|
|
241
|
+
emit('cluster-click', cluster)
|
|
242
|
+
if (props.zoomOnClick) void b.zoomIn()
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const labelOf = (count: number) => locale.mapClusterZoom.replace('{count}', String(count))
|
|
246
|
+
|
|
247
|
+
onBeforeUnmount(() => {
|
|
248
|
+
if (frame) cancelAnimationFrame(frame)
|
|
249
|
+
for (const b of bubbles.values()) b.marker.remove()
|
|
250
|
+
bubbles.clear()
|
|
251
|
+
shown.value = []
|
|
252
|
+
if (!map) return
|
|
253
|
+
map.off('sourcedata', onSourceData)
|
|
254
|
+
map.off('move', schedule)
|
|
255
|
+
map.off('moveend', schedule)
|
|
256
|
+
removeLayers()
|
|
257
|
+
if (map.getSource(sourceId)) map.removeSource(sourceId)
|
|
258
|
+
map = undefined
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
defineExpose({
|
|
262
|
+
/** The source's id */
|
|
263
|
+
sourceId,
|
|
264
|
+
/** The ids of its point layers on the map */
|
|
265
|
+
layerIds: () => [...added],
|
|
266
|
+
/** The bubbles on screen now */
|
|
267
|
+
clusters: (): MapCluster[] => shown.value.map(({ id, count, lngLat, zoomIn, leaves }) => ({ id, count, lngLat, zoomIn, leaves })),
|
|
268
|
+
})
|
|
269
|
+
</script>
|
|
270
|
+
|
|
271
|
+
<!-- Each bubble is rendered into its MapLibre marker's element -->
|
|
272
|
+
<template>
|
|
273
|
+
<Teleport v-for="b in shown" :key="b.id" :to="b.el">
|
|
274
|
+
<slot
|
|
275
|
+
name="cluster"
|
|
276
|
+
:id="b.id"
|
|
277
|
+
:count="b.count"
|
|
278
|
+
:label="compact.format(b.count)"
|
|
279
|
+
:lng-lat="b.lngLat"
|
|
280
|
+
:zoom-in="b.zoomIn"
|
|
281
|
+
:leaves="b.leaves"
|
|
282
|
+
>
|
|
283
|
+
<button
|
|
284
|
+
type="button"
|
|
285
|
+
class="m3-map-cluster__bubble relative grid cursor-pointer place-items-center rounded-full border-2 border-surface text-label-large font-medium shadow-elevation-1 outline-none transition-[transform,box-shadow] duration-150 after:pointer-events-none after:absolute after:inset-0 after:rounded-full after:opacity-0 after:transition-opacity hover:shadow-elevation-2 hover:after:opacity-8 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-secondary active:after:opacity-10"
|
|
286
|
+
:class="COLORS[color]"
|
|
287
|
+
:style="{ width: `${sizeOf(b.count)}px`, height: `${sizeOf(b.count)}px` }"
|
|
288
|
+
:aria-label="labelOf(b.count)"
|
|
289
|
+
@click.stop="onBubbleClick(b)"
|
|
290
|
+
>
|
|
291
|
+
{{ compact.format(b.count) }}
|
|
292
|
+
</button>
|
|
293
|
+
</slot>
|
|
294
|
+
</Teleport>
|
|
295
|
+
</template>
|