@pixerate/editor 0.47.0 → 0.48.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 (76) hide show
  1. package/dist/agent/index.cjs +246 -29
  2. package/dist/agent/index.cjs.map +1 -1
  3. package/dist/agent/index.d.cts +18 -6
  4. package/dist/agent/index.d.ts +18 -6
  5. package/dist/agent/index.js +226 -9
  6. package/dist/agent/index.js.map +1 -1
  7. package/dist/{builtins-xs7rK6ys.d.cts → builtins-1kqwLUnb.d.cts} +1 -1
  8. package/dist/{builtins-D2nMtw2W.d.ts → builtins-BKYlHH1s.d.ts} +1 -1
  9. package/dist/chart/index.cjs +214 -3541
  10. package/dist/chart/index.cjs.map +1 -1
  11. package/dist/chart/index.d.cts +4 -494
  12. package/dist/chart/index.d.ts +4 -494
  13. package/dist/chart/index.js +135 -3462
  14. package/dist/chart/index.js.map +1 -1
  15. package/dist/{chunk-5VXI5GED.js → chunk-2CJ3LPYQ.js} +3 -3
  16. package/dist/{chunk-ZFBBVGCI.js → chunk-EKYHKQPG.js} +243 -243
  17. package/dist/{chunk-ZFBBVGCI.js.map → chunk-EKYHKQPG.js.map} +1 -1
  18. package/dist/chunk-HXUL3LS7.js +113 -0
  19. package/dist/chunk-HXUL3LS7.js.map +1 -0
  20. package/dist/{chunk-REAGGLXS.js → chunk-JQ3BB3E6.js} +2 -2
  21. package/dist/chunk-LTUM52X6.js +4074 -0
  22. package/dist/chunk-LTUM52X6.js.map +1 -0
  23. package/dist/{chunk-J3R2OWOE.cjs → chunk-MUCYWI6W.cjs} +608 -15
  24. package/dist/chunk-MUCYWI6W.cjs.map +1 -0
  25. package/dist/chunk-PIMCHMZE.cjs +521 -0
  26. package/dist/chunk-PIMCHMZE.cjs.map +1 -0
  27. package/dist/{chunk-TK2XZK6Z.js → chunk-PKBWLEL7.js} +594 -1
  28. package/dist/chunk-PKBWLEL7.js.map +1 -0
  29. package/dist/chunk-PRSJJZBS.cjs +4074 -0
  30. package/dist/chunk-PRSJJZBS.cjs.map +1 -0
  31. package/dist/chunk-U6IZKC7B.cjs +113 -0
  32. package/dist/chunk-U6IZKC7B.cjs.map +1 -0
  33. package/dist/{chunk-SQC26VQV.cjs → chunk-UN33YOXW.cjs} +191 -191
  34. package/dist/{chunk-SQC26VQV.cjs.map → chunk-UN33YOXW.cjs.map} +1 -1
  35. package/dist/{chunk-PQFAHT5O.js → chunk-VKPEPWKZ.js} +27 -94
  36. package/dist/chunk-VKPEPWKZ.js.map +1 -0
  37. package/dist/{chunk-H4PICYNL.cjs → chunk-WXEHCVJQ.cjs} +113 -180
  38. package/dist/chunk-WXEHCVJQ.cjs.map +1 -0
  39. package/dist/{chunk-LYGEEDNR.cjs → chunk-XP5IUZUO.cjs} +242 -242
  40. package/dist/chunk-XP5IUZUO.cjs.map +1 -0
  41. package/dist/{chunk-C3NWJE3K.js → chunk-XUUD43OV.js} +11 -672
  42. package/dist/chunk-XUUD43OV.js.map +1 -0
  43. package/dist/{chunk-BBRK6MOI.cjs → chunk-YU4WQE5M.cjs} +100 -100
  44. package/dist/{chunk-BBRK6MOI.cjs.map → chunk-YU4WQE5M.cjs.map} +1 -1
  45. package/dist/commands/index.d.cts +1 -1
  46. package/dist/commands/index.d.ts +1 -1
  47. package/dist/controller-ChjCCMLl.d.cts +822 -0
  48. package/dist/controller-DtbEo3om.d.ts +822 -0
  49. package/dist/extensions/index.cjs +32 -4
  50. package/dist/extensions/index.cjs.map +1 -1
  51. package/dist/extensions/index.d.cts +4 -2
  52. package/dist/extensions/index.d.ts +4 -2
  53. package/dist/extensions/index.js +31 -3
  54. package/dist/{index-QrqMmZ75.d.cts → index-DoHqT1mq.d.cts} +203 -7
  55. package/dist/{index-CSUCQYAH.d.ts → index-YLZ0fKqE.d.ts} +203 -7
  56. package/dist/index.cjs +37 -12
  57. package/dist/index.cjs.map +1 -1
  58. package/dist/index.d.cts +9 -7
  59. package/dist/index.d.ts +9 -7
  60. package/dist/index.js +31 -6
  61. package/dist/index.js.map +1 -1
  62. package/dist/spreadsheet/index.cjs +4 -4
  63. package/dist/spreadsheet/index.js +3 -3
  64. package/package.json +1 -1
  65. package/dist/chunk-C3NWJE3K.js.map +0 -1
  66. package/dist/chunk-H4PICYNL.cjs.map +0 -1
  67. package/dist/chunk-J3R2OWOE.cjs.map +0 -1
  68. package/dist/chunk-LYGEEDNR.cjs.map +0 -1
  69. package/dist/chunk-NEOO6QJD.cjs +0 -1182
  70. package/dist/chunk-NEOO6QJD.cjs.map +0 -1
  71. package/dist/chunk-PQFAHT5O.js.map +0 -1
  72. package/dist/chunk-TK2XZK6Z.js.map +0 -1
  73. package/dist/types-BVqWm3d1.d.cts +0 -320
  74. package/dist/types-BVqWm3d1.d.ts +0 -320
  75. /package/dist/{chunk-5VXI5GED.js.map → chunk-2CJ3LPYQ.js.map} +0 -0
  76. /package/dist/{chunk-REAGGLXS.js.map → chunk-JQ3BB3E6.js.map} +0 -0
@@ -1,3 +1,8 @@
1
+ import {
2
+ CHART_UPDATE_PROPERTIES,
3
+ SERIES_PROPS,
4
+ VALUE
5
+ } from "../chunk-HXUL3LS7.js";
1
6
  import {
2
7
  EDITOR_CANVAS_TOOLS,
3
8
  EDITOR_MCP_TOOLS,
@@ -35,14 +40,24 @@ import {
35
40
  validateJsonSchema
36
41
  } from "../chunk-4FX5ACVG.js";
37
42
  import {
43
+ MAX_SPARKLINE_VALUES,
44
+ SPARKLINE_KINDS,
38
45
  TABLE_ACTIONS,
39
46
  applyReplacements,
47
+ getDocumentCharts,
40
48
  getTableActionState,
41
49
  getTableState,
42
50
  isTableEnabled,
51
+ normalizeSparklineValues,
43
52
  runTableAction,
44
- searchDocument
45
- } from "../chunk-TK2XZK6Z.js";
53
+ searchDocument,
54
+ sparklineLabel
55
+ } from "../chunk-PKBWLEL7.js";
56
+ import {
57
+ describeChart,
58
+ normalizeChartSpec,
59
+ parseChartValue
60
+ } from "../chunk-LTUM52X6.js";
46
61
  import {
47
62
  getEditorMarkdown,
48
63
  getEditorText,
@@ -50,12 +65,14 @@ import {
50
65
  } from "../chunk-UKI64KUD.js";
51
66
  import "../chunk-O5RYH2PG.js";
52
67
  import "../chunk-SWE3NPOU.js";
53
- import "../chunk-REAGGLXS.js";
68
+ import "../chunk-JQ3BB3E6.js";
54
69
  import {
55
70
  colNameToIndex,
56
71
  indexToColName,
57
72
  isFormulaError
58
- } from "../chunk-ZFBBVGCI.js";
73
+ } from "../chunk-EKYHKQPG.js";
74
+ import "../chunk-664LQYFJ.js";
75
+ import "../chunk-QVZZGT4X.js";
59
76
  import {
60
77
  ensureLayout,
61
78
  getLayoutedNodes,
@@ -387,6 +404,204 @@ function planToolCall(name, args, snapshot, options) {
387
404
 
388
405
  // src/agent/providers.ts
389
406
  import { TextSelection } from "@tiptap/pm/state";
407
+
408
+ // src/agent/documentChartTools.ts
409
+ import { closeHistory } from "@tiptap/pm/history";
410
+ var READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
411
+ var WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false };
412
+ var WRITE_IDEMPOTENT = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false };
413
+ var SIZE_WIDTH = {
414
+ type: ["number", "null"],
415
+ minimum: 50,
416
+ maximum: 4096,
417
+ description: "Width in pixels, or null to fill the line (default null)."
418
+ };
419
+ var SIZE_HEIGHT = { type: "number", minimum: 50, maximum: 4096, description: "Height in pixels (default 320)." };
420
+ var SPEC_PROPERTIES = {
421
+ ...CHART_UPDATE_PROPERTIES,
422
+ categories: { type: "array", items: { type: "string" }, description: "Category labels in order (x axis labels, or pie slices)." },
423
+ series: {
424
+ type: "array",
425
+ description: "The series, each with one value per category (padded with gaps).",
426
+ items: {
427
+ type: "object",
428
+ properties: { id: { type: "string", description: "Stable id (default: from the name)." }, ...SERIES_PROPS },
429
+ required: ["name", "values"],
430
+ additionalProperties: false
431
+ }
432
+ }
433
+ };
434
+ function cleanSeries(series) {
435
+ if (!Array.isArray(series)) return series;
436
+ return series.map((s) => s && typeof s === "object" ? Object.fromEntries(Object.entries(s).filter(([, v]) => v !== null)) : s);
437
+ }
438
+ function checkedSpec(input) {
439
+ const { spec, issues } = normalizeChartSpec({ ...input, ...input.series !== void 0 ? { series: cleanSeries(input.series) } : {} });
440
+ if (issues.length) throw new Error(`The chart was not changed: ${issues.map((i) => i.message).join(" ")}`);
441
+ return spec;
442
+ }
443
+ function describe(chart, includeSpec) {
444
+ const { spec, node } = chart;
445
+ return {
446
+ id: chart.id,
447
+ pos: chart.pos,
448
+ type: spec.type,
449
+ title: spec.title,
450
+ categories: spec.categories,
451
+ series: spec.series.map((s) => ({ id: s.id, name: s.name })),
452
+ width: node.attrs.width ?? null,
453
+ height: node.attrs.height,
454
+ description: describeChart(spec),
455
+ ...includeSpec ? { spec } : {}
456
+ };
457
+ }
458
+ function sparklines(doc) {
459
+ const found = [];
460
+ doc.descendants((node, pos) => {
461
+ if (node.type.name === "sparkline") found.push({ pos, kind: node.attrs.kind, values: node.attrs.values, label: sparklineLabel(node) });
462
+ });
463
+ return found;
464
+ }
465
+ function checkPosition(editor, at) {
466
+ const size = editor.state.doc.content.size;
467
+ if (at !== void 0 && at > size) throw new Error(`Position ${at} is outside the document (size ${size}).`);
468
+ }
469
+ function createDocumentChartTools(editor) {
470
+ const chartType = () => editor().schema.nodes.chart;
471
+ const findChart = (args) => {
472
+ const charts = getDocumentCharts(editor().state.doc);
473
+ const list = charts.map((c) => `"${c.id}" at ${c.pos}`).join(", ") || "none; add one with insert_chart";
474
+ if (args.chartId !== void 0) {
475
+ const chart = charts.find((c) => c.id === args.chartId);
476
+ if (!chart) throw new Error(`There is no chart "${args.chartId}" in the document. Charts: ${list}.`);
477
+ if (args.pos !== void 0 && args.pos !== chart.pos) throw new Error(`Chart "${args.chartId}" is at ${chart.pos}, not ${args.pos}; pass one of chartId or pos.`);
478
+ return chart;
479
+ }
480
+ if (args.pos !== void 0) {
481
+ const chart = charts.find((c) => c.pos === args.pos);
482
+ if (!chart) throw new Error(`There is no chart at position ${args.pos}. Charts: ${list}.`);
483
+ return chart;
484
+ }
485
+ throw new Error(`Pass chartId or pos (from list_document_charts). Charts: ${list}.`);
486
+ };
487
+ const listCharts = {
488
+ name: "list_document_charts",
489
+ title: "List charts in the document",
490
+ description: "Lists the charts in the document in order: id, document position, type, title, categories, series (ids and names), size in pixels and a plain-language description of the data. Also lists inline sparklines (position, kind, values). Pass the id or position to update_chart_in_document.",
491
+ inputSchema: {
492
+ type: "object",
493
+ properties: { includeSpec: { type: "boolean", description: "Also return each chart's full spec (default false)." } },
494
+ additionalProperties: false
495
+ },
496
+ annotations: { title: "List charts in the document", ...READ },
497
+ handler: ({ includeSpec = false }) => {
498
+ const doc = editor().state.doc;
499
+ return { charts: getDocumentCharts(doc).map((c) => describe(c, includeSpec)), sparklines: editor().schema.nodes.sparkline ? sparklines(doc) : [] };
500
+ }
501
+ };
502
+ const insertChart = {
503
+ name: "insert_chart",
504
+ title: "Insert a chart",
505
+ description: "Inserts a chart block at a document position (or the cursor), as one undo step. Give the categories and series (one value per category) and any presentation fields (type, titles, axes, legend, stacking, palette, \u2026). Invalid fields change nothing and come back as sentences. Returns the new chart's id, position and stored spec.",
506
+ inputSchema: {
507
+ type: "object",
508
+ properties: {
509
+ spec: { type: "object", description: "The chart: categories and series, plus optional presentation fields.", properties: SPEC_PROPERTIES, required: ["categories", "series"], additionalProperties: false },
510
+ at: { type: "integer", minimum: 0, description: "Document position (default: the selection). A position inside a paragraph splits it." },
511
+ width: SIZE_WIDTH,
512
+ height: SIZE_HEIGHT
513
+ },
514
+ required: ["spec"],
515
+ additionalProperties: false
516
+ },
517
+ annotations: { title: "Insert a chart", ...WRITE },
518
+ handler: ({ spec: input, at, width = null, height }) => {
519
+ const ed = editor();
520
+ checkPosition(ed, at);
521
+ const spec = checkedSpec(input);
522
+ const id = ed.extensionManager.extensions.find((e) => e.name === "chart")?.options.generateId?.() ?? `chart-${Date.now().toString(36)}`;
523
+ const node = { type: "chart", attrs: { id, spec, width, ...height !== void 0 ? { height } : {} } };
524
+ const chain = ed.chain().command(({ tr }) => (closeHistory(tr), true));
525
+ const ok = (at !== void 0 ? chain.insertContentAt(at, node) : chain.insertContent(node)).run();
526
+ const chart = getDocumentCharts(ed.state.doc).find((c) => c.id === id);
527
+ if (!ok || !chart) throw new Error(`A chart cannot go at ${at ?? ed.state.selection.from}; pass a position between blocks or inside a paragraph.`);
528
+ return { id: chart.id, pos: chart.pos, spec: chart.spec, width: chart.node.attrs.width, height: chart.node.attrs.height };
529
+ }
530
+ };
531
+ const updateChart = {
532
+ name: "update_chart_in_document",
533
+ title: "Change a chart in the document",
534
+ description: "Changes one chart (by id or position from list_document_charts) as one undo step: data (categories, series \u2014 given series replace all) and / or presentation fields, which merge into the current spec (axes and legend field by field), plus its size. All-or-nothing: invalid values change nothing and come back as sentences. Returns the chart's id, position and new spec.",
535
+ inputSchema: {
536
+ type: "object",
537
+ properties: {
538
+ chartId: { type: "string", description: "Chart id from list_document_charts." },
539
+ pos: { type: "integer", minimum: 0, description: "Document position of the chart (from list_document_charts), instead of chartId." },
540
+ changes: { type: "object", description: "Fields to change; omitted fields keep their value.", properties: SPEC_PROPERTIES, additionalProperties: false },
541
+ width: SIZE_WIDTH,
542
+ height: { ...SIZE_HEIGHT, description: "Height in pixels (default: unchanged)." }
543
+ },
544
+ additionalProperties: false
545
+ },
546
+ annotations: { title: "Change a chart in the document", ...WRITE_IDEMPOTENT },
547
+ handler: ({ chartId, pos, changes, width, height }) => {
548
+ const ed = editor();
549
+ const chart = findChart({ chartId, pos });
550
+ if (!changes && width === void 0 && height === void 0) throw new Error('Nothing to change: pass changes, width or height, e.g. {"changes": {"type": "line"}}.');
551
+ const s = chart.spec;
552
+ const patch = changes ?? {};
553
+ const spec = checkedSpec({
554
+ ...s,
555
+ ...patch,
556
+ xAxis: patch.xAxis ? { ...s.xAxis, ...patch.xAxis } : s.xAxis,
557
+ yAxis: patch.yAxis ? { ...s.yAxis, ...patch.yAxis } : s.yAxis,
558
+ yAxis2: patch.yAxis2 ? { ...s.yAxis2, ...patch.yAxis2 } : s.yAxis2,
559
+ legend: patch.legend ? { ...s.legend, ...patch.legend } : s.legend
560
+ });
561
+ const attrs = { ...chart.node.attrs, spec, ...width !== void 0 ? { width } : {}, ...height !== void 0 ? { height } : {} };
562
+ ed.view.dispatch(closeHistory(ed.state.tr.setNodeMarkup(chart.pos, void 0, attrs)));
563
+ return { id: chart.id, pos: chart.pos, spec, width: attrs.width, height: attrs.height };
564
+ }
565
+ };
566
+ const insertSparkline = {
567
+ name: "insert_sparkline",
568
+ title: "Insert a sparkline",
569
+ description: "Inserts a word-sized chart into the text at a document position (or the cursor), as one undo step. Returns its position and stored values.",
570
+ inputSchema: {
571
+ type: "object",
572
+ properties: {
573
+ values: { type: "array", items: VALUE, minItems: 1, maxItems: MAX_SPARKLINE_VALUES, description: "Values in order (null for a gap)." },
574
+ kind: { type: "string", enum: [...SPARKLINE_KINDS], description: "line (default), column, or win-loss (sign only)." },
575
+ at: { type: "integer", minimum: 0, description: "Document position inside a paragraph (default: the selection)." },
576
+ width: { type: "number", minimum: 4, maximum: 1e3, description: "Width in pixels (default 80)." },
577
+ height: { type: "number", minimum: 4, maximum: 200, description: "Height in pixels (default 18)." },
578
+ color: { type: "string", description: "CSS colour (default: the first palette colour)." },
579
+ label: { type: "string", description: 'Accessible label (default: "Trend from <first> to <last>").' }
580
+ },
581
+ required: ["values"],
582
+ additionalProperties: false
583
+ },
584
+ annotations: { title: "Insert a sparkline", ...WRITE },
585
+ handler: ({ values, kind = "line", at, width = 80, height = 18, color = null, label = null }) => {
586
+ const ed = editor();
587
+ checkPosition(ed, at);
588
+ const parsed = values.map((v) => parseChartValue(v));
589
+ const bad = parsed.findIndex((v) => v === void 0);
590
+ if (bad >= 0) throw new Error(`values[${bad}] ("${String(values[bad])}") is not a number; pass numbers, numeric text or null. Nothing was inserted.`);
591
+ const pos = at ?? ed.state.selection.from;
592
+ if (!ed.state.doc.resolve(pos).parent.inlineContent) throw new Error(`Position ${pos} is between blocks; a sparkline goes inside a paragraph (use a position from get_text {blocks: true}).`);
593
+ const stored = normalizeSparklineValues(parsed);
594
+ ed.chain().command(({ tr }) => (closeHistory(tr), true)).insertContentAt(pos, { type: "sparkline", attrs: { values: stored, kind, width, height, color, label } }).run();
595
+ return { pos, kind, values: stored };
596
+ }
597
+ };
598
+ return {
599
+ read: () => chartType() ? [listCharts] : [],
600
+ write: () => chartType() ? [insertChart, updateChart, ...editor().schema.nodes.sparkline ? [insertSparkline] : []] : []
601
+ };
602
+ }
603
+
604
+ // src/agent/providers.ts
390
605
  var toEditor = (target) => "commands" in target ? target : target.editor;
391
606
  function replaceWithText(editor, from, to, text) {
392
607
  const { state, view } = editor;
@@ -432,6 +647,7 @@ function findMatches(editor, query, args, replacement) {
432
647
  }
433
648
  function createRichTextToolProvider(target, options) {
434
649
  const editor = () => toEditor(target);
650
+ const charts = createDocumentChartTools(editor);
435
651
  const getText = {
436
652
  name: "get_text",
437
653
  title: "Get document text",
@@ -721,9 +937,9 @@ function createRichTextToolProvider(target, options) {
721
937
  tools: () => {
722
938
  const ed = editor();
723
939
  if (!ed || ed.isDestroyed) return [];
724
- if (!ed.isEditable) return [getText, findText];
940
+ if (!ed.isEditable) return [getText, findText, ...charts.read()];
725
941
  const tools = [getText, findText, insertText, replaceText, replaceRange, replaceSelection, setSelection];
726
- return isTableEnabled(ed) ? [...tools, editTable] : tools;
942
+ return [...tools, ...isTableEnabled(ed) ? [editTable] : [], ...charts.read(), ...charts.write()];
727
943
  },
728
944
  subscribe: (notify) => {
729
945
  const ed = editor();
@@ -1053,8 +1269,8 @@ var COMPONENT_ID = { type: "string", description: "Component or component set id
1053
1269
  var PARENT_ID = { type: "string", description: "Frame to place the instance in (default: the canvas root)." };
1054
1270
  var X = { type: "number", description: "X position (canvas coordinates, or relative to the parent frame)." };
1055
1271
  var Y = { type: "number", description: "Y position (canvas coordinates, or relative to the parent frame)." };
1056
- var READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
1057
- var WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false };
1272
+ var READ2 = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
1273
+ var WRITE2 = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false };
1058
1274
  var DESTRUCTIVE = { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false };
1059
1275
  var TITLES = {
1060
1276
  list_components: "List components",
@@ -1088,7 +1304,7 @@ function createCanvasComponentToolProvider(controller, options = { id: "canvas-c
1088
1304
  inputSchema: { type: "object", properties, ...extra.required ? { required: extra.required } : {}, additionalProperties: false },
1089
1305
  annotations: {
1090
1306
  title: TITLES[name],
1091
- ...extra.readOnly ? READ : DESTRUCTIVE_TOOLS.has(name) ? DESTRUCTIVE : WRITE
1307
+ ...extra.readOnly ? READ2 : DESTRUCTIVE_TOOLS.has(name) ? DESTRUCTIVE : WRITE2
1092
1308
  },
1093
1309
  handler
1094
1310
  });
@@ -1268,6 +1484,7 @@ export {
1268
1484
  ToolRegistry,
1269
1485
  ToolRegistryError,
1270
1486
  createCanvasComponentToolProvider,
1487
+ createDocumentChartTools,
1271
1488
  createEditorMcpToolProvider,
1272
1489
  createMcpServer,
1273
1490
  createRichTextToolProvider,