tinymce / tinymce-react

Offical TinyMCE React component
MIT License
938 stars 151 forks source link

I want to make Editor readonly, but still enable comment #376

Closed jackle23 closed 1 year ago

jackle23 commented 1 year ago

currently, I have use case where I want Editor to be readable only by users, but still able to comment

currently, TinyMCE already has readonly feature that what I want, but in Editor for React, it can not work.

This is my using version: "@tinymce/tinymce-react": "^4.2.0"

exalate-issue-sync[bot] commented 1 year ago

Ref: INT-2986

tiny-james commented 1 year ago

TinyMCE doesn't currently support that feature. The best I can do is to simulate it with a controlled component.

https://codesandbox.io/s/readonly-comments-w2knjz?file=/src/index.js

Note: this does not validate that only comments are added to the content. It uses the event fired when comments are created to grab a snapshot of the HTML. Basically it makes it very hard to permanently modify the content but it is certainly not impossible. With the use of the browser console I could easily trick this implementation by setting the content and manually firing the event - though this is true of anything that is client side validated only.

If you wanted to make sure this was correct you'd have to perform a diff server side and ensure that the content was only modified in approved ways.