UNPKG

wix-style-react

Version:
93 lines (77 loc) 2.82 kB
import { dragAndDropDriverFactory, changeItemDepth, } from '../utils/DragAndDrop/dragAndDropDriverFactory'; import { baseUniDriverFactory, findByHook } from '../../test/utils/unidriver'; import { dataHooks } from './constants'; export const nestableListUniDriverFactory = (base, body) => { const dndProviderBase = findByHook(base, dataHooks.provider); return { ...baseUniDriverFactory(dndProviderBase, body), /** * reorder nestable list items by id * @param {ReorderIds} ids { addedId: string | number, removedId: string | number } * @return {Promise<void>} * @deprecated use reorderByDataHook */ reorder: async ({ removedId, addedId }, offset) => { const baseEl = await dndProviderBase.getNative(); const dragAndDropDriver = dragAndDropDriverFactory({ base: dndProviderBase, element: baseEl, }); await dragAndDropDriver.beginDrag({ id: removedId }); await dragAndDropDriver.dragOver({ id: addedId, offset }); await dragAndDropDriver.endDrag({ id: addedId }); }, /** * reorder nestable list items by data-hook * @param {ReorderDataHooks} dataHooks { from: string, to: string } * @return {Promise<void>} */ reorderByDataHook: async ({ from, to }) => { const baseEl = await dndProviderBase.getNative(); const dragAndDropDriver = dragAndDropDriverFactory({ base: dndProviderBase, element: baseEl, }); await dragAndDropDriver.beginDrag({ dataHook: from }); await dragAndDropDriver.dragOver({ dataHook: to }); await dragAndDropDriver.endDrag({ dataHook: to }); }, /** * change nestable list item depth * @param {NestableItemDetails} dataHooks { dataHook: string, depthLevel: number, threshold: number } * @return {Promise<void>} */ changeItemDepth: async ({ dataHook, depthLevel, threshold = 30 }) => changeItemDepth({ dataHook, depthLevel, threshold, dragAndDropDriver: dragAndDropDriverFactory({ base: dndProviderBase, element: await dndProviderBase.getNative(), }), }), /** * get nestable list item position * @param {DraggableItemDetails} itemDetails { dataHook: string } * @return {Promise<void>} */ getItemPosition: async ({ dataHook }) => dragAndDropDriverFactory({ base: dndProviderBase }).getItemPosition({ dataHook, }), /** * get nestable list item depth * @param {DraggableItemDetails} itemDetails { dataHook: string } * @return {Promise<void>} */ getItemDepth: async ({ dataHook }) => dragAndDropDriverFactory({ base: dndProviderBase }).getItemDepth({ dataHook, }), }; }; export default nestableListUniDriverFactory;