UNPKG

@lyonbot/interactive-blocks

Version:

Make interactive selectable, drag-and-drop, copy-and-paste ready, Block and Slot components easily! Works with Vue, React and any MV* framework.

178 lines (177 loc) 6.57 kB
import type { BlockHandler } from "./BlockHandler"; import type { SlotHandler } from "./SlotHandler"; import type { BlockContext } from "./BlockContext"; export interface IBClipboardData { readonly isIBClipboardData: true; readonly ibContextBrand: string; readonly ibContextUUID?: string; readonly blocksData: any[]; } export declare function isIBClipboardData(data: any, limitToBrand?: string): data is IBClipboardData; export declare type IBPasteAction = InstanceType<typeof IBPasteAction>; export declare const IBPasteAction: new (data: { readonly type: "paste"; readonly ctx: BlockContext; readonly data: IBClipboardData; readonly slot: SlotHandler; readonly index: number; }) => { readonly type: "paste"; readonly ctx: BlockContext; readonly data: IBClipboardData; readonly slot: SlotHandler; readonly index: number; } & { preventDefault(): void; returnValue: boolean; }; export declare type IBCutAction = InstanceType<typeof IBCutAction>; export declare const IBCutAction: new (data: { readonly type: "cut"; readonly ctx: BlockContext; readonly slot: SlotHandler; /** the blocks to be cut, in selector order */ readonly blocks: BlockHandler[]; /** * the indexes of blocks to be cut, in selector order * * @see indexesDescending */ readonly indexes: number[]; /** * the indexes of blocks to be cut, in descending order * * the descending order may help you wipe out the items one-by-one safely: * * ```js * action.indexesDescending.forEach(index => { * array.splice(index, 1); * }) * ``` */ readonly indexesDescending: number[]; }) => { readonly type: "cut"; readonly ctx: BlockContext; readonly slot: SlotHandler; /** the blocks to be cut, in selector order */ readonly blocks: BlockHandler[]; /** * the indexes of blocks to be cut, in selector order * * @see indexesDescending */ readonly indexes: number[]; /** * the indexes of blocks to be cut, in descending order * * the descending order may help you wipe out the items one-by-one safely: * * ```js * action.indexesDescending.forEach(index => { * array.splice(index, 1); * }) * ``` */ readonly indexesDescending: number[]; } & { preventDefault(): void; returnValue: boolean; }; export declare type IBMoveInSlotAction = InstanceType<typeof IBMoveInSlotAction>; export declare const IBMoveInSlotAction: new (data: { readonly type: "moveInSlot"; readonly ctx: BlockContext; readonly slot: SlotHandler; /** source blocks. theirs ownerSlot is the same as current slot! */ readonly blocks: BlockHandler[]; /** position after removing blocks, before inserting */ readonly index: number; }) => { readonly type: "moveInSlot"; readonly ctx: BlockContext; readonly slot: SlotHandler; /** source blocks. theirs ownerSlot is the same as current slot! */ readonly blocks: BlockHandler[]; /** position after removing blocks, before inserting */ readonly index: number; } & { preventDefault(): void; returnValue: boolean; }; export declare type IBMoveBetweenSlotsAction = InstanceType<typeof IBMoveBetweenSlotsAction>; export declare const IBMoveBetweenSlotsAction: new (data: { readonly type: "moveBetweenSlots"; readonly ctx: BlockContext; readonly fromSlot: SlotHandler | null; /** source blocks. theirs ownerSlot is the same as fromSlot! */ readonly blocks: BlockHandler[]; readonly toSlot: SlotHandler; readonly index: number; }) => { readonly type: "moveBetweenSlots"; readonly ctx: BlockContext; readonly fromSlot: SlotHandler | null; /** source blocks. theirs ownerSlot is the same as fromSlot! */ readonly blocks: BlockHandler[]; readonly toSlot: SlotHandler; readonly index: number; } & { preventDefault(): void; returnValue: boolean; }; export declare type IBAction = IBPasteAction | IBCutAction | IBMoveInSlotAction | IBMoveBetweenSlotsAction; export declare type IBBlockDragStartAction = InstanceType<typeof IBBlockDragStartAction>; export declare const IBBlockDragStartAction: new (data: { readonly type: "blockDragStart"; readonly ctx: BlockContext; /** all selected blocks that will be dragged */ readonly blocks: readonly BlockHandler[]; /** the current block which fires dragStart event */ readonly currentBlock: BlockHandler; readonly event: DragEvent; readonly dataTransfer: DataTransfer; /** text content that writes to the dataTransfer. can be updated here. */ text: string; }) => { readonly type: "blockDragStart"; readonly ctx: BlockContext; /** all selected blocks that will be dragged */ readonly blocks: readonly BlockHandler[]; /** the current block which fires dragStart event */ readonly currentBlock: BlockHandler; readonly event: DragEvent; readonly dataTransfer: DataTransfer; /** text content that writes to the dataTransfer. can be updated here. */ text: string; } & { preventDefault(): void; returnValue: boolean; }; export declare type IBSlotBeforeDropAction = InstanceType<typeof IBSlotBeforeDropAction>; export declare const IBSlotBeforeDropAction: new (data: { readonly type: "slotBeforeDrop"; readonly ctx: BlockContext; readonly slot: SlotHandler; readonly indexToDrop: number; readonly isDraggingFromCurrentCtx: boolean; /** if drag source is from current BlockContext, this will be the array of current dragging blocks */ readonly draggingBlocks?: readonly BlockHandler[] | undefined; readonly event: DragEvent; readonly dropEffect: "none" | "copy" | "link" | "move"; readonly dataTransfer: DataTransfer; }) => { readonly type: "slotBeforeDrop"; readonly ctx: BlockContext; readonly slot: SlotHandler; readonly indexToDrop: number; readonly isDraggingFromCurrentCtx: boolean; /** if drag source is from current BlockContext, this will be the array of current dragging blocks */ readonly draggingBlocks?: readonly BlockHandler[] | undefined; readonly event: DragEvent; readonly dropEffect: "none" | "copy" | "link" | "move"; readonly dataTransfer: DataTransfer; } & { preventDefault(): void; returnValue: boolean; };