@skirbi/sugar 0.1.12 → 0.1.13
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/Changes
CHANGED
package/lib/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: MIT
|
|
4
4
|
|
|
5
|
-
const VERSION = "0.1.
|
|
5
|
+
const VERSION = "0.1.13";
|
|
6
6
|
|
|
7
7
|
export { HTMLElementSugar } from './htmlelement.mjs';
|
|
8
8
|
export { HTMLElementSugarInput } from './htmlelement-input.mjs';
|
|
@@ -11,3 +11,4 @@ export { parseBoolean } from '@opndev/html';
|
|
|
11
11
|
export { registerDevAlias, applyDevAliases } from './aliases.mjs';
|
|
12
12
|
export { registerAliases } from './aliases-register.mjs';
|
|
13
13
|
export { withConnectedSugar } from './with-connected-sugar.mjs';
|
|
14
|
+
export { withConnectedSucu } from './with-connected-sucu.mjs';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-License-Identifier: MIT
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* withConnectSucu
|
|
7
7
|
*
|
|
8
8
|
* Second-generation connected-lifecycle mixin. Built and tested alongside
|
|
9
9
|
* withConnectedSugar so existing components can migrate one at a time.
|
|
@@ -18,20 +18,20 @@
|
|
|
18
18
|
* (wired up in htmlelement.mjs's attributeChangedCallback) instead.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
const sucuState = new WeakMap();
|
|
22
22
|
|
|
23
|
-
export const
|
|
23
|
+
export const withConnectSucu = (Base) =>
|
|
24
24
|
class extends Base {
|
|
25
25
|
static morphTriggerSelector = '';
|
|
26
26
|
|
|
27
27
|
connectedCallback() {
|
|
28
|
-
if (!
|
|
29
|
-
|
|
28
|
+
if (!sucuState.has(this)) {
|
|
29
|
+
sucuState.set(this, {
|
|
30
30
|
rendered: false,
|
|
31
31
|
firstUpdatedCalled: false,
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
const state =
|
|
34
|
+
const state = sucuState.get(this);
|
|
35
35
|
|
|
36
36
|
this._syncObservedAttributesToConfig();
|
|
37
37
|
this._armMorphObserver();
|
|
@@ -75,11 +75,11 @@ export const withConnectSuccu = (Base) =>
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
renderIfParent(parent = null, cb) {
|
|
78
|
-
if (!parent || !
|
|
78
|
+
if (!parent || !sucuState.has(parent)) {
|
|
79
79
|
cb();
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
-
const parentState =
|
|
82
|
+
const parentState = sucuState.get(parent);
|
|
83
83
|
if (parentState.rendered) {
|
|
84
84
|
cb();
|
|
85
85
|
return;
|
|
@@ -114,7 +114,7 @@ export const withConnectSuccu = (Base) =>
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
_armMorphObserver() {
|
|
117
|
-
if (this.
|
|
117
|
+
if (this._sucuMo) return;
|
|
118
118
|
if (this.hasAttribute('morph-ignore')) return;
|
|
119
119
|
|
|
120
120
|
const hasExplicit = this.hasAttribute('morph-child') ||
|
|
@@ -129,10 +129,10 @@ export const withConnectSuccu = (Base) =>
|
|
|
129
129
|
childList: true,
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
-
this.
|
|
132
|
+
this._sucuMo = new MutationObserver((mutations) => {
|
|
133
133
|
|
|
134
134
|
if (this.hasAttribute('morph-debug')) {
|
|
135
|
-
console.group(`[
|
|
135
|
+
console.group(`[sucu-morph] ${this.tagName}${this.id ? '#' + this.id : ''}${this.getAttribute('label') ? `[label="${this.getAttribute('label')}"]` : ''}${this.getAttribute('title') ? `[title="${this.getAttribute('title')}"]` : ''}`);
|
|
136
136
|
console.log('parent:', this.parentElement?.tagName);
|
|
137
137
|
console.log('mutations:', mutations.map(m => ({
|
|
138
138
|
type: m.type,
|
|
@@ -158,7 +158,7 @@ export const withConnectSuccu = (Base) =>
|
|
|
158
158
|
|
|
159
159
|
});
|
|
160
160
|
|
|
161
|
-
this.
|
|
161
|
+
this._sucuMo.observe(this, this._morphObserveOptions);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
_shouldRenderOnMorph() {
|
|
@@ -178,19 +178,19 @@ export const withConnectSuccu = (Base) =>
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
withMorphObserverPaused(fn) {
|
|
181
|
-
this.
|
|
181
|
+
this._sucuMo?.disconnect();
|
|
182
182
|
try {
|
|
183
183
|
fn();
|
|
184
184
|
} finally {
|
|
185
185
|
if (this._morphObserveOptions) {
|
|
186
|
-
this.
|
|
186
|
+
this._sucuMo?.observe(this, this._morphObserveOptions);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
disconnectedCallback() {
|
|
192
|
-
this.
|
|
193
|
-
this.
|
|
192
|
+
this._sucuMo?.disconnect();
|
|
193
|
+
this._sucuMo = null;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
};
|
package/package.json
CHANGED