From 021e54895bac9a4b0980d623d235d06cf9216213 Mon Sep 17 00:00:00 2001 From: dmitrykurmanov Date: Mon, 5 Aug 2024 16:49:33 +0400 Subject: [PATCH 1/3] work for the https://github.com/surveyjs/survey-creator/issues/5740 --- src/dragdrop/core.ts | 3 ++- tests/dragdrophelpertests.ts | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dragdrop/core.ts b/src/dragdrop/core.ts index e8a9fd7a9a..30ac0b54b6 100644 --- a/src/dragdrop/core.ts +++ b/src/dragdrop/core.ts @@ -63,6 +63,8 @@ export abstract class DragDropCore implements IDragDropEngine { event ); this.onStartDrag(event); + const fromElement = this.draggedElement.parent; + this.onDragStart.fire(this, { fromElement: fromElement, draggedElement: this.draggedElement }); } protected onStartDrag(event?: PointerEvent): void { @@ -230,7 +232,6 @@ export abstract class DragDropCore implements IDragDropEngine { public drop(): void { if (this.allowDropHere) { const fromElement = this.draggedElement.parent; - this.onDragStart.fire(this, { fromElement: fromElement, draggedElement: this.draggedElement }); const newElement = this.doDrop(); this.onDragEnd.fire(this, { fromElement: fromElement, draggedElement: newElement, toElement: this.dropTarget }); } diff --git a/tests/dragdrophelpertests.ts b/tests/dragdrophelpertests.ts index 7dd074b581..8e165e645e 100644 --- a/tests/dragdrophelpertests.ts +++ b/tests/dragdrophelpertests.ts @@ -144,12 +144,14 @@ QUnit.test("choices: onDragStart and onDragEnd events", function (assert) { ddHelper.parentElement = question; ddHelper.draggedElement = question.choices[2]; + ddHelper["createDraggedElementShortcut"] = ()=>{}; + ddHelper.dragInit(null, ddHelper.draggedElement, ddHelper.parentElement, document.createElement("div")); + assert.equal(beforeCount, 1); + ddHelper["allowDropHere"] = true; ddHelper["domAdapter"]["draggedElementShortcut"] = document.body.appendChild( document.createElement("div") ); - ddHelper["allowDropHere"] = true; ddHelper["drop"](); - assert.equal(beforeCount, 1); assert.equal(afterCount, 1); assert.equal(draggedElementParent.name, "q"); }); From 658040d9e02cc9f5b2fd648f7a07721f9e1de322 Mon Sep 17 00:00:00 2001 From: dmitrykurmanov Date: Mon, 5 Aug 2024 16:57:08 +0400 Subject: [PATCH 2/3] work for the https://github.com/surveyjs/survey-creator/issues/5740 --- src/dragdrop/core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dragdrop/core.ts b/src/dragdrop/core.ts index 30ac0b54b6..61d3e77b7e 100644 --- a/src/dragdrop/core.ts +++ b/src/dragdrop/core.ts @@ -63,7 +63,7 @@ export abstract class DragDropCore implements IDragDropEngine { event ); this.onStartDrag(event); - const fromElement = this.draggedElement.parent; + const fromElement = this.draggedElement && this.draggedElement.parent; this.onDragStart.fire(this, { fromElement: fromElement, draggedElement: this.draggedElement }); } From 17570bb19e0a70d73d2be5dc6df47142fb1b9903 Mon Sep 17 00:00:00 2001 From: dmitrykurmanov Date: Mon, 5 Aug 2024 17:13:21 +0400 Subject: [PATCH 3/3] work for the https://github.com/surveyjs/survey-creator/issues/5740 --- src/dragdrop/core.ts | 2 ++ tests/dragdrophelpertests.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/dragdrop/core.ts b/src/dragdrop/core.ts index 61d3e77b7e..11357a6ace 100644 --- a/src/dragdrop/core.ts +++ b/src/dragdrop/core.ts @@ -22,6 +22,7 @@ export abstract class DragDropCore implements IDragDropEngine { public onDragStart: EventBase> = new EventBase(); public onDragEnd: EventBase> = new EventBase(); + public onDragClear: EventBase> = new EventBase(); public onBeforeDrop = this.onDragStart; public onAfterDrop = this.onDragEnd; @@ -243,5 +244,6 @@ export abstract class DragDropCore implements IDragDropEngine { this.draggedElement = null; this.isBottom = null; this.parentElement = null; + this.onDragClear.fire(this, {}); } } diff --git a/tests/dragdrophelpertests.ts b/tests/dragdrophelpertests.ts index 8e165e645e..77d87bf9a7 100644 --- a/tests/dragdrophelpertests.ts +++ b/tests/dragdrophelpertests.ts @@ -116,7 +116,7 @@ QUnit.test("dropTargetDataAttributeName for choices", function (assert) { ); }); -QUnit.test("choices: onDragStart and onDragEnd events", function (assert) { +QUnit.test("choices: onDragStart, onDragEnd, onDragClear events", function (assert) { const survey = new SurveyModel({ elements: [ { @@ -131,6 +131,7 @@ QUnit.test("choices: onDragStart and onDragEnd events", function (assert) { ); let beforeCount = 0; let afterCount = 0; + let clearCount = 0; let draggedElementParent; const ddHelper: any = new DragDropChoices(survey); @@ -141,6 +142,10 @@ QUnit.test("choices: onDragStart and onDragEnd events", function (assert) { afterCount++; draggedElementParent = options.draggedElement; }); + ddHelper.onDragClear.add((sender, options) => { + clearCount++; + }); + ddHelper.parentElement = question; ddHelper.draggedElement = question.choices[2]; @@ -154,6 +159,8 @@ QUnit.test("choices: onDragStart and onDragEnd events", function (assert) { ddHelper["drop"](); assert.equal(afterCount, 1); assert.equal(draggedElementParent.name, "q"); + ddHelper["clear"](); + assert.equal(clearCount, 1); }); QUnit.test("DragDropRankingChoices shortcutClass getter", function (assert) {