collective / volto-hydra

A volto addon to let you edit content in realtime when you have many frontends written in any framework
1 stars 2 forks source link

I can manage container blocks #99

Open djay opened 2 months ago

djay commented 2 months ago

Current volto doesn't handle containers very well. There isn't a built in way to navigate up and down container heirachies and add sub blocks. This was managed by block specific custom code. Removing block custom inline UI we need to have a generic way to manage this.

e.g.

User stories (As an editor...)

Out of scope

Proposed integrator api

<table data-block-id="..." data-block-container="{field:blocks, min:2, max:4, allowed:['SlateBlock', 'ImageBlock'], default:'SlateBlock', 'hide_chooser_add':true, style:'horizontal'}">
<tr data-block-id="..."><td data-editable-field="value"><p>my text</p></td></td>
<tr data-block-id="..."><td data-editable-field="value"><p>other slate</p></td></td>
</table>

This syntax allows for the top level page to have more than one container instead of just the single "blocks" main section. volto doesn't let allow it but in the future we could use this to have blocks placed in a sidebar or footer etc so they don't have to be all in the middle of the page.

djay commented 1 month ago

@MAX-786 of the things that are left this is the thing I'd most like to see

What it means is that if we have a block like the grid - https://demo.plone.org/block/grid-block/text.

So the goal of a demo would be just to be able to add a block to a grid block, remove it and DND it in and out.

btw. Not really sure what they did in https://demo.plone.org/block/grid-block/text to allow multiline text. but it doesn't seem right to me to have paragraphs be seperate blocks outside a grid but one block inside a block. So instead of this I would

djay commented 1 month ago

for the integrator.

json looks like

"debb8187-e54f-4cad-8301-2343d65e2024": {
      "@type": "gridBlock", 
      "blocks": {
        "91cdc344-e34c-4387-b0d2-73962abc2559": {
          "@type": "slate", 
        ...
        }, 
        "b6d056e8-0f7f-453e-b8bc-ef97a654b48f": {
          "@type": "slate", 
        ...
        }
      }, 
      "blocks_layout": {
        "items": [
          "b6d056e8-0f7f-453e-b8bc-ef97a654b48f", 
          "91cdc344-e34c-4387-b0d2-73962abc2559"
        ]
      }, 
      "styles": {}
    }
  }, 

The integrator needs to tell hydra what html element to place the blocks inside only I think.

Something like this?

<table data-block-id="..." data-block-container-horizontal="blocks,blocks_layout">
<tr data-block-id="..."><td data-editable-field="value"><p>my text</p></td></td>
<tr data-block-id="..."><td data-editable-field="value"><p>other slate</p></td></td>
</table>

You can see in this case the integrator has decided to change how the blocks are rendered when inside a container. which this should allow them to do. The above would also allow us to have more than one container in the same block, which I think is something that should be allowed. for example a left slot and a right slot.

Questions

djay commented 3 weeks ago

If the default block isn't slate but you have multiple choices of block then filling the empty container with the first one isn't that good. the user then has to create a new block, rearrange them and remove the default one. If the max size is 1 that can't be done.

There is a couple of options

djay commented 2 weeks ago

I've given it some thought and put what I think is the best approach in the main comment above. Using the idea of a virtual ChooserBlock as the placeholder to be able to render the add button on an empty container.

MAX-786 commented 1 week ago

container block will have multiple instructions and since we using staged approach I will open up a PR and break down these into tasks so that we can tryout containers with each integrations. But first want to discuss few things below.

@djay few things I am not clear with:

the integrator customise the add button on a chooser block or turn another block into a chooser block by adding data-chooser attribute an element within that block.

You can use a container hints outside of a block in order to create multiple areas of a page that can contain blocks

djay commented 1 week ago

@MAX-786 the first one was a mistake which I've now fixed.

The rest I've tried to rewrite it to make it clearer.