feat: add location property to executeLocationControl api #753
Co-authored-by: Hufe921 <huangyunfeihufe@hotmail.com>
This commit is contained in:
@@ -929,7 +929,7 @@ Feature: Positioning and activating control
|
||||
Usage:
|
||||
|
||||
```javascript
|
||||
instance.command.executeLocationControl(controlId: string)
|
||||
instance.command.executeLocationControl(controlId: string, options?: ILocationControlOption)
|
||||
```
|
||||
|
||||
## executeInsertControl
|
||||
|
||||
@@ -929,7 +929,7 @@ instance.command.executeSetControlHighlight(payload: ISetControlHighlightOption)
|
||||
用法:
|
||||
|
||||
```javascript
|
||||
instance.command.executeLocationControl(controlId: string)
|
||||
instance.command.executeLocationControl(controlId: string, options?: ILocationControlOption)
|
||||
```
|
||||
|
||||
## executeInsertControl
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
titleSizeMapping
|
||||
} from '../../dataset/constant/Title'
|
||||
import { defaultWatermarkOption } from '../../dataset/constant/Watermark'
|
||||
import { ImageDisplay } from '../../dataset/enum/Common'
|
||||
import { ImageDisplay, LocationPosition } from '../../dataset/enum/Common'
|
||||
import { ControlComponent } from '../../dataset/enum/Control'
|
||||
import {
|
||||
EditorContext,
|
||||
@@ -31,6 +31,7 @@ import { DeepRequired } from '../../interface/Common'
|
||||
import {
|
||||
IGetControlValueOption,
|
||||
IGetControlValueResult,
|
||||
ILocationControlOption,
|
||||
ISetControlExtensionOption,
|
||||
ISetControlHighlightOption,
|
||||
ISetControlProperties,
|
||||
@@ -2468,7 +2469,8 @@ export class CommandAdapt {
|
||||
return this.draw.getControl().getList()
|
||||
}
|
||||
|
||||
public locationControl(controlId: string) {
|
||||
public locationControl(controlId: string, options?: ILocationControlOption) {
|
||||
const isLocationAfter = options?.position === LocationPosition.AFTER
|
||||
function location(
|
||||
elementList: IElement[],
|
||||
zone: EditorZone
|
||||
@@ -2502,7 +2504,16 @@ export class CommandAdapt {
|
||||
}
|
||||
}
|
||||
if (element?.controlId !== controlId) continue
|
||||
const curIndex = i - 1
|
||||
let curIndex = i - 1
|
||||
if (isLocationAfter) {
|
||||
curIndex -= 1
|
||||
if (
|
||||
element.controlComponent !== ControlComponent.PLACEHOLDER &&
|
||||
element.controlComponent !== ControlComponent.POSTFIX
|
||||
) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
return {
|
||||
zone,
|
||||
range: {
|
||||
|
||||
@@ -15,3 +15,8 @@ export enum ImageDisplay {
|
||||
FLOAT_TOP = 'float-top',
|
||||
FLOAT_BOTTOM = 'float-bottom'
|
||||
}
|
||||
|
||||
export enum LocationPosition {
|
||||
BEFORE = 'before',
|
||||
AFTER = 'after'
|
||||
}
|
||||
|
||||
+3
-2
@@ -6,7 +6,7 @@ import { Command } from './core/command/Command'
|
||||
import { CommandAdapt } from './core/command/CommandAdapt'
|
||||
import { Listener } from './core/listener/Listener'
|
||||
import { RowFlex } from './dataset/enum/Row'
|
||||
import { ImageDisplay } from './dataset/enum/Common'
|
||||
import { ImageDisplay, LocationPosition } from './dataset/enum/Common'
|
||||
import { ElementType } from './dataset/enum/Element'
|
||||
import { formatElementList } from './utils/element'
|
||||
import { Register } from './core/register/Register'
|
||||
@@ -171,7 +171,8 @@ export {
|
||||
BackgroundRepeat,
|
||||
BackgroundSize,
|
||||
TextDecorationStyle,
|
||||
LineNumberType
|
||||
LineNumberType,
|
||||
LocationPosition
|
||||
}
|
||||
|
||||
// 对外类型
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { LocationPosition } from '../dataset/enum/Common'
|
||||
import { ControlType, ControlIndentation } from '../dataset/enum/Control'
|
||||
import { EditorZone } from '../dataset/enum/Editor'
|
||||
import { MoveDirection } from '../dataset/enum/Observer'
|
||||
@@ -168,3 +169,7 @@ export interface INextControlContext {
|
||||
export interface IInitNextControlOption {
|
||||
direction?: MoveDirection
|
||||
}
|
||||
|
||||
export interface ILocationControlOption {
|
||||
position: LocationPosition
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user