@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
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { Schema } from '@tiptap/pm/model'
|
|
2
|
+
|
|
3
|
+
import type { JSONContent } from '../types.js'
|
|
4
|
+
|
|
5
|
+
type RewriteUnknownContentOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* If true, unknown nodes will be treated as paragraphs
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
fallbackToParagraph?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type RewrittenContent = {
|
|
14
|
+
/**
|
|
15
|
+
* The original JSON content that was rewritten
|
|
16
|
+
*/
|
|
17
|
+
original: JSONContent
|
|
18
|
+
/**
|
|
19
|
+
* The name of the node or mark that was unsupported
|
|
20
|
+
*/
|
|
21
|
+
unsupported: string
|
|
22
|
+
}[]
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The actual implementation of the rewriteUnknownContent function
|
|
26
|
+
*/
|
|
27
|
+
function rewriteUnknownContentInner({
|
|
28
|
+
json,
|
|
29
|
+
validMarks,
|
|
30
|
+
validNodes,
|
|
31
|
+
options,
|
|
32
|
+
rewrittenContent = [],
|
|
33
|
+
}: {
|
|
34
|
+
json: JSONContent
|
|
35
|
+
validMarks: Set<string>
|
|
36
|
+
validNodes: Set<string>
|
|
37
|
+
options?: RewriteUnknownContentOptions
|
|
38
|
+
rewrittenContent?: RewrittenContent
|
|
39
|
+
}): {
|
|
40
|
+
/**
|
|
41
|
+
* The cleaned JSON content
|
|
42
|
+
*/
|
|
43
|
+
json: JSONContent | null
|
|
44
|
+
/**
|
|
45
|
+
* The array of nodes and marks that were rewritten
|
|
46
|
+
*/
|
|
47
|
+
rewrittenContent: RewrittenContent
|
|
48
|
+
} {
|
|
49
|
+
if (json.marks && Array.isArray(json.marks)) {
|
|
50
|
+
json.marks = json.marks.filter(mark => {
|
|
51
|
+
const name = typeof mark === 'string' ? mark : mark.type
|
|
52
|
+
|
|
53
|
+
if (validMarks.has(name)) {
|
|
54
|
+
return true
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
rewrittenContent.push({
|
|
58
|
+
original: JSON.parse(JSON.stringify(mark)),
|
|
59
|
+
unsupported: name,
|
|
60
|
+
})
|
|
61
|
+
// Just ignore any unknown marks
|
|
62
|
+
return false
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (json.content && Array.isArray(json.content)) {
|
|
67
|
+
json.content = json.content
|
|
68
|
+
.map(
|
|
69
|
+
value =>
|
|
70
|
+
rewriteUnknownContentInner({
|
|
71
|
+
json: value,
|
|
72
|
+
validMarks,
|
|
73
|
+
validNodes,
|
|
74
|
+
options,
|
|
75
|
+
rewrittenContent,
|
|
76
|
+
}).json,
|
|
77
|
+
)
|
|
78
|
+
.filter(a => a !== null && a !== undefined)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (json.type && !validNodes.has(json.type)) {
|
|
82
|
+
rewrittenContent.push({
|
|
83
|
+
original: JSON.parse(JSON.stringify(json)),
|
|
84
|
+
unsupported: json.type,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
if (json.content && Array.isArray(json.content) && options?.fallbackToParagraph !== false) {
|
|
88
|
+
// Just treat it like a paragraph and hope for the best
|
|
89
|
+
json.type = 'paragraph'
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
json,
|
|
93
|
+
rewrittenContent,
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// or just omit it entirely
|
|
98
|
+
return {
|
|
99
|
+
json: null,
|
|
100
|
+
rewrittenContent,
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return { json, rewrittenContent }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Rewrite unknown nodes and marks within JSON content
|
|
109
|
+
* Allowing for user within the editor
|
|
110
|
+
*/
|
|
111
|
+
export function rewriteUnknownContent(
|
|
112
|
+
/**
|
|
113
|
+
* The JSON content to clean of unknown nodes and marks
|
|
114
|
+
*/
|
|
115
|
+
json: JSONContent,
|
|
116
|
+
/**
|
|
117
|
+
* The schema to use for validation
|
|
118
|
+
*/
|
|
119
|
+
schema: Schema,
|
|
120
|
+
/**
|
|
121
|
+
* Options for the cleaning process
|
|
122
|
+
*/
|
|
123
|
+
options?: RewriteUnknownContentOptions,
|
|
124
|
+
): {
|
|
125
|
+
/**
|
|
126
|
+
* The cleaned JSON content
|
|
127
|
+
*/
|
|
128
|
+
json: JSONContent | null
|
|
129
|
+
/**
|
|
130
|
+
* The array of nodes and marks that were rewritten
|
|
131
|
+
*/
|
|
132
|
+
rewrittenContent: {
|
|
133
|
+
/**
|
|
134
|
+
* The original JSON content that was rewritten
|
|
135
|
+
*/
|
|
136
|
+
original: JSONContent
|
|
137
|
+
/**
|
|
138
|
+
* The name of the node or mark that was unsupported
|
|
139
|
+
*/
|
|
140
|
+
unsupported: string
|
|
141
|
+
}[]
|
|
142
|
+
} {
|
|
143
|
+
return rewriteUnknownContentInner({
|
|
144
|
+
json,
|
|
145
|
+
validNodes: new Set(Object.keys(schema.nodes)),
|
|
146
|
+
validMarks: new Set(Object.keys(schema.marks)),
|
|
147
|
+
options,
|
|
148
|
+
})
|
|
149
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Transaction } from '@tiptap/pm/state'
|
|
2
|
+
import { Selection } from '@tiptap/pm/state'
|
|
2
3
|
import { ReplaceAroundStep, ReplaceStep } from '@tiptap/pm/transform'
|
|
3
4
|
|
|
4
5
|
// source: https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.js#L466
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AnyConfig, Extensions } from '../types.js'
|
|
2
|
+
import { getExtensionField } from './getExtensionField.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sort extensions by priority.
|
|
6
|
+
* @param extensions An array of Tiptap extensions
|
|
7
|
+
* @returns A sorted array of Tiptap extensions by priority
|
|
8
|
+
*/
|
|
9
|
+
export function sortExtensions(extensions: Extensions): Extensions {
|
|
10
|
+
const defaultPriority = 100
|
|
11
|
+
|
|
12
|
+
return extensions.sort((a, b) => {
|
|
13
|
+
const priorityA = getExtensionField<AnyConfig['priority']>(a, 'priority') || defaultPriority
|
|
14
|
+
const priorityB = getExtensionField<AnyConfig['priority']>(b, 'priority') || defaultPriority
|
|
15
|
+
|
|
16
|
+
if (priorityA > priorityB) {
|
|
17
|
+
return -1
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (priorityA < priorityB) {
|
|
21
|
+
return 1
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return 0
|
|
25
|
+
})
|
|
26
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Extension } from '../Extension.js'
|
|
2
|
-
import { Mark } from '../Mark.js'
|
|
3
|
-
import { Node } from '../Node.js'
|
|
4
|
-
import { Extensions } from '../types.js'
|
|
1
|
+
import type { Extension } from '../Extension.js'
|
|
2
|
+
import type { Mark } from '../Mark.js'
|
|
3
|
+
import type { Node } from '../Node.js'
|
|
4
|
+
import type { Extensions } from '../types.js'
|
|
5
5
|
|
|
6
6
|
export function splitExtensions(extensions: Extensions) {
|
|
7
7
|
const baseExtensions = extensions.filter(extension => extension.type === 'extension') as Extension[]
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,9 @@ export * as extensions from './extensions/index.js'
|
|
|
5
5
|
export * from './helpers/index.js'
|
|
6
6
|
export * from './InputRule.js'
|
|
7
7
|
export * from './inputRules/index.js'
|
|
8
|
+
export { createElement, Fragment, createElement as h } from './jsx-runtime.js'
|
|
8
9
|
export * from './Mark.js'
|
|
10
|
+
export * from './MarkView.js'
|
|
9
11
|
export * from './Node.js'
|
|
10
12
|
export * from './NodePos.js'
|
|
11
13
|
export * from './NodeView.js'
|
|
@@ -19,10 +21,4 @@ export * from './utilities/index.js'
|
|
|
19
21
|
export interface Commands<ReturnType = any> {}
|
|
20
22
|
|
|
21
23
|
// eslint-disable-next-line
|
|
22
|
-
export interface
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line
|
|
25
|
-
export interface NodeConfig<Options = any, Storage = any> {}
|
|
26
|
-
|
|
27
|
-
// eslint-disable-next-line
|
|
28
|
-
export interface MarkConfig<Options = any, Storage = any> {}
|
|
24
|
+
export interface Storage {}
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import { MarkType } from '@tiptap/pm/model'
|
|
1
|
+
import type { MarkType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { getMarksBetween } from '../helpers/getMarksBetween.js'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import type { InputRuleFinder } from '../InputRule.js'
|
|
5
|
+
import { InputRule } from '../InputRule.js'
|
|
6
|
+
import type { ExtendedRegExpMatchArray } from '../types.js'
|
|
6
7
|
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Build an input rule that adds a mark when the
|
|
10
11
|
* matched text is typed into it.
|
|
11
|
-
* @see https://tiptap.dev/
|
|
12
|
+
* @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules
|
|
12
13
|
*/
|
|
13
14
|
export function markInputRule(config: {
|
|
14
15
|
find: InputRuleFinder
|
|
15
16
|
type: MarkType
|
|
16
|
-
getAttributes?:
|
|
17
|
-
| Record<string, any>
|
|
18
|
-
| ((match: ExtendedRegExpMatchArray) => Record<string, any>)
|
|
19
|
-
| false
|
|
20
|
-
| null
|
|
17
|
+
getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null
|
|
21
18
|
}) {
|
|
22
19
|
return new InputRule({
|
|
23
20
|
find: config.find,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { NodeType } from '@tiptap/pm/model'
|
|
1
|
+
import type { NodeType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { InputRuleFinder } from '../InputRule.js'
|
|
4
|
+
import { InputRule } from '../InputRule.js'
|
|
5
|
+
import type { ExtendedRegExpMatchArray } from '../types.js'
|
|
5
6
|
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Build an input rule that adds a node when the
|
|
9
10
|
* matched text is typed into it.
|
|
10
|
-
* @see https://tiptap.dev/
|
|
11
|
+
* @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules
|
|
11
12
|
*/
|
|
12
13
|
export function nodeInputRule(config: {
|
|
13
14
|
/**
|
|
@@ -24,11 +25,7 @@ export function nodeInputRule(config: {
|
|
|
24
25
|
* A function that returns the attributes for the node
|
|
25
26
|
* can also be an object of attributes
|
|
26
27
|
*/
|
|
27
|
-
getAttributes?:
|
|
28
|
-
| Record<string, any>
|
|
29
|
-
| ((match: ExtendedRegExpMatchArray) => Record<string, any>)
|
|
30
|
-
| false
|
|
31
|
-
| null
|
|
28
|
+
getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null
|
|
32
29
|
}) {
|
|
33
30
|
return new InputRule({
|
|
34
31
|
find: config.find,
|
|
@@ -60,10 +57,7 @@ export function nodeInputRule(config: {
|
|
|
60
57
|
} else if (match[0]) {
|
|
61
58
|
const insertionStart = config.type.isInline ? start : start - 1
|
|
62
59
|
|
|
63
|
-
tr.insert(insertionStart, config.type.create(attributes)).delete(
|
|
64
|
-
tr.mapping.map(start),
|
|
65
|
-
tr.mapping.map(end),
|
|
66
|
-
)
|
|
60
|
+
tr.insert(insertionStart, config.type.create(attributes)).delete(tr.mapping.map(start), tr.mapping.map(end))
|
|
67
61
|
}
|
|
68
62
|
|
|
69
63
|
tr.scrollIntoView()
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { InputRuleFinder } from '../InputRule.js'
|
|
2
|
+
import { InputRule } from '../InputRule.js'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Build an input rule that replaces text when the
|
|
5
6
|
* matched text is typed into it.
|
|
6
|
-
* @see https://tiptap.dev/
|
|
7
|
+
* @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules
|
|
7
8
|
*/
|
|
8
|
-
export function textInputRule(config: {
|
|
9
|
-
find: InputRuleFinder,
|
|
10
|
-
replace: string,
|
|
11
|
-
}) {
|
|
9
|
+
export function textInputRule(config: { find: InputRuleFinder; replace: string }) {
|
|
12
10
|
return new InputRule({
|
|
13
11
|
find: config.find,
|
|
14
12
|
handler: ({ state, range, match }) => {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { NodeType } from '@tiptap/pm/model'
|
|
1
|
+
import type { NodeType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { InputRuleFinder } from '../InputRule.js'
|
|
4
|
+
import { InputRule } from '../InputRule.js'
|
|
5
|
+
import type { ExtendedRegExpMatchArray } from '../types.js'
|
|
5
6
|
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -9,16 +10,12 @@ import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
|
9
10
|
* matched text is typed into it. When using a regular expresion you’ll
|
|
10
11
|
* probably want the regexp to start with `^`, so that the pattern can
|
|
11
12
|
* only occur at the start of a textblock.
|
|
12
|
-
* @see https://tiptap.dev/
|
|
13
|
+
* @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules
|
|
13
14
|
*/
|
|
14
15
|
export function textblockTypeInputRule(config: {
|
|
15
16
|
find: InputRuleFinder
|
|
16
17
|
type: NodeType
|
|
17
|
-
getAttributes?:
|
|
18
|
-
| Record<string, any>
|
|
19
|
-
| ((match: ExtendedRegExpMatchArray) => Record<string, any>)
|
|
20
|
-
| false
|
|
21
|
-
| null
|
|
18
|
+
getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null
|
|
22
19
|
}) {
|
|
23
20
|
return new InputRule({
|
|
24
21
|
find: config.find,
|
|
@@ -30,9 +27,7 @@ export function textblockTypeInputRule(config: {
|
|
|
30
27
|
return null
|
|
31
28
|
}
|
|
32
29
|
|
|
33
|
-
state.tr
|
|
34
|
-
.delete(range.from, range.to)
|
|
35
|
-
.setBlockType(range.from, range.from, config.type, attributes)
|
|
30
|
+
state.tr.delete(range.from, range.to).setBlockType(range.from, range.from, config.type, attributes)
|
|
36
31
|
},
|
|
37
32
|
})
|
|
38
33
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode, NodeType } from '@tiptap/pm/model'
|
|
1
|
+
import type { Node as ProseMirrorNode, NodeType } from '@tiptap/pm/model'
|
|
2
2
|
import { canJoin, findWrapping } from '@tiptap/pm/transform'
|
|
3
3
|
|
|
4
|
-
import { Editor } from '../Editor.js'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import type { Editor } from '../Editor.js'
|
|
5
|
+
import type { InputRuleFinder } from '../InputRule.js'
|
|
6
|
+
import { InputRule } from '../InputRule.js'
|
|
7
|
+
import type { ExtendedRegExpMatchArray } from '../types.js'
|
|
7
8
|
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -19,27 +20,20 @@ import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
|
19
20
|
* two nodes. You can pass a join predicate, which takes a regular
|
|
20
21
|
* expression match and the node before the wrapped node, and can
|
|
21
22
|
* return a boolean to indicate whether a join should happen.
|
|
22
|
-
* @see https://tiptap.dev/
|
|
23
|
+
* @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules
|
|
23
24
|
*/
|
|
24
25
|
export function wrappingInputRule(config: {
|
|
25
|
-
find: InputRuleFinder
|
|
26
|
-
type: NodeType
|
|
27
|
-
keepMarks?: boolean
|
|
28
|
-
keepAttributes?: boolean
|
|
26
|
+
find: InputRuleFinder
|
|
27
|
+
type: NodeType
|
|
28
|
+
keepMarks?: boolean
|
|
29
|
+
keepAttributes?: boolean
|
|
29
30
|
editor?: Editor
|
|
30
|
-
getAttributes?:
|
|
31
|
-
|
|
32
|
-
| ((match: ExtendedRegExpMatchArray) => Record<string, any>)
|
|
33
|
-
| false
|
|
34
|
-
| null
|
|
35
|
-
,
|
|
36
|
-
joinPredicate?: (match: ExtendedRegExpMatchArray, node: ProseMirrorNode) => boolean,
|
|
31
|
+
getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null
|
|
32
|
+
joinPredicate?: (match: ExtendedRegExpMatchArray, node: ProseMirrorNode) => boolean
|
|
37
33
|
}) {
|
|
38
34
|
return new InputRule({
|
|
39
35
|
find: config.find,
|
|
40
|
-
handler: ({
|
|
41
|
-
state, range, match, chain,
|
|
42
|
-
}) => {
|
|
36
|
+
handler: ({ state, range, match, chain }) => {
|
|
43
37
|
const attributes = callOrReturn(config.getAttributes, undefined, match) || {}
|
|
44
38
|
const tr = state.tr.delete(range.from, range.to)
|
|
45
39
|
const $start = tr.doc.resolve(range.from)
|
|
@@ -65,7 +59,8 @@ export function wrappingInputRule(config: {
|
|
|
65
59
|
}
|
|
66
60
|
if (config.keepAttributes) {
|
|
67
61
|
/** If the nodeType is `bulletList` or `orderedList` set the `nodeType` as `listItem` */
|
|
68
|
-
const nodeType =
|
|
62
|
+
const nodeType =
|
|
63
|
+
config.type.name === 'bulletList' || config.type.name === 'orderedList' ? 'listItem' : 'taskList'
|
|
69
64
|
|
|
70
65
|
chain().updateAttributes(nodeType, attributes).run()
|
|
71
66
|
}
|
|
@@ -73,10 +68,10 @@ export function wrappingInputRule(config: {
|
|
|
73
68
|
const before = tr.doc.resolve(range.from - 1).nodeBefore
|
|
74
69
|
|
|
75
70
|
if (
|
|
76
|
-
before
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
before &&
|
|
72
|
+
before.type === config.type &&
|
|
73
|
+
canJoin(tr.doc, range.from - 1) &&
|
|
74
|
+
(!config.joinPredicate || config.joinPredicate(match, before))
|
|
80
75
|
) {
|
|
81
76
|
tr.join(range.from - 1)
|
|
82
77
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export type Attributes = Record<string, any>
|
|
2
|
+
|
|
3
|
+
export type DOMOutputSpecElement = 0 | Attributes | DOMOutputSpecArray
|
|
4
|
+
/**
|
|
5
|
+
* Better describes the output of a `renderHTML` function in prosemirror
|
|
6
|
+
* @see https://prosemirror.net/docs/ref/#model.DOMOutputSpec
|
|
7
|
+
*/
|
|
8
|
+
export type DOMOutputSpecArray =
|
|
9
|
+
| [string]
|
|
10
|
+
| [string, Attributes]
|
|
11
|
+
| [string, 0]
|
|
12
|
+
| [string, Attributes, 0]
|
|
13
|
+
| [string, Attributes, DOMOutputSpecArray | 0]
|
|
14
|
+
| [string, DOMOutputSpecArray]
|
|
15
|
+
|
|
16
|
+
declare global {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
18
|
+
namespace JSX {
|
|
19
|
+
// @ts-ignore - conflict with React typings
|
|
20
|
+
type Element = [string, ...any[]]
|
|
21
|
+
// @ts-ignore - conflict with React typings
|
|
22
|
+
interface IntrinsicElements {
|
|
23
|
+
// @ts-ignore - conflict with React typings
|
|
24
|
+
[key: string]: any
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type JSXRenderer = (
|
|
30
|
+
tag: 'slot' | string | ((props?: Attributes) => DOMOutputSpecArray | DOMOutputSpecElement),
|
|
31
|
+
props?: Attributes,
|
|
32
|
+
...children: JSXRenderer[]
|
|
33
|
+
) => DOMOutputSpecArray | DOMOutputSpecElement
|
|
34
|
+
|
|
35
|
+
export function Fragment(props: { children: JSXRenderer[] }) {
|
|
36
|
+
return props.children
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const h: JSXRenderer = (tag, attributes) => {
|
|
40
|
+
// Treat the slot tag as the Prosemirror hole to render content into
|
|
41
|
+
if (tag === 'slot') {
|
|
42
|
+
return 0
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// If the tag is a function, call it with the props
|
|
46
|
+
if (tag instanceof Function) {
|
|
47
|
+
return tag(attributes)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const { children, ...rest } = attributes ?? {}
|
|
51
|
+
|
|
52
|
+
if (tag === 'svg') {
|
|
53
|
+
throw new Error('SVG elements are not supported in the JSX syntax, use the array syntax instead')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Otherwise, return the tag, attributes, and children
|
|
57
|
+
return [tag, rest, children]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// See
|
|
61
|
+
// https://esbuild.github.io/api/#jsx-import-source
|
|
62
|
+
// https://www.typescriptlang.org/tsconfig/#jsxImportSource
|
|
63
|
+
|
|
64
|
+
export { h as createElement, h as jsx, h as jsxDEV, h as jsxs }
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { MarkType } from '@tiptap/pm/model'
|
|
1
|
+
import type { MarkType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { getMarksBetween } from '../helpers/getMarksBetween.js'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import type { PasteRuleFinder } from '../PasteRule.js'
|
|
5
|
+
import { PasteRule } from '../PasteRule.js'
|
|
6
|
+
import type { ExtendedRegExpMatchArray } from '../types.js'
|
|
6
7
|
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Build an paste rule that adds a mark when the
|
|
10
11
|
* matched text is pasted into it.
|
|
11
|
-
* @see https://tiptap.dev/
|
|
12
|
+
* @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#paste-rules
|
|
12
13
|
*/
|
|
13
14
|
export function markPasteRule(config: {
|
|
14
15
|
find: PasteRuleFinder
|
|
@@ -21,9 +22,7 @@ export function markPasteRule(config: {
|
|
|
21
22
|
}) {
|
|
22
23
|
return new PasteRule({
|
|
23
24
|
find: config.find,
|
|
24
|
-
handler: ({
|
|
25
|
-
state, range, match, pasteEvent,
|
|
26
|
-
}) => {
|
|
25
|
+
handler: ({ state, range, match, pasteEvent }) => {
|
|
27
26
|
const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)
|
|
28
27
|
|
|
29
28
|
if (attributes === false || attributes === null) {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { NodeType } from '@tiptap/pm/model'
|
|
1
|
+
import type { NodeType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { PasteRuleFinder } from '../PasteRule.js'
|
|
4
|
+
import { PasteRule } from '../PasteRule.js'
|
|
5
|
+
import type { ExtendedRegExpMatchArray, JSONContent } from '../types.js'
|
|
5
6
|
import { callOrReturn } from '../utilities/index.js'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Build an paste rule that adds a node when the
|
|
9
10
|
* matched text is pasted into it.
|
|
10
|
-
* @see https://tiptap.dev/
|
|
11
|
+
* @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#paste-rules
|
|
11
12
|
*/
|
|
12
13
|
export function nodePasteRule(config: {
|
|
13
14
|
find: PasteRuleFinder
|
|
@@ -17,23 +18,26 @@ export function nodePasteRule(config: {
|
|
|
17
18
|
| ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>)
|
|
18
19
|
| false
|
|
19
20
|
| null
|
|
21
|
+
getContent?: JSONContent[] | ((attrs: Record<string, any>) => JSONContent[]) | false | null
|
|
20
22
|
}) {
|
|
21
23
|
return new PasteRule({
|
|
22
24
|
find: config.find,
|
|
23
|
-
handler({
|
|
24
|
-
match, chain, range, pasteEvent,
|
|
25
|
-
}) {
|
|
25
|
+
handler({ match, chain, range, pasteEvent }) {
|
|
26
26
|
const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)
|
|
27
|
+
const content = callOrReturn(config.getContent, undefined, attributes)
|
|
27
28
|
|
|
28
29
|
if (attributes === false || attributes === null) {
|
|
29
30
|
return null
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
const node = { type: config.type.name, attrs: attributes } as JSONContent
|
|
34
|
+
|
|
35
|
+
if (content) {
|
|
36
|
+
node.content = content
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
if (match.input) {
|
|
33
|
-
chain().deleteRange(range).insertContentAt(range.from,
|
|
34
|
-
type: config.type.name,
|
|
35
|
-
attrs: attributes,
|
|
36
|
-
})
|
|
40
|
+
chain().deleteRange(range).insertContentAt(range.from, node)
|
|
37
41
|
}
|
|
38
42
|
},
|
|
39
43
|
})
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PasteRuleFinder } from '../PasteRule.js'
|
|
2
|
+
import { PasteRule } from '../PasteRule.js'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Build an paste rule that replaces text when the
|
|
5
6
|
* matched text is pasted into it.
|
|
6
|
-
* @see https://tiptap.dev/
|
|
7
|
+
* @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#paste-rules
|
|
7
8
|
*/
|
|
8
|
-
export function textPasteRule(config: {
|
|
9
|
-
find: PasteRuleFinder,
|
|
10
|
-
replace: string,
|
|
11
|
-
}) {
|
|
9
|
+
export function textPasteRule(config: { find: PasteRuleFinder; replace: string }) {
|
|
12
10
|
return new PasteRule({
|
|
13
11
|
find: config.find,
|
|
14
12
|
handler: ({ state, range, match }) => {
|
package/src/style.ts
CHANGED
|
@@ -27,8 +27,8 @@ img.ProseMirror-separator {
|
|
|
27
27
|
display: inline !important;
|
|
28
28
|
border: none !important;
|
|
29
29
|
margin: 0 !important;
|
|
30
|
-
width:
|
|
31
|
-
height:
|
|
30
|
+
width: 0 !important;
|
|
31
|
+
height: 0 !important;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
.ProseMirror-gapcursor {
|
|
@@ -68,8 +68,4 @@ img.ProseMirror-separator {
|
|
|
68
68
|
|
|
69
69
|
.ProseMirror-focused .ProseMirror-gapcursor {
|
|
70
70
|
display: block;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.tippy-box[data-animation=fade][data-state=hidden] {
|
|
74
|
-
opacity: 0
|
|
75
71
|
}`
|