@arcgis/map-components
Version:
ArcGIS Map Components
238 lines (237 loc) • 23.4 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c as m } from "../../chunks/runtime.js";
import { css as _, html as s } from "lit";
import { ref as v } from "lit/directives/ref.js";
import w from "@arcgis/core/widgets/Search/SearchViewModel.js";
import { LitElement as f, createEvent as b, renderElement as x, safeClassMap as M, nothing as S } from "@arcgis/lumina";
import { reEmitEvent as l } from "@arcgis/lumina/controllers/accessor";
import { a as u } from "../../chunks/maybe.js";
import { classes as y } from "@arcgis/toolkit/dom";
import { g as C } from "../../chunks/globalCss.js";
import { isAbortError as $ } from "@arcgis/core/core/promiseUtils.js";
import { m as R } from "../../chunks/useViewModel.js";
import { s as k } from "../../chunks/sr.js";
import { substitute as h } from "@arcgis/core/intl.js";
import { usePropertyChange as D } from "@arcgis/lumina/controllers";
import { u as E } from "../../chunks/useT9n.js";
import { watch as d, on as T } from "@arcgis/core/core/reactiveUtils.js";
const A = _`.esri-widget__heading{color:var(--calcite-color-text-2);margin:0 0 .5rem;font-weight:var(--calcite-font-weight-semibold)}h1.esri-widget__heading{font-size:var(--calcite-font-size-xl)}h2.esri-widget__heading{font-size:var(--calcite-font-size-md)}h3.esri-widget__heading,h4.esri-widget__heading,h5.esri-widget__heading,h6.esri-widget__heading{font-size:var(--calcite-font-size)}.esri-widget{box-sizing:border-box;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);font-size:var(--calcite-font-size);line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget *,.esri-widget :before,.esri-widget :after{box-sizing:inherit}.esri-widget.esri-widget--disabled>*{opacity:.4;pointer-events:none}.esri-widget.esri-widget--compact{--esri-widget-padding-y: 0;--esri-widget-padding-x: 0}.esri-widget__anchor{color:var(--calcite-color-text-2)}.esri-widget__anchor:hover{color:var(--calcite-color-text-3)}.esri-widget__anchor:hover,.esri-widget__anchor:focus{text-decoration:underline}.esri-widget__anchor--disabled{opacity:.4;pointer-events:none}.esri-widget__header{background-color:var(--calcite-color-foreground-1);flex:1 0 100%;justify-content:space-between;align-items:center;width:100%;min-height:48px;padding:12px 0 12px 15px;display:flex}.esri-widget__heading{word-break:break-word}.esri-widget__header .esri-widget__heading{width:calc(100% - 48px);text-align:initial;color:var(--calcite-color-text-1);align-items:center;margin:0;padding:0;display:flex}.esri-widget__header-button{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);border:none;flex:0 0 48px;justify-content:center;align-self:stretch;align-items:center;width:48px;padding:0;display:flex}.esri-widget__footer{background-color:var(--calcite-color-foreground-1);justify-content:center;align-items:center;width:100%;min-height:48px;display:flex}.esri-widget__footer-pagination{color:var(--calcite-color-text-2);justify-content:space-between;align-items:center;display:flex}.esri-widget__footer-pagination-previous-button,.esri-widget__footer-pagination-next-button{cursor:pointer;background-color:var(--calcite-color-foreground-1);border:0;margin:0 7px;padding:12px 15px;transition:background-color .125s ease-in-out}.esri-widget__footer-pagination-previous-button:hover,.esri-widget__footer-pagination-previous-button:focus,.esri-widget__footer-pagination-next-button:hover,.esri-widget__footer-pagination-next-button:focus{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1)}.esri-menu{visibility:hidden;z-index:1;background-clip:padding;background-color:var(--calcite-color-foreground-1);background-clip:padding-box;width:100%;max-height:0;margin:2px 0 0;padding:0;font-size:var(--calcite-font-size);line-height:var(--calcite-spacing-xl);position:absolute;top:100%;left:0;overflow:hidden;box-shadow:0 1px 2px #0000004d}.esri-menu .esri-menu__header{color:var(--calcite-color-text-inverse);background-color:var(--calcite-color-inverse);padding:6px 12px}.esri-menu__list{margin:0;padding:0;list-style:none}.esri-menu__list-item{cursor:pointer;border-top:1px solid #adadad4d;border-left:3px solid #0000;padding:.8em 1em}.esri-menu__list-item [class^=esri-icon-],.esri-menu__list-item [class*=" esri-icon-"]{padding-right:2.8px}.esri-menu__list-item:first-child{border-top:none}.esri-menu__list-item--focus,.esri-menu__list-item:hover,.esri-menu__list-item:focus{background-color:var(--calcite-color-foreground-1)}.esri-menu__list-item:active{background-color:var(--calcite-color-foreground-current)}.esri-menu__list-item--active,.esri-menu__list-item--active:hover,.esri-menu__list-item--active:focus{background-color:var(--calcite-color-foreground-1);border-left-color:var(--calcite-color-brand)}.esri-widget__table{border-collapse:collapse;color:var(--calcite-color-text-1);border:none;width:100%;line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget__table tr:nth-child(odd){background-color:var(--calcite-color-transparent)}.esri-widget__table tr:nth-child(2n){background-color:var(--calcite-color-transparent-press)}.esri-widget__table tr a{color:var(--calcite-color-text-2)}.esri-widget__table tr a:hover,.esri-widget__table tr a:focus{color:var(--calcite-color-text-1)}.esri-widget__table tr td,.esri-widget__table tr th{vertical-align:top;word-break:break-word;padding:.5em .7em;font-size:var(--calcite-font-size-sm);font-weight:var(--calcite-font-weight-regular)}.esri-widget__table tr th{text-align:left;border-right:3px solid #0000000d;width:50%}.esri-widget__table tr td{width:50%}.esri-input{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1);border:1px solid #959595;font-size:var(--calcite-font-size)}.esri-input::-ms-clear{display:none}.esri-input::placeholder{opacity:1;color:var(--calcite-color-text-2)}.esri-input:placeholder-shown{text-overflow:ellipsis}.esri-input[type=text],.esri-input[type=password],.esri-input[type=number]{height:32px;padding:0 .5em}calcite-combobox.esri-input{border:none}.esri-widget__content--empty{text-align:center;color:var(--calcite-color-border-input);flex-flow:column wrap;align-items:center;padding:18px 22px;display:flex}.esri-widget__content--empty h1.esri-widget__heading,.esri-widget__content--empty h2.esri-widget__heading,.esri-widget__content--empty h3.esri-widget__heading,.esri-widget__content--empty h4.esri-widget__heading,.esri-widget__content--empty h5.esri-widget__heading{font-weight:var(--calcite-font-weight-regular)}.esri-widget__content-illustration--empty{width:128px;padding:1rem 0}.esri-widget__content-icon--empty{width:32px;padding:.5rem 0}.esri-select{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background:var(--calcite-color-foreground-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-8 -8 32 32' width='32' height='32'%3E%3Cpath d='M8 11.207l-4-4V5.793l4 4 4-4v1.414z' fill='%23adadad' fillrule='nonzero'/%3E%3C/svg%3E") 100% no-repeat;border:1px solid #959595;border-radius:0;width:100%;height:32px;margin:0;padding:0 .5em;font-family:inherit;font-size:.85em;display:block}.esri-select[disabled]{cursor:auto}.esri-select::-ms-expand{display:none}.esri-disabled a,.esri-disabled [role=menu],.esri-disabled [role=checkbox],.esri-disabled [class^=esri-icon-],.esri-disabled [class*=" esri-icon-"]{color:var(--calcite-color-text-3)}.keynav-mode .esri-widget:focus,.keynav-mode .esri-widget :focus{z-index:1;outline-offset:2px;outline:2px solid #adadad}.esri-widget__loader-animation{border:.15em solid #adadad4d;border-top-color:var(--calcite-color-border-input);border-radius:100%;width:1em;height:1em;font-size:var(--calcite-font-size-md);animation:1.25s linear infinite esri-rotate;display:block;transform:translateZ(0)}:dir(rtl) .esri-widget__table th{text-align:right;border-left:3px solid #0000000d;border-right:none}:dir(rtl) .esri-select{background-position:0}:dir(rtl) .esri-menu__list-item{border-left:none;border-right:3px solid #0000}:dir(rtl) .esri-menu__list-item [class^=esri-icon-],:dir(rtl) .esri-menu__list-item [class*=" esri-icon-"]{padding-left:2px;padding-right:0}:dir(rtl) .esri-menu__list-item--active{border-right-color:var(--calcite-color-brand)}.esri-icon-font-fallback-text{clip:rect(0 0 0 0);width:1px;height:1px;position:absolute;overflow:hidden}.esri-rotating{animation:1.25s linear infinite esri-rotate;transform:translateZ(0)}.esri-clearfix:before,.esri-clearfix:after{content:" ";display:table}.esri-clearfix:after{clear:both}.esri-interactive{cursor:pointer}.esri-invisible{visibility:hidden!important}.esri-offscreen{position:absolute;top:-999em;left:-999em}.esri-match-height{flex-direction:column;flex:auto;display:flex;overflow:hidden}.esri-hidden{display:none!important}:host{width:240px}.root{--arcgis-internal-search-width: 240px;display:flex;flex-flow:row nowrap;align-items:center;justify-content:center;width:100%}.dropdown{--calcite-color-border-1: var(--calcite-color-border-input);--calcite-dropdown-width: var(--arcgis-internal-search-width);width:31px}.dropdown calcite-button{--calcite-offset-invert-focus: 1}.autocomplete{flex:1}.container{display:flex;position:relative;flex:1 0 100%;flex-flow:row nowrap;align-items:stretch}.form{display:flex;flex:1 0;flex-flow:row nowrap;align-items:stretch;margin:0;padding:0}.submit-button{position:absolute;margin:-1px;border-width:0;padding:0;width:1px;height:1px;overflow:hidden;white-space:nowrap;clip:rect(0,0,0,0)}`, L = R(w);
function g(a) {
return typeof a == "object" && a !== null && "openPopup" in a && "closePopup" in a;
}
class z extends f {
constructor() {
super(...arguments), this.viewModel = L(this), this._currentLocationValue = "search-use-current-location", this._autocompleteEl = void 0, this._searchResultRendererEl = void 0, this._searchResultRendererContentEl = void 0, this._suggestController = void 0, this._searchController = void 0, this._lastSearchTerm = "", this._handleSelectResult = (e) => {
const { name: t } = e.detail.result;
this._selectedMessage = h(this.messages.resultSelected, { resultName: t });
}, this.messages = E({ blocking: !0 }), this._locateFailed = !1, this._showNoResults = !1, this.view = this.viewModel.view, this.goToOverride = this.viewModel.goToOverride, this.icon = "search", this.activeMenu = "none", this.activeSourceIndex = this.viewModel.activeSourceIndex, this.allPlaceholder = this.viewModel.allPlaceholder, this.allSources = this.viewModel.allSources, this.autoNavigateDisabled = this.viewModel.autoNavigate, this.autoSelectDisabled = this.viewModel.autoSelect, this.defaultSources = this.viewModel.defaultSources, this.disabled = !1, this.includeDefaultSourcesDisabled = this.viewModel.includeDefaultSources, this.locationDisabled = this.viewModel.locationEnabled, this.maxResults = this.viewModel.maxResults, this.maxSuggestions = this.viewModel.maxSuggestions, this.minSuggestCharacters = this.viewModel.minSuggestCharacters, this.popupDisabled = this.viewModel.popupEnabled, this.popupTemplate = this.viewModel.popupTemplate, this.portal = this.viewModel.portal, this.resultGraphic = this.viewModel.resultGraphic, this.resultGraphicDisabled = this.viewModel.resultGraphicEnabled, this.results = this.viewModel.results, this.searchAllDisabled = this.viewModel.searchAllEnabled, this.searchTerm = this.viewModel.searchTerm, this.selectedResult = this.viewModel.selectedResult, this.sources = this.viewModel.sources, this.suggestions = this.viewModel.suggestions, this.suggestionsDisabled = this.viewModel.suggestionsEnabled, this.topLayerDisabled = !1, this.autoDestroyDisabled = !1, this.state = this.viewModel.state, this.arcgisPropertyChange = D()("state"), this.arcgisReady = b(), this.arcgisSearchClear = l(() => this.viewModel, "search-clear"), this.arcgisSearchComplete = l(() => this.viewModel, "search-complete"), this.arcgisSearchStart = l(() => this.viewModel, "search-start"), this.arcgisSelectResult = l(() => this.viewModel, "select-result"), this.arcgisSuggestComplete = l(() => this.viewModel, "suggest-complete"), this.arcgisSuggestStart = l(() => this.viewModel, "suggest-start");
}
static {
this.properties = { _selectedMessage: 16, messages: 16, _locateFailed: 16, _showNoResults: 16, _isDisabled: 16, _showCurrentLocation: 16, _effectiveActiveMenu: 16, view: 0, referenceElement: 1, goToOverride: 0, icon: 1, activeMenu: 1, activeSource: 32, activeSourceIndex: 9, allPlaceholder: 1, allSources: 0, autoNavigateDisabled: 5, autoSelectDisabled: 5, defaultSources: 0, disabled: 5, includeDefaultSourcesDisabled: 5, locationDisabled: 5, maxResults: 9, maxSuggestions: 9, minSuggestCharacters: 9, popupDisabled: 5, popupTemplate: 0, portal: 0, resultGraphic: 0, resultGraphicDisabled: 5, results: 0, searchAllDisabled: 5, searchTerm: 1, selectedResult: 0, sources: 0, suggestions: 32, suggestionsDisabled: 5, topLayerDisabled: 5, autoDestroyDisabled: 5, messageOverrides: 0, label: 1, state: 32 };
}
static {
this.styles = [A, k];
}
get _isDisabled() {
const { state: e } = this.viewModel;
return e === "disabled" || e === "loading" || this.disabled;
}
get _showCurrentLocation() {
return !this.locationDisabled && !this.searchTerm?.trim();
}
get _effectiveActiveMenu() {
return this._isDisabled ? "none" : this.activeMenu;
}
get activeSource() {
return this.viewModel?.activeSource;
}
clear() {
this._locateFailed = !1, this._selectedMessage = void 0, this.viewModel.clear();
}
async destroy() {
this._closePopup(this.viewModel.resultGraphic), this._cancelQueries(), await this._searchResultRendererEl?.destroy(), await this._searchResultRendererContentEl?.destroy(), await this.manager.destroy();
}
async search(e) {
this._cancelQueries();
const t = new AbortController(), { signal: i } = t;
this._searchController = t;
try {
const r = await this.viewModel.search(e, { signal: i });
return this._searchController !== t ? void 0 : (r?.numResults || (this._showNoResults = !0, this.activeMenu = "suggestion"), this._searchController = void 0, r);
} catch {
if (this._searchController !== t)
return;
this._searchController = void 0;
return;
}
}
async setFocus() {
await this._autocompleteEl?.setFocus();
}
async suggest(e) {
this._cancelSuggest();
const t = new AbortController(), { signal: i } = t;
this._suggestController = t;
try {
const r = await this.viewModel.suggest(e, null, { signal: i });
return this._suggestController !== t ? void 0 : (this._suggestController = void 0, r?.numResults && (this.activeMenu = "suggestion", this._scrollToTopSuggestion()), r);
} catch {
return this._suggestController !== t || (this._suggestController = void 0), null;
}
}
loaded() {
this.listen("arcgisSelectResult", this._handleSelectResult), this.manager.onLifecycle(() => [
d(() => [this._searchResultRendererEl, this.viewModel?.defaultPopupTemplate], () => {
const e = this.viewModel?.defaultPopupTemplate, { _searchResultRendererEl: t } = this;
if (e && t) {
const i = document.createElement("div");
i.appendChild(t), e.content = i, this._searchResultRendererContentEl = t;
}
}, { initial: !0 }),
d(() => this.messages, (e) => this.viewModel.messages = e, { initial: !0 }),
d(() => this.viewModel?.resultGraphic, (e, t) => this._closePopup(t)),
T(() => this.viewModel, "select-result", (e) => {
const { popupEnabled: t } = e;
t && this._openPopup();
})
]);
}
_addSearchResultRenderer() {
this._searchResultRendererEl = x(s`<arcgis-search-result-renderer auto-destroy-disabled .messages=${this.messages} .viewModel=${this.viewModel}></arcgis-search-result-renderer>`);
}
_closePopup(e) {
const { referenceElement: t, view: i } = this;
g(t) && t.popupElement?.selectedFeature === e ? t?.closePopup() : i?.popup?.selectedFeature === e && i?.closePopup();
}
_openPopup() {
if (g(this.referenceElement)) {
const { resultGraphic: e, resultLocation: t } = this.viewModel, i = { features: e ? [e] : [], location: t };
this.referenceElement?.openPopup(i);
} else if (this.view) {
const { resultGraphic: e, resultLocation: t } = this.viewModel;
this.view.openPopup({
features: e ? [e] : [],
location: t
});
}
}
_handleInputKeydown(e) {
e.key === "Tab" && this._cancelSuggest();
}
_handleAutocompleteCreate(e) {
this._autocompleteEl = e;
}
_handleCalciteAutocompleteTextInput(e) {
const i = e.target.inputValue;
i !== this.viewModel.searchTerm && (this.viewModel.searchTerm = i, i || this.clear(), this.suggest());
}
_handleAutocompleteOpen() {
this.activeMenu = "suggestion";
}
_handleAutocompleteClose() {
this.activeMenu === "suggestion" && (this.activeMenu = "none");
}
_handleCalciteAutocompleteChange(e) {
const t = e.target.value;
if (t === this._currentLocationValue) {
this._useCurrentLocation();
return;
}
const i = JSON.parse(t), r = this.viewModel.suggestions?.find(({ sourceIndex: o }) => o === i.sourceIndex)?.results?.find(({ key: o }) => `${o}` == `${i.key}`);
r && this.search(r);
}
async _useCurrentLocation() {
this._cancelQueries();
const e = new AbortController(), { signal: t } = e;
this._searchController = e;
try {
await this.viewModel.searchNearby({ signal: t });
} catch (i) {
$(i) || (this._locateFailed = !0, this.activeMenu = "suggestion");
} finally {
this._searchController = void 0;
}
}
_handleSourceOpen() {
this.activeMenu = "source";
}
_handleSourceClose() {
this.activeMenu === "source" && (this.activeMenu = "none");
}
_handleSourceSelect(e) {
const r = e.target.selectedItems[0].getAttribute("data-source-index");
r && (this.viewModel.activeSourceIndex = Number.parseInt(r, 10));
}
_cancelSuggest() {
this.activeMenu = "none", this._locateFailed = !1, this._showNoResults = !1, this._suggestController = u(this._suggestController);
}
_cancelQueries() {
this._cancelSuggest(), this._searchController = u(this._searchController);
}
_scrollToTopSuggestion() {
this._autocompleteEl?.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: i } = this.viewModel, r = i.at(e);
return (e === -1 ? t.all : r?.name || t.untitledSource) || "";
}
render() {
return this._addSearchResultRenderer(), s`<div class=${M(y("root", C.widget))}><div class="sr-only" aria-live=polite>${this._selectedMessage}</div><div class="container">${this._renderSourcesMenu()}${this._renderForm()}</div></div>`;
}
_renderSourcesMenu() {
const { messages: e, _isDisabled: t, _effectiveActiveMenu: i } = this, { allSources: r, searchAllEnabled: o } = this.viewModel;
return r.length > 1 ? s`<calcite-dropdown class="dropdown" .disabled=${t} .open=${i === "source"} overlay-positioning=fixed .topLayerDisabled=${this.topLayerDisabled} =${this._handleSourceClose} =${this._handleSourceOpen} =${this._handleSourceSelect}><calcite-button appearance=outline-fill icon-start=caret-down kind=neutral .label=${e.searchIn} slot=trigger></calcite-button><calcite-dropdown-group .groupTitle=${e.searchIn}>${o ? this._renderSource(-1) : null}${r.map((n, c) => this._renderSource(c)).toArray()}</calcite-dropdown-group></calcite-dropdown>` : null;
}
_renderUseCurrentLocation() {
const { _currentLocationValue: e } = this;
return s`<calcite-autocomplete-item .heading=${this.messages.useCurrentLocation ?? ""} icon-start=gps-on .value=${e}></calcite-autocomplete-item>`;
}
_renderAutocomplete() {
const { _effectiveActiveMenu: e, messages: t, _isDisabled: i } = this, { maxInputLength: r, placeholder: o, searchTerm: n, state: c } = this.viewModel, p = this.label ?? t.searchButtonTitle ?? "";
return s`<calcite-autocomplete autocomplete=off class="autocomplete" .disabled=${i} .icon=${this.icon || void 0} .inputValue=${n} .label=${p} .loading=${c === "searching"} .maxLength=${r} .name=${this.el.id} =${this._handleInputKeydown} .open=${e === "suggestion"} overlay-positioning=fixed .placeholder=${o} .topLayerDisabled=${this.topLayerDisabled} title=${(n ? "" : o) ?? S} =${this._handleCalciteAutocompleteChange} =${this._handleAutocompleteClose} =${this._handleAutocompleteOpen} =${this._handleCalciteAutocompleteTextInput} =${this._handleCalciteAutocompleteTextInput} ${v(this._handleAutocompleteCreate)}>${this._renderSuggestions()}${this._renderNotices()}</calcite-autocomplete>`;
}
_renderForm() {
return s`<form class="form" =${this._formSubmit} role=search>${this._renderAutocomplete()}<button class="submit-button" type=submit>${this.label ?? this.messages.searchButtonTitle ?? ""}</button></form>`;
}
_renderSuggestGroup(e) {
return e.results?.map((t) => this._renderSuggestion(t));
}
_renderSuggestions() {
const { suggestions: e } = this.viewModel;
return this._showNoResults ? null : this._showCurrentLocation ? this._renderUseCurrentLocation() : e?.map((t) => this._renderSuggestResults(t));
}
_renderSuggestResults(e) {
const { allSources: t, activeSourceIndex: i } = this.viewModel, { sourceIndex: r } = e, o = e.results?.length, n = t.length > 1 && i === -1, c = this._getSourceName(r);
return o && n ? s`<calcite-autocomplete-item-group .heading=${c}>${this._renderSuggestGroup(e)}</calcite-autocomplete-item-group>` : this._renderSuggestGroup(e);
}
_renderSuggestion(e) {
const { key: t, sourceIndex: i, text: r } = e, o = {
key: t,
sourceIndex: i
};
return s`<calcite-autocomplete-item .heading=${r ?? this.messages.untitledResult ?? ""} .value=${JSON.stringify(o)} .selected=${e === this.viewModel.selectedSuggestion}></calcite-autocomplete-item>`;
}
_renderSource(e) {
const t = this._getSourceName(e);
return s`<calcite-dropdown-item data-source-index=${`${e}`} .selected=${e === this.viewModel.activeSourceIndex}>${t}</calcite-dropdown-item>`;
}
_renderNoResultsWarning(e) {
const { messages: t } = this, i = e ? h(t.noResultsFoundForValue ?? "", {
value: `"${e}"`
}) : t.noResultsFound;
return s`<calcite-notice icon=exclamation-mark-triangle kind=warning open slot=content-bottom><div slot=title>${t.noResults}</div><div slot=message>${i}</div></calcite-notice>`;
}
_renderLocateError() {
return s`<calcite-notice icon=exclamation-mark-circle kind=danger open slot=content-bottom><div slot=message>${this.messages.locateError}</div></calcite-notice>`;
}
_renderNotices() {
return this._locateFailed ? this._renderLocateError() : this._showNoResults ? this._renderNoResultsWarning(this._lastSearchTerm ?? this.viewModel.searchTerm) : null;
}
}
m("arcgis-search", z);
export {
z as ArcgisSearch
};