@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
|
@@ -246,18 +246,18 @@ const zCloseDeco = zBaseDeco.extend({
|
|
|
246
246
|
export type CloseDeco = z.infer<typeof zCloseDeco>
|
|
247
247
|
|
|
248
248
|
|
|
249
|
-
const
|
|
249
|
+
const zFrameDeco = zBaseDeco.extend({
|
|
250
250
|
id: z.uuid(),
|
|
251
251
|
type: z.literal("drop"),
|
|
252
252
|
position: zSide.or(z.enum(["center"]))
|
|
253
253
|
})
|
|
254
254
|
|
|
255
|
-
export type
|
|
255
|
+
export type FrameDeco = z.infer<typeof zFrameDeco>
|
|
256
256
|
|
|
257
257
|
export const zDeco = z.union([
|
|
258
258
|
zSplitDeco,
|
|
259
259
|
zCloseDeco,
|
|
260
|
-
|
|
260
|
+
zFrameDeco
|
|
261
261
|
])
|
|
262
262
|
|
|
263
263
|
export type Deco = z.infer<typeof zDeco>
|
|
@@ -331,19 +331,19 @@ export type LayoutErrorsInfo = {
|
|
|
331
331
|
frame: LayoutFrame
|
|
332
332
|
}
|
|
333
333
|
[LAYOUT_ERROR.CANT_REARRANGE_TO_SAME_RELATIVE_POSITION]: {
|
|
334
|
-
|
|
334
|
+
movingFrameId: string
|
|
335
335
|
hoveredFrameId: string
|
|
336
|
-
zoneSide:
|
|
336
|
+
zoneSide: Zone["side"]
|
|
337
337
|
}
|
|
338
338
|
[LAYOUT_ERROR.CANT_REARRANGE_WITH_DOCKED_EDGES]: {
|
|
339
|
-
|
|
339
|
+
movingFrameId: string
|
|
340
340
|
hoveredFrameId: string
|
|
341
|
-
zoneSide:
|
|
341
|
+
zoneSide: Zone["side"]
|
|
342
342
|
}
|
|
343
343
|
[LAYOUT_ERROR.CANT_REARRANGE_DOCKED_WITH_NON_DOCKED]: {
|
|
344
|
-
|
|
344
|
+
movingFrameId: string
|
|
345
345
|
hoveredFrameId: string
|
|
346
|
-
zoneSide:
|
|
346
|
+
zoneSide: Zone["side"]
|
|
347
347
|
}
|
|
348
348
|
[LAYOUT_ERROR.CANT_SPLIT_DOCKED_FRAME]: {
|
|
349
349
|
frame: LayoutFrame
|
|
@@ -389,7 +389,7 @@ export type LayoutErrorsInfo = {
|
|
|
389
389
|
export type HasOpposite = Direction | EdgeSide | ExtendedDirection | ExtendedEdgeSide | keyof Point | keyof Size
|
|
390
390
|
|
|
391
391
|
|
|
392
|
-
export type
|
|
392
|
+
export type BaseZone = {
|
|
393
393
|
x: number
|
|
394
394
|
y: number
|
|
395
395
|
width: number
|
|
@@ -398,17 +398,17 @@ export type BaseDragZone = {
|
|
|
398
398
|
pxHeight: number
|
|
399
399
|
}
|
|
400
400
|
|
|
401
|
-
export type
|
|
401
|
+
export type FrameZone = BaseZone & {
|
|
402
402
|
type: "frame"
|
|
403
403
|
side: EdgeSide | "center"
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
-
export type WindowEdgeZone =
|
|
406
|
+
export type WindowEdgeZone = BaseZone & {
|
|
407
407
|
type: "window"
|
|
408
408
|
side: EdgeSide
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
-
export type
|
|
411
|
+
export type Zone = FrameZone | WindowEdgeZone
|
|
412
412
|
|
|
413
413
|
export const zWindowCreate = zLayoutWindowLoose
|
|
414
414
|
.partial({ id: true, pxWidth: true, pxHeight: true, pxX: true, pxY: true })
|
|
@@ -441,33 +441,33 @@ export type LayoutChange<TInfo = never> = {
|
|
|
441
441
|
window?: Partial<LayoutWindow>
|
|
442
442
|
info?: TInfo
|
|
443
443
|
}
|
|
444
|
-
export type
|
|
444
|
+
export type MoveState = {
|
|
445
445
|
/** The current directions in the corresponding orientations that the user is dragging in. */
|
|
446
|
-
|
|
446
|
+
moveDirections: Record<Orientation, Direction | undefined>
|
|
447
447
|
/** The curren point (in scaled window coordinates) the user is dragging at. */
|
|
448
|
-
|
|
448
|
+
movePoint?: Point
|
|
449
449
|
/** Cumulative pixel distance the user has dragged from the initial click point. 0 on start, increases on each move. */
|
|
450
|
-
|
|
450
|
+
moveDistance: number
|
|
451
451
|
/** Whether the user is currently dragging and what type of drag. Is truthy string during all drag events. */
|
|
452
|
-
|
|
452
|
+
isMoving: boolean | "frame" | "edge"
|
|
453
453
|
/** Whether to show the moved frames while dragging. */
|
|
454
|
-
|
|
455
|
-
/** The frame being dragged during a frame drag. Only set when
|
|
456
|
-
|
|
454
|
+
showMoving: boolean
|
|
455
|
+
/** The frame being dragged during a frame drag. Only set when isMoving is "frame". */
|
|
456
|
+
movingFrameId?: FrameId
|
|
457
457
|
/**
|
|
458
458
|
* The edges that are currently being dragged. There are multiple edges if they drag an intersection since what's actually happening is we're just dragging the closest horizontal and vertical edges.
|
|
459
459
|
*/
|
|
460
|
-
|
|
460
|
+
movingEdges: Edge[]
|
|
461
461
|
/**
|
|
462
462
|
* The intersection that is currently being dragged.
|
|
463
463
|
*/
|
|
464
|
-
|
|
464
|
+
movingIntersection?: IntersectionEntry
|
|
465
465
|
/** The "visual" edges that can be displayed for dragging. See {@link getVisualEdges} */
|
|
466
466
|
visualEdges: Edge[]
|
|
467
467
|
/**
|
|
468
468
|
* The frames touching the currently dragged edges. Each entry corresponds to the frames touching the corresponding dragging edge.
|
|
469
469
|
*
|
|
470
|
-
* So you can use the index in
|
|
470
|
+
* So you can use the index in movingEdges to get the corresponding frames.
|
|
471
471
|
*/
|
|
472
472
|
touchingFrames: Record<string, LayoutFrame>[]
|
|
473
473
|
/**
|
|
@@ -475,13 +475,13 @@ export type DragState = {
|
|
|
475
475
|
*/
|
|
476
476
|
touchingFramesArrays: LayoutFrame[][]
|
|
477
477
|
/**
|
|
478
|
-
* All the frames, with/without the currently dragged frames depending on if `
|
|
478
|
+
* All the frames, with/without the currently dragged frames depending on if `showMoving` is true.
|
|
479
479
|
*/
|
|
480
480
|
frames: Record<string, LayoutFrame>
|
|
481
481
|
/**
|
|
482
|
-
* The frame that is currently being hovered over (according to whether `
|
|
482
|
+
* The frame that is currently being hovered over (according to whether `movePoint` in in the frame or not).
|
|
483
483
|
*/
|
|
484
|
-
|
|
484
|
+
moveHoveredFrame: LayoutFrame | undefined
|
|
485
485
|
/**
|
|
486
486
|
* A list of corner intersections. Frames can also be dragged by these.
|
|
487
487
|
*/
|
|
@@ -489,22 +489,22 @@ export type DragState = {
|
|
|
489
489
|
/**
|
|
490
490
|
* Whether the drag was initiated from a point along the window edge.
|
|
491
491
|
*/
|
|
492
|
-
|
|
493
|
-
/** Custom context passed to
|
|
492
|
+
isMovingFromWindowEdge: boolean
|
|
493
|
+
/** Custom context passed to moveStart, available to action handlers via state.eventContext. */
|
|
494
494
|
eventContext?: Record<string, unknown>
|
|
495
495
|
win: LayoutWindow
|
|
496
496
|
}
|
|
497
497
|
|
|
498
498
|
|
|
499
|
-
export interface
|
|
499
|
+
export interface ActionChangeResult {
|
|
500
500
|
/** Whether the drag should update the edges. Defaults to false. */
|
|
501
501
|
updateEdges?: boolean
|
|
502
502
|
/** Deco shapes produced by this action during this drag step. */
|
|
503
503
|
shapes: LayoutShape[]
|
|
504
504
|
/** Whether to show the moved edges while dragging. Defaults to true. */
|
|
505
|
-
|
|
505
|
+
showMoving?: boolean
|
|
506
506
|
}
|
|
507
|
-
export type
|
|
507
|
+
export type MoveChangeResult = Omit<ActionChangeResult, "shapes">
|
|
508
508
|
|
|
509
509
|
/**
|
|
510
510
|
* Called when the drag coordinates change (during any event).
|
|
@@ -512,14 +512,21 @@ export type DragChangeResult = Omit<ActionDragChangeResult, "shapes">
|
|
|
512
512
|
* Should return `{ allowed: true/false, shapes: LayoutShape[] }` to control whether the action is allowed and edges update and what deco shapes to render.
|
|
513
513
|
*
|
|
514
514
|
* Note that the allowed return type only affect the `move` event but is also typed as `boolean` for other events for ease of use.
|
|
515
|
+
*
|
|
516
|
+
* Use also to cleanup your action when type is "end".
|
|
517
|
+
*
|
|
518
|
+
* See also {@link ActionHandler.onMoveChange} to understand it's lifecycle as it is the extended version of.
|
|
515
519
|
*/
|
|
516
|
-
export type
|
|
520
|
+
export type MoveChangeHandler = <T extends "start" | "move" | "end">(
|
|
517
521
|
type: T,
|
|
518
522
|
e: T extends "end" ? PointerEvent | undefined : PointerEvent,
|
|
519
|
-
state:
|
|
523
|
+
state: MoveState,
|
|
520
524
|
forceRecalculateEdges: () => void,
|
|
521
|
-
|
|
522
|
-
) =>
|
|
525
|
+
/** Calls moveEnd with apply: false. This can technically be called from "end", it should still work. */
|
|
526
|
+
cancel: (e: PointerEvent | KeyboardEvent | undefined, state: MoveState) => void,
|
|
527
|
+
/** Saves result to resolve moveStart promise with then calls moveEnd with given apply. Not available during "end" event. It's designed for resolving from other external evente (e.g. key events). */
|
|
528
|
+
resolve: T extends "end" ? undefined : ({ apply, result }: { apply: boolean, result: any }) => void
|
|
529
|
+
) => ActionChangeResult
|
|
523
530
|
|
|
524
531
|
/**
|
|
525
532
|
* A drag action describes when and how to handle a drag event.
|
|
@@ -529,19 +536,21 @@ export type DragChangeHandler = <T extends "start" | "move" | "end">(
|
|
|
529
536
|
* Each action should handle it's configuration and saving/caching any state it needs. See {@link SplitAction} and {@link CloseAction} for examples.
|
|
530
537
|
*/
|
|
531
538
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
532
|
-
export interface
|
|
539
|
+
export interface IAction {
|
|
533
540
|
/** A unique name for your action. */
|
|
534
541
|
name: string
|
|
535
|
-
|
|
542
|
+
onMoveChange: MoveChangeHandler
|
|
536
543
|
/**
|
|
537
544
|
*
|
|
538
|
-
* Is called
|
|
545
|
+
* Is called before `onMoveChange("end")` with the same event. Might not be called if the request was cancelled.
|
|
539
546
|
*
|
|
540
547
|
* You should apply your action if possible and return whether it was applied.
|
|
541
548
|
*
|
|
542
|
-
*
|
|
549
|
+
* Do not reset state here, use onMoveChange ("end").
|
|
550
|
+
*
|
|
551
|
+
* See also {@link ActionHandler.onMoveApply} which this is the extended version of.
|
|
543
552
|
*/
|
|
544
|
-
|
|
553
|
+
onMoveApply: (state: MoveState, forceRecalculateEdges: () => void) => boolean
|
|
545
554
|
/**
|
|
546
555
|
* Should return true if it should handle the "request"/event (e.g. some modifier is being pressed => user is requesting x action).
|
|
547
556
|
*
|
|
@@ -551,22 +560,16 @@ export interface IDragAction {
|
|
|
551
560
|
*/
|
|
552
561
|
canHandleRequest(
|
|
553
562
|
e: KeyboardEvent | PointerEvent,
|
|
554
|
-
state:
|
|
563
|
+
state: MoveState,
|
|
555
564
|
forceRecalculateEdges: () => void
|
|
556
565
|
): boolean
|
|
557
566
|
/**
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
* You should reset your state here.
|
|
561
|
-
*/
|
|
562
|
-
cancel(e: PointerEvent | KeyboardEvent | undefined, state: DragState): void
|
|
563
|
-
/**
|
|
564
|
-
* Plugins should implement some basic debug logs by calling {@link DragActionHandler.debugState } at least before and after applying actions in onDragApply. Debug can be a string because it can be an object key to filter on (see the debugState function).
|
|
567
|
+
* 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).
|
|
565
568
|
*
|
|
566
569
|
*
|
|
567
570
|
* Calls look like this usually, where this.state is the plugin state:
|
|
568
571
|
* ```ts
|
|
569
|
-
*
|
|
572
|
+
* ActionHandler.debugState(this.name, "before", state, this.state, this.debug)
|
|
570
573
|
* ```
|
|
571
574
|
*/
|
|
572
575
|
debug: boolean | string
|
|
@@ -584,6 +587,11 @@ export interface IDragAction {
|
|
|
584
587
|
/** Error texts/hints to display when the action produces an error. */
|
|
585
588
|
errors?: string[]
|
|
586
589
|
}
|
|
590
|
+
/**
|
|
591
|
+
* Called when an action is cancelled. Call action specific onCancel hooks here.
|
|
592
|
+
*/
|
|
593
|
+
// note: internally this is done by the actionhandler wrapping the given cancel function for an event
|
|
594
|
+
cancel(e: PointerEvent | KeyboardEvent | undefined, state: MoveState): void
|
|
587
595
|
/**
|
|
588
596
|
* Called after visual edges are recalculated, once per edge. Action handlers can annotate edges with error info here ({@link Edge.error}).
|
|
589
597
|
*
|
|
@@ -605,35 +613,48 @@ export interface IDragAction {
|
|
|
605
613
|
*/
|
|
606
614
|
annotateEdge?(edge: Edge, frames: LayoutFrame[]): void
|
|
607
615
|
}
|
|
608
|
-
export type
|
|
609
|
-
export type
|
|
616
|
+
export type EdgeMoveStartData = { edge?: Edge, intersection?: IntersectionEntry }
|
|
617
|
+
export type FrameMoveStartData = { frameId: FrameId }
|
|
618
|
+
|
|
619
|
+
export type ActionHandlerApplyResult = {
|
|
620
|
+
/** Whether to apply the regular drag end changes. Return false to reset to the position before dragging. */
|
|
621
|
+
apply: boolean
|
|
622
|
+
/** Value to resolve the drag promise with. Ignored if `apply` is false. */
|
|
623
|
+
result: any
|
|
624
|
+
}
|
|
610
625
|
|
|
611
626
|
/**
|
|
612
627
|
* Handler interface for drag actions.
|
|
613
628
|
*/
|
|
614
629
|
export interface ActionHandler {
|
|
615
|
-
eventHandler: (e: KeyboardEvent, state:
|
|
630
|
+
eventHandler: (e: KeyboardEvent, state: MoveState, forceRecalculateEdges: () => void) => void
|
|
616
631
|
/**
|
|
617
|
-
* Called when the drag coordinates change (during any event). Should return true to allow the edges to be updated/moved, or false to prevent it.
|
|
632
|
+
* Called when the drag coordinates change (during any event). Should return true to allow the edges to be updated/moved, or false to prevent it. See also {@link MoveChangeHandler} for the built in action handler.
|
|
618
633
|
*
|
|
619
|
-
* Can
|
|
634
|
+
* Can be used to save some context/info to later apply safely during onMoveApply.
|
|
620
635
|
*
|
|
621
|
-
*
|
|
636
|
+
* The call order is:
|
|
637
|
+
* - onMoveChange("start", ...)
|
|
638
|
+
* - onMoveChange("move", ...)
|
|
639
|
+
* - onMoveChange("end", ...)
|
|
640
|
+
* - onMoveApply(...) (IF moveEnd was called with apply: true, otherwise this is skipped)
|
|
641
|
+
* - onMoveEnded() // do cleanup here
|
|
622
642
|
*/
|
|
623
|
-
|
|
643
|
+
onMoveChange: (...args: Parameters<MoveChangeHandler>) => MoveChangeResult
|
|
624
644
|
/**
|
|
625
|
-
* Called when drag will be applied. If
|
|
645
|
+
* Called when drag will be applied. If moveEnd was called with apply false, it will not be called.
|
|
626
646
|
* Return false to not apply the regular drag end changes (i.e. return false to reset to the position before dragging).
|
|
647
|
+
*
|
|
648
|
+
* Do not use for resetting handler state, use onMoveEnded for that.
|
|
627
649
|
*/
|
|
628
|
-
|
|
629
|
-
state:
|
|
650
|
+
onMoveApply: (
|
|
651
|
+
state: MoveState,
|
|
630
652
|
forceRecalculateEdges: () => void
|
|
631
|
-
) =>
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
}
|
|
653
|
+
) => ActionHandlerApplyResult
|
|
654
|
+
|
|
655
|
+
/** For doing cleanup */
|
|
656
|
+
onMoveEnded: () => void
|
|
657
|
+
|
|
637
658
|
/**
|
|
638
659
|
* Called after visual edges are recalculated. Action handlers can annotate edges with error info.
|
|
639
660
|
*/
|
|
@@ -641,9 +662,9 @@ export interface ActionHandler {
|
|
|
641
662
|
}
|
|
642
663
|
|
|
643
664
|
// drag start overloads for triggering dragsj
|
|
644
|
-
export type
|
|
645
|
-
(e: PointerEvent, type: "edge", data:
|
|
646
|
-
(e: PointerEvent, type: "frame", data:
|
|
665
|
+
export type MoveStartFn = {
|
|
666
|
+
(e: PointerEvent, type: "edge", data: EdgeMoveStartData): void
|
|
667
|
+
(e: PointerEvent, type: "frame", data: FrameMoveStartData): void
|
|
647
668
|
}
|
|
648
669
|
|
|
649
670
|
export type * from "./vue.js"
|
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 { ActionHandler,
|
|
4
|
+
import type { ActionHandler, ActionHandlerApplyResult, Direction, Edge, FrameId, IntersectionEntry, LayoutFrame, LayoutShape, LayoutWindow, MoveState, Orientation, Point } from "./index.js"
|
|
5
5
|
|
|
6
6
|
export type LayoutContext = ComputedRef<
|
|
7
7
|
& {
|
|
@@ -16,28 +16,28 @@ export const layoutContextInjectionKey = Symbol.for("@witchcraft/layout:context"
|
|
|
16
16
|
|
|
17
17
|
export interface UseFramesContext {
|
|
18
18
|
actionHandler: ActionHandler
|
|
19
|
-
|
|
19
|
+
moveStart: {
|
|
20
20
|
(e: PointerEvent, type: "edge", data: { edge?: Edge, intersection?: IntersectionEntry }, opts?: { moveEvent?: string, endEvent?: string, context?: Record<string, unknown> }): Promise<any>
|
|
21
21
|
(e: PointerEvent, type: "frame", data: { frameId: FrameId }, opts?: { moveEvent?: string, endEvent?: string, context?: Record<string, unknown> }): Promise<any>
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
onMove: (e: PointerEvent) => void
|
|
24
|
+
moveEnd: (e?: PointerEvent, options?: Partial<Pick<ActionHandlerApplyResult, "apply">>) => void
|
|
25
25
|
cancel: () => void
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
moveDirections: Ref<Record<Orientation, Direction | undefined>>
|
|
27
|
+
movePoint: Ref<Point | undefined>
|
|
28
|
+
isMoving: Ref<false | "frame" | "edge">
|
|
29
|
+
movingEdges: Ref<Edge[]>
|
|
30
|
+
movingIntersection: Ref<IntersectionEntry | undefined>
|
|
31
31
|
visualEdges: Ref<Edge[]>
|
|
32
32
|
touchingFrames: Ref<Record<string, LayoutFrame>[]>
|
|
33
33
|
touchingFramesArrays: Ref<LayoutFrame[][]>
|
|
34
34
|
frames: ComputedRef<Record<string, LayoutFrame>>
|
|
35
|
-
|
|
35
|
+
moveHoveredFrame: ComputedRef<LayoutFrame | undefined>
|
|
36
36
|
intersections: ComputedRef<IntersectionEntry[]>
|
|
37
|
-
|
|
37
|
+
isMovingFromWindowEdge: Ref<boolean>
|
|
38
38
|
forceRecalculateEdges: () => void
|
|
39
|
-
state: ComputedRef<
|
|
40
|
-
|
|
39
|
+
state: ComputedRef<MoveState>
|
|
40
|
+
movingFrameId: Ref<FrameId | undefined>
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export const
|
|
43
|
+
export const moveContextInjectionKey = Symbol.for("@witchcraft/layout:moveContext") as InjectionKey<UseFramesContext>
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { DragState, DragZone } from "../types/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Find the drag zone under the drag point.
|
|
4
|
-
*/
|
|
5
|
-
export declare function getDragZones(state: Pick<DragState, "dragPoint" | "dragHoveredFrame" | "frames" | "win">, { frameEdgePx, windowEdgePx }: {
|
|
6
|
-
frameEdgePx: number;
|
|
7
|
-
windowEdgePx: number;
|
|
8
|
-
}): DragZone | undefined;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { getFrameDragZones } from "./getFrameDragZones.js";
|
|
2
|
-
import { getWindowDragZones } from "./getWindowDragZones.js";
|
|
3
|
-
import { isPointInRect } from "./isPointInRect.js";
|
|
4
|
-
export function getDragZones(state, { frameEdgePx, windowEdgePx }) {
|
|
5
|
-
const { dragPoint, win } = state;
|
|
6
|
-
const frameId = state.dragHoveredFrame?.id;
|
|
7
|
-
if (!frameId) return;
|
|
8
|
-
const frame = state.frames[frameId];
|
|
9
|
-
if (!frame || !dragPoint) return;
|
|
10
|
-
const frameZones = getFrameDragZones(frame, frameEdgePx, win.pxWidth, win.pxHeight);
|
|
11
|
-
const windowZones = getWindowDragZones(win, windowEdgePx);
|
|
12
|
-
let matchedZone;
|
|
13
|
-
for (const zone of windowZones) {
|
|
14
|
-
if (isPointInRect(zone, dragPoint)) {
|
|
15
|
-
matchedZone = {
|
|
16
|
-
...zone,
|
|
17
|
-
type: "window"
|
|
18
|
-
};
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
if (!matchedZone) {
|
|
23
|
-
for (const zone of frameZones) {
|
|
24
|
-
if (isPointInRect(zone, dragPoint)) {
|
|
25
|
-
matchedZone = zone;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (!matchedZone) return void 0;
|
|
31
|
-
return matchedZone;
|
|
32
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { getFrameDragZones } from "./getFrameDragZones.js"
|
|
2
|
-
import { getWindowDragZones } from "./getWindowDragZones.js"
|
|
3
|
-
import { isPointInRect } from "./isPointInRect.js"
|
|
4
|
-
|
|
5
|
-
import type { DragState, DragZone, WindowEdgeZone } from "../types/index.js"
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Find the drag zone under the drag point.
|
|
9
|
-
*/
|
|
10
|
-
export function getDragZones(
|
|
11
|
-
state: Pick<DragState, "dragPoint" | "dragHoveredFrame" | "frames" | "win">,
|
|
12
|
-
{ frameEdgePx, windowEdgePx }: { frameEdgePx: number, windowEdgePx: number }
|
|
13
|
-
): DragZone | undefined {
|
|
14
|
-
const { dragPoint, win } = state
|
|
15
|
-
const frameId = state.dragHoveredFrame?.id
|
|
16
|
-
if (!frameId) return
|
|
17
|
-
|
|
18
|
-
const frame = state.frames[frameId]
|
|
19
|
-
if (!frame || !dragPoint) return
|
|
20
|
-
|
|
21
|
-
const frameZones = getFrameDragZones(frame, frameEdgePx, win.pxWidth, win.pxHeight)
|
|
22
|
-
|
|
23
|
-
const windowZones = getWindowDragZones(win, windowEdgePx)
|
|
24
|
-
|
|
25
|
-
let matchedZone: DragZone | undefined
|
|
26
|
-
for (const zone of windowZones) {
|
|
27
|
-
if (isPointInRect(zone, dragPoint)) {
|
|
28
|
-
matchedZone = {
|
|
29
|
-
...zone,
|
|
30
|
-
type: "window"
|
|
31
|
-
} as WindowEdgeZone
|
|
32
|
-
break
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!matchedZone) {
|
|
37
|
-
for (const zone of frameZones) {
|
|
38
|
-
if (isPointInRect(zone, dragPoint)) {
|
|
39
|
-
matchedZone = zone
|
|
40
|
-
break
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (!matchedZone) return undefined
|
|
46
|
-
|
|
47
|
-
return matchedZone
|
|
48
|
-
}
|
|
File without changes
|