-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add EditorCore for isomorphic react-editor-js (#178)
- Loading branch information
1 parent
307aeb5
commit 26e061c
Showing
23 changed files
with
200 additions
and
120 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
packages/@react-editor-js/client/src/ClientEditorJSFactory.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/@react-editor-js/client/src/client-editor-core.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import EditorJS, { EditorConfig, OutputData } from '@editorjs/editorjs' | ||
import Paragraph from '@editorjs/paragraph' | ||
import { EditorCore } from '@react-editor-js/core' | ||
|
||
export class ClientEditorCore implements EditorCore { | ||
private _editorJS: EditorJS | ||
|
||
constructor({ tools, ...config }: EditorConfig) { | ||
const extendTools = { | ||
// default tools | ||
paragraph: { | ||
class: Paragraph, | ||
inlineToolbar: true, | ||
}, | ||
...tools, | ||
} | ||
|
||
this._editorJS = new EditorJS({ | ||
tools: extendTools, | ||
...config, | ||
}) | ||
} | ||
|
||
public async clear() { | ||
await this._editorJS.clear() | ||
} | ||
|
||
public async save() { | ||
return this._editorJS.save() | ||
} | ||
|
||
public async destroy() { | ||
await this._editorJS.destroy() | ||
} | ||
|
||
public async render(data: OutputData) { | ||
await this._editorJS.render(data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
import React from 'react' | ||
import EditorJS, { EditorConfig } from '@editorjs/editorjs' | ||
import { EditorConfig } from '@editorjs/editorjs' | ||
|
||
import { EditorJSFactory } from './factory' | ||
import { EditorCoreFactory } from './factory' | ||
import { EditorCore } from './editor-core' | ||
|
||
export interface Props extends Omit<EditorConfig, 'data'> { | ||
factory: EditorJSFactory | ||
factory: EditorCoreFactory | ||
|
||
holder?: string | ||
children?: React.ReactElement | ||
value?: EditorConfig['data'] | ||
defaultValue?: EditorConfig['data'] | ||
|
||
onInitialize?: (editorJS: EditorJS) => void | ||
onInitialize?: (core: EditorCore) => void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { OutputData } from '@editorjs/editorjs' | ||
|
||
export interface EditorCore { | ||
destroy(): Promise<void> | ||
|
||
clear(): Promise<void> | ||
|
||
save(): Promise<OutputData> | ||
|
||
render(data: OutputData): Promise<void> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import EditorJS, { EditorConfig } from '@editorjs/editorjs' | ||
import { EditorConfig } from '@editorjs/editorjs' | ||
|
||
export interface EditorJSFactory { | ||
create(config?: EditorConfig | string): EditorJS | ||
} | ||
import { EditorCore } from './editor-core' | ||
|
||
export type EditorCoreFactory = (config: EditorConfig) => EditorCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './component-types' | ||
export * from './factory' | ||
export * from './editor-core' | ||
|
||
export { default as ReactEditorJS } from './ReactEditorJS' |
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
packages/@react-editor-js/core/tests/EditorJSStubFactory.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.