Skip to content

Commit

Permalink
#5680 - supported dynamic panel
Browse files Browse the repository at this point in the history
  • Loading branch information
novikov82 committed Aug 14, 2024
1 parent f6eb6e7 commit 71b1421
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { SurveyCreatorModel } from "../creator-base";
import { settings } from "../creator-settings";
import { DesignerStateManager } from "./tabs/designer-state-manager";
import { TabDesignerPlugin } from "./tabs/designer-plugin";
import { isPanelDynamic } from "../survey-elements";

export class SurveyElementActionContainer extends AdaptiveActionContainer {
private needToShrink(item: Action, shrinkStart: boolean, shrinkEnd: boolean) {
Expand Down Expand Up @@ -115,8 +116,12 @@ export class SurveyElementAdornerBase<T extends SurveyElement = SurveyElement> e

private dragCollapsedTimer;

protected get canExpandOnDrag() {
return this.surveyElement.isPanel || this.surveyElement.isPage || isPanelDynamic(this.surveyElement);
}

protected dragIn() {
if ((this.surveyElement.isPanel || this.surveyElement.isPage) && this.collapsed) {
if (this.canExpandOnDrag && this.collapsed) {
this.dragCollapsedTimer = setTimeout(() => {
this.expandWithDragIn();
}, this.creator.expandOnDragTimeOut);
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-creator-core/src/components/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { SurveyElementAdornerBase } from "./action-container-view-model";
require("./question.scss");
import { settings } from "../creator-settings";
import { StringEditorConnector, StringItemsNavigatorBase } from "./string-editor";
import { DragDropSurveyElements } from "../survey-elements";
import { DragDropSurveyElements, isPanelDynamic } from "../survey-elements";
import { QuestionToolbox, QuestionToolboxItem } from "../toolbox";

export interface QuestionBannerParams {
Expand Down Expand Up @@ -132,7 +132,7 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
result += " svc-question__content--dragged";
}

if (!!this.dragTypeOverMe && this.surveyElement.isPanel && this.dragInsideCollapsedContainer) {
if (!!this.dragTypeOverMe && (this.canExpandOnDrag) && this.dragInsideCollapsedContainer) {
result += " svc-question__content--collapsed-drag-over-inside";
}

Expand Down
14 changes: 10 additions & 4 deletions packages/survey-creator-core/src/survey-elements.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DragDropAllowEvent, DragDropCore, DragTypeOverMeEnum, IElement, IPanel, IShortcutText, ISurveyElement, JsonObject, PageModel, PanelModelBase, QuestionRowModel, Serializer, SurveyModel } from "survey-core";
import { DragDropAllowEvent, DragDropCore, DragTypeOverMeEnum, IElement, IPanel, IShortcutText, ISurveyElement, JsonObject, PageModel, PanelModelBase, QuestionPanelDynamicModel, QuestionRowModel, Serializer, SurveyModel } from "survey-core";
import { settings } from "./creator-settings";
import { IQuestionToolboxItem } from "./toolbox";
import { SurveyHelper } from "./survey-helper";
Expand Down Expand Up @@ -43,6 +43,10 @@ export function calculateDragOverLocation(clientX: number, clientY: number, drop
}
}

export function isPanelDynamic(element: ISurveyElement) {
return element instanceof QuestionPanelDynamicModel;
}

export class DragDropSurveyElements extends DragDropCore<any> {
public static newGhostPage: PageModel = null;
public static restrictDragQuestionBetweenPages: boolean = false;
Expand Down Expand Up @@ -154,6 +158,8 @@ export class DragDropSurveyElements extends DragDropCore<any> {
}

protected getDropTargetByDataAttributeValue(dataAttributeValue: string, dropTargetNode: HTMLElement, event: PointerEvent): any {
const oldDragOverIndicatorElement = this.dragOverIndicatorElement;

this.dragOverIndicatorElement = null;

if (!dataAttributeValue) {
Expand Down Expand Up @@ -219,10 +225,10 @@ export class DragDropSurveyElements extends DragDropCore<any> {
let page: any = this.survey.getPageByName(dataAttributeValue);
dropTarget.__page = page;
}
if (this.dragOverIndicatorElement != dragOverElement) {
this.removeDragOverMarker(this.dragOverIndicatorElement);
this.dragOverIndicatorElement = dragOverElement;
if (this.dragOverIndicatorElement != oldDragOverIndicatorElement) {
this.removeDragOverMarker(oldDragOverIndicatorElement);
}
this.dragOverIndicatorElement = dragOverElement;
return dropTarget;
// EO drop to question or panel
}
Expand Down

0 comments on commit 71b1421

Please sign in to comment.