feat: add executeLocationControl api #592

This commit is contained in:
Hufe921
2024-06-05 21:20:24 +08:00
parent bf322dfea3
commit 53701fc46c
7 changed files with 147 additions and 16 deletions
+35 -14
View File
@@ -487,12 +487,22 @@ export function isSameElementExceptValue(
}
return true
}
export function pickElementAttr(payload: IElement): IElement {
interface IPickElementOption {
extraPickAttrs?: Array<keyof IElement>
}
export function pickElementAttr(
payload: IElement,
option: IPickElementOption = {}
): IElement {
const { extraPickAttrs } = option
const zipAttrs = EDITOR_ELEMENT_ZIP_ATTR
if (extraPickAttrs) {
zipAttrs.push(...extraPickAttrs)
}
const element: IElement = {
value: payload.value === ZERO ? `\n` : payload.value
}
EDITOR_ELEMENT_ZIP_ATTR.forEach(attr => {
zipAttrs.forEach(attr => {
const value = payload[attr] as never
if (value !== undefined) {
element[attr] = value
@@ -501,7 +511,14 @@ export function pickElementAttr(payload: IElement): IElement {
return element
}
export function zipElementList(payload: IElement[]): IElement[] {
interface IZipElementListOption {
extraPickAttrs?: Array<keyof IElement>
}
export function zipElementList(
payload: IElement[],
options: IZipElementListOption = {}
): IElement[] {
const { extraPickAttrs } = options
const elementList = deepClone(payload)
const zipElementListData: IElement[] = []
let e = 0
@@ -541,7 +558,7 @@ export function zipElementList(payload: IElement[]): IElement[] {
valueList.push(titleE)
e++
}
titleElement.valueList = zipElementList(valueList)
titleElement.valueList = zipElementList(valueList, options)
element = titleElement
}
} else if (element.listId && element.listType) {
@@ -569,7 +586,7 @@ export function zipElementList(payload: IElement[]): IElement[] {
valueList.push(listE)
e++
}
listElement.valueList = zipElementList(valueList)
listElement.valueList = zipElementList(valueList, options)
element = listElement
}
} else if (element.type === ElementType.TABLE) {
@@ -599,7 +616,7 @@ export function zipElementList(payload: IElement[]): IElement[] {
const zipTd: ITd = {
colspan: td.colspan,
rowspan: td.rowspan,
value: zipElementList(td.value)
value: zipElementList(td.value, options)
}
// 压缩单元格属性
TABLE_TD_ZIP_ATTR.forEach(attr => {
@@ -633,7 +650,7 @@ export function zipElementList(payload: IElement[]): IElement[] {
valueList.push(hyperlinkE)
e++
}
hyperlinkElement.valueList = zipElementList(valueList)
hyperlinkElement.valueList = zipElementList(valueList, options)
element = hyperlinkElement
}
} else if (element.type === ElementType.DATE) {
@@ -656,7 +673,7 @@ export function zipElementList(payload: IElement[]): IElement[] {
valueList.push(dateE)
e++
}
dateElement.valueList = zipElementList(valueList)
dateElement.valueList = zipElementList(valueList, options)
element = dateElement
}
} else if (element.controlId) {
@@ -675,7 +692,8 @@ export function zipElementList(payload: IElement[]): IElement[] {
...pickObject(element, EDITOR_ROW_ATTR),
type: ElementType.CONTROL,
value: '',
control
control,
controlId
}
const valueList: IElement[] = []
while (e < elementList.length) {
@@ -691,12 +709,12 @@ export function zipElementList(payload: IElement[]): IElement[] {
}
e++
}
controlElement.control!.value = zipElementList(valueList)
element = controlElement
controlElement.control!.value = zipElementList(valueList, options)
element = pickElementAttr(controlElement, { extraPickAttrs })
}
}
// 组合元素
const pickElement = pickElementAttr(element)
const pickElement = pickElementAttr(element, { extraPickAttrs })
if (
!element.type ||
element.type === ElementType.TEXT ||
@@ -708,7 +726,10 @@ export function zipElementList(payload: IElement[]): IElement[] {
e++
if (
nextElement &&
isSameElementExceptValue(pickElement, pickElementAttr(nextElement))
isSameElementExceptValue(
pickElement,
pickElementAttr(nextElement, { extraPickAttrs })
)
) {
const nextValue =
nextElement.value === ZERO ? '\n' : nextElement.value