@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
@@ -1,563 +1,33 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
29
2
 
30
- // src/serializers/index.ts
31
- var serializers_exports = {};
32
- __export(serializers_exports, {
33
- MARKDOWN_MENTION_SPLIT_REGEX: () => MARKDOWN_MENTION_SPLIT_REGEX,
34
- MENTION_REGEX: () => MENTION_REGEX,
35
- escapeHtml: () => escapeHtml,
36
- extractMentions: () => extractMentions,
37
- extractMentionsFromDoc: () => extractMentionsFromDoc,
38
- getEditorMarkdown: () => getEditorMarkdown,
39
- getEditorText: () => getEditorText,
40
- htmlToPlainText: () => htmlToPlainText,
41
- markdownToTipTapHtml: () => markdownToTipTapHtml,
42
- parseMentionSegments: () => parseMentionSegments,
43
- plainTextToTipTapHtml: () => plainTextToTipTapHtml,
44
- preprocessMarkdownFileLinks: () => preprocessMarkdownFileLinks,
45
- preprocessMarkdownMentions: () => preprocessMarkdownMentions,
46
- stripMarkdownCode: () => stripMarkdownCode
47
- });
48
- module.exports = __toCommonJS(serializers_exports);
49
3
 
50
- // src/serializers/mentions.ts
51
- var MENTION_REGEX = /(?:^|[\s>(*_"';\\/[\]{}~`:]|"|>|<|&)@(?:"([^"]+)"|"([^&]+)"|([a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_-]+)*))/g;
52
- 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;
53
- function stripMarkdownCode(content) {
54
- if (!content || typeof content !== "string") return "";
55
- 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, "");
56
- }
57
- function extractMentions(content) {
58
- if (!content || typeof content !== "string") return [];
59
- const normalizedMentionNodes = content.replace(
60
- /<span\b[^>]*\b(?:data-type=["']mention["']|class=["'][^"']*pixerate-mention-node[^"']*["'])[^>]*>([\s\S]*?)<\/span>/gi,
61
- (match2, inner) => {
62
- const labelMatch = match2.match(/\bdata-label=["']([^"']+)["']/i);
63
- if (labelMatch) return ` @${labelMatch[1]} `;
64
- const idMatch = match2.match(/\bdata-id=["']([^"']+)["']/i);
65
- if (idMatch) return ` @${idMatch[1]} `;
66
- return ` ${inner} `;
67
- }
68
- );
69
- const cleanContent = stripMarkdownCode(normalizedMentionNodes);
70
- const withoutUrls = cleanContent.replace(/(?:https?|ftp|file|vscode|cursor|mailto):\/\/[^\s<>()]+/gi, "").replace(/\]\([^)]*\)/g, "]");
71
- const textOnly = withoutUrls.replace(/<[^>]+>/g, " ");
72
- const mentions = [];
73
- const seen = /* @__PURE__ */ new Set();
74
- const regex = new RegExp(MENTION_REGEX.source, "g");
75
- let match;
76
- while ((match = regex.exec(textOnly)) !== null) {
77
- const handle = (match[1] ?? match[2] ?? match[3] ?? "").trim();
78
- if (handle && !seen.has(handle)) {
79
- seen.add(handle);
80
- mentions.push(handle);
81
- }
82
- }
83
- return mentions;
84
- }
85
- function parseMentionSegments(content) {
86
- if (!content) return [];
87
- const segments = [];
88
- const regex = new RegExp(MENTION_REGEX.source, "g");
89
- let lastIndex = 0;
90
- let match;
91
- while ((match = regex.exec(content)) !== null) {
92
- const fullMatch = match[0];
93
- const atIndex = fullMatch.indexOf("@");
94
- const prefix = atIndex > 0 ? fullMatch.slice(0, atIndex) : "";
95
- const mentionToken = fullMatch.slice(atIndex);
96
- const handle = match[1] ?? match[2] ?? match[3];
97
- const matchStart = match.index + prefix.length;
98
- if (matchStart > lastIndex) {
99
- segments.push({
100
- type: "text",
101
- value: content.slice(lastIndex, matchStart)
102
- });
103
- }
104
- segments.push({
105
- type: "mention",
106
- value: mentionToken,
107
- handle
108
- });
109
- lastIndex = matchStart + mentionToken.length;
110
- }
111
- if (lastIndex < content.length) {
112
- segments.push({
113
- type: "text",
114
- value: content.slice(lastIndex)
115
- });
116
- }
117
- return segments;
118
- }
119
- function preprocessMarkdownMentions(content, optionsOrMentionables = []) {
120
- if (!content || typeof content !== "string") return "";
121
- const options = Array.isArray(optionsOrMentionables) ? { mentionables: optionsOrMentionables } : optionsOrMentionables;
122
- const allMentionables = options.mentionables || [];
123
- const defaultType = options.defaultType || "user";
124
- const resolveMention = options.resolveMention;
125
- const parts = content.split(MARKDOWN_MENTION_SPLIT_REGEX);
126
- return parts.map((part) => {
127
- if (!part) return "";
128
- 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(
129
- part
130
- )) {
131
- return part;
132
- }
133
- const regex = new RegExp(MENTION_REGEX.source, "g");
134
- return part.replace(regex, (match, quotedHandle, escapedQuotedHandle, standardHandle) => {
135
- const atIndex = match.indexOf("@");
136
- const prefix = atIndex > 0 ? match.slice(0, atIndex) : "";
137
- const rawHandle = (quotedHandle || escapedQuotedHandle || standardHandle || "").trim();
138
- if (!rawHandle) return match;
139
- const lowerHandle = rawHandle.toLowerCase();
140
- const entity = allMentionables.find((e) => {
141
- if (e.label?.toLowerCase() === lowerHandle) return true;
142
- if (e.handle?.toLowerCase() === lowerHandle) return true;
143
- if (e.name?.toLowerCase() === lowerHandle) return true;
144
- if (e.id?.toLowerCase() === lowerHandle) return true;
145
- if (e.type === "agent" && `agent${(e.handle || e.label || "").toLowerCase()}` === lowerHandle) return true;
146
- if (e.aliases?.some(
147
- (a) => a.toLowerCase() === lowerHandle || e.type === "agent" && `agent${a.toLowerCase()}` === lowerHandle
148
- )) {
149
- return true;
150
- }
151
- return false;
152
- });
153
- let id = entity?.id;
154
- let label = entity?.label || entity?.handle || rawHandle;
155
- let type = entity?.type;
156
- let avatarUrl = entity?.avatarUrl;
157
- let color = entity?.color || entity?.hexColor;
158
- if (!entity) {
159
- const customResolved = resolveMention?.(rawHandle);
160
- if (customResolved) {
161
- id = customResolved.id ?? id;
162
- label = customResolved.label ?? customResolved.handle ?? label;
163
- type = customResolved.type ?? type;
164
- avatarUrl = customResolved.avatarUrl ?? avatarUrl;
165
- color = customResolved.color ?? customResolved.hexColor ?? color;
166
- } else {
167
- const stripped = lowerHandle.replace(/^agent[\s\-_]*/i, "");
168
- if (["supervisor", "coordinator", "planner", "validator", "executor"].includes(stripped)) {
169
- type = "agent";
170
- id = stripped;
171
- label = stripped;
172
- } else if (lowerHandle === "agents") {
173
- type = "team";
174
- id = "agents";
175
- label = "agents";
176
- } else {
177
- type = defaultType;
178
- id = rawHandle;
179
- label = rawHandle;
180
- }
181
- }
182
- }
183
- const avatarAttr = avatarUrl ? ` data-avatar-url="${escapeHtml(avatarUrl)}"` : "";
184
- const colorAttr = color ? ` data-color="${escapeHtml(color)}"` : "";
185
- return `${prefix}<span class="pixerate-mention-node" data-type="mention" data-id="${escapeHtml(
186
- id || label
187
- )}" data-label="${escapeHtml(label)}" data-mention-suggestion-char="@" data-type-name="${escapeHtml(
188
- type || defaultType
189
- )}"${avatarAttr}${colorAttr}>@${escapeHtml(label)}</span>`;
190
- });
191
- }).join("");
192
- }
193
4
 
194
- // src/serializers/plain-text.ts
195
- function escapeHtml(text) {
196
- if (!text) return "";
197
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
198
- }
199
- var PARAGRAPH_HTML_REGEX = /^\s*<p[\s>][\s\S]*<\/p>\s*$/i;
200
- function plainTextToTipTapHtml(text) {
201
- if (!text) return "<p></p>";
202
- if (PARAGRAPH_HTML_REGEX.test(text)) {
203
- return text;
204
- }
205
- return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n").map((line) => `<p>${escapeHtml(line)}</p>`).join("");
206
- }
207
- var BLOCK_TAGS = /* @__PURE__ */ new Set([
208
- "P",
209
- "DIV",
210
- "LI",
211
- "UL",
212
- "OL",
213
- "PRE",
214
- "BLOCKQUOTE",
215
- "TABLE",
216
- "TR",
217
- "H1",
218
- "H2",
219
- "H3",
220
- "H4",
221
- "H5",
222
- "H6",
223
- "HR"
224
- ]);
225
- var MENTION_SPAN_REGEX = /<span\b(?=[^>]*\bdata-type=["']mention["'])([^>]*)>[\s\S]*?<\/span>/gi;
226
- function getHtmlAttribute(attrs, name) {
227
- const match = new RegExp(`\\b${name}=(?:"([^"]*)"|'([^']*)')`, "i").exec(
228
- attrs
229
- );
230
- return match ? match[1] ?? match[2] : void 0;
231
- }
232
- function parseHtmlFragment(html) {
233
- const template = document.createElement("template");
234
- template.innerHTML = html;
235
- return template.content;
236
- }
237
- function decodeHtmlEntities(text) {
238
- return text.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#0*39;/g, "'").replace(/&nbsp;/g, "\xA0").replace(/&amp;/g, "&");
239
- }
240
- function htmlToPlainText(html) {
241
- if (!html) return "";
242
- const mentionNormalized = html.replace(MENTION_SPAN_REGEX, (match, attrs) => {
243
- const label = getHtmlAttribute(attrs, "data-label") || getHtmlAttribute(attrs, "data-id");
244
- return label ? `@${label}` : match;
245
- });
246
- if (typeof document !== "undefined") {
247
- const fragment = parseHtmlFragment(mentionNormalized);
248
- fragment.querySelectorAll("br.ProseMirror-trailingBreak").forEach((br) => br.remove());
249
- const lines = [];
250
- let current = null;
251
- const flush = () => {
252
- if (current !== null) {
253
- lines.push(current);
254
- current = null;
255
- }
256
- };
257
- const visit = (node) => {
258
- if (node.nodeType === 3) {
259
- const value = node.nodeValue ?? "";
260
- if (current === null && value.trim() === "") return;
261
- current = (current ?? "") + value;
262
- return;
263
- }
264
- if (node.nodeType !== 1) return;
265
- const tag = node.tagName.toUpperCase();
266
- if (tag === "BR") {
267
- current = (current ?? "") + "\n";
268
- return;
269
- }
270
- if (!BLOCK_TAGS.has(tag)) {
271
- node.childNodes.forEach(visit);
272
- return;
273
- }
274
- flush();
275
- const linesBefore = lines.length;
276
- node.childNodes.forEach(visit);
277
- flush();
278
- if (lines.length === linesBefore && tag !== "HR") {
279
- lines.push("");
280
- }
281
- };
282
- fragment.childNodes.forEach(visit);
283
- flush();
284
- return lines.join("\n");
285
- }
286
- const text = mentionNormalized.replace(/<br\s*\/?>/gi, "\n").replace(
287
- /<\/(?:p|div|li|pre|blockquote|h[1-6])>(?:\s*<\/(?:li|ul|ol|blockquote|div)>)*/gi,
288
- "\n"
289
- ).replace(/<[^>]+>/g, "");
290
- return decodeHtmlEntities(text).replace(/\n$/, "");
291
- }
292
- function getEditorText(editor) {
293
- if (!editor) return "";
294
- const html = typeof editor.getHTML === "function" ? editor.getHTML() : "";
295
- if (html) {
296
- return htmlToPlainText(html);
297
- }
298
- if (typeof editor.getText === "function") {
299
- try {
300
- return editor.getText({ blockSeparator: "\n" });
301
- } catch {
302
- return editor.getText();
303
- }
304
- }
305
- return "";
306
- }
307
- function extractMentionsFromDoc(docOrEditor) {
308
- if (!docOrEditor) return [];
309
- const mentions = [];
310
- const doc = docOrEditor?.state?.doc || (typeof docOrEditor?.descendants === "function" ? docOrEditor : null);
311
- if (doc && typeof doc.descendants === "function") {
312
- doc.descendants((node) => {
313
- if (node.type?.name === "mention" && node.attrs) {
314
- mentions.push({
315
- id: node.attrs.id || "",
316
- label: node.attrs.label || "",
317
- type: node.attrs.type,
318
- avatarUrl: node.attrs.avatarUrl,
319
- color: node.attrs.color,
320
- ...node.attrs
321
- });
322
- }
323
- });
324
- return mentions;
325
- }
326
- if (typeof docOrEditor === "object" && docOrEditor.content) {
327
- const walk = (nodes) => {
328
- for (const node of nodes) {
329
- if (node.type === "mention" && node.attrs) {
330
- mentions.push({
331
- id: node.attrs.id || "",
332
- label: node.attrs.label || "",
333
- type: node.attrs.type,
334
- avatarUrl: node.attrs.avatarUrl,
335
- color: node.attrs.color,
336
- ...node.attrs
337
- });
338
- }
339
- if (Array.isArray(node.content)) {
340
- walk(node.content);
341
- }
342
- }
343
- };
344
- walk(docOrEditor.content);
345
- return mentions;
346
- }
347
- if (typeof docOrEditor === "string") {
348
- if (typeof document !== "undefined") {
349
- parseHtmlFragment(docOrEditor).querySelectorAll('span[data-type="mention"]').forEach((el) => {
350
- mentions.push({
351
- id: el.getAttribute("data-id") || "",
352
- label: el.getAttribute("data-label") || "",
353
- type: el.getAttribute("data-type-name") || void 0,
354
- avatarUrl: el.getAttribute("data-avatar-url") || void 0,
355
- color: el.getAttribute("data-color") || void 0
356
- });
357
- });
358
- } else {
359
- const spanRegex = /<span([^>]*data-type=["']mention["'][^>]*)>/gi;
360
- let match;
361
- while ((match = spanRegex.exec(docOrEditor)) !== null) {
362
- const attrStr = match[1];
363
- const getAttr = (name) => {
364
- const m = new RegExp(`${name}=["']([^"']*)["']`, "i").exec(attrStr);
365
- return m ? m[1] : void 0;
366
- };
367
- mentions.push({
368
- id: getAttr("data-id") || "",
369
- label: getAttr("data-label") || "",
370
- type: getAttr("data-type-name") || getAttr("data-entity-type"),
371
- avatarUrl: getAttr("data-avatar-url"),
372
- color: getAttr("data-color")
373
- });
374
- }
375
- }
376
- if (mentions.length === 0) {
377
- const rawHandles = extractMentions(docOrEditor);
378
- for (const handle of rawHandles) {
379
- mentions.push({
380
- id: handle,
381
- label: handle,
382
- type: "user"
383
- });
384
- }
385
- }
386
- }
387
- return mentions;
388
- }
389
5
 
390
- // src/serializers/markdown.ts
391
- var import_markdown_it = __toESM(require("markdown-it"), 1);
392
- var import_markdown_it_task_lists = __toESM(require("markdown-it-task-lists"), 1);
393
- var md = new import_markdown_it.default({
394
- html: true,
395
- linkify: true,
396
- breaks: true
397
- }).use(import_markdown_it_task_lists.default);
398
- var defaultValidateLink = md.validateLink;
399
- md.validateLink = (url) => {
400
- if (url.startsWith("file://") || url.startsWith("vscode://") || url.startsWith("cursor://")) {
401
- return true;
402
- }
403
- return defaultValidateLink.call(md, url);
404
- };
405
- var ALLOWED_HTML_TAGS = /* @__PURE__ */ new Set([
406
- "a",
407
- "abbr",
408
- "b",
409
- "blockquote",
410
- "br",
411
- "code",
412
- "del",
413
- "details",
414
- "div",
415
- "em",
416
- "h1",
417
- "h2",
418
- "h3",
419
- "h4",
420
- "h5",
421
- "h6",
422
- "hr",
423
- "i",
424
- "img",
425
- "input",
426
- "kbd",
427
- "li",
428
- "mark",
429
- "ol",
430
- "p",
431
- "pre",
432
- "s",
433
- "span",
434
- "strong",
435
- "sub",
436
- "summary",
437
- "sup",
438
- "table",
439
- "tbody",
440
- "td",
441
- "tfoot",
442
- "th",
443
- "thead",
444
- "tr",
445
- "u",
446
- "ul"
447
- ]);
448
- var ALLOWED_HTML_ATTRS = /* @__PURE__ */ new Set([
449
- "alt",
450
- "align",
451
- "checked",
452
- "class",
453
- "colspan",
454
- "disabled",
455
- "height",
456
- "href",
457
- "rel",
458
- "rowspan",
459
- "src",
460
- "start",
461
- "target",
462
- "title",
463
- "type",
464
- "width"
465
- ]);
466
- var HTML_TAG_REGEX = /<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\s+[^\s"'>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*)\s*\/?>/g;
467
- var HTML_ATTR_REGEX = /([^\s"'>\/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
468
- function sanitizeTag(tagText, isClosing, rawTagName, rawAttrs) {
469
- const tagName = rawTagName.toLowerCase();
470
- if (!ALLOWED_HTML_TAGS.has(tagName)) return escapeHtml(tagText);
471
- if (isClosing) return `</${tagName}>`;
472
- if (tagName === "input" && !/\stype\s*=\s*["']?checkbox["']?[\s>/]/i.test(tagText)) {
473
- return escapeHtml(tagText);
474
- }
475
- let attrs = "";
476
- let attrMatch;
477
- HTML_ATTR_REGEX.lastIndex = 0;
478
- while ((attrMatch = HTML_ATTR_REGEX.exec(rawAttrs)) !== null) {
479
- const name = attrMatch[1].toLowerCase();
480
- if (!ALLOWED_HTML_ATTRS.has(name) && !/^data-[a-z0-9_.-]+$/.test(name)) {
481
- continue;
482
- }
483
- const rawValue = attrMatch[2] ?? attrMatch[3] ?? attrMatch[4];
484
- if (rawValue === void 0) {
485
- attrs += ` ${name}`;
486
- continue;
487
- }
488
- const value = md.utils.unescapeAll(rawValue);
489
- if ((name === "href" || name === "src") && // Browsers ignore control characters and whitespace inside schemes.
490
- !md.validateLink(value.replace(/[\u0000-\u0020\u007f]/g, ""))) {
491
- continue;
492
- }
493
- attrs += ` ${name}="${escapeHtml(value)}"`;
494
- }
495
- return `<${tagName}${attrs}>`;
496
- }
497
- function sanitizeEmbeddedHtml(html) {
498
- let result = "";
499
- let lastIndex = 0;
500
- let match;
501
- HTML_TAG_REGEX.lastIndex = 0;
502
- while ((match = HTML_TAG_REGEX.exec(html)) !== null) {
503
- result += html.slice(lastIndex, match.index).replace(/</g, "&lt;");
504
- result += sanitizeTag(match[0], match[1], match[2], match[3]);
505
- lastIndex = match.index + match[0].length;
506
- }
507
- return result + html.slice(lastIndex).replace(/</g, "&lt;");
508
- }
509
- var defaultHtmlInline = md.renderer.rules.html_inline;
510
- var defaultHtmlBlock = md.renderer.rules.html_block;
511
- md.renderer.rules.html_inline = (tokens, idx, options, env, self) => env?.allowUnsafeHtml ? defaultHtmlInline(tokens, idx, options, env, self) : sanitizeEmbeddedHtml(tokens[idx].content);
512
- md.renderer.rules.html_block = (tokens, idx, options, env, self) => env?.allowUnsafeHtml ? defaultHtmlBlock(tokens, idx, options, env, self) : sanitizeEmbeddedHtml(tokens[idx].content);
513
- function preprocessMarkdownFileLinks(content) {
514
- if (!content) return "";
515
- return content.replace(
516
- /\[([^\]]+)\]\(((?:file|vscode|cursor):\/\/[^)]+)\)/g,
517
- (_match, rawLabel, href) => {
518
- const trimmed = rawLabel.trim();
519
- const codeMatch = trimmed.match(/^`([^`]+)`$/);
520
- const labelContent = codeMatch ? `<code>${escapeHtml(codeMatch[1])}</code>` : escapeHtml(trimmed);
521
- return `<a href="${escapeHtml(href)}" data-file-link="true" title="Click to copy file path">${labelContent}</a>`;
522
- }
523
- );
524
- }
525
- function markdownToTipTapHtml(markdown, options) {
526
- if (!markdown) return "<p></p>";
527
- let content = markdown;
528
- if (options?.preprocessFileLinks) {
529
- content = preprocessMarkdownFileLinks(content);
530
- }
531
- if (options?.preprocessMentions || options?.mentionables || options?.preprocessOptions) {
532
- const mentionOpts = options.preprocessOptions || {
533
- mentionables: options.mentionables
534
- };
535
- content = preprocessMarkdownMentions(content, mentionOpts);
536
- }
537
- return md.render(content, { allowUnsafeHtml: options?.allowUnsafeHtml });
538
- }
539
- function getEditorMarkdown(editor) {
540
- if (!editor) return "";
541
- if (typeof editor.storage?.markdown?.getMarkdown === "function") {
542
- return editor.storage.markdown.getMarkdown();
543
- }
544
- return getEditorText(editor);
545
- }
546
- // Annotate the CommonJS export names for ESM import in node:
547
- 0 && (module.exports = {
548
- MARKDOWN_MENTION_SPLIT_REGEX,
549
- MENTION_REGEX,
550
- escapeHtml,
551
- extractMentions,
552
- extractMentionsFromDoc,
553
- getEditorMarkdown,
554
- getEditorText,
555
- htmlToPlainText,
556
- markdownToTipTapHtml,
557
- parseMentionSegments,
558
- plainTextToTipTapHtml,
559
- preprocessMarkdownFileLinks,
560
- preprocessMarkdownMentions,
561
- stripMarkdownCode
562
- });
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+ var _chunkSHWP2A43cjs = require('../chunk-SHWP2A43.cjs');
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ exports.MARKDOWN_MENTION_SPLIT_REGEX = _chunkSHWP2A43cjs.MARKDOWN_MENTION_SPLIT_REGEX; exports.MENTION_REGEX = _chunkSHWP2A43cjs.MENTION_REGEX; exports.escapeHtml = _chunkSHWP2A43cjs.escapeHtml; exports.extractMentions = _chunkSHWP2A43cjs.extractMentions; exports.extractMentionsFromDoc = _chunkSHWP2A43cjs.extractMentionsFromDoc; exports.getEditorMarkdown = _chunkSHWP2A43cjs.getEditorMarkdown; exports.getEditorText = _chunkSHWP2A43cjs.getEditorText; exports.htmlToPlainText = _chunkSHWP2A43cjs.htmlToPlainText; exports.markdownToTipTapHtml = _chunkSHWP2A43cjs.markdownToTipTapHtml; exports.parseMentionSegments = _chunkSHWP2A43cjs.parseMentionSegments; exports.plainTextToTipTapHtml = _chunkSHWP2A43cjs.plainTextToTipTapHtml; exports.preprocessMarkdownFileLinks = _chunkSHWP2A43cjs.preprocessMarkdownFileLinks; exports.preprocessMarkdownMentions = _chunkSHWP2A43cjs.preprocessMarkdownMentions; exports.stripMarkdownCode = _chunkSHWP2A43cjs.stripMarkdownCode;
563
33
  //# sourceMappingURL=index.cjs.map