@tiptap/core 3.0.0 → 3.0.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/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +5169 -4654
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3356 -0
- package/dist/index.d.ts +3356 -0
- package/dist/index.js +5051 -4561
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime/jsx-runtime.cjs +56 -0
- package/dist/jsx-runtime/jsx-runtime.cjs.map +1 -0
- package/dist/jsx-runtime/jsx-runtime.d.cts +22 -0
- package/dist/jsx-runtime/jsx-runtime.d.ts +22 -0
- package/dist/jsx-runtime/jsx-runtime.js +26 -0
- package/dist/jsx-runtime/jsx-runtime.js.map +1 -0
- package/jsx-dev-runtime/index.cjs +1 -0
- package/jsx-dev-runtime/index.d.cts +1 -0
- package/jsx-dev-runtime/index.d.ts +1 -0
- package/jsx-dev-runtime/index.js +1 -0
- package/jsx-runtime/index.cjs +1 -0
- package/jsx-runtime/index.d.cts +1 -0
- package/jsx-runtime/index.d.ts +1 -0
- package/jsx-runtime/index.js +1 -0
- package/package.json +30 -10
- package/src/CommandManager.ts +4 -11
- package/src/Editor.ts +273 -100
- package/src/EventEmitter.ts +16 -10
- package/src/Extendable.ts +484 -0
- package/src/Extension.ts +29 -493
- package/src/ExtensionManager.ts +100 -143
- package/src/InputRule.ts +28 -24
- package/src/Mark.ts +157 -624
- package/src/MarkView.ts +122 -0
- package/src/Node.ts +343 -807
- package/src/NodePos.ts +18 -9
- package/src/NodeView.ts +58 -35
- package/src/PasteRule.ts +68 -24
- package/src/Tracker.ts +8 -10
- package/src/commands/blur.ts +15 -13
- package/src/commands/clearContent.ts +13 -6
- package/src/commands/clearNodes.ts +33 -31
- package/src/commands/command.ts +2 -2
- package/src/commands/createParagraphNear.ts +6 -4
- package/src/commands/cut.ts +13 -11
- package/src/commands/deleteCurrentNode.ts +24 -22
- package/src/commands/deleteNode.ts +20 -18
- package/src/commands/deleteRange.ts +11 -9
- package/src/commands/deleteSelection.ts +6 -4
- package/src/commands/enter.ts +7 -5
- package/src/commands/exitCode.ts +6 -4
- package/src/commands/extendMarkRange.ts +16 -14
- package/src/commands/first.ts +3 -5
- package/src/commands/focus.ts +51 -53
- package/src/commands/forEach.ts +3 -3
- package/src/commands/insertContent.ts +8 -10
- package/src/commands/insertContentAt.ts +131 -76
- package/src/commands/join.ts +21 -13
- package/src/commands/joinItemBackward.ts +17 -19
- package/src/commands/joinItemForward.ts +17 -19
- package/src/commands/joinTextblockBackward.ts +6 -4
- package/src/commands/joinTextblockForward.ts +6 -4
- package/src/commands/keyboardShortcut.ts +30 -35
- package/src/commands/lift.ts +12 -10
- package/src/commands/liftEmptyBlock.ts +7 -5
- package/src/commands/liftListItem.ts +8 -6
- package/src/commands/newlineInCode.ts +6 -4
- package/src/commands/resetAttributes.ts +38 -43
- package/src/commands/scrollIntoView.ts +10 -8
- package/src/commands/selectAll.ts +15 -8
- package/src/commands/selectNodeBackward.ts +6 -4
- package/src/commands/selectNodeForward.ts +6 -4
- package/src/commands/selectParentNode.ts +6 -4
- package/src/commands/selectTextblockEnd.ts +6 -4
- package/src/commands/selectTextblockStart.ts +6 -4
- package/src/commands/setContent.ts +37 -40
- package/src/commands/setMark.ts +58 -60
- package/src/commands/setMeta.ts +10 -6
- package/src/commands/setNode.ts +36 -27
- package/src/commands/setNodeSelection.ts +12 -10
- package/src/commands/setTextSelection.ts +16 -14
- package/src/commands/sinkListItem.ts +8 -6
- package/src/commands/splitBlock.ts +60 -68
- package/src/commands/splitListItem.ts +99 -101
- package/src/commands/toggleList.ts +76 -74
- package/src/commands/toggleMark.ts +13 -11
- package/src/commands/toggleNode.ts +22 -11
- package/src/commands/toggleWrap.ts +12 -10
- package/src/commands/undoInputRule.ts +32 -30
- package/src/commands/unsetAllMarks.ts +17 -15
- package/src/commands/unsetMark.ts +29 -27
- package/src/commands/updateAttributes.ts +97 -45
- package/src/commands/wrapIn.ts +8 -6
- package/src/commands/wrapInList.ts +8 -6
- package/src/extensions/clipboardTextSerializer.ts +2 -4
- package/src/extensions/delete.ts +89 -0
- package/src/extensions/drop.ts +26 -0
- package/src/extensions/focusEvents.ts +5 -7
- package/src/extensions/index.ts +4 -1
- package/src/extensions/keymap.ts +63 -52
- package/src/extensions/paste.ts +25 -0
- package/src/extensions/tabindex.ts +1 -1
- package/src/helpers/combineTransactionSteps.ts +3 -6
- package/src/helpers/createChainableState.ts +2 -5
- package/src/helpers/createDocument.ts +3 -3
- package/src/helpers/createNodeFromContent.ts +37 -25
- package/src/helpers/defaultBlockAt.ts +1 -1
- package/src/helpers/findChildren.ts +2 -2
- package/src/helpers/findChildrenInRange.ts +3 -7
- package/src/helpers/findParentNode.ts +5 -3
- package/src/helpers/findParentNodeClosestToPos.ts +2 -2
- package/src/helpers/flattenExtensions.ts +30 -0
- package/src/helpers/generateHTML.ts +1 -1
- package/src/helpers/generateJSON.ts +1 -1
- package/src/helpers/generateText.ts +1 -1
- package/src/helpers/getAttributes.ts +3 -6
- package/src/helpers/getAttributesFromExtensions.ts +29 -38
- package/src/helpers/getChangedRanges.ts +15 -13
- package/src/helpers/getDebugJSON.ts +2 -2
- package/src/helpers/getExtensionField.ts +12 -12
- package/src/helpers/getHTMLFromFragment.ts +2 -1
- package/src/helpers/getMarkAttributes.ts +3 -6
- package/src/helpers/getMarkRange.ts +36 -19
- package/src/helpers/getMarkType.ts +2 -4
- package/src/helpers/getMarksBetween.ts +3 -3
- package/src/helpers/getNodeAtPosition.ts +2 -2
- package/src/helpers/getNodeAttributes.ts +3 -6
- package/src/helpers/getNodeType.ts +2 -4
- package/src/helpers/getRenderedAttributes.ts +3 -2
- package/src/helpers/getSchema.ts +5 -5
- package/src/helpers/getSchemaByResolvedExtensions.ts +49 -79
- package/src/helpers/getSchemaTypeByName.ts +1 -1
- package/src/helpers/getSchemaTypeNameByName.ts +1 -1
- package/src/helpers/getSplittedAttributes.ts +5 -5
- package/src/helpers/getText.ts +2 -2
- package/src/helpers/getTextBetween.ts +2 -2
- package/src/helpers/getTextContentFromNodes.ts +9 -12
- package/src/helpers/getTextSerializersFromSchema.ts +2 -2
- package/src/helpers/index.ts +4 -0
- package/src/helpers/injectExtensionAttributesToParseRule.ts +3 -3
- package/src/helpers/isActive.ts +2 -6
- package/src/helpers/isAtEndOfNode.ts +1 -1
- package/src/helpers/isAtStartOfNode.ts +1 -1
- package/src/helpers/isExtensionRulesEnabled.ts +2 -4
- package/src/helpers/isList.ts +2 -2
- package/src/helpers/isMarkActive.ts +3 -3
- package/src/helpers/isNodeActive.ts +3 -3
- package/src/helpers/isNodeEmpty.ts +56 -5
- package/src/helpers/posToDOMRect.ts +1 -1
- package/src/helpers/resolveExtensions.ts +25 -0
- package/src/helpers/resolveFocusPosition.ts +5 -16
- package/src/helpers/rewriteUnknownContent.ts +149 -0
- package/src/helpers/selectionToInsertionEnd.ts +2 -1
- package/src/helpers/sortExtensions.ts +26 -0
- package/src/helpers/splitExtensions.ts +4 -4
- package/src/index.ts +3 -7
- package/src/inputRules/markInputRule.ts +6 -9
- package/src/inputRules/nodeInputRule.ts +7 -13
- package/src/inputRules/textInputRule.ts +4 -6
- package/src/inputRules/textblockTypeInputRule.ts +7 -12
- package/src/inputRules/wrappingInputRule.ts +19 -24
- package/src/jsx-runtime.ts +64 -0
- package/src/pasteRules/markPasteRule.ts +6 -7
- package/src/pasteRules/nodePasteRule.ts +15 -11
- package/src/pasteRules/textPasteRule.ts +4 -6
- package/src/style.ts +2 -6
- package/src/types.ts +513 -58
- package/src/utilities/callOrReturn.ts +1 -1
- package/src/utilities/canInsertNode.ts +30 -0
- package/src/utilities/createStyleTag.ts +3 -1
- package/src/utilities/deleteProps.ts +7 -11
- package/src/utilities/elementFromString.ts +3 -0
- package/src/utilities/findDuplicates.ts +5 -2
- package/src/utilities/index.ts +2 -0
- package/src/utilities/isFunction.ts +1 -0
- package/src/utilities/isMacOS.ts +1 -3
- package/src/utilities/isiOS.ts +5 -10
- package/src/utilities/mergeAttributes.ts +32 -5
- package/src/utilities/removeDuplicates.ts +1 -3
- package/dist/index.umd.js +0 -5098
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -161
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -343
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -451
- package/dist/packages/core/src/Node.d.ts +0 -611
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -255
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
package/src/commands/wrapIn.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { wrapIn as originalWrapIn } from '@tiptap/pm/commands'
|
|
2
|
-
import { NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import type { NodeType } from '@tiptap/pm/model'
|
|
3
3
|
|
|
4
4
|
import { getNodeType } from '../helpers/getNodeType.js'
|
|
5
|
-
import { RawCommands } from '../types.js'
|
|
5
|
+
import type { RawCommands } from '../types.js'
|
|
6
6
|
|
|
7
7
|
declare module '@tiptap/core' {
|
|
8
8
|
interface Commands<ReturnType> {
|
|
@@ -18,8 +18,10 @@ declare module '@tiptap/core' {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export const wrapIn: RawCommands['wrapIn'] =
|
|
22
|
-
|
|
21
|
+
export const wrapIn: RawCommands['wrapIn'] =
|
|
22
|
+
(typeOrName, attributes = {}) =>
|
|
23
|
+
({ state, dispatch }) => {
|
|
24
|
+
const type = getNodeType(typeOrName, state.schema)
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
+
return originalWrapIn(type, attributes)(state, dispatch)
|
|
27
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { NodeType } from '@tiptap/pm/model'
|
|
1
|
+
import type { NodeType } from '@tiptap/pm/model'
|
|
2
2
|
import { wrapInList as originalWrapInList } from '@tiptap/pm/schema-list'
|
|
3
3
|
|
|
4
4
|
import { getNodeType } from '../helpers/getNodeType.js'
|
|
5
|
-
import { RawCommands } from '../types.js'
|
|
5
|
+
import type { RawCommands } from '../types.js'
|
|
6
6
|
|
|
7
7
|
declare module '@tiptap/core' {
|
|
8
8
|
interface Commands<ReturnType> {
|
|
@@ -18,8 +18,10 @@ declare module '@tiptap/core' {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export const wrapInList: RawCommands['wrapInList'] =
|
|
22
|
-
|
|
21
|
+
export const wrapInList: RawCommands['wrapInList'] =
|
|
22
|
+
(typeOrName, attributes = {}) =>
|
|
23
|
+
({ state, dispatch }) => {
|
|
24
|
+
const type = getNodeType(typeOrName, state.schema)
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
+
return originalWrapInList(type, attributes)(state, dispatch)
|
|
27
|
+
}
|
|
@@ -5,7 +5,7 @@ import { getTextBetween } from '../helpers/getTextBetween.js'
|
|
|
5
5
|
import { getTextSerializersFromSchema } from '../helpers/getTextSerializersFromSchema.js'
|
|
6
6
|
|
|
7
7
|
export type ClipboardTextSerializerOptions = {
|
|
8
|
-
blockSeparator?: string
|
|
8
|
+
blockSeparator?: string
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const ClipboardTextSerializer = Extension.create<ClipboardTextSerializerOptions>({
|
|
@@ -33,9 +33,7 @@ export const ClipboardTextSerializer = Extension.create<ClipboardTextSerializerO
|
|
|
33
33
|
const range = { from, to }
|
|
34
34
|
|
|
35
35
|
return getTextBetween(doc, range, {
|
|
36
|
-
...(this.options.blockSeparator !== undefined
|
|
37
|
-
? { blockSeparator: this.options.blockSeparator }
|
|
38
|
-
: {}),
|
|
36
|
+
...(this.options.blockSeparator !== undefined ? { blockSeparator: this.options.blockSeparator } : {}),
|
|
39
37
|
textSerializers,
|
|
40
38
|
})
|
|
41
39
|
},
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { RemoveMarkStep } from '@tiptap/pm/transform'
|
|
2
|
+
|
|
3
|
+
import { Extension } from '../Extension.js'
|
|
4
|
+
import { combineTransactionSteps, getChangedRanges } from '../helpers/index.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This extension allows you to be notified when the user deletes content you are interested in.
|
|
8
|
+
*/
|
|
9
|
+
export const Delete = Extension.create({
|
|
10
|
+
name: 'delete',
|
|
11
|
+
|
|
12
|
+
onUpdate({ transaction, appendedTransactions }) {
|
|
13
|
+
const callback = () => {
|
|
14
|
+
if (
|
|
15
|
+
this.editor.options.coreExtensionOptions?.delete?.filterTransaction?.(transaction) ??
|
|
16
|
+
transaction.getMeta('y-sync$')
|
|
17
|
+
) {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
const nextTransaction = combineTransactionSteps(transaction.before, [transaction, ...appendedTransactions])
|
|
21
|
+
const changes = getChangedRanges(nextTransaction)
|
|
22
|
+
|
|
23
|
+
changes.forEach(change => {
|
|
24
|
+
if (
|
|
25
|
+
nextTransaction.mapping.mapResult(change.oldRange.from).deletedAfter &&
|
|
26
|
+
nextTransaction.mapping.mapResult(change.oldRange.to).deletedBefore
|
|
27
|
+
) {
|
|
28
|
+
nextTransaction.before.nodesBetween(change.oldRange.from, change.oldRange.to, (node, from) => {
|
|
29
|
+
const to = from + node.nodeSize - 2
|
|
30
|
+
const isFullyWithinRange = change.oldRange.from <= from && to <= change.oldRange.to
|
|
31
|
+
|
|
32
|
+
this.editor.emit('delete', {
|
|
33
|
+
type: 'node',
|
|
34
|
+
node,
|
|
35
|
+
from,
|
|
36
|
+
to,
|
|
37
|
+
newFrom: nextTransaction.mapping.map(from),
|
|
38
|
+
newTo: nextTransaction.mapping.map(to),
|
|
39
|
+
deletedRange: change.oldRange,
|
|
40
|
+
newRange: change.newRange,
|
|
41
|
+
partial: !isFullyWithinRange,
|
|
42
|
+
editor: this.editor,
|
|
43
|
+
transaction,
|
|
44
|
+
combinedTransform: nextTransaction,
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const mapping = nextTransaction.mapping
|
|
51
|
+
nextTransaction.steps.forEach((step, index) => {
|
|
52
|
+
if (step instanceof RemoveMarkStep) {
|
|
53
|
+
const newStart = mapping.slice(index).map(step.from, -1)
|
|
54
|
+
const newEnd = mapping.slice(index).map(step.to)
|
|
55
|
+
const oldStart = mapping.invert().map(newStart, -1)
|
|
56
|
+
const oldEnd = mapping.invert().map(newEnd)
|
|
57
|
+
|
|
58
|
+
const foundBeforeMark = nextTransaction.doc.nodeAt(newStart - 1)?.marks.some(mark => mark.eq(step.mark))
|
|
59
|
+
const foundAfterMark = nextTransaction.doc.nodeAt(newEnd)?.marks.some(mark => mark.eq(step.mark))
|
|
60
|
+
|
|
61
|
+
this.editor.emit('delete', {
|
|
62
|
+
type: 'mark',
|
|
63
|
+
mark: step.mark,
|
|
64
|
+
from: step.from,
|
|
65
|
+
to: step.to,
|
|
66
|
+
deletedRange: {
|
|
67
|
+
from: oldStart,
|
|
68
|
+
to: oldEnd,
|
|
69
|
+
},
|
|
70
|
+
newRange: {
|
|
71
|
+
from: newStart,
|
|
72
|
+
to: newEnd,
|
|
73
|
+
},
|
|
74
|
+
partial: Boolean(foundAfterMark || foundBeforeMark),
|
|
75
|
+
editor: this.editor,
|
|
76
|
+
transaction,
|
|
77
|
+
combinedTransform: nextTransaction,
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (this.editor.options.coreExtensionOptions?.delete?.async ?? true) {
|
|
84
|
+
setTimeout(callback, 0)
|
|
85
|
+
} else {
|
|
86
|
+
callback()
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state'
|
|
2
|
+
|
|
3
|
+
import { Extension } from '../Extension.js'
|
|
4
|
+
|
|
5
|
+
export const Drop = Extension.create({
|
|
6
|
+
name: 'drop',
|
|
7
|
+
|
|
8
|
+
addProseMirrorPlugins() {
|
|
9
|
+
return [
|
|
10
|
+
new Plugin({
|
|
11
|
+
key: new PluginKey('tiptapDrop'),
|
|
12
|
+
|
|
13
|
+
props: {
|
|
14
|
+
handleDrop: (_, e, slice, moved) => {
|
|
15
|
+
this.editor.emit('drop', {
|
|
16
|
+
editor: this.editor,
|
|
17
|
+
event: e,
|
|
18
|
+
slice,
|
|
19
|
+
moved,
|
|
20
|
+
})
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
}),
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
})
|
|
@@ -2,6 +2,8 @@ import { Plugin, PluginKey } from '@tiptap/pm/state'
|
|
|
2
2
|
|
|
3
3
|
import { Extension } from '../Extension.js'
|
|
4
4
|
|
|
5
|
+
export const focusEventsPluginKey = new PluginKey('focusEvents')
|
|
6
|
+
|
|
5
7
|
export const FocusEvents = Extension.create({
|
|
6
8
|
name: 'focusEvents',
|
|
7
9
|
|
|
@@ -10,15 +12,13 @@ export const FocusEvents = Extension.create({
|
|
|
10
12
|
|
|
11
13
|
return [
|
|
12
14
|
new Plugin({
|
|
13
|
-
key:
|
|
15
|
+
key: focusEventsPluginKey,
|
|
14
16
|
props: {
|
|
15
17
|
handleDOMEvents: {
|
|
16
18
|
focus: (view, event: Event) => {
|
|
17
19
|
editor.isFocused = true
|
|
18
20
|
|
|
19
|
-
const transaction = editor.state.tr
|
|
20
|
-
.setMeta('focus', { event })
|
|
21
|
-
.setMeta('addToHistory', false)
|
|
21
|
+
const transaction = editor.state.tr.setMeta('focus', { event }).setMeta('addToHistory', false)
|
|
22
22
|
|
|
23
23
|
view.dispatch(transaction)
|
|
24
24
|
|
|
@@ -27,9 +27,7 @@ export const FocusEvents = Extension.create({
|
|
|
27
27
|
blur: (view, event: Event) => {
|
|
28
28
|
editor.isFocused = false
|
|
29
29
|
|
|
30
|
-
const transaction = editor.state.tr
|
|
31
|
-
.setMeta('blur', { event })
|
|
32
|
-
.setMeta('addToHistory', false)
|
|
30
|
+
const transaction = editor.state.tr.setMeta('blur', { event }).setMeta('addToHistory', false)
|
|
33
31
|
|
|
34
32
|
view.dispatch(transaction)
|
|
35
33
|
|
package/src/extensions/index.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { ClipboardTextSerializer } from './clipboardTextSerializer.js'
|
|
2
2
|
export { Commands } from './commands.js'
|
|
3
|
+
export { Delete } from './delete.js'
|
|
4
|
+
export { Drop } from './drop.js'
|
|
3
5
|
export { Editable } from './editable.js'
|
|
4
|
-
export { FocusEvents } from './focusEvents.js'
|
|
6
|
+
export { FocusEvents, focusEventsPluginKey } from './focusEvents.js'
|
|
5
7
|
export { Keymap } from './keymap.js'
|
|
8
|
+
export { Paste } from './paste.js'
|
|
6
9
|
export { Tabindex } from './tabindex.js'
|
package/src/extensions/keymap.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Plugin, PluginKey, Selection } from '@tiptap/pm/state'
|
|
|
3
3
|
import { CommandManager } from '../CommandManager.js'
|
|
4
4
|
import { Extension } from '../Extension.js'
|
|
5
5
|
import { createChainableState } from '../helpers/createChainableState.js'
|
|
6
|
+
import { isNodeEmpty } from '../helpers/isNodeEmpty.js'
|
|
6
7
|
import { isiOS } from '../utilities/isiOS.js'
|
|
7
8
|
import { isMacOS } from '../utilities/isMacOS.js'
|
|
8
9
|
|
|
@@ -10,54 +11,59 @@ export const Keymap = Extension.create({
|
|
|
10
11
|
name: 'keymap',
|
|
11
12
|
|
|
12
13
|
addKeyboardShortcuts() {
|
|
13
|
-
const handleBackspace = () =>
|
|
14
|
-
() =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
() =>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
14
|
+
const handleBackspace = () =>
|
|
15
|
+
this.editor.commands.first(({ commands }) => [
|
|
16
|
+
() => commands.undoInputRule(),
|
|
17
|
+
|
|
18
|
+
// maybe convert first text block node to default node
|
|
19
|
+
() =>
|
|
20
|
+
commands.command(({ tr }) => {
|
|
21
|
+
const { selection, doc } = tr
|
|
22
|
+
const { empty, $anchor } = selection
|
|
23
|
+
const { pos, parent } = $anchor
|
|
24
|
+
const $parentPos = $anchor.parent.isTextblock && pos > 0 ? tr.doc.resolve(pos - 1) : $anchor
|
|
25
|
+
const parentIsIsolating = $parentPos.parent.type.spec.isolating
|
|
26
|
+
|
|
27
|
+
const parentPos = $anchor.pos - $anchor.parentOffset
|
|
28
|
+
|
|
29
|
+
const isAtStart =
|
|
30
|
+
parentIsIsolating && $parentPos.parent.childCount === 1
|
|
31
|
+
? parentPos === $anchor.pos
|
|
32
|
+
: Selection.atStart(doc).from === pos
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
!empty ||
|
|
36
|
+
!parent.type.isTextblock ||
|
|
37
|
+
parent.textContent.length ||
|
|
38
|
+
!isAtStart ||
|
|
39
|
+
(isAtStart && $anchor.parent.type.name === 'paragraph') // prevent clearNodes when no nodes to clear, otherwise history stack is appended
|
|
40
|
+
) {
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return commands.clearNodes()
|
|
45
|
+
}),
|
|
46
|
+
|
|
47
|
+
() => commands.deleteSelection(),
|
|
48
|
+
() => commands.joinBackward(),
|
|
49
|
+
() => commands.selectNodeBackward(),
|
|
50
|
+
])
|
|
51
|
+
|
|
52
|
+
const handleDelete = () =>
|
|
53
|
+
this.editor.commands.first(({ commands }) => [
|
|
54
|
+
() => commands.deleteSelection(),
|
|
55
|
+
() => commands.deleteCurrentNode(),
|
|
56
|
+
() => commands.joinForward(),
|
|
57
|
+
() => commands.selectNodeForward(),
|
|
58
|
+
])
|
|
59
|
+
|
|
60
|
+
const handleEnter = () =>
|
|
61
|
+
this.editor.commands.first(({ commands }) => [
|
|
62
|
+
() => commands.newlineInCode(),
|
|
63
|
+
() => commands.createParagraphNear(),
|
|
64
|
+
() => commands.liftEmptyBlock(),
|
|
65
|
+
() => commands.splitBlock(),
|
|
66
|
+
])
|
|
61
67
|
|
|
62
68
|
const baseKeymap = {
|
|
63
69
|
Enter: handleEnter,
|
|
@@ -103,10 +109,15 @@ export const Keymap = Extension.create({
|
|
|
103
109
|
new Plugin({
|
|
104
110
|
key: new PluginKey('clearDocument'),
|
|
105
111
|
appendTransaction: (transactions, oldState, newState) => {
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
if (transactions.some(tr => tr.getMeta('composition'))) {
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const docChanges = transactions.some(transaction => transaction.docChanged) && !oldState.doc.eq(newState.doc)
|
|
117
|
+
|
|
118
|
+
const ignoreTr = transactions.some(transaction => transaction.getMeta('preventClearDocument'))
|
|
108
119
|
|
|
109
|
-
if (!docChanges) {
|
|
120
|
+
if (!docChanges || ignoreTr) {
|
|
110
121
|
return
|
|
111
122
|
}
|
|
112
123
|
|
|
@@ -119,7 +130,7 @@ export const Keymap = Extension.create({
|
|
|
119
130
|
return
|
|
120
131
|
}
|
|
121
132
|
|
|
122
|
-
const isEmpty =
|
|
133
|
+
const isEmpty = isNodeEmpty(newState.doc)
|
|
123
134
|
|
|
124
135
|
if (!isEmpty) {
|
|
125
136
|
return
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state'
|
|
2
|
+
|
|
3
|
+
import { Extension } from '../Extension.js'
|
|
4
|
+
|
|
5
|
+
export const Paste = Extension.create({
|
|
6
|
+
name: 'paste',
|
|
7
|
+
|
|
8
|
+
addProseMirrorPlugins() {
|
|
9
|
+
return [
|
|
10
|
+
new Plugin({
|
|
11
|
+
key: new PluginKey('tiptapPaste'),
|
|
12
|
+
|
|
13
|
+
props: {
|
|
14
|
+
handlePaste: (_view, e, slice) => {
|
|
15
|
+
this.editor.emit('paste', {
|
|
16
|
+
editor: this.editor,
|
|
17
|
+
event: e,
|
|
18
|
+
slice,
|
|
19
|
+
})
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
})
|
|
@@ -10,7 +10,7 @@ export const Tabindex = Extension.create({
|
|
|
10
10
|
new Plugin({
|
|
11
11
|
key: new PluginKey('tabindex'),
|
|
12
12
|
props: {
|
|
13
|
-
attributes: (): { [name: string]: string
|
|
13
|
+
attributes: (): { [name: string]: string } => (this.editor.isEditable ? { tabindex: '0' } : {}),
|
|
14
14
|
},
|
|
15
15
|
}),
|
|
16
16
|
]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
|
-
import { Transaction } from '@tiptap/pm/state'
|
|
1
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
|
+
import type { Transaction } from '@tiptap/pm/state'
|
|
3
3
|
import { Transform } from '@tiptap/pm/transform'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -8,10 +8,7 @@ import { Transform } from '@tiptap/pm/transform'
|
|
|
8
8
|
* @param transactions The transactions to combine
|
|
9
9
|
* @returns A new `Transform` with all steps of the passed transactions
|
|
10
10
|
*/
|
|
11
|
-
export function combineTransactionSteps(
|
|
12
|
-
oldDoc: ProseMirrorNode,
|
|
13
|
-
transactions: Transaction[],
|
|
14
|
-
): Transform {
|
|
11
|
+
export function combineTransactionSteps(oldDoc: ProseMirrorNode, transactions: Transaction[]): Transform {
|
|
15
12
|
const transform = new Transform(oldDoc)
|
|
16
13
|
|
|
17
14
|
transactions.forEach(transaction => {
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { EditorState, Transaction } from '@tiptap/pm/state'
|
|
1
|
+
import type { EditorState, Transaction } from '@tiptap/pm/state'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Takes a Transaction & Editor State and turns it into a chainable state object
|
|
5
5
|
* @param config The transaction and state to create the chainable state from
|
|
6
6
|
* @returns A chainable Editor state object
|
|
7
7
|
*/
|
|
8
|
-
export function createChainableState(config: {
|
|
9
|
-
transaction: Transaction
|
|
10
|
-
state: EditorState
|
|
11
|
-
}): EditorState {
|
|
8
|
+
export function createChainableState(config: { transaction: Transaction; state: EditorState }): EditorState {
|
|
12
9
|
const { state, transaction } = config
|
|
13
10
|
let { selection } = transaction
|
|
14
11
|
let { doc } = transaction
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode, ParseOptions, Schema } from '@tiptap/pm/model'
|
|
1
|
+
import type { Fragment, Node as ProseMirrorNode, ParseOptions, Schema } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { Content } from '../types.js'
|
|
3
|
+
import type { Content } from '../types.js'
|
|
4
4
|
import { createNodeFromContent } from './createNodeFromContent.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -11,7 +11,7 @@ import { createNodeFromContent } from './createNodeFromContent.js'
|
|
|
11
11
|
* @returns The created Prosemirror document node
|
|
12
12
|
*/
|
|
13
13
|
export function createDocument(
|
|
14
|
-
content: Content,
|
|
14
|
+
content: Content | ProseMirrorNode | Fragment,
|
|
15
15
|
schema: Schema,
|
|
16
16
|
parseOptions: ParseOptions = {},
|
|
17
17
|
options: { errorOnInvalidContent?: boolean } = {},
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
ParseOptions,
|
|
6
|
-
Schema,
|
|
7
|
-
} from '@tiptap/pm/model'
|
|
8
|
-
|
|
9
|
-
import { Content } from '../types.js'
|
|
1
|
+
import type { ParseOptions } from '@tiptap/pm/model'
|
|
2
|
+
import { DOMParser, Fragment, Node as ProseMirrorNode, Schema } from '@tiptap/pm/model'
|
|
3
|
+
|
|
4
|
+
import type { Content } from '../types.js'
|
|
10
5
|
import { elementFromString } from '../utilities/elementFromString.js'
|
|
11
6
|
|
|
12
7
|
export type CreateNodeFromContentOptions = {
|
|
@@ -23,10 +18,13 @@ export type CreateNodeFromContentOptions = {
|
|
|
23
18
|
* @returns The created Prosemirror node or fragment
|
|
24
19
|
*/
|
|
25
20
|
export function createNodeFromContent(
|
|
26
|
-
content: Content,
|
|
21
|
+
content: Content | ProseMirrorNode | Fragment,
|
|
27
22
|
schema: Schema,
|
|
28
23
|
options?: CreateNodeFromContentOptions,
|
|
29
24
|
): ProseMirrorNode | Fragment {
|
|
25
|
+
if (content instanceof ProseMirrorNode || content instanceof Fragment) {
|
|
26
|
+
return content
|
|
27
|
+
}
|
|
30
28
|
options = {
|
|
31
29
|
slice: true,
|
|
32
30
|
parseOptions: {},
|
|
@@ -45,7 +43,13 @@ export function createNodeFromContent(
|
|
|
45
43
|
return Fragment.fromArray(content.map(item => schema.nodeFromJSON(item)))
|
|
46
44
|
}
|
|
47
45
|
|
|
48
|
-
|
|
46
|
+
const node = schema.nodeFromJSON(content)
|
|
47
|
+
|
|
48
|
+
if (options.errorOnInvalidContent) {
|
|
49
|
+
node.check()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return node
|
|
49
53
|
} catch (error) {
|
|
50
54
|
if (options.errorOnInvalidContent) {
|
|
51
55
|
throw new Error('[tiptap error]: Invalid JSON content', { cause: error as Error })
|
|
@@ -58,13 +62,13 @@ export function createNodeFromContent(
|
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
if (isTextContent) {
|
|
61
|
-
|
|
62
|
-
let hasInvalidContent = false
|
|
63
|
-
let invalidContent = ''
|
|
64
|
-
|
|
65
|
-
// Only ever check for invalid content if we're supposed to throw an error
|
|
65
|
+
// Check for invalid content
|
|
66
66
|
if (options.errorOnInvalidContent) {
|
|
67
|
-
|
|
67
|
+
let hasInvalidContent = false
|
|
68
|
+
let invalidContent = ''
|
|
69
|
+
|
|
70
|
+
// A copy of the current schema with a catch-all node at the end
|
|
71
|
+
const contentCheckSchema = new Schema({
|
|
68
72
|
topNode: schema.spec.topNode,
|
|
69
73
|
marks: schema.spec.marks,
|
|
70
74
|
// Prosemirror's schemas are executed such that: the last to execute, matches last
|
|
@@ -88,19 +92,27 @@ export function createNodeFromContent(
|
|
|
88
92
|
},
|
|
89
93
|
}),
|
|
90
94
|
})
|
|
91
|
-
}
|
|
92
95
|
|
|
93
|
-
|
|
96
|
+
if (options.slice) {
|
|
97
|
+
DOMParser.fromSchema(contentCheckSchema).parseSlice(elementFromString(content), options.parseOptions)
|
|
98
|
+
} else {
|
|
99
|
+
DOMParser.fromSchema(contentCheckSchema).parse(elementFromString(content), options.parseOptions)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (options.errorOnInvalidContent && hasInvalidContent) {
|
|
103
|
+
throw new Error('[tiptap error]: Invalid HTML content', {
|
|
104
|
+
cause: new Error(`Invalid element found: ${invalidContent}`),
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
}
|
|
94
108
|
|
|
95
|
-
const
|
|
96
|
-
? parser.parseSlice(elementFromString(content), options.parseOptions).content
|
|
97
|
-
: parser.parse(elementFromString(content), options.parseOptions)
|
|
109
|
+
const parser = DOMParser.fromSchema(schema)
|
|
98
110
|
|
|
99
|
-
if (options.
|
|
100
|
-
|
|
111
|
+
if (options.slice) {
|
|
112
|
+
return parser.parseSlice(elementFromString(content), options.parseOptions).content
|
|
101
113
|
}
|
|
102
114
|
|
|
103
|
-
return
|
|
115
|
+
return parser.parse(elementFromString(content), options.parseOptions)
|
|
104
116
|
}
|
|
105
117
|
|
|
106
118
|
return createNodeFromContent('', schema, options)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
1
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { NodeWithPos, Predicate } from '../types.js'
|
|
3
|
+
import type { NodeWithPos, Predicate } from '../types.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Find children inside a Prosemirror node that match a predicate.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
1
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { NodeWithPos, Predicate, Range } from '../types.js'
|
|
3
|
+
import type { NodeWithPos, Predicate, Range } from '../types.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Same as `findChildren` but searches only within a `range`.
|
|
@@ -9,11 +9,7 @@ import { NodeWithPos, Predicate, Range } from '../types.js'
|
|
|
9
9
|
* @param predicate The predicate to match
|
|
10
10
|
* @returns An array of nodes with their positions
|
|
11
11
|
*/
|
|
12
|
-
export function findChildrenInRange(
|
|
13
|
-
node: ProseMirrorNode,
|
|
14
|
-
range: Range,
|
|
15
|
-
predicate: Predicate,
|
|
16
|
-
): NodeWithPos[] {
|
|
12
|
+
export function findChildrenInRange(node: ProseMirrorNode, range: Range, predicate: Predicate): NodeWithPos[] {
|
|
17
13
|
const nodesWithPos: NodeWithPos[] = []
|
|
18
14
|
|
|
19
15
|
// if (range.from === range.to) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Selection } from '@tiptap/pm/state'
|
|
1
|
+
import type { Selection } from '@tiptap/pm/state'
|
|
2
2
|
|
|
3
|
-
import { Predicate } from '../types.js'
|
|
3
|
+
import type { Predicate } from '../types.js'
|
|
4
4
|
import { findParentNodeClosestToPos } from './findParentNodeClosestToPos.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -11,6 +11,8 @@ import { findParentNodeClosestToPos } from './findParentNodeClosestToPos.js'
|
|
|
11
11
|
* findParentNode(node => node.type.name === 'paragraph')
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
export function findParentNode(
|
|
14
|
+
export function findParentNode(
|
|
15
|
+
predicate: Predicate,
|
|
16
|
+
): (selection: Selection) => ReturnType<typeof findParentNodeClosestToPos> {
|
|
15
17
|
return (selection: Selection) => findParentNodeClosestToPos(selection.$from, predicate)
|
|
16
18
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode, ResolvedPos } from '@tiptap/pm/model'
|
|
1
|
+
import type { Node as ProseMirrorNode, ResolvedPos } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { Predicate } from '../types.js'
|
|
3
|
+
import type { Predicate } from '../types.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Finds the closest parent node to a resolved position that matches a predicate.
|