79 lines
3.3 KiB
JavaScript
79 lines
3.3 KiB
JavaScript
import { __assign } from "tslib";
|
|
import { GlobalSettings } from '../GlobalSettings';
|
|
var CustomizationsGlobalKey = 'customizations';
|
|
var NO_CUSTOMIZATIONS = { settings: {}, scopedSettings: {}, inCustomizerContext: false };
|
|
var _allSettings = GlobalSettings.getValue(CustomizationsGlobalKey, {
|
|
settings: {},
|
|
scopedSettings: {},
|
|
inCustomizerContext: false,
|
|
});
|
|
var _events = [];
|
|
var Customizations = /** @class */ (function () {
|
|
function Customizations() {
|
|
}
|
|
Customizations.reset = function () {
|
|
_allSettings.settings = {};
|
|
_allSettings.scopedSettings = {};
|
|
};
|
|
/** Apply global Customization settings.
|
|
* @example Customizations.applySettings(\{ theme: \{...\} \});
|
|
*/
|
|
Customizations.applySettings = function (settings) {
|
|
_allSettings.settings = __assign(__assign({}, _allSettings.settings), settings);
|
|
Customizations._raiseChange();
|
|
};
|
|
/** Apply Customizations to a particular named scope, like a component.
|
|
* @example Customizations.applyScopedSettings('Nav', \{ styles: () =\> \{\} \});
|
|
*/
|
|
Customizations.applyScopedSettings = function (scopeName, settings) {
|
|
_allSettings.scopedSettings[scopeName] = __assign(__assign({}, _allSettings.scopedSettings[scopeName]), settings);
|
|
Customizations._raiseChange();
|
|
};
|
|
Customizations.getSettings = function (properties, scopeName, localSettings) {
|
|
if (localSettings === void 0) { localSettings = NO_CUSTOMIZATIONS; }
|
|
var settings = {};
|
|
var localScopedSettings = (scopeName && localSettings.scopedSettings[scopeName]) || {};
|
|
var globalScopedSettings = (scopeName && _allSettings.scopedSettings[scopeName]) || {};
|
|
for (var _i = 0, properties_1 = properties; _i < properties_1.length; _i++) {
|
|
var property = properties_1[_i];
|
|
settings[property] =
|
|
localScopedSettings[property] ||
|
|
localSettings.settings[property] ||
|
|
globalScopedSettings[property] ||
|
|
_allSettings.settings[property];
|
|
}
|
|
return settings;
|
|
};
|
|
/** Used to run some code that sets Customizations without triggering an update until the end.
|
|
* Useful for applying Customizations that don't affect anything currently rendered, or for
|
|
* applying many customizations at once.
|
|
* @param suppressUpdate - Do not raise the change event at the end, preventing all updates
|
|
*/
|
|
Customizations.applyBatchedUpdates = function (code, suppressUpdate) {
|
|
Customizations._suppressUpdates = true;
|
|
try {
|
|
code();
|
|
}
|
|
catch (_a) {
|
|
/* do nothing */
|
|
}
|
|
Customizations._suppressUpdates = false;
|
|
if (!suppressUpdate) {
|
|
Customizations._raiseChange();
|
|
}
|
|
};
|
|
Customizations.observe = function (onChange) {
|
|
_events.push(onChange);
|
|
};
|
|
Customizations.unobserve = function (onChange) {
|
|
_events = _events.filter(function (cb) { return cb !== onChange; });
|
|
};
|
|
Customizations._raiseChange = function () {
|
|
if (!Customizations._suppressUpdates) {
|
|
_events.forEach(function (cb) { return cb(); });
|
|
}
|
|
};
|
|
return Customizations;
|
|
}());
|
|
export { Customizations };
|
|
//# sourceMappingURL=Customizations.js.map
|