editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

No readonly property

Open YogurtTheHorse opened this issue 7 years ago • 34 comments

No property to make editor readonly (or I didn't found it)

YogurtTheHorse avatar Feb 11 '19 15:02 YogurtTheHorse

Hi there!

There is no option to make the editor read-only at the moment. We are planning a release of the version 2 in the next couple of weeks (now the editor is on beta-stage). This feature will not be included to the release, but we would add it to our backlog for the next version.

gohabereg avatar Feb 11 '19 16:02 gohabereg

Hi there, just putting in one more vote for read-only. Editor.js seems amazing and thank you for all of the great work. Without read-only, however, how can editor.js be used to publish anything? What are the use cases if there is no read-only support? For my use cases (an education publishing platform), read-only is a critical mvp feature. Content is generally created by a few to be consumed by many.

tomchify avatar Apr 05 '19 16:04 tomchify

any other workaround for read only?

AsathalMannan avatar Apr 16 '19 01:04 AsathalMannan

After render editor js, find all content editable elements and off it. And hide control elements by css class.

dimensi avatar Apr 16 '19 09:04 dimensi

@dimensi Seems like an approachable idea for now. Do you have an example or do you know how to find all content editable?

EcaterinaM avatar Apr 17 '19 13:04 EcaterinaM

@dimensi Seems like an approachable idea for now. Do you have an example or do you know how to find all content editable?

document.querySelectorAll('[contenteditable=true]')

dimensi avatar Apr 17 '19 13:04 dimensi

+1

ohsik avatar Apr 22 '19 22:04 ohsik

+1 can we have a proper property in the constructor please?

Vik-Th0r avatar Apr 23 '19 13:04 Vik-Th0r

Hi there, I totally agree with @tomchify.

We would like to use the editor in our next product but really need the read-only mode so users can only read the text.

aximobile avatar May 16 '19 07:05 aximobile

Hi there.

We are planning to editorjs as well. Rendering content using editorjs and hiding the toolkit wont work for us since it effects SEO.

siddug avatar Jun 05 '19 17:06 siddug

Hi there.

We are planning to editorjs as well. Rendering content using editorjs and hiding the toolkit wont work for us since it effects SEO.

I haven't tried this yet - you may clone the editor element to a div, remove the tools and content-editable attributes from there, and then save the HTML parsed by the editor to your database.

elhardoum avatar Jun 14 '19 09:06 elhardoum

https://medium.com/@sumitvekariya7/editor-js-read-only-mode-in-angular-4f73192ed860

I have created readOnly view mode for angular using switchcase statement based on block type and I have used css classes given in editor.js iteslf, so It creates almost same user interface.

sumitvekariya avatar Dec 12 '19 05:12 sumitvekariya

+1

Dagorik avatar Dec 23 '19 21:12 Dagorik

In react i create a component. It has the main elements.

import React from 'react';
import parser from 'html-react-parser';

function ReadOnly({ data }) {
  const renderBlock = ({type, data}) => {
    let content = ""
    switch (type) {
      case "header":
        const element =  React.createElement(
          `h${data.level}`,
          {
            className: 'ce-header',
          },
          data.text
        )  
        content =    (<div style={{height: "fit-content"}}>
            {element}
          </div>)
      break;
      case "list":
        content = (<ul className={`"cdx-block" "cdx-list" "cdx-list--${data.style}"`}>
          {data.items.map(item =>  <li class="cdx-list__item">{item}</li>)}
        </ul>)
      break;
      case "embed":
          content = (<div className="cdx-block embed-tool">
          <iframe className="embed-tool__content" style={{width: "fit-100%"}} height="320" frameborder="0" width="580"
            allowfullscreen src={data.embed}></iframe>
          <div style={{'text-align': "center", 'margin-top': "5px"}}>{data.caption}</div>
          </div> )
      break;
      case "code":
        content = (<div class="cdx-block ce-code">
            <span style={{'text-align': "right", 'margin-bottom': "5px"}}>{data.language}</span>
            <pre className="ce-code__textarea cdx-input prettyprint"><code className="lang-js">{data.code+""}</code></pre>
          </div>)
      break;
      case "image":
          content = (
            <div className="cdx-block image-tool image-tool--filled">
              <div className="image-tool__image">
                <img className="image-tool__image-picture" src={data.file.url}></img>
                <span style={{'text-align': "right", 'margin-bottom': "5px"}}>{data.caption}</span>
              </div>
            </div>
          )
      break;
      default:
        content = (<div className="ce-paragraph cdx-block"> {parser(`${data.text}`)} </div>)
        break;
    }
    return (<div className="ce-block">
    <div className="ce-block__content">
      {content}
    </div>
  </div>)
  }

  return (
    data.blocks.map(block => renderBlock(block))
  );
}

export default ReadOnly;

Dagorik avatar Jan 02 '20 19:01 Dagorik

I can't agree more that read-only is the critical mvp feature.

ForestWang6616 avatar Jan 13 '20 12:01 ForestWang6616

@Dagorik Thanks for sharing your work. I have used Your code it seems to be working fine but styling not works for me. Did you write CSS in another file or anything else?

UddeshJain avatar Jan 13 '20 14:01 UddeshJain

@UddeshJain no, the classes are what editor.js uses

Dagorik avatar Jan 13 '20 21:01 Dagorik

@Dagorik Do I need to import any file from anywhere to make Css work?

UddeshJain avatar Jan 14 '20 07:01 UddeshJain

any updates for read only property ?

KareemDa avatar May 03 '20 08:05 KareemDa

@KareemDa Hi. It is included in the next 2.18 release. You can follow the PR

khaydarov avatar May 03 '20 08:05 khaydarov