@tiptap/extensions 3.23.6 → 3.24.0

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.
@@ -20,15 +20,27 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/placeholder/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ DEFAULT_DATA_ATTRIBUTE: () => DEFAULT_DATA_ATTRIBUTE,
23
24
  PLUGIN_KEY: () => PLUGIN_KEY,
24
25
  Placeholder: () => Placeholder,
25
26
  preparePlaceholderAttribute: () => preparePlaceholderAttribute
26
27
  });
27
28
  module.exports = __toCommonJS(index_exports);
28
29
 
30
+ // src/placeholder/constants.ts
31
+ var import_state = require("@tiptap/pm/state");
32
+ var DEFAULT_DATA_ATTRIBUTE = "placeholder";
33
+ var PLUGIN_KEY = new import_state.PluginKey("tiptap__placeholder");
34
+ var VIEWPORT_OVERSCAN_PX = 200;
35
+
29
36
  // src/placeholder/placeholder.ts
37
+ var import_core2 = require("@tiptap/core");
38
+
39
+ // src/placeholder/plugins/PlaceholderPlugin.ts
40
+ var import_state2 = require("@tiptap/pm/state");
41
+
42
+ // src/placeholder/utils/buildPlaceholderDecorations.ts
30
43
  var import_core = require("@tiptap/core");
31
- var import_state = require("@tiptap/pm/state");
32
44
  var import_view2 = require("@tiptap/pm/view");
33
45
 
34
46
  // src/placeholder/utils/createPlaceholderDecoration.ts
@@ -59,6 +71,81 @@ function createPlaceholderDecoration(options) {
59
71
  });
60
72
  }
61
73
 
74
+ // src/placeholder/utils/buildPlaceholderDecorations.ts
75
+ function buildPlaceholderDecorations({
76
+ editor,
77
+ options,
78
+ dataAttribute,
79
+ doc,
80
+ selection
81
+ }) {
82
+ var _a, _b;
83
+ const active = editor.isEditable || !options.showOnlyWhenEditable;
84
+ if (!active) {
85
+ return null;
86
+ }
87
+ const { anchor } = selection;
88
+ const decorations = [];
89
+ const isEmptyDoc = editor.isEmpty;
90
+ const classes = {
91
+ emptyEditor: options.emptyEditorClass,
92
+ emptyNode: options.emptyNodeClass
93
+ };
94
+ const useResolvedPath = options.showOnlyCurrent && !options.includeChildren;
95
+ if (useResolvedPath) {
96
+ const resolved = doc.resolve(anchor);
97
+ const node = resolved.depth > 0 ? resolved.node(1) : resolved.nodeAfter;
98
+ const nodeStart = resolved.depth > 0 ? resolved.before(1) : anchor;
99
+ if (node && node.type.isTextblock && (0, import_core.isNodeEmpty)(node)) {
100
+ const hasAnchor = anchor >= nodeStart && anchor <= nodeStart + node.nodeSize;
101
+ decorations.push(
102
+ createPlaceholderDecoration({
103
+ editor,
104
+ isEmptyDoc,
105
+ dataAttribute,
106
+ hasAnchor,
107
+ placeholder: options.placeholder,
108
+ classes,
109
+ node,
110
+ pos: nodeStart
111
+ })
112
+ );
113
+ }
114
+ } else {
115
+ const pluginState = PLUGIN_KEY.getState(editor.state);
116
+ const from = (_a = pluginState == null ? void 0 : pluginState.topPos) != null ? _a : 0;
117
+ const to = (_b = pluginState == null ? void 0 : pluginState.bottomPos) != null ? _b : doc.content.size;
118
+ doc.nodesBetween(from, to, (node, pos) => {
119
+ const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
120
+ const isEmpty = !node.isLeaf && (0, import_core.isNodeEmpty)(node);
121
+ if (!node.type.isTextblock) {
122
+ return options.includeChildren;
123
+ }
124
+ if ((hasAnchor || !options.showOnlyCurrent) && isEmpty) {
125
+ decorations.push(
126
+ createPlaceholderDecoration({
127
+ editor,
128
+ isEmptyDoc,
129
+ dataAttribute,
130
+ hasAnchor,
131
+ placeholder: options.placeholder,
132
+ classes,
133
+ node,
134
+ pos
135
+ })
136
+ );
137
+ }
138
+ return options.includeChildren;
139
+ });
140
+ }
141
+ return import_view2.DecorationSet.create(doc, decorations);
142
+ }
143
+
144
+ // src/placeholder/utils/preparePlaceholderAttribute.ts
145
+ function preparePlaceholderAttribute(attr) {
146
+ return attr.replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-]/g, "").replace(/^[0-9-]+/, "").replace(/^-+/, "").toLowerCase();
147
+ }
148
+
62
149
  // src/placeholder/utils/findScrollParent.ts
63
150
  function isScrollable(el) {
64
151
  const style = getComputedStyle(el);
@@ -99,8 +186,8 @@ function getViewportBoundaryPositions({
99
186
  }) {
100
187
  const editorRect = view.dom.getBoundingClientRect();
101
188
  const containerRect = scrollContainer ? getContainerRect(scrollContainer) : { top: 0, bottom: window.innerHeight };
102
- const visibleTop = Math.max(editorRect.top, containerRect.top);
103
- const visibleBottom = Math.min(editorRect.bottom, containerRect.bottom);
189
+ const visibleTop = Math.max(editorRect.top, containerRect.top) - VIEWPORT_OVERSCAN_PX;
190
+ const visibleBottom = Math.min(editorRect.bottom, containerRect.bottom) + VIEWPORT_OVERSCAN_PX;
104
191
  if (visibleTop >= visibleBottom) {
105
192
  return { top: 0, bottom: doc.content.size };
106
193
  }
@@ -114,34 +201,98 @@ function getViewportBoundaryPositions({
114
201
  };
115
202
  }
116
203
 
117
- // src/placeholder/utils/throttle.ts
118
- function throttle(fn, delay) {
119
- let timer = null;
120
- const call = ((...args) => {
121
- if (timer) {
204
+ // src/placeholder/utils/viewportTracking.ts
205
+ var viewportPluginState = {
206
+ /**
207
+ * Initialises the viewport state with no known positions.
208
+ * @returns The initial viewport state.
209
+ */
210
+ init() {
211
+ return { topPos: null, bottomPos: null };
212
+ },
213
+ /**
214
+ * Updates the viewport state from incoming transactions.
215
+ * @param tr - The transaction being applied.
216
+ * @param prev - The previous viewport state.
217
+ * @returns The next viewport state.
218
+ */
219
+ apply(tr, prev) {
220
+ const meta = tr.getMeta(PLUGIN_KEY);
221
+ if (meta == null ? void 0 : meta.positions) {
222
+ return { topPos: meta.positions.top, bottomPos: meta.positions.bottom };
223
+ }
224
+ if (!tr.docChanged) {
225
+ return prev;
226
+ }
227
+ return {
228
+ topPos: prev.topPos !== null ? tr.mapping.map(prev.topPos) : null,
229
+ bottomPos: prev.bottomPos !== null ? tr.mapping.map(prev.bottomPos) : null
230
+ };
231
+ }
232
+ };
233
+ function createViewportPluginView(view) {
234
+ const scrollContainer = findScrollParent(view.dom);
235
+ const computeAndDispatch = () => {
236
+ const positions = getViewportBoundaryPositions({
237
+ view,
238
+ doc: view.state.doc,
239
+ scrollContainer
240
+ });
241
+ const prev = PLUGIN_KEY.getState(view.state);
242
+ if ((prev == null ? void 0 : prev.topPos) === positions.top && (prev == null ? void 0 : prev.bottomPos) === positions.bottom) {
122
243
  return;
123
244
  }
124
- fn(...args);
125
- timer = setTimeout(() => {
126
- timer = null;
127
- }, delay);
128
- });
129
- const cancel = () => {
130
- if (timer) {
131
- clearTimeout(timer);
132
- timer = null;
245
+ const tr = view.state.tr.setMeta(PLUGIN_KEY, { positions });
246
+ view.dispatch(tr);
247
+ };
248
+ let frame = null;
249
+ let lastCompute = 0;
250
+ const MIN_SCROLL_INTERVAL = 150;
251
+ const scheduleFrame = () => {
252
+ if (frame !== null) return;
253
+ frame = requestAnimationFrame(() => {
254
+ frame = null;
255
+ const now = performance.now();
256
+ if (now - lastCompute >= MIN_SCROLL_INTERVAL) {
257
+ lastCompute = now;
258
+ computeAndDispatch();
259
+ } else {
260
+ scheduleFrame();
261
+ }
262
+ });
263
+ };
264
+ scrollContainer.addEventListener("scroll", scheduleFrame, { passive: true });
265
+ computeAndDispatch();
266
+ return {
267
+ update(_view, prevState) {
268
+ if (view.state.doc.content.size !== prevState.doc.content.size) {
269
+ scheduleFrame();
270
+ }
271
+ },
272
+ destroy: () => {
273
+ if (frame !== null) {
274
+ cancelAnimationFrame(frame);
275
+ }
276
+ scrollContainer.removeEventListener("scroll", scheduleFrame);
133
277
  }
134
278
  };
135
- return { call, cancel };
136
279
  }
137
280
 
138
- // src/placeholder/placeholder.ts
139
- var DEFAULT_DATA_ATTRIBUTE = "placeholder";
140
- function preparePlaceholderAttribute(attr) {
141
- return attr.replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-]/g, "").replace(/^[0-9-]+/, "").replace(/^-+/, "").toLowerCase();
281
+ // src/placeholder/plugins/PlaceholderPlugin.ts
282
+ function createPlaceholderPlugin({ editor, options }) {
283
+ const dataAttribute = options.dataAttribute ? `data-${preparePlaceholderAttribute(options.dataAttribute)}` : `data-${DEFAULT_DATA_ATTRIBUTE}`;
284
+ return new import_state2.Plugin({
285
+ key: PLUGIN_KEY,
286
+ state: viewportPluginState,
287
+ view: createViewportPluginView,
288
+ props: {
289
+ decorations: ({ doc, selection }) => buildPlaceholderDecorations({ editor, options, dataAttribute, doc, selection })
290
+ }
291
+ });
142
292
  }
143
- var PLUGIN_KEY = new import_state.PluginKey("tiptap__placeholder");
144
- var Placeholder = import_core.Extension.create({
293
+
294
+ // src/placeholder/placeholder.ts
295
+ var Placeholder = import_core2.Extension.create({
145
296
  name: "placeholder",
146
297
  addOptions() {
147
298
  return {
@@ -155,136 +306,12 @@ var Placeholder = import_core.Extension.create({
155
306
  };
156
307
  },
157
308
  addProseMirrorPlugins() {
158
- const dataAttribute = this.options.dataAttribute ? `data-${preparePlaceholderAttribute(this.options.dataAttribute)}` : `data-${DEFAULT_DATA_ATTRIBUTE}`;
159
- return [
160
- new import_state.Plugin({
161
- state: {
162
- init() {
163
- return {
164
- // null means "no viewport info yet" — decoration callback falls
165
- // back to full document scan until the scroll handler fires.
166
- topPos: null,
167
- bottomPos: null
168
- };
169
- },
170
- apply(tr, prev) {
171
- const meta = tr.getMeta(PLUGIN_KEY);
172
- if (meta == null ? void 0 : meta.positions) {
173
- return {
174
- topPos: meta.positions.top,
175
- bottomPos: meta.positions.bottom
176
- };
177
- }
178
- if (!tr.docChanged) {
179
- return prev;
180
- }
181
- return {
182
- topPos: prev.topPos !== null ? tr.mapping.map(prev.topPos) : null,
183
- bottomPos: prev.bottomPos !== null ? tr.mapping.map(prev.bottomPos) : null
184
- };
185
- }
186
- },
187
- key: PLUGIN_KEY,
188
- view(view) {
189
- const scrollContainer = findScrollParent(view.dom);
190
- const computeAndDispatch = () => {
191
- const positions = getViewportBoundaryPositions({
192
- view,
193
- doc: view.state.doc,
194
- scrollContainer
195
- });
196
- const prev = PLUGIN_KEY.getState(view.state);
197
- if (prev.topPos === positions.top && prev.bottomPos === positions.bottom) {
198
- return;
199
- }
200
- const tr = view.state.tr.setMeta(PLUGIN_KEY, { positions }).setMeta("tiptap__viewportUpdate", true);
201
- view.dispatch(tr);
202
- };
203
- const { call: throttledUpdate, cancel: cancelThrottle } = throttle(computeAndDispatch, 250);
204
- const scrollParent = scrollContainer;
205
- scrollParent.addEventListener("scroll", throttledUpdate, { passive: true });
206
- computeAndDispatch();
207
- return {
208
- update(_, prevState) {
209
- if (view.state.doc.content.size !== prevState.doc.content.size) {
210
- computeAndDispatch();
211
- }
212
- },
213
- destroy: () => {
214
- cancelThrottle();
215
- scrollParent.removeEventListener("scroll", throttledUpdate);
216
- }
217
- };
218
- },
219
- props: {
220
- decorations: ({ doc, selection }) => {
221
- var _a, _b;
222
- const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
223
- if (!active) {
224
- return null;
225
- }
226
- const { anchor } = selection;
227
- const decorations = [];
228
- const isEmptyDoc = this.editor.isEmpty;
229
- const useResolvedPath = this.options.showOnlyCurrent && !this.options.includeChildren;
230
- if (useResolvedPath) {
231
- const resolved = doc.resolve(anchor);
232
- if (resolved.depth > 0) {
233
- const node = resolved.node(1);
234
- const nodeStart = resolved.before(1);
235
- if (node.type.isTextblock && (0, import_core.isNodeEmpty)(node)) {
236
- const hasAnchor = anchor >= nodeStart && anchor <= nodeStart + node.nodeSize;
237
- const decoration = createPlaceholderDecoration({
238
- node,
239
- dataAttribute,
240
- hasAnchor,
241
- placeholder: this.options.placeholder,
242
- classes: {
243
- emptyEditor: this.options.emptyEditorClass,
244
- emptyNode: this.options.emptyNodeClass
245
- },
246
- editor: this.editor,
247
- isEmptyDoc,
248
- pos: resolved.before(1)
249
- });
250
- decorations.push(decoration);
251
- }
252
- }
253
- } else {
254
- const pluginState = PLUGIN_KEY.getState(this.editor.state);
255
- const from = (_a = pluginState.topPos) != null ? _a : 0;
256
- const to = (_b = pluginState.bottomPos) != null ? _b : doc.content.size;
257
- doc.nodesBetween(from, to, (node, pos) => {
258
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
259
- const isEmpty = !node.isLeaf && (0, import_core.isNodeEmpty)(node);
260
- if (!node.type.isTextblock) {
261
- return this.options.includeChildren;
262
- }
263
- if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
264
- const decoration = createPlaceholderDecoration({
265
- classes: { emptyEditor: this.options.emptyEditorClass, emptyNode: this.options.emptyNodeClass },
266
- editor: this.editor,
267
- isEmptyDoc,
268
- dataAttribute,
269
- hasAnchor,
270
- placeholder: this.options.placeholder,
271
- node,
272
- pos
273
- });
274
- decorations.push(decoration);
275
- }
276
- return this.options.includeChildren;
277
- });
278
- }
279
- return import_view2.DecorationSet.create(doc, decorations);
280
- }
281
- }
282
- })
283
- ];
309
+ return [createPlaceholderPlugin({ editor: this.editor, options: this.options })];
284
310
  }
285
311
  });
286
312
  // Annotate the CommonJS export names for ESM import in node:
287
313
  0 && (module.exports = {
314
+ DEFAULT_DATA_ATTRIBUTE,
288
315
  PLUGIN_KEY,
289
316
  Placeholder,
290
317
  preparePlaceholderAttribute
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/placeholder/index.ts","../../src/placeholder/placeholder.ts","../../src/placeholder/utils/createPlaceholderDecoration.ts","../../src/placeholder/utils/findScrollParent.ts","../../src/placeholder/utils/getViewportBoundaryPositions.ts","../../src/placeholder/utils/throttle.ts"],"sourcesContent":["export * from './placeholder.js'\nexport * from './types.js'\n","import { Extension, isNodeEmpty } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { Decoration } from '@tiptap/pm/view'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from './types.js'\nimport { createPlaceholderDecoration } from './utils/createPlaceholderDecoration.js'\nimport { findScrollParent } from './utils/findScrollParent.js'\nimport { getViewportBoundaryPositions } from './utils/getViewportBoundaryPositions.js'\nimport { throttle } from './utils/throttle.js'\n\n/**\n * The default data attribute label\n */\nconst DEFAULT_DATA_ATTRIBUTE = 'placeholder'\n\n/**\n * Prepares the placeholder attribute by ensuring it is properly formatted.\n * @param attr - The placeholder attribute string.\n * @returns The prepared placeholder attribute string.\n */\nexport function preparePlaceholderAttribute(attr: string): string {\n return (\n attr\n // replace whitespace with dashes\n .replace(/\\s+/g, '-')\n // replace non-alphanumeric characters\n // or special chars like $, %, &, etc.\n // but not dashes\n .replace(/[^a-zA-Z0-9-]/g, '')\n // and replace any numeric character at the start\n .replace(/^[0-9-]+/, '')\n // and finally replace any stray, leading dashes\n .replace(/^-+/, '')\n .toLowerCase()\n )\n}\n\nexport const PLUGIN_KEY = new PluginKey('tiptap__placeholder')\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 dataAttribute: DEFAULT_DATA_ATTRIBUTE,\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\n },\n\n addProseMirrorPlugins() {\n const dataAttribute = this.options.dataAttribute\n ? `data-${preparePlaceholderAttribute(this.options.dataAttribute)}`\n : `data-${DEFAULT_DATA_ATTRIBUTE}`\n\n return [\n new Plugin({\n state: {\n init() {\n return {\n // null means \"no viewport info yet\" — decoration callback falls\n // back to full document scan until the scroll handler fires.\n topPos: null as number | null,\n bottomPos: null as number | null,\n }\n },\n apply(tr, prev) {\n const meta = tr.getMeta(PLUGIN_KEY) as { positions?: { top: number; bottom: number } } | undefined\n\n if (meta?.positions) {\n return {\n topPos: meta.positions.top,\n bottomPos: meta.positions.bottom,\n }\n }\n\n if (!tr.docChanged) {\n return prev\n }\n\n // Preserve last known viewport positions across transactions.\n // Without this, every keystroke resets back to a full document\n // scan, defeating the viewport optimisation.\n // Only map when we have actual positions — null means \"no viewport\n // info yet\" and should stay null to fall back to full doc scan.\n return {\n topPos: prev.topPos !== null ? tr.mapping.map(prev.topPos) : null,\n bottomPos: prev.bottomPos !== null ? tr.mapping.map(prev.bottomPos) : null,\n }\n },\n },\n key: PLUGIN_KEY,\n view(view) {\n const scrollContainer = findScrollParent(view.dom)\n\n const computeAndDispatch = () => {\n const positions = getViewportBoundaryPositions({\n view,\n doc: view.state.doc,\n scrollContainer,\n })\n\n const prev = PLUGIN_KEY.getState(view.state)\n if (prev.topPos === positions.top && prev.bottomPos === positions.bottom) {\n return\n }\n\n const tr = view.state.tr\n .setMeta(PLUGIN_KEY, { positions })\n // Flag this transaction so the update() method can detect\n // it and avoid re-entrant computation.\n .setMeta('tiptap__viewportUpdate', true)\n view.dispatch(tr)\n }\n\n const { call: throttledUpdate, cancel: cancelThrottle } = throttle(computeAndDispatch, 250)\n const scrollParent = scrollContainer\n\n scrollParent.addEventListener('scroll', throttledUpdate, { passive: true })\n\n // Fire once to populate initial viewport (bypass throttle)\n computeAndDispatch()\n\n return {\n update(_, prevState) {\n // Skip re-entry: the dispatch inside computeAndDispatch would\n // trigger this update again, but the doc didn't change so the\n // size guard catches that. The meta flag is an extra safeguard.\n if (view.state.doc.content.size !== prevState.doc.content.size) {\n computeAndDispatch()\n }\n },\n destroy: () => {\n cancelThrottle()\n scrollParent.removeEventListener('scroll', throttledUpdate)\n },\n }\n },\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n\n if (!active) {\n return null\n }\n\n const { anchor } = selection\n const decorations: Decoration[] = []\n const isEmptyDoc = this.editor.isEmpty\n\n const useResolvedPath = this.options.showOnlyCurrent && !this.options.includeChildren\n\n if (useResolvedPath) {\n const resolved = doc.resolve(anchor)\n\n if (resolved.depth > 0) {\n const node = resolved.node(1)\n const nodeStart = resolved.before(1)\n\n if (node.type.isTextblock && isNodeEmpty(node)) {\n const hasAnchor = anchor >= nodeStart && anchor <= nodeStart + node.nodeSize\n const decoration = createPlaceholderDecoration({\n node,\n dataAttribute,\n hasAnchor,\n placeholder: this.options.placeholder,\n classes: {\n emptyEditor: this.options.emptyEditorClass,\n emptyNode: this.options.emptyNodeClass,\n },\n editor: this.editor,\n isEmptyDoc,\n pos: resolved.before(1),\n })\n\n decorations.push(decoration)\n }\n }\n } else {\n const pluginState = PLUGIN_KEY.getState(this.editor.state)\n const from = pluginState.topPos ?? 0\n const to = pluginState.bottomPos ?? doc.content.size\n\n doc.nodesBetween(from, to, (node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize\n const isEmpty = !node.isLeaf && isNodeEmpty(node)\n\n if (!node.type.isTextblock) {\n return this.options.includeChildren\n }\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const decoration = createPlaceholderDecoration({\n classes: { emptyEditor: this.options.emptyEditorClass, emptyNode: this.options.emptyNodeClass },\n editor: this.editor,\n isEmptyDoc,\n dataAttribute,\n hasAnchor,\n placeholder: this.options.placeholder,\n node,\n pos,\n })\n decorations.push(decoration)\n }\n\n return this.options.includeChildren\n })\n }\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n","import type { Editor } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport { Decoration } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\n\n/**\n * Creates a ProseMirror node decoration that applies a placeholder\n * CSS class and data attribute to an empty node.\n * @param options.editor - The editor instance\n * @param options.pos - The position of the node in the document\n * @param options.node - The ProseMirror node\n * @param options.isEmptyDoc - Whether the entire document is empty\n * @param options.hasAnchor - Whether the selection anchor is within the node\n * @param options.dataAttribute - The data attribute name (e.g. `data-placeholder`)\n * @param options.classes - CSS classes for empty nodes and the empty editor\n * @param options.placeholder - The placeholder text or a function that returns it\n * @returns A ProseMirror node decoration with placeholder classes and data attribute\n */\nexport function createPlaceholderDecoration(options: {\n editor: Editor\n pos: number\n node: Node\n isEmptyDoc: boolean\n hasAnchor: boolean\n dataAttribute: string\n classes: {\n emptyEditor: PlaceholderOptions['emptyEditorClass']\n emptyNode: PlaceholderOptions['emptyNodeClass']\n }\n placeholder: PlaceholderOptions['placeholder']\n}) {\n const {\n editor,\n placeholder,\n dataAttribute,\n pos,\n node,\n isEmptyDoc,\n hasAnchor,\n classes: { emptyNode, emptyEditor },\n } = options\n const classes = [emptyNode]\n\n if (isEmptyDoc) {\n classes.push(emptyEditor)\n }\n\n return Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n [dataAttribute]:\n typeof placeholder === 'function'\n ? placeholder({\n editor,\n node,\n pos,\n hasAnchor,\n })\n : placeholder,\n })\n}\n","/**\n * Checks if an element is scrollable by testing its overflow properties.\n * Elements with `overflow: hidden` or `overflow: clip` are intentionally\n * excluded — they clip content but don't emit scroll events.\n */\nfunction isScrollable(el: HTMLElement): boolean {\n const style = getComputedStyle(el)\n const overflow = `${style.overflow} ${style.overflowY} ${style.overflowX}`\n\n return /auto|scroll|overlay/.test(overflow)\n}\n\nexport function findScrollParent(element: HTMLElement): HTMLElement | Window {\n let el: HTMLElement | null = element\n\n while (el) {\n if (isScrollable(el)) {\n return el\n }\n\n // Check if we hit a Shadow DOM boundary. If so, jump to the shadow host\n // and continue traversing the light DOM.\n const parent = el.parentElement\n if (!parent) {\n const root = el.getRootNode()\n if (root instanceof ShadowRoot) {\n el = root.host as HTMLElement\n continue\n }\n\n return window\n }\n\n el = parent\n }\n\n return window\n}\n","import type { Node } from '@tiptap/pm/model'\nimport type { EditorView } from '@tiptap/pm/view'\n\nfunction getContainerRect(container: HTMLElement | Window): { top: number; bottom: number } {\n if (container === window) {\n return { top: 0, bottom: window.innerHeight }\n }\n\n return (container as HTMLElement).getBoundingClientRect()\n}\n\nexport function getViewportBoundaryPositions({\n doc,\n view,\n scrollContainer,\n}: {\n doc: Node\n view: EditorView\n scrollContainer?: HTMLElement | Window\n}) {\n const editorRect = view.dom.getBoundingClientRect()\n const containerRect = scrollContainer ? getContainerRect(scrollContainer) : { top: 0, bottom: window.innerHeight }\n\n const visibleTop = Math.max(editorRect.top, containerRect.top)\n const visibleBottom = Math.min(editorRect.bottom, containerRect.bottom)\n\n if (visibleTop >= visibleBottom) {\n // Editor is not visible — fall back to full document range\n return { top: 0, bottom: doc.content.size }\n }\n\n // Pick the x-coordinate based on text direction. In LTR the content\n // starts at the left edge; in RTL it starts at the right edge.\n // Clamp to ensure the coordinate stays inside the editor bounds.\n const isRTL = getComputedStyle(view.dom).direction === 'rtl'\n const x = isRTL ? Math.max(editorRect.right - 2, editorRect.left + 2) : editorRect.left + 2\n\n const topPos = view.posAtCoords({ left: x, top: visibleTop + 2 })\n const bottomPos = view.posAtCoords({ left: x, top: visibleBottom - 2 })\n\n return {\n top: topPos ? topPos.pos : 0,\n bottom: bottomPos ? bottomPos.pos : doc.content.size,\n }\n}\n","export function throttle<T extends (...args: any[]) => void>(fn: T, delay: number): { call: T; cancel: () => void } {\n let timer: ReturnType<typeof setTimeout> | null = null\n\n const call = ((...args: any[]) => {\n if (timer) {\n return\n }\n\n // Leading-edge: fire immediately, then prevent subsequent calls\n // until the timer fires and resets.\n fn(...args)\n timer = setTimeout(() => {\n timer = null\n }, delay)\n }) as T\n\n const cancel = () => {\n if (timer) {\n clearTimeout(timer)\n timer = null\n }\n }\n\n return { call, cancel }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAuC;AACvC,mBAAkC;AAElC,IAAAA,eAA8B;;;ACD9B,kBAA2B;AAiBpB,SAAS,4BAA4B,SAYzC;AACD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,EAAE,WAAW,YAAY;AAAA,EACpC,IAAI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B,SAAS;AAAA,sBACP,aAAa,KAAK,QAAQ;AAAA,sBAC1B,WAAW,KAAK,QAAQ;AAAA,oBAC1B;AAAA,oBACA,QAAQ,KAAK;AAAA,oBACb;AAAA,oBACA,KAAK,SAAS,OAAO,CAAC;AAAA,kBACxB,CAAC;AAED,8BAAY,KAAK,UAAU;AAAA,gBAC7B;AAAA,cACF;AAAA,YACF,OAAO;AACL,oBAAM,cAAc,WAAW,SAAS,KAAK,OAAO,KAAK;AACzD,oBAAM,QAAO,iBAAY,WAAZ,YAAsB;AACnC,oBAAM,MAAK,iBAAY,cAAZ,YAAyB,IAAI,QAAQ;AAEhD,kBAAI,aAAa,MAAM,IAAI,CAAC,MAAM,QAAQ;AACxC,sBAAM,YAAY,UAAU,OAAO,UAAU,MAAM,KAAK;AACxD,sBAAM,UAAU,CAAC,KAAK,cAAU,yBAAY,IAAI;AAEhD,oBAAI,CAAC,KAAK,KAAK,aAAa;AAC1B,yBAAO,KAAK,QAAQ;AAAA,gBACtB;AAEA,qBAAK,aAAa,CAAC,KAAK,QAAQ,oBAAoB,SAAS;AAC3D,wBAAM,aAAa,4BAA4B;AAAA,oBAC7C,SAAS,EAAE,aAAa,KAAK,QAAQ,kBAAkB,WAAW,KAAK,QAAQ,eAAe;AAAA,oBAC9F,QAAQ,KAAK;AAAA,oBACb;AAAA,oBACA;AAAA,oBACA;AAAA,oBACA,aAAa,KAAK,QAAQ;AAAA,oBAC1B;AAAA,oBACA;AAAA,kBACF,CAAC;AACD,8BAAY,KAAK,UAAU;AAAA,gBAC7B;AAEA,uBAAO,KAAK,QAAQ;AAAA,cACtB,CAAC;AAAA,YACH;AAEA,mBAAO,2BAAc,OAAO,KAAK,WAAW;AAAA,UAC9C;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":["import_view"]}
1
+ {"version":3,"sources":["../../src/placeholder/index.ts","../../src/placeholder/constants.ts","../../src/placeholder/placeholder.ts","../../src/placeholder/plugins/PlaceholderPlugin.ts","../../src/placeholder/utils/buildPlaceholderDecorations.ts","../../src/placeholder/utils/createPlaceholderDecoration.ts","../../src/placeholder/utils/preparePlaceholderAttribute.ts","../../src/placeholder/utils/findScrollParent.ts","../../src/placeholder/utils/getViewportBoundaryPositions.ts","../../src/placeholder/utils/viewportTracking.ts"],"sourcesContent":["export { DEFAULT_DATA_ATTRIBUTE, PLUGIN_KEY } from './constants.js'\nexport * from './placeholder.js'\nexport * from './types.js'\nexport { preparePlaceholderAttribute } from './utils/preparePlaceholderAttribute.js'\n","import { PluginKey } from '@tiptap/pm/state'\n\nimport type { ViewportState } from './types.js'\n\n/** The default data attribute label */\nexport const DEFAULT_DATA_ATTRIBUTE = 'placeholder'\n\n/** The plugin key used to store and read the placeholder viewport state */\nexport const PLUGIN_KEY = new PluginKey<ViewportState>('tiptap__placeholder')\n\n/**\n * Extra pixels added above and below the visible viewport when computing the\n * range of nodes to decorate. Decorating slightly beyond the fold means a\n * node already has its placeholder before it scrolls into view, which hides\n * the latency introduced by the throttled viewport recompute.\n */\nexport const VIEWPORT_OVERSCAN_PX = 200\n","import { Extension } from '@tiptap/core'\n\nimport { DEFAULT_DATA_ATTRIBUTE } from './constants.js'\nimport { createPlaceholderPlugin } from './plugins/PlaceholderPlugin.js'\nimport type { PlaceholderOptions } from './types.js'\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 dataAttribute: DEFAULT_DATA_ATTRIBUTE,\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\n },\n\n addProseMirrorPlugins() {\n return [createPlaceholderPlugin({ editor: this.editor, options: this.options })]\n },\n})\n","import type { Editor } from '@tiptap/core'\nimport { Plugin } from '@tiptap/pm/state'\n\nimport { DEFAULT_DATA_ATTRIBUTE, PLUGIN_KEY } from '../constants.js'\nimport type { PlaceholderOptions } from '../types.js'\nimport { buildPlaceholderDecorations } from '../utils/buildPlaceholderDecorations.js'\nimport { preparePlaceholderAttribute } from '../utils/preparePlaceholderAttribute.js'\nimport { createViewportPluginView, viewportPluginState } from '../utils/viewportTracking.js'\n\nexport type CreatePluginOptions = {\n editor: Editor\n options: PlaceholderOptions\n}\n\n/**\n * Creates the ProseMirror plugin that renders placeholder decorations.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @returns The configured placeholder plugin.\n */\nexport function createPlaceholderPlugin({ editor, options }: CreatePluginOptions) {\n const dataAttribute = options.dataAttribute\n ? `data-${preparePlaceholderAttribute(options.dataAttribute)}`\n : `data-${DEFAULT_DATA_ATTRIBUTE}`\n\n return new Plugin({\n key: PLUGIN_KEY,\n state: viewportPluginState,\n view: createViewportPluginView,\n props: {\n decorations: ({ doc, selection }) =>\n buildPlaceholderDecorations({ editor, options, dataAttribute, doc, selection }),\n },\n })\n}\n","import type { Editor } from '@tiptap/core'\nimport { isNodeEmpty } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Selection } from '@tiptap/pm/state'\nimport type { Decoration } from '@tiptap/pm/view'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport { PLUGIN_KEY } from '../constants.js'\nimport type { PlaceholderOptions } from '../types.js'\nimport { createPlaceholderDecoration } from './createPlaceholderDecoration.js'\n\n/**\n * Builds the placeholder decorations for the current document state.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @param options.dataAttribute - The prepared `data-*` attribute name.\n * @param options.doc - The current document node.\n * @param options.selection - The current selection.\n * @returns A decoration set, or `null` when no placeholders should be shown.\n */\nexport function buildPlaceholderDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n}: {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n}): DecorationSet | null {\n const active = editor.isEditable || !options.showOnlyWhenEditable\n\n if (!active) {\n return null\n }\n\n const { anchor } = selection\n const decorations: Decoration[] = []\n const isEmptyDoc = editor.isEmpty\n\n const classes = {\n emptyEditor: options.emptyEditorClass,\n emptyNode: options.emptyNodeClass,\n }\n\n const useResolvedPath = options.showOnlyCurrent && !options.includeChildren\n\n if (useResolvedPath) {\n const resolved = doc.resolve(anchor)\n\n // When the selection spans the whole document (e.g. an `AllSelection`\n // after Cmd+A), the anchor resolves to the document level (depth 0). In\n // that case the relevant textblock is the node directly after the\n // position rather than an ancestor. otherwise the placeholder would\n // disappear after selecting all and deleting.\n const node = resolved.depth > 0 ? resolved.node(1) : resolved.nodeAfter\n const nodeStart = resolved.depth > 0 ? resolved.before(1) : anchor\n\n if (node && node.type.isTextblock && isNodeEmpty(node)) {\n const hasAnchor = anchor >= nodeStart && anchor <= nodeStart + node.nodeSize\n\n decorations.push(\n createPlaceholderDecoration({\n editor,\n isEmptyDoc,\n dataAttribute,\n hasAnchor,\n placeholder: options.placeholder,\n classes,\n node,\n pos: nodeStart,\n }),\n )\n }\n } else {\n const pluginState = PLUGIN_KEY.getState(editor.state)\n const from = pluginState?.topPos ?? 0\n const to = pluginState?.bottomPos ?? doc.content.size\n\n doc.nodesBetween(from, to, (node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize\n const isEmpty = !node.isLeaf && isNodeEmpty(node)\n\n if (!node.type.isTextblock) {\n return options.includeChildren\n }\n\n if ((hasAnchor || !options.showOnlyCurrent) && isEmpty) {\n decorations.push(\n createPlaceholderDecoration({\n editor,\n isEmptyDoc,\n dataAttribute,\n hasAnchor,\n placeholder: options.placeholder,\n classes,\n node,\n pos,\n }),\n )\n }\n\n return options.includeChildren\n })\n }\n\n return DecorationSet.create(doc, decorations)\n}\n","import type { Editor } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport { Decoration } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\n\n/**\n * Creates a ProseMirror node decoration that applies a placeholder\n * CSS class and data attribute to an empty node.\n * @param options.editor - The editor instance\n * @param options.pos - The position of the node in the document\n * @param options.node - The ProseMirror node\n * @param options.isEmptyDoc - Whether the entire document is empty\n * @param options.hasAnchor - Whether the selection anchor is within the node\n * @param options.dataAttribute - The data attribute name (e.g. `data-placeholder`)\n * @param options.classes - CSS classes for empty nodes and the empty editor\n * @param options.placeholder - The placeholder text or a function that returns it\n * @returns A ProseMirror node decoration with placeholder classes and data attribute\n */\nexport function createPlaceholderDecoration(options: {\n editor: Editor\n pos: number\n node: Node\n isEmptyDoc: boolean\n hasAnchor: boolean\n dataAttribute: string\n classes: {\n emptyEditor: PlaceholderOptions['emptyEditorClass']\n emptyNode: PlaceholderOptions['emptyNodeClass']\n }\n placeholder: PlaceholderOptions['placeholder']\n}) {\n const {\n editor,\n placeholder,\n dataAttribute,\n pos,\n node,\n isEmptyDoc,\n hasAnchor,\n classes: { emptyNode, emptyEditor },\n } = options\n const classes = [emptyNode]\n\n if (isEmptyDoc) {\n classes.push(emptyEditor)\n }\n\n return Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n [dataAttribute]:\n typeof placeholder === 'function'\n ? placeholder({\n editor,\n node,\n pos,\n hasAnchor,\n })\n : placeholder,\n })\n}\n","/**\n * Prepares the placeholder attribute by ensuring it is properly formatted.\n * @param attr - The placeholder attribute string.\n * @returns The prepared placeholder attribute string.\n */\nexport function preparePlaceholderAttribute(attr: string): string {\n return (\n attr\n // replace whitespace with dashes\n .replace(/\\s+/g, '-')\n // replace non-alphanumeric characters\n // or special chars like $, %, &, etc.\n // but not dashes\n .replace(/[^a-zA-Z0-9-]/g, '')\n // and replace any numeric character at the start\n .replace(/^[0-9-]+/, '')\n // and finally replace any stray, leading dashes\n .replace(/^-+/, '')\n .toLowerCase()\n )\n}\n","/**\n * Checks if an element is scrollable by testing its overflow properties.\n * Elements with `overflow: hidden` or `overflow: clip` are intentionally\n * excluded — they clip content but don't emit scroll events.\n */\nfunction isScrollable(el: HTMLElement): boolean {\n const style = getComputedStyle(el)\n const overflow = `${style.overflow} ${style.overflowY} ${style.overflowX}`\n\n return /auto|scroll|overlay/.test(overflow)\n}\n\nexport function findScrollParent(element: HTMLElement): HTMLElement | Window {\n let el: HTMLElement | null = element\n\n while (el) {\n if (isScrollable(el)) {\n return el\n }\n\n // Check if we hit a Shadow DOM boundary. If so, jump to the shadow host\n // and continue traversing the light DOM.\n const parent = el.parentElement\n if (!parent) {\n const root = el.getRootNode()\n if (root instanceof ShadowRoot) {\n el = root.host as HTMLElement\n continue\n }\n\n return window\n }\n\n el = parent\n }\n\n return window\n}\n","import type { Node } from '@tiptap/pm/model'\nimport type { EditorView } from '@tiptap/pm/view'\n\nimport { VIEWPORT_OVERSCAN_PX } from '../constants.js'\n\nfunction getContainerRect(container: HTMLElement | Window): { top: number; bottom: number } {\n if (container === window) {\n return { top: 0, bottom: window.innerHeight }\n }\n\n return (container as HTMLElement).getBoundingClientRect()\n}\n\nexport function getViewportBoundaryPositions({\n doc,\n view,\n scrollContainer,\n}: {\n doc: Node\n view: EditorView\n scrollContainer?: HTMLElement | Window\n}) {\n const editorRect = view.dom.getBoundingClientRect()\n const containerRect = scrollContainer\n ? getContainerRect(scrollContainer)\n : { top: 0, bottom: window.innerHeight }\n\n const visibleTop = Math.max(editorRect.top, containerRect.top) - VIEWPORT_OVERSCAN_PX\n const visibleBottom = Math.min(editorRect.bottom, containerRect.bottom) + VIEWPORT_OVERSCAN_PX\n\n if (visibleTop >= visibleBottom) {\n // Editor is not visible — fall back to full document range\n return { top: 0, bottom: doc.content.size }\n }\n\n // Pick the x-coordinate based on text direction. In LTR the content\n // starts at the left edge; in RTL it starts at the right edge.\n // Clamp to ensure the coordinate stays inside the editor bounds.\n const isRTL = getComputedStyle(view.dom).direction === 'rtl'\n const x = isRTL ? Math.max(editorRect.right - 2, editorRect.left + 2) : editorRect.left + 2\n\n const topPos = view.posAtCoords({ left: x, top: visibleTop + 2 })\n const bottomPos = view.posAtCoords({ left: x, top: visibleBottom - 2 })\n\n return {\n top: topPos ? topPos.pos : 0,\n bottom: bottomPos ? bottomPos.pos : doc.content.size,\n }\n}\n","import type { EditorState, PluginView, StateField, Transaction } from '@tiptap/pm/state'\nimport type { EditorView } from '@tiptap/pm/view'\n\nimport { PLUGIN_KEY } from '../constants.js'\nimport type { ViewportState } from '../types.js'\nimport { findScrollParent } from './findScrollParent.js'\nimport { getViewportBoundaryPositions } from './getViewportBoundaryPositions.js'\n\n/**\n * The plugin `state` config that tracks the visible viewport boundaries so the\n * decoration callback only scans the nodes currently on screen.\n */\nexport const viewportPluginState: StateField<ViewportState> = {\n /**\n * Initialises the viewport state with no known positions.\n * @returns The initial viewport state.\n */\n init(): ViewportState {\n return { topPos: null, bottomPos: null }\n },\n\n /**\n * Updates the viewport state from incoming transactions.\n * @param tr - The transaction being applied.\n * @param prev - The previous viewport state.\n * @returns The next viewport state.\n */\n apply(tr: Transaction, prev: ViewportState): ViewportState {\n const meta = tr.getMeta(PLUGIN_KEY) as\n | { positions?: { top: number; bottom: number } }\n | undefined\n\n if (meta?.positions) {\n return { topPos: meta.positions.top, bottomPos: meta.positions.bottom }\n }\n\n if (!tr.docChanged) {\n return prev\n }\n\n // Preserve last known viewport positions across transactions.\n // Without this, every keystroke resets back to a full document\n // scan, defeating the viewport optimisation.\n // Only map when we have actual positions — null means \"no viewport\n // info yet\" and should stay null to fall back to full doc scan.\n return {\n topPos: prev.topPos !== null ? tr.mapping.map(prev.topPos) : null,\n bottomPos: prev.bottomPos !== null ? tr.mapping.map(prev.bottomPos) : null,\n }\n },\n}\n\n/**\n * Creates the plugin `view` that recomputes the visible viewport on scroll and\n * document size changes, dispatching the result into the plugin state.\n * @param view - The editor view the plugin is attached to.\n * @returns A plugin view with `update` and `destroy` handlers.\n */\nexport function createViewportPluginView(view: EditorView): PluginView {\n const scrollContainer = findScrollParent(view.dom)\n\n const computeAndDispatch = () => {\n const positions = getViewportBoundaryPositions({\n view,\n doc: view.state.doc,\n scrollContainer,\n })\n\n const prev = PLUGIN_KEY.getState(view.state)\n if (prev?.topPos === positions.top && prev?.bottomPos === positions.bottom) {\n return\n }\n\n const tr = view.state.tr.setMeta(PLUGIN_KEY, { positions })\n view.dispatch(tr)\n }\n\n // rAF-based scheduler with interval guard (150ms → ~6–7 Hz) used by\n // scroll events and update(). The overscan margin hides the extra\n // latency. When the guard blocks, the callback reschedules itself so\n // the trailing position is always captured.\n let frame: number | null = null\n let lastCompute = 0\n const MIN_SCROLL_INTERVAL = 150\n\n const scheduleFrame = () => {\n if (frame !== null) return\n frame = requestAnimationFrame(() => {\n frame = null\n const now = performance.now()\n if (now - lastCompute >= MIN_SCROLL_INTERVAL) {\n lastCompute = now\n computeAndDispatch()\n } else {\n scheduleFrame()\n }\n })\n }\n\n scrollContainer.addEventListener('scroll', scheduleFrame, { passive: true })\n\n // Fire once to populate initial viewport\n computeAndDispatch()\n\n return {\n update(_view: EditorView, prevState: EditorState) {\n if (view.state.doc.content.size !== prevState.doc.content.size) {\n scheduleFrame()\n }\n },\n destroy: () => {\n if (frame !== null) {\n cancelAnimationFrame(frame)\n }\n scrollContainer.removeEventListener('scroll', scheduleFrame)\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0B;AAKnB,IAAM,yBAAyB;AAG/B,IAAM,aAAa,IAAI,uBAAyB,qBAAqB;AAQrE,IAAM,uBAAuB;;;AChBpC,IAAAA,eAA0B;;;ACC1B,IAAAC,gBAAuB;;;ACAvB,kBAA4B;AAI5B,IAAAC,eAA8B;;;ACH9B,kBAA2B;AAiBpB,SAAS,4BAA4B,SAYzC;AACD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,EAAE,WAAW,YAA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AAEnB,SAAO;AAAA,IACL,OAAO,OAAmB,WAAwB;AAChD,UAAI,KAAK,MAAM,IAAI,QAAQ,SAAS,UAAU,IAAI,QAAQ,MAAM;AAC9D,sBAAc;AAAA,MAChB;AAAA,IACF;AAAA,IACA,SAAS,MAAM;AACb,UAAI,UAAU,MAAM;AAClB,6BAAqB,KAAK;AAAA,MAC5B;AACA,sBAAgB,oBAAoB,UAAU,aAAa;AAAA,IAC7D;AAAA,EACF;AACF;;;ANjGO,SAAS,wBAAwB,EAAE,QAAQ,QAAQ,GAAwB;AAChF,QAAM,gBAAgB,QAAQ,gBAC1B,QAAQ,4BAA4B,QAAQ,aAAa,CAAC,KAC1D,QAAQ,sBAAsB;AAElC,SAAO,IAAI,qBAAO;AAAA,IAChB,KAAK;AAAA,IACL,OAAO;AAAA,IACP,MAAM;AAAA,IACN,OAAO;AAAA,MACL,aAAa,CAAC,EAAE,KAAK,UAAU,MAC7B,4BAA4B,EAAE,QAAQ,SAAS,eAAe,KAAK,UAAU,CAAC;AAAA,IAClF;AAAA,EACF,CAAC;AACH;;;ADvBO,IAAM,cAAc,uBAAU,OAA2B;AAAA,EAC9D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,kBAAkB;AAAA,MAClB,gBAAgB;AAAA,MAChB,eAAe;AAAA,MACf,aAAa;AAAA,MACb,sBAAsB;AAAA,MACtB,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO,CAAC,wBAAwB,EAAE,QAAQ,KAAK,QAAQ,SAAS,KAAK,QAAQ,CAAC,CAAC;AAAA,EACjF;AACF,CAAC;","names":["import_core","import_state","import_view"]}
@@ -1,7 +1,16 @@
1
- import { Editor, Extension } from '@tiptap/core';
2
1
  import { PluginKey } from '@tiptap/pm/state';
2
+ import { Editor, Extension } from '@tiptap/core';
3
3
  import { Node } from '@tiptap/pm/model';
4
4
 
5
+ /**
6
+ * The viewport positions tracked by the placeholder plugin.
7
+ * `null` means "no viewport info yet" — the decoration callback falls back to
8
+ * a full document scan until the scroll handler fires.
9
+ */
10
+ interface ViewportState {
11
+ topPos: number | null;
12
+ bottomPos: number | null;
13
+ }
5
14
  interface PlaceholderOptions {
6
15
  /**
7
16
  * **The class name for the empty editor**
@@ -57,13 +66,11 @@ interface PlaceholderOptions {
57
66
  includeChildren: boolean;
58
67
  }
59
68
 
60
- /**
61
- * Prepares the placeholder attribute by ensuring it is properly formatted.
62
- * @param attr - The placeholder attribute string.
63
- * @returns The prepared placeholder attribute string.
64
- */
65
- declare function preparePlaceholderAttribute(attr: string): string;
66
- declare const PLUGIN_KEY: PluginKey<any>;
69
+ /** The default data attribute label */
70
+ declare const DEFAULT_DATA_ATTRIBUTE = "placeholder";
71
+ /** The plugin key used to store and read the placeholder viewport state */
72
+ declare const PLUGIN_KEY: PluginKey<ViewportState>;
73
+
67
74
  /**
68
75
  * This extension allows you to add a placeholder to your editor.
69
76
  * A placeholder is a text that appears when the editor or a node is empty.
@@ -71,4 +78,11 @@ declare const PLUGIN_KEY: PluginKey<any>;
71
78
  */
72
79
  declare const Placeholder: Extension<PlaceholderOptions, any>;
73
80
 
74
- export { PLUGIN_KEY, Placeholder, type PlaceholderOptions, preparePlaceholderAttribute };
81
+ /**
82
+ * Prepares the placeholder attribute by ensuring it is properly formatted.
83
+ * @param attr - The placeholder attribute string.
84
+ * @returns The prepared placeholder attribute string.
85
+ */
86
+ declare function preparePlaceholderAttribute(attr: string): string;
87
+
88
+ export { DEFAULT_DATA_ATTRIBUTE, PLUGIN_KEY, Placeholder, type PlaceholderOptions, type ViewportState, preparePlaceholderAttribute };
@@ -1,7 +1,16 @@
1
- import { Editor, Extension } from '@tiptap/core';
2
1
  import { PluginKey } from '@tiptap/pm/state';
2
+ import { Editor, Extension } from '@tiptap/core';
3
3
  import { Node } from '@tiptap/pm/model';
4
4
 
5
+ /**
6
+ * The viewport positions tracked by the placeholder plugin.
7
+ * `null` means "no viewport info yet" — the decoration callback falls back to
8
+ * a full document scan until the scroll handler fires.
9
+ */
10
+ interface ViewportState {
11
+ topPos: number | null;
12
+ bottomPos: number | null;
13
+ }
5
14
  interface PlaceholderOptions {
6
15
  /**
7
16
  * **The class name for the empty editor**
@@ -57,13 +66,11 @@ interface PlaceholderOptions {
57
66
  includeChildren: boolean;
58
67
  }
59
68
 
60
- /**
61
- * Prepares the placeholder attribute by ensuring it is properly formatted.
62
- * @param attr - The placeholder attribute string.
63
- * @returns The prepared placeholder attribute string.
64
- */
65
- declare function preparePlaceholderAttribute(attr: string): string;
66
- declare const PLUGIN_KEY: PluginKey<any>;
69
+ /** The default data attribute label */
70
+ declare const DEFAULT_DATA_ATTRIBUTE = "placeholder";
71
+ /** The plugin key used to store and read the placeholder viewport state */
72
+ declare const PLUGIN_KEY: PluginKey<ViewportState>;
73
+
67
74
  /**
68
75
  * This extension allows you to add a placeholder to your editor.
69
76
  * A placeholder is a text that appears when the editor or a node is empty.
@@ -71,4 +78,11 @@ declare const PLUGIN_KEY: PluginKey<any>;
71
78
  */
72
79
  declare const Placeholder: Extension<PlaceholderOptions, any>;
73
80
 
74
- export { PLUGIN_KEY, Placeholder, type PlaceholderOptions, preparePlaceholderAttribute };
81
+ /**
82
+ * Prepares the placeholder attribute by ensuring it is properly formatted.
83
+ * @param attr - The placeholder attribute string.
84
+ * @returns The prepared placeholder attribute string.
85
+ */
86
+ declare function preparePlaceholderAttribute(attr: string): string;
87
+
88
+ export { DEFAULT_DATA_ATTRIBUTE, PLUGIN_KEY, Placeholder, type PlaceholderOptions, type ViewportState, preparePlaceholderAttribute };