@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 5.78 kB
JavaScript
/*
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{property as e}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as n}from"../../../core/accessorSupport/decorators/subclass.js";import o from"./Column.js";import{autoLink as i}from"../../support/uriUtils.js";const l={showInput:"Enter",hideInput:"Escape"};let r=class extends o{constructor(t){super(t),this.editInfo=null,this.cellValueValidatorFunction=({oldValue:t,value:e})=>t!==e,this.editable=!0,this.headerRenderFunction=t=>{const{root:e}=t,n=this.createHeaderContent();this.tableEditingEnabled&&!this.effectiveEditable&&n.prepend(this._lockIconNode),this.removeCellContent(e),e.appendChild(n)},this.inputRenderFunction=({root:t,column:e,rowData:n})=>{if(this.editInfo||!this.effectiveEditable||!n)return;const o=this.getCellValue(n),i=this.createInputElement({value:o});this._set("editInfo",{column:e,inputs:[i],root:t,rowData:n,oldValue:o});const l=document.createElement("div");l.appendChild(i),this.removeCellContent(t),t.appendChild(l),i.focus(),i instanceof HTMLInputElement&&i.select()},this.loadingMessage="",this.inputType="text",this.maxLength=null,this.onShowPromptCallback=()=>{},this.parseInputValueFunction=({inputs:t})=>t?.length||1!==t.length||Array.isArray(t[0].value)?null:t[0].value,this.renderFunction=t=>{const{root:e,rowData:n}=t,{editInfo:o}=this;if(o)return;const r=this.getCellValue(n),s=this.cellValueFormatFunction({root:e,rowData:n,value:r});let a=null;e.onclick=()=>e.focus(),e.ondblclick=()=>this.inputRenderFunction(t),e.ontouchend=()=>this.inputRenderFunction(t);const c=this.grid?.getSlotElementByName(e.slot),u=c?.parentElement;u&&!u.onkeydown&&(u.onkeydown=e=>{e.key!==l.showInput||this.editInfo||this.inputRenderFunction(t),e.key===l.hideInput&&this.editInfo&&this.cancel()}),null!=r&&null!=s?e.title=s.toString():e.title&&e.removeAttribute("title"),a=s instanceof HTMLElement?s:i(this.messagesURIUtils,s),this.removeCellContent(e),a instanceof HTMLElement?e.appendChild(a):null!=a&&(e.innerHTML=a.toString())},this.required=!1,this.tableEditingEnabled=!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 shouldShowPrompt(){return!1}cancel(){const{editInfo:t}=this;if(!t)return;const{column:e,root:n,rowData:o}=t;this.onEditComplete(),this.renderFunction({column:e,root:n,rowData:o})}createCalciteOption(t,e,n=!1){const o=document.createElement("calcite-option");return o.label=t,o.value=`${e}`,o.selected=n,o}createCalciteSelect(t,e){const{effectiveRequired:n,messages:o}=this;let i=!1;const l=e.map((({name:e,value:n})=>{const o=n===t;return o&&(i=!0),this.createCalciteOption(e,n,o)}));if(null!=t&&""!==t&&!i){const e=t.toString(),n=this.createCalciteOption(e,e);l.unshift(n)}n||l.unshift(this.createCalciteOption(`<${o?.noValue}>`,""));const r=document.createElement("calcite-select");return l.forEach((t=>r.appendChild(t))),r}createInputElement({value:t}){const{effectiveRequired:e,maxLength:n}=this,o=document.createElement("calcite-input");return null!=n&&(o.maxLength=n),o.required=e,o.value=t,o.addEventListener("calciteInputChange",(()=>this.onInputBlur(o))),o.onkeydown=t=>{t.key===l.hideInput&&this.onInputBlur(o,!0)},o.onblur=()=>this.onInputBlur(o),o}createDateComponent(){const t=document.createElement("calcite-input-date-picker");return t.focusTrapDisabled=!0,t.overlayPositioning="fixed",t}createTimeComponent(){const t=document.createElement("calcite-input-time-picker");return t.overlayPositioning="fixed",t.placement="auto-start",t.step=1,t}createTimeZoneComponent(){const t=document.createElement("calcite-input-time-zone");return t.maxItems=4,t.overlayPositioning="fixed",t}onEditComplete(){this._set("editInfo",null),this.grid?.generateCellPartNames()}onInputBlur(t,e=!1){t.onblur=null,e?this.cancel():this.submit()}async submit(){const{editInfo:t}=this;if(!t)return void this.cancel();const{inputs:e,rowData:n,oldValue:o}=t,i=this.parseInputValueFunction({inputs:e});if(!this.cellValueValidatorFunction({value:i,oldValue:o}))return void this.cancel();const{root:l}=t,r=n.item.objectId,{fieldName:s}=this;l.textContent=this.loadingMessage,this.shouldShowPrompt?this.onShowPromptCallback({column:this,objectId:r,oldValue:o,value:i}):await this.updateItems({objectId:r,updates:[{fieldName:s,value:i}]})}async updateItems(t){const{store:e}=this;if(e)try{await e.updateItem(t),this.onEditComplete()}catch{this.cancel()}else this.cancel()}};t([e()],r.prototype,"_lockIconNode",null),t([e({readOnly:!0})],r.prototype,"editInfo",void 0),t([e()],r.prototype,"cellValueValidatorFunction",void 0),t([e()],r.prototype,"editable",void 0),t([e()],r.prototype,"effectiveEditable",null),t([e()],r.prototype,"effectiveRequired",null),t([e()],r.prototype,"editing",null),t([e()],r.prototype,"headerRenderFunction",void 0),t([e()],r.prototype,"inputRenderFunction",void 0),t([e({constructOnly:!0})],r.prototype,"loadingMessage",void 0),t([e()],r.prototype,"inputType",void 0),t([e()],r.prototype,"maxLength",void 0),t([e()],r.prototype,"onShowPromptCallback",void 0),t([e()],r.prototype,"parseInputValueFunction",void 0),t([e()],r.prototype,"renderFunction",void 0),t([e()],r.prototype,"required",void 0),t([e()],r.prototype,"shouldShowPrompt",null),t([e()],r.prototype,"tableEditingEnabled",void 0),r=t([n("esri.widgets.FeatureTable.Grid.EditorColumn")],r);const s=r;export{s as default};