UNPKG

@arcgis/map-components

Version:
105 lines (104 loc) 5.69 kB
import { c as k } from "../../chunks/runtime.js"; import { html as a } from "lit-html"; import { hasSameOrigin as f } from "@arcgis/components-utils"; import { watch as g, whenOnce as v } from "@arcgis/core/core/reactiveUtils.js"; import { LitElement as $, noShadowRoot as b, nothing as u, safeClassMap as c } from "@arcgis/lumina"; import { css as w } from "@lit/reactive-element/css-tag.js"; /*! All material copyright Esri, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. v4.33.13 */ const x = w`@layer{.arcgis-print__exported-file{display:flex;align-items:center;justify-content:space-between}.arcgis-print__exported-file-link-title,.arcgis-print__exported-file-link-description{word-wrap:break-word;word-break:break-all;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;line-clamp:2;-webkit-box-orient:vertical}}`, d = "arcgis-print", m = { exportedFile: `${d}__exported-file`, exportedFileLinkTitle: `${d}__exported-file-link-title`, exportedFileLinkDescription: `${d}__exported-file-link-description` }; function _(l) { const { state: e, extension: t } = l; switch (e) { case "pending": return "spinner"; case "error": return "exclamation-mark-circle"; default: return t?.toLowerCase()?.includes("pdf") ? "file-pdf" : "file"; } } function h(l, e) { return !l || l === "all" || !!(e && l.includes(e)); } class I extends $ { constructor() { super(...arguments), this._handleLinkClick = (e) => { if (!e || e.state !== "ready" || !e.url) return; const t = e.url, i = document.createElement("a"); i.target = "_blank", i.href = t, i.rel = "noreferrer", i.download = e.formattedName ?? ""; { i.click(); return; } }; } static { this.properties = { saveAsButtonCallback: 0, allowedFormatsForSaving: 1, exportedLink: 0, viewModel: 0, messages: 0 }; } static { this.styles = x; } static { this.shadowRootOptions = b; } loaded() { this.manager.onLifecycle(() => [ g(() => this.exportedLink.state, () => this.requestUpdate()) ]); } render() { const { messages: e, exportedLink: t } = this, { error: i, state: n } = t; let s; switch (n) { case "pending": s = e.pending; break; case "ready": s = e.ready; break; case "error": s = e.errorMessage; break; } const r = n === "error" ? i?.name === "print-task:cim-symbol-unsupported" ? e.exportWebMapCIMError : e.exportWebMapError : ""; return a`<calcite-list-item .ariaLabel=${s} title=${r ?? u}>${this._renderExportedLinkItemContent(t, r)}${this._renderExportedLinkItemIcon(t)}${this._renderExportedLinkItemAction(t, r)}</calcite-list-item>${this._renderExportedLinkItemPopover(t)}`; } _renderExportedLinkItemPopover(e) { const t = this.messages, i = e.formattedName ?? "", { state: n } = e, s = this.saveAsButtonCallback && n !== "error" && h(this.allowedFormatsForSaving, e.extension); return n !== "pending" && s ? a`<calcite-popover auto-close label=Popover offset-distance=1 overlay-positioning=fixed pointer-disabled .referenceElement=${`${i}-popover-button`} scale=s><calcite-list label>${e.portalItem ? a`<calcite-list-item .label=${t.openItem} @calciteListItemSelect=${() => { const r = e.portalItem; if (!r?.itemPageUrl) return; const o = document.createElement("a"); o.target = "_blank", o.href = r.itemPageUrl, o.rel = "noreferrer", o.click(); }}><calcite-icon icon=launch2 scale=s slot=content-start></calcite-icon></calcite-list-item>` : a`<calcite-list-item .label=${t.saveAs} @calciteListItemSelect=${async () => { this.saveAsButtonCallback && (v(() => e.portalItem).then((r) => { r.itemPageUrl && this.requestUpdate(); }), await this.saveAsButtonCallback(e)); }}><calcite-icon icon=save scale=s slot=content-start></calcite-icon></calcite-list-item>`}<calcite-list-item label=Delete @calciteListItemSelect=${() => this.viewModel.exportedLinks.remove(e)}><calcite-icon icon=trash scale=s slot=content-start></calcite-icon></calcite-list-item></calcite-list></calcite-popover>` : null; } _renderExportedLinkItemContent(e, t) { const i = this.messages, { url: n, state: s } = e, r = e.formattedName ?? "", p = f(n || null, document.location.href); return a`<div class=${c(m.exportedFile)} slot=content @click=${() => this._handleLinkClick(e)}><div><div class=${c(m.exportedFileLinkTitle)}>${r}</div><div class=${c(m.exportedFileLinkDescription)}>${s === "pending" ? i.generatingExport : t || (p ? i.ready : i.linkReady)}</div></div>${s === "ready" ? a`<calcite-icon .ariaLabel=${`${r}. ${i.linkReady}`} .icon=${p ? "download-to" : "launch"} scale=s slot=content-end></calcite-icon>` : null}</div>`; } _renderExportedLinkItemIcon(e) { return e.state === "pending" ? a`<calcite-loader inline .label=${this.messages.generatingExport} scale=m slot=content-start></calcite-loader>` : a`<calcite-icon .icon=${_(e)} scale=s slot=content-start></calcite-icon>`; } _renderExportedLinkItemAction(e, t) { const { state: i } = e, n = e.formattedName ?? "", s = this.saveAsButtonCallback && i !== "error" && h(this.allowedFormatsForSaving, e.extension); return i !== "pending" ? a`<calcite-action .ariaLabel=${t} .icon=${s ? "ellipsis" : "x"} id=${(s ? `${n}-popover-button` : void 0) ?? u} @click=${s ? void 0 : () => { this.viewModel.exportedLinks.remove(e); }} slot=actions-end .text=${t}></calcite-action>` : null; } } k("arcgis-print-exported-link", I); export { I as PrintExportedLink };