@arcgis/core 4.33.0-next.20250205 → 4.33.0-next.20250207
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/arcade.js +1 -1
- package/assets/components/assets/icon/dualImageArea16.json +1 -0
- package/assets/components/assets/icon/dualImageArea24.json +1 -0
- package/assets/components/assets/icon/dualImageArea32.json +1 -0
- package/assets/components/assets/icon/dualImageDistance16.json +1 -0
- package/assets/components/assets/icon/dualImageDistance24.json +1 -0
- package/assets/components/assets/icon/dualImageDistance32.json +1 -0
- package/assets/components/assets/icon/dualImageLocation16.json +1 -0
- package/assets/components/assets/icon/dualImageLocation24.json +1 -0
- package/assets/components/assets/icon/dualImageLocation32.json +1 -0
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{24a86c52c8bdd0b5eb4d.js → 09a99c556089c166d1f8.js} +1 -1
- package/assets/esri/core/workers/chunks/0a8e388e96af44deeabb.js +1 -0
- package/assets/esri/core/workers/chunks/12d6baeffd55a98a7c75.js +1 -0
- package/assets/esri/core/workers/chunks/143a193fa3a6e645c8ac.js +1 -0
- package/assets/esri/core/workers/chunks/{9b4f471fcd8a3b5e089f.js → 192569dfa7c0ea8dd864.js} +1 -1
- package/assets/esri/core/workers/chunks/{ad215219e5eef8598745.js → 28dbbfc44cc2bdcd221d.js} +1 -1
- package/assets/esri/core/workers/chunks/308ec51ff4a66f7fcb0d.js.LICENSE.txt +1 -1
- package/assets/esri/core/workers/chunks/{72cf9192292e5c85c6df.js → 32d3657dcae89b740f8b.js} +2 -2
- package/assets/esri/core/workers/chunks/{72cf9192292e5c85c6df.js.LICENSE.txt → 32d3657dcae89b740f8b.js.LICENSE.txt} +1 -1
- package/assets/esri/core/workers/chunks/333091ab2e267652ed56.js +1 -0
- package/assets/esri/core/workers/chunks/354531dc2f0dea2ad96f.js.LICENSE.txt +1 -1
- package/assets/esri/core/workers/chunks/35e4af82a08b4eadbfab.js +1 -0
- package/assets/esri/core/workers/chunks/369a2b8484a8807bde38.js +1 -0
- package/assets/esri/core/workers/chunks/4040158835f9036967cd.js +2 -0
- package/assets/esri/core/workers/chunks/{1a2e1a414e651e988435.js.LICENSE.txt → 4040158835f9036967cd.js.LICENSE.txt} +1 -6
- package/assets/esri/core/workers/chunks/{8a1e4f65fc81aba7a704.js → 4122d10bc910e888eee1.js} +1 -1
- package/assets/esri/core/workers/chunks/433576983754f690bcc7.js +1 -0
- package/assets/esri/core/workers/chunks/459af0c3d62c3ed11c19.js +1 -0
- package/assets/esri/core/workers/chunks/53810519ff5922b42cd2.js +1 -0
- package/assets/esri/core/workers/chunks/5721557a1d8eab23a55b.js +1 -0
- package/assets/esri/core/workers/chunks/594d923400fd74881833.js +1 -0
- package/assets/esri/core/workers/chunks/{7a0415db78c68d31733f.js → 6039da57a2adedd3b83f.js} +1 -1
- package/assets/esri/core/workers/chunks/62a1d60ad4bf6469c4dd.js +1 -0
- package/assets/esri/core/workers/chunks/{81aa8cc289fd02ca4da6.js → 7058001bf66f9f3d5d45.js} +1 -1
- package/assets/esri/core/workers/chunks/{e8ae8a11d8439e2a66ad.js → 706f867a9034d62a8ef7.js} +1 -1
- package/assets/esri/core/workers/chunks/73d03c208242778e67bf.js +1 -0
- package/assets/esri/core/workers/chunks/77764ca90bdd13ee2167.js.LICENSE.txt +1 -1
- package/assets/esri/core/workers/chunks/{1ab83753d9eec0463461.js → 7b367bb0ed9c218ca595.js} +1 -1
- package/assets/esri/core/workers/chunks/{723a9fba144e2fa6d017.js → 7cb09e58bcc537ec1f7a.js} +1 -1
- package/assets/esri/core/workers/chunks/8191dd3d7451b2e7b95e.js +1 -0
- package/assets/esri/core/workers/chunks/842db06ce62758fab1e7.js +1 -0
- package/assets/esri/core/workers/chunks/8c32cee395da0a7b9a8e.js +1 -0
- package/assets/esri/core/workers/chunks/8d8f5f08d730270e1165.js +1 -0
- package/assets/esri/core/workers/chunks/94225d92afbdb10dfedb.js +1 -0
- package/assets/esri/core/workers/chunks/94490937dca566fe2640.js +1 -0
- package/assets/esri/core/workers/chunks/{b9ce0049e27a3e1ed9f9.js → 9b2fab133786e5d47631.js} +1 -1
- package/assets/esri/core/workers/chunks/9d61590c4d21c7421925.js +1 -0
- package/assets/esri/core/workers/chunks/{610b33b7291cffcc4e5d.js → a42ae5d5e5f66d120b4d.js} +1 -1
- package/assets/esri/core/workers/chunks/a5e9ea13e844a62b2a7f.js +1 -0
- package/assets/esri/core/workers/chunks/b21b152fa15896577242.js.LICENSE.txt +1 -1
- package/assets/esri/core/workers/chunks/b43d88b6e7dc4ab13599.js +1 -0
- package/assets/esri/core/workers/chunks/{6d5bfcc7856cafe7b043.js → b765670b47d209d7655a.js} +2 -2
- package/assets/esri/core/workers/chunks/{6d5bfcc7856cafe7b043.js.LICENSE.txt → b765670b47d209d7655a.js.LICENSE.txt} +1 -1
- package/assets/esri/core/workers/chunks/d29c3bf29fcd7fa31f1a.js +1 -0
- package/assets/esri/core/workers/chunks/d339dee99c4820b63f39.js +1 -0
- package/assets/esri/core/workers/chunks/{9c5c6ecaf5be24279fa5.js → ddc30044f61a2c2df3fe.js} +1 -1
- package/assets/esri/core/workers/chunks/de1f3c4b8000c2d73013.js +1 -0
- package/assets/esri/core/workers/chunks/e4b3f2d5c43518b0cde7.js +1 -0
- package/assets/esri/core/workers/chunks/e5e3b6d00d27b5bb354f.js +1 -0
- package/assets/esri/core/workers/chunks/ef6279f5c63ab1e88c71.js +1 -0
- package/assets/esri/core/workers/chunks/{0711d3ad4d403bcfdcad.js → f117a89d1f4001a1f9f0.js} +1 -1
- package/assets/esri/core/workers/chunks/f14b318bab5efcf43419.js +1 -0
- package/assets/esri/core/workers/chunks/f32ca4381e804cc3481e.js +1 -0
- package/assets/esri/core/workers/chunks/f9070edd8e0b2a57af79.js +1 -0
- package/assets/esri/core/workers/chunks/f9e48205178a5a804d38.js +1 -0
- package/assets/esri/themes/base/widgets/_Directions.scss +15 -6
- package/assets/esri/themes/base/widgets/_ItemList.scss +6 -0
- package/assets/esri/themes/dark/main.css +1 -1
- package/assets/esri/themes/light/main.css +1 -1
- package/assets/esri/themes/light/view.css +1 -1
- package/chunks/WaterSurface.glsl.js +2 -2
- package/geometry/operators/projectOperator.js +1 -1
- package/geometry/operators/shapePreservingProjectOperator.js +1 -1
- package/geometry/support/meshUtils/elevation.js +1 -1
- package/interfaces.d.ts +121 -84
- package/layers/FeatureLayer.js +1 -1
- package/layers/Layer.js +1 -1
- package/layers/SubtypeGroupLayer.js +1 -1
- package/layers/WCSLayer.js +1 -1
- package/layers/graphics/data/FeatureStore.js +1 -1
- package/layers/graphics/data/QueryEngineCapabilities.js +1 -1
- package/layers/graphics/sources/FeatureLayerSource.js +1 -1
- package/layers/graphics/sources/geojson/GeoJSONSourceWorker.js +1 -1
- package/layers/graphics/sources/support/MemorySourceWorker.js +1 -1
- package/layers/graphics/sources/support/clientSideDefaults.js +1 -1
- package/layers/graphics/sources/support/sourceUtils.js +1 -1
- package/layers/mixins/BlendLayer.js +1 -1
- package/layers/mixins/FeatureLayerBase.js +1 -1
- package/layers/mixins/OperationalLayer.js +1 -1
- package/layers/mixins/operationalLayerModuleMap.js +1 -1
- package/layers/ogc/wcsUtils.js +1 -1
- package/layers/support/RasterFunctionTemplate.js +1 -1
- package/layers/support/SubtypeSublayer.js +1 -1
- package/layers/support/arcadeUtils.js +1 -1
- package/layers/support/commonProperties.js +1 -1
- package/layers/support/layersCreator.js +1 -1
- package/layers/support/rasterDatasets/WCSRaster.js +1 -1
- package/layers/support/rasterDatasets/multipartParser.js +1 -1
- package/layers/support/rasterDatasets/wcsCapabilitiesParser.js +1 -1
- package/layers/support/rasterFunctionUtils.d.ts +2 -1
- package/layers/support/rasterFunctionUtils.js +1 -1
- package/layers/support/rasterFunctions/creators/createDataManagementFunctions.js +1 -1
- package/package.json +2 -2
- package/portal/support/layersLoader.js +1 -1
- package/portal/support/loadUtils.js +1 -1
- package/rest/imageService.js +1 -1
- package/rest/support/ImageSampleParameters.js +1 -1
- package/rest/support/ImageSampleResult.js +1 -1
- package/rest/support/ImageVolumeResult.js +1 -1
- package/smartMapping/support/adapters/InMemoryLayerAdapter.js +1 -1
- package/smartMapping/support/adapters/support/histogramUtils.js +1 -1
- package/support/TablesMixin.js +1 -1
- package/support/revision.js +1 -1
- package/symbols/cim/CIMSymbolRasterizer.js +1 -1
- package/symbols/cim/cimAnalyzer.js +1 -1
- package/symbols/cim/fitVectorMarker.js +5 -0
- package/symbols/support/previewCIMSymbol.js +1 -1
- package/views/2d/engine/webgl/TextureManager.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/heatmap/HeatmapResources.js +1 -1
- package/views/2d/layers/FeatureLayerView2D.js +1 -1
- package/views/2d/layers/GraphicsLayerView2D.js +1 -1
- package/views/2d/layers/ImageryLayerView2D.js +1 -1
- package/views/2d/layers/LayerView2D.js +1 -1
- package/views/2d/layers/MapImageLayerView2D.js +1 -1
- package/views/2d/layers/TileLayerView2D.js +1 -1
- package/views/2d/layers/features/schema/SourceSchema.js +1 -1
- package/views/2d/layers/features/sources/FeatureSource.js +1 -1
- package/views/2d/layers/features/sources/FeatureSourceQueryInfo.js +1 -1
- package/views/2d/layers/features/sources/strategies/DrillDownTileLoadStrategy.js +1 -1
- package/views/2d/layers/features/sources/strategies/PagedTileLoadStrategy.js +1 -1
- package/views/2d/layers/features/sources/strategies/ParquetLoadStrategy.js +1 -1
- package/views/2d/layers/features/sources/strategies/SnapshotLoadStrategy.js +1 -1
- package/views/2d/layers/features/sources/strategies/StreamLoadStrategy.js +1 -1
- package/views/2d/layers/graphics/HighlightGraphicContainer.js +1 -1
- package/views/2d/layers/imagery/BaseImageryTileSubView2D.js +1 -1
- package/views/2d/layers/support/util.js +1 -1
- package/views/3d/environment/ChapmanAtmosphere.js +1 -1
- package/views/3d/layers/MediaLayerView3D.js +1 -1
- package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
- package/views/3d/layers/support/FeatureTileFetcher3D.js +1 -1
- package/views/3d/terrain/OverlayManager.js +1 -1
- package/views/3d/terrain/OverlayRenderer.js +1 -1
- package/views/3d/terrain/TerrainSurface.js +1 -1
- package/views/3d/webgl-engine/Stage.js +1 -1
- package/views/3d/webgl-engine/effects/haze/Haze.js +1 -1
- package/views/3d/webgl-engine/parts/RenderView.js +1 -1
- package/views/3d/webgl-engine/parts/ScreenshotManager.js +1 -1
- package/views/LayerViewManager.js +1 -1
- package/views/SceneView.js +1 -1
- package/views/interactive/snapping/featureSources/featureServiceSource/FeatureServiceSnappingSourceWorker.js +1 -1
- package/views/interactive/snapping/featureSources/featureServiceSource/FeatureServiceTileCache.js +1 -1
- package/views/interactive/snapping/featureSources/featureServiceSource/FeatureServiceTileStore.js +1 -1
- package/views/interactive/snapping/featureSources/featureServiceSource/FeatureServiceTiledFetcher.js +1 -1
- package/views/layers/support/MapServiceLayerViewHelper.js +1 -1
- package/widgets/Directions.js +1 -1
- package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
- package/widgets/Editor/EditorViewModel.js +1 -1
- package/widgets/Editor/UpdateWorkflow.js +1 -1
- package/widgets/Editor/VisibleElements.js +1 -1
- package/widgets/Editor/components/FeatureList.js +1 -1
- package/widgets/Editor/components/UpdateFeaturePanelContent.js +1 -1
- package/widgets/Editor/support/EditorItem.js +1 -1
- package/widgets/Editor/workflowUtils.js +1 -1
- package/widgets/Editor.js +1 -1
- package/widgets/Feature/FeatureExpression/FeatureExpressionViewModel.js +1 -1
- package/widgets/Feature/FeatureViewModel.js +1 -1
- package/widgets/Feature/support/arcadeFeatureUtils.js +1 -1
- package/widgets/OrientedImageryViewer/adapters/sketch/MeasurementAdapter.js +1 -1
- package/widgets/OrientedImageryViewer/components/ImageLocationWidget.js +1 -1
- package/widgets/Sketch.js +1 -1
- package/widgets/support/UtilityNetworkAssociations/UtilityNetworkAssociationsViewModel.js +1 -1
- package/assets/esri/core/workers/chunks/07bff9e742f3e5877f3f.js +0 -1
- package/assets/esri/core/workers/chunks/1a2e1a414e651e988435.js +0 -2
- package/assets/esri/core/workers/chunks/287362f9af132fafe4de.js +0 -1
- package/assets/esri/core/workers/chunks/2ea5e5e6c4660a06b516.js +0 -1
- package/assets/esri/core/workers/chunks/380d37ceb8cf52bad190.js +0 -1
- package/assets/esri/core/workers/chunks/3984bf01f055fc42bfbf.js +0 -1
- package/assets/esri/core/workers/chunks/39e38aab86dcee3f79be.js +0 -1
- package/assets/esri/core/workers/chunks/41cd1a5c99ab3bbd1fb4.js +0 -1
- package/assets/esri/core/workers/chunks/5e7f16b312077ca8c18d.js +0 -1
- package/assets/esri/core/workers/chunks/69d307758262e5d7a32e.js +0 -1
- package/assets/esri/core/workers/chunks/6ef2514a6b7bbfb8e37d.js +0 -1
- package/assets/esri/core/workers/chunks/7e4d72279cc599b7029c.js +0 -1
- package/assets/esri/core/workers/chunks/82d26884127ed772cc4b.js +0 -1
- package/assets/esri/core/workers/chunks/8438fba57e82e4cc7c11.js +0 -1
- package/assets/esri/core/workers/chunks/858b191c078d04232342.js +0 -1
- package/assets/esri/core/workers/chunks/918bdba41fa470cf77fd.js +0 -1
- package/assets/esri/core/workers/chunks/91d2bdfa6e34c10b7f50.js +0 -1
- package/assets/esri/core/workers/chunks/92155d112ebb6a4c6c6e.js +0 -1
- package/assets/esri/core/workers/chunks/991e0f619f1f81f94d56.js +0 -1
- package/assets/esri/core/workers/chunks/9a27824d94df702e6e28.js +0 -1
- package/assets/esri/core/workers/chunks/b1269b51cef3e11c85e3.js +0 -1
- package/assets/esri/core/workers/chunks/b33122adfd1fb68f7c0f.js +0 -1
- package/assets/esri/core/workers/chunks/bbbe5d6cb8b737811c84.js +0 -1
- package/assets/esri/core/workers/chunks/bf26f58210755875748c.js +0 -1
- package/assets/esri/core/workers/chunks/c1fd87af3129873369fd.js +0 -1
- package/assets/esri/core/workers/chunks/c4c2b94e5cee7b824093.js +0 -1
- package/assets/esri/core/workers/chunks/c85374360ac5e169af16.js +0 -1
- package/assets/esri/core/workers/chunks/c94ec324ecad77c53a87.js +0 -1
- package/assets/esri/core/workers/chunks/d175953337fa655dc6b0.js +0 -1
- package/assets/esri/core/workers/chunks/d8c762ca94e3a11b125d.js +0 -1
- package/assets/esri/core/workers/chunks/dbc447413ab40a79ba87.js +0 -1
- package/assets/esri/core/workers/chunks/e26dc0c1654316bb1558.js +0 -1
- package/assets/esri/core/workers/chunks/e410a09650530d7aad10.js +0 -1
package/widgets/Directions.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.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import{isSome as t}from"../core/arrayUtils.js";import{isAbortError as i}from"../core/promiseUtils.js";import{watch as s,initial as o,on as r}from"../core/reactiveUtils.js";import{escapeRegExpString as a}from"../core/string.js";import{property as n}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/Logger.js";import{subclass as l}from"../core/accessorSupport/decorators/subclass.js";import c from"../portal/Portal.js";import{defaultUnitPropertyMetadata as d}from"../properties/defaultUnit.js";import m from"../rest/support/Stop.js";import p from"../symbols/SimpleMarkerSymbol.js";import u from"./Search.js";import h from"./Widget.js";import{DirectionsSearchTool as v}from"./Directions/DirectionsSearchTool.js";import g from"./Directions/DirectionsViewModel.js";import _ from"./Directions/DirectionsVisibleElements.js";import{formatDistance as w,formatDuration as y,DepartureTimeOption as b,getIconName as f}from"./Directions/support/directionsUtils.js";import{isArcGISWorldGeocoder as S,meteredArcGISLocatorUrl as M}from"./Search/support/locatorUtils.js";import{loadCalciteComponents as k}from"./support/componentsUtils.js";import{globalCss as I}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as F}from"./support/decorators/messageBundle.js";import{tsx as x}from"./support/jsxFactory.js";function T(e){const{branchName:i,displayText:s,exitName:o,intersectingName:r,name:n,objectId:l,towardName:c}=e;if(null==s)return null;const d=[i,o,r,n,c].filter(t).sort(((e,t)=>t.length-e.length)).map((e=>a(e)));if(!d.length)return s;const m=new RegExp(d.join("|"),"g"),p=s.matchAll(m);let u=0;const h=[];for(const{0:t,index:a}of p)h.push(s.slice(u,a),x("span",{class:$.labelEmphasize,key:`maneuver-${a}`},t)),u=a+t.length;return h.push(s.slice(u)),x("span",{id:`key-${l}`},h)}function C(e){const t=new Date(e);return new Date(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())}const D="esri-directions",$={base:D,accordion:`${D}__accordion`,actionContainer:`${D}__action-container`,departureTimeOptions:`${D}__departure-time-options`,directionsHeader:`${D}__directions-header`,directionsHeaderStopName:`${D}__directions-header-stop-name`,editFooter:`${D}__edit-footer`,editToolbar:`${D}__edit-toolbar`,editToolbarContainer:`${D}__edit-toolbar-container`,flexColumn:`${D}__flex-column`,flexRow:`${D}__flex-row`,headerStops:`${D}__header-stops`,labelEmphasize:`${D}__label-emphasize`,labelNoBottomMargin:`${D}__label-no-bottom-margin`,marginInlineMedium:`${D}__margin-inline-medium`,paddingMedium:`${D}__padding-medium`,primaryFlowItem:`${D}__primary-flow-item`,primaryFooter:`${D}__primary-footer`,primaryFooterCentered:`${D}__primary-footer-centered`,routeItem:`${D}__route-item`,routeItemButton:`${D}__route-item-button`,routeItemButtonContent:`${D}__route-item-button-content`,routeItemLabel:`${D}__route-item-label`,routeItemDescription:`${D}__route-item-description`,saveError:`${D}__save-error`,saveErrorIcon:`${D}__save-error-icon`,saveErrorLabel:`${D}__save-error-label`,saveProcessLoader:`${D}__save-process-loader`,selectedFeatureContainer:`${D}__selected-feature-container`,separator:`${D}__separator`,stopContainer:`${D}__stop-container`,stopItem:`${D}__stop-item`};let L=class extends h{constructor(e,t){super(e,t),this._activeManeuver=null,this._placeholderStops=[new m,new m],this._portalFolderCombobox=null,this._portalFolders=null,this._portalItemNameInput=null,this._portalUserName=null,this._sections=null,this._stopsToSearches=new Map,this._currentFlowItem="primary",this._parentFlowItem="primary",this._saveState="initialized",this.headingLevel=2,this.messages=null,this.messagesUnits=null,this.searchProperties=null,this.viewModel=new g,this.visibleElements=new _}initialize(){this.addHandles([s((()=>this.viewModel.layer),(()=>{try{this.viewModel.load()}catch{}}),o),s((()=>this.viewModel.layer?.routeInfo),(()=>{this._sections=this._getStopSections()}),o)])}loadDependencies(){return k({accordion:()=>import("@esri/calcite-components/dist/components/calcite-accordion"),"accordion-item":()=>import("@esri/calcite-components/dist/components/calcite-accordion-item"),action:()=>import("@esri/calcite-components/dist/components/calcite-action"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),dropdown:()=>import("@esri/calcite-components/dist/components/calcite-dropdown"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice"),panel:()=>import("@esri/calcite-components/dist/components/calcite-panel"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch")})}get apiKey(){return this.viewModel.apiKey}set apiKey(e){this.viewModel.apiKey=e}get goToOverride(){return this.viewModel.goToOverride}set goToOverride(e){this.viewModel.goToOverride=e}get icon(){return"right"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get lastRoute(){return this.viewModel.lastRoute}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get maxStops(){return this.viewModel.maxStops}set maxStops(e){this.viewModel.maxStops=e}get unit(){return this.defaultUnit}set unit(e){this._overrideIfSome("unit",e)}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}acquireSearch(e){const{view:t}=this.viewModel;if(this._stopsToSearches.has(e)){const i=this._stopsToSearches.get(e);return i.view=t,this._overrideDefaultSources(i),i}const i=new u({icon:!1,popupEnabled:!1,resultGraphicEnabled:!1,view:t,...this.searchProperties});return this._normalizeSearchSources(i),this.addHandles([r((()=>i.allSources),"change",(()=>this._normalizeSearchSources(i))),i.on("search-clear",(()=>{e.geometry=null,e.name=null,this.viewModel.layer?.removeResult()})),i.on("select-result",(()=>{const t=i.selectedResult;e.geometry=t?.feature.geometry,e.name=t?.name,this._solveRoute()})),s((()=>i.searchTerm),(t=>{e.name=t}))],i),this._stopsToSearches.set(e,i),i}getDirections(){return this.viewModel.getDirections()}render(){return x("div",{class:this.classes($.base,I.widget,I.panel)},x("calcite-flow",null,this._renderPrimaryFlowItem(),this._renderDirectionsFlowItem(),this._renderEditFlowItem(),this._renderSaveFlowItem()))}save(){return this.viewModel.save()}saveAs(e,t={}){return this.viewModel.saveAs(e,t)}zoomToRoute(){return this.viewModel.zoomToRoute()}_applyLocatorSourceOverrides({allSources:e}){for(const t of e)"url"in t&&t.url&&(t.locationType??="street",S(t.url)&&this.apiKey&&null==t.apiKey&&(t.apiKey=this.apiKey,t.url=M))}_disposeSearch(e){if(!e||!this._stopsToSearches.has(e))return;const t=this._stopsToSearches.get(e);this.removeHandles(t),t.destroy(),this._stopsToSearches.delete(e)}_getErrorDescription(){switch(this.viewModel.lastError?.name){case"directions-view-model:unable-to-route":return this.messages.errors.unableToRoute;case"directions-view-model:service-metadata-unavailable":return this.messages.errors.unableToLoadServiceMetadata;default:return this.messages.errors.unknownError}}_getNetworkFeatureName(e){switch(e.type){case"stop":switch(e.locationType){case"stop":default:return this.messages.networkFeatures.stops.stop;case"waypoint":return this.messages.networkFeatures.stops.waypoint;case"break":return this.messages.networkFeatures.stops.break}case"point-barrier":return this.messages.networkFeatures.pointBarrier;case"polyline-barrier":return this.messages.networkFeatures.polylineBarrier;case"polygon-barrier":return this.messages.networkFeatures.polygonBarrier}}_getRouteCostSummary(){const e=this.viewModel.layer?.routeInfo;if(!e)return null;const t=e.totalDistance??0,i=e.totalDuration??0,{messagesUnits:s,unit:o}=this;return{distance:w(s,t,o),duration:y(i)}}_getStopSections(){if(!this.viewModel.layer)return null;const{directionPoints:e,directionLines:t,stops:i}=this.viewModel.layer;if(!e||!t)return null;const s=[];let o=null;for(const r of e){const{objectId:e,stopId:a}=r;if(null!=a){const e=i.find((({objectId:e})=>e===a));o&&o.stop===e||(o={stop:e,directions:[]},s.push(o));continue}if(null==o)continue;const n=t.find((({directionPointId:t})=>t===e));null!=n&&o.directions.push({directionPoint:r,directionLine:n})}return s}_handleLocateStopAction(e){const{view:t}=this;if(!t)return;const i=new v({stop:e,view:t}),s="directions-search-tool";this.removeHandles(s),this.addHandles(i.on("click",(async i=>{if(i.mapPoint&&this._stopsToSearches.has(e)){const s=this._stopsToSearches.get(e),o=await s.search(i.mapPoint),r=o?.results?.[0].results?.[0];if(r){const{feature:i,name:o}=r;s.searchTerm=o,e.geometry=i.geometry,t.activeTool=null}}this.removeHandles(s)})),s),t.addAndActivateTool(i)}async _handleSaveLayerAsAction(){const e=c.getDefault();try{await e.signIn()}catch(t){if(i(t)||"identity-manager:user-aborted"===t.name)return;return this._parentFlowItem=this._currentFlowItem,this._currentFlowItem="save",void(this._saveState="connect-to-portal-error")}this._saveState="fetch-portal-information",this._parentFlowItem=this._currentFlowItem,this._currentFlowItem="save",this._portalUserName=e.user?.username;try{this._portalFolders=await(e.user?.fetchFolders())}catch{return void(this._saveState="fetch-portal-information-error")}this._saveState="save-layer"}_normalizeSearchSources(e){this._overrideDefaultSources(e),this._applyLocatorSourceOverrides(e)}_overrideDefaultSources(e){for(const t of e.viewModel.defaultSources)t.autoNavigate=!1}_renderClearRouteAction(e){return x("calcite-action",{icon:"trash",key:"clear-route",onclick:()=>{this._currentFlowItem="primary",this.viewModel.reset()},...e,text:this.messages.common.clear,textEnabled:!0})}_renderDeleteStopAction(e){const t=this.viewModel.layer?.stops;return x("calcite-action",{disabled:(t?.length??0)<=2,icon:"trash",onclick:()=>{this.viewModel.layer?.stops.remove(e),this._disposeSearch(e),this._solveRoute()},scale:"s",text:this.messages.deleteStop})}_renderDepartureTime(){const{DEPART_AT:e,NOW:t,UNSPECIFIED:i}=b;return x("calcite-label",{key:"departure-time",scale:"s"},this.messages.departureTime,x("calcite-combobox",{clearDisabled:!0,label:this.messages.departureTime,overlayPositioning:"fixed",scale:"s",selectionMode:"single",onCalciteComboboxChange:({currentTarget:e})=>{const{selectedItems:t}=e;t.length&&(this.viewModel.departureOption=t[0].value,this._solveRoute())}},x("calcite-combobox-item",{heading:this.messages.leaveNow,key:t,label:this.messages.leaveNow,selected:this.viewModel.departureOption===t,value:t}),x("calcite-combobox-item",{heading:this.messages.departAt,key:e,label:this.messages.departAt,selected:this.viewModel.departureOption===e,value:e}),x("calcite-combobox-item",{heading:this.messages.timeUnspecified,key:i,label:this.messages.timeUnspecified,selected:this.viewModel.departureOption===i,value:i})))}_renderDepartureTimeOptions(){return this.viewModel.departureOption!==b.DEPART_AT?null:x("div",{class:$.departureTimeOptions},x("calcite-input-date-picker",{scale:"s",valueAsDate:C(this.viewModel.departureIsoDate),onCalciteInputDatePickerChange:({currentTarget:{value:e}})=>{this.viewModel.departureIsoDate=e,this._solveRoute()}}),x("calcite-input-time-picker",{scale:"s",value:this.viewModel.departureIsoTime,onCalciteInputTimePickerChange:({currentTarget:{value:e}})=>{this.viewModel.departureIsoTime=e,this._solveRoute()}}))}_renderDirectionsFlowItem(){if("directions"!==this._currentFlowItem)return null;const e=this._getRouteCostSummary();if(!this._sections||!e)return null;const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel,o=this._sections.at(0)?.stop.name??"",r=this._sections.at(-1)?.stop.name??"";return x("calcite-flow-item",{key:"directions-flow-item",overlayPositioning:"fixed",selected:"directions"===this._currentFlowItem,onCalciteFlowItemBack:e=>{e.stopPropagation(),this._currentFlowItem="primary"}},x("div",{class:$.directionsHeader,slot:"header-content"},x("div",{class:$.headerStops},x("span",null,this.messages.from)," ",x("span",{class:$.directionsHeaderStopName},o),x("span",null,this.messages.to)," ",x("span",{class:$.directionsHeaderStopName},r)),x("div",{class:$.flexColumn},x("span",null,`${i} (${t})`),s?x("span",null,s):null)),this._renderRouteLayerActions({slot:"header-menu-actions"}),x("calcite-accordion",{class:$.accordion,iconPosition:"start",selectionMode:"single"},this._sections.map(((e,t)=>{const{stop:i,directions:s}=e,{name:o}=i;return x("calcite-accordion-item",{expanded:0===t,heading:o??"",key:`stop-${t}`},x("calcite-action",{icon:"zoom-to-object",onclick:()=>{this.viewModel.centerAt(i)},slot:"actions-end",text:this.messages.panToStop}),this._renderDirectionTurns(s))}))))}_renderDirectionTurns(e){return x("calcite-list",{label:this.messages.drivingDirections,selectionMode:"none"},e.map(((e,t)=>{const{directionPoint:i,directionLine:s}=e,{distance:o,duration:r}=s,a=w(this.messagesUnits,o??0,this.unit),n=y(r??0),l=a&&n?`${a} | ${n}`:`${a||n}`,c=T(i),d=f(i.directionPointType);return x("calcite-list-item",{class:$.labelNoBottomMargin,key:`driving-direction-${t}`,onpointerenter:()=>{this.viewModel.highlight(s)},onpointerleave:()=>{this.viewModel.clearHighlights()},onCalciteListItemSelect:()=>{this._activeManeuver===s?this.zoomToRoute():(this._activeManeuver=s,this.viewModel.centerAt(s.geometry))}},x("calcite-icon",{icon:d,slot:"content-start"}),x("div",{slot:"content"},x("calcite-label",{layout:"inline",scale:"s"},c),x("calcite-label",{layout:"inline",scale:"s"},l)))})))}_renderEditFlowItem(){return"edit"!==this._currentFlowItem?null:x("calcite-flow-item",{heading:this.messages.editRoute,headingLevel:this.headingLevel,key:"edit-flow-item",selected:"edit"===this._currentFlowItem,onCalciteFlowItemBack:e=>{e.stopPropagation(),this.viewModel.stopEditing(),this._currentFlowItem="primary"}},x("div",{class:$.flexColumn,key:"edit-container"},x("div",{class:$.editToolbarContainer},x("div",{class:$.editToolbar},x("calcite-action",{icon:"flag",key:"add-stop",onclick:()=>{this.viewModel.create("stop")},scale:"s",text:this.messages.networkFeatures.stops.stop,textEnabled:!0}),x("calcite-action",{icon:"line",key:"add-barrier",onclick:()=>{this.viewModel.create("polyline-barrier")},scale:"s",text:this.messages.barrier,textEnabled:!0}),x("calcite-action",{disabled:this.viewModel.autoSolve,icon:"refresh",key:"solve",onclick:()=>{this._solveRoute()},scale:"s",text:this.messages.solve}),x("calcite-action",{active:this.viewModel.autoSolve,icon:"app-update",key:"auto-solve",onclick:()=>{this.viewModel.autoSolve=!this.viewModel.autoSolve},scale:"s",text:this.messages.automaticallySolve}))),x("div",{class:$.selectedFeatureContainer},x("calcite-list",{label:this.messages.selectedNetworkFeatures,scale:"s",selectionMode:"none"},this.viewModel.selectedNetworkFeatures?.toArray().map(((e,t)=>x("calcite-list-item",{description:this._getNetworkFeatureName(e),key:`network-feature-${t}`,label:e.name??e.objectId?.toString()??this.messages.unnamed},x("calcite-action",{icon:"trash",onclick:()=>{this.viewModel.delete()},scale:"s",slot:"actions-end",text:this.messages.common.delete})))))),x("div",{class:$.editFooter},x("calcite-button",{onclick:e=>{e.stopPropagation(),this.viewModel.stopEditing(),this._currentFlowItem="primary"},scale:"m",width:"full"},this.messages.common.done))))}_renderFooter(){if(!this.viewModel.layer)return x("div",{class:$.primaryFooter,key:"footer-missing-layer"},x("calcite-notice",{icon:"information",open:!0},x("calcite-label",{class:$.labelNoBottomMargin,slot:"message"},this.messages.missingLayer)));if("unauthenticated"===this.viewModel.state)return x("div",{class:$.primaryFooterCentered,key:"footer-sign-in"},x("calcite-label",null,this.messages.signInRequired),x("calcite-button",{onclick:()=>{this.viewModel.load().catch((()=>{}))}},this.messages.common.auth.signIn));if("error"===this.viewModel.state&&!this.viewModel.serviceDescription)return x("div",{class:$.primaryFooter,key:"footer-service-error"},x("calcite-notice",{icon:"exclamation-mark-circle",kind:"danger",open:!0},x("calcite-label",{class:$.labelNoBottomMargin,slot:"message"},this._getErrorDescription())));if(!this.viewModel.layer?.routeInfo)return x("div",{class:$.primaryFooter,key:"footer-unsolved-route"},x("calcite-notice",{icon:"information",open:!0},x("calcite-label",{class:$.labelNoBottomMargin,slot:"message"},this.messages.directionsPlaceholder)));const e=this._getRouteCostSummary();if(!e||!this.viewModel.layer?.directionPoints)return x("div",{class:$.primaryFooter,key:"footer-invalid-route"},x("calcite-notice",{icon:"exclamation-mark-triangle",kind:"danger",open:!0},x("calcite-label",{class:$.labelNoBottomMargin,slot:"message"},this.messages.invalidRoute)));const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel;return x("div",{class:$.routeItem,key:"footer-directions-summary"},x("button",{"aria-busy":"false","aria-label":this.messages.viewDrivingDirections,"aria-live":"polite",class:$.routeItemButton,onclick:()=>{this._currentFlowItem="directions"},type:"button"},x("div",{class:$.routeItemButtonContent},x("span",{class:$.routeItemLabel},`${i} (${t})`),x("span",{class:$.routeItemDescription},s)),x("calcite-icon",{icon:"chevron-right",scale:"s"})),x("calcite-dropdown",null,x("calcite-action",{icon:"ellipsis",slot:"trigger",text:"Route actions"}),this._renderRouteLayerActions()))}_renderInteractiveRouteActions(){return x("div",{class:$.actionContainer,key:"interactive-route-action-container"},x("calcite-button",{appearance:"outline",iconStart:"plus",kind:"neutral",label:this.messages.addStop,onclick:()=>{const e=new p;this.viewModel.layer?.stops.add(new m({symbol:e}))}},this.messages.addStop),x("calcite-button",{appearance:"outline",iconStart:"pencil",kind:"neutral",label:this.messages.editRoute,onclick:()=>{this._currentFlowItem="edit",this.viewModel.startEditing()}},this.messages.editRoute),x("calcite-button",{appearance:"outline",bind:this,iconStart:"arrow-up-down",kind:"neutral",label:this.messages.reverseStops,onclick:()=>{this.viewModel.layer?.stops.reverse(),this._resetStopSequence(),this._solveRoute()}}))}_renderLocateStopAction(e){if(null!=e.name||null!=e.geometry)return null;const t=this.viewModel.layer?.stops.indexOf(e)??-1;return x("calcite-action",{icon:"select",key:`stop-location-action-${t}`,onclick:()=>this._handleLocateStopAction(e),scale:"s",text:this.messages.pickALocationOnTheMap})}_renderOptimizeStopOrder(){const{routeParameters:e}=this.viewModel,{findBestSequence:t,preserveFirstStop:i,preserveLastStop:s}=e;return x("div",null,x("calcite-label",{layout:"inline-space-between",scale:"s"},this.messages.optimizeOrder,x("calcite-switch",{checked:t,scale:"s",onCalciteSwitchChange:({target:t})=>{e.findBestSequence=t.checked,t.checked||this._resetStopSequence(),this._solveRoute()}})),t?[x("calcite-label",{key:"preserve-first-stop",layout:"inline-space-between",scale:"s"},this.messages.preserveFirstStop,x("calcite-switch",{checked:i,scale:"s",onCalciteSwitchChange:({target:{checked:t}})=>{e.preserveFirstStop=t,this._resetStopSequence(),this._solveRoute()}})),x("calcite-label",{key:"preserve-last-stop",layout:"inline-space-between",scale:"s"},this.messages.preserveLastStop,x("calcite-switch",{checked:s,scale:"s",onCalciteSwitchChange:({target:{checked:t}})=>{e.preserveLastStop=t,this._resetStopSequence(),this._solveRoute()}}))]:null)}_renderPrimaryFlowItem(){return x("calcite-flow-item",{key:"primary-flow-item",loading:"initializing"===this.viewModel.state,selected:"primary"===this._currentFlowItem},x("calcite-panel",{class:$.primaryFlowItem,disabled:!this.viewModel.layer||"unauthenticated"===this.viewModel.state||"error"===this.viewModel.state&&!this.viewModel.serviceDescription},this._renderStops(),this._renderInteractiveRouteActions(),this._renderSeparator(),this._renderRouteSolveOptions()),this._renderFooter())}_renderRouteLayerActions(e){return[this._renderClearRouteAction(e),this._renderSaveLayerAction(e),this._renderSaveLayerAsAction(e),this._renderViewItemDetailsAction(e)]}_renderRouteSolveOptions(){return x("div",{class:$.marginInlineMedium,key:"route-solve-options"},this._renderTravelModes(),this._renderDepartureTime(),this._renderDepartureTimeOptions(),this._renderOptimizeStopOrder())}_renderSaveContent(){switch(this._saveState){case"initialized":return this._renderSaveInitialized();case"connect-to-portal":return this._renderSaveProcessing(this.messages.identity.lblSigning);case"connect-to-portal-error":return this._renderSaveError(this.messages.errors.authenticating);case"fetch-portal-information":return this._renderSaveProcessing(this.messages.processing.fetching);case"fetch-portal-information-error":return this._renderSaveError(this.messages.errors.fetching);case"save-layer":return this._renderSaveLayerSettings();case"saving":return this._renderSaveProcessing(this.messages.processing.saving);case"saving-error":return this._renderSaveError(this.messages.errors.saving)}}_renderSaveError(e){return x("calcite-panel",{class:$.paddingMedium,key:"save-layer-error"},x("div",{class:$.saveError},x("calcite-icon",{class:$.saveErrorIcon,icon:"exclamation-mark-triangle",scale:"l",textLabel:this.messages.common.errorMessage}),x("calcite-label",{class:$.saveErrorLabel},e)),x("calcite-button",{appearance:"outline",onclick:()=>{this._currentFlowItem=this._parentFlowItem},slot:"footer-actions",width:"full"},this.messages.common.close))}_renderSaveInitialized(){return x("calcite-panel",{class:$.paddingMedium,key:"save-layer-initialized"})}_renderSaveFlowItem(){return"save"!==this._currentFlowItem?null:x("calcite-flow-item",{heading:this.messages.saveLayer,headingLevel:this.headingLevel,key:"save-layer-flow-item",selected:"save"===this._currentFlowItem,onCalciteFlowItemBack:e=>{e.stopPropagation(),this._currentFlowItem=this._parentFlowItem}},this._renderSaveContent())}_renderSaveLayerAction(e){if(!this.visibleElements.saveButton)return null;const t=this.viewModel.layer,i=t?.routeInfo,s=t?.portalItem?.itemControl;return x("calcite-action",{disabled:!(!!i&&("admin"===s||"update"===s)),icon:"save",key:"save-route",onclick:()=>{this.viewModel.layer?.save()},...e,text:this.messages.common.save,textEnabled:!0})}_renderSaveLayerAsAction(e){if(!this.visibleElements.saveAsButton)return null;const t=!this.viewModel.layer?.routeInfo;return x("calcite-action",{disabled:t,icon:"save-as",key:"save-as-route",onclick:()=>{this._handleSaveLayerAsAction()},...e,text:this.messages.common.saveAs,textEnabled:!0})}_renderSaveLayerSettings(){if(null==this.layer||null==this._portalFolders||null==this._portalUserName)return this._renderSaveInitialized();const{stops:e}=this.layer,t=`${e.at(0).name} - ${e.at(-1).name}`,i=this._portalFolders.map((e=>x("calcite-combobox-item",{heading:e.title??"",key:`${D}-folder-${e.id}`,value:e.id})));return i.unshift(x("calcite-combobox-item",{heading:`${this._portalUserName} (${this.messages.common.home})`,key:`${D}-folder-home`,selected:!0,value:null})),x("calcite-panel",{key:"save-layer-panel"},x("div",{class:$.paddingMedium},x("calcite-label",null,this.messages.laverName,x("calcite-input",{afterCreate:e=>{this._portalItemNameInput=e},label:this.messages.laverName,value:t})),x("calcite-label",null,this.messages.saveInFolder,x("calcite-combobox",{afterCreate:e=>{this._portalFolderCombobox=e},label:this.messages.saveInFolder,overlayPositioning:"fixed",selectionMode:"single"},i))),x("calcite-button",{onclick:()=>{if(this._saveState="saving",null==this.layer||null==this._portalFolders)return;const e=this._portalItemNameInput?.value,t=this._portalFolderCombobox?.value,i=this._portalFolders.find((({id:e})=>e===t));this.layer.saveAs({title:e},{folder:i}).then((()=>{this._currentFlowItem=this._parentFlowItem})).catch((()=>{this._saveState="saving-error"}))},slot:"footer-actions",width:"full"},this.messages.common.save),x("calcite-button",{appearance:"outline",onclick:()=>{this._currentFlowItem=this._parentFlowItem},slot:"footer-actions",width:"full"},this.messages.common.cancel))}_renderSaveProcessing(e){return x("calcite-panel",{class:$.marginInlineMedium,key:"save-layer-processing"},x("calcite-loader",{class:$.saveProcessLoader,label:e,text:e}))}_renderSeparator(){return x("div",{class:$.separator,key:"separator"})}_renderStop(e){const t=this.acquireSearch(e);null!=e.name&&(t.searchTerm=e.name);const i=this._renderLocateStopAction(e),s=this._renderDeleteStopAction(e),o=this.viewModel.layer?.stops.indexOf(e)??-1;return x("calcite-list-item",{key:`stop-${o}`,value:e},x("div",{class:$.flexRow,slot:"actions-end"},i,s),x("div",{class:$.stopItem,slot:"content"},t.render()))}_renderStops(){const e=this.viewModel.layer?.stops.toArray()??this._placeholderStops;for(const t of this._stopsToSearches.keys())e.includes(t)||this._disposeSearch(t);return x("div",{class:$.stopContainer,key:$.stopContainer},x("calcite-list",{dragEnabled:!0,label:this.messages.widgetLabel,scale:"s",onCalciteListOrderChange:({detail:e})=>{this.viewModel.layer?.stops.reorder(e.dragEl.value,e.newIndex),this._resetStopSequence(),this._solveRoute()}},e.map((e=>this._renderStop(e)))))}_renderTravelModes(){return this.viewModel.travelModes.length?x("calcite-label",{key:"travel-modes",scale:"s"},this.messages.mode,x("calcite-combobox",{clearDisabled:!0,label:"mode",overlayPositioning:"fixed",scale:"s",selectionMode:"single",onCalciteComboboxChange:({currentTarget:e})=>{const{selectedItems:t}=e;t.length&&(this.viewModel.selectedTravelMode=t[0].value,this._solveRoute())}},this.viewModel.travelModes.map((e=>x("calcite-combobox-item",{heading:e.name,key:e.id,label:e.name,selected:this.viewModel.selectedTravelMode?.id===e.id,value:e}))))):null}_renderViewItemDetailsAction(e){if(!this.visibleElements.layerDetails)return null;const t=this.viewModel.layer?.portalItem;return x("calcite-action",{disabled:!t,icon:"launch",key:"open-route-details-link",onclick:()=>{t&&window.open(`${t.portal.url}/home/item.html?id=${t.id}`,"_blank")},...e,text:this.messages.viewLayerDetails,textEnabled:!0})}_resetStopSequence(){this.viewModel.layer?.stops.forEach((e=>{e.sequence=null}))}async _solveRoute(){this.viewModel.updateDepartureTime();const e=this.viewModel.layer?.stops.filter((({geometry:e})=>null!=e));if(e&&!(e.length<2))try{await this.viewModel.getDirections()}catch{}}};e([n()],L.prototype,"_currentFlowItem",void 0),e([n()],L.prototype,"_saveState",void 0),e([n()],L.prototype,"apiKey",null),e([n(d)],L.prototype,"defaultUnit",void 0),e([n()],L.prototype,"goToOverride",null),e([n()],L.prototype,"headingLevel",void 0),e([n()],L.prototype,"icon",null),e([n()],L.prototype,"label",null),e([n({readOnly:!0})],L.prototype,"lastRoute",null),e([n()],L.prototype,"layer",null),e([n()],L.prototype,"maxStops",null),e([n(),F("esri/widgets/Directions/t9n/Directions")],L.prototype,"messages",void 0),e([n(),F("esri/core/t9n/Units")],L.prototype,"messagesUnits",void 0),e([n()],L.prototype,"searchProperties",void 0),e([n()],L.prototype,"unit",null),e([n()],L.prototype,"view",null),e([n({type:g})],L.prototype,"viewModel",void 0),e([n({type:_,nonNullable:!0})],L.prototype,"visibleElements",void 0),L=e([l("esri.widgets.Directions")],L);const A=L;export{A as default};
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import{isSome as t}from"../core/arrayUtils.js";import i from"../core/Collection.js";import{isAbortError as s}from"../core/promiseUtils.js";import{watch as o,initial as r,on as a}from"../core/reactiveUtils.js";import{escapeRegExpString as n}from"../core/string.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/Logger.js";import{subclass as c}from"../core/accessorSupport/decorators/subclass.js";import d from"../portal/Portal.js";import{defaultUnitPropertyMetadata as m}from"../properties/defaultUnit.js";import p from"../rest/support/Stop.js";import u from"../symbols/SimpleMarkerSymbol.js";import h from"./Search.js";import v from"./Widget.js";import{DirectionsSearchTool as g}from"./Directions/DirectionsSearchTool.js";import _ from"./Directions/DirectionsViewModel.js";import w from"./Directions/DirectionsVisibleElements.js";import{formatDistance as y,formatDuration as b,DepartureTimeOption as f,getIconName as S}from"./Directions/support/directionsUtils.js";import{isArcGISWorldGeocoder as M,meteredArcGISLocatorUrl as k}from"./Search/support/locatorUtils.js";import{loadCalciteComponents as I}from"./support/componentsUtils.js";import{globalCss as F}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as x}from"./support/decorators/messageBundle.js";import{tsx as T}from"./support/jsxFactory.js";function C(e){const{branchName:i,displayText:s,exitName:o,intersectingName:r,name:a,objectId:l,towardName:c}=e;if(null==s)return null;const d=[i,o,r,a,c].filter(t).sort(((e,t)=>t.length-e.length)).map((e=>n(e)));if(!d.length)return s;const m=new RegExp(d.join("|"),"g"),p=s.matchAll(m);let u=0;const h=[];for(const{0:t,index:n}of p)h.push(s.slice(u,n),T("span",{class:L.labelEmphasize,key:`maneuver-${n}`},t)),u=n+t.length;return h.push(s.slice(u)),T("span",{id:`key-${l}`},h)}function D(e){const t=new Date(e);return new Date(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())}const $="esri-directions",L={base:$,accordion:`${$}__accordion`,actionContainer:`${$}__action-container`,addStopButton:`${$}__add-stop-button`,departureTimeOptions:`${$}__departure-time-options`,directionsHeader:`${$}__directions-header`,directionsHeaderStopName:`${$}__directions-header-stop-name`,editFooter:`${$}__edit-footer`,editToolbar:`${$}__edit-toolbar`,editToolbarContainer:`${$}__edit-toolbar-container`,flexColumn:`${$}__flex-column`,flexRow:`${$}__flex-row`,headerStops:`${$}__header-stops`,labelEmphasize:`${$}__label-emphasize`,labelNoBottomMargin:`${$}__label-no-bottom-margin`,marginInlineMedium:`${$}__margin-inline-medium`,paddingMedium:`${$}__padding-medium`,primaryFlowItem:`${$}__primary-flow-item`,primaryFooter:`${$}__primary-footer`,primaryFooterCentered:`${$}__primary-footer-centered`,routeItem:`${$}__route-item`,routeItemButton:`${$}__route-item-button`,routeItemButtonContent:`${$}__route-item-button-content`,routeItemLabel:`${$}__route-item-label`,routeItemDescription:`${$}__route-item-description`,saveError:`${$}__save-error`,saveErrorIcon:`${$}__save-error-icon`,saveErrorLabel:`${$}__save-error-label`,saveProcessLoader:`${$}__save-process-loader`,selectedFeatureContainer:`${$}__selected-feature-container`,separator:`${$}__separator`,stopContainer:`${$}__stop-container`,stopList:`${$}__stop-list`,stopItem:`${$}__stop-item`};let A=class extends v{constructor(e,t){super(e,t),this._activeManeuver=null,this._placeholderStops=new i([new p,new p]),this._portalFolderCombobox=null,this._portalFolders=null,this._portalItemNameInput=null,this._portalUserName=null,this._sections=null,this._stopsToSearches=new Map,this._currentFlowItem="primary",this._parentFlowItem="primary",this._saveState="initialized",this.headingLevel=2,this.messages=null,this.messagesUnits=null,this.searchProperties=null,this.viewModel=new _,this.visibleElements=new w}initialize(){this.addHandles([o((()=>this.viewModel.layer),(()=>{try{this.viewModel.load()}catch{}}),r),o((()=>this.viewModel.layer?.routeInfo),(()=>{this._sections=this._getStopSections()}),r)])}loadDependencies(){return I({accordion:()=>import("@esri/calcite-components/dist/components/calcite-accordion"),"accordion-item":()=>import("@esri/calcite-components/dist/components/calcite-accordion-item"),action:()=>import("@esri/calcite-components/dist/components/calcite-action"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),dropdown:()=>import("@esri/calcite-components/dist/components/calcite-dropdown"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice"),panel:()=>import("@esri/calcite-components/dist/components/calcite-panel"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch")})}get apiKey(){return this.viewModel.apiKey}set apiKey(e){this.viewModel.apiKey=e}get goToOverride(){return this.viewModel.goToOverride}set goToOverride(e){this.viewModel.goToOverride=e}get icon(){return"right"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get lastRoute(){return this.viewModel.lastRoute}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get maxStops(){return this.viewModel.maxStops}set maxStops(e){this.viewModel.maxStops=e}get unit(){return this.defaultUnit}set unit(e){this._overrideIfSome("unit",e)}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}acquireSearch(e){const{view:t}=this.viewModel;if(this._stopsToSearches.has(e)){const i=this._stopsToSearches.get(e);return i.view=t,this._overrideDefaultSources(i),i}const i=new h({icon:!1,popupEnabled:!1,resultGraphicEnabled:!1,view:t,...this.searchProperties});return this._normalizeSearchSources(i),this.addHandles([a((()=>i.allSources),"change",(()=>this._normalizeSearchSources(i))),i.on("search-clear",(()=>{e.geometry=null,e.name=null,this.viewModel.layer?.removeResult()})),i.on("select-result",(()=>{const t=i.selectedResult;e.geometry=t?.feature.geometry,e.name=t?.name,this._solveRoute()})),o((()=>i.searchTerm),(t=>{e.name=t}))],i),this._stopsToSearches.set(e,i),i}getDirections(){return this.viewModel.getDirections()}render(){return T("div",{class:this.classes(L.base,F.widget,F.panel)},T("calcite-flow",null,this._renderPrimaryFlowItem(),this._renderDirectionsFlowItem(),this._renderEditFlowItem(),this._renderSaveFlowItem()))}save(){return this.viewModel.save()}saveAs(e,t={}){return this.viewModel.saveAs(e,t)}zoomToRoute(){return this.viewModel.zoomToRoute()}_applyLocatorSourceOverrides({allSources:e}){for(const t of e)"url"in t&&t.url&&(t.locationType??="street",M(t.url)&&this.apiKey&&null==t.apiKey&&(t.apiKey=this.apiKey,t.url=k))}_disposeSearch(e){if(!e||!this._stopsToSearches.has(e))return;const t=this._stopsToSearches.get(e);this.removeHandles(t),t.destroy(),this._stopsToSearches.delete(e)}_getErrorDescription(){switch(this.viewModel.lastError?.name){case"directions-view-model:unable-to-route":return this.messages.errors.unableToRoute;case"directions-view-model:service-metadata-unavailable":return this.messages.errors.unableToLoadServiceMetadata;default:return this.messages.errors.unknownError}}_getNetworkFeatureName(e){switch(e.type){case"stop":switch(e.locationType){case"stop":default:return this.messages.networkFeatures.stops.stop;case"waypoint":return this.messages.networkFeatures.stops.waypoint;case"break":return this.messages.networkFeatures.stops.break}case"point-barrier":return this.messages.networkFeatures.pointBarrier;case"polyline-barrier":return this.messages.networkFeatures.polylineBarrier;case"polygon-barrier":return this.messages.networkFeatures.polygonBarrier}}_getRouteCostSummary(){const e=this.viewModel.layer?.routeInfo;if(!e)return null;const t=e.totalDistance??0,i=e.totalDuration??0,{messagesUnits:s,unit:o}=this;return{distance:y(s,t,o),duration:b(i)}}_getStopSections(){if(!this.viewModel.layer)return null;const{directionPoints:e,directionLines:t,stops:i}=this.viewModel.layer;if(!e||!t)return null;const s=[];let o=null;for(const r of e){const{objectId:e,stopId:a}=r;if(null!=a){const e=i.find((({objectId:e})=>e===a));o&&o.stop===e||(o={stop:e,directions:[]},s.push(o));continue}if(null==o)continue;const n=t.find((({directionPointId:t})=>t===e));null!=n&&o.directions.push({directionPoint:r,directionLine:n})}return s}_handleLocateStopAction(e){const{view:t}=this;if(!t)return;const i=new g({stop:e,view:t}),s="directions-search-tool";this.removeHandles(s),this.addHandles(i.on("click",(async i=>{if(i.mapPoint&&this._stopsToSearches.has(e)){const s=this._stopsToSearches.get(e),o=await s.search(i.mapPoint),r=o?.results?.[0].results?.[0];if(r){const{feature:i,name:o}=r;s.searchTerm=o,e.geometry=i.geometry,t.activeTool=null}}this.removeHandles(s)})),s),t.addAndActivateTool(i)}async _handleSaveLayerAsAction(){const e=d.getDefault();try{await e.signIn()}catch(t){if(s(t)||"identity-manager:user-aborted"===t.name)return;return this._parentFlowItem=this._currentFlowItem,this._currentFlowItem="save",void(this._saveState="connect-to-portal-error")}this._saveState="fetch-portal-information",this._parentFlowItem=this._currentFlowItem,this._currentFlowItem="save",this._portalUserName=e.user?.username;try{this._portalFolders=await(e.user?.fetchFolders())}catch{return void(this._saveState="fetch-portal-information-error")}this._saveState="save-layer"}_normalizeSearchSources(e){this._overrideDefaultSources(e),this._applyLocatorSourceOverrides(e)}_overrideDefaultSources(e){for(const t of e.viewModel.defaultSources)t.autoNavigate=!1}_renderClearRouteAction(e){return T("calcite-action",{icon:"trash",key:"clear-route",onclick:()=>{this._currentFlowItem="primary",this.viewModel.reset()},...e,text:this.messages.common.clear,textEnabled:!0})}_renderDeleteStopAction(e){const t=this.viewModel.layer?.stops;return T("calcite-action",{disabled:(t?.length??0)<=2,icon:"trash",onclick:()=>{this.viewModel.layer?.stops.remove(e),this._disposeSearch(e),this._solveRoute()},scale:"s",slot:"actions-end",text:this.messages.deleteStop})}_renderDepartureTime(){const{DEPART_AT:e,NOW:t,UNSPECIFIED:i}=f;return T("calcite-label",{key:"departure-time",scale:"s"},this.messages.departureTime,T("calcite-combobox",{clearDisabled:!0,label:this.messages.departureTime,overlayPositioning:"fixed",scale:"s",selectionMode:"single",onCalciteComboboxChange:({currentTarget:e})=>{const{selectedItems:t}=e;t.length&&(this.viewModel.departureOption=t[0].value,this._solveRoute())}},T("calcite-combobox-item",{heading:this.messages.leaveNow,key:t,label:this.messages.leaveNow,selected:this.viewModel.departureOption===t,value:t}),T("calcite-combobox-item",{heading:this.messages.departAt,key:e,label:this.messages.departAt,selected:this.viewModel.departureOption===e,value:e}),T("calcite-combobox-item",{heading:this.messages.timeUnspecified,key:i,label:this.messages.timeUnspecified,selected:this.viewModel.departureOption===i,value:i})))}_renderDepartureTimeOptions(){return this.viewModel.departureOption!==f.DEPART_AT?null:T("div",{class:L.departureTimeOptions},T("calcite-input-date-picker",{scale:"s",valueAsDate:D(this.viewModel.departureIsoDate),onCalciteInputDatePickerChange:({currentTarget:{value:e}})=>{this.viewModel.departureIsoDate=e,this._solveRoute()}}),T("calcite-input-time-picker",{scale:"s",value:this.viewModel.departureIsoTime,onCalciteInputTimePickerChange:({currentTarget:{value:e}})=>{this.viewModel.departureIsoTime=e,this._solveRoute()}}))}_renderDirectionsFlowItem(){if("directions"!==this._currentFlowItem)return null;const e=this._getRouteCostSummary();if(!this._sections||!e)return null;const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel,o=this._sections.at(0)?.stop.name??"",r=this._sections.at(-1)?.stop.name??"";return T("calcite-flow-item",{key:"directions-flow-item",overlayPositioning:"fixed",selected:"directions"===this._currentFlowItem,onCalciteFlowItemBack:e=>{e.stopPropagation(),this._currentFlowItem="primary"}},T("div",{class:L.directionsHeader,slot:"header-content"},T("div",{class:L.headerStops},T("span",null,this.messages.from)," ",T("span",{class:L.directionsHeaderStopName},o),T("span",null,this.messages.to)," ",T("span",{class:L.directionsHeaderStopName},r)),T("div",{class:L.flexColumn},T("span",null,`${i} (${t})`),s?T("span",null,s):null)),this._renderRouteLayerActions({slot:"header-menu-actions"}),T("calcite-accordion",{class:L.accordion,iconPosition:"start",selectionMode:"single"},this._sections.map(((e,t)=>{const{stop:i,directions:s}=e,{name:o}=i;return T("calcite-accordion-item",{expanded:0===t,heading:o??"",key:`stop-${t}`},T("calcite-action",{icon:"zoom-to-object",onclick:()=>{this.viewModel.centerAt(i)},slot:"actions-end",text:this.messages.panToStop}),this._renderDirectionTurns(s))}))))}_renderDirectionTurns(e){return T("calcite-list",{label:this.messages.drivingDirections,selectionMode:"none"},e.map(((e,t)=>{const{directionPoint:i,directionLine:s}=e,{distance:o,duration:r}=s,a=y(this.messagesUnits,o??0,this.unit),n=b(r??0),l=a&&n?`${a} | ${n}`:`${a||n}`,c=C(i),d=S(i.directionPointType);return T("calcite-list-item",{class:L.labelNoBottomMargin,key:`driving-direction-${t}`,onpointerenter:()=>{this.viewModel.highlight(s)},onpointerleave:()=>{this.viewModel.clearHighlights()},onCalciteListItemSelect:()=>{this._activeManeuver===s?this.zoomToRoute():(this._activeManeuver=s,this.viewModel.centerAt(s.geometry))}},T("calcite-icon",{icon:d,slot:"content-start"}),T("div",{slot:"content"},T("calcite-label",{layout:"inline",scale:"s"},c),T("calcite-label",{layout:"inline",scale:"s"},l)))})))}_renderEditFlowItem(){return"edit"!==this._currentFlowItem?null:T("calcite-flow-item",{heading:this.messages.editRoute,headingLevel:this.headingLevel,key:"edit-flow-item",selected:"edit"===this._currentFlowItem,onCalciteFlowItemBack:e=>{e.stopPropagation(),this.viewModel.stopEditing(),this._currentFlowItem="primary"}},T("div",{class:L.flexColumn,key:"edit-container"},T("div",{class:L.editToolbarContainer},T("div",{class:L.editToolbar},T("calcite-action",{icon:"flag",key:"add-stop",onclick:()=>{this.viewModel.create("stop")},scale:"s",text:this.messages.networkFeatures.stops.stop,textEnabled:!0}),T("calcite-action",{icon:"line",key:"add-barrier",onclick:()=>{this.viewModel.create("polyline-barrier")},scale:"s",text:this.messages.barrier,textEnabled:!0}),T("calcite-action",{disabled:this.viewModel.autoSolve,icon:"refresh",key:"solve",onclick:()=>{this._solveRoute()},scale:"s",text:this.messages.solve}),T("calcite-action",{active:this.viewModel.autoSolve,icon:"app-update",key:"auto-solve",onclick:()=>{this.viewModel.autoSolve=!this.viewModel.autoSolve},scale:"s",text:this.messages.automaticallySolve}))),T("div",{class:L.selectedFeatureContainer},T("calcite-list",{label:this.messages.selectedNetworkFeatures,scale:"s",selectionMode:"none"},this.viewModel.selectedNetworkFeatures?.toArray().map(((e,t)=>T("calcite-list-item",{description:this._getNetworkFeatureName(e),key:`network-feature-${t}`,label:e.name??e.objectId?.toString()??this.messages.unnamed},T("calcite-action",{icon:"trash",onclick:()=>{this.viewModel.delete()},scale:"s",slot:"actions-end",text:this.messages.common.delete})))))),T("div",{class:L.editFooter},T("calcite-button",{onclick:e=>{e.stopPropagation(),this.viewModel.stopEditing(),this._currentFlowItem="primary"},scale:"m",width:"full"},this.messages.common.done))))}_renderFooter(){if(!this.viewModel.layer)return T("div",{class:L.primaryFooter,key:"footer-missing-layer"},T("calcite-notice",{icon:"information",open:!0},T("calcite-label",{class:L.labelNoBottomMargin,slot:"message"},this.messages.missingLayer)));if("unauthenticated"===this.viewModel.state)return T("div",{class:L.primaryFooterCentered,key:"footer-sign-in"},T("calcite-label",null,this.messages.signInRequired),T("calcite-button",{onclick:()=>{this.viewModel.load().catch((()=>{}))}},this.messages.common.auth.signIn));if("error"===this.viewModel.state&&!this.viewModel.serviceDescription)return T("div",{class:L.primaryFooter,key:"footer-service-error"},T("calcite-notice",{icon:"exclamation-mark-circle",kind:"danger",open:!0},T("calcite-label",{class:L.labelNoBottomMargin,slot:"message"},this._getErrorDescription())));if(!this.viewModel.layer?.routeInfo)return T("div",{class:L.primaryFooter,key:"footer-unsolved-route"},T("calcite-notice",{icon:"information",open:!0},T("calcite-label",{class:L.labelNoBottomMargin,slot:"message"},this.messages.directionsPlaceholder)));const e=this._getRouteCostSummary();if(!e||!this.viewModel.layer?.directionPoints)return T("div",{class:L.primaryFooter,key:"footer-invalid-route"},T("calcite-notice",{icon:"exclamation-mark-triangle",kind:"danger",open:!0},T("calcite-label",{class:L.labelNoBottomMargin,slot:"message"},this.messages.invalidRoute)));const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel;return T("div",{class:L.routeItem,key:"footer-directions-summary"},T("button",{"aria-busy":"false","aria-label":this.messages.viewDrivingDirections,"aria-live":"polite",class:L.routeItemButton,onclick:()=>{this._currentFlowItem="directions"},type:"button"},T("div",{class:L.routeItemButtonContent},T("span",{class:L.routeItemLabel},`${i} (${t})`),T("span",{class:L.routeItemDescription},s)),T("calcite-icon",{icon:"chevron-right",scale:"s"})),T("calcite-dropdown",null,T("calcite-action",{icon:"ellipsis",slot:"trigger",text:"Route actions"}),this._renderRouteLayerActions()))}_renderInteractiveRouteActions(){return T("div",{class:L.actionContainer,key:"interactive-route-action-container"},T("calcite-button",{appearance:"outline",class:L.addStopButton,iconStart:"plus",kind:"neutral",label:this.messages.addStop,onclick:()=>{const e=new u;this.viewModel.layer?.stops.add(new p({symbol:e}))},width:"half"},this.messages.addStop),T("calcite-button",{appearance:"outline",iconStart:"pencil",kind:"neutral",label:this.messages.editRoute,onclick:()=>{this._currentFlowItem="edit",this.viewModel.startEditing()},width:"half"},this.messages.editRoute))}_renderLocateStopAction(e){if(null!=e.name||null!=e.geometry)return null;const t=this.viewModel.layer?.stops.indexOf(e)??-1;return T("calcite-action",{icon:"select",key:`stop-location-action-${t}`,onclick:()=>this._handleLocateStopAction(e),scale:"s",slot:"actions-end",text:this.messages.pickALocationOnTheMap})}_renderOptimizeStopOrder(){const{routeParameters:e}=this.viewModel,{findBestSequence:t,preserveFirstStop:i,preserveLastStop:s}=e;return T("div",null,T("calcite-label",{layout:"inline-space-between",scale:"s"},this.messages.optimizeOrder,T("calcite-switch",{checked:t,scale:"s",onCalciteSwitchChange:({target:t})=>{e.findBestSequence=t.checked,t.checked||this._resetStopSequence(),this._solveRoute()}})),t?[T("calcite-label",{key:"preserve-first-stop",layout:"inline-space-between",scale:"s"},this.messages.preserveFirstStop,T("calcite-switch",{checked:i,scale:"s",onCalciteSwitchChange:({target:{checked:t}})=>{e.preserveFirstStop=t,this._resetStopSequence(),this._solveRoute()}})),T("calcite-label",{key:"preserve-last-stop",layout:"inline-space-between",scale:"s"},this.messages.preserveLastStop,T("calcite-switch",{checked:s,scale:"s",onCalciteSwitchChange:({target:{checked:t}})=>{e.preserveLastStop=t,this._resetStopSequence(),this._solveRoute()}}))]:null)}_renderPrimaryFlowItem(){return T("calcite-flow-item",{key:"primary-flow-item",loading:"initializing"===this.viewModel.state,selected:"primary"===this._currentFlowItem},T("calcite-panel",{class:L.primaryFlowItem,disabled:!this.viewModel.layer||"unauthenticated"===this.viewModel.state||"error"===this.viewModel.state&&!this.viewModel.serviceDescription},this._renderStops(),this._renderInteractiveRouteActions(),this._renderSeparator(),this._renderRouteSolveOptions()),this._renderFooter())}_renderRouteLayerActions(e){return[this._renderClearRouteAction(e),this._renderSaveLayerAction(e),this._renderSaveLayerAsAction(e),this._renderViewItemDetailsAction(e)]}_renderRouteSolveOptions(){return T("div",{class:L.marginInlineMedium,key:"route-solve-options"},this._renderTravelModes(),this._renderDepartureTime(),this._renderDepartureTimeOptions(),this._renderOptimizeStopOrder())}_renderSaveContent(){switch(this._saveState){case"initialized":return this._renderSaveInitialized();case"connect-to-portal":return this._renderSaveProcessing(this.messages.identity.lblSigning);case"connect-to-portal-error":return this._renderSaveError(this.messages.errors.authenticating);case"fetch-portal-information":return this._renderSaveProcessing(this.messages.processing.fetching);case"fetch-portal-information-error":return this._renderSaveError(this.messages.errors.fetching);case"save-layer":return this._renderSaveLayerSettings();case"saving":return this._renderSaveProcessing(this.messages.processing.saving);case"saving-error":return this._renderSaveError(this.messages.errors.saving)}}_renderSaveError(e){return T("calcite-panel",{class:L.paddingMedium,key:"save-layer-error"},T("div",{class:L.saveError},T("calcite-icon",{class:L.saveErrorIcon,icon:"exclamation-mark-triangle",scale:"l",textLabel:this.messages.common.errorMessage}),T("calcite-label",{class:L.saveErrorLabel},e)),T("calcite-button",{appearance:"outline",onclick:()=>{this._currentFlowItem=this._parentFlowItem},slot:"footer-actions",width:"full"},this.messages.common.close))}_renderSaveInitialized(){return T("calcite-panel",{class:L.paddingMedium,key:"save-layer-initialized"})}_renderSaveFlowItem(){return"save"!==this._currentFlowItem?null:T("calcite-flow-item",{heading:this.messages.saveLayer,headingLevel:this.headingLevel,key:"save-layer-flow-item",selected:"save"===this._currentFlowItem,onCalciteFlowItemBack:e=>{e.stopPropagation(),this._currentFlowItem=this._parentFlowItem}},this._renderSaveContent())}_renderSaveLayerAction(e){if(!this.visibleElements.saveButton)return null;const t=this.viewModel.layer,i=t?.routeInfo,s=t?.portalItem?.itemControl;return T("calcite-action",{disabled:!(!!i&&("admin"===s||"update"===s)),icon:"save",key:"save-route",onclick:()=>{this.viewModel.layer?.save()},...e,text:this.messages.common.save,textEnabled:!0})}_renderSaveLayerAsAction(e){if(!this.visibleElements.saveAsButton)return null;const t=!this.viewModel.layer?.routeInfo;return T("calcite-action",{disabled:t,icon:"save-as",key:"save-as-route",onclick:()=>{this._handleSaveLayerAsAction()},...e,text:this.messages.common.saveAs,textEnabled:!0})}_renderSaveLayerSettings(){if(null==this.layer||null==this._portalFolders||null==this._portalUserName)return this._renderSaveInitialized();const{stops:e}=this.layer,t=`${e.at(0).name} - ${e.at(-1).name}`,i=this._portalFolders.map((e=>T("calcite-combobox-item",{heading:e.title??"",key:`${$}-folder-${e.id}`,value:e.id})));return i.unshift(T("calcite-combobox-item",{heading:`${this._portalUserName} (${this.messages.common.home})`,key:`${$}-folder-home`,selected:!0,value:null})),T("calcite-panel",{key:"save-layer-panel"},T("div",{class:L.paddingMedium},T("calcite-label",null,this.messages.laverName,T("calcite-input",{afterCreate:e=>{this._portalItemNameInput=e},label:this.messages.laverName,value:t})),T("calcite-label",null,this.messages.saveInFolder,T("calcite-combobox",{afterCreate:e=>{this._portalFolderCombobox=e},label:this.messages.saveInFolder,overlayPositioning:"fixed",selectionMode:"single"},i))),T("calcite-button",{onclick:()=>{if(this._saveState="saving",null==this.layer||null==this._portalFolders)return;const e=this._portalItemNameInput?.value,t=this._portalFolderCombobox?.value,i=this._portalFolders.find((({id:e})=>e===t));this.layer.saveAs({title:e},{folder:i}).then((()=>{this._currentFlowItem=this._parentFlowItem})).catch((()=>{this._saveState="saving-error"}))},slot:"footer-actions",width:"full"},this.messages.common.save),T("calcite-button",{appearance:"outline",onclick:()=>{this._currentFlowItem=this._parentFlowItem},slot:"footer-actions",width:"full"},this.messages.common.cancel))}_renderSaveProcessing(e){return T("calcite-panel",{class:L.marginInlineMedium,key:"save-layer-processing"},T("calcite-loader",{class:L.saveProcessLoader,label:e,text:e}))}_renderSeparator(){return T("div",{class:L.separator,key:"separator"})}_renderStop(e){const t=this.acquireSearch(e);null!=e.name&&(t.searchTerm=e.name);const i=this.viewModel.layer?.stops??this._placeholderStops,s=this._renderLocateStopAction(e),o=i.length>2&&this._renderDeleteStopAction(e);return T("calcite-list-item",{key:e,value:e},s,o,T("div",{class:L.stopItem,slot:"content"},t.render()))}_renderStops(){const e=this.viewModel.layer?.stops??this._placeholderStops;for(const t of this._stopsToSearches.keys())e.includes(t)||this._disposeSearch(t);return T("div",{class:L.stopContainer,key:L.stopContainer},T("calcite-list",{class:L.stopList,dragEnabled:!0,label:this.messages.widgetLabel,scale:"s",onCalciteListOrderChange:({detail:t})=>{e.reorder(t.dragEl.value,t.newIndex),this._resetStopSequence(),this._solveRoute()}},e.toArray().map((e=>this._renderStop(e)))),e.length>1&&T("calcite-action",{icon:"arrow-up-down",onclick:()=>{e.reverse(),this._resetStopSequence(),this._solveRoute()},scale:"s",text:this.messages.reverseStops}))}_renderTravelModes(){return this.viewModel.travelModes.length?T("calcite-label",{key:"travel-modes",scale:"s"},this.messages.mode,T("calcite-combobox",{clearDisabled:!0,label:"mode",overlayPositioning:"fixed",scale:"s",selectionMode:"single",onCalciteComboboxChange:({currentTarget:e})=>{const{selectedItems:t}=e;t.length&&(this.viewModel.selectedTravelMode=t[0].value,this._solveRoute())}},this.viewModel.travelModes.map((e=>T("calcite-combobox-item",{heading:e.name,key:e.id,label:e.name,selected:this.viewModel.selectedTravelMode?.id===e.id,value:e}))))):null}_renderViewItemDetailsAction(e){if(!this.visibleElements.layerDetails)return null;const t=this.viewModel.layer?.portalItem;return T("calcite-action",{disabled:!t,icon:"launch",key:"open-route-details-link",onclick:()=>{t&&window.open(`${t.portal.url}/home/item.html?id=${t.id}`,"_blank")},...e,text:this.messages.viewLayerDetails,textEnabled:!0})}_resetStopSequence(){this.viewModel.layer?.stops.forEach((e=>{e.sequence=null}))}async _solveRoute(){this.viewModel.updateDepartureTime();const e=this.viewModel.layer?.stops.filter((({geometry:e})=>null!=e));if(e&&!(e.length<2))try{await this.viewModel.getDirections()}catch{}}};e([l()],A.prototype,"_currentFlowItem",void 0),e([l()],A.prototype,"_saveState",void 0),e([l()],A.prototype,"apiKey",null),e([l(m)],A.prototype,"defaultUnit",void 0),e([l()],A.prototype,"goToOverride",null),e([l()],A.prototype,"headingLevel",void 0),e([l()],A.prototype,"icon",null),e([l()],A.prototype,"label",null),e([l({readOnly:!0})],A.prototype,"lastRoute",null),e([l()],A.prototype,"layer",null),e([l()],A.prototype,"maxStops",null),e([l(),x("esri/widgets/Directions/t9n/Directions")],A.prototype,"messages",void 0),e([l(),x("esri/core/t9n/Units")],A.prototype,"messagesUnits",void 0),e([l()],A.prototype,"searchProperties",void 0),e([l()],A.prototype,"unit",null),e([l()],A.prototype,"view",null),e([l({type:_})],A.prototype,"viewModel",void 0),e([l({type:w,nonNullable:!0})],A.prototype,"visibleElements",void 0),A=e([c("esri.widgets.Directions")],A);const E=A;export{E 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.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import a from"../../core/Error.js";import{makeHandle as i,handlesGroup as r,abortHandle as s}from"../../core/handleUtils.js";import"../../core/has.js";import{removeMaybe as o,destroyMaybe as n}from"../../core/maybe.js";import{debounce as l}from"../../core/promiseUtils.js";import{watch as d,when as c,initial as u,whenOnce as h,syncAndInitial as p}from"../../core/reactiveUtils.js";import{generateBracedUUID as m}from"../../core/uuid.js";import{property as f}from"../../core/accessorSupport/decorators/property.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as w}from"../../core/accessorSupport/decorators/subclass.js";import{isSharedTemplateOrMetadata as g}from"../../editing/templateUtils.js";import y from"../../layers/GraphicsLayer.js";import{isTable as v}from"../../layers/support/layerUtils.js";import{getDrawHelpMessage as F}from"../../views/draw/support/helpMessageUtils.js";import _ from"../../views/draw/support/HighlightHelper.js";import M from"../../views/interactive/sketch/SketchOptions.js";import b from"../../views/interactive/snapping/FeatureSnappingLayerSource.js";import{temporaryHighlightName as V}from"../../views/support/HighlightDefaults.js";import k from"./CreateFeaturesWorkflowData.js";import{isModelUpload as I,handleModelUpload as S}from"./modelUploadUtils.js";import C from"./Workflow.js";import{startCreatingNewFeature as H,findLayerInfo as A,updateGraphicSymbolWhenRequired as P,isTerminalUpdateEventType as j,getVisualVariableAttributes as E,startUpdatingFeatureGeometry as U,createWorkflowSteps as T,avoidFeatureTemplateSelectionWithOnlyOneItem as O,prepareAttachmentsForCreateFeaturesWorkflow as D,showProgressCursor as L,visualVariableInteractiveUpdate as x}from"./workflowUtils.js";import W from"../FeatureForm/FeatureFormViewModel.js";import G from"../Sketch/SketchViewModel.js";var N;const z=Symbol(),R=Symbol(),Z=Symbol(),q=Symbol(),K={point:["point"],multipoint:["multipoint"],polygon:["polygon","freehandPolygon","rectangle","circle"],polyline:["polyline","freehandPolyline"],mesh:[],multipatch:[]};let B=N=class extends C{constructor(e){super(e),this.type="create-features",this.createFeatureState="create-new",this.data=void 0,this.isNested=!1,this._getDrawMeshHelpMessage=void 0,this._webStyleCache=new Map,this._featureFormHandle=null,this._visualVariableAttributes={rotation:null,size:null},this._featureFormViewModel=new W,this._sketchViewModel=null,this._attachmentFileInfos=new Map,this._isActive=!0,this._updateGraphicDebounced=l(((e,t,a)=>P(e,t,a)))}initialize(){this.isNested&&(this._isActive=!1),this._initializeSketchViewModel()}destroy(){this._sketchViewModel.destroy()}get featureFormViewModel(){return this._featureFormViewModel}get hasPendingEdits(){if(this.pendingFeatures.some((e=>!!this.data.getEditsForPendingFeature(e)?.modified)))return!0;const{creationInfo:e,upload:t}=this.data,a=this._sketchViewModel,{activeComponent:i}=a,r=a.createGraphic?.geometry?.type;return!("polyline"!==r&&"polygon"!==r&&"multipoint"!==r||"draw-2d"!==i?.type&&"draw-3d"!==i?.type)&&i.drawOperation.committedVertices.length>0||(!(!t||"pending"!==t.state&&"success"!==t.state)||!!e?.geometryToPlace)}get helpMessage(){const{creationInfo:e,viewModel:t}=this.data;if("creating-features"!==this.stepId||!e)return;const a=e.layer.geometryType,i=this._sketchViewModel.createGraphic;if("mesh"===a){this._getDrawMeshHelpMessage||import("../../views/draw/support/helpMessageUtils3d.js").then((e=>{this._getDrawMeshHelpMessage=e.getDrawMeshHelpMessage}));const{view:e}=t;return"3d"===e?.type?this._getDrawMeshHelpMessage?.(i,e):void 0}const r=this._sketchViewModel.activeCreateToolDrawMode,s=this._sketchViewModel.activeTool;return F("rectangle"===s?"rectangle":"circle"===s?"circle":a,i?.geometry,r)}get layer(){return this.data.creationInfo?.layer}get numPendingFeatures(){return this.pendingFeatures.length}get parent(){return this.data.parent}get parentLayer(){return this.parent?.data.editorItem.layer}get pendingFeatures(){return this.data.pendingFeatures}get keyboardCancellationEnabled(){return 0===this.numPendingFeatures}get reliesOnOwnerAdminPrivileges(){return this.data.editorItem?.capabilities.create.reliesOnOwnerAdminPrivileges??!1}get shouldShowAttachments(){return(this.data.selectedPendingFeature&&this.data.editorItem?.capabilities.create.attachments.enabled)??!1}get shouldAllowAttachmentEditing(){return this.shouldShowAttachments}get sketchViewModel(){return this._sketchViewModel}get test(){}get availableCreateTools(){const e=this.data.creationInfo?.layer.geometryType,t=this.data.viewModel.view;return e?this.data.creationInfo?.maxFeatures&&this.data.creationInfo.maxFeatures<=this.numPendingFeatures||"2d"!==t?.type&&"multipoint"===e?[]:[...K[e]]:[]}async enter(){this._isActive=!0,"awaiting-feature-creation-info"!==this.stepId&&this._setUpCreatingFeaturesStep()}exit(){this._isActive=!1,this.removeHandles([Z])}async updatePendingFeature(e){if(e!==this.data.selectedPendingFeature)return this._sketchViewModel.cancel(),this._startUpdating({feature:e})}async start(){return await super.start(),v(this.data.creationInfo?.layer)?null:{enter:async()=>{},exit:async()=>{},viewModel:this._sketchViewModel}}async save(){const{featureFormViewModel:e}=this;if(e.pendingSubtypeChoice)return;e.submit(),this._stashValidationState();const t=this.data.selectedPendingFeature,a=this._hasValidationErrors(t)?t:this.data.pendingFeatures.find((e=>this._hasValidationErrors(e)));return a?(await this._startUpdating({feature:a}),void e?.submit()):super.save()}cancelFeature(e){this.data.removePendingFeature(e),this.sketchViewModel.layer.graphics.remove(e)}static create(e){const{addAttachmentsCallback:t,applyEditsCallback:a,isNested:i,creationInfo:r,parent:s,snappingManager:o,startAt:n,viewModel:l}=e,d=e.sketchOptions??new M,c=r?.layer,u=c?l.findEditorItemForLayer(c):void 0,h=new N({data:new k({creationInfo:r,editorItem:u,parent:s,sketchOptions:d,snappingManager:o,viewModel:l}),isNested:i,onCommit:async e=>{const{creationInfo:i}=e;if(!i)return;h._sketchViewModel.cancel();const r=e.pendingFeatures.toArray(),{layer:s}=i,o=s.capabilities?.editing.supportsGlobalId&&"globalIdField"in s,n=h._attachmentFileInfos;if(o){const e=Y(r,s,n);return void await a(s,e,{globalIdUsed:!0})}const l=await a(s,{addFeatures:r});if(n.size>0){const e=l?.addFeatureResults??[];await t(s,X(r,e,s,n))}}});return h._set("steps",this._createWorkflowSteps(h,n)),h}_fadeExistingFeatures(e){if("effect"in e){const t=e.effect;return e.effect="saturate(0.6) opacity(0.8)",i((()=>e.effect=t))}const t=e.opacity;return e.opacity=.7,i((()=>e.opacity=t))}async _startCreating(){this.removeHandles(R);const{creationInfo:e}=this.data;if(!e)return;const t=this.data.creationInfo?.maxFeatures;if(t&&this.numPendingFeatures>=t)return this.sketchViewModel.cancel(),void(this.numPendingFeatures&&await this._startUpdating({feature:this.pendingFeatures.at(-1)}));this.createFeatureState="create-new";const a=await H(this._sketchViewModel,this._webStyleCache,e);this.addHandles(a,R)}async _clearSelectedFeature(){const e=this._featureFormViewModel.pendingSubtypeChoice;e&&(e.resolve("undo"),await e.promise),this._stashValidationState(),this.data.selectedPendingFeature=null,this._featureFormViewModel.feature=null;const t=this.data.viewModel.attachmentsViewModel;"add"!==t.mode&&"edit"!==t.mode||this.data.viewModel.activeWorkflow?.previous()}_stashValidationState(){const e=this._featureFormViewModel.feature,t=e&&this.data.getEditsForPendingFeature(e);t&&(t.submittable=this._featureFormViewModel.submittable)}async _selectFeatureForUpdate({feature:e,initialFeature:t=e}){this._stashValidationState();const{data:a,pendingFeatures:i,_webStyleCache:s}=this;i.includes(e)||a.addPendingFeature(e,t),a.selectedPendingFeature=e;const{_featureFormViewModel:n,_sketchViewModel:l}=this,{creationInfo:c,viewModel:u}=a,{attachmentsViewModel:h,layerInfos:p,view:m}=u;if(!m||!c)return;const f=c.layer,w=A(p,f),g=w?.formTemplate,y=m.spatialReference;n.set({arcadeEditType:"INSERT",feature:e,formTemplate:g,spatialReference:y,map:m.map}),"add"!==h.mode&&"edit"!==h.mode||u.activeWorkflow?.previous(),h.graphic=e,h.fileInfos.removeAll(),h.mode="view";if((this._attachmentFileInfos.get(e)||[]).forEach((({file:e,form:t})=>h.addFile(e,t))),await P(e,s,"2d"===m.type?m.scale:null),this.removeHandles(R),o(this._featureFormHandle),"2d"===m.type){const t=d((()=>m.scale),(t=>this._updateGraphicDebounced(e,s,t)));this.addHandles(t,R)}const v=a.getEditsForPendingFeature(e);this._featureFormHandle=r([n.on("value-change",(async()=>{v?.updateAttributes(n.getValues()),await P(e,s,"2d"===m.type?m.scale:null)})),l.on(["update","undo","redo"],(e=>{("undo"===e.type||"redo"===e.type||"update"===e.type&&null!=e.toolEventInfo&&j(e.toolEventInfo.type))&&n.notifyFeatureGeometryChanged()})),d((()=>n.feature?.sourceLayer),(t=>e.sourceLayer=t))]),this.createFeatureState="update-pending",this._visualVariableAttributes=E(e)}async _startUpdating({feature:e,initialFeature:t=e}){await this._selectFeatureForUpdate({feature:e,initialFeature:t});const{_sketchViewModel:a,data:i}=this,{creationInfo:r,viewModel:s}=i,{view:o}=s;if(!o||!r)return;const n=r.layer;return v(n)?void 0:U({graphic:e,sketchViewModel:a,sourceLayer:n,visualVariables:this._visualVariableAttributes,webStyleCache:this._webStyleCache})}static _createWorkflowSteps(e,t="awaiting-feature-creation-info"){const{data:a}=e,i=T(["awaiting-feature-creation-info","creating-features","adding-attachment","editing-attachment"],t,{"awaiting-feature-creation-info":()=>({id:"awaiting-feature-creation-info",async setUp(){const{creationInfo:t,viewModel:i}=a,{view:r}=i;r&&(I(t)?e.addHandles(await S({view:r,data:a,next:()=>e.next(),cancel:()=>i.cancelWorkflow({warnIfNoWorkflow:!1})}),this.id):(a.parent&&t&&(e.addHandles(i.lockFeatureTemplatesViewModel(),this.id),i.featureTemplatesViewModel.layers=[t.layer]),e.addHandles(i.featureTemplatesViewModel.on("select",(({item:t})=>{t&&(a.creationInfo={...a.creationInfo,layer:t.layer,template:t.template},e.next())})),this.id)))},async tearDown(){e.removeHandles([this.id,R])}}),"creating-features":()=>({id:"creating-features",async setUp(){e._isActive&&await e._setUpCreatingFeaturesStep()},async tearDown(t){const{viewModel:i}=a;t.canceled&&(e.removeHandles([Z,z,R,q]),i.attachmentsViewModel.fileInfos.removeAll(),e._attachmentFileInfos.clear())}}),"adding-attachment":()=>({id:"adding-attachment",parent:"creating-features",async setUp(){},async tearDown(){const{attachmentsViewModel:t}=a.viewModel,{graphic:i,fileInfos:r}=t;e._attachmentFileInfos.set(i,r.toArray()),t.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"creating-features",async setUp(){},async tearDown(){const{attachmentsViewModel:t}=a.viewModel,{graphic:i,fileInfos:r}=t;e._attachmentFileInfos.set(i,r.toArray()),t.mode="view"}})});return O(a,i)}static _configureSketchViewModel(e){const{data:t}=e,{creationInfo:a,viewModel:s}=t,{view:o}=s,n=e._sketchViewModel,l=[];if(!o)return i();"2d"===o.type&&a&&l.push(e._fadeExistingFeatures(a.layer));const u=async t=>{if("cancel"===t.state&&null!==o.activeTool&&o.activeTool!==e.sketchViewModel.activeComponent&&(await e._waitForActiveToolCleared(),await e._startCreating()),"complete"===t.state&&t.graphic){const a=t.graphic,i=t.graphic.clone();return i.geometry=null,await e._waitForActiveToolCleared(),void await e._selectFeatureForUpdate({feature:a,initialFeature:i})}},h=async i=>{const{attachmentsViewModel:r}=s,{_featureFormViewModel:n}=e;if(i.graphics.length>1)return void await e._clearSelectedFeature();const l=i.graphics[0];if("complete"===i.state){const{submittable:t}=n;if(e.numPendingFeatures!==a?.maxFeatures&&t||n.submit(),await e._clearSelectedFeature(),"add"!==r.mode&&"edit"!==r.mode||s.activeWorkflow?.previous(),!i.aborted&&o.activeTool===e.sketchViewModel.activeComponent&&(await e.sketchViewModel.wait(),"ready"===e.sketchViewModel.state&&"mesh"!==e.data.creationInfo?.layer.geometryType))return e._startCreating()}else{if("start"===i.state)return l.sourceLayer=t.creationInfo?.layer,e._selectFeatureForUpdate({feature:l});if("active"===i.state){await e.updatePendingFeature(l);const t=e._visualVariableAttributes;await x(o,l,i,t,e._webStyleCache);const a=l.attributes,{rotation:r,size:s}=t;if(null!=r){const{field:e}=r;n.setValue(e,a[e])}if(null!=s){const{field:e}=s;n.setValue(e,a[e])}}}},p=async a=>{if(a.graphics.forEach((e=>{t.removePendingFeature(e)})),!I(t.creationInfo))return e._startCreating()},m=async()=>(I(t.creationInfo)&&await e.data.viewModel.back(),e._startCreating());l.push(n.on("create",(t=>e._updatingHandles.addPromise(u(t)))),n.on("update",(t=>e._updatingHandles.addPromise(h(t)))),n.on("delete",(t=>e._updatingHandles.addPromise(p(t)))),c((()=>!e.numPendingFeatures),(()=>e._updatingHandles.addPromise(m()))),J(n,t),...Q(t)),l.push(d((()=>[e._featureFormViewModel.feature,e._featureFormViewModel.submittable]),(()=>{e._stashValidationState()})));const f=r(l);return n.addHandles(f),f}_initializeSketchViewModel(){const{data:e}=this,{view:t}=e.viewModel,a=new y({elevationInfo:e.creationInfo?.layer.elevationInfo,internal:!0,listMode:"hide"}),r=new G({layer:a,creationMode:"update",sketchOptions:e.sketchOptions,snappingManager:e.snappingManager,updateOnGraphicClick:!1,defaultUpdateOptions:{multipleSelectionEnabled:!1},view:t});this._sketchViewModel=r,t?.map.add(a),this.addHandles([i((()=>{t?.destroyed||t?.map.remove(a),a.destroy()})),d((()=>this.numPendingFeatures>0),(e=>this._sketchViewModel.updateOnGraphicClick=e),u)])}_hasValidationErrors(e){return!!e&&(!this.data.isSubmittable(e)||!!this._featureFormViewModel.validateContingencyConstraints(e.attributes,{includeIncompleteViolations:!0})?.length)}async _setUpCreatingFeaturesStep(){if(this.hasHandles(Z))return;const{data:e,sketchViewModel:s}=this,{creationInfo:n,viewModel:l}=e,{attachmentsViewModel:c,view:h}=l;if(!h||!n?.layer)throw new a("missing-parameters","CreateFeaturesWorkflow requires a view and creationInfo.");const{initialFeature:p,layer:m}=n,f=[];this._featureFormHandle=o(this._featureFormHandle),this._visualVariableAttributes={rotation:null,size:null},this.data.editorItem=l.findEditorItemForLayer(n.layer),D(c),f.push(d((()=>c.mode),(e=>{switch(e){case"add":this.go("adding-attachment");break;case"edit":this.go("editing-attachment")}})));const w=L(h);f.push(w);const y=v(n.layer);try{if(y){const{template:e}=n;if(e&&g(e))throw new a("Shared templates are not yet supported");const i=p??new t({attributes:{...e?.prototype.attributes,...n.attributeOverrides},sourceLayer:m});await this._startUpdating({feature:i})}else f.push(N._configureSketchViewModel(this)),p?(s.layer.add(p),await this._startUpdating({feature:p})):await this._startCreating()}finally{w.remove()}const F=i((()=>{for(const t of e.pendingFeatures)s.layer.remove(t),e.removePendingFeature(t)})),_=d((()=>h?.timeZone),(e=>this._featureFormViewModel.timeZone=e),u),M=i((()=>{I(n)&&l.cancelWorkflow({warnIfNoWorkflow:!1})}));this._featureFormHandle&&f.push(this._featureFormHandle),this.addHandles(f,this._handleKeys.beforeCommit),this.addHandles([i((()=>c.fileInfos.removeAll())),r(f),M,F,_],Z)}async _waitForActiveToolCleared(){const e=this.data.viewModel.view;if(null==e?.activeTool)return;const t=new AbortController;this.addHandles(s(t),q),await h((()=>null==e?.activeTool),t.signal),t.abort()}};function J(e,t){let a=null;const s=()=>e.snappingOptions.featureSources,o=()=>(a=new b({layer:e.layer}),s().add(a),a),l=()=>{null!=a&&(s().remove(a),a=n(a))};return r([d((()=>{const e=t.creationInfo?.layer,a=s().find((t=>t.layer===e));return{hasFeatureLayerSource:!!a,enabled:a?.enabled??!1}}),(({hasFeatureLayerSource:e,enabled:t})=>{if(!e)return l();a??=o(),a.enabled=t}),p),i(l)])}function Q(e){const t=e.viewModel.view;if(!t)return[];const a=[];if("3d"===t.type){const r=new _({view:t});a.push(d((()=>e.selectedPendingFeature),((e,t)=>{r.remove(e),r.add(t)})),i((()=>r.destroy())))}const r=new _({view:t,highlightName:V});return a.push(d((()=>e.temporaryHighlightFeature),(e=>{r.removeAll(),r.add(e)})),i((()=>r.destroy()))),a}function X(e,t,a,i){const r=[];return t.forEach(((t,s)=>{if(!t.error){const o=e[s],n=i.get(o)||[];o.attributes[a.objectIdField]=t.objectId,n.forEach((({form:e})=>r.push({feature:o,attachment:e})))}})),r}function Y(e,t,a){const i=[],r=t.globalIdField;return e.forEach(((t,s)=>{e[s].attributes[r]??=m(),(a?.get(t)||[]).forEach((({file:e})=>i.push({feature:t,attachment:{globalId:m(),data:e}})))})),i.length?{addFeatures:e,addAttachments:i}:{addFeatures:e}}e([f()],B.prototype,"createFeatureState",void 0),e([f()],B.prototype,"data",void 0),e([f({constructOnly:!0})],B.prototype,"isNested",void 0),e([f()],B.prototype,"featureFormViewModel",null),e([f()],B.prototype,"hasPendingEdits",null),e([f()],B.prototype,"_getDrawMeshHelpMessage",void 0),e([f()],B.prototype,"helpMessage",null),e([f()],B.prototype,"layer",null),e([f()],B.prototype,"parent",null),e([f()],B.prototype,"parentLayer",null),e([f()],B.prototype,"keyboardCancellationEnabled",null),e([f()],B.prototype,"reliesOnOwnerAdminPrivileges",null),e([f()],B.prototype,"shouldShowAttachments",null),e([f()],B.prototype,"shouldAllowAttachmentEditing",null),e([f()],B.prototype,"sketchViewModel",null),e([f()],B.prototype,"availableCreateTools",null),B=N=e([w("esri.widgets.Editor.CreateFeaturesWorkflow")],B);const $=B;export{$ as default};
|
|
5
|
+
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import a from"../../core/Error.js";import{makeHandle as i,handlesGroup as r,abortHandle as s}from"../../core/handleUtils.js";import"../../core/has.js";import{removeMaybe as o,destroyMaybe as n}from"../../core/maybe.js";import{debounce as l}from"../../core/promiseUtils.js";import{watch as d,when as c,initial as u,whenOnce as h,syncAndInitial as p}from"../../core/reactiveUtils.js";import{generateBracedUUID as m}from"../../core/uuid.js";import{property as f}from"../../core/accessorSupport/decorators/property.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as w}from"../../core/accessorSupport/decorators/subclass.js";import{isSharedTemplateOrMetadata as g}from"../../editing/templateUtils.js";import y from"../../layers/GraphicsLayer.js";import{isTable as v}from"../../layers/support/layerUtils.js";import{getDrawHelpMessage as F}from"../../views/draw/support/helpMessageUtils.js";import _ from"../../views/draw/support/HighlightHelper.js";import M from"../../views/interactive/sketch/SketchOptions.js";import b from"../../views/interactive/snapping/FeatureSnappingLayerSource.js";import{temporaryHighlightName as V}from"../../views/support/HighlightDefaults.js";import k from"./CreateFeaturesWorkflowData.js";import{isModelUpload as I,handleModelUpload as S}from"./modelUploadUtils.js";import C from"./Workflow.js";import{startCreatingNewFeature as P,findLayerInfo as H,updateGraphicSymbolWhenRequired as A,isTerminalUpdateEventType as j,getVisualVariableAttributes as E,startUpdatingFeatureGeometry as U,createWorkflowSteps as T,avoidFeatureTemplateSelectionWithOnlyOneItem as O,prepareAttachmentsForCreateFeaturesWorkflow as D,showProgressCursor as L,visualVariableInteractiveUpdate as x}from"./workflowUtils.js";import W from"../FeatureForm/FeatureFormViewModel.js";import G from"../Sketch/SketchViewModel.js";var N;const z=Symbol(),R=Symbol(),Z=Symbol(),q=Symbol(),K={point:["point"],multipoint:["multipoint"],polygon:["polygon","freehandPolygon","rectangle","circle"],polyline:["polyline","freehandPolyline"],mesh:[],multipatch:[]};let B=N=class extends C{constructor(e){super(e),this.type="create-features",this.createFeatureState="create-new",this.data=void 0,this.isNested=!1,this._getDrawMeshHelpMessage=void 0,this._webStyleCache=new Map,this._featureFormHandle=null,this._visualVariableAttributes={rotation:null,size:null},this._featureFormViewModel=new W,this._sketchViewModel=null,this._attachmentFileInfos=new Map,this._isActive=!0,this._updateGraphicDebounced=l(((e,t,a)=>A(e,t,a)))}initialize(){this.isNested&&(this._isActive=!1),this._initializeSketchViewModel()}destroy(){this._sketchViewModel.destroy()}get featureFormViewModel(){return this._featureFormViewModel}get hasPendingEdits(){if(this.pendingFeatures.some((e=>!!this.data.getEditsForPendingFeature(e)?.modified)))return!0;const{creationInfo:e,upload:t}=this.data,a=this._sketchViewModel,{activeComponent:i}=a,r=a.createGraphic?.geometry?.type;return!("polyline"!==r&&"polygon"!==r&&"multipoint"!==r||"draw-2d"!==i?.type&&"draw-3d"!==i?.type)&&i.drawOperation.committedVertices.length>0||(!(!t||"pending"!==t.state&&"success"!==t.state)||!!e?.geometryToPlace)}get hasPreviousStep(){return"update-pending"===this.createFeatureState&&!!this.data.selectedPendingFeature}get helpMessage(){const{creationInfo:e,viewModel:t}=this.data;if("creating-features"!==this.stepId||!e)return;const a=e.layer.geometryType,i=this._sketchViewModel.createGraphic;if("mesh"===a){this._getDrawMeshHelpMessage||import("../../views/draw/support/helpMessageUtils3d.js").then((e=>{this._getDrawMeshHelpMessage=e.getDrawMeshHelpMessage}));const{view:e}=t;return"3d"===e?.type?this._getDrawMeshHelpMessage?.(i,e):void 0}const r=this._sketchViewModel.activeCreateToolDrawMode,s=this._sketchViewModel.activeTool;return F("rectangle"===s?"rectangle":"circle"===s?"circle":a,i?.geometry,r)}get layer(){return this.data.creationInfo?.layer}get numPendingFeatures(){return this.pendingFeatures.length}get parent(){return this.data.parent}get parentLayer(){return this.parent?.data.editorItem.layer}get pendingFeatures(){return this.data.pendingFeatures}get keyboardCancellationEnabled(){return 0===this.numPendingFeatures}get reliesOnOwnerAdminPrivileges(){return this.data.editorItem?.capabilities.create.reliesOnOwnerAdminPrivileges??!1}get shouldShowAttachments(){return(this.data.selectedPendingFeature&&this.data.editorItem?.capabilities.create.attachments.enabled)??!1}get shouldAllowAttachmentEditing(){return this.shouldShowAttachments}get sketchViewModel(){return this._sketchViewModel}get test(){}get availableCreateTools(){const e=this.data.creationInfo?.layer.geometryType,t=this.data.viewModel.view;return e?this.data.creationInfo?.maxFeatures&&this.data.creationInfo.maxFeatures<=this.numPendingFeatures||"2d"!==t?.type&&"multipoint"===e?[]:[...K[e]]:[]}async enter(){this._isActive=!0,"awaiting-feature-creation-info"!==this.stepId&&this._setUpCreatingFeaturesStep()}exit(){this._isActive=!1,this.removeHandles([Z])}async updatePendingFeature(e){if(e!==this.data.selectedPendingFeature)return this._sketchViewModel.cancel(),this._startUpdating({feature:e})}async start(){return await super.start(),v(this.data.creationInfo?.layer)?null:{enter:async()=>{},exit:async()=>{},viewModel:this._sketchViewModel}}async save(){const{featureFormViewModel:e}=this;if(e.pendingSubtypeChoice)return;e.submit(),this._stashValidationState();const t=this.data.selectedPendingFeature,a=this._hasValidationErrors(t)?t:this.data.pendingFeatures.find((e=>this._hasValidationErrors(e)));return a?(await this._startUpdating({feature:a}),void e?.submit()):super.save()}back(e){return"update-pending"===this.createFeatureState&&this.data.selectedPendingFeature&&!I(this.data.creationInfo)?this._clearSelectedFeature():super.back(e)}previous(e){return"update-pending"===this.createFeatureState&&this.data.selectedPendingFeature&&!I(this.data.creationInfo)?this._clearSelectedFeature():super.previous(e)}cancelFeature(e){this.data.removePendingFeature(e),this.sketchViewModel.layer.graphics.remove(e)}static create(e){const{addAttachmentsCallback:t,applyEditsCallback:a,isNested:i,creationInfo:r,parent:s,snappingManager:o,startAt:n,viewModel:l}=e,d=e.sketchOptions??new M,c=r?.layer,u=c?l.findEditorItemForLayer(c):void 0,h=new N({data:new k({creationInfo:r,editorItem:u,parent:s,sketchOptions:d,snappingManager:o,viewModel:l}),isNested:i,onCommit:async e=>{const{creationInfo:i}=e;if(!i)return;h._sketchViewModel.cancel();const r=e.pendingFeatures.toArray(),{layer:s}=i,o=s.capabilities?.editing.supportsGlobalId&&"globalIdField"in s,n=h._attachmentFileInfos;if(o){const e=Y(r,s,n);return void await a(s,e,{globalIdUsed:!0})}const l=await a(s,{addFeatures:r});if(n.size>0){const e=l?.addFeatureResults??[];await t(s,X(r,e,s,n))}}});return h._set("steps",this._createWorkflowSteps(h,n)),h}_fadeExistingFeatures(e){if("effect"in e){const t=e.effect;return e.effect="saturate(0.6) opacity(0.8)",i((()=>e.effect=t))}const t=e.opacity;return e.opacity=.7,i((()=>e.opacity=t))}async _startCreating(){this.removeHandles(R);const{creationInfo:e}=this.data;if(!e)return;const t=this.data.creationInfo?.maxFeatures;if(t&&this.numPendingFeatures>=t)return this.sketchViewModel.cancel(),void(this.numPendingFeatures&&await this._startUpdating({feature:this.pendingFeatures.at(-1)}));this.createFeatureState="create-new";const a=await P(this._sketchViewModel,this._webStyleCache,e);this.addHandles(a,R)}async _clearSelectedFeature(){const e=this._featureFormViewModel.pendingSubtypeChoice;e&&(e.resolve("undo"),await e.promise),this._stashValidationState(),this.sketchViewModel.cancel(),this.data.selectedPendingFeature=null,this._featureFormViewModel.feature=null;const t=this.data.viewModel.attachmentsViewModel;"add"!==t.mode&&"edit"!==t.mode||this.data.viewModel.activeWorkflow?.previous()}_stashValidationState(){const e=this._featureFormViewModel.feature,t=e&&this.data.getEditsForPendingFeature(e);t&&(t.submittable=this._featureFormViewModel.submittable)}async _selectFeatureForUpdate({feature:e,initialFeature:t=e}){this._stashValidationState();const{data:a,pendingFeatures:i,_webStyleCache:s}=this;i.includes(e)||a.addPendingFeature(e,t),a.selectedPendingFeature=e;const{_featureFormViewModel:n,_sketchViewModel:l}=this,{creationInfo:c,viewModel:u}=a,{attachmentsViewModel:h,layerInfos:p,view:m}=u;if(!m||!c)return;const f=c.layer,w=H(p,f),g=w?.formTemplate,y=m.spatialReference;n.set({arcadeEditType:"INSERT",feature:e,formTemplate:g,spatialReference:y,map:m.map}),"add"!==h.mode&&"edit"!==h.mode||u.activeWorkflow?.previous(),h.graphic=e,h.fileInfos.removeAll(),h.mode="view";if((this._attachmentFileInfos.get(e)||[]).forEach((({file:e,form:t})=>h.addFile(e,t))),await A(e,s,"2d"===m.type?m.scale:null),this.removeHandles(R),o(this._featureFormHandle),"2d"===m.type){const t=d((()=>m.scale),(t=>this._updateGraphicDebounced(e,s,t)));this.addHandles(t,R)}const v=a.getEditsForPendingFeature(e);this._featureFormHandle=r([n.on("value-change",(async()=>{v?.updateAttributes(n.getValues()),await A(e,s,"2d"===m.type?m.scale:null)})),l.on(["update","undo","redo"],(e=>{("undo"===e.type||"redo"===e.type||"update"===e.type&&null!=e.toolEventInfo&&j(e.toolEventInfo.type))&&n.notifyFeatureGeometryChanged()})),d((()=>n.feature?.sourceLayer),(t=>e.sourceLayer=t))]),this.createFeatureState="update-pending",this._visualVariableAttributes=E(e)}async _startUpdating({feature:e,initialFeature:t=e}){await this._selectFeatureForUpdate({feature:e,initialFeature:t});const{_sketchViewModel:a,data:i}=this,{creationInfo:r,viewModel:s}=i,{view:o}=s;if(!o||!r)return;const n=r.layer;return v(n)?void 0:U({graphic:e,sketchViewModel:a,sourceLayer:n,visualVariables:this._visualVariableAttributes,webStyleCache:this._webStyleCache})}static _createWorkflowSteps(e,t="awaiting-feature-creation-info"){const{data:a}=e,i=T(["awaiting-feature-creation-info","creating-features","adding-attachment","editing-attachment"],t,{"awaiting-feature-creation-info":()=>({id:"awaiting-feature-creation-info",async setUp(){const{creationInfo:t,viewModel:i}=a,{view:r}=i;r&&(I(t)?e.addHandles(await S({view:r,data:a,next:()=>e.next(),cancel:()=>i.cancelWorkflow({warnIfNoWorkflow:!1})}),this.id):(a.parent&&t&&(e.addHandles(i.lockFeatureTemplatesViewModel(),this.id),i.featureTemplatesViewModel.layers=[t.layer]),e.addHandles(i.featureTemplatesViewModel.on("select",(({item:t})=>{t&&(a.creationInfo={...a.creationInfo,layer:t.layer,template:t.template},e.next())})),this.id)))},async tearDown(){e.removeHandles([this.id,R])}}),"creating-features":()=>({id:"creating-features",async setUp(){e._isActive&&await e._setUpCreatingFeaturesStep()},async tearDown(t){const{viewModel:i}=a;t.canceled&&(e.removeHandles([Z,z,R,q]),i.attachmentsViewModel.fileInfos.removeAll(),e._attachmentFileInfos.clear())}}),"adding-attachment":()=>({id:"adding-attachment",parent:"creating-features",async setUp(){},async tearDown(){const{attachmentsViewModel:t}=a.viewModel,{graphic:i,fileInfos:r}=t;e._attachmentFileInfos.set(i,r.toArray()),t.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"creating-features",async setUp(){},async tearDown(){const{attachmentsViewModel:t}=a.viewModel,{graphic:i,fileInfos:r}=t;e._attachmentFileInfos.set(i,r.toArray()),t.mode="view"}})});return O(a,i)}static _configureSketchViewModel(e){const{data:t}=e,{creationInfo:a,viewModel:s}=t,{view:o}=s,n=e._sketchViewModel,l=[];if(!o)return i();"2d"===o.type&&a&&l.push(e._fadeExistingFeatures(a.layer));const u=async t=>{if("cancel"===t.state&&null!==o.activeTool&&o.activeTool!==e.sketchViewModel.activeComponent&&(await e._waitForActiveToolCleared(),await e._startCreating()),"complete"===t.state&&t.graphic){const a=t.graphic,i=t.graphic.clone();return i.geometry=null,await e._waitForActiveToolCleared(),void await e._selectFeatureForUpdate({feature:a,initialFeature:i})}},h=async i=>{const{attachmentsViewModel:r}=s,{_featureFormViewModel:n}=e;if(i.graphics.length>1)return void await e._clearSelectedFeature();const l=i.graphics[0];if("complete"===i.state){const{submittable:t}=n;if(e.numPendingFeatures!==a?.maxFeatures&&t||n.submit(),await e._clearSelectedFeature(),"add"!==r.mode&&"edit"!==r.mode||s.activeWorkflow?.previous(),!i.aborted&&o.activeTool===e.sketchViewModel.activeComponent&&(await e.sketchViewModel.wait(),"ready"===e.sketchViewModel.state&&"mesh"!==e.data.creationInfo?.layer.geometryType))return e._startCreating()}else{if("start"===i.state)return l.sourceLayer=t.creationInfo?.layer,e._selectFeatureForUpdate({feature:l});if("active"===i.state){await e.updatePendingFeature(l);const t=e._visualVariableAttributes;await x(o,l,i,t,e._webStyleCache);const a=l.attributes,{rotation:r,size:s}=t;if(null!=r){const{field:e}=r;n.setValue(e,a[e])}if(null!=s){const{field:e}=s;n.setValue(e,a[e])}}}},p=async a=>{if(a.graphics.forEach((e=>{t.removePendingFeature(e)})),!I(t.creationInfo))return e._startCreating()},m=async()=>{if(I(t.creationInfo))try{await e.data.viewModel.back()}catch{}return e._startCreating()};l.push(n.on("create",(t=>e._updatingHandles.addPromise(u(t)))),n.on("update",(t=>e._updatingHandles.addPromise(h(t)))),n.on("delete",(t=>e._updatingHandles.addPromise(p(t)))),c((()=>!e.numPendingFeatures),(()=>e._updatingHandles.addPromise(m()))),J(n,t),...Q(t)),l.push(d((()=>[e._featureFormViewModel.feature,e._featureFormViewModel.submittable]),(()=>{e._stashValidationState()})));const f=r(l);return n.addHandles(f),f}_initializeSketchViewModel(){const{data:e}=this,{view:t}=e.viewModel,a=new y({elevationInfo:e.creationInfo?.layer.elevationInfo,internal:!0,listMode:"hide"}),r=new G({layer:a,creationMode:"update",sketchOptions:e.sketchOptions,snappingManager:e.snappingManager,updateOnGraphicClick:!1,defaultUpdateOptions:{multipleSelectionEnabled:!1},view:t});this._sketchViewModel=r,t?.map.add(a),this.addHandles([i((()=>{t?.destroyed||t?.map.remove(a),a.destroy()})),d((()=>this.numPendingFeatures>0),(e=>this._sketchViewModel.updateOnGraphicClick=e),u)])}_hasValidationErrors(e){return!!e&&(!this.data.isSubmittable(e)||!!this._featureFormViewModel.validateContingencyConstraints(e.attributes,{includeIncompleteViolations:!0})?.length)}async _setUpCreatingFeaturesStep(){if(this.hasHandles(Z))return;const{data:e,sketchViewModel:s}=this,{creationInfo:n,viewModel:l}=e,{attachmentsViewModel:c,view:h}=l;if(!h||!n?.layer)throw new a("missing-parameters","CreateFeaturesWorkflow requires a view and creationInfo.");const{initialFeature:p,layer:m}=n,f=[];this._featureFormHandle=o(this._featureFormHandle),this._visualVariableAttributes={rotation:null,size:null},this.data.editorItem=l.findEditorItemForLayer(n.layer),D(c),f.push(d((()=>c.mode),(e=>{switch(e){case"add":this.go("adding-attachment");break;case"edit":this.go("editing-attachment")}})));const w=L(h);f.push(w);const y=v(n.layer);try{if(y){const{template:e}=n;if(e&&g(e))throw new a("Shared templates are not yet supported");const i=p??new t({attributes:{...e?.prototype.attributes,...n.attributeOverrides},sourceLayer:m});await this._startUpdating({feature:i})}else f.push(N._configureSketchViewModel(this)),p?(s.layer.add(p),await this._startUpdating({feature:p})):await this._startCreating()}finally{w.remove()}const F=i((()=>{for(const t of e.pendingFeatures)s.layer.remove(t),e.removePendingFeature(t)})),_=d((()=>h?.timeZone),(e=>this._featureFormViewModel.timeZone=e),u),M=i((()=>{I(n)&&l.cancelWorkflow({warnIfNoWorkflow:!1})}));this._featureFormHandle&&f.push(this._featureFormHandle),this.addHandles(f,this._handleKeys.beforeCommit),this.addHandles([i((()=>c.fileInfos.removeAll())),r(f),M,F,_],Z)}async _waitForActiveToolCleared(){const e=this.data.viewModel.view;if(null==e?.activeTool)return;const t=new AbortController;this.addHandles(s(t),q),await h((()=>null==e?.activeTool),t.signal),t.abort()}};function J(e,t){let a=null;const s=()=>e.snappingOptions.featureSources,o=()=>(a=new b({layer:e.layer}),s().add(a),a),l=()=>{null!=a&&(s().remove(a),a=n(a))};return r([d((()=>{const e=t.creationInfo?.layer,a=s().find((t=>t.layer===e));return{hasFeatureLayerSource:!!a,enabled:a?.enabled??!1}}),(({hasFeatureLayerSource:e,enabled:t})=>{if(!e)return l();a??=o(),a.enabled=t}),p),i(l)])}function Q(e){const t=e.viewModel.view;if(!t)return[];const a=[];if("3d"===t.type){const r=new _({view:t});a.push(d((()=>e.selectedPendingFeature),((e,t)=>{r.remove(e),r.add(t)})),i((()=>r.destroy())))}const r=new _({view:t,highlightName:V});return a.push(d((()=>e.temporaryHighlightFeature),(e=>{r.removeAll(),r.add(e)})),i((()=>r.destroy()))),a}function X(e,t,a,i){const r=[];return t.forEach(((t,s)=>{if(!t.error){const o=e[s],n=i.get(o)||[];o.attributes[a.objectIdField]=t.objectId,n.forEach((({form:e})=>r.push({feature:o,attachment:e})))}})),r}function Y(e,t,a){const i=[],r=t.globalIdField;return e.forEach(((t,s)=>{e[s].attributes[r]??=m(),(a?.get(t)||[]).forEach((({file:e})=>i.push({feature:t,attachment:{globalId:m(),data:e}})))})),i.length?{addFeatures:e,addAttachments:i}:{addFeatures:e}}e([f()],B.prototype,"createFeatureState",void 0),e([f()],B.prototype,"data",void 0),e([f({constructOnly:!0})],B.prototype,"isNested",void 0),e([f()],B.prototype,"featureFormViewModel",null),e([f()],B.prototype,"hasPendingEdits",null),e([f()],B.prototype,"hasPreviousStep",null),e([f()],B.prototype,"_getDrawMeshHelpMessage",void 0),e([f()],B.prototype,"helpMessage",null),e([f()],B.prototype,"layer",null),e([f()],B.prototype,"parent",null),e([f()],B.prototype,"parentLayer",null),e([f()],B.prototype,"keyboardCancellationEnabled",null),e([f()],B.prototype,"reliesOnOwnerAdminPrivileges",null),e([f()],B.prototype,"shouldShowAttachments",null),e([f()],B.prototype,"shouldAllowAttachmentEditing",null),e([f()],B.prototype,"sketchViewModel",null),e([f()],B.prototype,"availableCreateTools",null),B=N=e([w("esri.widgets.Editor.CreateFeaturesWorkflow")],B);const $=B;export{$ 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.33/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 i from"../../core/Error.js";import r from"../../core/Evented.js";import{makeHandle as s}from"../../core/handleUtils.js";import o from"../../core/Logger.js";import{abortMaybe as n,removeMaybe as l,destroyMaybe as p}from"../../core/maybe.js";import{throwIfAborted as d,createResolver as c}from"../../core/promiseUtils.js";import{watch as u,on as h,when as w,whenOnce as f,syncAndInitial as m,initial as y,sync as k}from"../../core/reactiveUtils.js";import{property as g}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as v}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as _}from"../../core/support/UpdatingHandles.js";import W from"../../layers/GraphicsLayer.js";import{isEditableLayer as F}from"../../layers/support/editableLayers.js";import{isFeatureLayer as E,getOwningPortalUrl as M}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as I}from"../../portal/support/urlUtils.js";import b from"../../views/interactive/sketch/SketchOptions.js";import{SnappingManager as C}from"../../views/interactive/snapping/SnappingManager.js";import V from"../../views/interactive/snapping/SnappingOptions.js";import A from"../Attachments/AttachmentsViewModel.js";import U from"./CreateFeaturesWorkflow.js";import O from"./UpdateWorkflow.js";import{isUpdateWorkflow as T,whenEditorLayerView as L}from"./workflowUtils.js";import S from"./support/EditorItem.js";import j from"../FeatureTemplates/FeatureTemplatesViewModel.js";import P from"../Sketch/SketchViewModel.js";import R from"../Spinner/SpinnerViewModel.js";const H="esri.widgets.Editor.EditorViewModel",x=()=>o.getLogger(H);function D(t,e,a){x().error(new i(t,e,a))}function G(t,e){return t?.find((t=>t.layer===e))}let q=class extends r.EventedAccessor{constructor(t){super(t),this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new W({listMode:"hide",internal:!0}),this._snappingManager=null,this._updateItemsTask=null,this._updatingHandles=new _,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 j({disabledItemFunction:({layer:t})=>this._itemIsSuspended(t)}),this.layerInfos=null,this.ownSketchViewModel=new P({layer:this._sketchGraphicsLayer}),this.sketchOptions=new b,this.snappingOptions=new V({attributeRulesEnabled:!0}),this.spinnerViewModel=new R,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&&"create-features"!==this.activeWorkflow?.type){if(t.submit(),!t.submittable||t.pendingSubtypeChoice)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([u((()=>{const t=this.view,e=t?.map?.editableLayers,a=t?.allLayerViews,i=a?.filter((t=>!!e?.includes(t.layer)));return[e,i,this.layerInfos]}),(()=>this._updateEditorItems()),m),u((()=>this.hideTemplatesForInactiveLayers),(()=>this.syncFeatureTemplates())),h((()=>this.activeWorkflow),"cancel",(()=>this.emit("workflow-cancel"))),h((()=>this.activeWorkflow),"commit",(()=>this.emit("workflow-commit"))),h((()=>this.activeWorkflow),"complete",(()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)})),w((()=>this.view?.map),(t=>t.add(this._sketchGraphicsLayer)),y),h((()=>this.editorItems),"change",(()=>this._afterEditorItemsChange())),u((()=>[this.canCreate,this.canUpdateVisible]),(()=>this._afterEditorItemsChange())),u((()=>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}),m),w((()=>"awaiting-update-feature-candidate"===this.state),(()=>this._candidateCommitted=!1)),h((()=>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)})),h((()=>this.view),"key-down",(t=>{"Escape"===t.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(t.stopPropagation(),this.back())})),h((()=>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})}),k),u((()=>this.view),(t=>{if(this._snappingManager=p(this._snappingManager),!t)return;const e=this.snappingOptions;this._snappingManager=new C({view:t,options:e}),this.ownSketchViewModel.snappingManager=this._snappingManager}),m),u((()=>this.snappingOptions),(t=>{this._snappingManager&&(this._snappingManager.options=t)}),m)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then((()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null})),this._updateItemsTask=n(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=l(this._sketchEventListenerHandle)}get activeLeafWorkflow(){const t=this.activeWorkflow;return t&&T(t)?t.activeWorkflow??t:t}get canCreate(){return this.editorItems.some((t=>t.supportsCreateFeaturesWorkflow))}get canCreateVisible(){return!!this.featureTemplatesLayers.length}get canUpdate(){return this.editorItems.some((t=>t.supportsUpdateWorkflow))}get canUpdateVisible(){return this.editorItems.some((t=>t.supportsUpdateWorkflow&&t.visible))}get featureTemplatesLayers(){const t=new a;for(const e of this.editorItems){const a=e.supportsCreateFeaturesWorkflow&&!e.isTable,i=this.hideTemplatesForInactiveLayers&&!e.visible;a&&!i&&t.push(e.layer)}return t}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}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&&null!=t?.activeWorkflow?.featureFormViewModel.associatedLayer)return"viewing-associated-features";if("update"===t?.type&&null!=t?.activeWorkflow?.featureFormViewModel.associationId)return"viewing-associated-layers";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 featureFormHasAssociation(){return!!this.featureFormViewModel?.activeAssociation}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}get snappingManager(){return this._snappingManager}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(t){return this.startCreateFeaturesWorkflow(t,"creating-features")}async startCreateFeaturesWorkflow(t,e="awaiting-feature-creation-info"){if(await f((()=>!this.updating)),!this.canCreate)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled.");const a=this._createUpdatingResolver();try{await this._cancelWorkflow();const a=this._createCreateFeaturesWorkflow(t,e);this._set("activeWorkflow",a),await a.start()}catch(r){this._logErrorAndCancelWorkflow(r)}finally{a.resolve()}}async startCreateFeaturesWorkflowAtFeatureEdit(t){await f((()=>!this.updating));const e=this._createUpdatingResolver();try{const{initialFeature:e}=t,a=e.sourceLayer=e.layer,r=a?this.findEditorItemForLayer(a):void 0;if(!r?.supportsCreateFeaturesWorkflow)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled for this layer.");await this._cancelWorkflow();const s=this._createCreateFeaturesWorkflow({initialFeature:e,layer:r.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",s),await s.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async startUpdateWorkflowAtFeatureSelection(){if(await f((()=>!this.updating)),!this.canUpdate)return void D("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow();const t=this._createUpdateWorkflow();this._set("activeWorkflow",t),await t.start()}catch(e){this._logErrorAndCancelWorkflow(e)}finally{t.resolve()}}async startUpdateWorkflowAtMultipleFeatureSelection(t){if(await f((()=>!this.updating)),!this.canUpdate)return void D("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow("awaiting-update-feature-candidate");e.data.candidates=t,this._set("activeWorkflow",e),await e.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async startUpdateWorkflowAtFeatureEdit(t){if(await f((()=>!this.updating)),!this.canUpdate)return void D("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow("editing-existing-feature");e.data.rootFeature=t,this._set("activeWorkflow",e),await e.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async deleteFeatureFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveFeature():D("editing:unsupported-workflow","Deleting a feature requires an active update workflow.")}async deleteAssociationFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveAssociation():D("editing:unsupported-workflow","Deleting an association requires an active update workflow.")}async cancelWorkflow(t){return this._cancelWorkflow({warnIfNoWorkflow:!0,...t})}findEditorItemForLayer(t){return this.editorItems.find((e=>e.layer===t))}itemHasInvalidFormTemplate(t){return null!=t&&!0===this.findEditorItemForLayer(t.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){this._featureTemplatesViewModelLocked||(this.featureTemplatesViewModel.layers=this.featureTemplatesLayers.toArray())}zoomTo(t){const e=t??this.sketchViewModel?.updateGraphics.toArray();e&&this.view?.goTo(e)}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,s((()=>{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()))]),d(t),[...i.reverse(),...r.reverse()].filter((t=>F(t)&&("mesh"!==t.geometryType||"3d"===e.type))).flatMap((t=>"subtype-group"===t.type?t.sublayers.toArray():t))}_drainEditorItems(){this.editorItems.drain((t=>t.destroy()))}async _updateEditorItems(){n(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=G(o,l),a=await L(t,l).catch((()=>null));(e?i:a?r:s).push(new S({layer:l,layerInfo:e,layerView:a}))}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}_afterEditorItemsChange(){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.canUpdateVisible||"awaiting-update-feature-candidate"===e&&!t.hasUpdatableCandidates)&&this._cancelWorkflow():"awaiting-feature-creation-info"!==e||this.canCreate||this._cancelWorkflow()}async _cancelWorkflow(t){const e=this.activeWorkflow;if(!e)return void(t?.warnIfNoWorkflow&&D("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 U.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 O.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),applyEditsAssociationCallback:(t,e,a)=>this._applyEditsAssociation(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 r=null;if(!("addAttachment"in t)||null==t.capabilities?.attachment)throw new i("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation((async()=>(r=await(t.addAttachment?.(e,a).catch((t=>{throw t?.error||t})))??null,r))),r}async _applyEdits(t,e,a){let i=null;const r=t.url?await M(t.url):null,s={returnServiceEditsOption:(!r||!I(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 L(a,t).catch((()=>null));return i=await t.applyEdits(e,s),r&&await f((()=>!r.updating)),i})),i}async _applyEditsAssociation(t,e,a){let i=null;const r={globalIdUsed:!0,...a};return await this._queueOperation((async()=>i=await t.applyEdits(e,r))),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=>(Array.isArray(t)?t.forEach((t=>this._handleEditsResultError(t))):this._handleEditsResultError(t),t))).catch((a=>{D("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)}))}_handleEditsResultError(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}}_createUpdatingResolver(){const t=c();return this._updatingHandles.addPromise(t.promise),t}_logErrorAndCancelWorkflow(t){const{name:e,message:a,details:i}=t;D(e??"editing:workflow-start-failed",a??void 0,i??t),this._cancelWorkflow({force:!0})}_itemIsSuspended(t){const e=this.findEditorItemForLayer(t);return null!=e&&(!e.visible||e.disabled)}};t([g()],q.prototype,"_snappingManager",void 0),t([g({readOnly:!0})],q.prototype,"activeWorkflow",void 0),t([g()],q.prototype,"activeLeafWorkflow",null),t([g({readOnly:!0})],q.prototype,"_activityQueue",void 0),t([g({readOnly:!0})],q.prototype,"canCreate",null),t([g()],q.prototype,"canCreateVisible",null),t([g({readOnly:!0})],q.prototype,"canUpdate",null),t([g()],q.prototype,"canUpdateVisible",null),t([g()],q.prototype,"featureTemplatesLayers",null),t([g()],q.prototype,"editorItems",void 0),t([g({readOnly:!0})],q.prototype,"failures",void 0),t([g()],q.prototype,"hideTemplatesForInactiveLayers",void 0),t([g({type:A})],q.prototype,"attachmentsViewModel",void 0),t([g()],q.prototype,"featureFormViewModel",null),t([g({type:j})],q.prototype,"featureTemplatesViewModel",void 0),t([g()],q.prototype,"labelOptions",null),t([g()],q.prototype,"layerInfos",void 0),t([g()],q.prototype,"ownSketchViewModel",void 0),t([g()],q.prototype,"sketchOptions",void 0),t([g()],q.prototype,"sketchViewModel",null),t([g({type:V,nonNullable:!0})],q.prototype,"snappingOptions",void 0),t([g()],q.prototype,"spinnerViewModel",void 0),t([g()],q.prototype,"state",null),t([g({readOnly:!0})],q.prototype,"syncing",null),t([g()],q.prototype,"updating",null),t([g()],q.prototype,"tooltipOptions",null),t([g()],q.prototype,"valueOptions",null),t([g()],q.prototype,"view",null),t([g()],q.prototype,"pageStack",void 0),t([g()],q.prototype,"showDiscardEditsPrompt",void 0),t([g()],q.prototype,"_candidateCommitted",void 0),t([g()],q.prototype,"page",null),t([g()],q.prototype,"featureFormDisabled",null),t([g()],q.prototype,"featureFormHasAssociation",null),t([g()],q.prototype,"canGoBack",null),t([g()],q.prototype,"shouldShowDeleteButton",null),t([g()],q.prototype,"hasPendingEdits",null),t([g()],q.prototype,"snappingManager",null),q=t([v(H)],q);const B=q;export{B 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 i from"../../core/Error.js";import r from"../../core/Evented.js";import{makeHandle as o}from"../../core/handleUtils.js";import s from"../../core/Logger.js";import{abortMaybe as n,removeMaybe as l,destroyMaybe as p}from"../../core/maybe.js";import{throwIfAborted as d,createResolver as c}from"../../core/promiseUtils.js";import{watch as u,on as h,when as w,whenOnce as f,syncAndInitial as m,initial as y,sync as k}from"../../core/reactiveUtils.js";import{property as g}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as v}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as _}from"../../core/support/UpdatingHandles.js";import W from"../../layers/GraphicsLayer.js";import{isEditableLayer as F}from"../../layers/support/editableLayers.js";import{isFeatureLayer as E,getOwningPortalUrl as M}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as I}from"../../portal/support/urlUtils.js";import b from"../../views/interactive/sketch/SketchOptions.js";import{SnappingManager as C}from"../../views/interactive/snapping/SnappingManager.js";import V from"../../views/interactive/snapping/SnappingOptions.js";import A from"../Attachments/AttachmentsViewModel.js";import U from"./CreateFeaturesWorkflow.js";import O from"./UpdateWorkflow.js";import{isUpdateWorkflow as T,whenEditorLayerView as L}from"./workflowUtils.js";import S from"./support/EditorItem.js";import j from"../FeatureTemplates/FeatureTemplatesViewModel.js";import P from"../Sketch/SketchViewModel.js";import R from"../Spinner/SpinnerViewModel.js";const G="esri.widgets.Editor.EditorViewModel",H=()=>s.getLogger(G);function x(t,e,a){H().error(new i(t,e,a))}function D(t,e){return t?.find((t=>t.layer===e))}let q=class extends r.EventedAccessor{constructor(t){super(t),this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new W({listMode:"hide",internal:!0}),this._snappingManager=null,this._updateItemsTask=null,this._updatingHandles=new _,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 j({disabledItemFunction:({layer:t})=>this._itemIsSuspended(t)}),this.layerInfos=null,this.ownSketchViewModel=new P({layer:this._sketchGraphicsLayer}),this.sketchOptions=new b,this.snappingOptions=new V({attributeRulesEnabled:!0}),this.spinnerViewModel=new R,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&&"create-features"!==this.activeWorkflow?.type){if(t.submit(),!t.submittable||t.pendingSubtypeChoice)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([u((()=>{const t=this.view,e=t?.map?.editableLayers,a=t?.allLayerViews,i=a?.filter((t=>!!e?.includes(t.layer)));return[e,i,this.layerInfos]}),(()=>this._updateEditorItems()),m),u((()=>this.hideTemplatesForInactiveLayers),(()=>this.syncFeatureTemplates())),h((()=>this.activeWorkflow),"cancel",(()=>this.emit("workflow-cancel"))),h((()=>this.activeWorkflow),"commit",(()=>this.emit("workflow-commit"))),h((()=>this.activeWorkflow),"complete",(()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)})),w((()=>this.view?.map),(t=>t.add(this._sketchGraphicsLayer)),y),h((()=>this.editorItems),"change",(()=>this._afterEditorItemsChange())),u((()=>[this.canCreate,this.canUpdateVisible]),(()=>this._afterEditorItemsChange())),u((()=>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}),m),w((()=>"awaiting-update-feature-candidate"===this.state),(()=>this._candidateCommitted=!1)),h((()=>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)})),h((()=>this.view),"key-down",(t=>{"Escape"===t.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(t.stopPropagation(),this.back())})),h((()=>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,o=`sketch-${t.type}`;this.emit(o,{type:o,detail:t,layer:i,parentLayer:r})}),k),u((()=>this.view),(t=>{if(this._snappingManager=p(this._snappingManager),!t)return;const e=this.snappingOptions;this._snappingManager=new C({view:t,options:e}),this.ownSketchViewModel.snappingManager=this._snappingManager}),m),u((()=>this.snappingOptions),(t=>{this._snappingManager&&(this._snappingManager.options=t)}),m)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then((()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null})),this._updateItemsTask=n(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=l(this._sketchEventListenerHandle)}get activeLeafWorkflow(){const t=this.activeWorkflow;return t&&T(t)?t.activeWorkflow??t:t}get canCreate(){return this.editorItems.some((t=>t.supportsCreateFeaturesWorkflow))}get canCreateVisible(){return!!this.featureTemplatesLayers.length}get canUpdate(){return this.editorItems.some((t=>t.supportsUpdateWorkflow))}get canUpdateVisible(){return this.editorItems.some((t=>t.supportsUpdateWorkflow&&t.visible))}get featureTemplatesLayers(){const t=new a;for(const e of this.editorItems){const a=e.supportsCreateFeaturesWorkflow&&!e.isTable,i=this.hideTemplatesForInactiveLayers&&!e.visible;a&&!i&&t.push(e.layer)}return t}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}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 canZoomTo(){const t=this.sketchViewModel,e=t?.createGraphic?.geometry?.type;return!(!t?.updateGraphics?.length&&"multipoint"!==e)}get page(){const{activeWorkflow:t,state:e}=this;if("update"===t?.type&&null!=t?.activeWorkflow?.featureFormViewModel.associatedLayer)return"viewing-associated-features";if("update"===t?.type&&null!=t?.activeWorkflow?.featureFormViewModel.associationId)return"viewing-associated-layers";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 featureFormHasAssociation(){return!!this.featureFormViewModel?.activeAssociation}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}get snappingManager(){return this._snappingManager}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(t){return this.startCreateFeaturesWorkflow(t,"creating-features")}async startCreateFeaturesWorkflow(t,e="awaiting-feature-creation-info"){if(await f((()=>!this.updating)),!this.canCreate)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled.");const a=this._createUpdatingResolver();try{await this._cancelWorkflow();const a=this._createCreateFeaturesWorkflow(t,e);this._set("activeWorkflow",a),await a.start()}catch(r){this._logErrorAndCancelWorkflow(r)}finally{a.resolve()}}async startCreateFeaturesWorkflowAtFeatureEdit(t){await f((()=>!this.updating));const e=this._createUpdatingResolver();try{const{initialFeature:e}=t,a=e.sourceLayer=e.layer,r=a?this.findEditorItemForLayer(a):void 0;if(!r?.supportsCreateFeaturesWorkflow)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled for this layer.");await this._cancelWorkflow();const o=this._createCreateFeaturesWorkflow({initialFeature:e,layer:r.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",o),await o.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async startUpdateWorkflowAtFeatureSelection(){if(await f((()=>!this.updating)),!this.canUpdate)return void x("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow();const t=this._createUpdateWorkflow();this._set("activeWorkflow",t),await t.start()}catch(e){this._logErrorAndCancelWorkflow(e)}finally{t.resolve()}}async startUpdateWorkflowAtMultipleFeatureSelection(t){if(await f((()=>!this.updating)),!this.canUpdate)return void x("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow("awaiting-update-feature-candidate");e.data.candidates=t,this._set("activeWorkflow",e),await e.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async startUpdateWorkflowAtFeatureEdit(t){if(await f((()=>!this.updating)),!this.canUpdate)return void x("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow("editing-existing-feature");e.data.rootFeature=t,this._set("activeWorkflow",e),await e.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async deleteFeatureFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveFeature():x("editing:unsupported-workflow","Deleting a feature requires an active update workflow.")}async deleteAssociationFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveAssociation():x("editing:unsupported-workflow","Deleting an association requires an active update workflow.")}async cancelWorkflow(t){return this._cancelWorkflow({warnIfNoWorkflow:!0,...t})}findEditorItemForLayer(t){return this.editorItems.find((e=>e.layer===t))}itemHasInvalidFormTemplate(t){return null!=t&&!0===this.findEditorItemForLayer(t.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){this._featureTemplatesViewModelLocked||(this.featureTemplatesViewModel.layers=this.featureTemplatesLayers.toArray())}zoomTo(t){const e=this.sketchViewModel,a=t??(e?.updateGraphics.length?e?.updateGraphics.toArray():e?.createGraphic);a&&this.view?.goTo(a)}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,o((()=>{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()))]),d(t),[...i.reverse(),...r.reverse()].filter((t=>F(t)&&("mesh"!==t.geometryType||"3d"===e.type))).flatMap((t=>"subtype-group"===t.type?t.sublayers.toArray():t))}_drainEditorItems(){this.editorItems.drain((t=>t.destroy()))}async _updateEditorItems(){n(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=[],o=[],{layerInfos:s}=this;for(const l of a){const e=D(s,l),a=await L(t,l).catch((()=>null));(e?i:a?r:o).push(new S({layer:l,layerInfo:e,layerView:a}))}s?.length&&i.sort(((t,e)=>s.findIndex((({layer:e})=>e===t.layer))-s.findIndex((({layer:t})=>t===e.layer))));const n=[...i,...r,...o];e.aborted||(this._drainEditorItems(),this.editorItems.addMany(n))}));this._updatingHandles.addPromise(a.promise),this._updateItemsTask=a}_afterEditorItemsChange(){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.canUpdateVisible||"awaiting-update-feature-candidate"===e&&!t.hasUpdatableCandidates)&&this._cancelWorkflow():"awaiting-feature-creation-info"!==e||this.canCreate||this._cancelWorkflow()}async _cancelWorkflow(t){const e=this.activeWorkflow;if(!e)return void(t?.warnIfNoWorkflow&&x("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 U.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 O.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),applyEditsAssociationCallback:(t,e,a)=>this._applyEditsAssociation(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 r=null;if(!("addAttachment"in t)||null==t.capabilities?.attachment)throw new i("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation((async()=>(r=await(t.addAttachment?.(e,a).catch((t=>{throw t?.error||t})))??null,r))),r}async _applyEdits(t,e,a){let i=null;const r=t.url?await M(t.url):null,o={returnServiceEditsOption:(!r||!I(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 L(a,t).catch((()=>null));return i=await t.applyEdits(e,o),r&&await f((()=>!r.updating)),i})),i}async _applyEditsAssociation(t,e,a){let i=null;const r={globalIdUsed:!0,...a};return await this._queueOperation((async()=>i=await t.applyEdits(e,r))),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=>(Array.isArray(t)?t.forEach((t=>this._handleEditsResultError(t))):this._handleEditsResultError(t),t))).catch((a=>{x("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)}))}_handleEditsResultError(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}}_createUpdatingResolver(){const t=c();return this._updatingHandles.addPromise(t.promise),t}_logErrorAndCancelWorkflow(t){const{name:e,message:a,details:i}=t;x(e??"editing:workflow-start-failed",a??void 0,i??t),this._cancelWorkflow({force:!0})}_itemIsSuspended(t){const e=this.findEditorItemForLayer(t);return null!=e&&(!e.visible||e.disabled)}};t([g()],q.prototype,"_snappingManager",void 0),t([g({readOnly:!0})],q.prototype,"activeWorkflow",void 0),t([g()],q.prototype,"activeLeafWorkflow",null),t([g({readOnly:!0})],q.prototype,"_activityQueue",void 0),t([g({readOnly:!0})],q.prototype,"canCreate",null),t([g()],q.prototype,"canCreateVisible",null),t([g({readOnly:!0})],q.prototype,"canUpdate",null),t([g()],q.prototype,"canUpdateVisible",null),t([g()],q.prototype,"featureTemplatesLayers",null),t([g()],q.prototype,"editorItems",void 0),t([g({readOnly:!0})],q.prototype,"failures",void 0),t([g()],q.prototype,"hideTemplatesForInactiveLayers",void 0),t([g({type:A})],q.prototype,"attachmentsViewModel",void 0),t([g()],q.prototype,"featureFormViewModel",null),t([g({type:j})],q.prototype,"featureTemplatesViewModel",void 0),t([g()],q.prototype,"labelOptions",null),t([g()],q.prototype,"layerInfos",void 0),t([g()],q.prototype,"ownSketchViewModel",void 0),t([g()],q.prototype,"sketchOptions",void 0),t([g()],q.prototype,"sketchViewModel",null),t([g({type:V,nonNullable:!0})],q.prototype,"snappingOptions",void 0),t([g()],q.prototype,"spinnerViewModel",void 0),t([g()],q.prototype,"state",null),t([g({readOnly:!0})],q.prototype,"syncing",null),t([g()],q.prototype,"updating",null),t([g()],q.prototype,"tooltipOptions",null),t([g()],q.prototype,"valueOptions",null),t([g()],q.prototype,"view",null),t([g()],q.prototype,"canZoomTo",null),t([g()],q.prototype,"pageStack",void 0),t([g()],q.prototype,"showDiscardEditsPrompt",void 0),t([g()],q.prototype,"_candidateCommitted",void 0),t([g()],q.prototype,"page",null),t([g()],q.prototype,"featureFormDisabled",null),t([g()],q.prototype,"featureFormHasAssociation",null),t([g()],q.prototype,"canGoBack",null),t([g()],q.prototype,"shouldShowDeleteButton",null),t([g()],q.prototype,"hasPendingEdits",null),t([g()],q.prototype,"snappingManager",null),q=t([v(G)],q);const B=q;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.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import a from"../../core/Error.js";import{makeHandle as i}from"../../core/handleUtils.js";import o from"../../core/Logger.js";import{abortMaybe as r}from"../../core/maybe.js";import{createResolver as s,onAbort as n,createAbortError as l,throwIfAborted as d,debounce as c}from"../../core/promiseUtils.js";import p from"../../core/Queue.js";import{whenOnce as u,when as w,watch as h,sync as f}from"../../core/reactiveUtils.js";import{last as g}from"../../core/SetUtils.js";import{property as m}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as k}from"../../core/accessorSupport/decorators/subclass.js";import{getServiceInfoForLayer as v,getAllStandardFeatureTemplatesForLayer as y}from"../../editing/templateUtils.js";import{isEditableLayer as W}from"../../layers/support/editableLayers.js";import{isFeatureLayer as b,isSubtypeSublayer as C,isSubtypeGroupLayer as _,isTable as M}from"../../layers/support/layerUtils.js";import{getServices as A}from"../../undoredo/support/Services.js";import F from"../../views/draw/support/HighlightHelper.js";import{ViewEventPriorities as S}from"../../views/input/InputManager.js";import I from"../../views/interactive/sketch/SketchOptions.js";import{temporaryHighlightName as j}from"../../views/support/HighlightDefaults.js";import E from"./CreateFeaturesWorkflow.js";import{UpdateFeatureWorkflow as U}from"./UpdateFeatureWorkflow.js";import{UpdateRecordWorkflow as P}from"./UpdateRecordWorkflow.js";import L from"./UpdateWorkflowData.js";import V from"./Workflow.js";import{createWorkflowSteps as x,fetchCandidates as O}from"./workflowUtils.js";import{isGraphicForRelatableFeatureSupportedLayer as R}from"../Feature/support/featureUtils.js";var T;const H="esri.widgets.Editor.UpdateWorkflow",D=()=>o.getLogger(H);let N=T=class extends V{constructor(e){super(e),this._workflowStack=new p(g),this._sketchStack=new p(g),this.data=void 0,this.type="update"}get activeEditorItem(){return this.activeWorkflow?.data.editorItem??void 0}get activeFeatureFormViewModel(){return this.activeWorkflow?.featureFormViewModel}get activeSketchViewModel(){return this._sketchStack.peek()?.viewModel}get canDeleteAssociation(){const{activeFeatureFormViewModel:e}=this;if(!this.activeWorkflow||!this.data.viewModel.view||!e)return!1;const{activeAssociation:t,feature:a}=e;return!(!t||!a?.sourceLayer||!b(a?.sourceLayer)&&!C(a?.sourceLayer))}get activeWorkflow(){return this._workflowStack.last()}get updating(){return this._updatingHandles.updating||!!this.activeWorkflow?.updating}get hasPreviousStep(){const e=this.activeWorkflow?.featureFormViewModel;return this._stepIndex>0||this.nestedWorkflowCount>1||null!=e?.relationshipId||"view"!==this.data.viewModel.attachmentsViewModel.mode||null!=e?.associationId||null!=e?.associatedLayer}get hasUpdatableCandidates(){const{candidates:e,viewModel:t}=this.data;return e.some((({layer:e})=>t.findEditorItemForLayer(e)?.supportsUpdateWorkflow))}get nestedWorkflowCount(){return this._workflowStack.length}get shouldShowAttachments(){return!!this.activeEditorItem?.capabilities.attachments.enabled}get shouldAllowAttachmentEditing(){return!!this.activeEditorItem?.capabilities.update.attachments.enabled}get hasPendingEdits(){return Array.from(this._workflowStack).some((e=>e.hasPendingEdits))}get helpMessage(){return this.activeWorkflow?.helpMessage?this.activeWorkflow.helpMessage:"awaiting-feature-to-update"===this.stepId?"select":void 0}get reliesOnOwnerAdminPrivileges(){return this.activeWorkflow?.reliesOnOwnerAdminPrivileges??!1}get hasInvalidFormTemplate(){return!!this.activeEditorItem?.hasInvalidFormTemplate}async back(e=()=>Promise.resolve(!0)){const{activeWorkflow:t}=this,a=t?.featureFormViewModel;if(null==a?.relationshipId)if(null==a?.associatedLayer)if(null==a?.associationId)if(t){if(t.hasPendingEdits){if(!await e())return}t.hasPreviousStep?await t.previous({cancelCurrentStep:!0}):await this.cancelActiveWorkflow({force:!0})}else this.hasPreviousStep?await this.previous({cancelCurrentStep:!0}):await this.cancel({force:!0});else a.associationId=null;else a.associatedLayer=null;else a.relationshipId=null}async cancelActiveWorkflow(e){await(this.activeWorkflow?.cancel(e)),await this._popWorkflow()}async commit(){await this._drainWorkflowStack((e=>e.commit())),await super.commit()}static create(e){const{viewModel:t,snappingManager:a,startAt:i,addAttachmentsCallback:o,applyEditsCallback:r,applyEditsAssociationCallback:s}=e,n=e.sketchOptions??new I,l=new T({data:new L({addAttachmentsCallback:o,applyEditsCallback:r,applyEditsAssociationCallback:s,sketchOptions:n,snappingManager:a,viewModel:t}),onCommit:async()=>{}});return l._set("steps",this._createWorkflowSteps(l,i)),l}async save(){this.nestedWorkflowCount>1?(await(this.activeWorkflow?.commit()),await this._popWorkflow()):await this.commit()}async startCreatingRelatedRecord(e){try{const t=await this._createNestedCreateFeaturesWorkflow(e);await this._pushWorkflow(t)}catch(t){throw new a("editor:unable-to-start-creating","Could not begin updating the provided feature or table record.",{error:t})}}async startUpdating(e,t){try{const a=await this._createNestedUpdateWorkflow(e,t);await this._pushWorkflow(a)}catch(i){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:i})}}async deleteActiveFeature(){const{activeWorkflow:e}=this;if(!e)throw new a("editor:nothing-to-delete","There is no feature to delete");z(e)?await e.deleteAndCommit():await e.cancel(),1===this.nestedWorkflowCount?await this.reset():(await this._popWorkflow(),await this._returnToPageWithContent())}async deleteActiveAssociation(){if(!this.canDeleteAssociation)throw new a("editor:nothing-to-delete","There is no association to delete");await this._deleteActiveAssociation(),await this._popWorkflow(),await this._returnToPageWithContent()}async cancelAll(){await this._drainWorkflowStack((e=>e.cancel({force:!0})))}async _deleteActiveAssociation(){const{activeFeatureFormViewModel:e,data:t}=this,{activeAssociation:i,feature:o}=e,{applyEditsAssociationCallback:r}=t,{view:s}=t.viewModel,n=await A(s).load(),l=v(n,o.sourceLayer)?.featureService,{utilityNetwork:d}=e.allAssociationInputs[0],c=d?.generateDeleteAssociations([i]),p=d?.gdbVersion??void 0;if(!l||!c)throw new a("editor:failed-to-delete-association","Could not create payload needed to delete association");await r(l,[c],{gdbVersion:p})}async _returnToPageWithContent(){const{activeFeatureFormViewModel:e}=this;if(!e?.activeAssociationInput)return;const{activeAssociationInput:t,associationId:a}=e;await t.refresh(),t.associatedLayer&&!t.associatedFeatures?.length&&(e.associatedLayer=null),null==a||t.associatedFeatureInfos.size||(e.associationId=null)}async _createNestedCreateFeaturesWorkflow(e){const{relatedLayer:t}=e,{addAttachmentsCallback:i,applyEditsCallback:o,sketchOptions:r,snappingManager:s,viewModel:n}=this.data;if(!W(t))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const l=this._getCreationInfoForNestedCreateFeaturesWorkflow(e),d=l.template||l.initialFeature?"creating-features":"awaiting-feature-creation-info",c="create-features"!==this.activeWorkflow?.type?this.activeWorkflow:void 0;return E.create({addAttachmentsCallback:i,applyEditsCallback:o,creationInfo:l,isNested:!0,parent:c,sketchOptions:r,snappingManager:s,startAt:d,viewModel:n})}_getCreationInfoForNestedCreateFeaturesWorkflow(e){const{relatedLayer:i}=e;if(!W(i)||_(i))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const o={layer:i,maxFeatures:1},r=this._makeRelatedRecordAttributes(e),s=y(i);return s?.length>0?(o.attributeOverrides=r,1===s.length&&(o.template=s[0])):o.initialFeature=new t({sourceLayer:i,attributes:r}),o}async _createNestedUpdateWorkflow(e,t){const a=M(e.sourceLayer)?P:U,{applyEditsCallback:i,applyEditsAssociationCallback:o,sketchOptions:r,snappingManager:s,viewModel:n}=this.data,l="create-features"!==this.activeWorkflow?.type?this.activeWorkflow:void 0,d=await a.create({association:t,feature:e,parent:l,sketchOptions:r,snappingManager:s,viewModel:n,applyEdits:i,applyEditsAssociation:o,featureFormCallbacks:{addRelatedRecord:async e=>await this.startCreatingRelatedRecord(e),editRelatedRecord:async({relatedFeature:e})=>await this.startUpdating(e),selectAssociatedFeature:async({feature:e,association:t})=>await this.startUpdating(e,t)}});return await u((()=>!d.updating)),d}async _drainWorkflowStack(e){const t=this._workflowStack,a=[];for(;t.length>0;){const i=t.pop();this._sketchStack.pop();const o=e(i).then((()=>i.destroy()));this._updatingHandles.addPromise(o),a.push(o)}await Promise.all(a)}_makeRelatedRecordAttributes(e){const{parentFeature:t,relatedLayer:a,relationshipId:i}=e;if(!R(t))return;const o=a.relationships?.find((e=>e.id===i));if(!o)return void G("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the destination layer.");if("origin"===o.role)return void G("unsupported-role","Creating new related records in the 'origin' table of a relationship is not yet supported");const r=t.sourceLayer;o.relatedTableId!==r.layerId&&G("invalid-argument-combination","The given parent feature does not belong to the relationship designated by the given relationship ID.");const s=r.relationships?.find((e=>e.id===i));if(!s)return void G("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the origin layer.");const n=q(r,s),l=t.getAttribute(n);l||G("no-key-on-origin-feature","The given parent feature does not have a value for the relationship's origin primary key field.");const d=q(a,o);return{[d]:l}}async _popWorkflow(){this._workflowStack.pop()?.destroy(),this._sketchStack.pop();const e=await this._reconcileWorkflowStack();if(e.failureCount>0)throw new a("editor:next-workflow-failed","Popped the top workflow, but the next workflow in the stack failed to activate",e)}async _pushWorkflow(e){const t=this._workflowRequiresSketchViewModel(e);this.activeWorkflow?.exit({removeSketchHandles:t});const i=this._sketchStack,o=await(e?.start()),r=i.peek();o?(r?.exit(),i.push(o)):i.push(this._cloneSketchController(r)),this._workflowStack.push(e);const s=await this._reconcileWorkflowStack();if(s.failureCount>0)throw new a("editor:failed-to-start-updating-feature","Failed to enter the provided workflow.",s)}async _reconcileWorkflowStack(){const e=this._workflowStack,t=this._sketchStack;try{const a=e.peek();return await(a?.enter()),await(t.peek()?.enter()),{activeWorkflow:a,failureCount:0}}catch(a){e.pop().destroy(),t.pop();const{activeWorkflow:i,failureCount:o}=await this._reconcileWorkflowStack();return{activeWorkflow:i,failureCount:o+1}}}_cloneSketchController(e){return{enter:e?.enter??(async()=>{}),exit:e?.exit??(async()=>{}),viewModel:e?.viewModel}}_workflowRequiresSketchViewModel(e){const{type:t}=e;return"update-feature"===t||"create-features"===t&&!M(e.data.creationInfo?.layer)}static _createWorkflowSteps(e,t="awaiting-feature-to-update"){const{data:o}=e;return x(["awaiting-feature-to-update","awaiting-update-feature-candidate","editing-existing-feature","adding-attachment","editing-attachment"],t,{"awaiting-feature-to-update":()=>({id:"awaiting-feature-to-update",async setUp(){const{spinnerViewModel:t}=o.viewModel,a=o.viewModel.view;a.activeTool=null;let c=null;e.addHandles(i((()=>{c=r(c)})),this.id),o.rootFeature=null,o.candidates=[];const p=a.on("immediate-click",(async i=>{const r=s();e._updatingHandles.addPromise(r.promise);try{t.location=i.mapPoint,t.visible=!0,c?.abort();const{editorItems:r}=o.viewModel;c=new AbortController;const s=await i.async((()=>new Promise(((e,t)=>{n(c?.signal,(()=>t(l()))),e(O(r,a,i,c?.signal))}))));if(d(c),o.candidates=s.filter((e=>"fulfilled"===e.status)).flatMap((e=>e.value)).filter((e=>!e.isAggregate)),t.visible=1===o.candidates.length,0===o.candidates.length)return;i.stopPropagation(),1===o.candidates.length?(o.rootFeature=o.candidates[0],e.go("editing-existing-feature").catch((()=>{})).then((()=>t.visible=!1))):e.next()}finally{r.resolve()}}),S.TOOL),u=w((()=>null!=a.activeTool),(()=>e.cancel({force:!0})),{once:!0});a.focus(),e.addHandles([p,u],this.id)},async tearDown(){0===o.candidates.length&&(o.viewModel.spinnerViewModel.visible=!1),e.removeHandles(this.id)}}),"awaiting-update-feature-candidate":()=>({id:"awaiting-update-feature-candidate",async setUp(){o.rootFeature=null;const{view:t}=o.viewModel;if(!t)return;const a=new F({view:t,highlightName:j});e.addHandles([h((()=>o.rootFeature),((e,t)=>{a.remove(t),a.add(e)}),f),i((()=>a.removeAll()))],this.id)},async tearDown(){e.removeHandles(this.id)}}),"editing-existing-feature":()=>({id:"editing-existing-feature",async setUp(){const{rootFeature:t,viewModel:i}=e.data;if(!t)throw new a("editor:no-feature-specified","Cannot setup the 'updating-existing-feature' step until the root feature is defined");await e.startUpdating(t),i.spinnerViewModel.visible=!1;const o=c((async()=>{await u((()=>!e.updating)),e.previous()}));e.addHandles([h((()=>e.nestedWorkflowCount),((e,t)=>{0===e&&0!==t&&o()}),f)],this.id)},async tearDown(){await e.cancelAll(),e.removeHandles(this.id)}}),"adding-attachment":()=>({id:"adding-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){o.viewModel.attachmentsViewModel.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){o.viewModel.attachmentsViewModel.mode="view"}})})}};function q(e,{keyField:t}){return e.getField(t)?.name??t}e([m()],N.prototype,"activeEditorItem",null),e([m()],N.prototype,"activeFeatureFormViewModel",null),e([m()],N.prototype,"activeSketchViewModel",null),e([m()],N.prototype,"canDeleteAssociation",null),e([m()],N.prototype,"activeWorkflow",null),e([m()],N.prototype,"updating",null),e([m()],N.prototype,"data",void 0),e([m()],N.prototype,"hasPreviousStep",null),e([m()],N.prototype,"hasUpdatableCandidates",null),e([m()],N.prototype,"nestedWorkflowCount",null),e([m()],N.prototype,"shouldShowAttachments",null),e([m()],N.prototype,"shouldAllowAttachmentEditing",null),e([m()],N.prototype,"hasPendingEdits",null),e([m()],N.prototype,"helpMessage",null),e([m()],N.prototype,"reliesOnOwnerAdminPrivileges",null),e([m()],N.prototype,"hasInvalidFormTemplate",null),N=T=e([k(H)],N);const G=(e,t)=>D().warn(`editor:${e}`,t,"The create operation will be allowed to proceed, but the resulting feature may not be related to the given parent feature."),z=e=>!!e&&/update-/.test(e.type),Q=N;export{Q as default};
|
|
5
|
+
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import a from"../../core/Error.js";import{makeHandle as i}from"../../core/handleUtils.js";import o from"../../core/Logger.js";import{abortMaybe as r}from"../../core/maybe.js";import{createResolver as s,onAbort as n,createAbortError as l,throwIfAborted as d,debounce as c}from"../../core/promiseUtils.js";import p from"../../core/Queue.js";import{whenOnce as u,when as w,watch as h,sync as f}from"../../core/reactiveUtils.js";import{last as g}from"../../core/SetUtils.js";import{property as m}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as k}from"../../core/accessorSupport/decorators/subclass.js";import{getAllStandardFeatureTemplatesForLayer as v}from"../../editing/templateUtils.js";import{isEditableLayer as y}from"../../layers/support/editableLayers.js";import{isFeatureLayer as W,isSubtypeSublayer as b,isSubtypeGroupLayer as C,isTable as _}from"../../layers/support/layerUtils.js";import{createFeatureServices as M}from"../../rest/featureService/utils.js";import A from"../../views/draw/support/HighlightHelper.js";import{ViewEventPriorities as S}from"../../views/input/InputManager.js";import F from"../../views/interactive/sketch/SketchOptions.js";import{temporaryHighlightName as I}from"../../views/support/HighlightDefaults.js";import j from"./CreateFeaturesWorkflow.js";import{UpdateFeatureWorkflow as E}from"./UpdateFeatureWorkflow.js";import{UpdateRecordWorkflow as U}from"./UpdateRecordWorkflow.js";import P from"./UpdateWorkflowData.js";import L from"./Workflow.js";import{createWorkflowSteps as V,fetchCandidates as x}from"./workflowUtils.js";import{findUtilityNetwork as O,isGraphicForRelatableFeatureSupportedLayer as R}from"../Feature/support/featureUtils.js";var T;const H="esri.widgets.Editor.UpdateWorkflow",D=()=>o.getLogger(H);let N=T=class extends L{constructor(e){super(e),this._workflowStack=new p(g),this._sketchStack=new p(g),this.data=void 0,this.type="update"}get activeEditorItem(){return this.activeWorkflow?.data.editorItem??void 0}get activeFeatureFormViewModel(){return this.activeWorkflow?.featureFormViewModel}get activeSketchViewModel(){return this._sketchStack.peek()?.viewModel}get canDeleteAssociation(){const{activeFeatureFormViewModel:e}=this;if(!this.activeWorkflow||!this.data.viewModel.view?.map||!e)return!1;const{activeAssociation:t,feature:a}=e;return!(!t||!a?.sourceLayer||!W(a?.sourceLayer)&&!b(a?.sourceLayer))}get activeWorkflow(){return this._workflowStack.last()}get updating(){return this._updatingHandles.updating||!!this.activeWorkflow?.updating}get hasPreviousStep(){const e=this.activeWorkflow?.featureFormViewModel;return this._stepIndex>0||this.nestedWorkflowCount>1||null!=e?.relationshipId||"view"!==this.data.viewModel.attachmentsViewModel.mode||null!=e?.associationId||null!=e?.associatedLayer}get hasUpdatableCandidates(){const{candidates:e,viewModel:t}=this.data;return e.some((({layer:e})=>t.findEditorItemForLayer(e)?.supportsUpdateWorkflow))}get nestedWorkflowCount(){return this._workflowStack.length}get shouldShowAttachments(){return!!this.activeEditorItem?.capabilities.attachments.enabled}get shouldAllowAttachmentEditing(){return!!this.activeEditorItem?.capabilities.update.attachments.enabled}get hasPendingEdits(){return Array.from(this._workflowStack).some((e=>e.hasPendingEdits))}get helpMessage(){return this.activeWorkflow?.helpMessage?this.activeWorkflow.helpMessage:"awaiting-feature-to-update"===this.stepId?"select":void 0}get reliesOnOwnerAdminPrivileges(){return this.activeWorkflow?.reliesOnOwnerAdminPrivileges??!1}get hasInvalidFormTemplate(){return!!this.activeEditorItem?.hasInvalidFormTemplate}async back(e=()=>Promise.resolve(!0)){const{activeWorkflow:t}=this,a=t?.featureFormViewModel;if(null==a?.relationshipId)if(null==a?.associatedLayer)if(null==a?.associationId)if("create-features"===t?.type&&t.hasPreviousStep)await t.previous({cancelCurrentStep:!0});else if(t){if(t.hasPendingEdits){if(!await e())return}t.hasPreviousStep?await t.previous({cancelCurrentStep:!0}):await this.cancelActiveWorkflow({force:!0})}else this.hasPreviousStep?await this.previous({cancelCurrentStep:!0}):await this.cancel({force:!0});else a.associationId=null;else a.associatedLayer=null;else a.relationshipId=null}async cancelActiveWorkflow(e){await(this.activeWorkflow?.cancel(e)),await this._popWorkflow()}async commit(){await this._drainWorkflowStack((e=>e.commit())),await super.commit()}static create(e){const{viewModel:t,snappingManager:a,startAt:i,addAttachmentsCallback:o,applyEditsCallback:r,applyEditsAssociationCallback:s}=e,n=e.sketchOptions??new F,l=new T({data:new P({addAttachmentsCallback:o,applyEditsCallback:r,applyEditsAssociationCallback:s,sketchOptions:n,snappingManager:a,viewModel:t}),onCommit:async()=>{}});return l._set("steps",this._createWorkflowSteps(l,i)),l}async save(){this.nestedWorkflowCount>1?(await(this.activeWorkflow?.commit()),await this._popWorkflow()):await this.commit()}async startCreatingRelatedRecord(e){try{const t=await this._createNestedCreateFeaturesWorkflow(e);await this._pushWorkflow(t)}catch(t){throw new a("editor:unable-to-start-creating","Could not begin updating the provided feature or table record.",{error:t})}}async startUpdating(e,t){try{const a=await this._createNestedUpdateWorkflow(e,t);await this._pushWorkflow(a)}catch(i){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:i})}}async deleteActiveFeature(){const{activeWorkflow:e}=this;if(!e)throw new a("editor:nothing-to-delete","There is no feature to delete");z(e)?await e.deleteAndCommit():await e.cancel(),1===this.nestedWorkflowCount?await this.reset():(await this._popWorkflow(),await this._returnToPageWithContent())}async deleteActiveAssociation(){if(!this.canDeleteAssociation)throw new a("editor:nothing-to-delete","There is no association to delete");await this._deleteActiveAssociation(),await this._popWorkflow(),await this._returnToPageWithContent()}async cancelAll(){await this._drainWorkflowStack((e=>e.cancel({force:!0})))}async _deleteActiveAssociation(){const{activeFeatureFormViewModel:e,data:t}=this,{activeAssociation:i,feature:o}=e,{applyEditsAssociationCallback:r,viewModel:s}=t,{sourceLayer:n}=o,l=b(n)&&n.parent?n.parent:n,d=M([l]),c=d.values().next().value?.featureService;if(!c)throw new a("editor:failed-to-delete-association","Could not retrieve feature service needed to delete association");await(c?.load());const p=s.view.map,u=O(p,l),w=u?.generateDeleteAssociations([i]);if(!w)throw new a("editor:failed-to-delete-association","Could not create payload needed to delete association");const h=u?.gdbVersion??void 0;await r(c,[w],{gdbVersion:h})}async _returnToPageWithContent(){const{activeFeatureFormViewModel:e}=this;if(!e?.activeAssociationInput)return;const{activeAssociationInput:t,associationId:a}=e;await t.refresh(),t.associatedLayer&&!t.associatedFeatures?.length&&(e.associatedLayer=null),null==a||t.associatedFeatureInfos.size||(e.associationId=null)}async _createNestedCreateFeaturesWorkflow(e){const{relatedLayer:t}=e,{addAttachmentsCallback:i,applyEditsCallback:o,sketchOptions:r,snappingManager:s,viewModel:n}=this.data;if(!y(t))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const l=this._getCreationInfoForNestedCreateFeaturesWorkflow(e),d=l.template||l.initialFeature?"creating-features":"awaiting-feature-creation-info",c="create-features"!==this.activeWorkflow?.type?this.activeWorkflow:void 0;return j.create({addAttachmentsCallback:i,applyEditsCallback:o,creationInfo:l,isNested:!0,parent:c,sketchOptions:r,snappingManager:s,startAt:d,viewModel:n})}_getCreationInfoForNestedCreateFeaturesWorkflow(e){const{relatedLayer:i}=e;if(!y(i)||C(i))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const o={layer:i,maxFeatures:1},r=this._makeRelatedRecordAttributes(e),s=v(i);return s?.length>0?(o.attributeOverrides=r,1===s.length&&(o.template=s[0])):o.initialFeature=new t({sourceLayer:i,attributes:r}),o}async _createNestedUpdateWorkflow(e,t){const a=_(e.sourceLayer)?U:E,{applyEditsCallback:i,applyEditsAssociationCallback:o,sketchOptions:r,snappingManager:s,viewModel:n}=this.data,l="create-features"!==this.activeWorkflow?.type?this.activeWorkflow:void 0,d=await a.create({association:t,feature:e,parent:l,sketchOptions:r,snappingManager:s,viewModel:n,applyEdits:i,applyEditsAssociation:o,featureFormCallbacks:{addRelatedRecord:async e=>await this.startCreatingRelatedRecord(e),editRelatedRecord:async({relatedFeature:e})=>await this.startUpdating(e),selectAssociatedFeature:async({feature:e,association:t})=>await this.startUpdating(e,t)}});return await u((()=>!d.updating)),d}async _drainWorkflowStack(e){const t=this._workflowStack,a=[];for(;t.length>0;){const i=t.pop();this._sketchStack.pop();const o=e(i).then((()=>i.destroy()));this._updatingHandles.addPromise(o),a.push(o)}await Promise.all(a)}_makeRelatedRecordAttributes(e){const{parentFeature:t,relatedLayer:a,relationshipId:i}=e;if(!R(t))return;const o=a.relationships?.find((e=>e.id===i));if(!o)return void G("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the destination layer.");if("origin"===o.role)return void G("unsupported-role","Creating new related records in the 'origin' table of a relationship is not yet supported");const r=t.sourceLayer;o.relatedTableId!==r.layerId&&G("invalid-argument-combination","The given parent feature does not belong to the relationship designated by the given relationship ID.");const s=r.relationships?.find((e=>e.id===i));if(!s)return void G("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the origin layer.");const n=q(r,s),l=t.getAttribute(n);l||G("no-key-on-origin-feature","The given parent feature does not have a value for the relationship's origin primary key field.");const d=q(a,o);return{[d]:l}}async _popWorkflow(){this._workflowStack.pop()?.destroy(),this._sketchStack.pop();const e=await this._reconcileWorkflowStack();if(e.failureCount>0)throw new a("editor:next-workflow-failed","Popped the top workflow, but the next workflow in the stack failed to activate",e)}async _pushWorkflow(e){const t=this._workflowRequiresSketchViewModel(e);this.activeWorkflow?.exit({removeSketchHandles:t});const i=this._sketchStack,o=await(e?.start()),r=i.peek();o?(r?.exit(),i.push(o)):i.push(this._cloneSketchController(r)),this._workflowStack.push(e);const s=await this._reconcileWorkflowStack();if(s.failureCount>0)throw new a("editor:failed-to-start-updating-feature","Failed to enter the provided workflow.",s)}async _reconcileWorkflowStack(){const e=this._workflowStack,t=this._sketchStack;try{const a=e.peek();return await(a?.enter()),await(t.peek()?.enter()),{activeWorkflow:a,failureCount:0}}catch(a){e.pop().destroy(),t.pop();const{activeWorkflow:i,failureCount:o}=await this._reconcileWorkflowStack();return{activeWorkflow:i,failureCount:o+1}}}_cloneSketchController(e){return{enter:e?.enter??(async()=>{}),exit:e?.exit??(async()=>{}),viewModel:e?.viewModel}}_workflowRequiresSketchViewModel(e){const{type:t}=e;return"update-feature"===t||"create-features"===t&&!_(e.data.creationInfo?.layer)}static _createWorkflowSteps(e,t="awaiting-feature-to-update"){const{data:o}=e;return V(["awaiting-feature-to-update","awaiting-update-feature-candidate","editing-existing-feature","adding-attachment","editing-attachment"],t,{"awaiting-feature-to-update":()=>({id:"awaiting-feature-to-update",async setUp(){const{spinnerViewModel:t}=o.viewModel,a=o.viewModel.view;a.activeTool=null;let c=null;e.addHandles(i((()=>{c=r(c)})),this.id),o.rootFeature=null,o.candidates=[];const p=a.on("immediate-click",(async i=>{const r=s();e._updatingHandles.addPromise(r.promise);try{t.location=i.mapPoint,t.visible=!0,c?.abort();const{editorItems:r}=o.viewModel;c=new AbortController;const s=await i.async((()=>new Promise(((e,t)=>{n(c?.signal,(()=>t(l()))),e(x(r,a,i,c?.signal))}))));if(d(c),o.candidates=s.filter((e=>"fulfilled"===e.status)).flatMap((e=>e.value)).filter((e=>!e.isAggregate)),t.visible=1===o.candidates.length,0===o.candidates.length)return;i.stopPropagation(),1===o.candidates.length?(o.rootFeature=o.candidates[0],e.go("editing-existing-feature").catch((()=>{})).then((()=>t.visible=!1))):e.next()}finally{r.resolve()}}),S.TOOL),u=w((()=>null!=a.activeTool),(()=>e.cancel({force:!0})),{once:!0});a.focus(),e.addHandles([p,u],this.id)},async tearDown(){0===o.candidates.length&&(o.viewModel.spinnerViewModel.visible=!1),e.removeHandles(this.id)}}),"awaiting-update-feature-candidate":()=>({id:"awaiting-update-feature-candidate",async setUp(){o.rootFeature=null;const{view:t}=o.viewModel;if(!t)return;const a=new A({view:t,highlightName:I});e.addHandles([h((()=>o.rootFeature),((e,t)=>{a.remove(t),a.add(e)}),f),i((()=>a.removeAll()))],this.id)},async tearDown(){e.removeHandles(this.id)}}),"editing-existing-feature":()=>({id:"editing-existing-feature",async setUp(){const{rootFeature:t,viewModel:i}=e.data;if(!t)throw new a("editor:no-feature-specified","Cannot setup the 'updating-existing-feature' step until the root feature is defined");await e.startUpdating(t),i.spinnerViewModel.visible=!1;const o=c((async()=>{await u((()=>!e.updating)),e.previous()}));e.addHandles([h((()=>e.nestedWorkflowCount),((e,t)=>{0===e&&0!==t&&o()}),f)],this.id)},async tearDown(){await e.cancelAll(),e.removeHandles(this.id)}}),"adding-attachment":()=>({id:"adding-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){o.viewModel.attachmentsViewModel.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){o.viewModel.attachmentsViewModel.mode="view"}})})}};function q(e,{keyField:t}){return e.getField(t)?.name??t}e([m()],N.prototype,"activeEditorItem",null),e([m()],N.prototype,"activeFeatureFormViewModel",null),e([m()],N.prototype,"activeSketchViewModel",null),e([m()],N.prototype,"canDeleteAssociation",null),e([m()],N.prototype,"activeWorkflow",null),e([m()],N.prototype,"updating",null),e([m()],N.prototype,"data",void 0),e([m()],N.prototype,"hasPreviousStep",null),e([m()],N.prototype,"hasUpdatableCandidates",null),e([m()],N.prototype,"nestedWorkflowCount",null),e([m()],N.prototype,"shouldShowAttachments",null),e([m()],N.prototype,"shouldAllowAttachmentEditing",null),e([m()],N.prototype,"hasPendingEdits",null),e([m()],N.prototype,"helpMessage",null),e([m()],N.prototype,"reliesOnOwnerAdminPrivileges",null),e([m()],N.prototype,"hasInvalidFormTemplate",null),N=T=e([k(H)],N);const G=(e,t)=>D().warn(`editor:${e}`,t,"The create operation will be allowed to proceed, but the resulting feature may not be related to the given parent feature."),z=e=>!!e&&/update-/.test(e.type),Q=N;export{Q 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.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as o}from"../../chunks/tslib.es6.js";import e from"../../core/Accessor.js";import{property as t}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import
|
|
5
|
+
import{_ as o}from"../../chunks/tslib.es6.js";import e from"../../core/Accessor.js";import{property as t}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import n from"../support/SnappingControls/VisibleElements.js";let l=class extends e{constructor(o){super(o),this.createFeaturesSection=!0,this.directionModePicker=!1,this.editFeaturesSection=!0,this.flow=!0,this.labelsToggle=!0,this.settingsMenu=!0,this.snappingControls=!0,this.snappingControlsElements=new n,this.tooltipsToggle=!0,this.undoRedoButtons=!0,this.sketch=!0,this.zoomToButton=!0}};o([t({type:Boolean,nonNullable:!0})],l.prototype,"createFeaturesSection",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"directionModePicker",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"editFeaturesSection",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"flow",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"labelsToggle",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"settingsMenu",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"snappingControls",void 0),o([t({type:n,nonNullable:!0})],l.prototype,"snappingControlsElements",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"tooltipsToggle",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"undoRedoButtons",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"sketch",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"zoomToButton",void 0),l=o([s("esri.widgets.Editor.VisibleElements")],l);const p=l;export{p 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.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{isSome as e}from"../../../core/arrayUtils.js";import{getDisplayFieldName as t}from"../../../layers/support/fieldUtils.js";import{loadPanelContentComponents as
|
|
5
|
+
import{isSome as e}from"../../../core/arrayUtils.js";import{getDisplayFieldName as t}from"../../../layers/support/fieldUtils.js";import{loadPanelContentComponents as o,PanelContentSection as r,PanelContent as a}from"./PanelContent.js";import{loadCalciteComponents as s}from"../../support/componentsUtils.js";import{ItemList as l}from"../../support/ItemList.js";import"../../support/widgetUtils.js";import{tsx as n}from"../../support/jsxFactory.js";const i=()=>Promise.all([o(),s({action:()=>import("@esri/calcite-components/dist/components/calcite-action")})]);function c({editorItems:t,filterText:o,id:s,messagesTemplates:i,onFilterTextChange:c,onSelectFeature:p,onZoomTo:u,workflow:f,editorMessages:y}){const j=new Map,I=f.data.candidates;let b=0;I.map((e=>({label:m(e),id:e.attributes[e.layer.objectIdField],data:e}))).filter((({label:e,data:r})=>{const a=o.toLowerCase(),{title:s}=r.layer,l=t.find((e=>e.layer===r.sourceLayer));return l?l.supportsUpdateWorkflow&&(!a||e?.toLowerCase().includes(a)||s?.toLowerCase().includes(a)):null})).filter(e).forEach((e=>{b++;const t=e.data.layer;j.has(t)?j.get(t)?.items.push(e):j.set(t,{id:`${t.id}`,label:t.title??"",items:[e]})}));const g=t.toArray().map((({layer:e})=>j.get(e))).filter(e),h=b>10||o.length>0;return n(a,{key:"feature-list"},n(r,null,l({enableListScroll:!1,filterEnabled:h,filterText:o,id:s,items:g,messages:{filterPlaceholder:i.filterPlaceholder,noItems:i.noItems,noMatches:i.noMatches},onFilterChange:e=>c(e),onItemMouseEnter:e=>p(e.data),onItemMouseLeave:()=>p(null),onItemSelect:e=>p(e.data,!0),renderItemActionEnd:e=>d(e.data,u,y.zoomTo)})))}function m(e){const o=e.layer;if(!o)return null;const r=o.fieldsIndex.get(o.objectIdField),a=r.alias||r.name,{attributes:s}=e,l=t(o);return l&&s[l]&&`${s[l]}`||`${a}: ${s[r.name]}`}function d(e,t,o){return n("calcite-action",{appearance:"transparent",icon:"zoom-to-object",onclick:()=>t(e),scale:"s",slot:"actions-end",text:o,title:o})}export{c as FeatureList,i as loadFeatureListComponents};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{substitute as e}from"../../../intl/substitute.js";import{loadFooterActionsComponents as t,FooterActions as o}from"./FooterActions.js";import{loadNoticesComponents as n,Notices as
|
|
5
|
+
import{substitute as e}from"../../../intl/substitute.js";import{loadFooterActionsComponents as t,FooterActions as o}from"./FooterActions.js";import{loadNoticesComponents as n,Notices as i}from"./Notices.js";import{loadPanelContentComponents as s,PanelContentSection as a,PanelContentSectionGroup as r,PanelContent as l}from"./PanelContent.js";import u from"./PendingFeatureList.js";import{Heading as d,incrementHeadingLevel as p}from"../../support/Heading.js";import"../../support/widgetUtils.js";import{tsx as c,tsxFragment as m}from"../../support/jsxFactory.js";const f=()=>Promise.all([t(),n(),s()]);function h({editorViewModel:t,headingLevel:n,messages:s,messagesCommon:f,onDelete:h,onDeleteAssociation:y,onSave:g,renderAttachments:w,renderFeatureForm:b,renderSketchToolbar:k}){const{activeLeafWorkflow:v,activeWorkflow:F,featureFormViewModel:A,syncing:j}=t;if(!v||!F||!A)return null;const S=v.type.includes("update"),C=S&&!v.hasPendingEdits||j||A.updating,L=S?f.update:f.create,P="create-features"===v?.type?v.numPendingFeatures:0,D="create-features"!==v?.type||!!v.data.selectedPendingFeature,T=P>1?e(s.createFeaturesTemplate,{numFeatures:P}):L,H="shouldShowAttachments"in v&&v.shouldShowAttachments&&!A.activeRelationshipInput,x=A.inputs.every((e=>!e.visible))&&!H,B=x?c(a,null,"create-features"===v.type?c(u,{headingLevel:n,key:"pending-feature-list",workflow:v}):void 0):c(a,{key:"panel-content-section"},c(i,{messages:s,workflow:F}),c(r,null,D||"create-features"!==v.type?b():c(u,{headingLevel:n,key:"pending-feature-list",workflow:v}),H?c("div",{key:"attachments"},c(d,{level:p(n)},s.attachments),w()):null)),I={onClick:g,disabled:C,label:T,type:"button"},M={appearance:"outline",onClick:h,disabled:j,kind:"danger",label:f.delete,type:"button"},V={...M,onClick:y,label:s.deleteAssociationTitle,type:"button"},W={...M,primaryLabel:f.delete,primaryText:f.delete,dropdownItems:[{onClick:y,label:s.deleteAssociationTitle}],type:"split-button"};return c(m,null,x?k():void 0,c(l,{key:"attribute-panel-content"},B),c(o,{buttons:[I,t.shouldShowDeleteButton&&!t.featureFormHasAssociation?M:void 0,!t.shouldShowDeleteButton&&t.featureFormHasAssociation?V:void 0,t.shouldShowDeleteButton&&t.featureFormHasAssociation?W:void 0]}))}export{h as UpdateFeaturePanelContent,f as loadUpdateFeaturePanelContentComponents};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import{property as r}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as s}from"../../../core/accessorSupport/decorators/subclass.js";import{isTable as o}from"../../../layers/support/layerUtils.js";import i from"./EditorEditingCapabilities.js";import{formTemplateHasInvalidFields as
|
|
5
|
+
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import{property as r}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as s}from"../../../core/accessorSupport/decorators/subclass.js";import{isTable as o}from"../../../layers/support/layerUtils.js";import{hasEffectiveFeatureExpressionInfo as i}from"../../../support/elevationInfoUtils.js";import l from"./EditorEditingCapabilities.js";import{formTemplateHasInvalidFields as a}from"../../FeatureForm/featureFormUtils.js";let p=class extends t{constructor(e){super(e),this.disabled=!1,this.layer=null,this.layerInfo=null,this.layerView=null}get _suspended(){return!!this.layerView?.suspended}get capabilities(){return new l({layer:this.layer,layerInfo:this.layerInfo,layerView:this.layerView})}get editable(){const{create:e,relationship:t,update:r,delete:{enabled:s}}=this.capabilities,o=e.attachments.enabled||r.attachments.enabled;return!this.disabled&&(e.enabled||r.enabled||o||s||t.enabled)}get formTemplate(){return this.capabilities.formTemplate}get hasInvalidFormTemplate(){return a(this.layer,this.formTemplate)}get isTable(){return o(this.layer)}get supportsCreateFeaturesWorkflow(){if(this.disabled)return!1;if("3d"===this.layerView?.view?.type&&i(this.layer.elevationInfo))return!1;const{enabled:e,geometry:t}=this.capabilities.create;return this.isTable?e:e&&t}get supportsUpdateWorkflow(){const{capabilities:e}=this;return!this.disabled&&(e.update.enabled||e.update.attachments.enabled||e.delete.enabled)}get visible(){const{layer:e}=this,t=e.parent;return!this._suspended&&e.visible&&(!t||!("visible"in t)||t.visible)}};e([r()],p.prototype,"_suspended",null),e([r()],p.prototype,"capabilities",null),e([r()],p.prototype,"disabled",void 0),e([r()],p.prototype,"editable",null),e([r()],p.prototype,"formTemplate",null),e([r()],p.prototype,"hasInvalidFormTemplate",null),e([r()],p.prototype,"isTable",null),e([r()],p.prototype,"layer",void 0),e([r()],p.prototype,"layerInfo",void 0),e([r()],p.prototype,"layerView",void 0),e([r()],p.prototype,"supportsCreateFeaturesWorkflow",null),e([r()],p.prototype,"supportsUpdateWorkflow",null),e([r()],p.prototype,"visible",null),p=e([s("esri.widgets.Editor.support.EditorItem")],p);const n=p;export{n as default};
|