tiptop-editor 1.2.0 → 1.4.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,3 +1,4 @@
1
+ import { Extensions, JSONContent } from '@tiptap/core';
1
2
  import { Editor, EditorContentProps, Range, UseEditorOptions } from '@tiptap/react';
2
3
  import { icons } from 'lucide-react';
3
4
  export type ImageUploadResponseResolver = string | string[] | ((response: Record<string, unknown>) => string | null | undefined);
@@ -27,6 +28,12 @@ export type TiptopEditorOptions = Omit<Partial<UseEditorOptions & {
27
28
  * @default true
28
29
  */
29
30
  showDragHandle?: boolean;
31
+ /**
32
+ * Additional Tiptap extensions to append after the built-in editor set.
33
+ * Use this to add feature-specific extensions like AI commands or collaboration.
34
+ * @default undefined
35
+ */
36
+ extraExtensions?: Extensions;
30
37
  }>, 'extensions'>;
31
38
  export interface EditorButtonProps {
32
39
  tooltipText?: React.ReactNode;
@@ -64,6 +71,7 @@ export type TiptopEditorProps = Omit<EditorContentProps, 'editor'> & {
64
71
  * implementation.
65
72
  */
66
73
  editorOptions?: TiptopEditorOptions;
74
+ slots?: TiptopEditorSlots;
67
75
  };
68
76
  export interface ColorButtonProps {
69
77
  editor: Editor;
@@ -79,11 +87,99 @@ export interface TextSelectionMenuProps {
79
87
  prepend?: React.ReactNode;
80
88
  append?: React.ReactNode;
81
89
  }
90
+ export interface TiptopEditorSlotProps {
91
+ editor: Editor;
92
+ }
93
+ export type TiptopEditorSlot = React.ReactNode | ((props: TiptopEditorSlotProps) => React.ReactNode);
94
+ export interface TiptopEditorSlots {
95
+ editorTop?: TiptopEditorSlot;
96
+ editorBottom?: TiptopEditorSlot;
97
+ selectionMenuPrepend?: TiptopEditorSlot;
98
+ selectionMenuAppend?: TiptopEditorSlot;
99
+ tableMenuPrepend?: TiptopEditorSlot;
100
+ tableMenuAppend?: TiptopEditorSlot;
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
+ }
82
160
  export interface TiptopEditorHandle {
83
161
  getEditor: () => Editor | null;
84
162
  on: Editor['on'];
85
163
  off: Editor['off'];
86
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;
87
183
  }
88
184
  export interface KeyDownRef {
89
185
  onKeyDown: (props: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiptop-editor",
3
- "version": "1.2.0",
3
+ "version": "1.4.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",