@tiptap/core 2.22.2 → 2.23.0

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.
@@ -0,0 +1,4 @@
1
+ import type { NodeType } from '@tiptap/pm/model';
2
+ import { type EditorState } from '@tiptap/pm/state';
3
+ export declare function canInsertNode(state: EditorState, nodeType: NodeType): boolean;
4
+ //# sourceMappingURL=canInsertNode.d.ts.map
@@ -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,4 +1,5 @@
1
1
  export * from './callOrReturn.js';
2
+ export * from './canInsertNode.js';
2
3
  export * from './createStyleTag.js';
3
4
  export * from './deleteProps.js';
4
5
  export * from './elementFromString.js';
@@ -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.2",
4
+ "version": "2.23.0",
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.2"
35
+ "@tiptap/pm": "^2.23.0"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@tiptap/pm": "^2.7.0"
package/src/PasteRule.ts CHANGED
@@ -277,7 +277,7 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
277
277
  if (!isDroppedFromProseMirror) {
278
278
  const dragFromOtherEditor = tiptapDragFromOtherEditor
279
279
 
280
- if (dragFromOtherEditor) {
280
+ if (dragFromOtherEditor?.isEditable) {
281
281
  // setTimeout to avoid the wrong content after drop, timeout arg can't be empty or 0
282
282
  setTimeout(() => {
283
283
  const selection = dragFromOtherEditor.state.selection
@@ -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
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './callOrReturn.js'
2
+ export * from './canInsertNode.js'
2
3
  export * from './createStyleTag.js'
3
4
  export * from './deleteProps.js'
4
5
  export * from './elementFromString.js'