@arcgis/core 4.33.0-next.20250411 → 4.33.0-next.20250412

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{deprecatedPropertyValue as t}from"../core/deprecate.js";import o from"../core/Logger.js";import{destroyMaybe as s,abortMaybe as r}from"../core/maybe.js";import{ignoreAbortErrors as i,isAbortError as l}from"../core/promiseUtils.js";import{watch as n,initial as a}from"../core/reactiveUtils.js";import{waitAnimationFrame as c}from"../core/scheduling.js";import{property as u}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as h}from"../core/accessorSupport/decorators/subclass.js";import d from"./Widget.js";import{css as p}from"./Search/css.js";import g from"./Search/SearchResultRenderer.js";import m from"./Search/SearchViewModel.js";import{loadCalciteComponents as v}from"./support/componentsUtils.js";import{globalCss as _}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as w}from"./support/decorators/messageBundle.js";import{vmEvent as M}from"./support/decorators/vmEvent.js";import{tsx as S}from"./support/jsxFactory.js";import{substitute as b}from"../intl/substitute.js";let y=class extends d{constructor(e,t){super(e,t),this._currentLocationValue=`${this.id}-search-use-current-location`,this._autocompleteNode=null,this._focusAbortController=null,this._searchResultRenderer=new g,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 m,this._renderSearchResultsContent=()=>this._searchResultRenderer,this.addHandles([n((()=>this.viewModel),(e=>this._searchResultRenderer.viewModel=e),a),n((()=>this.viewModel.results),(()=>this._searchResultRenderer.showMoreResultsOpen=!1)),n((()=>this.viewModel?.defaultPopupTemplate),(e=>{e&&(e.content=this._renderSearchResultsContent)}),a)])}loadDependencies(){return v({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=s(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&&t(o.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:o}=t;this._searchController=t;try{const s=await this.viewModel.search(e,{signal:o});if(this._searchController!==t)return;return s?.numResults||(this._showNoResults=!0,this.activeMenu="suggestion"),this._searchController=null,s}catch(s){if(this._searchController!==t)return;return void(this._searchController=null)}}async suggest(e){this._cancelSuggest();const t=new AbortController,{signal:o}=t;this._suggestController=t;try{const s=await this.viewModel.suggest(e,null,{signal:o});if(this._suggestController!==t)return;return this._suggestController=null,s?.numResults&&(this.activeMenu="suggestion",this._scrollToTopSuggestion()),s}catch(s){return this._suggestController!==t||(this._suggestController=null),null}}render(){return S("div",{class:this.classes(p.base,_.widget)},S("div",{class:p.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 i(c(e)),this._autocompleteNode?.setFocus()}_renderSourcesMenu(){const{messages:e,_isDisabled:t,_effectiveActiveMenu:o}=this,{allSources:s,searchAllEnabled:r}=this.viewModel;return s.length>1?S("calcite-dropdown",{bind:this,class:p.dropdown,disabled:t,open:"source"===o,overlayPositioning:"fixed",onCalciteDropdownClose:this._handleSourceClose,onCalciteDropdownOpen:this._handleSourceOpen,onCalciteDropdownSelect:this._handleSourceSelect},S("calcite-button",{appearance:"outline-fill",iconStart:"caret-down",kind:"neutral",label:e.searchIn,slot:"trigger"}),S("calcite-dropdown-group",{groupTitle:e.searchIn},r?this._renderSource(m.ALL_INDEX):null,s.map(((e,t)=>this._renderSource(t))).toArray())):null}_renderUseCurrentLocation(){const{_currentLocationValue:e}=this;return S("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 o=this.viewModel.suggestions?.flatMap((e=>e.results??[])),s=o?.find((e=>`${e.key}`==`${t}`));s&&this.search(s)}_renderAutocomplete(){const{_effectiveActiveMenu:e,messages:t,_isDisabled:o}=this,{maxInputLength:s,placeholder:r,searchTerm:i,state:l}=this.viewModel,n=this.label??t.searchButtonTitle??"";return S("calcite-autocomplete",{afterCreate:this._handleAutocompleteCreate,autocomplete:"off",bind:this,class:p.autocomplete,disabled:o,icon:this.icon,inputValue:i,label:n,loading:"searching"===l,maxLength:s,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 S("form",{bind:this,class:p.form,disabled:this._isDisabled,key:p.form,onsubmit:this._formSubmit,role:"search"},this._renderAutocomplete())}_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:o}=this.viewModel,{sourceIndex:s}=e,r=e.results?.length,i=t.length>1&&o===m.ALL_INDEX,l=this._getSourceName(s);return r&&i?S("calcite-autocomplete-item-group",{heading:l,key:`suggestion-group-${l}-${s}`},this._renderSuggestGroup(e)):this._renderSuggestGroup(e)}_renderSuggestion(e){return S("calcite-autocomplete-item",{heading:e.text??this.messages.untitledResult,key:`suggestion_${e.key}`,value:`${e.key}`})}_renderSource(e){const t=this._getSourceName(e);return S("calcite-dropdown-item",{"data-source-index":`${e}`,key:`source-${t}-${e}`,selected:e===this.viewModel.activeSourceIndex},t)}_renderNoResultsWarning(e){const{messages:t}=this,o=e?b(t.noResultsFoundForValue,{value:`"${e}"`}):t.noResultsFound;return S("calcite-notice",{icon:"exclamation-mark-triangle",key:"no-results-warning",kind:"warning",open:!0,slot:"content-bottom"},S("div",{slot:"title"},t.noResults),S("div",{slot:"message"},o))}_renderLocateError(){return S("calcite-notice",{icon:"exclamation-mark-circle",key:"locate-warning",kind:"danger",open:!0,slot:"content-bottom"},S("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(o){l(o)||(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=r(this._suggestController)}_cancelQueries(){this._cancelSuggest(),this._searchController=r(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:o}=this.viewModel,s=o.at(e);return e===m.ALL_INDEX?t.all:s?.name||t.untitledSource}};e([u()],y.prototype,"_locateFailed",void 0),e([u()],y.prototype,"_showNoResults",void 0),e([u()],y.prototype,"_isDisabled",null),e([u()],y.prototype,"_showCurrentLocation",null),e([u()],y.prototype,"_effectiveActiveMenu",null),e([u()],y.prototype,"activeMenu",null),e([u({readOnly:!0})],y.prototype,"activeSource",null),e([u()],y.prototype,"activeSourceIndex",null),e([u()],y.prototype,"allPlaceholder",null),e([u({readOnly:!0})],y.prototype,"allSources",null),e([u()],y.prototype,"autoNavigate",null),e([u()],y.prototype,"autoSelect",null),e([u({readOnly:!0})],y.prototype,"defaultSources",null),e([u()],y.prototype,"disabled",void 0),e([u()],y.prototype,"goToOverride",null),e([u()],y.prototype,"icon",null),e([u()],y.prototype,"includeDefaultSources",null),e([u()],y.prototype,"label",null),e([u()],y.prototype,"locationEnabled",null),e([u()],y.prototype,"maxResults",null),e([u()],y.prototype,"maxSuggestions",null),e([u(),w("esri/widgets/Search/t9n/Search")],y.prototype,"messages",void 0),e([u(),w("esri/t9n/common")],y.prototype,"messagesCommon",void 0),e([u()],y.prototype,"minSuggestCharacters",null),e([u()],y.prototype,"popupEnabled",null),e([u()],y.prototype,"popupTemplate",null),e([u()],y.prototype,"portal",null),e([u()],y.prototype,"resultGraphic",null),e([u()],y.prototype,"resultGraphicEnabled",null),e([u({readOnly:!0})],y.prototype,"results",null),e([u()],y.prototype,"searchAllEnabled",null),e([u()],y.prototype,"searchTerm",null),e([u({readOnly:!0})],y.prototype,"selectedResult",null),e([u()],y.prototype,"sources",null),e([u({readOnly:!0})],y.prototype,"suggestions",null),e([u()],y.prototype,"suggestionsEnabled",null),e([u()],y.prototype,"view",null),e([M(["search-complete","search-clear","search-start","select-result","suggest-start","suggest-complete"]),u({type:m})],y.prototype,"viewModel",void 0),y=e([h("esri.widgets.Search")],y);const C=y;export{C as default};
5
+ import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{deprecatedPropertyValue as t}from"../core/deprecate.js";import o from"../core/Logger.js";import{destroyMaybe as s,abortMaybe as r}from"../core/maybe.js";import{ignoreAbortErrors as i,isAbortError as l}from"../core/promiseUtils.js";import{watch as n,initial as a}from"../core/reactiveUtils.js";import{waitAnimationFrame as c}from"../core/scheduling.js";import{property as u}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as h}from"../core/accessorSupport/decorators/subclass.js";import d from"./Widget.js";import{css as p}from"./Search/css.js";import g from"./Search/SearchResultRenderer.js";import m from"./Search/SearchViewModel.js";import{loadCalciteComponents as v}from"./support/componentsUtils.js";import{globalCss as _}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as w}from"./support/decorators/messageBundle.js";import{vmEvent as S}from"./support/decorators/vmEvent.js";import{tsx as M}from"./support/jsxFactory.js";import{substitute as b}from"../intl/substitute.js";let y=class extends d{constructor(e,t){super(e,t),this._currentLocationValue=`${this.id}-search-use-current-location`,this._autocompleteNode=null,this._focusAbortController=null,this._searchResultRenderer=new g,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 m,this._renderSearchResultsContent=()=>this._searchResultRenderer,this.addHandles([n((()=>this.viewModel),(e=>this._searchResultRenderer.viewModel=e),a),n((()=>this.viewModel.results),(()=>this._searchResultRenderer.showMoreResultsOpen=!1)),n((()=>this.viewModel?.defaultPopupTemplate),(e=>{e&&(e.content=this._renderSearchResultsContent)}),a)])}loadDependencies(){return v({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=s(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&&t(o.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:o}=t;this._searchController=t;try{const s=await this.viewModel.search(e,{signal:o});if(this._searchController!==t)return;return s?.numResults||(this._showNoResults=!0,this.activeMenu="suggestion"),this._searchController=null,s}catch(s){if(this._searchController!==t)return;return void(this._searchController=null)}}async suggest(e){this._cancelSuggest();const t=new AbortController,{signal:o}=t;this._suggestController=t;try{const s=await this.viewModel.suggest(e,null,{signal:o});if(this._suggestController!==t)return;return this._suggestController=null,s?.numResults&&(this.activeMenu="suggestion",this._scrollToTopSuggestion()),s}catch(s){return this._suggestController!==t||(this._suggestController=null),null}}render(){return M("div",{class:this.classes(p.base,_.widget)},M("div",{class:p.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 i(c(e)),this._autocompleteNode?.setFocus()}_renderSourcesMenu(){const{messages:e,_isDisabled:t,_effectiveActiveMenu:o}=this,{allSources:s,searchAllEnabled:r}=this.viewModel;return s.length>1?M("calcite-dropdown",{bind:this,class:p.dropdown,disabled:t,open:"source"===o,overlayPositioning:"fixed",onCalciteDropdownClose:this._handleSourceClose,onCalciteDropdownOpen:this._handleSourceOpen,onCalciteDropdownSelect:this._handleSourceSelect},M("calcite-button",{appearance:"outline-fill",iconStart:"caret-down",kind:"neutral",label:e.searchIn,slot:"trigger"}),M("calcite-dropdown-group",{groupTitle:e.searchIn},r?this._renderSource(m.ALL_INDEX):null,s.map(((e,t)=>this._renderSource(t))).toArray())):null}_renderUseCurrentLocation(){const{_currentLocationValue:e}=this;return M("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 o=JSON.parse(t),s=this.viewModel.suggestions?.find((({sourceIndex:e})=>e===o.sourceIndex))?.results?.find((({key:e})=>`${e}`==`${o.key}`));s&&this.search(s)}_renderAutocomplete(){const{_effectiveActiveMenu:e,messages:t,_isDisabled:o}=this,{maxInputLength:s,placeholder:r,searchTerm:i,state:l}=this.viewModel,n=this.label??t.searchButtonTitle??"";return M("calcite-autocomplete",{afterCreate:this._handleAutocompleteCreate,autocomplete:"off",bind:this,class:p.autocomplete,disabled:o,icon:this.icon,inputValue:i,label:n,loading:"searching"===l,maxLength:s,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 M("form",{bind:this,class:p.form,disabled:this._isDisabled,key:p.form,onsubmit:this._formSubmit,role:"search"},this._renderAutocomplete())}_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:o}=this.viewModel,{sourceIndex:s}=e,r=e.results?.length,i=t.length>1&&o===m.ALL_INDEX,l=this._getSourceName(s);return r&&i?M("calcite-autocomplete-item-group",{heading:l,key:`suggestion-group-${l}-${s}`},this._renderSuggestGroup(e)):this._renderSuggestGroup(e)}_renderSuggestion({key:e,sourceIndex:t,text:o}){const s={key:e,sourceIndex:t};return M("calcite-autocomplete-item",{heading:o??this.messages.untitledResult,key:`suggestion_${e}`,value:JSON.stringify(s)})}_renderSource(e){const t=this._getSourceName(e);return M("calcite-dropdown-item",{"data-source-index":`${e}`,key:`source-${t}-${e}`,selected:e===this.viewModel.activeSourceIndex},t)}_renderNoResultsWarning(e){const{messages:t}=this,o=e?b(t.noResultsFoundForValue,{value:`"${e}"`}):t.noResultsFound;return M("calcite-notice",{icon:"exclamation-mark-triangle",key:"no-results-warning",kind:"warning",open:!0,slot:"content-bottom"},M("div",{slot:"title"},t.noResults),M("div",{slot:"message"},o))}_renderLocateError(){return M("calcite-notice",{icon:"exclamation-mark-circle",key:"locate-warning",kind:"danger",open:!0,slot:"content-bottom"},M("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(o){l(o)||(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=r(this._suggestController)}_cancelQueries(){this._cancelSuggest(),this._searchController=r(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:o}=this.viewModel,s=o.at(e);return e===m.ALL_INDEX?t.all:s?.name||t.untitledSource}};e([u()],y.prototype,"_locateFailed",void 0),e([u()],y.prototype,"_showNoResults",void 0),e([u()],y.prototype,"_isDisabled",null),e([u()],y.prototype,"_showCurrentLocation",null),e([u()],y.prototype,"_effectiveActiveMenu",null),e([u()],y.prototype,"activeMenu",null),e([u({readOnly:!0})],y.prototype,"activeSource",null),e([u()],y.prototype,"activeSourceIndex",null),e([u()],y.prototype,"allPlaceholder",null),e([u({readOnly:!0})],y.prototype,"allSources",null),e([u()],y.prototype,"autoNavigate",null),e([u()],y.prototype,"autoSelect",null),e([u({readOnly:!0})],y.prototype,"defaultSources",null),e([u()],y.prototype,"disabled",void 0),e([u()],y.prototype,"goToOverride",null),e([u()],y.prototype,"icon",null),e([u()],y.prototype,"includeDefaultSources",null),e([u()],y.prototype,"label",null),e([u()],y.prototype,"locationEnabled",null),e([u()],y.prototype,"maxResults",null),e([u()],y.prototype,"maxSuggestions",null),e([u(),w("esri/widgets/Search/t9n/Search")],y.prototype,"messages",void 0),e([u(),w("esri/t9n/common")],y.prototype,"messagesCommon",void 0),e([u()],y.prototype,"minSuggestCharacters",null),e([u()],y.prototype,"popupEnabled",null),e([u()],y.prototype,"popupTemplate",null),e([u()],y.prototype,"portal",null),e([u()],y.prototype,"resultGraphic",null),e([u()],y.prototype,"resultGraphicEnabled",null),e([u({readOnly:!0})],y.prototype,"results",null),e([u()],y.prototype,"searchAllEnabled",null),e([u()],y.prototype,"searchTerm",null),e([u({readOnly:!0})],y.prototype,"selectedResult",null),e([u()],y.prototype,"sources",null),e([u({readOnly:!0})],y.prototype,"suggestions",null),e([u()],y.prototype,"suggestionsEnabled",null),e([u()],y.prototype,"view",null),e([S(["search-complete","search-clear","search-start","select-result","suggest-start","suggest-complete"]),u({type:m})],y.prototype,"viewModel",void 0),y=e([h("esri.widgets.Search")],y);const C=y;export{C as default};