@worktile/theia 2.4.1 → 2.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/bundles/worktile-theia.umd.js +1117 -1034
  2. package/bundles/worktile-theia.umd.js.map +1 -1
  3. package/constants/auto-format-rules.d.ts +1 -1
  4. package/editor.module.d.ts +2 -1
  5. package/esm2015/constants/auto-format-rules.js +3 -2
  6. package/esm2015/editor.component.js +5 -2
  7. package/esm2015/interfaces/auto-format.js +1 -1
  8. package/esm2015/interfaces/editor.js +1 -1
  9. package/esm2015/plugins/autoformat/autoformat.plugin.js +23 -6
  10. package/esm2015/plugins/indent/indent.editor.js +11 -13
  11. package/esm2015/plugins/indent/indent.plugin.js +15 -2
  12. package/esm2015/plugins/indent/on-keydown-indent.js +3 -5
  13. package/esm2015/plugins/index.js +2 -3
  14. package/esm2015/plugins/quick-insert/components/quick-insert.component.js +6 -2
  15. package/esm2015/plugins/quick-insert/components/quick-toolbar/quick-toolbar.component.js +14 -15
  16. package/esm2015/plugins/quick-insert/quick-insert.editor.js +18 -27
  17. package/esm2015/plugins/quick-insert/quick-insert.plugin.js +33 -15
  18. package/esm2015/plugins/table/components/insert-mark/insert-mark.component.js +4 -4
  19. package/esm2015/plugins/table/components/table.component.js +2 -2
  20. package/esm2015/plugins/table/components/td/td.component.js +5 -7
  21. package/esm2015/plugins/table/table.service.js +6 -6
  22. package/esm2015/plugins/todo-item/todo-item.component.js +15 -7
  23. package/esm2015/transforms/index.js +3 -2
  24. package/esm2015/transforms/insert-element-next.js +1 -1
  25. package/esm2015/transforms/insert-element-node.js +36 -0
  26. package/esm2015/utils/is-clean-empty-paragraph.js +4 -1
  27. package/fesm2015/worktile-theia.js +1054 -969
  28. package/fesm2015/worktile-theia.js.map +1 -1
  29. package/interfaces/auto-format.d.ts +1 -0
  30. package/interfaces/editor.d.ts +14 -1
  31. package/package.json +1 -1
  32. package/plugins/autoformat/autoformat.plugin.d.ts +1 -2
  33. package/plugins/indent/indent.plugin.d.ts +1 -0
  34. package/plugins/indent/on-keydown-indent.d.ts +1 -1
  35. package/plugins/quick-insert/components/quick-toolbar/quick-toolbar.component.d.ts +3 -4
  36. package/plugins/quick-insert/quick-insert.editor.d.ts +3 -4
  37. package/plugins/quick-insert/quick-insert.plugin.d.ts +2 -0
  38. package/plugins/table/components/table.component.scss +43 -42
  39. package/plugins/todo-item/todo-item.component.d.ts +3 -1
  40. package/transforms/index.d.ts +2 -1
  41. package/transforms/insert-element-node.d.ts +2 -0
  42. package/utils/is-clean-empty-paragraph.d.ts +2 -1
@@ -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, Editor, Range, Node, Span, Path, Text, Point, Transforms, Operation, createEditor } from 'slate';
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';
@@ -54,7 +54,7 @@ import { ThySharedModule } from 'ngx-tethys/shared';
54
54
  import * as i1$6 from 'ngx-tethys';
55
55
  import { coerceCssPixelValue } from '@angular/cdk/coercion';
56
56
  import { PortalInjector, ComponentPortal } from '@angular/cdk/portal';
57
- import * as i2$3 from 'ngx-tethys/list';
57
+ import * as i1$7 from 'ngx-tethys/list';
58
58
  import { ThyListModule } from 'ngx-tethys/list';
59
59
  import { ThyAutocompleteModule } from 'ngx-tethys/autocomplete';
60
60
  import { ThyAvatarModule } from 'ngx-tethys/avatar';
@@ -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);
@@ -1564,6 +1589,40 @@ function handleContinualInsertBreak(editor, lowestBlock, type) {
1564
1589
  return false;
1565
1590
  }
1566
1591
 
1592
+ const insertElementNode = (editor, node) => {
1593
+ if (Range.isExpanded(editor.selection)) {
1594
+ Editor.deleteFragment(editor);
1595
+ }
1596
+ const isBlockCardCursor$1 = isBlockCardCursor(editor);
1597
+ const containerBlocks = getContainerBlocks(editor);
1598
+ const isContainer = isNodeTypeIn(editor, containerBlocks, { at: editor.selection });
1599
+ const [anchorBlock, anchorBlockPath] = anchorBlockEntry(editor);
1600
+ const isEmpty = Editor.isEmpty(editor, anchorBlock);
1601
+ if (isContainer && !isBlockCardCursor$1) {
1602
+ const [, containerPath] = Editor.above(editor, {
1603
+ match: n => Editor.isBlock(editor, n) && containerBlocks.includes(n.type),
1604
+ at: editor.selection
1605
+ });
1606
+ Editor.withoutNormalizing(editor, () => {
1607
+ const containerPathFirstPath = anchorBlockPath.slice(0, containerPath.length + 1);
1608
+ Transforms.insertNodes(editor, node, { at: Path.next(containerPathFirstPath), select: true });
1609
+ if (isEmpty) {
1610
+ Transforms.removeNodes(editor, { at: anchorBlockPath });
1611
+ }
1612
+ });
1613
+ return;
1614
+ }
1615
+ const nextPath = Path.next([anchorBlockPath[0]]);
1616
+ Transforms.insertNodes(editor, node, { at: nextPath });
1617
+ if (isEmpty && anchorBlockPath.length === 1) {
1618
+ Transforms.delete(editor, { at: anchorBlockPath });
1619
+ Transforms.select(editor, Editor.start(editor, anchorBlockPath));
1620
+ }
1621
+ else {
1622
+ Transforms.select(editor, Editor.start(editor, nextPath));
1623
+ }
1624
+ };
1625
+
1567
1626
  var index = /*#__PURE__*/Object.freeze({
1568
1627
  __proto__: null,
1569
1628
  setMarks: setMarks,
@@ -1583,442 +1642,23 @@ var index = /*#__PURE__*/Object.freeze({
1583
1642
  setEndSelection: setEndSelection,
1584
1643
  closeConversionHint: closeConversionHint,
1585
1644
  handleContinualDeleteBackward: handleContinualDeleteBackward,
1586
- handleContinualInsertBreak: handleContinualInsertBreak
1645
+ handleContinualInsertBreak: handleContinualInsertBreak,
1646
+ insertElementNode: insertElementNode
1587
1647
  });
1588
1648
 
1589
- const isNodeTypeList = (n) => {
1590
- return [ElementKinds.bulletedList, ElementKinds.numberedList].includes(n.type);
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;
1649
+ class TheConversionHintComponent {
1650
+ constructor() {
1651
+ this.duration = 10000;
1652
+ this.pauseOnHover = true;
1653
+ }
1654
+ mouseenter() {
1655
+ if (this.pauseOnHover) {
1656
+ this.clearCloseTimer();
1710
1657
  }
1711
- return this.buildInsertDataChildren(listItem);
1712
1658
  }
1713
- };
1714
-
1715
- const TodoItemEditor = {
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
- });
1731
- }
1732
- else {
1733
- if (isNumberedList || isBulletedList) {
1734
- ListEditor.unwrapList(editor);
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();
1659
+ mouseleave() {
1660
+ if (this.pauseOnHover) {
1661
+ this.creatCloseTimer();
2022
1662
  }
2023
1663
  }
2024
1664
  ngOnInit() {
@@ -2132,6 +1772,9 @@ const isCleanEmptyParagraph = (editor) => {
2132
1772
  return false;
2133
1773
  }
2134
1774
  const block = Node.ancestor(editor, [editor.selection.anchor.path[0]]);
1775
+ return isPureEmptyParagraph(editor, block);
1776
+ };
1777
+ const isPureEmptyParagraph = (editor, block) => {
2135
1778
  const textIndent = 'textIndent';
2136
1779
  const align = 'align';
2137
1780
  const hasTextIndent = block[textIndent];
@@ -3053,6 +2696,10 @@ const hasStableListItem = (listItemNode) => {
3053
2696
  return listItemNode.children.length === 1 && type === ElementKinds.paragraph;
3054
2697
  };
3055
2698
 
2699
+ const isNodeTypeList = (n) => {
2700
+ return [ElementKinds.bulletedList, ElementKinds.numberedList].includes(n.type);
2701
+ };
2702
+
3056
2703
  /**
3057
2704
  * list 中 是否是单个listItem,且listItem没有子列表
3058
2705
  */
@@ -3898,432 +3545,835 @@ const withList = ({ validLiChildrenTypes } = {}) => (editor) => {
3898
3545
  return;
3899
3546
  }
3900
3547
  }
3901
- insertData(data);
3548
+ insertData(data);
3549
+ };
3550
+ editor.onKeydown = (event) => {
3551
+ const isContinue = !onKeyDownList(event, editor);
3552
+ if (isContinue) {
3553
+ onKeydown(event);
3554
+ }
3555
+ };
3556
+ editor.normalizeNode = getListNormalizer(editor, { validLiChildrenTypes: validLiChildrenTypes });
3557
+ editor.renderElement = (element) => {
3558
+ if (element.type === ElementKinds.numberedList) {
3559
+ return TheNumberedListComponent;
3560
+ }
3561
+ if (element.type === ElementKinds.bulletedList) {
3562
+ return TheBulletedListComponent;
3563
+ }
3564
+ if (element.type === ElementKinds.listItem) {
3565
+ return TheListItemComponent;
3566
+ }
3567
+ return renderElement(element);
3568
+ };
3569
+ return editor;
3570
+ };
3571
+
3572
+ class TheTodoItemComponent extends TheBaseElementComponent {
3573
+ constructor(elementRef, cdr, ctxService) {
3574
+ super(elementRef, cdr);
3575
+ this.elementRef = elementRef;
3576
+ this.cdr = cdr;
3577
+ this.ctxService = ctxService;
3578
+ this.checkItemClass = true;
3579
+ }
3580
+ get level() {
3581
+ var _a;
3582
+ return (_a = this.element) === null || _a === void 0 ? void 0 : _a.indent;
3583
+ }
3584
+ ngOnInit() {
3585
+ super.ngOnInit();
3586
+ }
3587
+ onCheck(checked) {
3588
+ const options = this.ctxService.getTheOptions();
3589
+ const noBindReadonly = options.noBindReadonlyPlugins && options.noBindReadonlyPlugins.includes(ElementKinds.checkItem);
3590
+ if (!noBindReadonly && this.readonly) {
3591
+ return false;
3592
+ }
3593
+ else {
3594
+ setNode(this.editor, { checked }, this.element);
3595
+ }
3596
+ setNode(this.editor, { checked }, this.element);
3597
+ }
3598
+ }
3599
+ TheTodoItemComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheTodoItemComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: TheContextService }], target: i0.ɵɵFactoryTarget.Component });
3600
+ TheTodoItemComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.15", type: TheTodoItemComponent, selector: "div[theTodoItem]", host: { properties: { "class.the-check-item": "this.checkItemClass", "attr.the-level": "this.level" } }, usesInheritance: true, ngImport: i0, template: `
3601
+ <span contenteditable="false" class="todo-item-status">
3602
+ <input #checkbox type="checkbox" [checked]="element.checked" (click)="onCheck(checkbox.checked)" />
3603
+ </span>
3604
+ <span><slate-children [children]="children" [context]="childrenContext" [viewContext]="viewContext"></slate-children></span>
3605
+ `, isInline: true, components: [{ type: i1.SlateChildrenComponent, selector: "slate-children", inputs: ["children", "context", "viewContext"] }] });
3606
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheTodoItemComponent, decorators: [{
3607
+ type: Component,
3608
+ args: [{
3609
+ selector: 'div[theTodoItem]',
3610
+ template: `
3611
+ <span contenteditable="false" class="todo-item-status">
3612
+ <input #checkbox type="checkbox" [checked]="element.checked" (click)="onCheck(checkbox.checked)" />
3613
+ </span>
3614
+ <span><slate-children [children]="children" [context]="childrenContext" [viewContext]="viewContext"></slate-children></span>
3615
+ `
3616
+ }]
3617
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }, { type: TheContextService }]; }, propDecorators: { checkItemClass: [{
3618
+ type: HostBinding,
3619
+ args: ['class.the-check-item']
3620
+ }], level: [{
3621
+ type: HostBinding,
3622
+ args: ['attr.the-level']
3623
+ }] } });
3624
+
3625
+ const withTodoItem = (editor) => {
3626
+ const { insertBreak, deleteBackward, renderElement } = editor;
3627
+ editor.insertBreak = () => {
3628
+ const { selection } = editor;
3629
+ if (selection && Range.isCollapsed(selection)) {
3630
+ const [match] = Editor.nodes(editor, {
3631
+ match: n => Element$1.isElement(n) && n.type === ElementKinds.checkItem
3632
+ });
3633
+ if (match) {
3634
+ const [, path] = match;
3635
+ const block = anchorBlock(editor);
3636
+ if (block && Editor.isStart(editor, selection.anchor, path) && Editor.isEmpty(editor, block)) {
3637
+ Transforms.setNodes(editor, {
3638
+ type: ElementKinds.default,
3639
+ checked: undefined
3640
+ }, {
3641
+ match: n => Element$1.isElement(n) && n.type === ElementKinds.checkItem
3642
+ });
3643
+ return;
3644
+ }
3645
+ }
3646
+ }
3647
+ insertBreak();
3648
+ const anchorBlock$1 = anchorBlock(editor);
3649
+ if (anchorBlock$1 && anchorBlock$1.type === ElementKinds.checkItem) {
3650
+ Transforms.setNodes(editor, { checked: false });
3651
+ }
3652
+ };
3653
+ editor.deleteBackward = unit => {
3654
+ const { selection } = editor;
3655
+ if (selection && Range.isCollapsed(selection)) {
3656
+ const [match] = Editor.nodes(editor, {
3657
+ match: n => Element$1.isElement(n) && n.type === ElementKinds.checkItem
3658
+ });
3659
+ if (match) {
3660
+ const [, path] = match;
3661
+ if (Editor.isStart(editor, selection.anchor, path)) {
3662
+ Transforms.setNodes(editor, { type: ElementKinds.default, checked: undefined }, {
3663
+ match: n => Element$1.isElement(n) && n.type === ElementKinds.checkItem
3664
+ });
3665
+ return;
3666
+ }
3667
+ }
3668
+ }
3669
+ deleteBackward(unit);
3670
+ };
3671
+ editor.renderElement = (element) => {
3672
+ if (element.type === ElementKinds.checkItem) {
3673
+ return TheTodoItemComponent;
3674
+ }
3675
+ return renderElement(element);
3676
+ };
3677
+ return editor;
3678
+ };
3679
+
3680
+ class TheHrComponent extends TheBaseElementComponent {
3681
+ constructor(elementRef, cdr) {
3682
+ super(elementRef, cdr);
3683
+ this.elementRef = elementRef;
3684
+ this.cdr = cdr;
3685
+ }
3686
+ ngAfterViewInit() {
3687
+ setTimeout(() => {
3688
+ const blockCardElement = this.nativeElement.closest('slate-block-card');
3689
+ if (blockCardElement) {
3690
+ blockCardElement.classList.add(`slate-block-card-${this.element.type}`);
3691
+ }
3692
+ });
3693
+ }
3694
+ }
3695
+ TheHrComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheHrComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
3696
+ TheHrComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.15", type: TheHrComponent, selector: "the-hr, [theHr]", usesInheritance: true, ngImport: i0, template: `
3697
+ <div class="the-hr" contenteditable="false" [ngClass]="{ active: selection }">
3698
+ <hr class="the-hr" />
3699
+ <slate-children [children]="children" [context]="childrenContext" [viewContext]="viewContext"></slate-children>
3700
+ </div>
3701
+ `, isInline: true, components: [{ type: i1.SlateChildrenComponent, selector: "slate-children", inputs: ["children", "context", "viewContext"] }], directives: [{ type: i10.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }] });
3702
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheHrComponent, decorators: [{
3703
+ type: Component,
3704
+ args: [{
3705
+ selector: 'the-hr, [theHr]',
3706
+ template: `
3707
+ <div class="the-hr" contenteditable="false" [ngClass]="{ active: selection }">
3708
+ <hr class="the-hr" />
3709
+ <slate-children [children]="children" [context]="childrenContext" [viewContext]="viewContext"></slate-children>
3710
+ </div>
3711
+ `
3712
+ }]
3713
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; } });
3714
+
3715
+ const withHr = (editor) => {
3716
+ const { isVoid, isBlockCard, renderElement } = editor;
3717
+ editor.isVoid = (element) => {
3718
+ return element.type === ElementKinds.hr || isVoid(element);
3719
+ };
3720
+ editor.isBlockCard = (element) => {
3721
+ if (element.type === ElementKinds.hr) {
3722
+ return true;
3723
+ }
3724
+ return isBlockCard(element);
3725
+ };
3726
+ editor.renderElement = (element) => {
3727
+ if (element.type === ElementKinds.hr) {
3728
+ return TheHrComponent;
3729
+ }
3730
+ return renderElement(element);
3731
+ };
3732
+ return editor;
3733
+ };
3734
+
3735
+ const withAlign = (editor) => {
3736
+ const { deleteBackward } = editor;
3737
+ editor.deleteBackward = unit => {
3738
+ const { anchor } = editor.selection;
3739
+ const node = anchorBlock(editor);
3740
+ const isVoid = Editor.isVoid(editor, node);
3741
+ const alignTypes = [Alignment.center, Alignment.right];
3742
+ const startLine = Editor.start(editor, anchor.path);
3743
+ const startLineRange = { anchor, focus: startLine };
3744
+ const beforeText = Editor.string(editor, startLineRange);
3745
+ if (!isVoid && node && node.align && alignTypes.includes(node.align) && beforeText === '') {
3746
+ const align = alignTypes.indexOf(node.align) ? Alignment.center : undefined;
3747
+ return Transforms.setNodes(editor, { align });
3748
+ }
3749
+ deleteBackward(unit);
3750
+ };
3751
+ return editor;
3752
+ };
3753
+
3754
+ const withHeading = (editor) => {
3755
+ const { insertBreak } = editor;
3756
+ editor.insertBreak = () => {
3757
+ const { selection } = editor;
3758
+ const anchorBlock = getAnchorBlockEntry(editor);
3759
+ if (anchorBlock && Range.isCollapsed(selection) && anchorBlock[0].type.startsWith('heading')) {
3760
+ if (Editor.isStart(editor, selection.anchor, anchorBlock[1])) {
3761
+ insertBreak();
3762
+ Transforms.setNodes(editor, { type: ElementKinds.paragraph }, {
3763
+ at: selection
3764
+ });
3765
+ return;
3766
+ }
3767
+ if (Editor.isEnd(editor, selection.focus, anchorBlock[1])) {
3768
+ insertBreak();
3769
+ Transforms.setNodes(editor, { type: ElementKinds.paragraph });
3770
+ return;
3771
+ }
3772
+ }
3773
+ insertBreak();
3774
+ };
3775
+ return editor;
3776
+ };
3777
+
3778
+ const withMark = () => (editor) => {
3779
+ const e = editor;
3780
+ e.removeMark = (key, shouldChange = true) => {
3781
+ const { selection } = e;
3782
+ if (selection) {
3783
+ if (Range.isExpanded(selection)) {
3784
+ Transforms.unsetNodes(e, key, {
3785
+ match: Text.isText,
3786
+ split: true
3787
+ });
3788
+ }
3789
+ else {
3790
+ const marks = Object.assign({}, (Editor.marks(e) || {}));
3791
+ delete marks[key];
3792
+ editor.marks = marks;
3793
+ const text = Editor.string(e, selection.anchor.path);
3794
+ if (text !== '') {
3795
+ Editor.setNormalizing(editor, false);
3796
+ e.insertText('');
3797
+ editor.marks = marks;
3798
+ Editor.setNormalizing(editor, true);
3799
+ }
3800
+ else {
3801
+ Transforms.unsetNodes(e, key, { at: selection.anchor.path });
3802
+ }
3803
+ if (shouldChange) {
3804
+ editor.onChange();
3805
+ }
3806
+ }
3807
+ }
3902
3808
  };
3903
- editor.onKeydown = (event) => {
3904
- const isContinue = !onKeyDownList(event, editor);
3905
- if (isContinue) {
3906
- onKeydown(event);
3809
+ e.addMark = (key, value) => {
3810
+ const { selection } = editor;
3811
+ if (selection) {
3812
+ if (Range.isExpanded(selection)) {
3813
+ Transforms.setNodes(e, { [key]: value }, { match: Text.isText, split: true });
3814
+ }
3815
+ else {
3816
+ const marks = Object.assign(Object.assign({}, (Editor.marks(e) || {})), { [key]: value });
3817
+ editor.marks = marks;
3818
+ const text = Editor.string(e, selection.anchor.path);
3819
+ if (text !== '') {
3820
+ Editor.setNormalizing(editor, false);
3821
+ e.insertText('');
3822
+ editor.marks = marks;
3823
+ Editor.setNormalizing(editor, true);
3824
+ }
3825
+ else {
3826
+ Transforms.setNodes(e, { [key]: value }, { at: selection.anchor.path });
3827
+ }
3828
+ }
3907
3829
  }
3908
3830
  };
3909
- editor.normalizeNode = getListNormalizer(editor, { validLiChildrenTypes: validLiChildrenTypes });
3910
- editor.renderElement = (element) => {
3911
- if (element.type === ElementKinds.numberedList) {
3912
- return TheNumberedListComponent;
3831
+ return e;
3832
+ };
3833
+
3834
+ const withNodeID = ({ idKey = 'id', idCreator = () => Date.now(), filterText = true, filter = () => true } = {}) => (e) => {
3835
+ const editor = e;
3836
+ const { apply, getFragment } = editor;
3837
+ const idPropsCreator = () => ({ [idKey]: idCreator() });
3838
+ editor.removedIDs = new Set();
3839
+ editor.apply = (operation) => {
3840
+ if (operation.type === 'insert_node') {
3841
+ const newFilter = (entry) => {
3842
+ const [_node] = entry;
3843
+ return filter(entry) && filterText ? Element$1.isElement(_node) : isDescendant(_node);
3844
+ };
3845
+ // fix can not find path by orign node
3846
+ let node = operation.node;
3847
+ if (!Object.isExtensible(node)) {
3848
+ node = _.cloneDeep(node);
3849
+ }
3850
+ // it will not overwrite ids once it's set as it's read-only
3851
+ mergeDeepToNodes({
3852
+ node,
3853
+ source: idPropsCreator,
3854
+ query: {
3855
+ filter: newFilter,
3856
+ }
3857
+ });
3858
+ return apply(Object.assign(Object.assign({}, operation), { node }));
3913
3859
  }
3914
- if (element.type === ElementKinds.bulletedList) {
3915
- return TheBulletedListComponent;
3860
+ if (operation.type === 'split_node' && (!filterText || operation.properties.type)) {
3861
+ let id = operation.properties[idKey];
3862
+ if (editor.removedIDs.has(id)) {
3863
+ editor.removedIDs.delete(id);
3864
+ }
3865
+ else {
3866
+ id = idCreator();
3867
+ }
3868
+ return apply(Object.assign(Object.assign({}, operation), { properties: Object.assign(Object.assign({}, operation.properties), { [idKey]: id }) }));
3916
3869
  }
3917
- if (element.type === ElementKinds.listItem) {
3918
- return TheListItemComponent;
3870
+ if (operation.type === 'merge_node' && (!filterText || operation.properties.type)) {
3871
+ editor.removedIDs.add(operation.properties[idKey]);
3919
3872
  }
3920
- return renderElement(element);
3873
+ return apply(operation);
3874
+ };
3875
+ editor.getFragment = () => {
3876
+ const fragment = _.cloneDeep(getFragment());
3877
+ return deleteElementKey(fragment, idKey);
3921
3878
  };
3922
3879
  return editor;
3923
3880
  };
3924
3881
 
3925
- class TheTodoItemComponent extends TheBaseElementComponent {
3926
- constructor(elementRef, cdr) {
3927
- super(elementRef, cdr);
3928
- this.elementRef = elementRef;
3929
- this.cdr = cdr;
3930
- this.checkItemClass = true;
3882
+ const autoFormatBlock = (editor, type, at, { preFormat, format }, markups) => {
3883
+ Transforms.delete(editor, { at });
3884
+ if (preFormat) {
3885
+ preFormat(editor);
3931
3886
  }
3932
- get level() {
3933
- var _a;
3934
- return (_a = this.element) === null || _a === void 0 ? void 0 : _a.indent;
3887
+ if (!format) {
3888
+ Transforms.setNodes(editor, { type }, { match: n => Editor.isBlock(editor, n) });
3935
3889
  }
3936
- ngOnInit() {
3937
- super.ngOnInit();
3890
+ else {
3891
+ format(editor, markups);
3938
3892
  }
3939
- onCheck(checked) {
3940
- if (this.readonly) {
3893
+ };
3894
+
3895
+ const autoFormatInline = (editor, { type, between, markup, ignoreTrim, format }) => {
3896
+ const selection = editor.selection;
3897
+ const startMarkup = between ? between[0] : markup;
3898
+ const endMarkup = between ? between[1] : '';
3899
+ let endMarkupPointBefore = selection.anchor;
3900
+ if (endMarkup) {
3901
+ endMarkupPointBefore = getPointBefore(editor, selection, {
3902
+ matchString: endMarkup
3903
+ });
3904
+ if (!endMarkupPointBefore) {
3941
3905
  return false;
3942
3906
  }
3943
- setNode(this.editor, { checked }, this.element);
3944
3907
  }
3945
- }
3946
- TheTodoItemComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheTodoItemComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
3947
- TheTodoItemComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.15", type: TheTodoItemComponent, selector: "div[theTodoItem]", host: { properties: { "class.the-check-item": "this.checkItemClass", "attr.the-level": "this.level" } }, usesInheritance: true, ngImport: i0, template: `
3948
- <span contenteditable="false" class="todo-item-status">
3949
- <input #checkbox type="checkbox" [checked]="element.checked" (click)="onCheck(checkbox.checked)" />
3950
- </span>
3951
- <span><slate-children [children]="children" [context]="childrenContext" [viewContext]="viewContext"></slate-children></span>
3952
- `, isInline: true, components: [{ type: i1.SlateChildrenComponent, selector: "slate-children", inputs: ["children", "context", "viewContext"] }] });
3953
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheTodoItemComponent, decorators: [{
3954
- type: Component,
3955
- args: [{
3956
- selector: 'div[theTodoItem]',
3957
- template: `
3958
- <span contenteditable="false" class="todo-item-status">
3959
- <input #checkbox type="checkbox" [checked]="element.checked" (click)="onCheck(checkbox.checked)" />
3960
- </span>
3961
- <span><slate-children [children]="children" [context]="childrenContext" [viewContext]="viewContext"></slate-children></span>
3962
- `
3963
- }]
3964
- }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { checkItemClass: [{
3965
- type: HostBinding,
3966
- args: ['class.the-check-item']
3967
- }], level: [{
3968
- type: HostBinding,
3969
- args: ['attr.the-level']
3970
- }] } });
3971
-
3972
- const withTodoItem = (editor) => {
3973
- const { insertBreak, deleteBackward, renderElement } = editor;
3974
- editor.insertBreak = () => {
3975
- const { selection } = editor;
3976
- if (selection && Range.isCollapsed(selection)) {
3977
- const [match] = Editor.nodes(editor, {
3978
- match: n => Element$1.isElement(n) && n.type === ElementKinds.checkItem
3979
- });
3980
- if (match) {
3981
- const [, path] = match;
3982
- const block = anchorBlock(editor);
3983
- if (block && Editor.isStart(editor, selection.anchor, path) && Editor.isEmpty(editor, block)) {
3984
- Transforms.setNodes(editor, {
3985
- type: ElementKinds.default,
3986
- checked: undefined
3987
- }, {
3988
- match: n => Element$1.isElement(n) && n.type === ElementKinds.checkItem
3989
- });
3990
- return;
3991
- }
3992
- }
3993
- }
3994
- insertBreak();
3995
- const anchorBlock$1 = anchorBlock(editor);
3996
- if (anchorBlock$1 && anchorBlock$1.type === ElementKinds.checkItem) {
3997
- Transforms.setNodes(editor, { checked: false });
3998
- }
3999
- };
4000
- editor.deleteBackward = unit => {
4001
- const { selection } = editor;
4002
- if (selection && Range.isCollapsed(selection)) {
4003
- const [match] = Editor.nodes(editor, {
4004
- match: n => Element$1.isElement(n) && n.type === ElementKinds.checkItem
4005
- });
4006
- if (match) {
4007
- const [, path] = match;
4008
- if (Editor.isStart(editor, selection.anchor, path)) {
4009
- Transforms.setNodes(editor, { type: ElementKinds.default, checked: undefined }, {
4010
- match: n => Element$1.isElement(n) && n.type === ElementKinds.checkItem
4011
- });
4012
- return;
4013
- }
4014
- }
4015
- }
4016
- deleteBackward(unit);
3908
+ const startMarkupPointAfter = getPointBefore(editor, endMarkupPointBefore, {
3909
+ matchString: startMarkup,
3910
+ skipInvalid: true,
3911
+ afterMatch: true
3912
+ });
3913
+ if (!startMarkupPointAfter) {
3914
+ return false;
3915
+ }
3916
+ // found
3917
+ const markupRange = {
3918
+ anchor: startMarkupPointAfter,
3919
+ focus: endMarkupPointBefore
4017
3920
  };
4018
- editor.renderElement = (element) => {
4019
- if (element.type === ElementKinds.checkItem) {
4020
- return TheTodoItemComponent;
3921
+ if (!ignoreTrim) {
3922
+ const markupText = getText(editor, markupRange);
3923
+ if (markupText.trim() !== markupText) {
3924
+ return false;
4021
3925
  }
4022
- return renderElement(element);
4023
- };
4024
- return editor;
4025
- };
4026
-
4027
- class TheHrComponent extends TheBaseElementComponent {
4028
- constructor(elementRef, cdr) {
4029
- super(elementRef, cdr);
4030
- this.elementRef = elementRef;
4031
- this.cdr = cdr;
4032
3926
  }
4033
- ngAfterViewInit() {
4034
- setTimeout(() => {
4035
- const blockCardElement = this.nativeElement.closest('slate-block-card');
4036
- if (blockCardElement) {
4037
- blockCardElement.classList.add(`slate-block-card-${this.element.type}`);
3927
+ // delete end markup
3928
+ if (endMarkup) {
3929
+ endMarkupPointBefore = getPointBefore(editor, selection, {
3930
+ matchString: endMarkup
3931
+ });
3932
+ Transforms.delete(editor, {
3933
+ at: {
3934
+ anchor: endMarkupPointBefore,
3935
+ focus: selection.anchor
3936
+ }
3937
+ });
3938
+ }
3939
+ const startMarkupPointBefore = getPointBefore(editor, selection, {
3940
+ matchString: startMarkup,
3941
+ skipInvalid: true
3942
+ });
3943
+ if (format) {
3944
+ const markupText = getText(editor, markupRange);
3945
+ format(editor, markupText);
3946
+ // delete start to end selection
3947
+ Transforms.delete(editor, {
3948
+ at: {
3949
+ anchor: startMarkupPointBefore,
3950
+ focus: selection.anchor
3951
+ }
3952
+ });
3953
+ }
3954
+ else {
3955
+ // add mark to the text between the markups
3956
+ Transforms.select(editor, markupRange);
3957
+ editor.addMark(type, true);
3958
+ Transforms.collapse(editor, { edge: 'end' });
3959
+ editor.removeMark(type, false);
3960
+ // delete start markup
3961
+ Transforms.delete(editor, {
3962
+ at: {
3963
+ anchor: startMarkupPointBefore,
3964
+ focus: startMarkupPointAfter
4038
3965
  }
4039
3966
  });
4040
3967
  }
4041
- }
4042
- TheHrComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheHrComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
4043
- TheHrComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.15", type: TheHrComponent, selector: "the-hr, [theHr]", usesInheritance: true, ngImport: i0, template: `
4044
- <div class="the-hr" contenteditable="false" [ngClass]="{ active: selection }">
4045
- <hr class="the-hr" />
4046
- <slate-children [children]="children" [context]="childrenContext" [viewContext]="viewContext"></slate-children>
4047
- </div>
4048
- `, isInline: true, components: [{ type: i1.SlateChildrenComponent, selector: "slate-children", inputs: ["children", "context", "viewContext"] }], directives: [{ type: i10.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }] });
4049
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheHrComponent, decorators: [{
4050
- type: Component,
4051
- args: [{
4052
- selector: 'the-hr, [theHr]',
4053
- template: `
4054
- <div class="the-hr" contenteditable="false" [ngClass]="{ active: selection }">
4055
- <hr class="the-hr" />
4056
- <slate-children [children]="children" [context]="childrenContext" [viewContext]="viewContext"></slate-children>
4057
- </div>
4058
- `
4059
- }]
4060
- }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; } });
4061
-
4062
- const withHr = (editor) => {
4063
- const { isVoid, isBlockCard, renderElement } = editor;
4064
- editor.isVoid = (element) => {
4065
- return element.type === ElementKinds.hr || isVoid(element);
4066
- };
4067
- editor.isBlockCard = (element) => {
4068
- if (element.type === ElementKinds.hr) {
4069
- return true;
4070
- }
4071
- return isBlockCard(element);
4072
- };
4073
- editor.renderElement = (element) => {
4074
- if (element.type === ElementKinds.hr) {
4075
- return TheHrComponent;
4076
- }
4077
- return renderElement(element);
4078
- };
4079
- return editor;
3968
+ return true;
4080
3969
  };
4081
3970
 
4082
- const withAlign = (editor) => {
4083
- const { deleteBackward } = editor;
4084
- editor.deleteBackward = unit => {
4085
- const { anchor } = editor.selection;
4086
- const node = anchorBlock(editor);
4087
- const isVoid = Editor.isVoid(editor, node);
4088
- const alignTypes = [Alignment.center, Alignment.right];
4089
- const startLine = Editor.start(editor, anchor.path);
4090
- const startLineRange = { anchor, focus: startLine };
4091
- const beforeText = Editor.string(editor, startLineRange);
4092
- if (!isVoid && node && node.align && alignTypes.includes(node.align) && beforeText === '') {
4093
- const align = alignTypes.indexOf(node.align) ? Alignment.center : undefined;
4094
- return Transforms.setNodes(editor, { align });
3971
+ const ListEditor = {
3972
+ isList(editor, element, type) {
3973
+ return Editor.isBlock(editor, element) && element.type === type;
3974
+ },
3975
+ toggleList(editor, type, startIndex) {
3976
+ if (!editor.selection) {
3977
+ return;
4095
3978
  }
4096
- deleteBackward(unit);
4097
- };
4098
- return editor;
4099
- };
4100
-
4101
- const withHeading = (editor) => {
4102
- const { insertBreak } = editor;
4103
- editor.insertBreak = () => {
4104
- const { selection } = editor;
4105
- const anchorBlock = getAnchorBlockEntry(editor);
4106
- if (anchorBlock && Range.isCollapsed(selection) && anchorBlock[0].type.startsWith('heading')) {
4107
- if (Editor.isStart(editor, selection.anchor, anchorBlock[1])) {
4108
- insertBreak();
4109
- Transforms.setNodes(editor, { type: ElementKinds.paragraph }, {
4110
- at: selection
3979
+ if (!startIndex) {
3980
+ startIndex = 1;
3981
+ }
3982
+ const types = [ElementKinds.bulletedList, ElementKinds.numberedList];
3983
+ Editor.withoutNormalizing(editor, () => {
3984
+ const [...listItems] = Editor.nodes(editor, {
3985
+ match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem,
3986
+ mode: 'lowest'
3987
+ });
3988
+ const firstListItemPath = listItems.length && listItems[0][1];
3989
+ const activeListPath = listItems.length && Path.parent(firstListItemPath);
3990
+ const activeListNode = listItems.length && Node.get(editor, activeListPath);
3991
+ // 同级且类型相同:unwrap
3992
+ const isLowestActive = listItems.length &&
3993
+ listItems.every(([, path]) => activeListNode.type === type && (Path.isSibling(firstListItemPath, path) || Path.equals(firstListItemPath, path)));
3994
+ if (isLowestActive) {
3995
+ const upListItem = Path.parent(activeListPath);
3996
+ Transforms.unwrapNodes(editor, {
3997
+ at: editor.selection,
3998
+ match: node => node === activeListNode,
3999
+ split: true,
4000
+ mode: 'lowest'
4111
4001
  });
4002
+ if (upListItem && Node.get(editor, upListItem).type === ElementKinds.listItem) {
4003
+ Transforms.moveNodes(editor, {
4004
+ at: editor.selection,
4005
+ to: Path.next(upListItem),
4006
+ match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem
4007
+ });
4008
+ }
4009
+ else {
4010
+ Transforms.unwrapNodes(editor, {
4011
+ match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem
4012
+ });
4013
+ }
4112
4014
  return;
4113
4015
  }
4114
- if (Editor.isEnd(editor, selection.focus, anchorBlock[1])) {
4115
- insertBreak();
4116
- Transforms.setNodes(editor, { type: ElementKinds.paragraph });
4016
+ // 跨级、同级且类型不同
4017
+ if (activeListNode && types.includes(activeListNode.type)) {
4018
+ Transforms.setNodes(editor, { type }, { match: node => Element$1.isElement(node) && node.type !== type && types.includes(node.type) });
4117
4019
  return;
4118
4020
  }
4119
- }
4120
- insertBreak();
4121
- };
4122
- return editor;
4123
- };
4124
-
4125
- const withMark = () => (editor) => {
4126
- const e = editor;
4127
- e.removeMark = (key, shouldChange = true) => {
4128
- const { selection } = e;
4129
- if (selection) {
4130
- if (Range.isExpanded(selection)) {
4131
- Transforms.unsetNodes(e, key, {
4132
- match: Text.isText,
4133
- split: true
4134
- });
4021
+ // wrap
4022
+ this.buildListItem(editor);
4023
+ // Todo: types
4024
+ Transforms.wrapNodes(editor, { type, children: [], start: startIndex }, {
4025
+ at: editor.selection,
4026
+ match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem
4027
+ });
4028
+ });
4029
+ },
4030
+ unwrapList(editor) {
4031
+ Editor.withoutNormalizing(editor, () => {
4032
+ unwrapNodesByType(editor, [ElementKinds.bulletedList, ElementKinds.numberedList], { split: true, mode: 'all' });
4033
+ unwrapNodesByType(editor, [ElementKinds.listItem], { split: true, mode: 'all' });
4034
+ });
4035
+ },
4036
+ wrapList(editor, type) {
4037
+ Editor.withoutNormalizing(editor, () => {
4038
+ const listItem = {
4039
+ type: ElementKinds.listItem,
4040
+ children: []
4041
+ };
4042
+ const list = {
4043
+ type,
4044
+ children: []
4045
+ };
4046
+ Transforms.wrapNodes(editor, list, { split: true });
4047
+ Transforms.wrapNodes(editor, listItem, { split: true });
4048
+ });
4049
+ },
4050
+ isActive(editor, type) {
4051
+ const [match] = getNodesByType(editor, type);
4052
+ return !!match;
4053
+ },
4054
+ getActiveList(editor) {
4055
+ const [match] = getNodesByType(editor, LIST_BLOCK_TYPES);
4056
+ return match;
4057
+ },
4058
+ buildListItem(editor) {
4059
+ const nodes = Editor.nodes(editor, {
4060
+ match: node => Editor.isBlock(editor, node),
4061
+ mode: 'lowest'
4062
+ });
4063
+ for (const [node, path] of nodes) {
4064
+ if (!Editor.isVoid(editor, node) && Element$1.isElement(node) && node.type !== ElementKinds.paragraph) {
4065
+ Transforms.setNodes(editor, { type: ElementKinds.paragraph, checked: undefined }, // todo remove checked
4066
+ { at: path });
4135
4067
  }
4136
- else {
4137
- const marks = Object.assign({}, (Editor.marks(e) || {}));
4138
- delete marks[key];
4139
- editor.marks = marks;
4140
- const text = Editor.string(e, selection.anchor.path);
4141
- if (text !== '') {
4142
- Editor.setNormalizing(editor, false);
4143
- e.insertText('');
4144
- editor.marks = marks;
4145
- Editor.setNormalizing(editor, true);
4146
- }
4147
- else {
4148
- Transforms.unsetNodes(e, key, { at: selection.anchor.path });
4149
- }
4150
- if (shouldChange) {
4151
- editor.onChange();
4068
+ else if (Element$1.isElement(node) && node.type === ElementKinds.paragraph) {
4069
+ let { textIndent } = node;
4070
+ if (textIndent) {
4071
+ Transforms.setNodes(editor, { textIndent: undefined, indent: undefined }, // remove indent
4072
+ { at: path });
4152
4073
  }
4153
4074
  }
4154
- }
4155
- };
4156
- e.addMark = (key, value) => {
4157
- const { selection } = editor;
4158
- if (selection) {
4159
- if (Range.isExpanded(selection)) {
4160
- Transforms.setNodes(e, { [key]: value }, { match: Text.isText, split: true });
4075
+ if (Node.parent(editor, path).type !== ElementKinds.listItem) {
4076
+ Transforms.wrapNodes(editor, { type: ElementKinds.listItem, children: [] }, {
4077
+ at: path,
4078
+ split: true
4079
+ });
4161
4080
  }
4162
- else {
4163
- const marks = Object.assign(Object.assign({}, (Editor.marks(e) || {})), { [key]: value });
4164
- editor.marks = marks;
4165
- const text = Editor.string(e, selection.anchor.path);
4166
- if (text !== '') {
4167
- Editor.setNormalizing(editor, false);
4168
- e.insertText('');
4169
- editor.marks = marks;
4170
- Editor.setNormalizing(editor, true);
4171
- }
4172
- else {
4173
- Transforms.setNodes(e, { [key]: value }, { at: selection.anchor.path });
4174
- }
4081
+ }
4082
+ },
4083
+ buildInsertDataChildren(node) {
4084
+ const { children } = node;
4085
+ const listItem = children[0];
4086
+ if (isNodeTypeList(node) && Element$1.isElement(listItem) && listItem.children[0].type === ElementKinds.paragraph) {
4087
+ return node;
4088
+ }
4089
+ return this.buildInsertDataChildren(listItem);
4090
+ }
4091
+ };
4092
+
4093
+ const TodoItemEditor = {
4094
+ isActive(editor) {
4095
+ const [match] = getNodesByType(editor, ElementKinds.checkItem);
4096
+ return !!match;
4097
+ },
4098
+ insertTodoItem(editor) {
4099
+ if (!editor.selection) {
4100
+ return;
4101
+ }
4102
+ const isActive = this.isActive(editor);
4103
+ const isNumberedList = ListEditor.isActive(editor, ElementKinds.numberedList);
4104
+ const isBulletedList = ListEditor.isActive(editor, ElementKinds.bulletedList);
4105
+ if (isActive) {
4106
+ Transforms.setNodes(editor, {
4107
+ type: ElementKinds.paragraph
4108
+ });
4109
+ }
4110
+ else {
4111
+ if (isNumberedList || isBulletedList) {
4112
+ ListEditor.unwrapList(editor);
4175
4113
  }
4114
+ Transforms.setNodes(editor, {
4115
+ type: ElementKinds.checkItem
4116
+ });
4176
4117
  }
4177
- };
4178
- return e;
4118
+ }
4179
4119
  };
4180
4120
 
4181
- const withNodeID = ({ idKey = 'id', idCreator = () => Date.now(), filterText = true, filter = () => true } = {}) => (e) => {
4182
- const editor = e;
4183
- const { apply, getFragment } = editor;
4184
- const idPropsCreator = () => ({ [idKey]: idCreator() });
4185
- editor.removedIDs = new Set();
4186
- editor.apply = (operation) => {
4187
- if (operation.type === 'insert_node') {
4188
- const newFilter = (entry) => {
4189
- const [_node] = entry;
4190
- return filter(entry) && filterText ? Element$1.isElement(_node) : isDescendant(_node);
4191
- };
4192
- // fix can not find path by orign node
4193
- let node = operation.node;
4194
- if (!Object.isExtensible(node)) {
4195
- node = _.cloneDeep(node);
4196
- }
4197
- // it will not overwrite ids once it's set as it's read-only
4198
- mergeDeepToNodes({
4199
- node,
4200
- source: idPropsCreator,
4201
- query: {
4202
- filter: newFilter,
4203
- }
4121
+ const BlockquoteEditor = {
4122
+ toggleBlockquote(editor) {
4123
+ if (!isParagraph(editor)) {
4124
+ Transforms.insertNodes(editor, {
4125
+ type: ElementKinds.paragraph,
4126
+ mode: 'text',
4127
+ children: [
4128
+ {
4129
+ text: ''
4130
+ }
4131
+ ]
4204
4132
  });
4205
- return apply(Object.assign(Object.assign({}, operation), { node }));
4206
4133
  }
4207
- if (operation.type === 'split_node' && (!filterText || operation.properties.type)) {
4208
- let id = operation.properties[idKey];
4209
- if (editor.removedIDs.has(id)) {
4210
- editor.removedIDs.delete(id);
4211
- }
4212
- else {
4213
- id = idCreator();
4214
- }
4215
- return apply(Object.assign(Object.assign({}, operation), { properties: Object.assign(Object.assign({}, operation.properties), { [idKey]: id }) }));
4134
+ const isActive = isBlockActive(editor, ElementKinds.blockquote);
4135
+ if (!isActive) {
4136
+ Transforms.wrapNodes(editor, { type: ElementKinds.blockquote, children: [] }, {
4137
+ mode: 'lowest'
4138
+ });
4216
4139
  }
4217
- if (operation.type === 'merge_node' && (!filterText || operation.properties.type)) {
4218
- editor.removedIDs.add(operation.properties[idKey]);
4140
+ else {
4141
+ Transforms.unwrapNodes(editor, { match: n => Element$1.isElement(n) && n.type === ElementKinds.blockquote });
4219
4142
  }
4220
- return apply(operation);
4221
- };
4222
- editor.getFragment = () => {
4223
- const fragment = _.cloneDeep(getFragment());
4224
- return deleteElementKey(fragment, idKey);
4225
- };
4226
- return editor;
4143
+ }
4227
4144
  };
4228
4145
 
4229
- const autoFormatBlock = (editor, type, at, { preFormat, format }, markups) => {
4230
- Transforms.delete(editor, { at });
4231
- if (preFormat) {
4232
- preFormat(editor);
4233
- }
4234
- if (!format) {
4235
- Transforms.setNodes(editor, { type }, { match: n => Editor.isBlock(editor, n) });
4236
- }
4237
- else {
4238
- format(editor, markups);
4146
+ const InlineCodeEditor = {
4147
+ toggleInlineCode(editor, text) {
4148
+ const isActive = InlineCodeEditor.isInlineCodeActive(editor);
4149
+ if (isActive) {
4150
+ InlineCodeEditor.unwrapInlineCode(editor);
4151
+ return;
4152
+ }
4153
+ if (Range.isCollapsed(editor.selection)) {
4154
+ InlineCodeEditor.wrapInlineCode(editor, text);
4155
+ }
4156
+ else {
4157
+ const fragment = Node.fragment(editor, editor.selection)[0];
4158
+ const selectNode = Node.get(fragment, []);
4159
+ const selectText = Node.string(selectNode);
4160
+ InlineCodeEditor.wrapInlineCode(editor, selectText);
4161
+ }
4162
+ },
4163
+ wrapInlineCode(editor, text = '') {
4164
+ if (InlineCodeEditor.isInlineCodeActive(editor)) {
4165
+ InlineCodeEditor.unwrapInlineCode(editor);
4166
+ }
4167
+ const { selection } = editor;
4168
+ const isCollapsed = selection && Range.isCollapsed(selection);
4169
+ const inlineCode = {
4170
+ type: ElementKinds.inlineCode,
4171
+ children: isCollapsed ? [{ text: text ? text : ZERO_WIDTH_CHAR }] : []
4172
+ };
4173
+ if (isCollapsed) {
4174
+ Transforms.insertNodes(editor, inlineCode);
4175
+ }
4176
+ else {
4177
+ Transforms.wrapNodes(editor, inlineCode, { split: true });
4178
+ }
4179
+ },
4180
+ unwrapInlineCode(editor) {
4181
+ Transforms.unwrapNodes(editor, { match: n => Element$1.isElement(n) && n.type === ElementKinds.inlineCode });
4182
+ },
4183
+ isInlineCodeActive(editor, path) {
4184
+ var _a;
4185
+ const [inlineCode] = Editor.nodes(editor, {
4186
+ at: path ? path : (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor.path,
4187
+ match: n => Element$1.isElement(n) && n.type === ElementKinds.inlineCode
4188
+ });
4189
+ return !!inlineCode;
4239
4190
  }
4240
4191
  };
4241
4192
 
4242
- const autoFormatInline = (editor, { type, between, markup, ignoreTrim, format }) => {
4243
- const selection = editor.selection;
4244
- const startMarkup = between ? between[0] : markup;
4245
- const endMarkup = between ? between[1] : '';
4246
- let endMarkupPointBefore = selection.anchor;
4247
- if (endMarkup) {
4248
- endMarkupPointBefore = getPointBefore(editor, selection, {
4249
- matchString: endMarkup
4193
+ const HeadingEditor = {
4194
+ setHeading(editor, heading) {
4195
+ Editor.withoutNormalizing(editor, () => {
4196
+ const types = [ElementKinds.bulletedList, ElementKinds.numberedList, ElementKinds.listItem];
4197
+ Transforms.unwrapNodes(editor, {
4198
+ at: editor.selection,
4199
+ match: n => Element$1.isElement(n) && types.includes(n.type),
4200
+ mode: 'all',
4201
+ split: true
4202
+ });
4203
+ Transforms.setNodes(editor, { type: heading });
4204
+ const entry = anchorBlockEntry(editor);
4205
+ const unMarks = {
4206
+ [MarkTypes.fontSize]: null
4207
+ };
4208
+ if (entry) {
4209
+ setMarks(editor, unMarks, entry[1]);
4210
+ return;
4211
+ }
4212
+ setMarks(editor, unMarks, editor.selection);
4250
4213
  });
4251
- if (!endMarkupPointBefore) {
4252
- return false;
4253
- }
4254
- }
4255
- const startMarkupPointAfter = getPointBefore(editor, endMarkupPointBefore, {
4256
- matchString: startMarkup,
4257
- skipInvalid: true,
4258
- afterMatch: true
4259
- });
4260
- if (!startMarkupPointAfter) {
4261
- return false;
4214
+ },
4215
+ isHeadingActive(editor, heading) {
4216
+ const [match] = Editor.nodes(editor, {
4217
+ match: n => Element$1.isElement(n) && n.type === heading,
4218
+ universal: true
4219
+ });
4220
+ return !!match;
4262
4221
  }
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;
4222
+ };
4223
+
4224
+ const defaultAutoFormatRules = [
4225
+ {
4226
+ type: ElementKinds.heading_1,
4227
+ markup: '#',
4228
+ format: (editor) => {
4229
+ HeadingEditor.setHeading(editor, ElementKinds.heading_1);
4230
+ }
4231
+ },
4232
+ {
4233
+ type: ElementKinds.heading_2,
4234
+ markup: '##',
4235
+ format: (editor) => {
4236
+ HeadingEditor.setHeading(editor, ElementKinds.heading_2);
4237
+ }
4238
+ },
4239
+ {
4240
+ type: ElementKinds.heading_3,
4241
+ markup: '###',
4242
+ format: (editor) => {
4243
+ HeadingEditor.setHeading(editor, ElementKinds.heading_3);
4244
+ }
4245
+ },
4246
+ {
4247
+ type: ElementKinds.heading_4,
4248
+ markup: '####',
4249
+ format: (editor) => {
4250
+ HeadingEditor.setHeading(editor, ElementKinds.heading_4);
4251
+ }
4252
+ },
4253
+ {
4254
+ type: ElementKinds.heading_5,
4255
+ markup: '#####',
4256
+ format: (editor) => {
4257
+ HeadingEditor.setHeading(editor, ElementKinds.heading_5);
4258
+ }
4259
+ },
4260
+ {
4261
+ type: ElementKinds.heading_6,
4262
+ markup: '######',
4263
+ format: (editor) => {
4264
+ HeadingEditor.setHeading(editor, ElementKinds.heading_6);
4265
+ }
4266
+ },
4267
+ {
4268
+ type: ElementKinds.blockquote,
4269
+ markup: ['>'],
4270
+ format: (editor) => {
4271
+ BlockquoteEditor.toggleBlockquote(editor);
4272
+ }
4273
+ },
4274
+ {
4275
+ type: MarkTypes.bold,
4276
+ between: ['**', '**'],
4277
+ mode: 'inline',
4278
+ insertTrigger: true
4279
+ },
4280
+ {
4281
+ type: MarkTypes.bold,
4282
+ between: ['__', '__'],
4283
+ mode: 'inline',
4284
+ insertTrigger: true
4285
+ },
4286
+ {
4287
+ type: MarkTypes.italic,
4288
+ between: ['*', '*'],
4289
+ mode: 'inline',
4290
+ insertTrigger: true
4291
+ },
4292
+ {
4293
+ type: MarkTypes.italic,
4294
+ between: ['_', '_'],
4295
+ mode: 'inline',
4296
+ insertTrigger: true
4297
+ },
4298
+ {
4299
+ type: ElementKinds.inlineCode,
4300
+ between: ['`', '`'],
4301
+ mode: 'inline',
4302
+ format: (editor, text) => {
4303
+ InlineCodeEditor.toggleInlineCode(editor, text);
4304
+ Transforms.select(editor, Editor.after(editor, editor.selection));
4272
4305
  }
4273
- }
4274
- // delete end markup
4275
- if (endMarkup) {
4276
- endMarkupPointBefore = getPointBefore(editor, selection, {
4277
- matchString: endMarkup
4278
- });
4279
- Transforms.delete(editor, {
4280
- at: {
4281
- anchor: endMarkupPointBefore,
4282
- focus: selection.anchor
4283
- }
4284
- });
4285
- }
4286
- const startMarkupPointBefore = getPointBefore(editor, selection, {
4287
- matchString: startMarkup,
4288
- skipInvalid: true
4289
- });
4290
- if (format) {
4291
- const markupText = getText(editor, markupRange);
4292
- format(editor, markupText);
4293
- // delete start to end selection
4294
- Transforms.delete(editor, {
4295
- at: {
4296
- anchor: startMarkupPointBefore,
4297
- focus: selection.anchor
4298
- }
4299
- });
4300
- }
4301
- else {
4302
- // add mark to the text between the markups
4303
- Transforms.select(editor, markupRange);
4304
- editor.addMark(type, true);
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
4306
+ },
4307
+ {
4308
+ type: MarkTypes.strike,
4309
+ between: ['~~', '~~'],
4310
+ mode: 'inline',
4311
+ insertTrigger: true
4312
+ },
4313
+ {
4314
+ type: ElementKinds.code,
4315
+ markup: '```',
4316
+ insertTrigger: true
4317
+ },
4318
+ {
4319
+ type: ElementKinds.listItem,
4320
+ markup: [],
4321
+ match: (editor) => {
4322
+ return isParagraph(editor) ? ['*', '-', '+'] : [];
4323
+ },
4324
+ format: (editor) => {
4325
+ ListEditor.toggleList(editor, ElementKinds.bulletedList);
4326
+ }
4327
+ },
4328
+ {
4329
+ type: ElementKinds.listItem,
4330
+ key: ElementKinds.numberedList,
4331
+ markup: [],
4332
+ match: (editor, textFromBlockStart) => {
4333
+ return isParagraph(editor) && /^-?\d+(\.|\))$/.test(textFromBlockStart) ? [textFromBlockStart] : [];
4334
+ },
4335
+ format: (editor, markup) => {
4336
+ let startIndex = 1;
4337
+ if (markup) {
4338
+ startIndex = markup[0].split('.')[0];
4339
+ if (startIndex === 0) {
4340
+ startIndex = 1;
4341
+ }
4312
4342
  }
4313
- });
4343
+ ListEditor.toggleList(editor, ElementKinds.numberedList, startIndex);
4344
+ }
4345
+ },
4346
+ {
4347
+ type: ElementKinds.checkItem,
4348
+ markup: [],
4349
+ match: (editor) => {
4350
+ return isParagraph(editor) ? ['[]'] : [];
4351
+ },
4352
+ format: (editor) => {
4353
+ TodoItemEditor.insertTodoItem(editor);
4354
+ }
4355
+ },
4356
+ {
4357
+ type: ElementKinds.hr,
4358
+ markup: '---',
4359
+ insertTrigger: true
4314
4360
  }
4315
- return true;
4316
- };
4361
+ ];
4317
4362
 
4318
- const withAutoFormat = ({ rules }) => (editor) => {
4363
+ const withAutoFormat = () => (editor) => {
4319
4364
  const { insertText } = editor;
4320
4365
  editor.insertText = text => {
4321
- var _a;
4366
+ var _a, _b;
4367
+ let autoFormatRules = defaultAutoFormatRules;
4368
+ if ((_a = editor.extraAutoFormatRules) === null || _a === void 0 ? void 0 : _a.length) {
4369
+ const extraRules = mergAutoFormateRules(editor.extraAutoFormatRules);
4370
+ autoFormatRules = Object.values(extraRules);
4371
+ }
4322
4372
  if (!isCollapsed(editor.selection)) {
4323
4373
  return insertText(text);
4324
4374
  }
4325
- for (let _b of rules) {
4326
- const { query } = _b, rule = __rest(_b, ["query"]);
4375
+ for (let _c of autoFormatRules) {
4376
+ const { query } = _c, rule = __rest(_c, ["query"]);
4327
4377
  const { trigger = ' ', mode = 'block', type, markup, preFormat, format, match, between, ignoreTrim, insertTrigger, allowSameTypeAbove = false, triggerAtBlockStart = true } = rule;
4328
4378
  if (query && !query(editor, rule))
4329
4379
  continue;
@@ -4358,7 +4408,7 @@ const withAutoFormat = ({ rules }) => (editor) => {
4358
4408
  });
4359
4409
  if (!markupRange)
4360
4410
  continue;
4361
- const blockAbovePath = (_a = getBlockAbove(editor)) === null || _a === void 0 ? void 0 : _a[1];
4411
+ const blockAbovePath = (_b = getBlockAbove(editor)) === null || _b === void 0 ? void 0 : _b[1];
4362
4412
  if (!blockAbovePath)
4363
4413
  continue;
4364
4414
  // If the markup is not at the start, insert break before autoformatting.
@@ -4395,6 +4445,17 @@ const withAutoFormat = ({ rules }) => (editor) => {
4395
4445
  };
4396
4446
  return editor;
4397
4447
  };
4448
+ const mergAutoFormateRules = (extraAutoFormatRules) => {
4449
+ const combinationData = [...defaultAutoFormatRules, ...extraAutoFormatRules];
4450
+ const dataInfo = {};
4451
+ combinationData.forEach(item => {
4452
+ if (!dataInfo[item.type + item.key]) {
4453
+ dataInfo[item.type + item.key] = Object.assign({}, item);
4454
+ }
4455
+ dataInfo[item.type + item.key] = Object.assign(Object.assign({}, dataInfo[item.type + item.key]), item);
4456
+ });
4457
+ return dataInfo;
4458
+ };
4398
4459
 
4399
4460
  const withTransforms = () => (editor) => {
4400
4461
  const e = editor;
@@ -8683,7 +8744,7 @@ class TableService {
8683
8744
  offset: this.offset,
8684
8745
  hasBackdrop: this.hasBackdrop,
8685
8746
  insideClosable: this.insideClosable,
8686
- panelClass: 'the-table-toolbar-wrap',
8747
+ panelClass: 'the-temp-table-toolbar-wrap',
8687
8748
  scrollStrategy: this.overlay.scrollStrategies.reposition(),
8688
8749
  manualClosure: true
8689
8750
  });
@@ -8693,15 +8754,15 @@ class TableService {
8693
8754
  if (origin instanceof HTMLTableCellElement && origin.tagName !== 'TH') {
8694
8755
  const { selectedRowsIndex, selectedColumnsIndex, focusCellPath, isSelectedTable, focusCellElement } = this.tableStore;
8695
8756
  const [row, col] = focusCellPath.slice(-2);
8696
- const tableElement = focusCellElement.closest('.the-table-container');
8757
+ const tableElement = focusCellElement.closest('.the-temp-table-container');
8697
8758
  if (isSelectedTable && col === 0 && row === 0) {
8698
- return tableElement.querySelector('.the-table-corner-controls');
8759
+ return tableElement.querySelector('.the-temp-table-corner-controls');
8699
8760
  }
8700
8761
  if (selectedColumnsIndex.length > 0 && row === 0) {
8701
- return tableElement.querySelectorAll('.the-table-col-controls')[col];
8762
+ return tableElement.querySelectorAll('.the-temp-table-col-controls')[col];
8702
8763
  }
8703
8764
  if (selectedRowsIndex.length > 0 && col === 0) {
8704
- return tableElement.querySelectorAll('.the-table-row-controls-button-wrap')[row];
8765
+ return tableElement.querySelectorAll('.the-temp-table-row-controls-button-wrap')[row];
8705
8766
  }
8706
8767
  }
8707
8768
  return origin;
@@ -8802,13 +8863,13 @@ class TheInsertMarkComponent {
8802
8863
  const tableWrapper = tableComponent.tableWrapper.nativeElement;
8803
8864
  const tableElement = tableComponent.theTableElement.nativeElement;
8804
8865
  let result = 0;
8805
- const rowControl = tableComponent.nativeElement.querySelector('.the-table-row-controls');
8866
+ const rowControl = tableComponent.nativeElement.querySelector('.the-temp-table-row-controls');
8806
8867
  let rowControlWidth = 11;
8807
8868
  if (rowControl) {
8808
8869
  rowControlWidth = rowControl.getBoundingClientRect().width;
8809
8870
  }
8810
8871
  if (this.type === 'row') {
8811
- result = tableWrapper.offsetWidth + rowControlWidth;
8872
+ result = tableWrapper.offsetWidth + rowControlWidth - 2;
8812
8873
  }
8813
8874
  else {
8814
8875
  result = tableElement.offsetHeight - 1;
@@ -8819,7 +8880,7 @@ class TheInsertMarkComponent {
8819
8880
  ngOnDestroy() { }
8820
8881
  }
8821
8882
  TheInsertMarkComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheInsertMarkComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
8822
- TheInsertMarkComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.15", type: TheInsertMarkComponent, selector: "the-table-insert-mark", inputs: { type: "type", at: "at", tableStore: "tableStore" }, ngImport: i0, template: "<div\n [thyTooltip]=\"!disabled && tooltipContent\"\n class=\"the-table-controls-insert-wrapper\"\n [ngClass]=\"{ disabled: disabled }\"\n contenteditable=\"false\"\n (mousedown)=\"onMouseDown($event)\"\n (mouseenter)=\"onMouseEnter($event)\"\n (mouseleave)=\"onMouseLeave($event)\"\n>\n <div\n class=\"the-table-controls-insert-line\"\n *ngIf=\"dotWrapperHovered\"\n [attr.data-dot-type]=\"type\"\n [ngStyle]=\"{ height: type === 'column' && insertLength, width: type === 'row' && insertLength }\"\n ></div>\n</div>\n", directives: [{ type: i5.ThyTooltipDirective, selector: "[thyTooltip],[thy-tooltip]", inputs: ["thyTooltip", "thyTooltipPlacement", "thyTooltipClass", "thyTooltipShowDelay", "thyTooltipHideDelay", "thyTooltipTrigger", "thyTooltipDisabled", "thyTooltipTemplateContext", "thyTooltipOffset", "thyTooltipPin"], exportAs: ["thyTooltip"] }, { type: i10.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i10.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i10.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }] });
8883
+ TheInsertMarkComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.15", type: TheInsertMarkComponent, selector: "the-table-insert-mark", inputs: { type: "type", at: "at", tableStore: "tableStore" }, ngImport: i0, template: "<div\n [thyTooltip]=\"!disabled && tooltipContent\"\n class=\"the-temp-table-controls-insert-wrapper\"\n [ngClass]=\"{ disabled: disabled }\"\n contenteditable=\"false\"\n (mousedown)=\"onMouseDown($event)\"\n (mouseenter)=\"onMouseEnter($event)\"\n (mouseleave)=\"onMouseLeave($event)\"\n>\n <div\n class=\"the-temp-table-controls-insert-line\"\n *ngIf=\"dotWrapperHovered\"\n [attr.data-dot-type]=\"type\"\n [ngStyle]=\"{ height: type === 'column' && insertLength, width: type === 'row' && insertLength }\"\n ></div>\n</div>\n", directives: [{ type: i5.ThyTooltipDirective, selector: "[thyTooltip],[thy-tooltip]", inputs: ["thyTooltip", "thyTooltipPlacement", "thyTooltipClass", "thyTooltipShowDelay", "thyTooltipHideDelay", "thyTooltipTrigger", "thyTooltipDisabled", "thyTooltipTemplateContext", "thyTooltipOffset", "thyTooltipPin"], exportAs: ["thyTooltip"] }, { type: i10.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i10.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i10.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }] });
8823
8884
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheInsertMarkComponent, decorators: [{
8824
8885
  type: Component,
8825
8886
  args: [{
@@ -9298,7 +9359,7 @@ TheTableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", vers
9298
9359
  provide: TheTableToken,
9299
9360
  useExisting: TheTableComponent
9300
9361
  }
9301
- ], viewQueries: [{ propertyName: "tableWrapper", first: true, predicate: ["tableWrapper"], descendants: true, read: ElementRef, static: true }, { propertyName: "theTableElement", first: true, predicate: ["theTable"], descendants: true, read: ElementRef, static: true }, { propertyName: "tbodyElement", first: true, predicate: ["tbody"], descendants: true, read: ElementRef, static: true }], usesInheritance: true, ngImport: i0, template: "<div\n class=\"the-table-container\"\n theColumnResize\n [ngClass]=\"{\n 'the-table-with-controls': isInTable,\n 'the-numbered-column-container': element?.options?.numberedColumn,\n 'the-table-selection-hide': tableStore.isCellSelecting || tableStore.isRightClicking\n }\"\n>\n <div\n class=\"the-table-row-controls-wrapper\"\n [ngClass]=\"{\n 'the-table-focus': isInTable\n }\"\n >\n <div\n class=\"the-table-corner-controls\"\n [ngClass]=\"{\n visible: !readonly && isInTable,\n active: isSelectedAllCell,\n dangerous: tableStore.isSelectedTable && tableStore.dangerousCells.length > 0\n }\"\n >\n <div class=\"the-table-corner-button\" (mousedown)=\"onSelectTable($event)\"></div>\n <div class=\"the-table-corner-controls-insert-row-marker\">\n <the-table-insert-mark type=\"row\" [at]=\"0\" [tableStore]=\"tableStore\"></the-table-insert-mark>\n </div>\n <div class=\"the-table-corner-controls-insert-column-marker\">\n <the-table-insert-mark type=\"column\" [at]=\"0\" [tableStore]=\"tableStore\"></the-table-insert-mark>\n </div>\n </div>\n <div class=\"the-table-row-controls\">\n <div class=\"the-table-row-controls-inner\">\n <div\n class=\"the-table-row-controls-button-wrap\"\n *ngFor=\"let control of rowControls; let i = index; trackBy: trackByFnRowCotrols\"\n [ngClass]=\"{\n active: tableStore.selectedRowsIndex.includes(control.rowIndex),\n dangerous: tableStore.dangerousRowsIndex.includes(control.rowIndex) && tableStore.dangerousCells.length > 0\n }\"\n >\n <ng-container *ngIf=\"!readonly && isInTable && !element?.options?.numberedColumn\">\n <button\n (mousedown)=\"onRowMouseDown($event, control.rowIndex)\"\n type=\"button\"\n [ngStyle]=\"{ height: control.height + 1 + 'px' }\"\n class=\"the-table-row-controls-button the-table-controls-button\"\n ></button>\n </ng-container>\n <ng-container *ngIf=\"element?.options?.numberedColumn\">\n <div\n [contentEditable]=\"false\"\n contenteditable=\"false\"\n (mousedown)=\"onRowMouseDown($event, control.rowIndex)\"\n class=\"the-table-numbered-controls-button\"\n [ngStyle]=\"{ height: control.height + 1 + 'px' }\"\n >\n <p class=\"row-number d-flex align-items-center\">{{ i + 1 }}</p>\n </div>\n </ng-container>\n <the-table-insert-mark type=\"row\" [at]=\"control.rowIndex + 1\" [tableStore]=\"tableStore\"> </the-table-insert-mark>\n </div>\n </div>\n </div>\n </div>\n <div class=\"the-table-wrapper\" #tableWrapper [ngClass]=\"{ 'the-table-numbered': element?.options?.numberedColumn }\">\n <table class=\"the-table\" #theTable [ngClass]=\"{ 'the-table-with-controls': isInTable }\">\n <colgroup *ngIf=\"columns\">\n <col *ngFor=\"let col of columns\" [ngStyle]=\"{ width: col.width + 'px' }\" />\n </colgroup>\n <thead>\n <tr class=\"the-table-col-controls-wrapper\">\n <th\n class=\"the-table-col-controls\"\n [ngClass]=\"{\n active: tableStore.selectedColumnsIndex.includes(i),\n dangerous: tableStore.dangerousColumnsIndex.includes(i) && tableStore.dangerousCells.length > 0\n }\"\n (mousedown)=\"onColMouseDown($event, i)\"\n *ngFor=\"let control of colControls; let i = index; trackBy: trackByFnColCotrols\"\n >\n <the-table-insert-mark *ngIf=\"isInTable\" type=\"column\" [at]=\"i + 1\" [tableStore]=\"tableStore\">\n </the-table-insert-mark>\n </th>\n </tr>\n </thead>\n <tbody #tbody>\n <slate-children [children]=\"children\" [context]=\"childrenContext\" [viewContext]=\"viewContext\"> </slate-children>\n </tbody>\n </table>\n </div>\n</div>\n", components: [{ type: TheInsertMarkComponent, selector: "the-table-insert-mark", inputs: ["type", "at", "tableStore"] }, { type: i1.SlateChildrenComponent, selector: "slate-children", inputs: ["children", "context", "viewContext"] }], directives: [{ type: TheColumnResizeDirective, selector: "div[theColumnResize]" }, { type: i10.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i10.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i10.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i10.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }] });
9362
+ ], viewQueries: [{ propertyName: "tableWrapper", first: true, predicate: ["tableWrapper"], descendants: true, read: ElementRef, static: true }, { propertyName: "theTableElement", first: true, predicate: ["theTable"], descendants: true, read: ElementRef, static: true }, { propertyName: "tbodyElement", first: true, predicate: ["tbody"], descendants: true, read: ElementRef, static: true }], usesInheritance: true, ngImport: i0, template: "<!-- \u7C7B\u540D the-temp-*: \u4E34\u65F6\u89E3\u51B3\u56E0\u53D7portal\u5F71\u54CD\u8868\u683C\u6837\u5F0F\u95EE\u9898\uFF0C\u540E\u671F\u6539\u56DEthe-* -->\n<div\n class=\"the-temp-table-container\"\n theColumnResize\n [ngClass]=\"{\n 'the-temp-table-with-controls': isInTable,\n 'the-temp-numbered-column-container': element?.options?.numberedColumn,\n 'the-temp-table-selection-hide': tableStore.isCellSelecting || tableStore.isRightClicking\n }\"\n>\n <div\n class=\"the-temp-table-row-controls-wrapper\"\n [ngClass]=\"{\n 'the-temp-table-focus': isInTable\n }\"\n >\n <div\n class=\"the-temp-table-corner-controls\"\n [ngClass]=\"{\n visible: !readonly && isInTable,\n active: isSelectedAllCell,\n dangerous: tableStore.isSelectedTable && tableStore.dangerousCells.length > 0\n }\"\n >\n <div class=\"the-temp-table-corner-button\" (mousedown)=\"onSelectTable($event)\"></div>\n <div class=\"the-temp-table-corner-controls-insert-row-marker\">\n <the-table-insert-mark type=\"row\" [at]=\"0\" [tableStore]=\"tableStore\"></the-table-insert-mark>\n </div>\n <div class=\"the-temp-table-corner-controls-insert-column-marker\">\n <the-table-insert-mark type=\"column\" [at]=\"0\" [tableStore]=\"tableStore\"></the-table-insert-mark>\n </div>\n </div>\n <div class=\"the-temp-table-row-controls\">\n <div class=\"the-temp-table-row-controls-inner\">\n <div\n class=\"the-temp-table-row-controls-button-wrap\"\n *ngFor=\"let control of rowControls; let i = index; trackBy: trackByFnRowCotrols\"\n [ngClass]=\"{\n active: tableStore.selectedRowsIndex.includes(control.rowIndex),\n dangerous: tableStore.dangerousRowsIndex.includes(control.rowIndex) && tableStore.dangerousCells.length > 0\n }\"\n >\n <ng-container *ngIf=\"!readonly && isInTable && !element?.options?.numberedColumn\">\n <button\n (mousedown)=\"onRowMouseDown($event, control.rowIndex)\"\n type=\"button\"\n [ngStyle]=\"{ height: control.height + 1 + 'px' }\"\n class=\"the-temp-table-row-controls-button the-temp-table-controls-button\"\n ></button>\n </ng-container>\n <ng-container *ngIf=\"element?.options?.numberedColumn\">\n <div\n [contentEditable]=\"false\"\n contenteditable=\"false\"\n (mousedown)=\"onRowMouseDown($event, control.rowIndex)\"\n class=\"the-temp-table-numbered-controls-button\"\n [ngStyle]=\"{ height: control.height + 1 + 'px' }\"\n >\n <p class=\"row-number d-flex align-items-center\">{{ i + 1 }}</p>\n </div>\n </ng-container>\n <the-table-insert-mark type=\"row\" [at]=\"control.rowIndex + 1\" [tableStore]=\"tableStore\"> </the-table-insert-mark>\n </div>\n </div>\n </div>\n </div>\n <div class=\"the-temp-table-wrapper\" #tableWrapper [ngClass]=\"{ 'the-temp-table-numbered': element?.options?.numberedColumn }\">\n <table class=\"the-temp-table\" #theTable [ngClass]=\"{ 'the-temp-table-with-controls': isInTable }\">\n <colgroup *ngIf=\"columns\">\n <col *ngFor=\"let col of columns\" [ngStyle]=\"{ width: col.width + 'px' }\" />\n </colgroup>\n <thead>\n <tr class=\"the-temp-table-col-controls-wrapper\">\n <th\n class=\"the-temp-table-col-controls\"\n [ngClass]=\"{\n active: tableStore.selectedColumnsIndex.includes(i),\n dangerous: tableStore.dangerousColumnsIndex.includes(i) && tableStore.dangerousCells.length > 0\n }\"\n (mousedown)=\"onColMouseDown($event, i)\"\n *ngFor=\"let control of colControls; let i = index; trackBy: trackByFnColCotrols\"\n >\n <the-table-insert-mark *ngIf=\"isInTable\" type=\"column\" [at]=\"i + 1\" [tableStore]=\"tableStore\">\n </the-table-insert-mark>\n </th>\n </tr>\n </thead>\n <tbody #tbody>\n <slate-children [children]=\"children\" [context]=\"childrenContext\" [viewContext]=\"viewContext\"> </slate-children>\n </tbody>\n </table>\n </div>\n</div>\n", components: [{ type: TheInsertMarkComponent, selector: "the-table-insert-mark", inputs: ["type", "at", "tableStore"] }, { type: i1.SlateChildrenComponent, selector: "slate-children", inputs: ["children", "context", "viewContext"] }], directives: [{ type: TheColumnResizeDirective, selector: "div[theColumnResize]" }, { type: i10.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i10.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i10.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i10.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }] });
9302
9363
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheTableComponent, decorators: [{
9303
9364
  type: Component,
9304
9365
  args: [{
@@ -10155,12 +10216,12 @@ class TheTdComponent extends TheBaseElementComponent {
10155
10216
  }
10156
10217
  updateOverlayHandleRowSize() {
10157
10218
  const tableElement = this.tableComponent.nativeElement;
10158
- const rowControl = tableElement.querySelector('.the-table-row-controls');
10219
+ const rowControl = tableElement.querySelector('.the-temp-table-row-controls');
10159
10220
  let rowControlWidth = 11;
10160
10221
  if (rowControl) {
10161
10222
  rowControlWidth = rowControl.getBoundingClientRect().width;
10162
10223
  }
10163
- const width = this.tableComponent.tableWrapper.nativeElement.offsetWidth + rowControlWidth;
10224
+ const width = this.tableComponent.tableWrapper.nativeElement.offsetWidth + rowControlWidth - 2;
10164
10225
  this.overlayRef.addPanelClass(this.rowResizeClass);
10165
10226
  this.overlayRef.updateSize({ width, height: OVERLAY_INIT_SIZE });
10166
10227
  }
@@ -10352,8 +10413,7 @@ class TheTdComponent extends TheBaseElementComponent {
10352
10413
  applyTopRows(rows, deltaY, rowIndex) {
10353
10414
  while (deltaY < 0 && rows[rowIndex]) {
10354
10415
  const rowOffsetHeight = getElementHeight(rows[rowIndex]);
10355
- const rowStyleHeight = coercePixelsFromCssValue(rows[rowIndex].style.height);
10356
- if (rowOffsetHeight > this.tableOptions.minHeightPx && rowOffsetHeight === rowStyleHeight) {
10416
+ if (rowOffsetHeight > this.tableOptions.minHeightPx) {
10357
10417
  if (this.resizingStore.isResizing(deltaY, this.isXAxisHover)) {
10358
10418
  this.resizingStore.storeResizingRow(rows[rowIndex]);
10359
10419
  }
@@ -10373,8 +10433,7 @@ class TheTdComponent extends TheBaseElementComponent {
10373
10433
  applyBottomRows(rows, deltaY, rowIndex) {
10374
10434
  while (rows[rowIndex] && deltaY > 0) {
10375
10435
  const rowOffsetHeight = getElementHeight(rows[rowIndex]);
10376
- const rowStyleHeight = coercePixelsFromCssValue(rows[rowIndex].style.height);
10377
- if (rowOffsetHeight > this.tableOptions.minHeightPx && rowOffsetHeight === rowStyleHeight) {
10436
+ if (rowOffsetHeight > this.tableOptions.minHeightPx) {
10378
10437
  if (this.resizingStore.isResizing(deltaY, this.isXAxisHover)) {
10379
10438
  this.resizingStore.storeResizingRow(rows[rowIndex]);
10380
10439
  }
@@ -11251,26 +11310,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
11251
11310
  }] } });
11252
11311
 
11253
11312
  class TheQuickToolbarComponent extends mixinUnsubscribe(MixinBase) {
11254
- constructor(popoverRef, elementRef) {
11313
+ constructor(elementRef, cdr) {
11255
11314
  super();
11256
- this.popoverRef = popoverRef;
11257
11315
  this.elementRef = elementRef;
11316
+ this.cdr = cdr;
11258
11317
  this.ToolbarItemMode = ToolbarItemMode;
11259
11318
  this.ToolbarActionTypes = ToolbarActionTypes;
11260
11319
  }
11261
11320
  handleMouseDown(event) {
11262
11321
  if (!this.elementRef.nativeElement.contains(event.target)) {
11263
- QuickInsertEditor.closeQuickToolbar(this.editor);
11322
+ QuickInsertEditor.closeQuickInsertToolbar(this.editor);
11264
11323
  }
11265
11324
  else {
11266
11325
  event.preventDefault();
11267
11326
  }
11268
11327
  }
11269
11328
  handleEnter() {
11270
- QuickInsertEditor.closeQuickToolbar(this.editor);
11329
+ QuickInsertEditor.closeQuickInsertToolbar(this.editor);
11271
11330
  }
11272
11331
  handleEsc() {
11273
- QuickInsertEditor.closeQuickToolbar(this.editor);
11332
+ QuickInsertEditor.closeQuickInsertToolbar(this.editor);
11274
11333
  }
11275
11334
  ngOnInit() {
11276
11335
  this.editorElement = AngularEditor.toDOMNode(this.editor, this.editor);
@@ -11295,15 +11354,15 @@ class TheQuickToolbarComponent extends mixinUnsubscribe(MixinBase) {
11295
11354
  super.ngOnDestroy();
11296
11355
  }
11297
11356
  }
11298
- TheQuickToolbarComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheQuickToolbarComponent, deps: [{ token: i1$3.ThyPopoverRef }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
11299
- TheQuickToolbarComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.15", type: TheQuickToolbarComponent, selector: "the-quick-toolbar", inputs: { editor: "editor", quickToolbarItems: "quickToolbarItems" }, host: { listeners: { "document: mousedown": "handleMouseDown($event)", "document: keydown.enter": "handleEnter()", "document: keydown.escape": "handleEsc()" } }, usesInheritance: true, ngImport: i0, template: "<thy-selection-list\n class=\"the-quick-toolbar\"\n [thyBindKeyEventContainer]=\"editorElement\"\n (thySelectionChange)=\"selectionChange($event)\"\n [thyMultiple]=\"false\"\n>\n <ng-container *ngFor=\"let item of quickToolbarItems\">\n <ng-container *ngIf=\"item.key !== ToolbarActionTypes.split; else splitLine\">\n <thy-list-option [thyValue]=\"item?.key\" (mousedown)=\"stopPropagation($event)\">\n <the-toolbar-item [editor]=\"editor\" [item]=\"item\" [itemMode]=\"ToolbarItemMode.vertical\"></the-toolbar-item>\n </thy-list-option>\n </ng-container>\n </ng-container>\n</thy-selection-list>\n\n<ng-template #splitLine>\n <nav-split-line [mode]=\"ToolbarItemMode.horizontal\"></nav-split-line>\n</ng-template>\n", components: [{ type: i2$3.ThySelectionListComponent, selector: "thy-selection-list,[thy-selection-list]", inputs: ["thyMultiple", "thyBindKeyEventContainer", "thyScrollContainer", "thyBeforeKeydown", "thyUniqueKey", "thyCompareWith", "thyLayout", "thyAutoActiveFirstItem", "thySize", "thySpaceKeyEnabled"], outputs: ["thySelectionChange"] }, { type: i5$2.ThyListOptionComponent, selector: "thy-list-option,[thy-list-option]", inputs: ["id", "thyValue", "thyDisabled"] }, { type: TheToolbarItemComponent, selector: "the-toolbar-item", inputs: ["editor", "item", "itemMode"] }, { type: NavSplitLineComponent, selector: "nav-split-line", inputs: ["mode"] }], directives: [{ type: i10.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i10.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
11357
+ TheQuickToolbarComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheQuickToolbarComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
11358
+ TheQuickToolbarComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.15", type: TheQuickToolbarComponent, selector: "the-quick-toolbar", inputs: { editor: "editor", quickToolbarItems: "quickToolbarItems" }, host: { listeners: { "document: mousedown": "handleMouseDown($event)", "document: keydown.enter": "handleEnter()", "document: keydown.escape": "handleEsc()" } }, usesInheritance: true, ngImport: i0, template: "<thy-selection-list\n class=\"the-quick-toolbar\"\n [thyBindKeyEventContainer]=\"editorElement\"\n (thySelectionChange)=\"selectionChange($event)\"\n [thyMultiple]=\"false\"\n>\n <ng-container *ngFor=\"let item of quickToolbarItems\">\n <ng-container *ngIf=\"item.key !== ToolbarActionTypes.split; else splitLine\">\n <thy-list-option [thyValue]=\"item?.key\" (mousedown)=\"stopPropagation($event)\">\n <the-toolbar-item [editor]=\"editor\" [item]=\"item\" [itemMode]=\"ToolbarItemMode.vertical\"></the-toolbar-item>\n </thy-list-option>\n </ng-container>\n </ng-container>\n</thy-selection-list>\n\n<ng-template #splitLine>\n <nav-split-line [mode]=\"ToolbarItemMode.horizontal\"></nav-split-line>\n</ng-template>\n", components: [{ type: i1$7.ThySelectionListComponent, selector: "thy-selection-list,[thy-selection-list]", inputs: ["thyMultiple", "thyBindKeyEventContainer", "thyScrollContainer", "thyBeforeKeydown", "thyUniqueKey", "thyCompareWith", "thyLayout", "thyAutoActiveFirstItem", "thySize", "thySpaceKeyEnabled"], outputs: ["thySelectionChange"] }, { type: i5$2.ThyListOptionComponent, selector: "thy-list-option,[thy-list-option]", inputs: ["id", "thyValue", "thyDisabled"] }, { type: TheToolbarItemComponent, selector: "the-toolbar-item", inputs: ["editor", "item", "itemMode"] }, { type: NavSplitLineComponent, selector: "nav-split-line", inputs: ["mode"] }], directives: [{ type: i10.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i10.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
11300
11359
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheQuickToolbarComponent, decorators: [{
11301
11360
  type: Component,
11302
11361
  args: [{
11303
11362
  selector: 'the-quick-toolbar',
11304
11363
  templateUrl: 'quick-toolbar.component.html'
11305
11364
  }]
11306
- }], ctorParameters: function () { return [{ type: i1$3.ThyPopoverRef }, { type: i0.ElementRef }]; }, propDecorators: { editor: [{
11365
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { editor: [{
11307
11366
  type: Input
11308
11367
  }], quickToolbarItems: [{
11309
11368
  type: Input
@@ -11318,16 +11377,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
11318
11377
  args: ['document: keydown.escape']
11319
11378
  }] } });
11320
11379
 
11321
- const OperationTypes = ['insert_text', 'remove_node', 'merge_node'];
11322
11380
  const QuickInsertEditor = {
11323
- openQuickToolbar(editor, toolbarItems, origin) {
11381
+ openQuickInsertToolbar(editor, quickToolbarItems, origin) {
11382
+ if (QuickInsertEditor.isOpenedToolbar(editor)) {
11383
+ return;
11384
+ }
11385
+ if (!origin) {
11386
+ const [block,] = getBlockAbove(editor);
11387
+ const rootNode = AngularEditor.toDOMNode(editor, block);
11388
+ origin = rootNode.querySelector('[data-slate-leaf="true"]');
11389
+ }
11324
11390
  const overlay = editor.injector.get(Overlay);
11325
11391
  const viewContainerRef = editor.injector.get(ViewContainerRef);
11326
11392
  const thyPopover = editor.injector.get(ThyPopover);
11327
11393
  const quickToolbarRef = thyPopover.open(TheQuickToolbarComponent, {
11328
11394
  initialState: {
11329
11395
  editor,
11330
- quickToolbarItems: toolbarItems
11396
+ quickToolbarItems
11331
11397
  },
11332
11398
  origin,
11333
11399
  viewContainerRef: viewContainerRef,
@@ -11340,52 +11406,39 @@ const QuickInsertEditor = {
11340
11406
  scrollStrategy: overlay.scrollStrategies.reposition(),
11341
11407
  manualClosure: true
11342
11408
  });
11409
+ quickToolbarRef.componentInstance.cdr.markForCheck();
11343
11410
  THE_EDITOR_QUICK_TOOLBAR_REF.set(editor, quickToolbarRef);
11344
11411
  },
11345
- closeQuickToolbar(editor) {
11412
+ closeQuickInsertToolbar(editor) {
11346
11413
  const quickToolbarRef = THE_EDITOR_QUICK_TOOLBAR_REF.get(editor);
11347
11414
  if (quickToolbarRef) {
11348
11415
  quickToolbarRef.close();
11349
11416
  THE_EDITOR_QUICK_TOOLBAR_REF.set(editor, null);
11350
11417
  }
11351
11418
  },
11352
- isOpenToolbar(editor, opTypes = OperationTypes) {
11353
- const isCollapsedCursor = TheEditor.isFocused(editor) && editor.selection && Range.isCollapsed(editor.selection);
11354
- if (!isCollapsedCursor) {
11355
- return false;
11356
- }
11357
- const block = Node.ancestor(editor, [editor.selection.anchor.path[0]]);
11358
- const { undos } = editor.history;
11359
- const lastBatch = undos[undos.length - 1];
11360
- const lastOp = lastBatch && lastBatch[lastBatch.length - 1];
11361
- if (lastOp &&
11362
- block.children.length === 1 &&
11363
- block.type === ElementKinds.paragraph &&
11364
- Node.string(block) === QUICK_TOOLBAR_HOTKEY &&
11365
- opTypes.includes(lastOp.type) &&
11366
- (lastOp.text === QUICK_TOOLBAR_HOTKEY || lastOp.text === undefined)) {
11367
- return true;
11368
- }
11369
- return false;
11419
+ isOpenedToolbar(editor) {
11420
+ const quickToolbarRef = THE_EDITOR_QUICK_TOOLBAR_REF.get(editor);
11421
+ return !!quickToolbarRef;
11370
11422
  }
11371
11423
  };
11372
11424
 
11373
11425
  const withQuickInsert = (editor) => {
11374
11426
  const { onKeydown, deleteBackward, onChange } = editor;
11427
+ let presseingQuickInsertHotkey = false;
11375
11428
  editor.onKeydown = (event) => {
11376
- if (event.key === QUICK_TOOLBAR_HOTKEY && isCleanEmptyParagraph(editor)) {
11377
- const rootNode = AngularEditor.toDOMNode(editor, Node.ancestor(editor, [editor.selection.anchor.path[0]]));
11378
- const theEditorComponent = editor.injector.get(TheEditorComponent);
11379
- const quickToolbars = theEditorComponent.quickToolbarItems;
11380
- const leafElement = rootNode.querySelector('[data-slate-leaf="true"]');
11381
- const origin = leafElement || rootNode;
11382
- QuickInsertEditor.openQuickToolbar(editor, quickToolbars, origin);
11429
+ var _a;
11430
+ if (event.key === QUICK_TOOLBAR_HOTKEY) {
11431
+ const types = [...(((_a = editor.options) === null || _a === void 0 ? void 0 : _a.triggerQuickToolbarTypes) || [])];
11432
+ const [block,] = getBlockAbove(editor);
11433
+ if (isPureEmptyParagraph(editor, block) && allowOpenQuickToolbar(editor, types)) {
11434
+ presseingQuickInsertHotkey = true;
11435
+ }
11383
11436
  }
11384
11437
  onKeydown(event);
11385
11438
  };
11386
11439
  editor.deleteBackward = unit => {
11387
- if (!QuickInsertEditor.isOpenToolbar(editor, ['remove_text'])) {
11388
- QuickInsertEditor.closeQuickToolbar(editor);
11440
+ if (QuickInsertEditor.isOpenedToolbar(editor)) {
11441
+ QuickInsertEditor.closeQuickInsertToolbar(editor);
11389
11442
  }
11390
11443
  deleteBackward(unit);
11391
11444
  };
@@ -11393,16 +11446,33 @@ const withQuickInsert = (editor) => {
11393
11446
  var _a;
11394
11447
  onChange();
11395
11448
  if (editor.selection) {
11449
+ const [block, path] = getBlockAbove(editor);
11450
+ // quick insert plus
11396
11451
  const editorComponent = editor.injector.get(TheEditorComponent);
11397
11452
  (_a = editorComponent.quickInsertInstance) === null || _a === void 0 ? void 0 : _a.checkStatus();
11398
- const block = Node.ancestor(editor, [editor.selection.anchor.path[0]]);
11399
- if (!isCleanEmptyParagraph(editor) && Node.string(block) !== QUICK_TOOLBAR_HOTKEY) {
11400
- QuickInsertEditor.closeQuickToolbar(editor);
11453
+ if (presseingQuickInsertHotkey && Node.string(block) === QUICK_TOOLBAR_HOTKEY) {
11454
+ QuickInsertEditor.openQuickInsertToolbar(editor, editorComponent.quickToolbarItems);
11455
+ presseingQuickInsertHotkey = false;
11456
+ return;
11457
+ }
11458
+ else {
11459
+ presseingQuickInsertHotkey = false;
11460
+ }
11461
+ if (QuickInsertEditor.isOpenedToolbar(editor) && !isPureEmptyParagraph(editor, block) && Node.string(block) !== QUICK_TOOLBAR_HOTKEY) {
11462
+ QuickInsertEditor.closeQuickInsertToolbar(editor);
11401
11463
  }
11402
11464
  }
11403
11465
  };
11404
11466
  return editor;
11405
11467
  };
11468
+ const allowOpenQuickToolbar = (editor, allowTypes) => {
11469
+ const [block, path] = getBlockAbove(editor);
11470
+ const parentNode = Node.parent(editor, path);
11471
+ if (path.length === 1 || (parentNode && allowTypes.includes(parentNode.type))) {
11472
+ return true;
11473
+ }
11474
+ return false;
11475
+ };
11406
11476
 
11407
11477
  const withSoftBreak = (options = { rules: [{ hotkey: 'shift+enter' }] }) => (editor) => {
11408
11478
  const { onKeydown } = editor;
@@ -11692,6 +11762,78 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
11692
11762
  args: ['class.disabled']
11693
11763
  }] } });
11694
11764
 
11765
+ const onKeydownTextIndent = (editor, event, kinds, textIndentDisabled) => {
11766
+ const { selection } = editor;
11767
+ const isExpanded = Range.isExpanded(selection);
11768
+ const nodes = Array.from(Editor.nodes(editor, {
11769
+ mode: 'highest',
11770
+ match: node => Element$1.isElement(node) && kinds.includes(node.type)
11771
+ }));
11772
+ const [startBlock] = nodes;
11773
+ if (!startBlock) {
11774
+ return false;
11775
+ }
11776
+ const [block, path] = startBlock;
11777
+ const isStart = Editor.isStart(editor, selection.anchor, path);
11778
+ if (isKeyHotkey('Tab', event)) {
11779
+ event.preventDefault();
11780
+ if (startBlock && (isExpanded || isStart)) {
11781
+ if (!editor.isVoid(block)) {
11782
+ let { textIndent, type } = block;
11783
+ // do not apply first-line indentation for lists
11784
+ if (!textIndent && !textIndentDisabled.includes(type)) {
11785
+ IndentEditor.setTextIndent(editor, kinds, 2);
11786
+ return true;
11787
+ }
11788
+ else {
11789
+ IndentEditor.setIndent(editor);
11790
+ return true;
11791
+ }
11792
+ }
11793
+ }
11794
+ else {
11795
+ editor.insertText(TAB_SPACE);
11796
+ return true;
11797
+ }
11798
+ }
11799
+ if (isKeyHotkey('shift+Tab', event)) {
11800
+ if (startBlock && (isExpanded || isStart)) {
11801
+ if (!editor.isVoid(block)) {
11802
+ return IndentEditor.cancelTextIntent(editor, event, block, kinds);
11803
+ }
11804
+ }
11805
+ }
11806
+ if (selection && Range.isCollapsed(selection) && hotkeys.isDeleteBackward(event)) {
11807
+ if (startBlock && isStart) {
11808
+ return IndentEditor.cancelTextIntent(editor, event, block, kinds);
11809
+ }
11810
+ }
11811
+ return false;
11812
+ };
11813
+
11814
+ const withIndent = (kinds) => (editor) => {
11815
+ const { onKeydown } = editor;
11816
+ editor.onKeydown = (event) => {
11817
+ var _a, _b, _c, _d;
11818
+ let indentTypes = kinds;
11819
+ let disableIndentTypes = [ElementKinds.bulletedList, ElementKinds.numberedList, ElementKinds.checkItem];
11820
+ if ((_b = (_a = editor.extraIndentOptions) === null || _a === void 0 ? void 0 : _a.indentTypes) === null || _b === void 0 ? void 0 : _b.length) {
11821
+ indentTypes = mergIndentTypes(kinds, editor.extraIndentOptions.indentTypes);
11822
+ }
11823
+ if ((_d = (_c = editor.extraIndentOptions) === null || _c === void 0 ? void 0 : _c.disabledIndentTypes) === null || _d === void 0 ? void 0 : _d.length) {
11824
+ disableIndentTypes = mergIndentTypes(disableIndentTypes, editor.extraIndentOptions.disabledIndentTypes);
11825
+ }
11826
+ const isContinue = !onKeydownTextIndent(editor, event, indentTypes, disableIndentTypes);
11827
+ if (isContinue) {
11828
+ onKeydown(event);
11829
+ }
11830
+ };
11831
+ return editor;
11832
+ };
11833
+ const mergIndentTypes = (defaultTypes, indentTypes) => {
11834
+ return Array.from(new Set([...defaultTypes, ...indentTypes]));
11835
+ };
11836
+
11695
11837
  const MaxIndent = 11;
11696
11838
  const includesIndentTypes = [
11697
11839
  ElementKinds.checkItem,
@@ -11700,11 +11842,15 @@ const includesIndentTypes = [
11700
11842
  ElementKinds.paragraph,
11701
11843
  ...HEADING_TYPES
11702
11844
  ];
11845
+ const getIndentTypes = editor => {
11846
+ let indentTypes = editor.extraIndentOptions ? editor.extraIndentOptions.indentTypes : [];
11847
+ return mergIndentTypes(includesIndentTypes, indentTypes);
11848
+ };
11703
11849
  const IndentEditor = {
11704
11850
  setIndent(editor) {
11705
11851
  const nodes = Array.from(Editor.nodes(editor, {
11706
11852
  mode: 'highest',
11707
- match: n => Element$1.isElement(n) && includesIndentTypes.includes(n.type)
11853
+ match: n => Element$1.isElement(n) && getIndentTypes(editor).includes(n.type)
11708
11854
  }));
11709
11855
  const [startBlock] = nodes;
11710
11856
  if (startBlock) {
@@ -11714,7 +11860,7 @@ const IndentEditor = {
11714
11860
  if (indent <= MaxIndent) {
11715
11861
  Transforms.setNodes(editor, { indent }, {
11716
11862
  mode: 'highest',
11717
- match: n => Element$1.isElement(n) && includesIndentTypes.includes(n.type)
11863
+ match: n => Element$1.isElement(n) && getIndentTypes(editor).includes(n.type)
11718
11864
  });
11719
11865
  }
11720
11866
  }
@@ -11722,7 +11868,7 @@ const IndentEditor = {
11722
11868
  cancelIndent(editor) {
11723
11869
  const nodes = Array.from(Editor.nodes(editor, {
11724
11870
  mode: 'highest',
11725
- match: n => Element$1.isElement(n) && includesIndentTypes.includes(n.type)
11871
+ match: n => Element$1.isElement(n) && getIndentTypes(editor).includes(n.type)
11726
11872
  }));
11727
11873
  const [startBlock] = nodes;
11728
11874
  if (startBlock) {
@@ -11730,7 +11876,7 @@ const IndentEditor = {
11730
11876
  indent = indent === 1 ? null : (indent -= 1);
11731
11877
  Transforms.setNodes(editor, { indent }, {
11732
11878
  mode: 'highest',
11733
- match: n => Element$1.isElement(n) && includesIndentTypes.includes(n.type)
11879
+ match: n => Element$1.isElement(n) && getIndentTypes(editor).includes(n.type)
11734
11880
  });
11735
11881
  }
11736
11882
  },
@@ -11762,15 +11908,8 @@ const IndentEditor = {
11762
11908
  },
11763
11909
  isDisabled(editor) {
11764
11910
  if (editor.selection) {
11765
- const allowGroup = [
11766
- ElementKinds.paragraph,
11767
- ElementKinds.numberedList,
11768
- ElementKinds.bulletedList,
11769
- ElementKinds.checkItem,
11770
- ...HEADING_TYPES
11771
- ];
11772
11911
  const anchorBlock$1 = anchorBlock(editor);
11773
- return anchorBlock$1 && !allowGroup.includes(anchorBlock$1 === null || anchorBlock$1 === void 0 ? void 0 : anchorBlock$1.type);
11912
+ return anchorBlock$1 && !getIndentTypes(editor).includes(anchorBlock$1 === null || anchorBlock$1 === void 0 ? void 0 : anchorBlock$1.type);
11774
11913
  }
11775
11914
  return false;
11776
11915
  }
@@ -11800,67 +11939,6 @@ const IndentOptions = [
11800
11939
  }
11801
11940
  ];
11802
11941
 
11803
- const onKeydownTextIndent = (editor, event, kinds) => {
11804
- const { selection } = editor;
11805
- const isExpanded = Range.isExpanded(selection);
11806
- const nodes = Array.from(Editor.nodes(editor, {
11807
- mode: 'highest',
11808
- match: node => Element$1.isElement(node) && kinds.includes(node.type)
11809
- }));
11810
- const [startBlock] = nodes;
11811
- if (!startBlock) {
11812
- return false;
11813
- }
11814
- const [block, path] = startBlock;
11815
- const isStart = Editor.isStart(editor, selection.anchor, path);
11816
- const textIndentDisable = [ElementKinds.bulletedList, ElementKinds.numberedList, ElementKinds.checkItem];
11817
- if (isKeyHotkey('Tab', event)) {
11818
- event.preventDefault();
11819
- if (startBlock && (isExpanded || isStart)) {
11820
- if (!editor.isVoid(block)) {
11821
- let { textIndent, type } = block;
11822
- // do not apply first-line indentation for lists
11823
- if (!textIndent && !textIndentDisable.includes(type)) {
11824
- IndentEditor.setTextIndent(editor, kinds, 2);
11825
- return true;
11826
- }
11827
- else {
11828
- IndentEditor.setIndent(editor);
11829
- return true;
11830
- }
11831
- }
11832
- }
11833
- else {
11834
- editor.insertText(TAB_SPACE);
11835
- return true;
11836
- }
11837
- }
11838
- if (isKeyHotkey('shift+Tab', event)) {
11839
- if (startBlock && (isExpanded || isStart)) {
11840
- if (!editor.isVoid(block)) {
11841
- return IndentEditor.cancelTextIntent(editor, event, block, kinds);
11842
- }
11843
- }
11844
- }
11845
- if (selection && Range.isCollapsed(selection) && hotkeys.isDeleteBackward(event)) {
11846
- if (startBlock && isStart) {
11847
- return IndentEditor.cancelTextIntent(editor, event, block, kinds);
11848
- }
11849
- }
11850
- return false;
11851
- };
11852
-
11853
- const withIndent = (kinds) => (editor) => {
11854
- const { onKeydown } = editor;
11855
- editor.onKeydown = (event) => {
11856
- const isContinue = !onKeydownTextIndent(editor, event, kinds);
11857
- if (isContinue) {
11858
- onKeydown(event);
11859
- }
11860
- };
11861
- return editor;
11862
- };
11863
-
11864
11942
  const internalPlugins = [
11865
11943
  withTheHistory,
11866
11944
  withAutoInsertData(),
@@ -11891,7 +11969,7 @@ const internalPlugins = [
11891
11969
  }),
11892
11970
  withBlockquote,
11893
11971
  withNodeID({ idKey: ELEMENT_UNIQUE_ID, idCreator }),
11894
- withAutoFormat({ rules: autoFormatRules }),
11972
+ withAutoFormat(),
11895
11973
  withTransforms(),
11896
11974
  withTrailingNode({ type: ElementKinds.paragraph, level: 0 }),
11897
11975
  withMoveSelection,
@@ -12483,7 +12561,11 @@ class TheQuickInsertComponent {
12483
12561
  handleClick(event) {
12484
12562
  event.stopPropagation();
12485
12563
  event.preventDefault();
12486
- QuickInsertEditor.openQuickToolbar(this.editor, this.quickToolbarItems, this.iconElement.nativeElement);
12564
+ if (QuickInsertEditor.isOpenedToolbar(this.editor)) {
12565
+ QuickInsertEditor.closeQuickInsertToolbar(this.editor);
12566
+ return;
12567
+ }
12568
+ QuickInsertEditor.openQuickInsertToolbar(this.editor, this.quickToolbarItems, this.iconElement.nativeElement);
12487
12569
  }
12488
12570
  }
12489
12571
  TheQuickInsertComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: TheQuickInsertComponent, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
@@ -12756,11 +12838,14 @@ class TheEditorComponent extends mixinUnsubscribe(MixinBase) {
12756
12838
  super.ngOnDestroy();
12757
12839
  }
12758
12840
  initialize() {
12759
- var _a, _b;
12841
+ var _a, _b, _c, _d;
12760
12842
  this.editor = withTheEditor(this.thePlugins, withHistory(withAngular(createEditor(), CLIPBOARD_FORMAT_KEY)));
12761
12843
  this.generateDecorate();
12762
12844
  this.editor.disabled = (_a = this.theOptions) === null || _a === void 0 ? void 0 : _a.disabled;
12763
12845
  this.editor.extraElementOptions = (_b = this.theOptions) === null || _b === void 0 ? void 0 : _b.extraElementOptions;
12846
+ this.editor.extraAutoFormatRules = (_c = this.theOptions) === null || _c === void 0 ? void 0 : _c.extraAutoFormatRules;
12847
+ this.editor.extraIndentOptions = (_d = this.theOptions) === null || _d === void 0 ? void 0 : _d.extraIndentOptions;
12848
+ this.editor.options = this.theOptions;
12764
12849
  setEditorUUID(this.editor, idCreator());
12765
12850
  this.theContextService.initialize({
12766
12851
  theOptions: this.theOptions,
@@ -13305,5 +13390,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
13305
13390
  * Generated bundle index. Do not edit.
13306
13391
  */
13307
13392
 
13308
- export { ALIGN_BLOCK_TYPES, A_TAG_REL_ATTR, AlignEditor, Alignment, BLOCK_DELETEBACKWARD_TYPES, BlockquoteEditor, CLIPBOARD_FORMAT_KEY, CODEMIRROR_PADDING_TOP, CODE_MODES, COMPONENTS, CONTAINER_BLOCKS, CONTROL_KEY, CodeEditor, CodeMode, ColorEditor, DEFAULT_LANGUAGE, DEFAULT_SCROLL_CONTAINER, DefaultElementOptions, DefaultGlobalToolbarDefinition, DefaultInlineToolbarDefinition, DefaultQuickToolbarDefinition, DropdownMode, ELEMENT_UNIQUE_ID, ElementKinds, ErrorCodes, FontSizeTypes, FontSizes, HEADING_TYPES, HeadingEditor, HrEditor, IS_MAC, ImageEditor, Indents, LINK_DEFAULT_TEXT, LIST_BLOCK_TYPES, LayoutTypes, LinkEditor, ListEditor, MarkEditor, MarkProps, MarkTypes, PICTURE_ACCEPTED_UPLOAD_MIME, PICTURE_ACCEPTED_UPLOAD_SIZE, PLUGIN_COMPONENTS, QUICK_TOOLBAR_HOTKEY, QuickInsertEditor, STANDARD_HEADING_TYPES, TAB_SPACE, THE_CODE_MODE_PROVIDER, THE_CODE_MODE_TOKEN, THE_EDITOR_CONVERSION_HINT_REF, THE_EDITOR_QUICK_TOOLBAR_REF, THE_EDITOR_UUID, THE_INLINE_TOOLBAR_TYPES, THE_UPLOAD_SERVICE_TOKEN, TableEditor, TheBaseElementComponent, TheCodeConfig, TheContextService, TheDataMode, TheDefaultElementComponent, TheEditor, TheEditorComponent, TheEditorModule, TheImageComponent, TheMode, index$1 as TheQueries, TheToolbarBaseItemComponent, TheToolbarComponent, TheToolbarDropdownComponent, TheToolbarGroupComponent, TheToolbarGroupToken, TheToolbarItemComponent, TheToolbarService, index as TheTransforms, TodoItemEditor, ToolbarActionTypes, ToolbarAlignment, ToolbarItemMode, ToolbarItemType, ToolbarMoreGroup, VOID_BLOCK_TYPES, VerticalAlignEditor, VerticalAlignment, ZERO_WIDTH_CHAR, coercePixelsFromCssValue, createEmptyParagraph, dataDeserialize, dataSerializing, getColsTotalWidth, getElementClassByPrefix, getElementHeight, getElementWidth, getRowsTotalHeight, getToolbarClass, htmlToTheia, inValidTypes, isCleanEmptyParagraph, mergeElementOptions, plainToTheia, toolbarCompose, useElementStyle, withTheEditor };
13393
+ export { ALIGN_BLOCK_TYPES, A_TAG_REL_ATTR, AlignEditor, Alignment, BLOCK_DELETEBACKWARD_TYPES, BlockquoteEditor, CLIPBOARD_FORMAT_KEY, CODEMIRROR_PADDING_TOP, CODE_MODES, COMPONENTS, CONTAINER_BLOCKS, CONTROL_KEY, CodeEditor, CodeMode, ColorEditor, DEFAULT_LANGUAGE, DEFAULT_SCROLL_CONTAINER, DefaultElementOptions, DefaultGlobalToolbarDefinition, DefaultInlineToolbarDefinition, DefaultQuickToolbarDefinition, DropdownMode, ELEMENT_UNIQUE_ID, ElementKinds, ErrorCodes, FontSizeTypes, FontSizes, HEADING_TYPES, HeadingEditor, HrEditor, IS_MAC, ImageEditor, Indents, LINK_DEFAULT_TEXT, LIST_BLOCK_TYPES, LayoutTypes, LinkEditor, ListEditor, MarkEditor, MarkProps, MarkTypes, PICTURE_ACCEPTED_UPLOAD_MIME, PICTURE_ACCEPTED_UPLOAD_SIZE, PLUGIN_COMPONENTS, QUICK_TOOLBAR_HOTKEY, QuickInsertEditor, STANDARD_HEADING_TYPES, TAB_SPACE, THE_CODE_MODE_PROVIDER, THE_CODE_MODE_TOKEN, THE_EDITOR_CONVERSION_HINT_REF, THE_EDITOR_QUICK_TOOLBAR_REF, THE_EDITOR_UUID, THE_INLINE_TOOLBAR_TYPES, THE_UPLOAD_SERVICE_TOKEN, TableEditor, TheBaseElementComponent, TheCodeConfig, TheContextService, TheDataMode, TheDefaultElementComponent, TheEditor, TheEditorComponent, TheEditorModule, TheImageComponent, TheMode, index$1 as TheQueries, TheToolbarBaseItemComponent, TheToolbarComponent, TheToolbarDropdownComponent, TheToolbarGroupComponent, TheToolbarGroupToken, TheToolbarItemComponent, TheToolbarService, index as TheTransforms, TodoItemEditor, ToolbarActionTypes, ToolbarAlignment, ToolbarItemMode, ToolbarItemType, ToolbarMoreGroup, VOID_BLOCK_TYPES, VerticalAlignEditor, VerticalAlignment, ZERO_WIDTH_CHAR, coercePixelsFromCssValue, createEmptyParagraph, dataDeserialize, dataSerializing, getColsTotalWidth, getElementClassByPrefix, getElementHeight, getElementWidth, getRowsTotalHeight, getToolbarClass, htmlToTheia, inValidTypes, isCleanEmptyParagraph, isPureEmptyParagraph, mergeElementOptions, plainToTheia, toolbarCompose, useElementStyle, withTheEditor };
13309
13394
  //# sourceMappingURL=worktile-theia.js.map