@tiptap/core 3.0.0-beta.13 → 3.0.0-beta.15
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 +31 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +30 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/NodePos.ts +6 -0
- package/src/utilities/canInsertNode.ts +30 -0
- package/src/utilities/index.ts +1 -0
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-beta.
|
|
4
|
+
"version": "3.0.0-beta.15",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"jsx-dev-runtime"
|
|
53
53
|
],
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@tiptap/pm": "3.0.0-beta.
|
|
55
|
+
"@tiptap/pm": "3.0.0-beta.15"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@tiptap/pm": "3.0.0-beta.
|
|
58
|
+
"@tiptap/pm": "3.0.0-beta.15"
|
|
59
59
|
},
|
|
60
60
|
"repository": {
|
|
61
61
|
"type": "git",
|
package/src/NodePos.ts
CHANGED
|
@@ -136,6 +136,12 @@ export class NodePos {
|
|
|
136
136
|
const isNonTextAtom = node.isAtom && !node.isText
|
|
137
137
|
|
|
138
138
|
const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1)
|
|
139
|
+
|
|
140
|
+
// Check if targetPos is within valid document range
|
|
141
|
+
if (targetPos < 0 || targetPos > this.resolvedPos.doc.nodeSize - 2) {
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
|
|
139
145
|
const $pos = this.resolvedPos.doc.resolve(targetPos)
|
|
140
146
|
|
|
141
147
|
if (!isBlock && $pos.depth <= this.depth) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import { type EditorState, NodeSelection } from '@tiptap/pm/state'
|
|
3
|
+
|
|
4
|
+
export function canInsertNode(state: EditorState, nodeType: NodeType): boolean {
|
|
5
|
+
const { selection } = state
|
|
6
|
+
const { $from } = selection
|
|
7
|
+
|
|
8
|
+
// Special handling for NodeSelection
|
|
9
|
+
if (selection instanceof NodeSelection) {
|
|
10
|
+
const index = $from.index()
|
|
11
|
+
const parent = $from.parent
|
|
12
|
+
|
|
13
|
+
// Can we replace the selected node with the horizontal rule?
|
|
14
|
+
return parent.canReplaceWith(index, index + 1, nodeType)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Default: check if we can insert at the current position
|
|
18
|
+
let depth = $from.depth
|
|
19
|
+
|
|
20
|
+
while (depth >= 0) {
|
|
21
|
+
const index = $from.index(depth)
|
|
22
|
+
const parent = $from.node(depth)
|
|
23
|
+
const match = parent.contentMatchAt(index)
|
|
24
|
+
if (match.matchType(nodeType)) {
|
|
25
|
+
return true
|
|
26
|
+
}
|
|
27
|
+
depth -= 1
|
|
28
|
+
}
|
|
29
|
+
return false
|
|
30
|
+
}
|