@@ -32,10 +32,12 @@ const getPlaceholderPluginKeys = (schema: Schema) => {
3232const b = cn ( 'placeholder' ) ;
3333
3434export const createPlaceholder = ( node : Node , parent : Node | null , focus ?: boolean ) => {
35+ const content = getPlaceholderContent ( node , parent ) ;
36+ if ( ! content ) return null ;
37+
3538 const placeholder = document . createElement ( 'div' ) ;
3639 placeholder . classList . add ( ...b ( { focus} ) . split ( ' ' ) ) ;
37- placeholder . textContent = getPlaceholderContent ( node , parent ) ;
38-
40+ placeholder . textContent = content ;
3941 return placeholder ;
4042} ;
4143
@@ -67,18 +69,19 @@ const addDecoration = (
6769
6870 if ( placeholderSpec . customPlugin ) {
6971 widgetsMap [ decorationPosition ] = placeholderSpec . customPlugin ;
70-
7172 return ;
7273 }
7374
7475 const focus = decorationPosition === cursorPos ;
75- if ( focus ) {
76- globalState . hasFocus = true ;
77- }
76+
77+ const placeholderDOM = createPlaceholder ( node , parent , focus ) ;
78+ if ( ! placeholderDOM ) return ;
79+
80+ if ( focus ) globalState . hasFocus = true ;
7881
7982 widgetsMap [ decorationPosition ] = {
8083 pos : decorationPosition ,
81- toDOM : createPlaceholder ( node , parent , focus ) ,
84+ toDOM : placeholderDOM ,
8285 } ;
8386} ;
8487
@@ -185,7 +188,7 @@ function applyState(state: EditorState): PlaceholderPluginState {
185188declare module 'prosemirror-model' {
186189 interface NodeSpec {
187190 placeholder ?: {
188- content : string | ( ( node : Node , parent ?: Node | null ) => string ) ;
191+ content : string | ( ( node : Node , parent ?: Node | null ) => string | null ) ;
189192 customPlugin ?: PluginKey < DecorationSet > ;
190193 alwaysVisible ?: boolean ;
191194 } ;
0 commit comments