Moveable
    Preparing search index...

    Interface MoveableInterface

    interface MoveableInterface {
        destroy(): void;
        dragStart(e: MouseEvent | TouchEvent, target?: EventTarget | null): void;
        forceUpdate(callback?: () => any): any;
        getAble<T extends Able<IObject<any>, IObject<any>>>(
            ableName: string,
        ): T | undefined;
        getControlBoxElement(): HTMLElement;
        getDragElement(): SVGElement | HTMLElement | null | undefined;
        getManager(): MoveableManagerInterface<any, any>;
        getMoveables(): MoveableManagerInterface<{}, {}>[];
        getRect(): RectInfo;
        getTargets(): (SVGElement | HTMLElement)[];
        hitTest(el: Element | HitRect): number;
        isDragging(ableName?: string): boolean;
        isInside(clientX: number, clientY: number): boolean;
        isMoveableElement(target: Element): boolean;
        request<
            RequestParam extends AbleRequestParam,
            Name extends string = string,
        >(
            ableName: Name,
            params?: RequestParam,
            isInstant?: boolean,
        ): Requester<RequestParam>;
        setState(state: any, callback?: () => any): any;
        stopDrag(type?: "target" | "control"): void;
        updateRect(
            type?: "" | "Start" | "End",
            isTarget?: boolean,
            isSetState?: boolean,
        ): void;
        updateSelectors(): void;
        updateTarget(): void;
        waitToChangeTarget(): Promise<void>;
    }

    Hierarchy (View Summary)

    Index
    • Remove the Moveable object and the events.

      Returns void

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body);

      moveable.destroy();
    • You can drag start the Moveable through the external MouseEventor TouchEvent. (Angular: ngDragStart)

      Parameters

      • e: MouseEvent | TouchEvent

        external MouseEventor TouchEvent

      • Optionaltarget: EventTarget | null

      Returns void

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body);

      document.body.addEventListener("mousedown", e => {
      if (!moveable.isMoveableElement(e.target)) {
      moveable.dragStart(e);
      }
      });
    • Get the able used in MoveableManager.

      Type Parameters

      • T extends Able<IObject<any>, IObject<any>>

      Parameters

      • ableName: string

        able name

      Returns T | undefined

    • Target element to be dragged in moveable

      Returns SVGElement | HTMLElement | null | undefined

    • You can get the vertex information, position and offset size information of the target based on the container.

      Returns RectInfo

      The Rect Info

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body);

      const rectInfo = moveable.getRect();
    • Get targets set in moveable through target or targets of props.

      Returns (SVGElement | HTMLElement)[]

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body, {
      target: [targetRef, ".target", document.querySelectorAll(".target")],
      });

      console.log(moveable.getTargets());
    • Hit test an element or rect on a moveable target. (100% = 100)

      Parameters

      • el: Element | HitRect

        element or rect to test

      Returns number

      Get hit test rate (rate > 0 is hitted)

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body);

      document.body.addEventListener("mousedown", e => {
      if (moveable.hitTest(e.target) > 0) {
      console.log("hiited");
      }
      });
    • Check if the moveable state is being dragged.

      Parameters

      • OptionalableName: string

        If you want to check if able is dragging, specify ableName.

      Returns boolean

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body);

      // false
      console.log(moveable.isDragging());

      moveable.on("drag", () => {
      // true
      console.log(moveable.isDragging());
      });
    • Whether the coordinates are inside Moveable

      Parameters

      • clientX: number

        x coordinate

      • clientY: number

        y coordinate

      Returns boolean

      True if the coordinate is in moveable or false

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body);

      document.body.addEventListener("mousedown", e => {
      if (moveable.isInside(e.clientX, e.clientY)) {
      console.log("inside");
      }
      });
    • Check if the target is an element included in the moveable.

      Parameters

      • target: Element

        the target

      Returns boolean

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body);

      window.addEventListener("click", e => {
      if (!moveable.isMoveableElement(e.target)) {
      moveable.target = e.target;
      }
      });
    • Request able through a method rather than an event. At the moment of execution, requestStart is executed, and then request and requestEnd can be executed through Requester.

      Type Parameters

      Parameters

      • ableName: Name

        ableName

      • Optionalparams: RequestParam

        request to be able params.

      • OptionalisInstant: boolean

        If isInstant is true, request and requestEnd are executed immediately.

      Returns Requester<RequestParam>

      Able Requester. If there is no request in able, nothing will work.

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body);

      // Instantly Request (requestStart - request - requestEnd)
      moveable.request("draggable", { deltaX: 10, deltaY: 10 }, true);

      // Start move
      const requester = moveable.request("draggable");
      requester.request({ deltaX: 10, deltaY: 10 });
      requester.request({ deltaX: 10, deltaY: 10 });
      requester.request({ deltaX: 10, deltaY: 10 });
      requester.requestEnd();
    • You can stop the dragging currently in progress through a method from outside.

      Parameters

      • Optionaltype: "target" | "control"

      Returns void

      The Rect Info

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body);

      moveable.stopDrag();
    • If the location or size of the target is changed, call the .updateRect() method. Use the useResizeObserver and useMutationObserver props to update automatically.

      If the width, height, left, and top of all elements change, update the shape of the moveable.

      Parameters

      • Optionaltype: "" | "Start" | "End"
      • OptionalisTarget: boolean
      • OptionalisSetState: boolean

      Returns void

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body);

      window.addEventListener("resize", e => {
      moveable.updateRect();
      });
    • If the element list corresponding to the selector among the targets is changed, it is updated.

      Returns void

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body, {
      target: ".target",
      });

      moveable.updateSelectors();
    • If the width, height, left, and top of the only target change, update the shape of the moveable. Use .updateRect() method

      Returns void

      Use .updateRect() method

      import Moveable from "@moveable-next/vanilla";

      const moveable = new Moveable(document.body);

      moveable.updateTarget();
    • User changes target and waits for target to change.

      Returns Promise<void>

      document.querySelector(".target").addEventListener("mousedown", e => {
      moveable.waitToChangeTarget().then(() => {
      moveable.dragStart(e, e.currentTarget);
      });
      moveable.target = e.currentTarget;
      });