UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 7.29 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import{fetchMessageBundle as t,onLocaleChange as r}from"../intl.js";import{byId as s}from"../core/domUtils.js";import{EventedAccessor as o}from"../core/Evented.js";import{isEventedOrEventTarget as i,on as n}from"../core/events.js";import"../core/has.js";import{clone as d}from"../core/lang.js";import a from"../core/Logger.js";import{destroyMaybe as l}from"../core/maybe.js";import{EsriPromiseMixin as c}from"../core/Promise.js";import{debounce as h,throwIfNotAbortError as p}from"../core/promiseUtils.js";import{watch as u,syncAndInitial as m,when as g}from"../core/reactiveUtils.js";import{generateUUID as y}from"../core/uuid.js";import{property as v,subclass as _}from"../core/accessorSupport/decorators.js";import{runTracked as f}from"../core/accessorSupport/tracking.js";import{SimpleTrackingTarget as j}from"../core/accessorSupport/tracking/SimpleTrackingTarget.js";import{createAdvancedProjector as b}from"../libs/maquette-advanced-projector/projector.js";import{commitAssetPath as w}from"./support/componentsUtils.js";import{isWidgetConstructor as R,processWidgets as S}from"./support/jsxWidgetSupport.js";import{widgetSymbol as L,widgetTestDataSymbol as P}from"./support/symbols.js";import{registerAlive as k,registerLoading as C}from"./support/tests.js";import{getVNodeCache as E,setVNodeCache as F,deleteVNodeCache as T,clearVNodeCache as I}from"./support/vnodeCache.js";import{classes as N}from"./support/widget.js";var H;let $=0;function D(e,t){const r=Object.prototype.hasOwnProperty;for(const s in t)r.call(t,s)&&r.call(e,s)&&(null!=e[s]&&null!=t[s]&&"object"==typeof e[s]&&"object"==typeof t[s]?D(e[s],t[s]):e[s]=t[s]);return e}const U=b({postProcessProjectionOptions(e){const t=e.eventHandlerInterceptor,r=/capture$/i;e.eventHandlerInterceptor=(e,s,o,i)=>{const n=t?.(e,s,o,i),d=r.test(e);if(!((e=e.replace(r,"")).toLowerCase()in o)||d){const t=e[2].toLowerCase()+e.slice(3),r=e=>n?.call(o,e);o.addEventListener(t,r,d);const s=()=>o.removeEventListener(t,r,d),a=i.afterRemoved;i.afterRemoved=e=>{a?.(e),s()}}return n}},handleInterceptedEvent(e,t,r,s){const{eventPhase:o,type:i}=s,n=o===Event.CAPTURING_PHASE;let d=`on${i}${n?"capture":""}`;const a=t.properties;(a&&d in a||(d=`on${i[0].toUpperCase()}${i.slice(1)}${n?"Capture":""}`,a&&d in a))&&(I(),e.scheduleRender(),a[d].call(a.bind||r,s))}});let z=!1,x=class extends(c(o)){static{this[H]=!0}constructor(e,r){super(e,r),this._attached=!1,this._projector=U,this._readyForTrueRender=!1,this.key=this,this.autoRenderingEnabled=!0,this.topLayerDisabled=!1,this._loadLocale=h(async()=>{if(this._messageBundleProps?.length){const e=await Promise.allSettled(this._messageBundleProps.map(async({bundlePath:e,propertyName:r})=>{if(this.destroyed)return;let s=await t(e);this.destroyed||(this.uiStrings&&Object.keys(this.uiStrings)&&(s=D(d(s),this.uiStrings)),this[r]=s)}));if(this.destroyed)return;for(const t of e)"rejected"===t.status&&a.getLogger(this).error("widget-intl:locale-error",this.declaredClass,t.reason)}await this.loadLocale()}),this.addHandles(k()),w();const s="esri-widget-uid-"+y(),o=this.render.bind(this);this._trackingTarget=new j(()=>{this.autoRenderingEnabled&&this.scheduleRender()});const i=()=>({vnodeSelector:"div",properties:{key:`${s}-hidden`,class:"",styles:{display:"none"}},domNode:null,children:void 0,text:void 0}),n=()=>{if(!this._readyForTrueRender||this.destroyed)return null;const e=o()??i(),t=e.properties??={};if(t.key??=s,R(e.vnodeSelector)){if(!this.visible)return i()}else this.visible?t.styles||(t.styles={}):(t.class="",t.styles={display:"none"}),t.styles.display??="";let r=0;return e.children?.forEach(e=>{R(e.vnodeSelector)||(e.properties??={},e.properties.key??=`${this.id}--${r++}`)}),S(this,e)};this.render=()=>{if(z)return n();let e=E(this)??null;if(e)return e;this._trackingTarget.clear(),z=!0;try{e=f(this._trackingTarget,n)}catch(t){throw a.getLogger(this).error(t),t}finally{z=!1}return e&&F(this,e),e};const l=this.beforeFirstRender();l?this._resourcesFetch=l.then(()=>{this.destroyed||(this._readyForTrueRender=!0,this._postInitialize())}):(this._resourcesFetch=Promise.resolve().then(()=>{this.destroyed||this._postInitialize()}),this._readyForTrueRender=!0),this.addResolvingPromise(this._resourcesFetch),C(this._resourcesFetch)}normalizeCtorArgs(e,t){const r={...e};return t&&(r.container=t),r}postInitialize(){}beforeFirstRender(){const e=this.loadDependencies();return this._messageBundleProps?.length||e?Promise.all([e,this._loadLocale()]).then(()=>{}).catch(p):null}loadDependencies(){return null}loadLocale(){return null}destroy(){this.destroyed||(l(this._trackingTarget),l(this.viewModel),this._detach(this.container),this._set("container",null),this.render=()=>null,this._projector=null,T(this))}get container(){return this._get("container")}set container(e){this._get("container")||this._set("container",s(e))}get destroyed(){return super.destroyed}get domNode(){return this.container}set domNode(e){this.container=e}get icon(){return null}set icon(e){this._overrideIfSome("icon",e)}get id(){return this._get("id")||this.container?.id||Date.now().toString(16)+"-widget-"+$++}set id(e){e&&this._set("id",e)}get label(){return this.declaredClass.split(".").pop()}set label(e){this._overrideIfSome("label",e)}get renderable(){return this._resourcesFetch}get visible(){return this._get("visible")}set visible(e){this._set("visible",e)}get[(H=L,P)](){return{projector:this._projector}}static{this.vnodeSelector="div"}render(){throw new Error("not implemented")}removeContainer(){this._set("container",null)}scheduleRender(){this.destroyed||(T(this),this._projector.scheduleRender())}classes(...e){return N.apply(this,e)}renderNow(){T(this),this._projector.renderNow()}_postInitialize(){if(this.destroyed)return;this.scheduleRender(),this._delegatedEventNames?.length&&this.addHandles(u(()=>this.viewModel,(e,t)=>{t&&this.removeHandles("delegated-events"),e&&i(e)&&this.addHandles(this._delegatedEventNames.map(t=>n(e,t,e=>{this.emit(t,e)})),"delegated-events")},m)),this.postInitialize();const e=async()=>{await this._loadLocale().catch(p),this.scheduleRender()};this.addHandles([r(e),u(()=>this.uiStrings,e)]),this.addHandles(g(()=>this.container,e=>{this.destroyed||(e.closest("[arcgis-widget-wrapped]")||(this.topLayerDisabled=!0,this.announceDeprecation?.()),this._attach(e))},{initial:!0,once:!0}))}_attach(e){e&&(this._projector.merge(e,this.render),this._attached=!0)}_detach(e){this._attached&&(this._projector.detach(this.render),this._attached=!1),e?.parentNode?.removeChild(e)}};e([v()],x.prototype,"_readyForTrueRender",void 0),e([v({value:null})],x.prototype,"container",null),e([v()],x.prototype,"icon",null),e([v()],x.prototype,"id",null),e([v()],x.prototype,"label",null),e([v()],x.prototype,"renderable",null),e([v()],x.prototype,"uiStrings",void 0),e([v()],x.prototype,"viewModel",void 0),e([v({value:!0})],x.prototype,"visible",null),e([v()],x.prototype,"key",void 0),e([v()],x.prototype,"children",void 0),e([v()],x.prototype,"afterCreate",void 0),e([v()],x.prototype,"afterUpdate",void 0),e([v()],x.prototype,"afterRemoved",void 0),e([v()],x.prototype,"topLayerDisabled",void 0),x=e([_("esri.widgets.Widget")],x);const O=x;export{O as default};