@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 16.3 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import"../../core/has.js";import t from"../../core/Logger.js";import{on as i,sync as n}from"../../core/reactiveUtils.js";import{property as o,subclass as l}from"../../core/accessorSupport/decorators.js";import{getEffectiveFieldAlias as a}from"../../editing/fieldUtils.js";import{convertDateFormatToIntlOptions as r,defaultFormatterOptionsNoTime as s,convertDateTimeFieldFormatToIntlOptions as u,defaultFormatterOptions as d}from"../../intl/date.js";import{formatNumber as p,convertNumberFormatToIntlOptions as m,convertNumberFieldFormatToIntlOptions as c}from"../../intl/number.js";import{isEditableLayer as h}from"../../layers/support/editableLayers.js";import{computeDomainFromTypes as f}from"../../layers/support/featureLayerUtils.js";import g from"../../layers/support/Field.js";import{defaultFieldFormat as y}from"../../layers/support/fieldFormatUtils.js";import{validateFieldValue as v,isDateField as F,isTimeOnlyField as b,isIntegerField as _,isNumericField as C,isStringField as D,isDateOnlyField as I,isTimestampOffsetField as x}from"../../layers/support/fieldUtils.js";import{isAnyDateField as V}from"../../smartMapping/support/utils.js";import{system as O}from"../../time/constants.js";import{getTimeZoneFormattingOptions as T}from"../../time/timeZoneUtils.js";import w from"../FeatureForm/FieldInput.js";import E from"./Grid/EditorColumn.js";import{isIFeatureTableSupportedLayerWithFieldConfigurations as Z,isEmptyStringOrWhitespace as L}from"./support/tableUtils.js";import{valueIsInRange as j,dateTimeIsInRange as R,getUnixFieldValueFromDateComponents as N,getISOFieldValueFromDateComponents as S,normalizeTimeOnlyString as U,getLabelForDateFieldValue as A,prepareISOFieldValueForDateComponents as q,prepareUnixFieldValueForDateComponents as B}from"../support/dateUtils.js";import{setFocus as H,selectText as k}from"../support/widgetUtils.js";const P={cancelEdit:"Escape"},z=Symbol(),G="esri-column",W={input:`${G}__cell-input`,inputContainer:`${G}__cell__input-container`};let M=class extends E{constructor(e){super(e),this._activeFieldInput=null,this.cellValueFormatFunction=({root:e,rowData:t,value:i})=>{const{formatFunction:n}=this;if(n&&t){const{index:o,item:{attachments:l,feature:a,relatedRecords:r}}=t;return n({attachments:l,column:this,feature:a,field:this.field,index:o,relatedRecords:r,value:this.sanitizeContent(i),virtualIndex:this.getVirtualRowIndex(e)})}if(null===i)return" ";const o=this._getDomainForFeature(t?.item?.feature),l=this._getComputedDomain(i,o)||i;return this._isAnyDateOrTimeField&&"coded-value"!==o?.type?this._formatDateValueForDisplay(this.field,l):this._isNumericField&&"coded-value"!==o?.type?p(parseFloat(l),this._numberFormatOptions):this.sanitizeContent(l)},this.cellValueValidatorFunction=({oldValue:e,value:i})=>{const{_effectiveRange:n,field:o}=this,{max:l,min:a}=n;if(this.effectiveRequired&&(null==i||""===i))return!1;if(this._isNumericField&&(v(o,i)||!j({max:l,min:a,value:i})))return t.getLogger(this).warn("value-exceeds-valid-range","Field value exceeds valid range. Attempted edit was rejected."),!1;if(this._isAnyDateOrTimeField){const e=o.type;if(!R({type:e,range:n,value:i}))return!1}return e!==i},this.field=null,this.formatFunction=null,this.inputRenderFunction=async({root:e,column:i,rowData:n})=>{if(this.editInfo||!this.effectiveEditable||!n)return;const o=n.item.feature,l=o.getObjectId();if(!o||null==l)return;if(this.tableHasInvalidPendingEdits&&!this.itemHasInvalidPendingEdits(l))return void t.getLogger(this).warn("editing-disabled:fix-invalid-pending-edits","Editing is disabled for this row. Table has existing invalid pending edits that must be addressed.");const a=this.getCellValue(n),{field:r}=this;if("big-integer"===r.type&&v(r,a))return void t.getLogger(this).warn("value-exceeds-valid-range","Field value is beyond supported limit. Editing is disabled for this field value.");this._activeFieldInput=this._setUpFieldInput(o,a);const s=document.createElement("div");s.classList.add(W.inputContainer);const u=[],d="coded-value"===this._effectiveDomain?.type;if(this._isAnyDateOrTimeField&&!d){const e=document.createElement("div"),t=this._setUpDateComponents(a),i=this._setUpDateActionBar();t.forEach(t=>e.appendChild(t)),s.appendChild(e),s.appendChild(i),u.push(...t)}else{const e=this.createInputElement({rowData:n,value:a});s.appendChild(e),u.push(e)}this._set("editInfo",{column:i,inputs:u,root:e,rowData:n,oldValue:a}),this.removeCellContent(e),e.appendChild(s),this._syncRowEditingState(e,!0),this.grid?.generateCellPartNames();const p=u[0];await H(p),await k(p)},this.layer=null,this.parseInputValueFunction=({inputs:e})=>{const{editInfo:t,field:i,includeTime:n}=this;if(!t||!e.length)return null;const o=e[0];if(this._isAnyDateOrTimeField){if("coded-value"===this._effectiveDomain?.type){if(null==o.value||""===o.value)return null;const e=String(o.value);return F(i)?parseFloat(e):e}const{timeZone:l}=this.effectiveTimeZoneOptions,a=t.oldValue??void 0;switch(i.type){case"date-only":{const e=o.value;return""!==e?e:null}case"time-only":{const e=U(o.value);return""!==e?e:null}case"timestamp-offset":{const t=n?e[1]:void 0,i=e.at(-1);return S({oldValue:a,dateComponent:o,timeComponent:t,timeZoneComponent:i,defaultTimeZone:l})}case"date":{const{max:t,min:i}=this._effectiveRange;return N({oldValue:a,dateComponent:o,timeComponent:e[1],timeZone:l,max:t,min:i})}}return null}const l=o.value,{effectiveRequired:a}=this;return a||null!=l&&""!==l?this._isNumericField?parseFloat(l):this._isStringField?l.trim():l:null},this.sortable=!0,this.store=null,this.template=null,this.view=null}get _effectiveDomain(){const e=this._activeFieldInput?.feature;return e?this._getDomainForFeature(e):null}get _effectiveRange(){return this._activeFieldInput?.range??{max:null,min:null}}get _isAnyDateOrTimeField(){const{field:e}=this;return V(e)||b(e)}get _isIntegerField(){return _(this.field)}get _isNumericField(){return C(this.field)}get _isStringField(){return D(this.field)}get _isSubtypeField(){const{layer:e}=this;if(e?.subtypeField){const{subtypeField:t,fieldsIndex:i}=e;return(i.get(t)?.name??t)===this.fieldName}return!1}get _layerWithFieldConfigurations(){const{layer:e}=this;return Z(e)?e:null}get _dateTimeFormatOptions(){const{layerFieldConfigurationFormat:e,template:t}=this;return t?.format?.dateFormat?r(t.format.dateFormat):t?.input&&"includeTime"in t.input&&!1===t.input.includeTime?s:"date-time"===e?.type?u(e):this._isAnyDateOrTimeField?d:void 0}get _numberFormatOptions(){const{layerFieldConfigurationFormat:e,template:t}=this;return t?.format?m(t.format):"number"===e?.type?c(e):this._isNumericField?{useGrouping:!0,maximumFractionDigits:20}:void 0}get alias(){return a(this.field,this._layerWithFieldConfigurations)}get defaultValue(){return this.field?.defaultValue}get effectiveDescription(){const{description:e,field:t}=this,i=t.description,n=L(e)?L(i)?null:i:e;return null==n?null:this.sanitizeLabel(n)}get effectiveEditable(){const{editable:e,field:t,layer:i,tableEditingEnabled:n}=this;if(!t||!i)return!1;const o=h(i),l=i.effectiveCapabilities??i.capabilities,a=l?.operations?.supportsUpdate;return!!(t.editable&&o&&a&&"oid"!==t.type&&n)&&e}get effectiveLabel(){return this.sanitizeLabel(this.label||this.alias||this.fieldName)}get effectiveRequired(){return!this.nullable||this._isSubtypeField||this._activeFieldInput?.required||this.required}get effectiveSortable(){return!(!this.layer?.capabilities?.query?.supportsOrderBy||!this.sortable)}get effectiveTimeZoneOptions(){const{layer:e,field:t}=this;if(!e||"date"!==t?.type&&"timestamp-offset"!==t?.type)return{timeZone:void 0,timeZoneName:void 0};const{tableTimeZone:i,timeZone:n,view:o}=this;return T(e.preferredTimeZone||null,!!e.datesInUnknownTimezone,n??i??o?.timeZone??O,this._dateTimeFormatOptions??d,t.type)}get includeTime(){const{field:e,template:t}=this;return"time-only"===e.type||"date-only"!==e.type&&(!t?.input||"includeTime"in t.input&&!1!==t.input.includeTime)}get hasContingentValues(){return!!this.store.fieldsWithContingentValues?.has(this.fieldName)}get layerFieldConfigurationFormat(){const{_layerWithFieldConfigurations:e}=this;if(e)return e.getFieldConfiguration(this.fieldName)?.fieldFormat??y(this.field)}get maxLength(){const{field:e,template:t}=this,i=e?.length??-1,n=t?.input&&"maxLength"in t.input?t.input.maxLength:null;return null!=n&&!isNaN(n)&&n>=-1&&(-1===i||n<=i)?n:i}get minLength(){const{template:e,maxLength:t}=this,i=e?.input&&"minLength"in e.input?e.input.minLength:null;return t&&i<=t?i:null}get name(){return this.field?.name}get nullable(){return!1!==this.field.nullable}get shouldShowPrompt(){return this._isSubtypeField}createInputElement({rowData:e,value:t}){const{_effectiveDomain:o,maxLength:l,minLength:a,effectiveRequired:r}=this;let s;if("coded-value"===o?.type){const o=e.item.feature,l=this.getFieldValueOptions(o,this.fieldName);this.hasContingentValues?(s=this._setUpComboboxComponent(l,t),this.addHandles([i(()=>s,"calciteComboboxChange",()=>this.onInputBlur(),n),i(()=>s,"pointerdown",e=>e.preventDefault(),n)],z)):(s=this.createCalciteSelect(t,l.recommended),this.addHandles(i(()=>s,"calciteSelectChange",()=>this.onInputBlur(),n),z))}else{if(this._isNumericField){const{_effectiveRange:{max:e,min:i}}=this;s=document.createElement("calcite-input"),s.type="number",this._isIntegerField&&(s.step=1),null!=e&&(s.max=e),null!=i&&(s.min=i),s.status=j({max:e,min:i,value:t})?"idle":"invalid"}else s=document.createElement("calcite-input"),this.addHandles(i(()=>s,"calciteInputChange",()=>this.onInputBlur(),n),z),l>-1&&(s.maxLength=l),a>0&&(s.minLength=a);s.value=null!=t?t.toString():""}return s.classList.add(W.input),s.required=r,this.addHandles([i(()=>s,"keydown",e=>{e.key===P.cancelEdit&&this.onInputBlur(!0)},n),i(()=>s,"blur",()=>this.onInputBlur(),n)],z),s}onInputBlur(e=!1){this.removeHandles(z),super.onInputBlur(e)}onEditComplete(){const e=this.editInfo?.root;e&&this._syncRowEditingState(e,!1),this._activeFieldInput=null,super.onEditComplete()}get test(){}_clearActiveEditValues(){this.editInfo?.inputs?.forEach(e=>e.value="")}_setUpDateActionBar(){const{messagesCommon:e}=this,t=e?.cancel??"",i=e?.clear??"",n=e?.save??"",o=document.createElement("calcite-action-bar");return o.expandDisabled=!0,o.layout="horizontal",o.appendChild(this.createCalciteAction({text:n,icon:"save",onclick:()=>this.submit()})),this.effectiveRequired||o.appendChild(this.createCalciteAction({text:i,icon:"trash",onclick:()=>{this._clearActiveEditValues(),this.submit()}})),o.appendChild(this.createCalciteAction({text:t,icon:"x",onclick:()=>this.cancel()})),o}_formatDateValueForDisplay(e,t){const{timeZone:i,timeZoneName:n}=this.effectiveTimeZoneOptions;return null!=t?A(e,t,{...this._dateTimeFormatOptions,timeZone:i,timeZoneName:n}):null}_fieldValueOptionToComboboxItem({disabled:e,name:t,value:i},n){const o=n===i||null==n&&""===i;return this.createCalciteComboboxItem({disabled:e,heading:t,selected:o,value:i})}_setUpComboboxComponent(e,t){const{recommended:i,other:n,unsupported:o}=e,l=this.effectiveRequired,a=this.messages,r=this.createCalciteCombobox({label:this.effectiveLabel,required:l}),s=i.map(e=>this._fieldValueOptionToComboboxItem(e,t));if(!l||null==t||""===t){const e=this._fieldValueOptionToComboboxItem({disabled:l,name:a?.noValue,value:""},t);r.appendChild(e)}if(0===n.length&&0===o.length)return s.forEach(e=>r.appendChild(e)),r;const u=this.createCalciteComboboxItemGroup({label:a.contingentValues.recommended});if(s.forEach(e=>u.appendChild(e)),r.appendChild(u),n.length){const e=this.createCalciteComboboxItemGroup({label:a.contingentValues.other});n.forEach(i=>e.appendChild(this._fieldValueOptionToComboboxItem(i,t))),r.appendChild(e)}if(o.length){const e=this.createCalciteComboboxItemGroup({label:a.subtypes.unsupportedDomainGroupTitle});o.forEach(i=>e.appendChild(this._fieldValueOptionToComboboxItem(i,t))),r.appendChild(e)}return r}_setUpDateComponents(e){const{_effectiveRange:{max:t,min:n,rawMax:o,rawMin:l},field:a,effectiveRequired:r}=this,s=this._getDateFieldValuesForComponents(a,e),u=[];if(V(a)){const e=this.createDateComponent(),d=I(a)||x(a)?o:t,p=I(a)||x(a)?l:n,m=this._getDateFieldValuesForComponents(a,d??null),c=this._getDateFieldValuesForComponents(a,p??null);e.value=s.date??"",e.max=m.date??"",e.min=c.date??"",e.required=r,this.addHandles([i(()=>e,"calciteInputDatePickerOpen",()=>this._onDateComponentOpen(e))],z),u.push(e)}if(this.includeTime){const e=this.createTimeComponent();e.value=s.time??"",e.required=r,this.addHandles([i(()=>e,"calciteInputTimePickerOpen",()=>this._onDateComponentOpen(e))],z),u.push(e)}if("timestamp-offset"===a.type){const e=this.createTimeZoneComponent();e.value=s.timeZoneOffset??"0",this.addHandles([i(()=>e,"calciteInputTimeZoneOpen",()=>this._onDateComponentOpen(e))],z),u.push(e)}return u}_onDateComponentOpen(e){this.editInfo?.inputs.forEach(t=>{t!==e&&"open"in t&&(t.open=!1)})}_syncRowEditingState(e,t=!1){const i=this.grid?.getRowContainingNode(e);i&&(t?i.setAttribute("editing","true"):i.removeAttribute("editing"))}_getDateFieldValuesForComponents(e,t){switch(e.type){case"date":return B(t,this.effectiveTimeZoneOptions.timeZone);case"date-only":return{date:t};case"time-only":return{time:t};case"timestamp-offset":return q(t);default:return{}}}_setUpFieldInput(e,t){const{field:i,layer:n,effectiveTimeZoneOptions:{timeZone:o}}=this,l=new w({feature:e,field:i,initialFeature:e.clone(),layer:n,timeZone:o});return l.set("value",t),l}_isDomainCompatible(e){if(!e)return!1;const{_isNumericField:t,_isStringField:i}=this,{type:n}=e;if("coded-value"===n){const n=typeof e.codedValues[0].code;if("string"===n&&i||"number"===n&&t)return!0}return!("range"!==n||!t)}_getDomainForFeature(e){const{fieldName:t,layer:i,template:n}=this;if(!e||!i?.getFieldDomain)return null;if("wfs"===i.type||"geojson"===i.type||"csv"===i.type)return null;if(n?.domain&&this._isDomainCompatible(n.domain))return n.domain;if("feature"!==i.type&&"subtype-group"!==i.type&&null==i.getField(t)?.domain){const e=f(i,t);if(e)return e}return i.getFieldDomain(t,{feature:e})}_getComputedDomain(e,t){if(!t)return null;if("range"===t.type)return e;if("coded-value"===t.type){const i=t.codedValues.filter(t=>t.hasOwnProperty("code")&&t.code===e);return i&&i.length?i[0].name:e}return null}getFieldValueOptions(e,t){return this.store.getFieldValueOptions({feature:e,fieldName:t,layer:this.layer,emptyString:this.messages?.noValue})}};e([o()],M.prototype,"_effectiveDomain",null),e([o()],M.prototype,"_activeFieldInput",void 0),e([o()],M.prototype,"_effectiveRange",null),e([o()],M.prototype,"_isAnyDateOrTimeField",null),e([o()],M.prototype,"_isIntegerField",null),e([o()],M.prototype,"_isNumericField",null),e([o()],M.prototype,"_isStringField",null),e([o()],M.prototype,"_isSubtypeField",null),e([o()],M.prototype,"_layerWithFieldConfigurations",null),e([o()],M.prototype,"_dateTimeFormatOptions",null),e([o()],M.prototype,"_numberFormatOptions",null),e([o({readOnly:!0})],M.prototype,"alias",null),e([o()],M.prototype,"cellValueFormatFunction",void 0),e([o()],M.prototype,"cellValueValidatorFunction",void 0),e([o({readOnly:!0})],M.prototype,"defaultValue",null),e([o()],M.prototype,"effectiveDescription",null),e([o()],M.prototype,"effectiveEditable",null),e([o()],M.prototype,"effectiveLabel",null),e([o()],M.prototype,"effectiveRequired",null),e([o()],M.prototype,"effectiveSortable",null),e([o()],M.prototype,"effectiveTimeZoneOptions",null),e([o({type:g})],M.prototype,"field",void 0),e([o()],M.prototype,"formatFunction",void 0),e([o()],M.prototype,"includeTime",null),e([o()],M.prototype,"inputRenderFunction",void 0),e([o()],M.prototype,"hasContingentValues",null),e([o()],M.prototype,"layer",void 0),e([o()],M.prototype,"layerFieldConfigurationFormat",null),e([o()],M.prototype,"maxLength",null),e([o()],M.prototype,"minLength",null),e([o({readOnly:!0})],M.prototype,"name",null),e([o({readOnly:!0})],M.prototype,"nullable",null),e([o()],M.prototype,"parseInputValueFunction",void 0),e([o()],M.prototype,"shouldShowPrompt",null),e([o()],M.prototype,"sortable",void 0),e([o()],M.prototype,"store",void 0),e([o()],M.prototype,"template",void 0),e([o()],M.prototype,"view",void 0),M=e([l("esri.widgets.FeatureTable.FieldColumn")],M);const $=M;export{$ as default};