@tiptap/core 2.0.0-beta.209 → 2.0.0-beta.210
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4311 -0
- package/dist/index.d.ts +2330 -0
- package/dist/index.js +4311 -0
- package/package.json +24 -23
- package/src/CommandManager.ts +27 -36
- package/src/Editor.ts +27 -37
- package/src/Extension.ts +193 -179
- package/src/ExtensionManager.ts +82 -98
- package/src/InputRule.ts +38 -43
- package/src/Mark.ts +277 -264
- package/src/Node.ts +349 -314
- package/src/NodeView.ts +24 -23
- package/src/PasteRule.ts +37 -44
- package/src/Tracker.ts +4 -8
- package/src/commands/clearNodes.ts +1 -1
- package/src/commands/createParagraphNear.ts +2 -2
- package/src/commands/deleteNode.ts +1 -1
- package/src/commands/deleteSelection.ts +2 -2
- package/src/commands/exitCode.ts +2 -2
- package/src/commands/extendMarkRange.ts +6 -3
- package/src/commands/insertContent.ts +9 -5
- package/src/commands/insertContentAt.ts +10 -24
- package/src/commands/join.ts +9 -6
- package/src/commands/lift.ts +3 -3
- package/src/commands/liftEmptyBlock.ts +1 -1
- package/src/commands/liftListItem.ts +3 -3
- package/src/commands/newlineInCode.ts +2 -2
- package/src/commands/resetAttributes.ts +11 -6
- package/src/commands/selectNodeBackward.ts +2 -2
- package/src/commands/selectNodeForward.ts +2 -2
- package/src/commands/selectParentNode.ts +2 -2
- package/src/commands/selectTextblockEnd.ts +2 -2
- package/src/commands/selectTextblockStart.ts +2 -2
- package/src/commands/setContent.ts +3 -4
- package/src/commands/setMark.ts +26 -16
- package/src/commands/setNode.ts +19 -17
- package/src/commands/setNodeSelection.ts +2 -2
- package/src/commands/setTextSelection.ts +3 -5
- package/src/commands/sinkListItem.ts +3 -3
- package/src/commands/splitBlock.ts +20 -25
- package/src/commands/splitListItem.ts +15 -25
- package/src/commands/toggleList.ts +27 -24
- package/src/commands/toggleMark.ts +3 -3
- package/src/commands/toggleNode.ts +6 -2
- package/src/commands/toggleWrap.ts +2 -2
- package/src/commands/unsetMark.ts +3 -3
- package/src/commands/updateAttributes.ts +14 -9
- package/src/commands/wrapIn.ts +3 -3
- package/src/commands/wrapInList.ts +3 -3
- package/src/extensions/clipboardTextSerializer.ts +1 -1
- package/src/extensions/editable.ts +1 -1
- package/src/extensions/focusEvents.ts +1 -1
- package/src/extensions/keymap.ts +2 -7
- package/src/extensions/tabindex.ts +1 -1
- package/src/helpers/combineTransactionSteps.ts +7 -4
- package/src/helpers/createChainableState.ts +3 -3
- package/src/helpers/createDocument.ts +1 -1
- package/src/helpers/createNodeFromContent.ts +4 -10
- package/src/helpers/defaultBlockAt.ts +1 -1
- package/src/helpers/findChildren.ts +1 -1
- package/src/helpers/findChildrenInRange.ts +6 -2
- package/src/helpers/findParentNode.ts +1 -1
- package/src/helpers/findParentNodeClosestToPos.ts +12 -7
- package/src/helpers/generateHTML.ts +1 -1
- package/src/helpers/generateJSON.ts +2 -4
- package/src/helpers/generateText.ts +4 -7
- package/src/helpers/getAttributes.ts +3 -5
- package/src/helpers/getChangedRanges.ts +1 -1
- package/src/helpers/getDebugJSON.ts +4 -4
- package/src/helpers/getHTMLFromFragment.ts +2 -4
- package/src/helpers/getMarkAttributes.ts +6 -3
- package/src/helpers/getMarkRange.ts +1 -1
- package/src/helpers/getMarkType.ts +4 -2
- package/src/helpers/getMarksBetween.ts +8 -6
- package/src/helpers/getNodeAttributes.ts +7 -6
- package/src/helpers/getNodeType.ts +4 -2
- package/src/helpers/getRenderedAttributes.ts +5 -2
- package/src/helpers/getSchema.ts +1 -1
- package/src/helpers/getSchemaByResolvedExtensions.ts +151 -107
- package/src/helpers/getSchemaTypeByName.ts +1 -1
- package/src/helpers/getSchemaTypeNameByName.ts +1 -1
- package/src/helpers/getText.ts +3 -3
- package/src/helpers/getTextBetween.ts +4 -7
- package/src/helpers/getTextContentFromNodes.ts +8 -3
- package/src/helpers/getTextSerializersFromSchema.ts +6 -5
- package/src/helpers/injectExtensionAttributesToParseRule.ts +6 -5
- package/src/helpers/isActive.ts +6 -2
- package/src/helpers/isMarkActive.ts +12 -15
- package/src/helpers/isNodeActive.ts +4 -7
- package/src/helpers/isNodeEmpty.ts +1 -1
- package/src/helpers/isNodeSelection.ts +1 -1
- package/src/helpers/isTextSelection.ts +1 -1
- package/src/helpers/posToDOMRect.ts +1 -1
- package/src/helpers/resolveFocusPosition.ts +2 -3
- package/src/helpers/selectionToInsertionEnd.ts +2 -2
- package/src/inputRules/markInputRule.ts +3 -4
- package/src/inputRules/nodeInputRule.ts +3 -4
- package/src/inputRules/textblockTypeInputRule.ts +3 -4
- package/src/inputRules/wrappingInputRule.ts +5 -6
- package/src/pasteRules/markPasteRule.ts +3 -4
- package/src/pasteRules/nodePasteRule.ts +8 -10
- package/src/types.ts +109 -125
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -147
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -227
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -18
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -327
- package/dist/packages/core/src/Node.d.ts +0 -397
- package/dist/packages/core/src/NodeView.d.ts +0 -27
- package/dist/packages/core/src/PasteRule.d.ts +0 -42
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -12
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -12
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -12
- package/dist/packages/core/src/commands/command.d.ts +0 -12
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -12
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -12
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -12
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -12
- package/dist/packages/core/src/commands/enter.d.ts +0 -12
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -12
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -13
- package/dist/packages/core/src/commands/first.d.ts +0 -12
- package/dist/packages/core/src/commands/focus.d.ts +0 -14
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -50
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -16
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -16
- package/dist/packages/core/src/commands/join.d.ts +0 -33
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -12
- package/dist/packages/core/src/commands/lift.d.ts +0 -13
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -12
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -13
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -12
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -13
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -12
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -12
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -12
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -12
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -12
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -12
- package/dist/packages/core/src/commands/setContent.d.ts +0 -13
- package/dist/packages/core/src/commands/setMark.d.ts +0 -13
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -12
- package/dist/packages/core/src/commands/setNode.d.ts +0 -13
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -12
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -12
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -13
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -14
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -13
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -12
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -12
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -18
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -13
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -13
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -13
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -2
- 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 -7
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -5
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -3
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -7
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -2
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -3
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -6
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -8
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -2
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -2
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -5
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -3
- 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 -2
- 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/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 -3
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -2
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -2
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -2
- package/dist/packages/core/src/helpers/getText.d.ts +0 -6
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -6
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -2
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -3
- package/dist/packages/core/src/helpers/index.d.ts +0 -33
- 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/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 -23
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -12
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -12
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -9
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -14
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -23
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -12
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -12
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -9
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -214
- 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/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
- package/dist/tiptap-core.cjs +0 -4360
- package/dist/tiptap-core.cjs.map +0 -1
- package/dist/tiptap-core.esm.js +0 -4284
- package/dist/tiptap-core.esm.js.map +0 -1
- package/dist/tiptap-core.umd.js +0 -4358
- package/dist/tiptap-core.umd.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.210",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -18,41 +18,42 @@
|
|
|
18
18
|
"type": "module",
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
-
"types": "./dist/
|
|
22
|
-
"import": "./dist/
|
|
23
|
-
"require": "./dist/
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.cjs"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
-
"main": "dist/
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"types": "dist/packages/core/src/index.d.ts",
|
|
26
|
+
"main": "dist/index.cjs",
|
|
27
|
+
"module": "dist/index.js",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
30
29
|
"files": [
|
|
31
30
|
"src",
|
|
32
31
|
"dist"
|
|
33
32
|
],
|
|
34
33
|
"peerDependencies": {
|
|
35
|
-
"
|
|
36
|
-
"prosemirror-keymap": "^1.2.0",
|
|
37
|
-
"prosemirror-model": "^1.18.1",
|
|
38
|
-
"prosemirror-schema-list": "^1.2.2",
|
|
39
|
-
"prosemirror-state": "^1.4.1",
|
|
40
|
-
"prosemirror-transform": "^1.7.0",
|
|
41
|
-
"prosemirror-view": "^1.28.2"
|
|
34
|
+
"@tiptap/pm": "^2.0.0-beta.209"
|
|
42
35
|
},
|
|
43
36
|
"devDependencies": {
|
|
44
|
-
"
|
|
45
|
-
"prosemirror-keymap": "^1.2.0",
|
|
46
|
-
"prosemirror-model": "^1.18.1",
|
|
47
|
-
"prosemirror-schema-list": "^1.2.2",
|
|
48
|
-
"prosemirror-state": "^1.4.1",
|
|
49
|
-
"prosemirror-transform": "^1.7.0",
|
|
50
|
-
"prosemirror-view": "^1.28.2"
|
|
37
|
+
"@tiptap/pm": "^2.0.0-beta.210"
|
|
51
38
|
},
|
|
52
39
|
"repository": {
|
|
53
40
|
"type": "git",
|
|
54
41
|
"url": "https://github.com/ueberdosis/tiptap",
|
|
55
42
|
"directory": "packages/core"
|
|
56
43
|
},
|
|
57
|
-
"sideEffects": false
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup"
|
|
47
|
+
},
|
|
48
|
+
"tsup": {
|
|
49
|
+
"entry": [
|
|
50
|
+
"src/index.ts"
|
|
51
|
+
],
|
|
52
|
+
"dts": true,
|
|
53
|
+
"splitting": true,
|
|
54
|
+
"format": [
|
|
55
|
+
"esm",
|
|
56
|
+
"cjs"
|
|
57
|
+
]
|
|
58
|
+
}
|
|
58
59
|
}
|
package/src/CommandManager.ts
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
import { EditorState, Transaction } from '
|
|
1
|
+
import { EditorState, Transaction } from '@tiptap/pm/state'
|
|
2
2
|
|
|
3
3
|
import { Editor } from './Editor'
|
|
4
4
|
import { createChainableState } from './helpers/createChainableState'
|
|
5
5
|
import {
|
|
6
|
-
AnyCommands,
|
|
7
|
-
CanCommands,
|
|
8
|
-
ChainedCommands,
|
|
9
|
-
CommandProps,
|
|
10
|
-
SingleCommands,
|
|
6
|
+
AnyCommands, CanCommands, ChainedCommands, CommandProps, SingleCommands,
|
|
11
7
|
} from './types'
|
|
12
8
|
|
|
13
9
|
export class CommandManager {
|
|
14
|
-
|
|
15
10
|
editor: Editor
|
|
16
11
|
|
|
17
12
|
rawCommands: AnyCommands
|
|
18
13
|
|
|
19
14
|
customState?: EditorState
|
|
20
15
|
|
|
21
|
-
constructor(props: {
|
|
22
|
-
editor: Editor,
|
|
23
|
-
state?: EditorState,
|
|
24
|
-
}) {
|
|
16
|
+
constructor(props: { editor: Editor; state?: EditorState }) {
|
|
25
17
|
this.editor = props.editor
|
|
26
18
|
this.rawCommands = this.editor.extensionManager.commands
|
|
27
19
|
this.customState = props.state
|
|
@@ -41,9 +33,8 @@ export class CommandManager {
|
|
|
41
33
|
const { tr } = state
|
|
42
34
|
const props = this.buildProps(tr)
|
|
43
35
|
|
|
44
|
-
return Object.fromEntries(
|
|
45
|
-
.entries(rawCommands)
|
|
46
|
-
.map(([name, command]) => {
|
|
36
|
+
return Object.fromEntries(
|
|
37
|
+
Object.entries(rawCommands).map(([name, command]) => {
|
|
47
38
|
const method = (...args: any[]) => {
|
|
48
39
|
const callback = command(...args)(props)
|
|
49
40
|
|
|
@@ -55,7 +46,8 @@ export class CommandManager {
|
|
|
55
46
|
}
|
|
56
47
|
|
|
57
48
|
return [name, method]
|
|
58
|
-
})
|
|
49
|
+
}),
|
|
50
|
+
) as unknown as SingleCommands
|
|
59
51
|
}
|
|
60
52
|
|
|
61
53
|
get chain(): () => ChainedCommands {
|
|
@@ -87,18 +79,20 @@ export class CommandManager {
|
|
|
87
79
|
}
|
|
88
80
|
|
|
89
81
|
const chain = {
|
|
90
|
-
...Object.fromEntries(
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
82
|
+
...Object.fromEntries(
|
|
83
|
+
Object.entries(rawCommands).map(([name, command]) => {
|
|
84
|
+
const chainedCommand = (...args: never[]) => {
|
|
85
|
+
const props = this.buildProps(tr, shouldDispatch)
|
|
86
|
+
const callback = command(...args)(props)
|
|
94
87
|
|
|
95
|
-
|
|
88
|
+
callbacks.push(callback)
|
|
96
89
|
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
return chain
|
|
91
|
+
}
|
|
99
92
|
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
return [name, chainedCommand]
|
|
94
|
+
}),
|
|
95
|
+
),
|
|
102
96
|
run,
|
|
103
97
|
} as unknown as ChainedCommands
|
|
104
98
|
|
|
@@ -110,11 +104,11 @@ export class CommandManager {
|
|
|
110
104
|
const dispatch = false
|
|
111
105
|
const tr = startTr || state.tr
|
|
112
106
|
const props = this.buildProps(tr, dispatch)
|
|
113
|
-
const formattedCommands = Object.fromEntries(
|
|
114
|
-
.entries(rawCommands)
|
|
115
|
-
.map(([name, command]) => {
|
|
107
|
+
const formattedCommands = Object.fromEntries(
|
|
108
|
+
Object.entries(rawCommands).map(([name, command]) => {
|
|
116
109
|
return [name, (...args: never[]) => command(...args)({ ...props, dispatch: undefined })]
|
|
117
|
-
})
|
|
110
|
+
}),
|
|
111
|
+
) as unknown as SingleCommands
|
|
118
112
|
|
|
119
113
|
return {
|
|
120
114
|
...formattedCommands,
|
|
@@ -138,21 +132,18 @@ export class CommandManager {
|
|
|
138
132
|
state,
|
|
139
133
|
transaction: tr,
|
|
140
134
|
}),
|
|
141
|
-
dispatch: shouldDispatch
|
|
142
|
-
? () => undefined
|
|
143
|
-
: undefined,
|
|
135
|
+
dispatch: shouldDispatch ? () => undefined : undefined,
|
|
144
136
|
chain: () => this.createChain(tr),
|
|
145
137
|
can: () => this.createCan(tr),
|
|
146
138
|
get commands() {
|
|
147
|
-
return Object.fromEntries(
|
|
148
|
-
.entries(rawCommands)
|
|
149
|
-
.map(([name, command]) => {
|
|
139
|
+
return Object.fromEntries(
|
|
140
|
+
Object.entries(rawCommands).map(([name, command]) => {
|
|
150
141
|
return [name, (...args: never[]) => command(...args)(props)]
|
|
151
|
-
})
|
|
142
|
+
}),
|
|
143
|
+
) as unknown as SingleCommands
|
|
152
144
|
},
|
|
153
145
|
}
|
|
154
146
|
|
|
155
147
|
return props
|
|
156
148
|
}
|
|
157
|
-
|
|
158
149
|
}
|
package/src/Editor.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { MarkType, NodeType, Schema } from '
|
|
1
|
+
import { MarkType, NodeType, Schema } from '@tiptap/pm/model'
|
|
2
2
|
import {
|
|
3
|
-
EditorState,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Transaction,
|
|
7
|
-
} from 'prosemirror-state'
|
|
8
|
-
import { EditorView } from 'prosemirror-view'
|
|
3
|
+
EditorState, Plugin, PluginKey, Transaction,
|
|
4
|
+
} from '@tiptap/pm/state'
|
|
5
|
+
import { EditorView } from '@tiptap/pm/view'
|
|
9
6
|
|
|
10
7
|
import { CommandManager } from './CommandManager'
|
|
11
8
|
import { EventEmitter } from './EventEmitter'
|
|
@@ -39,7 +36,6 @@ export interface HTMLElement {
|
|
|
39
36
|
}
|
|
40
37
|
|
|
41
38
|
export class Editor extends EventEmitter<EditorEvents> {
|
|
42
|
-
|
|
43
39
|
private commandManager!: CommandManager
|
|
44
40
|
|
|
45
41
|
public extensionManager!: ExtensionManager
|
|
@@ -167,9 +163,12 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
167
163
|
/**
|
|
168
164
|
* Update editable state of the editor.
|
|
169
165
|
*/
|
|
170
|
-
public setEditable(editable: boolean): void {
|
|
166
|
+
public setEditable(editable: boolean, emitUpdate = true): void {
|
|
171
167
|
this.setOptions({ editable })
|
|
172
|
-
|
|
168
|
+
|
|
169
|
+
if (emitUpdate) {
|
|
170
|
+
this.emit('update', { editor: this, transaction: this.state.tr })
|
|
171
|
+
}
|
|
173
172
|
}
|
|
174
173
|
|
|
175
174
|
/**
|
|
@@ -179,9 +178,7 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
179
178
|
// since plugins are applied after creating the view
|
|
180
179
|
// `editable` is always `true` for one tick.
|
|
181
180
|
// that’s why we also have to check for `options.editable`
|
|
182
|
-
return this.options.editable
|
|
183
|
-
&& this.view
|
|
184
|
-
&& this.view.editable
|
|
181
|
+
return this.options.editable && this.view && this.view.editable
|
|
185
182
|
}
|
|
186
183
|
|
|
187
184
|
/**
|
|
@@ -197,7 +194,10 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
197
194
|
* @param plugin A ProseMirror plugin
|
|
198
195
|
* @param handlePlugins Control how to merge the plugin into the existing plugins.
|
|
199
196
|
*/
|
|
200
|
-
public registerPlugin(
|
|
197
|
+
public registerPlugin(
|
|
198
|
+
plugin: Plugin,
|
|
199
|
+
handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[],
|
|
200
|
+
): void {
|
|
201
201
|
const plugins = isFunction(handlePlugins)
|
|
202
202
|
? handlePlugins(plugin, [...this.state.plugins])
|
|
203
203
|
: [...this.state.plugins, plugin]
|
|
@@ -217,10 +217,8 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
217
217
|
return
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
// @ts-ignore
|
|
223
|
-
: nameOrPluginKey.key
|
|
220
|
+
// @ts-ignore
|
|
221
|
+
const name = typeof nameOrPluginKey === 'string' ? `${nameOrPluginKey}$` : nameOrPluginKey.key
|
|
224
222
|
|
|
225
223
|
const state = this.state.reconfigure({
|
|
226
224
|
// @ts-ignore
|
|
@@ -234,9 +232,7 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
234
232
|
* Creates an extension manager.
|
|
235
233
|
*/
|
|
236
234
|
private createExtensionManager(): void {
|
|
237
|
-
const coreExtensions = this.options.enableCoreExtensions
|
|
238
|
-
? Object.values(extensions)
|
|
239
|
-
: []
|
|
235
|
+
const coreExtensions = this.options.enableCoreExtensions ? Object.values(extensions) : []
|
|
240
236
|
const allExtensions = [...coreExtensions, ...this.options.extensions].filter(extension => {
|
|
241
237
|
return ['extension', 'node', 'mark'].includes(extension?.type)
|
|
242
238
|
})
|
|
@@ -394,16 +390,12 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
394
390
|
* @param name Name of the node or mark
|
|
395
391
|
* @param attributes Attributes of the node or mark
|
|
396
392
|
*/
|
|
397
|
-
public isActive(name: string, attributes?: {}): boolean
|
|
398
|
-
public isActive(attributes: {}): boolean
|
|
393
|
+
public isActive(name: string, attributes?: {}): boolean
|
|
394
|
+
public isActive(attributes: {}): boolean
|
|
399
395
|
public isActive(nameOrAttributes: string, attributesOrUndefined?: {}): boolean {
|
|
400
|
-
const name = typeof nameOrAttributes === 'string'
|
|
401
|
-
? nameOrAttributes
|
|
402
|
-
: null
|
|
396
|
+
const name = typeof nameOrAttributes === 'string' ? nameOrAttributes : null
|
|
403
397
|
|
|
404
|
-
const attributes = typeof nameOrAttributes === 'string'
|
|
405
|
-
? attributesOrUndefined
|
|
406
|
-
: nameOrAttributes
|
|
398
|
+
const attributes = typeof nameOrAttributes === 'string' ? attributesOrUndefined : nameOrAttributes
|
|
407
399
|
|
|
408
400
|
return isActive(this.state, name, attributes)
|
|
409
401
|
}
|
|
@@ -426,13 +418,10 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
426
418
|
* Get the document as text.
|
|
427
419
|
*/
|
|
428
420
|
public getText(options?: {
|
|
429
|
-
blockSeparator?: string
|
|
430
|
-
textSerializers?: Record<string, TextSerializer
|
|
421
|
+
blockSeparator?: string
|
|
422
|
+
textSerializers?: Record<string, TextSerializer>
|
|
431
423
|
}): string {
|
|
432
|
-
const {
|
|
433
|
-
blockSeparator = '\n\n',
|
|
434
|
-
textSerializers = {},
|
|
435
|
-
} = options || {}
|
|
424
|
+
const { blockSeparator = '\n\n', textSerializers = {} } = options || {}
|
|
436
425
|
|
|
437
426
|
return getText(this.state.doc, {
|
|
438
427
|
blockSeparator,
|
|
@@ -456,7 +445,9 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
456
445
|
* @deprecated
|
|
457
446
|
*/
|
|
458
447
|
public getCharacterCount(): number {
|
|
459
|
-
console.warn(
|
|
448
|
+
console.warn(
|
|
449
|
+
'[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.',
|
|
450
|
+
)
|
|
460
451
|
|
|
461
452
|
return this.state.doc.content.size - 2
|
|
462
453
|
}
|
|
@@ -481,5 +472,4 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
481
472
|
// @ts-ignore
|
|
482
473
|
return !this.view?.docView
|
|
483
474
|
}
|
|
484
|
-
|
|
485
475
|
}
|