@tiptap/core 2.7.1 → 2.7.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/index.cjs +6 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +6 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/Editor.d.ts +4 -2
- package/dist/packages/core/src/ExtensionManager.d.ts +2 -1
- package/dist/packages/core/src/types.d.ts +4 -7
- package/package.json +2 -2
- package/src/Editor.ts +9 -3
- package/src/ExtensionManager.ts +1 -1
- package/src/helpers/getRenderedAttributes.ts +3 -0
- package/src/types.ts +24 -16
|
@@ -66,14 +66,16 @@ export declare class Editor extends EventEmitter<EditorEvents> {
|
|
|
66
66
|
*
|
|
67
67
|
* @param plugin A ProseMirror plugin
|
|
68
68
|
* @param handlePlugins Control how to merge the plugin into the existing plugins.
|
|
69
|
+
* @returns The new editor state
|
|
69
70
|
*/
|
|
70
|
-
registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]):
|
|
71
|
+
registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): EditorState;
|
|
71
72
|
/**
|
|
72
73
|
* Unregister a ProseMirror plugin.
|
|
73
74
|
*
|
|
74
75
|
* @param nameOrPluginKey The plugins name
|
|
76
|
+
* @returns The new editor state or undefined if the editor is destroyed
|
|
75
77
|
*/
|
|
76
|
-
unregisterPlugin(nameOrPluginKey: string | PluginKey):
|
|
78
|
+
unregisterPlugin(nameOrPluginKey: string | PluginKey): EditorState | undefined;
|
|
77
79
|
/**
|
|
78
80
|
* Creates an extension manager.
|
|
79
81
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Schema } from '@tiptap/pm/model';
|
|
2
2
|
import { Plugin } from '@tiptap/pm/state';
|
|
3
|
+
import { NodeViewConstructor } from '@tiptap/pm/view';
|
|
3
4
|
import type { Editor } from './Editor.js';
|
|
4
5
|
import { Extensions, RawCommands } from './types.js';
|
|
5
6
|
export declare class ExtensionManager {
|
|
@@ -46,7 +47,7 @@ export declare class ExtensionManager {
|
|
|
46
47
|
* Get all node views from the extensions.
|
|
47
48
|
* @returns An object with all node views where the key is the node name and the value is the node view function
|
|
48
49
|
*/
|
|
49
|
-
get nodeViews():
|
|
50
|
+
get nodeViews(): Record<string, NodeViewConstructor>;
|
|
50
51
|
/**
|
|
51
52
|
* Go through all extensions, create extension storages & setup marks
|
|
52
53
|
* & bind editor event listener.
|
|
@@ -189,18 +189,15 @@ export type ValuesOf<T> = T[keyof T];
|
|
|
189
189
|
export type KeysWithTypeOf<T, Type> = {
|
|
190
190
|
[P in keyof T]: T[P] extends Type ? P : never;
|
|
191
191
|
}[keyof T];
|
|
192
|
-
export type Simplify<T> = {
|
|
193
|
-
[KeyType in keyof T]: T[KeyType];
|
|
194
|
-
} & {};
|
|
195
192
|
export type DecorationWithType = Decoration & {
|
|
196
193
|
type: NodeType;
|
|
197
194
|
};
|
|
198
|
-
export
|
|
195
|
+
export interface NodeViewProps extends NodeViewRendererProps {
|
|
199
196
|
decorations: readonly DecorationWithType[];
|
|
200
197
|
selected: boolean;
|
|
201
198
|
updateAttributes: (attributes: Record<string, any>) => void;
|
|
202
199
|
deleteNode: () => void;
|
|
203
|
-
}
|
|
200
|
+
}
|
|
204
201
|
export interface NodeViewRendererOptions {
|
|
205
202
|
stopEvent: ((props: {
|
|
206
203
|
event: Event;
|
|
@@ -213,7 +210,7 @@ export interface NodeViewRendererOptions {
|
|
|
213
210
|
}) => boolean) | null;
|
|
214
211
|
contentDOMElementTag: string;
|
|
215
212
|
}
|
|
216
|
-
export
|
|
213
|
+
export interface NodeViewRendererProps {
|
|
217
214
|
node: Parameters<NodeViewConstructor>[0];
|
|
218
215
|
view: Parameters<NodeViewConstructor>[1];
|
|
219
216
|
getPos: () => number;
|
|
@@ -222,7 +219,7 @@ export type NodeViewRendererProps = {
|
|
|
222
219
|
editor: Editor;
|
|
223
220
|
extension: Node;
|
|
224
221
|
HTMLAttributes: Record<string, any>;
|
|
225
|
-
}
|
|
222
|
+
}
|
|
226
223
|
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView;
|
|
227
224
|
export type AnyCommands = Record<string, (...args: any[]) => Command>;
|
|
228
225
|
export type UnionCommands<T = Command> = UnionToIntersection<ValuesOf<Pick<Commands<T>, KeysWithTypeOf<Commands<T>, {}>>>>;
|
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.7.
|
|
4
|
+
"version": "2.7.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.7.
|
|
35
|
+
"@tiptap/pm": "^2.7.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@tiptap/pm": "^2.7.0"
|
package/src/Editor.ts
CHANGED
|
@@ -224,11 +224,12 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
224
224
|
*
|
|
225
225
|
* @param plugin A ProseMirror plugin
|
|
226
226
|
* @param handlePlugins Control how to merge the plugin into the existing plugins.
|
|
227
|
+
* @returns The new editor state
|
|
227
228
|
*/
|
|
228
229
|
public registerPlugin(
|
|
229
230
|
plugin: Plugin,
|
|
230
231
|
handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[],
|
|
231
|
-
):
|
|
232
|
+
): EditorState {
|
|
232
233
|
const plugins = isFunction(handlePlugins)
|
|
233
234
|
? handlePlugins(plugin, [...this.state.plugins])
|
|
234
235
|
: [...this.state.plugins, plugin]
|
|
@@ -236,16 +237,19 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
236
237
|
const state = this.state.reconfigure({ plugins })
|
|
237
238
|
|
|
238
239
|
this.view.updateState(state)
|
|
240
|
+
|
|
241
|
+
return state
|
|
239
242
|
}
|
|
240
243
|
|
|
241
244
|
/**
|
|
242
245
|
* Unregister a ProseMirror plugin.
|
|
243
246
|
*
|
|
244
247
|
* @param nameOrPluginKey The plugins name
|
|
248
|
+
* @returns The new editor state or undefined if the editor is destroyed
|
|
245
249
|
*/
|
|
246
|
-
public unregisterPlugin(nameOrPluginKey: string | PluginKey):
|
|
250
|
+
public unregisterPlugin(nameOrPluginKey: string | PluginKey): EditorState | undefined {
|
|
247
251
|
if (this.isDestroyed) {
|
|
248
|
-
return
|
|
252
|
+
return undefined
|
|
249
253
|
}
|
|
250
254
|
|
|
251
255
|
// @ts-ignore
|
|
@@ -257,6 +261,8 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
257
261
|
})
|
|
258
262
|
|
|
259
263
|
this.view.updateState(state)
|
|
264
|
+
|
|
265
|
+
return state
|
|
260
266
|
}
|
|
261
267
|
|
|
262
268
|
/**
|
package/src/ExtensionManager.ts
CHANGED
|
@@ -260,7 +260,7 @@ export class ExtensionManager {
|
|
|
260
260
|
* Get all node views from the extensions.
|
|
261
261
|
* @returns An object with all node views where the key is the node name and the value is the node view function
|
|
262
262
|
*/
|
|
263
|
-
get nodeViews() {
|
|
263
|
+
get nodeViews(): Record<string, NodeViewConstructor> {
|
|
264
264
|
const { editor } = this
|
|
265
265
|
const { nodeExtensions } = splitExtensions(this.extensions)
|
|
266
266
|
|
|
@@ -8,6 +8,9 @@ export function getRenderedAttributes(
|
|
|
8
8
|
extensionAttributes: ExtensionAttribute[],
|
|
9
9
|
): Record<string, any> {
|
|
10
10
|
return extensionAttributes
|
|
11
|
+
.filter(
|
|
12
|
+
attribute => attribute.type === nodeOrMark.type.name,
|
|
13
|
+
)
|
|
11
14
|
.filter(item => item.attribute.rendered)
|
|
12
15
|
.map(item => {
|
|
13
16
|
if (!item.attribute.renderHTML) {
|
package/src/types.ts
CHANGED
|
@@ -101,7 +101,19 @@ export interface EditorOptions {
|
|
|
101
101
|
*
|
|
102
102
|
* @default true
|
|
103
103
|
*/
|
|
104
|
-
enableCoreExtensions?:
|
|
104
|
+
enableCoreExtensions?:
|
|
105
|
+
| boolean
|
|
106
|
+
| Partial<
|
|
107
|
+
Record<
|
|
108
|
+
| 'editable'
|
|
109
|
+
| 'clipboardTextSerializer'
|
|
110
|
+
| 'commands'
|
|
111
|
+
| 'focusEvents'
|
|
112
|
+
| 'keymap'
|
|
113
|
+
| 'tabindex',
|
|
114
|
+
false
|
|
115
|
+
>
|
|
116
|
+
>;
|
|
105
117
|
/**
|
|
106
118
|
* If `true`, the editor will check the content for errors on initialization.
|
|
107
119
|
* Emitting the `contentError` event if the content is invalid.
|
|
@@ -122,8 +134,8 @@ export interface EditorOptions {
|
|
|
122
134
|
onFocus: (props: EditorEvents['focus']) => void;
|
|
123
135
|
onBlur: (props: EditorEvents['blur']) => void;
|
|
124
136
|
onDestroy: (props: EditorEvents['destroy']) => void;
|
|
125
|
-
onPaste: (e: ClipboardEvent, slice: Slice) => void
|
|
126
|
-
onDrop: (e: DragEvent, slice: Slice, moved: boolean) => void
|
|
137
|
+
onPaste: (e: ClipboardEvent, slice: Slice) => void;
|
|
138
|
+
onDrop: (e: DragEvent, slice: Slice, moved: boolean) => void;
|
|
127
139
|
}
|
|
128
140
|
|
|
129
141
|
export type HTMLContent = string;
|
|
@@ -208,21 +220,17 @@ export type ValuesOf<T> = T[keyof T];
|
|
|
208
220
|
|
|
209
221
|
export type KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T];
|
|
210
222
|
|
|
211
|
-
export type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
212
|
-
|
|
213
223
|
export type DecorationWithType = Decoration & {
|
|
214
224
|
type: NodeType;
|
|
215
225
|
};
|
|
216
226
|
|
|
217
|
-
export
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
>;
|
|
227
|
+
export interface NodeViewProps extends NodeViewRendererProps {
|
|
228
|
+
// TODO this type is not technically correct, but it's the best we can do for now since prosemirror doesn't expose the type of decorations
|
|
229
|
+
decorations: readonly DecorationWithType[];
|
|
230
|
+
selected: boolean;
|
|
231
|
+
updateAttributes: (attributes: Record<string, any>) => void;
|
|
232
|
+
deleteNode: () => void;
|
|
233
|
+
}
|
|
226
234
|
|
|
227
235
|
export interface NodeViewRendererOptions {
|
|
228
236
|
stopEvent: ((props: { event: Event }) => boolean) | null;
|
|
@@ -232,7 +240,7 @@ export interface NodeViewRendererOptions {
|
|
|
232
240
|
contentDOMElementTag: string;
|
|
233
241
|
}
|
|
234
242
|
|
|
235
|
-
export
|
|
243
|
+
export interface NodeViewRendererProps {
|
|
236
244
|
// pass-through from prosemirror
|
|
237
245
|
node: Parameters<NodeViewConstructor>[0];
|
|
238
246
|
view: Parameters<NodeViewConstructor>[1];
|
|
@@ -243,7 +251,7 @@ export type NodeViewRendererProps = {
|
|
|
243
251
|
editor: Editor;
|
|
244
252
|
extension: Node;
|
|
245
253
|
HTMLAttributes: Record<string, any>;
|
|
246
|
-
}
|
|
254
|
+
}
|
|
247
255
|
|
|
248
256
|
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView;
|
|
249
257
|
|