feat:format control data option

pr675
Hufe921 4 years ago
parent befb39f26b
commit 54cbd83577

@ -1236,7 +1236,10 @@ export class CommandAdapt {
const { startIndex, endIndex } = this.range.getRange() const { startIndex, endIndex } = this.range.getRange()
if (!~startIndex && !~endIndex) return if (!~startIndex && !~endIndex) return
// 格式化element // 格式化element
formatElementList(payload, false) formatElementList(payload, {
isHandleFirstElement: false,
editorOptions: this.options
})
const elementList = this.draw.getElementList() const elementList = this.draw.getElementList()
const isCollapsed = startIndex === endIndex const isCollapsed = startIndex === endIndex
const start = startIndex + 1 const start = startIndex + 1

@ -78,7 +78,9 @@ export default class Editor {
watermark: waterMarkOptions, watermark: waterMarkOptions,
control: controlOptions control: controlOptions
} }
formatElementList(elementList) formatElementList(elementList, {
editorOptions
})
// 监听 // 监听
this.listener = new Listener() this.listener = new Listener()
// 启动 // 启动

@ -1,10 +1,19 @@
import { deepClone, getUUID } from '.' import { deepClone, getUUID } from '.'
import { ElementType, IElement } from '..' import { ElementType, IEditorOption, IElement } from '..'
import { ZERO } from '../dataset/constant/Common' import { ZERO } from '../dataset/constant/Common'
import { EDITOR_ELEMENT_ZIP_ATTR } from '../dataset/constant/Element' import { EDITOR_ELEMENT_ZIP_ATTR } from '../dataset/constant/Element'
import { ControlComponent } from '../dataset/enum/Control' import { ControlComponent } from '../dataset/enum/Control'
export function formatElementList(elementList: IElement[], isHandleFirstElement = true) { interface IFormatElementListOption {
isHandleFirstElement?: boolean;
editorOptions?: Required<IEditorOption>;
}
export function formatElementList(elementList: IElement[], options: IFormatElementListOption = {}) {
const { isHandleFirstElement, editorOptions } = <IFormatElementListOption>{
isHandleFirstElement: true,
...options
}
if (isHandleFirstElement && elementList[0]?.value !== ZERO) { if (isHandleFirstElement && elementList[0]?.value !== ZERO) {
elementList.unshift({ elementList.unshift({
value: ZERO value: ZERO
@ -25,7 +34,7 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
const td = tr.tdList[d] const td = tr.tdList[d]
const tdId = getUUID() const tdId = getUUID()
td.id = tdId td.id = tdId
formatElementList(td.value) formatElementList(td.value, options)
for (let v = 0; v < td.value.length; v++) { for (let v = 0; v < td.value.length; v++) {
const value = td.value[v] const value = td.value[v]
value.tdId = tdId value.tdId = tdId
@ -65,6 +74,11 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
const controlId = getUUID() const controlId = getUUID()
// 移除父节点 // 移除父节点
elementList.splice(i, 1) elementList.splice(i, 1)
// 前后缀个性化设置
const thePreSuffixArgs: Pick<IElement, 'color'> = {}
if (editorOptions && editorOptions.control) {
thePreSuffixArgs.color = editorOptions.control.bracketColor
}
// 前缀 // 前缀
if (prefix) { if (prefix) {
const prefixStrList = prefix.split('') const prefixStrList = prefix.split('')
@ -75,7 +89,8 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
value, value,
type: el.type, type: el.type,
control: el.control, control: el.control,
controlComponent: ControlComponent.SUFFIX controlComponent: ControlComponent.SUFFIX,
...thePreSuffixArgs
}) })
i++ i++
} }
@ -99,6 +114,10 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
} }
} else { } else {
// placeholder // placeholder
const thePlaceholderArgs: Pick<IElement, 'color'> = {}
if (editorOptions && editorOptions.control) {
thePlaceholderArgs.color = editorOptions.control.placeholderColor
}
const placeholderStrList = placeholder.split('') const placeholderStrList = placeholder.split('')
for (let p = 0; p < placeholderStrList.length; p++) { for (let p = 0; p < placeholderStrList.length; p++) {
const value = placeholderStrList[p] const value = placeholderStrList[p]
@ -107,7 +126,8 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
value, value,
type: el.type, type: el.type,
control: el.control, control: el.control,
controlComponent: ControlComponent.PLACEHOLDER controlComponent: ControlComponent.PLACEHOLDER,
...thePlaceholderArgs
}) })
i++ i++
} }
@ -122,7 +142,8 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
value, value,
type: el.type, type: el.type,
control: el.control, control: el.control,
controlComponent: ControlComponent.POSTFIX controlComponent: ControlComponent.POSTFIX,
...thePreSuffixArgs
}) })
i++ i++
} }

Loading…
Cancel
Save