@tiptap/core 2.0.0-beta.134 → 2.0.0-beta.138
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/packages/core/src/Editor.d.ts +2 -2
- package/dist/tiptap-core.cjs.js +11 -12
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +11 -12
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +11 -12
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/Editor.ts +2 -3
- package/src/commands/insertContentAt.ts +13 -6
- package/dist/packages/core/src/utilities/removeElement.d.ts +0 -1
- package/src/utilities/removeElement.ts +0 -5
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.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.138",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"url": "https://github.com/ueberdosis/tiptap",
|
|
45
45
|
"directory": "packages/core"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "893f87047d3e8a31b19f88f1ce6d4544492f7edc"
|
|
48
48
|
}
|
package/src/Editor.ts
CHANGED
|
@@ -8,7 +8,6 @@ import { EditorView } from 'prosemirror-view'
|
|
|
8
8
|
import { Schema, MarkType, NodeType } from 'prosemirror-model'
|
|
9
9
|
import getAttributes from './helpers/getAttributes'
|
|
10
10
|
import isActive from './helpers/isActive'
|
|
11
|
-
import removeElement from './utilities/removeElement'
|
|
12
11
|
import createDocument from './helpers/createDocument'
|
|
13
12
|
import getHTMLFromFragment from './helpers/getHTMLFromFragment'
|
|
14
13
|
import getText from './helpers/getText'
|
|
@@ -23,6 +22,7 @@ import {
|
|
|
23
22
|
EditorOptions,
|
|
24
23
|
CanCommands,
|
|
25
24
|
ChainedCommands,
|
|
25
|
+
JSONContent,
|
|
26
26
|
SingleCommands,
|
|
27
27
|
TextSerializer,
|
|
28
28
|
EditorEvents,
|
|
@@ -402,7 +402,7 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
402
402
|
/**
|
|
403
403
|
* Get the document as JSON.
|
|
404
404
|
*/
|
|
405
|
-
public getJSON():
|
|
405
|
+
public getJSON(): JSONContent {
|
|
406
406
|
return this.state.doc.toJSON()
|
|
407
407
|
}
|
|
408
408
|
|
|
@@ -459,7 +459,6 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
459
459
|
}
|
|
460
460
|
|
|
461
461
|
this.removeAllListeners()
|
|
462
|
-
removeElement(this.css)
|
|
463
462
|
}
|
|
464
463
|
|
|
465
464
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParseOptions } from 'prosemirror-model'
|
|
1
|
+
import { Fragment, Node as ProseMirrorNode, ParseOptions } from 'prosemirror-model'
|
|
2
2
|
import createNodeFromContent from '../helpers/createNodeFromContent'
|
|
3
3
|
import selectionToInsertionEnd from '../helpers/selectionToInsertionEnd'
|
|
4
4
|
import {
|
|
@@ -25,6 +25,10 @@ declare module '@tiptap/core' {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
const isFragment = (nodeOrFragment: ProseMirrorNode | Fragment): nodeOrFragment is Fragment => {
|
|
29
|
+
return nodeOrFragment.toString().startsWith('<')
|
|
30
|
+
}
|
|
31
|
+
|
|
28
32
|
export const insertContentAt: RawCommands['insertContentAt'] = (position, value, options) => ({ tr, dispatch, editor }) => {
|
|
29
33
|
if (dispatch) {
|
|
30
34
|
options = {
|
|
@@ -50,8 +54,11 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value,
|
|
|
50
54
|
: position
|
|
51
55
|
|
|
52
56
|
let isOnlyBlockContent = true
|
|
57
|
+
const nodes = isFragment(content)
|
|
58
|
+
? content
|
|
59
|
+
: [content]
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
nodes.forEach(node => {
|
|
55
62
|
isOnlyBlockContent = isOnlyBlockContent
|
|
56
63
|
? node.isBlock
|
|
57
64
|
: false
|
|
@@ -63,10 +70,10 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value,
|
|
|
63
70
|
// replace an empty paragraph by an inserted image
|
|
64
71
|
// instead of inserting the image below the paragraph
|
|
65
72
|
if (from === to && isOnlyBlockContent) {
|
|
66
|
-
const
|
|
67
|
-
const isEmptyTextBlock =
|
|
68
|
-
&&
|
|
69
|
-
&&
|
|
73
|
+
const { parent } = tr.doc.resolve(from)
|
|
74
|
+
const isEmptyTextBlock = parent.isTextblock
|
|
75
|
+
&& !parent.type.spec.code
|
|
76
|
+
&& !parent.childCount
|
|
70
77
|
|
|
71
78
|
if (isEmptyTextBlock) {
|
|
72
79
|
from -= 1
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function removeElement(element: HTMLElement): void;
|