feat: optimization of table operations in form mode #662

pr675
Hufe921 2 years ago
parent 9a4b4f9a4a
commit b74063741f

@ -181,7 +181,8 @@ export class ContextMenu {
isInTable: isTable, isInTable: isTable,
trIndex: trIndex ?? null, trIndex: trIndex ?? null,
tdIndex: tdIndex ?? null, tdIndex: tdIndex ?? null,
tableElement tableElement,
options: this.options
} }
} }

@ -1,4 +1,5 @@
import { INTERNAL_CONTEXT_MENU_KEY } from '../../../dataset/constant/ContextMenu' import { INTERNAL_CONTEXT_MENU_KEY } from '../../../dataset/constant/ContextMenu'
import { EditorMode } from '../../../dataset/enum/Editor'
import { IRegisterContextMenu } from '../../../interface/contextmenu/ContextMenu' import { IRegisterContextMenu } from '../../../interface/contextmenu/ContextMenu'
import { Command } from '../../command/Command' import { Command } from '../../command/Command'
const { const {
@ -13,7 +14,8 @@ export const controlMenus: IRegisterContextMenu[] = [
return ( return (
!payload.isReadonly && !payload.isReadonly &&
!payload.editorHasSelection && !payload.editorHasSelection &&
!!payload.startElement?.controlId !!payload.startElement?.controlId &&
payload.options.mode !== EditorMode.FORM
) )
}, },
callback: (command: Command) => { callback: (command: Command) => {

@ -1,4 +1,5 @@
import { INTERNAL_CONTEXT_MENU_KEY } from '../../../dataset/constant/ContextMenu' import { INTERNAL_CONTEXT_MENU_KEY } from '../../../dataset/constant/ContextMenu'
import { EditorMode } from '../../../dataset/enum/Editor'
import { VerticalAlign } from '../../../dataset/enum/VerticalAlign' import { VerticalAlign } from '../../../dataset/enum/VerticalAlign'
import { import {
TableBorder, TableBorder,
@ -47,7 +48,11 @@ export const tableMenus: IRegisterContextMenu[] = [
i18nPath: 'contextmenu.table.border', i18nPath: 'contextmenu.table.border',
icon: 'border-all', icon: 'border-all',
when: payload => { when: payload => {
return !payload.isReadonly && payload.isInTable return (
!payload.isReadonly &&
payload.isInTable &&
payload.options.mode !== EditorMode.FORM
)
}, },
childMenus: [ childMenus: [
{ {
@ -146,7 +151,11 @@ export const tableMenus: IRegisterContextMenu[] = [
i18nPath: 'contextmenu.table.verticalAlign', i18nPath: 'contextmenu.table.verticalAlign',
icon: 'vertical-align', icon: 'vertical-align',
when: payload => { when: payload => {
return !payload.isReadonly && payload.isInTable return (
!payload.isReadonly &&
payload.isInTable &&
payload.options.mode !== EditorMode.FORM
)
}, },
childMenus: [ childMenus: [
{ {
@ -183,7 +192,11 @@ export const tableMenus: IRegisterContextMenu[] = [
i18nPath: 'contextmenu.table.insertRowCol', i18nPath: 'contextmenu.table.insertRowCol',
icon: 'insert-row-col', icon: 'insert-row-col',
when: payload => { when: payload => {
return !payload.isReadonly && payload.isInTable return (
!payload.isReadonly &&
payload.isInTable &&
payload.options.mode !== EditorMode.FORM
)
}, },
childMenus: [ childMenus: [
{ {
@ -229,7 +242,11 @@ export const tableMenus: IRegisterContextMenu[] = [
i18nPath: 'contextmenu.table.deleteRowCol', i18nPath: 'contextmenu.table.deleteRowCol',
icon: 'delete-row-col', icon: 'delete-row-col',
when: payload => { when: payload => {
return !payload.isReadonly && payload.isInTable return (
!payload.isReadonly &&
payload.isInTable &&
payload.options.mode !== EditorMode.FORM
)
}, },
childMenus: [ childMenus: [
{ {
@ -266,7 +283,11 @@ export const tableMenus: IRegisterContextMenu[] = [
i18nPath: 'contextmenu.table.mergeCell', i18nPath: 'contextmenu.table.mergeCell',
icon: 'merge-cell', icon: 'merge-cell',
when: payload => { when: payload => {
return !payload.isReadonly && payload.isCrossRowCol return (
!payload.isReadonly &&
payload.isCrossRowCol &&
payload.options.mode !== EditorMode.FORM
)
}, },
callback: (command: Command) => { callback: (command: Command) => {
command.executeMergeTableCell() command.executeMergeTableCell()
@ -277,7 +298,11 @@ export const tableMenus: IRegisterContextMenu[] = [
i18nPath: 'contextmenu.table.mergeCancelCell', i18nPath: 'contextmenu.table.mergeCancelCell',
icon: 'merge-cancel-cell', icon: 'merge-cancel-cell',
when: payload => { when: payload => {
return !payload.isReadonly && payload.isInTable return (
!payload.isReadonly &&
payload.isInTable &&
payload.options.mode !== EditorMode.FORM
)
}, },
callback: (command: Command) => { callback: (command: Command) => {
command.executeCancelMergeTableCell() command.executeCancelMergeTableCell()

@ -295,6 +295,7 @@ export class Draw {
this.setEditorData(this.printModeData) this.setEditorData(this.printModeData)
this.printModeData = null this.printModeData = null
} }
this.clearSideEffect()
this.range.clearRange() this.range.clearRange()
this.mode = payload this.mode = payload
this.render({ this.render({

@ -170,7 +170,7 @@ export class Previewer {
'mouseup', 'mouseup',
() => { () => {
// 改变尺寸 // 改变尺寸
if (this.curElement) { if (this.curElement && !this.previewerDrawOption.dragDisable) {
this.curElement.width = this.width this.curElement.width = this.width
this.curElement.height = this.height this.curElement.height = this.height
this.draw.render({ this.draw.render({
@ -192,7 +192,7 @@ export class Previewer {
} }
private _mousemove(evt: MouseEvent) { private _mousemove(evt: MouseEvent) {
if (!this.curElement) return if (!this.curElement || this.previewerDrawOption.dragDisable) return
const { scale } = this.options const { scale } = this.options
let dx = 0 let dx = 0
let dy = 0 let dy = 0

@ -1,6 +1,8 @@
import { ImageDisplay } from '../../../dataset/enum/Common' import { ImageDisplay } from '../../../dataset/enum/Common'
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 { 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'
@ -135,15 +137,20 @@ export function mousedown(evt: MouseEvent, host: CanvasEvent) {
const previewer = draw.getPreviewer() const previewer = draw.getPreviewer()
previewer.clearResizer() previewer.clearResizer()
if (isDirectHitImage) { if (isDirectHitImage) {
const previewerDrawOption: IPreviewerDrawOption = {
// 只读或控件外表单模式禁用拖拽
dragDisable:
isReadonly ||
(!curElement.controlId && draw.getMode() === EditorMode.FORM)
}
if (curElement.type === ElementType.LATEX) {
previewerDrawOption.mime = 'svg'
previewerDrawOption.srcKey = 'laTexSVG'
}
previewer.drawResizer( previewer.drawResizer(
curElement, curElement,
positionList[curIndex], positionList[curIndex],
curElement.type === ElementType.LATEX previewerDrawOption
? {
mime: 'svg',
srcKey: 'laTexSVG'
}
: {}
) )
// 光标事件代理丢失,重新定位 // 光标事件代理丢失,重新定位
draw.getCursor().drawCursor({ draw.getCursor().drawCursor({
@ -162,7 +169,7 @@ export function mousedown(evt: MouseEvent, host: CanvasEvent) {
// 表格工具组件 // 表格工具组件
const tableTool = draw.getTableTool() const tableTool = draw.getTableTool()
tableTool.dispose() tableTool.dispose()
if (isTable && !isReadonly) { if (isTable && !isReadonly && draw.getMode() !== EditorMode.FORM) {
tableTool.render() tableTool.render()
} }
// 超链接 // 超链接

@ -11,4 +11,5 @@ export interface IPreviewerCreateResult {
export interface IPreviewerDrawOption { export interface IPreviewerDrawOption {
mime?: 'png' | 'jpg' | 'jpeg' | 'svg' mime?: 'png' | 'jpg' | 'jpeg' | 'svg'
srcKey?: keyof Pick<IElement, 'value' | 'laTexSVG'> srcKey?: keyof Pick<IElement, 'value' | 'laTexSVG'>
dragDisable?: boolean
} }

@ -1,5 +1,7 @@
import { Command } from '../../core/command/Command' import { Command } from '../../core/command/Command'
import { EditorZone } from '../../dataset/enum/Editor' import { EditorZone } from '../../dataset/enum/Editor'
import { DeepRequired } from '../Common'
import { IEditorOption } from '../Editor'
import { IElement } from '../Element' import { IElement } from '../Element'
export interface IContextMenuContext { export interface IContextMenuContext {
@ -14,6 +16,7 @@ export interface IContextMenuContext {
trIndex: number | null trIndex: number | null
tdIndex: number | null tdIndex: number | null
tableElement: IElement | null tableElement: IElement | null
options: DeepRequired<IEditorOption>
} }
export interface IRegisterContextMenu { export interface IRegisterContextMenu {

Loading…
Cancel
Save