@tiptap/extension-placeholder 2.6.2 → 3.0.0-next.1

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.
Files changed (172) hide show
  1. package/dist/index.cjs +88 -68
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/{packages/extension-placeholder/src/placeholder.d.ts → index.d.cts} +7 -9
  4. package/dist/index.d.ts +59 -0
  5. package/dist/index.js +63 -65
  6. package/dist/index.js.map +1 -1
  7. package/package.json +8 -10
  8. package/src/placeholder.ts +0 -6
  9. package/dist/index.umd.js +0 -74
  10. package/dist/index.umd.js.map +0 -1
  11. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  12. package/dist/packages/core/src/Editor.d.ts +0 -163
  13. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  14. package/dist/packages/core/src/Extension.d.ts +0 -344
  15. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  16. package/dist/packages/core/src/InputRule.d.ts +0 -42
  17. package/dist/packages/core/src/Mark.d.ts +0 -452
  18. package/dist/packages/core/src/Node.d.ts +0 -612
  19. package/dist/packages/core/src/NodePos.d.ts +0 -44
  20. package/dist/packages/core/src/NodeView.d.ts +0 -31
  21. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  22. package/dist/packages/core/src/Tracker.d.ts +0 -11
  23. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  24. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  25. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  26. package/dist/packages/core/src/commands/command.d.ts +0 -18
  27. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  28. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  29. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  30. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  31. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  32. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  33. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  34. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  35. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  36. package/dist/packages/core/src/commands/first.d.ts +0 -14
  37. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  38. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  39. package/dist/packages/core/src/commands/index.d.ts +0 -55
  40. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  41. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  42. package/dist/packages/core/src/commands/join.d.ts +0 -41
  43. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  44. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  45. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  46. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  47. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  48. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  49. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  50. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  51. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  52. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  53. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  54. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  55. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  56. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  57. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  58. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  59. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  60. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  61. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  62. package/dist/packages/core/src/commands/setMeta.d.ts +0 -16
  63. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  64. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  65. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  66. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  67. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  68. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -16
  69. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  70. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  71. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  72. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  73. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  74. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  75. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  76. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  77. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  78. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  79. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  80. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  81. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  82. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  83. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  84. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  85. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  86. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  87. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  88. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  89. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  90. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  91. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  92. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  93. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  94. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  95. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  96. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  97. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  98. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  99. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  100. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  101. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  102. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  103. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  104. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  105. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  106. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  107. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  108. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  109. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  110. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  111. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  112. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  113. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  114. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  115. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  116. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  117. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  118. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  119. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  120. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  121. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  122. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  123. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  124. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  125. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  126. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  127. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  128. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  129. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  130. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -14
  131. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  132. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  133. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  134. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  135. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  136. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  137. package/dist/packages/core/src/index.d.ts +0 -24
  138. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  139. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  140. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  141. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  142. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  143. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  144. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  145. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  146. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -14
  147. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  148. package/dist/packages/core/src/style.d.ts +0 -1
  149. package/dist/packages/core/src/types.d.ts +0 -253
  150. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  151. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  152. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  153. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  154. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  155. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  156. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  157. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  158. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  159. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  160. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  161. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  162. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  163. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  164. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  165. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  166. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  167. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  168. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  169. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  170. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  171. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  172. package/dist/packages/extension-placeholder/src/index.d.ts +0 -3
package/dist/index.cjs CHANGED
@@ -1,72 +1,92 @@
1
- 'use strict';
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
19
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var core = require('@tiptap/core');
6
- var state = require('@tiptap/pm/state');
7
- var view = require('@tiptap/pm/view');
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Placeholder: () => Placeholder,
24
+ default: () => src_default
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
8
27
 
9
- /**
10
- * This extension allows you to add a placeholder to your editor.
11
- * A placeholder is a text that appears when the editor or a node is empty.
12
- * @see https://www.tiptap.dev/api/extensions/placeholder
13
- */
14
- const Placeholder = core.Extension.create({
15
- name: 'placeholder',
16
- addOptions() {
17
- return {
18
- emptyEditorClass: 'is-editor-empty',
19
- emptyNodeClass: 'is-empty',
20
- placeholder: 'Write something …',
21
- showOnlyWhenEditable: true,
22
- showOnlyCurrent: true,
23
- includeChildren: false,
24
- };
25
- },
26
- addProseMirrorPlugins() {
27
- return [
28
- new state.Plugin({
29
- key: new state.PluginKey('placeholder'),
30
- props: {
31
- decorations: ({ doc, selection }) => {
32
- const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
33
- const { anchor } = selection;
34
- const decorations = [];
35
- if (!active) {
36
- return null;
37
- }
38
- const isEmptyDoc = this.editor.isEmpty;
39
- doc.descendants((node, pos) => {
40
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
41
- const isEmpty = !node.isLeaf && core.isNodeEmpty(node);
42
- if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
43
- const classes = [this.options.emptyNodeClass];
44
- if (isEmptyDoc) {
45
- classes.push(this.options.emptyEditorClass);
46
- }
47
- const decoration = view.Decoration.node(pos, pos + node.nodeSize, {
48
- class: classes.join(' '),
49
- 'data-placeholder': typeof this.options.placeholder === 'function'
50
- ? this.options.placeholder({
51
- editor: this.editor,
52
- node,
53
- pos,
54
- hasAnchor,
55
- })
56
- : this.options.placeholder,
57
- });
58
- decorations.push(decoration);
59
- }
60
- return this.options.includeChildren;
61
- });
62
- return view.DecorationSet.create(doc, decorations);
63
- },
64
- },
65
- }),
66
- ];
67
- },
28
+ // src/placeholder.ts
29
+ var import_core = require("@tiptap/core");
30
+ var import_state = require("@tiptap/pm/state");
31
+ var import_view = require("@tiptap/pm/view");
32
+ var Placeholder = import_core.Extension.create({
33
+ name: "placeholder",
34
+ addOptions() {
35
+ return {
36
+ emptyEditorClass: "is-editor-empty",
37
+ emptyNodeClass: "is-empty",
38
+ placeholder: "Write something \u2026",
39
+ showOnlyWhenEditable: true,
40
+ showOnlyCurrent: true,
41
+ includeChildren: false
42
+ };
43
+ },
44
+ addProseMirrorPlugins() {
45
+ return [
46
+ new import_state.Plugin({
47
+ key: new import_state.PluginKey("placeholder"),
48
+ props: {
49
+ decorations: ({ doc, selection }) => {
50
+ const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
51
+ const { anchor } = selection;
52
+ const decorations = [];
53
+ if (!active) {
54
+ return null;
55
+ }
56
+ const isEmptyDoc = this.editor.isEmpty;
57
+ doc.descendants((node, pos) => {
58
+ const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
59
+ const isEmpty = !node.isLeaf && (0, import_core.isNodeEmpty)(node);
60
+ if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
61
+ const classes = [this.options.emptyNodeClass];
62
+ if (isEmptyDoc) {
63
+ classes.push(this.options.emptyEditorClass);
64
+ }
65
+ const decoration = import_view.Decoration.node(pos, pos + node.nodeSize, {
66
+ class: classes.join(" "),
67
+ "data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
68
+ editor: this.editor,
69
+ node,
70
+ pos,
71
+ hasAnchor
72
+ }) : this.options.placeholder
73
+ });
74
+ decorations.push(decoration);
75
+ }
76
+ return this.options.includeChildren;
77
+ });
78
+ return import_view.DecorationSet.create(doc, decorations);
79
+ }
80
+ }
81
+ })
82
+ ];
83
+ }
68
84
  });
69
85
 
70
- exports.Placeholder = Placeholder;
71
- exports.default = Placeholder;
72
- //# sourceMappingURL=index.cjs.map
86
+ // src/index.ts
87
+ var src_default = Placeholder;
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ Placeholder
91
+ });
92
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension, isNodeEmpty } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface PlaceholderOptions {\n /**\n * **The class name for the empty editor**\n * @default 'is-editor-empty'\n */\n emptyEditorClass: string\n\n /**\n * **The class name for empty nodes**\n * @default 'is-empty'\n */\n emptyNodeClass: string\n\n /**\n * **The placeholder content**\n *\n * You can use a function to return a dynamic placeholder or a string.\n * @default 'Write something …'\n */\n placeholder:\n | ((PlaceholderProps: {\n editor: Editor\n node: ProsemirrorNode\n pos: number\n hasAnchor: boolean\n }) => string)\n | string\n\n /**\n * See https://github.com/ueberdosis/tiptap/pull/5278 for more information.\n * @deprecated This option is no longer respected and this type will be removed in the next major version.\n */\n considerAnyAsEmpty?: boolean\n\n /**\n * **Checks if the placeholder should be only shown when the editor is editable.**\n *\n * If true, the placeholder will only be shown when the editor is editable.\n * If false, the placeholder will always be shown.\n * @default true\n */\n showOnlyWhenEditable: boolean\n\n /**\n * **Checks if the placeholder should be only shown when the current node is empty.**\n *\n * If true, the placeholder will only be shown when the current node is empty.\n * If false, the placeholder will be shown when any node is empty.\n * @default true\n */\n showOnlyCurrent: boolean\n\n /**\n * **Controls if the placeholder should be shown for all descendents.**\n *\n * If true, the placeholder will be shown for all descendents.\n * If false, the placeholder will only be shown for the current node.\n * @default false\n */\n includeChildren: boolean\n}\n\n/**\n * This extension allows you to add a placeholder to your editor.\n * A placeholder is a text that appears when the editor or a node is empty.\n * @see https://www.tiptap.dev/api/extensions/placeholder\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 key: new PluginKey('placeholder'),\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 const isEmptyDoc = this.editor.isEmpty\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 (isEmptyDoc) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder':\n 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","PluginKey","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AAC,OAAO,CAAC,eAAe,KAAK,OAAO,EAAE;gCAC3D,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;gCAE7C,IAAI,UAAU,EAAE;oCACd,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;iCAC5C;AAED,gCAAA,MAAM,UAAU,GAAGC,eAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;AAC3D,oCAAA,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;oCACxB,kBAAkB,EAChB,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;AAC5C,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;4CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;4CACnB,IAAI;4CACJ,GAAG;4CACH,SAAS;yCACV,CAAC;AACF,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW;AAC/B,iCAAA,CAAC,CAAA;AAEF,gCAAA,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;6BAC7B;AAED,4BAAA,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAA;AACrC,yBAAC,CAAC,CAAA;wBAEF,OAAOC,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;;"}
1
+ {"version":3,"sources":["../src/index.ts","../src/placeholder.ts"],"sourcesContent":["import { Placeholder } from './placeholder.js'\n\nexport * from './placeholder.js'\n\nexport default Placeholder\n","import { Editor, Extension, isNodeEmpty } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface PlaceholderOptions {\n /**\n * **The class name for the empty editor**\n * @default 'is-editor-empty'\n */\n emptyEditorClass: string\n\n /**\n * **The class name for empty nodes**\n * @default 'is-empty'\n */\n emptyNodeClass: string\n\n /**\n * **The placeholder content**\n *\n * You can use a function to return a dynamic placeholder or a string.\n * @default 'Write something …'\n */\n placeholder:\n | ((PlaceholderProps: {\n editor: Editor\n node: ProsemirrorNode\n pos: number\n hasAnchor: boolean\n }) => string)\n | string\n\n /**\n * **Checks if the placeholder should be only shown when the editor is editable.**\n *\n * If true, the placeholder will only be shown when the editor is editable.\n * If false, the placeholder will always be shown.\n * @default true\n */\n showOnlyWhenEditable: boolean\n\n /**\n * **Checks if the placeholder should be only shown when the current node is empty.**\n *\n * If true, the placeholder will only be shown when the current node is empty.\n * If false, the placeholder will be shown when any node is empty.\n * @default true\n */\n showOnlyCurrent: boolean\n\n /**\n * **Controls if the placeholder should be shown for all descendents.**\n *\n * If true, the placeholder will be shown for all descendents.\n * If false, the placeholder will only be shown for the current node.\n * @default false\n */\n includeChildren: boolean\n}\n\n/**\n * This extension allows you to add a placeholder to your editor.\n * A placeholder is a text that appears when the editor or a node is empty.\n * @see https://www.tiptap.dev/api/extensions/placeholder\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 key: new PluginKey('placeholder'),\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 const isEmptyDoc = this.editor.isEmpty\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 (isEmptyDoc) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder':\n 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA+C;AAE/C,mBAAkC;AAClC,kBAA0C;AA+DnC,IAAM,cAAc,sBAAU,OAA2B;AAAA,EAC9D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,kBAAkB;AAAA,MAClB,gBAAgB;AAAA,MAChB,aAAa;AAAA,MACb,sBAAsB;AAAA,MACtB,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO;AAAA,MACL,IAAI,oBAAO;AAAA,QACT,KAAK,IAAI,uBAAU,aAAa;AAAA,QAChC,OAAO;AAAA,UACL,aAAa,CAAC,EAAE,KAAK,UAAU,MAAM;AACnC,kBAAM,SAAS,KAAK,OAAO,cAAc,CAAC,KAAK,QAAQ;AACvD,kBAAM,EAAE,OAAO,IAAI;AACnB,kBAAM,cAA4B,CAAC;AAEnC,gBAAI,CAAC,QAAQ;AACX,qBAAO;AAAA,YACT;AAEA,kBAAM,aAAa,KAAK,OAAO;AAE/B,gBAAI,YAAY,CAAC,MAAM,QAAQ;AAC7B,oBAAM,YAAY,UAAU,OAAO,UAAU,MAAM,KAAK;AACxD,oBAAM,UAAU,CAAC,KAAK,cAAU,yBAAY,IAAI;AAEhD,mBAAK,aAAa,CAAC,KAAK,QAAQ,oBAAoB,SAAS;AAC3D,sBAAM,UAAU,CAAC,KAAK,QAAQ,cAAc;AAE5C,oBAAI,YAAY;AACd,0BAAQ,KAAK,KAAK,QAAQ,gBAAgB;AAAA,gBAC5C;AAEA,sBAAM,aAAa,uBAAW,KAAK,KAAK,MAAM,KAAK,UAAU;AAAA,kBAC3D,OAAO,QAAQ,KAAK,GAAG;AAAA,kBACvB,oBACE,OAAO,KAAK,QAAQ,gBAAgB,aAChC,KAAK,QAAQ,YAAY;AAAA,oBACzB,QAAQ,KAAK;AAAA,oBACb;AAAA,oBACA;AAAA,oBACA;AAAA,kBACF,CAAC,IACC,KAAK,QAAQ;AAAA,gBACrB,CAAC;AAED,4BAAY,KAAK,UAAU;AAAA,cAC7B;AAEA,qBAAO,KAAK,QAAQ;AAAA,YACtB,CAAC;AAED,mBAAO,0BAAc,OAAO,KAAK,WAAW;AAAA,UAC9C;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;ADhID,IAAO,cAAQ;","names":[]}
@@ -1,6 +1,7 @@
1
1
  import { Editor, Extension } from '@tiptap/core';
2
- import { Node as ProsemirrorNode } from '@tiptap/pm/model';
3
- export interface PlaceholderOptions {
2
+ import { Node } from '@tiptap/pm/model';
3
+
4
+ interface PlaceholderOptions {
4
5
  /**
5
6
  * **The class name for the empty editor**
6
7
  * @default 'is-editor-empty'
@@ -19,15 +20,10 @@ export interface PlaceholderOptions {
19
20
  */
20
21
  placeholder: ((PlaceholderProps: {
21
22
  editor: Editor;
22
- node: ProsemirrorNode;
23
+ node: Node;
23
24
  pos: number;
24
25
  hasAnchor: boolean;
25
26
  }) => string) | string;
26
- /**
27
- * See https://github.com/ueberdosis/tiptap/pull/5278 for more information.
28
- * @deprecated This option is no longer respected and this type will be removed in the next major version.
29
- */
30
- considerAnyAsEmpty?: boolean;
31
27
  /**
32
28
  * **Checks if the placeholder should be only shown when the editor is editable.**
33
29
  *
@@ -58,4 +54,6 @@ export interface PlaceholderOptions {
58
54
  * A placeholder is a text that appears when the editor or a node is empty.
59
55
  * @see https://www.tiptap.dev/api/extensions/placeholder
60
56
  */
61
- export declare const Placeholder: Extension<PlaceholderOptions, any>;
57
+ declare const Placeholder: Extension<PlaceholderOptions, any>;
58
+
59
+ export { Placeholder, type PlaceholderOptions, Placeholder as default };
@@ -0,0 +1,59 @@
1
+ import { Editor, Extension } from '@tiptap/core';
2
+ import { Node } from '@tiptap/pm/model';
3
+
4
+ interface PlaceholderOptions {
5
+ /**
6
+ * **The class name for the empty editor**
7
+ * @default 'is-editor-empty'
8
+ */
9
+ emptyEditorClass: string;
10
+ /**
11
+ * **The class name for empty nodes**
12
+ * @default 'is-empty'
13
+ */
14
+ emptyNodeClass: string;
15
+ /**
16
+ * **The placeholder content**
17
+ *
18
+ * You can use a function to return a dynamic placeholder or a string.
19
+ * @default 'Write something …'
20
+ */
21
+ placeholder: ((PlaceholderProps: {
22
+ editor: Editor;
23
+ node: Node;
24
+ pos: number;
25
+ hasAnchor: boolean;
26
+ }) => string) | string;
27
+ /**
28
+ * **Checks if the placeholder should be only shown when the editor is editable.**
29
+ *
30
+ * If true, the placeholder will only be shown when the editor is editable.
31
+ * If false, the placeholder will always be shown.
32
+ * @default true
33
+ */
34
+ showOnlyWhenEditable: boolean;
35
+ /**
36
+ * **Checks if the placeholder should be only shown when the current node is empty.**
37
+ *
38
+ * If true, the placeholder will only be shown when the current node is empty.
39
+ * If false, the placeholder will be shown when any node is empty.
40
+ * @default true
41
+ */
42
+ showOnlyCurrent: boolean;
43
+ /**
44
+ * **Controls if the placeholder should be shown for all descendents.**
45
+ *
46
+ * If true, the placeholder will be shown for all descendents.
47
+ * If false, the placeholder will only be shown for the current node.
48
+ * @default false
49
+ */
50
+ includeChildren: boolean;
51
+ }
52
+ /**
53
+ * This extension allows you to add a placeholder to your editor.
54
+ * A placeholder is a text that appears when the editor or a node is empty.
55
+ * @see https://www.tiptap.dev/api/extensions/placeholder
56
+ */
57
+ declare const Placeholder: Extension<PlaceholderOptions, any>;
58
+
59
+ export { Placeholder, type PlaceholderOptions, Placeholder as default };
package/dist/index.js CHANGED
@@ -1,67 +1,65 @@
1
- import { Extension, isNodeEmpty } from '@tiptap/core';
2
- import { Plugin, PluginKey } from '@tiptap/pm/state';
3
- import { Decoration, DecorationSet } from '@tiptap/pm/view';
4
-
5
- /**
6
- * This extension allows you to add a placeholder to your editor.
7
- * A placeholder is a text that appears when the editor or a node is empty.
8
- * @see https://www.tiptap.dev/api/extensions/placeholder
9
- */
10
- const Placeholder = Extension.create({
11
- name: 'placeholder',
12
- addOptions() {
13
- return {
14
- emptyEditorClass: 'is-editor-empty',
15
- emptyNodeClass: 'is-empty',
16
- placeholder: 'Write something …',
17
- showOnlyWhenEditable: true,
18
- showOnlyCurrent: true,
19
- includeChildren: false,
20
- };
21
- },
22
- addProseMirrorPlugins() {
23
- return [
24
- new Plugin({
25
- key: new PluginKey('placeholder'),
26
- props: {
27
- decorations: ({ doc, selection }) => {
28
- const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
29
- const { anchor } = selection;
30
- const decorations = [];
31
- if (!active) {
32
- return null;
33
- }
34
- const isEmptyDoc = this.editor.isEmpty;
35
- doc.descendants((node, pos) => {
36
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
37
- const isEmpty = !node.isLeaf && isNodeEmpty(node);
38
- if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
39
- const classes = [this.options.emptyNodeClass];
40
- if (isEmptyDoc) {
41
- classes.push(this.options.emptyEditorClass);
42
- }
43
- const decoration = Decoration.node(pos, pos + node.nodeSize, {
44
- class: classes.join(' '),
45
- 'data-placeholder': typeof this.options.placeholder === 'function'
46
- ? this.options.placeholder({
47
- editor: this.editor,
48
- node,
49
- pos,
50
- hasAnchor,
51
- })
52
- : this.options.placeholder,
53
- });
54
- decorations.push(decoration);
55
- }
56
- return this.options.includeChildren;
57
- });
58
- return DecorationSet.create(doc, decorations);
59
- },
60
- },
61
- }),
62
- ];
63
- },
1
+ // src/placeholder.ts
2
+ import { Extension, isNodeEmpty } from "@tiptap/core";
3
+ import { Plugin, PluginKey } 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
+ key: new PluginKey("placeholder"),
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 null;
28
+ }
29
+ const isEmptyDoc = this.editor.isEmpty;
30
+ doc.descendants((node, pos) => {
31
+ const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
32
+ const isEmpty = !node.isLeaf && isNodeEmpty(node);
33
+ if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
34
+ const classes = [this.options.emptyNodeClass];
35
+ if (isEmptyDoc) {
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
+ }
64
57
  });
65
58
 
66
- export { Placeholder, Placeholder as default };
67
- //# sourceMappingURL=index.js.map
59
+ // src/index.ts
60
+ var src_default = Placeholder;
61
+ export {
62
+ Placeholder,
63
+ src_default as default
64
+ };
65
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension, isNodeEmpty } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface PlaceholderOptions {\n /**\n * **The class name for the empty editor**\n * @default 'is-editor-empty'\n */\n emptyEditorClass: string\n\n /**\n * **The class name for empty nodes**\n * @default 'is-empty'\n */\n emptyNodeClass: string\n\n /**\n * **The placeholder content**\n *\n * You can use a function to return a dynamic placeholder or a string.\n * @default 'Write something …'\n */\n placeholder:\n | ((PlaceholderProps: {\n editor: Editor\n node: ProsemirrorNode\n pos: number\n hasAnchor: boolean\n }) => string)\n | string\n\n /**\n * See https://github.com/ueberdosis/tiptap/pull/5278 for more information.\n * @deprecated This option is no longer respected and this type will be removed in the next major version.\n */\n considerAnyAsEmpty?: boolean\n\n /**\n * **Checks if the placeholder should be only shown when the editor is editable.**\n *\n * If true, the placeholder will only be shown when the editor is editable.\n * If false, the placeholder will always be shown.\n * @default true\n */\n showOnlyWhenEditable: boolean\n\n /**\n * **Checks if the placeholder should be only shown when the current node is empty.**\n *\n * If true, the placeholder will only be shown when the current node is empty.\n * If false, the placeholder will be shown when any node is empty.\n * @default true\n */\n showOnlyCurrent: boolean\n\n /**\n * **Controls if the placeholder should be shown for all descendents.**\n *\n * If true, the placeholder will be shown for all descendents.\n * If false, the placeholder will only be shown for the current node.\n * @default false\n */\n includeChildren: boolean\n}\n\n/**\n * This extension allows you to add a placeholder to your editor.\n * A placeholder is a text that appears when the editor or a node is empty.\n * @see https://www.tiptap.dev/api/extensions/placeholder\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 key: new PluginKey('placeholder'),\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 const isEmptyDoc = this.editor.isEmpty\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 (isEmptyDoc) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder':\n 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":";;;;AAmEA;;;;AAIG;AACU,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,GAAG,EAAE,IAAI,SAAS,CAAC,aAAa,CAAC;AACjC,gBAAA,KAAK,EA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MAAM,EAAE,IAAI,CAAC,MAAM;4CACnB,IAAI;4CACJ,GAAG;4CACH,SAAS;yCACV,CAAC;AACF,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW;AAC/B,iCAAA,CAAC,CAAA;AAEF,gCAAA,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;6BAC7B;AAED,4BAAA,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAA;AACrC,yBAAC,CAAC,CAAA;wBAEF,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;"}
1
+ {"version":3,"sources":["../src/placeholder.ts","../src/index.ts"],"sourcesContent":["import { Editor, Extension, isNodeEmpty } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface PlaceholderOptions {\n /**\n * **The class name for the empty editor**\n * @default 'is-editor-empty'\n */\n emptyEditorClass: string\n\n /**\n * **The class name for empty nodes**\n * @default 'is-empty'\n */\n emptyNodeClass: string\n\n /**\n * **The placeholder content**\n *\n * You can use a function to return a dynamic placeholder or a string.\n * @default 'Write something …'\n */\n placeholder:\n | ((PlaceholderProps: {\n editor: Editor\n node: ProsemirrorNode\n pos: number\n hasAnchor: boolean\n }) => string)\n | string\n\n /**\n * **Checks if the placeholder should be only shown when the editor is editable.**\n *\n * If true, the placeholder will only be shown when the editor is editable.\n * If false, the placeholder will always be shown.\n * @default true\n */\n showOnlyWhenEditable: boolean\n\n /**\n * **Checks if the placeholder should be only shown when the current node is empty.**\n *\n * If true, the placeholder will only be shown when the current node is empty.\n * If false, the placeholder will be shown when any node is empty.\n * @default true\n */\n showOnlyCurrent: boolean\n\n /**\n * **Controls if the placeholder should be shown for all descendents.**\n *\n * If true, the placeholder will be shown for all descendents.\n * If false, the placeholder will only be shown for the current node.\n * @default false\n */\n includeChildren: boolean\n}\n\n/**\n * This extension allows you to add a placeholder to your editor.\n * A placeholder is a text that appears when the editor or a node is empty.\n * @see https://www.tiptap.dev/api/extensions/placeholder\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 key: new PluginKey('placeholder'),\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 const isEmptyDoc = this.editor.isEmpty\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 (isEmptyDoc) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder':\n 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","import { Placeholder } from './placeholder.js'\n\nexport * from './placeholder.js'\n\nexport default Placeholder\n"],"mappings":";AAAA,SAAiB,WAAW,mBAAmB;AAE/C,SAAS,QAAQ,iBAAiB;AAClC,SAAS,YAAY,qBAAqB;AA+DnC,IAAM,cAAc,UAAU,OAA2B;AAAA,EAC9D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA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AA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AChID,IAAO,cAAQ;","names":[]}
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.6.2",
4
+ "version": "3.0.0-next.1",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -15,26 +15,25 @@
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/packages/extension-placeholder/src/index.d.ts",
18
+ "types": "./dist/index.d.ts",
19
19
  "import": "./dist/index.js",
20
20
  "require": "./dist/index.cjs"
21
21
  }
22
22
  },
23
23
  "main": "dist/index.cjs",
24
24
  "module": "dist/index.js",
25
- "umd": "dist/index.umd.js",
26
- "types": "dist/packages/extension-placeholder/src/index.d.ts",
25
+ "types": "dist/index.d.ts",
27
26
  "files": [
28
27
  "src",
29
28
  "dist"
30
29
  ],
31
30
  "devDependencies": {
32
- "@tiptap/core": "^2.6.2",
33
- "@tiptap/pm": "^2.6.2"
31
+ "@tiptap/core": "^3.0.0-next.1",
32
+ "@tiptap/pm": "^3.0.0-next.1"
34
33
  },
35
34
  "peerDependencies": {
36
- "@tiptap/core": "^2.6.2",
37
- "@tiptap/pm": "^2.6.2"
35
+ "@tiptap/core": "^3.0.0-next.1",
36
+ "@tiptap/pm": "^3.0.0-next.1"
38
37
  },
39
38
  "repository": {
40
39
  "type": "git",
@@ -42,7 +41,6 @@
42
41
  "directory": "packages/extension-placeholder"
43
42
  },
44
43
  "scripts": {
45
- "clean": "rm -rf dist",
46
- "build": "npm run clean && rollup -c"
44
+ "build": "tsup"
47
45
  }
48
46
  }
@@ -31,12 +31,6 @@ export interface PlaceholderOptions {
31
31
  }) => string)
32
32
  | string
33
33
 
34
- /**
35
- * See https://github.com/ueberdosis/tiptap/pull/5278 for more information.
36
- * @deprecated This option is no longer respected and this type will be removed in the next major version.
37
- */
38
- considerAnyAsEmpty?: boolean
39
-
40
34
  /**
41
35
  * **Checks if the placeholder should be only shown when the editor is editable.**
42
36
  *
package/dist/index.umd.js DELETED
@@ -1,74 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('@tiptap/pm/state'), require('@tiptap/pm/view')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', '@tiptap/pm/state', '@tiptap/pm/view'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-placeholder"] = {}, global.core, global.state, global.view));
5
- })(this, (function (exports, core, state, view) { 'use strict';
6
-
7
- /**
8
- * This extension allows you to add a placeholder to your editor.
9
- * A placeholder is a text that appears when the editor or a node is empty.
10
- * @see https://www.tiptap.dev/api/extensions/placeholder
11
- */
12
- const Placeholder = core.Extension.create({
13
- name: 'placeholder',
14
- addOptions() {
15
- return {
16
- emptyEditorClass: 'is-editor-empty',
17
- emptyNodeClass: 'is-empty',
18
- placeholder: 'Write something …',
19
- showOnlyWhenEditable: true,
20
- showOnlyCurrent: true,
21
- includeChildren: false,
22
- };
23
- },
24
- addProseMirrorPlugins() {
25
- return [
26
- new state.Plugin({
27
- key: new state.PluginKey('placeholder'),
28
- props: {
29
- decorations: ({ doc, selection }) => {
30
- const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
31
- const { anchor } = selection;
32
- const decorations = [];
33
- if (!active) {
34
- return null;
35
- }
36
- const isEmptyDoc = this.editor.isEmpty;
37
- doc.descendants((node, pos) => {
38
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
39
- const isEmpty = !node.isLeaf && core.isNodeEmpty(node);
40
- if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
41
- const classes = [this.options.emptyNodeClass];
42
- if (isEmptyDoc) {
43
- classes.push(this.options.emptyEditorClass);
44
- }
45
- const decoration = view.Decoration.node(pos, pos + node.nodeSize, {
46
- class: classes.join(' '),
47
- 'data-placeholder': typeof this.options.placeholder === 'function'
48
- ? this.options.placeholder({
49
- editor: this.editor,
50
- node,
51
- pos,
52
- hasAnchor,
53
- })
54
- : this.options.placeholder,
55
- });
56
- decorations.push(decoration);
57
- }
58
- return this.options.includeChildren;
59
- });
60
- return view.DecorationSet.create(doc, decorations);
61
- },
62
- },
63
- }),
64
- ];
65
- },
66
- });
67
-
68
- exports.Placeholder = Placeholder;
69
- exports.default = Placeholder;
70
-
71
- Object.defineProperty(exports, '__esModule', { value: true });
72
-
73
- }));
74
- //# sourceMappingURL=index.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension, isNodeEmpty } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface PlaceholderOptions {\n /**\n * **The class name for the empty editor**\n * @default 'is-editor-empty'\n */\n emptyEditorClass: string\n\n /**\n * **The class name for empty nodes**\n * @default 'is-empty'\n */\n emptyNodeClass: string\n\n /**\n * **The placeholder content**\n *\n * You can use a function to return a dynamic placeholder or a string.\n * @default 'Write something …'\n */\n placeholder:\n | ((PlaceholderProps: {\n editor: Editor\n node: ProsemirrorNode\n pos: number\n hasAnchor: boolean\n }) => string)\n | string\n\n /**\n * See https://github.com/ueberdosis/tiptap/pull/5278 for more information.\n * @deprecated This option is no longer respected and this type will be removed in the next major version.\n */\n considerAnyAsEmpty?: boolean\n\n /**\n * **Checks if the placeholder should be only shown when the editor is editable.**\n *\n * If true, the placeholder will only be shown when the editor is editable.\n * If false, the placeholder will always be shown.\n * @default true\n */\n showOnlyWhenEditable: boolean\n\n /**\n * **Checks if the placeholder should be only shown when the current node is empty.**\n *\n * If true, the placeholder will only be shown when the current node is empty.\n * If false, the placeholder will be shown when any node is empty.\n * @default true\n */\n showOnlyCurrent: boolean\n\n /**\n * **Controls if the placeholder should be shown for all descendents.**\n *\n * If true, the placeholder will be shown for all descendents.\n * If false, the placeholder will only be shown for the current node.\n * @default false\n */\n includeChildren: boolean\n}\n\n/**\n * This extension allows you to add a placeholder to your editor.\n * A placeholder is a text that appears when the editor or a node is empty.\n * @see https://www.tiptap.dev/api/extensions/placeholder\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 key: new PluginKey('placeholder'),\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 const isEmptyDoc = this.editor.isEmpty\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 (isEmptyDoc) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder':\n 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","PluginKey","isNodeEmpty","Decoration","DecorationSet"],"mappings":";;;;;;EAmEA;;;;EAIG;AACU,QAAA,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;EAC9D,IAAA,IAAI,EAAE,aAAa;M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