dap-design-system
Version:
Official design system for the DÁP (dap.gov.hu)
41 lines (40 loc) • 1.68 kB
JavaScript
import { ContextRequestEvent as x } from "../context-request-event.js";
import { ValueNotifier as u } from "../value-notifier.js";
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
class p extends Event {
constructor(n, e) {
super("context-provider", { bubbles: !0, composed: !0 }), this.context = n, this.contextTarget = e;
}
}
class b extends u {
constructor(n, e, d) {
var r, c;
super(e.context !== void 0 ? e.initialValue : d), this.onContextRequest = (t) => {
var o;
if (t.context !== this.context) return;
const s = (o = t.contextTarget) != null ? o : t.composedPath()[0];
s !== this.host && (t.stopPropagation(), this.addCallback(t.callback, s, t.subscribe));
}, this.onProviderRequest = (t) => {
var o;
if (t.context !== this.context || ((o = t.contextTarget) != null ? o : t.composedPath()[0]) === this.host) return;
const s = /* @__PURE__ */ new Set();
for (const [i, { consumerHost: h }] of this.subscriptions) s.has(i) || (s.add(i), h.dispatchEvent(new x(this.context, h, i, !0)));
t.stopPropagation();
}, this.host = n, e.context !== void 0 ? this.context = e.context : this.context = e, this.attachListeners(), (c = (r = this.host).addController) == null || c.call(r, this);
}
attachListeners() {
this.host.addEventListener("context-request", this.onContextRequest), this.host.addEventListener("context-provider", this.onProviderRequest);
}
hostConnected() {
this.host.dispatchEvent(new p(this.context, this.host));
}
}
export {
b as ContextProvider,
p as ContextProviderEvent
};
//# sourceMappingURL=context-provider.js.map