1

我在我的 react js 应用程序中添加了EditorJs插件:

import ReactDOM from "react-dom";
import React, { Component } from "react";

import EditorJs from "react-editor-js";

import { EDITOR_JS_TOOLS } from "./constants";

class ReactEditor extends Component {
  render() {
    return (
      <EditorJs
        tools={EDITOR_JS_TOOLS}
        data={{
          blocks: [
            {
              type: "header",
              data: {
                text: "Editor.js",
                level: 2
              }
            },
            {
              type: "paragraph",
              data: {
              }
            },
            {
              type: "header",
              data: {
                text: "Key features",
                level: 3
              }
            },
            {
              type: "list",
              data: {
                style: "unordered",
                items: [
                  "It is a block-styled editor",
                  "It returns clean data output in JSON",
                  "Designed to be extendable and pluggable with a simple API"
                ]
              }
            },
            {
              type: "header",
              data: {
                text: "What does it mean «block-styled editor»",
                level: 3
              }
            },
            {
              type: "paragraph",
              data: {
                text:
                  'Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js <mark class="cdx-marker">workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc</mark>. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor\'s Core.'
              }
            },
            {
              type: "paragraph",
              data: {
                text:
                  'There are dozens of <a href="https://github.com/editor-js">ready-to-use Blocks</a> and the <a href="https://editorjs.io/creating-a-block-tool">simple API</a> for creation any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA-buttons and even games.'
              }
            },
            {
              type: "header",
              data: {
                text: "What does it mean clean data output",
                level: 3
              }
            },
            {
              type: "paragraph",
              data: {
                text:
                  "Classic WYSIWYG-editors produce raw HTML-markup with both content data and content appearance. On the contrary, Editor.js outputs JSON object with data of each Block. You can see an example below"
              }
            },
            {
              type: "paragraph",
              data: {
                text:
                  'Given data can be used as you want: render with HTML for <code class="inline-code">Web clients</code>, render natively for <code class="inline-code">mobile apps</code>, create markup for <code class="inline-code">Facebook Instant Articles</code> or <code class="inline-code">Google AMP</code>, generate an <code class="inline-code">audio version</code> and so on.'
              }
            },
            {
              type: "paragraph",
              data: {
                text:
                  "Clean data is useful to sanitize, validate and process on the backend."
              }
            },
            {
              type: "delimiter",
              data: {}
            },
            {
              type: "paragraph",
              data: {
                text:
                  "We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make it's core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. "
              }
            },
            {
              type: "image",
              data: {
                file: {
                  url:
                    "https://codex.so/upload/redactor_images/o_e48549d1855c7fc1807308dd14990126.jpg"
                },
                caption: "",
                withBorder: true,
                stretched: false,
                withBackground: false
              }
            }
          ],
          version: "2.12.4"
        }}
      />
    );
  }
}

ReactDOM.render(<ReactEditor />, document.getElementById("root"));

根据文档,我可以创建一个自定义元素:

render() {
  return (
    <EditorJs holder="custom">
      <div id="custom" />
    </EditorJs>
  );
}

问题:我想将 : 作为自定义元素添加input<input type="text"/>但即使我这样做我也无法管理:

<EditorJs holder="custom">
  <input id="custom" type="text"/>
</EditorJs>

谁知道如何在上面的插件中添加这个自定义元素?
演示:https ://codesandbox.io/embed/react-editor-js-23opz

4

1 回答 1

1

我在文档中发现我可以为 editor.js 创建一个插件: https ://editorjs.io/the-first-plugin 。其中一个示例如下所示:

class SimpleImage {
  static get toolbox() {
    return {
      title: 'Image',
      icon: '<svg width="17" height="15" viewBox="0 0 336 276" xmlns="http://www.w3.org/2000/svg"><path d="M291 150V79c0-19-15-34-34-34H79c-19 0-34 15-34 34v42l67-44 81 72 56-29 42 30zm0 52l-43-30-56 30-81-67-66 39v23c0 19 15 34 34 34h178c17 0 31-13 34-29zM79 0h178c44 0 79 35 79 79v118c0 44-35 79-79 79H79c-44 0-79-35-79-79V79C0 35 35 0 79 0z"/></svg>'
    };
  }

  render() {
    return document.createElement('input');
  }

  save(blockContent) {
    return {
      url: blockContent.value
    }
  }
}

于 2021-01-05T06:57:00.703 回答