@tiptap/core 2.5.0-beta.2 → 2.5.0-beta.4
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 +4549 -4538
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4549 -4536
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +4549 -4538
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/CommandManager.d.ts +20 -20
- package/dist/packages/core/src/Editor.d.ts +161 -161
- package/dist/packages/core/src/EventEmitter.d.ts +11 -11
- package/dist/packages/core/src/Extension.d.ts +343 -342
- package/dist/packages/core/src/ExtensionManager.d.ts +55 -55
- package/dist/packages/core/src/InputRule.d.ts +42 -42
- package/dist/packages/core/src/Mark.d.ts +451 -450
- package/dist/packages/core/src/Node.d.ts +611 -609
- package/dist/packages/core/src/NodePos.d.ts +44 -44
- package/dist/packages/core/src/NodeView.d.ts +31 -31
- package/dist/packages/core/src/PasteRule.d.ts +50 -50
- package/dist/packages/core/src/Tracker.d.ts +11 -11
- package/dist/packages/core/src/commands/blur.d.ts +13 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +14 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +13 -13
- package/dist/packages/core/src/commands/command.d.ts +18 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +13 -13
- package/dist/packages/core/src/commands/cut.d.ts +20 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +13 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +15 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +14 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +13 -13
- package/dist/packages/core/src/commands/enter.d.ts +13 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +13 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +25 -25
- package/dist/packages/core/src/commands/first.d.ts +14 -14
- package/dist/packages/core/src/commands/focus.d.ts +27 -27
- package/dist/packages/core/src/commands/forEach.d.ts +14 -14
- package/dist/packages/core/src/commands/index.d.ts +55 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +34 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +47 -47
- package/dist/packages/core/src/commands/join.d.ts +41 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +13 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +13 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +12 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +12 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +14 -14
- package/dist/packages/core/src/commands/lift.d.ts +17 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +13 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +15 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +13 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +16 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +13 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +13 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +13 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +13 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +13 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +13 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +13 -13
- package/dist/packages/core/src/commands/setContent.d.ts +40 -40
- package/dist/packages/core/src/commands/setMark.d.ts +15 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +15 -15
- package/dist/packages/core/src/commands/setNode.d.ts +16 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +14 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +14 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +15 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +17 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +15 -15
- package/dist/packages/core/src/commands/toggleList.d.ts +18 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +30 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +17 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +16 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +13 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +13 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +25 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +24 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +16 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +16 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +5 -5
- package/dist/packages/core/src/extensions/commands.d.ts +3 -3
- package/dist/packages/core/src/extensions/editable.d.ts +2 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +2 -2
- package/dist/packages/core/src/extensions/index.d.ts +6 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +2 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +2 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +10 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +10 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +12 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +15 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +7 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +9 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +10 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +16 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +17 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +8 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +8 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +12 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +9 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +6 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +11 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +8 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +9 -9
- 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 +3 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +2 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +3 -3
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +11 -11
- 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 +3 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +4 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +10 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +8 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +8 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +9 -9
- package/dist/packages/core/src/helpers/getText.d.ts +15 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +14 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +8 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +8 -8
- package/dist/packages/core/src/helpers/index.d.ts +50 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +9 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +2 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +2 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +2 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +2 -2
- package/dist/packages/core/src/helpers/isList.d.ts +2 -2
- 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 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +2 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +9 -9
- package/dist/packages/core/src/index.d.ts +24 -24
- package/dist/packages/core/src/inputRules/index.d.ts +5 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +13 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +23 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +10 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +15 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +28 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +3 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +13 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +13 -13
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +10 -10
- package/dist/packages/core/src/style.d.ts +1 -1
- package/dist/packages/core/src/types.d.ts +250 -244
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +9 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +6 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +1 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +1 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +1 -1
- package/dist/packages/core/src/utilities/index.d.ts +20 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +1 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +1 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +1 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +1 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +1 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +1 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +1 -1
- package/dist/packages/core/src/utilities/isString.d.ts +1 -1
- 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 +8 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +8 -8
- package/package.json +2 -2
- package/src/Extension.ts +14 -12
- package/src/ExtensionManager.ts +2 -2
- package/src/Mark.ts +15 -12
- package/src/Node.ts +16 -12
- package/src/commands/insertContentAt.ts +1 -1
- package/src/extensions/tabindex.ts +1 -1
- package/src/helpers/getAttributesFromExtensions.ts +2 -3
- package/src/helpers/getSchemaByResolvedExtensions.ts +5 -2
- package/src/helpers/injectExtensionAttributesToParseRule.ts +4 -4
- package/src/helpers/isNodeEmpty.ts +6 -3
- package/src/types.ts +6 -0
- package/src/utilities/mergeDeep.ts +3 -7
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check if object1 includes object2
|
|
3
|
-
* @param object1 Object
|
|
4
|
-
* @param object2 Object
|
|
5
|
-
*/
|
|
6
|
-
export declare function objectIncludes(object1: Record<string, any>, object2: Record<string, any>, options?: {
|
|
7
|
-
strict: boolean;
|
|
8
|
-
}): boolean;
|
|
1
|
+
/**
|
|
2
|
+
* Check if object1 includes object2
|
|
3
|
+
* @param object1 Object
|
|
4
|
+
* @param object2 Object
|
|
5
|
+
*/
|
|
6
|
+
export declare function objectIncludes(object1: Record<string, any>, object2: Record<string, any>, options?: {
|
|
7
|
+
strict: boolean;
|
|
8
|
+
}): boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Removes duplicated values within an array.
|
|
3
|
-
* Supports numbers, strings and objects.
|
|
4
|
-
*/
|
|
5
|
-
export declare function removeDuplicates<T>(array: T[], by?: {
|
|
6
|
-
(value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
|
|
7
|
-
(value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
|
|
8
|
-
}): T[];
|
|
1
|
+
/**
|
|
2
|
+
* Removes duplicated values within an array.
|
|
3
|
+
* Supports numbers, strings and objects.
|
|
4
|
+
*/
|
|
5
|
+
export declare function removeDuplicates<T>(array: T[], by?: {
|
|
6
|
+
(value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
|
|
7
|
+
(value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
|
|
8
|
+
}): T[];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/core",
|
|
3
3
|
"description": "headless rich text editor",
|
|
4
|
-
"version": "2.5.0-beta.
|
|
4
|
+
"version": "2.5.0-beta.4",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@tiptap/pm": "^2.5.0-beta.
|
|
35
|
+
"@tiptap/pm": "^2.5.0-beta.4"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@tiptap/pm": "^2.0.0"
|
package/src/Extension.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { mergeDeep } from './utilities/mergeDeep.js'
|
|
|
20
20
|
|
|
21
21
|
declare module '@tiptap/core' {
|
|
22
22
|
interface ExtensionConfig<Options = any, Storage = any> {
|
|
23
|
+
// @ts-ignore - this is a dynamic key
|
|
23
24
|
[key: string]: any
|
|
24
25
|
|
|
25
26
|
/**
|
|
@@ -108,8 +109,9 @@ declare module '@tiptap/core' {
|
|
|
108
109
|
name: string
|
|
109
110
|
options: Options
|
|
110
111
|
storage: Storage
|
|
112
|
+
extensions: (Node | Mark)[]
|
|
111
113
|
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addGlobalAttributes']
|
|
112
|
-
}) => GlobalAttributes
|
|
114
|
+
}) => GlobalAttributes
|
|
113
115
|
|
|
114
116
|
/**
|
|
115
117
|
* This function adds commands to the editor
|
|
@@ -455,17 +457,17 @@ export class Extension<Options = any, Storage = any> {
|
|
|
455
457
|
configure(options: Partial<Options> = {}) {
|
|
456
458
|
// return a new instance so we can use the same extension
|
|
457
459
|
// with different calls of `configure`
|
|
458
|
-
const extension = this.extend(
|
|
459
|
-
|
|
460
|
+
const extension = this.extend({
|
|
461
|
+
...this.config,
|
|
462
|
+
addOptions() {
|
|
463
|
+
return mergeDeep(this.parent?.() || {}, options) as Options
|
|
464
|
+
},
|
|
465
|
+
})
|
|
466
|
+
|
|
467
|
+
// Always preserve the current name
|
|
468
|
+
extension.name = this.name
|
|
469
|
+
// Set the parent to be our parent
|
|
460
470
|
extension.parent = this.parent
|
|
461
|
-
extension.options = mergeDeep(this.options as Record<string, any>, options) as Options
|
|
462
|
-
|
|
463
|
-
extension.storage = callOrReturn(
|
|
464
|
-
getExtensionField<AnyConfig['addStorage']>(extension, 'addStorage', {
|
|
465
|
-
name: extension.name,
|
|
466
|
-
options: extension.options,
|
|
467
|
-
}),
|
|
468
|
-
)
|
|
469
471
|
|
|
470
472
|
return extension
|
|
471
473
|
}
|
|
@@ -481,7 +483,7 @@ export class Extension<Options = any, Storage = any> {
|
|
|
481
483
|
|
|
482
484
|
extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name
|
|
483
485
|
|
|
484
|
-
if (extendedConfig.defaultOptions) {
|
|
486
|
+
if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
|
|
485
487
|
console.warn(
|
|
486
488
|
`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`,
|
|
487
489
|
)
|
package/src/ExtensionManager.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Node as ProsemirrorNode, Schema } from '@tiptap/pm/model'
|
|
|
3
3
|
import { Plugin } from '@tiptap/pm/state'
|
|
4
4
|
import { Decoration, EditorView } from '@tiptap/pm/view'
|
|
5
5
|
|
|
6
|
-
import { Editor } from './Editor.js'
|
|
6
|
+
import type { Editor } from './Editor.js'
|
|
7
7
|
import { getAttributesFromExtensions } from './helpers/getAttributesFromExtensions.js'
|
|
8
8
|
import { getExtensionField } from './helpers/getExtensionField.js'
|
|
9
9
|
import { getNodeType } from './helpers/getNodeType.js'
|
|
@@ -181,7 +181,7 @@ export class ExtensionManager {
|
|
|
181
181
|
let defaultBindings: Record<string, () => boolean> = {}
|
|
182
182
|
|
|
183
183
|
// bind exit handling
|
|
184
|
-
if (extension.type === 'mark' && extension
|
|
184
|
+
if (extension.type === 'mark' && getExtensionField<AnyConfig['exitable']>(extension, 'exitable', context)) {
|
|
185
185
|
defaultBindings.ArrowRight = () => Mark.handleExit({ editor, mark: extension as Mark })
|
|
186
186
|
}
|
|
187
187
|
|
package/src/Mark.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { mergeDeep } from './utilities/mergeDeep.js'
|
|
|
23
23
|
|
|
24
24
|
declare module '@tiptap/core' {
|
|
25
25
|
export interface MarkConfig<Options = any, Storage = any> {
|
|
26
|
+
// @ts-ignore - this is a dynamic key
|
|
26
27
|
[key: string]: any
|
|
27
28
|
|
|
28
29
|
/**
|
|
@@ -111,8 +112,9 @@ declare module '@tiptap/core' {
|
|
|
111
112
|
name: string
|
|
112
113
|
options: Options
|
|
113
114
|
storage: Storage
|
|
115
|
+
extensions: (Node | Mark)[]
|
|
114
116
|
parent: ParentConfig<MarkConfig<Options, Storage>>['addGlobalAttributes']
|
|
115
|
-
}) => GlobalAttributes
|
|
117
|
+
}) => GlobalAttributes
|
|
116
118
|
|
|
117
119
|
/**
|
|
118
120
|
* This function adds commands to the editor
|
|
@@ -587,16 +589,17 @@ export class Mark<Options = any, Storage = any> {
|
|
|
587
589
|
configure(options: Partial<Options> = {}) {
|
|
588
590
|
// return a new instance so we can use the same extension
|
|
589
591
|
// with different calls of `configure`
|
|
590
|
-
const extension = this.extend(
|
|
591
|
-
|
|
592
|
-
|
|
592
|
+
const extension = this.extend({
|
|
593
|
+
...this.config,
|
|
594
|
+
addOptions() {
|
|
595
|
+
return mergeDeep(this.parent?.() || {}, options) as Options
|
|
596
|
+
},
|
|
597
|
+
})
|
|
593
598
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
}),
|
|
599
|
-
)
|
|
599
|
+
// Always preserve the current name
|
|
600
|
+
extension.name = this.name
|
|
601
|
+
// Set the parent to be our parent
|
|
602
|
+
extension.parent = this.parent
|
|
600
603
|
|
|
601
604
|
return extension
|
|
602
605
|
}
|
|
@@ -604,7 +607,7 @@ export class Mark<Options = any, Storage = any> {
|
|
|
604
607
|
extend<ExtendedOptions = Options, ExtendedStorage = Storage>(
|
|
605
608
|
extendedConfig: Partial<MarkConfig<ExtendedOptions, ExtendedStorage>> = {},
|
|
606
609
|
) {
|
|
607
|
-
const extension = new Mark<ExtendedOptions, ExtendedStorage>(
|
|
610
|
+
const extension = new Mark<ExtendedOptions, ExtendedStorage>(extendedConfig)
|
|
608
611
|
|
|
609
612
|
extension.parent = this
|
|
610
613
|
|
|
@@ -612,7 +615,7 @@ export class Mark<Options = any, Storage = any> {
|
|
|
612
615
|
|
|
613
616
|
extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name
|
|
614
617
|
|
|
615
|
-
if (extendedConfig.defaultOptions) {
|
|
618
|
+
if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
|
|
616
619
|
console.warn(
|
|
617
620
|
`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`,
|
|
618
621
|
)
|
package/src/Node.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { Editor } from './Editor.js'
|
|
|
7
7
|
import { getExtensionField } from './helpers/getExtensionField.js'
|
|
8
8
|
import { NodeConfig } from './index.js'
|
|
9
9
|
import { InputRule } from './InputRule.js'
|
|
10
|
+
import { Mark } from './Mark.js'
|
|
10
11
|
import { PasteRule } from './PasteRule.js'
|
|
11
12
|
import {
|
|
12
13
|
AnyConfig,
|
|
@@ -23,6 +24,7 @@ import { mergeDeep } from './utilities/mergeDeep.js'
|
|
|
23
24
|
|
|
24
25
|
declare module '@tiptap/core' {
|
|
25
26
|
interface NodeConfig<Options = any, Storage = any> {
|
|
27
|
+
// @ts-ignore - this is a dynamic key
|
|
26
28
|
[key: string]: any
|
|
27
29
|
|
|
28
30
|
/**
|
|
@@ -111,8 +113,9 @@ declare module '@tiptap/core' {
|
|
|
111
113
|
name: string
|
|
112
114
|
options: Options
|
|
113
115
|
storage: Storage
|
|
116
|
+
extensions: (Node | Mark)[]
|
|
114
117
|
parent: ParentConfig<NodeConfig<Options, Storage>>['addGlobalAttributes']
|
|
115
|
-
}) => GlobalAttributes
|
|
118
|
+
}) => GlobalAttributes
|
|
116
119
|
|
|
117
120
|
/**
|
|
118
121
|
* This function adds commands to the editor
|
|
@@ -777,16 +780,17 @@ export class Node<Options = any, Storage = any> {
|
|
|
777
780
|
configure(options: Partial<Options> = {}) {
|
|
778
781
|
// return a new instance so we can use the same extension
|
|
779
782
|
// with different calls of `configure`
|
|
780
|
-
const extension = this.extend(
|
|
781
|
-
|
|
782
|
-
|
|
783
|
+
const extension = this.extend({
|
|
784
|
+
...this.config,
|
|
785
|
+
addOptions() {
|
|
786
|
+
return mergeDeep(this.parent?.() || {}, options) as Options
|
|
787
|
+
},
|
|
788
|
+
})
|
|
783
789
|
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
}),
|
|
789
|
-
)
|
|
790
|
+
// Always preserve the current name
|
|
791
|
+
extension.name = this.name
|
|
792
|
+
// Set the parent to be our parent
|
|
793
|
+
extension.parent = this.parent
|
|
790
794
|
|
|
791
795
|
return extension
|
|
792
796
|
}
|
|
@@ -794,7 +798,7 @@ export class Node<Options = any, Storage = any> {
|
|
|
794
798
|
extend<ExtendedOptions = Options, ExtendedStorage = Storage>(
|
|
795
799
|
extendedConfig: Partial<NodeConfig<ExtendedOptions, ExtendedStorage>> = {},
|
|
796
800
|
) {
|
|
797
|
-
const extension = new Node<ExtendedOptions, ExtendedStorage>(
|
|
801
|
+
const extension = new Node<ExtendedOptions, ExtendedStorage>(extendedConfig)
|
|
798
802
|
|
|
799
803
|
extension.parent = this
|
|
800
804
|
|
|
@@ -802,7 +806,7 @@ export class Node<Options = any, Storage = any> {
|
|
|
802
806
|
|
|
803
807
|
extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name
|
|
804
808
|
|
|
805
|
-
if (extendedConfig.defaultOptions) {
|
|
809
|
+
if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
|
|
806
810
|
console.warn(
|
|
807
811
|
`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`,
|
|
808
812
|
)
|
|
@@ -57,7 +57,7 @@ declare module '@tiptap/core' {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const isFragment = (nodeOrFragment: ProseMirrorNode | Fragment): nodeOrFragment is Fragment => {
|
|
60
|
-
return
|
|
60
|
+
return !('type' in nodeOrFragment)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export const insertContentAt: RawCommands['insertContentAt'] = (position, value, options) => ({ tr, dispatch, editor }) => {
|
|
@@ -10,7 +10,7 @@ export const Tabindex = Extension.create({
|
|
|
10
10
|
new Plugin({
|
|
11
11
|
key: new PluginKey('tabindex'),
|
|
12
12
|
props: {
|
|
13
|
-
attributes: this.editor.isEditable ? { tabindex: '0' } : {},
|
|
13
|
+
attributes: (): { [name: string]: string; } => (this.editor.isEditable ? { tabindex: '0' } : {}),
|
|
14
14
|
},
|
|
15
15
|
}),
|
|
16
16
|
]
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
Attributes,
|
|
6
6
|
ExtensionAttribute,
|
|
7
7
|
Extensions,
|
|
8
|
-
GlobalAttributes,
|
|
9
8
|
} from '../types.js'
|
|
10
9
|
import { getExtensionField } from './getExtensionField.js'
|
|
11
10
|
import { splitExtensions } from './splitExtensions.js'
|
|
@@ -32,6 +31,7 @@ export function getAttributesFromExtensions(extensions: Extensions): ExtensionAt
|
|
|
32
31
|
name: extension.name,
|
|
33
32
|
options: extension.options,
|
|
34
33
|
storage: extension.storage,
|
|
34
|
+
extensions: nodeAndMarkExtensions,
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const addGlobalAttributes = getExtensionField<AnyConfig['addGlobalAttributes']>(
|
|
@@ -44,8 +44,7 @@ export function getAttributesFromExtensions(extensions: Extensions): ExtensionAt
|
|
|
44
44
|
return
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
const globalAttributes = addGlobalAttributes() as GlobalAttributes
|
|
47
|
+
const globalAttributes = addGlobalAttributes()
|
|
49
48
|
|
|
50
49
|
globalAttributes.forEach(globalAttribute => {
|
|
51
50
|
globalAttribute.types.forEach(type => {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
MarkSpec, NodeSpec, Schema, TagParseRule,
|
|
3
|
+
} from '@tiptap/pm/model'
|
|
2
4
|
|
|
3
5
|
import { Editor, MarkConfig, NodeConfig } from '../index.js'
|
|
4
6
|
import { AnyConfig, Extensions } from '../types.js'
|
|
@@ -75,6 +77,7 @@ export function getSchemaByResolvedExtensions(extensions: Extensions, editor?: E
|
|
|
75
77
|
getExtensionField<NodeConfig['draggable']>(extension, 'draggable', context),
|
|
76
78
|
),
|
|
77
79
|
code: callOrReturn(getExtensionField<NodeConfig['code']>(extension, 'code', context)),
|
|
80
|
+
whitespace: callOrReturn(getExtensionField<NodeConfig['whitespace']>(extension, 'whitespace', context)),
|
|
78
81
|
defining: callOrReturn(
|
|
79
82
|
getExtensionField<NodeConfig['defining']>(extension, 'defining', context),
|
|
80
83
|
),
|
|
@@ -93,7 +96,7 @@ export function getSchemaByResolvedExtensions(extensions: Extensions, editor?: E
|
|
|
93
96
|
)
|
|
94
97
|
|
|
95
98
|
if (parseHTML) {
|
|
96
|
-
schema.parseDOM = parseHTML.map(parseRule => injectExtensionAttributesToParseRule(parseRule, extensionAttributes))
|
|
99
|
+
schema.parseDOM = parseHTML.map(parseRule => injectExtensionAttributesToParseRule(parseRule, extensionAttributes)) as TagParseRule[]
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
const renderHTML = getExtensionField<NodeConfig['renderHTML']>(
|
|
@@ -13,13 +13,13 @@ export function injectExtensionAttributesToParseRule(
|
|
|
13
13
|
parseRule: ParseRule,
|
|
14
14
|
extensionAttributes: ExtensionAttribute[],
|
|
15
15
|
): ParseRule {
|
|
16
|
-
if (parseRule
|
|
16
|
+
if ('style' in parseRule) {
|
|
17
17
|
return parseRule
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
return {
|
|
21
21
|
...parseRule,
|
|
22
|
-
getAttrs: node => {
|
|
22
|
+
getAttrs: (node: HTMLElement) => {
|
|
23
23
|
const oldAttributes = parseRule.getAttrs ? parseRule.getAttrs(node) : parseRule.attrs
|
|
24
24
|
|
|
25
25
|
if (oldAttributes === false) {
|
|
@@ -28,8 +28,8 @@ export function injectExtensionAttributesToParseRule(
|
|
|
28
28
|
|
|
29
29
|
const newAttributes = extensionAttributes.reduce((items, item) => {
|
|
30
30
|
const value = item.attribute.parseHTML
|
|
31
|
-
? item.attribute.parseHTML(node
|
|
32
|
-
: fromString((node
|
|
31
|
+
? item.attribute.parseHTML(node)
|
|
32
|
+
: fromString((node).getAttribute(item.name))
|
|
33
33
|
|
|
34
34
|
if (value === null || value === undefined) {
|
|
35
35
|
return items
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
export function isNodeEmpty(node: ProseMirrorNode): boolean {
|
|
4
|
-
const defaultContent = node.type.createAndFill()
|
|
5
|
-
const content = node.toJSON()
|
|
4
|
+
const defaultContent = node.type.createAndFill()
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
if (!defaultContent) {
|
|
7
|
+
return false
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return node.eq(defaultContent)
|
|
8
11
|
}
|
package/src/types.ts
CHANGED
|
@@ -152,7 +152,13 @@ export type ExtensionAttribute = {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
export type GlobalAttributes = {
|
|
155
|
+
/**
|
|
156
|
+
* The node & mark types this attribute should be applied to.
|
|
157
|
+
*/
|
|
155
158
|
types: string[]
|
|
159
|
+
/**
|
|
160
|
+
* The attributes to add to the node or mark types.
|
|
161
|
+
*/
|
|
156
162
|
attributes: {
|
|
157
163
|
[key: string]: Attribute
|
|
158
164
|
}
|
|
@@ -5,14 +5,10 @@ export function mergeDeep(target: Record<string, any>, source: Record<string, an
|
|
|
5
5
|
|
|
6
6
|
if (isPlainObject(target) && isPlainObject(source)) {
|
|
7
7
|
Object.keys(source).forEach(key => {
|
|
8
|
-
if (isPlainObject(source[key])) {
|
|
9
|
-
|
|
10
|
-
Object.assign(output, { [key]: source[key] })
|
|
11
|
-
} else {
|
|
12
|
-
output[key] = mergeDeep(target[key], source[key])
|
|
13
|
-
}
|
|
8
|
+
if (isPlainObject(source[key]) && isPlainObject(target[key])) {
|
|
9
|
+
output[key] = mergeDeep(target[key], source[key])
|
|
14
10
|
} else {
|
|
15
|
-
|
|
11
|
+
output[key] = source[key]
|
|
16
12
|
}
|
|
17
13
|
})
|
|
18
14
|
}
|