@tiptap/extension-placeholder 2.0.0-beta.21 → 2.0.0-beta.211
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +64 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +64 -0
- package/package.json +36 -11
- package/src/placeholder.ts +44 -28
- package/CHANGELOG.md +0 -180
- package/LICENSE.md +0 -21
- package/dist/packages/extension-placeholder/src/index.d.ts +0 -3
- package/dist/packages/extension-placeholder/src/placeholder.d.ts +0 -13
- package/dist/tiptap-extension-placeholder.cjs.js +0 -60
- package/dist/tiptap-extension-placeholder.cjs.js.map +0 -1
- package/dist/tiptap-extension-placeholder.esm.js +0 -56
- package/dist/tiptap-extension-placeholder.esm.js.map +0 -1
- package/dist/tiptap-extension-placeholder.umd.js +0 -62
- package/dist/tiptap-extension-placeholder.umd.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/placeholder.ts
|
|
2
|
+
var _core = require('@tiptap/core');
|
|
3
|
+
var _state = require('@tiptap/pm/state');
|
|
4
|
+
var _view = require('@tiptap/pm/view');
|
|
5
|
+
var Placeholder = _core.Extension.create({
|
|
6
|
+
name: "placeholder",
|
|
7
|
+
addOptions() {
|
|
8
|
+
return {
|
|
9
|
+
emptyEditorClass: "is-editor-empty",
|
|
10
|
+
emptyNodeClass: "is-empty",
|
|
11
|
+
placeholder: "Write something \u2026",
|
|
12
|
+
showOnlyWhenEditable: true,
|
|
13
|
+
showOnlyCurrent: true,
|
|
14
|
+
includeChildren: false
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
addProseMirrorPlugins() {
|
|
18
|
+
return [
|
|
19
|
+
new (0, _state.Plugin)({
|
|
20
|
+
props: {
|
|
21
|
+
decorations: ({ doc, selection }) => {
|
|
22
|
+
const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
|
|
23
|
+
const { anchor } = selection;
|
|
24
|
+
const decorations = [];
|
|
25
|
+
if (!active) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const emptyDocInstance = doc.type.createAndFill();
|
|
29
|
+
const isEditorEmpty = (emptyDocInstance == null ? void 0 : emptyDocInstance.sameMarkup(doc)) && emptyDocInstance.content.findDiffStart(doc.content) === null;
|
|
30
|
+
doc.descendants((node, pos) => {
|
|
31
|
+
const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
|
|
32
|
+
const isEmpty = !node.isLeaf && !node.childCount;
|
|
33
|
+
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
34
|
+
const classes = [this.options.emptyNodeClass];
|
|
35
|
+
if (isEditorEmpty) {
|
|
36
|
+
classes.push(this.options.emptyEditorClass);
|
|
37
|
+
}
|
|
38
|
+
const decoration = _view.Decoration.node(pos, pos + node.nodeSize, {
|
|
39
|
+
class: classes.join(" "),
|
|
40
|
+
"data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
|
|
41
|
+
editor: this.editor,
|
|
42
|
+
node,
|
|
43
|
+
pos,
|
|
44
|
+
hasAnchor
|
|
45
|
+
}) : this.options.placeholder
|
|
46
|
+
});
|
|
47
|
+
decorations.push(decoration);
|
|
48
|
+
}
|
|
49
|
+
return this.options.includeChildren;
|
|
50
|
+
});
|
|
51
|
+
return _view.DecorationSet.create(doc, decorations);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// src/index.ts
|
|
60
|
+
var src_default = Placeholder;
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
exports.Placeholder = Placeholder; exports.default = src_default;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Editor, Extension } from '@tiptap/core';
|
|
2
|
+
import { Node } from '@tiptap/pm/model';
|
|
3
|
+
|
|
4
|
+
interface PlaceholderOptions {
|
|
5
|
+
emptyEditorClass: string;
|
|
6
|
+
emptyNodeClass: string;
|
|
7
|
+
placeholder: ((PlaceholderProps: {
|
|
8
|
+
editor: Editor;
|
|
9
|
+
node: Node;
|
|
10
|
+
pos: number;
|
|
11
|
+
hasAnchor: boolean;
|
|
12
|
+
}) => string) | string;
|
|
13
|
+
showOnlyWhenEditable: boolean;
|
|
14
|
+
showOnlyCurrent: boolean;
|
|
15
|
+
includeChildren: boolean;
|
|
16
|
+
}
|
|
17
|
+
declare const Placeholder: Extension<PlaceholderOptions, any>;
|
|
18
|
+
|
|
19
|
+
export { Placeholder, PlaceholderOptions, Placeholder as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/placeholder.ts
|
|
2
|
+
import { Extension } from "@tiptap/core";
|
|
3
|
+
import { Plugin } from "@tiptap/pm/state";
|
|
4
|
+
import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
|
5
|
+
var Placeholder = Extension.create({
|
|
6
|
+
name: "placeholder",
|
|
7
|
+
addOptions() {
|
|
8
|
+
return {
|
|
9
|
+
emptyEditorClass: "is-editor-empty",
|
|
10
|
+
emptyNodeClass: "is-empty",
|
|
11
|
+
placeholder: "Write something \u2026",
|
|
12
|
+
showOnlyWhenEditable: true,
|
|
13
|
+
showOnlyCurrent: true,
|
|
14
|
+
includeChildren: false
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
addProseMirrorPlugins() {
|
|
18
|
+
return [
|
|
19
|
+
new Plugin({
|
|
20
|
+
props: {
|
|
21
|
+
decorations: ({ doc, selection }) => {
|
|
22
|
+
const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
|
|
23
|
+
const { anchor } = selection;
|
|
24
|
+
const decorations = [];
|
|
25
|
+
if (!active) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const emptyDocInstance = doc.type.createAndFill();
|
|
29
|
+
const isEditorEmpty = (emptyDocInstance == null ? void 0 : emptyDocInstance.sameMarkup(doc)) && emptyDocInstance.content.findDiffStart(doc.content) === null;
|
|
30
|
+
doc.descendants((node, pos) => {
|
|
31
|
+
const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
|
|
32
|
+
const isEmpty = !node.isLeaf && !node.childCount;
|
|
33
|
+
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
34
|
+
const classes = [this.options.emptyNodeClass];
|
|
35
|
+
if (isEditorEmpty) {
|
|
36
|
+
classes.push(this.options.emptyEditorClass);
|
|
37
|
+
}
|
|
38
|
+
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
|
39
|
+
class: classes.join(" "),
|
|
40
|
+
"data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
|
|
41
|
+
editor: this.editor,
|
|
42
|
+
node,
|
|
43
|
+
pos,
|
|
44
|
+
hasAnchor
|
|
45
|
+
}) : this.options.placeholder
|
|
46
|
+
});
|
|
47
|
+
decorations.push(decoration);
|
|
48
|
+
}
|
|
49
|
+
return this.options.includeChildren;
|
|
50
|
+
});
|
|
51
|
+
return DecorationSet.create(doc, decorations);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// src/index.ts
|
|
60
|
+
var src_default = Placeholder;
|
|
61
|
+
export {
|
|
62
|
+
Placeholder,
|
|
63
|
+
src_default as default
|
|
64
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-placeholder",
|
|
3
3
|
"description": "placeholder extension for tiptap",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.211",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -12,21 +12,46 @@
|
|
|
12
12
|
"type": "github",
|
|
13
13
|
"url": "https://github.com/sponsors/ueberdosis"
|
|
14
14
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"require": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"main": "dist/index.cjs",
|
|
24
|
+
"module": "dist/index.js",
|
|
25
|
+
"types": "dist/index.d.ts",
|
|
19
26
|
"files": [
|
|
20
27
|
"src",
|
|
21
28
|
"dist"
|
|
22
29
|
],
|
|
23
30
|
"peerDependencies": {
|
|
24
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
31
|
+
"@tiptap/core": "^2.0.0-beta.209",
|
|
32
|
+
"@tiptap/pm": "^2.0.0-beta.209"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@tiptap/core": "^2.0.0-beta.211",
|
|
36
|
+
"@tiptap/pm": "^2.0.0-beta.211"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/ueberdosis/tiptap",
|
|
41
|
+
"directory": "packages/extension-placeholder"
|
|
25
42
|
},
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"prosemirror-state": "^1.3.4",
|
|
29
|
-
"prosemirror-view": "^1.18.7"
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup"
|
|
30
45
|
},
|
|
31
|
-
"
|
|
46
|
+
"tsup": {
|
|
47
|
+
"entry": [
|
|
48
|
+
"src/index.ts"
|
|
49
|
+
],
|
|
50
|
+
"dts": true,
|
|
51
|
+
"splitting": true,
|
|
52
|
+
"format": [
|
|
53
|
+
"esm",
|
|
54
|
+
"cjs"
|
|
55
|
+
]
|
|
56
|
+
}
|
|
32
57
|
}
|
package/src/placeholder.ts
CHANGED
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
import { Editor, Extension } from '@tiptap/core'
|
|
2
|
-
import { Node as ProsemirrorNode } from '
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { Node as ProsemirrorNode } from '@tiptap/pm/model'
|
|
3
|
+
import { Plugin } from '@tiptap/pm/state'
|
|
4
|
+
import { Decoration, DecorationSet } from '@tiptap/pm/view'
|
|
5
5
|
|
|
6
6
|
export interface PlaceholderOptions {
|
|
7
|
-
emptyEditorClass: string
|
|
8
|
-
emptyNodeClass: string
|
|
9
|
-
placeholder:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
emptyEditorClass: string
|
|
8
|
+
emptyNodeClass: string
|
|
9
|
+
placeholder:
|
|
10
|
+
| ((PlaceholderProps: {
|
|
11
|
+
editor: Editor
|
|
12
|
+
node: ProsemirrorNode
|
|
13
|
+
pos: number
|
|
14
|
+
hasAnchor: boolean
|
|
15
|
+
}) => string)
|
|
16
|
+
| string
|
|
17
|
+
showOnlyWhenEditable: boolean
|
|
18
|
+
showOnlyCurrent: boolean
|
|
19
|
+
includeChildren: boolean
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export const Placeholder = Extension.create<PlaceholderOptions>({
|
|
18
23
|
name: 'placeholder',
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
addOptions() {
|
|
26
|
+
return {
|
|
27
|
+
emptyEditorClass: 'is-editor-empty',
|
|
28
|
+
emptyNodeClass: 'is-empty',
|
|
29
|
+
placeholder: 'Write something …',
|
|
30
|
+
showOnlyWhenEditable: true,
|
|
31
|
+
showOnlyCurrent: true,
|
|
32
|
+
includeChildren: false,
|
|
33
|
+
}
|
|
26
34
|
},
|
|
27
35
|
|
|
28
36
|
addProseMirrorPlugins() {
|
|
@@ -35,34 +43,42 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|
|
35
43
|
const decorations: Decoration[] = []
|
|
36
44
|
|
|
37
45
|
if (!active) {
|
|
38
|
-
return
|
|
46
|
+
return null
|
|
39
47
|
}
|
|
40
48
|
|
|
49
|
+
// only calculate isEmpty once due to its performance impacts (see issue #3360)
|
|
50
|
+
const emptyDocInstance = doc.type.createAndFill()
|
|
51
|
+
const isEditorEmpty = emptyDocInstance?.sameMarkup(doc)
|
|
52
|
+
&& emptyDocInstance.content.findDiffStart(doc.content) === null
|
|
53
|
+
|
|
41
54
|
doc.descendants((node, pos) => {
|
|
42
|
-
const hasAnchor = anchor >= pos && anchor <=
|
|
43
|
-
const isEmpty = !node.isLeaf && !node.
|
|
55
|
+
const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize
|
|
56
|
+
const isEmpty = !node.isLeaf && !node.childCount
|
|
44
57
|
|
|
45
58
|
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
46
59
|
const classes = [this.options.emptyNodeClass]
|
|
47
60
|
|
|
48
|
-
if (
|
|
61
|
+
if (isEditorEmpty) {
|
|
49
62
|
classes.push(this.options.emptyEditorClass)
|
|
50
63
|
}
|
|
51
64
|
|
|
52
65
|
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
|
53
66
|
class: classes.join(' '),
|
|
54
|
-
'data-placeholder':
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
'data-placeholder':
|
|
68
|
+
typeof this.options.placeholder === 'function'
|
|
69
|
+
? this.options.placeholder({
|
|
70
|
+
editor: this.editor,
|
|
71
|
+
node,
|
|
72
|
+
pos,
|
|
73
|
+
hasAnchor,
|
|
74
|
+
})
|
|
75
|
+
: this.options.placeholder,
|
|
60
76
|
})
|
|
61
77
|
|
|
62
78
|
decorations.push(decoration)
|
|
63
79
|
}
|
|
64
80
|
|
|
65
|
-
return
|
|
81
|
+
return this.options.includeChildren
|
|
66
82
|
})
|
|
67
83
|
|
|
68
84
|
return DecorationSet.create(doc, decorations)
|
package/CHANGELOG.md
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [2.0.0-beta.21](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.20...@tiptap/extension-placeholder@2.0.0-beta.21) (2021-05-28)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [2.0.0-beta.20](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.19...@tiptap/extension-placeholder@2.0.0-beta.20) (2021-05-27)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [2.0.0-beta.19](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.18...@tiptap/extension-placeholder@2.0.0-beta.19) (2021-05-18)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# [2.0.0-beta.18](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.17...@tiptap/extension-placeholder@2.0.0-beta.18) (2021-05-17)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# [2.0.0-beta.17](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.16...@tiptap/extension-placeholder@2.0.0-beta.17) (2021-05-13)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Bug Fixes
|
|
42
|
-
|
|
43
|
-
* check for empty text, fix [#1292](https://github.com/ueberdosis/tiptap/issues/1292) ([456f2b7](https://github.com/ueberdosis/tiptap/commit/456f2b702b146cc3f4a156a71cba8354990c02e0))
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# [2.0.0-beta.16](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.15...@tiptap/extension-placeholder@2.0.0-beta.16) (2021-05-13)
|
|
50
|
-
|
|
51
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# [2.0.0-beta.15](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.14...@tiptap/extension-placeholder@2.0.0-beta.15) (2021-05-07)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
### Bug Fixes
|
|
61
|
-
|
|
62
|
-
* revert adding exports ([bc320d0](https://github.com/ueberdosis/tiptap/commit/bc320d0b4b80b0e37a7e47a56e0f6daec6e65d98))
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
# [2.0.0-beta.14](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.13...@tiptap/extension-placeholder@2.0.0-beta.14) (2021-05-06)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
### Bug Fixes
|
|
72
|
-
|
|
73
|
-
* revert adding type: module ([f8d6475](https://github.com/ueberdosis/tiptap/commit/f8d6475e2151faea6f96baecdd6bd75880d50d2c))
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
# [2.0.0-beta.13](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.12...@tiptap/extension-placeholder@2.0.0-beta.13) (2021-05-06)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
### Bug Fixes
|
|
83
|
-
|
|
84
|
-
* add exports to package.json ([1277fa4](https://github.com/ueberdosis/tiptap/commit/1277fa47151e9c039508cdb219bdd0ffe647f4ee))
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
# [2.0.0-beta.12](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.11...@tiptap/extension-placeholder@2.0.0-beta.12) (2021-05-06)
|
|
91
|
-
|
|
92
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
# [2.0.0-beta.11](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.10...@tiptap/extension-placeholder@2.0.0-beta.11) (2021-05-05)
|
|
99
|
-
|
|
100
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
# [2.0.0-beta.10](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.9...@tiptap/extension-placeholder@2.0.0-beta.10) (2021-05-04)
|
|
107
|
-
|
|
108
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
# [2.0.0-beta.9](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.8...@tiptap/extension-placeholder@2.0.0-beta.9) (2021-04-27)
|
|
115
|
-
|
|
116
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
# [2.0.0-beta.8](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.7...@tiptap/extension-placeholder@2.0.0-beta.8) (2021-04-23)
|
|
123
|
-
|
|
124
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
# [2.0.0-beta.7](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.6...@tiptap/extension-placeholder@2.0.0-beta.7) (2021-04-22)
|
|
131
|
-
|
|
132
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
# [2.0.0-beta.6](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.5...@tiptap/extension-placeholder@2.0.0-beta.6) (2021-04-16)
|
|
139
|
-
|
|
140
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
# [2.0.0-beta.5](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.4...@tiptap/extension-placeholder@2.0.0-beta.5) (2021-04-15)
|
|
147
|
-
|
|
148
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
# [2.0.0-beta.4](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.3...@tiptap/extension-placeholder@2.0.0-beta.4) (2021-04-06)
|
|
155
|
-
|
|
156
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
# [2.0.0-beta.3](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.2...@tiptap/extension-placeholder@2.0.0-beta.3) (2021-03-31)
|
|
163
|
-
|
|
164
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
# [2.0.0-beta.2](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.1...@tiptap/extension-placeholder@2.0.0-beta.2) (2021-03-28)
|
|
171
|
-
|
|
172
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
# 2.0.0-beta.1 (2021-03-24)
|
|
179
|
-
|
|
180
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
package/LICENSE.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021, überdosis GbR
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Editor, Extension } from '@tiptap/core';
|
|
2
|
-
import { Node as ProsemirrorNode } from 'prosemirror-model';
|
|
3
|
-
export interface PlaceholderOptions {
|
|
4
|
-
emptyEditorClass: string;
|
|
5
|
-
emptyNodeClass: string;
|
|
6
|
-
placeholder: ((PlaceholderProps: {
|
|
7
|
-
editor: Editor;
|
|
8
|
-
node: ProsemirrorNode;
|
|
9
|
-
}) => string) | string;
|
|
10
|
-
showOnlyWhenEditable: boolean;
|
|
11
|
-
showOnlyCurrent: boolean;
|
|
12
|
-
}
|
|
13
|
-
export declare const Placeholder: Extension<PlaceholderOptions>;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var core = require('@tiptap/core');
|
|
6
|
-
var prosemirrorView = require('prosemirror-view');
|
|
7
|
-
var prosemirrorState = require('prosemirror-state');
|
|
8
|
-
|
|
9
|
-
const Placeholder = core.Extension.create({
|
|
10
|
-
name: 'placeholder',
|
|
11
|
-
defaultOptions: {
|
|
12
|
-
emptyEditorClass: 'is-editor-empty',
|
|
13
|
-
emptyNodeClass: 'is-empty',
|
|
14
|
-
placeholder: 'Write something …',
|
|
15
|
-
showOnlyWhenEditable: true,
|
|
16
|
-
showOnlyCurrent: true,
|
|
17
|
-
},
|
|
18
|
-
addProseMirrorPlugins() {
|
|
19
|
-
return [
|
|
20
|
-
new prosemirrorState.Plugin({
|
|
21
|
-
props: {
|
|
22
|
-
decorations: ({ doc, selection }) => {
|
|
23
|
-
const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
|
|
24
|
-
const { anchor } = selection;
|
|
25
|
-
const decorations = [];
|
|
26
|
-
if (!active) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
doc.descendants((node, pos) => {
|
|
30
|
-
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
|
|
31
|
-
const isEmpty = !node.isLeaf && !node.textContent;
|
|
32
|
-
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
33
|
-
const classes = [this.options.emptyNodeClass];
|
|
34
|
-
if (this.editor.isEmpty) {
|
|
35
|
-
classes.push(this.options.emptyEditorClass);
|
|
36
|
-
}
|
|
37
|
-
const decoration = prosemirrorView.Decoration.node(pos, pos + node.nodeSize, {
|
|
38
|
-
class: classes.join(' '),
|
|
39
|
-
'data-placeholder': typeof this.options.placeholder === 'function'
|
|
40
|
-
? this.options.placeholder({
|
|
41
|
-
editor: this.editor,
|
|
42
|
-
node,
|
|
43
|
-
})
|
|
44
|
-
: this.options.placeholder,
|
|
45
|
-
});
|
|
46
|
-
decorations.push(decoration);
|
|
47
|
-
}
|
|
48
|
-
return false;
|
|
49
|
-
});
|
|
50
|
-
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
}),
|
|
54
|
-
];
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
exports.Placeholder = Placeholder;
|
|
59
|
-
exports.default = Placeholder;
|
|
60
|
-
//# sourceMappingURL=tiptap-extension-placeholder.cjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extension-placeholder.cjs.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from 'prosemirror-model'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { Plugin } from 'prosemirror-state'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n }) => string) | string,\n showOnlyWhenEditable: boolean,\n showOnlyCurrent: boolean,\n}\n\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n defaultOptions: {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!active) {\n return\n }\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)\n const isEmpty = !node.isLeaf && !node.textContent\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (this.editor.isEmpty) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder': typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return false\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;;;MAgBa,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;IAC9D,IAAI,EAAE,aAAa;IAEnB,cAAc,EAAE;QACd,gBAAgB,EAAE,iBAAiB;QACnC,cAAc,EAAE,UAAU;QAC1B,WAAW,EAAE,mBAAmB;QAChC,oBAAoB,EAAE,IAAI;QAC1B,eAAe,EAAE,IAAI;KACtB;IAED,qBAAqB;QACnB,OAAO;YACL,IAAIC,uBAAM,CAAC;gBACT,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE;wBAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAA;wBAC3E,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;wBAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;wBAEpC,IAAI,CAAC,MAAM,EAAE;4BACX,OAAM;yBACP;wBAED,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG;4BACxB,MAAM,SAAS,GAAG,MAAM,IAAI,GAAG,IAAI,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;4BAClE,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAA;4BAEjD,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,KAAK,OAAO,EAAE;gCAC3D,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;gCAE7C,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;oCACvB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;iCAC5C;gCAED,MAAM,UAAU,GAAGC,0BAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;oCAC3D,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;oCACxB,kBAAkB,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;0CAC9D,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;4CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;4CACnB,IAAI;yCACL,CAAC;0CACA,IAAI,CAAC,OAAO,CAAC,WAAW;iCAC7B,CAAC,CAAA;gCAEF,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;6BAC7B;4BAED,OAAO,KAAK,CAAA;yBACb,CAAC,CAAA;wBAEF,OAAOC,6BAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;iBACF;aACF,CAAC;SACH,CAAA;KACF;CACF;;;;;"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/core';
|
|
2
|
-
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
|
-
import { Plugin } from 'prosemirror-state';
|
|
4
|
-
|
|
5
|
-
const Placeholder = Extension.create({
|
|
6
|
-
name: 'placeholder',
|
|
7
|
-
defaultOptions: {
|
|
8
|
-
emptyEditorClass: 'is-editor-empty',
|
|
9
|
-
emptyNodeClass: 'is-empty',
|
|
10
|
-
placeholder: 'Write something …',
|
|
11
|
-
showOnlyWhenEditable: true,
|
|
12
|
-
showOnlyCurrent: true,
|
|
13
|
-
},
|
|
14
|
-
addProseMirrorPlugins() {
|
|
15
|
-
return [
|
|
16
|
-
new Plugin({
|
|
17
|
-
props: {
|
|
18
|
-
decorations: ({ doc, selection }) => {
|
|
19
|
-
const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
|
|
20
|
-
const { anchor } = selection;
|
|
21
|
-
const decorations = [];
|
|
22
|
-
if (!active) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
doc.descendants((node, pos) => {
|
|
26
|
-
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
|
|
27
|
-
const isEmpty = !node.isLeaf && !node.textContent;
|
|
28
|
-
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
29
|
-
const classes = [this.options.emptyNodeClass];
|
|
30
|
-
if (this.editor.isEmpty) {
|
|
31
|
-
classes.push(this.options.emptyEditorClass);
|
|
32
|
-
}
|
|
33
|
-
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
|
34
|
-
class: classes.join(' '),
|
|
35
|
-
'data-placeholder': typeof this.options.placeholder === 'function'
|
|
36
|
-
? this.options.placeholder({
|
|
37
|
-
editor: this.editor,
|
|
38
|
-
node,
|
|
39
|
-
})
|
|
40
|
-
: this.options.placeholder,
|
|
41
|
-
});
|
|
42
|
-
decorations.push(decoration);
|
|
43
|
-
}
|
|
44
|
-
return false;
|
|
45
|
-
});
|
|
46
|
-
return DecorationSet.create(doc, decorations);
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
}),
|
|
50
|
-
];
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
export default Placeholder;
|
|
55
|
-
export { Placeholder };
|
|
56
|
-
//# sourceMappingURL=tiptap-extension-placeholder.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extension-placeholder.esm.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from 'prosemirror-model'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { Plugin } from 'prosemirror-state'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n }) => string) | string,\n showOnlyWhenEditable: boolean,\n showOnlyCurrent: boolean,\n}\n\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n defaultOptions: {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!active) {\n return\n }\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)\n const isEmpty = !node.isLeaf && !node.textContent\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (this.editor.isEmpty) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder': typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return false\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;;;MAgBa,WAAW,GAAG,SAAS,CAAC,MAAM,CAAqB;IAC9D,IAAI,EAAE,aAAa;IAEnB,cAAc,EAAE;QACd,gBAAgB,EAAE,iBAAiB;QACnC,cAAc,EAAE,UAAU;QAC1B,WAAW,EAAE,mBAAmB;QAChC,oBAAoB,EAAE,IAAI;QAC1B,eAAe,EAAE,IAAI;KACtB;IAED,qBAAqB;QACnB,OAAO;YACL,IAAI,MAAM,CAAC;gBACT,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE;wBAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAA;wBAC3E,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;wBAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;wBAEpC,IAAI,CAAC,MAAM,EAAE;4BACX,OAAM;yBACP;wBAED,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG;4BACxB,MAAM,SAAS,GAAG,MAAM,IAAI,GAAG,IAAI,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;4BAClE,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAA;4BAEjD,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,KAAK,OAAO,EAAE;gCAC3D,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;gCAE7C,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;oCACvB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;iCAC5C;gCAED,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;oCAC3D,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;oCACxB,kBAAkB,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;0CAC9D,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;4CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;4CACnB,IAAI;yCACL,CAAC;0CACA,IAAI,CAAC,OAAO,CAAC,WAAW;iCAC7B,CAAC,CAAA;gCAEF,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;6BAC7B;4BAED,OAAO,KAAK,CAAA;yBACb,CAAC,CAAA;wBAEF,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;iBACF;aACF,CAAC;SACH,CAAA;KACF;CACF;;;;;"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('prosemirror-view'), require('prosemirror-state')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', 'prosemirror-view', 'prosemirror-state'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['@tiptap/extension-placeholder'] = {}, global.core, global.prosemirrorView, global.prosemirrorState));
|
|
5
|
-
}(this, (function (exports, core, prosemirrorView, prosemirrorState) { 'use strict';
|
|
6
|
-
|
|
7
|
-
const Placeholder = core.Extension.create({
|
|
8
|
-
name: 'placeholder',
|
|
9
|
-
defaultOptions: {
|
|
10
|
-
emptyEditorClass: 'is-editor-empty',
|
|
11
|
-
emptyNodeClass: 'is-empty',
|
|
12
|
-
placeholder: 'Write something …',
|
|
13
|
-
showOnlyWhenEditable: true,
|
|
14
|
-
showOnlyCurrent: true,
|
|
15
|
-
},
|
|
16
|
-
addProseMirrorPlugins() {
|
|
17
|
-
return [
|
|
18
|
-
new prosemirrorState.Plugin({
|
|
19
|
-
props: {
|
|
20
|
-
decorations: ({ doc, selection }) => {
|
|
21
|
-
const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
|
|
22
|
-
const { anchor } = selection;
|
|
23
|
-
const decorations = [];
|
|
24
|
-
if (!active) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
doc.descendants((node, pos) => {
|
|
28
|
-
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
|
|
29
|
-
const isEmpty = !node.isLeaf && !node.textContent;
|
|
30
|
-
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
31
|
-
const classes = [this.options.emptyNodeClass];
|
|
32
|
-
if (this.editor.isEmpty) {
|
|
33
|
-
classes.push(this.options.emptyEditorClass);
|
|
34
|
-
}
|
|
35
|
-
const decoration = prosemirrorView.Decoration.node(pos, pos + node.nodeSize, {
|
|
36
|
-
class: classes.join(' '),
|
|
37
|
-
'data-placeholder': typeof this.options.placeholder === 'function'
|
|
38
|
-
? this.options.placeholder({
|
|
39
|
-
editor: this.editor,
|
|
40
|
-
node,
|
|
41
|
-
})
|
|
42
|
-
: this.options.placeholder,
|
|
43
|
-
});
|
|
44
|
-
decorations.push(decoration);
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
});
|
|
48
|
-
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
}),
|
|
52
|
-
];
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
exports.Placeholder = Placeholder;
|
|
57
|
-
exports.default = Placeholder;
|
|
58
|
-
|
|
59
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
60
|
-
|
|
61
|
-
})));
|
|
62
|
-
//# sourceMappingURL=tiptap-extension-placeholder.umd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extension-placeholder.umd.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from 'prosemirror-model'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { Plugin } from 'prosemirror-state'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n }) => string) | string,\n showOnlyWhenEditable: boolean,\n showOnlyCurrent: boolean,\n}\n\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n defaultOptions: {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!active) {\n return\n }\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)\n const isEmpty = !node.isLeaf && !node.textContent\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (this.editor.isEmpty) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder': typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return false\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;QAgBa,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;MAC9D,IAAI,EAAE,aAAa;MAEnB,cAAc,EAAE;UACd,gBAAgB,EAAE,iBAAiB;UACnC,cAAc,EAAE,UAAU;UAC1B,WAAW,EAAE,mBAAmB;UAChC,oBAAoB,EAAE,IAAI;UAC1B,eAAe,EAAE,IAAI;OACtB;MAED,qBAAqB;UACnB,OAAO;cACL,IAAIC,uBAAM,CAAC;kBACT,KAAK,EAAE;sBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE;0BAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAA;0BAC3E,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;0BAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;0BAEpC,IAAI,CAAC,MAAM,EAAE;8BACX,OAAM;2BACP;0BAED,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG;8BACxB,MAAM,SAAS,GAAG,MAAM,IAAI,GAAG,IAAI,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;8BAClE,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAA;8BAEjD,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,KAAK,OAAO,EAAE;kCAC3D,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;kCAE7C,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;sCACvB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;mCAC5C;kCAED,MAAM,UAAU,GAAGC,0BAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;sCAC3D,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;sCACxB,kBAAkB,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;4CAC9D,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;8CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;8CACnB,IAAI;2CACL,CAAC;4CACA,IAAI,CAAC,OAAO,CAAC,WAAW;mCAC7B,CAAC,CAAA;kCAEF,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;+BAC7B;8BAED,OAAO,KAAK,CAAA;2BACb,CAAC,CAAA;0BAEF,OAAOC,6BAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;uBAC9C;mBACF;eACF,CAAC;WACH,CAAA;OACF;GACF;;;;;;;;;;;"}
|