fix: inability to select list pasted into table #206

pr675
Hufe921 3 years ago
parent 68bea13333
commit 53dd9628ca

@ -59,17 +59,29 @@ export const EDITOR_ELEMENT_ZIP_ATTR: Array<keyof IElement> = [
'listWrap'
]
export const EDITOR_ELEMENT_CONTEXT_ATTR: Array<keyof IElement> = [
export const TABLE_CONTEXT_ATTR: Array<keyof IElement> = [
'tdId',
'trId',
'tableId',
'tableId'
]
export const TITLE_CONTEXT_ATTR: Array<keyof IElement> = [
'level',
'titleId',
]
export const LIST_CONTEXT_ATTR: Array<keyof IElement> = [
'listId',
'listType',
'listStyle'
]
export const EDITOR_ELEMENT_CONTEXT_ATTR: Array<keyof IElement> = [
...TABLE_CONTEXT_ATTR,
...TITLE_CONTEXT_ATTR,
...LIST_CONTEXT_ATTR
]
export const TEXTLIKE_ELEMENT_TYPE: ElementType[] = [
ElementType.TEXT,
ElementType.HYPERLINK,

@ -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<IElement>(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<IElement>(EDITOR_ELEMENT_CONTEXT_ATTR, copyElement, targetElement)
}
}

@ -136,4 +136,16 @@ export function convertNumberToChinese(num: number) {
result = result.replace(/零+$/, '')
result = result.replace(/^一十/g, '十')
return result
}
export function cloneProperty<T>(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]
}
}
}
Loading…
Cancel
Save