2022-11-15 09:35:48 +01:00
|
|
|
import {
|
|
|
|
Block,
|
|
|
|
BlockOptions,
|
|
|
|
BlockWithOptionsType,
|
|
|
|
BubbleBlockContent,
|
|
|
|
BubbleBlockType,
|
|
|
|
defaultChatwootOptions,
|
|
|
|
defaultChoiceInputOptions,
|
|
|
|
defaultConditionContent,
|
|
|
|
defaultDateInputOptions,
|
|
|
|
defaultEmailInputOptions,
|
|
|
|
defaultEmbedBubbleContent,
|
|
|
|
defaultFileInputOptions,
|
|
|
|
defaultGoogleAnalyticsOptions,
|
|
|
|
defaultGoogleSheetsOptions,
|
|
|
|
defaultImageBubbleContent,
|
2022-11-17 10:33:17 +01:00
|
|
|
defaultAudioBubbleContent,
|
2022-11-15 09:35:48 +01:00
|
|
|
defaultNumberInputOptions,
|
|
|
|
defaultPaymentInputOptions,
|
|
|
|
defaultPhoneInputOptions,
|
|
|
|
defaultRatingInputOptions,
|
|
|
|
defaultRedirectOptions,
|
|
|
|
defaultSendEmailOptions,
|
|
|
|
defaultSetVariablesOptions,
|
|
|
|
defaultTextBubbleContent,
|
|
|
|
defaultTextInputOptions,
|
|
|
|
defaultUrlInputOptions,
|
|
|
|
defaultVideoBubbleContent,
|
|
|
|
defaultWebhookOptions,
|
|
|
|
DraggableBlock,
|
|
|
|
DraggableBlockType,
|
|
|
|
Edge,
|
|
|
|
IdMap,
|
|
|
|
InputBlockType,
|
|
|
|
IntegrationBlockType,
|
|
|
|
Item,
|
|
|
|
ItemType,
|
|
|
|
LogicBlockType,
|
2023-01-26 18:23:09 +01:00
|
|
|
defaultWaitOptions,
|
2023-01-27 15:58:05 +01:00
|
|
|
defaultScriptOptions,
|
2022-11-15 09:35:48 +01:00
|
|
|
} from 'models'
|
2021-12-16 10:43:49 +01:00
|
|
|
import {
|
|
|
|
stubLength,
|
|
|
|
blockWidth,
|
|
|
|
blockAnchorsOffset,
|
2022-01-15 17:30:20 +01:00
|
|
|
Endpoint,
|
2022-01-28 09:42:31 +01:00
|
|
|
Coordinates,
|
2022-11-15 09:35:48 +01:00
|
|
|
} from './providers'
|
2021-12-16 10:43:49 +01:00
|
|
|
import { roundCorners } from 'svg-round-corners'
|
2022-11-15 09:35:48 +01:00
|
|
|
import { AnchorsPositionProps } from './components/Edges/Edge'
|
2023-02-10 15:06:02 +01:00
|
|
|
import { createId } from '@paralleldrive/cuid2'
|
2022-11-15 09:35:48 +01:00
|
|
|
import {
|
|
|
|
isBubbleBlockType,
|
|
|
|
blockTypeHasOption,
|
|
|
|
blockTypeHasWebhook,
|
|
|
|
blockTypeHasItems,
|
|
|
|
isChoiceInput,
|
|
|
|
isConditionBlock,
|
2023-02-23 19:22:32 +01:00
|
|
|
isDefined,
|
2022-11-15 09:35:48 +01:00
|
|
|
} from 'utils'
|
2021-12-16 10:43:49 +01:00
|
|
|
|
2022-03-31 09:49:23 +02:00
|
|
|
const roundSize = 20
|
|
|
|
|
2022-01-03 17:39:59 +01:00
|
|
|
export const computeDropOffPath = (
|
|
|
|
sourcePosition: Coordinates,
|
2022-02-11 18:06:59 +01:00
|
|
|
sourceTop: number
|
2022-01-03 17:39:59 +01:00
|
|
|
) => {
|
2022-02-11 18:06:59 +01:00
|
|
|
const sourceCoord = computeSourceCoordinates(sourcePosition, sourceTop)
|
2022-01-03 17:39:59 +01:00
|
|
|
const segments = computeTwoSegments(sourceCoord, {
|
|
|
|
x: sourceCoord.x + 20,
|
|
|
|
y: sourceCoord.y + 80,
|
|
|
|
})
|
2022-03-31 09:49:23 +02:00
|
|
|
return roundCorners(
|
|
|
|
`M${sourceCoord.x},${sourceCoord.y} ${segments}`,
|
|
|
|
roundSize
|
|
|
|
).path
|
2022-01-03 17:39:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const computeSourceCoordinates = (
|
|
|
|
sourcePosition: Coordinates,
|
2022-01-15 17:30:20 +01:00
|
|
|
sourceTop: number
|
2022-01-03 17:39:59 +01:00
|
|
|
) => ({
|
|
|
|
x: sourcePosition.x + blockWidth,
|
2022-01-15 17:30:20 +01:00
|
|
|
y: sourceTop,
|
2022-01-03 17:39:59 +01:00
|
|
|
})
|
|
|
|
|
2021-12-16 10:43:49 +01:00
|
|
|
const getSegments = ({
|
|
|
|
sourcePosition,
|
|
|
|
targetPosition,
|
|
|
|
sourceType,
|
|
|
|
totalSegments,
|
|
|
|
}: AnchorsPositionProps) => {
|
|
|
|
switch (totalSegments) {
|
|
|
|
case 2:
|
|
|
|
return computeTwoSegments(sourcePosition, targetPosition)
|
|
|
|
case 3:
|
|
|
|
return computeThreeSegments(sourcePosition, targetPosition, sourceType)
|
|
|
|
case 4:
|
|
|
|
return computeFourSegments(sourcePosition, targetPosition, sourceType)
|
|
|
|
default:
|
|
|
|
return computeFiveSegments(sourcePosition, targetPosition, sourceType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const computeTwoSegments = (
|
|
|
|
sourcePosition: Coordinates,
|
|
|
|
targetPosition: Coordinates
|
|
|
|
) => {
|
|
|
|
const segments = []
|
|
|
|
segments.push(`L${targetPosition.x},${sourcePosition.y}`)
|
|
|
|
segments.push(`L${targetPosition.x},${targetPosition.y}`)
|
|
|
|
return segments.join(' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
const computeThreeSegments = (
|
|
|
|
sourcePosition: Coordinates,
|
|
|
|
targetPosition: Coordinates,
|
|
|
|
sourceType: 'right' | 'left'
|
|
|
|
) => {
|
|
|
|
const segments = []
|
|
|
|
const firstSegmentX =
|
|
|
|
sourceType === 'right'
|
|
|
|
? sourcePosition.x + (targetPosition.x - sourcePosition.x) / 2
|
|
|
|
: sourcePosition.x - (sourcePosition.x - targetPosition.x) / 2
|
|
|
|
segments.push(`L${firstSegmentX},${sourcePosition.y}`)
|
|
|
|
segments.push(`L${firstSegmentX},${targetPosition.y}`)
|
|
|
|
segments.push(`L${targetPosition.x},${targetPosition.y}`)
|
|
|
|
return segments.join(' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
const computeFourSegments = (
|
|
|
|
sourcePosition: Coordinates,
|
|
|
|
targetPosition: Coordinates,
|
|
|
|
sourceType: 'right' | 'left'
|
|
|
|
) => {
|
|
|
|
const segments = []
|
|
|
|
const firstSegmentX =
|
|
|
|
sourcePosition.x + (sourceType === 'right' ? stubLength : -stubLength)
|
|
|
|
segments.push(`L${firstSegmentX},${sourcePosition.y}`)
|
|
|
|
const secondSegmentY =
|
2022-11-18 07:58:43 +01:00
|
|
|
sourcePosition.y + (targetPosition.y - sourcePosition.y) - stubLength
|
2021-12-16 10:43:49 +01:00
|
|
|
segments.push(`L${firstSegmentX},${secondSegmentY}`)
|
|
|
|
|
|
|
|
segments.push(`L${targetPosition.x},${secondSegmentY}`)
|
|
|
|
|
|
|
|
segments.push(`L${targetPosition.x},${targetPosition.y}`)
|
|
|
|
return segments.join(' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
const computeFiveSegments = (
|
|
|
|
sourcePosition: Coordinates,
|
|
|
|
targetPosition: Coordinates,
|
|
|
|
sourceType: 'right' | 'left'
|
|
|
|
) => {
|
|
|
|
const segments = []
|
|
|
|
const firstSegmentX =
|
|
|
|
sourcePosition.x + (sourceType === 'right' ? stubLength : -stubLength)
|
|
|
|
segments.push(`L${firstSegmentX},${sourcePosition.y}`)
|
|
|
|
const firstSegmentY =
|
|
|
|
sourcePosition.y + (targetPosition.y - sourcePosition.y) / 2
|
|
|
|
segments.push(
|
|
|
|
`L${
|
|
|
|
sourcePosition.x + (sourceType === 'right' ? stubLength : -stubLength)
|
|
|
|
},${firstSegmentY}`
|
|
|
|
)
|
|
|
|
|
|
|
|
const secondSegmentX =
|
|
|
|
targetPosition.x - (sourceType === 'right' ? stubLength : -stubLength)
|
|
|
|
segments.push(`L${secondSegmentX},${firstSegmentY}`)
|
|
|
|
|
|
|
|
segments.push(`L${secondSegmentX},${targetPosition.y}`)
|
|
|
|
|
|
|
|
segments.push(`L${targetPosition.x},${targetPosition.y}`)
|
|
|
|
return segments.join(' ')
|
|
|
|
}
|
|
|
|
|
2022-01-12 09:10:59 +01:00
|
|
|
type GetAnchorsPositionParams = {
|
2022-06-11 07:27:38 +02:00
|
|
|
sourceGroupCoordinates: Coordinates
|
|
|
|
targetGroupCoordinates: Coordinates
|
2022-01-15 17:30:20 +01:00
|
|
|
sourceTop: number
|
2022-02-02 08:05:02 +01:00
|
|
|
targetTop?: number
|
2022-04-08 14:30:46 -05:00
|
|
|
graphScale: number
|
2022-01-12 09:10:59 +01:00
|
|
|
}
|
|
|
|
export const getAnchorsPosition = ({
|
2022-06-11 07:27:38 +02:00
|
|
|
sourceGroupCoordinates,
|
|
|
|
targetGroupCoordinates,
|
2022-01-15 17:30:20 +01:00
|
|
|
sourceTop,
|
|
|
|
targetTop,
|
2022-01-12 09:10:59 +01:00
|
|
|
}: GetAnchorsPositionParams): AnchorsPositionProps => {
|
2022-01-03 17:39:59 +01:00
|
|
|
const sourcePosition = computeSourceCoordinates(
|
2022-06-11 07:27:38 +02:00
|
|
|
sourceGroupCoordinates,
|
2022-01-15 17:30:20 +01:00
|
|
|
sourceTop
|
2022-01-03 17:39:59 +01:00
|
|
|
)
|
2021-12-16 10:43:49 +01:00
|
|
|
let sourceType: 'right' | 'left' = 'right'
|
2022-06-11 07:27:38 +02:00
|
|
|
if (sourceGroupCoordinates.x > targetGroupCoordinates.x) {
|
|
|
|
sourcePosition.x = sourceGroupCoordinates.x
|
2021-12-16 10:43:49 +01:00
|
|
|
sourceType = 'left'
|
|
|
|
}
|
|
|
|
|
2022-06-11 07:27:38 +02:00
|
|
|
const { targetPosition, totalSegments } = computeGroupTargetPosition(
|
|
|
|
sourceGroupCoordinates,
|
|
|
|
targetGroupCoordinates,
|
2022-01-03 17:39:59 +01:00
|
|
|
sourcePosition.y,
|
2022-02-02 08:05:02 +01:00
|
|
|
targetTop
|
2021-12-16 10:43:49 +01:00
|
|
|
)
|
|
|
|
return { sourcePosition, targetPosition, sourceType, totalSegments }
|
|
|
|
}
|
|
|
|
|
2022-06-11 07:27:38 +02:00
|
|
|
const computeGroupTargetPosition = (
|
|
|
|
sourceGroupPosition: Coordinates,
|
|
|
|
targetGroupPosition: Coordinates,
|
2022-02-02 08:05:02 +01:00
|
|
|
sourceOffsetY: number,
|
2021-12-16 10:43:49 +01:00
|
|
|
targetOffsetY?: number
|
|
|
|
): { targetPosition: Coordinates; totalSegments: number } => {
|
2022-06-11 07:27:38 +02:00
|
|
|
const isTargetGroupBelow =
|
|
|
|
targetGroupPosition.y > sourceOffsetY &&
|
|
|
|
targetGroupPosition.x < sourceGroupPosition.x + blockWidth + stubLength &&
|
|
|
|
targetGroupPosition.x > sourceGroupPosition.x - blockWidth - stubLength
|
|
|
|
const isTargetGroupToTheRight = targetGroupPosition.x < sourceGroupPosition.x
|
|
|
|
const isTargettingGroup = !targetOffsetY
|
2021-12-16 10:43:49 +01:00
|
|
|
|
2022-06-11 07:27:38 +02:00
|
|
|
if (isTargetGroupBelow && isTargettingGroup) {
|
2021-12-16 10:43:49 +01:00
|
|
|
const isExterior =
|
2022-06-11 07:27:38 +02:00
|
|
|
targetGroupPosition.x <
|
|
|
|
sourceGroupPosition.x - blockWidth / 2 - stubLength ||
|
|
|
|
targetGroupPosition.x >
|
|
|
|
sourceGroupPosition.x + blockWidth / 2 + stubLength
|
|
|
|
const targetPosition = parseGroupAnchorPosition(targetGroupPosition, 'top')
|
2021-12-16 10:43:49 +01:00
|
|
|
return { totalSegments: isExterior ? 2 : 4, targetPosition }
|
|
|
|
} else {
|
|
|
|
const isExterior =
|
2022-06-11 07:27:38 +02:00
|
|
|
targetGroupPosition.x < sourceGroupPosition.x - blockWidth ||
|
|
|
|
targetGroupPosition.x > sourceGroupPosition.x + blockWidth
|
|
|
|
const targetPosition = parseGroupAnchorPosition(
|
|
|
|
targetGroupPosition,
|
|
|
|
isTargetGroupToTheRight ? 'right' : 'left',
|
2021-12-16 10:43:49 +01:00
|
|
|
targetOffsetY
|
|
|
|
)
|
|
|
|
return { totalSegments: isExterior ? 3 : 5, targetPosition }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-11 07:27:38 +02:00
|
|
|
const parseGroupAnchorPosition = (
|
2021-12-16 10:43:49 +01:00
|
|
|
blockPosition: Coordinates,
|
|
|
|
anchor: 'left' | 'top' | 'right',
|
|
|
|
targetOffsetY?: number
|
|
|
|
): Coordinates => {
|
|
|
|
switch (anchor) {
|
|
|
|
case 'left':
|
|
|
|
return {
|
|
|
|
x: blockPosition.x + blockAnchorsOffset.left.x,
|
|
|
|
y: targetOffsetY ?? blockPosition.y + blockAnchorsOffset.left.y,
|
|
|
|
}
|
|
|
|
case 'top':
|
|
|
|
return {
|
|
|
|
x: blockPosition.x + blockAnchorsOffset.top.x,
|
|
|
|
y: blockPosition.y + blockAnchorsOffset.top.y,
|
|
|
|
}
|
|
|
|
case 'right':
|
|
|
|
return {
|
|
|
|
x: blockPosition.x + blockAnchorsOffset.right.x,
|
|
|
|
y: targetOffsetY ?? blockPosition.y + blockAnchorsOffset.right.y,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-12 09:10:59 +01:00
|
|
|
|
2022-01-15 17:30:20 +01:00
|
|
|
export const computeEdgePath = ({
|
|
|
|
sourcePosition,
|
|
|
|
targetPosition,
|
|
|
|
sourceType,
|
|
|
|
totalSegments,
|
|
|
|
}: AnchorsPositionProps) => {
|
|
|
|
const segments = getSegments({
|
|
|
|
sourcePosition,
|
|
|
|
targetPosition,
|
|
|
|
sourceType,
|
|
|
|
totalSegments,
|
|
|
|
})
|
|
|
|
return roundCorners(
|
|
|
|
`M${sourcePosition.x},${sourcePosition.y} ${segments}`,
|
2022-03-31 09:49:23 +02:00
|
|
|
roundSize
|
2022-01-15 17:30:20 +01:00
|
|
|
).path
|
|
|
|
}
|
|
|
|
|
2022-02-02 08:05:02 +01:00
|
|
|
export const computeConnectingEdgePath = ({
|
2022-06-11 07:27:38 +02:00
|
|
|
sourceGroupCoordinates,
|
|
|
|
targetGroupCoordinates,
|
2022-02-02 08:05:02 +01:00
|
|
|
sourceTop,
|
|
|
|
targetTop,
|
2022-04-08 14:30:46 -05:00
|
|
|
graphScale,
|
2022-02-04 19:00:08 +01:00
|
|
|
}: GetAnchorsPositionParams) => {
|
2022-01-12 09:10:59 +01:00
|
|
|
const anchorsPosition = getAnchorsPosition({
|
2022-06-11 07:27:38 +02:00
|
|
|
sourceGroupCoordinates,
|
|
|
|
targetGroupCoordinates,
|
2022-01-15 17:30:20 +01:00
|
|
|
sourceTop,
|
|
|
|
targetTop,
|
2022-04-08 14:30:46 -05:00
|
|
|
graphScale,
|
2022-01-12 09:10:59 +01:00
|
|
|
})
|
2022-01-15 17:30:20 +01:00
|
|
|
return computeEdgePath(anchorsPosition)
|
2022-01-12 09:10:59 +01:00
|
|
|
}
|
|
|
|
|
2022-01-15 17:30:20 +01:00
|
|
|
export const computeEdgePathToMouse = ({
|
2022-06-11 07:27:38 +02:00
|
|
|
sourceGroupCoordinates,
|
2022-01-12 09:10:59 +01:00
|
|
|
mousePosition,
|
2022-01-15 17:30:20 +01:00
|
|
|
sourceTop,
|
2022-01-12 09:10:59 +01:00
|
|
|
}: {
|
2022-06-11 07:27:38 +02:00
|
|
|
sourceGroupCoordinates: Coordinates
|
2022-01-12 09:10:59 +01:00
|
|
|
mousePosition: Coordinates
|
2022-01-15 17:30:20 +01:00
|
|
|
sourceTop: number
|
2022-01-12 09:10:59 +01:00
|
|
|
}): string => {
|
|
|
|
const sourcePosition = {
|
|
|
|
x:
|
2022-06-11 07:27:38 +02:00
|
|
|
mousePosition.x - sourceGroupCoordinates.x > blockWidth / 2
|
|
|
|
? sourceGroupCoordinates.x + blockWidth
|
|
|
|
: sourceGroupCoordinates.x,
|
2022-01-15 17:30:20 +01:00
|
|
|
y: sourceTop,
|
2022-01-12 09:10:59 +01:00
|
|
|
}
|
|
|
|
const sourceType =
|
2022-06-11 07:27:38 +02:00
|
|
|
mousePosition.x - sourceGroupCoordinates.x > blockWidth / 2
|
2022-02-04 19:00:08 +01:00
|
|
|
? 'right'
|
|
|
|
: 'left'
|
2022-01-12 09:10:59 +01:00
|
|
|
const segments = computeThreeSegments(
|
|
|
|
sourcePosition,
|
|
|
|
mousePosition,
|
|
|
|
sourceType
|
|
|
|
)
|
|
|
|
return roundCorners(
|
|
|
|
`M${sourcePosition.x},${sourcePosition.y} ${segments}`,
|
2022-03-31 09:49:23 +02:00
|
|
|
roundSize
|
2022-01-12 09:10:59 +01:00
|
|
|
).path
|
|
|
|
}
|
|
|
|
|
2022-04-08 14:30:46 -05:00
|
|
|
export const getEndpointTopOffset = ({
|
|
|
|
endpoints,
|
|
|
|
graphOffsetY,
|
|
|
|
endpointId,
|
|
|
|
graphScale,
|
|
|
|
}: {
|
|
|
|
endpoints: IdMap<Endpoint>
|
|
|
|
graphOffsetY: number
|
2022-02-14 18:56:29 +01:00
|
|
|
endpointId?: string
|
2022-04-08 14:30:46 -05:00
|
|
|
graphScale: number
|
|
|
|
}): number | undefined => {
|
2022-02-02 08:05:02 +01:00
|
|
|
if (!endpointId) return
|
2022-02-04 19:00:08 +01:00
|
|
|
const endpointRef = endpoints[endpointId]?.ref
|
2022-02-14 18:56:29 +01:00
|
|
|
if (!endpointRef?.current) return
|
2023-01-27 15:25:03 +01:00
|
|
|
const endpointHeight = 20 * graphScale
|
2022-01-15 17:30:20 +01:00
|
|
|
return (
|
2022-04-08 14:30:46 -05:00
|
|
|
(endpointRef.current.getBoundingClientRect().y +
|
|
|
|
endpointHeight / 2 -
|
|
|
|
graphOffsetY) /
|
|
|
|
graphScale
|
2022-01-15 17:30:20 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-19 18:54:49 +01:00
|
|
|
export const getSourceEndpointId = (edge?: Edge) =>
|
2022-06-11 07:27:38 +02:00
|
|
|
edge?.from.itemId ?? edge?.from.blockId
|
2022-11-15 09:35:48 +01:00
|
|
|
|
|
|
|
export const parseNewBlock = (
|
|
|
|
type: DraggableBlockType,
|
|
|
|
groupId: string
|
|
|
|
): DraggableBlock => {
|
2023-02-10 15:06:02 +01:00
|
|
|
const id = createId()
|
2022-11-15 09:35:48 +01:00
|
|
|
return {
|
|
|
|
id,
|
|
|
|
groupId,
|
|
|
|
type,
|
|
|
|
content: isBubbleBlockType(type) ? parseDefaultContent(type) : undefined,
|
|
|
|
options: blockTypeHasOption(type)
|
|
|
|
? parseDefaultBlockOptions(type)
|
|
|
|
: undefined,
|
2023-02-10 15:06:02 +01:00
|
|
|
webhookId: blockTypeHasWebhook(type) ? createId() : undefined,
|
2022-11-15 09:35:48 +01:00
|
|
|
items: blockTypeHasItems(type) ? parseDefaultItems(type, id) : undefined,
|
|
|
|
} as DraggableBlock
|
|
|
|
}
|
|
|
|
|
|
|
|
const parseDefaultItems = (
|
|
|
|
type: LogicBlockType.CONDITION | InputBlockType.CHOICE,
|
|
|
|
blockId: string
|
|
|
|
): Item[] => {
|
|
|
|
switch (type) {
|
|
|
|
case InputBlockType.CHOICE:
|
2023-02-10 15:06:02 +01:00
|
|
|
return [{ id: createId(), blockId, type: ItemType.BUTTON }]
|
2022-11-15 09:35:48 +01:00
|
|
|
case LogicBlockType.CONDITION:
|
|
|
|
return [
|
|
|
|
{
|
2023-02-10 15:06:02 +01:00
|
|
|
id: createId(),
|
2022-11-15 09:35:48 +01:00
|
|
|
blockId,
|
|
|
|
type: ItemType.CONDITION,
|
|
|
|
content: defaultConditionContent,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const parseDefaultContent = (type: BubbleBlockType): BubbleBlockContent => {
|
|
|
|
switch (type) {
|
|
|
|
case BubbleBlockType.TEXT:
|
|
|
|
return defaultTextBubbleContent
|
|
|
|
case BubbleBlockType.IMAGE:
|
|
|
|
return defaultImageBubbleContent
|
|
|
|
case BubbleBlockType.VIDEO:
|
|
|
|
return defaultVideoBubbleContent
|
|
|
|
case BubbleBlockType.EMBED:
|
|
|
|
return defaultEmbedBubbleContent
|
2022-11-17 10:33:17 +01:00
|
|
|
case BubbleBlockType.AUDIO:
|
|
|
|
return defaultAudioBubbleContent
|
2022-11-15 09:35:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const parseDefaultBlockOptions = (type: BlockWithOptionsType): BlockOptions => {
|
|
|
|
switch (type) {
|
|
|
|
case InputBlockType.TEXT:
|
|
|
|
return defaultTextInputOptions
|
|
|
|
case InputBlockType.NUMBER:
|
|
|
|
return defaultNumberInputOptions
|
|
|
|
case InputBlockType.EMAIL:
|
|
|
|
return defaultEmailInputOptions
|
|
|
|
case InputBlockType.DATE:
|
|
|
|
return defaultDateInputOptions
|
|
|
|
case InputBlockType.PHONE:
|
|
|
|
return defaultPhoneInputOptions
|
|
|
|
case InputBlockType.URL:
|
|
|
|
return defaultUrlInputOptions
|
|
|
|
case InputBlockType.CHOICE:
|
|
|
|
return defaultChoiceInputOptions
|
|
|
|
case InputBlockType.PAYMENT:
|
|
|
|
return defaultPaymentInputOptions
|
|
|
|
case InputBlockType.RATING:
|
|
|
|
return defaultRatingInputOptions
|
|
|
|
case InputBlockType.FILE:
|
|
|
|
return defaultFileInputOptions
|
|
|
|
case LogicBlockType.SET_VARIABLE:
|
|
|
|
return defaultSetVariablesOptions
|
|
|
|
case LogicBlockType.REDIRECT:
|
|
|
|
return defaultRedirectOptions
|
2023-01-27 15:58:05 +01:00
|
|
|
case LogicBlockType.SCRIPT:
|
|
|
|
return defaultScriptOptions
|
2023-01-26 18:23:09 +01:00
|
|
|
case LogicBlockType.WAIT:
|
|
|
|
return defaultWaitOptions
|
2022-11-15 09:35:48 +01:00
|
|
|
case LogicBlockType.TYPEBOT_LINK:
|
|
|
|
return {}
|
|
|
|
case IntegrationBlockType.GOOGLE_SHEETS:
|
|
|
|
return defaultGoogleSheetsOptions
|
|
|
|
case IntegrationBlockType.GOOGLE_ANALYTICS:
|
|
|
|
return defaultGoogleAnalyticsOptions
|
|
|
|
case IntegrationBlockType.ZAPIER:
|
|
|
|
case IntegrationBlockType.PABBLY_CONNECT:
|
|
|
|
case IntegrationBlockType.MAKE_COM:
|
|
|
|
case IntegrationBlockType.WEBHOOK:
|
|
|
|
return defaultWebhookOptions
|
|
|
|
case IntegrationBlockType.EMAIL:
|
|
|
|
return defaultSendEmailOptions
|
|
|
|
case IntegrationBlockType.CHATWOOT:
|
|
|
|
return defaultChatwootOptions
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const hasDefaultConnector = (block: Block) =>
|
2023-02-23 19:22:32 +01:00
|
|
|
(!isChoiceInput(block) && !isConditionBlock(block)) ||
|
|
|
|
(block.type === InputBlockType.CHOICE &&
|
|
|
|
isDefined(block.options.dynamicVariableId))
|