@witchcraft/layout 0.5.8 → 0.5.10
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/LayoutDragEdgeHandle.d.vue.ts +2 -3
- package/dist/runtime/components/LayoutDragEdgeHandle.vue +1 -1
- package/dist/runtime/components/LayoutDragEdgeHandle.vue.d.ts +2 -3
- package/dist/runtime/components/LayoutDragEdges.vue +1 -1
- package/dist/runtime/components/LayoutIntersectionHandle.d.vue.ts +2 -3
- package/dist/runtime/components/LayoutIntersectionHandle.vue +1 -2
- package/dist/runtime/components/LayoutIntersectionHandle.vue.d.ts +2 -3
- package/dist/runtime/components/LayoutWindow.d.vue.ts +2 -1370
- package/dist/runtime/components/LayoutWindow.vue +0 -2
- package/dist/runtime/components/LayoutWindow.vue.d.ts +2 -1370
- package/dist/runtime/composables/useFrames.d.ts +2 -1062
- package/dist/runtime/move/ActionHandler.d.ts +1 -1
- package/dist/runtime/move/ActionHandler.js +1 -1
- package/dist/runtime/move/CloseAction.d.ts +2 -2
- package/dist/runtime/move/CloseAction.js +2 -2
- package/dist/runtime/move/FrameDragAction.d.ts +2 -2
- package/dist/runtime/move/SplitAction.d.ts +2 -2
- package/dist/runtime/move/SplitAction.js +1 -1
- package/dist/runtime/types/index.d.ts +3 -1
- package/dist/runtime/types/vue.d.ts +15 -18
- package/package.json +1 -1
- package/src/runtime/components/LayoutDragEdgeHandle.vue +2 -2
- package/src/runtime/components/LayoutDragEdges.vue +1 -1
- package/src/runtime/components/LayoutIntersectionHandle.vue +2 -3
- package/src/runtime/components/LayoutWindow.vue +0 -2
- package/src/runtime/composables/useFrames.ts +8 -4
- package/src/runtime/move/ActionHandler.ts +3 -3
- package/src/runtime/move/CloseAction.ts +4 -4
- package/src/runtime/move/FrameDragAction.ts +3 -3
- package/src/runtime/move/SplitAction.ts +3 -3
- package/src/runtime/types/index.ts +3 -1
- package/src/runtime/types/vue.ts +24 -5
|
@@ -43,7 +43,7 @@ export declare class ActionHandler<TRawActions extends IAction[], TActions exten
|
|
|
43
43
|
* The default prevents movement when the edge is a window edge and when the edge is touching a collapsed frame.
|
|
44
44
|
*/
|
|
45
45
|
defaultOnMoveChange?: IAction["onMoveChange"]);
|
|
46
|
-
eventHandler(e: KeyboardEvent | PointerEvent, state: MoveState, forceRecalculateEdges: () => void): undefined;
|
|
46
|
+
eventHandler(e: KeyboardEvent | PointerEvent | undefined, state: MoveState, forceRecalculateEdges: () => void): undefined;
|
|
47
47
|
onMoveChange<T extends "start" | "move" | "end">(type: T, e: T extends "end" | "start" ? PointerEvent | undefined : PointerEvent, state: MoveState, forceRecalculateEdges: () => void, cancel: (e: PointerEvent | KeyboardEvent | undefined, state: MoveState) => void, resolve: T extends "end" ? undefined : ((opts: ActionResolve) => void)): MoveChangeResult;
|
|
48
48
|
onMoveApply(state: MoveState, forceRecalculateEdges: () => void): ActionHandlerApplyResult;
|
|
49
49
|
onMoveEnded(): void;
|
|
@@ -29,7 +29,7 @@ export declare class CloseAction implements IAction {
|
|
|
29
29
|
}) => string[]);
|
|
30
30
|
transformError: (e: KnownError) => string;
|
|
31
31
|
};
|
|
32
|
-
handleEvent: (e: PointerEvent | KeyboardEvent, state: MoveState) => boolean | "force";
|
|
32
|
+
handleEvent: (e: PointerEvent | KeyboardEvent | undefined, state: MoveState) => boolean | "force";
|
|
33
33
|
modifyDecos: (shapes: CloseDeco[]) => void;
|
|
34
34
|
hooks: {
|
|
35
35
|
onStart?: (active: boolean) => void;
|
|
@@ -51,7 +51,7 @@ export declare class CloseAction implements IAction {
|
|
|
51
51
|
actions: string[];
|
|
52
52
|
errors: string[];
|
|
53
53
|
};
|
|
54
|
-
canHandleRequest(e: PointerEvent | KeyboardEvent, state: MoveState): boolean;
|
|
54
|
+
canHandleRequest(e: PointerEvent | KeyboardEvent | undefined, state: MoveState): boolean;
|
|
55
55
|
onMoveChange(type: "start" | "end" | "move", _e: PointerEvent | undefined, state: MoveState): ActionChangeResult;
|
|
56
56
|
onMoveApply(state: MoveState): ActionApplyResult;
|
|
57
57
|
cancel(): void;
|
|
@@ -17,10 +17,10 @@ export class CloseAction {
|
|
|
17
17
|
transformError: (e) => e.message
|
|
18
18
|
};
|
|
19
19
|
handleEvent = (e) => {
|
|
20
|
-
if (e
|
|
20
|
+
if (e?.ctrlKey && e?.shiftKey) {
|
|
21
21
|
return "force";
|
|
22
22
|
}
|
|
23
|
-
if (e
|
|
23
|
+
if (e?.shiftKey) return true;
|
|
24
24
|
return false;
|
|
25
25
|
};
|
|
26
26
|
modifyDecos = () => {
|
|
@@ -11,7 +11,7 @@ export declare class FrameDragAction implements IAction {
|
|
|
11
11
|
actions: string[];
|
|
12
12
|
errors: string[];
|
|
13
13
|
};
|
|
14
|
-
handleEvent: (e: PointerEvent | KeyboardEvent, state: MoveState) => boolean;
|
|
14
|
+
handleEvent: (e: PointerEvent | KeyboardEvent | undefined, state: MoveState) => boolean;
|
|
15
15
|
dragHints: {
|
|
16
16
|
actions: {
|
|
17
17
|
split?: string;
|
|
@@ -43,7 +43,7 @@ export declare class FrameDragAction implements IAction {
|
|
|
43
43
|
errors: string[];
|
|
44
44
|
};
|
|
45
45
|
getDecos(matchedZone: Zone | undefined, state: MoveState, result: LayoutChange<"split" | "swap" | "rearrange" | "dock"> | KnownError | undefined): FrameDeco[];
|
|
46
|
-
canHandleRequest(e: PointerEvent | KeyboardEvent, state: MoveState): boolean;
|
|
46
|
+
canHandleRequest(e: PointerEvent | KeyboardEvent | undefined, state: MoveState): boolean;
|
|
47
47
|
onMoveChange<T extends "start" | "move" | "end">(type: T, _e: PointerEvent | undefined, state: MoveState): ActionChangeResult;
|
|
48
48
|
onMoveApply(state: MoveState): ActionApplyResult;
|
|
49
49
|
onMoveEnded(): void;
|
|
@@ -26,7 +26,7 @@ export declare class SplitAction implements IAction {
|
|
|
26
26
|
actions: string[] | ((type: DragChangeType) => string[]);
|
|
27
27
|
transformError: (e: KnownError) => string;
|
|
28
28
|
};
|
|
29
|
-
handleEvent: (e: PointerEvent | KeyboardEvent, state: MoveState) => boolean;
|
|
29
|
+
handleEvent: (e: PointerEvent | KeyboardEvent | undefined, state: MoveState) => boolean;
|
|
30
30
|
modifyDecos: (shapes: SplitDeco[]) => void;
|
|
31
31
|
hooks: {
|
|
32
32
|
onStart?: () => void;
|
|
@@ -43,7 +43,7 @@ export declare class SplitAction implements IAction {
|
|
|
43
43
|
});
|
|
44
44
|
reset(): void;
|
|
45
45
|
getDecos(state: MoveState): SplitDeco[];
|
|
46
|
-
canHandleRequest(e: PointerEvent | KeyboardEvent, state: MoveState): boolean;
|
|
46
|
+
canHandleRequest(e: PointerEvent | KeyboardEvent | undefined, state: MoveState): boolean;
|
|
47
47
|
setTextHints(result: true | SplitInfo | KnownError | undefined): void;
|
|
48
48
|
getTextHints(type: "start" | "move" | "end"): {
|
|
49
49
|
actions: string[];
|
|
@@ -15,7 +15,7 @@ export class SplitAction {
|
|
|
15
15
|
actions: ["Hold Alt to Split"],
|
|
16
16
|
transformError: (e) => e.message
|
|
17
17
|
};
|
|
18
|
-
handleEvent = (e, state) => e
|
|
18
|
+
handleEvent = (e, state) => e?.altKey || state.isMovingFromWindowEdge;
|
|
19
19
|
modifyDecos = () => {
|
|
20
20
|
};
|
|
21
21
|
hooks;
|
|
@@ -1956,8 +1956,10 @@ export interface IAction {
|
|
|
1956
1956
|
* The user is not necessarily dragging at this point, though they might also change actions mid drag. So it does not necessarily mean the event is allowed.
|
|
1957
1957
|
*
|
|
1958
1958
|
* Here is where you should initiate your state. Don't allow the action by default unless it can always be allowed.
|
|
1959
|
+
*
|
|
1960
|
+
* Event might be undefined if it was initiated manually via moveStart without an event.
|
|
1959
1961
|
*/
|
|
1960
|
-
canHandleRequest(e: KeyboardEvent | PointerEvent, state: MoveState, forceRecalculateEdges: () => void): boolean;
|
|
1962
|
+
canHandleRequest(e: KeyboardEvent | PointerEvent | undefined, state: MoveState, forceRecalculateEdges: () => void): boolean;
|
|
1961
1963
|
/**
|
|
1962
1964
|
* Plugins should implement some basic debug logs by calling {@link ActionHandler.debugState } at least before and after applying actions in onMoveApply. Debug can be a string because it can be an object key to filter on (see the debugState function).
|
|
1963
1965
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComputedRef, InjectionKey, Ref } from "vue";
|
|
2
|
-
import type { Direction, Edge, FrameId, IActionHandler, IntersectionEntry, LayoutFrame, LayoutShape, LayoutWindow, MoveState, Orientation, Point } from "./index.js";
|
|
2
|
+
import type { Direction, Edge, EdgeMoveStartData, ExtendedMoveTypes, FrameId, FrameMoveStartData, IActionHandler, IntersectionEntry, LayoutFrame, LayoutShape, LayoutWindow, MoveState, Orientation, Point } from "./index.js";
|
|
3
3
|
export type LayoutContext = ComputedRef<{
|
|
4
4
|
/** The owning window, needed so we can correctly scale coordinates. */
|
|
5
5
|
win: LayoutWindow;
|
|
@@ -9,23 +9,19 @@ export type LayoutContext = ComputedRef<{
|
|
|
9
9
|
export declare const layoutContextInjectionKey: InjectionKey<LayoutContext>;
|
|
10
10
|
export interface UseFramesContext {
|
|
11
11
|
actionHandler: IActionHandler;
|
|
12
|
-
moveStart
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
endEvent?: string;
|
|
26
|
-
context?: Record<string, unknown>;
|
|
27
|
-
}): Promise<any>;
|
|
28
|
-
};
|
|
12
|
+
moveStart<T extends "edge" | "frame" | "other", TContextType extends keyof ExtendedMoveTypes, TContext extends ExtendedMoveTypes[TContextType], TContextReturn extends TContext extends {
|
|
13
|
+
resolve: infer R;
|
|
14
|
+
} ? R : never, TContextMoveType extends TContext extends {
|
|
15
|
+
moveType: infer M;
|
|
16
|
+
} ? M : never, TContextContext extends TContext extends {
|
|
17
|
+
context: infer C;
|
|
18
|
+
} ? C : never, TType extends [TContextMoveType] extends [never] ? T : TContextMoveType>(e: PointerEvent | undefined, type: TType, data: T extends "edge" ? EdgeMoveStartData : T extends "frame" ? FrameMoveStartData : undefined, opts?: {
|
|
19
|
+
moveEvent?: string;
|
|
20
|
+
endEvent?: string;
|
|
21
|
+
context?: {
|
|
22
|
+
type: TContextType;
|
|
23
|
+
} & TContextContext;
|
|
24
|
+
}): TContext extends never ? Promise<void> : Promise<TContextReturn>;
|
|
29
25
|
onMove: (e: PointerEvent) => void;
|
|
30
26
|
moveEnd: (e?: PointerEvent, options?: {
|
|
31
27
|
apply?: boolean;
|
|
@@ -34,6 +30,7 @@ export interface UseFramesContext {
|
|
|
34
30
|
moveDirections: Ref<Record<Orientation, Direction | undefined>>;
|
|
35
31
|
movePoint: Ref<Point | undefined>;
|
|
36
32
|
isMoving: Ref<false | "frame" | "edge" | "other">;
|
|
33
|
+
showMoving: Ref<boolean>;
|
|
37
34
|
movingEdges: Ref<Edge[]>;
|
|
38
35
|
movingIntersection: Ref<IntersectionEntry | undefined>;
|
|
39
36
|
visualEdges: Ref<Edge[]>;
|
package/package.json
CHANGED
|
@@ -28,7 +28,7 @@ import { useAttrs, inject } from "vue"
|
|
|
28
28
|
import LayoutShapeRect from "./LayoutShapeRect.vue"
|
|
29
29
|
import { type EdgeMoveStartData } from "../types/index.js"
|
|
30
30
|
import { moveContextInjectionKey } from "../types/vue.js"
|
|
31
|
-
import type { Edge, EdgeCss } from "../types/index.js"
|
|
31
|
+
import type { Edge, EdgeCss, UseFramesContext } from "../types/index.js"
|
|
32
32
|
|
|
33
33
|
const $attrs = useAttrs()
|
|
34
34
|
|
|
@@ -39,7 +39,7 @@ defineOptions({
|
|
|
39
39
|
const props = defineProps<{
|
|
40
40
|
edge: Edge
|
|
41
41
|
css: EdgeCss
|
|
42
|
-
onPointerDown?:
|
|
42
|
+
onPointerDown?: UseFramesContext["moveStart"]
|
|
43
43
|
}>()
|
|
44
44
|
|
|
45
45
|
const ctx = inject(layoutContextInjectionKey, undefined)
|
|
@@ -20,9 +20,8 @@ import { twMerge } from "@witchcraft/ui/utils/twMerge"
|
|
|
20
20
|
import LayoutShapeRect from "./LayoutShapeRect.vue"
|
|
21
21
|
|
|
22
22
|
import { getIntersectionsCss } from "../helpers/getIntersectionsCss.js"
|
|
23
|
-
import { type EdgeMoveStartData } from "../types/index.js"
|
|
24
23
|
import { moveContextInjectionKey } from "../types/vue.js"
|
|
25
|
-
import type { IntersectionEntry } from "../types/index.js"
|
|
24
|
+
import type { IntersectionEntry, UseFramesContext } from "../types/index.js"
|
|
26
25
|
|
|
27
26
|
const $attrs = useAttrs()
|
|
28
27
|
|
|
@@ -33,7 +32,7 @@ defineOptions({
|
|
|
33
32
|
const props = defineProps<{
|
|
34
33
|
css: ReturnType<typeof getIntersectionsCss>[number]
|
|
35
34
|
intersection: IntersectionEntry
|
|
36
|
-
onPointerDown?:
|
|
35
|
+
onPointerDown?: UseFramesContext["moveStart"]
|
|
37
36
|
}>()
|
|
38
37
|
|
|
39
38
|
const ctx = inject(layoutContextInjectionKey, undefined)
|
|
@@ -128,7 +128,6 @@ const actionHandler = props.actionHandler ?? markRaw(new ActionHandler(
|
|
|
128
128
|
],
|
|
129
129
|
{
|
|
130
130
|
onEvent: (e, cancel) => {
|
|
131
|
-
showMoving.value = true
|
|
132
131
|
if (e instanceof KeyboardEvent && e.key === "Escape") {
|
|
133
132
|
cancel()
|
|
134
133
|
}
|
|
@@ -138,7 +137,6 @@ const actionHandler = props.actionHandler ?? markRaw(new ActionHandler(
|
|
|
138
137
|
},
|
|
139
138
|
onEnd: () => {
|
|
140
139
|
requestType.value = undefined
|
|
141
|
-
showMoving.value = true
|
|
142
140
|
},
|
|
143
141
|
}
|
|
144
142
|
))
|
|
@@ -26,14 +26,15 @@ import type {
|
|
|
26
26
|
LayoutWindow,
|
|
27
27
|
MoveState,
|
|
28
28
|
Orientation,
|
|
29
|
-
Point
|
|
29
|
+
Point,
|
|
30
|
+
UseFramesContext
|
|
30
31
|
} from "../types/index.js"
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
export function useFrames(
|
|
34
35
|
win: Ref<LayoutWindow>,
|
|
35
36
|
handler: IActionHandler
|
|
36
|
-
) {
|
|
37
|
+
): UseFramesContext {
|
|
37
38
|
const movingEdges = ref<Edge[]>([])
|
|
38
39
|
|
|
39
40
|
// each entry corresponds to the frames touching the corresponding dragging edge
|
|
@@ -153,16 +154,19 @@ export function useFrames(
|
|
|
153
154
|
handler.onMoveEnded()
|
|
154
155
|
}
|
|
155
156
|
|
|
157
|
+
|
|
156
158
|
function moveStart<
|
|
157
159
|
T extends "edge" | "frame" | "other",
|
|
158
160
|
TContextType extends keyof ExtendedMoveTypes,
|
|
159
161
|
TContext extends ExtendedMoveTypes[TContextType],
|
|
160
162
|
TContextReturn extends TContext extends { resolve: infer R } ? R : never,
|
|
161
163
|
TContextMoveType extends TContext extends { moveType: infer M } ? M : never,
|
|
162
|
-
TContextContext extends TContext extends { context: infer C } ? C : never
|
|
164
|
+
TContextContext extends TContext extends { context: infer C } ? C : never,
|
|
165
|
+
// cursed https://github.com/microsoft/TypeScript/issues/23182
|
|
166
|
+
TType extends [TContextMoveType] extends [never] ? T : TContextMoveType
|
|
163
167
|
>(
|
|
164
168
|
e: PointerEvent | undefined,
|
|
165
|
-
type:
|
|
169
|
+
type: TType,
|
|
166
170
|
// someday this will work
|
|
167
171
|
data: T extends "edge" ? EdgeMoveStartData : T extends "frame" ? FrameMoveStartData : undefined,
|
|
168
172
|
{
|
|
@@ -77,12 +77,12 @@ export class ActionHandler<
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
eventHandler(
|
|
80
|
-
e: KeyboardEvent | PointerEvent,
|
|
80
|
+
e: KeyboardEvent | PointerEvent | undefined,
|
|
81
81
|
state: MoveState,
|
|
82
82
|
forceRecalculateEdges: () => void
|
|
83
83
|
) {
|
|
84
84
|
if (state.isMoving) {
|
|
85
|
-
e
|
|
85
|
+
e?.preventDefault()
|
|
86
86
|
}
|
|
87
87
|
let cancelled = false
|
|
88
88
|
this.hooks.onEvent?.(e, () => {
|
|
@@ -131,7 +131,7 @@ export class ActionHandler<
|
|
|
131
131
|
): MoveChangeResult {
|
|
132
132
|
if (type === "start") {
|
|
133
133
|
this.eventCanceller = cancel
|
|
134
|
-
this.eventHandler(e
|
|
134
|
+
this.eventHandler(e, state, forceRecalculateEdges)
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
if (this.activeAction) {
|
|
@@ -40,11 +40,11 @@ export class CloseAction implements IAction {
|
|
|
40
40
|
transformError: e => e.message
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
handleEvent: (e: PointerEvent | KeyboardEvent, state: MoveState) => boolean | "force" = (e: PointerEvent | KeyboardEvent) => {
|
|
44
|
-
if (e
|
|
43
|
+
handleEvent: (e: PointerEvent | KeyboardEvent | undefined, state: MoveState) => boolean | "force" = (e: PointerEvent | KeyboardEvent | undefined) => {
|
|
44
|
+
if (e?.ctrlKey && e?.shiftKey) {
|
|
45
45
|
return "force"
|
|
46
46
|
}
|
|
47
|
-
if (e
|
|
47
|
+
if (e?.shiftKey) return true
|
|
48
48
|
return false
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -136,7 +136,7 @@ export class CloseAction implements IAction {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
|
|
139
|
-
canHandleRequest(e: PointerEvent | KeyboardEvent, state: MoveState): boolean {
|
|
139
|
+
canHandleRequest(e: PointerEvent | KeyboardEvent | undefined, state: MoveState): boolean {
|
|
140
140
|
const { movingEdges } = state
|
|
141
141
|
if (movingEdges.length !== 1) return false
|
|
142
142
|
const res = this.handleEvent(e, state)
|
|
@@ -25,8 +25,8 @@ export class FrameDragAction implements IAction {
|
|
|
25
25
|
debug: boolean | string = false
|
|
26
26
|
textHints: { actions: string[], errors: string[] } = { actions: [], errors: [] }
|
|
27
27
|
|
|
28
|
-
handleEvent: (e: PointerEvent | KeyboardEvent, state: MoveState) => boolean
|
|
29
|
-
= (_e: PointerEvent | KeyboardEvent, state: MoveState) => state.isMoving === "frame"
|
|
28
|
+
handleEvent: (e: PointerEvent | KeyboardEvent | undefined, state: MoveState) => boolean
|
|
29
|
+
= (_e: PointerEvent | KeyboardEvent | undefined, 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[])
|
|
@@ -139,7 +139,7 @@ export class FrameDragAction implements IAction {
|
|
|
139
139
|
return decos
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
canHandleRequest(e: PointerEvent | KeyboardEvent, state: MoveState): boolean {
|
|
142
|
+
canHandleRequest(e: PointerEvent | KeyboardEvent | undefined, state: MoveState): boolean {
|
|
143
143
|
const res = this.handleEvent(e, state)
|
|
144
144
|
this.setTextHints(undefined)
|
|
145
145
|
if (res) {
|
|
@@ -40,8 +40,8 @@ export class SplitAction implements IAction {
|
|
|
40
40
|
transformError: e => e.message
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
handleEvent: (e: PointerEvent | KeyboardEvent, state: MoveState) => boolean
|
|
44
|
-
= (e: PointerEvent | KeyboardEvent, state: MoveState) => e
|
|
43
|
+
handleEvent: (e: PointerEvent | KeyboardEvent | undefined, state: MoveState) => boolean
|
|
44
|
+
= (e: PointerEvent | KeyboardEvent | undefined, state: MoveState) => e?.altKey || state.isMovingFromWindowEdge
|
|
45
45
|
|
|
46
46
|
modifyDecos: (shapes: SplitDeco[]) => void = () => { }
|
|
47
47
|
hooks: {
|
|
@@ -107,7 +107,7 @@ export class SplitAction implements IAction {
|
|
|
107
107
|
return decos
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
canHandleRequest(e: PointerEvent | KeyboardEvent, state: MoveState): boolean {
|
|
110
|
+
canHandleRequest(e: PointerEvent | KeyboardEvent | undefined, state: MoveState): boolean {
|
|
111
111
|
const { movingEdges } = state
|
|
112
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
|
|
@@ -574,9 +574,11 @@ export interface IAction {
|
|
|
574
574
|
* The user is not necessarily dragging at this point, though they might also change actions mid drag. So it does not necessarily mean the event is allowed.
|
|
575
575
|
*
|
|
576
576
|
* Here is where you should initiate your state. Don't allow the action by default unless it can always be allowed.
|
|
577
|
+
*
|
|
578
|
+
* Event might be undefined if it was initiated manually via moveStart without an event.
|
|
577
579
|
*/
|
|
578
580
|
canHandleRequest(
|
|
579
|
-
e: KeyboardEvent | PointerEvent,
|
|
581
|
+
e: KeyboardEvent | PointerEvent | undefined,
|
|
580
582
|
state: MoveState,
|
|
581
583
|
forceRecalculateEdges: () => void
|
|
582
584
|
): boolean
|
package/src/runtime/types/vue.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComputedRef, InjectionKey, Ref } from "vue"
|
|
2
2
|
|
|
3
3
|
// eslint-disable-next-line no-restricted-imports
|
|
4
|
-
import type { Direction, Edge, FrameId, IActionHandler, IntersectionEntry, LayoutFrame, LayoutShape, LayoutWindow, MoveState, Orientation, Point } from "./index.js"
|
|
4
|
+
import type { Direction, Edge, EdgeMoveStartData, ExtendedMoveTypes, FrameId, FrameMoveStartData, IActionHandler, IntersectionEntry, LayoutFrame, LayoutShape, LayoutWindow, MoveState, Orientation, Point } from "./index.js"
|
|
5
5
|
|
|
6
6
|
export type LayoutContext = ComputedRef<
|
|
7
7
|
& {
|
|
@@ -16,16 +16,35 @@ export const layoutContextInjectionKey = Symbol.for("@witchcraft/layout:context"
|
|
|
16
16
|
|
|
17
17
|
export interface UseFramesContext {
|
|
18
18
|
actionHandler: IActionHandler
|
|
19
|
-
moveStart
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
moveStart<
|
|
20
|
+
T extends "edge" | "frame" | "other",
|
|
21
|
+
TContextType extends keyof ExtendedMoveTypes,
|
|
22
|
+
TContext extends ExtendedMoveTypes[TContextType],
|
|
23
|
+
TContextReturn extends TContext extends { resolve: infer R } ? R : never,
|
|
24
|
+
TContextMoveType extends TContext extends { moveType: infer M } ? M : never,
|
|
25
|
+
TContextContext extends TContext extends { context: infer C } ? C : never,
|
|
26
|
+
// cursed https://github.com/microsoft/TypeScript/issues/23182
|
|
27
|
+
TType extends [TContextMoveType] extends [never] ? T : TContextMoveType
|
|
28
|
+
>(
|
|
29
|
+
e: PointerEvent | undefined,
|
|
30
|
+
type: TType,
|
|
31
|
+
// someday this will work
|
|
32
|
+
data: T extends "edge" ? EdgeMoveStartData : T extends "frame" ? FrameMoveStartData : undefined,
|
|
33
|
+
opts?: {
|
|
34
|
+
moveEvent?: string
|
|
35
|
+
endEvent?: string
|
|
36
|
+
context?: { type: TContextType } & TContextContext
|
|
37
|
+
}
|
|
38
|
+
): TContext extends never
|
|
39
|
+
? Promise<void>
|
|
40
|
+
: Promise<TContextReturn>
|
|
23
41
|
onMove: (e: PointerEvent) => void
|
|
24
42
|
moveEnd: (e?: PointerEvent, options?: { apply?: boolean }) => void
|
|
25
43
|
cancel: () => void
|
|
26
44
|
moveDirections: Ref<Record<Orientation, Direction | undefined>>
|
|
27
45
|
movePoint: Ref<Point | undefined>
|
|
28
46
|
isMoving: Ref<false | "frame" | "edge" | "other">
|
|
47
|
+
showMoving: Ref<boolean>
|
|
29
48
|
movingEdges: Ref<Edge[]>
|
|
30
49
|
movingIntersection: Ref<IntersectionEntry | undefined>
|
|
31
50
|
visualEdges: Ref<Edge[]>
|