feat: add table context to contextmenu and getRangeContext api #576
This commit is contained in:
@@ -30,3 +30,15 @@ Usage:
|
|||||||
```javascript
|
```javascript
|
||||||
const contextMenuList = await instance.register.getContextMenuList()
|
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
|
```javascript
|
||||||
const contextMenuList = await instance.register.getContextMenuList()
|
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 zone = this.draw.getZone().getZone()
|
||||||
// 表格信息
|
// 表格信息
|
||||||
const isTable = this.position.getPositionContext().isTable
|
const { isTable, trIndex, tdIndex, index } =
|
||||||
return deepClone({
|
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,
|
isCollapsed,
|
||||||
startElement,
|
startElement,
|
||||||
endElement,
|
endElement,
|
||||||
@@ -2145,7 +2154,10 @@ export class CommandAdapt {
|
|||||||
endPageNo,
|
endPageNo,
|
||||||
rangeRects,
|
rangeRects,
|
||||||
zone,
|
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 { EditorComponent } from '../../dataset/enum/Editor'
|
||||||
import { DeepRequired } from '../../interface/Common'
|
import { DeepRequired } from '../../interface/Common'
|
||||||
import { IEditorOption } from '../../interface/Editor'
|
import { IEditorOption } from '../../interface/Editor'
|
||||||
|
import { IElement } from '../../interface/Element'
|
||||||
import {
|
import {
|
||||||
IContextMenuContext,
|
IContextMenuContext,
|
||||||
IRegisterContextMenu
|
IRegisterContextMenu
|
||||||
} from '../../interface/contextmenu/ContextMenu'
|
} from '../../interface/contextmenu/ContextMenu'
|
||||||
import { findParent } from '../../utils'
|
import { findParent } from '../../utils'
|
||||||
|
import { zipElementList } from '../../utils/element'
|
||||||
import { Command } from '../command/Command'
|
import { Command } from '../command/Command'
|
||||||
import { Draw } from '../draw/Draw'
|
import { Draw } from '../draw/Draw'
|
||||||
import { I18n } from '../i18n/I18n'
|
import { I18n } from '../i18n/I18n'
|
||||||
@@ -150,10 +152,18 @@ export class ContextMenu {
|
|||||||
// 是否存在选区
|
// 是否存在选区
|
||||||
const editorHasSelection = editorTextFocus && startIndex !== endIndex
|
const editorHasSelection = editorTextFocus && startIndex !== endIndex
|
||||||
// 是否在表格内
|
// 是否在表格内
|
||||||
const positionContext = this.position.getPositionContext()
|
const { isTable, trIndex, tdIndex, index } =
|
||||||
const isInTable = positionContext.isTable
|
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 elementList = this.draw.getElementList()
|
||||||
const startElement = elementList[startIndex] || null
|
const startElement = elementList[startIndex] || null
|
||||||
@@ -166,9 +176,12 @@ export class ContextMenu {
|
|||||||
isReadonly,
|
isReadonly,
|
||||||
editorHasSelection,
|
editorHasSelection,
|
||||||
editorTextFocus,
|
editorTextFocus,
|
||||||
isInTable,
|
|
||||||
isCrossRowCol,
|
isCrossRowCol,
|
||||||
zone
|
zone,
|
||||||
|
isInTable: isTable,
|
||||||
|
trIndex: trIndex ?? null,
|
||||||
|
tdIndex: tdIndex ?? null,
|
||||||
|
tableElement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ export type RangeContext = {
|
|||||||
rangeRects: RangeRect[]
|
rangeRects: RangeRect[]
|
||||||
zone: EditorZone
|
zone: EditorZone
|
||||||
isTable: boolean
|
isTable: boolean
|
||||||
|
trIndex: number | null
|
||||||
|
tdIndex: number | null
|
||||||
|
tableElement: IElement | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IRangeParagraphInfo {
|
export interface IRangeParagraphInfo {
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ export interface IContextMenuContext {
|
|||||||
isInTable: boolean
|
isInTable: boolean
|
||||||
isCrossRowCol: boolean
|
isCrossRowCol: boolean
|
||||||
zone: EditorZone
|
zone: EditorZone
|
||||||
|
trIndex: number | null
|
||||||
|
tdIndex: number | null
|
||||||
|
tableElement: IElement | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IRegisterContextMenu {
|
export interface IRegisterContextMenu {
|
||||||
|
|||||||
Reference in New Issue
Block a user