Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6337 SurveyCreator: renamings - element operations and actions #6356

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 @@ -446,7 +449,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 @@ -502,7 +504,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 @@ -513,7 +520,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 @@ -564,7 +571,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 @@ -643,17 +650,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 @@ -664,16 +671,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 @@ -2747,9 +2765,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 @@ -2863,10 +2881,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 @@ -2943,9 +2962,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 @@ -3012,8 +3033,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 @@ -3068,8 +3089,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 @@ -3883,9 +3904,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 @@ -3895,6 +3918,7 @@ export class SurveyCreatorModel extends Base
allowDelete: true,
allowCopy: true,
allowDragging: true,
allowDrag: true,
allowChangeType: true,
allowChangeInputType: true,
allowChangeRequired: true,
Expand All @@ -3903,6 +3927,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
Loading