@aegis-framework/pandora 0.1.4 → 0.1.8
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/LICENSE +1 -1
- package/dist/pandora.js +2 -773
- package/dist/pandora.js.map +1 -1
- package/dist/pandora.min.js +2 -10
- package/dist/pandora.min.js.map +1 -1
- package/dist/pandora.node.js +2 -0
- package/dist/pandora.node.js.map +1 -0
- package/index.js +2 -1
- package/package.json +47 -15
- package/src/Component.js +11 -6
- package/src/Registry.js +2 -1
- package/src/ShadowComponent.js +29 -3
- package/src/Util.js +13 -1
package/src/Component.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
1
2
|
import { callAsync, deserializeCSS } from './Util';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -21,13 +22,13 @@ export class Component extends HTMLElement {
|
|
|
21
22
|
const matches = tag.match (/([A-Z])/g);
|
|
22
23
|
if (matches !== null) {
|
|
23
24
|
for (const match of matches) {
|
|
24
|
-
tag = tag.replace (match, `-${match}`.toLowerCase ())
|
|
25
|
+
tag = tag.replace (match, `-${match}`.toLowerCase ());
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
this._tag = tag.slice (1);
|
|
28
29
|
}
|
|
29
30
|
return this._tag;
|
|
30
|
-
}
|
|
31
|
+
}
|
|
31
32
|
|
|
32
33
|
static set tag (value) {
|
|
33
34
|
this._tag = value;
|
|
@@ -68,6 +69,7 @@ export class Component extends HTMLElement {
|
|
|
68
69
|
|
|
69
70
|
constructor () {
|
|
70
71
|
super ();
|
|
72
|
+
this._children = this.innerHTML.trim ();
|
|
71
73
|
|
|
72
74
|
// State Object for the component
|
|
73
75
|
this._state = {};
|
|
@@ -259,7 +261,7 @@ export class Component extends HTMLElement {
|
|
|
259
261
|
this.updateCallback (key, oldState[key], this._state[key], 'state', oldState, this._state);
|
|
260
262
|
}
|
|
261
263
|
} else {
|
|
262
|
-
throw new TypeError(`A state must be an object. Received ${typeof state}.`)
|
|
264
|
+
throw new TypeError(`A state must be an object. Received ${typeof state}.`);
|
|
263
265
|
}
|
|
264
266
|
}
|
|
265
267
|
|
|
@@ -274,7 +276,7 @@ export class Component extends HTMLElement {
|
|
|
274
276
|
}
|
|
275
277
|
this._setPropAttributes (true);
|
|
276
278
|
} else {
|
|
277
|
-
throw new TypeError(`Props must be an object. Received ${typeof state}.`)
|
|
279
|
+
throw new TypeError(`Props must be an object. Received ${typeof state}.`);
|
|
278
280
|
}
|
|
279
281
|
}
|
|
280
282
|
|
|
@@ -390,7 +392,6 @@ export class Component extends HTMLElement {
|
|
|
390
392
|
// component.
|
|
391
393
|
return callAsync (render, this).then ((html) => {
|
|
392
394
|
const slot = this.dom.querySelector ('slot');
|
|
393
|
-
const currentContent = this.innerHTML;
|
|
394
395
|
|
|
395
396
|
if (typeof html === 'string') {
|
|
396
397
|
html = html.trim ();
|
|
@@ -408,7 +409,10 @@ export class Component extends HTMLElement {
|
|
|
408
409
|
slot.replaceWith (html);
|
|
409
410
|
} else {
|
|
410
411
|
this.innerHTML = html;
|
|
411
|
-
|
|
412
|
+
|
|
413
|
+
if (this._children !== '' && html.indexOf(this._children) === -1) {
|
|
414
|
+
this.innerHTML += this._children;
|
|
415
|
+
}
|
|
412
416
|
}
|
|
413
417
|
});
|
|
414
418
|
}
|
|
@@ -442,6 +446,7 @@ export class Component extends HTMLElement {
|
|
|
442
446
|
|
|
443
447
|
// Start the Mount Cycle
|
|
444
448
|
return this.willMount ().then (() => {
|
|
449
|
+
|
|
445
450
|
return this._render ().then (() => {
|
|
446
451
|
return this.didMount ().then (() => {
|
|
447
452
|
|
package/src/Registry.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
1
2
|
import { Component } from './Component';
|
|
2
3
|
|
|
3
4
|
export class Registry {
|
|
@@ -10,7 +11,7 @@ export class Registry {
|
|
|
10
11
|
|
|
11
12
|
const components = this.components;
|
|
12
13
|
window.customElements.define (tag, new Proxy (Component, {
|
|
13
|
-
getPrototypeOf(target) {
|
|
14
|
+
getPrototypeOf (target) {
|
|
14
15
|
return Reflect.getPrototypeOf (target);
|
|
15
16
|
},
|
|
16
17
|
getOwnPropertyDescriptor (target, propertyKey) {
|
package/src/ShadowComponent.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Component } from './Component';
|
|
2
|
-
import { callAsync } from './Util';
|
|
2
|
+
import { callAsync, deserializeCSS } from './Util';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @class ShadowComponent
|
|
6
|
+
*/
|
|
4
7
|
export class ShadowComponent extends Component {
|
|
5
8
|
constructor (...props) {
|
|
6
9
|
super (...props);
|
|
@@ -8,10 +11,31 @@ export class ShadowComponent extends Component {
|
|
|
8
11
|
this._shadowDOM = this.attachShadow ({ mode: 'open' });
|
|
9
12
|
}
|
|
10
13
|
|
|
14
|
+
setStyle (style, reset = false) {
|
|
15
|
+
this._createStyleElement ();
|
|
16
|
+
|
|
17
|
+
if (typeof style === 'object') {
|
|
18
|
+
if (reset === false) {
|
|
19
|
+
this._style = Object.assign ({}, this._style, style);
|
|
20
|
+
} else {
|
|
21
|
+
this._style = Object.assign ({}, style);
|
|
22
|
+
}
|
|
23
|
+
this._styleElement.innerHTML = deserializeCSS (this._style);
|
|
24
|
+
} else if (typeof style === 'string') {
|
|
25
|
+
if (reset === false) {
|
|
26
|
+
this._styleElement.innerHTML += style;
|
|
27
|
+
} else {
|
|
28
|
+
this._styleElement.innerHTML = style;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return this._style;
|
|
33
|
+
}
|
|
34
|
+
|
|
11
35
|
_createStyleElement () {
|
|
12
36
|
if (!(this._styleElement instanceof HTMLStyleElement)) {
|
|
13
37
|
this._styleElement = document.createElement ('style');
|
|
14
|
-
this.dom.
|
|
38
|
+
this.dom.prepend (this._styleElement);
|
|
15
39
|
}
|
|
16
40
|
}
|
|
17
41
|
|
|
@@ -29,7 +53,9 @@ export class ShadowComponent extends Component {
|
|
|
29
53
|
// component.
|
|
30
54
|
return callAsync (render, this).then ((html) => {
|
|
31
55
|
this._shadowDOM.innerHTML = '';
|
|
32
|
-
|
|
56
|
+
if (this._styleElement instanceof HTMLStyleElement) {
|
|
57
|
+
this._shadowDOM.appendChild (this._styleElement);
|
|
58
|
+
}
|
|
33
59
|
this._shadowDOM.innerHTML += html;
|
|
34
60
|
});
|
|
35
61
|
}
|
package/src/Util.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {*} callable
|
|
4
|
+
* @param {*} context
|
|
5
|
+
* @param {...any} args
|
|
6
|
+
*/
|
|
1
7
|
export function callAsync (callable, context, ...args) {
|
|
2
8
|
try {
|
|
3
9
|
// Call the provided function using the context and arguments given
|
|
@@ -14,6 +20,12 @@ export function callAsync (callable, context, ...args) {
|
|
|
14
20
|
}
|
|
15
21
|
}
|
|
16
22
|
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param {*} object
|
|
26
|
+
* @param {*} encapsulation
|
|
27
|
+
* @param {*} level
|
|
28
|
+
*/
|
|
17
29
|
export function deserializeCSS (object, encapsulation = '', level = 0, ) {
|
|
18
30
|
const keys = Object.keys (object);
|
|
19
31
|
|
|
@@ -21,7 +33,7 @@ export function deserializeCSS (object, encapsulation = '', level = 0, ) {
|
|
|
21
33
|
|
|
22
34
|
for (const key of keys) {
|
|
23
35
|
if (typeof object[key] === 'object') {
|
|
24
|
-
if (encapsulation) {
|
|
36
|
+
if (encapsulation && key.indexOf ('@') !== 0) {
|
|
25
37
|
if (key.indexOf ('&') === 0) {
|
|
26
38
|
css += `${key.replace(/&/g, encapsulation)} {\n`;
|
|
27
39
|
} else {
|