-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatalystcore.js
More file actions
76 lines (76 loc) · 3.01 KB
/
catalystcore.js
File metadata and controls
76 lines (76 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { register } from './register.js';
import { bind, bindShadow } from './bind.js';
import { autoShadowRoot } from './auto-shadow-root.js';
import { defineObservedAttributes, initializeAttrs } from './attr.js';
import { observe } from './lazy-define.js';
const symbol = Symbol.for('catalyst');
export class CatalystDelegate {
constructor(classObject) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const delegate = this;
const connectedCallback = classObject.prototype.connectedCallback;
classObject.prototype.connectedCallback = function () {
delegate.connectedCallback(this, connectedCallback);
};
const disconnectedCallback = classObject.prototype.disconnectedCallback;
classObject.prototype.disconnectedCallback = function () {
delegate.disconnectedCallback(this, disconnectedCallback);
};
const attributeChangedCallback = classObject.prototype.attributeChangedCallback;
classObject.prototype.attributeChangedCallback = function (name, oldValue, newValue) {
delegate.attributeChangedCallback(this, name, oldValue, newValue, attributeChangedCallback);
};
let observedAttributes = classObject.observedAttributes || [];
Object.defineProperty(classObject, 'observedAttributes', {
configurable: true,
get() {
return delegate.observedAttributes(this, observedAttributes);
},
set(attributes) {
observedAttributes = attributes;
}
});
defineObservedAttributes(classObject);
register(classObject);
}
observedAttributes(instance, observedAttributes) {
return observedAttributes;
}
connectedCallback(instance, connectedCallback) {
instance.toggleAttribute('data-catalyst', true);
customElements.upgrade(instance);
autoShadowRoot(instance);
initializeAttrs(instance);
bind(instance);
connectedCallback?.call(instance);
if (instance.shadowRoot) {
bindShadow(instance.shadowRoot);
observe(instance.shadowRoot);
}
}
disconnectedCallback(element, disconnectedCallback) {
disconnectedCallback?.call(element);
}
attributeChangedCallback(instance, name, oldValue, newValue, attributeChangedCallback) {
initializeAttrs(instance);
if (name !== 'data-catalyst' && attributeChangedCallback) {
attributeChangedCallback.call(instance, name, oldValue, newValue);
}
}
}
export function meta(proto, name) {
if (!Object.prototype.hasOwnProperty.call(proto, symbol)) {
const parent = proto[symbol];
const map = (proto[symbol] = new Map());
if (parent) {
for (const [key, value] of parent) {
map.set(key, new Set(value));
}
}
}
const map = proto[symbol];
if (!map.has(name))
map.set(name, new Set());
return map.get(name);
}
//# sourceMappingURL=core.js.map