@tiptap/extension-placeholder 2.0.0-beta.5 → 2.0.0-beta.53

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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020, überdosis GbR
3
+ Copyright (c) 2021, überdosis GbR
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -7,8 +7,8 @@
7
7
  ## Introduction
8
8
  tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
9
9
 
10
- ## Offical Documentation
10
+ ## Official Documentation
11
11
  Documentation can be found on the [tiptap website](https://tiptap.dev).
12
12
 
13
13
  ## License
14
- tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap-next/blob/main/LICENSE.md).
14
+ tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
@@ -6,8 +6,11 @@ export interface PlaceholderOptions {
6
6
  placeholder: ((PlaceholderProps: {
7
7
  editor: Editor;
8
8
  node: ProsemirrorNode;
9
+ pos: number;
10
+ hasAnchor: boolean;
9
11
  }) => string) | string;
10
12
  showOnlyWhenEditable: boolean;
11
13
  showOnlyCurrent: boolean;
14
+ includeChildren: boolean;
12
15
  }
13
- export declare const Placeholder: Extension<PlaceholderOptions>;
16
+ export declare const Placeholder: Extension<PlaceholderOptions, any>;
@@ -3,17 +3,20 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@tiptap/core');
6
- var prosemirrorView = require('prosemirror-view');
7
6
  var prosemirrorState = require('prosemirror-state');
7
+ var prosemirrorView = require('prosemirror-view');
8
8
 
9
9
  const Placeholder = core.Extension.create({
10
10
  name: 'placeholder',
11
- defaultOptions: {
12
- emptyEditorClass: 'is-editor-empty',
13
- emptyNodeClass: 'is-empty',
14
- placeholder: 'Write something …',
15
- showOnlyWhenEditable: true,
16
- showOnlyCurrent: true,
11
+ addOptions() {
12
+ return {
13
+ emptyEditorClass: 'is-editor-empty',
14
+ emptyNodeClass: 'is-empty',
15
+ placeholder: 'Write something …',
16
+ showOnlyWhenEditable: true,
17
+ showOnlyCurrent: true,
18
+ includeChildren: false,
19
+ };
17
20
  },
18
21
  addProseMirrorPlugins() {
19
22
  return [
@@ -24,11 +27,11 @@ const Placeholder = core.Extension.create({
24
27
  const { anchor } = selection;
25
28
  const decorations = [];
26
29
  if (!active) {
27
- return;
30
+ return null;
28
31
  }
29
32
  doc.descendants((node, pos) => {
30
33
  const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
31
- const isEmpty = !node.isLeaf && core.isNodeEmpty(node);
34
+ const isEmpty = !node.isLeaf && !node.childCount;
32
35
  if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
33
36
  const classes = [this.options.emptyNodeClass];
34
37
  if (this.editor.isEmpty) {
@@ -40,12 +43,14 @@ const Placeholder = core.Extension.create({
40
43
  ? this.options.placeholder({
41
44
  editor: this.editor,
42
45
  node,
46
+ pos,
47
+ hasAnchor,
43
48
  })
44
49
  : this.options.placeholder,
45
50
  });
46
51
  decorations.push(decoration);
47
52
  }
48
- return false;
53
+ return this.options.includeChildren;
49
54
  });
50
55
  return prosemirrorView.DecorationSet.create(doc, decorations);
51
56
  },
@@ -56,5 +61,5 @@ const Placeholder = core.Extension.create({
56
61
  });
57
62
 
58
63
  exports.Placeholder = Placeholder;
59
- exports.default = Placeholder;
64
+ exports["default"] = Placeholder;
60
65
  //# sourceMappingURL=tiptap-extension-placeholder.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tiptap-extension-placeholder.cjs.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension, isNodeEmpty } 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 && isNodeEmpty(node)\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","isNodeEmpty","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;Q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W,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
+ {"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 { Plugin } from 'prosemirror-state'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n pos: number,\n hasAnchor: boolean,\n }) => string) | string,\n showOnlyWhenEditable: boolean,\n showOnlyCurrent: boolean,\n includeChildren: boolean,\n}\n\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\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 null\n }\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)\n const isEmpty = !node.isLeaf && !node.childCount\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 pos,\n hasAnchor,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return this.options.includeChildren\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;;;AAmBa,MAAA,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;AAC9D,IAAA,IAAI,EAAE,aAAa;IAEnB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,gBAAgB,EAAE,iBAAiB;AACnC,YAAA,cAAc,EAAE,UAAU;AAC1B,YAAA,WAAW,EAAE,mBAAmB;AAChC,YAAA,oBAAoB,EAAE,IAAI;AAC1B,YAAA,eAAe,EAAE,IAAI;AACrB,YAAA,eAAe,EAAE,KAAK;SACvB,CAAA;KACF;IAED,qBAAqB,GAAA;QACnB,OAAO;AACL,YAAA,IAAIC,uBAAM,CAAC;AACT,gBAAA,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;AAClC,wBAAA,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAA;AAC3E,wBAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;wBAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;wBAEpC,IAAI,CAAC,MAAM,EAAE;AACX,4BAAA,OAAO,IAAI,CAAA;AACZ,yBAAA;wBAED,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG,KAAI;AAC5B,4BAAA,MAAM,SAAS,GAAG,MAAM,IAAI,GAAG,IAAI,MAAM,KAAK,G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decoration, DecorationSet } from 'prosemirror-view';
1
+ import { Extension } from '@tiptap/core';
3
2
  import { Plugin } from 'prosemirror-state';
3
+ import { Decoration, DecorationSet } from 'prosemirror-view';
4
4
 
5
5
  const Placeholder = Extension.create({
6
6
  name: 'placeholder',
7
- defaultOptions: {
8
- emptyEditorClass: 'is-editor-empty',
9
- emptyNodeClass: 'is-empty',
10
- placeholder: 'Write something …',
11
- showOnlyWhenEditable: true,
12
- showOnlyCurrent: true,
7
+ addOptions() {
8
+ return {
9
+ emptyEditorClass: 'is-editor-empty',
10
+ emptyNodeClass: 'is-empty',
11
+ placeholder: 'Write something …',
12
+ showOnlyWhenEditable: true,
13
+ showOnlyCurrent: true,
14
+ includeChildren: false,
15
+ };
13
16
  },
14
17
  addProseMirrorPlugins() {
15
18
  return [
@@ -20,11 +23,11 @@ const Placeholder = Extension.create({
20
23
  const { anchor } = selection;
21
24
  const decorations = [];
22
25
  if (!active) {
23
- return;
26
+ return null;
24
27
  }
25
28
  doc.descendants((node, pos) => {
26
29
  const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
27
- const isEmpty = !node.isLeaf && isNodeEmpty(node);
30
+ const isEmpty = !node.isLeaf && !node.childCount;
28
31
  if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
29
32
  const classes = [this.options.emptyNodeClass];
30
33
  if (this.editor.isEmpty) {
@@ -36,12 +39,14 @@ const Placeholder = Extension.create({
36
39
  ? this.options.placeholder({
37
40
  editor: this.editor,
38
41
  node,
42
+ pos,
43
+ hasAnchor,
39
44
  })
40
45
  : this.options.placeholder,
41
46
  });
42
47
  decorations.push(decoration);
43
48
  }
44
- return false;
49
+ return this.options.includeChildren;
45
50
  });
46
51
  return DecorationSet.create(doc, decorations);
47
52
  },
@@ -51,6 +56,5 @@ const Placeholder = Extension.create({
51
56
  },
52
57
  });
53
58
 
54
- export default Placeholder;
55
- export { Placeholder };
59
+ export { Placeholder, Placeholder as default };
56
60
  //# sourceMappingURL=tiptap-extension-placeholder.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tiptap-extension-placeholder.esm.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension, isNodeEmpty } 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 && isNodeEmpty(node)\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;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B,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
+ {"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 { Plugin } from 'prosemirror-state'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n pos: number,\n hasAnchor: boolean,\n }) => string) | string,\n showOnlyWhenEditable: boolean,\n showOnlyCurrent: boolean,\n includeChildren: boolean,\n}\n\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\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 null\n }\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)\n const isEmpty = !node.isLeaf && !node.childCount\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 pos,\n hasAnchor,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return this.options.includeChildren\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;;;AAmBa,MAAA,WAAW,GAAG,SAAS,CAAC,MAAM,CAAqB;AAC9D,IAAA,IAAI,EAAE,aAAa;IAEnB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,gBAAgB,EAAE,iBAAiB;AACnC,YAAA,cAAc,EAAE,UAAU;AAC1B,YAAA,WAAW,EAAE,mBAAmB;AAChC,YAAA,oBAAoB,EAAE,IAAI;AAC1B,YAAA,eAAe,EAAE,IAAI;AACrB,YAAA,eAAe,EAAE,KAAK;SACvB,CAAA;KACF;IAED,qBAAqB,GAAA;QACnB,OAAO;AACL,YAAA,IAAI,MAAM,CAAC;AACT,gBAAA,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;AAClC,wBAAA,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAA;AAC3E,wBAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;wBAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;wBAEpC,IAAI,CAAC,MAAM,EAAE;AACX,4BAAA,OAAO,IAAI,CAAA;AACZ,yBAAA;wBAED,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG,KAAI;AAC5B,4BAAA,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,20 @@
1
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';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('prosemirror-state'), require('prosemirror-view')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', 'prosemirror-state', 'prosemirror-view'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-placeholder"] = {}, global.core, global.prosemirrorState, global.prosemirrorView));
5
+ })(this, (function (exports, core, prosemirrorState, prosemirrorView) { 'use strict';
6
6
 
7
7
  const Placeholder = core.Extension.create({
8
8
  name: 'placeholder',
9
- defaultOptions: {
10
- emptyEditorClass: 'is-editor-empty',
11
- emptyNodeClass: 'is-empty',
12
- placeholder: 'Write something …',
13
- showOnlyWhenEditable: true,
14
- showOnlyCurrent: true,
9
+ addOptions() {
10
+ return {
11
+ emptyEditorClass: 'is-editor-empty',
12
+ emptyNodeClass: 'is-empty',
13
+ placeholder: 'Write something …',
14
+ showOnlyWhenEditable: true,
15
+ showOnlyCurrent: true,
16
+ includeChildren: false,
17
+ };
15
18
  },
16
19
  addProseMirrorPlugins() {
17
20
  return [
@@ -22,11 +25,11 @@
22
25
  const { anchor } = selection;
23
26
  const decorations = [];
24
27
  if (!active) {
25
- return;
28
+ return null;
26
29
  }
27
30
  doc.descendants((node, pos) => {
28
31
  const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
29
- const isEmpty = !node.isLeaf && core.isNodeEmpty(node);
32
+ const isEmpty = !node.isLeaf && !node.childCount;
30
33
  if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
31
34
  const classes = [this.options.emptyNodeClass];
32
35
  if (this.editor.isEmpty) {
@@ -38,12 +41,14 @@
38
41
  ? this.options.placeholder({
39
42
  editor: this.editor,
40
43
  node,
44
+ pos,
45
+ hasAnchor,
41
46
  })
42
47
  : this.options.placeholder,
43
48
  });
44
49
  decorations.push(decoration);
45
50
  }
46
- return false;
51
+ return this.options.includeChildren;
47
52
  });
48
53
  return prosemirrorView.DecorationSet.create(doc, decorations);
49
54
  },
@@ -54,9 +59,9 @@
54
59
  });
55
60
 
56
61
  exports.Placeholder = Placeholder;
57
- exports.default = Placeholder;
62
+ exports["default"] = Placeholder;
58
63
 
59
64
  Object.defineProperty(exports, '__esModule', { value: true });
60
65
 
61
- })));
66
+ }));
62
67
  //# sourceMappingURL=tiptap-extension-placeholder.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tiptap-extension-placeholder.umd.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension, isNodeEmpty } 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 && isNodeEmpty(node)\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","isNodeEmpty","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,IAAIC,gBAAW,CAAC,IAAI,CAAC,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;;;;;;;;;;;"}
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 { Plugin } from 'prosemirror-state'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n pos: number,\n hasAnchor: boolean,\n }) => string) | string,\n showOnlyWhenEditable: boolean,\n showOnlyCurrent: boolean,\n includeChildren: boolean,\n}\n\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\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 null\n }\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)\n const isEmpty = !node.isLeaf && !node.childCount\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 pos,\n hasAnchor,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return this.options.includeChildren\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;AAmBa,QAAA,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;EAC9D,IAAA,IAAI,EAAE,aAAa;MAEnB,UAAU,GAAA;UACR,OAAO;EACL,YAAA,gBAAgB,EAAE,iBAAiB;EACnC,YAAA,cAAc,EAAE,UAAU;EAC1B,YAAA,WAAW,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;EAC3D,oCAAA,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;sCACxB,kBAAkB,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;EAChE,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;8CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;8CACnB,IAAI;8CACJ,GAAG;8CACH,SAAS;2CACV,CAAC;EACF,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW;EAC7B,iCAAA,CAAC,CAAA;EAEF,gCAAA,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;EAC7B,6BAAA;EAED,4BAAA,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAA;EACrC,yBAAC,CAAC,CAAA;0BAEF,OAAOC,6BAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;uBAC9C;EACF,iBAAA;eACF,CAAC;WACH,CAAA;OACF;EACF,CAAA;;;;;;;;;;;"}
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.5",
4
+ "version": "2.0.0-beta.53",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -15,7 +15,6 @@
15
15
  "main": "dist/tiptap-extension-placeholder.cjs.js",
16
16
  "umd": "dist/tiptap-extension-placeholder.umd.js",
17
17
  "module": "dist/tiptap-extension-placeholder.esm.js",
18
- "unpkg": "dist/tiptap-extension-placeholder.bundle.umd.min.js",
19
18
  "types": "dist/packages/extension-placeholder/src/index.d.ts",
20
19
  "files": [
21
20
  "src",
@@ -25,9 +24,14 @@
25
24
  "@tiptap/core": "^2.0.0-beta.1"
26
25
  },
27
26
  "dependencies": {
28
- "prosemirror-model": "^1.14.0",
29
- "prosemirror-state": "^1.3.4",
30
- "prosemirror-view": "^1.18.2"
27
+ "prosemirror-model": "1.18.1",
28
+ "prosemirror-state": "1.4.1",
29
+ "prosemirror-view": "1.26.2"
31
30
  },
32
- "gitHead": "634c1ae4931a8a268c7251f702b2a7d5121f02d2"
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/ueberdosis/tiptap",
34
+ "directory": "packages/extension-placeholder"
35
+ },
36
+ "gitHead": "090c5a44566bcd936096574fa62bf301ab4a1285"
33
37
  }
@@ -1,7 +1,7 @@
1
- import { Editor, Extension, isNodeEmpty } from '@tiptap/core'
1
+ import { Editor, Extension } from '@tiptap/core'
2
2
  import { Node as ProsemirrorNode } from 'prosemirror-model'
3
- import { Decoration, DecorationSet } from 'prosemirror-view'
4
3
  import { Plugin } from 'prosemirror-state'
4
+ import { Decoration, DecorationSet } from 'prosemirror-view'
5
5
 
6
6
  export interface PlaceholderOptions {
7
7
  emptyEditorClass: string,
@@ -9,20 +9,26 @@ export interface PlaceholderOptions {
9
9
  placeholder: ((PlaceholderProps: {
10
10
  editor: Editor,
11
11
  node: ProsemirrorNode,
12
+ pos: number,
13
+ hasAnchor: boolean,
12
14
  }) => string) | string,
13
15
  showOnlyWhenEditable: boolean,
14
16
  showOnlyCurrent: boolean,
17
+ includeChildren: boolean,
15
18
  }
16
19
 
17
20
  export const Placeholder = Extension.create<PlaceholderOptions>({
18
21
  name: 'placeholder',
19
22
 
20
- defaultOptions: {
21
- emptyEditorClass: 'is-editor-empty',
22
- emptyNodeClass: 'is-empty',
23
- placeholder: 'Write something …',
24
- showOnlyWhenEditable: true,
25
- showOnlyCurrent: true,
23
+ addOptions() {
24
+ return {
25
+ emptyEditorClass: 'is-editor-empty',
26
+ emptyNodeClass: 'is-empty',
27
+ placeholder: 'Write something …',
28
+ showOnlyWhenEditable: true,
29
+ showOnlyCurrent: true,
30
+ includeChildren: false,
31
+ }
26
32
  },
27
33
 
28
34
  addProseMirrorPlugins() {
@@ -35,12 +41,12 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
35
41
  const decorations: Decoration[] = []
36
42
 
37
43
  if (!active) {
38
- return
44
+ return null
39
45
  }
40
46
 
41
47
  doc.descendants((node, pos) => {
42
48
  const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)
43
- const isEmpty = !node.isLeaf && isNodeEmpty(node)
49
+ const isEmpty = !node.isLeaf && !node.childCount
44
50
 
45
51
  if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
46
52
  const classes = [this.options.emptyNodeClass]
@@ -55,6 +61,8 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
55
61
  ? this.options.placeholder({
56
62
  editor: this.editor,
57
63
  node,
64
+ pos,
65
+ hasAnchor,
58
66
  })
59
67
  : this.options.placeholder,
60
68
  })
@@ -62,7 +70,7 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
62
70
  decorations.push(decoration)
63
71
  }
64
72
 
65
- return false
73
+ return this.options.includeChildren
66
74
  })
67
75
 
68
76
  return DecorationSet.create(doc, decorations)
package/CHANGELOG.md DELETED
@@ -1,40 +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.5](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-placeholder@2.0.0-beta.4...@tiptap/extension-placeholder@2.0.0-beta.5) (2021-04-15)
7
-
8
- **Note:** Version bump only for package @tiptap/extension-placeholder
9
-
10
-
11
-
12
-
13
-
14
- # [2.0.0-beta.4](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-placeholder@2.0.0-beta.3...@tiptap/extension-placeholder@2.0.0-beta.4) (2021-04-06)
15
-
16
- **Note:** Version bump only for package @tiptap/extension-placeholder
17
-
18
-
19
-
20
-
21
-
22
- # [2.0.0-beta.3](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-placeholder@2.0.0-beta.2...@tiptap/extension-placeholder@2.0.0-beta.3) (2021-03-31)
23
-
24
- **Note:** Version bump only for package @tiptap/extension-placeholder
25
-
26
-
27
-
28
-
29
-
30
- # [2.0.0-beta.2](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-placeholder@2.0.0-beta.1...@tiptap/extension-placeholder@2.0.0-beta.2) (2021-03-28)
31
-
32
- **Note:** Version bump only for package @tiptap/extension-placeholder
33
-
34
-
35
-
36
-
37
-
38
- # 2.0.0-beta.1 (2021-03-24)
39
-
40
- **Note:** Version bump only for package @tiptap/extension-placeholder