From bb1660a8abd840ac8480a95307312a199f88c441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A2=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BD=D1=86=D0=B5=D0=B2?= Date: Thu, 25 Jan 2024 15:03:54 +0100 Subject: [PATCH] feat: added ability to pass marks to updateAttributes method of ReactNodeView --- src/react-utils/react-node-view.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/react-utils/react-node-view.tsx b/src/react-utils/react-node-view.tsx index c310b112..0ac4d3da 100644 --- a/src/react-utils/react-node-view.tsx +++ b/src/react-utils/react-node-view.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import type {Node} from 'prosemirror-model'; +import type {Mark, Node} from 'prosemirror-model'; import type {EditorView, NodeView, NodeViewConstructor} from 'prosemirror-view'; import {createPortal} from 'react-dom'; @@ -17,7 +17,7 @@ export const ReactNodeStopEventCn = 'prosemirror-stop-event'; export type ReactNodeViewProps = { dom: HTMLElement; view: EditorView; - updateAttributes: (attrs: object) => void; + updateAttributes: (attrs: object, marks?: Mark[]) => void; node: Node; getPos: () => number | undefined; serializer: Serializer; @@ -94,15 +94,20 @@ export class ReactNodeView implements NodeView { return true; } - updateAttributes(attributes: {}) { + updateAttributes(attributes: {}, marks: Mark[] = []) { const pos = this.getPos(); if (pos === undefined) return; const {tr} = this.view.state; - tr.setNodeMarkup(pos, undefined, { - ...this.node.attrs, - ...attributes, - }); + tr.setNodeMarkup( + pos, + undefined, + { + ...this.node.attrs, + ...attributes, + }, + marks, + ); this.view.dispatch(tr); }