You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello and first of all: Thank you for the great framework! ❤️
I have a background in education and I try to adopt lexical for my work. In education we often with deal "structured data", i.e. nodes which have a predefined number and types of children. Take for example an exercise which consists of a task and a solution. In JSON I would describe such data with an object:
However to my knowledge lexical does not support nodes with predefined and named children.
My Question
How can I implement "structured data" like an exercise in lexical? Is there a canonical way to do it?
The exercise should always have its predefined structure. For example it shouldn't be possible to select the task and to delete it (so that there is a solution without a task) or to have an exercise with more than one task (for example when the user pastes a task after the current one).
So my idea is to create three different element nodes: The ExerciseNode is an ElementNode having exactly the two children TaskNode and SolutionNode (see exercise.ts). I use node transformations and listeners to make sure that an exercise always maintains it's internal structure:
At https://kulla.github.io/2025-08-05-lexical-editor-experiment/ you can try it out. It isn't perfect and buggy and I suggest I have missed some corner cases. I wonder whether there is an easier way to achieve my goal and I am happy for any suggestions! 🙏
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello and first of all: Thank you for the great framework! ❤️
I have a background in education and I try to adopt lexical for my work. In education we often with deal "structured data", i.e. nodes which have a predefined number and types of children. Take for example an exercise which consists of a task and a solution. In JSON I would describe such data with an object:
However to my knowledge lexical does not support nodes with predefined and named children.
My Question
How can I implement "structured data" like an exercise in lexical? Is there a canonical way to do it?
The exercise should always have its predefined structure. For example it shouldn't be possible to select the task and to delete it (so that there is a solution without a task) or to have an exercise with more than one task (for example when the user pastes a task after the current one).
My attempt
At https://github.com/kulla/2025-08-05-lexical-editor-experiment I experimented with a possible solution. I used the circumstance that an exercise can also be defined as a tuple:
So my idea is to create three different element nodes: The
ExerciseNodeis anElementNodehaving exactly the two childrenTaskNodeandSolutionNode(see exercise.ts). I use node transformations and listeners to make sure that an exercise always maintains it's internal structure::beforeelements for rendering non editable headings of the task and solution node.At https://kulla.github.io/2025-08-05-lexical-editor-experiment/ you can try it out. It isn't perfect and buggy and I suggest I have missed some corner cases. I wonder whether there is an easier way to achieve my goal and I am happy for any suggestions! 🙏
Beta Was this translation helpful? Give feedback.
All reactions