@worktile/theia 2.4.1 → 2.4.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/bundles/worktile-theia.umd.js +837 -822
- package/bundles/worktile-theia.umd.js.map +1 -1
- package/constants/auto-format-rules.d.ts +1 -1
- package/esm2015/constants/auto-format-rules.js +3 -2
- package/esm2015/editor.component.js +3 -2
- package/esm2015/interfaces/auto-format.js +1 -1
- package/esm2015/interfaces/editor.js +1 -1
- package/esm2015/plugins/autoformat/autoformat.plugin.js +23 -6
- package/esm2015/plugins/index.js +2 -3
- package/fesm2015/worktile-theia.js +544 -526
- package/fesm2015/worktile-theia.js.map +1 -1
- package/interfaces/auto-format.d.ts +1 -0
- package/interfaces/editor.d.ts +3 -0
- package/package.json +1 -1
- package/plugins/autoformat/autoformat.plugin.d.ts +1 -2
|
@@ -8,14 +8,14 @@ import * as i1 from 'slate-angular';
|
|
|
8
8
|
import { BaseTextComponent, BaseElementComponent, AngularEditor, NODE_TO_PARENT, NODE_TO_INDEX, IS_SAFARI, hotkeys, getPlainText as getPlainText$1, hasBlockCard, isCardLeft, FAKE_RIGHT_BLOCK_CARD_OFFSET, ELEMENT_TO_COMPONENT, EDITOR_TO_ELEMENT, isComponentType, withAngular, SlateModule } from 'slate-angular';
|
|
9
9
|
import { mixinUnsubscribe, MixinBase } from 'ngx-tethys/core';
|
|
10
10
|
import isHotkey, { isKeyHotkey } from 'is-hotkey';
|
|
11
|
-
import { Element as Element$1,
|
|
11
|
+
import { Transforms, Text, Range, Editor, Element as Element$1, Node, Span, Path, Point, Operation, createEditor } from 'slate';
|
|
12
12
|
import { HistoryEditor, withHistory } from 'slate-history';
|
|
13
|
-
import { __rest, __awaiter } from 'tslib';
|
|
14
|
-
import * as _lodash from 'lodash';
|
|
15
13
|
import marked from 'marked';
|
|
16
14
|
import { TheiaConverter } from '@atinc/selene';
|
|
17
15
|
import * as i1$3 from 'ngx-tethys/popover';
|
|
18
16
|
import { ThyPopover } from 'ngx-tethys/popover';
|
|
17
|
+
import { __rest, __awaiter } from 'tslib';
|
|
18
|
+
import * as _lodash from 'lodash';
|
|
19
19
|
import * as i2 from '@angular/cdk/overlay';
|
|
20
20
|
import { Overlay, OverlayModule } from '@angular/cdk/overlay';
|
|
21
21
|
import * as i1$1 from 'ngx-tethys/alert';
|
|
@@ -522,6 +522,61 @@ function idCreator(length = 5) {
|
|
|
522
522
|
return key;
|
|
523
523
|
}
|
|
524
524
|
|
|
525
|
+
const UNDOING = new WeakMap();
|
|
526
|
+
const REDOING = new WeakMap();
|
|
527
|
+
const withTheHistory = (editor) => {
|
|
528
|
+
const { undo, redo } = editor;
|
|
529
|
+
editor.undo = () => {
|
|
530
|
+
UNDOING.set(editor, true);
|
|
531
|
+
undo();
|
|
532
|
+
UNDOING.set(editor, false);
|
|
533
|
+
};
|
|
534
|
+
editor.redo = () => {
|
|
535
|
+
REDOING.set(editor, true);
|
|
536
|
+
redo();
|
|
537
|
+
REDOING.set(editor, false);
|
|
538
|
+
};
|
|
539
|
+
return editor;
|
|
540
|
+
};
|
|
541
|
+
const TheHistoryEditor = {
|
|
542
|
+
isUndoing(editor) {
|
|
543
|
+
return UNDOING.get(editor);
|
|
544
|
+
},
|
|
545
|
+
isRedoing(editor) {
|
|
546
|
+
return REDOING.get(editor);
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
const setMarks = (editor, marks, at) => {
|
|
551
|
+
Transforms.setNodes(editor, marks, {
|
|
552
|
+
at,
|
|
553
|
+
match: Text.isText,
|
|
554
|
+
split: true
|
|
555
|
+
});
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
const clearMarks = (editor) => {
|
|
559
|
+
const { selection } = editor;
|
|
560
|
+
if (!selection) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
if (Range.isCollapsed(selection)) {
|
|
564
|
+
const marks = Editor.marks(editor);
|
|
565
|
+
for (const key in marks) {
|
|
566
|
+
Editor.removeMark(editor, key);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
const unsetMarks = {};
|
|
571
|
+
MarkProps.forEach(key => {
|
|
572
|
+
unsetMarks[key] = null;
|
|
573
|
+
});
|
|
574
|
+
setMarks(editor, unsetMarks);
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
const insertElement = (editor, element) => editor.insertElement(element);
|
|
579
|
+
|
|
525
580
|
const isAncestor = (node) => Element$1.isElement(node) || Editor.isEditor(node);
|
|
526
581
|
|
|
527
582
|
const getLastChild$1 = (node, level) => {
|
|
@@ -1321,36 +1376,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
1321
1376
|
someNode: someNode
|
|
1322
1377
|
});
|
|
1323
1378
|
|
|
1324
|
-
const setMarks = (editor, marks, at) => {
|
|
1325
|
-
Transforms.setNodes(editor, marks, {
|
|
1326
|
-
at,
|
|
1327
|
-
match: Text.isText,
|
|
1328
|
-
split: true
|
|
1329
|
-
});
|
|
1330
|
-
};
|
|
1331
|
-
|
|
1332
|
-
const clearMarks = (editor) => {
|
|
1333
|
-
const { selection } = editor;
|
|
1334
|
-
if (!selection) {
|
|
1335
|
-
return;
|
|
1336
|
-
}
|
|
1337
|
-
if (Range.isCollapsed(selection)) {
|
|
1338
|
-
const marks = Editor.marks(editor);
|
|
1339
|
-
for (const key in marks) {
|
|
1340
|
-
Editor.removeMark(editor, key);
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
else {
|
|
1344
|
-
const unsetMarks = {};
|
|
1345
|
-
MarkProps.forEach(key => {
|
|
1346
|
-
unsetMarks[key] = null;
|
|
1347
|
-
});
|
|
1348
|
-
setMarks(editor, unsetMarks);
|
|
1349
|
-
}
|
|
1350
|
-
};
|
|
1351
|
-
|
|
1352
|
-
const insertElement = (editor, element) => editor.insertElement(element);
|
|
1353
|
-
|
|
1354
1379
|
const insertElementNext = (editor, node) => {
|
|
1355
1380
|
if (Range.isExpanded(editor.selection)) {
|
|
1356
1381
|
Editor.deleteFragment(editor);
|
|
@@ -1586,439 +1611,19 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
1586
1611
|
handleContinualInsertBreak: handleContinualInsertBreak
|
|
1587
1612
|
});
|
|
1588
1613
|
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
const ListEditor = {
|
|
1594
|
-
isList(editor, element, type) {
|
|
1595
|
-
return Editor.isBlock(editor, element) && element.type === type;
|
|
1596
|
-
},
|
|
1597
|
-
toggleList(editor, type, startIndex) {
|
|
1598
|
-
if (!editor.selection) {
|
|
1599
|
-
return;
|
|
1600
|
-
}
|
|
1601
|
-
if (!startIndex) {
|
|
1602
|
-
startIndex = 1;
|
|
1603
|
-
}
|
|
1604
|
-
const types = [ElementKinds.bulletedList, ElementKinds.numberedList];
|
|
1605
|
-
Editor.withoutNormalizing(editor, () => {
|
|
1606
|
-
const [...listItems] = Editor.nodes(editor, {
|
|
1607
|
-
match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem,
|
|
1608
|
-
mode: 'lowest'
|
|
1609
|
-
});
|
|
1610
|
-
const firstListItemPath = listItems.length && listItems[0][1];
|
|
1611
|
-
const activeListPath = listItems.length && Path.parent(firstListItemPath);
|
|
1612
|
-
const activeListNode = listItems.length && Node.get(editor, activeListPath);
|
|
1613
|
-
// 同级且类型相同:unwrap
|
|
1614
|
-
const isLowestActive = listItems.length &&
|
|
1615
|
-
listItems.every(([, path]) => activeListNode.type === type && (Path.isSibling(firstListItemPath, path) || Path.equals(firstListItemPath, path)));
|
|
1616
|
-
if (isLowestActive) {
|
|
1617
|
-
const upListItem = Path.parent(activeListPath);
|
|
1618
|
-
Transforms.unwrapNodes(editor, {
|
|
1619
|
-
at: editor.selection,
|
|
1620
|
-
match: node => node === activeListNode,
|
|
1621
|
-
split: true,
|
|
1622
|
-
mode: 'lowest'
|
|
1623
|
-
});
|
|
1624
|
-
if (upListItem && Node.get(editor, upListItem).type === ElementKinds.listItem) {
|
|
1625
|
-
Transforms.moveNodes(editor, {
|
|
1626
|
-
at: editor.selection,
|
|
1627
|
-
to: Path.next(upListItem),
|
|
1628
|
-
match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem
|
|
1629
|
-
});
|
|
1630
|
-
}
|
|
1631
|
-
else {
|
|
1632
|
-
Transforms.unwrapNodes(editor, {
|
|
1633
|
-
match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem
|
|
1634
|
-
});
|
|
1635
|
-
}
|
|
1636
|
-
return;
|
|
1637
|
-
}
|
|
1638
|
-
// 跨级、同级且类型不同
|
|
1639
|
-
if (activeListNode && types.includes(activeListNode.type)) {
|
|
1640
|
-
Transforms.setNodes(editor, { type }, { match: node => Element$1.isElement(node) && node.type !== type && types.includes(node.type) });
|
|
1641
|
-
return;
|
|
1642
|
-
}
|
|
1643
|
-
// wrap
|
|
1644
|
-
this.buildListItem(editor);
|
|
1645
|
-
// Todo: types
|
|
1646
|
-
Transforms.wrapNodes(editor, { type, children: [], start: startIndex }, {
|
|
1647
|
-
at: editor.selection,
|
|
1648
|
-
match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem
|
|
1649
|
-
});
|
|
1650
|
-
});
|
|
1651
|
-
},
|
|
1652
|
-
unwrapList(editor) {
|
|
1653
|
-
Editor.withoutNormalizing(editor, () => {
|
|
1654
|
-
unwrapNodesByType(editor, [ElementKinds.bulletedList, ElementKinds.numberedList], { split: true, mode: 'all' });
|
|
1655
|
-
unwrapNodesByType(editor, [ElementKinds.listItem], { split: true, mode: 'all' });
|
|
1656
|
-
});
|
|
1657
|
-
},
|
|
1658
|
-
wrapList(editor, type) {
|
|
1659
|
-
Editor.withoutNormalizing(editor, () => {
|
|
1660
|
-
const listItem = {
|
|
1661
|
-
type: ElementKinds.listItem,
|
|
1662
|
-
children: []
|
|
1663
|
-
};
|
|
1664
|
-
const list = {
|
|
1665
|
-
type,
|
|
1666
|
-
children: []
|
|
1667
|
-
};
|
|
1668
|
-
Transforms.wrapNodes(editor, list, { split: true });
|
|
1669
|
-
Transforms.wrapNodes(editor, listItem, { split: true });
|
|
1670
|
-
});
|
|
1671
|
-
},
|
|
1672
|
-
isActive(editor, type) {
|
|
1673
|
-
const [match] = getNodesByType(editor, type);
|
|
1674
|
-
return !!match;
|
|
1675
|
-
},
|
|
1676
|
-
getActiveList(editor) {
|
|
1677
|
-
const [match] = getNodesByType(editor, LIST_BLOCK_TYPES);
|
|
1678
|
-
return match;
|
|
1679
|
-
},
|
|
1680
|
-
buildListItem(editor) {
|
|
1681
|
-
const nodes = Editor.nodes(editor, {
|
|
1682
|
-
match: node => Editor.isBlock(editor, node),
|
|
1683
|
-
mode: 'lowest'
|
|
1684
|
-
});
|
|
1685
|
-
for (const [node, path] of nodes) {
|
|
1686
|
-
if (!Editor.isVoid(editor, node) && Element$1.isElement(node) && node.type !== ElementKinds.paragraph) {
|
|
1687
|
-
Transforms.setNodes(editor, { type: ElementKinds.paragraph, checked: undefined }, // todo remove checked
|
|
1688
|
-
{ at: path });
|
|
1689
|
-
}
|
|
1690
|
-
else if (Element$1.isElement(node) && node.type === ElementKinds.paragraph) {
|
|
1691
|
-
let { textIndent } = node;
|
|
1692
|
-
if (textIndent) {
|
|
1693
|
-
Transforms.setNodes(editor, { textIndent: undefined, indent: undefined }, // remove indent
|
|
1694
|
-
{ at: path });
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
if (Node.parent(editor, path).type !== ElementKinds.listItem) {
|
|
1698
|
-
Transforms.wrapNodes(editor, { type: ElementKinds.listItem, children: [] }, {
|
|
1699
|
-
at: path,
|
|
1700
|
-
split: true
|
|
1701
|
-
});
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
},
|
|
1705
|
-
buildInsertDataChildren(node) {
|
|
1706
|
-
const { children } = node;
|
|
1707
|
-
const listItem = children[0];
|
|
1708
|
-
if (isNodeTypeList(node) && Element$1.isElement(listItem) && listItem.children[0].type === ElementKinds.paragraph) {
|
|
1709
|
-
return node;
|
|
1710
|
-
}
|
|
1711
|
-
return this.buildInsertDataChildren(listItem);
|
|
1614
|
+
class TheConversionHintComponent {
|
|
1615
|
+
constructor() {
|
|
1616
|
+
this.duration = 10000;
|
|
1617
|
+
this.pauseOnHover = true;
|
|
1712
1618
|
}
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
isActive(editor) {
|
|
1717
|
-
const [match] = getNodesByType(editor, ElementKinds.checkItem);
|
|
1718
|
-
return !!match;
|
|
1719
|
-
},
|
|
1720
|
-
insertTodoItem(editor) {
|
|
1721
|
-
if (!editor.selection) {
|
|
1722
|
-
return;
|
|
1723
|
-
}
|
|
1724
|
-
const isActive = this.isActive(editor);
|
|
1725
|
-
const isNumberedList = ListEditor.isActive(editor, ElementKinds.numberedList);
|
|
1726
|
-
const isBulletedList = ListEditor.isActive(editor, ElementKinds.bulletedList);
|
|
1727
|
-
if (isActive) {
|
|
1728
|
-
Transforms.setNodes(editor, {
|
|
1729
|
-
type: ElementKinds.paragraph
|
|
1730
|
-
});
|
|
1619
|
+
mouseenter() {
|
|
1620
|
+
if (this.pauseOnHover) {
|
|
1621
|
+
this.clearCloseTimer();
|
|
1731
1622
|
}
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
Transforms.setNodes(editor, {
|
|
1737
|
-
type: ElementKinds.checkItem
|
|
1738
|
-
});
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
};
|
|
1742
|
-
|
|
1743
|
-
const BlockquoteEditor = {
|
|
1744
|
-
toggleBlockquote(editor) {
|
|
1745
|
-
if (!isParagraph(editor)) {
|
|
1746
|
-
Transforms.insertNodes(editor, {
|
|
1747
|
-
type: ElementKinds.paragraph,
|
|
1748
|
-
mode: 'text',
|
|
1749
|
-
children: [
|
|
1750
|
-
{
|
|
1751
|
-
text: ''
|
|
1752
|
-
}
|
|
1753
|
-
]
|
|
1754
|
-
});
|
|
1755
|
-
}
|
|
1756
|
-
const isActive = isBlockActive(editor, ElementKinds.blockquote);
|
|
1757
|
-
if (!isActive) {
|
|
1758
|
-
Transforms.wrapNodes(editor, { type: ElementKinds.blockquote, children: [] }, {
|
|
1759
|
-
mode: 'lowest'
|
|
1760
|
-
});
|
|
1761
|
-
}
|
|
1762
|
-
else {
|
|
1763
|
-
Transforms.unwrapNodes(editor, { match: n => Element$1.isElement(n) && n.type === ElementKinds.blockquote });
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
};
|
|
1767
|
-
|
|
1768
|
-
const InlineCodeEditor = {
|
|
1769
|
-
toggleInlineCode(editor, text) {
|
|
1770
|
-
const isActive = InlineCodeEditor.isInlineCodeActive(editor);
|
|
1771
|
-
if (isActive) {
|
|
1772
|
-
InlineCodeEditor.unwrapInlineCode(editor);
|
|
1773
|
-
return;
|
|
1774
|
-
}
|
|
1775
|
-
if (Range.isCollapsed(editor.selection)) {
|
|
1776
|
-
InlineCodeEditor.wrapInlineCode(editor, text);
|
|
1777
|
-
}
|
|
1778
|
-
else {
|
|
1779
|
-
const fragment = Node.fragment(editor, editor.selection)[0];
|
|
1780
|
-
const selectNode = Node.get(fragment, []);
|
|
1781
|
-
const selectText = Node.string(selectNode);
|
|
1782
|
-
InlineCodeEditor.wrapInlineCode(editor, selectText);
|
|
1783
|
-
}
|
|
1784
|
-
},
|
|
1785
|
-
wrapInlineCode(editor, text = '') {
|
|
1786
|
-
if (InlineCodeEditor.isInlineCodeActive(editor)) {
|
|
1787
|
-
InlineCodeEditor.unwrapInlineCode(editor);
|
|
1788
|
-
}
|
|
1789
|
-
const { selection } = editor;
|
|
1790
|
-
const isCollapsed = selection && Range.isCollapsed(selection);
|
|
1791
|
-
const inlineCode = {
|
|
1792
|
-
type: ElementKinds.inlineCode,
|
|
1793
|
-
children: isCollapsed ? [{ text: text ? text : ZERO_WIDTH_CHAR }] : []
|
|
1794
|
-
};
|
|
1795
|
-
if (isCollapsed) {
|
|
1796
|
-
Transforms.insertNodes(editor, inlineCode);
|
|
1797
|
-
}
|
|
1798
|
-
else {
|
|
1799
|
-
Transforms.wrapNodes(editor, inlineCode, { split: true });
|
|
1800
|
-
}
|
|
1801
|
-
},
|
|
1802
|
-
unwrapInlineCode(editor) {
|
|
1803
|
-
Transforms.unwrapNodes(editor, { match: n => Element$1.isElement(n) && n.type === ElementKinds.inlineCode });
|
|
1804
|
-
},
|
|
1805
|
-
isInlineCodeActive(editor, path) {
|
|
1806
|
-
var _a;
|
|
1807
|
-
const [inlineCode] = Editor.nodes(editor, {
|
|
1808
|
-
at: path ? path : (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor.path,
|
|
1809
|
-
match: n => Element$1.isElement(n) && n.type === ElementKinds.inlineCode
|
|
1810
|
-
});
|
|
1811
|
-
return !!inlineCode;
|
|
1812
|
-
}
|
|
1813
|
-
};
|
|
1814
|
-
|
|
1815
|
-
const HeadingEditor = {
|
|
1816
|
-
setHeading(editor, heading) {
|
|
1817
|
-
Editor.withoutNormalizing(editor, () => {
|
|
1818
|
-
const types = [ElementKinds.bulletedList, ElementKinds.numberedList, ElementKinds.listItem];
|
|
1819
|
-
Transforms.unwrapNodes(editor, {
|
|
1820
|
-
at: editor.selection,
|
|
1821
|
-
match: n => Element$1.isElement(n) && types.includes(n.type),
|
|
1822
|
-
mode: 'all',
|
|
1823
|
-
split: true
|
|
1824
|
-
});
|
|
1825
|
-
Transforms.setNodes(editor, { type: heading });
|
|
1826
|
-
const entry = anchorBlockEntry(editor);
|
|
1827
|
-
const unMarks = {
|
|
1828
|
-
[MarkTypes.fontSize]: null
|
|
1829
|
-
};
|
|
1830
|
-
if (entry) {
|
|
1831
|
-
setMarks(editor, unMarks, entry[1]);
|
|
1832
|
-
return;
|
|
1833
|
-
}
|
|
1834
|
-
setMarks(editor, unMarks, editor.selection);
|
|
1835
|
-
});
|
|
1836
|
-
},
|
|
1837
|
-
isHeadingActive(editor, heading) {
|
|
1838
|
-
const [match] = Editor.nodes(editor, {
|
|
1839
|
-
match: n => Element$1.isElement(n) && n.type === heading,
|
|
1840
|
-
universal: true
|
|
1841
|
-
});
|
|
1842
|
-
return !!match;
|
|
1843
|
-
}
|
|
1844
|
-
};
|
|
1845
|
-
|
|
1846
|
-
const autoFormatRules = [
|
|
1847
|
-
{
|
|
1848
|
-
type: ElementKinds.heading_1,
|
|
1849
|
-
markup: '#',
|
|
1850
|
-
format: (editor) => {
|
|
1851
|
-
HeadingEditor.setHeading(editor, ElementKinds.heading_1);
|
|
1852
|
-
}
|
|
1853
|
-
},
|
|
1854
|
-
{
|
|
1855
|
-
type: ElementKinds.heading_2,
|
|
1856
|
-
markup: '##',
|
|
1857
|
-
format: (editor) => {
|
|
1858
|
-
HeadingEditor.setHeading(editor, ElementKinds.heading_2);
|
|
1859
|
-
}
|
|
1860
|
-
},
|
|
1861
|
-
{
|
|
1862
|
-
type: ElementKinds.heading_3,
|
|
1863
|
-
markup: '###',
|
|
1864
|
-
format: (editor) => {
|
|
1865
|
-
HeadingEditor.setHeading(editor, ElementKinds.heading_3);
|
|
1866
|
-
}
|
|
1867
|
-
},
|
|
1868
|
-
{
|
|
1869
|
-
type: ElementKinds.heading_4,
|
|
1870
|
-
markup: '####',
|
|
1871
|
-
format: (editor) => {
|
|
1872
|
-
HeadingEditor.setHeading(editor, ElementKinds.heading_4);
|
|
1873
|
-
}
|
|
1874
|
-
},
|
|
1875
|
-
{
|
|
1876
|
-
type: ElementKinds.heading_5,
|
|
1877
|
-
markup: '#####',
|
|
1878
|
-
format: (editor) => {
|
|
1879
|
-
HeadingEditor.setHeading(editor, ElementKinds.heading_5);
|
|
1880
|
-
}
|
|
1881
|
-
},
|
|
1882
|
-
{
|
|
1883
|
-
type: ElementKinds.heading_6,
|
|
1884
|
-
markup: '######',
|
|
1885
|
-
format: (editor) => {
|
|
1886
|
-
HeadingEditor.setHeading(editor, ElementKinds.heading_6);
|
|
1887
|
-
}
|
|
1888
|
-
},
|
|
1889
|
-
{
|
|
1890
|
-
type: ElementKinds.blockquote,
|
|
1891
|
-
markup: ['>'],
|
|
1892
|
-
format: (editor) => {
|
|
1893
|
-
BlockquoteEditor.toggleBlockquote(editor);
|
|
1894
|
-
}
|
|
1895
|
-
},
|
|
1896
|
-
{
|
|
1897
|
-
type: MarkTypes.bold,
|
|
1898
|
-
between: ['**', '**'],
|
|
1899
|
-
mode: 'inline',
|
|
1900
|
-
insertTrigger: true
|
|
1901
|
-
},
|
|
1902
|
-
{
|
|
1903
|
-
type: MarkTypes.bold,
|
|
1904
|
-
between: ['__', '__'],
|
|
1905
|
-
mode: 'inline',
|
|
1906
|
-
insertTrigger: true
|
|
1907
|
-
},
|
|
1908
|
-
{
|
|
1909
|
-
type: MarkTypes.italic,
|
|
1910
|
-
between: ['*', '*'],
|
|
1911
|
-
mode: 'inline',
|
|
1912
|
-
insertTrigger: true
|
|
1913
|
-
},
|
|
1914
|
-
{
|
|
1915
|
-
type: MarkTypes.italic,
|
|
1916
|
-
between: ['_', '_'],
|
|
1917
|
-
mode: 'inline',
|
|
1918
|
-
insertTrigger: true
|
|
1919
|
-
},
|
|
1920
|
-
{
|
|
1921
|
-
type: ElementKinds.inlineCode,
|
|
1922
|
-
between: ['`', '`'],
|
|
1923
|
-
mode: 'inline',
|
|
1924
|
-
format: (editor, text) => {
|
|
1925
|
-
InlineCodeEditor.toggleInlineCode(editor, text);
|
|
1926
|
-
Transforms.select(editor, Editor.after(editor, editor.selection));
|
|
1927
|
-
}
|
|
1928
|
-
},
|
|
1929
|
-
{
|
|
1930
|
-
type: MarkTypes.strike,
|
|
1931
|
-
between: ['~~', '~~'],
|
|
1932
|
-
mode: 'inline',
|
|
1933
|
-
insertTrigger: true
|
|
1934
|
-
},
|
|
1935
|
-
{
|
|
1936
|
-
type: ElementKinds.code,
|
|
1937
|
-
markup: '```',
|
|
1938
|
-
insertTrigger: true
|
|
1939
|
-
},
|
|
1940
|
-
{
|
|
1941
|
-
type: ElementKinds.listItem,
|
|
1942
|
-
markup: [],
|
|
1943
|
-
match: (editor) => {
|
|
1944
|
-
return isParagraph(editor) ? ['*', '-', '+'] : [];
|
|
1945
|
-
},
|
|
1946
|
-
format: (editor) => {
|
|
1947
|
-
ListEditor.toggleList(editor, ElementKinds.bulletedList);
|
|
1948
|
-
}
|
|
1949
|
-
},
|
|
1950
|
-
{
|
|
1951
|
-
type: ElementKinds.listItem,
|
|
1952
|
-
markup: [],
|
|
1953
|
-
match: (editor, textFromBlockStart) => {
|
|
1954
|
-
return isParagraph(editor) && /^-?\d+(\.|\))$/.test(textFromBlockStart) ? [textFromBlockStart] : [];
|
|
1955
|
-
},
|
|
1956
|
-
format: (editor, markup) => {
|
|
1957
|
-
let startIndex = 1;
|
|
1958
|
-
if (markup) {
|
|
1959
|
-
startIndex = markup[0].split('.')[0];
|
|
1960
|
-
if (startIndex === 0) {
|
|
1961
|
-
startIndex = 1;
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
ListEditor.toggleList(editor, ElementKinds.numberedList, startIndex);
|
|
1965
|
-
}
|
|
1966
|
-
},
|
|
1967
|
-
{
|
|
1968
|
-
type: ElementKinds.checkItem,
|
|
1969
|
-
markup: [],
|
|
1970
|
-
match: (editor) => {
|
|
1971
|
-
return isParagraph(editor) ? ['[]'] : [];
|
|
1972
|
-
},
|
|
1973
|
-
format: (editor) => {
|
|
1974
|
-
TodoItemEditor.insertTodoItem(editor);
|
|
1975
|
-
}
|
|
1976
|
-
},
|
|
1977
|
-
{
|
|
1978
|
-
type: ElementKinds.hr,
|
|
1979
|
-
markup: '---',
|
|
1980
|
-
insertTrigger: true
|
|
1981
|
-
}
|
|
1982
|
-
];
|
|
1983
|
-
|
|
1984
|
-
const UNDOING = new WeakMap();
|
|
1985
|
-
const REDOING = new WeakMap();
|
|
1986
|
-
const withTheHistory = (editor) => {
|
|
1987
|
-
const { undo, redo } = editor;
|
|
1988
|
-
editor.undo = () => {
|
|
1989
|
-
UNDOING.set(editor, true);
|
|
1990
|
-
undo();
|
|
1991
|
-
UNDOING.set(editor, false);
|
|
1992
|
-
};
|
|
1993
|
-
editor.redo = () => {
|
|
1994
|
-
REDOING.set(editor, true);
|
|
1995
|
-
redo();
|
|
1996
|
-
REDOING.set(editor, false);
|
|
1997
|
-
};
|
|
1998
|
-
return editor;
|
|
1999
|
-
};
|
|
2000
|
-
const TheHistoryEditor = {
|
|
2001
|
-
isUndoing(editor) {
|
|
2002
|
-
return UNDOING.get(editor);
|
|
2003
|
-
},
|
|
2004
|
-
isRedoing(editor) {
|
|
2005
|
-
return REDOING.get(editor);
|
|
2006
|
-
}
|
|
2007
|
-
};
|
|
2008
|
-
|
|
2009
|
-
class TheConversionHintComponent {
|
|
2010
|
-
constructor() {
|
|
2011
|
-
this.duration = 10000;
|
|
2012
|
-
this.pauseOnHover = true;
|
|
2013
|
-
}
|
|
2014
|
-
mouseenter() {
|
|
2015
|
-
if (this.pauseOnHover) {
|
|
2016
|
-
this.clearCloseTimer();
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
2019
|
-
mouseleave() {
|
|
2020
|
-
if (this.pauseOnHover) {
|
|
2021
|
-
this.creatCloseTimer();
|
|
1623
|
+
}
|
|
1624
|
+
mouseleave() {
|
|
1625
|
+
if (this.pauseOnHover) {
|
|
1626
|
+
this.creatCloseTimer();
|
|
2022
1627
|
}
|
|
2023
1628
|
}
|
|
2024
1629
|
ngOnInit() {
|
|
@@ -3053,6 +2658,10 @@ const hasStableListItem = (listItemNode) => {
|
|
|
3053
2658
|
return listItemNode.children.length === 1 && type === ElementKinds.paragraph;
|
|
3054
2659
|
};
|
|
3055
2660
|
|
|
2661
|
+
const isNodeTypeList = (n) => {
|
|
2662
|
+
return [ElementKinds.bulletedList, ElementKinds.numberedList].includes(n.type);
|
|
2663
|
+
};
|
|
2664
|
+
|
|
3056
2665
|
/**
|
|
3057
2666
|
* list 中 是否是单个listItem,且listItem没有子列表
|
|
3058
2667
|
*/
|
|
@@ -4251,79 +3860,476 @@ const autoFormatInline = (editor, { type, between, markup, ignoreTrim, format })
|
|
|
4251
3860
|
if (!endMarkupPointBefore) {
|
|
4252
3861
|
return false;
|
|
4253
3862
|
}
|
|
4254
|
-
}
|
|
4255
|
-
const startMarkupPointAfter = getPointBefore(editor, endMarkupPointBefore, {
|
|
4256
|
-
matchString: startMarkup,
|
|
4257
|
-
skipInvalid: true,
|
|
4258
|
-
afterMatch: true
|
|
4259
|
-
});
|
|
4260
|
-
if (!startMarkupPointAfter) {
|
|
4261
|
-
return false;
|
|
4262
|
-
}
|
|
4263
|
-
// found
|
|
4264
|
-
const markupRange = {
|
|
4265
|
-
anchor: startMarkupPointAfter,
|
|
4266
|
-
focus: endMarkupPointBefore
|
|
4267
|
-
};
|
|
4268
|
-
if (!ignoreTrim) {
|
|
4269
|
-
const markupText = getText(editor, markupRange);
|
|
4270
|
-
if (markupText.trim() !== markupText) {
|
|
4271
|
-
return false;
|
|
3863
|
+
}
|
|
3864
|
+
const startMarkupPointAfter = getPointBefore(editor, endMarkupPointBefore, {
|
|
3865
|
+
matchString: startMarkup,
|
|
3866
|
+
skipInvalid: true,
|
|
3867
|
+
afterMatch: true
|
|
3868
|
+
});
|
|
3869
|
+
if (!startMarkupPointAfter) {
|
|
3870
|
+
return false;
|
|
3871
|
+
}
|
|
3872
|
+
// found
|
|
3873
|
+
const markupRange = {
|
|
3874
|
+
anchor: startMarkupPointAfter,
|
|
3875
|
+
focus: endMarkupPointBefore
|
|
3876
|
+
};
|
|
3877
|
+
if (!ignoreTrim) {
|
|
3878
|
+
const markupText = getText(editor, markupRange);
|
|
3879
|
+
if (markupText.trim() !== markupText) {
|
|
3880
|
+
return false;
|
|
3881
|
+
}
|
|
3882
|
+
}
|
|
3883
|
+
// delete end markup
|
|
3884
|
+
if (endMarkup) {
|
|
3885
|
+
endMarkupPointBefore = getPointBefore(editor, selection, {
|
|
3886
|
+
matchString: endMarkup
|
|
3887
|
+
});
|
|
3888
|
+
Transforms.delete(editor, {
|
|
3889
|
+
at: {
|
|
3890
|
+
anchor: endMarkupPointBefore,
|
|
3891
|
+
focus: selection.anchor
|
|
3892
|
+
}
|
|
3893
|
+
});
|
|
3894
|
+
}
|
|
3895
|
+
const startMarkupPointBefore = getPointBefore(editor, selection, {
|
|
3896
|
+
matchString: startMarkup,
|
|
3897
|
+
skipInvalid: true
|
|
3898
|
+
});
|
|
3899
|
+
if (format) {
|
|
3900
|
+
const markupText = getText(editor, markupRange);
|
|
3901
|
+
format(editor, markupText);
|
|
3902
|
+
// delete start to end selection
|
|
3903
|
+
Transforms.delete(editor, {
|
|
3904
|
+
at: {
|
|
3905
|
+
anchor: startMarkupPointBefore,
|
|
3906
|
+
focus: selection.anchor
|
|
3907
|
+
}
|
|
3908
|
+
});
|
|
3909
|
+
}
|
|
3910
|
+
else {
|
|
3911
|
+
// add mark to the text between the markups
|
|
3912
|
+
Transforms.select(editor, markupRange);
|
|
3913
|
+
editor.addMark(type, true);
|
|
3914
|
+
Transforms.collapse(editor, { edge: 'end' });
|
|
3915
|
+
editor.removeMark(type, false);
|
|
3916
|
+
// delete start markup
|
|
3917
|
+
Transforms.delete(editor, {
|
|
3918
|
+
at: {
|
|
3919
|
+
anchor: startMarkupPointBefore,
|
|
3920
|
+
focus: startMarkupPointAfter
|
|
3921
|
+
}
|
|
3922
|
+
});
|
|
3923
|
+
}
|
|
3924
|
+
return true;
|
|
3925
|
+
};
|
|
3926
|
+
|
|
3927
|
+
const ListEditor = {
|
|
3928
|
+
isList(editor, element, type) {
|
|
3929
|
+
return Editor.isBlock(editor, element) && element.type === type;
|
|
3930
|
+
},
|
|
3931
|
+
toggleList(editor, type, startIndex) {
|
|
3932
|
+
if (!editor.selection) {
|
|
3933
|
+
return;
|
|
3934
|
+
}
|
|
3935
|
+
if (!startIndex) {
|
|
3936
|
+
startIndex = 1;
|
|
3937
|
+
}
|
|
3938
|
+
const types = [ElementKinds.bulletedList, ElementKinds.numberedList];
|
|
3939
|
+
Editor.withoutNormalizing(editor, () => {
|
|
3940
|
+
const [...listItems] = Editor.nodes(editor, {
|
|
3941
|
+
match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem,
|
|
3942
|
+
mode: 'lowest'
|
|
3943
|
+
});
|
|
3944
|
+
const firstListItemPath = listItems.length && listItems[0][1];
|
|
3945
|
+
const activeListPath = listItems.length && Path.parent(firstListItemPath);
|
|
3946
|
+
const activeListNode = listItems.length && Node.get(editor, activeListPath);
|
|
3947
|
+
// 同级且类型相同:unwrap
|
|
3948
|
+
const isLowestActive = listItems.length &&
|
|
3949
|
+
listItems.every(([, path]) => activeListNode.type === type && (Path.isSibling(firstListItemPath, path) || Path.equals(firstListItemPath, path)));
|
|
3950
|
+
if (isLowestActive) {
|
|
3951
|
+
const upListItem = Path.parent(activeListPath);
|
|
3952
|
+
Transforms.unwrapNodes(editor, {
|
|
3953
|
+
at: editor.selection,
|
|
3954
|
+
match: node => node === activeListNode,
|
|
3955
|
+
split: true,
|
|
3956
|
+
mode: 'lowest'
|
|
3957
|
+
});
|
|
3958
|
+
if (upListItem && Node.get(editor, upListItem).type === ElementKinds.listItem) {
|
|
3959
|
+
Transforms.moveNodes(editor, {
|
|
3960
|
+
at: editor.selection,
|
|
3961
|
+
to: Path.next(upListItem),
|
|
3962
|
+
match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem
|
|
3963
|
+
});
|
|
3964
|
+
}
|
|
3965
|
+
else {
|
|
3966
|
+
Transforms.unwrapNodes(editor, {
|
|
3967
|
+
match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem
|
|
3968
|
+
});
|
|
3969
|
+
}
|
|
3970
|
+
return;
|
|
3971
|
+
}
|
|
3972
|
+
// 跨级、同级且类型不同
|
|
3973
|
+
if (activeListNode && types.includes(activeListNode.type)) {
|
|
3974
|
+
Transforms.setNodes(editor, { type }, { match: node => Element$1.isElement(node) && node.type !== type && types.includes(node.type) });
|
|
3975
|
+
return;
|
|
3976
|
+
}
|
|
3977
|
+
// wrap
|
|
3978
|
+
this.buildListItem(editor);
|
|
3979
|
+
// Todo: types
|
|
3980
|
+
Transforms.wrapNodes(editor, { type, children: [], start: startIndex }, {
|
|
3981
|
+
at: editor.selection,
|
|
3982
|
+
match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem
|
|
3983
|
+
});
|
|
3984
|
+
});
|
|
3985
|
+
},
|
|
3986
|
+
unwrapList(editor) {
|
|
3987
|
+
Editor.withoutNormalizing(editor, () => {
|
|
3988
|
+
unwrapNodesByType(editor, [ElementKinds.bulletedList, ElementKinds.numberedList], { split: true, mode: 'all' });
|
|
3989
|
+
unwrapNodesByType(editor, [ElementKinds.listItem], { split: true, mode: 'all' });
|
|
3990
|
+
});
|
|
3991
|
+
},
|
|
3992
|
+
wrapList(editor, type) {
|
|
3993
|
+
Editor.withoutNormalizing(editor, () => {
|
|
3994
|
+
const listItem = {
|
|
3995
|
+
type: ElementKinds.listItem,
|
|
3996
|
+
children: []
|
|
3997
|
+
};
|
|
3998
|
+
const list = {
|
|
3999
|
+
type,
|
|
4000
|
+
children: []
|
|
4001
|
+
};
|
|
4002
|
+
Transforms.wrapNodes(editor, list, { split: true });
|
|
4003
|
+
Transforms.wrapNodes(editor, listItem, { split: true });
|
|
4004
|
+
});
|
|
4005
|
+
},
|
|
4006
|
+
isActive(editor, type) {
|
|
4007
|
+
const [match] = getNodesByType(editor, type);
|
|
4008
|
+
return !!match;
|
|
4009
|
+
},
|
|
4010
|
+
getActiveList(editor) {
|
|
4011
|
+
const [match] = getNodesByType(editor, LIST_BLOCK_TYPES);
|
|
4012
|
+
return match;
|
|
4013
|
+
},
|
|
4014
|
+
buildListItem(editor) {
|
|
4015
|
+
const nodes = Editor.nodes(editor, {
|
|
4016
|
+
match: node => Editor.isBlock(editor, node),
|
|
4017
|
+
mode: 'lowest'
|
|
4018
|
+
});
|
|
4019
|
+
for (const [node, path] of nodes) {
|
|
4020
|
+
if (!Editor.isVoid(editor, node) && Element$1.isElement(node) && node.type !== ElementKinds.paragraph) {
|
|
4021
|
+
Transforms.setNodes(editor, { type: ElementKinds.paragraph, checked: undefined }, // todo remove checked
|
|
4022
|
+
{ at: path });
|
|
4023
|
+
}
|
|
4024
|
+
else if (Element$1.isElement(node) && node.type === ElementKinds.paragraph) {
|
|
4025
|
+
let { textIndent } = node;
|
|
4026
|
+
if (textIndent) {
|
|
4027
|
+
Transforms.setNodes(editor, { textIndent: undefined, indent: undefined }, // remove indent
|
|
4028
|
+
{ at: path });
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
if (Node.parent(editor, path).type !== ElementKinds.listItem) {
|
|
4032
|
+
Transforms.wrapNodes(editor, { type: ElementKinds.listItem, children: [] }, {
|
|
4033
|
+
at: path,
|
|
4034
|
+
split: true
|
|
4035
|
+
});
|
|
4036
|
+
}
|
|
4037
|
+
}
|
|
4038
|
+
},
|
|
4039
|
+
buildInsertDataChildren(node) {
|
|
4040
|
+
const { children } = node;
|
|
4041
|
+
const listItem = children[0];
|
|
4042
|
+
if (isNodeTypeList(node) && Element$1.isElement(listItem) && listItem.children[0].type === ElementKinds.paragraph) {
|
|
4043
|
+
return node;
|
|
4044
|
+
}
|
|
4045
|
+
return this.buildInsertDataChildren(listItem);
|
|
4046
|
+
}
|
|
4047
|
+
};
|
|
4048
|
+
|
|
4049
|
+
const TodoItemEditor = {
|
|
4050
|
+
isActive(editor) {
|
|
4051
|
+
const [match] = getNodesByType(editor, ElementKinds.checkItem);
|
|
4052
|
+
return !!match;
|
|
4053
|
+
},
|
|
4054
|
+
insertTodoItem(editor) {
|
|
4055
|
+
if (!editor.selection) {
|
|
4056
|
+
return;
|
|
4057
|
+
}
|
|
4058
|
+
const isActive = this.isActive(editor);
|
|
4059
|
+
const isNumberedList = ListEditor.isActive(editor, ElementKinds.numberedList);
|
|
4060
|
+
const isBulletedList = ListEditor.isActive(editor, ElementKinds.bulletedList);
|
|
4061
|
+
if (isActive) {
|
|
4062
|
+
Transforms.setNodes(editor, {
|
|
4063
|
+
type: ElementKinds.paragraph
|
|
4064
|
+
});
|
|
4065
|
+
}
|
|
4066
|
+
else {
|
|
4067
|
+
if (isNumberedList || isBulletedList) {
|
|
4068
|
+
ListEditor.unwrapList(editor);
|
|
4069
|
+
}
|
|
4070
|
+
Transforms.setNodes(editor, {
|
|
4071
|
+
type: ElementKinds.checkItem
|
|
4072
|
+
});
|
|
4073
|
+
}
|
|
4074
|
+
}
|
|
4075
|
+
};
|
|
4076
|
+
|
|
4077
|
+
const BlockquoteEditor = {
|
|
4078
|
+
toggleBlockquote(editor) {
|
|
4079
|
+
if (!isParagraph(editor)) {
|
|
4080
|
+
Transforms.insertNodes(editor, {
|
|
4081
|
+
type: ElementKinds.paragraph,
|
|
4082
|
+
mode: 'text',
|
|
4083
|
+
children: [
|
|
4084
|
+
{
|
|
4085
|
+
text: ''
|
|
4086
|
+
}
|
|
4087
|
+
]
|
|
4088
|
+
});
|
|
4089
|
+
}
|
|
4090
|
+
const isActive = isBlockActive(editor, ElementKinds.blockquote);
|
|
4091
|
+
if (!isActive) {
|
|
4092
|
+
Transforms.wrapNodes(editor, { type: ElementKinds.blockquote, children: [] }, {
|
|
4093
|
+
mode: 'lowest'
|
|
4094
|
+
});
|
|
4095
|
+
}
|
|
4096
|
+
else {
|
|
4097
|
+
Transforms.unwrapNodes(editor, { match: n => Element$1.isElement(n) && n.type === ElementKinds.blockquote });
|
|
4098
|
+
}
|
|
4099
|
+
}
|
|
4100
|
+
};
|
|
4101
|
+
|
|
4102
|
+
const InlineCodeEditor = {
|
|
4103
|
+
toggleInlineCode(editor, text) {
|
|
4104
|
+
const isActive = InlineCodeEditor.isInlineCodeActive(editor);
|
|
4105
|
+
if (isActive) {
|
|
4106
|
+
InlineCodeEditor.unwrapInlineCode(editor);
|
|
4107
|
+
return;
|
|
4108
|
+
}
|
|
4109
|
+
if (Range.isCollapsed(editor.selection)) {
|
|
4110
|
+
InlineCodeEditor.wrapInlineCode(editor, text);
|
|
4111
|
+
}
|
|
4112
|
+
else {
|
|
4113
|
+
const fragment = Node.fragment(editor, editor.selection)[0];
|
|
4114
|
+
const selectNode = Node.get(fragment, []);
|
|
4115
|
+
const selectText = Node.string(selectNode);
|
|
4116
|
+
InlineCodeEditor.wrapInlineCode(editor, selectText);
|
|
4117
|
+
}
|
|
4118
|
+
},
|
|
4119
|
+
wrapInlineCode(editor, text = '') {
|
|
4120
|
+
if (InlineCodeEditor.isInlineCodeActive(editor)) {
|
|
4121
|
+
InlineCodeEditor.unwrapInlineCode(editor);
|
|
4122
|
+
}
|
|
4123
|
+
const { selection } = editor;
|
|
4124
|
+
const isCollapsed = selection && Range.isCollapsed(selection);
|
|
4125
|
+
const inlineCode = {
|
|
4126
|
+
type: ElementKinds.inlineCode,
|
|
4127
|
+
children: isCollapsed ? [{ text: text ? text : ZERO_WIDTH_CHAR }] : []
|
|
4128
|
+
};
|
|
4129
|
+
if (isCollapsed) {
|
|
4130
|
+
Transforms.insertNodes(editor, inlineCode);
|
|
4272
4131
|
}
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
});
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4132
|
+
else {
|
|
4133
|
+
Transforms.wrapNodes(editor, inlineCode, { split: true });
|
|
4134
|
+
}
|
|
4135
|
+
},
|
|
4136
|
+
unwrapInlineCode(editor) {
|
|
4137
|
+
Transforms.unwrapNodes(editor, { match: n => Element$1.isElement(n) && n.type === ElementKinds.inlineCode });
|
|
4138
|
+
},
|
|
4139
|
+
isInlineCodeActive(editor, path) {
|
|
4140
|
+
var _a;
|
|
4141
|
+
const [inlineCode] = Editor.nodes(editor, {
|
|
4142
|
+
at: path ? path : (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor.path,
|
|
4143
|
+
match: n => Element$1.isElement(n) && n.type === ElementKinds.inlineCode
|
|
4284
4144
|
});
|
|
4145
|
+
return !!inlineCode;
|
|
4285
4146
|
}
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4147
|
+
};
|
|
4148
|
+
|
|
4149
|
+
const HeadingEditor = {
|
|
4150
|
+
setHeading(editor, heading) {
|
|
4151
|
+
Editor.withoutNormalizing(editor, () => {
|
|
4152
|
+
const types = [ElementKinds.bulletedList, ElementKinds.numberedList, ElementKinds.listItem];
|
|
4153
|
+
Transforms.unwrapNodes(editor, {
|
|
4154
|
+
at: editor.selection,
|
|
4155
|
+
match: n => Element$1.isElement(n) && types.includes(n.type),
|
|
4156
|
+
mode: 'all',
|
|
4157
|
+
split: true
|
|
4158
|
+
});
|
|
4159
|
+
Transforms.setNodes(editor, { type: heading });
|
|
4160
|
+
const entry = anchorBlockEntry(editor);
|
|
4161
|
+
const unMarks = {
|
|
4162
|
+
[MarkTypes.fontSize]: null
|
|
4163
|
+
};
|
|
4164
|
+
if (entry) {
|
|
4165
|
+
setMarks(editor, unMarks, entry[1]);
|
|
4166
|
+
return;
|
|
4298
4167
|
}
|
|
4168
|
+
setMarks(editor, unMarks, editor.selection);
|
|
4299
4169
|
});
|
|
4300
|
-
}
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
Transforms.collapse(editor, { edge: 'end' });
|
|
4306
|
-
editor.removeMark(type, false);
|
|
4307
|
-
// delete start markup
|
|
4308
|
-
Transforms.delete(editor, {
|
|
4309
|
-
at: {
|
|
4310
|
-
anchor: startMarkupPointBefore,
|
|
4311
|
-
focus: startMarkupPointAfter
|
|
4312
|
-
}
|
|
4170
|
+
},
|
|
4171
|
+
isHeadingActive(editor, heading) {
|
|
4172
|
+
const [match] = Editor.nodes(editor, {
|
|
4173
|
+
match: n => Element$1.isElement(n) && n.type === heading,
|
|
4174
|
+
universal: true
|
|
4313
4175
|
});
|
|
4176
|
+
return !!match;
|
|
4314
4177
|
}
|
|
4315
|
-
return true;
|
|
4316
4178
|
};
|
|
4317
4179
|
|
|
4318
|
-
const
|
|
4180
|
+
const defaultAutoFormatRules = [
|
|
4181
|
+
{
|
|
4182
|
+
type: ElementKinds.heading_1,
|
|
4183
|
+
markup: '#',
|
|
4184
|
+
format: (editor) => {
|
|
4185
|
+
HeadingEditor.setHeading(editor, ElementKinds.heading_1);
|
|
4186
|
+
}
|
|
4187
|
+
},
|
|
4188
|
+
{
|
|
4189
|
+
type: ElementKinds.heading_2,
|
|
4190
|
+
markup: '##',
|
|
4191
|
+
format: (editor) => {
|
|
4192
|
+
HeadingEditor.setHeading(editor, ElementKinds.heading_2);
|
|
4193
|
+
}
|
|
4194
|
+
},
|
|
4195
|
+
{
|
|
4196
|
+
type: ElementKinds.heading_3,
|
|
4197
|
+
markup: '###',
|
|
4198
|
+
format: (editor) => {
|
|
4199
|
+
HeadingEditor.setHeading(editor, ElementKinds.heading_3);
|
|
4200
|
+
}
|
|
4201
|
+
},
|
|
4202
|
+
{
|
|
4203
|
+
type: ElementKinds.heading_4,
|
|
4204
|
+
markup: '####',
|
|
4205
|
+
format: (editor) => {
|
|
4206
|
+
HeadingEditor.setHeading(editor, ElementKinds.heading_4);
|
|
4207
|
+
}
|
|
4208
|
+
},
|
|
4209
|
+
{
|
|
4210
|
+
type: ElementKinds.heading_5,
|
|
4211
|
+
markup: '#####',
|
|
4212
|
+
format: (editor) => {
|
|
4213
|
+
HeadingEditor.setHeading(editor, ElementKinds.heading_5);
|
|
4214
|
+
}
|
|
4215
|
+
},
|
|
4216
|
+
{
|
|
4217
|
+
type: ElementKinds.heading_6,
|
|
4218
|
+
markup: '######',
|
|
4219
|
+
format: (editor) => {
|
|
4220
|
+
HeadingEditor.setHeading(editor, ElementKinds.heading_6);
|
|
4221
|
+
}
|
|
4222
|
+
},
|
|
4223
|
+
{
|
|
4224
|
+
type: ElementKinds.blockquote,
|
|
4225
|
+
markup: ['>'],
|
|
4226
|
+
format: (editor) => {
|
|
4227
|
+
BlockquoteEditor.toggleBlockquote(editor);
|
|
4228
|
+
}
|
|
4229
|
+
},
|
|
4230
|
+
{
|
|
4231
|
+
type: MarkTypes.bold,
|
|
4232
|
+
between: ['**', '**'],
|
|
4233
|
+
mode: 'inline',
|
|
4234
|
+
insertTrigger: true
|
|
4235
|
+
},
|
|
4236
|
+
{
|
|
4237
|
+
type: MarkTypes.bold,
|
|
4238
|
+
between: ['__', '__'],
|
|
4239
|
+
mode: 'inline',
|
|
4240
|
+
insertTrigger: true
|
|
4241
|
+
},
|
|
4242
|
+
{
|
|
4243
|
+
type: MarkTypes.italic,
|
|
4244
|
+
between: ['*', '*'],
|
|
4245
|
+
mode: 'inline',
|
|
4246
|
+
insertTrigger: true
|
|
4247
|
+
},
|
|
4248
|
+
{
|
|
4249
|
+
type: MarkTypes.italic,
|
|
4250
|
+
between: ['_', '_'],
|
|
4251
|
+
mode: 'inline',
|
|
4252
|
+
insertTrigger: true
|
|
4253
|
+
},
|
|
4254
|
+
{
|
|
4255
|
+
type: ElementKinds.inlineCode,
|
|
4256
|
+
between: ['`', '`'],
|
|
4257
|
+
mode: 'inline',
|
|
4258
|
+
format: (editor, text) => {
|
|
4259
|
+
InlineCodeEditor.toggleInlineCode(editor, text);
|
|
4260
|
+
Transforms.select(editor, Editor.after(editor, editor.selection));
|
|
4261
|
+
}
|
|
4262
|
+
},
|
|
4263
|
+
{
|
|
4264
|
+
type: MarkTypes.strike,
|
|
4265
|
+
between: ['~~', '~~'],
|
|
4266
|
+
mode: 'inline',
|
|
4267
|
+
insertTrigger: true
|
|
4268
|
+
},
|
|
4269
|
+
{
|
|
4270
|
+
type: ElementKinds.code,
|
|
4271
|
+
markup: '```',
|
|
4272
|
+
insertTrigger: true
|
|
4273
|
+
},
|
|
4274
|
+
{
|
|
4275
|
+
type: ElementKinds.listItem,
|
|
4276
|
+
markup: [],
|
|
4277
|
+
match: (editor) => {
|
|
4278
|
+
return isParagraph(editor) ? ['*', '-', '+'] : [];
|
|
4279
|
+
},
|
|
4280
|
+
format: (editor) => {
|
|
4281
|
+
ListEditor.toggleList(editor, ElementKinds.bulletedList);
|
|
4282
|
+
}
|
|
4283
|
+
},
|
|
4284
|
+
{
|
|
4285
|
+
type: ElementKinds.listItem,
|
|
4286
|
+
key: ElementKinds.numberedList,
|
|
4287
|
+
markup: [],
|
|
4288
|
+
match: (editor, textFromBlockStart) => {
|
|
4289
|
+
return isParagraph(editor) && /^-?\d+(\.|\))$/.test(textFromBlockStart) ? [textFromBlockStart] : [];
|
|
4290
|
+
},
|
|
4291
|
+
format: (editor, markup) => {
|
|
4292
|
+
let startIndex = 1;
|
|
4293
|
+
if (markup) {
|
|
4294
|
+
startIndex = markup[0].split('.')[0];
|
|
4295
|
+
if (startIndex === 0) {
|
|
4296
|
+
startIndex = 1;
|
|
4297
|
+
}
|
|
4298
|
+
}
|
|
4299
|
+
ListEditor.toggleList(editor, ElementKinds.numberedList, startIndex);
|
|
4300
|
+
}
|
|
4301
|
+
},
|
|
4302
|
+
{
|
|
4303
|
+
type: ElementKinds.checkItem,
|
|
4304
|
+
markup: [],
|
|
4305
|
+
match: (editor) => {
|
|
4306
|
+
return isParagraph(editor) ? ['[]'] : [];
|
|
4307
|
+
},
|
|
4308
|
+
format: (editor) => {
|
|
4309
|
+
TodoItemEditor.insertTodoItem(editor);
|
|
4310
|
+
}
|
|
4311
|
+
},
|
|
4312
|
+
{
|
|
4313
|
+
type: ElementKinds.hr,
|
|
4314
|
+
markup: '---',
|
|
4315
|
+
insertTrigger: true
|
|
4316
|
+
}
|
|
4317
|
+
];
|
|
4318
|
+
|
|
4319
|
+
const withAutoFormat = () => (editor) => {
|
|
4319
4320
|
const { insertText } = editor;
|
|
4320
4321
|
editor.insertText = text => {
|
|
4321
|
-
var _a;
|
|
4322
|
+
var _a, _b;
|
|
4323
|
+
let autoFormatRules = defaultAutoFormatRules;
|
|
4324
|
+
if ((_a = editor.extraAutoFormatRules) === null || _a === void 0 ? void 0 : _a.length) {
|
|
4325
|
+
const extraRules = mergAutoFormateRules(editor.extraAutoFormatRules);
|
|
4326
|
+
autoFormatRules = Object.values(extraRules);
|
|
4327
|
+
}
|
|
4322
4328
|
if (!isCollapsed(editor.selection)) {
|
|
4323
4329
|
return insertText(text);
|
|
4324
4330
|
}
|
|
4325
|
-
for (let
|
|
4326
|
-
const { query } =
|
|
4331
|
+
for (let _c of autoFormatRules) {
|
|
4332
|
+
const { query } = _c, rule = __rest(_c, ["query"]);
|
|
4327
4333
|
const { trigger = ' ', mode = 'block', type, markup, preFormat, format, match, between, ignoreTrim, insertTrigger, allowSameTypeAbove = false, triggerAtBlockStart = true } = rule;
|
|
4328
4334
|
if (query && !query(editor, rule))
|
|
4329
4335
|
continue;
|
|
@@ -4358,7 +4364,7 @@ const withAutoFormat = ({ rules }) => (editor) => {
|
|
|
4358
4364
|
});
|
|
4359
4365
|
if (!markupRange)
|
|
4360
4366
|
continue;
|
|
4361
|
-
const blockAbovePath = (
|
|
4367
|
+
const blockAbovePath = (_b = getBlockAbove(editor)) === null || _b === void 0 ? void 0 : _b[1];
|
|
4362
4368
|
if (!blockAbovePath)
|
|
4363
4369
|
continue;
|
|
4364
4370
|
// If the markup is not at the start, insert break before autoformatting.
|
|
@@ -4395,6 +4401,17 @@ const withAutoFormat = ({ rules }) => (editor) => {
|
|
|
4395
4401
|
};
|
|
4396
4402
|
return editor;
|
|
4397
4403
|
};
|
|
4404
|
+
const mergAutoFormateRules = (extraAutoFormatRules) => {
|
|
4405
|
+
const combinationData = [...defaultAutoFormatRules, ...extraAutoFormatRules];
|
|
4406
|
+
const dataInfo = {};
|
|
4407
|
+
combinationData.forEach(item => {
|
|
4408
|
+
if (!dataInfo[item.type + item.key]) {
|
|
4409
|
+
dataInfo[item.type + item.key] = Object.assign({}, item);
|
|
4410
|
+
}
|
|
4411
|
+
dataInfo[item.type + item.key] = Object.assign(Object.assign({}, dataInfo[item.type + item.key]), item);
|
|
4412
|
+
});
|
|
4413
|
+
return dataInfo;
|
|
4414
|
+
};
|
|
4398
4415
|
|
|
4399
4416
|
const withTransforms = () => (editor) => {
|
|
4400
4417
|
const e = editor;
|
|
@@ -11891,7 +11908,7 @@ const internalPlugins = [
|
|
|
11891
11908
|
}),
|
|
11892
11909
|
withBlockquote,
|
|
11893
11910
|
withNodeID({ idKey: ELEMENT_UNIQUE_ID, idCreator }),
|
|
11894
|
-
withAutoFormat(
|
|
11911
|
+
withAutoFormat(),
|
|
11895
11912
|
withTransforms(),
|
|
11896
11913
|
withTrailingNode({ type: ElementKinds.paragraph, level: 0 }),
|
|
11897
11914
|
withMoveSelection,
|
|
@@ -12756,11 +12773,12 @@ class TheEditorComponent extends mixinUnsubscribe(MixinBase) {
|
|
|
12756
12773
|
super.ngOnDestroy();
|
|
12757
12774
|
}
|
|
12758
12775
|
initialize() {
|
|
12759
|
-
var _a, _b;
|
|
12776
|
+
var _a, _b, _c;
|
|
12760
12777
|
this.editor = withTheEditor(this.thePlugins, withHistory(withAngular(createEditor(), CLIPBOARD_FORMAT_KEY)));
|
|
12761
12778
|
this.generateDecorate();
|
|
12762
12779
|
this.editor.disabled = (_a = this.theOptions) === null || _a === void 0 ? void 0 : _a.disabled;
|
|
12763
12780
|
this.editor.extraElementOptions = (_b = this.theOptions) === null || _b === void 0 ? void 0 : _b.extraElementOptions;
|
|
12781
|
+
this.editor.extraAutoFormatRules = (_c = this.theOptions) === null || _c === void 0 ? void 0 : _c.extraAutoFormatRules;
|
|
12764
12782
|
setEditorUUID(this.editor, idCreator());
|
|
12765
12783
|
this.theContextService.initialize({
|
|
12766
12784
|
theOptions: this.theOptions,
|