UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 5.29 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../core/Accessor.js";import{isSome as i}from"../../core/arrayUtils.js";import s from"../../core/Collection.js";import r from"../../core/Identifiable.js";import{watch as o,initial as l}from"../../core/reactiveUtils.js";import{property as n}from"../../core/accessorSupport/decorators/property.js";import{cast as a}from"../../core/accessorSupport/decorators/cast.js";import"../../core/has.js";import{subclass as h}from"../../core/accessorSupport/decorators/subclass.js";import{get as d}from"../../core/accessorSupport/get.js";import c from"../../support/actions/ActionBase.js";import p from"../../support/actions/ActionButton.js";import u from"../../support/actions/ActionToggle.js";import{canDisplayLayer as y,findLayerListMode as m,getNormalizedChildLayerProperty as b}from"../LayerList/support/layerListUtils.js";import f from"./ListItemPanel.js";var C;const _="layer",v="child-list-mode",g="hide",I=s.ofType({key:"type",defaultKeyValue:"button",base:c,typeMap:{button:p,toggle:u}}),P=s.ofType(I);let S=C=class extends(r.IdentifiableMixin(e)){constructor(t){super(t),this.actionsSections=new P,this.actionsOpen=!1,this.checkPublishStatusEnabled=!1,this.children=new(s.ofType(C)),this.hidden=!1,this.layer=null,this.listItemCreatedFunction=null,this.listModeDisabled=!1,this.open=!1,this.panel=null,this.parent=null,this.sortable=!0}initialize(){if(this.addHandles([o((()=>[this.layer?.listMode,this.listModeDisabled]),(()=>this._watchLayerProperties(this.layer)),l),o((()=>this.checkPublishStatusEnabled),(t=>this._updateChildrenPublishing(t)),l),o((()=>this.panel),(t=>this._setListItemOnPanel(t)),l)]),"function"==typeof this.listItemCreatedFunction){const t={item:this};this.listItemCreatedFunction.call(null,t)}}destroy(){this.panel?.destroy(),this.children.destroyAll()}get error(){return this.layer?.loadError}castPanel(t){return this.panel?.open&&!t.hasOwnProperty("open")&&(t.open=!0),t?new f(t):null}get publishing(){const{layer:t,checkPublishStatusEnabled:e}=this;return(e&&t&&"publishingInfo"in t&&"publishing"===t.publishingInfo?.status)??!1}get title(){const t=d(this,"layer.layer");return(!t||t&&d(this,"layer.layer.loaded")?this.layer?.title:null)??""}set title(t){this._overrideIfSome("title",t)}clone(){return new C({actionsSections:this.actionsSections.clone(),actionsOpen:this.actionsOpen,checkPublishStatusEnabled:this.checkPublishStatusEnabled,children:this.children.clone(),hidden:this.hidden,layer:this.layer,listItemCreatedFunction:this.listItemCreatedFunction,listModeDisabled:this.listModeDisabled,open:this.open,panel:this.panel,parent:this.parent,sortable:this.sortable,title:this.title})}_updateChildrenPublishing(t){this.children?.forEach((e=>e.checkPublishStatusEnabled=t))}_setListItemOnPanel(t){t&&(t.listItem=this)}_createChildItems(t,e){return t.reverse().map((t=>e||y(t)?new C({layer:t,checkPublishStatusEnabled:this.checkPublishStatusEnabled,listItemCreatedFunction:this.listItemCreatedFunction,listModeDisabled:this.listModeDisabled,parent:this}):null)).filter(i)}_createChildren(t){const{listModeDisabled:e,children:i}=this,s=t.reverse().filter((t=>!i.some((e=>e.layer===t))));i.addMany(this._createChildItems(s,e))}_destroyChildren(t){const{children:e}=this,i=e.filter((e=>!!e.layer&&!t.includes(e.layer)));e.destroyMany(i)}_sortChildren(t){this.children.sort(((e,i)=>t.indexOf(i.layer)-t.indexOf(e.layer)))}_destroyAllChildren(){this.removeHandles(v),this.children.destroyAll()}_compileChildren(t){const e=this.listModeDisabled?t:t?.filter((t=>m(t)!==g));t?.length?(this._createChildren(e),this._destroyChildren(e),this._sortChildren(e),this._watchChildLayerListMode(t)):this._destroyAllChildren()}_watchChildLayerListMode(t){this.removeHandles(v),this.listModeDisabled||this.addHandles(t.toArray().map((e=>o((()=>e.listMode),(()=>this._compileChildren(t))))),v)}_watchSublayerChanges(t){t&&this.addHandles(t.on("change",(()=>this._compileChildren(t))),_)}_initializeChildLayers(t){this._compileChildren(t),this._watchSublayerChanges(t)}_watchLayerProperties(t){if(this.removeHandles(_),this.removeHandles(v),!t)return;t.load();if("hide-children"===(!this.listModeDisabled&&m(t)))return void this.children.destroyAll();const e=b(t);e&&this.addHandles(o((()=>t[e]),(i=>{t.hasOwnProperty(e)&&this._initializeChildLayers(i)}),l),_)}};t([n({type:P})],S.prototype,"actionsSections",void 0),t([n()],S.prototype,"actionsOpen",void 0),t([n()],S.prototype,"checkPublishStatusEnabled",void 0),t([n({type:s.ofType(S)})],S.prototype,"children",void 0),t([n({readOnly:!0})],S.prototype,"error",null),t([n()],S.prototype,"hidden",void 0),t([n()],S.prototype,"layer",void 0),t([n()],S.prototype,"listItemCreatedFunction",void 0),t([n({nonNullable:!0})],S.prototype,"listModeDisabled",void 0),t([n()],S.prototype,"open",void 0),t([n({type:f})],S.prototype,"panel",void 0),t([a("panel")],S.prototype,"castPanel",null),t([n()],S.prototype,"parent",void 0),t([n({readOnly:!0})],S.prototype,"publishing",null),t([n()],S.prototype,"sortable",void 0),t([n()],S.prototype,"title",null),S=C=t([h("esri.widgets.TableList.ListItem")],S);const M=S;export{M as default};