Skip to content

Commit

Permalink
#5925 - add new event
Browse files Browse the repository at this point in the history
  • Loading branch information
novikov82 committed Oct 10, 2024
1 parent 84e72a5 commit 19c970d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
3 changes: 3 additions & 0 deletions packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,8 @@ export class SurveyCreatorModel extends Base
*/
public onDragDropAllow: EventBase<SurveyCreatorModel, DragDropAllowEvent> = this.addCreatorEvent<SurveyCreatorModel, DragDropAllowEvent>();

public onDragOverLocationCalculating: EventBase<SurveyCreatorModel, any> = this.addCreatorEvent<SurveyCreatorModel, any>();

/**
* An event that allows you to create a custom message panel.
*
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/survey-creator-core/src/entries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
34 changes: 19 additions & 15 deletions packages/survey-creator-core/src/survey-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class DragDropSurveyElements extends DragDropCore<any> {
}
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;
Expand Down Expand Up @@ -306,7 +307,7 @@ export class DragDropSurveyElements extends DragDropCore<any> {
}
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)) {
Expand All @@ -320,17 +321,8 @@ export class DragDropSurveyElements extends DragDropCore<any> {
? this.dropTarget
: ((<any>this.dropTarget).page || (<any>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;
Expand Down Expand Up @@ -371,13 +363,25 @@ export class DragDropSurveyElements extends DragDropCore<any> {
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,
Expand All @@ -391,7 +395,7 @@ export class DragDropSurveyElements extends DragDropCore<any> {

this.allowDropHere = true;

this.dragOverCore(dropTarget, dragOverLocation, dragOverLocationSide);
this.dragOverCore(dropTarget, dragOverLocation);
}

protected onStartDrag(): void {
Expand Down

0 comments on commit 19c970d

Please sign in to comment.