UNPKG

@arcgis/map-components

Version:
5 lines (4 loc) 4.07 kB
/*! 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 */ import{c as y,e as g,h as S,i as M,k as C,l as $,m as L,n as R,o as h}from"./NIZJVZRG.js";var I=typeof window<"u"&&"$arcgis"in window&&typeof window.$arcgis=="object"&&"import"in window.$arcgis&&!("forceESM"in window.$arcgis);function W(t){return t.default!==void 0}async function V(){if(I)return await window.$arcgis.import("esri/core/reactiveUtils");let t=await $arcgis.l("core/reactiveUtils");return W(t)?t.default:t}var l;async function b(){return l??(l=V()),await l}var x=(t,e)=>(r,i)=>T(r,t,i),F=class extends M{constructor(t,e,r){super(t),this._loadAccessor=e,this._options=r,this._watchedProperties=new Map,this._isBinding={value:!0},this.setProvisionalExports(f.makeGetterProxy(t,this._watchedProperties,this._isBinding,this.constructor.allowedPropNameMismatches)),C(t,i=>{i&&(this._instancePropName=i)},this.exports)}hostConnected(){this._isBinding.value=!1}async hostLoad(){this.reactiveUtils=await b();let t=this.component,e=this._gatherParameters(),r=this._options?.editConstructorProperties?.call(t,e)??e,i=r instanceof Promise?await r:r,c=t,n=typeof this._instancePropName=="string"?c[this._instancePropName]:void 0;n!=null&&n!==this.exports?(this._instance=n,n.set(i)):this._instance=await this._createInstance(i),!t.manager.destroyed&&(f.watchComponentUpdates(this,this._instance,this._watchedProperties),f.watchAccessorUpdates(this,this._instance,this._watchedProperties),this.exports=this._instance)}_gatherParameters(){return Object.fromEntries(Array.from(this._watchedProperties,([r,i])=>[i,this.component[r]]).filter(([,r])=>r!==void 0))}async _createInstance(t){return this._isAccessorConstructor(this._loadAccessor)?new this._loadAccessor(t):await this._loadAccessor(t)}_isAccessorConstructor(t){return"prototype"in t&&"declaredClass"in t.prototype}hostDestroy(){this._instance&&this._instance.destroy()}async reCreate(){this.hostDestroy(),await this.hostLoad()}},T=h(F),f={makeGetterProxy:(t,e,r,i)=>new Proxy({},{has:(c,n)=>typeof n=="string"||n in c,get:(c,n)=>{let w=Reflect.get(c,n);if(typeof n=="symbol"||n in Promise.prototype)return w;let u=n in c,o=r?.value??!0;if(u||!o)return w;if(!e.has(n))return $(t,a=>{a!==void 0&&e.set(a.key,n)},w)}}),watchComponentUpdates(t,e,r){function i(u,o){let a=r.get(o),s=e[a];return typeof s=="boolean"&&a!==o&&o.toLowerCase().includes("disable")?!s:s}let c=(u,o,a)=>{let s=r.get(a),p=e[s],m=typeof p=="boolean"&&s!==a&&a.toLowerCase().includes("disable");if((m?!p:n.manager.isLit?p??void 0:p)===u)return u;e[s]=m?!u:u;let d=e[s];return m?!d:d},n=t.component,w=n.manager.internals;r.forEach((u,o)=>{w.accessorGetter[o]=i,w.accessorSetter[o]=c})},watchAccessorUpdates(t,e,r){let{component:i}=t,c=i,n=e,w=G(e);R(()=>r.forEach((u,o)=>{if(w.has(u))return;let a=c[o],s=n[u];i.manager.isLit&&(s??(s=void 0));let m=typeof a=="boolean"&&u!==o&&o.toLowerCase().includes("disable")?!a:a;m!=null&&s!==m&&(n[u]=m)})),t.onLifecycle(()=>{if(!e.destroyed)return Array.from(r,([u,o])=>t.reactiveUtils.watch(()=>n[o],()=>{let a=n[o],p=typeof a=="boolean"&&o!==u&&u.toLowerCase().includes("disable")?!a:a;L(()=>{c[u]=p})},{initial:!0}))})},reEmitAccessorEvents(t,e,r,i){if(!("on"in e&&typeof e.on=="function"))return;let n=Object.entries(t.component).map(([o,a])=>{let s=a;if(!o.startsWith(i)||o===i||typeof s!="object"||s===null||!("emit"in s)||typeof s.emit!="function")return;let p=s.emit,m=o.slice(i.length);return[y(m).toLowerCase(),p]}).filter(g);if(n.length===0)return;let w=e,u=()=>w;t.onLifecycle(()=>{if(!e.destroyed)return n.map(([o,a])=>r.on(u,o,a))})},async reCreate(t,e){let r=e.manager.useRefSync(t);r!==void 0&&await r.reCreate()}};function G(t){let r=Object.entries(t.__accessor__?.metadata??{});return new Set(r.filter(([i,c])=>c?.readOnly===!0).map(([i])=>i))}function N(t,e){let r=S(),i=r.manager,c=b();i.onLoaded(()=>{c.then(w=>i.onLifecycle(()=>w.on(t,e,n.emit)))});let n=r.constructor.$createEvent();return n}export{x as a,F as b,f as c,N as d};