@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,382 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A dashboard of widgets on a grid that people rearrange: drag a widget to move it (others make room and everything
|
|
4
|
+
* floats up to fill gaps), drag its corner to resize it, all on springs. Touch picks a widget up on a long press,
|
|
5
|
+
* so the page still scrolls; the keyboard does it all too (Space to pick up, arrows to move, Shift and arrows to
|
|
6
|
+
* resize, Space to drop, Escape to cancel), announced to screen readers. The layout (cells: `x`, `y`, `w`, `h`) is
|
|
7
|
+
* the v-model; your content goes in `#item`. Below `breakpoint` (its own width) the widgets stack in one column.
|
|
8
|
+
*
|
|
9
|
+
* @slot item One widget's content: `{ item, dragging, resizing }`
|
|
10
|
+
* @event update:modelValue The layout changed (moved, resized)
|
|
11
|
+
*/
|
|
12
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
|
|
13
|
+
import MIcon from './MIcon.vue'
|
|
14
|
+
import { useLocale } from '../composables/useLocale'
|
|
15
|
+
import { moveItem, normalizeLayout, layoutRows, type DashboardItem } from '../composables/dashboardLayout'
|
|
16
|
+
|
|
17
|
+
const props = withDefaults(
|
|
18
|
+
defineProps<{
|
|
19
|
+
/** The layout (v-model): `{ id, x, y, w, h, minW?, minH?, maxW?, maxH?, static?, label? }[]`, in cells */
|
|
20
|
+
modelValue: (DashboardItem & { label?: string })[]
|
|
21
|
+
/** Columns */
|
|
22
|
+
columns?: number
|
|
23
|
+
/** A row's height, in px */
|
|
24
|
+
rowHeight?: number
|
|
25
|
+
/** The gap between cells, in px */
|
|
26
|
+
gap?: number
|
|
27
|
+
/** Let people move and resize widgets */
|
|
28
|
+
editable?: boolean
|
|
29
|
+
/** Show a resize handle on each widget's corner */
|
|
30
|
+
resizable?: boolean
|
|
31
|
+
/** Below this width (px, the grid's own) the widgets stack in one column, in reading order */
|
|
32
|
+
breakpoint?: number
|
|
33
|
+
/** Only start a drag from inside an element matching this (a widget's title bar), instead of anywhere on it */
|
|
34
|
+
handle?: string
|
|
35
|
+
}>(),
|
|
36
|
+
{ columns: 12, rowHeight: 96, gap: 16, editable: true, resizable: true, breakpoint: 600 },
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
const emit = defineEmits<{ 'update:modelValue': [layout: (DashboardItem & { label?: string })[]] }>()
|
|
40
|
+
|
|
41
|
+
const t = useLocale()
|
|
42
|
+
const root = ref<HTMLElement>()
|
|
43
|
+
const width = ref(0)
|
|
44
|
+
const stacked = computed(() => width.value > 0 && width.value < props.breakpoint)
|
|
45
|
+
const canEdit = computed(() => props.editable && !stacked.value)
|
|
46
|
+
|
|
47
|
+
// The layout shown: the v-model, or a preview while dragging / resizing / moving with keys
|
|
48
|
+
const items = computed(() => (Array.isArray(props.modelValue) ? props.modelValue : []))
|
|
49
|
+
const layout = computed(() => normalizeLayout(items.value, props.columns))
|
|
50
|
+
const preview = ref<DashboardItem[] | null>(null)
|
|
51
|
+
const shown = computed(() => preview.value ?? layout.value)
|
|
52
|
+
|
|
53
|
+
const colWidth = computed(() => Math.max(0, (width.value - props.gap * (props.columns - 1)) / props.columns))
|
|
54
|
+
const cellX = (x: number) => x * (colWidth.value + props.gap)
|
|
55
|
+
const cellY = (y: number) => y * (props.rowHeight + props.gap)
|
|
56
|
+
const spanW = (w: number) => w * colWidth.value + (w - 1) * props.gap
|
|
57
|
+
const spanH = (h: number) => h * props.rowHeight + (h - 1) * props.gap
|
|
58
|
+
const height = computed(() => {
|
|
59
|
+
const rows = layoutRows(shown.value)
|
|
60
|
+
return rows ? cellY(rows) - props.gap : 0
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
// ── Springs (Standard DefaultSpatial: dampingRatio 0.9, stiffness 700), one rAF loop ────────────
|
|
64
|
+
|
|
65
|
+
interface Spring { x: number; y: number; w: number; h: number; vx: number; vy: number; vw: number; vh: number }
|
|
66
|
+
const springs = new Map<DashboardItem['id'], Spring>()
|
|
67
|
+
const els = new Map<DashboardItem['id'], HTMLElement>()
|
|
68
|
+
const STIFF = 700
|
|
69
|
+
const DAMP = 2 * 0.9 * Math.sqrt(STIFF)
|
|
70
|
+
let raf = 0
|
|
71
|
+
let last = 0
|
|
72
|
+
|
|
73
|
+
const dragging = ref<DashboardItem['id'] | null>(null)
|
|
74
|
+
const resizing = ref<DashboardItem['id'] | null>(null)
|
|
75
|
+
/** The held widget's box, in px, following the pointer */
|
|
76
|
+
const held = reactive({ x: 0, y: 0, w: 0, h: 0 })
|
|
77
|
+
|
|
78
|
+
function target(item: DashboardItem) {
|
|
79
|
+
return { x: cellX(item.x), y: cellY(item.y), w: spanW(item.w), h: spanH(item.h) }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function write(id: DashboardItem['id'], s: { x: number; y: number; w: number; h: number }) {
|
|
83
|
+
const el = els.get(id)
|
|
84
|
+
if (!el) return
|
|
85
|
+
el.style.transform = `translate(${s.x}px, ${s.y}px)`
|
|
86
|
+
el.style.width = `${s.w}px`
|
|
87
|
+
el.style.height = `${s.h}px`
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function step(now: number) {
|
|
91
|
+
const dt = Math.min((now - last) / 1000, 1 / 30)
|
|
92
|
+
last = now
|
|
93
|
+
let moving = false
|
|
94
|
+
for (const item of shown.value) {
|
|
95
|
+
const s = springs.get(item.id)
|
|
96
|
+
if (!s) continue
|
|
97
|
+
if (item.id === dragging.value || item.id === resizing.value) {
|
|
98
|
+
// The held one follows the pointer; its spring waits where it is, to take over on drop
|
|
99
|
+
Object.assign(s, held, { vx: 0, vy: 0, vw: 0, vh: 0 })
|
|
100
|
+
write(item.id, s)
|
|
101
|
+
continue
|
|
102
|
+
}
|
|
103
|
+
const goal = target(item)
|
|
104
|
+
// Fixed 4ms substeps: stable at any frame rate
|
|
105
|
+
for (let left = dt; left > 0; left -= 0.004) {
|
|
106
|
+
const h = Math.min(0.004, left)
|
|
107
|
+
for (const k of ['x', 'y', 'w', 'h'] as const) {
|
|
108
|
+
const v = `v${k}` as 'vx' | 'vy' | 'vw' | 'vh'
|
|
109
|
+
s[v] += (-STIFF * (s[k] - goal[k]) - DAMP * s[v]) * h
|
|
110
|
+
s[k] += s[v] * h
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const settled = (['x', 'y', 'w', 'h'] as const).every((k) => Math.abs(s[k] - goal[k]) < 0.3 && Math.abs(s[`v${k}` as 'vx']) < 0.3)
|
|
114
|
+
if (settled) Object.assign(s, goal, { vx: 0, vy: 0, vw: 0, vh: 0 })
|
|
115
|
+
else moving = true
|
|
116
|
+
write(item.id, s)
|
|
117
|
+
}
|
|
118
|
+
raf = moving || dragging.value !== null || resizing.value !== null ? requestAnimationFrame(step) : 0
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function animate() {
|
|
122
|
+
if (raf) return
|
|
123
|
+
last = performance.now()
|
|
124
|
+
raf = requestAnimationFrame(step)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Puts every widget where it belongs at once (first layout, width changes, reduced motion) */
|
|
128
|
+
function snap() {
|
|
129
|
+
for (const item of shown.value) {
|
|
130
|
+
const goal = target(item)
|
|
131
|
+
springs.set(item.id, { ...goal, vx: 0, vy: 0, vw: 0, vh: 0 })
|
|
132
|
+
write(item.id, goal)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const reduced = () => typeof window !== 'undefined' && !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
|
|
137
|
+
|
|
138
|
+
watch(shown, (items) => {
|
|
139
|
+
for (const item of items) if (!springs.has(item.id)) springs.set(item.id, { ...target(item), vx: 0, vy: 0, vw: 0, vh: 0 })
|
|
140
|
+
for (const id of springs.keys()) if (!items.some((i) => i.id === id)) springs.delete(id)
|
|
141
|
+
nextTick(() => (reduced() ? snap() : animate()))
|
|
142
|
+
}, { deep: true })
|
|
143
|
+
|
|
144
|
+
// ── Pointer: move and resize ───────────────────────────────────────────────────────────────────
|
|
145
|
+
|
|
146
|
+
let press: { id: DashboardItem['id']; mode: 'move' | 'resize'; x: number; y: number; pointer: string; timer?: ReturnType<typeof setTimeout>; active: boolean } | null = null
|
|
147
|
+
let start = { x: 0, y: 0, w: 0, h: 0 }
|
|
148
|
+
let snapshot: DashboardItem[] = []
|
|
149
|
+
|
|
150
|
+
const CONTROLS = 'input, textarea, select, button, a, label, [contenteditable], [data-dashboard-action]'
|
|
151
|
+
|
|
152
|
+
function onPointerDown(e: PointerEvent, item: DashboardItem, mode: 'move' | 'resize') {
|
|
153
|
+
if (!canEdit.value || item.static || e.button > 0) return
|
|
154
|
+
const el = e.target as HTMLElement
|
|
155
|
+
if (mode === 'move') {
|
|
156
|
+
if (el.closest(CONTROLS) && !el.closest('[data-dashboard-resize]')) return
|
|
157
|
+
if (props.handle && !el.closest(props.handle)) return
|
|
158
|
+
}
|
|
159
|
+
press = { id: item.id, mode, x: e.clientX, y: e.clientY, pointer: e.pointerType, active: false }
|
|
160
|
+
// A finger picks up on a long press (moving first is a scroll); the resize corner and a mouse right away-ish
|
|
161
|
+
if (e.pointerType === 'touch' && mode === 'move') press.timer = setTimeout(() => activate(), 350)
|
|
162
|
+
window.addEventListener('pointermove', onPointerMove)
|
|
163
|
+
window.addEventListener('pointerup', onPointerUp)
|
|
164
|
+
window.addEventListener('pointercancel', onPointerCancel)
|
|
165
|
+
if (mode === 'resize') {
|
|
166
|
+
e.preventDefault()
|
|
167
|
+
activate()
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function activate() {
|
|
172
|
+
if (!press) return
|
|
173
|
+
press.active = true
|
|
174
|
+
const item = shown.value.find((i) => i.id === press!.id)!
|
|
175
|
+
snapshot = layout.value
|
|
176
|
+
start = target(item)
|
|
177
|
+
Object.assign(held, start)
|
|
178
|
+
if (press.mode === 'move') dragging.value = item.id
|
|
179
|
+
else resizing.value = item.id
|
|
180
|
+
preview.value = layout.value
|
|
181
|
+
document.body.style.userSelect = 'none'
|
|
182
|
+
animate()
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function onPointerMove(e: PointerEvent) {
|
|
186
|
+
if (!press) return
|
|
187
|
+
const dx = e.clientX - press.x
|
|
188
|
+
const dy = e.clientY - press.y
|
|
189
|
+
if (!press.active) {
|
|
190
|
+
if (press.pointer === 'touch') {
|
|
191
|
+
if (Math.hypot(dx, dy) > 8) cleanup()
|
|
192
|
+
return
|
|
193
|
+
}
|
|
194
|
+
if (Math.hypot(dx, dy) < 4) return
|
|
195
|
+
activate()
|
|
196
|
+
}
|
|
197
|
+
const unitX = colWidth.value + props.gap
|
|
198
|
+
const unitY = props.rowHeight + props.gap
|
|
199
|
+
if (press.mode === 'move') {
|
|
200
|
+
held.x = Math.max(0, Math.min(width.value - start.w, start.x + dx))
|
|
201
|
+
held.y = Math.max(0, start.y + dy)
|
|
202
|
+
const x = Math.round(held.x / unitX)
|
|
203
|
+
const y = Math.round(held.y / unitY)
|
|
204
|
+
preview.value = moveItem(snapshot, press.id, { x, y }, props.columns)
|
|
205
|
+
} else {
|
|
206
|
+
held.w = Math.max(colWidth.value, Math.min(width.value - start.x, start.w + dx))
|
|
207
|
+
held.h = Math.max(props.rowHeight, start.h + dy)
|
|
208
|
+
const w = Math.round((held.w + props.gap) / unitX)
|
|
209
|
+
const h = Math.round((held.h + props.gap) / unitY)
|
|
210
|
+
preview.value = moveItem(snapshot, press.id, { w, h }, props.columns)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function onPointerUp() {
|
|
215
|
+
if (press?.active && preview.value) commit(preview.value)
|
|
216
|
+
cleanup()
|
|
217
|
+
}
|
|
218
|
+
function onPointerCancel() {
|
|
219
|
+
preview.value = null
|
|
220
|
+
cleanup()
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function commit(next: DashboardItem[]) {
|
|
224
|
+
const byId = new Map(items.value.map((i) => [i.id, i]))
|
|
225
|
+
emit('update:modelValue', next.map((i) => ({ ...byId.get(i.id)!, x: i.x, y: i.y, w: i.w, h: i.h })))
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function cleanup() {
|
|
229
|
+
clearTimeout(press?.timer)
|
|
230
|
+
press = null
|
|
231
|
+
dragging.value = null
|
|
232
|
+
resizing.value = null
|
|
233
|
+
// The preview stays until the v-model comes back with it, so nothing jumps
|
|
234
|
+
nextTick(() => { preview.value = null })
|
|
235
|
+
document.body.style.userSelect = ''
|
|
236
|
+
window.removeEventListener('pointermove', onPointerMove)
|
|
237
|
+
window.removeEventListener('pointerup', onPointerUp)
|
|
238
|
+
window.removeEventListener('pointercancel', onPointerCancel)
|
|
239
|
+
animate()
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// A finger dragging a widget mustn't scroll the page (decided on its first touchmove, non-passive)
|
|
243
|
+
function onTouchMove(e: TouchEvent) {
|
|
244
|
+
if (dragging.value !== null || resizing.value !== null) e.preventDefault()
|
|
245
|
+
}
|
|
246
|
+
const noMenu = (e: Event) => { if (press) e.preventDefault() }
|
|
247
|
+
|
|
248
|
+
// ── Keyboard ───────────────────────────────────────────────────────────────────────────────────
|
|
249
|
+
|
|
250
|
+
const grabbed = ref<DashboardItem['id'] | null>(null)
|
|
251
|
+
const announcement = ref('')
|
|
252
|
+
const labelOf = (item: DashboardItem & { label?: string }) => item.label ?? String(item.id)
|
|
253
|
+
|
|
254
|
+
function say(text: string) {
|
|
255
|
+
announcement.value = ''
|
|
256
|
+
nextTick(() => (announcement.value = text))
|
|
257
|
+
}
|
|
258
|
+
function describe(item: DashboardItem & { label?: string }) {
|
|
259
|
+
return t.dashPlaced.replace('{name}', labelOf(item)).replace('{x}', String(item.x + 1)).replace('{y}', String(item.y + 1))
|
|
260
|
+
.replace('{w}', String(item.w)).replace('{h}', String(item.h))
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function onKeydown(e: KeyboardEvent, item: DashboardItem & { label?: string }) {
|
|
264
|
+
if (!canEdit.value || item.static || e.target !== e.currentTarget) return
|
|
265
|
+
if (e.key === ' ' || e.key === 'Enter') {
|
|
266
|
+
e.preventDefault()
|
|
267
|
+
if (grabbed.value === item.id) {
|
|
268
|
+
grabbed.value = null
|
|
269
|
+
say(t.dashDropped.replace('{name}', labelOf(item)))
|
|
270
|
+
} else {
|
|
271
|
+
grabbed.value = item.id
|
|
272
|
+
snapshot = layout.value
|
|
273
|
+
say(t.dashGrabbed.replace('{name}', labelOf(item)))
|
|
274
|
+
}
|
|
275
|
+
return
|
|
276
|
+
}
|
|
277
|
+
if (grabbed.value !== item.id) return
|
|
278
|
+
if (e.key === 'Escape') {
|
|
279
|
+
e.preventDefault()
|
|
280
|
+
e.stopPropagation()
|
|
281
|
+
grabbed.value = null
|
|
282
|
+
commit(snapshot)
|
|
283
|
+
say(t.dashCancelled)
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
const d = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }[e.key]
|
|
287
|
+
if (!d) return
|
|
288
|
+
e.preventDefault()
|
|
289
|
+
const cur = layout.value.find((i) => i.id === item.id)!
|
|
290
|
+
const change = e.shiftKey ? { w: cur.w + d[0]!, h: cur.h + d[1]! } : { x: cur.x + d[0]!, y: cur.y + d[1]! }
|
|
291
|
+
const next = moveItem(layout.value, item.id, change, props.columns)
|
|
292
|
+
commit(next)
|
|
293
|
+
say(describe({ ...next.find((i) => i.id === item.id)!, label: item.label }))
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// ── Size ───────────────────────────────────────────────────────────────────────────────────────
|
|
297
|
+
|
|
298
|
+
let observer: ResizeObserver | undefined
|
|
299
|
+
onMounted(() => {
|
|
300
|
+
const measure = () => {
|
|
301
|
+
const before = width.value
|
|
302
|
+
width.value = root.value?.clientWidth ?? 0
|
|
303
|
+
// A new width moves everything at once, not on springs
|
|
304
|
+
if (before !== width.value) nextTick(snap)
|
|
305
|
+
}
|
|
306
|
+
measure()
|
|
307
|
+
if (typeof ResizeObserver !== 'undefined' && root.value) {
|
|
308
|
+
observer = new ResizeObserver(measure)
|
|
309
|
+
observer.observe(root.value)
|
|
310
|
+
}
|
|
311
|
+
root.value?.addEventListener('touchmove', onTouchMove, { passive: false })
|
|
312
|
+
})
|
|
313
|
+
onBeforeUnmount(() => {
|
|
314
|
+
cancelAnimationFrame(raf)
|
|
315
|
+
observer?.disconnect()
|
|
316
|
+
root.value?.removeEventListener('touchmove', onTouchMove)
|
|
317
|
+
cleanup()
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
const setEl = (id: DashboardItem['id']) => (el: unknown) => {
|
|
321
|
+
if (el instanceof HTMLElement) {
|
|
322
|
+
els.set(id, el)
|
|
323
|
+
const s = springs.get(id)
|
|
324
|
+
if (s) write(id, s)
|
|
325
|
+
} else els.delete(id)
|
|
326
|
+
}
|
|
327
|
+
const heldItem = computed(() => (dragging.value ?? resizing.value) !== null ? shown.value.find((i) => i.id === (dragging.value ?? resizing.value)) : undefined)
|
|
328
|
+
const stackOrder = computed(() => [...items.value].sort((a, b) => a.y - b.y || a.x - b.x))
|
|
329
|
+
</script>
|
|
330
|
+
|
|
331
|
+
<template>
|
|
332
|
+
<div ref="root" class="m3-dashboard-grid relative" :style="stacked ? undefined : { height: `${height}px` }" @contextmenu="noMenu">
|
|
333
|
+
<!-- Narrow: one column, in reading order, no editing -->
|
|
334
|
+
<div v-if="stacked" class="flex flex-col" :style="{ gap: `${gap}px` }">
|
|
335
|
+
<div v-for="item in stackOrder" :key="item.id" class="m3-dashboard-grid__item min-w-0" :style="{ height: `${spanH(item.h)}px` }">
|
|
336
|
+
<slot name="item" :item="item" :dragging="false" :resizing="false" />
|
|
337
|
+
</div>
|
|
338
|
+
</div>
|
|
339
|
+
|
|
340
|
+
<template v-else-if="width">
|
|
341
|
+
<!-- Where the held widget will land -->
|
|
342
|
+
<div
|
|
343
|
+
v-if="heldItem"
|
|
344
|
+
class="pointer-events-none absolute left-0 top-0 rounded-lg border-2 border-dashed border-primary/60 bg-primary/8 transition-transform duration-100"
|
|
345
|
+
:style="{ transform: `translate(${cellX(heldItem.x)}px, ${cellY(heldItem.y)}px)`, width: `${spanW(heldItem.w)}px`, height: `${spanH(heldItem.h)}px` }"
|
|
346
|
+
/>
|
|
347
|
+
<div
|
|
348
|
+
v-for="item in items"
|
|
349
|
+
:key="item.id"
|
|
350
|
+
:ref="setEl(item.id)"
|
|
351
|
+
class="m3-dashboard-grid__item absolute left-0 top-0 min-w-0 rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-secondary"
|
|
352
|
+
:class="[
|
|
353
|
+
dragging === item.id || resizing === item.id ? 'z-10 shadow-elevation-4' : '',
|
|
354
|
+
grabbed === item.id ? 'ring-2 ring-primary' : '',
|
|
355
|
+
canEdit && !item.static && !handle ? (dragging === item.id ? 'cursor-grabbing' : 'cursor-grab') : '',
|
|
356
|
+
]"
|
|
357
|
+
:style="{ touchAction: canEdit && !item.static ? 'pan-y' : undefined }"
|
|
358
|
+
:tabindex="canEdit && !item.static ? 0 : undefined"
|
|
359
|
+
:aria-roledescription="canEdit && !item.static ? 'draggable' : undefined"
|
|
360
|
+
:aria-label="item.label"
|
|
361
|
+
@pointerdown="onPointerDown($event, item, 'move')"
|
|
362
|
+
@keydown="onKeydown($event, item)"
|
|
363
|
+
@blur="grabbed === item.id && (grabbed = null)"
|
|
364
|
+
>
|
|
365
|
+
<slot name="item" :item="item" :dragging="dragging === item.id" :resizing="resizing === item.id" />
|
|
366
|
+
<!-- Resize corner -->
|
|
367
|
+
<span
|
|
368
|
+
v-if="canEdit && resizable && !item.static"
|
|
369
|
+
data-dashboard-resize
|
|
370
|
+
class="absolute bottom-0 right-0 z-[1] grid size-6 cursor-nwse-resize touch-none place-items-center rounded-br-lg text-on-surface-variant opacity-60 hover:opacity-100"
|
|
371
|
+
:aria-label="t.dashResize"
|
|
372
|
+
role="presentation"
|
|
373
|
+
@pointerdown.stop="onPointerDown($event, item, 'resize')"
|
|
374
|
+
>
|
|
375
|
+
<MIcon name="south_east" :size="16" />
|
|
376
|
+
</span>
|
|
377
|
+
</div>
|
|
378
|
+
</template>
|
|
379
|
+
|
|
380
|
+
<span class="sr-only" aria-live="assertive">{{ announcement }}</span>
|
|
381
|
+
</div>
|
|
382
|
+
</template>
|
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @event update:modelValue Emitted with the picked date.
|
|
6
6
|
*/
|
|
7
|
-
import { computed,
|
|
7
|
+
import { computed, onUnmounted, ref, watch } from 'vue'
|
|
8
8
|
import MIcon from './MIcon.vue'
|
|
9
9
|
import MIconButton from './MIconButton.vue'
|
|
10
10
|
import MMonthYearButton from './_MMonthYearButton.vue'
|
|
11
11
|
import MYearGrid from './_MYearGrid.vue'
|
|
12
12
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
13
13
|
import { useLocale } from '../composables/useLocale'
|
|
14
|
+
import { useFollowAnchor } from '../composables/_useFollowAnchor'
|
|
14
15
|
import { POPUP_MARGIN, dropdownX, fitPopup } from '../composables/_popupPosition'
|
|
15
16
|
import { useCalendarMonth } from '../composables/_useCalendarMonth'
|
|
16
17
|
import { OUTLINED_FLOATED_LABEL, vOverflowTitle } from '../composables/_fieldLayout'
|
|
@@ -142,11 +143,15 @@ function onClickOutside(e: MouseEvent) {
|
|
|
142
143
|
open.value = false
|
|
143
144
|
}
|
|
144
145
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
|
|
146
|
+
// Following the field: re-measure it and re-run placeDrop() from an unconstrained left edge (see above)
|
|
147
|
+
function followAnchor() {
|
|
148
|
+
if (!triggerEl.value || !panelEl.value) return
|
|
149
|
+
anchorRect = triggerEl.value.getBoundingClientRect()
|
|
150
|
+
panelEl.value.style.left = '0px'
|
|
151
|
+
placeDrop(panelEl.value)
|
|
149
152
|
}
|
|
153
|
+
// Stays on its field while the page or a container scrolls, the window/zoom changes or the field resizes
|
|
154
|
+
useFollowAnchor({ open: () => open.value, anchor: triggerEl, popup: panelEl, place: followAnchor, close: () => (open.value = false) })
|
|
150
155
|
|
|
151
156
|
watch(open, (v) => {
|
|
152
157
|
if (v) {
|
|
@@ -157,9 +162,7 @@ watch(open, (v) => {
|
|
|
157
162
|
}
|
|
158
163
|
})
|
|
159
164
|
|
|
160
|
-
onMounted(() => window.addEventListener('scroll', onScroll, true))
|
|
161
165
|
onUnmounted(() => {
|
|
162
|
-
window.removeEventListener('scroll', onScroll, true)
|
|
163
166
|
document.removeEventListener('mousedown', onClickOutside)
|
|
164
167
|
})
|
|
165
168
|
</script>
|
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @event update:modelValue Emitted with the picked range.
|
|
6
6
|
*/
|
|
7
|
-
import { computed,
|
|
7
|
+
import { computed, onUnmounted, ref, watch } from 'vue'
|
|
8
8
|
import MIcon from './MIcon.vue'
|
|
9
9
|
import MIconButton from './MIconButton.vue'
|
|
10
10
|
import MMonthYearButton from './_MMonthYearButton.vue'
|
|
11
11
|
import MYearGrid from './_MYearGrid.vue'
|
|
12
12
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
13
13
|
import { useLocale } from '../composables/useLocale'
|
|
14
|
+
import { useFollowAnchor } from '../composables/_useFollowAnchor'
|
|
14
15
|
import { POPUP_MARGIN, dropdownX, fitPopup } from '../composables/_popupPosition'
|
|
15
16
|
import { isoDate as fmt, useCalendarMonth } from '../composables/_useCalendarMonth'
|
|
16
17
|
import { OUTLINED_FLOATED_LABEL, vOverflowTitle } from '../composables/_fieldLayout'
|
|
@@ -177,11 +178,15 @@ function onOut(e: MouseEvent) {
|
|
|
177
178
|
open.value = false
|
|
178
179
|
}
|
|
179
180
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (
|
|
183
|
-
|
|
181
|
+
// Following the field: re-measure it and re-run placeDrop() from an unconstrained left edge (see above)
|
|
182
|
+
function followAnchor() {
|
|
183
|
+
if (!triggerEl.value || !panelEl.value) return
|
|
184
|
+
anchorRect = triggerEl.value.getBoundingClientRect()
|
|
185
|
+
panelEl.value.style.left = '0px'
|
|
186
|
+
placeDrop(panelEl.value)
|
|
184
187
|
}
|
|
188
|
+
// Stays on its field while the page or a container scrolls, the window/zoom changes or the field resizes
|
|
189
|
+
useFollowAnchor({ open: () => open.value, anchor: triggerEl, popup: panelEl, place: followAnchor, close: () => (open.value = false) })
|
|
185
190
|
|
|
186
191
|
watch(open, (v) => {
|
|
187
192
|
if (v) {
|
|
@@ -193,9 +198,7 @@ watch(open, (v) => {
|
|
|
193
198
|
}
|
|
194
199
|
})
|
|
195
200
|
|
|
196
|
-
onMounted(() => window.addEventListener('scroll', onScroll, true))
|
|
197
201
|
onUnmounted(() => {
|
|
198
|
-
window.removeEventListener('scroll', onScroll, true)
|
|
199
202
|
document.removeEventListener('mousedown', onOut)
|
|
200
203
|
})
|
|
201
204
|
</script>
|