@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.
@@ -1,6 +1,6 @@
1
1
  import { Plugin, PluginKey, TextSelection, Selection, NodeSelection, EditorState } from 'prosemirror-state';
2
2
  import { liftTarget, ReplaceStep, ReplaceAroundStep, canSplit, canJoin, findWrapping, Transform } from 'prosemirror-transform';
3
- import { createParagraphNear as createParagraphNear$2, deleteSelection as deleteSelection$2, exitCode as exitCode$2, joinBackward as joinBackward$2, joinForward as joinForward$2, lift as lift$2, liftEmptyBlock as liftEmptyBlock$2, newlineInCode as newlineInCode$2, selectNodeBackward as selectNodeBackward$2, selectNodeForward as selectNodeForward$2, selectParentNode as selectParentNode$2, setBlockType, wrapIn as wrapIn$2 } from 'prosemirror-commands';
3
+ import { createParagraphNear as createParagraphNear$2, deleteSelection as deleteSelection$2, exitCode as exitCode$2, joinBackward as joinBackward$2, joinForward as joinForward$2, lift as lift$2, liftEmptyBlock as liftEmptyBlock$2, newlineInCode as newlineInCode$2, selectNodeBackward as selectNodeBackward$2, selectNodeForward as selectNodeForward$2, selectParentNode as selectParentNode$2, selectTextblockEnd as selectTextblockEnd$2, selectTextblockStart as selectTextblockStart$2, setBlockType, wrapIn as wrapIn$2 } from 'prosemirror-commands';
4
4
  import { Fragment, DOMParser, Slice, DOMSerializer, Schema, Node as Node$1 } from 'prosemirror-model';
5
5
  import { liftListItem as liftListItem$2, sinkListItem as sinkListItem$2, wrapInList as wrapInList$2 } from 'prosemirror-schema-list';
6
6
  import { EditorView } from 'prosemirror-view';
@@ -206,8 +206,12 @@ const ClipboardTextSerializer = Extension.create({
206
206
 
207
207
  const blur = () => ({ editor, view }) => {
208
208
  requestAnimationFrame(() => {
209
+ var _a;
209
210
  if (!editor.isDestroyed) {
210
211
  view.dom.blur();
212
+ // Browsers should remove the caret on blur but safari does not.
213
+ // See: https://github.com/ueberdosis/tiptap/issues/2405
214
+ (_a = window === null || window === void 0 ? void 0 : window.getSelection()) === null || _a === void 0 ? void 0 : _a.removeAllRanges();
211
215
  }
212
216
  });
213
217
  return true;
@@ -666,6 +670,7 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
666
670
  let { from, to } = typeof position === 'number'
667
671
  ? { from: position, to: position }
668
672
  : position;
673
+ let isOnlyTextContent = true;
669
674
  let isOnlyBlockContent = true;
670
675
  const nodes = isFragment(content)
671
676
  ? content
@@ -673,6 +678,9 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
673
678
  nodes.forEach(node => {
674
679
  // check if added node is valid
675
680
  node.check();
681
+ isOnlyTextContent = isOnlyTextContent
682
+ ? node.isText && node.marks.length === 0
683
+ : false;
676
684
  isOnlyBlockContent = isOnlyBlockContent
677
685
  ? node.isBlock
678
686
  : false;
@@ -692,7 +700,14 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
692
700
  to += 1;
693
701
  }
694
702
  }
695
- tr.replaceWith(from, to, content);
703
+ // if there is only plain text we have to use `insertText`
704
+ // because this will keep the current marks
705
+ if (isOnlyTextContent) {
706
+ tr.insertText(value, from, to);
707
+ }
708
+ else {
709
+ tr.replaceWith(from, to, content);
710
+ }
696
711
  // set cursor at end of inserted content
697
712
  if (options.updateSelection) {
698
713
  selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
@@ -724,7 +739,12 @@ var joinForward$1 = /*#__PURE__*/Object.freeze({
724
739
  joinForward: joinForward
725
740
  });
726
741
 
727
- const mac = typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false;
742
+ function isMacOS() {
743
+ return typeof navigator !== 'undefined'
744
+ ? /Mac/.test(navigator.platform)
745
+ : false;
746
+ }
747
+
728
748
  function normalizeKeyName(name) {
729
749
  const parts = name.split(/-(?!$)/);
730
750
  let result = parts[parts.length - 1];
@@ -750,7 +770,7 @@ function normalizeKeyName(name) {
750
770
  shift = true;
751
771
  }
752
772
  else if (/^mod$/i.test(mod)) {
753
- if (mac) {
773
+ if (isiOS() || isMacOS()) {
754
774
  meta = true;
755
775
  }
756
776
  else {
@@ -1002,6 +1022,26 @@ var selectParentNode$1 = /*#__PURE__*/Object.freeze({
1002
1022
  selectParentNode: selectParentNode
1003
1023
  });
1004
1024
 
1025
+ // @ts-ignore
1026
+ const selectTextblockEnd = () => ({ state, dispatch }) => {
1027
+ return selectTextblockEnd$2(state, dispatch);
1028
+ };
1029
+
1030
+ var selectTextblockEnd$1 = /*#__PURE__*/Object.freeze({
1031
+ __proto__: null,
1032
+ selectTextblockEnd: selectTextblockEnd
1033
+ });
1034
+
1035
+ // @ts-ignore
1036
+ const selectTextblockStart = () => ({ state, dispatch }) => {
1037
+ return selectTextblockStart$2(state, dispatch);
1038
+ };
1039
+
1040
+ var selectTextblockStart$1 = /*#__PURE__*/Object.freeze({
1041
+ __proto__: null,
1042
+ selectTextblockStart: selectTextblockStart
1043
+ });
1044
+
1005
1045
  function createDocument(content, schema, parseOptions = {}) {
1006
1046
  return createNodeFromContent(content, schema, { slice: false, parseOptions });
1007
1047
  }
@@ -1800,6 +1840,8 @@ const Commands = Extension.create({
1800
1840
  ...selectNodeBackward$1,
1801
1841
  ...selectNodeForward$1,
1802
1842
  ...selectParentNode$1,
1843
+ ...selectTextblockEnd$1,
1844
+ ...selectTextblockStart$1,
1803
1845
  ...setContent$1,
1804
1846
  ...setMark$1,
1805
1847
  ...setMeta$1,
@@ -2039,13 +2081,14 @@ const Keymap = Extension.create({
2039
2081
  () => commands.joinForward(),
2040
2082
  () => commands.selectNodeForward(),
2041
2083
  ]);
2042
- return {
2043
- Enter: () => this.editor.commands.first(({ commands }) => [
2044
- () => commands.newlineInCode(),
2045
- () => commands.createParagraphNear(),
2046
- () => commands.liftEmptyBlock(),
2047
- () => commands.splitBlock(),
2048
- ]),
2084
+ const handleEnter = () => this.editor.commands.first(({ commands }) => [
2085
+ () => commands.newlineInCode(),
2086
+ () => commands.createParagraphNear(),
2087
+ () => commands.liftEmptyBlock(),
2088
+ () => commands.splitBlock(),
2089
+ ]);
2090
+ const baseKeymap = {
2091
+ Enter: handleEnter,
2049
2092
  'Mod-Enter': () => this.editor.commands.exitCode(),
2050
2093
  Backspace: handleBackspace,
2051
2094
  'Mod-Backspace': handleBackspace,
@@ -2054,6 +2097,26 @@ const Keymap = Extension.create({
2054
2097
  'Mod-Delete': handleDelete,
2055
2098
  'Mod-a': () => this.editor.commands.selectAll(),
2056
2099
  };
2100
+ const pcKeymap = {
2101
+ ...baseKeymap,
2102
+ Home: () => this.editor.commands.selectTextblockStart(),
2103
+ End: () => this.editor.commands.selectTextblockStart(),
2104
+ };
2105
+ const macKeymap = {
2106
+ ...baseKeymap,
2107
+ 'Ctrl-h': handleBackspace,
2108
+ 'Alt-Backspace': handleBackspace,
2109
+ 'Ctrl-d': handleDelete,
2110
+ 'Ctrl-Alt-Backspace': handleDelete,
2111
+ 'Alt-Delete': handleDelete,
2112
+ 'Alt-d': handleDelete,
2113
+ 'Ctrl-a': () => this.editor.commands.selectTextblockStart(),
2114
+ 'Ctrl-e': () => this.editor.commands.selectTextblockEnd(),
2115
+ };
2116
+ if (isiOS() || isMacOS()) {
2117
+ return macKeymap;
2118
+ }
2119
+ return pcKeymap;
2057
2120
  },
2058
2121
  addProseMirrorPlugins() {
2059
2122
  return [
@@ -2673,15 +2736,10 @@ function injectExtensionAttributesToParseRule(parseRule, extensionAttributes) {
2673
2736
  if (oldAttributes === false) {
2674
2737
  return false;
2675
2738
  }
2676
- const newAttributes = extensionAttributes
2677
- .filter(item => item.attribute.rendered)
2678
- .reduce((items, item) => {
2739
+ const newAttributes = extensionAttributes.reduce((items, item) => {
2679
2740
  const value = item.attribute.parseHTML
2680
2741
  ? item.attribute.parseHTML(node)
2681
2742
  : fromString(node.getAttribute(item.name));
2682
- if (isObject(value)) {
2683
- 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`);
2684
- }
2685
2743
  if (value === null || value === undefined) {
2686
2744
  return items;
2687
2745
  }