UNPKG

@adaptabletools/adaptable-cjs

Version:

Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

98 lines (97 loc) 3.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ThemeApiImpl = void 0; const tslib_1 = require("tslib"); const ThemeRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/ThemeRedux")); const ModuleConstants = tslib_1.__importStar(require("../../Utilities/Constants/ModuleConstants")); const ApiBase_1 = require("./ApiBase"); const themes_1 = require("../../themes"); const ThemeInternalApi_1 = require("../Internal/ThemeInternalApi"); const AdaptableHelper_1 = tslib_1.__importDefault(require("../../Utilities/Helpers/AdaptableHelper")); const logDeprecation_1 = require("../../Utilities/logDeprecation"); class ThemeApiImpl extends ApiBase_1.ApiBase { constructor(_adaptable) { super(_adaptable); this.internalApi = new ThemeInternalApi_1.ThemeInternalApi(_adaptable); } getThemeState() { return this.getAdaptableState().Theme; } loadTheme(theme) { this.dispatchAction(ThemeRedux.ThemeSelect(theme)); } loadLightTheme() { this.loadTheme('light'); } loadDarkTheme() { this.loadTheme('dark'); } getCurrentTheme() { return this.getAdaptableState().Theme.CurrentTheme; } getCurrentThemeObject() { const currentTheme = this.getCurrentTheme(); return this.getThemes().find((themeObj) => themeObj.Name === currentTheme); } setSystemThemes(systemThemes) { this.dispatchAction(ThemeRedux.ThemeSetSystemThemes(systemThemes)); } setUserThemes(userThemes) { this.dispatchAction(ThemeRedux.ThemeSetUserThemes(userThemes)); } getSystemThemes() { const themes = this.getAdaptableState().Theme.SystemThemes ?? []; return themes.map((theme) => { if (typeof theme === 'string') { const description = themes_1.StaticThemes.find((staticTheme) => staticTheme.Name === theme)?.Description ?? theme; return { Name: theme, Description: description, }; } return theme; }); } applyCurrentTheme() { const currentTheme = this.getThemes().filter((theme) => typeof theme === 'string' ? theme === this.getCurrentTheme() : theme.Name === this.getCurrentTheme())[0]; if (!currentTheme) { return; } this._adaptable.applyAdaptableTheme(currentTheme); this.getEventApi().internalApi.fireThemeChangedEvent(currentTheme, 'ThemeSelected'); } getUserThemes() { return this.getAdaptableState().Theme.UserThemes ?? []; } getThemes() { return [...this.getSystemThemes(), ...this.getUserThemes()]; } getThemeByName(themeName) { return this.getThemes().find((theme) => theme.Name === themeName); } openThemeSettingsPanel() { this.showModulePopup(ModuleConstants.ThemeModuleId); } getAgGridCurrentThemeName() { (0, logDeprecation_1.logDeprecation)(this._adaptable.logger, 'ThemeApi', 'getAgGridCurrentThemeName', null, `This is required only for AG Grid's legacy themes. See https://www.ag-grid.com/javascript-data-grid/theming-v32/`); return this._adaptable.agGridThemeAdapter.getAgGridCurrentThemeClassNames(); } editTheme(theme) { this.dispatchAction(ThemeRedux.ThemeEdit(theme)); this.getEventApi().internalApi.fireThemeChangedEvent(theme, 'ThemeEdited'); const currentTheme = this.getCurrentTheme(); if (currentTheme === theme.Name) { this._adaptable.applyAdaptableTheme(theme); } } addUserTheme(theme) { AdaptableHelper_1.default.addAdaptableObjectPrimitives(theme); this.dispatchAction(ThemeRedux.ThemeAdd(theme)); } deleteUserTheme(theme) { this.dispatchAction(ThemeRedux.ThemeDelete(theme)); } } exports.ThemeApiImpl = ThemeApiImpl;