@arcgis/core 4.30.0-next.20240210 → 4.30.0-next.20240213
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/05ebb9cec0e1826b283f.js +1 -0
- package/assets/esri/core/workers/chunks/0d54451c740f54a59f49.js +1 -0
- package/assets/esri/core/workers/chunks/{2b7513fe57eca6cff7c3.js → 0f30059c4e7a9cb85d1d.js} +1 -1
- package/assets/esri/core/workers/chunks/18551a7eb5a9b88aa0dc.js +1 -0
- package/assets/esri/core/workers/chunks/24d19abc680b341d13bb.js +1 -0
- package/assets/esri/core/workers/chunks/{3f4d63436c3de04a6ebb.js → 254b4ee3621bbe345bb1.js} +1 -1
- package/assets/esri/core/workers/chunks/2d682ee6e5d66f2ea5cd.js +1 -0
- package/assets/esri/core/workers/chunks/{d5484d470121de2b403b.js → 36d091be859bbb1a149b.js} +1 -1
- package/assets/esri/core/workers/chunks/50b41f91be903a0977f9.js +1 -0
- package/assets/esri/core/workers/chunks/50bb67f2eeace5d50673.js +1 -0
- package/assets/esri/core/workers/chunks/784b6a8216b97440b180.js +1 -0
- package/assets/esri/core/workers/chunks/{7f7a4de2cd4ab71b9aee.js → 8d119dc0a92ad3612daa.js} +1 -1
- package/assets/esri/core/workers/chunks/966cc0b54008c7348678.js +1 -0
- package/assets/esri/core/workers/chunks/{2853221e88ed7077a447.js → 9850b0e04cce8c1bdddf.js} +1 -1
- package/assets/esri/core/workers/chunks/{0014635097a32ad38895.js → a854611d1a86b838c6ad.js} +1 -1
- package/assets/esri/core/workers/chunks/{cf6970b490b98aa0a117.js → be562536212360943388.js} +1 -1
- package/assets/esri/core/workers/chunks/{50a5abd75fa7dbb571a5.js → ccd53b81c2688dd11584.js} +1 -1
- package/assets/esri/core/workers/chunks/{b2b8e6a0b3f70ada2799.js → e4da908079417cc2f495.js} +1 -1
- package/assets/esri/core/workers/chunks/{af0314c2b5b7dc4f5bbd.js → e6dbf0a7b7b1cf64f23f.js} +1 -1
- package/assets/esri/core/workers/chunks/{eba72ff1726ff6998204.js → f03d62ab7806b68d0b62.js} +1 -1
- package/assets/esri/core/workers/chunks/{5fcda75ed02b8aee3a3c.js → f89278782ddfb154aa9f.js} +1 -1
- package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
- package/geometry/Mesh.js +1 -1
- package/geometry/support/meshVertexSpaceUtils.js +1 -1
- package/interfaces.d.ts +174 -16
- package/layers/Lyr3DWasmPerSceneView.js +1 -1
- package/layers/SceneLayer.js +1 -1
- package/layers/graphics/sources/FeatureLayerSource.js +1 -1
- package/layers/support/PixelBlock.js +1 -1
- package/layers/support/rasterDatasets/BaseRaster.js +1 -1
- package/layers/support/rasterDatasets/MRFRaster.js +1 -1
- package/layers/support/rasterFormats/RasterCodec.js +1 -1
- package/layers/support/rasterFunctions/surfaceUtils.js +1 -1
- package/package.json +2 -2
- package/portal/support/resourceUtils.js +1 -1
- package/rest/query/operations/pbfJSONFeatureSet.js +1 -1
- package/rest/support/meshFeatureSet.js +1 -1
- package/support/revision.js +1 -1
- package/symbols/cim/constants.js +1 -1
- package/symbols/support/previewSymbol2D.js +1 -1
- package/versionManagement/support/versionManagementUtils.js +1 -1
- package/views/2d/engine/webgl/collisions/CollisionEngine.js +1 -1
- package/views/2d/engine/webgl/collisions/CollisionGrid.js +1 -1
- package/views/2d/engine/webgl/collisions/LabelMetric.js +1 -1
- package/views/2d/engine/webgl/mesh/templates/segmentUtils.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/GLSLShaderModule.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/labels/LabelMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/markers/MarkerMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/pieChart/PieChartMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/shaders/constants.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/text/TextMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/text/TextShader.js +1 -1
- package/views/2d/layers/features/processor/BinningStrategy.js +1 -1
- package/views/2d/layers/features/schema/processor/symbols/SymbolSchema.js +1 -1
- package/views/2d/layers/features/support/FeatureSetReader.js +1 -1
- package/views/3d/interactive/editingTools/transformGraphic/ExtentScale.js +1 -1
- package/views/3d/interactive/editingTools/transformGraphic/extentUtils.js +1 -1
- package/views/3d/layers/I3SMeshView3D.js +1 -1
- package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
- package/views/3d/webgl-engine/collections/Component/Material/ComponentMaterial.js +1 -1
- package/views/SceneView.js +1 -1
- package/views/draw/DrawOperation.js +1 -1
- package/views/draw/support/Box.js +1 -1
- package/views/interactive/tooltip/components/TooltipEditableField.js +1 -1
- package/views/support/automaticLengthMeasurementUtils.js +1 -1
- package/views/support/extentUtils.js +5 -0
- package/widgets/BasemapLayerList.js +1 -1
- package/widgets/Editor/EditorViewModel.js +1 -1
- package/widgets/FeatureForm.js +1 -1
- package/widgets/LayerList.js +1 -1
- package/widgets/TableList.js +1 -1
- package/assets/esri/core/workers/chunks/062629a9b4695dea8bf8.js +0 -1
- package/assets/esri/core/workers/chunks/3401157faaa8619aaa47.js +0 -1
- package/assets/esri/core/workers/chunks/37803888bd9a537481a7.js +0 -1
- package/assets/esri/core/workers/chunks/560f677a356c7ebde5d3.js +0 -1
- package/assets/esri/core/workers/chunks/5bfc5ffad705aaaafcd4.js +0 -1
- package/assets/esri/core/workers/chunks/655f4560fb36a0d9ff0b.js +0 -1
- package/assets/esri/core/workers/chunks/b927b655e955abe00d48.js +0 -1
- package/assets/esri/core/workers/chunks/d2417d179d015f1193a1.js +0 -1
- package/assets/esri/core/workers/chunks/f75ec599f53c66cab194.js +0 -1
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import t from"../core/Collection.js";import{deprecatedProperty as i}from"../core/deprecate.js";import s from"../core/Logger.js";import{property as n}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as o}from"../core/accessorSupport/decorators/subclass.js";import{getActionIcon as l,getActionStyles as r}from"../support/actions/actionUtils.js";import a from"./Widget.js";import c from"./BasemapLayerList/BasemapLayerListViewModel.js";import d from"./BasemapLayerList/BasemapLayerListVisibleElements.js";import{css as m}from"./BasemapLayerList/css.js";import p from"./LayerList/ListItem.js";import{minFilterItems as u,getItem as h,getLayerType as g,getStatusIcon as b,getVisibilityIcon as f,sortableRoot as v,sortLayersToIds as _,sortChildLayersToIds as y,listItemHasChildren as I,canSortSublayers as E}from"./LayerList/support/layerListUtils.js";import{loadCalciteComponents as L}from"./support/componentsUtils.js";import{globalCss as w}from"./support/globalCss.js";import{incrementHeadingLevel as F}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as C}from"./support/decorators/messageBundle.js";import{vmEvent as T}from"./support/decorators/vmEvent.js";import{tsx as M}from"./support/jsxFactory.js";const A=t.ofType(p),k="basemap",S=".*\\S+.*";let x=class extends a{constructor(e,t){super(e,t),this._activeItem=null,this._tooltipReferenceMap=new Map,this._editTitleInput=null,this._focusRootFlowItem=!1,this._focusPanelFlowItem=!1,this._focusEditingFlowItem=!1,this._lastDragDetail=null,this._selectedDragItemLayerUid=null,this.collapsed=!1,this.dragEnabled=!1,this.editingTitle=!1,this.filterPlaceholder="",this.baseFilterText="",this.referenceFilterText="",this.listItemCanGiveFunction=null,this.listItemCanReceiveFunction=null,this.headingLevel=2,this.iconClass=m.widgetIcon,this.messages=null,this.messagesCommon=null,this.minFilterItems=u,this.selectedItems=new A,this.selectionMode="none",this.viewModel=new c,this.visibilityAppearance="default",this.visibleElements=new d,this._canMove=({dragEl:e,fromEl:t,toEl:i},s)=>{const n="pull"===s?this.listItemCanGiveFunction:this.listItemCanReceiveFunction,o=h(e);if(!o?.sortable)return!1;const l=h(t),r=g(t),a=h(i),c=g(i),d=!!r&&!!c&&r===c,m={selected:o,from:l,to:a};return t.group&&i.group&&"function"==typeof n?n.call(null,m):d&&"sublayer"!==o?.layer?.type&&"map-image"!==l?.layer?.type&&"map-image"!==a?.layer?.type},this._clearActiveItem=()=>{this._activeItem=null},this._setActiveItem=e=>{if("default"!==this.visibilityAppearance)return;const t=Array.from(e.composedPath()).find((e=>e.classList?.contains(m.item)));this._activeItem=h(t)},this._onCalciteListOrderChange=e=>{const{_lastDragDetail:t}=this,{toEl:i,fromEl:s,dragEl:n,newIndex:o}=e;if(!s||!i||t?.newIndex===o&&t?.dragEl===n&&t?.toEl===i&&t?.fromEl===s)return;this._lastDragDetail=e;const l=s,r=i;if(l!==r)this._moveLayerFromChildList({toEl:r,fromEl:l,dragEl:n,newIndex:o});else{const e=Array.from(s.children).filter((e=>e?.matches("calcite-list-item"))).map((e=>e.value));this._sortLayers(l,e)}}}normalizeCtorArgs(e){return null!=e?.editingEnabled&&null!=e.visibleElements?{...e,visibleElements:new d({...e.visibleElements,editTitleButton:e.editingEnabled})}:e}loadDependencies(){return L({action:()=>import("@esri/calcite-components/dist/components/calcite-action.js"),"action-group":()=>import("@esri/calcite-components/dist/components/calcite-action-group.js"),"action-menu":()=>import("@esri/calcite-components/dist/components/calcite-action-menu.js"),block:()=>import("@esri/calcite-components/dist/components/calcite-block.js"),label:()=>import("@esri/calcite-components/dist/components/calcite-label.js"),input:()=>import("@esri/calcite-components/dist/components/calcite-input.js"),button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow.js"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice.js"),tooltip:()=>import("@esri/calcite-components/dist/components/calcite-tooltip.js")})}destroy(){this._tooltipReferenceMap.clear()}get _baseFilterEnabled(){return this.viewModel.totalBaseItems>=this.minFilterItems&&this.visibleElements.filter}get _referenceFilterEnabled(){return this.viewModel.totalReferenceItems>=this.minFilterItems&&this.visibleElements.filter}get basemapTitle(){return this.viewModel.basemapTitle}set basemapTitle(e){this.viewModel.basemapTitle=e}get baseListItemCreatedFunction(){return this.viewModel.baseListItemCreatedFunction}set baseListItemCreatedFunction(e){this.viewModel.baseListItemCreatedFunction=e}get editingEnabled(){return i(s.getLogger(this),"editingEnabled",{replacement:"selectionMode, dragEnabled, visibleElements.editTitleButton",version:"4.29",warnOnce:!0}),"none"!==this.selectionMode&&this.dragEnabled&&this.visibleElements.editTitleButton}set editingEnabled(e){i(s.getLogger(this),"editingEnabled",{replacement:"selectionMode, dragEnabled, visibleElements.editTitleButton",version:"4.29",warnOnce:!0}),this.dragEnabled=e,this.visibleElements.editTitleButton=e,this.selectionMode=e?this.multipleSelectionEnabled?"multiple":"single":"none"}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get multipleSelectionEnabled(){return i(s.getLogger(this),"multipleSelectionEnabled",{replacement:"selectionMode",version:"4.29",warnOnce:!0}),"multiple"===this.selectionMode}set multipleSelectionEnabled(e){i(s.getLogger(this),"multipleSelectionEnabled",{replacement:"selectionMode",version:"4.29",warnOnce:!0}),this.selectionMode=e?"multiple":this.editingEnabled?"single":"none"}get referenceListItemCreatedFunction(){return this.viewModel.referenceListItemCreatedFunction}set referenceListItemCreatedFunction(e){this.viewModel.referenceListItemCreatedFunction=e}get baseItems(){return this.viewModel.baseItems}get referenceItems(){return this.viewModel.referenceItems}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}triggerAction(e,t){return this.viewModel.triggerAction(e,t)}render(){const{state:e}=this.viewModel,t={[w.hidden]:"loading"===e,[w.disabled]:"disabled"===e};return M("div",{class:this.classes(m.base,w.widget,w.panel,t)},this._renderItems())}_renderItemTooltip(e){return e?M("calcite-tooltip",{key:`tooltip-${e.layer.uid}`,referenceElement:this._tooltipReferenceMap.get(e.layer.uid)},this.messages.layerIncompatibleTooltip):null}_renderItemTooltipNodes(e){return e.incompatible?this._renderItemTooltip(e):e.children?.filter((e=>!e.hidden)).toArray().map((e=>this._renderItemTooltipNodes(e)))}_renderItemTooltips(e){return e?.toArray().map((e=>this._renderItemTooltipNodes(e)))}_renderPanelFlowItems(e){return e?e.flatten((e=>e.children)).filter((e=>!e.hidden)).toArray().filter((({panel:e})=>e?.open&&!e.disabled&&e.flowEnabled)).map((({title:e,panel:t})=>{const i=()=>this._handlePanelFlowItemBack(t);return M("calcite-flow-item",{afterCreate:this._focusPanelFlowItemNode,afterUpdate:this._focusPanelFlowItemNode,bind:this,description:e,heading:t.title,headingLevel:this.headingLevel,key:`flow-panel-${t.uid}`,onCalciteFlowItemBack:e=>{e.preventDefault(),i()}},t.render(),M("calcite-button",{appearance:"transparent",onclick:i,slot:"footer-actions",width:"full"},this.messagesCommon.back))})):[]}_handlePanelFlowItemBack(e){e.open=!1,this._focusRootFlowItem=!0}_focusEditingFlowItemNode(e){this._focusEditingFlowItem&&(this._focusEditingFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_focusRootFlowItemNode(e){this._focusRootFlowItem&&(this._focusRootFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_focusPanelFlowItemNode(e){this._focusPanelFlowItem&&(this._focusPanelFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_renderItemMessage(e){return e.error?M("div",{class:m.itemMessage,key:"esri-layer-list__error",slot:"content-bottom"},M("calcite-notice",{icon:"exclamation-mark-triangle",kind:"warning",open:!0,scale:"s",width:"full"},M("div",{slot:"message"},this.messages.layerError))):e.incompatible?M("div",{class:m.itemMessage,key:"esri-layer-list__incompatible",slot:"content-bottom"},M("calcite-notice",{afterCreate:t=>this._setTooltipReference(t,e),afterRemoved:()=>this._removeTooltipReference(e),icon:"exclamation-mark-triangle",kind:"warning",open:!0,scale:"s",tabIndex:0,width:"full"},M("div",{slot:"message"},this.messages.layerIncompatible))):null}_renderItem(e,t,i,s,n){const{_activeItem:o,_selectedDragItemLayerUid:l,selectionMode:r,selectedItems:a,messages:c}=this,d=e.title||c.untitledLayer,p=e.visibleAtCurrentScale?d:`${d} (${c.layerInvisibleAtScale})`,u=this._filterActions(e.actionsSections),h=this._countActions(u);return M("calcite-list-item",{afterCreate:t=>this._focusSelectedDragEl(t,e),afterUpdate:t=>this._focusSelectedDragEl(t,e),class:this.classes(m.item,{[m.itemActive]:o===e}),"data-item":e,dragDisabled:!e.sortable||i,dragSelected:e.layer.uid===l,id:e.layer.uid,key:`list-item-${e.layer.uid}`,metadata:{parentTitles:n,title:d},open:e.open,selected:"none"!==r&&a.includes(e),title:p,value:e.layer.uid,onCalciteListItemDragHandleChange:t=>this._handleCalciteListItemDragHandleChange(t,e),onCalciteListItemSelect:t=>this._handleCalciteListItemSelect(t,e,s),onCalciteListItemToggle:t=>this._handleCalciteListItemToggle(t,e)},M("div",{class:m.itemContent,slot:"content"},M("div",{class:this.classes({[m.itemInvisibleAtScale]:!e.visibleAtCurrentScale})},d)),this._renderItemStatus(e,s),this._renderItemToggle(e,s),this._renderItemTemporaryIcon(e),this._renderChildList(e,t,n),this._renderItemMessage(e),this._renderPanel(e.panel),this._renderPanelAction(e.panel),h>1?this._renderActionsSections(e,u):1===h?this._renderAction({item:e,action:this._getSingleActionButton(u),textEnabled:!1}):null)}_renderItemStatus(e,t){const{visibleElements:i}=this;if(!i.statusIndicators)return null;const{connectionStatus:s,publishing:n,updating:o}=e,l=o&&!t,r=!!s;return M("calcite-icon",{class:this.classes({[m.statusIndicator]:!0,[m.publishing]:n,[m.updating]:l,[m.connectionStatus]:r,[m.connectionStatusConnected]:r&&"connected"===s}),icon:b({connectionStatus:s,publishing:n}),key:"layer-item-status",scale:"s",slot:"actions-end"})}_renderItemTemporaryIcon(e){return this.visibleElements.temporaryLayerIndicators&&"persistenceEnabled"in e.layer&&!e.layer.persistenceEnabled?M("calcite-icon",{class:m.itemTemporaryIcon,icon:"temporary",key:"temporary-icon",scale:"s",slot:"actions-start",title:this.messages.temporary}):null}_renderItemToggle(e,t){const{messages:i,visibilityAppearance:s}=this,{visible:n}=e,o=t?.visibilityMode;if("inherited"===o)return null;const l=f({visible:n,exclusive:"exclusive"===o,visibilityAppearance:s}),r="checkbox"===s;return M("calcite-action",{appearance:"transparent",class:m.visibleToggle,icon:r?l:void 0,key:"visibility-toggle",onclick:()=>this._toggleVisibility(e,t),scale:"s",slot:r?"actions-start":"actions-end",text:i.layerVisibility,title:i.layerVisibility},r?null:M("calcite-icon",{class:this.classes({[m.visibleIcon]:"exclusive"!==o&&n}),icon:l,scale:"s"}))}_renderPanel(e){return!e?.open||e.disabled||e.flowEnabled?null:M("div",{class:m.itemContentBottom,key:`content-panel-${e.uid}`,slot:"content-bottom"},e.render())}_renderPanelAction(e){if(!e?.visible)return null;const{open:t,title:i,disabled:s}=e;return M("calcite-action",{active:t,appearance:"transparent",disabled:s,icon:l(e),key:`action-${e.uid}`,onclick:()=>this._togglePanel(e),scale:"s",slot:"actions-end",text:i??"",title:i??void 0},this._renderFallbackIcon(e))}_renderActionsSections(e,t){return M("calcite-action-menu",{appearance:"transparent",key:"item-action-menu",label:this.messagesCommon.menu,open:e.actionsOpen,overlayPositioning:"fixed",placement:"bottom-end",scale:"s",slot:"actions-end",onCalciteActionMenuOpen:t=>e.actionsOpen=t.target.open},M("calcite-action",{appearance:"transparent",icon:"ellipsis",scale:"s",slot:"trigger",text:this.messagesCommon.options,title:this.messagesCommon.options}),t.toArray().map(((t,i)=>this._renderActionSection(e,t,i))))}_renderActionSection(e,t,i){return M("calcite-action-group",{key:`action-section-${i}`},t.toArray().map((t=>this._renderAction({item:e,action:t,textEnabled:!0}))))}_renderFallbackIcon(e){const{className:t,icon:i}=e;if(i)return null;const s="image"in e?e.image:void 0,n={[m.itemActionIcon]:!!t,[m.itemActionImage]:!!s};return t&&(n[t]=!0),s||t?M("span",{"aria-hidden":"true",class:this.classes(m.itemActionIcon,n),key:"icon",styles:r(s)}):null}_renderAction(e){const{item:t,action:i,textEnabled:s}=e,{active:n,disabled:o,title:r,type:a,indicator:c}=i;return M("calcite-action",{active:"toggle"===a&&i.value,appearance:"transparent",disabled:o,icon:l(i),indicator:c,key:`action-${i.uid}`,loading:n,onclick:()=>this._triggerAction(t,i),scale:"s",slot:s?void 0:"actions-end",text:r??"",textEnabled:s,title:r??void 0},this._renderFallbackIcon(i))}_setTooltipReference(e,t){this._tooltipReferenceMap.set(t.layer.uid,e)}_removeTooltipReference(e){this._tooltipReferenceMap.delete(e.layer.uid)}_moveLayerFromChildList({toEl:e,fromEl:t,dragEl:i,newIndex:s}){const n=h(i),o=h(e),l=h(t),r=j(t),a=j(e);r&&a&&this.viewModel.moveListItem({targetItem:n,fromParentItem:l,toParentItem:o,newIndex:s,from:r,to:a})}_handleCalciteListDragEnd(e){const{fromEl:t,dragEl:i,oldIndex:s}=e;t.insertBefore(i,t.children[s])}_sortLayers(e,t){if(e)if(e.group===v){const i=j(e),s="base"===i?this.view?.map?.basemap?.baseLayers:"reference"===i?this.view?.map?.basemap?.referenceLayers:null;_(s,t)}else{const i=h(e);if(!i)return;y(i,t)}}_getSingleActionButton(e){return e.reduce((e=>e)).filter((e=>e&&"button"===e.type)).at(0)}_filterActions(e){return e.map((e=>e.filter((e=>e.visible))))}_countActions(e){return e.reduce(((e,t)=>e+t.length),0)}_triggerAction(e,t){t&&e&&("toggle"===t.type&&(t.value=!t.value),this.triggerAction(t,e))}_handleCalciteListChange(e){const{selectionMode:t,selectedItems:i}=this;if("none"===t)return;const s=e.target.selectedItems.map((e=>h(e))).filter(Boolean);i.removeAll(),i.addMany(s)}_handleCalciteListItemToggle(e,t){e.stopPropagation(),t.open=e.target.open}_focusSelectedDragEl(e,t){this._selectedDragItemLayerUid===t.layer.uid&&requestAnimationFrame((()=>e?.setFocus()))}_handleCalciteListItemDragHandleChange(e,t){e.stopPropagation();const i=e.target.dragSelected;this._selectedDragItemLayerUid=i?t.layer.uid:null}_handleCalciteListItemSelect(e,t,i){h(e.target)===t&&"none"===this.selectionMode&&"inherited"!==i?.visibilityMode&&this._toggleVisibility(t,i)}_togglePanel(e){e.open=!e.open,e.open&&(this._focusPanelFlowItem=!0)}_toggleVisibility(e,t){if(!e)return;const i=t?.visibilityMode;"exclusive"===i&&e.visible||(e.visible=!e.visible)}_renderEditingInput(){const{messages:e}=this,{basemapTitle:t}=this.viewModel;return M("div",{class:m.editing},M("calcite-label",null,e.basemapTitle,M("calcite-input",{afterCreate:e=>this._editTitleInput=e,label:e.basemapTitle,name:"basemaptitle",pattern:S,placeholder:e.basemapTitle,required:!0,title:e.basemapTitle,type:"text",value:t??void 0})))}_renderCancelButton(){const{messagesCommon:{cancel:e}}=this;return M("calcite-button",{appearance:"outline",bind:this,label:e,onclick:this._toggleEditingTitle,slot:"footer",title:e,width:"half"},e)}_renderSubmitButton(){const{messagesCommon:e}=this;return M("calcite-button",{label:e.form.submit,slot:"footer",title:e.form.submit,type:"submit",width:"half"},e.form.ok)}_renderEditingForm(){return this.editingTitle?M("form",{bind:this,onsubmit:this._formSubmit},M("calcite-flow-item",{afterCreate:this._focusEditingFlowItemNode,afterUpdate:this._focusEditingFlowItemNode,bind:this,heading:this.visibleElements.heading?this.messages.basemapTitle:void 0,headingLevel:this.headingLevel,onCalciteFlowItemBack:e=>{e.preventDefault(),this._toggleEditingTitle()}},this._renderEditingInput(),this._renderCancelButton(),this._renderSubmitButton())):null}_renderEditTitleButton(){const{editingTitle:e,visibleElements:{editTitleButton:t},messagesCommon:{edit:i}}=this;return t&&!e?M("calcite-action",{bind:this,icon:"pencil",label:i,onclick:this._toggleEditingTitle,slot:"header-actions-end",text:i,title:i}):null}_renderNoLayersInfoMessage(e){return M("div",{slot:"message"},e)}_renderNoLayersInfo(e,t){return M("div",{class:m.itemMessage},M("calcite-notice",{icon:"information",key:t,kind:"info",open:!0,scale:"m",width:"full"},this._renderNoLayersInfoMessage(e)))}_getFilteredItems(e){return e?.filter((e=>!e.hidden&&(this.visibleElements.errors||!e.error)))}_renderItems(){const{collapsed:e,visible:t,visibleElements:{closeButton:i,collapseButton:s,heading:n,flow:o},messages:l,viewModel:r,referenceItems:a,baseItems:c}=this,d=this.visibleElements.referenceLayers?this._getFilteredItems(a):null,m=this.visibleElements.baseLayers?this._getFilteredItems(c):null,p=[M("calcite-flow-item",{afterCreate:this._focusRootFlowItemNode,afterUpdate:this._focusRootFlowItemNode,bind:this,closable:i,closed:!t,collapsed:e,collapsible:s,heading:n?r.basemapTitle??l.widgetLabel:void 0,headingLevel:this.headingLevel,key:"root-flow-item",onCalciteFlowItemClose:()=>this.visible=!1},this._renderEditTitleButton(),this._renderReferenceSection(d),this._renderBaseSection(m,1===m?.length)),this._renderEditingForm(),this._renderPanelFlowItems(m),this._renderPanelFlowItems(d)];return t?[o?M("calcite-flow",{key:"root-flow"},p):p,this._renderItemTooltips(d),this._renderItemTooltips(m)]:null}_renderChildList(e,t,i=[]){const{dragEnabled:s}=this,{children:n}=e,o=I(e),l=!o&&s&&"group"===e.layer?.type;return o||l?M("calcite-list",{canPull:e=>this._canMove(e,"pull"),canPut:e=>this._canMove(e,"put"),"data-basemap-layer-type":t,"data-item":e,"data-layer-type":k,dragEnabled:!!s&&(e.childrenSortable&&E(e)),group:e.layer.uid},n?.filter((e=>!e.hidden)).toArray().map((s=>this._renderItem(s,t,!1,e,[...i,e.title])))):null}_renderList(e,t,i){const{messages:s,dragEnabled:n,selectionMode:o,filterPlaceholder:l,baseFilterText:r,referenceFilterText:a,_baseFilterEnabled:c,_referenceFilterEnabled:d}=this,p="reference"===t?s.noReferenceLayers:s.noBaseLayers,u="reference"===t?d:c;return M("calcite-block",{class:m.section,collapsible:!0,heading:"reference"===t?s.referenceHeading:s.baseHeading,headingLevel:F(this.headingLevel),key:`block-${t}`,open:!0},0===e?.length?this._renderNoLayersInfo(p,t):null,M("calcite-list",{afterCreate:e=>{e.addEventListener("focusin",this._setActiveItem),e.addEventListener("focusout",this._clearActiveItem)},afterRemoved:e=>{e.removeEventListener("focusin",this._setActiveItem),e.removeEventListener("focusout",this._clearActiveItem)},canPull:e=>this._canMove(e,"pull"),canPut:e=>this._canMove(e,"put"),"data-basemap-layer-type":t,"data-layer-type":k,dragEnabled:n,filterEnabled:u,filterPlaceholder:l,filterText:"reference"===t?a:r,group:v,key:`list-${t}`,label:s.widgetLabel,onmouseleave:this._clearActiveItem,onmouseover:this._setActiveItem,selectionAppearance:"border",selectionMode:o,onCalciteListChange:e=>this._handleCalciteListChange(e),onCalciteListDragEnd:e=>this._handleCalciteListDragEnd(e.detail),onCalciteListFilter:e=>this["reference"===t?"referenceFilterText":"baseFilterText"]=e.target?.filterText??"",onCalciteListOrderChange:e=>this._onCalciteListOrderChange(e.detail)},e?.toArray().map((e=>this._renderItem(e,t,i))),e?.length&&u?M("div",{class:m.filterNoResults,slot:"filter-no-results"},M("calcite-notice",{kind:"info",open:!0,scale:"m",width:"full"},this._renderNoLayersInfoMessage(p))):null))}_renderBaseSection(e,t){return this.visibleElements.baseLayers?this._renderList(e,"base",t):null}_renderReferenceSection(e){return this.visibleElements.referenceLayers?this._renderList(e,"reference",!1):null}_toggleEditingTitle(){const{editingTitle:e}=this,t=!e;this.editingTitle=t,t?this._focusEditingFlowItem=!0:this._focusRootFlowItem=!0}_formSubmit(e){e.preventDefault();const t=this._editTitleInput?.value;t?.trim()&&(this.basemapTitle=t),this._toggleEditingTitle()}};function j(e){return e?.getAttribute("data-basemap-layer-type")}e([n()],x.prototype,"_activeItem",void 0),e([n()],x.prototype,"_tooltipReferenceMap",void 0),e([n()],x.prototype,"_focusRootFlowItem",void 0),e([n()],x.prototype,"_focusPanelFlowItem",void 0),e([n()],x.prototype,"_focusEditingFlowItem",void 0),e([n()],x.prototype,"_baseFilterEnabled",null),e([n()],x.prototype,"_referenceFilterEnabled",null),e([n()],x.prototype,"basemapTitle",null),e([n()],x.prototype,"collapsed",void 0),e([n()],x.prototype,"dragEnabled",void 0),e([n()],x.prototype,"editingTitle",void 0),e([n()],x.prototype,"filterPlaceholder",void 0),e([n()],x.prototype,"baseFilterText",void 0),e([n()],x.prototype,"referenceFilterText",void 0),e([n()],x.prototype,"listItemCanGiveFunction",void 0),e([n()],x.prototype,"listItemCanReceiveFunction",void 0),e([n()],x.prototype,"baseListItemCreatedFunction",null),e([n()],x.prototype,"editingEnabled",null),e([n()],x.prototype,"headingLevel",void 0),e([n()],x.prototype,"iconClass",void 0),e([n()],x.prototype,"label",null),e([n(),C("esri/widgets/BasemapLayerList/t9n/BasemapLayerList")],x.prototype,"messages",void 0),e([n(),C("esri/t9n/common")],x.prototype,"messagesCommon",void 0),e([n()],x.prototype,"minFilterItems",void 0),e([n()],x.prototype,"multipleSelectionEnabled",null),e([n()],x.prototype,"referenceListItemCreatedFunction",null),e([n({readOnly:!0})],x.prototype,"baseItems",null),e([n({readOnly:!0})],x.prototype,"referenceItems",null),e([n()],x.prototype,"selectedItems",void 0),e([n()],x.prototype,"selectionMode",void 0),e([n()],x.prototype,"view",null),e([T("trigger-action"),n({type:c})],x.prototype,"viewModel",void 0),e([n()],x.prototype,"visibilityAppearance",void 0),e([n({type:d,nonNullable:!0})],x.prototype,"visibleElements",void 0),x=e([o("esri.widgets.BasemapLayerList")],x);const B=x;export{B as default};
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import t from"../core/Collection.js";import{deprecatedProperty as i}from"../core/deprecate.js";import s from"../core/Logger.js";import{property as n}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as o}from"../core/accessorSupport/decorators/subclass.js";import{getActionIcon as l,getActionStyles as r}from"../support/actions/actionUtils.js";import a from"./Widget.js";import c from"./BasemapLayerList/BasemapLayerListViewModel.js";import d from"./BasemapLayerList/BasemapLayerListVisibleElements.js";import{css as m}from"./BasemapLayerList/css.js";import p from"./LayerList/ListItem.js";import{minFilterItems as u,getItem as h,getLayerType as g,getStatusIcon as b,getVisibilityIcon as f,sortableRoot as v,sortLayersToIds as _,sortChildLayersToIds as y,listItemHasChildren as I,canSortSublayers as E}from"./LayerList/support/layerListUtils.js";import{loadCalciteComponents as L}from"./support/componentsUtils.js";import{globalCss as w}from"./support/globalCss.js";import{incrementHeadingLevel as F}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as C}from"./support/decorators/messageBundle.js";import{vmEvent as T}from"./support/decorators/vmEvent.js";import{tsx as M}from"./support/jsxFactory.js";const A=t.ofType(p),k="basemap",S=".*\\S+.*";let x=class extends a{constructor(e,t){super(e,t),this._activeItem=null,this._tooltipReferenceMap=new Map,this._editTitleInput=null,this._focusRootFlowItem=!1,this._focusPanelFlowItem=!1,this._focusEditingFlowItem=!1,this._lastDragDetail=null,this._selectedDragItemLayerUid=null,this.collapsed=!1,this.dragEnabled=!1,this.editingTitle=!1,this.filterPlaceholder="",this.baseFilterText="",this.referenceFilterText="",this.listItemCanGiveFunction=null,this.listItemCanReceiveFunction=null,this.headingLevel=2,this.iconClass=m.widgetIcon,this.messages=null,this.messagesCommon=null,this.minFilterItems=u,this.selectedItems=new A,this.selectionMode="none",this.viewModel=new c,this.visibilityAppearance="default",this.visibleElements=new d,this._canMove=({dragEl:e,fromEl:t,toEl:i},s)=>{const n="pull"===s?this.listItemCanGiveFunction:this.listItemCanReceiveFunction,o=h(e);if(!o?.sortable)return!1;const l=h(t),r=g(t),a=h(i),c=g(i),d=!!r&&!!c&&r===c,m={selected:o,from:l,to:a};return t.group&&i.group&&"function"==typeof n?n.call(null,m):d&&"sublayer"!==o?.layer?.type&&"map-image"!==l?.layer?.type&&"map-image"!==a?.layer?.type},this._clearActiveItem=()=>{this._activeItem=null},this._setActiveItem=e=>{if("default"!==this.visibilityAppearance)return;const t=Array.from(e.composedPath()).find((e=>e.classList?.contains(m.item)));this._activeItem=h(t)},this._onCalciteListOrderChange=e=>{const{_lastDragDetail:t}=this,{toEl:i,fromEl:s,dragEl:n,newIndex:o}=e;if(!s||!i||t?.newIndex===o&&t?.dragEl===n&&t?.toEl===i&&t?.fromEl===s)return;this._lastDragDetail=e;const l=s,r=i;if(l!==r)this._moveLayerFromChildList({toEl:r,fromEl:l,dragEl:n,newIndex:o});else{const e=Array.from(s.children).filter((e=>e?.matches("calcite-list-item"))).map((e=>e.value));this._sortLayers(l,e)}}}normalizeCtorArgs(e){return null!=e?.editingEnabled&&null!=e.visibleElements?{...e,visibleElements:new d({...e.visibleElements,editTitleButton:e.editingEnabled})}:e}loadDependencies(){return L({action:()=>import("@esri/calcite-components/dist/components/calcite-action.js"),"action-group":()=>import("@esri/calcite-components/dist/components/calcite-action-group.js"),"action-menu":()=>import("@esri/calcite-components/dist/components/calcite-action-menu.js"),block:()=>import("@esri/calcite-components/dist/components/calcite-block.js"),label:()=>import("@esri/calcite-components/dist/components/calcite-label.js"),input:()=>import("@esri/calcite-components/dist/components/calcite-input.js"),button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow.js"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice.js"),tooltip:()=>import("@esri/calcite-components/dist/components/calcite-tooltip.js")})}destroy(){this._tooltipReferenceMap.clear()}get _baseFilterEnabled(){return this.viewModel.totalBaseItems>=this.minFilterItems&&this.visibleElements.filter}get _referenceFilterEnabled(){return this.viewModel.totalReferenceItems>=this.minFilterItems&&this.visibleElements.filter}get basemapTitle(){return this.viewModel.basemapTitle}set basemapTitle(e){this.viewModel.basemapTitle=e}get baseListItemCreatedFunction(){return this.viewModel.baseListItemCreatedFunction}set baseListItemCreatedFunction(e){this.viewModel.baseListItemCreatedFunction=e}get editingEnabled(){return i(s.getLogger(this),"editingEnabled",{replacement:"selectionMode, dragEnabled, visibleElements.editTitleButton",version:"4.29",warnOnce:!0}),"none"!==this.selectionMode&&this.dragEnabled&&this.visibleElements.editTitleButton}set editingEnabled(e){i(s.getLogger(this),"editingEnabled",{replacement:"selectionMode, dragEnabled, visibleElements.editTitleButton",version:"4.29",warnOnce:!0}),this.dragEnabled=e,this.visibleElements.editTitleButton=e,this.selectionMode=e?this.multipleSelectionEnabled?"multiple":"single":"none"}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get multipleSelectionEnabled(){return i(s.getLogger(this),"multipleSelectionEnabled",{replacement:"selectionMode",version:"4.29",warnOnce:!0}),"multiple"===this.selectionMode}set multipleSelectionEnabled(e){i(s.getLogger(this),"multipleSelectionEnabled",{replacement:"selectionMode",version:"4.29",warnOnce:!0}),this.selectionMode=e?"multiple":this.editingEnabled?"single":"none"}get referenceListItemCreatedFunction(){return this.viewModel.referenceListItemCreatedFunction}set referenceListItemCreatedFunction(e){this.viewModel.referenceListItemCreatedFunction=e}get baseItems(){return this.viewModel.baseItems}get referenceItems(){return this.viewModel.referenceItems}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}triggerAction(e,t){return this.viewModel.triggerAction(e,t)}render(){const{state:e}=this.viewModel,t={[w.hidden]:"loading"===e,[w.disabled]:"disabled"===e};return M("div",{class:this.classes(m.base,w.widget,w.panel,t)},this._renderItems())}_renderItemTooltip(e){return e?M("calcite-tooltip",{key:`tooltip-${e.layer.uid}`,referenceElement:this._tooltipReferenceMap.get(e.layer.uid)},this.messages.layerIncompatibleTooltip):null}_renderItemTooltipNodes(e){return e.incompatible?this._renderItemTooltip(e):e.children?.filter((e=>!e.hidden)).toArray().map((e=>this._renderItemTooltipNodes(e)))}_renderItemTooltips(e){return e?.toArray().map((e=>this._renderItemTooltipNodes(e)))}_renderPanelFlowItems(e){return e?e.flatten((e=>e.children)).filter((e=>!e.hidden)).toArray().filter((({panel:e})=>e?.open&&!e.disabled&&e.flowEnabled)).map((({title:e,panel:t})=>{const i=()=>this._handlePanelFlowItemBack(t);return M("calcite-flow-item",{afterCreate:this._focusPanelFlowItemNode,afterUpdate:this._focusPanelFlowItemNode,bind:this,description:e,heading:t.title,headingLevel:this.headingLevel,key:`flow-panel-${t.uid}`,onCalciteFlowItemBack:e=>{e.preventDefault(),i()}},t.render(),M("calcite-button",{appearance:"transparent",onclick:i,slot:"footer-actions",width:"full"},this.messagesCommon.back))})):[]}_handlePanelFlowItemBack(e){e.open=!1,this._focusRootFlowItem=!0}_focusEditingFlowItemNode(e){this._focusEditingFlowItem&&(this._focusEditingFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_focusRootFlowItemNode(e){this._focusRootFlowItem&&(this._focusRootFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_focusPanelFlowItemNode(e){this._focusPanelFlowItem&&(this._focusPanelFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_renderItemMessage(e){return e.error?M("div",{class:m.itemMessage,key:"esri-layer-list__error",slot:"content-bottom"},M("calcite-notice",{icon:"exclamation-mark-triangle",kind:"warning",open:!0,scale:"s",width:"full"},M("div",{slot:"message"},this.messages.layerError))):e.incompatible?M("div",{class:m.itemMessage,key:"esri-layer-list__incompatible",slot:"content-bottom"},M("calcite-notice",{afterCreate:t=>this._setTooltipReference(t,e),afterRemoved:()=>this._removeTooltipReference(e),icon:"exclamation-mark-triangle",kind:"warning",open:!0,scale:"s",tabIndex:0,width:"full"},M("div",{slot:"message"},this.messages.layerIncompatible))):null}_renderItem(e,t,i,s,n){const{_activeItem:o,_selectedDragItemLayerUid:l,selectionMode:r,selectedItems:a,messages:c}=this,d=e.title||c.untitledLayer,p=e.visibleAtCurrentScale?d:`${d} (${c.layerInvisibleAtScale})`,u=this._filterActions(e.actionsSections),h=this._countActions(u);return M("calcite-list-item",{afterCreate:t=>this._focusSelectedDragEl(t,e),afterUpdate:t=>this._focusSelectedDragEl(t,e),class:this.classes(m.item,{[m.itemActive]:o===e}),"data-item":e,dragDisabled:!e.sortable||i,dragSelected:e.layer.uid===l,id:e.layer.uid,key:`list-item-${e.layer.uid}`,label:d,metadata:{parentTitles:n,title:d},open:e.open,selected:"none"!==r&&a.includes(e),title:p,value:e.layer.uid,onCalciteListItemDragHandleChange:t=>this._handleCalciteListItemDragHandleChange(t,e),onCalciteListItemSelect:t=>this._handleCalciteListItemSelect(t,e,s),onCalciteListItemToggle:t=>this._handleCalciteListItemToggle(t,e)},M("div",{class:this.classes({[m.itemContent]:!0,[m.itemInvisibleAtScale]:!e.visibleAtCurrentScale}),slot:"content"},d),this._renderItemStatus(e,s),this._renderItemToggle(e,s),this._renderItemTemporaryIcon(e),this._renderChildList(e,t,n),this._renderItemMessage(e),this._renderPanel(e.panel),this._renderPanelAction(e.panel),h>1?this._renderActionsSections(e,u):1===h?this._renderAction({item:e,action:this._getSingleActionButton(u),textEnabled:!1}):null)}_renderItemStatus(e,t){const{visibleElements:i}=this;if(!i.statusIndicators)return null;const{connectionStatus:s,publishing:n,updating:o}=e,l=o&&!t,r=!!s;return M("calcite-icon",{class:this.classes({[m.statusIndicator]:!0,[m.publishing]:n,[m.updating]:l,[m.connectionStatus]:r,[m.connectionStatusConnected]:r&&"connected"===s}),icon:b({connectionStatus:s,publishing:n}),key:"layer-item-status",scale:"s",slot:"actions-end"})}_renderItemTemporaryIcon(e){return this.visibleElements.temporaryLayerIndicators&&"persistenceEnabled"in e.layer&&!e.layer.persistenceEnabled?M("calcite-icon",{class:m.itemTemporaryIcon,icon:"temporary",key:"temporary-icon",scale:"s",slot:"actions-start",title:this.messages.temporary}):null}_renderItemToggle(e,t){const{messages:i,visibilityAppearance:s}=this,{visible:n}=e,o=t?.visibilityMode;if("inherited"===o)return null;const l=f({visible:n,exclusive:"exclusive"===o,visibilityAppearance:s}),r="checkbox"===s;return M("calcite-action",{appearance:"transparent",class:m.visibleToggle,icon:r?l:void 0,key:"visibility-toggle",onclick:()=>this._toggleVisibility(e,t),scale:"s",slot:r?"actions-start":"actions-end",text:i.layerVisibility,title:i.layerVisibility},r?null:M("calcite-icon",{class:this.classes({[m.visibleIcon]:"exclusive"!==o&&n}),icon:l,scale:"s"}))}_renderPanel(e){return!e?.open||e.disabled||e.flowEnabled?null:M("div",{class:m.itemContentBottom,key:`content-panel-${e.uid}`,slot:"content-bottom"},e.render())}_renderPanelAction(e){if(!e?.visible)return null;const{open:t,title:i,disabled:s}=e;return M("calcite-action",{active:t,appearance:"transparent",disabled:s,icon:l(e),key:`action-${e.uid}`,onclick:()=>this._togglePanel(e),scale:"s",slot:"actions-end",text:i??"",title:i??void 0},this._renderFallbackIcon(e))}_renderActionsSections(e,t){return M("calcite-action-menu",{appearance:"transparent",key:"item-action-menu",label:this.messagesCommon.menu,open:e.actionsOpen,overlayPositioning:"fixed",placement:"bottom-end",scale:"s",slot:"actions-end",onCalciteActionMenuOpen:t=>e.actionsOpen=t.target.open},M("calcite-action",{appearance:"transparent",icon:"ellipsis",scale:"s",slot:"trigger",text:this.messagesCommon.options,title:this.messagesCommon.options}),t.toArray().map(((t,i)=>this._renderActionSection(e,t,i))))}_renderActionSection(e,t,i){return M("calcite-action-group",{key:`action-section-${i}`},t.toArray().map((t=>this._renderAction({item:e,action:t,textEnabled:!0}))))}_renderFallbackIcon(e){const{className:t,icon:i}=e;if(i)return null;const s="image"in e?e.image:void 0,n={[m.itemActionIcon]:!!t,[m.itemActionImage]:!!s};return t&&(n[t]=!0),s||t?M("span",{"aria-hidden":"true",class:this.classes(m.itemActionIcon,n),key:"icon",styles:r(s)}):null}_renderAction(e){const{item:t,action:i,textEnabled:s}=e,{active:n,disabled:o,title:r,type:a,indicator:c}=i;return M("calcite-action",{active:"toggle"===a&&i.value,appearance:"transparent",disabled:o,icon:l(i),indicator:c,key:`action-${i.uid}`,loading:n,onclick:()=>this._triggerAction(t,i),scale:"s",slot:s?void 0:"actions-end",text:r??"",textEnabled:s,title:r??void 0},this._renderFallbackIcon(i))}_setTooltipReference(e,t){this._tooltipReferenceMap.set(t.layer.uid,e)}_removeTooltipReference(e){this._tooltipReferenceMap.delete(e.layer.uid)}_moveLayerFromChildList({toEl:e,fromEl:t,dragEl:i,newIndex:s}){const n=h(i),o=h(e),l=h(t),r=j(t),a=j(e);r&&a&&this.viewModel.moveListItem({targetItem:n,fromParentItem:l,toParentItem:o,newIndex:s,from:r,to:a})}_handleCalciteListDragEnd(e){const{fromEl:t,dragEl:i,oldIndex:s}=e;t.insertBefore(i,t.children[s])}_sortLayers(e,t){if(e)if(e.group===v){const i=j(e),s="base"===i?this.view?.map?.basemap?.baseLayers:"reference"===i?this.view?.map?.basemap?.referenceLayers:null;_(s,t)}else{const i=h(e);if(!i)return;y(i,t)}}_getSingleActionButton(e){return e.reduce((e=>e)).filter((e=>e&&"button"===e.type)).at(0)}_filterActions(e){return e.map((e=>e.filter((e=>e.visible))))}_countActions(e){return e.reduce(((e,t)=>e+t.length),0)}_triggerAction(e,t){t&&e&&("toggle"===t.type&&(t.value=!t.value),this.triggerAction(t,e))}_handleCalciteListChange(e){const{selectionMode:t,selectedItems:i}=this;if("none"===t)return;const s=e.target.selectedItems.map((e=>h(e))).filter(Boolean);i.removeAll(),i.addMany(s)}_handleCalciteListItemToggle(e,t){e.stopPropagation(),t.open=e.target.open}_focusSelectedDragEl(e,t){this._selectedDragItemLayerUid===t.layer.uid&&requestAnimationFrame((()=>e?.setFocus()))}_handleCalciteListItemDragHandleChange(e,t){e.stopPropagation();const i=e.target.dragSelected;this._selectedDragItemLayerUid=i?t.layer.uid:null}_handleCalciteListItemSelect(e,t,i){h(e.target)===t&&"none"===this.selectionMode&&"inherited"!==i?.visibilityMode&&this._toggleVisibility(t,i)}_togglePanel(e){e.open=!e.open,e.open&&(this._focusPanelFlowItem=!0)}_toggleVisibility(e,t){if(!e)return;const i=t?.visibilityMode;"exclusive"===i&&e.visible||(e.visible=!e.visible)}_renderEditingInput(){const{messages:e}=this,{basemapTitle:t}=this.viewModel;return M("div",{class:m.editing},M("calcite-label",null,e.basemapTitle,M("calcite-input",{afterCreate:e=>this._editTitleInput=e,label:e.basemapTitle,name:"basemaptitle",pattern:S,placeholder:e.basemapTitle,required:!0,title:e.basemapTitle,type:"text",value:t??void 0})))}_renderCancelButton(){const{messagesCommon:{cancel:e}}=this;return M("calcite-button",{appearance:"outline",bind:this,label:e,onclick:this._toggleEditingTitle,slot:"footer",title:e,width:"half"},e)}_renderSubmitButton(){const{messagesCommon:e}=this;return M("calcite-button",{label:e.form.submit,slot:"footer",title:e.form.submit,type:"submit",width:"half"},e.form.ok)}_renderEditingForm(){return this.editingTitle?M("form",{bind:this,onsubmit:this._formSubmit},M("calcite-flow-item",{afterCreate:this._focusEditingFlowItemNode,afterUpdate:this._focusEditingFlowItemNode,bind:this,heading:this.visibleElements.heading?this.messages.basemapTitle:void 0,headingLevel:this.headingLevel,onCalciteFlowItemBack:e=>{e.preventDefault(),this._toggleEditingTitle()}},this._renderEditingInput(),this._renderCancelButton(),this._renderSubmitButton())):null}_renderEditTitleButton(){const{editingTitle:e,visibleElements:{editTitleButton:t},messagesCommon:{edit:i}}=this;return t&&!e?M("calcite-action",{bind:this,icon:"pencil",label:i,onclick:this._toggleEditingTitle,slot:"header-actions-end",text:i,title:i}):null}_renderNoLayersInfoMessage(e){return M("div",{slot:"message"},e)}_renderNoLayersInfo(e,t){return M("div",{class:m.itemMessage},M("calcite-notice",{icon:"information",key:t,kind:"info",open:!0,scale:"m",width:"full"},this._renderNoLayersInfoMessage(e)))}_getFilteredItems(e){return e?.filter((e=>!e.hidden&&(this.visibleElements.errors||!e.error)))}_renderItems(){const{collapsed:e,visible:t,visibleElements:{closeButton:i,collapseButton:s,heading:n,flow:o},messages:l,viewModel:r,referenceItems:a,baseItems:c}=this,d=this.visibleElements.referenceLayers?this._getFilteredItems(a):null,m=this.visibleElements.baseLayers?this._getFilteredItems(c):null,p=[M("calcite-flow-item",{afterCreate:this._focusRootFlowItemNode,afterUpdate:this._focusRootFlowItemNode,bind:this,closable:i,closed:!t,collapsed:e,collapsible:s,heading:n?r.basemapTitle??l.widgetLabel:void 0,headingLevel:this.headingLevel,key:"root-flow-item",onCalciteFlowItemClose:()=>this.visible=!1},this._renderEditTitleButton(),this._renderReferenceSection(d),this._renderBaseSection(m,1===m?.length)),this._renderEditingForm(),this._renderPanelFlowItems(m),this._renderPanelFlowItems(d)];return t?[o?M("calcite-flow",{key:"root-flow"},p):p,this._renderItemTooltips(d),this._renderItemTooltips(m)]:null}_renderChildList(e,t,i=[]){const{dragEnabled:s}=this,{children:n}=e,o=I(e),l=!o&&s&&"group"===e.layer?.type;return o||l?M("calcite-list",{canPull:e=>this._canMove(e,"pull"),canPut:e=>this._canMove(e,"put"),"data-basemap-layer-type":t,"data-item":e,"data-layer-type":k,dragEnabled:!!s&&(e.childrenSortable&&E(e)),group:e.layer.uid},n?.filter((e=>!e.hidden)).toArray().map((s=>this._renderItem(s,t,!1,e,[...i,e.title])))):null}_renderList(e,t,i){const{messages:s,dragEnabled:n,selectionMode:o,filterPlaceholder:l,baseFilterText:r,referenceFilterText:a,_baseFilterEnabled:c,_referenceFilterEnabled:d}=this,p="reference"===t?s.noReferenceLayers:s.noBaseLayers,u="reference"===t?d:c;return M("calcite-block",{class:m.section,collapsible:!0,heading:"reference"===t?s.referenceHeading:s.baseHeading,headingLevel:F(this.headingLevel),key:`block-${t}`,open:!0},0===e?.length?this._renderNoLayersInfo(p,t):null,M("calcite-list",{afterCreate:e=>{e.addEventListener("focusin",this._setActiveItem),e.addEventListener("focusout",this._clearActiveItem)},afterRemoved:e=>{e.removeEventListener("focusin",this._setActiveItem),e.removeEventListener("focusout",this._clearActiveItem)},canPull:e=>this._canMove(e,"pull"),canPut:e=>this._canMove(e,"put"),"data-basemap-layer-type":t,"data-layer-type":k,dragEnabled:n,filterEnabled:u,filterPlaceholder:l,filterText:"reference"===t?a:r,group:v,key:`list-${t}`,label:s.widgetLabel,onmouseleave:this._clearActiveItem,onmouseover:this._setActiveItem,selectionAppearance:"border",selectionMode:o,onCalciteListChange:e=>this._handleCalciteListChange(e),onCalciteListDragEnd:e=>this._handleCalciteListDragEnd(e.detail),onCalciteListFilter:e=>this["reference"===t?"referenceFilterText":"baseFilterText"]=e.target?.filterText??"",onCalciteListOrderChange:e=>this._onCalciteListOrderChange(e.detail)},e?.toArray().map((e=>this._renderItem(e,t,i))),e?.length&&u?M("div",{class:m.filterNoResults,slot:"filter-no-results"},M("calcite-notice",{kind:"info",open:!0,scale:"m",width:"full"},this._renderNoLayersInfoMessage(p))):null))}_renderBaseSection(e,t){return this.visibleElements.baseLayers?this._renderList(e,"base",t):null}_renderReferenceSection(e){return this.visibleElements.referenceLayers?this._renderList(e,"reference",!1):null}_toggleEditingTitle(){const{editingTitle:e}=this,t=!e;this.editingTitle=t,t?this._focusEditingFlowItem=!0:this._focusRootFlowItem=!0}_formSubmit(e){e.preventDefault();const t=this._editTitleInput?.value;t?.trim()&&(this.basemapTitle=t),this._toggleEditingTitle()}};function j(e){return e?.getAttribute("data-basemap-layer-type")}e([n()],x.prototype,"_activeItem",void 0),e([n()],x.prototype,"_tooltipReferenceMap",void 0),e([n()],x.prototype,"_focusRootFlowItem",void 0),e([n()],x.prototype,"_focusPanelFlowItem",void 0),e([n()],x.prototype,"_focusEditingFlowItem",void 0),e([n()],x.prototype,"_baseFilterEnabled",null),e([n()],x.prototype,"_referenceFilterEnabled",null),e([n()],x.prototype,"basemapTitle",null),e([n()],x.prototype,"collapsed",void 0),e([n()],x.prototype,"dragEnabled",void 0),e([n()],x.prototype,"editingTitle",void 0),e([n()],x.prototype,"filterPlaceholder",void 0),e([n()],x.prototype,"baseFilterText",void 0),e([n()],x.prototype,"referenceFilterText",void 0),e([n()],x.prototype,"listItemCanGiveFunction",void 0),e([n()],x.prototype,"listItemCanReceiveFunction",void 0),e([n()],x.prototype,"baseListItemCreatedFunction",null),e([n()],x.prototype,"editingEnabled",null),e([n()],x.prototype,"headingLevel",void 0),e([n()],x.prototype,"iconClass",void 0),e([n()],x.prototype,"label",null),e([n(),C("esri/widgets/BasemapLayerList/t9n/BasemapLayerList")],x.prototype,"messages",void 0),e([n(),C("esri/t9n/common")],x.prototype,"messagesCommon",void 0),e([n()],x.prototype,"minFilterItems",void 0),e([n()],x.prototype,"multipleSelectionEnabled",null),e([n()],x.prototype,"referenceListItemCreatedFunction",null),e([n({readOnly:!0})],x.prototype,"baseItems",null),e([n({readOnly:!0})],x.prototype,"referenceItems",null),e([n()],x.prototype,"selectedItems",void 0),e([n()],x.prototype,"selectionMode",void 0),e([n()],x.prototype,"view",null),e([T("trigger-action"),n({type:c})],x.prototype,"viewModel",void 0),e([n()],x.prototype,"visibilityAppearance",void 0),e([n({type:d,nonNullable:!0})],x.prototype,"visibleElements",void 0),x=e([o("esri.widgets.BasemapLayerList")],x);const B=x;export{B as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as t}from"../../chunks/tslib.es6.js";import{createTask as e}from"../../core/asyncUtils.js";import a from"../../core/Collection.js";import{deprecatedProperty as i,deprecated as r}from"../../core/deprecate.js";import s from"../../core/Error.js";import o from"../../core/Evented.js";import{makeHandle as n}from"../../core/handleUtils.js";import l from"../../core/Logger.js";import{abortMaybe as d,removeMaybe as p,destroyMaybe as c}from"../../core/maybe.js";import{throwIfAborted as u,createResolver as h}from"../../core/promiseUtils.js";import{watch as w,on as f,when as m,whenOnce as y,syncAndInitial as k,initial as g,sync as v}from"../../core/reactiveUtils.js";import{property as _}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as W}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as b}from"../../core/support/UpdatingHandles.js";import I from"../../layers/GraphicsLayer.js";import{isEditableLayer as F}from"../../layers/support/editableLayers.js";import{isTable as M,isFeatureLayer as E,getOwningPortalUrl as O}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as C}from"../../portal/support/urlUtils.js";import U from"../../views/interactive/sketch/SketchOptions.js";import{SnappingManager as V}from"../../views/interactive/snapping/SnappingManager.js";import L from"../../views/interactive/snapping/SnappingOptions.js";import A from"../Attachments/AttachmentsViewModel.js";import T from"./CreateFeaturesWorkflow.js";import j from"./UpdateWorkflow.js";import{whenEditorLayerView as S}from"./workflowUtils.js";import P from"./support/EditorItem.js";import R from"../FeatureTemplates/FeatureTemplatesViewModel.js";import H from"../Sketch/SketchViewModel.js";import x from"../Spinner/SpinnerViewModel.js";const G="esri.widgets.Editor.EditorViewModel",D=()=>l.getLogger(G),q=["create-features","update"];function B(t,e,a){D().error(new s(t,e,a))}function Q(t,e){return t?.find((t=>t.layer===e))}let N=class extends o.EventedAccessor{constructor(t){super(t),this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new I({listMode:"hide",internal:!0}),this._snappingManager=null,this._updateItemsTask=null,this._updatingHandles=new b,this._featureTemplatesViewModelLocked=!1,this.activeWorkflow=null,this._activityQueue=[],this.editorItems=new a,this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new A({capabilities:{editing:!0}}),this.featureTemplatesViewModel=new R({disabledItemFunction:({layer:t})=>this._itemIsSuspended(t)}),this.ownSketchViewModel=new H({layer:this._sketchGraphicsLayer}),this.sketchOptions=new U,this.snappingOptions=new L,this.spinnerViewModel=new x,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.back=async()=>{this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>{const{featureFormViewModel:t}=this;if(t){if(t.submit(),!t.submittable)return;const e=t.getValues();if(t.validateContingencyConstraints(e,{includeIncompleteViolations:!0}).length>0)return}await(this.activeWorkflow?.save())},this.selectFeature=(t,e=!1)=>{const a=this.activeWorkflow;this._candidateCommitted||"update"!==a?.type||(a.data.rootFeature=t,e&&(a.next(),this._candidateCommitted=!0))}}initialize(){this.addHandles([w((()=>{const t=this.view?.map?.editableLayers.filter((({parent:t,visible:e})=>t&&"visible"in t?e&&t.visible:e)),e=this.view?.allLayerViews,a=e?.filter((e=>!!t?.includes(e.layer)&&!e.suspended));return[t,a,this.layerInfos,this.allowedWorkflows,this.hideTemplatesForInactiveLayers]}),(()=>this._updateEditorItems()),k),f((()=>this.activeWorkflow),"cancel",(()=>this.emit("workflow-cancel"))),f((()=>this.activeWorkflow),"commit",(()=>this.emit("workflow-commit"))),f((()=>this.activeWorkflow),"complete",(()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)})),m((()=>this.view?.map),(t=>t.add(this._sketchGraphicsLayer)),g),w((()=>this.editorItems.toArray()),(()=>{const{activeWorkflow:t}=this;if(this.syncFeatureTemplates(),!t)return;const{stepId:e}=t;"create-features"!==t.type?"update"===t.type&&("awaiting-feature-to-update"===e&&!this.canUpdate||"awaiting-update-feature-candidate"===e&&!t.data.candidates.some((t=>this.findEditorItemForLayer(t.layer)?.capabilities.update.enabled)))&&this._cancelWorkflow():"awaiting-feature-creation-info"!==e||this.canCreate||this._cancelWorkflow()})),w((()=>this.page),((t,e)=>{const a=[...this.pageStack];if(-1===a.indexOf(t))a.push(t);else for(;a.length&&a.at(-1)!==t;)a.pop();this.pageStack=a}),k),m((()=>"awaiting-update-feature-candidate"===this.state),(()=>this._candidateCommitted=!1)),f((()=>this.featureTemplatesViewModel),"select",(async({item:t,oldItem:e})=>{const{activeWorkflow:a}=this;if(a){if("update"===a.type&&"awaiting-feature-creation-info"===a.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(e,{emit:!1})}}if(!t)return;const i={layer:t.layer,template:t.template};if(t.supportsUpload)return this.featureTemplatesViewModel.select(e,{emit:!1}),this.startCreateFeaturesWorkflow(i);this.startCreateFeaturesWorkflowAtFeatureCreation(i)})),f((()=>this.view),"key-down",(t=>{"Escape"===t.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(t.stopPropagation(),this.back())})),f((()=>this.sketchViewModel),["create","delete","update"],(t=>{const{activeWorkflow:e}=this,a="update"===e?.type,i=a?e.activeWorkflow?.layer:e?.layer,r=a?e?.activeWorkflow?.parentLayer:void 0,s=`sketch-${t.type}`;this.emit(s,{type:s,detail:t,layer:i,parentLayer:r})}),v),w((()=>this.view),(t=>{if(this._snappingManager=c(this._snappingManager),!t)return;const e=this.snappingOptions;this._snappingManager=new V({view:t,options:e})}),k),w((()=>this.snappingOptions),(t=>{this._snappingManager&&(this._snappingManager.options=t)}),k)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then((()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null})),this._updateItemsTask=d(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=p(this._sketchEventListenerHandle)}get allowedWorkflows(){return this._get("allowedWorkflows")}set allowedWorkflows(t){i(l.getLogger(this),"allowedWorkflows",{replacement:"Editor.visibleElements",version:"4.29",warnOnce:!0}),t&&0!==t.length||(t=[...q]),this._set("allowedWorkflows",t)}get canCreate(){return this.editorItems.some((t=>t.supportsCreateFeaturesWorkflow))}get canUpdate(){return this.editorItems.some((t=>t.supportsUpdateWorkflow))}get editableItems(){return i(l.getLogger(this),"editableItems",{replacement:"editorItems",version:"4.29",warnOnce:!0}),this.editorItems.map((t=>{const{capabilities:e,disabled:a,hasInvalidFormTemplate:i,layer:r}=t,s=[],o=e.create,n=e.update,l=e.delete;return o.enabled&&s.push("create"),n.enabled&&s.push("update"),l.enabled&&s.push("delete"),{layer:r,supports:s,suspended:a,attributeUpdatesEnabled:n.attributes,geometryUpdatesEnabled:n.geometry,attachmentsOnCreateEnabled:o.attachments.enabled,attachmentsOnUpdateEnabled:n.attachments.enabled,hasInvalidFormTemplate:i,hasAttachments:e.attachments.enabled}}))}get featureFormViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeFeatureFormViewModel:"create-features"===t?.type?t.featureFormViewModel:null}get labelOptions(){return this.sketchOptions.labels}set labelOptions(t){this.sketchOptions.labels=t}set layerInfos(t){const e=t?.some((t=>"allowAttachments"in t));e&&r(D(),"Property: layerInfo.allowAttachments",{replacement:"layerInfo.attachmentsOnCreateEnabled or layerInfo.attachmentsOnUpdateEnabled",version:"4.26"}),this._set("layerInfos",t)}get sketchViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeSketchViewModel:"create-features"===t?.type?t.sketchViewModel:this.ownSketchViewModel}get state(){if(!this.view?.ready)return"disabled";const t=this.attachmentsViewModel.mode;if("add"===t)return"adding-attachment";if("edit"===t)return"editing-attachment";const{activeWorkflow:e}=this;return e?.stepId?"update"===e.type&&e.activeWorkflow?.stepId?e.activeWorkflow.stepId:e.stepId:"ready"}get syncing(){return this._activityQueue.length>0}get updating(){return this._updatingHandles.updating||!0===this.activeWorkflow?.updating}get tooltipOptions(){return this.sketchOptions.tooltips}set tooltipOptions(t){this.sketchOptions.tooltips=t}get valueOptions(){return this.sketchOptions.values}set valueOptions(t){this.sketchOptions.values=t}set view(t){this.ownSketchViewModel.view=t,this.spinnerViewModel.view=t,this._set("view",t)}get page(){const{activeWorkflow:t,state:e}=this;if("update"===t?.type&&"awaiting-feature-to-update"===t.stepId)return"ready";if("create-features"===t?.type&&0===t.numPendingFeatures){const e=t.data.upload;if(e)return"default"===e.state?"ready":"creating-features-upload-details"}return e??"disabled"}get featureFormDisabled(){const{activeWorkflow:t}=this;return"update"===t?.type&&!1===t.activeEditorItem?.capabilities.update.attributes}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeWorkflow:t}=this;return!!t&&"update"===t.type&&!!t.activeEditorItem?.capabilities.delete.enabled}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(t){return this.startCreateFeaturesWorkflow(t,"creating-features")}async startCreateFeaturesWorkflow(t,e="awaiting-feature-creation-info"){if(await y((()=>!this.updating)),!this.canCreate)throw new s("editing:unsupported-workflow","Creating features is unsupported or disabled.");const a=this._createUpdatingResolver();await this._cancelWorkflow();const i=this._createCreateFeaturesWorkflow(t,e);this._set("activeWorkflow",i),await i.start(),a.resolve()}async startCreateFeaturesWorkflowAtFeatureEdit(t){await y((()=>!this.updating));const e=this._createUpdatingResolver(),{initialFeature:a}=t,i=a.sourceLayer,r=i?this.findEditorItemForLayer(i):void 0;if(!this.canCreate||!r)throw new s("editing:unsupported-workflow","Creating features is unsupported or disabled.");await this._cancelWorkflow();const o=this._createCreateFeaturesWorkflow({initialFeature:a,layer:r.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",o),await o.start(),e.resolve()}async startUpdateWorkflowAtFeatureSelection(){if(await y((()=>!this.updating)),!this.canUpdate)return void B("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();await this._cancelWorkflow();const e=this._createUpdateWorkflow();this._set("activeWorkflow",e),await e.start(),t.resolve()}async startUpdateWorkflowAtMultipleFeatureSelection(t){if(await y((()=>!this.updating)),!this.canUpdate)return void B("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();await this._cancelWorkflow();const a=this._createUpdateWorkflow("awaiting-update-feature-candidate");a.data.candidates=t,this._set("activeWorkflow",a),await a.start(),e.resolve()}async startUpdateWorkflowAtFeatureEdit(t){if(await y((()=>!this.updating)),!this.canUpdate)return void B("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();await this._cancelWorkflow();const a=this._createUpdateWorkflow("editing-existing-feature");a.data.rootFeature=t,this._set("activeWorkflow",a),await a.start(),e.resolve()}async deleteFeatureFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveFeature():B("editing:unsupported-workflow","Deleting requires an active update workflow.")}async cancelWorkflow(t){return this._cancelWorkflow({warnIfNoWorkflow:!0,...t})}findEditorItemForLayer(t){const e="subtype-sublayer"===t.type?t.parent:t;return this.editorItems.find((t=>t.layer===e))}itemHasInvalidFormTemplate(t){return null!=t&&!0===this.findEditorItemForLayer(t.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){if(this._featureTemplatesViewModelLocked)return;const t=[];for(const{capabilities:e,disabled:a,layer:i}of this.editorItems){const r=i.loaded&&e.create.enabled&&!M(i),s=this.hideTemplatesForInactiveLayers&&a;r&&!s&&t.push(i)}this.featureTemplatesViewModel.layers=t}async toggleUpdateWorkflow(){this.canUpdate&&(this.hasPendingEdits&&!await this.showDiscardEditsPrompt()||(this.activeWorkflow&&"awaiting-feature-to-update"===this.state?await this.cancelWorkflow({force:!0}):await this.startUpdateWorkflowAtFeatureSelection()))}lockFeatureTemplatesViewModel(){return this._featureTemplatesViewModelLocked=!0,n((()=>{this._featureTemplatesViewModelLocked=!1,this.syncFeatureTemplates()}))}async _getEditorItemCandidates(t){const{view:e}=this;if(!e?.map)return[];const{map:a}=e,i=a.editableLayers.toArray()??[],r=a.allTables.toArray().filter(E)??[];return await Promise.allSettled([...i.map((t=>"subtype-group"===t.type?t.loadAll():Promise.resolve())),...r.map((t=>t.load()))]),u(t),[...i.reverse(),...r.reverse()].filter((t=>{if(!F(t))return!1;const{geometryType:a,spatialReference:i}=t;if("mesh"===a){if("3d"!==e.type)return!1;const{isGeographic:t,isWebMercator:a}=i;switch(e.viewingMode){case"global":return t||a;case"local":return!t||a}}return!0})).flatMap((t=>"subtype-group"===t.type?t.sublayers.toArray():t))}_drainEditorItems(){this.editorItems.drain((t=>t.destroy()))}async _updateEditorItems(){d(this._updateItemsTask);const{view:t}=this,a=e((async e=>{if(!t?.map||!t?.allLayerViews)return;const a=await this._getEditorItemCandidates(e);if(!a.length)return void this._drainEditorItems();const i=[],r=[],s=[],{layerInfos:o}=this;for(const l of a){const e=Q(o,l),a=await S(t,l).catch((()=>null));(e?i:a?r:s).push(new P({layer:l,layerInfo:e,disabled:!!a?.suspended}))}o?.length&&i.sort(((t,e)=>o.findIndex((({layer:e})=>e===t.layer))-o.findIndex((({layer:t})=>t===e.layer))));const n=[...i,...r,...s];e.aborted||(this._drainEditorItems(),this.editorItems.addMany(n))}));this._updatingHandles.addPromise(a.promise),this._updateItemsTask=a}async _cancelWorkflow(t){const e=this.activeWorkflow;if(!e)return void(t?.warnIfNoWorkflow&&B("editing:no-active-workflow","There is no active workflow to cancel."));if(!t||!1!==t.force)return this.emit("workflow-cancel"),this._set("activeWorkflow",null),void await e.cancel(t);await e.cancel(t),this._set("activeWorkflow",null)}_createCreateFeaturesWorkflow(t,e){return T.create({viewModel:this,creationInfo:t,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:e,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_createUpdateWorkflow(t){return j.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_addAttachments(t,e){const a=e.map((e=>this._addAttachment(t,e.feature,e.attachment)))??[];return Promise.all(a)}async _addAttachment(t,e,a){let i=null;if(!("addAttachment"in t)||null==t.capabilities?.attachment)throw new s("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation((async()=>(i=await(t.addAttachment?.(e,a).catch((t=>{throw t?.error||t})))??null,i))),i}async _applyEdits(t,e,a){let i=null;const r=t.url?await O(t.url):null,s={returnServiceEditsOption:(!r||!C(r))&&!RegExp("/hosted/","i").test(t.url)?"original-and-current-features":void 0,...a};return await this._queueOperation((async()=>{const{view:a}=this;if(!a)return null;const r=await S(a,t).catch((()=>null));return i=await t.applyEdits(e,s),r&&await y((()=>!r.updating)),i})),i}_queueOperation(t){this._activityQueue.push(t),this.notifyChange("syncing");const e=(t,e)=>{const a=e.indexOf(t);a>-1&&e.splice(a,1)};return t().then((t=>{if(null!=t&&"error"in t&&null!=t.error)throw t.error;if(null!=t&&"addFeatureResults"in t){const{addFeatureResults:e,deleteFeatureResults:a,updateFeatureResults:i}=t,r=e.find((t=>!!t.error))||i.find((t=>!!t.error))||a.find((t=>!!t.error));if(r)throw r.error}return t})).catch((a=>{B("editing:operation-error","An error occurred.",{error:a});const i={error:a,retry:()=>(e(i,this.failures),this._queueOperation(t)),cancel:()=>{e(i,this.failures)}};this._set("failures",[...this.failures,i])})).then((()=>{e(t,this._activityQueue),this.notifyChange("syncing")}))}_createUpdatingResolver(){const t=h();return this._updatingHandles.addPromise(t.promise),t}_itemIsSuspended(t){return this.findEditorItemForLayer(t)?.disabled??!1}};t([_({readOnly:!0})],N.prototype,"activeWorkflow",void 0),t([_({readOnly:!0})],N.prototype,"_activityQueue",void 0),t([_({value:[...q]})],N.prototype,"allowedWorkflows",null),t([_({readOnly:!0})],N.prototype,"canCreate",null),t([_({readOnly:!0})],N.prototype,"canUpdate",null),t([_()],N.prototype,"editableItems",null),t([_()],N.prototype,"editorItems",void 0),t([_({readOnly:!0})],N.prototype,"failures",void 0),t([_()],N.prototype,"hideTemplatesForInactiveLayers",void 0),t([_()],N.prototype,"attachmentsViewModel",void 0),t([_()],N.prototype,"featureFormViewModel",null),t([_()],N.prototype,"featureTemplatesViewModel",void 0),t([_()],N.prototype,"labelOptions",null),t([_()],N.prototype,"layerInfos",null),t([_()],N.prototype,"ownSketchViewModel",void 0),t([_()],N.prototype,"sketchOptions",void 0),t([_()],N.prototype,"sketchViewModel",null),t([_({type:L,nonNullable:!0})],N.prototype,"snappingOptions",void 0),t([_()],N.prototype,"spinnerViewModel",void 0),t([_()],N.prototype,"state",null),t([_({readOnly:!0})],N.prototype,"syncing",null),t([_()],N.prototype,"updating",null),t([_()],N.prototype,"tooltipOptions",null),t([_()],N.prototype,"valueOptions",null),t([_()],N.prototype,"view",null),t([_()],N.prototype,"pageStack",void 0),t([_()],N.prototype,"showDiscardEditsPrompt",void 0),t([_()],N.prototype,"_candidateCommitted",void 0),t([_()],N.prototype,"page",null),t([_()],N.prototype,"featureFormDisabled",null),t([_()],N.prototype,"canGoBack",null),t([_()],N.prototype,"shouldShowDeleteButton",null),t([_()],N.prototype,"hasPendingEdits",null),N=t([W(G)],N);const z=N;export{z as default};
|
|
5
|
+
import{_ as t}from"../../chunks/tslib.es6.js";import{createTask as e}from"../../core/asyncUtils.js";import a from"../../core/Collection.js";import{deprecatedProperty as i,deprecated as r}from"../../core/deprecate.js";import s from"../../core/Error.js";import o from"../../core/Evented.js";import{makeHandle as n}from"../../core/handleUtils.js";import l from"../../core/Logger.js";import{abortMaybe as d,removeMaybe as p,destroyMaybe as c}from"../../core/maybe.js";import{throwIfAborted as u,createResolver as h}from"../../core/promiseUtils.js";import{watch as w,on as f,when as m,whenOnce as y,syncAndInitial as k,initial as g,sync as v}from"../../core/reactiveUtils.js";import{property as _}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as W}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as b}from"../../core/support/UpdatingHandles.js";import I from"../../layers/GraphicsLayer.js";import{isEditableLayer as F}from"../../layers/support/editableLayers.js";import{isTable as M,isFeatureLayer as E,getOwningPortalUrl as O}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as C}from"../../portal/support/urlUtils.js";import U from"../../views/interactive/sketch/SketchOptions.js";import{SnappingManager as V}from"../../views/interactive/snapping/SnappingManager.js";import L from"../../views/interactive/snapping/SnappingOptions.js";import A from"../Attachments/AttachmentsViewModel.js";import T from"./CreateFeaturesWorkflow.js";import j from"./UpdateWorkflow.js";import{whenEditorLayerView as S}from"./workflowUtils.js";import P from"./support/EditorItem.js";import R from"../FeatureTemplates/FeatureTemplatesViewModel.js";import H from"../Sketch/SketchViewModel.js";import x from"../Spinner/SpinnerViewModel.js";const G="esri.widgets.Editor.EditorViewModel",D=()=>l.getLogger(G),q=["create-features","update"];function B(t,e,a){D().error(new s(t,e,a))}function Q(t,e){return t?.find((t=>t.layer===e))}let N=class extends o.EventedAccessor{constructor(t){super(t),this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new I({listMode:"hide",internal:!0}),this._snappingManager=null,this._updateItemsTask=null,this._updatingHandles=new b,this._featureTemplatesViewModelLocked=!1,this.activeWorkflow=null,this._activityQueue=new a,this.editorItems=new a,this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new A({capabilities:{editing:!0}}),this.featureTemplatesViewModel=new R({disabledItemFunction:({layer:t})=>this._itemIsSuspended(t)}),this.ownSketchViewModel=new H({layer:this._sketchGraphicsLayer}),this.sketchOptions=new U,this.snappingOptions=new L,this.spinnerViewModel=new x,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.back=async()=>{this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>{const{featureFormViewModel:t}=this;if(t){if(t.submit(),!t.submittable)return;const e=t.getValues();if(t.validateContingencyConstraints(e,{includeIncompleteViolations:!0}).length>0)return}await(this.activeWorkflow?.save())},this.selectFeature=(t,e=!1)=>{const a=this.activeWorkflow;this._candidateCommitted||"update"!==a?.type||(a.data.rootFeature=t,e&&(a.next(),this._candidateCommitted=!0))}}initialize(){this.addHandles([w((()=>{const t=this.view?.map?.editableLayers.filter((({parent:t,visible:e})=>t&&"visible"in t?e&&t.visible:e)),e=this.view?.allLayerViews,a=e?.filter((e=>!!t?.includes(e.layer)&&!e.suspended));return[t,a,this.layerInfos,this.allowedWorkflows,this.hideTemplatesForInactiveLayers]}),(()=>this._updateEditorItems()),k),f((()=>this.activeWorkflow),"cancel",(()=>this.emit("workflow-cancel"))),f((()=>this.activeWorkflow),"commit",(()=>this.emit("workflow-commit"))),f((()=>this.activeWorkflow),"complete",(()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)})),m((()=>this.view?.map),(t=>t.add(this._sketchGraphicsLayer)),g),w((()=>this.editorItems.toArray()),(()=>{const{activeWorkflow:t}=this;if(this.syncFeatureTemplates(),!t)return;const{stepId:e}=t;"create-features"!==t.type?"update"===t.type&&("awaiting-feature-to-update"===e&&!this.canUpdate||"awaiting-update-feature-candidate"===e&&!t.data.candidates.some((t=>this.findEditorItemForLayer(t.layer)?.capabilities.update.enabled)))&&this._cancelWorkflow():"awaiting-feature-creation-info"!==e||this.canCreate||this._cancelWorkflow()})),w((()=>this.page),((t,e)=>{const a=[...this.pageStack];if(-1===a.indexOf(t))a.push(t);else for(;a.length&&a.at(-1)!==t;)a.pop();this.pageStack=a}),k),m((()=>"awaiting-update-feature-candidate"===this.state),(()=>this._candidateCommitted=!1)),f((()=>this.featureTemplatesViewModel),"select",(async({item:t,oldItem:e})=>{const{activeWorkflow:a}=this;if(a){if("update"===a.type&&"awaiting-feature-creation-info"===a.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(e,{emit:!1})}}if(!t)return;const i={layer:t.layer,template:t.template};if(t.supportsUpload)return this.featureTemplatesViewModel.select(e,{emit:!1}),this.startCreateFeaturesWorkflow(i);this.startCreateFeaturesWorkflowAtFeatureCreation(i)})),f((()=>this.view),"key-down",(t=>{"Escape"===t.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(t.stopPropagation(),this.back())})),f((()=>this.sketchViewModel),["create","delete","update"],(t=>{const{activeWorkflow:e}=this,a="update"===e?.type,i=a?e.activeWorkflow?.layer:e?.layer,r=a?e?.activeWorkflow?.parentLayer:void 0,s=`sketch-${t.type}`;this.emit(s,{type:s,detail:t,layer:i,parentLayer:r})}),v),w((()=>this.view),(t=>{if(this._snappingManager=c(this._snappingManager),!t)return;const e=this.snappingOptions;this._snappingManager=new V({view:t,options:e})}),k),w((()=>this.snappingOptions),(t=>{this._snappingManager&&(this._snappingManager.options=t)}),k)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then((()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null})),this._updateItemsTask=d(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=p(this._sketchEventListenerHandle)}get allowedWorkflows(){return this._get("allowedWorkflows")}set allowedWorkflows(t){i(l.getLogger(this),"allowedWorkflows",{replacement:"Editor.visibleElements",version:"4.29",warnOnce:!0}),t&&0!==t.length||(t=[...q]),this._set("allowedWorkflows",t)}get canCreate(){return this.editorItems.some((t=>t.supportsCreateFeaturesWorkflow))}get canUpdate(){return this.editorItems.some((t=>t.supportsUpdateWorkflow))}get editableItems(){return i(l.getLogger(this),"editableItems",{replacement:"editorItems",version:"4.29",warnOnce:!0}),this.editorItems.map((t=>{const{capabilities:e,disabled:a,hasInvalidFormTemplate:i,layer:r}=t,s=[],o=e.create,n=e.update,l=e.delete;return o.enabled&&s.push("create"),n.enabled&&s.push("update"),l.enabled&&s.push("delete"),{layer:r,supports:s,suspended:a,attributeUpdatesEnabled:n.attributes,geometryUpdatesEnabled:n.geometry,attachmentsOnCreateEnabled:o.attachments.enabled,attachmentsOnUpdateEnabled:n.attachments.enabled,hasInvalidFormTemplate:i,hasAttachments:e.attachments.enabled}}))}get featureFormViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeFeatureFormViewModel:"create-features"===t?.type?t.featureFormViewModel:null}get labelOptions(){return this.sketchOptions.labels}set labelOptions(t){this.sketchOptions.labels=t}set layerInfos(t){const e=t?.some((t=>"allowAttachments"in t));e&&r(D(),"Property: layerInfo.allowAttachments",{replacement:"layerInfo.attachmentsOnCreateEnabled or layerInfo.attachmentsOnUpdateEnabled",version:"4.26"}),this._set("layerInfos",t)}get sketchViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeSketchViewModel:"create-features"===t?.type?t.sketchViewModel:this.ownSketchViewModel}get state(){if(!this.view?.ready)return"disabled";const t=this.attachmentsViewModel.mode;if("add"===t)return"adding-attachment";if("edit"===t)return"editing-attachment";const{activeWorkflow:e}=this;return e?.stepId?"update"===e.type&&e.activeWorkflow?.stepId?e.activeWorkflow.stepId:e.stepId:"ready"}get syncing(){return this._activityQueue.length>0}get updating(){return this._updatingHandles.updating||!0===this.activeWorkflow?.updating}get tooltipOptions(){return this.sketchOptions.tooltips}set tooltipOptions(t){this.sketchOptions.tooltips=t}get valueOptions(){return this.sketchOptions.values}set valueOptions(t){this.sketchOptions.values=t}set view(t){this.ownSketchViewModel.view=t,this.spinnerViewModel.view=t,this._set("view",t)}get page(){const{activeWorkflow:t,state:e}=this;if("update"===t?.type&&"awaiting-feature-to-update"===t.stepId)return"ready";if("create-features"===t?.type&&0===t.numPendingFeatures){const e=t.data.upload;if(e)return"default"===e.state?"ready":"creating-features-upload-details"}return e??"disabled"}get featureFormDisabled(){const{activeWorkflow:t}=this;return"update"===t?.type&&!1===t.activeEditorItem?.capabilities.update.attributes}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeWorkflow:t}=this;return!!t&&"update"===t.type&&!!t.activeEditorItem?.capabilities.delete.enabled}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(t){return this.startCreateFeaturesWorkflow(t,"creating-features")}async startCreateFeaturesWorkflow(t,e="awaiting-feature-creation-info"){if(await y((()=>!this.updating)),!this.canCreate)throw new s("editing:unsupported-workflow","Creating features is unsupported or disabled.");const a=this._createUpdatingResolver();await this._cancelWorkflow();const i=this._createCreateFeaturesWorkflow(t,e);this._set("activeWorkflow",i),await i.start(),a.resolve()}async startCreateFeaturesWorkflowAtFeatureEdit(t){await y((()=>!this.updating));const e=this._createUpdatingResolver(),{initialFeature:a}=t,i=a.sourceLayer,r=i?this.findEditorItemForLayer(i):void 0;if(!this.canCreate||!r)throw new s("editing:unsupported-workflow","Creating features is unsupported or disabled.");await this._cancelWorkflow();const o=this._createCreateFeaturesWorkflow({initialFeature:a,layer:r.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",o),await o.start(),e.resolve()}async startUpdateWorkflowAtFeatureSelection(){if(await y((()=>!this.updating)),!this.canUpdate)return void B("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();await this._cancelWorkflow();const e=this._createUpdateWorkflow();this._set("activeWorkflow",e),await e.start(),t.resolve()}async startUpdateWorkflowAtMultipleFeatureSelection(t){if(await y((()=>!this.updating)),!this.canUpdate)return void B("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();await this._cancelWorkflow();const a=this._createUpdateWorkflow("awaiting-update-feature-candidate");a.data.candidates=t,this._set("activeWorkflow",a),await a.start(),e.resolve()}async startUpdateWorkflowAtFeatureEdit(t){if(await y((()=>!this.updating)),!this.canUpdate)return void B("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();await this._cancelWorkflow();const a=this._createUpdateWorkflow("editing-existing-feature");a.data.rootFeature=t,this._set("activeWorkflow",a),await a.start(),e.resolve()}async deleteFeatureFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveFeature():B("editing:unsupported-workflow","Deleting requires an active update workflow.")}async cancelWorkflow(t){return this._cancelWorkflow({warnIfNoWorkflow:!0,...t})}findEditorItemForLayer(t){const e="subtype-sublayer"===t.type?t.parent:t;return this.editorItems.find((t=>t.layer===e))}itemHasInvalidFormTemplate(t){return null!=t&&!0===this.findEditorItemForLayer(t.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){if(this._featureTemplatesViewModelLocked)return;const t=[];for(const{capabilities:e,disabled:a,layer:i}of this.editorItems){const r=i.loaded&&e.create.enabled&&!M(i),s=this.hideTemplatesForInactiveLayers&&a;r&&!s&&t.push(i)}this.featureTemplatesViewModel.layers=t}async toggleUpdateWorkflow(){this.canUpdate&&(this.hasPendingEdits&&!await this.showDiscardEditsPrompt()||(this.activeWorkflow&&"awaiting-feature-to-update"===this.state?await this.cancelWorkflow({force:!0}):await this.startUpdateWorkflowAtFeatureSelection()))}lockFeatureTemplatesViewModel(){return this._featureTemplatesViewModelLocked=!0,n((()=>{this._featureTemplatesViewModelLocked=!1,this.syncFeatureTemplates()}))}async _getEditorItemCandidates(t){const{view:e}=this;if(!e?.map)return[];const{map:a}=e,i=a.editableLayers.toArray()??[],r=a.allTables.toArray().filter(E)??[];return await Promise.allSettled([...i.map((t=>"subtype-group"===t.type?t.loadAll():Promise.resolve())),...r.map((t=>t.load()))]),u(t),[...i.reverse(),...r.reverse()].filter((t=>{if(!F(t))return!1;const{geometryType:a,spatialReference:i}=t;if("mesh"===a){if("3d"!==e.type)return!1;const{isGeographic:t,isWebMercator:a}=i;switch(e.viewingMode){case"global":return t||a;case"local":return!t||a}}return!0})).flatMap((t=>"subtype-group"===t.type?t.sublayers.toArray():t))}_drainEditorItems(){this.editorItems.drain((t=>t.destroy()))}async _updateEditorItems(){d(this._updateItemsTask);const{view:t}=this,a=e((async e=>{if(!t?.map||!t?.allLayerViews)return;const a=await this._getEditorItemCandidates(e);if(!a.length)return void this._drainEditorItems();const i=[],r=[],s=[],{layerInfos:o}=this;for(const l of a){const e=Q(o,l),a=await S(t,l).catch((()=>null));(e?i:a?r:s).push(new P({layer:l,layerInfo:e,disabled:!!a?.suspended}))}o?.length&&i.sort(((t,e)=>o.findIndex((({layer:e})=>e===t.layer))-o.findIndex((({layer:t})=>t===e.layer))));const n=[...i,...r,...s];e.aborted||(this._drainEditorItems(),this.editorItems.addMany(n))}));this._updatingHandles.addPromise(a.promise),this._updateItemsTask=a}async _cancelWorkflow(t){const e=this.activeWorkflow;if(!e)return void(t?.warnIfNoWorkflow&&B("editing:no-active-workflow","There is no active workflow to cancel."));if(!t||!1!==t.force)return this.emit("workflow-cancel"),this._set("activeWorkflow",null),void await e.cancel(t);await e.cancel(t),this._set("activeWorkflow",null)}_createCreateFeaturesWorkflow(t,e){return T.create({viewModel:this,creationInfo:t,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:e,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_createUpdateWorkflow(t){return j.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_addAttachments(t,e){const a=e.map((e=>this._addAttachment(t,e.feature,e.attachment)))??[];return Promise.all(a)}async _addAttachment(t,e,a){let i=null;if(!("addAttachment"in t)||null==t.capabilities?.attachment)throw new s("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation((async()=>(i=await(t.addAttachment?.(e,a).catch((t=>{throw t?.error||t})))??null,i))),i}async _applyEdits(t,e,a){let i=null;const r=t.url?await O(t.url):null,s={returnServiceEditsOption:(!r||!C(r))&&!RegExp("/hosted/","i").test(t.url)?"original-and-current-features":void 0,...a};return await this._queueOperation((async()=>{const{view:a}=this;if(!a)return null;const r=await S(a,t).catch((()=>null));return i=await t.applyEdits(e,s),r&&await y((()=>!r.updating)),i})),i}_queueOperation(t){this._activityQueue.push(t);const e=(t,e)=>{const a=e.indexOf(t);a>-1&&e.splice(a,1)};return t().then((t=>{if(null!=t&&"error"in t&&null!=t.error)throw t.error;if(null!=t&&"addFeatureResults"in t){const{addFeatureResults:e,deleteFeatureResults:a,updateFeatureResults:i}=t,r=e.find((t=>!!t.error))||i.find((t=>!!t.error))||a.find((t=>!!t.error));if(r)throw r.error}return t})).catch((a=>{B("editing:operation-error","An error occurred.",{error:a});const i={error:a,retry:()=>(e(i,this.failures),this._queueOperation(t)),cancel:()=>{e(i,this.failures)}};this._set("failures",[...this.failures,i])})).then((()=>{e(t,this._activityQueue)}))}_createUpdatingResolver(){const t=h();return this._updatingHandles.addPromise(t.promise),t}_itemIsSuspended(t){return this.findEditorItemForLayer(t)?.disabled??!1}};t([_({readOnly:!0})],N.prototype,"activeWorkflow",void 0),t([_({readOnly:!0})],N.prototype,"_activityQueue",void 0),t([_({value:[...q]})],N.prototype,"allowedWorkflows",null),t([_({readOnly:!0})],N.prototype,"canCreate",null),t([_({readOnly:!0})],N.prototype,"canUpdate",null),t([_()],N.prototype,"editableItems",null),t([_()],N.prototype,"editorItems",void 0),t([_({readOnly:!0})],N.prototype,"failures",void 0),t([_()],N.prototype,"hideTemplatesForInactiveLayers",void 0),t([_()],N.prototype,"attachmentsViewModel",void 0),t([_()],N.prototype,"featureFormViewModel",null),t([_()],N.prototype,"featureTemplatesViewModel",void 0),t([_()],N.prototype,"labelOptions",null),t([_()],N.prototype,"layerInfos",null),t([_()],N.prototype,"ownSketchViewModel",void 0),t([_()],N.prototype,"sketchOptions",void 0),t([_()],N.prototype,"sketchViewModel",null),t([_({type:L,nonNullable:!0})],N.prototype,"snappingOptions",void 0),t([_()],N.prototype,"spinnerViewModel",void 0),t([_()],N.prototype,"state",null),t([_({readOnly:!0})],N.prototype,"syncing",null),t([_()],N.prototype,"updating",null),t([_()],N.prototype,"tooltipOptions",null),t([_()],N.prototype,"valueOptions",null),t([_()],N.prototype,"view",null),t([_()],N.prototype,"pageStack",void 0),t([_()],N.prototype,"showDiscardEditsPrompt",void 0),t([_()],N.prototype,"_candidateCommitted",void 0),t([_()],N.prototype,"page",null),t([_()],N.prototype,"featureFormDisabled",null),t([_()],N.prototype,"canGoBack",null),t([_()],N.prototype,"shouldShowDeleteButton",null),t([_()],N.prototype,"hasPendingEdits",null),N=t([W(G)],N);const z=N;export{z as default};
|
package/widgets/FeatureForm.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{isSome as t}from"../core/arrayUtils.js";import{deprecatedProperty as i}from"../core/deprecate.js";import o from"../core/Logger.js";import{watch as n,whenOnce as a}from"../core/reactiveUtils.js";import{property as s}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import{subclass as r}from"../core/accessorSupport/decorators/subclass.js";import{isIntegerField as l}from"../layers/support/fieldUtils.js";import d from"./Widget.js";import{css as p}from"./FeatureForm/css.js";import{isGroupInput as c,isFieldInput as u,isRelationshipInput as m,isInputInGroupInput as h,isFieldElementWithInputType as v,getErrorMessageForFieldInput as _,getIconForFeature as g,isNumberFieldInput as b}from"./FeatureForm/featureFormUtils.js";import f from"./FeatureForm/FeatureFormViewModel.js";import{loadCalciteComponents as C}from"./support/componentsUtils.js";import{isString as y}from"./support/dataUtils.js";import{getLabelForDateFieldValue as F,getIntlOptionsForField as w,numberingSystem as R,prepareISOFieldValueForDateComponents as O,prepareUnixFieldValueForDateComponents as k,normalizeTimeOnlyString as I,getISOFieldValueFromDateComponents as M,getUnixFieldValueFromDateComponents as D}from"./support/dateUtils.js";import{globalCss as x}from"./support/globalCss.js";import{Heading as V,incrementHeadingLevel as N}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as L}from"./support/decorators/messageBundle.js";import{vmEvent as T}from"./support/decorators/vmEvent.js";import{tsx as j}from"./support/jsxFactory.js";import{substitute as E}from"../intl/substitute.js";const U="data-field-name";let S=class extends d{constructor(e,t){super(e,t),this._attemptFocusOnNextRender=!1,this._dateComponentMap=new Map,this._inputsWithChanges=new Set,this._focusedFieldName=null,this._listObserverNode=null,this._listObserver=new IntersectionObserver((e=>{e.length&&e[0].isIntersecting&&this._incrementRelatedRecordPage()}),{root:window.document}),this.groupDisplay="all",this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.messagesFeature=null,this.messagesTemplates=null,this.viewModel=new f,this._onShowAllRelatedRecordsClick=e=>{const{feature:t,relatedRecordCallbacks:i}=this;t&&i?.showAllRelatedRecords&&i.showAllRelatedRecords({parentFeature:t,relationshipId:e})},this._onAddRelatedRecordsClick=(e,t)=>{const{feature:i,relatedRecordCallbacks:o}=this;i&&o?.addRelatedRecord&&o.addRelatedRecord({parentFeature:i,relatedLayer:t,relationshipId:e})},this._onFormKeyDown=this._onFormKeyDown.bind(this),this._onFormSubmit=this._onFormSubmit.bind(this),this._onGroupToggle=this._onGroupToggle.bind(this),this._onComponentBlur=this._onComponentBlur.bind(this),this._onComponentFocus=this._onComponentFocus.bind(this),this._onComponentKeyDown=this._onComponentKeyDown.bind(this),this._afterComponentCreate=this._afterComponentCreate.bind(this),this._afterComponentCreateOrUpdate=this._afterComponentCreateOrUpdate.bind(this),this._afterDateComponentCreate=this._afterDateComponentCreate.bind(this),this._afterDateComponentCreateOrUpdate=this._afterDateComponentCreateOrUpdate.bind(this),this._afterRadioGroupCreateOrUpdate=this._afterRadioGroupCreateOrUpdate.bind(this)}initialize(){this.addHandles([n((()=>this.feature),(()=>{a((()=>!this.viewModel.updating)).then((()=>{const e=this._getFocusableInput("forward");this._inputsWithChanges.clear(),this._dateComponentMap.clear(),this._syncGroupInputStates(),this._focusedFieldName=e?.name||null,this._attemptFocusOnNextRender=!0}))})),n((()=>this.groupDisplay),(()=>this._syncGroupInputStates())),this.on("submit",(e=>{if(e.invalid.length>0){const[t]=e.invalid;e.invalid.forEach((e=>this._inputsWithChanges.add(e))),this._focusedFieldName=t,this._attemptFocusOnNextRender=!0,this.scheduleRender()}})),n((()=>[this.viewModel.activeRelationshipInput,this._listObserverNode]),(()=>this._onObserverChange()))])}loadDependencies(){return C({block:()=>import("@esri/calcite-components/dist/components/calcite-block.js"),button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox.js"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),"combobox-item-group":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item-group.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),input:()=>import("@esri/calcite-components/dist/components/calcite-input.js"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker.js"),"input-message":()=>import("@esri/calcite-components/dist/components/calcite-input-message.js"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number.js"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker.js"),"input-time-zone":()=>import("@esri/calcite-components/dist/components/calcite-input-time-zone.js"),label:()=>import("@esri/calcite-components/dist/components/calcite-label.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader.js"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice.js"),"radio-button":()=>import("@esri/calcite-components/dist/components/calcite-radio-button.js"),"radio-button-group":()=>import("@esri/calcite-components/dist/components/calcite-radio-button-group.js"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch.js"),"text-area":()=>import("@esri/calcite-components/dist/components/calcite-text-area.js")})}destroy(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode)}get _relatedRecordsEnabled(){const e=this.relatedRecordCallbacks;return!(!e||!(e.addRelatedRecord||e.editRelatedRecord||e.showAllRelatedRecords))}get disabled(){return this.viewModel.disabled}set disabled(e){this.viewModel.disabled=e}get feature(){return this.viewModel.feature}set feature(e){this.viewModel.feature=e}get formTemplate(){return this.viewModel.formTemplate}set formTemplate(e){this.viewModel.formTemplate=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get relatedRecordCallbacks(){return this.viewModel.relatedRecordCallbacks}set relatedRecordCallbacks(e){this.viewModel.relatedRecordCallbacks=e}get relationshipId(){return this.viewModel.relationshipId}set relationshipId(e){this.viewModel.relationshipId=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get strict(){return this.viewModel.strict}set strict(e){this.viewModel.strict=e}get timeZone(){return this.viewModel.timeZone}set timeZone(e){this.viewModel.timeZone=e}get view(){return i(o.getLogger(this),"view",{replacement:"Use FeatureForm.map instead.",version:"4.27"}),this.viewModel.view}set view(e){i(o.getLogger(this),"view",{replacement:"Use FeatureForm.map instead.",version:"4.27"}),this.viewModel.view=e}getValues(){return this.viewModel.getValues()}submit(){return this.viewModel.submit()}render(){const{state:e}=this.viewModel;return j("div",{class:this.classes(p.base,x.widget,x.panel)},"ready"===e?this._renderForm():null)}_renderForm(){return j("form",{class:p.form,novalidate:!0,onkeydown:this._onFormKeyDown,onsubmit:this._onFormSubmit},this._renderHeader(),this._renderContent())}_renderHeader(){const e=this.viewModel;if(!e.formHeaderVisible)return;const t=null!=e.formTitle&&j(V,{key:"title",level:this.headingLevel},e.formTitle),i=null!=e.formDescription&&j("p",{class:p.description,key:"description"},e.formDescription);return j("div",{class:p.formHeader},t,i)}_renderContent(){const{viewModel:e}=this;return e.activeRelationshipInput?this._renderActiveRelationshipInput(e.activeRelationshipInput):e.inputs.filter(t).filter((e=>e.visible)).map(((e,t)=>c(e)?this._renderGroup(e,t):u(e)?this._renderLabeledField(e):m(e)?this._renderRelationshipInput(e):void 0))}_renderActiveRelationshipInput(e){return this._renderRelationshipInput(e)}_renderDescriptionOrEmpty(e,t){return null==e?null:j("div",{class:this.classes(p.description),id:t},e)}_renderGroup(e,t){const{disabled:i,formTemplate:o,headingLevel:n}=this,{description:a,inputs:s,label:r,open:l}=e,d=s.filter((e=>e.visible)),c=this.viewModel.findField(this._focusedFieldName),h=c?.group===e,v=`${this.id}_group_${t}`,_="sequential"===this.groupDisplay;return j("calcite-block",{class:this.classes(p.group,_?p.groupSequential:null,h?p.groupActive:null,i?p.inputDisabled:null),collapsible:!0,"data-group":e,description:a||void 0,disabled:i,heading:`${r}`,headingLevel:o?.title?N(n):n,id:v,key:v,open:l,onCalciteBlockToggle:({target:t})=>this._onGroupToggle(t,e)},d.map((e=>u(e)?this._renderLabeledField(e):m(e)?this._renderRelationshipInput(e):void 0)))}_getFocusableInput(e,t){const i=this.viewModel.allFieldInputs,o="forward"===e?i:i.slice().reverse();let n;if(!t||m(t))n=0;else if(c(t)){const e=t.inputs.find(u);n=e?o.indexOf(e):0}else{let i;if(h(t)&&!t.group.open){const o=t.group.inputs.filter(u);i="forward"===e?o[o.length-1]:o[0]}else i=t;n=o.indexOf(i)+1}for(let a=n;a<o.length;a++){const e=o[a];if(e.visible&&u(e))return e}return null}_renderLabeledField(e){const{dataType:t,feature:i,label:o,layer:n,required:a}=e,s={"aria-label":a?E(this.messages.requiredFieldLabel,{name:o}):o,class:p.label,key:`${n.id}-${i.uid}-${e.name}`},r=[j("div",{class:p.labelTextContent,key:"labelTextContainer"},o,a?j("span",{"aria-hidden":"true",title:this.messagesCommon.required},"*"):void 0),"unsupported"!==t?this._renderFieldInput(e):this._renderReadOnlyComponent(e),this._renderAuxiliaryText(e)];return"date"===t&&"coded-value"!==e.domain?.type?j("label",{...s},r):j("calcite-label",{...s},r)}_renderFieldInput(e){const{dataType:t,domain:i,inputType:o,name:n}=e,a=this.getCommonInputProps(e);if("coded-value"===i?.type){const t=this.viewModel.getFieldValueOptionsForField(n,this.messages.empty);return"switch"!==o||e.hasInvalidSwitchValue?"radio-buttons"===o?this._renderRadioButtonComponents(e,t.flat(),a):this._renderComboBoxComponent(e,t,a):this._renderSwitchComponent(e,a)}return"datetime-picker"===o||"date"===t?this._renderDateComponents(e,a):"number"===t?this._renderNumberComponent(e,a):this._renderStringComponent(e,a)}_renderStringComponent(e,t){return"text-area"===e.inputType?t.readOnly?j("calcite-input",{...t,loading:e.updating,type:"textarea",onCalciteInputInput:e=>this._saveValueFromComponent(e.target)}):j("calcite-text-area",{...t,resize:"vertical",onCalciteTextAreaInput:e=>this._saveValueFromComponent(e.target)}):j("calcite-input",{...t,loading:e.updating,type:"text",onCalciteInputInput:e=>this._saveValueFromComponent(e.target)})}_renderNumberComponent(e,t){return j("calcite-input-number",{...t,integer:l(e.field),loading:e.updating,type:"number",onCalciteInputNumberInput:e=>this._saveValueFromComponent(e.target)})}_renderDateComponents(e,t){const{field:i}=e;switch(i.type){case"date":return this._renderDateFieldComponents(e,t);case"date-only":return this._renderDateOnlyFieldComponent(e,t);case"time-only":return this._renderTimeOnlyFieldComponent(e,t);case"timestamp-offset":return this._renderTimestampOffsetFieldComponents(e,t);default:return this._renderReadOnlyComponent(e,F(i,t.value,{timeZone:this.timeZone,...w(i)}))}}_renderDateOnlyFieldComponent(e,t){const{range:i,valid:o,value:n}=e,{class:a,key:s,readOnly:r}=t,{rawMax:l,rawMin:d}=i;return j("calcite-input-date-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!o,class:a,"data-date-part":"date","data-field-name":t[U],key:`${s}-date-input`,max:y(l)?l:void 0,min:y(d)?d:void 0,numberingSystem:R,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:r,value:null!=n?`${n}`:void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target)})}_renderTimeOnlyFieldComponent(e,t){const{valid:i,value:o}=e,{class:n,key:a,readOnly:s}=t;return j("calcite-input-time-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!i,class:n,"data-date-part":"time","data-field-name":t[U],key:`${a}-time-input`,numberingSystem:R,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:s,step:e.timeStep,value:null!=o?`${o}`:void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target)})}_renderTimestampOffsetFieldComponents(e,t){const{name:i,range:o,timeZone:n,valid:a,value:s}=e,{class:r,key:l,readOnly:d}=t,{rawMax:c,rawMin:u}=o,m={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!a,numberingSystem:R,overlayPositioning:"fixed",readOnly:d,[U]:i,onfocus:this._onComponentFocus},h=O(c,n),v=O(u,n),_=O(s,n);return j("div",{class:p.dateInputContainer,key:`${l}-date-time-container`},j("calcite-input-date-picker",{...m,class:r,"data-date-part":"date",key:`${l}-date-input`,max:h?.date??void 0,min:v?.date??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:_.date??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target)}),j("calcite-input-time-picker",{...m,class:r,"data-date-part":"time",key:`${l}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:e.timeStep,value:_.time??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target)}),e.includeTimeOffset?j("calcite-input-time-zone",{...m,class:r,"data-date-part":"timeZone",disabled:d,key:`${l}-timezone-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:_.timeZoneOffset??"0",onCalciteInputTimeZoneChange:e=>this._saveValueFromDateComponent(e.target)}):null)}_renderDateFieldComponents(e,t){const{includeTime:i,name:o,valid:n,value:a}=e,{class:s,key:r,max:l,min:d,readOnly:c}=t,{timeZone:u}=this,m={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!n,numberingSystem:R,overlayPositioning:"fixed",readOnly:c,[U]:o,onfocus:this._onComponentFocus},h=k(a,u),v=k(l,u),_=k(d,u);return j("div",{class:p.dateInputContainer,key:`${r}-date-time-container`},j("calcite-input-date-picker",{...m,class:s,"data-date-part":"date",key:`${r}-date-input`,max:v?.date??void 0,min:_?.date??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:h.date??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target)}),i?j("calcite-input-time-picker",{...m,class:s,"data-date-part":"time",key:`${r}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:1,value:h.time??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target)}):null)}_renderReadOnlyComponent(e,t){const i=this.getCommonInputProps(e);return j("calcite-input",{...i,class:this.classes(p.fieldInput,p.inputDisabled),readOnly:!0,type:"text",value:null!=t?`${t}`:i.value})}_renderComboBoxComponent(e,t,i){const{value:o,name:n}=e,{messages:a,messagesTemplates:s,viewModel:r,_inputsWithChanges:l}=this,d=t.map((e=>e.map((({name:e,value:t})=>j("calcite-combobox-item",{key:`#${t}`,selected:o===t,textLabel:e,value:`${t}`}))))),[p,c]=d;this.viewModel.fieldsWithInvalidCodedValue.has(e)&&c.unshift(j("calcite-combobox-item",{key:"incompatible-option",readOnly:!0,textLabel:`${e.value}`,value:`${e.value}`}));const u=c.length>0?[j("calcite-combobox-item-group",{key:"recommended",label:a.recommended},p),j("calcite-combobox-item-group",{key:"other",label:s.other},c)]:p,m="INSERT"===r.arcadeEditType,h=l.has(n),v=null==o&&(!m||h);if(e.showNoValueOptionEnabled){const t="",i=e.showNoValueLabel||a.empty;u.unshift(j("calcite-combobox-item",{key:"empty-option",selected:v,textLabel:a.empty,value:t},i))}const _=m&&e.showNoValueOptionEnabled&&!h?()=>{}:i.onblur;return j("calcite-combobox",{...i,allowCustomValues:!1,clearDisabled:!0,disabled:i.readOnly,onblur:_,overlayPositioning:"fixed",selectionMode:"single",onCalciteComboboxChange:({target:e})=>{v&&0===e.selectedItems.length?this._ignoreDeselectionOfNoValueOption(e):this._saveValueFromComponent(e)}},u)}_renderRadioButtonComponents(e,t,i){const{name:o,value:n}=e,a=t.map((({name:e,value:t})=>this._renderRadioButtonComponent({key:e,label:e,name:o,value:t,selected:t===n,props:i})));if(e.showNoValueOptionEnabled){const t="",s=e.showNoValueLabel||this.messages.empty,r=n===t||null===n;a.unshift(this._renderRadioButtonComponent({key:"empty-option",label:s,name:o,value:t,selected:r,props:i}))}return j("calcite-radio-button-group",{afterCreate:this._afterRadioGroupCreateOrUpdate,afterUpdate:this._afterRadioGroupCreateOrUpdate,class:p.inputRadioGroup,"data-field-name":i[U],key:`${i.key}-radio-group`,layout:"vertical",name:i.key,required:i.required},a)}_renderSwitchComponent(e,t){const{value:i}=e,o=!!v(e.element,"switch")&&i===e.element.input.onValue;return j("calcite-switch",{...t,checked:o,class:p.inputSwitch,disabled:t.readOnly,onblur:()=>{this._focusedFieldName=null},onCalciteSwitchChange:e=>this._saveValueFromComponent(e.target)})}_renderRadioButtonComponent({key:e,name:t,value:i,selected:o,label:n,props:a}){return j("calcite-label",{class:p.inputRadioLabel,key:e,layout:"inline"},j("calcite-radio-button",{...a,afterCreate:void 0,afterUpdate:void 0,checked:o,class:p.inputRadio,disabled:a.readOnly,name:t,onblur:()=>{this._focusedFieldName=null},value:i,onCalciteRadioButtonChange:({target:e})=>{e.checked&&this._saveValueFromComponent(e)}}),n)}_renderAuxiliaryText(e){const t=e.name,i=this._inputsWithChanges.has(t)&&!e.valid?_(e,this.messages,this.timeZone):null!=this.viewModel.contingencyConstraintViolations.get(t)?this.messages.validationErrors.valuesIncompatible:null!=e.valueExpressionExecutor&&e.valueExpressionExecutor.stale?this.messages.valueExpressionError:null;return null!=i?j("calcite-input-message",{icon:!0,status:"invalid"},i):this._renderDescriptionOrEmpty(e.description)}_renderShowAllRelatedRecordsListItem(e){const{featureCount:t,relationshipId:i,showAllActionVisible:o}=e,{relatedRecordCallbacks:n}=this;if(!o||!n?.showAllRelatedRecords)return;const a=this.messages;return j("calcite-list-item",{description:E(a.totalCount,{count:t}),label:a.showAll,value:!0,onCalciteListItemSelect:()=>this._onShowAllRelatedRecordsClick(i)},j("calcite-icon",{icon:"list",scale:"s",slot:"content-end"}))}_renderAddRelatedRecordButton(e){const{canAddRelatedFeature:t,relationshipId:i,relatedLayer:o}=e,{messages:n,relatedRecordCallbacks:a}=this;if(t&&a?.addRelatedRecord&&o)return j("calcite-button",{alignment:"center",appearance:"outline-fill",class:p.centeredButton,disabled:e.updating||!e.originHasValidKey,iconStart:"plus",key:`${i}-add-button`,onclick:()=>this._onAddRelatedRecordsClick(i,o),round:!0,scale:"s",width:"half"},e.relatedLayerIsTable?n.addRecord:n.addFeature)}_renderRelatedRecordListItem(e,t){const{feature:i,description:o,title:n}=e,{feature:a,relatedRecordCallbacks:s}=this,{highlightHelper:r}=this.viewModel,l=()=>{r?.removeAll(),s?.editRelatedRecord&&a&&s.editRelatedRecord({parentFeature:a,relationshipId:t,relatedFeature:i})},d=r?()=>r.add(i):void 0,p=r?()=>r.remove(i):void 0;return j("calcite-list-item",{bind:this,description:o,key:`${t}-${i.uid}`,label:n,onclick:l,onmouseenter:d,onmouseleave:p,value:n},j("calcite-icon",{icon:g(i),scale:"m",slot:"content-start"}),j("calcite-icon",{icon:"chevron-right",scale:"s",slot:"content-end"}))}_renderRelationshipInput(e){if(!this._relatedRecordsEnabled||!e.editable)return;const{featureCount:t,relationshipId:i,showAllEnabled:o}=e,n=o?null:this._renderDescriptionOrEmpty(e.description),a=t>0?this._renderRelatedRecordsList(e):e.loaded?e.originHasValidKey?this._renderNoRelatedRecordsNotice():this._renderNoValidOriginKeyNotice(e):void 0;return j("calcite-label",{class:this.classes(p.label,p.relatedRecordsLabel),key:`relationship-${i}-container`},j("div",null,this._renderRelatedRecordsHeaderContainer(e),n,a),this._renderAddRelatedRecordButton(e))}_renderRelatedRecordsHeaderContainer(e){const t=e.updating||!e.loaded;return j("div",{class:p.relatedRecordsHeader,key:`relationship-${e.relationshipId}-header`},j("span",null,e.label),t?j("calcite-loader",{inline:!0,key:"loader",label:this.messagesCommon?.loading,scale:"s",type:"indeterminate"}):void 0)}_renderRelatedRecordsList(e){const{relationshipId:t}=e;return j("calcite-list",{class:p.relatedRecordsList},e.relatedFeatureInfos.map((e=>this._renderRelatedRecordListItem(e,t))),this._renderShowAllRelatedRecordsListItem(e),this._renderObserverNode())}_renderNoValidOriginKeyNotice(e){const{messages:t}=this,i=e.relatedLayerIsTable?t.noOriginKeyRecord:t.noOriginKeyFeature,o=e.relationship?.keyField,n=this.viewModel.findField(o),a=e.layer?.fieldsIndex.get(o),s=n?.label||a?.alias||o,r=E(i,{relatedLayerName:e.relatedLayer?.title,originKeyField:s});return j("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},j("div",{slot:"message"},r))}_renderNoRelatedRecordsNotice(){return j("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},j("div",{slot:"message"},this.messagesFeature.noRelatedFeatures))}_renderObserverNode(){if(this.viewModel.activeRelationshipInput?.showAllEnabled)return j("div",{afterCreate:this._afterListObserverCreated,afterRemoved:this._afterListObserverRemoved,bind:this,class:p.listObserver,key:"feature-observer"})}getCommonInputProps(e){const{disabled:t}=this,{editable:i,hint:o,label:n,maxLength:a,minLength:s,name:r,range:{max:l,min:d},required:c,valid:u,value:m}=e,h=this._inputsWithChanges.has(r),v=!i||t;return{afterCreate:this._afterComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,"aria-invalid":u?"false":"true",class:this.classes(p.fieldInput,v?p.inputDisabled:null,h&&!u?p.inputInvalid:null),key:r,label:n,max:null!=l?l:void 0,min:null!=d?d:void 0,maxLength:a>-1?a:void 0,minLength:s>-1?s:void 0,placeholder:o??void 0,readOnly:v,required:c,value:null==m?"":`${m}`,onblur:this._onComponentBlur,onfocus:this._onComponentFocus,onkeydown:this._onComponentKeyDown,[U]:r}}_getFieldInputFromHTMLElement(e){return this.viewModel.findField(e.getAttribute(U))}_afterDateComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e),i=e.dataset.datePart,o=this._dateComponentMap.get(t.name);if("valueAsDate"in e&&null!=e.value){const t=e.value,i=new ResizeObserver((()=>{e.value=void 0,e.value=t,i.unobserve(e)}));i.observe(e)}if(null!=o)switch(i){case"date":o.date=e;break;case"time":o.time=e;break;case"timeZone":o.timeZone=e}else this._dateComponentMap.set(t.name,{[i]:e});this._afterDateComponentCreateOrUpdate(e)}_afterDateComponentCreateOrUpdate(e){this._afterComponentCreateOrUpdate(e)}_afterComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e);b(t)&&null!=e.value&&"setNumberValue"in e&&e.setNumberValue({committing:!1,value:e.value,origin:"direct"}),this._afterComponentCreateOrUpdate(e)}_afterRadioGroupCreateOrUpdate(e){const t=e.selectedItem,i=e.querySelector("calcite-radio-button"),o=t||i;o&&this._afterComponentCreateOrUpdate(o)}_afterComponentCreateOrUpdate(e){const{viewModel:t}=this,i=this._getFieldInputFromHTMLElement(e),o=t.findField(this._focusedFieldName);this._attemptFocusOnNextRender&&o===i&&(this._attemptFocusOnNextRender=!1,h(i)&&(i.group.open=!0),e.setFocus())}_onComponentFocus(e){const t=e.target,i=this._getFieldInputFromHTMLElement(t);this._focusedFieldName=i.name}_onComponentBlur(e){const t=e.target;this._focusedFieldName=null,this._saveValueFromComponent(t)}_saveValueFromDateComponent(e){const{timeZone:t}=this,i=this._getFieldInputFromHTMLElement(e),o=i.field.type,{name:n,range:a}=i,s=this._dateComponentMap.get(n);if(!s)return;let r=this.viewModel.getValue(n),l=null;"date-only"===o?l=e.value:"time-only"===o?(r=I(r),l=I(e.value)):l="timestamp-offset"===o?null!=e.value?M({dateComponent:s.date,timeComponent:s.time,timeZoneComponent:s.timeZone,oldValue:r,defaultTimeZone:t}):null:null!=e.value?D({oldValue:r,dateComponent:s.date,timeComponent:s.time,timeZone:t,max:a.max,min:a.min}):null,null!==l&&e.value?r!==l&&this._updateFieldValue(n,l):this._updateFieldValue(n,null)}_saveValueFromComponent(e){const t=this._getFieldInputFromHTMLElement(e);this._updateFieldValue(t.name,this._parseValue(e))}_onComponentKeyDown({key:e,target:t}){const i=this._getFieldInputFromHTMLElement(t);"Enter"===e&&h(i)&&!i.group.open&&(i.group.open=!0)}_updateFieldValue(e,t){if(this.viewModel.setValue(e,t),this._inputsWithChanges.add(e),this.viewModel.fieldsWithContingentValues.has(e)){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>null!=t)));this.viewModel.validateContingencyConstraints(e)}}_parseValue(e){const t=this._getFieldInputFromHTMLElement(e),i=e.value;return v(t.element,"switch")?e.checked?t.element.input.onValue:t.element.input.offValue:null==i||""===i?null:"number"===t.dataType?"-0"===i||"-0."===i||"-0,"===i?i:parseFloat(i):"date"===t.field.type?parseFloat(i):i}_ignoreDeselectionOfNoValueOption(e){const{firstChild:t,selectedItems:i}=e;0===i.length&&t&&"selected"in t?t.selected=!0:o.getLogger(this).warnOnce("Failed to override user attempt to deselect 'No value' option.")}_onGroupToggle(e,t){e.open?(t.open=!0,this._focusedFieldName=this._getFocusableInput("forward",t)?.name||null,this._attemptFocusOnNextRender=!0,"sequential"===this.groupDisplay&&this.viewModel.allGroupInputs.forEach((e=>{e!==t&&(e.open=!1)}))):t.open=!1,this.scheduleRender()}_onFormSubmit(e){e.preventDefault()}_onFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_afterListObserverCreated(e){this.viewModel.activeRelationshipInput&&(this._listObserverNode=e)}_afterListObserverRemoved(){this._listObserverNode=null}_onObserverChange(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode);const e=this.viewModel.activeRelationshipInput;e&&this._listObserverNode&&e.showAllEnabled&&this._listObserver.observe(this._listObserverNode)}_incrementRelatedRecordPage(){const e=this.viewModel.activeRelationshipInput;e?.incrementPage()}_syncGroupInputStates(){if("sequential"!==this.groupDisplay)return;const e=this.viewModel.allGroupInputs;if(!e.length)return;const t=e.filter((e=>e.open));0===t.length?e[0].open=!0:t.length>1&&t.slice(1).forEach((e=>e.open=!1))}};e([s()],S.prototype,"_listObserverNode",void 0),e([s()],S.prototype,"_relatedRecordsEnabled",null),e([s()],S.prototype,"disabled",null),e([s()],S.prototype,"feature",null),e([s()],S.prototype,"formTemplate",null),e([s()],S.prototype,"groupDisplay",void 0),e([s()],S.prototype,"headingLevel",void 0),e([s()],S.prototype,"label",null),e([s()],S.prototype,"layer",null),e([s()],S.prototype,"map",null),e([s(),L("esri/widgets/FeatureForm/t9n/FeatureForm")],S.prototype,"messages",void 0),e([s(),L("esri/t9n/common")],S.prototype,"messagesCommon",void 0),e([s(),L("esri/widgets/Feature/t9n/Feature")],S.prototype,"messagesFeature",void 0),e([s(),L("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],S.prototype,"messagesTemplates",void 0),e([s()],S.prototype,"relatedRecordCallbacks",null),e([s()],S.prototype,"relationshipId",null),e([s()],S.prototype,"spatialReference",null),e([s()],S.prototype,"strict",null),e([s()],S.prototype,"timeZone",null),e([s()],S.prototype,"view",null),e([s(),T(["value-change","submit"])],S.prototype,"viewModel",void 0),S=e([r("esri.widgets.FeatureForm")],S);const $=S;export{$ as default};
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{isSome as t}from"../core/arrayUtils.js";import{deprecatedProperty as i}from"../core/deprecate.js";import o from"../core/Logger.js";import{watch as n,whenOnce as a}from"../core/reactiveUtils.js";import{property as s}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import{subclass as r}from"../core/accessorSupport/decorators/subclass.js";import{isIntegerField as l}from"../layers/support/fieldUtils.js";import d from"./Widget.js";import{css as p}from"./FeatureForm/css.js";import{isGroupInput as c,isFieldInput as u,isRelationshipInput as m,isInputInGroupInput as h,isFieldElementWithInputType as v,getErrorMessageForFieldInput as _,getIconForFeature as g,isNumberFieldInput as b}from"./FeatureForm/featureFormUtils.js";import C from"./FeatureForm/FeatureFormViewModel.js";import{loadCalciteComponents as f}from"./support/componentsUtils.js";import{isString as y}from"./support/dataUtils.js";import{getLabelForDateFieldValue as F,getIntlOptionsForField as w,numberingSystem as R,prepareISOFieldValueForDateComponents as O,prepareUnixFieldValueForDateComponents as k,normalizeTimeOnlyString as I,getISOFieldValueFromDateComponents as M,getUnixFieldValueFromDateComponents as D}from"./support/dateUtils.js";import{globalCss as x}from"./support/globalCss.js";import{Heading as V,incrementHeadingLevel as N}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as L}from"./support/decorators/messageBundle.js";import{vmEvent as T}from"./support/decorators/vmEvent.js";import{tsx as j}from"./support/jsxFactory.js";import{substitute as E}from"../intl/substitute.js";const U="data-field-name";let S=class extends d{constructor(e,t){super(e,t),this._attemptFocusOnNextRender=!1,this._dateComponentMap=new Map,this._inputsWithChanges=new Set,this._focusedFieldName=null,this._listObserverNode=null,this._listObserver=new IntersectionObserver((e=>{e.length&&e[0].isIntersecting&&this._incrementRelatedRecordPage()}),{root:window.document}),this.groupDisplay="all",this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.messagesFeature=null,this.messagesTemplates=null,this.viewModel=new C,this._onShowAllRelatedRecordsClick=e=>{const{feature:t,relatedRecordCallbacks:i}=this;t&&i?.showAllRelatedRecords&&i.showAllRelatedRecords({parentFeature:t,relationshipId:e})},this._onAddRelatedRecordsClick=(e,t)=>{const{feature:i,relatedRecordCallbacks:o}=this;i&&o?.addRelatedRecord&&o.addRelatedRecord({parentFeature:i,relatedLayer:t,relationshipId:e})},this._onFormKeyDown=this._onFormKeyDown.bind(this),this._onFormSubmit=this._onFormSubmit.bind(this),this._onGroupToggle=this._onGroupToggle.bind(this),this._onComponentBlur=this._onComponentBlur.bind(this),this._onComponentFocus=this._onComponentFocus.bind(this),this._onComponentKeyDown=this._onComponentKeyDown.bind(this),this._afterComponentCreate=this._afterComponentCreate.bind(this),this._afterComponentCreateOrUpdate=this._afterComponentCreateOrUpdate.bind(this),this._afterDateComponentCreate=this._afterDateComponentCreate.bind(this),this._afterDateComponentCreateOrUpdate=this._afterDateComponentCreateOrUpdate.bind(this),this._afterRadioGroupCreateOrUpdate=this._afterRadioGroupCreateOrUpdate.bind(this)}initialize(){this.addHandles([n((()=>this.feature),(()=>{a((()=>!this.viewModel.updating)).then((()=>{const e=this._getFocusableInput("forward");this._inputsWithChanges.clear(),this._dateComponentMap.clear(),this._syncGroupInputStates(),this._focusedFieldName=e?.name||null,this._attemptFocusOnNextRender=!0}))})),n((()=>this.groupDisplay),(()=>this._syncGroupInputStates())),this.on("submit",(e=>{if(e.invalid.length>0){const[t]=e.invalid;e.invalid.forEach((e=>this._inputsWithChanges.add(e))),this._focusedFieldName=t,this._attemptFocusOnNextRender=!0,this.scheduleRender()}})),n((()=>[this.viewModel.activeRelationshipInput,this._listObserverNode]),(()=>this._onObserverChange()))])}loadDependencies(){return f({block:()=>import("@esri/calcite-components/dist/components/calcite-block.js"),button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox.js"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),"combobox-item-group":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item-group.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),input:()=>import("@esri/calcite-components/dist/components/calcite-input.js"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker.js"),"input-message":()=>import("@esri/calcite-components/dist/components/calcite-input-message.js"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number.js"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker.js"),"input-time-zone":()=>import("@esri/calcite-components/dist/components/calcite-input-time-zone.js"),label:()=>import("@esri/calcite-components/dist/components/calcite-label.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader.js"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice.js"),"radio-button":()=>import("@esri/calcite-components/dist/components/calcite-radio-button.js"),"radio-button-group":()=>import("@esri/calcite-components/dist/components/calcite-radio-button-group.js"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch.js"),"text-area":()=>import("@esri/calcite-components/dist/components/calcite-text-area.js")})}destroy(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode)}get _relatedRecordsEnabled(){const e=this.relatedRecordCallbacks;return!(!e||!(e.addRelatedRecord||e.editRelatedRecord||e.showAllRelatedRecords))}get disabled(){return this.viewModel.disabled}set disabled(e){this.viewModel.disabled=e}get feature(){return this.viewModel.feature}set feature(e){this.viewModel.feature=e}get formTemplate(){return this.viewModel.formTemplate}set formTemplate(e){this.viewModel.formTemplate=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get relatedRecordCallbacks(){return this.viewModel.relatedRecordCallbacks}set relatedRecordCallbacks(e){this.viewModel.relatedRecordCallbacks=e}get relationshipId(){return this.viewModel.relationshipId}set relationshipId(e){this.viewModel.relationshipId=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get strict(){return this.viewModel.strict}set strict(e){this.viewModel.strict=e}get timeZone(){return this.viewModel.timeZone}set timeZone(e){this.viewModel.timeZone=e}get view(){return i(o.getLogger(this),"view",{replacement:"Use FeatureForm.map instead.",version:"4.27"}),this.viewModel.view}set view(e){i(o.getLogger(this),"view",{replacement:"Use FeatureForm.map instead.",version:"4.27"}),this.viewModel.view=e}getValues(){return this.viewModel.getValues()}submit(){return this.viewModel.submit()}render(){const{state:e}=this.viewModel;return j("div",{class:this.classes(p.base,x.widget,x.panel)},"ready"===e?this._renderForm():null)}_renderForm(){return j("form",{class:p.form,novalidate:!0,onkeydown:this._onFormKeyDown,onsubmit:this._onFormSubmit},this._renderHeader(),this._renderContent())}_renderHeader(){const e=this.viewModel;if(!e.formHeaderVisible)return;const t=null!=e.formTitle&&j(V,{key:"title",level:this.headingLevel},e.formTitle),i=null!=e.formDescription&&j("p",{class:p.description,key:"description"},e.formDescription);return j("div",{class:p.formHeader},t,i)}_renderContent(){const{viewModel:e}=this;return e.activeRelationshipInput?this._renderActiveRelationshipInput(e.activeRelationshipInput):e.inputs.filter(t).filter((e=>e.visible)).map(((e,t)=>c(e)?this._renderGroup(e,t):u(e)?this._renderLabeledField(e):m(e)?this._renderRelationshipInput(e):void 0))}_renderActiveRelationshipInput(e){return this._renderRelationshipInput(e)}_renderDescriptionOrEmpty(e,t){return null==e?null:j("div",{class:this.classes(p.description),id:t},e)}_renderGroup(e,t){const{disabled:i,formTemplate:o,headingLevel:n}=this,{description:a,inputs:s,label:r,open:l}=e,d=s.filter((e=>e.visible)),c=this.viewModel.findField(this._focusedFieldName),h=c?.group===e,v=`${this.id}_group_${t}`,_="sequential"===this.groupDisplay;return j("calcite-block",{class:this.classes(p.group,_?p.groupSequential:null,h?p.groupActive:null,i?p.inputDisabled:null),collapsible:!0,"data-group":e,description:a||void 0,disabled:i,heading:`${r}`,headingLevel:o?.title?N(n):n,id:v,key:v,open:l,onCalciteBlockToggle:({target:t})=>this._onGroupToggle(t,e)},d.map((e=>u(e)?this._renderLabeledField(e):m(e)?this._renderRelationshipInput(e):void 0)))}_getFocusableInput(e,t){const i=this.viewModel.allFieldInputs,o="forward"===e?i:i.slice().reverse();let n;if(!t||m(t))n=0;else if(c(t)){const e=t.inputs.find(u);n=e?o.indexOf(e):0}else{let i;if(h(t)&&!t.group.open){const o=t.group.inputs.filter(u);i="forward"===e?o[o.length-1]:o[0]}else i=t;n=o.indexOf(i)+1}for(let a=n;a<o.length;a++){const e=o[a];if(e.visible&&u(e))return e}return null}_renderLabeledField(e){const{dataType:t,feature:i,label:o,layer:n,required:a}=e,s={"aria-label":a?E(this.messages.requiredFieldLabel,{name:o}):o,class:p.label,key:`${n.id}-${i.uid}-${e.name}`},r=[j("div",{class:p.labelTextContent,key:"labelTextContainer"},o,a?j("span",{"aria-hidden":"true",title:this.messagesCommon.required},"*"):void 0),"unsupported"!==t?this._renderFieldInput(e):this._renderReadOnlyComponent(e),this._renderAuxiliaryText(e)];return"date"===t&&"coded-value"!==e.domain?.type?j("label",{...s},r):j("calcite-label",{...s},r)}_renderFieldInput(e){const{dataType:t,domain:i,inputType:o,name:n}=e,a=this.getCommonInputProps(e);if("coded-value"===i?.type){const t=this.viewModel.getFieldValueOptionsForField(n,this.messages.empty);return"switch"!==o||e.hasInvalidSwitchValue?"radio-buttons"===o?this._renderRadioButtonComponents(e,t.flat(),a):this._renderComboBoxComponent(e,t,a):this._renderSwitchComponent(e,a)}return"datetime-picker"===o||"date"===t?this._renderDateComponents(e,a):"number"===t?this._renderNumberComponent(e,a):this._renderStringComponent(e,a)}_renderStringComponent(e,t){return"text-area"===e.inputType?t.readOnly?j("calcite-input",{...t,loading:e.updating,type:"textarea",onCalciteInputInput:e=>this._saveValueFromComponent(e.target)}):j("calcite-text-area",{...t,resize:"vertical",onCalciteTextAreaInput:e=>this._saveValueFromComponent(e.target)}):j("calcite-input",{...t,loading:e.updating,type:"text",onCalciteInputInput:e=>this._saveValueFromComponent(e.target)})}_renderNumberComponent(e,t){return j("calcite-input-number",{...t,integer:l(e.field),loading:e.updating,type:"number",onCalciteInputNumberInput:e=>this._saveValueFromComponent(e.target)})}_renderDateComponents(e,t){const{field:i}=e;switch(i.type){case"date":return this._renderDateFieldComponents(e,t);case"date-only":return this._renderDateOnlyFieldComponent(e,t);case"time-only":return this._renderTimeOnlyFieldComponent(e,t);case"timestamp-offset":return this._renderTimestampOffsetFieldComponents(e,t);default:return this._renderReadOnlyComponent(e,F(i,t.value,{timeZone:this.timeZone,...w(i)}))}}_renderDateOnlyFieldComponent(e,t){const{range:i,valid:o,value:n}=e,{class:a,key:s,readOnly:r}=t,{rawMax:l,rawMin:d}=i;return j("calcite-input-date-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!o,class:a,"data-date-part":"date","data-field-name":t[U],key:`${s}-date-input`,max:y(l)?l:void 0,min:y(d)?d:void 0,numberingSystem:R,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:r,value:null!=n?`${n}`:void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target)})}_renderTimeOnlyFieldComponent(e,t){const{valid:i,value:o}=e,{class:n,key:a,readOnly:s}=t;return j("calcite-input-time-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!i,class:n,"data-date-part":"time","data-field-name":t[U],key:`${a}-time-input`,numberingSystem:R,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:s,step:e.timeStep,value:null!=o?`${o}`:void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target)})}_renderTimestampOffsetFieldComponents(e,t){const{name:i,range:o,timeZone:n,valid:a,value:s}=e,{class:r,key:l,readOnly:d}=t,{rawMax:c,rawMin:u}=o,m={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!a,numberingSystem:R,overlayPositioning:"fixed",readOnly:d,[U]:i,onfocus:this._onComponentFocus},h=O(c,n),v=O(u,n),_=O(s,n);return j("div",{class:p.dateInputContainer,key:`${l}-date-time-container`},j("calcite-input-date-picker",{...m,class:r,"data-date-part":"date",key:`${l}-date-input`,max:h?.date??void 0,min:v?.date??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:_.date??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target)}),j("calcite-input-time-picker",{...m,class:r,"data-date-part":"time",key:`${l}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:e.timeStep,value:_.time??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target)}),e.includeTimeOffset?j("calcite-input-time-zone",{...m,class:r,"data-date-part":"timeZone",disabled:d,key:`${l}-timezone-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:_.timeZoneOffset??"0",onCalciteInputTimeZoneChange:e=>this._saveValueFromDateComponent(e.target)}):null)}_renderDateFieldComponents(e,t){const{includeTime:i,name:o,valid:n,value:a}=e,{class:s,key:r,max:l,min:d,readOnly:c}=t,{timeZone:u}=this,m={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!n,numberingSystem:R,overlayPositioning:"fixed",readOnly:c,[U]:o,onfocus:this._onComponentFocus},h=k(a,u),v=k(l,u),_=k(d,u);return j("div",{class:p.dateInputContainer,key:`${r}-date-time-container`},j("calcite-input-date-picker",{...m,class:s,"data-date-part":"date",key:`${r}-date-input`,max:v?.date??void 0,min:_?.date??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:h.date??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target)}),i?j("calcite-input-time-picker",{...m,class:s,"data-date-part":"time",key:`${r}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:1,value:h.time??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target)}):null)}_renderReadOnlyComponent(e,t){const i=this.getCommonInputProps(e);return j("calcite-input",{...i,class:this.classes(p.fieldInput,p.inputDisabled),readOnly:!0,type:"text",value:null!=t?`${t}`:i.value})}_renderComboBoxComponent(e,t,i){const{value:o,name:n}=e,{messages:a,messagesTemplates:s,viewModel:r,_inputsWithChanges:l}=this,d=t.map((e=>e.map((({name:e,value:t})=>j("calcite-combobox-item",{key:`#${t}`,selected:o===t,textLabel:e,value:`${t}`}))))),[p,c]=d;this.viewModel.fieldsWithInvalidCodedValue.has(e)&&c.unshift(j("calcite-combobox-item",{key:"incompatible-option",readOnly:!0,textLabel:`${e.value}`,value:`${e.value}`}));const u=c.length>0?[j("calcite-combobox-item-group",{key:"recommended",label:a.recommended},p),j("calcite-combobox-item-group",{key:"other",label:s.other},c)]:p,m="INSERT"===r.arcadeEditType,h=l.has(n),v=null==o&&(!m||h);e.showNoValueOptionEnabled&&u.unshift(j("calcite-combobox-item",{key:"empty-option",selected:v,textLabel:e.showNoValueLabel||a.empty,value:""}));const _=m&&e.showNoValueOptionEnabled&&!h?()=>{}:i.onblur;return j("calcite-combobox",{...i,allowCustomValues:!1,clearDisabled:!0,disabled:i.readOnly,onblur:_,overlayPositioning:"fixed",selectionMode:"single",onCalciteComboboxChange:({target:e})=>{v&&0===e.selectedItems.length?this._ignoreDeselectionOfNoValueOption(e):this._saveValueFromComponent(e)}},u)}_renderRadioButtonComponents(e,t,i){const{name:o,value:n}=e,a=t.map((({name:e,value:t})=>this._renderRadioButtonComponent({key:e,label:e,name:o,value:t,selected:t===n,props:i})));if(e.showNoValueOptionEnabled){const t="",s=e.showNoValueLabel||this.messages.empty,r=n===t||null===n;a.unshift(this._renderRadioButtonComponent({key:"empty-option",label:s,name:o,value:t,selected:r,props:i}))}return j("calcite-radio-button-group",{afterCreate:this._afterRadioGroupCreateOrUpdate,afterUpdate:this._afterRadioGroupCreateOrUpdate,class:p.inputRadioGroup,"data-field-name":i[U],key:`${i.key}-radio-group`,layout:"vertical",name:i.key,required:i.required},a)}_renderSwitchComponent(e,t){const{value:i}=e,o=!!v(e.element,"switch")&&i===e.element.input.onValue;return j("calcite-switch",{...t,checked:o,class:p.inputSwitch,disabled:t.readOnly,onblur:()=>{this._focusedFieldName=null},onCalciteSwitchChange:e=>this._saveValueFromComponent(e.target)})}_renderRadioButtonComponent({key:e,name:t,value:i,selected:o,label:n,props:a}){return j("calcite-label",{class:p.inputRadioLabel,key:e,layout:"inline"},j("calcite-radio-button",{...a,afterCreate:void 0,afterUpdate:void 0,checked:o,class:p.inputRadio,disabled:a.readOnly,name:t,onblur:()=>{this._focusedFieldName=null},value:i,onCalciteRadioButtonChange:({target:e})=>{e.checked&&this._saveValueFromComponent(e)}}),n)}_renderAuxiliaryText(e){const t=e.name,i=this._inputsWithChanges.has(t)&&!e.valid?_(e,this.messages,this.timeZone):null!=this.viewModel.contingencyConstraintViolations.get(t)?this.messages.validationErrors.valuesIncompatible:null!=e.valueExpressionExecutor&&e.valueExpressionExecutor.stale?this.messages.valueExpressionError:null;return null!=i?j("calcite-input-message",{icon:!0,status:"invalid"},i):this._renderDescriptionOrEmpty(e.description)}_renderShowAllRelatedRecordsListItem(e){const{featureCount:t,relationshipId:i,showAllActionVisible:o}=e,{relatedRecordCallbacks:n}=this;if(!o||!n?.showAllRelatedRecords)return;const a=this.messages;return j("calcite-list-item",{description:E(a.totalCount,{count:t}),label:a.showAll,value:!0,onCalciteListItemSelect:()=>this._onShowAllRelatedRecordsClick(i)},j("calcite-icon",{icon:"list",scale:"s",slot:"content-end"}))}_renderAddRelatedRecordButton(e){const{canAddRelatedFeature:t,relationshipId:i,relatedLayer:o}=e,{messages:n,relatedRecordCallbacks:a}=this;if(t&&a?.addRelatedRecord&&o)return j("calcite-button",{alignment:"center",appearance:"outline-fill",class:p.centeredButton,disabled:e.updating||!e.originHasValidKey,iconStart:"plus",key:`${i}-add-button`,onclick:()=>this._onAddRelatedRecordsClick(i,o),round:!0,scale:"s",width:"half"},e.relatedLayerIsTable?n.addRecord:n.addFeature)}_renderRelatedRecordListItem(e,t){const{feature:i,description:o,title:n}=e,{feature:a,relatedRecordCallbacks:s}=this,{highlightHelper:r}=this.viewModel,l=()=>{r?.removeAll(),s?.editRelatedRecord&&a&&s.editRelatedRecord({parentFeature:a,relationshipId:t,relatedFeature:i})},d=r?()=>r.add(i):void 0,p=r?()=>r.remove(i):void 0;return j("calcite-list-item",{bind:this,description:o,key:`${t}-${i.uid}`,label:n,onclick:l,onmouseenter:d,onmouseleave:p,value:n},j("calcite-icon",{icon:g(i),scale:"m",slot:"content-start"}),j("calcite-icon",{icon:"chevron-right",scale:"s",slot:"content-end"}))}_renderRelationshipInput(e){if(!this._relatedRecordsEnabled||!e.editable)return;const{featureCount:t,relationshipId:i,showAllEnabled:o}=e,n=o?null:this._renderDescriptionOrEmpty(e.description),a=t>0?this._renderRelatedRecordsList(e):e.loaded?e.originHasValidKey?this._renderNoRelatedRecordsNotice():this._renderNoValidOriginKeyNotice(e):void 0;return j("calcite-label",{class:this.classes(p.label,p.relatedRecordsLabel),key:`relationship-${i}-container`},j("div",null,this._renderRelatedRecordsHeaderContainer(e),n,a),this._renderAddRelatedRecordButton(e))}_renderRelatedRecordsHeaderContainer(e){const t=e.updating||!e.loaded;return j("div",{class:p.relatedRecordsHeader,key:`relationship-${e.relationshipId}-header`},j("span",null,e.label),t?j("calcite-loader",{inline:!0,key:"loader",label:this.messagesCommon?.loading,scale:"s",type:"indeterminate"}):void 0)}_renderRelatedRecordsList(e){const{relationshipId:t}=e;return j("calcite-list",{class:p.relatedRecordsList},e.relatedFeatureInfos.map((e=>this._renderRelatedRecordListItem(e,t))),this._renderShowAllRelatedRecordsListItem(e),this._renderObserverNode())}_renderNoValidOriginKeyNotice(e){const{messages:t}=this,i=e.relatedLayerIsTable?t.noOriginKeyRecord:t.noOriginKeyFeature,o=e.relationship?.keyField,n=this.viewModel.findField(o),a=e.layer?.fieldsIndex.get(o),s=n?.label||a?.alias||o,r=E(i,{relatedLayerName:e.relatedLayer?.title,originKeyField:s});return j("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},j("div",{slot:"message"},r))}_renderNoRelatedRecordsNotice(){return j("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},j("div",{slot:"message"},this.messagesFeature.noRelatedFeatures))}_renderObserverNode(){if(this.viewModel.activeRelationshipInput?.showAllEnabled)return j("div",{afterCreate:this._afterListObserverCreated,afterRemoved:this._afterListObserverRemoved,bind:this,class:p.listObserver,key:"feature-observer"})}getCommonInputProps(e){const{disabled:t}=this,{editable:i,hint:o,label:n,maxLength:a,minLength:s,name:r,range:{max:l,min:d},required:c,valid:u,value:m}=e,h=this._inputsWithChanges.has(r),v=!i||t;return{afterCreate:this._afterComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,"aria-invalid":u?"false":"true",class:this.classes(p.fieldInput,v?p.inputDisabled:null,h&&!u?p.inputInvalid:null),key:r,label:n,max:null!=l?l:void 0,min:null!=d?d:void 0,maxLength:a>-1?a:void 0,minLength:s>-1?s:void 0,placeholder:o??void 0,readOnly:v,required:c,value:null==m?"":`${m}`,onblur:this._onComponentBlur,onfocus:this._onComponentFocus,onkeydown:this._onComponentKeyDown,[U]:r}}_getFieldInputFromHTMLElement(e){return this.viewModel.findField(e.getAttribute(U))}_afterDateComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e),i=e.dataset.datePart,o=this._dateComponentMap.get(t.name);if("valueAsDate"in e&&null!=e.value){const t=e.value,i=new ResizeObserver((()=>{e.value=void 0,e.value=t,i.unobserve(e)}));i.observe(e)}if(null!=o)switch(i){case"date":o.date=e;break;case"time":o.time=e;break;case"timeZone":o.timeZone=e}else this._dateComponentMap.set(t.name,{[i]:e});this._afterDateComponentCreateOrUpdate(e)}_afterDateComponentCreateOrUpdate(e){this._afterComponentCreateOrUpdate(e)}_afterComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e);b(t)&&null!=e.value&&"setNumberValue"in e&&e.setNumberValue({committing:!1,value:e.value,origin:"direct"}),this._afterComponentCreateOrUpdate(e)}_afterRadioGroupCreateOrUpdate(e){const t=e.selectedItem,i=e.querySelector("calcite-radio-button"),o=t||i;o&&this._afterComponentCreateOrUpdate(o)}_afterComponentCreateOrUpdate(e){const{viewModel:t}=this,i=this._getFieldInputFromHTMLElement(e),o=t.findField(this._focusedFieldName);this._attemptFocusOnNextRender&&o===i&&(this._attemptFocusOnNextRender=!1,h(i)&&(i.group.open=!0),e.setFocus())}_onComponentFocus(e){const t=e.target,i=this._getFieldInputFromHTMLElement(t);this._focusedFieldName=i.name}_onComponentBlur(e){const t=e.target;this._focusedFieldName=null,this._saveValueFromComponent(t)}_saveValueFromDateComponent(e){const{timeZone:t}=this,i=this._getFieldInputFromHTMLElement(e),o=i.field.type,{name:n,range:a}=i,s=this._dateComponentMap.get(n);if(!s)return;let r=this.viewModel.getValue(n),l=null;"date-only"===o?l=e.value:"time-only"===o?(r=I(r),l=I(e.value)):l="timestamp-offset"===o?null!=e.value?M({dateComponent:s.date,timeComponent:s.time,timeZoneComponent:s.timeZone,oldValue:r,defaultTimeZone:t}):null:null!=e.value?D({oldValue:r,dateComponent:s.date,timeComponent:s.time,timeZone:t,max:a.max,min:a.min}):null,null!==l&&e.value?r!==l&&this._updateFieldValue(n,l):this._updateFieldValue(n,null)}_saveValueFromComponent(e){const t=this._getFieldInputFromHTMLElement(e);this._updateFieldValue(t.name,this._parseValue(e))}_onComponentKeyDown({key:e,target:t}){const i=this._getFieldInputFromHTMLElement(t);"Enter"===e&&h(i)&&!i.group.open&&(i.group.open=!0)}_updateFieldValue(e,t){if(this.viewModel.setValue(e,t),this._inputsWithChanges.add(e),this.viewModel.fieldsWithContingentValues.has(e)){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>null!=t)));this.viewModel.validateContingencyConstraints(e)}}_parseValue(e){const t=this._getFieldInputFromHTMLElement(e),i=e.value;return v(t.element,"switch")?e.checked?t.element.input.onValue:t.element.input.offValue:null==i||""===i?null:"number"===t.dataType?"-0"===i||"-0."===i||"-0,"===i?i:parseFloat(i):"date"===t.field.type?parseFloat(i):i}_ignoreDeselectionOfNoValueOption(e){const{firstChild:t,selectedItems:i}=e;0===i.length&&t&&"selected"in t?t.selected=!0:o.getLogger(this).warnOnce("Failed to override user attempt to deselect 'No value' option.")}_onGroupToggle(e,t){e.open?(t.open=!0,this._focusedFieldName=this._getFocusableInput("forward",t)?.name||null,this._attemptFocusOnNextRender=!0,"sequential"===this.groupDisplay&&this.viewModel.allGroupInputs.forEach((e=>{e!==t&&(e.open=!1)}))):t.open=!1,this.scheduleRender()}_onFormSubmit(e){e.preventDefault()}_onFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_afterListObserverCreated(e){this.viewModel.activeRelationshipInput&&(this._listObserverNode=e)}_afterListObserverRemoved(){this._listObserverNode=null}_onObserverChange(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode);const e=this.viewModel.activeRelationshipInput;e&&this._listObserverNode&&e.showAllEnabled&&this._listObserver.observe(this._listObserverNode)}_incrementRelatedRecordPage(){const e=this.viewModel.activeRelationshipInput;e?.incrementPage()}_syncGroupInputStates(){if("sequential"!==this.groupDisplay)return;const e=this.viewModel.allGroupInputs;if(!e.length)return;const t=e.filter((e=>e.open));0===t.length?e[0].open=!0:t.length>1&&t.slice(1).forEach((e=>e.open=!1))}};e([s()],S.prototype,"_listObserverNode",void 0),e([s()],S.prototype,"_relatedRecordsEnabled",null),e([s()],S.prototype,"disabled",null),e([s()],S.prototype,"feature",null),e([s()],S.prototype,"formTemplate",null),e([s()],S.prototype,"groupDisplay",void 0),e([s()],S.prototype,"headingLevel",void 0),e([s()],S.prototype,"label",null),e([s()],S.prototype,"layer",null),e([s()],S.prototype,"map",null),e([s(),L("esri/widgets/FeatureForm/t9n/FeatureForm")],S.prototype,"messages",void 0),e([s(),L("esri/t9n/common")],S.prototype,"messagesCommon",void 0),e([s(),L("esri/widgets/Feature/t9n/Feature")],S.prototype,"messagesFeature",void 0),e([s(),L("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],S.prototype,"messagesTemplates",void 0),e([s()],S.prototype,"relatedRecordCallbacks",null),e([s()],S.prototype,"relationshipId",null),e([s()],S.prototype,"spatialReference",null),e([s()],S.prototype,"strict",null),e([s()],S.prototype,"timeZone",null),e([s()],S.prototype,"view",null),e([s(),T(["value-change","submit"])],S.prototype,"viewModel",void 0),S=e([r("esri.widgets.FeatureForm")],S);const $=S;export{$ as default};
|
package/widgets/LayerList.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import t from"../core/Collection.js";import{deprecatedProperty as i}from"../core/deprecate.js";import o from"../core/Logger.js";import s from"../core/ReactiveMap.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as n}from"../core/accessorSupport/decorators/subclass.js";import{getActionIcon as r,getActionStyles as a}from"../support/actions/actionUtils.js";import c from"./Widget.js";import{css as d}from"./LayerList/css.js";import m from"./LayerList/LayerListViewModel.js";import p from"./LayerList/LayerListVisibleElements.js";import u from"./LayerList/ListItem.js";import{minDragEnabledItems as h,minFilterItems as g,getItem as v,getLayerType as y,sortableRoot as f,listItemHasChildren as _,canSortSublayers as b,getStatusIcon as I,getVisibilityIcon as w,sortLayersToIds as E,sortChildLayersToIds as L}from"./LayerList/support/layerListUtils.js";import{loadCalciteComponents as C}from"./support/componentsUtils.js";import{globalCss as A}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as M}from"./support/decorators/messageBundle.js";import{vmEvent as F}from"./support/decorators/vmEvent.js";import{tsx as k}from"./support/jsxFactory.js";const S=t.ofType(u),j="operational";let x=class extends c{constructor(e,t){super(e,t),this._activeItem=null,this._tooltipReferenceMap=new s,this._focusRootFlowItem=!1,this._focusPanelFlowItem=!1,this._lastDragDetail=null,this._selectedDragItemLayerUid=null,this.collapsed=!1,this.dragEnabled=!1,this.filterPlaceholder="",this.filterText="",this.headingLevel=2,this.icon=null,this.iconClass=d.widgetIcon,this.listItemCanGiveFunction=null,this.listItemCanReceiveFunction=null,this.messages=null,this.messagesCommon=null,this.minDragEnabledItems=h,this.minFilterItems=g,this.selectedItems=new S,this.selectionMode="none",this.viewModel=new m,this.visibilityAppearance="default",this.visibleElements=new p,this._canMove=({dragEl:e,fromEl:t,toEl:i},o)=>{const s="pull"===o?this.listItemCanGiveFunction:this.listItemCanReceiveFunction,l=v(e);if(!l?.sortable)return!1;const n=v(t),r=y(t),a=v(i),c=y(i),d=!!r&&!!c&&r===c,m={selected:l,from:n,to:a};return t.group&&i.group&&"function"==typeof s?s.call(null,m):d&&"sublayer"!==l?.layer?.type&&"map-image"!==n?.layer?.type&&"map-image"!==a?.layer?.type},this._clearActiveItem=()=>{this._activeItem=null},this._setActiveItem=e=>{if("default"!==this.visibilityAppearance)return;const t=Array.from(e.composedPath()).find((e=>e.classList?.contains(d.item)));this._activeItem=v(t)},this._onCalciteListOrderChange=e=>{const{_lastDragDetail:t}=this,{toEl:i,fromEl:o,dragEl:s,newIndex:l}=e;if(o&&i&&!(t?.newIndex===l&&t?.dragEl===s&&t?.toEl===i&&t?.fromEl===o))if(this._lastDragDetail=e,o!==i)this._moveLayerFromChildList({toEl:i,fromEl:o,dragEl:s,newIndex:l});else{const e=Array.from(o.children).filter((e=>e?.matches("calcite-list-item"))).map((e=>e.value));this._sortLayers(o,e)}}}loadDependencies(){return C({action:()=>import("@esri/calcite-components/dist/components/calcite-action.js"),"action-group":()=>import("@esri/calcite-components/dist/components/calcite-action-group.js"),"action-menu":()=>import("@esri/calcite-components/dist/components/calcite-action-menu.js"),button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow.js"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice.js"),tooltip:()=>import("@esri/calcite-components/dist/components/calcite-tooltip.js")})}destroy(){this._tooltipReferenceMap.clear()}get _dragEnabled(){return this.viewModel.totalItems>=this.minDragEnabledItems&&this.dragEnabled}get _filterEnabled(){return this.viewModel.totalItems>=this.minFilterItems&&this.visibleElements.filter}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get listItemCreatedFunction(){return this.viewModel.listItemCreatedFunction}set listItemCreatedFunction(e){this.viewModel.listItemCreatedFunction=e}get multipleSelectionEnabled(){return i(o.getLogger(this),"multipleSelectionEnabled",{replacement:"selectionMode",version:"4.29",warnOnce:!0}),"multiple"===this.selectionMode}set multipleSelectionEnabled(e){i(o.getLogger(this),"multipleSelectionEnabled",{replacement:"selectionMode",version:"4.29",warnOnce:!0}),this.selectionMode=e?"multiple":this.selectionEnabled?"single":"none"}get operationalItems(){return this.viewModel.operationalItems}set operationalItems(e){this.viewModel.operationalItems=e}get selectionEnabled(){return i(o.getLogger(this),"selectionEnabled",{replacement:"selectionMode, dragEnabled",version:"4.29",warnOnce:!0}),"none"!==this.selectionMode&&this.dragEnabled}set selectionEnabled(e){i(o.getLogger(this),"selectionEnabled",{replacement:"selectionMode, dragEnabled",version:"4.29",warnOnce:!0}),this.dragEnabled=e,this.selectionMode=e?this.multipleSelectionEnabled?"multiple":"single":"none"}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}triggerAction(e,t){return this.viewModel.triggerAction(e,t)}render(){const e=this.viewModel?.state,t={[A.hidden]:"loading"===e,[A.disabled]:"disabled"===e},i=this.operationalItems?.filter((e=>!e.hidden&&(this.visibleElements.errors||!e.error)));return k("div",{class:this.classes(d.base,A.widget,A.panel,t)},i?.length?[this._renderItemTooltips(i),this._renderItems(i)]:this._renderNoItems())}_renderItemTooltip(e){const{_tooltipReferenceMap:t,messages:i}=this;return e?k("calcite-tooltip",{key:`tooltip-${e.layer.uid}`,referenceElement:t.get(e.layer.uid)},i.layerIncompatibleTooltip):null}_renderItemTooltipNodes(e){return e.incompatible?this._renderItemTooltip(e):e.children?.filter((e=>!e.hidden)).toArray().map((e=>this._renderItemTooltipNodes(e)))}_renderItemTooltips(e){return e?.toArray().map((e=>this._renderItemTooltipNodes(e)))}_renderNoItemsMessage(){return k("div",{slot:"message"},this.messages.noItemsToDisplay)}_renderNoItems(){return k("div",{class:d.itemMessage,key:"esri-layer-list__no-items"},k("calcite-notice",{icon:"information",kind:"info",open:!0,scale:"m",width:"full"},this._renderNoItemsMessage()))}_renderPanelFlowItems(e){return e?e.flatten((e=>e.children)).filter((e=>!e.hidden)).toArray().filter((({panel:e})=>e?.open&&!e.disabled&&e.flowEnabled)).map((({title:e,panel:t})=>{const i=()=>this._handlePanelFlowItemBack(t);return k("calcite-flow-item",{afterCreate:this._focusPanelFlowItemNode,afterUpdate:this._focusPanelFlowItemNode,bind:this,description:e,heading:t.title,headingLevel:this.headingLevel,key:`flow-panel-${t.uid}`,onCalciteFlowItemBack:e=>{e.preventDefault(),i()}},t.render(),k("calcite-button",{appearance:"transparent",onclick:i,slot:"footer-actions",width:"full"},this.messagesCommon.back))})):[]}_handlePanelFlowItemBack(e){e.open=!1,this._focusRootFlowItem=!0}_focusRootFlowItemNode(e){this._focusRootFlowItem&&(this._focusRootFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_focusPanelFlowItemNode(e){this._focusPanelFlowItem&&(this._focusPanelFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_renderItems(e){const{visible:t,collapsed:i,_filterEnabled:o,visibleElements:{closeButton:s,collapseButton:l,heading:n,flow:r},_dragEnabled:a,selectionMode:c,filterText:m,filterPlaceholder:p,messages:u}=this,h=[k("calcite-flow-item",{afterCreate:this._focusRootFlowItemNode,afterUpdate:this._focusRootFlowItemNode,bind:this,closable:s,closed:!t,collapsed:i,collapsible:l,heading:n?u.widgetLabel:void 0,headingLevel:this.headingLevel,key:"root-flow-item",onCalciteFlowItemClose:()=>this.visible=!1},k("calcite-list",{afterCreate:e=>{e.addEventListener("focusin",this._setActiveItem),e.addEventListener("focusout",this._clearActiveItem)},afterRemoved:e=>{e.removeEventListener("focusin",this._setActiveItem),e.removeEventListener("focusout",this._clearActiveItem)},canPull:e=>this._canMove(e,"pull"),canPut:e=>this._canMove(e,"put"),"data-layer-type":j,dragEnabled:a,filterEnabled:o,filterPlaceholder:p,filterText:m,group:f,key:"root-list",label:u.widgetLabel,onmouseleave:this._clearActiveItem,onmouseover:this._setActiveItem,selectionAppearance:"border",selectionMode:c,onCalciteListChange:e=>this._handleCalciteListChange(e),onCalciteListDragEnd:e=>this._handleCalciteListDragEnd(e.detail),onCalciteListFilter:e=>this.filterText=e.target?.filterText??"",onCalciteListOrderChange:e=>this._onCalciteListOrderChange(e.detail)},e?.toArray().map((e=>this._renderItem(e))),e?.length&&o?k("div",{class:d.filterNoResults,slot:"filter-no-results"},k("calcite-notice",{kind:"info",open:!0,scale:"m",width:"full"},this._renderNoItemsMessage())):null)),this._renderPanelFlowItems(e)];return t?r?k("calcite-flow",{key:"root-flow"},h):h:null}_renderChildList(e,t=[]){const{_dragEnabled:i}=this,{children:o}=e,s=_(e),l=!s&&i&&"group"===e.layer?.type;return s||l?k("calcite-list",{canPull:e=>this._canMove(e,"pull"),canPut:e=>this._canMove(e,"put"),"data-item":e,"data-layer-type":j,dragEnabled:!!i&&(e.childrenSortable&&b(e)),group:e.layer.uid},o?.filter((e=>!e.hidden)).toArray().map((i=>this._renderItem(i,e,[...t,e.title])))):null}_renderItemMessage(e){return e.error?k("div",{class:d.itemMessage,key:"esri-layer-list__error",slot:"content-bottom"},k("calcite-notice",{icon:"exclamation-mark-triangle",kind:"warning",open:!0,scale:"s",width:"full"},k("div",{slot:"message"},this.messages.layerError))):e.incompatible?k("div",{class:d.itemMessage,key:"esri-layer-list__incompatible",slot:"content-bottom"},k("calcite-notice",{afterCreate:t=>this._setTooltipReference(t,e),afterRemoved:()=>this._removeTooltipReference(e),bind:this,icon:"exclamation-mark-triangle",kind:"warning",open:!0,scale:"s",tabIndex:0,width:"full"},k("div",{slot:"message"},this.messages.layerIncompatible))):null}_renderItem(e,t,i){const{_activeItem:o,_selectedDragItemLayerUid:s,selectionMode:l,selectedItems:n,messages:r}=this,a=e.title||r.untitledLayer,c=e.visibleAtCurrentScale?a:`${a} (${r.layerInvisibleAtScale})`,m=this._filterActions(e.actionsSections),p=this._countActions(m);return k("calcite-list-item",{afterCreate:t=>this._focusSelectedDragEl(t,e),afterUpdate:t=>this._focusSelectedDragEl(t,e),class:this.classes(d.item,{[d.itemActive]:o===e}),"data-item":e,dragDisabled:!e.sortable,dragSelected:e.layer.uid===s,id:e.layer.uid,key:`list-item-${e.layer.uid}`,metadata:{parentTitles:i,title:a},open:e.open,selected:"none"!==l&&n.includes(e),title:c,value:e.layer.uid,onCalciteListItemDragHandleChange:t=>this._handleCalciteListItemDragHandleChange(t,e),onCalciteListItemSelect:i=>this._handleCalciteListItemSelect(i,e,t),onCalciteListItemToggle:t=>this._handleCalciteListItemToggle(t,e)},k("div",{class:d.itemContent,slot:"content"},k("div",{class:this.classes({[d.itemInvisibleAtScale]:!e.visibleAtCurrentScale})},a)),this._renderItemStatus(e,t),this._renderItemToggle(e,t),this._renderItemTemporaryIcon(e),this._renderChildList(e,i),this._renderItemMessage(e),this._renderPanel(e.panel),this._renderPanelAction(e.panel),p>1?this._renderActionsSections(e,m):1===p?this._renderAction({item:e,action:this._getSingleActionButton(m),textEnabled:!1}):null)}_renderItemStatus(e,t){const{visibleElements:i}=this;if(!i.statusIndicators)return null;const{connectionStatus:o,publishing:s,updating:l}=e,n=l&&!t,r=!!o;return k("calcite-icon",{class:this.classes({[d.statusIndicator]:!0,[d.publishing]:s,[d.updating]:n,[d.connectionStatus]:r,[d.connectionStatusConnected]:r&&"connected"===o}),icon:I({connectionStatus:o,publishing:s}),key:"layer-item-status",scale:"s",slot:"actions-end"})}_renderItemTemporaryIcon(e){return this.visibleElements.temporaryLayerIndicators&&"persistenceEnabled"in e.layer&&!e.layer.persistenceEnabled?k("calcite-icon",{class:d.itemTemporaryIcon,icon:"temporary",key:"temporary-icon",scale:"s",slot:"actions-start",title:this.messages.temporary}):null}_renderItemToggle(e,t){const{messages:i,visibilityAppearance:o}=this,{visible:s}=e,l=t?.visibilityMode;if("inherited"===l)return null;const n=w({visible:s,exclusive:"exclusive"===l,visibilityAppearance:o}),r="checkbox"===o;return k("calcite-action",{appearance:"transparent",class:d.visibleToggle,icon:r?n:void 0,key:"visibility-toggle",onclick:()=>this._toggleVisibility(e,t),scale:"s",slot:r?"actions-start":"actions-end",text:i.layerVisibility,title:i.layerVisibility},r?null:k("calcite-icon",{class:this.classes({[d.visibleIcon]:"exclusive"!==l&&s}),icon:n,scale:"s"}))}_renderPanel(e){return!e?.open||e.disabled||e.flowEnabled?null:k("div",{class:d.itemContentBottom,key:`content-panel-${e.uid}`,slot:"content-bottom"},e.render())}_renderPanelAction(e){if(!e?.visible)return null;const{open:t,title:i,disabled:o}=e;return k("calcite-action",{active:t,appearance:"transparent",disabled:o,icon:r(e),key:`action-${e.uid}`,onclick:()=>this._togglePanel(e),scale:"s",slot:"actions-end",text:i??"",title:i??void 0},this._renderFallbackIcon(e))}_renderActionsSections(e,t){return k("calcite-action-menu",{appearance:"transparent",key:"item-action-menu",label:this.messagesCommon.menu,open:e.actionsOpen,overlayPositioning:"fixed",placement:"bottom-end",scale:"s",slot:"actions-end",onCalciteActionMenuOpen:t=>e.actionsOpen=t.target.open},k("calcite-action",{appearance:"transparent",icon:"ellipsis",scale:"s",slot:"trigger",text:this.messagesCommon.options,title:this.messagesCommon.options}),t.toArray().map(((t,i)=>this._renderActionSection(e,t,i))))}_renderActionSection(e,t,i){return k("calcite-action-group",{key:`action-section-${i}`},t.toArray().map((t=>this._renderAction({item:e,action:t,textEnabled:!0}))))}_renderFallbackIcon(e){const{className:t,icon:i}=e;if(i)return null;const o="image"in e?e.image:void 0,s={[d.itemActionIcon]:!!t,[d.itemActionImage]:!!o};return t&&(s[t]=!0),o||t?k("span",{"aria-hidden":"true",class:this.classes(d.itemActionIcon,s),key:"icon",styles:a(o)}):null}_renderAction(e){const{item:t,action:i,textEnabled:o}=e,{active:s,disabled:l,title:n,type:a,indicator:c}=i;return k("calcite-action",{active:"toggle"===a&&i.value,appearance:"transparent",disabled:l,icon:r(i),indicator:c,key:`action-${i.uid}`,loading:s,onclick:()=>this._triggerAction(t,i),scale:"s",slot:o?void 0:"actions-end",text:n??"",textEnabled:o,title:n??void 0},this._renderFallbackIcon(i))}_setTooltipReference(e,t){this._tooltipReferenceMap.set(t.layer.uid,e)}_removeTooltipReference(e){this._tooltipReferenceMap.delete(e.layer.uid)}_moveLayerFromChildList({toEl:e,fromEl:t,dragEl:i,newIndex:o}){const s=v(i),l=v(e),n=v(t);this.viewModel.moveListItem(s,n,l,o)}_handleCalciteListDragEnd(e){const{fromEl:t,dragEl:i,oldIndex:o}=e;t.insertBefore(i,t.children[o])}_sortLayers(e,t){if(e)if(e.group===f)E(this.view?.map?.layers,t);else{const i=v(e);if(!i)return;L(i,t)}}_getSingleActionButton(e){return e.reduce((e=>e)).filter((e=>e&&"button"===e.type)).at(0)}_filterActions(e){return e.map((e=>e.filter((e=>e.visible))))}_countActions(e){return e.reduce(((e,t)=>e+t.length),0)}_triggerAction(e,t){t&&e&&("toggle"===t.type&&(t.value=!t.value),this.triggerAction(t,e))}_handleCalciteListChange(e){const{selectionMode:t,selectedItems:i}=this;if("none"===t)return;const o=e.target.selectedItems.map((e=>v(e))).filter(Boolean);i.removeAll(),i.addMany(o)}_handleCalciteListItemToggle(e,t){e.stopPropagation(),t.open=e.target.open}_focusSelectedDragEl(e,t){this._selectedDragItemLayerUid===t.layer.uid&&requestAnimationFrame((()=>e?.setFocus()))}_handleCalciteListItemDragHandleChange(e,t){e.stopPropagation();const i=e.target.dragSelected;this._selectedDragItemLayerUid=i?t.layer.uid:null}_handleCalciteListItemSelect(e,t,i){v(e.target)===t&&"none"===this.selectionMode&&"inherited"!==i?.visibilityMode&&this._toggleVisibility(t,i)}_togglePanel(e){e.open=!e.open,e.open&&(this._focusPanelFlowItem=!0)}_toggleVisibility(e,t){if(!e)return;const i=t?.visibilityMode;"exclusive"===i&&e.visible||(e.visible=!e.visible)}};e([l()],x.prototype,"_activeItem",void 0),e([l()],x.prototype,"_tooltipReferenceMap",void 0),e([l()],x.prototype,"_focusRootFlowItem",void 0),e([l()],x.prototype,"_focusPanelFlowItem",void 0),e([l()],x.prototype,"_dragEnabled",null),e([l()],x.prototype,"_filterEnabled",null),e([l()],x.prototype,"collapsed",void 0),e([l()],x.prototype,"dragEnabled",void 0),e([l()],x.prototype,"filterPlaceholder",void 0),e([l()],x.prototype,"filterText",void 0),e([l()],x.prototype,"headingLevel",void 0),e([l()],x.prototype,"icon",void 0),e([l()],x.prototype,"iconClass",void 0),e([l()],x.prototype,"label",null),e([l()],x.prototype,"listItemCanGiveFunction",void 0),e([l()],x.prototype,"listItemCanReceiveFunction",void 0),e([l()],x.prototype,"listItemCreatedFunction",null),e([l(),M("esri/widgets/LayerList/t9n/LayerList")],x.prototype,"messages",void 0),e([l(),M("esri/t9n/common")],x.prototype,"messagesCommon",void 0),e([l()],x.prototype,"minDragEnabledItems",void 0),e([l()],x.prototype,"minFilterItems",void 0),e([l()],x.prototype,"multipleSelectionEnabled",null),e([l()],x.prototype,"operationalItems",null),e([l()],x.prototype,"selectionEnabled",null),e([l()],x.prototype,"selectedItems",void 0),e([l()],x.prototype,"selectionMode",void 0),e([l()],x.prototype,"view",null),e([F("trigger-action"),l({type:m})],x.prototype,"viewModel",void 0),e([l()],x.prototype,"visibilityAppearance",void 0),e([l({type:p,nonNullable:!0})],x.prototype,"visibleElements",void 0),x=e([n("esri.widgets.LayerList")],x);const P=x;export{P as default};
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import t from"../core/Collection.js";import{deprecatedProperty as i}from"../core/deprecate.js";import o from"../core/Logger.js";import s from"../core/ReactiveMap.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as n}from"../core/accessorSupport/decorators/subclass.js";import{getActionIcon as r,getActionStyles as a}from"../support/actions/actionUtils.js";import c from"./Widget.js";import{css as d}from"./LayerList/css.js";import m from"./LayerList/LayerListViewModel.js";import p from"./LayerList/LayerListVisibleElements.js";import u from"./LayerList/ListItem.js";import{minDragEnabledItems as h,minFilterItems as g,getItem as v,getLayerType as y,sortableRoot as f,listItemHasChildren as _,canSortSublayers as b,getStatusIcon as I,getVisibilityIcon as w,sortLayersToIds as E,sortChildLayersToIds as L}from"./LayerList/support/layerListUtils.js";import{loadCalciteComponents as C}from"./support/componentsUtils.js";import{globalCss as A}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as M}from"./support/decorators/messageBundle.js";import{vmEvent as F}from"./support/decorators/vmEvent.js";import{tsx as k}from"./support/jsxFactory.js";const S=t.ofType(u),j="operational";let x=class extends c{constructor(e,t){super(e,t),this._activeItem=null,this._tooltipReferenceMap=new s,this._focusRootFlowItem=!1,this._focusPanelFlowItem=!1,this._lastDragDetail=null,this._selectedDragItemLayerUid=null,this.collapsed=!1,this.dragEnabled=!1,this.filterPlaceholder="",this.filterText="",this.headingLevel=2,this.icon=null,this.iconClass=d.widgetIcon,this.listItemCanGiveFunction=null,this.listItemCanReceiveFunction=null,this.messages=null,this.messagesCommon=null,this.minDragEnabledItems=h,this.minFilterItems=g,this.selectedItems=new S,this.selectionMode="none",this.viewModel=new m,this.visibilityAppearance="default",this.visibleElements=new p,this._canMove=({dragEl:e,fromEl:t,toEl:i},o)=>{const s="pull"===o?this.listItemCanGiveFunction:this.listItemCanReceiveFunction,l=v(e);if(!l?.sortable)return!1;const n=v(t),r=y(t),a=v(i),c=y(i),d=!!r&&!!c&&r===c,m={selected:l,from:n,to:a};return t.group&&i.group&&"function"==typeof s?s.call(null,m):d&&"sublayer"!==l?.layer?.type&&"map-image"!==n?.layer?.type&&"map-image"!==a?.layer?.type},this._clearActiveItem=()=>{this._activeItem=null},this._setActiveItem=e=>{if("default"!==this.visibilityAppearance)return;const t=Array.from(e.composedPath()).find((e=>e.classList?.contains(d.item)));this._activeItem=v(t)},this._onCalciteListOrderChange=e=>{const{_lastDragDetail:t}=this,{toEl:i,fromEl:o,dragEl:s,newIndex:l}=e;if(o&&i&&!(t?.newIndex===l&&t?.dragEl===s&&t?.toEl===i&&t?.fromEl===o))if(this._lastDragDetail=e,o!==i)this._moveLayerFromChildList({toEl:i,fromEl:o,dragEl:s,newIndex:l});else{const e=Array.from(o.children).filter((e=>e?.matches("calcite-list-item"))).map((e=>e.value));this._sortLayers(o,e)}}}loadDependencies(){return C({action:()=>import("@esri/calcite-components/dist/components/calcite-action.js"),"action-group":()=>import("@esri/calcite-components/dist/components/calcite-action-group.js"),"action-menu":()=>import("@esri/calcite-components/dist/components/calcite-action-menu.js"),button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow.js"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice.js"),tooltip:()=>import("@esri/calcite-components/dist/components/calcite-tooltip.js")})}destroy(){this._tooltipReferenceMap.clear()}get _dragEnabled(){return this.viewModel.totalItems>=this.minDragEnabledItems&&this.dragEnabled}get _filterEnabled(){return this.viewModel.totalItems>=this.minFilterItems&&this.visibleElements.filter}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get listItemCreatedFunction(){return this.viewModel.listItemCreatedFunction}set listItemCreatedFunction(e){this.viewModel.listItemCreatedFunction=e}get multipleSelectionEnabled(){return i(o.getLogger(this),"multipleSelectionEnabled",{replacement:"selectionMode",version:"4.29",warnOnce:!0}),"multiple"===this.selectionMode}set multipleSelectionEnabled(e){i(o.getLogger(this),"multipleSelectionEnabled",{replacement:"selectionMode",version:"4.29",warnOnce:!0}),this.selectionMode=e?"multiple":this.selectionEnabled?"single":"none"}get operationalItems(){return this.viewModel.operationalItems}set operationalItems(e){this.viewModel.operationalItems=e}get selectionEnabled(){return i(o.getLogger(this),"selectionEnabled",{replacement:"selectionMode, dragEnabled",version:"4.29",warnOnce:!0}),"none"!==this.selectionMode&&this.dragEnabled}set selectionEnabled(e){i(o.getLogger(this),"selectionEnabled",{replacement:"selectionMode, dragEnabled",version:"4.29",warnOnce:!0}),this.dragEnabled=e,this.selectionMode=e?this.multipleSelectionEnabled?"multiple":"single":"none"}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}triggerAction(e,t){return this.viewModel.triggerAction(e,t)}render(){const e=this.viewModel?.state,t={[A.hidden]:"loading"===e,[A.disabled]:"disabled"===e},i=this.operationalItems?.filter((e=>!e.hidden&&(this.visibleElements.errors||!e.error)));return k("div",{class:this.classes(d.base,A.widget,A.panel,t)},i?.length?[this._renderItemTooltips(i),this._renderItems(i)]:this._renderNoItems())}_renderItemTooltip(e){const{_tooltipReferenceMap:t,messages:i}=this;return e?k("calcite-tooltip",{key:`tooltip-${e.layer.uid}`,referenceElement:t.get(e.layer.uid)},i.layerIncompatibleTooltip):null}_renderItemTooltipNodes(e){return e.incompatible?this._renderItemTooltip(e):e.children?.filter((e=>!e.hidden)).toArray().map((e=>this._renderItemTooltipNodes(e)))}_renderItemTooltips(e){return e?.toArray().map((e=>this._renderItemTooltipNodes(e)))}_renderNoItemsMessage(){return k("div",{slot:"message"},this.messages.noItemsToDisplay)}_renderNoItems(){return k("div",{class:d.itemMessage,key:"esri-layer-list__no-items"},k("calcite-notice",{icon:"information",kind:"info",open:!0,scale:"m",width:"full"},this._renderNoItemsMessage()))}_renderPanelFlowItems(e){return e?e.flatten((e=>e.children)).filter((e=>!e.hidden)).toArray().filter((({panel:e})=>e?.open&&!e.disabled&&e.flowEnabled)).map((({title:e,panel:t})=>{const i=()=>this._handlePanelFlowItemBack(t);return k("calcite-flow-item",{afterCreate:this._focusPanelFlowItemNode,afterUpdate:this._focusPanelFlowItemNode,bind:this,description:e,heading:t.title,headingLevel:this.headingLevel,key:`flow-panel-${t.uid}`,onCalciteFlowItemBack:e=>{e.preventDefault(),i()}},t.render(),k("calcite-button",{appearance:"transparent",onclick:i,slot:"footer-actions",width:"full"},this.messagesCommon.back))})):[]}_handlePanelFlowItemBack(e){e.open=!1,this._focusRootFlowItem=!0}_focusRootFlowItemNode(e){this._focusRootFlowItem&&(this._focusRootFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_focusPanelFlowItemNode(e){this._focusPanelFlowItem&&(this._focusPanelFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_renderItems(e){const{visible:t,collapsed:i,_filterEnabled:o,visibleElements:{closeButton:s,collapseButton:l,heading:n,flow:r},_dragEnabled:a,selectionMode:c,filterText:m,filterPlaceholder:p,messages:u}=this,h=[k("calcite-flow-item",{afterCreate:this._focusRootFlowItemNode,afterUpdate:this._focusRootFlowItemNode,bind:this,closable:s,closed:!t,collapsed:i,collapsible:l,heading:n?u.widgetLabel:void 0,headingLevel:this.headingLevel,key:"root-flow-item",onCalciteFlowItemClose:()=>this.visible=!1},k("calcite-list",{afterCreate:e=>{e.addEventListener("focusin",this._setActiveItem),e.addEventListener("focusout",this._clearActiveItem)},afterRemoved:e=>{e.removeEventListener("focusin",this._setActiveItem),e.removeEventListener("focusout",this._clearActiveItem)},canPull:e=>this._canMove(e,"pull"),canPut:e=>this._canMove(e,"put"),"data-layer-type":j,dragEnabled:a,filterEnabled:o,filterPlaceholder:p,filterText:m,group:f,key:"root-list",label:u.widgetLabel,onmouseleave:this._clearActiveItem,onmouseover:this._setActiveItem,selectionAppearance:"border",selectionMode:c,onCalciteListChange:e=>this._handleCalciteListChange(e),onCalciteListDragEnd:e=>this._handleCalciteListDragEnd(e.detail),onCalciteListFilter:e=>this.filterText=e.target?.filterText??"",onCalciteListOrderChange:e=>this._onCalciteListOrderChange(e.detail)},e?.toArray().map((e=>this._renderItem(e))),e?.length&&o?k("div",{class:d.filterNoResults,slot:"filter-no-results"},k("calcite-notice",{kind:"info",open:!0,scale:"m",width:"full"},this._renderNoItemsMessage())):null)),this._renderPanelFlowItems(e)];return t?r?k("calcite-flow",{key:"root-flow"},h):h:null}_renderChildList(e,t=[]){const{_dragEnabled:i}=this,{children:o}=e,s=_(e),l=!s&&i&&"group"===e.layer?.type;return s||l?k("calcite-list",{canPull:e=>this._canMove(e,"pull"),canPut:e=>this._canMove(e,"put"),"data-item":e,"data-layer-type":j,dragEnabled:!!i&&(e.childrenSortable&&b(e)),group:e.layer.uid},o?.filter((e=>!e.hidden)).toArray().map((i=>this._renderItem(i,e,[...t,e.title])))):null}_renderItemMessage(e){return e.error?k("div",{class:d.itemMessage,key:"esri-layer-list__error",slot:"content-bottom"},k("calcite-notice",{icon:"exclamation-mark-triangle",kind:"warning",open:!0,scale:"s",width:"full"},k("div",{slot:"message"},this.messages.layerError))):e.incompatible?k("div",{class:d.itemMessage,key:"esri-layer-list__incompatible",slot:"content-bottom"},k("calcite-notice",{afterCreate:t=>this._setTooltipReference(t,e),afterRemoved:()=>this._removeTooltipReference(e),bind:this,icon:"exclamation-mark-triangle",kind:"warning",open:!0,scale:"s",tabIndex:0,width:"full"},k("div",{slot:"message"},this.messages.layerIncompatible))):null}_renderItem(e,t,i){const{_activeItem:o,_selectedDragItemLayerUid:s,selectionMode:l,selectedItems:n,messages:r}=this,a=e.title||r.untitledLayer,c=e.visibleAtCurrentScale?a:`${a} (${r.layerInvisibleAtScale})`,m=this._filterActions(e.actionsSections),p=this._countActions(m);return k("calcite-list-item",{afterCreate:t=>this._focusSelectedDragEl(t,e),afterUpdate:t=>this._focusSelectedDragEl(t,e),class:this.classes(d.item,{[d.itemActive]:o===e}),"data-item":e,dragDisabled:!e.sortable,dragSelected:e.layer.uid===s,id:e.layer.uid,key:`list-item-${e.layer.uid}`,label:a,metadata:{parentTitles:i,title:a},open:e.open,selected:"none"!==l&&n.includes(e),title:c,value:e.layer.uid,onCalciteListItemDragHandleChange:t=>this._handleCalciteListItemDragHandleChange(t,e),onCalciteListItemSelect:i=>this._handleCalciteListItemSelect(i,e,t),onCalciteListItemToggle:t=>this._handleCalciteListItemToggle(t,e)},k("div",{class:this.classes({[d.itemContent]:!0,[d.itemInvisibleAtScale]:!e.visibleAtCurrentScale}),slot:"content"},a),this._renderItemStatus(e,t),this._renderItemToggle(e,t),this._renderItemTemporaryIcon(e),this._renderChildList(e,i),this._renderItemMessage(e),this._renderPanel(e.panel),this._renderPanelAction(e.panel),p>1?this._renderActionsSections(e,m):1===p?this._renderAction({item:e,action:this._getSingleActionButton(m),textEnabled:!1}):null)}_renderItemStatus(e,t){const{visibleElements:i}=this;if(!i.statusIndicators)return null;const{connectionStatus:o,publishing:s,updating:l}=e,n=l&&!t,r=!!o;return k("calcite-icon",{class:this.classes({[d.statusIndicator]:!0,[d.publishing]:s,[d.updating]:n,[d.connectionStatus]:r,[d.connectionStatusConnected]:r&&"connected"===o}),icon:I({connectionStatus:o,publishing:s}),key:"layer-item-status",scale:"s",slot:"actions-end"})}_renderItemTemporaryIcon(e){return this.visibleElements.temporaryLayerIndicators&&"persistenceEnabled"in e.layer&&!e.layer.persistenceEnabled?k("calcite-icon",{class:d.itemTemporaryIcon,icon:"temporary",key:"temporary-icon",scale:"s",slot:"actions-start",title:this.messages.temporary}):null}_renderItemToggle(e,t){const{messages:i,visibilityAppearance:o}=this,{visible:s}=e,l=t?.visibilityMode;if("inherited"===l)return null;const n=w({visible:s,exclusive:"exclusive"===l,visibilityAppearance:o}),r="checkbox"===o;return k("calcite-action",{appearance:"transparent",class:d.visibleToggle,icon:r?n:void 0,key:"visibility-toggle",onclick:()=>this._toggleVisibility(e,t),scale:"s",slot:r?"actions-start":"actions-end",text:i.layerVisibility,title:i.layerVisibility},r?null:k("calcite-icon",{class:this.classes({[d.visibleIcon]:"exclusive"!==l&&s}),icon:n,scale:"s"}))}_renderPanel(e){return!e?.open||e.disabled||e.flowEnabled?null:k("div",{class:d.itemContentBottom,key:`content-panel-${e.uid}`,slot:"content-bottom"},e.render())}_renderPanelAction(e){if(!e?.visible)return null;const{open:t,title:i,disabled:o}=e;return k("calcite-action",{active:t,appearance:"transparent",disabled:o,icon:r(e),key:`action-${e.uid}`,onclick:()=>this._togglePanel(e),scale:"s",slot:"actions-end",text:i??"",title:i??void 0},this._renderFallbackIcon(e))}_renderActionsSections(e,t){return k("calcite-action-menu",{appearance:"transparent",key:"item-action-menu",label:this.messagesCommon.menu,open:e.actionsOpen,overlayPositioning:"fixed",placement:"bottom-end",scale:"s",slot:"actions-end",onCalciteActionMenuOpen:t=>e.actionsOpen=t.target.open},k("calcite-action",{appearance:"transparent",icon:"ellipsis",scale:"s",slot:"trigger",text:this.messagesCommon.options,title:this.messagesCommon.options}),t.toArray().map(((t,i)=>this._renderActionSection(e,t,i))))}_renderActionSection(e,t,i){return k("calcite-action-group",{key:`action-section-${i}`},t.toArray().map((t=>this._renderAction({item:e,action:t,textEnabled:!0}))))}_renderFallbackIcon(e){const{className:t,icon:i}=e;if(i)return null;const o="image"in e?e.image:void 0,s={[d.itemActionIcon]:!!t,[d.itemActionImage]:!!o};return t&&(s[t]=!0),o||t?k("span",{"aria-hidden":"true",class:this.classes(d.itemActionIcon,s),key:"icon",styles:a(o)}):null}_renderAction(e){const{item:t,action:i,textEnabled:o}=e,{active:s,disabled:l,title:n,type:a,indicator:c}=i;return k("calcite-action",{active:"toggle"===a&&i.value,appearance:"transparent",disabled:l,icon:r(i),indicator:c,key:`action-${i.uid}`,loading:s,onclick:()=>this._triggerAction(t,i),scale:"s",slot:o?void 0:"actions-end",text:n??"",textEnabled:o,title:n??void 0},this._renderFallbackIcon(i))}_setTooltipReference(e,t){this._tooltipReferenceMap.set(t.layer.uid,e)}_removeTooltipReference(e){this._tooltipReferenceMap.delete(e.layer.uid)}_moveLayerFromChildList({toEl:e,fromEl:t,dragEl:i,newIndex:o}){const s=v(i),l=v(e),n=v(t);this.viewModel.moveListItem(s,n,l,o)}_handleCalciteListDragEnd(e){const{fromEl:t,dragEl:i,oldIndex:o}=e;t.insertBefore(i,t.children[o])}_sortLayers(e,t){if(e)if(e.group===f)E(this.view?.map?.layers,t);else{const i=v(e);if(!i)return;L(i,t)}}_getSingleActionButton(e){return e.reduce((e=>e)).filter((e=>e&&"button"===e.type)).at(0)}_filterActions(e){return e.map((e=>e.filter((e=>e.visible))))}_countActions(e){return e.reduce(((e,t)=>e+t.length),0)}_triggerAction(e,t){t&&e&&("toggle"===t.type&&(t.value=!t.value),this.triggerAction(t,e))}_handleCalciteListChange(e){const{selectionMode:t,selectedItems:i}=this;if("none"===t)return;const o=e.target.selectedItems.map((e=>v(e))).filter(Boolean);i.removeAll(),i.addMany(o)}_handleCalciteListItemToggle(e,t){e.stopPropagation(),t.open=e.target.open}_focusSelectedDragEl(e,t){this._selectedDragItemLayerUid===t.layer.uid&&requestAnimationFrame((()=>e?.setFocus()))}_handleCalciteListItemDragHandleChange(e,t){e.stopPropagation();const i=e.target.dragSelected;this._selectedDragItemLayerUid=i?t.layer.uid:null}_handleCalciteListItemSelect(e,t,i){v(e.target)===t&&"none"===this.selectionMode&&"inherited"!==i?.visibilityMode&&this._toggleVisibility(t,i)}_togglePanel(e){e.open=!e.open,e.open&&(this._focusPanelFlowItem=!0)}_toggleVisibility(e,t){if(!e)return;const i=t?.visibilityMode;"exclusive"===i&&e.visible||(e.visible=!e.visible)}};e([l()],x.prototype,"_activeItem",void 0),e([l()],x.prototype,"_tooltipReferenceMap",void 0),e([l()],x.prototype,"_focusRootFlowItem",void 0),e([l()],x.prototype,"_focusPanelFlowItem",void 0),e([l()],x.prototype,"_dragEnabled",null),e([l()],x.prototype,"_filterEnabled",null),e([l()],x.prototype,"collapsed",void 0),e([l()],x.prototype,"dragEnabled",void 0),e([l()],x.prototype,"filterPlaceholder",void 0),e([l()],x.prototype,"filterText",void 0),e([l()],x.prototype,"headingLevel",void 0),e([l()],x.prototype,"icon",void 0),e([l()],x.prototype,"iconClass",void 0),e([l()],x.prototype,"label",null),e([l()],x.prototype,"listItemCanGiveFunction",void 0),e([l()],x.prototype,"listItemCanReceiveFunction",void 0),e([l()],x.prototype,"listItemCreatedFunction",null),e([l(),M("esri/widgets/LayerList/t9n/LayerList")],x.prototype,"messages",void 0),e([l(),M("esri/t9n/common")],x.prototype,"messagesCommon",void 0),e([l()],x.prototype,"minDragEnabledItems",void 0),e([l()],x.prototype,"minFilterItems",void 0),e([l()],x.prototype,"multipleSelectionEnabled",null),e([l()],x.prototype,"operationalItems",null),e([l()],x.prototype,"selectionEnabled",null),e([l()],x.prototype,"selectedItems",void 0),e([l()],x.prototype,"selectionMode",void 0),e([l()],x.prototype,"view",null),e([F("trigger-action"),l({type:m})],x.prototype,"viewModel",void 0),e([l()],x.prototype,"visibilityAppearance",void 0),e([l({type:p,nonNullable:!0})],x.prototype,"visibleElements",void 0),x=e([n("esri.widgets.LayerList")],x);const P=x;export{P as default};
|
package/widgets/TableList.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import t from"../core/Collection.js";import{deprecatedProperty as i}from"../core/deprecate.js";import o from"../core/Logger.js";import{property as s}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as n}from"../core/accessorSupport/decorators/subclass.js";import{getActionIcon as l,getActionStyles as a}from"../support/actions/actionUtils.js";import r from"./Widget.js";import{minDragEnabledItems as c,minFilterItems as d,getLayerType as m,sortableRoot as p}from"./LayerList/support/layerListUtils.js";import{loadCalciteComponents as u}from"./support/componentsUtils.js";import{globalCss as h}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as g}from"./support/decorators/messageBundle.js";import{vmEvent as b}from"./support/decorators/vmEvent.js";import{tsx as f}from"./support/jsxFactory.js";import{css as _}from"./TableList/css.js";import I from"./TableList/ListItem.js";import v from"./TableList/TableListViewModel.js";import y from"./TableList/TableListVisibleElements.js";import{getItem as w,sortTablesToIds as E}from"./TableList/support/tableListUtils.js";const C=t.ofType(I),F="table";let L=class extends r{constructor(e,t){super(e,t),this._focusRootFlowItem=!1,this._focusPanelFlowItem=!1,this._lastDragDetail=null,this._selectedDragItemLayerUid=null,this.collapsed=!1,this.dragEnabled=!1,this.filterPlaceholder="",this.filterText="",this.headingLevel=2,this.icon=null,this.iconClass=_.widgetIcon,this.listItemCanGiveFunction=null,this.listItemCanReceiveFunction=null,this.messages=null,this.messagesCommon=null,this.minDragEnabledItems=c,this.minFilterItems=d,this.selectedItems=new C,this.selectionMode="none",this.viewModel=new v,this.visibleElements=new y,this._canMove=({dragEl:e,fromEl:t,toEl:i},o)=>{const s="pull"===o?this.listItemCanGiveFunction:this.listItemCanReceiveFunction,n=w(e);if(!n?.sortable)return!1;const l=w(t),a=m(t),r=w(i),c=m(i),d=!!a&&!!c&&a===c,p={selected:n,from:l,to:r};return t.group&&i.group&&"function"==typeof s?s.call(null,p):d},this._onCalciteListOrderChange=e=>{const{_lastDragDetail:t}=this,{toEl:i,fromEl:o,dragEl:s,newIndex:n}=e;if(!o||!i||t?.newIndex===n&&t?.dragEl===s&&t?.toEl===i&&t?.fromEl===o)return;this._lastDragDetail=e;const l=Array.from(o.children).filter((e=>e?.matches("calcite-list-item"))).map((e=>e.value));E(this.map?.tables,l)}}loadDependencies(){return u({action:()=>import("@esri/calcite-components/dist/components/calcite-action.js"),"action-group":()=>import("@esri/calcite-components/dist/components/calcite-action-group.js"),"action-menu":()=>import("@esri/calcite-components/dist/components/calcite-action-menu.js"),button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow.js"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice.js")})}get _dragEnabled(){return this.viewModel.totalItems>=this.minDragEnabledItems&&this.dragEnabled}get _filterEnabled(){return this.viewModel.totalItems>=this.minFilterItems&&this.visibleElements.filter}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get listItemCreatedFunction(){return this.viewModel.listItemCreatedFunction}set listItemCreatedFunction(e){this.viewModel.listItemCreatedFunction=e}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get multipleSelectionEnabled(){return i(o.getLogger(this),"multipleSelectionEnabled",{replacement:"selectionMode",version:"4.29",warnOnce:!0}),"multiple"===this.selectionMode}set multipleSelectionEnabled(e){i(o.getLogger(this),"multipleSelectionEnabled",{replacement:"selectionMode",version:"4.29",warnOnce:!0}),this.selectionMode=e?"multiple":this.selectionEnabled?"single":"none"}get selectionEnabled(){return i(o.getLogger(this),"selectionEnabled",{replacement:"selectionMode, dragEnabled",version:"4.29",warnOnce:!0}),"none"!==this.selectionMode&&this.dragEnabled}set selectionEnabled(e){i(o.getLogger(this),"selectionEnabled",{replacement:"selectionMode, dragEnabled",version:"4.29",warnOnce:!0}),this.dragEnabled=e,this.selectionMode=e?this.multipleSelectionEnabled?"multiple":"single":"none"}get tableItems(){return this.viewModel.tableItems}triggerAction(e,t){return this.viewModel.triggerAction(e,t)}render(){const e=this.viewModel?.state,t={[h.hidden]:"loading"===e,[h.disabled]:"disabled"===e},i=this.tableItems?.filter((e=>!e.hidden&&(this.visibleElements.errors||!e.error)));return f("div",{class:this.classes(_.base,h.widget,h.panel,t)},i?.length?this._renderItems(i):this._renderNoItems())}_renderNoItemsMessage(){return f("div",{slot:"message"},this.messages.noItemsToDisplay)}_renderNoItems(){return f("div",{class:_.itemMessage,key:"esri-layer-list__no-items"},f("calcite-notice",{icon:"information",kind:"info",open:!0,scale:"m",width:"full"},this._renderNoItemsMessage()))}_renderPanelFlowItems(e){return e?.toArray().filter((({panel:e})=>e?.open&&!e.disabled&&e.flowEnabled)).map((({title:e,panel:t})=>{const i=()=>this._handlePanelFlowItemBack(t);return f("calcite-flow-item",{afterCreate:this._focusPanelFlowItemNode,afterUpdate:this._focusPanelFlowItemNode,bind:this,description:e,heading:t.title,headingLevel:this.headingLevel,key:`flow-panel-${t.uid}`,onCalciteFlowItemBack:e=>{e.preventDefault(),i()}},t.render(),f("calcite-button",{appearance:"transparent",onclick:i,slot:"footer-actions",width:"full"},this.messagesCommon.back))}))}_handlePanelFlowItemBack(e){e.open=!1,this._focusRootFlowItem=!0}_focusRootFlowItemNode(e){this._focusRootFlowItem&&(this._focusRootFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_focusPanelFlowItemNode(e){this._focusPanelFlowItem&&(this._focusPanelFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_renderItems(e){const{visible:t,collapsed:i,visibleElements:{closeButton:o,collapseButton:s,heading:n,flow:l},_dragEnabled:a,_filterEnabled:r,selectionMode:c,messages:d,filterPlaceholder:m,filterText:u}=this,h=[f("calcite-flow-item",{afterCreate:this._focusRootFlowItemNode,afterUpdate:this._focusRootFlowItemNode,bind:this,closable:o,closed:!t,collapsed:i,collapsible:s,heading:n?d.widgetLabel:void 0,headingLevel:this.headingLevel,key:"root-flow-item",onCalciteFlowItemClose:()=>this.visible=!1},f("calcite-list",{canPull:e=>this._canMove(e,"pull"),canPut:e=>this._canMove(e,"put"),"data-layer-type":F,dragEnabled:a,filterEnabled:r,filterPlaceholder:m,filterText:u,group:p,key:"root-list",label:d.widgetLabel,selectionAppearance:"border",selectionMode:c,onCalciteListChange:e=>this._handleCalciteListChange(e),onCalciteListDragEnd:e=>this._handleCalciteListDragEnd(e.detail),onCalciteListFilter:e=>this.filterText=e.target?.filterText??"",onCalciteListOrderChange:e=>this._onCalciteListOrderChange(e.detail)},e?.toArray().map((e=>this._renderItem(e))),e?.length&&r?f("div",{class:_.filterNoResults,slot:"filter-no-results"},f("calcite-notice",{kind:"info",open:!0,scale:"m",width:"full"},this._renderNoItemsMessage())):null)),this._renderPanelFlowItems(e)];return t?l?f("calcite-flow",{key:"root-flow"},h):h:null}_handleCalciteListDragEnd(e){const{fromEl:t,dragEl:i,oldIndex:o}=e;t.insertBefore(i,t.children[o])}_renderItemMessage(e){return e.error?f("div",{class:_.itemMessage,key:"esri-layer-list__error",slot:"content-bottom"},f("calcite-notice",{icon:"exclamation-mark-triangle",kind:"warning",open:!0,scale:"s",width:"full"},f("div",{slot:"message"},this.messages.tableError))):null}_renderItem(e){const{_selectedDragItemLayerUid:t,selectionMode:i,selectedItems:o,messages:s}=this,n=e.title||s.untitledTable,l=this._filterActions(e.actionsSections),a=this._countActions(l);return f("calcite-list-item",{afterCreate:t=>this._focusSelectedDragEl(t,e),afterUpdate:t=>this._focusSelectedDragEl(t,e),class:_.item,"data-item":e,dragDisabled:!e.sortable,dragSelected:e.layer.uid===t,id:e.layer?.uid,key:`list-item-${e.layer.uid}`,metadata:{title:n},selected:"none"!==i&&o.includes(e),title:n,value:e.layer?.uid,onCalciteListItemDragHandleChange:t=>this._handleCalciteListItemDragHandleChange(t,e)},f("div",{class:_.itemContent,slot:"content"},n),this._renderItemStatus(e),this._renderItemTemporaryIcon(e),this._renderItemMessage(e),this._renderPanel(e.panel),this._renderPanelAction(e.panel),a>1?this._renderActionsSections(e,l):1===a?this._renderAction({item:e,action:this._getSingleActionButton(l),textEnabled:!1}):null)}_renderItemTemporaryIcon(e){return this.visibleElements.temporaryTableIndicators&&!e.layer.persistenceEnabled?f("calcite-icon",{class:_.itemTemporaryIcon,icon:"temporary",key:"temporary-icon",scale:"s",slot:"actions-start",title:this.messages.temporary}):null}_renderItemStatus(e){const{visibleElements:t}=this;if(!t.statusIndicators)return null;const{publishing:i}=e;return f("calcite-icon",{class:this.classes({[_.statusIndicator]:!0,[_.publishing]:i}),icon:"stop-square",key:"layer-item-status",scale:"s",slot:"actions-end"})}_renderPanel(e){return!e?.open||e.disabled||e.flowEnabled?null:f("div",{class:_.itemContentBottom,key:`content-panel-${e.uid}`,slot:"content-bottom"},e.render())}_renderPanelAction(e){if(!e?.visible)return null;const{open:t,title:i,disabled:o}=e;return f("calcite-action",{active:t,appearance:"transparent",disabled:o,icon:l(e),key:`action-${e.uid}`,onclick:()=>this._togglePanel(e),scale:"s",slot:"actions-end",text:i??"",title:i??void 0},this._renderFallbackIcon(e))}_renderActionsSections(e,t){return f("calcite-action-menu",{appearance:"transparent",key:"item-action-menu",label:this.messagesCommon.menu,open:e.actionsOpen,overlayPositioning:"fixed",placement:"bottom-end",scale:"s",slot:"actions-end",onCalciteActionMenuOpen:t=>e.actionsOpen=t.target.open},f("calcite-action",{appearance:"transparent",icon:"ellipsis",scale:"s",slot:"trigger",text:this.messagesCommon.options,title:this.messagesCommon.options}),t.toArray().map(((t,i)=>this._renderActionSection(e,t,i))))}_renderActionSection(e,t,i){return f("calcite-action-group",{key:`action-section-${i}`},t.toArray().map((t=>this._renderAction({item:e,action:t,textEnabled:!0}))))}_renderFallbackIcon(e){const{className:t,icon:i}=e;if(i)return null;const o="image"in e?e.image:void 0,s={[_.itemActionIcon]:!!t,[_.itemActionImage]:!!o};return t&&(s[t]=!0),o||t?f("span",{"aria-hidden":"true",class:this.classes(_.itemActionIcon,s),key:"icon",styles:a(o)}):null}_renderAction(e){const{item:t,action:i,textEnabled:o}=e,{active:s,disabled:n,title:a,type:r,indicator:c}=i;return f("calcite-action",{active:"toggle"===r&&i.value,appearance:"transparent",disabled:n,icon:l(i),indicator:c,key:`action-${i.uid}`,loading:s,onclick:()=>this._triggerAction(t,i),scale:"s",slot:o?void 0:"actions-end",text:a??"",textEnabled:o,title:a??void 0},this._renderFallbackIcon(i))}_filterActions(e){return e.map((e=>e.filter((e=>e.visible))))}_getSingleActionButton(e){return e.reduce((e=>e)).filter((e=>e&&"button"===e.type)).at(0)}_countActions(e){return e.reduce(((e,t)=>e+t.length),0)}_focusSelectedDragEl(e,t){this._selectedDragItemLayerUid===t.layer.uid&&requestAnimationFrame((()=>e?.setFocus()))}_handleCalciteListItemDragHandleChange(e,t){e.stopPropagation();const i=e.target.dragSelected;this._selectedDragItemLayerUid=i?t.layer.uid:null}_handleCalciteListChange(e){const{selectionMode:t,selectedItems:i}=this;if("none"===t)return;const o=e.target.selectedItems.map((e=>w(e))).filter(Boolean);i.removeAll(),i.addMany(o)}_togglePanel(e){e.open=!e.open,e.open&&(this._focusPanelFlowItem=!0)}_triggerAction(e,t){t&&e&&("toggle"===t.type&&(t.value=!t.value),this.triggerAction(t,e))}};e([s()],L.prototype,"_focusRootFlowItem",void 0),e([s()],L.prototype,"_focusPanelFlowItem",void 0),e([s()],L.prototype,"_dragEnabled",null),e([s()],L.prototype,"_filterEnabled",null),e([s()],L.prototype,"collapsed",void 0),e([s()],L.prototype,"dragEnabled",void 0),e([s()],L.prototype,"filterPlaceholder",void 0),e([s()],L.prototype,"filterText",void 0),e([s()],L.prototype,"headingLevel",void 0),e([s()],L.prototype,"icon",void 0),e([s()],L.prototype,"iconClass",void 0),e([s()],L.prototype,"label",null),e([s()],L.prototype,"listItemCanGiveFunction",void 0),e([s()],L.prototype,"listItemCanReceiveFunction",void 0),e([s()],L.prototype,"listItemCreatedFunction",null),e([s()],L.prototype,"map",null),e([s(),g("esri/widgets/TableList/t9n/TableList")],L.prototype,"messages",void 0),e([s(),g("esri/t9n/common")],L.prototype,"messagesCommon",void 0),e([s()],L.prototype,"minDragEnabledItems",void 0),e([s()],L.prototype,"minFilterItems",void 0),e([s()],L.prototype,"multipleSelectionEnabled",null),e([s()],L.prototype,"selectionEnabled",null),e([s()],L.prototype,"selectedItems",void 0),e([s()],L.prototype,"selectionMode",void 0),e([s({readOnly:!0})],L.prototype,"tableItems",null),e([b("trigger-action"),s({type:v})],L.prototype,"viewModel",void 0),e([s({type:y,nonNullable:!0})],L.prototype,"visibleElements",void 0),L=e([n("esri.widgets.TableList")],L);const M=L;export{M as default};
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import t from"../core/Collection.js";import{deprecatedProperty as i}from"../core/deprecate.js";import o from"../core/Logger.js";import{property as s}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as n}from"../core/accessorSupport/decorators/subclass.js";import{getActionIcon as l,getActionStyles as a}from"../support/actions/actionUtils.js";import r from"./Widget.js";import{minDragEnabledItems as c,minFilterItems as d,getLayerType as m,sortableRoot as p}from"./LayerList/support/layerListUtils.js";import{loadCalciteComponents as u}from"./support/componentsUtils.js";import{globalCss as h}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as g}from"./support/decorators/messageBundle.js";import{vmEvent as b}from"./support/decorators/vmEvent.js";import{tsx as f}from"./support/jsxFactory.js";import{css as _}from"./TableList/css.js";import I from"./TableList/ListItem.js";import v from"./TableList/TableListViewModel.js";import y from"./TableList/TableListVisibleElements.js";import{getItem as w,sortTablesToIds as E}from"./TableList/support/tableListUtils.js";const C=t.ofType(I),F="table";let L=class extends r{constructor(e,t){super(e,t),this._focusRootFlowItem=!1,this._focusPanelFlowItem=!1,this._lastDragDetail=null,this._selectedDragItemLayerUid=null,this.collapsed=!1,this.dragEnabled=!1,this.filterPlaceholder="",this.filterText="",this.headingLevel=2,this.icon=null,this.iconClass=_.widgetIcon,this.listItemCanGiveFunction=null,this.listItemCanReceiveFunction=null,this.messages=null,this.messagesCommon=null,this.minDragEnabledItems=c,this.minFilterItems=d,this.selectedItems=new C,this.selectionMode="none",this.viewModel=new v,this.visibleElements=new y,this._canMove=({dragEl:e,fromEl:t,toEl:i},o)=>{const s="pull"===o?this.listItemCanGiveFunction:this.listItemCanReceiveFunction,n=w(e);if(!n?.sortable)return!1;const l=w(t),a=m(t),r=w(i),c=m(i),d=!!a&&!!c&&a===c,p={selected:n,from:l,to:r};return t.group&&i.group&&"function"==typeof s?s.call(null,p):d},this._onCalciteListOrderChange=e=>{const{_lastDragDetail:t}=this,{toEl:i,fromEl:o,dragEl:s,newIndex:n}=e;if(!o||!i||t?.newIndex===n&&t?.dragEl===s&&t?.toEl===i&&t?.fromEl===o)return;this._lastDragDetail=e;const l=Array.from(o.children).filter((e=>e?.matches("calcite-list-item"))).map((e=>e.value));E(this.map?.tables,l)}}loadDependencies(){return u({action:()=>import("@esri/calcite-components/dist/components/calcite-action.js"),"action-group":()=>import("@esri/calcite-components/dist/components/calcite-action-group.js"),"action-menu":()=>import("@esri/calcite-components/dist/components/calcite-action-menu.js"),button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow.js"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice.js")})}get _dragEnabled(){return this.viewModel.totalItems>=this.minDragEnabledItems&&this.dragEnabled}get _filterEnabled(){return this.viewModel.totalItems>=this.minFilterItems&&this.visibleElements.filter}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get listItemCreatedFunction(){return this.viewModel.listItemCreatedFunction}set listItemCreatedFunction(e){this.viewModel.listItemCreatedFunction=e}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get multipleSelectionEnabled(){return i(o.getLogger(this),"multipleSelectionEnabled",{replacement:"selectionMode",version:"4.29",warnOnce:!0}),"multiple"===this.selectionMode}set multipleSelectionEnabled(e){i(o.getLogger(this),"multipleSelectionEnabled",{replacement:"selectionMode",version:"4.29",warnOnce:!0}),this.selectionMode=e?"multiple":this.selectionEnabled?"single":"none"}get selectionEnabled(){return i(o.getLogger(this),"selectionEnabled",{replacement:"selectionMode, dragEnabled",version:"4.29",warnOnce:!0}),"none"!==this.selectionMode&&this.dragEnabled}set selectionEnabled(e){i(o.getLogger(this),"selectionEnabled",{replacement:"selectionMode, dragEnabled",version:"4.29",warnOnce:!0}),this.dragEnabled=e,this.selectionMode=e?this.multipleSelectionEnabled?"multiple":"single":"none"}get tableItems(){return this.viewModel.tableItems}triggerAction(e,t){return this.viewModel.triggerAction(e,t)}render(){const e=this.viewModel?.state,t={[h.hidden]:"loading"===e,[h.disabled]:"disabled"===e},i=this.tableItems?.filter((e=>!e.hidden&&(this.visibleElements.errors||!e.error)));return f("div",{class:this.classes(_.base,h.widget,h.panel,t)},i?.length?this._renderItems(i):this._renderNoItems())}_renderNoItemsMessage(){return f("div",{slot:"message"},this.messages.noItemsToDisplay)}_renderNoItems(){return f("div",{class:_.itemMessage,key:"esri-layer-list__no-items"},f("calcite-notice",{icon:"information",kind:"info",open:!0,scale:"m",width:"full"},this._renderNoItemsMessage()))}_renderPanelFlowItems(e){return e?.toArray().filter((({panel:e})=>e?.open&&!e.disabled&&e.flowEnabled)).map((({title:e,panel:t})=>{const i=()=>this._handlePanelFlowItemBack(t);return f("calcite-flow-item",{afterCreate:this._focusPanelFlowItemNode,afterUpdate:this._focusPanelFlowItemNode,bind:this,description:e,heading:t.title,headingLevel:this.headingLevel,key:`flow-panel-${t.uid}`,onCalciteFlowItemBack:e=>{e.preventDefault(),i()}},t.render(),f("calcite-button",{appearance:"transparent",onclick:i,slot:"footer-actions",width:"full"},this.messagesCommon.back))}))}_handlePanelFlowItemBack(e){e.open=!1,this._focusRootFlowItem=!0}_focusRootFlowItemNode(e){this._focusRootFlowItem&&(this._focusRootFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_focusPanelFlowItemNode(e){this._focusPanelFlowItem&&(this._focusPanelFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_renderItems(e){const{visible:t,collapsed:i,visibleElements:{closeButton:o,collapseButton:s,heading:n,flow:l},_dragEnabled:a,_filterEnabled:r,selectionMode:c,messages:d,filterPlaceholder:m,filterText:u}=this,h=[f("calcite-flow-item",{afterCreate:this._focusRootFlowItemNode,afterUpdate:this._focusRootFlowItemNode,bind:this,closable:o,closed:!t,collapsed:i,collapsible:s,heading:n?d.widgetLabel:void 0,headingLevel:this.headingLevel,key:"root-flow-item",onCalciteFlowItemClose:()=>this.visible=!1},f("calcite-list",{canPull:e=>this._canMove(e,"pull"),canPut:e=>this._canMove(e,"put"),"data-layer-type":F,dragEnabled:a,filterEnabled:r,filterPlaceholder:m,filterText:u,group:p,key:"root-list",label:d.widgetLabel,selectionAppearance:"border",selectionMode:c,onCalciteListChange:e=>this._handleCalciteListChange(e),onCalciteListDragEnd:e=>this._handleCalciteListDragEnd(e.detail),onCalciteListFilter:e=>this.filterText=e.target?.filterText??"",onCalciteListOrderChange:e=>this._onCalciteListOrderChange(e.detail)},e?.toArray().map((e=>this._renderItem(e))),e?.length&&r?f("div",{class:_.filterNoResults,slot:"filter-no-results"},f("calcite-notice",{kind:"info",open:!0,scale:"m",width:"full"},this._renderNoItemsMessage())):null)),this._renderPanelFlowItems(e)];return t?l?f("calcite-flow",{key:"root-flow"},h):h:null}_handleCalciteListDragEnd(e){const{fromEl:t,dragEl:i,oldIndex:o}=e;t.insertBefore(i,t.children[o])}_renderItemMessage(e){return e.error?f("div",{class:_.itemMessage,key:"esri-layer-list__error",slot:"content-bottom"},f("calcite-notice",{icon:"exclamation-mark-triangle",kind:"warning",open:!0,scale:"s",width:"full"},f("div",{slot:"message"},this.messages.tableError))):null}_renderItem(e){const{_selectedDragItemLayerUid:t,selectionMode:i,selectedItems:o,messages:s}=this,n=e.title||s.untitledTable,l=this._filterActions(e.actionsSections),a=this._countActions(l);return f("calcite-list-item",{afterCreate:t=>this._focusSelectedDragEl(t,e),afterUpdate:t=>this._focusSelectedDragEl(t,e),class:_.item,"data-item":e,dragDisabled:!e.sortable,dragSelected:e.layer.uid===t,id:e.layer?.uid,key:`list-item-${e.layer.uid}`,label:n,metadata:{title:n},selected:"none"!==i&&o.includes(e),title:n,value:e.layer?.uid,onCalciteListItemDragHandleChange:t=>this._handleCalciteListItemDragHandleChange(t,e)},f("div",{class:_.itemContent,slot:"content"},n),this._renderItemStatus(e),this._renderItemTemporaryIcon(e),this._renderItemMessage(e),this._renderPanel(e.panel),this._renderPanelAction(e.panel),a>1?this._renderActionsSections(e,l):1===a?this._renderAction({item:e,action:this._getSingleActionButton(l),textEnabled:!1}):null)}_renderItemTemporaryIcon(e){return this.visibleElements.temporaryTableIndicators&&!e.layer.persistenceEnabled?f("calcite-icon",{class:_.itemTemporaryIcon,icon:"temporary",key:"temporary-icon",scale:"s",slot:"actions-start",title:this.messages.temporary}):null}_renderItemStatus(e){const{visibleElements:t}=this;if(!t.statusIndicators)return null;const{publishing:i}=e;return f("calcite-icon",{class:this.classes({[_.statusIndicator]:!0,[_.publishing]:i}),icon:"stop-square",key:"layer-item-status",scale:"s",slot:"actions-end"})}_renderPanel(e){return!e?.open||e.disabled||e.flowEnabled?null:f("div",{class:_.itemContentBottom,key:`content-panel-${e.uid}`,slot:"content-bottom"},e.render())}_renderPanelAction(e){if(!e?.visible)return null;const{open:t,title:i,disabled:o}=e;return f("calcite-action",{active:t,appearance:"transparent",disabled:o,icon:l(e),key:`action-${e.uid}`,onclick:()=>this._togglePanel(e),scale:"s",slot:"actions-end",text:i??"",title:i??void 0},this._renderFallbackIcon(e))}_renderActionsSections(e,t){return f("calcite-action-menu",{appearance:"transparent",key:"item-action-menu",label:this.messagesCommon.menu,open:e.actionsOpen,overlayPositioning:"fixed",placement:"bottom-end",scale:"s",slot:"actions-end",onCalciteActionMenuOpen:t=>e.actionsOpen=t.target.open},f("calcite-action",{appearance:"transparent",icon:"ellipsis",scale:"s",slot:"trigger",text:this.messagesCommon.options,title:this.messagesCommon.options}),t.toArray().map(((t,i)=>this._renderActionSection(e,t,i))))}_renderActionSection(e,t,i){return f("calcite-action-group",{key:`action-section-${i}`},t.toArray().map((t=>this._renderAction({item:e,action:t,textEnabled:!0}))))}_renderFallbackIcon(e){const{className:t,icon:i}=e;if(i)return null;const o="image"in e?e.image:void 0,s={[_.itemActionIcon]:!!t,[_.itemActionImage]:!!o};return t&&(s[t]=!0),o||t?f("span",{"aria-hidden":"true",class:this.classes(_.itemActionIcon,s),key:"icon",styles:a(o)}):null}_renderAction(e){const{item:t,action:i,textEnabled:o}=e,{active:s,disabled:n,title:a,type:r,indicator:c}=i;return f("calcite-action",{active:"toggle"===r&&i.value,appearance:"transparent",disabled:n,icon:l(i),indicator:c,key:`action-${i.uid}`,loading:s,onclick:()=>this._triggerAction(t,i),scale:"s",slot:o?void 0:"actions-end",text:a??"",textEnabled:o,title:a??void 0},this._renderFallbackIcon(i))}_filterActions(e){return e.map((e=>e.filter((e=>e.visible))))}_getSingleActionButton(e){return e.reduce((e=>e)).filter((e=>e&&"button"===e.type)).at(0)}_countActions(e){return e.reduce(((e,t)=>e+t.length),0)}_focusSelectedDragEl(e,t){this._selectedDragItemLayerUid===t.layer.uid&&requestAnimationFrame((()=>e?.setFocus()))}_handleCalciteListItemDragHandleChange(e,t){e.stopPropagation();const i=e.target.dragSelected;this._selectedDragItemLayerUid=i?t.layer.uid:null}_handleCalciteListChange(e){const{selectionMode:t,selectedItems:i}=this;if("none"===t)return;const o=e.target.selectedItems.map((e=>w(e))).filter(Boolean);i.removeAll(),i.addMany(o)}_togglePanel(e){e.open=!e.open,e.open&&(this._focusPanelFlowItem=!0)}_triggerAction(e,t){t&&e&&("toggle"===t.type&&(t.value=!t.value),this.triggerAction(t,e))}};e([s()],L.prototype,"_focusRootFlowItem",void 0),e([s()],L.prototype,"_focusPanelFlowItem",void 0),e([s()],L.prototype,"_dragEnabled",null),e([s()],L.prototype,"_filterEnabled",null),e([s()],L.prototype,"collapsed",void 0),e([s()],L.prototype,"dragEnabled",void 0),e([s()],L.prototype,"filterPlaceholder",void 0),e([s()],L.prototype,"filterText",void 0),e([s()],L.prototype,"headingLevel",void 0),e([s()],L.prototype,"icon",void 0),e([s()],L.prototype,"iconClass",void 0),e([s()],L.prototype,"label",null),e([s()],L.prototype,"listItemCanGiveFunction",void 0),e([s()],L.prototype,"listItemCanReceiveFunction",void 0),e([s()],L.prototype,"listItemCreatedFunction",null),e([s()],L.prototype,"map",null),e([s(),g("esri/widgets/TableList/t9n/TableList")],L.prototype,"messages",void 0),e([s(),g("esri/t9n/common")],L.prototype,"messagesCommon",void 0),e([s()],L.prototype,"minDragEnabledItems",void 0),e([s()],L.prototype,"minFilterItems",void 0),e([s()],L.prototype,"multipleSelectionEnabled",null),e([s()],L.prototype,"selectionEnabled",null),e([s()],L.prototype,"selectedItems",void 0),e([s()],L.prototype,"selectionMode",void 0),e([s({readOnly:!0})],L.prototype,"tableItems",null),e([b("trigger-action"),s({type:v})],L.prototype,"viewModel",void 0),e([s({type:y,nonNullable:!0})],L.prototype,"visibleElements",void 0),L=e([n("esri.widgets.TableList")],L);const M=L;export{M as default};
|