@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 5.41 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/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{ensureType as d}from"../../core/accessorSupport/ensureType.js";import{get as p}from"../../core/accessorSupport/get.js";import c from"../../support/actions/ActionBase.js";import u from"../../support/actions/ActionButton.js";import y from"../../support/actions/ActionToggle.js";import{canDisplayLayer as m,findLayerListMode as b,getNormalizedChildLayerProperty as f}from"../LayerList/support/layerListUtils.js";import C from"./ListItemPanel.js";var _;const g="layer",v="child-list-mode",S="hide",I=s.ofType({key:"type",defaultKeyValue:"button",base:c,typeMap:{button:u,toggle:y}}),P=s.ofType(I);let M=_=class extends(r.IdentifiableMixin(e)){constructor(t){super(t),this.actionsSections=new P,this.actionsOpen=!1,this.checkPublishStatusEnabled=!1,this.children=new(s.ofType(_)),this.hidden=!1,this.layer=null,this.listItemCreatedFunction=null,this.listModeDisabled=!1,this.open=!1,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}set panel(t){const e=this._get("panel");t!==e&&t&&e?.destroy(),this._set("panel",t)}castPanel(t){return this.panel?.open&&!t.hasOwnProperty("open")&&(t.open=!0),d(C,t)}get publishing(){const{layer:t,checkPublishStatusEnabled:e}=this;return(e&&t&&"publishingInfo"in t&&"publishing"===t.publishingInfo?.status)??!1}get title(){const t=p(this,"layer.layer");return(!t||t&&p(this,"layer.layer.loaded")?this.layer?.title:null)??""}set title(t){this._overrideIfSome("title",t)}clone(){return new _({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||m(t)?new _({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=>b(t)!==S));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))),g)}_initializeChildLayers(t){this._compileChildren(t),this._watchSublayerChanges(t)}_watchLayerProperties(t){if(this.removeHandles(g),this.removeHandles(v),!t)return;t.load();if("hide-children"===(!this.listModeDisabled&&b(t)))return void this.children.destroyAll();const e=f(t);e&&this.addHandles(o((()=>t[e]),(i=>{t.hasOwnProperty(e)&&this._initializeChildLayers(i)}),l),g)}};t([n({type:P})],M.prototype,"actionsSections",void 0),t([n()],M.prototype,"actionsOpen",void 0),t([n()],M.prototype,"checkPublishStatusEnabled",void 0),t([n({type:s.ofType(M)})],M.prototype,"children",void 0),t([n({readOnly:!0})],M.prototype,"error",null),t([n()],M.prototype,"hidden",void 0),t([n()],M.prototype,"layer",void 0),t([n()],M.prototype,"listItemCreatedFunction",void 0),t([n({nonNullable:!0})],M.prototype,"listModeDisabled",void 0),t([n()],M.prototype,"open",void 0),t([n({type:C})],M.prototype,"panel",null),t([a("panel")],M.prototype,"castPanel",null),t([n()],M.prototype,"parent",void 0),t([n({readOnly:!0})],M.prototype,"publishing",null),t([n()],M.prototype,"sortable",void 0),t([n()],M.prototype,"title",null),M=_=t([h("esri.widgets.TableList.ListItem")],M);export{M as default};