@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/src/ExtensionManager.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { keymap } from '
|
|
2
|
-
import { Node as ProsemirrorNode, Schema } from '
|
|
3
|
-
import { Plugin } from '
|
|
4
|
-
import { Decoration, EditorView } from '
|
|
1
|
+
import { keymap } from '@tiptap/pm/keymap'
|
|
2
|
+
import { Node as ProsemirrorNode, Schema } from '@tiptap/pm/model'
|
|
3
|
+
import { Plugin } from '@tiptap/pm/state'
|
|
4
|
+
import { Decoration, EditorView } from '@tiptap/pm/view'
|
|
5
5
|
|
|
6
6
|
import { Mark, NodeConfig } from '.'
|
|
7
7
|
import { Editor } from './Editor'
|
|
@@ -20,7 +20,6 @@ import { callOrReturn } from './utilities/callOrReturn'
|
|
|
20
20
|
import { findDuplicates } from './utilities/findDuplicates'
|
|
21
21
|
|
|
22
22
|
export class ExtensionManager {
|
|
23
|
-
|
|
24
23
|
editor: Editor
|
|
25
24
|
|
|
26
25
|
schema: Schema
|
|
@@ -64,21 +63,13 @@ export class ExtensionManager {
|
|
|
64
63
|
this.editor.on('beforeCreate', onBeforeCreate)
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
const onCreate = getExtensionField<AnyConfig['onCreate']>(
|
|
68
|
-
extension,
|
|
69
|
-
'onCreate',
|
|
70
|
-
context,
|
|
71
|
-
)
|
|
66
|
+
const onCreate = getExtensionField<AnyConfig['onCreate']>(extension, 'onCreate', context)
|
|
72
67
|
|
|
73
68
|
if (onCreate) {
|
|
74
69
|
this.editor.on('create', onCreate)
|
|
75
70
|
}
|
|
76
71
|
|
|
77
|
-
const onUpdate = getExtensionField<AnyConfig['onUpdate']>(
|
|
78
|
-
extension,
|
|
79
|
-
'onUpdate',
|
|
80
|
-
context,
|
|
81
|
-
)
|
|
72
|
+
const onUpdate = getExtensionField<AnyConfig['onUpdate']>(extension, 'onUpdate', context)
|
|
82
73
|
|
|
83
74
|
if (onUpdate) {
|
|
84
75
|
this.editor.on('update', onUpdate)
|
|
@@ -104,31 +95,19 @@ export class ExtensionManager {
|
|
|
104
95
|
this.editor.on('transaction', onTransaction)
|
|
105
96
|
}
|
|
106
97
|
|
|
107
|
-
const onFocus = getExtensionField<AnyConfig['onFocus']>(
|
|
108
|
-
extension,
|
|
109
|
-
'onFocus',
|
|
110
|
-
context,
|
|
111
|
-
)
|
|
98
|
+
const onFocus = getExtensionField<AnyConfig['onFocus']>(extension, 'onFocus', context)
|
|
112
99
|
|
|
113
100
|
if (onFocus) {
|
|
114
101
|
this.editor.on('focus', onFocus)
|
|
115
102
|
}
|
|
116
103
|
|
|
117
|
-
const onBlur = getExtensionField<AnyConfig['onBlur']>(
|
|
118
|
-
extension,
|
|
119
|
-
'onBlur',
|
|
120
|
-
context,
|
|
121
|
-
)
|
|
104
|
+
const onBlur = getExtensionField<AnyConfig['onBlur']>(extension, 'onBlur', context)
|
|
122
105
|
|
|
123
106
|
if (onBlur) {
|
|
124
107
|
this.editor.on('blur', onBlur)
|
|
125
108
|
}
|
|
126
109
|
|
|
127
|
-
const onDestroy = getExtensionField<AnyConfig['onDestroy']>(
|
|
128
|
-
extension,
|
|
129
|
-
'onDestroy',
|
|
130
|
-
context,
|
|
131
|
-
)
|
|
110
|
+
const onDestroy = getExtensionField<AnyConfig['onDestroy']>(extension, 'onDestroy', context)
|
|
132
111
|
|
|
133
112
|
if (onDestroy) {
|
|
134
113
|
this.editor.on('destroy', onDestroy)
|
|
@@ -141,38 +120,41 @@ export class ExtensionManager {
|
|
|
141
120
|
const duplicatedNames = findDuplicates(resolvedExtensions.map(extension => extension.name))
|
|
142
121
|
|
|
143
122
|
if (duplicatedNames.length) {
|
|
144
|
-
console.warn(
|
|
123
|
+
console.warn(
|
|
124
|
+
`[tiptap warn]: Duplicate extension names found: [${duplicatedNames
|
|
125
|
+
.map(item => `'${item}'`)
|
|
126
|
+
.join(', ')}]. This can lead to issues.`,
|
|
127
|
+
)
|
|
145
128
|
}
|
|
146
129
|
|
|
147
130
|
return resolvedExtensions
|
|
148
131
|
}
|
|
149
132
|
|
|
150
133
|
static flatten(extensions: Extensions): Extensions {
|
|
151
|
-
return
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
'addExtensions',
|
|
162
|
-
context,
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
if (addExtensions) {
|
|
166
|
-
return [
|
|
134
|
+
return (
|
|
135
|
+
extensions
|
|
136
|
+
.map(extension => {
|
|
137
|
+
const context = {
|
|
138
|
+
name: extension.name,
|
|
139
|
+
options: extension.options,
|
|
140
|
+
storage: extension.storage,
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const addExtensions = getExtensionField<AnyConfig['addExtensions']>(
|
|
167
144
|
extension,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
145
|
+
'addExtensions',
|
|
146
|
+
context,
|
|
147
|
+
)
|
|
171
148
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
149
|
+
if (addExtensions) {
|
|
150
|
+
return [extension, ...this.flatten(addExtensions())]
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return extension
|
|
154
|
+
})
|
|
155
|
+
// `Infinity` will break TypeScript so we set a number that is probably high enough
|
|
156
|
+
.flat(10)
|
|
157
|
+
)
|
|
176
158
|
}
|
|
177
159
|
|
|
178
160
|
static sort(extensions: Extensions): Extensions {
|
|
@@ -256,16 +238,14 @@ export class ExtensionManager {
|
|
|
256
238
|
|
|
257
239
|
// bind exit handling
|
|
258
240
|
if (extension.type === 'mark' && extension.config.exitable) {
|
|
259
|
-
defaultBindings.ArrowRight = () => Mark.handleExit({ editor, mark:
|
|
241
|
+
defaultBindings.ArrowRight = () => Mark.handleExit({ editor, mark: extension as Mark })
|
|
260
242
|
}
|
|
261
243
|
|
|
262
244
|
if (addKeyboardShortcuts) {
|
|
263
245
|
const bindings = Object.fromEntries(
|
|
264
|
-
Object
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
return [shortcut, () => method({ editor })]
|
|
268
|
-
}),
|
|
246
|
+
Object.entries(addKeyboardShortcuts()).map(([shortcut, method]) => {
|
|
247
|
+
return [shortcut, () => method({ editor })]
|
|
248
|
+
}),
|
|
269
249
|
)
|
|
270
250
|
|
|
271
251
|
defaultBindings = { ...defaultBindings, ...bindings }
|
|
@@ -332,46 +312,50 @@ export class ExtensionManager {
|
|
|
332
312
|
const { editor } = this
|
|
333
313
|
const { nodeExtensions } = splitExtensions(this.extensions)
|
|
334
314
|
|
|
335
|
-
return Object.fromEntries(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const addNodeView = getExtensionField<NodeConfig['addNodeView']>(
|
|
347
|
-
extension,
|
|
348
|
-
'addNodeView',
|
|
349
|
-
context,
|
|
350
|
-
)
|
|
351
|
-
|
|
352
|
-
if (!addNodeView) {
|
|
353
|
-
return []
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const nodeview = (
|
|
357
|
-
node: ProsemirrorNode,
|
|
358
|
-
view: EditorView,
|
|
359
|
-
getPos: (() => number) | boolean,
|
|
360
|
-
decorations: Decoration[],
|
|
361
|
-
) => {
|
|
362
|
-
const HTMLAttributes = getRenderedAttributes(node, extensionAttributes)
|
|
363
|
-
|
|
364
|
-
return addNodeView()({
|
|
315
|
+
return Object.fromEntries(
|
|
316
|
+
nodeExtensions
|
|
317
|
+
.filter(extension => !!getExtensionField(extension, 'addNodeView'))
|
|
318
|
+
.map(extension => {
|
|
319
|
+
const extensionAttributes = this.attributes.filter(
|
|
320
|
+
attribute => attribute.type === extension.name,
|
|
321
|
+
)
|
|
322
|
+
const context = {
|
|
323
|
+
name: extension.name,
|
|
324
|
+
options: extension.options,
|
|
325
|
+
storage: extension.storage,
|
|
365
326
|
editor,
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
HTMLAttributes,
|
|
327
|
+
type: getNodeType(extension.name, this.schema),
|
|
328
|
+
}
|
|
329
|
+
const addNodeView = getExtensionField<NodeConfig['addNodeView']>(
|
|
370
330
|
extension,
|
|
371
|
-
|
|
372
|
-
|
|
331
|
+
'addNodeView',
|
|
332
|
+
context,
|
|
333
|
+
)
|
|
373
334
|
|
|
374
|
-
|
|
375
|
-
|
|
335
|
+
if (!addNodeView) {
|
|
336
|
+
return []
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const nodeview = (
|
|
340
|
+
node: ProsemirrorNode,
|
|
341
|
+
view: EditorView,
|
|
342
|
+
getPos: (() => number) | boolean,
|
|
343
|
+
decorations: Decoration[],
|
|
344
|
+
) => {
|
|
345
|
+
const HTMLAttributes = getRenderedAttributes(node, extensionAttributes)
|
|
346
|
+
|
|
347
|
+
return addNodeView()({
|
|
348
|
+
editor,
|
|
349
|
+
node,
|
|
350
|
+
getPos,
|
|
351
|
+
decorations,
|
|
352
|
+
HTMLAttributes,
|
|
353
|
+
extension,
|
|
354
|
+
})
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return [extension.name, nodeview]
|
|
358
|
+
}),
|
|
359
|
+
)
|
|
376
360
|
}
|
|
377
361
|
}
|
package/src/InputRule.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EditorState, Plugin, TextSelection } from '
|
|
1
|
+
import { EditorState, Plugin, TextSelection } from '@tiptap/pm/state'
|
|
2
2
|
|
|
3
3
|
import { CommandManager } from './CommandManager'
|
|
4
4
|
import { Editor } from './Editor'
|
|
@@ -14,46 +14,47 @@ import {
|
|
|
14
14
|
import { isRegExp } from './utilities/isRegExp'
|
|
15
15
|
|
|
16
16
|
export type InputRuleMatch = {
|
|
17
|
-
index: number
|
|
18
|
-
text: string
|
|
19
|
-
replaceWith?: string
|
|
20
|
-
match?: RegExpMatchArray
|
|
21
|
-
data?: Record<string, any
|
|
17
|
+
index: number
|
|
18
|
+
text: string
|
|
19
|
+
replaceWith?: string
|
|
20
|
+
match?: RegExpMatchArray
|
|
21
|
+
data?: Record<string, any>
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export type InputRuleFinder =
|
|
25
|
-
| RegExp
|
|
26
|
-
| ((text: string) => InputRuleMatch | null)
|
|
24
|
+
export type InputRuleFinder = RegExp | ((text: string) => InputRuleMatch | null)
|
|
27
25
|
|
|
28
26
|
export class InputRule {
|
|
29
27
|
find: InputRuleFinder
|
|
30
28
|
|
|
31
29
|
handler: (props: {
|
|
32
|
-
state: EditorState
|
|
33
|
-
range: Range
|
|
34
|
-
match: ExtendedRegExpMatchArray
|
|
35
|
-
commands: SingleCommands
|
|
36
|
-
chain: () => ChainedCommands
|
|
37
|
-
can: () => CanCommands
|
|
30
|
+
state: EditorState
|
|
31
|
+
range: Range
|
|
32
|
+
match: ExtendedRegExpMatchArray
|
|
33
|
+
commands: SingleCommands
|
|
34
|
+
chain: () => ChainedCommands
|
|
35
|
+
can: () => CanCommands
|
|
38
36
|
}) => void | null
|
|
39
37
|
|
|
40
38
|
constructor(config: {
|
|
41
|
-
find: InputRuleFinder
|
|
39
|
+
find: InputRuleFinder
|
|
42
40
|
handler: (props: {
|
|
43
|
-
state: EditorState
|
|
44
|
-
range: Range
|
|
45
|
-
match: ExtendedRegExpMatchArray
|
|
46
|
-
commands: SingleCommands
|
|
47
|
-
chain: () => ChainedCommands
|
|
48
|
-
can: () => CanCommands
|
|
49
|
-
}) => void | null
|
|
41
|
+
state: EditorState
|
|
42
|
+
range: Range
|
|
43
|
+
match: ExtendedRegExpMatchArray
|
|
44
|
+
commands: SingleCommands
|
|
45
|
+
chain: () => ChainedCommands
|
|
46
|
+
can: () => CanCommands
|
|
47
|
+
}) => void | null
|
|
50
48
|
}) {
|
|
51
49
|
this.find = config.find
|
|
52
50
|
this.handler = config.handler
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
const inputRuleMatcherHandler = (
|
|
54
|
+
const inputRuleMatcherHandler = (
|
|
55
|
+
text: string,
|
|
56
|
+
find: InputRuleFinder,
|
|
57
|
+
): ExtendedRegExpMatchArray | null => {
|
|
57
58
|
if (isRegExp(find)) {
|
|
58
59
|
return find.exec(text)
|
|
59
60
|
}
|
|
@@ -64,16 +65,17 @@ const inputRuleMatcherHandler = (text: string, find: InputRuleFinder): ExtendedR
|
|
|
64
65
|
return null
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
const result: ExtendedRegExpMatchArray = []
|
|
68
|
+
const result: ExtendedRegExpMatchArray = [inputRuleMatch.text]
|
|
68
69
|
|
|
69
|
-
result.push(inputRuleMatch.text)
|
|
70
70
|
result.index = inputRuleMatch.index
|
|
71
71
|
result.input = text
|
|
72
72
|
result.data = inputRuleMatch.data
|
|
73
73
|
|
|
74
74
|
if (inputRuleMatch.replaceWith) {
|
|
75
75
|
if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
|
|
76
|
-
console.warn(
|
|
76
|
+
console.warn(
|
|
77
|
+
'[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".',
|
|
78
|
+
)
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
result.push(inputRuleMatch.replaceWith)
|
|
@@ -83,20 +85,15 @@ const inputRuleMatcherHandler = (text: string, find: InputRuleFinder): ExtendedR
|
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
function run(config: {
|
|
86
|
-
editor: Editor
|
|
87
|
-
from: number
|
|
88
|
-
to: number
|
|
89
|
-
text: string
|
|
90
|
-
rules: InputRule[]
|
|
91
|
-
plugin: Plugin
|
|
88
|
+
editor: Editor
|
|
89
|
+
from: number
|
|
90
|
+
to: number
|
|
91
|
+
text: string
|
|
92
|
+
rules: InputRule[]
|
|
93
|
+
plugin: Plugin
|
|
92
94
|
}): boolean {
|
|
93
95
|
const {
|
|
94
|
-
editor,
|
|
95
|
-
from,
|
|
96
|
-
to,
|
|
97
|
-
text,
|
|
98
|
-
rules,
|
|
99
|
-
plugin,
|
|
96
|
+
editor, from, to, text, rules, plugin,
|
|
100
97
|
} = config
|
|
101
98
|
const { view } = editor
|
|
102
99
|
|
|
@@ -180,7 +177,7 @@ function run(config: {
|
|
|
180
177
|
* input that matches any of the given rules to trigger the rule’s
|
|
181
178
|
* action.
|
|
182
179
|
*/
|
|
183
|
-
export function inputRulesPlugin(props: { editor: Editor
|
|
180
|
+
export function inputRulesPlugin(props: { editor: Editor; rules: InputRule[] }): Plugin {
|
|
184
181
|
const { editor, rules } = props
|
|
185
182
|
const plugin = new Plugin({
|
|
186
183
|
state: {
|
|
@@ -194,9 +191,7 @@ export function inputRulesPlugin(props: { editor: Editor, rules: InputRule[] }):
|
|
|
194
191
|
return stored
|
|
195
192
|
}
|
|
196
193
|
|
|
197
|
-
return tr.selectionSet || tr.docChanged
|
|
198
|
-
? null
|
|
199
|
-
: prev
|
|
194
|
+
return tr.selectionSet || tr.docChanged ? null : prev
|
|
200
195
|
},
|
|
201
196
|
},
|
|
202
197
|
|