@arcgis/core 4.24.1 → 4.24.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{1872276fb7f434c41c09.js → 1d6f79eae87228ba21c9.js} +1 -1
- package/assets/esri/core/workers/chunks/{dd51b8f77fd9472c2e54.js → 48576ac3dd2efaa25141.js} +1 -1
- package/assets/esri/core/workers/chunks/{b780228a520e1a0b100b.js → 8706454ab4002d4b60f6.js} +1 -1
- package/assets/esri/core/workers/chunks/{de5c5c216a804becdaf6.js → a68428fde8bc960da276.js} +1 -1
- package/assets/esri/core/workers/chunks/{ed1bb19480397d388fe9.js → d1bc85b78d6f217b022a.js} +1 -1
- package/assets/esri/themes/base/widgets/_Editor.scss +6 -0
- package/assets/esri/themes/dark/main.css +1 -1
- package/assets/esri/themes/light/main.css +1 -1
- package/assets/esri/themes/light/view.css +1 -1
- package/chunks/BlendLayers.glsl.js +4 -4
- package/config.js +1 -1
- package/interfaces.d.ts +68 -2
- package/layers/support/FeatureReductionBinning.js +1 -1
- package/package.json +1 -1
- package/support/revision.js +1 -1
- package/symbols/support/previewSymbol2D.js +1 -1
- package/views/2d/layers/features/processors/SymbolProcessor.js +1 -1
- package/views/3d/analysis/Slice/SliceTool.js +1 -1
- package/views/3d/interactive/editingTools/manipulations/MoveXYAxisManipulation.js +1 -1
- package/views/3d/interactive/editingTools/transformGraphic/GraphicScaleRotateTransform.js +1 -1
- package/views/3d/state/utils/navigationUtils.js +1 -1
- package/views/3d/terrain/TerrainSurface.js +1 -1
- package/views/3d/terrain/Tile.js +1 -1
- package/views/3d/terrain/tileUtils.js +1 -1
- package/views/webgl/context-util.js +1 -1
- package/widgets/Editor.js +1 -1
- package/widgets/FeatureForm/FeatureFormViewModel.js +1 -1
- package/widgets/FeatureForm/InputField.js +1 -1
- package/widgets/FeatureForm/InputFieldGroup.js +1 -1
- package/widgets/FeatureForm.js +1 -1
- package/widgets/Legend/LegendViewModel.js +1 -1
- package/widgets/Legend/support/ActiveLayerInfo.js +1 -1
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import t from"../../core/Accessor.js";import{HandleOwnerMixin as i}from"../../core/HandleOwner.js";import{makeHandle as r}from"../../core/handleUtils.js";import{isSome as s,isNone as n,get as o}from"../../core/maybe.js";import{watch as l,syncAndInitial as a}from"../../core/reactiveUtils.js";import{generateUID as u}from"../../core/uid.js";import{property as p}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as d}from"../../core/accessorSupport/decorators/subclass.js";import c from"../../layers/support/CodedValueDomain.js";import"../../layers/support/Domain.js";import"../../layers/support/InheritedDomain.js";import"../../layers/support/RangeDomain.js";import{validateDomainValue as h,DomainValidationError as m,getDomainRange as f}from"../../layers/support/domainUtils.js";import{isNumericField as y,isStringField as g,isDateField as v,TypeValidationError as E,validateFieldValue as x,getFeatureEditFields as b,getFeatureGeometryFields as _,NumericRangeValidationError as F,getFieldRange as T}from"../../layers/support/fieldUtils.js";import{substitute as V}from"../../intl/substitute.js";var U,O;!function(e){e.Text="text",e.Number="number",e.Date="date",e.Unsupported="unsupported"}(U||(U={})),function(e){e.TOO_SHORT="length-validation-error::too-short"}(O||(O={}));const R={type:"number"},j={type:"number",intlOptions:{notation:"scientific"}},D={type:"date",intlOptions:{day:"2-digit",month:"2-digit",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric"}};function A(e){return e>=1e7||e<=-1e7}const w=["editable","required","value","visibility"];let N=class extends(i(t)){constructor(e){super(e),this._storedValue=null,this._expressionTrackingHandles=new Map,this.arcade=null,this.editableFunction=null,this.id=u().toString(),this.requiredFunction=null,this.expressionTrackingProvider={registerExpression:()=>r()},this.valueFunction=null,this.visibilityFunction=null,this.feature=null,this.field=null,this.fieldElement=null,this.layer=null,this.description=null,this.inputType=null,this.error=null,this.group=null,this.hint=null,this.messages=null,this.name=null}initialize(){const e=e=>"value"!==e,t=w.filter(e);this.own(t.map((e=>l((()=>this.get(`${e}Function`)),(t=>{s(t)?this._registerExpressionWithTrackingProvider(e):this._unregisterExpressionWithTrackingProvider(e)}),a))))}get _configAllowsEdits(){const{fieldElement:e,layer:t,name:i}=this;if(s(e))return e.editableExpression?this.evaluatedEditableExpression:!1!==e.editable;return("subtype-group"!==t?.type?t?.popupTemplate?.fieldInfos?.find((({fieldName:e})=>e===i)):null)?.isEditable??!0}get _layerFieldAllowsEdits(){const{field:e,layer:t}=this;return t?.capabilities.operations.supportsEditing&&e?.editable}get isUsingValueExpression(){return this._shouldUseValueExpression()}get evaluatedEditableExpression(){const{editableFunction:e,spatialReference:t}=this;if(n(e))return null;const{arcade:i}=this,r=i.arcadeUtils.getViewInfo({spatialReference:t});return i.arcadeUtils.executeFunction(e,i.arcadeUtils.createExecContext(this.feature,r))}get evaluatedRequiredExpression(){const{requiredFunction:e,spatialReference:t}=this;if(n(e))return null;const{arcade:i}=this,r=i.arcadeUtils.getViewInfo({spatialReference:t});return i.arcadeUtils.executeFunction(e,i.arcadeUtils.createExecContext(this.feature,r))}get evaluatedVisibilityExpression(){const{visibilityFunction:e,spatialReference:t}=this;if(n(e))return null;const{arcade:i}=this,r=i.arcadeUtils.getViewInfo({spatialReference:t});return i.arcadeUtils.executeFunction(e,i.arcadeUtils.createExecContext(this.feature,r))}get evaluatedValueExpression(){const{valueFunction:e,spatialReference:t}=this;if(n(e))return null;const{arcade:i}=this,r=i.arcadeUtils.getViewInfo({spatialReference:t});return i.arcadeUtils.executeFunction(e,i.arcadeUtils.createExecContext(this.feature,r))}set initialFeature(e){this._set("initialFeature",e),this.notifyChange("valid")}get domain(){const{typeIdField:e}=this.layer,t=e===this.name,i=this.field?.domain;if(t&&!i){const{layer:e}=this,t="subtype-group"===e.type?e.sublayers.map((({subtypeCode:e,title:t})=>({id:e,name:t}))):e.types.map((({id:e,name:t})=>({code:e,name:t})));return new c({name:"__internal-type-based-coded-value-domain__",codedValues:t})}const{feature:r}=this,n=e&&this.layer.getFieldDomain(this.name,{feature:r})||i,l=o(this.fieldElement,"domain");return s(l)&&this._isDomainCompatible(l)?l:n}get editable(){return!!this._layerFieldAllowsEdits&&(this.evaluatedEditableExpression??this._configAllowsEdits)}get errorMessage(){return this._toErrorMessage()}get includeTime(){const{fieldElement:e}=this,t=s(e)&&"datetime-picker"===e.input?.type?e.input.includeTime:void 0;return void 0===t||t}get label(){return s(this.fieldElement)&&this.fieldElement.label||this.field.alias||this.field.name}get maxLength(){const e=-1;if(this.type===U.Date)return e;const{field:t,fieldElement:i}=this,r=t?.length,n=s(i)&&k(i.input)?i.input.maxLength:NaN;return!isNaN(n)&&n>=e&&(r===e||n<=r)?n:r}get minLength(){const e=-1;if(this.type===U.Date)return e;const{field:t,fieldElement:i}=this,r=t?.length,n=s(i)&&k(i.input)?i.input.minLength:NaN;return!isNaN(n)&&n>=e&&(r===e||n<=r)?n:e}get required(){return!!this.editable&&(!1===this.field?.nullable||(this.evaluatedRequiredExpression??!1))}get spatialReference(){return this.layer?.spatialReference||null}set spatialReference(e){void 0===e?this._clearOverride("spatialReference"):this._override("spatialReference",e)}get submittable(){const{field:e,required:t,valid:i,value:r}=this;return(!t||!n(r))&&(!!i||this.initialFeature.getAttribute(e.name)===r)}get type(){const{field:e}=this;return y(e)?U.Number:g(e)?U.Text:v(e)?U.Date:U.Unsupported}get valid(){const e=this.editable?this._validate():null;return this._set("error",e),null===e}get value(){if(this._shouldUseValueExpression()){const e=this.evaluatedValueExpression;return this.type===U.Date&&e instanceof Date?e.getTime():s(e)&&"object"==typeof e?e.toString():e}return this.get("_storedValue")}set value(e){this.notifyChange("evaluatedVisibilityExpression"),this.set("_storedValue",e)}get visible(){return!this._isEditorField()&&(s(this.fieldElement)?this.evaluatedVisibilityExpression??!0:this._isVisibleByDefault())}_isDomainCompatible(e){const{field:t}=this;if("coded-value"===e?.type){const i=typeof e.codedValues[0].code;if("string"===i&&g(t)||"number"===i&&y(t))return!0}return!!("range"===e?.type&&y(t)||v(t))}_validate(){const{domain:e,field:t,initialFeature:i,minLength:r,required:s,type:n,valid:o,value:l}=this,a=s&&null===l,u=void 0!==o;return!a&&i.getAttribute(t.name)===l&&u?null:a?E.INVALID_TYPE:"text"===n&&r>-1&&"string"==typeof l&&l.length<r?O.TOO_SHORT:e?null!==l||s?h(e,l):null:x(t,l)}_isVisibleByDefault(){const e=this.field?.type;return"oid"!==e&&"global-id"!==e&&!this._isGeometryField()}_isEditorField(){return b(this.layer).includes(this.name)}_isGeometryField(){return _(this.layer).includes(this.name)}_shouldUseValueExpression(){const e=this._layerFieldAllowsEdits&&!this._configAllowsEdits&&s(this.valueFunction);return e?this._registerExpressionWithTrackingProvider("value"):this._unregisterExpressionWithTrackingProvider("value"),e}_toErrorMessage(){const{domain:e,field:t,messages:i,minLength:r,value:s,required:n,type:o}=this,l=this.error;if(n&&null===s)return i.validationErrors.cannotBeNull;if(l===m.VALUE_OUT_OF_RANGE||l===F.OUT_OF_RANGE){const r=f(e)||T(t);return V(i.validationErrors.outsideRange,r,{format:{max:"date"===o?D:A(r.max)?j:R,min:"date"===o?D:A(r.min)?j:R}})}return l===m.INVALID_CODED_VALUE?i.validationErrors.invalidCodedValue:l===E.INVALID_TYPE?i.validationErrors.invalidType:l===O.TOO_SHORT?V(i.validationErrors.tooShort,{min:r}):null}_registerExpressionWithTrackingProvider(e){const{_expressionTrackingHandles:t}=this;if(t.has(e))return;const i=`evaluated${C(e)}Expression`,r=this.expressionTrackingProvider.registerExpression((()=>this.notifyChange(i)));t.set(e,r)}_unregisterExpressionWithTrackingProvider(e){const{_expressionTrackingHandles:t}=this,i=t.get(e);i&&(i.remove(),t.delete(e))}};function k(e){return!!e&&"maxLength"in e}e([p()],N.prototype,"_storedValue",void 0),e([p()],N.prototype,"_configAllowsEdits",null),e([p()],N.prototype,"_layerFieldAllowsEdits",null),e([p()],N.prototype,"arcade",void 0),e([p()],N.prototype,"editableFunction",void 0),e([p()],N.prototype,"requiredFunction",void 0),e([p()],N.prototype,"expressionTrackingProvider",void 0),e([p()],N.prototype,"valueFunction",void 0),e([p()],N.prototype,"isUsingValueExpression",null),e([p()],N.prototype,"visibilityFunction",void 0),e([p()],N.prototype,"evaluatedEditableExpression",null),e([p()],N.prototype,"evaluatedRequiredExpression",null),e([p()],N.prototype,"evaluatedVisibilityExpression",null),e([p()],N.prototype,"evaluatedValueExpression",null),e([p()],N.prototype,"feature",void 0),e([p()],N.prototype,"field",void 0),e([p()],N.prototype,"fieldElement",void 0),e([p()],N.prototype,"initialFeature",null),e([p()],N.prototype,"layer",void 0),e([p({aliasOf:"fieldElement.description"})],N.prototype,"description",void 0),e([p()],N.prototype,"domain",null),e([p()],N.prototype,"editable",null),e([p({aliasOf:"fieldElement.input.type"})],N.prototype,"inputType",void 0),e([p({readOnly:!0})],N.prototype,"error",void 0),e([p({dependsOn:["error","messages","value"]})],N.prototype,"errorMessage",null),e([p()],N.prototype,"group",void 0),e([p({aliasOf:"fieldElement.hint"})],N.prototype,"hint",void 0),e([p()],N.prototype,"includeTime",null),e([p()],N.prototype,"label",null),e([p()],N.prototype,"maxLength",null),e([p()],N.prototype,"minLength",null),e([p()],N.prototype,"messages",void 0),e([p({aliasOf:"field.name"})],N.prototype,"name",void 0),e([p()],N.prototype,"required",null),e([p()],N.prototype,"spatialReference",null),e([p()],N.prototype,"submittable",null),e([p()],N.prototype,"type",null),e([p()],N.prototype,"valid",null),e([p({value:null})],N.prototype,"value",null),e([p()],N.prototype,"visible",null),N=e([d("esri.widgets.FeatureForm.InputField")],N);const C=e=>e.charAt(0).toUpperCase()+e.slice(1),I=N;export{I as default};
|
|
5
|
+
import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import t from"../../core/Accessor.js";import{HandleOwnerMixin as i}from"../../core/HandleOwner.js";import{isSome as r,isNone as s,get as n}from"../../core/maybe.js";import{watch as o,syncAndInitial as l}from"../../core/reactiveUtils.js";import{generateUID as a}from"../../core/uid.js";import{property as u}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as d}from"../../core/accessorSupport/decorators/subclass.js";import p from"../../layers/support/CodedValueDomain.js";import"../../layers/support/Domain.js";import"../../layers/support/InheritedDomain.js";import"../../layers/support/RangeDomain.js";import{validateDomainValue as c,DomainValidationError as h,getDomainRange as m}from"../../layers/support/domainUtils.js";import{isNumericField as f,isStringField as y,isDateField as g,TypeValidationError as v,validateFieldValue as E,getFeatureEditFields as _,getFeatureGeometryFields as b,NumericRangeValidationError as x,getFieldRange as F}from"../../layers/support/fieldUtils.js";import{substitute as T}from"../../intl/substitute.js";var V,U;!function(e){e.Text="text",e.Number="number",e.Date="date",e.Unsupported="unsupported"}(V||(V={})),function(e){e.TOO_SHORT="length-validation-error::too-short"}(U||(U={}));const O={type:"number"},R={type:"number",intlOptions:{notation:"scientific"}},j={type:"date",intlOptions:{day:"2-digit",month:"2-digit",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric"}};function D(e){return e>=1e7||e<=-1e7}const A=["editable","required","value","visibility"];let w=class extends(i(t)){constructor(e){super(e),this._storedValue=null,this._expressionTrackingHandles=new Map,this.arcade=null,this.editableFunction=null,this.id=a().toString(),this.requiredFunction=null,this.expressionTrackingProvider=null,this.valueFunction=null,this.visibilityFunction=null,this.feature=null,this.field=null,this.fieldElement=null,this.layer=null,this.description=null,this.inputType=null,this.error=null,this.group=null,this.hint=null,this.messages=null,this.name=null}initialize(){const e=e=>"value"!==e,t=A.filter(e);this.own(t.map((e=>o((()=>this.get(`${e}Function`)),(t=>{r(t)?this._registerExpressionWithTrackingProvider(e):this._unregisterExpressionWithTrackingProvider(e)}),l))))}destroy(){for(const e of this._expressionTrackingHandles.values())e.remove()}get _configAllowsEdits(){const{fieldElement:e,layer:t,name:i}=this;if(r(e))return e.editableExpression?this.evaluatedEditableExpression:!1!==e.editable;return("subtype-group"!==t?.type?t?.popupTemplate?.fieldInfos?.find((({fieldName:e})=>e===i)):null)?.isEditable??!0}get _layerFieldAllowsEdits(){const{field:e,layer:t}=this;return t?.capabilities.operations.supportsEditing&&e?.editable}get isUsingValueExpression(){return this._shouldUseValueExpression()}get evaluatedEditableExpression(){const{editableFunction:e,spatialReference:t}=this;if(s(e))return null;const{arcade:i}=this,r=i.arcadeUtils.getViewInfo({spatialReference:t});return i.arcadeUtils.executeFunction(e,i.arcadeUtils.createExecContext(this.feature,r))}get evaluatedRequiredExpression(){const{requiredFunction:e,spatialReference:t}=this;if(s(e))return null;const{arcade:i}=this,r=i.arcadeUtils.getViewInfo({spatialReference:t});return i.arcadeUtils.executeFunction(e,i.arcadeUtils.createExecContext(this.feature,r))}get evaluatedVisibilityExpression(){const{visibilityFunction:e,spatialReference:t}=this;if(s(e))return null;const{arcade:i}=this,r=i.arcadeUtils.getViewInfo({spatialReference:t});return i.arcadeUtils.executeFunction(e,i.arcadeUtils.createExecContext(this.feature,r))}get evaluatedValueExpression(){const{valueFunction:e,spatialReference:t}=this;if(s(e))return null;const{arcade:i}=this,r=i.arcadeUtils.getViewInfo({spatialReference:t});return i.arcadeUtils.executeFunction(e,i.arcadeUtils.createExecContext(this.feature,r))}set initialFeature(e){this._set("initialFeature",e),this.notifyChange("valid")}get domain(){const{typeIdField:e}=this.layer,t=e===this.name,i=this.field?.domain;if(t&&!i){const{layer:e}=this,t="subtype-group"===e.type?e.sublayers.map((({subtypeCode:e,title:t})=>({id:e,name:t}))):e.types.map((({id:e,name:t})=>({code:e,name:t})));return new p({name:"__internal-type-based-coded-value-domain__",codedValues:t})}const{feature:s}=this,o=e&&this.layer.getFieldDomain(this.name,{feature:s})||i,l=n(this.fieldElement,"domain");return r(l)&&this._isDomainCompatible(l)?l:o}get editable(){return!!this._layerFieldAllowsEdits&&(this.evaluatedEditableExpression??this._configAllowsEdits)}get errorMessage(){return this._toErrorMessage()}get includeTime(){const{fieldElement:e}=this,t=r(e)&&"datetime-picker"===e.input?.type?e.input.includeTime:void 0;return void 0===t||t}get label(){return r(this.fieldElement)&&this.fieldElement.label||this.field.alias||this.field.name}get maxLength(){const e=-1;if(this.type===V.Date)return e;const{field:t,fieldElement:i}=this,s=t?.length,n=r(i)&&N(i.input)?i.input.maxLength:NaN;return!isNaN(n)&&n>=e&&(s===e||n<=s)?n:s}get minLength(){const e=-1;if(this.type===V.Date)return e;const{field:t,fieldElement:i}=this,s=t?.length,n=r(i)&&N(i.input)?i.input.minLength:NaN;return!isNaN(n)&&n>=e&&(s===e||n<=s)?n:e}get required(){const{editable:e,evaluatedRequiredExpression:t,field:i,visible:s}=this;return!!e&&(!1===i?.nullable||!(!s||!r(t))&&t)}set required(e){s(e)?this._clearOverride("required"):this._override("required",e)}get spatialReference(){return this.layer?.spatialReference||null}set spatialReference(e){void 0===e?this._clearOverride("spatialReference"):this._override("spatialReference",e)}get submittable(){const{field:e,required:t,valid:i,value:r}=this;return(!t||!s(r))&&(!!i||this.initialFeature.getAttribute(e.name)===r)}get type(){const{field:e}=this;return f(e)?V.Number:y(e)?V.Text:g(e)?V.Date:V.Unsupported}get valid(){const e=this.editable?this._validate():null;return this._set("error",e),null===e}get value(){if(this._shouldUseValueExpression()){const e=this.evaluatedValueExpression;return this.type===V.Date&&e instanceof Date?e.getTime():r(e)&&"object"==typeof e?e.toString():e}return this.get("_storedValue")}set value(e){this.notifyChange("evaluatedVisibilityExpression"),this.set("_storedValue",e)}get visible(){return!this._isEditorField()&&(r(this.fieldElement)?this.evaluatedVisibilityExpression??!0:this._isVisibleByDefault())}_isDomainCompatible(e){const{field:t}=this;if("coded-value"===e?.type){const i=typeof e.codedValues[0].code;if("string"===i&&y(t)||"number"===i&&f(t))return!0}return!!("range"===e?.type&&f(t)||g(t))}_validate(){const{domain:e,field:t,initialFeature:i,minLength:r,required:s,type:n,valid:o,value:l}=this,a=s&&null===l,u=void 0!==o;return!a&&i.getAttribute(t.name)===l&&u?null:a?v.INVALID_TYPE:"text"===n&&r>-1&&"string"==typeof l&&l.length<r?U.TOO_SHORT:e?null!==l||s?c(e,l):null:E(t,l)}_isVisibleByDefault(){const e=this.field?.type;return"oid"!==e&&"global-id"!==e&&!this._isGeometryField()}_isEditorField(){return _(this.layer).includes(this.name)}_isGeometryField(){return b(this.layer).includes(this.name)}_shouldUseValueExpression(){const e=this._layerFieldAllowsEdits&&!this._configAllowsEdits&&r(this.valueFunction);return e?this._registerExpressionWithTrackingProvider("value"):this._unregisterExpressionWithTrackingProvider("value"),e}_toErrorMessage(){const{domain:e,field:t,messages:i,minLength:r,value:s,required:n,type:o}=this,l=this.error;if(n&&null===s)return i.validationErrors.cannotBeNull;if(l===h.VALUE_OUT_OF_RANGE||l===x.OUT_OF_RANGE){const r=m(e)||F(t);return T(i.validationErrors.outsideRange,r,{format:{max:"date"===o?j:D(r.max)?R:O,min:"date"===o?j:D(r.min)?R:O}})}return l===h.INVALID_CODED_VALUE?i.validationErrors.invalidCodedValue:l===v.INVALID_TYPE?i.validationErrors.invalidType:l===U.TOO_SHORT?T(i.validationErrors.tooShort,{min:r}):null}_registerExpressionWithTrackingProvider(e){const{_expressionTrackingHandles:t,expressionTrackingProvider:i}=this;if(s(i)||t.has(e))return;const r=`evaluated${k(e)}Expression`,n=i.registerExpression((()=>this.notifyChange(r)));t.set(e,n)}_unregisterExpressionWithTrackingProvider(e){const{_expressionTrackingHandles:t}=this,i=t.get(e);i&&(i.remove(),t.delete(e))}};function N(e){return!!e&&"maxLength"in e}e([u()],w.prototype,"_storedValue",void 0),e([u()],w.prototype,"_configAllowsEdits",null),e([u()],w.prototype,"_layerFieldAllowsEdits",null),e([u()],w.prototype,"arcade",void 0),e([u()],w.prototype,"editableFunction",void 0),e([u()],w.prototype,"requiredFunction",void 0),e([u()],w.prototype,"expressionTrackingProvider",void 0),e([u()],w.prototype,"valueFunction",void 0),e([u()],w.prototype,"isUsingValueExpression",null),e([u()],w.prototype,"visibilityFunction",void 0),e([u()],w.prototype,"evaluatedEditableExpression",null),e([u()],w.prototype,"evaluatedRequiredExpression",null),e([u()],w.prototype,"evaluatedVisibilityExpression",null),e([u()],w.prototype,"evaluatedValueExpression",null),e([u()],w.prototype,"feature",void 0),e([u()],w.prototype,"field",void 0),e([u()],w.prototype,"fieldElement",void 0),e([u()],w.prototype,"initialFeature",null),e([u()],w.prototype,"layer",void 0),e([u({aliasOf:"fieldElement.description"})],w.prototype,"description",void 0),e([u()],w.prototype,"domain",null),e([u()],w.prototype,"editable",null),e([u({aliasOf:"fieldElement.input.type"})],w.prototype,"inputType",void 0),e([u({readOnly:!0})],w.prototype,"error",void 0),e([u({dependsOn:["error","messages","value"]})],w.prototype,"errorMessage",null),e([u()],w.prototype,"group",void 0),e([u({aliasOf:"fieldElement.hint"})],w.prototype,"hint",void 0),e([u()],w.prototype,"includeTime",null),e([u()],w.prototype,"label",null),e([u()],w.prototype,"maxLength",null),e([u()],w.prototype,"minLength",null),e([u()],w.prototype,"messages",void 0),e([u({aliasOf:"field.name"})],w.prototype,"name",void 0),e([u()],w.prototype,"required",null),e([u()],w.prototype,"spatialReference",null),e([u()],w.prototype,"submittable",null),e([u()],w.prototype,"type",null),e([u()],w.prototype,"valid",null),e([u({value:null})],w.prototype,"value",null),e([u()],w.prototype,"visible",null),w=e([d("esri.widgets.FeatureForm.InputField")],w);const k=e=>e.charAt(0).toUpperCase()+e.slice(1),q=w;export{q as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as i}from"../../chunks/tslib.es6.js";import e from"../../core/Accessor.js";import{HandleOwnerMixin as t}from"../../core/HandleOwner.js";import{
|
|
5
|
+
import{_ as i}from"../../chunks/tslib.es6.js";import e from"../../core/Accessor.js";import{HandleOwnerMixin as t}from"../../core/HandleOwner.js";import{isSome as s,isNone as r,unwrap as o}from"../../core/maybe.js";import{watch as n,syncAndInitial as l,initial as p}from"../../core/reactiveUtils.js";import{aliasOf as a}from"../../core/accessorSupport/decorators/aliasOf.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{property as c}from"../../core/accessorSupport/decorators/property.js";import{subclass as u}from"../../core/accessorSupport/decorators/subclass.js";const d=["visibility"];let h=class extends(t(e)){constructor(i){super(i),this._expressionTrackingHandles=new Map,this.arcade=null,this.visibilityExpression=null,this.description=null,this.expressionTrackingProvider=null,this.feature=null,this.groupElement=null,this.label=null,this.spatialReference=null}initialize(){this.own([...d.map((i=>n((()=>this.get(`${i}Function`)),(e=>{s(e)?this._registerExpressionWithTrackingProvider(i):this._unregisterExpressionWithTrackingProvider(i)}),l))),n((()=>this.visible),(i=>{const{inputFields:e}=this;if(!e||e.length<1)return;const t=!!i&&void 0;for(const s of e)s.required=t}),p)])}destroy(){for(const i of this._expressionTrackingHandles.values())i.remove()}set visibilityFunction(i){this._set("visibilityFunction",i),s(i)?this._registerExpressionWithTrackingProvider("visibility"):this._unregisterExpressionWithTrackingProvider("visibility")}get evaluatedVisibilityExpression(){const{visibilityFunction:i,spatialReference:e}=this;if(r(i))return;const{arcade:t}=this,s=t.arcadeUtils.getViewInfo({spatialReference:o(e)});return t.arcadeUtils.executeFunction(i,t.arcadeUtils.createExecContext(this.feature,s))}get inputFields(){return this._get("inputFields")}set inputFields(i){this.handles.removeAll(),i&&this.handles.add(i.map((i=>n((()=>i.visible),(()=>this._dirtyEvaluatedVisibilityExpression()))))),this._set("inputFields",i)}get state(){return s(this.groupElement)&&this.groupElement.initialState||"expanded"}set state(i){r(i)?this._clearOverride("state"):this._override("state",i)}get visible(){return!1!==this.evaluatedVisibilityExpression&&this.inputFields&&this.inputFields.some((i=>i.visible))}_registerExpressionWithTrackingProvider(i){const{_expressionTrackingHandles:e,expressionTrackingProvider:t}=this;if(r(t)||e.has(i))return;const s=`evaluated${v(i)}Expression`,o=t.registerExpression((()=>this.notifyChange(s)));e.set(i,o)}_unregisterExpressionWithTrackingProvider(i){const{_expressionTrackingHandles:e}=this,t=e.get(i);t&&(t.remove(),e.delete(i))}_dirtyEvaluatedVisibilityExpression(){const{groupElement:i}=this;s(i)&&i.visibilityExpression&&this.notifyChange("evaluatedVisibilityExpression")}};i([c()],h.prototype,"arcade",void 0),i([a("groupElement.visibilityExpression")],h.prototype,"visibilityExpression",void 0),i([c()],h.prototype,"visibilityFunction",null),i([c()],h.prototype,"evaluatedVisibilityExpression",null),i([a("groupElement.description")],h.prototype,"description",void 0),i([c()],h.prototype,"expressionTrackingProvider",void 0),i([c()],h.prototype,"feature",void 0),i([c()],h.prototype,"groupElement",void 0),i([c()],h.prototype,"inputFields",null),i([a("groupElement.label")],h.prototype,"label",void 0),i([c()],h.prototype,"spatialReference",void 0),i([c()],h.prototype,"state",null),i([c()],h.prototype,"visible",null),h=i([u("esri.widgets.FeatureForm.InputFieldGroup")],h);const v=i=>i.charAt(0).toUpperCase()+i.slice(1),g=h;export{g as default};
|
package/widgets/FeatureForm.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{neverReached as t}from"../core/compilerUtils.js";import{isSome as i,isNone as a}from"../core/maybe.js";import{watch as n}from"../core/reactiveUtils.js";import{aliasOf as s}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import"../core/accessorSupport/ensureType.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import{subclass as r}from"../core/accessorSupport/decorators/subclass.js";import{getDomainRange as o}from"../layers/support/domainUtils.js";import{getFieldRange as u}from"../layers/support/fieldUtils.js";import d from"./Widget.js";import p from"./FeatureForm/FeatureFormViewModel.js";import{Heading as c,incrementHeadingLevel as m}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as h}from"./support/decorators/messageBundle.js";import{vmEvent as f}from"./support/decorators/vmEvent.js";import{tsx as _}from"./support/jsxFactory.js";import{DateTime as g}from"luxon";import{getLocale as v}from"../intl/locale.js";const b={base:"esri-feature-form",form:"esri-feature-form__form",formHeader:"esri-feature-form__form-header",label:"esri-feature-form__label",inputField:"esri-feature-form__input",inputDate:"esri-feature-form__input--date",inputTime:"esri-feature-form__input--time",inputRadioGroup:"esri-feature-form__input--radio-group",inputRadio:"esri-feature-form__input--radio",inputRadioLabel:"esri-feature-form__input--radio-label",inputDisabled:"esri-feature-form__input--disabled",inputSwitch:"esri-feature-form__input--switch",inputInvalid:"esri-feature-form__input--invalid",inputIconInvalid:"esri-feature-form__input-icon--invalid",errorMessage:"esri-feature-form__field-error-message",description:"esri-feature-form__description-text",dateInputPart:"esri-feature-form__date-input-part",loneDateInputPart:"esri-feature-form__date-input-part--lone",dateInputContainer:"esri-feature-form__date-input-container",dateFormatHint:"esri-feature-form__date-format-hint",group:"esri-feature-form__group",groupLabel:"esri-feature-form__group-label",groupHeader:"esri-feature-form__group-header",groupHeading:"esri-feature-form__group-header",groupTitle:"esri-feature-form__group-title",groupDescription:"esri-feature-form__group-description",groupToggleIcon:"esri-feature-form__group-toggle-icon",groupCollapsed:"esri-feature-form__group--collapsed",groupSequential:"esri-feature-form__group--sequential",groupActive:"esri-feature-form__group--active",collapseIcon:"esri-icon-up",errorIcon:"esri-icon-notice-triangle",expandIcon:"esri-icon-down",widget:"esri-widget",panel:"esri-widget--panel",input:"esri-input",select:"esri-select"},I={datePattern:"D",timePattern:"tt"};function F(e){return e&&e.inputFields}const y="data-field-name";let w=class extends d{constructor(e,t){super(e,t),this._activeDateFieldEdit=null,this._activeInputName=null,this._activeNumberFieldEdit=null,this._fieldFocusNeeded=!1,this._fieldToInitialIncompatibleDomainValue=new Map,this._switchFieldsWithInitialIncompatibleValue=new Set,this._userUpdatedInputFieldNames=new Set,this.feature=null,this.formTemplate=null,this.groupDisplay="all",this.headingLevel=2,this.label=void 0,this.layer=null,this.messages=null,this.messagesTemplates=null,this.spatialReference=null,this.strict=null,this.viewModel=new p,this._handleSwitchClick=e=>{e.target===e.currentTarget&&e.stopImmediatePropagation()},this._handleRadioInputChange=e=>{this._commitInputValue(e.target)},this._handleInputInput=e=>{this._commitInputValue(e.currentTarget,!0)},this._handleFormKeyDown=this._handleFormKeyDown.bind(this),this._handleInputBlur=this._handleInputBlur.bind(this),this._handleInputFocus=this._handleInputFocus.bind(this),this._handleNumberInputMouseDown=this._handleNumberInputMouseDown.bind(this),this._handleInputKeyDown=this._handleInputKeyDown.bind(this),this._handleOptionChange=this._handleOptionChange.bind(this),this._handleGroupClick=this._handleGroupClick.bind(this),this._handleSubmit=this._handleSubmit.bind(this),this._afterInputCreateOrUpdate=this._afterInputCreateOrUpdate.bind(this)}initialize(){this.own([n((()=>this.feature),(()=>{const e=this._getFocusableInput("forward");this._activeInputName=e&&e.name,this._userUpdatedInputFieldNames.clear(),this._fieldToInitialIncompatibleDomainValue.clear(),this._switchFieldsWithInitialIncompatibleValue.clear(),this._fieldFocusNeeded=!0})),this.on("submit",(e=>{if(e.invalid.length>0){const[t]=e.invalid;e.invalid.forEach((e=>this._userUpdatedInputFieldNames.add(e))),this._activeInputName=t,this._fieldFocusNeeded=!0,this.scheduleRender()}}))])}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-combobox.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item-group.js"),import("@esri/calcite-components/dist/components/calcite-input-message.js"),import("@esri/calcite-components/dist/components/calcite-switch.js")])}destroy(){this._userUpdatedInputFieldNames.clear(),this._userUpdatedInputFieldNames=null}getValues(){return null}submit(){return null}render(){const{state:e}=this.viewModel;return _("div",{class:this.classes(b.base,b.widget,b.panel)},"ready"===e?this.renderForm():null)}renderForm(){const e=this.formTemplate?.title?_(c,{key:"title",level:this.headingLevel},this.formTemplate.title):null,t=this.formTemplate?.description?_("p",{class:b.description,key:"description"},this.formTemplate.description):null,i=e||t?_("div",{class:b.formHeader},e,t):null;return _("form",{class:b.form,novalidate:!0,onsubmit:this._handleSubmit,onkeydown:this._handleFormKeyDown},i,this.renderFields())}renderFields(){const{viewModel:{inputFields:e}}=this;return e.filter((e=>e.visible)).map(((e,t)=>F(e)?this.renderGroup(e,t):this.renderLabeledField(e)))}renderGroup(e,t){const{description:i,inputFields:a,label:n,state:s}=e,l=a.filter((e=>e.visible)),r=this.viewModel.findField(this._activeInputName),o=!(!r||r.group!==e),u=`${this.id}_group_${t}`,d=`${this.id}_group-label_${t}`,p=`${this.id}_group-description_${t}`,h=i?_("p",{class:this.classes(b.groupDescription,b.description),id:p},i):null,f="sequential"===this.groupDisplay,g=f?o:"expanded"===s,v=g?b.collapseIcon:b.expandIcon;return _("fieldset",{"aria-expanded":g.toString(),"aria-labelledby":d,"aria-describedby":i?p:"",class:this.classes(b.group,f?b.groupSequential:null,g?null:b.groupCollapsed,o?b.groupActive:null),"data-group":e,id:u,key:t,onclick:this._handleGroupClick},_("button",{role:f?"presentation":void 0,class:b.groupHeader,type:"button",tabIndex:f?-1:0},_("div",{class:b.groupTitle},_(c,{class:b.groupLabel,id:d,level:this.formTemplate?.title?m(this.headingLevel):this.headingLevel},n),h),f?null:_("span",{class:this.classes(v,b.groupToggleIcon)})),l.map((e=>this.renderLabeledField(e))))}_getFocusableInput(e,t){const i=this.viewModel.allInputFields,a="forward"===e?i:i.slice().reverse();let n;if(t)if(F(t))n=a.indexOf(t.inputFields[0]);else{let i;if(this._isInputFieldInGroup(t)&&"collapsed"===t.group.state){const{inputFields:a}=t.group;i="forward"===e?a[a.length-1]:a[0]}else i=t;n=a.indexOf(i)+1}else n=0;for(let s=n;s<a.length;s++){const e=a[s];if(e.visible)return e}return null}renderLabeledField(e){const{feature:t,label:i,layer:a,type:n}=e;return _("label",{key:`${a.id}-${t.uid}-${e.name}`,class:b.label},[i,"unsupported"!==n?this.renderInputField(e):this.renderUnsupportedField(e),this.renderAuxiliaryText(e)])}renderInputField(e){const{domain:t,name:a,type:n,value:s}=e,l=this.getCommonInputProps(e);if("coded-value"===t?.type){if(this._inputFieldHasInputType(e,"switch")){const{fieldElement:t}=e;if(!(this._switchFieldsWithInitialIncompatibleValue.has(a)||null==s||t.input.onValue!==s&&t.input.offValue!==s))return this.renderSwitchInputField(e,l);this._switchFieldsWithInitialIncompatibleValue.add(a)}return"radio-buttons"===e.inputType?this.renderRadioButtonsInputField(e,t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),l):this.renderSelectInputField(e,this._getFieldValueOptions(a,t),l)}return"datetime-picker"===e.inputType||"date"===n?this.renderDateInputField(e,l):"number"===n?_("input",{type:"number",...l,value:i(this._activeNumberFieldEdit)&&this._activeNumberFieldEdit.fieldName===e.name?this._activeNumberFieldEdit.value:`${l.value}`}):"text-area"===e.inputType?_("textarea",{...l}):_("input",{type:"text",...l})}_parseDateTime(e,t,i){if(i){let a=g.fromJSDate(this._parseDate(e,i));const n=g.fromMillis(t.value??Date.now());return a="date"===i?a.set({hour:n.hour,minute:n.minute,second:n.second}):a.set({day:n.day,month:n.month,year:n.year}),a.isValid?a.toMillis():null}const a=g.fromJSDate(this._parseDate(e));return a.isValid?a.toMillis():null}renderDateInputField(e,t){const{value:i,includeTime:a}=e,{date:n,time:s}=this._formatDate(0),l=`${this.id}-${t.key}`,r=`${l}-date`,o=`${l}-time`,{_activeDateFieldEdit:u}=this;let{date:d,time:p}=this._formatDate(i);return u?.fieldName===e.name&&(d=u.date.input?.value??d,p=u.time.input?.value??p),_("div",{key:`${t.key}-date`,class:b.dateInputContainer},_("div",{class:this.classes(b.dateInputPart,a?null:b.loneDateInputPart)},_("input",{"aria-label":e.label,"aria-describedby":r,type:"text",...t,"data-date-part":"date",class:this.classes(t.class,b.inputDate),value:d}),_("div",{class:b.dateFormatHint,id:r},n)),a?_("div",{class:b.dateInputPart,key:"time-input"},_("input",{"aria-describedby":o,"aria-label":e.label,type:"text",...t,"data-date-part":"time",class:this.classes(t.class,b.inputTime),value:p}),_("div",{class:b.dateFormatHint,id:o},s)):null)}renderUnsupportedField(e){const t=this.getCommonInputProps(e);return _("input",{afterCreate:t.afterCreate,afterUpdate:t.afterUpdate,class:this.classes(b.input,b.inputField,b.inputDisabled),onfocus:t.onfocus,readOnly:!0,tabIndex:t.tabIndex,type:"text",value:t.value,[y]:t[y]})}renderSelectInputField(e,t,i){const{value:n}=e,{messages:s,messagesTemplates:l}=this,r=t.map((e=>e.map((e=>_("calcite-combobox-item",{value:`${e.value}`,"text-label":e.name,key:`#${e.value}`,selected:n===e.value}))))),[o,u]=r;this._registerIncompatibleValue(n,t.flat(),e,(e=>{u.unshift(_("calcite-combobox-item",{value:`${e}`,"text-label":`${e}`,key:"incompatible-option",readOnly:!0}))}));const d=u.length>0?[_("calcite-combobox-item-group",{key:"recommended",label:s.recommended},o),_("calcite-combobox-item-group",{key:"other",label:l.other},u)]:o,p=a(e.fieldElement)||this._inputFieldHasInputType(e,"combo-box")&&e.fieldElement.input.showNoValueOption;if(!e.required&&p){const t="",i=this._inputFieldHasInputType(e,"combo-box")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty;d.unshift(_("calcite-combobox-item",{value:t,"text-label":this.messages.empty,key:"empty-option"},i))}return _("calcite-combobox",{...i,"selection-mode":"single",disabled:i.readOnly,allowCustomValues:!1,onCalciteComboboxChange:e=>this._handleOptionChange(e.target)},d)}_registerIncompatibleValue(e,t,i,a){const n=this._fieldToInitialIncompatibleDomainValue,s=n.has(i.name);(s||null!=e&&""!==e&&!t.some((t=>t.value===e))||s)&&(s||n.set(i.name,e),a?.(n.get(i.name)))}renderRadioButtonsInputField(e,t,i){const{value:n}=e,s=t.map((t=>this.renderRadioButton({key:t.name,label:t.name,name:e.name,value:t.value,selected:t.value===n,props:i})));this._registerIncompatibleValue(n,t,e);const l=a(e.fieldElement)||this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.showNoValueOption;if(!e.required&&l){const t="",a=this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty,l=n===t||null===n;s.unshift(this.renderRadioButton({key:"empty-option",label:a,name:e.name,value:t,selected:l,props:i}))}return _("div",{key:`${i.key}-radio`,class:b.inputRadioGroup},s)}renderSwitchInputField(e,t){const{value:i}=e,a=!!this._inputFieldHasInputType(e,"switch")&&i===e.fieldElement.input.onValue;return _("calcite-switch",{...t,class:b.inputSwitch,onclick:this._handleSwitchClick,checked:a,disabled:t.readOnly})}renderRadioButton({key:e,name:t,value:i,selected:a,label:n,props:s}){return _("label",{key:e,class:b.inputRadioLabel},_("input",{...s,class:b.inputRadio,name:t,type:"radio",value:i,checked:a,onchange:this._handleRadioInputChange}),n)}renderAuxiliaryText(e){const t=this._userUpdatedInputFieldNames.has(e.name)&&!e.valid?e.errorMessage:i(this.viewModel.contingencyConstraintViolations.get(e.name))?this.messages.validationErrors.valuesIncompatible:null;return i(t)?_("calcite-input-message",{status:"invalid",icon:!0,active:!0},t):e.description?_("div",{key:"description",class:b.description},e.description):void 0}getCommonInputProps(e){const{groupDisplay:t}=this,{editable:a,group:n,hint:s,maxLength:l,minLength:r,name:o,required:u,type:d,valid:p,value:c}=e,m=this._userUpdatedInputFieldNames.has(o),h=!a,f="all"===t&&i(n)&&"collapsed"===n.state;return{afterCreate:this._afterInputCreateOrUpdate,afterUpdate:this._afterInputCreateOrUpdate,"aria-invalid":p?"false":"true",class:this.classes(b.input,b.inputField,h?b.inputDisabled:null,m&&!p?b.inputInvalid:null),key:o,label:o,minlength:r>-1?`${r}`:"",maxlength:l>-1?`${l}`:"",...this._getNumberFieldConstraints(e),readOnly:h,value:null==c?"":`${c}`,[y]:o,onfocus:this._handleInputFocus,oninput:this._handleInputInput,onblur:this._handleInputBlur,onkeydown:this._handleInputKeyDown,onmousedown:"number"===d?this._handleNumberInputMouseDown:null,placeholder:"number"===d||"text"===d?s:"",required:u,tabIndex:f?-1:0}}_isInputFieldInGroup(e){return!F(e)&&i(e.group)}_handleNumberInputMouseDown({target:e}){e.focus(),this.scheduleRender()}_getFieldValueOptions(e,t){const i=t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),a=this.viewModel.fieldsWithContingentValues.has(e)?this._getContingentValueOptions(e):[];if(a.length>0){const e=new Set(a.map((e=>e.value)));return[a,i.filter((t=>!e.has(t.value)))]}return[i,[]]}_getContingentValueOptions(e){const t={};for(const s of this.viewModel.allInputFields){const{name:i,value:n}=s;!a(n)&&i!==e&&this.viewModel.fieldsWithContingentValues.has(i)&&(t[i]=n)}const i=this.viewModel.joinedContingentValues.slice(),n=new Map;for(const s of i){const i=s.values[e];if(a(i)||"code"!==i.objectType&&"null"!==i.objectType)continue;const{code:l,name:r}="null"===i.objectType?{code:"",name:this.messages.empty}:i.codedValue;if(n.has(l))continue;Object.entries(t).every((([e,t])=>!s.values.hasOwnProperty(e)||this._valueIsValidContingentValue(t,s.values[e])))&&n.set(l,{name:r,value:l})}return[...n.values()]}_getInputFieldFromInput(e){return this.viewModel.findField(e.getAttribute(y))}_getNumberFieldConstraints(e){const t=o(e.domain)||u(e.field);return t&&t.max!==Number.MAX_VALUE&&t.min!==Number.MIN_VALUE?t:{min:null,max:null}}_afterInputCreateOrUpdate(e){const{viewModel:t}=this,i=this._getInputFieldFromInput(e),a=t.findField(this._activeInputName),n=this._fieldToInitialIncompatibleDomainValue.get(i.name)===i.value;this._fieldFocusNeeded&&a===i&&("radio-buttons"!==i.inputType||n||e.checked)&&(this._fieldFocusNeeded=!1,e.focus())}_handleInputFocus(e){const t=e.target,i=this._getInputFieldFromInput(t);this._activeInputName=i.name,"date"===i.type?this._syncDateFieldEdits(t):this._isNumberInputField(i)&&this._setUpNumberFieldEdit(t)}_isNumberInputField({domain:e,inputType:t="text-box",type:i}){return"number"===i&&"text-box"===t&&(!e||"coded-value"!==e.type)}_handleInputBlur(e){const t=e.target,a=this._getInputFieldFromInput(t);if("date"===a.type){const i=e.relatedTarget,n=i&&this._getInputFieldFromInput(i);if(n&&"date"===a.type&&"date"===n.type&&a.field===n.field){if(""!==t.value&&""===i.value){const n=i.getAttribute("data-date-part");i.value=this._formatDate(a.value??Date.now())[n],this._parseDate(t.value,t.getAttribute("data-date-part"))&&this._commitInputValue(e.target,!0,!1)}return}}"number"===a.type&&i(this._activeNumberFieldEdit)&&(this._activeNumberFieldEdit.input.value=`${a.value}`,this._activeNumberFieldEdit=null),this._commitInputValue(t),this.scheduleRender()}_commitInputValue(e,t=!1,a=!0){const n=this._getInputFieldFromInput(e);if(this._activeDateFieldEdit){const{date:i,time:s}=this._activeDateFieldEdit,l=this._parseDateTime(e.value,n,i.active?"date":"time"),r=null!==this.viewModel.getValue(n.name),o=i.input&&(s.input||!n.includeTime),u=null===l;if(t){if(u)return;(o||!a||r)&&this._updateDateFieldValue(n,l)}else{if(""===i.input?.value||""===s.input?.value)this._updateDateFieldValue(n,null);else if(o){const e=`${i.input.value} ${s.input?.value??""}`,t=this._parseDateTime(e,n);!(null!==t)&&r||this._updateDateFieldValue(n,t)}this._activeDateFieldEdit=null}}else i(this._activeNumberFieldEdit)&&this._isNumberInputField(n)&&(this._activeNumberFieldEdit.value=e.value),this._updateFieldValue(e)}_handleInputKeyDown(e){const{key:t,altKey:i,ctrlKey:a,metaKey:n}=e,s=this._getInputFieldFromInput(e.target);if("Enter"===t)this._isInputFieldInGroup(s)&&"collapsed"===s.group.state&&(s.group.state="expanded");else{const{type:l}=s.field,r="single"===l||"double"===l,o=!i&&!a&&!n;if(("integer"===l||"small-integer"===l||r)&&o&&1===t.length){const i=Number(t),a=["-","+"],n=["e","."],s=r?[...a,...n]:a;isNaN(i)&&!s.includes(t)&&e.preventDefault()}}}_setUpNumberFieldEdit(e){const t=this._getInputFieldFromInput(e);this._activeNumberFieldEdit={fieldName:t.name,input:e,value:e.value}}_syncDateFieldEdits(e){const t=this._getInputFieldFromInput(e);if("date"!==t.type)return;const i=e.getAttribute("data-date-part"),a="date"===i?{value:e.value,input:e,active:!0}:{...this._activeDateFieldEdit?.date,active:!1},n="time"===i?{value:e.value,input:e,active:!0}:{...this._activeDateFieldEdit?.time,active:!1};this._activeDateFieldEdit={fieldName:t.name,date:a,time:n}}_updateFieldValue(e){const t=e.getAttribute(y);if(this.viewModel.setValue(t,this._parseValue(e)),this._userUpdatedInputFieldNames.add(t),this.viewModel.fieldsWithContingentValues.has(t)){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>i(t))));this.viewModel.validateContingencyConstraints(e)}}_updateDateFieldValue(e,t){this.viewModel.setValue(e.name,t),this._userUpdatedInputFieldNames.add(e.name)}_parseValue(e){const t=this._getInputFieldFromInput(e),i=e.value;if(this._inputFieldHasInputType(t,"switch")&&"CALCITE-COMBOBOX"!==e.tagName)return e.checked?t.fieldElement.input.onValue:t.fieldElement.input.offValue;if("radio-buttons"===t.inputType&&"radio"===e.type&&!e.checked)return t.value;const{type:a}=t;if("number"===a)return i?parseFloat(i):null;if("date"===a){if(!i)return null;const a=Number(i);if(!isNaN(a))return a;const n=e.getAttribute("data-date-part"),s=this._parseDate(i,n);if(!s)return null;let l=g.fromJSDate(s);const r=t.domain,o=g.now();let u=o;if(r&&"range"===r.type){const e=g.fromMillis(r.maxValue);o<e&&(u=e)}const d=this.viewModel.getValue(t.name),p=null!=d?g.fromMillis(d):u;return l="date"===n?l.set({hour:p.hour,minute:p.minute,second:p.second}):l.set({day:p.day,month:p.month,year:p.year}),l.toMillis()}return i}_handleOptionChange(e){this._commitInputValue(e),this.scheduleRender()}_handleGroupClick(e){const t=e.currentTarget["data-group"],i="expanded"===t.state,a="sequential"===this.groupDisplay,n=`.${b.groupHeader}`;if(!(i&&!e.target.closest(n))){if(this._activeInputName=this._getFocusableInput("forward",t)?.name,a){const a=e.target.closest(n);if(i&&!a)return;this.viewModel.inputFields.forEach((e=>{F(e)&&e!==t&&(e.state="collapsed")}))}t.state=i?"collapsed":"expanded",this._fieldFocusNeeded=a,this.scheduleRender()}}_handleSubmit(e){e.preventDefault()}_handleFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_formatDate(e){if(null==e)return{date:"",time:""};const t=g.fromMillis(e,{locale:v(),numberingSystem:"latn"});return{date:t.toLocaleString({year:"numeric",month:"2-digit",day:"2-digit"}),time:t.toFormat(I.timePattern)}}_parseDate(e,t){if(null==e||""===e)return null;const{timePattern:i,datePattern:a}=I,n=t?"date"===t?a:i:`${a} ${i}`,s=g.fromFormat(e,n,{locale:v(),numberingSystem:"latn"});return s.isValid?s.toJSDate():null}_inputFieldHasInputType(e,t){return i(e.fieldElement)&&e.fieldElement.input?.type===t}_valueIsValidContingentValue(e,i){switch(i.objectType){case"any":return!0;case"null":return null==e;case"code":return e===i.codedValue?.code;case"range":return e>=i.minValue&&e<=i.maxValue;default:return t(i.objectType),!1}}};e([s("viewModel.feature")],w.prototype,"feature",void 0),e([s("viewModel.formTemplate")],w.prototype,"formTemplate",void 0),e([l()],w.prototype,"groupDisplay",void 0),e([l()],w.prototype,"headingLevel",void 0),e([l({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],w.prototype,"label",void 0),e([s("viewModel.layer")],w.prototype,"layer",void 0),e([l(),h("esri/widgets/FeatureForm/t9n/FeatureForm")],w.prototype,"messages",void 0),e([l(),h("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],w.prototype,"messagesTemplates",void 0),e([s("viewModel.spatialReference")],w.prototype,"spatialReference",void 0),e([s("viewModel.strict")],w.prototype,"strict",void 0),e([l(),f(["value-change","submit"])],w.prototype,"viewModel",void 0),e([s("viewModel.getValues")],w.prototype,"getValues",null),e([s("viewModel.submit")],w.prototype,"submit",null),w=e([r("esri.widgets.FeatureForm")],w);const V=w;export{V as default};
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{neverReached as t}from"../core/compilerUtils.js";import{isSome as i,isNone as a}from"../core/maybe.js";import{watch as n}from"../core/reactiveUtils.js";import{aliasOf as s}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import"../core/accessorSupport/ensureType.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import{subclass as r}from"../core/accessorSupport/decorators/subclass.js";import{getDomainRange as o}from"../layers/support/domainUtils.js";import{getFieldRange as u}from"../layers/support/fieldUtils.js";import d from"./Widget.js";import p from"./FeatureForm/FeatureFormViewModel.js";import{Heading as c,incrementHeadingLevel as m}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as h}from"./support/decorators/messageBundle.js";import{vmEvent as f}from"./support/decorators/vmEvent.js";import{tsx as _}from"./support/jsxFactory.js";import{DateTime as g}from"luxon";import{getLocale as v}from"../intl/locale.js";const b={base:"esri-feature-form",form:"esri-feature-form__form",formHeader:"esri-feature-form__form-header",label:"esri-feature-form__label",inputField:"esri-feature-form__input",inputDate:"esri-feature-form__input--date",inputTime:"esri-feature-form__input--time",inputRadioGroup:"esri-feature-form__input--radio-group",inputRadio:"esri-feature-form__input--radio",inputRadioLabel:"esri-feature-form__input--radio-label",inputDisabled:"esri-feature-form__input--disabled",inputSwitch:"esri-feature-form__input--switch",inputInvalid:"esri-feature-form__input--invalid",inputIconInvalid:"esri-feature-form__input-icon--invalid",errorMessage:"esri-feature-form__field-error-message",description:"esri-feature-form__description-text",dateInputPart:"esri-feature-form__date-input-part",loneDateInputPart:"esri-feature-form__date-input-part--lone",dateInputContainer:"esri-feature-form__date-input-container",dateFormatHint:"esri-feature-form__date-format-hint",group:"esri-feature-form__group",groupLabel:"esri-feature-form__group-label",groupHeader:"esri-feature-form__group-header",groupHeading:"esri-feature-form__group-header",groupTitle:"esri-feature-form__group-title",groupDescription:"esri-feature-form__group-description",groupToggleIcon:"esri-feature-form__group-toggle-icon",groupCollapsed:"esri-feature-form__group--collapsed",groupSequential:"esri-feature-form__group--sequential",groupActive:"esri-feature-form__group--active",collapseIcon:"esri-icon-up",errorIcon:"esri-icon-notice-triangle",expandIcon:"esri-icon-down",widget:"esri-widget",panel:"esri-widget--panel",input:"esri-input",select:"esri-select"},I={datePattern:"D",timePattern:"tt"};function F(e){return e&&e.inputFields}const y="data-field-name";let w=class extends d{constructor(e,t){super(e,t),this._activeDateFieldEdit=null,this._activeInputName=null,this._activeNumberFieldEdit=null,this._fieldFocusNeeded=!1,this._fieldToInitialIncompatibleDomainValue=new Map,this._switchFieldsWithInitialIncompatibleValue=new Set,this._userUpdatedInputFieldNames=new Set,this.feature=null,this.formTemplate=null,this.groupDisplay="all",this.headingLevel=2,this.label=void 0,this.layer=null,this.messages=null,this.messagesTemplates=null,this.spatialReference=null,this.strict=null,this.viewModel=new p,this._handleRadioInputChange=e=>{this._commitInputValue(e.target)},this._handleInputInput=e=>{this._commitInputValue(e.currentTarget,!0)},this._handleFormKeyDown=this._handleFormKeyDown.bind(this),this._handleInputBlur=this._handleInputBlur.bind(this),this._handleInputFocus=this._handleInputFocus.bind(this),this._handleNumberInputMouseDown=this._handleNumberInputMouseDown.bind(this),this._handleInputKeyDown=this._handleInputKeyDown.bind(this),this._handleOptionChange=this._handleOptionChange.bind(this),this._handleGroupClick=this._handleGroupClick.bind(this),this._handleSubmit=this._handleSubmit.bind(this),this._afterInputCreateOrUpdate=this._afterInputCreateOrUpdate.bind(this)}initialize(){this.own([n((()=>this.feature),(()=>{const e=this._getFocusableInput("forward");this._activeInputName=e&&e.name,this._userUpdatedInputFieldNames.clear(),this._fieldToInitialIncompatibleDomainValue.clear(),this._switchFieldsWithInitialIncompatibleValue.clear(),this._fieldFocusNeeded=!0})),this.on("submit",(e=>{if(e.invalid.length>0){const[t]=e.invalid;e.invalid.forEach((e=>this._userUpdatedInputFieldNames.add(e))),this._activeInputName=t,this._fieldFocusNeeded=!0,this.scheduleRender()}}))])}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-combobox.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item-group.js"),import("@esri/calcite-components/dist/components/calcite-input-message.js"),import("@esri/calcite-components/dist/components/calcite-switch.js")])}destroy(){this._userUpdatedInputFieldNames.clear(),this._userUpdatedInputFieldNames=null}getValues(){return null}submit(){return null}render(){const{state:e}=this.viewModel;return _("div",{class:this.classes(b.base,b.widget,b.panel)},"ready"===e?this.renderForm():null)}renderForm(){const e=this.formTemplate?.title?_(c,{key:"title",level:this.headingLevel},this.formTemplate.title):null,t=this.formTemplate?.description?_("p",{class:b.description,key:"description"},this.formTemplate.description):null,i=e||t?_("div",{class:b.formHeader},e,t):null;return _("form",{class:b.form,novalidate:!0,onsubmit:this._handleSubmit,onkeydown:this._handleFormKeyDown},i,this.renderFields())}renderFields(){const{viewModel:{inputFields:e}}=this;return e.filter((e=>e.visible)).map(((e,t)=>F(e)?this.renderGroup(e,t):this.renderLabeledField(e)))}renderGroup(e,t){const{description:i,inputFields:a,label:n,state:s}=e,l=a.filter((e=>e.visible)),r=this.viewModel.findField(this._activeInputName),o=!(!r||r.group!==e),u=`${this.id}_group_${t}`,d=`${this.id}_group-label_${t}`,p=`${this.id}_group-description_${t}`,h=i?_("p",{class:this.classes(b.groupDescription,b.description),id:p},i):null,f="sequential"===this.groupDisplay,g=f?o:"expanded"===s,v=g?b.collapseIcon:b.expandIcon;return _("fieldset",{"aria-expanded":g.toString(),"aria-labelledby":d,"aria-describedby":i?p:"",class:this.classes(b.group,f?b.groupSequential:null,g?null:b.groupCollapsed,o?b.groupActive:null),"data-group":e,id:u,key:t,onclick:this._handleGroupClick},_("button",{role:f?"presentation":void 0,class:b.groupHeader,type:"button",tabIndex:f?-1:0},_("div",{class:b.groupTitle},_(c,{class:b.groupLabel,id:d,level:this.formTemplate?.title?m(this.headingLevel):this.headingLevel},n),h),f?null:_("span",{class:this.classes(v,b.groupToggleIcon)})),l.map((e=>this.renderLabeledField(e))))}_getFocusableInput(e,t){const i=this.viewModel.allInputFields,a="forward"===e?i:i.slice().reverse();let n;if(t)if(F(t))n=a.indexOf(t.inputFields[0]);else{let i;if(this._isInputFieldInGroup(t)&&"collapsed"===t.group.state){const{inputFields:a}=t.group;i="forward"===e?a[a.length-1]:a[0]}else i=t;n=a.indexOf(i)+1}else n=0;for(let s=n;s<a.length;s++){const e=a[s];if(e.visible)return e}return null}renderLabeledField(e){const{feature:t,label:i,layer:a,type:n}=e;return _("label",{key:`${a.id}-${t.uid}-${e.name}`,class:b.label},[i,"unsupported"!==n?this.renderInputField(e):this.renderUnsupportedField(e),this.renderAuxiliaryText(e)])}renderInputField(e){const{domain:t,name:a,type:n,value:s}=e,l=this.getCommonInputProps(e);if("coded-value"===t?.type){if(this._inputFieldHasInputType(e,"switch")){const{fieldElement:t}=e;if(!(this._switchFieldsWithInitialIncompatibleValue.has(a)||null==s||t.input.onValue!==s&&t.input.offValue!==s))return this.renderSwitchInputField(e,l);this._switchFieldsWithInitialIncompatibleValue.add(a)}return"radio-buttons"===e.inputType?this.renderRadioButtonsInputField(e,t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),l):this.renderSelectInputField(e,this._getFieldValueOptions(a,t),l)}return"datetime-picker"===e.inputType||"date"===n?this.renderDateInputField(e,l):"number"===n?_("input",{type:"number",...l,value:i(this._activeNumberFieldEdit)&&this._activeNumberFieldEdit.fieldName===e.name?this._activeNumberFieldEdit.value:`${l.value}`}):"text-area"===e.inputType?_("textarea",{...l}):_("input",{type:"text",...l})}_parseDateTime(e,t,i){if(i){let a=g.fromJSDate(this._parseDate(e,i));const n=g.fromMillis(t.value??Date.now());return a="date"===i?a.set({hour:n.hour,minute:n.minute,second:n.second}):a.set({day:n.day,month:n.month,year:n.year}),a.isValid?a.toMillis():null}const a=g.fromJSDate(this._parseDate(e));return a.isValid?a.toMillis():null}renderDateInputField(e,t){const{value:i,includeTime:a}=e,{date:n,time:s}=this._formatDate(0),l=`${this.id}-${t.key}`,r=`${l}-date`,o=`${l}-time`,{_activeDateFieldEdit:u}=this;let{date:d,time:p}=this._formatDate(i);return u?.fieldName===e.name&&(d=u.date.input?.value??d,p=u.time.input?.value??p),_("div",{key:`${t.key}-date`,class:b.dateInputContainer},_("div",{class:this.classes(b.dateInputPart,a?null:b.loneDateInputPart)},_("input",{"aria-label":e.label,"aria-describedby":r,type:"text",...t,"data-date-part":"date",class:this.classes(t.class,b.inputDate),value:d}),_("div",{class:b.dateFormatHint,id:r},n)),a?_("div",{class:b.dateInputPart,key:"time-input"},_("input",{"aria-describedby":o,"aria-label":e.label,type:"text",...t,"data-date-part":"time",class:this.classes(t.class,b.inputTime),value:p}),_("div",{class:b.dateFormatHint,id:o},s)):null)}renderUnsupportedField(e){const t=this.getCommonInputProps(e);return _("input",{afterCreate:t.afterCreate,afterUpdate:t.afterUpdate,class:this.classes(b.input,b.inputField,b.inputDisabled),onfocus:t.onfocus,readOnly:!0,tabIndex:t.tabIndex,type:"text",value:t.value,[y]:t[y]})}renderSelectInputField(e,t,i){const{value:n}=e,{messages:s,messagesTemplates:l}=this,r=t.map((e=>e.map((e=>_("calcite-combobox-item",{value:`${e.value}`,"text-label":e.name,key:`#${e.value}`,selected:n===e.value}))))),[o,u]=r;this._registerIncompatibleValue(n,t.flat(),e,(e=>{u.unshift(_("calcite-combobox-item",{value:`${e}`,"text-label":`${e}`,key:"incompatible-option",readOnly:!0}))}));const d=u.length>0?[_("calcite-combobox-item-group",{key:"recommended",label:s.recommended},o),_("calcite-combobox-item-group",{key:"other",label:l.other},u)]:o,p=a(e.fieldElement)||this._inputFieldHasInputType(e,"combo-box")&&e.fieldElement.input.showNoValueOption;if(!e.required&&p){const t="",i=this._inputFieldHasInputType(e,"combo-box")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty;d.unshift(_("calcite-combobox-item",{value:t,"text-label":this.messages.empty,key:"empty-option"},i))}return _("calcite-combobox",{...i,"selection-mode":"single",disabled:i.readOnly,allowCustomValues:!1,onCalciteComboboxChange:e=>this._handleOptionChange(e.target)},d)}_registerIncompatibleValue(e,t,i,a){const n=this._fieldToInitialIncompatibleDomainValue,s=n.has(i.name);(s||null!=e&&""!==e&&!t.some((t=>t.value===e))||s)&&(s||n.set(i.name,e),a?.(n.get(i.name)))}renderRadioButtonsInputField(e,t,i){const{value:n}=e,s=t.map((t=>this.renderRadioButton({key:t.name,label:t.name,name:e.name,value:t.value,selected:t.value===n,props:i})));this._registerIncompatibleValue(n,t,e);const l=a(e.fieldElement)||this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.showNoValueOption;if(!e.required&&l){const t="",a=this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty,l=n===t||null===n;s.unshift(this.renderRadioButton({key:"empty-option",label:a,name:e.name,value:t,selected:l,props:i}))}return _("div",{key:`${i.key}-radio`,class:b.inputRadioGroup},s)}renderSwitchInputField(e,t){const{value:i}=e,a=!!this._inputFieldHasInputType(e,"switch")&&i===e.fieldElement.input.onValue;return _("calcite-switch",{...t,class:b.inputSwitch,onCalciteSwitchChange:e=>{this._parseValue(e.currentTarget)},checked:a,disabled:t.readOnly})}renderRadioButton({key:e,name:t,value:i,selected:a,label:n,props:s}){return _("label",{key:e,class:b.inputRadioLabel},_("input",{...s,class:b.inputRadio,name:t,type:"radio",value:i,checked:a,onchange:this._handleRadioInputChange}),n)}renderAuxiliaryText(e){const t=this._userUpdatedInputFieldNames.has(e.name)&&!e.valid?e.errorMessage:i(this.viewModel.contingencyConstraintViolations.get(e.name))?this.messages.validationErrors.valuesIncompatible:null;return i(t)?_("calcite-input-message",{status:"invalid",icon:!0,active:!0},t):e.description?_("div",{key:"description",class:b.description},e.description):void 0}getCommonInputProps(e){const{groupDisplay:t}=this,{editable:a,group:n,hint:s,maxLength:l,minLength:r,name:o,required:u,type:d,valid:p,value:c}=e,m=this._userUpdatedInputFieldNames.has(o),h=!a,f="all"===t&&i(n)&&"collapsed"===n.state;return{afterCreate:this._afterInputCreateOrUpdate,afterUpdate:this._afterInputCreateOrUpdate,"aria-invalid":p?"false":"true",class:this.classes(b.input,b.inputField,h?b.inputDisabled:null,m&&!p?b.inputInvalid:null),key:o,label:o,minlength:r>-1?`${r}`:"",maxlength:l>-1?`${l}`:"",...this._getNumberFieldConstraints(e),readOnly:h,value:null==c?"":`${c}`,[y]:o,onfocus:this._handleInputFocus,oninput:this._handleInputInput,onblur:this._handleInputBlur,onkeydown:this._handleInputKeyDown,onmousedown:"number"===d?this._handleNumberInputMouseDown:null,placeholder:"number"===d||"text"===d?s:"",required:u,tabIndex:f?-1:0}}_isInputFieldInGroup(e){return!F(e)&&i(e.group)}_handleNumberInputMouseDown({target:e}){e.focus(),this.scheduleRender()}_getFieldValueOptions(e,t){const i=t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),a=this.viewModel.fieldsWithContingentValues.has(e)?this._getContingentValueOptions(e):[];if(a.length>0){const e=new Set(a.map((e=>e.value)));return[a,i.filter((t=>!e.has(t.value)))]}return[i,[]]}_getContingentValueOptions(e){const t={};for(const s of this.viewModel.allInputFields){const{name:i,value:n}=s;!a(n)&&i!==e&&this.viewModel.fieldsWithContingentValues.has(i)&&(t[i]=n)}const i=this.viewModel.joinedContingentValues.slice(),n=new Map;for(const s of i){const i=s.values[e];if(a(i)||"code"!==i.objectType&&"null"!==i.objectType)continue;const{code:l,name:r}="null"===i.objectType?{code:"",name:this.messages.empty}:i.codedValue;if(n.has(l))continue;Object.entries(t).every((([e,t])=>!s.values.hasOwnProperty(e)||this._valueIsValidContingentValue(t,s.values[e])))&&n.set(l,{name:r,value:l})}return[...n.values()]}_getInputFieldFromInput(e){return this.viewModel.findField(e.getAttribute(y))}_getNumberFieldConstraints(e){const t=o(e.domain)||u(e.field);return t&&t.max!==Number.MAX_VALUE&&t.min!==Number.MIN_VALUE?t:{min:null,max:null}}_afterInputCreateOrUpdate(e){const{viewModel:t}=this,i=this._getInputFieldFromInput(e),a=t.findField(this._activeInputName),n=this._fieldToInitialIncompatibleDomainValue.get(i.name)===i.value;this._fieldFocusNeeded&&a===i&&("radio-buttons"!==i.inputType||n||e.checked)&&(this._fieldFocusNeeded=!1,e.focus())}_handleInputFocus(e){const t=e.target,i=this._getInputFieldFromInput(t);this._activeInputName=i.name,"date"===i.type?this._syncDateFieldEdits(t):this._isNumberInputField(i)&&this._setUpNumberFieldEdit(t)}_isNumberInputField({domain:e,inputType:t="text-box",type:i}){return"number"===i&&"text-box"===t&&(!e||"coded-value"!==e.type)}_handleInputBlur(e){const t=e.target,a=this._getInputFieldFromInput(t);if("date"===a.type){const i=e.relatedTarget,n=i&&this._getInputFieldFromInput(i);if(n&&"date"===a.type&&"date"===n.type&&a.field===n.field){if(""!==t.value&&""===i.value){const n=i.getAttribute("data-date-part");i.value=this._formatDate(a.value??Date.now())[n],this._parseDate(t.value,t.getAttribute("data-date-part"))&&this._commitInputValue(e.target,!0,!1)}return}}"number"===a.type&&i(this._activeNumberFieldEdit)&&(this._activeNumberFieldEdit.input.value=`${a.value}`,this._activeNumberFieldEdit=null),this._commitInputValue(t),this.scheduleRender()}_commitInputValue(e,t=!1,a=!0){const n=this._getInputFieldFromInput(e);if(this._activeDateFieldEdit){const{date:i,time:s}=this._activeDateFieldEdit,l=this._parseDateTime(e.value,n,i.active?"date":"time"),r=null!==this.viewModel.getValue(n.name),o=i.input&&(s.input||!n.includeTime),u=null===l;if(t){if(u)return;(o||!a||r)&&this._updateDateFieldValue(n,l)}else{if(""===i.input?.value||""===s.input?.value)this._updateDateFieldValue(n,null);else if(o){const e=`${i.input.value} ${s.input?.value??""}`,t=this._parseDateTime(e,n);!(null!==t)&&r||this._updateDateFieldValue(n,t)}this._activeDateFieldEdit=null}}else i(this._activeNumberFieldEdit)&&this._isNumberInputField(n)&&(this._activeNumberFieldEdit.value=e.value),this._updateFieldValue(e)}_handleInputKeyDown(e){const{key:t,altKey:i,ctrlKey:a,metaKey:n}=e,s=this._getInputFieldFromInput(e.target);if("Enter"===t)this._isInputFieldInGroup(s)&&"collapsed"===s.group.state&&(s.group.state="expanded");else{const{type:l}=s.field,r="single"===l||"double"===l,o=!i&&!a&&!n;if(("integer"===l||"small-integer"===l||r)&&o&&1===t.length){const i=Number(t),a=["-","+"],n=["e","."],s=r?[...a,...n]:a;isNaN(i)&&!s.includes(t)&&e.preventDefault()}}}_setUpNumberFieldEdit(e){const t=this._getInputFieldFromInput(e);this._activeNumberFieldEdit={fieldName:t.name,input:e,value:e.value}}_syncDateFieldEdits(e){const t=this._getInputFieldFromInput(e);if("date"!==t.type)return;const i=e.getAttribute("data-date-part"),a="date"===i?{value:e.value,input:e,active:!0}:{...this._activeDateFieldEdit?.date,active:!1},n="time"===i?{value:e.value,input:e,active:!0}:{...this._activeDateFieldEdit?.time,active:!1};this._activeDateFieldEdit={fieldName:t.name,date:a,time:n}}_updateFieldValue(e){const t=e.getAttribute(y);if(this.viewModel.setValue(t,this._parseValue(e)),this._userUpdatedInputFieldNames.add(t),this.viewModel.fieldsWithContingentValues.has(t)){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>i(t))));this.viewModel.validateContingencyConstraints(e)}}_updateDateFieldValue(e,t){this.viewModel.setValue(e.name,t),this._userUpdatedInputFieldNames.add(e.name)}_parseValue(e){const t=this._getInputFieldFromInput(e),i=e.value;if(this._inputFieldHasInputType(t,"switch")&&"CALCITE-COMBOBOX"!==e.tagName)return e.checked?t.fieldElement.input.onValue:t.fieldElement.input.offValue;if("radio-buttons"===t.inputType&&"radio"===e.type&&!e.checked)return t.value;const{type:a}=t;if("number"===a)return i?parseFloat(i):null;if("date"===a){if(!i)return null;const a=Number(i);if(!isNaN(a))return a;const n=e.getAttribute("data-date-part"),s=this._parseDate(i,n);if(!s)return null;let l=g.fromJSDate(s);const r=t.domain,o=g.now();let u=o;if(r&&"range"===r.type){const e=g.fromMillis(r.maxValue);o<e&&(u=e)}const d=this.viewModel.getValue(t.name),p=null!=d?g.fromMillis(d):u;return l="date"===n?l.set({hour:p.hour,minute:p.minute,second:p.second}):l.set({day:p.day,month:p.month,year:p.year}),l.toMillis()}return i}_handleOptionChange(e){this._commitInputValue(e),this.scheduleRender()}_handleGroupClick(e){const t=e.currentTarget["data-group"],i="expanded"===t.state,a="sequential"===this.groupDisplay,n=`.${b.groupHeader}`;if(!(i&&!e.target.closest(n))){if(this._activeInputName=this._getFocusableInput("forward",t)?.name,a){const a=e.target.closest(n);if(i&&!a)return;this.viewModel.inputFields.forEach((e=>{F(e)&&e!==t&&(e.state="collapsed")}))}t.state=i?"collapsed":"expanded",this._fieldFocusNeeded=a,this.scheduleRender()}}_handleSubmit(e){e.preventDefault()}_handleFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_formatDate(e){if(null==e)return{date:"",time:""};const t=g.fromMillis(e,{locale:v(),numberingSystem:"latn"});return{date:t.toLocaleString({year:"numeric",month:"2-digit",day:"2-digit"}),time:t.toFormat(I.timePattern)}}_parseDate(e,t){if(null==e||""===e)return null;const{timePattern:i,datePattern:a}=I,n=t?"date"===t?a:i:`${a} ${i}`,s=g.fromFormat(e,n,{locale:v(),numberingSystem:"latn"});return s.isValid?s.toJSDate():null}_inputFieldHasInputType(e,t){return i(e.fieldElement)&&e.fieldElement.input?.type===t}_valueIsValidContingentValue(e,i){switch(i.objectType){case"any":return!0;case"null":return null==e;case"code":return e===i.codedValue?.code;case"range":return e>=i.minValue&&e<=i.maxValue;default:return t(i.objectType),!1}}};e([s("viewModel.feature")],w.prototype,"feature",void 0),e([s("viewModel.formTemplate")],w.prototype,"formTemplate",void 0),e([l()],w.prototype,"groupDisplay",void 0),e([l()],w.prototype,"headingLevel",void 0),e([l({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],w.prototype,"label",void 0),e([s("viewModel.layer")],w.prototype,"layer",void 0),e([l(),h("esri/widgets/FeatureForm/t9n/FeatureForm")],w.prototype,"messages",void 0),e([l(),h("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],w.prototype,"messagesTemplates",void 0),e([s("viewModel.spatialReference")],w.prototype,"spatialReference",void 0),e([s("viewModel.strict")],w.prototype,"strict",void 0),e([l(),f(["value-change","submit"])],w.prototype,"viewModel",void 0),e([s("viewModel.getValues")],w.prototype,"getValues",null),e([s("viewModel.submit")],w.prototype,"submit",null),w=e([r("esri.widgets.FeatureForm")],w);const V=w;export{V as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import i from"../../core/Accessor.js";import r from"../../core/Collection.js";import t from"../../core/Handles.js";import{watch as s,initial as a,when as n}from"../../core/reactiveUtils.js";import{property as o}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as l}from"../../core/accessorSupport/decorators/subclass.js";import y from"./support/ActiveLayerInfo.js";import{onLocaleChange as d}from"../../intl/locale.js";const h={state:"state",view:"view",allLayerViews:"all-layer-views",legendProperties:"legend-properties"},c=r.ofType(y),L=["esri.layers.BuildingSceneLayer","esri.layers.CSVLayer","esri.layers.FeatureLayer","esri.layers.GeoJSONLayer","esri.layers.GeoRSSLayer","esri.layers.GroupLayer","esri.layers.HeatmapLayer","esri.layers.ImageryLayer","esri.layers.ImageryTileLayer","esri.layers.MapImageLayer","esri.layers.OGCFeatureLayer","esri.layers.PointCloudLayer","esri.layers.StreamLayer","esri.layers.SceneLayer","esri.layers.TileLayer","esri.layers.VoxelLayer","esri.layers.WFSLayer","esri.layers.WMSLayer","esri.layers.WMTSLayer","esri.layers.WCSLayer"],_="view.basemapView.baseLayerViews",f="view.groundView.layerViews",u="view.basemapView.referenceLayerViews",p=[_,f,"view.layerViews",u];let v=class extends i{constructor(e){super(e),this._handles=new t,this._layerViewByLayerId={},this._layerInfosByLayerViewId={},this._activeLayerInfosByLayerViewId={},this._activeLayerInfosWithNoParent=new r,this.activeLayerInfos=new c,this.basemapLegendVisible=!1,this.groundLegendVisible=!1,this.hideLayersNotInCurrentView=!1,this.keepCacheOnDestroy=!1,this.respectLayerVisibility=!0,this.layerInfos=[],this.view=null}initialize(){this._handles.add(s((()=>this.view),(()=>this._viewHandles()),a),h.view),this._handles.add(d((()=>this._refresh())))}destroy(){this._destroyViewActiveLayerInfos(),this._handles.destroy(),this._handles=null,this.view=null}get state(){return this.get("view.ready")?"ready":"disabled"}_viewHandles(){this._handles.remove(h.state),this.view&&this._handles.add(s((()=>this.state),(()=>this._stateHandles()),a),h.state)}_stateHandles(){this._resetAll(),"ready"===this.state&&this._watchPropertiesAndAllLayerViews()}_resetAll(){this._handles.remove([h.allLayerViews,h.legendProperties]),this._destroyViewActiveLayerInfos(),this.activeLayerInfos.removeAll()}_destroyViewActiveLayerInfos(){Object.keys(this._activeLayerInfosByLayerViewId).forEach(this._destroyViewActiveLayerInfo,this)}_destroyViewActiveLayerInfo(e){this._handles.remove(e);const i=this._activeLayerInfosByLayerViewId[e];delete this._activeLayerInfosByLayerViewId[e],i&&i.parent&&i.parent.children.remove(i)}_watchPropertiesAndAllLayerViews(){const{allLayerViews:e}=this.view;e.length&&this._refresh(),this._handles.add(e.on("change",(e=>this._allLayerViewsChangeHandle(e))),h.allLayerViews),this._handles.add(s((()=>[this.layerInfos,this.basemapLegendVisible,this.groundLegendVisible]),(()=>this._propertiesChangeHandle())),h.legendProperties)}_allLayerViewsChangeHandle(e){e.removed.forEach((e=>this._destroyViewActiveLayerInfo(e.uid))),this._refresh()}_propertiesChangeHandle(){this._destroyViewActiveLayerInfos(),this._refresh()}_refresh(){this._layerInfosByLayerViewId={},this.activeLayerInfos.removeAll(),this._generateLayerViews().filter(this._filterLayerViewsByLayerInfos,this).filter(this._isLayerViewSupported,this).forEach(this._generateActiveLayerInfo,this),this._sortActiveLayerInfos(this.activeLayerInfos)}_sortActiveLayerInfos(e){if(e.length<2)return;const i=[];e.forEach((r=>{if(!r.parent){const t=r.layer.parent,s=t&&"uid"in t&&this._layerViewByLayerId[t.uid],a=s&&this._activeLayerInfosByLayerViewId[s.uid];a&&e.includes(a)&&(i.push(r),r.parent=a,a.children.add(r),this._sortActiveLayerInfos(a.children))}})),e.removeMany(i);const r={};this.view.allLayerViews.forEach(((e,i)=>r[e.layer.uid]=i)),e.sort(((e,i)=>{const t=r[e.layer.uid]||0;return(r[i.layer.uid]||0)-t}))}_generateLayerViews(){const e=[];return p.filter(this._filterLayerViews,this).map(this.get,this).filter((e=>null!=e)).forEach(this._collectLayerViews("layerViews",e)),e}_filterLayerViews(e){const i=!this.basemapLegendVisible&&(e===_||e===u),r=!this.groundLegendVisible&&e===f;return!i&&!r}_collectLayerViews(e,i){const r=t=>(t&&t.forEach((t=>{i.push(t),r(t[e])})),i);return r}_filterLayerViewsByLayerInfos(e){const i=this.layerInfos;return!i||!i.length||i.some((i=>this._hasLayerInfo(i,e)))}_hasLayerInfo(e,i){const r=this._isLayerUIDMatching(e.layer,i.layer.uid);return r&&(this._layerInfosByLayerViewId[i.uid]=e),r}_isLayerUIDMatching(e,i){return e&&(e.uid===i||this._hasLayerUID(e.layers,i))}_hasLayerUID(e,i){return e&&e.some((e=>this._isLayerUIDMatching(e,i)))}_isLayerViewSupported(e){return!!L.includes(e.layer.declaredClass)&&(this._layerViewByLayerId[e.layer.uid]=e,!0)}_generateActiveLayerInfo(e){this._isLayerActive(e)?this._buildActiveLayerInfo(e):(this._handles.remove(e.uid),this._handles.add(s((()=>[e.legendEnabled,e.layer
|
|
5
|
+
import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import i from"../../core/Accessor.js";import r from"../../core/Collection.js";import t from"../../core/Handles.js";import{watch as s,initial as a,when as n}from"../../core/reactiveUtils.js";import{property as o}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as l}from"../../core/accessorSupport/decorators/subclass.js";import y from"./support/ActiveLayerInfo.js";import{onLocaleChange as d}from"../../intl/locale.js";const h={state:"state",view:"view",allLayerViews:"all-layer-views",legendProperties:"legend-properties"},c=r.ofType(y),L=["esri.layers.BuildingSceneLayer","esri.layers.CSVLayer","esri.layers.FeatureLayer","esri.layers.GeoJSONLayer","esri.layers.GeoRSSLayer","esri.layers.GroupLayer","esri.layers.HeatmapLayer","esri.layers.ImageryLayer","esri.layers.ImageryTileLayer","esri.layers.MapImageLayer","esri.layers.OGCFeatureLayer","esri.layers.PointCloudLayer","esri.layers.StreamLayer","esri.layers.SceneLayer","esri.layers.TileLayer","esri.layers.VoxelLayer","esri.layers.WFSLayer","esri.layers.WMSLayer","esri.layers.WMTSLayer","esri.layers.WCSLayer"],_="view.basemapView.baseLayerViews",f="view.groundView.layerViews",u="view.basemapView.referenceLayerViews",p=[_,f,"view.layerViews",u];let v=class extends i{constructor(e){super(e),this._handles=new t,this._layerViewByLayerId={},this._layerInfosByLayerViewId={},this._activeLayerInfosByLayerViewId={},this._activeLayerInfosWithNoParent=new r,this.activeLayerInfos=new c,this.basemapLegendVisible=!1,this.groundLegendVisible=!1,this.hideLayersNotInCurrentView=!1,this.keepCacheOnDestroy=!1,this.respectLayerVisibility=!0,this.layerInfos=[],this.view=null}initialize(){this._handles.add(s((()=>this.view),(()=>this._viewHandles()),a),h.view),this._handles.add(d((()=>this._refresh())))}destroy(){this._destroyViewActiveLayerInfos(),this._handles.destroy(),this._handles=null,this.view=null}get state(){return this.get("view.ready")?"ready":"disabled"}_viewHandles(){this._handles.remove(h.state),this.view&&this._handles.add(s((()=>this.state),(()=>this._stateHandles()),a),h.state)}_stateHandles(){this._resetAll(),"ready"===this.state&&this._watchPropertiesAndAllLayerViews()}_resetAll(){this._handles.remove([h.allLayerViews,h.legendProperties]),this._destroyViewActiveLayerInfos(),this.activeLayerInfos.removeAll()}_destroyViewActiveLayerInfos(){Object.keys(this._activeLayerInfosByLayerViewId).forEach(this._destroyViewActiveLayerInfo,this)}_destroyViewActiveLayerInfo(e){this._handles.remove(e);const i=this._activeLayerInfosByLayerViewId[e];delete this._activeLayerInfosByLayerViewId[e],i&&i.parent&&i.parent.children.remove(i)}_watchPropertiesAndAllLayerViews(){const{allLayerViews:e}=this.view;e.length&&this._refresh(),this._handles.add(e.on("change",(e=>this._allLayerViewsChangeHandle(e))),h.allLayerViews),this._handles.add(s((()=>[this.layerInfos,this.basemapLegendVisible,this.groundLegendVisible]),(()=>this._propertiesChangeHandle())),h.legendProperties)}_allLayerViewsChangeHandle(e){e.removed.forEach((e=>this._destroyViewActiveLayerInfo(e.uid))),this._refresh()}_propertiesChangeHandle(){this._destroyViewActiveLayerInfos(),this._refresh()}_refresh(){this._layerInfosByLayerViewId={},this.activeLayerInfos.removeAll(),this._generateLayerViews().filter(this._filterLayerViewsByLayerInfos,this).filter(this._isLayerViewSupported,this).forEach(this._generateActiveLayerInfo,this),this._sortActiveLayerInfos(this.activeLayerInfos)}_sortActiveLayerInfos(e){if(e.length<2)return;const i=[];e.forEach((r=>{if(!r.parent){const t=r.layer.parent,s=t&&"uid"in t&&this._layerViewByLayerId[t.uid],a=s&&this._activeLayerInfosByLayerViewId[s.uid];a&&e.includes(a)&&(i.push(r),r.parent=a,a.children.add(r),this._sortActiveLayerInfos(a.children))}})),e.removeMany(i);const r={};this.view.allLayerViews.forEach(((e,i)=>r[e.layer.uid]=i)),e.sort(((e,i)=>{const t=r[e.layer.uid]||0;return(r[i.layer.uid]||0)-t}))}_generateLayerViews(){const e=[];return p.filter(this._filterLayerViews,this).map(this.get,this).filter((e=>null!=e)).forEach(this._collectLayerViews("layerViews",e)),e}_filterLayerViews(e){const i=!this.basemapLegendVisible&&(e===_||e===u),r=!this.groundLegendVisible&&e===f;return!i&&!r}_collectLayerViews(e,i){const r=t=>(t&&t.forEach((t=>{i.push(t),r(t[e])})),i);return r}_filterLayerViewsByLayerInfos(e){const i=this.layerInfos;return!i||!i.length||i.some((i=>this._hasLayerInfo(i,e)))}_hasLayerInfo(e,i){const r=this._isLayerUIDMatching(e.layer,i.layer.uid);return r&&(this._layerInfosByLayerViewId[i.uid]=e),r}_isLayerUIDMatching(e,i){return e&&(e.uid===i||this._hasLayerUID(e.layers,i))}_hasLayerUID(e,i){return e&&e.some((e=>this._isLayerUIDMatching(e,i)))}_isLayerViewSupported(e){return!!L.includes(e.layer.declaredClass)&&(this._layerViewByLayerId[e.layer.uid]=e,!0)}_generateActiveLayerInfo(e){this._isLayerActive(e)?this._buildActiveLayerInfo(e):(this._handles.remove(e.uid),this._handles.add(s((()=>[e.legendEnabled,e.layer?.legendEnabled]),(()=>this._layerActiveHandle(e))),e.uid))}_layerActiveHandle(e){this._isLayerActive(e)&&(this._handles.remove(e.uid),this._buildActiveLayerInfo(e))}_isLayerActive(e){return!this.respectLayerVisibility||e.legendEnabled&&e.get("layer.legendEnabled")}_buildActiveLayerInfo(e){const i=e.layer,r=e.uid,t=this._layerInfosByLayerViewId[r];let o=this._activeLayerInfosByLayerViewId[r];if(!o){const s=t&&void 0!==t.title&&t.layer.uid===i.uid;o=new y({layer:i,layerView:e,title:s?t.title:i.title,view:this.view,respectLayerVisibility:this.respectLayerVisibility,hideLayersNotInCurrentView:this.hideLayersNotInCurrentView,keepCacheOnDestroy:this.keepCacheOnDestroy,sublayerIds:t&&t.sublayerIds||[]}),this._activeLayerInfosByLayerViewId[r]=o}const l=i.parent&&"uid"in i.parent&&this._layerViewByLayerId[i.parent?.uid];if(o.parent=this._activeLayerInfosByLayerViewId[l?.uid],!this._handles.has(r)){const t=[s((()=>i.title),(e=>this._titleHandle(e,o))),s((()=>[i.opacity,"renderer"in i&&i.renderer,"pointSymbol"in i&&i.pointSymbol,"lineSymbol"in i&&i.lineSymbol,"polygonSymbol"in i&&i.polygonSymbol]),(()=>this._constructLegendElements(o))),n((()=>!0===this.view?.stationary),(()=>this._scaleHandle(o)),a),s((()=>e._effectiveRenderer),(()=>this._constructLegendElements(o))),s((()=>"effect"in i&&i.effect),(()=>this._constructLegendElements(o)))];if(this.respectLayerVisibility){const r=s((()=>e.legendEnabled),(e=>this._legendEnabledHandle(e,o))),a=s((()=>i.legendEnabled),(e=>this._legendEnabledHandle(e,o)));t.push(r,a)}this._handles.add(t,r)}o.isScaleDriven||this._constructLegendElements(o),this._addActiveLayerInfo(o)}_titleHandle(e,i){i.title=e,this._constructLegendElements(i)}_legendEnabledHandle(e,i){e?this._addActiveLayerInfo(i):this._removeActiveLayerInfo(i)}_scaleHandle(e){(e.isScaleDriven||e.hideLayersNotInCurrentView)&&this._constructLegendElements(e)}_addActiveLayerInfo(e){const{layerView:i,layer:r}=e;if(this._isLayerActive(i)&&!this.activeLayerInfos.includes(e)){const i=e.parent;if(i)i.children.includes(e)||i.children.push(e),this._sortActiveLayerInfos(i.children);else{const i=this.layerInfos?.some((e=>e.layer.uid===r.uid));r.parent&&"uid"in r.parent&&!i?this._activeLayerInfosWithNoParent.add(e):(this.activeLayerInfos.add(e),this._sortActiveLayerInfos(this.activeLayerInfos))}if(this._activeLayerInfosWithNoParent.length){const e=[];this._activeLayerInfosWithNoParent.forEach((i=>{const r=i.layer.parent,t=r&&"uid"in r&&this._layerViewByLayerId[r?.uid],s=this._activeLayerInfosByLayerViewId[t?.uid];s&&(e.push(i),i.parent=s)})),e.length&&(this._activeLayerInfosWithNoParent.removeMany(e),e.forEach((e=>this._addActiveLayerInfo(e))))}}}_removeActiveLayerInfo(e){const i=e.parent;i?i.children.remove(e):this.activeLayerInfos.remove(e)}_constructLegendElements(e){const i=e.layer;"featureCollections"in i&&i.featureCollections?e.buildLegendElementsForFeatureCollections(i.featureCollections):"featureReduction"in i&&"binning"===i.featureReduction?.type&&"renderer"in i.featureReduction?e.buildLegendElementsForRenderer(i.featureReduction.renderer):"renderer"in i&&i.renderer?e.buildLegendElementsForRenderer(i.renderer):"url"in i&&i.url?e.buildLegendElementsForTools():e.children.forEach((e=>this._constructLegendElements(e)))}};e([o({type:c})],v.prototype,"activeLayerInfos",void 0),e([o()],v.prototype,"basemapLegendVisible",void 0),e([o()],v.prototype,"groundLegendVisible",void 0),e([o()],v.prototype,"hideLayersNotInCurrentView",void 0),e([o()],v.prototype,"keepCacheOnDestroy",void 0),e([o()],v.prototype,"respectLayerVisibility",void 0),e([o()],v.prototype,"layerInfos",void 0),e([o({readOnly:!0})],v.prototype,"state",null),e([o()],v.prototype,"view",void 0),v=e([l("esri.widgets.Legend.LegendViewModel")],v);const I=v;export{I as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import{addTokenParameter as s}from"../../../kernel.js";import l from"../../../request.js";import"../../../symbols.js";import r from"../../../core/Accessor.js";import i from"../../../core/Collection.js";import n from"../../../core/Handles.js";import{JSONMap as a}from"../../../core/jsonMap.js";import o from"../../../core/Logger.js";import{unwrap as c,isSome as u}from"../../../core/maybe.js";import{eachAlways as d,debounce as y}from"../../../core/promiseUtils.js";import{on as h,watch as m,whenOnce as f,initial as p}from"../../../core/reactiveUtils.js";import{px2pt as g}from"../../../core/screenUtils.js";import{addQueryParameters as b}from"../../../core/urlUtils.js";import{property as S}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as _}from"../../../core/accessorSupport/decorators/subclass.js";import{OriginId as w}from"../../../core/accessorSupport/PropertyOrigin.js";import{EffectView as L}from"../../../layers/effects/EffectView.js";import{effectFunctionsFromJSON as v}from"../../../layers/effects/jsonUtils.js";import{ExportImageParameters as E}from"../../../layers/support/ExportImageParameters.js";import{isDateField as C}from"../../../layers/support/fieldUtils.js";import{fromJSON as I}from"../../../renderers/support/jsonUtils.js";import{isSupportedRenderer3D as R}from"../../../renderers/support/rendererConversion.js";import V from"../../../renderers/visualVariables/support/SizeVariableLegendOptions.js";import{applyCIMSymbolColor as F}from"../../../symbols/support/cimSymbolUtils.js";import{SymbolSizeDefaults as T}from"../../../symbols/support/previewUtils.js";import{renderSymbol as z}from"../../../symbols/support/renderUtils.js";import{renderColorRampPreviewHTML as x,renderDotDensityPreviewHTML as j,renderPieChartPreviewHTML as O,renderPreviewHTML as D}from"../../../symbols/support/symbolUtils.js";import{isVolumetricSymbol as P}from"../../../symbols/support/utils.js";import{getClusterSizeVariable as M}from"./clusterUtils.js";import{getColorFromPointCloudStops as A,getRampStopsForPointCloud as B,getStrectchRampStops as U,getRampStops as k}from"./colorRampUtils.js";import{getHeatmapRampStops as N}from"./heatmapRampUtils.js";import{getRotationAngleForFocus as q,getRelationshipRampElement as W}from"./relationshipRampUtils.js";import{getRampStops as $,REAL_WORLD_MAX_SIZE as G,REAL_WORLD_MIN_SIZE as J}from"./sizeRampUtils.js";import{SPECIAL_CHARS_LESS_THAN as Q,SPECIAL_CHARS_GREATER_THAN as H,getSymbolForFlowRenderer as X,getMedianColor as K,RGB_IMG_SOURCE as Y}from"./utils.js";import{formatNumberLabel as Z}from"../../smartMapping/support/utils.js";import ee from"../../../symbols/SimpleMarkerSymbol.js";import te from"../../../symbols/SimpleFillSymbol.js";const se=o.getLogger("esri.widgets.Legend.support.ActiveLayerInfo"),le="https://utility.arcgis.com/sharing/tools/legend",re="esri.layers.ImageryLayer",ie="esri.layers.ImageryTileLayer",ne="esri.layers.WCSLayer",ae=/^\s*(return\s+)?\$view\.scale\s*(;)?\s*$/i,oe=new a({esriGeometryPoint:"point",esriGeometryMultipoint:"multipoint",esriGeometryPolyline:"polyline",esriGeometryPolygon:"polygon",esriGeometryMultiPatch:"multipatch"}),ce={u1:[0,1],u2:[0,3],u4:[0,15],u8:[0,255],s8:[-128,127],u16:[0,65535],s16:[-32768,32767],u32:[0,4294967295],s32:[-2147483648,2147483647],f32:[-34e38,34e38],f64:[-Number.MAX_VALUE,Number.MAX_VALUE]},ue=new ee({size:6,outline:{color:[128,128,128,.5],width:.5}}),de=new te({style:"solid"});function ye(e){return"flow"===e.type}function he(e){return"vector-field"===e.type}function me(e){return"raster-colormap"===e.type}function fe(e){return"raster-stretch"===e.type}function pe(e){return"raster-shaded-relief"===e.type}function ge(e){return"esri.renderers.SimpleRenderer"===e.declaredClass}function be(e){return"esri.renderers.ClassBreaksRenderer"===e.declaredClass}function Se(e){return"esri.renderers.UniqueValueRenderer"===e.declaredClass}function _e(e){return"esri.renderers.HeatmapRenderer"===e.declaredClass}function we(e){return ve(e)||Ee(e)||Ce(e)||Le(e)}function Le(e){return"esri.renderers.PointCloudRGBRenderer"===e.declaredClass}function ve(e){return"esri.renderers.PointCloudClassBreaksRenderer"===e.declaredClass}function Ee(e){return"esri.renderers.PointCloudStretchRenderer"===e.declaredClass}function Ce(e){return"esri.renderers.PointCloudUniqueValueRenderer"===e.declaredClass}function Ie(e){return"esri.renderers.DotDensityRenderer"===e.declaredClass}function Re(e){return"esri.renderers.PieChartRenderer"===e.declaredClass}function Ve(e,t){return ge(e)||be(e)||Se(e)||_e(e)||Ie(e)||Re(e)?"2d"===t.type||R(e):fe(e)||me(e)||pe(e)||ve(e)||Ee(e)||Ce(e)||he(e)||ye(e)}function Fe(e){return"esri.layers.BuildingSceneLayer"===e.declaredClass}function Te(e){return"esri.layers.VoxelLayer"===e.declaredClass}function ze(e){return"esri.layers.WMSLayer"===e.declaredClass}function xe(e){return"esri.layers.WMTSLayer"===e.declaredClass}function je(e){return"esri.layers.MapImageLayer"===e.declaredClass}function Oe(e){return"esri.layers.TileLayer"===e.declaredClass}function De(e){return"esri.layers.FeatureLayer"===e.declaredClass}function Pe(e){return e.declaredClass===re}function Me(e){return e.declaredClass===ie}function Ae(e){return e.declaredClass===ne}function Be(e){return"stretch-ramp"===e.type}function Ue(e){return"univariate-color-size"===("authoringInfo"in e&&e?.authoringInfo)?.type}function ke(e){const t="authoringInfo"in e&&e?.authoringInfo;return"univariate-color-size"===t?.type&&"above-and-below"===t?.univariateTheme}const Ne=new ee({style:"path",path:"M10,5 L5,0 0,5 M5,0 L5,15",size:15,outline:{width:1,color:[85,85,85,1]}});let qe={},We=class extends r{constructor(e){super(e),this._handles=new n,this._hasColorRamp=!1,this._hasOpacityRamp=!1,this._hasSizeRamp=!1,this._webStyleSymbolCache=new Map,this._dotDensityUrlCache=new Map,this._scaleDrivenSizeVariable=null,this._hasClusterSizeVariable=!1,this.children=new i,this.layerView=null,this.layer=null,this.legendElements=[],this.parent=null,this.hideLayersNotInCurrentView=!1,this.keepCacheOnDestroy=!1,this.respectLayerVisibility=!0,this.sublayerIds=[],this.title=null,this.view=null}initialize(){const e=()=>this.notifyChange("ready");this._handles.add([h((()=>this.children),"change",(t=>{const{added:s,removed:l}=t,r=this._handles;s.forEach((t=>{const s=`activeLayerInfo-ready-watcher-${t.layer.uid}`;r.add(m((()=>t.ready),e,p),s)})),l.forEach((e=>r.remove(e.layer.uid))),e()}))]),this.keepCacheOnDestroy||(qe={})}destroy(){this._handles.destroy(),this._handles=null,this._webStyleSymbolCache=null,this._dotDensityUrlCache=null,this._scaleDrivenSizeVariable=null,this.keepCacheOnDestroy||(qe=null)}get effectList(){const e=this.layer;let t=null;return"effect"in e&&e.effect&&(t=new L,t.effect=e.effect,t.end(),t.scale=this.scale),t}get opacity(){const e=this.layer.opacity,t=this.parent?.opacity,s=this.layer.parent,l=s&&"uid"in s?this._getParentLayerOpacity(s):null;return null!=t?t*e:null!=l?l*e:e}get ready(){return null===this.layer||(this.children.length>0?this._isGroupActive():this.legendElements.length>0)}get scale(){return this.view&&this.view.scale}get isScaleDriven(){const e=this.layer;if(null===e)return!1;if("effect"in e&&e.effect&&Array.isArray(e.effect))return!0;if("featureReduction"in e&&e.featureReduction&&"cluster"===e.featureReduction.type)return!0;if("renderer"in e&&e.renderer){if("dot-density"===e.renderer.type)return!0;const t=e.get("renderer.valueExpression");if(ae.test(t))return!0;const s=e.get("renderer.visualVariables");if(s)return s.some((e=>this._isScaleDrivenSizeVariable(e)))}return this._isLayerScaleDriven(this.layer)}get version(){return this._get("version")+1}async buildLegendElementsForFeatureCollections(e){if(!(!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView()))return this.legendElements=[],void this.notifyChange("ready");const t=Array.from(e,(e=>{if(De(e))return this._getRendererLegendElements(e.renderer,{title:e.title});if(e.featureSet&&e.featureSet.features.length){const t=e.layerDefinition,s=t&&t.drawingInfo,l=s&&I(s.renderer),r=oe.read(t.geometryType);return l?this._getRendererLegendElements(l,{title:e.name,geometryType:r}):(se.warn("drawingInfo not available!"),null)}return null}));try{const e=[];await d(t).then((t=>{t.forEach((({value:t})=>t&&e.push(...t)))})),this.legendElements=e,this.notifyChange("ready")}catch(s){se.warn("error while building legend for layer!",s)}}async buildLegendElementsForRenderer(e){try{const t=!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView();this.legendElements=t?await this._getRendererLegendElements(e):[],this.notifyChange("ready")}catch(t){se.warn("error while building legend for layer!",t)}}async buildLegendElementsForTools(){const e=this.layer;if(Te(e))this._constructLegendElementsForVoxellayer();else if(xe(e))this._constructLegendElementsForWMTSlayer();else if(ze(e))await this._constructLegendElementsForWMSSublayers();else if(Fe(e))await this._constructLegendElementsForBuildingSceneLayer();else if(je(e)||Oe(e)||Fe(e))await this._constructLegendElementsForSublayers();else{this._handles.remove("imageryLayers-watcher");let t="default";if(Pe(e)){t=(e?.renderingRule?.functionName||"default")+"_"+(e.bandIds?.length?e.bandIds.join(""):"###")}await this._getLegendLayers(`${e.uid}-${t}`).then((async t=>{this.legendElements=[],this.notifyChange("ready");const s=t.map((async t=>{if(Pe(e)||Me(e)){const t=m((()=>["renderingRule"in e&&e.renderingRule,e.bandIds]),(()=>y((async()=>{qe.default=null,e.renderer?await this.buildLegendElementsForRenderer(e.renderer):await this.buildLegendElementsForTools()}))()));this._handles.add(t,"imageryLayers-watcher")}const s=this._generateSymbolTableElementForLegendLayer(t);s&&s.infos.length&&(Pe(e)&&(s.title=e.title),this.legendElements.push(s)),this.notifyChange("ready")}));await d(s)})).catch((e=>{se.warn("Request to server for legend has failed!",e)}))}}async _isLayerInCurrentView(){const e=this.layer,t=this.layerView,s=t&&"createQuery"in t&&"queryFeatureCount"in t;if(!s&&!(t&&"createQuery"in e&&"queryFeatureCount"in e))return!0;await f((()=>!t.updating));const l=s?"createQuery"in t&&t.createQuery():"createQuery"in e&&e.createQuery();l.geometry=this.view.extent;return 0!==(s?"queryFeatureCount"in t&&await t.queryFeatureCount(l):"queryFeatureCount"in e&&await e.queryFeatureCount(l))}_getParentLayerOpacity(e){let t=1;const s=e.parent;return s&&"uid"in s&&(t=this._getParentLayerOpacity(s)),e.opacity*t}_isGroupActive(){const e=this.children;return!!e.length&&e.some((e=>e.ready))}_isScaleDrivenSizeVariable(e){if(e&&"size"!==e.type)return!1;const t=e,s=t.minSize,l=t.maxSize;return"object"==typeof s&&s?this._isScaleDrivenSizeVariable(s):"object"==typeof l&&l?this._isScaleDrivenSizeVariable(l):!!t.expression||ae.test(t.valueExpression)}_isLayerScaleDriven(e){if("minScale"in e&&e.minScale>0||"maxScale"in e&&e.maxScale>0)return!0;if("sublayers"in e&&e.sublayers)return e.sublayers.some((e=>this._isLayerScaleDriven(e)));const t=e.parent;if(!1===e.loaded&&t&&je(t)&&"source"in e&&e.source&&"map-layer"===e.source.type)for(const s of t.sourceJSON.layers)if(s.id===e.source.mapLayerId&&(s.minScale>0||s.maxScale>0))return!0;return!1}async _constructLegendElementsForVoxellayer(){this.legendElements=[],this._handles.remove("voxel-style-watcher");const e=this.layer;this._handles.add(m((()=>e.currentVariableId),(()=>this._constructLegendElementsForVoxellayer())),"voxel-style-watcher");const t=c(e.getVariableStyle(null)),s=[];if(t)if(t.uniqueValues?.length){const e=[];t.uniqueValues.forEach((t=>{t.enabled&&e.push({label:t.label||`${t.value}`,value:t.value,symbol:new te({color:t.color,outline:null})})})),e.length&&s.push({type:"symbol-table",title:t.label,infos:e})}else if(t.transferFunction){const{colorStops:e,stretchRange:l}=t.transferFunction,r=e.toArray().reverse(),i=l.map(((e,t)=>`${0===t?Q:H} ${Z(e)}`)).reverse(),n=r.map((e=>({color:e.color,value:null,label:null})));n[0].label=i[0],n[n.length-1].label=i[1],s.push({type:"color-ramp",title:t.label,infos:n,preview:x(r.map((e=>e.color)))})}const l=e.opacity,r=s.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]).filter((e=>!!e?.symbol)).map((e=>this._getSymbolPreview(e,l)));await d(r),this.legendElements=s,this.notifyChange("ready")}_constructLegendElementsForWMTSlayer(){this.legendElements=[],this._handles.remove("wmts-activeLayer-watcher");const e=this.layer.activeLayer;if(this._handles.add(m((()=>{const{layer:e}=this;return e&&"activeLayer"in e&&e.activeLayer}),(()=>this._constructLegendElementsForWMTSlayer())),"wmts-activeLayer-watcher"),e.styleId&&e.styles){let t=null;e.styles.some((s=>e.styleId===s.id&&(t=s.legendUrl,!0))),t&&(this.legendElements=[{type:"symbol-table",title:e.title,infos:[{src:t,opacity:this.opacity}]}])}this.notifyChange("ready")}async _constructLegendElementsForWMSSublayers(){this.legendElements=[],this._handles.remove("wms-sublayers-watcher");const e=this.layer;let t=null;(e.customParameters||e.customLayerParameters)&&(t={...e.customParameters,...e.customLayerParameters}),this._handles.add(m((()=>{const{layer:e}=this;return e&&"sublayers"in e&&e.sublayers}),(()=>this._constructLegendElementsForWMSSublayers())),"wms-sublayers-watcher"),this.legendElements=await this._generateLegendElementsForWMSSublayers(e.sublayers,t),this.notifyChange("ready")}async _generateLegendElementsForWMSSublayers(e,t){const s=[];this._handles.add(e.on("change",(()=>this._constructLegendElementsForWMSSublayers())),"wms-sublayers-watcher");const l=e.toArray();for(const r of l){const e=m((()=>[r.title,r.visible,r.legendEnabled]),(()=>this._constructLegendElementsForWMSSublayers()));if(this._handles.add(e,"wms-sublayers-watcher"),!this.respectLayerVisibility||r.visible&&r.legendEnabled){const e=await this._generateSymbolTableElementForWMSSublayer(r,t);e&&e.infos.length&&s.unshift(e)}}return s}async _generateSymbolTableElementForWMSSublayer(e,t){if(!e.legendUrl&&e.sublayers){const s=(await this._generateLegendElementsForWMSSublayers(e.sublayers,t)).filter((e=>e));return{type:"symbol-table",title:e.title,infos:s}}return this._generateSymbolTableElementForLegendUrl(e,t)}async _generateSymbolTableElementForLegendUrl(e,t){let s=e.legendUrl;if(!s)return;const r={type:"symbol-table",title:e.title||e.name||e.id&&e.id+"",infos:[]};t&&(s=b(s,t));let i=null;const n=e.layer?.opacity;try{i=(await l(s,{responseType:"image"})).data,i&&(i.style.opacity=n)}catch{}return r.infos.push({src:s,preview:i,opacity:n}),r}_getLegendLayers(e,t){const s=qe&&qe[e];return s?Promise.resolve(s):this._legendRequest(t).then((t=>{const s=t.layers;return qe[e]=s,s}))}_legendRequest(e){const t=this.layer;let s={f:"json",dynamicLayers:e};if(Pe(t)){const e=t.exportImageServiceParameters.renderingRule;if(e&&(s.renderingRule=JSON.stringify(e.rasterFunctionDefinition||e.toJSON())),t.bandIds&&(s.bandIds=t.bandIds.join()),t.raster||t.viewId||t.customParameters){const{raster:e,viewId:l,customParameters:r}=t;s={raster:e,viewId:l,...s,...r}}}let r=t.url.replace(/(\/)+$/,"");if("version"in t&&t.version>=10.01){const e=r.indexOf("?");e>-1?r=r.substring(0,e)+"/legend"+r.substring(e):r+="/legend"}else{const e=r.toLowerCase().indexOf("/rest/"),t=r.substring(0,e)+r.substring(e+5,r.length);r=le+"?soapUrl="+encodeURI(t)+"&returnbytes=true"}return l(r,{query:s}).then((e=>e.data))}async _constructLegendElementsForBuildingSceneLayer(){this.legendElements=[],this._handles.remove("sublayers-watcher");const e=this.layer;this._handles.add(m((()=>e.sublayers),(()=>this._constructLegendElementsForBuildingSceneLayer())),"sublayers-watcher");try{this.legendElements=await this._generateLegendElementsForBuildingSublayers(e.sublayers,this.opacity),this.notifyChange("ready")}catch(t){se.warn("Request to server for legend has failed!",t)}}async _generateLegendElementsForBuildingSublayers(e,t){let s=[];this._handles.add(e.on("change",(()=>this._constructLegendElementsForBuildingSceneLayer())),"sublayers-watcher");const l=e.toArray();for(const r of l){const e=m((()=>["renderer"in r&&r.renderer,r.opacity,r.title,r.visible]),(()=>this._constructLegendElementsForBuildingSceneLayer()));if(this._handles.add(e,"sublayers-watcher"),!this.respectLayerVisibility||r.visible){const e=r&&null!=r.opacity?r.opacity:null,l=null!=e?e*t:t;if("building-group"===r.type){const e={type:"symbol-table",title:r.title,infos:[]},t=await this._generateLegendElementsForBuildingSublayers(r.sublayers,l);e.infos.push(...t),s=[e,...s]}else if(r.renderer){s=[...await this._getRendererLegendElements(r.renderer,{title:r.title,opacity:l,sublayer:r}),...s]}}}return s.filter((e=>!!e&&(!("infos"in e)||e.infos.length>0)))}async _constructLegendElementsForSublayers(){this.legendElements=[],this._handles.remove("sublayers-watcher");const e=this.layer;this._handles.add(m((()=>e.sublayers),(()=>this._constructLegendElementsForSublayers)),"sublayers-watcher");try{this.legendElements=await this._generateLegendElementsForSublayers(e.sublayers,this.opacity),this.notifyChange("ready")}catch(t){se.warn("Request to server for legend has failed!",t)}}async _generateLegendElementsForSublayers(e,t,s){const l=this.layer;let r=[];this._handles.add(e.on("change",(()=>this._constructLegendElementsForSublayers())),"sublayers-watcher");let i=e.toArray();!s&&this.sublayerIds&&this.sublayerIds.length&&(i=this.sublayerIds.map((e=>l.findSublayerById(e))).filter(Boolean));for(const n of i){const e=m((()=>[n.renderer,n.opacity,n.title,n.visible,n.legendEnabled]),(()=>this._constructLegendElementsForSublayers()));if(this._handles.add(e,"sublayers-watcher"),!this.respectLayerVisibility||n.visible&&n.legendEnabled&&this._isSublayerInScale(n)){const e=n&&null!=n.opacity?n.opacity:null,l=null!=e?e*t:t;if(n.renderer&&!n.sublayers&&n.originIdOf("renderer")>w.SERVICE){await n.load();r=[...await this._getRendererLegendElements(n.renderer,{title:n.title,opacity:l,sublayer:n}),...r]}else{const e=await this._generateSymbolTableElementForSublayer(n,l,s);e&&r.unshift(e)}}}return r.filter((e=>!!e&&(!("infos"in e)||e.infos.length>0)))}async _generateSymbolTableElementForSublayer(e,t,s){if(!s){s=new Map;const t=this.layer,l=e.source;let r=null;if(!(!l||"map-layer"===l.type&&l.mapLayerId===e.id&&(!l.gdbVersion||l.gdbVersion===("gdbVersion"in t&&t.gdbVersion)))||e.originIdOf("renderer")>w.SERVICE||e.originIdOf("labelingInfo")>w.SERVICE||e.originIdOf("labelsVisible")>w.SERVICE){const e=new E({layer:this.layer});r=e.hasDynamicLayers?e.dynamicLayers:null,e.destroy()}const i=r||`${t.uid}-default`;(await this._getLegendLayers(i,r)).forEach((e=>s.set(e.layerId,e)))}const l=s.get(e.id);if((!l||l?.subLayerIds&&l.defaultVisibility)&&e.sublayers){const l=await this._generateLegendElementsForSublayers(e.sublayers,t,s);return{type:"symbol-table",title:e.title,infos:l}}return this._generateSymbolTableElementForLegendLayer(l,e,t)}_generateSymbolTableElementForLegendLayer(e,t,s){if(!e||!e.legend||this.respectLayerVisibility&&!this._isLegendLayerInScale(e,t))return null;const l=t?.renderer;let r=t?.title||e.layerName;if(l&&(!t||t?.originIdOf("renderer")>w.SERVICE)){const e=t?.title||this._getRendererTitle(l,t);e&&(r&&"string"!=typeof e&&"title"in e&&(e.title=r),r=e)}const i={type:"symbol-table",title:r,legendType:e.legendType?e.legendType:null,infos:[]},n=t?this._sanitizeLegendForSublayer(e.legend.slice(),t):e.legend;return e.legendGroups?.length>0?e.legendGroups.forEach((t=>{const l={type:"symbol-table",title:t.heading,legendType:e.legendType?e.legendType:null,infos:this._generateSymbolTableElementInfosForLegendLayer(n.filter((e=>e.groupId===t.id)),e.layerId,s)};l.infos?.length>0&&i.infos.push(l)})):i.infos=this._generateSymbolTableElementInfosForLegendLayer(n,e.layerId,s),i.infos.length>0?i:null}_generateSymbolTableElementInfosForLegendLayer(e,t,l){return e.map((e=>{let r=e.url;if(e.imageData&&e.imageData.length>0)r=`data:image/png;base64,${e.imageData}`;else{if(0===r.indexOf("http"))return null;r=s(`${this.layer.url}/${t}/images/${r}`)}return{label:e.label,src:r,opacity:null==l?this.opacity:l,width:e.width,height:e.height}})).filter((e=>!!e))}_isSublayerInScale(e){const t=e.minScale||0,s=e.maxScale||0;return!(t>0&&t<this.scale||s>this.scale)}_isLegendLayerInScale(e,t){const s=t||this.layer;let l=null,r=null,i=!0;return!s.minScale&&0!==s.minScale||!s.maxScale&&0!==s.maxScale?(0===e.minScale&&s.tileInfo&&(l=s.tileInfo.lods[0].scale),0===e.maxScale&&s.tileInfo&&(r=s.tileInfo.lods[s.tileInfo.lods.length-1].scale)):(l=Math.min(s.minScale,e.minScale)||s.minScale||e.minScale,r=Math.max(s.maxScale,e.maxScale)),(l>0&&l<this.scale||r>this.scale)&&(i=!1),i}_sanitizeLegendForSublayer(e,t){if("version"in this.layer&&this.layer.version<10.1||0===e.length)return e;const s=t.renderer,l=e.some((e=>e.values));let r=null,i=null;return l&&e.some(((e,t)=>(e.values||(r=t,i=e,i.label||(i.label="others")),null!=i))),s?"unique-value"===s.type?i&&(e.splice(r,1),e.push(i)):"class-breaks"===s.type&&(i&&e.splice(r,1),e.reverse(),i&&e.push(i)):i&&(e.splice(r,1),e.push(i)),e}async _getRendererLegendElements(e,t={}){return Ve(e,this.view)?we(e)?this._constructPointCloudRendererLegendElements(e,t):Ie(e)?this._constructDotDensityRendererLegendElements(e):Re(e)?this._constructPieChartRendererLegendElements(e):this._constructRendererLegendElements(e,t):(se.warn(`Renderer of type '${e.type}' not supported!`),[])}_getPointCloudRendererTitle(e){return e.legendOptions&&e.legendOptions.title||e.field}_constructPointCloudRendererLegendElements(e,t={}){const s=t.title,l=[];let r=null,i=null;if(ve(e))r={type:"symbol-table",title:s||this._getPointCloudRendererTitle(e),infos:[]},e.colorClassBreakInfos.forEach((e=>{r.infos.unshift({label:e.label||e.minValue+" - "+e.maxValue,value:[e.minValue,e.maxValue],symbol:this._getAppliedCloneSymbol(ue,e.color)})}));else if(Ee(e)){const t=e.stops;let l=null;if(t.length&&(1===t.length&&(l=t[0].color),!l)){const e=t[0].value,s=t[t.length-1].value;if(null!=e&&null!=s){l=A(e+(s-e)/2,t)}}r={type:"symbol-table",title:null,infos:[{label:null,value:null,symbol:this._getAppliedCloneSymbol(ue,l||ue.color)}]};const n=B(e.stops);i={type:"color-ramp",title:s||this._getPointCloudRendererTitle(e),infos:n,preview:x(n.map((e=>e.color)))}}else Ce(e)&&(r={type:"symbol-table",title:s||this._getPointCloudRendererTitle(e),infos:[]},e.colorUniqueValueInfos.forEach((e=>{r.infos.push({label:e.label||e.values.join(", "),value:e.values.join(", "),symbol:this._getAppliedCloneSymbol(ue,e.color)})})));r&&r.infos.length&&l.push(r),i&&i.infos.length&&l.push(i);const n=l.reduce(((e,t)=>e.concat(t.infos)),[]).filter((e=>!!e.symbol)).map((t=>this._getSymbolPreview(t,this.opacity,{symbolConfig:{applyColorModulation:!!e.colorModulation}})));return d(n).then((()=>l))}_getElementInfoForDotDensity(e,t){const{backgroundColor:s,outline:l,dotSize:r}=e,i=this.effectList?.effects.map((e=>e.toJSON())),n=v(i),a=r+"-"+t+"-"+s+"-"+(l&&JSON.stringify(l.toJSON()))+"-"+n,o=this._dotDensityUrlCache,c=o.has(a)?o.get(a):j(e,t);o.set(a,c);const u={shape:{type:"image",x:0,y:0,width:c.width,height:c.height,src:c.src},fill:null,stroke:null,offset:[0,0]},d=z([[u]],[c.width,c.height],{effectView:this.effectList});return{opacity:1,src:c.src,preview:d,width:c.width,height:c.height}}_constructDotDensityRendererLegendElements(e){const t=e.calculateDotValue(this.view.scale),s=e.legendOptions&&e.legendOptions.unit,l={type:"symbol-table",title:{value:t&&Math.round(t),unit:s||""},infos:[]};return e.attributes.forEach((t=>{const s=this._getElementInfoForDotDensity(e,t.color);s.label=t.label||t.valueExpressionTitle||t.field,l.infos.push(s)})),Promise.resolve([l])}async _constructPieChartRendererLegendElements(e){const t=this.layer.opacity,s=[],l="Others",r=e.outline;e.attributes.forEach((e=>{const t=new ee({color:e.color,outline:r}),l=e.label||e.valueExpressionTitle||e.field;s.push({label:l,symbol:t})}));const i=s.length?[...s]:[];if(e.othersCategory?.color&&0!==e.othersCategory?.threshold){const t=new ee({color:e.othersCategory.color,outline:r});s.push({label:e.othersCategory.label||l,symbol:t})}if(e.defaultColor?.a){const t=new ee({color:e.defaultColor,outline:r});s.push({label:e.defaultLabel,symbol:t})}const n=await this._getVisualVariableLegendElements(e,this.layer)||[];if(s.length){n.unshift({type:"symbol-table",title:null,infos:s});const t=i.filter((e=>e.label!==l)).map((e=>e.symbol.color)).filter(Boolean),a=O(t,{holePercentage:e.holePercentage,backgroundColor:e.backgroundFillSymbol?.color,effectList:this.effectList,outline:r});n.unshift({type:"pie-chart-ramp",title:this._getRendererTitle(e,this.layer),infos:s,preview:a})}const a=n.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]).filter((e=>!!e?.symbol&&!e?.preview)).map((e=>this._getSymbolPreview(e,t,{effectList:this.effectList})));return await d(a),n}async _constructRendererLegendElements(e,t={}){const{title:s,sublayer:l}=t,r=l||this.layer;let i=await this._loadRenderer(e);this._hasColorRamp=!1,this._hasOpacityRamp=!1,this._hasSizeRamp=!1,this._scaleDrivenSizeVariable=null;const n=await this._getVisualVariableLegendElements(i,r)||[],a={type:"symbol-table",title:s||this._getRendererTitle(i,r),infos:[]};let o=null,u=!1;const y=new Set;if(ye(i)&&!this._hasSizeRamp){const e=await X(i);a.infos.push({label:null,symbol:e})}else if(Ue(i)){let e=s;const t=ke(i)?"univariate-above-and-below-ramp":"univariate-color-size-ramp",l=n.findIndex((e=>"color-ramp"===e.type)),r=-1!==l?n.splice(l,1)[0]:null,a=n.findIndex((e=>"size-ramp"===e.type)),o=-1!==a?n.splice(a,1)[0]:null,c=[];r&&(e=r.title,c.push(r)),o&&(e=o.title,c.push(o)),c.length>0&&n.push({type:t,title:e,infos:c})}else if(_e(i)){const e=N(i);n.push({type:"heatmap-ramp",title:s||i.legendOptions?.title,infos:e,preview:x(e.map((e=>e.color)),{effectList:this.effectList})})}else if(Se(i)){const e=i&&i.authoringInfo;if(e&&"relationship"===e.type){const{focus:t,numClasses:s,field1:l,field2:o}=e;if(s&&l&&o){const e=[l,o];let c=q(t)||0;for(const t of e){const{field:e,normalizationField:s,label:l}=t,i=l||{field:this._getFieldAlias(e,r),normField:s&&this._getFieldAlias(s,r)},n=Ne.clone();n.angle=c,a.infos.push({label:i,symbol:n}),y.add(n),c+=90}const u=W({focus:t,numClasses:s,infos:i.uniqueValueInfos});n.unshift(u)}}else{const e=i.field;i.uniqueValueInfos.forEach((t=>{t.symbol&&a.infos.push({label:t.label||this._getDomainName(e,t.value,r)||t.value,value:t.value,symbol:t.symbol})}))}i.defaultSymbol&&(a.infos.push({label:i.defaultLabel||"others",symbol:i.defaultSymbol}),u=!0)}else if(be(i)){o=this._isUnclassedRenderer(i);(!o||!this._hasSizeRamp)&&(i.classBreakInfos.forEach((e=>{e.symbol&&a.infos.unshift({label:e.label||(o?null:e.minValue+" - "+e.maxValue),value:[e.minValue,e.maxValue],symbol:e.symbol})})),o&&(a.title=null),this._updateInfosforClassedSizeRenderer(i,a.infos)),i.defaultSymbol&&!o&&(a.infos.push({label:i.defaultLabel||"others",symbol:i.defaultSymbol}),u=!0)}else if(fe(i))if(Me(this.layer)||Ae(this.layer)){const e=this._constructTileImageryStretchRendererElements(i);Be(e)?n.push(e):a.infos=e}else{const e=this.layer;let t,s;i.statistics&&i.statistics.length&&(t=null!=i.statistics[0].min?i.statistics[0].min:i.statistics[0][0],s=null!=i.statistics[0].max?i.statistics[0].max:i.statistics[0][1]);let l=[];const r=c(e.renderingRule?await e.generateRasterInfo(e.renderingRule):e.serviceRasterInfo),o=r.keyProperties.BandProperties,u=ce[e.rasterInfo.pixelType.toLowerCase()];1===r.bandCount||e.bandIds&&1===e.bandIds.length?(t=null!=t?t:r.statistics?r.statistics[e.bandIds[0]].min:u[0],s=null!=s?s:r.statistics?r.statistics[e.bandIds[0]].max:u[1],t||s?n.push(this._getStretchLegendElements(i,{min:t,max:s})):this._getServerSideLegend()):r.bandCount>=3?o&&o.length>=r.bandCount?e.bandIds&&3===e.bandIds.length?(l=e.bandIds.map((e=>o[e].BandName)),a.infos=this._createSymbolTableElementMultiBand(l)):"lerc"===e.format?(l=[0,1,2].map((e=>o[e].BandName)),a.infos=this._createSymbolTableElementMultiBand(l)):this._getServerSideLegend():"lerc"===e.format?(l=["band1","band2","band3"],a.infos=this._createSymbolTableElementMultiBand(l)):this._getServerSideLegend():this._getServerSideLegend()}else if(me(i))i.colormapInfos.forEach((e=>{a.infos.push({label:e.label,value:e.value,symbol:this._getAppliedCloneSymbol(de,e.color)})}));else if(ge(i)){let e=i.symbol;switch(t.geometryType){case"point":e="pointSymbol"in r&&r.pointSymbol;break;case"polyline":e="lineSymbol"in r&&r.lineSymbol;break;case"polygon":e="polygonSymbol"in r&&r.polygonSymbol}i.symbol&&!this._hasSizeRamp&&a.infos.push({label:i.label,symbol:e})}else if(he(i)){i.outputUnit&&(this.title="("+i.toJSON().outputUnit+")"),a.title=i.attributeField;const e=i.getClassBreakInfos();e?.length?e.forEach((e=>{a.infos.push({label:e.minValue+" - "+e.maxValue,symbol:e.symbol})})):a.infos.push({label:i.attributeField,symbol:i.getDefaultSymbol()})}else pe(i)&&n.push(this._getStretchLegendElements(i,{min:0,max:255}));const h=i.defaultSymbol;!h||u||ge(i)||o&&!this._hasColorRamp&&!this._hasSizeRamp&&!this._hasOpacityRamp||n.push({type:"symbol-table",infos:[{label:i.defaultLabel||"others",symbol:h}]}),a.infos.length&&n.unshift(a);const m=null==t.opacity?this.opacity:t.opacity,f=this._isTallSymbol("visualVariables"in i&&i.visualVariables),p=Pe(this.layer)||Me(this.layer),g=n.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]).filter((e=>!!e?.symbol)).map((e=>this._getSymbolPreview(e,m,{isDefault:e.symbol===h,applyScaleDrivenSize:!y.has(e.symbol),symbolConfig:{isTall:f,isSquareFill:p},effectList:y.has(e.symbol)?null:this.effectList})));return i=null,await d(g),n}_getServerSideLegend(){setTimeout((()=>this.buildLegendElementsForTools()),0)}_getAllInfos(e){const t=e?.infos;return t?t.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]):[e]}_constructTileImageryStretchRendererElements(e){const t=this.layer,s=t.rasterInfo,l=s.bandCount||e.statistics.length;let r,i,n=[];const a=s.keyProperties&&s.keyProperties.BandProperties,o=e?.statistics?.length?e.statistics:s?.statistics;if(o)r=void 0!==o[0].min?o[0].min:o[0][0],i=o[0].max||o[0][1];else{const e=ce[t.rasterInfo.pixelType.toLowerCase()];r=e[0],i=e[1]}if(t.hasStandardTime()&&(r=t.getStandardTimeValue(r),i=t.getStandardTimeValue(i)),1===s.bandCount||1===t.bandIds?.length)return this._getStretchLegendElements(e,{min:r,max:i});function c(e){const l=(t?.bandIds?.length?t.bandIds:Array.from(Array(Math.min(s.bandCount,3)).keys())).map((t=>e&&e[t]&&e[t].BandName||"band"+(t+1)));return l.length<3?l.push(l[1]):l.length>3&&l.splice(3),l}return n=a&&a.length>=l?c(a):c(),this._createSymbolTableElementMultiBand(n)}_getStretchLegendElements(e,t){const s=e.colorRamp,l=U(s,t);return{type:"stretch-ramp",title:"",infos:l,preview:x(l.map((e=>e.color)))}}async _getSizeLegendElement(e,t,s,l){return{type:"size-ramp",title:this._hasClusterSizeVariable?this._getClusterTitle(t):e,infos:await $(s,t,await K(s),this.scale,this.view.type,l)}}_createSymbolTableElementMultiBand(e){const t=[],s=["red","green","blue"];return e.forEach(((e,l)=>{t.push({label:{colorName:s[l],bandName:e},src:Y[l],opacity:this.opacity??1})})),t}_updateInfosforClassedSizeRenderer(e,t){const s=e.authoringInfo&&"class-breaks-size"===e.authoringInfo.type,l=e.classBreakInfos.some((e=>P(e.symbol)));if(s&&l){const s=G,l=J,r=e.classBreakInfos.length,i=(s-l)/(r>1?r-1:r);t.forEach(((e,t)=>{e.size=s-i*t}))}}_isTallSymbol(e){let t=!1,s=!1;if(e)for(let l=0;l<e.length&&(!t||!s);l++){const r=e[l];"size"===r.type&&("height"===r.axis&&(t=!0),"width-and-depth"===r.axis&&(s=!0))}return t&&s}async _getSymbolPreview(e,t,s){let l=!s?.isDefault&&null==e.size&&this._hasSizeRamp?g(T.size):e.size;if(this._scaleDrivenSizeVariable&&s?.applyScaleDrivenSize){const{getSize:t}=await import("../../../renderers/visualVariables/support/visualVariableUtils.js");l=t(this._scaleDrivenSizeVariable,null,{view:this.view.type,scale:this.scale,shape:"simple-marker"===e.symbol.type?e.symbol.style:null})}return D(e.symbol,{size:l,opacity:t,scale:!1,symbolConfig:s?.symbolConfig,effectView:s?.effectList}).then((t=>(e.preview=t,e))).catch((()=>(e.preview=null,e)))}async _loadRenderer(e){const t=[],s=this.layer;e=e.clone(),this._hasClusterSizeVariable=!1;const l="visualVariables"in e&&e.visualVariables?.some((e=>"size"===e.type&&"outline"!==e.target&&!ae.test(e.valueExpression)));if(e&&"visualVariables"in e&&!l&&"featureReduction"in s&&"cluster"===s.featureReduction?.type){const t=this.layerView._effectiveRenderer,l=c(M(t,this.view));if(l){const t=s.featureReduction;if("clusterMinSize"in t&&"clusterMaxSize"in t){const{clusterMinSize:e,clusterMaxSize:s}=t;l.legendOptions=new V({showLegend:e!==s})}const r=e.visualVariables||[];e.visualVariables=r.concat([l]),this._hasClusterSizeVariable=!0}}const r=await K(e);if(be(e)||Se(e)){const s=(e.classBreakInfos||e.uniqueValueInfos).map((e=>this._fetchSymbol(e.symbol,r).then((t=>{e.symbol=t})).catch((()=>{e.symbol=null}))));Array.prototype.push.apply(t,s)}return t.push(this._fetchSymbol(e.symbol||e.defaultSymbol,e.defaultSymbol?null:r).then((t=>{this._applySymbolToRenderer(e,t,ge(e))})).catch((()=>{this._applySymbolToRenderer(e,null,ge(e))}))),d(t).then((()=>e))}_applySymbolToRenderer(e,t,s){s?e.symbol=t:e.defaultSymbol=t}async _fetchSymbol(e,t){if(!e)throw new Error;if("web-style"===e.type){const s=this._webStyleSymbolCache;try{const l=await("2d"===this.view.type?e.fetchCIMSymbol({cache:s}):e.fetchSymbol({cache:s}));return this._getAppliedCloneSymbol(l,t)}catch{throw se.warn("Fetching web-style failed!"),new Error}}return this._getAppliedCloneSymbol(e,t)}_getAppliedCloneSymbol(e,s){if(!e||!s)return e;const l=e.clone(),r=s&&s.toRgba();return l.type.includes("3d")?this._applyColorTo3dSymbol(l,r):"cim"===l.type?F(l,s):l.color&&(l.color=new t(r||l.color)),l}_applyColorTo3dSymbol(e,s){s&&e.symbolLayers.forEach((e=>{e&&(e.material||(e.material={}),e.material.color=new t(s))}))}async _getVisualVariableLegendElements(e,t){if(!("visualVariables"in e)||!e.visualVariables||"vector-field"===e.type)return null;const s=e.visualVariables,l=[],r=[],i=[];for(const u of s)"color"===u.type?l.push(u):"size"===u.type?r.push(u):"opacity"===u.type&&i.push(u);const n=[...l,...r,...i];let a,o;if(0===l.length&&be(e)&&e.classBreakInfos&&1===e.classBreakInfos.length){const t=e.classBreakInfos[0];a=t&&t.symbol}if(0===l.length&&ge(e)&&(a=e.symbol),a)if(a.type.includes("3d")){const e=a.symbolLayers.getItemAt(0);"water"===e.type?u(e.color)&&(o=e.color):u(e.material)&&u(e.material.color)&&(o=e.material.color)}else a.url||(o=a.color);const c=this.effectList;return(await Promise.all(n.map((async s=>{if(!s.legendOptions||!1!==s.legendOptions.showLegend){const l=ye(e)?s.field:this._getRampTitle(s,t);let r=null;const i="getField"in t&&t.getField&&t.getField(s.field),n=i&&C(i);if("color"===s.type){const e=await k(s,null,n);r={type:"color-ramp",title:l,infos:e,preview:x(e.map((e=>e.color)),{effectList:c})},this._hasColorRamp||(this._hasColorRamp=!(null==r.infos||!r.infos.length))}else if("size"===s.type&&"outline"!==s.target)ae.test(s.valueExpression)?this._hasClusterSizeVariable||(this._scaleDrivenSizeVariable=s):(r=await this._getSizeLegendElement(l,s,e,n),this._hasSizeRamp||(this._hasSizeRamp=!(null==r.infos||!r.infos.length)));else if("opacity"===s.type){const e=await k(s,o,n);r={type:"opacity-ramp",title:l,infos:e,preview:x(e.map((e=>e.color)),{effectList:c})},this._hasOpacityRamp||(this._hasOpacityRamp=!(null==r.infos||!r.infos.length))}return r&&r.infos?r:null}})))).filter((e=>!!e))}_getDomainName(e,t,s){if(e&&"function"!=typeof e){const l="getField"in s&&s.getField&&s.getField(e),r=l&&"getFieldDomain"in s&&s.getFieldDomain?s.getFieldDomain(l.name):null;return r&&"coded-value"===r.type?r.getName(t):null}return null}_getClusterTitle(e){const t=this.layer,s=e.field;if("featureReduction"in t&&t.featureReduction&&"cluster"===t.featureReduction.type){const e=t.featureReduction,l="popupTemplate"in e&&e.popupTemplate,r=l&&l.fieldInfos;if(r)for(const t of r)if(t.fieldName===s)return"cluster_count"===s?t.label||{showCount:!0}:t.label}return{showCount:!0}}_getRampTitle(e,t){let s=e.field,l=e.normalizationField,r=!1,i=!1,n=!1,a=null;s="function"==typeof s?null:s,l="function"==typeof l?null:l;const o=e.legendOptions&&e.legendOptions.title;if(null!=o)a=o;else if(e.valueExpressionTitle)a=e.valueExpressionTitle;else{if("renderer"in t&&t.renderer&&"authoringInfo"in t.renderer&&t.renderer.authoringInfo&&t.renderer.authoringInfo.visualVariables){const e=t.renderer.authoringInfo.visualVariables;for(let t=0;t<e.length;t++){const s=e[t];if("color"===s.type){if("ratio"===s.style){r=!0;break}if("percent"===s.style){i=!0;break}if("percent-of-total"===s.style){n=!0;break}}}}a={field:s&&this._getFieldAlias(s,t),normField:l&&this._getFieldAlias(l,t),ratio:r,ratioPercent:i,ratioPercentTotal:n}}return a}_getRendererTitle(e,t){const s=e;if(s.legendOptions&&s.legendOptions.title)return s.legendOptions.title;if(s.valueExpressionTitle)return s.valueExpressionTitle;let l=s.field,r=null,i=null;be(s)&&(r=s.normalizationField,i="percent-of-total"===s.normalizationType),l="function"==typeof l?null:l,r="function"==typeof r?null:r;let n=null;return(l||r)&&(n={field:l&&this._getFieldAlias(l,t),normField:r&&this._getFieldAlias(r,t),normByPct:i}),n}_getFieldAlias(e,t){const s="popupTemplate"in t&&t.popupTemplate,l=s&&s.fieldInfos;let r=null;l&&l.some((t=>e===t.fieldName&&(r=t,!0)));let i=null;"getField"in t&&t.getField?i=t.getField(e):"fieldsIndex"in t&&t.fieldsIndex&&(i=t.fieldsIndex.get(e));const n=r||i;let a=null;return n&&(a=r&&r.label||i&&i.alias||"name"in n&&n.name||"fieldName"in n&&n.fieldName),a}_isUnclassedRenderer(e){const t=e.visualVariables;let s=!1;return be(e)&&e.classBreakInfos&&1===e.classBreakInfos.length&&t&&(s=e.field?t.some((t=>!(!t||e.field!==t.field||(e.normalizationField||t.normalizationField)&&e.normalizationField!==t.normalizationField))):!!t.length),s}};e([S()],We.prototype,"children",void 0),e([S({readOnly:!0})],We.prototype,"effectList",null),e([S()],We.prototype,"layerView",void 0),e([S()],We.prototype,"layer",void 0),e([S()],We.prototype,"legendElements",void 0),e([S({readOnly:!0})],We.prototype,"opacity",null),e([S()],We.prototype,"parent",void 0),e([S({readOnly:!0,dependsOn:[]})],We.prototype,"ready",null),e([S()],We.prototype,"hideLayersNotInCurrentView",void 0),e([S()],We.prototype,"keepCacheOnDestroy",void 0),e([S()],We.prototype,"respectLayerVisibility",void 0),e([S({readOnly:!0})],We.prototype,"scale",null),e([S()],We.prototype,"sublayerIds",void 0),e([S({readOnly:!0})],We.prototype,"isScaleDriven",null),e([S()],We.prototype,"title",void 0),e([S({readOnly:!0,dependsOn:["ready"],value:0})],We.prototype,"version",null),e([S()],We.prototype,"view",void 0),We=e([_("esri.widgets.Legend.support.ActiveLayerInfo")],We);const $e=We;export{$e as default};
|
|
5
|
+
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import{addTokenParameter as s}from"../../../kernel.js";import l from"../../../request.js";import"../../../symbols.js";import r from"../../../core/Accessor.js";import i from"../../../core/Collection.js";import n from"../../../core/Handles.js";import{JSONMap as a}from"../../../core/jsonMap.js";import o from"../../../core/Logger.js";import{unwrap as u,isSome as c}from"../../../core/maybe.js";import{eachAlways as d,debounce as y}from"../../../core/promiseUtils.js";import{on as h,watch as m,whenOnce as f,initial as p}from"../../../core/reactiveUtils.js";import{px2pt as g}from"../../../core/screenUtils.js";import{addQueryParameters as b}from"../../../core/urlUtils.js";import{property as S}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as _}from"../../../core/accessorSupport/decorators/subclass.js";import{OriginId as v}from"../../../core/accessorSupport/PropertyOrigin.js";import{EffectView as w}from"../../../layers/effects/EffectView.js";import{effectFunctionsFromJSON as L}from"../../../layers/effects/jsonUtils.js";import{ExportImageParameters as E}from"../../../layers/support/ExportImageParameters.js";import{isDateField as C}from"../../../layers/support/fieldUtils.js";import{fromJSON as I}from"../../../renderers/support/jsonUtils.js";import{isSupportedRenderer3D as R}from"../../../renderers/support/rendererConversion.js";import V from"../../../renderers/visualVariables/support/SizeVariableLegendOptions.js";import{applyCIMSymbolColor as F}from"../../../symbols/support/cimSymbolUtils.js";import{SymbolSizeDefaults as T}from"../../../symbols/support/previewUtils.js";import{renderSymbol as z}from"../../../symbols/support/renderUtils.js";import{renderColorRampPreviewHTML as x,renderDotDensityPreviewHTML as j,renderPieChartPreviewHTML as D,renderPreviewHTML as O}from"../../../symbols/support/symbolUtils.js";import{isVolumetricSymbol as P}from"../../../symbols/support/utils.js";import{getClusterSizeVariable as M}from"./clusterUtils.js";import{getColorFromPointCloudStops as A,getRampStopsForPointCloud as B,getStrectchRampStops as U,getRampStops as k}from"./colorRampUtils.js";import{getHeatmapRampStops as N}from"./heatmapRampUtils.js";import{getRotationAngleForFocus as q,getRelationshipRampElement as W}from"./relationshipRampUtils.js";import{getRampStops as $,REAL_WORLD_MAX_SIZE as G,REAL_WORLD_MIN_SIZE as J}from"./sizeRampUtils.js";import{SPECIAL_CHARS_LESS_THAN as Q,SPECIAL_CHARS_GREATER_THAN as H,getSymbolForFlowRenderer as X,getMedianColor as K,RGB_IMG_SOURCE as Y}from"./utils.js";import{formatNumberLabel as Z}from"../../smartMapping/support/utils.js";import ee from"../../../symbols/SimpleMarkerSymbol.js";import te from"../../../symbols/SimpleFillSymbol.js";const se=o.getLogger("esri.widgets.Legend.support.ActiveLayerInfo"),le="https://utility.arcgis.com/sharing/tools/legend",re="esri.layers.ImageryLayer",ie="esri.layers.ImageryTileLayer",ne="esri.layers.WCSLayer",ae=/^\s*(return\s+)?\$view\.scale\s*(;)?\s*$/i,oe=new a({esriGeometryPoint:"point",esriGeometryMultipoint:"multipoint",esriGeometryPolyline:"polyline",esriGeometryPolygon:"polygon",esriGeometryMultiPatch:"multipatch"}),ue={u1:[0,1],u2:[0,3],u4:[0,15],u8:[0,255],s8:[-128,127],u16:[0,65535],s16:[-32768,32767],u32:[0,4294967295],s32:[-2147483648,2147483647],f32:[-34e38,34e38],f64:[-Number.MAX_VALUE,Number.MAX_VALUE]},ce=new ee({size:6,outline:{color:[128,128,128,.5],width:.5}}),de=new te({style:"solid"});function ye(e){return"flow"===e.type}function he(e){return"vector-field"===e.type}function me(e){return"raster-colormap"===e.type}function fe(e){return"raster-stretch"===e.type}function pe(e){return"raster-shaded-relief"===e.type}function ge(e){return"esri.renderers.SimpleRenderer"===e.declaredClass}function be(e){return"esri.renderers.ClassBreaksRenderer"===e.declaredClass}function Se(e){return"esri.renderers.UniqueValueRenderer"===e.declaredClass}function _e(e){return"esri.renderers.HeatmapRenderer"===e.declaredClass}function ve(e){return Le(e)||Ee(e)||Ce(e)||we(e)}function we(e){return"esri.renderers.PointCloudRGBRenderer"===e.declaredClass}function Le(e){return"esri.renderers.PointCloudClassBreaksRenderer"===e.declaredClass}function Ee(e){return"esri.renderers.PointCloudStretchRenderer"===e.declaredClass}function Ce(e){return"esri.renderers.PointCloudUniqueValueRenderer"===e.declaredClass}function Ie(e){return"esri.renderers.DotDensityRenderer"===e.declaredClass}function Re(e){return"esri.renderers.PieChartRenderer"===e.declaredClass}function Ve(e,t){return ge(e)||be(e)||Se(e)||_e(e)||Ie(e)||Re(e)?"2d"===t.type||R(e):fe(e)||me(e)||pe(e)||Le(e)||Ee(e)||Ce(e)||he(e)||ye(e)}function Fe(e){return"esri.layers.BuildingSceneLayer"===e.declaredClass}function Te(e){return"esri.layers.VoxelLayer"===e.declaredClass}function ze(e){return"esri.layers.WMSLayer"===e.declaredClass}function xe(e){return"esri.layers.WMTSLayer"===e.declaredClass}function je(e){return"esri.layers.MapImageLayer"===e.declaredClass}function De(e){return"esri.layers.TileLayer"===e.declaredClass}function Oe(e){return"esri.layers.FeatureLayer"===e.declaredClass}function Pe(e){return e.declaredClass===re}function Me(e){return e.declaredClass===ie}function Ae(e){return e.declaredClass===ne}function Be(e){return"stretch-ramp"===e.type}function Ue(e){return"univariate-color-size"===("authoringInfo"in e&&e?.authoringInfo)?.type}function ke(e){const t="authoringInfo"in e&&e?.authoringInfo;return"univariate-color-size"===t?.type&&"above-and-below"===t?.univariateTheme}const Ne=new ee({style:"path",path:"M10,5 L5,0 0,5 M5,0 L5,15",size:15,outline:{width:1,color:[85,85,85,1]}});let qe={},We=class extends r{constructor(e){super(e),this._handles=new n,this._hasColorRamp=!1,this._hasOpacityRamp=!1,this._hasSizeRamp=!1,this._webStyleSymbolCache=new Map,this._dotDensityUrlCache=new Map,this._scaleDrivenSizeVariable=null,this._hasClusterSizeVariable=!1,this.children=new i,this.layerView=null,this.layer=null,this.legendElements=[],this.parent=null,this.hideLayersNotInCurrentView=!1,this.keepCacheOnDestroy=!1,this.respectLayerVisibility=!0,this.sublayerIds=[],this.title=null,this.view=null}initialize(){const e=()=>this.notifyChange("ready");this._handles.add([h((()=>this.children),"change",(t=>{const{added:s,removed:l}=t,r=this._handles;s.forEach((t=>{const s=`activeLayerInfo-ready-watcher-${t.layer.uid}`;r.add(m((()=>t.ready),e,p),s)})),l.forEach((e=>r.remove(e.layer.uid))),e()}))]),this.keepCacheOnDestroy||(qe={})}destroy(){this._handles.destroy(),this._handles=null,this._webStyleSymbolCache=null,this._dotDensityUrlCache=null,this._scaleDrivenSizeVariable=null,this.keepCacheOnDestroy||(qe=null)}get effectList(){const e=this.layer;let t=null;return"effect"in e&&e.effect&&(t=new w,t.effect=e.effect,t.end(),t.scale=this.scale),t}get opacity(){const e=this.layer.opacity,t=this.parent?.opacity,s=this.layer.parent,l=s&&"uid"in s?this._getParentLayerOpacity(s):null;return null!=t?t*e:null!=l?l*e:e}get ready(){return null===this.layer||(this.children.length>0?this._isGroupActive():this.legendElements.length>0)}get scale(){return this.view&&this.view.scale}get isScaleDriven(){const e=this.layer;if(null===e)return!1;if("effect"in e&&e.effect&&Array.isArray(e.effect))return!0;if("featureReduction"in e&&e.featureReduction){if("cluster"===e.featureReduction.type)return!0;if("binning"===e.featureReduction.type&&"renderer"in e.featureReduction&&e.featureReduction.renderer)return this._isRendererScaleDriven(e.featureReduction.renderer)}return"renderer"in e&&e.renderer?this._isRendererScaleDriven(e.renderer):this._isLayerScaleDriven(this.layer)}get version(){return this._get("version")+1}async buildLegendElementsForFeatureCollections(e){if(!(!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView()))return this.legendElements=[],void this.notifyChange("ready");const t=Array.from(e,(e=>{if(Oe(e))return this._getRendererLegendElements(e.renderer,{title:e.title});if(e.featureSet&&e.featureSet.features.length){const t=e.layerDefinition,s=t&&t.drawingInfo,l=s&&I(s.renderer),r=oe.read(t.geometryType);return l?this._getRendererLegendElements(l,{title:e.name,geometryType:r}):(se.warn("drawingInfo not available!"),null)}return null}));try{const e=[];await d(t).then((t=>{t.forEach((({value:t})=>t&&e.push(...t)))})),this.legendElements=e,this.notifyChange("ready")}catch(s){se.warn("error while building legend for layer!",s)}}async buildLegendElementsForRenderer(e){try{const t=!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView();this.legendElements=t?await this._getRendererLegendElements(e):[],this.notifyChange("ready")}catch(t){se.warn("error while building legend for layer!",t)}}async buildLegendElementsForTools(){const e=this.layer;if(Te(e))this._constructLegendElementsForVoxellayer();else if(xe(e))this._constructLegendElementsForWMTSlayer();else if(ze(e))await this._constructLegendElementsForWMSSublayers();else if(Fe(e))await this._constructLegendElementsForBuildingSceneLayer();else if(je(e)||De(e)||Fe(e))await this._constructLegendElementsForSublayers();else{this._handles.remove("imageryLayers-watcher");let t="default";if(Pe(e)){t=(e?.renderingRule?.functionName||"default")+"_"+(e.bandIds?.length?e.bandIds.join(""):"###")}await this._getLegendLayers(`${e.uid}-${t}`).then((async t=>{this.legendElements=[],this.notifyChange("ready");const s=t.map((async t=>{if(Pe(e)||Me(e)){const t=m((()=>["renderingRule"in e&&e.renderingRule,e.bandIds]),(()=>y((async()=>{qe.default=null,e.renderer?await this.buildLegendElementsForRenderer(e.renderer):await this.buildLegendElementsForTools()}))()));this._handles.add(t,"imageryLayers-watcher")}const s=this._generateSymbolTableElementForLegendLayer(t);s&&s.infos.length&&(Pe(e)&&(s.title=e.title),this.legendElements.push(s)),this.notifyChange("ready")}));await d(s)})).catch((e=>{se.warn("Request to server for legend has failed!",e)}))}}async _isLayerInCurrentView(){const e=this.layer,t=this.layerView,s=t&&"createQuery"in t&&"queryFeatureCount"in t;if(!s&&!(t&&"createQuery"in e&&"queryFeatureCount"in e))return!0;await f((()=>!t.updating));const l=s?"createQuery"in t&&t.createQuery():"createQuery"in e&&e.createQuery();l.geometry=this.view.extent;return 0!==(s?"queryFeatureCount"in t&&await t.queryFeatureCount(l):"queryFeatureCount"in e&&await e.queryFeatureCount(l))}_getParentLayerOpacity(e){let t=1;const s=e.parent;return s&&"uid"in s&&(t=this._getParentLayerOpacity(s)),e.opacity*t}_isGroupActive(){const e=this.children;return!!e.length&&e.some((e=>e.ready))}_isRendererScaleDriven(e){if("dot-density"===e.type)return!0;const t="valueExpression"in e&&e.valueExpression;if(ae.test(t))return!0;const s="visualVariables"in e&&e.visualVariables;return!!s&&s.some((e=>this._isScaleDrivenSizeVariable(e)))}_isScaleDrivenSizeVariable(e){if(e&&"size"!==e.type)return!1;const t=e,s=t.minSize,l=t.maxSize;return"object"==typeof s&&s?this._isScaleDrivenSizeVariable(s):"object"==typeof l&&l?this._isScaleDrivenSizeVariable(l):!!t.expression||ae.test(t.valueExpression)}_isLayerScaleDriven(e){if("minScale"in e&&e.minScale>0||"maxScale"in e&&e.maxScale>0)return!0;if("sublayers"in e&&e.sublayers)return e.sublayers.some((e=>this._isLayerScaleDriven(e)));const t=e.parent;if(!1===e.loaded&&t&&je(t)&&"source"in e&&e.source&&"map-layer"===e.source.type)for(const s of t.sourceJSON.layers)if(s.id===e.source.mapLayerId&&(s.minScale>0||s.maxScale>0))return!0;return!1}async _constructLegendElementsForVoxellayer(){this.legendElements=[],this._handles.remove("voxel-style-watcher");const e=this.layer;this._handles.add(m((()=>e.currentVariableId),(()=>this._constructLegendElementsForVoxellayer())),"voxel-style-watcher");const t=u(e.getVariableStyle(null)),s=[];if(t)if(t.uniqueValues?.length){const e=[];t.uniqueValues.forEach((t=>{t.enabled&&e.push({label:t.label||`${t.value}`,value:t.value,symbol:new te({color:t.color,outline:null})})})),e.length&&s.push({type:"symbol-table",title:t.label,infos:e})}else if(t.transferFunction){const{colorStops:e,stretchRange:l}=t.transferFunction,r=e.toArray().reverse(),i=l.map(((e,t)=>`${0===t?Q:H} ${Z(e)}`)).reverse(),n=r.map((e=>({color:e.color,value:null,label:null})));n[0].label=i[0],n[n.length-1].label=i[1],s.push({type:"color-ramp",title:t.label,infos:n,preview:x(r.map((e=>e.color)))})}const l=e.opacity,r=s.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]).filter((e=>!!e?.symbol)).map((e=>this._getSymbolPreview(e,l)));await d(r),this.legendElements=s,this.notifyChange("ready")}_constructLegendElementsForWMTSlayer(){this.legendElements=[],this._handles.remove("wmts-activeLayer-watcher");const e=this.layer.activeLayer;if(this._handles.add(m((()=>{const{layer:e}=this;return e&&"activeLayer"in e&&e.activeLayer}),(()=>this._constructLegendElementsForWMTSlayer())),"wmts-activeLayer-watcher"),e.styleId&&e.styles){let t=null;e.styles.some((s=>e.styleId===s.id&&(t=s.legendUrl,!0))),t&&(this.legendElements=[{type:"symbol-table",title:e.title,infos:[{src:t,opacity:this.opacity}]}])}this.notifyChange("ready")}async _constructLegendElementsForWMSSublayers(){this.legendElements=[],this._handles.remove("wms-sublayers-watcher");const e=this.layer;let t=null;(e.customParameters||e.customLayerParameters)&&(t={...e.customParameters,...e.customLayerParameters}),this._handles.add(m((()=>{const{layer:e}=this;return e&&"sublayers"in e&&e.sublayers}),(()=>this._constructLegendElementsForWMSSublayers())),"wms-sublayers-watcher"),this.legendElements=await this._generateLegendElementsForWMSSublayers(e.sublayers,t),this.notifyChange("ready")}async _generateLegendElementsForWMSSublayers(e,t){const s=[];this._handles.add(e.on("change",(()=>this._constructLegendElementsForWMSSublayers())),"wms-sublayers-watcher");const l=e.toArray();for(const r of l){const e=m((()=>[r.title,r.visible,r.legendEnabled]),(()=>this._constructLegendElementsForWMSSublayers()));if(this._handles.add(e,"wms-sublayers-watcher"),!this.respectLayerVisibility||r.visible&&r.legendEnabled){const e=await this._generateSymbolTableElementForWMSSublayer(r,t);e&&e.infos.length&&s.unshift(e)}}return s}async _generateSymbolTableElementForWMSSublayer(e,t){if(!e.legendUrl&&e.sublayers){const s=(await this._generateLegendElementsForWMSSublayers(e.sublayers,t)).filter((e=>e));return{type:"symbol-table",title:e.title,infos:s}}return this._generateSymbolTableElementForLegendUrl(e,t)}async _generateSymbolTableElementForLegendUrl(e,t){let s=e.legendUrl;if(!s)return;const r={type:"symbol-table",title:e.title||e.name||e.id&&e.id+"",infos:[]};t&&(s=b(s,t));let i=null;const n=e.layer?.opacity;try{i=(await l(s,{responseType:"image"})).data,i&&(i.style.opacity=n)}catch{}return r.infos.push({src:s,preview:i,opacity:n}),r}_getLegendLayers(e,t){const s=qe&&qe[e];return s?Promise.resolve(s):this._legendRequest(t).then((t=>{const s=t.layers;return qe[e]=s,s}))}_legendRequest(e){const t=this.layer;let s={f:"json",dynamicLayers:e};if(Pe(t)){const e=t.exportImageServiceParameters.renderingRule;if(e&&(s.renderingRule=JSON.stringify(e.rasterFunctionDefinition||e.toJSON())),t.bandIds&&(s.bandIds=t.bandIds.join()),t.raster||t.viewId||t.customParameters){const{raster:e,viewId:l,customParameters:r}=t;s={raster:e,viewId:l,...s,...r}}}let r=t.url.replace(/(\/)+$/,"");if("version"in t&&t.version>=10.01){const e=r.indexOf("?");e>-1?r=r.substring(0,e)+"/legend"+r.substring(e):r+="/legend"}else{const e=r.toLowerCase().indexOf("/rest/"),t=r.substring(0,e)+r.substring(e+5,r.length);r=le+"?soapUrl="+encodeURI(t)+"&returnbytes=true"}return l(r,{query:s}).then((e=>e.data))}async _constructLegendElementsForBuildingSceneLayer(){this.legendElements=[],this._handles.remove("sublayers-watcher");const e=this.layer;this._handles.add(m((()=>e.sublayers),(()=>this._constructLegendElementsForBuildingSceneLayer())),"sublayers-watcher");try{this.legendElements=await this._generateLegendElementsForBuildingSublayers(e.sublayers,this.opacity),this.notifyChange("ready")}catch(t){se.warn("Request to server for legend has failed!",t)}}async _generateLegendElementsForBuildingSublayers(e,t){let s=[];this._handles.add(e.on("change",(()=>this._constructLegendElementsForBuildingSceneLayer())),"sublayers-watcher");const l=e.toArray();for(const r of l){const e=m((()=>["renderer"in r&&r.renderer,r.opacity,r.title,r.visible]),(()=>this._constructLegendElementsForBuildingSceneLayer()));if(this._handles.add(e,"sublayers-watcher"),!this.respectLayerVisibility||r.visible){const e=r&&null!=r.opacity?r.opacity:null,l=null!=e?e*t:t;if("building-group"===r.type){const e={type:"symbol-table",title:r.title,infos:[]},t=await this._generateLegendElementsForBuildingSublayers(r.sublayers,l);e.infos.push(...t),s=[e,...s]}else if(r.renderer){s=[...await this._getRendererLegendElements(r.renderer,{title:r.title,opacity:l,sublayer:r}),...s]}}}return s.filter((e=>!!e&&(!("infos"in e)||e.infos.length>0)))}async _constructLegendElementsForSublayers(){this.legendElements=[],this._handles.remove("sublayers-watcher");const e=this.layer;this._handles.add(m((()=>e.sublayers),(()=>this._constructLegendElementsForSublayers)),"sublayers-watcher");try{this.legendElements=await this._generateLegendElementsForSublayers(e.sublayers,this.opacity),this.notifyChange("ready")}catch(t){se.warn("Request to server for legend has failed!",t)}}async _generateLegendElementsForSublayers(e,t,s){const l=this.layer;let r=[];this._handles.add(e.on("change",(()=>this._constructLegendElementsForSublayers())),"sublayers-watcher");let i=e.toArray();!s&&this.sublayerIds&&this.sublayerIds.length&&(i=this.sublayerIds.map((e=>l.findSublayerById(e))).filter(Boolean));for(const n of i){const e=m((()=>[n.renderer,n.opacity,n.title,n.visible,n.legendEnabled]),(()=>this._constructLegendElementsForSublayers()));if(this._handles.add(e,"sublayers-watcher"),!this.respectLayerVisibility||n.visible&&n.legendEnabled&&this._isSublayerInScale(n)){const e=n&&null!=n.opacity?n.opacity:null,l=null!=e?e*t:t;if(n.renderer&&!n.sublayers&&n.originIdOf("renderer")>v.SERVICE){await n.load();r=[...await this._getRendererLegendElements(n.renderer,{title:n.title,opacity:l,sublayer:n}),...r]}else{const e=await this._generateSymbolTableElementForSublayer(n,l,s);e&&r.unshift(e)}}}return r.filter((e=>!!e&&(!("infos"in e)||e.infos.length>0)))}async _generateSymbolTableElementForSublayer(e,t,s){if(!s){s=new Map;const t=this.layer,l=e.source;let r=null;if(!(!l||"map-layer"===l.type&&l.mapLayerId===e.id&&(!l.gdbVersion||l.gdbVersion===("gdbVersion"in t&&t.gdbVersion)))||e.originIdOf("renderer")>v.SERVICE||e.originIdOf("labelingInfo")>v.SERVICE||e.originIdOf("labelsVisible")>v.SERVICE){const e=new E({layer:this.layer});r=e.hasDynamicLayers?e.dynamicLayers:null,e.destroy()}const i=r||`${t.uid}-default`;(await this._getLegendLayers(i,r)).forEach((e=>s.set(e.layerId,e)))}const l=s.get(e.id);if((!l||l?.subLayerIds&&l.defaultVisibility)&&e.sublayers){const l=await this._generateLegendElementsForSublayers(e.sublayers,t,s);return{type:"symbol-table",title:e.title,infos:l}}return this._generateSymbolTableElementForLegendLayer(l,e,t)}_generateSymbolTableElementForLegendLayer(e,t,s){if(!e||!e.legend||this.respectLayerVisibility&&!this._isLegendLayerInScale(e,t))return null;const l=t?.renderer;let r=t?.title||e.layerName;if(l&&(!t||t?.originIdOf("renderer")>v.SERVICE)){const e=t?.title||this._getRendererTitle(l,t);e&&(r&&"string"!=typeof e&&"title"in e&&(e.title=r),r=e)}const i={type:"symbol-table",title:r,legendType:e.legendType?e.legendType:null,infos:[]},n=t?this._sanitizeLegendForSublayer(e.legend.slice(),t):e.legend;return e.legendGroups?.length>0?e.legendGroups.forEach((t=>{const l={type:"symbol-table",title:t.heading,legendType:e.legendType?e.legendType:null,infos:this._generateSymbolTableElementInfosForLegendLayer(n.filter((e=>e.groupId===t.id)),e.layerId,s)};l.infos?.length>0&&i.infos.push(l)})):i.infos=this._generateSymbolTableElementInfosForLegendLayer(n,e.layerId,s),i.infos.length>0?i:null}_generateSymbolTableElementInfosForLegendLayer(e,t,l){return e.map((e=>{let r=e.url;if(e.imageData&&e.imageData.length>0)r=`data:image/png;base64,${e.imageData}`;else{if(0===r.indexOf("http"))return null;r=s(`${this.layer.url}/${t}/images/${r}`)}return{label:e.label,src:r,opacity:null==l?this.opacity:l,width:e.width,height:e.height}})).filter((e=>!!e))}_isSublayerInScale(e){const t=e.minScale||0,s=e.maxScale||0;return!(t>0&&t<this.scale||s>this.scale)}_isLegendLayerInScale(e,t){const s=t||this.layer;let l=null,r=null,i=!0;return!s.minScale&&0!==s.minScale||!s.maxScale&&0!==s.maxScale?(0===e.minScale&&s.tileInfo&&(l=s.tileInfo.lods[0].scale),0===e.maxScale&&s.tileInfo&&(r=s.tileInfo.lods[s.tileInfo.lods.length-1].scale)):(l=Math.min(s.minScale,e.minScale)||s.minScale||e.minScale,r=Math.max(s.maxScale,e.maxScale)),(l>0&&l<this.scale||r>this.scale)&&(i=!1),i}_sanitizeLegendForSublayer(e,t){if("version"in this.layer&&this.layer.version<10.1||0===e.length)return e;const s=t.renderer,l=e.some((e=>e.values));let r=null,i=null;return l&&e.some(((e,t)=>(e.values||(r=t,i=e,i.label||(i.label="others")),null!=i))),s?"unique-value"===s.type?i&&(e.splice(r,1),e.push(i)):"class-breaks"===s.type&&(i&&e.splice(r,1),e.reverse(),i&&e.push(i)):i&&(e.splice(r,1),e.push(i)),e}async _getRendererLegendElements(e,t={}){return Ve(e,this.view)?ve(e)?this._constructPointCloudRendererLegendElements(e,t):Ie(e)?this._constructDotDensityRendererLegendElements(e):Re(e)?this._constructPieChartRendererLegendElements(e):this._constructRendererLegendElements(e,t):(se.warn(`Renderer of type '${e.type}' not supported!`),[])}_getPointCloudRendererTitle(e){return e.legendOptions&&e.legendOptions.title||e.field}_constructPointCloudRendererLegendElements(e,t={}){const s=t.title,l=[];let r=null,i=null;if(Le(e))r={type:"symbol-table",title:s||this._getPointCloudRendererTitle(e),infos:[]},e.colorClassBreakInfos.forEach((e=>{r.infos.unshift({label:e.label||e.minValue+" - "+e.maxValue,value:[e.minValue,e.maxValue],symbol:this._getAppliedCloneSymbol(ce,e.color)})}));else if(Ee(e)){const t=e.stops;let l=null;if(t.length&&(1===t.length&&(l=t[0].color),!l)){const e=t[0].value,s=t[t.length-1].value;if(null!=e&&null!=s){l=A(e+(s-e)/2,t)}}r={type:"symbol-table",title:null,infos:[{label:null,value:null,symbol:this._getAppliedCloneSymbol(ce,l||ce.color)}]};const n=B(e.stops);i={type:"color-ramp",title:s||this._getPointCloudRendererTitle(e),infos:n,preview:x(n.map((e=>e.color)))}}else Ce(e)&&(r={type:"symbol-table",title:s||this._getPointCloudRendererTitle(e),infos:[]},e.colorUniqueValueInfos.forEach((e=>{r.infos.push({label:e.label||e.values.join(", "),value:e.values.join(", "),symbol:this._getAppliedCloneSymbol(ce,e.color)})})));r&&r.infos.length&&l.push(r),i&&i.infos.length&&l.push(i);const n=l.reduce(((e,t)=>e.concat(t.infos)),[]).filter((e=>!!e.symbol)).map((t=>this._getSymbolPreview(t,this.opacity,{symbolConfig:{applyColorModulation:!!e.colorModulation}})));return d(n).then((()=>l))}_getElementInfoForDotDensity(e,t){const{backgroundColor:s,outline:l,dotSize:r}=e,i=this.effectList?.effects.map((e=>e.toJSON())),n=L(i),a=r+"-"+t+"-"+s+"-"+(l&&JSON.stringify(l.toJSON()))+"-"+n,o=this._dotDensityUrlCache,u=o.has(a)?o.get(a):j(e,t);o.set(a,u);const c={shape:{type:"image",x:0,y:0,width:u.width,height:u.height,src:u.src},fill:null,stroke:null,offset:[0,0]},d=z([[c]],[u.width,u.height],{effectView:this.effectList});return{opacity:1,src:u.src,preview:d,width:u.width,height:u.height}}_constructDotDensityRendererLegendElements(e){const t=e.calculateDotValue(this.view.scale),s=e.legendOptions&&e.legendOptions.unit,l={type:"symbol-table",title:{value:t&&Math.round(t),unit:s||""},infos:[]};return e.attributes.forEach((t=>{const s=this._getElementInfoForDotDensity(e,t.color);s.label=t.label||t.valueExpressionTitle||t.field,l.infos.push(s)})),Promise.resolve([l])}async _constructPieChartRendererLegendElements(e){const t=this.layer.opacity,s=[],l="Others",r=e.outline;e.attributes.forEach((e=>{const t=new ee({color:e.color,outline:r}),l=e.label||e.valueExpressionTitle||e.field;s.push({label:l,symbol:t})}));const i=s.length?[...s]:[];if(e.othersCategory?.color&&0!==e.othersCategory?.threshold){const t=new ee({color:e.othersCategory.color,outline:r});s.push({label:e.othersCategory.label||l,symbol:t})}if(e.defaultColor?.a){const t=new ee({color:e.defaultColor,outline:r});s.push({label:e.defaultLabel,symbol:t})}const n=await this._getVisualVariableLegendElements(e,this.layer)||[];if(s.length){n.unshift({type:"symbol-table",title:null,infos:s});const t=i.filter((e=>e.label!==l)).map((e=>e.symbol.color)).filter(Boolean),a=D(t,{holePercentage:e.holePercentage,backgroundColor:e.backgroundFillSymbol?.color,effectList:this.effectList,outline:r});n.unshift({type:"pie-chart-ramp",title:this._getRendererTitle(e,this.layer),infos:s,preview:a})}const a=n.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]).filter((e=>!!e?.symbol&&!e?.preview)).map((e=>this._getSymbolPreview(e,t,{effectList:this.effectList})));return await d(a),n}async _constructRendererLegendElements(e,t={}){const{title:s,sublayer:l}=t,r=l||this.layer;let i=await this._loadRenderer(e);this._hasColorRamp=!1,this._hasOpacityRamp=!1,this._hasSizeRamp=!1,this._scaleDrivenSizeVariable=null;const n=await this._getVisualVariableLegendElements(i,r)||[],a={type:"symbol-table",title:s||this._getRendererTitle(i,r),infos:[]};let o=null,c=!1;const y=new Set;if(ye(i)&&!this._hasSizeRamp){const e=await X(i);a.infos.push({label:null,symbol:e})}else if(Ue(i)){let e=s;const t=ke(i)?"univariate-above-and-below-ramp":"univariate-color-size-ramp",l=n.findIndex((e=>"color-ramp"===e.type)),r=-1!==l?n.splice(l,1)[0]:null,a=n.findIndex((e=>"size-ramp"===e.type)),o=-1!==a?n.splice(a,1)[0]:null,u=[];r&&(e=r.title,u.push(r)),o&&(e=o.title,u.push(o)),u.length>0&&n.push({type:t,title:e,infos:u})}else if(_e(i)){const e=N(i);n.push({type:"heatmap-ramp",title:s||i.legendOptions?.title,infos:e,preview:x(e.map((e=>e.color)),{effectList:this.effectList})})}else if(Se(i)){const e=i&&i.authoringInfo;if(e&&"relationship"===e.type){const{focus:t,numClasses:s,field1:l,field2:o}=e;if(s&&l&&o){const e=[l,o];let u=q(t)||0;for(const t of e){const{field:e,normalizationField:s,label:l}=t,i=l||{field:this._getFieldAlias(e,r),normField:s&&this._getFieldAlias(s,r)},n=Ne.clone();n.angle=u,a.infos.push({label:i,symbol:n}),y.add(n),u+=90}const c=W({focus:t,numClasses:s,infos:i.uniqueValueInfos});n.unshift(c)}}else{const e=i.field;i.uniqueValueInfos.forEach((t=>{t.symbol&&a.infos.push({label:t.label||this._getDomainName(e,t.value,r)||t.value,value:t.value,symbol:t.symbol})}))}i.defaultSymbol&&(a.infos.push({label:i.defaultLabel||"others",symbol:i.defaultSymbol}),c=!0)}else if(be(i)){o=this._isUnclassedRenderer(i);(!o||!this._hasSizeRamp)&&(i.classBreakInfos.forEach((e=>{e.symbol&&a.infos.unshift({label:e.label||(o?null:e.minValue+" - "+e.maxValue),value:[e.minValue,e.maxValue],symbol:e.symbol})})),o&&(a.title=null),this._updateInfosforClassedSizeRenderer(i,a.infos)),i.defaultSymbol&&!o&&(a.infos.push({label:i.defaultLabel||"others",symbol:i.defaultSymbol}),c=!0)}else if(fe(i))if(Me(this.layer)||Ae(this.layer)){const e=this._constructTileImageryStretchRendererElements(i);Be(e)?n.push(e):a.infos=e}else{const e=this.layer;let t,s;i.statistics&&i.statistics.length&&(t=null!=i.statistics[0].min?i.statistics[0].min:i.statistics[0][0],s=null!=i.statistics[0].max?i.statistics[0].max:i.statistics[0][1]);let l=[];const r=u(e.renderingRule?await e.generateRasterInfo(e.renderingRule):e.serviceRasterInfo),o=r.keyProperties.BandProperties,c=ue[e.rasterInfo.pixelType.toLowerCase()];1===r.bandCount||e.bandIds&&1===e.bandIds.length?(t=null!=t?t:r.statistics?r.statistics[e.bandIds[0]].min:c[0],s=null!=s?s:r.statistics?r.statistics[e.bandIds[0]].max:c[1],t||s?n.push(this._getStretchLegendElements(i,{min:t,max:s})):this._getServerSideLegend()):r.bandCount>=3?o&&o.length>=r.bandCount?e.bandIds&&3===e.bandIds.length?(l=e.bandIds.map((e=>o[e].BandName)),a.infos=this._createSymbolTableElementMultiBand(l)):"lerc"===e.format?(l=[0,1,2].map((e=>o[e].BandName)),a.infos=this._createSymbolTableElementMultiBand(l)):this._getServerSideLegend():"lerc"===e.format?(l=["band1","band2","band3"],a.infos=this._createSymbolTableElementMultiBand(l)):this._getServerSideLegend():this._getServerSideLegend()}else if(me(i))i.colormapInfos.forEach((e=>{a.infos.push({label:e.label,value:e.value,symbol:this._getAppliedCloneSymbol(de,e.color)})}));else if(ge(i)){let e=i.symbol;switch(t.geometryType){case"point":e="pointSymbol"in r&&r.pointSymbol;break;case"polyline":e="lineSymbol"in r&&r.lineSymbol;break;case"polygon":e="polygonSymbol"in r&&r.polygonSymbol}i.symbol&&!this._hasSizeRamp&&a.infos.push({label:i.label,symbol:e})}else if(he(i)){i.outputUnit&&(this.title="("+i.toJSON().outputUnit+")"),a.title=i.attributeField;const e=i.getClassBreakInfos();e?.length?e.forEach((e=>{a.infos.push({label:e.minValue+" - "+e.maxValue,symbol:e.symbol})})):a.infos.push({label:i.attributeField,symbol:i.getDefaultSymbol()})}else pe(i)&&n.push(this._getStretchLegendElements(i,{min:0,max:255}));const h=i.defaultSymbol;!h||c||ge(i)||o&&!this._hasColorRamp&&!this._hasSizeRamp&&!this._hasOpacityRamp||n.push({type:"symbol-table",infos:[{label:i.defaultLabel||"others",symbol:h}]}),a.infos.length&&n.unshift(a);const m=null==t.opacity?this.opacity:t.opacity,f=this._isTallSymbol("visualVariables"in i&&i.visualVariables),p=Pe(this.layer)||Me(this.layer),g=n.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]).filter((e=>!!e?.symbol)).map((e=>this._getSymbolPreview(e,m,{isDefault:e.symbol===h,applyScaleDrivenSize:!y.has(e.symbol),symbolConfig:{isTall:f,isSquareFill:p},effectList:y.has(e.symbol)?null:this.effectList})));return i=null,await d(g),n}_getServerSideLegend(){setTimeout((()=>this.buildLegendElementsForTools()),0)}_getAllInfos(e){const t=e?.infos;return t?t.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]):[e]}_constructTileImageryStretchRendererElements(e){const t=this.layer,s=t.rasterInfo,l=s.bandCount||e.statistics.length;let r,i,n=[];const a=s.keyProperties&&s.keyProperties.BandProperties,o=e?.statistics?.length?e.statistics:s?.statistics;if(o)r=void 0!==o[0].min?o[0].min:o[0][0],i=o[0].max||o[0][1];else{const e=ue[t.rasterInfo.pixelType.toLowerCase()];r=e[0],i=e[1]}if(t.hasStandardTime()&&(r=t.getStandardTimeValue(r),i=t.getStandardTimeValue(i)),1===s.bandCount||1===t.bandIds?.length)return this._getStretchLegendElements(e,{min:r,max:i});function u(e){const l=(t?.bandIds?.length?t.bandIds:Array.from(Array(Math.min(s.bandCount,3)).keys())).map((t=>e&&e[t]&&e[t].BandName||"band"+(t+1)));return l.length<3?l.push(l[1]):l.length>3&&l.splice(3),l}return n=a&&a.length>=l?u(a):u(),this._createSymbolTableElementMultiBand(n)}_getStretchLegendElements(e,t){const s=e.colorRamp,l=U(s,t);return{type:"stretch-ramp",title:"",infos:l,preview:x(l.map((e=>e.color)))}}async _getSizeLegendElement(e,t,s,l){return{type:"size-ramp",title:this._hasClusterSizeVariable?this._getClusterTitle(t):e,infos:await $(s,t,await K(s),this.scale,this.view.type,l)}}_createSymbolTableElementMultiBand(e){const t=[],s=["red","green","blue"];return e.forEach(((e,l)=>{t.push({label:{colorName:s[l],bandName:e},src:Y[l],opacity:this.opacity??1})})),t}_updateInfosforClassedSizeRenderer(e,t){const s=e.authoringInfo&&"class-breaks-size"===e.authoringInfo.type,l=e.classBreakInfos.some((e=>P(e.symbol)));if(s&&l){const s=G,l=J,r=e.classBreakInfos.length,i=(s-l)/(r>1?r-1:r);t.forEach(((e,t)=>{e.size=s-i*t}))}}_isTallSymbol(e){let t=!1,s=!1;if(e)for(let l=0;l<e.length&&(!t||!s);l++){const r=e[l];"size"===r.type&&("height"===r.axis&&(t=!0),"width-and-depth"===r.axis&&(s=!0))}return t&&s}async _getSymbolPreview(e,t,s){let l=!s?.isDefault&&null==e.size&&this._hasSizeRamp?g(T.size):e.size;if(this._scaleDrivenSizeVariable&&s?.applyScaleDrivenSize){const{getSize:t}=await import("../../../renderers/visualVariables/support/visualVariableUtils.js");l=t(this._scaleDrivenSizeVariable,null,{view:this.view.type,scale:this.scale,shape:"simple-marker"===e.symbol.type?e.symbol.style:null})}return O(e.symbol,{size:l,opacity:t,scale:!1,symbolConfig:s?.symbolConfig,effectView:s?.effectList}).then((t=>(e.preview=t,e))).catch((()=>(e.preview=null,e)))}async _loadRenderer(e){const t=[],s=this.layer;e=e.clone(),this._hasClusterSizeVariable=!1;const l="visualVariables"in e&&e.visualVariables?.some((e=>"size"===e.type&&"outline"!==e.target&&!ae.test(e.valueExpression)));if(e&&"visualVariables"in e&&!l&&"featureReduction"in s&&"cluster"===s.featureReduction?.type){const t=this.layerView._effectiveRenderer,l=u(M(t,this.view));if(l){const t=s.featureReduction;if("clusterMinSize"in t&&"clusterMaxSize"in t){const{clusterMinSize:e,clusterMaxSize:s}=t;l.legendOptions=new V({showLegend:e!==s})}const r=e.visualVariables||[];e.visualVariables=r.concat([l]),this._hasClusterSizeVariable=!0}}const r=await K(e);if(be(e)||Se(e)){const s=(e.classBreakInfos||e.uniqueValueInfos).map((e=>this._fetchSymbol(e.symbol,r).then((t=>{e.symbol=t})).catch((()=>{e.symbol=null}))));Array.prototype.push.apply(t,s)}return t.push(this._fetchSymbol(e.symbol||e.defaultSymbol,e.defaultSymbol?null:r).then((t=>{this._applySymbolToRenderer(e,t,ge(e))})).catch((()=>{this._applySymbolToRenderer(e,null,ge(e))}))),d(t).then((()=>e))}_applySymbolToRenderer(e,t,s){s?e.symbol=t:e.defaultSymbol=t}async _fetchSymbol(e,t){if(!e)throw new Error;if("web-style"===e.type){const s=this._webStyleSymbolCache;try{const l=await("2d"===this.view.type?e.fetchCIMSymbol({cache:s}):e.fetchSymbol({cache:s}));return this._getAppliedCloneSymbol(l,t)}catch{throw se.warn("Fetching web-style failed!"),new Error}}return this._getAppliedCloneSymbol(e,t)}_getAppliedCloneSymbol(e,s){if(!e||!s)return e;const l=e.clone(),r=s&&s.toRgba();return l.type.includes("3d")?this._applyColorTo3dSymbol(l,r):"cim"===l.type?F(l,s):l.color&&(l.color=new t(r||l.color)),l}_applyColorTo3dSymbol(e,s){s&&e.symbolLayers.forEach((e=>{e&&(e.material||(e.material={}),e.material.color=new t(s))}))}async _getVisualVariableLegendElements(e,t){if(!("visualVariables"in e)||!e.visualVariables||"vector-field"===e.type)return null;const s=e.visualVariables,l=[],r=[],i=[];for(const c of s)"color"===c.type?l.push(c):"size"===c.type?r.push(c):"opacity"===c.type&&i.push(c);const n=[...l,...r,...i];let a,o;if(0===l.length&&be(e)&&e.classBreakInfos&&1===e.classBreakInfos.length){const t=e.classBreakInfos[0];a=t&&t.symbol}if(0===l.length&&ge(e)&&(a=e.symbol),a)if(a.type.includes("3d")){const e=a.symbolLayers.getItemAt(0);"water"===e.type?c(e.color)&&(o=e.color):c(e.material)&&c(e.material.color)&&(o=e.material.color)}else a.url||(o=a.color);const u=this.effectList;return(await Promise.all(n.map((async s=>{if(!s.legendOptions||!1!==s.legendOptions.showLegend){const l=ye(e)?s.field:this._getRampTitle(s,t);let r=null;const i="getField"in t&&t.getField&&t.getField(s.field),n=i&&C(i);if("color"===s.type){const e=await k(s,null,n);r={type:"color-ramp",title:l,infos:e,preview:x(e.map((e=>e.color)),{effectList:u})},this._hasColorRamp||(this._hasColorRamp=!(null==r.infos||!r.infos.length))}else if("size"===s.type&&"outline"!==s.target)ae.test(s.valueExpression)?this._hasClusterSizeVariable||(this._scaleDrivenSizeVariable=s):(r=await this._getSizeLegendElement(l,s,e,n),this._hasSizeRamp||(this._hasSizeRamp=!(null==r.infos||!r.infos.length)));else if("opacity"===s.type){const e=await k(s,o,n);r={type:"opacity-ramp",title:l,infos:e,preview:x(e.map((e=>e.color)),{effectList:u})},this._hasOpacityRamp||(this._hasOpacityRamp=!(null==r.infos||!r.infos.length))}return r&&r.infos?r:null}})))).filter((e=>!!e))}_getDomainName(e,t,s){if(e&&"function"!=typeof e){const l="getField"in s&&s.getField&&s.getField(e),r=l&&"getFieldDomain"in s&&s.getFieldDomain?s.getFieldDomain(l.name):null;return r&&"coded-value"===r.type?r.getName(t):null}return null}_getClusterTitle(e){const t=this.layer,s=e.field;if("featureReduction"in t&&t.featureReduction&&"cluster"===t.featureReduction.type){const e=t.featureReduction,l="popupTemplate"in e&&e.popupTemplate,r=l&&l.fieldInfos;if(r)for(const t of r)if(t.fieldName===s)return"cluster_count"===s?t.label||{showCount:!0}:t.label}return{showCount:!0}}_getRampTitle(e,t){let s=e.field,l=e.normalizationField,r=!1,i=!1,n=!1,a=null;s="function"==typeof s?null:s,l="function"==typeof l?null:l;const o=e.legendOptions&&e.legendOptions.title;if(null!=o)a=o;else if(e.valueExpressionTitle)a=e.valueExpressionTitle;else{if("renderer"in t&&t.renderer&&"authoringInfo"in t.renderer&&t.renderer.authoringInfo&&t.renderer.authoringInfo.visualVariables){const e=t.renderer.authoringInfo.visualVariables;for(let t=0;t<e.length;t++){const s=e[t];if("color"===s.type){if("ratio"===s.style){r=!0;break}if("percent"===s.style){i=!0;break}if("percent-of-total"===s.style){n=!0;break}}}}a={field:s&&this._getFieldAlias(s,t),normField:l&&this._getFieldAlias(l,t),ratio:r,ratioPercent:i,ratioPercentTotal:n}}return a}_getRendererTitle(e,t){const s=e;if(s.legendOptions&&s.legendOptions.title)return s.legendOptions.title;if(s.valueExpressionTitle)return s.valueExpressionTitle;let l=s.field,r=null,i=null;be(s)&&(r=s.normalizationField,i="percent-of-total"===s.normalizationType),l="function"==typeof l?null:l,r="function"==typeof r?null:r;let n=null;return(l||r)&&(n={field:l&&this._getFieldAlias(l,t),normField:r&&this._getFieldAlias(r,t),normByPct:i}),n}_getFieldAlias(e,t){const s="popupTemplate"in t&&t.popupTemplate,l=s&&s.fieldInfos;let r=null;l&&l.some((t=>e===t.fieldName&&(r=t,!0)));let i=null;"getField"in t&&t.getField?i=t.getField(e):"fieldsIndex"in t&&t.fieldsIndex&&(i=t.fieldsIndex.get(e));const n=r||i;let a=null;return n&&(a=r&&r.label||i&&i.alias||"name"in n&&n.name||"fieldName"in n&&n.fieldName),a}_isUnclassedRenderer(e){const t=e.visualVariables;let s=!1;return be(e)&&e.classBreakInfos&&1===e.classBreakInfos.length&&t&&(s=e.field?t.some((t=>!(!t||e.field!==t.field||(e.normalizationField||t.normalizationField)&&e.normalizationField!==t.normalizationField))):!!t.length),s}};e([S()],We.prototype,"children",void 0),e([S({readOnly:!0})],We.prototype,"effectList",null),e([S()],We.prototype,"layerView",void 0),e([S()],We.prototype,"layer",void 0),e([S()],We.prototype,"legendElements",void 0),e([S({readOnly:!0})],We.prototype,"opacity",null),e([S()],We.prototype,"parent",void 0),e([S({readOnly:!0,dependsOn:[]})],We.prototype,"ready",null),e([S()],We.prototype,"hideLayersNotInCurrentView",void 0),e([S()],We.prototype,"keepCacheOnDestroy",void 0),e([S()],We.prototype,"respectLayerVisibility",void 0),e([S({readOnly:!0})],We.prototype,"scale",null),e([S()],We.prototype,"sublayerIds",void 0),e([S({readOnly:!0})],We.prototype,"isScaleDriven",null),e([S()],We.prototype,"title",void 0),e([S({readOnly:!0,dependsOn:["ready"],value:0})],We.prototype,"version",null),e([S()],We.prototype,"view",void 0),We=e([_("esri.widgets.Legend.support.ActiveLayerInfo")],We);const $e=We;export{$e as default};
|