@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.
@@ -0,0 +1,12 @@
1
+ import { RawCommands } from '../types';
2
+ declare module '@tiptap/core' {
3
+ interface Commands<ReturnType> {
4
+ selectTextblockEnd: {
5
+ /**
6
+ * Moves the cursor to the end of current text block.
7
+ */
8
+ selectTextblockEnd: () => ReturnType;
9
+ };
10
+ }
11
+ }
12
+ export declare const selectTextblockEnd: RawCommands['selectTextblockEnd'];
@@ -0,0 +1,12 @@
1
+ import { RawCommands } from '../types';
2
+ declare module '@tiptap/core' {
3
+ interface Commands<ReturnType> {
4
+ selectTextblockStart: {
5
+ /**
6
+ * Moves the cursor to the start of current text block.
7
+ */
8
+ selectTextblockStart: () => ReturnType;
9
+ };
10
+ }
11
+ }
12
+ export declare const selectTextblockStart: RawCommands['selectTextblockStart'];
@@ -28,6 +28,8 @@ import * as selectAll from '../commands/selectAll';
28
28
  import * as selectNodeBackward from '../commands/selectNodeBackward';
29
29
  import * as selectNodeForward from '../commands/selectNodeForward';
30
30
  import * as selectParentNode from '../commands/selectParentNode';
31
+ import * as selectTextblockEnd from '../commands/selectTextblockEnd';
32
+ import * as selectTextblockStart from '../commands/selectTextblockStart';
31
33
  import * as setContent from '../commands/setContent';
32
34
  import * as setMark from '../commands/setMark';
33
35
  import * as setMeta from '../commands/setMeta';
@@ -76,6 +78,8 @@ export { selectAll };
76
78
  export { selectNodeBackward };
77
79
  export { selectNodeForward };
78
80
  export { selectParentNode };
81
+ export { selectTextblockEnd };
82
+ export { selectTextblockStart };
79
83
  export { setContent };
80
84
  export { setMark };
81
85
  export { setMeta };
@@ -0,0 +1 @@
1
+ export declare function isMacOS(): boolean;
@@ -210,8 +210,12 @@ const ClipboardTextSerializer = Extension.create({
210
210
 
211
211
  const blur = () => ({ editor, view }) => {
212
212
  requestAnimationFrame(() => {
213
+ var _a;
213
214
  if (!editor.isDestroyed) {
214
215
  view.dom.blur();
216
+ // Browsers should remove the caret on blur but safari does not.
217
+ // See: https://github.com/ueberdosis/tiptap/issues/2405
218
+ (_a = window === null || window === void 0 ? void 0 : window.getSelection()) === null || _a === void 0 ? void 0 : _a.removeAllRanges();
215
219
  }
216
220
  });
217
221
  return true;
@@ -670,6 +674,7 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
670
674
  let { from, to } = typeof position === 'number'
671
675
  ? { from: position, to: position }
672
676
  : position;
677
+ let isOnlyTextContent = true;
673
678
  let isOnlyBlockContent = true;
674
679
  const nodes = isFragment(content)
675
680
  ? content
@@ -677,6 +682,9 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
677
682
  nodes.forEach(node => {
678
683
  // check if added node is valid
679
684
  node.check();
685
+ isOnlyTextContent = isOnlyTextContent
686
+ ? node.isText && node.marks.length === 0
687
+ : false;
680
688
  isOnlyBlockContent = isOnlyBlockContent
681
689
  ? node.isBlock
682
690
  : false;
@@ -696,7 +704,14 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
696
704
  to += 1;
697
705
  }
698
706
  }
699
- tr.replaceWith(from, to, content);
707
+ // if there is only plain text we have to use `insertText`
708
+ // because this will keep the current marks
709
+ if (isOnlyTextContent) {
710
+ tr.insertText(value, from, to);
711
+ }
712
+ else {
713
+ tr.replaceWith(from, to, content);
714
+ }
700
715
  // set cursor at end of inserted content
701
716
  if (options.updateSelection) {
702
717
  selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
@@ -728,7 +743,12 @@ var joinForward$1 = /*#__PURE__*/Object.freeze({
728
743
  joinForward: joinForward
729
744
  });
730
745
 
731
- const mac = typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false;
746
+ function isMacOS() {
747
+ return typeof navigator !== 'undefined'
748
+ ? /Mac/.test(navigator.platform)
749
+ : false;
750
+ }
751
+
732
752
  function normalizeKeyName(name) {
733
753
  const parts = name.split(/-(?!$)/);
734
754
  let result = parts[parts.length - 1];
@@ -754,7 +774,7 @@ function normalizeKeyName(name) {
754
774
  shift = true;
755
775
  }
756
776
  else if (/^mod$/i.test(mod)) {
757
- if (mac) {
777
+ if (isiOS() || isMacOS()) {
758
778
  meta = true;
759
779
  }
760
780
  else {
@@ -1006,6 +1026,26 @@ var selectParentNode$1 = /*#__PURE__*/Object.freeze({
1006
1026
  selectParentNode: selectParentNode
1007
1027
  });
1008
1028
 
1029
+ // @ts-ignore
1030
+ const selectTextblockEnd = () => ({ state, dispatch }) => {
1031
+ return prosemirrorCommands.selectTextblockEnd(state, dispatch);
1032
+ };
1033
+
1034
+ var selectTextblockEnd$1 = /*#__PURE__*/Object.freeze({
1035
+ __proto__: null,
1036
+ selectTextblockEnd: selectTextblockEnd
1037
+ });
1038
+
1039
+ // @ts-ignore
1040
+ const selectTextblockStart = () => ({ state, dispatch }) => {
1041
+ return prosemirrorCommands.selectTextblockStart(state, dispatch);
1042
+ };
1043
+
1044
+ var selectTextblockStart$1 = /*#__PURE__*/Object.freeze({
1045
+ __proto__: null,
1046
+ selectTextblockStart: selectTextblockStart
1047
+ });
1048
+
1009
1049
  function createDocument(content, schema, parseOptions = {}) {
1010
1050
  return createNodeFromContent(content, schema, { slice: false, parseOptions });
1011
1051
  }
@@ -1804,6 +1844,8 @@ const Commands = Extension.create({
1804
1844
  ...selectNodeBackward$1,
1805
1845
  ...selectNodeForward$1,
1806
1846
  ...selectParentNode$1,
1847
+ ...selectTextblockEnd$1,
1848
+ ...selectTextblockStart$1,
1807
1849
  ...setContent$1,
1808
1850
  ...setMark$1,
1809
1851
  ...setMeta$1,
@@ -2043,13 +2085,14 @@ const Keymap = Extension.create({
2043
2085
  () => commands.joinForward(),
2044
2086
  () => commands.selectNodeForward(),
2045
2087
  ]);
2046
- return {
2047
- Enter: () => this.editor.commands.first(({ commands }) => [
2048
- () => commands.newlineInCode(),
2049
- () => commands.createParagraphNear(),
2050
- () => commands.liftEmptyBlock(),
2051
- () => commands.splitBlock(),
2052
- ]),
2088
+ const handleEnter = () => this.editor.commands.first(({ commands }) => [
2089
+ () => commands.newlineInCode(),
2090
+ () => commands.createParagraphNear(),
2091
+ () => commands.liftEmptyBlock(),
2092
+ () => commands.splitBlock(),
2093
+ ]);
2094
+ const baseKeymap = {
2095
+ Enter: handleEnter,
2053
2096
  'Mod-Enter': () => this.editor.commands.exitCode(),
2054
2097
  Backspace: handleBackspace,
2055
2098
  'Mod-Backspace': handleBackspace,
@@ -2058,6 +2101,26 @@ const Keymap = Extension.create({
2058
2101
  'Mod-Delete': handleDelete,
2059
2102
  'Mod-a': () => this.editor.commands.selectAll(),
2060
2103
  };
2104
+ const pcKeymap = {
2105
+ ...baseKeymap,
2106
+ Home: () => this.editor.commands.selectTextblockStart(),
2107
+ End: () => this.editor.commands.selectTextblockStart(),
2108
+ };
2109
+ const macKeymap = {
2110
+ ...baseKeymap,
2111
+ 'Ctrl-h': handleBackspace,
2112
+ 'Alt-Backspace': handleBackspace,
2113
+ 'Ctrl-d': handleDelete,
2114
+ 'Ctrl-Alt-Backspace': handleDelete,
2115
+ 'Alt-Delete': handleDelete,
2116
+ 'Alt-d': handleDelete,
2117
+ 'Ctrl-a': () => this.editor.commands.selectTextblockStart(),
2118
+ 'Ctrl-e': () => this.editor.commands.selectTextblockEnd(),
2119
+ };
2120
+ if (isiOS() || isMacOS()) {
2121
+ return macKeymap;
2122
+ }
2123
+ return pcKeymap;
2061
2124
  },
2062
2125
  addProseMirrorPlugins() {
2063
2126
  return [
@@ -2677,15 +2740,10 @@ function injectExtensionAttributesToParseRule(parseRule, extensionAttributes) {
2677
2740
  if (oldAttributes === false) {
2678
2741
  return false;
2679
2742
  }
2680
- const newAttributes = extensionAttributes
2681
- .filter(item => item.attribute.rendered)
2682
- .reduce((items, item) => {
2743
+ const newAttributes = extensionAttributes.reduce((items, item) => {
2683
2744
  const value = item.attribute.parseHTML
2684
2745
  ? item.attribute.parseHTML(node)
2685
2746
  : fromString(node.getAttribute(item.name));
2686
- if (isObject(value)) {
2687
- 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`);
2688
- }
2689
2747
  if (value === null || value === undefined) {
2690
2748
  return items;
2691
2749
  }