@arcgis/core 4.24.0-next.20220619 → 4.24.0
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/_Editor.scss +12 -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/config.js +1 -1
- package/interfaces.d.ts +15 -9
- package/package.json +1 -1
- package/support/revision.js +1 -1
- package/views/2d/layers/imagery/BaseImageryTileSubView2D.js +1 -1
- package/views/3d/analysis/LineOfSightAnalysisResult.js +1 -1
- package/views/3d/layers/support/FeatureTileFetcher3D.js +1 -1
- package/views/interactive/snapping/featureSources/featureServiceSource/FeatureServiceSnappingSourceWorkerHandle.js +1 -1
- package/widgets/Directions.js +1 -1
- package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
- package/widgets/Editor/CreateWorkflow.js +1 -1
- package/widgets/Editor/UpdateWorkflow.js +1 -1
- package/widgets/Editor.js +1 -1
- package/widgets/FeatureForm/FeatureFormViewModel.js +1 -1
- package/widgets/FeatureForm/InputField.js +1 -1
- package/widgets/FeatureForm/InputFieldGroup.js +1 -1
- package/widgets/FeatureForm.js +1 -1
- package/widgets/support/datePickerUtils.js +1 -1
package/widgets/Editor.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{HandleOwnerMixin as t}from"../core/HandleOwner.js";import s from"../core/Logger.js";import{isSome as i}from"../core/maybe.js";import{watch as a,on as o,when as n,initial as r}from"../core/reactiveUtils.js";import{aliasOf as l}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import{cast as d}from"../core/accessorSupport/decorators/cast.js";import{property as c}from"../core/accessorSupport/decorators/property.js";import{subclass as p}from"../core/accessorSupport/decorators/subclass.js";import{getDisplayFieldName as h}from"../layers/support/fieldUtils.js";import m from"../views/interactive/sketch/SketchLabelOptions.js";import u from"../views/interactive/sketch/SketchTooltipOptions.js";import g from"../views/interactive/snapping/SnappingOptions.js";import w from"./Attachments.js";import v from"./FeatureForm.js";import f from"./FeatureTemplates.js";import _ from"./Spinner.js";import k from"./Widget.js";import{workflowDeprecation as y}from"./Editor/deprecationUtils.js";import b from"./Editor/EditorViewModel.js";import{ItemList as C}from"./FeatureTemplates/ItemList.js";import{Heading as M,incrementHeadingLevel as A}from"./support/Heading.js";import F from"./support/SnappingControls.js";import{accessibleHandler as W}from"./support/decorators/accessibleHandler.js";import{messageBundle as T}from"./support/decorators/messageBundle.js";import{vmEvent as S}from"./support/decorators/vmEvent.js";import{tsx as E}from"./support/jsxFactory.js";import{classes as B}from"./support/widgetUtils.js";import{substitute as j}from"../intl/substitute.js";const L={base:"esri-editor esri-widget esri-widget--panel",message:"esri-editor__message",controls:"esri-editor__controls",controlButton:"esri-editor__control-button",progressBar:"esri-editor__progress-bar",panelToolbar:"esri-editor__panel-toolbar",panelContent:"esri-editor__panel-content",panelContentSection:"esri-editor__panel-content__section",panelContentSectionGroup:"esri-editor__panel-content__section__group",panelContentMessage:"esri-editor__panel-content__message",scroller:"esri-editor__scroller",snappingSettingsContainer:"esri-editor__snapping-settings",updateFeaturesActionButtons:"esri-editor__update-features-action-buttons",updateFeaturesActionButtonsButton:"esri-editor__update-features-action-buttons--button",featureTemplatesContainer:"esri-editor__feature-templates-container",promptContainer:"esri-editor__prompt",promptHeader:"esri-editor__prompt__header",promptHeading:"esri-editor__prompt__header__heading",promptMessage:"esri-editor__prompt__message",promptDivider:"esri-editor__prompt__divider",promptActions:"esri-editor__prompt__actions",warningIcon:"esri-icon-notice-triangle",widgetIcon:"esri-icon-edit",button:"esri-button",buttonDisabled:"esri-button--disabled",buttonSecondary:"esri-button--secondary",buttonTertiary:"esri-button--tertiary"},P=B(L.scroller,L.panelContent),V={undoRedoButtons:!1};function x(e){e.focus()}const U="esri.widgets.Editor",D=s.getLogger(U);let I=class extends(t(k)){constructor(e,t){super(e,t),this._candidateCommitted=!1,this._featureForm=new v,this._stateStack=[],this._attachments=new w({visibleElements:{addSubmitButton:!1,cancelAddButton:!1,cancelUpdateButton:!1,deleteButton:!1,errorMessage:!1,progressBar:!1,updateButton:!1}}),this._featureTemplates=new f({enableListScroll:!1}),this._filterText="",this._prompt=null,this._spinner=new _,this._snappingPopover=null,this.activeWorkflow=null,this.allowedWorkflows=null,this.useDeprecatedCreateWorkflow=!1,this.headingLevel=4,this.iconClass=L.widgetIcon,this.label=void 0,this.labelOptions=new m,this.layerInfos=null,this.messages=null,this.messagesCommon=null,this.messagesTemplates=null,this.snappingOptions=new g,this.tooltipOptions=new u,this.supportingWidgetDefaults=null,this.view=null,this.viewModel=new b,this.visibleElements={...V},this._setCandidateFeature=(e,t=!1)=>{if(this._candidateCommitted)return;const s=this._assertActiveUpdateWorkflow();s.data.edits.feature=e,t&&(s.next(),this._candidateCommitted=!0)},this._handleSave=this._handleSave.bind(this),this._handleBack=this._handleBack.bind(this),this._handleDone=this._handleDone.bind(this),this._handleDelete=this._handleDelete.bind(this),this._handleAdd=this._handleAdd.bind(this),this._handleEdit=this._handleEdit.bind(this),this._handleAttachmentAdd=this._handleAttachmentAdd.bind(this),this._handleAttachmentUpdate=this._handleAttachmentUpdate.bind(this),this._handleAttachmentDelete=this._handleAttachmentDelete.bind(this),this.EditorPanel=this.EditorPanel.bind(this)}initialize(){const{view:e,snappingOptions:t}=this;this._snappingControls=new F({snappingOptions:t,view:e,visibleElements:{header:!1}}),this.own([a((()=>this.headingLevel),(e=>{this._featureForm.headingLevel=A(e),this._featureTemplates.headingLevel=A(e)}),r),this.viewModel.featureTemplatesViewModel.on("select",(({item:e})=>this.useDeprecatedCreateWorkflow?this.startCreateWorkflowAtFeatureCreation(e):this.startCreateFeaturesWorkflowAtFeatureCreation(e))),a((()=>this.viewModel.state),((e,t)=>{const s=this._stateStack.indexOf(e);-1===s?this._stateStack.push(t):this._stateStack.splice(s)})),a((()=>this.viewModel),(e=>{this._featureForm.viewModel=e?e.featureFormViewModel:null,this._attachments.viewModel=e?e.attachmentsViewModel:null,this._featureTemplates.viewModel=e?e.featureTemplatesViewModel:null,this._spinner.viewModel=e?e.spinnerViewModel:null}),r),a((()=>this.view),((e,t)=>{const s=`editor-${this.id}-spinner`;t&&t.ui.remove(this._spinner,s),e&&e.ui.add(this._spinner,{key:s,position:"manual"})}),r),o((()=>this.viewModel?.sketchViewModel),"create",(()=>{this.scheduleRender()})),o((()=>this.viewModel?.activeWorkflow),"cancel-request",(({controller:e})=>{const{messages:t,messagesCommon:s}=this;this._prompt={title:t.cancelRequestTitle,message:t.cancelRequestWarningMessage,context:"danger",actions:{primary:{label:s.form.yes,action:()=>{e.allow(),this._prompt=null}},secondary:{label:s.form.no,action:()=>(e.deny(),this._prompt=null)}}},this.scheduleRender()})),a((()=>this.supportingWidgetDefaults),(e=>{e&&(this._featureForm.set(e.featureForm),this._attachments.set(e.attachments),this._featureTemplates.set(e.featureTemplates),this.viewModel.sketchViewModel.set(e.sketch))}),r),a((()=>this._attachments?.error),(e=>{if(!e)return;const{messages:t,messagesCommon:s}=this;this._prompt={title:t.errorWarningTitle,message:e.message,context:"warning",actions:{primary:{label:s.form.ok,action:()=>{this._prompt=null}}}}})),a((()=>this.viewModel?.failures),(e=>{if(!e)return;const{messages:t}=this,[{error:s,retry:i,cancel:a}]=e;this._prompt={title:t.errorWarningTitle,message:j(t.errorWarningMessageTemplate,{errorMessage:s.message}),context:"warning",actions:{primary:{label:t.retry,action:()=>{i(),this._prompt=null}},secondary:{label:t.ignore,action:()=>(a(),this._prompt=null)}}}})),a((()=>this.viewModel?.state),(e=>{"awaiting-feature-to-update"===e&&(this._filterText=""),"awaiting-update-feature-candidate"===e&&(this._candidateCommitted=!1)})),a((()=>[this._attachments?.selectedFile,this._attachments?.submitting]),(()=>this.scheduleRender())),n((()=>!this.viewModel?.activeWorkflow),(()=>this._featureTemplates.filterText="")),o((()=>this.view),"key-down",(e=>{"Escape"===e.key&&this.viewModel?.activeWorkflow&&this._handleBack()}))])}destroy(){this._attachments.destroy(),this._featureForm.destroy(),this._featureTemplates.destroy(),this._snappingControls.destroy()}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-action.js"),import("@esri/calcite-components/dist/components/calcite-action-menu.js"),import("@esri/calcite-components/dist/components/calcite-button.js"),import("@esri/calcite-components/dist/components/calcite-flow.js"),import("@esri/calcite-components/dist/components/calcite-icon.js"),import("@esri/calcite-components/dist/components/calcite-loader.js"),import("@esri/calcite-components/dist/components/calcite-panel.js"),import("@esri/calcite-components/dist/components/calcite-block.js"),import("@esri/calcite-components/dist/components/calcite-scrim.js"),import("@esri/calcite-components/dist/components/calcite-accordion.js"),import("@esri/calcite-components/dist/components/calcite-accordion-item.js")])}castVisibleElements(e){return{...V,...e}}startCreateWorkflowAtFeatureTypeSelection(){return y(D,"startCreateWorkflowAtFeatureTypeSelection","startCreateFeaturesWorkflowAtFeatureTypeSelection"),this.viewModel.startCreateWorkflowAtFeatureTypeSelection()}startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.viewModel.startCreateFeaturesWorkflowAtFeatureTypeSelection()}startCreateWorkflowAtFeatureCreation(e){return y(D,"startCreateWorkflowAtFeatureCreation","startCreateFeaturesWorkflowAtFeatureCreation"),this.viewModel.startCreateWorkflowAtFeatureCreation(e)}startCreateFeaturesWorkflowAtFeatureCreation(e){return this.viewModel.startCreateFeaturesWorkflowAtFeatureCreation(e)}startCreateWorkflowAtFeatureEdit(e){return y(D,"startCreateWorkflowAtFeatureEdit"),this.viewModel.startCreateWorkflowAtFeatureEdit(e)}startUpdateWorkflowAtFeatureSelection(){return this.viewModel.startUpdateWorkflowAtFeatureSelection()}startUpdateWorkflowAtMultipleFeatureSelection(e){return this.viewModel.startUpdateWorkflowAtMultipleFeatureSelection(e)}startUpdateWorkflowAtFeatureEdit(e){return this.viewModel.startUpdateWorkflowAtFeatureEdit(e)}deleteFeatureFromWorkflow(){return this.viewModel.deleteFeatureFromWorkflow()}cancelWorkflow(e){return this.viewModel.cancelWorkflow(e)}render(){const{_attachments:e,_prompt:t,viewModel:s}=this;if(!s)return E("div",{class:L.base});const{state:a}=s,o=i(t)?E("calcite-scrim",null,this.renderPrompt(t)):null;return E("div",{class:L.base},s.syncing||e.submitting?this.renderProgressBar():null,E("calcite-flow",null,this._stateStack.map((e=>this.renderState(e))),this.renderState(a)),o)}renderState(e){switch(e){case"disabled":break;case"ready":return this.renderLanding(e);case"awaiting-feature-creation-info":return this.renderTemplates(e);case"creating-features":case"editing-new-feature":case"editing-existing-feature":return this.renderAttributeEditing(e);case"awaiting-feature-to-update":return this.renderFeatureUpdating(e);case"awaiting-update-feature-candidate":return this.renderFeatureList(e);case"awaiting-feature-to-create":return this.renderFeatureCreation(e);case"adding-attachment":return this.renderAttachmentAdding(e);case"editing-attachment":return this.renderAttachmentEditing(e)}return E("div",null)}isPanelActive(e){return this.viewModel.state===e}renderTemplates(e){const{EditorPanel:t,headingLevel:s,messages:i,messagesCommon:a,_handleBack:o,_snappingControls:n,viewModel:{sketchViewModel:r}}=this;return E(t,{active:this.isPanelActive(e),key:"templates-panel",handleBack:o,heading:i.selectTemplate,headingLevel:s,messages:i,messagesCommon:a,sketchViewModel:r,snappingControls:n},E("div",{class:P},this._featureTemplates.render()))}renderAttributeEditing(e){const{activeWorkflow:t,EditorPanel:s,messages:i,messagesCommon:a,headingLevel:o,_handleBack:n,_snappingControls:r,viewModel:l}=this,{sketchViewModel:d}=l,c=l.featureFormViewModel;if("create-features"===t.type&&t.pendingFeatures.length<1)return this.renderFeatureCreation(e);const p="update"===t.type&&!t.data.edits.modified||l.syncing,h="update"===t.type?i.editFeature:i.createFeatures,m="update"===t.type?a.update:a.create,u="create-features"===t.type&&"create-new"===t.createFeatureState,g="update"===t.type&&t.data.editableItem.supports.includes("delete"),w="update"===t.type&&t.data.editableItem.hasAttachments,v=[{label:"create-features"===t.type&&t.numPendingFeatures>1?j(i.createFeaturesTemplate,{numFeatures:t.numPendingFeatures}):m,type:"primary",disabled:p,clickHandler:this._handleSave,width:g?"half":"full"}];return g&&v.push({label:a.delete,type:"tertiary",clickHandler:this._handleDelete,appearance:"outline",width:"half"}),E(s,{active:this.isPanelActive(e),key:"attribute-editing-panel",heading:h,headingLevel:o,handleBack:n,messages:i,messagesCommon:a,sketchViewModel:d,snappingControls:r},E("div",{class:P},E("div",{class:L.panelContentSection},E("div",{class:L.panelContentSectionGroup},c.inputFields.length>0?this._featureForm.render():this.renderMessage(j(i.clickToFinishTemplate,{button:m})),w?E("div",{key:"attachments"},E("div",null,i.attachments),this._attachments.render()):null),u?E("calcite-scrim",null):null)),this.renderFooterActions(v))}renderAttachmentAdding(e){const{_attachments:t,EditorPanel:s,_handleBack:i,headingLevel:a,messages:o,messagesCommon:n,_snappingControls:r,viewModel:{sketchViewModel:l}}=this,d=[{label:t.submitting?n.cancel:n.add,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentAdd,width:"full"}];return E(s,{active:this.isPanelActive(e),key:"attachment-adding-panel",heading:o.addAttachment,headingLevel:a,handleBack:i,messages:o,messagesCommon:n,sketchViewModel:l,snappingControls:r},E("div",{class:P},t.render()),this.renderFooterActions(d))}renderAttachmentEditing(e){const{_attachments:t,EditorPanel:s,_handleBack:i,headingLevel:a,messages:o,messagesCommon:n,_snappingControls:r,viewModel:{sketchViewModel:l}}=this,d=[{label:n.update,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentUpdate,width:"half"},{label:n.delete,disabled:t.submitting,type:"tertiary",clickHandler:this._handleAttachmentDelete,width:"half",appearance:"outline"}];return E(s,{active:this.isPanelActive(e),key:"attachment-editing-panel",heading:o.editAttachment,headingLevel:a,handleBack:i,messages:o,messagesCommon:n,sketchViewModel:l,snappingControls:r},E("div",{class:P},t.render()),this.renderFooterActions(d))}renderFeatureUpdating(e){const{EditorPanel:t,_handleBack:s,headingLevel:i,messages:a,messagesCommon:o,_snappingControls:n,viewModel:{sketchViewModel:r}}=this;return E(t,{active:this.isPanelActive(e),key:"feature-updating-panel",heading:a.selectFeature,headingLevel:i,handleBack:s,messages:a,messagesCommon:o,sketchViewModel:r,snappingControls:n},E("div",{class:B(P,L.panelContentMessage)},this.renderMessage(a.selectFeatureToEdit)))}renderMessage(e){return E("div",{class:L.message},e)}renderFeatureCreation(e){const{EditorPanel:t,_handleBack:s,headingLevel:i,messages:a,messagesCommon:o,_snappingControls:n,viewModel:r}=this,{sketchViewModel:l}=r,d=r.sketchViewModel,c=this._assertActiveCreateWorkflow().data.creationInfo.layer,p=d.canUndo()&&d.createGraphic?d.createGraphic:null,h=this._getSketchingTip(c.geometryType,p);return E(t,{active:this.isPanelActive(e),key:"feature-creation-panel",heading:a.placeFeature,headingLevel:i,handleBack:s,messages:a,messagesCommon:o,sketchViewModel:l,snappingControls:n},E("div",{class:B(P,L.panelContentMessage)},this.renderMessage(h)))}renderFooterActions(e){return e.map((({type:e,disabled:t,class:s,...i},a)=>this.renderButton({class:this.classes(L.controlButton,"secondary"===e?L.buttonSecondary:"tertiary"===e?L.buttonTertiary:null,t?L.buttonDisabled:null,s),disabled:t??!1,key:a,slot:"footer-actions",...i})))}renderPrompt({title:e,message:t,context:s,actions:i}){const a=!!i.secondary,o=E("calcite-button",{appearance:"solid",color:"danger"===s?"red":"blue",width:a?"half":"full",onclick:i.primary.action,key:"prompt-primary-button",afterCreate:x},i.primary.label),n=a?E("calcite-button",{appearance:"clear",color:"danger"===s?"red":"blue",width:"half",onclick:i.secondary.action,key:"prompt-secondary-button"},i.secondary.label):null;return E("div",{class:`${L.promptContainer}--${s}`},E("div",{class:L.promptHeader},E("calcite-icon",{icon:"exclamation-mark-triangle"}),E(M,{class:L.promptHeading,level:this.headingLevel},e)),E("div",{class:L.promptMessage},t),E("div",{class:L.promptDivider}),E("div",{class:L.promptActions},n,o))}renderProgressBar(){return E("div",{class:this.classes(L.progressBar),key:"progress-bar"})}renderButton(e){const{disabled:t,class:s,key:i,clickHandler:a,label:o,...n}=e;return E("calcite-button",{class:s,disabled:t,key:i,onclick:a,type:"button",...n},o)}renderLanding(e){const{EditorPanel:t,headingLevel:s,messages:i,messagesCommon:a,_snappingControls:o,viewModel:{sketchViewModel:n}}=this;return E(t,{active:this.isPanelActive(e),key:"landing-panel",heading:i.widgetLabel,headingLevel:s,showBackButton:!1,messages:i,messagesCommon:a,sketchViewModel:n,snappingControls:o},E("div",{class:P},E("div",{key:"edit-actions",class:L.panelContentSection},this.renderUpdateActions()),E("div",{key:"create-actions",class:L.panelContentSection},this.renderCreateActions())))}renderUpdateActions(){const{messages:e,messagesCommon:t}=this;return E("div",null,E(M,{level:A(this.headingLevel)},e.editFeatures),E("div",{class:L.updateFeaturesActionButtons},E("calcite-action",{text:t.select,textEnabled:!0,icon:"cursor",alignment:"start",class:L.updateFeaturesActionButtonsButton,onclick:this._handleEdit})))}renderCreateActions(){const{_featureTemplates:e,headingLevel:t,messages:s}=this,i=e.viewModel.items;if(i&&i.length)return E("div",null,E(M,{level:A(t)},s.createFeatures),E("div",{key:"templates",class:L.featureTemplatesContainer},e.render()))}renderFeatureList(e){const{EditorPanel:t,_handleBack:s,headingLevel:i,messages:a,messagesCommon:o,messagesTemplates:n,_snappingControls:r,viewModel:{editableItems:l,sketchViewModel:d}}=this,c=this._assertActiveUpdateWorkflow().data.candidates,p=j(a.multipleFeaturesTemplate,{total:c.length}),h=new Map;let m=0;c.map((e=>({label:this._getLabel(e),id:e.attributes[e.layer.objectIdField],data:e}))).filter((e=>{const{label:t,data:s}=e,i=this._filterText.toLowerCase(),{title:a}=s.layer,o=this.viewModel.editableItems.find((e=>e.layer===s.layer));return o.supports.includes("update")&&(!i||t.toLowerCase().includes(i)||a.toLowerCase().includes(i))})).forEach((e=>{m++;const t=e.data.layer;h.has(t)?h.get(t).items.push(e):h.set(t,{id:`${t.id}`,label:t.title,items:[e]})}));const u=l.filter((({layer:e})=>h.has(e))).map((({layer:e})=>h.get(e))).toArray(),g=m>10||this._filterText.length>0;return E(t,{active:this.isPanelActive(e),key:"feature-list",heading:p,headingLevel:i,handleBack:s,messages:a,messagesCommon:o,sketchViewModel:d,snappingControls:r},E("div",{class:P},C({id:this.id,enableListScroll:!1,filterEnabled:g,filterText:this._filterText,items:u,messages:{filterPlaceholder:n.filterPlaceholder,noItems:n.noItems,noMatches:n.noMatches},onItemMouseEnter:({data:e})=>this._setCandidateFeature(e),onItemMouseLeave:()=>this._setCandidateFeature(null),onItemSelect:({data:e})=>this._setCandidateFeature(e,!0),onFilterChange:e=>this._filterText=e})))}EditorPanel(e,...t){const{handleBack:s,heading:i,headingLevel:a,key:o,messages:n,messagesCommon:r,showBackButton:l,sketchViewModel:d,snappingControls:c}=e;return E("calcite-panel",{bind:this,key:o,heading:i,headingLevel:a,showBackButton:l??!0,beforeBack:s??null,onCalcitePanelScroll:this._onSnappingPopoverPanelScroll},E("div",{class:L.panelToolbar},E("calcite-accordion",{class:L.snappingSettingsContainer,appearance:"transparent"},E("calcite-accordion-item",{"item-title":n.snapping,icon:"vertex-gps"},c.render())),this.visibleElements.undoRedoButtons?[E("calcite-button",{key:"undo-button",text:r.undo,appearance:"transparent",color:"neutral",alignment:"center","icon-start":"undo",scale:"l",disabled:!d.canUndo(),onclick:d.undo.bind(d)}),E("calcite-button",{key:"redo-button",text:r.redo,appearance:"transparent",color:"neutral",alignment:"center","icon-start":"redo",scale:"l",disabled:!d.canRedo(),onclick:d.redo.bind(d)})]:null),t)}_onSnappingPopoverPanelScroll(){this._snappingPopover?.open&&this._snappingPopover.toggle()}_getSketchingTip(e,t){const{messages:s}=this;if("point"===e)return s.tips.clickToAddPoint;if("polygon"===e||"polyline"===e){if(!t)return s.tips.clickToStart;const i=t.geometry,a="polygon"===e?"rings":"paths",[o]=i[a];return"polygon"===e&&o<4?s.tips.clickToContinue:s.tips.clickToContinueThenDoubleClickToEnd}return s.tips.clickToAddFeature}_getLabel(e){const t=e.layer;if(!t)return null;const{objectIdField:s}=t,{attributes:i}=e,a=h(t);return a&&i[a]&&`${i[a]}`||j(this.messages.untitledFeatureTemplate,{id:i[s]})}_handleDelete(){const{messages:e,messagesCommon:t}=this;this._prompt={title:e.deleteWarningTitle,message:e.deleteWarningMessage,context:"danger",actions:{primary:{label:t.delete,action:()=>{this.viewModel.deleteFeatureFromWorkflow(),this._prompt=null}},secondary:{label:e.keepFeature,action:()=>this._prompt=null}}}}_handleSave(){const{featureFormViewModel:e}=this.viewModel;e.submit(),!e.submittable||e.validateContingencyConstraints(e.getValues(),{includeIncompleteViolations:!0}).length>0||this.viewModel.activeWorkflow.commit()}_handleAttachmentAdd(){const{_attachments:e}=this,{activeWorkflow:t}=this.viewModel;e.addAttachment().then((()=>t.previous()))}_handleAttachmentUpdate(){const{_attachments:e}=this,{activeWorkflow:t}=this.viewModel;e.updateAttachment().then((()=>t.previous()))}_handleAttachmentDelete(){const{messages:e,messagesCommon:t}=this;this._prompt={title:e.deleteAttachmentWarningTitle,message:e.deleteAttachmentWarningMessage,context:"danger",actions:{primary:{label:t.delete,action:()=>{const{_attachments:e}=this,{activeWorkflow:t}=this.viewModel;e.deleteAttachment(e.viewModel.activeAttachmentInfo).then((()=>{t.previous(),this._prompt=null}))}},secondary:{label:e.keepAttachment,action:()=>this._prompt=null}}}}_handleAdd(){this.viewModel.canCreate}_handleEdit(){this.viewModel.canUpdate&&this.viewModel.startUpdateWorkflowAtFeatureSelection()}_handleDone(){this.viewModel.cancelWorkflow({force:!0})}async _handleBack(){const{messages:e}=this,t=this.activeWorkflow,s=()=>{t.hasPreviousStep?t.previous({cancelCurrentStep:!0}):this.viewModel.cancelWorkflow({force:!0})};if("create"===t.type||"create-features"===t.type&&t.numPendingFeatures>0||"editing-existing-feature"===t.stepId&&t.data.edits.modified){const{type:i}=t,a="create"===i?e.cancelAddWarningMessage:e.cancelEditWarningMessage,o="create"===i?e.cancelAddTitle:e.cancelEditTitle,n="create"===i?e.continueAdding:e.continueEditing,r="create"===i?e.discardFeature:e.discardEdits;throw this._prompt={title:o,message:a,context:"danger",actions:{primary:{label:r,action:()=>{s(),this._prompt=null}},secondary:{label:n,action:()=>this._prompt=null}}},this.scheduleRender(),new Error}s()}_assertActiveCreateWorkflow(){const{type:e}=this.viewModel.activeWorkflow;if("create"===e||"create-features"===e)return this.viewModel.activeWorkflow;throw Error("Expected activeWorkflow to be instance of CreateWorkflow or CreateFeaturesWorkflow")}_assertActiveUpdateWorkflow(){if("update"===this.viewModel.activeWorkflow.type)return this.viewModel.activeWorkflow;throw Error("Expected activeWorkflow to be an UpdateWorkflow")}};e([c()],I.prototype,"_attachments",void 0),e([l("viewModel.activeWorkflow")],I.prototype,"activeWorkflow",void 0),e([l("viewModel.allowedWorkflows")],I.prototype,"allowedWorkflows",void 0),e([c()],I.prototype,"useDeprecatedCreateWorkflow",void 0),e([c()],I.prototype,"headingLevel",void 0),e([c()],I.prototype,"iconClass",void 0),e([c({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],I.prototype,"label",void 0),e([l("viewModel.labelOptions")],I.prototype,"labelOptions",void 0),e([l("viewModel.layerInfos")],I.prototype,"layerInfos",void 0),e([c(),T("esri/widgets/Editor/t9n/Editor")],I.prototype,"messages",void 0),e([c(),T("esri/t9n/common")],I.prototype,"messagesCommon",void 0),e([c(),T("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],I.prototype,"messagesTemplates",void 0),e([l("viewModel.snappingOptions")],I.prototype,"snappingOptions",void 0),e([l("viewModel.tooltipOptions")],I.prototype,"tooltipOptions",void 0),e([c()],I.prototype,"supportingWidgetDefaults",void 0),e([l("viewModel.view")],I.prototype,"view",void 0),e([c(),S(["workflow-cancel","workflow-commit"])],I.prototype,"viewModel",void 0),e([c()],I.prototype,"visibleElements",void 0),e([d("visibleElements")],I.prototype,"castVisibleElements",null),e([W()],I.prototype,"_handleDelete",null),e([W()],I.prototype,"_handleAttachmentAdd",null),e([W()],I.prototype,"_handleAttachmentUpdate",null),e([W()],I.prototype,"_handleAttachmentDelete",null),e([W()],I.prototype,"_handleAdd",null),e([W()],I.prototype,"_handleEdit",null),e([W()],I.prototype,"_handleDone",null),I=e([p(U)],I);const O=I;export{O as default};
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{HandleOwnerMixin as t}from"../core/HandleOwner.js";import s from"../core/Logger.js";import{isSome as a}from"../core/maybe.js";import{watch as i,on as n,when as o,initial as r}from"../core/reactiveUtils.js";import{aliasOf as l}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import{cast as d}from"../core/accessorSupport/decorators/cast.js";import{property as c}from"../core/accessorSupport/decorators/property.js";import{subclass as p}from"../core/accessorSupport/decorators/subclass.js";import{getDisplayFieldName as h}from"../layers/support/fieldUtils.js";import m from"../views/interactive/sketch/SketchLabelOptions.js";import u from"../views/interactive/sketch/SketchTooltipOptions.js";import g from"../views/interactive/snapping/SnappingOptions.js";import v from"./Attachments.js";import w from"./FeatureForm.js";import _ from"./FeatureTemplates.js";import f from"./Spinner.js";import k from"./Widget.js";import{workflowDeprecation as b}from"./Editor/deprecationUtils.js";import y from"./Editor/EditorViewModel.js";import{ItemList as C}from"./FeatureTemplates/ItemList.js";import{Heading as M,incrementHeadingLevel as A}from"./support/Heading.js";import F from"./support/SnappingControls.js";import{accessibleHandler as W}from"./support/decorators/accessibleHandler.js";import{messageBundle as T}from"./support/decorators/messageBundle.js";import{vmEvent as S}from"./support/decorators/vmEvent.js";import{tsx as E}from"./support/jsxFactory.js";import{classes as B}from"./support/widgetUtils.js";import{substitute as P}from"../intl/substitute.js";const j={base:"esri-editor esri-widget esri-widget--panel",message:"esri-editor__message",controls:"esri-editor__controls",controlButton:"esri-editor__control-button",progressBar:"esri-editor__progress-bar",panelToolbar:"esri-editor__panel-toolbar",panelToolbarSnappingButton:"esri-editor__panel-toolbar__snapping-button",panelContent:"esri-editor__panel-content",panelContentSection:"esri-editor__panel-content__section",panelContentSectionGroup:"esri-editor__panel-content__section__group",panelContentMessage:"esri-editor__panel-content__message",scroller:"esri-editor__scroller",snappingControlsPopover:"esri-editor__snapping-controls-popover",updateFeaturesActionButtons:"esri-editor__update-features-action-buttons",updateFeaturesActionButtonsButton:"esri-editor__update-features-action-buttons--button",featureTemplatesContainer:"esri-editor__feature-templates-container",promptContainer:"esri-editor__prompt",promptHeader:"esri-editor__prompt__header",promptHeading:"esri-editor__prompt__header__heading",promptMessage:"esri-editor__prompt__message",promptDivider:"esri-editor__prompt__divider",promptActions:"esri-editor__prompt__actions",warningIcon:"esri-icon-notice-triangle",widgetIcon:"esri-icon-edit",button:"esri-button",buttonDisabled:"esri-button--disabled",buttonSecondary:"esri-button--secondary",buttonTertiary:"esri-button--tertiary"},L=B(j.scroller,j.panelContent),x={undoRedoButtons:!1};function U(e){e.focus()}const V="esri.widgets.Editor",D=s.getLogger(V);let I=class extends(t(k)){constructor(e,t){super(e,t),this._candidateCommitted=!1,this._featureForm=new w,this._stateStack=[],this._attachments=new v({visibleElements:{addSubmitButton:!1,cancelAddButton:!1,cancelUpdateButton:!1,deleteButton:!1,errorMessage:!1,progressBar:!1,updateButton:!1}}),this._featureTemplates=new _({enableListScroll:!1}),this._filterText="",this._prompt=null,this._spinner=new f,this._snappingPopover=null,this.activeWorkflow=null,this.allowedWorkflows=null,this.useDeprecatedCreateWorkflow=!1,this.headingLevel=4,this.iconClass=j.widgetIcon,this.label=void 0,this.labelOptions=new m,this.layerInfos=null,this.messages=null,this.messagesCommon=null,this.messagesTemplates=null,this.snappingOptions=new g,this.tooltipOptions=new u,this.supportingWidgetDefaults=null,this.view=null,this.viewModel=new y,this.visibleElements={...x},this._setCandidateFeature=(e,t=!1)=>{if(this._candidateCommitted)return;const s=this._assertActiveUpdateWorkflow();s.data.edits.feature=e,t&&(s.next(),this._candidateCommitted=!0)},this._handleSave=this._handleSave.bind(this),this._handleBack=this._handleBack.bind(this),this._handleDone=this._handleDone.bind(this),this._handleDelete=this._handleDelete.bind(this),this._handleAdd=this._handleAdd.bind(this),this._handleEdit=this._handleEdit.bind(this),this._handleAttachmentAdd=this._handleAttachmentAdd.bind(this),this._handleAttachmentUpdate=this._handleAttachmentUpdate.bind(this),this._handleAttachmentDelete=this._handleAttachmentDelete.bind(this),this.EditorPanel=this.EditorPanel.bind(this)}initialize(){const{view:e,snappingOptions:t}=this;this._snappingControls=new F({snappingOptions:t,view:e,visibleElements:{header:!1}}),this.own([i((()=>this.headingLevel),(e=>{this._featureForm.headingLevel=A(e),this._featureTemplates.headingLevel=A(e)}),r),this.viewModel.featureTemplatesViewModel.on("select",(({item:e})=>this.useDeprecatedCreateWorkflow?this.startCreateWorkflowAtFeatureCreation(e):this.startCreateFeaturesWorkflowAtFeatureCreation(e))),i((()=>this.viewModel.state),((e,t)=>{const s=this._stateStack.indexOf(e);-1===s?this._stateStack.push(t):this._stateStack.splice(s)})),i((()=>this.viewModel),(e=>{this._featureForm.viewModel=e?e.featureFormViewModel:null,this._attachments.viewModel=e?e.attachmentsViewModel:null,this._featureTemplates.viewModel=e?e.featureTemplatesViewModel:null,this._spinner.viewModel=e?e.spinnerViewModel:null}),r),i((()=>this.view),((e,t)=>{const s=`editor-${this.id}-spinner`;t&&t.ui.remove(this._spinner,s),e&&e.ui.add(this._spinner,{key:s,position:"manual"})}),r),n((()=>this.viewModel?.sketchViewModel),"create",(()=>{this.scheduleRender()})),n((()=>this.viewModel?.activeWorkflow),"cancel-request",(({controller:e})=>{const{messages:t,messagesCommon:s}=this;this._prompt={title:t.cancelRequestTitle,message:t.cancelRequestWarningMessage,context:"danger",actions:{primary:{label:s.form.yes,action:()=>{e.allow(),this._prompt=null}},secondary:{label:s.form.no,action:()=>(e.deny(),this._prompt=null)}}},this.scheduleRender()})),i((()=>this.supportingWidgetDefaults),(e=>{e&&(this._featureForm.set(e.featureForm),this._attachments.set(e.attachments),this._featureTemplates.set(e.featureTemplates),this.viewModel.sketchViewModel.set(e.sketch))}),r),i((()=>this._attachments?.error),(e=>{if(!e)return;const{messages:t,messagesCommon:s}=this;this._prompt={title:t.errorWarningTitle,message:e.message,context:"warning",actions:{primary:{label:s.form.ok,action:()=>{this._prompt=null}}}}})),i((()=>this.viewModel?.failures),(e=>{if(!e)return;const{messages:t}=this,[{error:s,retry:a,cancel:i}]=e;this._prompt={title:t.errorWarningTitle,message:P(t.errorWarningMessageTemplate,{errorMessage:s.message}),context:"warning",actions:{primary:{label:t.retry,action:()=>{a(),this._prompt=null}},secondary:{label:t.ignore,action:()=>(i(),this._prompt=null)}}}})),i((()=>this.viewModel?.state),(e=>{"awaiting-feature-to-update"===e&&(this._filterText=""),"awaiting-update-feature-candidate"===e&&(this._candidateCommitted=!1)})),i((()=>[this._attachments?.selectedFile,this._attachments?.submitting]),(()=>this.scheduleRender())),o((()=>!this.viewModel?.activeWorkflow),(()=>this._featureTemplates.filterText="")),n((()=>this.view),"key-down",(e=>{"Escape"===e.key&&this.viewModel?.activeWorkflow&&this._handleBack()}))])}destroy(){this._attachments.destroy(),this._featureForm.destroy(),this._featureTemplates.destroy(),this._snappingControls.destroy()}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-action.js"),import("@esri/calcite-components/dist/components/calcite-action-menu.js"),import("@esri/calcite-components/dist/components/calcite-button.js"),import("@esri/calcite-components/dist/components/calcite-flow.js"),import("@esri/calcite-components/dist/components/calcite-icon.js"),import("@esri/calcite-components/dist/components/calcite-loader.js"),import("@esri/calcite-components/dist/components/calcite-panel.js"),import("@esri/calcite-components/dist/components/calcite-popover.js"),import("@esri/calcite-components/dist/components/calcite-scrim.js")])}castVisibleElements(e){return{...x,...e}}startCreateWorkflowAtFeatureTypeSelection(){return b(D,"startCreateWorkflowAtFeatureTypeSelection","startCreateFeaturesWorkflowAtFeatureTypeSelection"),this.viewModel.startCreateWorkflowAtFeatureTypeSelection()}startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.viewModel.startCreateFeaturesWorkflowAtFeatureTypeSelection()}startCreateWorkflowAtFeatureCreation(e){return b(D,"startCreateWorkflowAtFeatureCreation","startCreateFeaturesWorkflowAtFeatureCreation"),this.viewModel.startCreateWorkflowAtFeatureCreation(e)}startCreateFeaturesWorkflowAtFeatureCreation(e){return this.viewModel.startCreateFeaturesWorkflowAtFeatureCreation(e)}startCreateWorkflowAtFeatureEdit(e){return b(D,"startCreateWorkflowAtFeatureEdit"),this.viewModel.startCreateWorkflowAtFeatureEdit(e)}startUpdateWorkflowAtFeatureSelection(){return this.viewModel.startUpdateWorkflowAtFeatureSelection()}startUpdateWorkflowAtMultipleFeatureSelection(e){return this.viewModel.startUpdateWorkflowAtMultipleFeatureSelection(e)}startUpdateWorkflowAtFeatureEdit(e){return this.viewModel.startUpdateWorkflowAtFeatureEdit(e)}deleteFeatureFromWorkflow(){return this.viewModel.deleteFeatureFromWorkflow()}cancelWorkflow(e){return this.viewModel.cancelWorkflow(e)}render(){const{_attachments:e,_prompt:t,viewModel:s}=this;if(!s)return E("div",{class:j.base});const{state:i}=s,n=a(t)?E("calcite-scrim",null,this.renderPrompt(t)):null;return E("div",{class:j.base},s.syncing||e.submitting?this.renderProgressBar():null,E("calcite-flow",null,this._stateStack.map((e=>this.renderState(e))),this.renderState(i)),n)}renderState(e){switch(e){case"disabled":break;case"ready":return this.renderLanding(e);case"awaiting-feature-creation-info":return this.renderTemplates(e);case"creating-features":case"editing-new-feature":case"editing-existing-feature":return this.renderAttributeEditing(e);case"awaiting-feature-to-update":return this.renderFeatureUpdating(e);case"awaiting-update-feature-candidate":return this.renderFeatureList(e);case"awaiting-feature-to-create":return this.renderFeatureCreation(e);case"adding-attachment":return this.renderAttachmentAdding(e);case"editing-attachment":return this.renderAttachmentEditing(e)}return E("div",null)}isPanelActive(e){return this.viewModel.state===e}renderTemplates(e){const{EditorPanel:t,headingLevel:s,messages:a,messagesCommon:i,_handleBack:n,_snappingControls:o,viewModel:{sketchViewModel:r}}=this;return E(t,{active:this.isPanelActive(e),key:"templates-panel",handleBack:n,heading:a.selectTemplate,headingLevel:s,messages:a,messagesCommon:i,sketchViewModel:r,snappingControls:o},E("div",{class:L},this._featureTemplates.render()))}renderAttributeEditing(e){const{activeWorkflow:t,EditorPanel:s,messages:a,messagesCommon:i,headingLevel:n,_handleBack:o,_snappingControls:r,viewModel:l}=this,{sketchViewModel:d}=l,c=l.featureFormViewModel;if("create-features"===t.type&&t.pendingFeatures.length<1)return this.renderFeatureCreation(e);const p="update"===t.type&&!t.data.edits.modified||l.syncing,h="update"===t.type?a.editFeature:a.createFeatures,m="update"===t.type?i.update:i.create,u="create-features"===t.type&&"create-new"===t.createFeatureState,g="update"===t.type&&t.data.editableItem.supports.includes("delete"),v="update"===t.type&&t.data.editableItem.hasAttachments,w=[{label:"create-features"===t.type&&t.numPendingFeatures>1?P(a.createFeaturesTemplate,{numFeatures:t.numPendingFeatures}):m,type:"primary",disabled:p,clickHandler:this._handleSave,width:g?"half":"full"}];return g&&w.push({label:i.delete,type:"tertiary",clickHandler:this._handleDelete,appearance:"outline",width:"half"}),E(s,{active:this.isPanelActive(e),key:"attribute-editing-panel",heading:h,headingLevel:n,handleBack:o,messages:a,messagesCommon:i,sketchViewModel:d,snappingControls:r},E("div",{class:L},E("div",{class:j.panelContentSection},E("div",{class:j.panelContentSectionGroup},c.inputFields.length>0?this._featureForm.render():this.renderMessage(P(a.clickToFinishTemplate,{button:m})),v?E("div",{key:"attachments"},E("div",null,a.attachments),this._attachments.render()):null),u?E("calcite-scrim",null):null)),this.renderFooterActions(w))}renderAttachmentAdding(e){const{_attachments:t,EditorPanel:s,_handleBack:a,headingLevel:i,messages:n,messagesCommon:o,_snappingControls:r,viewModel:{sketchViewModel:l}}=this,d=[{label:t.submitting?o.cancel:o.add,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentAdd,width:"full"}];return E(s,{active:this.isPanelActive(e),key:"attachment-adding-panel",heading:n.addAttachment,headingLevel:i,handleBack:a,messages:n,messagesCommon:o,sketchViewModel:l,snappingControls:r},E("div",{class:L},t.render()),this.renderFooterActions(d))}renderAttachmentEditing(e){const{_attachments:t,EditorPanel:s,_handleBack:a,headingLevel:i,messages:n,messagesCommon:o,_snappingControls:r,viewModel:{sketchViewModel:l}}=this,d=[{label:o.update,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentUpdate,width:"half"},{label:o.delete,disabled:t.submitting,type:"tertiary",clickHandler:this._handleAttachmentDelete,width:"half",appearance:"outline"}];return E(s,{active:this.isPanelActive(e),key:"attachment-editing-panel",heading:n.editAttachment,headingLevel:i,handleBack:a,messages:n,messagesCommon:o,sketchViewModel:l,snappingControls:r},E("div",{class:L},t.render()),this.renderFooterActions(d))}renderFeatureUpdating(e){const{EditorPanel:t,_handleBack:s,headingLevel:a,messages:i,messagesCommon:n,_snappingControls:o,viewModel:{sketchViewModel:r}}=this;return E(t,{active:this.isPanelActive(e),key:"feature-updating-panel",heading:i.selectFeature,headingLevel:a,handleBack:s,messages:i,messagesCommon:n,sketchViewModel:r,snappingControls:o},E("div",{class:B(L,j.panelContentMessage)},this.renderMessage(i.selectFeatureToEdit)))}renderMessage(e){return E("div",{class:j.message},e)}renderFeatureCreation(e){const{EditorPanel:t,_handleBack:s,headingLevel:a,messages:i,messagesCommon:n,_snappingControls:o,viewModel:r}=this,{sketchViewModel:l}=r,d=r.sketchViewModel,c=this._assertActiveCreateWorkflow().data.creationInfo.layer,p=d.canUndo()&&d.createGraphic?d.createGraphic:null,h=this._getSketchingTip(c.geometryType,p);return E(t,{active:this.isPanelActive(e),key:"feature-creation-panel",heading:i.placeFeature,headingLevel:a,handleBack:s,messages:i,messagesCommon:n,sketchViewModel:l,snappingControls:o},E("div",{class:B(L,j.panelContentMessage)},this.renderMessage(h)))}renderFooterActions(e){return e.map((({type:e,disabled:t,class:s,...a},i)=>this.renderButton({class:this.classes(j.controlButton,"secondary"===e?j.buttonSecondary:"tertiary"===e?j.buttonTertiary:null,t?j.buttonDisabled:null,s),disabled:t??!1,key:i,slot:"footer-actions",...a})))}renderPrompt({title:e,message:t,context:s,actions:a}){const i=!!a.secondary,n=E("calcite-button",{appearance:"solid",color:"danger"===s?"red":"blue",width:i?"half":"full",onclick:a.primary.action,key:"prompt-primary-button",afterCreate:U},a.primary.label),o=i?E("calcite-button",{appearance:"clear",color:"danger"===s?"red":"blue",width:"half",onclick:a.secondary.action,key:"prompt-secondary-button"},a.secondary.label):null;return E("div",{class:`${j.promptContainer}--${s}`},E("div",{class:j.promptHeader},E("calcite-icon",{icon:"exclamation-mark-triangle"}),E(M,{class:j.promptHeading,level:this.headingLevel},e)),E("div",{class:j.promptMessage},t),E("div",{class:j.promptDivider}),E("div",{class:j.promptActions},o,n))}renderProgressBar(){return E("div",{class:this.classes(j.progressBar),key:"progress-bar"})}renderButton(e){const{disabled:t,class:s,key:a,clickHandler:i,label:n,...o}=e;return E("calcite-button",{class:s,disabled:t,key:a,onclick:i,type:"button",...o},n)}renderLanding(e){const{EditorPanel:t,headingLevel:s,messages:a,messagesCommon:i,_snappingControls:n,viewModel:{sketchViewModel:o}}=this;return E(t,{active:this.isPanelActive(e),key:"landing-panel",heading:a.widgetLabel,headingLevel:s,showBackButton:!1,messages:a,messagesCommon:i,sketchViewModel:o,snappingControls:n},E("div",{class:L},E("div",{key:"edit-actions",class:j.panelContentSection},this.renderUpdateActions()),E("div",{key:"create-actions",class:j.panelContentSection},this.renderCreateActions())))}renderUpdateActions(){const{messages:e,messagesCommon:t}=this;return E("div",null,E(M,{level:A(this.headingLevel)},e.editFeatures),E("div",{class:j.updateFeaturesActionButtons},E("calcite-action",{text:t.select,textEnabled:!0,icon:"cursor",alignment:"start",class:j.updateFeaturesActionButtonsButton,onclick:this._handleEdit})))}renderCreateActions(){const{_featureTemplates:e,headingLevel:t,messages:s}=this;if(0!==e.viewModel.numberOfFeatureTemplates)return E("div",null,E(M,{level:A(t)},s.createFeatures),E("div",{key:"templates",class:j.featureTemplatesContainer},e.render()))}renderFeatureList(e){const{EditorPanel:t,_handleBack:s,headingLevel:a,messages:i,messagesCommon:n,messagesTemplates:o,_snappingControls:r,viewModel:{editableItems:l,sketchViewModel:d}}=this,c=this._assertActiveUpdateWorkflow().data.candidates,p=P(i.multipleFeaturesTemplate,{total:c.length}),h=new Map;let m=0;c.map((e=>({label:this._getLabel(e),id:e.attributes[e.layer.objectIdField],data:e}))).filter((e=>{const{label:t,data:s}=e,a=this._filterText.toLowerCase(),{title:i}=s.layer,n=this.viewModel.editableItems.find((e=>e.layer===s.layer));return n.supports.includes("update")&&(!a||t.toLowerCase().includes(a)||i.toLowerCase().includes(a))})).forEach((e=>{m++;const t=e.data.layer;h.has(t)?h.get(t).items.push(e):h.set(t,{id:`${t.id}`,label:t.title,items:[e]})}));const u=l.filter((({layer:e})=>h.has(e))).map((({layer:e})=>h.get(e))).toArray(),g=m>10||this._filterText.length>0;return E(t,{active:this.isPanelActive(e),key:"feature-list",heading:p,headingLevel:a,handleBack:s,messages:i,messagesCommon:n,sketchViewModel:d,snappingControls:r},E("div",{class:L},C({id:this.id,enableListScroll:!1,filterEnabled:g,filterText:this._filterText,items:u,messages:{filterPlaceholder:o.filterPlaceholder,noItems:o.noItems,noMatches:o.noMatches},onItemMouseEnter:({data:e})=>this._setCandidateFeature(e),onItemMouseLeave:()=>this._setCandidateFeature(null),onItemSelect:({data:e})=>this._setCandidateFeature(e,!0),onFilterChange:e=>this._filterText=e})))}EditorPanel(e,...t){const{active:s,handleBack:a,heading:i,headingLevel:n,key:o,messages:r,messagesCommon:l,showBackButton:d,sketchViewModel:c,snappingControls:p}=e;return E("calcite-panel",{bind:this,key:o,heading:i,headingLevel:n,showBackButton:d??!0,beforeBack:a??null,onCalcitePanelScroll:this._onSnappingPopoverPanelScroll},E("div",{class:j.panelToolbar},E("calcite-popover",{autoClose:s,afterCreate:this._afterSnappingPopoverCreated,afterUpdate:this._afterSnappingPopoverUpdated,bind:this,label:r.snappingSettings,heading:r.snappingSettings,"reference-element":`${o}__snappingButton`,"overlay-positioning":"fixed",placement:"bottom"},E("div",{class:j.snappingControlsPopover},p.render())),E("calcite-button",{id:`${o}__snappingButton`,text:r.snapping,appearance:"transparent",color:"neutral",alignment:"icon-end-space-between","icon-start":"vertex-gps","icon-end":"caret-down",width:"full",class:j.panelToolbarSnappingButton},r.snapping),this.visibleElements.undoRedoButtons?[E("calcite-button",{key:"undo-button",text:l.undo,appearance:"transparent",color:"neutral",alignment:"center","icon-start":"undo",scale:"l",disabled:!c.canUndo(),onclick:c.undo.bind(c)}),E("calcite-button",{key:"redo-button",text:l.redo,appearance:"transparent",color:"neutral",alignment:"center","icon-start":"redo",scale:"l",disabled:!c.canRedo(),onclick:c.redo.bind(c)})]:null),t)}_onSnappingPopoverPanelScroll(){this._snappingPopover?.open&&this._snappingPopover.toggle()}_afterSnappingPopoverCreated(e){this._snappingPopover=e}_afterSnappingPopoverUpdated(e){this._snappingPopover=e}_getSketchingTip(e,t){const{messages:s}=this;if("point"===e)return s.tips.clickToAddPoint;if("polygon"===e||"polyline"===e){if(!t)return s.tips.clickToStart;const a=t.geometry,i="polygon"===e?"rings":"paths",[n]=a[i];return"polygon"===e&&n<4?s.tips.clickToContinue:s.tips.clickToContinueThenDoubleClickToEnd}return s.tips.clickToAddFeature}_getLabel(e){const t=e.layer;if(!t)return null;const{objectIdField:s}=t,{attributes:a}=e,i=h(t);return i&&a[i]&&`${a[i]}`||P(this.messages.untitledFeatureTemplate,{id:a[s]})}_handleDelete(){const{messages:e,messagesCommon:t}=this;this._prompt={title:e.deleteWarningTitle,message:e.deleteWarningMessage,context:"danger",actions:{primary:{label:t.delete,action:()=>{this.viewModel.deleteFeatureFromWorkflow(),this._prompt=null}},secondary:{label:e.keepFeature,action:()=>this._prompt=null}}}}_handleSave(){const{featureFormViewModel:e}=this.viewModel;e.submit(),!e.submittable||e.validateContingencyConstraints(e.getValues(),{includeIncompleteViolations:!0}).length>0||this.viewModel.activeWorkflow.commit()}_handleAttachmentAdd(){const{_attachments:e}=this,{activeWorkflow:t}=this.viewModel;e.addAttachment().then((()=>t.previous()))}_handleAttachmentUpdate(){const{_attachments:e}=this,{activeWorkflow:t}=this.viewModel;e.updateAttachment().then((()=>t.previous()))}_handleAttachmentDelete(){const{messages:e,messagesCommon:t}=this;this._prompt={title:e.deleteAttachmentWarningTitle,message:e.deleteAttachmentWarningMessage,context:"danger",actions:{primary:{label:t.delete,action:()=>{const{_attachments:e}=this,{activeWorkflow:t}=this.viewModel;e.deleteAttachment(e.viewModel.activeAttachmentInfo).then((()=>{t.previous(),this._prompt=null}))}},secondary:{label:e.keepAttachment,action:()=>this._prompt=null}}}}_handleAdd(){this.viewModel.canCreate}_handleEdit(){this.viewModel.canUpdate&&this.viewModel.startUpdateWorkflowAtFeatureSelection()}_handleDone(){this.viewModel.cancelWorkflow({force:!0})}async _handleBack(){const{messages:e}=this,t=this.activeWorkflow,s=()=>{t.hasPreviousStep?t.previous({cancelCurrentStep:!0}):this.viewModel.cancelWorkflow({force:!0})};if("create"===t.type||"create-features"===t.type&&t.numPendingFeatures>0||"editing-existing-feature"===t.stepId&&t.data.edits.modified){const{type:a}=t,i="create"===a?e.cancelAddWarningMessage:e.cancelEditWarningMessage,n="create"===a?e.cancelAddTitle:e.cancelEditTitle,o="create"===a?e.continueAdding:e.continueEditing,r="create"===a?e.discardFeature:e.discardEdits;throw this._prompt={title:n,message:i,context:"danger",actions:{primary:{label:r,action:()=>{s(),this._prompt=null}},secondary:{label:o,action:()=>this._prompt=null}}},this.scheduleRender(),new Error}s()}_assertActiveCreateWorkflow(){const{type:e}=this.viewModel.activeWorkflow;if("create"===e||"create-features"===e)return this.viewModel.activeWorkflow;throw Error("Expected activeWorkflow to be instance of CreateWorkflow or CreateFeaturesWorkflow")}_assertActiveUpdateWorkflow(){if("update"===this.viewModel.activeWorkflow.type)return this.viewModel.activeWorkflow;throw Error("Expected activeWorkflow to be an UpdateWorkflow")}};e([c()],I.prototype,"_attachments",void 0),e([l("viewModel.activeWorkflow")],I.prototype,"activeWorkflow",void 0),e([l("viewModel.allowedWorkflows")],I.prototype,"allowedWorkflows",void 0),e([c()],I.prototype,"useDeprecatedCreateWorkflow",void 0),e([c()],I.prototype,"headingLevel",void 0),e([c()],I.prototype,"iconClass",void 0),e([c({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],I.prototype,"label",void 0),e([l("viewModel.labelOptions")],I.prototype,"labelOptions",void 0),e([l("viewModel.layerInfos")],I.prototype,"layerInfos",void 0),e([c(),T("esri/widgets/Editor/t9n/Editor")],I.prototype,"messages",void 0),e([c(),T("esri/t9n/common")],I.prototype,"messagesCommon",void 0),e([c(),T("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],I.prototype,"messagesTemplates",void 0),e([l("viewModel.snappingOptions")],I.prototype,"snappingOptions",void 0),e([l("viewModel.tooltipOptions")],I.prototype,"tooltipOptions",void 0),e([c()],I.prototype,"supportingWidgetDefaults",void 0),e([l("viewModel.view")],I.prototype,"view",void 0),e([c(),S(["workflow-cancel","workflow-commit"])],I.prototype,"viewModel",void 0),e([c()],I.prototype,"visibleElements",void 0),e([d("visibleElements")],I.prototype,"castVisibleElements",null),e([W()],I.prototype,"_handleDelete",null),e([W()],I.prototype,"_handleAttachmentAdd",null),e([W()],I.prototype,"_handleAttachmentUpdate",null),e([W()],I.prototype,"_handleAttachmentDelete",null),e([W()],I.prototype,"_handleAdd",null),e([W()],I.prototype,"_handleEdit",null),e([W()],I.prototype,"_handleDone",null),I=e([p(V)],I);const O=I;export{O as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import"../../intl.js";import n from"../../core/Evented.js";import{HandleOwnerMixin as i}from"../../core/HandleOwner.js";import s from"../../core/Logger.js";import{destroyMaybe as o,isNone as r,isSome as a}from"../../core/maybe.js";import{EsriPromiseMixin as l}from"../../core/Promise.js";import{watch as u}from"../../core/reactiveUtils.js";import{ReentrantObjectPool as c}from"../../core/ReentrantObjectPool.js";import{property as d}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as p}from"../../core/accessorSupport/decorators/subclass.js";import h from"../../form/FormTemplate.js";import f from"../../layers/support/ContingentValue.js";import m from"../../layers/support/LayerContingentValuesCache.js";import{loadArcade as g}from"../../support/arcadeOnDemand.js";import y from"./InputField.js";import _ from"./InputFieldGroup.js";import{onLocaleChange as F}from"../../intl/locale.js";import{fetchMessageBundle as C}from"../../intl/messages.js";const v=new t({attributes:{}}),b="esri.widgets.FeatureForm.FeatureFormViewModel",E=s.getLogger(b),V=["editable","required","value","visibility"],j="#JSAPI_CONTINGENT_VALUE_EMPTY_HASH",w="#JSAPI_CONTINGENT_VALUE_ANY_HASH",I="#JSAPI_CONTINGENT_VALUE_NULL_HASH";let x=class extends(i(l(n.EventedAccessor))){constructor(e){super(e),this._arcade=null,this._compiledExpressionLookup=new Map,this._expressionLookup=new Map,this._contingentValuesCache=null,this._fieldPool=new c(y,(e=>this.handles.add(u((()=>e.value),(()=>{e.isUsingValueExpression&&this._afterValueChange(e)})),e.id)),(({id:e})=>this.handles.remove(e))),this._fieldGroupPool=new c(_),this._featureClone=v.clone(),this._initialFeature=v.clone(),this._arcadeGeometryOperationsEnabled=!1,this._inputFieldCache=[],this.contingencyConstraintViolations=new Map,this.messages=null,this.strict=!1}initialize(){const e=async()=>this.messages=await C("esri/widgets/FeatureForm/t9n/FeatureForm");e();const t=u((()=>this.layer),(e=>{"feature"===e?.type&&this.addResolvingPromise(m.createLoadedLayerContingentValuesCache(e).then((e=>{this._contingentValuesCache=e,this.notifyChange("fieldsWithContingentValues")})))}),{initial:!0});this.handles.add([F(e),t])}destroy(){this.feature=null,this.layer=null,this._contingentValuesCache=o(this._contingentValuesCache),this._fieldPool.destroy(),this._fieldGroupPool.destroy()}get allInputFields(){return this.inputFields.reduce(((e,t)=>A(t)?[...e,...t.inputFields]:[...e,t]),[])}get _layerFieldsByName(){return new Map(this.layer.fields.map((e=>[e.name,e])))}get feature(){return this._get("feature")}set feature(e){this._featureClone=e?e.clone():v.clone(),this._initialFeature=this._featureClone.clone(),this.contingencyConstraintViolations.clear(),this._clearInputFieldCache(),this._set("feature",e)}get fieldsWithContingentValues(){if(r(this._contingentValuesCache))return new Set;const e=this._contingentValuesCache.fieldGroups.flatMap((e=>e.fields));return new Set(e)}get formTemplate(){return this.layer&&"formTemplate"in this.layer?this.layer.formTemplate:null}set formTemplate(e){null!=e?this._override("formTemplate",e):this._clearOverride("formTemplate")}get inputFields(){const{_arcade:e,_featureClone:t,_initialFeature:n,_inputFieldCache:i,formTemplate:s,messages:o,layer:r,state:l}=this;if("ready"!==l)return[];const u={arcade:e,feature:t,initialFeature:n,layer:r,messages:o},c=a(s)&&s.elements.length>0?this._updateInputFieldsFromElements(i,s.elements,u):this._updateInputFieldsFromLayerFields(i,r?.fields,u);return this._inputFieldCache=c,c}get joinedContingentValues(){return this._joinContingentValues()}get layer(){return this.feature?.sourceLayer&&"applyEdits"in this.feature.sourceLayer?this.feature.sourceLayer:null}set layer(e){e?this._override("layer",e):this._clearOverride("layer")}get state(){return this.messages&&this.get("layer.loaded")?"ready":"disabled"}get submittable(){return!!this.valid||this.allInputFields.filter((e=>!e.valid)).every((({submittable:e})=>e))}get valid(){const e=this.allInputFields;return e.length>0&&e.every((({valid:e})=>e))}findField(e){return this.allInputFields.find((t=>t.name===e))}getValue(e){const{_featureClone:t,layer:n}=this,i=!!n?.getField(e);return t.getAttribute(e)??(i?null:void 0)}setValue(e,t){const{_featureClone:n,strict:i}=this,s=this.findField(e);t=""===t?null:t,s&&n.getAttribute(e)!==t&&(s.value=t,i&&!s.valid||this._afterValueChange(s))}getValues(){return{...this._featureClone.attributes}}submit(){const e=this.allInputFields,t=new Set(e.filter((e=>e.valid)).map((({name:e})=>e))),n=e.filter((e=>!e.valid)).map((({name:e})=>e)),i=this.getValues();if(this.validateContingencyConstraints(i,{includeIncompleteViolations:!0}).length>0)for(const[s,o]of this.contingencyConstraintViolations.entries())"error"===o.type&&(t.delete(s),n.push(s));this.emit("submit",{valid:[...t],invalid:n,values:i})}validateContingencyConstraints(e,t){const{_contingentValuesCache:n}=this,i=new Map;if(this.contingencyConstraintViolations=i,r(n))return[];const{invalid:s,incomplete:o}=n.validateContingencyConstraints(e),a=[...s,...t?.includeIncompleteViolations?o:[]];for(const r of a)for(const e of r.fieldGroup.fields)i.set(e,r);return a}_emitChangeEvent({name:e,valid:t,value:n}){this.emit("value-change",{layer:this.layer,feature:this.feature,fieldName:e,value:n,valid:t})}_updateInputFieldsFromElements(e,t,n){const i=new Map;for(const o of e)if(A(o)){M(i,o.groupElement,o);for(const e of o.inputFields)M(i,e.fieldElement,e)}else M(i,o.fieldElement,o);const s=this._updateInputFieldsRecursive(i,t.filter(this._isSupportedElement),n);for(const[o,r]of i.entries())i.delete(o),r.destroy();return s}_updateInputFieldsRecursive(e,t,n,i=null){const s=[];for(const o of t){const t=e.has(o),r=t?e.get(o):T(o)?this._makeInputFieldGroupFromGroupElement(o,n):this._makeInputFieldFromFieldElement(o,n,i);if(s.push(r),t&&(e.delete(o),r.set(n)),T(o)){const t=o.elements.filter((e=>this._isSupportedElement(e)));r.inputFields=this._updateInputFieldsRecursive(e,t,n,r)}}return s}_updateInputFieldsFromLayerFields(e,t,n){if(!Array.isArray(t))return E.warn(b,"No attribute fields found."),[];const i=new Map;for(const u of e)if(A(u)){for(const e of u.inputFields)e.destroy();u.inputFields.length=0,u.destroy()}else i.set(u.field,u);const s=[],{feature:o,initialFeature:r,layer:a,messages:l}=n;for(const u of t){const e=i.get(u)??new y({field:u,feature:o,initialFeature:r,layer:a,messages:l,value:o.getAttribute(u.name)});e.set({fieldElement:null,requiredFunction:null,visibilityFunction:null,valueFunction:null,editableFunction:null}),s.push(e),i.delete(u)}for(const[u,c]of i.entries())i.delete(u),c.destroy();return s}_makeInputFieldFromFieldElement(e,t,n=null){const{arcade:i,feature:s,initialFeature:o,layer:r,messages:l}=t,c=new y({fieldElement:e,field:this._layerFieldsByName.get(e.fieldName),requiredFunction:this._getCompiledExpression(e.requiredExpression),visibilityFunction:this._getCompiledExpression(e.visibilityExpression),valueFunction:this._getCompiledExpression(e.valueExpression),editableFunction:this._getCompiledExpression(e.editableExpression),group:n,arcade:i,feature:s,initialFeature:o,layer:r,messages:l,value:s.getAttribute(e.fieldName)});return c.own(u((()=>c.fieldElement),(e=>a(e)&&e.own(V.map((t=>u((()=>e[`${t}Expression`]),(async e=>{e&&""!==e&&(c[`${t}Function`]=await this._getOrMakeCompiledExpression(e),c.arcade=this._arcade)}),{initial:!0,sync:!0}))))),{initial:!0,sync:!0})),c}_makeInputFieldGroupFromGroupElement(e,t){const{arcade:n,feature:i}=t,s=new _({groupElement:e,visibilityFunction:this._getCompiledExpression(e.visibilityExpression),inputFields:[],arcade:n,feature:i});return s.own(u((()=>s.groupElement),(e=>a(e)&&e.own(u((()=>e.visibilityExpression),(async e=>{e&&""!==e&&(s.visibilityFunction=await this._getOrMakeCompiledExpression(e),s.arcade=this._arcade)}),{initial:!0}))),{initial:!0})),s}_clearInputFieldCache(){for(const e of this._inputFieldCache)e.destroy();this._inputFieldCache=[]}_afterValueChange(e){const{name:t,value:n}=e;if(this.get("layer.typeIdField")===e.name&&"types"in this.layer){const e=new Set;this.layer.types.forEach((t=>Object.keys(t.domains).forEach((t=>e.add(t))))),e.forEach((e=>{const t=this.findField(e);t&&t.notifyChange("domain")}))}this._featureClone.setAttribute(t,n),this.notifyChange("inputFields"),this._emitChangeEvent(e)}_getCompiledExpression(e){return this._compiledExpressionLookup.get(this._expressionLookup.get(e))}async _getOrMakeCompiledExpression(e){{if(r(e)||""===e)return null;const t=this._expressionLookup.get(e)??this._addToExpressionLookup(e);if(this._compiledExpressionLookup.has(t))return this._compiledExpressionLookup.get(t);this._arcade||(this._arcade=await g());const n=this._arcade.arcadeUtils;return!this._arcadeGeometryOperationsEnabled&&n.hasGeometryOperations(t)&&(await n.enableGeometryOperations(),this._arcadeGeometryOperationsEnabled=!0),this._addToCompiledExpressionLookup(t)}}_addToCompiledExpressionLookup(e){const{_arcade:{arcadeUtils:t},_compiledExpressionLookup:n}=this,i=t.createFunction(e);return n.set(e,i),i}_addToExpressionLookup(e){const{_expressionLookup:t,formTemplate:n}=this,i=(a(n)&&a(n.expressionInfos)?Object.values(n.expressionInfos).find((t=>t.name===e)):null)?.expression??e;return t.set(e,i),e!==i&&t.set(i,i),i}_isSupportedElement(e){return"field"===e.type||"group"===e.type||(E.warn("form-info::unsupported-element-type","Only element types 'field' and 'group' are supported",`Element ${e.label} has unsupported type '${e.type}'`),!1)}_joinContingentValues(){const e=this._contingentValuesCache;if(r(e))return[];const t="typeIdField"in this.layer?this.layer.typeIdField:null,n=t?this.getValue(t):null,i=[];for(const r of e.fieldGroups){const{contingencies:e,fields:t,name:s}=r,o=[];for(const i of e)i.isRetired||a(i.subtype)&&i.subtype.code!==n||o.push({values:i.values});o.length>0&&i.push({name:s,fields:t,contingencies:o})}const[s,o]=this._generateJoinPlan(i);return[...s.flatMap((e=>this._joinFieldGroupContingencies(e))),...o.flatMap((e=>e.contingencies))]}_generateJoinPlan(e){const t=new Map,n=[],i=new Set;for(const l of e)for(const e of l.fields)if(t.has(e)){const s=t.get(e),o=l,r=[s.name,o.name].sort().join("|");if(i.has(r))continue;n.push([s,o]),i.add(r),t.set(e,o)}else t.set(e,l);const s=new Set(n.flat()),o=new Set(e);for(const l of s)o.delete(l);const r=new Map,a=new Map;for(const l of new Set(n.flat())){const e=Symbol(l.name);r.set(e,new Set([l])),a.set(l,e)}for(const[l,u]of n){const e=a.get(l),t=a.get(u);if(e===t)continue;const n=r.get(e),i=r.get(t);for(const s of i)n.add(s),a.set(s,e);r.delete(t)}return[[...r.values()].map((e=>[...e])),[...o]]}_joinFieldGroupContingencies(e){const t=e.slice(),n=t.shift();let i=t.shift(),s=this._generateJoinKey(n.fields,i.fields),o=new Set([...n.fields,...i.fields]),l=new Map;for(const r of n.contingencies){const[e]=this._hashContingency(r,s.codedValueFields,!0);l.has(e)?l.get(e).push(r):l.set(e,[r])}for(;t.length>0;){const e=new Map,n=t.shift(),a=this._generateJoinKey(o,n.fields);for(const t of i.contingencies){const[n,i]=this._hashContingency(t,s.codedValueFields),o=i?this._findMatchingContingenciesWithAnyHashMask(l,n):l.get(n);if(l.has(w)&&o.push(...this._findMatchingContingenciesContainingAny(t,l.get(w),s.codedValueFields)),!r(o))for(const l of o){const n=s.rangeFields.length>0?this._joinContingenciesWithRangeDomains(l,t,s.rangeFields):this._joinContingencies(l,t);if(r(n))break;const[i]=this._hashContingency(n,a.codedValueFields,!0);e.has(i)?e.get(i).push(n):e.set(i,[n])}}l=e,i=n,s=a,o=new Set([...o,...i.fields])}const u=[];for(const c of i.contingencies){const[e,t]=this._hashContingency(c,s.codedValueFields),n=t?this._findMatchingContingenciesWithAnyHashMask(l,e):l.get(e);if(l.has(w)&&n.push(...this._findMatchingContingenciesContainingAny(c,l.get(w),s.codedValueFields)),!r(n))for(const i of n){const e=s.rangeFields.length>0?this._joinContingenciesWithRangeDomains(i,c,s.rangeFields):this._joinContingencies(i,c);a(e)&&u.push(e)}}return u}_joinContingencies(e,t){const n={values:{...e.values,...t.values}};for(const[i,s]of Object.entries(n.values))"any"===s.objectType&&a(e.values[i])&&(n.values[i]=e.values[i]);return n}_joinContingenciesWithRangeDomains(e,t,n){const i=this._joinContingencies(e,t);for(const s of n){const n=e.values[s],o=t.values[s],{leftIsNull:r,rightIsNull:a,bothAreNull:l,leftIsAny:u,rightIsAny:c,bothAreAny:d,leftIsRange:p,rightIsRange:h}=this._compareObjectTypes(n.objectType,o.objectType);if(l||d)continue;if(r&&c||a&&u){i.values[s]=new f({objectType:"null"});continue}if(r&&h||a&&p)return null;u?(n.minValue=-1/0,n.maxValue=1/0):c&&(o.minValue=-1/0,o.maxValue=1/0);const m=Math.max(n.minValue,o.minValue),g=Math.min(n.maxValue,o.maxValue);if(m>g)return null;i.values[s]=new f({objectType:"range",minValue:m,maxValue:g})}return i}_findMatchingContingenciesContainingAny(e,t,n){return t.filter((t=>n.every((n=>{const i=t.values[n],s=e.values[n];return"any"===i.objectType||"any"===s.objectType||i.codedValue?.code===s.codedValue?.code}))))}_findMatchingContingenciesWithAnyHashMask(e,t){const n=RegExp(`${t}$`),i=[];for(const[s,o]of e){if(s===w)break;n.test(s)&&i.push(...o)}return i}_generateJoinKey(e,t){const n=Array.isArray(e)?new Set(e):e,i=Array.isArray(t)?new Set(t):t,s=n.size<i.size?n:i,o=s===n?i:n,a=new Set,l=new Set;for(const u of s)if(o.has(u)){const e=this.layer.getFieldDomain(u,{feature:this.feature});if(r(e))continue;switch(e.type){case"coded-value":a.add(u);break;case"range":l.add(u)}}return{codedValueFields:[...a],rangeFields:[...l]}}_hashContingency(e,t,n=!1){if(t.length<1)return[j,!1];const i=[];let s=!1;for(const o of t){const t=e.values[o];if("any"===t.objectType){if(n)return[w,!0];s=!0,i.push(`${o}:.*`)}else"null"===t.objectType?i.push(`${o}:${I}`):i.push(`${o}:${t.codedValue?.code}`)}return[i.sort().join("&"),s]}_compareObjectTypes(e,t){return{leftIsNull:"null"===e,rightIsNull:"null"===t,bothAreNull:"null"===e&&"null"===t,leftIsAny:"any"===e,rightIsAny:"any"===t,bothAreAny:"any"===e&&"any"===t,leftIsRange:"range"===e,rightIsRange:"range"===t}}};e([d({readOnly:!0})],x.prototype,"allInputFields",null),e([d()],x.prototype,"_layerFieldsByName",null),e([d()],x.prototype,"_inputFieldCache",void 0),e([d()],x.prototype,"contingencyConstraintViolations",void 0),e([d()],x.prototype,"feature",null),e([d()],x.prototype,"fieldsWithContingentValues",null),e([d({type:h})],x.prototype,"formTemplate",null),e([d({readOnly:!0})],x.prototype,"inputFields",null),e([d()],x.prototype,"joinedContingentValues",null),e([d()],x.prototype,"layer",null),e([d()],x.prototype,"messages",void 0),e([d()],x.prototype,"state",null),e([d()],x.prototype,"strict",void 0),e([d()],x.prototype,"submittable",null),e([d()],x.prototype,"valid",null),e([d()],x.prototype,"getValues",null),e([d()],x.prototype,"submit",null),x=e([p(b)],x);const A=e=>!!e.inputFields,T=e=>"group"===e.type,M=(e,t,n)=>{a(t)&&e.set(t,n)},k=x;export{k as default};
|
|
5
|
+
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import"../../intl.js";import i from"../../core/Evented.js";import{HandleOwnerMixin as n}from"../../core/HandleOwner.js";import{makeHandle as s}from"../../core/handleUtils.js";import o from"../../core/Logger.js";import{destroyMaybe as r,isNone as a,isSome as l}from"../../core/maybe.js";import{EsriPromiseMixin as u}from"../../core/Promise.js";import{watch as c}from"../../core/reactiveUtils.js";import{property as p}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as d}from"../../core/accessorSupport/decorators/subclass.js";import h from"../../form/FormTemplate.js";import f from"../../layers/support/ContingentValue.js";import m from"../../layers/support/LayerContingentValuesCache.js";import{loadArcade as g}from"../../support/arcadeOnDemand.js";import y from"./InputField.js";import _ from"./InputFieldGroup.js";import{onLocaleChange as F}from"../../intl/locale.js";import{fetchMessageBundle as C}from"../../intl/messages.js";const v=new t({attributes:{}}),b="esri.widgets.FeatureForm.FeatureFormViewModel",E=o.getLogger(b),V=["editable","required","value","visibility"],x="#JSAPI_CONTINGENT_VALUE_EMPTY_HASH",j="#JSAPI_CONTINGENT_VALUE_ANY_HASH",w="#JSAPI_CONTINGENT_VALUE_NULL_HASH";let I=class extends(n(u(i.EventedAccessor))){constructor(e){super(e),this._arcade=null,this._compiledExpressionLookup=new Map,this._expressionLookup=new Map,this._expressionInvalidationCallbacks=new Set,this._contingentValuesCache=null,this._featureClone=v.clone(),this._initialFeature=v.clone(),this._arcadeGeometryOperationsEnabled=!1,this._inputFieldCache=[],this.contingencyConstraintViolations=new Map,this.messages=null,this.strict=!1}initialize(){const e=async()=>this.messages=await C("esri/widgets/FeatureForm/t9n/FeatureForm");e();const t=c((()=>this.layer),(e=>{"feature"===e?.type&&this.addResolvingPromise(m.createLoadedLayerContingentValuesCache(e).then((e=>{this._contingentValuesCache=e,this.notifyChange("fieldsWithContingentValues")})))}),{initial:!0});this.handles.add([F(e),t])}destroy(){this.feature=null,this.layer=null,this._contingentValuesCache=r(this._contingentValuesCache)}get allInputFields(){return this.inputFields.reduce(((e,t)=>T(t)?[...e,...t.inputFields]:[...e,t]),[])}get _layerFieldsByName(){return new Map(this.layer.fields.map((e=>[e.name,e])))}get feature(){return this._get("feature")}set feature(e){this._featureClone=e?e.clone():v.clone(),this._initialFeature=this._featureClone.clone(),this.contingencyConstraintViolations.clear(),this._clearInputFieldCache(),this._set("feature",e)}get fieldsWithContingentValues(){if(a(this._contingentValuesCache))return new Set;const e=this._contingentValuesCache.fieldGroups.flatMap((e=>e.fields));return new Set(e)}get formTemplate(){return this.layer&&"formTemplate"in this.layer?this.layer.formTemplate:null}set formTemplate(e){null!=e?this._override("formTemplate",e):this._clearOverride("formTemplate")}get inputFields(){const{_arcade:e,_featureClone:t,_initialFeature:i,_inputFieldCache:n,formTemplate:s,messages:o,layer:r,state:a,spatialReference:u}=this;if("ready"!==a)return[];const c={arcade:e,feature:t,initialFeature:i,layer:r,messages:o,expressionTrackingProvider:{registerExpression:this._registerExpression.bind(this)},spatialReference:u},p=l(s)&&s.elements.length>0?this._updateInputFieldsFromElements(n,s.elements,c):this._updateInputFieldsFromLayerFields(n,r?.fields,c);return this._inputFieldCache=p,p}get joinedContingentValues(){return this._joinContingentValues()}get layer(){return this.feature?.sourceLayer&&"applyEdits"in this.feature.sourceLayer?this.feature.sourceLayer:null}set layer(e){e?this._override("layer",e):this._clearOverride("layer")}get spatialReference(){return this.layer?.spatialReference||null}set spatialReference(e){void 0===e?this._clearOverride("spatialReference"):this._override("spatialReference",e)}get state(){return this.messages&&this.get("layer.loaded")?"ready":"disabled"}get submittable(){return!!this.valid||this.allInputFields.filter((e=>!e.valid)).every((({submittable:e})=>e))}get valid(){const e=this.allInputFields;return e.length>0&&e.every((({valid:e})=>e))}findField(e){return this.allInputFields.find((t=>t.name===e))}getValue(e){const{_featureClone:t,layer:i}=this,n=!!i?.getField(e);return t.getAttribute(e)??(n?null:void 0)}setValue(e,t){const{_featureClone:i,strict:n}=this,s=this.findField(e);t=""===t?null:t,s&&i.getAttribute(e)!==t&&(s.value=t,n&&!s.valid||this._afterValueChange(s))}getValues(){return{...this._featureClone.attributes}}submit(){const e=this.allInputFields,t=new Set(e.filter((e=>e.valid)).map((({name:e})=>e))),i=e.filter((e=>!e.valid)).map((({name:e})=>e)),n=this.getValues();if(this.validateContingencyConstraints(n,{includeIncompleteViolations:!0}).length>0)for(const[s,o]of this.contingencyConstraintViolations.entries())"error"===o.type&&(t.delete(s),i.push(s));this.emit("submit",{valid:[...t],invalid:i,values:n})}validateContingencyConstraints(e,t){const{_contingentValuesCache:i}=this,n=new Map;if(this.contingencyConstraintViolations=n,a(i))return[];const{invalid:s,incomplete:o}=i.validateContingencyConstraints(e),r=[...s,...t?.includeIncompleteViolations?o:[]];for(const a of r)for(const e of a.fieldGroup.fields)n.set(e,a);return r}_emitChangeEvent({name:e,valid:t,value:i}){this.emit("value-change",{layer:this.layer,feature:this.feature,fieldName:e,value:i,valid:t})}_updateInputFieldsFromElements(e,t,i){const n=new Map;for(const o of e)if(T(o)){A(n,o.groupElement,o);for(const e of o.inputFields)A(n,e.fieldElement,e)}else A(n,o.fieldElement,o);const s=this._updateInputFieldsRecursive(n,t.filter(this._isSupportedElement),i);for(const[o,r]of n.entries())n.delete(o),r.destroy();return s}_updateInputFieldsRecursive(e,t,i,n=null){const s=[];for(const o of t){const t=e.has(o),r=t?e.get(o):k(o)?this._makeInputFieldGroupFromGroupElement(o,i):this._makeInputFieldFromFieldElement(o,i,n);if(s.push(r),t)if(e.delete(o),T(r)){const{arcade:e,feature:t,expressionTrackingProvider:n,spatialReference:s}=i;r.set({arcade:e,feature:t,expressionTrackingProvider:n,spatialReference:s})}else r.set(i);if(k(o)){const t=o.elements.filter((e=>this._isSupportedElement(e)));r.inputFields=this._updateInputFieldsRecursive(e,t,i,r)}}return s}_updateInputFieldsFromLayerFields(e,t,i){if(!Array.isArray(t))return E.warn(b,"No attribute fields found."),[];const n=new Map;for(const c of e)if(T(c)){for(const e of c.inputFields)e.destroy();c.inputFields.length=0,c.destroy()}else n.set(c.field,c);const s=[],{feature:o,initialFeature:r,layer:a,messages:l,spatialReference:u}=i;for(const c of t){const e=n.get(c)??new y({field:c,feature:o,initialFeature:r,layer:a,messages:l,spatialReference:u,value:o.getAttribute(c.name)});e.set({fieldElement:null,requiredFunction:null,visibilityFunction:null,valueFunction:null,editableFunction:null}),s.push(e),n.delete(c)}for(const[c,p]of n.entries())n.delete(c),p.destroy();return s}_makeInputFieldFromFieldElement(e,t,i=null){const{arcade:n,expressionTrackingProvider:o,feature:r,initialFeature:a,layer:u,messages:p,spatialReference:d}=t,h=new y({fieldElement:e,field:this._layerFieldsByName.get(e.fieldName),requiredFunction:this._getCompiledExpression(e.requiredExpression),visibilityFunction:this._getCompiledExpression(e.visibilityExpression),valueFunction:this._getCompiledExpression(e.valueExpression),editableFunction:this._getCompiledExpression(e.editableExpression),group:i,arcade:n,expressionTrackingProvider:o,feature:r,initialFeature:a,layer:u,messages:p,spatialReference:d,value:r.getAttribute(e.fieldName)}),f=`watch-expression-field-${h.id}`,m=c((()=>h.fieldElement),(e=>{this.handles.remove(f),l(e)&&this.handles.add(V.map((t=>c((()=>e[`${t}Expression`]),(async e=>{e&&""!==e&&(h[`${t}Function`]=await this._getOrMakeCompiledExpression(e),h.arcade=this._arcade)}),{initial:!0,sync:!0}))),f)}),{initial:!0,sync:!0}),g=s((()=>this.handles.remove(f))),_=c((()=>h.value),(()=>this._afterValueChange(h)));return h.own([m,g,_]),h}_makeInputFieldGroupFromGroupElement(e,t){const{arcade:i,feature:n,expressionTrackingProvider:s,spatialReference:o}=t,r=new _({groupElement:e,visibilityFunction:this._getCompiledExpression(e.visibilityExpression),inputFields:[],arcade:i,feature:n,expressionTrackingProvider:s,spatialReference:o});return r.own(c((()=>r.groupElement),(e=>l(e)&&e.own(c((()=>e.visibilityExpression),(async e=>{e&&""!==e&&(r.visibilityFunction=await this._getOrMakeCompiledExpression(e),r.arcade=this._arcade)}),{initial:!0}))),{initial:!0})),r}_clearInputFieldCache(){for(const e of this._inputFieldCache)e.destroy();this._inputFieldCache=[]}_afterValueChange(e){const{name:t,value:i}=e;if(this.get("layer.typeIdField")===t&&"types"in this.layer){const e=new Set;this.layer.types.forEach((t=>Object.keys(t.domains).forEach((t=>e.add(t))))),e.forEach((e=>{const t=this.findField(e);t&&t.notifyChange("domain")}))}this._featureClone.setAttribute(t,i);for(const n of this._expressionInvalidationCallbacks)n();this._emitChangeEvent(e)}_registerExpression(e){const{_expressionInvalidationCallbacks:t}=this;return t.add(e),s((()=>t.delete(e)))}_getCompiledExpression(e){return this._compiledExpressionLookup.get(this._expressionLookup.get(e))}async _getOrMakeCompiledExpression(e){{if(a(e)||""===e)return null;const t=this._expressionLookup.get(e)??this._addToExpressionLookup(e);if(this._compiledExpressionLookup.has(t))return this._compiledExpressionLookup.get(t);this._arcade||(this._arcade=await g());const i=this._arcade.arcadeUtils;return!this._arcadeGeometryOperationsEnabled&&i.hasGeometryOperations(t)&&(await i.enableGeometryOperations(),this._arcadeGeometryOperationsEnabled=!0),this._addToCompiledExpressionLookup(t)}}_addToCompiledExpressionLookup(e){const{_arcade:{arcadeUtils:t},_compiledExpressionLookup:i}=this,n=t.createFunction(e);return i.set(e,n),n}_addToExpressionLookup(e){const{_expressionLookup:t,formTemplate:i}=this,n=(l(i)&&l(i.expressionInfos)?Object.values(i.expressionInfos).find((t=>t.name===e)):null)?.expression??e;return t.set(e,n),e!==n&&t.set(n,n),n}_isSupportedElement(e){return"field"===e.type||"group"===e.type||(E.warn("form-info::unsupported-element-type","Only element types 'field' and 'group' are supported",`Element ${e.label} has unsupported type '${e.type}'`),!1)}_joinContingentValues(){const e=this._contingentValuesCache;if(a(e))return[];const t="typeIdField"in this.layer?this.layer.typeIdField:null,i=t?this.getValue(t):null,n=[];for(const r of e.fieldGroups){const{contingencies:e,fields:t,name:s}=r,o=[];for(const n of e)n.isRetired||l(n.subtype)&&n.subtype.code!==i||o.push({values:n.values});o.length>0&&n.push({name:s,fields:t,contingencies:o})}const[s,o]=this._generateJoinPlan(n);return[...s.flatMap((e=>this._joinFieldGroupContingencies(e))),...o.flatMap((e=>e.contingencies))]}_generateJoinPlan(e){const t=new Map,i=[],n=new Set;for(const l of e)for(const e of l.fields)if(t.has(e)){const s=t.get(e),o=l,r=[s.name,o.name].sort().join("|");if(n.has(r))continue;i.push([s,o]),n.add(r),t.set(e,o)}else t.set(e,l);const s=new Set(i.flat()),o=new Set(e);for(const l of s)o.delete(l);const r=new Map,a=new Map;for(const l of new Set(i.flat())){const e=Symbol(l.name);r.set(e,new Set([l])),a.set(l,e)}for(const[l,u]of i){const e=a.get(l),t=a.get(u);if(e===t)continue;const i=r.get(e),n=r.get(t);for(const s of n)i.add(s),a.set(s,e);r.delete(t)}return[[...r.values()].map((e=>[...e])),[...o]]}_joinFieldGroupContingencies(e){const t=e.slice(),i=t.shift();let n=t.shift(),s=this._generateJoinKey(i.fields,n.fields),o=new Set([...i.fields,...n.fields]),r=new Map;for(const a of i.contingencies){const[e]=this._hashContingency(a,s.codedValueFields,!0);r.has(e)?r.get(e).push(a):r.set(e,[a])}for(;t.length>0;){const e=new Map,i=t.shift(),l=this._generateJoinKey(o,i.fields);for(const t of n.contingencies){const[i,n]=this._hashContingency(t,s.codedValueFields),o=n?this._findMatchingContingenciesWithAnyHashMask(r,i):r.get(i);if(r.has(j)&&o.push(...this._findMatchingContingenciesContainingAny(t,r.get(j),s.codedValueFields)),!a(o))for(const r of o){const i=s.rangeFields.length>0?this._joinContingenciesWithRangeDomains(r,t,s.rangeFields):this._joinContingencies(r,t);if(a(i))break;const[n]=this._hashContingency(i,l.codedValueFields,!0);e.has(n)?e.get(n).push(i):e.set(n,[i])}}r=e,n=i,s=l,o=new Set([...o,...n.fields])}const u=[];for(const c of n.contingencies){const[e,t]=this._hashContingency(c,s.codedValueFields),i=t?this._findMatchingContingenciesWithAnyHashMask(r,e):r.get(e);if(r.has(j)&&i.push(...this._findMatchingContingenciesContainingAny(c,r.get(j),s.codedValueFields)),!a(i))for(const n of i){const e=s.rangeFields.length>0?this._joinContingenciesWithRangeDomains(n,c,s.rangeFields):this._joinContingencies(n,c);l(e)&&u.push(e)}}return u}_joinContingencies(e,t){const i={values:{...e.values,...t.values}};for(const[n,s]of Object.entries(i.values))"any"===s.objectType&&l(e.values[n])&&(i.values[n]=e.values[n]);return i}_joinContingenciesWithRangeDomains(e,t,i){const n=this._joinContingencies(e,t);for(const s of i){const i=e.values[s],o=t.values[s],{leftIsNull:r,rightIsNull:a,bothAreNull:l,leftIsAny:u,rightIsAny:c,bothAreAny:p,leftIsRange:d,rightIsRange:h}=this._compareObjectTypes(i.objectType,o.objectType);if(l||p)continue;if(r&&c||a&&u){n.values[s]=new f({objectType:"null"});continue}if(r&&h||a&&d)return null;u?(i.minValue=-1/0,i.maxValue=1/0):c&&(o.minValue=-1/0,o.maxValue=1/0);const m=Math.max(i.minValue,o.minValue),g=Math.min(i.maxValue,o.maxValue);if(m>g)return null;n.values[s]=new f({objectType:"range",minValue:m,maxValue:g})}return n}_findMatchingContingenciesContainingAny(e,t,i){return t.filter((t=>i.every((i=>{const n=t.values[i],s=e.values[i];return"any"===n.objectType||"any"===s.objectType||n.codedValue?.code===s.codedValue?.code}))))}_findMatchingContingenciesWithAnyHashMask(e,t){const i=RegExp(`${t}$`),n=[];for(const[s,o]of e){if(s===j)break;i.test(s)&&n.push(...o)}return n}_generateJoinKey(e,t){const i=Array.isArray(e)?new Set(e):e,n=Array.isArray(t)?new Set(t):t,s=i.size<n.size?i:n,o=s===i?n:i,r=new Set,l=new Set;for(const u of s)if(o.has(u)){const e=this.layer.getFieldDomain(u,{feature:this.feature});if(a(e))continue;switch(e.type){case"coded-value":r.add(u);break;case"range":l.add(u)}}return{codedValueFields:[...r],rangeFields:[...l]}}_hashContingency(e,t,i=!1){if(t.length<1)return[x,!1];const n=[];let s=!1;for(const o of t){const t=e.values[o];if("any"===t.objectType){if(i)return[j,!0];s=!0,n.push(`${o}:.*`)}else"null"===t.objectType?n.push(`${o}:${w}`):n.push(`${o}:${t.codedValue?.code}`)}return[n.sort().join("&"),s]}_compareObjectTypes(e,t){return{leftIsNull:"null"===e,rightIsNull:"null"===t,bothAreNull:"null"===e&&"null"===t,leftIsAny:"any"===e,rightIsAny:"any"===t,bothAreAny:"any"===e&&"any"===t,leftIsRange:"range"===e,rightIsRange:"range"===t}}};e([p({readOnly:!0})],I.prototype,"allInputFields",null),e([p()],I.prototype,"_layerFieldsByName",null),e([p()],I.prototype,"_inputFieldCache",void 0),e([p()],I.prototype,"contingencyConstraintViolations",void 0),e([p()],I.prototype,"feature",null),e([p()],I.prototype,"fieldsWithContingentValues",null),e([p({type:h})],I.prototype,"formTemplate",null),e([p({readOnly:!0})],I.prototype,"inputFields",null),e([p()],I.prototype,"joinedContingentValues",null),e([p()],I.prototype,"layer",null),e([p()],I.prototype,"messages",void 0),e([p()],I.prototype,"spatialReference",null),e([p()],I.prototype,"state",null),e([p()],I.prototype,"strict",void 0),e([p()],I.prototype,"submittable",null),e([p()],I.prototype,"valid",null),e([p()],I.prototype,"getValues",null),e([p()],I.prototype,"submit",null),I=e([d(b)],I);const T=e=>!!e.inputFields,k=e=>"group"===e.type,A=(e,t,i)=>{l(t)&&e.set(t,i)},M=I;export{M as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import t from"../../core/Accessor.js";import{HandleOwnerMixin as i}from"../../core/HandleOwner.js";import{isSome as r,isNone as s,get as l}from"../../core/maybe.js";import{watch as n}from"../../core/reactiveUtils.js";import{generateUID as o}from"../../core/uid.js";import{property as a}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as u}from"../../core/accessorSupport/decorators/subclass.js";import d from"../../layers/support/CodedValueDomain.js";import"../../layers/support/Domain.js";import"../../layers/support/InheritedDomain.js";import"../../layers/support/RangeDomain.js";import{validateDomainValue as p,DomainValidationError as c,getDomainRange as m}from"../../layers/support/domainUtils.js";import{isNumericField as h,isStringField as y,isDateField as f,TypeValidationError as v,validateFieldValue as g,getFeatureEditFields as E,getFeatureGeometryFields as b,NumericRangeValidationError as _,getFieldRange as x}from"../../layers/support/fieldUtils.js";import{substitute as F}from"../../intl/substitute.js";var V,O;!function(e){e.Text="text",e.Number="number",e.Date="date",e.Unsupported="unsupported"}(V||(V={})),function(e){e.TOO_SHORT="length-validation-error::too-short"}(O||(O={}));const U={type:"number"},T={type:"number",intlOptions:{notation:"scientific"}},j={type:"date",intlOptions:{day:"2-digit",month:"2-digit",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric"}};function A(e){return e>=1e7||e<=-1e7}let D=class extends(i(t)){constructor(e){super(e),this._storedValue=null,this.arcade=null,this.editableFunction=null,this.id=o().toString(),this.requiredFunction=null,this.valueFunction=null,this.visibilityFunction=null,this.feature=null,this.field=null,this.fieldElement=null,this.layer=null,this.description=null,this.inputType=null,this.error=null,this.group=null,this.hint=null,this.messages=null,this.name=null}initialize(){this.handles.add(n((()=>this.value),((e,t)=>{if(e!==t){const{feature:e,name:t,value:i}=this;e.setAttribute(t,i)}})))}get _configAllowsEdits(){const{fieldElement:e,layer:t,name:i}=this;if(r(e))return!1!==e.editable;return("subtype-group"!==t?.type?t?.popupTemplate?.fieldInfos?.find((({fieldName:e})=>e===i)):null)?.isEditable??!0}get _layerFieldAllowsEdits(){const{field:e,layer:t}=this;return t?.capabilities.operations.supportsEditing&&e?.editable}get isUsingValueExpression(){return this._shouldUseValueExpression()}get evaluatedEditableExpression(){const{editableFunction:e}=this;if(s(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}get evaluatedRequiredExpression(){const{requiredFunction:e}=this;if(s(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}get evaluatedVisibilityExpression(){const{visibilityFunction:e}=this;if(s(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}get evaluatedValueExpression(){const{valueFunction:e}=this;if(s(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}set initialFeature(e){this._set("initialFeature",e),this.notifyChange("valid")}get domain(){const{typeIdField:e}=this.layer,t=e===this.name,i=this.field?.domain;if(t&&!i){const{layer:e}=this,t="subtype-group"===e.type?e.sublayers.map((({subtypeCode:e,title:t})=>({id:e,name:t}))):e.types.map((({id:e,name:t})=>({code:e,name:t})));return new d({name:"__internal-type-based-coded-value-domain__",codedValues:t})}const{feature:s}=this,n=e&&this.layer.getFieldDomain(this.name,{feature:s})||i,o=l(this.fieldElement,"domain");return r(o)&&this._isDomainCompatible(o)?o:n}get editable(){return!!this._layerFieldAllowsEdits&&(this.evaluatedEditableExpression??this._configAllowsEdits)}get errorMessage(){return this._toErrorMessage()}get includeTime(){const{fieldElement:e}=this,t=r(e)&&"datetime-picker"===e.input?.type?e.input.includeTime:void 0;return void 0===t||t}get label(){return r(this.fieldElement)&&this.fieldElement.label||this.field.alias||this.field.name}get maxLength(){const e=-1;if(this.type===V.Date)return e;const{field:t,fieldElement:i}=this,s=t?.length,l=r(i)&&N(i.input)?i.input.maxLength:NaN;return!isNaN(l)&&l>=e&&(s===e||l<=s)?l:s}get minLength(){const e=-1;if(this.type===V.Date)return e;const{field:t,fieldElement:i}=this,s=t?.length,l=r(i)&&N(i.input)?i.input.minLength:NaN;return!isNaN(l)&&l>=e&&(s===e||l<=s)?l:e}get required(){return!!this.editable&&(!1===this.field?.nullable||(this.evaluatedRequiredExpression??!1))}get submittable(){const{field:e,required:t,valid:i,value:r}=this;return(!t||!s(r))&&(!!i||this.initialFeature.getAttribute(e.name)===r)}get type(){const{field:e}=this;return h(e)?V.Number:y(e)?V.Text:f(e)?V.Date:V.Unsupported}get valid(){const e=this.editable?this._validate():null;return this._set("error",e),null===e}get value(){return this._shouldUseValueExpression()?this.evaluatedValueExpression:this.get("_storedValue")}set value(e){this.notifyChange("evaluatedVisibilityExpression"),this.set("_storedValue",e)}get visible(){return!this._isEditorField()&&(r(this.fieldElement)?this.evaluatedVisibilityExpression??!0:this._isVisibleByDefault())}_isDomainCompatible(e){const{field:t}=this;if("coded-value"===e?.type){const i=typeof e.codedValues[0].code;if("string"===i&&y(t)||"number"===i&&h(t))return!0}return!!("range"===e?.type&&h(t)||f(t))}_validate(){const{domain:e,field:t,initialFeature:i,minLength:r,required:s,type:l,valid:n,value:o}=this,a=s&&null===o,u=void 0!==n;return!a&&i.getAttribute(t.name)===o&&u?null:a?v.INVALID_TYPE:"text"===l&&r>-1&&"string"==typeof o&&o.length<r?O.TOO_SHORT:e?null!==o||s?p(e,o):null:g(t,o)}_isVisibleByDefault(){const e=this.field?.type;return"oid"!==e&&"global-id"!==e&&!this._isGeometryField()}_isEditorField(){return E(this.layer).includes(this.name)}_isGeometryField(){return b(this.layer).includes(this.name)}_shouldUseValueExpression(){return this._layerFieldAllowsEdits&&!this._configAllowsEdits&&r(this.valueFunction)}_toErrorMessage(){const{domain:e,field:t,messages:i,minLength:r,value:s,required:l,type:n}=this,o=this.error;if(l&&null===s)return i.validationErrors.cannotBeNull;if(o===c.VALUE_OUT_OF_RANGE||o===_.OUT_OF_RANGE){const r=m(e)||x(t);return F(i.validationErrors.outsideRange,r,{format:{max:"date"===n?j:A(r.max)?T:U,min:"date"===n?j:A(r.min)?T:U}})}return o===c.INVALID_CODED_VALUE?i.validationErrors.invalidCodedValue:o===v.INVALID_TYPE?i.validationErrors.invalidType:o===O.TOO_SHORT?F(i.validationErrors.tooShort,{min:r}):null}};function N(e){return!!e&&"maxLength"in e}e([a()],D.prototype,"_storedValue",void 0),e([a()],D.prototype,"_configAllowsEdits",null),e([a()],D.prototype,"_layerFieldAllowsEdits",null),e([a()],D.prototype,"arcade",void 0),e([a()],D.prototype,"editableFunction",void 0),e([a()],D.prototype,"requiredFunction",void 0),e([a()],D.prototype,"valueFunction",void 0),e([a()],D.prototype,"isUsingValueExpression",null),e([a()],D.prototype,"visibilityFunction",void 0),e([a()],D.prototype,"evaluatedEditableExpression",null),e([a()],D.prototype,"evaluatedRequiredExpression",null),e([a()],D.prototype,"evaluatedVisibilityExpression",null),e([a()],D.prototype,"evaluatedValueExpression",null),e([a()],D.prototype,"feature",void 0),e([a()],D.prototype,"field",void 0),e([a()],D.prototype,"fieldElement",void 0),e([a()],D.prototype,"initialFeature",null),e([a()],D.prototype,"layer",void 0),e([a({aliasOf:"fieldElement.description"})],D.prototype,"description",void 0),e([a()],D.prototype,"domain",null),e([a()],D.prototype,"editable",null),e([a({aliasOf:"fieldElement.input.type"})],D.prototype,"inputType",void 0),e([a({readOnly:!0})],D.prototype,"error",void 0),e([a({dependsOn:["error","messages","value"]})],D.prototype,"errorMessage",null),e([a()],D.prototype,"group",void 0),e([a({aliasOf:"fieldElement.hint"})],D.prototype,"hint",void 0),e([a()],D.prototype,"includeTime",null),e([a()],D.prototype,"label",null),e([a()],D.prototype,"maxLength",null),e([a()],D.prototype,"minLength",null),e([a()],D.prototype,"messages",void 0),e([a({aliasOf:"field.name"})],D.prototype,"name",void 0),e([a()],D.prototype,"required",null),e([a()],D.prototype,"submittable",null),e([a()],D.prototype,"type",null),e([a()],D.prototype,"valid",null),e([a({value:null})],D.prototype,"value",null),e([a()],D.prototype,"visible",null),D=e([u("esri.widgets.FeatureForm.InputField")],D);const L=D;export{L as default};
|
|
5
|
+
import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import t from"../../core/Accessor.js";import{HandleOwnerMixin as i}from"../../core/HandleOwner.js";import{makeHandle as r}from"../../core/handleUtils.js";import{isSome as s,isNone as n,get as o}from"../../core/maybe.js";import{watch as l,syncAndInitial as a}from"../../core/reactiveUtils.js";import{generateUID as u}from"../../core/uid.js";import{property as p}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as d}from"../../core/accessorSupport/decorators/subclass.js";import c from"../../layers/support/CodedValueDomain.js";import"../../layers/support/Domain.js";import"../../layers/support/InheritedDomain.js";import"../../layers/support/RangeDomain.js";import{validateDomainValue as h,DomainValidationError as m,getDomainRange as y}from"../../layers/support/domainUtils.js";import{isNumericField as f,isStringField as g,isDateField as v,TypeValidationError as E,validateFieldValue as x,getFeatureEditFields as b,getFeatureGeometryFields as _,NumericRangeValidationError as F,getFieldRange as T}from"../../layers/support/fieldUtils.js";import{substitute as V}from"../../intl/substitute.js";var U,O;!function(e){e.Text="text",e.Number="number",e.Date="date",e.Unsupported="unsupported"}(U||(U={})),function(e){e.TOO_SHORT="length-validation-error::too-short"}(O||(O={}));const R={type:"number"},j={type:"number",intlOptions:{notation:"scientific"}},A={type:"date",intlOptions:{day:"2-digit",month:"2-digit",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric"}};function D(e){return e>=1e7||e<=-1e7}const w=["editable","required","value","visibility"];let N=class extends(i(t)){constructor(e){super(e),this._storedValue=null,this._expressionTrackingHandles=new Map,this.arcade=null,this.editableFunction=null,this.id=u().toString(),this.requiredFunction=null,this.expressionTrackingProvider={registerExpression:()=>r()},this.valueFunction=null,this.visibilityFunction=null,this.feature=null,this.field=null,this.fieldElement=null,this.layer=null,this.description=null,this.inputType=null,this.error=null,this.group=null,this.hint=null,this.messages=null,this.name=null}initialize(){const e=e=>"value"!==e,t=w.filter(e);this.own(t.map((e=>l((()=>this.get(`${e}Function`)),(t=>{s(t)?this._registerExpressionWithTrackingProvider(e):this._unregisterExpressionWithTrackingProvider(e)}),a))))}get _configAllowsEdits(){const{fieldElement:e,layer:t,name:i}=this;if(s(e))return e.editableExpression?this.evaluatedEditableExpression:!1!==e.editable;return("subtype-group"!==t?.type?t?.popupTemplate?.fieldInfos?.find((({fieldName:e})=>e===i)):null)?.isEditable??!0}get _layerFieldAllowsEdits(){const{field:e,layer:t}=this;return t?.capabilities.operations.supportsEditing&&e?.editable}get isUsingValueExpression(){return this._shouldUseValueExpression()}get evaluatedEditableExpression(){const{editableFunction:e,spatialReference:t}=this;if(n(e))return null;const{arcade:i}=this,r=i.arcadeUtils.getViewInfo({spatialReference:t});return i.arcadeUtils.executeFunction(e,i.arcadeUtils.createExecContext(this.feature,r))}get evaluatedRequiredExpression(){const{requiredFunction:e,spatialReference:t}=this;if(n(e))return null;const{arcade:i}=this,r=i.arcadeUtils.getViewInfo({spatialReference:t});return i.arcadeUtils.executeFunction(e,i.arcadeUtils.createExecContext(this.feature,r))}get evaluatedVisibilityExpression(){const{visibilityFunction:e,spatialReference:t}=this;if(n(e))return null;const{arcade:i}=this,r=i.arcadeUtils.getViewInfo({spatialReference:t});return i.arcadeUtils.executeFunction(e,i.arcadeUtils.createExecContext(this.feature,r))}get evaluatedValueExpression(){const{valueFunction:e,spatialReference:t}=this;if(n(e))return null;const{arcade:i}=this,r=i.arcadeUtils.getViewInfo({spatialReference:t});return i.arcadeUtils.executeFunction(e,i.arcadeUtils.createExecContext(this.feature,r))}set initialFeature(e){this._set("initialFeature",e),this.notifyChange("valid")}get domain(){const{typeIdField:e}=this.layer,t=e===this.name,i=this.field?.domain;if(t&&!i){const{layer:e}=this,t="subtype-group"===e.type?e.sublayers.map((({subtypeCode:e,title:t})=>({id:e,name:t}))):e.types.map((({id:e,name:t})=>({code:e,name:t})));return new c({name:"__internal-type-based-coded-value-domain__",codedValues:t})}const{feature:r}=this,n=e&&this.layer.getFieldDomain(this.name,{feature:r})||i,l=o(this.fieldElement,"domain");return s(l)&&this._isDomainCompatible(l)?l:n}get editable(){return!!this._layerFieldAllowsEdits&&(this.evaluatedEditableExpression??this._configAllowsEdits)}get errorMessage(){return this._toErrorMessage()}get includeTime(){const{fieldElement:e}=this,t=s(e)&&"datetime-picker"===e.input?.type?e.input.includeTime:void 0;return void 0===t||t}get label(){return s(this.fieldElement)&&this.fieldElement.label||this.field.alias||this.field.name}get maxLength(){const e=-1;if(this.type===U.Date)return e;const{field:t,fieldElement:i}=this,r=t?.length,n=s(i)&&k(i.input)?i.input.maxLength:NaN;return!isNaN(n)&&n>=e&&(r===e||n<=r)?n:r}get minLength(){const e=-1;if(this.type===U.Date)return e;const{field:t,fieldElement:i}=this,r=t?.length,n=s(i)&&k(i.input)?i.input.minLength:NaN;return!isNaN(n)&&n>=e&&(r===e||n<=r)?n:e}get required(){return!!this.editable&&(!1===this.field?.nullable||(this.evaluatedRequiredExpression??!1))}get spatialReference(){return this.layer?.spatialReference||null}set spatialReference(e){void 0===e?this._clearOverride("spatialReference"):this._override("spatialReference",e)}get submittable(){const{field:e,required:t,valid:i,value:r}=this;return(!t||!n(r))&&(!!i||this.initialFeature.getAttribute(e.name)===r)}get type(){const{field:e}=this;return f(e)?U.Number:g(e)?U.Text:v(e)?U.Date:U.Unsupported}get valid(){const e=this.editable?this._validate():null;return this._set("error",e),null===e}get value(){return this._shouldUseValueExpression()?this.evaluatedValueExpression:this.get("_storedValue")}set value(e){this.notifyChange("evaluatedVisibilityExpression"),this.set("_storedValue",e)}get visible(){return!this._isEditorField()&&(s(this.fieldElement)?this.evaluatedVisibilityExpression??!0:this._isVisibleByDefault())}_isDomainCompatible(e){const{field:t}=this;if("coded-value"===e?.type){const i=typeof e.codedValues[0].code;if("string"===i&&g(t)||"number"===i&&f(t))return!0}return!!("range"===e?.type&&f(t)||v(t))}_validate(){const{domain:e,field:t,initialFeature:i,minLength:r,required:s,type:n,valid:o,value:l}=this,a=s&&null===l,u=void 0!==o;return!a&&i.getAttribute(t.name)===l&&u?null:a?E.INVALID_TYPE:"text"===n&&r>-1&&"string"==typeof l&&l.length<r?O.TOO_SHORT:e?null!==l||s?h(e,l):null:x(t,l)}_isVisibleByDefault(){const e=this.field?.type;return"oid"!==e&&"global-id"!==e&&!this._isGeometryField()}_isEditorField(){return b(this.layer).includes(this.name)}_isGeometryField(){return _(this.layer).includes(this.name)}_shouldUseValueExpression(){const e=this._layerFieldAllowsEdits&&!this._configAllowsEdits&&s(this.valueFunction);return e?this._registerExpressionWithTrackingProvider("value"):this._unregisterExpressionWithTrackingProvider("value"),e}_toErrorMessage(){const{domain:e,field:t,messages:i,minLength:r,value:s,required:n,type:o}=this,l=this.error;if(n&&null===s)return i.validationErrors.cannotBeNull;if(l===m.VALUE_OUT_OF_RANGE||l===F.OUT_OF_RANGE){const r=y(e)||T(t);return V(i.validationErrors.outsideRange,r,{format:{max:"date"===o?A:D(r.max)?j:R,min:"date"===o?A:D(r.min)?j:R}})}return l===m.INVALID_CODED_VALUE?i.validationErrors.invalidCodedValue:l===E.INVALID_TYPE?i.validationErrors.invalidType:l===O.TOO_SHORT?V(i.validationErrors.tooShort,{min:r}):null}_registerExpressionWithTrackingProvider(e){const{_expressionTrackingHandles:t}=this;if(t.has(e))return;const i=`evaluated${C(e)}Expression`,r=this.expressionTrackingProvider.registerExpression((()=>this.notifyChange(i)));t.set(e,r)}_unregisterExpressionWithTrackingProvider(e){const{_expressionTrackingHandles:t}=this,i=t.get(e);i&&(i.remove(),t.delete(e))}};function k(e){return!!e&&"maxLength"in e}e([p()],N.prototype,"_storedValue",void 0),e([p()],N.prototype,"_configAllowsEdits",null),e([p()],N.prototype,"_layerFieldAllowsEdits",null),e([p()],N.prototype,"arcade",void 0),e([p()],N.prototype,"editableFunction",void 0),e([p()],N.prototype,"requiredFunction",void 0),e([p()],N.prototype,"expressionTrackingProvider",void 0),e([p()],N.prototype,"valueFunction",void 0),e([p()],N.prototype,"isUsingValueExpression",null),e([p()],N.prototype,"visibilityFunction",void 0),e([p()],N.prototype,"evaluatedEditableExpression",null),e([p()],N.prototype,"evaluatedRequiredExpression",null),e([p()],N.prototype,"evaluatedVisibilityExpression",null),e([p()],N.prototype,"evaluatedValueExpression",null),e([p()],N.prototype,"feature",void 0),e([p()],N.prototype,"field",void 0),e([p()],N.prototype,"fieldElement",void 0),e([p()],N.prototype,"initialFeature",null),e([p()],N.prototype,"layer",void 0),e([p({aliasOf:"fieldElement.description"})],N.prototype,"description",void 0),e([p()],N.prototype,"domain",null),e([p()],N.prototype,"editable",null),e([p({aliasOf:"fieldElement.input.type"})],N.prototype,"inputType",void 0),e([p({readOnly:!0})],N.prototype,"error",void 0),e([p({dependsOn:["error","messages","value"]})],N.prototype,"errorMessage",null),e([p()],N.prototype,"group",void 0),e([p({aliasOf:"fieldElement.hint"})],N.prototype,"hint",void 0),e([p()],N.prototype,"includeTime",null),e([p()],N.prototype,"label",null),e([p()],N.prototype,"maxLength",null),e([p()],N.prototype,"minLength",null),e([p()],N.prototype,"messages",void 0),e([p({aliasOf:"field.name"})],N.prototype,"name",void 0),e([p()],N.prototype,"required",null),e([p()],N.prototype,"spatialReference",null),e([p()],N.prototype,"submittable",null),e([p()],N.prototype,"type",null),e([p()],N.prototype,"valid",null),e([p({value:null})],N.prototype,"value",null),e([p()],N.prototype,"visible",null),N=e([d("esri.widgets.FeatureForm.InputField")],N);const C=e=>e.charAt(0).toUpperCase()+e.slice(1),I=N;export{I as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as
|
|
5
|
+
import{_ as i}from"../../chunks/tslib.es6.js";import e from"../../core/Accessor.js";import{HandleOwnerMixin as t}from"../../core/HandleOwner.js";import{makeHandle as s}from"../../core/handleUtils.js";import{isSome as r,isNone as o,unwrap as n}from"../../core/maybe.js";import{watch as p,syncAndInitial as l}from"../../core/reactiveUtils.js";import{aliasOf as a}from"../../core/accessorSupport/decorators/aliasOf.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{property as c}from"../../core/accessorSupport/decorators/property.js";import{subclass as u}from"../../core/accessorSupport/decorators/subclass.js";const d=["visibility"];let h=class extends(t(e)){constructor(i){super(i),this._expressionTrackingHandles=new Map,this.arcade=null,this.visibilityExpression=null,this.description=null,this.expressionTrackingProvider={registerExpression:()=>s()},this.feature=null,this.groupElement=null,this.label=null,this.spatialReference=null}initialize(){this.own(d.map((i=>p((()=>this.get(`${i}Function`)),(e=>{r(e)?this._registerExpressionWithTrackingProvider(i):this._unregisterExpressionWithTrackingProvider(i)}),l))))}set visibilityFunction(i){this._set("visibilityFunction",i),r(i)?this._registerExpressionWithTrackingProvider("visibility"):this._unregisterExpressionWithTrackingProvider("visibility")}get evaluatedVisibilityExpression(){const{visibilityFunction:i,spatialReference:e}=this;if(o(i))return;const{arcade:t}=this,s=t.arcadeUtils.getViewInfo({spatialReference:n(e)});return t.arcadeUtils.executeFunction(i,t.arcadeUtils.createExecContext(this.feature,s))}get inputFields(){return this._get("inputFields")}set inputFields(i){this.handles.removeAll(),i&&this.handles.add(i.map((i=>p((()=>i.visible),(()=>this._dirtyEvaluatedVisibilityExpression()))))),this._set("inputFields",i)}get state(){return r(this.groupElement)&&this.groupElement.initialState||"expanded"}set state(i){o(i)?this._clearOverride("state"):this._override("state",i)}get visible(){return!1!==this.evaluatedVisibilityExpression&&this.inputFields&&this.inputFields.some((i=>i.visible))}_registerExpressionWithTrackingProvider(i){const{_expressionTrackingHandles:e}=this;if(e.has(i))return;const t=`evaluated${v(i)}Expression`,s=this.expressionTrackingProvider.registerExpression((()=>this.notifyChange(t)));e.set(i,s)}_unregisterExpressionWithTrackingProvider(i){const{_expressionTrackingHandles:e}=this,t=e.get(i);t&&(t.remove(),e.delete(i))}_dirtyEvaluatedVisibilityExpression(){const{groupElement:i}=this;r(i)&&i.visibilityExpression&&this.notifyChange("evaluatedVisibilityExpression")}};i([c()],h.prototype,"arcade",void 0),i([a("groupElement.visibilityExpression")],h.prototype,"visibilityExpression",void 0),i([c()],h.prototype,"visibilityFunction",null),i([c()],h.prototype,"evaluatedVisibilityExpression",null),i([a("groupElement.description")],h.prototype,"description",void 0),i([c()],h.prototype,"expressionTrackingProvider",void 0),i([c()],h.prototype,"feature",void 0),i([c()],h.prototype,"groupElement",void 0),i([c()],h.prototype,"inputFields",null),i([a("groupElement.label")],h.prototype,"label",void 0),i([c()],h.prototype,"spatialReference",void 0),i([c()],h.prototype,"state",null),i([c()],h.prototype,"visible",null),h=i([u("esri.widgets.FeatureForm.InputFieldGroup")],h);const v=i=>i.charAt(0).toUpperCase()+i.slice(1),g=h;export{g as default};
|
package/widgets/FeatureForm.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{neverReached as t}from"../core/compilerUtils.js";import{isSome as i,isNone as a}from"../core/maybe.js";import{watch as n}from"../core/reactiveUtils.js";import{aliasOf as s}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import"../core/accessorSupport/ensureType.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import{subclass as r}from"../core/accessorSupport/decorators/subclass.js";import{getDomainRange as o}from"../layers/support/domainUtils.js";import{getFieldRange as u}from"../layers/support/fieldUtils.js";import d from"./Widget.js";import p from"./FeatureForm/FeatureFormViewModel.js";import{Heading as c,incrementHeadingLevel as m}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as h}from"./support/decorators/messageBundle.js";import{vmEvent as f}from"./support/decorators/vmEvent.js";import{tsx as _}from"./support/jsxFactory.js";import{DateTime as g}from"luxon";import{getLocale as v}from"../intl/locale.js";const b={base:"esri-feature-form",form:"esri-feature-form__form",formHeader:"esri-feature-form__form-header",label:"esri-feature-form__label",inputField:"esri-feature-form__input",inputDate:"esri-feature-form__input--date",inputTime:"esri-feature-form__input--time",inputRadioGroup:"esri-feature-form__input--radio-group",inputRadio:"esri-feature-form__input--radio",inputRadioLabel:"esri-feature-form__input--radio-label",inputDisabled:"esri-feature-form__input--disabled",inputSwitch:"esri-feature-form__input--switch",inputInvalid:"esri-feature-form__input--invalid",inputIconInvalid:"esri-feature-form__input-icon--invalid",errorMessage:"esri-feature-form__field-error-message",description:"esri-feature-form__description-text",dateInputPart:"esri-feature-form__date-input-part",loneDateInputPart:"esri-feature-form__date-input-part--lone",dateInputContainer:"esri-feature-form__date-input-container",dateFormatHint:"esri-feature-form__date-format-hint",group:"esri-feature-form__group",groupLabel:"esri-feature-form__group-label",groupHeader:"esri-feature-form__group-header",groupHeading:"esri-feature-form__group-header",groupTitle:"esri-feature-form__group-title",groupDescription:"esri-feature-form__group-description",groupToggleIcon:"esri-feature-form__group-toggle-icon",groupCollapsed:"esri-feature-form__group--collapsed",groupSequential:"esri-feature-form__group--sequential",groupActive:"esri-feature-form__group--active",collapseIcon:"esri-icon-up",errorIcon:"esri-icon-notice-triangle",expandIcon:"esri-icon-down",widget:"esri-widget",panel:"esri-widget--panel",input:"esri-input",select:"esri-select"},I={datePattern:"D",timePattern:"tt"};function F(e){return e&&e.inputFields}const y="data-field-name";let w=class extends d{constructor(e,t){super(e,t),this._activeDateFieldEdit=null,this._activeInputName=null,this._activeNumberFieldEdit=null,this._fieldFocusNeeded=!1,this._fieldToInitialIncompatibleDomainValue=new Map,this._switchFieldsWithInitialIncompatibleValue=new Set,this._userUpdatedInputFieldNames=new Set,this.feature=null,this.formTemplate=null,this.groupDisplay="all",this.headingLevel=2,this.label=void 0,this.layer=null,this.messages=null,this.messagesTemplates=null,this.strict=null,this.viewModel=new p,this._handleSwitchClick=e=>{e.target===e.currentTarget&&e.stopImmediatePropagation()},this._handleRadioInputChange=e=>{this._commitInputValue(e.target)},this._handleInputInput=e=>{this._commitInputValue(e.currentTarget,!0)},this._handleFormKeyDown=this._handleFormKeyDown.bind(this),this._handleInputBlur=this._handleInputBlur.bind(this),this._handleInputFocus=this._handleInputFocus.bind(this),this._handleNumberInputMouseDown=this._handleNumberInputMouseDown.bind(this),this._handleInputKeyDown=this._handleInputKeyDown.bind(this),this._handleOptionChange=this._handleOptionChange.bind(this),this._handleGroupClick=this._handleGroupClick.bind(this),this._handleSubmit=this._handleSubmit.bind(this),this._afterInputCreateOrUpdate=this._afterInputCreateOrUpdate.bind(this)}initialize(){this.own([n((()=>this.feature),(()=>{const e=this._getFocusableInput("forward");this._activeInputName=e&&e.name,this._userUpdatedInputFieldNames.clear(),this._fieldToInitialIncompatibleDomainValue.clear(),this._switchFieldsWithInitialIncompatibleValue.clear(),this._fieldFocusNeeded=!0})),this.on("submit",(e=>{if(e.invalid.length>0){const[t]=e.invalid;e.invalid.forEach((e=>this._userUpdatedInputFieldNames.add(e))),this._activeInputName=t,this._fieldFocusNeeded=!0,this.scheduleRender()}}))])}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-combobox.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item-group.js"),import("@esri/calcite-components/dist/components/calcite-input-message.js"),import("@esri/calcite-components/dist/components/calcite-switch.js")])}destroy(){this._userUpdatedInputFieldNames.clear(),this._userUpdatedInputFieldNames=null}getValues(){return null}submit(){return null}render(){const{state:e}=this.viewModel;return _("div",{class:this.classes(b.base,b.widget,b.panel)},"ready"===e?this.renderForm():null)}renderForm(){const e=this.formTemplate?.title?_(c,{key:"title",level:this.headingLevel},this.formTemplate.title):null,t=this.formTemplate?.description?_("p",{class:b.description,key:"description"},this.formTemplate.description):null,i=e||t?_("div",{class:b.formHeader},e,t):null;return _("form",{class:b.form,novalidate:!0,onsubmit:this._handleSubmit,onkeydown:this._handleFormKeyDown},i,this.renderFields())}renderFields(){const{viewModel:{inputFields:e}}=this;return e.filter((e=>e.visible)).map(((e,t)=>F(e)?this.renderGroup(e,t):this.renderLabeledField(e)))}renderGroup(e,t){const{description:i,inputFields:a,label:n,state:s}=e,l=a.filter((e=>e.visible)),r=this.viewModel.findField(this._activeInputName),o=!(!r||r.group!==e),u=`${this.id}_group_${t}`,d=`${this.id}_group-label_${t}`,p=`${this.id}_group-description_${t}`,h=i?_("p",{class:this.classes(b.groupDescription,b.description),id:p},i):null,f="sequential"===this.groupDisplay,g=f?o:"expanded"===s,v=g?b.collapseIcon:b.expandIcon;return _("fieldset",{"aria-expanded":g.toString(),"aria-labelledby":d,"aria-describedby":i?p:"",class:this.classes(b.group,f?b.groupSequential:null,g?null:b.groupCollapsed,o?b.groupActive:null),"data-group":e,id:u,key:t,onclick:this._handleGroupClick},_("button",{role:f?"presentation":void 0,class:b.groupHeader,type:"button",tabIndex:f?-1:0},_("div",{class:b.groupTitle},_(c,{class:b.groupLabel,id:d,level:this.formTemplate?.title?m(this.headingLevel):this.headingLevel},n),h),f?null:_("span",{class:this.classes(v,b.groupToggleIcon)})),l.map((e=>this.renderLabeledField(e))))}_getFocusableInput(e,t){const i=this.viewModel.allInputFields,a="forward"===e?i:i.slice().reverse();let n;if(t)if(F(t))n=a.indexOf(t.inputFields[0]);else{let i;if(this._isInputFieldInGroup(t)&&"collapsed"===t.group.state){const{inputFields:a}=t.group;i="forward"===e?a[a.length-1]:a[0]}else i=t;n=a.indexOf(i)+1}else n=0;for(let s=n;s<a.length;s++){const e=a[s];if(e.visible)return e}return null}renderLabeledField(e){const{feature:t,label:i,layer:a,type:n}=e;return _("label",{key:`${a.id}-${t.uid}-${e.name}`,class:b.label},[i,"unsupported"!==n?this.renderInputField(e):this.renderUnsupportedField(e),this.renderAuxiliaryText(e)])}renderInputField(e){const{domain:t,name:a,type:n,value:s}=e,l=this.getCommonInputProps(e);if("coded-value"===t?.type){if(this._inputFieldHasInputType(e,"switch")){const{fieldElement:t}=e;if(!(this._switchFieldsWithInitialIncompatibleValue.has(a)||null==s||t.input.onValue!==s&&t.input.offValue!==s))return this.renderSwitchInputField(e,l);this._switchFieldsWithInitialIncompatibleValue.add(a)}return"radio-buttons"===e.inputType?this.renderRadioButtonsInputField(e,t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),l):this.renderSelectInputField(e,this._getFieldValueOptions(a,t),l)}return"datetime-picker"===e.inputType||"date"===n?this.renderDateInputField(e,l):"number"===n?_("input",{type:"number",...l,value:i(this._activeNumberFieldEdit)&&this._activeNumberFieldEdit.fieldName===e.name?this._activeNumberFieldEdit.value:`${l.value}`}):"text-area"===e.inputType?_("textarea",{...l}):_("input",{type:"text",...l})}_parseDateTime(e,t,i){if(i){let a=g.fromJSDate(this._parseDate(e,i));const n=g.fromMillis(t.value??Date.now());return a="date"===i?a.set({hour:n.hour,minute:n.minute,second:n.second}):a.set({day:n.day,month:n.month,year:n.year}),a.isValid?a.toMillis():null}const a=g.fromJSDate(this._parseDate(e));return a.isValid?a.toMillis():null}renderDateInputField(e,t){const{value:i,includeTime:a}=e,{date:n,time:s}=this._formatDate(0),l=`${this.id}-${t.key}`,r=`${l}-date`,o=`${l}-time`,{_activeDateFieldEdit:u}=this;let{date:d,time:p}=this._formatDate(i);return u?.fieldName===e.name&&(d=u.date.input?.value??d,p=u.time.input?.value??p),_("div",{key:`${t.key}-date`,class:b.dateInputContainer},_("div",{class:this.classes(b.dateInputPart,a?null:b.loneDateInputPart)},_("input",{"aria-label":e.label,"aria-describedby":r,type:"text",...t,"data-date-part":"date",class:this.classes(t.class,b.inputDate),value:d}),_("div",{class:b.dateFormatHint,id:r},n)),a?_("div",{class:b.dateInputPart,key:"time-input"},_("input",{"aria-describedby":o,"aria-label":e.label,type:"text",...t,"data-date-part":"time",class:this.classes(t.class,b.inputTime),value:p}),_("div",{class:b.dateFormatHint,id:o},s)):null)}renderUnsupportedField(e){const t=this.getCommonInputProps(e);return _("input",{afterCreate:t.afterCreate,afterUpdate:t.afterUpdate,class:this.classes(b.input,b.inputField,b.inputDisabled),onfocus:t.onfocus,readOnly:!0,tabIndex:t.tabIndex,type:"text",value:t.value,[y]:t[y]})}renderSelectInputField(e,t,i){const{value:n}=e,{messages:s,messagesTemplates:l}=this,r=t.map((e=>e.map((e=>_("calcite-combobox-item",{value:`${e.value}`,"text-label":e.name,key:`#${e.value}`,selected:n===e.value}))))),[o,u]=r;this._registerIncompatibleValue(n,t.flat(),e,(e=>{u.unshift(_("calcite-combobox-item",{value:`${e}`,"text-label":`${e}`,key:"incompatible-option",readOnly:!0}))}));const d=u.length>0?[_("calcite-combobox-item-group",{key:"recommended",label:s.recommended},o),_("calcite-combobox-item-group",{key:"other",label:l.other},u)]:o,p=a(e.fieldElement)||this._inputFieldHasInputType(e,"combo-box")&&e.fieldElement.input.showNoValueOption;if(!e.required&&p){const t="",i=this._inputFieldHasInputType(e,"combo-box")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty;d.unshift(_("calcite-combobox-item",{value:t,"text-label":this.messages.empty,key:"empty-option"},i))}return _("calcite-combobox",{...i,"selection-mode":"single",disabled:i.readOnly,allowCustomValues:!1,onCalciteComboboxChange:e=>this._handleOptionChange(e.target)},d)}_registerIncompatibleValue(e,t,i,a){const n=this._fieldToInitialIncompatibleDomainValue,s=n.has(i.name);(s||null!=e&&""!==e&&!t.some((t=>t.value===e))||s)&&(s||n.set(i.name,e),a?.(n.get(i.name)))}renderRadioButtonsInputField(e,t,i){const{value:n}=e,s=t.map((t=>this.renderRadioButton({key:t.name,label:t.name,name:e.name,value:t.value,selected:t.value===n,props:i})));this._registerIncompatibleValue(n,t,e);const l=a(e.fieldElement)||this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.showNoValueOption;if(!e.required&&l){const t="",a=this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty,l=n===t||null===n;s.unshift(this.renderRadioButton({key:"empty-option",label:a,name:e.name,value:t,selected:l,props:i}))}return _("div",{key:`${i.key}-radio`,class:b.inputRadioGroup},s)}renderSwitchInputField(e,t){const{value:i}=e,a=!!this._inputFieldHasInputType(e,"switch")&&i===e.fieldElement.input.onValue;return _("calcite-switch",{...t,class:b.inputSwitch,onclick:this._handleSwitchClick,checked:a,disabled:t.readOnly})}renderRadioButton({key:e,name:t,value:i,selected:a,label:n,props:s}){return _("label",{key:e,class:b.inputRadioLabel},_("input",{...s,class:b.inputRadio,name:t,type:"radio",value:i,checked:a,onchange:this._handleRadioInputChange}),n)}renderAuxiliaryText(e){const t=this._userUpdatedInputFieldNames.has(e.name)&&!e.valid?e.errorMessage:i(this.viewModel.contingencyConstraintViolations.get(e.name))?this.messages.validationErrors.valuesIncompatible:null;return i(t)?_("calcite-input-message",{status:"invalid",icon:!0,active:!0},t):e.description?_("div",{key:"description",class:b.description},e.description):void 0}getCommonInputProps(e){const{groupDisplay:t}=this,{editable:a,group:n,hint:s,maxLength:l,minLength:r,name:o,required:u,type:d,valid:p,value:c}=e,m=this._userUpdatedInputFieldNames.has(o),h=!a,f="all"===t&&i(n)&&"collapsed"===n.state;return{afterCreate:this._afterInputCreateOrUpdate,afterUpdate:this._afterInputCreateOrUpdate,"aria-invalid":p?"false":"true",class:this.classes(b.input,b.inputField,h?b.inputDisabled:null,m&&!p?b.inputInvalid:null),key:o,label:o,minlength:r>-1?`${r}`:"",maxlength:l>-1?`${l}`:"",...this._getNumberFieldConstraints(e),readOnly:h,value:null==c?"":`${c}`,[y]:o,onfocus:this._handleInputFocus,oninput:this._handleInputInput,onblur:this._handleInputBlur,onkeydown:this._handleInputKeyDown,onmousedown:"number"===d?this._handleNumberInputMouseDown:null,placeholder:"number"===d||"text"===d?s:"",required:u,tabIndex:f?-1:0}}_isInputFieldInGroup(e){return!F(e)&&i(e.group)}_handleNumberInputMouseDown({target:e}){e.focus(),this.scheduleRender()}_getFieldValueOptions(e,t){const i=t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),a=this.viewModel.fieldsWithContingentValues.has(e)?this._getContingentValueOptions(e):[];if(a.length>0){const e=new Set(a.map((e=>e.value)));return[a,i.filter((t=>!e.has(t.value)))]}return[i,[]]}_getContingentValueOptions(e){const t={};for(const s of this.viewModel.allInputFields){const{name:i,value:n}=s;!a(n)&&i!==e&&this.viewModel.fieldsWithContingentValues.has(i)&&(t[i]=n)}const i=this.viewModel.joinedContingentValues.slice(),n=new Map;for(const s of i){const i=s.values[e];if(a(i)||"code"!==i.objectType&&"null"!==i.objectType)continue;const{code:l,name:r}="null"===i.objectType?{code:"",name:this.messages.empty}:i.codedValue;if(n.has(l))continue;Object.entries(t).every((([e,t])=>!s.values.hasOwnProperty(e)||this._valueIsValidContingentValue(t,s.values[e])))&&n.set(l,{name:r,value:l})}return[...n.values()]}_getInputFieldFromInput(e){return this.viewModel.findField(e.getAttribute(y))}_getNumberFieldConstraints(e){const t=o(e.domain)||u(e.field);return t&&t.max!==Number.MAX_VALUE&&t.min!==Number.MIN_VALUE?t:{min:null,max:null}}_afterInputCreateOrUpdate(e){const{viewModel:t}=this,i=this._getInputFieldFromInput(e),a=t.findField(this._activeInputName),n=this._fieldToInitialIncompatibleDomainValue.get(i.name)===i.value;this._fieldFocusNeeded&&a===i&&("radio-buttons"!==i.inputType||n||e.checked)&&(this._fieldFocusNeeded=!1,e.focus())}_handleInputFocus(e){const t=e.target,i=this._getInputFieldFromInput(t);this._activeInputName=i.name,"date"===i.type?this._syncDateFieldEdits(t):this._isNumberInputField(i)&&this._setUpNumberFieldEdit(t)}_isNumberInputField({domain:e,inputType:t="text-box",type:i}){return"number"===i&&"text-box"===t&&(!e||"coded-value"!==e.type)}_handleInputBlur(e){const t=e.target,a=this._getInputFieldFromInput(t);if("date"===a.type){const i=e.relatedTarget,n=i&&this._getInputFieldFromInput(i);if(n&&"date"===a.type&&"date"===n.type&&a.field===n.field){if(""!==t.value&&""===i.value){const n=i.getAttribute("data-date-part");i.value=this._formatDate(a.value??Date.now())[n],this._parseDate(t.value,t.getAttribute("data-date-part"))&&this._commitInputValue(e.target,!0,!1)}return}}"number"===a.type&&i(this._activeNumberFieldEdit)&&(this._activeNumberFieldEdit.input.value=`${a.value}`,this._activeNumberFieldEdit=null),this._commitInputValue(t),this.scheduleRender()}_commitInputValue(e,t=!1,a=!0){const n=this._getInputFieldFromInput(e);if(this._activeDateFieldEdit){const{date:i,time:s}=this._activeDateFieldEdit,l=this._parseDateTime(e.value,n,i.active?"date":"time"),r=null!==this.viewModel.getValue(n.name),o=i.input&&(s.input||!n.includeTime),u=null===l;if(t){if(u)return;(o||!a||r)&&this._updateDateFieldValue(n,l)}else{if(""===i.input?.value||""===s.input?.value)this._updateDateFieldValue(n,null);else if(o){const e=`${i.input.value} ${s.input?.value??""}`,t=this._parseDateTime(e,n);!(null!==t)&&r||this._updateDateFieldValue(n,t)}this._activeDateFieldEdit=null}}else i(this._activeNumberFieldEdit)&&this._isNumberInputField(n)&&(this._activeNumberFieldEdit.value=e.value),this._updateFieldValue(e)}_handleInputKeyDown(e){const{key:t,altKey:i,ctrlKey:a,metaKey:n}=e,s=this._getInputFieldFromInput(e.target);if("Enter"===t)this._isInputFieldInGroup(s)&&"collapsed"===s.group.state&&(s.group.state="expanded");else{const{type:l}=s.field,r="single"===l||"double"===l,o=!i&&!a&&!n;if(("integer"===l||"small-integer"===l||r)&&o&&1===t.length){const i=Number(t),a=["-","+"],n=["e","."],s=r?[...a,...n]:a;isNaN(i)&&!s.includes(t)&&e.preventDefault()}}}_setUpNumberFieldEdit(e){const t=this._getInputFieldFromInput(e);this._activeNumberFieldEdit={fieldName:t.name,input:e,value:e.value}}_syncDateFieldEdits(e){const t=this._getInputFieldFromInput(e);if("date"!==t.type)return;const i=e.getAttribute("data-date-part"),a="date"===i?{value:e.value,input:e,active:!0}:{...this._activeDateFieldEdit?.date,active:!1},n="time"===i?{value:e.value,input:e,active:!0}:{...this._activeDateFieldEdit?.time,active:!1};this._activeDateFieldEdit={fieldName:t.name,date:a,time:n}}_updateFieldValue(e){const t=e.getAttribute(y);if(this.viewModel.setValue(t,this._parseValue(e)),this._userUpdatedInputFieldNames.add(t),this.viewModel.fieldsWithContingentValues.has(t)){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>i(t))));this.viewModel.validateContingencyConstraints(e)}}_updateDateFieldValue(e,t){this.viewModel.setValue(e.name,t),this._userUpdatedInputFieldNames.add(e.name)}_parseValue(e){const t=this._getInputFieldFromInput(e),i=e.value;if(this._inputFieldHasInputType(t,"switch")&&"CALCITE-COMBOBOX"!==e.tagName)return e.checked?t.fieldElement.input.onValue:t.fieldElement.input.offValue;if("radio-buttons"===t.inputType&&"radio"===e.type&&!e.checked)return t.value;const{type:a}=t;if("number"===a)return i?parseFloat(i):null;if("date"===a){if(!i)return null;const a=Number(i);if(!isNaN(a))return a;const n=e.getAttribute("data-date-part"),s=this._parseDate(i,n);if(!s)return null;let l=g.fromJSDate(s);const r=t.domain,o=g.now();let u=o;if(r&&"range"===r.type){const e=g.fromMillis(r.maxValue);o<e&&(u=e)}const d=this.viewModel.getValue(t.name),p=null!=d?g.fromMillis(d):u;return l="date"===n?l.set({hour:p.hour,minute:p.minute,second:p.second}):l.set({day:p.day,month:p.month,year:p.year}),l.toMillis()}return i}_handleOptionChange(e){this._commitInputValue(e),this.scheduleRender()}_handleGroupClick(e){const t=e.currentTarget["data-group"],i="expanded"===t.state,a="sequential"===this.groupDisplay,n=`.${b.groupHeader}`;if(!(i&&!e.target.closest(n))){if(this._activeInputName=this._getFocusableInput("forward",t)?.name,a){const a=e.target.closest(n);if(i&&!a)return;this.viewModel.inputFields.forEach((e=>{F(e)&&e!==t&&(e.state="collapsed")}))}t.state=i?"collapsed":"expanded",this._fieldFocusNeeded=a,this.scheduleRender()}}_handleSubmit(e){e.preventDefault()}_handleFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_formatDate(e){if(null==e)return{date:"",time:""};const t=g.fromMillis(e,{locale:v(),numberingSystem:"latn"});return{date:t.toLocaleString({year:"numeric",month:"2-digit",day:"2-digit"}),time:t.toFormat(I.timePattern)}}_parseDate(e,t){if(null==e||""===e)return null;const{timePattern:i,datePattern:a}=I,n=t?"date"===t?a:i:`${a} ${i}`,s=g.fromFormat(e,n,{locale:v(),numberingSystem:"latn"});return s.isValid?s.toJSDate():null}_inputFieldHasInputType(e,t){return i(e.fieldElement)&&e.fieldElement.input?.type===t}_valueIsValidContingentValue(e,i){switch(i.objectType){case"any":return!0;case"null":return null==e;case"code":return e===i.codedValue?.code;case"range":return e>=i.minValue&&e<=i.maxValue;default:return t(i.objectType),!1}}};e([s("viewModel.feature")],w.prototype,"feature",void 0),e([s("viewModel.formTemplate")],w.prototype,"formTemplate",void 0),e([l()],w.prototype,"groupDisplay",void 0),e([l()],w.prototype,"headingLevel",void 0),e([l({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],w.prototype,"label",void 0),e([s("viewModel.layer")],w.prototype,"layer",void 0),e([l(),h("esri/widgets/FeatureForm/t9n/FeatureForm")],w.prototype,"messages",void 0),e([l(),h("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],w.prototype,"messagesTemplates",void 0),e([s("viewModel.strict")],w.prototype,"strict",void 0),e([l(),f(["value-change","submit"])],w.prototype,"viewModel",void 0),e([s("viewModel.getValues")],w.prototype,"getValues",null),e([s("viewModel.submit")],w.prototype,"submit",null),w=e([r("esri.widgets.FeatureForm")],w);const V=w;export{V as default};
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{neverReached as t}from"../core/compilerUtils.js";import{isSome as i,isNone as a}from"../core/maybe.js";import{watch as n}from"../core/reactiveUtils.js";import{aliasOf as s}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import"../core/accessorSupport/ensureType.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import{subclass as r}from"../core/accessorSupport/decorators/subclass.js";import{getDomainRange as o}from"../layers/support/domainUtils.js";import{getFieldRange as u}from"../layers/support/fieldUtils.js";import d from"./Widget.js";import p from"./FeatureForm/FeatureFormViewModel.js";import{Heading as c,incrementHeadingLevel as m}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as h}from"./support/decorators/messageBundle.js";import{vmEvent as f}from"./support/decorators/vmEvent.js";import{tsx as _}from"./support/jsxFactory.js";import{DateTime as g}from"luxon";import{getLocale as v}from"../intl/locale.js";const b={base:"esri-feature-form",form:"esri-feature-form__form",formHeader:"esri-feature-form__form-header",label:"esri-feature-form__label",inputField:"esri-feature-form__input",inputDate:"esri-feature-form__input--date",inputTime:"esri-feature-form__input--time",inputRadioGroup:"esri-feature-form__input--radio-group",inputRadio:"esri-feature-form__input--radio",inputRadioLabel:"esri-feature-form__input--radio-label",inputDisabled:"esri-feature-form__input--disabled",inputSwitch:"esri-feature-form__input--switch",inputInvalid:"esri-feature-form__input--invalid",inputIconInvalid:"esri-feature-form__input-icon--invalid",errorMessage:"esri-feature-form__field-error-message",description:"esri-feature-form__description-text",dateInputPart:"esri-feature-form__date-input-part",loneDateInputPart:"esri-feature-form__date-input-part--lone",dateInputContainer:"esri-feature-form__date-input-container",dateFormatHint:"esri-feature-form__date-format-hint",group:"esri-feature-form__group",groupLabel:"esri-feature-form__group-label",groupHeader:"esri-feature-form__group-header",groupHeading:"esri-feature-form__group-header",groupTitle:"esri-feature-form__group-title",groupDescription:"esri-feature-form__group-description",groupToggleIcon:"esri-feature-form__group-toggle-icon",groupCollapsed:"esri-feature-form__group--collapsed",groupSequential:"esri-feature-form__group--sequential",groupActive:"esri-feature-form__group--active",collapseIcon:"esri-icon-up",errorIcon:"esri-icon-notice-triangle",expandIcon:"esri-icon-down",widget:"esri-widget",panel:"esri-widget--panel",input:"esri-input",select:"esri-select"},I={datePattern:"D",timePattern:"tt"};function F(e){return e&&e.inputFields}const y="data-field-name";let w=class extends d{constructor(e,t){super(e,t),this._activeDateFieldEdit=null,this._activeInputName=null,this._activeNumberFieldEdit=null,this._fieldFocusNeeded=!1,this._fieldToInitialIncompatibleDomainValue=new Map,this._switchFieldsWithInitialIncompatibleValue=new Set,this._userUpdatedInputFieldNames=new Set,this.feature=null,this.formTemplate=null,this.groupDisplay="all",this.headingLevel=2,this.label=void 0,this.layer=null,this.messages=null,this.messagesTemplates=null,this.spatialReference=null,this.strict=null,this.viewModel=new p,this._handleSwitchClick=e=>{e.target===e.currentTarget&&e.stopImmediatePropagation()},this._handleRadioInputChange=e=>{this._commitInputValue(e.target)},this._handleInputInput=e=>{this._commitInputValue(e.currentTarget,!0)},this._handleFormKeyDown=this._handleFormKeyDown.bind(this),this._handleInputBlur=this._handleInputBlur.bind(this),this._handleInputFocus=this._handleInputFocus.bind(this),this._handleNumberInputMouseDown=this._handleNumberInputMouseDown.bind(this),this._handleInputKeyDown=this._handleInputKeyDown.bind(this),this._handleOptionChange=this._handleOptionChange.bind(this),this._handleGroupClick=this._handleGroupClick.bind(this),this._handleSubmit=this._handleSubmit.bind(this),this._afterInputCreateOrUpdate=this._afterInputCreateOrUpdate.bind(this)}initialize(){this.own([n((()=>this.feature),(()=>{const e=this._getFocusableInput("forward");this._activeInputName=e&&e.name,this._userUpdatedInputFieldNames.clear(),this._fieldToInitialIncompatibleDomainValue.clear(),this._switchFieldsWithInitialIncompatibleValue.clear(),this._fieldFocusNeeded=!0})),this.on("submit",(e=>{if(e.invalid.length>0){const[t]=e.invalid;e.invalid.forEach((e=>this._userUpdatedInputFieldNames.add(e))),this._activeInputName=t,this._fieldFocusNeeded=!0,this.scheduleRender()}}))])}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-combobox.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item-group.js"),import("@esri/calcite-components/dist/components/calcite-input-message.js"),import("@esri/calcite-components/dist/components/calcite-switch.js")])}destroy(){this._userUpdatedInputFieldNames.clear(),this._userUpdatedInputFieldNames=null}getValues(){return null}submit(){return null}render(){const{state:e}=this.viewModel;return _("div",{class:this.classes(b.base,b.widget,b.panel)},"ready"===e?this.renderForm():null)}renderForm(){const e=this.formTemplate?.title?_(c,{key:"title",level:this.headingLevel},this.formTemplate.title):null,t=this.formTemplate?.description?_("p",{class:b.description,key:"description"},this.formTemplate.description):null,i=e||t?_("div",{class:b.formHeader},e,t):null;return _("form",{class:b.form,novalidate:!0,onsubmit:this._handleSubmit,onkeydown:this._handleFormKeyDown},i,this.renderFields())}renderFields(){const{viewModel:{inputFields:e}}=this;return e.filter((e=>e.visible)).map(((e,t)=>F(e)?this.renderGroup(e,t):this.renderLabeledField(e)))}renderGroup(e,t){const{description:i,inputFields:a,label:n,state:s}=e,l=a.filter((e=>e.visible)),r=this.viewModel.findField(this._activeInputName),o=!(!r||r.group!==e),u=`${this.id}_group_${t}`,d=`${this.id}_group-label_${t}`,p=`${this.id}_group-description_${t}`,h=i?_("p",{class:this.classes(b.groupDescription,b.description),id:p},i):null,f="sequential"===this.groupDisplay,g=f?o:"expanded"===s,v=g?b.collapseIcon:b.expandIcon;return _("fieldset",{"aria-expanded":g.toString(),"aria-labelledby":d,"aria-describedby":i?p:"",class:this.classes(b.group,f?b.groupSequential:null,g?null:b.groupCollapsed,o?b.groupActive:null),"data-group":e,id:u,key:t,onclick:this._handleGroupClick},_("button",{role:f?"presentation":void 0,class:b.groupHeader,type:"button",tabIndex:f?-1:0},_("div",{class:b.groupTitle},_(c,{class:b.groupLabel,id:d,level:this.formTemplate?.title?m(this.headingLevel):this.headingLevel},n),h),f?null:_("span",{class:this.classes(v,b.groupToggleIcon)})),l.map((e=>this.renderLabeledField(e))))}_getFocusableInput(e,t){const i=this.viewModel.allInputFields,a="forward"===e?i:i.slice().reverse();let n;if(t)if(F(t))n=a.indexOf(t.inputFields[0]);else{let i;if(this._isInputFieldInGroup(t)&&"collapsed"===t.group.state){const{inputFields:a}=t.group;i="forward"===e?a[a.length-1]:a[0]}else i=t;n=a.indexOf(i)+1}else n=0;for(let s=n;s<a.length;s++){const e=a[s];if(e.visible)return e}return null}renderLabeledField(e){const{feature:t,label:i,layer:a,type:n}=e;return _("label",{key:`${a.id}-${t.uid}-${e.name}`,class:b.label},[i,"unsupported"!==n?this.renderInputField(e):this.renderUnsupportedField(e),this.renderAuxiliaryText(e)])}renderInputField(e){const{domain:t,name:a,type:n,value:s}=e,l=this.getCommonInputProps(e);if("coded-value"===t?.type){if(this._inputFieldHasInputType(e,"switch")){const{fieldElement:t}=e;if(!(this._switchFieldsWithInitialIncompatibleValue.has(a)||null==s||t.input.onValue!==s&&t.input.offValue!==s))return this.renderSwitchInputField(e,l);this._switchFieldsWithInitialIncompatibleValue.add(a)}return"radio-buttons"===e.inputType?this.renderRadioButtonsInputField(e,t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),l):this.renderSelectInputField(e,this._getFieldValueOptions(a,t),l)}return"datetime-picker"===e.inputType||"date"===n?this.renderDateInputField(e,l):"number"===n?_("input",{type:"number",...l,value:i(this._activeNumberFieldEdit)&&this._activeNumberFieldEdit.fieldName===e.name?this._activeNumberFieldEdit.value:`${l.value}`}):"text-area"===e.inputType?_("textarea",{...l}):_("input",{type:"text",...l})}_parseDateTime(e,t,i){if(i){let a=g.fromJSDate(this._parseDate(e,i));const n=g.fromMillis(t.value??Date.now());return a="date"===i?a.set({hour:n.hour,minute:n.minute,second:n.second}):a.set({day:n.day,month:n.month,year:n.year}),a.isValid?a.toMillis():null}const a=g.fromJSDate(this._parseDate(e));return a.isValid?a.toMillis():null}renderDateInputField(e,t){const{value:i,includeTime:a}=e,{date:n,time:s}=this._formatDate(0),l=`${this.id}-${t.key}`,r=`${l}-date`,o=`${l}-time`,{_activeDateFieldEdit:u}=this;let{date:d,time:p}=this._formatDate(i);return u?.fieldName===e.name&&(d=u.date.input?.value??d,p=u.time.input?.value??p),_("div",{key:`${t.key}-date`,class:b.dateInputContainer},_("div",{class:this.classes(b.dateInputPart,a?null:b.loneDateInputPart)},_("input",{"aria-label":e.label,"aria-describedby":r,type:"text",...t,"data-date-part":"date",class:this.classes(t.class,b.inputDate),value:d}),_("div",{class:b.dateFormatHint,id:r},n)),a?_("div",{class:b.dateInputPart,key:"time-input"},_("input",{"aria-describedby":o,"aria-label":e.label,type:"text",...t,"data-date-part":"time",class:this.classes(t.class,b.inputTime),value:p}),_("div",{class:b.dateFormatHint,id:o},s)):null)}renderUnsupportedField(e){const t=this.getCommonInputProps(e);return _("input",{afterCreate:t.afterCreate,afterUpdate:t.afterUpdate,class:this.classes(b.input,b.inputField,b.inputDisabled),onfocus:t.onfocus,readOnly:!0,tabIndex:t.tabIndex,type:"text",value:t.value,[y]:t[y]})}renderSelectInputField(e,t,i){const{value:n}=e,{messages:s,messagesTemplates:l}=this,r=t.map((e=>e.map((e=>_("calcite-combobox-item",{value:`${e.value}`,"text-label":e.name,key:`#${e.value}`,selected:n===e.value}))))),[o,u]=r;this._registerIncompatibleValue(n,t.flat(),e,(e=>{u.unshift(_("calcite-combobox-item",{value:`${e}`,"text-label":`${e}`,key:"incompatible-option",readOnly:!0}))}));const d=u.length>0?[_("calcite-combobox-item-group",{key:"recommended",label:s.recommended},o),_("calcite-combobox-item-group",{key:"other",label:l.other},u)]:o,p=a(e.fieldElement)||this._inputFieldHasInputType(e,"combo-box")&&e.fieldElement.input.showNoValueOption;if(!e.required&&p){const t="",i=this._inputFieldHasInputType(e,"combo-box")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty;d.unshift(_("calcite-combobox-item",{value:t,"text-label":this.messages.empty,key:"empty-option"},i))}return _("calcite-combobox",{...i,"selection-mode":"single",disabled:i.readOnly,allowCustomValues:!1,onCalciteComboboxChange:e=>this._handleOptionChange(e.target)},d)}_registerIncompatibleValue(e,t,i,a){const n=this._fieldToInitialIncompatibleDomainValue,s=n.has(i.name);(s||null!=e&&""!==e&&!t.some((t=>t.value===e))||s)&&(s||n.set(i.name,e),a?.(n.get(i.name)))}renderRadioButtonsInputField(e,t,i){const{value:n}=e,s=t.map((t=>this.renderRadioButton({key:t.name,label:t.name,name:e.name,value:t.value,selected:t.value===n,props:i})));this._registerIncompatibleValue(n,t,e);const l=a(e.fieldElement)||this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.showNoValueOption;if(!e.required&&l){const t="",a=this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty,l=n===t||null===n;s.unshift(this.renderRadioButton({key:"empty-option",label:a,name:e.name,value:t,selected:l,props:i}))}return _("div",{key:`${i.key}-radio`,class:b.inputRadioGroup},s)}renderSwitchInputField(e,t){const{value:i}=e,a=!!this._inputFieldHasInputType(e,"switch")&&i===e.fieldElement.input.onValue;return _("calcite-switch",{...t,class:b.inputSwitch,onclick:this._handleSwitchClick,checked:a,disabled:t.readOnly})}renderRadioButton({key:e,name:t,value:i,selected:a,label:n,props:s}){return _("label",{key:e,class:b.inputRadioLabel},_("input",{...s,class:b.inputRadio,name:t,type:"radio",value:i,checked:a,onchange:this._handleRadioInputChange}),n)}renderAuxiliaryText(e){const t=this._userUpdatedInputFieldNames.has(e.name)&&!e.valid?e.errorMessage:i(this.viewModel.contingencyConstraintViolations.get(e.name))?this.messages.validationErrors.valuesIncompatible:null;return i(t)?_("calcite-input-message",{status:"invalid",icon:!0,active:!0},t):e.description?_("div",{key:"description",class:b.description},e.description):void 0}getCommonInputProps(e){const{groupDisplay:t}=this,{editable:a,group:n,hint:s,maxLength:l,minLength:r,name:o,required:u,type:d,valid:p,value:c}=e,m=this._userUpdatedInputFieldNames.has(o),h=!a,f="all"===t&&i(n)&&"collapsed"===n.state;return{afterCreate:this._afterInputCreateOrUpdate,afterUpdate:this._afterInputCreateOrUpdate,"aria-invalid":p?"false":"true",class:this.classes(b.input,b.inputField,h?b.inputDisabled:null,m&&!p?b.inputInvalid:null),key:o,label:o,minlength:r>-1?`${r}`:"",maxlength:l>-1?`${l}`:"",...this._getNumberFieldConstraints(e),readOnly:h,value:null==c?"":`${c}`,[y]:o,onfocus:this._handleInputFocus,oninput:this._handleInputInput,onblur:this._handleInputBlur,onkeydown:this._handleInputKeyDown,onmousedown:"number"===d?this._handleNumberInputMouseDown:null,placeholder:"number"===d||"text"===d?s:"",required:u,tabIndex:f?-1:0}}_isInputFieldInGroup(e){return!F(e)&&i(e.group)}_handleNumberInputMouseDown({target:e}){e.focus(),this.scheduleRender()}_getFieldValueOptions(e,t){const i=t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),a=this.viewModel.fieldsWithContingentValues.has(e)?this._getContingentValueOptions(e):[];if(a.length>0){const e=new Set(a.map((e=>e.value)));return[a,i.filter((t=>!e.has(t.value)))]}return[i,[]]}_getContingentValueOptions(e){const t={};for(const s of this.viewModel.allInputFields){const{name:i,value:n}=s;!a(n)&&i!==e&&this.viewModel.fieldsWithContingentValues.has(i)&&(t[i]=n)}const i=this.viewModel.joinedContingentValues.slice(),n=new Map;for(const s of i){const i=s.values[e];if(a(i)||"code"!==i.objectType&&"null"!==i.objectType)continue;const{code:l,name:r}="null"===i.objectType?{code:"",name:this.messages.empty}:i.codedValue;if(n.has(l))continue;Object.entries(t).every((([e,t])=>!s.values.hasOwnProperty(e)||this._valueIsValidContingentValue(t,s.values[e])))&&n.set(l,{name:r,value:l})}return[...n.values()]}_getInputFieldFromInput(e){return this.viewModel.findField(e.getAttribute(y))}_getNumberFieldConstraints(e){const t=o(e.domain)||u(e.field);return t&&t.max!==Number.MAX_VALUE&&t.min!==Number.MIN_VALUE?t:{min:null,max:null}}_afterInputCreateOrUpdate(e){const{viewModel:t}=this,i=this._getInputFieldFromInput(e),a=t.findField(this._activeInputName),n=this._fieldToInitialIncompatibleDomainValue.get(i.name)===i.value;this._fieldFocusNeeded&&a===i&&("radio-buttons"!==i.inputType||n||e.checked)&&(this._fieldFocusNeeded=!1,e.focus())}_handleInputFocus(e){const t=e.target,i=this._getInputFieldFromInput(t);this._activeInputName=i.name,"date"===i.type?this._syncDateFieldEdits(t):this._isNumberInputField(i)&&this._setUpNumberFieldEdit(t)}_isNumberInputField({domain:e,inputType:t="text-box",type:i}){return"number"===i&&"text-box"===t&&(!e||"coded-value"!==e.type)}_handleInputBlur(e){const t=e.target,a=this._getInputFieldFromInput(t);if("date"===a.type){const i=e.relatedTarget,n=i&&this._getInputFieldFromInput(i);if(n&&"date"===a.type&&"date"===n.type&&a.field===n.field){if(""!==t.value&&""===i.value){const n=i.getAttribute("data-date-part");i.value=this._formatDate(a.value??Date.now())[n],this._parseDate(t.value,t.getAttribute("data-date-part"))&&this._commitInputValue(e.target,!0,!1)}return}}"number"===a.type&&i(this._activeNumberFieldEdit)&&(this._activeNumberFieldEdit.input.value=`${a.value}`,this._activeNumberFieldEdit=null),this._commitInputValue(t),this.scheduleRender()}_commitInputValue(e,t=!1,a=!0){const n=this._getInputFieldFromInput(e);if(this._activeDateFieldEdit){const{date:i,time:s}=this._activeDateFieldEdit,l=this._parseDateTime(e.value,n,i.active?"date":"time"),r=null!==this.viewModel.getValue(n.name),o=i.input&&(s.input||!n.includeTime),u=null===l;if(t){if(u)return;(o||!a||r)&&this._updateDateFieldValue(n,l)}else{if(""===i.input?.value||""===s.input?.value)this._updateDateFieldValue(n,null);else if(o){const e=`${i.input.value} ${s.input?.value??""}`,t=this._parseDateTime(e,n);!(null!==t)&&r||this._updateDateFieldValue(n,t)}this._activeDateFieldEdit=null}}else i(this._activeNumberFieldEdit)&&this._isNumberInputField(n)&&(this._activeNumberFieldEdit.value=e.value),this._updateFieldValue(e)}_handleInputKeyDown(e){const{key:t,altKey:i,ctrlKey:a,metaKey:n}=e,s=this._getInputFieldFromInput(e.target);if("Enter"===t)this._isInputFieldInGroup(s)&&"collapsed"===s.group.state&&(s.group.state="expanded");else{const{type:l}=s.field,r="single"===l||"double"===l,o=!i&&!a&&!n;if(("integer"===l||"small-integer"===l||r)&&o&&1===t.length){const i=Number(t),a=["-","+"],n=["e","."],s=r?[...a,...n]:a;isNaN(i)&&!s.includes(t)&&e.preventDefault()}}}_setUpNumberFieldEdit(e){const t=this._getInputFieldFromInput(e);this._activeNumberFieldEdit={fieldName:t.name,input:e,value:e.value}}_syncDateFieldEdits(e){const t=this._getInputFieldFromInput(e);if("date"!==t.type)return;const i=e.getAttribute("data-date-part"),a="date"===i?{value:e.value,input:e,active:!0}:{...this._activeDateFieldEdit?.date,active:!1},n="time"===i?{value:e.value,input:e,active:!0}:{...this._activeDateFieldEdit?.time,active:!1};this._activeDateFieldEdit={fieldName:t.name,date:a,time:n}}_updateFieldValue(e){const t=e.getAttribute(y);if(this.viewModel.setValue(t,this._parseValue(e)),this._userUpdatedInputFieldNames.add(t),this.viewModel.fieldsWithContingentValues.has(t)){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>i(t))));this.viewModel.validateContingencyConstraints(e)}}_updateDateFieldValue(e,t){this.viewModel.setValue(e.name,t),this._userUpdatedInputFieldNames.add(e.name)}_parseValue(e){const t=this._getInputFieldFromInput(e),i=e.value;if(this._inputFieldHasInputType(t,"switch")&&"CALCITE-COMBOBOX"!==e.tagName)return e.checked?t.fieldElement.input.onValue:t.fieldElement.input.offValue;if("radio-buttons"===t.inputType&&"radio"===e.type&&!e.checked)return t.value;const{type:a}=t;if("number"===a)return i?parseFloat(i):null;if("date"===a){if(!i)return null;const a=Number(i);if(!isNaN(a))return a;const n=e.getAttribute("data-date-part"),s=this._parseDate(i,n);if(!s)return null;let l=g.fromJSDate(s);const r=t.domain,o=g.now();let u=o;if(r&&"range"===r.type){const e=g.fromMillis(r.maxValue);o<e&&(u=e)}const d=this.viewModel.getValue(t.name),p=null!=d?g.fromMillis(d):u;return l="date"===n?l.set({hour:p.hour,minute:p.minute,second:p.second}):l.set({day:p.day,month:p.month,year:p.year}),l.toMillis()}return i}_handleOptionChange(e){this._commitInputValue(e),this.scheduleRender()}_handleGroupClick(e){const t=e.currentTarget["data-group"],i="expanded"===t.state,a="sequential"===this.groupDisplay,n=`.${b.groupHeader}`;if(!(i&&!e.target.closest(n))){if(this._activeInputName=this._getFocusableInput("forward",t)?.name,a){const a=e.target.closest(n);if(i&&!a)return;this.viewModel.inputFields.forEach((e=>{F(e)&&e!==t&&(e.state="collapsed")}))}t.state=i?"collapsed":"expanded",this._fieldFocusNeeded=a,this.scheduleRender()}}_handleSubmit(e){e.preventDefault()}_handleFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_formatDate(e){if(null==e)return{date:"",time:""};const t=g.fromMillis(e,{locale:v(),numberingSystem:"latn"});return{date:t.toLocaleString({year:"numeric",month:"2-digit",day:"2-digit"}),time:t.toFormat(I.timePattern)}}_parseDate(e,t){if(null==e||""===e)return null;const{timePattern:i,datePattern:a}=I,n=t?"date"===t?a:i:`${a} ${i}`,s=g.fromFormat(e,n,{locale:v(),numberingSystem:"latn"});return s.isValid?s.toJSDate():null}_inputFieldHasInputType(e,t){return i(e.fieldElement)&&e.fieldElement.input?.type===t}_valueIsValidContingentValue(e,i){switch(i.objectType){case"any":return!0;case"null":return null==e;case"code":return e===i.codedValue?.code;case"range":return e>=i.minValue&&e<=i.maxValue;default:return t(i.objectType),!1}}};e([s("viewModel.feature")],w.prototype,"feature",void 0),e([s("viewModel.formTemplate")],w.prototype,"formTemplate",void 0),e([l()],w.prototype,"groupDisplay",void 0),e([l()],w.prototype,"headingLevel",void 0),e([l({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],w.prototype,"label",void 0),e([s("viewModel.layer")],w.prototype,"layer",void 0),e([l(),h("esri/widgets/FeatureForm/t9n/FeatureForm")],w.prototype,"messages",void 0),e([l(),h("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],w.prototype,"messagesTemplates",void 0),e([s("viewModel.spatialReference")],w.prototype,"spatialReference",void 0),e([s("viewModel.strict")],w.prototype,"strict",void 0),e([l(),f(["value-change","submit"])],w.prototype,"viewModel",void 0),e([s("viewModel.getValues")],w.prototype,"getValues",null),e([s("viewModel.submit")],w.prototype,"submit",null),w=e([r("esri.widgets.FeatureForm")],w);const V=w;export{V as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import t from"../../core/Error.js";import{getDateTimeFormatter as e,formatDate as r}from"../../intl/date.js";import{getLanguage as n}from"../../intl/locale.js";function o(t,r){const n=e(r),o=Date.now(),c=n.formatToParts(o),l=new Set;c.filter((({type:t})=>"literal"===t)).forEach((({value:t})=>l.add(t)));let s=0;const f={};for(;c.length>0;){const{type:e,value:r}=c.shift();for(let n=0;n<r.length;n++,s++){const r=t.charAt(s);if(l.has(r)){s++;break}if("literal"===e)break;f[e]||(f[e]=[]),f[e].push(r)}}const h={};try{h.day=a(f.day.join("")),h.month=a(f.month.join(""))
|
|
5
|
+
import t from"../../core/Error.js";import{getDateTimeFormatter as e,formatDate as r}from"../../intl/date.js";import{getLanguage as n}from"../../intl/locale.js";function o(t,r){const n=e(r),o=Date.now(),c=n.formatToParts(o),l=new Set;c.filter((({type:t})=>"literal"===t)).forEach((({value:t})=>l.add(t)));let s=0;const f={};for(;c.length>0;){const{type:e,value:r}=c.shift();for(let n=0;n<r.length;n++,s++){const r=t.charAt(s);if(l.has(r)){s++;break}if("literal"===e)break;f[e]||(f[e]=[]),f[e].push(r)}}const h={};try{h.day=a(f.day.join("")),h.month=a(f.month.join("")),h.year=a((f.year||f.relatedYear).join(""))}catch(u){throw i(r)}if(isNaN(h.day)||isNaN(h.month)||isNaN(h.year))throw i(r);return h}function a(t){const e=[/٠/g,/١/g,/٢/g,/٣/g,/٤/g,/٥/g,/٦/g,/٧/g,/٨/g,/٩/g];for(let r=0;r<10;r++)t=t.replace(e[r],r.toString());return Number(t)}function i(e){return new t(`could not parse date input, expecting the following format: ${r(Date.now(),e)}`)}const c={ar:6,"ar-dz":6,"ar-kw":6,"ar-ly":6,"ar-ma":1,"ar-sa":7,"ar-tn":1,bg:1,bs:1,ca:1,cs:1,da:1,de:1,"de-at":1,"de-ch":1,el:1,"en-au":1,"en-ca":7,"en-gb":1,"en-ie":1,"en-il":7,"en-in":7,"en-nz":1,"en-sg":7,es:1,"es-do":7,"es-mx":7,"es-us":7,et:1,fi:1,fr:1,"fr-ca":7,"fr-ch":1,he:7,hr:1,hu:1,id:7,it:1,"it-ch":1,ja:7,ko:7,lt:1,lv:1,nb:1,nl:1,"nl-be":1,pl:1,pt:7,"pt-br":7,ro:1,ru:1,sk:1,sl:1,sr:1,"sr-cyrl":1,sv:1,th:7,tr:1,uk:1,vi:1,"zh-cn":7,"zh-hk":7,"zh-mo":7,"zh-tw":7},l="Locale"in Intl&&"weekInfo"in Intl.Locale.prototype;function s(t){if(t=t.toLowerCase(),c[t])return c[t];if(l)try{const e=new Intl.Locale(t).weekInfo.firstDay;return c[t]=e,e}catch{}const e=n(t);return c[e]?c[e]:7}function f(t,e){return(e+7-s(t))%7}export{s as getFirstDayOfWeek,f as getLocaleDayOfWeek,o as parseDateIntoParts};
|