@m3ui-vue/m3ui-vue 0.8.6 → 0.8.8
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/README.md +4 -0
- package/dist/{MMenuItem-BmPLAyv5.js → MMenuItem-5xojJYAL.js} +2 -2
- package/dist/{MMenuItem-BmPLAyv5.js.map → MMenuItem-5xojJYAL.js.map} +1 -1
- package/dist/chart.js +5 -1
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MBottomSheet.vue.d.ts +3 -3
- package/dist/components/MListDetail.vue.d.ts +31 -0
- package/dist/components/MNavigationRail.vue.d.ts +6 -3
- package/dist/components/MNavigationSuite.vue.d.ts +46 -0
- package/dist/components/MShortNavigationBar.vue.d.ts +6 -1
- package/dist/components/MSideSheet.vue.d.ts +4 -4
- package/dist/components/MSupportingPane.vue.d.ts +34 -0
- package/dist/components/MTransferList.vue.d.ts +55 -34
- package/dist/components/MWindow.vue.d.ts +39 -1
- package/dist/components/_MTransferPane.vue.d.ts +10 -3
- package/dist/composables/_useItemLink.d.ts +30 -0
- package/dist/composables/_useSheetMotion.d.ts +7 -0
- package/dist/composables/useLocale.d.ts +7 -0
- package/dist/composables/useWindowSizeClass.d.ts +19 -0
- package/dist/index.d.ts +6 -0
- package/dist/locales/index.js +56 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +2399 -1899
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +2 -2
- package/dist/styles.css +1 -1
- package/dist/{useLocale-4afAzuuP.js → useLocale-D3ZWZ8jY.js} +9 -2
- package/dist/useLocale-D3ZWZ8jY.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MChart.test.ts +28 -0
- package/src/__tests__/MPagination.test.ts +37 -0
- package/src/__tests__/MPullToRefresh.test.ts +39 -0
- package/src/__tests__/MShortNavigationBar.test.ts +25 -0
- package/src/__tests__/MTransferList.test.ts +73 -0
- package/src/__tests__/MWindow.test.ts +258 -0
- package/src/__tests__/adaptiveLayouts.test.ts +191 -0
- package/src/__tests__/sheets.test.ts +76 -0
- package/src/components/MBottomSheet.vue +11 -57
- package/src/components/MChart.vue +2 -1
- package/src/components/MListDetail.vue +103 -0
- package/src/components/MNavigationRail.vue +18 -10
- package/src/components/MNavigationSuite.vue +89 -0
- package/src/components/MPagination.vue +8 -5
- package/src/components/MPullToRefresh.vue +13 -1
- package/src/components/MShortNavigationBar.vue +37 -17
- package/src/components/MSideSheet.vue +11 -56
- package/src/components/MSupportingPane.vue +70 -0
- package/src/components/MTransferList.vue +43 -9
- package/src/components/MWindow.vue +507 -108
- package/src/components/_MTransferPane.vue +113 -35
- package/src/composables/_useItemLink.ts +19 -0
- package/src/composables/_useSheetMotion.ts +181 -0
- package/src/composables/useLocale.ts +17 -0
- package/src/composables/useWindowSizeClass.ts +93 -0
- package/src/index.ts +6 -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/useLocale-4afAzuuP.js.map +0 -1
|
@@ -2,12 +2,21 @@
|
|
|
2
2
|
// Module-scoped so it's actually shared across every MWindow instance.
|
|
3
3
|
// Kept below the app-level overlay scale (dialogs/spotlight/command palette use z-50)
|
|
4
4
|
// so windows never render on top of a real modal.
|
|
5
|
+
import { ref as moduleRef } from 'vue'
|
|
6
|
+
|
|
5
7
|
let sharedZIndex = 10
|
|
8
|
+
let nextId = 0
|
|
9
|
+
/** The window brought to front last: it alone gets the focused look. */
|
|
10
|
+
const activeWindowId = moduleRef<number | null>(null)
|
|
6
11
|
</script>
|
|
7
12
|
|
|
8
13
|
<script setup lang="ts">
|
|
9
14
|
import { ref, computed, onMounted, onUnmounted, watch, nextTick } from 'vue'
|
|
10
15
|
import MIcon from './MIcon.vue'
|
|
16
|
+
import { useLocale } from '../composables/useLocale'
|
|
17
|
+
|
|
18
|
+
const locale = useLocale()
|
|
19
|
+
const id = ++nextId
|
|
11
20
|
|
|
12
21
|
const props = withDefaults(
|
|
13
22
|
defineProps<{
|
|
@@ -24,6 +33,19 @@ const props = withDefaults(
|
|
|
24
33
|
draggable?: boolean
|
|
25
34
|
closable?: boolean
|
|
26
35
|
minimizable?: boolean
|
|
36
|
+
/** Maximize button, and double-click on the title bar, to fill the parent and back. */
|
|
37
|
+
maximizable?: boolean
|
|
38
|
+
/**
|
|
39
|
+
* Edge snapping while dragging, like GNOME: hold the pointer at the parent's top edge to
|
|
40
|
+
* maximize, or at its left/right edge to fill that half. A preview shows where it will land.
|
|
41
|
+
*/
|
|
42
|
+
snap?: boolean
|
|
43
|
+
/**
|
|
44
|
+
* Lets the window be dragged partly out of its container, like a desktop: up to 3/4 of its
|
|
45
|
+
* width past either side, and down until only the title bar shows; never above the top.
|
|
46
|
+
* The container should clip it (`overflow: hidden`).
|
|
47
|
+
*/
|
|
48
|
+
offscreen?: boolean
|
|
27
49
|
x?: number
|
|
28
50
|
y?: number
|
|
29
51
|
resetPosition?: boolean
|
|
@@ -37,6 +59,9 @@ const props = withDefaults(
|
|
|
37
59
|
draggable: true,
|
|
38
60
|
closable: true,
|
|
39
61
|
minimizable: true,
|
|
62
|
+
maximizable: true,
|
|
63
|
+
snap: false,
|
|
64
|
+
offscreen: false,
|
|
40
65
|
x: 50,
|
|
41
66
|
y: 50,
|
|
42
67
|
resetPosition: false,
|
|
@@ -47,6 +72,9 @@ const emit = defineEmits<{
|
|
|
47
72
|
'update:modelValue': [value: boolean]
|
|
48
73
|
close: []
|
|
49
74
|
minimize: []
|
|
75
|
+
maximize: [maximized: boolean]
|
|
76
|
+
/** The window came to the front (clicked, dragged, opened, or `focus()`). */
|
|
77
|
+
focus: []
|
|
50
78
|
}>()
|
|
51
79
|
|
|
52
80
|
// ---- State ----
|
|
@@ -55,7 +83,38 @@ const posY = ref(props.y)
|
|
|
55
83
|
const winWidth = ref(parseInt(props.width) || 400)
|
|
56
84
|
const winHeight = ref(parseInt(props.height) || 300)
|
|
57
85
|
const minimized = ref(false)
|
|
86
|
+
const maximized = ref(false)
|
|
58
87
|
const zIndex = ref(sharedZIndex)
|
|
88
|
+
/** The front window looks focused; the others step back (lower bar contrast and elevation). */
|
|
89
|
+
const active = computed(() => activeWindowId.value === id)
|
|
90
|
+
const dragging = ref(false)
|
|
91
|
+
// Maximize/restore animates the geometry; dragging and resizing must not.
|
|
92
|
+
const animatingGeometry = ref(false)
|
|
93
|
+
let geometryTimer: ReturnType<typeof setTimeout> | undefined
|
|
94
|
+
let restoreBox = { x: 0, y: 0, w: 0, h: 0 }
|
|
95
|
+
/** Filling the left or right half after a snap (maximized is its own state). */
|
|
96
|
+
const tiled = ref<'left' | 'right' | null>(null)
|
|
97
|
+
const snapped = computed(() => maximized.value || tiled.value !== null)
|
|
98
|
+
/** Where a release would snap to while dragging with `snap`; drives the preview. */
|
|
99
|
+
const snapTarget = ref<'top' | 'left' | 'right' | null>(null)
|
|
100
|
+
const parentEl = ref<HTMLElement | null>(null)
|
|
101
|
+
/** Title bar height: a minimized window is exactly this tall. */
|
|
102
|
+
const BAR = 40
|
|
103
|
+
/** How close (px) the pointer must get to the parent's edge to offer a snap. */
|
|
104
|
+
const SNAP_EDGE = 12
|
|
105
|
+
|
|
106
|
+
/** Allowed left for a window this wide: inside the parent, or with `offscreen`, 1/4 kept visible. */
|
|
107
|
+
function clampLeft(x: number, w: number) {
|
|
108
|
+
const pw = windowRef.value?.parentElement?.clientWidth ?? Infinity
|
|
109
|
+
if (!props.offscreen) return Math.max(0, Math.min(pw - w, x))
|
|
110
|
+
const keep = Math.min(w, Math.max(48, w / 4))
|
|
111
|
+
return Math.max(keep - w, Math.min(pw - keep, x))
|
|
112
|
+
}
|
|
113
|
+
/** Allowed top: never above the parent; with `offscreen`, down until only the title bar shows. */
|
|
114
|
+
function clampTop(y: number, h: number) {
|
|
115
|
+
const ph = windowRef.value?.parentElement?.clientHeight ?? Infinity
|
|
116
|
+
return Math.max(0, Math.min(ph - (props.offscreen ? BAR : h), y))
|
|
117
|
+
}
|
|
59
118
|
|
|
60
119
|
const windowRef = ref<HTMLElement | null>(null)
|
|
61
120
|
|
|
@@ -82,64 +141,136 @@ const windowStyle = computed(() => ({
|
|
|
82
141
|
left: `${posX.value}px`,
|
|
83
142
|
top: `${posY.value}px`,
|
|
84
143
|
width: `${winWidth.value}px`,
|
|
85
|
-
height: minimized.value ?
|
|
144
|
+
height: minimized.value ? `${BAR}px` : `${winHeight.value}px`,
|
|
86
145
|
zIndex: zIndex.value,
|
|
87
146
|
}))
|
|
88
147
|
|
|
89
148
|
// ---- Bring to front ----
|
|
90
149
|
function bringToFront() {
|
|
150
|
+
if (activeWindowId.value !== id) emit('focus')
|
|
151
|
+
activeWindowId.value = id
|
|
91
152
|
sharedZIndex++
|
|
92
153
|
zIndex.value = sharedZIndex
|
|
93
154
|
}
|
|
94
155
|
|
|
95
|
-
// ---- Pointer
|
|
96
|
-
function getXY(e: MouseEvent | TouchEvent): { x: number; y: number } {
|
|
97
|
-
if ('touches' in e) {
|
|
98
|
-
const t = e.touches[0] ?? e.changedTouches[0]
|
|
99
|
-
return { x: t!.clientX, y: t!.clientY }
|
|
100
|
-
}
|
|
101
|
-
return { x: e.clientX, y: e.clientY }
|
|
102
|
-
}
|
|
103
|
-
|
|
156
|
+
// ---- Pointer listeners (Pointer Events: mouse, touch and pen alike) ----
|
|
104
157
|
function addListeners() {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
document.addEventListener('touchend', onPointerUp)
|
|
158
|
+
window.addEventListener('pointermove', onPointerMove)
|
|
159
|
+
window.addEventListener('pointerup', onPointerUp)
|
|
160
|
+
window.addEventListener('pointercancel', onPointerUp)
|
|
109
161
|
}
|
|
110
|
-
|
|
111
162
|
function removeListeners() {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
document.removeEventListener('touchend', onPointerUp)
|
|
163
|
+
window.removeEventListener('pointermove', onPointerMove)
|
|
164
|
+
window.removeEventListener('pointerup', onPointerUp)
|
|
165
|
+
window.removeEventListener('pointercancel', onPointerUp)
|
|
116
166
|
}
|
|
117
167
|
|
|
118
168
|
// ---- Drag ----
|
|
119
|
-
|
|
120
|
-
|
|
169
|
+
// A drag that starts on a maximized or snapped window first restores it, but only once the
|
|
170
|
+
// pointer has travelled DETACH_DISTANCE (desktops make you pull it away deliberately, so a
|
|
171
|
+
// click, double-click or small slip doesn't). The size then eases back to the restored one
|
|
172
|
+
// while the window stays anchored to the pointer at the same proportional grab point.
|
|
173
|
+
const DETACH_DISTANCE = 40
|
|
174
|
+
const RESTORE_MS = 250
|
|
175
|
+
let restoreOnMove = false
|
|
176
|
+
/** Set after a detach: the window is positioned from the pointer instead of from deltas. */
|
|
177
|
+
let anchor: { ratio: number; grabY: number } | null = null
|
|
178
|
+
let pointerLocal = { x: 0, y: 0 }
|
|
179
|
+
let sizeAnim: { fromW: number; fromH: number; toW: number; toH: number; start: number } | null = null
|
|
180
|
+
let sizeRaf = 0
|
|
181
|
+
let parentLeft = 0
|
|
182
|
+
let parentTop = 0
|
|
183
|
+
/** Geometry to restore after a snap: the window as it was before this drag. */
|
|
184
|
+
let preDragBox = { x: 0, y: 0, w: 0, h: 0 }
|
|
185
|
+
|
|
186
|
+
function onTitleBarStart(e: PointerEvent) {
|
|
187
|
+
bringToFront()
|
|
188
|
+
if (!props.draggable || e.button !== 0) return
|
|
121
189
|
if ((e.target as HTMLElement).closest('button')) return
|
|
122
190
|
e.preventDefault()
|
|
123
|
-
const { x, y } = getXY(e)
|
|
124
191
|
isDragging = true
|
|
125
|
-
|
|
126
|
-
|
|
192
|
+
dragging.value = true
|
|
193
|
+
dragStartX = e.clientX
|
|
194
|
+
dragStartY = e.clientY
|
|
127
195
|
dragStartPosX = posX.value
|
|
128
196
|
dragStartPosY = posY.value
|
|
129
|
-
|
|
197
|
+
const rect = windowRef.value?.parentElement?.getBoundingClientRect()
|
|
198
|
+
parentLeft = rect?.left ?? 0
|
|
199
|
+
parentTop = rect?.top ?? 0
|
|
200
|
+
restoreOnMove = snapped.value
|
|
201
|
+
preDragBox = snapped.value ? { ...restoreBox } : { x: posX.value, y: posY.value, w: winWidth.value, h: winHeight.value }
|
|
130
202
|
addListeners()
|
|
131
203
|
}
|
|
132
204
|
|
|
205
|
+
function restoreUnderPointer() {
|
|
206
|
+
anchor = {
|
|
207
|
+
ratio: winWidth.value ? (dragStartX - parentLeft - posX.value) / winWidth.value : 0.5,
|
|
208
|
+
grabY: dragStartY - parentTop - posY.value,
|
|
209
|
+
}
|
|
210
|
+
const wasMaximized = maximized.value
|
|
211
|
+
maximized.value = false
|
|
212
|
+
tiled.value = null
|
|
213
|
+
restoreOnMove = false
|
|
214
|
+
const reduced = typeof window !== 'undefined' && !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
|
|
215
|
+
if (reduced) {
|
|
216
|
+
winWidth.value = restoreBox.w
|
|
217
|
+
winHeight.value = restoreBox.h
|
|
218
|
+
positionFromAnchor()
|
|
219
|
+
} else {
|
|
220
|
+
sizeAnim = { fromW: winWidth.value, fromH: winHeight.value, toW: restoreBox.w, toH: restoreBox.h, start: performance.now() }
|
|
221
|
+
cancelAnimationFrame(sizeRaf)
|
|
222
|
+
sizeRaf = requestAnimationFrame(stepRestore)
|
|
223
|
+
}
|
|
224
|
+
if (wasMaximized) emit('maximize', false)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function stepRestore(now: number) {
|
|
228
|
+
if (!sizeAnim) return
|
|
229
|
+
const t = Math.min(1, (now - sizeAnim.start) / RESTORE_MS)
|
|
230
|
+
const eased = 1 - (1 - t) ** 3
|
|
231
|
+
winWidth.value = sizeAnim.fromW + (sizeAnim.toW - sizeAnim.fromW) * eased
|
|
232
|
+
winHeight.value = sizeAnim.fromH + (sizeAnim.toH - sizeAnim.fromH) * eased
|
|
233
|
+
positionFromAnchor()
|
|
234
|
+
if (t < 1) {
|
|
235
|
+
sizeRaf = requestAnimationFrame(stepRestore)
|
|
236
|
+
return
|
|
237
|
+
}
|
|
238
|
+
winWidth.value = sizeAnim.toW
|
|
239
|
+
winHeight.value = sizeAnim.toH
|
|
240
|
+
positionFromAnchor()
|
|
241
|
+
sizeAnim = null
|
|
242
|
+
sizeRaf = 0
|
|
243
|
+
if (!isDragging) anchor = null
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Keeps the grab point under the pointer while the size changes under it. */
|
|
247
|
+
function positionFromAnchor() {
|
|
248
|
+
if (!anchor) return
|
|
249
|
+
posX.value = clampLeft(pointerLocal.x - anchor.ratio * winWidth.value, winWidth.value)
|
|
250
|
+
posY.value = clampTop(pointerLocal.y - anchor.grabY, winHeight.value)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function snapAt(e: PointerEvent): 'top' | 'left' | 'right' | null {
|
|
254
|
+
const parent = windowRef.value?.parentElement
|
|
255
|
+
if (!props.snap || !parent) return null
|
|
256
|
+
const localX = e.clientX - parentLeft
|
|
257
|
+
const localY = e.clientY - parentTop
|
|
258
|
+
// Sides first: pushed into a top corner means "that half", not "maximize".
|
|
259
|
+
if (localX <= SNAP_EDGE) return 'left'
|
|
260
|
+
if (localX >= parent.clientWidth - SNAP_EDGE) return 'right'
|
|
261
|
+
if (localY <= SNAP_EDGE && props.maximizable) return 'top'
|
|
262
|
+
return null
|
|
263
|
+
}
|
|
264
|
+
|
|
133
265
|
// ---- Resize ----
|
|
134
|
-
function onResizeStart(e:
|
|
135
|
-
if (!props.resizable) return
|
|
266
|
+
function onResizeStart(e: PointerEvent, direction: ResizeDirection) {
|
|
267
|
+
if (!props.resizable || e.button !== 0) return
|
|
136
268
|
e.preventDefault()
|
|
137
269
|
e.stopPropagation()
|
|
138
|
-
const { x, y } = getXY(e)
|
|
139
270
|
isResizing = true
|
|
140
271
|
resizeDir = direction
|
|
141
|
-
resizeStartX =
|
|
142
|
-
resizeStartY =
|
|
272
|
+
resizeStartX = e.clientX
|
|
273
|
+
resizeStartY = e.clientY
|
|
143
274
|
resizeStartW = winWidth.value
|
|
144
275
|
resizeStartH = winHeight.value
|
|
145
276
|
resizeStartPosX = posX.value
|
|
@@ -148,18 +279,20 @@ function onResizeStart(e: MouseEvent | TouchEvent, direction: ResizeDirection) {
|
|
|
148
279
|
addListeners()
|
|
149
280
|
}
|
|
150
281
|
|
|
151
|
-
function onPointerMove(e:
|
|
152
|
-
e.
|
|
153
|
-
const
|
|
282
|
+
function onPointerMove(e: PointerEvent) {
|
|
283
|
+
const x = e.clientX
|
|
284
|
+
const y = e.clientY
|
|
154
285
|
|
|
155
286
|
if (isDragging) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
287
|
+
pointerLocal = { x: x - parentLeft, y: y - parentTop }
|
|
288
|
+
if (restoreOnMove) {
|
|
289
|
+
if (Math.hypot(x - dragStartX, y - dragStartY) < DETACH_DISTANCE) return
|
|
290
|
+
restoreUnderPointer()
|
|
291
|
+
}
|
|
292
|
+
snapTarget.value = snapAt(e)
|
|
293
|
+
if (anchor) return positionFromAnchor()
|
|
294
|
+
posX.value = clampLeft(dragStartPosX + x - dragStartX, winWidth.value)
|
|
295
|
+
posY.value = clampTop(dragStartPosY + y - dragStartY, minimized.value ? BAR : winHeight.value)
|
|
163
296
|
}
|
|
164
297
|
|
|
165
298
|
if (isResizing) {
|
|
@@ -167,8 +300,9 @@ function onPointerMove(e: MouseEvent | TouchEvent) {
|
|
|
167
300
|
const dy = y - resizeStartY
|
|
168
301
|
const dir = resizeDir
|
|
169
302
|
const parent = windowRef.value?.parentElement
|
|
170
|
-
|
|
171
|
-
const
|
|
303
|
+
// With `offscreen` the right/bottom/left edges may grow past the parent too.
|
|
304
|
+
const parentW = parent && !props.offscreen ? parent.clientWidth : Infinity
|
|
305
|
+
const parentH = parent && !props.offscreen ? parent.clientHeight : Infinity
|
|
172
306
|
|
|
173
307
|
const clampW = (w: number) => Math.min(props.maxWidth ?? Infinity, Math.max(props.minWidth, w))
|
|
174
308
|
const clampH = (h: number) => Math.min(props.maxHeight ?? Infinity, Math.max(props.minHeight, h))
|
|
@@ -177,22 +311,78 @@ function onPointerMove(e: MouseEvent | TouchEvent) {
|
|
|
177
311
|
winWidth.value = Math.min(parentW - resizeStartPosX, clampW(resizeStartW + dx))
|
|
178
312
|
}
|
|
179
313
|
if (dir.includes('w')) {
|
|
180
|
-
const newW =
|
|
181
|
-
|
|
314
|
+
const newW = props.offscreen
|
|
315
|
+
? clampW(resizeStartW - dx)
|
|
316
|
+
: Math.min(resizeStartPosX + resizeStartW, clampW(resizeStartW - dx))
|
|
317
|
+
posX.value = props.offscreen ? resizeStartPosX + (resizeStartW - newW) : Math.max(0, resizeStartPosX + (resizeStartW - newW))
|
|
182
318
|
winWidth.value = newW
|
|
183
319
|
}
|
|
184
320
|
if (dir.includes('s')) {
|
|
185
321
|
winHeight.value = Math.min(parentH - resizeStartPosY, clampH(resizeStartH + dy))
|
|
186
322
|
}
|
|
323
|
+
if (dir.includes('n')) {
|
|
324
|
+
// The bottom edge stays put: grow upward, never past the parent's top.
|
|
325
|
+
const newH = Math.min(resizeStartPosY + resizeStartH, clampH(resizeStartH - dy))
|
|
326
|
+
posY.value = Math.max(0, resizeStartPosY + (resizeStartH - newH))
|
|
327
|
+
winHeight.value = newH
|
|
328
|
+
}
|
|
187
329
|
}
|
|
188
330
|
}
|
|
189
331
|
|
|
190
332
|
function onPointerUp() {
|
|
333
|
+
const target = isDragging ? snapTarget.value : null
|
|
191
334
|
isDragging = false
|
|
192
335
|
isResizing = false
|
|
336
|
+
dragging.value = false
|
|
337
|
+
restoreOnMove = false
|
|
338
|
+
snapTarget.value = null
|
|
339
|
+
// A restore still easing keeps its anchor until it ends (stepRestore clears it).
|
|
340
|
+
if (!sizeAnim) anchor = null
|
|
193
341
|
removeListeners()
|
|
342
|
+
if (target) snapTo(target)
|
|
194
343
|
}
|
|
195
344
|
|
|
345
|
+
function snapTo(target: 'top' | 'left' | 'right') {
|
|
346
|
+
cancelAnimationFrame(sizeRaf)
|
|
347
|
+
sizeAnim = null
|
|
348
|
+
anchor = null
|
|
349
|
+
restoreBox = { ...preDragBox }
|
|
350
|
+
animateGeometry()
|
|
351
|
+
minimized.value = false
|
|
352
|
+
if (target === 'top') {
|
|
353
|
+
tiled.value = null
|
|
354
|
+
maximized.value = true
|
|
355
|
+
fillParent()
|
|
356
|
+
emit('maximize', true)
|
|
357
|
+
} else {
|
|
358
|
+
maximized.value = false
|
|
359
|
+
tiled.value = target
|
|
360
|
+
fillHalf()
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function fillHalf() {
|
|
365
|
+
const parent = windowRef.value?.parentElement
|
|
366
|
+
if (!parent) return
|
|
367
|
+
winWidth.value = Math.floor(parent.clientWidth / 2)
|
|
368
|
+
winHeight.value = parent.clientHeight
|
|
369
|
+
posX.value = tiled.value === 'right' ? parent.clientWidth - winWidth.value : 0
|
|
370
|
+
posY.value = 0
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** The snap preview, in the parent's coordinates, inset like GNOME's. */
|
|
374
|
+
const snapRect = computed(() => {
|
|
375
|
+
const parent = parentEl.value
|
|
376
|
+
if (!parent || !snapTarget.value) return undefined
|
|
377
|
+
const w = parent.clientWidth
|
|
378
|
+
const h = parent.clientHeight
|
|
379
|
+
const gap = 8
|
|
380
|
+
const half = (w - gap * 3) / 2
|
|
381
|
+
const left = snapTarget.value === 'right' ? gap * 2 + half : gap
|
|
382
|
+
const width = snapTarget.value === 'top' ? w - gap * 2 : half
|
|
383
|
+
return { left: `${left}px`, top: `${gap}px`, width: `${width}px`, height: `${h - gap * 2}px`, zIndex: zIndex.value - 1 }
|
|
384
|
+
})
|
|
385
|
+
|
|
196
386
|
// ---- Actions ----
|
|
197
387
|
function close() {
|
|
198
388
|
emit('update:modelValue', false)
|
|
@@ -203,40 +393,99 @@ function close() {
|
|
|
203
393
|
winWidth.value = parseInt(props.width) || 400
|
|
204
394
|
winHeight.value = parseInt(props.height) || 300
|
|
205
395
|
minimized.value = false
|
|
396
|
+
maximized.value = false
|
|
397
|
+
tiled.value = null
|
|
206
398
|
}
|
|
207
399
|
}
|
|
208
400
|
|
|
209
401
|
function toggleMinimize() {
|
|
402
|
+
// The height animates between the window's and the title bar's (see animateGeometry); the
|
|
403
|
+
// body stays rendered during it so the content is folded away rather than vanishing first.
|
|
404
|
+
animateGeometry()
|
|
210
405
|
minimized.value = !minimized.value
|
|
211
406
|
emit('minimize')
|
|
212
407
|
}
|
|
213
408
|
|
|
409
|
+
function animateGeometry() {
|
|
410
|
+
animatingGeometry.value = true
|
|
411
|
+
clearTimeout(geometryTimer)
|
|
412
|
+
geometryTimer = setTimeout(() => (animatingGeometry.value = false), 300)
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function toggleMaximize() {
|
|
416
|
+
if (!props.maximizable) return
|
|
417
|
+
const parent = windowRef.value?.parentElement
|
|
418
|
+
if (!parent) return
|
|
419
|
+
animateGeometry()
|
|
420
|
+
if (!maximized.value) {
|
|
421
|
+
// From a half snap, keep the size it had before snapping as the one to restore.
|
|
422
|
+
if (!tiled.value) restoreBox = { x: posX.value, y: posY.value, w: winWidth.value, h: winHeight.value }
|
|
423
|
+
tiled.value = null
|
|
424
|
+
minimized.value = false
|
|
425
|
+
maximized.value = true
|
|
426
|
+
fillParent()
|
|
427
|
+
} else {
|
|
428
|
+
maximized.value = false
|
|
429
|
+
posX.value = restoreBox.x
|
|
430
|
+
posY.value = restoreBox.y
|
|
431
|
+
winWidth.value = restoreBox.w
|
|
432
|
+
winHeight.value = restoreBox.h
|
|
433
|
+
clampToParent()
|
|
434
|
+
}
|
|
435
|
+
bringToFront()
|
|
436
|
+
emit('maximize', maximized.value)
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function fillParent() {
|
|
440
|
+
const parent = windowRef.value?.parentElement
|
|
441
|
+
if (!parent) return
|
|
442
|
+
posX.value = 0
|
|
443
|
+
posY.value = 0
|
|
444
|
+
winWidth.value = parent.clientWidth
|
|
445
|
+
winHeight.value = parent.clientHeight
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function onTitleBarDoubleClick(e: MouseEvent) {
|
|
449
|
+
if ((e.target as HTMLElement).closest('button')) return
|
|
450
|
+
toggleMaximize()
|
|
451
|
+
}
|
|
452
|
+
|
|
214
453
|
// ---- Focus on click ----
|
|
215
|
-
function
|
|
454
|
+
function onWindowPointerDown() {
|
|
216
455
|
bringToFront()
|
|
217
456
|
}
|
|
218
457
|
|
|
219
458
|
// ---- Clamp to parent ----
|
|
220
459
|
function clampToParent() {
|
|
460
|
+
if (maximized.value) return fillParent()
|
|
461
|
+
if (tiled.value) return fillHalf()
|
|
221
462
|
const parent = windowRef.value?.parentElement
|
|
222
463
|
if (!parent) return
|
|
223
464
|
const pw = parent.clientWidth
|
|
224
465
|
const ph = parent.clientHeight
|
|
225
466
|
if (winWidth.value > pw) winWidth.value = Math.max(props.minWidth, pw)
|
|
226
467
|
if (winHeight.value > ph) winHeight.value = Math.max(props.minHeight, ph)
|
|
227
|
-
|
|
228
|
-
|
|
468
|
+
posX.value = clampLeft(posX.value, winWidth.value)
|
|
469
|
+
posY.value = clampTop(posY.value, minimized.value ? BAR : winHeight.value)
|
|
229
470
|
}
|
|
230
471
|
|
|
231
472
|
let resizeObserver: ResizeObserver | null = null
|
|
232
473
|
|
|
474
|
+
// Keeps following the parent's size, also for windows that open after mounting.
|
|
475
|
+
function watchParent() {
|
|
476
|
+
const parent = windowRef.value?.parentElement ?? null
|
|
477
|
+
if (!parent || parent === parentEl.value) return
|
|
478
|
+
parentEl.value = parent
|
|
479
|
+
resizeObserver?.disconnect()
|
|
480
|
+
if (typeof ResizeObserver === 'undefined') return
|
|
481
|
+
resizeObserver = new ResizeObserver(clampToParent)
|
|
482
|
+
resizeObserver.observe(parent)
|
|
483
|
+
}
|
|
484
|
+
|
|
233
485
|
onMounted(() => {
|
|
486
|
+
watchParent()
|
|
234
487
|
clampToParent()
|
|
235
|
-
|
|
236
|
-
if (parent) {
|
|
237
|
-
resizeObserver = new ResizeObserver(clampToParent)
|
|
238
|
-
resizeObserver.observe(parent)
|
|
239
|
-
}
|
|
488
|
+
if (props.modelValue) bringToFront()
|
|
240
489
|
})
|
|
241
490
|
|
|
242
491
|
// ---- Sync initial props ----
|
|
@@ -250,17 +499,37 @@ watch(
|
|
|
250
499
|
)
|
|
251
500
|
watch(
|
|
252
501
|
() => props.modelValue,
|
|
253
|
-
(v) => {
|
|
502
|
+
(v) => {
|
|
503
|
+
if (!v) return
|
|
504
|
+
bringToFront()
|
|
505
|
+
nextTick(() => {
|
|
506
|
+
watchParent()
|
|
507
|
+
clampToParent()
|
|
508
|
+
})
|
|
509
|
+
},
|
|
254
510
|
)
|
|
255
511
|
|
|
256
512
|
// ---- Cleanup ----
|
|
257
513
|
onUnmounted(() => {
|
|
258
514
|
removeListeners()
|
|
515
|
+
clearTimeout(geometryTimer)
|
|
516
|
+
cancelAnimationFrame(sizeRaf)
|
|
517
|
+
if (activeWindowId.value === id) activeWindowId.value = null
|
|
259
518
|
resizeObserver?.disconnect()
|
|
260
519
|
})
|
|
261
520
|
|
|
521
|
+
defineExpose({
|
|
522
|
+
/** Brings the window to the front, e.g. from a taskbar. */
|
|
523
|
+
focus: bringToFront,
|
|
524
|
+
toggleMaximize,
|
|
525
|
+
toggleMinimize,
|
|
526
|
+
})
|
|
527
|
+
|
|
262
528
|
// Resize handle definitions
|
|
263
529
|
const resizeHandles: { dir: ResizeDirection; class: string; cursor: string }[] = [
|
|
530
|
+
{ dir: 'n', class: 'top-0 left-[20px] right-[20px] h-[6px]', cursor: 'cursor-ns-resize' },
|
|
531
|
+
{ dir: 'ne', class: 'top-0 right-0 w-[16px] h-[16px]', cursor: 'cursor-nesw-resize' },
|
|
532
|
+
{ dir: 'nw', class: 'top-0 left-0 w-[16px] h-[16px]', cursor: 'cursor-nwse-resize' },
|
|
264
533
|
{ dir: 's', class: 'bottom-0 left-[20px] right-[20px] h-[8px]', cursor: 'cursor-ns-resize' },
|
|
265
534
|
{ dir: 'e', class: 'top-[20px] right-0 bottom-[20px] w-[8px]', cursor: 'cursor-ew-resize' },
|
|
266
535
|
{ dir: 'w', class: 'top-[20px] left-0 bottom-[20px] w-[8px]', cursor: 'cursor-ew-resize' },
|
|
@@ -270,65 +539,195 @@ const resizeHandles: { dir: ResizeDirection; class: string; cursor: string }[] =
|
|
|
270
539
|
</script>
|
|
271
540
|
|
|
272
541
|
<template>
|
|
273
|
-
<
|
|
274
|
-
v-if="modelValue"
|
|
275
|
-
ref="windowRef"
|
|
276
|
-
class="absolute flex flex-col rounded-xl bg-surface shadow-elevation-3 overflow-hidden"
|
|
277
|
-
:style="windowStyle"
|
|
278
|
-
@mousedown="onWindowMouseDown"
|
|
279
|
-
>
|
|
280
|
-
<!-- Title bar -->
|
|
542
|
+
<Transition name="m3-window">
|
|
281
543
|
<div
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
544
|
+
v-if="modelValue"
|
|
545
|
+
ref="windowRef"
|
|
546
|
+
role="dialog"
|
|
547
|
+
:aria-label="title"
|
|
548
|
+
class="absolute flex flex-col overflow-hidden bg-surface transition-shadow duration-200"
|
|
549
|
+
:class="[
|
|
550
|
+
snapped ? 'rounded-none' : 'rounded-xl',
|
|
551
|
+
dragging ? 'shadow-elevation-4' : active ? 'shadow-elevation-3' : 'shadow-elevation-1',
|
|
552
|
+
animatingGeometry && 'm3-window-geometry',
|
|
553
|
+
]"
|
|
554
|
+
:style="windowStyle"
|
|
555
|
+
@pointerdown="onWindowPointerDown"
|
|
286
556
|
>
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
@
|
|
300
|
-
>
|
|
301
|
-
<MIcon :name="minimized ? 'open_in_full' : 'minimize'" :size="16" />
|
|
302
|
-
</button>
|
|
303
|
-
|
|
304
|
-
<button
|
|
305
|
-
v-if="closable"
|
|
306
|
-
class="text-on-surface-variant hover:bg-error/12 hover:text-error rounded-full w-7 h-7 flex items-center justify-center transition-colors"
|
|
307
|
-
@click="close"
|
|
557
|
+
<!--
|
|
558
|
+
Title bar. Not an M3 spec component (M3 has no window); built from its pieces: the front
|
|
559
|
+
window's bar is surface-container-high with on-surface text, the ones behind step back
|
|
560
|
+
to surface-container / on-surface-variant at elevation 1, like a desktop's focus cue.
|
|
561
|
+
-->
|
|
562
|
+
<div
|
|
563
|
+
class="flex h-10 shrink-0 select-none items-center gap-1 pr-1.5 pl-4 transition-colors duration-200"
|
|
564
|
+
:class="[
|
|
565
|
+
active ? 'bg-surface-container-high' : 'bg-surface-container',
|
|
566
|
+
draggable ? 'cursor-move touch-none' : '',
|
|
567
|
+
]"
|
|
568
|
+
@pointerdown="onTitleBarStart"
|
|
569
|
+
@dblclick="onTitleBarDoubleClick"
|
|
308
570
|
>
|
|
309
|
-
<
|
|
310
|
-
|
|
571
|
+
<slot name="header">
|
|
572
|
+
<MIcon
|
|
573
|
+
v-if="icon"
|
|
574
|
+
:name="icon"
|
|
575
|
+
:size="18"
|
|
576
|
+
class="mr-1 shrink-0 transition-colors duration-200"
|
|
577
|
+
:class="active ? 'text-primary' : 'text-on-surface-variant'"
|
|
578
|
+
/>
|
|
579
|
+
<span
|
|
580
|
+
class="flex-1 truncate text-title-small font-medium transition-colors duration-200"
|
|
581
|
+
:class="active ? 'text-on-surface' : 'text-on-surface-variant'"
|
|
582
|
+
>
|
|
583
|
+
{{ title }}
|
|
584
|
+
</span>
|
|
585
|
+
</slot>
|
|
586
|
+
|
|
587
|
+
<slot name="actions" />
|
|
588
|
+
|
|
589
|
+
<button
|
|
590
|
+
v-if="minimizable"
|
|
591
|
+
type="button"
|
|
592
|
+
class="m3-window-btn"
|
|
593
|
+
:aria-label="minimized ? locale.windowRestore : locale.windowMinimize"
|
|
594
|
+
:title="minimized ? locale.windowRestore : locale.windowMinimize"
|
|
595
|
+
@click="toggleMinimize"
|
|
596
|
+
>
|
|
597
|
+
<MIcon :name="minimized ? 'expand_content' : 'minimize'" :size="18" />
|
|
598
|
+
</button>
|
|
599
|
+
|
|
600
|
+
<button
|
|
601
|
+
v-if="maximizable"
|
|
602
|
+
type="button"
|
|
603
|
+
class="m3-window-btn"
|
|
604
|
+
:aria-label="maximized ? locale.windowRestore : locale.windowMaximize"
|
|
605
|
+
:title="maximized ? locale.windowRestore : locale.windowMaximize"
|
|
606
|
+
@click="toggleMaximize"
|
|
607
|
+
>
|
|
608
|
+
<MIcon :name="maximized ? 'close_fullscreen' : 'open_in_full'" :size="16" />
|
|
609
|
+
</button>
|
|
610
|
+
|
|
611
|
+
<button
|
|
612
|
+
v-if="closable"
|
|
613
|
+
type="button"
|
|
614
|
+
class="m3-window-btn m3-window-btn-close"
|
|
615
|
+
:aria-label="locale.close"
|
|
616
|
+
:title="locale.close"
|
|
617
|
+
@click="close"
|
|
618
|
+
>
|
|
619
|
+
<MIcon name="close" :size="18" />
|
|
620
|
+
</button>
|
|
621
|
+
</div>
|
|
622
|
+
|
|
623
|
+
<!-- Body -->
|
|
624
|
+
<div v-show="!minimized || animatingGeometry" class="min-h-0 flex-1 overflow-auto">
|
|
625
|
+
<slot />
|
|
626
|
+
</div>
|
|
627
|
+
|
|
628
|
+
<!-- Snap preview: drawn in the parent, since the window clips its own content. -->
|
|
629
|
+
<Teleport v-if="snap && parentEl" :to="parentEl">
|
|
630
|
+
<Transition name="m3-window-snap">
|
|
631
|
+
<div
|
|
632
|
+
v-if="snapTarget"
|
|
633
|
+
aria-hidden="true"
|
|
634
|
+
class="m3-window-snap-preview pointer-events-none absolute rounded-xl border-2 border-primary/40 bg-primary/12"
|
|
635
|
+
:style="snapRect"
|
|
636
|
+
/>
|
|
637
|
+
</Transition>
|
|
638
|
+
</Teleport>
|
|
639
|
+
|
|
640
|
+
<!-- Resize handles -->
|
|
641
|
+
<template v-if="resizable && !minimized && !snapped">
|
|
642
|
+
<div
|
|
643
|
+
v-for="handle in resizeHandles"
|
|
644
|
+
:key="handle.dir"
|
|
645
|
+
class="absolute touch-none"
|
|
646
|
+
:class="[handle.class, handle.cursor]"
|
|
647
|
+
@pointerdown="onResizeStart($event, handle.dir)"
|
|
648
|
+
/>
|
|
649
|
+
</template>
|
|
311
650
|
</div>
|
|
651
|
+
</Transition>
|
|
652
|
+
</template>
|
|
312
653
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
654
|
+
<style scoped>
|
|
655
|
+
/* 32dp circular buttons with M3 state layers (8% hover, 10% press) and the library's focus ring. */
|
|
656
|
+
.m3-window-btn {
|
|
657
|
+
position: relative;
|
|
658
|
+
display: flex;
|
|
659
|
+
width: 32px;
|
|
660
|
+
height: 32px;
|
|
661
|
+
flex-shrink: 0;
|
|
662
|
+
cursor: pointer;
|
|
663
|
+
align-items: center;
|
|
664
|
+
justify-content: center;
|
|
665
|
+
border-radius: 9999px;
|
|
666
|
+
color: var(--color-on-surface-variant);
|
|
667
|
+
outline: none;
|
|
668
|
+
transition: background-color 150ms, color 150ms;
|
|
669
|
+
}
|
|
670
|
+
.m3-window-btn:hover {
|
|
671
|
+
background-color: color-mix(in srgb, var(--color-on-surface-variant) 8%, transparent);
|
|
672
|
+
}
|
|
673
|
+
.m3-window-btn:active {
|
|
674
|
+
background-color: color-mix(in srgb, var(--color-on-surface-variant) 10%, transparent);
|
|
675
|
+
}
|
|
676
|
+
.m3-window-btn:focus-visible {
|
|
677
|
+
box-shadow: 0 0 0 2px var(--color-secondary);
|
|
678
|
+
}
|
|
679
|
+
.m3-window-btn-close:hover {
|
|
680
|
+
color: var(--color-error);
|
|
681
|
+
background-color: color-mix(in srgb, var(--color-error) 8%, transparent);
|
|
682
|
+
}
|
|
683
|
+
.m3-window-btn-close:active {
|
|
684
|
+
background-color: color-mix(in srgb, var(--color-error) 10%, transparent);
|
|
685
|
+
}
|
|
320
686
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
687
|
+
/* Maximize/restore only: drag and resize write the geometry directly, untransitioned. */
|
|
688
|
+
.m3-window-geometry {
|
|
689
|
+
transition-property: left, top, width, height, box-shadow, border-radius;
|
|
690
|
+
transition-duration: 300ms;
|
|
691
|
+
transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/* Snap preview: glides between targets, fades and grows in (GNOME-like). */
|
|
695
|
+
.m3-window-snap-preview {
|
|
696
|
+
transition:
|
|
697
|
+
left 200ms cubic-bezier(0.2, 0, 0, 1),
|
|
698
|
+
width 200ms cubic-bezier(0.2, 0, 0, 1),
|
|
699
|
+
opacity 150ms linear,
|
|
700
|
+
transform 200ms cubic-bezier(0.2, 0, 0, 1);
|
|
701
|
+
}
|
|
702
|
+
.m3-window-snap-enter-from,
|
|
703
|
+
.m3-window-snap-leave-to {
|
|
704
|
+
opacity: 0;
|
|
705
|
+
transform: scale(0.96);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/* Open: scale up from 92% and fade in (emphasized decelerate); close: quicker, accelerate. */
|
|
709
|
+
.m3-window-enter-active {
|
|
710
|
+
transition:
|
|
711
|
+
opacity 150ms linear,
|
|
712
|
+
transform 300ms cubic-bezier(0.05, 0.7, 0.1, 1);
|
|
713
|
+
}
|
|
714
|
+
.m3-window-leave-active {
|
|
715
|
+
transition:
|
|
716
|
+
opacity 150ms linear,
|
|
717
|
+
transform 200ms cubic-bezier(0.3, 0, 0.8, 0.15);
|
|
718
|
+
}
|
|
719
|
+
.m3-window-enter-from,
|
|
720
|
+
.m3-window-leave-to {
|
|
721
|
+
opacity: 0;
|
|
722
|
+
transform: scale(0.92);
|
|
723
|
+
}
|
|
334
724
|
|
|
725
|
+
@media (prefers-reduced-motion: reduce) {
|
|
726
|
+
.m3-window-geometry,
|
|
727
|
+
.m3-window-snap-preview,
|
|
728
|
+
.m3-window-enter-active,
|
|
729
|
+
.m3-window-leave-active {
|
|
730
|
+
transition: none;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
</style>
|