From 66c6259587fbff593cdb41a652fa1d6f00988094 Mon Sep 17 00:00:00 2001 From: ShadiBlitz <101566855+ShadiBlitz@users.noreply.github.com> Date: Tue, 21 Jan 2025 21:39:56 +0200 Subject: [PATCH] feat(placeholder): hide placeholder in atom nodes by default --- .changeset/ten-cars-sparkle.md | 5 +++++ packages/extension-placeholder/src/placeholder.ts | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/ten-cars-sparkle.md diff --git a/.changeset/ten-cars-sparkle.md b/.changeset/ten-cars-sparkle.md new file mode 100644 index 00000000000..58083644103 --- /dev/null +++ b/.changeset/ten-cars-sparkle.md @@ -0,0 +1,5 @@ +--- +"@tiptap/extension-placeholder": patch +--- + +feat(placeholder): do not show placeholder on atom nodes by default diff --git a/packages/extension-placeholder/src/placeholder.ts b/packages/extension-placeholder/src/placeholder.ts index 08427a257c0..9d184a5e3c9 100644 --- a/packages/extension-placeholder/src/placeholder.ts +++ b/packages/extension-placeholder/src/placeholder.ts @@ -63,6 +63,15 @@ export interface PlaceholderOptions { * @default false */ includeChildren: boolean + + /** + * **Controls if the placeholder should be shown for atom nodes.** + * + * If true, the placeholder will be shown for atom nodes. + * If false, the placeholder will not be shown for atom nodes. + * @default false + */ + showWhenAtom: boolean; } /** @@ -81,6 +90,7 @@ export const Placeholder = Extension.create({ showOnlyWhenEditable: true, showOnlyCurrent: true, includeChildren: false, + showWhenAtom: false, } }, @@ -103,8 +113,9 @@ export const Placeholder = Extension.create({ doc.descendants((node, pos) => { const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize const isEmpty = !node.isLeaf && isNodeEmpty(node) + const isContentEditable = this.options.showWhenAtom ? !node.type.isAtom : true; - if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) { + if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty && isContentEditable) { const classes = [this.options.emptyNodeClass] if (isEmptyDoc) {