@tiptap/core 2.0.0-beta.17 → 2.0.0-beta.170
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 +1 -1
- package/README.md +2 -2
- package/dist/packages/core/src/CommandManager.d.ts +13 -6
- package/dist/packages/core/src/Editor.d.ts +23 -18
- package/dist/packages/core/src/EventEmitter.d.ts +8 -4
- package/dist/packages/core/src/Extension.d.ts +102 -26
- package/dist/packages/core/src/ExtensionManager.d.ts +7 -12
- package/dist/packages/core/src/InputRule.d.ts +42 -0
- package/dist/packages/core/src/Mark.d.ts +134 -30
- package/dist/packages/core/src/Node.d.ts +160 -32
- package/dist/packages/core/src/NodeView.d.ts +5 -9
- package/dist/packages/core/src/PasteRule.d.ts +42 -0
- package/dist/packages/core/src/Tracker.d.ts +11 -0
- package/dist/packages/core/src/commands/blur.d.ts +3 -3
- package/dist/packages/core/src/commands/clearContent.d.ts +3 -3
- package/dist/packages/core/src/commands/clearNodes.d.ts +3 -3
- package/dist/packages/core/src/commands/command.d.ts +2 -2
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +3 -3
- package/dist/packages/core/src/commands/deleteNode.d.ts +13 -0
- package/dist/packages/core/src/commands/deleteRange.d.ts +3 -3
- package/dist/packages/core/src/commands/deleteSelection.d.ts +3 -3
- package/dist/packages/core/src/commands/enter.d.ts +3 -3
- package/dist/packages/core/src/commands/exitCode.d.ts +3 -3
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +3 -3
- package/dist/packages/core/src/commands/first.d.ts +3 -3
- package/dist/packages/core/src/commands/focus.d.ts +5 -3
- package/dist/packages/core/src/commands/forEach.d.ts +14 -0
- package/dist/packages/core/src/commands/insertContent.d.ts +7 -3
- package/dist/packages/core/src/commands/insertContentAt.d.ts +16 -0
- package/dist/packages/core/src/commands/joinBackward.d.ts +3 -3
- package/dist/packages/core/src/commands/joinForward.d.ts +3 -3
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +3 -3
- package/dist/packages/core/src/commands/lift.d.ts +3 -3
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +3 -3
- package/dist/packages/core/src/commands/liftListItem.d.ts +3 -3
- package/dist/packages/core/src/commands/newlineInCode.d.ts +3 -3
- package/dist/packages/core/src/commands/resetAttributes.d.ts +13 -0
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +3 -3
- package/dist/packages/core/src/commands/selectAll.d.ts +3 -3
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +3 -3
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +3 -3
- package/dist/packages/core/src/commands/selectParentNode.d.ts +3 -3
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +12 -0
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +12 -0
- package/dist/packages/core/src/commands/setContent.d.ts +4 -3
- package/dist/packages/core/src/commands/setMark.d.ts +3 -3
- package/dist/packages/core/src/commands/setMeta.d.ts +12 -0
- package/dist/packages/core/src/commands/setNode.d.ts +3 -3
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +12 -0
- package/dist/packages/core/src/commands/setTextSelection.d.ts +12 -0
- package/dist/packages/core/src/commands/sinkListItem.d.ts +3 -3
- package/dist/packages/core/src/commands/splitBlock.d.ts +3 -3
- package/dist/packages/core/src/commands/splitListItem.d.ts +3 -3
- package/dist/packages/core/src/commands/toggleList.d.ts +3 -3
- package/dist/packages/core/src/commands/toggleMark.d.ts +8 -3
- package/dist/packages/core/src/commands/toggleNode.d.ts +3 -3
- package/dist/packages/core/src/commands/toggleWrap.d.ts +3 -3
- package/dist/packages/core/src/commands/undoInputRule.d.ts +3 -3
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +3 -3
- package/dist/packages/core/src/commands/unsetMark.d.ts +8 -3
- package/dist/packages/core/src/commands/updateAttributes.d.ts +13 -0
- package/dist/packages/core/src/commands/wrapIn.d.ts +3 -3
- package/dist/packages/core/src/commands/wrapInList.d.ts +3 -3
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +1 -1
- package/dist/packages/core/src/extensions/commands.d.ts +21 -15
- package/dist/packages/core/src/extensions/editable.d.ts +1 -1
- package/dist/packages/core/src/extensions/focusEvents.d.ts +1 -1
- package/dist/packages/core/src/extensions/index.d.ts +1 -0
- package/dist/packages/core/src/extensions/keymap.d.ts +1 -1
- package/dist/packages/core/src/extensions/tabindex.d.ts +2 -0
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +7 -0
- package/dist/packages/core/src/helpers/createChainableState.d.ts +5 -0
- package/dist/packages/core/src/helpers/createDocument.d.ts +3 -4
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +4 -5
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +2 -0
- package/dist/packages/core/src/helpers/findChildren.d.ts +3 -0
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +6 -0
- package/dist/packages/core/src/helpers/findParentNode.d.ts +1 -1
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +1 -1
- package/dist/packages/core/src/helpers/generateHTML.d.ts +2 -2
- package/dist/packages/core/src/helpers/generateJSON.d.ts +2 -0
- package/dist/packages/core/src/helpers/generateText.d.ts +5 -0
- package/dist/packages/core/src/helpers/getAttributes.d.ts +3 -0
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +1 -1
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +11 -0
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +8 -0
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +2 -0
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +2 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +1 -2
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +1 -1
- package/dist/packages/core/src/helpers/getMarkType.d.ts +1 -1
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +2 -2
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +1 -2
- package/dist/packages/core/src/helpers/getNodeType.d.ts +1 -1
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +2 -2
- package/dist/packages/core/src/helpers/getSchema.d.ts +1 -1
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +3 -0
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +1 -1
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +1 -1
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +2 -2
- package/dist/packages/core/src/helpers/getText.d.ts +6 -0
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +6 -0
- package/dist/packages/core/src/helpers/getTextSeralizersFromSchema.d.ts +3 -0
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +1 -1
- package/dist/packages/core/src/helpers/isActive.d.ts +1 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +2 -0
- package/dist/packages/core/src/helpers/isList.d.ts +1 -1
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +1 -2
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +1 -2
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +1 -1
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +1 -1
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +1 -1
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +2 -0
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +4 -0
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +1 -1
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +4 -4
- package/dist/packages/core/src/index.d.ts +51 -20
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +11 -2
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +11 -2
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +9 -0
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +14 -0
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +23 -0
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +11 -2
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +9 -0
- package/dist/packages/core/src/style.d.ts +1 -2
- package/dist/packages/core/src/types.d.ts +105 -52
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +2 -1
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +1 -2
- package/dist/packages/core/src/utilities/elementFromString.d.ts +1 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -0
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +1 -0
- package/dist/packages/core/src/utilities/fromString.d.ts +1 -1
- package/dist/packages/core/src/utilities/isClass.d.ts +1 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +1 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +1 -0
- package/dist/packages/core/src/utilities/isMacOS.d.ts +1 -0
- package/dist/packages/core/src/utilities/isNumber.d.ts +1 -0
- package/dist/packages/core/src/utilities/isObject.d.ts +1 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +1 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +1 -0
- package/dist/packages/core/src/utilities/isiOS.d.ts +1 -0
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +1 -2
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +1 -2
- package/dist/packages/core/src/utilities/minMax.d.ts +1 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +3 -2
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +8 -0
- package/dist/tiptap-core.cjs.js +3572 -2041
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +3544 -2044
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +3430 -1898
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +20 -16
- package/src/CommandManager.ts +60 -62
- package/src/Editor.ts +109 -74
- package/src/EventEmitter.ts +14 -4
- package/src/Extension.ts +196 -41
- package/src/ExtensionManager.ts +242 -78
- package/src/InputRule.ts +268 -0
- package/src/Mark.ts +242 -47
- package/src/Node.ts +279 -52
- package/src/NodeView.ts +105 -42
- package/src/PasteRule.ts +246 -0
- package/src/Tracker.ts +42 -0
- package/src/commands/blur.ts +12 -6
- package/src/commands/clearContent.ts +3 -3
- package/src/commands/clearNodes.ts +29 -18
- package/src/commands/command.ts +2 -2
- package/src/commands/createParagraphNear.ts +3 -3
- package/src/commands/deleteNode.ts +36 -0
- package/src/commands/deleteRange.ts +3 -3
- package/src/commands/deleteSelection.ts +3 -3
- package/src/commands/enter.ts +3 -3
- package/src/commands/exitCode.ts +3 -3
- package/src/commands/extendMarkRange.ts +10 -10
- package/src/commands/first.ts +3 -3
- package/src/commands/focus.ts +45 -44
- package/src/commands/forEach.ts +24 -0
- package/src/commands/insertContent.ts +12 -24
- package/src/commands/insertContentAt.ts +107 -0
- package/src/commands/joinBackward.ts +3 -3
- package/src/commands/joinForward.ts +3 -3
- package/src/commands/keyboardShortcut.ts +6 -6
- package/src/commands/lift.ts +5 -5
- package/src/commands/liftEmptyBlock.ts +3 -3
- package/src/commands/liftListItem.ts +4 -4
- package/src/commands/newlineInCode.ts +3 -3
- package/src/commands/resetAttributes.ts +61 -0
- package/src/commands/scrollIntoView.ts +3 -3
- package/src/commands/selectAll.ts +8 -6
- package/src/commands/selectNodeBackward.ts +3 -3
- package/src/commands/selectNodeForward.ts +3 -3
- package/src/commands/selectParentNode.ts +3 -3
- package/src/commands/selectTextblockEnd.ts +19 -0
- package/src/commands/selectTextblockStart.ts +19 -0
- package/src/commands/setContent.ts +7 -11
- package/src/commands/setMark.ts +35 -12
- package/src/commands/setMeta.ts +18 -0
- package/src/commands/setNode.ts +27 -6
- package/src/commands/setNodeSelection.ts +28 -0
- package/src/commands/setTextSelection.ts +32 -0
- package/src/commands/sinkListItem.ts +4 -4
- package/src/commands/splitBlock.ts +14 -9
- package/src/commands/splitListItem.ts +41 -15
- package/src/commands/toggleList.ts +82 -18
- package/src/commands/toggleMark.ts +17 -7
- package/src/commands/toggleNode.ts +5 -5
- package/src/commands/toggleWrap.ts +8 -9
- package/src/commands/undoInputRule.ts +34 -5
- package/src/commands/unsetAllMarks.ts +7 -11
- package/src/commands/unsetMark.ts +34 -22
- package/src/commands/updateAttributes.ts +72 -0
- package/src/commands/wrapIn.ts +4 -10
- package/src/commands/wrapInList.ts +4 -4
- package/src/extensions/clipboardTextSerializer.ts +13 -35
- package/src/extensions/commands.ts +30 -21
- package/src/extensions/focusEvents.ts +0 -3
- package/src/extensions/index.ts +1 -0
- package/src/extensions/keymap.ts +111 -13
- package/src/extensions/tabindex.ts +19 -0
- package/src/helpers/combineTransactionSteps.ts +18 -0
- package/src/helpers/createChainableState.ts +37 -0
- package/src/helpers/createDocument.ts +5 -7
- package/src/helpers/createNodeFromContent.ts +15 -18
- package/src/helpers/defaultBlockAt.ts +13 -0
- package/src/helpers/findChildren.ts +17 -0
- package/src/helpers/findChildrenInRange.ts +31 -0
- package/src/helpers/findParentNode.ts +2 -2
- package/src/helpers/findParentNodeClosestToPos.ts +1 -1
- package/src/helpers/generateHTML.ts +5 -5
- package/src/helpers/generateJSON.ts +13 -0
- package/src/helpers/generateText.ts +29 -0
- package/src/helpers/getAttributes.ts +27 -0
- package/src/helpers/getAttributesFromExtensions.ts +28 -7
- package/src/helpers/getChangedRanges.ts +82 -0
- package/src/helpers/getDebugJSON.ts +53 -0
- package/src/helpers/getExtensionField.ts +25 -0
- package/src/helpers/getHTMLFromFragment.ts +6 -5
- package/src/helpers/getMarkAttributes.ts +12 -9
- package/src/helpers/getMarkRange.ts +34 -6
- package/src/helpers/getMarkType.ts +5 -1
- package/src/helpers/getMarksBetween.ts +31 -10
- package/src/helpers/getNodeAttributes.ts +7 -8
- package/src/helpers/getNodeType.ts +5 -1
- package/src/helpers/getRenderedAttributes.ts +4 -6
- package/src/helpers/getSchema.ts +6 -133
- package/src/helpers/getSchemaByResolvedExtensions.ts +147 -0
- package/src/helpers/getSchemaTypeByName.ts +2 -10
- package/src/helpers/getSchemaTypeNameByName.ts +1 -1
- package/src/helpers/getSplittedAttributes.ts +4 -4
- package/src/helpers/getText.ts +18 -0
- package/src/helpers/getTextBetween.ts +45 -0
- package/src/helpers/getTextSeralizersFromSchema.ts +9 -0
- package/src/helpers/injectExtensionAttributesToParseRule.ts +15 -17
- package/src/helpers/isActive.ts +4 -5
- package/src/helpers/isExtensionRulesEnabled.ts +15 -0
- package/src/helpers/isList.ts +14 -7
- package/src/helpers/isMarkActive.ts +43 -19
- package/src/helpers/isNodeActive.ts +26 -34
- package/src/helpers/isNodeEmpty.ts +1 -1
- package/src/helpers/isNodeSelection.ts +2 -2
- package/src/helpers/isTextSelection.ts +2 -2
- package/src/helpers/posToDOMRect.ts +34 -0
- package/src/helpers/resolveFocusPosition.ts +34 -0
- package/src/helpers/selectionToInsertionEnd.ts +1 -1
- package/src/helpers/splitExtensions.ts +1 -1
- package/src/index.ts +53 -20
- package/src/inputRules/markInputRule.ts +58 -39
- package/src/inputRules/nodeInputRule.ts +44 -11
- package/src/inputRules/textInputRule.ts +35 -0
- package/src/inputRules/textblockTypeInputRule.ts +37 -0
- package/src/inputRules/wrappingInputRule.ts +59 -0
- package/src/pasteRules/markPasteRule.ts +61 -53
- package/src/pasteRules/textPasteRule.ts +35 -0
- package/src/style.ts +16 -3
- package/src/types.ts +119 -37
- package/src/utilities/callOrReturn.ts +6 -3
- package/src/utilities/createStyleTag.ts +8 -1
- package/src/utilities/deleteProps.ts +2 -4
- package/src/utilities/elementFromString.ts +4 -5
- package/src/utilities/escapeForRegEx.ts +4 -0
- package/src/utilities/findDuplicates.ts +5 -0
- package/src/utilities/fromString.ts +2 -2
- package/src/utilities/isClass.ts +2 -2
- package/src/utilities/isEmptyObject.ts +2 -2
- package/src/utilities/isFunction.ts +3 -0
- package/src/utilities/isMacOS.ts +5 -0
- package/src/utilities/isNumber.ts +3 -0
- package/src/utilities/isObject.ts +6 -6
- package/src/utilities/isPlainObject.ts +8 -5
- package/src/utilities/isRegExp.ts +3 -0
- package/src/utilities/isString.ts +3 -0
- package/src/utilities/isiOS.ts +12 -0
- package/src/utilities/mergeAttributes.ts +2 -3
- package/src/utilities/mergeDeep.ts +2 -3
- package/src/utilities/minMax.ts +1 -1
- package/src/utilities/objectIncludes.ts +17 -5
- package/src/utilities/removeDuplicates.ts +15 -0
- package/CHANGELOG.md +0 -324
- package/dist/packages/core/src/commands/insertHTML.d.ts +0 -12
- package/dist/packages/core/src/commands/insertNode.d.ts +0 -13
- package/dist/packages/core/src/commands/insertText.d.ts +0 -12
- package/dist/packages/core/src/commands/replace.d.ts +0 -13
- package/dist/packages/core/src/commands/replaceRange.d.ts +0 -13
- package/dist/packages/core/src/commands/resetNodeAttributes.d.ts +0 -13
- package/dist/packages/core/src/commands/updateNodeAttributes.d.ts +0 -13
- package/dist/packages/core/src/utilities/removeElement.d.ts +0 -1
- package/dist/tiptap-core.bundle.umd.min.js +0 -17
- package/dist/tiptap-core.bundle.umd.min.js.map +0 -1
- package/src/commands/insertHTML.ts +0 -30
- package/src/commands/insertNode.ts +0 -33
- package/src/commands/insertText.ts +0 -22
- package/src/commands/replace.ts +0 -20
- package/src/commands/replaceRange.ts +0 -36
- package/src/commands/resetNodeAttributes.ts +0 -31
- package/src/commands/updateNodeAttributes.ts +0 -33
- package/src/utilities/removeElement.ts +0 -5
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/core",
|
|
3
3
|
"description": "headless rich text editor",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.170",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
8
8
|
"headless",
|
|
9
9
|
"wysiwyg",
|
|
10
|
-
"text editor"
|
|
10
|
+
"text editor",
|
|
11
|
+
"prosemirror"
|
|
11
12
|
],
|
|
12
13
|
"license": "MIT",
|
|
13
14
|
"funding": {
|
|
@@ -17,7 +18,6 @@
|
|
|
17
18
|
"main": "dist/tiptap-core.cjs.js",
|
|
18
19
|
"umd": "dist/tiptap-core.umd.js",
|
|
19
20
|
"module": "dist/tiptap-core.esm.js",
|
|
20
|
-
"unpkg": "dist/tiptap-core.bundle.umd.min.js",
|
|
21
21
|
"types": "dist/packages/core/src/index.d.ts",
|
|
22
22
|
"files": [
|
|
23
23
|
"src",
|
|
@@ -25,21 +25,25 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@types/prosemirror-commands": "^1.0.4",
|
|
28
|
-
"@types/prosemirror-inputrules": "^1.0.4",
|
|
29
28
|
"@types/prosemirror-keymap": "^1.0.4",
|
|
30
|
-
"@types/prosemirror-model": "^1.
|
|
29
|
+
"@types/prosemirror-model": "^1.16.0",
|
|
31
30
|
"@types/prosemirror-schema-list": "^1.0.3",
|
|
32
|
-
"@types/prosemirror-state": "^1.2.
|
|
33
|
-
"@types/prosemirror-transform": "^1.1.
|
|
34
|
-
"@types/prosemirror-view": "^1.
|
|
35
|
-
"prosemirror-commands": "^1.1
|
|
36
|
-
"prosemirror-
|
|
37
|
-
"prosemirror-
|
|
38
|
-
"prosemirror-
|
|
39
|
-
"prosemirror-schema-list": "^1.1.4",
|
|
31
|
+
"@types/prosemirror-state": "^1.2.8",
|
|
32
|
+
"@types/prosemirror-transform": "^1.1.5",
|
|
33
|
+
"@types/prosemirror-view": "^1.23.1",
|
|
34
|
+
"prosemirror-commands": "^1.2.1",
|
|
35
|
+
"prosemirror-keymap": "^1.1.5",
|
|
36
|
+
"prosemirror-model": "^1.16.1",
|
|
37
|
+
"prosemirror-schema-list": "^1.1.6",
|
|
40
38
|
"prosemirror-state": "^1.3.4",
|
|
41
|
-
"prosemirror-transform": "^1.3.
|
|
42
|
-
"prosemirror-view": "^1.
|
|
39
|
+
"prosemirror-transform": "^1.3.3",
|
|
40
|
+
"prosemirror-view": "^1.23.6"
|
|
43
41
|
},
|
|
44
|
-
"
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/ueberdosis/tiptap",
|
|
45
|
+
"directory": "packages/core"
|
|
46
|
+
},
|
|
47
|
+
"sideEffects": false,
|
|
48
|
+
"gitHead": "9ef798d53713edd2163d779b78fa7e142664a97b"
|
|
45
49
|
}
|
package/src/CommandManager.ts
CHANGED
|
@@ -1,37 +1,52 @@
|
|
|
1
1
|
import { EditorState, Transaction } from 'prosemirror-state'
|
|
2
2
|
import { Editor } from './Editor'
|
|
3
|
+
import { createChainableState } from './helpers/createChainableState'
|
|
3
4
|
import {
|
|
4
5
|
SingleCommands,
|
|
5
6
|
ChainedCommands,
|
|
6
7
|
CanCommands,
|
|
7
|
-
|
|
8
|
+
AnyCommands,
|
|
8
9
|
CommandProps,
|
|
9
10
|
} from './types'
|
|
10
11
|
|
|
11
|
-
export
|
|
12
|
+
export class CommandManager {
|
|
12
13
|
|
|
13
14
|
editor: Editor
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
rawCommands: AnyCommands
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
customState?: EditorState
|
|
19
|
+
|
|
20
|
+
constructor(props: {
|
|
21
|
+
editor: Editor,
|
|
22
|
+
state?: EditorState,
|
|
23
|
+
}) {
|
|
24
|
+
this.editor = props.editor
|
|
25
|
+
this.rawCommands = this.editor.extensionManager.commands
|
|
26
|
+
this.customState = props.state
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get hasCustomState(): boolean {
|
|
30
|
+
return !!this.customState
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get state(): EditorState {
|
|
34
|
+
return this.customState || this.editor.state
|
|
20
35
|
}
|
|
21
36
|
|
|
22
|
-
|
|
23
|
-
const {
|
|
24
|
-
const {
|
|
37
|
+
get commands(): SingleCommands {
|
|
38
|
+
const { rawCommands, editor, state } = this
|
|
39
|
+
const { view } = editor
|
|
25
40
|
const { tr } = state
|
|
26
41
|
const props = this.buildProps(tr)
|
|
27
42
|
|
|
28
43
|
return Object.fromEntries(Object
|
|
29
|
-
.entries(
|
|
44
|
+
.entries(rawCommands)
|
|
30
45
|
.map(([name, command]) => {
|
|
31
|
-
const method = (...args: any) => {
|
|
46
|
+
const method = (...args: any[]) => {
|
|
32
47
|
const callback = command(...args)(props)
|
|
33
48
|
|
|
34
|
-
if (!tr.getMeta('preventDispatch')) {
|
|
49
|
+
if (!tr.getMeta('preventDispatch') && !this.hasCustomState) {
|
|
35
50
|
view.dispatch(tr)
|
|
36
51
|
}
|
|
37
52
|
|
|
@@ -39,27 +54,40 @@ export default class CommandManager {
|
|
|
39
54
|
}
|
|
40
55
|
|
|
41
56
|
return [name, method]
|
|
42
|
-
})) as SingleCommands
|
|
57
|
+
})) as unknown as SingleCommands
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get chain(): () => ChainedCommands {
|
|
61
|
+
return () => this.createChain()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get can(): () => CanCommands {
|
|
65
|
+
return () => this.createCan()
|
|
43
66
|
}
|
|
44
67
|
|
|
45
68
|
public createChain(startTr?: Transaction, shouldDispatch = true): ChainedCommands {
|
|
46
|
-
const {
|
|
47
|
-
const {
|
|
69
|
+
const { rawCommands, editor, state } = this
|
|
70
|
+
const { view } = editor
|
|
48
71
|
const callbacks: boolean[] = []
|
|
49
72
|
const hasStartTransaction = !!startTr
|
|
50
73
|
const tr = startTr || state.tr
|
|
51
74
|
|
|
52
75
|
const run = () => {
|
|
53
|
-
if (
|
|
76
|
+
if (
|
|
77
|
+
!hasStartTransaction
|
|
78
|
+
&& shouldDispatch
|
|
79
|
+
&& !tr.getMeta('preventDispatch')
|
|
80
|
+
&& !this.hasCustomState
|
|
81
|
+
) {
|
|
54
82
|
view.dispatch(tr)
|
|
55
83
|
}
|
|
56
84
|
|
|
57
|
-
return
|
|
85
|
+
return callbacks.every(callback => callback === true)
|
|
58
86
|
}
|
|
59
87
|
|
|
60
88
|
const chain = {
|
|
61
|
-
...Object.fromEntries(Object.entries(
|
|
62
|
-
const chainedCommand = (...args:
|
|
89
|
+
...Object.fromEntries(Object.entries(rawCommands).map(([name, command]) => {
|
|
90
|
+
const chainedCommand = (...args: never[]) => {
|
|
63
91
|
const props = this.buildProps(tr, shouldDispatch)
|
|
64
92
|
const callback = command(...args)(props)
|
|
65
93
|
|
|
@@ -77,16 +105,15 @@ export default class CommandManager {
|
|
|
77
105
|
}
|
|
78
106
|
|
|
79
107
|
public createCan(startTr?: Transaction): CanCommands {
|
|
80
|
-
const {
|
|
81
|
-
const { state } = editor
|
|
108
|
+
const { rawCommands, state } = this
|
|
82
109
|
const dispatch = undefined
|
|
83
110
|
const tr = startTr || state.tr
|
|
84
111
|
const props = this.buildProps(tr, dispatch)
|
|
85
112
|
const formattedCommands = Object.fromEntries(Object
|
|
86
|
-
.entries(
|
|
113
|
+
.entries(rawCommands)
|
|
87
114
|
.map(([name, command]) => {
|
|
88
|
-
return [name, (...args:
|
|
89
|
-
})) as SingleCommands
|
|
115
|
+
return [name, (...args: never[]) => command(...args)({ ...props, dispatch })]
|
|
116
|
+
})) as unknown as SingleCommands
|
|
90
117
|
|
|
91
118
|
return {
|
|
92
119
|
...formattedCommands,
|
|
@@ -95,8 +122,8 @@ export default class CommandManager {
|
|
|
95
122
|
}
|
|
96
123
|
|
|
97
124
|
public buildProps(tr: Transaction, shouldDispatch = true): CommandProps {
|
|
98
|
-
const { editor,
|
|
99
|
-
const {
|
|
125
|
+
const { rawCommands, editor, state } = this
|
|
126
|
+
const { view } = editor
|
|
100
127
|
|
|
101
128
|
if (state.storedMarks) {
|
|
102
129
|
tr.setStoredMarks(state.storedMarks)
|
|
@@ -106,7 +133,10 @@ export default class CommandManager {
|
|
|
106
133
|
tr,
|
|
107
134
|
editor,
|
|
108
135
|
view,
|
|
109
|
-
state:
|
|
136
|
+
state: createChainableState({
|
|
137
|
+
state,
|
|
138
|
+
transaction: tr,
|
|
139
|
+
}),
|
|
110
140
|
dispatch: shouldDispatch
|
|
111
141
|
? () => undefined
|
|
112
142
|
: undefined,
|
|
@@ -114,46 +144,14 @@ export default class CommandManager {
|
|
|
114
144
|
can: () => this.createCan(tr),
|
|
115
145
|
get commands() {
|
|
116
146
|
return Object.fromEntries(Object
|
|
117
|
-
.entries(
|
|
147
|
+
.entries(rawCommands)
|
|
118
148
|
.map(([name, command]) => {
|
|
119
|
-
return [name, (...args:
|
|
120
|
-
})) as SingleCommands
|
|
149
|
+
return [name, (...args: never[]) => command(...args)(props)]
|
|
150
|
+
})) as unknown as SingleCommands
|
|
121
151
|
},
|
|
122
152
|
}
|
|
123
153
|
|
|
124
154
|
return props
|
|
125
155
|
}
|
|
126
156
|
|
|
127
|
-
public chainableState(tr: Transaction, state: EditorState): EditorState {
|
|
128
|
-
let { selection } = tr
|
|
129
|
-
let { doc } = tr
|
|
130
|
-
let { storedMarks } = tr
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
...state,
|
|
134
|
-
schema: state.schema,
|
|
135
|
-
plugins: state.plugins,
|
|
136
|
-
apply: state.apply.bind(state),
|
|
137
|
-
applyTransaction: state.applyTransaction.bind(state),
|
|
138
|
-
reconfigure: state.reconfigure.bind(state),
|
|
139
|
-
toJSON: state.toJSON.bind(state),
|
|
140
|
-
get storedMarks() {
|
|
141
|
-
return storedMarks
|
|
142
|
-
},
|
|
143
|
-
get selection() {
|
|
144
|
-
return selection
|
|
145
|
-
},
|
|
146
|
-
get doc() {
|
|
147
|
-
return doc
|
|
148
|
-
},
|
|
149
|
-
get tr() {
|
|
150
|
-
selection = tr.selection
|
|
151
|
-
doc = tr.doc
|
|
152
|
-
storedMarks = tr.storedMarks
|
|
153
|
-
|
|
154
|
-
return tr
|
|
155
|
-
},
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
157
|
}
|
package/src/Editor.ts
CHANGED
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
|
-
EditorState,
|
|
2
|
+
EditorState,
|
|
3
|
+
Plugin,
|
|
4
|
+
PluginKey,
|
|
5
|
+
Transaction,
|
|
3
6
|
} from 'prosemirror-state'
|
|
4
7
|
import { EditorView } from 'prosemirror-view'
|
|
5
|
-
import { Schema } from 'prosemirror-model'
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
8
|
+
import { Schema, MarkType, NodeType } from 'prosemirror-model'
|
|
9
|
+
import { getAttributes } from './helpers/getAttributes'
|
|
10
|
+
import { isActive } from './helpers/isActive'
|
|
11
|
+
import { createDocument } from './helpers/createDocument'
|
|
12
|
+
import { getHTMLFromFragment } from './helpers/getHTMLFromFragment'
|
|
13
|
+
import { getText } from './helpers/getText'
|
|
14
|
+
import { isNodeEmpty } from './helpers/isNodeEmpty'
|
|
15
|
+
import { resolveFocusPosition } from './helpers/resolveFocusPosition'
|
|
16
|
+
import { getTextSeralizersFromSchema } from './helpers/getTextSeralizersFromSchema'
|
|
17
|
+
import { createStyleTag } from './utilities/createStyleTag'
|
|
18
|
+
import { isFunction } from './utilities/isFunction'
|
|
19
|
+
import { CommandManager } from './CommandManager'
|
|
20
|
+
import { ExtensionManager } from './ExtensionManager'
|
|
21
|
+
import { EventEmitter } from './EventEmitter'
|
|
17
22
|
import {
|
|
18
23
|
EditorOptions,
|
|
19
24
|
CanCommands,
|
|
20
25
|
ChainedCommands,
|
|
26
|
+
JSONContent,
|
|
21
27
|
SingleCommands,
|
|
22
|
-
|
|
28
|
+
TextSerializer,
|
|
29
|
+
EditorEvents,
|
|
23
30
|
} from './types'
|
|
24
31
|
import * as extensions from './extensions'
|
|
25
|
-
import style from './style'
|
|
32
|
+
import { style } from './style'
|
|
26
33
|
|
|
27
34
|
export { extensions }
|
|
28
35
|
|
|
@@ -30,7 +37,7 @@ export interface HTMLElement {
|
|
|
30
37
|
editor?: Editor
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
export class Editor extends EventEmitter {
|
|
40
|
+
export class Editor extends EventEmitter<EditorEvents> {
|
|
34
41
|
|
|
35
42
|
private commandManager!: CommandManager
|
|
36
43
|
|
|
@@ -44,7 +51,7 @@ export class Editor extends EventEmitter {
|
|
|
44
51
|
|
|
45
52
|
public isFocused = false
|
|
46
53
|
|
|
47
|
-
|
|
54
|
+
public extensionStorage: Record<string, any> = {}
|
|
48
55
|
|
|
49
56
|
public options: EditorOptions = {
|
|
50
57
|
element: document.createElement('div'),
|
|
@@ -57,14 +64,14 @@ export class Editor extends EventEmitter {
|
|
|
57
64
|
parseOptions: {},
|
|
58
65
|
enableInputRules: true,
|
|
59
66
|
enablePasteRules: true,
|
|
67
|
+
enableCoreExtensions: true,
|
|
68
|
+
onBeforeCreate: () => null,
|
|
60
69
|
onCreate: () => null,
|
|
61
70
|
onUpdate: () => null,
|
|
62
71
|
onSelectionUpdate: () => null,
|
|
63
|
-
onViewUpdate: () => null,
|
|
64
72
|
onTransaction: () => null,
|
|
65
73
|
onFocus: () => null,
|
|
66
74
|
onBlur: () => null,
|
|
67
|
-
onResize: () => null,
|
|
68
75
|
onDestroy: () => null,
|
|
69
76
|
}
|
|
70
77
|
|
|
@@ -74,50 +81,54 @@ export class Editor extends EventEmitter {
|
|
|
74
81
|
this.createExtensionManager()
|
|
75
82
|
this.createCommandManager()
|
|
76
83
|
this.createSchema()
|
|
84
|
+
this.on('beforeCreate', this.options.onBeforeCreate)
|
|
85
|
+
this.emit('beforeCreate', { editor: this })
|
|
77
86
|
this.createView()
|
|
78
87
|
this.injectCSS()
|
|
79
88
|
this.on('create', this.options.onCreate)
|
|
80
89
|
this.on('update', this.options.onUpdate)
|
|
81
90
|
this.on('selectionUpdate', this.options.onSelectionUpdate)
|
|
82
|
-
this.on('viewUpdate', this.options.onViewUpdate)
|
|
83
91
|
this.on('transaction', this.options.onTransaction)
|
|
84
92
|
this.on('focus', this.options.onFocus)
|
|
85
93
|
this.on('blur', this.options.onBlur)
|
|
86
94
|
this.on('destroy', this.options.onDestroy)
|
|
87
95
|
|
|
88
96
|
window.setTimeout(() => {
|
|
97
|
+
if (this.isDestroyed) {
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
89
101
|
this.commands.focus(this.options.autofocus)
|
|
90
102
|
this.emit('create', { editor: this })
|
|
91
|
-
|
|
92
|
-
if (window.ResizeObserver) {
|
|
93
|
-
this.resizeObserver = new ResizeObserver(() => {
|
|
94
|
-
this.emit('resize', { editor: this })
|
|
95
|
-
})
|
|
96
|
-
this.resizeObserver.observe(this.view.dom)
|
|
97
|
-
}
|
|
98
103
|
}, 0)
|
|
104
|
+
}
|
|
99
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Returns the editor storage.
|
|
108
|
+
*/
|
|
109
|
+
public get storage(): Record<string, any> {
|
|
110
|
+
return this.extensionStorage
|
|
100
111
|
}
|
|
101
112
|
|
|
102
113
|
/**
|
|
103
114
|
* An object of all registered commands.
|
|
104
115
|
*/
|
|
105
116
|
public get commands(): SingleCommands {
|
|
106
|
-
return this.commandManager.
|
|
117
|
+
return this.commandManager.commands
|
|
107
118
|
}
|
|
108
119
|
|
|
109
120
|
/**
|
|
110
121
|
* Create a command chain to call multiple commands at once.
|
|
111
122
|
*/
|
|
112
123
|
public chain(): ChainedCommands {
|
|
113
|
-
return this.commandManager.
|
|
124
|
+
return this.commandManager.chain()
|
|
114
125
|
}
|
|
115
126
|
|
|
116
127
|
/**
|
|
117
128
|
* Check if a command or a command chain can be executed. Without executing it.
|
|
118
129
|
*/
|
|
119
130
|
public can(): CanCommands {
|
|
120
|
-
return this.commandManager.
|
|
131
|
+
return this.commandManager.can()
|
|
121
132
|
}
|
|
122
133
|
|
|
123
134
|
/**
|
|
@@ -135,7 +146,20 @@ export class Editor extends EventEmitter {
|
|
|
135
146
|
* @param options A list of options
|
|
136
147
|
*/
|
|
137
148
|
public setOptions(options: Partial<EditorOptions> = {}): void {
|
|
138
|
-
this.options = {
|
|
149
|
+
this.options = {
|
|
150
|
+
...this.options,
|
|
151
|
+
...options,
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!this.view || !this.state || this.isDestroyed) {
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (this.options.editorProps) {
|
|
159
|
+
this.view.setProps(this.options.editorProps)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
this.view.updateState(this.state)
|
|
139
163
|
}
|
|
140
164
|
|
|
141
165
|
/**
|
|
@@ -143,17 +167,18 @@ export class Editor extends EventEmitter {
|
|
|
143
167
|
*/
|
|
144
168
|
public setEditable(editable: boolean): void {
|
|
145
169
|
this.setOptions({ editable })
|
|
146
|
-
|
|
147
|
-
if (this.view && this.state && !this.isDestroyed) {
|
|
148
|
-
this.view.updateState(this.state)
|
|
149
|
-
}
|
|
150
170
|
}
|
|
151
171
|
|
|
152
172
|
/**
|
|
153
173
|
* Returns whether the editor is editable.
|
|
154
174
|
*/
|
|
155
175
|
public get isEditable(): boolean {
|
|
156
|
-
|
|
176
|
+
// since plugins are applied after creating the view
|
|
177
|
+
// `editable` is always `true` for one tick.
|
|
178
|
+
// that’s why we also have to check for `options.editable`
|
|
179
|
+
return this.options.editable
|
|
180
|
+
&& this.view
|
|
181
|
+
&& this.view.editable
|
|
157
182
|
}
|
|
158
183
|
|
|
159
184
|
/**
|
|
@@ -170,7 +195,7 @@ export class Editor extends EventEmitter {
|
|
|
170
195
|
* @param handlePlugins Control how to merge the plugin into the existing plugins.
|
|
171
196
|
*/
|
|
172
197
|
public registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): void {
|
|
173
|
-
const plugins =
|
|
198
|
+
const plugins = isFunction(handlePlugins)
|
|
174
199
|
? handlePlugins(plugin, this.state.plugins)
|
|
175
200
|
: [...this.state.plugins, plugin]
|
|
176
201
|
|
|
@@ -182,7 +207,7 @@ export class Editor extends EventEmitter {
|
|
|
182
207
|
/**
|
|
183
208
|
* Unregister a ProseMirror plugin.
|
|
184
209
|
*
|
|
185
|
-
* @param
|
|
210
|
+
* @param nameOrPluginKey The plugins name
|
|
186
211
|
*/
|
|
187
212
|
public unregisterPlugin(nameOrPluginKey: string | PluginKey): void {
|
|
188
213
|
if (this.isDestroyed) {
|
|
@@ -206,7 +231,9 @@ export class Editor extends EventEmitter {
|
|
|
206
231
|
* Creates an extension manager.
|
|
207
232
|
*/
|
|
208
233
|
private createExtensionManager(): void {
|
|
209
|
-
const coreExtensions =
|
|
234
|
+
const coreExtensions = this.options.enableCoreExtensions
|
|
235
|
+
? Object.values(extensions)
|
|
236
|
+
: []
|
|
210
237
|
const allExtensions = [...coreExtensions, ...this.options.extensions].filter(extension => {
|
|
211
238
|
return ['extension', 'node', 'mark'].includes(extension?.type)
|
|
212
239
|
})
|
|
@@ -218,7 +245,9 @@ export class Editor extends EventEmitter {
|
|
|
218
245
|
* Creates an command manager.
|
|
219
246
|
*/
|
|
220
247
|
private createCommandManager(): void {
|
|
221
|
-
this.commandManager = new CommandManager(
|
|
248
|
+
this.commandManager = new CommandManager({
|
|
249
|
+
editor: this,
|
|
250
|
+
})
|
|
222
251
|
}
|
|
223
252
|
|
|
224
253
|
/**
|
|
@@ -232,27 +261,22 @@ export class Editor extends EventEmitter {
|
|
|
232
261
|
* Creates a ProseMirror view.
|
|
233
262
|
*/
|
|
234
263
|
private createView(): void {
|
|
264
|
+
const doc = createDocument(this.options.content, this.schema, this.options.parseOptions)
|
|
265
|
+
const selection = resolveFocusPosition(doc, this.options.autofocus)
|
|
266
|
+
|
|
235
267
|
this.view = new EditorView(this.options.element, {
|
|
236
268
|
...this.options.editorProps,
|
|
237
269
|
dispatchTransaction: this.dispatchTransaction.bind(this),
|
|
238
270
|
state: EditorState.create({
|
|
239
|
-
doc
|
|
271
|
+
doc,
|
|
272
|
+
selection,
|
|
240
273
|
}),
|
|
241
274
|
})
|
|
242
275
|
|
|
243
276
|
// `editor.view` is not yet available at this time.
|
|
244
277
|
// Therefore we will add all plugins and node views directly afterwards.
|
|
245
278
|
const newState = this.state.reconfigure({
|
|
246
|
-
plugins:
|
|
247
|
-
new Plugin({
|
|
248
|
-
view: () => ({
|
|
249
|
-
update: () => this.emit('viewUpdate', {
|
|
250
|
-
editor: this,
|
|
251
|
-
}),
|
|
252
|
-
}),
|
|
253
|
-
}),
|
|
254
|
-
...this.extensionManager.plugins,
|
|
255
|
-
],
|
|
279
|
+
plugins: this.extensionManager.plugins,
|
|
256
280
|
})
|
|
257
281
|
|
|
258
282
|
this.view.updateState(newState)
|
|
@@ -262,6 +286,7 @@ export class Editor extends EventEmitter {
|
|
|
262
286
|
// Let’s store the editor instance in the DOM element.
|
|
263
287
|
// So we’ll have access to it for tests.
|
|
264
288
|
const dom = this.view.dom as HTMLElement
|
|
289
|
+
|
|
265
290
|
dom.editor = this
|
|
266
291
|
}
|
|
267
292
|
|
|
@@ -296,10 +321,6 @@ export class Editor extends EventEmitter {
|
|
|
296
321
|
* @param transaction An editor state transaction
|
|
297
322
|
*/
|
|
298
323
|
private dispatchTransaction(transaction: Transaction): void {
|
|
299
|
-
if (transaction.docChanged && !this.isEditable) {
|
|
300
|
-
return
|
|
301
|
-
}
|
|
302
|
-
|
|
303
324
|
if (this.isCapturingTransaction) {
|
|
304
325
|
if (!this.capturedTransaction) {
|
|
305
326
|
this.capturedTransaction = transaction
|
|
@@ -324,6 +345,7 @@ export class Editor extends EventEmitter {
|
|
|
324
345
|
if (selectionHasChanged) {
|
|
325
346
|
this.emit('selectionUpdate', {
|
|
326
347
|
editor: this,
|
|
348
|
+
transaction,
|
|
327
349
|
})
|
|
328
350
|
}
|
|
329
351
|
|
|
@@ -334,6 +356,7 @@ export class Editor extends EventEmitter {
|
|
|
334
356
|
this.emit('focus', {
|
|
335
357
|
editor: this,
|
|
336
358
|
event: focus.event,
|
|
359
|
+
transaction,
|
|
337
360
|
})
|
|
338
361
|
}
|
|
339
362
|
|
|
@@ -341,6 +364,7 @@ export class Editor extends EventEmitter {
|
|
|
341
364
|
this.emit('blur', {
|
|
342
365
|
editor: this,
|
|
343
366
|
event: blur.event,
|
|
367
|
+
transaction,
|
|
344
368
|
})
|
|
345
369
|
}
|
|
346
370
|
|
|
@@ -355,21 +379,10 @@ export class Editor extends EventEmitter {
|
|
|
355
379
|
}
|
|
356
380
|
|
|
357
381
|
/**
|
|
358
|
-
* Get attributes of the currently selected node.
|
|
359
|
-
*
|
|
360
|
-
* @param name Name of the node
|
|
382
|
+
* Get attributes of the currently selected node or mark.
|
|
361
383
|
*/
|
|
362
|
-
public
|
|
363
|
-
return
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Get attributes of the currently selected mark.
|
|
368
|
-
*
|
|
369
|
-
* @param name Name of the mark
|
|
370
|
-
*/
|
|
371
|
-
public getMarkAttributes(name: string): AnyObject {
|
|
372
|
-
return getMarkAttributes(this.state, name)
|
|
384
|
+
public getAttributes(nameOrType: string | NodeType | MarkType): Record<string, any> {
|
|
385
|
+
return getAttributes(this.state, nameOrType)
|
|
373
386
|
}
|
|
374
387
|
|
|
375
388
|
/**
|
|
@@ -395,7 +408,7 @@ export class Editor extends EventEmitter {
|
|
|
395
408
|
/**
|
|
396
409
|
* Get the document as JSON.
|
|
397
410
|
*/
|
|
398
|
-
public getJSON():
|
|
411
|
+
public getJSON(): JSONContent {
|
|
399
412
|
return this.state.doc.toJSON()
|
|
400
413
|
}
|
|
401
414
|
|
|
@@ -403,7 +416,28 @@ export class Editor extends EventEmitter {
|
|
|
403
416
|
* Get the document as HTML.
|
|
404
417
|
*/
|
|
405
418
|
public getHTML(): string {
|
|
406
|
-
return getHTMLFromFragment(this.state.doc, this.schema)
|
|
419
|
+
return getHTMLFromFragment(this.state.doc.content, this.schema)
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Get the document as text.
|
|
424
|
+
*/
|
|
425
|
+
public getText(options?: {
|
|
426
|
+
blockSeparator?: string,
|
|
427
|
+
textSerializers?: Record<string, TextSerializer>,
|
|
428
|
+
}): string {
|
|
429
|
+
const {
|
|
430
|
+
blockSeparator = '\n\n',
|
|
431
|
+
textSerializers = {},
|
|
432
|
+
} = options || {}
|
|
433
|
+
|
|
434
|
+
return getText(this.state.doc, {
|
|
435
|
+
blockSeparator,
|
|
436
|
+
textSerializers: {
|
|
437
|
+
...textSerializers,
|
|
438
|
+
...getTextSeralizersFromSchema(this.schema),
|
|
439
|
+
},
|
|
440
|
+
})
|
|
407
441
|
}
|
|
408
442
|
|
|
409
443
|
/**
|
|
@@ -415,8 +449,12 @@ export class Editor extends EventEmitter {
|
|
|
415
449
|
|
|
416
450
|
/**
|
|
417
451
|
* Get the number of characters for the current document.
|
|
452
|
+
*
|
|
453
|
+
* @deprecated
|
|
418
454
|
*/
|
|
419
455
|
public getCharacterCount(): number {
|
|
456
|
+
console.warn('[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.')
|
|
457
|
+
|
|
420
458
|
return this.state.doc.content.size - 2
|
|
421
459
|
}
|
|
422
460
|
|
|
@@ -424,8 +462,6 @@ export class Editor extends EventEmitter {
|
|
|
424
462
|
* Destroy the editor.
|
|
425
463
|
*/
|
|
426
464
|
public destroy(): void {
|
|
427
|
-
this.resizeObserver?.unobserve(this.view.dom)
|
|
428
|
-
|
|
429
465
|
this.emit('destroy')
|
|
430
466
|
|
|
431
467
|
if (this.view) {
|
|
@@ -433,7 +469,6 @@ export class Editor extends EventEmitter {
|
|
|
433
469
|
}
|
|
434
470
|
|
|
435
471
|
this.removeAllListeners()
|
|
436
|
-
removeElement(this.css)
|
|
437
472
|
}
|
|
438
473
|
|
|
439
474
|
/**
|