feat: get range context info
This commit is contained in:
@@ -48,6 +48,14 @@ const wordCount = await instance.command.getWordCount()
|
|||||||
const rangeText = instance.command.getRangeText()
|
const rangeText = instance.command.getRangeText()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## getRangeContext
|
||||||
|
功能:获取选区上下文
|
||||||
|
|
||||||
|
用法:
|
||||||
|
```javascript
|
||||||
|
const rangeContext = instance.command.getRangeContext()
|
||||||
|
```
|
||||||
|
|
||||||
## getPaperMargin
|
## getPaperMargin
|
||||||
功能:获取页边距
|
功能:获取页边距
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ export class Command {
|
|||||||
public getValue: CommandAdapt['getValue']
|
public getValue: CommandAdapt['getValue']
|
||||||
public getWordCount: CommandAdapt['getWordCount']
|
public getWordCount: CommandAdapt['getWordCount']
|
||||||
public getRangeText: CommandAdapt['getRangeText']
|
public getRangeText: CommandAdapt['getRangeText']
|
||||||
|
public getRangeContext: CommandAdapt['getRangeContext']
|
||||||
public getPaperMargin: CommandAdapt['getPaperMargin']
|
public getPaperMargin: CommandAdapt['getPaperMargin']
|
||||||
public getSearchNavigateInfo: CommandAdapt['getSearchNavigateInfo']
|
public getSearchNavigateInfo: CommandAdapt['getSearchNavigateInfo']
|
||||||
|
|
||||||
@@ -168,6 +169,7 @@ export class Command {
|
|||||||
this.getValue = adapt.getValue.bind(adapt)
|
this.getValue = adapt.getValue.bind(adapt)
|
||||||
this.getWordCount = adapt.getWordCount.bind(adapt)
|
this.getWordCount = adapt.getWordCount.bind(adapt)
|
||||||
this.getRangeText = adapt.getRangeText.bind(adapt)
|
this.getRangeText = adapt.getRangeText.bind(adapt)
|
||||||
|
this.getRangeContext = adapt.getRangeContext.bind(adapt)
|
||||||
this.getCatalog = adapt.getCatalog.bind(adapt)
|
this.getCatalog = adapt.getCatalog.bind(adapt)
|
||||||
this.getPaperMargin = adapt.getPaperMargin.bind(adapt)
|
this.getPaperMargin = adapt.getPaperMargin.bind(adapt)
|
||||||
this.getSearchNavigateInfo = adapt.getSearchNavigateInfo.bind(adapt)
|
this.getSearchNavigateInfo = adapt.getSearchNavigateInfo.bind(adapt)
|
||||||
|
|||||||
@@ -16,12 +16,13 @@ import { IAppendElementListOption, IDrawImagePayload, IGetValueOption, IPainterO
|
|||||||
import { IEditorData, IEditorOption, IEditorResult } from '../../interface/Editor'
|
import { IEditorData, IEditorOption, IEditorResult } from '../../interface/Editor'
|
||||||
import { IElement, IElementStyle } from '../../interface/Element'
|
import { IElement, IElementStyle } from '../../interface/Element'
|
||||||
import { IMargin } from '../../interface/Margin'
|
import { IMargin } from '../../interface/Margin'
|
||||||
|
import { RangeContext } from '../../interface/Range'
|
||||||
import { IColgroup } from '../../interface/table/Colgroup'
|
import { IColgroup } from '../../interface/table/Colgroup'
|
||||||
import { ITd } from '../../interface/table/Td'
|
import { ITd } from '../../interface/table/Td'
|
||||||
import { ITr } from '../../interface/table/Tr'
|
import { ITr } from '../../interface/table/Tr'
|
||||||
import { IWatermark } from '../../interface/Watermark'
|
import { IWatermark } from '../../interface/Watermark'
|
||||||
import { downloadFile, getUUID } from '../../utils'
|
import { deepClone, downloadFile, getUUID } from '../../utils'
|
||||||
import { formatElementContext, formatElementList, isTextLikeElement } from '../../utils/element'
|
import { formatElementContext, formatElementList, isTextLikeElement, pickElementAttr } from '../../utils/element'
|
||||||
import { printImageBase64 } from '../../utils/print'
|
import { printImageBase64 } from '../../utils/print'
|
||||||
import { Control } from '../draw/control/Control'
|
import { Control } from '../draw/control/Control'
|
||||||
import { Draw } from '../draw/Draw'
|
import { Draw } from '../draw/Draw'
|
||||||
@@ -1601,6 +1602,29 @@ export class CommandAdapt {
|
|||||||
return this.range.toString()
|
return this.range.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getRangeContext(): RangeContext | null {
|
||||||
|
const range = this.range.getRange()
|
||||||
|
const { startIndex, endIndex } = range
|
||||||
|
if (!~startIndex && !~endIndex) return null
|
||||||
|
// 选区信息
|
||||||
|
const isCollapsed = startIndex === endIndex
|
||||||
|
// 元素信息
|
||||||
|
const elementList = this.draw.getElementList()
|
||||||
|
const startElement = pickElementAttr(elementList[isCollapsed ? startIndex : startIndex + 1])
|
||||||
|
const endElement = pickElementAttr(elementList[endIndex])
|
||||||
|
// 页码信息
|
||||||
|
const positionList = this.position.getPositionList()
|
||||||
|
const startPageNo = positionList[startIndex].pageNo
|
||||||
|
const endPageNo = positionList[endIndex].pageNo
|
||||||
|
return deepClone({
|
||||||
|
isCollapsed,
|
||||||
|
startElement,
|
||||||
|
endElement,
|
||||||
|
startPageNo,
|
||||||
|
endPageNo
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public pageMode(payload: PageMode) {
|
public pageMode(payload: PageMode) {
|
||||||
this.draw.setPageMode(payload)
|
this.draw.setPageMode(payload)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { EditorZone } from '../dataset/enum/Editor'
|
import { EditorZone } from '../dataset/enum/Editor'
|
||||||
|
import { IElement } from './Element'
|
||||||
|
|
||||||
export interface IRange {
|
export interface IRange {
|
||||||
startIndex: number;
|
startIndex: number;
|
||||||
@@ -15,3 +16,11 @@ export interface IRange {
|
|||||||
export type RangeRowArray = Map<number, number[]>
|
export type RangeRowArray = Map<number, number[]>
|
||||||
|
|
||||||
export type RangeRowMap = Map<number, Set<number>>
|
export type RangeRowMap = Map<number, Set<number>>
|
||||||
|
|
||||||
|
export type RangeContext = {
|
||||||
|
isCollapsed: boolean;
|
||||||
|
startElement: IElement;
|
||||||
|
endElement: IElement;
|
||||||
|
startPageNo: number;
|
||||||
|
endPageNo: number;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user