@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 6.03 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import{on as t,sync as n}from"../../../core/reactiveUtils.js";import{property as o,subclass as i}from"../../../core/accessorSupport/decorators.js";import l from"./Column.js";import{autoLink as a}from"../../support/uriUtils.js";const r={showInput:"Enter",cancelEdit:"Escape"},c=Symbol();let s=class extends l{constructor(e){super(e),this.editInfo=null,this.cellValueValidatorFunction=({oldValue:e,value:t})=>e!==t,this.editable=!0,this.headerRenderFunction=e=>{const{root:t}=e,n=this.createHeaderContent();this.tableEditingEnabled&&!this.effectiveEditable&&n.prepend(this._lockIconNode),this.removeCellContent(t),t.appendChild(n)},this.inputRenderFunction=({root:e,column:t,rowData:n})=>{if(this.editInfo||!this.effectiveEditable||!n)return;const o=this.getCellValue(n),i=this.createInputElement({rowData:n,value:o});this._set("editInfo",{column:t,inputs:[i],root:e,rowData:n,oldValue:o});const l=document.createElement("div");l.appendChild(i),this.removeCellContent(e),e.appendChild(l),i.focus(),i instanceof HTMLInputElement&&i.select()},this.inputType="text",this.maxLength=null,this.onShowPromptCallback=()=>{},this.parseInputValueFunction=({inputs:e})=>e?.length||1!==e.length||Array.isArray(e[0].value)?null:e[0].value,this.renderFunction=e=>{const{root:t,rowData:n}=e,{editInfo:o}=this;if(o)return;const i=this.getCellValue(n),l=this.cellValueFormatFunction({root:t,rowData:n,value:i});let c=null;t.onclick=()=>t.focus(),t.ondblclick=()=>this.inputRenderFunction(e),t.ontouchend=()=>this.inputRenderFunction(e);const s=this.grid?.getSlotElementByName(t.slot),u=s?.parentElement;u&&!u.onkeydown&&(u.onkeydown=t=>{t.key!==r.showInput||this.editInfo||this.inputRenderFunction(e),t.key===r.cancelEdit&&this.editInfo&&this.cancel()}),null!=i&&null!=l?t.title=l.toString():t.title&&t.removeAttribute("title"),c=l instanceof HTMLElement?l:a(this.messagesURIUtils,l),this.removeCellContent(t),c instanceof HTMLElement?t.appendChild(c):null!=c&&(t.innerHTML=c.toString())},this.required=!1}get _lockIconNode(){return this.createCalciteIcon({icon:"lock",textLabel:this.messages?.editingPreventedColumn})}get effectiveEditable(){return this.tableEditingEnabled&&this.editable}get effectiveRequired(){return this.required}get editing(){return!!this.editInfo}get loadingMessage(){return this.messages?.loading||"..."}get shouldShowPrompt(){return!1}get tableEditingEnabled(){return this.store.editingEnabled}cancel(){this.onEditComplete()}createCalciteCombobox(e){const t=document.createElement("calcite-combobox");return t.clearDisabled=!0,t.selectionMode="single",t.required=!!e.required,t}createCalciteComboboxItem(e){const t=document.createElement("calcite-combobox-item");return t.disabled=e.disabled??!1,t.heading=e.heading,t.value=e.value,t.selected=e.selected??!1,t}createCalciteComboboxItemGroup(e){const t=document.createElement("calcite-combobox-item-group");return t.label=e.label,t}createCalciteOption(e,t,n=!1){const o=document.createElement("calcite-option");return o.label=e,o.value=`${t}`,o.selected=n,o}createCalciteSelect(e,t){const{effectiveRequired:n,messages:o}=this;let i=!1;const l=t.map(({name:t,value:n})=>{const o=n===e;return o&&(i=!0),this.createCalciteOption(t,n,o)});if(null!=e&&""!==e&&!i){const t=e.toString(),n=this.createCalciteOption(t,t);l.unshift(n)}n||l.unshift(this.createCalciteOption(`<${o?.noValue}>`,""));const a=document.createElement("calcite-select");return l.forEach(e=>a.appendChild(e)),a}createInputElement({value:e}){const{effectiveRequired:o,maxLength:i}=this,l=document.createElement("calcite-input");return null!=i&&(l.maxLength=i),l.required=o,l.value=null!=e?e.toString():"",this.addHandles([t(()=>l,"calciteInputChange",()=>this.onInputBlur(),n),t(()=>l,"keydown",e=>{e.key===r.cancelEdit&&this.onInputBlur(!0)},n),t(()=>l,"blur",()=>this.onInputBlur(),n)],c),l}createDateComponent(){const e=document.createElement("calcite-input-date-picker");return e.focusTrapDisabled=!0,e.overlayPositioning="fixed",e}createTimeComponent(){const e=document.createElement("calcite-input-time-picker");return e.overlayPositioning="fixed",e.placement="auto-start",e.step=1,e}createTimeZoneComponent(){const e=document.createElement("calcite-input-time-zone");return e.maxItems=4,e.overlayPositioning="fixed",e}onEditComplete(){this._set("editInfo",null);const e=this.grid;e&&(e.generateCellPartNames(),e.refreshPageCache())}onInputBlur(e=!1){this.removeHandles(c),e?this.cancel():this.submit()}async submit(){const{editInfo:e}=this;if(!e)return void this.cancel();const{inputs:t,rowData:n,oldValue:o}=e,i=this.parseInputValueFunction({inputs:t});if(!this.cellValueValidatorFunction({value:i,oldValue:o}))return void this.cancel();const{root:l}=e,a=n.item.objectId,{fieldName:r}=this;l.textContent=this.loadingMessage,this.shouldShowPrompt?this.onShowPromptCallback({column:this,objectId:a,oldValue:o,value:i}):await this.updateItems({objectId:a,updates:[{fieldName:r,value:i}]})}async updateItems(e){try{await this.store.updateItem(e),this.onEditComplete()}catch{this.cancel()}}};e([o()],s.prototype,"_lockIconNode",null),e([o({readOnly:!0})],s.prototype,"editInfo",void 0),e([o()],s.prototype,"cellValueValidatorFunction",void 0),e([o()],s.prototype,"editable",void 0),e([o()],s.prototype,"effectiveEditable",null),e([o()],s.prototype,"effectiveRequired",null),e([o()],s.prototype,"editing",null),e([o()],s.prototype,"headerRenderFunction",void 0),e([o()],s.prototype,"inputRenderFunction",void 0),e([o()],s.prototype,"loadingMessage",null),e([o()],s.prototype,"inputType",void 0),e([o()],s.prototype,"maxLength",void 0),e([o()],s.prototype,"onShowPromptCallback",void 0),e([o()],s.prototype,"parseInputValueFunction",void 0),e([o()],s.prototype,"renderFunction",void 0),e([o()],s.prototype,"required",void 0),e([o()],s.prototype,"shouldShowPrompt",null),e([o()],s.prototype,"tableEditingEnabled",null),s=e([i("esri.widgets.FeatureTable.Grid.EditorColumn")],s);const u=s;export{u as default};