Skip to content

Commit

Permalink
add third condition
Browse files Browse the repository at this point in the history
  • Loading branch information
PMAWorks committed Dec 3, 2024
1 parent 3dddf77 commit a74661f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bundle/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type ParseInsertedUrlAsImage = (text: string) => {imageUrl: string; title
export type WysiwygPlaceholderOptions = {
value?: string | (() => string);
/** Default – empty-doc */
behavior?: 'empty-doc' | 'empty-row';
behavior?: 'empty-doc' | 'empty-doc-row' | 'empty-row';
};

export type MarkdownEditorMdOptions = {
Expand Down
11 changes: 8 additions & 3 deletions src/bundle/wysiwyg-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ export const BundlePreset: ExtensionAuto<BundlePresetOptions> = (builder, opts)
paragraphPlaceholder: (node: Node, parent?: Node | null) => {
const {value, behavior} = opts.placeholderOptions || {};

const isRowEmpty = !node.text && parent?.type.name === BaseNode.Doc;
const isDocEmpty = isRowEmpty && parent.childCount === 1;
const showPlaceholder = behavior === 'empty-row' ? isRowEmpty : isDocEmpty;
const emptyList = {
'empty-row': !node.text,
'empty-doc-row': !node.text && parent?.type.name === BaseNode.Doc,
'empty-doc':
!node.text && parent?.type.name === BaseNode.Doc && parent.childCount === 1,
};

const showPlaceholder = emptyList[behavior || 'empty-doc'];

if (!showPlaceholder) return null;

Expand Down

0 comments on commit a74661f

Please sign in to comment.