Skip to content

Commit 93e63de

Browse files
authored
feat: added ability to pass marks to updateAttributes method of ReactNodeView (#177)
1 parent 3a62b9b commit 93e63de

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/react-utils/react-node-view.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import type {Node} from 'prosemirror-model';
3+
import type {Mark, Node} from 'prosemirror-model';
44
import type {EditorView, NodeView, NodeViewConstructor} from 'prosemirror-view';
55
import {createPortal} from 'react-dom';
66

@@ -17,7 +17,7 @@ export const ReactNodeStopEventCn = 'prosemirror-stop-event';
1717
export type ReactNodeViewProps<T extends object = {}> = {
1818
dom: HTMLElement;
1919
view: EditorView;
20-
updateAttributes: (attrs: object) => void;
20+
updateAttributes: (attrs: object, marks?: Mark[]) => void;
2121
node: Node;
2222
getPos: () => number | undefined;
2323
serializer: Serializer;
@@ -94,15 +94,20 @@ export class ReactNodeView<T extends object = {}> implements NodeView {
9494
return true;
9595
}
9696

97-
updateAttributes(attributes: {}) {
97+
updateAttributes(attributes: {}, marks: Mark[] = []) {
9898
const pos = this.getPos();
9999
if (pos === undefined) return;
100100

101101
const {tr} = this.view.state;
102-
tr.setNodeMarkup(pos, undefined, {
103-
...this.node.attrs,
104-
...attributes,
105-
});
102+
tr.setNodeMarkup(
103+
pos,
104+
undefined,
105+
{
106+
...this.node.attrs,
107+
...attributes,
108+
},
109+
marks,
110+
);
106111
this.view.dispatch(tr);
107112
}
108113

0 commit comments

Comments
 (0)