Tui.editor: In reactJs how can i add youtubeplugin?

Created on 14 Apr 2020  Â·  9Comments  Â·  Source: nhn/tui.editor

Summary

Use React like doc in https://nhn.github.io/tui.editor/latest/tutorial-example17-creating-plugin
Got error in Editor.codeBlockManager.setReplacer.

Version

"@toast-ui/react-editor": "^2.0.1",

Additional context

import { Editor} from '@toast-ui/react-editor';
...
previewStyle="vertical"
initialEditType="wysiwyg"
initialValue="Hello world"
usageStatistics={false}
ref={editorRef}
plugins={[colorSyntax, youtubePlugin]}
onChange={getPostInfo}
/>

const youtubePlugin =() => {
//TypeError: Cannot read property 'setReplacer' of undefined
Editor.codeBlockManager.setReplacer('youtube', function(youtubeId) {
...
});
}

Question React inactive

Most helpful comment

const videoPlugin = (editor) => {
  const { codeBlockManager } = Object.getPrototypeOf(editor).constructor
  codeBlockManager.setReplacer('youtube', function(sourceId) {
  ……
}

this way work in Editor and Viewer

All 9 comments

@yoojeen126
codeBlockManager is static property, so that you can use as below.
We consider improving the way to provide static method in wrapper for usability.

import ToastEditor from '@toast-ui/editor';
import { Editor } from '@toast-ui/react-editor';

// ...
const youtubePlugin =() => {
  ToastEditor.codeBlockManager.setReplacer('youtube', function(youtubeId) {
  // ...
  }
});

<Editor placeholder="hello react editor world!"
  previewStyle="vertical"
  initialEditType="wysiwyg"
  initialValue="Hello world"
  usageStatistics={false}
  ref={editorRef}
  plugins={[colorSyntax, youtubePlugin]}
  onChange={getPostInfo}
/>

This issue has been automatically marked as inactive because there hasn’t been much going on it lately. It is going to be closed after 7 days. Thanks!

This issue will be closed due to inactivity. Thanks for your contribution!

@yoojeen126
codeBlockManager is static property, so that you can use as below.
We consider improving the way to provide static method in wrapper for usability.

import ToastEditor from '@toast-ui/editor';
import { Editor } from '@toast-ui/react-editor';

// ...
const youtubePlugin =() => {
  ToastEditor.codeBlockManager.setReplacer('youtube', function(youtubeId) {
  // ...
  }
});

<Editor placeholder="hello react editor world!"
  previewStyle="vertical"
  initialEditType="wysiwyg"
  initialValue="Hello world"
  usageStatistics={false}
  ref={editorRef}
  plugins={[colorSyntax, youtubePlugin]}
  onChange={getPostInfo}
/>

@js87zz

is this way work in Viewer ?

i define the video plugin function which use in Editor and Viewer, but only work in Editor

const videoPlugin = (editor) => {
  const { codeBlockManager } = Object.getPrototypeOf(editor).constructor
  codeBlockManager.setReplacer('youtube', function(sourceId) {
  ……
}

this way work in Editor and Viewer

@leeonfield/editor-plugin-video now can help to insert video in Tui.editor

const videoPlugin = (editor) => {
  const { codeBlockManager } = Object.getPrototypeOf(editor).constructor
  codeBlockManager.setReplacer('youtube', function(sourceId) {
  ……
}

this way work in Editor and Viewer

How we can get the reference of editor.

const videoPlugin = (editor) => {
  const { codeBlockManager } = Object.getPrototypeOf(editor).constructor
  codeBlockManager.setReplacer('youtube', function(sourceId) {
  ……
}

this way work in Editor and Viewer

How we can get the reference of editor.

editor is the param of this plugin,no need to get the reference of editor

const plugins = [videoPlugin]
<TuiEditor plugins={plugins} />
const videoPlugin = (editor) => {
  const { codeBlockManager } = Object.getPrototypeOf(editor).constructor
  codeBlockManager.setReplacer('youtube', function(sourceId) {
  ……
}

this way work in Editor and Viewer

How we can get the reference of editor.

editor is the param of this plugin,no need to get the reference of editor

const plugins = [videoPlugin]
<TuiEditor plugins={plugins} />

Thanks, It worked.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aarangara picture aarangara  Â·  3Comments

alirizaadiyahsi picture alirizaadiyahsi  Â·  4Comments

hrvoj3e picture hrvoj3e  Â·  3Comments

hellojsna picture hellojsna  Â·  4Comments

mygyugyu picture mygyugyu  Â·  3Comments