@tiptap/extension-placeholder
Advanced tools
Comparing version 3.0.0-next.4 to 3.0.0-next.5
@@ -1,59 +0,2 @@ | ||
import { Editor, Extension } from '@tiptap/core'; | ||
import { Node } from '@tiptap/pm/model'; | ||
interface PlaceholderOptions { | ||
/** | ||
* **The class name for the empty editor** | ||
* @default 'is-editor-empty' | ||
*/ | ||
emptyEditorClass: string; | ||
/** | ||
* **The class name for empty nodes** | ||
* @default 'is-empty' | ||
*/ | ||
emptyNodeClass: string; | ||
/** | ||
* **The placeholder content** | ||
* | ||
* You can use a function to return a dynamic placeholder or a string. | ||
* @default 'Write something …' | ||
*/ | ||
placeholder: ((PlaceholderProps: { | ||
editor: Editor; | ||
node: Node; | ||
pos: number; | ||
hasAnchor: boolean; | ||
}) => string) | string; | ||
/** | ||
* **Checks if the placeholder should be only shown when the editor is editable.** | ||
* | ||
* If true, the placeholder will only be shown when the editor is editable. | ||
* If false, the placeholder will always be shown. | ||
* @default true | ||
*/ | ||
showOnlyWhenEditable: boolean; | ||
/** | ||
* **Checks if the placeholder should be only shown when the current node is empty.** | ||
* | ||
* If true, the placeholder will only be shown when the current node is empty. | ||
* If false, the placeholder will be shown when any node is empty. | ||
* @default true | ||
*/ | ||
showOnlyCurrent: boolean; | ||
/** | ||
* **Controls if the placeholder should be shown for all descendents.** | ||
* | ||
* If true, the placeholder will be shown for all descendents. | ||
* If false, the placeholder will only be shown for the current node. | ||
* @default false | ||
*/ | ||
includeChildren: boolean; | ||
} | ||
/** | ||
* This extension allows you to add a placeholder to your editor. | ||
* A placeholder is a text that appears when the editor or a node is empty. | ||
* @see https://www.tiptap.dev/api/extensions/placeholder | ||
*/ | ||
declare const Placeholder: Extension<PlaceholderOptions, any>; | ||
export { Placeholder, type PlaceholderOptions, Placeholder as default }; | ||
import { Placeholder } from '@tiptap/extensions'; | ||
export { Placeholder, PlaceholderOptions, Placeholder as default } from '@tiptap/extensions'; |
@@ -1,65 +0,10 @@ | ||
// src/placeholder.ts | ||
import { Extension, isNodeEmpty } from "@tiptap/core"; | ||
import { Plugin, PluginKey } from "@tiptap/pm/state"; | ||
import { Decoration, DecorationSet } from "@tiptap/pm/view"; | ||
var Placeholder = Extension.create({ | ||
name: "placeholder", | ||
addOptions() { | ||
return { | ||
emptyEditorClass: "is-editor-empty", | ||
emptyNodeClass: "is-empty", | ||
placeholder: "Write something \u2026", | ||
showOnlyWhenEditable: true, | ||
showOnlyCurrent: true, | ||
includeChildren: false | ||
}; | ||
}, | ||
addProseMirrorPlugins() { | ||
return [ | ||
new Plugin({ | ||
key: new PluginKey("placeholder"), | ||
props: { | ||
decorations: ({ doc, selection }) => { | ||
const active = this.editor.isEditable || !this.options.showOnlyWhenEditable; | ||
const { anchor } = selection; | ||
const decorations = []; | ||
if (!active) { | ||
return null; | ||
} | ||
const isEmptyDoc = this.editor.isEmpty; | ||
doc.descendants((node, pos) => { | ||
const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize; | ||
const isEmpty = !node.isLeaf && isNodeEmpty(node); | ||
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) { | ||
const classes = [this.options.emptyNodeClass]; | ||
if (isEmptyDoc) { | ||
classes.push(this.options.emptyEditorClass); | ||
} | ||
const decoration = Decoration.node(pos, pos + node.nodeSize, { | ||
class: classes.join(" "), | ||
"data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({ | ||
editor: this.editor, | ||
node, | ||
pos, | ||
hasAnchor | ||
}) : this.options.placeholder | ||
}); | ||
decorations.push(decoration); | ||
} | ||
return this.options.includeChildren; | ||
}); | ||
return DecorationSet.create(doc, decorations); | ||
} | ||
} | ||
}) | ||
]; | ||
} | ||
}); | ||
// src/index.ts | ||
import { Placeholder } from "@tiptap/extensions"; | ||
import { Placeholder as Placeholder2, PlaceholderOptions } from "@tiptap/extensions"; | ||
var index_default = Placeholder; | ||
export { | ||
Placeholder, | ||
Placeholder2 as Placeholder, | ||
PlaceholderOptions, | ||
index_default as default | ||
}; | ||
//# sourceMappingURL=index.js.map |
MIT License | ||
Copyright (c) 2024, Tiptap GmbH | ||
Copyright (c) 2025, Tiptap GmbH | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"name": "@tiptap/extension-placeholder", | ||
"description": "placeholder extension for tiptap", | ||
"version": "3.0.0-next.4", | ||
"version": "3.0.0-next.5", | ||
"homepage": "https://tiptap.dev", | ||
@@ -34,8 +34,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"@tiptap/core": "^3.0.0-next.4", | ||
"@tiptap/pm": "^3.0.0-next.4" | ||
"@tiptap/extensions": "^3.0.0-next.5" | ||
}, | ||
"peerDependencies": { | ||
"@tiptap/core": "^3.0.0-next.1", | ||
"@tiptap/pm": "^3.0.0-next.1" | ||
"@tiptap/extensions": "^3.0.0-next.3" | ||
}, | ||
@@ -42,0 +40,0 @@ "repository": { |
@@ -1,5 +0,5 @@ | ||
import { Placeholder } from './placeholder.js' | ||
import { Placeholder } from '@tiptap/extensions' | ||
export * from './placeholder.js' | ||
export { Placeholder, PlaceholderOptions } from '@tiptap/extensions' | ||
export default Placeholder |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
1
6090
10
48
1