Replies: 2 comments 5 replies
-
|
PlateJS doesn't have a built-in way to make only specific blocks (like a paragraph or heading) read-only while keeping the rest of the editor editable docs. The editor-level However, Plate's plugin system is flexible. You can create a custom plugin that intercepts editing operations (like insert, delete, or setNodes) and blocks them for blocks you want to lock. For example, you could add a Here's a rough outline: const ReadOnlyBlockPlugin = {
overrideEditor: (editor) => {
const { deleteBackward, insertText, setNodes } = editor;
editor.deleteBackward = (...args) => {
if (isBlockReadOnly(editor)) return;
deleteBackward(...args);
};
editor.insertText = (text) => {
if (isBlockReadOnly(editor)) return;
insertText(text);
};
editor.setNodes = (...args) => {
if (isBlockReadOnly(editor)) return;
setNodes(...args);
};
return editor;
}
};
function isBlockReadOnly(editor) {
const [block] = Editor.nodes(editor, { match: n => n.readOnly });
return !!block;
}You'd need to adapt this to your block structure and editing needs, but this pattern is supported by Plate's extensible plugin system plugin overrides. There isn't an official example or doc for this use case, but the architecture supports it. If you need more details or a more complete example, let me know! To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
PlateJS doesn't have a built-in feature to make only specific blocks (like paragraphs or headings) read-only while keeping the rest of the editor editable. However, you can achieve this by rendering those blocks as custom void elements with You can also use the There's also an There isn't a plugin or config option for block-level read-only out of the box, so this approach is the recommended workaround for now. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi PlateJS team,
I'm working on a project using PlateJS and I would like to know if it is possible to set just a specific block (for example, a paragraph or heading) as read-only, instead of making the whole editor read-only.
My use case requires users to edit most of the document, but keep certain sections locked to prevent any changes. I've checked the docs but couldn't find a clear approach for this scenario.
Is there a built-in way or recommended technique to make only selected blocks or elements read-only while keeping the rest of the editor editable? If so, could you please point me to an example or documentation link?
Thanks in advance for your help!
Originally posted by @shawonsaha in #4716
Beta Was this translation helpful? Give feedback.
All reactions