@tiptap/core 2.8.0 → 2.9.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.
- package/dist/Editor.d.ts +2 -2
- package/dist/Editor.d.ts.map +1 -1
- package/dist/NodePos.d.ts.map +1 -1
- package/dist/commands/insertContentAt.d.ts.map +1 -1
- package/dist/helpers/getMarkRange.d.ts.map +1 -1
- package/dist/index.cjs +42 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +42 -14
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +42 -14
- package/dist/index.umd.js.map +1 -1
- package/dist/types.d.ts +47 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/Editor.ts +29 -6
- package/src/NodePos.ts +9 -4
- package/src/commands/insertContentAt.ts +4 -2
- package/src/helpers/getMarkRange.ts +6 -3
- package/src/types.ts +48 -2
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Mark as ProseMirrorMark, Node as ProseMirrorNode,
|
|
1
|
+
import { Mark as ProseMirrorMark, Node as ProseMirrorNode, ParseOptions, Slice } from '@tiptap/pm/model';
|
|
2
2
|
import { EditorState, Transaction } from '@tiptap/pm/state';
|
|
3
|
-
import {
|
|
3
|
+
import { Mappable } from '@tiptap/pm/transform';
|
|
4
|
+
import { Decoration, DecorationAttrs, EditorProps, EditorView, NodeView, NodeViewConstructor } from '@tiptap/pm/view';
|
|
4
5
|
import { Editor } from './Editor.js';
|
|
5
6
|
import { Extension } from './Extension.js';
|
|
6
7
|
import { Commands, ExtensionConfig, MarkConfig, NodeConfig } from './index.js';
|
|
@@ -200,8 +201,25 @@ export type ValuesOf<T> = T[keyof T];
|
|
|
200
201
|
export type KeysWithTypeOf<T, Type> = {
|
|
201
202
|
[P in keyof T]: T[P] extends Type ? P : never;
|
|
202
203
|
}[keyof T];
|
|
204
|
+
export type DOMNode = InstanceType<typeof window.Node>;
|
|
205
|
+
/**
|
|
206
|
+
* prosemirror-view does not export the `type` property of `Decoration`.
|
|
207
|
+
* So, this defines the `DecorationType` interface to include the `type` property.
|
|
208
|
+
*/
|
|
209
|
+
export interface DecorationType {
|
|
210
|
+
spec: any;
|
|
211
|
+
map(mapping: Mappable, span: Decoration, offset: number, oldOffset: number): Decoration | null;
|
|
212
|
+
valid(node: Node, span: Decoration): boolean;
|
|
213
|
+
eq(other: DecorationType): boolean;
|
|
214
|
+
destroy(dom: DOMNode): void;
|
|
215
|
+
readonly attrs: DecorationAttrs;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* prosemirror-view does not export the `type` property of `Decoration`.
|
|
219
|
+
* This adds the `type` property to the `Decoration` type.
|
|
220
|
+
*/
|
|
203
221
|
export type DecorationWithType = Decoration & {
|
|
204
|
-
type:
|
|
222
|
+
type: DecorationType;
|
|
205
223
|
};
|
|
206
224
|
export interface NodeViewProps extends NodeViewRendererProps {
|
|
207
225
|
decorations: readonly DecorationWithType[];
|
|
@@ -222,13 +240,39 @@ export interface NodeViewRendererOptions {
|
|
|
222
240
|
contentDOMElementTag: string;
|
|
223
241
|
}
|
|
224
242
|
export interface NodeViewRendererProps {
|
|
243
|
+
/**
|
|
244
|
+
* The node that is being rendered.
|
|
245
|
+
*/
|
|
225
246
|
node: Parameters<NodeViewConstructor>[0];
|
|
247
|
+
/**
|
|
248
|
+
* The editor's view.
|
|
249
|
+
*/
|
|
226
250
|
view: Parameters<NodeViewConstructor>[1];
|
|
251
|
+
/**
|
|
252
|
+
* A function that can be called to get the node's current position in the document.
|
|
253
|
+
*/
|
|
227
254
|
getPos: () => number;
|
|
255
|
+
/**
|
|
256
|
+
* is an array of node or inline decorations that are active around the node.
|
|
257
|
+
* They are automatically drawn in the normal way, and you will usually just want to ignore this, but they can also be used as a way to provide context information to the node view without adding it to the document itself.
|
|
258
|
+
*/
|
|
228
259
|
decorations: Parameters<NodeViewConstructor>[3];
|
|
260
|
+
/**
|
|
261
|
+
* holds the decorations for the node's content. You can safely ignore this if your view has no content or a contentDOM property, since the editor will draw the decorations on the content.
|
|
262
|
+
* But if you, for example, want to create a nested editor with the content, it may make sense to provide it with the inner decorations.
|
|
263
|
+
*/
|
|
229
264
|
innerDecorations: Parameters<NodeViewConstructor>[4];
|
|
265
|
+
/**
|
|
266
|
+
* The editor instance.
|
|
267
|
+
*/
|
|
230
268
|
editor: Editor;
|
|
269
|
+
/**
|
|
270
|
+
* The extension that is responsible for the node.
|
|
271
|
+
*/
|
|
231
272
|
extension: Node;
|
|
273
|
+
/**
|
|
274
|
+
* The HTML attributes that should be added to the node's DOM element.
|
|
275
|
+
*/
|
|
232
276
|
HTMLAttributes: Record<string, any>;
|
|
233
277
|
}
|
|
234
278
|
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,IAAI,eAAe,EACvB,IAAI,IAAI,eAAe,EACvB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,IAAI,eAAe,EACvB,IAAI,IAAI,eAAe,EACvB,YAAY,EACZ,KAAK,EACN,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EACL,UAAU,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,QAAQ,EACR,mBAAmB,EACpB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EACL,QAAQ,EAAE,eAAe,EAAE,UAAU,EA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AM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC"}
|
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.
|
|
4
|
+
"version": "2.9.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.
|
|
35
|
+
"@tiptap/pm": "^2.9.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@tiptap/pm": "^2.7.0"
|
package/src/Editor.ts
CHANGED
|
@@ -237,20 +237,32 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
237
237
|
/**
|
|
238
238
|
* Unregister a ProseMirror plugin.
|
|
239
239
|
*
|
|
240
|
-
* @param
|
|
240
|
+
* @param nameOrPluginKeyToRemove The plugins name
|
|
241
241
|
* @returns The new editor state or undefined if the editor is destroyed
|
|
242
242
|
*/
|
|
243
|
-
public unregisterPlugin(
|
|
243
|
+
public unregisterPlugin(nameOrPluginKeyToRemove: string | PluginKey | (string | PluginKey)[]): EditorState | undefined {
|
|
244
244
|
if (this.isDestroyed) {
|
|
245
245
|
return undefined
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
|
|
249
|
-
|
|
248
|
+
const prevPlugins = this.state.plugins
|
|
249
|
+
let plugins = prevPlugins;
|
|
250
|
+
|
|
251
|
+
([] as (string | PluginKey)[]).concat(nameOrPluginKeyToRemove).forEach(nameOrPluginKey => {
|
|
252
|
+
// @ts-ignore
|
|
253
|
+
const name = typeof nameOrPluginKey === 'string' ? `${nameOrPluginKey}$` : nameOrPluginKey.key
|
|
250
254
|
|
|
251
|
-
const state = this.state.reconfigure({
|
|
252
255
|
// @ts-ignore
|
|
253
|
-
plugins
|
|
256
|
+
plugins = prevPlugins.filter(plugin => !plugin.key.startsWith(name))
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
if (prevPlugins.length === plugins.length) {
|
|
260
|
+
// No plugin was removed, so we don’t need to update the state
|
|
261
|
+
return undefined
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const state = this.state.reconfigure({
|
|
265
|
+
plugins,
|
|
254
266
|
})
|
|
255
267
|
|
|
256
268
|
this.view.updateState(state)
|
|
@@ -325,6 +337,9 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
325
337
|
editor: this,
|
|
326
338
|
error: e as Error,
|
|
327
339
|
disableCollaboration: () => {
|
|
340
|
+
if (this.storage.collaboration) {
|
|
341
|
+
this.storage.collaboration.isDisabled = true
|
|
342
|
+
}
|
|
328
343
|
// To avoid syncing back invalid content, reinitialize the extensions without the collaboration extension
|
|
329
344
|
this.options.extensions = this.options.extensions.filter(extension => extension.name !== 'collaboration')
|
|
330
345
|
|
|
@@ -352,6 +367,14 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|
|
352
367
|
}),
|
|
353
368
|
})
|
|
354
369
|
|
|
370
|
+
// add `role="textbox"` to the editor element
|
|
371
|
+
this.view.dom.setAttribute('role', 'textbox')
|
|
372
|
+
|
|
373
|
+
// add aria-label to the editor element
|
|
374
|
+
if (!this.view.dom.getAttribute('aria-label')) {
|
|
375
|
+
this.view.dom.setAttribute('aria-label', 'Rich-Text Editor')
|
|
376
|
+
}
|
|
377
|
+
|
|
355
378
|
// `editor.view` is not yet available at this time.
|
|
356
379
|
// Therefore we will add all plugins and node views directly afterwards.
|
|
357
380
|
const newState = this.state.reconfigure({
|
package/src/NodePos.ts
CHANGED
|
@@ -135,8 +135,9 @@ export class NodePos {
|
|
|
135
135
|
|
|
136
136
|
this.node.content.forEach((node, offset) => {
|
|
137
137
|
const isBlock = node.isBlock && !node.isTextblock
|
|
138
|
+
const isNonTextAtom = node.isAtom && !node.isText
|
|
138
139
|
|
|
139
|
-
const targetPos = this.pos + offset + 1
|
|
140
|
+
const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1)
|
|
140
141
|
const $pos = this.resolvedPos.doc.resolve(targetPos)
|
|
141
142
|
|
|
142
143
|
if (!isBlock && $pos.depth <= this.depth) {
|
|
@@ -235,9 +236,13 @@ export class NodePos {
|
|
|
235
236
|
}
|
|
236
237
|
|
|
237
238
|
setAttribute(attributes: { [key: string]: any }) {
|
|
238
|
-
const
|
|
239
|
+
const { tr } = this.editor.state
|
|
239
240
|
|
|
240
|
-
|
|
241
|
-
.
|
|
241
|
+
tr.setNodeMarkup(this.from, undefined, {
|
|
242
|
+
...this.node.attrs,
|
|
243
|
+
...attributes,
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
this.editor.view.dispatch(tr)
|
|
242
247
|
}
|
|
243
248
|
}
|
|
@@ -63,7 +63,7 @@ const isFragment = (nodeOrFragment: ProseMirrorNode | Fragment): nodeOrFragment
|
|
|
63
63
|
export const insertContentAt: RawCommands['insertContentAt'] = (position, value, options) => ({ tr, dispatch, editor }) => {
|
|
64
64
|
if (dispatch) {
|
|
65
65
|
options = {
|
|
66
|
-
parseOptions:
|
|
66
|
+
parseOptions: editor.options.parseOptions,
|
|
67
67
|
updateSelection: true,
|
|
68
68
|
applyInputRules: false,
|
|
69
69
|
applyPasteRules: false,
|
|
@@ -85,7 +85,9 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value,
|
|
|
85
85
|
editor,
|
|
86
86
|
error: e as Error,
|
|
87
87
|
disableCollaboration: () => {
|
|
88
|
-
|
|
88
|
+
if (editor.storage.collaboration) {
|
|
89
|
+
editor.storage.collaboration.isDisabled = true
|
|
90
|
+
}
|
|
89
91
|
},
|
|
90
92
|
})
|
|
91
93
|
return false
|
|
@@ -29,17 +29,20 @@ export function getMarkRange(
|
|
|
29
29
|
if (!$pos || !type) {
|
|
30
30
|
return
|
|
31
31
|
}
|
|
32
|
-
|
|
33
32
|
let start = $pos.parent.childAfter($pos.parentOffset)
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
// If the cursor is at the start of a text node that does not have the mark, look backward
|
|
35
|
+
if (!start.node || !start.node.marks.some(mark => mark.type === type)) {
|
|
36
36
|
start = $pos.parent.childBefore($pos.parentOffset)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
// If there is no text node with the mark even backward, return undefined
|
|
40
|
+
if (!start.node || !start.node.marks.some(mark => mark.type === type)) {
|
|
40
41
|
return
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
// We now know that the cursor is either at the start, middle or end of a text node with the specified mark
|
|
45
|
+
// so we can look it up on the targeted mark
|
|
43
46
|
const mark = findMarkInSet([...start.node.marks], type, attributes)
|
|
44
47
|
|
|
45
48
|
if (!mark) {
|
package/src/types.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Mark as ProseMirrorMark,
|
|
3
3
|
Node as ProseMirrorNode,
|
|
4
|
-
NodeType,
|
|
5
4
|
ParseOptions,
|
|
6
5
|
Slice,
|
|
7
6
|
} from '@tiptap/pm/model'
|
|
8
7
|
import { EditorState, Transaction } from '@tiptap/pm/state'
|
|
8
|
+
import { Mappable } from '@tiptap/pm/transform'
|
|
9
9
|
import {
|
|
10
10
|
Decoration,
|
|
11
|
+
DecorationAttrs,
|
|
11
12
|
EditorProps,
|
|
12
13
|
EditorView,
|
|
13
14
|
NodeView,
|
|
@@ -224,8 +225,27 @@ export type ValuesOf<T> = T[keyof T];
|
|
|
224
225
|
|
|
225
226
|
export type KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T];
|
|
226
227
|
|
|
228
|
+
export type DOMNode = InstanceType<typeof window.Node>
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* prosemirror-view does not export the `type` property of `Decoration`.
|
|
232
|
+
* So, this defines the `DecorationType` interface to include the `type` property.
|
|
233
|
+
*/
|
|
234
|
+
export interface DecorationType {
|
|
235
|
+
spec: any
|
|
236
|
+
map(mapping: Mappable, span: Decoration, offset: number, oldOffset: number): Decoration | null
|
|
237
|
+
valid(node: Node, span: Decoration): boolean
|
|
238
|
+
eq(other: DecorationType): boolean
|
|
239
|
+
destroy(dom: DOMNode): void
|
|
240
|
+
readonly attrs: DecorationAttrs
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* prosemirror-view does not export the `type` property of `Decoration`.
|
|
245
|
+
* This adds the `type` property to the `Decoration` type.
|
|
246
|
+
*/
|
|
227
247
|
export type DecorationWithType = Decoration & {
|
|
228
|
-
type:
|
|
248
|
+
type: DecorationType;
|
|
229
249
|
};
|
|
230
250
|
|
|
231
251
|
export interface NodeViewProps extends NodeViewRendererProps {
|
|
@@ -246,14 +266,40 @@ export interface NodeViewRendererOptions {
|
|
|
246
266
|
|
|
247
267
|
export interface NodeViewRendererProps {
|
|
248
268
|
// pass-through from prosemirror
|
|
269
|
+
/**
|
|
270
|
+
* The node that is being rendered.
|
|
271
|
+
*/
|
|
249
272
|
node: Parameters<NodeViewConstructor>[0];
|
|
273
|
+
/**
|
|
274
|
+
* The editor's view.
|
|
275
|
+
*/
|
|
250
276
|
view: Parameters<NodeViewConstructor>[1];
|
|
277
|
+
/**
|
|
278
|
+
* A function that can be called to get the node's current position in the document.
|
|
279
|
+
*/
|
|
251
280
|
getPos: () => number; // TODO getPos was incorrectly typed before, change to `Parameters<NodeViewConstructor>[2];` in the next major version
|
|
281
|
+
/**
|
|
282
|
+
* is an array of node or inline decorations that are active around the node.
|
|
283
|
+
* They are automatically drawn in the normal way, and you will usually just want to ignore this, but they can also be used as a way to provide context information to the node view without adding it to the document itself.
|
|
284
|
+
*/
|
|
252
285
|
decorations: Parameters<NodeViewConstructor>[3];
|
|
286
|
+
/**
|
|
287
|
+
* holds the decorations for the node's content. You can safely ignore this if your view has no content or a contentDOM property, since the editor will draw the decorations on the content.
|
|
288
|
+
* But if you, for example, want to create a nested editor with the content, it may make sense to provide it with the inner decorations.
|
|
289
|
+
*/
|
|
253
290
|
innerDecorations: Parameters<NodeViewConstructor>[4];
|
|
254
291
|
// tiptap-specific
|
|
292
|
+
/**
|
|
293
|
+
* The editor instance.
|
|
294
|
+
*/
|
|
255
295
|
editor: Editor;
|
|
296
|
+
/**
|
|
297
|
+
* The extension that is responsible for the node.
|
|
298
|
+
*/
|
|
256
299
|
extension: Node;
|
|
300
|
+
/**
|
|
301
|
+
* The HTML attributes that should be added to the node's DOM element.
|
|
302
|
+
*/
|
|
257
303
|
HTMLAttributes: Record<string, any>;
|
|
258
304
|
}
|
|
259
305
|
|