feat: add bounding rect to getRangeContext api
This commit is contained in:
@@ -40,7 +40,7 @@ import {
|
|||||||
} from '../../interface/Editor'
|
} 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 { RangeContext, RangeRect } 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'
|
||||||
@@ -1808,12 +1808,52 @@ export class CommandAdapt {
|
|||||||
const positionList = this.position.getPositionList()
|
const positionList = this.position.getPositionList()
|
||||||
const startPageNo = positionList[startIndex].pageNo
|
const startPageNo = positionList[startIndex].pageNo
|
||||||
const endPageNo = positionList[endIndex].pageNo
|
const endPageNo = positionList[endIndex].pageNo
|
||||||
|
// 坐标信息(相对编辑器书写区)
|
||||||
|
const rangeRects: RangeRect[] = []
|
||||||
|
const selectionPositionList = this.position.getSelectionPositionList()
|
||||||
|
if (selectionPositionList) {
|
||||||
|
const height = this.draw.getOriginalHeight()
|
||||||
|
const pageGap = this.draw.getOriginalPageGap()
|
||||||
|
// 起始信息及x坐标
|
||||||
|
let currentRowNo: number | null = null
|
||||||
|
let currentX = 0
|
||||||
|
let rangeRect: RangeRect | null = null
|
||||||
|
for (let p = 0; p < selectionPositionList.length; p++) {
|
||||||
|
const {
|
||||||
|
rowNo,
|
||||||
|
pageNo,
|
||||||
|
coordinate: { leftTop, rightTop },
|
||||||
|
lineHeight
|
||||||
|
} = selectionPositionList[p]
|
||||||
|
// 起始行变化追加选区信息
|
||||||
|
if (currentRowNo === null || currentRowNo !== rowNo) {
|
||||||
|
if (rangeRect) {
|
||||||
|
rangeRects.push(rangeRect)
|
||||||
|
}
|
||||||
|
rangeRect = {
|
||||||
|
x: leftTop[0],
|
||||||
|
y: leftTop[1] + pageNo * (height + pageGap),
|
||||||
|
width: rightTop[0] - leftTop[0],
|
||||||
|
height: lineHeight
|
||||||
|
}
|
||||||
|
currentRowNo = rowNo
|
||||||
|
currentX = leftTop[0]
|
||||||
|
} else {
|
||||||
|
rangeRect!.width = rightTop[0] - currentX
|
||||||
|
// 最后一个元素结束追加选区信息
|
||||||
|
if (p === selectionPositionList.length - 1 && rangeRect) {
|
||||||
|
rangeRects.push(rangeRect)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return deepClone({
|
return deepClone({
|
||||||
isCollapsed,
|
isCollapsed,
|
||||||
startElement,
|
startElement,
|
||||||
endElement,
|
endElement,
|
||||||
startPageNo,
|
startPageNo,
|
||||||
endPageNo
|
endPageNo,
|
||||||
|
rangeRects
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -352,6 +352,10 @@ export class Draw {
|
|||||||
return this.options.pageGap * this.options.scale
|
return this.options.pageGap * this.options.scale
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getOriginalPageGap(): number {
|
||||||
|
return this.options.pageGap
|
||||||
|
}
|
||||||
|
|
||||||
public getPageNumberBottom(): number {
|
public getPageNumberBottom(): number {
|
||||||
const {
|
const {
|
||||||
pageNumber: { bottom },
|
pageNumber: { bottom },
|
||||||
|
|||||||
@@ -74,6 +74,13 @@ export class Position {
|
|||||||
return this.positionList
|
return this.positionList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getSelectionPositionList(): IElementPosition[] | null {
|
||||||
|
const { startIndex, endIndex } = this.draw.getRange().getRange()
|
||||||
|
if (startIndex === endIndex) return null
|
||||||
|
const positionList = this.getPositionList()
|
||||||
|
return positionList.slice(startIndex + 1, endIndex + 1)
|
||||||
|
}
|
||||||
|
|
||||||
public setPositionList(payload: IElementPosition[]) {
|
public setPositionList(payload: IElementPosition[]) {
|
||||||
this.positionList = payload
|
this.positionList = payload
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { EditorZone } from '../dataset/enum/Editor'
|
import { EditorZone } from '../dataset/enum/Editor'
|
||||||
import { IElement } from './Element'
|
import { IElement, IElementFillRect } from './Element'
|
||||||
|
|
||||||
export interface IRange {
|
export interface IRange {
|
||||||
startIndex: number
|
startIndex: number
|
||||||
@@ -17,10 +17,13 @@ export type RangeRowArray = Map<number, number[]>
|
|||||||
|
|
||||||
export type RangeRowMap = Map<number, Set<number>>
|
export type RangeRowMap = Map<number, Set<number>>
|
||||||
|
|
||||||
|
export type RangeRect = IElementFillRect
|
||||||
|
|
||||||
export type RangeContext = {
|
export type RangeContext = {
|
||||||
isCollapsed: boolean
|
isCollapsed: boolean
|
||||||
startElement: IElement
|
startElement: IElement
|
||||||
endElement: IElement
|
endElement: IElement
|
||||||
startPageNo: number
|
startPageNo: number
|
||||||
endPageNo: number
|
endPageNo: number
|
||||||
|
rangeRects: RangeRect[]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user