@arcgis/core 5.0.0-next.84 → 5.0.0-next.85

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.
Files changed (100) hide show
  1. package/applications/Components/applySetUtils.d.ts +237 -0
  2. package/applications/Components/applySetUtils.js +5 -0
  3. package/applications/Components/editUtils.d.ts +92 -0
  4. package/applications/Components/editUtils.js +5 -0
  5. package/applications/Components/symbolUtils.d.ts +37 -0
  6. package/applications/Components/symbolUtils.js +5 -0
  7. package/applications/Components/templateUtils.d.ts +106 -0
  8. package/applications/Components/templateUtils.js +5 -0
  9. package/assets/esri/core/workers/RemoteClient.js +1 -1
  10. package/assets/esri/core/workers/chunks/001fd3d30e5bb0d180c6.js +1 -0
  11. package/assets/esri/core/workers/chunks/008a555ce169640e2a35.js.LICENSE.txt +1 -1
  12. package/assets/esri/core/workers/chunks/0402b7996940ba0f8cc8.js +2 -0
  13. package/assets/esri/core/workers/chunks/{534ed6574e4a1613ba05.js.LICENSE.txt → 0402b7996940ba0f8cc8.js.LICENSE.txt} +1 -1
  14. package/assets/esri/core/workers/chunks/{5b0ca8d2154ef59da600.js → 055aead7135a2f8bca29.js} +1 -1
  15. package/assets/esri/core/workers/chunks/0889e3d1a034be031c9e.js +2 -0
  16. package/assets/esri/core/workers/chunks/{e3d3fc87789fd711f161.js.LICENSE.txt → 0889e3d1a034be031c9e.js.LICENSE.txt} +1 -1
  17. package/assets/esri/core/workers/chunks/21739c37160061f229ef.js +1 -0
  18. package/assets/esri/core/workers/chunks/{76d6843d56bff0d4c45e.js → 301fa6276f4098521106.js} +1 -1
  19. package/assets/esri/core/workers/chunks/4c07b2d1a14906371fc5.js +2 -0
  20. package/assets/esri/core/workers/chunks/{21ac84b5c7dedcfd747d.js.LICENSE.txt → 4c07b2d1a14906371fc5.js.LICENSE.txt} +1 -1
  21. package/assets/esri/core/workers/chunks/{e881629bf230a148963d.js → 52ae2073604deef63ea2.js} +1 -1
  22. package/assets/esri/core/workers/chunks/{3909217130048b5feeae.js → 5543de9a0435c319f4f9.js} +1 -1
  23. package/assets/esri/core/workers/chunks/5eee48b02e1683f022df.js +2 -0
  24. package/assets/esri/core/workers/chunks/{ef519984fa691aad8d87.js.LICENSE.txt → 5eee48b02e1683f022df.js.LICENSE.txt} +1 -1
  25. package/assets/esri/core/workers/chunks/{911912b0ef7ffed875be.js → 7a1ec6ac88d974cc5074.js} +1 -1
  26. package/assets/esri/core/workers/chunks/{5e3dd05f1ecfdb21350e.js → 7f7c4ffbdf7b20dc7a54.js} +1 -1
  27. package/assets/esri/core/workers/chunks/{dc57400b835724204909.js → 8b1fa59d436e2815b2f1.js} +2 -2
  28. package/assets/esri/core/workers/chunks/{dc57400b835724204909.js.LICENSE.txt → 8b1fa59d436e2815b2f1.js.LICENSE.txt} +1 -1
  29. package/assets/esri/core/workers/chunks/9264cce4699284eae97c.js +2 -0
  30. package/assets/esri/core/workers/chunks/{5aee84e827e6fcc9c4c4.js.LICENSE.txt → 9264cce4699284eae97c.js.LICENSE.txt} +1 -1
  31. package/assets/esri/core/workers/chunks/95e93884b39ca4b312d1.js +2 -0
  32. package/assets/esri/core/workers/chunks/{90a53bfe95ed687c28c1.js.LICENSE.txt → 95e93884b39ca4b312d1.js.LICENSE.txt} +1 -1
  33. package/assets/esri/core/workers/chunks/{2a1898c5b8d7757e39e3.js → a09099697955eb44bfac.js} +1 -1
  34. package/assets/esri/core/workers/chunks/{6610d23d8539f06e64ca.js → adecd31fd64d6753682d.js} +1 -1
  35. package/assets/esri/core/workers/chunks/{df40be5a050b8d20617a.js → b190a776de4859ac00f8.js} +1 -1
  36. package/assets/esri/core/workers/chunks/c18a2948ae3cb527d8bb.js +1 -0
  37. package/assets/esri/core/workers/chunks/{d8c8f54532714d4db2cd.js → c791e8ebf3ee0805c479.js} +1 -1
  38. package/assets/esri/core/workers/chunks/f5ed6953a9255f0bed6a.js.LICENSE.txt +1 -1
  39. package/assets/esri/themes/dark/main.css +1 -1
  40. package/assets/esri/themes/light/main.css +1 -1
  41. package/assets/esri/themes/light/view.css +1 -1
  42. package/chunks/HUDMaterial.glsl.js +1 -1
  43. package/config.js +1 -1
  44. package/copyright.txt +2 -2
  45. package/editing/sharedTemplates/templateLoader.js +5 -0
  46. package/editing/templateUtils.js +1 -1
  47. package/interfaces.d.ts +6 -0
  48. package/kernel.js +1 -1
  49. package/layers/mixins/ImageryTileMixin.js +1 -1
  50. package/layers/raster/datasets/FunctionRaster.js +1 -1
  51. package/layers/raster/functions/BaseRasterFunction.js +1 -1
  52. package/layers/raster/functions/StretchFunction.js +1 -1
  53. package/layers/support/RasterJobHandler.js +1 -1
  54. package/layers/support/RasterWorker.js +1 -1
  55. package/networks/CircuitManager.d.ts +1 -1
  56. package/networks/support/jsonTypes.d.ts +65 -0
  57. package/package.json +1 -1
  58. package/rest/featureService/types.d.ts +42 -5
  59. package/rest/networks/circuits/exportCircuits.js +1 -1
  60. package/rest/networks/circuits/support/ExportCircuitsParameters.d.ts +10 -2
  61. package/rest/networks/circuits/support/ExportCircuitsParameters.js +1 -1
  62. package/rest/support/Query.d.ts +12 -1
  63. package/support/revision.js +1 -1
  64. package/symbols/support/symbolUtils.js +1 -1
  65. package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
  66. package/views/2d/layers/imagery/BaseImageryTileSubView2D.js +1 -1
  67. package/views/2d/layers/imagery/ImageryTileView2D.js +1 -1
  68. package/views/3d/analysis/VolumeMeasurement/VolumeMeasurementShiftTool.js +1 -1
  69. package/views/3d/camera/intersectionUtils.js +1 -1
  70. package/views/3d/support/gaussianSplatting/GaussianSplatDataStore.js +1 -1
  71. package/views/3d/support/gaussianSplatting/GaussianSplatFadeHelper.js +1 -1
  72. package/views/3d/webgl-engine/lib/GPUPointOcclusionQuery.js +1 -1
  73. package/views/interactive/snapping/SelfSnappingEngine.js +1 -1
  74. package/views/interactive/snapping/SnappingContext.js +1 -1
  75. package/widgets/BatchAttributeForm/BatchAttributeFormViewModel.d.ts +18 -0
  76. package/widgets/BatchAttributeForm.d.ts +2 -0
  77. package/widgets/BatchAttributeForm.js +1 -1
  78. package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
  79. package/widgets/Editor/workflowUtils.js +1 -1
  80. package/widgets/Feature/support/featureUtils.js +1 -1
  81. package/widgets/FeatureTable/FeatureTableViewModel.d.ts +43 -4
  82. package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
  83. package/widgets/FeatureTable/Grid/types.d.ts +7 -1
  84. package/widgets/FeatureTable/support/FeatureStore.js +1 -1
  85. package/widgets/FeatureTable.d.ts +43 -4
  86. package/widgets/FeatureTable.js +1 -1
  87. package/widgets/Legend/support/ActiveLayerInfo.js +1 -1
  88. package/widgets/Search/SearchViewModel.d.ts +5 -0
  89. package/widgets/Search/SearchViewModel.js +1 -1
  90. package/widgets/Search/support/layerSearchUtils.js +1 -1
  91. package/widgets/Search.js +1 -1
  92. package/assets/esri/core/workers/chunks/21ac84b5c7dedcfd747d.js +0 -2
  93. package/assets/esri/core/workers/chunks/22503abc06354741d28a.js +0 -1
  94. package/assets/esri/core/workers/chunks/534ed6574e4a1613ba05.js +0 -2
  95. package/assets/esri/core/workers/chunks/5aee84e827e6fcc9c4c4.js +0 -2
  96. package/assets/esri/core/workers/chunks/7b2f848947b296c7c785.js +0 -1
  97. package/assets/esri/core/workers/chunks/90a53bfe95ed687c28c1.js +0 -2
  98. package/assets/esri/core/workers/chunks/c16115cfbca879dd6717.js +0 -1
  99. package/assets/esri/core/workers/chunks/e3d3fc87789fd711f161.js +0 -2
  100. package/assets/esri/core/workers/chunks/ef519984fa691aad8d87.js +0 -2
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import{getAssetUrl as t}from"../../assets.js";import s from"../../Graphic.js";import r from"../../PopupTemplate.js";import{isSome as o}from"../../core/arrayUtils.js";import i from"../../core/Error.js";import{EventedAccessor as l}from"../../core/Evented.js";import a from"../../core/Logger.js";import{mappedFind as n}from"../../core/maybe.js";import{eachAlways as u,after as c}from"../../core/promiseUtils.js";import{watch as h,initial as p,whenOnce as g}from"../../core/reactiveUtils.js";import{property as d,subclass as m}from"../../core/accessorSupport/decorators.js";import y from"../../geometry/Point.js";import f from"../../geometry/SpatialReference.js";import{getPointFromGeometry as S,getPointWithElevation as _}from"../../geometry/support/geometryUtils.js";import v from"../../portal/Portal.js";import{isApiKeyApplicable as w}from"../../support/apiKeyUtils.js";import b from"../../symbols/PictureMarkerSymbol.js";import x from"../../symbols/SimpleFillSymbol.js";import L from"../../symbols/SimpleLineSymbol.js";import I from"../../symbols/TextSymbol.js";import{popupFromView as T,closePopup as E}from"../../views/popupAdapter.js";import{highlightsSupported as R}from"../../views/support/layerViewUtils.js";import F from"./LayerSearchSource.js";import P from"./LocatorSearchSource.js";import{SourceCollection as j}from"./types.js";import{isArcGISWorldGeocoder as G,meteredArcGISLocatorUrl as C,isProxiedArcGISWorldGeocoder as O,isMeteredArcGISWorldGeocoder as A}from"./support/locatorUtils.js";import{supported as N,getCurrentPosition as D,positionToPoint as M}from"../support/geolocationUtils.js";import{GoTo as V}from"../support/GoTo.js";function J(e,t){return e.hasOwnProperty(t)&&null!=e[t]&&""!==e[t]}const U="highlight",H=f.WGS84,k="esri/images/search/search-symbol-32.png",B=/<[\s\S]*?>/g,Q=-1;let Z=class extends(V(l)){constructor(e){super(e),this._defaultPopupTemplate=new r({content:"{Match_addr}"}),this._gotoController=null,this._searching=null,this._updatingPromise=null,this._createdFeatureLayers=[],this.autoNavigate=!0,this.autoSelect=!0,this.defaultSources=new j,this.defaultSymbols={point:new b({url:t(k),size:24,width:24,height:24}),polyline:new L({color:[130,130,130,1],width:2}),polygon:new x({color:[235,235,235,.4],outline:{color:[130,130,130,1],width:2}})},this.includeDefaultSources=!0,this.maxInputLength=128,this.maxResults=6,this.maxSuggestions=6,this.messages=null,this.minSuggestCharacters=3,this.popupEnabled=!0,this.popupTemplate=null,this.portal=v.getDefault(),this.resultCount=null,this.resultGraphicEnabled=!0,this.resultGraphic=null,this.results=null,this.selectedSuggestion=null,this.searchAllEnabled=!0,this.selectedResult=null,this.sources=new j,this.suggestionDelay=350,this.suggestionCount=null,this.suggestions=null,this.suggestionsEnabled=!0,this.view=null}initialize(){this.addHandles([h(()=>[this.includeDefaultSources,this.view,this.portal],()=>this._update(),p),h(()=>this.messages,()=>{this._defaultPopupTemplate.title=this.messages?.searchResult??"",this._update()},p)])}destroy(){this._destroyFeatureLayers(),this._abortGoTo(),this.clearGraphics()}static{this.ALL_INDEX=Q}get activeSource(){return this.allSources.at(this.activeSourceIndex)??null}get activeSourceIndex(){return 1===this.allSources.length||!this.searchAllEnabled?0:Q}set activeSourceIndex(e){this._overrideIfSome("activeSourceIndex",e)}get allPlaceholder(){return this.messages?.allPlaceholder}set allPlaceholder(e){this._overrideIfSome("allPlaceholder",e)}get allSources(){const{sources:e,defaultSources:t,includeDefaultSources:s}=this,r="function"==typeof s?s.call(null,{sources:e,defaultSources:t}):s?t.concat(e):e,o=this._get("allSources")||new j;return o.removeAll(),o.addMany(r.filter(Boolean)),o}get defaultPopupTemplate(){return this._defaultPopupTemplate}set defaultPopupTemplate(e){this._overrideIfSome("defaultPopupTemplate",e)}get locationEnabled(){return this._get("locationEnabled")||N()}set locationEnabled(e){if(void 0===e)return void this._clearOverride("locationEnabled");const t=N();if(e&&!t){const e=new i("locationEnabled:geolocation-unsupported","Geolocation API is unsupported.",{geolocation:navigator.geolocation});a.getLogger(this).error(e)}this._override("locationEnabled",!!e&&t)}get placeholder(){const{allSources:e,activeSourceIndex:t,allPlaceholder:s}=this;if(t===Q)return s??"";const r=e.at(t);return r?.placeholder??""}set searchTerm(e){this._set("searchTerm",e||""),this.clearGraphics(),this.selectedSuggestion&&this.selectedSuggestion.text!==e&&this._set("selectedSuggestion",null),""===e&&this._clear()}get searchTerm(){return this._get("searchTerm")||""}get state(){return this._searching?"searching":this.updating?"loading":0===this.allSources.length?"disabled":"ready"}get updating(){return null!=this._updatingPromise}clear(){this.searchTerm=""}clearGraphics(){this._removeHighlight(),this._closePopup();const{view:e,resultGraphic:t}=this;e&&t&&e.graphics.remove(t),this._set("resultGraphic",null)}search(e,t){this.emit("search-start"),this.clearGraphics();const s=this._createSuggestionForSearch(e),r=(async()=>{try{await this.when();const e=await this._getResultsFromSources(s,t);if(t?.signal?.aborted)return null;const r={activeSourceIndex:this.activeSourceIndex,searchTerm:s.text??"",numResults:0,numErrors:0,errors:[],results:[]};this._formatResponse(r,e,s);const o=this._getFirstResult(r.results),i=s.location&&o?o.name:s.text,l=i?.replaceAll(B,"");return this._set("searchTerm",l),(s.key&&"number"==typeof s.sourceIndex||s.location)&&this._set("selectedSuggestion",s),this._set("results",r.results),this._set("resultCount",r.results.reduce((e,t)=>e+(t.results?.length??0),0)),this.emit("search-complete",r),await this._selectFirstResult(o),r}finally{this._clearSearching()}})();return this._searching=r,r}async searchNearby(e){if(!this.locationEnabled){const e=new i("searchNearby:geolocation-unsupported","Geolocation API is unsupported.",{geolocation:navigator.geolocation});throw a.getLogger(this).error(e),e}const t=(async()=>{try{const t=await D(),s=await M({position:t,view:this.view},e);return await this.search(s,e)}finally{this._clearSearching()}})();return this._searching=t,t}async select(e){if(this.clearGraphics(),!e){const t=new i("select:missing-parameter","Cannot select without a searchResult.",{value:e});throw a.getLogger(this).error(t),t}const{view:t}=this,r=J(e,"sourceIndex")?e.sourceIndex:this._getSourceIndexOfResult(e),o=null!=r?this.allSources.at(r):null;if(!o){const e=new i("select:missing-source","Cannot select without a source.",{source:o});throw a.getLogger(this).error(e),e}const l=o instanceof F?this._getLayerSourcePopupTemplate(o):o.popupTemplate,n=o.resultSymbol||this._getDefaultSymbol(e),c=J(o,"resultGraphicEnabled")?o.resultGraphicEnabled:this.resultGraphicEnabled,h=J(o,"autoNavigate")?o.autoNavigate:this.autoNavigate,p=J(o,"popupEnabled")?o.popupEnabled:this.popupEnabled,g=p?l||this.popupTemplate||this.defaultPopupTemplate:null,{feature:d}=e;if(!d){const e=new i("select:missing-feature","Cannot select without a feature.",{feature:d});throw a.getLogger(this).error(e),e}const{attributes:m,geometry:y,layer:f,sourceLayer:v}=d,w=y?S(y):null,b={layerViewQuery:this._getLayerView(d),elevationQuery:t&&null!=w?_(w,t):Promise.resolve(w)},x=await u(b),L=x.layerViewQuery.value,E=x.elevationQuery.value;n instanceof I&&(n.text=e.name);const P=t&&h?e.target||e.extent:null,j=null!=P?this._goToSearchResult(P):Promise.resolve();await j;const G=L?d:new s({geometry:y,symbol:n,attributes:m,layer:f,sourceLayer:v,popupTemplate:g}),C=T(t),O=C&&p&&G.getEffectivePopupTemplate(C.defaultPopupTemplateEnabled);return O&&this.emit("popup-open",{features:[G],location:E??null}),L&&R(L)&&!O&&this._highlightFeature({graphic:G,layerView:L}),!L&&c&&t&&t.graphics.push(G),this._setResultFloor(e),this._set("selectedResult",e),this._set("resultGraphic",G),this.emit("select-result",{result:e,source:o,sourceIndex:r}),e}async suggest(e,t,s){const r=e||this.searchTerm;this.emit("suggest-start",{searchTerm:r}),await this._suggestTimer(t,s);const o=await this._suggestImmediate(r,s);return this._set("suggestions",o?.results),this._set("suggestionCount",o?.results.reduce((e,t)=>e+(t.results?.length??0),0)??null),this.emit("suggest-complete",o),o}async when(){await g(()=>!this.updating)}async _update(){const{portal:e,view:t}=this;if(this.includeDefaultSources){const s=this._updatingPromise=u([e?.load(),t?.when()]);if(this.destroyed)return;if(await s,s!==this._updatingPromise)return}this.destroyed||this._updateDefaultSources(),this._updatingPromise=null}_clearSearching(){this._searching=null}_convertHelperServices(){const e=this.portal?.helperServices?.geocode;if(!e)return[];return e.map(e=>{if(!1===e.placefinding)return;const t=G(e.url)&&w(e.url)?{url:C}:null,s=P.fromJSON({...e,...t}),r=s.url;if(G(r)||O(r)||A(r)){const e=s.outFields??["Addr_type","Match_addr","StAddr","City"],t=(s.placeholder||this.messages?.placeholder)??"",r="number"==typeof s.defaultZoomScale?s.defaultZoomScale:2500;s.singleLineFieldName="SingleLine",s.outFields=e,s.placeholder=t,s.defaultZoomScale=r}return s.singleLineFieldName?s:void 0}).filter(o)}_destroyFeatureLayers(){this._createdFeatureLayers.forEach(e=>e?.destroy()),this._createdFeatureLayers=[]}_getLayerSources(e,t){const s=this.view?.map;return e.map(e=>{const r=s.findLayerById(e.id);if(!r)return;const o=this._getLayerJSON(e),i=F.fromJSON(o);return i.placeholder=t,this._getLayer(r,o).then(e=>{i.layer=e}),i}).filter(o).toArray()}_getTableSources(e,t){const s=this.view?.map;return e.map(e=>{if(!e.id)return;const r=s.findTableById(e.id);if(!r)return;const o=this._getLayerJSON(e),i=F.fromJSON(o);return i.placeholder=t,this._getLayer(r,o).then(e=>{i.layer=e}),i}).filter(o).toArray()}_convertApplicationProperties(){const e=this.view?.map,t=e?.applicationProperties?.viewing?.search;if(!t)return[];const{enabled:s,hintText:r,layers:o,tables:i}=t;if(!s)return[];return[...this._getLayerSources(o,r),...this._getTableSources(i,r)]}async _getSubLayer(e,t){if(await e.load(),!e.allSublayers)throw new Error;const s=e.allSublayers.find(e=>e.id===t.subLayer);if(!s)throw new Error;const r=await(s.createFeatureLayer?.());if(!r)throw new Error;return this._createdFeatureLayers.push(r),r}async _getBuildingSubLayer(e,t){await e.load();const s=e.allSublayers.find(e=>e.id===t.subLayer);if("building-component"!==s?.type)throw new Error;if(await s.load(),null==s.associatedLayer)throw new Error;return await s.associatedLayer.load(),s}async _getLayer(e,t){if("feature"===e.type||"scene"===e.type||"csv"===e.type||"geojson"===e.type||"ogc-feature"===e.type)return e;if("map-image"===e.type)try{return await this._getSubLayer(e,t)}catch(s){const t=new i("search:create-featurelayer","Could not create a FeatureLayer from the MapImageLayer",{layer:e});return a.getLogger(this).error(t),null}return"building-scene"===e.type?this._getBuildingSubLayer(e,t):null}_getLayerJSON(e){return"function"==typeof e.toJSON?e.toJSON():e}_updateDefaultSources(){const{defaultSources:e,includeDefaultSources:t}=this;this._destroyFeatureLayers(),e.removeAll(),t&&e.addMany([...this._convertApplicationProperties(),...this._convertHelperServices()])}_abortGoTo(){this._gotoController&&this._gotoController.abort(),this._gotoController=null}_clear(){this._abortGoTo(),this._set("resultCount",null),this._set("results",null),this._set("suggestions",null),this._set("suggestionCount",null),this._set("selectedResult",null),this._set("selectedSuggestion",null),this.emit("search-clear")}_closePopup(){const e=T(this.view),{resultGraphic:t}=this;if(!e||!t)return;const s="selectedFeature"in e,r=s?e.selectedFeature:null;s&&(r&&r===t)&&E(this.view?.popup,this.view?.popupElement)}_suggestTimer(e,t){const s=null!=e?e:this.suggestionDelay;return c(s,null,t?.signal)}_createLocationForSearch(e){return e instanceof s&&e.geometry?S(e.geometry):e instanceof y?e:Array.isArray(e)&&2===e.length?new y({longitude:e[0],latitude:e[1]}):null}_createSuggestionForSearch(e){if(e&&J(e,"key")&&J(e,"text")&&J(e,"sourceIndex"))return e;const t=this._createLocationForSearch(e),s="string"==typeof e?e:this.searchTerm,{selectedSuggestion:r,selectedResult:o}=this,i=!e&&r&&o,l=i&&r.key===o.key&&r.sourceIndex===o.sourceIndex,a=i&&r.location;return l||a?r:{location:t,text:t?"":s,sourceIndex:null,key:null}}_getFirstResult(e){return n(e,({results:e})=>e?.[0])??null}async _selectFirstResult(e){return this.autoSelect&&e?this.select(e):null}async _suggestImmediate(e,t){await this.when();const s=await this._getSuggestionsFromSources(e,t);if(t?.signal?.aborted)return null;const r={activeSourceIndex:this.activeSourceIndex,searchTerm:e??"",numResults:0,numErrors:0,errors:[],results:[]};return this._formatResponse(r,s),r}_formatSourceResponse(e,t,s){const r=t?.value||[],o=t?.error,i=this.allSources.at(s);if(o){const t={sourceIndex:s,source:i,error:o};e.errors.push(t),a.getLogger(this).error(o),e.numErrors++}else{const t={sourceIndex:s,source:i,results:r};e.results.push(t),e.numResults+=r.length}}_formatResponse(e,t,s){if(t)if(e.activeSourceIndex===Q){const r=s&&J(s,"sourceIndex")&&-1!==s.sourceIndex?s.sourceIndex:void 0;t.forEach((t,s)=>{const o=void 0!==r?r:s;this._formatSourceResponse(e,t,o)})}else this._formatSourceResponse(e,t[0],e.activeSourceIndex)}async _getResultsFromSources(e,t){const{allSources:s}=this,r=!e.location&&J(e,"sourceIndex")?e.sourceIndex:this.activeSourceIndex,o=[];if(!s.length){const e=new i("search:no-sources-defined","At least one source is required.",{allSources:s});throw a.getLogger(this).error(e),e}return r===Q?s.forEach((s,r)=>{o.push(this._getResultsFromSource(e,r,t))}):o.push(this._getResultsFromSource(e,r,t)),u(o)}async _getSuggestionsFromSources(e,t){const{allSources:s,activeSourceIndex:r}=this,o=[];if(!s.length){const e=new i("suggest:no-sources-defined","At least one source is required.",{allSources:s});throw a.getLogger(this).error(e),e}return r===Q?s.forEach((s,r)=>{o.push(this._getSuggestionsFromSource(e,r,t))}):o.push(this._getSuggestionsFromSource(e,r,t)),u(o)}async _getResultsFromSource(e,t,s){const r=null!=t?this.allSources.at(t):null;if(!r)return null;const{location:o=null}=e,i=this.view?.spatialReference??H,l=J(r,"maxResults")?r.maxResults:this.maxResults,a=!!(r instanceof F&&J(r,"exactMatch"))&&r.exactMatch,{view:n}=this;return r.getResults?.({exactMatch:a,location:o,maxResults:l,sourceIndex:t,spatialReference:i,suggestResult:e,view:n},s)}async _getSuggestionsFromSource(e,t,s){const r=this.allSources.at(t);if(!r)return null;e??="";const o=J(r,"suggestionsEnabled")?r.suggestionsEnabled:this.suggestionsEnabled,i=e?.length,l=J(r,"minSuggestCharacters")?r.minSuggestCharacters:this.minSuggestCharacters;if(o&&e.trim()&&i>=l){const o=this.view?.spatialReference||H,i=J(r,"maxSuggestions")?r.maxSuggestions:this.maxSuggestions,{view:l}=this,a=!!(r instanceof F&&J(r,"exactMatch"))&&r.exactMatch;return r.getSuggestions?.({view:l,sourceIndex:t,suggestTerm:e,spatialReference:o,maxSuggestions:i,exactMatch:a},s)}return null}_getLayerSourcePopupTemplate(e){const{layer:t}=e;if(t)return J(e,"popupTemplate")?e.popupTemplate:t.popupTemplate}_getSourceIndexOfResult(e){return n(this.results??[],({results:t,sourceIndex:s})=>{const r=t?.includes(e);return r?s:null})??null}async _goToSearchResult(e){this._abortGoTo();const t=new AbortController;this._gotoController=t;const s={target:{target:e},options:{signal:t.signal}};e||(s.options.animate=!1),await this.callGoTo(s),this._gotoController=null}_getDefaultSymbol(e){const{defaultSymbols:t}=this,s=e.feature?.geometry;if(null==s)return null;switch(s.type){case"point":case"multipoint":return t.point;case"polyline":return t.polyline;case"extent":case"polygon":return t.polygon;default:return null}}_removeHighlight(){this.removeHandles(U)}async _getLayerView(e){const{view:t}=this;if(!e||!t)return null;const{layer:s,sourceLayer:r}=e,o=s??r;return o&&"building-component"!==o.type&&"subtype-sublayer"!==o.type?(await t.when(),t.whenLayerView(o)):null}_highlightFeature(e){const{graphic:t,layerView:s}=e,{attributes:r,layer:o,sourceLayer:i}=t,l=o??i,{objectIdField:a}=l,n=(a&&r?.[a])??null,u=s.highlight(n??t);this.addHandles(u,U)}_setResultFloor(e){const{view:t}=this,s=e.feature?.attributes,r=e.feature?.sourceLayer;if(r&&"floorInfo"in r&&r?.floorInfo?.floorField&&s){const e=s[r.floorInfo.floorField];t?.emit("select-result-floor",e)}}};e([d()],Z.prototype,"_searching",void 0),e([d()],Z.prototype,"_updatingPromise",void 0),e([d({readOnly:!0,value:null})],Z.prototype,"activeSource",null),e([d()],Z.prototype,"activeSourceIndex",null),e([d()],Z.prototype,"allPlaceholder",null),e([d({readOnly:!0})],Z.prototype,"allSources",null),e([d()],Z.prototype,"autoNavigate",void 0),e([d()],Z.prototype,"autoSelect",void 0),e([d({type:r})],Z.prototype,"defaultPopupTemplate",null),e([d({readOnly:!0})],Z.prototype,"defaultSources",void 0),e([d()],Z.prototype,"defaultSymbols",void 0),e([d()],Z.prototype,"includeDefaultSources",void 0),e([d()],Z.prototype,"locationEnabled",null),e([d()],Z.prototype,"maxInputLength",void 0),e([d()],Z.prototype,"maxResults",void 0),e([d()],Z.prototype,"maxSuggestions",void 0),e([d()],Z.prototype,"messages",void 0),e([d()],Z.prototype,"minSuggestCharacters",void 0),e([d({readOnly:!0})],Z.prototype,"placeholder",null),e([d()],Z.prototype,"popupEnabled",void 0),e([d({type:r})],Z.prototype,"popupTemplate",void 0),e([d({type:v})],Z.prototype,"portal",void 0),e([d()],Z.prototype,"resultCount",void 0),e([d()],Z.prototype,"resultGraphicEnabled",void 0),e([d({readOnly:!0})],Z.prototype,"resultGraphic",void 0),e([d({readOnly:!0})],Z.prototype,"results",void 0),e([d({readOnly:!0})],Z.prototype,"selectedSuggestion",void 0),e([d()],Z.prototype,"searchAllEnabled",void 0),e([d({readOnly:!0})],Z.prototype,"selectedResult",void 0),e([d()],Z.prototype,"searchTerm",null),e([d({type:j})],Z.prototype,"sources",void 0),e([d({readOnly:!0})],Z.prototype,"state",null),e([d()],Z.prototype,"suggestionDelay",void 0),e([d()],Z.prototype,"suggestionCount",void 0),e([d({readOnly:!0})],Z.prototype,"suggestions",void 0),e([d()],Z.prototype,"suggestionsEnabled",void 0),e([d({readOnly:!0})],Z.prototype,"updating",null),e([d()],Z.prototype,"view",void 0),e([d()],Z.prototype,"clear",null),Z=e([m("esri.widgets.Search.SearchViewModel")],Z);const q=Z;export{q as default};
5
+ import{__decorate as e}from"tslib";import{getAssetUrl as t}from"../../assets.js";import s from"../../Graphic.js";import r from"../../PopupTemplate.js";import{isSome as o}from"../../core/arrayUtils.js";import i from"../../core/Error.js";import{EventedAccessor as l}from"../../core/Evented.js";import a from"../../core/Logger.js";import{mappedFind as n}from"../../core/maybe.js";import{eachAlways as u,after as c}from"../../core/promiseUtils.js";import{watch as h,initial as p,whenOnce as g}from"../../core/reactiveUtils.js";import{property as d,subclass as m}from"../../core/accessorSupport/decorators.js";import y from"../../geometry/Point.js";import f from"../../geometry/SpatialReference.js";import{getPointFromGeometry as S,getPointWithElevation as _}from"../../geometry/support/geometryUtils.js";import v from"../../portal/Portal.js";import{isApiKeyApplicable as w}from"../../support/apiKeyUtils.js";import b from"../../symbols/PictureMarkerSymbol.js";import x from"../../symbols/SimpleFillSymbol.js";import L from"../../symbols/SimpleLineSymbol.js";import I from"../../symbols/TextSymbol.js";import{highlightsSupported as T}from"../../views/support/layerViewUtils.js";import R from"./LayerSearchSource.js";import E from"./LocatorSearchSource.js";import{SourceCollection as F}from"./types.js";import{isArcGISWorldGeocoder as P,meteredArcGISLocatorUrl as j,isProxiedArcGISWorldGeocoder as C,isMeteredArcGISWorldGeocoder as G}from"./support/locatorUtils.js";import{supported as O,getCurrentPosition as A,positionToPoint as N}from"../support/geolocationUtils.js";import{GoTo as D}from"../support/GoTo.js";function M(e,t){return e.hasOwnProperty(t)&&null!=e[t]&&""!==e[t]}const V="highlight",J=f.WGS84,U="esri/images/search/search-symbol-32.png",H=/<[\s\S]*?>/g,k=-1;let B=class extends(D(l)){constructor(e){super(e),this._defaultPopupTemplate=new r({content:"{Match_addr}"}),this._gotoController=null,this._searching=null,this._updatingPromise=null,this._createdFeatureLayers=[],this.autoNavigate=!0,this.autoSelect=!0,this.defaultSources=new F,this.defaultSymbols={point:new b({url:t(U),size:24,width:24,height:24}),polyline:new L({color:[130,130,130,1],width:2}),polygon:new x({color:[235,235,235,.4],outline:{color:[130,130,130,1],width:2}})},this.includeDefaultSources=!0,this.maxInputLength=128,this.maxResults=6,this.maxSuggestions=6,this.messages=null,this.minSuggestCharacters=3,this.popupEnabled=!0,this.popupTemplate=null,this.portal=v.getDefault(),this.resultCount=null,this.resultGraphicEnabled=!0,this.resultGraphic=null,this.resultLocation=null,this.results=null,this.selectedSuggestion=null,this.searchAllEnabled=!0,this.selectedResult=null,this.sources=new F,this.suggestionDelay=350,this.suggestionCount=null,this.suggestions=null,this.suggestionsEnabled=!0,this.view=null}initialize(){this.addHandles([h(()=>[this.includeDefaultSources,this.view,this.portal],()=>this._update(),p),h(()=>this.messages,()=>{this._defaultPopupTemplate.title=this.messages?.searchResult??"",this._update()},p)])}destroy(){this._destroyFeatureLayers(),this._abortGoTo(),this.clearGraphics()}static{this.ALL_INDEX=k}get activeSource(){return this.allSources.at(this.activeSourceIndex)??null}get activeSourceIndex(){return 1===this.allSources.length||!this.searchAllEnabled?0:k}set activeSourceIndex(e){this._overrideIfSome("activeSourceIndex",e)}get allPlaceholder(){return this.messages?.allPlaceholder}set allPlaceholder(e){this._overrideIfSome("allPlaceholder",e)}get allSources(){const{sources:e,defaultSources:t,includeDefaultSources:s}=this,r="function"==typeof s?s.call(null,{sources:e,defaultSources:t}):s?t.concat(e):e,o=this._get("allSources")||new F;return o.removeAll(),o.addMany(r.filter(Boolean)),o}get defaultPopupTemplate(){return this._defaultPopupTemplate}set defaultPopupTemplate(e){this._overrideIfSome("defaultPopupTemplate",e)}get locationEnabled(){return this._get("locationEnabled")||O()}set locationEnabled(e){if(void 0===e)return void this._clearOverride("locationEnabled");const t=O();if(e&&!t){const e=new i("locationEnabled:geolocation-unsupported","Geolocation API is unsupported.",{geolocation:navigator.geolocation});a.getLogger(this).error(e)}this._override("locationEnabled",!!e&&t)}get placeholder(){const{allSources:e,activeSourceIndex:t,allPlaceholder:s}=this;if(t===k)return s??"";const r=e.at(t);return r?.placeholder??""}set searchTerm(e){this._set("searchTerm",e||""),this.clearGraphics(),this.selectedSuggestion&&this.selectedSuggestion.text!==e&&this._set("selectedSuggestion",null),""===e&&this._clear()}get searchTerm(){return this._get("searchTerm")||""}get state(){return this._searching?"searching":this.updating?"loading":0===this.allSources.length?"disabled":"ready"}get updating(){return null!=this._updatingPromise}clear(){this.searchTerm=""}clearGraphics(){this._removeHighlight();const{view:e,resultGraphic:t}=this;e&&t&&e.graphics.remove(t),this._set("resultLocation",null),this._set("resultGraphic",null)}search(e,t){this.emit("search-start"),this.clearGraphics();const s=this._createSuggestionForSearch(e),r=(async()=>{try{await this.when();const e=await this._getResultsFromSources(s,t);if(t?.signal?.aborted)return null;const r={activeSourceIndex:this.activeSourceIndex,searchTerm:s.text??"",numResults:0,numErrors:0,errors:[],results:[]};this._formatResponse(r,e,s);const o=this._getFirstResult(r.results),i=s.location&&o?o.name:s.text,l=i?.replaceAll(H,"");return this._set("searchTerm",l),(s.key&&"number"==typeof s.sourceIndex||s.location)&&this._set("selectedSuggestion",s),this._set("results",r.results),this._set("resultCount",r.results.reduce((e,t)=>e+(t.results?.length??0),0)),this.emit("search-complete",r),await this._selectFirstResult(o),r}finally{this._clearSearching()}})();return this._searching=r,r}async searchNearby(e){if(!this.locationEnabled){const e=new i("searchNearby:geolocation-unsupported","Geolocation API is unsupported.",{geolocation:navigator.geolocation});throw a.getLogger(this).error(e),e}const t=(async()=>{try{const t=await A(),s=await N({position:t,view:this.view},e);return await this.search(s,e)}finally{this._clearSearching()}})();return this._searching=t,t}async select(e){if(this.clearGraphics(),!e){const t=new i("select:missing-parameter","Cannot select without a searchResult.",{value:e});throw a.getLogger(this).error(t),t}const{view:t}=this,r=M(e,"sourceIndex")?e.sourceIndex:this._getSourceIndexOfResult(e),o=null!=r?this.allSources.at(r):null;if(!o){const e=new i("select:missing-source","Cannot select without a source.",{source:o});throw a.getLogger(this).error(e),e}const l=o instanceof R?this._getLayerSourcePopupTemplate(o):o.popupTemplate,n=o.resultSymbol||this._getDefaultSymbol(e),c=M(o,"resultGraphicEnabled")?!!o.resultGraphicEnabled:this.resultGraphicEnabled,h=M(o,"autoNavigate")?!!o.autoNavigate:this.autoNavigate,p=M(o,"popupEnabled")?!!o.popupEnabled:this.popupEnabled,g=p?l||this.popupTemplate||this.defaultPopupTemplate:null,{feature:d}=e;if(!d){const e=new i("select:missing-feature","Cannot select without a feature.",{feature:d});throw a.getLogger(this).error(e),e}const{attributes:m,geometry:y,layer:f,sourceLayer:v}=d,w=y?S(y):null,b={layerViewQuery:this._getLayerView(d),elevationQuery:t&&null!=w?_(w,t):Promise.resolve(w)},x=await u(b),L=x.layerViewQuery.value,E=x.elevationQuery.value;n instanceof I&&(n.text=e.name);const F=t&&h?e.target||e.extent:null,P=null!=F?this._goToSearchResult(F):Promise.resolve();await P;const j=L?d:new s({geometry:y,symbol:n,attributes:m,layer:f,sourceLayer:v,popupTemplate:g});return L&&T(L)&&!p&&this._highlightFeature({graphic:j,layerView:L}),!L&&c&&t&&t.graphics.push(j),this._setResultFloor(e),this._set("selectedResult",e),this._set("resultGraphic",j),this._set("resultLocation",E),this.emit("select-result",{popupEnabled:p,result:e,source:o,sourceIndex:r}),e}async suggest(e,t,s){const r=e||this.searchTerm;this.emit("suggest-start",{searchTerm:r}),await this._suggestTimer(t,s);const o=await this._suggestImmediate(r,s);return this._set("suggestions",o?.results),this._set("suggestionCount",o?.results.reduce((e,t)=>e+(t.results?.length??0),0)??null),this.emit("suggest-complete",o),o}async when(){await g(()=>!this.updating)}async _update(){const{portal:e,view:t}=this;if(this.includeDefaultSources){const s=this._updatingPromise=u([e?.load(),t?.when()]);if(this.destroyed)return;if(await s,s!==this._updatingPromise)return}this.destroyed||this._updateDefaultSources(),this._updatingPromise=null}_clearSearching(){this._searching=null}_convertHelperServices(){const e=this.portal?.helperServices?.geocode;if(!e)return[];return e.map(e=>{if(!1===e.placefinding)return;const t=P(e.url)&&w(e.url)?{url:j}:null,s=E.fromJSON({...e,...t}),r=s.url;if(P(r)||C(r)||G(r)){const e=s.outFields??["Addr_type","Match_addr","StAddr","City"],t=(s.placeholder||this.messages?.placeholder)??"",r="number"==typeof s.defaultZoomScale?s.defaultZoomScale:2500;s.singleLineFieldName="SingleLine",s.outFields=e,s.placeholder=t,s.defaultZoomScale=r}return s.singleLineFieldName?s:void 0}).filter(o)}_destroyFeatureLayers(){this._createdFeatureLayers.forEach(e=>e?.destroy()),this._createdFeatureLayers=[]}_getLayerSources(e,t){const s=this.view?.map;return e.map(e=>{const r=s.findLayerById(e.id);if(!r)return;const o=this._getLayerJSON(e),i=R.fromJSON(o);return i.placeholder=t,this._getLayer(r,o).then(e=>{i.layer=e}),i}).filter(o).toArray()}_getTableSources(e,t){const s=this.view?.map;return e.map(e=>{if(!e.id)return;const r=s.findTableById(e.id);if(!r)return;const o=this._getLayerJSON(e),i=R.fromJSON(o);return i.placeholder=t,this._getLayer(r,o).then(e=>{i.layer=e}),i}).filter(o).toArray()}_convertApplicationProperties(){const e=this.view?.map,t=e?.applicationProperties?.viewing?.search;if(!t)return[];const{enabled:s,hintText:r,layers:o,tables:i}=t;if(!s)return[];return[...this._getLayerSources(o,r),...this._getTableSources(i,r)]}async _getSubLayer(e,t){if(await e.load(),!e.allSublayers)throw new Error;const s=e.allSublayers.find(e=>e.id===t.subLayer);if(!s)throw new Error;const r=await(s.createFeatureLayer?.());if(!r)throw new Error;return this._createdFeatureLayers.push(r),r}async _getBuildingSubLayer(e,t){await e.load();const s=e.allSublayers.find(e=>e.id===t.subLayer);if("building-component"!==s?.type)throw new Error;if(await s.load(),null==s.associatedLayer)throw new Error;return await s.associatedLayer.load(),s}async _getLayer(e,t){if("feature"===e.type||"scene"===e.type||"csv"===e.type||"geojson"===e.type||"ogc-feature"===e.type||"subtype-group"===e.type)return e;if("map-image"===e.type)try{return await this._getSubLayer(e,t)}catch(s){const t=new i("search:create-featurelayer","Could not create a FeatureLayer from the MapImageLayer",{layer:e});return a.getLogger(this).error(t),null}return"building-scene"===e.type?this._getBuildingSubLayer(e,t):null}_getLayerJSON(e){return"function"==typeof e.toJSON?e.toJSON():e}_updateDefaultSources(){const{defaultSources:e,includeDefaultSources:t}=this;this._destroyFeatureLayers(),e.removeAll(),t&&e.addMany([...this._convertApplicationProperties(),...this._convertHelperServices()])}_abortGoTo(){this._gotoController&&this._gotoController.abort(),this._gotoController=null}_clear(){this._abortGoTo(),this._set("resultCount",null),this._set("results",null),this._set("suggestions",null),this._set("suggestionCount",null),this._set("selectedResult",null),this._set("selectedSuggestion",null),this.emit("search-clear")}_suggestTimer(e,t){const s=null!=e?e:this.suggestionDelay;return c(s,null,t?.signal)}_createLocationForSearch(e){return e instanceof s&&e.geometry?S(e.geometry):e instanceof y?e:Array.isArray(e)&&2===e.length?new y({longitude:e[0],latitude:e[1]}):null}_createSuggestionForSearch(e){if(e&&M(e,"key")&&M(e,"text")&&M(e,"sourceIndex"))return e;const t=this._createLocationForSearch(e),s="string"==typeof e?e:this.searchTerm,{selectedSuggestion:r,selectedResult:o}=this,i=!e&&r&&o,l=i&&r.key===o.key&&r.sourceIndex===o.sourceIndex,a=i&&r.location;return l||a?r:{location:t,text:t?"":s,sourceIndex:null,key:null}}_getFirstResult(e){return n(e,({results:e})=>e?.[0])??null}async _selectFirstResult(e){return this.autoSelect&&e?this.select(e):null}async _suggestImmediate(e,t){await this.when();const s=await this._getSuggestionsFromSources(e,t);if(t?.signal?.aborted)return null;const r={activeSourceIndex:this.activeSourceIndex,searchTerm:e??"",numResults:0,numErrors:0,errors:[],results:[]};return this._formatResponse(r,s),r}_formatSourceResponse(e,t,s){const r=t?.value||[],o=t?.error,i=this.allSources.at(s);if(o){const t={sourceIndex:s,source:i,error:o};e.errors.push(t),a.getLogger(this).error(o),e.numErrors++}else{const t={sourceIndex:s,source:i,results:r};e.results.push(t),e.numResults+=r.length}}_formatResponse(e,t,s){if(t)if(e.activeSourceIndex===k){const r=s&&M(s,"sourceIndex")&&-1!==s.sourceIndex?s.sourceIndex:void 0;t.forEach((t,s)=>{const o=void 0!==r?r:s;this._formatSourceResponse(e,t,o)})}else this._formatSourceResponse(e,t[0],e.activeSourceIndex)}async _getResultsFromSources(e,t){const{allSources:s}=this,r=!e.location&&M(e,"sourceIndex")?e.sourceIndex:this.activeSourceIndex,o=[];if(!s.length){const e=new i("search:no-sources-defined","At least one source is required.",{allSources:s});throw a.getLogger(this).error(e),e}return r===k?s.forEach((s,r)=>{o.push(this._getResultsFromSource(e,r,t))}):o.push(this._getResultsFromSource(e,r,t)),u(o)}async _getSuggestionsFromSources(e,t){const{allSources:s,activeSourceIndex:r}=this,o=[];if(!s.length){const e=new i("suggest:no-sources-defined","At least one source is required.",{allSources:s});throw a.getLogger(this).error(e),e}return r===k?s.forEach((s,r)=>{o.push(this._getSuggestionsFromSource(e,r,t))}):o.push(this._getSuggestionsFromSource(e,r,t)),u(o)}async _getResultsFromSource(e,t,s){const r=null!=t?this.allSources.at(t):null;if(!r)return null;const{location:o=null}=e,i=this.view?.spatialReference??J,l=M(r,"maxResults")?r.maxResults:this.maxResults,a=!!(r instanceof R&&M(r,"exactMatch"))&&r.exactMatch,{view:n}=this;return r.getResults?.({exactMatch:a,location:o,maxResults:l,sourceIndex:t,spatialReference:i,suggestResult:e,view:n},s)}async _getSuggestionsFromSource(e,t,s){const r=this.allSources.at(t);if(!r)return null;e??="";const o=M(r,"suggestionsEnabled")?r.suggestionsEnabled:this.suggestionsEnabled,i=e?.length,l=M(r,"minSuggestCharacters")?r.minSuggestCharacters:this.minSuggestCharacters;if(o&&e.trim()&&i>=l){const o=this.view?.spatialReference||J,i=M(r,"maxSuggestions")?r.maxSuggestions:this.maxSuggestions,{view:l}=this,a=!!(r instanceof R&&M(r,"exactMatch"))&&r.exactMatch;return r.getSuggestions?.({view:l,sourceIndex:t,suggestTerm:e,spatialReference:o,maxSuggestions:i,exactMatch:a},s)}return null}_getLayerSourcePopupTemplate(e){const{layer:t}=e;if(t)return M(e,"popupTemplate")?e.popupTemplate:t.popupTemplate}_getSourceIndexOfResult(e){return n(this.results??[],({results:t,sourceIndex:s})=>{const r=t?.includes(e);return r?s:null})??null}async _goToSearchResult(e){this._abortGoTo();const t=new AbortController;this._gotoController=t;const s={target:{target:e},options:{signal:t.signal}};e||(s.options.animate=!1),await this.callGoTo(s),this._gotoController=null}_getDefaultSymbol(e){const{defaultSymbols:t}=this,s=e.feature?.geometry;if(null==s)return null;switch(s.type){case"point":case"multipoint":return t.point;case"polyline":return t.polyline;case"extent":case"polygon":return t.polygon;default:return null}}_removeHighlight(){this.removeHandles(V)}async _getLayerView(e){const{view:t}=this;if(!e||!t)return null;const{layer:s,sourceLayer:r}=e,o=s??r;return o&&"building-component"!==o.type&&"subtype-sublayer"!==o.type?(await t.when(),t.whenLayerView(o)):null}_highlightFeature(e){const{graphic:t,layerView:s}=e,{attributes:r,layer:o,sourceLayer:i}=t,l=o??i,{objectIdField:a}=l,n=(a&&r?.[a])??null,u=s.highlight(n??t);this.addHandles(u,V)}_setResultFloor(e){const{view:t}=this,s=e.feature?.attributes,r=e.feature?.sourceLayer;if(r&&"floorInfo"in r&&r?.floorInfo?.floorField&&s){const e=s[r.floorInfo.floorField];t?.emit("select-result-floor",e)}}};e([d()],B.prototype,"_searching",void 0),e([d()],B.prototype,"_updatingPromise",void 0),e([d({readOnly:!0,value:null})],B.prototype,"activeSource",null),e([d()],B.prototype,"activeSourceIndex",null),e([d()],B.prototype,"allPlaceholder",null),e([d({readOnly:!0})],B.prototype,"allSources",null),e([d()],B.prototype,"autoNavigate",void 0),e([d()],B.prototype,"autoSelect",void 0),e([d({type:r})],B.prototype,"defaultPopupTemplate",null),e([d({readOnly:!0})],B.prototype,"defaultSources",void 0),e([d()],B.prototype,"defaultSymbols",void 0),e([d()],B.prototype,"includeDefaultSources",void 0),e([d()],B.prototype,"locationEnabled",null),e([d()],B.prototype,"maxInputLength",void 0),e([d()],B.prototype,"maxResults",void 0),e([d()],B.prototype,"maxSuggestions",void 0),e([d()],B.prototype,"messages",void 0),e([d()],B.prototype,"minSuggestCharacters",void 0),e([d({readOnly:!0})],B.prototype,"placeholder",null),e([d()],B.prototype,"popupEnabled",void 0),e([d({type:r})],B.prototype,"popupTemplate",void 0),e([d({type:v})],B.prototype,"portal",void 0),e([d()],B.prototype,"resultCount",void 0),e([d()],B.prototype,"resultGraphicEnabled",void 0),e([d({readOnly:!0})],B.prototype,"resultGraphic",void 0),e([d({readOnly:!0})],B.prototype,"resultLocation",void 0),e([d({readOnly:!0})],B.prototype,"results",void 0),e([d({readOnly:!0})],B.prototype,"selectedSuggestion",void 0),e([d()],B.prototype,"searchAllEnabled",void 0),e([d({readOnly:!0})],B.prototype,"selectedResult",void 0),e([d()],B.prototype,"searchTerm",null),e([d({type:F})],B.prototype,"sources",void 0),e([d({readOnly:!0})],B.prototype,"state",null),e([d()],B.prototype,"suggestionDelay",void 0),e([d()],B.prototype,"suggestionCount",void 0),e([d({readOnly:!0})],B.prototype,"suggestions",void 0),e([d()],B.prototype,"suggestionsEnabled",void 0),e([d({readOnly:!0})],B.prototype,"updating",null),e([d()],B.prototype,"view",void 0),e([d()],B.prototype,"clear",null),B=e([m("esri.widgets.Search.SearchViewModel")],B);const Q=B;export{Q as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{substitute as e,formatDate as t}from"../../../intl.js";import r from"../../../core/Error.js";import has from"../../../core/has.js";import{clone as i}from"../../../core/lang.js";import n from"../../../core/Logger.js";import{mappedFind as l}from"../../../core/maybe.js";import{getMetersPerUnitForSR as o}from"../../../core/units.js";import s from"../../../geometry/Polygon.js";import{createExtentFromGeometry as a,scaleExtent as u}from"../../../geometry/support/geometryUtils.js";import c from"../../../rest/support/FullTextSearch.js";const d=/https?:\/\/services.*\.arcgis\.com/i,f=/(?:\{([^}]+)\})/g,m=()=>n.getLogger("esri.widgets.Search.support.layerSearchUtils");function p(e,t){const{exactMatch:i=!1,location:n,maxResults:l,spatialReference:s,source:a,sourceIndex:u,suggestResult:c,view:d}=e,{layer:f,filter:p,zoomScale:g}=a,b=d?.scale,L=y(a,d),R=t?.signal;return x(f).then(()=>{const e=f.popupTemplate;return e?e.getRequiredFields(f.fieldsIndex):null}).then(e=>{const{objectIdField:t,returnZ:y}=f,x=S(a);if(!j(f,x))throw m().error("invalid-field: displayField is invalid."),new r("getResults():invalid-field","displayField is invalid.");const C=e?.length?e:[x],E=a.outFields||C,D=h(E);E.includes(t)||D||E.push(t),f.floorInfo?.floorField&&E.push(f.floorInfo.floorField);if(!(D||I(f,E)))throw m().error("invalid-field: outField is invalid."),new r("getResults():invalid-field","outField is invalid.");const A=f.createQuery(),{orderByFields:N}=a;if(N&&(A.orderByFields=N),s){A.outSpatialReference=s;const e=1/o(s);e&&(A.maxAllowableOffset=e)}const k="mesh"===f.geometryType||"multipatch"===f.geometryType,O=f.capabilities?.data?.supportsZ&&!k;if(A.returnZ=O&&!1!==y,A.returnGeometry=!0,A.multipatchOption=k?"xyFootprint":null,E&&(A.outFields=E),n)A.geometry=n;else if(c.key)A.objectIds=[c.key];else{const e=a.searchFields||[x];if(!I(f,e))throw m().error("invalid-field: search field is invalid."),new r("getResults():invalid-field","search field is invalid.");T(f)&&(A.num=l),L&&(A.geometry=L);const t=c.text?.trim();if(!t)return[];const n=c.text,{prefix:o="",suffix:s=""}=a,u=q(`${o}${n}${s}`);$(f)&&v(f,e)&&!i&&n&&(A.fullText=w({text:n,searchFields:e}));const d=M({searchTerm:u,layer:f,searchFields:e,filter:p,exactMatch:i,query:A,type:"search"});if(A.where=d,!F(A))return[]}return f.queryFeatures(A,{signal:R}).then(e=>G(e,d,a,u,x,b,g))})}function g(e,t){const{source:i,spatialReference:n,view:l,suggestTerm:o,maxSuggestions:s,sourceIndex:a,exactMatch:u}=e,{layer:c,filter:d}=i,p=t?.signal,g=y(i,l);return x(c).then(()=>{if(!T(c))return[];const e=S(i),t=i.searchFields||[e],l=[];i.suggestionTemplate?i.suggestionTemplate.replaceAll(f,(e,t)=>(l.push(t),e)):l.push(e);const y=h(l);l.includes(c.objectIdField)||y||l.push(c.objectIdField);const x=j(c,e),b=y||I(c,l),L=I(c,t);if(!x)throw m().error("invalid-field: displayField is invalid."),new r("getSuggestions():invalid-field","displayField is invalid.");if(!b)throw m().error("invalid-field: outField is invalid."),new r("getSuggestions():invalid-field","outField is invalid.");if(!L)throw m().error("invalid-field: search field is invalid."),new r("getSuggestions():invalid-field","search field is invalid.");const R=c.createQuery(),{orderByFields:C}=i;C&&(R.orderByFields=C),R.outSpatialReference=n,R.returnGeometry=!1,R.num=s,R.outFields=l,g&&(R.geometry=g);if(!o.trim())return[];const{prefix:E="",suffix:D=""}=i,A=q(`${E}${o}${D}`);$(c)&&v(c,t)&&!u&&o&&(R.fullText=w({text:o,searchFields:t}));const N=M({searchTerm:A,layer:c,searchFields:t,filter:d,exactMatch:u,query:R,type:"suggest"});return R.where=N,F(R)?c.queryFeatures(R,{signal:p}).then(t=>B(t,i,a,e)):[]})}function y(e,t){const{filter:r,withinViewEnabled:i}=e,n=t?.extent,l=r?.geometry;return l??(i&&n?n:void 0)}function h(e){return e&&e.includes("*")}async function x(e){e&&await e.load()}function F(e){return!(!e.fullText&&!e.where)}function v(e,t){const r=e?.indexes;if(!r||!t?.length)return!1;return r.filter(e=>"FullText"===e.indexType).some(e=>{const r=e.fields?.split(",").map(e=>e.trim().toLowerCase())||[];return t.every(e=>r.includes(e.toLowerCase()))})}function w({text:e,searchFields:t}){return e.trim().split(" ").filter(e=>!!e.trim()).map(e=>new c({onFields:t,searchTerm:e,searchType:"prefix"}))}function $(e){return e?.capabilities?.query?.supportsFullTextSearch??!1}function T(e){return e?.capabilities?.query?.supportsPagination??!1}function b(e){return e?.fieldsIndex?.fields?.find(e=>"string"===e.type)?.name??""}function S(e){return e.displayField||e.layer.displayField||b(e.layer)}function I(e,t){return!(!e||!t?.length)&&t.every(t=>j(e,t))}function j(e,t){return!!e.getField(t)}function L(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!0;return!1}function R({codedValues:e},t,r){return l(e??[],e=>{const i=e.name,n=r?i:i.toLowerCase();return(r?t:t.toLowerCase())===n?e.code.toString():null})??null}function q(e){return e.replaceAll("'","''")}function C(e,t){const r=t?.where;return r?`(${e}) AND (${r})`:e}function E({currentTerm:e,field:t,filter:r,exactMatch:i,url:n,type:l}){const o=t?.type,s=t?.name;if("string"===o||"date"===o||"global-id"===o){const t=d.test(n??""),o=t&&L(e)?"N":"";if(i&&"search"===l)return C(`${s} = ${o}'${e}'`,r);if(t){return C(`${s} LIKE ${o}${`'${e}%'`}`,r)}return C(`${`LOWER(${s})`} LIKE ${o}${`'${e.toLowerCase()}%'`}`,r)}if("oid"===o||"small-integer"===o||"integer"===o||"single"===o||"double"===o){const t=Number(e);return isNaN(t)?null:C(`${s} = ${t}`,r)}return C(`${s} = ${e}`,r)}function D(e,t){return e?` OR (${t})`:`(${t})`}function M({searchTerm:e,layer:t,searchFields:r,filter:i,exactMatch:n,query:l,type:o}){const{definitionExpression:s,url:a}=t;let u="";return!l.fullText&&e&&r&&r.forEach(r=>{const l=t.getField(r),s=t.getFieldDomain?.(r,{excludeImpliedDomains:has("esri-widget-legacy-field-domain-calculation")}),c=("coded-value"===s?.type?R(s,e,n):null)||e||null;if(null!==c){const e=E({currentTerm:c,field:l,filter:i,exactMatch:n,url:a,type:o});e&&(u+=D(u,e))}}),s&&u?`(${s}) AND (${u})`:s||u}function A(e,t){let r=null;const{codedValues:i}=e;return i&&i.length&&i.some(e=>e.code===t&&(r=e.name,!0)),r}function N(e,t){return e[t]??e[Object.keys(e).find(e=>e.toLowerCase()===t.toLowerCase())]}function k(r,i,n){const l=r.sourceLayer,{attributes:o}=r,s=l.getFieldDomain?.(n,{feature:r,excludeImpliedDomains:has("esri-widget-legacy-field-domain-calculation")});if(i)return e(i,o);if(n&&o){const e=l.getField(n),r=N(o,n);return null==r?"":"coded-value"===s?.type?A(s,r)??"":"date"===e?.type?t(new Date(r)):"number"==typeof r?r.toString():"string"!=typeof r?"":r.trim()}return""}function O(e,t,r,i){const n=e.sourceLayer,{attributes:l}=e,{objectIdField:o}=n,s=o?l[o]:null;return{text:k(e,t.suggestionTemplate,i),key:s,sourceIndex:r}}function B(e,t,r,i){return e.features.map(e=>O(e,t,r,i))}function V(e){return null!=e&&null!=e.minScale&&null!=e.maxScale}function Z(e,t,r,n,l,o,c){const d=e.clone();d.layer=e.layer;const f=e.sourceLayer,m=f?.objectIdField,p=m?e.attributes[m]:null,g=k(e,r.searchTemplate,l);null!=o&&V(f)&&(f.minScale&&f.minScale<o?o=f.minScale:f.maxScale&&f.maxScale>o&&(o=f.maxScale));const y=d.geometry?a(d.geometry,t??void 0,o??void 0):void 0,h="number"==typeof c&&y?u(i(y),t??void 0,c):y,x=e.clone();return x.layer=e.layer,null!=h&&(x.geometry=s.fromExtent(h)),{extent:h,target:x,feature:d,key:p,name:g,sourceIndex:n}}function G(e,t,r,i,n,l,o){return e.features.map(e=>Z(e,t,r,i,n,l,o))}export{w as createFullTextSearchInfos,p as getResults,g as getSuggestions};
5
+ import{substitute as e,formatDate as t}from"../../../intl.js";import r from"../../../core/Error.js";import{clone as i}from"../../../core/lang.js";import n from"../../../core/Logger.js";import{mappedFind as l}from"../../../core/maybe.js";import{getMetersPerUnitForSR as o}from"../../../core/units.js";import s from"../../../geometry/Polygon.js";import{createExtentFromGeometry as u,scaleExtent as a}from"../../../geometry/support/geometryUtils.js";import c from"../../../rest/support/FullTextSearch.js";const d=/https?:\/\/services.*\.arcgis\.com/i,f=/(?:\{([^}]+)\})/g,m=()=>n.getLogger("esri.widgets.Search.support.layerSearchUtils");function p(e,t){const{exactMatch:i=!1,location:n,maxResults:l,spatialReference:s,source:u,sourceIndex:a,suggestResult:c,view:d}=e,{layer:f,filter:p,zoomScale:y}=u,b=d?.scale,L=g(u,d),R=t?.signal;return x(f).then(()=>{const e=f.popupTemplate;return e?e.getRequiredFields(f.fieldsIndex):null}).then(e=>{const{objectIdField:t,returnZ:g}=f,x=S(u);if(!I(f,x))throw m().error("invalid-field: displayField is invalid."),new r("getResults():invalid-field","displayField is invalid.");const C=e?.length?e:[x],E=u.outFields||C,M=h(E);E.includes(t)||M||E.push(t),f.floorInfo?.floorField&&E.push(f.floorInfo.floorField);if(!(M||j(f,E)))throw m().error("invalid-field: outField is invalid."),new r("getResults():invalid-field","outField is invalid.");const N=f.createQuery(),{orderByFields:k}=u;if(k&&(N.orderByFields=k),s){N.outSpatialReference=s;const e=1/o(s);e&&(N.maxAllowableOffset=e)}const D="mesh"===f.geometryType||"multipatch"===f.geometryType,O=f.capabilities?.data?.supportsZ&&!D;if(N.returnZ=O&&!1!==g,N.returnGeometry=!0,N.multipatchOption=D?"xyFootprint":null,E&&(N.outFields=E),n)N.geometry=n;else if(c.key)N.objectIds=[c.key];else{const e=u.searchFields||[x];if(!j(f,e))throw m().error("invalid-field: search field is invalid."),new r("getResults():invalid-field","search field is invalid.");T(f)&&(N.num=l),L&&(N.geometry=L);const t=c.text?.trim();if(!t)return[];const n=c.text,{prefix:o="",suffix:s=""}=u,a=q(`${o}${n}${s}`);$(f)&&v(f,e)&&!i&&n&&(N.fullText=w({text:n,searchFields:e}));const d=A({searchTerm:a,layer:f,searchFields:e,filter:p,exactMatch:i,query:N,type:"search"});if(N.where=d,!F(N))return[]}return f.queryFeatures(N,{signal:R}).then(e=>G(e,d,u,a,x,b,y))})}function y(e,t){const{source:i,spatialReference:n,view:l,suggestTerm:o,maxSuggestions:s,sourceIndex:u,exactMatch:a}=e,{layer:c,filter:d}=i,p=t?.signal,y=g(i,l);return x(c).then(()=>{if(!T(c))return[];const e=S(i),t=i.searchFields||[e],l=[];i.suggestionTemplate?i.suggestionTemplate.replaceAll(f,(e,t)=>(l.push(t),e)):l.push(e);const g=h(l);l.includes(c.objectIdField)||g||l.push(c.objectIdField);const x=I(c,e),b=g||j(c,l),L=j(c,t);if(!x)throw m().error("invalid-field: displayField is invalid."),new r("getSuggestions():invalid-field","displayField is invalid.");if(!b)throw m().error("invalid-field: outField is invalid."),new r("getSuggestions():invalid-field","outField is invalid.");if(!L)throw m().error("invalid-field: search field is invalid."),new r("getSuggestions():invalid-field","search field is invalid.");const R=c.createQuery(),{orderByFields:C}=i;C&&(R.orderByFields=C),R.outSpatialReference=n,R.returnGeometry=!1,R.num=s,R.outFields=l,y&&(R.geometry=y);if(!o.trim())return[];const{prefix:E="",suffix:M=""}=i,N=q(`${E}${o}${M}`);$(c)&&v(c,t)&&!a&&o&&(R.fullText=w({text:o,searchFields:t}));const k=A({searchTerm:N,layer:c,searchFields:t,filter:d,exactMatch:a,query:R,type:"suggest"});return R.where=k,F(R)?c.queryFeatures(R,{signal:p}).then(t=>B(t,i,u,e)):[]})}function g(e,t){const{filter:r,withinViewEnabled:i}=e,n=t?.extent,l=r?.geometry;return l??(i&&n?n:void 0)}function h(e){return e&&e.includes("*")}async function x(e){e&&await e.load()}function F(e){return!(!e.fullText&&!e.where)}function v(e,t){const r=e?.indexes;if(!r||!t?.length)return!1;return r.filter(e=>"FullText"===e.indexType).some(e=>{const r=e.fields?.split(",").map(e=>e.trim().toLowerCase())||[];return t.every(e=>r.includes(e.toLowerCase()))})}function w({text:e,searchFields:t}){return e.trim().split(" ").filter(e=>!!e.trim()).map(e=>new c({onFields:t,searchTerm:e,searchType:"prefix"}))}function $(e){return e?.capabilities?.query?.supportsFullTextSearch??!1}function T(e){return e?.capabilities?.query?.supportsPagination??!1}function b(e){return e?.fieldsIndex?.fields?.find(e=>"string"===e.type)?.name??""}function S(e){return e.displayField||e.layer.displayField||b(e.layer)}function j(e,t){return!(!e||!t?.length)&&t.every(t=>I(e,t))}function I(e,t){return!!e.getField(t)}function L(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!0;return!1}function R({codedValues:e},t,r){return l(e??[],e=>{const i=e.name,n=r?i:i.toLowerCase();return(r?t:t.toLowerCase())===n?e.code.toString():null})??null}function q(e){return e.replaceAll("'","''")}function C(e,t){const r=t?.where;return r?`(${e}) AND (${r})`:e}function E({currentTerm:e,field:t,filter:r,exactMatch:i,url:n,type:l}){const o=t?.type,s=t?.name;if("string"===o||"date"===o||"global-id"===o){const t=d.test(n??""),o=t&&L(e)?"N":"";if(i&&"search"===l)return C(`${s} = ${o}'${e}'`,r);if(t){return C(`${s} LIKE ${o}${`'${e}%'`}`,r)}return C(`${`LOWER(${s})`} LIKE ${o}${`'${e.toLowerCase()}%'`}`,r)}if("oid"===o||"small-integer"===o||"integer"===o||"single"===o||"double"===o){const t=Number(e);return isNaN(t)?null:C(`${s} = ${t}`,r)}return C(`${s} = ${e}`,r)}function M(e,t){return e?` OR (${t})`:`(${t})`}function A({searchTerm:e,layer:t,searchFields:r,filter:i,exactMatch:n,query:l,type:o}){const{definitionExpression:s,url:u}=t;let a="";return!l.fullText&&e&&r&&r.forEach(r=>{const l=t.getField(r),s=t.getFieldDomain?.(r),c=("coded-value"===s?.type?R(s,e,n):null)||e||null;if(null!==c){const e=E({currentTerm:c,field:l,filter:i,exactMatch:n,url:u,type:o});e&&(a+=M(a,e))}}),s&&a?`(${s}) AND (${a})`:s||a}function N(e,t){let r=null;const{codedValues:i}=e;return i&&i.length&&i.some(e=>e.code===t&&(r=e.name,!0)),r}function k(e,t){return e[t]??e[Object.keys(e).find(e=>e.toLowerCase()===t.toLowerCase())]}function D(r,i,n){const l=r.sourceLayer,{attributes:o}=r,s=l.getFieldDomain?.(n,{feature:r});if(i)return e(i,o);if(n&&o){const e=l.getField(n),r=k(o,n);return null==r?"":"coded-value"===s?.type?N(s,r)??"":"date"===e?.type?t(new Date(r)):"number"==typeof r?r.toString():"string"!=typeof r?"":r.trim()}return""}function O(e,t,r,i){const n=e.sourceLayer,{attributes:l}=e,{objectIdField:o}=n,s=o?l[o]:null;return{text:D(e,t.suggestionTemplate,i),key:s,sourceIndex:r}}function B(e,t,r,i){return e.features.map(e=>O(e,t,r,i))}function V(e){return null!=e&&null!=e.minScale&&null!=e.maxScale}function Z(e,t,r,n,l,o,c){const d=e.clone();d.layer=e.layer;const f=e.sourceLayer,m=f?.objectIdField,p=m?e.attributes[m]:null,y=D(e,r.searchTemplate,l);null!=o&&V(f)&&(f.minScale&&f.minScale<o?o=f.minScale:f.maxScale&&f.maxScale>o&&(o=f.maxScale));const g=d.geometry?u(d.geometry,t??void 0,o??void 0):void 0,h="number"==typeof c&&g?a(i(g),t??void 0,c):g,x=e.clone();return x.layer=e.layer,null!=h&&(x.geometry=s.fromExtent(h)),{extent:h,target:x,feature:d,key:p,name:y,sourceIndex:n}}function G(e,t,r,i,n,l,o){return e.features.map(e=>Z(e,t,r,i,n,l,o))}export{w as createFullTextSearchInfos,p as getResults,y as getSuggestions};
package/widgets/Search.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/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import{substitute as t}from"../intl.js";import s from"../PopupTemplate.js";import{deprecateWidget as o,deprecatedPropertyValue as r}from"../core/deprecate.js";import i from"../core/Logger.js";import{destroyMaybe as l,abortMaybe as n}from"../core/maybe.js";import{ignoreAbortErrors as a,isAbortError as c}from"../core/promiseUtils.js";import{watch as u,on as h,initial as d}from"../core/reactiveUtils.js";import{waitAnimationFrame as p}from"../core/scheduling.js";import{property as g,subclass as m}from"../core/accessorSupport/decorators.js";import v from"../portal/Portal.js";import _ from"./Widget.js";import{css as w}from"./Search/css.js";import M from"./Search/SearchResultRenderer.js";import S from"./Search/SearchViewModel.js";import{SourceCollection as b}from"./Search/types.js";import{loadCalciteComponents as y}from"./support/componentsUtils.js";import{globalCss as f}from"./support/globalCss.js";import{messageBundle as C,vmEvent as T,tsx as A}from"./support/widget.js";let R=class extends _{constructor(e,t){super(e,t),this._currentLocationValue=`${this.id}-search-use-current-location`,this._autocompleteNode=null,this._focusAbortController=null,this._searchResultRenderer=new M,this._suggestController=null,this._searchController=null,this._lastSearchTerm="",this._locateFailed=!1,this._showNoResults=!1,this.disabled=!1,this.messages=null,this.messagesCommon=null,this.viewModel=new S,this._renderSearchResultsContent=()=>this._searchResultRenderer,o(i.getLogger(this),"Search","arcgis-search",{version:"4.33"}),this.addHandles([u(()=>this.viewModel,e=>this._searchResultRenderer.viewModel=e,d),u(()=>this.viewModel.results,()=>this._searchResultRenderer.showMoreResultsOpen=!1),u(()=>this.messages,e=>this.viewModel.messages=e),u(()=>this.viewModel?.defaultPopupTemplate,e=>{e&&(e.content=this._renderSearchResultsContent)},d),u(()=>this.viewModel?.view?.popupElement&&this.viewModel?.defaultPopupTemplate,()=>{if(this.viewModel?.defaultPopupTemplate&&this.viewModel?.view?.popupElement){const e=document.createElement("arcgis-search-result-renderer");e.viewModel=this.viewModel,e.messages=this.messages,this.viewModel.defaultPopupTemplate.content=e}},d),h(()=>this.viewModel,"popup-open",async e=>{const{features:t,location:s}=e;await(this.view?.openPopup({features:t,location:s??void 0}))})])}loadDependencies(){return y({autocomplete:()=>import("@esri/calcite-components/dist/components/calcite-autocomplete"),"autocomplete-item-group":()=>import("@esri/calcite-components/dist/components/calcite-autocomplete-item-group"),"autocomplete-item":()=>import("@esri/calcite-components/dist/components/calcite-autocomplete-item"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),dropdown:()=>import("@esri/calcite-components/dist/components/calcite-dropdown"),"dropdown-group":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-group"),"dropdown-item":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-item"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice")})}destroy(){this._cancelQueries(),this._searchResultRenderer=l(this._searchResultRenderer),this._focusAbortController?.abort()}get _isDisabled(){const{state:e}=this.viewModel;return"disabled"===e||"loading"===e||this.disabled}get _showCurrentLocation(){return this.locationEnabled&&!this.searchTerm?.trim()}get _effectiveActiveMenu(){const{activeMenu:e}=this;return this._isDisabled?"none":"warning"===e?"suggestion":e}get activeMenu(){return"none"}set activeMenu(e){"warning"===e&&r(i.getLogger(this),"activeMenu","warning",{replacement:"Use the value 'suggestion' instead",version:"4.32",warnOnce:!0}),this._overrideIfSome("activeMenu",e)}get activeSource(){return this.viewModel?.activeSource}get activeSourceIndex(){return this.viewModel.activeSourceIndex}set activeSourceIndex(e){this.viewModel.activeSourceIndex=e}get allPlaceholder(){return this.viewModel.allPlaceholder}set allPlaceholder(e){this.viewModel.allPlaceholder=e}get allSources(){return this.viewModel.allSources}get autoNavigate(){return this.viewModel.autoNavigate}set autoNavigate(e){this.viewModel.autoNavigate=e}get autoSelect(){return this.viewModel.autoSelect}set autoSelect(e){this.viewModel.autoSelect=e}get defaultSources(){return this.viewModel.defaultSources}get goToOverride(){return this.viewModel.goToOverride}set goToOverride(e){this.viewModel.goToOverride=e}get icon(){return"search"}set icon(e){this._overrideIfSome("icon",e)}get includeDefaultSources(){return this.viewModel.includeDefaultSources}set includeDefaultSources(e){this.viewModel.includeDefaultSources=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get locationEnabled(){return this.viewModel.locationEnabled}set locationEnabled(e){this.viewModel.locationEnabled=e}get maxResults(){return this.viewModel.maxResults}set maxResults(e){this.viewModel.maxResults=e}get maxSuggestions(){return this.viewModel.maxSuggestions}set maxSuggestions(e){this.viewModel.maxSuggestions=e}get minSuggestCharacters(){return this.viewModel.minSuggestCharacters}set minSuggestCharacters(e){this.viewModel.minSuggestCharacters=e}get popupEnabled(){return this.viewModel.popupEnabled}set popupEnabled(e){this.viewModel.popupEnabled=e}get popupTemplate(){return this.viewModel.popupTemplate}set popupTemplate(e){this.viewModel.popupTemplate=e}get portal(){return this.viewModel?.portal}set portal(e){this.viewModel&&(this.viewModel.portal=e)}get resultGraphic(){return this.viewModel.resultGraphic}set resultGraphic(e){this.viewModel.resultGraphic=e}get resultGraphicEnabled(){return this.viewModel.resultGraphicEnabled}set resultGraphicEnabled(e){this.viewModel.resultGraphicEnabled=e}get results(){return this.viewModel.results}get searchAllEnabled(){return this.viewModel.searchAllEnabled}set searchAllEnabled(e){this.viewModel.searchAllEnabled=e}get searchTerm(){return this.viewModel.searchTerm}set searchTerm(e){this.viewModel.searchTerm=e}get selectedResult(){return this.viewModel.selectedResult}get sources(){return this.viewModel.sources}set sources(e){this.viewModel.sources=e}get suggestions(){return this.viewModel.suggestions}get suggestionsEnabled(){return this.viewModel.suggestionsEnabled}set suggestionsEnabled(e){this.viewModel.suggestionsEnabled=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}clear(){this._locateFailed=!1,this.viewModel.clear()}focus(){this._handleFocus(),this._emitFocus()}blur(){this._autocompleteNode?.blur(),this._emitBlur()}async search(e){this._cancelQueries();const t=new AbortController,{signal:s}=t;this._searchController=t;try{const o=await this.viewModel.search(e,{signal:s});if(this._searchController!==t)return;return o?.numResults||(this._showNoResults=!0,this.activeMenu="suggestion"),this._searchController=null,o}catch(o){if(this._searchController!==t)return;return void(this._searchController=null)}}async suggest(e){this._cancelSuggest();const t=new AbortController,{signal:s}=t;this._suggestController=t;try{const o=await this.viewModel.suggest(e,null,{signal:s});if(this._suggestController!==t)return;return this._suggestController=null,o?.numResults&&(this.activeMenu="suggestion",this._scrollToTopSuggestion()),o}catch(o){return this._suggestController!==t||(this._suggestController=null),null}}render(){return A("div",{class:this.classes(w.base,f.widget)},A("div",{class:w.container},this._renderSourcesMenu(),this._renderForm()))}_handleInputKeydown(e){"Tab"===e.key&&this._cancelSuggest()}_emitFocus(){this.emit("search-focus")}_emitBlur(){this.emit("search-blur")}async _handleFocus(){this._focusAbortController?.abort(),this._focusAbortController=new AbortController;const e=this._focusAbortController.signal;await a(p(e)),this._autocompleteNode?.setFocus()}_renderSourcesMenu(){const{messages:e,_isDisabled:t,_effectiveActiveMenu:s}=this,{allSources:o,searchAllEnabled:r}=this.viewModel;return o.length>1?A("calcite-dropdown",{bind:this,class:w.dropdown,disabled:t,open:"source"===s,overlayPositioning:"fixed",onCalciteDropdownClose:this._handleSourceClose,onCalciteDropdownOpen:this._handleSourceOpen,onCalciteDropdownSelect:this._handleSourceSelect},A("calcite-button",{appearance:"outline-fill",iconStart:"caret-down",kind:"neutral",label:e.searchIn,slot:"trigger"}),A("calcite-dropdown-group",{groupTitle:e.searchIn},r?this._renderSource(S.ALL_INDEX):null,o.map((e,t)=>this._renderSource(t)).toArray())):null}_renderUseCurrentLocation(){const{_currentLocationValue:e}=this;return A("calcite-autocomplete-item",{heading:this.messages.useCurrentLocation,iconStart:"gps-on",key:e,value:e})}_handleAutocompleteCreate(e){this._autocompleteNode=e}_handleCalciteAutocompleteTextInput(e){const t=e.target.inputValue;t!==this.viewModel.searchTerm&&(this.viewModel.searchTerm=t,t||this.clear(),this.suggest())}_handleAutocompleteOpen(){this.activeMenu="suggestion"}_handleAutocompleteClose(){"suggestion"===this.activeMenu&&(this.activeMenu="none")}_handleCalciteAutocompleteChange(e){const t=e.target.value;if(t===this._currentLocationValue)return void this._useCurrentLocation();const s=JSON.parse(t),o=this.viewModel.suggestions?.find(({sourceIndex:e})=>e===s.sourceIndex)?.results?.find(({key:e})=>`${e}`==`${s.key}`);o&&this.search(o)}_renderAutocomplete(){const{_effectiveActiveMenu:e,messages:t,_isDisabled:s}=this,{maxInputLength:o,placeholder:r,searchTerm:i,state:l}=this.viewModel,n=this.label??t.searchButtonTitle??"";return A("calcite-autocomplete",{afterCreate:this._handleAutocompleteCreate,autocomplete:"off",bind:this,class:w.autocomplete,disabled:s,icon:this.icon||!1,inputValue:i,label:n,loading:"searching"===l,maxLength:o,name:this.id,onblur:this._emitBlur,onfocus:this._emitFocus,onkeydown:this._handleInputKeydown,open:"suggestion"===e,overlayPositioning:"fixed",placeholder:r,title:i?"":r,onCalciteAutocompleteChange:this._handleCalciteAutocompleteChange,onCalciteAutocompleteClose:this._handleAutocompleteClose,onCalciteAutocompleteOpen:this._handleAutocompleteOpen,onCalciteAutocompleteTextChange:this._handleCalciteAutocompleteTextInput,onCalciteAutocompleteTextInput:this._handleCalciteAutocompleteTextInput},this._renderSuggestions(),this._renderNotices())}_renderForm(){return A("form",{bind:this,class:w.form,disabled:this._isDisabled,key:w.form,onsubmit:this._formSubmit,role:"search"},this._renderAutocomplete(),A("button",{class:w.submitButton,type:"submit"},this.label??this.messages.searchButtonTitle??""))}_renderSuggestGroup(e){return e.results?.map(e=>this._renderSuggestion(e))}_renderSuggestions(){const{suggestions:e}=this.viewModel;return this._showNoResults?null:this._showCurrentLocation?this._renderUseCurrentLocation():e?.map(e=>this._renderSuggestResults(e))}_renderSuggestResults(e){const{allSources:t,activeSourceIndex:s}=this.viewModel,{sourceIndex:o}=e,r=e.results?.length,i=t.length>1&&s===S.ALL_INDEX,l=this._getSourceName(o);return r&&i?A("calcite-autocomplete-item-group",{heading:l,key:`suggestion-group-${l}-${o}`},this._renderSuggestGroup(e)):this._renderSuggestGroup(e)}_renderSuggestion({key:e,sourceIndex:t,text:s}){const o={key:e,sourceIndex:t};return A("calcite-autocomplete-item",{heading:s??this.messages.untitledResult,key:`suggestion_${e}`,value:JSON.stringify(o)})}_renderSource(e){const t=this._getSourceName(e);return A("calcite-dropdown-item",{"data-source-index":`${e}`,key:`source-${t}-${e}`,selected:e===this.viewModel.activeSourceIndex},t)}_renderNoResultsWarning(e){const{messages:s}=this,o=e?t(s.noResultsFoundForValue,{value:`"${e}"`}):s.noResultsFound;return A("calcite-notice",{icon:"exclamation-mark-triangle",key:"no-results-warning",kind:"warning",open:!0,slot:"content-bottom"},A("div",{slot:"title"},s.noResults),A("div",{slot:"message"},o))}_renderLocateError(){return A("calcite-notice",{icon:"exclamation-mark-circle",key:"locate-warning",kind:"danger",open:!0,slot:"content-bottom"},A("div",{slot:"message"},this.messages.locateError))}_renderNotices(){return this._locateFailed?this._renderLocateError():this._showNoResults?this._renderNoResultsWarning(this._lastSearchTerm??this.viewModel.searchTerm):null}async _useCurrentLocation(){this._cancelQueries();const e=new AbortController,{signal:t}=e;this._searchController=e;try{await this.viewModel.searchNearby({signal:t})}catch(s){c(s)||(this._locateFailed=!0,this.activeMenu="suggestion")}finally{this._searchController=null}}_handleSourceOpen(){this.activeMenu="source"}_handleSourceClose(){"source"===this.activeMenu&&(this.activeMenu="none")}_handleSourceSelect(e){const t=e.target.selectedItems[0].getAttribute("data-source-index");t&&(this.viewModel.activeSourceIndex=parseInt(t,10))}_cancelSuggest(){this.activeMenu="none",this._locateFailed=!1,this._showNoResults=!1,this._suggestController=n(this._suggestController)}_cancelQueries(){this._cancelSuggest(),this._searchController=n(this._searchController)}_scrollToTopSuggestion(){this._autocompleteNode?.scrollContentTo({top:0})}_formSubmit(e){e.preventDefault(),this.activeMenu="none",this._lastSearchTerm=this.searchTerm,this.searchTerm&&this.search()}_getSourceName(e){const{messages:t}=this,{allSources:s}=this.viewModel,o=s.at(e);return e===S.ALL_INDEX?t.all:o?.name||t.untitledSource}};e([g()],R.prototype,"_locateFailed",void 0),e([g()],R.prototype,"_showNoResults",void 0),e([g()],R.prototype,"_isDisabled",null),e([g()],R.prototype,"_showCurrentLocation",null),e([g()],R.prototype,"_effectiveActiveMenu",null),e([g()],R.prototype,"activeMenu",null),e([g({readOnly:!0})],R.prototype,"activeSource",null),e([g()],R.prototype,"activeSourceIndex",null),e([g()],R.prototype,"allPlaceholder",null),e([g({readOnly:!0})],R.prototype,"allSources",null),e([g()],R.prototype,"autoNavigate",null),e([g()],R.prototype,"autoSelect",null),e([g({readOnly:!0})],R.prototype,"defaultSources",null),e([g()],R.prototype,"disabled",void 0),e([g()],R.prototype,"goToOverride",null),e([g()],R.prototype,"icon",null),e([g()],R.prototype,"includeDefaultSources",null),e([g()],R.prototype,"label",null),e([g()],R.prototype,"locationEnabled",null),e([g()],R.prototype,"maxResults",null),e([g()],R.prototype,"maxSuggestions",null),e([g(),C("esri/widgets/Search/t9n/Search")],R.prototype,"messages",void 0),e([g(),C("esri/t9n/common")],R.prototype,"messagesCommon",void 0),e([g()],R.prototype,"minSuggestCharacters",null),e([g()],R.prototype,"popupEnabled",null),e([g({type:s})],R.prototype,"popupTemplate",null),e([g({type:v})],R.prototype,"portal",null),e([g()],R.prototype,"resultGraphic",null),e([g()],R.prototype,"resultGraphicEnabled",null),e([g({readOnly:!0})],R.prototype,"results",null),e([g()],R.prototype,"searchAllEnabled",null),e([g()],R.prototype,"searchTerm",null),e([g({readOnly:!0})],R.prototype,"selectedResult",null),e([g({type:b})],R.prototype,"sources",null),e([g({readOnly:!0})],R.prototype,"suggestions",null),e([g()],R.prototype,"suggestionsEnabled",null),e([g()],R.prototype,"view",null),e([T(["search-complete","search-clear","search-start","select-result","suggest-start","suggest-complete"]),g({type:S})],R.prototype,"viewModel",void 0),R=e([m("esri.widgets.Search")],R);const x=R;export{x as default};
5
+ import{__decorate as e}from"tslib";import{substitute as t}from"../intl.js";import s from"../PopupTemplate.js";import{deprecateWidget as o,deprecatedPropertyValue as r}from"../core/deprecate.js";import i from"../core/Logger.js";import{destroyMaybe as l,abortMaybe as n}from"../core/maybe.js";import{ignoreAbortErrors as a,isAbortError as c}from"../core/promiseUtils.js";import{watch as u,on as h,initial as d}from"../core/reactiveUtils.js";import{waitAnimationFrame as p}from"../core/scheduling.js";import{property as g,subclass as m}from"../core/accessorSupport/decorators.js";import v from"../portal/Portal.js";import{popupFromView as _,closePopup as w}from"../views/popupAdapter.js";import M from"./Widget.js";import{css as S}from"./Search/css.js";import b from"./Search/SearchResultRenderer.js";import y from"./Search/SearchViewModel.js";import{SourceCollection as f}from"./Search/types.js";import{loadCalciteComponents as C}from"./support/componentsUtils.js";import{globalCss as T}from"./support/globalCss.js";import{messageBundle as A,vmEvent as R,tsx as E}from"./support/widget.js";let x=class extends M{constructor(e,t){super(e,t),this._currentLocationValue=`${this.id}-search-use-current-location`,this._autocompleteNode=null,this._focusAbortController=null,this._searchResultRenderer=new b,this._suggestController=null,this._searchController=null,this._lastSearchTerm="",this._locateFailed=!1,this._showNoResults=!1,this.disabled=!1,this.messages=null,this.messagesCommon=null,this.viewModel=new y,this._renderSearchResultsContent=()=>this._searchResultRenderer,o(i.getLogger(this),"Search","arcgis-search",{version:"4.33"}),this.addHandles([u(()=>this.viewModel,e=>this._searchResultRenderer.viewModel=e,d),u(()=>this.viewModel.results,()=>this._searchResultRenderer.showMoreResultsOpen=!1),u(()=>this.messages,e=>this.viewModel.messages=e),u(()=>this.viewModel?.defaultPopupTemplate,e=>{e&&(e.content=this._renderSearchResultsContent)},d),u(()=>this.viewModel?.view?.popupElement&&this.viewModel?.defaultPopupTemplate,()=>{if(this.viewModel?.defaultPopupTemplate&&this.viewModel?.view?.popupElement){const e=document.createElement("arcgis-search-result-renderer");e.viewModel=this.viewModel,e.messages=this.messages,this.viewModel.defaultPopupTemplate.content=e}},d),u(()=>this.viewModel?.resultGraphic,(e,t)=>this._closePopup(t)),h(()=>this.viewModel,"select-result",e=>{const{popupEnabled:t}=e,{view:s,resultGraphic:o,resultLocation:r}=this.viewModel,i=_(s);s&&i&&t&&r&&o?.getEffectivePopupTemplate(i.defaultPopupTemplateEnabled)&&s.openPopup({features:o?[o]:[],location:r})})])}loadDependencies(){return C({autocomplete:()=>import("@esri/calcite-components/dist/components/calcite-autocomplete"),"autocomplete-item-group":()=>import("@esri/calcite-components/dist/components/calcite-autocomplete-item-group"),"autocomplete-item":()=>import("@esri/calcite-components/dist/components/calcite-autocomplete-item"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),dropdown:()=>import("@esri/calcite-components/dist/components/calcite-dropdown"),"dropdown-group":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-group"),"dropdown-item":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-item"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice")})}destroy(){this._cancelQueries(),this._searchResultRenderer=l(this._searchResultRenderer),this._focusAbortController?.abort()}get _isDisabled(){const{state:e}=this.viewModel;return"disabled"===e||"loading"===e||this.disabled}get _showCurrentLocation(){return this.locationEnabled&&!this.searchTerm?.trim()}get _effectiveActiveMenu(){const{activeMenu:e}=this;return this._isDisabled?"none":"warning"===e?"suggestion":e}get activeMenu(){return"none"}set activeMenu(e){"warning"===e&&r(i.getLogger(this),"activeMenu","warning",{replacement:"Use the value 'suggestion' instead",version:"4.32",warnOnce:!0}),this._overrideIfSome("activeMenu",e)}get activeSource(){return this.viewModel?.activeSource}get activeSourceIndex(){return this.viewModel.activeSourceIndex}set activeSourceIndex(e){this.viewModel.activeSourceIndex=e}get allPlaceholder(){return this.viewModel.allPlaceholder}set allPlaceholder(e){this.viewModel.allPlaceholder=e}get allSources(){return this.viewModel.allSources}get autoNavigate(){return this.viewModel.autoNavigate}set autoNavigate(e){this.viewModel.autoNavigate=e}get autoSelect(){return this.viewModel.autoSelect}set autoSelect(e){this.viewModel.autoSelect=e}get defaultSources(){return this.viewModel.defaultSources}get goToOverride(){return this.viewModel.goToOverride}set goToOverride(e){this.viewModel.goToOverride=e}get icon(){return"search"}set icon(e){this._overrideIfSome("icon",e)}get includeDefaultSources(){return this.viewModel.includeDefaultSources}set includeDefaultSources(e){this.viewModel.includeDefaultSources=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get locationEnabled(){return this.viewModel.locationEnabled}set locationEnabled(e){this.viewModel.locationEnabled=e}get maxResults(){return this.viewModel.maxResults}set maxResults(e){this.viewModel.maxResults=e}get maxSuggestions(){return this.viewModel.maxSuggestions}set maxSuggestions(e){this.viewModel.maxSuggestions=e}get minSuggestCharacters(){return this.viewModel.minSuggestCharacters}set minSuggestCharacters(e){this.viewModel.minSuggestCharacters=e}get popupEnabled(){return this.viewModel.popupEnabled}set popupEnabled(e){this.viewModel.popupEnabled=e}get popupTemplate(){return this.viewModel.popupTemplate}set popupTemplate(e){this.viewModel.popupTemplate=e}get portal(){return this.viewModel?.portal}set portal(e){this.viewModel&&(this.viewModel.portal=e)}get resultGraphic(){return this.viewModel.resultGraphic}set resultGraphic(e){this.viewModel.resultGraphic=e}get resultGraphicEnabled(){return this.viewModel.resultGraphicEnabled}set resultGraphicEnabled(e){this.viewModel.resultGraphicEnabled=e}get results(){return this.viewModel.results}get searchAllEnabled(){return this.viewModel.searchAllEnabled}set searchAllEnabled(e){this.viewModel.searchAllEnabled=e}get searchTerm(){return this.viewModel.searchTerm}set searchTerm(e){this.viewModel.searchTerm=e}get selectedResult(){return this.viewModel.selectedResult}get sources(){return this.viewModel.sources}set sources(e){this.viewModel.sources=e}get suggestions(){return this.viewModel.suggestions}get suggestionsEnabled(){return this.viewModel.suggestionsEnabled}set suggestionsEnabled(e){this.viewModel.suggestionsEnabled=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}clear(){this._locateFailed=!1,this.viewModel.clear()}focus(){this._handleFocus(),this._emitFocus()}blur(){this._autocompleteNode?.blur(),this._emitBlur()}async search(e){this._cancelQueries();const t=new AbortController,{signal:s}=t;this._searchController=t;try{const o=await this.viewModel.search(e,{signal:s});if(this._searchController!==t)return;return o?.numResults||(this._showNoResults=!0,this.activeMenu="suggestion"),this._searchController=null,o}catch(o){if(this._searchController!==t)return;return void(this._searchController=null)}}async suggest(e){this._cancelSuggest();const t=new AbortController,{signal:s}=t;this._suggestController=t;try{const o=await this.viewModel.suggest(e,null,{signal:s});if(this._suggestController!==t)return;return this._suggestController=null,o?.numResults&&(this.activeMenu="suggestion",this._scrollToTopSuggestion()),o}catch(o){return this._suggestController!==t||(this._suggestController=null),null}}render(){return E("div",{class:this.classes(S.base,T.widget)},E("div",{class:S.container},this._renderSourcesMenu(),this._renderForm()))}_closePopup(e){const t=_(this.view);e&&t?.selectedFeature===e&&w(this.view?.popup,this.view?.popupElement)}_handleInputKeydown(e){"Tab"===e.key&&this._cancelSuggest()}_emitFocus(){this.emit("search-focus")}_emitBlur(){this.emit("search-blur")}async _handleFocus(){this._focusAbortController?.abort(),this._focusAbortController=new AbortController;const e=this._focusAbortController.signal;await a(p(e)),this._autocompleteNode?.setFocus()}_renderSourcesMenu(){const{messages:e,_isDisabled:t,_effectiveActiveMenu:s}=this,{allSources:o,searchAllEnabled:r}=this.viewModel;return o.length>1?E("calcite-dropdown",{bind:this,class:S.dropdown,disabled:t,open:"source"===s,overlayPositioning:"fixed",onCalciteDropdownClose:this._handleSourceClose,onCalciteDropdownOpen:this._handleSourceOpen,onCalciteDropdownSelect:this._handleSourceSelect},E("calcite-button",{appearance:"outline-fill",iconStart:"caret-down",kind:"neutral",label:e.searchIn,slot:"trigger"}),E("calcite-dropdown-group",{groupTitle:e.searchIn},r?this._renderSource(y.ALL_INDEX):null,o.map((e,t)=>this._renderSource(t)).toArray())):null}_renderUseCurrentLocation(){const{_currentLocationValue:e}=this;return E("calcite-autocomplete-item",{heading:this.messages.useCurrentLocation,iconStart:"gps-on",key:e,value:e})}_handleAutocompleteCreate(e){this._autocompleteNode=e}_handleCalciteAutocompleteTextInput(e){const t=e.target.inputValue;t!==this.viewModel.searchTerm&&(this.viewModel.searchTerm=t,t||this.clear(),this.suggest())}_handleAutocompleteOpen(){this.activeMenu="suggestion"}_handleAutocompleteClose(){"suggestion"===this.activeMenu&&(this.activeMenu="none")}_handleCalciteAutocompleteChange(e){const t=e.target.value;if(t===this._currentLocationValue)return void this._useCurrentLocation();const s=JSON.parse(t),o=this.viewModel.suggestions?.find(({sourceIndex:e})=>e===s.sourceIndex)?.results?.find(({key:e})=>`${e}`==`${s.key}`);o&&this.search(o)}_renderAutocomplete(){const{_effectiveActiveMenu:e,messages:t,_isDisabled:s}=this,{maxInputLength:o,placeholder:r,searchTerm:i,state:l}=this.viewModel,n=this.label??t.searchButtonTitle??"";return E("calcite-autocomplete",{afterCreate:this._handleAutocompleteCreate,autocomplete:"off",bind:this,class:S.autocomplete,disabled:s,icon:this.icon||!1,inputValue:i,label:n,loading:"searching"===l,maxLength:o,name:this.id,onblur:this._emitBlur,onfocus:this._emitFocus,onkeydown:this._handleInputKeydown,open:"suggestion"===e,overlayPositioning:"fixed",placeholder:r,title:i?"":r,onCalciteAutocompleteChange:this._handleCalciteAutocompleteChange,onCalciteAutocompleteClose:this._handleAutocompleteClose,onCalciteAutocompleteOpen:this._handleAutocompleteOpen,onCalciteAutocompleteTextChange:this._handleCalciteAutocompleteTextInput,onCalciteAutocompleteTextInput:this._handleCalciteAutocompleteTextInput},this._renderSuggestions(),this._renderNotices())}_renderForm(){return E("form",{bind:this,class:S.form,disabled:this._isDisabled,key:S.form,onsubmit:this._formSubmit,role:"search"},this._renderAutocomplete(),E("button",{class:S.submitButton,type:"submit"},this.label??this.messages.searchButtonTitle??""))}_renderSuggestGroup(e){return e.results?.map(e=>this._renderSuggestion(e))}_renderSuggestions(){const{suggestions:e}=this.viewModel;return this._showNoResults?null:this._showCurrentLocation?this._renderUseCurrentLocation():e?.map(e=>this._renderSuggestResults(e))}_renderSuggestResults(e){const{allSources:t,activeSourceIndex:s}=this.viewModel,{sourceIndex:o}=e,r=e.results?.length,i=t.length>1&&s===y.ALL_INDEX,l=this._getSourceName(o);return r&&i?E("calcite-autocomplete-item-group",{heading:l,key:`suggestion-group-${l}-${o}`},this._renderSuggestGroup(e)):this._renderSuggestGroup(e)}_renderSuggestion({key:e,sourceIndex:t,text:s}){const o={key:e,sourceIndex:t};return E("calcite-autocomplete-item",{heading:s??this.messages.untitledResult,key:`suggestion_${e}`,value:JSON.stringify(o)})}_renderSource(e){const t=this._getSourceName(e);return E("calcite-dropdown-item",{"data-source-index":`${e}`,key:`source-${t}-${e}`,selected:e===this.viewModel.activeSourceIndex},t)}_renderNoResultsWarning(e){const{messages:s}=this,o=e?t(s.noResultsFoundForValue,{value:`"${e}"`}):s.noResultsFound;return E("calcite-notice",{icon:"exclamation-mark-triangle",key:"no-results-warning",kind:"warning",open:!0,slot:"content-bottom"},E("div",{slot:"title"},s.noResults),E("div",{slot:"message"},o))}_renderLocateError(){return E("calcite-notice",{icon:"exclamation-mark-circle",key:"locate-warning",kind:"danger",open:!0,slot:"content-bottom"},E("div",{slot:"message"},this.messages.locateError))}_renderNotices(){return this._locateFailed?this._renderLocateError():this._showNoResults?this._renderNoResultsWarning(this._lastSearchTerm??this.viewModel.searchTerm):null}async _useCurrentLocation(){this._cancelQueries();const e=new AbortController,{signal:t}=e;this._searchController=e;try{await this.viewModel.searchNearby({signal:t})}catch(s){c(s)||(this._locateFailed=!0,this.activeMenu="suggestion")}finally{this._searchController=null}}_handleSourceOpen(){this.activeMenu="source"}_handleSourceClose(){"source"===this.activeMenu&&(this.activeMenu="none")}_handleSourceSelect(e){const t=e.target.selectedItems[0].getAttribute("data-source-index");t&&(this.viewModel.activeSourceIndex=parseInt(t,10))}_cancelSuggest(){this.activeMenu="none",this._locateFailed=!1,this._showNoResults=!1,this._suggestController=n(this._suggestController)}_cancelQueries(){this._cancelSuggest(),this._searchController=n(this._searchController)}_scrollToTopSuggestion(){this._autocompleteNode?.scrollContentTo({top:0})}_formSubmit(e){e.preventDefault(),this.activeMenu="none",this._lastSearchTerm=this.searchTerm,this.searchTerm&&this.search()}_getSourceName(e){const{messages:t}=this,{allSources:s}=this.viewModel,o=s.at(e);return e===y.ALL_INDEX?t.all:o?.name||t.untitledSource}};e([g()],x.prototype,"_locateFailed",void 0),e([g()],x.prototype,"_showNoResults",void 0),e([g()],x.prototype,"_isDisabled",null),e([g()],x.prototype,"_showCurrentLocation",null),e([g()],x.prototype,"_effectiveActiveMenu",null),e([g()],x.prototype,"activeMenu",null),e([g({readOnly:!0})],x.prototype,"activeSource",null),e([g()],x.prototype,"activeSourceIndex",null),e([g()],x.prototype,"allPlaceholder",null),e([g({readOnly:!0})],x.prototype,"allSources",null),e([g()],x.prototype,"autoNavigate",null),e([g()],x.prototype,"autoSelect",null),e([g({readOnly:!0})],x.prototype,"defaultSources",null),e([g()],x.prototype,"disabled",void 0),e([g()],x.prototype,"goToOverride",null),e([g()],x.prototype,"icon",null),e([g()],x.prototype,"includeDefaultSources",null),e([g()],x.prototype,"label",null),e([g()],x.prototype,"locationEnabled",null),e([g()],x.prototype,"maxResults",null),e([g()],x.prototype,"maxSuggestions",null),e([g(),A("esri/widgets/Search/t9n/Search")],x.prototype,"messages",void 0),e([g(),A("esri/t9n/common")],x.prototype,"messagesCommon",void 0),e([g()],x.prototype,"minSuggestCharacters",null),e([g()],x.prototype,"popupEnabled",null),e([g({type:s})],x.prototype,"popupTemplate",null),e([g({type:v})],x.prototype,"portal",null),e([g()],x.prototype,"resultGraphic",null),e([g()],x.prototype,"resultGraphicEnabled",null),e([g({readOnly:!0})],x.prototype,"results",null),e([g()],x.prototype,"searchAllEnabled",null),e([g()],x.prototype,"searchTerm",null),e([g({readOnly:!0})],x.prototype,"selectedResult",null),e([g({type:f})],x.prototype,"sources",null),e([g({readOnly:!0})],x.prototype,"suggestions",null),e([g()],x.prototype,"suggestionsEnabled",null),e([g()],x.prototype,"view",null),e([R(["search-complete","search-clear","search-start","select-result","suggest-start","suggest-complete"]),g({type:y})],x.prototype,"viewModel",void 0),x=e([m("esri.widgets.Search")],x);const I=x;export{I as default};
@@ -1,2 +0,0 @@
1
- /*! For license information please see 21ac84b5c7dedcfd747d.js.LICENSE.txt */
2
- "use strict";(self.webpackChunkRemoteClient=self.webpackChunkRemoteClient||[]).push([[224],{87843(e,t,n){n.r(t),n.d(t,{Label:()=>r});var l=n(34088),a=n(46337),i=n(98268),c=n(8348),s=n(93174);const o=a.AH`:host([disabled]){cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-opacity-disabled)}:host([disabled]) *,:host([disabled]) ::slotted(*){pointer-events:none}:host{display:flex}:host([alignment=start]){text-align:start}:host([alignment=end]){text-align:end}:host([alignment=center]){text-align:center}:host([scale=s]) .container{gap:.25rem;font-size:var(--calcite-font-size--2);line-height:1rem;margin-block-end:var(--calcite-label-margin-bottom, .5rem)}:host([scale=m]) .container{gap:.5rem;font-size:var(--calcite-font-size--1);line-height:1rem;margin-block-end:var(--calcite-label-margin-bottom, .75rem)}:host([scale=l]) .container{gap:.5rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;margin-block-end:var(--calcite-label-margin-bottom, 1rem)}:host .container{margin-inline:0px;margin-block-start:0px;inline-size:100%;line-height:1.375;color:var(--calcite-color-text-1);color:var(--calcite-label-text-color, var(--calcite-color-text-1))}:host([layout=block]) .container,:host([layout=default]) .container{display:flex;flex-direction:column}:host([layout=inline]) .container,:host([layout=inline-space-between]) .container{display:flex;flex-direction:row;align-items:center;gap:.5rem}:host([layout=inline][scale=l]) .container{gap:.75rem}:host([layout=inline-space-between]) .container{justify-content:space-between}:host([disabled])>.container{opacity:var(--calcite-opacity-disabled)}:host([disabled]) ::slotted(*[disabled]),:host([disabled]) ::slotted(*[disabled] *){--tw-bg-opacity: 1}:host([disabled]) ::slotted(calcite-input-message:not([active])){--tw-bg-opacity: 0}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.interaction-container{display:contents}:host([hidden]){display:none}[hidden]{display:none}`;class r extends i.WF{constructor(){super(),this.alignment="start",this.layout="default",this.scale="m",this.calciteInternalLabelClick=(0,c.c)({bubbles:!1,cancelable:!1}),this.listen("click",this.labelClickHandler)}static{this.properties={alignment:[3,{},{reflect:!0}],for:[3,{},{reflect:!0}],layout:[3,{},{reflect:!0}],scale:[3,{},{reflect:!0}]}}static{this.styles=o}connectedCallback(){super.connectedCallback(),document.dispatchEvent(new CustomEvent(s.l))}willUpdate(e){e.has("for")&&(0,s.a)(this.el)}disconnectedCallback(){super.disconnectedCallback(),document.dispatchEvent(new CustomEvent(s.b))}labelClickHandler(e){"Range"!==window.getSelection()?.type&&this.calciteInternalLabelClick.emit({sourceEvent:e})}render(){return a.qy`<div class=${(0,i.CP)("container")}><slot></slot></div>`}}(0,l.c)("calcite-label",r)},93174(e,t,n){n.d(t,{a:()=>y,b:()=>c,c:()=>u,d:()=>m,g:()=>p,l:()=>i});var l=n(79e3);const a="calciteInternalLabelClick",i="calciteInternalLabelConnected",c="calciteInternalLabelDisconnected",s="calcite-label",o=new WeakMap,r=new WeakMap,d=new WeakMap,b=new WeakMap,h=new Set;function u(e){if(!e)return;const t=(e=>{const{id:t}=e,n=t&&(0,l.q)(e,{selector:`${s}[for="${t}"]`});if(n)return n;const a=(0,l.o)(e,s);return!a||function(e,t){let n;const l="custom-element-ancestor-check",a=l=>{l.stopImmediatePropagation();const a=l.composedPath();n=a.slice(a.indexOf(t),a.indexOf(e))};return e.addEventListener(l,a,{once:!0}),t.dispatchEvent(new CustomEvent(l,{composed:!0,bubbles:!0})),e.removeEventListener(l,a),n.filter(n=>n!==t&&n!==e).filter(e=>e.tagName?.includes("-")).length>0}(a,e)?null:a})(e.el);if(r.has(t)&&t===e.labelEl||!t&&h.has(e))return;const n=E.bind(e);if(t){e.labelEl=t;const l=o.get(t)||[];l.push(e),o.set(t,l.sort(f)),r.has(e.labelEl)||(r.set(e.labelEl,g),e.labelEl.addEventListener(a,g)),h.delete(e),document.removeEventListener(i,d.get(e)),b.set(e,n),document.addEventListener(c,n)}else h.has(e)||(n(),document.removeEventListener(c,b.get(e)))}function m(e){if(!e)return;if(h.delete(e),document.removeEventListener(i,d.get(e)),document.removeEventListener(c,b.get(e)),d.delete(e),b.delete(e),!e.labelEl)return;const t=o.get(e.labelEl);1===t.length&&(e.labelEl.removeEventListener(a,r.get(e.labelEl)),r.delete(e.labelEl)),o.set(e.labelEl,t.filter(t=>t!==e).sort(f)),e.labelEl=null}function f(e,t){return(0,l.p)(e.el,t.el)?-1:1}function p(e){return e.label||e.labelEl?.textContent?.trim()||""}function g(e){const t=e.detail.sourceEvent.target,n=o.get(this),l=n.find(e=>e.el===t);if(n.includes(l))return;const a=n[0];a.disabled||a.onLabelClick(e)}function v(){h.has(this)&&u(this)}function E(){h.add(this);const e=d.get(this)||v.bind(this);d.set(this,e),document.addEventListener(i,e)}async function y(e){if(await e.componentOnReady(),o.has(e))return;const t=e.ownerDocument?.getElementById(e.for);t&&requestAnimationFrame(()=>{for(const e of h)if(e.el===t){u(e);break}})}}}]);