@tiptap/core 2.22.1 → 2.22.3
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/NodePos.d.ts.map +1 -1
- package/dist/index.cjs +29 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +29 -0
- package/dist/index.umd.js.map +1 -1
- package/dist/utilities/canInsertNode.d.ts +4 -0
- package/dist/utilities/canInsertNode.d.ts.map +1 -0
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/NodePos.ts +6 -0
- package/src/utilities/canInsertNode.ts +31 -0
- package/src/utilities/index.ts +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canInsertNode.d.ts","sourceRoot":"","sources":["../../src/utilities/canInsertNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,kBAAkB,CAAA;AAElE,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CA2B7E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA"}
|
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.22.
|
|
4
|
+
"version": "2.22.3",
|
|
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.22.
|
|
35
|
+
"@tiptap/pm": "^2.22.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@tiptap/pm": "^2.7.0"
|
package/src/NodePos.ts
CHANGED
|
@@ -138,6 +138,12 @@ export class NodePos {
|
|
|
138
138
|
const isNonTextAtom = node.isAtom && !node.isText
|
|
139
139
|
|
|
140
140
|
const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1)
|
|
141
|
+
|
|
142
|
+
// Check if targetPos is within valid document range
|
|
143
|
+
if (targetPos < 0 || targetPos > this.resolvedPos.doc.nodeSize - 2) {
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
|
|
141
147
|
const $pos = this.resolvedPos.doc.resolve(targetPos)
|
|
142
148
|
|
|
143
149
|
if (!isBlock && $pos.depth <= this.depth) {
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
|
|
25
|
+
if (match.matchType(nodeType)) {
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
depth -= 1
|
|
29
|
+
}
|
|
30
|
+
return false
|
|
31
|
+
}
|