@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,484 @@
|
|
|
1
|
+
import type { Plugin } from '@tiptap/pm/state'
|
|
2
|
+
|
|
3
|
+
import type { Editor } from './Editor.js'
|
|
4
|
+
import { getExtensionField } from './helpers/getExtensionField.js'
|
|
5
|
+
import type { ExtensionConfig, MarkConfig, NodeConfig } from './index.js'
|
|
6
|
+
import type { InputRule } from './InputRule.js'
|
|
7
|
+
import type { Mark } from './Mark.js'
|
|
8
|
+
import type { Node } from './Node.js'
|
|
9
|
+
import type { PasteRule } from './PasteRule.js'
|
|
10
|
+
import type {
|
|
11
|
+
AnyConfig,
|
|
12
|
+
EditorEvents,
|
|
13
|
+
Extensions,
|
|
14
|
+
GlobalAttributes,
|
|
15
|
+
KeyboardShortcutCommand,
|
|
16
|
+
ParentConfig,
|
|
17
|
+
RawCommands,
|
|
18
|
+
} from './types.js'
|
|
19
|
+
import { callOrReturn } from './utilities/callOrReturn.js'
|
|
20
|
+
import { mergeDeep } from './utilities/mergeDeep.js'
|
|
21
|
+
|
|
22
|
+
export interface ExtendableConfig<
|
|
23
|
+
Options = any,
|
|
24
|
+
Storage = any,
|
|
25
|
+
Config extends
|
|
26
|
+
| ExtensionConfig<Options, Storage>
|
|
27
|
+
| NodeConfig<Options, Storage>
|
|
28
|
+
| MarkConfig<Options, Storage>
|
|
29
|
+
| ExtendableConfig<Options, Storage> = ExtendableConfig<Options, Storage, any, any>,
|
|
30
|
+
PMType = any,
|
|
31
|
+
> {
|
|
32
|
+
/**
|
|
33
|
+
* The extension name - this must be unique.
|
|
34
|
+
* It will be used to identify the extension.
|
|
35
|
+
*
|
|
36
|
+
* @example 'myExtension'
|
|
37
|
+
*/
|
|
38
|
+
name: string
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The priority of your extension. The higher, the earlier it will be called
|
|
42
|
+
* and will take precedence over other extensions with a lower priority.
|
|
43
|
+
* @default 100
|
|
44
|
+
* @example 101
|
|
45
|
+
*/
|
|
46
|
+
priority?: number
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* This method will add options to this extension
|
|
50
|
+
* @see https://tiptap.dev/docs/editor/guide/custom-extensions#settings
|
|
51
|
+
* @example
|
|
52
|
+
* addOptions() {
|
|
53
|
+
* return {
|
|
54
|
+
* myOption: 'foo',
|
|
55
|
+
* myOtherOption: 10,
|
|
56
|
+
* }
|
|
57
|
+
*/
|
|
58
|
+
addOptions?: (this: { name: string; parent: ParentConfig<Config>['addOptions'] }) => Options
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The default storage this extension can save data to.
|
|
62
|
+
* @see https://tiptap.dev/docs/editor/guide/custom-extensions#storage
|
|
63
|
+
* @example
|
|
64
|
+
* defaultStorage: {
|
|
65
|
+
* prefetchedUsers: [],
|
|
66
|
+
* loading: false,
|
|
67
|
+
* }
|
|
68
|
+
*/
|
|
69
|
+
addStorage?: (this: { name: string; options: Options; parent: ParentConfig<Config>['addStorage'] }) => Storage
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* This function adds globalAttributes to specific nodes.
|
|
73
|
+
* @see https://tiptap.dev/docs/editor/guide/custom-extensions#global-attributes
|
|
74
|
+
* @example
|
|
75
|
+
* addGlobalAttributes() {
|
|
76
|
+
* return [
|
|
77
|
+
* {
|
|
78
|
+
// Extend the following extensions
|
|
79
|
+
* types: [
|
|
80
|
+
* 'heading',
|
|
81
|
+
* 'paragraph',
|
|
82
|
+
* ],
|
|
83
|
+
* // … with those attributes
|
|
84
|
+
* attributes: {
|
|
85
|
+
* textAlign: {
|
|
86
|
+
* default: 'left',
|
|
87
|
+
* renderHTML: attributes => ({
|
|
88
|
+
* style: `text-align: ${attributes.textAlign}`,
|
|
89
|
+
* }),
|
|
90
|
+
* parseHTML: element => element.style.textAlign || 'left',
|
|
91
|
+
* },
|
|
92
|
+
* },
|
|
93
|
+
* },
|
|
94
|
+
* ]
|
|
95
|
+
* }
|
|
96
|
+
*/
|
|
97
|
+
addGlobalAttributes?: (this: {
|
|
98
|
+
name: string
|
|
99
|
+
options: Options
|
|
100
|
+
storage: Storage
|
|
101
|
+
extensions: (Node | Mark)[]
|
|
102
|
+
parent: ParentConfig<Config>['addGlobalAttributes']
|
|
103
|
+
}) => GlobalAttributes
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* This function adds commands to the editor
|
|
107
|
+
* @see https://tiptap.dev/docs/editor/guide/custom-extensions#commands
|
|
108
|
+
* @example
|
|
109
|
+
* addCommands() {
|
|
110
|
+
* return {
|
|
111
|
+
* myCommand: () => ({ chain }) => chain().setMark('type', 'foo').run(),
|
|
112
|
+
* }
|
|
113
|
+
* }
|
|
114
|
+
*/
|
|
115
|
+
addCommands?: (this: {
|
|
116
|
+
name: string
|
|
117
|
+
options: Options
|
|
118
|
+
storage: Storage
|
|
119
|
+
editor: Editor
|
|
120
|
+
type: PMType
|
|
121
|
+
parent: ParentConfig<Config>['addCommands']
|
|
122
|
+
}) => Partial<RawCommands>
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* This function registers keyboard shortcuts.
|
|
126
|
+
* @see https://tiptap.dev/docs/editor/guide/custom-extensions#keyboard-shortcuts
|
|
127
|
+
* @example
|
|
128
|
+
* addKeyboardShortcuts() {
|
|
129
|
+
* return {
|
|
130
|
+
* 'Mod-l': () => this.editor.commands.toggleBulletList(),
|
|
131
|
+
* }
|
|
132
|
+
* },
|
|
133
|
+
*/
|
|
134
|
+
addKeyboardShortcuts?: (this: {
|
|
135
|
+
name: string
|
|
136
|
+
options: Options
|
|
137
|
+
storage: Storage
|
|
138
|
+
editor: Editor
|
|
139
|
+
type: PMType
|
|
140
|
+
parent: ParentConfig<Config>['addKeyboardShortcuts']
|
|
141
|
+
}) => {
|
|
142
|
+
[key: string]: KeyboardShortcutCommand
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* This function adds input rules to the editor.
|
|
147
|
+
* @see https://tiptap.dev/docs/editor/guide/custom-extensions#input-rules
|
|
148
|
+
* @example
|
|
149
|
+
* addInputRules() {
|
|
150
|
+
* return [
|
|
151
|
+
* markInputRule({
|
|
152
|
+
* find: inputRegex,
|
|
153
|
+
* type: this.type,
|
|
154
|
+
* }),
|
|
155
|
+
* ]
|
|
156
|
+
* },
|
|
157
|
+
*/
|
|
158
|
+
addInputRules?: (this: {
|
|
159
|
+
name: string
|
|
160
|
+
options: Options
|
|
161
|
+
storage: Storage
|
|
162
|
+
editor: Editor
|
|
163
|
+
type: PMType
|
|
164
|
+
parent: ParentConfig<Config>['addInputRules']
|
|
165
|
+
}) => InputRule[]
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* This function adds paste rules to the editor.
|
|
169
|
+
* @see https://tiptap.dev/docs/editor/guide/custom-extensions#paste-rules
|
|
170
|
+
* @example
|
|
171
|
+
* addPasteRules() {
|
|
172
|
+
* return [
|
|
173
|
+
* markPasteRule({
|
|
174
|
+
* find: pasteRegex,
|
|
175
|
+
* type: this.type,
|
|
176
|
+
* }),
|
|
177
|
+
* ]
|
|
178
|
+
* },
|
|
179
|
+
*/
|
|
180
|
+
addPasteRules?: (this: {
|
|
181
|
+
name: string
|
|
182
|
+
options: Options
|
|
183
|
+
storage: Storage
|
|
184
|
+
editor: Editor
|
|
185
|
+
type: PMType
|
|
186
|
+
parent: ParentConfig<Config>['addPasteRules']
|
|
187
|
+
}) => PasteRule[]
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* This function adds Prosemirror plugins to the editor
|
|
191
|
+
* @see https://tiptap.dev/docs/editor/guide/custom-extensions#prosemirror-plugins
|
|
192
|
+
* @example
|
|
193
|
+
* addProseMirrorPlugins() {
|
|
194
|
+
* return [
|
|
195
|
+
* customPlugin(),
|
|
196
|
+
* ]
|
|
197
|
+
* }
|
|
198
|
+
*/
|
|
199
|
+
addProseMirrorPlugins?: (this: {
|
|
200
|
+
name: string
|
|
201
|
+
options: Options
|
|
202
|
+
storage: Storage
|
|
203
|
+
editor: Editor
|
|
204
|
+
type: PMType
|
|
205
|
+
parent: ParentConfig<Config>['addProseMirrorPlugins']
|
|
206
|
+
}) => Plugin[]
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* This function adds additional extensions to the editor. This is useful for
|
|
210
|
+
* building extension kits.
|
|
211
|
+
* @example
|
|
212
|
+
* addExtensions() {
|
|
213
|
+
* return [
|
|
214
|
+
* BulletList,
|
|
215
|
+
* OrderedList,
|
|
216
|
+
* ListItem
|
|
217
|
+
* ]
|
|
218
|
+
* }
|
|
219
|
+
*/
|
|
220
|
+
addExtensions?: (this: {
|
|
221
|
+
name: string
|
|
222
|
+
options: Options
|
|
223
|
+
storage: Storage
|
|
224
|
+
parent: ParentConfig<Config>['addExtensions']
|
|
225
|
+
}) => Extensions
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* This function extends the schema of the node.
|
|
229
|
+
* @example
|
|
230
|
+
* extendNodeSchema() {
|
|
231
|
+
* return {
|
|
232
|
+
* group: 'inline',
|
|
233
|
+
* selectable: false,
|
|
234
|
+
* }
|
|
235
|
+
* }
|
|
236
|
+
*/
|
|
237
|
+
extendNodeSchema?:
|
|
238
|
+
| ((
|
|
239
|
+
this: {
|
|
240
|
+
name: string
|
|
241
|
+
options: Options
|
|
242
|
+
storage: Storage
|
|
243
|
+
parent: ParentConfig<Config>['extendNodeSchema']
|
|
244
|
+
},
|
|
245
|
+
extension: Node,
|
|
246
|
+
) => Record<string, any>)
|
|
247
|
+
| null
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* This function extends the schema of the mark.
|
|
251
|
+
* @example
|
|
252
|
+
* extendMarkSchema() {
|
|
253
|
+
* return {
|
|
254
|
+
* group: 'inline',
|
|
255
|
+
* selectable: false,
|
|
256
|
+
* }
|
|
257
|
+
* }
|
|
258
|
+
*/
|
|
259
|
+
extendMarkSchema?:
|
|
260
|
+
| ((
|
|
261
|
+
this: {
|
|
262
|
+
name: string
|
|
263
|
+
options: Options
|
|
264
|
+
storage: Storage
|
|
265
|
+
parent: ParentConfig<Config>['extendMarkSchema']
|
|
266
|
+
},
|
|
267
|
+
extension: Mark,
|
|
268
|
+
) => Record<string, any>)
|
|
269
|
+
| null
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The editor is not ready yet.
|
|
273
|
+
*/
|
|
274
|
+
onBeforeCreate?:
|
|
275
|
+
| ((
|
|
276
|
+
this: {
|
|
277
|
+
name: string
|
|
278
|
+
options: Options
|
|
279
|
+
storage: Storage
|
|
280
|
+
editor: Editor
|
|
281
|
+
type: PMType
|
|
282
|
+
parent: ParentConfig<Config>['onBeforeCreate']
|
|
283
|
+
},
|
|
284
|
+
event: EditorEvents['beforeCreate'],
|
|
285
|
+
) => void)
|
|
286
|
+
| null
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* The editor is ready.
|
|
290
|
+
*/
|
|
291
|
+
onCreate?:
|
|
292
|
+
| ((
|
|
293
|
+
this: {
|
|
294
|
+
name: string
|
|
295
|
+
options: Options
|
|
296
|
+
storage: Storage
|
|
297
|
+
editor: Editor
|
|
298
|
+
type: PMType
|
|
299
|
+
parent: ParentConfig<Config>['onCreate']
|
|
300
|
+
},
|
|
301
|
+
event: EditorEvents['create'],
|
|
302
|
+
) => void)
|
|
303
|
+
| null
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The content has changed.
|
|
307
|
+
*/
|
|
308
|
+
onUpdate?:
|
|
309
|
+
| ((
|
|
310
|
+
this: {
|
|
311
|
+
name: string
|
|
312
|
+
options: Options
|
|
313
|
+
storage: Storage
|
|
314
|
+
editor: Editor
|
|
315
|
+
type: PMType
|
|
316
|
+
parent: ParentConfig<Config>['onUpdate']
|
|
317
|
+
},
|
|
318
|
+
event: EditorEvents['update'],
|
|
319
|
+
) => void)
|
|
320
|
+
| null
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* The selection has changed.
|
|
324
|
+
*/
|
|
325
|
+
onSelectionUpdate?:
|
|
326
|
+
| ((
|
|
327
|
+
this: {
|
|
328
|
+
name: string
|
|
329
|
+
options: Options
|
|
330
|
+
storage: Storage
|
|
331
|
+
editor: Editor
|
|
332
|
+
type: PMType
|
|
333
|
+
parent: ParentConfig<Config>['onSelectionUpdate']
|
|
334
|
+
},
|
|
335
|
+
event: EditorEvents['selectionUpdate'],
|
|
336
|
+
) => void)
|
|
337
|
+
| null
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* The editor state has changed.
|
|
341
|
+
*/
|
|
342
|
+
onTransaction?:
|
|
343
|
+
| ((
|
|
344
|
+
this: {
|
|
345
|
+
name: string
|
|
346
|
+
options: Options
|
|
347
|
+
storage: Storage
|
|
348
|
+
editor: Editor
|
|
349
|
+
type: PMType
|
|
350
|
+
parent: ParentConfig<Config>['onTransaction']
|
|
351
|
+
},
|
|
352
|
+
event: EditorEvents['transaction'],
|
|
353
|
+
) => void)
|
|
354
|
+
| null
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* The editor is focused.
|
|
358
|
+
*/
|
|
359
|
+
onFocus?:
|
|
360
|
+
| ((
|
|
361
|
+
this: {
|
|
362
|
+
name: string
|
|
363
|
+
options: Options
|
|
364
|
+
storage: Storage
|
|
365
|
+
editor: Editor
|
|
366
|
+
type: PMType
|
|
367
|
+
parent: ParentConfig<Config>['onFocus']
|
|
368
|
+
},
|
|
369
|
+
event: EditorEvents['focus'],
|
|
370
|
+
) => void)
|
|
371
|
+
| null
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* The editor isn’t focused anymore.
|
|
375
|
+
*/
|
|
376
|
+
onBlur?:
|
|
377
|
+
| ((
|
|
378
|
+
this: {
|
|
379
|
+
name: string
|
|
380
|
+
options: Options
|
|
381
|
+
storage: Storage
|
|
382
|
+
editor: Editor
|
|
383
|
+
type: PMType
|
|
384
|
+
parent: ParentConfig<Config>['onBlur']
|
|
385
|
+
},
|
|
386
|
+
event: EditorEvents['blur'],
|
|
387
|
+
) => void)
|
|
388
|
+
| null
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* The editor is destroyed.
|
|
392
|
+
*/
|
|
393
|
+
onDestroy?:
|
|
394
|
+
| ((
|
|
395
|
+
this: {
|
|
396
|
+
name: string
|
|
397
|
+
options: Options
|
|
398
|
+
storage: Storage
|
|
399
|
+
editor: Editor
|
|
400
|
+
type: PMType
|
|
401
|
+
parent: ParentConfig<Config>['onDestroy']
|
|
402
|
+
},
|
|
403
|
+
event: EditorEvents['destroy'],
|
|
404
|
+
) => void)
|
|
405
|
+
| null
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export class Extendable<
|
|
409
|
+
Options = any,
|
|
410
|
+
Storage = any,
|
|
411
|
+
Config = ExtensionConfig<Options, Storage> | NodeConfig<Options, Storage> | MarkConfig<Options, Storage>,
|
|
412
|
+
> {
|
|
413
|
+
type = 'extendable'
|
|
414
|
+
parent: Extendable | null = null
|
|
415
|
+
|
|
416
|
+
child: Extendable | null = null
|
|
417
|
+
|
|
418
|
+
name = ''
|
|
419
|
+
|
|
420
|
+
config: Config = {
|
|
421
|
+
name: this.name,
|
|
422
|
+
} as Config
|
|
423
|
+
|
|
424
|
+
constructor(config: Partial<Config> = {}) {
|
|
425
|
+
this.config = {
|
|
426
|
+
...this.config,
|
|
427
|
+
...config,
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
this.name = (this.config as any).name
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
get options(): Options {
|
|
434
|
+
return {
|
|
435
|
+
...(callOrReturn(
|
|
436
|
+
getExtensionField<AnyConfig['addOptions']>(this as any, 'addOptions', {
|
|
437
|
+
name: this.name,
|
|
438
|
+
}),
|
|
439
|
+
) || {}),
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
get storage(): Readonly<Storage> {
|
|
444
|
+
return {
|
|
445
|
+
...(callOrReturn(
|
|
446
|
+
getExtensionField<AnyConfig['addStorage']>(this as any, 'addStorage', {
|
|
447
|
+
name: this.name,
|
|
448
|
+
options: this.options,
|
|
449
|
+
}),
|
|
450
|
+
) || {}),
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
configure(options: Partial<Options> = {}) {
|
|
455
|
+
const extension = this.extend<Options, Storage, Config>({
|
|
456
|
+
...this.config,
|
|
457
|
+
addOptions: () => {
|
|
458
|
+
return mergeDeep(this.options as Record<string, any>, options) as Options
|
|
459
|
+
},
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
extension.name = this.name
|
|
463
|
+
extension.parent = this.parent
|
|
464
|
+
|
|
465
|
+
return extension
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
extend<
|
|
469
|
+
ExtendedOptions = Options,
|
|
470
|
+
ExtendedStorage = Storage,
|
|
471
|
+
ExtendedConfig =
|
|
472
|
+
| ExtensionConfig<ExtendedOptions, ExtendedStorage>
|
|
473
|
+
| NodeConfig<ExtendedOptions, ExtendedStorage>
|
|
474
|
+
| MarkConfig<ExtendedOptions, ExtendedStorage>,
|
|
475
|
+
>(extendedConfig: Partial<ExtendedConfig> = {}): Extendable<ExtendedOptions, ExtendedStorage> {
|
|
476
|
+
const extension = new (this.constructor as any)({ ...this.config, ...extendedConfig })
|
|
477
|
+
|
|
478
|
+
extension.parent = this
|
|
479
|
+
this.child = extension
|
|
480
|
+
extension.name = 'name' in extendedConfig ? extendedConfig.name : extension.parent.name
|
|
481
|
+
|
|
482
|
+
return extension
|
|
483
|
+
}
|
|
484
|
+
}
|