3

I need to create nested list objects like :

1. Abc
2. def
    a. abc
        i. lmn
        ii. opq
    b. def
3. ghi

I am using Slate Js as my editor where when a user presses tab I have added the code where the node is updated with its level :

if (event.key === "Tab") {
      event.preventDefault();
      
      
      let currentNode = Editor.above(editor,{at : editor.selection})[0];
      if(currentNode.type === "listItem"){
      let newLevel = currentNode.level ? currentNode.level + 1 : 1;
     
      Transforms.setNodes(editor, {level : newLevel});
}}

Here the level is getting added to the node but I cannot nest this data into a tree structure as slateJs only allows three level of nesting of nodes and it needs a text key in the third level.

Sonu Kumar
  • 31
  • 4

1 Answers1

0

You can. The trick is wrapping the text of a 'list item' node in a 'list item text' node (e.g. a span or p), as explained in this slate schema of @prezly/slate-lists. The subsequent nested list can now be added to the same 'list item' node as a 'list' node.

Blee
  • 419
  • 5
  • 11