@tiptap/core 2.0.0-beta.165 → 2.0.0-beta.169

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';
@@ -670,6 +670,7 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
670
670
  let { from, to } = typeof position === 'number'
671
671
  ? { from: position, to: position }
672
672
  : position;
673
+ let isOnlyTextContent = true;
673
674
  let isOnlyBlockContent = true;
674
675
  const nodes = isFragment(content)
675
676
  ? content
@@ -677,6 +678,9 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
677
678
  nodes.forEach(node => {
678
679
  // check if added node is valid
679
680
  node.check();
681
+ isOnlyTextContent = isOnlyTextContent
682
+ ? node.isText && node.marks.length === 0
683
+ : false;
680
684
  isOnlyBlockContent = isOnlyBlockContent
681
685
  ? node.isBlock
682
686
  : false;
@@ -696,7 +700,14 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
696
700
  to += 1;
697
701
  }
698
702
  }
699
- 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
+ }
700
711
  // set cursor at end of inserted content
701
712
  if (options.updateSelection) {
702
713
  selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
@@ -728,7 +739,12 @@ var joinForward$1 = /*#__PURE__*/Object.freeze({
728
739
  joinForward: joinForward
729
740
  });
730
741
 
731
- 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
+
732
748
  function normalizeKeyName(name) {
733
749
  const parts = name.split(/-(?!$)/);
734
750
  let result = parts[parts.length - 1];
@@ -754,7 +770,7 @@ function normalizeKeyName(name) {
754
770
  shift = true;
755
771
  }
756
772
  else if (/^mod$/i.test(mod)) {
757
- if (mac) {
773
+ if (isiOS() || isMacOS()) {
758
774
  meta = true;
759
775
  }
760
776
  else {
@@ -1006,6 +1022,26 @@ var selectParentNode$1 = /*#__PURE__*/Object.freeze({
1006
1022
  selectParentNode: selectParentNode
1007
1023
  });
1008
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
+
1009
1045
  function createDocument(content, schema, parseOptions = {}) {
1010
1046
  return createNodeFromContent(content, schema, { slice: false, parseOptions });
1011
1047
  }
@@ -1804,6 +1840,8 @@ const Commands = Extension.create({
1804
1840
  ...selectNodeBackward$1,
1805
1841
  ...selectNodeForward$1,
1806
1842
  ...selectParentNode$1,
1843
+ ...selectTextblockEnd$1,
1844
+ ...selectTextblockStart$1,
1807
1845
  ...setContent$1,
1808
1846
  ...setMark$1,
1809
1847
  ...setMeta$1,
@@ -2043,13 +2081,14 @@ const Keymap = Extension.create({
2043
2081
  () => commands.joinForward(),
2044
2082
  () => commands.selectNodeForward(),
2045
2083
  ]);
2046
- return {
2047
- Enter: () => this.editor.commands.first(({ commands }) => [
2048
- () => commands.newlineInCode(),
2049
- () => commands.createParagraphNear(),
2050
- () => commands.liftEmptyBlock(),
2051
- () => commands.splitBlock(),
2052
- ]),
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,
2053
2092
  'Mod-Enter': () => this.editor.commands.exitCode(),
2054
2093
  Backspace: handleBackspace,
2055
2094
  'Mod-Backspace': handleBackspace,
@@ -2058,6 +2097,26 @@ const Keymap = Extension.create({
2058
2097
  'Mod-Delete': handleDelete,
2059
2098
  'Mod-a': () => this.editor.commands.selectAll(),
2060
2099
  };
2100
+ const pcKeymap = {
2101
+ ...baseKeymap,
2102
+ Home: () => this.editor.commands.selectTextblockStart(),
2103
+ End: () => this.editor.commands.selectTextblockEnd(),
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;
2061
2120
  },
2062
2121
  addProseMirrorPlugins() {
2063
2122
  return [
@@ -2677,15 +2736,10 @@ function injectExtensionAttributesToParseRule(parseRule, extensionAttributes) {
2677
2736
  if (oldAttributes === false) {
2678
2737
  return false;
2679
2738
  }
2680
- const newAttributes = extensionAttributes
2681
- .filter(item => item.attribute.rendered)
2682
- .reduce((items, item) => {
2739
+ const newAttributes = extensionAttributes.reduce((items, item) => {
2683
2740
  const value = item.attribute.parseHTML
2684
2741
  ? item.attribute.parseHTML(node)
2685
2742
  : 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
2743
  if (value === null || value === undefined) {
2690
2744
  return items;
2691
2745
  }