From 6b87ef49ff1b1a6ea10ce290a6ec5665582d5e7c Mon Sep 17 00:00:00 2001 From: pipipi-pikachu Date: Sat, 24 Sep 2022 11:55:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AF=8C=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E9=BB=98=E8=AE=A4=E5=B1=9E=E6=80=A7=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/prosemirror/utils.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/utils/prosemirror/utils.ts b/src/utils/prosemirror/utils.ts index f47735c7..ccea4f87 100644 --- a/src/utils/prosemirror/utils.ts +++ b/src/utils/prosemirror/utils.ts @@ -123,7 +123,7 @@ export const getMarkAttrs = (view: EditorView) => { return node?.marks || [] } -export const getAttrValue = (marks: readonly Mark[], markType: string, attr: string) => { +export const getAttrValue = (marks: readonly Mark[], markType: string, attr: string): string | null => { for (const mark of marks) { if (mark.type.name === markType && mark.attrs[attr]) return mark.attrs[attr] } @@ -162,11 +162,11 @@ export const getAttrValueInSelection = (view: EditorView, attr: string) => { type Align = 'left' | 'right' | 'center' interface DefaultAttrs { - color?: string - backcolor?: string - fontsize?: string - fontname?: string - align?: Align + color: string + backcolor: string + fontsize: string + fontname: string + align: Align } const _defaultAttrs: DefaultAttrs = { color: '#000', @@ -175,8 +175,8 @@ const _defaultAttrs: DefaultAttrs = { fontname: '微软雅黑', align: 'left', } -export const getTextAttrs = (view: EditorView, defaultAttrs: DefaultAttrs = {}) => { - defaultAttrs = { ..._defaultAttrs, ...defaultAttrs } +export const getTextAttrs = (view: EditorView, attrs: Partial = {}) => { + const defaultAttrs: DefaultAttrs = { ..._defaultAttrs, ...attrs } const marks = getMarkAttrs(view)