@tiptap/extension-placeholder
Advanced tools
Comparing version 3.0.0-next.0 to 3.0.0-next.1
@@ -1,67 +0,65 @@ | ||
import { Extension, isNodeEmpty } from '@tiptap/core'; | ||
import { Plugin, PluginKey } from '@tiptap/pm/state'; | ||
import { Decoration, DecorationSet } from '@tiptap/pm/view'; | ||
/** | ||
* 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 | ||
*/ | ||
const Placeholder = Extension.create({ | ||
name: 'placeholder', | ||
addOptions() { | ||
return { | ||
emptyEditorClass: 'is-editor-empty', | ||
emptyNodeClass: 'is-empty', | ||
placeholder: 'Write something …', | ||
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/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); | ||
} | ||
} | ||
}) | ||
]; | ||
} | ||
}); | ||
export { Placeholder, Placeholder as default }; | ||
//# sourceMappingURL=index.js.map | ||
// src/index.ts | ||
var src_default = Placeholder; | ||
export { | ||
Placeholder, | ||
src_default as default | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@tiptap/extension-placeholder", | ||
"description": "placeholder extension for tiptap", | ||
"version": "3.0.0-next.0", | ||
"version": "3.0.0-next.1", | ||
"homepage": "https://tiptap.dev", | ||
@@ -18,3 +18,3 @@ "keywords": [ | ||
".": { | ||
"types": "./dist/packages/extension-placeholder/src/index.d.ts", | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
@@ -26,4 +26,3 @@ "require": "./dist/index.cjs" | ||
"module": "dist/index.js", | ||
"umd": "dist/index.umd.js", | ||
"types": "dist/packages/extension-placeholder/src/index.d.ts", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
@@ -34,8 +33,8 @@ "src", | ||
"devDependencies": { | ||
"@tiptap/core": "^3.0.0-next.0", | ||
"@tiptap/pm": "^3.0.0-next.0" | ||
"@tiptap/core": "^3.0.0-next.1", | ||
"@tiptap/pm": "^3.0.0-next.1" | ||
}, | ||
"peerDependencies": { | ||
"@tiptap/core": "^3.0.0-next.0", | ||
"@tiptap/pm": "^3.0.0-next.0" | ||
"@tiptap/core": "^3.0.0-next.1", | ||
"@tiptap/pm": "^3.0.0-next.1" | ||
}, | ||
@@ -48,5 +47,4 @@ "repository": { | ||
"scripts": { | ||
"clean": "rm -rf dist", | ||
"build": "npm run clean && rollup -c" | ||
"build": "tsup" | ||
} | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26545
10
326
1