@alexgyver/component 1.3.0 → 1.3.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/Component.js +4 -21
- package/package.json +1 -1
package/Component.js
CHANGED
|
@@ -57,14 +57,14 @@ export class Component {
|
|
|
57
57
|
}
|
|
58
58
|
if (!(el instanceof Node) || (typeof data !== 'object')) return el;
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
Component.ctx = (data.context === null) ? null : (data.context ? data.context : Component.ctx);
|
|
61
|
+
const ctx = Component.ctx;
|
|
61
62
|
|
|
62
63
|
let addChild = (obj) => {
|
|
63
64
|
if (!obj) return;
|
|
64
65
|
if (obj instanceof Node) el.appendChild(obj);
|
|
65
66
|
else if (obj instanceof Component) el.appendChild(obj.$root);
|
|
66
67
|
else if (typeof obj === 'object') {
|
|
67
|
-
if (!obj.context) obj.context = ctx;
|
|
68
68
|
let cmp = Component.make(obj.tag ?? 'div', obj, svg || obj.tag == 'svg');
|
|
69
69
|
if (cmp) el.appendChild(cmp);
|
|
70
70
|
} else if (typeof obj === 'string') {
|
|
@@ -151,6 +151,8 @@ export class Component {
|
|
|
151
151
|
Component.config($host, data);
|
|
152
152
|
return $host;
|
|
153
153
|
}
|
|
154
|
+
|
|
155
|
+
static ctx;
|
|
154
156
|
}
|
|
155
157
|
|
|
156
158
|
export class Sheet {
|
|
@@ -234,23 +236,4 @@ export class SVG {
|
|
|
234
236
|
static text = (text, x, y, attrs = {}, props = {}) => SVG._make('text', { ...attrs, x: x, y: y }, { ...props, text: text });
|
|
235
237
|
|
|
236
238
|
static _make = (tag, attrs = {}, props = {}) => Component.makeSVG(tag, { attrs: { ...attrs }, ...props });
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export async function waitRender(elm, cb = null, ctx = window) {
|
|
240
|
-
return new Promise(res => {
|
|
241
|
-
let e = elm;
|
|
242
|
-
while (e.parentNode) e = e.parentNode;
|
|
243
|
-
if (e instanceof Document) {
|
|
244
|
-
if (cb) cb(elm);
|
|
245
|
-
res(elm);
|
|
246
|
-
}
|
|
247
|
-
const obs = new MutationObserver((mut) => {
|
|
248
|
-
if (mut[0].addedNodes.length === 0) return;
|
|
249
|
-
if (Array.prototype.indexOf.call(mut[0].addedNodes, e) === -1) return;
|
|
250
|
-
obs.disconnect();
|
|
251
|
-
if (cb) cb(elm);
|
|
252
|
-
res(elm);
|
|
253
|
-
});
|
|
254
|
-
obs.observe(ctx.document.body, { childList: true, subtree: true });
|
|
255
|
-
});
|
|
256
239
|
}
|