@witchcraft/layout 0.4.4 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 +107 -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} +19 -21
- package/dist/runtime/{drag/DragActionHandler.js → move/ActionHandler.js} +21 -18
- package/dist/runtime/{drag → move}/CloseAction.d.ts +9 -8
- package/dist/runtime/{drag → move}/CloseAction.js +31 -27
- package/dist/runtime/{drag → move}/FrameDragAction.d.ts +9 -8
- package/dist/runtime/{drag → move}/FrameDragAction.js +23 -22
- 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 +10 -9
- package/dist/runtime/{drag → move}/SplitAction.js +53 -44
- package/dist/runtime/{drag → move}/createDefaultHandlers.d.ts +2 -2
- package/dist/runtime/types/index.d.ts +192 -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 +115 -104
- 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} +48 -41
- package/src/runtime/{drag → move}/CloseAction.ts +42 -37
- package/src/runtime/{drag → move}/FrameDragAction.ts +37 -36
- package/src/runtime/{drag/DragDirectionStore.ts → move/MoveDirectionStore.ts} +10 -10
- package/src/runtime/{drag → move}/SplitAction.ts +64 -54
- package/src/runtime/{drag → move}/createDefaultHandlers.ts +2 -2
- package/src/runtime/types/index.ts +90 -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
|
@@ -118,7 +118,7 @@ const zCloseDeco = zBaseDeco.extend({
|
|
|
118
118
|
type: z.literal("close"),
|
|
119
119
|
force: z.boolean().optional()
|
|
120
120
|
});
|
|
121
|
-
const
|
|
121
|
+
const zFrameDeco = zBaseDeco.extend({
|
|
122
122
|
id: z.uuid(),
|
|
123
123
|
type: z.literal("drop"),
|
|
124
124
|
position: zSide.or(z.enum(["center"]))
|
|
@@ -126,7 +126,7 @@ const zFrameDragDeco = zBaseDeco.extend({
|
|
|
126
126
|
export const zDeco = z.union([
|
|
127
127
|
zSplitDeco,
|
|
128
128
|
zCloseDeco,
|
|
129
|
-
|
|
129
|
+
zFrameDeco
|
|
130
130
|
]);
|
|
131
131
|
export const LAYOUT_ERROR = enumFromArray([
|
|
132
132
|
"INVALID_ID",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComputedRef, InjectionKey, Ref } from "vue";
|
|
2
|
-
import type { ActionHandler,
|
|
2
|
+
import type { ActionHandler, ActionHandlerApplyResult, Direction, Edge, FrameId, 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,7 +9,7 @@ export type LayoutContext = ComputedRef<{
|
|
|
9
9
|
export declare const layoutContextInjectionKey: InjectionKey<LayoutContext>;
|
|
10
10
|
export interface UseFramesContext {
|
|
11
11
|
actionHandler: ActionHandler;
|
|
12
|
-
|
|
12
|
+
moveStart: {
|
|
13
13
|
(e: PointerEvent, type: "edge", data: {
|
|
14
14
|
edge?: Edge;
|
|
15
15
|
intersection?: IntersectionEntry;
|
|
@@ -26,25 +26,23 @@ export interface UseFramesContext {
|
|
|
26
26
|
context?: Record<string, unknown>;
|
|
27
27
|
}): Promise<any>;
|
|
28
28
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
apply?: boolean;
|
|
32
|
-
}) => void;
|
|
29
|
+
onMove: (e: PointerEvent) => void;
|
|
30
|
+
moveEnd: (e?: PointerEvent, options?: Partial<Pick<ActionHandlerApplyResult, "apply">>) => void;
|
|
33
31
|
cancel: () => void;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
moveDirections: Ref<Record<Orientation, Direction | undefined>>;
|
|
33
|
+
movePoint: Ref<Point | undefined>;
|
|
34
|
+
isMoving: Ref<false | "frame" | "edge">;
|
|
35
|
+
movingEdges: Ref<Edge[]>;
|
|
36
|
+
movingIntersection: Ref<IntersectionEntry | undefined>;
|
|
39
37
|
visualEdges: Ref<Edge[]>;
|
|
40
38
|
touchingFrames: Ref<Record<string, LayoutFrame>[]>;
|
|
41
39
|
touchingFramesArrays: Ref<LayoutFrame[][]>;
|
|
42
40
|
frames: ComputedRef<Record<string, LayoutFrame>>;
|
|
43
|
-
|
|
41
|
+
moveHoveredFrame: ComputedRef<LayoutFrame | undefined>;
|
|
44
42
|
intersections: ComputedRef<IntersectionEntry[]>;
|
|
45
|
-
|
|
43
|
+
isMovingFromWindowEdge: Ref<boolean>;
|
|
46
44
|
forceRecalculateEdges: () => void;
|
|
47
|
-
state: ComputedRef<
|
|
48
|
-
|
|
45
|
+
state: ComputedRef<MoveState>;
|
|
46
|
+
movingFrameId: Ref<FrameId | undefined>;
|
|
49
47
|
}
|
|
50
|
-
export declare const
|
|
48
|
+
export declare const moveContextInjectionKey: InjectionKey<UseFramesContext>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const layoutContextInjectionKey = Symbol.for("@witchcraft/layout:context");
|
|
2
|
-
export const
|
|
2
|
+
export const moveContextInjectionKey = Symbol.for("@witchcraft/layout:moveContext");
|
package/package.json
CHANGED
|
@@ -8,21 +8,21 @@
|
|
|
8
8
|
</template>
|
|
9
9
|
<script lang="ts" setup>
|
|
10
10
|
import { inject, onBeforeUnmount } from "vue"
|
|
11
|
-
import {
|
|
11
|
+
import { moveContextInjectionKey } from "../types/vue.js"
|
|
12
12
|
|
|
13
13
|
const props = defineProps<{
|
|
14
14
|
frameId: string
|
|
15
15
|
}>()
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
const dragContext = inject(
|
|
18
|
+
const dragContext = inject(moveContextInjectionKey)
|
|
19
19
|
if (!dragContext) {
|
|
20
20
|
throw new Error("FrameDragHandle must be used inside a LayoutWindow and drag context returned by useFrames must be injected.")
|
|
21
21
|
}
|
|
22
22
|
function handlePointerDown(e: PointerEvent): void {
|
|
23
23
|
e.preventDefault()
|
|
24
24
|
e.stopPropagation()
|
|
25
|
-
dragContext!.
|
|
25
|
+
dragContext!.moveStart( e,"frame", {frameId: props.frameId})
|
|
26
26
|
}
|
|
27
27
|
onBeforeUnmount(() => {
|
|
28
28
|
dragContext.cancel()
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
/>
|
|
17
17
|
</template>
|
|
18
18
|
<script lang="ts" setup>
|
|
19
|
-
import {
|
|
19
|
+
import { moveContextInjectionKey, layoutContextInjectionKey } from "../types/vue.js"
|
|
20
20
|
import { twMerge } from "@witchcraft/ui/utils/twMerge"
|
|
21
21
|
import { computed, inject, useAttrs } from "vue"
|
|
22
22
|
|
|
@@ -34,10 +34,10 @@ defineOptions({
|
|
|
34
34
|
const ctx = inject(layoutContextInjectionKey, undefined)
|
|
35
35
|
if (!ctx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
36
36
|
|
|
37
|
-
const dragCtx = inject(
|
|
37
|
+
const dragCtx = inject(moveContextInjectionKey, undefined)
|
|
38
38
|
if (!dragCtx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
39
39
|
|
|
40
|
-
const draggingEdge = computed(() => dragCtx.
|
|
40
|
+
const draggingEdge = computed(() => dragCtx.movingEdges.value.length === 1 ? dragCtx.movingEdges.value[0] : undefined)
|
|
41
41
|
|
|
42
42
|
const cssDragEdge = computed(() => {
|
|
43
43
|
if (!draggingEdge.value) return []
|
|
@@ -26,8 +26,8 @@ import { twMerge } from "@witchcraft/ui/utils/twMerge"
|
|
|
26
26
|
import { useAttrs, inject } from "vue"
|
|
27
27
|
|
|
28
28
|
import LayoutShapeRect from "./LayoutShapeRect.vue"
|
|
29
|
-
import { type
|
|
30
|
-
import {
|
|
29
|
+
import { type EdgeMoveStartData } from "../types/index.js"
|
|
30
|
+
import { moveContextInjectionKey } from "../types/vue.js"
|
|
31
31
|
import type { Edge, EdgeCss } from "../types/index.js"
|
|
32
32
|
|
|
33
33
|
const $attrs = useAttrs()
|
|
@@ -39,13 +39,13 @@ defineOptions({
|
|
|
39
39
|
const props = defineProps<{
|
|
40
40
|
edge: Edge
|
|
41
41
|
css: EdgeCss
|
|
42
|
-
onPointerDown?: (e: PointerEvent, type: "edge", data:
|
|
42
|
+
onPointerDown?: (e: PointerEvent, type: "edge", data: EdgeMoveStartData) => void
|
|
43
43
|
}>()
|
|
44
44
|
|
|
45
45
|
const ctx = inject(layoutContextInjectionKey, undefined)
|
|
46
46
|
if (!ctx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
47
47
|
|
|
48
|
-
const dragCtx = inject(
|
|
48
|
+
const dragCtx = inject(moveContextInjectionKey, undefined)
|
|
49
49
|
if (!dragCtx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
50
50
|
|
|
51
51
|
</script>
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
<slot name="handle" v-bind="{
|
|
7
7
|
css: css.handle,
|
|
8
8
|
edge: visualEdges[i],
|
|
9
|
-
onPointerDown: dragCtx.
|
|
9
|
+
onPointerDown: dragCtx.moveStart
|
|
10
10
|
}">
|
|
11
11
|
<LayoutDragEdgeHandle
|
|
12
12
|
:css="css.handle"
|
|
13
13
|
:edge="visualEdges[i]"
|
|
14
|
-
:on-pointer-down="dragCtx.
|
|
14
|
+
:on-pointer-down="dragCtx.moveStart"
|
|
15
15
|
/>
|
|
16
16
|
</slot>
|
|
17
17
|
<slot name="indicator" v-bind="{
|
|
@@ -37,7 +37,7 @@ import { isEdgeEqual } from "../helpers/isEdgeEqual.js"
|
|
|
37
37
|
import { toRef } from "vue"
|
|
38
38
|
import {cssToKey} from "../utils/cssToKey.js"
|
|
39
39
|
import { type EdgeCss } from "../types/index.js"
|
|
40
|
-
import {
|
|
40
|
+
import { moveContextInjectionKey } from "../types/vue.js"
|
|
41
41
|
|
|
42
42
|
defineOptions({
|
|
43
43
|
inheritAttrs: false
|
|
@@ -46,13 +46,13 @@ defineOptions({
|
|
|
46
46
|
const ctx = inject(layoutContextInjectionKey, undefined)
|
|
47
47
|
if (!ctx) throw new Error("LayoutEdges must be used wivisible a LayoutWindow")
|
|
48
48
|
|
|
49
|
-
const dragCtx = inject(
|
|
49
|
+
const dragCtx = inject(moveContextInjectionKey, undefined)
|
|
50
50
|
if (!dragCtx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
const visualEdges = toRef(dragCtx, "visualEdges")
|
|
54
54
|
|
|
55
|
-
const draggingEdge = computed(() => dragCtx.
|
|
55
|
+
const draggingEdge = computed(() => dragCtx.movingEdges.value.length === 1 ? dragCtx.movingEdges.value[0] : undefined)
|
|
56
56
|
|
|
57
57
|
const cssDragEdges = computed(() => {
|
|
58
58
|
const handleEdges = getVisualEdgesCss(
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
</template>
|
|
18
18
|
|
|
19
19
|
<script lang="ts" setup>
|
|
20
|
-
import {
|
|
20
|
+
import { moveContextInjectionKey, layoutContextInjectionKey } from "../types/vue.js"
|
|
21
21
|
import { computed, inject, useAttrs } from "vue"
|
|
22
22
|
import { twMerge } from "@witchcraft/ui/utils/twMerge"
|
|
23
23
|
|
|
@@ -34,7 +34,7 @@ defineOptions({
|
|
|
34
34
|
const ctx = inject(layoutContextInjectionKey, undefined)
|
|
35
35
|
if (!ctx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
36
36
|
|
|
37
|
-
const dragCtx = inject(
|
|
37
|
+
const dragCtx = inject(moveContextInjectionKey, undefined)
|
|
38
38
|
if (!dragCtx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
39
39
|
|
|
40
40
|
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
</template>
|
|
26
26
|
|
|
27
27
|
<script lang="ts" setup>
|
|
28
|
-
import {
|
|
28
|
+
import { moveContextInjectionKey, layoutContextInjectionKey } from "../types/vue.js"
|
|
29
29
|
import { twMerge } from "@witchcraft/ui/utils/twMerge"
|
|
30
30
|
import { useAttrs, inject, toRef } from "vue"
|
|
31
31
|
|
|
@@ -48,7 +48,7 @@ const emit = defineEmits<{
|
|
|
48
48
|
const ctx = inject(layoutContextInjectionKey, undefined)
|
|
49
49
|
if (!ctx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
50
50
|
|
|
51
|
-
const dragCtx = inject(
|
|
51
|
+
const dragCtx = inject(moveContextInjectionKey, undefined)
|
|
52
52
|
if (!dragCtx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
53
53
|
|
|
54
54
|
const frames = toRef(dragCtx, "frames")
|
|
@@ -20,8 +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
|
|
24
|
-
import {
|
|
23
|
+
import { type EdgeMoveStartData } from "../types/index.js"
|
|
24
|
+
import { moveContextInjectionKey } from "../types/vue.js"
|
|
25
25
|
import type { IntersectionEntry } from "../types/index.js"
|
|
26
26
|
|
|
27
27
|
const $attrs = useAttrs()
|
|
@@ -33,13 +33,13 @@ defineOptions({
|
|
|
33
33
|
const props = defineProps<{
|
|
34
34
|
css: ReturnType<typeof getIntersectionsCss>[number]
|
|
35
35
|
intersection: IntersectionEntry
|
|
36
|
-
onPointerDown?: (e: PointerEvent, type: "edge", data:
|
|
36
|
+
onPointerDown?: (e: PointerEvent, type: "edge", data: EdgeMoveStartData) => void
|
|
37
37
|
}>()
|
|
38
38
|
|
|
39
39
|
const ctx = inject(layoutContextInjectionKey, undefined)
|
|
40
40
|
if (!ctx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
41
41
|
|
|
42
|
-
const dragCtx = inject(
|
|
42
|
+
const dragCtx = inject(moveContextInjectionKey, undefined)
|
|
43
43
|
if (!dragCtx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
44
44
|
|
|
45
45
|
</script>
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
>
|
|
6
6
|
<slot name="handler" v-bind="{
|
|
7
7
|
css: css.handle,
|
|
8
|
-
onPointerDown: dragCtx.
|
|
8
|
+
onPointerDown: dragCtx.moveStart,
|
|
9
9
|
intersection: draggableIntersections[i]
|
|
10
10
|
}">
|
|
11
11
|
<LayoutIntersectionHandle
|
|
12
12
|
:css="css.handle"
|
|
13
13
|
:intersection="draggableIntersections[i]"
|
|
14
|
-
:on-pointer-down="dragCtx.
|
|
14
|
+
:on-pointer-down="dragCtx.moveStart"
|
|
15
15
|
/>
|
|
16
16
|
</slot>
|
|
17
17
|
<slot name="indicator" v-bind="{ css: css.visible, intersection: draggableIntersections[i] }">
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
</template>
|
|
24
24
|
|
|
25
25
|
<script lang="ts" setup>
|
|
26
|
-
import {
|
|
26
|
+
import { moveContextInjectionKey, layoutContextInjectionKey } from "../types/vue.js"
|
|
27
27
|
import { computed, inject } from "vue"
|
|
28
28
|
|
|
29
29
|
|
|
@@ -40,7 +40,7 @@ defineOptions({
|
|
|
40
40
|
const ctx = inject(layoutContextInjectionKey, undefined)
|
|
41
41
|
if (!ctx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
42
42
|
|
|
43
|
-
const dragCtx = inject(
|
|
43
|
+
const dragCtx = inject(moveContextInjectionKey, undefined)
|
|
44
44
|
if (!dragCtx) throw new Error("LayoutEdges must be used within a LayoutWindow")
|
|
45
45
|
|
|
46
46
|
const draggableIntersections = computed(() => dragCtx.intersections.value
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
flex
|
|
8
8
|
flex-col
|
|
9
9
|
`,
|
|
10
|
-
|
|
10
|
+
isMoving && `dragging cursor-pointer user-select-none pointer-events-none`,
|
|
11
11
|
requestType && `request-${requestType}`,
|
|
12
12
|
($attrs as any).class
|
|
13
13
|
)"
|
|
@@ -23,25 +23,25 @@
|
|
|
23
23
|
</template>
|
|
24
24
|
</div>
|
|
25
25
|
<Teleport
|
|
26
|
-
v-if="
|
|
26
|
+
v-if="isMoving === 'frame' && movingFrameId && movePoint"
|
|
27
27
|
:to="ghostTeleportTo"
|
|
28
28
|
defer
|
|
29
29
|
>
|
|
30
30
|
<div
|
|
31
31
|
class="fixed z-[9999] pointer-events-none"
|
|
32
32
|
:style="{
|
|
33
|
-
left: (
|
|
34
|
-
top: (
|
|
35
|
-
width: frames[
|
|
36
|
-
? (frames[
|
|
33
|
+
left: (movePoint.x / settings.maxInt * win.pxWidth + win.pxX) + 'px',
|
|
34
|
+
top: (movePoint.y / settings.maxInt * win.pxHeight + win.pxY) + 'px',
|
|
35
|
+
width: frames[movingFrameId]
|
|
36
|
+
? (frames[movingFrameId].width / settings.maxInt * win.pxWidth) + 'px'
|
|
37
37
|
: undefined,
|
|
38
|
-
height: frames[
|
|
39
|
-
? (frames[
|
|
38
|
+
height: frames[movingFrameId]
|
|
39
|
+
? (frames[movingFrameId].height / settings.maxInt * win.pxHeight) + 'px'
|
|
40
40
|
: undefined
|
|
41
41
|
}"
|
|
42
42
|
>
|
|
43
43
|
<slot
|
|
44
|
-
:id="
|
|
44
|
+
:id="movingFrameId"
|
|
45
45
|
:name="`frame-drag-ghost`"
|
|
46
46
|
>
|
|
47
47
|
<div class="frame-drag-ghost border border-neutral-500 bg-white/50 w-10 h-10"/>
|
|
@@ -74,10 +74,10 @@ import { computed, markRaw, provide, reactive, ref, useAttrs, watch } from "vue"
|
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
import { useFrames } from "../composables/useFrames.js"
|
|
77
|
-
import { createDefaultHandlers } from "../
|
|
78
|
-
import {
|
|
79
|
-
import {
|
|
80
|
-
import { type
|
|
77
|
+
import { createDefaultHandlers } from "../move/createDefaultHandlers.js"
|
|
78
|
+
import { ActionHandler } from "../move/ActionHandler"
|
|
79
|
+
import { moveContextInjectionKey } from "../types/vue.js"
|
|
80
|
+
import { type MoveState, type IAction } from "../types/index.js"
|
|
81
81
|
import { getUpdateWindowSizeInfo } from "../layout/getUpdateWindowSizeInfo.js"
|
|
82
82
|
import { windowSetActiveFrame } from "../layout/windowSetActiveFrame.js"
|
|
83
83
|
import { type LayoutWindow } from "../types/index.js"
|
|
@@ -91,9 +91,9 @@ const win = defineModel<LayoutWindow>("win", { required: true })
|
|
|
91
91
|
|
|
92
92
|
const props = withDefaults(defineProps<{
|
|
93
93
|
/** If you really need it, you can provide your own drag action handler (remember to markRaw it), note the actionHandler's prop will no longer have any effect.*/
|
|
94
|
-
|
|
94
|
+
actionHandler?: ActionHandler<any, any>
|
|
95
95
|
/** Custom drag action handlers. Falls back to default split/close/frame handlers if not provided. */
|
|
96
|
-
actionHandlers?:
|
|
96
|
+
actionHandlers?: IAction[]
|
|
97
97
|
textHints?: {text:string, classes?:string}[]
|
|
98
98
|
textHintsTeleportTo: string | undefined
|
|
99
99
|
ghostTeleportTo?: string
|
|
@@ -113,8 +113,8 @@ const props = withDefaults(defineProps<{
|
|
|
113
113
|
allowWindowSizeUpdate: true
|
|
114
114
|
})
|
|
115
115
|
const emit = defineEmits<{
|
|
116
|
-
(e: "
|
|
117
|
-
(e: "
|
|
116
|
+
(e: "isShowingMove", value: boolean): void
|
|
117
|
+
(e: "moveState", value: MoveState): void
|
|
118
118
|
}>()
|
|
119
119
|
|
|
120
120
|
|
|
@@ -122,13 +122,13 @@ const windowEl = ref<HTMLElement | null>(null)
|
|
|
122
122
|
|
|
123
123
|
const requestType = ref<string | undefined | string>()
|
|
124
124
|
|
|
125
|
-
const
|
|
125
|
+
const actionHandler = props.actionHandler ?? markRaw(new ActionHandler(
|
|
126
126
|
[
|
|
127
127
|
...(props.actionHandlers ?? createDefaultHandlers())
|
|
128
128
|
],
|
|
129
129
|
{
|
|
130
130
|
onEvent: (e, cancel) => {
|
|
131
|
-
|
|
131
|
+
showMoving.value = true
|
|
132
132
|
if (e instanceof KeyboardEvent && e.key === "Escape") {
|
|
133
133
|
cancel()
|
|
134
134
|
}
|
|
@@ -138,29 +138,29 @@ const dragActionHandler = props.dragActionHandler ?? markRaw(new DragActionHandl
|
|
|
138
138
|
},
|
|
139
139
|
onEnd: () => {
|
|
140
140
|
requestType.value = undefined
|
|
141
|
-
|
|
141
|
+
showMoving.value = true
|
|
142
142
|
},
|
|
143
143
|
}
|
|
144
144
|
))
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const shapes =
|
|
145
|
+
actionHandler.shapes = reactive([])
|
|
146
|
+
actionHandler.textHints = reactive({ actions: [], errors: [] })
|
|
147
|
+
const shapes = actionHandler.shapes
|
|
148
148
|
|
|
149
149
|
const dragContext = useFrames(
|
|
150
150
|
win,
|
|
151
|
-
|
|
151
|
+
actionHandler
|
|
152
152
|
)
|
|
153
153
|
|
|
154
154
|
const {
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
movePoint,
|
|
156
|
+
isMoving,
|
|
157
157
|
frames,
|
|
158
158
|
state,
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
movingFrameId,
|
|
160
|
+
showMoving,
|
|
161
161
|
} = dragContext
|
|
162
162
|
|
|
163
|
-
provide(
|
|
163
|
+
provide(moveContextInjectionKey, dragContext)
|
|
164
164
|
|
|
165
165
|
function getWindowOffset() {
|
|
166
166
|
const windowElRect = windowEl.value!.getBoundingClientRect()
|
|
@@ -192,8 +192,8 @@ watch(() => props.allowWindowSizeUpdate, (newval, oldval) => {
|
|
|
192
192
|
})
|
|
193
193
|
|
|
194
194
|
|
|
195
|
-
watch(state, () => emit("
|
|
196
|
-
watch(
|
|
195
|
+
watch(state, () => emit("moveState", state.value))
|
|
196
|
+
watch(showMoving, () => emit("isShowingMove", showMoving.value))
|
|
197
197
|
|
|
198
198
|
const layoutContext = computed(() => {
|
|
199
199
|
return {
|
|
@@ -208,7 +208,7 @@ defineExpose({
|
|
|
208
208
|
state,
|
|
209
209
|
win,
|
|
210
210
|
getUpdateWindowSizeInfo,
|
|
211
|
-
|
|
211
|
+
actionHandler: actionHandler as ActionHandler<any, any>,
|
|
212
212
|
})
|
|
213
213
|
</script>
|
|
214
214
|
|