File tree 4 files changed +18
-4
lines changed
examples/ExampleReactBlockTool
4 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { useCallback } from "react";
2
2
import type { ChangeEventHandler , FunctionComponent } from "react" ;
3
3
import type { ExampleReactBlockToolDispatchData } from "./ExampleReactBlockTool" ;
4
4
5
- const Container : FunctionComponent < {
5
+ const Content : FunctionComponent < {
6
6
dispatchData : ExampleReactBlockToolDispatchData ;
7
7
text : string ;
8
8
} > = ( { dispatchData, text } ) => {
@@ -14,4 +14,4 @@ const Container: FunctionComponent<{
14
14
return < input value = { text } onChange = { handleTextChange } /> ;
15
15
} ;
16
16
17
- export { Container } ;
17
+ export { Content } ;
Original file line number Diff line number Diff line change 1
1
import type { BlockTool } from "@editorjs/editorjs" ;
2
+ import { nanoid } from "nanoid" ;
2
3
import ReactDOM from "react-dom" ;
3
- import { Container } from "./Container " ;
4
+ import { Content } from "./Content " ;
4
5
5
6
interface ExampleReactBlockToolData {
6
7
text : string ;
@@ -13,10 +14,12 @@ type ExampleReactBlockToolDispatchData = (action: { text?: string }) => void;
13
14
14
15
class ExampleReactBlockTool implements BlockTool {
15
16
#container: HTMLDivElement ;
17
+ #editorJSChangeEventID: string ;
16
18
#text: string ;
17
19
18
20
constructor ( ) {
19
21
this . #container = document . createElement ( "div" ) ;
22
+ this . #editorJSChangeEventID = nanoid ( ) ;
20
23
this . #text = "" ;
21
24
}
22
25
@@ -37,12 +40,17 @@ class ExampleReactBlockTool implements BlockTool {
37
40
this . #text = action . text ;
38
41
}
39
42
43
+ // Dispatch Editor.js change event even without DOM changes.
44
+ this . #editorJSChangeEventID = nanoid ( ) ;
45
+
40
46
this . renderContainer ( ) ;
41
47
} ;
42
48
43
49
renderContainer ( ) {
44
50
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 > ,
46
54
this . #container
47
55
) ;
48
56
}
Original file line number Diff line number Diff line change 15
15
"dependencies" : {
16
16
"@editorjs/editorjs" : " ^2.19.1" ,
17
17
"fast-deep-equal" : " ^3.1.3" ,
18
+ "nanoid" : " ^3.1.20" ,
18
19
"react" : " ^17.0.1" ,
19
20
"react-dom" : " ^17.0.1"
20
21
},
Original file line number Diff line number Diff line change @@ -1339,6 +1339,11 @@ ms@^2.1.1:
1339
1339
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
1340
1340
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
1341
1341
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
+
1342
1347
natural-compare@^1.4.0 :
1343
1348
version "1.4.0"
1344
1349
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
You can’t perform that action at this time.
0 commit comments