2
0

🐛 Fix new markdown parser on web runtime

This commit is contained in:
Baptiste Arnaud
2024-02-01 16:52:54 +01:00
parent 3e8e8829f1
commit 678e6d5c49
7 changed files with 41 additions and 67 deletions

View File

@ -1,2 +1,3 @@
emojiList.json emojiList.json
iconNames.ts iconNames.ts
reporters

View File

@ -153,7 +153,6 @@ const groupsActions = (setTypebot: SetTypebot): GroupsActions => ({
let outgoingEdgeId = item.outgoingEdgeId let outgoingEdgeId = item.outgoingEdgeId
if (outgoingEdgeId) { if (outgoingEdgeId) {
const edge = edges.find(byId(outgoingEdgeId)) const edge = edges.find(byId(outgoingEdgeId))
console.log(edge)
if (edge) { if (edge) {
outgoingEdgeId = createId() outgoingEdgeId = createId()
edgesToCreate.push({ edgesToCreate.push({

View File

@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/js", "name": "@typebot.io/js",
"version": "0.2.37", "version": "0.2.38",
"description": "Javascript library to display typebots on your website", "description": "Javascript library to display typebots on your website",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -1,13 +1,11 @@
import type { TElement, TText, TDescendant } from '@udecode/plate-common' import type { TElement, TText, TDescendant } from '@udecode/plate-common'
import { PlateText, PlateTextProps } from './PlateText' import { PlateText, PlateTextProps } from './PlateText'
import { For, Match, Switch, JSXElement } from 'solid-js' import { For, Match, Switch } from 'solid-js'
import { isDefined } from '@typebot.io/lib/utils' import { isDefined } from '@typebot.io/lib/utils'
import clsx from 'clsx'
type Props = { type Props = {
element: TElement | TText element: TElement | TText
isUniqueChild?: boolean isUniqueChild?: boolean
inElement?: boolean
} }
export const PlateElement = (props: Props) => ( export const PlateElement = (props: Props) => (
@ -33,7 +31,6 @@ export const PlateElement = (props: Props) => (
isUniqueChild={ isUniqueChild={
(props.element.children as TDescendant[])?.length === 1 (props.element.children as TDescendant[])?.length === 1
} }
inElement={true}
/> />
)} )}
</For> </For>
@ -48,7 +45,6 @@ export const PlateElement = (props: Props) => (
isUniqueChild={ isUniqueChild={
(props.element.children as TDescendant[])?.length === 1 (props.element.children as TDescendant[])?.length === 1
} }
inElement={true}
/> />
)} )}
</For> </For>
@ -63,7 +59,6 @@ export const PlateElement = (props: Props) => (
isUniqueChild={ isUniqueChild={
(props.element.children as TDescendant[])?.length === 1 (props.element.children as TDescendant[])?.length === 1
} }
inElement={true}
/> />
)} )}
</For> </For>
@ -78,17 +73,13 @@ export const PlateElement = (props: Props) => (
isUniqueChild={ isUniqueChild={
(props.element.children as TDescendant[])?.length === 1 (props.element.children as TDescendant[])?.length === 1
} }
inElement={true}
/> />
)} )}
</For> </For>
</li> </li>
</Match> </Match>
<Match when={true}> <Match when={true}>
<ElementRoot <div data-element-type={props.element.type}>
element={props.element as TElement}
inElement={props.inElement ?? false}
>
<For each={props.element.children as TDescendant[]}> <For each={props.element.children as TDescendant[]}>
{(child) => ( {(child) => (
<PlateElement <PlateElement
@ -96,39 +87,12 @@ export const PlateElement = (props: Props) => (
isUniqueChild={ isUniqueChild={
(props.element.children as TDescendant[])?.length === 1 (props.element.children as TDescendant[])?.length === 1
} }
inElement={true}
/> />
)} )}
</For> </For>
</ElementRoot> </div>
</Match> </Match>
</Switch> </Switch>
</Match> </Match>
</Switch> </Switch>
) )
type ElementRootProps = {
element: TElement
inElement: boolean
children: JSXElement
}
const ElementRoot = (props: ElementRootProps) => {
return (
<Switch>
<Match when={props.inElement}>
<span data-element-type={props.element.type}>{props.children}</span>
</Match>
<Match when={!props.inElement}>
<div
data-element-type={props.element.type}
class={clsx(
props.element.type === 'variable' && 'flex flex-col gap-6'
)}
>
{props.children}
</div>
</Match>
</Switch>
)
}

View File

@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/nextjs", "name": "@typebot.io/nextjs",
"version": "0.2.37", "version": "0.2.38",
"description": "Convenient library to display typebots on your Next.js website", "description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/react", "name": "@typebot.io/react",
"version": "0.2.37", "version": "0.2.38",
"description": "Convenient library to display typebots on your React app", "description": "Convenient library to display typebots on your React app",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@ -50,7 +50,7 @@ export const remarkDefaultElementRules: RemarkElementRules<Value> = {
type: getPluginType(options.editor, headingType), type: getPluginType(options.editor, headingType),
children: remarkTransformElementChildren( children: remarkTransformElementChildren(
node, node,
lastLineNumber, node.position.end.line,
options options
), ),
}, },
@ -76,7 +76,7 @@ export const remarkDefaultElementRules: RemarkElementRules<Value> = {
indent, indent,
children: remarkTransformElementChildren( children: remarkTransformElementChildren(
paragraph || '', paragraph || '',
lastLineNumber, node.position.end.line,
options options
), ),
}) })
@ -103,7 +103,7 @@ export const remarkDefaultElementRules: RemarkElementRules<Value> = {
), ),
children: remarkTransformElementChildren( children: remarkTransformElementChildren(
node, node,
lastLineNumber, node.position.end.line,
options options
), ),
}, },
@ -112,29 +112,31 @@ export const remarkDefaultElementRules: RemarkElementRules<Value> = {
}, },
}, },
listItem: { listItem: {
transform: (node, lastLineNumber, options) => ({ transform: (node, _lastLineNumber, options) => {
type: getPluginType(options.editor, ELEMENT_LI), return {
children: remarkTransformElementChildren( type: getPluginType(options.editor, ELEMENT_LI),
node, children: remarkTransformElementChildren(
lastLineNumber, node,
options node.position.end.line,
).map( options
(child) => ).map(
({ (child) =>
...child, ({
type: ...child,
child.type === getPluginType(options.editor, ELEMENT_PARAGRAPH) type:
? getPluginType(options.editor, ELEMENT_LIC) child.type === getPluginType(options.editor, ELEMENT_PARAGRAPH)
: child.type, ? getPluginType(options.editor, ELEMENT_LIC)
} as TDescendant) : child.type,
), } as TDescendant)
}), ),
}
},
}, },
paragraph: { paragraph: {
transform: (node, lastLineNumber, options) => { transform: (node, lastLineNumber, options) => {
const children = remarkTransformElementChildren( const children = remarkTransformElementChildren(
node, node,
lastLineNumber, node.position.end.line,
options options
) )
@ -182,7 +184,11 @@ export const remarkDefaultElementRules: RemarkElementRules<Value> = {
{ {
type: getPluginType(options.editor, ELEMENT_LINK), type: getPluginType(options.editor, ELEMENT_LINK),
url: node.url, url: node.url,
children: remarkTransformElementChildren(node, lastLineNumber, options), children: remarkTransformElementChildren(
node,
node.position.end.line,
options
),
}, },
], ],
}, },
@ -203,7 +209,11 @@ export const remarkDefaultElementRules: RemarkElementRules<Value> = {
{ {
type: getPluginType(options.editor, ELEMENT_BLOCKQUOTE), type: getPluginType(options.editor, ELEMENT_BLOCKQUOTE),
children: node.children!.flatMap((paragraph) => children: node.children!.flatMap((paragraph) =>
remarkTransformElementChildren(paragraph, lastLineNumber, options) remarkTransformElementChildren(
paragraph,
node.position.end.line,
options
)
), ),
}, },
], ],