UNPKG

@eclipse-scout/core

Version:
137 lines 5.84 kB
/// <reference types="jquery" /> import { DragAndDropHandler, Widget } from '../index'; export declare enum DropType { NONE = 0, FILE_TRANSFER = 1 } export declare const dragAndDrop: { DEFAULT_DROP_MAXIMUM_SIZE: number; /** * Mapping function from scout drag types to browser drag types. * * @param scoutTypesArray array of DropType */ scoutTypeToDragTypeMapping(scoutTypesArray: DropType | DropType[]): Array<string>; /** * Check if specific scout type is supported by dataTransfer, if event is not handled by this field (desktop might handle it) * * @param event including event.originalEvent.dataTransfer * @param fieldAllowedTypes allowed types on field (integer, bitwise comparison used) * @param scoutTypeArray e.g. FILE_TRANSFER */ verifyDataTransferTypesScoutTypes(event: JQuery.DragEventBase, scoutTypeArray: DropType | DropType[], fieldAllowedTypes: number): void; /** * Check if specific type is supported by dataTransfer, if event is not handled by this field (upstream field might handle it, at the latest desktop) * * @param dataTransfer dataTransfer object (not dataTransfer.types) * @param needleArray e.g. 'Files' */ verifyDataTransferTypes(event: JQuery.DragEventBase, needleArray: string | string[]): boolean; /** * dataTransfer.types might be an array (Chrome, IE) or a DOMStringList. * * Unfortunately there is no intersecting contains method for both types. * * @param dataTransfer dataTransfer object (not dataTransfer.types) * @param scoutTypesArray e.g. FILE_TRANSFER */ dataTransferTypesContainsScoutTypes(dataTransfer: DataTransfer, scoutTypesArray: DropType | DropType[]): boolean; /** * dataTransfer.types might be an array (Chrome, IE) or a DOMStringList. * * Unfortunately there is no intersecting contains method for both types. * * @param dataTransfer dataTransfer object (not dataTransfer.types) * @param needleArray e.g. 'Files' */ dataTransferTypesContains(dataTransfer: DataTransfer, needleArray: string | string[]): boolean; handler(options: DragAndDropOptions): DragAndDropHandler; /** * installs or uninstalls a {@link DragAndDropHandler} on the target. */ installOrUninstallDragAndDropHandler(options: DragAndDropOptions): void; /** @internal */ _installDragAndDropHandler(options: DragAndDropOptions): void; /** @internal */ _createDragAndDropHandlerOptions(target: DragAndDropTarget): DragAndDropOptions; /** * uninstalls a {@link DragAndDropHandler} from the target. If no handler is installed, this function does nothing. */ uninstallDragAndDropHandler(target: DragAndDropTarget): void; }; export type DragAndDropTarget = Widget & { /** * default drop maximum size used in {@link DragAndDropOptions.dropMaximumSize}. If the target object contains a different field or function to retrieve this value override the supplier. */ dropMaximumSize?: number; /** * default install/uninstall criteria used in {@link DragAndDropOptions.doInstall}. If the target object contains a different field or function to retrieve this value override the supplier. */ enabledComputed?: boolean; /** * default container used in {@link DragAndDropOptions.container}. If the target object contains a different field or function to retrieve this value override the supplier. */ $container?: JQuery; /** * installed drag & drop handler. Will be managed through {@link DragAndDropHandler} */ dragAndDropHandler: DragAndDropHandler; }; export interface DropValidationErrorMessage { title: string; message: string; } export interface FileDropEvent { originalEvent: JQuery.DropEvent; files: File[]; } export interface DragAndDropOptions { /** * the target widget where the handler shall be installed. */ target: DragAndDropTarget; /** * Will be called when a valid element has been dropped. */ onDrop?: (event: FileDropEvent) => void; /** * Determines if the drag & drop handler should be installed or uninstalled. Default implementation is checking {@link Widget.enabledComputed} */ doInstall?: () => boolean; /** * Returns the dom container providing the necessary drag & drop events. Default is {@link Widget.$container} */ container?: () => JQuery; /** * The scout type which will be allowed to drop into the target. Default is {@link DropType.FILE_TRANSFER} */ supportedScoutTypes?: DropType | DropType[]; /** * Allowed mime types. * @see https://developer.mozilla.org/en-US/docs/Glossary/MIME_type */ allowedTypes?: () => string[]; /** * CSS selector which will be added to the event source. */ selector?: JQuery.Selector; /** * Returns the allowed drop type during a drop event. Default is {@link DropType.FILE_TRANSFER} */ dropType?: () => DropType; /** * Returns the maximum allowed size of a dropped object. Default is {@link Widget.dropMaximumSize} */ dropMaximumSize?: () => number; /** * An optional function to add a custom file validation logic. Throw a {@link DropValidationErrorMessage} to indicate a failed validation. * If no custom validator is installed, the default maximum file size validator is invoked. * @throws DropValidationErrorMessage */ validateFiles?: (files: File[], defaultValidator: (f: File[]) => void) => void; /** * Returns additional drop properties to be used in {@link DragAndDropHandler.uploadFiles} as uploadProperties */ additionalDropProperties?: (event: JQuery.DropEvent) => any; } //# sourceMappingURL=dragAndDrop.d.ts.map