@pixerate/editor 0.14.3 → 0.15.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 (71) hide show
  1. package/dist/agent/index.cjs +28 -220
  2. package/dist/agent/index.cjs.map +1 -1
  3. package/dist/agent/index.d.cts +1 -1
  4. package/dist/agent/index.d.ts +1 -1
  5. package/dist/agent/index.js +5 -154
  6. package/dist/agent/index.js.map +1 -1
  7. package/dist/canvas/index.cjs +113 -377
  8. package/dist/canvas/index.cjs.map +1 -1
  9. package/dist/canvas/index.d.cts +2 -2
  10. package/dist/canvas/index.d.ts +2 -2
  11. package/dist/canvas/index.js +18 -208
  12. package/dist/canvas/index.js.map +1 -1
  13. package/dist/chunk-33UVEDOS.cjs +233 -0
  14. package/dist/chunk-33UVEDOS.cjs.map +1 -0
  15. package/dist/chunk-7FWEWE6T.js +1888 -0
  16. package/dist/chunk-7FWEWE6T.js.map +1 -0
  17. package/dist/chunk-BYCOFZAA.js +514 -0
  18. package/dist/chunk-BYCOFZAA.js.map +1 -0
  19. package/dist/chunk-CYKQLDYH.cjs +1290 -0
  20. package/dist/chunk-CYKQLDYH.cjs.map +1 -0
  21. package/dist/chunk-GLSIZKOX.js +17 -0
  22. package/dist/chunk-GLSIZKOX.js.map +1 -0
  23. package/dist/chunk-GWHJVZPI.js +233 -0
  24. package/dist/chunk-GWHJVZPI.js.map +1 -0
  25. package/dist/chunk-LDES3EOS.cjs +1888 -0
  26. package/dist/chunk-LDES3EOS.cjs.map +1 -0
  27. package/dist/chunk-MPPXH7U5.cjs +336 -0
  28. package/dist/chunk-MPPXH7U5.cjs.map +1 -0
  29. package/dist/chunk-NNJRJJSC.js +1290 -0
  30. package/dist/chunk-NNJRJJSC.js.map +1 -0
  31. package/dist/chunk-O7LOPQMH.js +336 -0
  32. package/dist/chunk-O7LOPQMH.js.map +1 -0
  33. package/dist/chunk-SEDR75VH.cjs +17 -0
  34. package/dist/chunk-SEDR75VH.cjs.map +1 -0
  35. package/dist/chunk-SHWP2A43.cjs +514 -0
  36. package/dist/chunk-SHWP2A43.cjs.map +1 -0
  37. package/dist/chunk-VHZCXHS4.js +222 -0
  38. package/dist/chunk-VHZCXHS4.js.map +1 -0
  39. package/dist/chunk-WADCJ7A7.cjs +222 -0
  40. package/dist/chunk-WADCJ7A7.cjs.map +1 -0
  41. package/dist/extensions/index.cjs +25 -1920
  42. package/dist/extensions/index.cjs.map +1 -1
  43. package/dist/extensions/index.js +22 -1868
  44. package/dist/extensions/index.js.map +1 -1
  45. package/dist/grammar/index.cjs +44 -387
  46. package/dist/grammar/index.cjs.map +1 -1
  47. package/dist/grammar/index.js +23 -321
  48. package/dist/grammar/index.js.map +1 -1
  49. package/dist/history/index.cjs +6 -257
  50. package/dist/history/index.cjs.map +1 -1
  51. package/dist/history/index.js +4 -227
  52. package/dist/history/index.js.map +1 -1
  53. package/dist/image-editor/index.cjs +63 -106
  54. package/dist/image-editor/index.cjs.map +1 -1
  55. package/dist/index.cjs +324 -7232
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.d.cts +0 -4
  58. package/dist/index.d.ts +0 -4
  59. package/dist/index.js +258 -7007
  60. package/dist/index.js.map +1 -1
  61. package/dist/serializers/index.cjs +28 -558
  62. package/dist/serializers/index.cjs.map +1 -1
  63. package/dist/serializers/index.js +16 -496
  64. package/dist/serializers/index.js.map +1 -1
  65. package/dist/spreadsheet/index.cjs +21 -1319
  66. package/dist/spreadsheet/index.cjs.map +1 -1
  67. package/dist/spreadsheet/index.js +14 -1274
  68. package/dist/spreadsheet/index.js.map +1 -1
  69. package/dist/{types-lGtRobRV.d.cts → types-DC8b2TsA.d.cts} +1 -1
  70. package/dist/{types-lGtRobRV.d.ts → types-DC8b2TsA.d.ts} +1 -1
  71. package/package.json +1 -1
@@ -0,0 +1,514 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/serializers/mentions.ts
2
+ var MENTION_REGEX = /(?:^|[\s>(*_"';\\/[\]{}~`:]|&quot;|&gt;|&lt;|&amp;)@(?:"([^"]+)"|&quot;([^&]+)&quot;|([a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_-]+)*))/g;
3
+ var MARKDOWN_MENTION_SPLIT_REGEX = /(```[\s\S]*?```|~~~[\s\S]*?~~~|<pre[\s\S]*?<\/pre>|<code[\s\S]*?<\/code>|`[^`\n]+`|<span\b[^>]*\b(?:data-type=["']mention["']|class=["'][^"']*pixerate-mention-node[^"']*["']|data-mention=["'][^"']*["'])[^>]*>[\s\S]*?<\/span>|<[^>]+>|\]\([^)]+\)|(?:https?|file|vscode|cursor|mailto):\/\/[^\s<)]+)/gi;
4
+ function stripMarkdownCode(content) {
5
+ if (!content || typeof content !== "string") return "";
6
+ return content.replace(/```[\s\S]*?```/g, "").replace(/~~~[\s\S]*?~~~/g, "").replace(/<pre[\s\S]*?<\/pre>/gi, "").replace(/<code[\s\S]*?<\/code>/gi, "").replace(/`[^`\n]*`/g, "");
7
+ }
8
+ function extractMentions(content) {
9
+ if (!content || typeof content !== "string") return [];
10
+ const normalizedMentionNodes = content.replace(
11
+ /<span\b[^>]*\b(?:data-type=["']mention["']|class=["'][^"']*pixerate-mention-node[^"']*["'])[^>]*>([\s\S]*?)<\/span>/gi,
12
+ (match2, inner) => {
13
+ const labelMatch = match2.match(/\bdata-label=["']([^"']+)["']/i);
14
+ if (labelMatch) return ` @${labelMatch[1]} `;
15
+ const idMatch = match2.match(/\bdata-id=["']([^"']+)["']/i);
16
+ if (idMatch) return ` @${idMatch[1]} `;
17
+ return ` ${inner} `;
18
+ }
19
+ );
20
+ const cleanContent = stripMarkdownCode(normalizedMentionNodes);
21
+ const withoutUrls = cleanContent.replace(/(?:https?|ftp|file|vscode|cursor|mailto):\/\/[^\s<>()]+/gi, "").replace(/\]\([^)]*\)/g, "]");
22
+ const textOnly = withoutUrls.replace(/<[^>]+>/g, " ");
23
+ const mentions = [];
24
+ const seen = /* @__PURE__ */ new Set();
25
+ const regex = new RegExp(MENTION_REGEX.source, "g");
26
+ let match;
27
+ while ((match = regex.exec(textOnly)) !== null) {
28
+ const handle = (_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(match[1], () => ( match[2])), () => ( match[3])), () => ( ""))).trim();
29
+ if (handle && !seen.has(handle)) {
30
+ seen.add(handle);
31
+ mentions.push(handle);
32
+ }
33
+ }
34
+ return mentions;
35
+ }
36
+ function parseMentionSegments(content) {
37
+ if (!content) return [];
38
+ const segments = [];
39
+ const regex = new RegExp(MENTION_REGEX.source, "g");
40
+ let lastIndex = 0;
41
+ let match;
42
+ while ((match = regex.exec(content)) !== null) {
43
+ const fullMatch = match[0];
44
+ const atIndex = fullMatch.indexOf("@");
45
+ const prefix = atIndex > 0 ? fullMatch.slice(0, atIndex) : "";
46
+ const mentionToken = fullMatch.slice(atIndex);
47
+ const handle = _nullishCoalesce(_nullishCoalesce(match[1], () => ( match[2])), () => ( match[3]));
48
+ const matchStart = match.index + prefix.length;
49
+ if (matchStart > lastIndex) {
50
+ segments.push({
51
+ type: "text",
52
+ value: content.slice(lastIndex, matchStart)
53
+ });
54
+ }
55
+ segments.push({
56
+ type: "mention",
57
+ value: mentionToken,
58
+ handle
59
+ });
60
+ lastIndex = matchStart + mentionToken.length;
61
+ }
62
+ if (lastIndex < content.length) {
63
+ segments.push({
64
+ type: "text",
65
+ value: content.slice(lastIndex)
66
+ });
67
+ }
68
+ return segments;
69
+ }
70
+ function preprocessMarkdownMentions(content, optionsOrMentionables = []) {
71
+ if (!content || typeof content !== "string") return "";
72
+ const options = Array.isArray(optionsOrMentionables) ? { mentionables: optionsOrMentionables } : optionsOrMentionables;
73
+ const allMentionables = options.mentionables || [];
74
+ const defaultType = options.defaultType || "user";
75
+ const resolveMention = options.resolveMention;
76
+ const parts = content.split(MARKDOWN_MENTION_SPLIT_REGEX);
77
+ return parts.map((part) => {
78
+ if (!part) return "";
79
+ if (part.startsWith("```") || part.startsWith("~~~") || part.startsWith("`") || part.startsWith("](") || /^(?:https?|file|vscode|cursor|mailto):\/\//i.test(part) || /^<pre[\s>]/i.test(part) || /^<code[\s>]/i.test(part) || /^<[^>]+>$/i.test(part) || /^<span\b[^>]*\b(?:data-type=["']mention["']|class=["'][^"']*pixerate-mention-node[^"']*["']|data-mention=["'][^"']*["'])/i.test(
80
+ part
81
+ )) {
82
+ return part;
83
+ }
84
+ const regex = new RegExp(MENTION_REGEX.source, "g");
85
+ return part.replace(regex, (match, quotedHandle, escapedQuotedHandle, standardHandle) => {
86
+ const atIndex = match.indexOf("@");
87
+ const prefix = atIndex > 0 ? match.slice(0, atIndex) : "";
88
+ const rawHandle = (quotedHandle || escapedQuotedHandle || standardHandle || "").trim();
89
+ if (!rawHandle) return match;
90
+ const lowerHandle = rawHandle.toLowerCase();
91
+ const entity = allMentionables.find((e) => {
92
+ if (_optionalChain([e, 'access', _ => _.label, 'optionalAccess', _2 => _2.toLowerCase, 'call', _3 => _3()]) === lowerHandle) return true;
93
+ if (_optionalChain([e, 'access', _4 => _4.handle, 'optionalAccess', _5 => _5.toLowerCase, 'call', _6 => _6()]) === lowerHandle) return true;
94
+ if (_optionalChain([e, 'access', _7 => _7.name, 'optionalAccess', _8 => _8.toLowerCase, 'call', _9 => _9()]) === lowerHandle) return true;
95
+ if (_optionalChain([e, 'access', _10 => _10.id, 'optionalAccess', _11 => _11.toLowerCase, 'call', _12 => _12()]) === lowerHandle) return true;
96
+ if (e.type === "agent" && `agent${(e.handle || e.label || "").toLowerCase()}` === lowerHandle) return true;
97
+ if (_optionalChain([e, 'access', _13 => _13.aliases, 'optionalAccess', _14 => _14.some, 'call', _15 => _15(
98
+ (a) => a.toLowerCase() === lowerHandle || e.type === "agent" && `agent${a.toLowerCase()}` === lowerHandle
99
+ )])) {
100
+ return true;
101
+ }
102
+ return false;
103
+ });
104
+ let id = _optionalChain([entity, 'optionalAccess', _16 => _16.id]);
105
+ let label = _optionalChain([entity, 'optionalAccess', _17 => _17.label]) || _optionalChain([entity, 'optionalAccess', _18 => _18.handle]) || rawHandle;
106
+ let type = _optionalChain([entity, 'optionalAccess', _19 => _19.type]);
107
+ let avatarUrl = _optionalChain([entity, 'optionalAccess', _20 => _20.avatarUrl]);
108
+ let color = _optionalChain([entity, 'optionalAccess', _21 => _21.color]) || _optionalChain([entity, 'optionalAccess', _22 => _22.hexColor]);
109
+ if (!entity) {
110
+ const customResolved = _optionalChain([resolveMention, 'optionalCall', _23 => _23(rawHandle)]);
111
+ if (customResolved) {
112
+ id = _nullishCoalesce(customResolved.id, () => ( id));
113
+ label = _nullishCoalesce(_nullishCoalesce(customResolved.label, () => ( customResolved.handle)), () => ( label));
114
+ type = _nullishCoalesce(customResolved.type, () => ( type));
115
+ avatarUrl = _nullishCoalesce(customResolved.avatarUrl, () => ( avatarUrl));
116
+ color = _nullishCoalesce(_nullishCoalesce(customResolved.color, () => ( customResolved.hexColor)), () => ( color));
117
+ } else {
118
+ const stripped = lowerHandle.replace(/^agent[\s\-_]*/i, "");
119
+ if (["supervisor", "coordinator", "planner", "validator", "executor"].includes(stripped)) {
120
+ type = "agent";
121
+ id = stripped;
122
+ label = stripped;
123
+ } else if (lowerHandle === "agents") {
124
+ type = "team";
125
+ id = "agents";
126
+ label = "agents";
127
+ } else {
128
+ type = defaultType;
129
+ id = rawHandle;
130
+ label = rawHandle;
131
+ }
132
+ }
133
+ }
134
+ const avatarAttr = avatarUrl ? ` data-avatar-url="${escapeHtml(avatarUrl)}"` : "";
135
+ const colorAttr = color ? ` data-color="${escapeHtml(color)}"` : "";
136
+ return `${prefix}<span class="pixerate-mention-node" data-type="mention" data-id="${escapeHtml(
137
+ id || label
138
+ )}" data-label="${escapeHtml(label)}" data-mention-suggestion-char="@" data-type-name="${escapeHtml(
139
+ type || defaultType
140
+ )}"${avatarAttr}${colorAttr}>@${escapeHtml(label)}</span>`;
141
+ });
142
+ }).join("");
143
+ }
144
+
145
+ // src/serializers/plain-text.ts
146
+ function escapeHtml(text) {
147
+ if (!text) return "";
148
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
149
+ }
150
+ var PARAGRAPH_HTML_REGEX = /^\s*<p[\s>][\s\S]*<\/p>\s*$/i;
151
+ function plainTextToTipTapHtml(text) {
152
+ if (!text) return "<p></p>";
153
+ if (PARAGRAPH_HTML_REGEX.test(text)) {
154
+ return text;
155
+ }
156
+ return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n").map((line) => `<p>${escapeHtml(line)}</p>`).join("");
157
+ }
158
+ var BLOCK_TAGS = /* @__PURE__ */ new Set([
159
+ "P",
160
+ "DIV",
161
+ "LI",
162
+ "UL",
163
+ "OL",
164
+ "PRE",
165
+ "BLOCKQUOTE",
166
+ "TABLE",
167
+ "TR",
168
+ "H1",
169
+ "H2",
170
+ "H3",
171
+ "H4",
172
+ "H5",
173
+ "H6",
174
+ "HR"
175
+ ]);
176
+ var MENTION_SPAN_REGEX = /<span\b(?=[^>]*\bdata-type=["']mention["'])([^>]*)>[\s\S]*?<\/span>/gi;
177
+ function getHtmlAttribute(attrs, name) {
178
+ const match = new RegExp(`\\b${name}=(?:"([^"]*)"|'([^']*)')`, "i").exec(
179
+ attrs
180
+ );
181
+ return match ? _nullishCoalesce(match[1], () => ( match[2])) : void 0;
182
+ }
183
+ function parseHtmlFragment(html) {
184
+ const template = document.createElement("template");
185
+ template.innerHTML = html;
186
+ return template.content;
187
+ }
188
+ function decodeHtmlEntities(text) {
189
+ return text.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#0*39;/g, "'").replace(/&nbsp;/g, "\xA0").replace(/&amp;/g, "&");
190
+ }
191
+ function htmlToPlainText(html) {
192
+ if (!html) return "";
193
+ const mentionNormalized = html.replace(MENTION_SPAN_REGEX, (match, attrs) => {
194
+ const label = getHtmlAttribute(attrs, "data-label") || getHtmlAttribute(attrs, "data-id");
195
+ return label ? `@${label}` : match;
196
+ });
197
+ if (typeof document !== "undefined") {
198
+ const fragment = parseHtmlFragment(mentionNormalized);
199
+ fragment.querySelectorAll("br.ProseMirror-trailingBreak").forEach((br) => br.remove());
200
+ const lines = [];
201
+ let current = null;
202
+ const flush = () => {
203
+ if (current !== null) {
204
+ lines.push(current);
205
+ current = null;
206
+ }
207
+ };
208
+ const visit = (node) => {
209
+ if (node.nodeType === 3) {
210
+ const value = _nullishCoalesce(node.nodeValue, () => ( ""));
211
+ if (current === null && value.trim() === "") return;
212
+ current = (_nullishCoalesce(current, () => ( ""))) + value;
213
+ return;
214
+ }
215
+ if (node.nodeType !== 1) return;
216
+ const tag = node.tagName.toUpperCase();
217
+ if (tag === "BR") {
218
+ current = (_nullishCoalesce(current, () => ( ""))) + "\n";
219
+ return;
220
+ }
221
+ if (!BLOCK_TAGS.has(tag)) {
222
+ node.childNodes.forEach(visit);
223
+ return;
224
+ }
225
+ flush();
226
+ const linesBefore = lines.length;
227
+ node.childNodes.forEach(visit);
228
+ flush();
229
+ if (lines.length === linesBefore && tag !== "HR") {
230
+ lines.push("");
231
+ }
232
+ };
233
+ fragment.childNodes.forEach(visit);
234
+ flush();
235
+ return lines.join("\n");
236
+ }
237
+ const text = mentionNormalized.replace(/<br\s*\/?>/gi, "\n").replace(
238
+ /<\/(?:p|div|li|pre|blockquote|h[1-6])>(?:\s*<\/(?:li|ul|ol|blockquote|div)>)*/gi,
239
+ "\n"
240
+ ).replace(/<[^>]+>/g, "");
241
+ return decodeHtmlEntities(text).replace(/\n$/, "");
242
+ }
243
+ function getEditorText(editor) {
244
+ if (!editor) return "";
245
+ const html = typeof editor.getHTML === "function" ? editor.getHTML() : "";
246
+ if (html) {
247
+ return htmlToPlainText(html);
248
+ }
249
+ if (typeof editor.getText === "function") {
250
+ try {
251
+ return editor.getText({ blockSeparator: "\n" });
252
+ } catch (e2) {
253
+ return editor.getText();
254
+ }
255
+ }
256
+ return "";
257
+ }
258
+ function extractMentionsFromDoc(docOrEditor) {
259
+ if (!docOrEditor) return [];
260
+ const mentions = [];
261
+ const doc = _optionalChain([docOrEditor, 'optionalAccess', _24 => _24.state, 'optionalAccess', _25 => _25.doc]) || (typeof _optionalChain([docOrEditor, 'optionalAccess', _26 => _26.descendants]) === "function" ? docOrEditor : null);
262
+ if (doc && typeof doc.descendants === "function") {
263
+ doc.descendants((node) => {
264
+ if (_optionalChain([node, 'access', _27 => _27.type, 'optionalAccess', _28 => _28.name]) === "mention" && node.attrs) {
265
+ mentions.push({
266
+ id: node.attrs.id || "",
267
+ label: node.attrs.label || "",
268
+ type: node.attrs.type,
269
+ avatarUrl: node.attrs.avatarUrl,
270
+ color: node.attrs.color,
271
+ ...node.attrs
272
+ });
273
+ }
274
+ });
275
+ return mentions;
276
+ }
277
+ if (typeof docOrEditor === "object" && docOrEditor.content) {
278
+ const walk = (nodes) => {
279
+ for (const node of nodes) {
280
+ if (node.type === "mention" && node.attrs) {
281
+ mentions.push({
282
+ id: node.attrs.id || "",
283
+ label: node.attrs.label || "",
284
+ type: node.attrs.type,
285
+ avatarUrl: node.attrs.avatarUrl,
286
+ color: node.attrs.color,
287
+ ...node.attrs
288
+ });
289
+ }
290
+ if (Array.isArray(node.content)) {
291
+ walk(node.content);
292
+ }
293
+ }
294
+ };
295
+ walk(docOrEditor.content);
296
+ return mentions;
297
+ }
298
+ if (typeof docOrEditor === "string") {
299
+ if (typeof document !== "undefined") {
300
+ parseHtmlFragment(docOrEditor).querySelectorAll('span[data-type="mention"]').forEach((el) => {
301
+ mentions.push({
302
+ id: el.getAttribute("data-id") || "",
303
+ label: el.getAttribute("data-label") || "",
304
+ type: el.getAttribute("data-type-name") || void 0,
305
+ avatarUrl: el.getAttribute("data-avatar-url") || void 0,
306
+ color: el.getAttribute("data-color") || void 0
307
+ });
308
+ });
309
+ } else {
310
+ const spanRegex = /<span([^>]*data-type=["']mention["'][^>]*)>/gi;
311
+ let match;
312
+ while ((match = spanRegex.exec(docOrEditor)) !== null) {
313
+ const attrStr = match[1];
314
+ const getAttr = (name) => {
315
+ const m = new RegExp(`${name}=["']([^"']*)["']`, "i").exec(attrStr);
316
+ return m ? m[1] : void 0;
317
+ };
318
+ mentions.push({
319
+ id: getAttr("data-id") || "",
320
+ label: getAttr("data-label") || "",
321
+ type: getAttr("data-type-name") || getAttr("data-entity-type"),
322
+ avatarUrl: getAttr("data-avatar-url"),
323
+ color: getAttr("data-color")
324
+ });
325
+ }
326
+ }
327
+ if (mentions.length === 0) {
328
+ const rawHandles = extractMentions(docOrEditor);
329
+ for (const handle of rawHandles) {
330
+ mentions.push({
331
+ id: handle,
332
+ label: handle,
333
+ type: "user"
334
+ });
335
+ }
336
+ }
337
+ }
338
+ return mentions;
339
+ }
340
+
341
+ // src/serializers/markdown.ts
342
+ var _markdownit = require('markdown-it'); var _markdownit2 = _interopRequireDefault(_markdownit);
343
+ var _markdownittasklists = require('markdown-it-task-lists'); var _markdownittasklists2 = _interopRequireDefault(_markdownittasklists);
344
+ var md = new (0, _markdownit2.default)({
345
+ html: true,
346
+ linkify: true,
347
+ breaks: true
348
+ }).use(_markdownittasklists2.default);
349
+ var defaultValidateLink = md.validateLink;
350
+ md.validateLink = (url) => {
351
+ if (url.startsWith("file://") || url.startsWith("vscode://") || url.startsWith("cursor://")) {
352
+ return true;
353
+ }
354
+ return defaultValidateLink.call(md, url);
355
+ };
356
+ var ALLOWED_HTML_TAGS = /* @__PURE__ */ new Set([
357
+ "a",
358
+ "abbr",
359
+ "b",
360
+ "blockquote",
361
+ "br",
362
+ "code",
363
+ "del",
364
+ "details",
365
+ "div",
366
+ "em",
367
+ "h1",
368
+ "h2",
369
+ "h3",
370
+ "h4",
371
+ "h5",
372
+ "h6",
373
+ "hr",
374
+ "i",
375
+ "img",
376
+ "input",
377
+ "kbd",
378
+ "li",
379
+ "mark",
380
+ "ol",
381
+ "p",
382
+ "pre",
383
+ "s",
384
+ "span",
385
+ "strong",
386
+ "sub",
387
+ "summary",
388
+ "sup",
389
+ "table",
390
+ "tbody",
391
+ "td",
392
+ "tfoot",
393
+ "th",
394
+ "thead",
395
+ "tr",
396
+ "u",
397
+ "ul"
398
+ ]);
399
+ var ALLOWED_HTML_ATTRS = /* @__PURE__ */ new Set([
400
+ "alt",
401
+ "align",
402
+ "checked",
403
+ "class",
404
+ "colspan",
405
+ "disabled",
406
+ "height",
407
+ "href",
408
+ "rel",
409
+ "rowspan",
410
+ "src",
411
+ "start",
412
+ "target",
413
+ "title",
414
+ "type",
415
+ "width"
416
+ ]);
417
+ var HTML_TAG_REGEX = /<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\s+[^\s"'>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*)\s*\/?>/g;
418
+ var HTML_ATTR_REGEX = /([^\s"'>\/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
419
+ function sanitizeTag(tagText, isClosing, rawTagName, rawAttrs) {
420
+ const tagName = rawTagName.toLowerCase();
421
+ if (!ALLOWED_HTML_TAGS.has(tagName)) return escapeHtml(tagText);
422
+ if (isClosing) return `</${tagName}>`;
423
+ if (tagName === "input" && !/\stype\s*=\s*["']?checkbox["']?[\s>/]/i.test(tagText)) {
424
+ return escapeHtml(tagText);
425
+ }
426
+ let attrs = "";
427
+ let attrMatch;
428
+ HTML_ATTR_REGEX.lastIndex = 0;
429
+ while ((attrMatch = HTML_ATTR_REGEX.exec(rawAttrs)) !== null) {
430
+ const name = attrMatch[1].toLowerCase();
431
+ if (!ALLOWED_HTML_ATTRS.has(name) && !/^data-[a-z0-9_.-]+$/.test(name)) {
432
+ continue;
433
+ }
434
+ const rawValue = _nullishCoalesce(_nullishCoalesce(attrMatch[2], () => ( attrMatch[3])), () => ( attrMatch[4]));
435
+ if (rawValue === void 0) {
436
+ attrs += ` ${name}`;
437
+ continue;
438
+ }
439
+ const value = md.utils.unescapeAll(rawValue);
440
+ if ((name === "href" || name === "src") && // Browsers ignore control characters and whitespace inside schemes.
441
+ !md.validateLink(value.replace(/[\u0000-\u0020\u007f]/g, ""))) {
442
+ continue;
443
+ }
444
+ attrs += ` ${name}="${escapeHtml(value)}"`;
445
+ }
446
+ return `<${tagName}${attrs}>`;
447
+ }
448
+ function sanitizeEmbeddedHtml(html) {
449
+ let result = "";
450
+ let lastIndex = 0;
451
+ let match;
452
+ HTML_TAG_REGEX.lastIndex = 0;
453
+ while ((match = HTML_TAG_REGEX.exec(html)) !== null) {
454
+ result += html.slice(lastIndex, match.index).replace(/</g, "&lt;");
455
+ result += sanitizeTag(match[0], match[1], match[2], match[3]);
456
+ lastIndex = match.index + match[0].length;
457
+ }
458
+ return result + html.slice(lastIndex).replace(/</g, "&lt;");
459
+ }
460
+ var defaultHtmlInline = md.renderer.rules.html_inline;
461
+ var defaultHtmlBlock = md.renderer.rules.html_block;
462
+ md.renderer.rules.html_inline = (tokens, idx, options, env, self) => _optionalChain([env, 'optionalAccess', _29 => _29.allowUnsafeHtml]) ? defaultHtmlInline(tokens, idx, options, env, self) : sanitizeEmbeddedHtml(tokens[idx].content);
463
+ md.renderer.rules.html_block = (tokens, idx, options, env, self) => _optionalChain([env, 'optionalAccess', _30 => _30.allowUnsafeHtml]) ? defaultHtmlBlock(tokens, idx, options, env, self) : sanitizeEmbeddedHtml(tokens[idx].content);
464
+ function preprocessMarkdownFileLinks(content) {
465
+ if (!content) return "";
466
+ return content.replace(
467
+ /\[([^\]]+)\]\(((?:file|vscode|cursor):\/\/[^)]+)\)/g,
468
+ (_match, rawLabel, href) => {
469
+ const trimmed = rawLabel.trim();
470
+ const codeMatch = trimmed.match(/^`([^`]+)`$/);
471
+ const labelContent = codeMatch ? `<code>${escapeHtml(codeMatch[1])}</code>` : escapeHtml(trimmed);
472
+ return `<a href="${escapeHtml(href)}" data-file-link="true" title="Click to copy file path">${labelContent}</a>`;
473
+ }
474
+ );
475
+ }
476
+ function markdownToTipTapHtml(markdown, options) {
477
+ if (!markdown) return "<p></p>";
478
+ let content = markdown;
479
+ if (_optionalChain([options, 'optionalAccess', _31 => _31.preprocessFileLinks])) {
480
+ content = preprocessMarkdownFileLinks(content);
481
+ }
482
+ if (_optionalChain([options, 'optionalAccess', _32 => _32.preprocessMentions]) || _optionalChain([options, 'optionalAccess', _33 => _33.mentionables]) || _optionalChain([options, 'optionalAccess', _34 => _34.preprocessOptions])) {
483
+ const mentionOpts = options.preprocessOptions || {
484
+ mentionables: options.mentionables
485
+ };
486
+ content = preprocessMarkdownMentions(content, mentionOpts);
487
+ }
488
+ return md.render(content, { allowUnsafeHtml: _optionalChain([options, 'optionalAccess', _35 => _35.allowUnsafeHtml]) });
489
+ }
490
+ function getEditorMarkdown(editor) {
491
+ if (!editor) return "";
492
+ if (typeof _optionalChain([editor, 'access', _36 => _36.storage, 'optionalAccess', _37 => _37.markdown, 'optionalAccess', _38 => _38.getMarkdown]) === "function") {
493
+ return editor.storage.markdown.getMarkdown();
494
+ }
495
+ return getEditorText(editor);
496
+ }
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+ exports.MENTION_REGEX = MENTION_REGEX; exports.MARKDOWN_MENTION_SPLIT_REGEX = MARKDOWN_MENTION_SPLIT_REGEX; exports.stripMarkdownCode = stripMarkdownCode; exports.extractMentions = extractMentions; exports.parseMentionSegments = parseMentionSegments; exports.preprocessMarkdownMentions = preprocessMarkdownMentions; exports.escapeHtml = escapeHtml; exports.plainTextToTipTapHtml = plainTextToTipTapHtml; exports.htmlToPlainText = htmlToPlainText; exports.getEditorText = getEditorText; exports.extractMentionsFromDoc = extractMentionsFromDoc; exports.preprocessMarkdownFileLinks = preprocessMarkdownFileLinks; exports.markdownToTipTapHtml = markdownToTipTapHtml; exports.getEditorMarkdown = getEditorMarkdown;
514
+ //# sourceMappingURL=chunk-SHWP2A43.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/editor/editor/packages/core/dist/chunk-SHWP2A43.cjs","../src/serializers/mentions.ts","../src/serializers/plain-text.ts","../src/serializers/markdown.ts"],"names":["match"],"mappings":"AAAA;ACUO,IAAM,cAAA,EACX,8HAAA;AAMK,IAAM,6BAAA,EACX,2SAAA;AA+BK,SAAS,iBAAA,CAAkB,OAAA,EAAyB;AACzD,EAAA,GAAA,CAAI,CAAC,QAAA,GAAW,OAAO,QAAA,IAAY,QAAA,EAAU,OAAO,EAAA;AACpD,EAAA,OAAO,OAAA,CACJ,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA,CAC7B,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA,CAC7B,OAAA,CAAQ,uBAAA,EAAyB,EAAE,CAAA,CACnC,OAAA,CAAQ,yBAAA,EAA2B,EAAE,CAAA,CACrC,OAAA,CAAQ,YAAA,EAAc,EAAE,CAAA;AAC7B;AAMO,SAAS,eAAA,CAAgB,OAAA,EAA2B;AACzD,EAAA,GAAA,CAAI,CAAC,QAAA,GAAW,OAAO,QAAA,IAAY,QAAA,EAAU,OAAO,CAAC,CAAA;AAKrD,EAAA,MAAM,uBAAA,EAAyB,OAAA,CAAQ,OAAA;AAAA,IACrC,uHAAA;AAAA,IACA,CAACA,MAAAA,EAAO,KAAA,EAAA,GAAU;AAChB,MAAA,MAAM,WAAA,EAAaA,MAAAA,CAAM,KAAA,CAAM,gCAAgC,CAAA;AAC/D,MAAA,GAAA,CAAI,UAAA,EAAY,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2A43.cjs","sourcesContent":[null,"import { escapeHtml } from \"./plain-text\";\nimport type { MentionEntity } from \"../extensions/mention\";\n\n/**\n * Canonical regex pattern for matching @mentions in plain text or markdown.\n * Supports:\n * - Standard unquoted handles: @username, @user.name, @team_alpha, @sa-1\n * - Quoted handles: @\"John Doe\", &quot;Jane Doe&quot;\n * Unquoted handles exclude trailing punctuation (e.g. @violet. matches \"violet\" without the dot).\n */\nexport const MENTION_REGEX =\n /(?:^|[\\s>(*_\"';\\\\/[\\]{}~`:]|&quot;|&gt;|&lt;|&amp;)@(?:\"([^\"]+)\"|&quot;([^&]+)&quot;|([a-zA-Z0-9_-]+(?:\\.[a-zA-Z0-9_-]+)*))/g;\n\n/**\n * Split regex identifying markdown code blocks, inline code, URLs, and existing HTML tags.\n * Used by preprocessMarkdownMentions to ensure non-mention regions remain completely untouched.\n */\nexport const MARKDOWN_MENTION_SPLIT_REGEX =\n /(```[\\s\\S]*?```|~~~[\\s\\S]*?~~~|<pre[\\s\\S]*?<\\/pre>|<code[\\s\\S]*?<\\/code>|`[^`\\n]+`|<span\\b[^>]*\\b(?:data-type=[\"']mention[\"']|class=[\"'][^\"']*pixerate-mention-node[^\"']*[\"']|data-mention=[\"'][^\"']*[\"'])[^>]*>[\\s\\S]*?<\\/span>|<[^>]+>|\\]\\([^)]+\\)|(?:https?|file|vscode|cursor|mailto):\\/\\/[^\\s<)]+)/gi;\n\nexport interface MentionSegment {\n type: \"text\" | \"mention\";\n value: string;\n handle?: string;\n}\n\nexport interface PreprocessMarkdownMentionsOptions {\n /**\n * Known pool of mentionable entities (users, agents, teams, etc.).\n */\n mentionables?: MentionEntity[];\n /**\n * Default entity type assigned when a handle does not match any entry in mentionables.\n * Defaults to 'user'.\n */\n defaultType?: string;\n /**\n * Custom resolver callback to derive entity metadata for unmatched handles.\n */\n resolveMention?: (handle: string) => Partial<MentionEntity> | null | undefined;\n}\n\n/**\n * Strips code blocks and inline code from markdown or HTML content:\n * - Fenced code blocks: ```...``` and ~~~...~~~\n * - Inline backtick code: `...`\n * - HTML code/pre tags: <pre>...</pre>, <code>...</code>\n * Used to avoid false-positive mention parsing and keyword analysis within code snippets, terminal logs, or stack traces.\n */\nexport function stripMarkdownCode(content: string): string {\n if (!content || typeof content !== \"string\") return \"\";\n return content\n .replace(/```[\\s\\S]*?```/g, \"\")\n .replace(/~~~[\\s\\S]*?~~~/g, \"\")\n .replace(/<pre[\\s\\S]*?<\\/pre>/gi, \"\")\n .replace(/<code[\\s\\S]*?<\\/code>/gi, \"\")\n .replace(/`[^`\\n]*`/g, \"\");\n}\n\n/**\n * Extracts unique mention handles from a text, markdown, or HTML string,\n * ignoring trailing punctuation, code blocks, URLs, and pre-existing HTML mention attributes.\n */\nexport function extractMentions(content: string): string[] {\n if (!content || typeof content !== \"string\") return [];\n\n // Normalize existing HTML mention nodes (e.g. from TipTap or rich text serializers)\n // so data-mention-suggestion-char=\"@\" does not trigger spurious quoted matches against attributes,\n // and ensure the actual mentioned label or ID is preserved cleanly.\n const normalizedMentionNodes = content.replace(\n /<span\\b[^>]*\\b(?:data-type=[\"']mention[\"']|class=[\"'][^\"']*pixerate-mention-node[^\"']*[\"'])[^>]*>([\\s\\S]*?)<\\/span>/gi,\n (match, inner) => {\n const labelMatch = match.match(/\\bdata-label=[\"']([^\"']+)[\"']/i);\n if (labelMatch) return ` @${labelMatch[1]} `;\n const idMatch = match.match(/\\bdata-id=[\"']([^\"']+)[\"']/i);\n if (idMatch) return ` @${idMatch[1]} `;\n return ` ${inner} `;\n }\n );\n\n const cleanContent = stripMarkdownCode(normalizedMentionNodes);\n // Strip URLs and markdown link destinations so @package or @handles in URLs are not extracted as mentions\n const withoutUrls = cleanContent\n .replace(/(?:https?|ftp|file|vscode|cursor|mailto):\\/\\/[^\\s<>()]+/gi, \"\")\n .replace(/\\]\\([^)]*\\)/g, \"]\");\n // Strip remaining HTML tags so attributes containing '@' or '>' aren't treated as mention triggers\n const textOnly = withoutUrls.replace(/<[^>]+>/g, \" \");\n\n const mentions: string[] = [];\n const seen = new Set<string>();\n\n const regex = new RegExp(MENTION_REGEX.source, \"g\");\n let match: RegExpExecArray | null;\n\n while ((match = regex.exec(textOnly)) !== null) {\n const handle = (match[1] ?? match[2] ?? match[3] ?? \"\").trim();\n if (handle && !seen.has(handle)) {\n seen.add(handle);\n mentions.push(handle);\n }\n }\n\n return mentions;\n}\n\n/**\n * Segments a text string into plain text parts and mention tokens.\n * Correctly leaves trailing punctuation (like \".\") as part of the following text segment.\n */\nexport function parseMentionSegments(content: string): MentionSegment[] {\n if (!content) return [];\n\n const segments: MentionSegment[] = [];\n const regex = new RegExp(MENTION_REGEX.source, \"g\");\n let lastIndex = 0;\n let match: RegExpExecArray | null;\n\n while ((match = regex.exec(content)) !== null) {\n const fullMatch = match[0];\n const atIndex = fullMatch.indexOf(\"@\");\n const prefix = atIndex > 0 ? fullMatch.slice(0, atIndex) : \"\";\n const mentionToken = fullMatch.slice(atIndex);\n const handle = match[1] ?? match[2] ?? match[3];\n const matchStart = match.index + prefix.length;\n\n if (matchStart > lastIndex) {\n segments.push({\n type: \"text\",\n value: content.slice(lastIndex, matchStart),\n });\n }\n\n segments.push({\n type: \"mention\",\n value: mentionToken,\n handle,\n });\n\n lastIndex = matchStart + mentionToken.length;\n }\n\n if (lastIndex < content.length) {\n segments.push({\n type: \"text\",\n value: content.slice(lastIndex),\n });\n }\n\n return segments;\n}\n\n/**\n * Preprocesses markdown text by turning raw @mention handles into TipTap-compatible\n * mention HTML spans (<span class=\"pixerate-mention-node\" data-type=\"mention\" ...>),\n * ensuring code blocks, inline code, existing mention nodes, and URLs remain immune.\n */\nexport function preprocessMarkdownMentions(\n content: string,\n optionsOrMentionables: MentionEntity[] | PreprocessMarkdownMentionsOptions = []\n): string {\n if (!content || typeof content !== \"string\") return \"\";\n\n const options: PreprocessMarkdownMentionsOptions = Array.isArray(optionsOrMentionables)\n ? { mentionables: optionsOrMentionables }\n : optionsOrMentionables;\n\n const allMentionables = options.mentionables || [];\n const defaultType = options.defaultType || \"user\";\n const resolveMention = options.resolveMention;\n\n const parts = content.split(MARKDOWN_MENTION_SPLIT_REGEX);\n\n return parts\n .map((part) => {\n if (!part) return \"\";\n\n // Preserve code fences, code tags, inline backticks, existing mention spans,\n // HTML tags, markdown link targets, and raw URLs untouched.\n if (\n part.startsWith(\"```\") ||\n part.startsWith(\"~~~\") ||\n part.startsWith(\"`\") ||\n part.startsWith(\"](\") ||\n /^(?:https?|file|vscode|cursor|mailto):\\/\\//i.test(part) ||\n /^<pre[\\s>]/i.test(part) ||\n /^<code[\\s>]/i.test(part) ||\n /^<[^>]+>$/i.test(part) ||\n /^<span\\b[^>]*\\b(?:data-type=[\"']mention[\"']|class=[\"'][^\"']*pixerate-mention-node[^\"']*[\"']|data-mention=[\"'][^\"']*[\"'])/i.test(\n part\n )\n ) {\n return part;\n }\n\n const regex = new RegExp(MENTION_REGEX.source, \"g\");\n return part.replace(regex, (match, quotedHandle, escapedQuotedHandle, standardHandle) => {\n const atIndex = match.indexOf(\"@\");\n const prefix = atIndex > 0 ? match.slice(0, atIndex) : \"\";\n const rawHandle = (quotedHandle || escapedQuotedHandle || standardHandle || \"\").trim();\n if (!rawHandle) return match;\n\n const lowerHandle = rawHandle.toLowerCase();\n const entity = allMentionables.find((e) => {\n if (e.label?.toLowerCase() === lowerHandle) return true;\n if (e.handle?.toLowerCase() === lowerHandle) return true;\n if (e.name?.toLowerCase() === lowerHandle) return true;\n if (e.id?.toLowerCase() === lowerHandle) return true;\n if (e.type === \"agent\" && `agent${(e.handle || e.label || \"\").toLowerCase()}` === lowerHandle) return true;\n if (\n e.aliases?.some(\n (a: string) =>\n a.toLowerCase() === lowerHandle ||\n (e.type === \"agent\" && `agent${a.toLowerCase()}` === lowerHandle)\n )\n ) {\n return true;\n }\n return false;\n });\n\n let id = entity?.id;\n let label = entity?.label || entity?.handle || rawHandle;\n let type = entity?.type;\n let avatarUrl = entity?.avatarUrl;\n let color = entity?.color || entity?.hexColor;\n\n if (!entity) {\n const customResolved = resolveMention?.(rawHandle);\n if (customResolved) {\n id = customResolved.id ?? id;\n label = customResolved.label ?? customResolved.handle ?? label;\n type = customResolved.type ?? type;\n avatarUrl = customResolved.avatarUrl ?? avatarUrl;\n color = customResolved.color ?? customResolved.hexColor ?? color;\n } else {\n const stripped = lowerHandle.replace(/^agent[\\s\\-_]*/i, \"\");\n if (\n [\"supervisor\", \"coordinator\", \"planner\", \"validator\", \"executor\"].includes(stripped)\n ) {\n type = \"agent\";\n id = stripped;\n label = stripped;\n } else if (lowerHandle === \"agents\") {\n type = \"team\";\n id = \"agents\";\n label = \"agents\";\n } else {\n type = defaultType;\n id = rawHandle;\n label = rawHandle;\n }\n }\n }\n\n const avatarAttr = avatarUrl ? ` data-avatar-url=\"${escapeHtml(avatarUrl)}\"` : \"\";\n const colorAttr = color ? ` data-color=\"${escapeHtml(color)}\"` : \"\";\n\n return `${prefix}<span class=\"pixerate-mention-node\" data-type=\"mention\" data-id=\"${escapeHtml(\n id || label\n )}\" data-label=\"${escapeHtml(label)}\" data-mention-suggestion-char=\"@\" data-type-name=\"${escapeHtml(\n type || defaultType\n )}\"${avatarAttr}${colorAttr}>@${escapeHtml(label)}</span>`;\n });\n })\n .join(\"\");\n}\n","/**\n * Escapes characters that have syntactic meaning in HTML text.\n */\nexport function escapeHtml(text: string): string {\n if (!text) return \"\";\n return text\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .replace(/\"/g, \"&quot;\")\n .replace(/'/g, \"&#039;\");\n}\n\n/**\n * Matches strings that are already TipTap paragraph HTML (start with `<p>` and\n * end with `</p>`), as opposed to plain text that merely mentions a `<p>` tag.\n */\nconst PARAGRAPH_HTML_REGEX = /^\\s*<p[\\s>][\\s\\S]*<\\/p>\\s*$/i;\n\n/**\n * Converts a plain-text string with newlines into HTML paragraphs suitable\n * for TipTap initial content or setContent, preserving line breaks.\n * Input that is already paragraph HTML (`<p>…</p>`) is passed through as-is.\n */\nexport function plainTextToTipTapHtml(text: string): string {\n if (!text) return \"<p></p>\";\n if (PARAGRAPH_HTML_REGEX.test(text)) {\n return text;\n }\n return text\n .replace(/\\r\\n/g, \"\\n\")\n .replace(/\\r/g, \"\\n\")\n .split(\"\\n\")\n .map((line) => `<p>${escapeHtml(line)}</p>`)\n .join(\"\");\n}\n\n/**\n * Block-level elements that start a new line in plain-text output.\n */\nconst BLOCK_TAGS = new Set([\n \"P\", \"DIV\", \"LI\", \"UL\", \"OL\", \"PRE\", \"BLOCKQUOTE\", \"TABLE\", \"TR\",\n \"H1\", \"H2\", \"H3\", \"H4\", \"H5\", \"H6\", \"HR\",\n]);\n\n/**\n * Matches a TipTap mention span (including its content). The lookahead keeps\n * a single `[^>]*` scan per tag, avoiding catastrophic backtracking on\n * malformed input.\n */\nconst MENTION_SPAN_REGEX =\n /<span\\b(?=[^>]*\\bdata-type=[\"']mention[\"'])([^>]*)>[\\s\\S]*?<\\/span>/gi;\n\nfunction getHtmlAttribute(attrs: string, name: string): string | undefined {\n const match = new RegExp(`\\\\b${name}=(?:\"([^\"]*)\"|'([^']*)')`, \"i\").exec(\n attrs,\n );\n return match ? (match[1] ?? match[2]) : undefined;\n}\n\n/**\n * Parses HTML into an inert fragment. Content of a `<template>` element is not\n * rendered, so `<img onerror>` and similar handlers never run.\n */\nfunction parseHtmlFragment(html: string): DocumentFragment {\n const template = document.createElement(\"template\");\n template.innerHTML = html;\n return template.content;\n}\n\nfunction decodeHtmlEntities(text: string): string {\n return text\n .replace(/&lt;/g, \"<\")\n .replace(/&gt;/g, \">\")\n .replace(/&quot;/g, '\"')\n .replace(/&#0*39;/g, \"'\")\n .replace(/&nbsp;/g, \"\\u00a0\")\n .replace(/&amp;/g, \"&\");\n}\n\n/**\n * Extracts plain text from an HTML string or TipTap HTML, preserving newlines between block tags.\n */\nexport function htmlToPlainText(html: string): string {\n if (!html) return \"\";\n\n // Normalize mentions so data-label is preserved as @label even if textContent is empty\n const mentionNormalized = html.replace(MENTION_SPAN_REGEX, (match, attrs) => {\n const label =\n getHtmlAttribute(attrs, \"data-label\") || getHtmlAttribute(attrs, \"data-id\");\n return label ? `@${label}` : match;\n });\n\n if (typeof document !== \"undefined\") {\n const fragment = parseHtmlFragment(mentionNormalized);\n fragment\n .querySelectorAll(\"br.ProseMirror-trailingBreak\")\n .forEach((br) => br.remove());\n\n // Walk the tree, emitting one line per innermost block so nested blocks\n // (e.g. TipTap's <li><p>…</p></li>) are not repeated.\n const lines: string[] = [];\n let current: string | null = null;\n const flush = () => {\n if (current !== null) {\n lines.push(current);\n current = null;\n }\n };\n const visit = (node: Node) => {\n if (node.nodeType === 3) {\n const value = node.nodeValue ?? \"\";\n // Skip formatting whitespace between blocks.\n if (current === null && value.trim() === \"\") return;\n current = (current ?? \"\") + value;\n return;\n }\n if (node.nodeType !== 1) return;\n const tag = (node as Element).tagName.toUpperCase();\n if (tag === \"BR\") {\n current = (current ?? \"\") + \"\\n\";\n return;\n }\n if (!BLOCK_TAGS.has(tag)) {\n node.childNodes.forEach(visit);\n return;\n }\n flush();\n const linesBefore = lines.length;\n node.childNodes.forEach(visit);\n flush();\n // An empty block (e.g. <p></p>) is an empty line.\n if (lines.length === linesBefore && tag !== \"HR\") {\n lines.push(\"\");\n }\n };\n fragment.childNodes.forEach(visit);\n flush();\n return lines.join(\"\\n\");\n }\n\n // Node.js fallback regex\n const text = mentionNormalized\n .replace(/<br\\s*\\/?>/gi, \"\\n\")\n // A closing block, plus any closing wrappers right after it, ends one line.\n .replace(\n /<\\/(?:p|div|li|pre|blockquote|h[1-6])>(?:\\s*<\\/(?:li|ul|ol|blockquote|div)>)*/gi,\n \"\\n\",\n )\n .replace(/<[^>]+>/g, \"\");\n return decodeHtmlEntities(text).replace(/\\n$/, \"\");\n}\n\n/**\n * Extracts plain text from a TipTap editor instance, preserving newline separators\n * between block nodes and converting mention nodes to @label.\n */\nexport function getEditorText(editor: any): string {\n if (!editor) return \"\";\n const html = typeof editor.getHTML === \"function\" ? editor.getHTML() : \"\";\n if (html) {\n return htmlToPlainText(html);\n }\n if (typeof editor.getText === \"function\") {\n try {\n return editor.getText({ blockSeparator: \"\\n\" });\n } catch {\n return editor.getText();\n }\n }\n return \"\";\n}\n\nexport interface ExtractedMention {\n id: string;\n label: string;\n type?: string;\n avatarUrl?: string;\n color?: string;\n [key: string]: any;\n}\n\nimport { extractMentions } from \"./mentions\";\n\n/**\n * Traverses an editor instance, ProseMirror document, JSONContent, or HTML string\n * and extracts all mention attributes without needing regex.\n */\nexport function extractMentionsFromDoc(docOrEditor: any): ExtractedMention[] {\n if (!docOrEditor) return [];\n const mentions: ExtractedMention[] = [];\n\n // TipTap editor or ProseMirror Node with .descendants()\n const doc =\n docOrEditor?.state?.doc ||\n (typeof docOrEditor?.descendants === \"function\" ? docOrEditor : null);\n\n if (doc && typeof doc.descendants === \"function\") {\n doc.descendants((node: any) => {\n if (node.type?.name === \"mention\" && node.attrs) {\n mentions.push({\n id: node.attrs.id || \"\",\n label: node.attrs.label || \"\",\n type: node.attrs.type,\n avatarUrl: node.attrs.avatarUrl,\n color: node.attrs.color,\n ...node.attrs,\n });\n }\n });\n return mentions;\n }\n\n // JSONContent tree\n if (typeof docOrEditor === \"object\" && docOrEditor.content) {\n const walk = (nodes: any[]) => {\n for (const node of nodes) {\n if (node.type === \"mention\" && node.attrs) {\n mentions.push({\n id: node.attrs.id || \"\",\n label: node.attrs.label || \"\",\n type: node.attrs.type,\n avatarUrl: node.attrs.avatarUrl,\n color: node.attrs.color,\n ...node.attrs,\n });\n }\n if (Array.isArray(node.content)) {\n walk(node.content);\n }\n }\n };\n walk(docOrEditor.content);\n return mentions;\n }\n\n // HTML String\n if (typeof docOrEditor === \"string\") {\n if (typeof document !== \"undefined\") {\n parseHtmlFragment(docOrEditor).querySelectorAll('span[data-type=\"mention\"]').forEach((el) => {\n mentions.push({\n id: el.getAttribute(\"data-id\") || \"\",\n label: el.getAttribute(\"data-label\") || \"\",\n type: el.getAttribute(\"data-type-name\") || undefined,\n avatarUrl: el.getAttribute(\"data-avatar-url\") || undefined,\n color: el.getAttribute(\"data-color\") || undefined,\n });\n });\n } else {\n const spanRegex = /<span([^>]*data-type=[\"']mention[\"'][^>]*)>/gi;\n let match;\n while ((match = spanRegex.exec(docOrEditor)) !== null) {\n const attrStr = match[1];\n const getAttr = (name: string) => {\n const m = new RegExp(`${name}=[\"']([^\"']*)[\"']`, \"i\").exec(attrStr);\n return m ? m[1] : undefined;\n };\n mentions.push({\n id: getAttr(\"data-id\") || \"\",\n label: getAttr(\"data-label\") || \"\",\n type: getAttr(\"data-type-name\") || getAttr(\"data-entity-type\"),\n avatarUrl: getAttr(\"data-avatar-url\"),\n color: getAttr(\"data-color\"),\n });\n }\n }\n\n // Fallback: If no HTML mention tags were found, extract raw @mentions from text or markdown\n if (mentions.length === 0) {\n const rawHandles = extractMentions(docOrEditor);\n for (const handle of rawHandles) {\n mentions.push({\n id: handle,\n label: handle,\n type: \"user\",\n });\n }\n }\n }\n\n return mentions;\n}\n","import MarkdownIt from \"markdown-it\";\nimport taskLists from \"markdown-it-task-lists\";\nimport { escapeHtml, getEditorText } from \"./plain-text\";\n\nconst md = new MarkdownIt({\n html: true,\n linkify: true,\n breaks: true,\n}).use(taskLists);\n\nconst defaultValidateLink = md.validateLink;\nmd.validateLink = (url: string) => {\n if (\n url.startsWith(\"file://\") ||\n url.startsWith(\"vscode://\") ||\n url.startsWith(\"cursor://\")\n ) {\n return true;\n }\n return defaultValidateLink.call(md, url);\n};\n\n/**\n * Tags allowed through from raw HTML embedded in markdown (e.g. mention spans\n * and file links that tiptap-markdown serializes as HTML). Anything else is\n * rendered as escaped text. `input` is limited to checkboxes, which\n * markdown-it-task-lists emits as raw HTML.\n */\nconst ALLOWED_HTML_TAGS = new Set([\n \"a\", \"abbr\", \"b\", \"blockquote\", \"br\", \"code\", \"del\", \"details\", \"div\", \"em\",\n \"h1\", \"h2\", \"h3\", \"h4\", \"h5\", \"h6\", \"hr\", \"i\", \"img\", \"input\", \"kbd\", \"li\", \"mark\",\n \"ol\", \"p\", \"pre\", \"s\", \"span\", \"strong\", \"sub\", \"summary\", \"sup\", \"table\",\n \"tbody\", \"td\", \"tfoot\", \"th\", \"thead\", \"tr\", \"u\", \"ul\",\n]);\n\nconst ALLOWED_HTML_ATTRS = new Set([\n \"alt\", \"align\", \"checked\", \"class\", \"colspan\", \"disabled\", \"height\", \"href\",\n \"rel\", \"rowspan\", \"src\", \"start\", \"target\", \"title\", \"type\", \"width\",\n]);\n\nconst HTML_TAG_REGEX =\n /<(\\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\\s+[^\\s\"'>\\/=]+(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s\"'=<>`]+))?)*)\\s*\\/?>/g;\nconst HTML_ATTR_REGEX =\n /([^\\s\"'>\\/=]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'=<>`]+)))?/g;\n\nfunction sanitizeTag(\n tagText: string,\n isClosing: string,\n rawTagName: string,\n rawAttrs: string,\n): string {\n const tagName = rawTagName.toLowerCase();\n if (!ALLOWED_HTML_TAGS.has(tagName)) return escapeHtml(tagText);\n if (isClosing) return `</${tagName}>`;\n if (tagName === \"input\" && !/\\stype\\s*=\\s*[\"']?checkbox[\"']?[\\s>/]/i.test(tagText)) {\n return escapeHtml(tagText);\n }\n\n let attrs = \"\";\n let attrMatch: RegExpExecArray | null;\n HTML_ATTR_REGEX.lastIndex = 0;\n while ((attrMatch = HTML_ATTR_REGEX.exec(rawAttrs)) !== null) {\n const name = attrMatch[1].toLowerCase();\n if (!ALLOWED_HTML_ATTRS.has(name) && !/^data-[a-z0-9_.-]+$/.test(name)) {\n continue;\n }\n const rawValue = attrMatch[2] ?? attrMatch[3] ?? attrMatch[4];\n if (rawValue === undefined) {\n attrs += ` ${name}`;\n continue;\n }\n const value = md.utils.unescapeAll(rawValue);\n if (\n (name === \"href\" || name === \"src\") &&\n // Browsers ignore control characters and whitespace inside schemes.\n !md.validateLink(value.replace(/[\\u0000-\\u0020\\u007f]/g, \"\"))\n ) {\n continue;\n }\n attrs += ` ${name}=\"${escapeHtml(value)}\"`;\n }\n return `<${tagName}${attrs}>`;\n}\n\n/**\n * Sanitizes raw HTML with an allowlist of tags and attributes: event handlers,\n * `style`, and unsafe URL schemes are dropped; disallowed tags are escaped.\n */\nfunction sanitizeEmbeddedHtml(html: string): string {\n let result = \"\";\n let lastIndex = 0;\n let match: RegExpExecArray | null;\n HTML_TAG_REGEX.lastIndex = 0;\n while ((match = HTML_TAG_REGEX.exec(html)) !== null) {\n result += html.slice(lastIndex, match.index).replace(/</g, \"&lt;\");\n result += sanitizeTag(match[0], match[1], match[2], match[3]);\n lastIndex = match.index + match[0].length;\n }\n return result + html.slice(lastIndex).replace(/</g, \"&lt;\");\n}\n\nconst defaultHtmlInline = md.renderer.rules.html_inline;\nconst defaultHtmlBlock = md.renderer.rules.html_block;\nmd.renderer.rules.html_inline = (tokens, idx, options, env, self) =>\n env?.allowUnsafeHtml\n ? defaultHtmlInline!(tokens, idx, options, env, self)\n : sanitizeEmbeddedHtml(tokens[idx].content);\nmd.renderer.rules.html_block = (tokens, idx, options, env, self) =>\n env?.allowUnsafeHtml\n ? defaultHtmlBlock!(tokens, idx, options, env, self)\n : sanitizeEmbeddedHtml(tokens[idx].content);\n\nimport {\n preprocessMarkdownMentions,\n type PreprocessMarkdownMentionsOptions,\n} from \"./mentions\";\nimport type { MentionEntity } from \"../extensions/mention\";\n\n/**\n * Preprocesses file-protocol and editor-protocol links in markdown content:\n * converts [label](file://...), vscode://, and cursor:// links into anchor tags\n * annotated with data-file-link=\"true\", preserving code backticks in labels.\n */\nexport function preprocessMarkdownFileLinks(content: string): string {\n if (!content) return \"\";\n return content.replace(\n /\\[([^\\]]+)\\]\\(((?:file|vscode|cursor):\\/\\/[^)]+)\\)/g,\n (_match, rawLabel, href) => {\n const trimmed = rawLabel.trim();\n const codeMatch = trimmed.match(/^`([^`]+)`$/);\n const labelContent = codeMatch\n ? `<code>${escapeHtml(codeMatch[1])}</code>`\n : escapeHtml(trimmed);\n return `<a href=\"${escapeHtml(href)}\" data-file-link=\"true\" title=\"Click to copy file path\">${labelContent}</a>`;\n }\n );\n}\n\nexport interface MarkdownToHtmlOptions {\n /**\n * Preprocess file, vscode, and cursor links into clickable data-file-link tags.\n */\n preprocessFileLinks?: boolean;\n /**\n * Whether to preprocess @mentions into TipTap mention node HTML spans.\n */\n preprocessMentions?: boolean;\n /**\n * Pool of mentionables to pass to preprocessMarkdownMentions.\n */\n mentionables?: MentionEntity[];\n /**\n * Full options for preprocessMarkdownMentions.\n */\n preprocessOptions?: PreprocessMarkdownMentionsOptions;\n /**\n * Render raw HTML embedded in the markdown without sanitizing it. By default,\n * embedded HTML is restricted to an allowlist of tags and attributes (event\n * handlers, `style` and unsafe URL schemes are removed). Only enable this for\n * fully trusted input.\n */\n allowUnsafeHtml?: boolean;\n}\n\n/**\n * Converts a markdown string into HTML suitable for TipTap initial content or setContent.\n * Raw HTML embedded in the markdown is sanitized unless `allowUnsafeHtml` is set.\n */\nexport function markdownToTipTapHtml(\n markdown: string,\n options?: MarkdownToHtmlOptions\n): string {\n if (!markdown) return \"<p></p>\";\n let content = markdown;\n if (options?.preprocessFileLinks) {\n content = preprocessMarkdownFileLinks(content);\n }\n if (\n options?.preprocessMentions ||\n options?.mentionables ||\n options?.preprocessOptions\n ) {\n const mentionOpts = options.preprocessOptions || {\n mentionables: options.mentionables,\n };\n content = preprocessMarkdownMentions(content, mentionOpts);\n }\n return md.render(content, { allowUnsafeHtml: options?.allowUnsafeHtml });\n}\n\n/**\n * Extracts clean markdown from a TipTap editor instance.\n * If the editor has the Markdown extension configured, it uses editor.storage.markdown.getMarkdown().\n * Otherwise, it falls back to getEditorText(editor).\n */\nexport function getEditorMarkdown(editor: any): string {\n if (!editor) return \"\";\n if (typeof editor.storage?.markdown?.getMarkdown === \"function\") {\n return editor.storage.markdown.getMarkdown();\n }\n return getEditorText(editor);\n}\n"]}