|
|
|
@ -2,12 +2,16 @@ import { ImageDisplay } from '../../../dataset/enum/Common'
|
|
|
|
import { EditorMode } from '../../../dataset/enum/Editor'
|
|
|
|
import { EditorMode } from '../../../dataset/enum/Editor'
|
|
|
|
import { ElementType } from '../../../dataset/enum/Element'
|
|
|
|
import { ElementType } from '../../../dataset/enum/Element'
|
|
|
|
import { MouseEventButton } from '../../../dataset/enum/Event'
|
|
|
|
import { MouseEventButton } from '../../../dataset/enum/Event'
|
|
|
|
|
|
|
|
import { ControlComponent } from '../../../dataset/enum/Control'
|
|
|
|
|
|
|
|
import { ControlType } from '../../../dataset/enum/Control'
|
|
|
|
import { IPreviewerDrawOption } from '../../../interface/Previewer'
|
|
|
|
import { IPreviewerDrawOption } from '../../../interface/Previewer'
|
|
|
|
import { deepClone } from '../../../utils'
|
|
|
|
import { deepClone } from '../../../utils'
|
|
|
|
import { isMod } from '../../../utils/hotkey'
|
|
|
|
import { isMod } from '../../../utils/hotkey'
|
|
|
|
import { CheckboxControl } from '../../draw/control/checkbox/CheckboxControl'
|
|
|
|
import { CheckboxControl } from '../../draw/control/checkbox/CheckboxControl'
|
|
|
|
import { RadioControl } from '../../draw/control/radio/RadioControl'
|
|
|
|
import { RadioControl } from '../../draw/control/radio/RadioControl'
|
|
|
|
import { CanvasEvent } from '../CanvasEvent'
|
|
|
|
import { CanvasEvent } from '../CanvasEvent'
|
|
|
|
|
|
|
|
import { IElement } from '../../../interface/Element'
|
|
|
|
|
|
|
|
import { Draw } from '../../draw/Draw'
|
|
|
|
|
|
|
|
|
|
|
|
export function setRangeCache(host: CanvasEvent) {
|
|
|
|
export function setRangeCache(host: CanvasEvent) {
|
|
|
|
const draw = host.getDraw()
|
|
|
|
const draw = host.getDraw()
|
|
|
|
@ -21,6 +25,42 @@ export function setRangeCache(host: CanvasEvent) {
|
|
|
|
host.cachePositionContext = position.getPositionContext()
|
|
|
|
host.cachePositionContext = position.getPositionContext()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function hitCheckbox(element: IElement, draw: Draw) {
|
|
|
|
|
|
|
|
const { checkbox, control } = element
|
|
|
|
|
|
|
|
// 复选框不在控件内独立控制
|
|
|
|
|
|
|
|
if (!control) {
|
|
|
|
|
|
|
|
draw.getCheckboxParticle().setSelect(element)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const codes = control?.code ? control.code.split(',') : []
|
|
|
|
|
|
|
|
if (checkbox?.value) {
|
|
|
|
|
|
|
|
const codeIndex = codes.findIndex(c => c === checkbox.code)
|
|
|
|
|
|
|
|
codes.splice(codeIndex, 1)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (checkbox?.code) {
|
|
|
|
|
|
|
|
codes.push(checkbox.code)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const activeControl = draw.getControl().getActiveControl()
|
|
|
|
|
|
|
|
if (activeControl instanceof CheckboxControl) {
|
|
|
|
|
|
|
|
activeControl.setSelect(codes)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function hitRadio(element: IElement, draw: Draw) {
|
|
|
|
|
|
|
|
const { radio, control } = element
|
|
|
|
|
|
|
|
// 单选框不在控件内独立控制
|
|
|
|
|
|
|
|
if (!control) {
|
|
|
|
|
|
|
|
draw.getRadioParticle().setSelect(element)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const codes = radio?.code ? [radio.code] : []
|
|
|
|
|
|
|
|
const activeControl = draw.getControl().getActiveControl()
|
|
|
|
|
|
|
|
if (activeControl instanceof RadioControl) {
|
|
|
|
|
|
|
|
activeControl.setSelect(codes)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function mousedown(evt: MouseEvent, host: CanvasEvent) {
|
|
|
|
export function mousedown(evt: MouseEvent, host: CanvasEvent) {
|
|
|
|
if (evt.button === MouseEventButton.RIGHT) return
|
|
|
|
if (evt.button === MouseEventButton.RIGHT) return
|
|
|
|
const draw = host.getDraw()
|
|
|
|
const draw = host.getDraw()
|
|
|
|
@ -100,40 +140,27 @@ export function mousedown(evt: MouseEvent, host: CanvasEvent) {
|
|
|
|
rangeManager.setRange(startIndex, endIndex)
|
|
|
|
rangeManager.setRange(startIndex, endIndex)
|
|
|
|
position.setCursorPosition(positionList[curIndex])
|
|
|
|
position.setCursorPosition(positionList[curIndex])
|
|
|
|
// 复选框
|
|
|
|
// 复选框
|
|
|
|
const isSetCheckbox = isDirectHitCheckbox && !isReadonly
|
|
|
|
if (isDirectHitCheckbox && !isReadonly) {
|
|
|
|
// 单选框
|
|
|
|
hitCheckbox(curElement, draw)
|
|
|
|
const isSetRadio = isDirectHitRadio && !isReadonly
|
|
|
|
} else if (isDirectHitRadio && !isReadonly) {
|
|
|
|
if (isSetCheckbox) {
|
|
|
|
hitRadio(curElement, draw)
|
|
|
|
const { checkbox, control } = curElement
|
|
|
|
} else if (
|
|
|
|
// 复选框不在控件内独立控制
|
|
|
|
curElement.controlComponent === ControlComponent.VALUE &&
|
|
|
|
if (!control) {
|
|
|
|
(curElement.control?.type === ControlType.CHECKBOX ||
|
|
|
|
draw.getCheckboxParticle().setSelect(curElement)
|
|
|
|
curElement.control?.type === ControlType.RADIO)
|
|
|
|
} else {
|
|
|
|
) {
|
|
|
|
const codes = control?.code ? control.code.split(',') : []
|
|
|
|
// 向左查找
|
|
|
|
if (checkbox?.value) {
|
|
|
|
let preIndex = curIndex
|
|
|
|
const codeIndex = codes.findIndex(c => c === checkbox.code)
|
|
|
|
while (preIndex > 0) {
|
|
|
|
codes.splice(codeIndex, 1)
|
|
|
|
const preElement = elementList[preIndex]
|
|
|
|
} else {
|
|
|
|
if (preElement.controlComponent === ControlComponent.CHECKBOX) {
|
|
|
|
if (checkbox?.code) {
|
|
|
|
hitCheckbox(preElement, draw)
|
|
|
|
codes.push(checkbox.code)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
} else if (preElement.controlComponent === ControlComponent.RADIO) {
|
|
|
|
}
|
|
|
|
hitRadio(preElement, draw)
|
|
|
|
const activeControl = draw.getControl().getActiveControl()
|
|
|
|
break
|
|
|
|
if (activeControl instanceof CheckboxControl) {
|
|
|
|
|
|
|
|
activeControl.setSelect(codes)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (isSetRadio) {
|
|
|
|
|
|
|
|
const { control, radio } = curElement
|
|
|
|
|
|
|
|
// 单选框不在控件内独立控制
|
|
|
|
|
|
|
|
if (!control) {
|
|
|
|
|
|
|
|
draw.getRadioParticle().setSelect(curElement)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const codes = radio?.code ? [radio.code] : []
|
|
|
|
|
|
|
|
const activeControl = draw.getControl().getActiveControl()
|
|
|
|
|
|
|
|
if (activeControl instanceof RadioControl) {
|
|
|
|
|
|
|
|
activeControl.setSelect(codes)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
preIndex--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
draw.render({
|
|
|
|
draw.render({
|
|
|
|
|