@tiptap/core 3.0.0-next.0 → 3.0.0-next.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/dist/index.cjs +4675 -4581
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3452 -0
- package/dist/index.d.ts +3452 -0
- package/dist/index.js +4574 -4483
- package/dist/index.js.map +1 -1
- package/package.json +6 -8
- package/src/Editor.ts +6 -0
- package/src/Extension.ts +4 -3
- package/src/ExtensionManager.ts +2 -1
- package/src/Mark.ts +4 -3
- package/src/Node.ts +4 -3
- package/src/commands/setMeta.ts +3 -1
- package/src/commands/splitListItem.ts +27 -17
- package/src/helpers/getAttributesFromExtensions.ts +1 -1
- package/src/helpers/getMarksBetween.ts +1 -1
- package/src/helpers/getSchemaByResolvedExtensions.ts +1 -1
- package/src/helpers/isList.ts +1 -1
- package/src/helpers/isNodeEmpty.ts +33 -12
- package/src/pasteRules/nodePasteRule.ts +14 -5
- package/src/style.ts +2 -2
- package/dist/index.umd.js +0 -5130
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -159
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -343
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -451
- package/dist/packages/core/src/Node.d.ts +0 -611
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- 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 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- 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 -9
- 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/getNodeAtPosition.d.ts +0 -11
- 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 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- 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/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.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 -8
- 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 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -253
- 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/isAndroid.d.ts +0 -1
- 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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/core",
|
|
3
3
|
"description": "headless rich text editor",
|
|
4
|
-
"version": "3.0.0-next.
|
|
4
|
+
"version": "3.0.0-next.1",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -18,24 +18,23 @@
|
|
|
18
18
|
"type": "module",
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
-
"types": "./dist/
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
22
|
"import": "./dist/index.js",
|
|
23
23
|
"require": "./dist/index.cjs"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"main": "dist/index.cjs",
|
|
27
27
|
"module": "dist/index.js",
|
|
28
|
-
"
|
|
29
|
-
"types": "dist/packages/core/src/index.d.ts",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
30
29
|
"files": [
|
|
31
30
|
"src",
|
|
32
31
|
"dist"
|
|
33
32
|
],
|
|
34
33
|
"devDependencies": {
|
|
35
|
-
"@tiptap/pm": "^3.0.0-next.
|
|
34
|
+
"@tiptap/pm": "^3.0.0-next.1"
|
|
36
35
|
},
|
|
37
36
|
"peerDependencies": {
|
|
38
|
-
"@tiptap/pm": "^3.0.0-next.
|
|
37
|
+
"@tiptap/pm": "^3.0.0-next.1"
|
|
39
38
|
},
|
|
40
39
|
"repository": {
|
|
41
40
|
"type": "git",
|
|
@@ -44,7 +43,6 @@
|
|
|
44
43
|
},
|
|
45
44
|
"sideEffects": false,
|
|
46
45
|
"scripts": {
|
|
47
|
-
"
|
|
48
|
-
"build": "npm run clean && rollup -c"
|
|
46
|
+
"build": "tsup"
|
|
49
47
|
}
|
|
50
48
|
}
|
package/src/Editor.ts
CHANGED
|
@@ -57,6 +57,11 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
57
57
|
|
|
58
58
|
public isFocused = false
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* The editor is considered initialized after the `create` event has been emitted.
|
|
62
|
+
*/
|
|
63
|
+
public isInitialized = false
|
|
64
|
+
|
|
60
65
|
public extensionStorage: Record<string, any> = {}
|
|
61
66
|
|
|
62
67
|
public options: EditorOptions = {
|
|
@@ -111,6 +116,7 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
111
116
|
|
|
112
117
|
this.commands.focus(this.options.autofocus)
|
|
113
118
|
this.emit('create', { editor: this })
|
|
119
|
+
this.isInitialized = true
|
|
114
120
|
}, 0)
|
|
115
121
|
}
|
|
116
122
|
|
package/src/Extension.ts
CHANGED
|
@@ -32,10 +32,10 @@ declare module '@tiptap/core' {
|
|
|
32
32
|
name: string
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* The priority of your extension. The higher, the
|
|
35
|
+
* The priority of your extension. The higher, the earlier it will be called
|
|
36
36
|
* and will take precedence over other extensions with a lower priority.
|
|
37
|
-
* @default
|
|
38
|
-
* @example
|
|
37
|
+
* @default 100
|
|
38
|
+
* @example 101
|
|
39
39
|
*/
|
|
40
40
|
priority?: number
|
|
41
41
|
|
|
@@ -339,6 +339,7 @@ declare module '@tiptap/core' {
|
|
|
339
339
|
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onTransaction']
|
|
340
340
|
},
|
|
341
341
|
props: {
|
|
342
|
+
editor: Editor
|
|
342
343
|
transaction: Transaction
|
|
343
344
|
},
|
|
344
345
|
) => void)
|
package/src/ExtensionManager.ts
CHANGED
|
@@ -12,8 +12,9 @@ import { getSchemaByResolvedExtensions } from './helpers/getSchemaByResolvedExte
|
|
|
12
12
|
import { getSchemaTypeByName } from './helpers/getSchemaTypeByName.js'
|
|
13
13
|
import { isExtensionRulesEnabled } from './helpers/isExtensionRulesEnabled.js'
|
|
14
14
|
import { splitExtensions } from './helpers/splitExtensions.js'
|
|
15
|
-
import {
|
|
15
|
+
import type { NodeConfig } from './index.js'
|
|
16
16
|
import { InputRule, inputRulesPlugin } from './InputRule.js'
|
|
17
|
+
import { Mark } from './Mark.js'
|
|
17
18
|
import { PasteRule, pasteRulesPlugin } from './PasteRule.js'
|
|
18
19
|
import { AnyConfig, Extensions, RawCommands } from './types.js'
|
|
19
20
|
import { callOrReturn } from './utilities/callOrReturn.js'
|
package/src/Mark.ts
CHANGED
|
@@ -35,10 +35,10 @@ declare module '@tiptap/core' {
|
|
|
35
35
|
name: string
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* The priority of your extension. The higher, the
|
|
38
|
+
* The priority of your extension. The higher, the earlier it will be called
|
|
39
39
|
* and will take precedence over other extensions with a lower priority.
|
|
40
|
-
* @default
|
|
41
|
-
* @example
|
|
40
|
+
* @default 100
|
|
41
|
+
* @example 101
|
|
42
42
|
*/
|
|
43
43
|
priority?: number
|
|
44
44
|
|
|
@@ -352,6 +352,7 @@ declare module '@tiptap/core' {
|
|
|
352
352
|
parent: ParentConfig<MarkConfig<Options, Storage>>['onTransaction']
|
|
353
353
|
},
|
|
354
354
|
props: {
|
|
355
|
+
editor: Editor
|
|
355
356
|
transaction: Transaction
|
|
356
357
|
},
|
|
357
358
|
) => void)
|
package/src/Node.ts
CHANGED
|
@@ -36,10 +36,10 @@ declare module '@tiptap/core' {
|
|
|
36
36
|
name: string
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* The priority of your extension. The higher, the
|
|
39
|
+
* The priority of your extension. The higher, the earlier it will be called
|
|
40
40
|
* and will take precedence over other extensions with a lower priority.
|
|
41
|
-
* @default
|
|
42
|
-
* @example
|
|
41
|
+
* @default 100
|
|
42
|
+
* @example 101
|
|
43
43
|
*/
|
|
44
44
|
priority?: number
|
|
45
45
|
|
|
@@ -354,6 +354,7 @@ declare module '@tiptap/core' {
|
|
|
354
354
|
parent: ParentConfig<NodeConfig<Options, Storage>>['onTransaction']
|
|
355
355
|
},
|
|
356
356
|
props: {
|
|
357
|
+
editor: Editor
|
|
357
358
|
transaction: Transaction
|
|
358
359
|
},
|
|
359
360
|
) => void)
|
package/src/commands/setMeta.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Plugin, PluginKey } from '@tiptap/pm/state'
|
|
2
|
+
|
|
1
3
|
import { RawCommands } from '../types.js'
|
|
2
4
|
|
|
3
5
|
declare module '@tiptap/core' {
|
|
@@ -9,7 +11,7 @@ declare module '@tiptap/core' {
|
|
|
9
11
|
* @param value The value to store.
|
|
10
12
|
* @example editor.commands.setMeta('foo', 'bar')
|
|
11
13
|
*/
|
|
12
|
-
setMeta: (key: string, value: any) => ReturnType,
|
|
14
|
+
setMeta: (key: string | Plugin | PluginKey, value: any) => ReturnType,
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
}
|
|
@@ -14,14 +14,15 @@ declare module '@tiptap/core' {
|
|
|
14
14
|
/**
|
|
15
15
|
* Splits one list item into two list items.
|
|
16
16
|
* @param typeOrName The type or name of the node.
|
|
17
|
+
* @param overrideAttrs The attributes to ensure on the new node.
|
|
17
18
|
* @example editor.commands.splitListItem('listItem')
|
|
18
19
|
*/
|
|
19
|
-
splitListItem: (typeOrName: string | NodeType) => ReturnType
|
|
20
|
+
splitListItem: (typeOrName: string | NodeType, overrideAttrs?: Record<string, any>) => ReturnType
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
|
|
25
|
+
export const splitListItem: RawCommands['splitListItem'] = (typeOrName, overrideAttrs = {}) => ({
|
|
25
26
|
tr, state, dispatch, editor,
|
|
26
27
|
}) => {
|
|
27
28
|
const type = getNodeType(typeOrName, state.schema)
|
|
@@ -70,11 +71,14 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
|
|
|
70
71
|
const depthAfter = $from.indexAfter(-1) < $from.node(-2).childCount ? 1 : $from.indexAfter(-2) < $from.node(-3).childCount ? 2 : 3
|
|
71
72
|
|
|
72
73
|
// Add a second list item with an empty default start node
|
|
73
|
-
const newNextTypeAttributes =
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
const newNextTypeAttributes = {
|
|
75
|
+
...getSplittedAttributes(
|
|
76
|
+
extensionAttributes,
|
|
77
|
+
$from.node().type.name,
|
|
78
|
+
$from.node().attrs,
|
|
79
|
+
),
|
|
80
|
+
...overrideAttrs,
|
|
81
|
+
}
|
|
78
82
|
const nextType = type.contentMatch.defaultType?.createAndFill(newNextTypeAttributes) || undefined
|
|
79
83
|
|
|
80
84
|
wrap = wrap.append(Fragment.from(type.createAndFill(null, nextType) || undefined))
|
|
@@ -107,16 +111,22 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
|
|
|
107
111
|
|
|
108
112
|
const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null
|
|
109
113
|
|
|
110
|
-
const newTypeAttributes =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
114
|
+
const newTypeAttributes = {
|
|
115
|
+
...getSplittedAttributes(
|
|
116
|
+
extensionAttributes,
|
|
117
|
+
grandParent.type.name,
|
|
118
|
+
grandParent.attrs,
|
|
119
|
+
),
|
|
120
|
+
...overrideAttrs,
|
|
121
|
+
}
|
|
122
|
+
const newNextTypeAttributes = {
|
|
123
|
+
...getSplittedAttributes(
|
|
124
|
+
extensionAttributes,
|
|
125
|
+
$from.node().type.name,
|
|
126
|
+
$from.node().attrs,
|
|
127
|
+
),
|
|
128
|
+
...overrideAttrs,
|
|
129
|
+
}
|
|
120
130
|
|
|
121
131
|
tr.delete($from.pos, $to.pos)
|
|
122
132
|
|
|
@@ -12,7 +12,7 @@ export function getMarksBetween(from: number, to: number, doc: ProseMirrorNode):
|
|
|
12
12
|
.resolve(from)
|
|
13
13
|
.marks()
|
|
14
14
|
.forEach(mark => {
|
|
15
|
-
const $pos = doc.resolve(from
|
|
15
|
+
const $pos = doc.resolve(from)
|
|
16
16
|
const range = getMarkRange($pos, mark.type)
|
|
17
17
|
|
|
18
18
|
if (!range) {
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
MarkSpec, NodeSpec, Schema, TagParseRule,
|
|
3
3
|
} from '@tiptap/pm/model'
|
|
4
4
|
|
|
5
|
-
import { Editor, MarkConfig, NodeConfig } from '../index.js'
|
|
5
|
+
import type { Editor, MarkConfig, NodeConfig } from '../index.js'
|
|
6
6
|
import { AnyConfig, Extensions } from '../types.js'
|
|
7
7
|
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
8
8
|
import { isEmptyObject } from '../utilities/isEmptyObject.js'
|
package/src/helpers/isList.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getExtensionField } from '../helpers/getExtensionField.js'
|
|
2
|
-
import { NodeConfig } from '../index.js'
|
|
2
|
+
import type { NodeConfig } from '../index.js'
|
|
3
3
|
import { Extensions } from '../types.js'
|
|
4
4
|
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
5
5
|
import { splitExtensions } from './splitExtensions.js'
|
|
@@ -1,40 +1,61 @@
|
|
|
1
1
|
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Returns true if the given node is empty.
|
|
5
|
-
* When `checkChildren` is true (default), it will also check if all children are empty.
|
|
4
|
+
* Returns true if the given prosemirror node is empty.
|
|
6
5
|
*/
|
|
7
6
|
export function isNodeEmpty(
|
|
8
7
|
node: ProseMirrorNode,
|
|
9
|
-
{
|
|
8
|
+
{
|
|
9
|
+
checkChildren = true,
|
|
10
|
+
ignoreWhitespace = false,
|
|
11
|
+
}: {
|
|
12
|
+
/**
|
|
13
|
+
* When true (default), it will also check if all children are empty.
|
|
14
|
+
*/
|
|
15
|
+
checkChildren?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* When true, it will ignore whitespace when checking for emptiness.
|
|
18
|
+
*/
|
|
19
|
+
ignoreWhitespace?: boolean;
|
|
20
|
+
} = {},
|
|
10
21
|
): boolean {
|
|
22
|
+
if (ignoreWhitespace) {
|
|
23
|
+
if (node.type.name === 'hardBreak') {
|
|
24
|
+
// Hard breaks are considered empty
|
|
25
|
+
return true
|
|
26
|
+
}
|
|
27
|
+
if (node.isText) {
|
|
28
|
+
return /^\s*$/m.test(node.text ?? '')
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
11
32
|
if (node.isText) {
|
|
12
33
|
return !node.text
|
|
13
34
|
}
|
|
14
35
|
|
|
15
|
-
if (node.
|
|
16
|
-
return
|
|
36
|
+
if (node.isAtom || node.isLeaf) {
|
|
37
|
+
return false
|
|
17
38
|
}
|
|
18
39
|
|
|
19
|
-
if (node.
|
|
20
|
-
return
|
|
40
|
+
if (node.content.childCount === 0) {
|
|
41
|
+
return true
|
|
21
42
|
}
|
|
22
43
|
|
|
23
44
|
if (checkChildren) {
|
|
24
|
-
let
|
|
45
|
+
let isContentEmpty = true
|
|
25
46
|
|
|
26
47
|
node.content.forEach(childNode => {
|
|
27
|
-
if (
|
|
48
|
+
if (isContentEmpty === false) {
|
|
28
49
|
// Exit early for perf
|
|
29
50
|
return
|
|
30
51
|
}
|
|
31
52
|
|
|
32
|
-
if (!isNodeEmpty(childNode)) {
|
|
33
|
-
|
|
53
|
+
if (!isNodeEmpty(childNode, { ignoreWhitespace, checkChildren })) {
|
|
54
|
+
isContentEmpty = false
|
|
34
55
|
}
|
|
35
56
|
})
|
|
36
57
|
|
|
37
|
-
return
|
|
58
|
+
return isContentEmpty
|
|
38
59
|
}
|
|
39
60
|
|
|
40
61
|
return false
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NodeType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { PasteRule, PasteRuleFinder } from '../PasteRule.js'
|
|
4
|
-
import { ExtendedRegExpMatchArray } from '../types.js'
|
|
4
|
+
import { ExtendedRegExpMatchArray, JSONContent } from '../types.js'
|
|
5
5
|
import { callOrReturn } from '../utilities/index.js'
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -17,6 +17,11 @@ export function nodePasteRule(config: {
|
|
|
17
17
|
| ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>)
|
|
18
18
|
| false
|
|
19
19
|
| null
|
|
20
|
+
getContent?:
|
|
21
|
+
| JSONContent[]
|
|
22
|
+
| ((attrs: Record<string, any>) => JSONContent[])
|
|
23
|
+
| false
|
|
24
|
+
| null
|
|
20
25
|
}) {
|
|
21
26
|
return new PasteRule({
|
|
22
27
|
find: config.find,
|
|
@@ -24,16 +29,20 @@ export function nodePasteRule(config: {
|
|
|
24
29
|
match, chain, range, pasteEvent,
|
|
25
30
|
}) {
|
|
26
31
|
const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)
|
|
32
|
+
const content = callOrReturn(config.getContent, undefined, attributes)
|
|
27
33
|
|
|
28
34
|
if (attributes === false || attributes === null) {
|
|
29
35
|
return null
|
|
30
36
|
}
|
|
31
37
|
|
|
38
|
+
const node = { type: config.type.name, attrs: attributes } as JSONContent
|
|
39
|
+
|
|
40
|
+
if (content) {
|
|
41
|
+
node.content = content
|
|
42
|
+
}
|
|
43
|
+
|
|
32
44
|
if (match.input) {
|
|
33
|
-
chain().deleteRange(range).insertContentAt(range.from,
|
|
34
|
-
type: config.type.name,
|
|
35
|
-
attrs: attributes,
|
|
36
|
-
})
|
|
45
|
+
chain().deleteRange(range).insertContentAt(range.from, node)
|
|
37
46
|
}
|
|
38
47
|
},
|
|
39
48
|
})
|
package/src/style.ts
CHANGED