feat: move control position by dragging #456
This commit is contained in:
@@ -179,6 +179,23 @@ export class Control {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否元素包含完整控件元素
|
||||||
|
public getIsElementListContainFullControl(elementList: IElement[]): boolean {
|
||||||
|
if (!elementList.some(element => element.controlId)) return false
|
||||||
|
let prefixCount = 0
|
||||||
|
let postfixCount = 0
|
||||||
|
for (let e = 0; e < elementList.length; e++) {
|
||||||
|
const element = elementList[e]
|
||||||
|
if (element.controlComponent === ControlComponent.PREFIX) {
|
||||||
|
prefixCount++
|
||||||
|
} else if (element.controlComponent === ControlComponent.POSTFIX) {
|
||||||
|
postfixCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!prefixCount || !postfixCount) return false
|
||||||
|
return prefixCount === postfixCount
|
||||||
|
}
|
||||||
|
|
||||||
public getIsDisabledControl(): boolean {
|
public getIsDisabledControl(): boolean {
|
||||||
return !!this.activeControl?.getElement().control?.disabled
|
return !!this.activeControl?.getElement().control?.disabled
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,14 +136,25 @@ export function mouseup(evt: MouseEvent, host: CanvasEvent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 格式化元素
|
// 格式化元素
|
||||||
const editorOptions = draw.getOptions()
|
const control = draw.getControl()
|
||||||
const elementList = draw.getElementList()
|
const elementList = draw.getElementList()
|
||||||
|
// 是否排除控件属性(1.不包含控件 2.新位置在控件内 3.选区不包含完整控件)
|
||||||
|
const isOmitControlAttr =
|
||||||
|
!isContainControl ||
|
||||||
|
!!elementList[range.startIndex].controlId ||
|
||||||
|
!control.getIsElementListContainFullControl(dragElementList)
|
||||||
|
const editorOptions = draw.getOptions()
|
||||||
|
// 元素属性复制(1.文本提取样式及相关上下文 2.非文本排除相关上下文)
|
||||||
const replaceElementList = dragElementList.map(el => {
|
const replaceElementList = dragElementList.map(el => {
|
||||||
if (!el.type || el.type === ElementType.TEXT) {
|
if (!el.type || el.type === ElementType.TEXT) {
|
||||||
const newElement: IElement = {
|
const newElement: IElement = {
|
||||||
value: el.value
|
value: el.value
|
||||||
}
|
}
|
||||||
EDITOR_ELEMENT_STYLE_ATTR.forEach(attr => {
|
const copyAttr = EDITOR_ELEMENT_STYLE_ATTR
|
||||||
|
if (!isOmitControlAttr) {
|
||||||
|
copyAttr.push(...CONTROL_CONTEXT_ATTR)
|
||||||
|
}
|
||||||
|
copyAttr.forEach(attr => {
|
||||||
const value = el[attr] as never
|
const value = el[attr] as never
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
newElement[attr] = value
|
newElement[attr] = value
|
||||||
@@ -151,8 +162,10 @@ export function mouseup(evt: MouseEvent, host: CanvasEvent) {
|
|||||||
})
|
})
|
||||||
return newElement
|
return newElement
|
||||||
} else {
|
} else {
|
||||||
// 移除控件上下文属性
|
let newElement = deepClone(el)
|
||||||
const newElement = omitObject(deepClone(el), CONTROL_CONTEXT_ATTR)
|
if (isOmitControlAttr) {
|
||||||
|
newElement = omitObject(newElement, CONTROL_CONTEXT_ATTR)
|
||||||
|
}
|
||||||
formatElementList([newElement], {
|
formatElementList([newElement], {
|
||||||
isHandleFirstElement: false,
|
isHandleFirstElement: false,
|
||||||
editorOptions
|
editorOptions
|
||||||
@@ -170,7 +183,6 @@ export function mouseup(evt: MouseEvent, host: CanvasEvent) {
|
|||||||
const replaceLength = replaceElementList.length
|
const replaceLength = replaceElementList.length
|
||||||
let rangeStart = range.startIndex
|
let rangeStart = range.startIndex
|
||||||
let rangeEnd = rangeStart + replaceLength
|
let rangeEnd = rangeStart + replaceLength
|
||||||
const control = draw.getControl()
|
|
||||||
const activeControl = control.getActiveControl()
|
const activeControl = control.getActiveControl()
|
||||||
if (
|
if (
|
||||||
activeControl &&
|
activeControl &&
|
||||||
|
|||||||
+2
-1
@@ -1686,7 +1686,8 @@ window.onload = function () {
|
|||||||
'table',
|
'table',
|
||||||
'hyperlink',
|
'hyperlink',
|
||||||
'separator',
|
'separator',
|
||||||
'page-break'
|
'page-break',
|
||||||
|
'control'
|
||||||
]
|
]
|
||||||
// 菜单操作权限
|
// 菜单操作权限
|
||||||
disableMenusInControlContext.forEach(menu => {
|
disableMenusInControlContext.forEach(menu => {
|
||||||
|
|||||||
Reference in New Issue
Block a user