import type { DropResult } from 'react-beautiful-dnd' ; export const draggableIdPrefix = 'draggableId' ; export const droppableIdPrefix = 'droppableId' ; export const draggableContentPrefix = `${ draggableIdPrefix }.content.` ; export const draggableTimelineProvidersPrefix = `${ draggableIdPrefix }.timelineProviders.` ; export const draggableFieldPrefix = `${ draggableIdPrefix }.field.` ; export const droppableContentPrefix = `${ droppableIdPrefix }.content.` ; export const droppableFieldPrefix = `${ droppableIdPrefix }.field.` ; export const droppableTimelineProvidersPrefix = `${ droppableIdPrefix }.timelineProviders.` ; export const droppableTimelineColumnsPrefix = `${ droppableIdPrefix }.timelineColumns.` ; export const droppableTimelineFlyoutBottomBarPrefix = `${ droppableIdPrefix }.flyoutButton.` ; export const getDraggableId = ( dataProviderId ) : string => `${ draggableContentPrefix }${ dataProviderId }` ; export const getDraggableFieldId = ( { contextId , fieldId , } ) : string => `${ draggableFieldPrefix }${ escapeContextId ( contextId ) }.${ escapeFieldId ( fieldId ) }` ; export const getTimelineProviderDroppableId = ( { groupIndex , timelineId , } ) : string => `${ droppableTimelineProvidersPrefix }${ timelineId }.group.${ groupIndex }` ; export const getTimelineProviderDraggableId = ( { dataProviderId , groupIndex , timelineId , } ) : string => `${ draggableTimelineProvidersPrefix }${ timelineId }.group.${ groupIndex }.${ dataProviderId }` ; export const getDroppableId = ( visualizationPlaceholderId ) : string => `${ droppableContentPrefix }${ visualizationPlaceholderId }` ; export const sourceIsContent = ( result ) : boolean => result . source . droppableId . startsWith ( droppableContentPrefix ) ; export const sourceAndDestinationAreSameTimelineProviders = ( result ) : boolean => { const regex = /^droppableId\.timelineProviders\.(\S+)\./ ; const sourceMatches = result . source . droppableId . match ( regex ) || [ ] ; const destinationMatches = ( result . destination && result . destination . droppableId . match ( regex ) ) || [ ] ; return ( sourceMatches . length >= 2 && destinationMatches . length >= 2 && sourceMatches [ 1 ] === destinationMatches [ 1 ] ) ; } ; export const draggableIsContent = ( result ) : boolean => result . draggableId . startsWith ( draggableContentPrefix ) ; export const draggableIsField = ( result ) : boolean => result . draggableId . startsWith ( draggableFieldPrefix ) ; export const reasonIsDrop = ( result ) : boolean => result . reason === 'DROP' ; export const destinationIsTimelineProviders = ( result ) : boolean => result . destination != null && result . destination . droppableId . startsWith ( droppableTimelineProvidersPrefix ) ; export const destinationIsTimelineColumns = ( result ) : boolean => result . destination != null && result . destination . droppableId . startsWith ( droppableTimelineColumnsPrefix ) ; export const destinationIsTimelineButton = ( result ) : boolean => result . destination != null && result . destination . droppableId . startsWith ( droppableTimelineFlyoutBottomBarPrefix ) ; export const getProviderIdFromDraggable = ( result ) : string => result . draggableId . substring ( result . draggableId . lastIndexOf ( '.' ) + 1 ) ; export const getFieldIdFromDraggable = ( result ) : string => unEscapeFieldId ( result . draggableId . substring ( result . draggableId . lastIndexOf ( '.' ) + 1 ) ) ; export const escapeDataProviderId = ( path ) => path . replace ( /\./g , '_' ) ; export const escapeContextId = ( path ) => path . replace ( /\./g , '_' ) ; export const escapeFieldId = ( path ) => path . replace ( /\./g , '!!!DOT!!!' ) ; export const unEscapeFieldId = ( path ) => path . replace ( /!!!DOT!!!/g , '.' ) ; export const providerWasDroppedOnTimeline = ( result ) : boolean => reasonIsDrop ( result ) && draggableIsContent ( result ) && sourceIsContent ( result ) && destinationIsTimelineProviders ( result ) ; export const userIsReArrangingProviders = ( result ) : boolean => reasonIsDrop ( result ) && sourceAndDestinationAreSameTimelineProviders ( result ) ; export const fieldWasDroppedOnTimelineColumns = ( result ) : boolean => reasonIsDrop ( result ) && draggableIsField ( result ) && destinationIsTimelineColumns ( result ) ; /**
 * Prevents fields from being dragged or dropped to any area other than column
 * header drop zone in the timeline
 */ export const DRAG_TYPE_FIELD = 'drag-type-field' ; /** This class is added to the document body while timeline field dragging */ export const IS_TIMELINE_FIELD_DRAGGING_CLASS_NAME = 'is-timeline-field-dragging' ;