@tiptap/core 2.1.0-rc.9 → 2.1.1
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.
- package/dist/index.cjs +383 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +372 -98
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +383 -99
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/CommandManager.d.ts +2 -2
- package/dist/packages/core/src/Editor.d.ts +4 -4
- package/dist/packages/core/src/Extension.d.ts +7 -7
- package/dist/packages/core/src/ExtensionManager.d.ts +2 -2
- package/dist/packages/core/src/InputRule.d.ts +2 -2
- package/dist/packages/core/src/Mark.d.ts +6 -6
- package/dist/packages/core/src/Node.d.ts +5 -5
- package/dist/packages/core/src/NodeView.d.ts +3 -3
- package/dist/packages/core/src/PasteRule.d.ts +2 -2
- package/dist/packages/core/src/commands/blur.d.ts +1 -1
- package/dist/packages/core/src/commands/clearContent.d.ts +1 -1
- package/dist/packages/core/src/commands/clearNodes.d.ts +1 -1
- package/dist/packages/core/src/commands/command.d.ts +1 -1
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +1 -1
- package/dist/packages/core/src/commands/cut.d.ts +15 -0
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +1 -1
- package/dist/packages/core/src/commands/deleteNode.d.ts +1 -1
- package/dist/packages/core/src/commands/deleteRange.d.ts +1 -1
- package/dist/packages/core/src/commands/deleteSelection.d.ts +1 -1
- package/dist/packages/core/src/commands/enter.d.ts +1 -1
- package/dist/packages/core/src/commands/exitCode.d.ts +1 -1
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +1 -1
- package/dist/packages/core/src/commands/first.d.ts +1 -1
- package/dist/packages/core/src/commands/focus.d.ts +1 -1
- package/dist/packages/core/src/commands/forEach.d.ts +1 -1
- package/dist/packages/core/src/commands/index.d.ts +53 -50
- package/dist/packages/core/src/commands/insertContent.d.ts +1 -1
- package/dist/packages/core/src/commands/insertContentAt.d.ts +1 -1
- package/dist/packages/core/src/commands/join.d.ts +1 -1
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +12 -0
- package/dist/packages/core/src/commands/joinItemForward.d.ts +12 -0
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +1 -1
- package/dist/packages/core/src/commands/lift.d.ts +1 -1
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +1 -1
- package/dist/packages/core/src/commands/liftListItem.d.ts +1 -1
- package/dist/packages/core/src/commands/newlineInCode.d.ts +1 -1
- package/dist/packages/core/src/commands/resetAttributes.d.ts +1 -1
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +1 -1
- package/dist/packages/core/src/commands/selectAll.d.ts +1 -1
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +1 -1
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +1 -1
- package/dist/packages/core/src/commands/selectParentNode.d.ts +1 -1
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +1 -1
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +1 -1
- package/dist/packages/core/src/commands/setContent.d.ts +1 -1
- package/dist/packages/core/src/commands/setMark.d.ts +1 -1
- package/dist/packages/core/src/commands/setMeta.d.ts +1 -1
- package/dist/packages/core/src/commands/setNode.d.ts +1 -1
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +1 -1
- package/dist/packages/core/src/commands/setTextSelection.d.ts +1 -1
- package/dist/packages/core/src/commands/sinkListItem.d.ts +1 -1
- package/dist/packages/core/src/commands/splitBlock.d.ts +1 -1
- package/dist/packages/core/src/commands/splitListItem.d.ts +1 -1
- package/dist/packages/core/src/commands/toggleList.d.ts +1 -1
- package/dist/packages/core/src/commands/toggleMark.d.ts +1 -1
- package/dist/packages/core/src/commands/toggleNode.d.ts +1 -1
- package/dist/packages/core/src/commands/toggleWrap.d.ts +1 -1
- package/dist/packages/core/src/commands/undoInputRule.d.ts +1 -1
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +1 -1
- package/dist/packages/core/src/commands/unsetMark.d.ts +1 -1
- package/dist/packages/core/src/commands/updateAttributes.d.ts +1 -1
- package/dist/packages/core/src/commands/wrapIn.d.ts +1 -1
- package/dist/packages/core/src/commands/wrapInList.d.ts +1 -1
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +1 -1
- package/dist/packages/core/src/extensions/commands.d.ts +2 -2
- package/dist/packages/core/src/extensions/editable.d.ts +1 -1
- package/dist/packages/core/src/extensions/focusEvents.d.ts +1 -1
- package/dist/packages/core/src/extensions/index.d.ts +6 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +1 -1
- package/dist/packages/core/src/extensions/tabindex.d.ts +1 -1
- package/dist/packages/core/src/helpers/createDocument.d.ts +1 -1
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +1 -1
- package/dist/packages/core/src/helpers/findChildren.d.ts +1 -1
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +1 -1
- package/dist/packages/core/src/helpers/findParentNode.d.ts +1 -1
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +1 -1
- package/dist/packages/core/src/helpers/generateHTML.d.ts +1 -1
- package/dist/packages/core/src/helpers/generateJSON.d.ts +1 -1
- package/dist/packages/core/src/helpers/generateText.d.ts +1 -1
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +1 -1
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +1 -1
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +1 -1
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +1 -1
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +1 -1
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +1 -1
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +1 -1
- package/dist/packages/core/src/helpers/getSchema.d.ts +2 -2
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +2 -2
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +1 -1
- package/dist/packages/core/src/helpers/getText.d.ts +1 -1
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +1 -1
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +1 -1
- package/dist/packages/core/src/helpers/index.d.ts +51 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +1 -1
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +1 -1
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +1 -1
- package/dist/packages/core/src/helpers/isList.d.ts +1 -1
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +1 -1
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +4 -4
- package/dist/packages/core/src/index.d.ts +15 -15
- package/dist/packages/core/src/inputRules/index.d.ts +5 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +2 -2
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +22 -2
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +1 -1
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +2 -2
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +3 -3
- package/dist/packages/core/src/pasteRules/index.d.ts +3 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +2 -2
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +2 -2
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +1 -1
- package/dist/packages/core/src/types.d.ts +5 -5
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +1 -1
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -1
- package/dist/packages/core/src/utilities/index.d.ts +20 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +1 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/findListItemPos.d.ts +6 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/getNextListDepth.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/handleBackspace.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/handleDelete.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/hasListBefore.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/hasListItemAfter.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/hasListItemBefore.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/index.d.ts +10 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/listItemHasSubList.d.ts +3 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/nextListIsDeeper.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/nextListIsHigher.d.ts +2 -0
- package/package.json +2 -2
- package/src/CommandManager.ts +4 -8
- package/src/Editor.ts +16 -16
- package/src/Extension.ts +10 -10
- package/src/ExtensionManager.ts +15 -15
- package/src/InputRule.ts +6 -6
- package/src/Mark.ts +9 -9
- package/src/Node.ts +8 -8
- package/src/NodeView.ts +8 -6
- package/src/PasteRule.ts +6 -6
- package/src/commands/blur.ts +1 -1
- package/src/commands/clearContent.ts +1 -1
- package/src/commands/clearNodes.ts +1 -1
- package/src/commands/command.ts +1 -1
- package/src/commands/createParagraphNear.ts +1 -1
- package/src/commands/cut.ts +29 -0
- package/src/commands/deleteCurrentNode.ts +1 -1
- package/src/commands/deleteNode.ts +2 -2
- package/src/commands/deleteRange.ts +1 -1
- package/src/commands/deleteSelection.ts +1 -1
- package/src/commands/enter.ts +1 -1
- package/src/commands/exitCode.ts +1 -1
- package/src/commands/extendMarkRange.ts +3 -3
- package/src/commands/first.ts +1 -1
- package/src/commands/focus.ts +4 -4
- package/src/commands/forEach.ts +1 -1
- package/src/commands/index.ts +53 -50
- package/src/commands/insertContent.ts +1 -1
- package/src/commands/insertContentAt.ts +4 -4
- package/src/commands/join.ts +1 -1
- package/src/commands/joinItemBackward.ts +36 -0
- package/src/commands/joinItemForward.ts +38 -0
- package/src/commands/keyboardShortcut.ts +3 -3
- package/src/commands/lift.ts +3 -3
- package/src/commands/liftEmptyBlock.ts +1 -1
- package/src/commands/liftListItem.ts +2 -2
- package/src/commands/newlineInCode.ts +1 -1
- package/src/commands/resetAttributes.ts +5 -5
- package/src/commands/scrollIntoView.ts +1 -1
- package/src/commands/selectAll.ts +1 -1
- package/src/commands/selectNodeBackward.ts +1 -1
- package/src/commands/selectNodeForward.ts +1 -1
- package/src/commands/selectParentNode.ts +1 -1
- package/src/commands/selectTextblockEnd.ts +1 -1
- package/src/commands/selectTextblockStart.ts +1 -1
- package/src/commands/setContent.ts +2 -2
- package/src/commands/setMark.ts +4 -4
- package/src/commands/setMeta.ts +1 -1
- package/src/commands/setNode.ts +2 -2
- package/src/commands/setNodeSelection.ts +2 -2
- package/src/commands/setTextSelection.ts +2 -2
- package/src/commands/sinkListItem.ts +2 -2
- package/src/commands/splitBlock.ts +3 -3
- package/src/commands/splitListItem.ts +3 -3
- package/src/commands/toggleList.ts +4 -4
- package/src/commands/toggleMark.ts +3 -3
- package/src/commands/toggleNode.ts +3 -3
- package/src/commands/toggleWrap.ts +3 -3
- package/src/commands/undoInputRule.ts +1 -1
- package/src/commands/unsetAllMarks.ts +1 -1
- package/src/commands/unsetMark.ts +3 -3
- package/src/commands/updateAttributes.ts +4 -4
- package/src/commands/wrapIn.ts +2 -2
- package/src/commands/wrapInList.ts +2 -2
- package/src/extensions/clipboardTextSerializer.ts +3 -3
- package/src/extensions/commands.ts +3 -3
- package/src/extensions/editable.ts +1 -1
- package/src/extensions/focusEvents.ts +1 -1
- package/src/extensions/index.ts +6 -6
- package/src/extensions/keymap.ts +7 -5
- package/src/extensions/tabindex.ts +1 -1
- package/src/helpers/createDocument.ts +2 -2
- package/src/helpers/createNodeFromContent.ts +2 -2
- package/src/helpers/findChildren.ts +1 -1
- package/src/helpers/findChildrenInRange.ts +1 -1
- package/src/helpers/findParentNode.ts +2 -2
- package/src/helpers/findParentNodeClosestToPos.ts +1 -1
- package/src/helpers/generateHTML.ts +3 -3
- package/src/helpers/generateJSON.ts +3 -3
- package/src/helpers/generateText.ts +4 -4
- package/src/helpers/getAttributes.ts +3 -3
- package/src/helpers/getAttributesFromExtensions.ts +4 -4
- package/src/helpers/getChangedRanges.ts +2 -2
- package/src/helpers/getDebugJSON.ts +1 -1
- package/src/helpers/getExtensionField.ts +1 -1
- package/src/helpers/getMarkAttributes.ts +1 -1
- package/src/helpers/getMarkRange.ts +2 -2
- package/src/helpers/getMarksBetween.ts +2 -2
- package/src/helpers/getNodeAttributes.ts +1 -1
- package/src/helpers/getRenderedAttributes.ts +2 -2
- package/src/helpers/getSchema.ts +4 -4
- package/src/helpers/getSchemaByResolvedExtensions.ts +9 -9
- package/src/helpers/getSplittedAttributes.ts +1 -1
- package/src/helpers/getText.ts +2 -2
- package/src/helpers/getTextBetween.ts +1 -1
- package/src/helpers/getTextSerializersFromSchema.ts +1 -1
- package/src/helpers/index.ts +51 -50
- package/src/helpers/injectExtensionAttributesToParseRule.ts +2 -2
- package/src/helpers/isActive.ts +3 -3
- package/src/helpers/isAtEndOfNode.ts +20 -2
- package/src/helpers/isExtensionRulesEnabled.ts +1 -1
- package/src/helpers/isList.ts +5 -5
- package/src/helpers/isMarkActive.ts +3 -3
- package/src/helpers/isNodeActive.ts +3 -3
- package/src/helpers/posToDOMRect.ts +1 -1
- package/src/helpers/resolveFocusPosition.ts +2 -2
- package/src/helpers/splitExtensions.ts +4 -4
- package/src/index.ts +15 -15
- package/src/inputRules/index.ts +5 -5
- package/src/inputRules/markInputRule.ts +5 -6
- package/src/inputRules/nodeInputRule.ts +59 -6
- package/src/inputRules/textInputRule.ts +1 -1
- package/src/inputRules/textblockTypeInputRule.ts +3 -3
- package/src/inputRules/wrappingInputRule.ts +4 -4
- package/src/pasteRules/index.ts +3 -3
- package/src/pasteRules/markPasteRule.ts +4 -4
- package/src/pasteRules/nodePasteRule.ts +3 -3
- package/src/pasteRules/textPasteRule.ts +1 -1
- package/src/types.ts +5 -5
- package/src/utilities/callOrReturn.ts +2 -2
- package/src/utilities/createStyleTag.ts +3 -3
- package/src/utilities/index.ts +20 -20
- package/src/utilities/isAndroid.ts +3 -0
- package/src/utilities/mergeAttributes.ts +8 -1
- package/src/utilities/mergeDeep.ts +1 -1
- package/src/utilities/objectIncludes.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -121,9 +121,6 @@ class CommandManager {
|
|
|
121
121
|
buildProps(tr, shouldDispatch = true) {
|
|
122
122
|
const { rawCommands, editor, state } = this;
|
|
123
123
|
const { view } = editor;
|
|
124
|
-
if (state.storedMarks) {
|
|
125
|
-
tr.setStoredMarks(state.storedMarks);
|
|
126
|
-
}
|
|
127
124
|
const props = {
|
|
128
125
|
tr,
|
|
129
126
|
editor,
|
|
@@ -133,7 +130,7 @@ class CommandManager {
|
|
|
133
130
|
transaction: tr,
|
|
134
131
|
}),
|
|
135
132
|
dispatch: shouldDispatch ? () => undefined : undefined,
|
|
136
|
-
chain: () => this.createChain(tr),
|
|
133
|
+
chain: () => this.createChain(tr, shouldDispatch),
|
|
137
134
|
can: () => this.createCan(tr),
|
|
138
135
|
get commands() {
|
|
139
136
|
return Object.fromEntries(Object.entries(rawCommands).map(([name, command]) => {
|
|
@@ -309,7 +306,10 @@ function mergeAttributes(...objects) {
|
|
|
309
306
|
return;
|
|
310
307
|
}
|
|
311
308
|
if (key === 'class') {
|
|
312
|
-
|
|
309
|
+
const valueClasses = value.split(' ');
|
|
310
|
+
const existingClasses = mergedAttributes[key].split(' ');
|
|
311
|
+
const insertClasses = valueClasses.filter(valueClass => !existingClasses.includes(valueClass));
|
|
312
|
+
mergedAttributes[key] = [...existingClasses, ...insertClasses].join(' ');
|
|
313
313
|
}
|
|
314
314
|
else if (key === 'style') {
|
|
315
315
|
mergedAttributes[key] = [mergedAttributes[key], value].join('; ');
|
|
@@ -1312,6 +1312,16 @@ const createParagraphNear = () => ({ state, dispatch }) => {
|
|
|
1312
1312
|
return commands$1.createParagraphNear(state, dispatch);
|
|
1313
1313
|
};
|
|
1314
1314
|
|
|
1315
|
+
const cut = (originRange, targetPos) => ({ editor, tr }) => {
|
|
1316
|
+
const { state: state$1 } = editor;
|
|
1317
|
+
const contentSlice = state$1.doc.slice(originRange.from, originRange.to);
|
|
1318
|
+
tr.deleteRange(originRange.from, originRange.to);
|
|
1319
|
+
const newPos = tr.mapping.map(targetPos);
|
|
1320
|
+
tr.insert(newPos, contentSlice.content);
|
|
1321
|
+
tr.setSelection(new state.TextSelection(tr.doc.resolve(newPos - 1)));
|
|
1322
|
+
return true;
|
|
1323
|
+
};
|
|
1324
|
+
|
|
1315
1325
|
const deleteCurrentNode = () => ({ tr, dispatch }) => {
|
|
1316
1326
|
const { selection } = tr;
|
|
1317
1327
|
const currentNode = selection.$anchor.node();
|
|
@@ -1641,7 +1651,7 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
1641
1651
|
if (content.toString() === '<>') {
|
|
1642
1652
|
return true;
|
|
1643
1653
|
}
|
|
1644
|
-
let { from, to } = typeof position === 'number' ? { from: position, to: position } : position;
|
|
1654
|
+
let { from, to } = typeof position === 'number' ? { from: position, to: position } : { from: position.from, to: position.to };
|
|
1645
1655
|
let isOnlyTextContent = true;
|
|
1646
1656
|
let isOnlyBlockContent = true;
|
|
1647
1657
|
const nodes = isFragment(content) ? content : [content];
|
|
@@ -1703,6 +1713,40 @@ const joinForward = () => ({ state, dispatch }) => {
|
|
|
1703
1713
|
return commands$1.joinForward(state, dispatch);
|
|
1704
1714
|
};
|
|
1705
1715
|
|
|
1716
|
+
const joinItemBackward = () => ({ tr, state, dispatch, }) => {
|
|
1717
|
+
try {
|
|
1718
|
+
const point = transform.joinPoint(state.doc, state.selection.$from.pos, -1);
|
|
1719
|
+
if (point === null || point === undefined) {
|
|
1720
|
+
return false;
|
|
1721
|
+
}
|
|
1722
|
+
tr.join(point, 2);
|
|
1723
|
+
if (dispatch) {
|
|
1724
|
+
dispatch(tr);
|
|
1725
|
+
}
|
|
1726
|
+
return true;
|
|
1727
|
+
}
|
|
1728
|
+
catch {
|
|
1729
|
+
return false;
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1732
|
+
|
|
1733
|
+
const joinItemForward = () => ({ state, dispatch, tr, }) => {
|
|
1734
|
+
try {
|
|
1735
|
+
const point = transform.joinPoint(state.doc, state.selection.$from.pos, +1);
|
|
1736
|
+
if (point === null || point === undefined) {
|
|
1737
|
+
return false;
|
|
1738
|
+
}
|
|
1739
|
+
tr.join(point, 2);
|
|
1740
|
+
if (dispatch) {
|
|
1741
|
+
dispatch(tr);
|
|
1742
|
+
}
|
|
1743
|
+
return true;
|
|
1744
|
+
}
|
|
1745
|
+
catch (e) {
|
|
1746
|
+
return false;
|
|
1747
|
+
}
|
|
1748
|
+
};
|
|
1749
|
+
|
|
1706
1750
|
function isMacOS() {
|
|
1707
1751
|
return typeof navigator !== 'undefined'
|
|
1708
1752
|
? /Mac/.test(navigator.platform)
|
|
@@ -1949,6 +1993,283 @@ const setContent = (content, emitUpdate = false, parseOptions = {}) => ({ tr, ed
|
|
|
1949
1993
|
return true;
|
|
1950
1994
|
};
|
|
1951
1995
|
|
|
1996
|
+
function getMarkAttributes(state, typeOrName) {
|
|
1997
|
+
const type = getMarkType(typeOrName, state.schema);
|
|
1998
|
+
const { from, to, empty } = state.selection;
|
|
1999
|
+
const marks = [];
|
|
2000
|
+
if (empty) {
|
|
2001
|
+
if (state.storedMarks) {
|
|
2002
|
+
marks.push(...state.storedMarks);
|
|
2003
|
+
}
|
|
2004
|
+
marks.push(...state.selection.$head.marks());
|
|
2005
|
+
}
|
|
2006
|
+
else {
|
|
2007
|
+
state.doc.nodesBetween(from, to, node => {
|
|
2008
|
+
marks.push(...node.marks);
|
|
2009
|
+
});
|
|
2010
|
+
}
|
|
2011
|
+
const mark = marks.find(markItem => markItem.type.name === type.name);
|
|
2012
|
+
if (!mark) {
|
|
2013
|
+
return {};
|
|
2014
|
+
}
|
|
2015
|
+
return { ...mark.attrs };
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
const findListItemPos = (typeOrName, state) => {
|
|
2019
|
+
const { $from } = state.selection;
|
|
2020
|
+
const nodeType = getNodeType(typeOrName, state.schema);
|
|
2021
|
+
let currentNode = null;
|
|
2022
|
+
let currentDepth = $from.depth;
|
|
2023
|
+
let currentPos = $from.pos;
|
|
2024
|
+
let targetDepth = null;
|
|
2025
|
+
while (currentDepth > 0 && targetDepth === null) {
|
|
2026
|
+
currentNode = $from.node(currentDepth);
|
|
2027
|
+
if (currentNode.type === nodeType) {
|
|
2028
|
+
targetDepth = currentDepth;
|
|
2029
|
+
}
|
|
2030
|
+
else {
|
|
2031
|
+
currentDepth -= 1;
|
|
2032
|
+
currentPos -= 1;
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
if (targetDepth === null) {
|
|
2036
|
+
return null;
|
|
2037
|
+
}
|
|
2038
|
+
return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
|
|
2039
|
+
};
|
|
2040
|
+
|
|
2041
|
+
/**
|
|
2042
|
+
* Finds the first node of a given type or name in the current selection.
|
|
2043
|
+
* @param state The editor state.
|
|
2044
|
+
* @param typeOrName The node type or name.
|
|
2045
|
+
* @param pos The position to start searching from.
|
|
2046
|
+
* @param maxDepth The maximum depth to search.
|
|
2047
|
+
* @returns The node and the depth as an array.
|
|
2048
|
+
*/
|
|
2049
|
+
const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
|
|
2050
|
+
const $pos = state.doc.resolve(pos);
|
|
2051
|
+
let currentDepth = maxDepth;
|
|
2052
|
+
let node = null;
|
|
2053
|
+
while (currentDepth > 0 && node === null) {
|
|
2054
|
+
const currentNode = $pos.node(currentDepth);
|
|
2055
|
+
if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
|
|
2056
|
+
node = currentNode;
|
|
2057
|
+
}
|
|
2058
|
+
else {
|
|
2059
|
+
currentDepth -= 1;
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
return [node, currentDepth];
|
|
2063
|
+
};
|
|
2064
|
+
|
|
2065
|
+
const getNextListDepth = (typeOrName, state) => {
|
|
2066
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2067
|
+
if (!listItemPos) {
|
|
2068
|
+
return false;
|
|
2069
|
+
}
|
|
2070
|
+
const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4);
|
|
2071
|
+
return depth;
|
|
2072
|
+
};
|
|
2073
|
+
|
|
2074
|
+
const isAtStartOfNode = (state) => {
|
|
2075
|
+
const { $from, $to } = state.selection;
|
|
2076
|
+
if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
|
|
2077
|
+
return false;
|
|
2078
|
+
}
|
|
2079
|
+
return true;
|
|
2080
|
+
};
|
|
2081
|
+
|
|
2082
|
+
const hasListBefore = (editorState, name, parentListTypes) => {
|
|
2083
|
+
const { $anchor } = editorState.selection;
|
|
2084
|
+
const previousNodePos = Math.max(0, $anchor.pos - 2);
|
|
2085
|
+
const previousNode = editorState.doc.resolve(previousNodePos).node();
|
|
2086
|
+
if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
|
|
2087
|
+
return false;
|
|
2088
|
+
}
|
|
2089
|
+
return true;
|
|
2090
|
+
};
|
|
2091
|
+
|
|
2092
|
+
const hasListItemBefore = (typeOrName, state) => {
|
|
2093
|
+
var _a;
|
|
2094
|
+
const { $anchor } = state.selection;
|
|
2095
|
+
const $targetPos = state.doc.resolve($anchor.pos - 2);
|
|
2096
|
+
if ($targetPos.index() === 0) {
|
|
2097
|
+
return false;
|
|
2098
|
+
}
|
|
2099
|
+
if (((_a = $targetPos.nodeBefore) === null || _a === void 0 ? void 0 : _a.type.name) !== typeOrName) {
|
|
2100
|
+
return false;
|
|
2101
|
+
}
|
|
2102
|
+
return true;
|
|
2103
|
+
};
|
|
2104
|
+
|
|
2105
|
+
const listItemHasSubList = (typeOrName, state, node) => {
|
|
2106
|
+
if (!node) {
|
|
2107
|
+
return false;
|
|
2108
|
+
}
|
|
2109
|
+
const nodeType = getNodeType(typeOrName, state.schema);
|
|
2110
|
+
let hasSubList = false;
|
|
2111
|
+
node.descendants(child => {
|
|
2112
|
+
if (child.type === nodeType) {
|
|
2113
|
+
hasSubList = true;
|
|
2114
|
+
}
|
|
2115
|
+
});
|
|
2116
|
+
return hasSubList;
|
|
2117
|
+
};
|
|
2118
|
+
|
|
2119
|
+
const handleBackspace = (editor, name, parentListTypes) => {
|
|
2120
|
+
// this is required to still handle the undo handling
|
|
2121
|
+
if (editor.commands.undoInputRule()) {
|
|
2122
|
+
return true;
|
|
2123
|
+
}
|
|
2124
|
+
// if the current item is NOT inside a list item &
|
|
2125
|
+
// the previous item is a list (orderedList or bulletList)
|
|
2126
|
+
// move the cursor into the list and delete the current item
|
|
2127
|
+
if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
|
|
2128
|
+
const { $anchor } = editor.state.selection;
|
|
2129
|
+
const $listPos = editor.state.doc.resolve($anchor.before() - 1);
|
|
2130
|
+
const listDescendants = [];
|
|
2131
|
+
$listPos.node().descendants((node, pos) => {
|
|
2132
|
+
if (node.type.name === name) {
|
|
2133
|
+
listDescendants.push({ node, pos });
|
|
2134
|
+
}
|
|
2135
|
+
});
|
|
2136
|
+
const lastItem = listDescendants.at(-1);
|
|
2137
|
+
if (!lastItem) {
|
|
2138
|
+
return false;
|
|
2139
|
+
}
|
|
2140
|
+
const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
|
|
2141
|
+
return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
|
|
2142
|
+
}
|
|
2143
|
+
// if the cursor is not inside the current node type
|
|
2144
|
+
// do nothing and proceed
|
|
2145
|
+
if (!isNodeActive(editor.state, name)) {
|
|
2146
|
+
return false;
|
|
2147
|
+
}
|
|
2148
|
+
// if the cursor is not at the start of a node
|
|
2149
|
+
// do nothing and proceed
|
|
2150
|
+
if (!isAtStartOfNode(editor.state)) {
|
|
2151
|
+
return false;
|
|
2152
|
+
}
|
|
2153
|
+
const listItemPos = findListItemPos(name, editor.state);
|
|
2154
|
+
if (!listItemPos) {
|
|
2155
|
+
return false;
|
|
2156
|
+
}
|
|
2157
|
+
const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
|
|
2158
|
+
const prevNode = $prev.node(listItemPos.depth);
|
|
2159
|
+
const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
|
|
2160
|
+
// if the previous item is a list item and doesn't have a sublist, join the list items
|
|
2161
|
+
if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
|
|
2162
|
+
return editor.commands.joinItemBackward();
|
|
2163
|
+
}
|
|
2164
|
+
// otherwise in the end, a backspace should
|
|
2165
|
+
// always just lift the list item if
|
|
2166
|
+
// joining / merging is not possible
|
|
2167
|
+
return editor.chain().liftListItem(name).run();
|
|
2168
|
+
};
|
|
2169
|
+
|
|
2170
|
+
function findParentNodeClosestToPos($pos, predicate) {
|
|
2171
|
+
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
2172
|
+
const node = $pos.node(i);
|
|
2173
|
+
if (predicate(node)) {
|
|
2174
|
+
return {
|
|
2175
|
+
pos: i > 0 ? $pos.before(i) : 0,
|
|
2176
|
+
start: $pos.start(i),
|
|
2177
|
+
depth: i,
|
|
2178
|
+
node,
|
|
2179
|
+
};
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
function findParentNode(predicate) {
|
|
2185
|
+
return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
const isAtEndOfNode = (state, nodeType) => {
|
|
2189
|
+
const { $from, $to, $anchor } = state.selection;
|
|
2190
|
+
if (nodeType) {
|
|
2191
|
+
const parentNode = findParentNode(node => node.type.name === nodeType)(state.selection);
|
|
2192
|
+
if (!parentNode) {
|
|
2193
|
+
return false;
|
|
2194
|
+
}
|
|
2195
|
+
const $parentPos = state.doc.resolve(parentNode.pos + 1);
|
|
2196
|
+
if ($anchor.pos + 1 === $parentPos.end()) {
|
|
2197
|
+
return true;
|
|
2198
|
+
}
|
|
2199
|
+
return false;
|
|
2200
|
+
}
|
|
2201
|
+
if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
|
|
2202
|
+
return false;
|
|
2203
|
+
}
|
|
2204
|
+
return true;
|
|
2205
|
+
};
|
|
2206
|
+
|
|
2207
|
+
const nextListIsDeeper = (typeOrName, state) => {
|
|
2208
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
2209
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2210
|
+
if (!listItemPos || !listDepth) {
|
|
2211
|
+
return false;
|
|
2212
|
+
}
|
|
2213
|
+
if (listDepth > listItemPos.depth) {
|
|
2214
|
+
return true;
|
|
2215
|
+
}
|
|
2216
|
+
return false;
|
|
2217
|
+
};
|
|
2218
|
+
|
|
2219
|
+
const nextListIsHigher = (typeOrName, state) => {
|
|
2220
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
2221
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2222
|
+
if (!listItemPos || !listDepth) {
|
|
2223
|
+
return false;
|
|
2224
|
+
}
|
|
2225
|
+
if (listDepth < listItemPos.depth) {
|
|
2226
|
+
return true;
|
|
2227
|
+
}
|
|
2228
|
+
return false;
|
|
2229
|
+
};
|
|
2230
|
+
|
|
2231
|
+
const handleDelete = (editor, name) => {
|
|
2232
|
+
// if the cursor is not inside the current node type
|
|
2233
|
+
// do nothing and proceed
|
|
2234
|
+
if (!isNodeActive(editor.state, name)) {
|
|
2235
|
+
return false;
|
|
2236
|
+
}
|
|
2237
|
+
// if the cursor is not at the end of a node
|
|
2238
|
+
// do nothing and proceed
|
|
2239
|
+
if (!isAtEndOfNode(editor.state, name)) {
|
|
2240
|
+
return false;
|
|
2241
|
+
}
|
|
2242
|
+
// check if the next node is a list with a deeper depth
|
|
2243
|
+
if (nextListIsDeeper(name, editor.state)) {
|
|
2244
|
+
return editor
|
|
2245
|
+
.chain()
|
|
2246
|
+
.focus(editor.state.selection.from + 4)
|
|
2247
|
+
.lift(name)
|
|
2248
|
+
.joinBackward()
|
|
2249
|
+
.run();
|
|
2250
|
+
}
|
|
2251
|
+
if (nextListIsHigher(name, editor.state)) {
|
|
2252
|
+
return editor.chain()
|
|
2253
|
+
.joinForward()
|
|
2254
|
+
.joinBackward()
|
|
2255
|
+
.run();
|
|
2256
|
+
}
|
|
2257
|
+
return editor.commands.joinItemForward();
|
|
2258
|
+
};
|
|
2259
|
+
|
|
2260
|
+
const hasListItemAfter = (typeOrName, state) => {
|
|
2261
|
+
var _a;
|
|
2262
|
+
const { $anchor } = state.selection;
|
|
2263
|
+
const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2);
|
|
2264
|
+
if ($targetPos.index() === $targetPos.parent.childCount - 1) {
|
|
2265
|
+
return false;
|
|
2266
|
+
}
|
|
2267
|
+
if (((_a = $targetPos.nodeAfter) === null || _a === void 0 ? void 0 : _a.type.name) !== typeOrName) {
|
|
2268
|
+
return false;
|
|
2269
|
+
}
|
|
2270
|
+
return true;
|
|
2271
|
+
};
|
|
2272
|
+
|
|
1952
2273
|
/**
|
|
1953
2274
|
* Returns a new `Transform` based on all steps of the passed transactions.
|
|
1954
2275
|
*/
|
|
@@ -2010,24 +2331,6 @@ function findChildrenInRange(node, range, predicate) {
|
|
|
2010
2331
|
return nodesWithPos;
|
|
2011
2332
|
}
|
|
2012
2333
|
|
|
2013
|
-
function findParentNodeClosestToPos($pos, predicate) {
|
|
2014
|
-
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
2015
|
-
const node = $pos.node(i);
|
|
2016
|
-
if (predicate(node)) {
|
|
2017
|
-
return {
|
|
2018
|
-
pos: i > 0 ? $pos.before(i) : 0,
|
|
2019
|
-
start: $pos.start(i),
|
|
2020
|
-
depth: i,
|
|
2021
|
-
node,
|
|
2022
|
-
};
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
|
-
function findParentNode(predicate) {
|
|
2028
|
-
return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
|
|
2029
|
-
}
|
|
2030
|
-
|
|
2031
2334
|
function getHTMLFromFragment(fragment, schema) {
|
|
2032
2335
|
const documentFragment = model.DOMSerializer.fromSchema(schema).serializeFragment(fragment);
|
|
2033
2336
|
const temporaryDocument = document.implementation.createHTMLDocument();
|
|
@@ -2074,28 +2377,6 @@ function generateText(doc, extensions, options) {
|
|
|
2074
2377
|
});
|
|
2075
2378
|
}
|
|
2076
2379
|
|
|
2077
|
-
function getMarkAttributes(state, typeOrName) {
|
|
2078
|
-
const type = getMarkType(typeOrName, state.schema);
|
|
2079
|
-
const { from, to, empty } = state.selection;
|
|
2080
|
-
const marks = [];
|
|
2081
|
-
if (empty) {
|
|
2082
|
-
if (state.storedMarks) {
|
|
2083
|
-
marks.push(...state.storedMarks);
|
|
2084
|
-
}
|
|
2085
|
-
marks.push(...state.selection.$head.marks());
|
|
2086
|
-
}
|
|
2087
|
-
else {
|
|
2088
|
-
state.doc.nodesBetween(from, to, node => {
|
|
2089
|
-
marks.push(...node.marks);
|
|
2090
|
-
});
|
|
2091
|
-
}
|
|
2092
|
-
const mark = marks.find(markItem => markItem.type.name === type.name);
|
|
2093
|
-
if (!mark) {
|
|
2094
|
-
return {};
|
|
2095
|
-
}
|
|
2096
|
-
return { ...mark.attrs };
|
|
2097
|
-
}
|
|
2098
|
-
|
|
2099
2380
|
function getNodeAttributes(state, typeOrName) {
|
|
2100
2381
|
const type = getNodeType(typeOrName, state.schema);
|
|
2101
2382
|
const { from, to } = state.selection;
|
|
@@ -2267,30 +2548,6 @@ function getMarksBetween(from, to, doc) {
|
|
|
2267
2548
|
return marks;
|
|
2268
2549
|
}
|
|
2269
2550
|
|
|
2270
|
-
/**
|
|
2271
|
-
* Finds the first node of a given type or name in the current selection.
|
|
2272
|
-
* @param state The editor state.
|
|
2273
|
-
* @param typeOrName The node type or name.
|
|
2274
|
-
* @param pos The position to start searching from.
|
|
2275
|
-
* @param maxDepth The maximum depth to search.
|
|
2276
|
-
* @returns The node and the depth as an array.
|
|
2277
|
-
*/
|
|
2278
|
-
const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
|
|
2279
|
-
const $pos = state.doc.resolve(pos);
|
|
2280
|
-
let currentDepth = maxDepth;
|
|
2281
|
-
let node = null;
|
|
2282
|
-
while (currentDepth > 0 && node === null) {
|
|
2283
|
-
const currentNode = $pos.node(currentDepth);
|
|
2284
|
-
if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
|
|
2285
|
-
node = currentNode;
|
|
2286
|
-
}
|
|
2287
|
-
else {
|
|
2288
|
-
currentDepth -= 1;
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
return [node, currentDepth];
|
|
2292
|
-
};
|
|
2293
|
-
|
|
2294
2551
|
function getSplittedAttributes(extensionAttributes, typeName, attributes) {
|
|
2295
2552
|
return Object.fromEntries(Object
|
|
2296
2553
|
.entries(attributes)
|
|
@@ -2381,22 +2638,6 @@ function isActive(state, name, attributes = {}) {
|
|
|
2381
2638
|
return false;
|
|
2382
2639
|
}
|
|
2383
2640
|
|
|
2384
|
-
const istAtEndOfNode = (state) => {
|
|
2385
|
-
const { $from, $to } = state.selection;
|
|
2386
|
-
if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
|
|
2387
|
-
return false;
|
|
2388
|
-
}
|
|
2389
|
-
return true;
|
|
2390
|
-
};
|
|
2391
|
-
|
|
2392
|
-
const isAtStartOfNode = (state) => {
|
|
2393
|
-
const { $from, $to } = state.selection;
|
|
2394
|
-
if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
|
|
2395
|
-
return false;
|
|
2396
|
-
}
|
|
2397
|
-
return true;
|
|
2398
|
-
};
|
|
2399
|
-
|
|
2400
2641
|
function isList(name, extensions) {
|
|
2401
2642
|
const { nodeExtensions } = splitExtensions(extensions);
|
|
2402
2643
|
const extension = nodeExtensions.find(item => item.name === name);
|
|
@@ -3004,6 +3245,7 @@ var commands = /*#__PURE__*/Object.freeze({
|
|
|
3004
3245
|
clearNodes: clearNodes,
|
|
3005
3246
|
command: command,
|
|
3006
3247
|
createParagraphNear: createParagraphNear,
|
|
3248
|
+
cut: cut,
|
|
3007
3249
|
deleteCurrentNode: deleteCurrentNode,
|
|
3008
3250
|
deleteNode: deleteNode,
|
|
3009
3251
|
deleteRange: deleteRange,
|
|
@@ -3020,6 +3262,8 @@ var commands = /*#__PURE__*/Object.freeze({
|
|
|
3020
3262
|
joinDown: joinDown,
|
|
3021
3263
|
joinBackward: joinBackward,
|
|
3022
3264
|
joinForward: joinForward,
|
|
3265
|
+
joinItemBackward: joinItemBackward,
|
|
3266
|
+
joinItemForward: joinItemForward,
|
|
3023
3267
|
keyboardShortcut: keyboardShortcut,
|
|
3024
3268
|
lift: lift,
|
|
3025
3269
|
liftEmptyBlock: liftEmptyBlock,
|
|
@@ -3321,8 +3565,8 @@ img.ProseMirror-separator {
|
|
|
3321
3565
|
opacity: 0
|
|
3322
3566
|
}`;
|
|
3323
3567
|
|
|
3324
|
-
function createStyleTag(style, nonce) {
|
|
3325
|
-
const tiptapStyleTag = document.querySelector(
|
|
3568
|
+
function createStyleTag(style, nonce, suffix) {
|
|
3569
|
+
const tiptapStyleTag = document.querySelector(`style[data-tiptap-style${suffix ? `-${suffix}` : ''}]`);
|
|
3326
3570
|
if (tiptapStyleTag !== null) {
|
|
3327
3571
|
return tiptapStyleTag;
|
|
3328
3572
|
}
|
|
@@ -3330,7 +3574,7 @@ function createStyleTag(style, nonce) {
|
|
|
3330
3574
|
if (nonce) {
|
|
3331
3575
|
styleNode.setAttribute('nonce', nonce);
|
|
3332
3576
|
}
|
|
3333
|
-
styleNode.setAttribute(
|
|
3577
|
+
styleNode.setAttribute(`data-tiptap-style${suffix ? `-${suffix}` : ''}`, '');
|
|
3334
3578
|
styleNode.innerHTML = style;
|
|
3335
3579
|
document.getElementsByTagName('head')[0].appendChild(styleNode);
|
|
3336
3580
|
return styleNode;
|
|
@@ -3707,7 +3951,6 @@ function markInputRule(config) {
|
|
|
3707
3951
|
const { tr } = state;
|
|
3708
3952
|
const captureGroup = match[match.length - 1];
|
|
3709
3953
|
const fullMatch = match[0];
|
|
3710
|
-
let markEnd = range.to;
|
|
3711
3954
|
if (captureGroup) {
|
|
3712
3955
|
const startSpaces = fullMatch.search(/\S/);
|
|
3713
3956
|
const textStart = range.from + fullMatch.indexOf(captureGroup);
|
|
@@ -3728,7 +3971,7 @@ function markInputRule(config) {
|
|
|
3728
3971
|
if (textStart > range.from) {
|
|
3729
3972
|
tr.delete(range.from + startSpaces, textStart);
|
|
3730
3973
|
}
|
|
3731
|
-
markEnd = range.from + startSpaces + captureGroup.length;
|
|
3974
|
+
const markEnd = range.from + startSpaces + captureGroup.length;
|
|
3732
3975
|
tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}));
|
|
3733
3976
|
tr.removeStoredMark(config.type);
|
|
3734
3977
|
}
|
|
@@ -3743,11 +3986,14 @@ function markInputRule(config) {
|
|
|
3743
3986
|
function nodeInputRule(config) {
|
|
3744
3987
|
return new InputRule({
|
|
3745
3988
|
find: config.find,
|
|
3746
|
-
handler: ({ state, range, match }) => {
|
|
3989
|
+
handler: ({ state: state$1, range, match }) => {
|
|
3990
|
+
var _a, _b;
|
|
3747
3991
|
const attributes = callOrReturn(config.getAttributes, undefined, match) || {};
|
|
3748
|
-
const { tr } = state;
|
|
3749
|
-
const start = range.from;
|
|
3992
|
+
const { tr } = state$1;
|
|
3993
|
+
const start = config.blockReplace ? range.from - 1 : range.from;
|
|
3750
3994
|
let end = range.to;
|
|
3995
|
+
const newNode = config.type.create(attributes);
|
|
3996
|
+
const { $to } = tr.selection;
|
|
3751
3997
|
if (match[1]) {
|
|
3752
3998
|
const offset = match[0].lastIndexOf(match[1]);
|
|
3753
3999
|
let matchStart = start + offset;
|
|
@@ -3761,10 +4007,33 @@ function nodeInputRule(config) {
|
|
|
3761
4007
|
const lastChar = match[0][match[0].length - 1];
|
|
3762
4008
|
tr.insertText(lastChar, start + match[0].length - 1);
|
|
3763
4009
|
// insert node from input rule
|
|
3764
|
-
tr.replaceWith(matchStart, end,
|
|
4010
|
+
tr.replaceWith(matchStart, end, newNode);
|
|
3765
4011
|
}
|
|
3766
4012
|
else if (match[0]) {
|
|
3767
|
-
tr.replaceWith(start, end,
|
|
4013
|
+
tr.replaceWith(start, end, newNode);
|
|
4014
|
+
}
|
|
4015
|
+
if (config.blockReplace && config.addExtraNewline) {
|
|
4016
|
+
if ($to.nodeAfter) {
|
|
4017
|
+
if ($to.nodeAfter.isTextblock) {
|
|
4018
|
+
tr.setSelection(state.TextSelection.create(tr.doc, $to.pos + 1));
|
|
4019
|
+
}
|
|
4020
|
+
else if ($to.nodeAfter.isBlock) {
|
|
4021
|
+
tr.setSelection(state.NodeSelection.create(tr.doc, $to.pos));
|
|
4022
|
+
}
|
|
4023
|
+
else {
|
|
4024
|
+
tr.setSelection(state.TextSelection.create(tr.doc, $to.pos - 1));
|
|
4025
|
+
}
|
|
4026
|
+
}
|
|
4027
|
+
else {
|
|
4028
|
+
// add node after horizontal rule if it’s the end of the document
|
|
4029
|
+
const defaultNode = ((_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create()) || ((_b = state$1.doc.type.contentMatch.defaultType) === null || _b === void 0 ? void 0 : _b.create());
|
|
4030
|
+
if (defaultNode) {
|
|
4031
|
+
const newPos = start + newNode.nodeSize;
|
|
4032
|
+
tr.insert(newPos, defaultNode);
|
|
4033
|
+
tr.setSelection(state.TextSelection.create(tr.doc, newPos));
|
|
4034
|
+
}
|
|
4035
|
+
}
|
|
4036
|
+
tr.scrollIntoView();
|
|
3768
4037
|
}
|
|
3769
4038
|
},
|
|
3770
4039
|
});
|
|
@@ -4016,6 +4285,10 @@ class Node {
|
|
|
4016
4285
|
}
|
|
4017
4286
|
}
|
|
4018
4287
|
|
|
4288
|
+
function isAndroid() {
|
|
4289
|
+
return navigator.platform === 'Android' || /android/i.test(navigator.userAgent);
|
|
4290
|
+
}
|
|
4291
|
+
|
|
4019
4292
|
class NodeView {
|
|
4020
4293
|
constructor(component, props, options) {
|
|
4021
4294
|
this.isDragging = false;
|
|
@@ -4156,13 +4429,14 @@ class NodeView {
|
|
|
4156
4429
|
if (mutation.type === 'selection') {
|
|
4157
4430
|
return false;
|
|
4158
4431
|
}
|
|
4159
|
-
// try to prevent a bug on iOS that will break node views on enter
|
|
4432
|
+
// try to prevent a bug on iOS and Android that will break node views on enter
|
|
4160
4433
|
// this is because ProseMirror can’t preventDispatch on enter
|
|
4161
4434
|
// this will lead to a re-render of the node view on enter
|
|
4162
4435
|
// see: https://github.com/ueberdosis/tiptap/issues/1214
|
|
4436
|
+
// see: https://github.com/ueberdosis/tiptap/issues/2534
|
|
4163
4437
|
if (this.dom.contains(mutation.target)
|
|
4164
4438
|
&& mutation.type === 'childList'
|
|
4165
|
-
&& isiOS()
|
|
4439
|
+
&& (isiOS() || isAndroid())
|
|
4166
4440
|
&& this.editor.isFocused) {
|
|
4167
4441
|
const changedNodes = [
|
|
4168
4442
|
...Array.from(mutation.addedNodes),
|
|
@@ -4349,6 +4623,7 @@ exports.extensions = extensions;
|
|
|
4349
4623
|
exports.findChildren = findChildren;
|
|
4350
4624
|
exports.findChildrenInRange = findChildrenInRange;
|
|
4351
4625
|
exports.findDuplicates = findDuplicates;
|
|
4626
|
+
exports.findListItemPos = findListItemPos;
|
|
4352
4627
|
exports.findParentNode = findParentNode;
|
|
4353
4628
|
exports.findParentNodeClosestToPos = findParentNodeClosestToPos;
|
|
4354
4629
|
exports.fromString = fromString;
|
|
@@ -4365,6 +4640,7 @@ exports.getMarkAttributes = getMarkAttributes;
|
|
|
4365
4640
|
exports.getMarkRange = getMarkRange;
|
|
4366
4641
|
exports.getMarkType = getMarkType;
|
|
4367
4642
|
exports.getMarksBetween = getMarksBetween;
|
|
4643
|
+
exports.getNextListDepth = getNextListDepth;
|
|
4368
4644
|
exports.getNodeAtPosition = getNodeAtPosition;
|
|
4369
4645
|
exports.getNodeAttributes = getNodeAttributes;
|
|
4370
4646
|
exports.getNodeType = getNodeType;
|
|
@@ -4378,9 +4654,15 @@ exports.getText = getText;
|
|
|
4378
4654
|
exports.getTextBetween = getTextBetween;
|
|
4379
4655
|
exports.getTextContentFromNodes = getTextContentFromNodes;
|
|
4380
4656
|
exports.getTextSerializersFromSchema = getTextSerializersFromSchema;
|
|
4657
|
+
exports.handleBackspace = handleBackspace;
|
|
4658
|
+
exports.handleDelete = handleDelete;
|
|
4659
|
+
exports.hasListBefore = hasListBefore;
|
|
4660
|
+
exports.hasListItemAfter = hasListItemAfter;
|
|
4661
|
+
exports.hasListItemBefore = hasListItemBefore;
|
|
4381
4662
|
exports.injectExtensionAttributesToParseRule = injectExtensionAttributesToParseRule;
|
|
4382
4663
|
exports.inputRulesPlugin = inputRulesPlugin;
|
|
4383
4664
|
exports.isActive = isActive;
|
|
4665
|
+
exports.isAtEndOfNode = isAtEndOfNode;
|
|
4384
4666
|
exports.isAtStartOfNode = isAtStartOfNode;
|
|
4385
4667
|
exports.isEmptyObject = isEmptyObject;
|
|
4386
4668
|
exports.isExtensionRulesEnabled = isExtensionRulesEnabled;
|
|
@@ -4397,12 +4679,14 @@ exports.isRegExp = isRegExp;
|
|
|
4397
4679
|
exports.isString = isString;
|
|
4398
4680
|
exports.isTextSelection = isTextSelection;
|
|
4399
4681
|
exports.isiOS = isiOS;
|
|
4400
|
-
exports.
|
|
4682
|
+
exports.listItemHasSubList = listItemHasSubList;
|
|
4401
4683
|
exports.markInputRule = markInputRule;
|
|
4402
4684
|
exports.markPasteRule = markPasteRule;
|
|
4403
4685
|
exports.mergeAttributes = mergeAttributes;
|
|
4404
4686
|
exports.mergeDeep = mergeDeep;
|
|
4405
4687
|
exports.minMax = minMax;
|
|
4688
|
+
exports.nextListIsDeeper = nextListIsDeeper;
|
|
4689
|
+
exports.nextListIsHigher = nextListIsHigher;
|
|
4406
4690
|
exports.nodeInputRule = nodeInputRule;
|
|
4407
4691
|
exports.nodePasteRule = nodePasteRule;
|
|
4408
4692
|
exports.objectIncludes = objectIncludes;
|