UNPKG

@arcgis/map-components

Version:
119 lines (118 loc) 5.65 kB
import { proxyExports as w, watch as r, trackPropKey as f } from "@arcgis/components-controllers"; import { AccessorController as p, accessorSupport as a } from "@arcgis/components-controllers/accessor"; import { a as l } from "./component-utils.js"; /*! All material copyright Esri, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. v4.32.13 */ const P = (d, s) => (i, e) => _(i, d, e); class y extends p { constructor(s, i, e) { super(s, i, e), this._watchedViewModelProperties = /* @__PURE__ */ new Map(), this._watchedVisibleElementsProperties = {}, this._isBindingViewModel = { value: !0 }, Object.defineProperty(this.exports, "viewModel", { value: a.makeGetterProxy(s, this._watchedViewModelProperties, this._isBindingViewModel) }), Object.defineProperty(this.exports, "visibleElements", { value: this._makeVisibleElementsBinder() }); } hostConnected() { super.hostConnected(), this._isBindingViewModel.value = !1, this.component.manager.loadedCalled && l(this.component); } async hostLoad() { if (this._watchedProperties.delete("viewModel"), await super.hostLoad(), this.component.manager.destroyed) return; this._watchMetaProperties(), this.onLifecycle(() => this.reactiveUtils.watch(() => this._instance.viewModel, (e) => { this.component.viewModel = e; }, { initial: !0 })); const s = this._instance.viewModel; typeof s == "object" && (a.watchComponentUpdates(this, s, this._watchedViewModelProperties), a.watchAccessorUpdates(this, s, this._watchedViewModelProperties)); const i = Object.entries(this._watchedVisibleElementsProperties); i.length > 0 && this.onLifecycle(() => i.map(([e, t]) => { let n = this._instance.visibleElements ?? {}, o; for (const c of t.slice(0, -1)) if (typeof n[c] == "object" && n[c] !== null) n = n[c]; else { o = !!n[c]; break; } o === void 0 && (o = !!(n[t.slice(-1)[0]] ?? !0)), e.startsWith("hide"); const m = e.startsWith("hide") || e.startsWith("show") ? e.startsWith("hide") : o, h = this.component; return typeof h[e] == "boolean" ? this._updateWidgetVisibleElement(t, h[e], m) : h[e] = !1, r(this.component, e, (c) => this._updateWidgetVisibleElement(t, c, m)); })); } _updateWidgetVisibleElement(s, i, e) { let t = this._instance.visibleElements ?? {}; for (const o of s.slice(0, -1)) (typeof t[o] != "object" || t[o] === null) && (t[o] = {}), t = t[o]; const n = !!(e ? !i : i); t[s.at(-1)] = n; } hostLoaded() { const { el: s } = this.component; s.childElem ??= document.createElement("div"), this._instance.container = s.childElem; let i = !1; const e = this.component.el.view; Object.defineProperty(this.component.el, "view", { get: () => this._instance.view ?? this._instance.viewModel?.view, set: (t) => { !("view" in this._instance) && typeof this._instance.viewModel == "object" ? this._instance.viewModel.view = t : this._instance.view = t, !("map" in this._instance) && typeof this._instance.viewModel == "object" ? this._instance.viewModel.map = t.map : this._instance.map = t.map, this._watchViewDestroy(), t && !i && (i = !0, this.component.arcgisReady.emit()); }, configurable: !0, enumerable: !0 }), e && (this._instance.view = e), this.component.el.isConnected && (l(this.component), this._watchViewDestroy()); } hostDisconnected() { typeof this.component.el.childElem == "object" && this.component.el.view?.ui?.remove(this.component.el.childElem); } hostDestroy() { super.hostDestroy(), this._watchViewDestroyHandle?.remove(); } _watchMetaProperties() { r(this.component, "position", (s) => { this.component.el.childElem != null && typeof s == "string" && l(this.component); }), r(this.component, "referenceElement", () => l(this.component)); } _makeVisibleElementsBinder() { return new Proxy({}, { has: (s, i) => typeof i == "string" || Reflect.has(s, i), get: (s, i) => { if (typeof i == "symbol" || i in Promise.prototype) return Reflect.get(s, i); const e = [i], t = this._makeRecursiveProxy(e); return f(this.component, (n) => { const o = n; this.component[o] = !1, this._watchedVisibleElementsProperties[o] = e; }, t); } }); } _makeRecursiveProxy(s) { const i = new Proxy({}, { get: (e, t) => { const n = Reflect.get(e, t); return typeof t == "symbol" || t in Promise.prototype ? n : (s.push(t), i); } }); return i; } /** * Destroy the component if view gets destroyed. * * When view is destroyed, component disconnect is triggered, which will * destroy the component in 1s but that can be too late, because in the * meanwhile, a watcher on the widget/viewModel instance may get triggered, * and throw an error if it's not able to access this.view.map or etc * (happens in VersionManagementViewModel for example). * * We can't check for this in disconnectedCallback though as, if the entire * component tree is removed, the disconnect for the component will be * triggered before that of arcgis-map, so the view might not be destroyed * yet at that point. */ _watchViewDestroy() { this._watchViewDestroyHandle?.remove(), this._watchViewDestroyHandle = this.reactiveUtils.when(() => this.component.el.view?.destroyed === !0, () => void this.component.destroy().catch(console.error), { sync: !0 }); } } const _ = w(y); export { P as m };