@ant-design/agentic-ui 2.0.22 → 2.0.23
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/dist/Components/GradientText/index.d.ts +2 -1
- package/dist/Components/GradientText/index.js +3 -2
- package/dist/Components/GradientText/style.js +3 -8
- package/dist/Components/TextAnimate/index.d.ts +1 -0
- package/dist/Components/TextAnimate/index.js +27 -16
- package/dist/Components/TypingAnimation/index.d.ts +1 -1
- package/dist/Components/TypingAnimation/index.js +9 -9
- package/dist/MarkdownEditor/editor/components/LazyElement/index.js +36 -4
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.d.ts +4 -0
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +245 -344
- package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +74 -56
- package/dist/MarkdownEditor/editor/store.d.ts +36 -0
- package/dist/MarkdownEditor/editor/store.js +208 -76
- package/dist/Schema/SchemaRenderer/index.js +80 -55
- package/dist/Utils/proxySandbox/ProxySandbox.d.ts +32 -0
- package/dist/Utils/proxySandbox/ProxySandbox.js +176 -128
- package/dist/WelcomeMessage/index.d.ts +2 -2
- package/dist/WelcomeMessage/index.js +8 -5
- package/dist/WelcomeMessage/style.js +0 -1
- package/package.json +1 -1
|
@@ -33,6 +33,10 @@ import { htmlToFragmentList } from "../plugins/insertParsedHtmlNodes";
|
|
|
33
33
|
import { EditorUtils } from "../utils";
|
|
34
34
|
import partialJsonParse from "./json-parse";
|
|
35
35
|
import mdastParser from "./remarkParse";
|
|
36
|
+
var EMPTY_LINE_DISTANCE_THRESHOLD = 4;
|
|
37
|
+
var EMPTY_LINE_CALCULATION_OFFSET = 2;
|
|
38
|
+
var EMPTY_LINE_DIVISOR = 2;
|
|
39
|
+
var MIN_TABLE_CELL_LENGTH = 5;
|
|
36
40
|
var processSchemaLanguage = (element, value) => {
|
|
37
41
|
let json = [];
|
|
38
42
|
try {
|
|
@@ -131,83 +135,105 @@ var findAnswerElement = (str) => {
|
|
|
131
135
|
return null;
|
|
132
136
|
}
|
|
133
137
|
};
|
|
138
|
+
var extractMediaAttributes = (str) => {
|
|
139
|
+
var _a, _b, _c, _d, _e;
|
|
140
|
+
return {
|
|
141
|
+
height: (_a = str.match(/height="(\d+)"/)) == null ? void 0 : _a[1],
|
|
142
|
+
width: (_b = str.match(/width="(\d+)"/)) == null ? void 0 : _b[1],
|
|
143
|
+
align: (_c = str.match(/data-align="(\w+)"/)) == null ? void 0 : _c[1],
|
|
144
|
+
alt: (_d = str.match(/alt="([^"\n]+)"/)) == null ? void 0 : _d[1],
|
|
145
|
+
controls: str.match(/controls/),
|
|
146
|
+
autoplay: str.match(/autoplay/),
|
|
147
|
+
loop: str.match(/loop/),
|
|
148
|
+
muted: str.match(/muted/),
|
|
149
|
+
poster: (_e = str.match(/poster="([^"\n]+)"/)) == null ? void 0 : _e[1]
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
var buildMediaElement = (url, tagName, attrs) => {
|
|
153
|
+
return {
|
|
154
|
+
url,
|
|
155
|
+
height: attrs.height ? +attrs.height : void 0,
|
|
156
|
+
width: attrs.width ? +attrs.width : void 0,
|
|
157
|
+
align: attrs.align,
|
|
158
|
+
alt: attrs.alt,
|
|
159
|
+
tagName,
|
|
160
|
+
controls: !!attrs.controls,
|
|
161
|
+
autoplay: !!attrs.autoplay,
|
|
162
|
+
loop: !!attrs.loop,
|
|
163
|
+
muted: !!attrs.muted,
|
|
164
|
+
poster: attrs.poster
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
var extractVideoSource = (str, tagName) => {
|
|
168
|
+
let url = str.match(/src="([^"\n]+)"/);
|
|
169
|
+
if (tagName === "video" && !url) {
|
|
170
|
+
const sourceMatch = str.match(/<source[^>]*src="([^"\n]+)"[^>]*>/);
|
|
171
|
+
if (sourceMatch) {
|
|
172
|
+
url = sourceMatch;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return url == null ? void 0 : url[1];
|
|
176
|
+
};
|
|
134
177
|
var findImageElement = (str) => {
|
|
135
|
-
var _a
|
|
178
|
+
var _a;
|
|
136
179
|
try {
|
|
137
180
|
const videoWithSourceMatch = str.match(
|
|
138
181
|
/^\s*<video[^>\n]*>[\s\S]*?<source[^>]*src="([^"\n]+)"[^>]*>[\s\S]*?<\/video>\s*$/
|
|
139
182
|
);
|
|
140
183
|
if (videoWithSourceMatch) {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
const width = str.match(/width="(\d+)"/);
|
|
144
|
-
const align = str.match(/data-align="(\w+)"/);
|
|
145
|
-
const controls = str.match(/controls/);
|
|
146
|
-
const autoplay = str.match(/autoplay/);
|
|
147
|
-
const loop = str.match(/loop/);
|
|
148
|
-
const muted = str.match(/muted/);
|
|
149
|
-
const poster = str.match(/poster="([^"\n]+)"/);
|
|
150
|
-
return {
|
|
151
|
-
url: videoWithSourceMatch[1],
|
|
152
|
-
height: height ? +height[1] : void 0,
|
|
153
|
-
width: width ? +width[1] : void 0,
|
|
154
|
-
align: align == null ? void 0 : align[1],
|
|
155
|
-
alt: (_a = str.match(/alt="([^"\n]+)"/)) == null ? void 0 : _a[1],
|
|
156
|
-
tagName,
|
|
157
|
-
controls: !!controls,
|
|
158
|
-
autoplay: !!autoplay,
|
|
159
|
-
loop: !!loop,
|
|
160
|
-
muted: !!muted,
|
|
161
|
-
poster: poster == null ? void 0 : poster[1]
|
|
162
|
-
};
|
|
184
|
+
const attrs = extractMediaAttributes(str);
|
|
185
|
+
return buildMediaElement(videoWithSourceMatch[1], "video", attrs);
|
|
163
186
|
}
|
|
164
|
-
const
|
|
165
|
-
/^\s*<(img|video|iframe)[^>\n]
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
/^\s*<(img|video|iframe)[^>\n]
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
url = sourceMatch;
|
|
182
|
-
}
|
|
187
|
+
const patterns = [
|
|
188
|
+
/^\s*<(img|video|iframe)[^>\n]*>.*?<\/(?:img|video|iframe)>\s*$/,
|
|
189
|
+
// 完整标签对
|
|
190
|
+
/^\s*<(img|video|iframe)[^>\n]*\/?>(.*<\/(?:img|video|iframe)>)?\s*$/,
|
|
191
|
+
// 完整标签
|
|
192
|
+
/^\s*<(img|video|iframe)[^>\n]*\/>\s*$/,
|
|
193
|
+
// 自闭合标签
|
|
194
|
+
/^\s*<(img|video|iframe)[^>\n]*>\s*$/
|
|
195
|
+
// 仅开始标签
|
|
196
|
+
];
|
|
197
|
+
for (const pattern of patterns) {
|
|
198
|
+
const match = str.match(pattern);
|
|
199
|
+
if (match) {
|
|
200
|
+
const tagName = (_a = match[0].match(/<(img|video|iframe)/)) == null ? void 0 : _a[1];
|
|
201
|
+
const url = extractVideoSource(match[0], tagName);
|
|
202
|
+
const attrs = extractMediaAttributes(match[0]);
|
|
203
|
+
return buildMediaElement(url, tagName, attrs);
|
|
183
204
|
}
|
|
184
|
-
const height = fullMatch[0].match(/height="(\d+)"/);
|
|
185
|
-
const width = fullMatch[0].match(/width="(\d+)"/);
|
|
186
|
-
const align = fullMatch[0].match(/data-align="(\w+)"/);
|
|
187
|
-
const controls = fullMatch[0].match(/controls/);
|
|
188
|
-
const autoplay = fullMatch[0].match(/autoplay/);
|
|
189
|
-
const loop = fullMatch[0].match(/loop/);
|
|
190
|
-
const muted = fullMatch[0].match(/muted/);
|
|
191
|
-
const poster = fullMatch[0].match(/poster="([^"\n]+)"/);
|
|
192
|
-
return {
|
|
193
|
-
url: url == null ? void 0 : url[1],
|
|
194
|
-
height: height ? +height[1] : void 0,
|
|
195
|
-
width: width ? +width[1] : void 0,
|
|
196
|
-
align: align == null ? void 0 : align[1],
|
|
197
|
-
alt: (_c = fullMatch[0].match(/alt="([^"\n]+)"/)) == null ? void 0 : _c[1],
|
|
198
|
-
tagName,
|
|
199
|
-
controls: !!controls,
|
|
200
|
-
autoplay: !!autoplay,
|
|
201
|
-
loop: !!loop,
|
|
202
|
-
muted: !!muted,
|
|
203
|
-
poster: poster == null ? void 0 : poster[1]
|
|
204
|
-
};
|
|
205
205
|
}
|
|
206
206
|
return null;
|
|
207
207
|
} catch (e) {
|
|
208
|
+
console.error("Failed to parse media element:", e);
|
|
208
209
|
return null;
|
|
209
210
|
}
|
|
210
211
|
};
|
|
212
|
+
var createMediaNodeFromElement = (mediaElement) => {
|
|
213
|
+
if (!mediaElement)
|
|
214
|
+
return null;
|
|
215
|
+
const mediaTypeMap = {
|
|
216
|
+
video: "video",
|
|
217
|
+
iframe: "iframe",
|
|
218
|
+
img: "image"
|
|
219
|
+
};
|
|
220
|
+
const mediaType = mediaTypeMap[mediaElement.tagName] || "image";
|
|
221
|
+
return EditorUtils.createMediaNode(
|
|
222
|
+
decodeURIComponentUrl(mediaElement.url || ""),
|
|
223
|
+
mediaType,
|
|
224
|
+
{
|
|
225
|
+
align: mediaElement.align,
|
|
226
|
+
alt: mediaElement.alt,
|
|
227
|
+
height: mediaElement.height,
|
|
228
|
+
width: mediaElement.width,
|
|
229
|
+
controls: mediaElement.controls,
|
|
230
|
+
autoplay: mediaElement.autoplay,
|
|
231
|
+
loop: mediaElement.loop,
|
|
232
|
+
muted: mediaElement.muted,
|
|
233
|
+
poster: mediaElement.poster
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
};
|
|
211
237
|
var findAttachment = (str) => {
|
|
212
238
|
try {
|
|
213
239
|
const match = str.match(/^\s*<a[^>\n]*download[^>\n]*\/?>(.*<\/a>:?)?\s*$/);
|
|
@@ -345,11 +371,11 @@ var parseTableOrChart = (table, preNode, plugins) => {
|
|
|
345
371
|
children: ((_a2 = c.children) == null ? void 0 : _a2.length) ? [
|
|
346
372
|
{
|
|
347
373
|
type: "paragraph",
|
|
348
|
-
children:
|
|
374
|
+
children: parseNodes(
|
|
349
375
|
c.children,
|
|
376
|
+
plugins,
|
|
350
377
|
false,
|
|
351
|
-
c
|
|
352
|
-
plugins
|
|
378
|
+
c
|
|
353
379
|
)
|
|
354
380
|
}
|
|
355
381
|
] : [
|
|
@@ -384,7 +410,7 @@ var handleHeading = (currentElement, plugins) => {
|
|
|
384
410
|
return {
|
|
385
411
|
type: "head",
|
|
386
412
|
level: currentElement.depth,
|
|
387
|
-
children: ((_a = currentElement.children) == null ? void 0 : _a.length) ?
|
|
413
|
+
children: ((_a = currentElement.children) == null ? void 0 : _a.length) ? parseNodes(currentElement.children, plugins, false, currentElement) : [{ text: "" }]
|
|
388
414
|
};
|
|
389
415
|
};
|
|
390
416
|
var decodeURIComponentUrl = (url) => {
|
|
@@ -405,9 +431,13 @@ var handleHtml = (currentElement, parent, htmlTag) => {
|
|
|
405
431
|
} catch (e) {
|
|
406
432
|
try {
|
|
407
433
|
contextProps = partialJsonParse(value);
|
|
408
|
-
} catch (
|
|
434
|
+
} catch (parseError) {
|
|
435
|
+
console.warn("Failed to parse HTML comment as JSON or partial JSON:", {
|
|
436
|
+
value,
|
|
437
|
+
error: parseError
|
|
438
|
+
});
|
|
409
439
|
}
|
|
410
|
-
console.
|
|
440
|
+
console.warn("HTML comment parse fallback attempted:", e);
|
|
411
441
|
}
|
|
412
442
|
}
|
|
413
443
|
let el;
|
|
@@ -431,27 +461,7 @@ var handleHtml = (currentElement, parent, htmlTag) => {
|
|
|
431
461
|
} else {
|
|
432
462
|
const mediaElement = findImageElement(currentElement.value);
|
|
433
463
|
if (mediaElement) {
|
|
434
|
-
|
|
435
|
-
if (mediaElement.tagName === "video") {
|
|
436
|
-
mediaType = "video";
|
|
437
|
-
} else if (mediaElement.tagName === "iframe") {
|
|
438
|
-
mediaType = "iframe";
|
|
439
|
-
}
|
|
440
|
-
el = EditorUtils.createMediaNode(
|
|
441
|
-
decodeURIComponentUrl((mediaElement == null ? void 0 : mediaElement.url) || ""),
|
|
442
|
-
mediaType,
|
|
443
|
-
{
|
|
444
|
-
align: mediaElement.align,
|
|
445
|
-
alt: mediaElement.alt,
|
|
446
|
-
height: mediaElement == null ? void 0 : mediaElement.height,
|
|
447
|
-
width: mediaElement == null ? void 0 : mediaElement.width,
|
|
448
|
-
controls: mediaElement == null ? void 0 : mediaElement.controls,
|
|
449
|
-
autoplay: mediaElement == null ? void 0 : mediaElement.autoplay,
|
|
450
|
-
loop: mediaElement == null ? void 0 : mediaElement.loop,
|
|
451
|
-
muted: mediaElement == null ? void 0 : mediaElement.muted,
|
|
452
|
-
poster: mediaElement == null ? void 0 : mediaElement.poster
|
|
453
|
-
}
|
|
454
|
-
);
|
|
464
|
+
el = createMediaNodeFromElement(mediaElement);
|
|
455
465
|
} else if (currentElement.value === "<br/>") {
|
|
456
466
|
el = { type: "paragraph", children: [{ text: "" }] };
|
|
457
467
|
} else if (currentElement.value.match(/^<\/(img|video|iframe)>/)) {
|
|
@@ -516,27 +526,7 @@ var processInlineHtml = (currentElement, htmlTag) => {
|
|
|
516
526
|
} else {
|
|
517
527
|
const mediaElement = findImageElement(currentElement.value);
|
|
518
528
|
if (mediaElement) {
|
|
519
|
-
|
|
520
|
-
if (mediaElement.tagName === "video") {
|
|
521
|
-
mediaType = "video";
|
|
522
|
-
} else if (mediaElement.tagName === "iframe") {
|
|
523
|
-
mediaType = "iframe";
|
|
524
|
-
}
|
|
525
|
-
return EditorUtils.createMediaNode(
|
|
526
|
-
decodeURIComponentUrl((mediaElement == null ? void 0 : mediaElement.url) || ""),
|
|
527
|
-
mediaType,
|
|
528
|
-
{
|
|
529
|
-
align: mediaElement.align,
|
|
530
|
-
alt: mediaElement.alt,
|
|
531
|
-
height: mediaElement == null ? void 0 : mediaElement.height,
|
|
532
|
-
width: mediaElement == null ? void 0 : mediaElement.width,
|
|
533
|
-
controls: mediaElement == null ? void 0 : mediaElement.controls,
|
|
534
|
-
autoplay: mediaElement == null ? void 0 : mediaElement.autoplay,
|
|
535
|
-
loop: mediaElement == null ? void 0 : mediaElement.loop,
|
|
536
|
-
muted: mediaElement == null ? void 0 : mediaElement.muted,
|
|
537
|
-
poster: mediaElement == null ? void 0 : mediaElement.poster
|
|
538
|
-
}
|
|
539
|
-
);
|
|
529
|
+
return createMediaNodeFromElement(mediaElement);
|
|
540
530
|
} else {
|
|
541
531
|
return { text: currentElement.value };
|
|
542
532
|
}
|
|
@@ -560,6 +550,7 @@ var processHtmlTag = (str, tag, htmlTag) => {
|
|
|
560
550
|
}
|
|
561
551
|
}
|
|
562
552
|
} catch (e) {
|
|
553
|
+
console.warn("Failed to parse span style attribute:", { str, error: e });
|
|
563
554
|
}
|
|
564
555
|
} else if (tag === "a") {
|
|
565
556
|
const url = str.match(/href="([\w:./_\-#\\]+)"/);
|
|
@@ -614,11 +605,11 @@ var handleList = (currentElement, plugins) => {
|
|
|
614
605
|
type: "list",
|
|
615
606
|
order: currentElement.ordered,
|
|
616
607
|
start: currentElement.start,
|
|
617
|
-
children:
|
|
608
|
+
children: parseNodes(
|
|
618
609
|
currentElement.children,
|
|
610
|
+
plugins,
|
|
619
611
|
false,
|
|
620
|
-
currentElement
|
|
621
|
-
plugins
|
|
612
|
+
currentElement
|
|
622
613
|
)
|
|
623
614
|
};
|
|
624
615
|
el.task = (_a = el.children) == null ? void 0 : _a.some((s) => typeof s.checked === "boolean");
|
|
@@ -634,11 +625,11 @@ var handleFootnoteReference = (currentElement) => {
|
|
|
634
625
|
};
|
|
635
626
|
var handleFootnoteDefinition = (currentElement, plugins) => {
|
|
636
627
|
var _a, _b;
|
|
637
|
-
const linkNode = (_a =
|
|
628
|
+
const linkNode = (_a = parseNodes(
|
|
638
629
|
currentElement.children,
|
|
630
|
+
plugins,
|
|
639
631
|
false,
|
|
640
|
-
currentElement
|
|
641
|
-
plugins
|
|
632
|
+
currentElement
|
|
642
633
|
)) == null ? void 0 : _a.at(0);
|
|
643
634
|
const cellNode = (_b = linkNode == null ? void 0 : linkNode.children) == null ? void 0 : _b.at(0);
|
|
644
635
|
return {
|
|
@@ -651,7 +642,7 @@ var handleFootnoteDefinition = (currentElement, plugins) => {
|
|
|
651
642
|
};
|
|
652
643
|
var handleListItem = (currentElement, plugins) => {
|
|
653
644
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
654
|
-
const children = ((_a = currentElement.children) == null ? void 0 : _a.length) ?
|
|
645
|
+
const children = ((_a = currentElement.children) == null ? void 0 : _a.length) ? parseNodes(currentElement.children, plugins, false, currentElement) : [{ type: "paragraph", children: [{ text: "" }] }];
|
|
655
646
|
let mentions = void 0;
|
|
656
647
|
if (((_e = (_d = (_c = (_b = currentElement.children) == null ? void 0 : _b[0]) == null ? void 0 : _c.children) == null ? void 0 : _d[0]) == null ? void 0 : _e.type) === "link" && ((_h = (_g = (_f = currentElement.children) == null ? void 0 : _f[0]) == null ? void 0 : _g.children) == null ? void 0 : _h.length) > 1) {
|
|
657
648
|
const item = (_j = (_i = children == null ? void 0 : children[0]) == null ? void 0 : _i.children) == null ? void 0 : _j[0];
|
|
@@ -690,49 +681,49 @@ var handleListItem = (currentElement, plugins) => {
|
|
|
690
681
|
mentions
|
|
691
682
|
};
|
|
692
683
|
};
|
|
693
|
-
var
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
684
|
+
var handleAttachmentLink = (currentElement) => {
|
|
685
|
+
const text = currentElement.children.map((n) => n.value || "").join("");
|
|
686
|
+
const attach = findAttachment(text);
|
|
687
|
+
if (!attach)
|
|
688
|
+
return null;
|
|
689
|
+
const name = text.match(/>(.*)<\/a>/);
|
|
690
|
+
return {
|
|
691
|
+
type: "attach",
|
|
692
|
+
url: decodeURIComponentUrl(attach == null ? void 0 : attach.url),
|
|
693
|
+
size: attach.size,
|
|
694
|
+
children: [
|
|
695
|
+
{
|
|
696
|
+
type: "card-before",
|
|
697
|
+
children: [{ text: "" }]
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
type: "card-after",
|
|
701
|
+
children: [{ text: "" }]
|
|
702
|
+
}
|
|
703
|
+
],
|
|
704
|
+
name: name ? name[1] : attach == null ? void 0 : attach.url
|
|
705
|
+
};
|
|
706
|
+
};
|
|
707
|
+
var handleLinkCard = (currentElement, config) => {
|
|
708
|
+
var _a;
|
|
709
|
+
const link = (_a = currentElement == null ? void 0 : currentElement.children) == null ? void 0 : _a.at(0);
|
|
710
|
+
return __spreadProps(__spreadValues({}, config), {
|
|
711
|
+
type: "link-card",
|
|
712
|
+
url: decodeURIComponentUrl(link == null ? void 0 : link.url),
|
|
713
|
+
children: [
|
|
714
|
+
{
|
|
715
|
+
type: "card-before",
|
|
716
|
+
children: [{ text: "" }]
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
type: "card-after",
|
|
720
|
+
children: [{ text: "" }]
|
|
721
|
+
}
|
|
722
|
+
],
|
|
723
|
+
name: link.title
|
|
724
|
+
});
|
|
725
|
+
};
|
|
726
|
+
var processParagraphChildren = (currentElement, plugins) => {
|
|
736
727
|
const elements = [];
|
|
737
728
|
let textNodes = [];
|
|
738
729
|
for (let currentChild of currentElement.children || []) {
|
|
@@ -740,7 +731,7 @@ var handleParagraph = (currentElement, config, plugins) => {
|
|
|
740
731
|
if (textNodes.length) {
|
|
741
732
|
elements.push({
|
|
742
733
|
type: "paragraph",
|
|
743
|
-
children:
|
|
734
|
+
children: parseNodes(textNodes, plugins, false, currentElement)
|
|
744
735
|
});
|
|
745
736
|
textNodes = [];
|
|
746
737
|
}
|
|
@@ -759,28 +750,10 @@ var handleParagraph = (currentElement, config, plugins) => {
|
|
|
759
750
|
}
|
|
760
751
|
const mediaElement = findImageElement(currentChild.value);
|
|
761
752
|
if (mediaElement) {
|
|
762
|
-
|
|
763
|
-
if (
|
|
764
|
-
|
|
765
|
-
} else if (mediaElement.tagName === "iframe") {
|
|
766
|
-
mediaType = "iframe";
|
|
753
|
+
const node = createMediaNodeFromElement(mediaElement);
|
|
754
|
+
if (node) {
|
|
755
|
+
elements.push(node);
|
|
767
756
|
}
|
|
768
|
-
elements.push(
|
|
769
|
-
EditorUtils.createMediaNode(
|
|
770
|
-
decodeURIComponentUrl((mediaElement == null ? void 0 : mediaElement.url) || ""),
|
|
771
|
-
mediaType,
|
|
772
|
-
{
|
|
773
|
-
alt: mediaElement.alt,
|
|
774
|
-
height: mediaElement == null ? void 0 : mediaElement.height,
|
|
775
|
-
width: mediaElement == null ? void 0 : mediaElement.width,
|
|
776
|
-
controls: mediaElement == null ? void 0 : mediaElement.controls,
|
|
777
|
-
autoplay: mediaElement == null ? void 0 : mediaElement.autoplay,
|
|
778
|
-
loop: mediaElement == null ? void 0 : mediaElement.loop,
|
|
779
|
-
muted: mediaElement == null ? void 0 : mediaElement.muted,
|
|
780
|
-
poster: mediaElement == null ? void 0 : mediaElement.poster
|
|
781
|
-
}
|
|
782
|
-
)
|
|
783
|
-
);
|
|
784
757
|
} else {
|
|
785
758
|
textNodes.push({ type: "html", value: currentChild.value });
|
|
786
759
|
}
|
|
@@ -791,11 +764,23 @@ var handleParagraph = (currentElement, config, plugins) => {
|
|
|
791
764
|
if (textNodes.length) {
|
|
792
765
|
elements.push({
|
|
793
766
|
type: "paragraph",
|
|
794
|
-
children:
|
|
767
|
+
children: parseNodes(textNodes, plugins, false, currentElement)
|
|
795
768
|
});
|
|
796
769
|
}
|
|
797
770
|
return elements;
|
|
798
771
|
};
|
|
772
|
+
var handleParagraph = (currentElement, config, plugins) => {
|
|
773
|
+
var _a, _b, _c;
|
|
774
|
+
if (((_a = currentElement.children) == null ? void 0 : _a[0].type) === "html" && currentElement.children[0].value.startsWith("<a")) {
|
|
775
|
+
const attachNode = handleAttachmentLink(currentElement);
|
|
776
|
+
if (attachNode)
|
|
777
|
+
return attachNode;
|
|
778
|
+
}
|
|
779
|
+
if (((_c = (_b = currentElement == null ? void 0 : currentElement.children) == null ? void 0 : _b.at(0)) == null ? void 0 : _c.type) === "link" && config.type === "card") {
|
|
780
|
+
return handleLinkCard(currentElement, config);
|
|
781
|
+
}
|
|
782
|
+
return processParagraphChildren(currentElement, plugins);
|
|
783
|
+
};
|
|
799
784
|
var handleInlineCode = (currentElement) => {
|
|
800
785
|
var _a, _b;
|
|
801
786
|
const hasPlaceHolder = (_a = currentElement.value) == null ? void 0 : _a.match(/\$\{(.*?)\}/);
|
|
@@ -844,7 +829,7 @@ var handleBlockquote = (currentElement, plugins) => {
|
|
|
844
829
|
var _a;
|
|
845
830
|
return {
|
|
846
831
|
type: "blockquote",
|
|
847
|
-
children: ((_a = currentElement.children) == null ? void 0 : _a.length) ?
|
|
832
|
+
children: ((_a = currentElement.children) == null ? void 0 : _a.length) ? parseNodes(currentElement.children, plugins, false, currentElement) : [{ type: "paragraph", children: [{ text: "" }] }]
|
|
848
833
|
};
|
|
849
834
|
};
|
|
850
835
|
var handleDefinition = (currentElement) => {
|
|
@@ -876,11 +861,11 @@ var handleTextAndInlineElements = (currentElement, htmlTag, plugins) => {
|
|
|
876
861
|
applyInlineFormatting(leaf, currentElement);
|
|
877
862
|
applyHtmlTagsToElement(leaf, htmlTag);
|
|
878
863
|
if ((_a = currentElement == null ? void 0 : currentElement.children) == null ? void 0 : _a.some((n) => n.type === "html")) {
|
|
879
|
-
return __spreadProps(__spreadValues({}, (_b =
|
|
864
|
+
return __spreadProps(__spreadValues({}, (_b = parseNodes(
|
|
880
865
|
currentElement == null ? void 0 : currentElement.children,
|
|
866
|
+
plugins,
|
|
881
867
|
false,
|
|
882
|
-
currentElement
|
|
883
|
-
plugins
|
|
868
|
+
currentElement
|
|
884
869
|
)) == null ? void 0 : _b.at(0)), {
|
|
885
870
|
url: leaf.url
|
|
886
871
|
});
|
|
@@ -960,101 +945,68 @@ var addEmptyLinesIfNeeded = (els, preNode, currentElement, top) => {
|
|
|
960
945
|
var _a, _b;
|
|
961
946
|
if (preNode && top) {
|
|
962
947
|
const distance = (((_a = currentElement.position) == null ? void 0 : _a.start.line) || 0) - (((_b = preNode.position) == null ? void 0 : _b.end.line) || 0);
|
|
963
|
-
if (distance >=
|
|
964
|
-
const lines = Math.floor(
|
|
948
|
+
if (distance >= EMPTY_LINE_DISTANCE_THRESHOLD) {
|
|
949
|
+
const lines = Math.floor(
|
|
950
|
+
(distance - EMPTY_LINE_CALCULATION_OFFSET) / EMPTY_LINE_DIVISOR
|
|
951
|
+
);
|
|
965
952
|
Array.from(new Array(lines)).forEach(() => {
|
|
966
953
|
els.push({ type: "paragraph", children: [{ text: "" }] });
|
|
967
954
|
});
|
|
968
955
|
}
|
|
969
956
|
}
|
|
970
957
|
};
|
|
971
|
-
var
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
break;
|
|
1006
|
-
case "footnoteReference":
|
|
1007
|
-
el = handleFootnoteReference(currentElement);
|
|
1008
|
-
break;
|
|
1009
|
-
case "footnoteDefinition":
|
|
1010
|
-
el = handleFootnoteDefinition(currentElement, plugins || []);
|
|
1011
|
-
break;
|
|
1012
|
-
case "listItem":
|
|
1013
|
-
el = handleListItem(currentElement, plugins || []);
|
|
1014
|
-
break;
|
|
1015
|
-
case "paragraph":
|
|
1016
|
-
el = handleParagraph(currentElement, config, plugins || []);
|
|
1017
|
-
break;
|
|
1018
|
-
case "inlineCode":
|
|
1019
|
-
el = handleInlineCode(currentElement);
|
|
1020
|
-
break;
|
|
1021
|
-
case "thematicBreak":
|
|
1022
|
-
el = handleThematicBreak();
|
|
1023
|
-
break;
|
|
1024
|
-
case "code":
|
|
1025
|
-
el = handleCode(currentElement);
|
|
1026
|
-
break;
|
|
1027
|
-
case "yaml":
|
|
1028
|
-
el = handleYaml(currentElement);
|
|
1029
|
-
break;
|
|
1030
|
-
case "blockquote":
|
|
1031
|
-
el = handleBlockquote(currentElement, plugins || []);
|
|
1032
|
-
break;
|
|
1033
|
-
case "table":
|
|
1034
|
-
el = parseTableOrChart(currentElement, preElement, plugins || []);
|
|
1035
|
-
break;
|
|
1036
|
-
case "definition":
|
|
1037
|
-
el = handleDefinition(currentElement);
|
|
1038
|
-
break;
|
|
1039
|
-
default:
|
|
1040
|
-
el = handleTextAndInlineElements(
|
|
1041
|
-
currentElement,
|
|
1042
|
-
htmlTag,
|
|
1043
|
-
plugins || []
|
|
1044
|
-
);
|
|
1045
|
-
}
|
|
1046
|
-
addEmptyLinesIfNeeded(els, preNode, currentElement, top);
|
|
1047
|
-
if (el) {
|
|
1048
|
-
el = applyContextPropsAndConfig(el, contextProps, config);
|
|
1049
|
-
Array.isArray(el) ? els.push(...el) : els.push(el);
|
|
1050
|
-
}
|
|
1051
|
-
preNode = currentElement;
|
|
1052
|
-
preElement = el;
|
|
1053
|
-
el = null;
|
|
958
|
+
var elementHandlers = {
|
|
959
|
+
heading: { handler: (el, plugins) => handleHeading(el, plugins) },
|
|
960
|
+
html: { handler: () => null, needsHtmlResult: true },
|
|
961
|
+
image: { handler: (el) => handleImage(el) },
|
|
962
|
+
inlineMath: { handler: (el) => handleInlineMath(el) },
|
|
963
|
+
math: { handler: (el) => handleMath(el) },
|
|
964
|
+
list: { handler: (el, plugins) => handleList(el, plugins) },
|
|
965
|
+
footnoteReference: { handler: (el) => handleFootnoteReference(el) },
|
|
966
|
+
footnoteDefinition: {
|
|
967
|
+
handler: (el, plugins) => handleFootnoteDefinition(el, plugins)
|
|
968
|
+
},
|
|
969
|
+
listItem: { handler: (el, plugins) => handleListItem(el, plugins) },
|
|
970
|
+
paragraph: {
|
|
971
|
+
handler: (el, plugins, config) => handleParagraph(el, config, plugins)
|
|
972
|
+
},
|
|
973
|
+
inlineCode: { handler: (el) => handleInlineCode(el) },
|
|
974
|
+
thematicBreak: { handler: () => handleThematicBreak() },
|
|
975
|
+
code: { handler: (el) => handleCode(el) },
|
|
976
|
+
yaml: { handler: (el) => handleYaml(el) },
|
|
977
|
+
blockquote: { handler: (el, plugins) => handleBlockquote(el, plugins) },
|
|
978
|
+
table: {
|
|
979
|
+
handler: (el, plugins, config, parent, htmlTag, preElement) => parseTableOrChart(el, preElement, plugins)
|
|
980
|
+
},
|
|
981
|
+
definition: { handler: (el) => handleDefinition(el) }
|
|
982
|
+
};
|
|
983
|
+
var handleSingleElement = (currentElement, config, plugins, parent, htmlTag, preElement) => {
|
|
984
|
+
const elementType = currentElement.type;
|
|
985
|
+
const handlerInfo = elementHandlers[elementType];
|
|
986
|
+
if (handlerInfo == null ? void 0 : handlerInfo.needsHtmlResult) {
|
|
987
|
+
const htmlResult = handleHtml(currentElement, parent, htmlTag);
|
|
988
|
+
return {
|
|
989
|
+
el: htmlResult.el,
|
|
990
|
+
contextProps: htmlResult.contextProps
|
|
991
|
+
};
|
|
1054
992
|
}
|
|
1055
|
-
|
|
993
|
+
if (handlerInfo) {
|
|
994
|
+
return {
|
|
995
|
+
el: handlerInfo.handler(
|
|
996
|
+
currentElement,
|
|
997
|
+
plugins || [],
|
|
998
|
+
config,
|
|
999
|
+
parent,
|
|
1000
|
+
htmlTag,
|
|
1001
|
+
preElement
|
|
1002
|
+
)
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
return {
|
|
1006
|
+
el: handleTextAndInlineElements(currentElement, htmlTag, plugins || [])
|
|
1007
|
+
};
|
|
1056
1008
|
};
|
|
1057
|
-
var
|
|
1009
|
+
var parseNodes = (nodes, plugins, top = false, parent) => {
|
|
1058
1010
|
var _a;
|
|
1059
1011
|
if (!(nodes == null ? void 0 : nodes.length))
|
|
1060
1012
|
return [{ type: "paragraph", children: [{ text: "" }] }];
|
|
@@ -1067,6 +1019,7 @@ var parseWithPlugins = (nodes, plugins, top = false, parent) => {
|
|
|
1067
1019
|
const currentElement = nodes[i];
|
|
1068
1020
|
let el = null;
|
|
1069
1021
|
let pluginHandled = false;
|
|
1022
|
+
const config = (preElement == null ? void 0 : preElement.type) === "code" && (preElement == null ? void 0 : preElement.language) === "html" && (preElement == null ? void 0 : preElement.otherProps) ? preElement == null ? void 0 : preElement.otherProps : {};
|
|
1070
1023
|
for (const plugin of plugins) {
|
|
1071
1024
|
const rule = (_a = plugin.parseMarkdown) == null ? void 0 : _a.find((r) => r.match(currentElement));
|
|
1072
1025
|
if (rule) {
|
|
@@ -1081,74 +1034,22 @@ var parseWithPlugins = (nodes, plugins, top = false, parent) => {
|
|
|
1081
1034
|
}
|
|
1082
1035
|
}
|
|
1083
1036
|
if (!pluginHandled) {
|
|
1084
|
-
const
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
break;
|
|
1096
|
-
case "image":
|
|
1097
|
-
el = handleImage(currentElement);
|
|
1098
|
-
break;
|
|
1099
|
-
case "inlineMath":
|
|
1100
|
-
el = handleInlineMath(currentElement);
|
|
1101
|
-
break;
|
|
1102
|
-
case "math":
|
|
1103
|
-
el = handleMath(currentElement);
|
|
1104
|
-
break;
|
|
1105
|
-
case "list":
|
|
1106
|
-
el = handleList(currentElement, plugins || []);
|
|
1107
|
-
break;
|
|
1108
|
-
case "footnoteReference":
|
|
1109
|
-
el = handleFootnoteReference(currentElement);
|
|
1110
|
-
break;
|
|
1111
|
-
case "footnoteDefinition":
|
|
1112
|
-
el = handleFootnoteDefinition(currentElement, plugins || []);
|
|
1113
|
-
break;
|
|
1114
|
-
case "listItem":
|
|
1115
|
-
el = handleListItem(currentElement, plugins || []);
|
|
1116
|
-
break;
|
|
1117
|
-
case "paragraph":
|
|
1118
|
-
el = handleParagraph(currentElement, config, plugins);
|
|
1119
|
-
break;
|
|
1120
|
-
case "inlineCode":
|
|
1121
|
-
el = handleInlineCode(currentElement);
|
|
1122
|
-
break;
|
|
1123
|
-
case "thematicBreak":
|
|
1124
|
-
el = handleThematicBreak();
|
|
1125
|
-
break;
|
|
1126
|
-
case "code":
|
|
1127
|
-
el = handleCode(currentElement);
|
|
1128
|
-
break;
|
|
1129
|
-
case "yaml":
|
|
1130
|
-
el = handleYaml(currentElement);
|
|
1131
|
-
break;
|
|
1132
|
-
case "blockquote":
|
|
1133
|
-
el = handleBlockquote(currentElement, plugins || []);
|
|
1134
|
-
break;
|
|
1135
|
-
case "table":
|
|
1136
|
-
el = parseTableOrChart(currentElement, preElement, plugins || []);
|
|
1137
|
-
break;
|
|
1138
|
-
case "definition":
|
|
1139
|
-
el = handleDefinition(currentElement);
|
|
1140
|
-
break;
|
|
1141
|
-
default:
|
|
1142
|
-
el = handleTextAndInlineElements(
|
|
1143
|
-
currentElement,
|
|
1144
|
-
htmlTag,
|
|
1145
|
-
plugins || []
|
|
1146
|
-
);
|
|
1037
|
+
const result = handleSingleElement(
|
|
1038
|
+
currentElement,
|
|
1039
|
+
config,
|
|
1040
|
+
plugins,
|
|
1041
|
+
parent,
|
|
1042
|
+
htmlTag,
|
|
1043
|
+
preElement
|
|
1044
|
+
);
|
|
1045
|
+
el = result.el;
|
|
1046
|
+
if (result.contextProps) {
|
|
1047
|
+
contextProps = __spreadValues(__spreadValues({}, contextProps), result.contextProps);
|
|
1147
1048
|
}
|
|
1148
1049
|
}
|
|
1149
1050
|
addEmptyLinesIfNeeded(els, preNode, currentElement, top);
|
|
1150
1051
|
if (el) {
|
|
1151
|
-
el = applyContextPropsAndConfig(el, contextProps,
|
|
1052
|
+
el = applyContextPropsAndConfig(el, contextProps, config);
|
|
1152
1053
|
Array.isArray(el) ? els.push(...el) : els.push(el);
|
|
1153
1054
|
}
|
|
1154
1055
|
preNode = currentElement;
|
|
@@ -1326,25 +1227,25 @@ function preprocessMarkdownTableNewlines(markdown) {
|
|
|
1326
1227
|
return line;
|
|
1327
1228
|
return line.replace(/\|([^|]+)\|/g, (match) => {
|
|
1328
1229
|
var _a;
|
|
1329
|
-
if (((_a = match.replaceAll("\n", "")) == null ? void 0 : _a.length) <
|
|
1230
|
+
if (((_a = match.replaceAll("\n", "")) == null ? void 0 : _a.length) < MIN_TABLE_CELL_LENGTH)
|
|
1330
1231
|
return match;
|
|
1331
1232
|
return match.split("\n").join("<br>");
|
|
1332
1233
|
});
|
|
1333
1234
|
}).join("\n\n");
|
|
1334
1235
|
}
|
|
1335
1236
|
var parserMarkdownToSlateNode = (md, plugins) => {
|
|
1336
|
-
var _a;
|
|
1337
1237
|
const thinkProcessed = preprocessThinkTags(md || "");
|
|
1338
1238
|
const nonStandardProcessed = preprocessNonStandardHtmlTags(thinkProcessed);
|
|
1339
1239
|
const processedMarkdown = mdastParser.parse(
|
|
1340
1240
|
preprocessMarkdownTableNewlines(nonStandardProcessed)
|
|
1341
1241
|
);
|
|
1342
1242
|
const markdownRoot = processedMarkdown.children;
|
|
1343
|
-
const
|
|
1243
|
+
const pluginList = plugins || [];
|
|
1244
|
+
const schema = parseNodes(markdownRoot, pluginList, true);
|
|
1344
1245
|
return {
|
|
1345
1246
|
schema: schema == null ? void 0 : schema.filter((item) => {
|
|
1346
|
-
var
|
|
1347
|
-
if (item.type === "paragraph" && ((
|
|
1247
|
+
var _a;
|
|
1248
|
+
if (item.type === "paragraph" && ((_a = item.children) == null ? void 0 : _a.length) === 1) {
|
|
1348
1249
|
if (item.children[0].text === "\n") {
|
|
1349
1250
|
return false;
|
|
1350
1251
|
}
|