// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("../../chunks/tslib.es6 ../../core/Logger ../../core/accessorSupport/decorators/property ../../core/has ../../core/RandomLCG ../../core/accessorSupport/decorators/subclass ../../intl/date ../../intl/number ../../layers/support/CodedValue ../../layers/support/CodedValueDomain ../../layers/support/editableLayers ../../layers/support/fieldUtils ../../smartMapping/support/utils ../FeatureForm/FieldInput ./Grid/EditorColumn ../support/dateUtils ../support/widgetUtils".split(" "),function(k,x,l, h,I,A,w,v,B,C,D,p,y,E,F,t,u){const G=w.convertDateFormatToIntlOptions("short-date-short-time"),H=w.convertDateFormatToIntlOptions("short-date"),z={useGrouping:!0,maximumFractionDigits:20};h=class extends F{constructor(b){super(b);this._activeFieldInput=null;this.cellValueFormatFunction=({rowData:a,value:d})=>{var {formatFunction:c}=this;if(c&&a){const {index:f,item:{feature:e}}=a;return c({column:this,feature:e,field:this.field,index:f,value:u.renderingSanitizer.sanitize(d)})}if(null===d)return"\x26nbsp;"; ({field:c}=this);if(a=this._getDomainForFeature(a?.item?.feature)){const f=this._getComputedDomain(d,a);return"date"===c.type&&"range"===a.type?this._formatDateValueForDisplay(c,f):p.isNumericField(c)&&"range"===a.type?(c=(c=this.template?.format)?v.convertNumberFormatToIntlOptions(c):z,v.formatNumber(parseFloat(d),c)):t.dateFieldsWithStringFieldValue.has(c.type)?"range"===a.type?u.renderingSanitizer.sanitize(t.getLabelForDateFieldValue(c,f)):u.renderingSanitizer.sanitize(f):f}return"date"===c.type|| t.dateFieldsWithStringFieldValue.has(c.type)?this._formatDateValueForDisplay(c,d):p.isNumericField(c)?(c=(c=this.template?.format)?v.convertNumberFormatToIntlOptions(c):z,v.formatNumber(parseFloat(d),c)):u.renderingSanitizer.sanitize(d)};this.cellValueValidatorFunction=({oldValue:a,value:d})=>{const {field:c}=this;return!this.effectiveRequired||null!=d&&""!==d?p.isNumericField(c)&&p.validateFieldValue(c,d)?(x.getLogger(this).warn("value-exceeds-valid-range","Field value exceeds valid range. Attempted edit was rejected."), !1):this._isAnyDateOrTimeField&&!t.dateTimeIsInRange({type:c.type,range:this._effectiveRange,value:d})?!1:a!==d:!1};this.formatFunction=this.field=this.expressionInfos=null;this.inputRenderFunction=({root:a,column:d,rowData:c})=>{if(!this.editInfo&&this.effectiveEditable){var f=this.getCellValue(d,c),{field:e}=this;if("big-integer"===e.type&&p.validateFieldValue(e,f))x.getLogger(this).warn("value-exceeds-valid-range","Field value is beyond supported limit. Editing is disabled for this field value."); else if(e=c?.item.feature){this._activeFieldInput=this._setUpFieldInput(e,f);e=document.createElement("div");e.classList.add("esri-column__cell__input-container");var g=[],n="coded-value"===this._effectiveDomain?.type;if(this._isAnyDateOrTimeField&&!n){const q=document.createElement("div");n=this._setUpDateComponents(f);const r=this._setUpDateActionBar();n.forEach(m=>q.appendChild(m));e.appendChild(q);e.appendChild(r);g.push(...n)}else n=this.createInputElement({root:a,column:d,rowData:c,value:f}), e.appendChild(n),g.push(n);this._set("editInfo",{column:d,inputs:g,root:a,rowData:c,oldValue:f});this.removeCellContent(a);a.appendChild(e);this._syncRowEditingState(a,!0);this.grid?.generateCellPartNames();if(a=g[0])a.focus(),a instanceof HTMLInputElement&&a.select()}}};this.layer=null;this.parseInputValueFunction=({inputs:a})=>{const {editInfo:d,field:c,includeTime:f}=this;if(!d||!a.length)return null;var e=a[0];if(this._isAnyDateOrTimeField){var g=d.oldValue??void 0;if("coded-value"===this._effectiveDomain?.type)return null!= e.value?parseFloat(e.value):null;switch(c.type){case "date-only":return e=e.value,""!==e?e:null;case "time-only":return e=t.normalizeTimeOnlyString(e.value),""!==e?e:null;case "timestamp-offset":const n=f?a[1]:void 0;a=a.at(-1);return t.getISOFieldValueFromDateComponents({oldValue:g,dateComponent:e,timeComponent:n,timeZoneComponent:a,defaultTimeZone:this.timeZone});case "date":const {max:q,min:r}=this._effectiveRange;return t.getUnixFieldValueFromDateComponents({oldValue:g,dateComponent:e,timeComponent:a[1], timeZone:this.timeZone??void 0,max:q,min:r})}return null}e=e.value;({effectiveRequired:g}=this);return g||""!==e?p.isNumericField(c)?parseFloat(e):p.isStringField(c)?e.trim():e:null};this.sortable=!0;this.template=this.store=null;this.updateRowItemFunction=({rowData:a,column:d,value:c})=>{a&&d.path&&(a.item.feature.attributes[d.path]=c)};this.updateStoreItemFunction=async({rowData:a,column:d,value:c})=>{if(a&&this.store&&d.path){var f=this.store.getItemIndexByObjectId(a.item.objectId);await this.store.updateItem({index:-1< f?f:a.index,name:d.path,value:c})}}}get _effectiveDomain(){const b=this._activeFieldInput?.feature;return b?this._getDomainForFeature(b):null}get _effectiveRange(){return this._activeFieldInput?.range??{max:null,min:null}}get _isAnyDateOrTimeField(){const {field:b}=this;return y.isAnyDateField(b)||p.isTimeOnlyField(b)}get alias(){return this.field?.alias}get defaultValue(){return this.field?.defaultValue}get description(){return this.template?.description??this.field?.description??null}get effectiveEditable(){const {editable:b, field:a,layer:d,tableEditingEnabled:c}=this;if(null==a||null==d)return!1;const f=D.isEditableLayer(d),e=d.effectiveCapabilities??d.capabilities;return a.editable&&f&&e?.operations?.supportsUpdate&&"oid"!==a.type&&c?b:!1}get effectiveLabel(){return u.renderingSanitizer.sanitize(this.label||this.alias||this.fieldName)}get effectiveRequired(){return!this.nullable||this._activeFieldInput?.required||this.required}get includeTime(){const {field:b,template:a}=this;return"time-only"===b.type?!0:"date-only"=== b.type?!1:!a?.input||"includeTime"in a.input&&!1!==a.input.includeTime}get loadingMessage(){return this.messages?.loading||"..."}get maxLength(){const {field:b,template:a}=this,d=b?.length??-1,c=a?.input&&"maxLength"in a.input?a.input.maxLength:null;return null!=c&&!isNaN(c)&&-1<=c&&(-1===d||c<=d)?c:d}get minLength(){const {template:b,maxLength:a}=this,d=b?.input&&"minLength"in b.input?b.input.minLength:null;return a&&d<=a?d:null}get name(){return this.field?.name}get nullable(){return!1!==this.field.nullable}createInputElement({value:b}){const {_effectiveDomain:a, field:d,maxLength:c,minLength:f,effectiveRequired:e}=this;let g;"coded-value"===a?.type?(g=this._createSelectElement(b,a.codedValues.map(({code:r,name:m})=>({value:r,name:m})),e),g.onchange=()=>{g.onblur=null;q()}):(g=document.createElement("input"),g.type=p.isNumericField(d)?"number":"text",-1{n="Escape"===r.key};g.onblur=()=>{g.onblur=null;q()};const q=()=>{n?this.cancel(): this.submit()};return g}getCellValue({path:b},a){return b&&a?.item?.feature?.attributes?a.item.feature.attributes?.[b]:null}onEditComplete(){const b=this.editInfo?.root;b&&this._syncRowEditingState(b,!1);this._activeFieldInput=null;super.onEditComplete()}_clearActiveEditValues(){this.editInfo?.inputs?.forEach(b=>b.value="")}_setUpDateActionBar(){var {messagesCommon:b}=this;const a=b?.cancel??"",d=b?.clear??"";b=b?.save??"";const c=document.createElement("calcite-action-bar");c.expandDisabled=!0;c.layout= "horizontal";c.appendChild(this.createCalciteAction({text:b,icon:"save",onclick:()=>this.submit()}));this.effectiveRequired||c.appendChild(this.createCalciteAction({text:d,icon:"trash",onclick:()=>{this._clearActiveEditValues();this.submit()}}));c.appendChild(this.createCalciteAction({text:a,icon:"x",onclick:()=>this.cancel()}));return c}_formatDateValueForDisplay(b,a){const {timeZone:d,timeZoneName:c}=this;return null!=a?t.getLabelForDateFieldValue(b,a,{...this._getDateFormatOptions(),timeZone:d?? void 0,timeZoneName:c??void 0}):null}_setUpDateComponents(b){const {_effectiveRange:{max:a,min:d,rawMax:c,rawMin:f},field:e,effectiveRequired:g}=this;b=this._getDateFieldValuesForComponents(e,b);const n=[];if(y.isAnyDateField(e)){const m=this.createDateComponent();var q=p.isDateOnlyField(e)||p.isTimestampOffsetField(e)?c:a,r=p.isDateOnlyField(e)||p.isTimestampOffsetField(e)?f:d;q=this._getDateFieldValuesForComponents(e,q??null);r=this._getDateFieldValuesForComponents(e,r??null);m.value=b.date??""; m.max=q.date??"";m.min=r.date??"";m.required=g;m.addEventListener("calciteInputDatePickerOpen",()=>this._onDateComponentOpen(m));n.push(m)}if(this.includeTime){const m=this.createTimeComponent();m.value=b.time??"";m.required=g;m.addEventListener("calciteInputTimePickerOpen",()=>this._onDateComponentOpen(m));n.push(m)}if("timestamp-offset"===e.type){const m=this.createTimeZoneComponent();m.value=b.timeZoneOffset??"0";m.addEventListener("calciteInputTimeZoneOpen",()=>this._onDateComponentOpen(m));n.push(m)}return n}_onDateComponentOpen(b){this.editInfo?.inputs.forEach(a=> {a!==b&&"open"in a&&(a.open=!1)})}_syncRowEditingState(b,a=!1){(b=this.grid?.getRowContainingNode(b))&&(a?b.setAttribute("editing","true"):b.removeAttribute("editing"))}_getDateFieldValuesForComponents(b,a){switch(b.type){case "date":return t.prepareUnixFieldValueForDateComponents(a,this.timeZone??void 0);case "date-only":return{date:a};case "time-only":return{time:a};case "timestamp-offset":return t.prepareISOFieldValueForDateComponents(a);default:return{}}}_createSelectElement(b,a,d=!1){let c=!1; a=a.map(e=>{e.value===b&&(c=!0);const g=document.createElement("option");g.text=e.name;g.value=e.value;return g});if(null!=b&&""!==b&&!c){const e=document.createElement("option");e.text=b;e.value=b;a.unshift(e)}d||null!=b||(d=document.createElement("option"),d.value="",a.unshift(d));const f=document.createElement("select");a.forEach(e=>f.add(e));f.value=b;return f}_setUpFieldInput(b,a){const {field:d,layer:c,timeZone:f}=this;b=new E({feature:b,field:d,initialFeature:b.clone(),layer:c,timeZone:f}); b.set("value",a);return b}_isDomainCompatible(b){const {field:a}=this;if(b&&"coded-value"===b.type){const d=typeof b.codedValues[0].code;if("string"===d&&p.isStringField(a)||"number"===d&&p.isNumericField(a))return!0}return b&&"range"===b.type&&p.isNumericField(a)?!0:!1}_getDomainForFeature(b){const {layer:a,name:d,template:c}=this;if(!b||!a?.getFieldDomain||"wfs"===a.type||"geojson"===a.type||"csv"===a.type||"knowledge-graph-sublayer"===a.type)return null;if(c?.domain&&this._isDomainCompatible(c.domain))return c.domain; const {typeIdField:f}=a,e=this.field.domain;return f!==d||e?f&&null!=d&&a.getFieldDomain(d,{feature:b})||e:new C({name:"__internal-type-based-coded-value-domain__",codedValues:a.types?.map(({id:g,name:n})=>new B.CodedValue({code:g,name:n}))})}_getComputedDomain(b,a){return a?"range"===a.type?b:"coded-value"===a.type?(a=a.codedValues.filter(d=>d.hasOwnProperty("code")&&d.code===b))&&a.length?a[0].name:b:null:null}_getDateFormatOptions(){const {template:b}=this,a=b?.format?.dateFormat;return a?w.convertDateFormatToIntlOptions(a): b?.input&&"includeTime"in b.input&&!1===b.input.includeTime?H:G}};k.__decorate([l.property()],h.prototype,"_effectiveDomain",null);k.__decorate([l.property()],h.prototype,"_activeFieldInput",void 0);k.__decorate([l.property()],h.prototype,"_effectiveRange",null);k.__decorate([l.property()],h.prototype,"_isAnyDateOrTimeField",null);k.__decorate([l.property({readOnly:!0})],h.prototype,"alias",null);k.__decorate([l.property()],h.prototype,"cellValueFormatFunction",void 0);k.__decorate([l.property()], h.prototype,"cellValueValidatorFunction",void 0);k.__decorate([l.property({readOnly:!0})],h.prototype,"defaultValue",null);k.__decorate([l.property({readOnly:!0})],h.prototype,"description",null);k.__decorate([l.property()],h.prototype,"effectiveEditable",null);k.__decorate([l.property()],h.prototype,"effectiveLabel",null);k.__decorate([l.property()],h.prototype,"effectiveRequired",null);k.__decorate([l.property()],h.prototype,"expressionInfos",void 0);k.__decorate([l.property()],h.prototype,"field", void 0);k.__decorate([l.property()],h.prototype,"formatFunction",void 0);k.__decorate([l.property()],h.prototype,"includeTime",null);k.__decorate([l.property()],h.prototype,"inputRenderFunction",void 0);k.__decorate([l.property()],h.prototype,"layer",void 0);k.__decorate([l.property({readOnly:!0})],h.prototype,"loadingMessage",null);k.__decorate([l.property()],h.prototype,"maxLength",null);k.__decorate([l.property()],h.prototype,"minLength",null);k.__decorate([l.property({readOnly:!0})],h.prototype, "name",null);k.__decorate([l.property({readOnly:!0})],h.prototype,"nullable",null);k.__decorate([l.property()],h.prototype,"parseInputValueFunction",void 0);k.__decorate([l.property()],h.prototype,"sortable",void 0);k.__decorate([l.property()],h.prototype,"store",void 0);k.__decorate([l.property()],h.prototype,"template",void 0);k.__decorate([l.property()],h.prototype,"updateRowItemFunction",void 0);k.__decorate([l.property()],h.prototype,"updateStoreItemFunction",void 0);return h=k.__decorate([A.subclass("esri.widgets.FeatureTable.FieldColumn")], h)});