feat: control default style #340
This commit is contained in:
+33
-12
@@ -4,6 +4,7 @@ import {
|
||||
deepCloneOmitKeys,
|
||||
getUUID,
|
||||
isArrayEqual,
|
||||
pickObject,
|
||||
splitText
|
||||
} from '.'
|
||||
import {
|
||||
@@ -19,6 +20,7 @@ import {
|
||||
import { LaTexParticle } from '../core/draw/particle/latex/LaTexParticle'
|
||||
import { NON_BREAKING_SPACE, ZERO } from '../dataset/constant/Common'
|
||||
import {
|
||||
CONTROL_STYLE_ATTR,
|
||||
EDITOR_ELEMENT_CONTEXT_ATTR,
|
||||
EDITOR_ELEMENT_ZIP_ATTR,
|
||||
INLINE_NODE_NAME,
|
||||
@@ -40,6 +42,7 @@ import {
|
||||
import { ControlComponent, ControlType } from '../dataset/enum/Control'
|
||||
import { UlStyle } from '../dataset/enum/List'
|
||||
import { DeepRequired } from '../interface/Common'
|
||||
import { IControlSelect } from '../interface/Control'
|
||||
import { IRowElement } from '../interface/Row'
|
||||
import { ITd } from '../interface/table/Td'
|
||||
import { ITr } from '../interface/table/Tr'
|
||||
@@ -224,22 +227,29 @@ export function formatElementList(
|
||||
const controlId = getUUID()
|
||||
// 移除父节点
|
||||
elementList.splice(i, 1)
|
||||
// 控件设置的默认样式(以前缀为基准)
|
||||
const controlDefaultStyle = pickObject(
|
||||
<IElement>(<unknown>el.control),
|
||||
CONTROL_STYLE_ATTR
|
||||
)
|
||||
// 前后缀个性化设置
|
||||
const thePrePostfixArgs: Pick<IElement, 'color'> = {}
|
||||
if (editorOptions && editorOptions.control) {
|
||||
thePrePostfixArgs.color = editorOptions.control.bracketColor
|
||||
const thePrePostfixArg: Omit<IElement, 'value'> = {
|
||||
...controlDefaultStyle
|
||||
}
|
||||
if (!thePrePostfixArg.color) {
|
||||
thePrePostfixArg.color = editorOptions.control.bracketColor
|
||||
}
|
||||
// 前缀
|
||||
const prefixStrList = splitText(prefix || controlOption.prefix)
|
||||
for (let p = 0; p < prefixStrList.length; p++) {
|
||||
const value = prefixStrList[p]
|
||||
elementList.splice(i, 0, {
|
||||
...thePrePostfixArg,
|
||||
controlId,
|
||||
value,
|
||||
type: el.type,
|
||||
control: el.control,
|
||||
controlComponent: ControlComponent.PREFIX,
|
||||
...thePrePostfixArgs
|
||||
controlComponent: ControlComponent.PREFIX
|
||||
})
|
||||
i++
|
||||
}
|
||||
@@ -283,6 +293,7 @@ export function formatElementList(
|
||||
const value = valueStrList[e]
|
||||
const isLastLetter = e === valueStrList.length - 1
|
||||
elementList.splice(i, 0, {
|
||||
...controlDefaultStyle,
|
||||
...valueStyleList[valueStyleIndex],
|
||||
controlId,
|
||||
value: value === '\n' ? ZERO : value,
|
||||
@@ -316,6 +327,7 @@ export function formatElementList(
|
||||
const element = valueList[v]
|
||||
const value = element.value
|
||||
elementList.splice(i, 0, {
|
||||
...controlDefaultStyle,
|
||||
...element,
|
||||
controlId,
|
||||
value: value === '\n' ? ZERO : value,
|
||||
@@ -328,20 +340,22 @@ export function formatElementList(
|
||||
}
|
||||
} else if (placeholder) {
|
||||
// placeholder
|
||||
const thePlaceholderArgs: Pick<IElement, 'color'> = {}
|
||||
if (editorOptions && editorOptions.control) {
|
||||
const thePlaceholderArgs: Omit<IElement, 'value'> = {
|
||||
...controlDefaultStyle
|
||||
}
|
||||
if (editorOptions?.control?.placeholderColor) {
|
||||
thePlaceholderArgs.color = editorOptions.control.placeholderColor
|
||||
}
|
||||
const placeholderStrList = splitText(placeholder)
|
||||
for (let p = 0; p < placeholderStrList.length; p++) {
|
||||
const value = placeholderStrList[p]
|
||||
elementList.splice(i, 0, {
|
||||
...thePlaceholderArgs,
|
||||
controlId,
|
||||
value: value === '\n' ? ZERO : value,
|
||||
type: el.type,
|
||||
control: el.control,
|
||||
controlComponent: ControlComponent.PLACEHOLDER,
|
||||
...thePlaceholderArgs
|
||||
controlComponent: ControlComponent.PLACEHOLDER
|
||||
})
|
||||
i++
|
||||
}
|
||||
@@ -351,12 +365,12 @@ export function formatElementList(
|
||||
for (let p = 0; p < postfixStrList.length; p++) {
|
||||
const value = postfixStrList[p]
|
||||
elementList.splice(i, 0, {
|
||||
...thePrePostfixArg,
|
||||
controlId,
|
||||
value,
|
||||
type: el.type,
|
||||
control: el.control,
|
||||
controlComponent: ControlComponent.POSTFIX,
|
||||
...thePrePostfixArgs
|
||||
controlComponent: ControlComponent.POSTFIX
|
||||
})
|
||||
i++
|
||||
}
|
||||
@@ -589,7 +603,14 @@ export function zipElementList(payload: IElement[]): IElement[] {
|
||||
// 控件处理
|
||||
const controlId = element.controlId
|
||||
if (controlId) {
|
||||
const control = element.control!
|
||||
// 以前缀为基准更新控件默认样式
|
||||
const controlDefaultStyle = <IControlSelect>(
|
||||
(<unknown>pickObject(element, CONTROL_STYLE_ATTR))
|
||||
)
|
||||
const control = {
|
||||
...element.control!,
|
||||
...controlDefaultStyle
|
||||
}
|
||||
const controlElement: IElement = {
|
||||
type: ElementType.CONTROL,
|
||||
value: '',
|
||||
|
||||
Reference in New Issue
Block a user