fix: fix a bug when using nested node views in react, fix #1747
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import React from 'react'
|
||||
import React, { useEffect } from 'react'
|
||||
import { useReactNodeView } from './useReactNodeView'
|
||||
|
||||
export interface NodeViewContentProps {
|
||||
[key: string]: any,
|
||||
@@ -7,6 +8,11 @@ export interface NodeViewContentProps {
|
||||
|
||||
export const NodeViewContent: React.FC<NodeViewContentProps> = React.forwardRef((props, ref) => {
|
||||
const Tag = props.as || 'div'
|
||||
const { maybeMoveContentDOM } = useReactNodeView()
|
||||
|
||||
useEffect(() => {
|
||||
maybeMoveContentDOM?.()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<Tag
|
||||
|
||||
@@ -50,10 +50,11 @@ class ReactNodeView extends NodeView<React.FunctionComponent, Editor, ReactNodeV
|
||||
|
||||
const ReactNodeViewProvider: React.FunctionComponent = componentProps => {
|
||||
const onDragStart = this.onDragStart.bind(this)
|
||||
const maybeMoveContentDOM = this.maybeMoveContentDOM.bind(this)
|
||||
const Component = this.component
|
||||
|
||||
return (
|
||||
<ReactNodeViewContext.Provider value={{ onDragStart }}>
|
||||
<ReactNodeViewContext.Provider value={{ onDragStart, maybeMoveContentDOM }}>
|
||||
<Component {...componentProps} />
|
||||
</ReactNodeViewContext.Provider>
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createContext, useContext } from 'react'
|
||||
|
||||
export interface ReactNodeViewContextProps {
|
||||
onDragStart: (event: DragEvent) => void,
|
||||
maybeMoveContentDOM: () => void,
|
||||
}
|
||||
|
||||
export const ReactNodeViewContext = createContext<Partial<ReactNodeViewContextProps>>({
|
||||
|
||||
Reference in New Issue
Block a user