@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,7 +1,8 @@
|
|
|
1
|
-
import { NodeType } from '
|
|
1
|
+
import { NodeType } from '@tiptap/pm/model'
|
|
2
|
+
|
|
3
|
+
import { getNodeType } from '../helpers/getNodeType'
|
|
4
|
+
import { isNodeActive } from '../helpers/isNodeActive'
|
|
2
5
|
import { RawCommands } from '../types'
|
|
3
|
-
import isNodeActive from '../helpers/isNodeActive'
|
|
4
|
-
import getNodeType from '../helpers/getNodeType'
|
|
5
6
|
|
|
6
7
|
declare module '@tiptap/core' {
|
|
7
8
|
interface Commands<ReturnType> {
|
|
@@ -9,7 +10,11 @@ declare module '@tiptap/core' {
|
|
|
9
10
|
/**
|
|
10
11
|
* Toggle a node with another node.
|
|
11
12
|
*/
|
|
12
|
-
toggleNode: (
|
|
13
|
+
toggleNode: (
|
|
14
|
+
typeOrName: string | NodeType,
|
|
15
|
+
toggleTypeOrName: string | NodeType,
|
|
16
|
+
attributes?: Record<string, any>,
|
|
17
|
+
) => ReturnType
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
20
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { NodeType } from '@tiptap/pm/model'
|
|
2
|
+
|
|
3
|
+
import { getNodeType } from '../helpers/getNodeType'
|
|
4
|
+
import { isNodeActive } from '../helpers/isNodeActive'
|
|
3
5
|
import { RawCommands } from '../types'
|
|
4
|
-
import isNodeActive from '../helpers/isNodeActive'
|
|
5
|
-
import getNodeType from '../helpers/getNodeType'
|
|
6
6
|
|
|
7
7
|
declare module '@tiptap/core' {
|
|
8
8
|
interface Commands<ReturnType> {
|
|
@@ -10,18 +10,18 @@ declare module '@tiptap/core' {
|
|
|
10
10
|
/**
|
|
11
11
|
* Wraps nodes in another node, or removes an existing wrap.
|
|
12
12
|
*/
|
|
13
|
-
toggleWrap: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
13
|
+
toggleWrap: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export const toggleWrap: RawCommands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state,
|
|
18
|
+
export const toggleWrap: RawCommands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
|
19
19
|
const type = getNodeType(typeOrName, state.schema)
|
|
20
20
|
const isActive = isNodeActive(state, type, attributes)
|
|
21
21
|
|
|
22
22
|
if (isActive) {
|
|
23
|
-
return lift(
|
|
23
|
+
return commands.lift(type)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
return wrapIn(type, attributes)
|
|
26
|
+
return commands.wrapIn(type, attributes)
|
|
27
27
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undoInputRule as originalUndoInputRule } from 'prosemirror-inputrules'
|
|
2
1
|
import { RawCommands } from '../types'
|
|
3
2
|
|
|
4
3
|
declare module '@tiptap/core' {
|
|
@@ -13,5 +12,35 @@ declare module '@tiptap/core' {
|
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
export const undoInputRule: RawCommands['undoInputRule'] = () => ({ state, dispatch }) => {
|
|
16
|
-
|
|
15
|
+
const plugins = state.plugins
|
|
16
|
+
|
|
17
|
+
for (let i = 0; i < plugins.length; i += 1) {
|
|
18
|
+
const plugin = plugins[i]
|
|
19
|
+
let undoable
|
|
20
|
+
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
// eslint-disable-next-line
|
|
23
|
+
if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) {
|
|
24
|
+
if (dispatch) {
|
|
25
|
+
const tr = state.tr
|
|
26
|
+
const toUndo = undoable.transform
|
|
27
|
+
|
|
28
|
+
for (let j = toUndo.steps.length - 1; j >= 0; j -= 1) {
|
|
29
|
+
tr.step(toUndo.steps[j].invert(toUndo.docs[j]))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (undoable.text) {
|
|
33
|
+
const marks = tr.doc.resolve(undoable.from).marks()
|
|
34
|
+
|
|
35
|
+
tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks))
|
|
36
|
+
} else {
|
|
37
|
+
tr.delete(undoable.from, undoable.to)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return false
|
|
17
46
|
}
|
|
@@ -11,7 +11,7 @@ declare module '@tiptap/core' {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export const unsetAllMarks: RawCommands['unsetAllMarks'] = () => ({ tr,
|
|
14
|
+
export const unsetAllMarks: RawCommands['unsetAllMarks'] = () => ({ tr, dispatch }) => {
|
|
15
15
|
const { selection } = tr
|
|
16
16
|
const { empty, ranges } = selection
|
|
17
17
|
|
|
@@ -20,13 +20,9 @@ export const unsetAllMarks: RawCommands['unsetAllMarks'] = () => ({ tr, state, d
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
if (dispatch) {
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
ranges.forEach(range => {
|
|
27
|
-
tr.removeMark(range.$from.pos, range.$to.pos, mark as any)
|
|
28
|
-
})
|
|
29
|
-
})
|
|
23
|
+
ranges.forEach(range => {
|
|
24
|
+
tr.removeMark(range.$from.pos, range.$to.pos)
|
|
25
|
+
})
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
return true
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { MarkType } from '
|
|
1
|
+
import { MarkType } from '@tiptap/pm/model'
|
|
2
|
+
|
|
3
|
+
import { getMarkRange } from '../helpers/getMarkRange'
|
|
4
|
+
import { getMarkType } from '../helpers/getMarkType'
|
|
2
5
|
import { RawCommands } from '../types'
|
|
3
|
-
import getMarkType from '../helpers/getMarkType'
|
|
4
|
-
import getMarkRange from '../helpers/getMarkRange'
|
|
5
6
|
|
|
6
7
|
declare module '@tiptap/core' {
|
|
7
8
|
interface Commands<ReturnType> {
|
|
@@ -9,35 +10,47 @@ declare module '@tiptap/core' {
|
|
|
9
10
|
/**
|
|
10
11
|
* Remove all marks in the current selection.
|
|
11
12
|
*/
|
|
12
|
-
unsetMark: (
|
|
13
|
+
unsetMark: (
|
|
14
|
+
typeOrName: string | MarkType,
|
|
15
|
+
options?: {
|
|
16
|
+
/**
|
|
17
|
+
* Removes the mark even across the current selection. Defaults to `false`.
|
|
18
|
+
*/
|
|
19
|
+
extendEmptyMarkRange?: boolean
|
|
20
|
+
},
|
|
21
|
+
) => ReturnType
|
|
13
22
|
}
|
|
14
23
|
}
|
|
15
24
|
}
|
|
16
25
|
|
|
17
|
-
export const unsetMark: RawCommands['unsetMark'] = typeOrName => ({ tr, state, dispatch }) => {
|
|
26
|
+
export const unsetMark: RawCommands['unsetMark'] = (typeOrName, options = {}) => ({ tr, state, dispatch }) => {
|
|
27
|
+
const { extendEmptyMarkRange = false } = options
|
|
18
28
|
const { selection } = tr
|
|
19
29
|
const type = getMarkType(typeOrName, state.schema)
|
|
20
30
|
const { $from, empty, ranges } = selection
|
|
21
31
|
|
|
22
|
-
if (dispatch) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
ranges.forEach(range => {
|
|
35
|
-
tr.removeMark(range.$from.pos, range.$to.pos, type)
|
|
36
|
-
})
|
|
32
|
+
if (!dispatch) {
|
|
33
|
+
return true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (empty && extendEmptyMarkRange) {
|
|
37
|
+
let { from, to } = selection
|
|
38
|
+
const attrs = $from.marks().find(mark => mark.type === type)?.attrs
|
|
39
|
+
const range = getMarkRange($from, type, attrs)
|
|
40
|
+
|
|
41
|
+
if (range) {
|
|
42
|
+
from = range.from
|
|
43
|
+
to = range.to
|
|
37
44
|
}
|
|
38
45
|
|
|
39
|
-
tr.
|
|
46
|
+
tr.removeMark(from, to, type)
|
|
47
|
+
} else {
|
|
48
|
+
ranges.forEach(range => {
|
|
49
|
+
tr.removeMark(range.$from.pos, range.$to.pos, type)
|
|
50
|
+
})
|
|
40
51
|
}
|
|
41
52
|
|
|
53
|
+
tr.removeStoredMark(type)
|
|
54
|
+
|
|
42
55
|
return true
|
|
43
56
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import getMarkType from '../helpers/getMarkType'
|
|
4
|
-
import
|
|
1
|
+
import { MarkType, NodeType } from '@tiptap/pm/model'
|
|
2
|
+
|
|
3
|
+
import { getMarkType } from '../helpers/getMarkType'
|
|
4
|
+
import { getNodeType } from '../helpers/getNodeType'
|
|
5
|
+
import { getSchemaTypeNameByName } from '../helpers/getSchemaTypeNameByName'
|
|
5
6
|
import { RawCommands } from '../types'
|
|
6
7
|
|
|
7
8
|
declare module '@tiptap/core' {
|
|
@@ -10,7 +11,10 @@ declare module '@tiptap/core' {
|
|
|
10
11
|
/**
|
|
11
12
|
* Update attributes of a node or mark.
|
|
12
13
|
*/
|
|
13
|
-
updateAttributes: (
|
|
14
|
+
updateAttributes: (
|
|
15
|
+
typeOrName: string | NodeType | MarkType,
|
|
16
|
+
attributes: Record<string, any>,
|
|
17
|
+
) => ReturnType
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
}
|
|
@@ -20,9 +24,7 @@ export const updateAttributes: RawCommands['updateAttributes'] = (typeOrName, at
|
|
|
20
24
|
let markType: MarkType | null = null
|
|
21
25
|
|
|
22
26
|
const schemaType = getSchemaTypeNameByName(
|
|
23
|
-
typeof typeOrName === 'string'
|
|
24
|
-
? typeOrName
|
|
25
|
-
: typeOrName.name,
|
|
27
|
+
typeof typeOrName === 'string' ? typeOrName : typeOrName.name,
|
|
26
28
|
state.schema,
|
|
27
29
|
)
|
|
28
30
|
|
|
@@ -57,10 +59,14 @@ export const updateAttributes: RawCommands['updateAttributes'] = (typeOrName, at
|
|
|
57
59
|
const trimmedFrom = Math.max(pos, from)
|
|
58
60
|
const trimmedTo = Math.min(pos + node.nodeSize, to)
|
|
59
61
|
|
|
60
|
-
tr.addMark(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
tr.addMark(
|
|
63
|
+
trimmedFrom,
|
|
64
|
+
trimmedTo,
|
|
65
|
+
markType.create({
|
|
66
|
+
...mark.attrs,
|
|
67
|
+
...attributes,
|
|
68
|
+
}),
|
|
69
|
+
)
|
|
64
70
|
}
|
|
65
71
|
})
|
|
66
72
|
}
|
package/src/commands/wrapIn.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { wrapIn as originalWrapIn } from '
|
|
2
|
-
import { NodeType } from '
|
|
1
|
+
import { wrapIn as originalWrapIn } from '@tiptap/pm/commands'
|
|
2
|
+
import { NodeType } from '@tiptap/pm/model'
|
|
3
|
+
|
|
4
|
+
import { getNodeType } from '../helpers/getNodeType'
|
|
3
5
|
import { RawCommands } from '../types'
|
|
4
|
-
import isNodeActive from '../helpers/isNodeActive'
|
|
5
|
-
import getNodeType from '../helpers/getNodeType'
|
|
6
6
|
|
|
7
7
|
declare module '@tiptap/core' {
|
|
8
8
|
interface Commands<ReturnType> {
|
|
@@ -10,18 +10,13 @@ declare module '@tiptap/core' {
|
|
|
10
10
|
/**
|
|
11
11
|
* Wraps nodes in another node.
|
|
12
12
|
*/
|
|
13
|
-
wrapIn: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
13
|
+
wrapIn: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export const wrapIn: RawCommands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
|
19
19
|
const type = getNodeType(typeOrName, state.schema)
|
|
20
|
-
const isActive = isNodeActive(state, type, attributes)
|
|
21
|
-
|
|
22
|
-
if (isActive) {
|
|
23
|
-
return false
|
|
24
|
-
}
|
|
25
20
|
|
|
26
21
|
return originalWrapIn(type, attributes)(state, dispatch)
|
|
27
22
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import { wrapInList as originalWrapInList } from '@tiptap/pm/schema-list'
|
|
3
|
+
|
|
4
|
+
import { getNodeType } from '../helpers/getNodeType'
|
|
3
5
|
import { RawCommands } from '../types'
|
|
4
|
-
import getNodeType from '../helpers/getNodeType'
|
|
5
6
|
|
|
6
7
|
declare module '@tiptap/core' {
|
|
7
8
|
interface Commands<ReturnType> {
|
|
@@ -9,7 +10,7 @@ declare module '@tiptap/core' {
|
|
|
9
10
|
/**
|
|
10
11
|
* Wrap a node in a list.
|
|
11
12
|
*/
|
|
12
|
-
wrapInList: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
13
|
+
wrapInList: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
}
|
|
@@ -1,40 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Plugin, PluginKey } from 'prosemirror-state'
|
|
3
|
-
import { Extension } from '../Extension'
|
|
4
|
-
|
|
5
|
-
const textBetween = (
|
|
6
|
-
editor: Editor,
|
|
7
|
-
from: number,
|
|
8
|
-
to: number,
|
|
9
|
-
blockSeparator?: string,
|
|
10
|
-
leafText?: string,
|
|
11
|
-
): string => {
|
|
12
|
-
let text = ''
|
|
13
|
-
let separated = true
|
|
14
|
-
|
|
15
|
-
editor.state.doc.nodesBetween(from, to, (node, pos) => {
|
|
16
|
-
const textSerializer = editor.extensionManager.textSerializers[node.type.name]
|
|
1
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state'
|
|
17
2
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} else if (node.isText) {
|
|
22
|
-
text += node?.text?.slice(Math.max(from, pos) - pos, to - pos)
|
|
23
|
-
separated = !blockSeparator
|
|
24
|
-
} else if (node.isLeaf && leafText) {
|
|
25
|
-
text += leafText
|
|
26
|
-
separated = !blockSeparator
|
|
27
|
-
} else if (!separated && node.isBlock) {
|
|
28
|
-
text += blockSeparator
|
|
29
|
-
separated = true
|
|
30
|
-
}
|
|
31
|
-
}, 0)
|
|
32
|
-
|
|
33
|
-
return text
|
|
34
|
-
}
|
|
3
|
+
import { Extension } from '../Extension'
|
|
4
|
+
import { getTextBetween } from '../helpers/getTextBetween'
|
|
5
|
+
import { getTextSerializersFromSchema } from '../helpers/getTextSerializersFromSchema'
|
|
35
6
|
|
|
36
7
|
export const ClipboardTextSerializer = Extension.create({
|
|
37
|
-
name: '
|
|
8
|
+
name: 'clipboardTextSerializer',
|
|
38
9
|
|
|
39
10
|
addProseMirrorPlugins() {
|
|
40
11
|
return [
|
|
@@ -43,9 +14,17 @@ export const ClipboardTextSerializer = Extension.create({
|
|
|
43
14
|
props: {
|
|
44
15
|
clipboardTextSerializer: () => {
|
|
45
16
|
const { editor } = this
|
|
46
|
-
const {
|
|
17
|
+
const { state, schema } = editor
|
|
18
|
+
const { doc, selection } = state
|
|
19
|
+
const { ranges } = selection
|
|
20
|
+
const from = Math.min(...ranges.map(range => range.$from.pos))
|
|
21
|
+
const to = Math.max(...ranges.map(range => range.$to.pos))
|
|
22
|
+
const textSerializers = getTextSerializersFromSchema(schema)
|
|
23
|
+
const range = { from, to }
|
|
47
24
|
|
|
48
|
-
return
|
|
25
|
+
return getTextBetween(doc, range, {
|
|
26
|
+
textSerializers,
|
|
27
|
+
})
|
|
49
28
|
},
|
|
50
29
|
},
|
|
51
30
|
}),
|
|
@@ -1,155 +1,14 @@
|
|
|
1
|
+
import * as commands from '../commands'
|
|
1
2
|
import { Extension } from '../Extension'
|
|
2
|
-
import * as blur from '../commands/blur'
|
|
3
|
-
import * as clearContent from '../commands/clearContent'
|
|
4
|
-
import * as clearNodes from '../commands/clearNodes'
|
|
5
|
-
import * as command from '../commands/command'
|
|
6
|
-
import * as createParagraphNear from '../commands/createParagraphNear'
|
|
7
|
-
import * as deleteNode from '../commands/deleteNode'
|
|
8
|
-
import * as deleteRange from '../commands/deleteRange'
|
|
9
|
-
import * as deleteSelection from '../commands/deleteSelection'
|
|
10
|
-
import * as enter from '../commands/enter'
|
|
11
|
-
import * as exitCode from '../commands/exitCode'
|
|
12
|
-
import * as extendMarkRange from '../commands/extendMarkRange'
|
|
13
|
-
import * as first from '../commands/first'
|
|
14
|
-
import * as focus from '../commands/focus'
|
|
15
|
-
import * as forEach from '../commands/forEach'
|
|
16
|
-
import * as insertContent from '../commands/insertContent'
|
|
17
|
-
import * as insertContentAt from '../commands/insertContentAt'
|
|
18
|
-
import * as joinBackward from '../commands/joinBackward'
|
|
19
|
-
import * as joinForward from '../commands/joinForward'
|
|
20
|
-
import * as keyboardShortcut from '../commands/keyboardShortcut'
|
|
21
|
-
import * as lift from '../commands/lift'
|
|
22
|
-
import * as liftEmptyBlock from '../commands/liftEmptyBlock'
|
|
23
|
-
import * as liftListItem from '../commands/liftListItem'
|
|
24
|
-
import * as newlineInCode from '../commands/newlineInCode'
|
|
25
|
-
import * as resetAttributes from '../commands/resetAttributes'
|
|
26
|
-
import * as scrollIntoView from '../commands/scrollIntoView'
|
|
27
|
-
import * as selectAll from '../commands/selectAll'
|
|
28
|
-
import * as selectNodeBackward from '../commands/selectNodeBackward'
|
|
29
|
-
import * as selectNodeForward from '../commands/selectNodeForward'
|
|
30
|
-
import * as selectParentNode from '../commands/selectParentNode'
|
|
31
|
-
import * as setContent from '../commands/setContent'
|
|
32
|
-
import * as setMark from '../commands/setMark'
|
|
33
|
-
import * as setMeta from '../commands/setMeta'
|
|
34
|
-
import * as setNode from '../commands/setNode'
|
|
35
|
-
import * as setNodeSelection from '../commands/setNodeSelection'
|
|
36
|
-
import * as setTextSelection from '../commands/setTextSelection'
|
|
37
|
-
import * as sinkListItem from '../commands/sinkListItem'
|
|
38
|
-
import * as splitBlock from '../commands/splitBlock'
|
|
39
|
-
import * as splitListItem from '../commands/splitListItem'
|
|
40
|
-
import * as toggleList from '../commands/toggleList'
|
|
41
|
-
import * as toggleMark from '../commands/toggleMark'
|
|
42
|
-
import * as toggleNode from '../commands/toggleNode'
|
|
43
|
-
import * as toggleWrap from '../commands/toggleWrap'
|
|
44
|
-
import * as undoInputRule from '../commands/undoInputRule'
|
|
45
|
-
import * as unsetAllMarks from '../commands/unsetAllMarks'
|
|
46
|
-
import * as unsetMark from '../commands/unsetMark'
|
|
47
|
-
import * as updateAttributes from '../commands/updateAttributes'
|
|
48
|
-
import * as wrapIn from '../commands/wrapIn'
|
|
49
|
-
import * as wrapInList from '../commands/wrapInList'
|
|
50
3
|
|
|
51
|
-
export
|
|
52
|
-
export { clearContent }
|
|
53
|
-
export { clearNodes }
|
|
54
|
-
export { command }
|
|
55
|
-
export { createParagraphNear }
|
|
56
|
-
export { deleteNode }
|
|
57
|
-
export { deleteRange }
|
|
58
|
-
export { deleteSelection }
|
|
59
|
-
export { enter }
|
|
60
|
-
export { exitCode }
|
|
61
|
-
export { extendMarkRange }
|
|
62
|
-
export { first }
|
|
63
|
-
export { focus }
|
|
64
|
-
export { forEach }
|
|
65
|
-
export { insertContent }
|
|
66
|
-
export { insertContentAt }
|
|
67
|
-
export { joinBackward }
|
|
68
|
-
export { joinForward }
|
|
69
|
-
export { keyboardShortcut }
|
|
70
|
-
export { lift }
|
|
71
|
-
export { liftEmptyBlock }
|
|
72
|
-
export { liftListItem }
|
|
73
|
-
export { newlineInCode }
|
|
74
|
-
export { resetAttributes }
|
|
75
|
-
export { scrollIntoView }
|
|
76
|
-
export { selectAll }
|
|
77
|
-
export { selectNodeBackward }
|
|
78
|
-
export { selectNodeForward }
|
|
79
|
-
export { selectParentNode }
|
|
80
|
-
export { setContent }
|
|
81
|
-
export { setMark }
|
|
82
|
-
export { setMeta }
|
|
83
|
-
export { setNode }
|
|
84
|
-
export { setNodeSelection }
|
|
85
|
-
export { setTextSelection }
|
|
86
|
-
export { sinkListItem }
|
|
87
|
-
export { splitBlock }
|
|
88
|
-
export { splitListItem }
|
|
89
|
-
export { toggleList }
|
|
90
|
-
export { toggleMark }
|
|
91
|
-
export { toggleNode }
|
|
92
|
-
export { toggleWrap }
|
|
93
|
-
export { undoInputRule }
|
|
94
|
-
export { unsetAllMarks }
|
|
95
|
-
export { unsetMark }
|
|
96
|
-
export { updateAttributes }
|
|
97
|
-
export { wrapIn }
|
|
98
|
-
export { wrapInList }
|
|
4
|
+
export * from '../commands'
|
|
99
5
|
|
|
100
6
|
export const Commands = Extension.create({
|
|
101
7
|
name: 'commands',
|
|
102
8
|
|
|
103
9
|
addCommands() {
|
|
104
10
|
return {
|
|
105
|
-
...
|
|
106
|
-
...clearContent,
|
|
107
|
-
...clearNodes,
|
|
108
|
-
...command,
|
|
109
|
-
...createParagraphNear,
|
|
110
|
-
...deleteNode,
|
|
111
|
-
...deleteRange,
|
|
112
|
-
...deleteSelection,
|
|
113
|
-
...enter,
|
|
114
|
-
...exitCode,
|
|
115
|
-
...extendMarkRange,
|
|
116
|
-
...first,
|
|
117
|
-
...focus,
|
|
118
|
-
...forEach,
|
|
119
|
-
...insertContent,
|
|
120
|
-
...insertContentAt,
|
|
121
|
-
...joinBackward,
|
|
122
|
-
...joinForward,
|
|
123
|
-
...keyboardShortcut,
|
|
124
|
-
...lift,
|
|
125
|
-
...liftEmptyBlock,
|
|
126
|
-
...liftListItem,
|
|
127
|
-
...newlineInCode,
|
|
128
|
-
...resetAttributes,
|
|
129
|
-
...scrollIntoView,
|
|
130
|
-
...selectAll,
|
|
131
|
-
...selectNodeBackward,
|
|
132
|
-
...selectNodeForward,
|
|
133
|
-
...selectParentNode,
|
|
134
|
-
...setContent,
|
|
135
|
-
...setMark,
|
|
136
|
-
...setMeta,
|
|
137
|
-
...setNode,
|
|
138
|
-
...setNodeSelection,
|
|
139
|
-
...setTextSelection,
|
|
140
|
-
...sinkListItem,
|
|
141
|
-
...splitBlock,
|
|
142
|
-
...splitListItem,
|
|
143
|
-
...toggleList,
|
|
144
|
-
...toggleMark,
|
|
145
|
-
...toggleNode,
|
|
146
|
-
...toggleWrap,
|
|
147
|
-
...undoInputRule,
|
|
148
|
-
...unsetAllMarks,
|
|
149
|
-
...unsetMark,
|
|
150
|
-
...updateAttributes,
|
|
151
|
-
...wrapIn,
|
|
152
|
-
...wrapInList,
|
|
11
|
+
...commands,
|
|
153
12
|
}
|
|
154
13
|
},
|
|
155
14
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Plugin, PluginKey } from '
|
|
1
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state'
|
|
2
|
+
|
|
2
3
|
import { Extension } from '../Extension'
|
|
3
4
|
|
|
4
5
|
export const FocusEvents = Extension.create({
|
|
@@ -11,11 +12,8 @@ export const FocusEvents = Extension.create({
|
|
|
11
12
|
new Plugin({
|
|
12
13
|
key: new PluginKey('focusEvents'),
|
|
13
14
|
props: {
|
|
14
|
-
attributes: {
|
|
15
|
-
tabindex: '0',
|
|
16
|
-
},
|
|
17
15
|
handleDOMEvents: {
|
|
18
|
-
focus: (view, event) => {
|
|
16
|
+
focus: (view, event: Event) => {
|
|
19
17
|
editor.isFocused = true
|
|
20
18
|
|
|
21
19
|
const transaction = editor.state.tr
|
|
@@ -26,7 +24,7 @@ export const FocusEvents = Extension.create({
|
|
|
26
24
|
|
|
27
25
|
return false
|
|
28
26
|
},
|
|
29
|
-
blur: (view, event) => {
|
|
27
|
+
blur: (view, event: Event) => {
|
|
30
28
|
editor.isFocused = false
|
|
31
29
|
|
|
32
30
|
const transaction = editor.state.tr
|
package/src/extensions/index.ts
CHANGED