@descope/sdk-mixins
Version:
Descope JavaScript SDK mixins
49 lines (46 loc) • 2.46 kB
JavaScript
import { __classPrivateFieldGet } from 'tslib';
import { createSingletonMixin, compose, createTemplate } from '@descope/sdk-helpers';
import { initLifecycleMixin } from '../initLifecycleMixin.js';
import { initElementMixin } from '../initElementMixin.js';
import { descopeUiMixin } from '../descopeUiMixin/descopeUiMixin.js';
import { createNotificationEle } from './helpers.js';
import { NOTIFICATION_ELE_TAG } from './constants.js';
import { NotificationDriver } from '@descope/sdk-component-drivers';
const notificationsMixin = createSingletonMixin((superclass) => {
var _NotificationsMixinClass_NotificationDriverWrapper, _a;
const BaseClass = compose(initLifecycleMixin, initElementMixin, descopeUiMixin)(superclass);
return _a = class NotificationsMixinClass extends BaseClass {
constructor() {
super(...arguments);
_NotificationsMixinClass_NotificationDriverWrapper.set(this, (() => {
const loadDescopeUiComponents = this.loadDescopeUiComponents.bind(this);
return class NotificationDriverWrapper extends NotificationDriver {
setContent(templateOrString) {
const template = typeof templateOrString === 'string'
? createTemplate(templateOrString)
: templateOrString;
loadDescopeUiComponents(template);
super.setContent(template);
}
};
})());
}
createNotification(config) {
const baseConfig = {};
const notification = createNotificationEle(Object.assign(Object.assign({}, baseConfig), config));
this.rootElement.append(notification);
return new (__classPrivateFieldGet(this, _NotificationsMixinClass_NotificationDriverWrapper, "f"))(notification, {
logger: this.logger,
});
}
async init() {
var _b;
await ((_b = super.init) === null || _b === void 0 ? void 0 : _b.call(this));
this.loadDescopeUiComponents([NOTIFICATION_ELE_TAG]);
}
},
_NotificationsMixinClass_NotificationDriverWrapper = new WeakMap(),
_a;
});
export { notificationsMixin };
//# sourceMappingURL=notificationsMixin.js.map