import type { DraggableItemTypes, DraggableItem } from '../types/draggable.js'; import type { BlokkliFieldElement, BlokkliItemHost } from '#blokkli/editor/types/field'; import type { DropArea } from '#blokkli/editor/types/ui'; type MaybePromise = T | Promise; export type DropResolveContext = { items: DraggableItemTypes[K][]; field: BlokkliFieldElement; host: BlokkliItemHost; afterUuid: string | null; }; export type DropExecuteContext = DropResolveContext & { bundle: string; }; export type DropExecuteResult = { /** If true, the dispatcher will focus the editable field after the block is added. */ focusEditable?: boolean; }; export type DropHandler = { /** * Optional. Called at drop time to refine which bundles are applicable. * Can read DataTransfer, detect content types, re-map via clipboardMapBundle, etc. * Returns the refined list of possible bundles. * If omitted, the overlay calls execute() directly without bundle resolution. */ resolveBundles?: (ctx: DropResolveContext) => string[] | Promise; /** * Called to perform the actual mutation. * If resolveBundles was provided, `ctx.bundle` is the resolved bundle * (either the single result or the user's BundleSelector pick). */ execute: (ctx: DropExecuteContext) => MaybePromise; }; type DropAreaProviderFunction = (items: DraggableItem[]) => DropArea[] | DropArea | undefined; export type DragDropProvider = { registerDropHandler: (itemType: K, handler: DropHandler) => void; unregisterDropHandler: (itemType: K, handler: DropHandler) => void; getDropHandler: (itemType: K) => DropHandler | undefined; /** * Register a drop area provider function. * * The function will be called when drop areas are requested during drag operations. * It receives the currently dragged items and can return drop areas where those items can be dropped. */ addDropArea: (fn: DropAreaProviderFunction) => void; /** * Unregister a drop area provider function. */ removeDropArea: (fn: DropAreaProviderFunction) => void; /** * Get all drop areas from all registered providers. */ getDropAreas: (items: DraggableItem[]) => DropArea[]; }; export default function (): DragDropProvider; export {};