82 lines
3.8 KiB
JavaScript
82 lines
3.8 KiB
JavaScript
|
define(["require", "exports", "tslib", "../GlobalSettings"], function (require, exports, tslib_1, GlobalSettings_1) {
|
||
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.Customizations = void 0;
|
||
|
var CustomizationsGlobalKey = 'customizations';
|
||
|
var NO_CUSTOMIZATIONS = { settings: {}, scopedSettings: {}, inCustomizerContext: false };
|
||
|
var _allSettings = GlobalSettings_1.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 = tslib_1.__assign(tslib_1.__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] = tslib_1.__assign(tslib_1.__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;
|
||
|
}());
|
||
|
exports.Customizations = Customizations;
|
||
|
});
|
||
|
//# sourceMappingURL=Customizations.js.map
|