ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
29.97k stars 3.25k forks source link

Read-only block / part of the block #549

Closed Mangatt closed 7 years ago

Mangatt commented 7 years ago

Hi, is there a way how to make a block or part of the block read-only? For example to have all block not editable, but let user change caption for that block?

hueypeard commented 7 years ago

I believe the best way to do this is to define a custom node in your schema and pass contentEditable={false} as a prop to it when it renders.

Not sure what the best way to allow caption editing would be. I suppose you could have another Slate instance (or, if you can go without rich text editing, just have a text input instead) rendering inside the block and updating node metadata (used by your custom node to render the caption) accordingly as input is received.

Mangatt commented 7 years ago

I did not knew about disabling editation per block. But idea with another Slate instance puzzles me - is there a way how to render another instance of slate from node blocks instead of regular nodes? And could this work? Because when I tried that, my editor crashed.

oyeanuj commented 7 years ago

@Mangatt Curious where you ended up with?

In the examples, the one with embed does something similar with single input field inside the node. I also think you could just make it a nested node where the caption is also an editable text node

ianstormtaylor commented 7 years ago

There's a new example called check-lists that shows how to add basic pieces around a block that aren't editable, while keeping selection behaviors intact. That's one way to do, and there are other previous issues about nesting Slate editors, although I haven't experimented with that personally. I'm going to close this in attempt to clean up issues, but feel free to keep discussing!

laurensiusadi commented 6 years ago

@ianstormtaylor I just tried implementing https://www.slatejs.org/#/check-lists. You said:

... a block that aren't editable, while keeping selection behaviors intact

But I can't select all check-lists, I can only select one.

2018-06-18_14-42-50

How can I make all selectable so I can delete some or all of them at once?