@x12i/editor 1.0.0 → 1.1.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/README.md +349 -16
- package/dist/chunk-FYXMOAJT.js +1890 -0
- package/dist/chunk-FYXMOAJT.js.map +1 -0
- package/dist/index.d.ts +207 -171
- package/dist/index.js +1321 -7
- package/dist/index.js.map +1 -1
- package/dist/outline-Drc3E0C1.d.ts +339 -0
- package/dist/react.d.ts +546 -0
- package/dist/react.js +4439 -0
- package/dist/react.js.map +1 -0
- package/dist/styles.css +1219 -0
- package/package.json +57 -8
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { Block, EditorDocument, OutlineItem, ConversionWarning, AiProvider, AiCommand } from './index.js';
|
|
4
|
+
import * as _tiptap_core from '@tiptap/core';
|
|
5
|
+
import { Extensions, Editor as Editor$1, JSONContent } from '@tiptap/core';
|
|
6
|
+
import { SuggestionProps, SuggestionKeyDownProps } from '@tiptap/suggestion';
|
|
7
|
+
import '@x12i/charts';
|
|
8
|
+
import '@x12i/data';
|
|
9
|
+
import '@x12i/diagrams';
|
|
10
|
+
|
|
11
|
+
/** The block kinds a person can insert or turn a block into. */
|
|
12
|
+
type BlockKind = "paragraph" | "heading1" | "heading2" | "heading3" | "heading4" | "quote" | "callout" | "toggle" | "bulletList" | "numberedList" | "taskList" | "code" | "equation" | "divider" | "table" | "image" | "video" | "audio" | "file" | "bookmark" | "columns" | "pageBreak" | "toc" | "chart" | "diagram" | "dataView" | "ai";
|
|
13
|
+
declare const BLOCK_KINDS: readonly BlockKind[];
|
|
14
|
+
type BlockMessage = {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
/** Extra words that find the block in the slash menu. Space separated. */
|
|
18
|
+
keywords: string;
|
|
19
|
+
};
|
|
20
|
+
type SlashGroup = "basic" | "lists" | "media" | "advanced" | "embeds";
|
|
21
|
+
interface Messages {
|
|
22
|
+
editorLabel: string;
|
|
23
|
+
placeholder: string;
|
|
24
|
+
viewLabel: string;
|
|
25
|
+
toolbar: {
|
|
26
|
+
label: string;
|
|
27
|
+
undo: string;
|
|
28
|
+
redo: string;
|
|
29
|
+
blockType: string;
|
|
30
|
+
bold: string;
|
|
31
|
+
italic: string;
|
|
32
|
+
underline: string;
|
|
33
|
+
strike: string;
|
|
34
|
+
code: string;
|
|
35
|
+
highlight: string;
|
|
36
|
+
textColor: string;
|
|
37
|
+
clearColor: string;
|
|
38
|
+
link: string;
|
|
39
|
+
bulletList: string;
|
|
40
|
+
numberedList: string;
|
|
41
|
+
taskList: string;
|
|
42
|
+
indent: string;
|
|
43
|
+
outdent: string;
|
|
44
|
+
quote: string;
|
|
45
|
+
divider: string;
|
|
46
|
+
table: string;
|
|
47
|
+
image: string;
|
|
48
|
+
selectionMenu: string;
|
|
49
|
+
};
|
|
50
|
+
/** Names for the color and highlight palettes, by token path. */
|
|
51
|
+
tokens: Record<string, string>;
|
|
52
|
+
blocks: Record<BlockKind, BlockMessage>;
|
|
53
|
+
groups: Record<SlashGroup, string>;
|
|
54
|
+
callouts: Record<"info" | "success" | "warning" | "danger" | "neutral", string>;
|
|
55
|
+
slash: {
|
|
56
|
+
label: string;
|
|
57
|
+
noResults: string;
|
|
58
|
+
resultCount: string;
|
|
59
|
+
instructions: string;
|
|
60
|
+
};
|
|
61
|
+
blockMenu: {
|
|
62
|
+
label: string;
|
|
63
|
+
trigger: string;
|
|
64
|
+
duplicate: string;
|
|
65
|
+
delete: string;
|
|
66
|
+
turnInto: string;
|
|
67
|
+
moveUp: string;
|
|
68
|
+
moveDown: string;
|
|
69
|
+
insertBelow: string;
|
|
70
|
+
};
|
|
71
|
+
table: {
|
|
72
|
+
addRowBefore: string;
|
|
73
|
+
addRowAfter: string;
|
|
74
|
+
addColumnBefore: string;
|
|
75
|
+
addColumnAfter: string;
|
|
76
|
+
deleteRow: string;
|
|
77
|
+
deleteColumn: string;
|
|
78
|
+
toggleHeaderRow: string;
|
|
79
|
+
toggleHeaderColumn: string;
|
|
80
|
+
deleteTable: string;
|
|
81
|
+
controls: string;
|
|
82
|
+
};
|
|
83
|
+
linkDialog: {
|
|
84
|
+
title: string;
|
|
85
|
+
urlLabel: string;
|
|
86
|
+
urlHint: string;
|
|
87
|
+
invalid: string;
|
|
88
|
+
required: string;
|
|
89
|
+
apply: string;
|
|
90
|
+
remove: string;
|
|
91
|
+
cancel: string;
|
|
92
|
+
};
|
|
93
|
+
imageDialog: {
|
|
94
|
+
title: string;
|
|
95
|
+
editTitle: string;
|
|
96
|
+
urlLabel: string;
|
|
97
|
+
altLabel: string;
|
|
98
|
+
altHint: string;
|
|
99
|
+
altRequired: string;
|
|
100
|
+
decorative: string;
|
|
101
|
+
captionLabel: string;
|
|
102
|
+
urlRequired: string;
|
|
103
|
+
urlInvalid: string;
|
|
104
|
+
insert: string;
|
|
105
|
+
update: string;
|
|
106
|
+
cancel: string;
|
|
107
|
+
};
|
|
108
|
+
code: {
|
|
109
|
+
language: string;
|
|
110
|
+
plainText: string;
|
|
111
|
+
copy: string;
|
|
112
|
+
copied: string;
|
|
113
|
+
};
|
|
114
|
+
task: {
|
|
115
|
+
done: string;
|
|
116
|
+
todo: string;
|
|
117
|
+
emptyLabel: string;
|
|
118
|
+
};
|
|
119
|
+
toggle: {
|
|
120
|
+
expand: string;
|
|
121
|
+
collapse: string;
|
|
122
|
+
summaryPlaceholder: string;
|
|
123
|
+
};
|
|
124
|
+
equation: {
|
|
125
|
+
label: string;
|
|
126
|
+
placeholder: string;
|
|
127
|
+
};
|
|
128
|
+
embed: {
|
|
129
|
+
groupLabel: string;
|
|
130
|
+
untitled: string;
|
|
131
|
+
edit: string;
|
|
132
|
+
remove: string;
|
|
133
|
+
moveUp: string;
|
|
134
|
+
moveDown: string;
|
|
135
|
+
toolbar: string;
|
|
136
|
+
request: string;
|
|
137
|
+
previewHint: string;
|
|
138
|
+
showData: string;
|
|
139
|
+
dataset: string;
|
|
140
|
+
prompt: string;
|
|
141
|
+
result: string;
|
|
142
|
+
engine: string;
|
|
143
|
+
unknown: string;
|
|
144
|
+
};
|
|
145
|
+
media: {
|
|
146
|
+
file: string;
|
|
147
|
+
download: string;
|
|
148
|
+
bookmark: string;
|
|
149
|
+
open: string;
|
|
150
|
+
unsafe: string;
|
|
151
|
+
image: string;
|
|
152
|
+
imageDecorative: string;
|
|
153
|
+
imageEdit: string;
|
|
154
|
+
video: string;
|
|
155
|
+
audio: string;
|
|
156
|
+
urlLabel: string;
|
|
157
|
+
nameLabel: string;
|
|
158
|
+
set: string;
|
|
159
|
+
};
|
|
160
|
+
ai: {
|
|
161
|
+
menuLabel: string;
|
|
162
|
+
improve: string;
|
|
163
|
+
shorten: string;
|
|
164
|
+
continue: string;
|
|
165
|
+
fixGrammar: string;
|
|
166
|
+
custom: string;
|
|
167
|
+
customLabel: string;
|
|
168
|
+
run: string;
|
|
169
|
+
accept: string;
|
|
170
|
+
reject: string;
|
|
171
|
+
cancel: string;
|
|
172
|
+
generating: string;
|
|
173
|
+
preview: string;
|
|
174
|
+
error: string;
|
|
175
|
+
noSelection: string;
|
|
176
|
+
done: string;
|
|
177
|
+
/** Instructions handed to the provider as the `tone` of a rewrite. */
|
|
178
|
+
prompts: {
|
|
179
|
+
improve: string;
|
|
180
|
+
shorten: string;
|
|
181
|
+
continue: string;
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
status: {
|
|
185
|
+
saved: string;
|
|
186
|
+
markOn: string;
|
|
187
|
+
markOff: string;
|
|
188
|
+
blockMoved: string;
|
|
189
|
+
blockMovedUp: string;
|
|
190
|
+
blockMovedDown: string;
|
|
191
|
+
blockDuplicated: string;
|
|
192
|
+
blockDeleted: string;
|
|
193
|
+
blockTurnedInto: string;
|
|
194
|
+
linkApplied: string;
|
|
195
|
+
linkRemoved: string;
|
|
196
|
+
imageInserted: string;
|
|
197
|
+
copied: string;
|
|
198
|
+
undone: string;
|
|
199
|
+
redone: string;
|
|
200
|
+
aiApplied: string;
|
|
201
|
+
cannotMove: string;
|
|
202
|
+
};
|
|
203
|
+
directions: {
|
|
204
|
+
up: string;
|
|
205
|
+
down: string;
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
declare const defaultMessages: Messages;
|
|
209
|
+
type DeepPartial<T> = {
|
|
210
|
+
[K in keyof T]?: T[K] extends Record<string, unknown> ? DeepPartial<T[K]> : T[K];
|
|
211
|
+
};
|
|
212
|
+
/** Overlays a partial table on a base table. Missing keys keep the base text. */
|
|
213
|
+
declare function mergeMessages(base: Messages, overrides?: DeepPartial<Messages>): Messages;
|
|
214
|
+
/**
|
|
215
|
+
* Fills `{name}` placeholders and `{name, plural, one {...} other {...}}`
|
|
216
|
+
* blocks (`#` stands for the number). Unknown names stay as written.
|
|
217
|
+
*/
|
|
218
|
+
declare function formatMessage(template: string, values?: Record<string, string | number>, locale?: string): string;
|
|
219
|
+
/** A translator bound to one message table. */
|
|
220
|
+
interface Translator {
|
|
221
|
+
messages: Messages;
|
|
222
|
+
locale: string | undefined;
|
|
223
|
+
/** Formats a template from the table. */
|
|
224
|
+
format: (template: string, values?: Record<string, string | number>) => string;
|
|
225
|
+
}
|
|
226
|
+
declare function createTranslator(messages: Messages, locale?: string): Translator;
|
|
227
|
+
/** Reads the translator of the nearest editor. */
|
|
228
|
+
declare function useTranslator(): Translator;
|
|
229
|
+
/** Reads the message table of the nearest editor. */
|
|
230
|
+
declare function useMessages(): Messages;
|
|
231
|
+
|
|
232
|
+
/** The block types that render through an injected renderer instead of editor content. */
|
|
233
|
+
type EmbedType = "chart" | "diagram" | "data-view" | "ai";
|
|
234
|
+
type ChartBlock = Extract<Block, {
|
|
235
|
+
type: "chart";
|
|
236
|
+
}>;
|
|
237
|
+
type DiagramBlock = Extract<Block, {
|
|
238
|
+
type: "diagram";
|
|
239
|
+
}>;
|
|
240
|
+
type DataViewBlock = Extract<Block, {
|
|
241
|
+
type: "data-view";
|
|
242
|
+
}>;
|
|
243
|
+
type AiBlock = Extract<Block, {
|
|
244
|
+
type: "ai";
|
|
245
|
+
}>;
|
|
246
|
+
/** The data each embedded block carries. These are the payloads of the stored document. */
|
|
247
|
+
interface EmbedPayloads {
|
|
248
|
+
chart: ChartBlock["spec"];
|
|
249
|
+
diagram: {
|
|
250
|
+
engine: DiagramBlock["engine"];
|
|
251
|
+
diagram?: DiagramBlock["diagram"];
|
|
252
|
+
source?: string;
|
|
253
|
+
};
|
|
254
|
+
"data-view": {
|
|
255
|
+
dataset: DataViewBlock["dataset"];
|
|
256
|
+
view: DataViewBlock["view"];
|
|
257
|
+
};
|
|
258
|
+
ai: {
|
|
259
|
+
prompt: AiBlock["prompt"];
|
|
260
|
+
result?: AiBlock["result"];
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
interface BlockRendererProps<T extends EmbedType = EmbedType> {
|
|
264
|
+
type: T;
|
|
265
|
+
/** The block id from the document. */
|
|
266
|
+
id: string;
|
|
267
|
+
payload: EmbedPayloads[T];
|
|
268
|
+
/** A short, human readable title taken from the payload, when it has one. */
|
|
269
|
+
title: string;
|
|
270
|
+
/** False in `EditorView` and when the editor is read-only. */
|
|
271
|
+
editable: boolean;
|
|
272
|
+
/** True while the block is the selection of the editor. */
|
|
273
|
+
selected: boolean;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Renderers for embedded blocks. The editor never imports chart, diagram or
|
|
277
|
+
* data components: pass the ones your app uses. A missing renderer falls back
|
|
278
|
+
* to an accessible JSON summary card.
|
|
279
|
+
*
|
|
280
|
+
* Each renderer is mounted as a React component (not called as a function), so
|
|
281
|
+
* it may use hooks. Keep the renderer functions stable between renders (define
|
|
282
|
+
* them at module level or memoize the object): a new function identity makes
|
|
283
|
+
* React remount that block and lose its state. A renderer that throws is
|
|
284
|
+
* caught by an error boundary and replaced by the fallback card.
|
|
285
|
+
*/
|
|
286
|
+
type BlockRenderers = {
|
|
287
|
+
[K in EmbedType]?: (props: BlockRendererProps<K>) => ReactNode;
|
|
288
|
+
} & {
|
|
289
|
+
/** Renders a block of a type this version does not know. Receives the stored data. */
|
|
290
|
+
unknown?: (props: {
|
|
291
|
+
id: string;
|
|
292
|
+
blockType: string;
|
|
293
|
+
payload: Record<string, unknown>;
|
|
294
|
+
editable: boolean;
|
|
295
|
+
}) => ReactNode;
|
|
296
|
+
};
|
|
297
|
+
type BlockPayload<T extends EmbedType = EmbedType> = EmbedPayloads[T];
|
|
298
|
+
/** Called when a person asks to edit an embedded block. Resolve with the new payload, or `null` to cancel. */
|
|
299
|
+
type EditBlockHandler = <T extends EmbedType>(type: T, payload: EmbedPayloads[T]) => Promise<EmbedPayloads[T] | null | undefined> | EmbedPayloads[T] | null | undefined;
|
|
300
|
+
/** Called when a person inserts a chart, diagram, data view or AI block. Resolve with its payload, or `null` to cancel. */
|
|
301
|
+
type RequestBlockHandler = <T extends EmbedType>(type: T) => Promise<EmbedPayloads[T] | null | undefined> | EmbedPayloads[T] | null | undefined;
|
|
302
|
+
/** A command for `EditorApi.exec`. */
|
|
303
|
+
type EditorCommand = "undo" | "redo" | "bold" | "italic" | "underline" | "strike" | "code" | "clearMarks" | "bulletList" | "numberedList" | "taskList" | "indent" | "outdent" | "quote" | "divider" | "paragraph" | "heading1" | "heading2" | "heading3" | "heading4" | "codeBlock" | "moveBlockUp" | "moveBlockDown" | "duplicateBlock" | "deleteBlock" | "selectAll" | "openBlockMenu";
|
|
304
|
+
interface SelectionInfo {
|
|
305
|
+
/** True when the selection is a caret. */
|
|
306
|
+
empty: boolean;
|
|
307
|
+
/** The selected text, or an empty string. */
|
|
308
|
+
text: string;
|
|
309
|
+
/** Id of the block the selection starts in, when known. */
|
|
310
|
+
blockId: string | null;
|
|
311
|
+
/** Marks active at the selection, such as `bold`. */
|
|
312
|
+
marks: string[];
|
|
313
|
+
/** The kind of the block the selection is in, such as `heading2`. */
|
|
314
|
+
blockKind: BlockKind | null;
|
|
315
|
+
}
|
|
316
|
+
/** The imperative handle of an `Editor`. */
|
|
317
|
+
interface EditorApi {
|
|
318
|
+
/** The current document in the kit's own format. */
|
|
319
|
+
getDocument(): EditorDocument;
|
|
320
|
+
/** Replaces the whole document. Does not call `onChange`. */
|
|
321
|
+
setDocument(doc: EditorDocument): void;
|
|
322
|
+
focus(position?: "start" | "end"): void;
|
|
323
|
+
/** Inserts a block after the selection (or in place of an empty paragraph). Returns the new block id when known. */
|
|
324
|
+
insertBlock(type: BlockKind | Block["type"], attrs?: Record<string, unknown>): Promise<string | null>;
|
|
325
|
+
exec(command: EditorCommand): boolean;
|
|
326
|
+
getMarkdown(): string;
|
|
327
|
+
getOutline(): OutlineItem[];
|
|
328
|
+
/** The underlying Tiptap editor, for advanced use. It may be null before the first mount. */
|
|
329
|
+
getEngine(): _tiptap_core.Editor | null;
|
|
330
|
+
/** Announces a message through the editor's status region. */
|
|
331
|
+
announce(message: string): void;
|
|
332
|
+
}
|
|
333
|
+
interface EditorProps {
|
|
334
|
+
/** Controlled document. */
|
|
335
|
+
value?: EditorDocument;
|
|
336
|
+
/** Uncontrolled initial document. */
|
|
337
|
+
defaultValue?: EditorDocument;
|
|
338
|
+
/** Called after edits with the new document. */
|
|
339
|
+
onChange?: (doc: EditorDocument) => void;
|
|
340
|
+
/** Milliseconds to wait after the last edit before `onChange`. Default 0 (each edit). */
|
|
341
|
+
debounce?: number;
|
|
342
|
+
/** Defaults to true. */
|
|
343
|
+
editable?: boolean;
|
|
344
|
+
placeholder?: string;
|
|
345
|
+
autoFocus?: boolean | "start" | "end";
|
|
346
|
+
blockRenderers?: BlockRenderers;
|
|
347
|
+
/** Extra Tiptap extensions. They are read once when the editor mounts. */
|
|
348
|
+
extensions?: Extensions;
|
|
349
|
+
messages?: DeepPartial<Messages>;
|
|
350
|
+
/** BCP 47 tag used for plurals, word counts and spell checking. */
|
|
351
|
+
locale?: string;
|
|
352
|
+
"aria-label"?: string;
|
|
353
|
+
"aria-labelledby"?: string;
|
|
354
|
+
/** Called once with the imperative API when the editor is ready. */
|
|
355
|
+
onReady?: (api: EditorApi) => void;
|
|
356
|
+
onSelectionChange?: (selection: SelectionInfo) => void;
|
|
357
|
+
onEditBlock?: EditBlockHandler;
|
|
358
|
+
onRequestBlock?: RequestBlockHandler;
|
|
359
|
+
/** Called with conversion warnings (unknown blocks, dropped marks) when the document loads or changes. */
|
|
360
|
+
onWarnings?: (warnings: ConversionWarning[]) => void;
|
|
361
|
+
/** Shows the formatting toolbar above the content. Defaults to true. */
|
|
362
|
+
toolbar?: boolean;
|
|
363
|
+
/** Shows a floating menu over selected text. Defaults to true. */
|
|
364
|
+
selectionMenu?: boolean;
|
|
365
|
+
/** Enables the "/" slash menu. Defaults to true. */
|
|
366
|
+
slashMenu?: boolean;
|
|
367
|
+
/** Connects the AI assistant menu to a provider. Without one the AI menu is hidden. */
|
|
368
|
+
aiProvider?: AiProvider;
|
|
369
|
+
className?: string;
|
|
370
|
+
/** Extra content placed after the toolbar, for example a save button. */
|
|
371
|
+
toolbarEnd?: ReactNode;
|
|
372
|
+
ref?: React.Ref<EditorApi>;
|
|
373
|
+
}
|
|
374
|
+
interface EditorViewProps {
|
|
375
|
+
value: EditorDocument;
|
|
376
|
+
blockRenderers?: BlockRenderers;
|
|
377
|
+
messages?: DeepPartial<Messages>;
|
|
378
|
+
locale?: string;
|
|
379
|
+
className?: string;
|
|
380
|
+
"aria-label"?: string;
|
|
381
|
+
"aria-labelledby"?: string;
|
|
382
|
+
/** Prefix for heading ids, so two views on a page do not clash. Defaults to `kit-`. */
|
|
383
|
+
idPrefix?: string;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* The block editor. Pass a document (`value` or `defaultValue`) in the kit's
|
|
388
|
+
* own JSON format and read the edited document back through `onChange` or
|
|
389
|
+
* the `ref`. The editing engine (Tiptap) stays behind this boundary.
|
|
390
|
+
*
|
|
391
|
+
* Until the engine mounts (on the server and during hydration) the component
|
|
392
|
+
* renders the document read-only, so the content is in the first HTML.
|
|
393
|
+
*/
|
|
394
|
+
declare function Editor(props: EditorProps): react.JSX.Element;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Renders a document read-only without the editor engine, so it works on the
|
|
398
|
+
* server and in lists of many documents. Embedded blocks render through
|
|
399
|
+
* `blockRenderers`, like in the editor.
|
|
400
|
+
*/
|
|
401
|
+
declare function EditorView({ value, blockRenderers, messages, locale, className, idPrefix, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, }: EditorViewProps): react.JSX.Element;
|
|
402
|
+
|
|
403
|
+
interface EditorToolbarProps {
|
|
404
|
+
editor: Editor$1 | null;
|
|
405
|
+
/** Opens the link dialog. Without it the link button is hidden. */
|
|
406
|
+
onOpenLink?: () => void;
|
|
407
|
+
/** Opens the image dialog. Without it the image button is hidden. */
|
|
408
|
+
onOpenImage?: () => void;
|
|
409
|
+
/** Opens the block actions menu. Without it the button is hidden. */
|
|
410
|
+
onOpenBlockMenu?: () => void;
|
|
411
|
+
/** Opens the AI menu. Without it the button is hidden. */
|
|
412
|
+
onOpenAi?: () => void;
|
|
413
|
+
/** Speaks a message through a status region. */
|
|
414
|
+
announce?: (message: string) => void;
|
|
415
|
+
/** Extra controls after the built-in ones. */
|
|
416
|
+
children?: ReactNode;
|
|
417
|
+
className?: string;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* The formatting toolbar: a WAI-ARIA toolbar with one tab stop, arrow keys
|
|
421
|
+
* between controls, `aria-pressed` on toggles and a tooltip on every control.
|
|
422
|
+
*/
|
|
423
|
+
declare function EditorToolbar({ editor, onOpenLink, onOpenImage, onOpenBlockMenu, onOpenAi, announce, children, className }: EditorToolbarProps): react.JSX.Element;
|
|
424
|
+
|
|
425
|
+
type AiStatus = "idle" | "running" | "preview" | "error";
|
|
426
|
+
interface UseAiAssistOptions {
|
|
427
|
+
provider: AiProvider | undefined;
|
|
428
|
+
editor: Editor$1 | null;
|
|
429
|
+
/** Called with a short message at each step, for a live region. */
|
|
430
|
+
announce?: (message: string) => void;
|
|
431
|
+
}
|
|
432
|
+
interface RunOptions {
|
|
433
|
+
/** Passed to the provider as `tone`; for `rewrite` it is the instruction. */
|
|
434
|
+
tone?: string;
|
|
435
|
+
}
|
|
436
|
+
interface UseAiAssist {
|
|
437
|
+
/** False without a provider; the AI menu stays hidden then. */
|
|
438
|
+
available: boolean;
|
|
439
|
+
status: AiStatus;
|
|
440
|
+
command: AiCommand | null;
|
|
441
|
+
/** The suggestion so far. Grows while `status` is `running`. */
|
|
442
|
+
preview: string;
|
|
443
|
+
error: string | null;
|
|
444
|
+
/** Streams a suggestion for the selection (or the text before the caret for `continue`). */
|
|
445
|
+
run: (command: AiCommand, options?: RunOptions) => Promise<void>;
|
|
446
|
+
/** Writes the suggestion into the document. */
|
|
447
|
+
accept: () => void;
|
|
448
|
+
/** Discards the suggestion. */
|
|
449
|
+
reject: () => void;
|
|
450
|
+
/** Stops a running request, keeping what arrived as the preview. */
|
|
451
|
+
cancel: () => void;
|
|
452
|
+
}
|
|
453
|
+
/** Plain text to Tiptap content: blank lines split paragraphs, single newlines become hard breaks. */
|
|
454
|
+
declare function textToContent(text: string): JSONContent[];
|
|
455
|
+
/**
|
|
456
|
+
* Connects the editor to an `AiProvider`. The kit calls no model itself: the
|
|
457
|
+
* provider streams text, the hook shows it as a preview, and nothing touches
|
|
458
|
+
* the document until `accept` is called.
|
|
459
|
+
*/
|
|
460
|
+
declare function useAiAssist({ provider, editor, announce }: UseAiAssistOptions): UseAiAssist;
|
|
461
|
+
|
|
462
|
+
interface AiAssistMenuProps {
|
|
463
|
+
assist: UseAiAssist;
|
|
464
|
+
editor: Editor$1;
|
|
465
|
+
onClose: () => void;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* A small panel for the AI assistant: pick an action, watch the suggestion
|
|
469
|
+
* stream in, then accept or reject it. Nothing is written to the document
|
|
470
|
+
* until Accept. It is not modal; Escape closes it and returns to the text.
|
|
471
|
+
*/
|
|
472
|
+
declare function AiAssistMenu({ assist, editor, onClose }: AiAssistMenuProps): react.JSX.Element;
|
|
473
|
+
|
|
474
|
+
interface EmbedPreviewProps {
|
|
475
|
+
type: EmbedType;
|
|
476
|
+
payload: unknown;
|
|
477
|
+
title: string;
|
|
478
|
+
}
|
|
479
|
+
/** The default look of a chart, diagram, data view or AI block: a summary card with the raw data. */
|
|
480
|
+
declare function EmbedPreview({ type, payload, title }: EmbedPreviewProps): react.JSX.Element;
|
|
481
|
+
|
|
482
|
+
/** What node views and menus need from the `Editor` that hosts them. */
|
|
483
|
+
interface EditorUi {
|
|
484
|
+
editable: boolean;
|
|
485
|
+
blockRenderers: BlockRenderers;
|
|
486
|
+
/** Speaks a message through the status live region. */
|
|
487
|
+
announce: (message: string) => void;
|
|
488
|
+
onEditBlock: EditBlockHandler | undefined;
|
|
489
|
+
onRequestBlock: RequestBlockHandler | undefined;
|
|
490
|
+
/** Opens the image dialog for the image at `pos`, or for a new image. */
|
|
491
|
+
openImageDialog: (pos?: number) => void;
|
|
492
|
+
/** Opens the link dialog for the selection. */
|
|
493
|
+
openLinkDialog: () => void;
|
|
494
|
+
/** Opens the block menu for the block at the selection. */
|
|
495
|
+
openBlockMenu: () => void;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
interface SlashItem {
|
|
499
|
+
kind: BlockKind;
|
|
500
|
+
group: SlashGroup;
|
|
501
|
+
name: string;
|
|
502
|
+
description: string;
|
|
503
|
+
}
|
|
504
|
+
/** The React side of the slash menu. The suggestion plugin calls into it. */
|
|
505
|
+
interface SlashBridge {
|
|
506
|
+
onStart: (props: SuggestionProps<SlashItem, SlashItem>) => void;
|
|
507
|
+
onUpdate: (props: SuggestionProps<SlashItem, SlashItem>) => void;
|
|
508
|
+
onKeyDown: (props: SuggestionKeyDownProps) => boolean;
|
|
509
|
+
onExit: () => void;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* What extensions read from the React tree at the moment they need it.
|
|
513
|
+
* Extensions are created once; the React component refreshes these getters on
|
|
514
|
+
* every render, so callbacks and messages are never stale.
|
|
515
|
+
*/
|
|
516
|
+
interface EditorRuntime {
|
|
517
|
+
ui: () => EditorUi;
|
|
518
|
+
translator: () => Translator;
|
|
519
|
+
placeholder: () => string;
|
|
520
|
+
slashEnabled: () => boolean;
|
|
521
|
+
slash: SlashBridge | null;
|
|
522
|
+
}
|
|
523
|
+
declare function createRuntime(): EditorRuntime;
|
|
524
|
+
|
|
525
|
+
interface CreateExtensionsOptions {
|
|
526
|
+
runtime: EditorRuntime;
|
|
527
|
+
/** Extensions from the `extensions` prop. */
|
|
528
|
+
extra?: Extensions;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* The editor schema. Node and mark names match `TIPTAP_NODES` and
|
|
532
|
+
* `TIPTAP_MARKS`, which the converters in the root entry read and write.
|
|
533
|
+
*/
|
|
534
|
+
declare function createExtensions({ runtime, extra }: CreateExtensionsOptions): Extensions;
|
|
535
|
+
|
|
536
|
+
/** All insertable blocks with localized names, ordered by group. */
|
|
537
|
+
declare function allSlashItems(messages: Messages): SlashItem[];
|
|
538
|
+
/**
|
|
539
|
+
* Filters and ranks slash menu items as the person types: names that start
|
|
540
|
+
* with the query first, then words that start with it, then substrings.
|
|
541
|
+
* Names, descriptions and keywords are all searched, in the active language.
|
|
542
|
+
*/
|
|
543
|
+
declare function filterSlashItems(query: string, messages: Messages, items?: readonly SlashItem[]): SlashItem[];
|
|
544
|
+
|
|
545
|
+
export { AiAssistMenu, BLOCK_KINDS, Editor, EditorToolbar, EditorView, EmbedPreview, allSlashItems, createExtensions, createRuntime, createTranslator, defaultMessages, filterSlashItems, formatMessage, mergeMessages, textToContent, useAiAssist, useMessages, useTranslator };
|
|
546
|
+
export type { AiAssistMenuProps, AiStatus, BlockKind, BlockMessage, BlockPayload, BlockRendererProps, BlockRenderers, CreateExtensionsOptions, DeepPartial, EditBlockHandler, EditorApi, EditorCommand, EditorProps, EditorRuntime, EditorToolbarProps, EditorViewProps, EmbedPayloads, EmbedPreviewProps, EmbedType, Messages, RequestBlockHandler, RunOptions, SelectionInfo, SlashGroup, SlashItem, Translator, UseAiAssist, UseAiAssistOptions };
|