@tiptap/core 3.0.0-beta.1 → 3.0.0-beta.11
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 +30 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +30 -14
- package/dist/index.js.map +1 -1
- package/jsx-dev-runtime/index.cjs +1 -0
- package/jsx-dev-runtime/index.d.cts +1 -0
- package/jsx-dev-runtime/index.d.ts +1 -0
- package/jsx-dev-runtime/index.js +1 -0
- package/package.json +5 -4
- package/src/Editor.ts +4 -3
- package/src/commands/insertContentAt.ts +29 -10
- package/src/types.ts +9 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/jsx-runtime/jsx-runtime.cjs'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../src/jsx-runtime.ts'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from '../src/jsx-runtime.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/jsx-runtime/jsx-runtime.js'
|
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.11",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -48,13 +48,14 @@
|
|
|
48
48
|
"files": [
|
|
49
49
|
"src",
|
|
50
50
|
"dist",
|
|
51
|
-
"jsx-runtime"
|
|
51
|
+
"jsx-runtime",
|
|
52
|
+
"jsx-dev-runtime"
|
|
52
53
|
],
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@tiptap/pm": "
|
|
55
|
+
"@tiptap/pm": "3.0.0-beta.11"
|
|
55
56
|
},
|
|
56
57
|
"peerDependencies": {
|
|
57
|
-
"@tiptap/pm": "
|
|
58
|
+
"@tiptap/pm": "3.0.0-beta.11"
|
|
58
59
|
},
|
|
59
60
|
"repository": {
|
|
60
61
|
"type": "git",
|
package/src/Editor.ts
CHANGED
|
@@ -92,6 +92,7 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
92
92
|
enablePasteRules: true,
|
|
93
93
|
enableCoreExtensions: true,
|
|
94
94
|
enableContentCheck: false,
|
|
95
|
+
emitContentError: false,
|
|
95
96
|
onBeforeCreate: () => null,
|
|
96
97
|
onCreate: () => null,
|
|
97
98
|
onUpdate: () => null,
|
|
@@ -287,6 +288,7 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
287
288
|
composing: false,
|
|
288
289
|
dragging: null,
|
|
289
290
|
editable: true,
|
|
291
|
+
isDestroyed: false,
|
|
290
292
|
} as EditorView,
|
|
291
293
|
{
|
|
292
294
|
get: (obj, key) => {
|
|
@@ -361,7 +363,7 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
361
363
|
const name = typeof nameOrPluginKey === 'string' ? `${nameOrPluginKey}$` : nameOrPluginKey.key
|
|
362
364
|
|
|
363
365
|
// @ts-ignore
|
|
364
|
-
plugins =
|
|
366
|
+
plugins = plugins.filter(plugin => !plugin.key.startsWith(name))
|
|
365
367
|
})
|
|
366
368
|
|
|
367
369
|
if (prevPlugins.length === plugins.length) {
|
|
@@ -717,8 +719,7 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
717
719
|
* Check if the editor is already destroyed.
|
|
718
720
|
*/
|
|
719
721
|
public get isDestroyed(): boolean {
|
|
720
|
-
|
|
721
|
-
return !this.view?.docView
|
|
722
|
+
return this.editorView?.isDestroyed ?? true
|
|
722
723
|
}
|
|
723
724
|
|
|
724
725
|
public $node(selector: string, attributes?: { [key: string]: any }): NodePos | null {
|
|
@@ -76,18 +76,10 @@ export const insertContentAt: RawCommands['insertContentAt'] =
|
|
|
76
76
|
let content: Fragment | ProseMirrorNode
|
|
77
77
|
const { selection } = editor.state
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
content = createNodeFromContent(value, editor.schema, {
|
|
81
|
-
parseOptions: {
|
|
82
|
-
preserveWhitespace: 'full',
|
|
83
|
-
...options.parseOptions,
|
|
84
|
-
},
|
|
85
|
-
errorOnInvalidContent: options.errorOnInvalidContent ?? editor.options.enableContentCheck,
|
|
86
|
-
})
|
|
87
|
-
} catch (e) {
|
|
79
|
+
const emitContentError = (error: Error) => {
|
|
88
80
|
editor.emit('contentError', {
|
|
89
81
|
editor,
|
|
90
|
-
error
|
|
82
|
+
error,
|
|
91
83
|
disableCollaboration: () => {
|
|
92
84
|
if (
|
|
93
85
|
'collaboration' in editor.storage &&
|
|
@@ -98,6 +90,33 @@ export const insertContentAt: RawCommands['insertContentAt'] =
|
|
|
98
90
|
}
|
|
99
91
|
},
|
|
100
92
|
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const parseOptions: ParseOptions = {
|
|
96
|
+
preserveWhitespace: 'full',
|
|
97
|
+
...options.parseOptions,
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// If `emitContentError` is enabled, we want to check the content for errors
|
|
101
|
+
// but ignore them (do not remove the invalid content from the document)
|
|
102
|
+
if (!options.errorOnInvalidContent && !editor.options.enableContentCheck && editor.options.emitContentError) {
|
|
103
|
+
try {
|
|
104
|
+
createNodeFromContent(value, editor.schema, {
|
|
105
|
+
parseOptions,
|
|
106
|
+
errorOnInvalidContent: true,
|
|
107
|
+
})
|
|
108
|
+
} catch (e) {
|
|
109
|
+
emitContentError(e as Error)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
content = createNodeFromContent(value, editor.schema, {
|
|
115
|
+
parseOptions,
|
|
116
|
+
errorOnInvalidContent: options.errorOnInvalidContent ?? editor.options.enableContentCheck,
|
|
117
|
+
})
|
|
118
|
+
} catch (e) {
|
|
119
|
+
emitContentError(e as Error)
|
|
101
120
|
return false
|
|
102
121
|
}
|
|
103
122
|
|
package/src/types.ts
CHANGED
|
@@ -354,6 +354,15 @@ export interface EditorOptions {
|
|
|
354
354
|
* @default false
|
|
355
355
|
*/
|
|
356
356
|
enableContentCheck: boolean
|
|
357
|
+
/**
|
|
358
|
+
* If `true`, the editor will emit the `contentError` event if invalid content is
|
|
359
|
+
* encountered but `enableContentCheck` is `false`. This lets you preserve the
|
|
360
|
+
* invalid editor content while still showing a warning or error message to
|
|
361
|
+
* the user.
|
|
362
|
+
*
|
|
363
|
+
* @default false
|
|
364
|
+
*/
|
|
365
|
+
emitContentError: boolean
|
|
357
366
|
/**
|
|
358
367
|
* Called before the editor is constructed.
|
|
359
368
|
*/
|