File size: 994 Bytes
2daf8de | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import type { ReactNode } from 'react'
import { createContext, createElement, useContext } from 'react'
export interface ReactNodeViewContextProps {
onDragStart?: (event: DragEvent) => void
nodeViewContentRef?: (element: HTMLElement | null) => void
/**
* This allows you to add children into the NodeViewContent component.
* This is useful when statically rendering the content of a node view.
*/
nodeViewContentChildren?: ReactNode
}
export const ReactNodeViewContext = createContext<ReactNodeViewContextProps>({
onDragStart: () => {
// no-op
},
nodeViewContentChildren: undefined,
nodeViewContentRef: () => {
// no-op
},
})
export const ReactNodeViewContentProvider = ({
children,
content,
}: {
children: ReactNode
content: ReactNode
}) => {
return createElement(
ReactNodeViewContext.Provider,
{ value: { nodeViewContentChildren: content } },
children,
)
}
export const useReactNodeView = () => useContext(ReactNodeViewContext)
|