Skip to content

Commit 5bce06e

Browse files
committed
Add data-editorjs-change-event-id property
1 parent 85281ef commit 5bce06e

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

examples/ExampleReactBlockTool/Container.tsx renamed to examples/ExampleReactBlockTool/Content.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useCallback } from "react";
22
import type { ChangeEventHandler, FunctionComponent } from "react";
33
import type { ExampleReactBlockToolDispatchData } from "./ExampleReactBlockTool";
44

5-
const Container: FunctionComponent<{
5+
const Content: FunctionComponent<{
66
dispatchData: ExampleReactBlockToolDispatchData;
77
text: string;
88
}> = ({ dispatchData, text }) => {
@@ -14,4 +14,4 @@ const Container: FunctionComponent<{
1414
return <input value={text} onChange={handleTextChange} />;
1515
};
1616

17-
export { Container };
17+
export { Content };

examples/ExampleReactBlockTool/ExampleReactBlockTool.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { BlockTool } from "@editorjs/editorjs";
2+
import { nanoid } from "nanoid";
23
import ReactDOM from "react-dom";
3-
import { Container } from "./Container";
4+
import { Content } from "./Content";
45

56
interface ExampleReactBlockToolData {
67
text: string;
@@ -13,10 +14,12 @@ type ExampleReactBlockToolDispatchData = (action: { text?: string }) => void;
1314

1415
class ExampleReactBlockTool implements BlockTool {
1516
#container: HTMLDivElement;
17+
#editorJSChangeEventID: string;
1618
#text: string;
1719

1820
constructor() {
1921
this.#container = document.createElement("div");
22+
this.#editorJSChangeEventID = nanoid();
2023
this.#text = "";
2124
}
2225

@@ -37,12 +40,17 @@ class ExampleReactBlockTool implements BlockTool {
3740
this.#text = action.text;
3841
}
3942

43+
// Dispatch Editor.js change event even without DOM changes.
44+
this.#editorJSChangeEventID = nanoid();
45+
4046
this.renderContainer();
4147
};
4248

4349
renderContainer() {
4450
ReactDOM.render(
45-
<Container dispatchData={this.#dispatchData} text={this.#text} />,
51+
<div data-editorjs-change-event-id={this.#editorJSChangeEventID}>
52+
<Content dispatchData={this.#dispatchData} text={this.#text} />
53+
</div>,
4654
this.#container
4755
);
4856
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dependencies": {
1616
"@editorjs/editorjs": "^2.19.1",
1717
"fast-deep-equal": "^3.1.3",
18+
"nanoid": "^3.1.20",
1819
"react": "^17.0.1",
1920
"react-dom": "^17.0.1"
2021
},

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,11 @@ ms@^2.1.1:
13391339
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
13401340
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
13411341

1342+
nanoid@^3.1.20:
1343+
version "3.1.20"
1344+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.20.tgz#badc263c6b1dcf14b71efaa85f6ab4c1d6cfc788"
1345+
integrity sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==
1346+
13421347
natural-compare@^1.4.0:
13431348
version "1.4.0"
13441349
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"

0 commit comments

Comments
 (0)