diff --git a/src/editor/dataset/constant/Element.ts b/src/editor/dataset/constant/Element.ts index f7be868..86b8b64 100644 --- a/src/editor/dataset/constant/Element.ts +++ b/src/editor/dataset/constant/Element.ts @@ -59,17 +59,29 @@ export const EDITOR_ELEMENT_ZIP_ATTR: Array = [ 'listWrap' ] -export const EDITOR_ELEMENT_CONTEXT_ATTR: Array = [ +export const TABLE_CONTEXT_ATTR: Array = [ 'tdId', 'trId', - 'tableId', + 'tableId' +] + +export const TITLE_CONTEXT_ATTR: Array = [ 'level', 'titleId', +] + +export const LIST_CONTEXT_ATTR: Array = [ 'listId', 'listType', 'listStyle' ] +export const EDITOR_ELEMENT_CONTEXT_ATTR: Array = [ + ...TABLE_CONTEXT_ATTR, + ...TITLE_CONTEXT_ATTR, + ...LIST_CONTEXT_ATTR +] + export const TEXTLIKE_ELEMENT_TYPE: ElementType[] = [ ElementType.TEXT, ElementType.HYPERLINK, diff --git a/src/editor/utils/element.ts b/src/editor/utils/element.ts index 751d1ec..eb23a1c 100644 --- a/src/editor/utils/element.ts +++ b/src/editor/utils/element.ts @@ -1,10 +1,10 @@ -import { deepClone, getUUID, splitText } from '.' +import { cloneProperty, deepClone, getUUID, splitText } from '.' import { ElementType, IEditorOption, IElement, RowFlex } from '..' import { LaTexParticle } from '../core/draw/particle/latex/LaTexParticle' import { defaultCheckboxOption } from '../dataset/constant/Checkbox' import { ZERO } from '../dataset/constant/Common' import { defaultControlOption } from '../dataset/constant/Control' -import { EDITOR_ELEMENT_CONTEXT_ATTR, EDITOR_ELEMENT_ZIP_ATTR, TEXTLIKE_ELEMENT_TYPE } from '../dataset/constant/Element' +import { EDITOR_ELEMENT_CONTEXT_ATTR, EDITOR_ELEMENT_ZIP_ATTR, TABLE_CONTEXT_ATTR, TEXTLIKE_ELEMENT_TYPE } from '../dataset/constant/Element' import { titleSizeMapping } from '../dataset/constant/Title' import { ControlComponent, ControlType } from '../dataset/enum/Control' import { ITd } from '../interface/table/Td' @@ -575,18 +575,15 @@ export function formatElementContext(sourceElementList: IElement[], formatElemen const targetElement = formatElementList[e] if (isBreakWhenWrap && !copyElement.listId && /^\n/.test(targetElement.value)) break // 定位元素非列表,无需处理粘贴列表的上下文 - if (!copyElement.listId && targetElement.type === ElementType.LIST) continue - if (targetElement.valueList && targetElement.valueList.length) { - formatElementContext(sourceElementList, targetElement.valueList, anchorIndex) + if (!copyElement.listId && targetElement.type === ElementType.LIST) { + targetElement.valueList?.forEach((valueItem) => { + cloneProperty(TABLE_CONTEXT_ATTR, copyElement, valueItem) + }) + continue } - for (let i = 0; i < EDITOR_ELEMENT_CONTEXT_ATTR.length; i++) { - const attr = EDITOR_ELEMENT_CONTEXT_ATTR[i] - const value = copyElement[attr] as never - if (value !== undefined) { - targetElement[attr] = value - } else { - delete targetElement[attr] - } + if (targetElement.valueList?.length) { + formatElementContext(sourceElementList, targetElement.valueList, anchorIndex) } + cloneProperty(EDITOR_ELEMENT_CONTEXT_ATTR, copyElement, targetElement) } } \ No newline at end of file diff --git a/src/editor/utils/index.ts b/src/editor/utils/index.ts index e6c9664..c3e5834 100644 --- a/src/editor/utils/index.ts +++ b/src/editor/utils/index.ts @@ -136,4 +136,16 @@ export function convertNumberToChinese(num: number) { result = result.replace(/零+$/, '') result = result.replace(/^一十/g, '十') return result +} + +export function cloneProperty(properties: (keyof T)[], sourceElement: T, targetElement: T) { + for (let i = 0; i < properties.length; i++) { + const property = properties[i] + const value = sourceElement[property] + if (value !== undefined) { + targetElement[property] = value + } else { + delete targetElement[property] + } + } } \ No newline at end of file