#Create a Custom NoWrap Feature for Lexical

1 messages · Page 1 of 1 (latest)

tacit ermineBOT
#

Hi, chat!

Could you please help me figure out how to create a custom feature for Lexical that wraps text and other inline nodes inside a "noWrap" wrapper, which would return something like {type: 'noWrap', children: []} in RichText?

Right now, I have a custom feature that inserts Lottie animations into the text. However, I need to wrap both the text and the Lottie elements inside the editor so that on the website, something like commu<lottie>nications renders within a single <span> rather than being split into three separate elements according to the JSON object hierarchy.

I've attached a screenshot showing how my editor currently look. And this is the object in the API.

"title": {
"root": {
"children": [
{
"children": [
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": "We are like, Netflix in commu",
"type": "text",
"version": 1
},
{
"type": "lottie",
"version": 1,
"lottieId": "67e04fda7ce6f4204c034d16"
},
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": "nications. For every single campaign we produce high",
"type": "text",
"version": 1
},
{
"type": "lottie",
"version": 1,
"lottieId": "67e02a447ce6f4204c034910"
},
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": "quality well-crafted branded content.",
"type": "text",
"version": 1
}
],
"direction": "ltr",
"format": "",
"indent": 0,
"type": "paragraph",
"version": 1,
"textFormat": 0,
"textStyle": ""
}
],
"direction": "ltr",
"format": "",
"indent": 0,
"type": "root",
"version": 1
}
},

hallow valeBOT
#

Original message from @dusty plinth - Moved from #general message

real jacinth
#

How are you currently inserting the lottie animation?

dusty plinth
real jacinth
#

I imagine this could vary in difficulty, and I'm no lexical expert, but I think you might want to check nearby nodes in proximity and, if found, then proceed to wrap them. Otherwise, what you could do is make a simple feature that just lets you highlight some text and wrap in a span manually - what do you think?

#

What I mean is text highlighting the text, including your lottie node, and then clicking an icon in the toolbar, it would replace the highlighted children with a single node that has those nodes as children themselves if that makes sense

dusty plinth
dusty plinth
real jacinth