@tiptap/core 2.0.0-beta.99 → 2.0.0-rc.2
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
package/src/EventEmitter.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
type StringKeyOf<T> = Extract<keyof T, string>
|
|
2
|
+
type CallbackType<
|
|
3
|
+
T extends Record<string, any>,
|
|
4
|
+
EventName extends StringKeyOf<T>,
|
|
5
|
+
> = T[EventName] extends any[] ? T[EventName] : [T[EventName]]
|
|
6
|
+
type CallbackFunction<
|
|
7
|
+
T extends Record<string, any>,
|
|
8
|
+
EventName extends StringKeyOf<T>,
|
|
9
|
+
> = (...props: CallbackType<T, EventName>) => any
|
|
10
|
+
|
|
11
|
+
export class EventEmitter<T extends Record<string, any>> {
|
|
2
12
|
|
|
3
13
|
private callbacks: { [key: string]: Function[] } = {}
|
|
4
14
|
|
|
5
|
-
public on(event:
|
|
15
|
+
public on<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): this {
|
|
6
16
|
if (!this.callbacks[event]) {
|
|
7
17
|
this.callbacks[event] = []
|
|
8
18
|
}
|
|
@@ -12,7 +22,7 @@ export default class EventEmitter {
|
|
|
12
22
|
return this
|
|
13
23
|
}
|
|
14
24
|
|
|
15
|
-
protected emit(event:
|
|
25
|
+
protected emit<EventName extends StringKeyOf<T>>(event: EventName, ...args: CallbackType<T, EventName>): this {
|
|
16
26
|
const callbacks = this.callbacks[event]
|
|
17
27
|
|
|
18
28
|
if (callbacks) {
|
|
@@ -22,7 +32,7 @@ export default class EventEmitter {
|
|
|
22
32
|
return this
|
|
23
33
|
}
|
|
24
34
|
|
|
25
|
-
public off(event:
|
|
35
|
+
public off<EventName extends StringKeyOf<T>>(event: EventName, fn?: CallbackFunction<T, EventName>): this {
|
|
26
36
|
const callbacks = this.callbacks[event]
|
|
27
37
|
|
|
28
38
|
if (callbacks) {
|
package/src/Extension.ts
CHANGED
|
@@ -1,229 +1,288 @@
|
|
|
1
|
-
import { Plugin, Transaction } from '
|
|
2
|
-
|
|
1
|
+
import { Plugin, Transaction } from '@tiptap/pm/state'
|
|
2
|
+
|
|
3
|
+
import { ExtensionConfig } from '.'
|
|
3
4
|
import { Editor } from './Editor'
|
|
4
|
-
import {
|
|
5
|
+
import { getExtensionField } from './helpers/getExtensionField'
|
|
6
|
+
import { InputRule } from './InputRule'
|
|
5
7
|
import { Mark } from './Mark'
|
|
6
|
-
import
|
|
8
|
+
import { Node } from './Node'
|
|
9
|
+
import { PasteRule } from './PasteRule'
|
|
7
10
|
import {
|
|
11
|
+
AnyConfig,
|
|
8
12
|
Extensions,
|
|
9
13
|
GlobalAttributes,
|
|
10
|
-
RawCommands,
|
|
11
|
-
ParentConfig,
|
|
12
14
|
KeyboardShortcutCommand,
|
|
15
|
+
ParentConfig,
|
|
16
|
+
RawCommands,
|
|
13
17
|
} from './types'
|
|
14
|
-
import {
|
|
18
|
+
import { callOrReturn } from './utilities/callOrReturn'
|
|
19
|
+
import { mergeDeep } from './utilities/mergeDeep'
|
|
15
20
|
|
|
16
21
|
declare module '@tiptap/core' {
|
|
17
|
-
interface ExtensionConfig<Options = any> {
|
|
18
|
-
[key: string]: any
|
|
22
|
+
interface ExtensionConfig<Options = any, Storage = any> {
|
|
23
|
+
[key: string]: any
|
|
19
24
|
|
|
20
25
|
/**
|
|
21
26
|
* Name
|
|
22
27
|
*/
|
|
23
|
-
name: string
|
|
28
|
+
name: string
|
|
24
29
|
|
|
25
30
|
/**
|
|
26
31
|
* Priority
|
|
27
32
|
*/
|
|
28
|
-
priority?: number
|
|
33
|
+
priority?: number
|
|
29
34
|
|
|
30
35
|
/**
|
|
31
36
|
* Default options
|
|
32
37
|
*/
|
|
33
|
-
defaultOptions?: Options
|
|
38
|
+
defaultOptions?: Options
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Default Options
|
|
42
|
+
*/
|
|
43
|
+
addOptions?: (this: {
|
|
44
|
+
name: string
|
|
45
|
+
parent: Exclude<ParentConfig<ExtensionConfig<Options, Storage>>['addOptions'], undefined>
|
|
46
|
+
}) => Options
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Default Storage
|
|
50
|
+
*/
|
|
51
|
+
addStorage?: (this: {
|
|
52
|
+
name: string
|
|
53
|
+
options: Options
|
|
54
|
+
parent: Exclude<ParentConfig<ExtensionConfig<Options, Storage>>['addStorage'], undefined>
|
|
55
|
+
}) => Storage
|
|
34
56
|
|
|
35
57
|
/**
|
|
36
58
|
* Global attributes
|
|
37
59
|
*/
|
|
38
60
|
addGlobalAttributes?: (this: {
|
|
39
|
-
name: string
|
|
40
|
-
options: Options
|
|
41
|
-
|
|
42
|
-
|
|
61
|
+
name: string
|
|
62
|
+
options: Options
|
|
63
|
+
storage: Storage
|
|
64
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addGlobalAttributes']
|
|
65
|
+
}) => GlobalAttributes | {}
|
|
43
66
|
|
|
44
67
|
/**
|
|
45
68
|
* Raw
|
|
46
69
|
*/
|
|
47
70
|
addCommands?: (this: {
|
|
48
|
-
name: string
|
|
49
|
-
options: Options
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
71
|
+
name: string
|
|
72
|
+
options: Options
|
|
73
|
+
storage: Storage
|
|
74
|
+
editor: Editor
|
|
75
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addCommands']
|
|
76
|
+
}) => Partial<RawCommands>
|
|
53
77
|
|
|
54
78
|
/**
|
|
55
79
|
* Keyboard shortcuts
|
|
56
80
|
*/
|
|
57
81
|
addKeyboardShortcuts?: (this: {
|
|
58
|
-
name: string
|
|
59
|
-
options: Options
|
|
60
|
-
|
|
61
|
-
|
|
82
|
+
name: string
|
|
83
|
+
options: Options
|
|
84
|
+
storage: Storage
|
|
85
|
+
editor: Editor
|
|
86
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addKeyboardShortcuts']
|
|
62
87
|
}) => {
|
|
63
|
-
[key: string]: KeyboardShortcutCommand
|
|
64
|
-
}
|
|
88
|
+
[key: string]: KeyboardShortcutCommand
|
|
89
|
+
}
|
|
65
90
|
|
|
66
91
|
/**
|
|
67
92
|
* Input rules
|
|
68
93
|
*/
|
|
69
94
|
addInputRules?: (this: {
|
|
70
|
-
name: string
|
|
71
|
-
options: Options
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
95
|
+
name: string
|
|
96
|
+
options: Options
|
|
97
|
+
storage: Storage
|
|
98
|
+
editor: Editor
|
|
99
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addInputRules']
|
|
100
|
+
}) => InputRule[]
|
|
75
101
|
|
|
76
102
|
/**
|
|
77
103
|
* Paste rules
|
|
78
104
|
*/
|
|
79
105
|
addPasteRules?: (this: {
|
|
80
|
-
name: string
|
|
81
|
-
options: Options
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
106
|
+
name: string
|
|
107
|
+
options: Options
|
|
108
|
+
storage: Storage
|
|
109
|
+
editor: Editor
|
|
110
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addPasteRules']
|
|
111
|
+
}) => PasteRule[]
|
|
85
112
|
|
|
86
113
|
/**
|
|
87
114
|
* ProseMirror plugins
|
|
88
115
|
*/
|
|
89
116
|
addProseMirrorPlugins?: (this: {
|
|
90
|
-
name: string
|
|
91
|
-
options: Options
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
117
|
+
name: string
|
|
118
|
+
options: Options
|
|
119
|
+
storage: Storage
|
|
120
|
+
editor: Editor
|
|
121
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addProseMirrorPlugins']
|
|
122
|
+
}) => Plugin[]
|
|
95
123
|
|
|
96
124
|
/**
|
|
97
125
|
* Extensions
|
|
98
126
|
*/
|
|
99
127
|
addExtensions?: (this: {
|
|
100
|
-
name: string
|
|
101
|
-
options: Options
|
|
102
|
-
|
|
103
|
-
|
|
128
|
+
name: string
|
|
129
|
+
options: Options
|
|
130
|
+
storage: Storage
|
|
131
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addExtensions']
|
|
132
|
+
}) => Extensions
|
|
104
133
|
|
|
105
134
|
/**
|
|
106
135
|
* Extend Node Schema
|
|
107
136
|
*/
|
|
108
|
-
extendNodeSchema?:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
137
|
+
extendNodeSchema?:
|
|
138
|
+
| ((
|
|
139
|
+
this: {
|
|
140
|
+
name: string
|
|
141
|
+
options: Options
|
|
142
|
+
storage: Storage
|
|
143
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['extendNodeSchema']
|
|
144
|
+
},
|
|
145
|
+
extension: Node,
|
|
146
|
+
) => Record<string, any>)
|
|
147
|
+
| null
|
|
116
148
|
|
|
117
149
|
/**
|
|
118
150
|
* Extend Mark Schema
|
|
119
151
|
*/
|
|
120
|
-
extendMarkSchema?:
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
152
|
+
extendMarkSchema?:
|
|
153
|
+
| ((
|
|
154
|
+
this: {
|
|
155
|
+
name: string
|
|
156
|
+
options: Options
|
|
157
|
+
storage: Storage
|
|
158
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['extendMarkSchema']
|
|
159
|
+
},
|
|
160
|
+
extension: Mark,
|
|
161
|
+
) => Record<string, any>)
|
|
162
|
+
| null
|
|
128
163
|
|
|
129
164
|
/**
|
|
130
165
|
* The editor is not ready yet.
|
|
131
166
|
*/
|
|
132
|
-
onBeforeCreate?:
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
167
|
+
onBeforeCreate?:
|
|
168
|
+
| ((this: {
|
|
169
|
+
name: string
|
|
170
|
+
options: Options
|
|
171
|
+
storage: Storage
|
|
172
|
+
editor: Editor
|
|
173
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onBeforeCreate']
|
|
174
|
+
}) => void)
|
|
175
|
+
| null
|
|
138
176
|
|
|
139
177
|
/**
|
|
140
178
|
* The editor is ready.
|
|
141
179
|
*/
|
|
142
|
-
onCreate?:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
180
|
+
onCreate?:
|
|
181
|
+
| ((this: {
|
|
182
|
+
name: string
|
|
183
|
+
options: Options
|
|
184
|
+
storage: Storage
|
|
185
|
+
editor: Editor
|
|
186
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onCreate']
|
|
187
|
+
}) => void)
|
|
188
|
+
| null
|
|
148
189
|
|
|
149
190
|
/**
|
|
150
191
|
* The content has changed.
|
|
151
192
|
*/
|
|
152
|
-
onUpdate?:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
193
|
+
onUpdate?:
|
|
194
|
+
| ((this: {
|
|
195
|
+
name: string
|
|
196
|
+
options: Options
|
|
197
|
+
storage: Storage
|
|
198
|
+
editor: Editor
|
|
199
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onUpdate']
|
|
200
|
+
}) => void)
|
|
201
|
+
| null
|
|
158
202
|
|
|
159
203
|
/**
|
|
160
204
|
* The selection has changed.
|
|
161
205
|
*/
|
|
162
|
-
onSelectionUpdate?:
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
206
|
+
onSelectionUpdate?:
|
|
207
|
+
| ((this: {
|
|
208
|
+
name: string
|
|
209
|
+
options: Options
|
|
210
|
+
storage: Storage
|
|
211
|
+
editor: Editor
|
|
212
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onSelectionUpdate']
|
|
213
|
+
}) => void)
|
|
214
|
+
| null
|
|
168
215
|
|
|
169
216
|
/**
|
|
170
217
|
* The editor state has changed.
|
|
171
218
|
*/
|
|
172
|
-
onTransaction?:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
219
|
+
onTransaction?:
|
|
220
|
+
| ((
|
|
221
|
+
this: {
|
|
222
|
+
name: string
|
|
223
|
+
options: Options
|
|
224
|
+
storage: Storage
|
|
225
|
+
editor: Editor
|
|
226
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onTransaction']
|
|
227
|
+
},
|
|
228
|
+
props: {
|
|
229
|
+
transaction: Transaction
|
|
230
|
+
},
|
|
231
|
+
) => void)
|
|
232
|
+
| null
|
|
183
233
|
|
|
184
234
|
/**
|
|
185
235
|
* The editor is focused.
|
|
186
236
|
*/
|
|
187
|
-
onFocus?:
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
237
|
+
onFocus?:
|
|
238
|
+
| ((
|
|
239
|
+
this: {
|
|
240
|
+
name: string
|
|
241
|
+
options: Options
|
|
242
|
+
storage: Storage
|
|
243
|
+
editor: Editor
|
|
244
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onFocus']
|
|
245
|
+
},
|
|
246
|
+
props: {
|
|
247
|
+
event: FocusEvent
|
|
248
|
+
},
|
|
249
|
+
) => void)
|
|
250
|
+
| null
|
|
198
251
|
|
|
199
252
|
/**
|
|
200
253
|
* The editor isn’t focused anymore.
|
|
201
254
|
*/
|
|
202
|
-
onBlur?:
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
255
|
+
onBlur?:
|
|
256
|
+
| ((
|
|
257
|
+
this: {
|
|
258
|
+
name: string
|
|
259
|
+
options: Options
|
|
260
|
+
storage: Storage
|
|
261
|
+
editor: Editor
|
|
262
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onBlur']
|
|
263
|
+
},
|
|
264
|
+
props: {
|
|
265
|
+
event: FocusEvent
|
|
266
|
+
},
|
|
267
|
+
) => void)
|
|
268
|
+
| null
|
|
213
269
|
|
|
214
270
|
/**
|
|
215
271
|
* The editor is destroyed.
|
|
216
272
|
*/
|
|
217
|
-
onDestroy?:
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
273
|
+
onDestroy?:
|
|
274
|
+
| ((this: {
|
|
275
|
+
name: string
|
|
276
|
+
options: Options
|
|
277
|
+
storage: Storage
|
|
278
|
+
editor: Editor
|
|
279
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onDestroy']
|
|
280
|
+
}) => void)
|
|
281
|
+
| null
|
|
223
282
|
}
|
|
224
283
|
}
|
|
225
284
|
|
|
226
|
-
export class Extension<Options = any> {
|
|
285
|
+
export class Extension<Options = any, Storage = any> {
|
|
227
286
|
type = 'extension'
|
|
228
287
|
|
|
229
288
|
name = 'extension'
|
|
@@ -234,23 +293,48 @@ export class Extension<Options = any> {
|
|
|
234
293
|
|
|
235
294
|
options: Options
|
|
236
295
|
|
|
296
|
+
storage: Storage
|
|
297
|
+
|
|
237
298
|
config: ExtensionConfig = {
|
|
238
299
|
name: this.name,
|
|
239
300
|
defaultOptions: {},
|
|
240
301
|
}
|
|
241
302
|
|
|
242
|
-
constructor(config: Partial<ExtensionConfig<Options>> = {}) {
|
|
303
|
+
constructor(config: Partial<ExtensionConfig<Options, Storage>> = {}) {
|
|
243
304
|
this.config = {
|
|
244
305
|
...this.config,
|
|
245
306
|
...config,
|
|
246
307
|
}
|
|
247
308
|
|
|
248
309
|
this.name = this.config.name
|
|
310
|
+
|
|
311
|
+
if (config.defaultOptions) {
|
|
312
|
+
console.warn(
|
|
313
|
+
`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`,
|
|
314
|
+
)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// TODO: remove `addOptions` fallback
|
|
249
318
|
this.options = this.config.defaultOptions
|
|
319
|
+
|
|
320
|
+
if (this.config.addOptions) {
|
|
321
|
+
this.options = callOrReturn(
|
|
322
|
+
getExtensionField<AnyConfig['addOptions']>(this, 'addOptions', {
|
|
323
|
+
name: this.name,
|
|
324
|
+
}),
|
|
325
|
+
)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
this.storage = callOrReturn(
|
|
329
|
+
getExtensionField<AnyConfig['addStorage']>(this, 'addStorage', {
|
|
330
|
+
name: this.name,
|
|
331
|
+
options: this.options,
|
|
332
|
+
}),
|
|
333
|
+
) || {}
|
|
250
334
|
}
|
|
251
335
|
|
|
252
|
-
static create<O>(config: Partial<ExtensionConfig<O>> = {}) {
|
|
253
|
-
return new Extension<O>(config)
|
|
336
|
+
static create<O = any, S = any>(config: Partial<ExtensionConfig<O, S>> = {}) {
|
|
337
|
+
return new Extension<O, S>(config)
|
|
254
338
|
}
|
|
255
339
|
|
|
256
340
|
configure(options: Partial<Options> = {}) {
|
|
@@ -258,25 +342,47 @@ export class Extension<Options = any> {
|
|
|
258
342
|
// with different calls of `configure`
|
|
259
343
|
const extension = this.extend()
|
|
260
344
|
|
|
261
|
-
extension.options = mergeDeep(this.options, options) as Options
|
|
345
|
+
extension.options = mergeDeep(this.options as Record<string, any>, options) as Options
|
|
346
|
+
|
|
347
|
+
extension.storage = callOrReturn(
|
|
348
|
+
getExtensionField<AnyConfig['addStorage']>(extension, 'addStorage', {
|
|
349
|
+
name: extension.name,
|
|
350
|
+
options: extension.options,
|
|
351
|
+
}),
|
|
352
|
+
)
|
|
262
353
|
|
|
263
354
|
return extension
|
|
264
355
|
}
|
|
265
356
|
|
|
266
|
-
extend<ExtendedOptions = Options
|
|
267
|
-
|
|
357
|
+
extend<ExtendedOptions = Options, ExtendedStorage = Storage>(
|
|
358
|
+
extendedConfig: Partial<ExtensionConfig<ExtendedOptions, ExtendedStorage>> = {},
|
|
359
|
+
) {
|
|
360
|
+
const extension = new Extension<ExtendedOptions, ExtendedStorage>(extendedConfig)
|
|
268
361
|
|
|
269
362
|
extension.parent = this
|
|
270
363
|
|
|
271
364
|
this.child = extension
|
|
272
365
|
|
|
273
|
-
extension.name = extendedConfig.name
|
|
274
|
-
|
|
275
|
-
|
|
366
|
+
extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name
|
|
367
|
+
|
|
368
|
+
if (extendedConfig.defaultOptions) {
|
|
369
|
+
console.warn(
|
|
370
|
+
`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`,
|
|
371
|
+
)
|
|
372
|
+
}
|
|
276
373
|
|
|
277
|
-
extension.options =
|
|
278
|
-
|
|
279
|
-
|
|
374
|
+
extension.options = callOrReturn(
|
|
375
|
+
getExtensionField<AnyConfig['addOptions']>(extension, 'addOptions', {
|
|
376
|
+
name: extension.name,
|
|
377
|
+
}),
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
extension.storage = callOrReturn(
|
|
381
|
+
getExtensionField<AnyConfig['addStorage']>(extension, 'addStorage', {
|
|
382
|
+
name: extension.name,
|
|
383
|
+
options: extension.options,
|
|
384
|
+
}),
|
|
385
|
+
)
|
|
280
386
|
|
|
281
387
|
return extension
|
|
282
388
|
}
|