Skip to content

Commit 595eb07

Browse files
committed
feat: add area hide option #1139
1 parent 2288b66 commit 595eb07

File tree

11 files changed

+49
-29
lines changed

11 files changed

+49
-29
lines changed

docs/en/guide/schema.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ interface IElement {
196196
area?: {
197197
extension?: unknown;
198198
top?: number;
199+
hide?: boolean;
199200
borderColor?: string;
200201
backgroundColor?: string;
201202
mode?: AreaMode;

docs/guide/schema.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ interface IElement {
196196
area?: {
197197
extension?: unknown;
198198
top?: number;
199+
hide?: boolean;
199200
borderColor?: string;
200201
backgroundColor?: string;
201202
mode?: AreaMode;

src/editor/core/draw/Draw.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ export class Draw {
820820
const deleteElement = elementList[deleteIndex]
821821
if (
822822
deleteElement?.control?.hide ||
823+
deleteElement?.area?.hide ||
823824
(tdDeletable !== false &&
824825
deleteElement?.control?.deletable !== false &&
825826
deleteElement?.title?.deletable !== false &&
@@ -1377,7 +1378,10 @@ export class Draw {
13771378
const isStartElement = curRow.elementList.length === 1
13781379
x += isStartElement ? offsetX : 0
13791380
y += isStartElement ? curRow.offsetY || 0 : 0
1380-
if (element.control?.hide && !this.isDesignMode()) {
1381+
if (
1382+
(element.control?.hide || element.area?.hide) &&
1383+
!this.isDesignMode()
1384+
) {
13811385
metrics.height =
13821386
curRow.elementList[curRow.elementList.length - 1]?.metrics.height ||
13831387
this.options.defaultSize * scale
@@ -1829,12 +1833,12 @@ export class Draw {
18291833
preElement?.imgDisplay === ImageDisplay.INLINE ||
18301834
element.imgDisplay === ImageDisplay.INLINE ||
18311835
preElement?.listId !== element.listId ||
1832-
preElement?.areaId !== element.areaId ||
1836+
(preElement?.areaId !== element.areaId && !element.area?.hide) ||
18331837
(element.control?.flexDirection === FlexDirection.COLUMN &&
18341838
(element.controlComponent === ControlComponent.CHECKBOX ||
18351839
element.controlComponent === ControlComponent.RADIO) &&
18361840
preElement?.controlComponent === ControlComponent.VALUE) ||
1837-
(i !== 0 && element.value === ZERO)
1841+
(i !== 0 && element.value === ZERO && !element.area?.hide)
18381842
// 是否宽度不足导致换行
18391843
const isWidthNotEnough = curRowWidth > availableWidth
18401844
const isWrap = isForceBreak || isWidthNotEnough
@@ -2127,7 +2131,10 @@ export class Draw {
21272131
} = positionList[curRow.startIndex + j]
21282132
const preElement = curRow.elementList[j - 1]
21292133
// 元素绘制
2130-
if (element.control?.hide && !this.isDesignMode()) {
2134+
if (
2135+
(element.control?.hide || element.area?.hide) &&
2136+
!this.isDesignMode()
2137+
) {
21312138
// 控件隐藏时不绘制
21322139
this.textParticle.complete()
21332140
} else if (element.type === ElementType.IMAGE) {

src/editor/core/draw/control/Control.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ export class Control {
554554
element = elementList[index]
555555
}
556556
// 隐藏元素移动光标
557-
if (element.control?.hide) {
557+
if (element.control?.hide || element.area?.hide) {
558558
const nonHideIndex = getNonHideElementIndex(elementList, newIndex)
559559
return {
560560
newIndex: nonHideIndex,
@@ -636,7 +636,11 @@ export class Control {
636636
const elementList = context.elementList || this.getElementList()
637637
const startElement = elementList[startIndex]
638638
// 设计模式 || 元素隐藏 => 不验证删除权限
639-
if (!this.draw.isDesignMode() && !startElement?.control?.hide) {
639+
if (
640+
!this.draw.isDesignMode() &&
641+
!startElement?.control?.hide &&
642+
!startElement?.area?.hide
643+
) {
640644
const { deletable = true } = startElement.control!
641645
if (!deletable) return null
642646
}

src/editor/core/draw/interactive/Area.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Draw } from '../Draw'
22
import { deepClone, getUUID, isNonValue } from '../../../utils'
33
import { ElementType } from '../../../dataset/enum/Element'
44
import {
5+
IArea,
56
IAreaInfo,
67
IGetAreaValueOption,
78
IGetAreaValueResult,
@@ -105,7 +106,10 @@ export class Area {
105106
const width = this.draw.getInnerWidth()
106107
for (const areaInfoItem of this.areaInfoMap) {
107108
const { area, positionList } = areaInfoItem[1]
108-
if (!area?.backgroundColor && !area?.borderColor && !area?.placeholder) {
109+
if (
110+
area.hide ||
111+
(!area?.backgroundColor && !area?.borderColor && !area?.placeholder)
112+
) {
109113
continue
110114
}
111115
const pagePositionList = positionList.filter(p => p.pageNo === pageNo)
@@ -211,22 +215,18 @@ export class Area {
211215
if (!areaInfo.area) {
212216
areaInfo.area = {}
213217
}
214-
// 是否计算
218+
// 需要计算的属性
215219
let isCompute = false
216-
// 修改属性
217-
if (payload.properties.mode) {
218-
areaInfo.area.mode = payload.properties.mode
219-
}
220-
if (payload.properties.borderColor) {
221-
areaInfo.area.borderColor = payload.properties.borderColor
222-
}
223-
if (payload.properties.backgroundColor) {
224-
areaInfo.area.backgroundColor = payload.properties.backgroundColor
225-
}
226-
if (!isNonValue(payload.properties.top)) {
227-
isCompute = true
228-
areaInfo.area.top = payload.properties.top
229-
}
220+
const computeProps: Array<keyof IArea> = ['top', 'hide']
221+
// 循环设置
222+
Object.entries(payload.properties).forEach(([key, value]) => {
223+
if (isNonValue(value)) return
224+
const propKey = key as keyof IArea
225+
areaInfo.area[propKey] = value
226+
if (computeProps.includes(propKey)) {
227+
isCompute = true
228+
}
229+
})
230230
this.draw.render({
231231
isCompute,
232232
isSetCursor: false

src/editor/core/draw/interactive/Search.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ export class Search {
216216
!e.type ||
217217
(TEXTLIKE_ELEMENT_TYPE.includes(e.type) &&
218218
e.controlComponent !== ControlComponent.CHECKBOX &&
219-
!e.control?.hide)
219+
!e.control?.hide &&
220+
!e.area?.hide)
220221
? e.value
221222
: ZERO
222223
)

src/editor/core/event/handlers/keydown/backspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function backspace(evt: KeyboardEvent, host: CanvasEvent) {
1414
const range = rangeManager.getRange()
1515
const elementList = draw.getElementList()
1616
const element = elementList[range.startIndex]
17-
if (element.control?.hide) {
17+
if (element.control?.hide || element.area?.hide) {
1818
const newIndex = control.removeControl(range.startIndex)
1919
if (newIndex) {
2020
// 更新选区信息

src/editor/core/event/handlers/keydown/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function del(evt: KeyboardEvent, host: CanvasEvent) {
1212
const control = draw.getControl()
1313
if (rangeManager.getIsCollapsed()) {
1414
const nextElement = elementList[startIndex + 1]
15-
if (nextElement?.control?.hide) {
15+
if (nextElement?.control?.hide || nextElement?.area?.hide) {
1616
const newIndex = control.removeControl(startIndex + 1)
1717
if (newIndex) {
1818
// 更新位置信息

src/editor/core/worker/works/wordCount.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ function pickText(elementList: IElement[]): string {
6262
}
6363
text += pickText(valueList)
6464
}
65-
} else if (!element.type || element.type === ElementType.TEXT) {
65+
} else if (
66+
(!element.type || element.type === ElementType.TEXT) &&
67+
!element.area?.hide
68+
) {
6669
text += element.value
6770
}
6871
e++

src/editor/interface/Area.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface IAreaStyle {
1616

1717
export interface IAreaRule {
1818
mode?: AreaMode
19+
hide?: boolean
1920
deletable?: boolean
2021
}
2122

0 commit comments

Comments
 (0)