@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 33.4 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{deprecateWidget as t}from"../core/deprecate.js";import{JSONMap as i}from"../core/jsonMap.js";import a from"../core/Logger.js";import{watch as l,on as o,whenOnce as s}from"../core/reactiveUtils.js";import{unitName as n}from"../core/unitFormatUtils.js";import{addProxy as r,hasSameOrigin as c}from"../core/urlUtils.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import{ensureInteger as d}from"../core/accessorSupport/ensureType.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as m}from"../core/accessorSupport/decorators/subclass.js";import u from"../geometry/SpatialReference.js";import{isValid as h}from"../geometry/support/spatialReferenceUtils.js";import{reArcGISOnlineDomain as b}from"../portal/support/urlUtils.js";import{findToken as _}from"../rest/utils.js";import{formatJsonMap as v}from"../rest/support/fileFormat.js";import g from"./Widget.js";import y from"./Print/PrintViewModel.js";import{loadCalciteComponents as f}from"./support/componentsUtils.js";import{globalCss as w}from"./support/globalCss.js";import{Heading as T}from"./support/Heading.js";import{legacyIcon as x}from"./support/legacyIcon.js";import{isRTL as k,isActivationKey as C}from"./support/widgetUtils.js";import{messageBundle as S}from"./support/decorators/messageBundle.js";import{tsx as I,tsxFragment as O}from"./support/jsxFactory.js";import{formatNumber as $}from"../intl/number.js";const E="map-only";var L;!function(e){e.layout="layoutTab",e.mapOnly="mapOnlyTab",e.export="exportTab"}(L||(L={}));const M="esri-print",F={base:M,headerTitle:`${M}__header-title`,layoutTabList:`${M}__layout-tab-list`,layoutTab:`${M}__layout-tab`,layoutSection:`${M}__layout-section`,mapOnlySection:`${M}__map-only-section`,panelItemsCentered:`${M}__panel-items--centered`,loader:`${M}__loader`,swapButton:`${M}__swap-button`,printButton:`${M}__export-button`,printButtonSection:`${M}__export-button-section`,printButtonSectionDivider:`${M}__export-button-section--divider`,templateSelectContainer:`${M}__template-select-container`,templateSelectIcon:`${M}__template-select-icon`,templateSelectError:`${M}__template-select-error`,templateSelectArrow:`${M}__template-select-arrow`,formSectionContainer:`${M}__form-section-container`,advancedOptionsSection:`${M}__advanced-options-section`,advancedOptionsContainer:`${M}__advanced-options-container`,browseTemplateButtonContainer:`${M}__browse-template-button-container`,browseTemplateButtonContainerFilter:`${M}__browse-template-button-container-filter`,exportedFilesContainer:`${M}__export-panel-container`,exportedFilesTitle:`${M}__export-title`,exportedFile:`${M}__exported-file`,exportedFileLinkTitle:`${M}__exported-file-link-title`,exportedFileLinkDescription:`${M}__exported-file-link-description`,exportedFilesEmpty:`${M}__exported-files-empty`,printWidgetContainer:`${M}__container`,content:`${M}__content`,panelContainer:`${M}__panel-container`,scaleInfoContainer:`${M}__scale-info-container`,scaleInputContainer:`${M}__scale-input-container`,scaleInput:`${M}__scale-input`,sizeContainer:`${M}__size-container`,panelError:`${M}__panel--error`,exportedFileLoader:`${M}__exported-file--loader`,exportSection:`${M}__export-section`,exportSectionCentered:`${M}__export-section--centered`,templateButtonContainer:`${M}__template-button-container`,templateDoneButton:`${M}__template-done-button`,templateSelectFlowItemContainer:`${M}__template-select-flow-item-container`,templateSelectFlowItemContent:`${M}__template-select-flow-item-content`,templateSelectFlowItemListHeading:`${M}__template-select-flow-item-list-heading`,srLabel:`${M}__sr-label`,invalidWkidText:`${M}__invalid-wkid-text`};function P(e){return!isNaN(e)&&e>0&&Number.isFinite(e)}function A(e){return e?.toLowerCase()===E}function R(e){const{state:t,extension:i}=e;switch(t){case"pending":return"spinner";case"error":return"exclamation-mark-circle";default:return i?.toLowerCase()?.includes("pdf")?"file-pdf":"file"}}const B=new i({inch:"inches",foot:"feet",yard:"yards",mile:"miles","nautical-mile":"nautical-miles",millimeter:"millimeters",centimeter:"centimeters",decimeter:"decimeters",meter:"meters",kilometer:"kilometers"}),N=new Map([["a3-landscape","a3-landscape"],["a3-portrait","a3-portrait"],["a4-landscape","a4-landscape"],["a4-portrait","a4-portrait"],["letter-ansi-a-landscape","ansi-a-landscape"],["letter-ansi-a-portrait","ansi-a-portrait"],["tabloid-ansi-b-landscape","ansi-b-landscape"],["tabloid-ansi-b-portrait","ansi-b-portrait"]]);let j=class extends g{constructor(e,i){super(e,i),this._activeTabFocusRequested=!1,this._awaitingServerResponse=!1,this._selectedTab=L.layout,this._pendingExportScroll=!1,this._rootNode=null,this._selectedTemplate=null,this._formats=[],this._showTemplates=!1,this._isValidSpatialReference=!0,this.allowedFormatsForSaving=null,this.browseTemplateButtonOnClick=null,this.headerVisible=!0,this.headingLevel=3,this.includeOrganizationTemplates=!0,this.messagesCommon=null,this.messagesUnits=null,this.saveExportHidden=!0,this.saveAsButtonCallback=null,this.viewModel=new y,this._onInput=e=>{this._selectedTab===L.layout?this.templateOptions.title=e.currentTarget.value:this._selectedTab===L.mapOnly&&(this.templateOptions.fileName=e.currentTarget.value)},this._handleLinkClick=e=>{const t=e.currentTarget["data-item"];if(!t||"ready"!==t.state||!t.url)return;const i=_(this.viewModel.effectivePrintServiceUrl),a=t.url,l=document.createElement("a");if(l.target="_blank",l.href=a,l.rel="noreferrer",l.download=t.formattedName??"",!i)return l.click(),void e.stopPropagation();e.preventDefault();const o=new URL(a);o.searchParams.set("token",i),l.href=o.href,l.click(),l.href=a},t(a.getLogger(this),"Print","arcgis-print",{version:"4.33"}),this._focusOnTabChange=this._focusOnTabChange.bind(this)}initialize(){this.addHandles([l((()=>[this.templateOptions.format,this.viewModel.templatesInfo?.format]),(()=>{const{templatesInfo:e}=this.viewModel;if(!e)return;if(this._formats.length!==e.format.choiceList.length){const t=v.apiValues;this._formats=e.format.choiceList.map((e=>{const i=t.find((t=>new RegExp(`\\b${t}\\b`,"i").test(e)))??e;return{value:i,label:e===i?e.toUpperCase():e}})).sort(((e,t)=>e.label.localeCompare(t.label)))}const t=this._formats.some((({value:e})=>new RegExp(`\\b${e}\\b`,"i").test(this.templateOptions.format)));if(!e.format.defaultValue||t);else{const t=this._formats.find((({value:t})=>new RegExp(`\\b${t}\\b`,"i").test(e.format.defaultValue)))?.value;t&&(this.templateOptions.format=t)}})),l((()=>[this.templateOptions.id,this.viewModel.loaded]),(async()=>{const{layout:e}=this.templateOptions;this._selectedTab=A(e)?L.mapOnly:L.layout,this._selectedTab===L.layout&&this.viewModel.loaded&&(this._selectedTemplate=this.viewModel.getLayoutTemplateById(this.templateOptions.id))})),l((()=>this.templateOptions.dpi),(e=>{e<=0&&(this.templateOptions.dpi=1)})),l((()=>this.viewModel.view?.scale),(e=>{!e||this.templateOptions.scaleEnabled&&this.templateOptions.scale||(this.templateOptions.scale=e)})),o((()=>this.viewModel),"submit",(e=>this.emit("submit",e))),o((()=>this.viewModel),"complete",(e=>this.emit("complete",e)))]);const{height:e,width:t}=this.templateOptions;this.templateOptions.width=t||800,this.templateOptions.height=e||1100;const i=setTimeout((()=>{this._awaitingServerResponse=!0,this.scheduleRender()}),500);this.viewModel.load().then((()=>{clearTimeout(i),this._awaitingServerResponse=!1}))}loadDependencies(){return f({action:()=>import("@esri/calcite-components/dist/components/calcite-action"),block:()=>import("@esri/calcite-components/dist/components/calcite-block"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),checkbox:()=>import("@esri/calcite-components/dist/components/calcite-checkbox"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch"),chip:()=>import("@esri/calcite-components/dist/components/calcite-chip"),popover:()=>import("@esri/calcite-components/dist/components/calcite-popover"),link:()=>import("@esri/calcite-components/dist/components/calcite-link")})}destroy(){this.viewModel.destroy()}get allowedFormats(){return this.viewModel.allowedFormats}set allowedFormats(e){this.viewModel.allowedFormats=e}get allowedLayouts(){return this.viewModel.allowedLayouts}set allowedLayouts(e){this.viewModel.allowedLayouts=e}get error(){return this.viewModel.error}get exportedLinks(){return this.viewModel.exportedLinks}set exportedLinks(e){this.viewModel.exportedLinks=e}get extraParameters(){return this.viewModel.extraParameters}set extraParameters(e){this.viewModel.extraParameters=e}get icon(){return"print"}set icon(e){this._overrideIfSome("icon",e)}get includeDefaultTemplates(){return this.viewModel.includeDefaultTemplates}set includeDefaultTemplates(e){this.viewModel.includeDefaultTemplates=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get outSpatialReference(){return this.viewModel.outSpatialReference}set outSpatialReference(e){this.viewModel.outSpatialReference=e}get portal(){return this.viewModel.portal}set portal(e){this.viewModel.portal=e}get saveExportEnabled(){return this.viewModel.saveExportEnabled}set saveExportEnabled(e){this.viewModel.saveExportEnabled=e}get showPrintAreaEnabled(){return this.viewModel.showPrintAreaEnabled}set showPrintAreaEnabled(e){this.viewModel.showPrintAreaEnabled=e}get printServiceUrl(){return this.viewModel.printServiceUrl}set printServiceUrl(e){this.viewModel.printServiceUrl=e}get templateCustomTextElements(){return this.viewModel.templateCustomTextElements}set templateCustomTextElements(e){this.viewModel.templateCustomTextElements=e}get templateOptions(){return this.viewModel.templateOptions}set templateOptions(e){this.viewModel.templateOptions=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}render(){const{messages:e,templateOptions:t,viewModel:i,view:a}=this,{attributionEnabled:l,author:o,copyright:s,dpi:n,format:r,height:c,layout:p,layoutItem:m,legendEnabled:b,northArrowEnabled:_,scaleBarEnabled:v,scaleEnabled:g,scale:y,width:f}=t,C="ready"!==i.state||this._awaitingServerResponse||!(p||m),S=this._renderTitleOrFileNameSection(),O=I("div",{class:F.formSectionContainer},I("calcite-label",null,e.fileFormatTitle,I("calcite-combobox",{clearDisabled:!0,label:e.formatDefaultOption,maxItems:6,placeholder:e.formatDefaultOption,selectionMode:"single-persist",onCalciteComboboxChange:({currentTarget:e})=>{this.templateOptions.format=e.selectedItems[0]?.value??"pdf"}},this._formats.map((({value:e,label:t},i)=>I("calcite-combobox-item",{key:`file-format-${i}`,selected:e===this.templateOptions.format,textLabel:t,value:e})))))),$=I("calcite-label",{layout:"inline"},I("calcite-switch",{checked:this.showPrintAreaEnabled,onCalciteSwitchChange:e=>{this.showPrintAreaEnabled=!!e.currentTarget.checked}}),e.printPreview),E=I("div",null,I("div",{class:F.formSectionContainer},I("calcite-label",null,e.template,I("calcite-block",{class:F.templateSelectContainer,collapsible:!1,description:this._getPageSizeLabel(this._selectedTemplate),heading:this._getTemplateLabel(this._selectedTemplate,!0),key:"template-select-block",loading:"loading"===this._selectedTemplate?.state,onclick:()=>this._showTemplates=!0,onkeydown:e=>{"Enter"!==e.key&&" "!==e.key||(this._showTemplates=!0)},tabIndex:0},I("calcite-icon",{class:F.templateSelectIcon,icon:(this._selectedTemplate?.layout?N.get(this._selectedTemplate.layout):null)||"custom-print",key:"template-select-icon",scale:"l",slot:"content-start"}),"error"===this._selectedTemplate?.state?I("calcite-icon",{class:F.templateSelectError,icon:"exclamation-mark-circle",key:"template-select-error",scale:"s",slot:"actions-end"}):null,I("calcite-icon",{class:F.templateSelectArrow,icon:k()?"chevron-left":"chevron-right",key:"template-select-arrow",scale:"s",slot:"actions-end"})))),$),M=I("div",{class:F.formSectionContainer},I("calcite-label",null,e.dpi,I("calcite-input-number",{bind:this,"data-input-name":"dpi",min:1,value:`${n}`,onCalciteInputNumberInput:this._updateNumberInputValue}))),P=I("div",{class:F.formSectionContainer},I("calcite-label",null,I("div",{class:F.srLabel},e.outSpatialReference,I("calcite-link",{href:"https://developers.arcgis.com/rest/services-reference/enterprise/using-spatial-references/",target:"_blank"},"(WKID)")),I("calcite-input-number",{bind:this,"data-input-name":"outSpatialReference",integer:!0,numberButtonType:"none",value:i.outSpatialReference?.wkid?.toString()??"",onCalciteInputNumberInput:({currentTarget:e})=>{const t=d(e.value);i.outSpatialReference=Number.isNaN(t)||null==t?null:new u({wkid:t}),this._isValidSpatialReference=!i.outSpatialReference||h(i.outSpatialReference)}}),this._isValidSpatialReference?null:I("div",{class:F.invalidWkidText,key:`out-sr-${i.outSpatialReference?.wkid}`},e.invalidWkid))),A=I("div",{class:this.classes(F.scaleInfoContainer,F.formSectionContainer)},I("calcite-label",{layout:"inline"},I("calcite-checkbox",{bind:this,checked:g,"data-option-name":"scaleEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.scale),I("div",{class:F.scaleInputContainer},I("calcite-input-number",{"aria-label":e.scaleLabel,"aria-valuenow":`${y}`,bind:this,class:F.scaleInput,"data-input-name":"scale",disabled:!g,value:`${y}`,onCalciteInputNumberInput:this._updateNumberInputValue}),I("calcite-button",{appearance:"outline","aria-label":e.reset,bind:this,disabled:!g,iconStart:"refresh",kind:"neutral",onclick:this._resetToCurrentScale}))),R=I("div",{"aria-labelledby":`${this.id}__advancedOptionsForLayout`,class:F.advancedOptionsContainer,key:"advanced-section-for-layout"},A,this._selectedTemplate?.layoutTemplateInfo?.layoutOptions?.hasAuthorText??1?I("div",{class:F.formSectionContainer,key:"author-info"},I("calcite-label",null,e.author,I("calcite-input",{bind:this,"data-input-name":"author",value:o??"",onCalciteInputInput:this._updateInputValue}))):null,this._selectedTemplate?.layoutTemplateInfo?.layoutOptions?.hasCopyrightText??1?I("div",{class:F.formSectionContainer,key:"copyright-text"},I("calcite-label",null,e.copyright,I("calcite-input",{bind:this,"data-input-name":"copyright",value:s??"",onCalciteInputInput:this._updateInputValue}))):null,M,P,this._renderCustomTextElementSection(),this._selectedTemplate?.layoutTemplateInfo?.layoutOptions?.hasLegend??1?I("div",{class:F.formSectionContainer,key:"legend-info"},I("calcite-label",{layout:"inline"},I("calcite-checkbox",{bind:this,checked:!!b,"data-option-name":"legendEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.legend)):null,this._selectedTemplate?.mapSurroundInfoOptions?.northArrow.length?I("div",{class:F.formSectionContainer,key:"north-arrow"},I("calcite-label",{layout:"inline"},I("calcite-checkbox",{bind:this,checked:!!_,"data-option-name":"northArrowEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.northArrow)):null,this._selectedTemplate?.mapSurroundInfoOptions?.scaleBar.length?I("div",{class:F.formSectionContainer,key:"scale-bar"},I("calcite-label",{layout:"inline"},I("calcite-checkbox",{bind:this,checked:!!v,"data-option-name":"scaleBarEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.scaleBar)):null),B=I("div",{"aria-labelledby":`${this.id}__advancedOptionsForMapOnly`,class:F.advancedOptionsContainer},A,M,P,I("div",{class:F.formSectionContainer},I("calcite-label",{layout:"inline"},I("calcite-checkbox",{bind:this,checked:l,"data-option-name":"attributionEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.attribution)),this._renderCustomTextElementSection()),j=this.exportedLinks.toArray(),V=this._renderExportedLinkItems(j),D={[F.exportSectionCentered]:!j.length},U=this._selectedTab===L.layout?I("section",{"aria-labelledby":`${this.id}__layoutTab`,class:F.layoutSection,id:`${this.id}__layoutContent`,key:"esri-print__layoutContent",role:"tabpanel"},I("div",{class:F.panelContainer},this._selectedTemplate?.layoutTemplateInfo?.layoutOptions?.hasTitleText??1?S:null,E,this._selectedTab===L.layout?O:null,I("calcite-block",{"aria-label":e.advancedOptions,class:this.classes(F.panelContainer,F.advancedOptionsSection),collapsible:!0,disabled:!(p||m?.id),heading:e.advancedOptions,id:"advancedOptionsForLayout",key:"advanced-options-for-layout"},R))):this._selectedTab===L.mapOnly?I("section",{"aria-labelledby":`${this.id}__mapOnlyTab`,class:F.mapOnlySection,id:`${this.id}__mapOnlyContent`,key:"esri-print__mapOnlyContent",role:"tabpanel"},I("div",{class:F.panelContainer},S,O,I("div",null,I("div",{class:this.classes(F.sizeContainer,F.formSectionContainer)},I("calcite-label",null,e.width,I("calcite-input-number",{bind:this,"data-input-name":"width",value:`${f}`,onCalciteInputNumberInput:this._updateNumberInputValue})),I("calcite-label",null,e.height,I("calcite-input-number",{bind:this,"data-input-name":"height",value:`${c}`,onCalciteInputNumberInput:this._updateNumberInputValue})),I("button",{"aria-label":e.swap,bind:this,class:this.classes(w.widgetButton,F.swapButton,x.swap),onclick:this._switchInput,type:"button"})),$),I("calcite-block",{"aria-label":e.advancedOptions,class:this.classes(F.panelContainer,F.advancedOptionsSection),collapsible:!0,heading:e.advancedOptions,id:"advancedOptionsForMapOnly",key:"advanced-options-for-map-only"},B))):I("section",{"aria-labelledby":`${this.id}__exportTab`,class:this.classes(F.exportSection,D),id:`${this.id}__exportContent`,key:"esri-print__exportContent",role:"tabpanel"},I("div",{class:F.panelContainer},I("div",{afterUpdate:this._scrollExportIntoView,bind:this,class:F.exportedFilesContainer},0===j.length?I("div",{class:F.exportedFilesEmpty},I("calcite-icon",{icon:"file",scale:"l"}),I("div",null,I(T,{class:F.exportedFilesTitle,level:this.headingLevel},e.noExportedFiles),I("div",null,e.exportHint))):V))),H="2d"!==a?.type,z=I("div",{class:F.panelError},a?H?e.sceneViewError:e.serviceError:e.noViewError),W=j.some((({state:e})=>"pending"===e)),q=I("div",{class:F.content,key:"panel"},I("div",null,I("ul",{bind:this,class:F.layoutTabList,onclick:this._toggleLayoutPanel,onkeydown:this._handleLayoutPanelKeyDown,role:"tablist"},I("li",{afterCreate:this._focusOnTabChange,afterUpdate:this._focusOnTabChange,"aria-selected":`${this._selectedTab===L.layout}`,class:F.layoutTab,"data-tab-id":L.layout,id:`${this.id}__layoutTab`,role:"tab",tabIndex:0},e.layoutTab),I("li",{afterCreate:this._focusOnTabChange,afterUpdate:this._focusOnTabChange,"aria-selected":`${this._selectedTab===L.mapOnly}`,class:F.layoutTab,"data-tab-id":L.mapOnly,id:`${this.id}__mapOnlyTab`,role:"tab",tabIndex:0},e.mapOnlyTab),I("li",{afterCreate:this._focusOnTabChange,afterUpdate:this._focusOnTabChange,"aria-selected":`${this._selectedTab===L.export}`,class:F.layoutTab,"data-tab-id":L.export,id:`${this.id}__exportedFilesTab`,role:"tab",tabIndex:0},W?I("calcite-loader",{inline:!0,label:"loading",scale:"s"}):null,e.exportsTab)),U),this._selectedTab!==L.export?I("div",{class:this.classes(F.printButtonSection,!this.saveExportHidden&&this.portal?F.printButtonSectionDivider:null),key:"export-button-section"},!this.saveExportHidden&&this.portal?I("calcite-label",{layout:"inline"},I("calcite-checkbox",{bind:this,checked:this.saveExportEnabled,onCalciteCheckboxChange:e=>{this.saveExportEnabled=!!e.currentTarget.checked}}),e.saveExportToMyContent):null,I("calcite-button",{"aria-label":e.exportDescription,bind:this,class:this.classes(F.printButton),disabled:C||!(p||m?.id)&&!r,onclick:this._handlePrintMap,scale:"l",width:"full"},e.export)):null),K=I("calcite-flow",{key:"root-flow"},I("calcite-flow-item",{bind:this,key:"root-flow-item",selected:!this._showTemplates},I("div",{class:F.printWidgetContainer},this.headerVisible?I("header",{class:F.headerTitle},e.export):null,this.error||H||!a?z:q)),this._renderChooseTemplateFlowItem()),G="initializing"===i.state,J=G?this._renderLoader():K,Q={[F.panelItemsCentered]:G};return I("div",{bind:this,class:this.classes(F.base,w.widget,w.panel,Q)},J)}_getPageSizeLabel(e){if(!e)return;const t=e.layoutTemplateInfo;if(!t)return;const i=B.fromJSON(t.pageUnits.toLowerCase());return`${$(t.pageSize[0])} × ${$(t.pageSize[1])} ${n(this.messagesUnits,i,"abbr")}`}_getTemplateLabel(e,t=!1){if(!e)return t?this.messages.selectTemplate:this.messages.untitled;const{label:i,layout:a,layoutItem:l,type:o}=e;if("print-service-template"===o&&this.messages[a])return this.messages[a];const s=i??a??l?.id;return s?.replaceAll("_"," ")??this.messages.untitled}_getPortalTemplates(){const{portalTemplateIds:e}=this.viewModel;return this.includeDefaultTemplates&&this.includeOrganizationTemplates?this.viewModel.defaultTemplates.toArray().filter((({layout:t,layoutItem:i})=>!A(t)&&!!i?.id&&e.includes(i.id))):[]}_getDefaultTemplates(){const{portalTemplateIds:e}=this.viewModel;return this.includeDefaultTemplates?this.viewModel.defaultTemplates.toArray().filter((({layout:t,layoutItem:i})=>!(A(t)||i?.id&&e.includes(i.id)))):[]}_getPrintServiceTemplates(){return this.includeDefaultTemplates&&this._getDefaultTemplates().length?[]:this.viewModel.printServiceTemplates.toArray().filter((({layout:e})=>!A(e)))}_renderLayoutTemplates(e,t=!1,i=!1){return t&&e.sort(((e,t)=>(e.label??"")>(t.label??"")?1:-1)),e.map((e=>I("calcite-list-item",{description:this._getPageSizeLabel(e),key:`template-${e.id}-${e.id===this.templateOptions.id}`,label:this._getTemplateLabel(e),selected:e.id===this.templateOptions.id,title:e.description??"",value:e},I("calcite-icon",{icon:(e.layout?N.get(e.layout):null)||"custom-print",slot:"content-start"}),"loading"===e.state?I("calcite-loader",{inline:!0,key:`template-loader-${e.id}`,label:"loading",scale:"s",slot:"content-end"}):null,"error"===e?.state?I("calcite-icon",{class:F.templateSelectError,icon:"exclamation-mark-circle",key:`template-error-${e.id}`,scale:"s",slot:"content-end"}):null,i?I("calcite-action",{icon:"trash",onclick:()=>this.viewModel.removePortalTemplate(e),slot:"actions-end",text:"delete"}):null)))}_renderChooseTemplateFlowItem(){if(!this._showTemplates)return null;const{messages:e}=this,t=b.test(this.portal?.url),i=this.viewModel.browseTemplates.toArray(),a=this._getPortalTemplates(),l=this._getDefaultTemplates(),o=this._getPrintServiceTemplates(),s=i.length+a.length+l.length+o.length>15,n=this.browseTemplateButtonOnClick?I("calcite-button",{appearance:"outline",class:s?F.browseTemplateButtonContainerFilter:F.browseTemplateButtonContainer,iconStart:"folder",key:"browse-template-button",onclick:this.browseTemplateButtonOnClick,slot:s?"filter-actions-end":"default"},s?null:e.browseTemplates):null;return I("calcite-flow-item",{bind:this,closable:!1,heading:e.chooseTemplate,key:"template-flow-item",selected:this._showTemplates,onCalciteFlowItemBack:e=>{e.preventDefault(),this._showTemplates=!1}},I("div",{class:F.templateSelectFlowItemContainer},I("div",{class:F.templateSelectFlowItemContent},s?null:n,I("calcite-list",{filterEnabled:s,filterProps:["label"],key:"template-list",label:e.templateList,selectionMode:"single-persist",onCalciteListChange:({currentTarget:e})=>this.viewModel.applyTemplate(e.selectedItems[0]?.value)},s?n:null,i.length?I("div",{key:"my-templates"},I("div",{class:F.templateSelectFlowItemListHeading},e.myTemplates,t?I("calcite-chip",{appearance:"outline",kind:"neutral",label:e.beta,scale:"s"},e.beta):null),this._renderLayoutTemplates(i,!0,!0)):null,a.length?I("div",{key:"org-templates"},I("div",{class:F.templateSelectFlowItemListHeading},e.organizationTemplates,t?I("calcite-chip",{appearance:"outline",kind:"neutral",label:e.beta,scale:"s"},e.beta):null),this._renderLayoutTemplates(a)):null,i.length||a.length?l.length?I("div",{key:"default-templates"},I("div",{class:F.templateSelectFlowItemListHeading},e.defaultTemplates),this._renderLayoutTemplates(l,!0)):null:this._renderLayoutTemplates(l,!0),i.length||a.length?o.length?I("div",{key:"service-templates"},I("div",{class:F.templateSelectFlowItemListHeading},e.defaultTemplates),this._renderLayoutTemplates(o)):null:this._renderLayoutTemplates(o))),I("div",{class:F.templateButtonContainer},I("calcite-button",{class:F.templateDoneButton,onclick:()=>this._showTemplates=!1},this.messagesCommon.done))))}_renderCustomTextElementSection(){const{customTextElements:e}=this.templateOptions;return e?I("div",{class:F.formSectionContainer,key:"custom-text-elements"},e.map(((e,t)=>{const[i,a]=Object.entries(e)[0];return"date"===i?null:I("calcite-label",{key:`custom-text-elements-${i}-${t}`},i,I("calcite-input",{bind:this,"data-input-custom":!0,"data-input-name":i,value:a??"",onCalciteInputInput:this._updateInputValue}))}))):null}_renderTitleOrFileNameSection(){const{title:e,fileName:t,titlePlaceHolder:i,fileNamePlaceHolder:a}=this.messages,l=this._selectedTab===L.layout?e:t,o=this._selectedTab===L.layout?i:a,s=this._selectedTab===L.layout?this.templateOptions.title:this.templateOptions.fileName;return I("div",{class:F.formSectionContainer,key:l},I("calcite-label",null,l,I("calcite-input",{placeholder:o,value:s??"",onCalciteInputInput:this._onInput})))}_focusOnTabChange(e){if(!this._activeTabFocusRequested)return;const t=e.getAttribute("data-tab-id");("layoutTab"===t&&this._selectedTab===L.layout||"mapOnlyTab"===t&&this._selectedTab===L.mapOnly||"exportTab"===t&&this._selectedTab===L.export)&&(e.focus(),this._activeTabFocusRequested=!1)}_renderLoader(){const e={[F.loader]:this._awaitingServerResponse};return I("div",{class:this.classes(e),key:"loader"})}_resetToCurrentScale(){this.templateOptions.scale=this.viewModel.view?.scale}_updateCustomTextElementValue(e,t,i){e.find((e=>{const[i]=Object.entries(e)[0];return i===t}))[t]=i}_updateInputValue(e){const t=e.currentTarget,i=t.getAttribute("data-input-name"),a=!!t["data-input-custom"],{templateOptions:l}=this;a?this._updateCustomTextElementValue(l.customTextElements,i,t.value):l[i]=t.value}_updateNumberInputValue(e){const t=e.currentTarget,i=t.getAttribute("data-input-name"),{templateOptions:a}=this,l=Number(t.value);if(P(l))a[i]=l;else{const e=a[i];t.value=`${e}`}}_handlePrintMap(){this._pendingExportScroll=!0;const{templateOptions:e}=this,t=this._selectedTab===L.layout?e.title:e.fileName,{promise:i}=this.viewModel.export(t||this.messages.untitled);this._selectedTab=L.export,i.then((()=>this.scheduleRender()))}_switchInput(){[this.templateOptions.width,this.templateOptions.height]=[this.templateOptions.height,this.templateOptions.width]}_scrollExportIntoView(){if(!this._pendingExportScroll)return;this._pendingExportScroll=!1;const e=this._rootNode;if(!e)return;const{clientHeight:t,scrollHeight:i}=e,a=i-t;a>0&&(e.scrollTop=a)}_toggleInputValue(e){const t=e.target,i=t.getAttribute("data-option-name");this.templateOptions[i]=t.checked,"scaleEnabled"===i&&this._resetToCurrentScale()}_renderExportedLinkItemPopover(e){const t=this.messages,i=e.formattedName??"",{state:a}=e,l=this.saveAsButtonCallback&&"error"!==a&&this._isFormatAllowedForSaving(e.extension);return"pending"!==a&&l?I("calcite-popover",{autoClose:!0,key:`${i}-popover`,label:"Popover",offsetDistance:1,overlayPositioning:"fixed",pointerDisabled:!0,referenceElement:`${i}-popover-button`,scale:"s"},I("calcite-list",{label:""},e.portalItem?I("calcite-list-item",{label:t.openItem,onCalciteListItemSelect:()=>{const t=e.portalItem;if(!t||!t.itemPageUrl)return;const i=document.createElement("a");i.target="_blank",i.href=t.itemPageUrl,i.rel="noreferrer",i.click()}},I("calcite-icon",{icon:"launch2",key:`${i}-launch-icon`,scale:"s",slot:"content-start"})):I("calcite-list-item",{label:t.saveAs,onCalciteListItemSelect:async()=>{this.saveAsButtonCallback&&(s((()=>e.portalItem)).then((e=>{e.itemPageUrl&&this.scheduleRender()})),await this.saveAsButtonCallback(e))}},I("calcite-icon",{icon:"save",key:`${i}-save-icon`,scale:"s",slot:"content-start"})),I("calcite-list-item",{label:this.messagesCommon.delete,onCalciteListItemSelect:()=>this.exportedLinks.remove(e)},I("calcite-icon",{icon:"trash",key:`${i}-delete-icon`,scale:"s",slot:"content-start"})))):null}_renderExportedLinkItemContent(e,t){const i=this.messages,{url:a,state:l}=e,o=e.formattedName??"";let s=a||null;s&&(s=r(s));const n=c(s,location.href);return I("div",{class:F.exportedFile,"data-item":e,onclick:this._handleLinkClick,slot:"content"},I("div",null,I("div",{class:F.exportedFileLinkTitle},o),I("div",{class:F.exportedFileLinkDescription},"pending"===l?i.generatingExport:t||(n?i.ready:i.linkReady))),"ready"===l?I("calcite-icon",{"aria-label":`${o}. ${i.linkReady}`,icon:n?"download-to":"launch",key:`${o}-end-icon`,scale:"s",slot:"content-end"}):null)}_renderExportedLinkItemIcon(e){const t=e.formattedName??"";return"pending"===e.state?I("calcite-loader",{class:F.exportedFileLoader,inline:!0,key:`${t}-loader`,label:this.messages.generatingExport,scale:"m",slot:"content-start"}):I("calcite-icon",{icon:R(e),key:`${t}-start-icon`,scale:"s",slot:"content-start"})}_renderExportedLinkItemAction(e,t){const{state:i}=e,a=e.formattedName??"",l=this.saveAsButtonCallback&&"error"!==i&&this._isFormatAllowedForSaving(e.extension);return"pending"!==i?I("calcite-action",{"aria-label":`${t}`,icon:l?"ellipsis":"x",id:l?`${a}-popover-button`:void 0,key:l?`${a}-saveAs-action`:`${a}-action`,onclick:l?void 0:()=>{this.exportedLinks.remove(e)},slot:"actions-end",text:`${t}`}):null}_renderExportedLinkItem(e){const t=this.messages,{error:i,state:a}=e,l=e.formattedName??"";let o;switch(a){case"pending":o=t.pending;break;case"ready":o=t.ready;break;case"error":o=t.errorMessage}const s="error"===a?"print-task:cim-symbol-unsupported"===i?.name?t.exportWebMapCIMError:t.exportWebMapError:"";return I(O,null,I("calcite-list-item",{"aria-label":o,key:l,title:s},this._renderExportedLinkItemContent(e,s),this._renderExportedLinkItemIcon(e),this._renderExportedLinkItemAction(e,s)),this._renderExportedLinkItemPopover(e))}_renderExportedLinkItems(e){return I("calcite-list",{filterEnabled:e?.length>10,label:this.messages.exportedLinksList},e.map(this._renderExportedLinkItem.bind(this)))}_isFormatAllowedForSaving(e){return!this.allowedFormatsForSaving||"all"===this.allowedFormatsForSaving||!(!e||!this.allowedFormatsForSaving.includes(e))}_toggleLayoutPanel(e){const t=e.target;this._toggleTab(t.getAttribute("data-tab-id"))}_toggleTab(e,t=!0){if(this._selectedTab=e,this._selectedTab===L.mapOnly)this.viewModel.applyTemplate(E);else if(this._selectedTab===L.layout){const e=this._selectedTemplate??this.viewModel.defaultTemplate;this.viewModel.applyTemplate(e)}t&&(this._activeTabFocusRequested=!0)}_handleLayoutPanelKeyDown(e){const{key:t}=e,i=e.target.getAttribute("data-tab-id");if(C(t))return this._toggleTab(i),e.preventDefault(),void e.stopPropagation();if("ArrowLeft"===t||"ArrowRight"===t){switch(i){case L.layout:this._toggleTab("ArrowLeft"===t?L.export:L.mapOnly);break;case L.mapOnly:this._toggleTab("ArrowLeft"===t?L.layout:L.export);break;case L.export:this._toggleTab("ArrowLeft"===t?L.mapOnly:L.layout)}e.preventDefault(),e.stopPropagation()}}};e([p()],j.prototype,"_showTemplates",void 0),e([p()],j.prototype,"_isValidSpatialReference",void 0),e([p()],j.prototype,"allowedFormats",null),e([p()],j.prototype,"allowedFormatsForSaving",void 0),e([p()],j.prototype,"allowedLayouts",null),e([p()],j.prototype,"browseTemplateButtonOnClick",void 0),e([p()],j.prototype,"error",null),e([p()],j.prototype,"exportedLinks",null),e([p()],j.prototype,"extraParameters",null),e([p()],j.prototype,"headerVisible",void 0),e([p()],j.prototype,"headingLevel",void 0),e([p()],j.prototype,"icon",null),e([p()],j.prototype,"includeDefaultTemplates",null),e([p()],j.prototype,"includeOrganizationTemplates",void 0),e([p()],j.prototype,"label",null),e([p(),S("esri/widgets/Print/t9n/Print")],j.prototype,"messages",void 0),e([p(),S("esri/t9n/common")],j.prototype,"messagesCommon",void 0),e([p(),S("esri/core/t9n/Units")],j.prototype,"messagesUnits",void 0),e([p({type:u})],j.prototype,"outSpatialReference",null),e([p()],j.prototype,"portal",null),e([p()],j.prototype,"saveExportEnabled",null),e([p()],j.prototype,"saveExportHidden",void 0),e([p()],j.prototype,"showPrintAreaEnabled",null),e([p()],j.prototype,"printServiceUrl",null),e([p()],j.prototype,"saveAsButtonCallback",void 0),e([p()],j.prototype,"templateCustomTextElements",null),e([p()],j.prototype,"templateOptions",null),e([p()],j.prototype,"view",null),e([p({type:y})],j.prototype,"viewModel",void 0),j=e([m("esri.widgets.Print")],j);const V=j;export{V as default};