feat: add table context to contextmenu and getRangeContext api #576
This commit is contained in:
@@ -30,3 +30,15 @@ Usage:
|
||||
```javascript
|
||||
const contextMenuList = await instance.register.getContextMenuList()
|
||||
```
|
||||
|
||||
Remark:
|
||||
|
||||
```javascript
|
||||
// Example of modifying internal contextmenu
|
||||
contextmenuList.forEach(menu => {
|
||||
// Find the menu item through the menu key and modify its properties
|
||||
if (menu.key === INTERNAL_CONTEXT_MENU_KEY.GLOBAL.PASTE) {
|
||||
menu.when = () => false
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
@@ -30,3 +30,15 @@ instance.register.contextMenuList([
|
||||
```javascript
|
||||
const contextMenuList = await instance.register.getContextMenuList()
|
||||
```
|
||||
|
||||
备注:
|
||||
|
||||
```javascript
|
||||
// 修改内部右键菜单示例
|
||||
contextmenuList.forEach(menu => {
|
||||
// 通过菜单key找到菜单项后进行属性修改
|
||||
if (menu.key === INTERNAL_CONTEXT_MENU_KEY.GLOBAL.PASTE) {
|
||||
menu.when = () => false
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
@@ -2136,8 +2136,17 @@ export class CommandAdapt {
|
||||
// 区域信息
|
||||
const zone = this.draw.getZone().getZone()
|
||||
// 表格信息
|
||||
const isTable = this.position.getPositionContext().isTable
|
||||
return deepClone({
|
||||
const { isTable, trIndex, tdIndex, index } =
|
||||
this.position.getPositionContext()
|
||||
let tableElement: IElement | null = null
|
||||
if (isTable) {
|
||||
const originalElementList = this.draw.getOriginalElementList()
|
||||
const originTableElement = originalElementList[index!] || null
|
||||
if (originTableElement) {
|
||||
tableElement = zipElementList([originTableElement])[0]
|
||||
}
|
||||
}
|
||||
return deepClone<RangeContext>({
|
||||
isCollapsed,
|
||||
startElement,
|
||||
endElement,
|
||||
@@ -2145,7 +2154,10 @@ export class CommandAdapt {
|
||||
endPageNo,
|
||||
rangeRects,
|
||||
zone,
|
||||
isTable
|
||||
isTable,
|
||||
trIndex: trIndex ?? null,
|
||||
tdIndex: tdIndex ?? null,
|
||||
tableElement
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@ import { EDITOR_COMPONENT, EDITOR_PREFIX } from '../../dataset/constant/Editor'
|
||||
import { EditorComponent } from '../../dataset/enum/Editor'
|
||||
import { DeepRequired } from '../../interface/Common'
|
||||
import { IEditorOption } from '../../interface/Editor'
|
||||
import { IElement } from '../../interface/Element'
|
||||
import {
|
||||
IContextMenuContext,
|
||||
IRegisterContextMenu
|
||||
} from '../../interface/contextmenu/ContextMenu'
|
||||
import { findParent } from '../../utils'
|
||||
import { zipElementList } from '../../utils/element'
|
||||
import { Command } from '../command/Command'
|
||||
import { Draw } from '../draw/Draw'
|
||||
import { I18n } from '../i18n/I18n'
|
||||
@@ -150,10 +152,18 @@ export class ContextMenu {
|
||||
// 是否存在选区
|
||||
const editorHasSelection = editorTextFocus && startIndex !== endIndex
|
||||
// 是否在表格内
|
||||
const positionContext = this.position.getPositionContext()
|
||||
const isInTable = positionContext.isTable
|
||||
const { isTable, trIndex, tdIndex, index } =
|
||||
this.position.getPositionContext()
|
||||
let tableElement: IElement | null = null
|
||||
if (isTable) {
|
||||
const originalElementList = this.draw.getOriginalElementList()
|
||||
const originTableElement = originalElementList[index!] || null
|
||||
if (originTableElement) {
|
||||
tableElement = zipElementList([originTableElement])[0]
|
||||
}
|
||||
}
|
||||
// 是否存在跨行/列
|
||||
const isCrossRowCol = isInTable && !!crossRowCol
|
||||
const isCrossRowCol = isTable && !!crossRowCol
|
||||
// 当前元素
|
||||
const elementList = this.draw.getElementList()
|
||||
const startElement = elementList[startIndex] || null
|
||||
@@ -166,9 +176,12 @@ export class ContextMenu {
|
||||
isReadonly,
|
||||
editorHasSelection,
|
||||
editorTextFocus,
|
||||
isInTable,
|
||||
isCrossRowCol,
|
||||
zone
|
||||
zone,
|
||||
isInTable: isTable,
|
||||
trIndex: trIndex ?? null,
|
||||
tdIndex: tdIndex ?? null,
|
||||
tableElement
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@ export type RangeContext = {
|
||||
rangeRects: RangeRect[]
|
||||
zone: EditorZone
|
||||
isTable: boolean
|
||||
trIndex: number | null
|
||||
tdIndex: number | null
|
||||
tableElement: IElement | null
|
||||
}
|
||||
|
||||
export interface IRangeParagraphInfo {
|
||||
|
||||
@@ -11,6 +11,9 @@ export interface IContextMenuContext {
|
||||
isInTable: boolean
|
||||
isCrossRowCol: boolean
|
||||
zone: EditorZone
|
||||
trIndex: number | null
|
||||
tdIndex: number | null
|
||||
tableElement: IElement | null
|
||||
}
|
||||
|
||||
export interface IRegisterContextMenu {
|
||||
|
||||
Reference in New Issue
Block a user