Skip to main content

Add editorjs format for RichString

Project description

** Warning this cube is not intended for use in production currently **

Summary

Add editorjs format for RichString. This cube adds the application/vnd.cubicweb.editorjs mimetype to the available formats for RichStrings. It also adds a widget which allows to edit the RichString using the EditorJS library (a WYSIWYG editor).

Status of this project

This project has been initiated as a POC to test integration of EditorJS in CubicWeb.

Features:

  • setting the format of a RichString to application/vnd.cubicweb.editorjs
  • edition on an already existing RichString attribute with EditorJS
  • rendering a RichString using this mime type in some conditions (see below)
  • RQL plugin allowing to edit and execute RQL queries

Known bugs:

  • when switching to application/vnd.cubicweb.editorjs the editor is not loaded which means that only already saved attributes can be edited with EditorJS
  • the rich string is not rendered when it is asynchroneously loaded (after the page's scripts have run). This happens with CubicWeb web in tab views.
  • the breadcrumb displays the json instead of a rendered version of the RichString
  • it makes automatic tests of client cubes fail

Implementation flaws:

  • the implementation use monkeypatches to
    • add the application/vnd.cubicweb.editorjs format to the known format list
    • override some views
    • override entities printable_value method (might not be the best place to add the widget)
  • missing mttransforms for application/vnd.cubicweb.editorjs to html
  • images uploads are not supported

Usage in react applications

React applications don't suffer most of the problems seen above as they handle the rendering themselves. Displaying an EditorJS is as easy as:

function Edit() {
  const instanceRef = React.useRef<EditorJS | null>(null);
  async function handleSave() {
    if (instanceRef.current !== null) {
      const savedData = await instanceRef.current.save();
      rqlClient.queryRows(
        `Set X content %(content)s Where X is BlogEntry, X eid ${eid}`,
        { content: JSON.stringify(savedData) }
      );
    }
  }
  return (
    <>
      <EditorJs
          instanceRef={(instance) => (instanceRef.current = instance)}
          data={JSON.parse(blogEntry.content)}
      />
      <button onClick={handleSave}>Save</button>
    </>
  )
}

For rendering, a library like https://github.com/jeremyrajan/editorjs2html can be used.

if (contentFormat === "application/vnd.cubicweb.editorjs") {
    const edjsParser = EditorJsToHTML();
    const html = edjsParser.parse(JSON.parse(blogEntry.content)).join("");
    return <div dangerouslySetInnerHTML={{ __html: html }} />;
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cubicweb-editorjs-0.2.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

cubicweb_editorjs-0.2.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file cubicweb-editorjs-0.2.0.tar.gz.

File metadata

  • Download URL: cubicweb-editorjs-0.2.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.2

File hashes

Hashes for cubicweb-editorjs-0.2.0.tar.gz
Algorithm Hash digest
SHA256 737a40e9742ee2308df37de5de2c0f774cf10745a36dac0f07a5800719014230
MD5 409b66e05f1a06ffd84b98b85b9aeff9
BLAKE2b-256 b47e5cae1a9ac001a178817a123ef9e84a9994b9c42fee3cc5eb24575516fb06

See more details on using hashes here.

File details

Details for the file cubicweb_editorjs-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cubicweb_editorjs-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 66e4cb4111a4381c845b2e696d7d75f6a98bd64cc5a41ad07fcb6fcfbb91fc5a
MD5 033075758b300f8e891f6057fd4daf24
BLAKE2b-256 843a96e3998c64da640042679dbf0c4633a98fd59e3108745aedf43c700bbd95

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page