12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{_ as e}from"../../chunks/tslib.es6.js";import{isSome as t}from"../../core/maybe.js";import{watch as n}from"../../core/reactiveUtils.js";import{property as i}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as o}from"../../core/accessorSupport/decorators/subclass.js";import{formatDate as l,convertDateFormatToIntlOptions as r}from"../../intl/date.js";import{convertNumberFormatToIntlOptions as a,formatNumber as s}from"../../intl/number.js";import u from"../../layers/support/CodedValueDomain.js";import{isNumericField as d,isStringField as p}from"../../layers/support/fieldUtils.js";import c from"../FeatureForm/InputField.js";import m from"./Grid/EditorColumn.js";import h from"../support/DatePicker.js";import f from"../support/TimePicker.js";import{renderingSanitizer as g}from"../support/widgetUtils.js";const y={cancelEdit:"Escape"},v={headerContent:"esri-field-column__header-content",headerLabel:"esri-field-column__header-label",input:"esri-field-column__cell-input",inputContainer:"esri-field-column__cell__input-container",dateInputContainer:"esri-field-column__cell__date-input-container",dateInputWrapper:"esri-field-column__cell__date-input-wrapper",button:"esri-field-column__button",saveIcon:"esri-icon-save",trashIcon:"esri-icon-trash",locked:"esri-icon-locked"},b=r("short-date-short-time"),_=r("short-date"),F={useGrouping:!0,maximumFractionDigits:20};let C=class extends m{constructor(e){super(e),this._inputField=null,this.cellValueFormatFunction=({rowData:e,value:t})=>{if(this.formatFunction){const{config:e,field:n}=this;return this.formatFunction({config:e,field:n,value:g.sanitize(t)})}if(null===t)return" ";const{config:n,field:i}=this,{item:{feature:o}}=e,r=this._getDomainForFeature(o);if(r)return this._getComputedDomain(t,r);if("date"===i.type){const e=this._getDateFormatOptions(),n="feature"===this.layer?.type&&this.layer.datesInUnknownTimezone?{timeZone:"UTC"}:null;return t?l(t,{...e,...n}):null}if(d(i)){const e=n?.format?a(n.format):F;return s(parseFloat(t),e)}return g.sanitize(t)},this.cellValueValidatorFunction=({oldValue:e,value:n})=>!(this._inputField&&!this._inputField.valid)&&(!(this.required&&(!t(n)||""===n))&&e!==n),this.config=null,this.editingEnabled=!1,this.expressionInfos=null,this.field=null,this.formatFunction=null,this.headerRenderFunction=e=>{const{root:t}=e,{editable:n,editingEnabled:i,headerMenuEnabled:o,sortable:l}=this;if(this.removeCellContent(t),t.classList.add(v.headerContent),i&&!n&&t.appendChild(this.createLockedElement()),l)this.headerSorterRenderFunction(e);else{const{header:e,path:n}=this,i=document.createElement("div");i.classList.add(v.headerLabel),i.innerHTML=e||n,t.appendChild(i)}o&&this.headerMenuRenderFunction(e)},this.inputRenderFunction=({root:e,column:t,rowData:n})=>{if(this.activeEditInfo?.updating)return;if(!this.editable)return;const i=this.getCellValue(t,n),o=this.createInputElement({root:e,column:t,rowData:n,value:i});if(this._set("activeEditInfo",{column:t,input:o,root:e,rowData:n,updating:!0,oldValue:i}),"date"===this.field.type)return void this._renderDateEditors(i,e,o);const l=this.createInputContainer();l.appendChild(o),this.removeCellContent(e),e.appendChild(l),o.focus(),o instanceof HTMLInputElement&&o.select(),this.grid?.notifyResize()},this.layer=null,this.parseInputValueFunction=({input:e})=>{const t=this._inputField,n=e.value,{required:i,type:o}=t;return i||""!==n?"number"===o||"date"===o?parseFloat(n):"text"===o?n.trim():n:null},this.template=null,this.updateRowItemFunction=({rowData:e,column:t,value:n})=>{e.item.feature.attributes[t.path]=n}}get alias(){return this.field?.alias}get defaultValue(){return this.field?.defaultValue}get description(){return this.template?.description??this.config?.description??this.field?.description??null}get editable(){const{config:e,editingEnabled:t,field:n,template:i}=this;return t?!1!==i?.editable&&(!1!==e?.editable&&n?.editable):i?i.editable:!!e&&(!0===e.editable&&n?.editable)}get header(){return this.template?.label||this.config?.label||this.alias||this.path||null}get hidden(){const{config:e}=this;return!1===e?.visible||this._get("hidden")||!1}set hidden(e){this._set("hidden",e)}get loadingMessage(){return this.messages?.loading||"..."}get maxLength(){const{field:e,config:t,template:n}=this,i=e?.length,o=n?.input&&"maxLength"in n.input?n.input.maxLength:t?.maxLength;return!isNaN(o)&&o>=-1&&(-1===i||o<=i)?o:i}get minLength(){const{config:e,template:t,maxLength:n}=this,i=t?.input&&"minLength"in t.input?t.input.minLength:e?.minLength||null;return n&&i<=n?i:null}get name(){return this.field?.name}get nullable(){return this.field?.nullable??!1}get path(){return this.field?.name}get required(){const{config:e,field:t,template:n}=this,i=t?.nullable,o=e?.required,l=n?.required;return this.editable&&(!i||!0===o||!0===l)}get sortable(){return this.template?!1!==this.template?.sortable:!1!==this.config?.sortable}createInputElement({rowData:e,value:t}){const{item:n}=e;if(!n||!n.feature)return null;this._inputField=this._setUpInputField(n.feature,t);const{field:i,maxLength:o,minLength:l,required:r}=this,{domain:a}=this._inputField;let s=null;"coded-value"===a?.type?(s=this._createSelectElement(t,a.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),this._inputField),s.onchange=()=>{s.onblur=null,p()}):(s=document.createElement("input"),s.type=d(i)?"number":"text",o>-1&&(s.maxLength=o),l>0&&(s.minLength=l)),s.classList.add(v.input),s.value=t,s.required=r;let u=!1;s.onkeydown=e=>{u=e.key===y.cancelEdit},s.onblur=()=>{s.onblur=null,p()};const p=()=>{u?this.cancel():this.submit(),this._inputField=null};return s}createInputContainer(){const e=document.createElement("div");return e.classList.add(v.inputContainer),e}createLockedElement(){const e=document.createElement("div");return e.classList.add(v.locked),e}getCellValue({path:e},{item:t}){return t?.feature?.attributes?.[e]??null}_renderDateEditors(e,t,i){const{config:o,messagesCommon:l,template:r}=this,a=e?new Date(e):new Date(Date.now()),s=new h({dateInputEnabled:!0,value:a}),u=new f({value:a});i.value=a.getTime().toString();let d=!e;const p=()=>{d=!0;const e=this._getCombinedDateTime(s.value,u.value);i.value=e.getTime().toString()},c=()=>{d?this.submit():this.cancel()},m=()=>{i.value=null,this.submit()};n((()=>[s.value,u.value]),(()=>p()));const g=document.createElement("div"),y=document.createElement("div");s.container=g,u.container=y;const b=document.createElement("button");b.classList.add(v.button,v.saveIcon),b.onclick=()=>c(),b.title=l?.save;const _=document.createElement("button");_.classList.add(v.button,v.trashIcon),_.onclick=()=>m(),_.title=l?.clear;const F=document.createElement("div");F.classList.add(v.dateInputWrapper),F.appendChild(g),(r&&r.input&&"datetime-picker"===r.input.type&&!1!==r.input.includeTime||o&&!1!==o.includeTime)&&F.appendChild(y);const C=document.createElement("div");C.classList.add(v.dateInputContainer),C.appendChild(F),C.appendChild(b),C.appendChild(_),s.when((()=>this.grid?.notifyResize())),u.when((()=>this.grid?.notifyResize())),this.removeCellContent(t),t.appendChild(C),this.grid?.notifyResize()}_createSelectElement(e,t,n){let i=!1;const o=t.map((t=>{t.value===e&&(i=!0);const n=document.createElement("option");return n.text=t.name,n.value=t.value,n}));if(null!=e&&""!==e&&!i){const t=document.createElement("option");t.text=e,t.value=e,o.unshift(t)}if(!n.required&&null==n.value){const e=document.createElement("option");e.value="",o.unshift(e)}const l=document.createElement("select");return o.forEach((e=>l.add(e))),l.value=e,l}_setUpInputField(e,t){const{config:n,field:i,layer:o}=this,l=new c({config:n,feature:e,initialFeature:e.clone(),field:i,layer:o,group:null,messages:null});return l.set("value",t),l}_isDomainCompatible(e){const{field:t}=this;if(e&&"coded-value"===e.type){const n=typeof e.codedValues[0].code;if("string"===n&&p(t)||"number"===n&&d(t))return!0}return!(!e||"range"!==e.type||!d(t))}_getDomainForFeature(e){const{config:t,layer:n,name:i,template:o}=this;if("wfs"===n.type||"geojson"===n.type||"csv"===n.type)return null;if(o?.domain&&this._isDomainCompatible(o.domain))return o.domain;const{typeIdField:l}=n,r=l===i,a=this.field.domain;if(r&&!a)return new u({name:"__internal-type-based-coded-value-domain__",codedValues:n.types.map((({id:e,name:t})=>({code:e,name:t})))});const s=l&&n.getFieldDomain(i,{feature:e})||a,d=t?.domain;return this._isDomainCompatible(d)?d:s}_getComputedDomain(e,t){if(!t)return null;if("range"===t.type)return e;if("coded-value"===t.type){const n=t.codedValues.filter((t=>t.hasOwnProperty("code")&&t.code===e));return n&&n.length?n[0].name:e}return null}_getCombinedDateTime(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes(),t.getSeconds())}_getDateFormatOptions(){const{config:e,template:t}=this,n=t?.format?.dateFormat||e?.format?.dateFormat;return n?r(n):t&&t.input&&"includeTime"in t.input==!1||!1===e?.includeTime?_:b}};e([i({readOnly:!0})],C.prototype,"alias",null),e([i()],C.prototype,"cellValueFormatFunction",void 0),e([i()],C.prototype,"cellValueValidatorFunction",void 0),e([i()],C.prototype,"config",void 0),e([i({readOnly:!0})],C.prototype,"defaultValue",null),e([i({readOnly:!0})],C.prototype,"description",null),e([i({readOnly:!0})],C.prototype,"editable",null),e([i()],C.prototype,"editingEnabled",void 0),e([i()],C.prototype,"expressionInfos",void 0),e([i()],C.prototype,"field",void 0),e([i()],C.prototype,"formatFunction",void 0),e([i({readOnly:!0})],C.prototype,"header",null),e([i()],C.prototype,"hidden",null),e([i()],C.prototype,"headerRenderFunction",void 0),e([i()],C.prototype,"inputRenderFunction",void 0),e([i()],C.prototype,"layer",void 0),e([i({readOnly:!0})],C.prototype,"loadingMessage",null),e([i()],C.prototype,"maxLength",null),e([i()],C.prototype,"minLength",null),e([i({readOnly:!0})],C.prototype,"name",null),e([i({readOnly:!0})],C.prototype,"nullable",null),e([i()],C.prototype,"parseInputValueFunction",void 0),e([i({readOnly:!0})],C.prototype,"path",null),e([i({readOnly:!0})],C.prototype,"required",null),e([i()],C.prototype,"sortable",null),e([i()],C.prototype,"template",void 0),e([i()],C.prototype,"updateRowItemFunction",void 0),C=e([o("esri.widgets.FeatureTable.FieldColumn")],C);const E=C;export{E as default};
|