@lordfokas/yrframe 0.4.0 → 0.4.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/dist/Component.d.ts +0 -2
- package/dist/Component.js +2 -3
- package/dist/ComponentEvents.js +2 -1
- package/dist/ComponentFactory.js +7 -13
- package/dist/Facade.d.ts +8 -2
- package/dist/Facade.js +19 -1
- package/package.json +1 -1
package/dist/Component.d.ts
CHANGED
|
@@ -2,8 +2,6 @@ import { ComponentEvents } from "./ComponentEvents.js";
|
|
|
2
2
|
import { Attributes } from "./utils.js";
|
|
3
3
|
declare const evt: unique symbol;
|
|
4
4
|
export declare class Component<A extends Attributes> extends HTMLElement {
|
|
5
|
-
/** Attribute Event Qualifier chars. Attributes starting with this are special. */
|
|
6
|
-
static readonly AEQ = "yr:";
|
|
7
5
|
readonly [evt]: ComponentEvents;
|
|
8
6
|
protected initialChildren: (string | Node)[];
|
|
9
7
|
private wasConnected;
|
package/dist/Component.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ComponentEvents } from "./ComponentEvents.js";
|
|
2
2
|
import { ComponentFactory } from "./ComponentFactory.js";
|
|
3
|
+
import { specialAttributes } from "./utils.js";
|
|
3
4
|
const evt = Symbol('evt');
|
|
4
5
|
export class Component extends HTMLElement {
|
|
5
|
-
/** Attribute Event Qualifier chars. Attributes starting with this are special. */
|
|
6
|
-
static AEQ = 'yr:';
|
|
7
6
|
[evt];
|
|
8
7
|
initialChildren = [];
|
|
9
8
|
wasConnected = false;
|
|
@@ -21,7 +20,7 @@ export class Component extends HTMLElement {
|
|
|
21
20
|
Object.assign(all, props);
|
|
22
21
|
const attrs = {};
|
|
23
22
|
for (const [k, v] of Object.entries(all)) {
|
|
24
|
-
if (!
|
|
23
|
+
if (!specialAttributes.test(k)) {
|
|
25
24
|
attrs[k] = v;
|
|
26
25
|
}
|
|
27
26
|
}
|
package/dist/ComponentEvents.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventBus, EventListener } from '@lordfokas/event-bus';
|
|
2
|
+
import { Component } from './Component.js';
|
|
2
3
|
class PersistentListener extends EventListener {
|
|
3
4
|
type;
|
|
4
5
|
constructor(type, callback, nice) {
|
|
@@ -21,7 +22,7 @@ export class ComponentEvents {
|
|
|
21
22
|
internals = 0;
|
|
22
23
|
constructor(component) {
|
|
23
24
|
this.component = component;
|
|
24
|
-
this.owner = component.constructor.name;
|
|
25
|
+
this.owner = component instanceof Component ? component.constructor.name : '<' + component.tagName + '>';
|
|
25
26
|
}
|
|
26
27
|
isEmpty() {
|
|
27
28
|
return (this.listeners.length + this.internals) === 0;
|
package/dist/ComponentFactory.js
CHANGED
|
@@ -44,20 +44,14 @@ export class ComponentFactory {
|
|
|
44
44
|
}
|
|
45
45
|
/** Logic for appending children to a parent element according to the possible returns of render() */
|
|
46
46
|
static appendChildren(element, ...children) {
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (child === undefined)
|
|
47
|
+
element.append(...(children
|
|
48
|
+
.flat(5) // flatten arrays of arrays up to depth=5 (should be enough, if you have more, fuck you)
|
|
49
|
+
.filter(c => c !== null) // ignore nulls
|
|
50
|
+
.map(c => {
|
|
51
|
+
if (c === undefined)
|
|
53
52
|
throw new Error("An element's child cannot be undefined");
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
element.append(child);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
53
|
+
return c; // accept anything else
|
|
54
|
+
})));
|
|
61
55
|
}
|
|
62
56
|
}
|
|
63
57
|
/**
|
package/dist/Facade.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ComponentEvents } from "./ComponentEvents.js";
|
|
|
2
2
|
import { Attributes, Source } from "./utils.js";
|
|
3
3
|
declare const evt: unique symbol;
|
|
4
4
|
interface EventHost {
|
|
5
|
-
[evt]:
|
|
5
|
+
[evt]: FacadeEvents;
|
|
6
6
|
}
|
|
7
7
|
type FacadeElement = HTMLElement & EventHost & {
|
|
8
8
|
connectedCallback: Source<void>;
|
|
@@ -15,8 +15,14 @@ type FacadeElement = HTMLElement & EventHost & {
|
|
|
15
15
|
export declare class Facade<A extends Attributes> {
|
|
16
16
|
protected readonly node: FacadeElement;
|
|
17
17
|
protected readonly isCustom: boolean;
|
|
18
|
-
protected events():
|
|
18
|
+
protected events(): FacadeEvents;
|
|
19
19
|
constructor(tag: string, props: Partial<A>, defaults?: Partial<A>);
|
|
20
20
|
content(): FacadeElement;
|
|
21
21
|
}
|
|
22
|
+
declare class FacadeEvents extends ComponentEvents {
|
|
23
|
+
private connected;
|
|
24
|
+
constructor(component: HTMLElement);
|
|
25
|
+
connect(): void;
|
|
26
|
+
disconnect(): void;
|
|
27
|
+
}
|
|
22
28
|
export {};
|
package/dist/Facade.js
CHANGED
|
@@ -11,7 +11,7 @@ export class Facade {
|
|
|
11
11
|
isCustom;
|
|
12
12
|
events() {
|
|
13
13
|
if (!this.node[evt]) { // Lazily instantiate event manager
|
|
14
|
-
this.node[evt] = new
|
|
14
|
+
this.node[evt] = new FacadeEvents(this.node);
|
|
15
15
|
}
|
|
16
16
|
return this.node[evt];
|
|
17
17
|
}
|
|
@@ -40,6 +40,24 @@ export class Facade {
|
|
|
40
40
|
return this.node;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
class FacadeEvents extends ComponentEvents {
|
|
44
|
+
connected = false;
|
|
45
|
+
constructor(component) {
|
|
46
|
+
super(component);
|
|
47
|
+
}
|
|
48
|
+
connect() {
|
|
49
|
+
if (this.connected)
|
|
50
|
+
return;
|
|
51
|
+
super.connect();
|
|
52
|
+
this.connected = true;
|
|
53
|
+
}
|
|
54
|
+
disconnect() {
|
|
55
|
+
if (!this.connected)
|
|
56
|
+
return;
|
|
57
|
+
super.disconnect();
|
|
58
|
+
this.connected = false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
43
61
|
(function FacadeMutationObserver() {
|
|
44
62
|
new MutationObserver((records, _mo) => {
|
|
45
63
|
for (const record of records) {
|