@react-editor-js/core
Advanced tools
Comparing version 2.0.5 to 2.0.6
@@ -6,3 +6,2 @@ 'use strict'; | ||
var React = require('react'); | ||
var Paragraph = require('@editorjs/paragraph'); | ||
@@ -12,3 +11,2 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
var Paragraph__default = /*#__PURE__*/_interopDefaultLegacy(Paragraph); | ||
@@ -43,13 +41,7 @@ /*! ***************************************************************************** | ||
function ReactEditorJS(_a) { | ||
var { factory, holder, tools, defaultValue, children, value, onInitialize } = _a, restProps = __rest(_a, ["factory", "holder", "tools", "defaultValue", "children", "value", "onInitialize"]); | ||
var { factory, holder, defaultValue, children, value, onInitialize } = _a, restProps = __rest(_a, ["factory", "holder", "defaultValue", "children", "value", "onInitialize"]); | ||
const memoizedHolder = React__default["default"].useRef(holder !== null && holder !== void 0 ? holder : `react-editor-js-${Date.now().toString(16)}`); | ||
const editorJS = React__default["default"].useRef(null); | ||
React__default["default"].useEffect(() => { | ||
const extendTools = Object.assign({ | ||
// default tools | ||
paragraph: { | ||
class: Paragraph__default["default"], | ||
inlineToolbar: true, | ||
} }, tools); | ||
editorJS.current = factory.create(Object.assign(Object.assign({ tools: extendTools, holder: memoizedHolder.current }, (defaultValue && { data: defaultValue })), restProps)); | ||
editorJS.current = factory(Object.assign(Object.assign({ holder: memoizedHolder.current }, (defaultValue && { data: defaultValue })), restProps)); | ||
onInitialize === null || onInitialize === void 0 ? void 0 : onInitialize(editorJS.current); | ||
@@ -64,3 +56,3 @@ return () => { | ||
if (value) { | ||
(_a = editorJS.current) === null || _a === void 0 ? void 0 : _a.blocks.render(value); | ||
(_a = editorJS.current) === null || _a === void 0 ? void 0 : _a.render(value); | ||
} | ||
@@ -67,0 +59,0 @@ }, [value]); |
import React from 'react'; | ||
import Paragraph from '@editorjs/paragraph'; | ||
@@ -32,13 +31,7 @@ /*! ***************************************************************************** | ||
function ReactEditorJS(_a) { | ||
var { factory, holder, tools, defaultValue, children, value, onInitialize } = _a, restProps = __rest(_a, ["factory", "holder", "tools", "defaultValue", "children", "value", "onInitialize"]); | ||
var { factory, holder, defaultValue, children, value, onInitialize } = _a, restProps = __rest(_a, ["factory", "holder", "defaultValue", "children", "value", "onInitialize"]); | ||
const memoizedHolder = React.useRef(holder !== null && holder !== void 0 ? holder : `react-editor-js-${Date.now().toString(16)}`); | ||
const editorJS = React.useRef(null); | ||
React.useEffect(() => { | ||
const extendTools = Object.assign({ | ||
// default tools | ||
paragraph: { | ||
class: Paragraph, | ||
inlineToolbar: true, | ||
} }, tools); | ||
editorJS.current = factory.create(Object.assign(Object.assign({ tools: extendTools, holder: memoizedHolder.current }, (defaultValue && { data: defaultValue })), restProps)); | ||
editorJS.current = factory(Object.assign(Object.assign({ holder: memoizedHolder.current }, (defaultValue && { data: defaultValue })), restProps)); | ||
onInitialize === null || onInitialize === void 0 ? void 0 : onInitialize(editorJS.current); | ||
@@ -53,3 +46,3 @@ return () => { | ||
if (value) { | ||
(_a = editorJS.current) === null || _a === void 0 ? void 0 : _a.blocks.render(value); | ||
(_a = editorJS.current) === null || _a === void 0 ? void 0 : _a.render(value); | ||
} | ||
@@ -56,0 +49,0 @@ }, [value]); |
import React from 'react'; | ||
import EditorJS, { EditorConfig } from '@editorjs/editorjs'; | ||
import { EditorJSFactory } from './factory'; | ||
import { EditorConfig } from '@editorjs/editorjs'; | ||
import { EditorCoreFactory } from './factory'; | ||
import { EditorCore } from './editor-core'; | ||
export interface Props extends Omit<EditorConfig, 'data'> { | ||
factory: EditorJSFactory; | ||
factory: EditorCoreFactory; | ||
holder?: string; | ||
@@ -10,3 +11,3 @@ children?: React.ReactElement; | ||
defaultValue?: EditorConfig['data']; | ||
onInitialize?: (editorJS: EditorJS) => void; | ||
onInitialize?: (core: EditorCore) => void; | ||
} |
@@ -1,4 +0,3 @@ | ||
import EditorJS, { EditorConfig } from '@editorjs/editorjs'; | ||
export interface EditorJSFactory { | ||
create(config?: EditorConfig | string): EditorJS; | ||
} | ||
import { EditorConfig } from '@editorjs/editorjs'; | ||
import { EditorCore } from './editor-core'; | ||
export declare type EditorCoreFactory = (config: EditorConfig) => EditorCore; |
export * from './component-types'; | ||
export * from './factory'; | ||
export * from './editor-core'; | ||
export { default as ReactEditorJS } from './ReactEditorJS'; |
import React from 'react'; | ||
import { Props } from '@react-editor-js/core'; | ||
declare function ReactEditorJS({ factory, holder, tools, defaultValue, children, value, onInitialize, ...restProps }: Props): React.ReactElement; | ||
import { Props } from './component-types'; | ||
declare function ReactEditorJS({ factory, holder, defaultValue, children, value, onInitialize, ...restProps }: Props): React.ReactElement; | ||
export default ReactEditorJS; |
{ | ||
"name": "@react-editor-js/core", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "The unofficial editor-js component for React on client", | ||
@@ -17,3 +17,2 @@ "main": "./dist/core.cjs.js", | ||
"@editorjs/editorjs": "*", | ||
"@editorjs/paragraph": "*", | ||
"react": "*" | ||
@@ -23,3 +22,2 @@ }, | ||
"@editorjs/editorjs": "*", | ||
"@editorjs/paragraph": "*", | ||
"@testing-library/react": "^12.1.2", | ||
@@ -26,0 +24,0 @@ "@types/jest": "^27.0.3", |
@@ -63,3 +63,3 @@ <div align="center"> | ||
| value | OutputData | data when using editor js as [controlled component](https://ko.reactjs.org/docs/forms.html#controlled-components). <br> ⚠️ Don't use it with onChange prop. Infinite loops can occur. | | ||
| onInitialize | (editorJS?: EditorJS) => void | Call after editor-js is initialized | | ||
| onInitialize | (editorCore?: EditorCore) => void | Call after editor-js is initialized | | ||
@@ -152,13 +152,26 @@ ## 🧐 FAQ | ||
You can access using instanceRef | ||
The editor-js instance is inaccessible. However, you can access the abstracted editor-js for isomorphic react-editor-js. | ||
```ts | ||
// abstracted editor-js interface | ||
interface EditorCore { | ||
destroy(): Promise<void> | ||
clear(): Promise<void> | ||
save(): Promise<OutputData> | ||
render(data: OutputData): Promise<void> | ||
} | ||
``` | ||
```tsx | ||
const editorJS = React.useRef(null) | ||
const editorCore = React.useRef(null) | ||
const handleInitialize = React.useCallback((instance) => { | ||
editorJS.current = instance | ||
editorCore.current = instance | ||
}, []) | ||
const handleSave = React.useCallback(() => { | ||
const savedData = await editorJS.current.save(); | ||
const savedData = await editorCore.current.save(); | ||
}, []) | ||
@@ -165,0 +178,0 @@ |
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 | ||
@@ -14,3 +15,3 @@ holder?: string | ||
onInitialize?: (editorJS: EditorJS) => void | ||
onInitialize?: (core: EditorCore) => void | ||
} |
@@ -1,5 +0,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 |
export * from './component-types' | ||
export * from './factory' | ||
export * from './editor-core' | ||
export { default as ReactEditorJS } from './ReactEditorJS' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2
8
199
0
18940
309