Skip to content

Commit

Permalink
#6337 SurveyCreator: renamings - element operations and actions (#6356)
Browse files Browse the repository at this point in the history
* #6337 SurveyCreator: renamings - element operations and actions
Fixes #6337

* Update deprecation messages

* #6337 - fixed tests

* #6337 - fixed tests

---------

Co-authored-by: RomanTsukanov <[email protected]>
  • Loading branch information
novikov82 and RomanTsukanov authored Jan 12, 2025
1 parent 9128868 commit 8ea1af8
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 45 deletions.
2 changes: 1 addition & 1 deletion functionalTests/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export async function resetHoverToCreator(t: TestController): Promise<void> {
export const hideAllAdornerActions = ClientFunction(() => {
(<any>window).creator.onElementAllowOperations.add((_, options) => {
Object.keys(options).forEach(key => {
if (key !== "allowDragging" && key !== "allowEdit") {
if (key !== "allowDragging" && key !== "allowDrag" && key !== "allowEdit") {
options[key] = false;
}
});
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-creator-core/src/components/matrix-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class MatrixCellWrapperViewModel extends Base {
// if(!question && !!this.templateData.data) {
// this.question = this.templateData.data;
// }
creator.onSelectedElementChanged.add(this.onSelectionChanged);
creator.onElementSelected.add(this.onSelectionChanged);
}
@property() isSelected: boolean;

Expand Down Expand Up @@ -146,7 +146,7 @@ export class MatrixCellWrapperViewModel extends Base {
}
}
public dispose(): void {
this.creator.onSelectedElementChanged.remove(this.onSelectionChanged);
this.creator.onElementSelected.remove(this.onSelectionChanged);
super.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class TabDesignerPlugin implements ICreatorPlugin {
return result;
});

creator.onSelectedElementChanged.add((sender, options) => {
creator.onElementSelected.add((sender, options) => {
if (this.showOneCategoryInPropertyGrid && this.creator.activeTab === "designer") {
this.setPropertyGridIsActivePage();
this.updateTabControlActions();
Expand Down Expand Up @@ -407,7 +407,7 @@ export class TabDesignerPlugin implements ICreatorPlugin {
items.push(this.saveSurveyAction);
items.push(toolboxAction);
items.push(this.surveySettingsAction);
this.creator.onSelectedElementChanged.add((sender, options) => {
this.creator.onElementSelected.add((sender, options) => {
this.surveySettingsAction.active = this.isSettingsActive;
});
this.creator.onShowSidebarVisibilityChanged.add((sender, options) => {
Expand Down
81 changes: 53 additions & 28 deletions packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ import {
CreateCustomMessagePanelEvent, ActiveTabChangingEvent, ActiveTabChangedEvent, BeforeUndoEvent, BeforeRedoEvent,
PageAddingEvent, DragStartEndEvent,
ElementGetExpandCollapseStateEvent,
ElementGetExpandCollapseStateEventReason
ElementGetExpandCollapseStateEventReason,
ElementSelectingEvent,
ElementSelectedEvent,
DefineElementMenuItemsEvent
} from "./creator-events-api";
import { ExpandCollapseManager } from "./expand-collapse-manager";
import designTabSurveyThemeJSON from "./designTabSurveyThemeJSON";
Expand Down Expand Up @@ -477,7 +480,6 @@ export class SurveyCreatorModel extends Base
* @see deleteElement
*/
public onElementDeleting: EventBase<SurveyCreatorModel, ElementDeletingEvent> = this.addCreatorEvent<SurveyCreatorModel, ElementDeletingEvent>();

/**
* An event that is raised when Survey Creator sets the read-only status for a survey element property. Use this event to change the read-only status for individual properties.
*/
Expand Down Expand Up @@ -533,7 +535,12 @@ export class SurveyCreatorModel extends Base
* @see onElementAllowOperations
* @see onGetPageActions
*/
public onDefineElementMenuItems: EventBase<SurveyCreatorModel, ElementGetActionsEvent> = this.addCreatorEvent<SurveyCreatorModel, ElementGetActionsEvent>();
public onElementGetActions: EventBase<SurveyCreatorModel, ElementGetActionsEvent> = this.addCreatorEvent<SurveyCreatorModel, ElementGetActionsEvent>();
/**
* Obsolete. Use the [`onElementGetActions`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onElementGetActions) event instead.
* @deprecated
*/
public onDefineElementMenuItems: EventBase<SurveyCreatorModel, DefineElementMenuItemsEvent> = this.onElementGetActions;
/**
* An event that is raised when Survey Creator adds properties to a survey element selected on the design surface. Handle this event if you cancel the addition of certain properties and thus [hide them from the Property Grid](https://surveyjs.io/survey-creator/documentation/property-grid-customization#hide-properties-from-the-property-grid).
*
Expand All @@ -544,7 +551,7 @@ export class SurveyCreatorModel extends Base
public onShowingProperty: EventBase<SurveyCreatorModel, PropertyAddingEvent> = this.addCreatorEvent<SurveyCreatorModel, PropertyAddingEvent>();
public onCanShowProperty: EventBase<SurveyCreatorModel, any> = this.onShowingProperty;
/**
* This event is obsolete. Use the [`onSurveyInstanceCreated`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onSurveyInstanceCreated) event instead.
* Obsolete. Use the [`onSurveyInstanceCreated`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onSurveyInstanceCreated) event instead.
* @deprecated
*/
public onPropertyGridSurveyCreated: EventBase<SurveyCreatorModel, PropertyGridSurveyCreatedEvent> = this.addCreatorEvent<SurveyCreatorModel, PropertyGridSurveyCreatedEvent>();
Expand Down Expand Up @@ -595,7 +602,7 @@ export class SurveyCreatorModel extends Base
*/
public onMatrixColumnAdded: EventBase<SurveyCreatorModel, MatrixColumnAddedEvent> = this.addCreatorEvent<SurveyCreatorModel, MatrixColumnAddedEvent>();
/**
* This event is obsolete. Use the [`onConfigureTablePropertyEditor`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onConfigureTablePropertyEditor) event instead.
* Obsolete. Use the [`onConfigureTablePropertyEditor`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onConfigureTablePropertyEditor) event instead.
* @deprecated
*/
public onSetPropertyEditorOptions: EventBase<SurveyCreatorModel, ConfigureTablePropertyEditorEvent> = this.addCreatorEvent<SurveyCreatorModel, ConfigureTablePropertyEditorEvent>();
Expand Down Expand Up @@ -674,17 +681,17 @@ export class SurveyCreatorModel extends Base

/**
* An event that is raised when Survey Creator renders action buttons under each page on the design surface. Use this event to add, remove, or modify the buttons.
* @see onDefineElementMenuItems
* @see onElementGetActions
*/
public onGetPageActions: EventBase<SurveyCreatorModel, PageGetFooterActionsEvent> = this.addCreatorEvent<SurveyCreatorModel, PageGetFooterActionsEvent>();

/**
* This event is obsolete. Use the [`onSurveyInstanceCreated`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onSurveyInstanceCreated) event instead.
* Obsolete. Use the [`onSurveyInstanceCreated`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onSurveyInstanceCreated) event instead.
* @deprecated
*/
public onDesignerSurveyCreated: EventBase<SurveyCreatorModel, DesignerSurveyCreatedEvent> = this.addCreatorEvent<SurveyCreatorModel, DesignerSurveyCreatedEvent>();
/**
* This event is obsolete. Use the [`onSurveyInstanceCreated`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onSurveyInstanceCreated) event instead.
* Obsolete. Use the [`onSurveyInstanceCreated`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onSurveyInstanceCreated) event instead.
* @deprecated
*/
public onPreviewSurveyCreated: EventBase<SurveyCreatorModel, PreviewSurveyCreatedEvent> = this.addCreatorEvent<SurveyCreatorModel, PreviewSurveyCreatedEvent>();
Expand All @@ -695,16 +702,27 @@ export class SurveyCreatorModel extends Base
*/
public onNotify: EventBase<SurveyCreatorModel, NotifyEvent> = this.addCreatorEvent<SurveyCreatorModel, NotifyEvent>();
/**
* An event that is raised before a survey element (question, panel, page, or the survey itself) is focused. Use this event to move focus to a different survey element.
* @see onSelectedElementChanged
* An event that is raised before a survey element (question, panel, page, or the survey itself) is selected. Use this event if you want to select a different survey element.
* @see onElementSelected
* @see selectedElement
*/
public onSelectedElementChanging: EventBase<SurveyCreatorModel, ElementFocusingEvent> = this.addCreatorEvent<SurveyCreatorModel, ElementFocusingEvent>();
public onElementSelecting: EventBase<SurveyCreatorModel, ElementSelectingEvent> = this.addCreatorEvent<SurveyCreatorModel, ElementSelectingEvent>();
/**
* Obsolete. Use the [`onElementSelecting`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onElementSelecting) event instead.
* @deprecated
*/
public onSelectedElementChanging: EventBase<SurveyCreatorModel, ElementFocusingEvent> = this.onElementSelecting;
/**
* An event that is raised after a survey element (a question, panel, page, or the survey itself) is focused.
* @see onSelectedElementChanging
* An event that is raised after a survey element (a question, panel, page, or the survey itself) is selected.
* @see onElementSelecting
*/
public onSelectedElementChanged: EventBase<SurveyCreatorModel, ElementFocusedEvent> = this.addCreatorEvent<SurveyCreatorModel, ElementFocusedEvent>();
public onElementSelected: EventBase<SurveyCreatorModel, ElementSelectedEvent> = this.addCreatorEvent<SurveyCreatorModel, ElementSelectedEvent>();
/**
* Obsolete. Use the [`onElementSelected`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onElementSelected) event instead.
* @deprecated
*/
public onSelectedElementChanged: EventBase<SurveyCreatorModel, ElementFocusedEvent> = this.onElementSelected;

/**
* An event that is raised when Survey Creator opens a dialog window for users to select files.
* @see onUploadFile
Expand Down Expand Up @@ -2795,9 +2813,9 @@ export class SurveyCreatorModel extends Base
return newElement;
}
/**
* Gets or sets the focused survey element: a question, panel, page, or the survey itself.
* @see onSelectedElementChanging
* @see onSelectedElementChanged
* Gets or sets the selected survey element: a question, panel, page, or the survey itself.
* @see onElementSelecting
* @see onElementSelected
*/
public get selectedElement(): Base {
return this.selectedElementValue;
Expand Down Expand Up @@ -2911,10 +2929,11 @@ export class SurveyCreatorModel extends Base
const options = {
element: obj,
elementType: SurveyHelper.getObjectType(obj),
allowing: true
allowing: true,
allow: true
};
this.onElementDeleting.fire(this, options);
return options.allowing;
return options.allowing && options.allow;
}
public isElementSelected(element: Base): boolean {
if (!element || element.isDisposed) return false;
Expand Down Expand Up @@ -2991,9 +3010,11 @@ export class SurveyCreatorModel extends Base
return sel.isInteractiveDesignElement && sel.id ? sel : null;
}
private onSelectingElement(val: Base): Base {
var options = { newSelectedElement: val };
this.onSelectedElementChanging.fire(this, options);
return options.newSelectedElement;
var options = { element: val, newSelectedElement: val };
this.onElementSelecting.fire(this, options);
if (options.element != val) return options.element;
if (options.newSelectedElement != val) return options.newSelectedElement;
return val;
}

//#region Obsolete designerPropertyGrid
Expand Down Expand Up @@ -3060,8 +3081,8 @@ export class SurveyCreatorModel extends Base
/**
* Validates the property values of the [focused element](#selectedElement).
* @returns `true` if all property values of the focused element are valid or if no element is focused, `false` otherwise.
* @see onSelectedElementChanging
* @see onSelectedElementChanged
* @see onElementSelecting
* @see onElementSelected
*/
public validateSelectedElement(): boolean {
var isValid = true;
Expand Down Expand Up @@ -3116,8 +3137,8 @@ export class SurveyCreatorModel extends Base
this.expandCategoryIfNeeded();
this.selectFromStringEditor = false;
}
var options = { newSelectedElement: element };
this.onSelectedElementChanged.fire(this, options);
var options = { newSelectedElement: element, element: element };
this.onElementSelected.fire(this, options);
}
private getCurrentPageByElement(element: Base): PageModel {
if (!element) return undefined;
Expand Down Expand Up @@ -3931,9 +3952,11 @@ export class SurveyCreatorModel extends Base
}

public onElementMenuItemsChanged(element: any, items: Action[]) {
this.onDefineElementMenuItems.fire(this, {
this.onElementGetActions.fire(this, {
obj: element,
items: items
element: element,
items: items,
actions: items
});
}
public getElementAllowOperations(element: SurveyElement): any {
Expand All @@ -3943,6 +3966,7 @@ export class SurveyCreatorModel extends Base
allowDelete: true,
allowCopy: true,
allowDragging: true,
allowDrag: true,
allowChangeType: true,
allowChangeInputType: true,
allowChangeRequired: true,
Expand All @@ -3951,6 +3975,7 @@ export class SurveyCreatorModel extends Base
allowExpandCollapse: undefined
};
this.onElementAllowOperations.fire(this, options);
options.allowDrag = options.allowDragging = options.allowDrag && options.allowDragging;
return options;
}

Expand Down
55 changes: 45 additions & 10 deletions packages/survey-creator-core/src/creator-events-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ export interface ElementDeletingEvent {
* The element type: `"question"`, `"panel"`, or `"page"`.
*/
elementType: string;
/**
* Obsolete. Use `options.allow` instead.
*/
allowing?: boolean;
/**
* A Boolean property that you can set to `false` if you want to cancel element deletion.
*/
allowing: boolean;
allow: boolean;
}

export interface PropertyGetReadOnlyEvent {
Expand Down Expand Up @@ -107,7 +111,11 @@ export interface ElementAllowOperationsEvent {
/**
* A survey element (question or panel) for which you can disable user interactions.
*/
obj: Base;
element: Base;
/**
* Obsolete. Use `options.element` instead.
*/
obj?: Base;
/**
* Allows users to mark the survey element as required.
*/
Expand All @@ -131,7 +139,11 @@ export interface ElementAllowOperationsEvent {
/**
* Allows users to drag and drop the survey element.
*/
allowDragging: boolean;
allowDrag: boolean;
/**
* Obsolete. Use `options.allowDrag` instead.
*/
allowDragging?: boolean;
/**
* Allows users to edit survey element properties on the design surface. If you disable this property, users can edit the properties only in the Property Grid.
*/
Expand All @@ -146,15 +158,26 @@ export interface ElementAllowOperationsEvent {
allowShowSettings: boolean | undefined;
}

export interface ElementGetActionsEvent {
export interface DefineElementMenuItemsEvent {
/**
* Obsolete. Use `options.element` instead.
*/
obj?: Base;
/**
* Obsolete. Use `options.actions` instead.
*/
items?: IAction[];
}

export interface ElementGetActionsEvent extends DefineElementMenuItemsEvent {
/**
* A survey element (question, panel, or page) whose adorners you can customize.
*/
obj: Base;
element: Base;
/**
* An array of adorner actions. You can add, modify, or remove actions from this array.
*/
items: IAction[];
actions: IAction[];
}
export interface PropertyAddingEvent {
/**
Expand Down Expand Up @@ -662,16 +685,28 @@ export interface NotifyEvent {

export interface ElementFocusingEvent {
/**
* An element that is going to be focused.
* Obsolete. Use `options.element` instead.
*/
newSelectedElement?: Base;
}
export interface ElementSelectingEvent extends ElementFocusingEvent {
/**
* An element that is going to be selected.
*/
newSelectedElement: Base;
element: Base;
}

export interface ElementFocusedEvent {
/**
* The [focused element](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#selectedElement).
* Obsolete. Use `options.element` instead.
*/
newSelectedElement?: Base;
}
export interface ElementSelectedEvent extends ElementFocusedEvent {
/**
* The [selected element](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#selectedElement).
*/
newSelectedElement: Base;
element: Base;
}

export interface OpenFileChooserEvent {
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-creator-core/tests/question-editors.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test("MatrixCellWrapperViewModel select context", () => {
selectedElement: undefined,
selectedProperty: undefined,
selectElement: undefined,
onSelectedElementChanged: new Event()
onElementSelected: new Event()
};
creator.selectElement = (element: any, property?: string, focus?: boolean) => {
creator.selectedElement = element;
Expand Down Expand Up @@ -91,7 +91,7 @@ test("MatrixCellWrapperViewModel.isSupportCellEditor", () => {
selectedElement: undefined,
selectedProperty: undefined,
selectElement: undefined,
onSelectedElementChanged: new Event()
onElementSelected: new Event()
};
creator.selectElement = (element: any, property?: string, focus?: boolean) => {
creator.selectedElement = element;
Expand Down

0 comments on commit 8ea1af8

Please sign in to comment.