codex-team / codex-team/editor.js

How to get instance of editor?

Open
#1,138 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
31.9k
Forks
2.2k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

# How to get a previously created editor instance?

For logistical reasons I cannot keep a store of editor instances. Is there a way to get a previously created editor instance on an element?

I.e.

```
EditorJS.getEditor(element);
```

My current solution:

```
import EditorJS from '@editorjs/editorjs';

export default {
instances: [],

create(element){
const editor = new EditorJS({
/**
* element
* @type {HtmlElement}
*/
holderId: element,

/**
* Available tools/blocks in the editor
* @type {Array}
*/
tools: [

],
});

this.instances.push({
element,
editor
});
},
destroy(element){
var instance = this.instances.find(instance => instance.element === element);
if (instance == null){
return false;
}
instance.editor.destroy();
return true;
},
}

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.