@pixerate/editor 0.18.0 → 0.20.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.
Files changed (118) hide show
  1. package/README.md +91 -2
  2. package/dist/agent/index.cjs +625 -2
  3. package/dist/agent/index.cjs.map +1 -1
  4. package/dist/agent/index.d.cts +286 -2
  5. package/dist/agent/index.d.ts +286 -2
  6. package/dist/agent/index.js +624 -1
  7. package/dist/agent/index.js.map +1 -1
  8. package/dist/canvas/index.cjs +1240 -22
  9. package/dist/canvas/index.cjs.map +1 -1
  10. package/dist/canvas/index.d.cts +515 -3
  11. package/dist/canvas/index.d.ts +515 -3
  12. package/dist/canvas/index.js +1219 -1
  13. package/dist/canvas/index.js.map +1 -1
  14. package/dist/chunk-3TYMNULT.js +1367 -0
  15. package/dist/chunk-3TYMNULT.js.map +1 -0
  16. package/dist/chunk-4QPLEUL2.cjs +4480 -0
  17. package/dist/chunk-4QPLEUL2.cjs.map +1 -0
  18. package/dist/chunk-4SUNJZWB.cjs +553 -0
  19. package/dist/chunk-4SUNJZWB.cjs.map +1 -0
  20. package/dist/chunk-A7DKIA72.js +2657 -0
  21. package/dist/chunk-A7DKIA72.js.map +1 -0
  22. package/dist/chunk-AXV2ZW34.cjs +118 -0
  23. package/dist/chunk-AXV2ZW34.cjs.map +1 -0
  24. package/dist/chunk-B2ZRLN4S.js +118 -0
  25. package/dist/chunk-B2ZRLN4S.js.map +1 -0
  26. package/dist/chunk-CYFJCKC4.js +4480 -0
  27. package/dist/chunk-CYFJCKC4.js.map +1 -0
  28. package/dist/chunk-GVW4P7BG.js +2706 -0
  29. package/dist/chunk-GVW4P7BG.js.map +1 -0
  30. package/dist/chunk-JACER6TE.cjs +1 -0
  31. package/dist/chunk-JACER6TE.cjs.map +1 -0
  32. package/dist/chunk-JYRIOFEN.cjs +2657 -0
  33. package/dist/chunk-JYRIOFEN.cjs.map +1 -0
  34. package/dist/chunk-KYRZDWM4.js +299 -0
  35. package/dist/chunk-KYRZDWM4.js.map +1 -0
  36. package/dist/chunk-LA7PEGU3.cjs +299 -0
  37. package/dist/chunk-LA7PEGU3.cjs.map +1 -0
  38. package/dist/chunk-N7FG6CBO.js +1 -0
  39. package/dist/chunk-N7FG6CBO.js.map +1 -0
  40. package/dist/chunk-OYXSKQFR.js +553 -0
  41. package/dist/chunk-OYXSKQFR.js.map +1 -0
  42. package/dist/chunk-TVRC4KVT.cjs +1367 -0
  43. package/dist/chunk-TVRC4KVT.cjs.map +1 -0
  44. package/dist/chunk-U6NDQFOK.cjs +2706 -0
  45. package/dist/chunk-U6NDQFOK.cjs.map +1 -0
  46. package/dist/controller-OUdxPY-X.d.cts +754 -0
  47. package/dist/controller-OUdxPY-X.d.ts +754 -0
  48. package/dist/extensions/index.cjs +144 -3
  49. package/dist/extensions/index.cjs.map +1 -1
  50. package/dist/extensions/index.d.cts +9 -144
  51. package/dist/extensions/index.d.ts +9 -144
  52. package/dist/extensions/index.js +145 -4
  53. package/dist/grammar/index.cjs +31 -3
  54. package/dist/grammar/index.cjs.map +1 -1
  55. package/dist/grammar/index.d.cts +239 -19
  56. package/dist/grammar/index.d.ts +239 -19
  57. package/dist/grammar/index.js +31 -3
  58. package/dist/history/index.d.cts +2 -41
  59. package/dist/history/index.d.ts +2 -41
  60. package/dist/image-editor/index.cjs +732 -497
  61. package/dist/image-editor/index.cjs.map +1 -1
  62. package/dist/image-editor/index.d.cts +105 -9
  63. package/dist/image-editor/index.d.ts +105 -9
  64. package/dist/image-editor/index.js +721 -486
  65. package/dist/image-editor/index.js.map +1 -1
  66. package/dist/index-Ng1pG7JE.d.ts +899 -0
  67. package/dist/index-k3mFbPx_.d.cts +899 -0
  68. package/dist/index.cjs +457 -20
  69. package/dist/index.cjs.map +1 -1
  70. package/dist/index.d.cts +99 -12
  71. package/dist/index.d.ts +99 -12
  72. package/dist/index.js +457 -20
  73. package/dist/index.js.map +1 -1
  74. package/dist/registry-iAHbqkYt.d.cts +128 -0
  75. package/dist/registry-iAHbqkYt.d.ts +128 -0
  76. package/dist/serializers/index.cjs +26 -3
  77. package/dist/serializers/index.cjs.map +1 -1
  78. package/dist/serializers/index.d.cts +119 -6
  79. package/dist/serializers/index.d.ts +119 -6
  80. package/dist/serializers/index.js +24 -1
  81. package/dist/spreadsheet/index.cjs +122 -2
  82. package/dist/spreadsheet/index.cjs.map +1 -1
  83. package/dist/spreadsheet/index.d.cts +371 -313
  84. package/dist/spreadsheet/index.d.ts +371 -313
  85. package/dist/spreadsheet/index.js +127 -7
  86. package/dist/tokens-CyLZmIei.d.cts +76 -0
  87. package/dist/tokens-CyLZmIei.d.ts +76 -0
  88. package/dist/track-changes-G8JcWB8b.d.cts +306 -0
  89. package/dist/track-changes-G8JcWB8b.d.ts +306 -0
  90. package/dist/types-BZgcDsC5.d.cts +42 -0
  91. package/dist/types-BZgcDsC5.d.ts +42 -0
  92. package/dist/{types-JV3S8VeR.d.cts → types-DMe0vFB1.d.cts} +1 -1
  93. package/dist/{types-JV3S8VeR.d.ts → types-DMe0vFB1.d.ts} +1 -1
  94. package/package.json +1 -1
  95. package/dist/chunk-7FWEWE6T.js +0 -1888
  96. package/dist/chunk-7FWEWE6T.js.map +0 -1
  97. package/dist/chunk-AIZUKWTL.js +0 -1715
  98. package/dist/chunk-AIZUKWTL.js.map +0 -1
  99. package/dist/chunk-GLSIZKOX.js +0 -17
  100. package/dist/chunk-GLSIZKOX.js.map +0 -1
  101. package/dist/chunk-LDES3EOS.cjs +0 -1888
  102. package/dist/chunk-LDES3EOS.cjs.map +0 -1
  103. package/dist/chunk-LLUAKTLW.cjs +0 -532
  104. package/dist/chunk-LLUAKTLW.cjs.map +0 -1
  105. package/dist/chunk-MPPXH7U5.cjs +0 -336
  106. package/dist/chunk-MPPXH7U5.cjs.map +0 -1
  107. package/dist/chunk-O7LOPQMH.js +0 -336
  108. package/dist/chunk-O7LOPQMH.js.map +0 -1
  109. package/dist/chunk-QGVMBCT5.js +0 -532
  110. package/dist/chunk-QGVMBCT5.js.map +0 -1
  111. package/dist/chunk-SEDR75VH.cjs +0 -17
  112. package/dist/chunk-SEDR75VH.cjs.map +0 -1
  113. package/dist/chunk-YQCI4CCN.cjs +0 -1715
  114. package/dist/chunk-YQCI4CCN.cjs.map +0 -1
  115. package/dist/mention-Dcevh3ff.d.cts +0 -32
  116. package/dist/mention-Dcevh3ff.d.ts +0 -32
  117. package/dist/tokens-7kRTEtPb.d.cts +0 -39
  118. package/dist/tokens-7kRTEtPb.d.ts +0 -39
package/README.md CHANGED
@@ -86,6 +86,95 @@ controller.isDirty(); // true
86
86
 
87
87
  Extensions (`@pixerate/editor/extensions`): `createRichTextPreset`, `GradientText`, `TemplateSuggestions`, `SlashCommands`, `LoadingNode`, `Mention` / `createMentionExtension`, `Image`, `Markdown`, `SmilieReplacer`, `ColorHighlighter`, `FontSize`.
88
88
 
89
+ ## Comments and tracked changes
90
+
91
+ ```ts
92
+ import { Comments, CommentStore, TrackChanges, getTrackedChanges } from "@pixerate/editor";
93
+
94
+ const me = { id: "u1", name: "Ada" };
95
+ const store = new CommentStore({ threads: savedJson }); // persistence is up to you
96
+ const editor = new Editor({
97
+ extensions: [
98
+ ...createRichTextPreset(),
99
+ Comments.configure({ store, author: me }),
100
+ TrackChanges.configure({ author: me, enabled: false }),
101
+ ],
102
+ });
103
+
104
+ editor.commands.addComment({ body: "Is this right?" }); // on the selection
105
+ editor.commands.resolveComment(id); // also deleteComment, setActiveComment, focusComment
106
+ store.subscribe((snapshot) => save(store.toJSON()));
107
+
108
+ editor.commands.toggleTrackChanges();
109
+ getTrackedChanges(editor); // [{ id, type: "insertion" | "deletion", author, from, to, text, … }]
110
+ editor.commands.acceptChange(id); // rejectChange, acceptAllChanges, rejectAllChanges: one undo step each
111
+ ```
112
+
113
+ - **Comments** are `comment` marks holding a thread id; thread content lives in the headless `CommentStore` (`subscribe` / `getSnapshot`, cached snapshots, `toJSON` / `load`). Threads whose text is deleted are flagged `orphaned` and re-attach on undo.
114
+ - **Track changes** marks typed and pasted text with an `insertion` mark and keeps deleted text with a `deletion` mark (struck through). Deleting your own insertion really deletes it. IME composition is tracked once it ends. Not tracked: formatting-only changes, block-structure changes (splitting/joining paragraphs, lists) and edits inside code blocks. Set the `TRACK_CHANGES_SKIP_META` transaction meta to apply a change untracked (e.g. `setContent`).
115
+ - **Serializers** render tracked content as if all changes were accepted: `getEditorText`, `htmlToPlainText` and `getEditorMarkdown` drop deleted text by default. Pass `{ trackedChanges: "original" }` (as if rejected) or `"all"` (both). `resolveTrackedChanges(doc, view)` returns a resolved document. TipTap's own `editor.getText()` still includes deleted text.
116
+ - Both extensions are also available as `createRichTextPreset({ comments: true, trackChanges: true })`. Mark styles use Tailwind classes; override them via `commentClass` / `activeClass` and `insertionHTMLAttributes` / `deletionHTMLAttributes`.
117
+
118
+ ## File import and rich clipboard
119
+
120
+ An import adapter registry maps file types (MIME types and extensions) to converters. Built-in `document` adapters cover markdown (`.md`, `.markdown`, `.mdown`, `.mkdn`, `.mkd`, `.Rmd`, `.md.txt`), HTML (sanitized with the same allowlist as markdown), plain text (`.txt`) and RTF (best-effort text extraction). The longest matching extension wins, then exact MIME types, then `priority`, then the most recent registration.
121
+
122
+ ```ts
123
+ import { importFile, registerImportAdapter, getImportAccept } from "@pixerate/editor";
124
+
125
+ const { adapterId, result } = await importFile(file); // result: { html, text }
126
+ input.accept = getImportAccept("document");
127
+
128
+ // DOCX, PDF, zipped exports or CSV → spreadsheet are pluggable:
129
+ registerImportAdapter({
130
+ id: "docx",
131
+ label: "Word",
132
+ mimeTypes: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
133
+ extensions: [".docx"],
134
+ target: "document",
135
+ async import(_file, ctx) {
136
+ const html = await myDocxToHtml(await ctx.readArrayBuffer());
137
+ return { html, text: htmlToPlainText(html) };
138
+ },
139
+ });
140
+ ```
141
+
142
+ `FileImport` (or `createRichTextPreset({ fileImport: true })`) inserts dropped or pasted files at the drop position, and `FileImportController` / `pickImportFiles` back file-picker buttons. `RichClipboard` (or `richClipboard: true`) also writes copied content as `application/x.pixerate.document+json` (ProseMirror slice JSON plus a schema signature) and prefers it on paste when the schemas match, falling back to HTML / plain text. Both are opt-in, and `EditorController` keeps them on plain text in `plainTextMode`.
143
+
144
+ ## Agent tool registry
145
+
146
+ `ToolRegistry` (`@pixerate/editor/agent`) collects MCP-shaped tools from live providers, for example one per mounted editor or spreadsheet. `listTools()` and `callTool()` return MCP `tools/list` / `tools/call` result shapes, arguments are validated against each tool's `inputSchema`, and `onListChanged` fires (coalesced) when providers come and go. Colliding names are namespaced as `<providerId>__<name>`.
147
+
148
+ ```ts
149
+ import { ToolRegistry, createRichTextToolProvider, createSpreadsheetToolProvider } from "@pixerate/editor/agent";
150
+
151
+ const registry = new ToolRegistry();
152
+ const unregister = registry.register(createRichTextToolProvider(controller, { id: "doc" }));
153
+ registry.register(createSpreadsheetToolProvider(sheet, { id: "sheet", namespace: "sheet" }));
154
+ registry.onListChanged((tools) => server.sendToolListChanged());
155
+
156
+ await registry.callTool("insert_text", { text: "Hello" }); // { content: [...], structuredContent }
157
+ ```
158
+
159
+ `createEditorMcpToolProvider` exposes the static tools (`get_editor_state`, `edit_canvas`, `edit_prompt`, `view_editor`) through the registry, and `planToolCall` turns any tool call into planner steps (`step:tool_call` for registry tools).
160
+
161
+ ### Document structure and autocorrect
162
+
163
+ Opt-in preset options add Word/Pages-style document structure:
164
+
165
+ ```ts
166
+ const extensions = createRichTextPreset({
167
+ outline: true, // stable heading ids + live outline (getOutline, createOutlineStore)
168
+ tableOfContents: true, // editor.commands.insertTableOfContents(); markdown `[[toc]]`
169
+ footnotes: true, // editor.commands.insertFootnote({ content }); markdown `[^1]`
170
+ bookmarks: true, // editor.commands.setBookmark({ name })
171
+ crossReferences: true, // editor.commands.insertCrossReference({ targetType, targetId })
172
+ autocorrect: { exceptions: [...DEFAULT_AUTOCORRECT_EXCEPTIONS, "approx."] },
173
+ });
174
+ ```
175
+
176
+ `Autocorrect` takes a `rules` list (`defaultAutocorrectRules`, or compose `smartQuoteRules`, `symbolRules`, `fractionRules`, `capitalizeSentenceRules`, `twoInitialCapitalsRules`, `smilieAutocorrectRules` and your own `{ id, find, replace }` rules). Undo right after a correction restores what was typed; nothing is corrected in code or inside prompt tokens. It replaces the Typography extension in the preset. `getDocumentStructureCommandItems(editor, query)` returns ready-made slash-menu/toolbar items for the installed extensions.
177
+
89
178
  ## Other modules
90
179
 
91
180
  Each module is also available as a subpath import:
@@ -96,10 +185,10 @@ Each module is also available as a subpath import:
96
185
  | `@pixerate/editor/serializers` | Plain text, markdown and mention serializers |
97
186
  | `@pixerate/editor/extensions` | Headless TipTap extensions |
98
187
  | `@pixerate/editor/history` | `HistoryManager`: a command-pattern undo/redo stack |
99
- | `@pixerate/editor/spreadsheet` | `SpreadsheetController`, formula parser/evaluator and dependency graph |
188
+ | `@pixerate/editor/spreadsheet` | `SpreadsheetController`, formula parser/evaluator and dependency graph, formula function registry (`registerFormulaFunction`, `listFormulaFunctions`, `searchFormulaFunctions`, `getFormulaSignature`) and autocomplete helpers (`getFormulaHints`, `applyFormulaSuggestion`) |
100
189
  | `@pixerate/editor/image-editor` | `ImageEditorController` and Canvas 2D renderer: crop, adjustments, annotations, depth masks and AI hooks. Needs a DOM/canvas environment. |
101
190
  | `@pixerate/editor/canvas` | Node-graph layout (dagre), placement, trajectories, displacement, clipboard and streaming layout helpers |
102
- | `@pixerate/editor/agent` | MCP tool schemas and a planner for agent-driven canvas edits |
191
+ | `@pixerate/editor/agent` | MCP tool schemas, a planner for agent-driven canvas edits, and the dynamic `ToolRegistry` with editor/spreadsheet tool providers |
103
192
 
104
193
  The root entry (`@pixerate/editor`) re-exports everything, including TipTap. In backends, import from `@pixerate/editor/grammar` to keep the dependency graph small.
105
194