feat: control default style #340

This commit is contained in:
Hufe921
2024-04-14 14:48:30 +08:00
parent de06f6cc9b
commit eee22363d3
7 changed files with 89 additions and 21 deletions
@@ -2,7 +2,10 @@ import {
EDITOR_COMPONENT,
EDITOR_PREFIX
} from '../../../../dataset/constant/Editor'
import { EDITOR_ELEMENT_STYLE_ATTR } from '../../../../dataset/constant/Element'
import {
CONTROL_STYLE_ATTR,
EDITOR_ELEMENT_STYLE_ATTR
} from '../../../../dataset/constant/Element'
import { ControlComponent } from '../../../../dataset/enum/Control'
import { EditorComponent } from '../../../../dataset/enum/Editor'
import { ElementType } from '../../../../dataset/enum/Element'
@@ -211,11 +214,12 @@ export class SelectControl implements IControlInstance {
const valueSet = valueSets.find(v => v.code === code)
if (!valueSet) return
const elementList = context.elementList || this.control.getElementList()
// 样式赋值元素-默认值的第一个字符样式
const styleElement = pickObject(
this.getValue(context)[0],
EDITOR_ELEMENT_STYLE_ATTR
)
const range = context.range || this.control.getRange()
// 样式赋值元素-默认值的第一个字符样式,否则取默认样式
const valueElement = this.getValue(context)[0]
const styleElement = valueElement
? pickObject(valueElement, EDITOR_ELEMENT_STYLE_ATTR)
: pickObject(elementList[range.startIndex], CONTROL_STYLE_ATTR)
// 清空选项
const prefixIndex = this.clearSelect(context)
if (!~prefixIndex) return
@@ -1,4 +1,7 @@
import { TEXTLIKE_ELEMENT_TYPE } from '../../../../dataset/constant/Element'
import {
CONTROL_STYLE_ATTR,
TEXTLIKE_ELEMENT_TYPE
} from '../../../../dataset/constant/Element'
import { ControlComponent } from '../../../../dataset/enum/Control'
import { KeyMap } from '../../../../dataset/enum/KeyMap'
import {
@@ -90,7 +93,11 @@ export class TextControl implements IControlInstance {
(startElement.type &&
!TEXTLIKE_ELEMENT_TYPE.includes(startElement.type)) ||
startElement.controlComponent === ControlComponent.PREFIX
? pickObject(startElement, ['control', 'controlId'])
? pickObject(startElement, [
'control',
'controlId',
...CONTROL_STYLE_ATTR
])
: omitObject(startElement, ['type'])
// 插入起始位置
const start = range.startIndex + 1