Skip to content

Commit

Permalink
feat: add control paste disabled rule #853
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Oct 26, 2024
1 parent 3a81d56 commit 2bb84ab
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/en/guide/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ interface IElement {
rowFlex?: RowFlex
deletable?: boolean;
disabled?: boolean;
pasteDisabled?: boolean;
code: string | null;
min?: number;
max?: number;
Expand Down
1 change: 1 addition & 0 deletions docs/guide/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ interface IElement {
rowFlex?: RowFlex
deletable?: boolean;
disabled?: boolean;
pasteDisabled?: boolean;
code: string | null;
min?: number;
max?: number;
Expand Down
13 changes: 13 additions & 0 deletions src/editor/core/draw/control/Control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ export class Control {
return !!this.activeControl.getElement()?.control?.disabled
}

public getIsDisabledPasteControl(context: IControlContext = {}): boolean {
if (this.draw.isDesignMode() || !this.activeControl) return false
const { startIndex, endIndex } = context.range || this.range.getRange()
if (startIndex === endIndex && ~startIndex && ~endIndex) {
const elementList = context.elementList || this.getElementList()
const startElement = elementList[startIndex]
if (startElement.controlComponent === ControlComponent.POSTFIX) {
return false
}
}
return !!this.activeControl.getElement()?.control?.pasteDisabled
}

public getContainer(): HTMLDivElement {
return this.draw.getContainer()
}
Expand Down
8 changes: 7 additions & 1 deletion src/editor/core/event/handlers/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import { IOverrideResult } from '../../override/Override'

export function pasteElement(host: CanvasEvent, elementList: IElement[]) {
const draw = host.getDraw()
if (draw.isReadonly() || draw.isDisabled()) return
if (
draw.isReadonly() ||
draw.isDisabled() ||
draw.getControl().getIsDisabledPasteControl()
) {
return
}
const rangeManager = draw.getRange()
const { startIndex } = rangeManager.getRange()
const originalElementList = draw.getElementList()
Expand Down
1 change: 1 addition & 0 deletions src/editor/interface/Control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface IControlHighlight {
export interface IControlRule {
deletable?: boolean
disabled?: boolean
pasteDisabled?: boolean
}

export interface IControlBasic {
Expand Down

0 comments on commit 2bb84ab

Please sign in to comment.