From 782cca694d02908a6221ae72b94c16222d926d79 Mon Sep 17 00:00:00 2001 From: tsv2013 Date: Wed, 12 Feb 2025 18:04:29 +0300 Subject: [PATCH] Work for https://github.com/surveyjs/private-tasks/issues/453 - urveyjs.io - Wrong icon version - Refactored API --- .../src/components/tabs/designer-plugin.ts | 2 +- .../src/components/tabs/json-editor-ace.ts | 2 +- .../components/tabs/json-editor-textarea.ts | 2 +- .../src/components/tabs/logic-plugin.ts | 2 +- .../src/components/tabs/test-plugin.ts | 2 +- .../src/components/tabs/theme-plugin.ts | 2 +- .../src/components/tabs/translation-plugin.ts | 2 +- .../survey-creator-core/src/creator-base.ts | 28 ++++++++++++++++--- 8 files changed, 31 insertions(+), 11 deletions(-) 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 15a28e9124..3a48d5d6b1 100644 --- a/packages/survey-creator-core/src/components/tabs/designer-plugin.ts +++ b/packages/survey-creator-core/src/components/tabs/designer-plugin.ts @@ -201,7 +201,7 @@ export class TabDesignerPlugin implements ICreatorPlugin { } constructor(private creator: SurveyCreatorModel) { - creator.addPluginTab("designer", this, undefined, "icon-config"); + creator.addPluginTab({ name: "designer", plugin: this, iconName: "icon-config" }); this.tabControlModel = new TabControlModel(this.creator.sidebar); this.propertyGrid = new PropertyGridModel(undefined, creator, creator.getPropertyGridDefinition()); this.showOneCategoryInPropertyGrid = creator.showOneCategoryInPropertyGrid; diff --git a/packages/survey-creator-core/src/components/tabs/json-editor-ace.ts b/packages/survey-creator-core/src/components/tabs/json-editor-ace.ts index 1008c261e5..8bece208ad 100644 --- a/packages/survey-creator-core/src/components/tabs/json-editor-ace.ts +++ b/packages/survey-creator-core/src/components/tabs/json-editor-ace.ts @@ -113,7 +113,7 @@ export class TabJsonEditorAcePlugin implements ICreatorPlugin { constructor(creator: SurveyCreatorModel) { super(creator); - creator.addPluginTab("json", this, undefined, "icon-codeeditor-24x24", "svc-tab-json-editor-ace"); + creator.addPluginTab({ name: "json", plugin: this, iconName: "icon-codeeditor-24x24", componentName: "svc-tab-json-editor-ace" }); } protected createModel( creator: SurveyCreatorModel diff --git a/packages/survey-creator-core/src/components/tabs/json-editor-textarea.ts b/packages/survey-creator-core/src/components/tabs/json-editor-textarea.ts index 8606bd6dee..3c2bac59e0 100644 --- a/packages/survey-creator-core/src/components/tabs/json-editor-textarea.ts +++ b/packages/survey-creator-core/src/components/tabs/json-editor-textarea.ts @@ -89,7 +89,7 @@ export class TabJsonEditorTextareaPlugin implements ICreatorPlugin { constructor(creator: SurveyCreatorModel) { super(creator); - creator.addPluginTab("json", this, undefined, "icon-codeeditor-24x24", "svc-tab-json-editor-textarea"); + creator.addPluginTab({ name: "json", plugin: this, iconName: "icon-codeeditor-24x24", componentName: "svc-tab-json-editor-textarea" }); } protected createModel( creator: SurveyCreatorModel diff --git a/packages/survey-creator-core/src/components/tabs/logic-plugin.ts b/packages/survey-creator-core/src/components/tabs/logic-plugin.ts index b2f941eea2..021a27d60a 100644 --- a/packages/survey-creator-core/src/components/tabs/logic-plugin.ts +++ b/packages/survey-creator-core/src/components/tabs/logic-plugin.ts @@ -13,7 +13,7 @@ export class TabLogicPlugin implements ICreatorPlugin { private fastEntryAction: Action; public model: SurveyLogicUI; constructor(private creator: SurveyCreatorModel) { - creator.addPluginTab("logic", this, undefined, "icon-logic-24x24"); + creator.addPluginTab({ name: "logic", plugin: this, iconName: "icon-logic-24x24" }); this.createActions().forEach(action => creator.toolbar.actions.push(action)); } public activate(): void { diff --git a/packages/survey-creator-core/src/components/tabs/test-plugin.ts b/packages/survey-creator-core/src/components/tabs/test-plugin.ts index 28eba4cd69..c568f05eb6 100644 --- a/packages/survey-creator-core/src/components/tabs/test-plugin.ts +++ b/packages/survey-creator-core/src/components/tabs/test-plugin.ts @@ -89,7 +89,7 @@ export class TabTestPlugin implements ICreatorPlugin { } constructor(private creator: SurveyCreatorModel) { - creator.addPluginTab("preview", this, undefined, "icon-preview"); + creator.addPluginTab({ name: "preview", plugin: this, iconName: "icon-preview" }); this.setPreviewTheme(this.creator.previewTheme); this.createActions().forEach(action => creator.toolbar.actions.push(action)); } diff --git a/packages/survey-creator-core/src/components/tabs/theme-plugin.ts b/packages/survey-creator-core/src/components/tabs/theme-plugin.ts index 53cc9c496c..e9da2cbea3 100644 --- a/packages/survey-creator-core/src/components/tabs/theme-plugin.ts +++ b/packages/survey-creator-core/src/components/tabs/theme-plugin.ts @@ -244,7 +244,7 @@ export class ThemeTabPlugin implements ICreatorPlugin { } constructor(private creator: SurveyCreatorModel) { - creator.addPluginTab("theme", this, undefined, "icon-theme"); + creator.addPluginTab({ name: "theme", plugin: this, iconName: "icon-theme" }); this.simulatorCssClasses = surveyCss[defaultThemeName]; this.tabControlModel = new TabControlModel(this.creator.sidebar); this.createActions().forEach(action => creator.toolbar.actions.push(action)); diff --git a/packages/survey-creator-core/src/components/tabs/translation-plugin.ts b/packages/survey-creator-core/src/components/tabs/translation-plugin.ts index c3727f109a..44c87eb0cf 100644 --- a/packages/survey-creator-core/src/components/tabs/translation-plugin.ts +++ b/packages/survey-creator-core/src/components/tabs/translation-plugin.ts @@ -40,7 +40,7 @@ export class TabTranslationPlugin implements ICreatorPlugin { } constructor(private creator: SurveyCreatorModel) { - creator.addPluginTab("translation", this, undefined, "icon-language"); + creator.addPluginTab({ name: "translation", plugin: this, iconName: "icon-language" }); this.showOneCategoryInPropertyGrid = creator.showOneCategoryInPropertyGrid; this.tabControlModel = new TabControlModel(this.creator.sidebar); this.sidebarTab = this.creator.sidebar.addPage("translation"); diff --git a/packages/survey-creator-core/src/creator-base.ts b/packages/survey-creator-core/src/creator-base.ts index 4503a741aa..d491955761 100644 --- a/packages/survey-creator-core/src/creator-base.ts +++ b/packages/survey-creator-core/src/creator-base.ts @@ -467,18 +467,38 @@ export class SurveyCreatorModel extends Base * @param name A unique tab ID. * @param plugin An object that allows you to handle user interactions with the tab. * @param title A tab caption. If `title` is undefined, the `name` argument value is displayed instead. To localize the caption, add its translations to the `ed` object within [localization dictionaries](https://github.com/surveyjs/survey-creator/tree/90de47d2c9da49b06a7f97414026d70f7acf05c6/packages/survey-creator-core/src/localization) and pass `ed.propertyName` as the `title` argument. - * @param iconName A tab icon. If `iconName` is undefined, the default icon is displayed. * @param componentName The name of the component that renders tab markup. Default value: `"svc-tab-" + name`. * @param index A zero-based index that specifies the tab's position relative to other tabs. */ public addPluginTab( - name: string, - plugin: ICreatorPlugin, + nameOrParams: string | { + name: string, + plugin: ICreatorPlugin, + title?: string, + iconName?: string, + componentName?: string, + index?: number + }, + plugin?: ICreatorPlugin, title?: string, - iconName?: string, componentName?: string, index?: number ) { + let name = nameOrParams as string; + let iconName: string = undefined; + if (typeof nameOrParams === "object") { + ({ + name, + plugin, + title, + iconName, + componentName, + index + } = nameOrParams); + } + if (!name || !plugin) { + throw new Error("Plugin or name is not set"); + } this.tabbedMenu.addTab(name, plugin, title, iconName, componentName, index); this.addPlugin(name, plugin); }