From 19c970db1774c7fa9e22ad75dc88523b3d44ae14 Mon Sep 17 00:00:00 2001 From: Aleksey Novikov Date: Thu, 10 Oct 2024 10:07:46 +0300 Subject: [PATCH] #5925 - add new event --- .../survey-creator-core/src/creator-base.ts | 3 ++ .../survey-creator-core/src/entries/index.ts | 1 + .../src/survey-elements.ts | 34 +++++++++++-------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/packages/survey-creator-core/src/creator-base.ts b/packages/survey-creator-core/src/creator-base.ts index 2010a22100..28e67a7b5a 100644 --- a/packages/survey-creator-core/src/creator-base.ts +++ b/packages/survey-creator-core/src/creator-base.ts @@ -771,6 +771,8 @@ export class SurveyCreatorModel extends Base */ public onDragDropAllow: EventBase = this.addCreatorEvent(); + public onDragOverLocationCalculating: EventBase = this.addCreatorEvent(); + /** * An event that allows you to create a custom message panel. * @@ -1909,6 +1911,7 @@ export class SurveyCreatorModel extends Base settings.dragDrop.restrictDragQuestionBetweenPages; this.dragDropSurveyElements = new DragDropSurveyElements(null, this); this.dragDropSurveyElements.onGetMaxNestedPanels = (): number => { return this.maxNestedPanels; }; + this.dragDropSurveyElements.onDragOverLocationCalculating = (options) => { this.onDragOverLocationCalculating.fire(this, options); }; let isDraggedFromToolbox = false; this.dragDropSurveyElements.onDragStart.add((sender, options) => { isDraggedFromToolbox = !sender.draggedElement.parent; diff --git a/packages/survey-creator-core/src/entries/index.ts b/packages/survey-creator-core/src/entries/index.ts index 6a21f5a81c..00642db300 100644 --- a/packages/survey-creator-core/src/entries/index.ts +++ b/packages/survey-creator-core/src/entries/index.ts @@ -100,6 +100,7 @@ export * from "../presets/presets"; export * from "../presets/presets-properties"; export * from "../presets/presets-tabs"; export * from "../presets/presets-toolbox"; +export * from "../survey-elements"; require("../components/property-panel/property-panel-item.scss"); require("../components/property-panel/property-panel.scss"); diff --git a/packages/survey-creator-core/src/survey-elements.ts b/packages/survey-creator-core/src/survey-elements.ts index 36f7564124..013a36639f 100644 --- a/packages/survey-creator-core/src/survey-elements.ts +++ b/packages/survey-creator-core/src/survey-elements.ts @@ -65,6 +65,7 @@ export class DragDropSurveyElements extends DragDropCore { } protected isDraggedElementSelected: boolean = false; public onGetMaxNestedPanels: () => number; + public onDragOverLocationCalculating: (options: any) => void; public get maxNestedPanels(): number { return this.onGetMaxNestedPanels ? this.onGetMaxNestedPanels() : -1; } // private isRight: boolean; @@ -306,7 +307,7 @@ export class DragDropSurveyElements extends DragDropCore { } return allowOptions.allow; } - public dragOverCore(dropTarget: ISurveyElement, dragOverLocation: DragTypeOverMeEnum, dragOverLocationIfNotAllowed: DragTypeOverMeEnum): void { + public dragOverCore(dropTarget: ISurveyElement, dragOverLocation: DragTypeOverMeEnum): void { const oldDragOverIndicatorElement = this.dragOverIndicatorElement; const oldDropTarget = this.dropTarget; if (this.isSameElement(dropTarget)) { @@ -320,17 +321,8 @@ export class DragDropSurveyElements extends DragDropCore { ? this.dropTarget : ((this.dropTarget).page || (this.dropTarget).__page); if (!this.isAllowDragOver(dropTarget, dragOverLocation)) { - if (dragOverLocation != DragTypeOverMeEnum.InsideEmptyPanel) { - this.allowDropHere = false; - return; - } - dragOverLocation = dragOverLocationIfNotAllowed; - this.dragOverLocation = dragOverLocation; - this.insideContainer = false; - if (!this.isAllowDragOver(dropTarget, dragOverLocation)) { - this.allowDropHere = false; - return; - } + this.allowDropHere = false; + return; } if (dragOverLocation == DragTypeOverMeEnum.InsideEmptyPanel) { this.dragOverIndicatorElement = this.dropTarget; @@ -371,13 +363,25 @@ export class DragDropSurveyElements extends DragDropCore { const dropTarget = this.getDropTargetByNode(dropTargetNode, event); if (!!oldInsideContainer != !!this.insideContainer) dropTarget.dragTypeOverMe = null; - const dragOverLocationSide = calculateDragOverLocation(event.clientX, event.clientY, dropTargetNode); - let dragOverLocation = dragOverLocationSide; + let dragOverLocation = calculateDragOverLocation(event.clientX, event.clientY, dropTargetNode); if (dropTarget && ((dropTarget.isPanel || dropTarget.isPage) && dropTarget.elements.length === 0 || isPanelDynamic(dropTarget) && dropTarget.template.elements.length == 0)) { if (dropTarget.isPage || this.insideContainer) { dragOverLocation = DragTypeOverMeEnum.InsideEmptyPanel; } } + const options = { + survey: this.survey, + draggedSurveyElement: this.draggedElement, + dragOverSurveyElement: dropTarget, + clientX: event.clientX, + clientY: event.clientY, + dragOverHtmlElement: dropTargetNode, + dragOverLocation + }; + if (this.onDragOverLocationCalculating) { + this.onDragOverLocationCalculating(options); + dragOverLocation = options.dragOverLocation; + } const isDropTargetValid = this.isDropTargetValid( dropTarget, dropTargetNode, @@ -391,7 +395,7 @@ export class DragDropSurveyElements extends DragDropCore { this.allowDropHere = true; - this.dragOverCore(dropTarget, dragOverLocation, dragOverLocationSide); + this.dragOverCore(dropTarget, dragOverLocation); } protected onStartDrag(): void {