@merkur/integration-custom-element 0.36.4 → 0.37.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/index.mjs CHANGED
@@ -108,11 +108,11 @@ export default function ({ emitter, EMITTER_EVENTS }) {
108
108
  );
109
109
 
110
110
  emitter.on(EMITTER_EVENTS.CLI_CONFIG, function removeNodeTask({ cliConfig }) {
111
- if (cliConfig.runTask.length === 0) {
112
- cliConfig.runTask = ['es13', 'es9'];
111
+ if (cliConfig.runTasks.length === 0) {
112
+ cliConfig.runTasks = ['es13', 'es9'];
113
113
  }
114
114
 
115
- cliConfig.runTask = cliConfig.runTask.filter((task) => task !== 'node');
115
+ cliConfig.runTasks = cliConfig.runTasks.filter((task) => task !== 'node');
116
116
  return cliConfig;
117
117
  });
118
118
 
package/lib/index.cjs CHANGED
@@ -37,84 +37,104 @@ function afterDOMLoad() {
37
37
  }
38
38
 
39
39
  function registerCustomElement(options) {
40
- const { widgetDefinition, callbacks } = deepMerge({}, options);
41
- class WidgetElement extends HTMLElement {
42
- constructor() {
43
- super();
44
-
45
- const customWidgetDefinition = deepMerge({}, widgetDefinition);
40
+ const { widgetDefinition, callbacks, observedAttributes } = deepMerge(
41
+ {},
42
+ options,
43
+ );
44
+ class HTMLCustomElement extends HTMLElement {
45
+ static get observedAttributes() {
46
+ return observedAttributes ?? [];
47
+ }
48
+ constructor(...$) {
49
+ const _ = super(...$);
50
+ _._init();
51
+ return _;
52
+ }
53
+ _init() {}
54
+ }
46
55
 
47
- (async () => {
48
- this._shadow = this.attachShadow({ mode: 'open' });
56
+ class WidgetElement extends HTMLCustomElement {
57
+ _init() {
58
+ try {
59
+ super._init();
60
+ const customWidgetDefinition = deepMerge({}, widgetDefinition);
49
61
 
50
- try {
51
- const widget = await callbacks?.getInstance?.();
62
+ this._widgetPromise = (async () => {
63
+ this._shadow = this.attachShadow({ mode: 'open' });
52
64
 
53
- if (widget && widget.name && widget.version) {
54
- this._widget = widget;
65
+ try {
66
+ const widget = await callbacks?.getInstance?.();
55
67
 
56
- await afterDOMLoad();
57
- await integration.loadAssets(widget.assets, this._shadow);
68
+ if (widget && widget.name && widget.version) {
69
+ this._widget = widget;
58
70
 
59
- await callbacks?.reconstructor?.(this._widget, {
60
- shadow: this._shadow,
61
- customElement: this,
62
- });
71
+ await afterDOMLoad();
72
+ await integration.loadAssets(widget.assets, this._shadow);
63
73
 
64
- if (typeof callbacks?.remount === 'function') {
65
- await callbacks?.remount?.(this._widget, {
74
+ await callbacks?.reconstructor?.(this._widget, {
66
75
  shadow: this._shadow,
67
76
  customElement: this,
68
77
  });
69
- } else {
70
- widget.root = this._shadow;
71
- widget.customElement = this;
72
- this._shadow.appendChild(widget.container);
78
+
79
+ if (typeof callbacks?.remount === 'function') {
80
+ await callbacks?.remount?.(this._widget, {
81
+ shadow: this._shadow,
82
+ customElement: this,
83
+ });
84
+ } else {
85
+ widget.root = this._shadow;
86
+ widget.customElement = this;
87
+ this._shadow.appendChild(widget.container);
88
+ }
89
+
90
+ return;
73
91
  }
92
+ } catch (error) {
93
+ console.error(error);
74
94
 
75
95
  return;
76
96
  }
77
- } catch (error) {
78
- console.error(error);
79
97
 
80
- return;
81
- }
98
+ try {
99
+ customWidgetDefinition.root = this._shadow;
100
+ customWidgetDefinition.customElement = this;
101
+
102
+ if (!customWidgetDefinition.container) {
103
+ customWidgetDefinition.container = document.createElement('div');
104
+ customWidgetDefinition.container.setAttribute(
105
+ 'id',
106
+ 'merkur-container',
107
+ );
108
+ }
82
109
 
83
- try {
84
- customWidgetDefinition.root = this._shadow;
85
- customWidgetDefinition.customElement = this;
110
+ this._shadow.appendChild(customWidgetDefinition.container);
86
111
 
87
- if (!customWidgetDefinition.container) {
88
- customWidgetDefinition.container = document.createElement('div');
89
- customWidgetDefinition.container.setAttribute(
90
- 'id',
91
- 'merkur-container',
112
+ this._widget = await createSPAWidget(
113
+ customWidgetDefinition,
114
+ this._shadow,
92
115
  );
93
- }
94
116
 
95
- this._shadow.appendChild(customWidgetDefinition.container);
96
-
97
- this._widget = await createSPAWidget(
98
- customWidgetDefinition,
99
- this._shadow,
100
- );
101
-
102
- await callbacks?.constructor?.(this._widget, {
103
- shadow: this._shadow,
104
- customElement: this,
105
- });
106
-
107
- (await callbacks?.mount?.(this._widget, {
108
- shadow: this._shadow,
109
- customElement: this,
110
- })) ?? (await this._widget.mount());
111
- } catch (error) {
112
- console.error(error);
113
- }
114
- })();
117
+ await callbacks?.constructor?.(this._widget, {
118
+ shadow: this._shadow,
119
+ customElement: this,
120
+ });
121
+
122
+ (await callbacks?.mount?.(this._widget, {
123
+ shadow: this._shadow,
124
+ customElement: this,
125
+ })) ?? (await this._widget.mount());
126
+ } catch (error) {
127
+ console.error(error);
128
+ }
129
+ })();
130
+ } catch (error) {
131
+ console.error(error);
132
+ }
115
133
  }
116
134
 
117
- connectedCallback() {
135
+ async connectedCallback() {
136
+ await this._widgetPromise;
137
+
118
138
  this._widget?.connectedCallback?.({
119
139
  shadow: this._shadow,
120
140
  customElement: this,
@@ -126,7 +146,9 @@ function registerCustomElement(options) {
126
146
  });
127
147
  }
128
148
 
129
- disconnectedCallback() {
149
+ async disconnectedCallback() {
150
+ await this._widgetPromise;
151
+
130
152
  this._widget?.disconnectedCallback?.({
131
153
  shadow: this._shadow,
132
154
  customElement: this,
@@ -138,7 +160,9 @@ function registerCustomElement(options) {
138
160
  });
139
161
  }
140
162
 
141
- adoptedCallback() {
163
+ async adoptedCallback() {
164
+ await this._widgetPromise;
165
+
142
166
  this._widget?.adoptedCallback?.({
143
167
  shadow: this._shadow,
144
168
  customElement: this,
@@ -150,7 +174,9 @@ function registerCustomElement(options) {
150
174
  });
151
175
  }
152
176
 
153
- attributeChangedCallback(name, oldValue, newValue) {
177
+ async attributeChangedCallback(name, oldValue, newValue) {
178
+ await this._widgetPromise;
179
+
154
180
  this._widget?.attributeChangedCallback?.(
155
181
  this._widget,
156
182
  name,
package/lib/index.es9.cjs CHANGED
@@ -33,70 +33,87 @@ function afterDOMLoad() {
33
33
  function registerCustomElement(options) {
34
34
  const {
35
35
  widgetDefinition,
36
- callbacks
36
+ callbacks,
37
+ observedAttributes
37
38
  } = deepMerge({}, options);
38
- class WidgetElement extends HTMLElement {
39
- constructor() {
40
- super();
41
- const customWidgetDefinition = deepMerge({}, widgetDefinition);
42
- (async () => {
43
- this._shadow = this.attachShadow({
44
- mode: 'open'
45
- });
46
- try {
47
- var _callbacks$getInstanc;
48
- const widget = await (callbacks === null || callbacks === void 0 || (_callbacks$getInstanc = callbacks.getInstance) === null || _callbacks$getInstanc === void 0 ? void 0 : _callbacks$getInstanc.call(callbacks));
49
- if (widget && widget.name && widget.version) {
50
- var _callbacks$reconstruc;
51
- this._widget = widget;
52
- await afterDOMLoad();
53
- await integration.loadAssets(widget.assets, this._shadow);
54
- await (callbacks === null || callbacks === void 0 || (_callbacks$reconstruc = callbacks.reconstructor) === null || _callbacks$reconstruc === void 0 ? void 0 : _callbacks$reconstruc.call(callbacks, this._widget, {
55
- shadow: this._shadow,
56
- customElement: this
57
- }));
58
- if (typeof (callbacks === null || callbacks === void 0 ? void 0 : callbacks.remount) === 'function') {
59
- var _callbacks$remount;
60
- await (callbacks === null || callbacks === void 0 || (_callbacks$remount = callbacks.remount) === null || _callbacks$remount === void 0 ? void 0 : _callbacks$remount.call(callbacks, this._widget, {
39
+ class HTMLCustomElement extends HTMLElement {
40
+ static get observedAttributes() {
41
+ return observedAttributes !== null && observedAttributes !== void 0 ? observedAttributes : [];
42
+ }
43
+ constructor(...$) {
44
+ const _ = super(...$);
45
+ _._init();
46
+ return _;
47
+ }
48
+ _init() {}
49
+ }
50
+ class WidgetElement extends HTMLCustomElement {
51
+ _init() {
52
+ try {
53
+ super._init();
54
+ const customWidgetDefinition = deepMerge({}, widgetDefinition);
55
+ this._widgetPromise = (async () => {
56
+ this._shadow = this.attachShadow({
57
+ mode: 'open'
58
+ });
59
+ try {
60
+ var _callbacks$getInstanc;
61
+ const widget = await (callbacks === null || callbacks === void 0 || (_callbacks$getInstanc = callbacks.getInstance) === null || _callbacks$getInstanc === void 0 ? void 0 : _callbacks$getInstanc.call(callbacks));
62
+ if (widget && widget.name && widget.version) {
63
+ var _callbacks$reconstruc;
64
+ this._widget = widget;
65
+ await afterDOMLoad();
66
+ await integration.loadAssets(widget.assets, this._shadow);
67
+ await (callbacks === null || callbacks === void 0 || (_callbacks$reconstruc = callbacks.reconstructor) === null || _callbacks$reconstruc === void 0 ? void 0 : _callbacks$reconstruc.call(callbacks, this._widget, {
61
68
  shadow: this._shadow,
62
69
  customElement: this
63
70
  }));
64
- } else {
65
- widget.root = this._shadow;
66
- widget.customElement = this;
67
- this._shadow.appendChild(widget.container);
71
+ if (typeof (callbacks === null || callbacks === void 0 ? void 0 : callbacks.remount) === 'function') {
72
+ var _callbacks$remount;
73
+ await (callbacks === null || callbacks === void 0 || (_callbacks$remount = callbacks.remount) === null || _callbacks$remount === void 0 ? void 0 : _callbacks$remount.call(callbacks, this._widget, {
74
+ shadow: this._shadow,
75
+ customElement: this
76
+ }));
77
+ } else {
78
+ widget.root = this._shadow;
79
+ widget.customElement = this;
80
+ this._shadow.appendChild(widget.container);
81
+ }
82
+ return;
68
83
  }
84
+ } catch (error) {
85
+ console.error(error);
69
86
  return;
70
87
  }
71
- } catch (error) {
72
- console.error(error);
73
- return;
74
- }
75
- try {
76
- var _callbacks$constructo, _await$callbacks$moun, _callbacks$mount;
77
- customWidgetDefinition.root = this._shadow;
78
- customWidgetDefinition.customElement = this;
79
- if (!customWidgetDefinition.container) {
80
- customWidgetDefinition.container = document.createElement('div');
81
- customWidgetDefinition.container.setAttribute('id', 'merkur-container');
88
+ try {
89
+ var _callbacks$constructo, _await$callbacks$moun, _callbacks$mount;
90
+ customWidgetDefinition.root = this._shadow;
91
+ customWidgetDefinition.customElement = this;
92
+ if (!customWidgetDefinition.container) {
93
+ customWidgetDefinition.container = document.createElement('div');
94
+ customWidgetDefinition.container.setAttribute('id', 'merkur-container');
95
+ }
96
+ this._shadow.appendChild(customWidgetDefinition.container);
97
+ this._widget = await createSPAWidget(customWidgetDefinition, this._shadow);
98
+ await (callbacks === null || callbacks === void 0 || (_callbacks$constructo = callbacks.constructor) === null || _callbacks$constructo === void 0 ? void 0 : _callbacks$constructo.call(callbacks, this._widget, {
99
+ shadow: this._shadow,
100
+ customElement: this
101
+ }));
102
+ (_await$callbacks$moun = await (callbacks === null || callbacks === void 0 || (_callbacks$mount = callbacks.mount) === null || _callbacks$mount === void 0 ? void 0 : _callbacks$mount.call(callbacks, this._widget, {
103
+ shadow: this._shadow,
104
+ customElement: this
105
+ }))) !== null && _await$callbacks$moun !== void 0 ? _await$callbacks$moun : await this._widget.mount();
106
+ } catch (error) {
107
+ console.error(error);
82
108
  }
83
- this._shadow.appendChild(customWidgetDefinition.container);
84
- this._widget = await createSPAWidget(customWidgetDefinition, this._shadow);
85
- await (callbacks === null || callbacks === void 0 || (_callbacks$constructo = callbacks.constructor) === null || _callbacks$constructo === void 0 ? void 0 : _callbacks$constructo.call(callbacks, this._widget, {
86
- shadow: this._shadow,
87
- customElement: this
88
- }));
89
- (_await$callbacks$moun = await (callbacks === null || callbacks === void 0 || (_callbacks$mount = callbacks.mount) === null || _callbacks$mount === void 0 ? void 0 : _callbacks$mount.call(callbacks, this._widget, {
90
- shadow: this._shadow,
91
- customElement: this
92
- }))) !== null && _await$callbacks$moun !== void 0 ? _await$callbacks$moun : await this._widget.mount();
93
- } catch (error) {
94
- console.error(error);
95
- }
96
- })();
109
+ })();
110
+ } catch (error) {
111
+ console.error(error);
112
+ }
97
113
  }
98
- connectedCallback() {
114
+ async connectedCallback() {
99
115
  var _this$_widget, _this$_widget$connect, _callbacks$connectedC;
116
+ await this._widgetPromise;
100
117
  (_this$_widget = this._widget) === null || _this$_widget === void 0 || (_this$_widget$connect = _this$_widget.connectedCallback) === null || _this$_widget$connect === void 0 || _this$_widget$connect.call(_this$_widget, {
101
118
  shadow: this._shadow,
102
119
  customElement: this
@@ -106,8 +123,9 @@ function registerCustomElement(options) {
106
123
  customElement: this
107
124
  });
108
125
  }
109
- disconnectedCallback() {
126
+ async disconnectedCallback() {
110
127
  var _this$_widget2, _this$_widget2$discon, _callbacks$disconnect;
128
+ await this._widgetPromise;
111
129
  (_this$_widget2 = this._widget) === null || _this$_widget2 === void 0 || (_this$_widget2$discon = _this$_widget2.disconnectedCallback) === null || _this$_widget2$discon === void 0 || _this$_widget2$discon.call(_this$_widget2, {
112
130
  shadow: this._shadow,
113
131
  customElement: this
@@ -117,8 +135,9 @@ function registerCustomElement(options) {
117
135
  customElement: this
118
136
  });
119
137
  }
120
- adoptedCallback() {
138
+ async adoptedCallback() {
121
139
  var _this$_widget3, _this$_widget3$adopte, _callbacks$adoptedCal;
140
+ await this._widgetPromise;
122
141
  (_this$_widget3 = this._widget) === null || _this$_widget3 === void 0 || (_this$_widget3$adopte = _this$_widget3.adoptedCallback) === null || _this$_widget3$adopte === void 0 || _this$_widget3$adopte.call(_this$_widget3, {
123
142
  shadow: this._shadow,
124
143
  customElement: this
@@ -128,8 +147,9 @@ function registerCustomElement(options) {
128
147
  customElement: this
129
148
  });
130
149
  }
131
- attributeChangedCallback(name, oldValue, newValue) {
150
+ async attributeChangedCallback(name, oldValue, newValue) {
132
151
  var _this$_widget4, _this$_widget4$attrib, _callbacks$attributeC;
152
+ await this._widgetPromise;
133
153
  (_this$_widget4 = this._widget) === null || _this$_widget4 === void 0 || (_this$_widget4$attrib = _this$_widget4.attributeChangedCallback) === null || _this$_widget4$attrib === void 0 || _this$_widget4$attrib.call(_this$_widget4, this._widget, name, oldValue, newValue, {
134
154
  shadow: this._shadow,
135
155
  customElement: this
package/lib/index.es9.mjs CHANGED
@@ -31,70 +31,87 @@ function afterDOMLoad() {
31
31
  function registerCustomElement(options) {
32
32
  const {
33
33
  widgetDefinition,
34
- callbacks
34
+ callbacks,
35
+ observedAttributes
35
36
  } = deepMerge({}, options);
36
- class WidgetElement extends HTMLElement {
37
- constructor() {
38
- super();
39
- const customWidgetDefinition = deepMerge({}, widgetDefinition);
40
- (async () => {
41
- this._shadow = this.attachShadow({
42
- mode: 'open'
43
- });
44
- try {
45
- var _callbacks$getInstanc;
46
- const widget = await (callbacks === null || callbacks === void 0 || (_callbacks$getInstanc = callbacks.getInstance) === null || _callbacks$getInstanc === void 0 ? void 0 : _callbacks$getInstanc.call(callbacks));
47
- if (widget && widget.name && widget.version) {
48
- var _callbacks$reconstruc;
49
- this._widget = widget;
50
- await afterDOMLoad();
51
- await loadAssets(widget.assets, this._shadow);
52
- await (callbacks === null || callbacks === void 0 || (_callbacks$reconstruc = callbacks.reconstructor) === null || _callbacks$reconstruc === void 0 ? void 0 : _callbacks$reconstruc.call(callbacks, this._widget, {
53
- shadow: this._shadow,
54
- customElement: this
55
- }));
56
- if (typeof (callbacks === null || callbacks === void 0 ? void 0 : callbacks.remount) === 'function') {
57
- var _callbacks$remount;
58
- await (callbacks === null || callbacks === void 0 || (_callbacks$remount = callbacks.remount) === null || _callbacks$remount === void 0 ? void 0 : _callbacks$remount.call(callbacks, this._widget, {
37
+ class HTMLCustomElement extends HTMLElement {
38
+ static get observedAttributes() {
39
+ return observedAttributes !== null && observedAttributes !== void 0 ? observedAttributes : [];
40
+ }
41
+ constructor(...$) {
42
+ const _ = super(...$);
43
+ _._init();
44
+ return _;
45
+ }
46
+ _init() {}
47
+ }
48
+ class WidgetElement extends HTMLCustomElement {
49
+ _init() {
50
+ try {
51
+ super._init();
52
+ const customWidgetDefinition = deepMerge({}, widgetDefinition);
53
+ this._widgetPromise = (async () => {
54
+ this._shadow = this.attachShadow({
55
+ mode: 'open'
56
+ });
57
+ try {
58
+ var _callbacks$getInstanc;
59
+ const widget = await (callbacks === null || callbacks === void 0 || (_callbacks$getInstanc = callbacks.getInstance) === null || _callbacks$getInstanc === void 0 ? void 0 : _callbacks$getInstanc.call(callbacks));
60
+ if (widget && widget.name && widget.version) {
61
+ var _callbacks$reconstruc;
62
+ this._widget = widget;
63
+ await afterDOMLoad();
64
+ await loadAssets(widget.assets, this._shadow);
65
+ await (callbacks === null || callbacks === void 0 || (_callbacks$reconstruc = callbacks.reconstructor) === null || _callbacks$reconstruc === void 0 ? void 0 : _callbacks$reconstruc.call(callbacks, this._widget, {
59
66
  shadow: this._shadow,
60
67
  customElement: this
61
68
  }));
62
- } else {
63
- widget.root = this._shadow;
64
- widget.customElement = this;
65
- this._shadow.appendChild(widget.container);
69
+ if (typeof (callbacks === null || callbacks === void 0 ? void 0 : callbacks.remount) === 'function') {
70
+ var _callbacks$remount;
71
+ await (callbacks === null || callbacks === void 0 || (_callbacks$remount = callbacks.remount) === null || _callbacks$remount === void 0 ? void 0 : _callbacks$remount.call(callbacks, this._widget, {
72
+ shadow: this._shadow,
73
+ customElement: this
74
+ }));
75
+ } else {
76
+ widget.root = this._shadow;
77
+ widget.customElement = this;
78
+ this._shadow.appendChild(widget.container);
79
+ }
80
+ return;
66
81
  }
82
+ } catch (error) {
83
+ console.error(error);
67
84
  return;
68
85
  }
69
- } catch (error) {
70
- console.error(error);
71
- return;
72
- }
73
- try {
74
- var _callbacks$constructo, _await$callbacks$moun, _callbacks$mount;
75
- customWidgetDefinition.root = this._shadow;
76
- customWidgetDefinition.customElement = this;
77
- if (!customWidgetDefinition.container) {
78
- customWidgetDefinition.container = document.createElement('div');
79
- customWidgetDefinition.container.setAttribute('id', 'merkur-container');
86
+ try {
87
+ var _callbacks$constructo, _await$callbacks$moun, _callbacks$mount;
88
+ customWidgetDefinition.root = this._shadow;
89
+ customWidgetDefinition.customElement = this;
90
+ if (!customWidgetDefinition.container) {
91
+ customWidgetDefinition.container = document.createElement('div');
92
+ customWidgetDefinition.container.setAttribute('id', 'merkur-container');
93
+ }
94
+ this._shadow.appendChild(customWidgetDefinition.container);
95
+ this._widget = await createSPAWidget(customWidgetDefinition, this._shadow);
96
+ await (callbacks === null || callbacks === void 0 || (_callbacks$constructo = callbacks.constructor) === null || _callbacks$constructo === void 0 ? void 0 : _callbacks$constructo.call(callbacks, this._widget, {
97
+ shadow: this._shadow,
98
+ customElement: this
99
+ }));
100
+ (_await$callbacks$moun = await (callbacks === null || callbacks === void 0 || (_callbacks$mount = callbacks.mount) === null || _callbacks$mount === void 0 ? void 0 : _callbacks$mount.call(callbacks, this._widget, {
101
+ shadow: this._shadow,
102
+ customElement: this
103
+ }))) !== null && _await$callbacks$moun !== void 0 ? _await$callbacks$moun : await this._widget.mount();
104
+ } catch (error) {
105
+ console.error(error);
80
106
  }
81
- this._shadow.appendChild(customWidgetDefinition.container);
82
- this._widget = await createSPAWidget(customWidgetDefinition, this._shadow);
83
- await (callbacks === null || callbacks === void 0 || (_callbacks$constructo = callbacks.constructor) === null || _callbacks$constructo === void 0 ? void 0 : _callbacks$constructo.call(callbacks, this._widget, {
84
- shadow: this._shadow,
85
- customElement: this
86
- }));
87
- (_await$callbacks$moun = await (callbacks === null || callbacks === void 0 || (_callbacks$mount = callbacks.mount) === null || _callbacks$mount === void 0 ? void 0 : _callbacks$mount.call(callbacks, this._widget, {
88
- shadow: this._shadow,
89
- customElement: this
90
- }))) !== null && _await$callbacks$moun !== void 0 ? _await$callbacks$moun : await this._widget.mount();
91
- } catch (error) {
92
- console.error(error);
93
- }
94
- })();
107
+ })();
108
+ } catch (error) {
109
+ console.error(error);
110
+ }
95
111
  }
96
- connectedCallback() {
112
+ async connectedCallback() {
97
113
  var _this$_widget, _this$_widget$connect, _callbacks$connectedC;
114
+ await this._widgetPromise;
98
115
  (_this$_widget = this._widget) === null || _this$_widget === void 0 || (_this$_widget$connect = _this$_widget.connectedCallback) === null || _this$_widget$connect === void 0 || _this$_widget$connect.call(_this$_widget, {
99
116
  shadow: this._shadow,
100
117
  customElement: this
@@ -104,8 +121,9 @@ function registerCustomElement(options) {
104
121
  customElement: this
105
122
  });
106
123
  }
107
- disconnectedCallback() {
124
+ async disconnectedCallback() {
108
125
  var _this$_widget2, _this$_widget2$discon, _callbacks$disconnect;
126
+ await this._widgetPromise;
109
127
  (_this$_widget2 = this._widget) === null || _this$_widget2 === void 0 || (_this$_widget2$discon = _this$_widget2.disconnectedCallback) === null || _this$_widget2$discon === void 0 || _this$_widget2$discon.call(_this$_widget2, {
110
128
  shadow: this._shadow,
111
129
  customElement: this
@@ -115,8 +133,9 @@ function registerCustomElement(options) {
115
133
  customElement: this
116
134
  });
117
135
  }
118
- adoptedCallback() {
136
+ async adoptedCallback() {
119
137
  var _this$_widget3, _this$_widget3$adopte, _callbacks$adoptedCal;
138
+ await this._widgetPromise;
120
139
  (_this$_widget3 = this._widget) === null || _this$_widget3 === void 0 || (_this$_widget3$adopte = _this$_widget3.adoptedCallback) === null || _this$_widget3$adopte === void 0 || _this$_widget3$adopte.call(_this$_widget3, {
121
140
  shadow: this._shadow,
122
141
  customElement: this
@@ -126,8 +145,9 @@ function registerCustomElement(options) {
126
145
  customElement: this
127
146
  });
128
147
  }
129
- attributeChangedCallback(name, oldValue, newValue) {
148
+ async attributeChangedCallback(name, oldValue, newValue) {
130
149
  var _this$_widget4, _this$_widget4$attrib, _callbacks$attributeC;
150
+ await this._widgetPromise;
131
151
  (_this$_widget4 = this._widget) === null || _this$_widget4 === void 0 || (_this$_widget4$attrib = _this$_widget4.attributeChangedCallback) === null || _this$_widget4$attrib === void 0 || _this$_widget4$attrib.call(_this$_widget4, this._widget, name, oldValue, newValue, {
132
152
  shadow: this._shadow,
133
153
  customElement: this
package/lib/index.js CHANGED
@@ -37,84 +37,104 @@ function afterDOMLoad() {
37
37
  }
38
38
 
39
39
  function registerCustomElement(options) {
40
- const { widgetDefinition, callbacks } = deepMerge({}, options);
41
- class WidgetElement extends HTMLElement {
42
- constructor() {
43
- super();
44
-
45
- const customWidgetDefinition = deepMerge({}, widgetDefinition);
40
+ const { widgetDefinition, callbacks, observedAttributes } = deepMerge(
41
+ {},
42
+ options,
43
+ );
44
+ class HTMLCustomElement extends HTMLElement {
45
+ static get observedAttributes() {
46
+ return observedAttributes ?? [];
47
+ }
48
+ constructor(...$) {
49
+ const _ = super(...$);
50
+ _._init();
51
+ return _;
52
+ }
53
+ _init() {}
54
+ }
46
55
 
47
- (async () => {
48
- this._shadow = this.attachShadow({ mode: 'open' });
56
+ class WidgetElement extends HTMLCustomElement {
57
+ _init() {
58
+ try {
59
+ super._init();
60
+ const customWidgetDefinition = deepMerge({}, widgetDefinition);
49
61
 
50
- try {
51
- const widget = await callbacks?.getInstance?.();
62
+ this._widgetPromise = (async () => {
63
+ this._shadow = this.attachShadow({ mode: 'open' });
52
64
 
53
- if (widget && widget.name && widget.version) {
54
- this._widget = widget;
65
+ try {
66
+ const widget = await callbacks?.getInstance?.();
55
67
 
56
- await afterDOMLoad();
57
- await integration.loadAssets(widget.assets, this._shadow);
68
+ if (widget && widget.name && widget.version) {
69
+ this._widget = widget;
58
70
 
59
- await callbacks?.reconstructor?.(this._widget, {
60
- shadow: this._shadow,
61
- customElement: this,
62
- });
71
+ await afterDOMLoad();
72
+ await integration.loadAssets(widget.assets, this._shadow);
63
73
 
64
- if (typeof callbacks?.remount === 'function') {
65
- await callbacks?.remount?.(this._widget, {
74
+ await callbacks?.reconstructor?.(this._widget, {
66
75
  shadow: this._shadow,
67
76
  customElement: this,
68
77
  });
69
- } else {
70
- widget.root = this._shadow;
71
- widget.customElement = this;
72
- this._shadow.appendChild(widget.container);
78
+
79
+ if (typeof callbacks?.remount === 'function') {
80
+ await callbacks?.remount?.(this._widget, {
81
+ shadow: this._shadow,
82
+ customElement: this,
83
+ });
84
+ } else {
85
+ widget.root = this._shadow;
86
+ widget.customElement = this;
87
+ this._shadow.appendChild(widget.container);
88
+ }
89
+
90
+ return;
73
91
  }
92
+ } catch (error) {
93
+ console.error(error);
74
94
 
75
95
  return;
76
96
  }
77
- } catch (error) {
78
- console.error(error);
79
97
 
80
- return;
81
- }
98
+ try {
99
+ customWidgetDefinition.root = this._shadow;
100
+ customWidgetDefinition.customElement = this;
101
+
102
+ if (!customWidgetDefinition.container) {
103
+ customWidgetDefinition.container = document.createElement('div');
104
+ customWidgetDefinition.container.setAttribute(
105
+ 'id',
106
+ 'merkur-container',
107
+ );
108
+ }
82
109
 
83
- try {
84
- customWidgetDefinition.root = this._shadow;
85
- customWidgetDefinition.customElement = this;
110
+ this._shadow.appendChild(customWidgetDefinition.container);
86
111
 
87
- if (!customWidgetDefinition.container) {
88
- customWidgetDefinition.container = document.createElement('div');
89
- customWidgetDefinition.container.setAttribute(
90
- 'id',
91
- 'merkur-container',
112
+ this._widget = await createSPAWidget(
113
+ customWidgetDefinition,
114
+ this._shadow,
92
115
  );
93
- }
94
116
 
95
- this._shadow.appendChild(customWidgetDefinition.container);
96
-
97
- this._widget = await createSPAWidget(
98
- customWidgetDefinition,
99
- this._shadow,
100
- );
101
-
102
- await callbacks?.constructor?.(this._widget, {
103
- shadow: this._shadow,
104
- customElement: this,
105
- });
106
-
107
- (await callbacks?.mount?.(this._widget, {
108
- shadow: this._shadow,
109
- customElement: this,
110
- })) ?? (await this._widget.mount());
111
- } catch (error) {
112
- console.error(error);
113
- }
114
- })();
117
+ await callbacks?.constructor?.(this._widget, {
118
+ shadow: this._shadow,
119
+ customElement: this,
120
+ });
121
+
122
+ (await callbacks?.mount?.(this._widget, {
123
+ shadow: this._shadow,
124
+ customElement: this,
125
+ })) ?? (await this._widget.mount());
126
+ } catch (error) {
127
+ console.error(error);
128
+ }
129
+ })();
130
+ } catch (error) {
131
+ console.error(error);
132
+ }
115
133
  }
116
134
 
117
- connectedCallback() {
135
+ async connectedCallback() {
136
+ await this._widgetPromise;
137
+
118
138
  this._widget?.connectedCallback?.({
119
139
  shadow: this._shadow,
120
140
  customElement: this,
@@ -126,7 +146,9 @@ function registerCustomElement(options) {
126
146
  });
127
147
  }
128
148
 
129
- disconnectedCallback() {
149
+ async disconnectedCallback() {
150
+ await this._widgetPromise;
151
+
130
152
  this._widget?.disconnectedCallback?.({
131
153
  shadow: this._shadow,
132
154
  customElement: this,
@@ -138,7 +160,9 @@ function registerCustomElement(options) {
138
160
  });
139
161
  }
140
162
 
141
- adoptedCallback() {
163
+ async adoptedCallback() {
164
+ await this._widgetPromise;
165
+
142
166
  this._widget?.adoptedCallback?.({
143
167
  shadow: this._shadow,
144
168
  customElement: this,
@@ -150,7 +174,9 @@ function registerCustomElement(options) {
150
174
  });
151
175
  }
152
176
 
153
- attributeChangedCallback(name, oldValue, newValue) {
177
+ async attributeChangedCallback(name, oldValue, newValue) {
178
+ await this._widgetPromise;
179
+
154
180
  this._widget?.attributeChangedCallback?.(
155
181
  this._widget,
156
182
  name,
package/lib/index.mjs CHANGED
@@ -35,84 +35,104 @@ function afterDOMLoad() {
35
35
  }
36
36
 
37
37
  function registerCustomElement(options) {
38
- const { widgetDefinition, callbacks } = deepMerge({}, options);
39
- class WidgetElement extends HTMLElement {
40
- constructor() {
41
- super();
42
-
43
- const customWidgetDefinition = deepMerge({}, widgetDefinition);
38
+ const { widgetDefinition, callbacks, observedAttributes } = deepMerge(
39
+ {},
40
+ options,
41
+ );
42
+ class HTMLCustomElement extends HTMLElement {
43
+ static get observedAttributes() {
44
+ return observedAttributes ?? [];
45
+ }
46
+ constructor(...$) {
47
+ const _ = super(...$);
48
+ _._init();
49
+ return _;
50
+ }
51
+ _init() {}
52
+ }
44
53
 
45
- (async () => {
46
- this._shadow = this.attachShadow({ mode: 'open' });
54
+ class WidgetElement extends HTMLCustomElement {
55
+ _init() {
56
+ try {
57
+ super._init();
58
+ const customWidgetDefinition = deepMerge({}, widgetDefinition);
47
59
 
48
- try {
49
- const widget = await callbacks?.getInstance?.();
60
+ this._widgetPromise = (async () => {
61
+ this._shadow = this.attachShadow({ mode: 'open' });
50
62
 
51
- if (widget && widget.name && widget.version) {
52
- this._widget = widget;
63
+ try {
64
+ const widget = await callbacks?.getInstance?.();
53
65
 
54
- await afterDOMLoad();
55
- await loadAssets(widget.assets, this._shadow);
66
+ if (widget && widget.name && widget.version) {
67
+ this._widget = widget;
56
68
 
57
- await callbacks?.reconstructor?.(this._widget, {
58
- shadow: this._shadow,
59
- customElement: this,
60
- });
69
+ await afterDOMLoad();
70
+ await loadAssets(widget.assets, this._shadow);
61
71
 
62
- if (typeof callbacks?.remount === 'function') {
63
- await callbacks?.remount?.(this._widget, {
72
+ await callbacks?.reconstructor?.(this._widget, {
64
73
  shadow: this._shadow,
65
74
  customElement: this,
66
75
  });
67
- } else {
68
- widget.root = this._shadow;
69
- widget.customElement = this;
70
- this._shadow.appendChild(widget.container);
76
+
77
+ if (typeof callbacks?.remount === 'function') {
78
+ await callbacks?.remount?.(this._widget, {
79
+ shadow: this._shadow,
80
+ customElement: this,
81
+ });
82
+ } else {
83
+ widget.root = this._shadow;
84
+ widget.customElement = this;
85
+ this._shadow.appendChild(widget.container);
86
+ }
87
+
88
+ return;
71
89
  }
90
+ } catch (error) {
91
+ console.error(error);
72
92
 
73
93
  return;
74
94
  }
75
- } catch (error) {
76
- console.error(error);
77
95
 
78
- return;
79
- }
96
+ try {
97
+ customWidgetDefinition.root = this._shadow;
98
+ customWidgetDefinition.customElement = this;
99
+
100
+ if (!customWidgetDefinition.container) {
101
+ customWidgetDefinition.container = document.createElement('div');
102
+ customWidgetDefinition.container.setAttribute(
103
+ 'id',
104
+ 'merkur-container',
105
+ );
106
+ }
80
107
 
81
- try {
82
- customWidgetDefinition.root = this._shadow;
83
- customWidgetDefinition.customElement = this;
108
+ this._shadow.appendChild(customWidgetDefinition.container);
84
109
 
85
- if (!customWidgetDefinition.container) {
86
- customWidgetDefinition.container = document.createElement('div');
87
- customWidgetDefinition.container.setAttribute(
88
- 'id',
89
- 'merkur-container',
110
+ this._widget = await createSPAWidget(
111
+ customWidgetDefinition,
112
+ this._shadow,
90
113
  );
91
- }
92
114
 
93
- this._shadow.appendChild(customWidgetDefinition.container);
94
-
95
- this._widget = await createSPAWidget(
96
- customWidgetDefinition,
97
- this._shadow,
98
- );
99
-
100
- await callbacks?.constructor?.(this._widget, {
101
- shadow: this._shadow,
102
- customElement: this,
103
- });
104
-
105
- (await callbacks?.mount?.(this._widget, {
106
- shadow: this._shadow,
107
- customElement: this,
108
- })) ?? (await this._widget.mount());
109
- } catch (error) {
110
- console.error(error);
111
- }
112
- })();
115
+ await callbacks?.constructor?.(this._widget, {
116
+ shadow: this._shadow,
117
+ customElement: this,
118
+ });
119
+
120
+ (await callbacks?.mount?.(this._widget, {
121
+ shadow: this._shadow,
122
+ customElement: this,
123
+ })) ?? (await this._widget.mount());
124
+ } catch (error) {
125
+ console.error(error);
126
+ }
127
+ })();
128
+ } catch (error) {
129
+ console.error(error);
130
+ }
113
131
  }
114
132
 
115
- connectedCallback() {
133
+ async connectedCallback() {
134
+ await this._widgetPromise;
135
+
116
136
  this._widget?.connectedCallback?.({
117
137
  shadow: this._shadow,
118
138
  customElement: this,
@@ -124,7 +144,9 @@ function registerCustomElement(options) {
124
144
  });
125
145
  }
126
146
 
127
- disconnectedCallback() {
147
+ async disconnectedCallback() {
148
+ await this._widgetPromise;
149
+
128
150
  this._widget?.disconnectedCallback?.({
129
151
  shadow: this._shadow,
130
152
  customElement: this,
@@ -136,7 +158,9 @@ function registerCustomElement(options) {
136
158
  });
137
159
  }
138
160
 
139
- adoptedCallback() {
161
+ async adoptedCallback() {
162
+ await this._widgetPromise;
163
+
140
164
  this._widget?.adoptedCallback?.({
141
165
  shadow: this._shadow,
142
166
  customElement: this,
@@ -148,7 +172,9 @@ function registerCustomElement(options) {
148
172
  });
149
173
  }
150
174
 
151
- attributeChangedCallback(name, oldValue, newValue) {
175
+ async attributeChangedCallback(name, oldValue, newValue) {
176
+ await this._widgetPromise;
177
+
152
178
  this._widget?.attributeChangedCallback?.(
153
179
  this._widget,
154
180
  name,
package/lib/index.umd.js CHANGED
@@ -1 +1 @@
1
- function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}!function(e,t){if("function"==typeof define&&define.amd)define("@merkur/integration-custom-element",["exports","@merkur/core","@merkur/integration"],t);else if("undefined"!=typeof exports)t(exports,require("@merkur/core"),require("@merkur/integration"));else{var n={exports:{}};t(n.exports,e.Merkur.Core,e.Merkur.Integration),e.merkurIntegrationCustomElement=n.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(t,n,o){function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){l(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function l(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,c(o.key),o)}}function c(t){var n=function(t,n){if("object"!=e(t)||!t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var r=o.call(t,n||"default");if("object"!=e(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}(t,"string");return"symbol"==e(n)?n:n+""}function a(e){var t="function"==typeof Map?new Map:void 0;return a=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return function(e,t,n){if(s())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,t);var r=new(e.bind.apply(e,o));return n&&d(r,n.prototype),r}(e,arguments,f(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),d(n,e)},a(e)}function s(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(s=function(){return!!e})()}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}function p(e,t,n,o,r,i,l){try{var u=e[i](l),c=u.value}catch(e){return void n(e)}u.done?t(c):Promise.resolve(c).then(o,r)}function y(e){return function(){var t=this,n=arguments;return new Promise((function(o,r){var i=e.apply(t,n);function l(e){p(i,o,r,l,u,"next",e)}function u(e){p(i,o,r,l,u,"throw",e)}l(void 0)}))}}function h(){return(h=y((function*(e,t){var r=i(i({},e),{},{createWidget:e.createWidget});return(0,n.getMerkur)().isRegistered(r.name+r.version)||(0,n.getMerkur)().register(r),yield m(),yield(0,o.loadAssets)(r.assets,t),yield(0,n.getMerkur)().create(r)}))).apply(this,arguments)}function m(){return new Promise((function(e){"undefined"!=typeof document?"loading"!==document.readyState?e():window.addEventListener("DOMContentLoaded",(function(){e()})):e()}))}Object.defineProperty(t,"__esModule",{value:!0}),t.deepMerge=b,t.registerCustomElement=function(t){var n=b({},t),r=n.widgetDefinition,i=n.callbacks,l=function(t){function n(){var t,l,u,c;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),l=this,u=f(u=n),t=function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;if(void 0!==n)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(l,s()?Reflect.construct(u,c||[],f(l).constructor):u.apply(l,c));var a=b({},r);return y((function*(){t._shadow=t.attachShadow({mode:"open"});try{var e,n=yield null==i||null===(e=i.getInstance)||void 0===e?void 0:e.call(i);if(n&&n.name&&n.version){var r,l;if(t._widget=n,yield m(),yield(0,o.loadAssets)(n.assets,t._shadow),yield null==i||null===(r=i.reconstructor)||void 0===r?void 0:r.call(i,t._widget,{shadow:t._shadow,customElement:t}),"function"==typeof(null==i?void 0:i.remount))yield null==i||null===(l=i.remount)||void 0===l?void 0:l.call(i,t._widget,{shadow:t._shadow,customElement:t});else n.root=t._shadow,n.customElement=t,t._shadow.appendChild(n.container);return}}catch(e){return void console.error(e)}try{var u,c,s;a.root=t._shadow,a.customElement=t,a.container||(a.container=document.createElement("div"),a.container.setAttribute("id","merkur-container")),t._shadow.appendChild(a.container),t._widget=yield function(e,t){return h.apply(this,arguments)}(a,t._shadow),yield null==i||null===(u=i.constructor)||void 0===u?void 0:u.call(i,t._widget,{shadow:t._shadow,customElement:t}),null!==(c=yield null==i||null===(s=i.mount)||void 0===s?void 0:s.call(i,t._widget,{shadow:t._shadow,customElement:t}))&&void 0!==c||(yield t._widget.mount())}catch(e){console.error(e)}}))(),t}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&d(e,t)}(n,t),function(e,t,n){t&&u(e.prototype,t);n&&u(e,n);return Object.defineProperty(e,"prototype",{writable:!1}),e}(n,[{key:"connectedCallback",value:function(){var e,t,n;null===(e=this._widget)||void 0===e||null===(t=e.connectedCallback)||void 0===t||t.call(e,{shadow:this._shadow,customElement:this}),null==i||null===(n=i.connectedCallback)||void 0===n||n.call(i,this._widget,{shadow:this._shadow,customElement:this})}},{key:"disconnectedCallback",value:function(){var e,t,n;null===(e=this._widget)||void 0===e||null===(t=e.disconnectedCallback)||void 0===t||t.call(e,{shadow:this._shadow,customElement:this}),null==i||null===(n=i.disconnectedCallback)||void 0===n||n.call(i,this._widget,{shadow:this._shadow,customElement:this})}},{key:"adoptedCallback",value:function(){var e,t,n;null===(e=this._widget)||void 0===e||null===(t=e.adoptedCallback)||void 0===t||t.call(e,{shadow:this._shadow,customElement:this}),null==i||null===(n=i.adoptedCallback)||void 0===n||n.call(i,this._widget,{shadow:this._shadow,customElement:this})}},{key:"attributeChangedCallback",value:function(e,t,n){var o,r,l;null===(o=this._widget)||void 0===o||null===(r=o.attributeChangedCallback)||void 0===r||r.call(o,this._widget,e,t,n,{shadow:this._shadow,customElement:this}),null==i||null===(l=i.attributeChangedCallback)||void 0===l||l.call(i,this._widget,e,t,n,{shadow:this._shadow,customElement:this})}}])}(a(HTMLElement));void 0===customElements.get(r.name)&&customElements.define(r.name,l)};var v=["__proto__","prototype","constructor"];function b(e,t){var n=function(e){return!!e&&e.constructor===Object};return n(e)&&n(t)?(Object.keys(t).forEach((function(o){if(!v.includes(o)){var r=e[o],i=t[o];Array.isArray(r)&&Array.isArray(i)?e[o]=r.concat(i):n(r)&&n(i)?e[o]=b(Object.assign({},r),i):e[o]=i}})),e):t}}));
1
+ function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}!function(t,e){if("function"==typeof define&&define.amd)define("@merkur/integration-custom-element",["exports","@merkur/core","@merkur/integration"],e);else if("undefined"!=typeof exports)e(exports,require("@merkur/core"),require("@merkur/integration"));else{var n={exports:{}};e(n.exports,t.Merkur.Core,t.Merkur.Integration),t.merkurIntegrationCustomElement=n.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(e,n,r){function o(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function i(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?o(Object(n),!0).forEach((function(e){u(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function u(t,e,n){return(e=d(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function l(){return l="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var r=function(t,e){for(;!{}.hasOwnProperty.call(t,e)&&null!==(t=b(t)););return t}(t,e);if(r){var o=Object.getOwnPropertyDescriptor(r,e);return o.get?o.get.call(arguments.length<3?t:n):o.value}},l.apply(null,arguments)}function c(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,d(r.key),r)}}function s(t,e,n){return e&&a(t.prototype,e),n&&a(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function d(e){var n=function(e,n){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,n||"default");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==t(n)?n:n+""}function f(t,e,n){return e=b(e),p(t,v()?Reflect.construct(e,n||[],b(t).constructor):e.apply(t,n))}function p(e,n){if(n&&("object"==t(n)||"function"==typeof n))return n;if(void 0!==n)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(e)}function y(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&m(t,e)}function h(t){var e="function"==typeof Map?new Map:void 0;return h=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return function(t,e,n){if(v())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,e);var o=new(t.bind.apply(t,r));return n&&m(o,n.prototype),o}(t,arguments,b(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),m(n,t)},h(t)}function v(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(v=function(){return!!t})()}function m(t,e){return m=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},m(t,e)}function b(t){return b=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},b(t)}function w(t,e,n,r,o,i,u){try{var l=t[i](u),c=l.value}catch(t){return void n(t)}l.done?e(c):Promise.resolve(c).then(r,o)}function g(t){return function(){var e=this,n=arguments;return new Promise((function(r,o){var i=t.apply(e,n);function u(t){w(i,r,o,u,l,"next",t)}function l(t){w(i,r,o,u,l,"throw",t)}u(void 0)}))}}function _(){return(_=g((function*(t,e){var o=i(i({},t),{},{createWidget:t.createWidget});return(0,n.getMerkur)().isRegistered(o.name+o.version)||(0,n.getMerkur)().register(o),yield O(),yield(0,r.loadAssets)(o.assets,e),yield(0,n.getMerkur)().create(o)}))).apply(this,arguments)}function O(){return new Promise((function(t){"undefined"!=typeof document?"loading"!==document.readyState?t():window.addEventListener("DOMContentLoaded",(function(){t()})):t()}))}Object.defineProperty(e,"__esModule",{value:!0}),e.deepMerge=j,e.registerCustomElement=function(t){var e=j({},t),n=e.widgetDefinition,o=e.callbacks,i=e.observedAttributes,u=function(t){function e(){var t;c(this,e);for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];var i=t=f(this,e,[].concat(r));return i._init(),p(t,i)}return y(e,t),s(e,[{key:"_init",value:function(){}}],[{key:"observedAttributes",get:function(){return null!=i?i:[]}}])}(h(HTMLElement)),a=function(t){function e(){return c(this,e),f(this,e,arguments)}return y(e,t),s(e,[{key:"_init",value:function(){var t,i,u,c,a,s=this;try{(t=e,i="_init",u=this,a=l(b(1&(c=3)?t.prototype:t),i,u),2&c&&"function"==typeof a?function(t){return a.apply(u,t)}:a)([]);var d=j({},n);this._widgetPromise=g((function*(){s._shadow=s.attachShadow({mode:"open"});try{var t,e=yield null==o||null===(t=o.getInstance)||void 0===t?void 0:t.call(o);if(e&&e.name&&e.version){var n,i;if(s._widget=e,yield O(),yield(0,r.loadAssets)(e.assets,s._shadow),yield null==o||null===(n=o.reconstructor)||void 0===n?void 0:n.call(o,s._widget,{shadow:s._shadow,customElement:s}),"function"==typeof(null==o?void 0:o.remount))yield null==o||null===(i=o.remount)||void 0===i?void 0:i.call(o,s._widget,{shadow:s._shadow,customElement:s});else e.root=s._shadow,e.customElement=s,s._shadow.appendChild(e.container);return}}catch(t){return void console.error(t)}try{var u,l,c;d.root=s._shadow,d.customElement=s,d.container||(d.container=document.createElement("div"),d.container.setAttribute("id","merkur-container")),s._shadow.appendChild(d.container),s._widget=yield function(t,e){return _.apply(this,arguments)}(d,s._shadow),yield null==o||null===(u=o.constructor)||void 0===u?void 0:u.call(o,s._widget,{shadow:s._shadow,customElement:s}),null!==(l=yield null==o||null===(c=o.mount)||void 0===c?void 0:c.call(o,s._widget,{shadow:s._shadow,customElement:s}))&&void 0!==l||(yield s._widget.mount())}catch(t){console.error(t)}}))()}catch(t){console.error(t)}}},{key:"connectedCallback",value:(d=g((function*(){var t,e,n;yield this._widgetPromise,null===(t=this._widget)||void 0===t||null===(e=t.connectedCallback)||void 0===e||e.call(t,{shadow:this._shadow,customElement:this}),null==o||null===(n=o.connectedCallback)||void 0===n||n.call(o,this._widget,{shadow:this._shadow,customElement:this})})),function(){return d.apply(this,arguments)})},{key:"disconnectedCallback",value:(a=g((function*(){var t,e,n;yield this._widgetPromise,null===(t=this._widget)||void 0===t||null===(e=t.disconnectedCallback)||void 0===e||e.call(t,{shadow:this._shadow,customElement:this}),null==o||null===(n=o.disconnectedCallback)||void 0===n||n.call(o,this._widget,{shadow:this._shadow,customElement:this})})),function(){return a.apply(this,arguments)})},{key:"adoptedCallback",value:(u=g((function*(){var t,e,n;yield this._widgetPromise,null===(t=this._widget)||void 0===t||null===(e=t.adoptedCallback)||void 0===e||e.call(t,{shadow:this._shadow,customElement:this}),null==o||null===(n=o.adoptedCallback)||void 0===n||n.call(o,this._widget,{shadow:this._shadow,customElement:this})})),function(){return u.apply(this,arguments)})},{key:"attributeChangedCallback",value:(i=g((function*(t,e,n){var r,i,u;yield this._widgetPromise,null===(r=this._widget)||void 0===r||null===(i=r.attributeChangedCallback)||void 0===i||i.call(r,this._widget,t,e,n,{shadow:this._shadow,customElement:this}),null==o||null===(u=o.attributeChangedCallback)||void 0===u||u.call(o,this._widget,t,e,n,{shadow:this._shadow,customElement:this})})),function(t,e,n){return i.apply(this,arguments)})}]);var i,u,a,d}(u);void 0===customElements.get(n.name)&&customElements.define(n.name,a)};var k=["__proto__","prototype","constructor"];function j(t,e){var n=function(t){return!!t&&t.constructor===Object};return n(t)&&n(e)?(Object.keys(e).forEach((function(r){if(!k.includes(r)){var o=t[r],i=e[r];Array.isArray(o)&&Array.isArray(i)?t[r]=o.concat(i):n(o)&&n(i)?t[r]=j(Object.assign({},o),i):t[r]=i}})),t):e}}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merkur/integration-custom-element",
3
- "version": "0.36.4",
3
+ "version": "0.37.2",
4
4
  "description": "Merkur module for easy integration with other apps with custom element.",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -51,12 +51,12 @@
51
51
  },
52
52
  "homepage": "https://merkur.js.org/",
53
53
  "devDependencies": {
54
- "@merkur/core": "^0.36.0",
55
- "@merkur/integration": "^0.36.0"
54
+ "@merkur/core": "^0.37.0",
55
+ "@merkur/integration": "^0.37.0"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@merkur/core": "*",
59
59
  "@merkur/integration": "*"
60
60
  },
61
- "gitHead": "d980d225d1aea2186663940f0a984dafa1232c21"
61
+ "gitHead": "1d30cc6289bd852bd58721c3207bbff8717d91e4"
62
62
  }