refactor: remove isEditable from node views, remove viewUpdate event

This commit is contained in:
Philipp Kühn
2021-04-07 22:07:36 +02:00
parent 7b1d8d103c
commit a0e2a830d7
14 changed files with 3 additions and 92 deletions

View File

@@ -1,5 +1,4 @@
import React from 'react'
import { useReactNodeView } from './useReactNodeView'
export interface NodeViewContentProps {
className?: string,
@@ -7,14 +6,12 @@ export interface NodeViewContentProps {
}
export const NodeViewContent: React.FC<NodeViewContentProps> = props => {
const { isEditable } = useReactNodeView()
const Tag = props.as || 'div'
return (
<Tag
className={props.className}
data-node-view-content=""
contentEditable={isEditable}
style={{ whiteSpace: 'pre-wrap' }}
/>
)

View File

@@ -40,21 +40,11 @@ class ReactNodeView extends NodeView<React.FunctionComponent, Editor> {
}
const ReactNodeViewProvider: React.FunctionComponent = componentProps => {
const [isEditable, setIsEditable] = useState(this.editor.isEditable)
const onDragStart = this.onDragStart.bind(this)
const onViewUpdate = () => setIsEditable(this.editor.isEditable)
const Component = this.component
useEffect(() => {
this.editor.on('viewUpdate', onViewUpdate)
return () => {
this.editor.off('viewUpdate', onViewUpdate)
}
}, [])
return (
<ReactNodeViewContext.Provider value={{ onDragStart, isEditable }}>
<ReactNodeViewContext.Provider value={{ onDragStart }}>
<Component {...componentProps} />
</ReactNodeViewContext.Provider>
)

View File

@@ -1,12 +1,10 @@
import { createContext, useContext } from 'react'
export interface ReactNodeViewContextProps {
isEditable: boolean,
onDragStart: (event: DragEvent) => void,
}
export const ReactNodeViewContext = createContext<Partial<ReactNodeViewContextProps>>({
isEditable: undefined,
onDragStart: undefined,
})