@witchcraft/layout 0.4.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/dist/runtime/components/FrameDragHandle.vue +3 -3
- package/dist/runtime/components/LayoutDragEdgeGrabbed.vue +3 -3
- package/dist/runtime/components/LayoutDragEdgeHandle.d.vue.ts +2 -2
- package/dist/runtime/components/LayoutDragEdgeHandle.vue +2 -2
- package/dist/runtime/components/LayoutDragEdgeHandle.vue.d.ts +2 -2
- package/dist/runtime/components/LayoutDragEdges.vue +5 -5
- package/dist/runtime/components/LayoutEdgesActiveFrame.vue +2 -2
- package/dist/runtime/components/LayoutFrame.vue +2 -2
- package/dist/runtime/components/LayoutIntersectionHandle.d.vue.ts +2 -2
- package/dist/runtime/components/LayoutIntersectionHandle.vue +2 -2
- package/dist/runtime/components/LayoutIntersectionHandle.vue.d.ts +2 -2
- package/dist/runtime/components/LayoutIntersections.vue +4 -4
- package/dist/runtime/components/LayoutWindow.d.vue.ts +44 -44
- package/dist/runtime/components/LayoutWindow.vue +27 -27
- package/dist/runtime/components/LayoutWindow.vue.d.ts +44 -44
- package/dist/runtime/composables/useFrames.d.ts +107 -109
- package/dist/runtime/composables/useFrames.js +103 -99
- package/dist/runtime/demo/App.vue +16 -16
- package/dist/runtime/demo/DemoControls.d.vue.ts +2 -2
- package/dist/runtime/demo/DemoControls.vue +4 -4
- package/dist/runtime/demo/DemoControls.vue.d.ts +2 -2
- package/dist/runtime/helpers/createZoneSideClipPath.d.ts +2 -2
- package/dist/runtime/helpers/{findFrameDraggableEdges.d.ts → findFrameMoveableEdges.d.ts} +2 -2
- package/dist/runtime/helpers/{findFrameDraggableEdges.js → findFrameMoveableEdges.js} +3 -3
- package/dist/runtime/helpers/{findDraggableEdge.d.ts → findMoveableEdge.d.ts} +1 -1
- package/dist/runtime/helpers/{findDraggableEdge.js → findMoveableEdge.js} +1 -1
- package/dist/runtime/helpers/index.d.ts +2 -2
- package/dist/runtime/helpers/index.js +2 -2
- package/dist/runtime/layout/createSplitDecoFromDrag.d.ts +1 -1
- package/dist/runtime/layout/createSplitDecoFromDrag.js +2 -2
- package/dist/runtime/layout/findSafeSplitEdge.d.ts +1 -1
- package/dist/runtime/layout/findSafeSplitEdge.js +2 -2
- package/dist/runtime/layout/getCloseFrameInfo.js +4 -4
- package/dist/runtime/layout/getFrameRearrangeInfo.d.ts +2 -2
- package/dist/runtime/layout/getFrameRearrangeInfo.js +8 -8
- package/dist/runtime/layout/getFrameSplitInfo.d.ts +1 -1
- package/dist/runtime/layout/getFrameSplitInfo.js +2 -2
- package/dist/runtime/layout/{getFrameDragZones.d.ts → getFrameZones.d.ts} +3 -3
- package/dist/runtime/layout/{getFrameDragZones.js → getFrameZones.js} +1 -1
- package/dist/runtime/layout/{getWindowDragZones.d.ts → getWindowZones.d.ts} +1 -1
- package/dist/runtime/layout/{getWindowDragZones.js → getWindowZones.js} +1 -1
- package/dist/runtime/layout/getZones.d.ts +8 -0
- package/dist/runtime/layout/getZones.js +32 -0
- package/dist/runtime/layout/index.d.ts +3 -3
- package/dist/runtime/layout/index.js +3 -3
- package/dist/runtime/{drag/DragActionHandler.d.ts → move/ActionHandler.d.ts} +18 -21
- package/dist/runtime/{drag/DragActionHandler.js → move/ActionHandler.js} +17 -17
- package/dist/runtime/{drag → move}/CloseAction.d.ts +8 -8
- package/dist/runtime/{drag → move}/CloseAction.js +29 -26
- package/dist/runtime/{drag → move}/FrameDragAction.d.ts +8 -8
- package/dist/runtime/{drag → move}/FrameDragAction.js +23 -21
- package/dist/runtime/{drag/DragDirectionStore.d.ts → move/MoveDirectionStore.d.ts} +4 -4
- package/dist/runtime/{drag/DragDirectionStore.js → move/MoveDirectionStore.js} +9 -9
- package/dist/runtime/{drag → move}/SplitAction.d.ts +9 -9
- package/dist/runtime/{drag → move}/SplitAction.js +46 -43
- package/dist/runtime/{drag → move}/createDefaultHandlers.d.ts +2 -2
- package/dist/runtime/types/index.d.ts +185 -171
- package/dist/runtime/types/index.js +2 -2
- package/dist/runtime/types/vue.d.ts +14 -16
- package/dist/runtime/types/vue.js +1 -1
- package/package.json +1 -1
- package/src/runtime/components/FrameDragHandle.vue +3 -3
- package/src/runtime/components/LayoutDragEdgeGrabbed.vue +3 -3
- package/src/runtime/components/LayoutDragEdgeHandle.vue +4 -4
- package/src/runtime/components/LayoutDragEdges.vue +5 -5
- package/src/runtime/components/LayoutEdgesActiveFrame.vue +2 -2
- package/src/runtime/components/LayoutFrame.vue +2 -2
- package/src/runtime/components/LayoutIntersectionHandle.vue +4 -4
- package/src/runtime/components/LayoutIntersections.vue +4 -4
- package/src/runtime/components/LayoutWindow.vue +32 -32
- package/src/runtime/composables/useFrames.ts +108 -102
- package/src/runtime/demo/App.vue +18 -18
- package/src/runtime/demo/DemoControls.vue +5 -5
- package/src/runtime/helpers/createZoneSideClipPath.ts +2 -2
- package/src/runtime/helpers/{findFrameDraggableEdges.ts → findFrameMoveableEdges.ts} +4 -4
- package/src/runtime/helpers/{findDraggableEdge.ts → findMoveableEdge.ts} +1 -1
- package/src/runtime/helpers/index.ts +2 -2
- package/src/runtime/layout/createSplitDecoFromDrag.ts +2 -2
- package/src/runtime/layout/findSafeSplitEdge.ts +4 -4
- package/src/runtime/layout/getCloseFrameInfo.ts +4 -4
- package/src/runtime/layout/getFrameRearrangeInfo.ts +10 -10
- package/src/runtime/layout/getFrameSplitInfo.ts +5 -5
- package/src/runtime/layout/{getFrameDragZones.ts → getFrameZones.ts} +4 -4
- package/src/runtime/layout/{getWindowDragZones.ts → getWindowZones.ts} +1 -1
- package/src/runtime/layout/getZones.ts +48 -0
- package/src/runtime/layout/index.ts +3 -3
- package/src/runtime/{drag/DragActionHandler.ts → move/ActionHandler.ts} +42 -40
- package/src/runtime/{drag → move}/CloseAction.ts +39 -36
- package/src/runtime/{drag → move}/FrameDragAction.ts +36 -35
- package/src/runtime/{drag/DragDirectionStore.ts → move/MoveDirectionStore.ts} +10 -10
- package/src/runtime/{drag → move}/SplitAction.ts +56 -53
- package/src/runtime/{drag → move}/createDefaultHandlers.ts +2 -2
- package/src/runtime/types/index.ts +80 -69
- package/src/runtime/types/vue.ts +14 -14
- package/dist/runtime/layout/getDragZones.d.ts +0 -8
- package/dist/runtime/layout/getDragZones.js +0 -32
- package/src/runtime/layout/getDragZones.ts +0 -48
- /package/dist/runtime/{drag → move}/createDefaultHandlers.js +0 -0
|
@@ -3,7 +3,6 @@ import { keys } from "@alanscodelog/utils/keys"
|
|
|
3
3
|
import type { Ref } from "vue"
|
|
4
4
|
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue"
|
|
5
5
|
|
|
6
|
-
import { DragDirectionStore } from "../drag/DragDirectionStore.js"
|
|
7
6
|
import { cloneFrame } from "../helpers/cloneFrame.js"
|
|
8
7
|
import { getIntersections } from "../helpers/getIntersections.js"
|
|
9
8
|
import { getVisualEdges } from "../helpers/getVisualEdges.js"
|
|
@@ -12,13 +11,14 @@ import { moveEdge } from "../helpers/moveEdge.js"
|
|
|
12
11
|
import { toWindowCoord } from "../helpers/toWindowCoord.js"
|
|
13
12
|
import { findFramesTouchingEdge } from "../layout/findFramesTouchingEdge.js"
|
|
14
13
|
import { isPointInRect } from "../layout/isPointInRect.js"
|
|
15
|
-
import
|
|
14
|
+
import { MoveDirectionStore } from "../move/MoveDirectionStore.js"
|
|
15
|
+
import type { ActionHandler, ActionHandlerApplyResult, Direction, Edge, EdgeMoveStartData, FrameId, FrameMoveStartData, IntersectionEntry, LayoutFrame, LayoutWindow, MoveState, Orientation, Point } from "../types/index.js"
|
|
16
16
|
|
|
17
17
|
export function useFrames(
|
|
18
18
|
win: Ref<LayoutWindow>,
|
|
19
19
|
handler: ActionHandler
|
|
20
20
|
) {
|
|
21
|
-
const
|
|
21
|
+
const movingEdges = ref<Edge[]>([])
|
|
22
22
|
|
|
23
23
|
// each entry corresponds to the frames touching the corresponding dragging edge
|
|
24
24
|
const touchingFrames = ref<Record<string, LayoutFrame>[]>([])
|
|
@@ -34,31 +34,31 @@ export function useFrames(
|
|
|
34
34
|
|
|
35
35
|
const touchingFramesArrays = computed(() => touchingFrames.value.map(entry => Object.values(entry)))
|
|
36
36
|
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
37
|
+
const isMoving = ref<false | "frame" | "edge">(false)
|
|
38
|
+
const showMoving = ref(false)
|
|
39
|
+
const movePoint = ref<Point | undefined>()
|
|
40
40
|
|
|
41
|
-
const
|
|
41
|
+
const moveDirections = ref<Record<Orientation, Direction | undefined>>({} as any)
|
|
42
42
|
|
|
43
|
-
let
|
|
44
|
-
const
|
|
43
|
+
let moveStartPoint: Point | undefined
|
|
44
|
+
const moveDistance = ref(-1)
|
|
45
45
|
|
|
46
|
-
const
|
|
47
|
-
const
|
|
46
|
+
const movingIntersection = ref<IntersectionEntry | undefined>(undefined)
|
|
47
|
+
const isMovingFromWindowEdge = ref<boolean>(false)
|
|
48
48
|
|
|
49
|
-
const
|
|
49
|
+
const movingFrameId = ref<FrameId | undefined>()
|
|
50
50
|
const eventContext = ref<Record<string, unknown> | undefined>()
|
|
51
51
|
|
|
52
52
|
const frames = computed(() =>
|
|
53
|
-
|
|
53
|
+
isMoving.value && showMoving.value
|
|
54
54
|
? { ...win.value.frames, ...allTouchingFrames.value }
|
|
55
55
|
: win.value.frames
|
|
56
56
|
)
|
|
57
57
|
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
58
|
+
const moveHoveredFrame = computed(() => {
|
|
59
|
+
if (isMoving.value) {
|
|
60
60
|
for (const id of keys(frames.value)) {
|
|
61
|
-
if (isPointInRect(frames.value[id],
|
|
61
|
+
if (isPointInRect(frames.value[id], movePoint.value!)) {
|
|
62
62
|
return frames.value[id]
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -70,77 +70,77 @@ export function useFrames(
|
|
|
70
70
|
const intersections = computed(() => getIntersections(visualEdges.value))
|
|
71
71
|
// avoid expensive calculation of edges when lots of frames are added/removed
|
|
72
72
|
// all at once (e.g. by clicking on some command many times in a row)
|
|
73
|
-
const
|
|
73
|
+
const debounceGetMoveableEdges = debounce((f: LayoutFrame[]) => {
|
|
74
74
|
visualEdges.value = getVisualEdges(f, { includeWindowEdges: true })
|
|
75
75
|
handler.annotateEdges?.(visualEdges.value, f)
|
|
76
76
|
}, 50, {}) as any
|
|
77
77
|
|
|
78
|
-
watch([
|
|
78
|
+
watch([isMoving, frames], () => {
|
|
79
79
|
// let request animation force recalc
|
|
80
|
-
if (
|
|
80
|
+
if (isMoving.value) return
|
|
81
81
|
// otherwise use more performant debounced version
|
|
82
|
-
|
|
82
|
+
debounceGetMoveableEdges(Object.values(frames.value))
|
|
83
83
|
}, { deep: true })
|
|
84
|
-
|
|
84
|
+
debounceGetMoveableEdges(Object.values(frames.value))
|
|
85
85
|
|
|
86
86
|
function forceRecalculateEdges(): void {
|
|
87
87
|
visualEdges.value = getVisualEdges(Object.values(frames.value), { includeWindowEdges: true })
|
|
88
88
|
handler.annotateEdges?.(visualEdges.value, Object.values(frames.value))
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
const
|
|
92
|
-
onUpdate: dir =>
|
|
91
|
+
const moveDirStore = new MoveDirectionStore({
|
|
92
|
+
onUpdate: dir => moveDirections.value = dir
|
|
93
93
|
})
|
|
94
94
|
|
|
95
95
|
const state = computed(() => ({
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
moveDirections: moveDirections.value,
|
|
97
|
+
movePoint: movePoint.value,
|
|
98
|
+
moveDistance: moveDistance.value,
|
|
99
|
+
isMoving: isMoving.value,
|
|
100
|
+
showMoving: showMoving.value,
|
|
101
|
+
movingFrameId: movingFrameId.value,
|
|
102
|
+
movingEdges: movingEdges.value,
|
|
103
|
+
movingIntersection: movingIntersection.value,
|
|
104
104
|
visualEdges: visualEdges.value,
|
|
105
105
|
touchingFrames: touchingFrames.value,
|
|
106
106
|
touchingFramesArrays: touchingFramesArrays.value,
|
|
107
107
|
frames: frames.value,
|
|
108
|
-
|
|
108
|
+
moveHoveredFrame: moveHoveredFrame.value,
|
|
109
109
|
intersections: intersections.value,
|
|
110
|
-
|
|
110
|
+
isMovingFromWindowEdge: isMovingFromWindowEdge.value,
|
|
111
111
|
eventContext: eventContext.value,
|
|
112
112
|
win: win.value
|
|
113
|
-
} satisfies
|
|
113
|
+
} satisfies MoveState))
|
|
114
114
|
|
|
115
115
|
let controller: AbortController
|
|
116
|
-
let
|
|
117
|
-
let
|
|
116
|
+
let moveResolve: ((result: any) => void) | undefined
|
|
117
|
+
let moveResult: any
|
|
118
118
|
|
|
119
119
|
function resetState(): void {
|
|
120
|
-
|
|
120
|
+
moveStartPoint = undefined
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
moveResolve?.(moveResult)
|
|
123
|
+
moveResolve = undefined
|
|
124
|
+
moveResult = undefined
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
126
|
+
movingEdges.value = []
|
|
127
|
+
movingIntersection.value = undefined
|
|
128
|
+
isMoving.value = false
|
|
129
|
+
movePoint.value = undefined
|
|
130
|
+
moveDistance.value = -1
|
|
131
131
|
touchingFrames.value = []
|
|
132
|
-
|
|
132
|
+
movingFrameId.value = undefined
|
|
133
133
|
eventContext.value = undefined
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
moveDirStore.reset()
|
|
135
|
+
showMoving.value = false
|
|
136
136
|
forceRecalculateEdges()
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
function
|
|
139
|
+
function moveStart<T extends "edge" | "frame">(
|
|
140
140
|
e: PointerEvent,
|
|
141
141
|
type: T,
|
|
142
142
|
// someday this will work
|
|
143
|
-
data: T extends "edge" ?
|
|
143
|
+
data: T extends "edge" ? EdgeMoveStartData : FrameMoveStartData,
|
|
144
144
|
{
|
|
145
145
|
moveEvent = "pointermove",
|
|
146
146
|
endEvent = "pointerup",
|
|
@@ -157,40 +157,40 @@ export function useFrames(
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
const promise = new Promise<any>(resolve => {
|
|
160
|
-
|
|
160
|
+
moveResolve = resolve
|
|
161
161
|
})
|
|
162
162
|
|
|
163
163
|
controller = new AbortController()
|
|
164
164
|
controller.signal.addEventListener("abort", () => resetState())
|
|
165
165
|
|
|
166
166
|
e.preventDefault()
|
|
167
|
-
window.addEventListener(moveEvent,
|
|
168
|
-
window.addEventListener(endEvent,
|
|
167
|
+
window.addEventListener(moveEvent, onMove as EventListener, { signal: controller.signal })
|
|
168
|
+
window.addEventListener(endEvent, moveEnd as EventListener, { signal: controller.signal })
|
|
169
169
|
|
|
170
170
|
const point = toWindowCoord(win.value, e)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
movePoint.value = point
|
|
172
|
+
moveStartPoint = { ...point }
|
|
173
|
+
moveDirStore.update(point)
|
|
174
174
|
eventContext.value = context
|
|
175
175
|
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
isMoving.value = type
|
|
177
|
+
showMoving.value = true
|
|
178
178
|
|
|
179
179
|
if (type === "frame") {
|
|
180
|
-
|
|
180
|
+
movingFrameId.value = (data as FrameMoveStartData).frameId
|
|
181
181
|
} else {
|
|
182
|
-
const { edge, intersection } = data as
|
|
183
|
-
|
|
182
|
+
const { edge, intersection } = data as EdgeMoveStartData
|
|
183
|
+
movingIntersection.value = intersection
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
movingEdges.value = edge
|
|
186
186
|
? [edge!]
|
|
187
187
|
: [
|
|
188
|
-
...(
|
|
189
|
-
...(
|
|
188
|
+
...(movingIntersection.value?.sharedEdges.horizontal ?? []),
|
|
189
|
+
...(movingIntersection.value?.sharedEdges.vertical ?? [])
|
|
190
190
|
]
|
|
191
191
|
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
isMovingFromWindowEdge.value = movingEdges.value.some(_ => isWindowEdge(_))
|
|
194
194
|
|
|
195
195
|
const framesArray = Object.values(win.value.frames)
|
|
196
196
|
|
|
@@ -198,10 +198,10 @@ export function useFrames(
|
|
|
198
198
|
// all frames in touchingFrames must be clones
|
|
199
199
|
// BUT they must be the same clone even if they are referenced by multiple dragging edges
|
|
200
200
|
const clones = new Map<string, LayoutFrame>()
|
|
201
|
-
for (let i = 0; i <
|
|
202
|
-
const
|
|
201
|
+
for (let i = 0; i < movingEdges.value.length; i++) {
|
|
202
|
+
const movingEdge = movingEdges.value[i]
|
|
203
203
|
touchingFrames.value[i] = {}
|
|
204
|
-
for (const { frame } of findFramesTouchingEdge(
|
|
204
|
+
for (const { frame } of findFramesTouchingEdge(movingEdge, framesArray)) {
|
|
205
205
|
if (!clones.has(frame.id)) {
|
|
206
206
|
const clone = cloneFrame(frame)
|
|
207
207
|
touchingFrames.value[i][frame.id] = clone
|
|
@@ -213,36 +213,36 @@ export function useFrames(
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
const res = handler.
|
|
217
|
-
|
|
216
|
+
const res = handler.onMoveChange("start", e, state.value, forceRecalculateEdges, cancel, resolve)
|
|
217
|
+
showMoving.value = res.showMoving ?? true
|
|
218
218
|
return promise
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
function
|
|
221
|
+
function onMove(e: PointerEvent): void {
|
|
222
222
|
e.preventDefault()
|
|
223
223
|
const point = toWindowCoord(win.value, e)
|
|
224
|
-
const didChange =
|
|
225
|
-
|
|
224
|
+
const didChange = moveDirStore.update(point)
|
|
225
|
+
movePoint.value = point
|
|
226
226
|
// at least one drag move has happened
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
Math.pow(point.x -
|
|
227
|
+
moveDistance.value = 0
|
|
228
|
+
if (moveStartPoint) {
|
|
229
|
+
moveDistance.value = Math.sqrt(
|
|
230
|
+
Math.pow(point.x - moveStartPoint.x, 2) + Math.pow(point.y - moveStartPoint.y, 2)
|
|
231
231
|
)
|
|
232
232
|
}
|
|
233
233
|
if (!didChange) return
|
|
234
|
-
const res = handler.
|
|
234
|
+
const res = handler.onMoveChange("move", e, state.value, forceRecalculateEdges, cancel, resolve)
|
|
235
235
|
|
|
236
236
|
|
|
237
|
-
|
|
237
|
+
showMoving.value = res.showMoving ?? true
|
|
238
238
|
if (!res.updateEdges) return
|
|
239
239
|
|
|
240
|
-
if (
|
|
240
|
+
if (isMoving.value === "edge") {
|
|
241
241
|
requestAnimationFrame(() => {
|
|
242
|
-
for (let i = 0; i <
|
|
243
|
-
const
|
|
244
|
-
if (
|
|
245
|
-
moveEdge(touchingFramesArrays.value[i],
|
|
242
|
+
for (let i = 0; i < movingEdges.value.length; i++) {
|
|
243
|
+
const movingEdge = movingEdges.value[i]
|
|
244
|
+
if (movingEdge) {
|
|
245
|
+
moveEdge(touchingFramesArrays.value[i], movingEdge, point)
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
forceRecalculateEdges()
|
|
@@ -250,15 +250,15 @@ export function useFrames(
|
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
function
|
|
253
|
+
function moveEnd(e?: PointerEvent, { apply = true }: Partial<Pick<ActionHandlerApplyResult, "apply">> = {}): void {
|
|
254
254
|
if (e) {
|
|
255
255
|
const point = toWindowCoord(win.value, e)
|
|
256
|
-
|
|
256
|
+
movePoint.value = point
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
if (apply) {
|
|
260
|
-
const applyResult = handler.
|
|
261
|
-
|
|
260
|
+
const applyResult = handler.onMoveApply(state.value, forceRecalculateEdges)
|
|
261
|
+
moveResult = applyResult.result
|
|
262
262
|
if (applyResult.apply) {
|
|
263
263
|
for (const frame of touchingFramesArrays.value.flat()) {
|
|
264
264
|
win!.value.frames[frame.id] = frame
|
|
@@ -266,15 +266,21 @@ export function useFrames(
|
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
handler.
|
|
269
|
+
handler.onMoveChange("end", e, state.value, forceRecalculateEdges, undefined, undefined)
|
|
270
270
|
|
|
271
271
|
// this can get called from elsewhere
|
|
272
272
|
// also takes care of cleanup nd resolving promise
|
|
273
273
|
controller?.abort()
|
|
274
274
|
}
|
|
275
|
+
|
|
275
276
|
function cancel(): void {
|
|
276
|
-
|
|
277
|
+
moveEnd(undefined, { apply: false })
|
|
278
|
+
}
|
|
279
|
+
function resolve({ apply, result: value }: ActionHandlerApplyResult): void {
|
|
280
|
+
moveResult = value
|
|
281
|
+
moveEnd(undefined, { apply })
|
|
277
282
|
}
|
|
283
|
+
|
|
278
284
|
const keydownController = new AbortController()
|
|
279
285
|
const wrappedKeydownHandler = (e: KeyboardEvent): void => {
|
|
280
286
|
handler.eventHandler(e, state.value, forceRecalculateEdges)
|
|
@@ -290,26 +296,26 @@ export function useFrames(
|
|
|
290
296
|
})
|
|
291
297
|
|
|
292
298
|
return {
|
|
293
|
-
|
|
294
|
-
|
|
299
|
+
moveStart,
|
|
300
|
+
moveEnd,
|
|
295
301
|
cancel,
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
+
onMove,
|
|
303
|
+
moveDirections,
|
|
304
|
+
movePoint,
|
|
305
|
+
isMoving,
|
|
306
|
+
movingEdges,
|
|
307
|
+
movingIntersection,
|
|
302
308
|
visualEdges,
|
|
303
309
|
touchingFrames,
|
|
304
310
|
touchingFramesArrays,
|
|
305
311
|
frames,
|
|
306
|
-
|
|
312
|
+
moveHoveredFrame,
|
|
307
313
|
intersections,
|
|
308
|
-
|
|
314
|
+
isMovingFromWindowEdge,
|
|
309
315
|
forceRecalculateEdges,
|
|
310
316
|
state,
|
|
311
|
-
|
|
312
|
-
|
|
317
|
+
showMoving,
|
|
318
|
+
movingFrameId,
|
|
313
319
|
actionHandler: handler
|
|
314
320
|
}
|
|
315
321
|
}
|
package/src/runtime/demo/App.vue
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
v-if="win"
|
|
11
11
|
:frames="frames!"
|
|
12
12
|
:win="win"
|
|
13
|
-
:
|
|
13
|
+
:actionHandler="actionHandler"
|
|
14
14
|
/>
|
|
15
15
|
|
|
16
16
|
<LayoutWindow
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
:textHints="textHints"
|
|
34
34
|
textHintsTeleportTo="#status-bar"
|
|
35
35
|
v-model:win="win"
|
|
36
|
-
@is-showing-
|
|
37
|
-
@
|
|
36
|
+
@is-showing-move="isShowingMove = $event"
|
|
37
|
+
@move-state="moveState = $event"
|
|
38
38
|
>
|
|
39
39
|
<LayoutFrame class="
|
|
40
40
|
flex
|
|
@@ -163,7 +163,7 @@ import LayoutIntersections from "../components/LayoutIntersections.vue"
|
|
|
163
163
|
import LayoutEdgesActiveFrame from "../components/LayoutEdgesActiveFrame.vue"
|
|
164
164
|
import LayoutDragEdges from "../components/LayoutDragEdges.vue"
|
|
165
165
|
import LayoutIntersectionHandle from "../components/LayoutIntersectionHandle.vue"
|
|
166
|
-
import type {
|
|
166
|
+
import type { MoveState } from "../types/index.js"
|
|
167
167
|
import { applyFrameChanges } from "../layout/applyFrameChanges.js"
|
|
168
168
|
import { debugFrame } from "../layout/debugFrame.js"
|
|
169
169
|
import { getFrameCollapseInfo } from "../layout/getFrameCollapseInfo.js"
|
|
@@ -179,7 +179,7 @@ import { settings } from "../settings.js"
|
|
|
179
179
|
import type { EdgeSide, Layout, Pos, Size } from "../types/index.js"
|
|
180
180
|
import { throwIfError } from "@alanscodelog/utils/throwIfError"
|
|
181
181
|
import { useTemplateRef } from "vue"
|
|
182
|
-
import {
|
|
182
|
+
import { ActionHandler } from "../move/ActionHandler.js"
|
|
183
183
|
import LayoutDragEdgeHandle from "../components/LayoutDragEdgeHandle.vue"
|
|
184
184
|
import LayoutDragEdgeVisible from "../components/LayoutDragEdgeVisible.vue"
|
|
185
185
|
import LayoutIntersectionVisible from "../components/LayoutIntersectionVisible.vue"
|
|
@@ -228,30 +228,30 @@ function layoutInitialize(layout: Layout, { defaultPos, defaultSize }: {
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
// whether layout window is showing the edge beneath the mouse
|
|
231
|
-
// as determined by the
|
|
232
|
-
const
|
|
231
|
+
// as determined by the ActionHandler in LayoutWindow
|
|
232
|
+
const isShowingMove = ref(false)
|
|
233
233
|
// drag state as returned by useFrames in LayoutWindow
|
|
234
|
-
const
|
|
234
|
+
const moveState = ref<MoveState | undefined>(undefined)
|
|
235
235
|
|
|
236
236
|
function handleUndock(frameId: string) {
|
|
237
237
|
const changes = throwIfError(getFrameUndockInfo(win.value!, frameId))
|
|
238
|
-
|
|
238
|
+
ActionHandler.debugState("undock", "before", moveState.value!, {}, undefined)
|
|
239
239
|
applyFrameChanges(win.value!, changes)
|
|
240
|
-
|
|
240
|
+
ActionHandler.debugState("undock", "after", moveState.value!, {}, undefined)
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
function handleCollapse(frameId: string) {
|
|
244
244
|
const changes = throwIfError(getFrameCollapseInfo(win.value!, frameId))
|
|
245
|
-
|
|
245
|
+
ActionHandler.debugState("collapse", "before", moveState.value!, {}, undefined)
|
|
246
246
|
applyFrameChanges(win.value!, changes)
|
|
247
|
-
|
|
247
|
+
ActionHandler.debugState("collapse", "after", moveState.value!, {}, undefined)
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
function handleUncollapse(frameId: string) {
|
|
251
251
|
const changes = throwIfError(getFrameUncollapseInfo(win.value!, frameId))
|
|
252
|
-
|
|
252
|
+
ActionHandler.debugState("uncollapse", "before", moveState.value!, {}, undefined)
|
|
253
253
|
applyFrameChanges(win.value!, changes)
|
|
254
|
-
|
|
254
|
+
ActionHandler.debugState("uncollapse", "after", moveState.value!, {}, undefined)
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
const collapsedDocks = computed(() => {
|
|
@@ -264,13 +264,13 @@ const collapsedDocks = computed(() => {
|
|
|
264
264
|
return sides
|
|
265
265
|
})
|
|
266
266
|
|
|
267
|
-
const
|
|
267
|
+
const actionHandler = computed(() => layoutComponent.value?.actionHandler)
|
|
268
268
|
|
|
269
269
|
const textHints = computed(() => {
|
|
270
|
-
const
|
|
271
|
-
const textHints =
|
|
270
|
+
const isMoving = moveState.value?.isMoving
|
|
271
|
+
const textHints = actionHandler.value?.textHints ?? {actions:[], errors:[]}
|
|
272
272
|
return [
|
|
273
|
-
...(!
|
|
273
|
+
...(!isMoving ? [{classes:"", text:"Drag from an edge to create a new frame."}] : []),
|
|
274
274
|
...textHints.errors.map((_: string) => ({classes:"text-red-500", text:_})),
|
|
275
275
|
...textHints.actions.map((_: string) => ({ text:_})),
|
|
276
276
|
]
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
<WButton class="flex-1" @click="copyState">Copy State</WButton>
|
|
26
26
|
<WCheckbox v-model="renameFrames">Easy Ids</WCheckbox>
|
|
27
27
|
</div>
|
|
28
|
-
<label class="flex flex-col gap-2 text-sm" v-if="
|
|
28
|
+
<label class="flex flex-col gap-2 text-sm" v-if="actionHandler">
|
|
29
29
|
<span>Plugin Debug Logs (true | debug path):</span>
|
|
30
30
|
<WSimpleInput v-model="debugKey" />
|
|
31
31
|
</label>
|
|
@@ -50,13 +50,13 @@ import { settings } from "../settings.js"
|
|
|
50
50
|
import type { LayoutFrame, LayoutWindow } from "../types/index.js"
|
|
51
51
|
import { throwIfError } from "@alanscodelog/utils/throwIfError";
|
|
52
52
|
import { walk } from "@alanscodelog/utils/walk"
|
|
53
|
-
import type {
|
|
53
|
+
import type { ActionHandler } from "../move/ActionHandler.js"
|
|
54
54
|
import { rotateLayout } from "../helpers/rotateFrames.js"
|
|
55
55
|
|
|
56
56
|
const props = defineProps<{
|
|
57
57
|
win: LayoutWindow
|
|
58
58
|
frames: LayoutFrame[],
|
|
59
|
-
|
|
59
|
+
actionHandler?: ActionHandler<any>
|
|
60
60
|
}>()
|
|
61
61
|
|
|
62
62
|
const showDevActions = ref(false)
|
|
@@ -112,14 +112,14 @@ function copyState() {
|
|
|
112
112
|
|
|
113
113
|
const debugKey = ref(import.meta.dev ? "state.win.frames" : "false")
|
|
114
114
|
watch(debugKey, () => {
|
|
115
|
-
if (!props.
|
|
115
|
+
if (!props.actionHandler) return
|
|
116
116
|
const value = debugKey.value === "true"
|
|
117
117
|
? true
|
|
118
118
|
: debugKey.value === "false"
|
|
119
119
|
? false
|
|
120
120
|
: debugKey.value
|
|
121
121
|
|
|
122
|
-
for (const plugin of Object.values(props.
|
|
122
|
+
for (const plugin of Object.values(props.actionHandler.actions)) {
|
|
123
123
|
plugin.debug = value
|
|
124
124
|
}
|
|
125
125
|
})
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* Accepts scaled coordinates.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { Zone } from "../types/index.js"
|
|
10
10
|
|
|
11
11
|
export function createZoneSideClipPath(
|
|
12
|
-
zone:
|
|
12
|
+
zone: Zone,
|
|
13
13
|
{ frameEdgePx, windowEdgePx }: { frameEdgePx: number, windowEdgePx: number }
|
|
14
14
|
): string | undefined {
|
|
15
15
|
const side = zone.side
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { findMoveableEdge } from "./findMoveableEdge.js"
|
|
2
2
|
import { frameToEdges } from "./frameToEdges.js"
|
|
3
3
|
import { isWindowEdge } from "./isWindowEdge.js"
|
|
4
4
|
import { sideToOrientation } from "./sideToOrientation.js"
|
|
@@ -8,10 +8,10 @@ import type {
|
|
|
8
8
|
EdgeSide, LayoutFrame
|
|
9
9
|
} from "../types/index.js"
|
|
10
10
|
|
|
11
|
-
export function
|
|
11
|
+
export function findFrameMoveableEdges(
|
|
12
12
|
frame: LayoutFrame,
|
|
13
13
|
edges: Edge[],
|
|
14
|
-
/** See {@link
|
|
14
|
+
/** See {@link findMoveableEdge} */
|
|
15
15
|
exact: boolean = true,
|
|
16
16
|
sides: EdgeSide[] = ["left", "right", "top", "bottom"]
|
|
17
17
|
): { edge: Edge, side: EdgeSide }[] | undefined {
|
|
@@ -23,7 +23,7 @@ export function findFrameDraggableEdges(
|
|
|
23
23
|
const isWinEdge = isWindowEdge(edge, edgeDirection)
|
|
24
24
|
|
|
25
25
|
if (isWinEdge) continue
|
|
26
|
-
const maybeEdge =
|
|
26
|
+
const maybeEdge = findMoveableEdge(edge, edges, exact, edgeDirection)
|
|
27
27
|
|
|
28
28
|
if (maybeEdge) res.push({ edge: maybeEdge, side })
|
|
29
29
|
}
|
|
@@ -4,7 +4,7 @@ import { isEdgeEqual } from "./isEdgeEqual.js"
|
|
|
4
4
|
|
|
5
5
|
import type { Edge, Orientation } from "../types/index.js"
|
|
6
6
|
|
|
7
|
-
export function
|
|
7
|
+
export function findMoveableEdge(
|
|
8
8
|
edge: Edge,
|
|
9
9
|
edges: Edge[],
|
|
10
10
|
/** Whether the edge must match exactly and does not "contain/touch" another frame. */
|
|
@@ -23,8 +23,8 @@ export { dirToSide } from "./dirToSide.js"
|
|
|
23
23
|
export { doEdgesOverlap } from "./doEdgesOverlap.js"
|
|
24
24
|
export { doesEdgeContinueEdge } from "./doesEdgeContinueEdge.js"
|
|
25
25
|
export { edgeToPoints } from "./edgeToPoints.js"
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
26
|
+
export { findMoveableEdge } from "./findMoveableEdge.js"
|
|
27
|
+
export { findFrameMoveableEdges } from "./findFrameMoveableEdges.js"
|
|
28
28
|
export { framesRedistributeFix } from "./framesRedistributeFix.js"
|
|
29
29
|
export { frameToEdges } from "./frameToEdges.js"
|
|
30
30
|
export { frameToPoints } from "./frameToPoints.js"
|
|
@@ -8,7 +8,7 @@ export function createSplitDecoFromDrag(
|
|
|
8
8
|
frames: Record<string, LayoutFrame>,
|
|
9
9
|
frame: LayoutFrame,
|
|
10
10
|
dragDirection: Direction,
|
|
11
|
-
|
|
11
|
+
movePoint: Point,
|
|
12
12
|
snapAmount: Point = settings.snapPointScaled,
|
|
13
13
|
minSize: Size = settings.minSizeScaled,
|
|
14
14
|
classes: {
|
|
@@ -22,7 +22,7 @@ export function createSplitDecoFromDrag(
|
|
|
22
22
|
const deco: RawSplitDeco & Partial<SplitDeco> = {
|
|
23
23
|
type: "split",
|
|
24
24
|
id: frame.id,
|
|
25
|
-
position:
|
|
25
|
+
position: movePoint[orientation === "horizontal" ? "x" : "y"],
|
|
26
26
|
direction: dragDirection
|
|
27
27
|
}
|
|
28
28
|
deco.shapes = createSplitDecoShapes(frames, deco, snapAmount, minSize, classes)
|
|
@@ -8,15 +8,15 @@ import type { Direction, Edge, LayoutFrame, Point, Size } from "../types/index.j
|
|
|
8
8
|
export function findSafeSplitEdgeAndPosition(
|
|
9
9
|
frame: LayoutFrame,
|
|
10
10
|
dragDirection: Direction,
|
|
11
|
-
|
|
11
|
+
movePointOrPosition: Point | number,
|
|
12
12
|
snapAmount: Point = settings.snapPointScaled,
|
|
13
13
|
minSize: Size = settings.minSizeScaled
|
|
14
14
|
): { edge: Edge, position: number } {
|
|
15
15
|
const orientation = dirToOrientation(dragDirection)
|
|
16
16
|
const position
|
|
17
|
-
= typeof
|
|
18
|
-
?
|
|
19
|
-
:
|
|
17
|
+
= typeof movePointOrPosition === "number"
|
|
18
|
+
? movePointOrPosition
|
|
19
|
+
: movePointOrPosition[orientation === "horizontal" ? "x" : "y"]
|
|
20
20
|
|
|
21
21
|
const coordKey = orientation === "vertical" ? "y" : "x"
|
|
22
22
|
const sizeKey = orientation === "vertical" ? "height" : "width"
|
|
@@ -7,7 +7,7 @@ import { findVisualEdge } from "./findVisualEdge.js"
|
|
|
7
7
|
|
|
8
8
|
import { cloneFrame } from "../helpers/cloneFrame.js"
|
|
9
9
|
import { dirToSide } from "../helpers/dirToSide.js"
|
|
10
|
-
import {
|
|
10
|
+
import { findFrameMoveableEdges } from "../helpers/findFrameMoveableEdges.js"
|
|
11
11
|
import { getEdgeOrientation } from "../helpers/getEdgeOrientation.js"
|
|
12
12
|
import { oppositeSide } from "../helpers/oppositeSide.js"
|
|
13
13
|
import { settings } from "../settings.js"
|
|
@@ -119,9 +119,9 @@ export function getCloseFrameInfo<T extends "edge" | "dir">(
|
|
|
119
119
|
: closeDirOrSide as EdgeSide
|
|
120
120
|
const sideOpposite = oppositeSide(side)
|
|
121
121
|
|
|
122
|
-
const
|
|
123
|
-
if (!
|
|
124
|
-
const { edge: frameEdge } =
|
|
122
|
+
const moveableEdges = findFrameMoveableEdges(frame, visualEdges, !force, [side])
|
|
123
|
+
if (!moveableEdges) return new KnownError(LAYOUT_ERROR.CANT_CLOSE_NO_DRAG_EDGE, `Could not find draggable edge for frame ${frame.id}`, { frame })
|
|
124
|
+
const { edge: frameEdge } = moveableEdges[0]
|
|
125
125
|
|
|
126
126
|
const visualEdge = findVisualEdge(visualEdges, frameEdge)
|
|
127
127
|
if (visualEdge === undefined) unreachable()
|