@pixerate/editor 0.46.1 → 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 (98) hide show
  1. package/THIRD_PARTY_NOTICES.md +20 -0
  2. package/dist/agent/index.cjs +252 -34
  3. package/dist/agent/index.cjs.map +1 -1
  4. package/dist/agent/index.d.cts +19 -7
  5. package/dist/agent/index.d.ts +19 -7
  6. package/dist/agent/index.js +228 -10
  7. package/dist/agent/index.js.map +1 -1
  8. package/dist/{builtins-CZW-aYKS.d.cts → builtins-1kqwLUnb.d.cts} +2 -2
  9. package/dist/{builtins-DghNQbT-.d.ts → builtins-BKYlHH1s.d.ts} +2 -2
  10. package/dist/chart/index.cjs +1596 -1849
  11. package/dist/chart/index.cjs.map +1 -1
  12. package/dist/chart/index.d.cts +760 -548
  13. package/dist/chart/index.d.ts +760 -548
  14. package/dist/chart/index.js +1499 -1752
  15. package/dist/chart/index.js.map +1 -1
  16. package/dist/{chunk-3RPOW4CS.js → chunk-2CJ3LPYQ.js} +12 -10
  17. package/dist/{chunk-3RPOW4CS.js.map → chunk-2CJ3LPYQ.js.map} +1 -1
  18. package/dist/{chunk-PQM5W7ZN.js → chunk-4FX5ACVG.js} +29 -2
  19. package/dist/{chunk-PQM5W7ZN.js.map → chunk-4FX5ACVG.js.map} +1 -1
  20. package/dist/{chunk-HHQ4XJWT.js → chunk-AMWXSYCI.js} +2 -2
  21. package/dist/chunk-EKYHKQPG.js +1895 -0
  22. package/dist/chunk-EKYHKQPG.js.map +1 -0
  23. package/dist/chunk-HXUL3LS7.js +113 -0
  24. package/dist/chunk-HXUL3LS7.js.map +1 -0
  25. package/dist/{chunk-ZRNHGAQT.js → chunk-JQ3BB3E6.js} +43 -1891
  26. package/dist/chunk-JQ3BB3E6.js.map +1 -0
  27. package/dist/chunk-LTUM52X6.js +4074 -0
  28. package/dist/chunk-LTUM52X6.js.map +1 -0
  29. package/dist/{chunk-J3R2OWOE.cjs → chunk-MUCYWI6W.cjs} +608 -15
  30. package/dist/chunk-MUCYWI6W.cjs.map +1 -0
  31. package/dist/chunk-PIMCHMZE.cjs +521 -0
  32. package/dist/chunk-PIMCHMZE.cjs.map +1 -0
  33. package/dist/{chunk-TK2XZK6Z.js → chunk-PKBWLEL7.js} +594 -1
  34. package/dist/chunk-PKBWLEL7.js.map +1 -0
  35. package/dist/chunk-PRSJJZBS.cjs +4074 -0
  36. package/dist/chunk-PRSJJZBS.cjs.map +1 -0
  37. package/dist/{chunk-EFDCLENW.cjs → chunk-RIWPYSKU.cjs} +29 -2
  38. package/dist/chunk-RIWPYSKU.cjs.map +1 -0
  39. package/dist/chunk-U6IZKC7B.cjs +113 -0
  40. package/dist/chunk-U6IZKC7B.cjs.map +1 -0
  41. package/dist/{chunk-EWCOFSCQ.cjs → chunk-UN33YOXW.cjs} +252 -2100
  42. package/dist/chunk-UN33YOXW.cjs.map +1 -0
  43. package/dist/{chunk-Q25ZS4F7.js → chunk-VKPEPWKZ.js} +72 -92
  44. package/dist/chunk-VKPEPWKZ.js.map +1 -0
  45. package/dist/{chunk-N4MLNJPO.cjs → chunk-WXEHCVJQ.cjs} +160 -180
  46. package/dist/chunk-WXEHCVJQ.cjs.map +1 -0
  47. package/dist/{chunk-K2LVZ4FA.cjs → chunk-XFYUFVAX.cjs} +3 -3
  48. package/dist/{chunk-K2LVZ4FA.cjs.map → chunk-XFYUFVAX.cjs.map} +1 -1
  49. package/dist/chunk-XP5IUZUO.cjs +1895 -0
  50. package/dist/chunk-XP5IUZUO.cjs.map +1 -0
  51. package/dist/chunk-XUUD43OV.js +521 -0
  52. package/dist/chunk-XUUD43OV.js.map +1 -0
  53. package/dist/{chunk-U7VGDSNY.cjs → chunk-YU4WQE5M.cjs} +101 -99
  54. package/dist/chunk-YU4WQE5M.cjs.map +1 -0
  55. package/dist/commands/index.cjs +93 -11
  56. package/dist/commands/index.cjs.map +1 -1
  57. package/dist/commands/index.d.cts +9 -7
  58. package/dist/commands/index.d.ts +9 -7
  59. package/dist/commands/index.js +92 -10
  60. package/dist/commands/index.js.map +1 -1
  61. package/dist/controller-ChjCCMLl.d.cts +822 -0
  62. package/dist/controller-DtbEo3om.d.ts +822 -0
  63. package/dist/extensions/index.cjs +32 -3
  64. package/dist/extensions/index.cjs.map +1 -1
  65. package/dist/extensions/index.d.cts +5 -2
  66. package/dist/extensions/index.d.ts +5 -2
  67. package/dist/extensions/index.js +31 -2
  68. package/dist/generation/index.cjs +2 -2
  69. package/dist/generation/index.js +1 -1
  70. package/dist/{index-CfOQf70b.d.cts → index-DoHqT1mq.d.cts} +222 -5
  71. package/dist/{index-jwJ_onWf.d.ts → index-YLZ0fKqE.d.ts} +222 -5
  72. package/dist/index.cjs +38 -10
  73. package/dist/index.cjs.map +1 -1
  74. package/dist/index.d.cts +13 -5
  75. package/dist/index.d.ts +13 -5
  76. package/dist/index.js +52 -24
  77. package/dist/index.js.map +1 -1
  78. package/dist/parameters/index.d.cts +1 -1
  79. package/dist/parameters/index.d.ts +1 -1
  80. package/dist/{registry-vz6HOiiy.d.cts → registry-CaR7LC6W.d.cts} +2 -0
  81. package/dist/{registry-BfVD-vVg.d.ts → registry-rVtFJjRM.d.ts} +2 -0
  82. package/dist/spreadsheet/index.cjs +5 -3
  83. package/dist/spreadsheet/index.cjs.map +1 -1
  84. package/dist/spreadsheet/index.js +24 -22
  85. package/dist/tools/index.cjs +3 -3
  86. package/dist/tools/index.js +2 -2
  87. package/dist/vector/index.d.cts +1 -1
  88. package/dist/vector/index.d.ts +1 -1
  89. package/package.json +2 -1
  90. package/dist/chunk-EFDCLENW.cjs.map +0 -1
  91. package/dist/chunk-EWCOFSCQ.cjs.map +0 -1
  92. package/dist/chunk-J3R2OWOE.cjs.map +0 -1
  93. package/dist/chunk-N4MLNJPO.cjs.map +0 -1
  94. package/dist/chunk-Q25ZS4F7.js.map +0 -1
  95. package/dist/chunk-TK2XZK6Z.js.map +0 -1
  96. package/dist/chunk-U7VGDSNY.cjs.map +0 -1
  97. package/dist/chunk-ZRNHGAQT.js.map +0 -1
  98. /package/dist/{chunk-HHQ4XJWT.js.map → chunk-AMWXSYCI.js.map} +0 -0
@@ -6,21 +6,36 @@ import {
6
6
  readZip
7
7
  } from "./chunk-MR2764X2.js";
8
8
  import {
9
+ CHART_OOXML_NS,
10
+ chartFromOoxml
11
+ } from "./chunk-XUUD43OV.js";
12
+ import {
13
+ Chart,
9
14
  MAX_TABLE_COLUMNS,
10
15
  MAX_TABLE_ROWS,
16
+ STRUCTURE_PRIORITY,
17
+ Sparkline,
11
18
  TABLE_ACTIONS,
12
19
  applyReplacements,
20
+ arraysEqual,
13
21
  compileFindPattern,
14
22
  createTableExtensions,
23
+ generateStructureId,
15
24
  getTableActionState,
16
25
  getTableState,
17
26
  handleTablePasteWithoutNesting,
18
27
  insertSliceAfterTable,
19
28
  outermostTableDepth,
29
+ presenceStateSpec,
20
30
  runTableAction,
31
+ scrollDomAtPos,
21
32
  searchDocument,
22
- sliceContainsTable
23
- } from "./chunk-TK2XZK6Z.js";
33
+ sliceContainsTable,
34
+ syncInitialContent
35
+ } from "./chunk-PKBWLEL7.js";
36
+ import {
37
+ chartDataToTable
38
+ } from "./chunk-LTUM52X6.js";
24
39
  import {
25
40
  compareDocuments
26
41
  } from "./chunk-QJSOZFCZ.js";
@@ -2442,6 +2457,36 @@ function toBase64(bytes) {
2442
2457
  }
2443
2458
  return btoa(binary);
2444
2459
  }
2460
+ async function loadCharts(zip, Parser, root, rels, options) {
2461
+ const charts = /* @__PURE__ */ new Map();
2462
+ if (options.charts === false) return charts;
2463
+ for (const el of descendants(root, "chart")) {
2464
+ if (el.namespaceURI !== CHART_OOXML_NS) continue;
2465
+ const id = attr(el, "id");
2466
+ const rel = id ? rels.get(id) : void 0;
2467
+ if (!id || !rel || rel.external || charts.has(id)) continue;
2468
+ const entry = zip.get(rel.target);
2469
+ if (!entry) continue;
2470
+ const read = chartFromOoxml(await zip.readText(entry), { DOMParser: Parser });
2471
+ charts.set(id, {
2472
+ id: `chart-${charts.size + 1}`,
2473
+ path: rel.target,
2474
+ title: read.spec.title,
2475
+ spec: read.spec,
2476
+ issues: read.issues.map((i) => i.message),
2477
+ unsupported: read.unsupported,
2478
+ lossless: read.lossless
2479
+ });
2480
+ }
2481
+ return charts;
2482
+ }
2483
+ function chartBlockHtml(chart) {
2484
+ const [head, ...rows] = chartDataToTable(chart.spec);
2485
+ const cell = (v, tag) => `<${tag}><p>${escapeHtml(v === null || v === void 0 ? "" : String(v))}</p></${tag}>`;
2486
+ const table = `<table><tbody><tr>${head.map((h) => cell(h, "th")).join("")}</tr>${rows.map((r) => `<tr>${r.map((v, i) => cell(v, i ? "td" : "th")).join("")}</tr>`).join("")}</tbody></table>`;
2487
+ const caption = `<p>${escapeHtml(`[Chart: ${chart.title || "untitled"}]`)}</p>`;
2488
+ return `<div data-type="chart" data-chart-id="${escapeHtml(chart.id)}" data-chart="${escapeHtml(JSON.stringify(chart.spec))}">${caption}${table}</div>`;
2489
+ }
2445
2490
  async function loadImages(zip, root, rels, options) {
2446
2491
  const images = /* @__PURE__ */ new Map();
2447
2492
  if (options.images === false) return images;
@@ -2910,6 +2955,7 @@ function renderSegments(segments, code = false) {
2910
2955
  if (seg.kind === "text") inner += escapeHtml(seg.text);
2911
2956
  else if (seg.kind === "br") inner += code ? "\n" : "<br>";
2912
2957
  else if (seg.kind === "img") inner += code ? "" : `<img src="${escapeHtml(seg.src)}" alt="${escapeHtml(seg.alt)}">`;
2958
+ else if (seg.kind === "chart") inner += code ? escapeHtml(`[Chart: ${seg.chart.title || "untitled"}]`) : "";
2913
2959
  else inner += `<sup>${seg.n}</sup>`;
2914
2960
  }
2915
2961
  const format = segments[i].format;
@@ -3088,7 +3134,7 @@ var ParagraphRenderer = class {
3088
3134
  };
3089
3135
  if (child.localName === "AlternateContent") {
3090
3136
  const branch = childElements(child).find(
3091
- (b) => descendants(b, "blip").length || descendants(b, "imagedata").length
3137
+ (b) => descendants(b, "blip").length || descendants(b, "imagedata").length || descendants(b, "chart").some((el) => el.namespaceURI === CHART_OOXML_NS)
3092
3138
  );
3093
3139
  if (branch) this.image(branch, format, push);
3094
3140
  return;
@@ -3152,7 +3198,17 @@ var ParagraphRenderer = class {
3152
3198
  break;
3153
3199
  }
3154
3200
  }
3201
+ /** Charts this paragraph contains, in order. */
3202
+ charts = [];
3155
3203
  image(container, format, push) {
3204
+ const chartRef = descendants(container, "chart").find((el) => el.namespaceURI === CHART_OOXML_NS);
3205
+ const chart = chartRef ? this.part.charts.get(attr(chartRef, "id") ?? "") : void 0;
3206
+ if (chart) {
3207
+ if (!this.ctx.charts.includes(chart)) this.ctx.charts.push(chart);
3208
+ this.charts.push(chart);
3209
+ push({ kind: "chart", chart, format });
3210
+ return;
3211
+ }
3156
3212
  const blip = descendants(container, "blip")[0];
3157
3213
  const imageData = descendants(container, "imagedata")[0];
3158
3214
  const id = blip ? attr(blip, "embed") : attr(imageData, "id");
@@ -3290,7 +3346,8 @@ function renderBlocks(container, ctx, part, topLevel = false) {
3290
3346
  const mappedStyle = styleId ? ctx.styleIds.get(styleId) : void 0;
3291
3347
  const styleAttr = !heading && !list && mappedStyle && mappedStyle !== NORMAL_STYLE_ID ? ` data-style="${escapeHtml(mappedStyle)}"` : "";
3292
3348
  const changeAttr = topLevel && !list && ctx.tracked === "marks" ? blockChangeAttr(pPr, ctx) : "";
3293
- const blockHtml = heading ? `<h${heading}${changeAttr}>${inner}</h${heading}>` : `<p${styleAttr}${changeAttr}>${inner}</p>`;
3349
+ const charts = renderer.charts.map(chartBlockHtml).join("");
3350
+ const blockHtml = (charts && !inner && !heading ? "" : heading ? `<h${heading}${changeAttr}>${inner}</h${heading}>` : `<p${styleAttr}${changeAttr}>${inner}</p>`) + charts;
3294
3351
  if (!list) {
3295
3352
  closeAll();
3296
3353
  html += blockHtml;
@@ -3438,21 +3495,22 @@ async function docxToDocumentImport(data, options = {}) {
3438
3495
  moveRanges: /* @__PURE__ */ new Map(),
3439
3496
  moveIds: /* @__PURE__ */ new Map(),
3440
3497
  segmentCount: 0,
3441
- lastChange: null
3498
+ lastChange: null,
3499
+ charts: []
3442
3500
  };
3443
3501
  for (const kind of ["footnote", "endnote"]) {
3444
3502
  const path = partByType(`${kind}s`) ?? `${baseDir}${kind}s.xml`;
3445
3503
  const notesXml = await readXmlPart(zip, Parser, path);
3446
3504
  if (!notesXml) continue;
3447
3505
  const noteRels = await readRelationships(zip, Parser, path);
3448
- const part2 = { rels: noteRels, images: await loadImages(zip, notesXml, noteRels, options) };
3506
+ const part2 = { rels: noteRels, images: await loadImages(zip, notesXml, noteRels, options), charts: await loadCharts(zip, Parser, notesXml, noteRels, options) };
3449
3507
  descendants(notesXml, kind).filter((note) => isW(note)).forEach((note) => {
3450
3508
  const type = attr(note, "type");
3451
3509
  if (type && type !== "normal") return;
3452
3510
  ctx.notes.set(`${kind}:${attr(note, "id")}`, { element: note, part: part2 });
3453
3511
  });
3454
3512
  }
3455
- const part = { rels, images: await loadImages(zip, documentXml, rels, options) };
3513
+ const part = { rels, images: await loadImages(zip, documentXml, rels, options), charts: await loadCharts(zip, Parser, documentXml, rels, options) };
3456
3514
  let html = renderBlocks(body, ctx, part, true);
3457
3515
  if (ctx.noteOrder.length) {
3458
3516
  let notesHtml = "";
@@ -3465,6 +3523,7 @@ async function docxToDocumentImport(data, options = {}) {
3465
3523
  const sanitized = sanitizeImportedHtml(html);
3466
3524
  const result = { html: sanitized, text: htmlToPlainText(sanitized) };
3467
3525
  if (threads.length) result.comments = { version: 1, threads };
3526
+ if (ctx.charts.length) result.charts = ctx.charts;
3468
3527
  if (useStyles) {
3469
3528
  const definitions = styleDefinitions(styles, styleIds);
3470
3529
  if (definitions.length) result.styles = createStyleRegistry({ styles: definitions });
@@ -4086,90 +4145,6 @@ import {
4086
4145
  PluginKey as PluginKey7,
4087
4146
  TextSelection as TextSelection2
4088
4147
  } from "@tiptap/pm/state";
4089
-
4090
- // src/extensions/document-structure/utils.ts
4091
- import { createDocument } from "@tiptap/core";
4092
- import { EditorState } from "@tiptap/pm/state";
4093
- import { ReplaceAroundStep, ReplaceStep } from "@tiptap/pm/transform";
4094
- var idCounter = 0;
4095
- function generateStructureId(prefix) {
4096
- idCounter = (idCounter + 1) % 1296;
4097
- const random = Math.random().toString(36).slice(2, 8).padEnd(6, "0");
4098
- return `${prefix}-${random}${idCounter.toString(36).padStart(2, "0")}`;
4099
- }
4100
- function transactionsInsert(transactions, typeNames) {
4101
- for (const tr of transactions) {
4102
- for (const step of tr.steps) {
4103
- if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {
4104
- const mark = step.mark;
4105
- if (mark && typeNames.includes(mark.type.name)) return true;
4106
- continue;
4107
- }
4108
- let found = false;
4109
- step.slice.content.descendants((node) => {
4110
- if (found) return false;
4111
- if (typeNames.includes(node.type.name) || node.marks.some((m) => typeNames.includes(m.type.name))) {
4112
- found = true;
4113
- }
4114
- return !found;
4115
- });
4116
- if (found) return true;
4117
- }
4118
- }
4119
- return false;
4120
- }
4121
- function docContains(doc, typeNames) {
4122
- let found = false;
4123
- doc.descendants((node) => {
4124
- if (found) return false;
4125
- if (typeNames.includes(node.type.name) || node.marks.some((m) => typeNames.includes(m.type.name))) {
4126
- found = true;
4127
- }
4128
- return !found;
4129
- });
4130
- return found;
4131
- }
4132
- function presenceStateSpec(typeNames) {
4133
- return {
4134
- init: (_config, state) => docContains(state.doc, typeNames),
4135
- apply: (tr, present, _oldState, newState) => {
4136
- if (!tr.docChanged) return present;
4137
- if (!present && !transactionsInsert([tr], typeNames)) return false;
4138
- return docContains(newState.doc, typeNames);
4139
- }
4140
- };
4141
- }
4142
- function arraysEqual(a, b, eq) {
4143
- if (a.length !== b.length) return false;
4144
- for (let i = 0; i < a.length; i++) {
4145
- if (!eq(a[i], b[i])) return false;
4146
- }
4147
- return true;
4148
- }
4149
- function scrollDomAtPos(view, pos, behavior = "smooth") {
4150
- try {
4151
- const dom = view?.nodeDOM?.(pos);
4152
- if (dom && typeof dom.scrollIntoView === "function") {
4153
- dom.scrollIntoView({ block: "start", behavior });
4154
- }
4155
- } catch {
4156
- }
4157
- }
4158
- function syncInitialContent(editor, sync) {
4159
- const { content } = editor.options;
4160
- if (content == null || content === "") return;
4161
- try {
4162
- const doc = createDocument(content, editor.schema, editor.options.parseOptions, {
4163
- errorOnInvalidContent: false
4164
- });
4165
- const tr = sync(EditorState.create({ doc }));
4166
- if (tr?.docChanged) editor.options.content = tr.doc;
4167
- } catch {
4168
- }
4169
- }
4170
- var STRUCTURE_PRIORITY = 45;
4171
-
4172
- // src/extensions/document-structure/outline.ts
4173
4148
  var outlinePluginKey = new PluginKey7("outline");
4174
4149
  var outlineIdPluginKey = new PluginKey7("outlineIds");
4175
4150
  var sameHeading = (a, b) => a.id === b.id && a.level === b.level && a.text === b.text && a.pos === b.pos && a.depth === b.depth;
@@ -6445,6 +6420,11 @@ function createRichTextPreset(options = {}) {
6445
6420
  if (options.findReplace) {
6446
6421
  extensions2.push(FindReplace.configure(optionObject(options.findReplace)));
6447
6422
  }
6423
+ if (options.chart) {
6424
+ const { sparkline = true, ...chartOptions } = optionObject(options.chart);
6425
+ extensions2.push(Chart.configure(chartOptions));
6426
+ if (sparkline) extensions2.push(Sparkline.configure(optionObject(sparkline)));
6427
+ }
6448
6428
  if (options.paragraphStyles) {
6449
6429
  extensions2.push(ParagraphStyles.configure(optionObject(options.paragraphStyles)));
6450
6430
  }
@@ -6773,4 +6753,4 @@ export {
6773
6753
  validateFindPattern,
6774
6754
  createTableCommands
6775
6755
  };
6776
- //# sourceMappingURL=chunk-Q25ZS4F7.js.map
6756
+ //# sourceMappingURL=chunk-VKPEPWKZ.js.map