diff --git a/functionalTests/helper.ts b/functionalTests/helper.ts index 3985aea5ac..78a2f5d2d3 100644 --- a/functionalTests/helper.ts +++ b/functionalTests/helper.ts @@ -238,7 +238,7 @@ export async function resetHoverToCreator(t: TestController): Promise { export const hideAllAdornerActions = ClientFunction(() => { (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; } }); diff --git a/packages/survey-creator-core/src/components/matrix-cell.ts b/packages/survey-creator-core/src/components/matrix-cell.ts index a7bdec586e..291cc67b87 100644 --- a/packages/survey-creator-core/src/components/matrix-cell.ts +++ b/packages/survey-creator-core/src/components/matrix-cell.ts @@ -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; @@ -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(); } } diff --git a/packages/survey-creator-core/src/components/tabs/designer-plugin.ts b/packages/survey-creator-core/src/components/tabs/designer-plugin.ts index ce02590ad8..c0e5ac3d18 100644 --- a/packages/survey-creator-core/src/components/tabs/designer-plugin.ts +++ b/packages/survey-creator-core/src/components/tabs/designer-plugin.ts @@ -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(); @@ -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) => { diff --git a/packages/survey-creator-core/src/creator-base.ts b/packages/survey-creator-core/src/creator-base.ts index 2291f6e82b..65d0409edd 100644 --- a/packages/survey-creator-core/src/creator-base.ts +++ b/packages/survey-creator-core/src/creator-base.ts @@ -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"; @@ -477,7 +480,6 @@ export class SurveyCreatorModel extends Base * @see deleteElement */ public onElementDeleting: EventBase = this.addCreatorEvent(); - /** * 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. */ @@ -533,7 +535,12 @@ export class SurveyCreatorModel extends Base * @see onElementAllowOperations * @see onGetPageActions */ - public onDefineElementMenuItems: EventBase = this.addCreatorEvent(); + public onElementGetActions: EventBase = this.addCreatorEvent(); + /** + * Obsolete. Use the [`onElementGetActions`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onElementGetActions) event instead. + * @deprecated + */ + public onDefineElementMenuItems: EventBase = 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). * @@ -544,7 +551,7 @@ export class SurveyCreatorModel extends Base public onShowingProperty: EventBase = this.addCreatorEvent(); public onCanShowProperty: EventBase = 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 = this.addCreatorEvent(); @@ -595,7 +602,7 @@ export class SurveyCreatorModel extends Base */ public onMatrixColumnAdded: EventBase = this.addCreatorEvent(); /** - * 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 = this.addCreatorEvent(); @@ -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 = this.addCreatorEvent(); /** - * 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 = this.addCreatorEvent(); /** - * 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 = this.addCreatorEvent(); @@ -695,16 +702,27 @@ export class SurveyCreatorModel extends Base */ public onNotify: EventBase = this.addCreatorEvent(); /** - * 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 = this.addCreatorEvent(); + public onElementSelecting: EventBase = this.addCreatorEvent(); + /** + * Obsolete. Use the [`onElementSelecting`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onElementSelecting) event instead. + * @deprecated + */ + public onSelectedElementChanging: EventBase = 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 = this.addCreatorEvent(); + public onElementSelected: EventBase = this.addCreatorEvent(); + /** + * Obsolete. Use the [`onElementSelected`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onElementSelected) event instead. + * @deprecated + */ + public onSelectedElementChanged: EventBase = this.onElementSelected; + /** * An event that is raised when Survey Creator opens a dialog window for users to select files. * @see onUploadFile @@ -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; @@ -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; @@ -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 @@ -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; @@ -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; @@ -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 { @@ -3943,6 +3966,7 @@ export class SurveyCreatorModel extends Base allowDelete: true, allowCopy: true, allowDragging: true, + allowDrag: true, allowChangeType: true, allowChangeInputType: true, allowChangeRequired: true, @@ -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; } diff --git a/packages/survey-creator-core/src/creator-events-api.ts b/packages/survey-creator-core/src/creator-events-api.ts index 5a942bbdfa..f6fd285928 100644 --- a/packages/survey-creator-core/src/creator-events-api.ts +++ b/packages/survey-creator-core/src/creator-events-api.ts @@ -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 { @@ -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. */ @@ -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. */ @@ -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 { /** @@ -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 { diff --git a/packages/survey-creator-core/tests/question-editors.tests.ts b/packages/survey-creator-core/tests/question-editors.tests.ts index 45d03e8acc..79a528c65a 100644 --- a/packages/survey-creator-core/tests/question-editors.tests.ts +++ b/packages/survey-creator-core/tests/question-editors.tests.ts @@ -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; @@ -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;