@tiptap/core 2.1.2 → 2.1.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 +5 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -27
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +5 -29
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -10
- package/package.json +2 -2
- package/src/inputRules/nodeInputRule.ts +6 -40
|
@@ -14,16 +14,6 @@ export declare function nodeInputRule(config: {
|
|
|
14
14
|
* The node type to add.
|
|
15
15
|
*/
|
|
16
16
|
type: NodeType;
|
|
17
|
-
/**
|
|
18
|
-
* Should the input rule replace the node or append to it
|
|
19
|
-
* If true, the node will be replaced
|
|
20
|
-
*/
|
|
21
|
-
blockReplace?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Insert empty paragraph after inserting the node
|
|
24
|
-
* Only works if blockReplace is true
|
|
25
|
-
*/
|
|
26
|
-
addExtraNewline?: boolean;
|
|
27
17
|
/**
|
|
28
18
|
* A function that returns the attributes for the node
|
|
29
19
|
* can also be an object of attributes
|
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.1.
|
|
4
|
+
"version": "2.1.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.1.
|
|
35
|
+
"@tiptap/pm": "^2.1.4"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@tiptap/pm": "^2.0.0"
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { NodeType } from '@tiptap/pm/model'
|
|
2
|
-
import { NodeSelection, TextSelection } from '@tiptap/pm/state'
|
|
3
2
|
|
|
4
3
|
import { InputRule, InputRuleFinder } from '../InputRule.js'
|
|
5
4
|
import { ExtendedRegExpMatchArray } from '../types.js'
|
|
@@ -20,18 +19,6 @@ export function nodeInputRule(config: {
|
|
|
20
19
|
*/
|
|
21
20
|
type: NodeType
|
|
22
21
|
|
|
23
|
-
/**
|
|
24
|
-
* Should the input rule replace the node or append to it
|
|
25
|
-
* If true, the node will be replaced
|
|
26
|
-
*/
|
|
27
|
-
blockReplace?: boolean
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Insert empty paragraph after inserting the node
|
|
31
|
-
* Only works if blockReplace is true
|
|
32
|
-
*/
|
|
33
|
-
addExtraNewline?: boolean
|
|
34
|
-
|
|
35
22
|
/**
|
|
36
23
|
* A function that returns the attributes for the node
|
|
37
24
|
* can also be an object of attributes
|
|
@@ -47,13 +34,11 @@ export function nodeInputRule(config: {
|
|
|
47
34
|
handler: ({ state, range, match }) => {
|
|
48
35
|
const attributes = callOrReturn(config.getAttributes, undefined, match) || {}
|
|
49
36
|
const { tr } = state
|
|
50
|
-
const start =
|
|
37
|
+
const start = range.from
|
|
51
38
|
let end = range.to
|
|
52
39
|
|
|
53
40
|
const newNode = config.type.create(attributes)
|
|
54
41
|
|
|
55
|
-
const { $to } = tr.selection
|
|
56
|
-
|
|
57
42
|
if (match[1]) {
|
|
58
43
|
const offset = match[0].lastIndexOf(match[1])
|
|
59
44
|
let matchStart = start + offset
|
|
@@ -72,32 +57,13 @@ export function nodeInputRule(config: {
|
|
|
72
57
|
// insert node from input rule
|
|
73
58
|
tr.replaceWith(matchStart, end, newNode)
|
|
74
59
|
} else if (match[0]) {
|
|
75
|
-
tr.
|
|
60
|
+
tr.insert(start - 1, config.type.create(attributes)).delete(
|
|
61
|
+
tr.mapping.map(start),
|
|
62
|
+
tr.mapping.map(end),
|
|
63
|
+
)
|
|
76
64
|
}
|
|
77
65
|
|
|
78
|
-
|
|
79
|
-
if ($to.nodeAfter) {
|
|
80
|
-
if ($to.nodeAfter.isTextblock) {
|
|
81
|
-
tr.setSelection(TextSelection.create(tr.doc, $to.pos + 1))
|
|
82
|
-
} else if ($to.nodeAfter.isBlock) {
|
|
83
|
-
tr.setSelection(NodeSelection.create(tr.doc, $to.pos))
|
|
84
|
-
} else {
|
|
85
|
-
tr.setSelection(TextSelection.create(tr.doc, $to.pos - 1))
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
// add node after horizontal rule if it’s the end of the document
|
|
89
|
-
const defaultNode = $to.parent.type.contentMatch.defaultType?.create() || state.doc.type.contentMatch.defaultType?.create()
|
|
90
|
-
|
|
91
|
-
if (defaultNode) {
|
|
92
|
-
const newPos = start + newNode.nodeSize
|
|
93
|
-
|
|
94
|
-
tr.insert(newPos, defaultNode)
|
|
95
|
-
tr.setSelection(TextSelection.create(tr.doc, newPos))
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
tr.scrollIntoView()
|
|
100
|
-
}
|
|
66
|
+
tr.scrollIntoView()
|
|
101
67
|
},
|
|
102
68
|
})
|
|
103
69
|
}
|