feat:format control data option
This commit is contained in:
@@ -1236,7 +1236,10 @@ export class CommandAdapt {
|
||||
const { startIndex, endIndex } = this.range.getRange()
|
||||
if (!~startIndex && !~endIndex) return
|
||||
// 格式化element
|
||||
formatElementList(payload, false)
|
||||
formatElementList(payload, {
|
||||
isHandleFirstElement: false,
|
||||
editorOptions: this.options
|
||||
})
|
||||
const elementList = this.draw.getElementList()
|
||||
const isCollapsed = startIndex === endIndex
|
||||
const start = startIndex + 1
|
||||
|
||||
+3
-1
@@ -78,7 +78,9 @@ export default class Editor {
|
||||
watermark: waterMarkOptions,
|
||||
control: controlOptions
|
||||
}
|
||||
formatElementList(elementList)
|
||||
formatElementList(elementList, {
|
||||
editorOptions
|
||||
})
|
||||
// 监听
|
||||
this.listener = new Listener()
|
||||
// 启动
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
import { deepClone, getUUID } from '.'
|
||||
import { ElementType, IElement } from '..'
|
||||
import { ElementType, IEditorOption, IElement } from '..'
|
||||
import { ZERO } from '../dataset/constant/Common'
|
||||
import { EDITOR_ELEMENT_ZIP_ATTR } from '../dataset/constant/Element'
|
||||
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) {
|
||||
elementList.unshift({
|
||||
value: ZERO
|
||||
@@ -25,7 +34,7 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
|
||||
const td = tr.tdList[d]
|
||||
const tdId = getUUID()
|
||||
td.id = tdId
|
||||
formatElementList(td.value)
|
||||
formatElementList(td.value, options)
|
||||
for (let v = 0; v < td.value.length; v++) {
|
||||
const value = td.value[v]
|
||||
value.tdId = tdId
|
||||
@@ -65,6 +74,11 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
|
||||
const controlId = getUUID()
|
||||
// 移除父节点
|
||||
elementList.splice(i, 1)
|
||||
// 前后缀个性化设置
|
||||
const thePreSuffixArgs: Pick<IElement, 'color'> = {}
|
||||
if (editorOptions && editorOptions.control) {
|
||||
thePreSuffixArgs.color = editorOptions.control.bracketColor
|
||||
}
|
||||
// 前缀
|
||||
if (prefix) {
|
||||
const prefixStrList = prefix.split('')
|
||||
@@ -75,7 +89,8 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
|
||||
value,
|
||||
type: el.type,
|
||||
control: el.control,
|
||||
controlComponent: ControlComponent.SUFFIX
|
||||
controlComponent: ControlComponent.SUFFIX,
|
||||
...thePreSuffixArgs
|
||||
})
|
||||
i++
|
||||
}
|
||||
@@ -99,6 +114,10 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
|
||||
}
|
||||
} else {
|
||||
// placeholder
|
||||
const thePlaceholderArgs: Pick<IElement, 'color'> = {}
|
||||
if (editorOptions && editorOptions.control) {
|
||||
thePlaceholderArgs.color = editorOptions.control.placeholderColor
|
||||
}
|
||||
const placeholderStrList = placeholder.split('')
|
||||
for (let p = 0; p < placeholderStrList.length; p++) {
|
||||
const value = placeholderStrList[p]
|
||||
@@ -107,7 +126,8 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
|
||||
value,
|
||||
type: el.type,
|
||||
control: el.control,
|
||||
controlComponent: ControlComponent.PLACEHOLDER
|
||||
controlComponent: ControlComponent.PLACEHOLDER,
|
||||
...thePlaceholderArgs
|
||||
})
|
||||
i++
|
||||
}
|
||||
@@ -122,7 +142,8 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
|
||||
value,
|
||||
type: el.type,
|
||||
control: el.control,
|
||||
controlComponent: ControlComponent.POSTFIX
|
||||
controlComponent: ControlComponent.POSTFIX,
|
||||
...thePreSuffixArgs
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user