@pixerate/editor-react 0.11.0 → 0.12.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/index.d.cts CHANGED
@@ -1,11 +1,12 @@
1
1
  import * as _tiptap_core from '@tiptap/core';
2
2
  import { Editor } from '@tiptap/core';
3
3
  import * as _pixerate_editor from '@pixerate/editor';
4
- import { Template, ColorGradient, RichTextPresetOptions, HistoryState, HistoryManager, Command, HistoryManagerOptions, SpreadsheetControllerOptions, SpreadsheetDocument, CellCoordinate, CellRange, SpreadsheetController, SpreadsheetColumn, SpreadsheetRow, SpreadsheetDataSource, CellData, EditorSlotsMap } from '@pixerate/editor';
5
- export { ColorGradient, Command, DirtyTracker, DirtyTrackerOptions, HistoryManager, HistoryManagerOptions, HistoryState, RichTextPresetOptions, Template, TemplateVersion, Token, TokenType, createDirtyTracker, createHistoryManager, defaultIsEqual } from '@pixerate/editor';
4
+ import { Template, ColorGradient, FileImportOptions, RichTextPresetOptions, RichClipboardOptions, HistoryState, HistoryManager, Command, HistoryManagerOptions, FileImportState, FileImportController, FileImportControllerOptions, PromptValues, OutlineSnapshot, OutlineHeading, SpreadsheetControllerOptions, CellRange, SpreadsheetDocument, CellCoordinate, SpreadsheetController, SpreadsheetColumn, SpreadsheetRow, SpreadsheetDataSource, CellData, SpreadsheetMenuItem, SpreadsheetRowGroup, SpreadsheetViewColumn, EditorSlotsMap, CommentStoreSnapshot, CommentStore, TrackChangesSnapshot, TrackedChange, ReviewAuthor } from '@pixerate/editor';
5
+ export { ColorGradient, Command, DirtyTracker, DirtyTrackerOptions, HistoryManager, HistoryManagerOptions, HistoryState, OutlineHeading, OutlineSnapshot, OutlineTreeItem, PromptDiagnostic, PromptValues, RichTextPresetOptions, Template, TemplateVersion, Token, TokenType, VariableFormField, createDirtyTracker, createHistoryManager, defaultIsEqual } from '@pixerate/editor';
6
6
  import { UseEditorOptions, EditorContentProps as EditorContentProps$1 } from '@tiptap/react';
7
+ import { ToolRegistry, AgentToolProvider } from '@pixerate/editor/agent';
7
8
  import * as React$1 from 'react';
8
- import React__default from 'react';
9
+ import React__default, { RefObject } from 'react';
9
10
  import { BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu';
10
11
  export { ImageEditor, ImageEditorProps, UseImageEditorReturn, useImageEditor } from './image-editor/index.cjs';
11
12
  import '@pixerate/editor/image-editor';
@@ -58,11 +59,28 @@ interface UsePromptEditorProps {
58
59
  jsonVariables?: string[];
59
60
  /** Animation speed for gradient decorations */
60
61
  speed?: number;
62
+ /**
63
+ * Import text from .md, .html, .txt and .rtf files dropped onto the editor
64
+ * (opt-in). Content is always inserted as plain text. Pasting keeps the
65
+ * plain-text paste handler, so pasted files are not imported.
66
+ */
67
+ fileImport?: Omit<FileImportOptions, "asPlainText"> | boolean;
61
68
  }
62
- declare function usePromptEditor({ content, onContentChange, templates, templateColorMap: userColorMap, isEditing, placeholder, className, onEscape, onKeyDown, onSelectionChange, onSlashCommandMatch, clearSlashCommand, slashCommandActive, onMilestone, containerId, jsonVariables, speed, }: UsePromptEditorProps): _tiptap_core.Editor | null;
69
+ declare function usePromptEditor({ content, onContentChange, templates, templateColorMap: userColorMap, isEditing, placeholder, className, onEscape, onKeyDown, onSelectionChange, onSlashCommandMatch, clearSlashCommand, slashCommandActive, onMilestone, containerId, jsonVariables, speed, fileImport, }: UsePromptEditorProps): _tiptap_core.Editor | null;
63
70
 
64
71
  interface UseRichEditorProps extends UseEditorOptions {
65
72
  richTextOptions?: RichTextPresetOptions;
73
+ /**
74
+ * Import .md, .html, .txt and .rtf files dropped or pasted into the editor
75
+ * at the drop position (opt-in; same as `richTextOptions.fileImport`).
76
+ */
77
+ fileImport?: FileImportOptions | boolean;
78
+ /**
79
+ * Copy/paste lossless ProseMirror slices between editors via the
80
+ * `application/x.pixerate.document+json` clipboard type (opt-in; same as
81
+ * `richTextOptions.richClipboard`).
82
+ */
83
+ richClipboard?: RichClipboardOptions | boolean;
66
84
  }
67
85
  /**
68
86
  * Hook to initialize a TipTap rich-text editor instance with pre-configured extensions.
@@ -163,6 +181,32 @@ interface HistoryShortcutsOptions {
163
181
  */
164
182
  declare function useHistoryShortcuts(manager: HistoryManager, options?: HistoryShortcutsOptions): void;
165
183
 
184
+ interface UseFileImportResult extends FileImportState {
185
+ /** Value for `<input type="file" accept={…}>`. */
186
+ accept: string;
187
+ /** Opens the browser file picker and imports the chosen files at the selection. */
188
+ openFilePicker: FileImportController["openFilePicker"];
189
+ /** Imports files (e.g. from your own `<input>` or drop zone) at `at` or the selection. */
190
+ importFiles: FileImportController["importFiles"];
191
+ }
192
+ /**
193
+ * Imports markdown, HTML, plain-text and RTF files (or anything registered
194
+ * with `registerImportAdapter` for the `document` target) into an editor.
195
+ * Pair it with `useEditor({ fileImport: true })` to also accept dropped files.
196
+ */
197
+ declare function useFileImport(editor: Editor | null | undefined, options?: FileImportControllerOptions): UseFileImportResult;
198
+
199
+ /**
200
+ * Registers a tool provider with a `ToolRegistry` while the component is
201
+ * mounted and unregisters it on unmount (the registry then announces the
202
+ * change through `onListChanged`).
203
+ *
204
+ * Memoize the provider (e.g. `useMemo(() => createRichTextToolProvider(editor,
205
+ * { id }), [editor])`): a new provider object re-registers it. Pass `null`
206
+ * while it isn't ready.
207
+ */
208
+ declare function useAgentToolProvider(registry: ToolRegistry | null | undefined, provider: AgentToolProvider | null | undefined): void;
209
+
166
210
  interface EditorContentProps extends EditorContentProps$1 {
167
211
  className?: string;
168
212
  }
@@ -188,6 +232,13 @@ interface TemplateRendererProps {
188
232
  templateColorMap?: Map<string, ColorGradient>;
189
233
  /** Whether to resolve nested templates recursively before displaying */
190
234
  resolve?: boolean;
235
+ /** Template version bindings used when `resolve` is set */
236
+ bindings?: Record<string, string>;
237
+ /**
238
+ * Variable values. When set, variables show their value (or default),
239
+ * sections whose condition fails are hidden, and section tags are dropped.
240
+ */
241
+ values?: PromptValues;
191
242
  /** Custom class name for the wrapper */
192
243
  className?: string;
193
244
  /** Click callback for template badges */
@@ -197,7 +248,109 @@ interface TemplateRendererProps {
197
248
  }
198
249
  declare const TemplateRenderer: React__default.FC<TemplateRendererProps>;
199
250
 
251
+ interface VariableFormProps {
252
+ /** Prompt whose variables become form fields */
253
+ content: string;
254
+ /** Templates searched recursively for further variables */
255
+ templates?: Template[];
256
+ /** Template version bindings */
257
+ bindings?: Record<string, string>;
258
+ /** Entered text per variable (controlled). Omit to let the form keep its own state. */
259
+ values?: Record<string, string>;
260
+ /** Initial entered text when uncontrolled */
261
+ defaultValues?: Record<string, string>;
262
+ /**
263
+ * Called on every edit with the values to resolve with (blank fields
264
+ * dropped so defaults apply) and the raw entered text.
265
+ */
266
+ onChange?: (values: PromptValues, entered: Record<string, string>) => void;
267
+ /** Custom class name for the wrapper */
268
+ className?: string;
269
+ }
270
+ /**
271
+ * Renders one input per prompt variable: labelled with its description,
272
+ * using its default as the placeholder. Variables only used by `{?name}`
273
+ * conditions render as checkboxes.
274
+ */
275
+ declare const VariableForm: React__default.FC<VariableFormProps>;
276
+
277
+ /**
278
+ * Subscribes to an editor's heading outline. Returns the headings (flat and
279
+ * nested) and the id of the heading whose section contains the selection.
280
+ * Re-renders only when the outline or the active heading changes.
281
+ *
282
+ * Install the `Outline` extension (`richTextOptions: { outline: true }`) for
283
+ * stable heading ids; without it, headings are still listed.
284
+ */
285
+ declare function useOutline(editor: Editor | null | undefined): OutlineSnapshot;
286
+
287
+ interface OutlinePanelProps {
288
+ editor: Editor | null;
289
+ /** Heading shown above the list. Pass `null` to hide it. */
290
+ title?: React__default.ReactNode;
291
+ /** Content shown when the document has no headings. */
292
+ emptyState?: React__default.ReactNode;
293
+ /** Deepest heading level listed. Defaults to 6. */
294
+ maxLevel?: number;
295
+ /** Whether clicking an entry focuses the editor. Defaults to `true`. */
296
+ focusOnNavigate?: boolean;
297
+ /** Custom class name for the wrapper. */
298
+ className?: string;
299
+ /** Class name for each entry button. */
300
+ itemClassName?: string;
301
+ /** Class name added to the entry of the section containing the selection. */
302
+ activeItemClassName?: string;
303
+ /** Called after navigating to a heading. */
304
+ onNavigate?: (heading: OutlineHeading) => void;
305
+ }
306
+ /**
307
+ * Navigation sidebar listing the document's headings (Word's Navigation pane).
308
+ * Clicking an entry moves the caret to that heading; the entry for the
309
+ * section containing the selection is highlighted.
310
+ */
311
+ declare const OutlinePanel: React__default.FC<OutlinePanelProps>;
312
+
200
313
  declare function useSpreadsheetEditor(options?: SpreadsheetControllerOptions): {
314
+ viewModel: _pixerate_editor.SpreadsheetViewModel;
315
+ undo: () => void;
316
+ redo: () => void;
317
+ sortRows: (keys: _pixerate_editor.SortKey[], options?: {
318
+ range?: CellRange | null;
319
+ }) => boolean;
320
+ getFilterState: () => _pixerate_editor.SpreadsheetFilterState;
321
+ setFilterRules: (rules: _pixerate_editor.NewFilterRule[]) => void;
322
+ addFilterRule: (rule: _pixerate_editor.NewFilterRule) => string;
323
+ updateFilterRule: (ruleId: string, changes: Partial<Omit<_pixerate_editor.FilterRule, "id">>) => void;
324
+ removeFilterRule: (ruleId: string) => void;
325
+ clearFilters: () => void;
326
+ setFiltersEnabled: (enabled: boolean) => void;
327
+ toggleFilters: () => void;
328
+ setHeaderRowCount: (count: number) => void;
329
+ setFooterRowCount: (count: number) => void;
330
+ setHeaderColumnCount: (count: number) => void;
331
+ setFrozenRowCount: (count: number) => void;
332
+ setFrozenColumnCount: (count: number) => void;
333
+ hideRows: (indices: number[]) => void;
334
+ unhideRows: (indices: number[]) => void;
335
+ hideColumns: (indices: number[]) => void;
336
+ unhideColumns: (indices: number[]) => void;
337
+ unhideAll: () => void;
338
+ getMerges: () => CellRange[];
339
+ getMergeAt: (row: number, col: number) => CellRange | null;
340
+ mergeCells: (range?: CellRange | null) => boolean;
341
+ unmergeCells: (range?: CellRange | null) => boolean;
342
+ autofill: (source: CellRange, target: CellRange) => boolean;
343
+ groupRowsBy: (colId: string, summaries?: _pixerate_editor.GroupSummary[]) => void;
344
+ ungroupRows: () => void;
345
+ setGroupSummary: (colId: string, aggregate: _pixerate_editor.GroupAggregate | null) => void;
346
+ setGroupCollapsed: (key: string, collapsed: boolean) => void;
347
+ toggleGroupCollapsed: (key: string) => void;
348
+ getGroups: () => _pixerate_editor.SpreadsheetRowGroup[];
349
+ transposeRange: (range?: CellRange | null) => boolean;
350
+ exportToCsv: (options?: _pixerate_editor.CsvExportOptions) => string;
351
+ importFromCsv: (csv: string, options?: _pixerate_editor.CsvImportOptions) => void;
352
+ copyToClipboardData: (range?: CellRange | null) => _pixerate_editor.SpreadsheetClipboardData;
353
+ pasteClipboardData: (source: _pixerate_editor.SpreadsheetClipboardSource, target?: _pixerate_editor.CellPosition) => boolean;
201
354
  document: SpreadsheetDocument;
202
355
  activeCell: CellCoordinate | null;
203
356
  selectedRange: CellRange | null;
@@ -226,8 +379,6 @@ declare function useSpreadsheetEditor(options?: SpreadsheetControllerOptions): {
226
379
  recalculateAll: () => void;
227
380
  exportToTsv: (range?: CellRange | null) => string;
228
381
  importFromTsv: (data: string) => void;
229
- undo: () => void;
230
- redo: () => void;
231
382
  };
232
383
 
233
384
  interface SpreadsheetEditorProps {
@@ -244,6 +395,75 @@ interface SpreadsheetEditorProps {
244
395
  }
245
396
  declare const SpreadsheetEditor: React__default.FC<SpreadsheetEditorProps>;
246
397
 
398
+ interface SpreadsheetContextMenuProps {
399
+ items: SpreadsheetMenuItem[];
400
+ x: number;
401
+ y: number;
402
+ onClose: () => void;
403
+ }
404
+ /** The table context menu (sort, filter, freeze, hide, merge, categories, transpose). */
405
+ declare const SpreadsheetContextMenu: React__default.FC<SpreadsheetContextMenuProps>;
406
+
407
+ interface SpreadsheetGroupRowProps {
408
+ group: SpreadsheetRowGroup;
409
+ columns: SpreadsheetViewColumn[];
410
+ /** Column the rows are grouped by: shows the group label and toggle. */
411
+ groupColId: string;
412
+ onToggle: (key: string) => void;
413
+ /** Render a trailing cell for the "add column" column. */
414
+ trailingCell?: boolean;
415
+ }
416
+ /** A category header row: collapse toggle, label, row count and per-column summaries. */
417
+ declare const SpreadsheetGroupRow: React__default.FC<SpreadsheetGroupRowProps>;
418
+
419
+ type SpreadsheetState = ReturnType<typeof useSpreadsheetEditor>;
420
+ /**
421
+ * Copy and paste for the grid. Copy writes TSV, an HTML table and the
422
+ * lossless `application/x.pixerate.spreadsheet+json` format; paste prefers
423
+ * that format, then HTML, then TSV.
424
+ *
425
+ * The listeners are on `document`: with no text selection the browser fires
426
+ * `copy`/`paste` at `<body>`, not at the focused grid. Text inputs inside the
427
+ * grid keep native copy/paste.
428
+ */
429
+ declare function useSpreadsheetClipboard(gridRef: RefObject<HTMLElement | null>, state: SpreadsheetState, readOnly: boolean): {
430
+ copyShortcutFallback: () => void;
431
+ };
432
+ /**
433
+ * Fill handle dragging: press on the handle, move over cells, release to
434
+ * autofill from the selection into the dragged range (one undo step).
435
+ */
436
+ declare function useFillHandle(state: SpreadsheetState): {
437
+ fillTarget: CellRange | null;
438
+ isFilling: boolean;
439
+ startFill: (e: {
440
+ preventDefault(): void;
441
+ stopPropagation(): void;
442
+ }) => void;
443
+ extendFill: (row: number, col: number) => void;
444
+ };
445
+
446
+ interface FormulaHintsProps {
447
+ /** The input being edited (a cell editor or the formula bar). */
448
+ inputRef: React__default.RefObject<HTMLInputElement | null>;
449
+ /** The input's current value. */
450
+ value: string;
451
+ /** Called with the new value when a suggestion is accepted. */
452
+ onAccept: (value: string) => void;
453
+ /** Maximum number of function suggestions (default 8). */
454
+ limit?: number;
455
+ }
456
+ /**
457
+ * Formula autocomplete for an input: while the value starts with `=`, lists
458
+ * functions matching the name at the caret (name, signature, description) and,
459
+ * inside a call, shows the signature with the current argument highlighted.
460
+ *
461
+ * Keys are handled on the input itself, before the grid sees them: ArrowUp /
462
+ * ArrowDown move the selection, Tab accepts it, Escape closes the list.
463
+ * Enter is left alone so it still commits the cell.
464
+ */
465
+ declare const FormulaHints: React__default.FC<FormulaHintsProps>;
466
+
247
467
  interface EditorSlotsProviderProps {
248
468
  slots?: Partial<EditorSlotsMap>;
249
469
  children: React__default.ReactNode;
@@ -257,4 +477,69 @@ declare function EditorSlotsProvider({ slots, children }: EditorSlotsProviderPro
257
477
  */
258
478
  declare function useEditorSlots(): EditorSlotsMap;
259
479
 
260
- export { BubbleMenu, type BubbleMenuProps, EditorContent, type EditorContentProps, EditorSlotsProvider, type EditorSlotsProviderProps, type HistoryShortcutsOptions, SpreadsheetEditor, type SpreadsheetEditorProps, TemplateRenderer, type TemplateRendererProps, type UseDismissGuardOptions, type UseDismissGuardReturn, type UseHistoryResult, type UseNavigationGuardOptions, type UseNavigationGuardReturn, type UsePromptEditorProps, type UseRichEditorProps, useDismissGuard, useEditor, useEditorSlots, useHistory, useHistoryShortcuts, useNavigationGuard, usePromptEditor, useSpreadsheetEditor };
480
+ interface UseCommentsResult extends CommentStoreSnapshot {
481
+ store: CommentStore | null;
482
+ }
483
+ /**
484
+ * Subscribes to a comment store: pass the store itself, or an editor using
485
+ * the `Comments` extension (`null` while the editor is being created).
486
+ */
487
+ declare function useComments(source: Editor | CommentStore | null | undefined): UseCommentsResult;
488
+ interface UseTrackChangesResult extends TrackChangesSnapshot {
489
+ currentChange: TrackedChange | null;
490
+ setEnabled: (enabled: boolean) => void;
491
+ toggle: () => void;
492
+ accept: (id: string) => void;
493
+ reject: (id: string) => void;
494
+ acceptAll: () => void;
495
+ rejectAll: () => void;
496
+ next: () => void;
497
+ previous: () => void;
498
+ }
499
+ /**
500
+ * Subscribes to the tracked-change state of an editor using the
501
+ * `TrackChanges` extension and exposes its commands.
502
+ */
503
+ declare function useTrackChanges(editor: Editor | null | undefined): UseTrackChangesResult;
504
+
505
+ interface CommentsPanelProps {
506
+ editor: Editor | null;
507
+ /** Defaults to the store of the editor's `Comments` extension. */
508
+ store?: CommentStore;
509
+ /** Author of replies. Defaults to the `Comments` extension's author. */
510
+ author?: ReviewAuthor;
511
+ /** Initially show resolved threads. */
512
+ showResolved?: boolean;
513
+ className?: string;
514
+ formatTime?: (timestamp: number) => string;
515
+ emptyMessage?: string;
516
+ }
517
+ /**
518
+ * Lists comment threads with reply, resolve and delete actions. Clicking a
519
+ * thread selects its text in the editor. Threads with an empty body are
520
+ * drafts (e.g. created by `CommentButton`) and show a compose box.
521
+ */
522
+ declare const CommentsPanel: React__default.FC<CommentsPanelProps>;
523
+
524
+ interface ReviewToolbarProps {
525
+ editor: Editor | null;
526
+ className?: string;
527
+ }
528
+ /**
529
+ * Toolbar for tracked changes: toggle tracking, step through changes, and
530
+ * accept or reject the current change or all changes.
531
+ */
532
+ declare const ReviewToolbar: React__default.FC<ReviewToolbarProps>;
533
+
534
+ interface CommentButtonProps {
535
+ editor: Editor | null;
536
+ className?: string;
537
+ children?: React__default.ReactNode;
538
+ }
539
+ /**
540
+ * Adds a draft comment on the selection; drop it into a `BubbleMenu`. The
541
+ * draft is completed in `CommentsPanel`.
542
+ */
543
+ declare const CommentButton: React__default.FC<CommentButtonProps>;
544
+
545
+ export { BubbleMenu, type BubbleMenuProps, CommentButton, type CommentButtonProps, CommentsPanel, type CommentsPanelProps, EditorContent, type EditorContentProps, EditorSlotsProvider, type EditorSlotsProviderProps, FormulaHints, type FormulaHintsProps, type HistoryShortcutsOptions, OutlinePanel, type OutlinePanelProps, ReviewToolbar, type ReviewToolbarProps, SpreadsheetContextMenu, type SpreadsheetContextMenuProps, SpreadsheetEditor, type SpreadsheetEditorProps, SpreadsheetGroupRow, type SpreadsheetGroupRowProps, TemplateRenderer, type TemplateRendererProps, type UseCommentsResult, type UseDismissGuardOptions, type UseDismissGuardReturn, type UseFileImportResult, type UseHistoryResult, type UseNavigationGuardOptions, type UseNavigationGuardReturn, type UsePromptEditorProps, type UseRichEditorProps, type UseTrackChangesResult, VariableForm, type VariableFormProps, useAgentToolProvider, useComments, useDismissGuard, useEditor, useEditorSlots, useFileImport, useFillHandle, useHistory, useHistoryShortcuts, useNavigationGuard, useOutline, usePromptEditor, useSpreadsheetClipboard, useSpreadsheetEditor, useTrackChanges };