Skip to content

Commit 2d6ee2c

Browse files
authored
feat: Add dangerouslyLowLevelInstance (#204)
1 parent 47719a3 commit 2d6ee2c

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,29 @@ const handleSave = React.useCallback(async () => {
177177
<ReactEditorJS onInitialize={handleInitialize} defaultValue={blocks} />
178178
```
179179

180+
If you want to access low-level instance, you can use `dangerouslyLowLevelInstance`
181+
182+
⚠️ dangerouslyLowLevelInstance depends on the execution environment.
183+
184+
| Environment | Instnace Type |
185+
| - | - |
186+
| Browser | EditorJS instance|
187+
| NodeJS | null |
188+
189+
```tsx
190+
const editorCore = React.useRef(null)
191+
192+
const handleInitialize = React.useCallback((instance) => {
193+
editorCore.current = instance
194+
}, [])
195+
196+
const handleSave = React.useCallback(async () => {
197+
const savedData = await editorCore.current.dangerouslyLowLevelInstance?.save();
198+
}, [])
199+
200+
<ReactEditorJS onInitialize={handleInitialize} defaultValue={blocks} />
201+
```
202+
180203
### Haven't received data from server (when use Link)
181204

182205
You should set linkTool [config](https://github.com/editor-js/link#usage). 💪🏻

packages/@react-editor-js/client/src/client-editor-core.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export class ClientEditorCore implements EditorCore {
2121
})
2222
}
2323

24+
public get dangerouslyLowLevelInstance() {
25+
return this._editorJS
26+
}
27+
2428
public async clear() {
2529
await this._editorJS.clear()
2630
}

packages/@react-editor-js/core/src/editor-core.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ export interface EditorCore {
88
save(): Promise<OutputData>
99

1010
render(data: OutputData): Promise<void>
11+
12+
get dangerouslyLowLevelInstance(): any | null
1113
}

packages/@react-editor-js/core/tests/TestEditorCore.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export class TestEditorCore implements EditorCore {
1111
return this._data
1212
}
1313

14+
public get dangerouslyLowLevelInstance() {
15+
return null
16+
}
17+
1418
public async clear() {}
1519

1620
public async save() {

packages/@react-editor-js/server/src/server-editor-core.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export class ServerEditorCore implements EditorCore {
1010
}
1111
}
1212

13+
public get dangerouslyLowLevelInstance() {
14+
return null
15+
}
16+
1317
public async clear() {}
1418

1519
public async save() {

0 commit comments

Comments
 (0)