@tiptap/core 2.0.0-beta.164 → 2.0.0-beta.168

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.
@@ -204,8 +204,12 @@
204
204
 
205
205
  const blur = () => ({ editor, view }) => {
206
206
  requestAnimationFrame(() => {
207
+ var _a;
207
208
  if (!editor.isDestroyed) {
208
209
  view.dom.blur();
210
+ // Browsers should remove the caret on blur but safari does not.
211
+ // See: https://github.com/ueberdosis/tiptap/issues/2405
212
+ (_a = window === null || window === void 0 ? void 0 : window.getSelection()) === null || _a === void 0 ? void 0 : _a.removeAllRanges();
209
213
  }
210
214
  });
211
215
  return true;
@@ -664,6 +668,7 @@
664
668
  let { from, to } = typeof position === 'number'
665
669
  ? { from: position, to: position }
666
670
  : position;
671
+ let isOnlyTextContent = true;
667
672
  let isOnlyBlockContent = true;
668
673
  const nodes = isFragment(content)
669
674
  ? content
@@ -671,6 +676,9 @@
671
676
  nodes.forEach(node => {
672
677
  // check if added node is valid
673
678
  node.check();
679
+ isOnlyTextContent = isOnlyTextContent
680
+ ? node.isText && node.marks.length === 0
681
+ : false;
674
682
  isOnlyBlockContent = isOnlyBlockContent
675
683
  ? node.isBlock
676
684
  : false;
@@ -690,7 +698,14 @@
690
698
  to += 1;
691
699
  }
692
700
  }
693
- tr.replaceWith(from, to, content);
701
+ // if there is only plain text we have to use `insertText`
702
+ // because this will keep the current marks
703
+ if (isOnlyTextContent) {
704
+ tr.insertText(value, from, to);
705
+ }
706
+ else {
707
+ tr.replaceWith(from, to, content);
708
+ }
694
709
  // set cursor at end of inserted content
695
710
  if (options.updateSelection) {
696
711
  selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
@@ -722,7 +737,12 @@
722
737
  joinForward: joinForward
723
738
  });
724
739
 
725
- const mac = typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false;
740
+ function isMacOS() {
741
+ return typeof navigator !== 'undefined'
742
+ ? /Mac/.test(navigator.platform)
743
+ : false;
744
+ }
745
+
726
746
  function normalizeKeyName(name) {
727
747
  const parts = name.split(/-(?!$)/);
728
748
  let result = parts[parts.length - 1];
@@ -748,7 +768,7 @@
748
768
  shift = true;
749
769
  }
750
770
  else if (/^mod$/i.test(mod)) {
751
- if (mac) {
771
+ if (isiOS() || isMacOS()) {
752
772
  meta = true;
753
773
  }
754
774
  else {
@@ -1000,6 +1020,26 @@
1000
1020
  selectParentNode: selectParentNode
1001
1021
  });
1002
1022
 
1023
+ // @ts-ignore
1024
+ const selectTextblockEnd = () => ({ state, dispatch }) => {
1025
+ return prosemirrorCommands.selectTextblockEnd(state, dispatch);
1026
+ };
1027
+
1028
+ var selectTextblockEnd$1 = /*#__PURE__*/Object.freeze({
1029
+ __proto__: null,
1030
+ selectTextblockEnd: selectTextblockEnd
1031
+ });
1032
+
1033
+ // @ts-ignore
1034
+ const selectTextblockStart = () => ({ state, dispatch }) => {
1035
+ return prosemirrorCommands.selectTextblockStart(state, dispatch);
1036
+ };
1037
+
1038
+ var selectTextblockStart$1 = /*#__PURE__*/Object.freeze({
1039
+ __proto__: null,
1040
+ selectTextblockStart: selectTextblockStart
1041
+ });
1042
+
1003
1043
  function createDocument(content, schema, parseOptions = {}) {
1004
1044
  return createNodeFromContent(content, schema, { slice: false, parseOptions });
1005
1045
  }
@@ -1798,6 +1838,8 @@
1798
1838
  ...selectNodeBackward$1,
1799
1839
  ...selectNodeForward$1,
1800
1840
  ...selectParentNode$1,
1841
+ ...selectTextblockEnd$1,
1842
+ ...selectTextblockStart$1,
1801
1843
  ...setContent$1,
1802
1844
  ...setMark$1,
1803
1845
  ...setMeta$1,
@@ -2037,13 +2079,14 @@
2037
2079
  () => commands.joinForward(),
2038
2080
  () => commands.selectNodeForward(),
2039
2081
  ]);
2040
- return {
2041
- Enter: () => this.editor.commands.first(({ commands }) => [
2042
- () => commands.newlineInCode(),
2043
- () => commands.createParagraphNear(),
2044
- () => commands.liftEmptyBlock(),
2045
- () => commands.splitBlock(),
2046
- ]),
2082
+ const handleEnter = () => this.editor.commands.first(({ commands }) => [
2083
+ () => commands.newlineInCode(),
2084
+ () => commands.createParagraphNear(),
2085
+ () => commands.liftEmptyBlock(),
2086
+ () => commands.splitBlock(),
2087
+ ]);
2088
+ const baseKeymap = {
2089
+ Enter: handleEnter,
2047
2090
  'Mod-Enter': () => this.editor.commands.exitCode(),
2048
2091
  Backspace: handleBackspace,
2049
2092
  'Mod-Backspace': handleBackspace,
@@ -2052,6 +2095,26 @@
2052
2095
  'Mod-Delete': handleDelete,
2053
2096
  'Mod-a': () => this.editor.commands.selectAll(),
2054
2097
  };
2098
+ const pcKeymap = {
2099
+ ...baseKeymap,
2100
+ Home: () => this.editor.commands.selectTextblockStart(),
2101
+ End: () => this.editor.commands.selectTextblockStart(),
2102
+ };
2103
+ const macKeymap = {
2104
+ ...baseKeymap,
2105
+ 'Ctrl-h': handleBackspace,
2106
+ 'Alt-Backspace': handleBackspace,
2107
+ 'Ctrl-d': handleDelete,
2108
+ 'Ctrl-Alt-Backspace': handleDelete,
2109
+ 'Alt-Delete': handleDelete,
2110
+ 'Alt-d': handleDelete,
2111
+ 'Ctrl-a': () => this.editor.commands.selectTextblockStart(),
2112
+ 'Ctrl-e': () => this.editor.commands.selectTextblockEnd(),
2113
+ };
2114
+ if (isiOS() || isMacOS()) {
2115
+ return macKeymap;
2116
+ }
2117
+ return pcKeymap;
2055
2118
  },
2056
2119
  addProseMirrorPlugins() {
2057
2120
  return [
@@ -2671,15 +2734,10 @@
2671
2734
  if (oldAttributes === false) {
2672
2735
  return false;
2673
2736
  }
2674
- const newAttributes = extensionAttributes
2675
- .filter(item => item.attribute.rendered)
2676
- .reduce((items, item) => {
2737
+ const newAttributes = extensionAttributes.reduce((items, item) => {
2677
2738
  const value = item.attribute.parseHTML
2678
2739
  ? item.attribute.parseHTML(node)
2679
2740
  : fromString(node.getAttribute(item.name));
2680
- if (isObject(value)) {
2681
- console.warn(`[tiptap warn]: BREAKING CHANGE: "parseHTML" for your attribute "${item.name}" returns an object but should return the value itself. If this is expected you can ignore this message. This warning will be removed in one of the next releases. Further information: https://github.com/ueberdosis/tiptap/issues/1863`);
2682
- }
2683
2741
  if (value === null || value === undefined) {
2684
2742
  return items;
2685
2743
  }