@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.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Plugin, PluginKey, TextSelection, Selection, NodeSelection, EditorState
|
|
|
2
2
|
import { EditorView } from '@tiptap/pm/view';
|
|
3
3
|
import { keymap } from '@tiptap/pm/keymap';
|
|
4
4
|
import { Schema, Fragment, DOMParser, DOMSerializer, Node as Node$1, Slice } from '@tiptap/pm/model';
|
|
5
|
-
import { liftTarget, ReplaceStep, ReplaceAroundStep, Transform, canSplit, canJoin, findWrapping } from '@tiptap/pm/transform';
|
|
5
|
+
import { liftTarget, ReplaceStep, ReplaceAroundStep, joinPoint, Transform, canSplit, canJoin, findWrapping } from '@tiptap/pm/transform';
|
|
6
6
|
import { createParagraphNear as createParagraphNear$1, deleteSelection as deleteSelection$1, exitCode as exitCode$1, joinUp as joinUp$1, joinDown as joinDown$1, joinBackward as joinBackward$1, joinForward as joinForward$1, lift as lift$1, liftEmptyBlock as liftEmptyBlock$1, newlineInCode as newlineInCode$1, selectNodeBackward as selectNodeBackward$1, selectNodeForward as selectNodeForward$1, selectParentNode as selectParentNode$1, selectTextblockEnd as selectTextblockEnd$1, selectTextblockStart as selectTextblockStart$1, setBlockType, wrapIn as wrapIn$1 } from '@tiptap/pm/commands';
|
|
7
7
|
import { liftListItem as liftListItem$1, sinkListItem as sinkListItem$1, wrapInList as wrapInList$1 } from '@tiptap/pm/schema-list';
|
|
8
8
|
|
|
@@ -117,9 +117,6 @@ class CommandManager {
|
|
|
117
117
|
buildProps(tr, shouldDispatch = true) {
|
|
118
118
|
const { rawCommands, editor, state } = this;
|
|
119
119
|
const { view } = editor;
|
|
120
|
-
if (state.storedMarks) {
|
|
121
|
-
tr.setStoredMarks(state.storedMarks);
|
|
122
|
-
}
|
|
123
120
|
const props = {
|
|
124
121
|
tr,
|
|
125
122
|
editor,
|
|
@@ -129,7 +126,7 @@ class CommandManager {
|
|
|
129
126
|
transaction: tr,
|
|
130
127
|
}),
|
|
131
128
|
dispatch: shouldDispatch ? () => undefined : undefined,
|
|
132
|
-
chain: () => this.createChain(tr),
|
|
129
|
+
chain: () => this.createChain(tr, shouldDispatch),
|
|
133
130
|
can: () => this.createCan(tr),
|
|
134
131
|
get commands() {
|
|
135
132
|
return Object.fromEntries(Object.entries(rawCommands).map(([name, command]) => {
|
|
@@ -305,7 +302,10 @@ function mergeAttributes(...objects) {
|
|
|
305
302
|
return;
|
|
306
303
|
}
|
|
307
304
|
if (key === 'class') {
|
|
308
|
-
|
|
305
|
+
const valueClasses = value.split(' ');
|
|
306
|
+
const existingClasses = mergedAttributes[key].split(' ');
|
|
307
|
+
const insertClasses = valueClasses.filter(valueClass => !existingClasses.includes(valueClass));
|
|
308
|
+
mergedAttributes[key] = [...existingClasses, ...insertClasses].join(' ');
|
|
309
309
|
}
|
|
310
310
|
else if (key === 'style') {
|
|
311
311
|
mergedAttributes[key] = [mergedAttributes[key], value].join('; ');
|
|
@@ -1308,6 +1308,16 @@ const createParagraphNear = () => ({ state, dispatch }) => {
|
|
|
1308
1308
|
return createParagraphNear$1(state, dispatch);
|
|
1309
1309
|
};
|
|
1310
1310
|
|
|
1311
|
+
const cut = (originRange, targetPos) => ({ editor, tr }) => {
|
|
1312
|
+
const { state } = editor;
|
|
1313
|
+
const contentSlice = state.doc.slice(originRange.from, originRange.to);
|
|
1314
|
+
tr.deleteRange(originRange.from, originRange.to);
|
|
1315
|
+
const newPos = tr.mapping.map(targetPos);
|
|
1316
|
+
tr.insert(newPos, contentSlice.content);
|
|
1317
|
+
tr.setSelection(new TextSelection(tr.doc.resolve(newPos - 1)));
|
|
1318
|
+
return true;
|
|
1319
|
+
};
|
|
1320
|
+
|
|
1311
1321
|
const deleteCurrentNode = () => ({ tr, dispatch }) => {
|
|
1312
1322
|
const { selection } = tr;
|
|
1313
1323
|
const currentNode = selection.$anchor.node();
|
|
@@ -1637,7 +1647,7 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
1637
1647
|
if (content.toString() === '<>') {
|
|
1638
1648
|
return true;
|
|
1639
1649
|
}
|
|
1640
|
-
let { from, to } = typeof position === 'number' ? { from: position, to: position } : position;
|
|
1650
|
+
let { from, to } = typeof position === 'number' ? { from: position, to: position } : { from: position.from, to: position.to };
|
|
1641
1651
|
let isOnlyTextContent = true;
|
|
1642
1652
|
let isOnlyBlockContent = true;
|
|
1643
1653
|
const nodes = isFragment(content) ? content : [content];
|
|
@@ -1699,6 +1709,40 @@ const joinForward = () => ({ state, dispatch }) => {
|
|
|
1699
1709
|
return joinForward$1(state, dispatch);
|
|
1700
1710
|
};
|
|
1701
1711
|
|
|
1712
|
+
const joinItemBackward = () => ({ tr, state, dispatch, }) => {
|
|
1713
|
+
try {
|
|
1714
|
+
const point = joinPoint(state.doc, state.selection.$from.pos, -1);
|
|
1715
|
+
if (point === null || point === undefined) {
|
|
1716
|
+
return false;
|
|
1717
|
+
}
|
|
1718
|
+
tr.join(point, 2);
|
|
1719
|
+
if (dispatch) {
|
|
1720
|
+
dispatch(tr);
|
|
1721
|
+
}
|
|
1722
|
+
return true;
|
|
1723
|
+
}
|
|
1724
|
+
catch {
|
|
1725
|
+
return false;
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
|
|
1729
|
+
const joinItemForward = () => ({ state, dispatch, tr, }) => {
|
|
1730
|
+
try {
|
|
1731
|
+
const point = joinPoint(state.doc, state.selection.$from.pos, +1);
|
|
1732
|
+
if (point === null || point === undefined) {
|
|
1733
|
+
return false;
|
|
1734
|
+
}
|
|
1735
|
+
tr.join(point, 2);
|
|
1736
|
+
if (dispatch) {
|
|
1737
|
+
dispatch(tr);
|
|
1738
|
+
}
|
|
1739
|
+
return true;
|
|
1740
|
+
}
|
|
1741
|
+
catch (e) {
|
|
1742
|
+
return false;
|
|
1743
|
+
}
|
|
1744
|
+
};
|
|
1745
|
+
|
|
1702
1746
|
function isMacOS() {
|
|
1703
1747
|
return typeof navigator !== 'undefined'
|
|
1704
1748
|
? /Mac/.test(navigator.platform)
|
|
@@ -1945,6 +1989,283 @@ const setContent = (content, emitUpdate = false, parseOptions = {}) => ({ tr, ed
|
|
|
1945
1989
|
return true;
|
|
1946
1990
|
};
|
|
1947
1991
|
|
|
1992
|
+
function getMarkAttributes(state, typeOrName) {
|
|
1993
|
+
const type = getMarkType(typeOrName, state.schema);
|
|
1994
|
+
const { from, to, empty } = state.selection;
|
|
1995
|
+
const marks = [];
|
|
1996
|
+
if (empty) {
|
|
1997
|
+
if (state.storedMarks) {
|
|
1998
|
+
marks.push(...state.storedMarks);
|
|
1999
|
+
}
|
|
2000
|
+
marks.push(...state.selection.$head.marks());
|
|
2001
|
+
}
|
|
2002
|
+
else {
|
|
2003
|
+
state.doc.nodesBetween(from, to, node => {
|
|
2004
|
+
marks.push(...node.marks);
|
|
2005
|
+
});
|
|
2006
|
+
}
|
|
2007
|
+
const mark = marks.find(markItem => markItem.type.name === type.name);
|
|
2008
|
+
if (!mark) {
|
|
2009
|
+
return {};
|
|
2010
|
+
}
|
|
2011
|
+
return { ...mark.attrs };
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
const findListItemPos = (typeOrName, state) => {
|
|
2015
|
+
const { $from } = state.selection;
|
|
2016
|
+
const nodeType = getNodeType(typeOrName, state.schema);
|
|
2017
|
+
let currentNode = null;
|
|
2018
|
+
let currentDepth = $from.depth;
|
|
2019
|
+
let currentPos = $from.pos;
|
|
2020
|
+
let targetDepth = null;
|
|
2021
|
+
while (currentDepth > 0 && targetDepth === null) {
|
|
2022
|
+
currentNode = $from.node(currentDepth);
|
|
2023
|
+
if (currentNode.type === nodeType) {
|
|
2024
|
+
targetDepth = currentDepth;
|
|
2025
|
+
}
|
|
2026
|
+
else {
|
|
2027
|
+
currentDepth -= 1;
|
|
2028
|
+
currentPos -= 1;
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
if (targetDepth === null) {
|
|
2032
|
+
return null;
|
|
2033
|
+
}
|
|
2034
|
+
return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
|
|
2035
|
+
};
|
|
2036
|
+
|
|
2037
|
+
/**
|
|
2038
|
+
* Finds the first node of a given type or name in the current selection.
|
|
2039
|
+
* @param state The editor state.
|
|
2040
|
+
* @param typeOrName The node type or name.
|
|
2041
|
+
* @param pos The position to start searching from.
|
|
2042
|
+
* @param maxDepth The maximum depth to search.
|
|
2043
|
+
* @returns The node and the depth as an array.
|
|
2044
|
+
*/
|
|
2045
|
+
const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
|
|
2046
|
+
const $pos = state.doc.resolve(pos);
|
|
2047
|
+
let currentDepth = maxDepth;
|
|
2048
|
+
let node = null;
|
|
2049
|
+
while (currentDepth > 0 && node === null) {
|
|
2050
|
+
const currentNode = $pos.node(currentDepth);
|
|
2051
|
+
if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
|
|
2052
|
+
node = currentNode;
|
|
2053
|
+
}
|
|
2054
|
+
else {
|
|
2055
|
+
currentDepth -= 1;
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
return [node, currentDepth];
|
|
2059
|
+
};
|
|
2060
|
+
|
|
2061
|
+
const getNextListDepth = (typeOrName, state) => {
|
|
2062
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2063
|
+
if (!listItemPos) {
|
|
2064
|
+
return false;
|
|
2065
|
+
}
|
|
2066
|
+
const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4);
|
|
2067
|
+
return depth;
|
|
2068
|
+
};
|
|
2069
|
+
|
|
2070
|
+
const isAtStartOfNode = (state) => {
|
|
2071
|
+
const { $from, $to } = state.selection;
|
|
2072
|
+
if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
|
|
2073
|
+
return false;
|
|
2074
|
+
}
|
|
2075
|
+
return true;
|
|
2076
|
+
};
|
|
2077
|
+
|
|
2078
|
+
const hasListBefore = (editorState, name, parentListTypes) => {
|
|
2079
|
+
const { $anchor } = editorState.selection;
|
|
2080
|
+
const previousNodePos = Math.max(0, $anchor.pos - 2);
|
|
2081
|
+
const previousNode = editorState.doc.resolve(previousNodePos).node();
|
|
2082
|
+
if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
|
|
2083
|
+
return false;
|
|
2084
|
+
}
|
|
2085
|
+
return true;
|
|
2086
|
+
};
|
|
2087
|
+
|
|
2088
|
+
const hasListItemBefore = (typeOrName, state) => {
|
|
2089
|
+
var _a;
|
|
2090
|
+
const { $anchor } = state.selection;
|
|
2091
|
+
const $targetPos = state.doc.resolve($anchor.pos - 2);
|
|
2092
|
+
if ($targetPos.index() === 0) {
|
|
2093
|
+
return false;
|
|
2094
|
+
}
|
|
2095
|
+
if (((_a = $targetPos.nodeBefore) === null || _a === void 0 ? void 0 : _a.type.name) !== typeOrName) {
|
|
2096
|
+
return false;
|
|
2097
|
+
}
|
|
2098
|
+
return true;
|
|
2099
|
+
};
|
|
2100
|
+
|
|
2101
|
+
const listItemHasSubList = (typeOrName, state, node) => {
|
|
2102
|
+
if (!node) {
|
|
2103
|
+
return false;
|
|
2104
|
+
}
|
|
2105
|
+
const nodeType = getNodeType(typeOrName, state.schema);
|
|
2106
|
+
let hasSubList = false;
|
|
2107
|
+
node.descendants(child => {
|
|
2108
|
+
if (child.type === nodeType) {
|
|
2109
|
+
hasSubList = true;
|
|
2110
|
+
}
|
|
2111
|
+
});
|
|
2112
|
+
return hasSubList;
|
|
2113
|
+
};
|
|
2114
|
+
|
|
2115
|
+
const handleBackspace = (editor, name, parentListTypes) => {
|
|
2116
|
+
// this is required to still handle the undo handling
|
|
2117
|
+
if (editor.commands.undoInputRule()) {
|
|
2118
|
+
return true;
|
|
2119
|
+
}
|
|
2120
|
+
// if the current item is NOT inside a list item &
|
|
2121
|
+
// the previous item is a list (orderedList or bulletList)
|
|
2122
|
+
// move the cursor into the list and delete the current item
|
|
2123
|
+
if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
|
|
2124
|
+
const { $anchor } = editor.state.selection;
|
|
2125
|
+
const $listPos = editor.state.doc.resolve($anchor.before() - 1);
|
|
2126
|
+
const listDescendants = [];
|
|
2127
|
+
$listPos.node().descendants((node, pos) => {
|
|
2128
|
+
if (node.type.name === name) {
|
|
2129
|
+
listDescendants.push({ node, pos });
|
|
2130
|
+
}
|
|
2131
|
+
});
|
|
2132
|
+
const lastItem = listDescendants.at(-1);
|
|
2133
|
+
if (!lastItem) {
|
|
2134
|
+
return false;
|
|
2135
|
+
}
|
|
2136
|
+
const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
|
|
2137
|
+
return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
|
|
2138
|
+
}
|
|
2139
|
+
// if the cursor is not inside the current node type
|
|
2140
|
+
// do nothing and proceed
|
|
2141
|
+
if (!isNodeActive(editor.state, name)) {
|
|
2142
|
+
return false;
|
|
2143
|
+
}
|
|
2144
|
+
// if the cursor is not at the start of a node
|
|
2145
|
+
// do nothing and proceed
|
|
2146
|
+
if (!isAtStartOfNode(editor.state)) {
|
|
2147
|
+
return false;
|
|
2148
|
+
}
|
|
2149
|
+
const listItemPos = findListItemPos(name, editor.state);
|
|
2150
|
+
if (!listItemPos) {
|
|
2151
|
+
return false;
|
|
2152
|
+
}
|
|
2153
|
+
const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
|
|
2154
|
+
const prevNode = $prev.node(listItemPos.depth);
|
|
2155
|
+
const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
|
|
2156
|
+
// if the previous item is a list item and doesn't have a sublist, join the list items
|
|
2157
|
+
if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
|
|
2158
|
+
return editor.commands.joinItemBackward();
|
|
2159
|
+
}
|
|
2160
|
+
// otherwise in the end, a backspace should
|
|
2161
|
+
// always just lift the list item if
|
|
2162
|
+
// joining / merging is not possible
|
|
2163
|
+
return editor.chain().liftListItem(name).run();
|
|
2164
|
+
};
|
|
2165
|
+
|
|
2166
|
+
function findParentNodeClosestToPos($pos, predicate) {
|
|
2167
|
+
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
2168
|
+
const node = $pos.node(i);
|
|
2169
|
+
if (predicate(node)) {
|
|
2170
|
+
return {
|
|
2171
|
+
pos: i > 0 ? $pos.before(i) : 0,
|
|
2172
|
+
start: $pos.start(i),
|
|
2173
|
+
depth: i,
|
|
2174
|
+
node,
|
|
2175
|
+
};
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
function findParentNode(predicate) {
|
|
2181
|
+
return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
const isAtEndOfNode = (state, nodeType) => {
|
|
2185
|
+
const { $from, $to, $anchor } = state.selection;
|
|
2186
|
+
if (nodeType) {
|
|
2187
|
+
const parentNode = findParentNode(node => node.type.name === nodeType)(state.selection);
|
|
2188
|
+
if (!parentNode) {
|
|
2189
|
+
return false;
|
|
2190
|
+
}
|
|
2191
|
+
const $parentPos = state.doc.resolve(parentNode.pos + 1);
|
|
2192
|
+
if ($anchor.pos + 1 === $parentPos.end()) {
|
|
2193
|
+
return true;
|
|
2194
|
+
}
|
|
2195
|
+
return false;
|
|
2196
|
+
}
|
|
2197
|
+
if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
|
|
2198
|
+
return false;
|
|
2199
|
+
}
|
|
2200
|
+
return true;
|
|
2201
|
+
};
|
|
2202
|
+
|
|
2203
|
+
const nextListIsDeeper = (typeOrName, state) => {
|
|
2204
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
2205
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2206
|
+
if (!listItemPos || !listDepth) {
|
|
2207
|
+
return false;
|
|
2208
|
+
}
|
|
2209
|
+
if (listDepth > listItemPos.depth) {
|
|
2210
|
+
return true;
|
|
2211
|
+
}
|
|
2212
|
+
return false;
|
|
2213
|
+
};
|
|
2214
|
+
|
|
2215
|
+
const nextListIsHigher = (typeOrName, state) => {
|
|
2216
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
2217
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2218
|
+
if (!listItemPos || !listDepth) {
|
|
2219
|
+
return false;
|
|
2220
|
+
}
|
|
2221
|
+
if (listDepth < listItemPos.depth) {
|
|
2222
|
+
return true;
|
|
2223
|
+
}
|
|
2224
|
+
return false;
|
|
2225
|
+
};
|
|
2226
|
+
|
|
2227
|
+
const handleDelete = (editor, name) => {
|
|
2228
|
+
// if the cursor is not inside the current node type
|
|
2229
|
+
// do nothing and proceed
|
|
2230
|
+
if (!isNodeActive(editor.state, name)) {
|
|
2231
|
+
return false;
|
|
2232
|
+
}
|
|
2233
|
+
// if the cursor is not at the end of a node
|
|
2234
|
+
// do nothing and proceed
|
|
2235
|
+
if (!isAtEndOfNode(editor.state, name)) {
|
|
2236
|
+
return false;
|
|
2237
|
+
}
|
|
2238
|
+
// check if the next node is a list with a deeper depth
|
|
2239
|
+
if (nextListIsDeeper(name, editor.state)) {
|
|
2240
|
+
return editor
|
|
2241
|
+
.chain()
|
|
2242
|
+
.focus(editor.state.selection.from + 4)
|
|
2243
|
+
.lift(name)
|
|
2244
|
+
.joinBackward()
|
|
2245
|
+
.run();
|
|
2246
|
+
}
|
|
2247
|
+
if (nextListIsHigher(name, editor.state)) {
|
|
2248
|
+
return editor.chain()
|
|
2249
|
+
.joinForward()
|
|
2250
|
+
.joinBackward()
|
|
2251
|
+
.run();
|
|
2252
|
+
}
|
|
2253
|
+
return editor.commands.joinItemForward();
|
|
2254
|
+
};
|
|
2255
|
+
|
|
2256
|
+
const hasListItemAfter = (typeOrName, state) => {
|
|
2257
|
+
var _a;
|
|
2258
|
+
const { $anchor } = state.selection;
|
|
2259
|
+
const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2);
|
|
2260
|
+
if ($targetPos.index() === $targetPos.parent.childCount - 1) {
|
|
2261
|
+
return false;
|
|
2262
|
+
}
|
|
2263
|
+
if (((_a = $targetPos.nodeAfter) === null || _a === void 0 ? void 0 : _a.type.name) !== typeOrName) {
|
|
2264
|
+
return false;
|
|
2265
|
+
}
|
|
2266
|
+
return true;
|
|
2267
|
+
};
|
|
2268
|
+
|
|
1948
2269
|
/**
|
|
1949
2270
|
* Returns a new `Transform` based on all steps of the passed transactions.
|
|
1950
2271
|
*/
|
|
@@ -2006,24 +2327,6 @@ function findChildrenInRange(node, range, predicate) {
|
|
|
2006
2327
|
return nodesWithPos;
|
|
2007
2328
|
}
|
|
2008
2329
|
|
|
2009
|
-
function findParentNodeClosestToPos($pos, predicate) {
|
|
2010
|
-
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
2011
|
-
const node = $pos.node(i);
|
|
2012
|
-
if (predicate(node)) {
|
|
2013
|
-
return {
|
|
2014
|
-
pos: i > 0 ? $pos.before(i) : 0,
|
|
2015
|
-
start: $pos.start(i),
|
|
2016
|
-
depth: i,
|
|
2017
|
-
node,
|
|
2018
|
-
};
|
|
2019
|
-
}
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
|
-
function findParentNode(predicate) {
|
|
2024
|
-
return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
2330
|
function getHTMLFromFragment(fragment, schema) {
|
|
2028
2331
|
const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
|
|
2029
2332
|
const temporaryDocument = document.implementation.createHTMLDocument();
|
|
@@ -2070,28 +2373,6 @@ function generateText(doc, extensions, options) {
|
|
|
2070
2373
|
});
|
|
2071
2374
|
}
|
|
2072
2375
|
|
|
2073
|
-
function getMarkAttributes(state, typeOrName) {
|
|
2074
|
-
const type = getMarkType(typeOrName, state.schema);
|
|
2075
|
-
const { from, to, empty } = state.selection;
|
|
2076
|
-
const marks = [];
|
|
2077
|
-
if (empty) {
|
|
2078
|
-
if (state.storedMarks) {
|
|
2079
|
-
marks.push(...state.storedMarks);
|
|
2080
|
-
}
|
|
2081
|
-
marks.push(...state.selection.$head.marks());
|
|
2082
|
-
}
|
|
2083
|
-
else {
|
|
2084
|
-
state.doc.nodesBetween(from, to, node => {
|
|
2085
|
-
marks.push(...node.marks);
|
|
2086
|
-
});
|
|
2087
|
-
}
|
|
2088
|
-
const mark = marks.find(markItem => markItem.type.name === type.name);
|
|
2089
|
-
if (!mark) {
|
|
2090
|
-
return {};
|
|
2091
|
-
}
|
|
2092
|
-
return { ...mark.attrs };
|
|
2093
|
-
}
|
|
2094
|
-
|
|
2095
2376
|
function getNodeAttributes(state, typeOrName) {
|
|
2096
2377
|
const type = getNodeType(typeOrName, state.schema);
|
|
2097
2378
|
const { from, to } = state.selection;
|
|
@@ -2263,30 +2544,6 @@ function getMarksBetween(from, to, doc) {
|
|
|
2263
2544
|
return marks;
|
|
2264
2545
|
}
|
|
2265
2546
|
|
|
2266
|
-
/**
|
|
2267
|
-
* Finds the first node of a given type or name in the current selection.
|
|
2268
|
-
* @param state The editor state.
|
|
2269
|
-
* @param typeOrName The node type or name.
|
|
2270
|
-
* @param pos The position to start searching from.
|
|
2271
|
-
* @param maxDepth The maximum depth to search.
|
|
2272
|
-
* @returns The node and the depth as an array.
|
|
2273
|
-
*/
|
|
2274
|
-
const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
|
|
2275
|
-
const $pos = state.doc.resolve(pos);
|
|
2276
|
-
let currentDepth = maxDepth;
|
|
2277
|
-
let node = null;
|
|
2278
|
-
while (currentDepth > 0 && node === null) {
|
|
2279
|
-
const currentNode = $pos.node(currentDepth);
|
|
2280
|
-
if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
|
|
2281
|
-
node = currentNode;
|
|
2282
|
-
}
|
|
2283
|
-
else {
|
|
2284
|
-
currentDepth -= 1;
|
|
2285
|
-
}
|
|
2286
|
-
}
|
|
2287
|
-
return [node, currentDepth];
|
|
2288
|
-
};
|
|
2289
|
-
|
|
2290
2547
|
function getSplittedAttributes(extensionAttributes, typeName, attributes) {
|
|
2291
2548
|
return Object.fromEntries(Object
|
|
2292
2549
|
.entries(attributes)
|
|
@@ -2377,22 +2634,6 @@ function isActive(state, name, attributes = {}) {
|
|
|
2377
2634
|
return false;
|
|
2378
2635
|
}
|
|
2379
2636
|
|
|
2380
|
-
const istAtEndOfNode = (state) => {
|
|
2381
|
-
const { $from, $to } = state.selection;
|
|
2382
|
-
if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
|
|
2383
|
-
return false;
|
|
2384
|
-
}
|
|
2385
|
-
return true;
|
|
2386
|
-
};
|
|
2387
|
-
|
|
2388
|
-
const isAtStartOfNode = (state) => {
|
|
2389
|
-
const { $from, $to } = state.selection;
|
|
2390
|
-
if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
|
|
2391
|
-
return false;
|
|
2392
|
-
}
|
|
2393
|
-
return true;
|
|
2394
|
-
};
|
|
2395
|
-
|
|
2396
2637
|
function isList(name, extensions) {
|
|
2397
2638
|
const { nodeExtensions } = splitExtensions(extensions);
|
|
2398
2639
|
const extension = nodeExtensions.find(item => item.name === name);
|
|
@@ -3000,6 +3241,7 @@ var commands = /*#__PURE__*/Object.freeze({
|
|
|
3000
3241
|
clearNodes: clearNodes,
|
|
3001
3242
|
command: command,
|
|
3002
3243
|
createParagraphNear: createParagraphNear,
|
|
3244
|
+
cut: cut,
|
|
3003
3245
|
deleteCurrentNode: deleteCurrentNode,
|
|
3004
3246
|
deleteNode: deleteNode,
|
|
3005
3247
|
deleteRange: deleteRange,
|
|
@@ -3016,6 +3258,8 @@ var commands = /*#__PURE__*/Object.freeze({
|
|
|
3016
3258
|
joinDown: joinDown,
|
|
3017
3259
|
joinBackward: joinBackward,
|
|
3018
3260
|
joinForward: joinForward,
|
|
3261
|
+
joinItemBackward: joinItemBackward,
|
|
3262
|
+
joinItemForward: joinItemForward,
|
|
3019
3263
|
keyboardShortcut: keyboardShortcut,
|
|
3020
3264
|
lift: lift,
|
|
3021
3265
|
liftEmptyBlock: liftEmptyBlock,
|
|
@@ -3317,8 +3561,8 @@ img.ProseMirror-separator {
|
|
|
3317
3561
|
opacity: 0
|
|
3318
3562
|
}`;
|
|
3319
3563
|
|
|
3320
|
-
function createStyleTag(style, nonce) {
|
|
3321
|
-
const tiptapStyleTag = document.querySelector(
|
|
3564
|
+
function createStyleTag(style, nonce, suffix) {
|
|
3565
|
+
const tiptapStyleTag = document.querySelector(`style[data-tiptap-style${suffix ? `-${suffix}` : ''}]`);
|
|
3322
3566
|
if (tiptapStyleTag !== null) {
|
|
3323
3567
|
return tiptapStyleTag;
|
|
3324
3568
|
}
|
|
@@ -3326,7 +3570,7 @@ function createStyleTag(style, nonce) {
|
|
|
3326
3570
|
if (nonce) {
|
|
3327
3571
|
styleNode.setAttribute('nonce', nonce);
|
|
3328
3572
|
}
|
|
3329
|
-
styleNode.setAttribute(
|
|
3573
|
+
styleNode.setAttribute(`data-tiptap-style${suffix ? `-${suffix}` : ''}`, '');
|
|
3330
3574
|
styleNode.innerHTML = style;
|
|
3331
3575
|
document.getElementsByTagName('head')[0].appendChild(styleNode);
|
|
3332
3576
|
return styleNode;
|
|
@@ -3703,7 +3947,6 @@ function markInputRule(config) {
|
|
|
3703
3947
|
const { tr } = state;
|
|
3704
3948
|
const captureGroup = match[match.length - 1];
|
|
3705
3949
|
const fullMatch = match[0];
|
|
3706
|
-
let markEnd = range.to;
|
|
3707
3950
|
if (captureGroup) {
|
|
3708
3951
|
const startSpaces = fullMatch.search(/\S/);
|
|
3709
3952
|
const textStart = range.from + fullMatch.indexOf(captureGroup);
|
|
@@ -3724,7 +3967,7 @@ function markInputRule(config) {
|
|
|
3724
3967
|
if (textStart > range.from) {
|
|
3725
3968
|
tr.delete(range.from + startSpaces, textStart);
|
|
3726
3969
|
}
|
|
3727
|
-
markEnd = range.from + startSpaces + captureGroup.length;
|
|
3970
|
+
const markEnd = range.from + startSpaces + captureGroup.length;
|
|
3728
3971
|
tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}));
|
|
3729
3972
|
tr.removeStoredMark(config.type);
|
|
3730
3973
|
}
|
|
@@ -3740,10 +3983,13 @@ function nodeInputRule(config) {
|
|
|
3740
3983
|
return new InputRule({
|
|
3741
3984
|
find: config.find,
|
|
3742
3985
|
handler: ({ state, range, match }) => {
|
|
3986
|
+
var _a, _b;
|
|
3743
3987
|
const attributes = callOrReturn(config.getAttributes, undefined, match) || {};
|
|
3744
3988
|
const { tr } = state;
|
|
3745
|
-
const start = range.from;
|
|
3989
|
+
const start = config.blockReplace ? range.from - 1 : range.from;
|
|
3746
3990
|
let end = range.to;
|
|
3991
|
+
const newNode = config.type.create(attributes);
|
|
3992
|
+
const { $to } = tr.selection;
|
|
3747
3993
|
if (match[1]) {
|
|
3748
3994
|
const offset = match[0].lastIndexOf(match[1]);
|
|
3749
3995
|
let matchStart = start + offset;
|
|
@@ -3757,10 +4003,33 @@ function nodeInputRule(config) {
|
|
|
3757
4003
|
const lastChar = match[0][match[0].length - 1];
|
|
3758
4004
|
tr.insertText(lastChar, start + match[0].length - 1);
|
|
3759
4005
|
// insert node from input rule
|
|
3760
|
-
tr.replaceWith(matchStart, end,
|
|
4006
|
+
tr.replaceWith(matchStart, end, newNode);
|
|
3761
4007
|
}
|
|
3762
4008
|
else if (match[0]) {
|
|
3763
|
-
tr.replaceWith(start, end,
|
|
4009
|
+
tr.replaceWith(start, end, newNode);
|
|
4010
|
+
}
|
|
4011
|
+
if (config.blockReplace && config.addExtraNewline) {
|
|
4012
|
+
if ($to.nodeAfter) {
|
|
4013
|
+
if ($to.nodeAfter.isTextblock) {
|
|
4014
|
+
tr.setSelection(TextSelection.create(tr.doc, $to.pos + 1));
|
|
4015
|
+
}
|
|
4016
|
+
else if ($to.nodeAfter.isBlock) {
|
|
4017
|
+
tr.setSelection(NodeSelection.create(tr.doc, $to.pos));
|
|
4018
|
+
}
|
|
4019
|
+
else {
|
|
4020
|
+
tr.setSelection(TextSelection.create(tr.doc, $to.pos - 1));
|
|
4021
|
+
}
|
|
4022
|
+
}
|
|
4023
|
+
else {
|
|
4024
|
+
// add node after horizontal rule if it’s the end of the document
|
|
4025
|
+
const defaultNode = ((_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create()) || ((_b = state.doc.type.contentMatch.defaultType) === null || _b === void 0 ? void 0 : _b.create());
|
|
4026
|
+
if (defaultNode) {
|
|
4027
|
+
const newPos = start + newNode.nodeSize;
|
|
4028
|
+
tr.insert(newPos, defaultNode);
|
|
4029
|
+
tr.setSelection(TextSelection.create(tr.doc, newPos));
|
|
4030
|
+
}
|
|
4031
|
+
}
|
|
4032
|
+
tr.scrollIntoView();
|
|
3764
4033
|
}
|
|
3765
4034
|
},
|
|
3766
4035
|
});
|
|
@@ -4012,6 +4281,10 @@ class Node {
|
|
|
4012
4281
|
}
|
|
4013
4282
|
}
|
|
4014
4283
|
|
|
4284
|
+
function isAndroid() {
|
|
4285
|
+
return navigator.platform === 'Android' || /android/i.test(navigator.userAgent);
|
|
4286
|
+
}
|
|
4287
|
+
|
|
4015
4288
|
class NodeView {
|
|
4016
4289
|
constructor(component, props, options) {
|
|
4017
4290
|
this.isDragging = false;
|
|
@@ -4152,13 +4425,14 @@ class NodeView {
|
|
|
4152
4425
|
if (mutation.type === 'selection') {
|
|
4153
4426
|
return false;
|
|
4154
4427
|
}
|
|
4155
|
-
// try to prevent a bug on iOS that will break node views on enter
|
|
4428
|
+
// try to prevent a bug on iOS and Android that will break node views on enter
|
|
4156
4429
|
// this is because ProseMirror can’t preventDispatch on enter
|
|
4157
4430
|
// this will lead to a re-render of the node view on enter
|
|
4158
4431
|
// see: https://github.com/ueberdosis/tiptap/issues/1214
|
|
4432
|
+
// see: https://github.com/ueberdosis/tiptap/issues/2534
|
|
4159
4433
|
if (this.dom.contains(mutation.target)
|
|
4160
4434
|
&& mutation.type === 'childList'
|
|
4161
|
-
&& isiOS()
|
|
4435
|
+
&& (isiOS() || isAndroid())
|
|
4162
4436
|
&& this.editor.isFocused) {
|
|
4163
4437
|
const changedNodes = [
|
|
4164
4438
|
...Array.from(mutation.addedNodes),
|
|
@@ -4322,5 +4596,5 @@ class Tracker {
|
|
|
4322
4596
|
}
|
|
4323
4597
|
}
|
|
4324
4598
|
|
|
4325
|
-
export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, createChainableState, createDocument, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, fromString, generateHTML, generateJSON, generateText, getAttributes, getAttributesFromExtensions, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAtPosition, getNodeAttributes, getNodeType, getRenderedAttributes, getSchema, getSchemaByResolvedExtensions, getSchemaTypeByName, getSchemaTypeNameByName, getSplittedAttributes, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, injectExtensionAttributesToParseRule, inputRulesPlugin, isActive, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS,
|
|
4599
|
+
export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, createChainableState, createDocument, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, extensions, findChildren, findChildrenInRange, findDuplicates, findListItemPos, findParentNode, findParentNodeClosestToPos, fromString, generateHTML, generateJSON, generateText, getAttributes, getAttributesFromExtensions, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNextListDepth, getNodeAtPosition, getNodeAttributes, getNodeType, getRenderedAttributes, getSchema, getSchemaByResolvedExtensions, getSchemaTypeByName, getSchemaTypeNameByName, getSplittedAttributes, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, handleBackspace, handleDelete, hasListBefore, hasListItemAfter, hasListItemBefore, injectExtensionAttributesToParseRule, inputRulesPlugin, isActive, isAtEndOfNode, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, listItemHasSubList, markInputRule, markPasteRule, mergeAttributes, mergeDeep, minMax, nextListIsDeeper, nextListIsHigher, nodeInputRule, nodePasteRule, objectIncludes, pasteRulesPlugin, posToDOMRect, removeDuplicates, resolveFocusPosition, selectionToInsertionEnd, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
|
|
4326
4600
|
//# sourceMappingURL=index.js.map
|