@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 11.5 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{watch as i,when as n,initial as o}from"../../../core/reactiveUtils.js";import{renderingSanitizer as s,stripHTMLSanitizer as l}from"../../../core/sanitizerUtils.js";import{property as r,subclass as a}from"../../../core/accessorSupport/decorators.js";import{css as c}from"./ColumnCSS.js";import{isEmptyStringOrWhitespace as d}from"../support/tableUtils.js";import{autoLink as p}from"../../support/uriUtils.js";import{setFocus as u}from"../../support/widgetUtils.js";const h=/<br\s*\/*>/gi;let m=class extends t{constructor(e){super(e),this._menuIsOpen=!1,this.autoWidth=!1,this.cellValueFormatFunction=({root:e,rowData:t,value:i})=>{const{formatFunction:n}=this,o=this.sanitizeContent(i);if(n&&t){const{index:i,item:{attachments:s,feature:l,relatedRecords:r}}=t;return n({attachments:s,column:this,feature:l,index:i,relatedRecords:r,value:o,virtualIndex:this.getVirtualRowIndex(e),field:void 0})}return o},this.description=null,this.direction=null,this.fieldName=null,this.flexGrow=1,this.footerRenderFunction=null,this.formatFunction=null,this.frozen=!1,this.frozenToEnd=!1,this.grid=null,this.headerRenderFunction=e=>{const{root:t}=e,i=this.createHeaderContent();this.removeCellContent(t),t.appendChild(i)},this.hidden=!1,this.icon=null,this.iconText=null,this.initialSortPriority=null,this.label=null,this.labelTooltipText=null,this.menuConfig=null,this.messages=null,this.messagesCommon=null,this.messagesURIUtils=null,this.renderFunction=({root:e,rowData:t})=>{const i=this.getCellValue(t),n=this.cellValueFormatFunction({root:e,rowData:t,value:i});let o=null;if(o=n instanceof HTMLElement?n:p(this.messagesURIUtils,n),this.removeCellContent(e),o instanceof HTMLElement)e.removeAttribute("title"),e.appendChild(o);else if(null!=o){const t=o.toString();e.innerHTML=t,e.title=t}},this.resizable=!0,this.sortable=!1,this.store=null,this.textAlign="start",this.textWrap=!1,this.timeZone=null,this.topLayerDisabled=!1,this.visibleElements=null,this.width=200}initialize(){const{fieldName:e}=this;this._set("sortElement",this.createSortElement()),this.sortElement.setAttribute("path",e),this.addHandles([i(()=>this.direction,e=>{const{sortElement:t}=this;this.effectiveSortable&&t&&(e?this.sortElement.direction!==e&&t.setAttribute("direction",e):t.removeAttribute("direction"))}),n(()=>this.grid?.isReady&&this.sortElement,()=>{const{direction:e,grid:t,hidden:i,sortElement:n}=this;i&&e&&n&&t&&!t.hasSorter(n)&&t.addSorter(n)},o),i(()=>[this.timeZone,this.icon,this.iconText,this.labelTooltipText],()=>this.grid?.requestContentUpdate()),i(()=>this.hidden,()=>this.closeMenu()),i(()=>this.fieldName,e=>{const{sortElement:t}=this;t&&t.path!==e&&t.setAttribute("path",e)}),i(()=>[this.effectiveLabel,this.labelTooltipText],([e,t])=>{const{sortElement:i}=this;i&&(i.setAttribute("title",t||e),i.textContent=e)})])}get _headerRequiresTextContainer(){return!(!this.effectiveSortable&&""===this.effectiveLabel&&null==this.effectiveDescription)}get customMenuItems(){return this.menuConfig?.items?.map(({disabled:e,hidden:t,icon:i,iconClass:n,label:o,selected:s,clickFunction:l})=>this.createCalciteDropdownItem({disabled:e,hidden:t,iconClass:n,iconStart:i,selected:s,textContent:o,onclick:e=>l(e)}))??[]}get defaultMenuItems(){if(!this.effectiveSortable)return[];const e=this.messages,t=[],i=this.visibleElements?.columnMenuItems;if(!1!==i?.sortAscending){const i=this.createCalciteDropdownItem({iconFlipRtl:"start",iconStart:"sort-ascending-arrow",textContent:e?.sortAsc,onclick:()=>this.direction="asc"});t.push(i)}if(!1!==i?.sortDescending){const i=this.createCalciteDropdownItem({iconFlipRtl:"start",iconStart:"sort-descending-arrow",textContent:e?.sortDesc,onclick:()=>this.direction="desc"});t.push(i)}return t}get effectiveDescription(){const{description:e}=this;return d(e)?null:this.sanitizeLabel(e)}get effectiveLabel(){return this.sanitizeLabel(this.label||this.fieldName)}get effectiveSortable(){return this.sortable}get iconNode(){const{icon:e,iconText:t}=this,i=t?this.sanitizeLabel(t):void 0;return e?this.createCalciteIcon({icon:e,textLabel:i}):null}set invalid(e){this._set("invalid",e),this.grid?.generateCellPartNames()}get invalid(){return this._get("invalid")??!1}get menu(){const{customMenuItems:e,defaultMenuItems:t,menuConfig:i}=this,n=!!i?.open,o=this.createCalciteAction({icon:i?.icon??"ellipsis",text:this.messages?.menu??"",scale:"m",slot:"trigger"}),s=document.createElement("calcite-dropdown");if(s.maxItems=i?.maxItems??4,s.placement="top-end",s.scale=i?.scale??"m",n&&(s.open=n,this._menuIsOpen=!0),s.appendChild(o),s.addEventListener("calciteDropdownOpen",()=>this._menuIsOpen=!0),s.addEventListener("calciteDropdownClose",()=>this._menuIsOpen=!1),s.onkeydown=this._stopPropagationOnSelect,s.addEventListener("mousewheel",e=>{e.stopPropagation()}),t.length){const e=s.appendChild(document.createElement("calcite-dropdown-group"));e.selectionMode="none",e.append(...t)}if(e.length){const t=s.appendChild(document.createElement("calcite-dropdown-group"));t.selectionMode=i?.selectionMode??"none",t.append(...e)}return s}get menuItems(){return[...this.defaultMenuItems,...this.customMenuItems]}get menuIsOpen(){return this._menuIsOpen}get menuIsVisible(){return!(!1===this.visibleElements?.columnMenus||!this.menuItems.length)}get tableHasInvalidPendingEdits(){return this.store.hasInvalidPendingEdits}get tableHasPendingEdits(){return this.store.hasPendingEdits}get tableTimeZone(){return this.store.timeZone}closeMenu(){this.menu.open=!1}createSortElement(){const{effectiveLabel:e,direction:t,fieldName:i,initialSortPriority:n}=this,o=document.createElement("vaadin-grid-sorter");return o.classList.add(c.sorter),o.setAttribute("path",i),o.setAttribute("title",this.labelTooltipText||e),o.textContent=e,t&&o.setAttribute("direction",t),null!=n&&(o._initialOrder=n),o.addEventListener("direction-changed",()=>{this.direction!==o.direction&&this._set("direction",o.direction)}),o}createCalciteAction(e){const t=document.createElement("calcite-action"),{alignment:i,className:n,disabled:o,icon:s,label:l,scale:r,slot:a,text:c,textEnabled:d,onclick:p}=e;return t.alignment=i??"center",t.className=n??"",t.disabled=!!o,s&&(t.icon=s),t.label=l??"",t.scale=r??"s",t.slot=a??"",t.text=t.title=c??"",t.textEnabled=!!d,t.onclick=p??null,t}createCalciteButton(e){const t=document.createElement("calcite-button"),{alignment:i,appearance:n,className:o,disabled:s,iconEnd:l,iconFlipRtl:r,kind:a,loading:c,onclick:d,scale:p,textContent:u,title:h,width:m}=e;return t.alignment=i??"center",t.className=o??"",t.scale=p??"s",t.appearance=n??"transparent",t.disabled=!!s,l&&(t.iconEnd=l),r&&(t.iconFlipRtl=r),t.kind=a??"brand",t.loading=!!c,t.textContent=u??"",h&&(t.title=h),t.width=m??"auto",t.onclick=d??null,t}createCalciteDropdownItem(e){const t=document.createElement("calcite-dropdown-item"),{disabled:i,hidden:n,iconClass:o,iconFlipRtl:s,iconStart:l,textContent:r,onclick:a,selected:d}=e,p=r??"";if(o&&!l){const e=document.createElement("span"),i=document.createElement("span");i.classList.add(c.headerMenuIcon,o),e.textContent=e.title=p,e.insertBefore(i,e.firstChild),t.appendChild(e)}else l&&(t.iconStart=l),t.textContent=t.title=p;return t.disabled=!!i,t.hidden="function"==typeof n?n():!!n,t.selected=!!d,s&&(t.iconFlipRtl=s),a&&(t.addEventListener("calciteDropdownItemSelect",a),t.onkeydown=this._stopPropagationOnSelect),t}createCalciteIcon(e){const{effectiveLabel:t}=this,{icon:i,scale:n,textLabel:o}=e,s=document.createElement("calcite-icon"),l=o??t;return s.icon=i,s.scale=n??"s",s.textLabel=l,s.title=l,s}createHeaderContent(){const{effectiveDescription:e,effectiveLabel:t,iconNode:i}=this,n=document.createElement("div");if(n.classList.add(c.headerContent),i&&n.appendChild(i),!this._headerRequiresTextContainer)return n;const o=n.appendChild(document.createElement("div"));return this.effectiveSortable?o.appendChild(this.sortElement):""!==t&&o.appendChild(this._createHeaderTextElement({label:t,cssClass:c.headerLabel,title:this.labelTooltipText})),null!=e&&!1!==this.visibleElements?.columnDescriptions&&o.appendChild(this._createHeaderTextElement({label:e,cssClass:c.headerDescription})),this.menuIsVisible&&n.appendChild(this.menu),n}getCellValue(e){return e?.item.feature.attributes?.[this.fieldName]}getVirtualRowIndex(e){const t=this.grid?.getRowContainingNode(e);return t?.parentElement?[...t.parentElement.children].indexOf(t):-1}itemHasInvalidPendingEdits(e,t){return this.store.itemHasInvalidPendingEdits(e,t)}itemHasPendingEdits(e,t){return this.store.itemHasPendingEdits(e,t)}openMenu(){this.menuIsVisible&&(this.menu.open=!0,u(this.menuItems[0]))}removeCellContent(e){if(e?.firstChild)try{for(;e?.firstChild;)e.removeChild(e.firstChild)}catch(t){}}sanitizeContent(e){return s.sanitize(e)}sanitizeLabel(e){return null==e||""===e?"":l.sanitize(e.toString()).replaceAll(h," ")}sort(){this.effectiveSortable&&this.sortElement?.click()}_stopPropagationOnSelect(e){"Enter"!==e.key&&" "!==e.key||e.stopPropagation()}_createHeaderTextElement({cssClass:e,label:t,title:i}){const n=document.createElement("span");n.classList.add(e);const o=n.appendChild(document.createElement("span"));return o.textContent=t,o.setAttribute("title",i||t),n}};e([r()],m.prototype,"_headerRequiresTextContainer",null),e([r()],m.prototype,"_menuIsOpen",void 0),e([r()],m.prototype,"autoWidth",void 0),e([r()],m.prototype,"cellValueFormatFunction",void 0),e([r()],m.prototype,"customMenuItems",null),e([r()],m.prototype,"defaultMenuItems",null),e([r()],m.prototype,"description",void 0),e([r()],m.prototype,"direction",void 0),e([r()],m.prototype,"effectiveDescription",null),e([r()],m.prototype,"effectiveLabel",null),e([r()],m.prototype,"effectiveSortable",null),e([r({constructOnly:!0})],m.prototype,"fieldName",void 0),e([r()],m.prototype,"flexGrow",void 0),e([r()],m.prototype,"footerRenderFunction",void 0),e([r()],m.prototype,"formatFunction",void 0),e([r()],m.prototype,"frozen",void 0),e([r()],m.prototype,"frozenToEnd",void 0),e([r()],m.prototype,"grid",void 0),e([r()],m.prototype,"headerRenderFunction",void 0),e([r()],m.prototype,"hidden",void 0),e([r()],m.prototype,"icon",void 0),e([r()],m.prototype,"iconNode",null),e([r()],m.prototype,"iconText",void 0),e([r({constructOnly:!0})],m.prototype,"initialSortPriority",void 0),e([r()],m.prototype,"invalid",null),e([r()],m.prototype,"label",void 0),e([r()],m.prototype,"labelTooltipText",void 0),e([r()],m.prototype,"menu",null),e([r()],m.prototype,"menuItems",null),e([r()],m.prototype,"menuConfig",void 0),e([r()],m.prototype,"menuIsOpen",null),e([r()],m.prototype,"menuIsVisible",null),e([r()],m.prototype,"messages",void 0),e([r()],m.prototype,"messagesCommon",void 0),e([r()],m.prototype,"messagesURIUtils",void 0),e([r()],m.prototype,"renderFunction",void 0),e([r()],m.prototype,"resizable",void 0),e([r()],m.prototype,"sortable",void 0),e([r({readOnly:!0})],m.prototype,"sortElement",void 0),e([r()],m.prototype,"store",void 0),e([r()],m.prototype,"tableHasInvalidPendingEdits",null),e([r()],m.prototype,"tableHasPendingEdits",null),e([r()],m.prototype,"tableTimeZone",null),e([r()],m.prototype,"textAlign",void 0),e([r()],m.prototype,"textWrap",void 0),e([r()],m.prototype,"timeZone",void 0),e([r()],m.prototype,"topLayerDisabled",void 0),e([r()],m.prototype,"visibleElements",void 0),e([r()],m.prototype,"width",void 0),m=e([a("esri.widgets.FeatureTable.Grid.Column")],m);const f=m;export{f as default};