fix: inability to select list pasted into table #206
This commit is contained in:
@@ -59,17 +59,29 @@ export const EDITOR_ELEMENT_ZIP_ATTR: Array<keyof IElement> = [
|
|||||||
'listWrap'
|
'listWrap'
|
||||||
]
|
]
|
||||||
|
|
||||||
export const EDITOR_ELEMENT_CONTEXT_ATTR: Array<keyof IElement> = [
|
export const TABLE_CONTEXT_ATTR: Array<keyof IElement> = [
|
||||||
'tdId',
|
'tdId',
|
||||||
'trId',
|
'trId',
|
||||||
'tableId',
|
'tableId'
|
||||||
|
]
|
||||||
|
|
||||||
|
export const TITLE_CONTEXT_ATTR: Array<keyof IElement> = [
|
||||||
'level',
|
'level',
|
||||||
'titleId',
|
'titleId',
|
||||||
|
]
|
||||||
|
|
||||||
|
export const LIST_CONTEXT_ATTR: Array<keyof IElement> = [
|
||||||
'listId',
|
'listId',
|
||||||
'listType',
|
'listType',
|
||||||
'listStyle'
|
'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[] = [
|
export const TEXTLIKE_ELEMENT_TYPE: ElementType[] = [
|
||||||
ElementType.TEXT,
|
ElementType.TEXT,
|
||||||
ElementType.HYPERLINK,
|
ElementType.HYPERLINK,
|
||||||
|
|||||||
+10
-13
@@ -1,10 +1,10 @@
|
|||||||
import { deepClone, getUUID, splitText } from '.'
|
import { cloneProperty, deepClone, getUUID, splitText } from '.'
|
||||||
import { ElementType, IEditorOption, IElement, RowFlex } from '..'
|
import { ElementType, IEditorOption, IElement, RowFlex } from '..'
|
||||||
import { LaTexParticle } from '../core/draw/particle/latex/LaTexParticle'
|
import { LaTexParticle } from '../core/draw/particle/latex/LaTexParticle'
|
||||||
import { defaultCheckboxOption } from '../dataset/constant/Checkbox'
|
import { defaultCheckboxOption } from '../dataset/constant/Checkbox'
|
||||||
import { ZERO } from '../dataset/constant/Common'
|
import { ZERO } from '../dataset/constant/Common'
|
||||||
import { defaultControlOption } from '../dataset/constant/Control'
|
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 { titleSizeMapping } from '../dataset/constant/Title'
|
||||||
import { ControlComponent, ControlType } from '../dataset/enum/Control'
|
import { ControlComponent, ControlType } from '../dataset/enum/Control'
|
||||||
import { ITd } from '../interface/table/Td'
|
import { ITd } from '../interface/table/Td'
|
||||||
@@ -575,18 +575,15 @@ export function formatElementContext(sourceElementList: IElement[], formatElemen
|
|||||||
const targetElement = formatElementList[e]
|
const targetElement = formatElementList[e]
|
||||||
if (isBreakWhenWrap && !copyElement.listId && /^\n/.test(targetElement.value)) break
|
if (isBreakWhenWrap && !copyElement.listId && /^\n/.test(targetElement.value)) break
|
||||||
// 定位元素非列表,无需处理粘贴列表的上下文
|
// 定位元素非列表,无需处理粘贴列表的上下文
|
||||||
if (!copyElement.listId && targetElement.type === ElementType.LIST) continue
|
if (!copyElement.listId && targetElement.type === ElementType.LIST) {
|
||||||
if (targetElement.valueList && targetElement.valueList.length) {
|
targetElement.valueList?.forEach((valueItem) => {
|
||||||
|
cloneProperty<IElement>(TABLE_CONTEXT_ATTR, copyElement, valueItem)
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (targetElement.valueList?.length) {
|
||||||
formatElementContext(sourceElementList, targetElement.valueList, anchorIndex)
|
formatElementContext(sourceElementList, targetElement.valueList, anchorIndex)
|
||||||
}
|
}
|
||||||
for (let i = 0; i < EDITOR_ELEMENT_CONTEXT_ATTR.length; i++) {
|
cloneProperty<IElement>(EDITOR_ELEMENT_CONTEXT_ATTR, copyElement, targetElement)
|
||||||
const attr = EDITOR_ELEMENT_CONTEXT_ATTR[i]
|
|
||||||
const value = copyElement[attr] as never
|
|
||||||
if (value !== undefined) {
|
|
||||||
targetElement[attr] = value
|
|
||||||
} else {
|
|
||||||
delete targetElement[attr]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,4 +136,16 @@ export function convertNumberToChinese(num: number) {
|
|||||||
result = result.replace(/零+$/, '')
|
result = result.replace(/零+$/, '')
|
||||||
result = result.replace(/^一十/g, '十')
|
result = result.replace(/^一十/g, '十')
|
||||||
return result
|
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user