All files / roosterjs-content-model-plugins/lib/imageEdit/utils getDropAndDragHelpers.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x 1x                   1x                   33x   138x                                   33x    
import { DragAndDropHelper } from '../../pluginUtils/DragAndDrop/DragAndDropHelper';
import { toArray } from 'roosterjs-content-model-dom';
import type { ImageEditElementClass } from '../types/ImageEditElementClass';
import type { ImageMetadataFormat } from 'roosterjs-content-model-types';
import type { ImageEditOptions } from '../types/ImageEditOptions';
import type { DragAndDropHandler } from '../../pluginUtils/DragAndDrop/DragAndDropHandler';
import type { DragAndDropContext, DNDDirectionX, DnDDirectionY } from '../types/DragAndDropContext';
 
/**
 * @internal
 */
export function getDropAndDragHelpers(
    wrapper: HTMLElement,
    editInfo: ImageMetadataFormat,
    options: ImageEditOptions,
    elementClass: ImageEditElementClass,
    helper: DragAndDropHandler<DragAndDropContext, any>,
    updateWrapper: (context: DragAndDropContext, _handle: HTMLElement) => void,
    zoomScale: number,
    useTouch: boolean
): DragAndDropHelper<DragAndDropContext, any>[] {
    return getEditElements(wrapper, elementClass).map(
        element =>
            new DragAndDropHelper<DragAndDropContext, any>(
                element,
                {
                    editInfo: editInfo,
                    options: options,
                    elementClass,
                    x: element.dataset.x as DNDDirectionX,
                    y: element.dataset.y as DnDDirectionY,
                },
                updateWrapper,
                helper,
                zoomScale,
                useTouch
            )
    );
}
 
function getEditElements(wrapper: HTMLElement, elementClass: ImageEditElementClass): HTMLElement[] {
    return toArray(wrapper.querySelectorAll('.' + elementClass)) as HTMLElement[];
}