editor-js / list

Advanced List tool for the Editor.js.
MIT License
48 stars 47 forks source link

How to store data for nested-list tool #1

Closed talyguryn closed 3 years ago

talyguryn commented 3 years ago

it looks almost the same as for list tool, but all elements now are objects. strings has type "string", nested lists has type "list" (a recursion). this way you can use any nesting level as you need.

{
        "type" : "list",
        "data" : {
            "style" : "unordered",
            "items" : [
                {
                    "type": "string",
                    "value": "This is a block-styled editor"
                },
                {
                    "type": "string",
                    "value": "Clean output data"
                },
                {
                    "type" : "list",
                    "data" : {
                        "style" : "ordered",
                        "items" : [
                            {
                                "type": "string",
                                "value": "This is a block-styled editor"
                            },
                            {
                                "type": "string",
                                "value": "Clean output data"
                            },
                            {
                                "type": "string",
                                "value": "Simple and powerful API"
                            }
                        ]
                    }
                }
            ]
        }
    }
neSpecc commented 3 years ago

I think the type is not useful.

That's for a homogeneous list:

{
  "type" : "list",
  "data" : {
    "style" : "unordered",
    "items" : [
      {
        "content": "Just a text item",
        "items": []
      },
      {
        "content": "The second text item",
        "items": [
          { 
            "content": "Nested item" ,
            "items": [] 
          }
        ]
      }
    ]
  }
}
neSpecc commented 3 years ago

And that's for an inhomogeneous list:

{
  "type" : "list",
  "data" : {
    "style" : "unordered",
    "items" : [
      {
        "content": "Just a text item",
        "items": []
      },
      {
        "content": "The second text item",
        "style" : "ordered",
        "items": [
          { 
            "content": "Nested item" ,
            "items": [] 
          }
        ]
      }
    ]
  }
}

But I don't like that the style is not a required field in this case.

alexanderjulmer commented 3 years ago

Just a side note as it's not explicitly specified in Taly's design. The strings should also allow for HTML formatting.

talyguryn commented 3 years ago

@alexanderjulmer yeah, is is not a problem. you'll be able to allow html tags there

talyguryn commented 3 years ago
  {
    "content": "Just a text item",
    "items": []
  }

why is it a good idea to store items and content in each block?

khaydarov commented 3 years ago

because list might be like this:

- item content-1
-- subitem content-1
-- subitem content-2
-- subitem content-3
- item content-2
-- subitem content-1
talyguryn commented 3 years ago

hm. does a parent item should exist for each sublist?

khaydarov commented 3 years ago

I think yes, otherwise it will look like a sequence of sublists.