UNPKG

@arcgis/map-components

Version:
232 lines (231 loc) • 12.3 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */ import { c as b } from "../../chunks/runtime.js"; import { css as y, html as r } from "lit"; import { on as _, when as d, watch as w } from "@arcgis/core/core/reactiveUtils.js"; import { g as $ } from "../../chunks/globalCss.js"; import { u as E } from "../../chunks/useT9n.js"; import { createRef as g, ref as h } from "lit/directives/ref.js"; import C from "@arcgis/core/core/Accessor.js"; import { property as p, subclass as D } from "@arcgis/core/core/accessorSupport/decorators.js"; import { usePropertyChange as T } from "@arcgis/lumina/controllers"; import { m as I } from "../../chunks/useViewModel.js"; import { LitElement as k, createEvent as H, safeClassMap as u, nothing as M } from "@arcgis/lumina"; import { classes as m } from "@arcgis/toolkit/dom"; var P = Object.defineProperty, O = Object.getOwnPropertyDescriptor, c = (i, e, t, a) => { for (var s = a > 1 ? void 0 : a ? O(e, t) : e, n = i.length - 1, l; n >= 0; n--) (l = i[n]) && (s = (a ? l(e, t, s) : l(s)) || s); return a && s && P(e, t, s), s; }; const v = new EventTarget(); function L(i, e, t) { let a = !1; const s = w( i, (n, l) => { a || e(n, l); }, t ); return { remove() { s.remove(); }, pause() { a = !0; }, resume() { a = !1; } }; } let o = class extends C { //#region Lifecycle constructor(i) { super(i), this._viewpointHandle = null, this.addHandles( _( () => v, "expand", (e) => { const { target: t } = e.detail; t !== this && t.expanded && t.group && t.group === this.group && this.expanded && this._collapse(); } ) ); } destroy() { this._viewpointHandle = null, this.view = null; } set autoCollapse(i) { this._set("autoCollapse", i), this._watchViewpoint(); } set expanded(i) { this._set("expanded", i), this.group && i && v.dispatchEvent(new CustomEvent("expand", { detail: { target: this } })), this._viewpointHandleChange(i); } get state() { return this.view?.ready ? "ready" : "disabled"; } set view(i) { this._get("view") !== i && (this._set("view", i), i && d( () => i.ready, () => { this.view === i && this._watchViewpoint(); }, { once: !0, initial: !0 } )); } //#endregion //#region Private Methods _viewpointHandleChange(i) { this._viewpointHandle && (i ? d( () => this.view?.stationary, () => this._viewpointHandle?.resume(), { once: !0, initial: !0 } ) : this._viewpointHandle.pause()); } _watchViewpoint() { const i = "viewpoint"; this.removeHandles(i), this._viewpointHandle = null; const { autoCollapse: e, view: t } = this; if (!t || !e) return; const a = L( () => t.type === "3d" ? t.camera : t.viewpoint, () => this._collapse() ); this.addHandles(a, i), this._viewpointHandle = a; } _collapse() { this.expanded = !1; } //#endregion }; c([ p({ value: !1 }) ], o.prototype, "autoCollapse", 1); c([ p({ value: !1 }) ], o.prototype, "expanded", 1); c([ p() ], o.prototype, "group", 2); c([ p({ readOnly: !0 }) ], o.prototype, "state", 1); c([ p({ value: null }) ], o.prototype, "view", 1); o = c([ D("map-components.expand.ExpandViewModel") ], o); const S = y`:host{display:flex;pointer-events:auto;--arcgis-internal-expand-icon-number-spacing-left: none;--arcgis-internal-expand-icon-number-spacing-right: none}arcgis-expand>.content-expanded{background-color:var(--calcite-color-background)}.root{--esri-widget-panel-max-height: 95svh;--calcite-sheet-max-height: var(--esri-widget-panel-max-height);--calcite-sheet-height: auto;--calcite-action-corner-radius: 0}.action{cursor:pointer;text-align:center;color:var(--calcite-color-text-2);justify-content:center;align-items:center;margin:0;padding:0;font-size:var(--calcite-font-size);transition:background-color .125s ease-in-out;display:flex;flex-direction:column;overflow:hidden}.toggle{position:relative}.popover-content{flex-direction:column;display:flex;max-height:var(--arcgis-internal-expand-max-height, 95svh);::slotted(*){max-height:var(--arcgis-internal-expand-max-height, 95svh);overflow-y:auto}::slotted(arcgis-sketch){--arcgis-internal-sketch-gap: var(--calcite-spacing-none)}::slotted(:is(arcgis-area-measurement-2d,arcgis-area-measurement-3d,arcgis-basemap-gallery,arcgis-basemap-layer-list,arcgis-bookmarks,arcgis-building-explorer,arcgis-catalog-layer-list,arcgis-directions,arcgis-direct-line-measurement-3d,arcgis-distance-measurement-2d,arcgis-editor,arcgis-feature-form,arcgis-features,arcgis-layer-list,arcgis-layer-list-next,arcgis-legend,arcgis-line-of-sight,arcgis-print,arcgis-shadow-cast,arcgis-slice,arcgis-table-list,arcgis-utility-network-trace,arcgis-grid-controls)){width:var(--arcgis-internal-panel-width);min-width:var(--calcite-spacing-xxxl);min-height:var(--calcite-spacing-xxxl);transition:max-height .25s ease-in-out}}.popover-content .esri-widget--panel{width:300px}.panel{max-height:var(--esri-widget-panel-max-height)}.panel-content{::slotted(*){width:100%}::slotted(:is(arcgis-area-measurement-2d,arcgis-area-measurement-3d,arcgis-basemap-gallery,arcgis-basemap-layer-list,arcgis-bookmarks,arcgis-building-explorer,arcgis-catalog-layer-list,arcgis-directions,arcgis-direct-line-measurement-3d,arcgis-distance-measurement-2d,arcgis-editor,arcgis-feature-form,arcgis-features,arcgis-layer-list,arcgis-layer-list-next,arcgis-legend,arcgis-line-of-sight,arcgis-print,arcgis-shadow-cast,arcgis-slice,arcgis-table-list,arcgis-utility-network-trace,arcgis-grid-controls)){overflow-y:auto}}.panel-content .esri-widget{width:auto}.panel-content .esri-widget--panel{flex:auto}.arcgis-map-container-ui__element .popover-content .esri-widget,.arcgis-map-container-ui__element .popover-content .esri-widget.esri-component,.arcgis-map-container-ui__element .panel-content .esri-widget,.arcgis-map-container-ui__element .panel-content .esri-widget.esri-component,.popover-content .esri-widget,.popover-content .esri-widget.esri-component,.panel-content .esri-widget,.panel-content .esri-widget.esri-component{box-sizing:border-box;box-shadow:none;margin-bottom:0}.panel-content,.content-container{background-color:var(--calcite-color-foreground-1);flex-direction:column;flex:auto;justify-content:stretch;display:flex}.sheet .panel-content,.sheet .content-container{overflow:hidden}.panel-icon-number{align-self:center}.icon{display:flex}calcite-button:not(:hover) .icon:not(calcite-icon){color:var(--calcite-color-text-3)}.icon-flip{transform:var(--arcgis-internal-collapse-icon-flip)}.icon-number{transform-origin:50%;color:var(--calcite-color-text-inverse);pointer-events:none;background-color:var(--calcite-color-text-3);border-radius:var(--calcite-spacing-xl);justify-content:center;align-items:center;height:var(--calcite-spacing-lg);padding:.125em .333em;font-size:var(--calcite-font-size-sm);line-height:1em;display:flex;position:absolute;top:-6px;left:var(--arcgis-internal-expand-icon-number-spacing-left);right:var(--arcgis-internal-expand-icon-number-spacing-right)}`, f = "chevrons-left", x = "chevrons-right", V = I(o); class z extends k { constructor() { super(...arguments), this.popoverEl = g(), this.messages = E({}), this.viewModel = V(this), this.toggleActionEl = g(), this.view = this.viewModel.view, this.state = this.viewModel.state, this.autoDestroyDisabled = !1, this.autoCollapse = this.viewModel.autoCollapse, this.closeOnEscDisabled = !1, this.content = "", this.expanded = this.viewModel.expanded, this.expandTooltip = "", this.collapseTooltip = "", this.focusTrapDisabled = !1, this.group = this.viewModel.group, this.iconNumber = 0, this.mode = "auto", this.topLayerDisabled = !1, this.visualScale = "m", this.arcgisPropertyChange = T()("expanded"), this.arcgisReady = H(); } static { this.properties = { expandTitle: 16, _displaySheet: 16, view: 0, state: 32, icon: 1, label: 1, autoDestroyDisabled: 5, referenceElement: 1, autoCollapse: 5, closeOnEscDisabled: 5, content: 1, expanded: 7, expandIcon: 3, expandTooltip: 1, collapseIcon: 3, collapseTooltip: 1, focusTrapDisabled: 5, group: 1, iconNumber: 9, mode: 1, placement: 1, messageOverrides: 0, topLayerDisabled: 5, visualScale: 1 }; } static { this.styles = S; } get expandTitle() { const { expanded: e, messages: t, collapseTooltip: a, expandTooltip: s } = this; return (e ? a || t.collapse : s || t.expand) ?? ""; } get _displaySheet() { switch (this.mode) { case "drawer": return !0; case "auto": return this.viewModel.view?.widthBreakpoint === "xsmall"; default: return !1; } } get expandIcon() { if (this._expandIcon) return this._expandIcon; let e = null; return this.content instanceof HTMLElement && ("widget" in this.content && this.content.widget?.icon ? e = this.content.widget.icon : "icon" in this.content ? e = this.content.icon : e = this.content.getAttribute("icon")), e ?? f; } set expandIcon(e) { this._expandIcon = e; } get collapseIcon() { return this._collapseIcon ?? x; } set collapseIcon(e) { this._collapseIcon = e; } async collapse() { this.expanded = !1; } async destroy() { await this.manager.destroy(); } async expand() { this.expanded = !0; } loaded() { this.manager.onLifecycle(() => [ w(() => this.viewModel?.view?.size, () => { this.popoverEl?.value?.reposition(); }, { initial: !0 }) ]); } toggle() { this.expanded = !this.expanded; } getPopoverPlacement() { if (this.placement) return this.placement; switch (this.el.slot) { case "bottom-start": case "bottom-left": return "right-end"; case "bottom-right": case "bottom-end": return "left-end"; case "top-start": case "top-left": return "right-start"; case "top-right": case "top-end": return "left-start"; default: return "auto"; } } _isCloseOnEscapeDisabled(e) { const { closeOnEscDisabled: t } = this; return typeof t == "function" ? t(e) : t; } _handlePopoverClose(e) { e.target === this.popoverEl.value && this.collapse(); } _handleKeyDown(e) { this.expanded && e.key === "Escape" && this._isCloseOnEscapeDisabled(e) && e.preventDefault(); } render() { const { _displaySheet: e, toggleActionEl: t, expanded: a, label: s, topLayerDisabled: n } = this; return r`<div class=${u(m("root", $.widget))}>${this._renderToggle()}${e ? r`<calcite-sheet class="sheet" height=l .label=${s ?? ""} .topLayerDisabled=${n} @keydown=${this._handleKeyDown} .open=${a} position=block-end @calciteSheetClose=${this.collapse}><calcite-panel class="panel" closable .closed=${!a} .heading=${s} @keydown=${this._handleKeyDown} @calcitePanelClose=${this.collapse}><div class="panel-content">${this._renderContent()}</div></calcite-panel></calcite-sheet>` : t.value ? r`<calcite-popover .focusTrapDisabled=${this.focusTrapDisabled} .label=${s ?? ""} @keydown=${this._handleKeyDown} trigger-disabled .open=${a} overlay-positioning=fixed .placement=${this.getPopoverPlacement()} .referenceElement=${t.value} .topLayerDisabled=${n} @calcitePopoverClose=${this._handlePopoverClose} ${h(this.popoverEl)}><div class="popover-content">${this._renderContent()}</div></calcite-popover>` : null}</div>`; } _renderBadgeNumber() { const { expanded: e, iconNumber: t } = this; return t && !e ? r`<span class="icon-number">${t}</span>` : null; } _renderToggleButton() { const { expanded: e, expandTitle: t, expandIcon: a, collapseIcon: s } = this, n = e ? s : a; return r`<calcite-action class=${u(m("action", "icon", { "icon-flip": n === f || n === x }))} @click=${this.toggle} .text=${t} title=${t ?? M} .icon=${n} .scale=${this.visualScale} appearance=solid ${h(this.toggleActionEl)}></calcite-action>`; } _renderToggle() { return r`<div class="toggle">${this._renderToggleButton()}${this._renderBadgeNumber()}</div>`; } _renderContent() { return r`<div class="content-container"><slot></slot></div>`; } } b("arcgis-expand", z); export { z as ArcgisExpand };