@arcgis/core 4.26.0-next.20221221 → 4.26.0-next.20221223
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/WebScene.js +1 -1
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{2163b9ee4d639d5ed6f3.js → 05bba3ba2f9ee02f52b5.js} +1 -1
- package/assets/esri/core/workers/chunks/{bbccf69f4aa1b1761265.js → 0b8dc54801a7aa5e6be3.js} +1 -1
- package/assets/esri/core/workers/chunks/{6dbd3aabfe4d5d593205.js → 0b9c53e01d6ac1e7d5ca.js} +29 -29
- package/assets/esri/core/workers/chunks/1039cd48a12e88baa97a.js +1 -0
- package/assets/esri/core/workers/chunks/{634e7957696f72c8b8b1.js → 3fb4ae8d6e8563a1c255.js} +1 -1
- package/assets/esri/core/workers/chunks/{b61ce04af4e57b1856cb.js → d447ebc944a9867f5a99.js} +1 -1
- package/assets/esri/core/workers/chunks/e3ba96417fd75a5d2feb.js +1 -0
- package/assets/esri/core/workers/chunks/{099765dff2b7e6958d3d.js → efc9030af5aac27055a1.js} +1 -1
- package/assets/esri/themes/base/widgets/_UtilityNetworkTrace.scss +1 -1
- 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/assets/esri/widgets/Directions/t9n/Directions_ar.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_bg.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_bs.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_ca.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_cs.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_da.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_de.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_el.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_es.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_et.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_fi.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_fr.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_he.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_hr.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_hu.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_id.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_it.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_ja.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_ko.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_lt.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_lv.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_nb.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_nl.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_pl.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_pt-BR.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_pt-PT.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_ro.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_ru.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_sk.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_sl.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_sr.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_sv.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_th.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_tr.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_uk.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_vi.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_zh-CN.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_zh-HK.json +1 -1
- package/assets/esri/widgets/Directions/t9n/Directions_zh-TW.json +1 -1
- package/assets/esri/widgets/Feature/t9n/Feature_he.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_ar.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_bg.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_bs.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_ca.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_cs.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_da.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_de.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_el.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_es.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_et.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_fi.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_fr.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_he.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_hr.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_hu.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_id.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_it.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_ja.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_ko.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_lt.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_lv.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_nb.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_nl.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_pl.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_pt-BR.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_pt-PT.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_ro.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_ru.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_sk.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_sl.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_sr.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_sv.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_th.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_tr.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_uk.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_vi.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_zh-CN.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_zh-HK.json +1 -1
- package/assets/esri/widgets/Popup/t9n/Popup_zh-TW.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_ar.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_bg.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_bs.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_ca.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_cs.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_da.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_de.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_el.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_es.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_et.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_fi.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_fr.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_he.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_hr.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_hu.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_id.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_it.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_ja.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_ko.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_lt.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_lv.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_nb.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_nl.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_pl.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_pt-BR.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_pt-PT.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_ro.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_ru.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_sk.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_sl.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_sr.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_sv.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_th.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_tr.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_uk.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_vi.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_zh-CN.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_zh-HK.json +1 -1
- package/assets/esri/widgets/Slice/t9n/Slice_zh-TW.json +1 -1
- package/core/workers/workers.js +1 -1
- package/geometry/support/intersects.js +1 -1
- package/geometry/support/meshUtils/elevation.js +1 -1
- package/geometry/support/meshUtils/exporters/gltf/index.js +1 -1
- package/geometry.js +1 -1
- package/interfaces.d.ts +868 -0
- package/intl.js +1 -1
- package/layers/support/ImageParameters.js +1 -1
- package/layers/support/VoxelVariable.js +1 -1
- package/layers/support/VoxelVolumeStyle.js +1 -1
- package/layers/support/domains.js +1 -1
- package/layers/support/rasterDatasets/wcsCoverageParser.js +1 -1
- package/libs/maquette/projection.js +1 -1
- package/package.json +1 -1
- package/pointCloudRenderers.js +1 -1
- package/popup/content.js +1 -1
- package/rasterRenderers.js +1 -1
- package/renderers.js +1 -1
- package/rest/locator/addressesToLocations.js +1 -1
- package/support/arcadeUtils.js +1 -1
- package/support/revision.js +1 -1
- package/symbols/support/unitConversionUtils.js +1 -1
- package/symbols.js +1 -1
- package/views/2d/engine/FeatureContainer.js +1 -1
- package/views/2d/layers/BaseLayerViewGL2D.js +1 -1
- package/views/2d/layers/FeatureLayerView2D.js +1 -1
- package/views/2d/layers/GraphicsLayerView2D.js +1 -1
- package/views/2d/layers/KMLLayerView2D.js +1 -1
- package/views/2d/layers/LayerView2D.js +1 -1
- package/views/2d/layers/MapImageLayerView2D.js +1 -1
- package/views/2d/layers/MapNotesLayerView2D.js +1 -1
- package/views/2d/layers/RouteLayerView2D.js +1 -1
- package/views/2d/layers/StreamLayerView2D.js +1 -1
- package/views/2d/layers/VectorTileLayerView2D.js +1 -1
- package/views/2d/layers/WMSLayerView2D.js +1 -1
- package/views/2d/layers/WMTSLayerView2D.js +1 -1
- package/views/2d/layers/features/FeatureStore2D.js +1 -1
- package/views/2d/layers/features/controllers/FeatureController2D.js +1 -1
- package/views/2d/layers/features/processors/HeatmapProcessor.js +1 -1
- package/views/2d/layers/features/processors/SymbolProcessor.js +1 -1
- package/views/2d/layers/features/schemaUtils.js +1 -1
- package/views/2d/layers/features/sources/BaseFeatureSource.js +1 -1
- package/views/2d/layers/features/sources/DataTileSource.js +1 -1
- package/views/2d/layers/features/sources/DataTileSubscription.js +1 -1
- package/views/2d/layers/features/sources/GeoEventSource.js +1 -1
- package/views/2d/layers/features/sources/SnapshotFeatureSource.js +1 -1
- package/views/2d/layers/features/support/AttributeStore.js +1 -1
- package/views/2d/layers/features/support/rendererUtils.js +1 -1
- package/views/2d/layers/features/tileRenderers/SymbolTileRenderer.js +1 -1
- package/views/2d/layers/features/tileRenderers/support/HeatmapSource.js +1 -1
- package/views/2d/layers/features/tileRenderers/support/WGLFeatureView.js +1 -1
- package/views/2d/layers/features/tileRenderers/support/visualVariablesUtils.js +1 -1
- package/views/2d/layers/graphics/BaseGraphicContainer.js +1 -1
- package/views/2d/layers/graphics/GraphicBoundsRenderer.js +1 -1
- package/views/2d/layers/graphics/graphicsUtils.js +1 -1
- package/views/2d/layers/imagery/ImageryView2D.js +1 -1
- package/views/2d/layers/support/DebugOverlay.js +1 -1
- package/views/2d/layers/support/ExportStrategy.js +1 -1
- package/views/2d/layers/support/FeatureLayerProxy.js +1 -1
- package/views/2d/magnifier/MagnifierView2D.js +1 -1
- package/views/2d/navigation/MapViewNavigation.js +1 -1
- package/views/2d/navigation/ZoomBox.js +1 -1
- package/views/2d/navigation/actions/Pan.js +1 -1
- package/views/2d/navigation/actions/Pinch.js +1 -1
- package/views/2d/tiling/TileManager.js +1 -1
- package/views/3d/analysis/DirectLineMeasurementAnalysisView3D.js +1 -1
- package/views/3d/layers/FeatureLayerViewBase3D.js +1 -1
- package/views/3d/layers/FeatureLikeLayerView3D.js +1 -1
- package/views/3d/layers/GraphicsView3D.js +1 -1
- package/views/3d/layers/ImageryTileLayerView3D.js +1 -1
- package/views/3d/layers/SceneLayerGraphicsView3D.js +1 -1
- package/views/3d/layers/TiledLayerView3D.js +1 -1
- package/views/3d/layers/VectorTileLayerView3D.js +1 -1
- package/views/3d/layers/WMTSLayerView3D.js +1 -1
- package/views/3d/layers/graphics/ElevationAligners.js +1 -1
- package/views/3d/layers/graphics/Graphics3DCore.js +1 -1
- package/views/3d/layers/graphics/Graphics3DElevationAlignment.js +1 -1
- package/views/3d/layers/graphics/Graphics3DExtrudeSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DFeatureStore.js +1 -1
- package/views/3d/layers/graphics/Graphics3DFrustumVisibility.js +1 -1
- package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DObject3DGraphicLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DObjectSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DPathSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DPolygonFillSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DScaleVisibility.js +1 -1
- package/views/3d/layers/graphics/Graphics3DSymbol.js +1 -1
- package/views/3d/layers/graphics/Graphics3DSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DTextSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/QueryEngine.js +1 -1
- package/views/3d/layers/graphics/SpatialIndex2D.js +1 -1
- package/views/3d/layers/graphics/elevationAlignmentUtils.js +1 -1
- package/views/3d/layers/graphics/featureExpressionInfoUtils.js +1 -1
- package/views/3d/layers/graphics/graphicUtils.js +1 -1
- package/views/3d/layers/graphics/objectResourceUtils.js +1 -1
- package/views/3d/layers/graphics/queryForSymbologySnapping.js +1 -1
- package/views/3d/layers/graphics/symbolComplexity.js +1 -1
- package/views/3d/layers/graphics/wosrLoader.js +1 -1
- package/views/3d/layers/i3s/I3SIndex.js +1 -1
- package/views/3d/layers/i3s/I3SOverrides.js +1 -1
- package/views/3d/layers/i3s/I3SUtil.js +1 -1
- package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
- package/views/3d/layers/i3s/attributeEditing.js +1 -1
- package/views/3d/layers/support/FastSymbolUpdates.js +1 -1
- package/views/3d/layers/support/FeatureTileFetcher3D.js +1 -1
- package/views/3d/layers/support/FeatureTileFetcher3DDebugger.js +1 -1
- package/views/3d/layers/support/FeatureTileTree3DDebugger.js +1 -1
- package/views/3d/layers/support/HeatmapFeatureProcessor.js +1 -1
- package/views/3d/layers/support/StageLayerElevationProvider.js +1 -1
- package/views/3d/layers/support/featureTileQuery3D.js +1 -1
- package/views/3d/layers/support/projectExtentUtils.js +1 -1
- package/views/3d/support/PBFDecoderWorker.js +1 -1
- package/views/3d/support/SharedSymbolResources.js +1 -1
- package/views/3d/terrain/PatchRenderData.js +1 -1
- package/views/support/geometry3dUtils.js +1 -1
- package/widgets/BasemapGallery/support/basemapCompatibilityUtils.js +1 -1
- package/widgets/Daylight.js +1 -1
- package/widgets/Directions/components/SaveLayer.js +1 -1
- package/widgets/Directions.js +1 -1
- package/widgets/Editor.js +1 -1
- package/widgets/FeatureForm.js +1 -1
- package/widgets/FeatureTemplates/ItemList.js +1 -1
- package/widgets/Popup.js +1 -1
- package/widgets/ShadowCast/components/Label.js +1 -1
- package/widgets/Slice/SlicePlane.js +1 -1
- package/widgets/Slice.js +1 -1
- package/widgets/UtilityNetworkTrace.js +1 -1
- package/widgets/Weather.js +1 -1
- package/widgets/support/SnappingControls.js +1 -1
- package/assets/esri/core/workers/chunks/7ce1b3056f392cd10031.js +0 -1
- package/assets/esri/core/workers/chunks/fc197a387187daab1df3.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.26/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{deprecatedProperty as t}from"../core/deprecate.js";import{on as s,pausable as r}from"../core/events.js";import i from"../core/Logger.js";import{isNone as o,isSome as n,unwrap as a,unwrapOrValue as l}from"../core/maybe.js";import{watch as c,initial as d,when as h,on as u}from"../core/reactiveUtils.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import{cast as v}from"../core/accessorSupport/decorators/cast.js";import"../core/arrayUtils.js";import{subclass as m}from"../core/accessorSupport/decorators/subclass.js";import{defaultUnitPropertyMetadata as _}from"../properties/defaultUnit.js";import g from"../rest/support/Stop.js";import y from"../symbols/SimpleMarkerSymbol.js";import S from"./Search.js";import w from"./Widget.js";import M from"./Directions/DirectionsViewModel.js";import{SaveLayer as b}from"./Directions/components/SaveLayer.js";import{formatDistance as f,formatDuration as T}from"./Directions/support/directionsUtils.js";import{DepartureTimeOption as C,CSS as k,getIconPath as I}from"./Directions/support/resources.js";import{isArcGISWorldGeocoder as D,meteredArcGISLocatorUrl as P}from"./Search/support/locatorUtils.js";import L from"./support/DatePicker.js";import{Heading as R,incrementHeadingLevel as B}from"./support/Heading.js";import A from"./support/TimePicker.js";import{accessibleHandler as H}from"./support/decorators/accessibleHandler.js";import{messageBundle as j}from"./support/decorators/messageBundle.js";import{tsx as E}from"./support/jsxFactory.js";import"./support/widgetUtils.js";import x from"sortablejs";import{formatNumber as O}from"../intl/number.js";import{formatDate as U,convertDateFormatToIntlOptions as z}from"../intl/date.js";const $={departureTime:!0,layerDetails:!0,printButton:!1,saveAsButton:!0,saveButton:!0,stops:!0,traveMode:!0};function F(e){const t=e.getTimezoneOffset(),s=t>0?"-":"+",r=60,i=Math.abs(Math.floor(t/r)),o=Math.abs(Math.floor(t)%r),n={minimumIntegerDigits:2};return`GMT${s}${O(i,n)}${O(o,n)}`}function N(e){return!!e.composedPath?.().find((e=>e.classList?.contains("esri-search__suggestions-list")))}const q="search-term",K="date-time-picker",V=100,W=500,G="esri.widgets.Directions",Y=i.getLogger(G);let J=class extends w{constructor(e,t){super(e,t),this._autoStopRemovalDelay=V,this._departureTimeOption=C.NOW,this._datePicker=new L,this._newPlaceholderStop=null,this._pointerPressedSearchSuggestionStop=null,this._renderSavePopoverFunction=null,this._saveAsButtonNode=null,this._saveLayer=new b,this._sections=null,this._stopsToSearches=new Map,this._timePicker=new A,this.headingLevel=2,this.iconClass=k.widgetIcon,this.messages=null,this.messagesCommon=null,this.messagesUnits=null,this.searchProperties=null,this.viewModel=new M,this.visibleElements={...$},this._setUpDragAndDropStops=e=>{this._sortable=x.create(e,{draggable:`.${k.validStopRow}`,ghostClass:k.stopRowGhost,handle:`.${k.stopHandle}`,onEnd:this._handleStopInputDragEnd})},this._handleDragHandlePointerDown=()=>this.viewModel.layer.stops.forEach((e=>this._acquireSearch(e).activeMenu="none")),this._handleStopInputDragEnd=({oldIndex:e,newIndex:t,target:s})=>{if(e===t)return;const{children:r}=s,i=r[t],o=r[e],n=t-e<0;s.insertBefore(i,n?o.nextElementSibling:o);const a=this.viewModel.layer.stops;a.reorder(a.getItemAt(e),t);for(const l of a)l.sequence=null;this._getDirections()}}initialize(){this.addHandles([c((()=>this.viewModel.layer.routeInfo),(()=>{this._activeManeuver=null,this._focusedManeuver=null,this._sections=this._getSections(),this.scheduleRender()}),d),h((()=>this.view),((e,t)=>{if(t&&(this._viewClickHandle=null,this.removeHandles(t)),e){const t=this._prepPointerDownUpClick(),r=this._prepViewClick();t.pause(),r.pause(),this.addHandles([s(e.surface,"mousedown",(()=>this._autoStopRemovalDelay=W)),s(e.surface,"mouseup",(()=>this._autoStopRemovalDelay=V)),t,r],e),this._pointerDownUpHandle=t,this._viewClickHandle=r}}),d),h((()=>o(this.viewModel.serviceDescription)),(()=>{try{this.viewModel.load()}catch{}}),d),c((()=>this._saveLayer.state),(()=>{this.scheduleRender()}))]),this.when((()=>{this.destroyed||(this._renderSavePopoverFunction=this._renderSavePopover.bind(this),this._projector.append(document.body,this._renderSavePopoverFunction))}))}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-button.js"),import("@esri/calcite-components/dist/components/calcite-link.js"),import("@esri/calcite-components/dist/components/calcite-popover.js")])}destroy(){this._datePicker.destroy(),this._timePicker.destroy();for(const e of this._stopsToSearches.values())e.destroy();this._sortable&&this._sortable.destroy(),n(this._renderSavePopoverFunction)&&this._projector.detach(this._renderSavePopoverFunction)}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 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}set routeServiceUrl(e){t(Y,"routeServiceUrl",{replacement:"viewModel.layer.url",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.url=e}get routeServiceUrl(){return t(Y,"routeServiceUrl",{replacement:"viewModel.layer.url",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.url}set routeSymbol(e){t(Y,"routeSymbol",{replacement:"viewModel.layer.defaultSymbols.directionLines",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.directionLines=e}get routeSymbol(){return t(Y,"routeSymbol",{replacement:"viewModel.layer.defaultSymbols.directionLines",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.directionLines}set stopSymbols(e){t(Y,"stopSymbols",{replacement:"viewModel.layer.defaultSymbols.stops",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.stops=e}get stopSymbols(){return t(Y,"stopSymbols",{replacement:"viewModel.layer.defaultSymbols.stops",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.stops}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}castVisibleElements(e){return{...$,...e}}getDirections(){return this.viewModel.getDirections()}render(){return E("div",{class:this.classes(k.base,k.scroller)},this._renderPanelContent())}save(){return this.viewModel.layer.save()}saveAs(e,t={}){return this.viewModel.layer.saveAs(e,t)}zoomToRoute(){return this.viewModel.zoomToRoute()}_renderPanelContent(){const{viewModel:{serviceDescription:e,state:t}}=this,s="initializing"===t,r="error"===t&&!e,i="unauthenticated"===t,o={[k.panelContentLoading]:s,[k.panelContentError]:r,[k.panelContentSignIn]:i},n=s?"presentation":"group",a=i?this._renderSignIn():r?this._renderMessage(this._getErrorMessage()):s?this._renderLoader():this._renderReadyContent();return E("div",{class:this.classes(k.panelContent,o),role:n},a)}_renderReadyContent(){return[this._renderStopsContainer(),this._renderTravelModeOptions(),this._renderDepartureTimeControls(),this._renderSaveContainer(),this._renderSectionSplitter(),this._renderDirectionsContainer()]}_renderSignIn(){return E("div",{key:"sign-in",class:k.signInContent},E(R,{class:k.contentTitle,level:this.headingLevel},this.messages.widgetLabel),this._renderPlaceholder(),E(R,{level:B(this.headingLevel)},this.messages.signInRequired),E("button",{class:this.classes(k.button,k.buttonSecondary,k.signInButton),tabIndex:0,onclick:this._handleSignInClick,bind:this,type:"button"},this.messagesCommon.auth.signIn))}_handleSignInClick(){this.viewModel.load().catch((()=>{}))}_renderTravelModeOptions(){if(!this.visibleElements.traveMode)return null;const{selectedTravelMode:e,travelModes:t}=this.viewModel;if(0===t.length)return null;const s=n(e)?e.name:this.messages.travelMode;return E("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(k.travelMode,this._saveLayer.opened&&k.buttonDisabled),key:"esri-directions__travel-mode-controls",role:"group"},E("select",{"aria-label":s,bind:this,class:this.classes(k.travelModeSelect,k.select),key:"esri-directions__travel-mode-options",onchange:this._handleTravelModeChange,title:s},t.map(((t,s)=>E("option",{key:`esri-directions__travel-mode-${s}`,"data-mode":t,selected:e===t,value:`${s}`},t.name)))))}_handleTravelModeChange(e){const t=e.currentTarget,s=t.item(t.selectedIndex);this.viewModel.selectedTravelMode=s["data-mode"],this._getDirections()}_renderStopsContainer(){return this.visibleElements.stops?E("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(k.section,this._saveLayer.opened&&k.buttonDisabled),key:"esri-directions__stops-container",role:"group"},this._renderStops()):null}_renderDepartureTimeControls(){if(!this.visibleElements.departureTime)return null;const{messages:{departAt:e,departureTime:t,leaveNow:s,timeUnspecified:r}}=this;return E("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(k.departureTime,this._saveLayer.opened&&k.buttonDisabled),key:"esri-directions__departure-time-controls",role:"group"},E("select",{"aria-label":t,bind:this,class:this.classes(k.departureTimeSelect,k.select),onchange:this._handleDepartureOptionChange,title:t},E("option",{value:C.NOW,selected:this._departureTimeOption===C.NOW},s),E("option",{value:C.DEPART_AT,selected:this._departureTimeOption===C.DEPART_AT},e),E("option",{value:C.UNSPECIFIED,selected:this._departureTimeOption===C.UNSPECIFIED},r)),this._departureTimeOption===C.DEPART_AT?this._renderTimeControls():null)}_renderStops(){const e=this.viewModel.layer.stops;let t=0;for(const i of this._stopsToSearches.keys())e.includes(i)||this._disposeSearch(i);for(const i of e){const e=this._acquireSearch(i);"none"!==e.activeMenu&&(t+=1),n(i.name)&&(e.searchTerm=i.name)}const s=e.toArray().map(((s,r)=>{const i=e.length,a=r>1&&o(s.geometry),l={[k.stopsIcon]:r>=0&&r<i-1,[k.lastStopIcon]:r===i-1},c={[k.lastStopIconContainer]:r===i-1},d={[k.validStopRow]:!a},h=e.getItemAt(r+1),u=h&&n(h.geometry),p=r===i-1,v=r===i-2,m=2===i&&0===r||i>2&&!p&&!v||i>2&&v&&u||i>2&&p&&o(s.geometry),_=i<3,g=this._acquireSearch(s),{messages:y}=this,{removeStop:S,reverseStops:w,unlocated:M}=y,b=n(s.geometry)&&n(s.name)?s.name:M,f=O(r+1),T=`${y.stopLabel} ${f} (${b})`,C=`${this.id}__stop--${r}`,I=!!g.searchTerm&&!!g.selectedResult&&n(s.geometry)&&g.selectedResult.name===s.name,D={zIndex:"none"!==g.activeMenu?""+t--:""};return E("li",{"aria-label":T,afterCreate:this._handleStopFieldCreation,bind:this,class:this.classes(k.stopRow,d),id:C,key:r,"data-stop-index":r,styles:D},E("div",{class:k.stopHandle},E("span",{"aria-hidden":"true",class:this.classes(k.stopIcon,k.handleIcon,k.stopHandleIcon,k.interactiveStopIcon),onpointerdown:this._handleDragHandlePointerDown}),E("div",{bind:this,"aria-labelledby":C,class:this.classes(k.stopIconContainer,c),"data-stop-index":r,onclick:this._handleStopIconClick,onkeydown:this._handleStopIconClick,role:"button"},E("span",{class:this.classes(k.stopIcon,l),tabindex:I?"0":null}))),E("div",{class:k.stopInput},g.render()),E("div",{class:k.stopOptions,role:"group"},E("div",{"aria-label":S,class:k.removeStopButton,bind:this,"data-stop-index":r,hidden:_,onkeydown:this._handleRemoveStop,onclick:this._handleRemoveStop,role:"button",tabIndex:0,title:S},E("span",{"aria-hidden":"true",class:this.classes(k.stopIcon,k.removeStop,k.removeStopIcon,k.interactiveStopIcon)}),E("span",{class:k.screenReaderText},"removeStopTitle")),E("div",{"aria-label":w,class:k.reverseStops,bind:this,hidden:m,onkeydown:this._handleReverseStops,onclick:this._handleReverseStops,role:"button",tabIndex:0,title:w},E("span",{"aria-hidden":"true",class:this.classes(k.stopIcon,k.reverseStopIcon,k.interactiveStopIcon)}),E("span",{class:k.screenReaderText},"removeStopTitle"))))})),r=this._renderAddStop();return E("div",null,E("ol",{class:k.stops,role:"group",afterCreate:this._setUpDragAndDropStops},s),r)}_renderAddStop(){const{stops:e}=this.viewModel.layer,t=e.filter((({geometry:e})=>n(e))),s=e.at(-1);return t.length>1&&t.length<this.maxStops&&n(s)&&n(s.geometry)?E("div",{class:k.toolbarSection},E("div",{class:k.toolbarButtons},E("calcite-button",{appearance:"outline",class:k.addStopButton,kind:"neutral",scale:"s",round:!0,"icon-start":"plus",key:k.addStopButton,onclick:()=>{this._addNewPlaceholder()},label:this.messages.addStop,width:"full"},this.messages.addStop))):null}_handleStopIconClick(e){const t=e.currentTarget["data-stop-index"],s=this.viewModel.layer.stops.getItemAt(t);s&&n(s.geometry)&&this._centerAtStop(s)}_handleClearRouteClick(){this.viewModel.reset()}_centerAtStop(e){this.viewModel.centerAt(e)}_handleStopFieldCreation(e){const t=this._newPlaceholderStop;if(!t)return;const s=e["data-stop-index"],r=this.viewModel.layer.stops.getItemAt(s);if(t===r){const e=this._acquireSearch(r);e.when((()=>{this.renderNow(),e.focus()}))}this._newPlaceholderStop=null}_handleStopInputBlur(e,t){if(this._saveLayer.opened)return;this.removeHandles(q);if(!!e.selectedResult&&n(t.geometry)&&n(e.selectedResult?.feature.geometry)&&t.geometry===e.selectedResult?.feature.geometry)return void this._pointerDownUpHandle.pause();const s=o(t.geometry)&&o(e.selectedResult?.feature.geometry),r=n(t.geometry)&&n(e.selectedResult?.feature.geometry)&&t.geometry!==e.selectedResult.feature.geometry;if((s||r)&&"none"===e.activeMenu&&e.searchTerm)return e.search(),void this._pointerDownUpHandle.pause();e.searchTerm||(this._viewClickHandle.resume(),clearTimeout(this._autoStopRemovalTimeoutId),this._autoStopRemovalTimeoutId=setTimeout((()=>{this.destroyed||(this._viewClickHandle.pause(),"searching"!==e.viewModel.state?this._pointerPressedSearchSuggestionStop||(n(t.geometry)&&(t.geometry=null,this._getDirections()),this.scheduleRender()):this._pointerDownUpHandle.pause())}),this._autoStopRemovalDelay))}_handleStopInputFocus(e,t){if(this._pointerDownUpHandle.resume(),this.hasHandles(q))return;const{view:s}=this,r=s.cursor;this.addHandles([{remove(){s.cursor=r}},c((()=>e.searchTerm),(t=>{e.destroyed||(s.cursor=t.length?r:"copy")}),d)],q),this._activeStop=t}_prepViewClick(){const{view:e}=this.viewModel,t=r(e,"click",this._handleViewClick.bind(this)),s=r(e.surface,"click",(()=>{clearTimeout(this._autoStopRemovalTimeoutId),s.pause()}));return{remove(){s.remove(),t.remove()},pause(){s.pause(),t.pause()},resume(){s.resume(),t.resume()}}}_prepPointerDownUpClick(){const e=r(document,"pointerdown",(e=>{this._pointerPressedSearchSuggestionStop=N(e)?this._activeStop:null})),t=r(document,"pointerup",(e=>{this._pointerDownUpHandle.pause();const t=N(e),s=this._activeStop;t||s!==this._pointerPressedSearchSuggestionStop||this._removeStop(s),this.scheduleRender(),this._pointerPressedSearchSuggestionStop=t?s:null}));return{remove(){t.remove(),e.remove()},pause(){t.pause(),e.pause()},resume(){e.resume()}}}_handleViewClick(e){e.stopPropagation();const t=this._stopsToSearches.get(this._activeStop);t&&!t.searchTerm&&(t.search(e.mapPoint).then((e=>{const s=e.results[0].results[0],{feature:r,name:i}=s;this._activeStop.geometry=r.geometry,this._activeStop.name=i,t.searchTerm=i})),this.scheduleRender()),this._viewClickHandle.pause(),clearTimeout(this._autoStopRemovalTimeoutId)}_addNewPlaceholder(){if(this._pointerDownUpHandle.pause(),this._newPlaceholderStop)return;const e=new g({symbol:new y});this.viewModel.layer.stops.add(e),this._newPlaceholderStop=e}_handleReverseStops(){this._reverseStops()}_reverseStops(){this.viewModel.layer.stops.reverse();for(const e of this.viewModel.layer.stops)e.sequence=null;this._getDirections()}_handleRemoveStop(e){const t=e.currentTarget["data-stop-index"],s=this.viewModel.layer.stops.getItemAt(t);this._removeStop(s),(n(s.geometry)||o(this.viewModel.layer.routeInfo))&&this._getDirections()}_removeStop(e){this.viewModel.layer.stops.length<=2||(this._disposeSearch(e),this.viewModel.layer.stops.remove(e))}_handleDepartureOptionChange(e){const t=e.currentTarget,s=t.item(t.selectedIndex);s.value===C.NOW?(this._departureTimeOption=C.NOW,this.viewModel.departureTime=C.NOW,this.removeHandles(K),this._getDirections()):s.value===C.DEPART_AT?(this._departureTimeOption=C.DEPART_AT,this.addHandles(c((()=>[this._datePicker.value,this._timePicker.value]),(()=>{this._updateDepartureTime(),this._getDirections()}),d),K)):(this._departureTimeOption=C.UNSPECIFIED,this.viewModel.departureTime=null,this._getDirections())}_updateDepartureTime(){const e=this._datePicker.value,t=this._timePicker.value;e&&t&&(this.viewModel.departureTime=new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes()))}_renderTimeControls(){return E("div",{class:k.departureTimeControls,key:"esri-directions__time-controls",role:"group"},this._datePicker.render(),this._timePicker.render())}_renderSectionSplitter(){return E("div",{class:k.sectionSplitter})}_renderSaveContainer(){const{saveButton:e,saveAsButton:t,printButton:s,layerDetails:r}=this.visibleElements;return e||t||s||r?E("div",{class:k.saveSection,key:k.saveSection},this._renderSaveButtons(),this._renderRouteLayerDetailsLink()):null}_renderSaveButtons(){const{saveButton:e,saveAsButton:t,printButton:s}=this.visibleElements;return e||t||s?E("div",{class:k.saveButtons,key:k.saveButtons},this._renderSaveButton(),this._renderSaveAsButton(),this._renderPrintButton()):null}_renderSaveButton(){if(!this.visibleElements.saveButton)return null;const e=this.viewModel.layer.portalItem?.itemControl,t=n(this.viewModel.layer.routeInfo)&&("admin"===e||"update"===e);return E("calcite-button",{appearance:"outline",class:k.saveButton,disabled:!t,"icon-start":"save",key:k.saveButton,onclick:()=>{this._handleSaveButtonClick()},label:this.messagesCommon.save,width:"full"},this.messagesCommon.save)}_renderSaveAsButton(){if(!this.visibleElements.saveAsButton)return null;const e=o(this.viewModel.layer.routeInfo);return E("div",{class:k.saveAsButtonPopover,key:k.saveAsButtonPopover},E("calcite-button",{afterCreate:e=>{this._saveAsButtonNode=e},appearance:"outline",class:k.saveAsButton,disabled:e,"icon-start":"duplicate",key:k.saveAsButton,onclick:()=>this._handleSaveAsButtonClick(),label:this.messagesCommon.saveAs,width:"full"},this.messagesCommon.saveAs))}_renderSavePopover(){return E("calcite-popover",{label:this._saveLayer.label,open:this._saveLayer.opened,"overlay-positioning":"fixed",referenceElement:a(this._saveAsButtonNode)},this._saveLayer.render())}_handleSaveAsButtonClick(){this._saveLayer.opened?this._saveLayer.close():this._saveLayer.open(this.viewModel.layer)}_renderPrintButton(){return this.visibleElements.printButton?E("calcite-button",{appearance:"outline",class:k.printButton,"icon-start":"print",key:k.printButton,label:this.messagesCommon.print}):null}_renderRouteLayerDetailsLink(){if(!this.visibleElements.layerDetails)return null;const{portalItem:e}=this.viewModel.layer;if(!e)return null;const{id:t,portal:{url:s}}=e,r=`${s}/home/item.html?id=${t}`;return E("calcite-link",{class:k.layerDetailsLink,href:r,key:k.layerDetailsLink,target:"_blank"},this.messages.viewLayerDetails)}_handleSaveButtonClick(){this.viewModel.layer.save()}_renderDirectionsContainer(){return E("div",{class:this.classes(k.directionsSection,k.section),key:"esri-directions__container"},this._renderDirectionsContainerContent())}_renderLoader(){return E("div",{class:k.loader,key:"loader"})}_renderWarningCard(){return E("div",{class:k.warningCard,role:"alert"},E("div",{class:k.warningHeader},E("span",{class:k.warningIcon,"aria-hidden":"true"}),E(R,{class:k.warningHeading,level:this.headingLevel},this.messagesCommon.warning)),E("div",{class:k.warningMessage},this._getErrorMessage()))}_renderDirectionsContainerContent(){const{viewModel:{layer:e,state:t}}=this,s="routing"===t;return"error"===t?this._renderWarningCard():s?this._renderLoader():n(e.directionLines)?E("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(k.summary,this._saveLayer.opened&&k.buttonDisabled),key:"esri-directions__summary",role:"group"},this._renderCosts(),this._renderRouteActions(),this._renderManeuverSections()):E("div",{key:"esri-directions__placeholder",class:k.emptyContent},this._renderPlaceholder(),E(R,{class:k.message,level:this.headingLevel},this.messages.directionsPlaceholder))}_renderPlaceholder(){return E("svg",{class:k.emptyIllustration,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256"},E("path",{fill:"currentcolor",d:"M192 36c-15.477 0-24 6.034-24 16.99v45.822l24 24 24-24v-45.82C216 42.033 207.477 36 192 36zm20 61.155l-20 20-20-20V52.99c0-8.62 6.73-12.99 20-12.99s20 4.37 20 12.99zM192 52a12 12 0 1 0 12 12 12.013 12.013 0 0 0-12-12zm0 20a8 8 0 1 1 8-8 8.008 8.008 0 0 1-8 8zM92 140.99C92 130.035 83.477 124 68 124s-24 6.034-24 16.99v45.822l24 24 24-24zm-4 44.165l-20 20-20-20V140.99c0-8.62 6.73-12.99 20-12.99s20 4.37 20 12.99zM68 140a12 12 0 1 0 12 12 12.013 12.013 0 0 0-12-12zm0 20a8 8 0 1 1 8-8 8.008 8.008 0 0 1-8 8zm84-44h16v4h-16zm-24 80h4v12h-12v-4h8zm0-28h4v16h-4zm0-52h12v4h-8v8h-4zm0 24h4v16h-4zm-36 64h16v4H92z"}))}_renderMessage(e){return E(R,{level:this.headingLevel},e)}_renderRouteActions(){return E("div",{class:k.routeActions},E("button",{"aria-label":this.messages.clearRoute,class:this.classes(k.clearRouteButton,k.button,k.buttonTertiary),tabIndex:0,onclick:this._handleClearRouteClick,bind:this,type:"button"},this.messages.clearRoute))}_getSections(){const{directionPoints:e,directionLines:t,stops:s}=this.viewModel.layer;if(o(e)||o(t))return null;const r=[];let i=null;for(const a of e){const{objectId:e,stopId:l}=a;if(n(l)){const e=s.find((e=>e.objectId===l)),t=0===r.length;(o(i)||i.stop!==e)&&(i={stop:e,directions:[],open:t},r.push(i));continue}if(o(i))continue;const c=t.find((t=>t.directionPointId===e));o(c)||i.directions.push({directionPoint:a,directionLine:c})}return r}_renderManeuverSections(){return o(this._sections)?null:E("div",{class:k.maneuvers,role:"group"},this._sections.map(((e,t)=>{const{open:s}=e;let r;e.directions.length>0&&s&&(r=E("ol",{class:k.maneuverList},e.directions.map((e=>this._renderManeuver(e)))));const i=a(this._sections).length>2,o=t===a(this._sections).length-1,n={[k.collapsibleSection]:i},l={[k.openIcon]:!s,[k.closeIcon]:s};let c;if(i&&!o){const t=s?this.messagesCommon.close:this.messagesCommon.open;c=E("header",{class:this.classes(k.maneuverSectionHeader,k.maneuverSectionToggle),key:k.maneuverSectionHeader},E("div",{"aria-expanded":s.toString(),"aria-label":t,bind:this,class:k.maneuverSectionHeaderButton,"data-maneuver-section":e,onkeydown:this._handleSectionToggle,onclick:this._handleSectionToggle,role:"button",tabIndex:0,title:t},E(R,{class:k.maneuverSectionTitle,level:this.headingLevel},e.stop.name),E("span",{"aria-hidden":"true",class:this.classes(l)})))}else c=E("header",{class:k.maneuverSectionHeader,key:k.maneuverSectionHeader},E(R,{class:k.maneuverSectionTitle,level:this.headingLevel},e.stop.name));return E("section",{class:this.classes(k.maneuverSection,n),key:t},c,r)})))}_handleSectionToggle(e){const t=e.currentTarget["data-maneuver-section"];t.open=!t.open}_renderCosts(){const e=this._getCostSummary(),{directionPoints:t}=this.viewModel.layer;if(o(t)||o(e))return null;const s=t.getItemAt(t.length-1).arrivalTime,{distance:r,duration:i}=e,{eta:a,primaryCosts:l,secondaryCosts:c,zoomToRoute:d}=this.messages,h=z("short-time"),u=n(s)?`<strong>${U(s,h)}</strong> ${F(s)}`:"";return E("div",{"aria-label":d,bind:this,class:k.directionCosts,onkeydown:this._handleSummaryInteraction,onclick:this._handleSummaryInteraction,role:"button",tabIndex:0,title:d},E("div",{class:k.costsDetails,role:"group"},E("div",{class:k.primaryCosts,title:l},i),E("div",{class:k.verticalSplitter}),E("div",{class:k.secondaryCosts,title:c},r)),E("div",{innerHTML:u,title:a}))}_handleSummaryInteraction(){this._activeManeuver=null,this._focusedManeuver=null,this.viewModel.clearHighlights(),this.zoomToRoute()}_getErrorMessage(){const{messages:e,viewModel:{lastError:t}}=this;if(n(t))switch(t.name){case"directions-view-model:unable-to-route":return e.errors.unableToRoute;case"directions-view-model:service-metadata-unavailable":return e.errors.unableToLoadServiceMetadata}return e.errors.unknownError}_normalizeSearchSources(e){this._overrideDefaultSources(e),this._applyLocatorSourceOverrides(e)}_overrideDefaultSources(e){e.viewModel.defaultSources.forEach((e=>{e.autoNavigate=!1}))}_applyLocatorSourceOverrides({allSources:e}){for(const t of e)"url"in t&&t.url&&(t.locationType??(t.locationType="street"),D(t.url)&&this.apiKey&&null==t.apiKey&&(t.apiKey=this.apiKey,t.url=P))}_acquireSearch(e){const{view:t}=this.viewModel;if(this._stopsToSearches.has(e)){const s=this._stopsToSearches.get(e);return s.view=t,this._overrideDefaultSources(s),s}const s=new S({view:t,resultGraphicEnabled:!1,popupEnabled:!1,...this.searchProperties});return this._normalizeSearchSources(s),this.addHandles([u((()=>s.allSources),"change",(()=>this._normalizeSearchSources(s))),s.on("select-result",(()=>{e.geometry=s.selectedResult.feature.geometry,e.name=s.selectedResult.name,this._getDirections()})),s.on("search-focus",(()=>this._handleStopInputFocus(s,e))),s.on("search-blur",(()=>this._handleStopInputBlur(s,e))),s.on("search-clear",(()=>{e.geometry=null,e.name=null,this._activeStop=e,this.viewModel.layer.removeResult()})),c((()=>s.searchTerm),(t=>{e.name=t}))],s),this._stopsToSearches.set(e,s),s}_disposeSearch(e){if(this._stopsToSearches.has(e)){const t=this._stopsToSearches.get(e);this.removeHandles(t),t.destroy(),this._stopsToSearches.delete(e)}}_renderManeuver(e){const{directionPoint:t,directionLine:s}=e,{distance:r,duration:i}=s,{messages:o,messagesUnits:a,unit:c}=this,d=f(a,l(r,0),c),h=T(l(i,0)),u=d&&h?`${d} · ${h}`:`${d}${h}`,p=this._getFormattedManeuverText(t),{objectId:v,directionPointType:m}=t,_=I(m),g=`esri-directions__maneuver-${v}`,y=`esri-directions__intermediate-costs-${v}`,S={[k.maneuverActive]:this._activeManeuver===s};return E("li",{"aria-labelledby":`${g} ${y}`,bind:this,class:this.classes(k.maneuver,S),"data-maneuver":s,key:s,onclick:this._handleManeuverClick,onkeydown:this._handleManeuverClick,onfocus:this._handleManeuverFocus,onmouseover:this._handleManeuverMouseOver,onmouseout:this._handleManeuverMouseOut,onblur:this._handleManeuverBlur,tabIndex:0},n(_)&&E("img",{alt:"",class:k.maneuverIcon,src:_}),E("div",{class:k.maneuverCostsContainer},E("span",{id:g,innerHTML:l(p,"")}),E("div",{class:k.maneuverCosts},E("div",{class:k.horizontalSplitter}),E("div",{"aria-hidden":"true",id:y,class:k.intermediateCost,innerHTML:u,title:o.intermediateCosts}))))}_handleManeuverClick(e){const t=e.currentTarget["data-maneuver"];if(this._activeManeuver===t)return this._activeManeuver=null,void this.zoomToRoute();this._activeManeuver=t;const{geometry:s}=t;this.viewModel.centerAt(s),this.viewModel.highlight(t)}_handleManeuverMouseOver(e){if(this._activeManeuver||this._focusedManeuver)return;const t=e.currentTarget["data-maneuver"];this.viewModel.highlight(t)}_handleManeuverMouseOut(){this._activeManeuver||this._focusedManeuver||this.viewModel.clearHighlights()}_handleManeuverBlur(){this._activeManeuver||(this._focusedManeuver=null,this.viewModel.clearHighlights())}_handleManeuverFocus(e){if(this._activeManeuver)return;const t=e.currentTarget["data-maneuver"];this._focusedManeuver=t,this.viewModel.highlight(t)}_getFormattedManeuverText(e){const{displayText:t,name:s,intersectingName:r}=e;if(o(t))return"";let i=t;return n(s)&&i.includes(s)&&(i=i.replace(s,`<strong>${s}</strong>`)),n(r)&&i.includes(r)&&(i=i.replace(r,`<strong>${r}</strong>`)),i}_getCostSummary(){const{messagesUnits:e,unit:t,viewModel:s}=this,{routeInfo:r}=s.layer;if(o(r))return null;const i=l(r.totalDistance,0),n=l(r.totalDuration,0);return{distance:f(e,i,t),duration:T(n)}}async _getDirections(){if(!(this.viewModel.layer.stops.filter((e=>n(e.geometry))).length<2))try{await this.viewModel.getDirections()}catch{}}get test(){return{projector:this._projector,acquireSearch:e=>this._acquireSearch(e)}}};e([p()],J.prototype,"apiKey",null),e([p(_)],J.prototype,"defaultUnit",void 0),e([p()],J.prototype,"goToOverride",null),e([p()],J.prototype,"headingLevel",void 0),e([p()],J.prototype,"iconClass",void 0),e([p()],J.prototype,"label",null),e([p({readOnly:!0})],J.prototype,"lastRoute",null),e([p()],J.prototype,"layer",null),e([p()],J.prototype,"maxStops",null),e([p(),j("esri/widgets/Directions/t9n/Directions")],J.prototype,"messages",void 0),e([p(),j("esri/t9n/common")],J.prototype,"messagesCommon",void 0),e([p(),j("esri/core/t9n/Units")],J.prototype,"messagesUnits",void 0),e([p()],J.prototype,"routeServiceUrl",null),e([p()],J.prototype,"routeSymbol",null),e([p()],J.prototype,"searchProperties",void 0),e([p()],J.prototype,"stopSymbols",null),e([p()],J.prototype,"unit",null),e([p()],J.prototype,"view",null),e([p({type:M})],J.prototype,"viewModel",void 0),e([p()],J.prototype,"visibleElements",void 0),e([v("visibleElements")],J.prototype,"castVisibleElements",null),e([H()],J.prototype,"_handleStopIconClick",null),e([H()],J.prototype,"_handleClearRouteClick",null),e([H()],J.prototype,"_handleReverseStops",null),e([H()],J.prototype,"_handleRemoveStop",null),e([H()],J.prototype,"_handleSectionToggle",null),e([H()],J.prototype,"_handleSummaryInteraction",null),e([H()],J.prototype,"_handleManeuverClick",null),J=e([m(G)],J);const Q=J;export{Q as default};
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{deprecatedProperty as t}from"../core/deprecate.js";import{on as s,pausable as r}from"../core/events.js";import i from"../core/Logger.js";import{isNone as o,isSome as n,unwrap as a,unwrapOrValue as l}from"../core/maybe.js";import{watch as c,initial as d,when as h,on as u}from"../core/reactiveUtils.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import{cast as v}from"../core/accessorSupport/decorators/cast.js";import"../core/arrayUtils.js";import{subclass as m}from"../core/accessorSupport/decorators/subclass.js";import{defaultUnitPropertyMetadata as _}from"../properties/defaultUnit.js";import g from"../rest/support/Stop.js";import y from"../symbols/SimpleMarkerSymbol.js";import S from"./Search.js";import w from"./Widget.js";import M from"./Directions/DirectionsViewModel.js";import{SaveLayer as b}from"./Directions/components/SaveLayer.js";import{formatDistance as f,formatDuration as T}from"./Directions/support/directionsUtils.js";import{DepartureTimeOption as C,CSS as k,getIconPath as I}from"./Directions/support/resources.js";import{isArcGISWorldGeocoder as D,meteredArcGISLocatorUrl as P}from"./Search/support/locatorUtils.js";import L from"./support/DatePicker.js";import{Heading as R,incrementHeadingLevel as B}from"./support/Heading.js";import A from"./support/TimePicker.js";import{accessibleHandler as H}from"./support/decorators/accessibleHandler.js";import{messageBundle as j}from"./support/decorators/messageBundle.js";import{tsx as E}from"./support/jsxFactory.js";import"./support/widgetUtils.js";import x from"sortablejs";import{formatNumber as O}from"../intl/number.js";import{formatDate as U,convertDateFormatToIntlOptions as z}from"../intl/date.js";const $={departureTime:!0,layerDetails:!0,printButton:!1,saveAsButton:!0,saveButton:!0,stops:!0,traveMode:!0};function F(e){const t=e.getTimezoneOffset(),s=t>0?"-":"+",r=60,i=Math.abs(Math.floor(t/r)),o=Math.abs(Math.floor(t)%r),n={minimumIntegerDigits:2};return`GMT${s}${O(i,n)}${O(o,n)}`}function N(e){return!!e.composedPath?.().find((e=>e.classList?.contains("esri-search__suggestions-list")))}const q="search-term",K="date-time-picker",V=100,W=500,G="esri.widgets.Directions",Y=i.getLogger(G);let J=class extends w{constructor(e,t){super(e,t),this._autoStopRemovalDelay=V,this._departureTimeOption=C.NOW,this._datePicker=new L,this._newPlaceholderStop=null,this._pointerPressedSearchSuggestionStop=null,this._renderSavePopoverFunction=null,this._saveAsButtonNode=null,this._saveLayer=new b,this._sections=null,this._stopsToSearches=new Map,this._timePicker=new A,this.headingLevel=2,this.iconClass=k.widgetIcon,this.messages=null,this.messagesCommon=null,this.messagesUnits=null,this.searchProperties=null,this.viewModel=new M,this.visibleElements={...$},this._setUpDragAndDropStops=e=>{this._sortable=x.create(e,{draggable:`.${k.validStopRow}`,ghostClass:k.stopRowGhost,handle:`.${k.stopHandle}`,onEnd:this._handleStopInputDragEnd})},this._handleDragHandlePointerDown=()=>this.viewModel.layer.stops.forEach((e=>this._acquireSearch(e).activeMenu="none")),this._handleStopInputDragEnd=({oldIndex:e,newIndex:t,target:s})=>{if(e===t)return;const{children:r}=s,i=r[t],o=r[e],n=t-e<0;s.insertBefore(i,n?o.nextElementSibling:o);const a=this.viewModel.layer.stops;a.reorder(a.getItemAt(e),t);for(const l of a)l.sequence=null;this._getDirections()}}initialize(){this.addHandles([c((()=>this.viewModel.layer.routeInfo),(()=>{this._activeManeuver=null,this._focusedManeuver=null,this._sections=this._getSections(),this.scheduleRender()}),d),h((()=>this.view),((e,t)=>{if(t&&(this._viewClickHandle=null,this.removeHandles(t)),e){const t=this._prepPointerDownUpClick(),r=this._prepViewClick();t.pause(),r.pause(),this.addHandles([s(e.surface,"mousedown",(()=>this._autoStopRemovalDelay=W)),s(e.surface,"mouseup",(()=>this._autoStopRemovalDelay=V)),t,r],e),this._pointerDownUpHandle=t,this._viewClickHandle=r}}),d),h((()=>o(this.viewModel.serviceDescription)),(()=>{try{this.viewModel.load()}catch{}}),d),c((()=>this._saveLayer.state),(()=>{this.scheduleRender()}))]),this.when((()=>{this.destroyed||(this._renderSavePopoverFunction=this._renderSavePopover.bind(this),this._projector.append(document.body,this._renderSavePopoverFunction))}))}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-button.js"),import("@esri/calcite-components/dist/components/calcite-link.js"),import("@esri/calcite-components/dist/components/calcite-popover.js")])}destroy(){this._datePicker.destroy(),this._timePicker.destroy();for(const e of this._stopsToSearches.values())e.destroy();this._sortable&&this._sortable.destroy(),n(this._renderSavePopoverFunction)&&this._projector.detach(this._renderSavePopoverFunction)}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 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}set routeServiceUrl(e){t(Y,"routeServiceUrl",{replacement:"viewModel.layer.url",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.url=e}get routeServiceUrl(){return t(Y,"routeServiceUrl",{replacement:"viewModel.layer.url",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.url}set routeSymbol(e){t(Y,"routeSymbol",{replacement:"viewModel.layer.defaultSymbols.directionLines",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.directionLines=e}get routeSymbol(){return t(Y,"routeSymbol",{replacement:"viewModel.layer.defaultSymbols.directionLines",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.directionLines}set stopSymbols(e){t(Y,"stopSymbols",{replacement:"viewModel.layer.defaultSymbols.stops",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.stops=e}get stopSymbols(){return t(Y,"stopSymbols",{replacement:"viewModel.layer.defaultSymbols.stops",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.stops}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}castVisibleElements(e){return{...$,...e}}getDirections(){return this.viewModel.getDirections()}render(){return E("div",{class:this.classes(k.base,k.scroller)},this._renderPanelContent())}save(){return this.viewModel.layer.save()}saveAs(e,t={}){return this.viewModel.layer.saveAs(e,t)}zoomToRoute(){return this.viewModel.zoomToRoute()}_renderPanelContent(){const{viewModel:{serviceDescription:e,state:t}}=this,s="initializing"===t,r="error"===t&&!e,i="unauthenticated"===t,o={[k.panelContentLoading]:s,[k.panelContentError]:r,[k.panelContentSignIn]:i},n=s?"presentation":"group",a=i?this._renderSignIn():r?this._renderMessage(this._getErrorMessage()):s?this._renderLoader():this._renderReadyContent();return E("div",{class:this.classes(k.panelContent,o),role:n},a)}_renderReadyContent(){return[this._renderStopsContainer(),this._renderTravelModeOptions(),this._renderDepartureTimeControls(),this._renderSaveContainer(),this._renderSectionSplitter(),this._renderDirectionsContainer()]}_renderSignIn(){return E("div",{key:"sign-in",class:k.signInContent},E(R,{class:k.contentTitle,level:this.headingLevel},this.messages.widgetLabel),this._renderPlaceholder(),E(R,{level:B(this.headingLevel)},this.messages.signInRequired),E("button",{class:this.classes(k.button,k.buttonSecondary,k.signInButton),tabIndex:0,onclick:this._handleSignInClick,bind:this,type:"button"},this.messagesCommon.auth.signIn))}_handleSignInClick(){this.viewModel.load().catch((()=>{}))}_renderTravelModeOptions(){if(!this.visibleElements.traveMode)return null;const{selectedTravelMode:e,travelModes:t}=this.viewModel;if(0===t.length)return null;const s=n(e)?e.name:this.messages.travelMode;return E("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(k.travelMode,this._saveLayer.opened&&k.buttonDisabled),key:"esri-directions__travel-mode-controls",role:"group"},E("select",{"aria-label":s,bind:this,class:this.classes(k.travelModeSelect,k.select),key:"esri-directions__travel-mode-options",onchange:this._handleTravelModeChange,title:s},t.map(((t,s)=>E("option",{key:`esri-directions__travel-mode-${s}`,"data-mode":t,selected:e===t,value:`${s}`},t.name)))))}_handleTravelModeChange(e){const t=e.currentTarget,s=t.item(t.selectedIndex);this.viewModel.selectedTravelMode=s["data-mode"],this._getDirections()}_renderStopsContainer(){return this.visibleElements.stops?E("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(k.section,this._saveLayer.opened&&k.buttonDisabled),key:"esri-directions__stops-container",role:"group"},this._renderStops()):null}_renderDepartureTimeControls(){if(!this.visibleElements.departureTime)return null;const{messages:{departAt:e,departureTime:t,leaveNow:s,timeUnspecified:r}}=this;return E("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(k.departureTime,this._saveLayer.opened&&k.buttonDisabled),key:"esri-directions__departure-time-controls",role:"group"},E("select",{"aria-label":t,bind:this,class:this.classes(k.departureTimeSelect,k.select),onchange:this._handleDepartureOptionChange,title:t},E("option",{value:C.NOW,selected:this._departureTimeOption===C.NOW},s),E("option",{value:C.DEPART_AT,selected:this._departureTimeOption===C.DEPART_AT},e),E("option",{value:C.UNSPECIFIED,selected:this._departureTimeOption===C.UNSPECIFIED},r)),this._departureTimeOption===C.DEPART_AT?this._renderTimeControls():null)}_renderStops(){const e=this.viewModel.layer.stops;let t=0;for(const i of this._stopsToSearches.keys())e.includes(i)||this._disposeSearch(i);for(const i of e){const e=this._acquireSearch(i);"none"!==e.activeMenu&&(t+=1),n(i.name)&&(e.searchTerm=i.name)}const s=e.toArray().map(((s,r)=>{const i=e.length,a=r>1&&o(s.geometry),l={[k.stopsIcon]:r>=0&&r<i-1,[k.lastStopIcon]:r===i-1},c={[k.lastStopIconContainer]:r===i-1},d={[k.validStopRow]:!a},h=e.getItemAt(r+1),u=h&&n(h.geometry),p=r===i-1,v=r===i-2,m=2===i&&0===r||i>2&&!p&&!v||i>2&&v&&u||i>2&&p&&o(s.geometry),_=i<3,g=this._acquireSearch(s),{messages:y}=this,{removeStop:S,reverseStops:w,unlocated:M}=y,b=n(s.geometry)&&n(s.name)?s.name:M,f=O(r+1),T=`${y.stopLabel} ${f} (${b})`,C=`${this.id}__stop--${r}`,I=!!g.searchTerm&&!!g.selectedResult&&n(s.geometry)&&g.selectedResult.name===s.name,D={zIndex:"none"!==g.activeMenu?""+t--:""};return E("li",{"aria-label":T,afterCreate:this._handleStopFieldCreation,bind:this,class:this.classes(k.stopRow,d),id:C,key:r,"data-stop-index":r,styles:D},E("div",{class:k.stopHandle},E("span",{"aria-hidden":"true",class:this.classes(k.stopIcon,k.handleIcon,k.stopHandleIcon,k.interactiveStopIcon),onpointerdown:this._handleDragHandlePointerDown}),E("div",{bind:this,"aria-labelledby":C,class:this.classes(k.stopIconContainer,c),"data-stop-index":r,onclick:this._handleStopIconClick,onkeydown:this._handleStopIconClick,role:"button"},E("span",{class:this.classes(k.stopIcon,l),tabindex:I?"0":null}))),E("div",{class:k.stopInput},g.render()),E("div",{class:k.stopOptions,role:"group"},E("div",{"aria-label":S,class:k.removeStopButton,bind:this,"data-stop-index":r,hidden:_,onkeydown:this._handleRemoveStop,onclick:this._handleRemoveStop,role:"button",tabIndex:0,title:S},E("span",{"aria-hidden":"true",class:this.classes(k.stopIcon,k.removeStop,k.removeStopIcon,k.interactiveStopIcon)}),E("span",{class:k.screenReaderText},"removeStopTitle")),E("div",{"aria-label":w,class:k.reverseStops,bind:this,hidden:m,onkeydown:this._handleReverseStops,onclick:this._handleReverseStops,role:"button",tabIndex:0,title:w},E("span",{"aria-hidden":"true",class:this.classes(k.stopIcon,k.reverseStopIcon,k.interactiveStopIcon)}),E("span",{class:k.screenReaderText},"removeStopTitle"))))})),r=this._renderAddStop();return E("div",null,E("ol",{class:k.stops,role:"group",afterCreate:this._setUpDragAndDropStops},s),r)}_renderAddStop(){const{stops:e}=this.viewModel.layer,t=e.filter((({geometry:e})=>n(e))),s=e.at(-1);return t.length>1&&t.length<this.maxStops&&n(s)&&n(s.geometry)?E("div",{class:k.toolbarSection},E("div",{class:k.toolbarButtons},E("calcite-button",{appearance:"outline",class:k.addStopButton,kind:"neutral",scale:"s",round:!0,iconStart:"plus",key:k.addStopButton,onclick:()=>{this._addNewPlaceholder()},label:this.messages.addStop,width:"full"},this.messages.addStop))):null}_handleStopIconClick(e){const t=e.currentTarget["data-stop-index"],s=this.viewModel.layer.stops.getItemAt(t);s&&n(s.geometry)&&this._centerAtStop(s)}_handleClearRouteClick(){this.viewModel.reset()}_centerAtStop(e){this.viewModel.centerAt(e)}_handleStopFieldCreation(e){const t=this._newPlaceholderStop;if(!t)return;const s=e["data-stop-index"],r=this.viewModel.layer.stops.getItemAt(s);if(t===r){const e=this._acquireSearch(r);e.when((()=>{this.renderNow(),e.focus()}))}this._newPlaceholderStop=null}_handleStopInputBlur(e,t){if(this._saveLayer.opened)return;this.removeHandles(q);if(!!e.selectedResult&&n(t.geometry)&&n(e.selectedResult?.feature.geometry)&&t.geometry===e.selectedResult?.feature.geometry)return void this._pointerDownUpHandle.pause();const s=o(t.geometry)&&o(e.selectedResult?.feature.geometry),r=n(t.geometry)&&n(e.selectedResult?.feature.geometry)&&t.geometry!==e.selectedResult.feature.geometry;if((s||r)&&"none"===e.activeMenu&&e.searchTerm)return e.search(),void this._pointerDownUpHandle.pause();e.searchTerm||(this._viewClickHandle.resume(),clearTimeout(this._autoStopRemovalTimeoutId),this._autoStopRemovalTimeoutId=setTimeout((()=>{this.destroyed||(this._viewClickHandle.pause(),"searching"!==e.viewModel.state?this._pointerPressedSearchSuggestionStop||(n(t.geometry)&&(t.geometry=null,this._getDirections()),this.scheduleRender()):this._pointerDownUpHandle.pause())}),this._autoStopRemovalDelay))}_handleStopInputFocus(e,t){if(this._pointerDownUpHandle.resume(),this.hasHandles(q))return;const{view:s}=this,r=s.cursor;this.addHandles([{remove(){s.cursor=r}},c((()=>e.searchTerm),(t=>{e.destroyed||(s.cursor=t.length?r:"copy")}),d)],q),this._activeStop=t}_prepViewClick(){const{view:e}=this.viewModel,t=r(e,"click",this._handleViewClick.bind(this)),s=r(e.surface,"click",(()=>{clearTimeout(this._autoStopRemovalTimeoutId),s.pause()}));return{remove(){s.remove(),t.remove()},pause(){s.pause(),t.pause()},resume(){s.resume(),t.resume()}}}_prepPointerDownUpClick(){const e=r(document,"pointerdown",(e=>{this._pointerPressedSearchSuggestionStop=N(e)?this._activeStop:null})),t=r(document,"pointerup",(e=>{this._pointerDownUpHandle.pause();const t=N(e),s=this._activeStop;t||s!==this._pointerPressedSearchSuggestionStop||this._removeStop(s),this.scheduleRender(),this._pointerPressedSearchSuggestionStop=t?s:null}));return{remove(){t.remove(),e.remove()},pause(){t.pause(),e.pause()},resume(){e.resume()}}}_handleViewClick(e){e.stopPropagation();const t=this._stopsToSearches.get(this._activeStop);t&&!t.searchTerm&&(t.search(e.mapPoint).then((e=>{const s=e.results[0].results[0],{feature:r,name:i}=s;this._activeStop.geometry=r.geometry,this._activeStop.name=i,t.searchTerm=i})),this.scheduleRender()),this._viewClickHandle.pause(),clearTimeout(this._autoStopRemovalTimeoutId)}_addNewPlaceholder(){if(this._pointerDownUpHandle.pause(),this._newPlaceholderStop)return;const e=new g({symbol:new y});this.viewModel.layer.stops.add(e),this._newPlaceholderStop=e}_handleReverseStops(){this._reverseStops()}_reverseStops(){this.viewModel.layer.stops.reverse();for(const e of this.viewModel.layer.stops)e.sequence=null;this._getDirections()}_handleRemoveStop(e){const t=e.currentTarget["data-stop-index"],s=this.viewModel.layer.stops.getItemAt(t);this._removeStop(s),(n(s.geometry)||o(this.viewModel.layer.routeInfo))&&this._getDirections()}_removeStop(e){this.viewModel.layer.stops.length<=2||(this._disposeSearch(e),this.viewModel.layer.stops.remove(e))}_handleDepartureOptionChange(e){const t=e.currentTarget,s=t.item(t.selectedIndex);s.value===C.NOW?(this._departureTimeOption=C.NOW,this.viewModel.departureTime=C.NOW,this.removeHandles(K),this._getDirections()):s.value===C.DEPART_AT?(this._departureTimeOption=C.DEPART_AT,this.addHandles(c((()=>[this._datePicker.value,this._timePicker.value]),(()=>{this._updateDepartureTime(),this._getDirections()}),d),K)):(this._departureTimeOption=C.UNSPECIFIED,this.viewModel.departureTime=null,this._getDirections())}_updateDepartureTime(){const e=this._datePicker.value,t=this._timePicker.value;e&&t&&(this.viewModel.departureTime=new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes()))}_renderTimeControls(){return E("div",{class:k.departureTimeControls,key:"esri-directions__time-controls",role:"group"},this._datePicker.render(),this._timePicker.render())}_renderSectionSplitter(){return E("div",{class:k.sectionSplitter})}_renderSaveContainer(){const{saveButton:e,saveAsButton:t,printButton:s,layerDetails:r}=this.visibleElements;return e||t||s||r?E("div",{class:k.saveSection,key:k.saveSection},this._renderSaveButtons(),this._renderRouteLayerDetailsLink()):null}_renderSaveButtons(){const{saveButton:e,saveAsButton:t,printButton:s}=this.visibleElements;return e||t||s?E("div",{class:k.saveButtons,key:k.saveButtons},this._renderSaveButton(),this._renderSaveAsButton(),this._renderPrintButton()):null}_renderSaveButton(){if(!this.visibleElements.saveButton)return null;const e=this.viewModel.layer.portalItem?.itemControl,t=n(this.viewModel.layer.routeInfo)&&("admin"===e||"update"===e);return E("calcite-button",{appearance:"outline",class:k.saveButton,disabled:!t,iconStart:"save",key:k.saveButton,onclick:()=>{this._handleSaveButtonClick()},label:this.messagesCommon.save,width:"full"},this.messagesCommon.save)}_renderSaveAsButton(){if(!this.visibleElements.saveAsButton)return null;const e=o(this.viewModel.layer.routeInfo);return E("div",{class:k.saveAsButtonPopover,key:k.saveAsButtonPopover},E("calcite-button",{afterCreate:e=>{this._saveAsButtonNode=e},appearance:"outline",class:k.saveAsButton,disabled:e,iconStart:"duplicate",key:k.saveAsButton,onclick:()=>this._handleSaveAsButtonClick(),label:this.messagesCommon.saveAs,width:"full"},this.messagesCommon.saveAs))}_renderSavePopover(){return E("calcite-popover",{label:this._saveLayer.label,open:this._saveLayer.opened,overlayPositioning:"fixed",referenceElement:a(this._saveAsButtonNode)},this._saveLayer.render())}_handleSaveAsButtonClick(){this._saveLayer.opened?this._saveLayer.close():this._saveLayer.open(this.viewModel.layer)}_renderPrintButton(){return this.visibleElements.printButton?E("calcite-button",{appearance:"outline",class:k.printButton,iconStart:"print",key:k.printButton,label:this.messagesCommon.print}):null}_renderRouteLayerDetailsLink(){if(!this.visibleElements.layerDetails)return null;const{portalItem:e}=this.viewModel.layer;if(!e)return null;const{id:t,portal:{url:s}}=e,r=`${s}/home/item.html?id=${t}`;return E("calcite-link",{class:k.layerDetailsLink,href:r,key:k.layerDetailsLink,target:"_blank"},this.messages.viewLayerDetails)}_handleSaveButtonClick(){this.viewModel.layer.save()}_renderDirectionsContainer(){return E("div",{class:this.classes(k.directionsSection,k.section),key:"esri-directions__container"},this._renderDirectionsContainerContent())}_renderLoader(){return E("div",{class:k.loader,key:"loader"})}_renderWarningCard(){return E("div",{class:k.warningCard,role:"alert"},E("div",{class:k.warningHeader},E("span",{class:k.warningIcon,"aria-hidden":"true"}),E(R,{class:k.warningHeading,level:this.headingLevel},this.messagesCommon.warning)),E("div",{class:k.warningMessage},this._getErrorMessage()))}_renderDirectionsContainerContent(){const{viewModel:{layer:e,state:t}}=this,s="routing"===t;return"error"===t?this._renderWarningCard():s?this._renderLoader():n(e.directionLines)?E("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(k.summary,this._saveLayer.opened&&k.buttonDisabled),key:"esri-directions__summary",role:"group"},this._renderCosts(),this._renderRouteActions(),this._renderManeuverSections()):E("div",{key:"esri-directions__placeholder",class:k.emptyContent},this._renderPlaceholder(),E(R,{class:k.message,level:this.headingLevel},this.messages.directionsPlaceholder))}_renderPlaceholder(){return E("svg",{class:k.emptyIllustration,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256"},E("path",{fill:"currentcolor",d:"M192 36c-15.477 0-24 6.034-24 16.99v45.822l24 24 24-24v-45.82C216 42.033 207.477 36 192 36zm20 61.155l-20 20-20-20V52.99c0-8.62 6.73-12.99 20-12.99s20 4.37 20 12.99zM192 52a12 12 0 1 0 12 12 12.013 12.013 0 0 0-12-12zm0 20a8 8 0 1 1 8-8 8.008 8.008 0 0 1-8 8zM92 140.99C92 130.035 83.477 124 68 124s-24 6.034-24 16.99v45.822l24 24 24-24zm-4 44.165l-20 20-20-20V140.99c0-8.62 6.73-12.99 20-12.99s20 4.37 20 12.99zM68 140a12 12 0 1 0 12 12 12.013 12.013 0 0 0-12-12zm0 20a8 8 0 1 1 8-8 8.008 8.008 0 0 1-8 8zm84-44h16v4h-16zm-24 80h4v12h-12v-4h8zm0-28h4v16h-4zm0-52h12v4h-8v8h-4zm0 24h4v16h-4zm-36 64h16v4H92z"}))}_renderMessage(e){return E(R,{level:this.headingLevel},e)}_renderRouteActions(){return E("div",{class:k.routeActions},E("button",{"aria-label":this.messages.clearRoute,class:this.classes(k.clearRouteButton,k.button,k.buttonTertiary),tabIndex:0,onclick:this._handleClearRouteClick,bind:this,type:"button"},this.messages.clearRoute))}_getSections(){const{directionPoints:e,directionLines:t,stops:s}=this.viewModel.layer;if(o(e)||o(t))return null;const r=[];let i=null;for(const a of e){const{objectId:e,stopId:l}=a;if(n(l)){const e=s.find((e=>e.objectId===l)),t=0===r.length;(o(i)||i.stop!==e)&&(i={stop:e,directions:[],open:t},r.push(i));continue}if(o(i))continue;const c=t.find((t=>t.directionPointId===e));o(c)||i.directions.push({directionPoint:a,directionLine:c})}return r}_renderManeuverSections(){return o(this._sections)?null:E("div",{class:k.maneuvers,role:"group"},this._sections.map(((e,t)=>{const{open:s}=e;let r;e.directions.length>0&&s&&(r=E("ol",{class:k.maneuverList},e.directions.map((e=>this._renderManeuver(e)))));const i=a(this._sections).length>2,o=t===a(this._sections).length-1,n={[k.collapsibleSection]:i},l={[k.openIcon]:!s,[k.closeIcon]:s};let c;if(i&&!o){const t=s?this.messagesCommon.close:this.messagesCommon.open;c=E("header",{class:this.classes(k.maneuverSectionHeader,k.maneuverSectionToggle),key:k.maneuverSectionHeader},E("div",{"aria-expanded":s.toString(),"aria-label":t,bind:this,class:k.maneuverSectionHeaderButton,"data-maneuver-section":e,onkeydown:this._handleSectionToggle,onclick:this._handleSectionToggle,role:"button",tabIndex:0,title:t},E(R,{class:k.maneuverSectionTitle,level:this.headingLevel},e.stop.name),E("span",{"aria-hidden":"true",class:this.classes(l)})))}else c=E("header",{class:k.maneuverSectionHeader,key:k.maneuverSectionHeader},E(R,{class:k.maneuverSectionTitle,level:this.headingLevel},e.stop.name));return E("section",{class:this.classes(k.maneuverSection,n),key:t},c,r)})))}_handleSectionToggle(e){const t=e.currentTarget["data-maneuver-section"];t.open=!t.open}_renderCosts(){const e=this._getCostSummary(),{directionPoints:t}=this.viewModel.layer;if(o(t)||o(e))return null;const s=t.getItemAt(t.length-1).arrivalTime,{distance:r,duration:i}=e,{eta:a,primaryCosts:l,secondaryCosts:c,zoomToRoute:d}=this.messages,h=z("short-time"),u=n(s)?`<strong>${U(s,h)}</strong> ${F(s)}`:"";return E("div",{"aria-label":d,bind:this,class:k.directionCosts,onkeydown:this._handleSummaryInteraction,onclick:this._handleSummaryInteraction,role:"button",tabIndex:0,title:d},E("div",{class:k.costsDetails,role:"group"},E("div",{class:k.primaryCosts,title:l},i),E("div",{class:k.verticalSplitter}),E("div",{class:k.secondaryCosts,title:c},r)),E("div",{innerHTML:u,title:a}))}_handleSummaryInteraction(){this._activeManeuver=null,this._focusedManeuver=null,this.viewModel.clearHighlights(),this.zoomToRoute()}_getErrorMessage(){const{messages:e,viewModel:{lastError:t}}=this;if(n(t))switch(t.name){case"directions-view-model:unable-to-route":return e.errors.unableToRoute;case"directions-view-model:service-metadata-unavailable":return e.errors.unableToLoadServiceMetadata}return e.errors.unknownError}_normalizeSearchSources(e){this._overrideDefaultSources(e),this._applyLocatorSourceOverrides(e)}_overrideDefaultSources(e){e.viewModel.defaultSources.forEach((e=>{e.autoNavigate=!1}))}_applyLocatorSourceOverrides({allSources:e}){for(const t of e)"url"in t&&t.url&&(t.locationType??(t.locationType="street"),D(t.url)&&this.apiKey&&null==t.apiKey&&(t.apiKey=this.apiKey,t.url=P))}_acquireSearch(e){const{view:t}=this.viewModel;if(this._stopsToSearches.has(e)){const s=this._stopsToSearches.get(e);return s.view=t,this._overrideDefaultSources(s),s}const s=new S({view:t,resultGraphicEnabled:!1,popupEnabled:!1,...this.searchProperties});return this._normalizeSearchSources(s),this.addHandles([u((()=>s.allSources),"change",(()=>this._normalizeSearchSources(s))),s.on("select-result",(()=>{e.geometry=s.selectedResult.feature.geometry,e.name=s.selectedResult.name,this._getDirections()})),s.on("search-focus",(()=>this._handleStopInputFocus(s,e))),s.on("search-blur",(()=>this._handleStopInputBlur(s,e))),s.on("search-clear",(()=>{e.geometry=null,e.name=null,this._activeStop=e,this.viewModel.layer.removeResult()})),c((()=>s.searchTerm),(t=>{e.name=t}))],s),this._stopsToSearches.set(e,s),s}_disposeSearch(e){if(this._stopsToSearches.has(e)){const t=this._stopsToSearches.get(e);this.removeHandles(t),t.destroy(),this._stopsToSearches.delete(e)}}_renderManeuver(e){const{directionPoint:t,directionLine:s}=e,{distance:r,duration:i}=s,{messages:o,messagesUnits:a,unit:c}=this,d=f(a,l(r,0),c),h=T(l(i,0)),u=d&&h?`${d} · ${h}`:`${d}${h}`,p=this._getFormattedManeuverText(t),{objectId:v,directionPointType:m}=t,_=I(m),g=`esri-directions__maneuver-${v}`,y=`esri-directions__intermediate-costs-${v}`,S={[k.maneuverActive]:this._activeManeuver===s};return E("li",{"aria-labelledby":`${g} ${y}`,bind:this,class:this.classes(k.maneuver,S),"data-maneuver":s,key:s,onclick:this._handleManeuverClick,onkeydown:this._handleManeuverClick,onfocus:this._handleManeuverFocus,onmouseover:this._handleManeuverMouseOver,onmouseout:this._handleManeuverMouseOut,onblur:this._handleManeuverBlur,tabIndex:0},n(_)&&E("img",{alt:"",class:k.maneuverIcon,src:_}),E("div",{class:k.maneuverCostsContainer},E("span",{id:g,innerHTML:l(p,"")}),E("div",{class:k.maneuverCosts},E("div",{class:k.horizontalSplitter}),E("div",{"aria-hidden":"true",id:y,class:k.intermediateCost,innerHTML:u,title:o.intermediateCosts}))))}_handleManeuverClick(e){const t=e.currentTarget["data-maneuver"];if(this._activeManeuver===t)return this._activeManeuver=null,void this.zoomToRoute();this._activeManeuver=t;const{geometry:s}=t;this.viewModel.centerAt(s),this.viewModel.highlight(t)}_handleManeuverMouseOver(e){if(this._activeManeuver||this._focusedManeuver)return;const t=e.currentTarget["data-maneuver"];this.viewModel.highlight(t)}_handleManeuverMouseOut(){this._activeManeuver||this._focusedManeuver||this.viewModel.clearHighlights()}_handleManeuverBlur(){this._activeManeuver||(this._focusedManeuver=null,this.viewModel.clearHighlights())}_handleManeuverFocus(e){if(this._activeManeuver)return;const t=e.currentTarget["data-maneuver"];this._focusedManeuver=t,this.viewModel.highlight(t)}_getFormattedManeuverText(e){const{displayText:t,name:s,intersectingName:r}=e;if(o(t))return"";let i=t;return n(s)&&i.includes(s)&&(i=i.replace(s,`<strong>${s}</strong>`)),n(r)&&i.includes(r)&&(i=i.replace(r,`<strong>${r}</strong>`)),i}_getCostSummary(){const{messagesUnits:e,unit:t,viewModel:s}=this,{routeInfo:r}=s.layer;if(o(r))return null;const i=l(r.totalDistance,0),n=l(r.totalDuration,0);return{distance:f(e,i,t),duration:T(n)}}async _getDirections(){if(!(this.viewModel.layer.stops.filter((e=>n(e.geometry))).length<2))try{await this.viewModel.getDirections()}catch{}}get test(){return{projector:this._projector,acquireSearch:e=>this._acquireSearch(e)}}};e([p()],J.prototype,"apiKey",null),e([p(_)],J.prototype,"defaultUnit",void 0),e([p()],J.prototype,"goToOverride",null),e([p()],J.prototype,"headingLevel",void 0),e([p()],J.prototype,"iconClass",void 0),e([p()],J.prototype,"label",null),e([p({readOnly:!0})],J.prototype,"lastRoute",null),e([p()],J.prototype,"layer",null),e([p()],J.prototype,"maxStops",null),e([p(),j("esri/widgets/Directions/t9n/Directions")],J.prototype,"messages",void 0),e([p(),j("esri/t9n/common")],J.prototype,"messagesCommon",void 0),e([p(),j("esri/core/t9n/Units")],J.prototype,"messagesUnits",void 0),e([p()],J.prototype,"routeServiceUrl",null),e([p()],J.prototype,"routeSymbol",null),e([p()],J.prototype,"searchProperties",void 0),e([p()],J.prototype,"stopSymbols",null),e([p()],J.prototype,"unit",null),e([p()],J.prototype,"view",null),e([p({type:M})],J.prototype,"viewModel",void 0),e([p()],J.prototype,"visibleElements",void 0),e([v("visibleElements")],J.prototype,"castVisibleElements",null),e([H()],J.prototype,"_handleStopIconClick",null),e([H()],J.prototype,"_handleClearRouteClick",null),e([H()],J.prototype,"_handleReverseStops",null),e([H()],J.prototype,"_handleRemoveStop",null),e([H()],J.prototype,"_handleSectionToggle",null),e([H()],J.prototype,"_handleSummaryInteraction",null),e([H()],J.prototype,"_handleManeuverClick",null),J=e([m(G)],J);const Q=J;export{Q as default};
|
package/widgets/Editor.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.26/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{HandleOwnerMixin as t}from"../core/HandleOwner.js";import s from"../core/Logger.js";import{isSome as a}from"../core/maybe.js";import{watch as n,on as i,when as o,initial as r}from"../core/reactiveUtils.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import{cast as d}from"../core/accessorSupport/decorators/cast.js";import"../core/arrayUtils.js";import{subclass as c}from"../core/accessorSupport/decorators/subclass.js";import{getDisplayFieldName as p}from"../layers/support/fieldUtils.js";import h from"./Attachments.js";import u from"./FeatureForm.js";import m from"./FeatureTemplates.js";import g from"./Spinner.js";import v from"./Widget.js";import{workflowDeprecation as w}from"./Editor/deprecationUtils.js";import f from"./Editor/EditorViewModel.js";import{ItemList as _}from"./FeatureTemplates/ItemList.js";import{Heading as k,incrementHeadingLevel as b}from"./support/Heading.js";import y from"./support/SnappingControls.js";import{accessibleHandler as C}from"./support/decorators/accessibleHandler.js";import{messageBundle as M}from"./support/decorators/messageBundle.js";import{vmEvent as F}from"./support/decorators/vmEvent.js";import{tsx as A}from"./support/jsxFactory.js";import"./support/widgetUtils.js";import{substitute as W}from"../intl/substitute.js";const E="esri-editor",T=`${E}__panel`,S=`${E}__prompt`,B={base:`${E} esri-widget esri-widget--panel`,message:`${E}__message`,controls:`${E}__controls`,controlButton:`${E}__control-button`,progressBar:`${E}__progress-bar`,panelToolbar:`${T}-toolbar`,panelToolbarSnappingButton:`${T}-toolbar__snapping-button`,panelContent:`${T}-content`,panelContentMessage:`${T}-content__message`,panelContentSection:`${T}-content__section`,panelContentSectionGroup:`${T}-content__section__group`,snappingControlsPopover:`${E}__snapping-controls-popover`,updateFeaturesActionButtons:`${E}__update-features-action-buttons`,updateFeaturesActionButtonsButton:`${E}__update-features-action-buttons--button`,featureTemplatesContainer:`${E}__feature-templates-container`,promptContainer:S,promptHeader:`${S}__header`,promptHeading:`${S}__header__heading`,promptMessage:`${S}__message`,promptDivider:`${S}__divider`,promptActions:`${S}__actions`,warningIcon:"esri-icon-notice-triangle",widgetIcon:"esri-icon-edit",button:"esri-button",buttonDisabled:"esri-button--disabled",buttonSecondary:"esri-button--secondary",buttonTertiary:"esri-button--tertiary"},L={undoRedoButtons:!1,snappingControls:!0,snappingControlsElements:{header:!1,enabledToggle:!0,selfEnabledToggle:!0,featureEnabledToggle:!0,layerList:!0}};function P(e){e.focus()}const j="esri.widgets.Editor",U=s.getLogger(j);let V=class extends(t(v)){constructor(e,t){super(e,t),this._candidateCommitted=!1,this._featureForm=new u,this._stateStack=[],this._attachments=new h({visibleElements:{addSubmitButton:!1,cancelAddButton:!1,cancelUpdateButton:!1,deleteButton:!1,errorMessage:!1,progressBar:!1,updateButton:!1}}),this._featureTemplates=new m({enableListScroll:!1}),this._filterText="",this._prompt=null,this._spinner=new g,this._snappingButton=null,this._snappingPopover=null,this.useDeprecatedCreateWorkflow=!1,this.headingLevel=4,this.iconClass=B.widgetIcon,this.messages=null,this.messagesCommon=null,this.messagesTemplates=null,this.supportingWidgetDefaults=null,this.viewModel=new f,this.visibleElements={...L},this._setCandidateFeature=(e,t=!1)=>{if(this._candidateCommitted)return;const s=this._assertActiveUpdateWorkflow();s.data.edits.feature=e,t&&(s.next(),this._candidateCommitted=!0)},this._handleSave=this._handleSave.bind(this),this._handleBack=this._handleBack.bind(this),this._handleDone=this._handleDone.bind(this),this._handleDelete=this._handleDelete.bind(this),this._handleAdd=this._handleAdd.bind(this),this._handleEdit=this._handleEdit.bind(this),this._handleAttachmentAdd=this._handleAttachmentAdd.bind(this),this._handleAttachmentUpdate=this._handleAttachmentUpdate.bind(this),this._handleAttachmentDelete=this._handleAttachmentDelete.bind(this),this.EditorPanel=this.EditorPanel.bind(this)}initialize(){const{view:e,snappingOptions:t}=this;this._snappingControls=new y({snappingOptions:t,view:e,visibleElements:this.visibleElements.snappingControlsElements}),this.addHandles([n((()=>this.headingLevel),(e=>{this._featureForm.headingLevel=b(e),this._featureTemplates.headingLevel=b(e)}),r),this.viewModel.featureTemplatesViewModel.on("select",(({item:e})=>{e&&(this.useDeprecatedCreateWorkflow?this.startCreateWorkflowAtFeatureCreation(e):this.startCreateFeaturesWorkflowAtFeatureCreation(e))})),n((()=>this.viewModel.state),((e,t)=>{const s=this._stateStack.indexOf(e);-1===s?this._stateStack.push(t):this._stateStack.splice(s)})),n((()=>this.viewModel),(e=>{this._featureForm.viewModel=e?e.featureFormViewModel:null,this._attachments.viewModel=e?e.attachmentsViewModel:null,this._featureTemplates.viewModel=e?e.featureTemplatesViewModel:null,this._spinner.viewModel=e?e.spinnerViewModel:null}),r),n((()=>this.view),((e,t)=>{const s=`editor-${this.id}-spinner`;t&&t.ui.remove(this._spinner,s),e&&e.ui.add(this._spinner,{key:s,position:"manual"})}),r),i((()=>this.viewModel?.sketchViewModel),"create",(()=>{this.scheduleRender()})),i((()=>this.viewModel?.activeWorkflow),"cancel-request",(({controller:e})=>{const{messages:t,messagesCommon:s}=this;this._prompt={title:t.cancelRequestTitle,message:t.cancelRequestWarningMessage,context:"danger",actions:{primary:{label:s.form.yes,action:()=>{e.allow(),this._prompt=null}},secondary:{label:s.form.no,action:()=>(e.deny(),this._prompt=null)}}},this.scheduleRender()})),n((()=>this.supportingWidgetDefaults),(e=>{e&&(this._featureForm.set(e.featureForm),this._attachments.set(e.attachments),this._featureTemplates.set(e.featureTemplates),this.viewModel.sketchViewModel.set(e.sketch))}),r),n((()=>this._attachments?.error),(e=>{if(!e)return;const{messages:t,messagesCommon:s}=this;this._prompt={title:t.errorWarningTitle,message:e.message,context:"warning",actions:{primary:{label:s.form.ok,action:()=>{this._prompt=null}}}}})),n((()=>this.viewModel?.failures),(e=>{if(!e)return;const{messages:t}=this,[{error:s,retry:a,cancel:n}]=e;this._prompt={title:t.errorWarningTitle,message:W(t.errorWarningMessageTemplate,{errorMessage:s.message}),context:"warning",actions:{primary:{label:t.retry,action:()=>{a(),this._prompt=null}},secondary:{label:t.ignore,action:()=>(n(),this._prompt=null)}}}})),n((()=>this.viewModel?.state),(e=>{if("awaiting-feature-to-update"===e&&(this._filterText=""),"awaiting-update-feature-candidate"===e&&(this._candidateCommitted=!1),"editing-existing-feature"===e){const{activeWorkflow:e}=this.viewModel;this._featureForm.disabled="update"===e?.type&&!1===e?.data.editableItem.attributeUpdatesEnabled}})),n((()=>[this._attachments?.selectedFile,this._attachments?.submitting]),(()=>this.scheduleRender())),n((()=>this.viewModel?.activeWorkflow),(()=>this._featureForm.disabled=!1)),o((()=>!this.viewModel?.activeWorkflow),(()=>this._featureTemplates.filterText="")),i((()=>this.view),"key-down",(e=>{"Escape"===e.key&&this.viewModel?.activeWorkflow&&this._handleBack()}))])}destroy(){this._attachments.destroy(),this._featureForm.destroy(),this._featureTemplates.destroy(),this._snappingControls.destroy()}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-action.js"),import("@esri/calcite-components/dist/components/calcite-button.js"),import("@esri/calcite-components/dist/components/calcite-flow.js"),import("@esri/calcite-components/dist/components/calcite-icon.js"),import("@esri/calcite-components/dist/components/calcite-flow-item.js"),import("@esri/calcite-components/dist/components/calcite-popover.js"),import("@esri/calcite-components/dist/components/calcite-scrim.js")])}get activeWorkflow(){return this.viewModel.activeWorkflow}get allowedWorkflows(){return this.viewModel.allowedWorkflows}set allowedWorkflows(e){this.viewModel.allowedWorkflows=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get labelOptions(){return this.viewModel.labelOptions}set labelOptions(e){this.viewModel.labelOptions=e}get layerInfos(){return this.viewModel.layerInfos}set layerInfos(e){this.viewModel.layerInfos=e}get snappingOptions(){return this.viewModel.snappingOptions}set snappingOptions(e){this.viewModel.snappingOptions=e}get tooltipOptions(){return this.viewModel.tooltipOptions}set tooltipOptions(e){this.viewModel.tooltipOptions=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}castVisibleElements(e){const t={...L,...e,snappingControlsElements:{...L.snappingControlsElements,...e?.snappingControlsElements}};return a(this._snappingControls)&&(this._snappingControls.visibleElements=t.snappingControlsElements),t}startCreateWorkflowAtFeatureTypeSelection(){return w(U,"startCreateWorkflowAtFeatureTypeSelection","startCreateFeaturesWorkflowAtFeatureTypeSelection"),this.viewModel.startCreateWorkflowAtFeatureTypeSelection()}startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.viewModel.startCreateFeaturesWorkflowAtFeatureTypeSelection()}startCreateWorkflowAtFeatureCreation(e){return w(U,"startCreateWorkflowAtFeatureCreation","startCreateFeaturesWorkflowAtFeatureCreation"),this.viewModel.startCreateWorkflowAtFeatureCreation(e)}startCreateFeaturesWorkflowAtFeatureCreation(e){return this.viewModel.startCreateFeaturesWorkflowAtFeatureCreation(e)}startCreateWorkflowAtFeatureEdit(e){return w(U,"startCreateWorkflowAtFeatureEdit"),this.viewModel.startCreateWorkflowAtFeatureEdit(e)}startUpdateWorkflowAtFeatureSelection(){return this.viewModel.startUpdateWorkflowAtFeatureSelection()}startUpdateWorkflowAtMultipleFeatureSelection(e){return this.viewModel.startUpdateWorkflowAtMultipleFeatureSelection(e)}startUpdateWorkflowAtFeatureEdit(e){return this.viewModel.startUpdateWorkflowAtFeatureEdit(e)}deleteFeatureFromWorkflow(){return this.viewModel.deleteFeatureFromWorkflow()}cancelWorkflow(e){return this.viewModel.cancelWorkflow(e)}render(){const{_attachments:e,_prompt:t,viewModel:s}=this;if(!s)return A("div",{class:B.base});const{state:n}=s,i=a(t)?A("calcite-scrim",null,this.renderPrompt(t)):null;return A("div",{class:B.base},s.syncing||e.submitting?this.renderProgressBar():null,A("calcite-flow",null,this._stateStack.map((e=>this.renderState(e))),this.renderState(n)),i)}renderState(e){switch(e){case"disabled":break;case"ready":return this.renderLanding(e);case"awaiting-feature-creation-info":return this.renderTemplates(e);case"creating-features":case"editing-new-feature":case"editing-existing-feature":return this.renderAttributeEditing(e);case"awaiting-feature-to-update":return this.renderFeatureUpdating(e);case"awaiting-update-feature-candidate":return this.renderFeatureList(e);case"awaiting-feature-to-create":return this.renderFeatureCreation(e);case"adding-attachment":return this.renderAttachmentAdding(e);case"editing-attachment":return this.renderAttachmentEditing(e)}return A("div",null)}isPanelActive(e){return this.viewModel.state===e}renderTemplates(e){const{EditorPanel:t,headingLevel:s,messages:a,messagesCommon:n,_handleBack:i,_snappingControls:o,viewModel:{sketchViewModel:r}}=this;return A(t,{active:this.isPanelActive(e),key:"templates-panel",handleBack:i,heading:a.selectTemplate,headingLevel:s,messages:a,messagesCommon:n,sketchViewModel:r,snappingControls:o},A("div",{class:B.panelContent},this._featureTemplates.render()))}renderAttributeEditing(e){const{activeWorkflow:t,EditorPanel:s,messages:a,messagesCommon:n,headingLevel:i,_handleBack:o,_snappingControls:r,viewModel:l}=this;if(!t)return null;const{sketchViewModel:d}=l,c=l.featureFormViewModel;if("create-features"===t.type&&t.pendingFeatures.length<1)return this.renderFeatureCreation(e);const p="update"===t.type&&!t.data.edits.modified||l.syncing||c.updating,h="update"===t.type?a.editFeature:a.createFeatures,u="update"===t.type?n.update:n.create,m="create-features"===t.type&&"create-new"===t.createFeatureState,g="update"===t.type&&t.data.editableItem.supports.includes("delete"),v=this._shouldShowAttachmentsForWorkflow(t),w=[{label:"create-features"===t.type&&t.numPendingFeatures>1?W(a.createFeaturesTemplate,{numFeatures:t.numPendingFeatures}):u,type:"primary",disabled:p,clickHandler:this._handleSave,width:g?"half":"full"}];g&&w.push({label:n.delete,type:"tertiary",clickHandler:this._handleDelete,disabled:l.syncing,appearance:"outline",width:"half"});const f=c.inputFields.every((e=>!e.visible))&&!v?this.renderMessage(W(a.clickToFinishTemplate,{button:u})):A("div",{class:B.panelContentSection},A("div",{class:B.panelContentSectionGroup},this._featureForm.render(),v?A("div",{key:"attachments"},A(k,{level:b(i)},a.attachments),this._attachments.render()):null));return A(s,{active:this.isPanelActive(e),key:"attribute-editing-panel",heading:h,headingLevel:i,handleBack:o,messages:a,messagesCommon:n,sketchViewModel:d,snappingControls:r},A("div",{class:B.panelContent},f,m?A("calcite-scrim",null):null),this.renderFooterActions(w))}renderAttachmentAdding(e){const{_attachments:t,EditorPanel:s,_handleBack:a,headingLevel:n,messages:i,messagesCommon:o,_snappingControls:r,viewModel:{sketchViewModel:l}}=this,d=[{label:t.submitting?o.cancel:o.add,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentAdd,width:"full"}];return A(s,{active:this.isPanelActive(e),key:"attachment-adding-panel",heading:i.addAttachment,headingLevel:n,handleBack:a,messages:i,messagesCommon:o,sketchViewModel:l,snappingControls:r},A("div",{class:B.panelContent},t.render()),this.renderFooterActions(d))}renderAttachmentEditing(e){const{_attachments:t,EditorPanel:s,_handleBack:a,headingLevel:n,messages:i,messagesCommon:o,_snappingControls:r,viewModel:{sketchViewModel:l}}=this,d=[{label:o.update,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentUpdate,width:"half"},{label:o.delete,disabled:t.submitting,type:"tertiary",clickHandler:this._handleAttachmentDelete,width:"half",appearance:"outline"}];return A(s,{active:this.isPanelActive(e),key:"attachment-editing-panel",heading:i.editAttachment,headingLevel:n,handleBack:a,messages:i,messagesCommon:o,sketchViewModel:l,snappingControls:r},A("div",{class:B.panelContent},t.render()),this.renderFooterActions(d))}renderFeatureUpdating(e){const{EditorPanel:t,_handleBack:s,headingLevel:a,messages:n,messagesCommon:i,_snappingControls:o,viewModel:{sketchViewModel:r}}=this;return A(t,{active:this.isPanelActive(e),key:"feature-updating-panel",heading:n.selectFeature,headingLevel:a,handleBack:s,messages:n,messagesCommon:i,sketchViewModel:r,snappingControls:o},A("div",{class:B.panelContent},this.renderMessage(n.selectFeatureToEdit)))}renderMessage(e){return A("div",{class:B.panelContentMessage},e)}renderFeatureCreation(e){const{EditorPanel:t,_handleBack:s,headingLevel:a,messages:n,messagesCommon:i,_snappingControls:o,viewModel:r}=this,{sketchViewModel:l}=r,d=r.sketchViewModel,c=this._assertActiveCreateWorkflow().data.creationInfo.layer,p=d.canUndo()&&d.createGraphic?d.createGraphic:null,h=this._getSketchingTip(c.geometryType,p);return A(t,{active:this.isPanelActive(e),key:"feature-creation-panel",heading:n.placeFeature,headingLevel:a,handleBack:s,messages:n,messagesCommon:i,sketchViewModel:l,snappingControls:o},A("div",{class:B.panelContent},this.renderMessage(h)))}renderFooterActions(e){return e.map((({type:e,disabled:t,class:s,...a},n)=>this.renderButton({class:this.classes(B.controlButton,"secondary"===e?B.buttonSecondary:"tertiary"===e?B.buttonTertiary:null,t?B.buttonDisabled:null,s),disabled:t??!1,key:n,slot:"footer-actions",...a})))}renderPrompt({title:e,message:t,context:s,actions:a}){const n=a.secondary,i=A("calcite-button",{appearance:"solid",kind:"danger"===s?"danger":"brand",width:n?"half":"full",onclick:a.primary.action,key:"prompt-primary-button",afterCreate:P},a.primary.label),o=n&&A("calcite-button",{appearance:"outline",kind:"danger"===s?"danger":"brand",width:"half",onclick:n.action,key:"prompt-secondary-button"},n.label);return A("div",{class:`${B.promptContainer}--${s}`},A("div",{class:B.promptHeader},A("calcite-icon",{icon:"exclamation-mark-triangle"}),A(k,{class:B.promptHeading,level:this.headingLevel},e)),A("div",{class:B.promptMessage},t),A("div",{class:B.promptDivider}),A("div",{class:B.promptActions},o,i))}renderProgressBar(){return A("div",{class:this.classes(B.progressBar),key:"progress-bar"})}renderButton(e){const{disabled:t,class:s,key:a,clickHandler:n,label:i,...o}=e;return A("calcite-button",{class:s,disabled:t,key:a,onclick:n,type:"button",...o},i)}renderLanding(e){const{EditorPanel:t,headingLevel:s,messages:a,messagesCommon:n,_snappingControls:i,_featureTemplates:{viewModel:{numberOfFeatureTemplates:o}},viewModel:{canUpdate:r,sketchViewModel:l}}=this,d=!r&&0===o;return A(t,{active:this.isPanelActive(e),key:"landing-panel",heading:a.widgetLabel,headingLevel:s,showBackButton:!1,messages:a,messagesCommon:n,sketchViewModel:l,snappingControls:i},A("div",{class:B.panelContent},r?A("div",{key:"edit-actions",class:B.panelContentSection},this.renderUpdateActions()):void 0,o>0?A("div",{key:"create-actions",class:B.panelContentSection},this.renderCreateActions()):void 0,d?A("div",{key:"no-content",class:B.panelContentMessage},a.noEditableLayers):void 0))}renderUpdateActions(){const{messages:e,messagesCommon:t}=this;return A("div",null,A(k,{level:b(this.headingLevel)},e.editFeatures),A("div",{class:B.updateFeaturesActionButtons},A("calcite-action",{text:t.select,textEnabled:!0,icon:"cursor",alignment:"start",class:B.updateFeaturesActionButtonsButton,onclick:this._handleEdit})))}renderCreateActions(){const{_featureTemplates:e,headingLevel:t,messages:s}=this;return A("div",null,A(k,{level:b(t)},s.createFeatures),A("div",{key:"templates",class:B.featureTemplatesContainer},e.render()))}renderFeatureList(e){const{EditorPanel:t,_handleBack:s,headingLevel:n,messages:i,messagesCommon:o,messagesTemplates:r,_snappingControls:l,viewModel:{editableItems:d,sketchViewModel:c}}=this,p=this._assertActiveUpdateWorkflow().data.candidates,h=W(i.multipleFeaturesTemplate,{total:p.length}),u=new Map;let m=0;p.map((e=>({label:this._getLabel(e),id:e.attributes[e.layer.objectIdField],data:e}))).filter((e=>{const{label:t,data:s}=e,a=this._filterText.toLowerCase(),{title:n}=s.layer,i=d.find((e=>e.layer===s.layer));if(!i)return null;const{attachmentsOnUpdateEnabled:o,supports:r}=i;return(r.includes("update")||r.includes("delete")||o)&&(!a||t?.toLowerCase().includes(a)||n?.toLowerCase().includes(a))})).filter(a).forEach((e=>{m++;const t=e.data.layer;u.has(t)?u.get(t)?.items.push(e):u.set(t,{id:`${t.id}`,label:t.title??"",items:[e]})}));const g=d.toArray().map((({layer:e})=>u.get(e))).filter(a),v=m>10||this._filterText.length>0;return A(t,{active:this.isPanelActive(e),key:"feature-list",heading:h,headingLevel:n,handleBack:s,messages:i,messagesCommon:o,sketchViewModel:c,snappingControls:l},A("div",{class:B.panelContent},A("div",{class:B.panelContentSection},_({id:this.id,enableListScroll:!1,filterEnabled:v,filterText:this._filterText,items:g,messages:{filterPlaceholder:r.filterPlaceholder,noItems:r.noItems,noMatches:r.noMatches},onItemMouseEnter:({data:e})=>this._setCandidateFeature(e),onItemMouseLeave:()=>this._setCandidateFeature(null),onItemSelect:({data:e})=>this._setCandidateFeature(e,!0),onFilterChange:e=>this._filterText=e}))))}EditorPanel(e,...t){const{active:s,handleBack:a,heading:n,headingLevel:i,key:o,messages:r,messagesCommon:l,showBackButton:d,sketchViewModel:c,snappingControls:p}=e,{snappingControls:h,undoRedoButtons:u}=this.visibleElements;return A("calcite-flow-item",{bind:this,key:o,heading:n,headingLevel:i,showBackButton:d??!0,closable:!1,onCalciteFlowItemScroll:this._closeSnappingPopover,onCalciteFlowItemBack:a??void 0},A("div",{class:B.panelToolbar},h?[A("calcite-popover",{autoClose:s,afterCreate:this._setSnappingPopover,afterUpdate:this._setSnappingPopover,bind:this,label:r.snappingSettings,heading:r.snappingSettings,referenceElement:this._snappingButton,"overlay-positioning":"fixed",placement:"bottom"},A("div",{class:B.snappingControlsPopover},p.render())),A("calcite-button",{id:`${o}__snappingButton`,afterCreate:this._setSnappingButton,afterUpdate:this._setSnappingButton,bind:this,label:r.snapping,appearance:"transparent",kind:"neutral",alignment:"icon-end-space-between","icon-start":"vertex-gps","icon-end":"caret-down",width:"full",class:B.panelToolbarSnappingButton,onkeydown:e=>{"Escape"===e.key&&this._closeSnappingPopover()}},r.snapping)]:null,u?[A("calcite-button",{key:"undo-button",label:l.undo,appearance:"transparent",kind:"neutral",alignment:"center","icon-start":"undo",scale:"l",disabled:!c.canUndo(),onclick:c.undo.bind(c)},l.undo),A("calcite-button",{key:"redo-button",label:l.redo,appearance:"transparent",kind:"neutral",alignment:"center","icon-start":"redo",scale:"l",disabled:!c.canRedo(),onclick:c.redo.bind(c)},l.redo)]:null),t)}_closeSnappingPopover(){this._snappingPopover?.open&&this._snappingPopover.toggle()}_setSnappingPopover(e){this._snappingPopover=e}_setSnappingButton(e){this._snappingButton=e,this.scheduleRender()}_getSketchingTip(e,t){const{messages:s}=this;if("point"===e)return s.tips.clickToAddPoint;if("polygon"===e||"polyline"===e){if(!t)return s.tips.clickToStart;const a=t.geometry,n="polygon"===e?"rings":"paths",[i]=a[n];return"polygon"===e&&i<4?s.tips.clickToContinue:s.tips.clickToContinueThenDoubleClickToEnd}return s.tips.clickToAddFeature}_getLabel(e){const t=e.layer;if(!t)return null;const{objectIdField:s}=t,{attributes:a}=e,n=p(t);return n&&a[n]&&`${a[n]}`||W(this.messages.untitledFeatureTemplate,{id:a[s]})}_handleDelete(){const{messages:e,messagesCommon:t}=this;this._prompt={title:e.deleteWarningTitle,message:e.deleteWarningMessage,context:"danger",actions:{primary:{label:t.delete,action:()=>{this.viewModel.deleteFeatureFromWorkflow(),this._prompt=null}},secondary:{label:e.keepFeature,action:()=>this._prompt=null}}}}_handleSave(){const{featureFormViewModel:e}=this.viewModel;e.submit(),!e.submittable||e.validateContingencyConstraints(e.getValues(),{includeIncompleteViolations:!0}).length>0||this.viewModel.activeWorkflow?.commit()}_handleAttachmentAdd(){const{activeWorkflow:e}=this.viewModel;e&&("create-features"===e.type?(this._attachments.addFile(),e.previous()):this._attachments.addAttachment().then((()=>e.previous())))}_handleAttachmentUpdate(){const{activeWorkflow:e}=this.viewModel;e&&("create-features"===e.type?(this._attachments.updateFile(),e.previous()):this._attachments.updateAttachment().then((()=>e.previous())))}_handleAttachmentDelete(){const{messages:e,messagesCommon:t}=this;this._prompt={title:e.deleteAttachmentWarningTitle,message:e.deleteAttachmentWarningMessage,context:"danger",actions:{primary:{label:t.delete,action:()=>{const{_attachments:e}=this,{activeWorkflow:t}=this.viewModel;t&&("create-features"===t.type?(e.deleteFile(),t.previous(),this._prompt=null):e.deleteAttachment(e.viewModel.activeAttachmentInfo).then((()=>{t.previous(),this._prompt=null})))}},secondary:{label:e.keepAttachment,action:()=>this._prompt=null}}}}_handleAdd(){this.viewModel.canCreate}_handleEdit(){this.viewModel.canUpdate&&this.viewModel.startUpdateWorkflowAtFeatureSelection()}_handleDone(){this.viewModel.cancelWorkflow({force:!0})}async _handleBack(e){if(!this.activeWorkflow)return;const t=this.activeWorkflow;if(e?.stopPropagation(),this.viewModel.syncing)return;const s=()=>{t.hasPreviousStep?t.previous({cancelCurrentStep:!0}):this.viewModel.cancelWorkflow({force:!0})};if("create"===t.type||"create-features"===t.type&&t.numPendingFeatures>0||"editing-existing-feature"===t.stepId&&t.data.edits.modified){const{messages:e}=this,{type:a}=t,n="create"===a?e.cancelAddWarningMessage:e.cancelEditWarningMessage,i="create"===a?e.cancelAddTitle:e.cancelEditTitle,o="create"===a?e.continueAdding:e.continueEditing,r="create"===a?e.discardFeature:e.discardEdits;return this._prompt={title:i,message:n,context:"danger",actions:{primary:{label:r,action:()=>{this._prompt=null,s()}},secondary:{label:o,action:()=>this._prompt=null}}},void this.scheduleRender()}s()}_assertActiveCreateWorkflow(){const e=this.viewModel.activeWorkflow;if("create"===e?.type||"create-features"===e?.type)return e;throw new Error("Expected activeWorkflow to be instance of CreateWorkflow or CreateFeaturesWorkflow")}_assertActiveUpdateWorkflow(){const e=this.viewModel.activeWorkflow;if("update"===e?.type)return e;throw new Error("Expected activeWorkflow to be an UpdateWorkflow")}_shouldShowAttachmentsForWorkflow(e){if("update"===e.type)return e.data.editableItem.attachmentsOnUpdateEnabled;const t=e.data.creationInfo;if(t){const{layerInfos:e}=this,{layer:s}=t,a=this.viewModel.editableItems.find((e=>e.layer===s));if(a)return a.attachmentsOnCreateEnabled;const{data:n}=s.capabilities,i=e&&e.find((e=>e.layer===s));return"supportsAttachment"in n&&n.supportsAttachment&&(!i||!1!==i.allowAttachments&&!1!==i.attachmentsOnUpdateEnabled)}return!1}};e([l()],V.prototype,"_attachments",void 0),e([l({readOnly:!0})],V.prototype,"activeWorkflow",null),e([l()],V.prototype,"allowedWorkflows",null),e([l()],V.prototype,"useDeprecatedCreateWorkflow",void 0),e([l()],V.prototype,"headingLevel",void 0),e([l()],V.prototype,"iconClass",void 0),e([l()],V.prototype,"label",null),e([l()],V.prototype,"labelOptions",null),e([l()],V.prototype,"layerInfos",null),e([l(),M("esri/widgets/Editor/t9n/Editor")],V.prototype,"messages",void 0),e([l(),M("esri/t9n/common")],V.prototype,"messagesCommon",void 0),e([l(),M("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],V.prototype,"messagesTemplates",void 0),e([l()],V.prototype,"snappingOptions",null),e([l()],V.prototype,"tooltipOptions",null),e([l()],V.prototype,"supportingWidgetDefaults",void 0),e([l()],V.prototype,"view",null),e([l(),F(["workflow-cancel","workflow-commit"])],V.prototype,"viewModel",void 0),e([l()],V.prototype,"visibleElements",void 0),e([d("visibleElements")],V.prototype,"castVisibleElements",null),e([C()],V.prototype,"_handleDelete",null),e([C()],V.prototype,"_handleAttachmentAdd",null),e([C()],V.prototype,"_handleAttachmentUpdate",null),e([C()],V.prototype,"_handleAttachmentDelete",null),e([C()],V.prototype,"_handleAdd",null),e([C()],V.prototype,"_handleEdit",null),e([C()],V.prototype,"_handleDone",null),V=e([c(j)],V);const x=V;export{x as default};
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{HandleOwnerMixin as t}from"../core/HandleOwner.js";import s from"../core/Logger.js";import{isSome as a}from"../core/maybe.js";import{watch as n,on as i,when as o,initial as r}from"../core/reactiveUtils.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import{cast as d}from"../core/accessorSupport/decorators/cast.js";import"../core/arrayUtils.js";import{subclass as c}from"../core/accessorSupport/decorators/subclass.js";import{getDisplayFieldName as p}from"../layers/support/fieldUtils.js";import h from"./Attachments.js";import u from"./FeatureForm.js";import m from"./FeatureTemplates.js";import g from"./Spinner.js";import v from"./Widget.js";import{workflowDeprecation as w}from"./Editor/deprecationUtils.js";import f from"./Editor/EditorViewModel.js";import{ItemList as _}from"./FeatureTemplates/ItemList.js";import{Heading as k,incrementHeadingLevel as b}from"./support/Heading.js";import y from"./support/SnappingControls.js";import{accessibleHandler as C}from"./support/decorators/accessibleHandler.js";import{messageBundle as M}from"./support/decorators/messageBundle.js";import{vmEvent as F}from"./support/decorators/vmEvent.js";import{tsx as A}from"./support/jsxFactory.js";import"./support/widgetUtils.js";import{substitute as W}from"../intl/substitute.js";const E="esri-editor",T=`${E}__panel`,S=`${E}__prompt`,B={base:`${E} esri-widget esri-widget--panel`,message:`${E}__message`,controls:`${E}__controls`,controlButton:`${E}__control-button`,progressBar:`${E}__progress-bar`,panelToolbar:`${T}-toolbar`,panelToolbarSnappingButton:`${T}-toolbar__snapping-button`,panelContent:`${T}-content`,panelContentMessage:`${T}-content__message`,panelContentSection:`${T}-content__section`,panelContentSectionGroup:`${T}-content__section__group`,snappingControlsPopover:`${E}__snapping-controls-popover`,updateFeaturesActionButtons:`${E}__update-features-action-buttons`,updateFeaturesActionButtonsButton:`${E}__update-features-action-buttons--button`,featureTemplatesContainer:`${E}__feature-templates-container`,promptContainer:S,promptHeader:`${S}__header`,promptHeading:`${S}__header__heading`,promptMessage:`${S}__message`,promptDivider:`${S}__divider`,promptActions:`${S}__actions`,warningIcon:"esri-icon-notice-triangle",widgetIcon:"esri-icon-edit",button:"esri-button",buttonDisabled:"esri-button--disabled",buttonSecondary:"esri-button--secondary",buttonTertiary:"esri-button--tertiary"},P={undoRedoButtons:!1,snappingControls:!0,snappingControlsElements:{header:!1,enabledToggle:!0,selfEnabledToggle:!0,featureEnabledToggle:!0,layerList:!0}};function L(e){e.focus()}const j="esri.widgets.Editor",U=s.getLogger(j);let V=class extends(t(v)){constructor(e,t){super(e,t),this._candidateCommitted=!1,this._featureForm=new u,this._stateStack=[],this._attachments=new h({visibleElements:{addSubmitButton:!1,cancelAddButton:!1,cancelUpdateButton:!1,deleteButton:!1,errorMessage:!1,progressBar:!1,updateButton:!1}}),this._featureTemplates=new m({enableListScroll:!1}),this._filterText="",this._prompt=null,this._spinner=new g,this._snappingButton=null,this._snappingPopover=null,this.useDeprecatedCreateWorkflow=!1,this.headingLevel=4,this.iconClass=B.widgetIcon,this.messages=null,this.messagesCommon=null,this.messagesTemplates=null,this.supportingWidgetDefaults=null,this.viewModel=new f,this.visibleElements={...P},this._setCandidateFeature=(e,t=!1)=>{if(this._candidateCommitted)return;const s=this._assertActiveUpdateWorkflow();s.data.edits.feature=e,t&&(s.next(),this._candidateCommitted=!0)},this._handleSave=this._handleSave.bind(this),this._handleBack=this._handleBack.bind(this),this._handleDone=this._handleDone.bind(this),this._handleDelete=this._handleDelete.bind(this),this._handleAdd=this._handleAdd.bind(this),this._handleEdit=this._handleEdit.bind(this),this._handleAttachmentAdd=this._handleAttachmentAdd.bind(this),this._handleAttachmentUpdate=this._handleAttachmentUpdate.bind(this),this._handleAttachmentDelete=this._handleAttachmentDelete.bind(this),this.EditorPanel=this.EditorPanel.bind(this)}initialize(){const{view:e,snappingOptions:t}=this;this._snappingControls=new y({snappingOptions:t,view:e,visibleElements:this.visibleElements.snappingControlsElements}),this.addHandles([n((()=>this.headingLevel),(e=>{this._featureForm.headingLevel=b(e),this._featureTemplates.headingLevel=b(e)}),r),this.viewModel.featureTemplatesViewModel.on("select",(({item:e})=>{e&&(this.useDeprecatedCreateWorkflow?this.startCreateWorkflowAtFeatureCreation(e):this.startCreateFeaturesWorkflowAtFeatureCreation(e))})),n((()=>this.viewModel.state),((e,t)=>{const s=this._stateStack.indexOf(e);-1===s?this._stateStack.push(t):this._stateStack.splice(s)})),n((()=>this.viewModel),(e=>{this._featureForm.viewModel=e?e.featureFormViewModel:null,this._attachments.viewModel=e?e.attachmentsViewModel:null,this._featureTemplates.viewModel=e?e.featureTemplatesViewModel:null,this._spinner.viewModel=e?e.spinnerViewModel:null}),r),n((()=>this.view),((e,t)=>{const s=`editor-${this.id}-spinner`;t&&t.ui.remove(this._spinner,s),e&&e.ui.add(this._spinner,{key:s,position:"manual"})}),r),i((()=>this.viewModel?.sketchViewModel),"create",(()=>{this.scheduleRender()})),i((()=>this.viewModel?.activeWorkflow),"cancel-request",(({controller:e})=>{const{messages:t,messagesCommon:s}=this;this._prompt={title:t.cancelRequestTitle,message:t.cancelRequestWarningMessage,context:"danger",actions:{primary:{label:s.form.yes,action:()=>{e.allow(),this._prompt=null}},secondary:{label:s.form.no,action:()=>(e.deny(),this._prompt=null)}}},this.scheduleRender()})),n((()=>this.supportingWidgetDefaults),(e=>{e&&(this._featureForm.set(e.featureForm),this._attachments.set(e.attachments),this._featureTemplates.set(e.featureTemplates),this.viewModel.sketchViewModel.set(e.sketch))}),r),n((()=>this._attachments?.error),(e=>{if(!e)return;const{messages:t,messagesCommon:s}=this;this._prompt={title:t.errorWarningTitle,message:e.message,context:"warning",actions:{primary:{label:s.form.ok,action:()=>{this._prompt=null}}}}})),n((()=>this.viewModel?.failures),(e=>{if(!e)return;const{messages:t}=this,[{error:s,retry:a,cancel:n}]=e;this._prompt={title:t.errorWarningTitle,message:W(t.errorWarningMessageTemplate,{errorMessage:s.message}),context:"warning",actions:{primary:{label:t.retry,action:()=>{a(),this._prompt=null}},secondary:{label:t.ignore,action:()=>(n(),this._prompt=null)}}}})),n((()=>this.viewModel?.state),(e=>{if("awaiting-feature-to-update"===e&&(this._filterText=""),"awaiting-update-feature-candidate"===e&&(this._candidateCommitted=!1),"editing-existing-feature"===e){const{activeWorkflow:e}=this.viewModel;this._featureForm.disabled="update"===e?.type&&!1===e?.data.editableItem.attributeUpdatesEnabled}})),n((()=>[this._attachments?.selectedFile,this._attachments?.submitting]),(()=>this.scheduleRender())),n((()=>this.viewModel?.activeWorkflow),(()=>this._featureForm.disabled=!1)),o((()=>!this.viewModel?.activeWorkflow),(()=>this._featureTemplates.filterText="")),i((()=>this.view),"key-down",(e=>{"Escape"===e.key&&this.viewModel?.activeWorkflow&&this._handleBack()}))])}destroy(){this._attachments.destroy(),this._featureForm.destroy(),this._featureTemplates.destroy(),this._snappingControls.destroy()}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-action.js"),import("@esri/calcite-components/dist/components/calcite-button.js"),import("@esri/calcite-components/dist/components/calcite-flow.js"),import("@esri/calcite-components/dist/components/calcite-icon.js"),import("@esri/calcite-components/dist/components/calcite-flow-item.js"),import("@esri/calcite-components/dist/components/calcite-popover.js"),import("@esri/calcite-components/dist/components/calcite-scrim.js")])}get activeWorkflow(){return this.viewModel.activeWorkflow}get allowedWorkflows(){return this.viewModel.allowedWorkflows}set allowedWorkflows(e){this.viewModel.allowedWorkflows=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get labelOptions(){return this.viewModel.labelOptions}set labelOptions(e){this.viewModel.labelOptions=e}get layerInfos(){return this.viewModel.layerInfos}set layerInfos(e){this.viewModel.layerInfos=e}get snappingOptions(){return this.viewModel.snappingOptions}set snappingOptions(e){this.viewModel.snappingOptions=e}get tooltipOptions(){return this.viewModel.tooltipOptions}set tooltipOptions(e){this.viewModel.tooltipOptions=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}castVisibleElements(e){const t={...P,...e,snappingControlsElements:{...P.snappingControlsElements,...e?.snappingControlsElements}};return a(this._snappingControls)&&(this._snappingControls.visibleElements=t.snappingControlsElements),t}startCreateWorkflowAtFeatureTypeSelection(){return w(U,"startCreateWorkflowAtFeatureTypeSelection","startCreateFeaturesWorkflowAtFeatureTypeSelection"),this.viewModel.startCreateWorkflowAtFeatureTypeSelection()}startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.viewModel.startCreateFeaturesWorkflowAtFeatureTypeSelection()}startCreateWorkflowAtFeatureCreation(e){return w(U,"startCreateWorkflowAtFeatureCreation","startCreateFeaturesWorkflowAtFeatureCreation"),this.viewModel.startCreateWorkflowAtFeatureCreation(e)}startCreateFeaturesWorkflowAtFeatureCreation(e){return this.viewModel.startCreateFeaturesWorkflowAtFeatureCreation(e)}startCreateWorkflowAtFeatureEdit(e){return w(U,"startCreateWorkflowAtFeatureEdit"),this.viewModel.startCreateWorkflowAtFeatureEdit(e)}startUpdateWorkflowAtFeatureSelection(){return this.viewModel.startUpdateWorkflowAtFeatureSelection()}startUpdateWorkflowAtMultipleFeatureSelection(e){return this.viewModel.startUpdateWorkflowAtMultipleFeatureSelection(e)}startUpdateWorkflowAtFeatureEdit(e){return this.viewModel.startUpdateWorkflowAtFeatureEdit(e)}deleteFeatureFromWorkflow(){return this.viewModel.deleteFeatureFromWorkflow()}cancelWorkflow(e){return this.viewModel.cancelWorkflow(e)}render(){const{_attachments:e,_prompt:t,viewModel:s}=this;if(!s)return A("div",{class:B.base});const{state:n}=s,i=a(t)?A("calcite-scrim",null,this.renderPrompt(t)):null;return A("div",{class:B.base},s.syncing||e.submitting?this.renderProgressBar():null,A("calcite-flow",null,this._stateStack.map((e=>this.renderState(e))),this.renderState(n)),i)}renderState(e){switch(e){case"disabled":break;case"ready":return this.renderLanding(e);case"awaiting-feature-creation-info":return this.renderTemplates(e);case"creating-features":case"editing-new-feature":case"editing-existing-feature":return this.renderAttributeEditing(e);case"awaiting-feature-to-update":return this.renderFeatureUpdating(e);case"awaiting-update-feature-candidate":return this.renderFeatureList(e);case"awaiting-feature-to-create":return this.renderFeatureCreation(e);case"adding-attachment":return this.renderAttachmentAdding(e);case"editing-attachment":return this.renderAttachmentEditing(e)}return A("div",null)}isPanelActive(e){return this.viewModel.state===e}renderTemplates(e){const{EditorPanel:t,headingLevel:s,messages:a,messagesCommon:n,_handleBack:i,_snappingControls:o,viewModel:{sketchViewModel:r}}=this;return A(t,{active:this.isPanelActive(e),key:"templates-panel",handleBack:i,heading:a.selectTemplate,headingLevel:s,messages:a,messagesCommon:n,sketchViewModel:r,snappingControls:o},A("div",{class:B.panelContent},this._featureTemplates.render()))}renderAttributeEditing(e){const{activeWorkflow:t,EditorPanel:s,messages:a,messagesCommon:n,headingLevel:i,_handleBack:o,_snappingControls:r,viewModel:l}=this;if(!t)return null;const{sketchViewModel:d}=l,c=l.featureFormViewModel;if("create-features"===t.type&&t.pendingFeatures.length<1)return this.renderFeatureCreation(e);const p="update"===t.type&&!t.data.edits.modified||l.syncing||c.updating,h="update"===t.type?a.editFeature:a.createFeatures,u="update"===t.type?n.update:n.create,m="create-features"===t.type&&"create-new"===t.createFeatureState,g="update"===t.type&&t.data.editableItem.supports.includes("delete"),v=this._shouldShowAttachmentsForWorkflow(t),w=[{label:"create-features"===t.type&&t.numPendingFeatures>1?W(a.createFeaturesTemplate,{numFeatures:t.numPendingFeatures}):u,type:"primary",disabled:p,clickHandler:this._handleSave,width:g?"half":"full"}];g&&w.push({label:n.delete,type:"tertiary",clickHandler:this._handleDelete,disabled:l.syncing,appearance:"outline",width:"half"});const f=c.inputFields.every((e=>!e.visible))&&!v?this.renderMessage(W(a.clickToFinishTemplate,{button:u})):A("div",{class:B.panelContentSection},A("div",{class:B.panelContentSectionGroup},this._featureForm.render(),v?A("div",{key:"attachments"},A(k,{level:b(i)},a.attachments),this._attachments.render()):null));return A(s,{active:this.isPanelActive(e),key:"attribute-editing-panel",heading:h,headingLevel:i,handleBack:o,messages:a,messagesCommon:n,sketchViewModel:d,snappingControls:r},A("div",{class:B.panelContent},f,m?A("calcite-scrim",null):null),this.renderFooterActions(w))}renderAttachmentAdding(e){const{_attachments:t,EditorPanel:s,_handleBack:a,headingLevel:n,messages:i,messagesCommon:o,_snappingControls:r,viewModel:{sketchViewModel:l}}=this,d=[{label:t.submitting?o.cancel:o.add,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentAdd,width:"full"}];return A(s,{active:this.isPanelActive(e),key:"attachment-adding-panel",heading:i.addAttachment,headingLevel:n,handleBack:a,messages:i,messagesCommon:o,sketchViewModel:l,snappingControls:r},A("div",{class:B.panelContent},t.render()),this.renderFooterActions(d))}renderAttachmentEditing(e){const{_attachments:t,EditorPanel:s,_handleBack:a,headingLevel:n,messages:i,messagesCommon:o,_snappingControls:r,viewModel:{sketchViewModel:l}}=this,d=[{label:o.update,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentUpdate,width:"half"},{label:o.delete,disabled:t.submitting,type:"tertiary",clickHandler:this._handleAttachmentDelete,width:"half",appearance:"outline"}];return A(s,{active:this.isPanelActive(e),key:"attachment-editing-panel",heading:i.editAttachment,headingLevel:n,handleBack:a,messages:i,messagesCommon:o,sketchViewModel:l,snappingControls:r},A("div",{class:B.panelContent},t.render()),this.renderFooterActions(d))}renderFeatureUpdating(e){const{EditorPanel:t,_handleBack:s,headingLevel:a,messages:n,messagesCommon:i,_snappingControls:o,viewModel:{sketchViewModel:r}}=this;return A(t,{active:this.isPanelActive(e),key:"feature-updating-panel",heading:n.selectFeature,headingLevel:a,handleBack:s,messages:n,messagesCommon:i,sketchViewModel:r,snappingControls:o},A("div",{class:B.panelContent},this.renderMessage(n.selectFeatureToEdit)))}renderMessage(e){return A("div",{class:B.panelContentMessage},e)}renderFeatureCreation(e){const{EditorPanel:t,_handleBack:s,headingLevel:a,messages:n,messagesCommon:i,_snappingControls:o,viewModel:r}=this,{sketchViewModel:l}=r,d=r.sketchViewModel,c=this._assertActiveCreateWorkflow().data.creationInfo.layer,p=d.canUndo()&&d.createGraphic?d.createGraphic:null,h=this._getSketchingTip(c.geometryType,p);return A(t,{active:this.isPanelActive(e),key:"feature-creation-panel",heading:n.placeFeature,headingLevel:a,handleBack:s,messages:n,messagesCommon:i,sketchViewModel:l,snappingControls:o},A("div",{class:B.panelContent},this.renderMessage(h)))}renderFooterActions(e){return e.map((({type:e,disabled:t,class:s,...a},n)=>this.renderButton({class:this.classes(B.controlButton,"secondary"===e?B.buttonSecondary:"tertiary"===e?B.buttonTertiary:null,t?B.buttonDisabled:null,s),disabled:t??!1,key:n,slot:"footer-actions",...a})))}renderPrompt({title:e,message:t,context:s,actions:a}){const n=a.secondary,i=A("calcite-button",{appearance:"solid",kind:"danger"===s?"danger":"brand",width:n?"half":"full",onclick:a.primary.action,key:"prompt-primary-button",afterCreate:L},a.primary.label),o=n&&A("calcite-button",{appearance:"outline",kind:"danger"===s?"danger":"brand",width:"half",onclick:n.action,key:"prompt-secondary-button"},n.label);return A("div",{class:`${B.promptContainer}--${s}`},A("div",{class:B.promptHeader},A("calcite-icon",{icon:"exclamation-mark-triangle"}),A(k,{class:B.promptHeading,level:this.headingLevel},e)),A("div",{class:B.promptMessage},t),A("div",{class:B.promptDivider}),A("div",{class:B.promptActions},o,i))}renderProgressBar(){return A("div",{class:this.classes(B.progressBar),key:"progress-bar"})}renderButton(e){const{disabled:t,class:s,key:a,clickHandler:n,label:i,...o}=e;return A("calcite-button",{class:s,disabled:t,key:a,onclick:n,type:"button",...o},i)}renderLanding(e){const{EditorPanel:t,headingLevel:s,messages:a,messagesCommon:n,_snappingControls:i,_featureTemplates:{viewModel:{numberOfFeatureTemplates:o}},viewModel:{canUpdate:r,sketchViewModel:l}}=this,d=!r&&0===o;return A(t,{active:this.isPanelActive(e),key:"landing-panel",heading:a.widgetLabel,headingLevel:s,showBackButton:!1,messages:a,messagesCommon:n,sketchViewModel:l,snappingControls:i},A("div",{class:B.panelContent},r?A("div",{key:"edit-actions",class:B.panelContentSection},this.renderUpdateActions()):void 0,o>0?A("div",{key:"create-actions",class:B.panelContentSection},this.renderCreateActions()):void 0,d?A("div",{key:"no-content",class:B.panelContentMessage},a.noEditableLayers):void 0))}renderUpdateActions(){const{messages:e,messagesCommon:t}=this;return A("div",null,A(k,{level:b(this.headingLevel)},e.editFeatures),A("div",{class:B.updateFeaturesActionButtons},A("calcite-action",{text:t.select,textEnabled:!0,icon:"cursor",alignment:"start",class:B.updateFeaturesActionButtonsButton,onclick:this._handleEdit})))}renderCreateActions(){const{_featureTemplates:e,headingLevel:t,messages:s}=this;return A("div",null,A(k,{level:b(t)},s.createFeatures),A("div",{key:"templates",class:B.featureTemplatesContainer},e.render()))}renderFeatureList(e){const{EditorPanel:t,_handleBack:s,headingLevel:n,messages:i,messagesCommon:o,messagesTemplates:r,_snappingControls:l,viewModel:{editableItems:d,sketchViewModel:c}}=this,p=this._assertActiveUpdateWorkflow().data.candidates,h=W(i.multipleFeaturesTemplate,{total:p.length}),u=new Map;let m=0;p.map((e=>({label:this._getLabel(e),id:e.attributes[e.layer.objectIdField],data:e}))).filter((e=>{const{label:t,data:s}=e,a=this._filterText.toLowerCase(),{title:n}=s.layer,i=d.find((e=>e.layer===s.layer));if(!i)return null;const{attachmentsOnUpdateEnabled:o,supports:r}=i;return(r.includes("update")||r.includes("delete")||o)&&(!a||t?.toLowerCase().includes(a)||n?.toLowerCase().includes(a))})).filter(a).forEach((e=>{m++;const t=e.data.layer;u.has(t)?u.get(t)?.items.push(e):u.set(t,{id:`${t.id}`,label:t.title??"",items:[e]})}));const g=d.toArray().map((({layer:e})=>u.get(e))).filter(a),v=m>10||this._filterText.length>0;return A(t,{active:this.isPanelActive(e),key:"feature-list",heading:h,headingLevel:n,handleBack:s,messages:i,messagesCommon:o,sketchViewModel:c,snappingControls:l},A("div",{class:B.panelContent},A("div",{class:B.panelContentSection},_({id:this.id,enableListScroll:!1,filterEnabled:v,filterText:this._filterText,items:g,messages:{filterPlaceholder:r.filterPlaceholder,noItems:r.noItems,noMatches:r.noMatches},onItemMouseEnter:({data:e})=>this._setCandidateFeature(e),onItemMouseLeave:()=>this._setCandidateFeature(null),onItemSelect:({data:e})=>this._setCandidateFeature(e,!0),onFilterChange:e=>this._filterText=e}))))}EditorPanel(e,...t){const{active:s,handleBack:a,heading:n,headingLevel:i,key:o,messages:r,messagesCommon:l,showBackButton:d,sketchViewModel:c,snappingControls:p}=e,{snappingControls:h,undoRedoButtons:u}=this.visibleElements;return A("calcite-flow-item",{bind:this,key:o,heading:n,headingLevel:i,showBackButton:d??!0,closable:!1,onCalciteFlowItemScroll:this._closeSnappingPopover,onCalciteFlowItemBack:a??void 0},A("div",{class:B.panelToolbar},h?[A("calcite-popover",{autoClose:s,afterCreate:this._setSnappingPopover,afterUpdate:this._setSnappingPopover,bind:this,label:r.snappingSettings,heading:r.snappingSettings,referenceElement:this._snappingButton,overlayPositioning:"fixed",placement:"bottom"},A("div",{class:B.snappingControlsPopover},p.render())),A("calcite-button",{id:`${o}__snappingButton`,afterCreate:this._setSnappingButton,afterUpdate:this._setSnappingButton,bind:this,label:r.snapping,appearance:"transparent",kind:"neutral",alignment:"icon-end-space-between",iconStart:"vertex-gps",iconEnd:"caret-down",width:"full",class:B.panelToolbarSnappingButton,onkeydown:e=>{"Escape"===e.key&&this._closeSnappingPopover()}},r.snapping)]:null,u?[A("calcite-button",{key:"undo-button",label:l.undo,appearance:"transparent",kind:"neutral",alignment:"center",iconStart:"undo",scale:"l",disabled:!c.canUndo(),onclick:c.undo.bind(c)},l.undo),A("calcite-button",{key:"redo-button",label:l.redo,appearance:"transparent",kind:"neutral",alignment:"center",iconStart:"redo",scale:"l",disabled:!c.canRedo(),onclick:c.redo.bind(c)},l.redo)]:null),t)}_closeSnappingPopover(){this._snappingPopover?.open&&this._snappingPopover.toggle()}_setSnappingPopover(e){this._snappingPopover=e}_setSnappingButton(e){this._snappingButton=e,this.scheduleRender()}_getSketchingTip(e,t){const{messages:s}=this;if("point"===e)return s.tips.clickToAddPoint;if("polygon"===e||"polyline"===e){if(!t)return s.tips.clickToStart;const a=t.geometry,n="polygon"===e?"rings":"paths",[i]=a[n];return"polygon"===e&&i<4?s.tips.clickToContinue:s.tips.clickToContinueThenDoubleClickToEnd}return s.tips.clickToAddFeature}_getLabel(e){const t=e.layer;if(!t)return null;const{objectIdField:s}=t,{attributes:a}=e,n=p(t);return n&&a[n]&&`${a[n]}`||W(this.messages.untitledFeatureTemplate,{id:a[s]})}_handleDelete(){const{messages:e,messagesCommon:t}=this;this._prompt={title:e.deleteWarningTitle,message:e.deleteWarningMessage,context:"danger",actions:{primary:{label:t.delete,action:()=>{this.viewModel.deleteFeatureFromWorkflow(),this._prompt=null}},secondary:{label:e.keepFeature,action:()=>this._prompt=null}}}}_handleSave(){const{featureFormViewModel:e}=this.viewModel;e.submit(),!e.submittable||e.validateContingencyConstraints(e.getValues(),{includeIncompleteViolations:!0}).length>0||this.viewModel.activeWorkflow?.commit()}_handleAttachmentAdd(){const{activeWorkflow:e}=this.viewModel;e&&("create-features"===e.type?(this._attachments.addFile(),e.previous()):this._attachments.addAttachment().then((()=>e.previous())))}_handleAttachmentUpdate(){const{activeWorkflow:e}=this.viewModel;e&&("create-features"===e.type?(this._attachments.updateFile(),e.previous()):this._attachments.updateAttachment().then((()=>e.previous())))}_handleAttachmentDelete(){const{messages:e,messagesCommon:t}=this;this._prompt={title:e.deleteAttachmentWarningTitle,message:e.deleteAttachmentWarningMessage,context:"danger",actions:{primary:{label:t.delete,action:()=>{const{_attachments:e}=this,{activeWorkflow:t}=this.viewModel;t&&("create-features"===t.type?(e.deleteFile(),t.previous(),this._prompt=null):e.deleteAttachment(e.viewModel.activeAttachmentInfo).then((()=>{t.previous(),this._prompt=null})))}},secondary:{label:e.keepAttachment,action:()=>this._prompt=null}}}}_handleAdd(){this.viewModel.canCreate}_handleEdit(){this.viewModel.canUpdate&&this.viewModel.startUpdateWorkflowAtFeatureSelection()}_handleDone(){this.viewModel.cancelWorkflow({force:!0})}async _handleBack(e){if(!this.activeWorkflow)return;const t=this.activeWorkflow;if(e?.stopPropagation(),this.viewModel.syncing)return;const s=()=>{t.hasPreviousStep?t.previous({cancelCurrentStep:!0}):this.viewModel.cancelWorkflow({force:!0})};if("create"===t.type||"create-features"===t.type&&t.numPendingFeatures>0||"editing-existing-feature"===t.stepId&&t.data.edits.modified){const{messages:e}=this,{type:a}=t,n="create"===a?e.cancelAddWarningMessage:e.cancelEditWarningMessage,i="create"===a?e.cancelAddTitle:e.cancelEditTitle,o="create"===a?e.continueAdding:e.continueEditing,r="create"===a?e.discardFeature:e.discardEdits;return this._prompt={title:i,message:n,context:"danger",actions:{primary:{label:r,action:()=>{this._prompt=null,s()}},secondary:{label:o,action:()=>this._prompt=null}}},void this.scheduleRender()}s()}_assertActiveCreateWorkflow(){const e=this.viewModel.activeWorkflow;if("create"===e?.type||"create-features"===e?.type)return e;throw new Error("Expected activeWorkflow to be instance of CreateWorkflow or CreateFeaturesWorkflow")}_assertActiveUpdateWorkflow(){const e=this.viewModel.activeWorkflow;if("update"===e?.type)return e;throw new Error("Expected activeWorkflow to be an UpdateWorkflow")}_shouldShowAttachmentsForWorkflow(e){if("update"===e.type)return e.data.editableItem.attachmentsOnUpdateEnabled;const t=e.data.creationInfo;if(t){const{layerInfos:e}=this,{layer:s}=t,a=this.viewModel.editableItems.find((e=>e.layer===s));if(a)return a.attachmentsOnCreateEnabled;const{data:n}=s.capabilities,i=e&&e.find((e=>e.layer===s));return"supportsAttachment"in n&&n.supportsAttachment&&(!i||!1!==i.allowAttachments&&!1!==i.attachmentsOnUpdateEnabled)}return!1}};e([l()],V.prototype,"_attachments",void 0),e([l({readOnly:!0})],V.prototype,"activeWorkflow",null),e([l()],V.prototype,"allowedWorkflows",null),e([l()],V.prototype,"useDeprecatedCreateWorkflow",void 0),e([l()],V.prototype,"headingLevel",void 0),e([l()],V.prototype,"iconClass",void 0),e([l()],V.prototype,"label",null),e([l()],V.prototype,"labelOptions",null),e([l()],V.prototype,"layerInfos",null),e([l(),M("esri/widgets/Editor/t9n/Editor")],V.prototype,"messages",void 0),e([l(),M("esri/t9n/common")],V.prototype,"messagesCommon",void 0),e([l(),M("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],V.prototype,"messagesTemplates",void 0),e([l()],V.prototype,"snappingOptions",null),e([l()],V.prototype,"tooltipOptions",null),e([l()],V.prototype,"supportingWidgetDefaults",void 0),e([l()],V.prototype,"view",null),e([l(),F(["workflow-cancel","workflow-commit"])],V.prototype,"viewModel",void 0),e([l()],V.prototype,"visibleElements",void 0),e([d("visibleElements")],V.prototype,"castVisibleElements",null),e([C()],V.prototype,"_handleDelete",null),e([C()],V.prototype,"_handleAttachmentAdd",null),e([C()],V.prototype,"_handleAttachmentUpdate",null),e([C()],V.prototype,"_handleAttachmentDelete",null),e([C()],V.prototype,"_handleAdd",null),e([C()],V.prototype,"_handleEdit",null),e([C()],V.prototype,"_handleDone",null),V=e([c(j)],V);const x=V;export{x as default};
|
package/widgets/FeatureForm.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.26/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{neverReached as t}from"../core/compilerUtils.js";import{isSome as i,isNone as a}from"../core/maybe.js";import{watch as s}from"../core/reactiveUtils.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import{subclass as n}from"../core/accessorSupport/decorators/subclass.js";import{getDomainRange as r}from"../layers/support/domainUtils.js";import{getFieldRange as o}from"../layers/support/fieldUtils.js";import u from"./Widget.js";import{CSS as d}from"./FeatureForm/css.js";import p from"./FeatureForm/FeatureFormViewModel.js";import{Heading as c,incrementHeadingLevel as m}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as h}from"./support/decorators/messageBundle.js";import{vmEvent as v}from"./support/decorators/vmEvent.js";import{tsx as b}from"./support/jsxFactory.js";import{DateTime as f}from"luxon";import{getLocale as g}from"../intl/locale.js";const _={datePattern:"D",timePattern:"tt"};function F(e){return e&&e.inputFields}const y="data-field-name";let I=class extends u{constructor(e,t){super(e,t),this._activeDateFieldEdit=null,this._activeInputName=null,this._activeNumberFieldEdit=null,this._fieldFocusNeeded=!1,this._fieldToInitialIncompatibleDomainValue=new Map,this._switchFieldsWithInitialIncompatibleValue=new Set,this._userUpdatedInputFieldNames=new Set,this.disabled=!1,this.groupDisplay="all",this.headingLevel=2,this.messages=null,this.messagesTemplates=null,this.viewModel=new p,this._handleRadioInputChange=e=>{this._commitInputValue(e.target)},this._handleInputInput=e=>{this._commitInputValue(e.currentTarget,!0)},this._handleFormKeyDown=this._handleFormKeyDown.bind(this),this._handleInputBlur=this._handleInputBlur.bind(this),this._handleInputFocus=this._handleInputFocus.bind(this),this._handleNumberInputMouseDown=this._handleNumberInputMouseDown.bind(this),this._handleInputKeyDown=this._handleInputKeyDown.bind(this),this._handleOptionChange=this._handleOptionChange.bind(this),this._handleGroupClick=this._handleGroupClick.bind(this),this._handleSubmit=this._handleSubmit.bind(this),this._afterInputCreateOrUpdate=this._afterInputCreateOrUpdate.bind(this)}initialize(){this.addHandles([s((()=>this.feature),(()=>{const e=this._getFocusableInput("forward");this._activeInputName=e&&e.name,this._userUpdatedInputFieldNames.clear(),this._fieldToInitialIncompatibleDomainValue.clear(),this._switchFieldsWithInitialIncompatibleValue.clear(),this._fieldFocusNeeded=!0})),this.on("submit",(e=>{if(e.invalid.length>0){const[t]=e.invalid;e.invalid.forEach((e=>this._userUpdatedInputFieldNames.add(e))),this._activeInputName=t,this._fieldFocusNeeded=!0,this.scheduleRender()}}))])}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-combobox.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item-group.js"),import("@esri/calcite-components/dist/components/calcite-input-message.js"),import("@esri/calcite-components/dist/components/calcite-progress.js"),import("@esri/calcite-components/dist/components/calcite-switch.js")])}destroy(){this._userUpdatedInputFieldNames.clear(),this._userUpdatedInputFieldNames=null}get feature(){return this.viewModel.feature}set feature(e){this.viewModel.feature=e}get formTemplate(){return this.viewModel.formTemplate}set formTemplate(e){this.viewModel.formTemplate=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get strict(){return this.viewModel.strict}set strict(e){this.viewModel.strict=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}getValues(){return this.viewModel.getValues()}submit(){return this.viewModel.submit()}render(){const{state:e}=this.viewModel;return b("div",{class:this.classes(d.base,d.widget,d.panel)},"ready"===e?this.renderForm():null)}renderForm(){const{formTemplate:e}=this,t=i(e)&&e.title&&b(c,{key:"title",level:this.headingLevel},e.title),a=i(e)&&e.description&&b("p",{class:d.description,key:"description"},e.description),s=t||a?b("div",{class:d.formHeader},t,a):null;return b("form",{class:d.form,novalidate:!0,onsubmit:this._handleSubmit,onkeydown:this._handleFormKeyDown},s,this.renderFields())}renderFields(){const{viewModel:{inputFields:e}}=this;return e.filter((e=>e.visible)).map(((e,t)=>F(e)?this.renderGroup(e,t):this.renderLabeledField(e)))}renderGroup(e,t){const{formTemplate:a,disabled:s}=this,{description:l,inputFields:n,label:r,state:o}=e,u=n.filter((e=>e.visible)),p=this.viewModel.findField(this._activeInputName),h=!(!p||p.group!==e),v=`${this.id}_group_${t}`,f=`${this.id}_group-label_${t}`,g=`${this.id}_group-description_${t}`,_=l?b("p",{class:this.classes(d.groupDescription,d.description),id:g},l):null,F="sequential"===this.groupDisplay,y=F?h:"expanded"===o,I=y?d.collapseIcon:d.expandIcon;return b("fieldset",{"aria-expanded":y.toString(),"aria-labelledby":f,"aria-describedby":l?g:"",class:this.classes(d.group,F?d.groupSequential:null,y?null:d.groupCollapsed,h?d.groupActive:null,s?d.inputDisabled:null),disabled:s,"data-group":e,id:v,key:t,onclick:this._handleGroupClick},b("button",{role:F?"presentation":void 0,class:d.groupHeader,type:"button",tabIndex:F?-1:0},b("div",{class:d.groupTitle},b(c,{class:d.groupLabel,id:f,level:i(a)&&a.title?m(this.headingLevel):this.headingLevel},r),_),F?null:b("span",{class:this.classes(I,d.groupToggleIcon)})),u.map((e=>this.renderLabeledField(e))))}_getFocusableInput(e,t){const i=this.viewModel.allInputFields,a="forward"===e?i:i.slice().reverse();let s;if(t)if(F(t))s=a.indexOf(t.inputFields[0]);else{let i;if(this._isInputFieldInGroup(t)&&"collapsed"===t.group.state){const{inputFields:a}=t.group;i="forward"===e?a[a.length-1]:a[0]}else i=t;s=a.indexOf(i)+1}else s=0;for(let l=s;l<a.length;l++){const e=a[l];if(e.visible)return e}return null}renderLabeledField(e){const{feature:t,label:i,layer:a,type:s}=e;return b("label",{key:`${a.id}-${t.uid}-${e.name}`,class:d.label},[i,"unsupported"!==s?this.renderInputField(e):this.renderUnsupportedField(e),this.renderAuxiliaryText(e)])}renderInputField(e){const{domain:t,name:a,type:s,updating:l,value:n}=e,r=this.getCommonInputProps(e);if("coded-value"===t?.type){if(this._inputFieldHasInputType(e,"switch")){const{fieldElement:t}=e;if(!(this._switchFieldsWithInitialIncompatibleValue.has(a)||null==n||t.input.onValue!==n&&t.input.offValue!==n))return this.renderSwitchInputField(e,r);this._switchFieldsWithInitialIncompatibleValue.add(a)}return"radio-buttons"===e.inputType?this.renderRadioButtonsInputField(e,t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),r):this.renderSelectInputField(e,this._getFieldValueOptions(a,t),r)}if("datetime-picker"===e.inputType||"date"===s)return this.renderDateInputField(e,r);const o="number"===s?b("input",{type:"number",...r,value:i(this._activeNumberFieldEdit)&&this._activeNumberFieldEdit.fieldName===e.name?this._activeNumberFieldEdit.value:`${r.value}`}):"text-area"===e.inputType?b("textarea",{...r}):b("input",{type:"text",...r});return l?b("div",{class:d.inputFieldWrapper},o,b("div",{class:d.inputFieldLoader},b("calcite-progress",{type:"indeterminate"}))):o}_parseDateTime(e,t,i){if(i){let a=f.fromJSDate(this._parseDate(e,i));const s=f.fromMillis(t.value??Date.now());return a="date"===i?a.set({hour:s.hour,minute:s.minute,second:s.second}):a.set({day:s.day,month:s.month,year:s.year}),a.isValid?a.toMillis():null}const a=f.fromJSDate(this._parseDate(e));return a.isValid?a.toMillis():null}renderDateInputField(e,t){const{value:i,includeTime:a}=e,{date:s,time:l}=this._formatDate(0),n=`${this.id}-${t.key}`,r=`${n}-date`,o=`${n}-time`,{_activeDateFieldEdit:u}=this;let{date:p,time:c}=this._formatDate(i);return u?.fieldName===e.name&&(p=u.date.input?.value??p,c=u.time.input?.value??c),b("div",{key:`${t.key}-date`,class:d.dateInputContainer},b("div",{class:this.classes(d.dateInputPart,a?null:d.loneDateInputPart)},b("input",{"aria-label":e.label,"aria-describedby":r,type:"text",...t,"data-date-part":"date",class:this.classes(t.class,d.inputDate),value:p}),b("div",{class:d.dateFormatHint,id:r},s)),a?b("div",{class:d.dateInputPart,key:"time-input"},b("input",{"aria-describedby":o,"aria-label":e.label,type:"text",...t,"data-date-part":"time",class:this.classes(t.class,d.inputTime),value:c}),b("div",{class:d.dateFormatHint,id:o},l)):null)}renderUnsupportedField(e){const t=this.getCommonInputProps(e);return b("input",{afterCreate:t.afterCreate,afterUpdate:t.afterUpdate,disabled:t.disabled,class:this.classes(d.input,d.inputField,d.inputDisabled),onfocus:t.onfocus,readOnly:!0,tabIndex:t.tabIndex,type:"text",value:t.value,[y]:t[y]})}renderSelectInputField(e,t,i){const{value:s}=e,{messages:l,messagesTemplates:n}=this,r=t.map((e=>e.map((e=>b("calcite-combobox-item",{value:`${e.value}`,"text-label":e.name,key:`#${e.value}`,selected:s===e.value}))))),[o,u]=r;this._registerIncompatibleValue(s,t.flat(),e,(e=>{u.unshift(b("calcite-combobox-item",{value:`${e}`,"text-label":`${e}`,key:"incompatible-option",readOnly:!0}))}));const d=u.length>0?[b("calcite-combobox-item-group",{key:"recommended",label:l.recommended},o),b("calcite-combobox-item-group",{key:"other",label:n.other},u)]:o,p=a(e.fieldElement)||this._inputFieldHasInputType(e,"combo-box")&&e.fieldElement.input.showNoValueOption;if(!e.required&&p){const t="",i=this._inputFieldHasInputType(e,"combo-box")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty;d.unshift(b("calcite-combobox-item",{value:t,"text-label":this.messages.empty,key:"empty-option"},i))}return b("calcite-combobox",{...i,"selection-mode":"single","overlay-positioning":"fixed",disabled:i.disabled||i.readOnly,allowCustomValues:!1,onCalciteComboboxChange:e=>this._handleOptionChange(e.target)},d)}_registerIncompatibleValue(e,t,i,a){const s=this._fieldToInitialIncompatibleDomainValue,l=s.has(i.name);(l||null!=e&&""!==e&&!t.some((t=>t.value===e))||l)&&(l||s.set(i.name,e),a?.(s.get(i.name)))}renderRadioButtonsInputField(e,t,i){const{value:s}=e,l=t.map((t=>this.renderRadioButton({key:t.name,label:t.name,name:e.name,value:t.value,selected:t.value===s,props:i})));this._registerIncompatibleValue(s,t,e);const n=a(e.fieldElement)||this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.showNoValueOption;if(!e.required&&n){const t="",a=this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty,n=s===t||null===s;l.unshift(this.renderRadioButton({key:"empty-option",label:a,name:e.name,value:t,selected:n,props:i}))}return b("div",{key:`${i.key}-radio`,class:d.inputRadioGroup},l)}renderSwitchInputField(e,t){const{value:i}=e,a=!!this._inputFieldHasInputType(e,"switch")&&i===e.fieldElement.input.onValue;return b("calcite-switch",{...t,class:d.inputSwitch,onCalciteSwitchChange:e=>{this._parseValue(e.currentTarget)},checked:a,disabled:t.disabled||t.readOnly})}renderRadioButton({key:e,name:t,value:i,selected:a,label:s,props:l}){return b("label",{key:e,class:d.inputRadioLabel},b("input",{...l,class:d.inputRadio,name:t,type:"radio",value:i,checked:a,onchange:this._handleRadioInputChange}),s)}renderAuxiliaryText(e){const t=this._userUpdatedInputFieldNames.has(e.name)&&!e.valid?e.errorMessage:i(this.viewModel.contingencyConstraintViolations.get(e.name))?this.messages.validationErrors.valuesIncompatible:i(e.valueExpressionExecutor)&&e.valueExpressionExecutor.stale?this.messages.valueExpressionError:null;return i(t)?b("calcite-input-message",{status:"invalid",icon:!0},t):e.description?b("div",{key:"description",class:d.description},e.description):void 0}getCommonInputProps(e){const{disabled:t,groupDisplay:a}=this,{editable:s,group:l,hint:n,maxLength:r,minLength:o,name:u,required:p,type:c,valid:m,value:h}=e,v=this._userUpdatedInputFieldNames.has(u),b=!s,f="all"===a&&i(l)&&"collapsed"===l.state;return{afterCreate:this._afterInputCreateOrUpdate,afterUpdate:this._afterInputCreateOrUpdate,"aria-invalid":m?"false":"true",class:this.classes(d.input,d.inputField,t||b?d.inputDisabled:null,v&&!m?d.inputInvalid:null),key:u,label:u,minlength:o>-1?`${o}`:"",maxlength:r>-1?`${r}`:"",...this._getNumberFieldConstraints(e),disabled:t,readOnly:b,value:null==h?"":`${h}`,[y]:u,onfocus:this._handleInputFocus,oninput:this._handleInputInput,onblur:this._handleInputBlur,onkeydown:this._handleInputKeyDown,onmousedown:"number"===c?this._handleNumberInputMouseDown:null,placeholder:"number"===c||"text"===c?n:"",required:p,tabIndex:f?-1:0}}_isInputFieldInGroup(e){return!F(e)&&i(e.group)}_handleNumberInputMouseDown({target:e}){e.focus(),this.scheduleRender()}_getFieldValueOptions(e,t){const i=t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),a=this.viewModel.fieldsWithContingentValues.has(e)?this._getContingentValueOptions(e):[];if(a.length>0){const e=new Set(a.map((e=>e.value)));return[a,i.filter((t=>!e.has(t.value)))]}return[i,[]]}_getContingentValueOptions(e){const t={};for(const l of this.viewModel.allInputFields){const{name:i,value:s}=l;!a(s)&&i!==e&&this.viewModel.fieldsWithContingentValues.has(i)&&(t[i]=s)}const i=this.viewModel.joinedContingentValues.slice(),s=new Map;for(const l of i){const i=l.values[e];if(a(i)||"code"!==i.objectType&&"null"!==i.objectType)continue;const{code:n,name:r}="null"===i.objectType?{code:"",name:this.messages.empty}:i.codedValue;if(s.has(n))continue;Object.entries(t).every((([e,t])=>!l.values.hasOwnProperty(e)||this._valueIsValidContingentValue(t,l.values[e])))&&s.set(n,{name:r,value:n})}return[...s.values()]}_getInputFieldFromInput(e){return this.viewModel.findField(e.getAttribute(y))}_getNumberFieldConstraints(e){const t=r(e.domain)||o(e.field);return t&&t.max!==Number.MAX_VALUE&&t.min!==Number.MIN_VALUE?t:{min:null,max:null}}_afterInputCreateOrUpdate(e){const{viewModel:t}=this,i=this._getInputFieldFromInput(e),a=t.findField(this._activeInputName),s=this._fieldToInitialIncompatibleDomainValue.get(i.name)===i.value;this._fieldFocusNeeded&&a===i&&("radio-buttons"!==i.inputType||s||e.checked)&&(this._fieldFocusNeeded=!1,this._isInputFieldInGroup(i)&&(i.group.state="expanded"),e.focus())}_handleInputFocus(e){const t=e.target,i=this._getInputFieldFromInput(t);this._activeInputName=i.name,"date"===i.type?this._syncDateFieldEdits(t):this._isNumberInputField(i)&&this._setUpNumberFieldEdit(t)}_isNumberInputField({domain:e,inputType:t="text-box",type:i}){return"number"===i&&"text-box"===t&&(!e||"coded-value"!==e.type)}_handleInputBlur(e){const t=e.target,a=this._getInputFieldFromInput(t);if("date"===a.type){const i=e.relatedTarget,s=i&&this._getInputFieldFromInput(i);if(s&&"date"===a.type&&"date"===s.type&&a.field===s.field){if(""!==t.value&&""===i.value){const s=i.getAttribute("data-date-part");i.value=this._formatDate(a.value??Date.now())[s],this._parseDate(t.value,t.getAttribute("data-date-part"))&&this._commitInputValue(e.target,!0,!1)}return}}"number"===a.type&&i(this._activeNumberFieldEdit)&&(this._activeNumberFieldEdit.input.value=`${a.value}`,this._activeNumberFieldEdit=null),this._commitInputValue(t),this.scheduleRender()}_commitInputValue(e,t=!1,a=!0){const s=this._getInputFieldFromInput(e);if(this._activeDateFieldEdit){const{date:i,time:l}=this._activeDateFieldEdit,n=this._parseDateTime(e.value,s,i.active?"date":"time"),r=null!==this.viewModel.getValue(s.name),o=i.input&&(l.input||!s.includeTime);if(t){if(null===n)return;(o||!a||r)&&this._updateDateFieldValue(s,n)}else{if(""===i.input?.value||""===l.input?.value)this._updateDateFieldValue(s,null);else if(o){const e=`${i.input.value} ${l.input?.value??""}`,t=this._parseDateTime(e,s);!(null!==t)&&r||this._updateDateFieldValue(s,t)}this._activeDateFieldEdit=null}}else i(this._activeNumberFieldEdit)&&this._isNumberInputField(s)&&(this._activeNumberFieldEdit.value=e.value),this._updateFieldValue(e)}_handleInputKeyDown(e){const{key:t,altKey:i,ctrlKey:a,metaKey:s}=e,l=this._getInputFieldFromInput(e.target);if("Enter"===t)this._isInputFieldInGroup(l)&&"collapsed"===l.group.state&&(l.group.state="expanded");else{const{type:n}=l.field,r="single"===n||"double"===n;if(("integer"===n||"small-integer"===n||r)&&(!i&&!a&&!s)&&1===t.length){const i=Number(t),a=["-","+"],s=["e","."],l=r?[...a,...s]:a;isNaN(i)&&!l.includes(t)&&e.preventDefault()}}}_setUpNumberFieldEdit(e){const t=this._getInputFieldFromInput(e);this._activeNumberFieldEdit={fieldName:t.name,input:e,value:e.value}}_syncDateFieldEdits(e){const t=this._getInputFieldFromInput(e);if("date"!==t.type)return;const i=e.getAttribute("data-date-part"),a="date"===i?{value:e.value,input:e,active:!0}:{...this._activeDateFieldEdit?.date,active:!1},s="time"===i?{value:e.value,input:e,active:!0}:{...this._activeDateFieldEdit?.time,active:!1};this._activeDateFieldEdit={fieldName:t.name,date:a,time:s}}_updateFieldValue(e){const t=e.getAttribute(y);if(this.viewModel.setValue(t,this._parseValue(e)),this._userUpdatedInputFieldNames.add(t),this.viewModel.fieldsWithContingentValues.has(t)){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>i(t))));this.viewModel.validateContingencyConstraints(e)}}_updateDateFieldValue(e,t){this.viewModel.setValue(e.name,t),this._userUpdatedInputFieldNames.add(e.name)}_parseValue(e){const t=this._getInputFieldFromInput(e),i=e.value;if(this._inputFieldHasInputType(t,"switch")&&"CALCITE-COMBOBOX"!==e.tagName)return e.checked?t.fieldElement.input.onValue:t.fieldElement.input.offValue;if("radio-buttons"===t.inputType&&"radio"===e.type&&!e.checked)return t.value;const{type:a}=t;if("number"===a)return i?parseFloat(i):null;if("date"===a){if(!i)return null;const a=Number(i);if(!isNaN(a))return a;const s=e.getAttribute("data-date-part"),l=this._parseDate(i,s);if(!l)return null;let n=f.fromJSDate(l);const r=t.domain,o=f.now();let u=o;if(r&&"range"===r.type){const e=f.fromMillis(r.maxValue);o<e&&(u=e)}const d=this.viewModel.getValue(t.name),p=null!=d?f.fromMillis(d):u;return n="date"===s?n.set({hour:p.hour,minute:p.minute,second:p.second}):n.set({day:p.day,month:p.month,year:p.year}),n.toMillis()}return i}_handleOptionChange(e){this._commitInputValue(e),this.scheduleRender()}_handleGroupClick(e){const t=e.currentTarget["data-group"],i="expanded"===t.state,a="sequential"===this.groupDisplay,s=`.${d.groupHeader}`;if(!(i&&!e.target.closest(s))){if(this._activeInputName=this._getFocusableInput("forward",t)?.name,a){const a=e.target.closest(s);if(i&&!a)return;this.viewModel.inputFields.forEach((e=>{F(e)&&e!==t&&(e.state="collapsed")}))}t.state=i?"collapsed":"expanded",this._fieldFocusNeeded=a,this.scheduleRender()}}_handleSubmit(e){e.preventDefault()}_handleFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_formatDate(e){if(null==e)return{date:"",time:""};const t=f.fromMillis(e,{locale:g(),numberingSystem:"latn"});return{date:t.toLocaleString({year:"numeric",month:"2-digit",day:"2-digit"}),time:t.toFormat(_.timePattern)}}_parseDate(e,t){if(null==e||""===e)return null;const{timePattern:i,datePattern:a}=_,s=t?"date"===t?a:i:`${a} ${i}`,l=f.fromFormat(e,s,{locale:g(),numberingSystem:"latn"});return l.isValid?l.toJSDate():null}_inputFieldHasInputType(e,t){return i(e.fieldElement)&&e.fieldElement.input?.type===t}_valueIsValidContingentValue(e,i){switch(i.objectType){case"any":return!0;case"null":return null==e;case"code":return e===i.codedValue?.code;case"range":return e>=i.minValue&&e<=i.maxValue;default:return t(i.objectType),!1}}};e([l()],I.prototype,"disabled",void 0),e([l()],I.prototype,"feature",null),e([l()],I.prototype,"formTemplate",null),e([l()],I.prototype,"groupDisplay",void 0),e([l()],I.prototype,"headingLevel",void 0),e([l()],I.prototype,"label",null),e([l()],I.prototype,"layer",null),e([l(),h("esri/widgets/FeatureForm/t9n/FeatureForm")],I.prototype,"messages",void 0),e([l(),h("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],I.prototype,"messagesTemplates",void 0),e([l()],I.prototype,"spatialReference",null),e([l()],I.prototype,"strict",null),e([l()],I.prototype,"view",null),e([l(),v(["value-change","submit"])],I.prototype,"viewModel",void 0),I=e([n("esri.widgets.FeatureForm")],I);const w=I;export{w as default};
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{neverReached as t}from"../core/compilerUtils.js";import{isSome as i,isNone as a}from"../core/maybe.js";import{watch as s}from"../core/reactiveUtils.js";import{property as n}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import{subclass as l}from"../core/accessorSupport/decorators/subclass.js";import{getDomainRange as r}from"../layers/support/domainUtils.js";import{getFieldRange as o}from"../layers/support/fieldUtils.js";import u from"./Widget.js";import{CSS as d}from"./FeatureForm/css.js";import p from"./FeatureForm/FeatureFormViewModel.js";import{Heading as c,incrementHeadingLevel as m}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as h}from"./support/decorators/messageBundle.js";import{vmEvent as v}from"./support/decorators/vmEvent.js";import{tsx as b}from"./support/jsxFactory.js";import{DateTime as f}from"luxon";import{getLocale as g}from"../intl/locale.js";const _={datePattern:"D",timePattern:"tt"};function F(e){return e&&e.inputFields}const y="data-field-name";let I=class extends u{constructor(e,t){super(e,t),this._activeDateFieldEdit=null,this._activeInputName=null,this._activeNumberFieldEdit=null,this._fieldFocusNeeded=!1,this._fieldToInitialIncompatibleDomainValue=new Map,this._switchFieldsWithInitialIncompatibleValue=new Set,this._userUpdatedInputFieldNames=new Set,this.disabled=!1,this.groupDisplay="all",this.headingLevel=2,this.messages=null,this.messagesTemplates=null,this.viewModel=new p,this._handleRadioInputChange=e=>{this._commitInputValue(e.target)},this._handleInputInput=e=>{this._commitInputValue(e.currentTarget,!0)},this._handleFormKeyDown=this._handleFormKeyDown.bind(this),this._handleInputBlur=this._handleInputBlur.bind(this),this._handleInputFocus=this._handleInputFocus.bind(this),this._handleNumberInputMouseDown=this._handleNumberInputMouseDown.bind(this),this._handleInputKeyDown=this._handleInputKeyDown.bind(this),this._handleOptionChange=this._handleOptionChange.bind(this),this._handleGroupClick=this._handleGroupClick.bind(this),this._handleSubmit=this._handleSubmit.bind(this),this._afterInputCreateOrUpdate=this._afterInputCreateOrUpdate.bind(this)}initialize(){this.addHandles([s((()=>this.feature),(()=>{const e=this._getFocusableInput("forward");this._activeInputName=e&&e.name,this._userUpdatedInputFieldNames.clear(),this._fieldToInitialIncompatibleDomainValue.clear(),this._switchFieldsWithInitialIncompatibleValue.clear(),this._fieldFocusNeeded=!0})),this.on("submit",(e=>{if(e.invalid.length>0){const[t]=e.invalid;e.invalid.forEach((e=>this._userUpdatedInputFieldNames.add(e))),this._activeInputName=t,this._fieldFocusNeeded=!0,this.scheduleRender()}}))])}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-combobox.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item-group.js"),import("@esri/calcite-components/dist/components/calcite-input-message.js"),import("@esri/calcite-components/dist/components/calcite-progress.js"),import("@esri/calcite-components/dist/components/calcite-switch.js")])}destroy(){this._userUpdatedInputFieldNames.clear(),this._userUpdatedInputFieldNames=null}get feature(){return this.viewModel.feature}set feature(e){this.viewModel.feature=e}get formTemplate(){return this.viewModel.formTemplate}set formTemplate(e){this.viewModel.formTemplate=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get strict(){return this.viewModel.strict}set strict(e){this.viewModel.strict=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}getValues(){return this.viewModel.getValues()}submit(){return this.viewModel.submit()}render(){const{state:e}=this.viewModel;return b("div",{class:this.classes(d.base,d.widget,d.panel)},"ready"===e?this.renderForm():null)}renderForm(){const{formTemplate:e}=this,t=i(e)&&e.title&&b(c,{key:"title",level:this.headingLevel},e.title),a=i(e)&&e.description&&b("p",{class:d.description,key:"description"},e.description),s=t||a?b("div",{class:d.formHeader},t,a):null;return b("form",{class:d.form,novalidate:!0,onsubmit:this._handleSubmit,onkeydown:this._handleFormKeyDown},s,this.renderFields())}renderFields(){const{viewModel:{inputFields:e}}=this;return e.filter((e=>e.visible)).map(((e,t)=>F(e)?this.renderGroup(e,t):this.renderLabeledField(e)))}renderGroup(e,t){const{formTemplate:a,disabled:s}=this,{description:n,inputFields:l,label:r,state:o}=e,u=l.filter((e=>e.visible)),p=this.viewModel.findField(this._activeInputName),h=!(!p||p.group!==e),v=`${this.id}_group_${t}`,f=`${this.id}_group-label_${t}`,g=`${this.id}_group-description_${t}`,_=n?b("p",{class:this.classes(d.groupDescription,d.description),id:g},n):null,F="sequential"===this.groupDisplay,y=F?h:"expanded"===o,I=y?d.collapseIcon:d.expandIcon;return b("fieldset",{"aria-expanded":y.toString(),"aria-labelledby":f,"aria-describedby":n?g:"",class:this.classes(d.group,F?d.groupSequential:null,y?null:d.groupCollapsed,h?d.groupActive:null,s?d.inputDisabled:null),disabled:s,"data-group":e,id:v,key:t,onclick:this._handleGroupClick},b("button",{role:F?"presentation":void 0,class:d.groupHeader,type:"button",tabIndex:F?-1:0},b("div",{class:d.groupTitle},b(c,{class:d.groupLabel,id:f,level:i(a)&&a.title?m(this.headingLevel):this.headingLevel},r),_),F?null:b("span",{class:this.classes(I,d.groupToggleIcon)})),u.map((e=>this.renderLabeledField(e))))}_getFocusableInput(e,t){const i=this.viewModel.allInputFields,a="forward"===e?i:i.slice().reverse();let s;if(t)if(F(t))s=a.indexOf(t.inputFields[0]);else{let i;if(this._isInputFieldInGroup(t)&&"collapsed"===t.group.state){const{inputFields:a}=t.group;i="forward"===e?a[a.length-1]:a[0]}else i=t;s=a.indexOf(i)+1}else s=0;for(let n=s;n<a.length;n++){const e=a[n];if(e.visible)return e}return null}renderLabeledField(e){const{feature:t,label:i,layer:a,type:s}=e;return b("label",{key:`${a.id}-${t.uid}-${e.name}`,class:d.label},[i,"unsupported"!==s?this.renderInputField(e):this.renderUnsupportedField(e),this.renderAuxiliaryText(e)])}renderInputField(e){const{domain:t,name:a,type:s,updating:n,value:l}=e,r=this.getCommonInputProps(e);if("coded-value"===t?.type){if(this._inputFieldHasInputType(e,"switch")){const{fieldElement:t}=e;if(!(this._switchFieldsWithInitialIncompatibleValue.has(a)||null==l||t.input.onValue!==l&&t.input.offValue!==l))return this.renderSwitchInputField(e,r);this._switchFieldsWithInitialIncompatibleValue.add(a)}return"radio-buttons"===e.inputType?this.renderRadioButtonsInputField(e,t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),r):this.renderSelectInputField(e,this._getFieldValueOptions(a,t),r)}if("datetime-picker"===e.inputType||"date"===s)return this.renderDateInputField(e,r);const o="number"===s?b("input",{type:"number",...r,value:i(this._activeNumberFieldEdit)&&this._activeNumberFieldEdit.fieldName===e.name?this._activeNumberFieldEdit.value:`${r.value}`}):"text-area"===e.inputType?b("textarea",{...r}):b("input",{type:"text",...r});return n?b("div",{class:d.inputFieldWrapper},o,b("div",{class:d.inputFieldLoader},b("calcite-progress",{type:"indeterminate"}))):o}_parseDateTime(e,t,i){if(i){let a=f.fromJSDate(this._parseDate(e,i));const s=f.fromMillis(t.value??Date.now());return a="date"===i?a.set({hour:s.hour,minute:s.minute,second:s.second}):a.set({day:s.day,month:s.month,year:s.year}),a.isValid?a.toMillis():null}const a=f.fromJSDate(this._parseDate(e));return a.isValid?a.toMillis():null}renderDateInputField(e,t){const{value:i,includeTime:a}=e,{date:s,time:n}=this._formatDate(0),l=`${this.id}-${t.key}`,r=`${l}-date`,o=`${l}-time`,{_activeDateFieldEdit:u}=this;let{date:p,time:c}=this._formatDate(i);return u?.fieldName===e.name&&(p=u.date.input?.value??p,c=u.time.input?.value??c),b("div",{key:`${t.key}-date`,class:d.dateInputContainer},b("div",{class:this.classes(d.dateInputPart,a?null:d.loneDateInputPart)},b("input",{"aria-label":e.label,"aria-describedby":r,type:"text",...t,"data-date-part":"date",class:this.classes(t.class,d.inputDate),value:p}),b("div",{class:d.dateFormatHint,id:r},s)),a?b("div",{class:d.dateInputPart,key:"time-input"},b("input",{"aria-describedby":o,"aria-label":e.label,type:"text",...t,"data-date-part":"time",class:this.classes(t.class,d.inputTime),value:c}),b("div",{class:d.dateFormatHint,id:o},n)):null)}renderUnsupportedField(e){const t=this.getCommonInputProps(e);return b("input",{afterCreate:t.afterCreate,afterUpdate:t.afterUpdate,disabled:t.disabled,class:this.classes(d.input,d.inputField,d.inputDisabled),onfocus:t.onfocus,readOnly:!0,tabIndex:t.tabIndex,type:"text",value:t.value,[y]:t[y]})}renderSelectInputField(e,t,i){const{value:s}=e,{messages:n,messagesTemplates:l}=this,r=t.map((e=>e.map((e=>b("calcite-combobox-item",{value:`${e.value}`,textLabel:e.name,key:`#${e.value}`,selected:s===e.value}))))),[o,u]=r;this._registerIncompatibleValue(s,t.flat(),e,(e=>{u.unshift(b("calcite-combobox-item",{value:`${e}`,textLabel:`${e}`,key:"incompatible-option",readOnly:!0}))}));const d=u.length>0?[b("calcite-combobox-item-group",{key:"recommended",label:n.recommended},o),b("calcite-combobox-item-group",{key:"other",label:l.other},u)]:o,p=a(e.fieldElement)||this._inputFieldHasInputType(e,"combo-box")&&e.fieldElement.input.showNoValueOption;if(!e.required&&p){const t="",i=this._inputFieldHasInputType(e,"combo-box")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty;d.unshift(b("calcite-combobox-item",{value:t,textLabel:this.messages.empty,key:"empty-option"},i))}return b("calcite-combobox",{...i,selectionMode:"single",overlayPositioning:"fixed",disabled:i.disabled||i.readOnly,allowCustomValues:!1,onCalciteComboboxChange:e=>this._handleOptionChange(e.target)},d)}_registerIncompatibleValue(e,t,i,a){const s=this._fieldToInitialIncompatibleDomainValue,n=s.has(i.name);(n||null!=e&&""!==e&&!t.some((t=>t.value===e))||n)&&(n||s.set(i.name,e),a?.(s.get(i.name)))}renderRadioButtonsInputField(e,t,i){const{value:s}=e,n=t.map((t=>this.renderRadioButton({key:t.name,label:t.name,name:e.name,value:t.value,selected:t.value===s,props:i})));this._registerIncompatibleValue(s,t,e);const l=a(e.fieldElement)||this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.showNoValueOption;if(!e.required&&l){const t="",a=this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty,l=s===t||null===s;n.unshift(this.renderRadioButton({key:"empty-option",label:a,name:e.name,value:t,selected:l,props:i}))}return b("div",{key:`${i.key}-radio`,class:d.inputRadioGroup},n)}renderSwitchInputField(e,t){const{value:i}=e,a=!!this._inputFieldHasInputType(e,"switch")&&i===e.fieldElement.input.onValue;return b("calcite-switch",{...t,class:d.inputSwitch,onCalciteSwitchChange:e=>{this._parseValue(e.currentTarget)},checked:a,disabled:t.disabled||t.readOnly})}renderRadioButton({key:e,name:t,value:i,selected:a,label:s,props:n}){return b("label",{key:e,class:d.inputRadioLabel},b("input",{...n,class:d.inputRadio,name:t,type:"radio",value:i,checked:a,onchange:this._handleRadioInputChange}),s)}renderAuxiliaryText(e){const t=this._userUpdatedInputFieldNames.has(e.name)&&!e.valid?e.errorMessage:i(this.viewModel.contingencyConstraintViolations.get(e.name))?this.messages.validationErrors.valuesIncompatible:i(e.valueExpressionExecutor)&&e.valueExpressionExecutor.stale?this.messages.valueExpressionError:null;return i(t)?b("calcite-input-message",{status:"invalid",icon:!0},t):e.description?b("div",{key:"description",class:d.description},e.description):void 0}getCommonInputProps(e){const{disabled:t,groupDisplay:a}=this,{editable:s,group:n,hint:l,maxLength:r,minLength:o,name:u,required:p,type:c,valid:m,value:h}=e,v=this._userUpdatedInputFieldNames.has(u),b=!s,f="all"===a&&i(n)&&"collapsed"===n.state;return{afterCreate:this._afterInputCreateOrUpdate,afterUpdate:this._afterInputCreateOrUpdate,"aria-invalid":m?"false":"true",class:this.classes(d.input,d.inputField,t||b?d.inputDisabled:null,v&&!m?d.inputInvalid:null),key:u,label:u,minlength:o>-1?`${o}`:"",maxlength:r>-1?`${r}`:"",...this._getNumberFieldConstraints(e),disabled:t,readOnly:b,value:null==h?"":`${h}`,[y]:u,onfocus:this._handleInputFocus,oninput:this._handleInputInput,onblur:this._handleInputBlur,onkeydown:this._handleInputKeyDown,onmousedown:"number"===c?this._handleNumberInputMouseDown:null,placeholder:"number"===c||"text"===c?l:"",required:p,tabIndex:f?-1:0}}_isInputFieldInGroup(e){return!F(e)&&i(e.group)}_handleNumberInputMouseDown({target:e}){e.focus(),this.scheduleRender()}_getFieldValueOptions(e,t){const i=t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),a=this.viewModel.fieldsWithContingentValues.has(e)?this._getContingentValueOptions(e):[];if(a.length>0){const e=new Set(a.map((e=>e.value)));return[a,i.filter((t=>!e.has(t.value)))]}return[i,[]]}_getContingentValueOptions(e){const t={};for(const n of this.viewModel.allInputFields){const{name:i,value:s}=n;!a(s)&&i!==e&&this.viewModel.fieldsWithContingentValues.has(i)&&(t[i]=s)}const i=this.viewModel.joinedContingentValues.slice(),s=new Map;for(const n of i){const i=n.values[e];if(a(i)||"code"!==i.objectType&&"null"!==i.objectType)continue;const{code:l,name:r}="null"===i.objectType?{code:"",name:this.messages.empty}:i.codedValue;if(s.has(l))continue;Object.entries(t).every((([e,t])=>!n.values.hasOwnProperty(e)||this._valueIsValidContingentValue(t,n.values[e])))&&s.set(l,{name:r,value:l})}return[...s.values()]}_getInputFieldFromInput(e){return this.viewModel.findField(e.getAttribute(y))}_getNumberFieldConstraints(e){const t=r(e.domain)||o(e.field);return t&&t.max!==Number.MAX_VALUE&&t.min!==Number.MIN_VALUE?t:{min:null,max:null}}_afterInputCreateOrUpdate(e){const{viewModel:t}=this,i=this._getInputFieldFromInput(e),a=t.findField(this._activeInputName),s=this._fieldToInitialIncompatibleDomainValue.get(i.name)===i.value;this._fieldFocusNeeded&&a===i&&("radio-buttons"!==i.inputType||s||e.checked)&&(this._fieldFocusNeeded=!1,this._isInputFieldInGroup(i)&&(i.group.state="expanded"),e.focus())}_handleInputFocus(e){const t=e.target,i=this._getInputFieldFromInput(t);this._activeInputName=i.name,"date"===i.type?this._syncDateFieldEdits(t):this._isNumberInputField(i)&&this._setUpNumberFieldEdit(t)}_isNumberInputField({domain:e,inputType:t="text-box",type:i}){return"number"===i&&"text-box"===t&&(!e||"coded-value"!==e.type)}_handleInputBlur(e){const t=e.target,a=this._getInputFieldFromInput(t);if("date"===a.type){const i=e.relatedTarget,s=i&&this._getInputFieldFromInput(i);if(s&&"date"===a.type&&"date"===s.type&&a.field===s.field){if(""!==t.value&&""===i.value){const s=i.getAttribute("data-date-part");i.value=this._formatDate(a.value??Date.now())[s],this._parseDate(t.value,t.getAttribute("data-date-part"))&&this._commitInputValue(e.target,!0,!1)}return}}"number"===a.type&&i(this._activeNumberFieldEdit)&&(this._activeNumberFieldEdit.input.value=`${a.value}`,this._activeNumberFieldEdit=null),this._commitInputValue(t),this.scheduleRender()}_commitInputValue(e,t=!1,a=!0){const s=this._getInputFieldFromInput(e);if(this._activeDateFieldEdit){const{date:i,time:n}=this._activeDateFieldEdit,l=this._parseDateTime(e.value,s,i.active?"date":"time"),r=null!==this.viewModel.getValue(s.name),o=i.input&&(n.input||!s.includeTime);if(t){if(null===l)return;(o||!a||r)&&this._updateDateFieldValue(s,l)}else{if(""===i.input?.value||""===n.input?.value)this._updateDateFieldValue(s,null);else if(o){const e=`${i.input.value} ${n.input?.value??""}`,t=this._parseDateTime(e,s);!(null!==t)&&r||this._updateDateFieldValue(s,t)}this._activeDateFieldEdit=null}}else i(this._activeNumberFieldEdit)&&this._isNumberInputField(s)&&(this._activeNumberFieldEdit.value=e.value),this._updateFieldValue(e)}_handleInputKeyDown(e){const{key:t,altKey:i,ctrlKey:a,metaKey:s}=e,n=this._getInputFieldFromInput(e.target);if("Enter"===t)this._isInputFieldInGroup(n)&&"collapsed"===n.group.state&&(n.group.state="expanded");else{const{type:l}=n.field,r="single"===l||"double"===l;if(("integer"===l||"small-integer"===l||r)&&(!i&&!a&&!s)&&1===t.length){const i=Number(t),a=["-","+"],s=["e","."],n=r?[...a,...s]:a;isNaN(i)&&!n.includes(t)&&e.preventDefault()}}}_setUpNumberFieldEdit(e){const t=this._getInputFieldFromInput(e);this._activeNumberFieldEdit={fieldName:t.name,input:e,value:e.value}}_syncDateFieldEdits(e){const t=this._getInputFieldFromInput(e);if("date"!==t.type)return;const i=e.getAttribute("data-date-part"),a="date"===i?{value:e.value,input:e,active:!0}:{...this._activeDateFieldEdit?.date,active:!1},s="time"===i?{value:e.value,input:e,active:!0}:{...this._activeDateFieldEdit?.time,active:!1};this._activeDateFieldEdit={fieldName:t.name,date:a,time:s}}_updateFieldValue(e){const t=e.getAttribute(y);if(this.viewModel.setValue(t,this._parseValue(e)),this._userUpdatedInputFieldNames.add(t),this.viewModel.fieldsWithContingentValues.has(t)){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>i(t))));this.viewModel.validateContingencyConstraints(e)}}_updateDateFieldValue(e,t){this.viewModel.setValue(e.name,t),this._userUpdatedInputFieldNames.add(e.name)}_parseValue(e){const t=this._getInputFieldFromInput(e),i=e.value;if(this._inputFieldHasInputType(t,"switch")&&"CALCITE-COMBOBOX"!==e.tagName)return e.checked?t.fieldElement.input.onValue:t.fieldElement.input.offValue;if("radio-buttons"===t.inputType&&"radio"===e.type&&!e.checked)return t.value;const{type:a}=t;if("number"===a)return i?parseFloat(i):null;if("date"===a){if(!i)return null;const a=Number(i);if(!isNaN(a))return a;const s=e.getAttribute("data-date-part"),n=this._parseDate(i,s);if(!n)return null;let l=f.fromJSDate(n);const r=t.domain,o=f.now();let u=o;if(r&&"range"===r.type){const e=f.fromMillis(r.maxValue);o<e&&(u=e)}const d=this.viewModel.getValue(t.name),p=null!=d?f.fromMillis(d):u;return l="date"===s?l.set({hour:p.hour,minute:p.minute,second:p.second}):l.set({day:p.day,month:p.month,year:p.year}),l.toMillis()}return i}_handleOptionChange(e){this._commitInputValue(e),this.scheduleRender()}_handleGroupClick(e){const t=e.currentTarget["data-group"],i="expanded"===t.state,a="sequential"===this.groupDisplay,s=`.${d.groupHeader}`;if(!(i&&!e.target.closest(s))){if(this._activeInputName=this._getFocusableInput("forward",t)?.name,a){const a=e.target.closest(s);if(i&&!a)return;this.viewModel.inputFields.forEach((e=>{F(e)&&e!==t&&(e.state="collapsed")}))}t.state=i?"collapsed":"expanded",this._fieldFocusNeeded=a,this.scheduleRender()}}_handleSubmit(e){e.preventDefault()}_handleFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_formatDate(e){if(null==e)return{date:"",time:""};const t=f.fromMillis(e,{locale:g(),numberingSystem:"latn"});return{date:t.toLocaleString({year:"numeric",month:"2-digit",day:"2-digit"}),time:t.toFormat(_.timePattern)}}_parseDate(e,t){if(null==e||""===e)return null;const{timePattern:i,datePattern:a}=_,s=t?"date"===t?a:i:`${a} ${i}`,n=f.fromFormat(e,s,{locale:g(),numberingSystem:"latn"});return n.isValid?n.toJSDate():null}_inputFieldHasInputType(e,t){return i(e.fieldElement)&&e.fieldElement.input?.type===t}_valueIsValidContingentValue(e,i){switch(i.objectType){case"any":return!0;case"null":return null==e;case"code":return e===i.codedValue?.code;case"range":return e>=i.minValue&&e<=i.maxValue;default:return t(i.objectType),!1}}};e([n()],I.prototype,"disabled",void 0),e([n()],I.prototype,"feature",null),e([n()],I.prototype,"formTemplate",null),e([n()],I.prototype,"groupDisplay",void 0),e([n()],I.prototype,"headingLevel",void 0),e([n()],I.prototype,"label",null),e([n()],I.prototype,"layer",null),e([n(),h("esri/widgets/FeatureForm/t9n/FeatureForm")],I.prototype,"messages",void 0),e([n(),h("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],I.prototype,"messagesTemplates",void 0),e([n()],I.prototype,"spatialReference",null),e([n()],I.prototype,"strict",null),e([n()],I.prototype,"view",null),e([n(),v(["value-change","submit"])],I.prototype,"viewModel",void 0),I=e([l("esri.widgets.FeatureForm")],I);const w=I;export{w 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.26/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{Heading as e}from"../support/Heading.js";import{classes as t,isActivationKey as n}from"../support/widgetUtils.js";import{tsx as i}from"../support/jsxFactory.js";const o="esri-item-list",r={base:o,list:`${o}__list`,group:`${o}__group`,scroller:`${o}__scroller`,groupHeader:`${o}__group__header`,item:`${o}__list-item`,itemSelected:`${o}__list-item--selected`,itemContainer:`${o}__list-item-container`,itemLabel:`${o}__list-item-label`,itemIcon:`${o}__list-item-icon`,noMatchesMessage:`${o}__no-matches-message`,noItemsMessage:`${o}__no-items-message`,filterContainer:`${o}__filter-container`,filterContainerSticky:`${o}__filter-container--sticky`,filterPlaceholder:`${o}__filter-placeholder`,filterInput:`${o}__filter-input`,filterPlaceholderText:`${o}__filter-placeholder-text`,searchIcon:"esri-icon-search",widget:"esri-widget",input:"esri-input"},l=4;function s(e){const{id:t,identify:n,filterEnabled:o=!0,headingLevel:r=l,items:s,selectedItem:a,messages:d,filterText:u="",onFilterChange:I,renderIcon:f,onItemMouseLeave:g,onItemMouseEnter:_,onItemSelect:p}=e,v=e.enableListScroll??!0;return i("div",{key:t},i("calcite-list",{
|
|
5
|
+
import{Heading as e}from"../support/Heading.js";import{classes as t,isActivationKey as n}from"../support/widgetUtils.js";import{tsx as i}from"../support/jsxFactory.js";const o="esri-item-list",r={base:o,list:`${o}__list`,group:`${o}__group`,scroller:`${o}__scroller`,groupHeader:`${o}__group__header`,item:`${o}__list-item`,itemSelected:`${o}__list-item--selected`,itemContainer:`${o}__list-item-container`,itemLabel:`${o}__list-item-label`,itemIcon:`${o}__list-item-icon`,noMatchesMessage:`${o}__no-matches-message`,noItemsMessage:`${o}__no-items-message`,filterContainer:`${o}__filter-container`,filterContainerSticky:`${o}__filter-container--sticky`,filterPlaceholder:`${o}__filter-placeholder`,filterInput:`${o}__filter-input`,filterPlaceholderText:`${o}__filter-placeholder-text`,searchIcon:"esri-icon-search",widget:"esri-widget",input:"esri-input"},l=4;function s(e){const{id:t,identify:n,filterEnabled:o=!0,headingLevel:r=l,items:s,selectedItem:a,messages:d,filterText:u="",onFilterChange:I,renderIcon:f,onItemMouseLeave:g,onItemMouseEnter:_,onItemSelect:p}=e,v=e.enableListScroll??!0;return i("div",{key:t},i("calcite-list",{selectionMode:"none"},o?m({filterText:u,messages:d,onFilterChange:I,id:t}):null,c({enableListScroll:v,identify:n,items:s,selectedItem:a,messages:d,filterText:u,headingLevel:r,renderIcon:f,onItemMouseLeave:g,onItemMouseEnter:_,onItemSelect:p})))}function a(e){return!!e.items}function c(e){const{headingLevel:t,identify:n,items:o,renderIcon:l,filterText:s,onItemMouseLeave:c,onItemMouseEnter:m,onItemSelect:I,selectedItem:f}=e,g=e.enableListScroll?r.scroller:void 0;return 0===o.length?i("div",{class:r.noMatchesMessage,key:"no-matches"},e.messages.noMatches):i("div",{class:g,key:"item-container"},o.map((e=>a(e)?u({group:e,filterText:s,headingLevel:t,identify:n,onItemMouseLeave:c,onItemMouseEnter:m,onItemSelect:I,renderIcon:l,selectedItem:f}):d({item:e,identify:n,grouped:!0,onItemMouseLeave:c,onItemMouseEnter:m,onItemSelect:I,renderIcon:l,filterText:s,selectedItem:f}))))}function m(e){const{messages:t,filterText:n,enableListScroll:o}=e;return i("div",{key:"filter",class:o?void 0:r.filterContainerSticky},i("calcite-input",{onCalciteInputInput:t=>{const n=t.currentTarget;e.onFilterChange&&e.onFilterChange(n.value)},placeholder:t.filterPlaceholder,value:n,type:"search"}))}function d(e){const{identify:o,item:l,selectedItem:s,grouped:a,onItemSelect:c,onItemMouseEnter:m,onItemMouseLeave:d,renderIcon:u}=e,I=`${o?.(l)||l.id}__${l.label}`,f=s?`${o?.(s)||s.id}__${s.label}`:"";return i("calcite-list-item",{"aria-level":a?"2":"","data-item":l,key:I,class:t(r.item,I===f?r.itemSelected:""),label:l.label,onCalciteListItemSelect:e=>{const t=e.currentTarget["data-item"];c&&c(t)},onmouseenter:e=>{const t=e.currentTarget["data-item"];m&&m(t)},onkeydown:e=>{if(!n(e.key))return;const t=e.currentTarget["data-item"];c&&c(t)},onmouseleave:e=>{const t=e.currentTarget["data-item"];d&&d(t)},tabIndex:0},i("div",{class:r.itemIcon,slot:"content-start"},u&&u({item:l})))}function u(t){const{group:n,identify:o,onItemMouseLeave:s,onItemMouseEnter:a,onItemSelect:c,filterText:m,renderIcon:u,selectedItem:I,headingLevel:f=l}=t;return i("div",{class:r.group,key:n.label},i(e,{level:f,class:r.groupHeader},n.label),n.items.map((e=>d({item:e,identify:o,grouped:!0,onItemMouseLeave:s,onItemMouseEnter:a,onItemSelect:c,renderIcon:u,filterText:m,selectedItem:I}))))}export{s as ItemList,u as renderGroup,d as renderItem};
|