tiptop-editor 1.3.0 → 1.5.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.
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Extensions } from '@tiptap/core';
1
+ import { Extensions, JSONContent } from '@tiptap/core';
2
2
  import { Editor, EditorContentProps, Range, UseEditorOptions } from '@tiptap/react';
3
3
  import { icons } from 'lucide-react';
4
4
  export type ImageUploadResponseResolver = string | string[] | ((response: Record<string, unknown>) => string | null | undefined);
@@ -99,11 +99,87 @@ export interface TiptopEditorSlots {
99
99
  tableMenuPrepend?: TiptopEditorSlot;
100
100
  tableMenuAppend?: TiptopEditorSlot;
101
101
  }
102
+ export interface DocumentWord {
103
+ /** 0-based index of this word within its block node */
104
+ index: number;
105
+ /** Plain text of this word */
106
+ text: string;
107
+ /** Absolute ProseMirror position of the word's first character */
108
+ absFrom: number;
109
+ /** Absolute ProseMirror position after the word's last character */
110
+ absTo: number;
111
+ }
112
+ export interface DocumentNode {
113
+ /** 0-based index of this block in the document */
114
+ index: number;
115
+ /** ProseMirror node type name (e.g. "paragraph", "heading") */
116
+ type: string;
117
+ /** Full plain-text content of this block */
118
+ text: string;
119
+ /** Absolute ProseMirror position of the block's opening tag */
120
+ absFrom: number;
121
+ /** Absolute ProseMirror position after the block's closing tag */
122
+ absTo: number;
123
+ /** Words extracted from this block's text */
124
+ words: DocumentWord[];
125
+ /**
126
+ * Maps each character index in `text` to its absolute ProseMirror position.
127
+ * Use this when word-level precision is not enough.
128
+ */
129
+ charMap: number[];
130
+ }
131
+ export interface DocumentMap {
132
+ nodes: DocumentNode[];
133
+ }
134
+ /**
135
+ * Replacement content for a targeted update.
136
+ * - `string`: plain text — marks from the replaced range are automatically preserved.
137
+ * - `JSONContent[]`: rich inline content (text nodes with explicit marks, etc.).
138
+ */
139
+ export type TargetedUpdateReplacement = string | JSONContent[];
140
+ export interface TargetedUpdate {
141
+ /** 0-based index of the target block in the document */
142
+ nodeIndex?: number;
143
+ /** 0-based word index within the target block */
144
+ wordIndex?: number;
145
+ /** Inclusive `[startWordIndex, endWordIndex]` word range within the target block */
146
+ wordRange?: [number, number];
147
+ /**
148
+ * 0-based character offset from the start of the block's text content.
149
+ * Must be paired with `charTo`.
150
+ */
151
+ charFrom?: number;
152
+ /**
153
+ * 0-based exclusive character offset from the start of the block's text content.
154
+ * Must be paired with `charFrom`.
155
+ */
156
+ charTo?: number;
157
+ /** Content to replace the targeted range with */
158
+ replacement: TargetedUpdateReplacement;
159
+ }
102
160
  export interface TiptopEditorHandle {
103
161
  getEditor: () => Editor | null;
104
162
  on: Editor['on'];
105
163
  off: Editor['off'];
106
164
  once: Editor['once'];
165
+ /**
166
+ * Returns a structured map of all top-level block nodes in the document with
167
+ * their text content, word boundaries, and absolute ProseMirror positions.
168
+ * Pass this to your AI model so it can reference specific locations.
169
+ * Returns `null` if the editor is not yet mounted.
170
+ */
171
+ getDocumentMap: () => DocumentMap | null;
172
+ /**
173
+ * Applies a single targeted content update, preserving marks on plain-text
174
+ * replacements. Returns `true` on success.
175
+ */
176
+ applyTargetedUpdate: (update: TargetedUpdate) => boolean;
177
+ /**
178
+ * Applies multiple targeted updates in one atomic ProseMirror transaction,
179
+ * processing from the bottom of the document upward so earlier replacements
180
+ * never shift the positions of later ones. Returns `true` on success.
181
+ */
182
+ applyTargetedUpdates: (updates: TargetedUpdate[]) => boolean;
107
183
  }
108
184
  export interface KeyDownRef {
109
185
  onKeyDown: (props: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiptop-editor",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "Notion-like editor built with Tiptap v3 and HeroUI",
5
5
  "type": "module",
6
6
  "main": "./dist/tiptop-editor.umd.js",