@lordfokas/yrframe 0.1.2 → 0.2.0
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/dist/Component.d.ts
CHANGED
|
@@ -5,8 +5,12 @@ export declare class Component<A extends Attributes> extends HTMLElement {
|
|
|
5
5
|
/** Attribute Event Qualifier chars. Attributes starting with this are special. */
|
|
6
6
|
static readonly AEQ = "yr:";
|
|
7
7
|
readonly [evt]: ComponentEvents;
|
|
8
|
+
protected initialChildren: (string | Node)[];
|
|
9
|
+
private wasConnected;
|
|
8
10
|
protected events(): ComponentEvents;
|
|
9
11
|
constructor(props: Partial<A>, defaults?: Partial<A>);
|
|
12
|
+
/** Override HTMLElement */
|
|
13
|
+
append(...nodes: (string | Node)[]): void;
|
|
10
14
|
/** Remove all children nodes. */
|
|
11
15
|
clearChildren(): void;
|
|
12
16
|
isDisabled(): boolean;
|
|
@@ -15,7 +19,7 @@ export declare class Component<A extends Attributes> extends HTMLElement {
|
|
|
15
19
|
/** HTML5 Custom Element lifecycle callback (add to page) */
|
|
16
20
|
connectedCallback(): void;
|
|
17
21
|
/** Draw this component's internals. Should return only children nodes. */
|
|
18
|
-
render():
|
|
22
|
+
render(): Node | string | (Node | string)[] | null;
|
|
19
23
|
/** Redraw this component. Works by deleting all children, calling render() and appending the results. */
|
|
20
24
|
redraw(): void;
|
|
21
25
|
/** Called after redraw() to do special manipulation of children nodes. */
|
package/dist/Component.js
CHANGED
|
@@ -5,6 +5,8 @@ export class Component extends HTMLElement {
|
|
|
5
5
|
/** Attribute Event Qualifier chars. Attributes starting with this are special. */
|
|
6
6
|
static AEQ = 'yr:';
|
|
7
7
|
[evt];
|
|
8
|
+
initialChildren = [];
|
|
9
|
+
wasConnected = false;
|
|
8
10
|
events() {
|
|
9
11
|
return this[evt];
|
|
10
12
|
}
|
|
@@ -25,6 +27,13 @@ export class Component extends HTMLElement {
|
|
|
25
27
|
}
|
|
26
28
|
ComponentFactory.setAttributesAndEvents(this, attrs);
|
|
27
29
|
}
|
|
30
|
+
/** Override HTMLElement */
|
|
31
|
+
append(...nodes) {
|
|
32
|
+
if (!this.wasConnected) {
|
|
33
|
+
this.initialChildren.push(...nodes);
|
|
34
|
+
}
|
|
35
|
+
super.append(...nodes);
|
|
36
|
+
}
|
|
28
37
|
/** Remove all children nodes. */
|
|
29
38
|
clearChildren() {
|
|
30
39
|
this.innerHTML = "";
|
|
@@ -38,21 +47,24 @@ export class Component extends HTMLElement {
|
|
|
38
47
|
}
|
|
39
48
|
/** HTML5 Custom Element lifecycle callback (add to page) */
|
|
40
49
|
connectedCallback() {
|
|
50
|
+
this.wasConnected = true;
|
|
41
51
|
this[evt].connect();
|
|
42
52
|
this.redraw();
|
|
43
53
|
}
|
|
44
54
|
/** Draw this component's internals. Should return only children nodes. */
|
|
45
|
-
render() {
|
|
55
|
+
render() {
|
|
56
|
+
return this.initialChildren;
|
|
57
|
+
}
|
|
46
58
|
/** Redraw this component. Works by deleting all children, calling render() and appending the results. */
|
|
47
59
|
redraw() {
|
|
48
60
|
const child = this.render();
|
|
49
61
|
this.clearChildren();
|
|
50
62
|
if (child) {
|
|
51
63
|
if (Array.isArray(child)) {
|
|
52
|
-
ComponentFactory.appendChildren(this, child);
|
|
64
|
+
ComponentFactory.appendChildren(this, ...child);
|
|
53
65
|
}
|
|
54
66
|
else {
|
|
55
|
-
ComponentFactory.appendChildren(this,
|
|
67
|
+
ComponentFactory.appendChildren(this, child);
|
|
56
68
|
}
|
|
57
69
|
}
|
|
58
70
|
this.inject();
|
package/dist/ComponentEvents.js
CHANGED
|
@@ -138,7 +138,7 @@ export class ComponentEvents {
|
|
|
138
138
|
if (!this.sources[name])
|
|
139
139
|
callback.call(this.component, undefined, undefined);
|
|
140
140
|
else
|
|
141
|
-
this.sources[name].call(callback);
|
|
141
|
+
this.sources[name].call(undefined, callback);
|
|
142
142
|
}
|
|
143
143
|
/** Create a function that will fire an event to export data. */
|
|
144
144
|
attachTrigger(target, name, optional) {
|
|
@@ -10,7 +10,7 @@ export declare class ComponentFactory {
|
|
|
10
10
|
/** Apply vanilla HTML attributes and event callback functions. There is no component level logic here. */
|
|
11
11
|
static setAttributesAndEvents(element: HTMLElement, props: any): void;
|
|
12
12
|
/** Logic for appending children to a parent element according to the possible returns of render() */
|
|
13
|
-
static appendChildren(element: HTMLElement, children:
|
|
13
|
+
static appendChildren(element: HTMLElement, ...children: (string | Node)[]): void;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* ## Here be Shenanigans
|
package/dist/ComponentFactory.js
CHANGED
|
@@ -23,7 +23,7 @@ export class ComponentFactory {
|
|
|
23
23
|
}
|
|
24
24
|
// Append children if any
|
|
25
25
|
if (children && children.length > 0) {
|
|
26
|
-
this.appendChildren(element, children);
|
|
26
|
+
this.appendChildren(element, ...children);
|
|
27
27
|
}
|
|
28
28
|
return element;
|
|
29
29
|
}
|
|
@@ -43,7 +43,7 @@ export class ComponentFactory {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
/** Logic for appending children to a parent element according to the possible returns of render() */
|
|
46
|
-
static appendChildren(element, children) {
|
|
46
|
+
static appendChildren(element, ...children) {
|
|
47
47
|
for (const child of children) {
|
|
48
48
|
// Allow returning null from render() when there is nothing to do
|
|
49
49
|
if (child === null)
|