@aegenet/au2-base-component
Version:
Aurelia 2 - Base Component
414 lines (413 loc) • 17.2 kB
JavaScript
var Pe = Object.defineProperty;
var Ce = (t, e, r) => e in t ? Pe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
var u = (t, e, r) => Ce(t, typeof e != "symbol" ? e + "" : e, r);
import { DI as re, bindable as O, IAuSlotsInfo as Oe, IEventAggregator as j, IPlatform as ie, inject as Q, IContainer as se, Registration as W, customElement as xe } from "aurelia";
import { I18N as k } from "@aurelia/i18n";
import { disposeAntiBounces as ae } from "@aegenet/belt-anti-bounce";
import { IRouter as X } from "@aurelia/router";
const U = re.createInterface("au2.aware-component-service"), K = re.createInterface("au2.store-service");
var ze = Object.create, Ae = Object.defineProperty, ke = (t, e) => (e = Symbol[t]) ? e : Symbol.for("Symbol." + t), ne = (t) => {
throw TypeError(t);
}, oe = (t, e, r) => e in t ? Ae(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, Ee = (t) => [, , , ze(null)], Fe = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], _e = (t) => t !== void 0 && typeof t != "function" ? ne("Function expected") : t, De = (t, e, r, s, i) => ({ kind: Fe[t], name: e, metadata: s, addInitializer: (a) => r._ ? ne("Already initialized") : i.push(_e(a || null)) }), Te = (t, e) => oe(e, ke("metadata"), t[3]), y = (t, e, r, s) => {
for (var i = 0, a = t[e >> 1], o = a && a.length; i < o; i++) e & 1 ? a[i].call(r) : s = a[i].call(r, s);
return s;
}, H = (t, e, r, s, i, a) => {
var o, c, d, h, b = e & 7, n = !!(e & 8), w = !!(e & 16), _ = t.length + 1, v = t[_ - 1] = [], A = t[_] || (t[_] = []);
i = i.prototype, b < 5;
for (var I = s.length - 1; I >= 0; I--)
d = De(b, r, c = {}, t[3], A), d.static = n, d.private = w, h = d.access = { has: (m) => r in m }, h.get = (m) => m[r], h.set = (m, p) => m[r] = p, o = (0, s[I])(void 0, d), c._ = 1, _e(o) && v.unshift(o);
return i;
}, l = (t, e, r) => oe(t, typeof e != "symbol" ? e + "" : e, r), ce, he, le, g;
le = [O()], he = [O()], ce = [O()];
const N = class ue {
constructor(e, r) {
this._element = e, this._container = r, l(this, "$antiBounces"), l(this, "_auSlotInfo"), l(this, "_ea"), l(this, "_aware"), l(this, "_platform"), l(this, "_store"), l(this, "i18n"), l(this, "uid"), l(this, "eventName", y(g, 8, this)), y(g, 11, this), l(this, "_isInit"), l(this, "slots", {}), l(this, "auSlots", {}), l(this, "auSlotNames"), l(this, "slotNames", []), l(this, "lastError"), l(this, "isBusy"), l(this, "embedData", y(g, 12, this)), y(g, 15, this), l(this, "changed", y(g, 16, this)), y(g, 19, this), this.uid = `au2-comp-${ue._COUNTER++}`, this._auSlotInfo = this._container.get(Oe), this._ea = this._container.get(j), this._aware = this._container.get(U), this._platform = this._container.get(ie), this._store = this._container.get(K), this._container.has(k, !0) ? this.i18n = this._container.get(k) : console.debug("I18N cannot be used without right configuration.");
}
/**
* On attached we refresh slots and au-slots objects, subscribe to aware service,
* then we call the protected `_init()` method
*/
async attached() {
try {
this._refreshSlots(), this.isBusy = !0, this._aware.subscribe(this), await Promise.resolve(this._init()), this._isInit = !0;
} finally {
this.isBusy = !1;
}
}
/**
* Detaching
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
detaching(e, r) {
this._aware.unsubscribe(this);
}
/**
* Custom logic (after attached)
*/
_init() {
}
/** Custom logic (after detaching and unbinding, before dispose) */
_deinit() {
}
/**
* Refresh slots and au-slots
*/
_refreshSlots() {
if (this.auSlotNames = this._auSlotInfo.projectedSlots, this.auSlots = {}, this.slots = {}, this.auSlotNames.length && this.auSlotNames.forEach((e) => {
this.auSlots[e] = !0;
}), this._element) {
const e = this._element.children ? Array.from(this._element.children) : [], r = [];
let s;
for (let i = 0; i < e.length; i++)
(s = e[i]) && s.slot && (this.slots[s.slot] = s, r.push(s.slot));
this.slotNames = r;
}
}
/**
* Unbinding
*/
async unbinding() {
this.slots = {}, this.slotNames = [], this.auSlots = {}, this.auSlotNames = [], ae(this), this._isInit = !1, await Promise.resolve(this._deinit());
}
/**
* TaskQueue
* @remark Can be used to rugged SSR
* @core
*/
get taskQueue() {
return this._platform.taskQueue;
}
/**
* Event aggregator
* @service
* @core
*/
get ea() {
return this._ea;
}
};
g = Ee();
H(g, 5, "eventName", le, N);
H(g, 5, "embedData", he, N);
H(g, 5, "changed", ce, N);
Te(g, N);
l(N, "_COUNTER", 1);
let Be = N;
class $t {
constructor(e) {
/**
* Instances of anti-bounce
* @remark Don't edit manually
*
* @private
* @core
*/
u(this, "$antiBounces");
/**
* Event aggregator
* @service
* @core
*/
u(this, "_ea");
/**
* Specify a special name for this instance
*
* "Je suis spécial !"
*/
u(this, "eventName");
/**
* Aware Service
* @service
* @core
*/
u(this, "_aware");
/**
* StoreService
* @service
* @core
*/
u(this, "_store");
/**
* i18n
* @service
* @core
*/
u(this, "i18n");
/** Router */
u(this, "_router");
/**
* Platform
* @service
* @core
*/
u(this, "_platform");
/**
* Has been init? (attached & _init())
* @core
*/
u(this, "_isInit");
/**
* Last error message
* @core
*/
u(this, "lastError");
this._container = e, this._ea = this._container.get(j), this._platform = this._container.get(ie), this._aware = this._container.get(U), this._store = this._container.get(K), this._container.has(k, !0) ? this.i18n = this._container.get(k) : console.debug("I18N cannot be used without the right configuration."), this._container.has(X, !0) ? this._router = this._container.get(X) : console.debug("Router cannot be used without the right configuration.");
}
async loading(e, r, s) {
this._aware.subscribe(this), await Promise.resolve(this._init(e, r, s)), this._isInit = !0;
}
/**
* Custom logic (on loading)
*/
_init(e, r, s) {
}
/** Custom logic (on unloading) */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_deinit(e, r) {
}
/** Unload the page */
async unloading(e, r) {
ae(this), this._aware.unsubscribe(this), this._isInit = !1, await Promise.resolve(this._deinit(e, r));
}
/**
* TaskQueue
* @remark Can be used to rugged SSR
* @core
*/
get taskQueue() {
return this._platform.taskQueue;
}
/**
* Event aggregator
* @service
* @core
*/
get ea() {
return this._ea;
}
/** Router */
get router() {
return this._router;
}
}
var je = Object.create, Y = Object.defineProperty, Qe = Object.getOwnPropertyDescriptor, Ue = (t, e) => (e = Symbol[t]) ? e : Symbol.for("Symbol." + t), de = (t) => {
throw TypeError(t);
}, Ke = (t, e, r) => e in t ? Y(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, He = (t, e) => Y(t, "name", { value: e, configurable: !0 }), Ye = (t) => [, , , je(null)], Ge = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], ve = (t) => t !== void 0 && typeof t != "function" ? de("Function expected") : t, qe = (t, e, r, s, i) => ({ kind: Ge[t], name: e, metadata: s, addInitializer: (a) => r._ ? de("Already initialized") : i.push(ve(a || null)) }), Je = (t, e) => Ke(e, Ue("metadata"), t[3]), Le = (t, e, r, s) => {
for (var i = 0, a = t[e >> 1], o = a && a.length; i < o; i++) a[i].call(r);
return s;
}, Re = (t, e, r, s, i, a) => {
var o, c, d, h = e & 7, b = !!(e & 16), n = 0, w = t[n] || (t[n] = []), _ = h && (i = i.prototype, h < 5 && (h > 3 || !b) && Qe(i, r));
He(i, r);
for (var v = s.length - 1; v >= 0; v--)
d = qe(h, r, c = {}, t[3], w), o = (0, s[v])(i, d), c._ = 1, ve(o) && (i = o);
return Je(t, i), _ && Y(i, r, _), b ? h ^ 4 ? a : _ : i;
}, pe, G;
pe = [Q(j)];
var S;
let E = (S = class {
constructor(e) {
this._ev = e;
}
/**
* @inheritdoc
*/
subscribe(e) {
var r;
if (e.eventName && ((r = e.$controller) != null && r.definition)) {
const s = e.$controller.definition;
if (s.name) {
const i = e.eventName.indexOf(":") !== -1 ? e.eventName : `${s.name}:${e.eventName}`;
e.$awareToken = this._ev.subscribe(i, (a) => {
this.publish(e, a);
});
}
}
}
/**
* @inheritdoc
*/
publish(e, r) {
if (r != null && r.property && S._RE_PROPERTY_CHECK.test(r.property) && r.property in e) {
const s = Object.getOwnPropertyDescriptor(e, r.property);
s ? s.set || s.get ? s.set && (e[r.property] = r.value) : s.value instanceof Function ? s.value.apply(e, r.value) : e[r.property] = r.value : e[r.property] instanceof Function && e[r.property].apply(
e,
r.value
);
}
}
/**
* @inheritdoc
*/
unsubscribe(e) {
e.$awareToken && (e.$awareToken.dispose(), e.$awareToken = void 0);
}
}, u(S, "_RE_PROPERTY_CHECK", /^[a-z]/i), S);
G = Ye();
E = Re(G, 0, "AwareComponentService", pe, E);
Le(G, 1, E);
let Ve = E;
var We = Object.create, q = Object.defineProperty, Xe = Object.getOwnPropertyDescriptor, Ze = (t, e) => (e = Symbol[t]) ? e : Symbol.for("Symbol." + t), fe = (t) => {
throw TypeError(t);
}, Me = (t, e, r) => e in t ? q(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, et = (t, e) => q(t, "name", { value: e, configurable: !0 }), tt = (t) => [, , , We(null)], rt = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], be = (t) => t !== void 0 && typeof t != "function" ? fe("Function expected") : t, it = (t, e, r, s, i) => ({ kind: rt[t], name: e, metadata: s, addInitializer: (a) => r._ ? fe("Already initialized") : i.push(be(a || null)) }), st = (t, e) => Me(e, Ze("metadata"), t[3]), at = (t, e, r, s) => {
for (var i = 0, a = t[e >> 1], o = a && a.length; i < o; i++) a[i].call(r);
return s;
}, nt = (t, e, r, s, i, a) => {
var o, c, d, h = e & 7, b = !!(e & 16), n = 0, w = t[n] || (t[n] = []), _ = h && (i = i.prototype, h < 5 && (h > 3 || !b) && Xe(i, r));
et(i, r);
for (var v = s.length - 1; v >= 0; v--)
d = it(h, r, c = {}, t[3], w), o = (0, s[v])(i, d), c._ = 1, be(o) && (i = o);
return st(t, i), _ && q(i, r, _), b ? h ^ 4 ? a : _ : i;
}, ge, J;
ge = [Q(se)];
class F {
constructor(e) {
u(this, "_isInit", !1);
u(this, "_store", /* @__PURE__ */ new Map());
u(this, "_tokens", []);
u(this, "_channel", "au2.store-service");
u(this, "_ev");
this._container = e;
}
/** Initialize */
initialize(e = {}) {
this._isInit || (e.channel && (this._channel = e.channel), e.eventAggregator && (this._ev = e.eventAggregator), this._ev && this._tokens.push(
this._ev.subscribe(`${this._channel}:set`, async (r) => {
await this.setStore(r);
}),
this._ev.subscribe(`${this._channel}:get`, async (r) => this.getStore(r.key)),
this._ev.subscribe(`${this._channel}:del`, async (r) => {
await this.delStore(r.key);
}),
this._ev.subscribe(`${this._channel}:refresh`, async (r) => {
await this.refreshStore(r.key);
})
), this._isInit = !0);
}
/** Dispose */
dispose() {
var e;
(e = this._tokens) == null || e.forEach((r) => r.dispose()), this._tokens = [], this._isInit = !1, this._store.clear();
}
/** Set data/load on Store */
setStore(...e) {
e == null || e.forEach((r) => {
this._store.set(r.key, r);
});
}
/** Delete data/load from Store */
delStore(e) {
this._store.delete(e);
}
/** Get data from Store */
async getStore(e) {
var s;
const r = this._store.get(e);
if (!r)
throw new Error(`Unknown store was provided: ${String(e)}`);
return !r.data && r.load && (r.data = await r.load(this._container), (s = this._ev) == null || s.publish(`${this._channel}:loaded`, {
key: e,
data: r.data
})), r.data;
}
/** Refresh data from Store */
async refreshStore(e) {
var s;
const r = this._store.get(e);
if (!r)
throw new Error(`Unknown store was provided: ${String(e)}`);
r.load && (r.data = await r.load(this._container), (s = this._ev) == null || s.publish(`${this._channel}:loaded`, {
key: e,
data: r.data
}));
}
}
J = tt();
F = nt(J, 0, "StoreService", ge, F);
at(J, 1, F);
function mt() {
return {
register: (t) => {
t.register(W.singleton(U, Ve)), t.register(W.singleton(K, F));
}
};
}
var ot = Object.create, L = Object.defineProperty, _t = Object.getOwnPropertyDescriptor, we = (t, e) => (e = Symbol[t]) ? e : Symbol.for("Symbol." + t), z = (t) => {
throw TypeError(t);
}, $e = (t, e, r) => e in t ? L(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, Z = (t, e) => L(t, "name", { value: e, configurable: !0 }), ct = (t) => [, , , ot((t == null ? void 0 : t[we("metadata")]) ?? null)], me = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], P = (t) => t !== void 0 && typeof t != "function" ? z("Function expected") : t, ht = (t, e, r, s, i) => ({ kind: me[t], name: e, metadata: s, addInitializer: (a) => r._ ? z("Already initialized") : i.push(P(a || null)) }), lt = (t, e) => $e(e, we("metadata"), t[3]), C = (t, e, r, s) => {
for (var i = 0, a = t[e >> 1], o = a && a.length; i < o; i++) e & 1 ? a[i].call(r) : s = a[i].call(r, s);
return s;
}, R = (t, e, r, s, i, a) => {
var o, c, d, h, b, n = e & 7, w = !!(e & 8), _ = !!(e & 16), v = n > 3 ? t.length + 1 : n ? w ? 1 : 2 : 0, A = me[n + 5], I = n > 3 && (t[v - 1] = []), m = t[v] || (t[v] = []), p = n && (!_ && !w && (i = i.prototype), n < 5 && (n > 3 || !_) && _t(n < 4 ? i : { get [r]() {
return ee(this, a);
}, set [r](f) {
return te(this, a, f);
} }, r));
n ? _ && n < 4 && Z(a, (n > 2 ? "set " : n > 1 ? "get " : "") + r) : Z(i, r);
for (var D = s.length - 1; D >= 0; D--)
h = ht(n, r, d = {}, t[3], m), n && (h.static = w, h.private = _, b = h.access = { has: _ ? (f) => ut(i, f) : (f) => r in f }, n ^ 3 && (b.get = _ ? (f) => (n ^ 1 ? ee : dt)(f, i, n ^ 4 ? a : p.get) : (f) => f[r]), n > 2 && (b.set = _ ? (f, T) => te(f, i, T, n ^ 4 ? a : p.set) : (f, T) => f[r] = T)), c = (0, s[D])(n ? n < 4 ? _ ? a : p[A] : n > 4 ? void 0 : { get: p.get, set: p.set } : i, h), d._ = 1, n ^ 4 || c === void 0 ? P(c) && (n > 4 ? I.unshift(c) : n ? _ ? a = c : p[A] = c : i = c) : typeof c != "object" || c === null ? z("Object expected") : (P(o = c.get) && (p.get = o), P(o = c.set) && (p.set = o), P(o = c.init) && I.unshift(o));
return n || lt(t, i), p && L(i, r, p), _ ? n ^ 4 ? a : p : i;
}, M = (t, e, r) => $e(t, typeof e != "symbol" ? e + "" : e, r), V = (t, e, r) => e.has(t) || z("Cannot " + r), ut = (t, e) => Object(e) !== e ? z('Cannot use the "in" operator on this value') : t.has(e), ee = (t, e, r) => (V(t, e, "read from private field"), r ? r.call(t) : e.get(t)), te = (t, e, r, s) => (V(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r), dt = (t, e, r) => (V(t, e, "access private method"), r), Se, Ie, B, ye, $;
ye = [xe({
name: "aware-component"
}), Q(Element, se)];
class x extends (B = Be, Ie = [O()], Se = [O()], B) {
constructor(e, r) {
super(e, r), M(this, "events", C($, 8, this, [])), C($, 11, this), M(this, "next", C($, 12, this)), C($, 15, this);
}
/** Publish the event */
async publish() {
if (this.events)
for (let e = 0; e < this.events.length; e++)
this._ea.publish(this.events[e].name, this.events[e].options);
this.next && await this.next(this);
}
}
$ = ct(B);
R($, 5, "events", Ie, x);
R($, 5, "next", Se, x);
x = R($, 0, "AwareComponent", ye, x);
C($, 1, x);
var Ne = /* @__PURE__ */ ((t) => (t[t.instance = 0] = "instance", t[t.singleton = 1] = "singleton", t[t.transient = 2] = "transient", t[t.callback = 3] = "callback", t[t.array = 4] = "array", t[t.alias = 5] = "alias", t))(Ne || {});
function St(t) {
var i;
const e = {
instance: [],
singleton: [],
transient: [],
callback: [],
array: [],
alias: []
};
if (t == null)
return e;
const r = "$", s = "h";
for (const [a, o] of ((i = t[s]) == null ? void 0 : i.entries()) || [])
o[r] != null && e[Ne[o[r]]].push({
[vt(a) || "unknown"]: {
resolving: o.resolving ?? !1,
current: o._state
// value.C === 0 ?? true ? container.get(key) : null,
}
});
return e;
}
function vt(t) {
return typeof t == "string" ? t : t.friendlyName || t.toString();
}
function It(t) {
return t !== "view-model" && t !== "component" && t !== "ref";
}
export {
x as AwareComponent,
Ve as AwareComponentService,
Be as BaseComponent,
$t as BasePage,
U as DIAwareComponentService,
K as DIStoreService,
Ne as ResolverStrategyMap,
F as StoreService,
St as debugContainer,
It as defaultCapture,
mt as register
};
//# sourceMappingURL=index.mjs.map