@witchcraft/layout
    Preparing search index...

    A drag action describes when and how to handle a drag event.

    For example, there are the default split/close actions that can be triggered in certain situations. This could be when holding down a modifier or key, or some other condition (e.g. the user is dragging a specific edge).

    Each action should handle it's configuration and saving/caching any state it needs. See SplitAction and CloseAction for examples.

    Implements

    Index

    Constructors

    • Parameters

      • handleEvent: (e: PointerEvent | KeyboardEvent, state: DragState) => boolean | "force"
      • updateCloseDecos: (decos: { force?: boolean; id: string; type: "close" }[]) => void
      • hooks: {
            onCancel?: () => void;
            onError?: (e: KnownError) => void;
            onStart?: (active: boolean) => void;
        } = {}

      Returns CloseAction

    Properties

    handleEvent: (
        e: PointerEvent | KeyboardEvent,
        state: DragState,
    ) => boolean | "force"
    hooks: {
        onCancel?: () => void;
        onError?: (e: KnownError) => void;
        onStart?: (active: boolean) => void;
    }
    name: "close" = ...

    A unique name for your action.

    state:
        | {
            allowed: true;
            cacheKey: undefined
            | string;
            force: boolean;
            res: { deletedFrames: LayoutFrame[]; modifiedFrames: LayoutFrame[] };
        }
        | {
            allowed: false;
            cacheKey: undefined
            | string;
            force: boolean;
            res:
                | undefined
                | { deletedFrames: LayoutFrame[]; modifiedFrames: LayoutFrame[] };
        } = ...
    updateCloseDecos: (
        decos: { force?: boolean; id: string; type: "close" }[],
    ) => void

    Methods

    • Should return true if it should handle the "request"/event (e.g. some modifier is being pressed => user is requesting x action).

      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.

      Here is where you should initiate your state. Don't allow the action by default unless it can always be allowed.

      Parameters

      • e: PointerEvent | KeyboardEvent
      • state: DragState

      Returns boolean

    • Is called after onDragChange("end") with the same event. Might not be called if the request was cancelled.

      You should apply your action if possible and return whether it was applied.

      This is also a good place to reset your state.

      Parameters

      Returns boolean

    • Called when the drag coordinates change (during any event). Should return true to allow the edges to be moved, or false to prevent it.

      Can be used to save some context/info to later apply safely during onDragApply.

      Parameters

      • _type: "start" | "move" | "end"
      • _e: undefined | PointerEvent
      • state: DragState

      Returns boolean