@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
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ActionHandler } from "./ActionHandler.js"
|
|
2
2
|
|
|
3
3
|
import { createZoneSideClipPath } from "../helpers/createZoneSideClipPath.js"
|
|
4
4
|
import { applyFrameChanges } from "../layout/applyFrameChanges.js"
|
|
5
|
-
import { getDragZones } from "../layout/getDragZones.js"
|
|
6
5
|
import { getFrameDockInfo } from "../layout/getFrameDockInfo.js"
|
|
7
6
|
import { getFrameRearrangeInfo } from "../layout/getFrameRearrangeInfo.js"
|
|
8
7
|
import { getFrameSwapInfo } from "../layout/getFrameSwapInfo.js"
|
|
8
|
+
import { getZones } from "../layout/getZones.js"
|
|
9
9
|
import { settings } from "../settings.js"
|
|
10
|
-
import type {
|
|
10
|
+
import type { ActionChangeResult, FrameDeco, IAction, LayoutChange, MoveState, Zone } from "../types/index.js"
|
|
11
11
|
import type { KnownError } from "../utils/KnownError.js"
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
export class FrameDragAction implements
|
|
14
|
+
export class FrameDragAction implements IAction {
|
|
15
15
|
name = "frameDrag" as const
|
|
16
16
|
|
|
17
17
|
minDragDistance = 5
|
|
@@ -25,8 +25,8 @@ export class FrameDragAction implements IDragAction {
|
|
|
25
25
|
debug: boolean | string = false
|
|
26
26
|
textHints: { actions: string[], errors: string[] } = { actions: [], errors: [] }
|
|
27
27
|
|
|
28
|
-
handleEvent: (e: PointerEvent | KeyboardEvent, state:
|
|
29
|
-
= (_e: PointerEvent | KeyboardEvent, state:
|
|
28
|
+
handleEvent: (e: PointerEvent | KeyboardEvent, state: MoveState) => boolean
|
|
29
|
+
= (_e: PointerEvent | KeyboardEvent, state: MoveState) => state.isMoving === "frame"
|
|
30
30
|
|
|
31
31
|
dragHints: {
|
|
32
32
|
actions: { split?: string, swap?: string, rearrange?: string, dock?: string } | ((state: { type: "split" | "swap" | "rearrange" | "dock" }) => string[])
|
|
@@ -41,7 +41,7 @@ export class FrameDragAction implements IDragAction {
|
|
|
41
41
|
transformError: e => e.message
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
modifyDecos: (shapes:
|
|
44
|
+
modifyDecos: (shapes: FrameDeco[]) => void = () => { }
|
|
45
45
|
hooks: {
|
|
46
46
|
onStart?: () => void
|
|
47
47
|
onCancel?: () => void
|
|
@@ -101,15 +101,15 @@ export class FrameDragAction implements IDragAction {
|
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
getDecos(
|
|
104
|
-
matchedZone:
|
|
105
|
-
state:
|
|
104
|
+
matchedZone: Zone | undefined,
|
|
105
|
+
state: MoveState,
|
|
106
106
|
result: LayoutChange<"split" | "swap" | "rearrange" | "dock"> | KnownError | undefined
|
|
107
|
-
):
|
|
107
|
+
): FrameDeco[] {
|
|
108
108
|
const isError = result instanceof Error
|
|
109
|
-
const frame = state.
|
|
109
|
+
const frame = state.moveHoveredFrame
|
|
110
110
|
|
|
111
111
|
if (!matchedZone || !frame) {
|
|
112
|
-
const decos:
|
|
112
|
+
const decos: FrameDeco[] = []
|
|
113
113
|
this.modifyDecos(decos)
|
|
114
114
|
return decos
|
|
115
115
|
}
|
|
@@ -120,7 +120,7 @@ export class FrameDragAction implements IDragAction {
|
|
|
120
120
|
? `deco-frame-drag deco-frame-drag-error deco-frame-drag-${matchedZone.type}-${matchedZone.side} bg-red-500/50`
|
|
121
121
|
: `deco-frame-drag deco-frame-drag-${matchedZone.type}-${matchedZone.side} bg-blue-500/50`
|
|
122
122
|
|
|
123
|
-
const decos:
|
|
123
|
+
const decos: FrameDeco[] = [{
|
|
124
124
|
id: frame.id,
|
|
125
125
|
type: "drop",
|
|
126
126
|
position: matchedZone.side ?? "center",
|
|
@@ -139,7 +139,7 @@ export class FrameDragAction implements IDragAction {
|
|
|
139
139
|
return decos
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
canHandleRequest(e: PointerEvent | KeyboardEvent, state:
|
|
142
|
+
canHandleRequest(e: PointerEvent | KeyboardEvent, state: MoveState): boolean {
|
|
143
143
|
const res = this.handleEvent(e, state)
|
|
144
144
|
this.setTextHints(undefined)
|
|
145
145
|
if (res) {
|
|
@@ -150,29 +150,33 @@ export class FrameDragAction implements IDragAction {
|
|
|
150
150
|
return false
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
onMoveChange<T extends "start" | "move" | "end">(
|
|
154
|
+
type: T,
|
|
155
155
|
_e: PointerEvent | undefined,
|
|
156
|
-
state:
|
|
157
|
-
):
|
|
158
|
-
if (
|
|
159
|
-
|
|
156
|
+
state: MoveState
|
|
157
|
+
): ActionChangeResult {
|
|
158
|
+
if (type === "end") {
|
|
159
|
+
this.reset()
|
|
160
|
+
return { shapes: [] }
|
|
161
|
+
}
|
|
162
|
+
if (state.moveDistance <= this.minDragDistance) {
|
|
163
|
+
return { updateEdges: false, shapes: [], showMoving: false }
|
|
160
164
|
}
|
|
161
|
-
const { win,
|
|
162
|
-
const matchedZone =
|
|
165
|
+
const { win, movingFrameId, moveHoveredFrame } = state
|
|
166
|
+
const matchedZone = getZones(state, settings.zoneSizes)
|
|
163
167
|
|
|
164
168
|
if (!matchedZone) {
|
|
165
169
|
this.state.lastReturn = undefined
|
|
166
|
-
} else if (
|
|
170
|
+
} else if (moveHoveredFrame && matchedZone.type === "frame" && matchedZone.side) {
|
|
167
171
|
if (matchedZone.side !== "center") {
|
|
168
|
-
this.state.lastReturn = getFrameRearrangeInfo(win,
|
|
172
|
+
this.state.lastReturn = getFrameRearrangeInfo(win, movingFrameId!, moveHoveredFrame.id!, matchedZone.side)
|
|
169
173
|
} else {
|
|
170
|
-
this.state.lastReturn = getFrameSwapInfo(win,
|
|
174
|
+
this.state.lastReturn = getFrameSwapInfo(win, movingFrameId!, moveHoveredFrame.id!)
|
|
171
175
|
// for the hints
|
|
172
176
|
if (!(this.state.lastReturn instanceof Error)) this.state.lastReturn.info = "swap"
|
|
173
177
|
}
|
|
174
|
-
} else if (matchedZone.type === "window" &&
|
|
175
|
-
this.state.lastReturn = getFrameDockInfo(win,
|
|
178
|
+
} else if (matchedZone.type === "window" && moveHoveredFrame && !moveHoveredFrame.docked) {
|
|
179
|
+
this.state.lastReturn = getFrameDockInfo(win, movingFrameId!, matchedZone.side)
|
|
176
180
|
// for the hints
|
|
177
181
|
if (!(this.state.lastReturn instanceof Error)) this.state.lastReturn.info = "dock"
|
|
178
182
|
}
|
|
@@ -183,27 +187,24 @@ export class FrameDragAction implements IDragAction {
|
|
|
183
187
|
return {
|
|
184
188
|
shapes: decos.flatMap(_ => _.shapes),
|
|
185
189
|
updateEdges: false,
|
|
186
|
-
|
|
190
|
+
showMoving: false
|
|
187
191
|
}
|
|
188
192
|
}
|
|
189
193
|
|
|
190
|
-
|
|
194
|
+
onMoveApply(state: MoveState): boolean {
|
|
191
195
|
const result = this.state.lastReturn
|
|
192
|
-
if (!result || !state.
|
|
193
|
-
this.reset()
|
|
196
|
+
if (!result || !state.moveHoveredFrame || !state.movingFrameId) {
|
|
194
197
|
return true
|
|
195
198
|
}
|
|
196
199
|
|
|
197
|
-
|
|
198
200
|
if (result instanceof Error) {
|
|
199
201
|
this.hooks.onError?.(result)
|
|
200
202
|
} else {
|
|
201
|
-
if (this.debug) {
|
|
203
|
+
if (this.debug) { ActionHandler.debugState(this.name, "before", state, this.state, this.debug) }
|
|
202
204
|
applyFrameChanges(state.win, result)
|
|
203
|
-
if (this.debug) {
|
|
205
|
+
if (this.debug) { ActionHandler.debugState(this.name, "after", state, this.state, this.debug) }
|
|
204
206
|
}
|
|
205
207
|
|
|
206
|
-
this.reset()
|
|
207
208
|
return true
|
|
208
209
|
}
|
|
209
210
|
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { Direction, Orientation, Point } from "../types/index.js"
|
|
2
2
|
|
|
3
|
-
export class
|
|
3
|
+
export class MoveDirectionStore {
|
|
4
4
|
hooks: {
|
|
5
5
|
onUpdate: (directions: Record<Orientation, Direction | undefined>) => void
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
constructor(
|
|
9
|
-
hooks:
|
|
9
|
+
hooks: MoveDirectionStore["hooks"]
|
|
10
10
|
) {
|
|
11
11
|
this.hooks = hooks
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
lastPoint: Point | undefined
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
moveDirection: Record<Orientation, Direction | undefined> = {} as any
|
|
17
17
|
|
|
18
18
|
lesser: { x: Direction, y: Direction } = {
|
|
19
19
|
x: "left",
|
|
@@ -27,20 +27,20 @@ export class DragDirectionStore {
|
|
|
27
27
|
|
|
28
28
|
reset(): void {
|
|
29
29
|
this.lastPoint = undefined
|
|
30
|
-
this.
|
|
30
|
+
this.moveDirection = {} as any
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
update(point: Point): boolean {
|
|
34
34
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
35
|
-
const newXDirection = this.
|
|
35
|
+
const newXDirection = this.getMoveDirection("x", point)
|
|
36
36
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
37
|
-
const newYDirection = this.
|
|
37
|
+
const newYDirection = this.getMoveDirection("y", point)
|
|
38
38
|
let changed = false
|
|
39
39
|
if (newXDirection) {
|
|
40
|
-
this.
|
|
40
|
+
this.moveDirection.horizontal = newXDirection
|
|
41
41
|
}
|
|
42
42
|
if (newYDirection) {
|
|
43
|
-
this.
|
|
43
|
+
this.moveDirection.vertical = newYDirection
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (this.lastPoint?.x !== point.x || this.lastPoint?.y !== point.y) {
|
|
@@ -49,11 +49,11 @@ export class DragDirectionStore {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (!changed) return false
|
|
52
|
-
this.hooks.onUpdate(this.
|
|
52
|
+
this.hooks.onUpdate(this.moveDirection)
|
|
53
53
|
return true
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
getMoveDirection(coord: "x" | "y", point: Point): Direction | false {
|
|
57
57
|
if (!this.lastPoint) return false
|
|
58
58
|
const diff = point[coord] - this.lastPoint![coord]
|
|
59
59
|
if (diff > 0) return this.greater[coord]
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ActionHandler } from "./ActionHandler.js"
|
|
2
2
|
|
|
3
3
|
import { getEdgeOrientation } from "../helpers/getEdgeOrientation.js"
|
|
4
4
|
import { oppositeSide } from "../helpers/oppositeSide.js"
|
|
5
5
|
import { applyFrameChanges } from "../layout/applyFrameChanges.js"
|
|
6
6
|
import { createSplitDecoFromDrag } from "../layout/createSplitDecoFromDrag.js"
|
|
7
7
|
import { getFrameSplitInfo } from "../layout/getFrameSplitInfo.js"
|
|
8
|
-
import type {
|
|
8
|
+
import type { ActionChangeResult, IAction, LayoutShape, MoveState, Point, SplitDeco } from "../types/index.js"
|
|
9
9
|
import type { KnownError } from "../utils/KnownError.js"
|
|
10
10
|
|
|
11
11
|
export type SplitInfo = Exclude<ReturnType<typeof getFrameSplitInfo>, KnownError>
|
|
@@ -14,7 +14,7 @@ export type SplitInfo = Exclude<ReturnType<typeof getFrameSplitInfo>, KnownError
|
|
|
14
14
|
|
|
15
15
|
export type DragChangeType = "start" | "move" | "end"
|
|
16
16
|
|
|
17
|
-
export class SplitAction implements
|
|
17
|
+
export class SplitAction implements IAction {
|
|
18
18
|
name = "split" as const
|
|
19
19
|
minDragDistance = 5
|
|
20
20
|
|
|
@@ -27,7 +27,7 @@ export class SplitAction implements IDragAction {
|
|
|
27
27
|
allowed: false
|
|
28
28
|
res: SplitInfo | undefined
|
|
29
29
|
lastPoint: Point | undefined
|
|
30
|
-
lastReturn:
|
|
30
|
+
lastReturn: ActionChangeResult | undefined
|
|
31
31
|
} = {} as any // this is initialized by `this.reset()`
|
|
32
32
|
|
|
33
33
|
debug: boolean | string = false
|
|
@@ -40,8 +40,8 @@ export class SplitAction implements IDragAction {
|
|
|
40
40
|
transformError: e => e.message
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
handleEvent: (e: PointerEvent | KeyboardEvent, state:
|
|
44
|
-
= (e: PointerEvent | KeyboardEvent, state:
|
|
43
|
+
handleEvent: (e: PointerEvent | KeyboardEvent, state: MoveState) => boolean
|
|
44
|
+
= (e: PointerEvent | KeyboardEvent, state: MoveState) => e.altKey || state.isMovingFromWindowEdge
|
|
45
45
|
|
|
46
46
|
modifyDecos: (shapes: SplitDeco[]) => void = () => { }
|
|
47
47
|
hooks: {
|
|
@@ -83,23 +83,23 @@ export class SplitAction implements IDragAction {
|
|
|
83
83
|
this.modifyDecos([])
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
getDecos(state:
|
|
86
|
+
getDecos(state: MoveState): SplitDeco[] {
|
|
87
87
|
let decos: SplitDeco[] = []
|
|
88
88
|
const {
|
|
89
89
|
win,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
isMoving,
|
|
91
|
+
moveHoveredFrame,
|
|
92
|
+
moveDirections,
|
|
93
|
+
movingEdges,
|
|
94
|
+
movePoint
|
|
95
95
|
} = state
|
|
96
|
-
if (
|
|
97
|
-
const oppositeOrientation = oppositeSide(getEdgeOrientation(
|
|
96
|
+
if (isMoving && this.state.allowed && moveHoveredFrame && movingEdges.length === 1) {
|
|
97
|
+
const oppositeOrientation = oppositeSide(getEdgeOrientation(movingEdges[0]))
|
|
98
98
|
const deco = createSplitDecoFromDrag(
|
|
99
99
|
win.frames,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
moveHoveredFrame,
|
|
101
|
+
moveDirections[oppositeOrientation]!,
|
|
102
|
+
movePoint!
|
|
103
103
|
)
|
|
104
104
|
decos = [deco]
|
|
105
105
|
}
|
|
@@ -107,11 +107,11 @@ export class SplitAction implements IDragAction {
|
|
|
107
107
|
return decos
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
canHandleRequest(e: PointerEvent | KeyboardEvent, state:
|
|
111
|
-
const {
|
|
112
|
-
if (
|
|
110
|
+
canHandleRequest(e: PointerEvent | KeyboardEvent, state: MoveState): boolean {
|
|
111
|
+
const { movingEdges } = state
|
|
112
|
+
if (movingEdges.length !== 1) return false
|
|
113
113
|
// hint should not be shown when dragging from window edge but we should still handle the event
|
|
114
|
-
this.setTextHints(state.
|
|
114
|
+
this.setTextHints(state.isMoving === "edge" && !state.isMovingFromWindowEdge ? true : undefined)
|
|
115
115
|
if (this.handleEvent(e, state)) {
|
|
116
116
|
this.hooks.onStart?.()
|
|
117
117
|
return true
|
|
@@ -144,26 +144,26 @@ export class SplitAction implements IDragAction {
|
|
|
144
144
|
return this.textHints
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
calculateSplitRequest(state:
|
|
147
|
+
calculateSplitRequest(state: MoveState): boolean {
|
|
148
148
|
const {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
149
|
+
moveHoveredFrame,
|
|
150
|
+
moveDirections,
|
|
151
|
+
movingEdges,
|
|
152
|
+
movePoint,
|
|
153
153
|
win
|
|
154
154
|
} = state
|
|
155
|
-
const oppositeOrientation = oppositeSide(getEdgeOrientation(
|
|
156
|
-
const originalDragHoveredFrame = win.frames[
|
|
155
|
+
const oppositeOrientation = oppositeSide(getEdgeOrientation(movingEdges[0]))
|
|
156
|
+
const originalDragHoveredFrame = win.frames[moveHoveredFrame!.id]
|
|
157
157
|
const canSplit = getFrameSplitInfo(
|
|
158
158
|
originalDragHoveredFrame!,
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
moveDirections[oppositeOrientation]!,
|
|
160
|
+
movePoint!
|
|
161
161
|
)
|
|
162
|
-
this.setTextHints(state.
|
|
162
|
+
this.setTextHints(state.isMoving === "edge" && !state.isMovingFromWindowEdge ? canSplit : undefined)
|
|
163
163
|
if (!(canSplit instanceof Error)) {
|
|
164
164
|
this.state.allowed = true
|
|
165
165
|
this.state.res = canSplit
|
|
166
|
-
this.state.lastPoint =
|
|
166
|
+
this.state.lastPoint = movePoint ? { ...movePoint } : undefined
|
|
167
167
|
return true
|
|
168
168
|
} else {
|
|
169
169
|
this.hooks.onError?.(canSplit)
|
|
@@ -173,18 +173,22 @@ export class SplitAction implements IDragAction {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
onMoveChange(
|
|
177
|
+
type: "start" | "end" | "move",
|
|
178
178
|
_e: PointerEvent | undefined,
|
|
179
|
-
state:
|
|
180
|
-
):
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return {
|
|
179
|
+
state: MoveState
|
|
180
|
+
): ActionChangeResult {
|
|
181
|
+
if (type === "end") {
|
|
182
|
+
this.reset()
|
|
183
|
+
return { shapes: [] }
|
|
184
|
+
}
|
|
185
|
+
const { moveHoveredFrame, moveDistance } = state
|
|
186
|
+
if (moveDistance <= this.minDragDistance) {
|
|
187
|
+
return { updateEdges: false, shapes: [], showMoving: false }
|
|
184
188
|
}
|
|
185
189
|
let ok = false
|
|
186
|
-
if (
|
|
187
|
-
if (this.state.lastPoint?.x === state.
|
|
190
|
+
if (moveHoveredFrame) {
|
|
191
|
+
if (this.state.lastPoint?.x === state.movePoint?.x && this.state.lastPoint?.y === state.movePoint?.y && this.state.lastReturn) {
|
|
188
192
|
return this.state.lastReturn!
|
|
189
193
|
}
|
|
190
194
|
ok = this.calculateSplitRequest(state)
|
|
@@ -192,37 +196,36 @@ export class SplitAction implements IDragAction {
|
|
|
192
196
|
const decos = this.getDecos(state)
|
|
193
197
|
|
|
194
198
|
if (!ok) {
|
|
195
|
-
if (
|
|
199
|
+
if (moveHoveredFrame && moveHoveredFrame.docked) {
|
|
196
200
|
const errorDeco: LayoutShape = {
|
|
197
201
|
type: "rect",
|
|
198
202
|
data: {
|
|
199
|
-
x:
|
|
200
|
-
y:
|
|
201
|
-
width:
|
|
202
|
-
height:
|
|
203
|
+
x: moveHoveredFrame.x,
|
|
204
|
+
y: moveHoveredFrame.y,
|
|
205
|
+
width: moveHoveredFrame.width,
|
|
206
|
+
height: moveHoveredFrame.height
|
|
203
207
|
},
|
|
204
208
|
attrs: { class: "deco-split-error bg-red-500/50" }
|
|
205
209
|
}
|
|
206
|
-
this.state.lastReturn = { updateEdges: true, shapes: [errorDeco],
|
|
210
|
+
this.state.lastReturn = { updateEdges: true, shapes: [errorDeco], showMoving: false }
|
|
207
211
|
return this.state.lastReturn
|
|
208
212
|
}
|
|
209
213
|
}
|
|
210
|
-
this.state.lastReturn = { updateEdges: false, shapes: decos.flatMap(_ => _.shapes),
|
|
214
|
+
this.state.lastReturn = { updateEdges: false, shapes: decos.flatMap(_ => _.shapes), showMoving: false }
|
|
211
215
|
return this.state.lastReturn
|
|
212
216
|
}
|
|
213
217
|
|
|
214
|
-
|
|
215
|
-
if (this.state.res && state.
|
|
218
|
+
onMoveApply(state: MoveState): boolean {
|
|
219
|
+
if (this.state.res && state.moveHoveredFrame) {
|
|
216
220
|
// this only caches once per frame hovered over
|
|
217
221
|
// so the drag position is outdated, we must recalculate
|
|
218
222
|
const ok = this.calculateSplitRequest(state)
|
|
219
223
|
if (ok) {
|
|
220
|
-
if (this.debug) {
|
|
224
|
+
if (this.debug) { ActionHandler.debugState(this.name, "before", state, this.state, this.debug) }
|
|
221
225
|
applyFrameChanges(state.win, this.state.res!)
|
|
222
|
-
if (this.debug) {
|
|
226
|
+
if (this.debug) { ActionHandler.debugState(this.name, "after", state, this.state, this.debug) }
|
|
223
227
|
}
|
|
224
228
|
}
|
|
225
|
-
this.reset()
|
|
226
229
|
return true
|
|
227
230
|
}
|
|
228
231
|
|
|
@@ -2,7 +2,7 @@ import { CloseAction } from "./CloseAction"
|
|
|
2
2
|
import { FrameDragAction } from "./FrameDragAction.js"
|
|
3
3
|
import { SplitAction } from "./SplitAction.js"
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { IAction } from "../types/index.js"
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Creates the default drag actions (Split, Close, FrameDrag).
|
|
@@ -11,7 +11,7 @@ export function createDefaultHandlers(config: {
|
|
|
11
11
|
debugSplit?: boolean
|
|
12
12
|
debugClose?: boolean
|
|
13
13
|
debugFrameDrag?: boolean
|
|
14
|
-
} = {}):
|
|
14
|
+
} = {}): IAction[] {
|
|
15
15
|
return [
|
|
16
16
|
new SplitAction(undefined, undefined, undefined, { debug: config.debugSplit }),
|
|
17
17
|
new CloseAction(undefined, undefined, undefined, { debug: config.debugClose }),
|