UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 5.06 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../core/ReactiveMap.js";import{property as n}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as o}from"../../core/accessorSupport/decorators/subclass.js";import{isSupportedImage as s,getCalciteIconForAttachment as a}from"../Attachments/support/attachmentUtils.js";import i from"./Grid/Column.js";import{css as r}from"./Grid/ColumnCSS.js";import{renderingSanitizer as l}from"../support/widgetUtils.js";const c="esri-attachments-column",h={contentContainer:`${c}__content`,showAttachmentsButton:`${c}__button`};let m=class extends i{constructor(t){super(t),this._buttonElements=new e,this._thumbnailElements=new e,this.attachmentsViewEnabled=!0,this.cellValueFormatFunction=({root:t,rowData:e})=>{const{_showAttachmentsViewEnabled:n,formatFunction:o}=this,s=this.getCellValue(e);if(o&&e){const{index:n,item:{attachments:a,feature:i,relatedRecords:r}}=e;return o({attachments:a,column:this,feature:i,index:n,relatedRecords:r,value:s,virtualIndex:this.getVirtualRowIndex(t)})}if(!e)return s;const{index:a,item:{attachments:i,objectId:r}}=e,l=`(${s})`;if(!this.thumbnailsEnabled&&!n)return s;const c=document.createElement("span");c.textContent=c.title=l;let m=null;if(this.thumbnailsEnabled&&(m=this._createOrSyncThumbnails(r,i??[])),this._showAttachmentsViewEnabled){const t=document.createElement("div");m&&t.appendChild(m),t.appendChild(c);const e=this._createOrSyncShowAttachmentsButton(r,a);return e.appendChild(t),e}const u=document.createElement("div");return u.classList.add(h.contentContainer),m&&u.appendChild(m),u.appendChild(c),u},this.icon="attachment",this.layer=null,this.onShowAttachments=null,this.sortable=!1,this.store=null,this.textAlign="center",this.thumbnailAppearance="image",this.thumbnailCount=8,this.thumbnailIconScale="m",this.thumbnailsEnabled=!0}get _showAttachmentsViewEnabled(){return!(!this.attachmentsViewEnabled||!this.onShowAttachments)}get _supportsResize(){return!!this.store?.supportsResizeAttachments}get effectiveLabel(){return l.sanitize(this.label??(this.messages?.attachments||this.fieldName))}getCellValue(t){return t?.item?.attachments?.length??0}_createOrSyncThumbnails(t,e){const n=document.createElement("div"),o=this._thumbnailElements.get(t);return o?.length&&o.length===e.length?o.forEach((t=>n.appendChild(t))):this._thumbnailElements.set(t,this._createThumbnailElements(e,n)),n}_createOrSyncShowAttachmentsButton(t,e){const n=this._buttonElements.get(t);if(n)return n.textContent="",n.onclick=n=>this._onShowAttachmentsClick({index:e,objectId:t,event:n}),n;const o=this.createCalciteButton({alignment:"icon-end-space-between",className:`${h.showAttachmentsButton} ${r.contentFull}`,iconEnd:"chevron-right",iconFlipRtl:"both",scale:this.thumbnailIconScale,textContent:"",title:this.messages?.viewAttachments,width:"full",onclick:n=>this._onShowAttachmentsClick({index:e,objectId:t,event:n})});return this._buttonElements.set(t,o),o}_createThumbnailAnchor({name:t,url:e},n){const o=document.createElement("a");return o.href=`${e}`,o.download=t,o.rel="noreferrer",o.target="_blank",o.appendChild(n),o}_createThumbnailElements(t,e){const{thumbnailAppearance:n,thumbnailCount:o,thumbnailIconScale:i}=this,r=[],l=Math.min(o,t.length),c=!this.onShowAttachments,h="image"===n&&!!this.store?.supportsResizeAttachments;for(let m=0;m<l;m++){const n=t[m],{name:o,contentType:l}=n,u=s(l)&&h?this._createThumbnailImage(n):this.createCalciteIcon({icon:a(l),scale:i,textLabel:o}),p=c?this._createThumbnailAnchor(n,u):u;e&&e.appendChild(p),r.push(p)}return r}_createThumbnailImage(t){const{name:e,size:n,url:o}=t,s=document.createElement("img"),a=`${o}${o?.includes("?")?"&":"?"}${this._supportsResize?"w=24":""}&fs=${n}`;return s.alt=this.messages?.attachmentThumbnail??e,s.src=a,s.title=e,s}_onShowAttachmentsClick({index:t,objectId:e,event:n}){n.preventDefault(),n.stopPropagation(),this.onShowAttachments?.({index:t,objectId:e})}};t([n()],m.prototype,"_showAttachmentsViewEnabled",null),t([n()],m.prototype,"_buttonElements",void 0),t([n()],m.prototype,"_supportsResize",null),t([n()],m.prototype,"_thumbnailElements",void 0),t([n()],m.prototype,"attachmentsViewEnabled",void 0),t([n()],m.prototype,"cellValueFormatFunction",void 0),t([n()],m.prototype,"effectiveLabel",null),t([n()],m.prototype,"icon",void 0),t([n()],m.prototype,"layer",void 0),t([n()],m.prototype,"onShowAttachments",void 0),t([n({readOnly:!0})],m.prototype,"sortable",void 0),t([n()],m.prototype,"store",void 0),t([n()],m.prototype,"textAlign",void 0),t([n()],m.prototype,"thumbnailAppearance",void 0),t([n()],m.prototype,"thumbnailCount",void 0),t([n()],m.prototype,"thumbnailIconScale",void 0),t([n()],m.prototype,"thumbnailsEnabled",void 0),m=t([o("esri.widgets.FeatureTable.AttachmentsColumn")],m);const u=m;export{u as default};