@tiptap/core 2.0.0-beta.99 → 2.0.0-rc.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/README.md +3 -3
- package/dist/index.cjs +4360 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{tiptap-core.esm.js → index.js} +2349 -1447
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +4358 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/packages/core/src/CommandManager.d.ts +14 -7
- package/dist/packages/core/src/Editor.d.ts +25 -11
- package/dist/packages/core/src/EventEmitter.d.ts +8 -4
- package/dist/packages/core/src/Extension.d.ts +63 -29
- package/dist/packages/core/src/ExtensionManager.d.ts +3 -4
- package/dist/packages/core/src/InputRule.d.ts +42 -0
- package/dist/packages/core/src/Mark.d.ts +94 -36
- package/dist/packages/core/src/Node.d.ts +104 -45
- package/dist/packages/core/src/NodeView.d.ts +8 -8
- package/dist/packages/core/src/PasteRule.d.ts +42 -0
- package/dist/packages/core/src/Tracker.d.ts +1 -1
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +12 -0
- package/dist/packages/core/src/commands/deleteNode.d.ts +1 -1
- package/dist/packages/core/src/commands/deleteRange.d.ts +1 -1
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +1 -1
- package/dist/packages/core/src/commands/focus.d.ts +4 -2
- package/dist/packages/core/src/commands/index.d.ts +50 -0
- package/dist/packages/core/src/commands/insertContent.d.ts +6 -3
- package/dist/packages/core/src/commands/insertContentAt.d.ts +6 -3
- package/dist/packages/core/src/commands/join.d.ts +33 -0
- package/dist/packages/core/src/commands/lift.d.ts +1 -1
- package/dist/packages/core/src/commands/liftListItem.d.ts +1 -1
- package/dist/packages/core/src/commands/resetAttributes.d.ts +1 -1
- 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 +2 -2
- package/dist/packages/core/src/commands/setMark.d.ts +1 -1
- package/dist/packages/core/src/commands/setNode.d.ts +1 -1
- package/dist/packages/core/src/commands/setTextSelection.d.ts +1 -1
- package/dist/packages/core/src/commands/sinkListItem.d.ts +1 -1
- package/dist/packages/core/src/commands/splitListItem.d.ts +1 -1
- package/dist/packages/core/src/commands/toggleList.d.ts +2 -2
- package/dist/packages/core/src/commands/toggleMark.d.ts +7 -2
- package/dist/packages/core/src/commands/toggleNode.d.ts +1 -1
- package/dist/packages/core/src/commands/toggleWrap.d.ts +1 -1
- package/dist/packages/core/src/commands/unsetMark.d.ts +7 -2
- package/dist/packages/core/src/commands/updateAttributes.d.ts +1 -1
- package/dist/packages/core/src/commands/wrapIn.d.ts +1 -1
- package/dist/packages/core/src/commands/wrapInList.d.ts +1 -1
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +1 -1
- package/dist/packages/core/src/extensions/commands.d.ts +2 -97
- 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 +2 -2
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +2 -2
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +2 -0
- package/dist/packages/core/src/helpers/findChildren.d.ts +3 -3
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +3 -3
- package/dist/packages/core/src/helpers/findParentNode.d.ts +3 -4
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +3 -3
- package/dist/packages/core/src/helpers/generateHTML.d.ts +1 -1
- package/dist/packages/core/src/helpers/generateJSON.d.ts +1 -1
- package/dist/packages/core/src/helpers/generateText.d.ts +5 -0
- package/dist/packages/core/src/helpers/getAttributes.d.ts +3 -3
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +2 -2
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +11 -0
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +2 -5
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +2 -2
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +2 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +3 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +2 -2
- package/dist/packages/core/src/helpers/getMarkType.d.ts +2 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +2 -2
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +3 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +2 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +2 -2
- package/dist/packages/core/src/helpers/getSchema.d.ts +2 -2
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +2 -2
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +2 -2
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +2 -2
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +1 -1
- 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/getTextContentFromNodes.d.ts +2 -0
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +3 -0
- package/dist/packages/core/src/helpers/index.d.ts +47 -0
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +2 -2
- package/dist/packages/core/src/helpers/isActive.d.ts +2 -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 +3 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +3 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +2 -2
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +2 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +2 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +2 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +4 -0
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +2 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +6 -6
- package/dist/packages/core/src/index.d.ts +12 -34
- package/dist/packages/core/src/inputRules/index.d.ts +5 -0
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +12 -3
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +12 -3
- 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 +27 -0
- package/dist/packages/core/src/pasteRules/index.d.ts +3 -0
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +12 -3
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +12 -0
- 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 +70 -40
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +1 -1
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +1 -1
- 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/index.d.ts +20 -0
- 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/isPlainObject.d.ts +1 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +1 -0
- package/dist/packages/core/src/utilities/isString.d.ts +1 -0
- package/dist/packages/core/src/utilities/isiOS.d.ts +1 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +1 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +1 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +1 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +3 -1
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +8 -0
- package/package.json +25 -24
- package/src/CommandManager.ts +73 -83
- package/src/Editor.ts +101 -53
- package/src/EventEmitter.ts +14 -4
- package/src/Extension.ts +244 -138
- package/src/ExtensionManager.ts +153 -152
- package/src/InputRule.ts +260 -0
- package/src/Mark.ts +365 -204
- package/src/Node.ts +406 -253
- package/src/NodeView.ts +59 -38
- package/src/PasteRule.ts +240 -0
- package/src/Tracker.ts +4 -8
- package/src/commands/blur.ts +4 -0
- package/src/commands/clearNodes.ts +15 -9
- package/src/commands/createParagraphNear.ts +3 -2
- package/src/commands/deleteCurrentNode.ts +41 -0
- package/src/commands/deleteNode.ts +3 -2
- package/src/commands/deleteRange.ts +1 -1
- package/src/commands/deleteSelection.ts +3 -2
- package/src/commands/exitCode.ts +3 -2
- package/src/commands/extendMarkRange.ts +9 -5
- package/src/commands/focus.ts +31 -42
- package/src/commands/index.ts +50 -0
- package/src/commands/insertContent.ts +15 -4
- package/src/commands/insertContentAt.ts +71 -14
- package/src/commands/join.ts +53 -0
- package/src/commands/keyboardShortcut.ts +3 -3
- package/src/commands/lift.ts +6 -5
- package/src/commands/liftEmptyBlock.ts +2 -1
- package/src/commands/liftListItem.ts +5 -4
- package/src/commands/newlineInCode.ts +3 -2
- package/src/commands/resetAttributes.ts +16 -10
- package/src/commands/selectAll.ts +5 -3
- package/src/commands/selectNodeBackward.ts +3 -2
- package/src/commands/selectNodeForward.ts +3 -2
- package/src/commands/selectParentNode.ts +3 -2
- package/src/commands/selectTextblockEnd.ts +20 -0
- package/src/commands/selectTextblockStart.ts +20 -0
- package/src/commands/setContent.ts +6 -9
- package/src/commands/setMark.ts +66 -13
- package/src/commands/setNode.ts +30 -6
- package/src/commands/setNodeSelection.ts +6 -7
- package/src/commands/setTextSelection.ts +8 -9
- package/src/commands/sinkListItem.ts +5 -4
- package/src/commands/splitBlock.ts +23 -38
- package/src/commands/splitListItem.ts +30 -27
- package/src/commands/toggleList.ts +108 -19
- package/src/commands/toggleMark.ts +17 -6
- package/src/commands/toggleNode.ts +9 -4
- package/src/commands/toggleWrap.ts +8 -8
- package/src/commands/undoInputRule.ts +31 -2
- package/src/commands/unsetAllMarks.ts +4 -8
- package/src/commands/unsetMark.ts +34 -21
- package/src/commands/updateAttributes.ts +18 -12
- package/src/commands/wrapIn.ts +5 -10
- package/src/commands/wrapInList.ts +5 -4
- package/src/extensions/clipboardTextSerializer.ts +15 -36
- package/src/extensions/commands.ts +3 -144
- package/src/extensions/editable.ts +2 -1
- package/src/extensions/focusEvents.ts +4 -6
- package/src/extensions/index.ts +1 -0
- package/src/extensions/keymap.ts +111 -13
- package/src/extensions/tabindex.ts +18 -0
- package/src/helpers/combineTransactionSteps.ts +21 -0
- package/src/helpers/createChainableState.ts +38 -0
- package/src/helpers/createDocument.ts +4 -3
- package/src/helpers/createNodeFromContent.ts +10 -15
- package/src/helpers/defaultBlockAt.ts +13 -0
- package/src/helpers/findChildren.ts +4 -3
- package/src/helpers/findChildrenInRange.ts +8 -3
- package/src/helpers/findParentNode.ts +4 -3
- package/src/helpers/findParentNodeClosestToPos.ts +13 -7
- package/src/helpers/generateHTML.ts +6 -5
- package/src/helpers/generateJSON.ts +6 -7
- package/src/helpers/generateText.ts +27 -0
- package/src/helpers/getAttributes.ts +8 -9
- package/src/helpers/getAttributesFromExtensions.ts +25 -12
- package/src/helpers/getChangedRanges.ts +83 -0
- package/src/helpers/getDebugJSON.ts +42 -38
- package/src/helpers/getExtensionField.ts +3 -3
- package/src/helpers/getHTMLFromFragment.ts +5 -6
- package/src/helpers/getMarkAttributes.ts +18 -10
- package/src/helpers/getMarkRange.ts +13 -8
- package/src/helpers/getMarkType.ts +5 -3
- package/src/helpers/getMarksBetween.ts +34 -10
- package/src/helpers/getNodeAttributes.ts +14 -12
- package/src/helpers/getNodeType.ts +5 -3
- package/src/helpers/getRenderedAttributes.ts +8 -6
- package/src/helpers/getSchema.ts +5 -4
- package/src/helpers/getSchemaByResolvedExtensions.ts +165 -111
- package/src/helpers/getSchemaTypeByName.ts +3 -11
- package/src/helpers/getSchemaTypeNameByName.ts +2 -2
- package/src/helpers/getSplittedAttributes.ts +1 -1
- package/src/helpers/getText.ts +19 -0
- package/src/helpers/getTextBetween.ts +46 -0
- package/src/helpers/getTextContentFromNodes.ts +26 -0
- package/src/helpers/getTextSerializersFromSchema.ts +11 -0
- package/src/helpers/index.ts +47 -0
- package/src/helpers/injectExtensionAttributesToParseRule.ts +22 -23
- package/src/helpers/isActive.ts +10 -5
- package/src/helpers/isExtensionRulesEnabled.ts +15 -0
- package/src/helpers/isList.ts +6 -5
- package/src/helpers/isMarkActive.ts +32 -35
- package/src/helpers/isNodeActive.ts +27 -37
- package/src/helpers/isNodeEmpty.ts +2 -2
- package/src/helpers/isNodeSelection.ts +3 -4
- package/src/helpers/isTextSelection.ts +3 -4
- package/src/helpers/posToDOMRect.ts +10 -4
- package/src/helpers/resolveFocusPosition.ts +42 -0
- package/src/helpers/selectionToInsertionEnd.ts +3 -3
- package/src/helpers/splitExtensions.ts +3 -3
- package/src/index.ts +12 -37
- package/src/inputRules/index.ts +5 -0
- package/src/inputRules/markInputRule.ts +59 -40
- package/src/inputRules/nodeInputRule.ts +45 -12
- package/src/inputRules/textInputRule.ts +35 -0
- package/src/inputRules/textblockTypeInputRule.ts +37 -0
- package/src/inputRules/wrappingInputRule.ts +84 -0
- package/src/pasteRules/index.ts +3 -0
- package/src/pasteRules/markPasteRule.ts +49 -56
- package/src/pasteRules/nodePasteRule.ts +37 -0
- package/src/pasteRules/textPasteRule.ts +35 -0
- package/src/style.ts +12 -3
- package/src/types.ts +140 -106
- package/src/utilities/callOrReturn.ts +3 -2
- package/src/utilities/createStyleTag.ts +8 -4
- package/src/utilities/deleteProps.ts +1 -1
- package/src/utilities/elementFromString.ts +1 -1
- package/src/utilities/escapeForRegEx.ts +4 -0
- package/src/utilities/findDuplicates.ts +5 -0
- package/src/utilities/fromString.ts +2 -2
- package/src/utilities/index.ts +20 -0
- 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/isPlainObject.ts +8 -5
- package/src/utilities/isRegExp.ts +3 -0
- package/src/utilities/isString.ts +3 -0
- package/src/utilities/isiOS.ts +1 -1
- package/src/utilities/mergeAttributes.ts +2 -1
- package/src/utilities/mergeDeep.ts +2 -2
- package/src/utilities/minMax.ts +1 -1
- package/src/utilities/objectIncludes.ts +18 -4
- package/src/utilities/removeDuplicates.ts +15 -0
- package/CHANGELOG.md +0 -1190
- package/LICENSE.md +0 -21
- package/dist/packages/core/src/commands/joinBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinForward.d.ts +0 -12
- package/dist/packages/core/src/utilities/isClass.d.ts +0 -1
- package/dist/packages/core/src/utilities/isObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/removeElement.d.ts +0 -1
- package/dist/tiptap-core.cjs.js +0 -3408
- package/dist/tiptap-core.cjs.js.map +0 -1
- package/dist/tiptap-core.esm.js.map +0 -1
- package/dist/tiptap-core.umd.js +0 -3405
- package/dist/tiptap-core.umd.js.map +0 -1
- package/src/commands/joinBackward.ts +0 -17
- package/src/commands/joinForward.ts +0 -17
- package/src/utilities/isClass.ts +0 -7
- package/src/utilities/isObject.ts +0 -10
- package/src/utilities/removeElement.ts +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function mergeAttributes(...objects: Record<string, any>[]): Record<string, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function mergeDeep(target: Record<string, any>, source: Record<string, any>): Record<string, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function minMax(value?: number, min?: number, max?: number): number;
|
|
@@ -3,4 +3,6 @@
|
|
|
3
3
|
* @param object1 Object
|
|
4
4
|
* @param object2 Object
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export declare function objectIncludes(object1: Record<string, any>, object2: Record<string, any>, options?: {
|
|
7
|
+
strict: boolean;
|
|
8
|
+
}): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes duplicated values within an array.
|
|
3
|
+
* Supports numbers, strings and objects.
|
|
4
|
+
*/
|
|
5
|
+
export declare function removeDuplicates<T>(array: T[], by?: {
|
|
6
|
+
(value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
|
|
7
|
+
(value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
|
|
8
|
+
}): T[];
|
package/package.json
CHANGED
|
@@ -1,49 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/core",
|
|
3
3
|
"description": "headless rich text editor",
|
|
4
|
-
"version": "2.0.0-
|
|
4
|
+
"version": "2.0.0-rc.1",
|
|
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": {
|
|
14
15
|
"type": "github",
|
|
15
16
|
"url": "https://github.com/sponsors/ueberdosis"
|
|
16
17
|
},
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/packages/core/src/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"main": "dist/index.cjs",
|
|
27
|
+
"module": "dist/index.js",
|
|
28
|
+
"umd": "dist/index.umd.js",
|
|
20
29
|
"types": "dist/packages/core/src/index.d.ts",
|
|
21
30
|
"files": [
|
|
22
31
|
"src",
|
|
23
32
|
"dist"
|
|
24
33
|
],
|
|
25
|
-
"
|
|
26
|
-
"@
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"@
|
|
30
|
-
"@types/prosemirror-schema-list": "^1.0.3",
|
|
31
|
-
"@types/prosemirror-state": "^1.2.7",
|
|
32
|
-
"@types/prosemirror-transform": "^1.1.4",
|
|
33
|
-
"@types/prosemirror-view": "^1.17.2",
|
|
34
|
-
"prosemirror-commands": "^1.1.10",
|
|
35
|
-
"prosemirror-inputrules": "^1.1.3",
|
|
36
|
-
"prosemirror-keymap": "^1.1.3",
|
|
37
|
-
"prosemirror-model": "^1.14.3",
|
|
38
|
-
"prosemirror-schema-list": "^1.1.5",
|
|
39
|
-
"prosemirror-state": "^1.3.4",
|
|
40
|
-
"prosemirror-transform": "^1.3.2",
|
|
41
|
-
"prosemirror-view": "^1.19.0"
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@tiptap/pm": "2.0.0-rc.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@tiptap/pm": "2.0.0-rc.1"
|
|
42
39
|
},
|
|
43
40
|
"repository": {
|
|
44
41
|
"type": "git",
|
|
45
42
|
"url": "https://github.com/ueberdosis/tiptap",
|
|
46
43
|
"directory": "packages/core"
|
|
47
44
|
},
|
|
48
|
-
"
|
|
49
|
-
|
|
45
|
+
"sideEffects": false,
|
|
46
|
+
"scripts": {
|
|
47
|
+
"clean": "rm -rf dist",
|
|
48
|
+
"build": "npm run clean && rollup -c"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/CommandManager.ts
CHANGED
|
@@ -1,37 +1,44 @@
|
|
|
1
|
-
import { EditorState, Transaction } from '
|
|
1
|
+
import { EditorState, Transaction } from '@tiptap/pm/state'
|
|
2
|
+
|
|
2
3
|
import { Editor } from './Editor'
|
|
4
|
+
import { createChainableState } from './helpers/createChainableState'
|
|
3
5
|
import {
|
|
4
|
-
SingleCommands,
|
|
5
|
-
ChainedCommands,
|
|
6
|
-
CanCommands,
|
|
7
|
-
AnyCommands,
|
|
8
|
-
CommandProps,
|
|
6
|
+
AnyCommands, CanCommands, ChainedCommands, CommandProps, SingleCommands,
|
|
9
7
|
} from './types'
|
|
10
8
|
|
|
11
|
-
export
|
|
12
|
-
|
|
9
|
+
export class CommandManager {
|
|
13
10
|
editor: Editor
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
rawCommands: AnyCommands
|
|
13
|
+
|
|
14
|
+
customState?: EditorState
|
|
15
|
+
|
|
16
|
+
constructor(props: { editor: Editor; state?: EditorState }) {
|
|
17
|
+
this.editor = props.editor
|
|
18
|
+
this.rawCommands = this.editor.extensionManager.commands
|
|
19
|
+
this.customState = props.state
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get hasCustomState(): boolean {
|
|
23
|
+
return !!this.customState
|
|
24
|
+
}
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
-
this.commands = commands
|
|
26
|
+
get state(): EditorState {
|
|
27
|
+
return this.customState || this.editor.state
|
|
20
28
|
}
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
const {
|
|
24
|
-
const {
|
|
30
|
+
get commands(): SingleCommands {
|
|
31
|
+
const { rawCommands, editor, state } = this
|
|
32
|
+
const { view } = editor
|
|
25
33
|
const { tr } = state
|
|
26
34
|
const props = this.buildProps(tr)
|
|
27
35
|
|
|
28
|
-
return Object.fromEntries(
|
|
29
|
-
.entries(
|
|
30
|
-
.map(([name, command]) => {
|
|
36
|
+
return Object.fromEntries(
|
|
37
|
+
Object.entries(rawCommands).map(([name, command]) => {
|
|
31
38
|
const method = (...args: any[]) => {
|
|
32
39
|
const callback = command(...args)(props)
|
|
33
40
|
|
|
34
|
-
if (!tr.getMeta('preventDispatch')) {
|
|
41
|
+
if (!tr.getMeta('preventDispatch') && !this.hasCustomState) {
|
|
35
42
|
view.dispatch(tr)
|
|
36
43
|
}
|
|
37
44
|
|
|
@@ -39,18 +46,32 @@ export default class CommandManager {
|
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
return [name, method]
|
|
42
|
-
})
|
|
49
|
+
}),
|
|
50
|
+
) as unknown as SingleCommands
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get chain(): () => ChainedCommands {
|
|
54
|
+
return () => this.createChain()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get can(): () => CanCommands {
|
|
58
|
+
return () => this.createCan()
|
|
43
59
|
}
|
|
44
60
|
|
|
45
61
|
public createChain(startTr?: Transaction, shouldDispatch = true): ChainedCommands {
|
|
46
|
-
const {
|
|
47
|
-
const {
|
|
62
|
+
const { rawCommands, editor, state } = this
|
|
63
|
+
const { view } = editor
|
|
48
64
|
const callbacks: boolean[] = []
|
|
49
65
|
const hasStartTransaction = !!startTr
|
|
50
66
|
const tr = startTr || state.tr
|
|
51
67
|
|
|
52
68
|
const run = () => {
|
|
53
|
-
if (
|
|
69
|
+
if (
|
|
70
|
+
!hasStartTransaction
|
|
71
|
+
&& shouldDispatch
|
|
72
|
+
&& !tr.getMeta('preventDispatch')
|
|
73
|
+
&& !this.hasCustomState
|
|
74
|
+
) {
|
|
54
75
|
view.dispatch(tr)
|
|
55
76
|
}
|
|
56
77
|
|
|
@@ -58,18 +79,20 @@ export default class CommandManager {
|
|
|
58
79
|
}
|
|
59
80
|
|
|
60
81
|
const chain = {
|
|
61
|
-
...Object.fromEntries(
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
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)
|
|
65
87
|
|
|
66
|
-
|
|
88
|
+
callbacks.push(callback)
|
|
67
89
|
|
|
68
|
-
|
|
69
|
-
|
|
90
|
+
return chain
|
|
91
|
+
}
|
|
70
92
|
|
|
71
|
-
|
|
72
|
-
|
|
93
|
+
return [name, chainedCommand]
|
|
94
|
+
}),
|
|
95
|
+
),
|
|
73
96
|
run,
|
|
74
97
|
} as unknown as ChainedCommands
|
|
75
98
|
|
|
@@ -77,16 +100,15 @@ export default class CommandManager {
|
|
|
77
100
|
}
|
|
78
101
|
|
|
79
102
|
public createCan(startTr?: Transaction): CanCommands {
|
|
80
|
-
const {
|
|
81
|
-
const
|
|
82
|
-
const dispatch = undefined
|
|
103
|
+
const { rawCommands, state } = this
|
|
104
|
+
const dispatch = false
|
|
83
105
|
const tr = startTr || state.tr
|
|
84
106
|
const props = this.buildProps(tr, dispatch)
|
|
85
|
-
const formattedCommands = Object.fromEntries(
|
|
86
|
-
.entries(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
107
|
+
const formattedCommands = Object.fromEntries(
|
|
108
|
+
Object.entries(rawCommands).map(([name, command]) => {
|
|
109
|
+
return [name, (...args: never[]) => command(...args)({ ...props, dispatch: undefined })]
|
|
110
|
+
}),
|
|
111
|
+
) as unknown as SingleCommands
|
|
90
112
|
|
|
91
113
|
return {
|
|
92
114
|
...formattedCommands,
|
|
@@ -95,8 +117,8 @@ export default class CommandManager {
|
|
|
95
117
|
}
|
|
96
118
|
|
|
97
119
|
public buildProps(tr: Transaction, shouldDispatch = true): CommandProps {
|
|
98
|
-
const { editor,
|
|
99
|
-
const {
|
|
120
|
+
const { rawCommands, editor, state } = this
|
|
121
|
+
const { view } = editor
|
|
100
122
|
|
|
101
123
|
if (state.storedMarks) {
|
|
102
124
|
tr.setStoredMarks(state.storedMarks)
|
|
@@ -106,54 +128,22 @@ export default class CommandManager {
|
|
|
106
128
|
tr,
|
|
107
129
|
editor,
|
|
108
130
|
view,
|
|
109
|
-
state:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
131
|
+
state: createChainableState({
|
|
132
|
+
state,
|
|
133
|
+
transaction: tr,
|
|
134
|
+
}),
|
|
135
|
+
dispatch: shouldDispatch ? () => undefined : undefined,
|
|
113
136
|
chain: () => this.createChain(tr),
|
|
114
137
|
can: () => this.createCan(tr),
|
|
115
138
|
get commands() {
|
|
116
|
-
return Object.fromEntries(
|
|
117
|
-
.entries(
|
|
118
|
-
.map(([name, command]) => {
|
|
139
|
+
return Object.fromEntries(
|
|
140
|
+
Object.entries(rawCommands).map(([name, command]) => {
|
|
119
141
|
return [name, (...args: never[]) => command(...args)(props)]
|
|
120
|
-
})
|
|
142
|
+
}),
|
|
143
|
+
) as unknown as SingleCommands
|
|
121
144
|
},
|
|
122
145
|
}
|
|
123
146
|
|
|
124
147
|
return props
|
|
125
148
|
}
|
|
126
|
-
|
|
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
149
|
}
|
package/src/Editor.ts
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
|
+
import { MarkType, NodeType, Schema } from '@tiptap/pm/model'
|
|
1
2
|
import {
|
|
2
|
-
EditorState,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from '
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
3
|
+
EditorState, Plugin, PluginKey, Transaction,
|
|
4
|
+
} from '@tiptap/pm/state'
|
|
5
|
+
import { EditorView } from '@tiptap/pm/view'
|
|
6
|
+
|
|
7
|
+
import { CommandManager } from './CommandManager'
|
|
8
|
+
import { EventEmitter } from './EventEmitter'
|
|
9
|
+
import { ExtensionManager } from './ExtensionManager'
|
|
10
|
+
import * as extensions from './extensions'
|
|
11
|
+
import { createDocument } from './helpers/createDocument'
|
|
12
|
+
import { getAttributes } from './helpers/getAttributes'
|
|
13
|
+
import { getHTMLFromFragment } from './helpers/getHTMLFromFragment'
|
|
14
|
+
import { getText } from './helpers/getText'
|
|
15
|
+
import { getTextSerializersFromSchema } from './helpers/getTextSerializersFromSchema'
|
|
16
|
+
import { isActive } from './helpers/isActive'
|
|
17
|
+
import { isNodeEmpty } from './helpers/isNodeEmpty'
|
|
18
|
+
import { resolveFocusPosition } from './helpers/resolveFocusPosition'
|
|
19
|
+
import { style } from './style'
|
|
19
20
|
import {
|
|
20
|
-
EditorOptions,
|
|
21
21
|
CanCommands,
|
|
22
22
|
ChainedCommands,
|
|
23
|
+
EditorEvents,
|
|
24
|
+
EditorOptions,
|
|
25
|
+
JSONContent,
|
|
23
26
|
SingleCommands,
|
|
27
|
+
TextSerializer,
|
|
24
28
|
} from './types'
|
|
25
|
-
import
|
|
26
|
-
import
|
|
29
|
+
import { createStyleTag } from './utilities/createStyleTag'
|
|
30
|
+
import { isFunction } from './utilities/isFunction'
|
|
27
31
|
|
|
28
32
|
export { extensions }
|
|
29
33
|
|
|
@@ -31,8 +35,7 @@ export interface HTMLElement {
|
|
|
31
35
|
editor?: Editor
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
export class Editor extends EventEmitter {
|
|
35
|
-
|
|
38
|
+
export class Editor extends EventEmitter<EditorEvents> {
|
|
36
39
|
private commandManager!: CommandManager
|
|
37
40
|
|
|
38
41
|
public extensionManager!: ExtensionManager
|
|
@@ -45,10 +48,13 @@ export class Editor extends EventEmitter {
|
|
|
45
48
|
|
|
46
49
|
public isFocused = false
|
|
47
50
|
|
|
51
|
+
public extensionStorage: Record<string, any> = {}
|
|
52
|
+
|
|
48
53
|
public options: EditorOptions = {
|
|
49
54
|
element: document.createElement('div'),
|
|
50
55
|
content: '',
|
|
51
56
|
injectCSS: true,
|
|
57
|
+
injectNonce: undefined,
|
|
52
58
|
extensions: [],
|
|
53
59
|
autofocus: false,
|
|
54
60
|
editable: true,
|
|
@@ -56,6 +62,7 @@ export class Editor extends EventEmitter {
|
|
|
56
62
|
parseOptions: {},
|
|
57
63
|
enableInputRules: true,
|
|
58
64
|
enablePasteRules: true,
|
|
65
|
+
enableCoreExtensions: true,
|
|
59
66
|
onBeforeCreate: () => null,
|
|
60
67
|
onCreate: () => null,
|
|
61
68
|
onUpdate: () => null,
|
|
@@ -94,25 +101,32 @@ export class Editor extends EventEmitter {
|
|
|
94
101
|
}, 0)
|
|
95
102
|
}
|
|
96
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Returns the editor storage.
|
|
106
|
+
*/
|
|
107
|
+
public get storage(): Record<string, any> {
|
|
108
|
+
return this.extensionStorage
|
|
109
|
+
}
|
|
110
|
+
|
|
97
111
|
/**
|
|
98
112
|
* An object of all registered commands.
|
|
99
113
|
*/
|
|
100
114
|
public get commands(): SingleCommands {
|
|
101
|
-
return this.commandManager.
|
|
115
|
+
return this.commandManager.commands
|
|
102
116
|
}
|
|
103
117
|
|
|
104
118
|
/**
|
|
105
119
|
* Create a command chain to call multiple commands at once.
|
|
106
120
|
*/
|
|
107
121
|
public chain(): ChainedCommands {
|
|
108
|
-
return this.commandManager.
|
|
122
|
+
return this.commandManager.chain()
|
|
109
123
|
}
|
|
110
124
|
|
|
111
125
|
/**
|
|
112
126
|
* Check if a command or a command chain can be executed. Without executing it.
|
|
113
127
|
*/
|
|
114
128
|
public can(): CanCommands {
|
|
115
|
-
return this.commandManager.
|
|
129
|
+
return this.commandManager.can()
|
|
116
130
|
}
|
|
117
131
|
|
|
118
132
|
/**
|
|
@@ -120,7 +134,7 @@ export class Editor extends EventEmitter {
|
|
|
120
134
|
*/
|
|
121
135
|
private injectCSS(): void {
|
|
122
136
|
if (this.options.injectCSS && document) {
|
|
123
|
-
this.css = createStyleTag(style)
|
|
137
|
+
this.css = createStyleTag(style, this.options.injectNonce)
|
|
124
138
|
}
|
|
125
139
|
}
|
|
126
140
|
|
|
@@ -149,8 +163,12 @@ export class Editor extends EventEmitter {
|
|
|
149
163
|
/**
|
|
150
164
|
* Update editable state of the editor.
|
|
151
165
|
*/
|
|
152
|
-
public setEditable(editable: boolean): void {
|
|
166
|
+
public setEditable(editable: boolean, emitUpdate = true): void {
|
|
153
167
|
this.setOptions({ editable })
|
|
168
|
+
|
|
169
|
+
if (emitUpdate) {
|
|
170
|
+
this.emit('update', { editor: this, transaction: this.state.tr })
|
|
171
|
+
}
|
|
154
172
|
}
|
|
155
173
|
|
|
156
174
|
/**
|
|
@@ -160,9 +178,7 @@ export class Editor extends EventEmitter {
|
|
|
160
178
|
// since plugins are applied after creating the view
|
|
161
179
|
// `editable` is always `true` for one tick.
|
|
162
180
|
// that’s why we also have to check for `options.editable`
|
|
163
|
-
return this.options.editable
|
|
164
|
-
&& this.view
|
|
165
|
-
&& this.view.editable
|
|
181
|
+
return this.options.editable && this.view && this.view.editable
|
|
166
182
|
}
|
|
167
183
|
|
|
168
184
|
/**
|
|
@@ -178,9 +194,12 @@ export class Editor extends EventEmitter {
|
|
|
178
194
|
* @param plugin A ProseMirror plugin
|
|
179
195
|
* @param handlePlugins Control how to merge the plugin into the existing plugins.
|
|
180
196
|
*/
|
|
181
|
-
public registerPlugin(
|
|
182
|
-
|
|
183
|
-
|
|
197
|
+
public registerPlugin(
|
|
198
|
+
plugin: Plugin,
|
|
199
|
+
handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[],
|
|
200
|
+
): void {
|
|
201
|
+
const plugins = isFunction(handlePlugins)
|
|
202
|
+
? handlePlugins(plugin, [...this.state.plugins])
|
|
184
203
|
: [...this.state.plugins, plugin]
|
|
185
204
|
|
|
186
205
|
const state = this.state.reconfigure({ plugins })
|
|
@@ -191,17 +210,15 @@ export class Editor extends EventEmitter {
|
|
|
191
210
|
/**
|
|
192
211
|
* Unregister a ProseMirror plugin.
|
|
193
212
|
*
|
|
194
|
-
* @param
|
|
213
|
+
* @param nameOrPluginKey The plugins name
|
|
195
214
|
*/
|
|
196
215
|
public unregisterPlugin(nameOrPluginKey: string | PluginKey): void {
|
|
197
216
|
if (this.isDestroyed) {
|
|
198
217
|
return
|
|
199
218
|
}
|
|
200
219
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
// @ts-ignore
|
|
204
|
-
: nameOrPluginKey.key
|
|
220
|
+
// @ts-ignore
|
|
221
|
+
const name = typeof nameOrPluginKey === 'string' ? `${nameOrPluginKey}$` : nameOrPluginKey.key
|
|
205
222
|
|
|
206
223
|
const state = this.state.reconfigure({
|
|
207
224
|
// @ts-ignore
|
|
@@ -215,7 +232,7 @@ export class Editor extends EventEmitter {
|
|
|
215
232
|
* Creates an extension manager.
|
|
216
233
|
*/
|
|
217
234
|
private createExtensionManager(): void {
|
|
218
|
-
const coreExtensions = Object.
|
|
235
|
+
const coreExtensions = this.options.enableCoreExtensions ? Object.values(extensions) : []
|
|
219
236
|
const allExtensions = [...coreExtensions, ...this.options.extensions].filter(extension => {
|
|
220
237
|
return ['extension', 'node', 'mark'].includes(extension?.type)
|
|
221
238
|
})
|
|
@@ -227,7 +244,9 @@ export class Editor extends EventEmitter {
|
|
|
227
244
|
* Creates an command manager.
|
|
228
245
|
*/
|
|
229
246
|
private createCommandManager(): void {
|
|
230
|
-
this.commandManager = new CommandManager(
|
|
247
|
+
this.commandManager = new CommandManager({
|
|
248
|
+
editor: this,
|
|
249
|
+
})
|
|
231
250
|
}
|
|
232
251
|
|
|
233
252
|
/**
|
|
@@ -241,11 +260,15 @@ export class Editor extends EventEmitter {
|
|
|
241
260
|
* Creates a ProseMirror view.
|
|
242
261
|
*/
|
|
243
262
|
private createView(): void {
|
|
263
|
+
const doc = createDocument(this.options.content, this.schema, this.options.parseOptions)
|
|
264
|
+
const selection = resolveFocusPosition(doc, this.options.autofocus)
|
|
265
|
+
|
|
244
266
|
this.view = new EditorView(this.options.element, {
|
|
245
267
|
...this.options.editorProps,
|
|
246
268
|
dispatchTransaction: this.dispatchTransaction.bind(this),
|
|
247
269
|
state: EditorState.create({
|
|
248
|
-
doc
|
|
270
|
+
doc,
|
|
271
|
+
selection: selection || undefined,
|
|
249
272
|
}),
|
|
250
273
|
})
|
|
251
274
|
|
|
@@ -262,6 +285,7 @@ export class Editor extends EventEmitter {
|
|
|
262
285
|
// Let’s store the editor instance in the DOM element.
|
|
263
286
|
// So we’ll have access to it for tests.
|
|
264
287
|
const dom = this.view.dom as HTMLElement
|
|
288
|
+
|
|
265
289
|
dom.editor = this
|
|
266
290
|
}
|
|
267
291
|
|
|
@@ -296,6 +320,12 @@ export class Editor extends EventEmitter {
|
|
|
296
320
|
* @param transaction An editor state transaction
|
|
297
321
|
*/
|
|
298
322
|
private dispatchTransaction(transaction: Transaction): void {
|
|
323
|
+
// if the editor / the view of the editor was destroyed
|
|
324
|
+
// the transaction should not be dispatched as there is no view anymore.
|
|
325
|
+
if (this.view.isDestroyed) {
|
|
326
|
+
return
|
|
327
|
+
}
|
|
328
|
+
|
|
299
329
|
if (this.isCapturingTransaction) {
|
|
300
330
|
if (!this.capturedTransaction) {
|
|
301
331
|
this.capturedTransaction = transaction
|
|
@@ -366,16 +396,12 @@ export class Editor extends EventEmitter {
|
|
|
366
396
|
* @param name Name of the node or mark
|
|
367
397
|
* @param attributes Attributes of the node or mark
|
|
368
398
|
*/
|
|
369
|
-
public isActive(name: string, attributes?: {}): boolean
|
|
370
|
-
public isActive(attributes: {}): boolean
|
|
399
|
+
public isActive(name: string, attributes?: {}): boolean
|
|
400
|
+
public isActive(attributes: {}): boolean
|
|
371
401
|
public isActive(nameOrAttributes: string, attributesOrUndefined?: {}): boolean {
|
|
372
|
-
const name = typeof nameOrAttributes === 'string'
|
|
373
|
-
? nameOrAttributes
|
|
374
|
-
: null
|
|
402
|
+
const name = typeof nameOrAttributes === 'string' ? nameOrAttributes : null
|
|
375
403
|
|
|
376
|
-
const attributes = typeof nameOrAttributes === 'string'
|
|
377
|
-
? attributesOrUndefined
|
|
378
|
-
: nameOrAttributes
|
|
404
|
+
const attributes = typeof nameOrAttributes === 'string' ? attributesOrUndefined : nameOrAttributes
|
|
379
405
|
|
|
380
406
|
return isActive(this.state, name, attributes)
|
|
381
407
|
}
|
|
@@ -383,7 +409,7 @@ export class Editor extends EventEmitter {
|
|
|
383
409
|
/**
|
|
384
410
|
* Get the document as JSON.
|
|
385
411
|
*/
|
|
386
|
-
public getJSON():
|
|
412
|
+
public getJSON(): JSONContent {
|
|
387
413
|
return this.state.doc.toJSON()
|
|
388
414
|
}
|
|
389
415
|
|
|
@@ -391,7 +417,25 @@ export class Editor extends EventEmitter {
|
|
|
391
417
|
* Get the document as HTML.
|
|
392
418
|
*/
|
|
393
419
|
public getHTML(): string {
|
|
394
|
-
return getHTMLFromFragment(this.state.doc, this.schema)
|
|
420
|
+
return getHTMLFromFragment(this.state.doc.content, this.schema)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Get the document as text.
|
|
425
|
+
*/
|
|
426
|
+
public getText(options?: {
|
|
427
|
+
blockSeparator?: string
|
|
428
|
+
textSerializers?: Record<string, TextSerializer>
|
|
429
|
+
}): string {
|
|
430
|
+
const { blockSeparator = '\n\n', textSerializers = {} } = options || {}
|
|
431
|
+
|
|
432
|
+
return getText(this.state.doc, {
|
|
433
|
+
blockSeparator,
|
|
434
|
+
textSerializers: {
|
|
435
|
+
...getTextSerializersFromSchema(this.schema),
|
|
436
|
+
...textSerializers,
|
|
437
|
+
},
|
|
438
|
+
})
|
|
395
439
|
}
|
|
396
440
|
|
|
397
441
|
/**
|
|
@@ -403,8 +447,14 @@ export class Editor extends EventEmitter {
|
|
|
403
447
|
|
|
404
448
|
/**
|
|
405
449
|
* Get the number of characters for the current document.
|
|
450
|
+
*
|
|
451
|
+
* @deprecated
|
|
406
452
|
*/
|
|
407
453
|
public getCharacterCount(): number {
|
|
454
|
+
console.warn(
|
|
455
|
+
'[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.',
|
|
456
|
+
)
|
|
457
|
+
|
|
408
458
|
return this.state.doc.content.size - 2
|
|
409
459
|
}
|
|
410
460
|
|
|
@@ -419,7 +469,6 @@ export class Editor extends EventEmitter {
|
|
|
419
469
|
}
|
|
420
470
|
|
|
421
471
|
this.removeAllListeners()
|
|
422
|
-
removeElement(this.css)
|
|
423
472
|
}
|
|
424
473
|
|
|
425
474
|
/**
|
|
@@ -429,5 +478,4 @@ export class Editor extends EventEmitter {
|
|
|
429
478
|
// @ts-ignore
|
|
430
479
|
return !this.view?.docView
|
|
431
480
|
}
|
|
432
|
-
|
|
433
481
|
}
|