2
0

🐛 (text) Fix text bubble content parsing when starting with variable

Closes #1594
This commit is contained in:
Baptiste Arnaud
2024-06-24 15:03:18 +02:00
parent b10383e027
commit 7790cf4f27
5 changed files with 38 additions and 4 deletions

View File

@ -206,7 +206,7 @@ const SetVariableValue = ({
}
onSelect={updateIsCode}
/>
{options?.isCode === undefined || options.isCode ? (
{options?.isCode ? (
<CodeEditor
defaultValue={options?.expressionToEvaluate ?? ''}
onChange={updateExpression}

View File

@ -236,6 +236,9 @@
},
"maxWidth": {
"type": "string"
},
"queryParamsStr": {
"type": "string"
}
}
}
@ -4572,6 +4575,9 @@
},
"maxWidth": {
"type": "string"
},
"queryParamsStr": {
"type": "string"
}
}
}
@ -8045,6 +8051,9 @@
},
"maxWidth": {
"type": "string"
},
"queryParamsStr": {
"type": "string"
}
}
}
@ -16560,6 +16569,9 @@
},
"maxWidth": {
"type": "string"
},
"queryParamsStr": {
"type": "string"
}
}
}
@ -22872,6 +22884,9 @@
},
"maxWidth": {
"type": "string"
},
"queryParamsStr": {
"type": "string"
}
}
}
@ -25714,6 +25729,9 @@
},
"maxWidth": {
"type": "string"
},
"queryParamsStr": {
"type": "string"
}
}
}

View File

@ -3433,6 +3433,9 @@
},
"maxWidth": {
"type": "string"
},
"queryParamsStr": {
"type": "string"
}
}
}
@ -7594,6 +7597,9 @@
},
"maxWidth": {
"type": "string"
},
"queryParamsStr": {
"type": "string"
}
}
}
@ -12777,6 +12783,9 @@
},
"maxWidth": {
"type": "string"
},
"queryParamsStr": {
"type": "string"
}
}
}

View File

@ -16,6 +16,7 @@ import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/con
import { defaultVideoBubbleContent } from '@typebot.io/schemas/features/blocks/bubbles/video/constants'
import { convertMarkdownToRichText } from '@typebot.io/lib/markdown/convertMarkdownToRichText'
import { convertRichTextToMarkdown } from '@typebot.io/lib/markdown/convertRichTextToMarkdown'
import { isSingleVariable } from '@typebot.io/variables/isSingleVariable'
type Params = {
version: 1 | 2
@ -144,7 +145,9 @@ export const parseVariablesInRichText = (
: undefined
lastTextEndIndex = variableInText.endIndex
const isStandaloneElement =
isEmpty(textBeforeVariable) && isEmpty(textAfterVariable)
isEmpty(textBeforeVariable) &&
isEmpty(textAfterVariable) &&
variablesInText.length === 1
const variableElements = convertMarkdownToRichText(
isStandaloneElement
? variableInText.value
@ -193,8 +196,7 @@ export const parseVariablesInRichText = (
const type =
element.children.length === 1 &&
'text' in element.children[0] &&
(element.children[0].text as string).startsWith('{{') &&
(element.children[0].text as string).endsWith('}}') &&
isSingleVariable(element.children[0].text as string) &&
element.type !== 'a'
? 'variable'
: element.type

View File

@ -0,0 +1,5 @@
export const isSingleVariable = (value: string | undefined): boolean =>
!!value &&
value.startsWith('{{') &&
value.endsWith('}}') &&
value.split('{{').length === 2