@pixerate/editor 0.23.0 → 0.25.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.
- package/README.md +167 -2
- package/THIRD_PARTY_NOTICES.md +80 -0
- package/dist/agent/index.cjs +10 -8
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +4 -3
- package/dist/agent/index.d.ts +4 -3
- package/dist/agent/index.js +4 -2
- package/dist/agent/index.js.map +1 -1
- package/dist/canvas/index.cjs +4437 -411
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.d.cts +934 -4
- package/dist/canvas/index.d.ts +934 -4
- package/dist/canvas/index.js +4309 -283
- package/dist/canvas/index.js.map +1 -1
- package/dist/chunk-4BVP64JJ.cjs +1406 -0
- package/dist/chunk-4BVP64JJ.cjs.map +1 -0
- package/dist/chunk-664LQYFJ.js +115 -0
- package/dist/chunk-664LQYFJ.js.map +1 -0
- package/dist/chunk-7WISYZFO.cjs +740 -0
- package/dist/chunk-7WISYZFO.cjs.map +1 -0
- package/dist/chunk-AL6JMGWW.cjs +783 -0
- package/dist/chunk-AL6JMGWW.cjs.map +1 -0
- package/dist/chunk-BVP3TSLH.cjs +69 -0
- package/dist/chunk-BVP3TSLH.cjs.map +1 -0
- package/dist/{chunk-RIKBJLS2.cjs → chunk-C7P22VIP.cjs} +2001 -279
- package/dist/chunk-C7P22VIP.cjs.map +1 -0
- package/dist/chunk-D6FH2YAX.cjs +131 -0
- package/dist/chunk-D6FH2YAX.cjs.map +1 -0
- package/dist/chunk-ECCCYKGL.js +740 -0
- package/dist/chunk-ECCCYKGL.js.map +1 -0
- package/dist/{chunk-4SUNJZWB.cjs → chunk-FD4LPFAE.cjs} +48 -200
- package/dist/chunk-FD4LPFAE.cjs.map +1 -0
- package/dist/{chunk-QBJ22YZR.js → chunk-FH6F67DN.js} +1999 -277
- package/dist/chunk-FH6F67DN.js.map +1 -0
- package/dist/{chunk-OYXSKQFR.js → chunk-FPENXAEJ.js} +35 -187
- package/dist/chunk-FPENXAEJ.js.map +1 -0
- package/dist/chunk-HLIMTC6N.js +1 -0
- package/dist/chunk-HLIMTC6N.js.map +1 -0
- package/dist/chunk-HRMEDT2L.js +1406 -0
- package/dist/chunk-HRMEDT2L.js.map +1 -0
- package/dist/{chunk-QGHGJ56O.js → chunk-IXHSYOVY.js} +2518 -122
- package/dist/chunk-IXHSYOVY.js.map +1 -0
- package/dist/chunk-MKA3AHLV.cjs +256 -0
- package/dist/chunk-MKA3AHLV.cjs.map +1 -0
- package/dist/chunk-NAXVVS5I.js +783 -0
- package/dist/chunk-NAXVVS5I.js.map +1 -0
- package/dist/chunk-O5RYH2PG.js +69 -0
- package/dist/chunk-O5RYH2PG.js.map +1 -0
- package/dist/chunk-OXSV64JX.js +689 -0
- package/dist/chunk-OXSV64JX.js.map +1 -0
- package/dist/chunk-P3RQ5UJE.cjs +689 -0
- package/dist/chunk-P3RQ5UJE.cjs.map +1 -0
- package/dist/chunk-P6ODPZ4W.js +256 -0
- package/dist/chunk-P6ODPZ4W.js.map +1 -0
- package/dist/chunk-PL4JB3BF.cjs +1 -0
- package/dist/chunk-PL4JB3BF.cjs.map +1 -0
- package/dist/{chunk-GVSMRPHB.cjs → chunk-PO6A6QQH.cjs} +2607 -211
- package/dist/chunk-PO6A6QQH.cjs.map +1 -0
- package/dist/{chunk-JJDLPEWL.js → chunk-QGYDWPRM.js} +2 -2
- package/dist/chunk-RR7F5GUM.js +5726 -0
- package/dist/chunk-RR7F5GUM.js.map +1 -0
- package/dist/chunk-TNNJXF46.cjs +115 -0
- package/dist/chunk-TNNJXF46.cjs.map +1 -0
- package/dist/chunk-U5HZSFCS.js +131 -0
- package/dist/chunk-U5HZSFCS.js.map +1 -0
- package/dist/{chunk-MJZBNWG7.js → chunk-UAKDG62Z.js} +309 -581
- package/dist/chunk-UAKDG62Z.js.map +1 -0
- package/dist/{chunk-CL37JGFW.cjs → chunk-V3CHHWOE.cjs} +4 -4
- package/dist/{chunk-CL37JGFW.cjs.map → chunk-V3CHHWOE.cjs.map} +1 -1
- package/dist/chunk-WSQKHXW7.cjs +5726 -0
- package/dist/chunk-WSQKHXW7.cjs.map +1 -0
- package/dist/{chunk-AA4ZEVCC.cjs → chunk-X4N4WUKB.cjs} +336 -608
- package/dist/chunk-X4N4WUKB.cjs.map +1 -0
- package/dist/commands/index.cjs +74 -1
- package/dist/commands/index.cjs.map +1 -1
- package/dist/commands/index.d.cts +38 -353
- package/dist/commands/index.d.ts +38 -353
- package/dist/commands/index.js +73 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/comment-store-BEMgVlAA.d.cts +135 -0
- package/dist/comment-store-BEMgVlAA.d.ts +135 -0
- package/dist/compare/index.cjs +15 -0
- package/dist/compare/index.cjs.map +1 -0
- package/dist/compare/index.d.cts +58 -0
- package/dist/compare/index.d.ts +58 -0
- package/dist/compare/index.js +15 -0
- package/dist/compare/index.js.map +1 -0
- package/dist/controller-BIJiNoVs.d.cts +1842 -0
- package/dist/controller-BIJiNoVs.d.ts +1842 -0
- package/dist/documents-CHT1U5Vs.d.ts +86 -0
- package/dist/documents-Gp7wb0Me.d.cts +86 -0
- package/dist/extensions/index.cjs +100 -5
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +16 -4
- package/dist/extensions/index.d.ts +16 -4
- package/dist/extensions/index.js +100 -5
- package/dist/generation/index.cjs +2317 -0
- package/dist/generation/index.cjs.map +1 -0
- package/dist/generation/index.d.cts +1015 -0
- package/dist/generation/index.d.ts +1015 -0
- package/dist/generation/index.js +2317 -0
- package/dist/generation/index.js.map +1 -0
- package/dist/grammar/index.cjs +48 -3
- package/dist/grammar/index.cjs.map +1 -1
- package/dist/grammar/index.d.cts +322 -100
- package/dist/grammar/index.d.ts +322 -100
- package/dist/grammar/index.js +54 -9
- package/dist/image-editor/index.cjs +4392 -481
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +1249 -97
- package/dist/image-editor/index.d.ts +1249 -97
- package/dist/image-editor/index.js +4281 -370
- package/dist/image-editor/index.js.map +1 -1
- package/dist/index-7a6bHTLy.d.ts +1754 -0
- package/dist/index-Csd5qI8u.d.cts +1754 -0
- package/dist/index.cjs +1682 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +118 -21
- package/dist/index.d.ts +118 -21
- package/dist/index.js +1630 -47
- package/dist/index.js.map +1 -1
- package/dist/mention-text-CDnCFd3c.d.cts +53 -0
- package/dist/mention-text-CDnCFd3c.d.ts +53 -0
- package/dist/migrate-iTlm3a8h.d.cts +112 -0
- package/dist/migrate-iTlm3a8h.d.ts +112 -0
- package/dist/model-C1zApQM8.d.cts +219 -0
- package/dist/model-C1zApQM8.d.ts +219 -0
- package/dist/persistence/index.cjs +676 -0
- package/dist/persistence/index.cjs.map +1 -0
- package/dist/persistence/index.d.cts +230 -0
- package/dist/persistence/index.d.ts +230 -0
- package/dist/persistence/index.js +676 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/{registry-D5-R90p0.d.cts → registry-BDe-vlv3.d.ts} +2 -40
- package/dist/{registry-GJI4gToU.d.ts → registry-CEgwXED1.d.cts} +12 -1
- package/dist/{registry-GJI4gToU.d.cts → registry-CEgwXED1.d.ts} +12 -1
- package/dist/registry-D32LpIc4.d.cts +354 -0
- package/dist/{registry-D5-R90p0.d.ts → registry-DnzpgY27.d.cts} +2 -40
- package/dist/registry-evKTP4ls.d.ts +354 -0
- package/dist/schema-DYDGdYL9.d.cts +41 -0
- package/dist/schema-DYDGdYL9.d.ts +41 -0
- package/dist/serializers/index.cjs +12 -3
- package/dist/serializers/index.cjs.map +1 -1
- package/dist/serializers/index.d.cts +40 -12
- package/dist/serializers/index.d.ts +40 -12
- package/dist/serializers/index.js +12 -3
- package/dist/sourcemap-C8AH3MBQ.d.cts +91 -0
- package/dist/sourcemap-DA1Evhrv.d.ts +91 -0
- package/dist/spreadsheet/index.cjs +161 -3
- package/dist/spreadsheet/index.cjs.map +1 -1
- package/dist/spreadsheet/index.d.cts +611 -20
- package/dist/spreadsheet/index.d.ts +611 -20
- package/dist/spreadsheet/index.js +168 -10
- package/dist/storage-BpFfspHm.d.cts +120 -0
- package/dist/storage-BpFfspHm.d.ts +120 -0
- package/dist/tokens/index.cjs +115 -0
- package/dist/tokens/index.cjs.map +1 -0
- package/dist/tokens/index.d.cts +212 -0
- package/dist/tokens/index.d.ts +212 -0
- package/dist/tokens/index.js +115 -0
- package/dist/tokens/index.js.map +1 -0
- package/dist/{tokens-CyLZmIei.d.cts → tokens-D7yXvUU6.d.cts} +15 -2
- package/dist/{tokens-CyLZmIei.d.ts → tokens-D7yXvUU6.d.ts} +15 -2
- package/dist/{track-changes-BSF58RK0.d.cts → track-changes-D_VAPELi.d.cts} +110 -144
- package/dist/{track-changes-BSF58RK0.d.ts → track-changes-Db_fGEvx.d.ts} +110 -144
- package/package.json +21 -1
- package/dist/chunk-4SUNJZWB.cjs.map +0 -1
- package/dist/chunk-AA4ZEVCC.cjs.map +0 -1
- package/dist/chunk-AXV2ZW34.cjs +0 -118
- package/dist/chunk-AXV2ZW34.cjs.map +0 -1
- package/dist/chunk-B2ZRLN4S.js +0 -118
- package/dist/chunk-B2ZRLN4S.js.map +0 -1
- package/dist/chunk-GVSMRPHB.cjs.map +0 -1
- package/dist/chunk-K3R5NG2D.js +0 -3100
- package/dist/chunk-K3R5NG2D.js.map +0 -1
- package/dist/chunk-MJZBNWG7.js.map +0 -1
- package/dist/chunk-OYXSKQFR.js.map +0 -1
- package/dist/chunk-QBJ22YZR.js.map +0 -1
- package/dist/chunk-QGHGJ56O.js.map +0 -1
- package/dist/chunk-RIKBJLS2.cjs.map +0 -1
- package/dist/chunk-XDMXXC4Z.cjs +0 -3100
- package/dist/chunk-XDMXXC4Z.cjs.map +0 -1
- package/dist/controller-pePCJLT1.d.cts +0 -959
- package/dist/controller-pePCJLT1.d.ts +0 -959
- package/dist/index-CCr_z9kF.d.cts +0 -899
- package/dist/index-Ck6ajwXh.d.ts +0 -899
- /package/dist/{chunk-JJDLPEWL.js.map → chunk-QGYDWPRM.js.map} +0 -0
|
@@ -0,0 +1,740 @@
|
|
|
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; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkBVP3TSLHcjs = require('./chunk-BVP3TSLH.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkX4N4WUKBcjs = require('./chunk-X4N4WUKB.cjs');
|
|
12
|
+
|
|
13
|
+
// src/serializers/plain-text.ts
|
|
14
|
+
var _model = require('@tiptap/pm/model');
|
|
15
|
+
|
|
16
|
+
// src/serializers/html-scan.ts
|
|
17
|
+
function findTagSpans(html, tag, attrTest, requireClose) {
|
|
18
|
+
const matches = typeof attrTest === "function" ? attrTest : (attrs) => attrTest.test(attrs);
|
|
19
|
+
const spans = [];
|
|
20
|
+
const openTag = new RegExp(`<${tag}\\b`, "gi");
|
|
21
|
+
const closeTag = new RegExp(`</${tag}>`, "gi");
|
|
22
|
+
const closeLength = tag.length + 3;
|
|
23
|
+
let nextGt = -1;
|
|
24
|
+
let nextClose = -1;
|
|
25
|
+
let from = 0;
|
|
26
|
+
for (; ; ) {
|
|
27
|
+
openTag.lastIndex = from;
|
|
28
|
+
const open = openTag.exec(html);
|
|
29
|
+
if (!open) break;
|
|
30
|
+
const start = open.index;
|
|
31
|
+
const attrsStart = start + open[0].length;
|
|
32
|
+
if (nextGt < attrsStart) {
|
|
33
|
+
nextGt = html.indexOf(">", attrsStart);
|
|
34
|
+
if (nextGt === -1) break;
|
|
35
|
+
}
|
|
36
|
+
const attrs = html.slice(attrsStart, nextGt);
|
|
37
|
+
const openEnd = nextGt + 1;
|
|
38
|
+
if (!matches(attrs)) {
|
|
39
|
+
from = attrsStart;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (!requireClose) {
|
|
43
|
+
spans.push({ start, openEnd, end: openEnd, attrs });
|
|
44
|
+
from = openEnd;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (nextClose < openEnd) {
|
|
48
|
+
closeTag.lastIndex = openEnd;
|
|
49
|
+
const close = closeTag.exec(html);
|
|
50
|
+
if (!close) break;
|
|
51
|
+
nextClose = close.index;
|
|
52
|
+
}
|
|
53
|
+
const end = nextClose + closeLength;
|
|
54
|
+
spans.push({ start, openEnd, end, attrs });
|
|
55
|
+
from = end;
|
|
56
|
+
}
|
|
57
|
+
return spans;
|
|
58
|
+
}
|
|
59
|
+
function replaceTagSpans(html, tag, attrTest, replace) {
|
|
60
|
+
const spans = findTagSpans(html, tag, attrTest, true);
|
|
61
|
+
if (spans.length === 0) return html;
|
|
62
|
+
let out = "";
|
|
63
|
+
let last = 0;
|
|
64
|
+
for (const span of spans) {
|
|
65
|
+
out += html.slice(last, span.start) + replace(html.slice(span.start, span.end), span.attrs);
|
|
66
|
+
last = span.end;
|
|
67
|
+
}
|
|
68
|
+
return out + html.slice(last);
|
|
69
|
+
}
|
|
70
|
+
function stripTags(html, replacement = "") {
|
|
71
|
+
let out = "";
|
|
72
|
+
let from = 0;
|
|
73
|
+
for (; ; ) {
|
|
74
|
+
const lt = html.indexOf("<", from);
|
|
75
|
+
if (lt === -1) break;
|
|
76
|
+
const gt = html.indexOf(">", lt + 1);
|
|
77
|
+
if (gt === -1) break;
|
|
78
|
+
if (gt === lt + 1) {
|
|
79
|
+
out += html.slice(from, gt + 1);
|
|
80
|
+
} else {
|
|
81
|
+
out += html.slice(from, lt) + replacement;
|
|
82
|
+
}
|
|
83
|
+
from = gt + 1;
|
|
84
|
+
}
|
|
85
|
+
return out + html.slice(from);
|
|
86
|
+
}
|
|
87
|
+
function replaceDelimited(text, open, close, replace = () => "", caseInsensitiveClose = false) {
|
|
88
|
+
const haystack = caseInsensitiveClose ? asciiLower(text) : text;
|
|
89
|
+
const needle = caseInsensitiveClose ? close.toLowerCase() : close;
|
|
90
|
+
let out = "";
|
|
91
|
+
let last = 0;
|
|
92
|
+
let from = 0;
|
|
93
|
+
let nextClose = -1;
|
|
94
|
+
for (; ; ) {
|
|
95
|
+
open.lastIndex = from;
|
|
96
|
+
const opened = open.exec(text);
|
|
97
|
+
if (!opened) break;
|
|
98
|
+
const afterOpen = opened.index + Math.max(opened[0].length, 1);
|
|
99
|
+
if (nextClose < afterOpen) {
|
|
100
|
+
nextClose = haystack.indexOf(needle, afterOpen);
|
|
101
|
+
if (nextClose === -1) break;
|
|
102
|
+
}
|
|
103
|
+
const end = nextClose + close.length;
|
|
104
|
+
out += text.slice(last, opened.index) + replace(text.slice(opened.index, end));
|
|
105
|
+
last = from = end;
|
|
106
|
+
}
|
|
107
|
+
return out + text.slice(last);
|
|
108
|
+
}
|
|
109
|
+
function asciiLower(text) {
|
|
110
|
+
return text.replace(/[A-Z]+/g, (m) => m.toLowerCase());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/serializers/plain-text.ts
|
|
114
|
+
var TRACKED_DELETION_ATTRIBUTE = /\bdata-change-type=["']deletion["']/i;
|
|
115
|
+
var TRACKED_INSERTION_ATTRIBUTE = /\bdata-change-type=["']insertion["']/i;
|
|
116
|
+
function stripTrackedChanges(html, view) {
|
|
117
|
+
if (view === "all" || !html.includes("data-change-type")) return html;
|
|
118
|
+
return view === "accepted" ? replaceTagSpans(html, "del", TRACKED_DELETION_ATTRIBUTE, () => "") : replaceTagSpans(html, "ins", TRACKED_INSERTION_ATTRIBUTE, () => "");
|
|
119
|
+
}
|
|
120
|
+
function escapeHtml(text) {
|
|
121
|
+
if (!text) return "";
|
|
122
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
123
|
+
}
|
|
124
|
+
var PARAGRAPH_HTML_REGEX = /^\s*<p[\s>][\s\S]*<\/p>\s*$/i;
|
|
125
|
+
function plainTextToTipTapHtml(text) {
|
|
126
|
+
if (!text) return "<p></p>";
|
|
127
|
+
if (PARAGRAPH_HTML_REGEX.test(text)) {
|
|
128
|
+
return text;
|
|
129
|
+
}
|
|
130
|
+
return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n").map((line) => `<p>${escapeHtml(line)}</p>`).join("");
|
|
131
|
+
}
|
|
132
|
+
function plainTextToSlice(text, schema) {
|
|
133
|
+
const nodes = [];
|
|
134
|
+
text.replace(/\r\n?/g, "\n").split("\n").forEach((line) => {
|
|
135
|
+
const nodeJson = { type: "paragraph" };
|
|
136
|
+
if (line.length > 0) {
|
|
137
|
+
nodeJson.content = [{ type: "text", text: line }];
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
nodes.push(_model.Node.fromJSON(schema, nodeJson));
|
|
141
|
+
} catch (e2) {
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return _model.Slice.maxOpen(_model.Fragment.fromArray(nodes));
|
|
145
|
+
}
|
|
146
|
+
var BLOCK_TAGS = /* @__PURE__ */ new Set([
|
|
147
|
+
"P",
|
|
148
|
+
"DIV",
|
|
149
|
+
"LI",
|
|
150
|
+
"UL",
|
|
151
|
+
"OL",
|
|
152
|
+
"PRE",
|
|
153
|
+
"BLOCKQUOTE",
|
|
154
|
+
"TABLE",
|
|
155
|
+
"TR",
|
|
156
|
+
"H1",
|
|
157
|
+
"H2",
|
|
158
|
+
"H3",
|
|
159
|
+
"H4",
|
|
160
|
+
"H5",
|
|
161
|
+
"H6",
|
|
162
|
+
"HR"
|
|
163
|
+
]);
|
|
164
|
+
var MENTION_TYPE_ATTRIBUTE = /\bdata-type=["']mention["']/i;
|
|
165
|
+
function getHtmlAttribute(attrs, name) {
|
|
166
|
+
const match = new RegExp(`\\b${name}=(?:"([^"]*)"|'([^']*)')`, "i").exec(
|
|
167
|
+
attrs
|
|
168
|
+
);
|
|
169
|
+
return match ? _nullishCoalesce(match[1], () => ( match[2])) : void 0;
|
|
170
|
+
}
|
|
171
|
+
function parseHtmlFragment(html) {
|
|
172
|
+
const template = document.createElement("template");
|
|
173
|
+
template.innerHTML = html;
|
|
174
|
+
return template.content;
|
|
175
|
+
}
|
|
176
|
+
function decodeHtmlEntities(text) {
|
|
177
|
+
return text.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/�*39;/g, "'").replace(/ /g, "\xA0").replace(/&/g, "&");
|
|
178
|
+
}
|
|
179
|
+
function htmlToPlainText(html, options = {}) {
|
|
180
|
+
if (!html) return "";
|
|
181
|
+
const trackedResolved = stripTrackedChanges(
|
|
182
|
+
html,
|
|
183
|
+
_nullishCoalesce(options.trackedChanges, () => ( "accepted"))
|
|
184
|
+
);
|
|
185
|
+
const mentionNormalized = replaceTagSpans(trackedResolved, "span", MENTION_TYPE_ATTRIBUTE, (match, attrs) => {
|
|
186
|
+
const label = getHtmlAttribute(attrs, "data-label") || getHtmlAttribute(attrs, "data-id");
|
|
187
|
+
const role = getHtmlAttribute(attrs, "data-role");
|
|
188
|
+
const validRole = role && /^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$/.test(role) ? role : "";
|
|
189
|
+
return label ? `@${label}${validRole ? `:${validRole}` : ""}` : match;
|
|
190
|
+
});
|
|
191
|
+
if (typeof document !== "undefined") {
|
|
192
|
+
const fragment = parseHtmlFragment(mentionNormalized);
|
|
193
|
+
fragment.querySelectorAll("br.ProseMirror-trailingBreak").forEach((br) => br.remove());
|
|
194
|
+
const lines = [];
|
|
195
|
+
let current = null;
|
|
196
|
+
const flush = () => {
|
|
197
|
+
if (current !== null) {
|
|
198
|
+
lines.push(current);
|
|
199
|
+
current = null;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const visit = (node) => {
|
|
203
|
+
if (node.nodeType === 3) {
|
|
204
|
+
const value = _nullishCoalesce(node.nodeValue, () => ( ""));
|
|
205
|
+
if (current === null && value.trim() === "") return;
|
|
206
|
+
current = (_nullishCoalesce(current, () => ( ""))) + value;
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (node.nodeType !== 1) return;
|
|
210
|
+
const tag = node.tagName.toUpperCase();
|
|
211
|
+
if (tag === "BR") {
|
|
212
|
+
current = (_nullishCoalesce(current, () => ( ""))) + "\n";
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (!BLOCK_TAGS.has(tag)) {
|
|
216
|
+
node.childNodes.forEach(visit);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
flush();
|
|
220
|
+
const linesBefore = lines.length;
|
|
221
|
+
node.childNodes.forEach(visit);
|
|
222
|
+
flush();
|
|
223
|
+
if (lines.length === linesBefore && tag !== "HR") {
|
|
224
|
+
lines.push("");
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
fragment.childNodes.forEach(visit);
|
|
228
|
+
flush();
|
|
229
|
+
return lines.join("\n");
|
|
230
|
+
}
|
|
231
|
+
const text = mentionNormalized.replace(/<br\s*\/?>/gi, "\n").replace(
|
|
232
|
+
/<\/(?:p|div|li|pre|blockquote|h[1-6])>(?:\s*<\/(?:li|ul|ol|blockquote|div)>)*/gi,
|
|
233
|
+
"\n"
|
|
234
|
+
);
|
|
235
|
+
return decodeHtmlEntities(stripTags(text)).replace(/\n$/, "");
|
|
236
|
+
}
|
|
237
|
+
function resolvedBlockOperationsHtml(editor, view) {
|
|
238
|
+
const doc = _optionalChain([editor, 'optionalAccess', _ => _.state, 'optionalAccess', _2 => _2.doc]);
|
|
239
|
+
if (!doc || view === "all" || typeof document === "undefined") return null;
|
|
240
|
+
let found = false;
|
|
241
|
+
doc.descendants((node) => {
|
|
242
|
+
if (found) return false;
|
|
243
|
+
if (node.isTextblock) {
|
|
244
|
+
if (_optionalChain([node, 'access', _3 => _3.attrs, 'optionalAccess', _4 => _4[_chunkX4N4WUKBcjs.BLOCK_CHANGE_ATTRIBUTE], 'optionalAccess', _5 => _5.operation])) found = true;
|
|
245
|
+
else node.forEach((child) => {
|
|
246
|
+
if (child.marks.some((mark) => _optionalChain([mark, 'access', _6 => _6.attrs, 'optionalAccess', _7 => _7[_chunkX4N4WUKBcjs.MOVE_ID_ATTRIBUTE]]))) found = true;
|
|
247
|
+
});
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
return true;
|
|
251
|
+
});
|
|
252
|
+
if (!found) return null;
|
|
253
|
+
const resolved = _chunkX4N4WUKBcjs.resolveTrackedChanges.call(void 0, doc, view);
|
|
254
|
+
const container = document.createElement("div");
|
|
255
|
+
container.appendChild(_model.DOMSerializer.fromSchema(doc.type.schema).serializeFragment(resolved.content));
|
|
256
|
+
return container.innerHTML;
|
|
257
|
+
}
|
|
258
|
+
function getEditorText(editor, options = {}) {
|
|
259
|
+
if (!editor) return "";
|
|
260
|
+
const html = _nullishCoalesce(resolvedBlockOperationsHtml(editor, _nullishCoalesce(options.trackedChanges, () => ( "accepted"))), () => ( (typeof editor.getHTML === "function" ? editor.getHTML() : "")));
|
|
261
|
+
if (html) {
|
|
262
|
+
return htmlToPlainText(html, options);
|
|
263
|
+
}
|
|
264
|
+
if (typeof editor.getText === "function") {
|
|
265
|
+
try {
|
|
266
|
+
return editor.getText({ blockSeparator: "\n" });
|
|
267
|
+
} catch (e3) {
|
|
268
|
+
return editor.getText();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return "";
|
|
272
|
+
}
|
|
273
|
+
function extractMentionsFromDoc(docOrEditor) {
|
|
274
|
+
if (!docOrEditor) return [];
|
|
275
|
+
const mentions = [];
|
|
276
|
+
const doc = _optionalChain([docOrEditor, 'optionalAccess', _8 => _8.state, 'optionalAccess', _9 => _9.doc]) || (typeof _optionalChain([docOrEditor, 'optionalAccess', _10 => _10.descendants]) === "function" ? docOrEditor : null);
|
|
277
|
+
if (doc && typeof doc.descendants === "function") {
|
|
278
|
+
doc.descendants((node) => {
|
|
279
|
+
if (_optionalChain([node, 'access', _11 => _11.type, 'optionalAccess', _12 => _12.name]) === "mention" && node.attrs) {
|
|
280
|
+
mentions.push({
|
|
281
|
+
id: node.attrs.id || "",
|
|
282
|
+
label: node.attrs.label || "",
|
|
283
|
+
type: node.attrs.type,
|
|
284
|
+
avatarUrl: node.attrs.avatarUrl,
|
|
285
|
+
color: node.attrs.color,
|
|
286
|
+
...node.attrs,
|
|
287
|
+
...node.attrs.assetRole ? { role: node.attrs.assetRole } : {}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
return mentions;
|
|
292
|
+
}
|
|
293
|
+
if (typeof docOrEditor === "object" && docOrEditor.content) {
|
|
294
|
+
const walk = (nodes) => {
|
|
295
|
+
for (const node of nodes) {
|
|
296
|
+
if (node.type === "mention" && node.attrs) {
|
|
297
|
+
mentions.push({
|
|
298
|
+
id: node.attrs.id || "",
|
|
299
|
+
label: node.attrs.label || "",
|
|
300
|
+
type: node.attrs.type,
|
|
301
|
+
avatarUrl: node.attrs.avatarUrl,
|
|
302
|
+
color: node.attrs.color,
|
|
303
|
+
...node.attrs,
|
|
304
|
+
...node.attrs.assetRole ? { role: node.attrs.assetRole } : {}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
if (Array.isArray(node.content)) {
|
|
308
|
+
walk(node.content);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
walk(docOrEditor.content);
|
|
313
|
+
return mentions;
|
|
314
|
+
}
|
|
315
|
+
if (typeof docOrEditor === "string") {
|
|
316
|
+
if (typeof document !== "undefined") {
|
|
317
|
+
parseHtmlFragment(docOrEditor).querySelectorAll('span[data-type="mention"]').forEach((el) => {
|
|
318
|
+
mentions.push({
|
|
319
|
+
id: el.getAttribute("data-id") || "",
|
|
320
|
+
label: el.getAttribute("data-label") || "",
|
|
321
|
+
type: el.getAttribute("data-type-name") || void 0,
|
|
322
|
+
avatarUrl: el.getAttribute("data-avatar-url") || void 0,
|
|
323
|
+
color: el.getAttribute("data-color") || void 0,
|
|
324
|
+
...el.getAttribute("data-role") ? { role: el.getAttribute("data-role") } : {}
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
} else {
|
|
328
|
+
for (const span of findTagSpans(docOrEditor, "span", MENTION_TYPE_ATTRIBUTE, false)) {
|
|
329
|
+
const attrStr = span.attrs;
|
|
330
|
+
const getAttr = (name) => {
|
|
331
|
+
const m = new RegExp(`${name}=["']([^"']*)["']`, "i").exec(attrStr);
|
|
332
|
+
return m ? m[1] : void 0;
|
|
333
|
+
};
|
|
334
|
+
mentions.push({
|
|
335
|
+
id: getAttr("data-id") || "",
|
|
336
|
+
label: getAttr("data-label") || "",
|
|
337
|
+
type: getAttr("data-type-name") || getAttr("data-entity-type"),
|
|
338
|
+
avatarUrl: getAttr("data-avatar-url"),
|
|
339
|
+
color: getAttr("data-color"),
|
|
340
|
+
...getAttr("data-role") ? { role: getAttr("data-role") } : {}
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (mentions.length === 0) {
|
|
345
|
+
const rawHandles = extractMentions(docOrEditor);
|
|
346
|
+
for (const handle of rawHandles) {
|
|
347
|
+
mentions.push({
|
|
348
|
+
id: handle,
|
|
349
|
+
label: handle,
|
|
350
|
+
type: "user"
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return mentions;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/serializers/mentions.ts
|
|
359
|
+
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;
|
|
360
|
+
function stripMarkdownCode(content) {
|
|
361
|
+
if (!content || typeof content !== "string") return "";
|
|
362
|
+
let text = replaceDelimited(content, /```/g, "```");
|
|
363
|
+
text = replaceDelimited(text, /~~~/g, "~~~");
|
|
364
|
+
text = replaceDelimited(text, /<pre/gi, "</pre>", void 0, true);
|
|
365
|
+
text = replaceDelimited(text, /<code/gi, "</code>", void 0, true);
|
|
366
|
+
return text.replace(/`[^`\n]*`/g, "");
|
|
367
|
+
}
|
|
368
|
+
function isMentionNodeAttributes(attrs) {
|
|
369
|
+
if (/\bdata-type=["']mention["']/i.test(attrs)) return true;
|
|
370
|
+
const classAttr = /\bclass=(["'])/i.exec(attrs);
|
|
371
|
+
if (!classAttr) return false;
|
|
372
|
+
const valueStart = classAttr.index + classAttr[0].length;
|
|
373
|
+
const valueEnd = attrs.indexOf(classAttr[1], valueStart);
|
|
374
|
+
return valueEnd !== -1 && attrs.slice(valueStart, valueEnd).includes("pixerate-mention-node");
|
|
375
|
+
}
|
|
376
|
+
function extractMentions(content, options = {}) {
|
|
377
|
+
if (!content || typeof content !== "string") return [];
|
|
378
|
+
const details = options.details === true;
|
|
379
|
+
let normalizedMentionNodes = "";
|
|
380
|
+
let last = 0;
|
|
381
|
+
for (const span of findTagSpans(content, "span", isMentionNodeAttributes, true)) {
|
|
382
|
+
const labelMatch = /\bdata-label=["']([^"']+)["']/i.exec(span.attrs);
|
|
383
|
+
const idMatch = labelMatch ? null : /\bdata-id=["']([^"']+)["']/i.exec(span.attrs);
|
|
384
|
+
const inner = content.slice(span.openEnd, span.end - "</span>".length);
|
|
385
|
+
let replacement = labelMatch ? ` @${labelMatch[1]} ` : idMatch ? ` @${idMatch[1]} ` : ` ${inner} `;
|
|
386
|
+
if (details && (labelMatch || idMatch)) {
|
|
387
|
+
const roleMatch = /\bdata-role=["']([^"']+)["']/i.exec(span.attrs);
|
|
388
|
+
const role = roleMatch && /^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$/.test(roleMatch[1]) ? roleMatch[1] : null;
|
|
389
|
+
const label = (_nullishCoalesce(labelMatch, () => ( idMatch)))[1];
|
|
390
|
+
replacement = ` ${_chunkBVP3TSLHcjs.formatMentionHandle.call(void 0, label)}${role ? _chunkBVP3TSLHcjs.NODE_ROLE_MARK + role : ""} `;
|
|
391
|
+
}
|
|
392
|
+
normalizedMentionNodes += content.slice(last, span.start) + replacement;
|
|
393
|
+
last = span.end;
|
|
394
|
+
}
|
|
395
|
+
normalizedMentionNodes += content.slice(last);
|
|
396
|
+
const cleanContent = stripMarkdownCode(normalizedMentionNodes);
|
|
397
|
+
const withoutUrls = cleanContent.replace(/(?:https?|ftp|file|vscode|cursor|mailto):\/\/[^\s<>()]+/gi, "");
|
|
398
|
+
const withoutLinks = replaceDelimited(withoutUrls, /\]\(/g, ")", () => "]");
|
|
399
|
+
const textOnly = stripTags(withoutLinks, " ");
|
|
400
|
+
const mentions = [];
|
|
401
|
+
const detailed = [];
|
|
402
|
+
const seen = /* @__PURE__ */ new Set();
|
|
403
|
+
const regex = new RegExp(_chunkBVP3TSLHcjs.MENTION_REGEX.source, "g");
|
|
404
|
+
let match;
|
|
405
|
+
while ((match = regex.exec(textOnly)) !== null) {
|
|
406
|
+
const handle = (_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(match[1], () => ( match[2])), () => ( match[3])), () => ( ""))).trim();
|
|
407
|
+
if (details) {
|
|
408
|
+
const suffix = _chunkBVP3TSLHcjs.readRoleSuffix.call(void 0, textOnly, regex.lastIndex, options.roles);
|
|
409
|
+
if (suffix) regex.lastIndex = suffix.end;
|
|
410
|
+
const key = `${handle}\0${_nullishCoalesce(_optionalChain([suffix, 'optionalAccess', _13 => _13.role]), () => ( ""))}`;
|
|
411
|
+
if (handle && !seen.has(key)) {
|
|
412
|
+
seen.add(key);
|
|
413
|
+
detailed.push(suffix ? { handle, role: suffix.role } : { handle });
|
|
414
|
+
}
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
if (handle && !seen.has(handle)) {
|
|
418
|
+
seen.add(handle);
|
|
419
|
+
mentions.push(handle);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return details ? detailed : mentions;
|
|
423
|
+
}
|
|
424
|
+
function parseMentionSegments(content, options = {}) {
|
|
425
|
+
if (!content) return [];
|
|
426
|
+
const segments = [];
|
|
427
|
+
const regex = new RegExp(_chunkBVP3TSLHcjs.MENTION_REGEX.source, "g");
|
|
428
|
+
let lastIndex = 0;
|
|
429
|
+
let match;
|
|
430
|
+
while ((match = regex.exec(content)) !== null) {
|
|
431
|
+
const fullMatch = match[0];
|
|
432
|
+
const atIndex = fullMatch.indexOf("@");
|
|
433
|
+
const prefix = atIndex > 0 ? fullMatch.slice(0, atIndex) : "";
|
|
434
|
+
let mentionToken = fullMatch.slice(atIndex);
|
|
435
|
+
const handle = _nullishCoalesce(_nullishCoalesce(match[1], () => ( match[2])), () => ( match[3]));
|
|
436
|
+
const matchStart = match.index + prefix.length;
|
|
437
|
+
const suffix = options.roles && content.charAt(regex.lastIndex) === ":" ? _chunkBVP3TSLHcjs.readRoleSuffix.call(void 0, content, regex.lastIndex, options.roles) : null;
|
|
438
|
+
if (suffix) {
|
|
439
|
+
mentionToken = content.slice(matchStart, suffix.end);
|
|
440
|
+
regex.lastIndex = suffix.end;
|
|
441
|
+
}
|
|
442
|
+
if (matchStart > lastIndex) {
|
|
443
|
+
segments.push({
|
|
444
|
+
type: "text",
|
|
445
|
+
value: content.slice(lastIndex, matchStart)
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
segments.push({
|
|
449
|
+
type: "mention",
|
|
450
|
+
value: mentionToken,
|
|
451
|
+
handle,
|
|
452
|
+
...suffix ? { role: suffix.role } : {}
|
|
453
|
+
});
|
|
454
|
+
lastIndex = matchStart + mentionToken.length;
|
|
455
|
+
}
|
|
456
|
+
if (lastIndex < content.length) {
|
|
457
|
+
segments.push({
|
|
458
|
+
type: "text",
|
|
459
|
+
value: content.slice(lastIndex)
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
return segments;
|
|
463
|
+
}
|
|
464
|
+
function preprocessMarkdownMentions(content, optionsOrMentionables = []) {
|
|
465
|
+
if (!content || typeof content !== "string") return "";
|
|
466
|
+
const options = Array.isArray(optionsOrMentionables) ? { mentionables: optionsOrMentionables } : optionsOrMentionables;
|
|
467
|
+
const allMentionables = options.mentionables || [];
|
|
468
|
+
const defaultType = options.defaultType || "user";
|
|
469
|
+
const resolveMention = options.resolveMention;
|
|
470
|
+
const parts = content.split(MARKDOWN_MENTION_SPLIT_REGEX);
|
|
471
|
+
return parts.map((part) => {
|
|
472
|
+
if (!part) return "";
|
|
473
|
+
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(
|
|
474
|
+
part
|
|
475
|
+
)) {
|
|
476
|
+
return part;
|
|
477
|
+
}
|
|
478
|
+
const regex = new RegExp(_chunkBVP3TSLHcjs.MENTION_REGEX.source, "g");
|
|
479
|
+
const render = (match2, quotedHandle, escapedQuotedHandle, standardHandle, role) => {
|
|
480
|
+
const atIndex = match2.indexOf("@");
|
|
481
|
+
const prefix = atIndex > 0 ? match2.slice(0, atIndex) : "";
|
|
482
|
+
const rawHandle = (quotedHandle || escapedQuotedHandle || standardHandle || "").trim();
|
|
483
|
+
if (!rawHandle) return match2;
|
|
484
|
+
const lowerHandle = rawHandle.toLowerCase();
|
|
485
|
+
const entity = allMentionables.find((e) => {
|
|
486
|
+
if (_optionalChain([e, 'access', _14 => _14.label, 'optionalAccess', _15 => _15.toLowerCase, 'call', _16 => _16()]) === lowerHandle) return true;
|
|
487
|
+
if (_optionalChain([e, 'access', _17 => _17.handle, 'optionalAccess', _18 => _18.toLowerCase, 'call', _19 => _19()]) === lowerHandle) return true;
|
|
488
|
+
if (_optionalChain([e, 'access', _20 => _20.name, 'optionalAccess', _21 => _21.toLowerCase, 'call', _22 => _22()]) === lowerHandle) return true;
|
|
489
|
+
if (_optionalChain([e, 'access', _23 => _23.id, 'optionalAccess', _24 => _24.toLowerCase, 'call', _25 => _25()]) === lowerHandle) return true;
|
|
490
|
+
if (e.type === "agent" && `agent${(e.handle || e.label || "").toLowerCase()}` === lowerHandle) return true;
|
|
491
|
+
if (_optionalChain([e, 'access', _26 => _26.aliases, 'optionalAccess', _27 => _27.some, 'call', _28 => _28(
|
|
492
|
+
(a) => a.toLowerCase() === lowerHandle || e.type === "agent" && `agent${a.toLowerCase()}` === lowerHandle
|
|
493
|
+
)])) {
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
return false;
|
|
497
|
+
});
|
|
498
|
+
let id = _optionalChain([entity, 'optionalAccess', _29 => _29.id]);
|
|
499
|
+
let label = _optionalChain([entity, 'optionalAccess', _30 => _30.label]) || _optionalChain([entity, 'optionalAccess', _31 => _31.handle]) || rawHandle;
|
|
500
|
+
let type = _optionalChain([entity, 'optionalAccess', _32 => _32.type]);
|
|
501
|
+
let avatarUrl = _optionalChain([entity, 'optionalAccess', _33 => _33.avatarUrl]);
|
|
502
|
+
let color = _optionalChain([entity, 'optionalAccess', _34 => _34.color]) || _optionalChain([entity, 'optionalAccess', _35 => _35.hexColor]);
|
|
503
|
+
if (!entity) {
|
|
504
|
+
const customResolved = _optionalChain([resolveMention, 'optionalCall', _36 => _36(rawHandle)]);
|
|
505
|
+
if (customResolved) {
|
|
506
|
+
id = _nullishCoalesce(customResolved.id, () => ( id));
|
|
507
|
+
label = _nullishCoalesce(_nullishCoalesce(customResolved.label, () => ( customResolved.handle)), () => ( label));
|
|
508
|
+
type = _nullishCoalesce(customResolved.type, () => ( type));
|
|
509
|
+
avatarUrl = _nullishCoalesce(customResolved.avatarUrl, () => ( avatarUrl));
|
|
510
|
+
color = _nullishCoalesce(_nullishCoalesce(customResolved.color, () => ( customResolved.hexColor)), () => ( color));
|
|
511
|
+
} else {
|
|
512
|
+
const stripped = lowerHandle.replace(/^agent[\s\-_]*/i, "");
|
|
513
|
+
if (["supervisor", "coordinator", "planner", "validator", "executor"].includes(stripped)) {
|
|
514
|
+
type = "agent";
|
|
515
|
+
id = stripped;
|
|
516
|
+
label = stripped;
|
|
517
|
+
} else if (lowerHandle === "agents") {
|
|
518
|
+
type = "team";
|
|
519
|
+
id = "agents";
|
|
520
|
+
label = "agents";
|
|
521
|
+
} else {
|
|
522
|
+
type = defaultType;
|
|
523
|
+
id = rawHandle;
|
|
524
|
+
label = rawHandle;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
const avatarAttr = avatarUrl ? ` data-avatar-url="${escapeHtml(avatarUrl)}"` : "";
|
|
529
|
+
const colorAttr = color ? ` data-color="${escapeHtml(color)}"` : "";
|
|
530
|
+
return `${prefix}<span class="pixerate-mention-node" data-type="mention" data-id="${escapeHtml(
|
|
531
|
+
id || label
|
|
532
|
+
)}" data-label="${escapeHtml(label)}" data-mention-suggestion-char="@" data-type-name="${escapeHtml(
|
|
533
|
+
type || defaultType
|
|
534
|
+
)}"${avatarAttr}${colorAttr}${role ? ` data-role="${escapeHtml(role)}"` : ""}>@${escapeHtml(label)}</span>`;
|
|
535
|
+
};
|
|
536
|
+
if (!options.roles) {
|
|
537
|
+
return part.replace(
|
|
538
|
+
regex,
|
|
539
|
+
(match2, quotedHandle, escapedQuotedHandle, standardHandle) => render(match2, quotedHandle, escapedQuotedHandle, standardHandle)
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
let out = "";
|
|
543
|
+
let last = 0;
|
|
544
|
+
let match;
|
|
545
|
+
while ((match = regex.exec(part)) !== null) {
|
|
546
|
+
const suffix = _chunkBVP3TSLHcjs.readRoleSuffix.call(void 0, part, regex.lastIndex, options.roles);
|
|
547
|
+
const rendered = render(match[0], match[1], match[2], match[3], _optionalChain([suffix, 'optionalAccess', _37 => _37.role]));
|
|
548
|
+
if (suffix && rendered !== match[0]) regex.lastIndex = suffix.end;
|
|
549
|
+
out += part.slice(last, match.index) + rendered;
|
|
550
|
+
last = regex.lastIndex;
|
|
551
|
+
}
|
|
552
|
+
return out + part.slice(last);
|
|
553
|
+
}).join("");
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// src/serializers/markdown.ts
|
|
557
|
+
var _markdownit = require('markdown-it'); var _markdownit2 = _interopRequireDefault(_markdownit);
|
|
558
|
+
var _markdownittasklists = require('markdown-it-task-lists'); var _markdownittasklists2 = _interopRequireDefault(_markdownittasklists);
|
|
559
|
+
var md = new (0, _markdownit2.default)({
|
|
560
|
+
html: true,
|
|
561
|
+
linkify: true,
|
|
562
|
+
breaks: true
|
|
563
|
+
}).use(_markdownittasklists2.default);
|
|
564
|
+
var defaultValidateLink = md.validateLink;
|
|
565
|
+
md.validateLink = (url) => {
|
|
566
|
+
if (url.startsWith("file://") || url.startsWith("vscode://") || url.startsWith("cursor://")) {
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
return defaultValidateLink.call(md, url);
|
|
570
|
+
};
|
|
571
|
+
var ALLOWED_HTML_TAGS = /* @__PURE__ */ new Set([
|
|
572
|
+
"a",
|
|
573
|
+
"abbr",
|
|
574
|
+
"b",
|
|
575
|
+
"blockquote",
|
|
576
|
+
"br",
|
|
577
|
+
"code",
|
|
578
|
+
"del",
|
|
579
|
+
"details",
|
|
580
|
+
"div",
|
|
581
|
+
"em",
|
|
582
|
+
"h1",
|
|
583
|
+
"h2",
|
|
584
|
+
"h3",
|
|
585
|
+
"h4",
|
|
586
|
+
"h5",
|
|
587
|
+
"h6",
|
|
588
|
+
"hr",
|
|
589
|
+
"i",
|
|
590
|
+
"img",
|
|
591
|
+
"input",
|
|
592
|
+
"kbd",
|
|
593
|
+
"li",
|
|
594
|
+
"mark",
|
|
595
|
+
"ol",
|
|
596
|
+
"p",
|
|
597
|
+
"pre",
|
|
598
|
+
"s",
|
|
599
|
+
"span",
|
|
600
|
+
"strong",
|
|
601
|
+
"sub",
|
|
602
|
+
"summary",
|
|
603
|
+
"sup",
|
|
604
|
+
"table",
|
|
605
|
+
"tbody",
|
|
606
|
+
"td",
|
|
607
|
+
"tfoot",
|
|
608
|
+
"th",
|
|
609
|
+
"thead",
|
|
610
|
+
"tr",
|
|
611
|
+
"u",
|
|
612
|
+
"ul"
|
|
613
|
+
]);
|
|
614
|
+
var ALLOWED_HTML_ATTRS = /* @__PURE__ */ new Set([
|
|
615
|
+
"alt",
|
|
616
|
+
"align",
|
|
617
|
+
"checked",
|
|
618
|
+
"class",
|
|
619
|
+
"colspan",
|
|
620
|
+
"disabled",
|
|
621
|
+
"height",
|
|
622
|
+
"href",
|
|
623
|
+
"rel",
|
|
624
|
+
"rowspan",
|
|
625
|
+
"src",
|
|
626
|
+
"start",
|
|
627
|
+
"target",
|
|
628
|
+
"title",
|
|
629
|
+
"type",
|
|
630
|
+
"width"
|
|
631
|
+
]);
|
|
632
|
+
var HTML_TAG_REGEX = /<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\s+[^\s"'>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*)\s*\/?>/g;
|
|
633
|
+
var HTML_ATTR_REGEX = /([^\s"'>\/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
|
|
634
|
+
function sanitizeTag(tagText, isClosing, rawTagName, rawAttrs, stripDisallowed) {
|
|
635
|
+
const tagName = rawTagName.toLowerCase();
|
|
636
|
+
const reject = () => stripDisallowed ? "" : escapeHtml(tagText);
|
|
637
|
+
if (!ALLOWED_HTML_TAGS.has(tagName)) return reject();
|
|
638
|
+
if (isClosing) return `</${tagName}>`;
|
|
639
|
+
if (tagName === "input" && !/\stype\s*=\s*["']?checkbox["']?[\s>/]/i.test(tagText)) {
|
|
640
|
+
return reject();
|
|
641
|
+
}
|
|
642
|
+
let attrs = "";
|
|
643
|
+
let attrMatch;
|
|
644
|
+
HTML_ATTR_REGEX.lastIndex = 0;
|
|
645
|
+
while ((attrMatch = HTML_ATTR_REGEX.exec(rawAttrs)) !== null) {
|
|
646
|
+
const name = attrMatch[1].toLowerCase();
|
|
647
|
+
if (!ALLOWED_HTML_ATTRS.has(name) && !/^data-[a-z0-9_.-]+$/.test(name)) {
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
const rawValue = _nullishCoalesce(_nullishCoalesce(attrMatch[2], () => ( attrMatch[3])), () => ( attrMatch[4]));
|
|
651
|
+
if (rawValue === void 0) {
|
|
652
|
+
attrs += ` ${name}`;
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
const value = md.utils.unescapeAll(rawValue);
|
|
656
|
+
if ((name === "href" || name === "src") && // Browsers ignore control characters and whitespace inside schemes.
|
|
657
|
+
!md.validateLink(value.replace(/[\u0000-\u0020\u007f]/g, ""))) {
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
attrs += ` ${name}="${escapeHtml(value)}"`;
|
|
661
|
+
}
|
|
662
|
+
return `<${tagName}${attrs}>`;
|
|
663
|
+
}
|
|
664
|
+
function sanitizeHtml(html, options = {}) {
|
|
665
|
+
return sanitizeEmbeddedHtml(html, options.disallowedTags === "strip");
|
|
666
|
+
}
|
|
667
|
+
function sanitizeEmbeddedHtml(html, stripDisallowed = false) {
|
|
668
|
+
let result = "";
|
|
669
|
+
let lastIndex = 0;
|
|
670
|
+
let match;
|
|
671
|
+
HTML_TAG_REGEX.lastIndex = 0;
|
|
672
|
+
while ((match = HTML_TAG_REGEX.exec(html)) !== null) {
|
|
673
|
+
result += html.slice(lastIndex, match.index).replace(/</g, "<");
|
|
674
|
+
result += sanitizeTag(match[0], match[1], match[2], match[3], stripDisallowed);
|
|
675
|
+
lastIndex = match.index + match[0].length;
|
|
676
|
+
}
|
|
677
|
+
return result + html.slice(lastIndex).replace(/</g, "<");
|
|
678
|
+
}
|
|
679
|
+
var defaultHtmlInline = md.renderer.rules.html_inline;
|
|
680
|
+
var defaultHtmlBlock = md.renderer.rules.html_block;
|
|
681
|
+
md.renderer.rules.html_inline = (tokens, idx, options, env, self) => _optionalChain([env, 'optionalAccess', _38 => _38.allowUnsafeHtml]) ? defaultHtmlInline(tokens, idx, options, env, self) : sanitizeEmbeddedHtml(tokens[idx].content);
|
|
682
|
+
md.renderer.rules.html_block = (tokens, idx, options, env, self) => _optionalChain([env, 'optionalAccess', _39 => _39.allowUnsafeHtml]) ? defaultHtmlBlock(tokens, idx, options, env, self) : sanitizeEmbeddedHtml(tokens[idx].content);
|
|
683
|
+
function preprocessMarkdownFileLinks(content) {
|
|
684
|
+
if (!content) return "";
|
|
685
|
+
return content.replace(
|
|
686
|
+
/\[([^\]]+)\]\(((?:file|vscode|cursor):\/\/[^)]+)\)/g,
|
|
687
|
+
(_match, rawLabel, href) => {
|
|
688
|
+
const trimmed = rawLabel.trim();
|
|
689
|
+
const codeMatch = trimmed.match(/^`([^`]+)`$/);
|
|
690
|
+
const labelContent = codeMatch ? `<code>${escapeHtml(codeMatch[1])}</code>` : escapeHtml(trimmed);
|
|
691
|
+
return `<a href="${escapeHtml(href)}" data-file-link="true" title="Click to copy file path">${labelContent}</a>`;
|
|
692
|
+
}
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
function markdownToTipTapHtml(markdown, options) {
|
|
696
|
+
if (!markdown) return "<p></p>";
|
|
697
|
+
let content = markdown;
|
|
698
|
+
if (_optionalChain([options, 'optionalAccess', _40 => _40.preprocessFileLinks])) {
|
|
699
|
+
content = preprocessMarkdownFileLinks(content);
|
|
700
|
+
}
|
|
701
|
+
if (_optionalChain([options, 'optionalAccess', _41 => _41.preprocessMentions]) || _optionalChain([options, 'optionalAccess', _42 => _42.mentionables]) || _optionalChain([options, 'optionalAccess', _43 => _43.preprocessOptions])) {
|
|
702
|
+
const mentionOpts = options.preprocessOptions || {
|
|
703
|
+
mentionables: options.mentionables
|
|
704
|
+
};
|
|
705
|
+
content = preprocessMarkdownMentions(content, mentionOpts);
|
|
706
|
+
}
|
|
707
|
+
return md.render(content, { allowUnsafeHtml: _optionalChain([options, 'optionalAccess', _44 => _44.allowUnsafeHtml]) });
|
|
708
|
+
}
|
|
709
|
+
function getEditorMarkdown(editor, options = {}) {
|
|
710
|
+
if (!editor) return "";
|
|
711
|
+
const markdown = _optionalChain([editor, 'access', _45 => _45.storage, 'optionalAccess', _46 => _46.markdown]);
|
|
712
|
+
if (typeof _optionalChain([markdown, 'optionalAccess', _47 => _47.getMarkdown]) === "function") {
|
|
713
|
+
const doc = _optionalChain([editor, 'access', _48 => _48.state, 'optionalAccess', _49 => _49.doc]);
|
|
714
|
+
if (doc && typeof _optionalChain([markdown, 'access', _50 => _50.serializer, 'optionalAccess', _51 => _51.serialize]) === "function") {
|
|
715
|
+
const resolved = _chunkX4N4WUKBcjs.resolveTrackedChanges.call(void 0, doc, _nullishCoalesce(options.trackedChanges, () => ( "accepted")));
|
|
716
|
+
if (resolved !== doc) return markdown.serializer.serialize(resolved);
|
|
717
|
+
}
|
|
718
|
+
return markdown.getMarkdown();
|
|
719
|
+
}
|
|
720
|
+
return getEditorText(editor, options);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
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.plainTextToSlice = plainTextToSlice; exports.htmlToPlainText = htmlToPlainText; exports.getEditorText = getEditorText; exports.extractMentionsFromDoc = extractMentionsFromDoc; exports.sanitizeHtml = sanitizeHtml; exports.preprocessMarkdownFileLinks = preprocessMarkdownFileLinks; exports.markdownToTipTapHtml = markdownToTipTapHtml; exports.getEditorMarkdown = getEditorMarkdown;
|
|
740
|
+
//# sourceMappingURL=chunk-7WISYZFO.cjs.map
|