Socket
Socket
Sign inDemoInstall

@tiptap/extension-placeholder

Package Overview
Dependencies
Maintainers
5
Versions
170
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tiptap/extension-placeholder - npm Package Compare versions

Comparing version 3.0.0-next.0 to 3.0.0-next.1

dist/index.d.cts

128

dist/index.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc