@witchcraft/layout 0.5.9 → 0.5.11
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 +2 -2
- 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.d.ts +2 -1370
- package/dist/runtime/composables/useFrames.d.ts +2 -1062
- package/dist/runtime/types/vue.d.ts +15 -18
- package/package.json +2 -2
- 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/composables/useFrames.ts +14 -10
- package/src/runtime/types/vue.ts +24 -5
|
@@ -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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@witchcraft/layout",
|
|
3
3
|
"description": "Headless layout manager.",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.11",
|
|
5
5
|
"main": "./dist/runtime/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@commitlint/cli": "^19.8.1",
|
|
54
54
|
"@nuxt/eslint-config": "^1.15.2",
|
|
55
55
|
"@nuxt/kit": "^4.4.6",
|
|
56
|
-
"@nuxt/module-builder": "^1.0.
|
|
56
|
+
"@nuxt/module-builder": "^1.0.3",
|
|
57
57
|
"@nuxt/schema": "^4.4.6",
|
|
58
58
|
"@nuxt/types": "^2.18.1",
|
|
59
59
|
"@tailwindcss/vite": "^4.3.0",
|
|
@@ -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)
|
|
@@ -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
|
-
TContextType extends keyof ExtendedMoveTypes,
|
|
159
|
-
TContext extends ExtendedMoveTypes[TContextType],
|
|
160
|
-
TContextReturn extends TContext extends { resolve: infer R } ? R : never,
|
|
161
|
-
TContextMoveType extends TContext extends { moveType: infer M } ? M : never,
|
|
162
|
-
TContextContext extends TContext extends { context: infer C } ? C : never
|
|
160
|
+
TContextType extends keyof ExtendedMoveTypes = keyof ExtendedMoveTypes,
|
|
161
|
+
TContext extends ExtendedMoveTypes[TContextType] = ExtendedMoveTypes[TContextType],
|
|
162
|
+
TContextReturn extends TContext extends { resolve: infer R } ? R : never = TContext extends { resolve: infer R } ? R : never,
|
|
163
|
+
TContextMoveType extends TContext extends { moveType: infer M } ? M : never = TContext extends { moveType: infer M } ? M : never,
|
|
164
|
+
TContextContext extends TContext extends { context: infer C } ? C : never = TContext extends { context: infer C } ? C : never,
|
|
165
|
+
// cursed https://github.com/microsoft/TypeScript/issues/23182
|
|
166
|
+
TType extends [TContextMoveType] extends [never] ? T : TContextMoveType = [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
|
{
|
|
@@ -172,7 +176,7 @@ export function useFrames(
|
|
|
172
176
|
}: {
|
|
173
177
|
moveEvent?: string
|
|
174
178
|
endEvent?: string
|
|
175
|
-
context?:
|
|
179
|
+
context?: TContextContext
|
|
176
180
|
} = {}
|
|
177
181
|
): TContext extends never
|
|
178
182
|
? Promise<void>
|
|
@@ -199,7 +203,7 @@ export function useFrames(
|
|
|
199
203
|
moveStartPoint = { ...point }
|
|
200
204
|
moveDirStore.update(point)
|
|
201
205
|
}
|
|
202
|
-
eventContext.value = context
|
|
206
|
+
eventContext.value = context as any
|
|
203
207
|
|
|
204
208
|
isMoving.value = type as any
|
|
205
209
|
showMoving.value = true
|
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[]>
|