@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 11.3 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../core/Error.js";import{watch as i,sync as l}from"../../core/reactiveUtils.js";import{property as n,subclass as r}from"../../core/accessorSupport/decorators.js";import{getEffectiveFieldAlias as s}from"../../editing/fieldUtils.js";import{getDomainRange as u,dateTimeFieldValuesToNumericRange as a,validateDomainValue as o}from"../../layers/support/domainUtils.js";import{isFieldVisibleByDefault as p,getLowerCaseEditTrackingFields as d,isNumericField as m,isStringField as h,isTimeOnlyField as f,getFieldRange as y}from"../../layers/support/fieldUtils.js";import{isAnyDateField as c}from"../../smartMapping/support/utils.js";import{isNumber as g}from"../../support/guards.js";import{isRelatableFeatureSupportedLayer as x}from"../Feature/support/featureUtils.js";import v from"./EditableInput.js";import{isFieldElementWithInputType as E,valueIsInvalidSwitchValue as b,isFieldElementWithShowNoValueOptionInput as _}from"./featureFormUtils.js";import{timeResolutionToStepMap as V,isArcadeDate as T,arcadeDateToFieldValue as w}from"../support/dateUtils.js";import{dateIsValid as F,getMaxLength as D,getMinLength as L,validateFormValue as M}from"../support/forms/formUtils.js";let O=class extends v{constructor(e){super(e),this._storedValue=null,this.error=null,this.preservesValueWhenHidden=!0,this.field=null,this.group=null,this.requiredExpressionExecutor=null,this.type="field",this._fieldInputWasVisibleDuringLifetime=!1,this.valueExpressionExecutor=null}initialize(){this.addHandles(i(()=>this.feature,()=>this._fieldInputWasVisibleDuringLifetime=!1,l))}get _dateFormRange(){const{element:e,field:t}=this;if("date"!==this.dataType)return{};const i=e?.domain?u(t,e.domain):null;if(!e?.input)return i??{};const l=e.input,{type:n}=l;let r={};if("date-picker"!==n&&"time-picker"!==n&&"datetimeoffset-picker"!==n||(r=a(t,l.max,l.min)),"datetime-picker"===n){const{max:e,min:t}=l;r={max:null!=e&&F(e)?e.getTime():null,min:null!=t&&F(t)?t.getTime():null}}const{max:s,min:o}=r;if(i){const{max:e,min:t}=i,l=g(e)&&(null==s||null!=s&&e<s),n=g(t)&&(null==o||null!=o&&t>o);return{max:l?e:s??null,min:n?t:o??null,rawMax:l?i.rawMax:r?.rawMax??null,rawMin:n?i.rawMin:r?.rawMin??null}}return{min:o,max:s,rawMax:r?.rawMax??null,rawMin:r?.rawMin??null}}get _dateRange(){const{_dateFormRange:e,field:t}=this;if("date"!==this.dataType)return{};const i=u(t);if(!i)return e;const{max:l,min:n,rawMax:r,rawMin:s}=e;if("date"===t.type){const{max:e,min:t}=i;return{max:g(l)&&(null===e||null!=e&&l<e)?l:e??null,min:g(n)&&(null===t||null!=t&&n>t)?n:t??null}}if("date-only"===t.type||"time-only"===t.type||"timestamp-offset"===t.type){const{max:e,min:t,rawMax:u,rawMin:a}=i,o=g(l)&&r&&(null==e||l<e),p=g(n)&&s&&(null==t||n>t);return{max:o?l:e,min:p?n:t,rawMax:o?r:u,rawMin:p?s:a}}return{max:null,min:null}}get _configAllowsEdits(){const{element:e,layer:t,name:i}=this;if(null!=e)return e.editableExpression?!!this.evaluatedEditableExpression:!1!==e.editable;if(t?.userHasUpdateItemPrivileges)return!0;const l=t&&"popupTemplate"in t?t?.popupTemplate?.fieldInfos?.find(({fieldName:e})=>e===i):null;return l?.isEditable??!0}get _layerAndFieldAllowEdits(){return this.layerAllowsEdits&&this.field?.editable}get _isVisibleByDefault(){const{field:e,layer:t}=this;return!!e?.visible&&p(e,t)}get _isEditTrackingField(){return d(this.layer).includes(this.name?.toLowerCase())}get _shouldUseValueExpression(){return this._layerAndFieldAllowEdits&&!this._configAllowsEdits&&null!=this.valueExpressionExecutor&&this.valueExpressionExecutor.initialExecutionComplete}get isSubtypeField(){const{layer:e}=this;if(e&&"subtypeField"in e){const{subtypeField:t,fieldsIndex:i}=e;return(i.get(t)?.name??t)===this.name}return!1}get valueIsOutOfDomain(){const{domain:e,value:t,field:i}=this;return!(!e||null==t)&&null!==o(i,t,e)}get alias(){return s(this.field,this.layer)}get dataType(){const{field:e}=this;return m(e)?"number":h(e)?"text":c(e)||f(e)?"date":"unsupported"}get dateDataType(){if("date"===this.dataType)return"date"!==this.field.type?"string":"number"}get domain(){const{layer:e,feature:t,name:i,element:l}=this,n=l?.domain;return null!=n&&this._isDomainCompatible(n)?n:e.getFieldDomain(i,{feature:t})}get editable(){return!!this._layerAndFieldAllowEdits&&(this.evaluatedEditableExpression??this._configAllowsEdits)}get evaluatedRequiredExpression(){const{requiredExpressionExecutor:e}=this;return null!=e?!!e.lastEvaluatedValue:null}get evaluatedValueExpression(){const{valueExpressionExecutor:e}=this;return null!=e?e.lastEvaluatedValue:null}get hint(){return this.element?.hint}get includeDate(){return!("date"!==this.dataType||"time-only"===this.field.type)}get includeTime(){const{element:e,field:t}=this;if("date"!==this.dataType)return!1;if("time-only"===t.type)return!0;if("date-only"===t.type)return!1;const i="datetime-picker"===e?.input?.type?e.input.includeTime:void 0;return void 0===i||i}get includeTimeOffset(){if("timestamp-offset"!==this.field.type)return!1;const e=this.element?.input;return!e||"datetimeoffset-picker"===e.type&&e.includeTimeOffset}set initialFeature(e){this._set("initialFeature",e),this.notifyChange("valid")}get inputType(){return this.element?.input?.type}get hasInvalidSwitchValue(){const{element:e}=this,t=E(e,"switch")?e.input:null;return!t||b(this.value,t)}get isRelationshipKeyField(){const{field:e,layer:t}=this;return x(t)&&!!t.relationships?.some(t=>t.keyField===e.name)}get label(){return this.getFormattedLabel(this.element?.label)||this.alias||this.field.name}get maxLength(){return D({dataType:this.dataType,field:this.field,input:this.element?.input})}get minLength(){return L({dataType:this.dataType,field:this.field,input:this.element?.input})}get name(){return this.field?.name}get range(){const{domain:e,element:t,field:i}=this;if("date"===this.dataType)return this._dateRange;const l=u(i,e)||y(i,e),n=l?.max===Number.MAX_VALUE?null:l?.max??null,r=l?.min===-Number.MAX_VALUE?null:l?.min??null;if(!t?.domain||"range"!==t.domain.type)return{max:n,min:r};const{max:s,min:a}=u(i)||{};return{max:null!=s&&(null===n||null!=n&&s<n)?s:n,min:null!=a&&(null===r||null!=r&&a>r)?a:r}}get required(){const{editable:e,evaluatedRequiredExpression:t,field:i,visible:l,isSubtypeField:n}=this;if(!e)return!1;if(!1===i?.nullable)return!0;if(n)return!0;return!(!l||!1===this.group?.visible||null==t)&&t}set required(e){this._overrideIfSome("required",e)}get showNoValueOptionEnabled(){const{element:e}=this;return!this.required&&(!_(e)||e.input.showNoValueOption)}get showNoValueLabel(){const{element:e}=this;return _(e)?e.input.noValueOptionLabel:null}get submittable(){const{field:e,required:t,valid:i,value:l}=this;return(!t||null!=l)&&(!!i||this.initialFeature.getAttribute(e.name)===l)}get timeResolution(){const e=this.element?.input;if(e&&("datetimeoffset-picker"===e.type||"time-picker"===e.type))return e.timeResolution??"minutes"}get timeStep(){return null!=this.timeResolution?V.get(this.timeResolution):void 0}get updating(){const{editableExpressionExecutor:e,valueExpressionExecutor:t,visibilityExpressionExecutor:i,preservesValueWhenHidden:l}=this;return null!=t&&t.updating||null!=e&&e.updating||!1===l&&null!=i&&i.updating}get valid(){const e=this.editable?this._validate():null;return this._set("error",e),null===e}get value(){if(this._fieldInputWasVisibleDuringLifetime=this._fieldInputWasVisibleDuringLifetime||this.visible&&!1!==this.group?.visible,!1===this.preservesValueWhenHidden&&this._fieldInputWasVisibleDuringLifetime&&(!1===this.visibilityExpressionExecutor?.lastEvaluatedValue||!1===this.group?.visibilityExpressionExecutor?.lastEvaluatedValue))return null!==this._storedValue&&this.set("_storedValue",null),null;if(this._shouldUseValueExpression){const e=this.evaluatedValueExpression;return"date"===this.dataType?this._arcadeOutputToDateFieldValue(e):null!=e&&"object"==typeof e?`${e}`:e}return this._storedValue}set value(e){this.notifyChange("evaluatedVisibilityExpression"),this.set("_storedValue",e),this.notifyChange("value"),this.notifyChange("valid")}get visible(){return!this._isEditTrackingField&&(null!=this.evaluatedVisibilityExpression?this.evaluatedVisibilityExpression:null!=this.element&&!1!==this.field?.visible||this._isVisibleByDefault)}_arcadeOutputToDateFieldValue(e){const i=this.field.type;try{if("object"==typeof e){if(null===e)return null;if(T(e))return w(e,i);if("getTime"in e&&"function"==typeof e.getTime&&"date"===i)return parseInt(e.getTime(),10);if("date-only"===i||"time-only"===i||"timestamp-offset"===i)return e.toString()}else{if("string"==typeof e)return"date"===i?parseInt(e,10):e;if("number"==typeof e&&"date"===i)return e}throw new t("feature-form:invalid-date-value","Date value is invalid")}catch{return"date"===i?NaN:""}}_isDomainCompatible(e){const{field:t}=this;if("coded-value"===e?.type){const i=typeof e.codedValues[0].code;if("string"===i&&h(t)||"number"===i&&m(t))return!0}return!!("range"===e?.type&&m(t)||c(t)||f(t))}_validate(){const{dataType:e,domain:t,field:i,minLength:l,range:n,required:r,value:s,maxLength:u}=this;return M(s,{dataType:e,domain:t,field:i,maxLength:u,minLength:l,range:n,required:r})}};e([n()],O.prototype,"_dateFormRange",null),e([n()],O.prototype,"_dateRange",null),e([n()],O.prototype,"_storedValue",void 0),e([n()],O.prototype,"_configAllowsEdits",null),e([n()],O.prototype,"_layerAndFieldAllowEdits",null),e([n()],O.prototype,"_isVisibleByDefault",null),e([n()],O.prototype,"_isEditTrackingField",null),e([n()],O.prototype,"_shouldUseValueExpression",null),e([n()],O.prototype,"isSubtypeField",null),e([n()],O.prototype,"valueIsOutOfDomain",null),e([n()],O.prototype,"alias",null),e([n()],O.prototype,"dataType",null),e([n()],O.prototype,"dateDataType",null),e([n()],O.prototype,"domain",null),e([n()],O.prototype,"editable",null),e([n({readOnly:!0})],O.prototype,"error",void 0),e([n({constructOnly:!0})],O.prototype,"preservesValueWhenHidden",void 0),e([n()],O.prototype,"evaluatedRequiredExpression",null),e([n()],O.prototype,"evaluatedValueExpression",null),e([n()],O.prototype,"field",void 0),e([n()],O.prototype,"group",void 0),e([n({readOnly:!0})],O.prototype,"hint",null),e([n()],O.prototype,"includeDate",null),e([n()],O.prototype,"includeTime",null),e([n()],O.prototype,"includeTimeOffset",null),e([n()],O.prototype,"initialFeature",null),e([n({readOnly:!0})],O.prototype,"inputType",null),e([n()],O.prototype,"hasInvalidSwitchValue",null),e([n()],O.prototype,"isRelationshipKeyField",null),e([n()],O.prototype,"label",null),e([n()],O.prototype,"maxLength",null),e([n()],O.prototype,"minLength",null),e([n({readOnly:!0})],O.prototype,"name",null),e([n()],O.prototype,"range",null),e([n()],O.prototype,"required",null),e([n()],O.prototype,"requiredExpressionExecutor",void 0),e([n()],O.prototype,"showNoValueOptionEnabled",null),e([n()],O.prototype,"submittable",null),e([n()],O.prototype,"timeResolution",null),e([n()],O.prototype,"timeStep",null),e([n({readOnly:!0})],O.prototype,"type",void 0),e([n()],O.prototype,"updating",null),e([n()],O.prototype,"valid",null),e([n({value:null})],O.prototype,"value",null),e([n()],O.prototype,"valueExpressionExecutor",void 0),e([n()],O.prototype,"visible",null),O=e([r("esri.widgets.FeatureForm.FieldInput")],O);const A=O;export{A as default};