@arcgis/core 5.1.0-next.110 → 5.1.0-next.111
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/themes/base/widgets/_BatchAttributeForm.scss +7 -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/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_ar.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_bg.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_bs.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_ca.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_cs.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_da.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_de.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_el.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_en.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_es.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_et.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_fi.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_fr.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_he.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_hr.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_hu.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_id.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_it.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_ja.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_ko.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_lt.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_lv.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_nl.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_no.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_pl.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_pt-BR.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_pt-PT.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_ro.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_ru.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_sk.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_sl.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_sr.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_sv.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_th.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_tr.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_uk.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_vi.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_zh-CN.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_zh-HK.json +1 -1
- package/assets/esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm_zh-TW.json +1 -1
- package/config.js +1 -1
- package/kernel.js +1 -1
- package/package.json +1 -1
- package/rest/print.js +1 -1
- package/support/revision.js +1 -1
- package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
- package/widgets/BatchAttributeForm/BatchAttributeFormViewModel.d.ts +10 -1
- package/widgets/BatchAttributeForm/BatchAttributeFormViewModel.js +1 -1
- package/widgets/BatchAttributeForm/css.js +1 -1
- package/widgets/BatchAttributeForm/inputs/AttachmentElementInput.d.ts +25 -1
- package/widgets/BatchAttributeForm/inputs/AttachmentElementInput.js +1 -1
- package/widgets/BatchAttributeForm.js +1 -1
- package/widgets/Print/PrintViewModel.js +1 -1
|
@@ -8,7 +8,7 @@ import type { ArcadeBatchFormCalculationContextInfo } from "../expressions/types
|
|
|
8
8
|
import type { EditableInputProperties } from "./EditableInput.js";
|
|
9
9
|
|
|
10
10
|
/** @since 5.1 */
|
|
11
|
-
export interface AttachmentElementInputProperties extends EditableInputProperties, Partial<Pick<AttachmentElementInput, "attachments">> {}
|
|
11
|
+
export interface AttachmentElementInputProperties extends EditableInputProperties, Partial<Pick<AttachmentElementInput, "attachments" | "displayCount">> {}
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* This is a read-only support class that represents an [attachment element](https://developers.arcgis.com/javascript/latest/references/core/form/elements/AttachmentElement/) in a [BatchAttributeForm](https://developers.arcgis.com/javascript/latest/references/core/widgets/BatchAttributeForm/).
|
|
@@ -20,12 +20,31 @@ export interface AttachmentElementInputProperties extends EditableInputPropertie
|
|
|
20
20
|
*/
|
|
21
21
|
export default class AttachmentElementInput extends EditableInput<any> {
|
|
22
22
|
constructor(properties: AttachmentElementInputProperties);
|
|
23
|
+
/**
|
|
24
|
+
* Indicates whether all attachments for this input are visible on the default page.
|
|
25
|
+
*
|
|
26
|
+
* @since 5.1
|
|
27
|
+
*/
|
|
28
|
+
get allAttachmentsVisibleOnDefaultPage(): boolean;
|
|
23
29
|
/** Indicates if the input allows users to rename attachments. */
|
|
24
30
|
get allowUserRename(): boolean | null | undefined;
|
|
25
31
|
/** The input's attachment keyword. This is used to filter attachments associated with the active feature. */
|
|
26
32
|
get attachmentKeyword(): string | null | undefined;
|
|
27
33
|
/** The attachments applicable to this input. */
|
|
28
34
|
accessor attachments: AttachmentInfo[];
|
|
35
|
+
/**
|
|
36
|
+
* The attachments visible on the default page before showing the full attachments list action.
|
|
37
|
+
*
|
|
38
|
+
* @since 5.1
|
|
39
|
+
*/
|
|
40
|
+
get defaultPageAttachments(): AttachmentInfo[];
|
|
41
|
+
/**
|
|
42
|
+
* The maximum number of attachments displayed on the default page before showing the full attachments list action.
|
|
43
|
+
*
|
|
44
|
+
* @default 3
|
|
45
|
+
* @since 5.1
|
|
46
|
+
*/
|
|
47
|
+
accessor displayCount: number;
|
|
29
48
|
/** Indicates if the attachment filename should be displayed. */
|
|
30
49
|
get displayFilename(): boolean | null | undefined;
|
|
31
50
|
/**
|
|
@@ -85,6 +104,11 @@ export default class AttachmentElementInput extends EditableInput<any> {
|
|
|
85
104
|
* @internal
|
|
86
105
|
*/
|
|
87
106
|
isFileAllowed(file: Blob | File): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* @param attachment - Attachment metadata to check.
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
isStagedAttachmentAddition(attachment: AttachmentInfo): boolean;
|
|
88
112
|
/**
|
|
89
113
|
* @param params - Attachment information and content to stage as a new attachment.
|
|
90
114
|
* @returns The staged attachment metadata.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import{__decorate as t}from"tslib";import e from"../../../core/Collection.js";import a from"../../../core/Logger.js";import{isAbortError as s}from"../../../core/promiseUtils.js";import n from"../../../core/ReactiveMap.js";import r from"../../../core/ReactiveSet.js";import{generateBracedUUID as i}from"../../../core/uuid.js";import{property as o,subclass as l}from"../../../core/accessorSupport/decorators.js";import{getEffectiveLayerCapabilities as c}from"../../../layers/support/layerUtils.js";import m from"../../../rest/query/support/AttachmentInfo.js";import{getAttachmentTypeCategory as h}from"../../Attachments/support/attachmentUtils.js";import{getAttachmentUrl as d}from"../attachmentUtils.js";import{isAttributeFormSupportedLayer as p}from"../batchAttributeFormUtils.js";import u from"./EditableInput.js";import g from"./SingleFeatureInputAdapter.js";let y=-1,f=class extends u{constructor(t){super(t),this.attachments=[],this.group=null,this.single=new g({input:this}),this.type="attachment",this._initialAttachments=[],this._stagedAdds=new e,this._stagedDeletes=new r,this._stagedUpdates=new n,this._temporaryAttachmentUrls=new n}get allowUserRename(){return this.template.allowUserRename}get addDisabled(){const t=this.maxAttachmentCount;return null!=t&&this.attachments.length>=t}get accept(){const{categories:t}=this;if(!t.size)return;const e=[];return t.has("image")&&e.push("image/*"),t.has("audio")&&e.push("audio/*"),t.has("video")&&e.push("video/*"),t.has("document")&&e.push("text/*","application/*","model/*"),e.length>0?e.join(","):void 0}get categories(){const{input:t}=this,e=new Set;if(!t)return e;if("attachment"===t.type){const{inputTypes:a}=t;if(!a||0===a.length)return e;for(const t of a)_(e,t.type);return e}return _(e,t.type),e}get attachmentKeyword(){return this.template.attachmentKeyword?.trim()}get displayFilename(){return this.template.displayFilename}get feature(){return this.single.feature}get hasAttachmentChanges(){return this._stagedAdds.length>0||this._stagedUpdates.size>0||this._stagedDeletes.size>0}get input(){return this.template.input}get layer(){return this.single.layer}get maxAttachmentCount(){return this.template.maxAttachmentCount}get minAttachmentCount(){return this.template.minAttachmentCount}get supportsResize(){const{layer:t}=this;if(!t)return!1;const e=c(t);return!!e&&("attachment"in e&&!!e.attachment?.supportsResize)}get useOriginalFilename(){return this.template.useOriginalFilename}get valid(){const t=this.attachments.length,e=this.minAttachmentCount??-1/0,a=this.maxAttachmentCount??1/0,s=this.hasAttachmentChanges;return!(t<e||t>a)||!s}get _expressionLayer(){const t=this.layer;if(t)return"scene"===t.type&&"associatedLayer"in t&&null!=t.associatedLayer?t.associatedLayer:"feature"===t.type?t:void 0}destroy(){this._clearTemporaryAttachmentUrls()}applyFetchedAttachments(t){for(const e of t)this._normalizeAttachmentName(e);this._initialAttachments=t,this._recomputeAttachments()}clearAttachmentChanges(){this._clearTemporaryAttachmentUrls(),this._stagedAdds.removeAll(),this._stagedUpdates.clear(),this._stagedDeletes.clear(),this._recomputeAttachments()}stageAddAttachment(t){const{contentType:e,data:a,name:s}=t,n=t.globalId??i(),r=a instanceof Blob?a.size:void 0,o=s.trim(),l=new m({contentType:e??void 0,globalId:n,id:y--,keywords:this.attachmentKeyword??void 0,name:o,size:r});return this._setTemporaryAttachmentUrl(n,a),this._stagedAdds.add({globalId:n,info:l,data:a}),this._recomputeAttachments(),l}async stageAddAttachments(t,e){const a=t.filter(t=>this.isFileAllowed(t));if(0===a.length)return[];const s=[],n=new Map,r=Date.now();for(let i=0;i<a.length;i++){const t=a[i],o=t instanceof File?t.name:`attachment-${r}_${i+1}`,l=await this._computeAttachmentFilename(o,e),c=this._makeUniqueFilenameForOperation(n,l);s.push(this.stageAddAttachment({contentType:t.type,data:t,name:c}))}return s}findAttachment(t){if(t)return this.attachments.find(e=>e.globalId===t)}getAttachmentPreviewUrl(t,e){return(t.globalId?this._temporaryAttachmentUrls.get(t.globalId):void 0)??d(t,this.supportsResize,e)}isFileAllowed(t){if(!t.type)return!0;const{categories:e}=this;return!e.size||e.has(h(t.type))}stageDeleteAttachment(t){const e=t.globalId;if(!e)return;const a=this._stagedAdds.findIndex(t=>t.globalId===e);if(a>-1)return this._clearTemporaryAttachmentUrl(e),this._stagedAdds.removeAt(a),void this._recomputeAttachments();this._clearTemporaryAttachmentUrl(e),this._stagedUpdates.delete(e),this._stagedDeletes.add(e),this._recomputeAttachments()}stageRenameAttachment(t,e){const a=t.globalId;if(!a)return;const s=this._stagedAdds.find(t=>t.globalId===a);if(s)return s.info.name=e,void this._recomputeAttachments();const n=this._stagedUpdates.get(a);this._stagedUpdates.set(a,{...n,info:t,name:e}),this._recomputeAttachments()}async stageReplaceAttachment(t,e,a){const s=e instanceof File?e.name:t.name,n=await this._computeAttachmentFilename(s,a);this._stageReplaceAttachment(t,e,n)}toSubmitEdits(){const t=[],e=[],s=Array.from(this._stagedDeletes);if(0===this._stagedAdds.length&&0===this._stagedUpdates.size&&0===s.length)return null;const n=this._featureIdentifier;if(!n)return a.getLogger(this).error("Unable to build attachment edits without a valid feature and layer."),null;for(const a of this._stagedAdds)t.push({feature:n,attachment:{globalId:a.globalId,contentType:a.info.contentType,data:a.data,name:a.info.name}});for(const[a,r]of this._stagedUpdates)e.push({feature:n,attachment:{globalId:a,contentType:r.contentType,data:r.data,name:r.name}});return{label:this.template.label,attachmentKeyword:this.attachmentKeyword,add:t,delete:s,update:e}}_recomputeAttachments(){const t=this._stagedDeletes,e=[];for(const a of this._stagedAdds)e.push(a.info);for(const a of this._initialAttachments){const s=a.globalId;if(!s||!t.has(s)){if(s&&this._stagedUpdates.has(s)){const t=this._stagedUpdates.get(s),n=a.clone();null!=t.name&&(n.name=t.name),e.push(n);continue}e.push(a)}}this.attachments=e}get _featureIdentifier(){const t=this.single.feature,e=this.layer;if(!t||!p(e))return null;const a=e.objectIdField,s="globalIdField"in e?e.globalIdField:null,n=t.getGlobalId()??(s?t.getAttribute(s):void 0);if(n)return{globalId:n};const r=t.getObjectId()??t.getAttribute(a),i=Number(r);return null==r||isNaN(i)?null:{objectId:i}}async _computeAttachmentFilename(t,e){const n=this.template.filenameExpressionExecutor;if(!n)return t;const r=this.single.feature,i=r?.plainGraphic,o=this._expressionLayer,l={$originalfeature:r?.original,$editcontext:{editType:e.editType},$layer:o,$featureset:o,$datastore:o?.url,$feature:i,$map:e.map},c={rawOutput:!0,spatialReference:e.spatialReference,timeZone:e.timeZone};try{const t=n.isAsync?await n.executeAsync(l,c):n.execute(l,c);if("string"==typeof t&&t.trim().length>0)return t.trim()}catch(m){s(m)||a.getLogger(this).error("Failed evaluating attachment filename expression",m)}return t}_makeUniqueFilenameForOperation(t,e){const a=e.toLowerCase(),s=t.get(a)??0;if(t.set(a,s+1),0===s)return e;const n=e.lastIndexOf(".");return`${n>0?e.slice(0,n):e}_${s}${n>0?e.slice(n):""}`}_stageReplaceAttachment(t,e,a){const s=t.globalId;if(!s)return;const n=this._stagedAdds.find(t=>t.globalId===s);if(n)return n.data=e,n.info.name=a,n.info.contentType=e.type,n.info.size=e.size,this._setTemporaryAttachmentUrl(s,e),void this._recomputeAttachments();const r=this._stagedUpdates.get(s);this._setTemporaryAttachmentUrl(s,e),this._stagedUpdates.set(s,{...r,info:t,contentType:e.type||r?.contentType,data:e,name:a}),this._recomputeAttachments()}_normalizeAttachmentName(t){const{name:e}=t;"string"==typeof e&&(t.name=e.trim())}_setTemporaryAttachmentUrl(t,e){if(this._clearTemporaryAttachmentUrl(t),!(e instanceof Blob))return;const a=URL.createObjectURL(e);return this._temporaryAttachmentUrls.set(t,a),a}_clearTemporaryAttachmentUrl(t){const e=this._temporaryAttachmentUrls.get(t);e&&(URL.revokeObjectURL(e),this._temporaryAttachmentUrls.delete(t))}_clearTemporaryAttachmentUrls(){for(const t of this._temporaryAttachmentUrls.values())URL.revokeObjectURL(t);this._temporaryAttachmentUrls.clear()}};t([o()],f.prototype,"allowUserRename",null),t([o({readOnly:!0})],f.prototype,"addDisabled",null),t([o({readOnly:!0})],f.prototype,"accept",null),t([o({readOnly:!0})],f.prototype,"categories",null),t([o()],f.prototype,"attachmentKeyword",null),t([o()],f.prototype,"attachments",void 0),t([o()],f.prototype,"displayFilename",null),t([o()],f.prototype,"feature",null),t([o()],f.prototype,"group",void 0),t([o({readOnly:!0})],f.prototype,"hasAttachmentChanges",null),t([o()],f.prototype,"input",null),t([o()],f.prototype,"layer",null),t([o()],f.prototype,"maxAttachmentCount",null),t([o()],f.prototype,"minAttachmentCount",null),t([o({readOnly:!0})],f.prototype,"single",void 0),t([o({readOnly:!0})],f.prototype,"type",void 0),t([o({readOnly:!0})],f.prototype,"supportsResize",null),t([o()],f.prototype,"useOriginalFilename",null),t([o({readOnly:!0})],f.prototype,"valid",null),t([o()],f.prototype,"_initialAttachments",void 0),t([o()],f.prototype,"_expressionLayer",null),t([o()],f.prototype,"_stagedAdds",void 0),t([o()],f.prototype,"_stagedDeletes",void 0),t([o()],f.prototype,"_stagedUpdates",void 0),t([o()],f.prototype,"_temporaryAttachmentUrls",void 0),t([o()],f.prototype,"_featureIdentifier",null),f=t([l("esri.widgets.BatchAttributeForm.inputs.AttachmentElementInput")],f);const A=f;function _(t,e){switch(e){case"audio":t.add("audio");break;case"document":t.add("document");break;case"image":case"signature":t.add("image");break;case"video":t.add("video")}}export{A as default};
|
|
2
|
+
import{__decorate as t}from"tslib";import e from"../../../core/Collection.js";import a from"../../../core/Logger.js";import{isAbortError as s}from"../../../core/promiseUtils.js";import n from"../../../core/ReactiveMap.js";import r from"../../../core/ReactiveSet.js";import{generateBracedUUID as i}from"../../../core/uuid.js";import{property as o,subclass as l}from"../../../core/accessorSupport/decorators.js";import{getEffectiveLayerCapabilities as c}from"../../../layers/support/layerUtils.js";import h from"../../../rest/query/support/AttachmentInfo.js";import{getAttachmentTypeCategory as m}from"../../Attachments/support/attachmentUtils.js";import{getAttachmentUrl as d}from"../attachmentUtils.js";import{isAttributeFormSupportedLayer as p}from"../batchAttributeFormUtils.js";import u from"./EditableInput.js";import g from"./SingleFeatureInputAdapter.js";let y=-1,f=class extends u{constructor(t){super(t),this.attachments=[],this.displayCount=3,this.group=null,this.single=new g({input:this}),this.type="attachment",this._initialAttachments=[],this._stagedAdds=new e,this._stagedDeletes=new r,this._stagedUpdates=new n,this._temporaryAttachmentUrls=new n}get allowUserRename(){return this.template.allowUserRename}get addDisabled(){const t=this.maxAttachmentCount;return null!=t&&this.attachments.length>=t}get accept(){const{categories:t}=this;if(!t.size)return;const e=[];return t.has("image")&&e.push("image/*"),t.has("audio")&&e.push("audio/*"),t.has("video")&&e.push("video/*"),t.has("document")&&e.push("text/*","application/*","model/*"),e.length>0?e.join(","):void 0}get categories(){const{input:t}=this,e=new Set;if(!t)return e;if("attachment"===t.type){const{inputTypes:a}=t;if(!a||0===a.length)return e;for(const t of a)_(e,t.type);return e}return _(e,t.type),e}get attachmentKeyword(){return this.template.attachmentKeyword?.trim()}get displayFilename(){return this.template.displayFilename}get allAttachmentsVisibleOnDefaultPage(){return this.defaultPageAttachments.length===this.attachments.length}get defaultPageAttachments(){return this.attachments.slice(0,this.displayCount)}get feature(){return this.single.feature}get hasAttachmentChanges(){return this._stagedAdds.length>0||this._stagedUpdates.size>0||this._stagedDeletes.size>0}get input(){return this.template.input}get layer(){return this.single.layer}get maxAttachmentCount(){return this.template.maxAttachmentCount}get minAttachmentCount(){return this.template.minAttachmentCount}get supportsResize(){const{layer:t}=this;if(!t)return!1;const e=c(t);return!!e&&("attachment"in e&&!!e.attachment?.supportsResize)}get useOriginalFilename(){return this.template.useOriginalFilename}get valid(){const t=this.attachments.length,e=this.minAttachmentCount??-1/0,a=this.maxAttachmentCount??1/0,s=this.hasAttachmentChanges;return!(t<e||t>a)||!s}get _expressionLayer(){const t=this.layer;if(t)return"scene"===t.type&&"associatedLayer"in t&&null!=t.associatedLayer?t.associatedLayer:"feature"===t.type?t:void 0}destroy(){this._clearTemporaryAttachmentUrls()}applyFetchedAttachments(t){for(const e of t)this._normalizeAttachmentName(e);this._initialAttachments=t,this._recomputeAttachments()}clearAttachmentChanges(){this._clearTemporaryAttachmentUrls(),this._stagedAdds.removeAll(),this._stagedUpdates.clear(),this._stagedDeletes.clear(),this._recomputeAttachments()}stageAddAttachment(t){const{contentType:e,data:a,name:s}=t,n=t.globalId??i(),r=a instanceof Blob?a.size:void 0,o=s.trim(),l=new h({contentType:e??void 0,globalId:n,id:y--,keywords:this.attachmentKeyword??void 0,name:o,size:r});return this._setTemporaryAttachmentUrl(n,a),this._stagedAdds.add({globalId:n,info:l,data:a}),this._recomputeAttachments(),l}async stageAddAttachments(t,e){const a=t.filter(t=>this.isFileAllowed(t));if(0===a.length)return[];const s=[],n=new Map,r=Date.now();for(let i=0;i<a.length;i++){const t=a[i],o=t instanceof File?t.name:`attachment-${r}_${i+1}`,l=await this._computeAttachmentFilename(o,e),c=this._makeUniqueFilenameForOperation(n,l);s.push(this.stageAddAttachment({contentType:t.type,data:t,name:c}))}return s}findAttachment(t){if(t)return this.attachments.find(e=>e.globalId===t)}getAttachmentPreviewUrl(t,e){return(t.globalId?this._temporaryAttachmentUrls.get(t.globalId):void 0)??d(t,this.supportsResize,e)}isFileAllowed(t){if(!t.type)return!0;const{categories:e}=this;return!e.size||e.has(m(t.type))}isStagedAttachmentAddition(t){return"number"==typeof t.id&&t.id<0}stageDeleteAttachment(t){const e=t.globalId;if(!e)return;const a=this._stagedAdds.findIndex(t=>t.globalId===e);if(a>-1)return this._clearTemporaryAttachmentUrl(e),this._stagedAdds.removeAt(a),void this._recomputeAttachments();this._clearTemporaryAttachmentUrl(e),this._stagedUpdates.delete(e),this._stagedDeletes.add(e),this._recomputeAttachments()}stageRenameAttachment(t,e){const a=t.globalId;if(!a)return;const s=this._stagedAdds.find(t=>t.globalId===a);if(s)return s.info.name=e,void this._recomputeAttachments();const n=this._stagedUpdates.get(a);this._stagedUpdates.set(a,{...n,info:t,name:e}),this._recomputeAttachments()}async stageReplaceAttachment(t,e,a){const s=e instanceof File?e.name:t.name,n=await this._computeAttachmentFilename(s,a);this._stageReplaceAttachment(t,e,n)}toSubmitEdits(){const t=[],e=[],s=Array.from(this._stagedDeletes);if(0===this._stagedAdds.length&&0===this._stagedUpdates.size&&0===s.length)return null;const n=this._featureIdentifier;if(!n)return a.getLogger(this).error("Unable to build attachment edits without a valid feature and layer."),null;for(const a of this._stagedAdds)t.push({feature:n,attachment:{globalId:a.globalId,contentType:a.info.contentType,data:a.data,name:a.info.name}});for(const[a,r]of this._stagedUpdates)e.push({feature:n,attachment:{globalId:a,contentType:r.contentType,data:r.data,name:r.name}});return{label:this.template.label,attachmentKeyword:this.attachmentKeyword,add:t,delete:s,update:e}}_recomputeAttachments(){const t=this._stagedDeletes,e=[];for(const a of this._stagedAdds)e.push(a.info);for(const a of this._initialAttachments){const s=a.globalId;if(!s||!t.has(s)){if(s&&this._stagedUpdates.has(s)){const t=this._stagedUpdates.get(s),n=a.clone();null!=t.name&&(n.name=t.name),e.push(n);continue}e.push(a)}}this.attachments=e}get _featureIdentifier(){const t=this.single.feature,e=this.layer;if(!t||!p(e))return null;const a=e.objectIdField,s="globalIdField"in e?e.globalIdField:null,n=t.getGlobalId()??(s?t.getAttribute(s):void 0);if(n)return{globalId:n};const r=t.getObjectId()??t.getAttribute(a),i=Number(r);return null==r||isNaN(i)?null:{objectId:i}}async _computeAttachmentFilename(t,e){const n=this.template.filenameExpressionExecutor;if(!n)return t;const r=this.single.feature,i=r?.plainGraphic,o=this._expressionLayer,l={$originalfeature:r?.original,$editcontext:{editType:e.editType},$layer:o,$featureset:o,$datastore:o?.url,$feature:i,$map:e.map},c={rawOutput:!0,spatialReference:e.spatialReference,timeZone:e.timeZone};try{const t=n.isAsync?await n.executeAsync(l,c):n.execute(l,c);if("string"==typeof t&&t.trim().length>0)return t.trim()}catch(h){s(h)||a.getLogger(this).error("Failed evaluating attachment filename expression",h)}return t}_makeUniqueFilenameForOperation(t,e){const a=e.toLowerCase(),s=t.get(a)??0;if(t.set(a,s+1),0===s)return e;const n=e.lastIndexOf(".");return`${n>0?e.slice(0,n):e}_${s}${n>0?e.slice(n):""}`}_stageReplaceAttachment(t,e,a){const s=t.globalId;if(!s)return;const n=this._stagedAdds.find(t=>t.globalId===s);if(n)return n.data=e,n.info.name=a,n.info.contentType=e.type,n.info.size=e.size,this._setTemporaryAttachmentUrl(s,e),void this._recomputeAttachments();const r=this._stagedUpdates.get(s);this._setTemporaryAttachmentUrl(s,e),this._stagedUpdates.set(s,{...r,info:t,contentType:e.type||r?.contentType,data:e,name:a}),this._recomputeAttachments()}_normalizeAttachmentName(t){const{name:e}=t;"string"==typeof e&&(t.name=e.trim())}_setTemporaryAttachmentUrl(t,e){if(this._clearTemporaryAttachmentUrl(t),!(e instanceof Blob))return;const a=URL.createObjectURL(e);return this._temporaryAttachmentUrls.set(t,a),a}_clearTemporaryAttachmentUrl(t){const e=this._temporaryAttachmentUrls.get(t);e&&(URL.revokeObjectURL(e),this._temporaryAttachmentUrls.delete(t))}_clearTemporaryAttachmentUrls(){for(const t of this._temporaryAttachmentUrls.values())URL.revokeObjectURL(t);this._temporaryAttachmentUrls.clear()}};t([o()],f.prototype,"allowUserRename",null),t([o({readOnly:!0})],f.prototype,"addDisabled",null),t([o({readOnly:!0})],f.prototype,"accept",null),t([o({readOnly:!0})],f.prototype,"categories",null),t([o()],f.prototype,"attachmentKeyword",null),t([o()],f.prototype,"attachments",void 0),t([o()],f.prototype,"displayFilename",null),t([o({readOnly:!0})],f.prototype,"allAttachmentsVisibleOnDefaultPage",null),t([o({readOnly:!0})],f.prototype,"defaultPageAttachments",null),t([o()],f.prototype,"displayCount",void 0),t([o()],f.prototype,"feature",null),t([o()],f.prototype,"group",void 0),t([o({readOnly:!0})],f.prototype,"hasAttachmentChanges",null),t([o()],f.prototype,"input",null),t([o()],f.prototype,"layer",null),t([o()],f.prototype,"maxAttachmentCount",null),t([o()],f.prototype,"minAttachmentCount",null),t([o({readOnly:!0})],f.prototype,"single",void 0),t([o({readOnly:!0})],f.prototype,"type",void 0),t([o({readOnly:!0})],f.prototype,"supportsResize",null),t([o()],f.prototype,"useOriginalFilename",null),t([o({readOnly:!0})],f.prototype,"valid",null),t([o()],f.prototype,"_initialAttachments",void 0),t([o()],f.prototype,"_expressionLayer",null),t([o()],f.prototype,"_stagedAdds",void 0),t([o()],f.prototype,"_stagedDeletes",void 0),t([o()],f.prototype,"_stagedUpdates",void 0),t([o()],f.prototype,"_temporaryAttachmentUrls",void 0),t([o()],f.prototype,"_featureIdentifier",null),f=t([l("esri.widgets.BatchAttributeForm.inputs.AttachmentElementInput")],f);const A=f;function _(t,e){switch(e){case"audio":t.add("audio");break;case"document":t.add("document");break;case"image":case"signature":t.add("image");break;case"video":t.add("video")}}export{A as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import{substitute as t}from"../intl.js";import{deprecateWidget as a}from"../core/deprecate.js";import i from"../core/Logger.js";import{getOrCreateMapValue as n}from"../core/MapUtils.js";import{watch as o,on as l}from"../core/reactiveUtils.js";import{formatFileSize as s}from"../core/unitFormatUtils.js";import{property as r,subclass as c}from"../core/accessorSupport/decorators.js";import{isIntegerField as d}from"../layers/support/fieldUtils.js";import{isString as u}from"../support/guards.js";import m from"./Widget.js";import{getAttachmentTypeCategory as p,getCalciteIconForAttachment as h}from"./Attachments/support/attachmentUtils.js";import{getAttachmentKey as f,isImageAttachment as v}from"./BatchAttributeForm/attachmentUtils.js";import{getHiddenFieldsValidationErrorMessage as g,getVisibleFieldInputValidationErrorMessage as b,isElementTemplateWithInputType as C}from"./BatchAttributeForm/batchAttributeFormUtils.js";import _ from"./BatchAttributeForm/BatchAttributeFormViewModel.js";import{css as y}from"./BatchAttributeForm/css.js";import{makeAddAttachmentFooterButtons as I,makeViewingAttachmentFooterButtons as F,makeDefaultFooterButtons as k}from"./BatchAttributeForm/interfaceUtils.js";import w from"./BatchAttributeForm/VisibleElements.js";import{isGroupInput as A,isFieldInput as x,isTextElementInput as M,isRelationshipElementInput as D,isAttachmentElementInput as V,isUtilityNetworkAssociationsElementInput as O,differentValuesString as S}from"./BatchAttributeForm/inputs/support/inputUtils.js";import{clearMultipleChoiceOtherChoiceStateForViewModel as E,getMultipleChoiceCheckboxState as T,otherChoiceCheckedPlaceholderValue as L,getUpdatedMultipleChoiceValueForFeature as U,getMultipleChoiceSelectAllState as N,splitMultipleChoiceValue as P,canRestoreMultipleChoiceOtherChoiceDraftValue as $}from"./BatchAttributeForm/inputs/support/multipleChoiceInputUtils.js";import{downloadAttachmentInfo as B}from"./FeatureTable/support/exportUtils.js";import{loadCalciteComponents as R}from"./support/componentsUtils.js";import{getLabelForDateFieldValue as j,getIntlOptionsForField as z,prepareISOFieldValueForDateComponents as Z,prepareUnixFieldValueForDateComponents as H,normalizeTimeOnlyString as q,getISOFieldValueFromDateComponents as G,getUnixFieldValueFromDateComponents as W}from"./support/dateUtils.js";import{globalCss as K}from"./support/globalCss.js";import{messageBundle as J,vmEvent as Q,tsx as X}from"./support/widget.js";import{setFocus as Y}from"./support/widgetUtils.js";import{isEmptyValue as ee}from"./support/forms/formUtils.js";const te="data-element-id",ae="esri_BatchAttributeForm_select_all",ie="esri_BatchAttributeForm_other_choice";let ne=class extends m{constructor(e,t){super(e,t),this.headingLevel=2,this.messagesCommon=null,this.messages=null,this.messagesUnits=null,this.viewModel=new _,this.visibleElements=new w,this.groupDisplay="all",this._attemptFocusOnNextRender=!1,this._dateComponentMap=new Map,this._touchedInputs=new Set,this._focusedFieldInput=null,this._batchSwitchInputInitialValues=new Map,this._attachmentDialogInfo=null,this._attachmentFileInputMap=new Map,this._maximizeSelectedAttachment=()=>{this._attachmentDialogInfo=this.selectedAttachmentDetails},this._closeAttachmentDialog=()=>{this.hideAttachmentDialog()},this._saveInput=this._saveInput.bind(this),this._onFormSubmit=this._onFormSubmit.bind(this),this._onComponentFocus=this._onComponentFocus.bind(this),this._onComponentBlur=this._onComponentBlur.bind(this),this._afterComponentCreateOrUpdate=this._afterComponentCreateOrUpdate.bind(this),this._afterDateComponentCreate=this._afterDateComponentCreate.bind(this),this._afterRadioGroupCreateOrUpdate=this._afterRadioGroupCreateOrUpdate.bind(this),e?.suppressDeprecationWarning||(this.announceDeprecation=()=>{a(i.getLogger(this),"Editor","arcgis-editor",{version:"5.0"})})}normalizeCtorArgs(e={}){const{suppressDeprecationWarning:t,...a}=e;return a}initialize(){this.addHandles([o(()=>this.features,()=>{this._dateComponentMap.clear(),this._resetTransientFormState(),E(this.viewModel,{includeDraftValues:!0})}),o(()=>this.viewModel.activeForm,()=>{this._batchSwitchInputInitialValues.clear(),this._resetTransientFormState(),E(this.viewModel)}),o(()=>this.viewModel.selectedAttachmentAddElementId,()=>{this.hideAttachmentDialog()}),l(()=>this.viewModel,"submit",()=>{this.valid||this.goToFirstError()})])}loadDependencies(){return R({block:()=>import("@esri/calcite-components/dist/components/calcite-block"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),checkbox:()=>import("@esri/calcite-components/dist/components/calcite-checkbox"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),"combobox-item-group":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item-group"),dialog:()=>import("@esri/calcite-components/dist/components/calcite-dialog"),dropdown:()=>import("@esri/calcite-components/dist/components/calcite-dropdown"),"dropdown-group":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-group"),"dropdown-item":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-item"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker"),"input-time-zone":()=>import("@esri/calcite-components/dist/components/calcite-input-time-zone"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),"input-message":()=>import("@esri/calcite-components/dist/components/calcite-input-message"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch"),"text-area":()=>import("@esri/calcite-components/dist/components/calcite-text-area"),"radio-button":()=>import("@esri/calcite-components/dist/components/calcite-radio-button"),"radio-button-group":()=>import("@esri/calcite-components/dist/components/calcite-radio-button-group")})}get activeFeatureIndex(){return this.viewModel.activeFeatureIndex}set activeFeatureIndex(e){this.viewModel.activeFeatureIndex=e}get disabled(){return this.viewModel.disabled}set disabled(e){this.viewModel.disabled=e}get effectiveTitle(){const{features:e,messages:t,page:a}=this;return"viewing-attachment-details"===a?t.titles.editAttachment:"adding-attachments"===a?t.titles.addAttachments:1===e.length||this.activeFeatureIndex>-1?t.titles.editFeature:e.length>1?t.titles.editFeatures:""}get effectiveDisabled(){return this.disabled||this.viewModel.updating}get features(){return this.viewModel.features}set features(e){this.viewModel.features=e}get footerButtonInfos(){if(!this.features.length)return[];const{page:e,messages:t}=this,a=this.viewModel.selectedAttachmentAddElementId;return"adding-attachments"===e&&a?I({messages:t,onclick:()=>this._attachmentFileInputMap.get(a)?.click()}):"viewing-attachment-details"===e?F({messages:t}):k({formId:this._formId,callback:this.submit,messages:t})}get footerNoticeInfos(){if(!this.features.length)return[];const{messages:{footerNotices:e}}=this;return[]}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get maximumFeatureCount(){return this.viewModel.maximumFeatureCount}set maximumFeatureCount(e){this.viewModel.maximumFeatureCount=e}get maximumFeatureCountWithComplexForms(){return this.viewModel.maximumFeatureCountWithComplexForms}set maximumFeatureCountWithComplexForms(e){this.viewModel.maximumFeatureCountWithComplexForms=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get layerInfos(){return this.viewModel.layerInfos}set layerInfos(e){this.viewModel.layerInfos=e}get timeZone(){return this.viewModel.timeZone}set timeZone(e){this.viewModel.timeZone=e}get icon(){return"edit-attributes"}set icon(e){this._overrideIfSome("icon",e)}get page(){return this.viewModel.page}get readOnly(){return this.viewModel.readOnly}set readOnly(e){this.viewModel.readOnly=e}get selectedAttachment(){return this.viewModel.selectedAttachment}get selectedAttachmentDetails(){return this.viewModel.selectedAttachmentDetails}get valid(){return this.viewModel.valid}get _formId(){return`${this.id}-form`}async goBack(){return this.viewModel.goBack()}async goHome(){return this.viewModel.goHome()}goToFirstError(){const e=this.viewModel.getFirstVisibleInvalidFieldInput();if(!e)return;const{groupInput:t}=e;t&&(t.open||(t.open=!0)),this._focusedFieldInput=e.input,this._attemptFocusOnNextRender=!0,this.scheduleRender()}render(){return X("div",{class:this.classes(y.base,K.widget,K.panel)},this._renderContent(),this._renderAttachmentDialog())}submit(){this.viewModel.submit()}_setDateTimeTimeZoneMap(e){const{datePart:t,elementId:a}=e.dataset,i=n(this._dateComponentMap,`${a}`,()=>({}));switch(t){case"date":i.date=e;break;case"time":i.time=e;break;case"timeZone":i.timeZone=e}}_renderContent(){const{messages:e,viewModel:a}=this,{status:i}=a;return"failed"===i?a.hasTooManyComplexFeatures?this._renderErrorNotice(t(e.formFailedToLoadTooManyComplexFeatures,{num:a.maximumFeatureCountWithComplexForms})):a.hasTooManyFeatures?this._renderErrorNotice(t(e.formFailedToLoadTooManyFeatures,{num:a.maximumFeatureCount})):e.formFailedToLoad:a.expressionEvaluationFailed?this._renderErrorNotice(e.expressionEvaluationFailed):a.hasLayersWithContingentValues?this._renderErrorNotice(e.unsupportedContingentValues):"loading"===i&&this.visibleElements.loadingIndicator?X("calcite-loader",{key:"loader",label:this.messagesCommon?.loading}):0!==this.features.length?this._renderForm():void 0}_renderErrorNotice(e){return X("calcite-notice",{class:y.noticeError,icon:!0,kind:"warning",open:!0},X("div",{slot:"message"},e))}_renderForm(){return X("form",{class:y.form,id:this._formId,onsubmit:this._onFormSubmit},this._renderInvisibleFieldsError(),this._renderPage())}_renderPage(){switch(this.page){case"adding-attachments":return this._renderAttachmentAddPage();case"viewing-attachment-details":return this._renderAttachmentDetailPage();default:return this._renderFormContent()}}_renderInvisibleFieldsError(){const{viewModel:e}=this,{hasNonActiveInvalidFeatures:t,activeForm:a}=e;let i;if(!e.submitHasBeenAttempted)return null;if(a.invalidHiddenInputs.length>0)if(i=g(a,e.mode,this.messages),"batch"===this.viewModel.mode){const e=a.invalidHiddenInputs.filter(e=>"hidden:group-visibility-expression:all-features"===e.effectiveVisibilityCode||"hidden:visibility-expression:all-features"===e.visibilityCode);e.length>0?i+=` (${e.map(e=>e.label).join(", ")})`:i=null}else i+=` (${a.invalidHiddenInputs.map(e=>e.label).join(", ")})`;else if(t)return null;return i?X("calcite-notice",{class:y.noticeError,icon:!0,kind:"danger",open:!0},X("div",{slot:"message"},i)):null}_renderFormContent(){if(!this.viewModel.hasVisibleInputs)return[X("calcite-notice",{class:y.noticeError,icon:!0,kind:"warning",open:!0},X("div",{slot:"message"},this.messages.noVisibleFields[this.viewModel.noVisibleElementsReason]))];const{inputs:e}=this.viewModel.activeForm;return e.filter(e=>e.visible).map(e=>this._renderInput(e))}_renderInput(e){return A(e)?this._renderGroupInput(e):x(e)?this._renderLabeledField(e):M(e)?this._renderTextComponent(e):D(e)?this._renderRelationshipElementInput(e):V(e)?this._renderAttachmentElementInput(e):O(e)?this._renderUtilityNetworkAssociationsElementInput(e):void 0}_renderGroupInput(e){const{inputs:t,template:a,open:i}=e,n=t.filter(e=>e.visible),o=a.label??"";return X("calcite-block",{class:this.classes(y.group,"sequential"===this.groupDisplay?y.groupSequential:null,this.disabled?y.inputDisabled:null),collapsible:!0,description:a.description??void 0,disabled:this.effectiveDisabled,expanded:i,heading:o,headingLevel:this.headingLevel,key:`{${a.elementId}-key}`,label:o,onCalciteBlockClose:()=>{e.open=!1},onCalciteBlockOpen:()=>{e.open=!0}},n.map(e=>this._renderInput(e)))}_renderLabeledField(e){const{elementId:a}=e.template,{label:i,required:n,dataType:o}=e,l=n?t(this.messages.requiredFieldLabel,{name:i}):i;return X("calcite-label",{"aria-label":l,class:y.label,key:`field--${a}`},X("div",{class:y.labelTextContent,key:"labelTextContainer"},i,n?X("span",{"aria-hidden":"true",title:this.messagesCommon.required},"*"):void 0),"unsupported"!==o?this._renderFieldInput(e):this._renderReadOnlyComponent(e),this._renderAuxiliaryText(e))}_renderFieldInput(e){const t=this.getCommonInputProps(e),{dataType:a}=e;return"date"===a?this._renderDateComponents(e,t):"coded-value"===e.domain?.type?this._renderCodedInputs({input:e,props:t}):null!==e.multipleChoiceChoices?this._renderMultipleChoiceComponent({input:e,props:t}):"number"===a?this._renderNumberComponent(e,t):this._renderStringComponent(e,t)}_renderAuxiliaryText(e){const{compositeError:t,description:a,submittable:i}=e,n=!i&&t&&(this.viewModel.submitHasBeenAttempted||this._touchedInputs.has(e.template.elementId))?b(e,t,this.messages):null;return n?X("calcite-input-message",{icon:!0,status:"invalid"},n):a?X("calcite-input-message",{class:y.description,icon:!1,status:"idle"},a):null}_renderCodedInputs({input:e,props:t}){const a=e.input?.type??null,i=e.codedValueOptions;switch(a){case"switch":return this._renderSwitchField({input:e,props:t});case"radio-buttons":return this._renderRadioButtonGroupComponent({input:e,options:i.flat(),props:t});default:return this._renderComboBoxComponent({options:i,props:t,input:e})}}_renderMultipleChoiceComponent({input:e,props:t}){const{messages:a}=this,{multipleChoiceChoices:i,multipleChoiceInput:n,multipleChoiceValues:o}=e;if(!n||!i||!o)return null;const l=!0===n.includeSelectAllChoices,s=new Map;let r=o.length>0,c=!1;for(const g of o){const t=T({input:e,choiceValue:g});s.set(g,t),(t.checked||t.indeterminate)&&(c=!0),t.checked||(r=!1)}const d={checked:r,indeterminate:!r&&c},u=d.checked?a.deselectAllLabel:a.selectAllLabel,m=e.getMultipleChoiceOtherChoiceRenderState(this.messages.otherOptionLabel),p=t=>{this._saveValueFromMultipleChoiceCheckbox({input:e,checkbox:t,isSelectAllCheckbox:!0})},h=t=>{this._saveValueFromMultipleChoiceCheckbox({input:e,checkbox:t})},f=t=>{const{fieldName:a}=m;a&&this._saveOtherChoiceCheckboxValue({input:e,isChecked:t.checked,otherChoiceFieldName:a})},v=t=>{this._saveValueFromMultipleChoiceTextInput({input:e,textInput:t,otherChoiceFieldName:m.fieldName})};return X("div",{class:y.multipleChoiceInput,key:`${t.key}-multiple-choice-group`},l?this._renderMultipleChoiceSelectAllCheckbox({props:t,selectAllState:d,selectAllLabel:u,handleSelectAllCheckboxChange:p}):null,this._renderMultipleChoiceChoiceCheckboxes({input:e,props:t,checkboxStatesByValue:s,handleChoiceCheckboxChange:h}),m.shouldShow?this._renderMultipleChoiceOtherChoice({props:t,includeSelectAllChoices:l,otherChoiceRenderState:m,handleOtherChoiceCheckboxChange:f,handleOtherChoiceInputChange:v,differentValuesPlaceholder:a.differentValuesPlaceholder}):null)}_renderMultipleChoiceSelectAllCheckbox({props:e,selectAllState:t,selectAllLabel:a,handleSelectAllCheckboxChange:i}){return X("calcite-checkbox",{afterCreate:e.afterCreate,afterUpdate:e.afterUpdate,"aria-invalid":e["aria-invalid"],checked:t.checked,class:y.multipleChoiceSelectAll,"data-element-id":e[te],disabled:e.readOnly,indeterminate:t.indeterminate,key:`${e.key}-select-all`,label:a,labelText:a,onblur:e.onblur,onfocus:e.onfocus,value:ae,onCalciteCheckboxChange:({currentTarget:e})=>i(e)})}_renderMultipleChoiceChoiceCheckboxes({input:e,props:t,checkboxStatesByValue:a,handleChoiceCheckboxChange:i}){const{multipleChoiceChoices:n}=e;return n?n.map(e=>{const n=a.get(e.value)??{checked:!1,indeterminate:!1};return X("calcite-checkbox",{afterCreate:t.afterCreate,afterUpdate:t.afterUpdate,"aria-invalid":t["aria-invalid"],checked:n.checked,class:t.class,"data-element-id":t[te],disabled:t.readOnly,indeterminate:n.indeterminate,key:`${t.key}-${e.value}`,label:e.label,labelText:e.label,onblur:t.onblur,onfocus:t.onfocus,required:t.required,value:e.value,onCalciteCheckboxChange:({currentTarget:e})=>i(e)})}):[]}_renderMultipleChoiceOtherChoice({props:e,includeSelectAllChoices:t,otherChoiceRenderState:a,handleOtherChoiceCheckboxChange:i,handleOtherChoiceInputChange:n,differentValuesPlaceholder:o}){return X("div",{class:this.classes(y.multipleChoiceOtherChoice,t?y.multipleChoiceOtherChoiceWithSelectAll:null),key:`${e.key}-other-choice`},X("calcite-checkbox",{afterCreate:e.afterCreate,afterUpdate:e.afterUpdate,"aria-invalid":e["aria-invalid"],checked:a.checkboxState.checked,class:e.class,"data-element-id":e[te],disabled:e.readOnly,indeterminate:a.checkboxState.indeterminate,key:`${e.key}-other-choice-checkbox`,label:a.label,labelText:a.label,onblur:e.onblur,onfocus:e.onfocus,value:ie,onCalciteCheckboxChange:({currentTarget:e})=>i(e)}),a.checkboxState.checked?X("calcite-input",{afterCreate:e.afterCreate,afterUpdate:e.afterUpdate,"aria-invalid":e["aria-invalid"],"aria-label":a.label,class:y.textElementInput,"data-element-id":e[te],disabled:e.readOnly,key:`${e.key}-other-choice-input`,maxLength:a.maxLength,onblur:e.onblur,onfocus:e.onfocus,placeholder:a.value===S?o:a.hint,required:e.required,type:"text",value:a.normalizedValue===S?"":a.normalizedValue?String(a.normalizedValue):"",onCalciteInputInput:({currentTarget:e})=>n(e)}):null)}async _saveValueFromMultipleChoiceCheckbox({input:e,checkbox:t,isSelectAllCheckbox:a=!1}){if(e.multipleChoiceInput&&!a&&"batch"===this.viewModel.mode)return void await this._saveMultipleChoiceCheckboxValueByFeature({input:e,checkbox:t});const i=e.value,n=this._parseValue(t,e,a);n!==i&&await this.viewModel.setValue(e.template.elementId,n)}async _saveValueFromMultipleChoiceTextInput({input:e,textInput:t,otherChoiceFieldName:a}){if(!a)return;const i=t.value,n=null==i||""===i?null:i;e.initializeExplicitMultipleChoiceOtherChoiceCheckedState(),e.stashMultipleChoiceOtherChoiceDraftValueForFeatures(e.features,n);const o=e.features.toArray().filter(e=>e.getAttribute(a)!==n);if(0!==o.length){for(const e of o)e.setAttribute(a,n);this.viewModel.userHasChangedValues=!0,await e.expressionsManager.valueChanged(a,o),this.viewModel.emit("value-change",{features:o.map(e=>e.source),fieldName:a,name:"value-change",value:n})}}async _saveOtherChoiceCheckboxValue({input:e,isChecked:t,otherChoiceFieldName:a}){e.setExplicitMultipleChoiceOtherChoiceCheckedState(t),t||e.setMultipleChoiceOtherChoiceDraftValuesFromFeatures(e.features.toArray());const i=e.features.toArray().filter(i=>{const n=i.getAttribute(a);if(t){if(!ee(n))return!1;const t=e.getMultipleChoiceOtherChoiceDraftValue(i),o=$(t)?t:L;return i.setAttribute(a,o),!0}return null!=n&&(i.setAttribute(a,null),!0)});0!==i.length&&(this.viewModel.userHasChangedValues=!0,await e.expressionsManager.valueChanged(a,i),this.viewModel.emit("value-change",{features:i.map(e=>e.source),fieldName:a,name:"value-change",value:this._getFieldValueByFieldNameForInput(e,a)}))}async _saveMultipleChoiceCheckboxValueByFeature({input:e,checkbox:t}){if(!e.multipleChoiceInput||!e.multipleChoiceValues)return;const a=e.features.toArray().filter(a=>{const i=a.getAttribute(e.fieldName),n=U({input:e,choiceValue:t.value,currentValue:i,isChecked:t.checked});return i!==n&&(a.setAttribute(e.fieldName,n),!0)});0!==a.length&&(this.viewModel.userHasChangedValues=!0,await e.expressionsManager.valueChanged(e.fieldName,a),this.viewModel.emit("value-change",{features:a.map(e=>e.source),fieldName:e.fieldName,name:"value-change",value:this._getFieldValueByFieldNameForInput(e,e.fieldName)}))}_getFieldValueByFieldNameForInput(e,t){const a=e.features.toArray().map(e=>e.getAttribute(t));if(0===a.length)return null;const[i]=a;return a.every(e=>e===i)?i:S}_renderSwitchField({input:e,props:t}){if((this._batchSwitchInputInitialValues.get(e)===S||e.value===S)&&"batch"===this.viewModel.mode){const a={dropdown:{afterCreate:this._afterComponentCreateOrUpdate,afterUpdate:this._afterComponentCreateOrUpdate,disabled:t.readOnly,open:!1,[te]:t[te]},trigger:{appearance:"transparent",iconEnd:"chevron-down",kind:"neutral",slot:"trigger",label:t.label},group:{mode:"single"}};return this._renderDropdownComponent({buttonValue:e.value,dropdownProps:a,options:[{name:this.messages.differentValuesPlaceholder,value:S,disabled:!0},...e.codedValueDomainOptions]})}return this._renderSwitchComponent({input:e,props:t})}_renderSwitchComponent({input:e,props:t}){return X("calcite-switch",{...t,checked:!!C(e.template,"switch")&&e.value===e.template.input.onValue,class:y.inputSwitch,disabled:t.readOnly,onblur:()=>{this._focusedFieldInput=null},onCalciteSwitchChange:({currentTarget:e})=>this._saveInput(e)})}_renderDropdownComponent({buttonValue:e,options:t,dropdownProps:a}){const{trigger:i,dropdown:n,group:o}=a;return X("calcite-dropdown",{...n,onblur:()=>{this._focusedFieldInput=null},onfocus:this._onComponentFocus,topLayerDisabled:this.topLayerDisabled,onCalciteDropdownSelect:({currentTarget:e})=>this._saveInput(e)},X("calcite-button",{...i},e===S?this.messages.differentValuesPlaceholder:e),X("calcite-dropdown-group",{selectionMode:o.mode},t.map(t=>X("calcite-dropdown-item",{disabled:t.disabled,label:String(t.name),selected:e===t.value},t.name))))}_renderComboBoxComponent({input:e,options:t,props:a}){const i="INSERT"===this.viewModel.editType,n=this._touchedInputs.has(e?.template?.elementId),o=i&&e.showNoValueOptionEnabled&&!n?()=>{}:a.onblur,l={...a,onblur:o};return X("calcite-combobox",{...l,selectionMode:"single",topLayerDisabled:this.topLayerDisabled,value:a.placeholder===this.messages.differentValuesPlaceholder?S:String(a.value),onCalciteComboboxChange:({currentTarget:e})=>{e.value!==S&&this._saveInput(e)}},this.renderComboboxOptionsList({input:e,options:t,props:a}))}renderComboboxOptionsList({input:e,options:t,props:a}){const[i,n]=t.map(e=>e.map(({name:e,value:t})=>X("calcite-combobox-item",{heading:e,key:`#${t}`,selected:a.value===t,value:`${t}`}))),o=[...i];n.length>0&&o.push(X("calcite-combobox-item-group",{key:"unsupported",label:this.messages.unsupportedDomainGroupTitle},n));const l=a.placeholder===this.messages.differentValuesPlaceholder,s=!l&&ee(a.value);return e.showNoValueOptionEnabled&&o.unshift(X("calcite-combobox-item",{heading:e.showNoValueLabel||this.messages.empty,key:"empty-option",selected:s,value:""})),l&&o.unshift(X("calcite-combobox-item",{heading:this.messages.differentValuesPlaceholder,key:S,selected:!0,value:S})),o}_renderRadioButtonGroupComponent({input:e,options:t,props:a}){const i=t.map(({name:t,value:i})=>this._renderRadioButtons({label:t,value:i,selected:i===e.value,props:a}));if(e.showNoValueOptionEnabled){const t="",n=e.showNoValueLabel||this.messages.empty,o=ee(e.value);i.unshift(this._renderRadioButtons({label:n,value:t,selected:o,props:a}))}return X("calcite-radio-button-group",{afterCreate:this._afterRadioGroupCreateOrUpdate,afterUpdate:this._afterRadioGroupCreateOrUpdate,class:y.inputRadioGroup,disabled:a.readOnly,key:`${a.key}-radio-group`,layout:"vertical",name:a.name,required:a.required},i,a.placeholder===this.messages.differentValuesPlaceholder?X("calcite-label",{class:y.placeholderRadio,key:a.label,layout:"inline"},X("calcite-radio-button",{checked:!0,class:y.inputRadio,disabled:!0,name:a.placeholder,value:a.placeholder}),a.placeholder):null)}_renderRadioButtons({value:e,selected:t,label:a,props:i}){return X("calcite-label",{class:y.inputRadioLabel,key:i.label,layout:"inline"},X("calcite-radio-button",{...i,afterCreate:void 0,afterUpdate:void 0,checked:t,class:y.inputRadio,disabled:i.readOnly,name:i.label,onblur:()=>{this._focusedFieldInput=null},value:e,onCalciteRadioButtonChange:({currentTarget:e})=>{e.checked&&this._saveInput(e)}}),a)}_renderStringComponent(e,t){const{template:a}=e;return!a.field.editable||this.readOnly?this._renderReadOnlyComponent(e):"text-area"===a.input?.type?X("calcite-text-area",{...t,class:this.classes(y.individualElement),resize:"vertical",value:t.value?String(t.value):"",onCalciteTextAreaInput:({currentTarget:e})=>this._saveInput(e)}):X("calcite-input",{...t,class:this.classes(y.individualElement),type:"text",value:t.value?String(t.value):"",onCalciteInputInput:({currentTarget:e})=>this._saveInput(e)})}_renderNumberComponent(e,t){const a=d(e.field);return X("calcite-input-number",{...t,integer:a,type:"number",value:a&&""!==t.value?Math.round(parseFloat(String(t.value))).toString():String(t.value),onCalciteInputNumberInput:({currentTarget:e})=>this._saveInput(e)})}_renderReadOnlyComponent(e,t){const a=this.getCommonInputProps(e);return X("calcite-input",{...a,class:this.classes(y.fieldInput,y.inputDisabled,y.individualElement),readOnly:!0,type:"text",value:String(t??a.value??"")})}_renderDateComponents(e,t){const{field:a}=e;let i;switch(a.type){case"date":i=this._renderDateFieldComponents(e,t);break;case"date-only":i=this._renderDateOnlyFieldComponent(e,t);break;case"time-only":i=this._renderTimeOnlyFieldComponent(e,t);break;case"timestamp-offset":i=this._renderTimestampOffsetFieldComponents(e,t);break;default:i=this._renderReadOnlyComponent(e,j(a,t.value,{timeZone:e.effectiveTimeZone,...z(e.template.field)}))}return e.value===S?[i,X("calcite-input-message",{icon:"information",key:"diff-values-message",status:"idle"},this.messages.differentValues)]:i}_renderDateOnlyFieldComponent(e,t){const{class:a,key:i,readOnly:n}=t,{rawMax:o,rawMin:l}=e.range;return X("calcite-input-date-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,class:a,"data-date-part":"date","data-element-id":t[te],key:`${i}-date-input`,max:u(o)?o:void 0,min:u(l)?l:void 0,onblur:()=>{this._focusedFieldInput=null},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:n,topLayerDisabled:this.topLayerDisabled,value:e.value===S?"":e.value?String(e.value):"",onCalciteInputDatePickerChange:t=>this._saveValueFromDateComponent(e,t.currentTarget)})}_renderTimeOnlyFieldComponent(e,t){const{class:a,key:i,readOnly:n}=t;return X("calcite-input-time-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,class:a,"data-date-part":"time","data-element-id":t[te],key:`${i}-time-input`,onblur:()=>{this._focusedFieldInput=null},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:n,value:e.value===S?"":e.value?String(e.value):"",onCalciteInputTimePickerChange:t=>this._saveValueFromDateComponent(e,t.currentTarget)})}_renderTimestampOffsetFieldComponents(e,t){const{class:a,key:i,readOnly:n}=t,{rawMax:o,rawMin:l}=e.range,s=Z(o),r=Z(l),c=Z(e.value===S?"":e.value),d=e.includeTimeOffset,u={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,overlayPositioning:"fixed",readOnly:n,[te]:t[te],onfocus:this._onComponentFocus};return X("div",{class:y.dateInputContainer,key:`${i}-date-time-container`},X("calcite-input-date-picker",{...u,class:a,"data-date-part":"date",key:`${i}-date-input`,max:s?.date??void 0,min:r?.date??void 0,onblur:()=>{this._focusedFieldInput=null},topLayerDisabled:this.topLayerDisabled,value:c.date??"",onCalciteInputDatePickerChange:t=>this._saveValueFromDateComponent(e,t.target)}),X("calcite-input-time-picker",{...u,class:a,"data-date-part":"time",key:`${i}-time-input`,onblur:()=>{this._focusedFieldInput=null},value:c.time??"",onCalciteInputTimePickerChange:t=>this._saveValueFromDateComponent(e,t.target)}),d?X("calcite-input-time-zone",{...u,class:a,clearable:e.value===S||null==e.value,"data-date-part":"timeZone",key:`${i}-timezone-input`,onblur:()=>{this._focusedFieldInput=null},value:c.timeZoneOffset||"",onCalciteInputTimeZoneChange:t=>this._saveValueFromDateComponent(e,t.target)}):null)}_renderDateFieldComponents(e,t){const{class:a,key:i,readOnly:n,min:o,max:l}=t,s=e.effectiveTimeZone,r=H(e.value===S?"":e.value,s),c=H(l,s),d=H(o,s),u=e.includeTime,m={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,overlayPositioning:"fixed",readOnly:n,[te]:t[te],onfocus:this._onComponentFocus};return X("div",{class:y.dateInputContainer,key:`${i}-date-time-container`},X("calcite-input-date-picker",{...m,class:a,"data-date-part":"date",key:`${i}-date-input`,max:c?.date??void 0,min:d?.date??void 0,onblur:()=>{this._focusedFieldInput=null},topLayerDisabled:this.topLayerDisabled,value:r.date??"",onCalciteInputDatePickerChange:t=>this._saveValueFromDateComponent(e,t.target)}),u?X("calcite-input-time-picker",{...m,"data-date-part":"time",key:`${i}-time-input`,onblur:()=>{this._focusedFieldInput=null},step:1,value:r.time??"",onCalciteInputTimePickerChange:t=>{this._saveValueFromDateComponent(e,t.target)}}):null)}_renderRelationshipElementInput(e){const{elementId:t}=e.template;return X("div",{class:y.relationshipElementInput,"data-testid":`relationship-element-${t}`,key:`relationship-element-${t}`})}_renderAttachmentElementInput(e){const{attachments:t,template:{description:a,elementId:i,label:n}}=e;return X("div",{class:y.attachmentElementInput,"data-testid":`attachment-element-${i}`,key:`attachment-element-${i}`},n?X("div",{class:y.attachmentElementLabel,key:`attachment-element-label-${i}`},n):null,a?X("div",{class:y.description,key:`attachment-element-description-${i}`},a):null,t.length?X("calcite-list",{class:y.attachmentElementList,key:`attachment-element-list-${i}`,label:n||this.messagesCommon.details,selectionAppearance:"border",selectionMode:"none"},t.map((t,a)=>{const n=this._formatAttachmentSize(t.size),o=this._getAttachmentLabel(t,a,n,e.displayFilename),l=o===n?void 0:n,s=f(t),r=this._isStagedAttachmentAddition(t);return X("calcite-list-item",{class:y.attachmentElementListItem,description:l,key:`attachment-item-${s}`,label:o,onCalciteListItemSelect:r?void 0:()=>this._setSelectedAttachment({attachmentKey:s,elementId:i})},X("div",{class:y.attachmentElementListItemStart,slot:"content-start"},this._renderAttachmentPreviewThumbnail(t,o,e)),r?X("div",{class:y.attachmentElementListItemActions,slot:"actions-end"},X("span",{class:y.attachmentElementListItemStagedIndicator}),X("calcite-button",{appearance:"transparent","aria-label":this.messagesCommon.delete,disabled:this.effectiveDisabled,iconStart:"x",kind:"neutral",onclick:()=>{this.viewModel.stageDeleteAttachment(i,t.globalId)},scale:"s"})):X("calcite-icon",{icon:"chevron-right",scale:"s",slot:"actions-end"}))})):X("div",{class:y.attachmentElementEmptyState,key:`attachment-element-empty-state-${i}`},this.messages.attachments.noAttachments),this._renderAttachmentAddAction(e))}_renderAttachmentAddAction(e){const{elementId:t}=e.template,a=this.effectiveDisabled||e.addDisabled;return X("div",{class:y.attachmentElementEmptyAction,key:`attachment-element-empty-action-${t}`},X("calcite-button",{appearance:"outline",disabled:a,iconStart:"attachment",kind:"neutral",onclick:()=>this._setAttachmentAddElementId(t),round:!0,scale:"s"},this.messages.attachments.attach))}_renderAttachmentAddPage(){const e=this.viewModel.selectedAttachmentAddInput;return e?this._renderAttachmentAddPanel(e):null}_renderAttachmentAddPanel(e){const{maxAttachmentCount:t}=e,{elementId:a}=e.template,i=null==t||t-e.attachments.length>1,n=this.effectiveDisabled||e.addDisabled,o=this.messages.attachments,l=o.dragAndDropFile,s="upload",r=e=>{this._attachmentFileInputMap.set(a,e)};return X("div",{class:y.attachmentElementAddPanel,key:`attachment-element-add-panel-${a}`},X("input",{accept:e.accept,afterCreate:r,afterRemoved:()=>{this._attachmentFileInputMap.delete(a)},afterUpdate:r,class:y.attachmentElementFileInput,"data-element-id":a,disabled:n,multiple:i,onchange:e=>{const t=e.currentTarget,i=t.files?Array.from(t.files):[];this._stageAttachmentFiles(a,i),t.value=""},type:"file"}),X("div",{class:y.attachmentElementAddDropzone,"data-disabled":n?"true":"false",ondragover:e=>{e.preventDefault()},ondrop:e=>{if(e.preventDefault(),n)return;const t=e.dataTransfer?.files?Array.from(e.dataTransfer.files):[];this._stageAttachmentFiles(a,t)}},X("calcite-icon",{class:y.attachmentElementAddDropzoneIcon,icon:s,scale:"l"}),X("div",{class:y.attachmentElementAddDropzoneHeading},o.addFile),X("div",{class:y.attachmentElementAddDropzoneDetail,title:l},l),X("calcite-button",{appearance:"outline-fill",disabled:n,iconStart:"folder-open",onclick:e=>{e.stopPropagation(),this._openAttachmentFilePicker(a,n)},scale:"s",type:"button"},o.selectFile)))}async _stageAttachmentFiles(e,t){if(0!==t.length)try{await this.viewModel.stageAddAttachments(e,t)}finally{this.viewModel.setSelectedAttachmentAddElementId(null)}}_openAttachmentFilePicker(e,t){t||this._attachmentFileInputMap.get(e)?.click()}_renderAttachmentDetailPage(){const e=this.selectedAttachmentDetails;if(!e)return;const{attachment:t,input:a}=e,i=f(t),n=!!a.getAttachmentPreviewUrl(t);return X("div",{class:y.attachmentElementDetail,key:`attachment-detail-panel-${a.template.elementId}-${i}`},X("div",{class:y.attachmentElementDetailPreview},this._renderAttachmentPreviewImageForInput(t,a)),X("div",{class:y.attachmentElementDetailActions},X("calcite-button",{appearance:"outline",disabled:!n,iconStart:"download-to",kind:"neutral",onclick:()=>{this._downloadAttachment(t)},scale:"s"},this.messages.attachments.download),v(t)?X("calcite-button",{appearance:"outline",disabled:!n,iconStart:"expand",kind:"neutral",onclick:this._maximizeSelectedAttachment,scale:"s"},this.messages.attachments.maximize):null,X("calcite-button",{appearance:"outline",disabled:!0,iconStart:"refresh",kind:"neutral",scale:"s"},this.messages.attachments.replace)),X("div",{class:y.attachmentElementDetailMetadata},X("span",{class:y.attachmentElementDetailMetadataLabel},this.messages.attachments.fileName),X("span",{class:y.attachmentElementDetailMetadataValue},t.name),X("span",{class:y.attachmentElementDetailMetadataLabel},this.messages.attachments.size),X("span",{class:y.attachmentElementDetailMetadataValue},this._formatAttachmentSize(t.size)),X("span",{class:y.attachmentElementDetailMetadataLabel},this.messages.attachments.type),X("span",{class:y.attachmentElementDetailMetadataValue},this._getLabelForAttachmentType(t))))}_renderAttachmentDialog(){const e=this._attachmentDialogInfo;if(!e)return null;const{attachment:t,input:a}=e;return X("calcite-dialog",{heading:t.name||this.messagesCommon.details,key:"attachment-preview-dialog",modal:!0,open:!0,placement:"cover",width:"l",onCalciteDialogClose:this._closeAttachmentDialog},X("div",{class:y.attachmentElementDetailPreview},this._renderAttachmentPreviewImageForInput(t,a)))}_setSelectedAttachment(e){this.viewModel.setSelectedAttachment(e),e||this.hideAttachmentDialog()}_setAttachmentAddElementId(e){this.viewModel.setSelectedAttachmentAddElementId(e),this.hideAttachmentDialog()}_getAttachmentLabel(e,a,i,n){return!1!==n&&u(e.name)&&e.name.length>0?e.name:i!==this.messagesCommon.notApplicable?i:t(this.messages.attachments.attachmentNumberedLabel,{index:a+1})}_formatAttachmentSize(e){return null==e||Number.isNaN(e)?this.messagesCommon.notApplicable:s(this.messagesUnits,e)}_getLabelForAttachmentType({contentType:e}){if(!e)return this.messagesCommon.notApplicable;const t=this.messages.attachments.attachmentTypes,a=p(e);return t?.[a]||e}_renderAttachmentPreviewThumbnail(e,t,a){const i=a.getAttachmentPreviewUrl(e,64);return i&&v(e)?X("img",{alt:t,class:y.attachmentElementListItemThumb,src:i}):X("calcite-icon",{class:y.attachmentElementListItemIcon,icon:h(e.contentType),scale:"s"})}_isStagedAttachmentAddition(e){return"number"==typeof e.id&&e.id<0}_renderAttachmentPreviewImageForInput(e,t){const a=t.getAttachmentPreviewUrl(e),i=e.name||this.messagesCommon.details;return a&&v(e)?X("img",{alt:i,class:y.attachmentElementDetailPreviewImage,src:a,title:i}):[X("calcite-icon",{class:y.attachmentElementDetailPreviewIcon,icon:h(e.contentType),scale:"l",textLabel:i,title:i}),this.messages.attachments.noPreviewAvailable]}async _downloadAttachment(e){await B(e)}hideAttachmentDialog(){this._attachmentDialogInfo=null}_renderTextComponent(e){const{elementId:t}=e.template;return X("div",{class:y.textElementInput,"data-testid":`text-element-${t}`,innerHTML:e.text,key:`text-element-${t}`})}_renderUtilityNetworkAssociationsElementInput(e){const{elementId:t}=e.template;return X("div",{class:y.utilityNetworkAssociationsElementInput,"data-testid":t,key:t})}getCommonInputProps(e){const{template:t,valid:a,value:i,minLength:n,maxLength:o,required:l,fieldName:s,editable:r,userHasChangedValue:c,range:{max:d,min:u}}=e,m=!r||this.readOnly,p=!m&&this.effectiveDisabled;let h=t.hint??void 0,f=!1;return i===S&&(h=this.messages.differentValuesPlaceholder,f=!0),{afterCreate:this._afterComponentCreateOrUpdate,afterUpdate:this._afterComponentCreateOrUpdate,"aria-invalid":a?"false":"true",class:this.classes(y.fieldInput,m?y.inputDisabled:null),status:!c&&!this.viewModel.submitHasBeenAttempted||a?"idle":"invalid",maxLength:o&&o>-1?o:void 0,minLength:n&&n>-1?n:void 0,key:t.elementId,label:s,name:s,max:null!=d?d:void 0,min:null!=u?u:void 0,disabled:p,readOnly:m,onblur:this._onComponentBlur,required:l,placeholder:h,value:f?"":i??"",[te]:t.elementId,onfocus:this._onComponentFocus}}_onFormSubmit(e){e.preventDefault()}_getFieldInputFromHTMLElement(e){return this.viewModel.findFieldInput(e.getAttribute(te))}_afterRadioGroupCreateOrUpdate(e){const t=e.selectedItem,a=e.querySelector("calcite-radio-button"),i=t||a;i&&this._afterComponentCreateOrUpdate(i)}_onComponentFocus(e){const t=e.target,a=this._getFieldInputFromHTMLElement(t);this._touchedInputs.add(a.template.elementId),this._focusedFieldInput=a}_afterComponentCreateOrUpdate(e){const t=this._getFieldInputFromHTMLElement(e),a=this._focusedFieldInput;this._attemptFocusOnNextRender&&a===t&&(this._attemptFocusOnNextRender=!1,Y(e))}_onComponentBlur(){this._focusedFieldInput=null}_resetTransientFormState(){this._attemptFocusOnNextRender=!1,this._focusedFieldInput=null,this._attachmentDialogInfo=null,this._attachmentFileInputMap.clear()}_parseValue(e,t,a=!1){const i=t.multipleChoiceInput,n=t.multipleChoiceValues;if(i&&n){const o=i.choiceDelimiter,l=e;if(a){return N({input:t}).checked?null:n.length>0?n.join(o):null}const s=P(t.value,o).filter(e=>e!==S),r=new Set(s);l.checked?r.add(l.value):r.delete(l.value);const c=n.filter(e=>r.has(e));return c.length?c.join(o):null}if(C(t.template,"switch")){if("calcite-dropdown"===e.localName&&t.domain)for(const a of t.domain.codedValues)if(a.name===e.selectedItems[0].textContent)return a.code;return e.checked?t.template.input.onValue:t.template.input.offValue}const o=e.value;return null==o||""===o?null:"number"===t.dataType?"-0"===o||"-0."===o||"-0,"===o?o:parseFloat(o):"date"===t.field.type?parseFloat(o):o}_saveInput(e){const t=this._getFieldInputFromHTMLElement(e),{elementId:a}=t.template;if(!t)return;const i=t?.value;if(C(t.template,"switch")&&"single"!==this.viewModel.mode){const e=n(this._batchSwitchInputInitialValues,t,()=>t.value);this._batchSwitchInputInitialValues.set(t,null===e?i:e)}const o=this._parseValue(e,t);o!==i&&this.viewModel.setValue(a,o)}_afterDateComponentCreate(e){this._setDateTimeTimeZoneMap(e),this._afterComponentCreateOrUpdate(e)}_saveValueFromDateComponent(e,t){const{elementId:a}=e.template,i=e.field.type,n=this._dateComponentMap.get(`${a}`);if(!n)return;const o=e.effectiveTimeZone;let l=e.value===S?void 0:e.value,s=null;"date-only"===i?s=Array.isArray(t.value)?t.value[0]:t.value:"time-only"===i?(l=q(l),s=q(t.value)):s="timestamp-offset"===i?null!=t.value?G({dateComponent:n.date,timeComponent:n.time,oldValue:l,timeZoneComponent:n.timeZone,defaultTimeZone:o}):null:null!=t.value?W({oldValue:l,dateComponent:n.date,timeZone:o,timeComponent:n.time?.value===S?void 0:n.time}):null,l!==s&&(null!==s&&t.value?this.viewModel.setValue(`${a}`,s):this.viewModel.setValue(`${a}`,null))}};e([r()],ne.prototype,"activeFeatureIndex",null),e([r()],ne.prototype,"disabled",null),e([r()],ne.prototype,"effectiveTitle",null),e([r()],ne.prototype,"effectiveDisabled",null),e([r()],ne.prototype,"features",null),e([r()],ne.prototype,"footerButtonInfos",null),e([r()],ne.prototype,"footerNoticeInfos",null),e([r()],ne.prototype,"map",null),e([r()],ne.prototype,"maximumFeatureCount",null),e([r()],ne.prototype,"maximumFeatureCountWithComplexForms",null),e([r()],ne.prototype,"spatialReference",null),e([r()],ne.prototype,"layerInfos",null),e([r()],ne.prototype,"timeZone",null),e([r()],ne.prototype,"headingLevel",void 0),e([r()],ne.prototype,"icon",null),e([r(),J("esri/t9n/common")],ne.prototype,"messagesCommon",void 0),e([r(),J("esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm")],ne.prototype,"messages",void 0),e([r(),J("esri/core/t9n/Units")],ne.prototype,"messagesUnits",void 0),e([r()],ne.prototype,"page",null),e([r()],ne.prototype,"readOnly",null),e([r()],ne.prototype,"selectedAttachment",null),e([r()],ne.prototype,"selectedAttachmentDetails",null),e([r()],ne.prototype,"valid",null),e([r({type:_}),Q(["value-change","submit"])],ne.prototype,"viewModel",void 0),e([r({type:w,nonNullable:!0})],ne.prototype,"visibleElements",void 0),e([r()],ne.prototype,"groupDisplay",void 0),e([r()],ne.prototype,"_attemptFocusOnNextRender",void 0),e([r()],ne.prototype,"_formId",null),e([r()],ne.prototype,"_focusedFieldInput",void 0),e([r()],ne.prototype,"_attachmentDialogInfo",void 0),ne=e([c("esri.widgets.BatchAttributeForm")],ne);const oe=ne;export{oe as default};
|
|
2
|
+
import{__decorate as e}from"tslib";import{substitute as t}from"../intl.js";import{deprecateWidget as a}from"../core/deprecate.js";import i from"../core/Logger.js";import{getOrCreateMapValue as n}from"../core/MapUtils.js";import{watch as l,when as s,on as o}from"../core/reactiveUtils.js";import{formatFileSize as r}from"../core/unitFormatUtils.js";import{property as c,subclass as d}from"../core/accessorSupport/decorators.js";import{isIntegerField as m}from"../layers/support/fieldUtils.js";import{isString as u}from"../support/guards.js";import p from"./Widget.js";import{getAttachmentTypeCategory as h,getCalciteIconForAttachment as v}from"./Attachments/support/attachmentUtils.js";import{getAttachmentKey as f,isImageAttachment as g}from"./BatchAttributeForm/attachmentUtils.js";import{getHiddenFieldsValidationErrorMessage as b,getVisibleFieldInputValidationErrorMessage as C,isElementTemplateWithInputType as _}from"./BatchAttributeForm/batchAttributeFormUtils.js";import y from"./BatchAttributeForm/BatchAttributeFormViewModel.js";import{css as I}from"./BatchAttributeForm/css.js";import{makeAddAttachmentFooterButtons as F,makeViewingAttachmentFooterButtons as A,makeDefaultFooterButtons as w}from"./BatchAttributeForm/interfaceUtils.js";import k from"./BatchAttributeForm/VisibleElements.js";import{isGroupInput as x,isFieldInput as M,isTextElementInput as D,isRelationshipElementInput as V,isAttachmentElementInput as E,isUtilityNetworkAssociationsElementInput as T,differentValuesString as O}from"./BatchAttributeForm/inputs/support/inputUtils.js";import{clearMultipleChoiceOtherChoiceStateForViewModel as S,getMultipleChoiceCheckboxState as L,otherChoiceCheckedPlaceholderValue as U,getUpdatedMultipleChoiceValueForFeature as P,getMultipleChoiceSelectAllState as N,splitMultipleChoiceValue as $,canRestoreMultipleChoiceOtherChoiceDraftValue as B}from"./BatchAttributeForm/inputs/support/multipleChoiceInputUtils.js";import{downloadAttachmentInfo as R}from"./FeatureTable/support/exportUtils.js";import{loadCalciteComponents as j}from"./support/componentsUtils.js";import{getLabelForDateFieldValue as z,getIntlOptionsForField as Z,prepareISOFieldValueForDateComponents as H,prepareUnixFieldValueForDateComponents as q,normalizeTimeOnlyString as G,getISOFieldValueFromDateComponents as W,getUnixFieldValueFromDateComponents as K}from"./support/dateUtils.js";import{globalCss as J}from"./support/globalCss.js";import{calciteListFilterProps as Q}from"./support/listUtils.js";import{messageBundle as X,vmEvent as Y,tsx as ee}from"./support/widget.js";import{setFocus as te}from"./support/widgetUtils.js";import{isEmptyValue as ae}from"./support/forms/formUtils.js";const ie="data-element-id",ne="esri_BatchAttributeForm_select_all",le="esri_BatchAttributeForm_other_choice";let se=class extends p{constructor(e,t){super(e,t),this.headingLevel=2,this.messagesCommon=null,this.messages=null,this.messagesUnits=null,this.viewModel=new y,this.visibleElements=new k,this.groupDisplay="all",this._attemptFocusOnNextRender=!1,this._dateComponentMap=new Map,this._touchedInputs=new Set,this._focusedFieldInput=null,this._batchSwitchInputInitialValues=new Map,this._attachmentDialogInfo=null,this._attachmentListFilterText="",this._attachmentFileInputMap=new Map,this._maximizeSelectedAttachment=()=>{this._attachmentDialogInfo=this.selectedAttachmentDetails},this._closeAttachmentDialog=()=>{this.hideAttachmentDialog()},this._saveInput=this._saveInput.bind(this),this._onFormSubmit=this._onFormSubmit.bind(this),this._onComponentFocus=this._onComponentFocus.bind(this),this._onComponentBlur=this._onComponentBlur.bind(this),this._afterComponentCreateOrUpdate=this._afterComponentCreateOrUpdate.bind(this),this._afterDateComponentCreate=this._afterDateComponentCreate.bind(this),this._afterRadioGroupCreateOrUpdate=this._afterRadioGroupCreateOrUpdate.bind(this),e?.suppressDeprecationWarning||(this.announceDeprecation=()=>{a(i.getLogger(this),"Editor","arcgis-editor",{version:"5.0"})})}normalizeCtorArgs(e={}){const{suppressDeprecationWarning:t,...a}=e;return a}initialize(){this.addHandles([l(()=>this.features,()=>{this._dateComponentMap.clear(),this._resetTransientFormState(),S(this.viewModel,{includeDraftValues:!0})}),l(()=>this.viewModel.activeForm,()=>{this._batchSwitchInputInitialValues.clear(),this._resetTransientFormState(),S(this.viewModel)}),l(()=>this.viewModel.selectedAttachmentAddElementId,()=>{this.hideAttachmentDialog()}),s(()=>!this.selectedAttachmentDetails,()=>this.hideAttachmentDialog()),l(()=>this.viewModel.selectedAttachmentListElementId,()=>{this._attachmentListFilterText=""}),o(()=>this.viewModel,"submit",()=>{this.valid||this.goToFirstError()})])}loadDependencies(){return j({action:()=>import("@esri/calcite-components/dist/components/calcite-action"),block:()=>import("@esri/calcite-components/dist/components/calcite-block"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),checkbox:()=>import("@esri/calcite-components/dist/components/calcite-checkbox"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),"combobox-item-group":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item-group"),dialog:()=>import("@esri/calcite-components/dist/components/calcite-dialog"),dropdown:()=>import("@esri/calcite-components/dist/components/calcite-dropdown"),"dropdown-group":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-group"),"dropdown-item":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-item"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker"),"input-time-zone":()=>import("@esri/calcite-components/dist/components/calcite-input-time-zone"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),"input-message":()=>import("@esri/calcite-components/dist/components/calcite-input-message"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch"),"text-area":()=>import("@esri/calcite-components/dist/components/calcite-text-area"),"radio-button":()=>import("@esri/calcite-components/dist/components/calcite-radio-button"),"radio-button-group":()=>import("@esri/calcite-components/dist/components/calcite-radio-button-group")})}get activeFeatureIndex(){return this.viewModel.activeFeatureIndex}set activeFeatureIndex(e){this.viewModel.activeFeatureIndex=e}get disabled(){return this.viewModel.disabled}set disabled(e){this.viewModel.disabled=e}get effectiveTitle(){const{features:e,messages:t,page:a}=this;return"viewing-attachment-details"===a?t.titles.editAttachment:"adding-attachments"===a?t.titles.addAttachments:"viewing-attachments"===a?t.titles.attachments:1===e.length||this.activeFeatureIndex>-1?t.titles.editFeature:e.length>1?t.titles.editFeatures:""}get effectiveDisabled(){return this.disabled||this.viewModel.updating}get features(){return this.viewModel.features}set features(e){this.viewModel.features=e}get footerButtonInfos(){if(!this.features.length)return[];const{page:e,messages:t}=this,a=this.viewModel.selectedAttachmentAddElementId;return"adding-attachments"===e&&a?F({messages:t,onclick:()=>this._attachmentFileInputMap.get(a)?.click()}):"viewing-attachment-details"===e?A({messages:t}):"viewing-attachments"===e?[]:w({formId:this._formId,callback:this.submit,messages:t})}get footerNoticeInfos(){if(!this.features.length)return[];const{messages:{footerNotices:e}}=this;return[]}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get maximumFeatureCount(){return this.viewModel.maximumFeatureCount}set maximumFeatureCount(e){this.viewModel.maximumFeatureCount=e}get maximumFeatureCountWithComplexForms(){return this.viewModel.maximumFeatureCountWithComplexForms}set maximumFeatureCountWithComplexForms(e){this.viewModel.maximumFeatureCountWithComplexForms=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get layerInfos(){return this.viewModel.layerInfos}set layerInfos(e){this.viewModel.layerInfos=e}get timeZone(){return this.viewModel.timeZone}set timeZone(e){this.viewModel.timeZone=e}get icon(){return"edit-attributes"}set icon(e){this._overrideIfSome("icon",e)}get page(){return this.viewModel.page}get readOnly(){return this.viewModel.readOnly}set readOnly(e){this.viewModel.readOnly=e}get selectedAttachment(){return this.viewModel.selectedAttachment}get selectedAttachmentDetails(){return this.viewModel.selectedAttachmentDetails}get valid(){return this.viewModel.valid}get _formId(){return`${this.id}-form`}async goBack(){return this.viewModel.goBack()}async goHome(){return this.viewModel.goHome()}goToFirstError(){const e=this.viewModel.getFirstVisibleInvalidFieldInput();if(!e)return;const{groupInput:t}=e;t&&(t.open||(t.open=!0)),this._focusedFieldInput=e.input,this._attemptFocusOnNextRender=!0,this.scheduleRender()}render(){return ee("div",{class:this.classes(I.base,J.widget,J.panel)},this._renderContent(),this._renderAttachmentDialog())}submit(){this.viewModel.submit()}_setDateTimeTimeZoneMap(e){const{datePart:t,elementId:a}=e.dataset,i=n(this._dateComponentMap,`${a}`,()=>({}));switch(t){case"date":i.date=e;break;case"time":i.time=e;break;case"timeZone":i.timeZone=e}}_renderContent(){const{messages:e,viewModel:a}=this,{status:i}=a;return"failed"===i?a.hasTooManyComplexFeatures?this._renderErrorNotice(t(e.formFailedToLoadTooManyComplexFeatures,{num:a.maximumFeatureCountWithComplexForms})):a.hasTooManyFeatures?this._renderErrorNotice(t(e.formFailedToLoadTooManyFeatures,{num:a.maximumFeatureCount})):e.formFailedToLoad:a.expressionEvaluationFailed?this._renderErrorNotice(e.expressionEvaluationFailed):a.hasLayersWithContingentValues?this._renderErrorNotice(e.unsupportedContingentValues):"loading"===i&&this.visibleElements.loadingIndicator?ee("calcite-loader",{key:"loader",label:this.messagesCommon?.loading}):0!==this.features.length?this._renderForm():void 0}_renderErrorNotice(e){return ee("calcite-notice",{class:I.noticeError,icon:!0,kind:"warning",open:!0},ee("div",{slot:"message"},e))}_renderForm(){return ee("form",{class:I.form,id:this._formId,onsubmit:this._onFormSubmit},this._renderInvisibleFieldsError(),this._renderPage())}_renderPage(){switch(this.page){case"adding-attachments":return this._renderAttachmentAddPage();case"viewing-attachments":return this._renderAttachmentListPage();case"viewing-attachment-details":return this._renderAttachmentDetailPage();default:return this._renderFormContent()}}_renderInvisibleFieldsError(){const{viewModel:e}=this,{hasNonActiveInvalidFeatures:t,activeForm:a}=e;let i;if(!e.submitHasBeenAttempted)return null;if(a.invalidHiddenInputs.length>0)if(i=b(a,e.mode,this.messages),"batch"===this.viewModel.mode){const e=a.invalidHiddenInputs.filter(e=>"hidden:group-visibility-expression:all-features"===e.effectiveVisibilityCode||"hidden:visibility-expression:all-features"===e.visibilityCode);e.length>0?i+=` (${e.map(e=>e.label).join(", ")})`:i=null}else i+=` (${a.invalidHiddenInputs.map(e=>e.label).join(", ")})`;else if(t)return null;return i?ee("calcite-notice",{class:I.noticeError,icon:!0,kind:"danger",open:!0},ee("div",{slot:"message"},i)):null}_renderFormContent(){if(!this.viewModel.hasVisibleInputs)return[ee("calcite-notice",{class:I.noticeError,icon:!0,kind:"warning",open:!0},ee("div",{slot:"message"},this.messages.noVisibleFields[this.viewModel.noVisibleElementsReason]))];const{inputs:e}=this.viewModel.activeForm;return e.filter(e=>e.visible).map(e=>this._renderInput(e))}_renderInput(e){return x(e)?this._renderGroupInput(e):M(e)?this._renderLabeledField(e):D(e)?this._renderTextComponent(e):V(e)?this._renderRelationshipElementInput(e):E(e)?this._renderAttachmentElementInput(e):T(e)?this._renderUtilityNetworkAssociationsElementInput(e):void 0}_renderGroupInput(e){const{inputs:t,template:a,open:i}=e,n=t.filter(e=>e.visible),l=a.label??"";return ee("calcite-block",{class:this.classes(I.group,"sequential"===this.groupDisplay?I.groupSequential:null,this.disabled?I.inputDisabled:null),collapsible:!0,description:a.description??void 0,disabled:this.effectiveDisabled,expanded:i,heading:l,headingLevel:this.headingLevel,key:`{${a.elementId}-key}`,label:l,onCalciteBlockClose:()=>{e.open=!1},onCalciteBlockOpen:()=>{e.open=!0}},n.map(e=>this._renderInput(e)))}_renderLabeledField(e){const{elementId:a}=e.template,{label:i,required:n,dataType:l}=e,s=n?t(this.messages.requiredFieldLabel,{name:i}):i;return ee("calcite-label",{"aria-label":s,class:I.label,key:`field--${a}`},ee("div",{class:I.labelTextContent,key:"labelTextContainer"},i,n?ee("span",{"aria-hidden":"true",title:this.messagesCommon.required},"*"):void 0),"unsupported"!==l?this._renderFieldInput(e):this._renderReadOnlyComponent(e),this._renderAuxiliaryText(e))}_renderFieldInput(e){const t=this.getCommonInputProps(e),{dataType:a}=e;return"date"===a?this._renderDateComponents(e,t):"coded-value"===e.domain?.type?this._renderCodedInputs({input:e,props:t}):null!==e.multipleChoiceChoices?this._renderMultipleChoiceComponent({input:e,props:t}):"number"===a?this._renderNumberComponent(e,t):this._renderStringComponent(e,t)}_renderAuxiliaryText(e){const{compositeError:t,description:a,submittable:i}=e,n=!i&&t&&(this.viewModel.submitHasBeenAttempted||this._touchedInputs.has(e.template.elementId))?C(e,t,this.messages):null;return n?ee("calcite-input-message",{icon:!0,status:"invalid"},n):a?ee("calcite-input-message",{class:I.description,icon:!1,status:"idle"},a):null}_renderCodedInputs({input:e,props:t}){const a=e.input?.type??null,i=e.codedValueOptions;switch(a){case"switch":return this._renderSwitchField({input:e,props:t});case"radio-buttons":return this._renderRadioButtonGroupComponent({input:e,options:i.flat(),props:t});default:return this._renderComboBoxComponent({options:i,props:t,input:e})}}_renderMultipleChoiceComponent({input:e,props:t}){const{messages:a}=this,{multipleChoiceChoices:i,multipleChoiceInput:n,multipleChoiceValues:l}=e;if(!n||!i||!l)return null;const s=!0===n.includeSelectAllChoices,o=new Map;let r=l.length>0,c=!1;for(const g of l){const t=L({input:e,choiceValue:g});o.set(g,t),(t.checked||t.indeterminate)&&(c=!0),t.checked||(r=!1)}const d={checked:r,indeterminate:!r&&c},m=d.checked?a.deselectAllLabel:a.selectAllLabel,u=e.getMultipleChoiceOtherChoiceRenderState(this.messages.otherOptionLabel),p=t=>{this._saveValueFromMultipleChoiceCheckbox({input:e,checkbox:t,isSelectAllCheckbox:!0})},h=t=>{this._saveValueFromMultipleChoiceCheckbox({input:e,checkbox:t})},v=t=>{const{fieldName:a}=u;a&&this._saveOtherChoiceCheckboxValue({input:e,isChecked:t.checked,otherChoiceFieldName:a})},f=t=>{this._saveValueFromMultipleChoiceTextInput({input:e,textInput:t,otherChoiceFieldName:u.fieldName})};return ee("div",{class:I.multipleChoiceInput,key:`${t.key}-multiple-choice-group`},s?this._renderMultipleChoiceSelectAllCheckbox({props:t,selectAllState:d,selectAllLabel:m,handleSelectAllCheckboxChange:p}):null,this._renderMultipleChoiceChoiceCheckboxes({input:e,props:t,checkboxStatesByValue:o,handleChoiceCheckboxChange:h}),u.shouldShow?this._renderMultipleChoiceOtherChoice({props:t,includeSelectAllChoices:s,otherChoiceRenderState:u,handleOtherChoiceCheckboxChange:v,handleOtherChoiceInputChange:f,differentValuesPlaceholder:a.differentValuesPlaceholder}):null)}_renderMultipleChoiceSelectAllCheckbox({props:e,selectAllState:t,selectAllLabel:a,handleSelectAllCheckboxChange:i}){return ee("calcite-checkbox",{afterCreate:e.afterCreate,afterUpdate:e.afterUpdate,"aria-invalid":e["aria-invalid"],checked:t.checked,class:I.multipleChoiceSelectAll,"data-element-id":e[ie],disabled:e.readOnly,indeterminate:t.indeterminate,key:`${e.key}-select-all`,label:a,labelText:a,onblur:e.onblur,onfocus:e.onfocus,value:ne,onCalciteCheckboxChange:({currentTarget:e})=>i(e)})}_renderMultipleChoiceChoiceCheckboxes({input:e,props:t,checkboxStatesByValue:a,handleChoiceCheckboxChange:i}){const{multipleChoiceChoices:n}=e;return n?n.map(e=>{const n=a.get(e.value)??{checked:!1,indeterminate:!1};return ee("calcite-checkbox",{afterCreate:t.afterCreate,afterUpdate:t.afterUpdate,"aria-invalid":t["aria-invalid"],checked:n.checked,class:t.class,"data-element-id":t[ie],disabled:t.readOnly,indeterminate:n.indeterminate,key:`${t.key}-${e.value}`,label:e.label,labelText:e.label,onblur:t.onblur,onfocus:t.onfocus,required:t.required,value:e.value,onCalciteCheckboxChange:({currentTarget:e})=>i(e)})}):[]}_renderMultipleChoiceOtherChoice({props:e,includeSelectAllChoices:t,otherChoiceRenderState:a,handleOtherChoiceCheckboxChange:i,handleOtherChoiceInputChange:n,differentValuesPlaceholder:l}){return ee("div",{class:this.classes(I.multipleChoiceOtherChoice,t?I.multipleChoiceOtherChoiceWithSelectAll:null),key:`${e.key}-other-choice`},ee("calcite-checkbox",{afterCreate:e.afterCreate,afterUpdate:e.afterUpdate,"aria-invalid":e["aria-invalid"],checked:a.checkboxState.checked,class:e.class,"data-element-id":e[ie],disabled:e.readOnly,indeterminate:a.checkboxState.indeterminate,key:`${e.key}-other-choice-checkbox`,label:a.label,labelText:a.label,onblur:e.onblur,onfocus:e.onfocus,value:le,onCalciteCheckboxChange:({currentTarget:e})=>i(e)}),a.checkboxState.checked?ee("calcite-input",{afterCreate:e.afterCreate,afterUpdate:e.afterUpdate,"aria-invalid":e["aria-invalid"],"aria-label":a.label,class:I.textElementInput,"data-element-id":e[ie],disabled:e.readOnly,key:`${e.key}-other-choice-input`,maxLength:a.maxLength,onblur:e.onblur,onfocus:e.onfocus,placeholder:a.value===O?l:a.hint,required:e.required,type:"text",value:a.normalizedValue===O?"":a.normalizedValue?String(a.normalizedValue):"",onCalciteInputInput:({currentTarget:e})=>n(e)}):null)}async _saveValueFromMultipleChoiceCheckbox({input:e,checkbox:t,isSelectAllCheckbox:a=!1}){if(e.multipleChoiceInput&&!a&&"batch"===this.viewModel.mode)return void await this._saveMultipleChoiceCheckboxValueByFeature({input:e,checkbox:t});const i=e.value,n=this._parseValue(t,e,a);n!==i&&await this.viewModel.setValue(e.template.elementId,n)}async _saveValueFromMultipleChoiceTextInput({input:e,textInput:t,otherChoiceFieldName:a}){if(!a)return;const i=t.value,n=null==i||""===i?null:i;e.initializeExplicitMultipleChoiceOtherChoiceCheckedState(),e.stashMultipleChoiceOtherChoiceDraftValueForFeatures(e.features,n);const l=e.features.toArray().filter(e=>e.getAttribute(a)!==n);if(0!==l.length){for(const e of l)e.setAttribute(a,n);this.viewModel.userHasChangedValues=!0,await e.expressionsManager.valueChanged(a,l),this.viewModel.emit("value-change",{features:l.map(e=>e.source),fieldName:a,name:"value-change",value:n})}}async _saveOtherChoiceCheckboxValue({input:e,isChecked:t,otherChoiceFieldName:a}){e.setExplicitMultipleChoiceOtherChoiceCheckedState(t),t||e.setMultipleChoiceOtherChoiceDraftValuesFromFeatures(e.features.toArray());const i=e.features.toArray().filter(i=>{const n=i.getAttribute(a);if(t){if(!ae(n))return!1;const t=e.getMultipleChoiceOtherChoiceDraftValue(i),l=B(t)?t:U;return i.setAttribute(a,l),!0}return null!=n&&(i.setAttribute(a,null),!0)});0!==i.length&&(this.viewModel.userHasChangedValues=!0,await e.expressionsManager.valueChanged(a,i),this.viewModel.emit("value-change",{features:i.map(e=>e.source),fieldName:a,name:"value-change",value:this._getFieldValueByFieldNameForInput(e,a)}))}async _saveMultipleChoiceCheckboxValueByFeature({input:e,checkbox:t}){if(!e.multipleChoiceInput||!e.multipleChoiceValues)return;const a=e.features.toArray().filter(a=>{const i=a.getAttribute(e.fieldName),n=P({input:e,choiceValue:t.value,currentValue:i,isChecked:t.checked});return i!==n&&(a.setAttribute(e.fieldName,n),!0)});0!==a.length&&(this.viewModel.userHasChangedValues=!0,await e.expressionsManager.valueChanged(e.fieldName,a),this.viewModel.emit("value-change",{features:a.map(e=>e.source),fieldName:e.fieldName,name:"value-change",value:this._getFieldValueByFieldNameForInput(e,e.fieldName)}))}_getFieldValueByFieldNameForInput(e,t){const a=e.features.toArray().map(e=>e.getAttribute(t));if(0===a.length)return null;const[i]=a;return a.every(e=>e===i)?i:O}_renderSwitchField({input:e,props:t}){if((this._batchSwitchInputInitialValues.get(e)===O||e.value===O)&&"batch"===this.viewModel.mode){const a={dropdown:{afterCreate:this._afterComponentCreateOrUpdate,afterUpdate:this._afterComponentCreateOrUpdate,disabled:t.readOnly,open:!1,[ie]:t[ie]},trigger:{appearance:"transparent",iconEnd:"chevron-down",kind:"neutral",slot:"trigger",label:t.label},group:{mode:"single"}};return this._renderDropdownComponent({buttonValue:e.value,dropdownProps:a,options:[{name:this.messages.differentValuesPlaceholder,value:O,disabled:!0},...e.codedValueDomainOptions]})}return this._renderSwitchComponent({input:e,props:t})}_renderSwitchComponent({input:e,props:t}){return ee("calcite-switch",{...t,checked:!!_(e.template,"switch")&&e.value===e.template.input.onValue,class:I.inputSwitch,disabled:t.readOnly,onblur:()=>{this._focusedFieldInput=null},onCalciteSwitchChange:({currentTarget:e})=>this._saveInput(e)})}_renderDropdownComponent({buttonValue:e,options:t,dropdownProps:a}){const{trigger:i,dropdown:n,group:l}=a;return ee("calcite-dropdown",{...n,onblur:()=>{this._focusedFieldInput=null},onfocus:this._onComponentFocus,topLayerDisabled:this.topLayerDisabled,onCalciteDropdownSelect:({currentTarget:e})=>this._saveInput(e)},ee("calcite-button",{...i},e===O?this.messages.differentValuesPlaceholder:e),ee("calcite-dropdown-group",{selectionMode:l.mode},t.map(t=>ee("calcite-dropdown-item",{disabled:t.disabled,label:String(t.name),selected:e===t.value},t.name))))}_renderComboBoxComponent({input:e,options:t,props:a}){const i="INSERT"===this.viewModel.editType,n=this._touchedInputs.has(e?.template?.elementId),l=i&&e.showNoValueOptionEnabled&&!n?()=>{}:a.onblur,s={...a,onblur:l};return ee("calcite-combobox",{...s,selectionMode:"single",topLayerDisabled:this.topLayerDisabled,value:a.placeholder===this.messages.differentValuesPlaceholder?O:String(a.value),onCalciteComboboxChange:({currentTarget:e})=>{e.value!==O&&this._saveInput(e)}},this.renderComboboxOptionsList({input:e,options:t,props:a}))}renderComboboxOptionsList({input:e,options:t,props:a}){const[i,n]=t.map(e=>e.map(({name:e,value:t})=>ee("calcite-combobox-item",{heading:e,key:`#${t}`,selected:a.value===t,value:`${t}`}))),l=[...i];n.length>0&&l.push(ee("calcite-combobox-item-group",{key:"unsupported",label:this.messages.unsupportedDomainGroupTitle},n));const s=a.placeholder===this.messages.differentValuesPlaceholder,o=!s&&ae(a.value);return e.showNoValueOptionEnabled&&l.unshift(ee("calcite-combobox-item",{heading:e.showNoValueLabel||this.messages.empty,key:"empty-option",selected:o,value:""})),s&&l.unshift(ee("calcite-combobox-item",{heading:this.messages.differentValuesPlaceholder,key:O,selected:!0,value:O})),l}_renderRadioButtonGroupComponent({input:e,options:t,props:a}){const i=t.map(({name:t,value:i})=>this._renderRadioButtons({label:t,value:i,selected:i===e.value,props:a}));if(e.showNoValueOptionEnabled){const t="",n=e.showNoValueLabel||this.messages.empty,l=ae(e.value);i.unshift(this._renderRadioButtons({label:n,value:t,selected:l,props:a}))}return ee("calcite-radio-button-group",{afterCreate:this._afterRadioGroupCreateOrUpdate,afterUpdate:this._afterRadioGroupCreateOrUpdate,class:I.inputRadioGroup,disabled:a.readOnly,key:`${a.key}-radio-group`,layout:"vertical",name:a.name,required:a.required},i,a.placeholder===this.messages.differentValuesPlaceholder?ee("calcite-label",{class:I.placeholderRadio,key:a.label,layout:"inline"},ee("calcite-radio-button",{checked:!0,class:I.inputRadio,disabled:!0,name:a.placeholder,value:a.placeholder}),a.placeholder):null)}_renderRadioButtons({value:e,selected:t,label:a,props:i}){return ee("calcite-label",{class:I.inputRadioLabel,key:i.label,layout:"inline"},ee("calcite-radio-button",{...i,afterCreate:void 0,afterUpdate:void 0,checked:t,class:I.inputRadio,disabled:i.readOnly,name:i.label,onblur:()=>{this._focusedFieldInput=null},value:e,onCalciteRadioButtonChange:({currentTarget:e})=>{e.checked&&this._saveInput(e)}}),a)}_renderStringComponent(e,t){const{template:a}=e;return!a.field.editable||this.readOnly?this._renderReadOnlyComponent(e):"text-area"===a.input?.type?ee("calcite-text-area",{...t,class:this.classes(I.individualElement),resize:"vertical",value:t.value?String(t.value):"",onCalciteTextAreaInput:({currentTarget:e})=>this._saveInput(e)}):ee("calcite-input",{...t,class:this.classes(I.individualElement),type:"text",value:t.value?String(t.value):"",onCalciteInputInput:({currentTarget:e})=>this._saveInput(e)})}_renderNumberComponent(e,t){const a=m(e.field);return ee("calcite-input-number",{...t,integer:a,type:"number",value:a&&""!==t.value?Math.round(parseFloat(String(t.value))).toString():String(t.value),onCalciteInputNumberInput:({currentTarget:e})=>this._saveInput(e)})}_renderReadOnlyComponent(e,t){const a=this.getCommonInputProps(e);return ee("calcite-input",{...a,class:this.classes(I.fieldInput,I.inputDisabled,I.individualElement),readOnly:!0,type:"text",value:String(t??a.value??"")})}_renderDateComponents(e,t){const{field:a}=e;let i;switch(a.type){case"date":i=this._renderDateFieldComponents(e,t);break;case"date-only":i=this._renderDateOnlyFieldComponent(e,t);break;case"time-only":i=this._renderTimeOnlyFieldComponent(e,t);break;case"timestamp-offset":i=this._renderTimestampOffsetFieldComponents(e,t);break;default:i=this._renderReadOnlyComponent(e,z(a,t.value,{timeZone:e.effectiveTimeZone,...Z(e.template.field)}))}return e.value===O?[i,ee("calcite-input-message",{icon:"information",key:"diff-values-message",status:"idle"},this.messages.differentValues)]:i}_renderDateOnlyFieldComponent(e,t){const{class:a,key:i,readOnly:n}=t,{rawMax:l,rawMin:s}=e.range;return ee("calcite-input-date-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,class:a,"data-date-part":"date","data-element-id":t[ie],key:`${i}-date-input`,max:u(l)?l:void 0,min:u(s)?s:void 0,onblur:()=>{this._focusedFieldInput=null},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:n,topLayerDisabled:this.topLayerDisabled,value:e.value===O?"":e.value?String(e.value):"",onCalciteInputDatePickerChange:t=>this._saveValueFromDateComponent(e,t.currentTarget)})}_renderTimeOnlyFieldComponent(e,t){const{class:a,key:i,readOnly:n}=t;return ee("calcite-input-time-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,class:a,"data-date-part":"time","data-element-id":t[ie],key:`${i}-time-input`,onblur:()=>{this._focusedFieldInput=null},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:n,value:e.value===O?"":e.value?String(e.value):"",onCalciteInputTimePickerChange:t=>this._saveValueFromDateComponent(e,t.currentTarget)})}_renderTimestampOffsetFieldComponents(e,t){const{class:a,key:i,readOnly:n}=t,{rawMax:l,rawMin:s}=e.range,o=H(l),r=H(s),c=H(e.value===O?"":e.value),d=e.includeTimeOffset,m={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,overlayPositioning:"fixed",readOnly:n,[ie]:t[ie],onfocus:this._onComponentFocus};return ee("div",{class:I.dateInputContainer,key:`${i}-date-time-container`},ee("calcite-input-date-picker",{...m,class:a,"data-date-part":"date",key:`${i}-date-input`,max:o?.date??void 0,min:r?.date??void 0,onblur:()=>{this._focusedFieldInput=null},topLayerDisabled:this.topLayerDisabled,value:c.date??"",onCalciteInputDatePickerChange:t=>this._saveValueFromDateComponent(e,t.target)}),ee("calcite-input-time-picker",{...m,class:a,"data-date-part":"time",key:`${i}-time-input`,onblur:()=>{this._focusedFieldInput=null},value:c.time??"",onCalciteInputTimePickerChange:t=>this._saveValueFromDateComponent(e,t.target)}),d?ee("calcite-input-time-zone",{...m,class:a,clearable:e.value===O||null==e.value,"data-date-part":"timeZone",key:`${i}-timezone-input`,onblur:()=>{this._focusedFieldInput=null},value:c.timeZoneOffset||"",onCalciteInputTimeZoneChange:t=>this._saveValueFromDateComponent(e,t.target)}):null)}_renderDateFieldComponents(e,t){const{class:a,key:i,readOnly:n,min:l,max:s}=t,o=e.effectiveTimeZone,r=q(e.value===O?"":e.value,o),c=q(s,o),d=q(l,o),m=e.includeTime,u={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,overlayPositioning:"fixed",readOnly:n,[ie]:t[ie],onfocus:this._onComponentFocus};return ee("div",{class:I.dateInputContainer,key:`${i}-date-time-container`},ee("calcite-input-date-picker",{...u,class:a,"data-date-part":"date",key:`${i}-date-input`,max:c?.date??void 0,min:d?.date??void 0,onblur:()=>{this._focusedFieldInput=null},topLayerDisabled:this.topLayerDisabled,value:r.date??"",onCalciteInputDatePickerChange:t=>this._saveValueFromDateComponent(e,t.target)}),m?ee("calcite-input-time-picker",{...u,"data-date-part":"time",key:`${i}-time-input`,onblur:()=>{this._focusedFieldInput=null},step:1,value:r.time??"",onCalciteInputTimePickerChange:t=>{this._saveValueFromDateComponent(e,t.target)}}):null)}_renderRelationshipElementInput(e){const{elementId:t}=e.template;return ee("div",{class:I.relationshipElementInput,"data-testid":`relationship-element-${t}`,key:`relationship-element-${t}`})}_renderAttachmentElementInput(e){const{allAttachmentsVisibleOnDefaultPage:t,attachments:a,defaultPageAttachments:i,template:{description:n,elementId:l,label:s}}=e,o=t?a:i;return ee("div",{class:I.attachmentElementInput,"data-testid":`attachment-element-${l}`,key:`attachment-element-${l}`},s?ee("div",{class:I.attachmentElementLabel,key:`attachment-element-label-${l}`},s):null,n?ee("div",{class:I.description,key:`attachment-element-description-${l}`},n):null,a.length?this._renderAttachmentList(e,o,{label:s||this.messagesCommon.details,viewAllCount:t?null:a.length}):ee("div",{class:I.attachmentElementEmptyState,key:`attachment-element-empty-state-${l}`},this.messages.attachments.noAttachments),this._renderAttachmentAddAction(e))}_renderAttachmentListPage(){const e=this.viewModel.selectedAttachmentListInput;if(e)return ee("div",{class:I.attachmentElementAllPanel,key:`attachment-element-all-panel-${e.template.elementId}`},this._renderAttachmentList(e,e.attachments,{filterEnabled:!0,label:this.messages.titles.attachments}))}_renderAttachmentList(e,t,a){const{filterEnabled:i,label:n,viewAllCount:l}=a;return ee("calcite-list",{class:I.attachmentElementList,filterEnabled:i,filterPlaceholder:i?this.messages.attachments.searchAttachments:void 0,filterProps:i?Q:void 0,filterText:i?this._attachmentListFilterText:void 0,label:n,selectionAppearance:"border",selectionMode:"none",onCalciteListFilter:i?e=>{this._attachmentListFilterText=e.currentTarget.filterText??""}:void 0},this._renderAttachmentListItems(e,t),null!=l?this._renderViewAllAttachmentsItem(e,l):null)}_renderAttachmentListItems(e,t){const{elementId:a}=e.template;return t.map((t,i)=>{const n=this._formatAttachmentSize(t.size),l=this._getAttachmentLabel(t,i,n,e.displayFilename),s=l===n?void 0:n,o=f(t),r=e.isStagedAttachmentAddition(t);return ee("calcite-list-item",{class:I.attachmentElementListItem,description:s,key:`attachment-item-${o}`,label:l,onCalciteListItemSelect:r?void 0:()=>this._setSelectedAttachment({attachmentKey:o,elementId:a})},ee("div",{class:I.attachmentElementListItemStart,slot:"content-start"},this._renderAttachmentPreviewThumbnail(t,l,e)),r?[ee("span",{class:I.attachmentElementListItemStagedIndicator,slot:"content-end"}),ee("calcite-action",{disabled:this.effectiveDisabled,icon:"x",onclick:()=>this.viewModel.stageDeleteAttachment(a,t.globalId),scale:"s",slot:"actions-end",text:this.messagesCommon.delete,title:this.messagesCommon.delete})]:ee("calcite-action",{icon:"chevron-right",scale:"s",slot:"actions-end",text:l,title:l}))})}_renderViewAllAttachmentsItem(e,a){const{elementId:i}=e.template,{viewAll:n}=this.messages.attachments;return ee("calcite-list-item",{class:I.attachmentElementListItem,description:t(this.messages.attachments.count,{count:a}),key:`attachment-item-view-all-${i}`,label:n,onCalciteListItemSelect:()=>this._setAttachmentListElementId(i)},ee("calcite-action",{icon:"chevron-right",scale:"s",slot:"actions-end",text:n,title:n}))}_renderAttachmentAddAction(e){const{elementId:t}=e.template,a=this.effectiveDisabled||e.addDisabled;return ee("div",{class:I.attachmentElementEmptyAction,key:`attachment-element-empty-action-${t}`},ee("calcite-button",{appearance:"outline",disabled:a,iconStart:"attachment",kind:"neutral",onclick:()=>this._setAttachmentAddElementId(t),round:!0,scale:"s"},this.messages.attachments.attach))}_renderAttachmentAddPage(){const e=this.viewModel.selectedAttachmentAddInput;return e?this._renderAttachmentAddPanel(e):null}_renderAttachmentAddPanel(e){const{maxAttachmentCount:t}=e,{elementId:a}=e.template,i=null==t||t-e.attachments.length>1,n=this.effectiveDisabled||e.addDisabled,l=this.messages.attachments,s=l.dragAndDropFile,o="upload",r=e=>{this._attachmentFileInputMap.set(a,e)};return ee("div",{class:I.attachmentElementAddPanel,key:`attachment-element-add-panel-${a}`},ee("input",{accept:e.accept,afterCreate:r,afterRemoved:()=>{this._attachmentFileInputMap.delete(a)},afterUpdate:r,class:I.attachmentElementFileInput,"data-element-id":a,disabled:n,multiple:i,onchange:e=>{const t=e.currentTarget,i=t.files?Array.from(t.files):[];this._stageAttachmentFiles(a,i),t.value=""},type:"file"}),ee("div",{class:I.attachmentElementAddDropzone,"data-disabled":n?"true":"false",ondragover:e=>{e.preventDefault()},ondrop:e=>{if(e.preventDefault(),n)return;const t=e.dataTransfer?.files?Array.from(e.dataTransfer.files):[];this._stageAttachmentFiles(a,t)}},ee("calcite-icon",{class:I.attachmentElementAddDropzoneIcon,icon:o,scale:"l"}),ee("div",{class:I.attachmentElementAddDropzoneHeading},l.addFile),ee("div",{class:I.attachmentElementAddDropzoneDetail,title:s},s),ee("calcite-button",{appearance:"outline-fill",disabled:n,iconStart:"folder-open",onclick:e=>{e.stopPropagation(),this._openAttachmentFilePicker(a,n)},scale:"s",type:"button"},l.selectFile)))}async _stageAttachmentFiles(e,t){if(0!==t.length)try{await this.viewModel.stageAddAttachments(e,t)}finally{this.viewModel.setSelectedAttachmentAddElementId(null)}}_openAttachmentFilePicker(e,t){t||this._attachmentFileInputMap.get(e)?.click()}_renderAttachmentDetailPage(){const e=this.selectedAttachmentDetails;if(!e)return;const{attachment:t,input:a}=e,i=f(t),n=!!a.getAttachmentPreviewUrl(t);return ee("div",{class:I.attachmentElementDetail,key:`attachment-detail-panel-${a.template.elementId}-${i}`},ee("div",{class:I.attachmentElementDetailPreview},this._renderAttachmentPreviewImageForInput(t,a)),ee("div",{class:I.attachmentElementDetailActions},ee("calcite-button",{appearance:"outline",disabled:!n,iconStart:"download-to",kind:"neutral",onclick:()=>{this._downloadAttachment(t)},scale:"s"},this.messages.attachments.download),g(t)?ee("calcite-button",{appearance:"outline",disabled:!n,iconStart:"expand",kind:"neutral",onclick:this._maximizeSelectedAttachment,scale:"s"},this.messages.attachments.maximize):null,ee("calcite-button",{appearance:"outline",disabled:!0,iconStart:"refresh",kind:"neutral",scale:"s"},this.messages.attachments.replace)),ee("div",{class:I.attachmentElementDetailMetadata},ee("span",{class:I.attachmentElementDetailMetadataLabel},this.messages.attachments.fileName),ee("span",{class:I.attachmentElementDetailMetadataValue},t.name),ee("span",{class:I.attachmentElementDetailMetadataLabel},this.messages.attachments.size),ee("span",{class:I.attachmentElementDetailMetadataValue},this._formatAttachmentSize(t.size)),ee("span",{class:I.attachmentElementDetailMetadataLabel},this.messages.attachments.type),ee("span",{class:I.attachmentElementDetailMetadataValue},this._getLabelForAttachmentType(t))))}_renderAttachmentDialog(){const e=this._attachmentDialogInfo;if(!e)return null;const{attachment:t,input:a}=e;return ee("calcite-dialog",{heading:t.name||this.messagesCommon.details,key:"attachment-preview-dialog",modal:!0,open:!0,placement:"cover",width:"l",onCalciteDialogClose:this._closeAttachmentDialog},ee("div",{class:I.attachmentElementDetailPreview},this._renderAttachmentPreviewImageForInput(t,a)))}_setSelectedAttachment(e){this.viewModel.setSelectedAttachment(e),e||this.hideAttachmentDialog()}_setAttachmentAddElementId(e){this.viewModel.setSelectedAttachmentAddElementId(e),this.hideAttachmentDialog()}_setAttachmentListElementId(e){this.viewModel.setSelectedAttachmentListElementId(e),this.hideAttachmentDialog()}_getAttachmentLabel(e,a,i,n){return!1!==n&&u(e.name)&&e.name.length>0?e.name:i!==this.messagesCommon.notApplicable?i:t(this.messages.attachments.attachmentNumberedLabel,{index:a+1})}_formatAttachmentSize(e){return null==e||Number.isNaN(e)?this.messagesCommon.notApplicable:r(this.messagesUnits,e)}_getLabelForAttachmentType({contentType:e}){if(!e)return this.messagesCommon.notApplicable;const t=this.messages.attachments.attachmentTypes,a=h(e);return t?.[a]||e}_renderAttachmentPreviewThumbnail(e,t,a){const i=a.getAttachmentPreviewUrl(e,64);return i&&g(e)?ee("img",{alt:t,class:I.attachmentElementListItemThumb,src:i}):ee("calcite-icon",{class:I.attachmentElementListItemIcon,icon:v(e.contentType),scale:"s"})}_renderAttachmentPreviewImageForInput(e,t){const a=t.getAttachmentPreviewUrl(e),i=e.name||this.messagesCommon.details;return a&&g(e)?ee("img",{alt:i,class:I.attachmentElementDetailPreviewImage,src:a,title:i}):[ee("calcite-icon",{class:I.attachmentElementDetailPreviewIcon,icon:v(e.contentType),scale:"l",textLabel:i,title:i}),this.messages.attachments.noPreviewAvailable]}async _downloadAttachment(e){await R(e)}hideAttachmentDialog(){this._attachmentDialogInfo=null}_renderTextComponent(e){const{elementId:t}=e.template;return ee("div",{class:I.textElementInput,"data-testid":`text-element-${t}`,innerHTML:e.text,key:`text-element-${t}`})}_renderUtilityNetworkAssociationsElementInput(e){const{elementId:t}=e.template;return ee("div",{class:I.utilityNetworkAssociationsElementInput,"data-testid":t,key:t})}getCommonInputProps(e){const{template:t,valid:a,value:i,minLength:n,maxLength:l,required:s,fieldName:o,editable:r,userHasChangedValue:c,range:{max:d,min:m}}=e,u=!r||this.readOnly,p=!u&&this.effectiveDisabled;let h=t.hint??void 0,v=!1;return i===O&&(h=this.messages.differentValuesPlaceholder,v=!0),{afterCreate:this._afterComponentCreateOrUpdate,afterUpdate:this._afterComponentCreateOrUpdate,"aria-invalid":a?"false":"true",class:this.classes(I.fieldInput,u?I.inputDisabled:null),status:!c&&!this.viewModel.submitHasBeenAttempted||a?"idle":"invalid",maxLength:l&&l>-1?l:void 0,minLength:n&&n>-1?n:void 0,key:t.elementId,label:o,name:o,max:null!=d?d:void 0,min:null!=m?m:void 0,disabled:p,readOnly:u,onblur:this._onComponentBlur,required:s,placeholder:h,value:v?"":i??"",[ie]:t.elementId,onfocus:this._onComponentFocus}}_onFormSubmit(e){e.preventDefault()}_getFieldInputFromHTMLElement(e){return this.viewModel.findFieldInput(e.getAttribute(ie))}_afterRadioGroupCreateOrUpdate(e){const t=e.selectedItem,a=e.querySelector("calcite-radio-button"),i=t||a;i&&this._afterComponentCreateOrUpdate(i)}_onComponentFocus(e){const t=e.target,a=this._getFieldInputFromHTMLElement(t);this._touchedInputs.add(a.template.elementId),this._focusedFieldInput=a}_afterComponentCreateOrUpdate(e){const t=this._getFieldInputFromHTMLElement(e),a=this._focusedFieldInput;this._attemptFocusOnNextRender&&a===t&&(this._attemptFocusOnNextRender=!1,te(e))}_onComponentBlur(){this._focusedFieldInput=null}_resetTransientFormState(){this._attemptFocusOnNextRender=!1,this._focusedFieldInput=null,this._attachmentDialogInfo=null,this._attachmentListFilterText="",this._attachmentFileInputMap.clear()}_parseValue(e,t,a=!1){const i=t.multipleChoiceInput,n=t.multipleChoiceValues;if(i&&n){const l=i.choiceDelimiter,s=e;if(a){return N({input:t}).checked?null:n.length>0?n.join(l):null}const o=$(t.value,l).filter(e=>e!==O),r=new Set(o);s.checked?r.add(s.value):r.delete(s.value);const c=n.filter(e=>r.has(e));return c.length?c.join(l):null}if(_(t.template,"switch")){if("calcite-dropdown"===e.localName&&t.domain)for(const a of t.domain.codedValues)if(a.name===e.selectedItems[0].textContent)return a.code;return e.checked?t.template.input.onValue:t.template.input.offValue}const l=e.value;return null==l||""===l?null:"number"===t.dataType?"-0"===l||"-0."===l||"-0,"===l?l:parseFloat(l):"date"===t.field.type?parseFloat(l):l}_saveInput(e){const t=this._getFieldInputFromHTMLElement(e),{elementId:a}=t.template;if(!t)return;const i=t?.value;if(_(t.template,"switch")&&"single"!==this.viewModel.mode){const e=n(this._batchSwitchInputInitialValues,t,()=>t.value);this._batchSwitchInputInitialValues.set(t,null===e?i:e)}const l=this._parseValue(e,t);l!==i&&this.viewModel.setValue(a,l)}_afterDateComponentCreate(e){this._setDateTimeTimeZoneMap(e),this._afterComponentCreateOrUpdate(e)}_saveValueFromDateComponent(e,t){const{elementId:a}=e.template,i=e.field.type,n=this._dateComponentMap.get(`${a}`);if(!n)return;const l=e.effectiveTimeZone;let s=e.value===O?void 0:e.value,o=null;"date-only"===i?o=Array.isArray(t.value)?t.value[0]:t.value:"time-only"===i?(s=G(s),o=G(t.value)):o="timestamp-offset"===i?null!=t.value?W({dateComponent:n.date,timeComponent:n.time,oldValue:s,timeZoneComponent:n.timeZone,defaultTimeZone:l}):null:null!=t.value?K({oldValue:s,dateComponent:n.date,timeZone:l,timeComponent:n.time?.value===O?void 0:n.time}):null,s!==o&&(null!==o&&t.value?this.viewModel.setValue(`${a}`,o):this.viewModel.setValue(`${a}`,null))}};e([c()],se.prototype,"activeFeatureIndex",null),e([c()],se.prototype,"disabled",null),e([c()],se.prototype,"effectiveTitle",null),e([c()],se.prototype,"effectiveDisabled",null),e([c()],se.prototype,"features",null),e([c()],se.prototype,"footerButtonInfos",null),e([c()],se.prototype,"footerNoticeInfos",null),e([c()],se.prototype,"map",null),e([c()],se.prototype,"maximumFeatureCount",null),e([c()],se.prototype,"maximumFeatureCountWithComplexForms",null),e([c()],se.prototype,"spatialReference",null),e([c()],se.prototype,"layerInfos",null),e([c()],se.prototype,"timeZone",null),e([c()],se.prototype,"headingLevel",void 0),e([c()],se.prototype,"icon",null),e([c(),X("esri/t9n/common")],se.prototype,"messagesCommon",void 0),e([c(),X("esri/widgets/BatchAttributeForm/t9n/BatchAttributeForm")],se.prototype,"messages",void 0),e([c(),X("esri/core/t9n/Units")],se.prototype,"messagesUnits",void 0),e([c()],se.prototype,"page",null),e([c()],se.prototype,"readOnly",null),e([c()],se.prototype,"selectedAttachment",null),e([c()],se.prototype,"selectedAttachmentDetails",null),e([c()],se.prototype,"valid",null),e([c({type:y}),Y(["value-change","submit"])],se.prototype,"viewModel",void 0),e([c({type:k,nonNullable:!0})],se.prototype,"visibleElements",void 0),e([c()],se.prototype,"groupDisplay",void 0),e([c()],se.prototype,"_attemptFocusOnNextRender",void 0),e([c()],se.prototype,"_formId",null),e([c()],se.prototype,"_focusedFieldInput",void 0),e([c()],se.prototype,"_attachmentDialogInfo",void 0),e([c()],se.prototype,"_attachmentListFilterText",void 0),se=e([d("esri.widgets.BatchAttributeForm")],se);const oe=se;export{oe as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import{__decorate as t}from"tslib";import{isSome as e}from"../../core/arrayUtils.js";import i from"../../core/Collection.js";import s from"../../core/Error.js";import{EventedAccessor as o}from"../../core/Evented.js";import{JSONMap as a}from"../../core/jsonMap.js";import{clone as r}from"../../core/lang.js";import{LoadableMixin as l}from"../../core/Loadable.js";import{EsriPromiseMixin as n}from"../../core/Promise.js";import p from"../../core/ReactiveMap.js";import{watch as m,initial as h,whenOnce as d}from"../../core/reactiveUtils.js";import{createScreenPoint as u}from"../../core/screenUtils.js";import{unitType as c,convertUnit as f,getMetersPerUnitForSR as y,inchesPerMeter as v}from"../../core/units.js";import{property as T,subclass as w}from"../../core/accessorSupport/decorators.js";import _ from"../../geometry/Extent.js";import I from"../../geometry/SpatialReference.js";import{formatDate as g,convertDateFormatToIntlOptions as x}from"../../intl/date.js";import{getLocaleLanguage as b}from"../../intl/locale.js";import O from"../../portal/Portal.js";import E from"../../portal/PortalQueryParams.js";import{execute as L,getTaskInfo as P}from"../../rest/print.js";import{formatJsonMap as S}from"../../rest/support/fileFormat.js";import{fromJSON as k}from"../../rest/support/layoutTemplate.js";import U from"../../rest/support/LegendLayer.js";import C from"../../rest/support/PrintParameters.js";import{getVisibleLayerViews as j}from"../../rest/support/printTaskUtils.js";import F from"../../rest/support/PrintTemplate.js";import{getExtent as M}from"../../views/2d/viewpointUtils.js";import{ViewEventPriorities as H}from"../../views/input/InputManager.js";import A from"../../views/overlay/BoxOverlayItem.js";import D from"./CustomTemplate.js";import W from"./FileLink.js";import N from"./TemplateOptions.js";import{fetchLayoutTemplateInfos as R,valueUnitKebabDict as V}from"./utils.js";const z=[30,144,255,255],B=[237,211,23,255],q=[216,48,32,255],G=/(\/GPServer\/).+/i,$=96,J=i.ofType(D),Q=i.ofType(W),K=new a({Feet:"feet",Miles:"miles",Meters:"meters",Kilometers:"kilometers"});function X(t){t.layoutOptions??={},t.layoutOptions.customTextElements??=[];const e="date";if(!t.layoutOptions.customTextElements.find(t=>e in t)){const{customTextElements:e}=t.layoutOptions;let i=g(Date.now(),x("short-date"));"ar"===b()&&(i=""+i),e.push({date:i})}}function Y(t,e,i){const s=t.visible??!0,o=t.legendEnabled??!0;if(!s||!o)return;const a=0===e,r=t.minScale??0,l=t.maxScale??0;if(!(a||(0===r||e<=r)&&(0===l||e>=l)))return;const n=t.sublayers?.toArray();if(n)for(const p of n)Y(p,e,i);else t.id&&i.push(String(t.id))}function Z(t,e,i,s){if(!e.layoutOptions)return;if(!i)return void(e.layoutOptions.legendLayers=[]);if(!t)return;let o=0;e.scalePreserved&&(o=e.outScale||t.scale);const a=j(t),r=[];for(const l of a)if(l.legendEnabled){const t="sublayers"in l.layer&&l.layer.sublayers?l.layer.sublayers.toArray():void 0,e=[];for(const i of t??[])Y(i,o,e);r.push(new U({layerId:l.layer.id,title:l.layer.title||void 0,subLayerIds:t?e:void 0,dynamicLegend:s}))}e.layoutOptions.legendLayers=r}function tt(t,e,i){if(!e)return;!(e.visible===i)&&t.layoutOptions&&(t.layoutOptions.elementOverrides?t.layoutOptions.elementOverrides[e.name]={visible:i}:t.layoutOptions.elementOverrides={[e.name]:{visible:i}})}let et=class extends(l(n(o))){constructor(t){super(t),this._serviceTemplateCustomTextElements=null,this._templateIdToCustomTemplate=new p,this._isFreeHand=!1,this._freeHandWidth=0,this._freehandHeight=0,this._asyncPrintTaskUrl=null,this._layoutInfoTaskUrl=null,this._portalLayoutInfoTaskUrl=null,this._customLayoutOptions=null,this._exportedFileNameMap={},this._layoutTemplateInfosCache=new Map,this._tasksInfoCache=new Map,this.allowedFormats="all",this.allowedLayouts="all",this.browseTemplates=new J,this.defaultTemplates=new J,this.error=null,this.exportedLinks=new Q,this.extraParameters=null,this.includeDefaultTemplates=!0,this.outSpatialReference=null,this.portal=O.getDefault(),this.portalTemplateIds=[],this.printServiceTemplates=new J,this.defaultTemplate=null,this.showPrintAreaEnabled=!1,this.printServiceUrl=null,this.printTimeout=12e4,this.saveExportEnabled=!1,this.templatesInfo=null,this.updateDelay=1e3,this.view=null,this.templateCustomTextElements=null,this.templateOptions=new N}initialize(){this.addHandles([m(()=>[this.showPrintAreaEnabled,this.view],()=>{this.showPrintAreaEnabled?this._enablePrintPreview():(this.removeHandles("overlay-handler"),this.view?.overlay?.removeItem(this._getOverlayItem()))}),m(()=>[this.templateOptions.layout,this.templateOptions.layoutItem],()=>{this.loaded&&this._processTemplateOptions()}),m(()=>[this.allowedFormats,this.allowedLayouts],()=>{this.loaded&&this._loadTemplateInfos()}),m(()=>this.exportedLinks,()=>{for(const{name:t,extension:e}of this.exportedLinks)t&&e&&this._updateExportedFileNameMap(`${t}${e}`)},h)])}destroy(){this.removeHandles("overlay-handler"),this.view&&(this._overlayItem&&(this.view.overlay?.removeItem(this._overlayItem),this._overlayItem.destroy(),this._overlayItem=null),this.view=null)}get effectivePrintServiceUrl(){return this.printServiceUrl??null}get effectiveTemplateCustomTextElements(){if(!this._serviceTemplateCustomTextElements)return{};const t=r(this._serviceTemplateCustomTextElements);return this.templateCustomTextElements&&Object.keys(this.templateCustomTextElements).forEach(e=>{const i=t[e];if(i){const t=this.templateCustomTextElements?.[e];i.forEach(e=>{const[i]=Object.entries(e)[0];t?.forEach(t=>{const[s,o]=Object.entries(t)[0];i===s&&(e[i]=o)})})}}),Object.freeze(t)}get state(){return"loading"===this.loadStatus?"initializing":"failed"===this.loadStatus||this.error?"error":"loaded"===this.loadStatus&&this.view?.ready?"ready":"disabled"}async print(t){const{view:e,extraParameters:i,updateDelay:o,outSpatialReference:a}=this;if(!e)throw new s("print:view-required","view is not set");X(t);const r=this._getOverlayItem(),l=t.scalePreserved||!this.showPrintAreaEnabled?void 0:M(new _,e.viewpoint,"map-only"===t.layout?[t.exportOptions.width,t.exportOptions.height]:[r.boxWidth,r.boxHeight]),n=new C({view:e,template:t,extent:l,extraParameters:i,updateDelay:o,outSpatialReference:a});try{const e=!!t.layoutItem?.id&&(this.defaultTemplates.some(e=>e.layoutItem?.id===t.layoutItem?.id)||this.browseTemplates.some(e=>e.layoutItem?.id===t.layoutItem?.id));return await L(e&&this._asyncPrintTaskUrl?this._asyncPrintTaskUrl:this.effectivePrintServiceUrl,n,{timeout:this.printTimeout})}catch(p){throw new s("print:export-error","An error occurred while exporting the web map.",{error:p})}}async load(t){return this.addResolvingPromise(this._loadResources(t).catch(t=>this.error=t)),this}toPrintTemplate({attributionEnabled:t,author:e,copyright:i,customTextElements:o,dpi:a,forceFeatureAttributes:r,format:l,height:n,id:p,includeTables:m,layout:h,layoutItem:d,legendEnabled:u,dynamicLegendEnabled:c,northArrowEnabled:f,scale:y,scaleBarEnabled:v,scaleBarUnit:T,scaleEnabled:w,title:_,width:I}){if(!h&&!d)throw new s("print:layout-required","layout is not set");const g=new F({attributionVisible:t,forceFeatureAttributes:r,format:l,includeTables:m,layout:h,layoutItem:d,layoutOptions:{authorText:e||"",copyrightText:i||"",customTextElements:o,titleText:_||"",scalebarUnit:v&&T?K.toJSON(T):void 0},outScale:y??0,scalePreserved:w});if(I&&(g.exportOptions.width=I),n&&(g.exportOptions.height=n),a&&(g.exportOptions.dpi=a),g.layoutOptions){Z(this.view,g,u,c);const t=this.getLayoutTemplateById(p)?.mapSurroundInfoOptions;if(t){const e=t.northArrow;for(const t of e)tt(g,t,f);const i=t.scaleBar;for(const t of i)tt(g,t,v);const s=t.legend;for(const t of s)tt(g,t,u)}}return g}getLayoutTemplateById(t){return t?this._templateIdToCustomTemplate.get(t):null}async addPortalTemplate(t){if(!this.portal||!t?.id)return;try{if("loading"===this.loadStatus&&await d(()=>this.loaded),!this.loaded)throw new s("print:load-required","PrintViewModel must be loaded before adding portal templates.");t.loaded||await t.load()}catch{return void this.applyTemplate(this.defaultTemplate)}const e=new D({type:"browse-template",layoutInfoTaskUrl:this._portalLayoutInfoTaskUrl,label:t.title,layoutItem:t});this._templateIdToCustomTemplate.set(e.id,e),this.browseTemplates.add(e)}removePortalTemplate(t){t.layoutItem&&this.templateOptions.id===t.layoutItem.id&&(this.defaultTemplate?this.applyTemplate(this.defaultTemplate):this.templateOptions.reset()),this.browseTemplates.remove(t),this._templateIdToCustomTemplate.delete(t.id)}async applyTemplate(t){if(t&&t===this.getLayoutTemplateById(this.templateOptions.id))return;if(this.templateOptions.reset(),!t)return;if("map-only"===t)return void(this.templateOptions.layout="map-only");!t.layout||!this.templatesInfo||this.templatesInfo.layout.choiceList.includes(t.layout)||(this.defaultTemplate?t=this.defaultTemplate:this.templateOptions.reset());const e=t.layout||t.layoutItem?.id,i=e?this.templateCustomTextElements?.[e]:void 0;if(await this.templateOptions.applyTemplate(t,{customTextElements:i,customLayoutOptions:this._customLayoutOptions}),e&&this._serviceTemplateCustomTextElements&&!this._serviceTemplateCustomTextElements[e]&&t.layoutTemplateInfo?.layoutOptions?.customTextElements){const i=r(this._serviceTemplateCustomTextElements);i[e]=t.layoutTemplateInfo.layoutOptions.customTextElements,this._serviceTemplateCustomTextElements=Object.freeze(i)}}createExportedFileLink(t){const e=this.toPrintTemplate(this.templateOptions).format.toLowerCase(),i=e.includes("png")?"png":e,s=t+i;return this._updateExportedFileNameMap(s),new W({name:t,extension:i,count:this._exportedFileNameMap[s]})}export(t){const e=this.createExportedFileLink(t);this.exportedLinks.add(e);const i=this.print(this.toPrintTemplate(this.templateOptions)).then(t=>e.set({url:t?.url,state:"ready"})).catch(t=>e.set({error:t,state:"error"}));return this.emit("submit",{link:e,saveExportEnabled:this.saveExportEnabled}),i.then(t=>this.emit("complete",{link:t,saveExportEnabled:this.saveExportEnabled})),{link:e,promise:i}}async _loadResources(t){this.destroyed||(await this._loadUrls(t),await this._loadTemplateInfos(t),await this._updateOverLayItem())}async _loadTemplateInfos(t){const e=[...this.defaultTemplates,...this.printServiceTemplates];for(const{id:o}of e)this._templateIdToCustomTemplate.delete(o);this.defaultTemplates.removeAll(),this.printServiceTemplates.removeAll();const[i,s]=await Promise.all([this._getLayoutToLayoutTemplateInfos(t),this._getPrintServiceTemplatesInfo(t)]);await this._loadAllTemplates(i,s,t),this._processPrintServiceTemplatesInfo(s),await this._processTemplateOptions()}_updateExportedFileNameMap(t){void 0!==this._exportedFileNameMap[t]?this._exportedFileNameMap[t]++:this._exportedFileNameMap[t]=0}async _processTemplateOptions(){const{layout:t,layoutItem:e}=this.templateOptions;if("map-only"!==t)if(this._customLayoutOptions={legend:this.templateOptions.legendEnabled,northArrow:this.templateOptions.northArrowEnabled,scaleBar:this.templateOptions.scaleBarEnabled},e?.id){try{e.loaded||await e.load()}catch{return void this.applyTemplate(this.defaultTemplate)}let t=this._templateIdToCustomTemplate.get(e.id);t||(t=new D({label:e.title,layoutItem:e,layoutInfoTaskUrl:this._portalLayoutInfoTaskUrl}),this._templateIdToCustomTemplate.set(t.id,t)),await this.applyTemplate(t)}else if(t){const t=this.defaultTemplates.find(t=>t.layout===this.templateOptions.layout)??this.printServiceTemplates.find(t=>t.layout===this.templateOptions.layout);await this.applyTemplate(t??this.defaultTemplate)}}async _loadPortal(t){try{await this.portal.load(t)}catch(e){throw new s("print:could-not-load-portal","Cannot load print resource information from portal",{error:e,url:this.effectivePrintServiceUrl})}}async _loadUrls(t){if(this.printServiceUrl)this._set("effectivePrintServiceUrl",this.printServiceUrl),this._layoutInfoTaskUrl=await this._getLayoutInfoTaskUrl(this.effectivePrintServiceUrl,t);else{await this._loadPortal(t);const{printTask:e,asyncPrintTask:i,layoutInfoTask:s}=this.portal?.helperServices??{};this._set("effectivePrintServiceUrl",e?.url),this._asyncPrintTaskUrl=i?.url,this._layoutInfoTaskUrl=await this._getLayoutInfoTaskUrl(this.effectivePrintServiceUrl,t),s?.url&&this.effectivePrintServiceUrl!==s.url?this._portalLayoutInfoTaskUrl=await this._getLayoutInfoTaskUrl(s.url,t):this._portalLayoutInfoTaskUrl=this._layoutInfoTaskUrl}const e=this.effectivePrintServiceUrl?.toLowerCase().split("/");if(!e?.includes("gpserver"))throw new s("print:invalid-print-service-url","Can't fetch print templates information from provided URL",{url:this.effectivePrintServiceUrl})}async _getLayoutInfoTaskUrl(t,e){if(!t)return null;const i=await P(t,"GetLayoutTemplatesInfo",e);return i?t.replace(G,`$1${encodeURI(i.displayName)}`):null}_getPortalDefaultTemplates(t,e){return this.portal?.helperServices?.printTask?.templates?.filter(t=>"map_only"!==t.layout.toLowerCase()&&(!e||e.includes(k(t.layout))))?.map(e=>{const i=D.fromJSON(e);if(i.type="default-template",i.layoutInfoTaskUrl=this._layoutInfoTaskUrl,i.layout){const e=t.get(i.layout);e&&i.setLayoutTemplateInfo(e)}return i})??[]}async _getPortalCustomTemplates(t){if(this.printServiceUrl||!this.portal)return[];const{layoutGroupQuery:e}=this.portal;if(!e)return[];const i=new E({query:e,disableExtraQuery:!0}),s=await this.portal.queryGroups(i,t);if(!s.total)return[];const o=s.results[0],a=new E({num:100,query:"type:Layout",sortField:o.sortField,sortOrder:o.sortOrder??void 0}),r=(await o.queryItems(a,t)).results;if(!r.length)return[];return r.map(t=>(this.portalTemplateIds.push(t.id),new D({type:"default-template",label:t.title,layoutItem:t,layoutInfoTaskUrl:this._portalLayoutInfoTaskUrl})))}async _loadAllTemplates(t,e,i){let s=!1;const o=e?.layout?.choiceList;if(this.includeDefaultTemplates&&this.portal&&!this.printServiceUrl){const e=this._getPortalDefaultTemplates(t,o);s=!!e.length,this.defaultTemplates.addMany(e);const a=await this._getPortalCustomTemplates(i);this.defaultTemplates.addMany(a);for(const t of this.defaultTemplates)this._templateIdToCustomTemplate.set(t.id,t)}s||t.forEach((t,e)=>{if(!o||o.includes(e)){const i=new D({type:"print-service-template",layout:e,layoutInfoTaskUrl:this._layoutInfoTaskUrl});i.setLayoutTemplateInfo(t),this.printServiceTemplates.add(i),this._templateIdToCustomTemplate.set(i.id,i)}})}_processPrintServiceTemplatesInfo(t){this._set("templatesInfo",t);const e=t?.layout?.defaultValue;if(e&&"map-only"!==e){const t=this.defaultTemplates.find(t=>t.layout===e)??this.printServiceTemplates.find(t=>t.layout===e)??this.defaultTemplates.at(0)??this.printServiceTemplates.at(0);this._set("defaultTemplate",t)}}async _getLayoutToLayoutTemplateInfos(t){const e=this._layoutInfoTaskUrl,i=e?this._layoutTemplateInfosCache.get(e):void 0,s=i??await R(e,void 0,t);i||this._layoutTemplateInfosCache.set(e,s);const o=new Map,a={};for(const r of s){const t=k(r.layoutTemplate);o.set(t,r),a[t]=r.layoutOptions.customTextElements}return this._serviceTemplateCustomTextElements=Object.freeze(a),o}async _getPrintServiceTemplatesInfo(t){const e=this.effectivePrintServiceUrl?this._tasksInfoCache.get(this.effectivePrintServiceUrl):void 0,i=e??await P(this.effectivePrintServiceUrl,"ExportWebMap",t);if(!i)throw new s("print:unavailable-service-info","Can't fetch templates info from service");e||this._tasksInfoCache.set(this.effectivePrintServiceUrl,i);const{parameters:o}=i,a=o.find(({name:t})=>"Format"===t),r=o.find(({name:t})=>"Layout_Template"===t);return{format:this._getFormat(a),layout:this._getLayout(r)}}_getFormat(t){const i="all"===this.allowedFormats?t.choiceList:t.choiceList.filter(t=>"string"!=typeof this.allowedFormats&&this.allowedFormats.some(e=>new RegExp(`\\b${e}\\b`,"i").test(t))),s=(i.length?i:t.choiceList).map(t=>S.fromJSON(t)).filter(e),o=S.fromJSON(t.defaultValue),a=s.some(t=>new RegExp(`\\b${o}\\b`,"i").test(t))?o:s[0];return{choiceList:s,defaultValue:a}}_getLayout(t){const i=t.choiceList.filter(t=>"map_only"!==t.toLowerCase()),s="all"===this.allowedLayouts?i:i.filter(t=>this.allowedLayouts.includes(k(t))),o=(s.length?s:i).map(k).filter(e),a=k(t.defaultValue),r=o.includes(a)?a:o.find(t=>/(?=.*letter)(?=.*landscape)/i.test(t))??o.find(t=>/(?=.*a4)(?=.*landscape)/i.test(t))??o[0];return{choiceList:o,defaultValue:r}}_getOverlayItem(){return this._overlayItem||(this._overlayItem=new A({strokeDash:[5],strokeWidth:2,strokeColor:[30,144,255,255]})),this._overlayItem}_enablePrintPreview(){if(!this.view?.overlay)return;const t=this.templateOptions,e=this._getOverlayItem();this.addHandles([m(()=>[t.width,t.height,t.scaleEnabled,t.scale,t.layout,t.layoutItem,t.id,t.state,t.dpi,this.view?.scale,this.view?.size,this.view?.state.paddedViewState.size,this.view?.state.padding,this.loaded],()=>{this._updateOverLayItem()},h),this.view?.on("drag",["Shift"],t=>this._handleDrag(t),H.WIDGET),this.view?.on("key-down",["Escape"],()=>this._resetDrag(),H.WIDGET)],"overlay-handler"),this.view.overlay.addItem(e)}async _updateOverLayItem(){if(!this.view)return;await this.view.when();const t=this.templateOptions,e=this._getOverlayItem(),i=t.layoutItem?.id??t.layout,s=this.view,o=s.spatialReference,[a,r]=s.state.paddedViewState.size,l=s.state.padding;let n=0,p=0;if("map-only"===i)null!=t.width&&null!=t.height&&(n=t.width,p=t.height);else if(i){const e=t.id?this._templateIdToCustomTemplate.get(t.id):null,{webMapFrameSize:i,pageUnits:s}=e?.layoutTemplateInfo??{};let l=!1;if(i&&s)if(this._isFreeHand){const t=i[0]/i[1];n=this._freeHandWidth,p=this._freehandHeight,n>p?p=n/t:n=p*t}else{const t=V.fromJSON(s.toLowerCase()),e=o.unit;c(t)===c(e)?(n=f(i[0],t,e),p=f(i[1],t,e)):(l=!0,n=i[0],p=i[1])}if(!this._isFreeHand)if(t.scaleEnabled&&t.scale){const t=l?Math.min(a/n,r/p):y(o)*v*$;n*=t,p*=t}else if(0===n||0===p)n=a,p=r;else{const t=(a-.1*a)/n,e=(r-.1*r)/p,i=Math.min(t,e);n*=i,p*=i}}const{scaleEnabled:m,scale:h}=t,d=m&&h?h/this.view.scale:1;if(e.boxWidth=n*d||a,e.boxHeight=p*d||r,l&&(e.padding=l),e.backgroundWidth=a??0,e.backgroundHeight=r??0,"loading"===this.loadStatus)e.strokeColor=B;else if("loaded"===this.loadStatus)switch(this.templateOptions.state){case"pending":e.strokeColor=B;break;case"ready":e.strokeColor=z;break;case"error":e.strokeColor=q}}_resetDrag(){this._isFreeHand=!1,this._updateOverLayItem()}_handleDrag(t){switch(t.action){case"start":this._start();break;case"update":this._update(t);break;case"end":this._end()}t.stopPropagation()}_start(){this._isFreeHand=!0}_update(t){const e=this._getOverlayItem(),{x:i,y:s}=t,{x:o,y:a}=t.origin;i>o?(e.x=o,e.boxWidth=i-o):(e.x=i,e.boxWidth=o-i),s>a?(e.y=a,e.boxHeight=s-a):(e.y=s,e.boxHeight=a-s)}_end(){const t=this._getOverlayItem();if(!this.view||null==t.x||null==t.y)return;const e=this.view,i=e.toMap(u(t.x+.5*t.boxWidth,t.y+.5*t.boxHeight));t.x=null,t.y=null,e.goTo({center:i}),this._freeHandWidth=t.boxWidth,this._freehandHeight=t.boxHeight,"map-only"===this.templateOptions.layout&&(this.templateOptions.width=this._freeHandWidth,this.templateOptions.height=this._freehandHeight),this.templateOptions.scale=this.view.scale,this._updateOverLayItem()}};t([T()],et.prototype,"_serviceTemplateCustomTextElements",void 0),t([T()],et.prototype,"_templateIdToCustomTemplate",void 0),t([T()],et.prototype,"allowedFormats",void 0),t([T()],et.prototype,"allowedLayouts",void 0),t([T({type:J})],et.prototype,"browseTemplates",void 0),t([T({type:J})],et.prototype,"defaultTemplates",void 0),t([T()],et.prototype,"error",void 0),t([T({type:Q})],et.prototype,"exportedLinks",void 0),t([T()],et.prototype,"extraParameters",void 0),t([T()],et.prototype,"includeDefaultTemplates",void 0),t([T({readOnly:!0})],et.prototype,"effectivePrintServiceUrl",null),t([T()],et.prototype,"effectiveTemplateCustomTextElements",null),t([T({type:I})],et.prototype,"outSpatialReference",void 0),t([T({type:O})],et.prototype,"portal",void 0),t([T()],et.prototype,"portalTemplateIds",void 0),t([T({type:J})],et.prototype,"printServiceTemplates",void 0),t([T({readOnly:!0})],et.prototype,"defaultTemplate",void 0),t([T()],et.prototype,"showPrintAreaEnabled",void 0),t([T()],et.prototype,"printServiceUrl",void 0),t([T()],et.prototype,"printTimeout",void 0),t([T()],et.prototype,"saveExportEnabled",void 0),t([T({readOnly:!0})],et.prototype,"state",null),t([T({readOnly:!0})],et.prototype,"templatesInfo",void 0),t([T()],et.prototype,"updateDelay",void 0),t([T()],et.prototype,"view",void 0),t([T()],et.prototype,"templateCustomTextElements",void 0),t([T({type:N})],et.prototype,"templateOptions",void 0),et=t([w("esri.widgets.Print.PrintViewModel")],et);const it=et;export{it as default};
|
|
2
|
+
import{__decorate as t}from"tslib";import{isSome as e}from"../../core/arrayUtils.js";import i from"../../core/Collection.js";import s from"../../core/Error.js";import{EventedAccessor as o}from"../../core/Evented.js";import{JSONMap as a}from"../../core/jsonMap.js";import{clone as r}from"../../core/lang.js";import{LoadableMixin as l}from"../../core/Loadable.js";import{EsriPromiseMixin as n}from"../../core/Promise.js";import p from"../../core/ReactiveMap.js";import{watch as m,initial as h,whenOnce as d}from"../../core/reactiveUtils.js";import{createScreenPoint as u}from"../../core/screenUtils.js";import{unitType as c,convertUnit as f,getMetersPerUnitForSR as y,inchesPerMeter as v}from"../../core/units.js";import{property as T,subclass as w}from"../../core/accessorSupport/decorators.js";import _ from"../../geometry/Extent.js";import I from"../../geometry/SpatialReference.js";import{formatDate as g,convertDateFormatToIntlOptions as x}from"../../intl/date.js";import{getLocaleLanguage as b}from"../../intl/locale.js";import O from"../../portal/Portal.js";import E from"../../portal/PortalQueryParams.js";import{execute as L,getTaskInfo as P}from"../../rest/print.js";import{formatJsonMap as S}from"../../rest/support/fileFormat.js";import{fromJSON as k}from"../../rest/support/layoutTemplate.js";import U from"../../rest/support/LegendLayer.js";import C from"../../rest/support/PrintParameters.js";import{getVisibleLayerViews as j}from"../../rest/support/printTaskUtils.js";import F from"../../rest/support/PrintTemplate.js";import{getExtent as M}from"../../views/2d/viewpointUtils.js";import{ViewEventPriorities as H}from"../../views/input/InputManager.js";import A from"../../views/overlay/BoxOverlayItem.js";import D from"./CustomTemplate.js";import W from"./FileLink.js";import N from"./TemplateOptions.js";import{fetchLayoutTemplateInfos as R,valueUnitKebabDict as V}from"./utils.js";const z=[30,144,255,255],B=[237,211,23,255],q=[216,48,32,255],G=/(\/GPServer\/).+/i,$=96,J=i.ofType(D),Q=i.ofType(W),K=new a({Feet:"feet",Miles:"miles",Meters:"meters",Kilometers:"kilometers"});function X(t){t.layoutOptions??={},t.layoutOptions.customTextElements??=[];const e="date";if(!t.layoutOptions.customTextElements.find(t=>e in t)){const{customTextElements:e}=t.layoutOptions;let i=g(Date.now(),x("short-date"));"ar"===b()&&(i=""+i),e.push({date:i})}}function Y(t,e,i){const s=t.visible??!0,o=t.legendEnabled??!0;if(!s||!o)return;const a=0===e,r=t.minScale??0,l=t.maxScale??0;if(!(a||(0===r||e<=r)&&(0===l||e>=l)))return;const n=t.sublayers?.toArray();if(n)for(const p of n)Y(p,e,i);else t.id&&i.push(String(t.id))}function Z(t,e,i,s){if(!e.layoutOptions)return;if(!i)return void(e.layoutOptions.legendLayers=[]);if(!t)return;let o=0;e.scalePreserved&&(o=e.outScale||t.scale);const a=j(t),r=[];for(const l of a)if(l.legendEnabled){const t="sublayers"in l.layer&&l.layer.sublayers?l.layer.sublayers.toArray():void 0,e=[];for(const i of t??[])Y(i,o,e);r.push(new U({layerId:l.layer.id,title:l.layer.title||void 0,subLayerIds:t?e:void 0,dynamicLegend:s}))}e.layoutOptions.legendLayers=r}function tt(t,e,i){if(!e)return;!(e.visible===i)&&t.layoutOptions&&(t.layoutOptions.elementOverrides?t.layoutOptions.elementOverrides[e.name]={visible:i}:t.layoutOptions.elementOverrides={[e.name]:{visible:i}})}let et=class extends(l(n(o))){constructor(t){super(t),this._serviceTemplateCustomTextElements=null,this._templateIdToCustomTemplate=new p,this._isFreeHand=!1,this._freeHandWidth=0,this._freehandHeight=0,this._asyncPrintTaskUrl=null,this._layoutInfoTaskUrl=null,this._portalLayoutInfoTaskUrl=null,this._customLayoutOptions=null,this._exportedFileNameMap={},this._layoutTemplateInfosCache=new Map,this._tasksInfoCache=new Map,this.allowedFormats="all",this.allowedLayouts="all",this.browseTemplates=new J,this.defaultTemplates=new J,this.error=null,this.exportedLinks=new Q,this.extraParameters=null,this.includeDefaultTemplates=!0,this.outSpatialReference=null,this.portal=O.getDefault(),this.portalTemplateIds=[],this.printServiceTemplates=new J,this.defaultTemplate=null,this.showPrintAreaEnabled=!1,this.printServiceUrl=null,this.printTimeout=12e4,this.saveExportEnabled=!1,this.templatesInfo=null,this.updateDelay=1e3,this.view=null,this.templateCustomTextElements=null,this.templateOptions=new N}initialize(){this.addHandles([m(()=>[this.showPrintAreaEnabled,this.view],()=>{this.showPrintAreaEnabled?this._enablePrintPreview():(this.removeHandles("overlay-handler"),this.view?.overlay?.removeItem(this._getOverlayItem()))}),m(()=>[this.templateOptions.layout,this.templateOptions.layoutItem],()=>{this.loaded&&this._processTemplateOptions()}),m(()=>[this.allowedFormats,this.allowedLayouts],()=>{this.loaded&&this._loadTemplateInfos()}),m(()=>this.exportedLinks,()=>{for(const{name:t,extension:e}of this.exportedLinks)t&&e&&this._updateExportedFileNameMap(`${t}${e}`)},h)])}destroy(){this.removeHandles("overlay-handler"),this.view&&(this._overlayItem&&(this.view.overlay?.removeItem(this._overlayItem),this._overlayItem.destroy(),this._overlayItem=null),this.view=null)}get effectivePrintServiceUrl(){return this.printServiceUrl??null}get effectiveTemplateCustomTextElements(){if(!this._serviceTemplateCustomTextElements)return{};const t=r(this._serviceTemplateCustomTextElements);return this.templateCustomTextElements&&Object.keys(this.templateCustomTextElements).forEach(e=>{const i=t[e];if(i){const t=this.templateCustomTextElements?.[e];i.forEach(e=>{const[i]=Object.entries(e)[0];t?.forEach(t=>{const[s,o]=Object.entries(t)[0];i===s&&(e[i]=o)})})}}),Object.freeze(t)}get state(){return"loading"===this.loadStatus?"initializing":"failed"===this.loadStatus||this.error?"error":"loaded"===this.loadStatus&&this.view?.ready?"ready":"disabled"}async print(t){const{view:e,extraParameters:i,updateDelay:o,outSpatialReference:a}=this;if(!e)throw new s("print:view-required","view is not set");X(t);const r=this._getOverlayItem(),l=t.scalePreserved||!this.showPrintAreaEnabled?void 0:M(new _,e.viewpoint,"map-only"===t.layout?[t.exportOptions.width,t.exportOptions.height]:[r.boxWidth,r.boxHeight]),n=new C({view:e,template:t,extent:l,extraParameters:i,updateDelay:o,outSpatialReference:a});try{const e=!!t.layoutItem?.id&&(this.defaultTemplates.some(e=>e.layoutItem?.id===t.layoutItem?.id)||this.browseTemplates.some(e=>e.layoutItem?.id===t.layoutItem?.id));return await L(e&&this._asyncPrintTaskUrl?this._asyncPrintTaskUrl:this.effectivePrintServiceUrl,n,{timeout:this.printTimeout})}catch(p){throw new s("print:export-error","An error occurred while exporting the web map.",{error:p})}}async load(t){return this.addResolvingPromise(this._loadResources(t).catch(t=>this.error=t)),this}toPrintTemplate({attributionEnabled:t,author:e,copyright:i,customTextElements:o,dpi:a,forceFeatureAttributes:r,format:l,height:n,id:p,includeTables:m,layout:h,layoutItem:d,legendEnabled:u,dynamicLegendEnabled:c,northArrowEnabled:f,scale:y,scaleBarEnabled:v,scaleBarUnit:T,scaleEnabled:w,title:_,width:I}){if(!h&&!d)throw new s("print:layout-required","layout is not set");const g=new F({attributionVisible:t,forceFeatureAttributes:r,format:l,includeTables:m,layout:h,layoutItem:d,layoutOptions:{authorText:e,copyrightText:i,customTextElements:o,titleText:_,scalebarUnit:v&&T?K.toJSON(T):void 0},outScale:y??0,scalePreserved:w});if(I&&(g.exportOptions.width=I),n&&(g.exportOptions.height=n),a&&(g.exportOptions.dpi=a),g.layoutOptions){Z(this.view,g,u,c);const t=this.getLayoutTemplateById(p)?.mapSurroundInfoOptions;if(t){const e=t.northArrow;for(const t of e)tt(g,t,f);const i=t.scaleBar;for(const t of i)tt(g,t,v);const s=t.legend;for(const t of s)tt(g,t,u)}}return g}getLayoutTemplateById(t){return t?this._templateIdToCustomTemplate.get(t):null}async addPortalTemplate(t){if(!this.portal||!t?.id)return;try{if("loading"===this.loadStatus&&await d(()=>this.loaded),!this.loaded)throw new s("print:load-required","PrintViewModel must be loaded before adding portal templates.");t.loaded||await t.load()}catch{return void this.applyTemplate(this.defaultTemplate)}const e=new D({type:"browse-template",layoutInfoTaskUrl:this._portalLayoutInfoTaskUrl,label:t.title,layoutItem:t});this._templateIdToCustomTemplate.set(e.id,e),this.browseTemplates.add(e)}removePortalTemplate(t){t.layoutItem&&this.templateOptions.id===t.layoutItem.id&&(this.defaultTemplate?this.applyTemplate(this.defaultTemplate):this.templateOptions.reset()),this.browseTemplates.remove(t),this._templateIdToCustomTemplate.delete(t.id)}async applyTemplate(t){if(t&&t===this.getLayoutTemplateById(this.templateOptions.id))return;if(this.templateOptions.reset(),!t)return;if("map-only"===t)return void(this.templateOptions.layout="map-only");!t.layout||!this.templatesInfo||this.templatesInfo.layout.choiceList.includes(t.layout)||(this.defaultTemplate?t=this.defaultTemplate:this.templateOptions.reset());const e=t.layout||t.layoutItem?.id,i=e?this.templateCustomTextElements?.[e]:void 0;if(await this.templateOptions.applyTemplate(t,{customTextElements:i,customLayoutOptions:this._customLayoutOptions}),e&&this._serviceTemplateCustomTextElements&&!this._serviceTemplateCustomTextElements[e]&&t.layoutTemplateInfo?.layoutOptions?.customTextElements){const i=r(this._serviceTemplateCustomTextElements);i[e]=t.layoutTemplateInfo.layoutOptions.customTextElements,this._serviceTemplateCustomTextElements=Object.freeze(i)}}createExportedFileLink(t){const e=this.toPrintTemplate(this.templateOptions).format.toLowerCase(),i=e.includes("png")?"png":e,s=t+i;return this._updateExportedFileNameMap(s),new W({name:t,extension:i,count:this._exportedFileNameMap[s]})}export(t){const e=this.createExportedFileLink(t);this.exportedLinks.add(e);const i=this.print(this.toPrintTemplate(this.templateOptions)).then(t=>e.set({url:t?.url,state:"ready"})).catch(t=>e.set({error:t,state:"error"}));return this.emit("submit",{link:e,saveExportEnabled:this.saveExportEnabled}),i.then(t=>this.emit("complete",{link:t,saveExportEnabled:this.saveExportEnabled})),{link:e,promise:i}}async _loadResources(t){this.destroyed||(await this._loadUrls(t),await this._loadTemplateInfos(t),await this._updateOverLayItem())}async _loadTemplateInfos(t){const e=[...this.defaultTemplates,...this.printServiceTemplates];for(const{id:o}of e)this._templateIdToCustomTemplate.delete(o);this.defaultTemplates.removeAll(),this.printServiceTemplates.removeAll();const[i,s]=await Promise.all([this._getLayoutToLayoutTemplateInfos(t),this._getPrintServiceTemplatesInfo(t)]);await this._loadAllTemplates(i,s,t),this._processPrintServiceTemplatesInfo(s),await this._processTemplateOptions()}_updateExportedFileNameMap(t){void 0!==this._exportedFileNameMap[t]?this._exportedFileNameMap[t]++:this._exportedFileNameMap[t]=0}async _processTemplateOptions(){const{layout:t,layoutItem:e}=this.templateOptions;if("map-only"!==t)if(this._customLayoutOptions={legend:this.templateOptions.legendEnabled,northArrow:this.templateOptions.northArrowEnabled,scaleBar:this.templateOptions.scaleBarEnabled},e?.id){try{e.loaded||await e.load()}catch{return void this.applyTemplate(this.defaultTemplate)}let t=this._templateIdToCustomTemplate.get(e.id);t||(t=new D({label:e.title,layoutItem:e,layoutInfoTaskUrl:this._portalLayoutInfoTaskUrl}),this._templateIdToCustomTemplate.set(t.id,t)),await this.applyTemplate(t)}else if(t){const t=this.defaultTemplates.find(t=>t.layout===this.templateOptions.layout)??this.printServiceTemplates.find(t=>t.layout===this.templateOptions.layout);await this.applyTemplate(t??this.defaultTemplate)}}async _loadPortal(t){try{await this.portal.load(t)}catch(e){throw new s("print:could-not-load-portal","Cannot load print resource information from portal",{error:e,url:this.effectivePrintServiceUrl})}}async _loadUrls(t){if(this.printServiceUrl)this._set("effectivePrintServiceUrl",this.printServiceUrl),this._layoutInfoTaskUrl=await this._getLayoutInfoTaskUrl(this.effectivePrintServiceUrl,t);else{await this._loadPortal(t);const{printTask:e,asyncPrintTask:i,layoutInfoTask:s}=this.portal?.helperServices??{};this._set("effectivePrintServiceUrl",e?.url),this._asyncPrintTaskUrl=i?.url,this._layoutInfoTaskUrl=await this._getLayoutInfoTaskUrl(this.effectivePrintServiceUrl,t),s?.url&&this.effectivePrintServiceUrl!==s.url?this._portalLayoutInfoTaskUrl=await this._getLayoutInfoTaskUrl(s.url,t):this._portalLayoutInfoTaskUrl=this._layoutInfoTaskUrl}const e=this.effectivePrintServiceUrl?.toLowerCase().split("/");if(!e?.includes("gpserver"))throw new s("print:invalid-print-service-url","Can't fetch print templates information from provided URL",{url:this.effectivePrintServiceUrl})}async _getLayoutInfoTaskUrl(t,e){if(!t)return null;const i=await P(t,"GetLayoutTemplatesInfo",e);return i?t.replace(G,`$1${encodeURI(i.displayName)}`):null}_getPortalDefaultTemplates(t,e){return this.portal?.helperServices?.printTask?.templates?.filter(t=>"map_only"!==t.layout.toLowerCase()&&(!e||e.includes(k(t.layout))))?.map(e=>{const i=D.fromJSON(e);if(i.type="default-template",i.layoutInfoTaskUrl=this._layoutInfoTaskUrl,i.layout){const e=t.get(i.layout);e&&i.setLayoutTemplateInfo(e)}return i})??[]}async _getPortalCustomTemplates(t){if(this.printServiceUrl||!this.portal)return[];const{layoutGroupQuery:e}=this.portal;if(!e)return[];const i=new E({query:e,disableExtraQuery:!0}),s=await this.portal.queryGroups(i,t);if(!s.total)return[];const o=s.results[0],a=new E({num:100,query:"type:Layout",sortField:o.sortField,sortOrder:o.sortOrder??void 0}),r=(await o.queryItems(a,t)).results;if(!r.length)return[];return r.map(t=>(this.portalTemplateIds.push(t.id),new D({type:"default-template",label:t.title,layoutItem:t,layoutInfoTaskUrl:this._portalLayoutInfoTaskUrl})))}async _loadAllTemplates(t,e,i){let s=!1;const o=e?.layout?.choiceList;if(this.includeDefaultTemplates&&this.portal&&!this.printServiceUrl){const e=this._getPortalDefaultTemplates(t,o);s=!!e.length,this.defaultTemplates.addMany(e);const a=await this._getPortalCustomTemplates(i);this.defaultTemplates.addMany(a);for(const t of this.defaultTemplates)this._templateIdToCustomTemplate.set(t.id,t)}s||t.forEach((t,e)=>{if(!o||o.includes(e)){const i=new D({type:"print-service-template",layout:e,layoutInfoTaskUrl:this._layoutInfoTaskUrl});i.setLayoutTemplateInfo(t),this.printServiceTemplates.add(i),this._templateIdToCustomTemplate.set(i.id,i)}})}_processPrintServiceTemplatesInfo(t){this._set("templatesInfo",t);const e=t?.layout?.defaultValue;if(e&&"map-only"!==e){const t=this.defaultTemplates.find(t=>t.layout===e)??this.printServiceTemplates.find(t=>t.layout===e)??this.defaultTemplates.at(0)??this.printServiceTemplates.at(0);this._set("defaultTemplate",t)}}async _getLayoutToLayoutTemplateInfos(t){const e=this._layoutInfoTaskUrl,i=e?this._layoutTemplateInfosCache.get(e):void 0,s=i??await R(e,void 0,t);i||this._layoutTemplateInfosCache.set(e,s);const o=new Map,a={};for(const r of s){const t=k(r.layoutTemplate);o.set(t,r),a[t]=r.layoutOptions.customTextElements}return this._serviceTemplateCustomTextElements=Object.freeze(a),o}async _getPrintServiceTemplatesInfo(t){const e=this.effectivePrintServiceUrl?this._tasksInfoCache.get(this.effectivePrintServiceUrl):void 0,i=e??await P(this.effectivePrintServiceUrl,"ExportWebMap",t);if(!i)throw new s("print:unavailable-service-info","Can't fetch templates info from service");e||this._tasksInfoCache.set(this.effectivePrintServiceUrl,i);const{parameters:o}=i,a=o.find(({name:t})=>"Format"===t),r=o.find(({name:t})=>"Layout_Template"===t);return{format:this._getFormat(a),layout:this._getLayout(r)}}_getFormat(t){const i="all"===this.allowedFormats?t.choiceList:t.choiceList.filter(t=>"string"!=typeof this.allowedFormats&&this.allowedFormats.some(e=>new RegExp(`\\b${e}\\b`,"i").test(t))),s=(i.length?i:t.choiceList).map(t=>S.fromJSON(t)).filter(e),o=S.fromJSON(t.defaultValue),a=s.some(t=>new RegExp(`\\b${o}\\b`,"i").test(t))?o:s[0];return{choiceList:s,defaultValue:a}}_getLayout(t){const i=t.choiceList.filter(t=>"map_only"!==t.toLowerCase()),s="all"===this.allowedLayouts?i:i.filter(t=>this.allowedLayouts.includes(k(t))),o=(s.length?s:i).map(k).filter(e),a=k(t.defaultValue),r=o.includes(a)?a:o.find(t=>/(?=.*letter)(?=.*landscape)/i.test(t))??o.find(t=>/(?=.*a4)(?=.*landscape)/i.test(t))??o[0];return{choiceList:o,defaultValue:r}}_getOverlayItem(){return this._overlayItem||(this._overlayItem=new A({strokeDash:[5],strokeWidth:2,strokeColor:[30,144,255,255]})),this._overlayItem}_enablePrintPreview(){if(!this.view?.overlay)return;const t=this.templateOptions,e=this._getOverlayItem();this.addHandles([m(()=>[t.width,t.height,t.scaleEnabled,t.scale,t.layout,t.layoutItem,t.id,t.state,t.dpi,this.view?.scale,this.view?.size,this.view?.state.paddedViewState.size,this.view?.state.padding,this.loaded],()=>{this._updateOverLayItem()},h),this.view?.on("drag",["Shift"],t=>this._handleDrag(t),H.WIDGET),this.view?.on("key-down",["Escape"],()=>this._resetDrag(),H.WIDGET)],"overlay-handler"),this.view.overlay.addItem(e)}async _updateOverLayItem(){if(!this.view)return;await this.view.when();const t=this.templateOptions,e=this._getOverlayItem(),i=t.layoutItem?.id??t.layout,s=this.view,o=s.spatialReference,[a,r]=s.state.paddedViewState.size,l=s.state.padding;let n=0,p=0;if("map-only"===i)null!=t.width&&null!=t.height&&(n=t.width,p=t.height);else if(i){const e=t.id?this._templateIdToCustomTemplate.get(t.id):null,{webMapFrameSize:i,pageUnits:s}=e?.layoutTemplateInfo??{};let l=!1;if(i&&s)if(this._isFreeHand){const t=i[0]/i[1];n=this._freeHandWidth,p=this._freehandHeight,n>p?p=n/t:n=p*t}else{const t=V.fromJSON(s.toLowerCase()),e=o.unit;c(t)===c(e)?(n=f(i[0],t,e),p=f(i[1],t,e)):(l=!0,n=i[0],p=i[1])}if(!this._isFreeHand)if(t.scaleEnabled&&t.scale){const t=l?Math.min(a/n,r/p):y(o)*v*$;n*=t,p*=t}else if(0===n||0===p)n=a,p=r;else{const t=(a-.1*a)/n,e=(r-.1*r)/p,i=Math.min(t,e);n*=i,p*=i}}const{scaleEnabled:m,scale:h}=t,d=m&&h?h/this.view.scale:1;if(e.boxWidth=n*d||a,e.boxHeight=p*d||r,l&&(e.padding=l),e.backgroundWidth=a??0,e.backgroundHeight=r??0,"loading"===this.loadStatus)e.strokeColor=B;else if("loaded"===this.loadStatus)switch(this.templateOptions.state){case"pending":e.strokeColor=B;break;case"ready":e.strokeColor=z;break;case"error":e.strokeColor=q}}_resetDrag(){this._isFreeHand=!1,this._updateOverLayItem()}_handleDrag(t){switch(t.action){case"start":this._start();break;case"update":this._update(t);break;case"end":this._end()}t.stopPropagation()}_start(){this._isFreeHand=!0}_update(t){const e=this._getOverlayItem(),{x:i,y:s}=t,{x:o,y:a}=t.origin;i>o?(e.x=o,e.boxWidth=i-o):(e.x=i,e.boxWidth=o-i),s>a?(e.y=a,e.boxHeight=s-a):(e.y=s,e.boxHeight=a-s)}_end(){const t=this._getOverlayItem();if(!this.view||null==t.x||null==t.y)return;const e=this.view,i=e.toMap(u(t.x+.5*t.boxWidth,t.y+.5*t.boxHeight));t.x=null,t.y=null,e.goTo({center:i}),this._freeHandWidth=t.boxWidth,this._freehandHeight=t.boxHeight,"map-only"===this.templateOptions.layout&&(this.templateOptions.width=this._freeHandWidth,this.templateOptions.height=this._freehandHeight),this.templateOptions.scale=this.view.scale,this._updateOverLayItem()}};t([T()],et.prototype,"_serviceTemplateCustomTextElements",void 0),t([T()],et.prototype,"_templateIdToCustomTemplate",void 0),t([T()],et.prototype,"allowedFormats",void 0),t([T()],et.prototype,"allowedLayouts",void 0),t([T({type:J})],et.prototype,"browseTemplates",void 0),t([T({type:J})],et.prototype,"defaultTemplates",void 0),t([T()],et.prototype,"error",void 0),t([T({type:Q})],et.prototype,"exportedLinks",void 0),t([T()],et.prototype,"extraParameters",void 0),t([T()],et.prototype,"includeDefaultTemplates",void 0),t([T({readOnly:!0})],et.prototype,"effectivePrintServiceUrl",null),t([T()],et.prototype,"effectiveTemplateCustomTextElements",null),t([T({type:I})],et.prototype,"outSpatialReference",void 0),t([T({type:O})],et.prototype,"portal",void 0),t([T()],et.prototype,"portalTemplateIds",void 0),t([T({type:J})],et.prototype,"printServiceTemplates",void 0),t([T({readOnly:!0})],et.prototype,"defaultTemplate",void 0),t([T()],et.prototype,"showPrintAreaEnabled",void 0),t([T()],et.prototype,"printServiceUrl",void 0),t([T()],et.prototype,"printTimeout",void 0),t([T()],et.prototype,"saveExportEnabled",void 0),t([T({readOnly:!0})],et.prototype,"state",null),t([T({readOnly:!0})],et.prototype,"templatesInfo",void 0),t([T()],et.prototype,"updateDelay",void 0),t([T()],et.prototype,"view",void 0),t([T()],et.prototype,"templateCustomTextElements",void 0),t([T({type:N})],et.prototype,"templateOptions",void 0),et=t([w("esri.widgets.Print.PrintViewModel")],et);const it=et;export{it as default};
|