@bikdotai/bik-component-library 0.0.838-beta.6 → 0.0.838

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 (81) hide show
  1. package/dist/cjs/components/WhatsAppTextEditor/WhatsAppTextEditor.js +23 -23
  2. package/dist/cjs/components/WhatsAppTextEditor/WhatsAppTextEditor.js.map +1 -1
  3. package/dist/cjs/components/agent-builder/components/AiTextArea.js +1 -1
  4. package/dist/cjs/components/agent-builder/components/AiTextArea.js.map +1 -1
  5. package/dist/cjs/components/agent-builder/components/ToolInstructionsField.js +2 -2
  6. package/dist/cjs/components/agent-builder/components/ToolInstructionsField.js.map +1 -1
  7. package/dist/cjs/components/bik-chatbot/components/ChatWindow.js +20 -20
  8. package/dist/cjs/components/bik-chatbot/components/ChatWindow.js.map +1 -1
  9. package/dist/cjs/components/input/ChipInput.js +1 -1
  10. package/dist/cjs/components/input/ChipInput.js.map +1 -1
  11. package/dist/cjs/components/input/Input-helper.js +1 -1
  12. package/dist/cjs/components/input/Input-helper.js.map +1 -1
  13. package/dist/cjs/components/input/Input.js +1 -1
  14. package/dist/cjs/components/input/Input.js.map +1 -1
  15. package/dist/cjs/components/plans/SubscriptionPlanSelector.js +5 -5
  16. package/dist/cjs/components/plans/SubscriptionPlanSelector.js.map +1 -1
  17. package/dist/cjs/editor/BikEditor.js +1 -1
  18. package/dist/cjs/editor/BikEditor.js.map +1 -1
  19. package/dist/cjs/editor/BikEditor.utils.js +3 -3
  20. package/dist/cjs/editor/BikEditor.utils.js.map +1 -1
  21. package/dist/cjs/editor/extensions/buildExtensions.js +2 -2
  22. package/dist/cjs/editor/extensions/buildExtensions.js.map +1 -1
  23. package/dist/cjs/icons/Informational/General/HourglassFilled.js +2 -0
  24. package/dist/cjs/icons/Informational/General/HourglassFilled.js.map +1 -0
  25. package/dist/cjs/icons/index.js +1 -1
  26. package/dist/cjs/index.js +1 -1
  27. package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditor.js +143 -144
  28. package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditor.js.map +1 -1
  29. package/dist/esm/components/agent-builder/components/AiTextArea.js +23 -24
  30. package/dist/esm/components/agent-builder/components/AiTextArea.js.map +1 -1
  31. package/dist/esm/components/agent-builder/components/ToolInstructionsField.js +30 -31
  32. package/dist/esm/components/agent-builder/components/ToolInstructionsField.js.map +1 -1
  33. package/dist/esm/components/bik-chatbot/components/ChatWindow.js +53 -54
  34. package/dist/esm/components/bik-chatbot/components/ChatWindow.js.map +1 -1
  35. package/dist/esm/components/input/ChipInput.js +40 -41
  36. package/dist/esm/components/input/ChipInput.js.map +1 -1
  37. package/dist/esm/components/input/Input-helper.d.ts +0 -7
  38. package/dist/esm/components/input/Input-helper.js +25 -16
  39. package/dist/esm/components/input/Input-helper.js.map +1 -1
  40. package/dist/esm/components/input/Input.js +58 -60
  41. package/dist/esm/components/input/Input.js.map +1 -1
  42. package/dist/esm/components/input/Input.model.d.ts +0 -1
  43. package/dist/esm/components/plans/SubscriptionPlanSelector.js +40 -42
  44. package/dist/esm/components/plans/SubscriptionPlanSelector.js.map +1 -1
  45. package/dist/esm/editor/BikEditor.js +118 -122
  46. package/dist/esm/editor/BikEditor.js.map +1 -1
  47. package/dist/esm/editor/BikEditor.utils.d.ts +1 -1
  48. package/dist/esm/editor/BikEditor.utils.js +140 -141
  49. package/dist/esm/editor/BikEditor.utils.js.map +1 -1
  50. package/dist/esm/editor/extensions/buildExtensions.js +39 -49
  51. package/dist/esm/editor/extensions/buildExtensions.js.map +1 -1
  52. package/dist/esm/helpers/index.d.ts +0 -1
  53. package/dist/esm/icons/Informational/General/HourglassFilled.d.ts +7 -0
  54. package/dist/esm/icons/Informational/General/HourglassFilled.js +33 -0
  55. package/dist/esm/icons/Informational/General/HourglassFilled.js.map +1 -0
  56. package/dist/esm/icons/Informational/General/index.d.ts +1 -0
  57. package/dist/esm/icons/Media/Visual/index.d.ts +0 -2
  58. package/dist/esm/icons/index.d.ts +25 -25
  59. package/dist/esm/icons/index.js +416 -418
  60. package/dist/esm/icons/index.js.map +1 -1
  61. package/dist/esm/index.js +114 -124
  62. package/dist/esm/index.js.map +1 -1
  63. package/package.json +1 -2
  64. package/dist/cjs/editor/extensions/htmlTagStrip/HtmlTagStripExtension.js +0 -2
  65. package/dist/cjs/editor/extensions/htmlTagStrip/HtmlTagStripExtension.js.map +0 -1
  66. package/dist/cjs/helpers/sanitize.js +0 -2
  67. package/dist/cjs/helpers/sanitize.js.map +0 -1
  68. package/dist/cjs/icons/Media/Visual/FormkitNeutral.js +0 -2
  69. package/dist/cjs/icons/Media/Visual/FormkitNeutral.js.map +0 -1
  70. package/dist/cjs/icons/Media/Visual/FormkitSad.js +0 -2
  71. package/dist/cjs/icons/Media/Visual/FormkitSad.js.map +0 -1
  72. package/dist/esm/editor/extensions/htmlTagStrip/HtmlTagStripExtension.d.ts +0 -13
  73. package/dist/esm/editor/extensions/htmlTagStrip/HtmlTagStripExtension.js +0 -64
  74. package/dist/esm/editor/extensions/htmlTagStrip/HtmlTagStripExtension.js.map +0 -1
  75. package/dist/esm/helpers/sanitize.d.ts +0 -32
  76. package/dist/esm/helpers/sanitize.js +0 -204
  77. package/dist/esm/helpers/sanitize.js.map +0 -1
  78. package/dist/esm/icons/Media/Visual/FormkitNeutral.js +0 -58
  79. package/dist/esm/icons/Media/Visual/FormkitNeutral.js.map +0 -1
  80. package/dist/esm/icons/Media/Visual/FormkitSad.js +0 -61
  81. package/dist/esm/icons/Media/Visual/FormkitSad.js.map +0 -1
@@ -1,113 +1,112 @@
1
1
  import { DOMSerializer as p, DOMParser as a } from "../node_modules/prosemirror-model/dist/index.js";
2
- import { sanitizeEmailHtml as v } from "../helpers/sanitize.js";
3
- import { normalizeHardBreaks as g } from "./extensions/plainClipboard/pasteUtils.js";
4
- function b(e, n = v) {
2
+ import { normalizeHardBreaks as v } from "./extensions/plainClipboard/pasteUtils.js";
3
+ function g(e) {
5
4
  if (!e || typeof document > "u") return e;
6
- const i = document.createElement("div");
7
- return i.innerHTML = n(e), i.querySelectorAll("span").forEach((t) => {
8
- const o = t.getAttribute("data-type");
9
- if (t.hasAttribute("style") || t.hasAttribute("data-variable") || o !== null && o.startsWith("mention"))
5
+ const t = document.createElement("div");
6
+ return t.innerHTML = e, t.querySelectorAll("span").forEach((i) => {
7
+ const n = i.getAttribute("data-type");
8
+ if (i.hasAttribute("style") || i.hasAttribute("data-variable") || n !== null && n.startsWith("mention"))
10
9
  return;
11
- const r = t.parentNode;
10
+ const r = i.parentNode;
12
11
  if (r) {
13
- for (; t.firstChild; ) r.insertBefore(t.firstChild, t);
14
- r.removeChild(t);
12
+ for (; i.firstChild; ) r.insertBefore(i.firstChild, i);
13
+ r.removeChild(i);
15
14
  }
16
- }), i.querySelectorAll("p").forEach((t) => {
17
- t.querySelectorAll("br").length === 1 && (t.textContent ?? "").trim() === "" && (t.innerHTML = "");
18
- }), i.innerHTML;
15
+ }), t.querySelectorAll("p").forEach((i) => {
16
+ i.querySelectorAll("br").length === 1 && (i.textContent ?? "").trim() === "" && (i.innerHTML = "");
17
+ }), t.innerHTML;
19
18
  }
20
19
  function u(e) {
21
- const n = document.createElement("div");
22
- n.innerHTML = e;
23
- const i = document.createTreeWalker(n, NodeFilter.SHOW_TEXT);
24
- let t;
25
- for (; t = i.nextNode(); )
26
- t.nodeValue && t.nodeValue.includes(" ") && (t.nodeValue = t.nodeValue.replace(/ {2}/g, "  "));
27
- const o = n.querySelectorAll("p");
28
- for (const r of Array.from(o)) {
29
- if (r.childNodes.length === 0) {
30
- r.appendChild(document.createElement("br"));
20
+ const t = document.createElement("div");
21
+ t.innerHTML = e;
22
+ const i = document.createTreeWalker(t, NodeFilter.SHOW_TEXT);
23
+ let n;
24
+ for (; n = i.nextNode(); )
25
+ n.nodeValue && n.nodeValue.includes(" ") && (n.nodeValue = n.nodeValue.replace(/ {2}/g, "  "));
26
+ const r = t.querySelectorAll("p");
27
+ for (const o of Array.from(r)) {
28
+ if (o.childNodes.length === 0) {
29
+ o.appendChild(document.createElement("br"));
31
30
  continue;
32
31
  }
33
- r.lastChild instanceof HTMLBRElement && r.childNodes.length > 1 && r.appendChild(document.createElement("br"));
32
+ o.lastChild instanceof HTMLBRElement && o.childNodes.length > 1 && o.appendChild(document.createElement("br"));
34
33
  }
35
- return n.innerHTML;
34
+ return t.innerHTML;
36
35
  }
37
- function B(e, n) {
38
- const i = b(n), t = document.createElement("div");
39
- t.innerHTML = i;
40
- const o = a.fromSchema(e.schema).parseSlice(t, {
36
+ function L(e, t) {
37
+ const i = g(t), n = document.createElement("div");
38
+ n.innerHTML = i;
39
+ const r = a.fromSchema(e.schema).parseSlice(n, {
41
40
  preserveWhitespace: !0
42
41
  });
43
- if (o.size === 0) return;
44
- const { from: r, to: c } = e.state.selection, s = e.state.tr.replaceRange(r, c, o);
42
+ if (r.size === 0) return;
43
+ const { from: o, to: c } = e.state.selection, s = e.state.tr.replaceRange(o, c, r);
45
44
  e.view.dispatch(s);
46
45
  }
47
46
  const d = (e) => `<div data-section-divider="${e}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;
48
- function M(e, n) {
47
+ function B(e, t) {
49
48
  let i = e;
50
- for (const t of n)
51
- i += d(t.id) + t.content;
49
+ for (const n of t)
50
+ i += d(n.id) + n.content;
52
51
  return i;
53
52
  }
54
- function y(e) {
55
- return e ? A(e).get("body") ?? e : "";
53
+ function b(e) {
54
+ return e ? y(e).get("body") ?? e : "";
56
55
  }
57
- function N(e) {
56
+ function M(e) {
58
57
  if (!e) return "";
59
- const n = y(e);
60
- return e.substring(n.length);
58
+ const t = b(e);
59
+ return e.substring(t.length);
61
60
  }
62
- function A(e) {
63
- const n = /* @__PURE__ */ new Map(), i = /<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g, t = [];
64
- let o;
65
- for (; (o = i.exec(e)) !== null; )
66
- t.push({
67
- id: o[1],
68
- index: o.index,
69
- endIndex: o.index + o[0].length
61
+ function y(e) {
62
+ const t = /* @__PURE__ */ new Map(), i = /<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g, n = [];
63
+ let r;
64
+ for (; (r = i.exec(e)) !== null; )
65
+ n.push({
66
+ id: r[1],
67
+ index: r.index,
68
+ endIndex: r.index + r[0].length
70
69
  });
71
- if (t.length === 0)
72
- return n.set("body", e), n;
73
- n.set("body", e.slice(0, t[0].index));
74
- for (let r = 0; r < t.length; r++) {
75
- const c = t[r].endIndex, s = r + 1 < t.length ? t[r + 1].index : e.length;
76
- n.set(t[r].id, e.slice(c, s));
70
+ if (n.length === 0)
71
+ return t.set("body", e), t;
72
+ t.set("body", e.slice(0, n[0].index));
73
+ for (let o = 0; o < n.length; o++) {
74
+ const c = n[o].endIndex, s = o + 1 < n.length ? n[o + 1].index : e.length;
75
+ t.set(n[o].id, e.slice(c, s));
77
76
  }
78
- return n;
77
+ return t;
79
78
  }
80
- function x(e, n) {
81
- const i = f(e, n);
79
+ function A(e, t) {
80
+ const i = f(e, t);
82
81
  if (i === -1)
83
82
  return { html: "", text: "", isEmpty: !0, characterCount: 0 };
84
- const t = m(e, n), o = e.state.doc.slice(i, t), r = document.createElement("div"), c = p.fromSchema(e.schema);
85
- r.appendChild(c.serializeFragment(o.content));
86
- const s = u(r.innerHTML), l = r.textContent ?? "";
83
+ const n = m(e, t), r = e.state.doc.slice(i, n), o = document.createElement("div"), c = p.fromSchema(e.schema);
84
+ o.appendChild(c.serializeFragment(r.content));
85
+ const s = u(o.innerHTML), l = o.textContent ?? "";
87
86
  return { html: s, text: l, isEmpty: !l.trim(), characterCount: l.length };
88
87
  }
89
- function S(e, n) {
88
+ function x(e, t) {
90
89
  const i = document.createElement("div");
91
- return i.innerHTML = n, a.fromSchema(e.schema).parse(i, {
90
+ return i.innerHTML = t, a.fromSchema(e.schema).parse(i, {
92
91
  preserveWhitespace: !0
93
92
  }).content;
94
93
  }
95
- function P(e, n, i) {
96
- const t = f(e, n);
97
- if (t === -1) {
98
- const l = e.state.doc.content.size, h = d(n) + i;
94
+ function z(e, t, i) {
95
+ const n = f(e, t);
96
+ if (n === -1) {
97
+ const l = e.state.doc.content.size, h = d(t) + i;
99
98
  e.commands.insertContentAt(l, h, {
100
99
  updateSelection: !1
101
100
  });
102
101
  return;
103
102
  }
104
- const o = m(e, n), r = S(e, i), { tr: c } = e.state, s = n === "body" ? 0 : t;
105
- c.replaceWith(s, o, r), c.setMeta("addToHistory", !1), e.view.dispatch(c);
103
+ const r = m(e, t), o = x(e, i), { tr: c } = e.state, s = t === "body" ? 0 : n;
104
+ c.replaceWith(s, r, o), c.setMeta("addToHistory", !1), e.view.dispatch(c);
106
105
  }
107
- function D(e) {
108
- return x(e, "body");
106
+ function N(e) {
107
+ return A(e, "body");
109
108
  }
110
- function F(e) {
109
+ function P(e) {
111
110
  return {
112
111
  bold: e.isActive("bold"),
113
112
  italic: e.isActive("italic"),
@@ -120,17 +119,17 @@ function F(e) {
120
119
  link: (() => {
121
120
  if (e.isActive("link"))
122
121
  return { href: e.getAttributes("link").href ?? "" };
123
- const { $from: n } = e.state.selection;
124
- if (n.pos > 0) {
125
- const t = n.doc.resolve(n.pos).marks().find((o) => o.type.name === "link");
126
- if (t)
127
- return { href: t.attrs.href ?? "" };
122
+ const { $from: t } = e.state.selection;
123
+ if (t.pos > 0) {
124
+ const n = t.doc.resolve(t.pos).marks().find((r) => r.type.name === "link");
125
+ if (n)
126
+ return { href: n.attrs.href ?? "" };
128
127
  {
129
- const r = n.nodeBefore?.marks.find(
128
+ const o = t.nodeBefore?.marks.find(
130
129
  (c) => c.type.name === "link"
131
130
  );
132
- if (r)
133
- return { href: r.attrs.href ?? "" };
131
+ if (o)
132
+ return { href: o.attrs.href ?? "" };
134
133
  }
135
134
  }
136
135
  return null;
@@ -144,84 +143,84 @@ function F(e) {
144
143
  subscript: e.isActive("subscript")
145
144
  };
146
145
  }
147
- function I(e) {
148
- const n = u(e.getHTML()), i = g(e.state.doc.content), t = e.schema.node("doc", null, i), o = t.textBetween(0, t.content.size, `
146
+ function D(e) {
147
+ const t = u(e.getHTML()), i = v(e.state.doc.content), n = e.schema.node("doc", null, i), r = n.textBetween(0, n.content.size, `
149
148
 
150
149
  `, `
151
150
  `);
152
151
  return {
153
- html: n,
154
- text: o,
152
+ html: t,
153
+ text: r,
155
154
  isEmpty: e.isEmpty,
156
- characterCount: o.length
155
+ characterCount: r.length
157
156
  };
158
157
  }
159
- function f(e, n) {
160
- if (n === "body") return 1;
158
+ function f(e, t) {
159
+ if (t === "body") return 1;
161
160
  let i = -1;
162
- return e.state.doc.descendants((t, o) => {
161
+ return e.state.doc.descendants((n, r) => {
163
162
  if (i !== -1) return !1;
164
- t.type.name === "sectionDivider" && t.attrs.sectionId === n && (i = o + t.nodeSize);
163
+ n.type.name === "sectionDivider" && n.attrs.sectionId === t && (i = r + n.nodeSize);
165
164
  }), i;
166
165
  }
167
- function m(e, n) {
168
- const i = e.state.doc, t = i.content.size;
169
- if (n === "body") {
166
+ function m(e, t) {
167
+ const i = e.state.doc, n = i.content.size;
168
+ if (t === "body") {
170
169
  let c = -1;
171
170
  return i.descendants((s, l) => {
172
171
  if (c !== -1) return !1;
173
172
  s.type.name === "sectionDivider" && (c = l);
174
- }), c !== -1 ? c : t;
173
+ }), c !== -1 ? c : n;
175
174
  }
176
- let o = !1, r = -1;
175
+ let r = !1, o = -1;
177
176
  return i.descendants((c, s) => {
178
- if (r !== -1) return !1;
179
- if (!o)
180
- return c.type.name === "sectionDivider" && c.attrs.sectionId === n && (o = !0), !1;
181
- c.type.name === "sectionDivider" && (r = s);
182
- }), r !== -1 ? r : t;
177
+ if (o !== -1) return !1;
178
+ if (!r)
179
+ return c.type.name === "sectionDivider" && c.attrs.sectionId === t && (r = !0), !1;
180
+ c.type.name === "sectionDivider" && (o = s);
181
+ }), o !== -1 ? o : n;
183
182
  }
184
- function C(e) {
183
+ function S(e) {
185
184
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
186
185
  }
187
- function H(e) {
188
- return `<pre><code>${C(e ?? "")}</code></pre>`;
186
+ function C(e) {
187
+ return `<pre><code>${S(e ?? "")}</code></pre>`;
189
188
  }
190
- function O(e) {
191
- let n = "", i = !1;
192
- return e.state.doc.descendants((t) => {
189
+ function F(e) {
190
+ let t = "", i = !1;
191
+ return e.state.doc.descendants((n) => {
193
192
  if (i) return !1;
194
- if (t.type.name === "codeBlock")
195
- return n = t.textContent, i = !0, !1;
196
- }), n;
193
+ if (n.type.name === "codeBlock")
194
+ return t = n.textContent, i = !0, !1;
195
+ }), t;
197
196
  }
198
- function q(e, n) {
199
- e.commands.setContent(H(n), { emitUpdate: !0 });
197
+ function I(e, t) {
198
+ e.commands.setContent(C(t), { emitUpdate: !0 });
200
199
  }
201
- function k(e, n) {
202
- const t = e.slice(0, Math.max(0, n)).split(`
200
+ function k(e, t) {
201
+ const n = e.slice(0, Math.max(0, t)).split(`
203
202
  `);
204
203
  return {
205
- line: t.length,
206
- column: (t[t.length - 1]?.length ?? 0) + 1
204
+ line: n.length,
205
+ column: (n[n.length - 1]?.length ?? 0) + 1
207
206
  };
208
207
  }
209
- function E(e, n) {
210
- const i = e.replace(/\s*in JSON at position[\s\S]*$/i, "").trim() || e, t = e.match(/line (\d+) column (\d+)/i);
211
- if (t)
208
+ function H(e, t) {
209
+ const i = e.replace(/\s*in JSON at position[\s\S]*$/i, "").trim() || e, n = e.match(/line (\d+) column (\d+)/i);
210
+ if (n)
212
211
  return {
213
212
  message: i,
214
- line: Number(t[1]),
215
- column: Number(t[2])
213
+ line: Number(n[1]),
214
+ column: Number(n[2])
216
215
  };
217
- const o = e.match(/position (\d+)/i);
218
- if (o) {
219
- const { line: r, column: c } = k(n, Number(o[1]));
220
- return { message: i, line: r, column: c };
216
+ const r = e.match(/position (\d+)/i);
217
+ if (r) {
218
+ const { line: o, column: c } = k(t, Number(r[1]));
219
+ return { message: i, line: o, column: c };
221
220
  }
222
221
  return { message: i, line: null, column: null };
223
222
  }
224
- function w(e) {
223
+ function O(e) {
225
224
  if (!e.trim())
226
225
  return { valid: !0, value: null, error: null, line: null, column: null };
227
226
  try {
@@ -232,33 +231,33 @@ function w(e) {
232
231
  line: null,
233
232
  column: null
234
233
  };
235
- } catch (n) {
236
- const { message: i, line: t, column: o } = E(
237
- n.message,
234
+ } catch (t) {
235
+ const { message: i, line: n, column: r } = H(
236
+ t.message,
238
237
  e
239
238
  );
240
- return { valid: !1, value: null, error: i, line: t, column: o };
239
+ return { valid: !1, value: null, error: i, line: n, column: r };
241
240
  }
242
241
  }
243
242
  export {
244
243
  d as SECTION_DIVIDER_HTML,
245
- H as buildJsonCodeBlockHtml,
246
- M as buildSectionedContent,
247
- F as extractActiveFormats,
248
- A as extractAllSectionsFromHtml,
249
- D as extractBodyContent,
250
- I as extractContent,
251
- x as extractSectionContent,
244
+ C as buildJsonCodeBlockHtml,
245
+ B as buildSectionedContent,
246
+ P as extractActiveFormats,
247
+ y as extractAllSectionsFromHtml,
248
+ N as extractBodyContent,
249
+ D as extractContent,
250
+ A as extractSectionContent,
252
251
  m as findSectionEndPos,
253
252
  f as findSectionStartPos,
254
- y as getBodyHtml,
255
- O as getCodeBlockText,
256
- N as getSectionsHtml,
257
- B as insertInlineHtml,
258
- b as normalizeHtml,
259
- w as parseJson,
260
- q as setCodeBlockText,
261
- P as setSectionContentInEditor,
253
+ b as getBodyHtml,
254
+ F as getCodeBlockText,
255
+ M as getSectionsHtml,
256
+ L as insertInlineHtml,
257
+ g as normalizeHtml,
258
+ O as parseJson,
259
+ I as setCodeBlockText,
260
+ z as setSectionContentInEditor,
262
261
  u as toPortableHtml
263
262
  };
264
263
  //# sourceMappingURL=BikEditor.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BikEditor.utils.js","sources":["../../../src/editor/BikEditor.utils.ts"],"sourcesContent":["import { Editor } from '@tiptap/core';\nimport { DOMParser, DOMSerializer } from 'prosemirror-model';\nimport { sanitizeEmailHtml } from '../helpers/sanitize';\nimport {\n\tEditorSnapshot,\n\tFormatState,\n\tJsonParseResult,\n} from './BikEditor.types';\nimport { normalizeHardBreaks } from './extensions/plainClipboard/pasteUtils';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * 1. Unwrap style-less `<span>` wrappers (plain spans, and editor-cursor spans\n * like Quill's `<span class=\"ql-cursor\">`). Spans that carry inline styling\n * (`color` / `font-family` / `font-size` render as styled spans) or that\n * represent a `{{variable}}` token are PRESERVED — otherwise a setContent\n * round-trip would silently drop colour/font formatting that paste keeps.\n * 2. Collapse placeholder paragraphs (`<p><br></p>`) to `<p></p>`. ProseMirror\n * parses `<p></p>` as an empty paragraph and adds its own DOM `<br>` for the\n * cursor — one blank line, correct height. Leaving the source `<br>` would\n * create a `hard_break` child AND the cursor `<br>` → double-height blank line.\n *\n * Uses the DOM (regex cannot selectively pair span tags). `normalizeHtml` runs\n * in the component body for `initialContent`, so it is guarded for SSR: the\n * editor is created lazily on the client (`immediatelyRender: false`), meaning\n * the value is only parsed client-side and passing through on the server is safe.\n */\nexport function normalizeHtml(\n\thtml: string,\n\tsanitizer: (input: string) => string = sanitizeEmailHtml,\n): string {\n\tif (!html || typeof document === 'undefined') return html;\n\n\t// Security boundary: every HTML string entering the editor (initialContent,\n\t// setContent, insertHtml, setBody/SectionContent) passes through here.\n\t// Sanitise BEFORE ProseMirror parses it — the schema drops unknown nodes,\n\t// but does NOT validate attributes it keeps (link href / image src), so we\n\t// strip scripts/handlers/dangerous schemes up front.\n\t// Email channels use sanitizeEmailHtml (tables, images, inline style);\n\t// non-email channels (WhatsApp, IG, private note) use sanitizeBasicHtml\n\t// (formatting allowlist only — no tables/images/style).\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = sanitizer(html);\n\n\tcontainer.querySelectorAll('span').forEach((span) => {\n\t\t// Keep schema-backed spans: styled spans, variables, and mention chips\n\t\t// (`data-type=\"mention…\"`). Stripping a mention span would drop the\n\t\t// `data-id`/`data-label`/`data-kind` the editor needs to reparse it.\n\t\tconst dataType = span.getAttribute('data-type');\n\t\tif (\n\t\t\tspan.hasAttribute('style') ||\n\t\t\tspan.hasAttribute('data-variable') ||\n\t\t\t(dataType !== null && dataType.startsWith('mention'))\n\t\t)\n\t\t\treturn;\n\t\tconst parent = span.parentNode;\n\t\tif (!parent) return;\n\t\twhile (span.firstChild) parent.insertBefore(span.firstChild, span);\n\t\tparent.removeChild(span);\n\t});\n\n\tcontainer.querySelectorAll('p').forEach((p) => {\n\t\tif (\n\t\t\tp.querySelectorAll('br').length === 1 &&\n\t\t\t(p.textContent ?? '').trim() === ''\n\t\t) {\n\t\t\tp.innerHTML = '';\n\t\t}\n\t});\n\n\treturn container.innerHTML;\n}\n\n/**\n * Make editor HTML portable across email clients and chat renderers.\n *\n * 1. Preserve consecutive spaces by converting every second space in a run\n * to `&nbsp;` (U+00A0). Standard HTML collapses adjacent regular spaces;\n * alternating with `&nbsp;` prevents that — same convention Gmail uses.\n * 2. Double a trailing `<br>` in content paragraphs so the blank line is\n * visible. A single trailing `<br>` before `</p>` is swallowed by most\n * email clients; `<br><br>` renders as a visible blank line (matches\n * Gmail's output).\n * 3. Convert empty `<p></p>` to `<p><br></p>` — email clients collapse\n * zero-height paragraphs without a `<br>`.\n */\nexport function toPortableHtml(html: string): string {\n\tconst div = document.createElement('div');\n\tdiv.innerHTML = html;\n\n\t// TreeWalker visits only text nodes, skipping HTML tags/attributes, so we safely\n\t// replace consecutive spaces with space + \\u00a0 (nbsp) to prevent email clients from collapsing them\n\tconst walker = document.createTreeWalker(div, NodeFilter.SHOW_TEXT);\n\tlet textNode: Text | null;\n\twhile ((textNode = walker.nextNode() as Text | null)) {\n\t\tif (textNode.nodeValue && textNode.nodeValue.includes(' ')) {\n\t\t\ttextNode.nodeValue = textNode.nodeValue.replace(/ {2}/g, '  ');\n\t\t}\n\t}\n\n\tconst blocks = div.querySelectorAll('p');\n\tfor (const p of Array.from(blocks)) {\n\t\tif (p.childNodes.length === 0) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t\tcontinue;\n\t\t}\n\t\tconst last = p.lastChild;\n\t\tif (last instanceof HTMLBRElement && p.childNodes.length > 1) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t}\n\t}\n\treturn div.innerHTML;\n}\n\n// ---------------------------------------------------------------------------\n// Inline content insertion\n// ---------------------------------------------------------------------------\n\n/**\n * Insert HTML at the current cursor position, merging the first paragraph\n * inline while preserving the block structure of subsequent paragraphs/lists.\n *\n * Uses `parseSlice` which returns an open-ended Slice — the first block merges\n * at the cursor, middle blocks stay intact, and the last block merges with any\n * text that follows the cursor.\n */\nexport function insertInlineHtml(editor: Editor, html: string): void {\n\tconst normalised = normalizeHtml(html);\n\tconst dom = document.createElement('div');\n\tdom.innerHTML = normalised;\n\tconst slice = DOMParser.fromSchema(editor.schema).parseSlice(dom, {\n\t\tpreserveWhitespace: true,\n\t});\n\n\tif (slice.size === 0) return;\n\n\tconst { from, to } = editor.state.selection;\n\tconst tr = editor.state.tr.replaceRange(from, to, slice);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Section divider HTML\n// ---------------------------------------------------------------------------\n\nexport const SECTION_DIVIDER_HTML = (id: string) =>\n\t`<div data-section-divider=\"${id}\" style=\"display:none;height:0;line-height:0;overflow:hidden;\"></div>`;\n\n/**\n * Build initial HTML for an editor with one or more named sections below the body.\n * Each section is separated by an invisible divider node.\n *\n * @example\n * buildSectionedContent('<p>Body</p>', [\n * { id: 'signature', content: '<p>Alice</p>' },\n * { id: 'forwarded', content: '<p>--- fwd ---</p>' },\n * ])\n */\nexport function buildSectionedContent(\n\tbody: string,\n\tsections: Array<{ id: string; content: string }>,\n): string {\n\tlet html = body;\n\tfor (const s of sections) {\n\t\thtml += SECTION_DIVIDER_HTML(s.id) + s.content;\n\t}\n\treturn html;\n}\n\n// ---------------------------------------------------------------------------\n// Section extraction\n// ---------------------------------------------------------------------------\n\n/**\n * Parse the editor HTML into a Map of sectionId → raw HTML string.\n * The special key `'body'` always holds the content before the first divider.\n * Map iteration order matches document order.\n */\nexport function extractAllSections(editor: Editor): Map<string, string> {\n\treturn extractAllSectionsFromHtml(editor.getHTML());\n}\n\n/**\n * Extract just the body portion (everything before the first section divider)\n * from an HTML string produced by BikEditor. Safe to call on plain HTML too —\n * returns the full string when no dividers are present.\n */\nexport function getBodyHtml(html: string): string {\n\tif (!html) return '';\n\tconst sections = extractAllSectionsFromHtml(html);\n\treturn sections.get('body') ?? html;\n}\n\n/**\n * Extract everything from the first section divider onward (dividers + their\n * content). Returns an empty string when there are no sections.\n */\nexport function getSectionsHtml(html: string): string {\n\tif (!html) return '';\n\tconst body = getBodyHtml(html);\n\treturn html.substring(body.length);\n}\n\nexport function extractAllSectionsFromHtml(html: string): Map<string, string> {\n\tconst sections = new Map<string, string>();\n\tconst dividerRegex =\n\t\t/<div[^>]*data-section-divider=\"([^\"]*)[^>]*>\\s*<\\/div>/g;\n\tconst dividers: Array<{ id: string; index: number; endIndex: number }> = [];\n\n\tlet match: RegExpExecArray | null;\n\twhile ((match = dividerRegex.exec(html)) !== null) {\n\t\tdividers.push({\n\t\t\tid: match[1],\n\t\t\tindex: match.index,\n\t\t\tendIndex: match.index + match[0].length,\n\t\t});\n\t}\n\n\tif (dividers.length === 0) {\n\t\tsections.set('body', html);\n\t\treturn sections;\n\t}\n\n\tsections.set('body', html.slice(0, dividers[0].index));\n\tfor (let i = 0; i < dividers.length; i++) {\n\t\tconst start = dividers[i].endIndex;\n\t\tconst end = i + 1 < dividers.length ? dividers[i + 1].index : html.length;\n\t\tsections.set(dividers[i].id, html.slice(start, end));\n\t}\n\n\treturn sections;\n}\n\n/** Returns BikEditorContent for a single named section (or 'body'). */\nexport function extractSectionContent(\n\teditor: Editor,\n\tid: string,\n): EditorSnapshot {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1)\n\t\treturn { html: '', text: '', isEmpty: true, characterCount: 0 };\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst slice = editor.state.doc.slice(startPos, endPos);\n\tconst container = document.createElement('div');\n\tconst serializer = DOMSerializer.fromSchema(editor.schema);\n\tcontainer.appendChild(serializer.serializeFragment(slice.content));\n\tconst html = toPortableHtml(container.innerHTML);\n\tconst text = container.textContent ?? '';\n\treturn { html, text, isEmpty: !text.trim(), characterCount: text.length };\n}\n\n/**\n * Parse an HTML string into ProseMirror nodes using the editor's schema.\n */\nfunction parseHtmlToNodes(editor: Editor, html: string) {\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\treturn DOMParser.fromSchema(editor.schema).parse(container, {\n\t\tpreserveWhitespace: true,\n\t}).content;\n}\n\n/**\n * Replace the content of a single named section without touching others.\n * Uses a ProseMirror transaction to replace only the target range,\n * preserving undo history and other sections' state.\n * If the section doesn't exist yet, it is appended at the end of the document.\n */\nexport function setSectionContentInEditor(\n\teditor: Editor,\n\tid: string,\n\thtml: string,\n): void {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1) {\n\t\tconst endPos = editor.state.doc.content.size;\n\t\tconst dividerHtml = SECTION_DIVIDER_HTML(id) + html;\n\t\teditor.commands.insertContentAt(endPos, dividerHtml, {\n\t\t\tupdateSelection: false,\n\t\t});\n\t\treturn;\n\t}\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst fragment = parseHtmlToNodes(editor, html);\n\tconst { tr } = editor.state;\n\t// For body, replace from position 0 (before the first paragraph's opening\n\t// boundary) so ProseMirror swaps entire block nodes cleanly. Position 1\n\t// (inside the paragraph) would force ProseMirror to close the open paragraph\n\t// first, creating a ghost empty <p></p>.\n\tconst replaceFrom = id === 'body' ? 0 : startPos;\n\ttr.replaceWith(replaceFrom, endPos, fragment);\n\ttr.setMeta('addToHistory', false);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Convenience shorthands (body = first section)\n// ---------------------------------------------------------------------------\n\n/** Extract BikEditorContent for just the body (before the first divider). */\nexport function extractBodyContent(editor: Editor): EditorSnapshot {\n\treturn extractSectionContent(editor, 'body');\n}\n\n// ---------------------------------------------------------------------------\n// Active formats\n// ---------------------------------------------------------------------------\n\nexport function extractActiveFormats(editor: Editor): FormatState {\n\treturn {\n\t\tbold: editor.isActive('bold'),\n\t\titalic: editor.isActive('italic'),\n\t\tunderline: editor.isActive('underline'),\n\t\tstrike: editor.isActive('strike'),\n\t\tbulletList: editor.isActive('bulletList'),\n\t\torderedList: editor.isActive('orderedList'),\n\t\tblockquote: editor.isActive('blockquote'),\n\t\tcodeBlock: editor.isActive('codeBlock'),\n\t\tlink: (() => {\n\t\t\tif (editor.isActive('link')) {\n\t\t\t\treturn { href: editor.getAttributes('link')['href'] ?? '' };\n\t\t\t}\n\t\t\tconst { $from } = editor.state.selection;\n\t\t\tif ($from.pos > 0) {\n\t\t\t\tconst before = $from.doc.resolve($from.pos);\n\t\t\t\tconst linkMark = before.marks().find((m) => m.type.name === 'link');\n\t\t\t\tif (!linkMark) {\n\t\t\t\t\tconst nodeBefore = $from.nodeBefore;\n\t\t\t\t\tconst markOnPrev = nodeBefore?.marks.find(\n\t\t\t\t\t\t(m) => m.type.name === 'link',\n\t\t\t\t\t);\n\t\t\t\t\tif (markOnPrev) {\n\t\t\t\t\t\treturn { href: markOnPrev.attrs['href'] ?? '' };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn { href: linkMark.attrs['href'] ?? '' };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t})(),\n\t\ttextAlign: editor.isActive({ textAlign: 'center' })\n\t\t\t? 'center'\n\t\t\t: editor.isActive({ textAlign: 'right' })\n\t\t\t? 'right'\n\t\t\t: editor.isActive({ textAlign: 'justify' })\n\t\t\t? 'justify'\n\t\t\t: editor.isActive({ textAlign: 'left' })\n\t\t\t? 'left'\n\t\t\t: null,\n\t\tfontFamily: editor.getAttributes('textStyle')['fontFamily'] ?? null,\n\t\tfontSize: editor.getAttributes('textStyle')['fontSize'] ?? null,\n\t\tcolor: editor.getAttributes('textStyle')['color'] ?? null,\n\t\thighlight: editor.isActive('highlight')\n\t\t\t? editor.getAttributes('highlight')['color'] ?? 'default'\n\t\t\t: null,\n\t\tsuperscript: editor.isActive('superscript'),\n\t\tsubscript: editor.isActive('subscript'),\n\t};\n}\n\nexport function extractContent(editor: Editor): EditorSnapshot {\n\tconst html = toPortableHtml(editor.getHTML());\n\tconst normalized = normalizeHardBreaks(editor.state.doc.content);\n\tconst tempDoc = editor.schema.node('doc', null, normalized);\n\t// Paragraph boundary → blank line (\\n\\n), soft line break (hardBreak) → \\n.\n\t// Matches Gmail's plain-text output for the same content.\n\tconst text = tempDoc.textBetween(0, tempDoc.content.size, '\\n\\n', '\\n');\n\treturn {\n\t\thtml,\n\t\ttext,\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount: text.length,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Section position helpers (used by insertAtSectionStart/End and appendBodyContent)\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the ProseMirror position immediately after a section's opening divider\n * (i.e. the start of the section's own content).\n * For `'body'`, returns 1 (beginning of the document).\n * Returns -1 if the named section's divider is not found.\n */\nexport function findSectionStartPos(editor: Editor, sectionId: string): number {\n\tif (sectionId === 'body') return 1;\n\tlet startPos = -1;\n\teditor.state.doc.descendants((node, pos) => {\n\t\tif (startPos !== -1) return false;\n\t\tif (\n\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t) {\n\t\t\tstartPos = pos + node.nodeSize; // position right after the divider\n\t\t}\n\t});\n\treturn startPos;\n}\n\n/**\n * Returns the ProseMirror position at the end of a named section's content:\n * - For `'body'`: position of the first section divider, or end of document.\n * - For a named section: position of the next divider, or end of document.\n */\nexport function findSectionEndPos(editor: Editor, sectionId: string): number {\n\tconst doc = editor.state.doc;\n\tconst docSize = doc.content.size;\n\n\tif (sectionId === 'body') {\n\t\tlet firstDividerPos = -1;\n\t\tdoc.descendants((node, pos) => {\n\t\t\tif (firstDividerPos !== -1) return false;\n\t\t\tif (node.type.name === 'sectionDivider') {\n\t\t\t\tfirstDividerPos = pos;\n\t\t\t}\n\t\t});\n\t\treturn firstDividerPos !== -1 ? firstDividerPos : docSize;\n\t}\n\n\tlet passedSection = false;\n\tlet nextDividerPos = -1;\n\tdoc.descendants((node, pos) => {\n\t\tif (nextDividerPos !== -1) return false;\n\t\tif (!passedSection) {\n\t\t\tif (\n\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t) {\n\t\t\t\tpassedSection = true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (node.type.name === 'sectionDivider') {\n\t\t\tnextDividerPos = pos;\n\t\t}\n\t});\n\treturn nextDividerPos !== -1 ? nextDividerPos : docSize;\n}\n\n// ---------------------------------------------------------------------------\n// JSON body helpers (used when features.jsonMode is on — the whole document is\n// a single code block whose text is raw JSON, Postman-style)\n// ---------------------------------------------------------------------------\n\nfunction escapeHtml(raw: string): string {\n\treturn raw.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n}\n\n/**\n * Wrap a raw JSON string in a `<pre><code>` code block so TipTap parses it as a\n * single code-block node (the container for JSON body mode).\n */\nexport function buildJsonCodeBlockHtml(raw: string): string {\n\treturn `<pre><code>${escapeHtml(raw ?? '')}</code></pre>`;\n}\n\n/** Returns the raw text of the first code block in the document (empty if none). */\nexport function getCodeBlockText(editor: Editor): string {\n\tlet text = '';\n\tlet found = false;\n\teditor.state.doc.descendants((node) => {\n\t\tif (found) return false;\n\t\tif (node.type.name === 'codeBlock') {\n\t\t\ttext = node.textContent;\n\t\t\tfound = true;\n\t\t\treturn false;\n\t\t}\n\t\treturn undefined;\n\t});\n\treturn text;\n}\n\n/**\n * Replace the text of the first code block with `raw`, keeping it a code block.\n * Falls back to replacing the whole document when no code block exists yet.\n */\nexport function setCodeBlockText(editor: Editor, raw: string): void {\n\teditor.commands.setContent(buildJsonCodeBlockHtml(raw), { emitUpdate: true });\n}\n\n/** 1-based line/column of a 0-based character offset within `text`. */\nfunction offsetToLineCol(\n\ttext: string,\n\toffset: number,\n): { line: number; column: number } {\n\tconst before = text.slice(0, Math.max(0, offset));\n\tconst lines = before.split('\\n');\n\treturn {\n\t\tline: lines.length,\n\t\tcolumn: (lines[lines.length - 1]?.length ?? 0) + 1,\n\t};\n}\n\n/**\n * Turn a raw `JSON.parse` error into a clean message + location. Engine messages\n * look like `\"Bad control character in string literal in JSON at position 94\n * (line 7 column 9)\"` — we strip the `\"in JSON at position …\"` tail for the\n * message and pull the line/column from it (falling back to computing them from\n * the position offset when the engine omits them).\n */\nfunction describeJsonError(\n\trawMessage: string,\n\ttext: string,\n): { message: string; line: number | null; column: number | null } {\n\tconst message =\n\t\trawMessage.replace(/\\s*in JSON at position[\\s\\S]*$/i, '').trim() ||\n\t\trawMessage;\n\n\tconst lineCol = rawMessage.match(/line (\\d+) column (\\d+)/i);\n\tif (lineCol) {\n\t\treturn {\n\t\t\tmessage,\n\t\t\tline: Number(lineCol[1]),\n\t\t\tcolumn: Number(lineCol[2]),\n\t\t};\n\t}\n\n\tconst posMatch = rawMessage.match(/position (\\d+)/i);\n\tif (posMatch) {\n\t\tconst { line, column } = offsetToLineCol(text, Number(posMatch[1]));\n\t\treturn { message, line, column };\n\t}\n\n\treturn { message, line: null, column: null };\n}\n\n/** Parse a JSON string without throwing. Empty / whitespace-only text is valid. */\nexport function parseJson(text: string): JsonParseResult {\n\tif (!text.trim()) {\n\t\treturn { valid: true, value: null, error: null, line: null, column: null };\n\t}\n\ttry {\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\tvalue: JSON.parse(text),\n\t\t\terror: null,\n\t\t\tline: null,\n\t\t\tcolumn: null,\n\t\t};\n\t} catch (e) {\n\t\tconst { message, line, column } = describeJsonError(\n\t\t\t(e as Error).message,\n\t\t\ttext,\n\t\t);\n\t\treturn { valid: false, value: null, error: message, line, column };\n\t}\n}\n"],"names":["normalizeHtml","html","sanitizer","sanitizeEmailHtml","container","span","dataType","parent","p","toPortableHtml","div","walker","textNode","blocks","insertInlineHtml","editor","normalised","dom","slice","DOMParser","from","to","tr","SECTION_DIVIDER_HTML","id","buildSectionedContent","body","sections","s","getBodyHtml","extractAllSectionsFromHtml","getSectionsHtml","dividerRegex","dividers","match","i","start","end","extractSectionContent","startPos","findSectionStartPos","endPos","findSectionEndPos","serializer","DOMSerializer","text","parseHtmlToNodes","setSectionContentInEditor","dividerHtml","fragment","replaceFrom","extractBodyContent","extractActiveFormats","$from","linkMark","m","markOnPrev","extractContent","normalized","normalizeHardBreaks","tempDoc","sectionId","node","pos","doc","docSize","firstDividerPos","passedSection","nextDividerPos","escapeHtml","raw","buildJsonCodeBlockHtml","getCodeBlockText","found","setCodeBlockText","offsetToLineCol","offset","lines","describeJsonError","rawMessage","message","lineCol","posMatch","line","column","parseJson","e"],"mappings":";;;AAgCO,SAASA,EACfC,GACAC,IAAuCC,GAC9B;AACT,MAAI,CAACF,KAAQ,OAAO,WAAa,IAAa,QAAOA;AAUrD,QAAMG,IAAY,SAAS,cAAc,KAAK;AAC9C,SAAAA,EAAU,YAAYF,EAAUD,CAAI,GAEpCG,EAAU,iBAAiB,MAAM,EAAE,QAAQ,CAACC,MAAS;AAIpD,UAAMC,IAAWD,EAAK,aAAa,WAAW;AAC9C,QACCA,EAAK,aAAa,OAAO,KACzBA,EAAK,aAAa,eAAe,KAChCC,MAAa,QAAQA,EAAS,WAAW,SAAS;AAEnD;AACD,UAAMC,IAASF,EAAK;AACpB,QAAKE,GACL;AAAA,aAAOF,EAAK,aAAY,CAAAE,EAAO,aAAaF,EAAK,YAAYA,CAAI;AACjE,MAAAE,EAAO,YAAYF,CAAI;AAAA;AAAA,EACxB,CAAC,GAEDD,EAAU,iBAAiB,GAAG,EAAE,QAAQ,CAACI,MAAM;AAC9C,IACCA,EAAE,iBAAiB,IAAI,EAAE,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AA,EAAA;AAEnD;AASA,SAASC,EACRC,GACAlC,GACkE;AAClE,QAAMmC,IACLD,EAAW,QAAQ,mCAAmC,EAAE,EAAE,UAC1DA,GAEKE,IAAUF,EAAW,MAAM,0BAA0B;AAC3D,MAAIE;AACH,WAAO;AAAA,MACN,SAAAD;AAAA,MACA,MAAM,OAAOC,EAAQ,CAAC,CAAC;AAAA,MACvB,QAAQ,OAAOA,EAAQ,CAAC,CAAC;AAAA,IAAA;AAI3B,QAAMC,IAAWH,EAAW,MAAM,iBAAiB;AACnD,MAAIG,GAAU;AACb,UAAM,EAAE,MAAAC,GAAM,QAAAC,EAAA,IAAWT,EAAgB9B,GAAM,OAAOqC,EAAS,CAAC,CAAC,CAAC;AAClE,WAAO,EAAE,SAAAF,GAAS,MAAAG,GAAM,QAAAC,EAAA;AAAA,EACzB;AAEA,SAAO,EAAE,SAAAJ,GAAS,MAAM,MAAM,QAAQ,KAAA;AACvC;AAGO,SAASK,EAAUxC,GAA+B;AACxD,MAAI,CAACA,EAAK;AACT,WAAO,EAAE,OAAO,IAAM,OAAO,MAAM,OAAO,MAAM,MAAM,MAAM,QAAQ,KAAA;AAErE,MAAI;AACH,WAAO;AAAA,MACN,OAAO;AAAA,MACP,OAAO,KAAK,MAAMA,CAAI;AAAA,MACtB,OAAO;AAAA,MACP,MAAM;AAAA,MACN,QAAQ;AAAA,IAAA;AAAA,EAEV,SAASyC,GAAG;AACX,UAAM,EAAE,SAAAN,GAAS,MAAAG,GAAM,QAAAC,EAAA,IAAWN;AAAA,MAChCQ,EAAY;AAAA,MACbzC;AAAA,IAAA;AAED,WAAO,EAAE,OAAO,IAAO,OAAO,MAAM,OAAOmC,GAAS,MAAAG,GAAM,QAAAC,EAAA;AAAA,EAC3D;AACD;"}
1
+ {"version":3,"file":"BikEditor.utils.js","sources":["../../../src/editor/BikEditor.utils.ts"],"sourcesContent":["import { Editor } from '@tiptap/core';\nimport { DOMParser, DOMSerializer } from 'prosemirror-model';\nimport {\n\tEditorSnapshot,\n\tFormatState,\n\tJsonParseResult,\n} from './BikEditor.types';\nimport { normalizeHardBreaks } from './extensions/plainClipboard/pasteUtils';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * 1. Unwrap style-less `<span>` wrappers (plain spans, and editor-cursor spans\n * like Quill's `<span class=\"ql-cursor\">`). Spans that carry inline styling\n * (`color` / `font-family` / `font-size` render as styled spans) or that\n * represent a `{{variable}}` token are PRESERVED — otherwise a setContent\n * round-trip would silently drop colour/font formatting that paste keeps.\n * 2. Collapse placeholder paragraphs (`<p><br></p>`) to `<p></p>`. ProseMirror\n * parses `<p></p>` as an empty paragraph and adds its own DOM `<br>` for the\n * cursor — one blank line, correct height. Leaving the source `<br>` would\n * create a `hard_break` child AND the cursor `<br>` → double-height blank line.\n *\n * Uses the DOM (regex cannot selectively pair span tags). `normalizeHtml` runs\n * in the component body for `initialContent`, so it is guarded for SSR: the\n * editor is created lazily on the client (`immediatelyRender: false`), meaning\n * the value is only parsed client-side and passing through on the server is safe.\n */\nexport function normalizeHtml(html: string): string {\n\tif (!html || typeof document === 'undefined') return html;\n\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\n\tcontainer.querySelectorAll('span').forEach((span) => {\n\t\t// Keep schema-backed spans: styled spans, variables, and mention chips\n\t\t// (`data-type=\"mention…\"`). Stripping a mention span would drop the\n\t\t// `data-id`/`data-label`/`data-kind` the editor needs to reparse it.\n\t\tconst dataType = span.getAttribute('data-type');\n\t\tif (\n\t\t\tspan.hasAttribute('style') ||\n\t\t\tspan.hasAttribute('data-variable') ||\n\t\t\t(dataType !== null && dataType.startsWith('mention'))\n\t\t)\n\t\t\treturn;\n\t\tconst parent = span.parentNode;\n\t\tif (!parent) return;\n\t\twhile (span.firstChild) parent.insertBefore(span.firstChild, span);\n\t\tparent.removeChild(span);\n\t});\n\n\tcontainer.querySelectorAll('p').forEach((p) => {\n\t\tif (\n\t\t\tp.querySelectorAll('br').length === 1 &&\n\t\t\t(p.textContent ?? '').trim() === ''\n\t\t) {\n\t\t\tp.innerHTML = '';\n\t\t}\n\t});\n\n\treturn container.innerHTML;\n}\n\n/**\n * Make editor HTML portable across email clients and chat renderers.\n *\n * 1. Preserve consecutive spaces by converting every second space in a run\n * to `&nbsp;` (U+00A0). Standard HTML collapses adjacent regular spaces;\n * alternating with `&nbsp;` prevents that — same convention Gmail uses.\n * 2. Double a trailing `<br>` in content paragraphs so the blank line is\n * visible. A single trailing `<br>` before `</p>` is swallowed by most\n * email clients; `<br><br>` renders as a visible blank line (matches\n * Gmail's output).\n * 3. Convert empty `<p></p>` to `<p><br></p>` — email clients collapse\n * zero-height paragraphs without a `<br>`.\n */\nexport function toPortableHtml(html: string): string {\n\tconst div = document.createElement('div');\n\tdiv.innerHTML = html;\n\n\t// TreeWalker visits only text nodes, skipping HTML tags/attributes, so we safely\n\t// replace consecutive spaces with space + \\u00a0 (nbsp) to prevent email clients from collapsing them\n\tconst walker = document.createTreeWalker(div, NodeFilter.SHOW_TEXT);\n\tlet textNode: Text | null;\n\twhile ((textNode = walker.nextNode() as Text | null)) {\n\t\tif (textNode.nodeValue && textNode.nodeValue.includes(' ')) {\n\t\t\ttextNode.nodeValue = textNode.nodeValue.replace(/ {2}/g, '  ');\n\t\t}\n\t}\n\n\tconst blocks = div.querySelectorAll('p');\n\tfor (const p of Array.from(blocks)) {\n\t\tif (p.childNodes.length === 0) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t\tcontinue;\n\t\t}\n\t\tconst last = p.lastChild;\n\t\tif (last instanceof HTMLBRElement && p.childNodes.length > 1) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t}\n\t}\n\treturn div.innerHTML;\n}\n\n// ---------------------------------------------------------------------------\n// Inline content insertion\n// ---------------------------------------------------------------------------\n\n/**\n * Insert HTML at the current cursor position, merging the first paragraph\n * inline while preserving the block structure of subsequent paragraphs/lists.\n *\n * Uses `parseSlice` which returns an open-ended Slice — the first block merges\n * at the cursor, middle blocks stay intact, and the last block merges with any\n * text that follows the cursor.\n */\nexport function insertInlineHtml(editor: Editor, html: string): void {\n\tconst normalised = normalizeHtml(html);\n\tconst dom = document.createElement('div');\n\tdom.innerHTML = normalised;\n\tconst slice = DOMParser.fromSchema(editor.schema).parseSlice(dom, {\n\t\tpreserveWhitespace: true,\n\t});\n\n\tif (slice.size === 0) return;\n\n\tconst { from, to } = editor.state.selection;\n\tconst tr = editor.state.tr.replaceRange(from, to, slice);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Section divider HTML\n// ---------------------------------------------------------------------------\n\nexport const SECTION_DIVIDER_HTML = (id: string) =>\n\t`<div data-section-divider=\"${id}\" style=\"display:none;height:0;line-height:0;overflow:hidden;\"></div>`;\n\n/**\n * Build initial HTML for an editor with one or more named sections below the body.\n * Each section is separated by an invisible divider node.\n *\n * @example\n * buildSectionedContent('<p>Body</p>', [\n * { id: 'signature', content: '<p>Alice</p>' },\n * { id: 'forwarded', content: '<p>--- fwd ---</p>' },\n * ])\n */\nexport function buildSectionedContent(\n\tbody: string,\n\tsections: Array<{ id: string; content: string }>,\n): string {\n\tlet html = body;\n\tfor (const s of sections) {\n\t\thtml += SECTION_DIVIDER_HTML(s.id) + s.content;\n\t}\n\treturn html;\n}\n\n// ---------------------------------------------------------------------------\n// Section extraction\n// ---------------------------------------------------------------------------\n\n/**\n * Parse the editor HTML into a Map of sectionId → raw HTML string.\n * The special key `'body'` always holds the content before the first divider.\n * Map iteration order matches document order.\n */\nexport function extractAllSections(editor: Editor): Map<string, string> {\n\treturn extractAllSectionsFromHtml(editor.getHTML());\n}\n\n/**\n * Extract just the body portion (everything before the first section divider)\n * from an HTML string produced by BikEditor. Safe to call on plain HTML too —\n * returns the full string when no dividers are present.\n */\nexport function getBodyHtml(html: string): string {\n\tif (!html) return '';\n\tconst sections = extractAllSectionsFromHtml(html);\n\treturn sections.get('body') ?? html;\n}\n\n/**\n * Extract everything from the first section divider onward (dividers + their\n * content). Returns an empty string when there are no sections.\n */\nexport function getSectionsHtml(html: string): string {\n\tif (!html) return '';\n\tconst body = getBodyHtml(html);\n\treturn html.substring(body.length);\n}\n\nexport function extractAllSectionsFromHtml(html: string): Map<string, string> {\n\tconst sections = new Map<string, string>();\n\tconst dividerRegex =\n\t\t/<div[^>]*data-section-divider=\"([^\"]*)[^>]*>\\s*<\\/div>/g;\n\tconst dividers: Array<{ id: string; index: number; endIndex: number }> = [];\n\n\tlet match: RegExpExecArray | null;\n\twhile ((match = dividerRegex.exec(html)) !== null) {\n\t\tdividers.push({\n\t\t\tid: match[1],\n\t\t\tindex: match.index,\n\t\t\tendIndex: match.index + match[0].length,\n\t\t});\n\t}\n\n\tif (dividers.length === 0) {\n\t\tsections.set('body', html);\n\t\treturn sections;\n\t}\n\n\tsections.set('body', html.slice(0, dividers[0].index));\n\tfor (let i = 0; i < dividers.length; i++) {\n\t\tconst start = dividers[i].endIndex;\n\t\tconst end = i + 1 < dividers.length ? dividers[i + 1].index : html.length;\n\t\tsections.set(dividers[i].id, html.slice(start, end));\n\t}\n\n\treturn sections;\n}\n\n/** Returns BikEditorContent for a single named section (or 'body'). */\nexport function extractSectionContent(\n\teditor: Editor,\n\tid: string,\n): EditorSnapshot {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1)\n\t\treturn { html: '', text: '', isEmpty: true, characterCount: 0 };\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst slice = editor.state.doc.slice(startPos, endPos);\n\tconst container = document.createElement('div');\n\tconst serializer = DOMSerializer.fromSchema(editor.schema);\n\tcontainer.appendChild(serializer.serializeFragment(slice.content));\n\tconst html = toPortableHtml(container.innerHTML);\n\tconst text = container.textContent ?? '';\n\treturn { html, text, isEmpty: !text.trim(), characterCount: text.length };\n}\n\n/**\n * Parse an HTML string into ProseMirror nodes using the editor's schema.\n */\nfunction parseHtmlToNodes(editor: Editor, html: string) {\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\treturn DOMParser.fromSchema(editor.schema).parse(container, {\n\t\tpreserveWhitespace: true,\n\t}).content;\n}\n\n/**\n * Replace the content of a single named section without touching others.\n * Uses a ProseMirror transaction to replace only the target range,\n * preserving undo history and other sections' state.\n * If the section doesn't exist yet, it is appended at the end of the document.\n */\nexport function setSectionContentInEditor(\n\teditor: Editor,\n\tid: string,\n\thtml: string,\n): void {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1) {\n\t\tconst endPos = editor.state.doc.content.size;\n\t\tconst dividerHtml = SECTION_DIVIDER_HTML(id) + html;\n\t\teditor.commands.insertContentAt(endPos, dividerHtml, {\n\t\t\tupdateSelection: false,\n\t\t});\n\t\treturn;\n\t}\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst fragment = parseHtmlToNodes(editor, html);\n\tconst { tr } = editor.state;\n\t// For body, replace from position 0 (before the first paragraph's opening\n\t// boundary) so ProseMirror swaps entire block nodes cleanly. Position 1\n\t// (inside the paragraph) would force ProseMirror to close the open paragraph\n\t// first, creating a ghost empty <p></p>.\n\tconst replaceFrom = id === 'body' ? 0 : startPos;\n\ttr.replaceWith(replaceFrom, endPos, fragment);\n\ttr.setMeta('addToHistory', false);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Convenience shorthands (body = first section)\n// ---------------------------------------------------------------------------\n\n/** Extract BikEditorContent for just the body (before the first divider). */\nexport function extractBodyContent(editor: Editor): EditorSnapshot {\n\treturn extractSectionContent(editor, 'body');\n}\n\n// ---------------------------------------------------------------------------\n// Active formats\n// ---------------------------------------------------------------------------\n\nexport function extractActiveFormats(editor: Editor): FormatState {\n\treturn {\n\t\tbold: editor.isActive('bold'),\n\t\titalic: editor.isActive('italic'),\n\t\tunderline: editor.isActive('underline'),\n\t\tstrike: editor.isActive('strike'),\n\t\tbulletList: editor.isActive('bulletList'),\n\t\torderedList: editor.isActive('orderedList'),\n\t\tblockquote: editor.isActive('blockquote'),\n\t\tcodeBlock: editor.isActive('codeBlock'),\n\t\tlink: (() => {\n\t\t\tif (editor.isActive('link')) {\n\t\t\t\treturn { href: editor.getAttributes('link')['href'] ?? '' };\n\t\t\t}\n\t\t\tconst { $from } = editor.state.selection;\n\t\t\tif ($from.pos > 0) {\n\t\t\t\tconst before = $from.doc.resolve($from.pos);\n\t\t\t\tconst linkMark = before.marks().find((m) => m.type.name === 'link');\n\t\t\t\tif (!linkMark) {\n\t\t\t\t\tconst nodeBefore = $from.nodeBefore;\n\t\t\t\t\tconst markOnPrev = nodeBefore?.marks.find(\n\t\t\t\t\t\t(m) => m.type.name === 'link',\n\t\t\t\t\t);\n\t\t\t\t\tif (markOnPrev) {\n\t\t\t\t\t\treturn { href: markOnPrev.attrs['href'] ?? '' };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn { href: linkMark.attrs['href'] ?? '' };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t})(),\n\t\ttextAlign: editor.isActive({ textAlign: 'center' })\n\t\t\t? 'center'\n\t\t\t: editor.isActive({ textAlign: 'right' })\n\t\t\t? 'right'\n\t\t\t: editor.isActive({ textAlign: 'justify' })\n\t\t\t? 'justify'\n\t\t\t: editor.isActive({ textAlign: 'left' })\n\t\t\t? 'left'\n\t\t\t: null,\n\t\tfontFamily: editor.getAttributes('textStyle')['fontFamily'] ?? null,\n\t\tfontSize: editor.getAttributes('textStyle')['fontSize'] ?? null,\n\t\tcolor: editor.getAttributes('textStyle')['color'] ?? null,\n\t\thighlight: editor.isActive('highlight')\n\t\t\t? editor.getAttributes('highlight')['color'] ?? 'default'\n\t\t\t: null,\n\t\tsuperscript: editor.isActive('superscript'),\n\t\tsubscript: editor.isActive('subscript'),\n\t};\n}\n\nexport function extractContent(editor: Editor): EditorSnapshot {\n\tconst html = toPortableHtml(editor.getHTML());\n\tconst normalized = normalizeHardBreaks(editor.state.doc.content);\n\tconst tempDoc = editor.schema.node('doc', null, normalized);\n\t// Paragraph boundary → blank line (\\n\\n), soft line break (hardBreak) → \\n.\n\t// Matches Gmail's plain-text output for the same content.\n\tconst text = tempDoc.textBetween(0, tempDoc.content.size, '\\n\\n', '\\n');\n\treturn {\n\t\thtml,\n\t\ttext,\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount: text.length,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Section position helpers (used by insertAtSectionStart/End and appendBodyContent)\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the ProseMirror position immediately after a section's opening divider\n * (i.e. the start of the section's own content).\n * For `'body'`, returns 1 (beginning of the document).\n * Returns -1 if the named section's divider is not found.\n */\nexport function findSectionStartPos(editor: Editor, sectionId: string): number {\n\tif (sectionId === 'body') return 1;\n\tlet startPos = -1;\n\teditor.state.doc.descendants((node, pos) => {\n\t\tif (startPos !== -1) return false;\n\t\tif (\n\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t) {\n\t\t\tstartPos = pos + node.nodeSize; // position right after the divider\n\t\t}\n\t});\n\treturn startPos;\n}\n\n/**\n * Returns the ProseMirror position at the end of a named section's content:\n * - For `'body'`: position of the first section divider, or end of document.\n * - For a named section: position of the next divider, or end of document.\n */\nexport function findSectionEndPos(editor: Editor, sectionId: string): number {\n\tconst doc = editor.state.doc;\n\tconst docSize = doc.content.size;\n\n\tif (sectionId === 'body') {\n\t\tlet firstDividerPos = -1;\n\t\tdoc.descendants((node, pos) => {\n\t\t\tif (firstDividerPos !== -1) return false;\n\t\t\tif (node.type.name === 'sectionDivider') {\n\t\t\t\tfirstDividerPos = pos;\n\t\t\t}\n\t\t});\n\t\treturn firstDividerPos !== -1 ? firstDividerPos : docSize;\n\t}\n\n\tlet passedSection = false;\n\tlet nextDividerPos = -1;\n\tdoc.descendants((node, pos) => {\n\t\tif (nextDividerPos !== -1) return false;\n\t\tif (!passedSection) {\n\t\t\tif (\n\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t) {\n\t\t\t\tpassedSection = true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (node.type.name === 'sectionDivider') {\n\t\t\tnextDividerPos = pos;\n\t\t}\n\t});\n\treturn nextDividerPos !== -1 ? nextDividerPos : docSize;\n}\n\n// ---------------------------------------------------------------------------\n// JSON body helpers (used when features.jsonMode is on — the whole document is\n// a single code block whose text is raw JSON, Postman-style)\n// ---------------------------------------------------------------------------\n\nfunction escapeHtml(raw: string): string {\n\treturn raw.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n}\n\n/**\n * Wrap a raw JSON string in a `<pre><code>` code block so TipTap parses it as a\n * single code-block node (the container for JSON body mode).\n */\nexport function buildJsonCodeBlockHtml(raw: string): string {\n\treturn `<pre><code>${escapeHtml(raw ?? '')}</code></pre>`;\n}\n\n/** Returns the raw text of the first code block in the document (empty if none). */\nexport function getCodeBlockText(editor: Editor): string {\n\tlet text = '';\n\tlet found = false;\n\teditor.state.doc.descendants((node) => {\n\t\tif (found) return false;\n\t\tif (node.type.name === 'codeBlock') {\n\t\t\ttext = node.textContent;\n\t\t\tfound = true;\n\t\t\treturn false;\n\t\t}\n\t\treturn undefined;\n\t});\n\treturn text;\n}\n\n/**\n * Replace the text of the first code block with `raw`, keeping it a code block.\n * Falls back to replacing the whole document when no code block exists yet.\n */\nexport function setCodeBlockText(editor: Editor, raw: string): void {\n\teditor.commands.setContent(buildJsonCodeBlockHtml(raw), { emitUpdate: true });\n}\n\n/** 1-based line/column of a 0-based character offset within `text`. */\nfunction offsetToLineCol(\n\ttext: string,\n\toffset: number,\n): { line: number; column: number } {\n\tconst before = text.slice(0, Math.max(0, offset));\n\tconst lines = before.split('\\n');\n\treturn {\n\t\tline: lines.length,\n\t\tcolumn: (lines[lines.length - 1]?.length ?? 0) + 1,\n\t};\n}\n\n/**\n * Turn a raw `JSON.parse` error into a clean message + location. Engine messages\n * look like `\"Bad control character in string literal in JSON at position 94\n * (line 7 column 9)\"` — we strip the `\"in JSON at position …\"` tail for the\n * message and pull the line/column from it (falling back to computing them from\n * the position offset when the engine omits them).\n */\nfunction describeJsonError(\n\trawMessage: string,\n\ttext: string,\n): { message: string; line: number | null; column: number | null } {\n\tconst message =\n\t\trawMessage.replace(/\\s*in JSON at position[\\s\\S]*$/i, '').trim() ||\n\t\trawMessage;\n\n\tconst lineCol = rawMessage.match(/line (\\d+) column (\\d+)/i);\n\tif (lineCol) {\n\t\treturn {\n\t\t\tmessage,\n\t\t\tline: Number(lineCol[1]),\n\t\t\tcolumn: Number(lineCol[2]),\n\t\t};\n\t}\n\n\tconst posMatch = rawMessage.match(/position (\\d+)/i);\n\tif (posMatch) {\n\t\tconst { line, column } = offsetToLineCol(text, Number(posMatch[1]));\n\t\treturn { message, line, column };\n\t}\n\n\treturn { message, line: null, column: null };\n}\n\n/** Parse a JSON string without throwing. Empty / whitespace-only text is valid. */\nexport function parseJson(text: string): JsonParseResult {\n\tif (!text.trim()) {\n\t\treturn { valid: true, value: null, error: null, line: null, column: null };\n\t}\n\ttry {\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\tvalue: JSON.parse(text),\n\t\t\terror: null,\n\t\t\tline: null,\n\t\t\tcolumn: null,\n\t\t};\n\t} catch (e) {\n\t\tconst { message, line, column } = describeJsonError(\n\t\t\t(e as Error).message,\n\t\t\ttext,\n\t\t);\n\t\treturn { valid: false, value: null, error: message, line, column };\n\t}\n}\n"],"names":["normalizeHtml","html","container","span","dataType","parent","p","toPortableHtml","div","walker","textNode","blocks","insertInlineHtml","editor","normalised","dom","slice","DOMParser","from","to","tr","SECTION_DIVIDER_HTML","id","buildSectionedContent","body","sections","s","getBodyHtml","extractAllSectionsFromHtml","getSectionsHtml","dividerRegex","dividers","match","i","start","end","extractSectionContent","startPos","findSectionStartPos","endPos","findSectionEndPos","serializer","DOMSerializer","text","parseHtmlToNodes","setSectionContentInEditor","dividerHtml","fragment","replaceFrom","extractBodyContent","extractActiveFormats","$from","linkMark","m","markOnPrev","extractContent","normalized","normalizeHardBreaks","tempDoc","sectionId","node","pos","doc","docSize","firstDividerPos","passedSection","nextDividerPos","escapeHtml","raw","buildJsonCodeBlockHtml","getCodeBlockText","found","setCodeBlockText","offsetToLineCol","offset","lines","describeJsonError","rawMessage","message","lineCol","posMatch","line","column","parseJson","e"],"mappings":";;AA+BO,SAASA,EAAcC,GAAsB;AACnD,MAAI,CAACA,KAAQ,OAAO,WAAa,IAAa,QAAOA;AAErD,QAAMC,IAAY,SAAS,cAAc,KAAK;AAC9C,SAAAA,EAAU,YAAYD,GAEtBC,EAAU,iBAAiB,MAAM,EAAE,QAAQ,CAACC,MAAS;AAIpD,UAAMC,IAAWD,EAAK,aAAa,WAAW;AAC9C,QACCA,EAAK,aAAa,OAAO,KACzBA,EAAK,aAAa,eAAe,KAChCC,MAAa,QAAQA,EAAS,WAAW,SAAS;AAEnD;AACD,UAAMC,IAASF,EAAK;AACpB,QAAKE,GACL;AAAA,aAAOF,EAAK,aAAY,CAAAE,EAAO,aAAaF,EAAK,YAAYA,CAAI;AACjE,MAAAE,EAAO,YAAYF,CAAI;AAAA;AAAA,EACxB,CAAC,GAEDD,EAAU,iBAAiB,GAAG,EAAE,QAAQ,CAACI,MAAM;AAC9C,IACCA,EAAE,iBAAiB,IAAI,EAAE,WAAW,MACnCA,EAAE,eAAe,IAAI,KAAA,MAAW,OAEjCA,EAAE,YAAY;AAAA,EAEhB,CAAC,GAEMJ,EAAU;AAClB;AAeO,SAASK,EAAeN,GAAsB;AACpD,QAAMO,IAAM,SAAS,cAAc,KAAK;AACxC,EAAAA,EAAI,YAAYP;AAIhB,QAAMQ,IAAS,SAAS,iBAAiBD,GAAK,WAAW,SAAS;AAClE,MAAIE;AACJ,SAAQA,IAAWD,EAAO;AACzB,IAAIC,EAAS,aAAaA,EAAS,UAAU,SAAS,IAAI,MACzDA,EAAS,YAAYA,EAAS,UAAU,QAAQ,SAAS,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