From 69f0eb0c2502ca91381106f0c8f5dc14d8c50998 Mon Sep 17 00:00:00 2001 From: Aleksey Novikov Date: Mon, 30 Dec 2024 16:46:39 +0300 Subject: [PATCH 1/4] #6337 SurveyCreator: renamings - element operations and actions Fixes #6337 --- .../src/components/matrix-cell.ts | 4 +- .../src/components/tabs/designer-plugin.ts | 4 +- .../survey-creator-core/src/creator-base.ts | 67 +++++++++++++------ .../src/creator-events-api.ts | 51 +++++++++++--- 4 files changed, 93 insertions(+), 33 deletions(-) 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 370802e2b1..84c3447c91 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 4a42b48b1e..ffa9fcd8fa 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"; @@ -446,7 +449,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. */ @@ -502,7 +504,12 @@ export class SurveyCreatorModel extends Base * @see onElementAllowOperations * @see onGetPageActions */ - public onDefineElementMenuItems: EventBase = this.addCreatorEvent(); + public onElementGetActions: EventBase = this.addCreatorEvent(); + /** + * This event is obsolete. Use the [`onElementGetActions`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onElementGetActions) event instead. + * @deprecated + */ + public onDefineElementMenuItems: EventBase = this.addCreatorEvent(); /** * 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). * @@ -643,7 +650,7 @@ 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(); @@ -665,15 +672,26 @@ 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 + * @see onElementSelected * @see selectedElement */ - public onSelectedElementChanging: EventBase = this.addCreatorEvent(); + public onElementSelecting: EventBase = this.addCreatorEvent(); + /** + * Obsolete. Use `onElementSelecting` 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 + * @see onElementSelecting */ - public onSelectedElementChanged: EventBase = this.addCreatorEvent(); + public onElementSelected: EventBase = this.addCreatorEvent(); + /** + * Obsolete. Use `onElementSelected` 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 @@ -2677,8 +2695,8 @@ export class SurveyCreatorModel extends Base } /** * Gets or sets the focused survey element: a question, panel, page, or the survey itself. - * @see onSelectedElementChanging - * @see onSelectedElementChanged + * @see onElementSelecting + * @see onElementSelected */ public get selectedElement(): Base { return this.selectedElementValue; @@ -2792,10 +2810,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; @@ -2872,9 +2891,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 @@ -2941,8 +2962,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; @@ -2997,8 +3018,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; @@ -3812,9 +3833,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 { @@ -3824,6 +3847,7 @@ export class SurveyCreatorModel extends Base allowDelete: true, allowCopy: true, allowDragging: true, + allowDrag: true, allowChangeType: true, allowChangeInputType: true, allowChangeRequired: true, @@ -3832,6 +3856,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 d21f104b8b..31f385f252 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 `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 `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 { /** * A survey element (question, panel, or page) whose adorners you can customize. */ - obj: Base; + obj?: Base; + /** + * An array of adorner actions. You can add, modify, or remove actions from this array. + */ + items?: IAction[]; +} + +export interface ElementGetActionsEvent extends DefineElementMenuItemsEvent { + /** + * A survey element (question, panel, or page) whose adorners you can customize. + */ + element: Base; /** * An array of adorner actions. You can add, modify, or remove actions from this array. */ - items: IAction[]; + actions: IAction[]; } export interface PropertyAddingEvent { /** @@ -661,17 +684,29 @@ export interface NotifyEvent { } export interface ElementFocusingEvent { + /** + * Obsolete. Use `options.element` instead. + */ + newSelectedElement?: Base; +} +export interface ElementSelectingEvent extends ElementFocusingEvent { /** * An element that is going to be focused. */ - newSelectedElement: Base; + element: Base; } export interface ElementFocusedEvent { + /** + * Obsolete. Use `options.element` instead. + */ + newSelectedElement?: Base; +} +export interface ElementSelectedEvent extends ElementFocusedEvent { /** * The [focused element](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#selectedElement). */ - newSelectedElement: Base; + element: Base; } export interface OpenFileChooserEvent { From 9a0ac93a0da8ac918470c31505af794a229248a5 Mon Sep 17 00:00:00 2001 From: RomanTsukanov Date: Tue, 7 Jan 2025 18:06:25 +0400 Subject: [PATCH 2/4] Update deprecation messages --- .../survey-creator-core/src/creator-base.ts | 22 +++++++++---------- .../src/creator-events-api.ts | 12 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/survey-creator-core/src/creator-base.ts b/packages/survey-creator-core/src/creator-base.ts index 5221a03217..c2426ced72 100644 --- a/packages/survey-creator-core/src/creator-base.ts +++ b/packages/survey-creator-core/src/creator-base.ts @@ -506,10 +506,10 @@ export class SurveyCreatorModel extends Base */ public onElementGetActions: EventBase = this.addCreatorEvent(); /** - * This event is obsolete. Use the [`onElementGetActions`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onElementGetActions) event instead. + * Obsolete. Use the [`onElementGetActions`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onElementGetActions) event instead. * @deprecated */ - public onDefineElementMenuItems: EventBase = this.addCreatorEvent(); + 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). * @@ -520,7 +520,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(); @@ -571,7 +571,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(); @@ -655,12 +655,12 @@ export class SurveyCreatorModel extends Base 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(); @@ -671,23 +671,23 @@ 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. + * 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 onElementSelecting: EventBase = this.addCreatorEvent(); /** - * Obsolete. Use `onElementSelecting` instead. + * 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. + * An event that is raised after a survey element (a question, panel, page, or the survey itself) is selected. * @see onElementSelecting */ public onElementSelected: EventBase = this.addCreatorEvent(); /** - * Obsolete. Use `onElementSelected` instead. + * Obsolete. Use the [`onElementSelected`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onElementSelected) event instead. * @deprecated */ public onSelectedElementChanged: EventBase = this.onElementSelected; @@ -2761,7 +2761,7 @@ export class SurveyCreatorModel extends Base return newElement; } /** - * Gets or sets the focused survey element: a question, panel, page, or the survey itself. + * Gets or sets the selected survey element: a question, panel, page, or the survey itself. * @see onElementSelecting * @see onElementSelected */ diff --git a/packages/survey-creator-core/src/creator-events-api.ts b/packages/survey-creator-core/src/creator-events-api.ts index 31f385f252..c85994e570 100644 --- a/packages/survey-creator-core/src/creator-events-api.ts +++ b/packages/survey-creator-core/src/creator-events-api.ts @@ -113,7 +113,7 @@ export interface ElementAllowOperationsEvent { */ element: Base; /** - * Obsolete. Use `element` instead. + * Obsolete. Use `options.element` instead. */ obj?: Base; /** @@ -141,7 +141,7 @@ export interface ElementAllowOperationsEvent { */ allowDrag: boolean; /** - * Obsolete. Use `allowDrag` instead. + * Obsolete. Use `options.allowDrag` instead. */ allowDragging?: boolean; /** @@ -160,11 +160,11 @@ export interface ElementAllowOperationsEvent { export interface DefineElementMenuItemsEvent { /** - * A survey element (question, panel, or page) whose adorners you can customize. + * Obsolete. Use `options.element` instead. */ obj?: Base; /** - * An array of adorner actions. You can add, modify, or remove actions from this array. + * Obsolete. Use `options.actions` instead. */ items?: IAction[]; } @@ -691,7 +691,7 @@ export interface ElementFocusingEvent { } export interface ElementSelectingEvent extends ElementFocusingEvent { /** - * An element that is going to be focused. + * An element that is going to be selected. */ element: Base; } @@ -704,7 +704,7 @@ export interface ElementFocusedEvent { } export interface ElementSelectedEvent extends ElementFocusedEvent { /** - * The [focused element](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#selectedElement). + * The [selected element](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#selectedElement). */ element: Base; } From 5fe3fb6def90ed22915dd0998495665d9644b947 Mon Sep 17 00:00:00 2001 From: Aleksey Novikov Date: Fri, 10 Jan 2025 12:58:16 +0300 Subject: [PATCH 3/4] #6337 - fixed tests --- packages/survey-creator-core/tests/question-editors.tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; From a0a450ece72d7c4730e29d61374a743cbd909a41 Mon Sep 17 00:00:00 2001 From: Aleksey Novikov Date: Fri, 10 Jan 2025 18:16:57 +0300 Subject: [PATCH 4/4] #6337 - fixed tests --- functionalTests/helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } });