md-editor-v3 5.2.1 → 5.2.2
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/lib/es/MdEditor.mjs
CHANGED
|
@@ -1411,268 +1411,260 @@ const useAutoScroll = (props2, html, codeMirrorUt) => {
|
|
|
1411
1411
|
onMounted(rebindEvent);
|
|
1412
1412
|
};
|
|
1413
1413
|
const directive2flag = async (direct, codeMirrorUt, params) => {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
let deviationStart = 0;
|
|
1417
|
-
let deviationEnd = 0;
|
|
1418
|
-
let select = true;
|
|
1419
|
-
let replaceAll = false;
|
|
1420
|
-
const selectedText = codeMirrorUt.getSelectedText();
|
|
1421
|
-
const mermaidTemplate = configOption.editorConfig.mermaidTemplate;
|
|
1422
|
-
if (/^h[1-6]{1}$/.test(direct)) {
|
|
1423
|
-
const pix = direct.replace(/^h(\d)/, (_, num) => {
|
|
1424
|
-
return new Array(Number(num)).fill("#", 0, num).join("");
|
|
1425
|
-
});
|
|
1426
|
-
targetValue = `${pix} ${selectedText}`;
|
|
1427
|
-
deviationStart = pix.length + 1;
|
|
1414
|
+
if (/^h[1-6]$/.test(direct)) {
|
|
1415
|
+
return handleHeading(direct, codeMirrorUt);
|
|
1428
1416
|
} else if (direct === "prettier") {
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1417
|
+
return await handlePrettier(codeMirrorUt, params);
|
|
1418
|
+
}
|
|
1419
|
+
switch (direct) {
|
|
1420
|
+
case "bold":
|
|
1421
|
+
case "underline":
|
|
1422
|
+
case "italic":
|
|
1423
|
+
case "strikeThrough":
|
|
1424
|
+
case "sub":
|
|
1425
|
+
case "sup":
|
|
1426
|
+
case "codeRow":
|
|
1427
|
+
case "katexInline":
|
|
1428
|
+
case "katexBlock": {
|
|
1429
|
+
return wrapText(direct, codeMirrorUt);
|
|
1430
|
+
}
|
|
1431
|
+
case "quote":
|
|
1432
|
+
case "orderedList":
|
|
1433
|
+
case "unorderedList":
|
|
1434
|
+
case "task": {
|
|
1435
|
+
return handleMultiLine(direct, codeMirrorUt);
|
|
1436
|
+
}
|
|
1437
|
+
case "code": {
|
|
1438
|
+
return handleCodeBlock(params, codeMirrorUt);
|
|
1439
|
+
}
|
|
1440
|
+
case "table": {
|
|
1441
|
+
return handleTable(params);
|
|
1442
|
+
}
|
|
1443
|
+
case "link": {
|
|
1444
|
+
return { text: `[${params.desc}](${params.url})`, options: { select: false } };
|
|
1445
|
+
}
|
|
1446
|
+
case "image": {
|
|
1447
|
+
return handleImage(params);
|
|
1448
|
+
}
|
|
1449
|
+
case "flow":
|
|
1450
|
+
case "sequence":
|
|
1451
|
+
case "gantt":
|
|
1452
|
+
case "class":
|
|
1453
|
+
case "state":
|
|
1454
|
+
case "pie":
|
|
1455
|
+
case "relationship":
|
|
1456
|
+
case "journey": {
|
|
1457
|
+
return handleMermaid(direct);
|
|
1458
|
+
}
|
|
1459
|
+
case "universal": {
|
|
1460
|
+
return handleUniversal(codeMirrorUt.getSelectedText(), params);
|
|
1461
|
+
}
|
|
1462
|
+
default: {
|
|
1463
|
+
return { text: "", options: {} };
|
|
1444
1464
|
}
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
for (let col = 0; col <= y; col++) {
|
|
1536
|
-
targetValue += " content |";
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
deviationStart = 2;
|
|
1540
|
-
deviationEnd = 5 - targetValue.length;
|
|
1541
|
-
break;
|
|
1542
|
-
}
|
|
1543
|
-
case "link": {
|
|
1544
|
-
const { desc, url } = params;
|
|
1545
|
-
targetValue = `[${desc}](${url})`;
|
|
1546
|
-
select = false;
|
|
1547
|
-
break;
|
|
1548
|
-
}
|
|
1549
|
-
case "image": {
|
|
1550
|
-
const { desc, url, urls } = params;
|
|
1551
|
-
if (urls instanceof Array) {
|
|
1552
|
-
targetValue = urls.reduce((pVal, _url) => {
|
|
1553
|
-
const {
|
|
1554
|
-
url: url2 = "",
|
|
1555
|
-
alt = "",
|
|
1556
|
-
title = ""
|
|
1557
|
-
} = typeof _url === "object" ? _url : { url: _url };
|
|
1558
|
-
return pVal + `
|
|
1559
|
-
`;
|
|
1560
|
-
}, "");
|
|
1561
|
-
} else {
|
|
1562
|
-
targetValue = `
|
|
1563
|
-
`;
|
|
1564
|
-
}
|
|
1565
|
-
select = false;
|
|
1566
|
-
break;
|
|
1567
|
-
}
|
|
1568
|
-
case "flow": {
|
|
1569
|
-
targetValue = `\`\`\`mermaid
|
|
1570
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.flow) || "flowchart TD \n Start --> Stop"}
|
|
1571
|
-
\`\`\`
|
|
1572
|
-
`;
|
|
1573
|
-
deviationStart = 11;
|
|
1574
|
-
deviationEnd = -5;
|
|
1575
|
-
break;
|
|
1576
|
-
}
|
|
1577
|
-
case "sequence": {
|
|
1578
|
-
targetValue = `\`\`\`mermaid
|
|
1579
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.sequence) || "sequenceDiagram\n A->>B: hello!\n B-->>A: hi!\n A-)B: bye!"}
|
|
1580
|
-
\`\`\`
|
|
1581
|
-
`;
|
|
1582
|
-
deviationStart = 11;
|
|
1583
|
-
deviationEnd = -5;
|
|
1584
|
-
break;
|
|
1585
|
-
}
|
|
1586
|
-
case "gantt": {
|
|
1587
|
-
targetValue = `\`\`\`mermaid
|
|
1588
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.gantt) || "gantt\ntitle A Gantt Diagram\ndateFormat YYYY-MM-DD\nsection Section\nA task :a1, 2014-01-01, 30d\nAnother task :after a1, 20d"}
|
|
1589
|
-
\`\`\`
|
|
1590
|
-
`;
|
|
1591
|
-
deviationStart = 11;
|
|
1592
|
-
deviationEnd = -5;
|
|
1593
|
-
break;
|
|
1594
|
-
}
|
|
1595
|
-
case "class": {
|
|
1596
|
-
targetValue = `\`\`\`mermaid
|
|
1597
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.class) || "classDiagram\n class Animal\n Vehicle <|-- Car"}
|
|
1598
|
-
\`\`\`
|
|
1599
|
-
`;
|
|
1600
|
-
deviationStart = 11;
|
|
1601
|
-
deviationEnd = -5;
|
|
1602
|
-
break;
|
|
1603
|
-
}
|
|
1604
|
-
case "state": {
|
|
1605
|
-
targetValue = `\`\`\`mermaid
|
|
1606
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.state) || "stateDiagram-v2\n s1 --> s2"}
|
|
1607
|
-
\`\`\`
|
|
1608
|
-
`;
|
|
1609
|
-
deviationStart = 11;
|
|
1610
|
-
deviationEnd = -5;
|
|
1611
|
-
break;
|
|
1612
|
-
}
|
|
1613
|
-
case "pie": {
|
|
1614
|
-
targetValue = `\`\`\`mermaid
|
|
1615
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.pie) || 'pie title Pets adopted by volunteers\n "Dogs" : 386\n "Cats" : 85\n "Rats" : 15'}
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
const handleHeading = (direct, codeMirrorUt) => {
|
|
1468
|
+
const level = direct.slice(1);
|
|
1469
|
+
const prefix2 = "#".repeat(Number(level));
|
|
1470
|
+
const [text, replaceStart, replaceEnd] = getSelectedInfo(codeMirrorUt, {
|
|
1471
|
+
wholeLine: true
|
|
1472
|
+
});
|
|
1473
|
+
return {
|
|
1474
|
+
text: `${prefix2} ${text}`,
|
|
1475
|
+
options: { deviationStart: prefix2.length + 1, replaceStart, replaceEnd }
|
|
1476
|
+
};
|
|
1477
|
+
};
|
|
1478
|
+
const handlePrettier = async (codeMirrorUt, params) => {
|
|
1479
|
+
var _a, _b, _c;
|
|
1480
|
+
const prettier = window.prettier || ((_a = configOption.editorExtensions.prettier) == null ? void 0 : _a.prettierInstance);
|
|
1481
|
+
const prettierPlugins = [
|
|
1482
|
+
((_b = window.prettierPlugins) == null ? void 0 : _b.markdown) || ((_c = configOption.editorExtensions.prettier) == null ? void 0 : _c.parserMarkdownInstance)
|
|
1483
|
+
];
|
|
1484
|
+
if (!prettier || !prettierPlugins[0]) {
|
|
1485
|
+
bus.emit(params.editorId, ERROR_CATCHER, {
|
|
1486
|
+
name: "prettier",
|
|
1487
|
+
message: "prettier is undefined"
|
|
1488
|
+
});
|
|
1489
|
+
return {
|
|
1490
|
+
text: codeMirrorUt.getValue(),
|
|
1491
|
+
options: { select: false, replaceAll: true }
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
return {
|
|
1495
|
+
text: await prettier.format(codeMirrorUt.getValue(), {
|
|
1496
|
+
parser: "markdown",
|
|
1497
|
+
plugins: prettierPlugins
|
|
1498
|
+
}),
|
|
1499
|
+
options: { select: false, replaceAll: true }
|
|
1500
|
+
};
|
|
1501
|
+
};
|
|
1502
|
+
const wrappers = {
|
|
1503
|
+
bold: ["**", "**", 2, -2],
|
|
1504
|
+
underline: ["<u>", "</u>", 3, -4],
|
|
1505
|
+
italic: ["*", "*", 1, -1],
|
|
1506
|
+
strikeThrough: ["~~", "~~", 2, -2],
|
|
1507
|
+
sub: ["~", "~", 1, -1],
|
|
1508
|
+
sup: ["^", "^", 1, -1],
|
|
1509
|
+
codeRow: ["`", "`", 1, -1],
|
|
1510
|
+
katexInline: ["$", "$", 1, -1],
|
|
1511
|
+
katexBlock: ["\n$$\n", "\n$$\n", 4, -4]
|
|
1512
|
+
};
|
|
1513
|
+
const wrapText = (type, codeMirrorUt) => {
|
|
1514
|
+
const text = codeMirrorUt.getSelectedText();
|
|
1515
|
+
const [prefix2, subfix, deviationStart, deviationEnd] = wrappers[type];
|
|
1516
|
+
return {
|
|
1517
|
+
text: `${prefix2}${text}${subfix}`,
|
|
1518
|
+
options: {
|
|
1519
|
+
deviationStart,
|
|
1520
|
+
deviationEnd
|
|
1521
|
+
// replaceStart, replaceEnd
|
|
1522
|
+
}
|
|
1523
|
+
};
|
|
1524
|
+
};
|
|
1525
|
+
const keys = {
|
|
1526
|
+
quote: "> ",
|
|
1527
|
+
unorderedList: "- ",
|
|
1528
|
+
orderedList: 1,
|
|
1529
|
+
task: "- [ ] "
|
|
1530
|
+
};
|
|
1531
|
+
const handleMultiLine = (type, codeMirrorUt) => {
|
|
1532
|
+
const [text, replaceStart, replaceEnd] = getSelectedInfo(codeMirrorUt, {
|
|
1533
|
+
wholeLine: true
|
|
1534
|
+
});
|
|
1535
|
+
const lines = text.split("\n");
|
|
1536
|
+
const key = keys[type];
|
|
1537
|
+
const formattedLines = type === "orderedList" ? lines.map((line, i) => `${key + i}. ${line}`) : lines.map((line) => `${key}${line}`);
|
|
1538
|
+
const firstLinePrefix = type === "orderedList" ? "1. " : key.toString();
|
|
1539
|
+
const deviationStart = lines.length === 1 ? firstLinePrefix.length : 0;
|
|
1540
|
+
return {
|
|
1541
|
+
text: formattedLines.join("\n"),
|
|
1542
|
+
options: {
|
|
1543
|
+
deviationStart,
|
|
1544
|
+
replaceStart,
|
|
1545
|
+
replaceEnd
|
|
1546
|
+
}
|
|
1547
|
+
};
|
|
1548
|
+
};
|
|
1549
|
+
const handleCodeBlock = (params, codeMirrorUt) => {
|
|
1550
|
+
const [text, replaceStart, replaceEnd] = getSelectedInfo(codeMirrorUt);
|
|
1551
|
+
const mode = params.mode || "language";
|
|
1552
|
+
const _text = `
|
|
1553
|
+
\`\`\`${mode}
|
|
1554
|
+
${params.text || text || ""}
|
|
1616
1555
|
\`\`\`
|
|
1617
1556
|
`;
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1557
|
+
return {
|
|
1558
|
+
text: _text,
|
|
1559
|
+
options: {
|
|
1560
|
+
deviationStart: 4,
|
|
1561
|
+
deviationEnd: 4 + mode.length - _text.length,
|
|
1562
|
+
replaceStart,
|
|
1563
|
+
replaceEnd
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1566
|
+
};
|
|
1567
|
+
const handleMermaid = (type) => {
|
|
1568
|
+
const mermaidTemplates = {
|
|
1569
|
+
flow: "flowchart TD \n Start --> Stop",
|
|
1570
|
+
sequence: "sequenceDiagram\n A->>B: hello!\n B-->>A: hi!",
|
|
1571
|
+
gantt: "gantt\ntitle Gantt Chart\ndateFormat YYYY-MM-DD",
|
|
1572
|
+
class: "classDiagram\n class Animal",
|
|
1573
|
+
state: "stateDiagram-v2\n s1 --> s2",
|
|
1574
|
+
pie: 'pie\n "Dogs" : 386\n "Cats" : 85\n "Rats" : 15',
|
|
1575
|
+
relationship: "erDiagram\n CAR ||--o{ NAMED-DRIVER : allows",
|
|
1576
|
+
journey: "journey\n title My Journey",
|
|
1577
|
+
...configOption.editorConfig.mermaidTemplate
|
|
1578
|
+
};
|
|
1579
|
+
return {
|
|
1580
|
+
text: `
|
|
1581
|
+
\`\`\`mermaid
|
|
1582
|
+
${mermaidTemplates[type]}
|
|
1625
1583
|
\`\`\`
|
|
1584
|
+
`,
|
|
1585
|
+
options: { deviationStart: 12, deviationEnd: -5 }
|
|
1586
|
+
};
|
|
1587
|
+
};
|
|
1588
|
+
const handleImage = (params) => {
|
|
1589
|
+
const { desc, url, urls } = params;
|
|
1590
|
+
let text = "";
|
|
1591
|
+
if (urls instanceof Array) {
|
|
1592
|
+
text = urls.reduce((pVal, _url) => {
|
|
1593
|
+
const {
|
|
1594
|
+
url: url2 = "",
|
|
1595
|
+
alt = "",
|
|
1596
|
+
title = ""
|
|
1597
|
+
} = typeof _url === "object" ? _url : { url: _url };
|
|
1598
|
+
return pVal + `
|
|
1626
1599
|
`;
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
}
|
|
1631
|
-
case "journey": {
|
|
1632
|
-
targetValue = `\`\`\`mermaid
|
|
1633
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.journey) || "journey\n title My working day\n section Go to work\n Make tea: 5: Me\n Go upstairs: 3: Me\n Do work: 1: Me, Cat\n section Go home\n Go downstairs: 5: Me\n Sit down: 5: Me"}
|
|
1634
|
-
\`\`\`
|
|
1600
|
+
}, "");
|
|
1601
|
+
} else {
|
|
1602
|
+
text = `
|
|
1635
1603
|
`;
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
const insertOptions = generate(selectedText);
|
|
1655
|
-
targetValue = insertOptions.targetValue;
|
|
1656
|
-
select = insertOptions.select ?? true;
|
|
1657
|
-
deviationStart = insertOptions.deviationStart || 0;
|
|
1658
|
-
deviationEnd = insertOptions.deviationEnd || 0;
|
|
1659
|
-
}
|
|
1604
|
+
}
|
|
1605
|
+
return { text, options: { select: false } };
|
|
1606
|
+
};
|
|
1607
|
+
const handleTable = (params) => {
|
|
1608
|
+
const { selectedShape = { x: 1, y: 1 } } = params;
|
|
1609
|
+
const { x, y } = selectedShape;
|
|
1610
|
+
let text = "\n| Column";
|
|
1611
|
+
for (let i = 0; i <= y; i++) {
|
|
1612
|
+
text += ` |`;
|
|
1613
|
+
}
|
|
1614
|
+
text += "\n|";
|
|
1615
|
+
for (let i = 0; i <= y; i++) {
|
|
1616
|
+
text += " - |";
|
|
1617
|
+
}
|
|
1618
|
+
for (let row = 0; row <= x; row++) {
|
|
1619
|
+
text += "\n|";
|
|
1620
|
+
for (let col = 0; col <= y; col++) {
|
|
1621
|
+
text += " |";
|
|
1660
1622
|
}
|
|
1661
1623
|
}
|
|
1624
|
+
text += "\n";
|
|
1662
1625
|
return {
|
|
1663
|
-
text
|
|
1626
|
+
text,
|
|
1664
1627
|
options: {
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1628
|
+
deviationStart: 3,
|
|
1629
|
+
deviationEnd: 10 - text.length
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
};
|
|
1633
|
+
const handleUniversal = (selectedText, params) => {
|
|
1634
|
+
const { generate } = params;
|
|
1635
|
+
const insertOptions = generate(selectedText);
|
|
1636
|
+
return {
|
|
1637
|
+
text: insertOptions.targetValue,
|
|
1638
|
+
options: {
|
|
1639
|
+
select: insertOptions.select ?? true,
|
|
1640
|
+
deviationStart: insertOptions.deviationStart || 0,
|
|
1641
|
+
deviationEnd: insertOptions.deviationEnd || 0
|
|
1673
1642
|
}
|
|
1674
1643
|
};
|
|
1675
1644
|
};
|
|
1645
|
+
const getSelectedInfo = (codeMirrorUt, options = {
|
|
1646
|
+
wholeLine: false
|
|
1647
|
+
}) => {
|
|
1648
|
+
const state = codeMirrorUt.view.state;
|
|
1649
|
+
const selection2 = state.selection.main;
|
|
1650
|
+
if (selection2.empty) {
|
|
1651
|
+
const startLine = state.doc.lineAt(selection2.from);
|
|
1652
|
+
return [state.doc.lineAt(selection2.from).text, startLine.from, startLine.to];
|
|
1653
|
+
} else if (options.wholeLine) {
|
|
1654
|
+
const startLine = state.doc.lineAt(selection2.from);
|
|
1655
|
+
const endLine = state.doc.lineAt(selection2.to);
|
|
1656
|
+
return [
|
|
1657
|
+
state.doc.sliceString(startLine.from, endLine.to),
|
|
1658
|
+
startLine.from,
|
|
1659
|
+
endLine.to
|
|
1660
|
+
];
|
|
1661
|
+
}
|
|
1662
|
+
return [
|
|
1663
|
+
state.doc.sliceString(selection2.from, selection2.to),
|
|
1664
|
+
selection2.from,
|
|
1665
|
+
selection2.to
|
|
1666
|
+
];
|
|
1667
|
+
};
|
|
1676
1668
|
const chalky$1 = "#e5c07b", coral$1 = "var(--md-color)", cyan$1 = "#56b6c2", invalid$1 = "#ffffff", ivory$1 = "var(--md-color)", stone$1 = "#e5c07b", malibu$1 = "#e5c07b", sage$1 = "var(--md-color)", whiskey$1 = "#d19a66", violet$1 = "#c678dd", darkBackground$1 = "#21252b", highlightBackground$1 = "#2c313a", background$1 = "var(--md-bk-color)", tooltipBackground$1 = "var(--md-bk-color)", selection$1 = "#ceedfa33", cursor$1 = "#528bff";
|
|
1677
1669
|
const oneDarkTheme = EditorView.theme(
|
|
1678
1670
|
{
|
|
@@ -2080,16 +2072,22 @@ class CodeMirrorUt {
|
|
|
2080
2072
|
* @param text 待替换内容
|
|
2081
2073
|
* @param options 替换后是否选中
|
|
2082
2074
|
*/
|
|
2083
|
-
replaceSelectedText(text,
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2075
|
+
replaceSelectedText(text, _options, editorId) {
|
|
2076
|
+
const options = {
|
|
2077
|
+
// 是否选中
|
|
2078
|
+
select: true,
|
|
2079
|
+
// 选中时,开始位置的偏移量
|
|
2080
|
+
deviationStart: 0,
|
|
2081
|
+
// 结束的偏移量
|
|
2082
|
+
deviationEnd: 0,
|
|
2083
|
+
// 直接替换所有文本
|
|
2084
|
+
replaceAll: false,
|
|
2085
|
+
// 替换旧文本的开始位置
|
|
2086
|
+
replaceStart: -1,
|
|
2087
|
+
// 替换旧文本的结束位置
|
|
2088
|
+
replaceEnd: -1,
|
|
2089
|
+
..._options
|
|
2090
|
+
};
|
|
2093
2091
|
try {
|
|
2094
2092
|
if (options.replaceAll) {
|
|
2095
2093
|
this.setValue(text);
|
|
@@ -2102,13 +2100,22 @@ class CodeMirrorUt {
|
|
|
2102
2100
|
throw new Error("The input text is too long");
|
|
2103
2101
|
}
|
|
2104
2102
|
const { from } = this.view.state.selection.main;
|
|
2105
|
-
|
|
2103
|
+
if (options.replaceStart !== -1) {
|
|
2104
|
+
this.view.dispatch({
|
|
2105
|
+
changes: {
|
|
2106
|
+
from: options.replaceStart,
|
|
2107
|
+
to: options.replaceEnd,
|
|
2108
|
+
insert: text
|
|
2109
|
+
}
|
|
2110
|
+
});
|
|
2111
|
+
} else {
|
|
2112
|
+
this.view.dispatch(this.view.state.replaceSelection(text));
|
|
2113
|
+
}
|
|
2106
2114
|
if (options.select) {
|
|
2107
|
-
const to = from + text.length + options.deviationEnd;
|
|
2108
2115
|
this.view.dispatch({
|
|
2109
2116
|
selection: {
|
|
2110
|
-
anchor: from + options.deviationStart,
|
|
2111
|
-
head:
|
|
2117
|
+
anchor: options.replaceStart === -1 ? from + options.deviationStart : options.replaceStart + options.deviationStart,
|
|
2118
|
+
head: options.replaceStart === -1 ? from + text.length + options.deviationEnd : options.replaceStart + text.length + options.deviationEnd
|
|
2112
2119
|
}
|
|
2113
2120
|
});
|
|
2114
2121
|
}
|
|
@@ -32,12 +32,7 @@ export default class CodeMirrorUt {
|
|
|
32
32
|
* @param text 待替换内容
|
|
33
33
|
* @param options 替换后是否选中
|
|
34
34
|
*/
|
|
35
|
-
replaceSelectedText(text: string,
|
|
36
|
-
select: boolean;
|
|
37
|
-
deviationStart: number;
|
|
38
|
-
deviationEnd: number;
|
|
39
|
-
replaceAll: boolean;
|
|
40
|
-
} | undefined, editorId: string): void;
|
|
35
|
+
replaceSelectedText(text: string, _options: any, editorId: string): void;
|
|
41
36
|
constructor(view: EditorView);
|
|
42
37
|
/**
|
|
43
38
|
* 设置tabSize
|
|
@@ -10,10 +10,31 @@ export type ToolDirective = 'bold' | 'underline' | 'italic' | 'strikeThrough' |
|
|
|
10
10
|
*/
|
|
11
11
|
export declare const directive2flag: (direct: ToolDirective, codeMirrorUt: CodeMirrorUt, params?: any) => Promise<{
|
|
12
12
|
text: string;
|
|
13
|
+
options: {
|
|
14
|
+
deviationStart: number;
|
|
15
|
+
replaceStart: number;
|
|
16
|
+
replaceEnd: number;
|
|
17
|
+
};
|
|
18
|
+
} | {
|
|
19
|
+
text: any;
|
|
13
20
|
options: {
|
|
14
21
|
select: boolean;
|
|
22
|
+
replaceAll: boolean;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
text: string;
|
|
26
|
+
options: {
|
|
15
27
|
deviationStart: number;
|
|
16
28
|
deviationEnd: number;
|
|
17
|
-
|
|
29
|
+
};
|
|
30
|
+
} | {
|
|
31
|
+
text: string;
|
|
32
|
+
options: {
|
|
33
|
+
select: boolean;
|
|
34
|
+
};
|
|
35
|
+
} | {
|
|
36
|
+
text: string;
|
|
37
|
+
options: {
|
|
38
|
+
select?: undefined;
|
|
18
39
|
};
|
|
19
40
|
}>;
|