@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 6.86 kB
JavaScript
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{byId as t}from"../core/domUtils.js";import r from"../core/Evented.js";import{isEventTarget as s,on as o}from"../core/events.js";import i from"../core/Handles.js";import"../core/has.js";import{clone as n}from"../core/lang.js";import a from"../core/Logger.js";import{destroyMaybe as c}from"../core/maybe.js";import{EsriPromiseMixin as l}from"../core/Promise.js";import{debounce as d,throwIfNotAbortError as p,eachAlways as h}from"../core/promiseUtils.js";import{watch as m,when as u,initial as g}from"../core/reactiveUtils.js";import{generateUUID as y}from"../core/uuid.js";import{property as _}from"../core/accessorSupport/decorators/property.js";import{cast as f}from"../core/accessorSupport/decorators/cast.js";import{subclass as v}from"../core/accessorSupport/decorators/subclass.js";import{runTracked as j}from"../core/accessorSupport/tracking.js";import{SimpleTrackingTarget as b}from"../core/accessorSupport/tracking/SimpleTrackingTarget.js";import{createAdvancedProjector as w}from"../libs/maquette-advanced-projector/projector.js";import{commitAssetPath as k}from"./support/componentsUtils.js";import{isWidgetConstructor as R,processWidgets as S}from"./support/jsxWidgetSupport.js";import{WIDGET_TEST_DATA_SYMBOL as C,WIDGET_SYMBOL as P}from"./support/symbols.js";import{registerLoading as E}from"./support/tests.js";import{getVNodeCache as I,setVNodeCache as L,deleteVNodeCache as T,clearVNodeCache as H}from"./support/vnodeCache.js";import{classes as N}from"./support/widgetUtils.js";import{onLocaleChange as F}from"../intl/locale.js";import{fetchMessageBundle as U}from"../intl/messages.js";var $;const x="esri.widgets.Widget";let z=0;const A={widgetIcon:"esri-icon-checkbox-unchecked"};function B(e,t){for(const r in t)null!=e[r]&&("object"==typeof e[r]&&"object"==typeof t[r]?B(e[r],t?.[r]):e[r]=t[r]);return e}const D=w({postProcessProjectionOptions(e){const t=e.eventHandlerInterceptor,r=/capture$/i;e.eventHandlerInterceptor=(e,s,o,i)=>{const n=t?.(e,s,o,i),a=r.test(e);if(!((e=e.replace(r,"")).toLowerCase()in o)||a){const t=e[2].toLowerCase()+e.slice(3),r=e=>n?.call(o,e);o.addEventListener(t,r,a);const s=()=>o.removeEventListener(t,r,a),c=i.afterRemoved;i.afterRemoved=e=>{c?.(e),s()}}return n}},handleInterceptedEvent(e,t,r,s){const{eventPhase:o,type:i}=s,n=o===Event.CAPTURING_PHASE;let a=`on${i}${n?"capture":""}`;const c=t.properties;(c&&a in c||(a=`on${i[0].toUpperCase()}${i.slice(1)}${n?"Capture":""}`,c&&a in c))&&(H(),e.scheduleRender(),c[a].call(c.bind||r,s))}});let M=!1,O=class extends(l(r.EventedAccessor)){constructor(e,t){super(e,t),this._attached=!1,this._internalHandles=new i,this._projector=D,this._readyForTrueRender=!1,this.iconClass=A.widgetIcon,this.key=this,this._loadLocale=d((async()=>{if(this._messageBundleProps&&this._messageBundleProps.length){const e=await h(this._messageBundleProps.map((async({bundlePath:e,propertyName:t})=>{let r=await U(e);this.uiStrings&&Object.keys(this.uiStrings)&&(r=B(n(r),this.uiStrings)),this[t]=r})));for(const t of e)t.error&&a.getLogger(this.declaredClass).error("widget-intl:locale-error",this.declaredClass,t.error)}await this.loadLocale()})),k();const r="esri-widget-uid-"+y(),s=this.render.bind(this);this._trackingTarget=new b((()=>this.scheduleRender()));const o=()=>{if(!this._readyForTrueRender||this.destroyed)return null;if(!this.visible)return{vnodeSelector:"div",properties:{key:r,class:"",styles:{display:"none"}},domNode:null,children:void 0,text:void 0};const e=s();let{properties:t}=e;t||(e.properties=t={});let{key:o,styles:i}=t;o||(t.key=r),i||(t.styles=i={}),i.display||(i.display="");let n=0;return e.children?.forEach((e=>{if(R(e.vnodeSelector))return;let{properties:t}=e;t||(e.properties=t={}),t.key||(t.key=`${this.id}--${n++}`)})),S(this,e)};this.render=()=>{if(M)return o();let e=I(this)??null;if(e)return e;this._trackingTarget.clear(),M=!0;try{e=j(this._trackingTarget,o)}catch(t){throw console.error(t),t}finally{M=!1}return e&&L(this,e),e},this.addResolvingPromise(this._resourcesFetch=this.beforeFirstRender().then((()=>{this._readyForTrueRender=!0,this._postInitialize()}))),E(this._resourcesFetch)}normalizeCtorArgs(e,t){const r={...e};return t&&(r.container=t),r}postInitialize(){}beforeFirstRender(){return Promise.all([this.loadDependencies(),this._loadLocale()]).then((()=>{})).catch(p)}async loadDependencies(){}async loadLocale(){}destroy(){this.destroyed||(c(this._trackingTarget),c(this.viewModel),this._detach(this.container),this._set("container",null),this._internalHandles.destroy(),this._emitter.clear(),this.render=()=>null,this._projector=null,T(this))}set container(e){this._get("container")||this._set("container",e)}castContainer(e){return t(e)}get domNode(){return this.container}set domNode(e){this.container=e}get id(){return this._get("id")||this.get("container.id")||Date.now().toString(16)+"-widget-"+z++}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[($=P,C)](){return{projector:this._projector}}render(){throw new Error("not implemented")}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._internalHandles.add(m((()=>this.viewModel),((e,t)=>{t&&this._internalHandles.remove("delegated-events"),e&&s(e)&&this._internalHandles.add(this._delegatedEventNames.map((t=>o(e,t,(e=>{this.emit(t,e)})))),"delegated-events")}),g)),this.postInitialize();const e=async()=>{await this._loadLocale().catch(p),this.scheduleRender()};this._internalHandles.add([F(e),m((()=>this.uiStrings),e),u((()=>this.container),(e=>{this.destroyed||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)}};O[$]=!0,e([_()],O.prototype,"_readyForTrueRender",void 0),e([_({value:null})],O.prototype,"container",null),e([f("container")],O.prototype,"castContainer",null),e([_()],O.prototype,"iconClass",void 0),e([_()],O.prototype,"id",null),e([_()],O.prototype,"label",null),e([_()],O.prototype,"renderable",null),e([_()],O.prototype,"uiStrings",void 0),e([_()],O.prototype,"viewModel",void 0),e([_({value:!0})],O.prototype,"visible",null),e([_()],O.prototype,"key",void 0),e([_()],O.prototype,"children",void 0),e([_()],O.prototype,"afterCreate",void 0),e([_()],O.prototype,"afterUpdate",void 0),e([_()],O.prototype,"afterRemoved",void 0),O=e([v(x)],O);const W=O;export{W as default};