@synergy-design-system/components
Version:
This package provides the base of the Synergy Design System as native web components. It uses [lit](https://www.lit.dev) and parts of [shoelace](https://shoelace.style/). Synergy officially supports the latest two versions of all major browsers (as define
87 lines (84 loc) • 3.53 kB
JavaScript
import {
addGlobalEventNotification,
extractDefaultSettingsForElement,
removeGlobalEventNotification
} from "./chunk.C4JMEKUF.js";
import {
__privateAdd,
__privateGet,
__privateSet
} from "./chunk.Z4XV3SMG.js";
// src/utilities/defaultSettings/decorator.ts
function enableDefaultSettings(name) {
return (Proto) => {
var _globalSettingsSetupComplete, _initialGlobalSettingEmptyProperties, _initialProperties, _systemDefaultSettings, _a;
return _a = class extends Proto {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(...args) {
super(...args);
__privateAdd(this, _globalSettingsSetupComplete, false);
__privateAdd(this, _initialGlobalSettingEmptyProperties, /* @__PURE__ */ new Map());
__privateAdd(this, _initialProperties, []);
__privateAdd(this, _systemDefaultSettings);
this._isInitialized = false;
this._isInitialized = true;
__privateSet(this, _systemDefaultSettings, extractDefaultSettingsForElement(name, "initial"));
}
// eslint-disable-next-line class-methods-use-this
get __originalDecoratedClassName() {
return name;
}
/**
* Override the global settings for the element
* Called from the global settings event
* @param changedProperties The properties that have changed
*/
overrideGlobalSettings(changedProperties) {
changedProperties.forEach((prop) => {
if (__privateGet(this, _initialGlobalSettingEmptyProperties).has(prop.attribute)) {
this[prop.attribute] = prop.newValue;
}
});
}
disconnectedCallback() {
super.disconnectedCallback();
removeGlobalEventNotification(this);
}
// eslint-disable-next-line complexity
requestUpdate(propName, oldValue, options) {
var _a2;
super.requestUpdate(propName, oldValue, options);
if (
// element initialization is not ready
!this._isInitialized || __privateGet(this, _globalSettingsSetupComplete) || !propName || !(propName in __privateGet(this, _systemDefaultSettings)) || ((_a2 = __privateGet(this, _initialProperties)) == null ? void 0 : _a2.includes(propName))
) {
return;
}
__privateGet(this, _initialProperties).push(propName);
}
willUpdate(changedProps) {
super.willUpdate(changedProps);
if (__privateGet(this, _globalSettingsSetupComplete)) {
return;
}
__privateSet(this, _globalSettingsSetupComplete, true);
const defaults = extractDefaultSettingsForElement(name);
Object.entries(defaults).forEach(([key, value]) => {
const currentProp = this[key];
const originalDefaultSetting = __privateGet(this, _systemDefaultSettings)[key];
if (currentProp === originalDefaultSetting && !__privateGet(this, _initialProperties).includes(key)) {
__privateGet(this, _initialGlobalSettingEmptyProperties).set(key, currentProp);
this[key] = value;
}
});
if (__privateGet(this, _initialGlobalSettingEmptyProperties).size > 0) {
addGlobalEventNotification(this);
}
}
}, _globalSettingsSetupComplete = new WeakMap(), _initialGlobalSettingEmptyProperties = new WeakMap(), _initialProperties = new WeakMap(), _systemDefaultSettings = new WeakMap(), _a;
};
}
export {
enableDefaultSettings
};
//# sourceMappingURL=chunk.HYFCK7MM.js.map