UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) • 12.4 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../../../chunks/tslib.es6.js";import{isSome as t}from"../../../core/arrayUtils.js";import{property as i}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import{subclass as r}from"../../../core/accessorSupport/decorators/subclass.js";import{CodedValue as n}from"../../../layers/support/CodedValue.js";import a from"../../../layers/support/CodedValueDomain.js";import"../../../layers/support/Domain.js";import"../../../layers/support/InheritedDomain.js";import s from"../../../layers/support/RangeDomain.js";import{getDomainRange as l,dateTimeFieldValuesToNumericRange as o,isDomainValidForField as u}from"../../../layers/support/domainUtils.js";import{isNumericField as m,isStringField as p,isTimeOnlyField as d,getFieldRange as f,isDateOnlyField as h,isTimestampOffsetField as c}from"../../../layers/support/fieldUtils.js";import{isAnyDateField as y}from"../../../smartMapping/support/utils.js";import{isNumber as g}from"../../../support/guards.js";import{unknown as _,utc as V}from"../../../time/constants.js";import b from"./EditableInput.js";import{MultiFeatureError as x,visibilityCodeToBoolean as v,InputVisibilityCode as E,isFieldInputWithShowNoValueOptionInput as D,differentValuesString as F}from"./support/inputUtils.js";import{FieldInputDataTypes as I,getMaxLength as M,getMinLength as N,isEmptyValue as T,dateIsValid as w,validateFormValue as R}from"../../support/forms/formUtils.js";let S=class extends b{constructor(e){super(e),this.group=null,this.type="field",this.userHasChangedValue=!1,this._hasIntersectionWithElementFieldDomain=!1}get compositeError(){if(this.valid)return null;const{errors:e}=this;if(e.length<this.features.length)return x.DIFFERENT_ERRORS;const t=e[0];for(const i of e)if(i.error!==t.error)return x.DIFFERENT_ERRORS;return t.error}get dataType(){const{field:e}=this;return m(e)?I.Number:p(e)?I.Text:y(e)||d(e)?I.Date:I.Unsupported}get domain(){const e=this._allDomains.toArray();return this.calculateDomain(e)}get distinctValues(){if(this.featuresHaveSameValue)return[this.value];const e=new Set;for(const t of this.features)e.add(t.getAttribute(this.fieldName));return Array.from(e)}get editable(){return!!this.field.editable&&(this._evaluatedEditableExpression??!0)}get effectiveVisible(){return v(this.effectiveVisibilityCode)}get effectiveVisibilityCode(){const{visibilityCode:e}=this;if(e!==E.VISIBLE)return e;const{group:t}=this;if(null==t)return e;const i=t.visibilityCode;return i===E.HIDDEN_VISIBILITY_EXPRESSION_ALL?E.HIDDEN_GROUP_VISIBILITY_EXPRESSION_ALL:i===E.HIDDEN_VISIBILITY_EXPRESSION_SOME?E.HIDDEN_GROUP_VISIBILITY_EXPRESSION_SOME:e}get errors(){return this._validate()}get featuresHaveSameValue(){const{fieldName:e}=this,t=this.features.at(0)?.getAttribute(e);return this.features.every((i=>i.getAttribute(e)===t))}get field(){return this.template.field}get fieldName(){return this.field.name}get invalidFeatures(){return this.errors.map((e=>e.feature))}get isSubtypeField(){return this.layers.some((e=>{if(e&&"subtypeField"in e){const{subtypeField:t,fieldsIndex:i}=e;return(i.get(t)?.name??t)===this.fieldName}return!1}))}get showNoValueOptionEnabled(){const{input:e}=this.template;return!this.required&&(!D(e)||!0===e?.showNoValueOption)}get showNoValueLabel(){const{input:e}=this.template;return D(e)?e?.noValueOptionLabel:null}get includeTime(){const{template:e,field:t}=this;return this.dataType===I.Date&&("time-only"===t.type||"date-only"!==t.type&&("datetime-picker"!==e.input?.type||e.input.includeTime))}get includeTimeOffset(){if("timestamp-offset"!==this.field.type)return!1;const e=this.template.input;return!e||"datetimeoffset-picker"===e.type&&e.includeTimeOffset}get maxLength(){return M({dataType:this.dataType,field:this.field,input:this.template.input})}get minLength(){return N({dataType:this.dataType,field:this.field,input:this.template.input})}get range(){if("date"===this.dataType)return this._dateRange;const{domain:e,field:t}=this;if(e){const i=l(t,e);return{max:i?.max,min:i?.min}}const i=this._allDomains.toArray().every((e=>!e))?f(t):null;return{max:i?.max===Number.MAX_VALUE?null:i?.max??null,min:i?.min===-Number.MAX_VALUE?null:i?.min??null}}get required(){if(!this.editable)return!1;if(!this.field.nullable||this.isSubtypeField)return!0;const e=this.visible&&!1!==this.group?.visible,t=this._evaluatedRequiredExpression;return!(!e||null==t)&&t}get submittable(){return(!this.required||!this.distinctValues.some((e=>T(e))))&&!!this.valid}get valid(){return 0===this.errors.length}get value(){return this.featuresHaveSameValue?this.features.at(0)?.getAttribute(this.fieldName)??null:F}get visibilityCode(){return this.field.visible?this._fieldShouldHaveDomain&&null==this.domain?E.HIDDEN_NO_DOMAIN_IN_COMMON:this._baseVisibilityCode:E.HIDDEN_FIELD_DEFINITION}get effectiveTimeZone(){const e=this.template;let t=e.formTimeZone??"system";return e.layerTimeZone?e.layerTimeZone===_?t=V:e.formTimeZone===_&&(t=e.layerTimeZone):e.formTimeZone===_&&(t=V),t}get codedValueDomainOptions(){return"coded-value"===this.domain?.type?this.domain.codedValues.map((({name:e,code:t})=>({name:e,value:t}))):[]}get codedValueOptions(){const e=this.codedValueDomainOptions,{value:t}=this,i=null==t||t===F||e.some((e=>e.value===t))?[]:[{name:`${t}`,value:t}];return[e,i]}get _evaluatedRequiredExpression(){let e=!1,t=!0;const i=this.template;for(const r of this.features){if(null==i.getExpressionExecutorsForLayer(r.layer)?.requiredExpression)continue;t=!1;const n=this._lookupEvaluatedExpression(r,"required");"success"===n?.status?e=e||!0===n.result:e=!0}return t?null:e}get _allDomains(){const e=this.template.domain;return this.features.map((t=>{const i=t.layer.getFieldDomain(this.fieldName,{feature:t.plainGraphic});return"range"===i?.type||"range"===e?.type?i??this.template.domain:i}))}get _fieldShouldHaveDomain(){return!!this._hasIntersectionWithElementFieldDomain||this._allDomains.some(t)}get _dateFormRange(){if("date"!==this.dataType)return{};const e=this.template.input;if(!e)return{};const{type:t}=e;let i={};if("date-picker"!==t&&"time-picker"!==t&&"datetimeoffset-picker"!==t||(i=o(this.field,e.max,e.min)),"datetime-picker"===t){const{max:t,min:r}=e;i={max:null!=t&&w(t)?t.getTime():null,min:null!=r&&w(r)?r.getTime():null}}return{min:i.min,max:i.max,rawMax:i?.rawMax??null,rawMin:i?.rawMin??null}}get _dateRange(){const{_dateFormRange:e,template:t,field:i,domain:r}=this;if("date"!==this.dataType)return{};if(!r)return this._fieldShouldHaveDomain?{}:e;const n=l(i,r);if(!n)return e;const{max:a,min:s,rawMax:o,rawMin:u}=e,{type:m}=t.field;if("date"===m){const{max:e,min:t}=n;return{max:g(a)&&(null===e||null!=e&&a<=e)?a:e??null,min:g(s)&&(null===t||null!=t&&s>=t)?s:t??null}}if("date-only"===m||"time-only"===m||"timestamp-offset"===m){const{max:e,min:t,rawMax:i,rawMin:r}=n,l=g(a)&&o&&(null==e||a<e),m=g(s)&&u&&(null==t||s>t);return{max:l?a:e,min:m?s:t,rawMax:l?o:i,rawMin:m?u:r}}return{}}async setValueFromUser(e){this.userHasChangedValue=!0;const t=[],i=this.fieldName;for(const r of this.features)r.getAttribute(i)!==e&&t.push(r);this._setValue(e),await this.expressionsManager.valueChanged(i,t)}_setValue(e){const{fieldName:t}=this;for(const i of this.features)i.setAttribute(t,e)}_validate(){const{dataType:e,fieldName:t,maxLength:i,minLength:r,range:n}=this,a=[];for(const s of this.features){const{layer:l}=s,o=l.getField(t)??this.field,u=l.getFieldDomain(t,{feature:s.plainGraphic}),m=this.calculateDomain([u]),p=this._requiredForFeature(s),d=s.getAttribute(t),f=R(d,{dataType:e,domain:m,field:o,maxLength:i,minLength:r,range:n,required:p});f&&a.push({error:f,feature:s.source})}return a}_editableForFeature(e){if(!this.field.editable)return!1;if(null==this.template.getExpressionExecutorsForLayer(e.layer)?.editableExpression)return!0;const t=this._lookupEvaluatedExpression(e,"editable");return"success"===t?.status&&!0===t.result}_effectiveVisibleFeature(e){if(this.group&&!this.group.visibleForFeature(e))return!1;if(null==this.template.getExpressionExecutorsForLayer(e.layer)?.visibilityExpression)return!0;const t=this._lookupEvaluatedExpression(e,"visibility");return"success"===t?.status&&!0===t.result}_requiredForFeature(e){if(!this._editableForFeature(e))return!1;if(!this.field.nullable||this.isSubtypeField)return!0;const t=this._effectiveVisibleFeature(e);if(null==this.template.getExpressionExecutorsForLayer(e.layer)?.requiredExpression)return!1;const i=this._lookupEvaluatedExpression(e,"required");return"success"!==i?.status?t:t&&!0===i.result}calculateDomain(e){const t=e.find((e=>null!=e)),i=this.template.domain;if(!t)return i&&u(this.field,i)?i:null;switch(t.type){case"coded-value":if(e.some((e=>!e))){if(!i)return null;e=e.filter((e=>null!==e))}break;case"range":e=e.filter((e=>null!==e))}if(!e.every((e=>e?.type===t?.type)))return null;let r=null;switch(t?.type){case"range":r=this._intersectRangeDomains(e);break;case"coded-value":r=this._intersectCodedValueDomains(e)}return r}_intersectCodedValueDomains(e){if(!e.length)return null;const t=new Map(e[0].codedValues.map((({code:e,name:t})=>[e,t]))),i=this.template.domain?new Map(this.template.domain.codedValues.map((({code:e,name:t})=>[e,t]))):null;for(const n of e)for(const[e,i]of t){n.codedValues.some((t=>t.code===e&&t.name===i))||t.delete(e)}let r=t;if(i){r=new Map;for(const[e,n]of i)t.has(e)&&r.set(e,n)}const s=Array.from(r.entries()).map((([e,t])=>new n({code:e,name:t})));return s.length?new a({codedValues:s}):null}_intersectRangeDomains(e){if(!e.length)return null;let t=e[0];for(let r=1;r<e.length;r++){if(!t)return null;t=this._findMinMaxValuesBetweenTwoDomains(t,e[r])}if(t&&!u(this.field,t))return null;const{domain:i}=this.template;if(t&&i&&i instanceof s){const e=this._findMinMaxValuesBetweenTwoDomains(t,i);return this._hasIntersectionWithElementFieldDomain=!!e,e}return t}_getMinMaxFromRangeDomain(e){const t=e.minValue,i=e.maxValue,{field:r}=this;return h(r)||d(r)||c(r)?o(r,i,t):{min:null!=t&&"number"==typeof t?t:null,max:null!=i&&"number"==typeof i?i:null}}_findMinMaxValuesBetweenTwoDomains(e,t){const i=new s,r=this._getMinMaxFromRangeDomain(e),n=this._getMinMaxFromRangeDomain(t),{field:a}=this,l=this._getValidRangeValue(r.min,-1/0),o=this._getValidRangeValue(r.max,1/0),u=this._getValidRangeValue(n.min,-1/0),m=this._getValidRangeValue(n.max,1/0);return i.minValue=Math.max(l,u),i.maxValue=Math.min(o,m),i.minValue===-1/0||i.maxValue===1/0||i.minValue>i.maxValue?null:((h(a)||d(a)||c(a))&&(i.minValue=Number(r.min)>Number(n.min)?r.rawMin:n.rawMin,i.maxValue=Number(r.max)<Number(n.max)?r.rawMax:n.rawMax),i.name="intersection",i)}_getValidRangeValue(e,t){return g(e)?e:t}};e([i()],S.prototype,"dataType",null),e([i()],S.prototype,"domain",null),e([i()],S.prototype,"distinctValues",null),e([i()],S.prototype,"editable",null),e([i()],S.prototype,"effectiveVisible",null),e([i()],S.prototype,"effectiveVisibilityCode",null),e([i()],S.prototype,"errors",null),e([i()],S.prototype,"featuresHaveSameValue",null),e([i()],S.prototype,"field",null),e([i()],S.prototype,"fieldName",null),e([i()],S.prototype,"group",void 0),e([i()],S.prototype,"invalidFeatures",null),e([i()],S.prototype,"isSubtypeField",null),e([i()],S.prototype,"showNoValueOptionEnabled",null),e([i()],S.prototype,"showNoValueLabel",null),e([i()],S.prototype,"includeTime",null),e([i()],S.prototype,"includeTimeOffset",null),e([i()],S.prototype,"maxLength",null),e([i()],S.prototype,"minLength",null),e([i()],S.prototype,"range",null),e([i()],S.prototype,"required",null),e([i()],S.prototype,"submittable",null),e([i({readOnly:!0})],S.prototype,"type",void 0),e([i()],S.prototype,"userHasChangedValue",void 0),e([i()],S.prototype,"valid",null),e([i()],S.prototype,"value",null),e([i()],S.prototype,"visibilityCode",null),e([i()],S.prototype,"effectiveTimeZone",null),e([i()],S.prototype,"_evaluatedRequiredExpression",null),e([i()],S.prototype,"_hasIntersectionWithElementFieldDomain",void 0),e([i()],S.prototype,"_allDomains",null),e([i()],S.prototype,"_fieldShouldHaveDomain",null),e([i()],S.prototype,"_dateFormRange",null),e([i()],S.prototype,"_dateRange",null),S=e([r("esri.widgets.BatchAttributeForm.inputs.FieldInput")],S);const L=S;export{L as default};