@arcgis/core 4.23.4 → 4.23.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/74b3b2d6b8d33d778469.js +1 -0
- package/config.js +1 -1
- package/copyright.txt +2 -2
- package/interfaces.d.ts +19 -19
- package/package.json +1 -1
- package/support/revision.js +1 -1
- package/views/2d/engine/webgl/definitions.js +1 -1
- package/views/2d/engine/webgl/effects/HittestEffect.js +1 -1
- package/views/2d/engine/webgl/effects/HittestEffectVTL.js +1 -1
- package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
- package/views/2d/layers/features/support/FeatureSetReaderPBF.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.js +1 -1
- package/widgets/support/SnappingControls.js +1 -1
- package/assets/esri/core/workers/chunks/410e9b40a2b7f88ea669.js +0 -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.23/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}from"../core/reactiveUtils.js";import{init as r,on as o,watch as n,whenNot as l}from"../core/watchUtils.js";import{aliasOf as d}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import{cast as c}from"../core/accessorSupport/decorators/cast.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import{subclass as h}from"../core/accessorSupport/decorators/subclass.js";import{getDisplayFieldName as m}from"../layers/support/fieldUtils.js";import u from"../views/interactive/snapping/SnappingOptions.js";import g from"./Attachments.js";import v from"./FeatureForm.js";import _ from"./FeatureTemplates.js";import w from"./Spinner.js";import f from"./Widget.js";import{workflowDeprecation as k}from"./Editor/deprecationUtils.js";import y from"./Editor/EditorViewModel.js";import{ItemList as b}from"./FeatureTemplates/ItemList.js";import{Heading as C,incrementHeadingLevel as M}from"./support/Heading.js";import F from"./support/SnappingControls.js";import{accessibleHandler as A}from"./support/decorators/accessibleHandler.js";import{messageBundle as W}from"./support/decorators/messageBundle.js";import{vmEvent as T}from"./support/decorators/vmEvent.js";import{tsx as S}from"./support/jsxFactory.js";import{classes as E}from"./support/widgetUtils.js";import{substitute as B}from"../intl/substitute.js";const P={base:"esri-editor esri-widget esri-widget--panel",scroller:"esri-editor__scroller",content:"esri-editor__content",contentGroup:"esri-editor__content-group",message:"esri-editor__message",controls:"esri-editor__controls",progressBar:"esri-editor__progress-bar",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",promptOption:"esri-editor__prompt__option",promptOptionPrimary:"esri-editor__prompt__option--primary",promptOptionNegative:"esri-editor__prompt__option--negative",promptOptionPositive:"esri-editor__prompt__option--positive",controlButton:"esri-editor__control-button",overlay:"esri-editor__overlay",warningIcon:"esri-icon-notice-triangle",widgetIcon:"esri-icon-edit",button:"esri-button",buttonDisabled:"esri-button--disabled",buttonSecondary:"esri-button--secondary",buttonTertiary:"esri-button--tertiary",input:"esri-input",interactive:"esri-interactive",select:"esri-select",panelToolbar:"esri-editor__panel-toolbar",panelToolbarSnappingButton:"esri-editor__panel-toolbar__snapping-button",panelContent:"esri-editor__panel-content",panelContentSection:"esri-editor__panel-content--section",updateFeaturesActionButtons:"esri-editor__update-features-action-buttons",updateFeaturesActionButtonsButton:"esri-editor__update-features-action-buttons--button",featureTemplatesContainer:"esri-editor__feature-templates-container",snappingControlsPopover:"esri-editor__snapping-controls-popover",scrimOverlay:"esri-editor__scrim-overlay"},j={undoRedoButtons:!1};function L(e){e.focus()}const x="esri.widgets.Editor",U=s.getLogger(x);let V=class extends(t(f)){constructor(e,t){super(e,t),this._candidateCommitted=!1,this._featureForm=new v,this._stateStack=[],this._attachments=new g({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 w,this._snappingPopover=null,this.activeWorkflow=null,this.allowedWorkflows=null,this.useDeprecatedCreateWorkflow=!1,this.headingLevel=4,this.iconClass=P.widgetIcon,this.label=void 0,this.layerInfos=null,this.messages=null,this.messagesCommon=null,this.messagesTemplates=null,this.snappingOptions=new u,this.supportingWidgetDefaults=null,this.view=null,this.viewModel=new y,this.visibleElements={...j},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([r(this,"headingLevel",(e=>{this._featureForm.headingLevel=M(e),this._featureTemplates.headingLevel=M(e)})),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)})),r(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(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"})})),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()})),r(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))})),n(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}}}}})),n(this,"viewModel.failures",(e=>{if(!e)return;const{messages:t}=this,[{error:s,retry:i,cancel:a}]=e;this._prompt={title:t.errorWarningTitle,message:B(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)}}}})),n(this,"viewModel.state",(e=>{"awaiting-feature-to-update"===e&&(this._filterText=""),"awaiting-update-feature-candidate"===e&&(this._candidateCommitted=!1)})),n(this,["_attachments.selectedFile","_attachments.submitting"],(()=>this.scheduleRender())),l(this,"viewModel.activeWorkflow",(()=>this._featureTemplates.filterText=""))])}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-popover-manager.js"),import("@esri/calcite-components/dist/components/calcite-scrim.js"),import("@esri/calcite-components/dist/components/calcite-tooltip-manager.js")])}castVisibleElements(e){return{...j,...e}}startCreateWorkflowAtFeatureTypeSelection(){return k(U,"startCreateWorkflowAtFeatureTypeSelection","startCreateFeaturesWorkflowAtFeatureTypeSelection"),this.viewModel.startCreateWorkflowAtFeatureTypeSelection()}startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.viewModel.startCreateFeaturesWorkflowAtFeatureTypeSelection()}startCreateWorkflowAtFeatureCreation(e){return k(U,"startCreateWorkflowAtFeatureCreation","startCreateFeaturesWorkflowAtFeatureCreation"),this.viewModel.startCreateWorkflowAtFeatureCreation(e)}startCreateFeaturesWorkflowAtFeatureCreation(e){return this.viewModel.startCreateFeaturesWorkflowAtFeatureCreation(e)}startCreateWorkflowAtFeatureEdit(e){return k(U,"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 S("div",{class:P.base});const{state:a}=s,r=i(t)?S("calcite-scrim",null,this.renderPrompt(t)):null;return S("div",{class:P.base},s.syncing||e.submitting?this.renderProgressBar():null,S("calcite-flow",null,this._stateStack.map((e=>this.renderState(e))),this.renderState(a)),r)}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 S("div",null)}isPanelActive(e){return this.viewModel.state===e}renderTemplates(e){const{EditorPanel:t,headingLevel:s,messages:i,messagesCommon:a,_handleBack:r,_snappingControls:o,viewModel:{sketchViewModel:n}}=this;return S(t,{active:this.isPanelActive(e),key:"templates-panel",handleBack:r,heading:i.selectTemplate,headingLevel:s,messages:i,messagesCommon:a,sketchViewModel:n,snappingControls:o},this._featureTemplates.render())}renderAttributeEditing(e){const{activeWorkflow:t,EditorPanel:s,messages:i,messagesCommon:a,headingLevel:r,_handleBack:o,_snappingControls:n,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||c.inputFields.length>0&&!c.submittable,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=[{label:"create-features"===t.type&&t.numPendingFeatures>1?B(i.createFeaturesTemplate,{numFeatures:t.numPendingFeatures}):m,type:"primary",disabled:p,clickHandler:this._handleSave}];let v=!1;return"update"===t.type&&(t.data.editableItem.hasAttachments&&(v=!0),t.data.editableItem.supports.includes("delete")&&g.push({label:a.delete,type:"tertiary",clickHandler:this._handleDelete})),S(s,{active:this.isPanelActive(e),key:"attribute-editing-panel",heading:h,headingLevel:r,showContentScrim:u,handleBack:o,messages:i,messagesCommon:a,sketchViewModel:d,snappingControls:n},S("div",{class:P.panelContentSection},S("div",{class:P.contentGroup},c.inputFields.length>0?this._featureForm.render():this.renderMessage(B(i.clickToFinishTemplate,{button:m})),v?S("div",{key:"attachments"},S("div",null,i.attachments),this._attachments.render()):null)),S("div",{class:this._prompt?"":P.scrimOverlay},this.renderControls(g)))}renderAttachmentAdding(e){const{_attachments:t,EditorPanel:s,_handleBack:i,headingLevel:a,messages:r,messagesCommon:o,_snappingControls:n,viewModel:{sketchViewModel:l}}=this,d=[{label:t.submitting?o.cancel:o.add,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentAdd}];return S(s,{active:this.isPanelActive(e),key:"attachment-adding-panel",heading:r.addAttachment,headingLevel:a,handleBack:i,messages:r,messagesCommon:o,sketchViewModel:l,snappingControls:n},S("div",{class:this.classes(P.content,P.scroller)},t.render()),this.renderControls(d))}renderAttachmentEditing(e){const{_attachments:t,EditorPanel:s,_handleBack:i,headingLevel:a,messages:r,messagesCommon:o,_snappingControls:n,viewModel:{sketchViewModel:l}}=this,d=[{label:o.update,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentUpdate},{label:o.delete,disabled:t.submitting,type:"tertiary",clickHandler:this._handleAttachmentDelete}];return S(s,{active:this.isPanelActive(e),key:"attachment-editing-panel",heading:r.editAttachment,headingLevel:a,handleBack:i,messages:r,messagesCommon:o,sketchViewModel:l,snappingControls:n},S("div",{class:this.classes(P.content,P.scroller)},t.render()),this.renderControls(d))}renderFeatureUpdating(e){const{EditorPanel:t,_handleBack:s,headingLevel:i,messages:a,messagesCommon:r,_snappingControls:o,viewModel:{sketchViewModel:n}}=this;return S(t,{active:this.isPanelActive(e),key:"feature-updating-panel",heading:a.selectFeature,headingLevel:i,handleBack:s,messages:a,messagesCommon:r,sketchViewModel:n,snappingControls:o},S("div",{class:this.classes(P.content,P.scroller)},this.renderMessage(a.selectFeatureToEdit)))}renderMessage(e){return S("div",{class:P.message},e)}renderFeatureCreation(e){const{EditorPanel:t,_handleBack:s,headingLevel:i,messages:a,messagesCommon:r,_snappingControls:o,viewModel:n}=this,{sketchViewModel:l}=n,d=n.sketchViewModel,c=this._assertActiveCreateWorkflow().data.creationInfo.layer,p=d.canUndo()&&d.createGraphic?d.createGraphic:null,h=this._getSketchingTip(c.geometryType,p);return S(t,{active:this.isPanelActive(e),key:"feature-creation-panel",heading:a.placeFeature,headingLevel:i,handleBack:s,messages:a,messagesCommon:r,sketchViewModel:l,snappingControls:o},S("div",{class:this.classes(P.content,P.scroller)},this.renderMessage(h)))}renderControls(e){return S("div",{class:P.controls,key:"controls"},e.map((({disabled:e=!1,label:t,type:s,clickHandler:i},a)=>this.renderButton({label:t,class:this.classes(P.controlButton,P.button,"secondary"===s?P.buttonSecondary:"tertiary"===s?P.buttonTertiary:null,e?P.buttonDisabled:null),disabled:e,clickHandler:i,key:a}))))}renderPrompt({title:e,message:t,context:s,actions:i}){const a=!!i.secondary,r=S("calcite-button",{appearance:"solid",color:"danger"===s?"red":"blue",width:a?"half":"full",onclick:i.primary.action,key:"prompt-primary-button",afterCreate:L},i.primary.label),o=a?S("calcite-button",{appearance:"clear",color:"danger"===s?"red":"blue",width:"half",onclick:i.secondary.action,key:"prompt-secondary-button"},i.secondary.label):null;return S("div",{class:`${P.promptContainer}--${s}`},S("div",{class:P.promptHeader},S("calcite-icon",{icon:"exclamation-mark-triangle"}),S(C,{class:P.promptHeading,level:this.headingLevel},e)),S("div",{class:P.promptMessage},t),S("div",{class:P.promptDivider}),S("div",{class:P.promptActions},o,r))}renderProgressBar(){return S("div",{class:this.classes(P.progressBar),key:"progress-bar"})}renderButton(e){return S("button",{class:e.class,disabled:e.disabled,key:e.key,onclick:e.clickHandler,type:"button"},e.label)}renderLanding(e){const{EditorPanel:t,headingLevel:s,messages:i,messagesCommon:a,_snappingControls:r,viewModel:{sketchViewModel:o}}=this;return S(t,{active:this.isPanelActive(e),key:"landing-panel",heading:i.widgetLabel,headingLevel:s,showBackButton:!1,messages:i,messagesCommon:a,sketchViewModel:o,snappingControls:r},S("div",{key:"edit-actions",class:P.panelContentSection},this.renderUpdateActions()),S("div",{key:"create-actions",class:P.panelContentSection},this.renderCreateActions()))}renderUpdateActions(){const{messages:e,messagesCommon:t}=this;return S("div",null,S(C,{level:M(this.headingLevel)},e.editFeatures),S("div",{class:P.updateFeaturesActionButtons},S("calcite-action",{text:t.select,textEnabled:!0,icon:"cursor",alignment:"start",class:P.updateFeaturesActionButtonsButton,onclick:this._handleEdit})))}renderCreateActions(){const{messages:e}=this;return S("div",null,S(C,{level:M(this.headingLevel)},e.createFeatures),S("div",{key:"templates",class:P.featureTemplatesContainer},this._featureTemplates.render()))}renderFeatureList(e){const{EditorPanel:t,_handleBack:s,headingLevel:i,messages:a,messagesCommon:r,messagesTemplates:o,_snappingControls:n,viewModel:{editableItems:l,sketchViewModel:d}}=this,c=this._assertActiveUpdateWorkflow().data.candidates,p=B(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,r=this.viewModel.editableItems.find((e=>e.layer===s.layer));return r.supports.indexOf("update")>-1&&(!i||t.toLowerCase().indexOf(i)>-1||a.toLowerCase().indexOf(i)>-1)})).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 S(t,{active:this.isPanelActive(e),key:"feature-list",heading:p,headingLevel:i,handleBack:s,messages:a,messagesCommon:r,sketchViewModel:d,snappingControls:n},b({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:i,heading:a,headingLevel:r,key:o,messages:n,messagesCommon:l,showBackButton:d,showContentScrim:c,sketchViewModel:p,snappingControls:h}=e;return S("calcite-panel",{bind:this,key:o,heading:a,headingLevel:r,showBackButton:null==d||d,beforeBack:null!=i?i:null,onCalcitePanelScroll:this._onSnappingPopoverPanelScroll},S("calcite-popover-manager",{autoClose:s,class:P.panelToolbar},S("calcite-popover",{afterCreate:this._afterSnappingPopoverCreated,afterUpdate:this._afterSnappingPopoverUpdated,bind:this,label:n.snappingSettings,heading:n.snappingSettings,"reference-element":`${o}__snappingButton`,"overlay-positioning":"fixed"},S("div",{class:P.snappingControlsPopover},h.render())),S("calcite-button",{id:`${o}__snappingButton`,text:n.snapping,appearance:"transparent",color:"neutral",alignment:"icon-end-space-between","icon-start":"vertex-gps","icon-end":"caret-down",width:"full",class:P.panelToolbarSnappingButton},n.snapping),this.visibleElements.undoRedoButtons?[S("calcite-button",{key:"undo-button",text:l.undo,appearance:"transparent",color:"neutral",alignment:"center","icon-start":"undo",scale:"l",disabled:!p.canUndo(),onclick:p.undo.bind(p)}),S("calcite-button",{key:"redo-button",text:l.redo,appearance:"transparent",color:"neutral",alignment:"center","icon-start":"redo",scale:"l",disabled:!p.canRedo(),onclick:p.redo.bind(p)})]:null),S("div",{class:E(P.panelContent,P.scroller)},t,c?S("calcite-scrim",null):null))}_onSnappingPopoverPanelScroll(){var e;null!=(e=this._snappingPopover)&&e.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 i=t.geometry,a="polygon"===e?"rings":"paths",[r]=i[a];return"polygon"===e&&r<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=m(t);return a&&i[a]&&`${i[a]}`||B(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(){this.viewModel.featureFormViewModel.validateContingencyConstraints(this.viewModel.featureFormViewModel.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||"update"===t.type&&t.data.edits.modified){const{type:i}=t,a="create"===i?e.cancelAddWarningMessage:e.cancelEditWarningMessage,r="create"===i?e.cancelAddTitle:e.cancelEditTitle,o="create"===i?e.continueAdding:e.continueEditing,n="create"===i?e.discardFeature:e.discardEdits;return this._prompt={title:r,message:a,context:"danger",actions:{primary:{label:n,action:()=>{s(),this._prompt=null}},secondary:{label:o,action:()=>this._prompt=null}}},this.scheduleRender(),Promise.reject()}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([p()],V.prototype,"_attachments",void 0),e([d("viewModel.activeWorkflow")],V.prototype,"activeWorkflow",void 0),e([d("viewModel.allowedWorkflows")],V.prototype,"allowedWorkflows",void 0),e([p()],V.prototype,"useDeprecatedCreateWorkflow",void 0),e([p()],V.prototype,"headingLevel",void 0),e([p()],V.prototype,"iconClass",void 0),e([p({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],V.prototype,"label",void 0),e([d("viewModel.layerInfos")],V.prototype,"layerInfos",void 0),e([p(),W("esri/widgets/Editor/t9n/Editor")],V.prototype,"messages",void 0),e([p(),W("esri/t9n/common")],V.prototype,"messagesCommon",void 0),e([p(),W("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],V.prototype,"messagesTemplates",void 0),e([d("viewModel.snappingOptions")],V.prototype,"snappingOptions",void 0),e([p()],V.prototype,"supportingWidgetDefaults",void 0),e([d("viewModel.view")],V.prototype,"view",void 0),e([p(),T(["workflow-cancel","workflow-commit"])],V.prototype,"viewModel",void 0),e([p()],V.prototype,"visibleElements",void 0),e([c("visibleElements")],V.prototype,"castVisibleElements",null),e([A()],V.prototype,"_handleDelete",null),e([A()],V.prototype,"_handleAttachmentAdd",null),e([A()],V.prototype,"_handleAttachmentUpdate",null),e([A()],V.prototype,"_handleAttachmentDelete",null),e([A()],V.prototype,"_handleAdd",null),e([A()],V.prototype,"_handleEdit",null),e([A()],V.prototype,"_handleDone",null),V=e([h(x)],V);const D=V;export{D 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 i}from"../core/maybe.js";import{watch as a}from"../core/reactiveUtils.js";import{init as r,on as o,watch as n,whenNot as l}from"../core/watchUtils.js";import{aliasOf as d}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import{cast as c}from"../core/accessorSupport/decorators/cast.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import{subclass as h}from"../core/accessorSupport/decorators/subclass.js";import{getDisplayFieldName as m}from"../layers/support/fieldUtils.js";import u from"../views/interactive/snapping/SnappingOptions.js";import g from"./Attachments.js";import v from"./FeatureForm.js";import _ from"./FeatureTemplates.js";import w from"./Spinner.js";import f from"./Widget.js";import{workflowDeprecation as k}from"./Editor/deprecationUtils.js";import y from"./Editor/EditorViewModel.js";import{ItemList as b}from"./FeatureTemplates/ItemList.js";import{Heading as C,incrementHeadingLevel as M}from"./support/Heading.js";import A from"./support/SnappingControls.js";import{accessibleHandler as F}from"./support/decorators/accessibleHandler.js";import{messageBundle as W}from"./support/decorators/messageBundle.js";import{vmEvent as T}from"./support/decorators/vmEvent.js";import{tsx as S}from"./support/jsxFactory.js";import{classes as E}from"./support/widgetUtils.js";import{substitute as B}from"../intl/substitute.js";const P={base:"esri-editor esri-widget esri-widget--panel",scroller:"esri-editor__scroller",content:"esri-editor__content",contentGroup:"esri-editor__content-group",message:"esri-editor__message",controls:"esri-editor__controls",progressBar:"esri-editor__progress-bar",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",promptOption:"esri-editor__prompt__option",promptOptionPrimary:"esri-editor__prompt__option--primary",promptOptionNegative:"esri-editor__prompt__option--negative",promptOptionPositive:"esri-editor__prompt__option--positive",controlButton:"esri-editor__control-button",overlay:"esri-editor__overlay",warningIcon:"esri-icon-notice-triangle",widgetIcon:"esri-icon-edit",button:"esri-button",buttonDisabled:"esri-button--disabled",buttonSecondary:"esri-button--secondary",buttonTertiary:"esri-button--tertiary",input:"esri-input",interactive:"esri-interactive",select:"esri-select",panelToolbar:"esri-editor__panel-toolbar",panelToolbarSnappingButton:"esri-editor__panel-toolbar__snapping-button",panelContent:"esri-editor__panel-content",panelContentSection:"esri-editor__panel-content--section",updateFeaturesActionButtons:"esri-editor__update-features-action-buttons",updateFeaturesActionButtonsButton:"esri-editor__update-features-action-buttons--button",featureTemplatesContainer:"esri-editor__feature-templates-container",snappingControlsPopover:"esri-editor__snapping-controls-popover",scrimOverlay:"esri-editor__scrim-overlay"},j={undoRedoButtons:!1};function L(e){e.focus()}const x="esri.widgets.Editor",U=s.getLogger(x);let V=class extends(t(f)){constructor(e,t){super(e,t),this._candidateCommitted=!1,this._featureForm=new v,this._stateStack=[],this._attachments=new g({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 w,this._snappingPopover=null,this.activeWorkflow=null,this.allowedWorkflows=null,this.useDeprecatedCreateWorkflow=!1,this.headingLevel=4,this.iconClass=P.widgetIcon,this.label=void 0,this.layerInfos=null,this.messages=null,this.messagesCommon=null,this.messagesTemplates=null,this.snappingOptions=new u,this.supportingWidgetDefaults=null,this.view=null,this.viewModel=new y,this.visibleElements={...j},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 A({snappingOptions:t,view:e,visibleElements:{header:!1}}),this.own([r(this,"headingLevel",(e=>{this._featureForm.headingLevel=M(e),this._featureTemplates.headingLevel=M(e)})),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)})),r(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(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"})})),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()})),r(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))})),n(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}}}}})),n(this,"viewModel.failures",(e=>{if(!e)return;const{messages:t}=this,[{error:s,retry:i,cancel:a}]=e;this._prompt={title:t.errorWarningTitle,message:B(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)}}}})),n(this,"viewModel.state",(e=>{"awaiting-feature-to-update"===e&&(this._filterText=""),"awaiting-update-feature-candidate"===e&&(this._candidateCommitted=!1)})),n(this,["_attachments.selectedFile","_attachments.submitting"],(()=>this.scheduleRender())),l(this,"viewModel.activeWorkflow",(()=>this._featureTemplates.filterText=""))])}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-popover-manager.js"),import("@esri/calcite-components/dist/components/calcite-scrim.js"),import("@esri/calcite-components/dist/components/calcite-tooltip-manager.js")])}castVisibleElements(e){return{...j,...e}}startCreateWorkflowAtFeatureTypeSelection(){return k(U,"startCreateWorkflowAtFeatureTypeSelection","startCreateFeaturesWorkflowAtFeatureTypeSelection"),this.viewModel.startCreateWorkflowAtFeatureTypeSelection()}startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.viewModel.startCreateFeaturesWorkflowAtFeatureTypeSelection()}startCreateWorkflowAtFeatureCreation(e){return k(U,"startCreateWorkflowAtFeatureCreation","startCreateFeaturesWorkflowAtFeatureCreation"),this.viewModel.startCreateWorkflowAtFeatureCreation(e)}startCreateFeaturesWorkflowAtFeatureCreation(e){return this.viewModel.startCreateFeaturesWorkflowAtFeatureCreation(e)}startCreateWorkflowAtFeatureEdit(e){return k(U,"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 S("div",{class:P.base});const{state:a}=s,r=i(t)?S("calcite-scrim",null,this.renderPrompt(t)):null;return S("div",{class:P.base},s.syncing||e.submitting?this.renderProgressBar():null,S("calcite-flow",null,this._stateStack.map((e=>this.renderState(e))),this.renderState(a)),r)}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 S("div",null)}isPanelActive(e){return this.viewModel.state===e}renderTemplates(e){const{EditorPanel:t,headingLevel:s,messages:i,messagesCommon:a,_handleBack:r,_snappingControls:o,viewModel:{sketchViewModel:n}}=this;return S(t,{active:this.isPanelActive(e),key:"templates-panel",handleBack:r,heading:i.selectTemplate,headingLevel:s,messages:i,messagesCommon:a,sketchViewModel:n,snappingControls:o},this._featureTemplates.render())}renderAttributeEditing(e){const{activeWorkflow:t,EditorPanel:s,messages:i,messagesCommon:a,headingLevel:r,_handleBack:o,_snappingControls:n,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=[{label:"create-features"===t.type&&t.numPendingFeatures>1?B(i.createFeaturesTemplate,{numFeatures:t.numPendingFeatures}):m,type:"primary",disabled:p,clickHandler:this._handleSave}];let v=!1;return"update"===t.type&&(t.data.editableItem.hasAttachments&&(v=!0),t.data.editableItem.supports.includes("delete")&&g.push({label:a.delete,type:"tertiary",clickHandler:this._handleDelete})),S(s,{active:this.isPanelActive(e),key:"attribute-editing-panel",heading:h,headingLevel:r,showContentScrim:u,handleBack:o,messages:i,messagesCommon:a,sketchViewModel:d,snappingControls:n},S("div",{class:P.panelContentSection},S("div",{class:P.contentGroup},c.inputFields.length>0?this._featureForm.render():this.renderMessage(B(i.clickToFinishTemplate,{button:m})),v?S("div",{key:"attachments"},S("div",null,i.attachments),this._attachments.render()):null)),S("div",{class:this._prompt?"":P.scrimOverlay},this.renderControls(g)))}renderAttachmentAdding(e){const{_attachments:t,EditorPanel:s,_handleBack:i,headingLevel:a,messages:r,messagesCommon:o,_snappingControls:n,viewModel:{sketchViewModel:l}}=this,d=[{label:t.submitting?o.cancel:o.add,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentAdd}];return S(s,{active:this.isPanelActive(e),key:"attachment-adding-panel",heading:r.addAttachment,headingLevel:a,handleBack:i,messages:r,messagesCommon:o,sketchViewModel:l,snappingControls:n},S("div",{class:this.classes(P.content,P.scroller)},t.render()),this.renderControls(d))}renderAttachmentEditing(e){const{_attachments:t,EditorPanel:s,_handleBack:i,headingLevel:a,messages:r,messagesCommon:o,_snappingControls:n,viewModel:{sketchViewModel:l}}=this,d=[{label:o.update,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentUpdate},{label:o.delete,disabled:t.submitting,type:"tertiary",clickHandler:this._handleAttachmentDelete}];return S(s,{active:this.isPanelActive(e),key:"attachment-editing-panel",heading:r.editAttachment,headingLevel:a,handleBack:i,messages:r,messagesCommon:o,sketchViewModel:l,snappingControls:n},S("div",{class:this.classes(P.content,P.scroller)},t.render()),this.renderControls(d))}renderFeatureUpdating(e){const{EditorPanel:t,_handleBack:s,headingLevel:i,messages:a,messagesCommon:r,_snappingControls:o,viewModel:{sketchViewModel:n}}=this;return S(t,{active:this.isPanelActive(e),key:"feature-updating-panel",heading:a.selectFeature,headingLevel:i,handleBack:s,messages:a,messagesCommon:r,sketchViewModel:n,snappingControls:o},S("div",{class:this.classes(P.content,P.scroller)},this.renderMessage(a.selectFeatureToEdit)))}renderMessage(e){return S("div",{class:P.message},e)}renderFeatureCreation(e){const{EditorPanel:t,_handleBack:s,headingLevel:i,messages:a,messagesCommon:r,_snappingControls:o,viewModel:n}=this,{sketchViewModel:l}=n,d=n.sketchViewModel,c=this._assertActiveCreateWorkflow().data.creationInfo.layer,p=d.canUndo()&&d.createGraphic?d.createGraphic:null,h=this._getSketchingTip(c.geometryType,p);return S(t,{active:this.isPanelActive(e),key:"feature-creation-panel",heading:a.placeFeature,headingLevel:i,handleBack:s,messages:a,messagesCommon:r,sketchViewModel:l,snappingControls:o},S("div",{class:this.classes(P.content,P.scroller)},this.renderMessage(h)))}renderControls(e){return S("div",{class:P.controls,key:"controls"},e.map((({disabled:e=!1,label:t,type:s,clickHandler:i},a)=>this.renderButton({label:t,class:this.classes(P.controlButton,P.button,"secondary"===s?P.buttonSecondary:"tertiary"===s?P.buttonTertiary:null,e?P.buttonDisabled:null),disabled:e,clickHandler:i,key:a}))))}renderPrompt({title:e,message:t,context:s,actions:i}){const a=!!i.secondary,r=S("calcite-button",{appearance:"solid",color:"danger"===s?"red":"blue",width:a?"half":"full",onclick:i.primary.action,key:"prompt-primary-button",afterCreate:L},i.primary.label),o=a?S("calcite-button",{appearance:"clear",color:"danger"===s?"red":"blue",width:"half",onclick:i.secondary.action,key:"prompt-secondary-button"},i.secondary.label):null;return S("div",{class:`${P.promptContainer}--${s}`},S("div",{class:P.promptHeader},S("calcite-icon",{icon:"exclamation-mark-triangle"}),S(C,{class:P.promptHeading,level:this.headingLevel},e)),S("div",{class:P.promptMessage},t),S("div",{class:P.promptDivider}),S("div",{class:P.promptActions},o,r))}renderProgressBar(){return S("div",{class:this.classes(P.progressBar),key:"progress-bar"})}renderButton(e){return S("button",{class:e.class,disabled:e.disabled,key:e.key,onclick:e.clickHandler,type:"button"},e.label)}renderLanding(e){const{EditorPanel:t,headingLevel:s,messages:i,messagesCommon:a,_snappingControls:r,viewModel:{sketchViewModel:o}}=this;return S(t,{active:this.isPanelActive(e),key:"landing-panel",heading:i.widgetLabel,headingLevel:s,showBackButton:!1,messages:i,messagesCommon:a,sketchViewModel:o,snappingControls:r},S("div",{key:"edit-actions",class:P.panelContentSection},this.renderUpdateActions()),S("div",{key:"create-actions",class:P.panelContentSection},this.renderCreateActions()))}renderUpdateActions(){const{messages:e,messagesCommon:t}=this;return S("div",null,S(C,{level:M(this.headingLevel)},e.editFeatures),S("div",{class:P.updateFeaturesActionButtons},S("calcite-action",{text:t.select,textEnabled:!0,icon:"cursor",alignment:"start",class:P.updateFeaturesActionButtonsButton,onclick:this._handleEdit})))}renderCreateActions(){const{messages:e}=this;return S("div",null,S(C,{level:M(this.headingLevel)},e.createFeatures),S("div",{key:"templates",class:P.featureTemplatesContainer},this._featureTemplates.render()))}renderFeatureList(e){const{EditorPanel:t,_handleBack:s,headingLevel:i,messages:a,messagesCommon:r,messagesTemplates:o,_snappingControls:n,viewModel:{editableItems:l,sketchViewModel:d}}=this,c=this._assertActiveUpdateWorkflow().data.candidates,p=B(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,r=this.viewModel.editableItems.find((e=>e.layer===s.layer));return r.supports.indexOf("update")>-1&&(!i||t.toLowerCase().indexOf(i)>-1||a.toLowerCase().indexOf(i)>-1)})).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 S(t,{active:this.isPanelActive(e),key:"feature-list",heading:p,headingLevel:i,handleBack:s,messages:a,messagesCommon:r,sketchViewModel:d,snappingControls:n},b({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:i,heading:a,headingLevel:r,key:o,messages:n,messagesCommon:l,showBackButton:d,showContentScrim:c,sketchViewModel:p,snappingControls:h}=e;return S("calcite-panel",{bind:this,key:o,heading:a,headingLevel:r,showBackButton:null==d||d,beforeBack:null!=i?i:null,onCalcitePanelScroll:this._onSnappingPopoverPanelScroll},S("calcite-popover-manager",{autoClose:s,class:P.panelToolbar},S("calcite-popover",{afterCreate:this._afterSnappingPopoverCreated,afterUpdate:this._afterSnappingPopoverUpdated,bind:this,label:n.snappingSettings,heading:n.snappingSettings,"reference-element":`${o}__snappingButton`,"overlay-positioning":"fixed"},S("div",{class:P.snappingControlsPopover},h.render())),S("calcite-button",{id:`${o}__snappingButton`,text:n.snapping,appearance:"transparent",color:"neutral",alignment:"icon-end-space-between","icon-start":"vertex-gps","icon-end":"caret-down",width:"full",class:P.panelToolbarSnappingButton},n.snapping),this.visibleElements.undoRedoButtons?[S("calcite-button",{key:"undo-button",text:l.undo,appearance:"transparent",color:"neutral",alignment:"center","icon-start":"undo",scale:"l",disabled:!p.canUndo(),onclick:p.undo.bind(p)}),S("calcite-button",{key:"redo-button",text:l.redo,appearance:"transparent",color:"neutral",alignment:"center","icon-start":"redo",scale:"l",disabled:!p.canRedo(),onclick:p.redo.bind(p)})]:null),S("div",{class:E(P.panelContent,P.scroller)},t,c?S("calcite-scrim",null):null))}_onSnappingPopoverPanelScroll(){var e;null!=(e=this._snappingPopover)&&e.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 i=t.geometry,a="polygon"===e?"rings":"paths",[r]=i[a];return"polygon"===e&&r<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=m(t);return a&&i[a]&&`${i[a]}`||B(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||"update"===t.type&&t.data.edits.modified){const{type:i}=t,a="create"===i?e.cancelAddWarningMessage:e.cancelEditWarningMessage,r="create"===i?e.cancelAddTitle:e.cancelEditTitle,o="create"===i?e.continueAdding:e.continueEditing,n="create"===i?e.discardFeature:e.discardEdits;return this._prompt={title:r,message:a,context:"danger",actions:{primary:{label:n,action:()=>{s(),this._prompt=null}},secondary:{label:o,action:()=>this._prompt=null}}},this.scheduleRender(),Promise.reject()}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([p()],V.prototype,"_attachments",void 0),e([d("viewModel.activeWorkflow")],V.prototype,"activeWorkflow",void 0),e([d("viewModel.allowedWorkflows")],V.prototype,"allowedWorkflows",void 0),e([p()],V.prototype,"useDeprecatedCreateWorkflow",void 0),e([p()],V.prototype,"headingLevel",void 0),e([p()],V.prototype,"iconClass",void 0),e([p({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],V.prototype,"label",void 0),e([d("viewModel.layerInfos")],V.prototype,"layerInfos",void 0),e([p(),W("esri/widgets/Editor/t9n/Editor")],V.prototype,"messages",void 0),e([p(),W("esri/t9n/common")],V.prototype,"messagesCommon",void 0),e([p(),W("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],V.prototype,"messagesTemplates",void 0),e([d("viewModel.snappingOptions")],V.prototype,"snappingOptions",void 0),e([p()],V.prototype,"supportingWidgetDefaults",void 0),e([d("viewModel.view")],V.prototype,"view",void 0),e([p(),T(["workflow-cancel","workflow-commit"])],V.prototype,"viewModel",void 0),e([p()],V.prototype,"visibleElements",void 0),e([c("visibleElements")],V.prototype,"castVisibleElements",null),e([F()],V.prototype,"_handleDelete",null),e([F()],V.prototype,"_handleAttachmentAdd",null),e([F()],V.prototype,"_handleAttachmentUpdate",null),e([F()],V.prototype,"_handleAttachmentDelete",null),e([F()],V.prototype,"_handleAdd",null),e([F()],V.prototype,"_handleEdit",null),e([F()],V.prototype,"_handleDone",null),V=e([h(x)],V);const D=V;export{D 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.23/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 i from"../../core/Evented.js";import{HandleOwnerMixin as n}from"../../core/HandleOwner.js";import s from"../../core/Logger.js";import{destroyMaybe as o,isSome as l,isNone as r}from"../../core/maybe.js";import{EsriPromiseMixin as a}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 v}from"../../intl/locale.js";import{fetchMessageBundle as F}from"../../intl/messages.js";function C(e){return!!e.inputFields}const V=new t({attributes:{}}),E="esri.widgets.FeatureForm.FeatureFormViewModel",I=s.getLogger(E),b="#JSAPI_CONTINGENT_VALUE_EMPTY_HASH",j="#JSAPI_CONTINGENT_VALUE_ANY_HASH",A="#JSAPI_CONTINGENT_VALUE_NULL_HASH";let w=class extends(n(a(i.EventedAccessor))){constructor(e){super(e),this._arcade=null,this._compiledExpressions=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._needsArcade=!1,this._inputFieldCache=new Map,this._inputFieldGroupCache=new Map,this.contingencyConstraintViolations=new Map,this.messages=null,this.strict=!1}initialize(){const e=async()=>this.messages=await F("esri/widgets/FeatureForm/t9n/FeatureForm");e();const t=u((()=>this.layer),(e=>{"feature"===(null==e?void 0:e.type)&&this.addResolvingPromise(m.createLoadedLayerContingentValuesCache(e).then((e=>{this._contingentValuesCache=e,this.notifyChange("fieldsWithContingentValues")})))}),{initial:!0}),i=u((()=>{var e,t;const{formTemplate:i}=this;if(r(i))return null;const n=null!=(e=i.expressionInfos)?e:[],s=null!=(t=i.elements)?t:[];return[...n.map((e=>e.expression)),...null==s?void 0:s.map((e=>this._getExpressionsFromElementRecursive(e))).flat()]}),(async e=>{if(e.length<1)return;const t=new Set(e),n=new Map;if(l(this.formTemplate)&&l(this.formTemplate.expressionInfos))for(const i of this.formTemplate.expressionInfos)t.delete(i.name),n.set(i.expression,i.name);for(const i of this._compiledExpressions.keys())t.delete(i);if(t.size<1)return;this._needsArcade=!0;const s=await g();this._arcade=s;const{arcadeUtils:o}=s;for(const l of t.values()){var r;o.hasGeometryOperations(l)&&(await o.enableGeometryOperations(),i.remove()),this._setFunctionForExpression(null!=(r=n.get(l))?r:l,l)}this.notifyChange("inputFields")})),n=u((()=>this.formTemplate),(()=>this._compiledExpressions.clear()));this.handles.add([v(e),i,n,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)=>C(t)?[...e,...t.inputFields]:[...e,t]),[])}get _layerFieldsByName(){return new Map(this.layer.fields.map((e=>[e.name,e])))}get description(){const{formTemplate:e}=this;return l(e)?e.description:""}set description(e){void 0===e?this._clearOverride("description"):this._override("description",e)}get feature(){return this._get("feature")}set feature(e){this._featureClone=e?e.clone():V.clone(),this._initialFeature=this._featureClone.clone(),this._inputFieldCache.clear(),this._inputFieldGroupCache.clear(),this.contingencyConstraintViolations.clear(),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){void 0===e?this._clearOverride("formTemplate"):this._override("formTemplate",e)}get inputFields(){const{_arcade:e,_featureClone:t,_initialFeature:i,_inputFieldCache:n,_needsArcade:s,formTemplate:o,messages:r,layer:a,state:u}=this;if("ready"!==u||s&&!e)return[];const c=t.clone(),d=Array.from(n.keys()),p={arcade:e,feature:c,initialFeature:i,layer:a,messages:r},h=l(o)&&o.elements.length>0?this._generateInputFieldsFromElements(o.elements,p):this._generateInputFieldsFromLayerFields(null==a?void 0:a.fields,p);return this._cullInputFieldCache(this._flattenGroups(h).map((e=>e.name)),d),this._releasePreviousInputFields(),h.filter((e=>e.visible))}get joinedContingentValues(){return this._joinContingentValues()}get layer(){var e;return null!=(e=this.feature)&&e.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 title(){const{formTemplate:e}=this;return l(e)?e.title:""}set title(e){void 0===e?this._clearOverride("title"):this._override("title",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){var t;const{_featureClone:i,layer:n}=this,s=!(null==n||!n.getField(e));return null!=(t=i.getAttribute(e))?t:s?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,r(i))return[];const{invalid:s,incomplete:o}=i.validateContingencyConstraints(e),l=[...s,...null!=t&&t.includeIncompleteViolations?o:[]];for(const r of l)for(const e of r.fieldGroup.fields)n.set(e,r);return l}_cullInputFieldCache(e,t){const i=t.filter((t=>!e.includes(t)));for(const n in i)this._inputFieldCache.delete(n)}_flattenGroups(e){return e.flatMap((e=>"groupElement"in e?e.inputFields:e))}_releasePreviousInputFields(){const e=this._get("inputFields");if(e&&!(e.length<1))for(const t of e)"groupElement"in t?this._releaseInputFieldGroup(t):this._releaseInputField(t)}_releaseInputFieldGroup(e){e.inputFields.forEach((e=>this._releaseInputField(e))),this._fieldGroupPool.release(e)}_releaseInputField(e){this._fieldPool.release(e)}_emitChangeEvent({name:e,valid:t,value:i}){this.emit("value-change",{layer:this.layer,feature:this.feature,fieldName:e,value:i,valid:t})}_generateInputFieldsFromElements(e,t){const i=[];for(const n of e)this._isSupportedElement(n)&&i.push("group"===n.type?this._acquireAndInitializeInputFieldGroup(n,t):this._acquireAndInitializeInputField({field:this._layerFieldsByName.get(n.fieldName),fieldElement:n,...t}));return i}_generateInputFieldsFromLayerFields(e,t){return Array.isArray(e)?e.map((e=>this._acquireAndInitializeInputField({field:e,fieldElement:null,...t}))):(I.warn(E,"No attribute fields found."),[])}_acquireAndInitializeInputField(e){var t,i,n,s,o,l;const{arcade:r,feature:a,field:u,fieldElement:c,group:d,initialFeature:p,layer:h,messages:f}=e,m=null!=(t=this._compiledExpressions.get(null==c?void 0:c.requiredExpression))?t:void 0,g=null!=(i=this._compiledExpressions.get(null==c?void 0:c.visibilityExpression))?i:void 0,y=null!=(n=this._compiledExpressions.get(null==c?void 0:c.valueExpression))?n:void 0,_=null!=(s=this._compiledExpressions.get(null==c?void 0:c.editableExpression))?s:void 0,v=u.name,F=null!=(o=null==(l=this._inputFieldCache.get(v))?void 0:l.value)?o:this.getValue(v),C=this._fieldPool.acquire();return this._inputFieldCache.set(v,C),C.set({field:u,fieldElement:c,arcade:r,feature:a,group:d,initialFeature:p,layer:h,messages:f,requiredFunction:m,visibilityFunction:g,editableFunction:_,valueFunction:y,value:F})}_acquireAndInitializeInputFieldGroup(e,t){const i=this._fieldGroupPool.acquire(),n=[];for(const r of e.elements)this._isSupportedElement(r)&&n.push(this._acquireAndInitializeInputField({field:this._layerFieldsByName.get(r.fieldName),fieldElement:r,group:i,...t}));const{arcade:s,feature:o}=t,l=this._compiledExpressions.get(e.visibilityExpression);return i.set({arcade:s,feature:o,groupElement:e,inputFields:n,visibilityFunction:l})}_afterValueChange(e){const{name:t,value:i}=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,i),this.notifyChange("inputFields"),this._emitChangeEvent(e)}_getExpressionsFromElementRecursive(e){const t=[];if(e.visibilityExpression&&t.push(e.visibilityExpression),"field"===e.type){const i=["requiredExpression","valueExpression","editableExpression"];for(const n of i)e[n]&&t.push(e[n])}if("group"===e.type&&e.elements)for(const i of e.elements)t.push(...this._getExpressionsFromElementRecursive(i));return t}_setFunctionForExpression(e,t){const{_arcade:{arcadeUtils:i},_compiledExpressions:n}=this;n.set(e,i.createFunction(t))}_isSupportedElement(e){return"field"===e.type||"group"===e.type||(I.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,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 a of e)for(const e of a.fields)if(t.has(e)){const s=t.get(e),o=a,l=[s.name,o.name].sort().join("|");if(n.has(l))continue;i.push([s,o]),n.add(l),t.set(e,o)}else t.set(e,a);const s=new Set(i.flat()),o=new Set(e);for(const a of s)o.delete(a);const l=new Map,r=new Map;for(const a of new Set(i.flat())){const e=Symbol(a.name);l.set(e,new Set([a])),r.set(a,e)}for(const[a,u]of i){const e=r.get(a),t=r.get(u);if(e===t)continue;const i=l.get(e),n=l.get(t);for(const s of n)i.add(s),r.set(s,e);l.delete(t)}return[[...l.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]),a=new Map;for(const l of i.contingencies){const[e]=this._hashContingency(l,s.codedValueFields,!0);a.has(e)?a.get(e).push(l):a.set(e,[l])}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(a,i):a.get(i);if(a.has(j)&&o.push(...this._findMatchingContingenciesContainingAny(t,a.get(j),s.codedValueFields)),!r(o))for(const a of o){const i=s.rangeFields.length>0?this._joinContingenciesWithRangeDomains(a,t,s.rangeFields):this._joinContingencies(a,t);if(r(i))break;const[n]=this._hashContingency(i,l.codedValueFields,!0);e.has(n)?e.get(n).push(i):e.set(n,[i])}}a=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(a,e):a.get(e);if(a.has(j)&&i.push(...this._findMatchingContingenciesContainingAny(c,a.get(j),s.codedValueFields)),!r(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:l,rightIsNull:r,bothAreNull:a,leftIsAny:u,rightIsAny:c,bothAreAny:d,leftIsRange:p,rightIsRange:h}=this._compareObjectTypes(i.objectType,o.objectType);if(a||d)continue;if(l&&c||r&&u){n.values[s]=new f({objectType:"null"});continue}if(l&&h||r&&p)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=>{var n,s;const o=t.values[i],l=e.values[i];return"any"===o.objectType||"any"===l.objectType||(null==(n=o.codedValue)?void 0:n.code)===(null==(s=l.codedValue)?void 0:s.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,l=new Set,a=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":l.add(u);break;case"range":a.add(u)}}return{codedValueFields:[...l],rangeFields:[...a]}}_hashContingency(e,t,i=!1){if(t.length<1)return[b,!1];const n=[];let s=!1;for(const l of t){const t=e.values[l];if("any"===t.objectType){if(i)return[j,!0];s=!0,n.push(`${l}:.*`)}else if("null"===t.objectType)n.push(`${l}:${A}`);else{var o;n.push(`${l}:${null==(o=t.codedValue)?void 0:o.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([d({readOnly:!0})],w.prototype,"allInputFields",null),e([d()],w.prototype,"_layerFieldsByName",null),e([d({readOnly:!0})],w.prototype,"_inputFieldCache",void 0),e([d({readOnly:!0})],w.prototype,"_inputFieldGroupCache",void 0),e([d()],w.prototype,"contingencyConstraintViolations",void 0),e([d()],w.prototype,"description",null),e([d()],w.prototype,"feature",null),e([d()],w.prototype,"fieldsWithContingentValues",null),e([d({type:h})],w.prototype,"formTemplate",null),e([d({readOnly:!0,dependsOn:["formTemplate","messages","feature","layer.fields","layer.loaded","state"]})],w.prototype,"inputFields",null),e([d()],w.prototype,"joinedContingentValues",null),e([d()],w.prototype,"layer",null),e([d()],w.prototype,"messages",void 0),e([d()],w.prototype,"state",null),e([d()],w.prototype,"strict",void 0),e([d()],w.prototype,"submittable",null),e([d()],w.prototype,"title",null),e([d()],w.prototype,"valid",null),e([d()],w.prototype,"getValues",null),e([d()],w.prototype,"submit",null),w=e([p(E)],w);const x=w;export{x 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 s from"../../core/Logger.js";import{destroyMaybe as o,isSome as l,isNone as r}from"../../core/maybe.js";import{EsriPromiseMixin as a}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 v}from"../../intl/messages.js";function C(e){return!!e.inputFields}const I=new t({attributes:{}}),V="esri.widgets.FeatureForm.FeatureFormViewModel",b=s.getLogger(V),E="#JSAPI_CONTINGENT_VALUE_EMPTY_HASH",j="#JSAPI_CONTINGENT_VALUE_ANY_HASH",A="#JSAPI_CONTINGENT_VALUE_NULL_HASH";let w=class extends(n(a(i.EventedAccessor))){constructor(e){super(e),this._arcade=null,this._compiledExpressions=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=I.clone(),this._initialFeature=I.clone(),this._needsArcade=!1,this._inputFieldCache=new Map,this._inputFieldGroupCache=new Map,this.contingencyConstraintViolations=new Map,this.messages=null,this.strict=!1}initialize(){const e=async()=>this.messages=await v("esri/widgets/FeatureForm/t9n/FeatureForm");e();const t=u((()=>this.layer),(e=>{"feature"===(null==e?void 0:e.type)&&this.addResolvingPromise(m.createLoadedLayerContingentValuesCache(e).then((e=>{this._contingentValuesCache=e,this.notifyChange("fieldsWithContingentValues")})))}),{initial:!0}),i=u((()=>{var e,t;const{formTemplate:i}=this;if(r(i))return null;const n=null!=(e=i.expressionInfos)?e:[],s=null!=(t=i.elements)?t:[];return[...n.map((e=>e.expression)),...null==s?void 0:s.map((e=>this._getExpressionsFromElementRecursive(e))).flat()]}),(async e=>{if(e.length<1)return;const t=new Set(e),n=new Map;if(l(this.formTemplate)&&l(this.formTemplate.expressionInfos))for(const i of this.formTemplate.expressionInfos)t.delete(i.name),n.set(i.expression,i.name);for(const i of this._compiledExpressions.keys())t.delete(i);if(t.size<1)return;this._needsArcade=!0;const s=await g();this._arcade=s;const{arcadeUtils:o}=s;for(const l of t.values()){var r;o.hasGeometryOperations(l)&&(await o.enableGeometryOperations(),i.remove()),this._setFunctionForExpression(null!=(r=n.get(l))?r:l,l)}this.notifyChange("inputFields")})),n=u((()=>this.formTemplate),(()=>this._compiledExpressions.clear()));this.handles.add([F(e),i,n,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)=>C(t)?[...e,...t.inputFields]:[...e,t]),[])}get _layerFieldsByName(){return new Map(this.layer.fields.map((e=>[e.name,e])))}get description(){const{formTemplate:e}=this;return l(e)?e.description:""}set description(e){void 0===e?this._clearOverride("description"):this._override("description",e)}get feature(){return this._get("feature")}set feature(e){this._featureClone=e?e.clone():I.clone(),this._initialFeature=this._featureClone.clone(),this._inputFieldCache.clear(),this._inputFieldGroupCache.clear(),this.contingencyConstraintViolations.clear(),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){void 0===e?this._clearOverride("formTemplate"):this._override("formTemplate",e)}get inputFields(){const{_arcade:e,_featureClone:t,_initialFeature:i,_inputFieldCache:n,_inputFieldGroupCache:s,_needsArcade:o,formTemplate:r,messages:a,layer:u,state:c}=this;if("ready"!==c||o&&!e)return[];const d=t.clone(),p=Array.from(n.keys()),h=Array.from(s.keys()),f={arcade:e,feature:d,initialFeature:i,layer:u,messages:a},m=l(r)&&r.elements.length>0?this._generateInputFieldsFromElements(r.elements,f):this._generateInputFieldsFromLayerFields(null==u?void 0:u.fields,f);return this._cullCaches(m,p,h),this._releasePreviousInputFields(),m.filter((e=>e.visible))}get joinedContingentValues(){return this._joinContingentValues()}get layer(){var e;return null!=(e=this.feature)&&e.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 title(){const{formTemplate:e}=this;return l(e)?e.title:""}set title(e){void 0===e?this._clearOverride("title"):this._override("title",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){var t;const{_featureClone:i,layer:n}=this,s=!(null==n||!n.getField(e));return null!=(t=i.getAttribute(e))?t:s?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,r(i))return[];const{invalid:s,incomplete:o}=i.validateContingencyConstraints(e),l=[...s,...null!=t&&t.includeIncompleteViolations?o:[]];for(const r of l)for(const e of r.fieldGroup.fields)n.set(e,r);return l}_cullCaches(e,t,i){const n=[],s=[];for(const o of e)C(o)?(s.push(o.label),n.push(...o.inputFields.map((e=>e.name)))):n.push(o.name);this._cullInputFieldCache(n,t),this._cullInputFieldGroupCache(s,i)}_cullInputFieldCache(e,t){const i=t.filter((t=>!e.includes(t)));for(const n in i)this._inputFieldCache.delete(n)}_cullInputFieldGroupCache(e,t){const i=t.filter((t=>!e.includes(t)));for(const n in i)this._inputFieldGroupCache.delete(n)}_releasePreviousInputFields(){const e=this._get("inputFields");if(e&&!(e.length<1))for(const t of e)"groupElement"in t?this._releaseInputFieldGroup(t):this._releaseInputField(t)}_releaseInputFieldGroup(e){e.inputFields.forEach((e=>this._releaseInputField(e))),this._fieldGroupPool.release(e)}_releaseInputField(e){this._fieldPool.release(e)}_emitChangeEvent({name:e,valid:t,value:i}){this.emit("value-change",{layer:this.layer,feature:this.feature,fieldName:e,value:i,valid:t})}_generateInputFieldsFromElements(e,t){const i=[];for(const n of e)this._isSupportedElement(n)&&i.push("group"===n.type?this._acquireAndInitializeInputFieldGroup(n,t):this._acquireAndInitializeInputField({field:this._layerFieldsByName.get(n.fieldName),fieldElement:n,...t}));return i}_generateInputFieldsFromLayerFields(e,t){return Array.isArray(e)?e.map((e=>this._acquireAndInitializeInputField({field:e,fieldElement:null,...t}))):(b.warn(V,"No attribute fields found."),[])}_acquireAndInitializeInputField(e){var t,i,n,s,o,l;const{arcade:r,feature:a,field:u,fieldElement:c,group:d,initialFeature:p,layer:h,messages:f}=e,m=null!=(t=this._compiledExpressions.get(null==c?void 0:c.requiredExpression))?t:void 0,g=null!=(i=this._compiledExpressions.get(null==c?void 0:c.visibilityExpression))?i:void 0,y=null!=(n=this._compiledExpressions.get(null==c?void 0:c.valueExpression))?n:void 0,_=null!=(s=this._compiledExpressions.get(null==c?void 0:c.editableExpression))?s:void 0,F=u.name,v=null!=(o=null==(l=this._inputFieldCache.get(F))?void 0:l.value)?o:this.getValue(F),C=this._fieldPool.acquire();return this._inputFieldCache.set(F,C),C.set({field:u,fieldElement:c,arcade:r,feature:a,group:d,initialFeature:p,layer:h,messages:f,requiredFunction:m,visibilityFunction:g,editableFunction:_,valueFunction:y,value:v})}_acquireAndInitializeInputFieldGroup(e,t){var i,n;const s=null!=(i=null==(n=this._inputFieldGroupCache.get(e.label))?void 0:n.state)?i:e.initialState,o=this._fieldGroupPool.acquire();this._inputFieldGroupCache.set(e.label,o);const l=[];for(const c of e.elements)this._isSupportedElement(c)&&l.push(this._acquireAndInitializeInputField({field:this._layerFieldsByName.get(c.fieldName),fieldElement:c,group:o,...t}));const{arcade:r,feature:a}=t,u=this._compiledExpressions.get(e.visibilityExpression);return o.set({arcade:r,feature:a,groupElement:e,inputFields:l,state:s,visibilityFunction:u})}_afterValueChange(e){const{name:t,value:i}=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,i),this.notifyChange("inputFields"),this._emitChangeEvent(e)}_getExpressionsFromElementRecursive(e){const t=[];if(e.visibilityExpression&&t.push(e.visibilityExpression),"field"===e.type){const i=["requiredExpression","valueExpression","editableExpression"];for(const n of i)e[n]&&t.push(e[n])}if("group"===e.type&&e.elements)for(const i of e.elements)t.push(...this._getExpressionsFromElementRecursive(i));return t}_setFunctionForExpression(e,t){const{_arcade:{arcadeUtils:i},_compiledExpressions:n}=this;n.set(e,i.createFunction(t))}_isSupportedElement(e){return"field"===e.type||"group"===e.type||(b.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,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 a of e)for(const e of a.fields)if(t.has(e)){const s=t.get(e),o=a,l=[s.name,o.name].sort().join("|");if(n.has(l))continue;i.push([s,o]),n.add(l),t.set(e,o)}else t.set(e,a);const s=new Set(i.flat()),o=new Set(e);for(const a of s)o.delete(a);const l=new Map,r=new Map;for(const a of new Set(i.flat())){const e=Symbol(a.name);l.set(e,new Set([a])),r.set(a,e)}for(const[a,u]of i){const e=r.get(a),t=r.get(u);if(e===t)continue;const i=l.get(e),n=l.get(t);for(const s of n)i.add(s),r.set(s,e);l.delete(t)}return[[...l.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]),a=new Map;for(const l of i.contingencies){const[e]=this._hashContingency(l,s.codedValueFields,!0);a.has(e)?a.get(e).push(l):a.set(e,[l])}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(a,i):a.get(i);if(a.has(j)&&o.push(...this._findMatchingContingenciesContainingAny(t,a.get(j),s.codedValueFields)),!r(o))for(const a of o){const i=s.rangeFields.length>0?this._joinContingenciesWithRangeDomains(a,t,s.rangeFields):this._joinContingencies(a,t);if(r(i))break;const[n]=this._hashContingency(i,l.codedValueFields,!0);e.has(n)?e.get(n).push(i):e.set(n,[i])}}a=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(a,e):a.get(e);if(a.has(j)&&i.push(...this._findMatchingContingenciesContainingAny(c,a.get(j),s.codedValueFields)),!r(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:l,rightIsNull:r,bothAreNull:a,leftIsAny:u,rightIsAny:c,bothAreAny:d,leftIsRange:p,rightIsRange:h}=this._compareObjectTypes(i.objectType,o.objectType);if(a||d)continue;if(l&&c||r&&u){n.values[s]=new f({objectType:"null"});continue}if(l&&h||r&&p)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=>{var n,s;const o=t.values[i],l=e.values[i];return"any"===o.objectType||"any"===l.objectType||(null==(n=o.codedValue)?void 0:n.code)===(null==(s=l.codedValue)?void 0:s.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,l=new Set,a=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":l.add(u);break;case"range":a.add(u)}}return{codedValueFields:[...l],rangeFields:[...a]}}_hashContingency(e,t,i=!1){if(t.length<1)return[E,!1];const n=[];let s=!1;for(const l of t){const t=e.values[l];if("any"===t.objectType){if(i)return[j,!0];s=!0,n.push(`${l}:.*`)}else if("null"===t.objectType)n.push(`${l}:${A}`);else{var o;n.push(`${l}:${null==(o=t.codedValue)?void 0:o.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([d({readOnly:!0})],w.prototype,"allInputFields",null),e([d()],w.prototype,"_layerFieldsByName",null),e([d({readOnly:!0})],w.prototype,"_inputFieldCache",void 0),e([d({readOnly:!0})],w.prototype,"_inputFieldGroupCache",void 0),e([d()],w.prototype,"contingencyConstraintViolations",void 0),e([d()],w.prototype,"description",null),e([d()],w.prototype,"feature",null),e([d()],w.prototype,"fieldsWithContingentValues",null),e([d({type:h})],w.prototype,"formTemplate",null),e([d({readOnly:!0,dependsOn:["formTemplate","messages","feature","layer.fields","layer.loaded","state"]})],w.prototype,"inputFields",null),e([d()],w.prototype,"joinedContingentValues",null),e([d()],w.prototype,"layer",null),e([d()],w.prototype,"messages",void 0),e([d()],w.prototype,"state",null),e([d()],w.prototype,"strict",void 0),e([d()],w.prototype,"submittable",null),e([d()],w.prototype,"title",null),e([d()],w.prototype,"valid",null),e([d()],w.prototype,"getValues",null),e([d()],w.prototype,"submit",null),w=e([p(V)],w);const x=w;export{x 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.23/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 l,isNone as r,get as n}from"../../core/maybe.js";import{watch as o}from"../../core/reactiveUtils.js";import{generateUID as s}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
|
|
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 l,isNone as r,get as n}from"../../core/maybe.js";import{watch as o}from"../../core/reactiveUtils.js";import{generateUID as s}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 h}from"../../layers/support/domainUtils.js";import{isNumericField as m,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=s().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(o((()=>this.value),((e,t)=>{if(e!==t){const{feature:e,name:t,value:i}=this;e.setAttribute(t,i)}})))}get _configAllowsEdits(){var e,t,i;const{fieldElement:r,layer:n,name:o}=this;if(l(r))return!1!==r.editable;const s="subtype-group"!==(null==n?void 0:n.type)?null==n||null==(e=n.popupTemplate)||null==(t=e.fieldInfos)?void 0:t.find((({fieldName:e})=>e===o)):null;return null==(i=null==s?void 0:s.isEditable)||i}get _layerFieldAllowsEdits(){const{field:e,layer:t}=this;return(null==t?void 0:t.capabilities.operations.supportsEditing)&&(null==e?void 0:e.editable)}get isUsingValueExpression(){return this._shouldUseValueExpression()}get evaluatedEditableExpression(){const{editableFunction:e}=this;if(r(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}get evaluatedRequiredExpression(){const{requiredFunction:e}=this;if(r(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}get evaluatedVisibilityExpression(){const{visibilityFunction:e}=this;if(r(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}get evaluatedValueExpression(){const{valueFunction:e}=this;if(r(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(){var e;const{typeIdField:t}=this.layer,i=t===this.name,r=null==(e=this.field)?void 0:e.domain;if(i&&!r){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:o}=this,s=t&&this.layer.getFieldDomain(this.name,{feature:o})||r,a=n(this.fieldElement,"domain");return l(a)&&this._isDomainCompatible(a)?a:s}get editable(){var e;return!!this._layerFieldAllowsEdits&&(null!=(e=this.evaluatedEditableExpression)?e:this._configAllowsEdits)}get errorMessage(){return this._toErrorMessage()}get includeTime(){var e;const{fieldElement:t}=this,i=l(t)&&"datetime-picker"===(null==(e=t.input)?void 0:e.type)?t.input.includeTime:void 0;return void 0===i||i}get label(){return l(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,r=null==t?void 0:t.length,n=l(i)&&N(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===V.Date)return e;const{field:t,fieldElement:i}=this,r=null==t?void 0:t.length,n=l(i)&&N(i.input)?i.input.minLength:NaN;return!isNaN(n)&&n>=e&&(r===e||n<=r)?n:e}get required(){var e,t;return!!this.editable&&(!1===(null==(e=this.field)?void 0:e.nullable)||null!=(t=this.evaluatedRequiredExpression)&&t)}get submittable(){return!!this.valid||this.initialFeature.getAttribute(this.field.name)===this.value}get type(){const{field:e}=this;return m(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()&&(l(this.fieldElement)?null==(e=this.evaluatedVisibilityExpression)||e:this._isVisibleByDefault());var e}_isDomainCompatible(e){const{field:t}=this;if("coded-value"===(null==e?void 0:e.type)){const i=typeof e.codedValues[0].code;if("string"===i&&y(t)||"number"===i&&m(t))return!0}return!!("range"===(null==e?void 0:e.type)&&m(t)||f(t))}_validate(){const{domain:e,field:t,initialFeature:i,minLength:l,required:r,type:n,valid:o,value:s}=this,a=r&&null===s,u=void 0!==o;return!a&&i.getAttribute(t.name)===s&&u?null:"text"===n&&l>-1&&"string"==typeof s&&s.length<l?O.TOO_SHORT:e?null!==s||r?p(e,s):null:a?v.INVALID_TYPE:g(t,s)}_isVisibleByDefault(){var e;const t=null==(e=this.field)?void 0:e.type;return"oid"!==t&&"global-id"!==t&&!this._isGeometryField()}_isEditorField(){return E(this.layer).indexOf(this.name)>-1}_isGeometryField(){return b(this.layer).indexOf(this.name)>-1}_shouldUseValueExpression(){return this._layerFieldAllowsEdits&&!this._configAllowsEdits&&l(this.valueFunction)}_toErrorMessage(){const{domain:e,field:t,messages:i,minLength:l,value:r,required:n,type:o}=this,s=this.error;if(n&&null===r)return i.validationErrors.cannotBeNull;if(s===c.VALUE_OUT_OF_RANGE||s===_.OUT_OF_RANGE){const l=h(e)||x(t);return F(i.validationErrors.outsideRange,l,{format:{max:"date"===o?j:A(l.max)?T:U,min:"date"===o?j:A(l.min)?T:U}})}return s===c.INVALID_CODED_VALUE?i.validationErrors.invalidCodedValue:s===v.INVALID_TYPE?i.validationErrors.invalidType:s===O.TOO_SHORT?F(i.validationErrors.tooShort,{min:l}):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};
|
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.23/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{aliasOf as l}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import"../core/accessorSupport/ensureType.js";import{property as n}from"../core/accessorSupport/decorators/property.js";import{subclass as s}from"../core/accessorSupport/decorators/subclass.js";import{getDomainRange as r}from"../layers/support/domainUtils.js";import{getFieldRange as o}from"../layers/support/fieldUtils.js";import u from"./Widget.js";import d from"./FeatureForm/FeatureFormViewModel.js";import{Heading as p,incrementHeadingLevel as c}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as m}from"./support/decorators/messageBundle.js";import"../core/Logger.js";import{vmEvent as h}from"./support/decorators/vmEvent.js";import{tsx as f}from"./support/jsxFactory.js";import{DateTime as _}from"luxon";import{getLocale as v}from"../intl/locale.js";const g={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"},b={datePattern:"D",timePattern:"tt"};function y(e){return e&&e.inputFields}let I=class extends u{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.description=null,this.feature=null,this.fieldConfig=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.title=null,this.viewModel=new d,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(this.watch("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 f("div",{class:this.classes(g.base,g.widget,g.panel)},"ready"===e?this.renderForm():null)}renderForm(){const e=this.title?f(p,{key:"title",level:this.headingLevel},this.title):null,t=this.description?f("p",{class:g.description,key:"description"},this.description):null,i=e||t?f("div",{class:g.formHeader},e,t):null;return f("form",{class:g.form,novalidate:!0,onsubmit:this._handleSubmit,onkeydown:this._handleFormKeyDown},i,this.renderFields())}renderFields(){const{viewModel:{inputFields:e}}=this;return e.map(((e,t)=>y(e)?this.renderGroup(e,t):this.renderLabeledField(e)))}renderGroup(e,t){const{description:i,inputFields:a,label:l,state:n}=e,s=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}`,m=`${this.id}_group-description_${t}`,h=i?f("p",{class:this.classes(g.groupDescription,g.description),id:m},i):null,_="sequential"===this.groupDisplay,v=_?o:"expanded"===n,b=v?g.collapseIcon:g.expandIcon;return f("fieldset",{"aria-expanded":v.toString(),"aria-labelledby":d,"aria-describedby":i?m:"",class:this.classes(g.group,_?g.groupSequential:null,v?null:g.groupCollapsed,o?g.groupActive:null),"data-group":e,id:u,key:t,onclick:this._handleGroupClick},f("button",{role:_?"presentation":void 0,class:g.groupHeader,type:"button",tabIndex:_?-1:0},f("div",{class:g.groupTitle},f(p,{class:g.groupLabel,id:d,level:this.title?c(this.headingLevel):this.headingLevel},l),h),_?null:f("span",{class:this.classes(b,g.groupToggleIcon)})),s.map((e=>this.renderLabeledField(e))))}_getFocusableInput(e,t){const i=this.viewModel.allInputFields,a="forward"===e?i:i.slice().reverse();let l;if(t)if(y(t))l=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;l=a.indexOf(i)+1}else l=0;for(let n=l;n<a.length;n++){const e=a[n];if(e.visible)return e}return null}renderLabeledField(e){const{label:t,layer:i,type:a}=e;return f("label",{key:`${i.id}-${e.name}`,class:g.label},[t,"unsupported"!==a?this.renderInputField(e):this.renderUnsupportedField(e),this.renderAuxiliaryText(e)])}renderInputField(e){const{domain:t,name:a,type:l,value:n}=e,s=this.getCommonInputProps(e);if("coded-value"===(null==t?void 0:t.type)){if(this._inputFieldHasInputType(e,"switch")){const{fieldElement:t}=e;if(!(this._switchFieldsWithInitialIncompatibleValue.has(a)||null==n||t.input.onValue!==n&&t.input.offValue!==n))return this.renderSwitchInputField(n,s);this._switchFieldsWithInitialIncompatibleValue.add(a)}return"radio-buttons"===e.inputType?this.renderRadioButtonsInputField(n,t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),s):this.renderSelectInputField(n,this._getFieldValueOptions(a,t),s)}return"datetime-picker"===e.inputType||"date"===l?this.renderDateInputField(n,s):"number"===l?f("input",{type:"number",...s,value:i(this._activeNumberFieldEdit)&&this._activeNumberFieldEdit.fieldName===e.name?this._activeNumberFieldEdit.value:`${s.value}`}):"text-area"===e.inputType?f("textarea",{...s}):f("input",{type:"text",...s})}_parseDateTime(e,t,i){if(i){var a;let l=_.fromJSDate(this._parseDate(e,i));const n=_.fromMillis(null!=(a=t.value)?a:Date.now());return l="date"===i?l.set({hour:n.hour,minute:n.minute,second:n.second}):l.set({day:n.day,month:n.month,year:n.year}),l.isValid?l.toMillis():null}const l=_.fromJSDate(this._parseDate(e));return l.isValid?l.toMillis():null}renderDateInputField(e,t){const{date:i,time:a}=this._formatDate(0),l=`${this.id}-${t.key}`,n=`${l}-date`,s=`${l}-time`,r=t["data-field"],{includeTime:o}=r,{_activeDateFieldEdit:u}=this;let{date:d,time:p}=this._formatDate(e);var c,m,h,_;(null==u?void 0:u.fieldName)===r.name&&(d=null!=(c=null==(m=u.date.input)?void 0:m.value)?c:d,p=null!=(h=null==(_=u.time.input)?void 0:_.value)?h:p);return f("div",{key:`${t.key}-date`,class:g.dateInputContainer},f("div",{class:this.classes(g.dateInputPart,o?null:g.loneDateInputPart)},f("input",{"aria-label":r.label,"aria-describedby":n,type:"text",...t,"data-date-part":"date",class:this.classes(t.class,g.inputDate),value:d}),f("div",{class:g.dateFormatHint,id:n},i)),o?f("div",{class:g.dateInputPart,key:"time-input"},f("input",{"aria-describedby":s,"aria-label":r.label,type:"text",...t,"data-date-part":"time",class:this.classes(t.class,g.inputTime),value:p}),f("div",{class:g.dateFormatHint,id:s},a)):null)}renderUnsupportedField(e){const t=this.getCommonInputProps(e);return f("input",{afterCreate:t.afterCreate,afterUpdate:t.afterUpdate,class:this.classes(g.input,g.inputField,g.inputDisabled),"data-field":t["data-field"],onfocus:t.onfocus,readOnly:!0,tabIndex:t.tabIndex,type:"text",value:t.value})}renderSelectInputField(e,t,i){const{messages:l,messagesTemplates:n}=this,s=t.map((t=>t.map((t=>f("calcite-combobox-item",{value:`${t.value}`,"text-label":t.name,key:`#${t.value}`,selected:e===t.value}))))),r=i["data-field"],[o,u]=s;this._registerIncompatibleValue(e,t.flat(),r,(e=>{u.unshift(f("calcite-combobox-item",{value:`${e}`,"text-label":`${e}`,key:"incompatible-option",readOnly:!0}))}));const d=u.length>0?[f("calcite-combobox-item-group",{key:"recommended",label:l.recommended},o),f("calcite-combobox-item-group",{key:"other",label:n.other},u)]:o,p=a(r.fieldElement)||this._inputFieldHasInputType(r,"combo-box")&&r.fieldElement.input.showNoValueOption;if(!r.required&&p){const e="",t=this._inputFieldHasInputType(r,"combo-box")&&r.fieldElement.input.noValueOptionLabel||this.messages.empty;d.unshift(f("calcite-combobox-item",{value:e,"text-label":this.messages.empty,key:"empty-option"},t))}return f("calcite-combobox",{...i,"selection-mode":"single",disabled:i.readOnly,allowCustomValues:!1,onCalciteComboboxChange:e=>this._handleOptionChange(e.target)},d)}_registerIncompatibleValue(e,t,i,a){const l=this._fieldToInitialIncompatibleDomainValue,n=l.has(i.name);(n||null!=e&&""!==e&&!t.find((t=>t.value===e))||n)&&(n||l.set(i.name,e),null==a||a(l.get(i.name)))}renderRadioButtonsInputField(e,t,i){const l=i["data-field"],n=t.map((t=>this.renderRadioButton({key:t.name,label:t.name,name:l.name,value:t.value,selected:t.value===e,props:i})));this._registerIncompatibleValue(e,t,l);const s=a(l.fieldElement)||this._inputFieldHasInputType(l,"radio-buttons")&&l.fieldElement.input.showNoValueOption;if(!l.required&&s){const t="",a=this._inputFieldHasInputType(l,"radio-buttons")&&l.fieldElement.input.noValueOptionLabel||this.messages.empty,s=e===t||null===e;n.unshift(this.renderRadioButton({key:"empty-option",label:a,name:l.name,value:t,selected:s,props:i}))}return f("div",{key:`${i.key}-radio`,class:g.inputRadioGroup},n)}renderSwitchInputField(e,t){const i=t["data-field"],a=!!this._inputFieldHasInputType(i,"switch")&&e===i.fieldElement.input.onValue;return f("calcite-switch",{...t,class:g.inputSwitch,onclick:this._handleSwitchClick,checked:a,disabled:t.readOnly})}renderRadioButton({key:e,name:t,value:i,selected:a,label:l,props:n}){return f("label",{key:e,class:g.inputRadioLabel},f("input",{...n,class:g.inputRadio,name:t,type:"radio",value:i,checked:a,onchange:this._handleRadioInputChange}),l)}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)?f("calcite-input-message",{status:"invalid",icon:!0,active:!0},t):e.description?f("div",{key:"description",class:g.description},e.description):void 0}getCommonInputProps(e){const{groupDisplay:t}=this,{editable:a,group:l,hint:n,maxLength:s,minLength:r,name:o,required:u,type:d,valid:p,value:c}=e,m=this._userUpdatedInputFieldNames.has(o),h=!a,f="all"===t&&i(l)&&"collapsed"===l.state;return{afterCreate:this._afterInputCreateOrUpdate,afterUpdate:this._afterInputCreateOrUpdate,"aria-invalid":p?"false":"true",class:this.classes(g.input,g.inputField,h?g.inputDisabled:null,m&&!p?g.inputInvalid:null),key:o,label:o,minlength:r>-1?`${r}`:"",maxlength:s>-1?`${s}`:"",...this._getNumberFieldConstraints(e),readOnly:h,value:null==c?"":`${c}`,"data-field":e,onfocus:this._handleInputFocus,oninput:this._handleInputInput,onblur:this._handleInputBlur,onkeydown:this._handleInputKeyDown,onmousedown:"number"===d?this._handleNumberInputMouseDown:null,placeholder:"number"===d||"text"===d?n:"",required:u,tabIndex:f?-1:0}}_isInputFieldInGroup(e){return!y(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 n of this.viewModel.allInputFields){const{name:i,value:l}=n;!a(l)&&i!==e&&this.viewModel.fieldsWithContingentValues.has(i)&&(t[i]=l)}const i=this.viewModel.joinedContingentValues.slice(),l=new Map;for(const n of i){const i=n.values[e];if(a(i)||"code"!==i.objectType&&"null"!==i.objectType)continue;const{code:s,name:r}="null"===i.objectType?{code:"",name:this.messages.empty}:i.codedValue;if(l.has(s))continue;Object.entries(t).every((([e,t])=>!n.values.hasOwnProperty(e)||this._valueIsValidContingentValue(t,n.values[e])))&&l.set(s,{name:r,value:s})}return[...l.values()]}_getNumberFieldConstraints(e){const t=r(e.domain)||o(e.field);return t&&t.max!==Number.MAX_VALUE&&t.min!==Number.MIN_VALUE?t:{min:null,max:null}}_afterInputCreateOrUpdate(e){const t=e["data-field"],i=this.viewModel.findField(this._activeInputName),a=this._fieldToInitialIncompatibleDomainValue.get(t.name)===t.value;this._fieldFocusNeeded&&i===t&&("radio-buttons"!==t.inputType||a||e.checked)&&(this._fieldFocusNeeded=!1,e.focus())}_handleInputFocus(e){const t=e.target,i=t["data-field"];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=t["data-field"];if("date"===a.type){const i=e.relatedTarget,n=i&&i["data-field"];if(n&&"date"===a.type&&"date"===n.type&&a.field===n.field){if(""!==t.value&&""===i.value){var l;const n=i.getAttribute("data-date-part");i.value=this._formatDate(null!=(l=a.value)?l: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 l=e["data-field"];if(this._activeDateFieldEdit){const{date:i,time:u}=this._activeDateFieldEdit,d=this._parseDateTime(e.value,l,i.active?"date":"time"),p=null!==this.viewModel.getValue(l.name),c=i.input&&(u.input||!l.includeTime),m=null===d;if(t){if(m)return;(c||!a||p)&&this._updateDateFieldValue(l,d)}else{var n,s;if(""===(null==(n=i.input)?void 0:n.value)||""===(null==(s=u.input)?void 0:s.value))this._updateDateFieldValue(l,null);else if(c){var r,o;const e=`${i.input.value} ${null!=(r=null==(o=u.input)?void 0:o.value)?r:""}`,t=this._parseDateTime(e,l);!(null!==t)&&p||this._updateDateFieldValue(l,t)}this._activeDateFieldEdit=null}}else i(this._activeNumberFieldEdit)&&this._isNumberInputField(l)&&(this._activeNumberFieldEdit.value=e.value),this._updateFieldValue(e)}_handleInputKeyDown(e){const{key:t,altKey:i,ctrlKey:a,metaKey:l}=e,n=e.target["data-field"];if("Enter"===t)this._isInputFieldInGroup(n)&&"collapsed"===n.group.state&&(n.group.state="expanded");else{const{type:s}=n.field,r="single"===s||"double"===s,o=!i&&!a&&!l;if(("integer"===s||"small-integer"===s||r)&&o&&1===t.length){const i=Number(t),a=["-","+"],l=["e","."],n=r?[...a,...l]:a;isNaN(i)&&-1===n.indexOf(t)&&e.preventDefault()}}}_setUpNumberFieldEdit(e){const t=e["data-field"];this._activeNumberFieldEdit={fieldName:t.name,input:e,value:e.value}}_syncDateFieldEdits(e){var t,i;const a=e["data-field"];if("date"!==a.type)return;const l=e.getAttribute("data-date-part"),n="date"===l?{value:e.value,input:e,active:!0}:{...null==(t=this._activeDateFieldEdit)?void 0:t.date,active:!1},s="time"===l?{value:e.value,input:e,active:!0}:{...null==(i=this._activeDateFieldEdit)?void 0:i.time,active:!1};this._activeDateFieldEdit={fieldName:a.name,date:n,time:s}}_updateFieldValue(e){const t=e["data-field"],{name:a}=t;if(this.viewModel.setValue(a,this._parseValue(e)),this._userUpdatedInputFieldNames.add(a),this.viewModel.fieldsWithContingentValues.has(a)){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=e["data-field"],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 l=e.getAttribute("data-date-part"),n=this._parseDate(i,l);if(!n)return null;let s=_.fromJSDate(n);const r=t.domain,o=_.now();let u=o;if(r&&"range"===r.type){const e=_.fromMillis(r.maxValue);o<e&&(u=e)}const d=this.viewModel.getValue(t.name),p=null!=d?_.fromMillis(d):u;return s="date"===l?s.set({hour:p.hour,minute:p.minute,second:p.second}):s.set({day:p.day,month:p.month,year:p.year}),s.toMillis()}return i}_handleOptionChange(e){this._commitInputValue(e),this.scheduleRender()}_handleGroupClick(e){var t;const i=e.currentTarget["data-group"],a="expanded"===i.state,l="sequential"===this.groupDisplay,n=`.${g.groupHeader}`;if(!(a&&!e.target.closest(n))){if(this._activeInputName=null==(t=this._getFocusableInput("forward",i))?void 0:t.name,l){const t=e.target.closest(n);if(a&&!t)return;this.viewModel.inputFields.forEach((e=>{y(e)&&e!==i&&(e.state="collapsed")}))}i.state=a?"collapsed":"expanded",this._fieldFocusNeeded=l,this.scheduleRender()}}_handleSubmit(e){e.preventDefault()}_handleFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_formatDate(e){if(null==e)return{date:"",time:""};const t=_.fromMillis(e,{locale:v(),numberingSystem:"latn"});return{date:t.toLocaleString({year:"numeric",month:"2-digit",day:"2-digit"}),time:t.toFormat(b.timePattern)}}_parseDate(e,t){if(null==e||""===e)return null;const{timePattern:i,datePattern:a}=b,l=t?"date"===t?a:i:`${a} ${i}`,n=_.fromFormat(e,l,{locale:v(),numberingSystem:"latn"});return n.isValid?n.toJSDate():null}_inputFieldHasInputType(e,t){var a;return i(e.fieldElement)&&(null==(a=e.fieldElement.input)?void 0:a.type)===t}_valueIsValidContingentValue(e,i){var a;switch(i.objectType){case"any":return!0;case"null":return null==e;case"code":return e===(null==(a=i.codedValue)?void 0:a.code);case"range":return e>=i.minValue&&e<=i.maxValue;default:return t(i.objectType),!1}}};e([l("viewModel.description")],I.prototype,"description",void 0),e([l("viewModel.feature")],I.prototype,"feature",void 0),e([l("viewModel.fieldConfig")],I.prototype,"fieldConfig",void 0),e([l("viewModel.formTemplate")],I.prototype,"formTemplate",void 0),e([n()],I.prototype,"groupDisplay",void 0),e([n()],I.prototype,"headingLevel",void 0),e([n({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],I.prototype,"label",void 0),e([l("viewModel.layer")],I.prototype,"layer",void 0),e([n(),m("esri/widgets/FeatureForm/t9n/FeatureForm")],I.prototype,"messages",void 0),e([n(),m("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],I.prototype,"messagesTemplates",void 0),e([l("viewModel.strict")],I.prototype,"strict",void 0),e([l("viewModel.title")],I.prototype,"title",void 0),e([n(),h(["value-change","submit"])],I.prototype,"viewModel",void 0),e([l("viewModel.getValues")],I.prototype,"getValues",null),e([l("viewModel.submit")],I.prototype,"submit",null),I=e([s("esri.widgets.FeatureForm")],I);const F=I;export{F 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{aliasOf as n}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 s}from"../core/accessorSupport/decorators/subclass.js";import{getDomainRange as r}from"../layers/support/domainUtils.js";import{getFieldRange as o}from"../layers/support/fieldUtils.js";import u from"./Widget.js";import d from"./FeatureForm/FeatureFormViewModel.js";import{Heading as p,incrementHeadingLevel as c}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as m}from"./support/decorators/messageBundle.js";import"../core/Logger.js";import{vmEvent as h}from"./support/decorators/vmEvent.js";import{tsx as f}from"./support/jsxFactory.js";import{DateTime as _}from"luxon";import{getLocale as v}from"../intl/locale.js";const g={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"},b={datePattern:"D",timePattern:"tt"};function I(e){return e&&e.inputFields}const y="data-field-name";let F=class extends u{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.description=null,this.feature=null,this.fieldConfig=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.title=null,this.viewModel=new d,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(this.watch("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 f("div",{class:this.classes(g.base,g.widget,g.panel)},"ready"===e?this.renderForm():null)}renderForm(){const e=this.title?f(p,{key:"title",level:this.headingLevel},this.title):null,t=this.description?f("p",{class:g.description,key:"description"},this.description):null,i=e||t?f("div",{class:g.formHeader},e,t):null;return f("form",{class:g.form,novalidate:!0,onsubmit:this._handleSubmit,onkeydown:this._handleFormKeyDown},i,this.renderFields())}renderFields(){const{viewModel:{inputFields:e}}=this;return e.map(((e,t)=>I(e)?this.renderGroup(e,t):this.renderLabeledField(e)))}renderGroup(e,t){const{description:i,inputFields:a,label:n,state:l}=e,s=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}`,m=`${this.id}_group-description_${t}`,h=i?f("p",{class:this.classes(g.groupDescription,g.description),id:m},i):null,_="sequential"===this.groupDisplay,v=_?o:"expanded"===l,b=v?g.collapseIcon:g.expandIcon;return f("fieldset",{"aria-expanded":v.toString(),"aria-labelledby":d,"aria-describedby":i?m:"",class:this.classes(g.group,_?g.groupSequential:null,v?null:g.groupCollapsed,o?g.groupActive:null),"data-group":e,id:u,key:t,onclick:this._handleGroupClick},f("button",{role:_?"presentation":void 0,class:g.groupHeader,type:"button",tabIndex:_?-1:0},f("div",{class:g.groupTitle},f(p,{class:g.groupLabel,id:d,level:this.title?c(this.headingLevel):this.headingLevel},n),h),_?null:f("span",{class:this.classes(b,g.groupToggleIcon)})),s.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(I(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 l=n;l<a.length;l++){const e=a[l];if(e.visible)return e}return null}renderLabeledField(e){const{label:t,layer:i,type:a}=e;return f("label",{key:`${i.id}-${e.name}`,class:g.label},[t,"unsupported"!==a?this.renderInputField(e):this.renderUnsupportedField(e),this.renderAuxiliaryText(e)])}renderInputField(e){const{domain:t,name:a,type:n,value:l}=e,s=this.getCommonInputProps(e);if("coded-value"===(null==t?void 0:t.type)){if(this._inputFieldHasInputType(e,"switch")){const{fieldElement:t}=e;if(!(this._switchFieldsWithInitialIncompatibleValue.has(a)||null==l||t.input.onValue!==l&&t.input.offValue!==l))return this.renderSwitchInputField(e,s);this._switchFieldsWithInitialIncompatibleValue.add(a)}return"radio-buttons"===e.inputType?this.renderRadioButtonsInputField(e,t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),s):this.renderSelectInputField(e,this._getFieldValueOptions(a,t),s)}return"datetime-picker"===e.inputType||"date"===n?this.renderDateInputField(e,s):"number"===n?f("input",{type:"number",...s,value:i(this._activeNumberFieldEdit)&&this._activeNumberFieldEdit.fieldName===e.name?this._activeNumberFieldEdit.value:`${s.value}`}):"text-area"===e.inputType?f("textarea",{...s}):f("input",{type:"text",...s})}_parseDateTime(e,t,i){if(i){var a;let n=_.fromJSDate(this._parseDate(e,i));const l=_.fromMillis(null!=(a=t.value)?a:Date.now());return n="date"===i?n.set({hour:l.hour,minute:l.minute,second:l.second}):n.set({day:l.day,month:l.month,year:l.year}),n.isValid?n.toMillis():null}const n=_.fromJSDate(this._parseDate(e));return n.isValid?n.toMillis():null}renderDateInputField(e,t){const{value:i,includeTime:a}=e,{date:n,time:l}=this._formatDate(0),s=`${this.id}-${t.key}`,r=`${s}-date`,o=`${s}-time`,{_activeDateFieldEdit:u}=this;let{date:d,time:p}=this._formatDate(i);var c,m,h,_;(null==u?void 0:u.fieldName)===e.name&&(d=null!=(c=null==(m=u.date.input)?void 0:m.value)?c:d,p=null!=(h=null==(_=u.time.input)?void 0:_.value)?h:p);return f("div",{key:`${t.key}-date`,class:g.dateInputContainer},f("div",{class:this.classes(g.dateInputPart,a?null:g.loneDateInputPart)},f("input",{"aria-label":e.label,"aria-describedby":r,type:"text",...t,"data-date-part":"date",class:this.classes(t.class,g.inputDate),value:d}),f("div",{class:g.dateFormatHint,id:r},n)),a?f("div",{class:g.dateInputPart,key:"time-input"},f("input",{"aria-describedby":o,"aria-label":e.label,type:"text",...t,"data-date-part":"time",class:this.classes(t.class,g.inputTime),value:p}),f("div",{class:g.dateFormatHint,id:o},l)):null)}renderUnsupportedField(e){const t=this.getCommonInputProps(e);return f("input",{afterCreate:t.afterCreate,afterUpdate:t.afterUpdate,class:this.classes(g.input,g.inputField,g.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:l,messagesTemplates:s}=this,r=t.map((e=>e.map((e=>f("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(f("calcite-combobox-item",{value:`${e}`,"text-label":`${e}`,key:"incompatible-option",readOnly:!0}))}));const d=u.length>0?[f("calcite-combobox-item-group",{key:"recommended",label:l.recommended},o),f("calcite-combobox-item-group",{key:"other",label:s.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(f("calcite-combobox-item",{value:t,"text-label":this.messages.empty,key:"empty-option"},i))}return f("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,l=n.has(i.name);(l||null!=e&&""!==e&&!t.find((t=>t.value===e))||l)&&(l||n.set(i.name,e),null==a||a(n.get(i.name)))}renderRadioButtonsInputField(e,t,i){const{value:n}=e,l=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 s=a(e.fieldElement)||this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.showNoValueOption;if(!e.required&&s){const t="",a=this._inputFieldHasInputType(e,"radio-buttons")&&e.fieldElement.input.noValueOptionLabel||this.messages.empty,s=n===t||null===n;l.unshift(this.renderRadioButton({key:"empty-option",label:a,name:e.name,value:t,selected:s,props:i}))}return f("div",{key:`${i.key}-radio`,class:g.inputRadioGroup},l)}renderSwitchInputField(e,t){const{value:i}=e,a=!!this._inputFieldHasInputType(e,"switch")&&i===e.fieldElement.input.onValue;return f("calcite-switch",{...t,class:g.inputSwitch,onclick:this._handleSwitchClick,checked:a,disabled:t.readOnly})}renderRadioButton({key:e,name:t,value:i,selected:a,label:n,props:l}){return f("label",{key:e,class:g.inputRadioLabel},f("input",{...l,class:g.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)?f("calcite-input-message",{status:"invalid",icon:!0,active:!0},t):e.description?f("div",{key:"description",class:g.description},e.description):void 0}getCommonInputProps(e){const{groupDisplay:t}=this,{editable:a,group:n,hint:l,maxLength:s,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(g.input,g.inputField,h?g.inputDisabled:null,m&&!p?g.inputInvalid:null),key:o,label:o,minlength:r>-1?`${r}`:"",maxlength:s>-1?`${s}`:"",...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?l:"",required:u,tabIndex:f?-1:0}}_isInputFieldInGroup(e){return!I(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 l of this.viewModel.allInputFields){const{name:i,value:n}=l;!a(n)&&i!==e&&this.viewModel.fieldsWithContingentValues.has(i)&&(t[i]=n)}const i=this.viewModel.joinedContingentValues.slice(),n=new Map;for(const l of i){const i=l.values[e];if(a(i)||"code"!==i.objectType&&"null"!==i.objectType)continue;const{code:s,name:r}="null"===i.objectType?{code:"",name:this.messages.empty}:i.codedValue;if(n.has(s))continue;Object.entries(t).every((([e,t])=>!l.values.hasOwnProperty(e)||this._valueIsValidContingentValue(t,l.values[e])))&&n.set(s,{name:r,value:s})}return[...n.values()]}_getInputFieldFromInput(e){return this.viewModel.findField(e.getAttribute(y))}_getNumberFieldConstraints(e){const t=r(e.domain)||o(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,l=i&&this._getInputFieldFromInput(i);if(l&&"date"===a.type&&"date"===l.type&&a.field===l.field){if(""!==t.value&&""===i.value){var n;const l=i.getAttribute("data-date-part");i.value=this._formatDate(null!=(n=a.value)?n:Date.now())[l],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:u}=this._activeDateFieldEdit,d=this._parseDateTime(e.value,n,i.active?"date":"time"),p=null!==this.viewModel.getValue(n.name),c=i.input&&(u.input||!n.includeTime),m=null===d;if(t){if(m)return;(c||!a||p)&&this._updateDateFieldValue(n,d)}else{var l,s;if(""===(null==(l=i.input)?void 0:l.value)||""===(null==(s=u.input)?void 0:s.value))this._updateDateFieldValue(n,null);else if(c){var r,o;const e=`${i.input.value} ${null!=(r=null==(o=u.input)?void 0:o.value)?r:""}`,t=this._parseDateTime(e,n);!(null!==t)&&p||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,l=this._getInputFieldFromInput(e.target);if("Enter"===t)this._isInputFieldInGroup(l)&&"collapsed"===l.group.state&&(l.group.state="expanded");else{const{type:s}=l.field,r="single"===s||"double"===s,o=!i&&!a&&!n;if(("integer"===s||"small-integer"===s||r)&&o&&1===t.length){const i=Number(t),a=["-","+"],n=["e","."],l=r?[...a,...n]:a;isNaN(i)&&-1===l.indexOf(t)&&e.preventDefault()}}}_setUpNumberFieldEdit(e){const t=this._getInputFieldFromInput(e);this._activeNumberFieldEdit={fieldName:t.name,input:e,value:e.value}}_syncDateFieldEdits(e){var t,i;const a=this._getInputFieldFromInput(e);if("date"!==a.type)return;const n=e.getAttribute("data-date-part"),l="date"===n?{value:e.value,input:e,active:!0}:{...null==(t=this._activeDateFieldEdit)?void 0:t.date,active:!1},s="time"===n?{value:e.value,input:e,active:!0}:{...null==(i=this._activeDateFieldEdit)?void 0:i.time,active:!1};this._activeDateFieldEdit={fieldName:a.name,date:l,time:s}}_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"),l=this._parseDate(i,n);if(!l)return null;let s=_.fromJSDate(l);const r=t.domain,o=_.now();let u=o;if(r&&"range"===r.type){const e=_.fromMillis(r.maxValue);o<e&&(u=e)}const d=this.viewModel.getValue(t.name),p=null!=d?_.fromMillis(d):u;return s="date"===n?s.set({hour:p.hour,minute:p.minute,second:p.second}):s.set({day:p.day,month:p.month,year:p.year}),s.toMillis()}return i}_handleOptionChange(e){this._commitInputValue(e),this.scheduleRender()}_handleGroupClick(e){var t;const i=e.currentTarget["data-group"],a="expanded"===i.state,n="sequential"===this.groupDisplay,l=`.${g.groupHeader}`;if(!(a&&!e.target.closest(l))){if(this._activeInputName=null==(t=this._getFocusableInput("forward",i))?void 0:t.name,n){const t=e.target.closest(l);if(a&&!t)return;this.viewModel.inputFields.forEach((e=>{I(e)&&e!==i&&(e.state="collapsed")}))}i.state=a?"collapsed":"expanded",this._fieldFocusNeeded=n,this.scheduleRender()}}_handleSubmit(e){e.preventDefault()}_handleFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_formatDate(e){if(null==e)return{date:"",time:""};const t=_.fromMillis(e,{locale:v(),numberingSystem:"latn"});return{date:t.toLocaleString({year:"numeric",month:"2-digit",day:"2-digit"}),time:t.toFormat(b.timePattern)}}_parseDate(e,t){if(null==e||""===e)return null;const{timePattern:i,datePattern:a}=b,n=t?"date"===t?a:i:`${a} ${i}`,l=_.fromFormat(e,n,{locale:v(),numberingSystem:"latn"});return l.isValid?l.toJSDate():null}_inputFieldHasInputType(e,t){var a;return i(e.fieldElement)&&(null==(a=e.fieldElement.input)?void 0:a.type)===t}_valueIsValidContingentValue(e,i){var a;switch(i.objectType){case"any":return!0;case"null":return null==e;case"code":return e===(null==(a=i.codedValue)?void 0:a.code);case"range":return e>=i.minValue&&e<=i.maxValue;default:return t(i.objectType),!1}}};e([n("viewModel.description")],F.prototype,"description",void 0),e([n("viewModel.feature")],F.prototype,"feature",void 0),e([n("viewModel.fieldConfig")],F.prototype,"fieldConfig",void 0),e([n("viewModel.formTemplate")],F.prototype,"formTemplate",void 0),e([l()],F.prototype,"groupDisplay",void 0),e([l()],F.prototype,"headingLevel",void 0),e([l({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],F.prototype,"label",void 0),e([n("viewModel.layer")],F.prototype,"layer",void 0),e([l(),m("esri/widgets/FeatureForm/t9n/FeatureForm")],F.prototype,"messages",void 0),e([l(),m("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],F.prototype,"messagesTemplates",void 0),e([n("viewModel.strict")],F.prototype,"strict",void 0),e([n("viewModel.title")],F.prototype,"title",void 0),e([l(),h(["value-change","submit"])],F.prototype,"viewModel",void 0),e([n("viewModel.getValues")],F.prototype,"getValues",null),e([n("viewModel.submit")],F.prototype,"submit",null),F=e([s("esri.widgets.FeatureForm")],F);const w=F;export{w 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.23/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../chunks/tslib.es6.js";import{destroyMaybe as t,isNone as i}from"../../core/maybe.js";import{aliasOf as s}from"../../core/accessorSupport/decorators/aliasOf.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{cast as n}from"../../core/accessorSupport/decorators/cast.js";import{property as l}from"../../core/accessorSupport/decorators/property.js";import{subclass as o}from"../../core/accessorSupport/decorators/subclass.js";import r from"../Widget.js";import"./widgetUtils.js";import{messageBundle as a}from"./decorators/messageBundle.js";import"../../core/Logger.js";import{tsx as c}from"./jsxFactory.js";import d from"./SnappingControls/SnappingControlsViewModel.js";const p={header:!0,enabledToggle:!0,selfEnabledToggle:!0,featureEnabledToggle:!0,layerList:!0},g={base:"esri-snapping-controls",container:"esri-snapping-controls__container",panel:"esri-snapping-controls__panel",item:"esri-snapping-controls__item",toggleBlock:"esri-snapping-controls__toggle-block",layerListBlock:"esri-snapping-controls__layer-list-block",layerList:"esri-snapping-controls__layer-list",nestedContainer:"esri-snapping-controls__nested-container",disabled:"esri-disabled",esriWidget:"esri-widget",widgetIcon:"esri-icon-vertex-gps"};let h=class extends r{constructor(e,t){super((()=>{const{view:t,viewModel:i,snappingOptions:s,...n}=e;return n})(),t),this.label=void 0,this.messages=null,this.messagesCommon=null,this.snappingOptions=null,this.view=null,this.visibleElements={...p},this._defaultViewModel=null,null!=e&&e.viewModel?this.viewModel=e.viewModel:(this._defaultViewModel=new d({snappingOptions:e.snappingOptions,view:e.view}),this.viewModel=this._defaultViewModel)}destroy(){this._defaultViewModel=t(this._defaultViewModel)}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-action.js"),import("@esri/calcite-components/dist/components/calcite-block.js"),import("@esri/calcite-components/dist/components/calcite-icon.js"),import("@esri/calcite-components/dist/components/calcite-label.js"),import("@esri/calcite-components/dist/components/calcite-panel.js"),import("@esri/calcite-components/dist/components/calcite-pick-list.js"),import("@esri/calcite-components/dist/components/calcite-pick-list-item.js"),import("@esri/calcite-components/dist/components/calcite-switch.js")])}set viewModel(e){e!==this._get("viewModel")&&((i(this._defaultViewModel)||this._defaultViewModel!==e)&&(this._defaultViewModel=t(this._defaultViewModel)),this._set("viewModel",e))}castVisibleElements(e){return{...p,...e}}render(){const{label:e,visibleElements:{header:t}}=this;return c("div",{"aria-label":e,class:this.classes(g.base,g.esriWidget)},c("div",{class:g.container},t?this.renderHeaderView():this.renderContent()))}renderHeaderView(){return c("calcite-panel",{heading:this.label,class:g.panel},this.renderContent())}renderContent(){return[this.renderToggles(),this.renderLayerList()]}renderToggles(){return c("calcite-block",{class:g.toggleBlock,heading:"",open:!0},this.renderEnabledToggle(),c("div",{class:g.nestedContainer},this.renderSelfEnabledToggle(),this.renderFeatureEnabledToggle()))}renderEnabledToggle(){if(!this.visibleElements.enabledToggle)return;const{messages:{enableSnapping:e},viewModel:{snappingOptions:{enabled:t,enabledToggled:i}}}=this;return c("calcite-label",{layout:"inline-space-between"},e,c("calcite-switch",{checked:t,disabled:i,bind:this,onCalciteSwitchChange:this._enableSnappingSwitchChange}))}renderSelfEnabledToggle(){if(!this.visibleElements.selfEnabledToggle)return;const{messages:{geometryGuides:e},viewModel:{snappingOptions:{enabled:t,selfEnabled:i,enabledToggled:s}}}=this;return c("calcite-label",{layout:"inline-space-between"},e,c("calcite-switch",{checked:i,disabled:s||!t,bind:this,onCalciteSwitchChange:this._selfEnabledSwitchChange}))}renderFeatureEnabledToggle(){if(!this.visibleElements.featureEnabledToggle)return;const{messages:{featureToFeature:e},viewModel:{snappingOptions:{enabled:t,featureEnabled:i,enabledToggled:s}}}=this;return c("calcite-label",{layout:"inline-space-between"},e,c("calcite-switch",{checked:i,disabled:s||!t,bind:this,onCalciteSwitchChange:this._featureEnabledSwitchChange}))}renderLayerList(){if(!this.visibleElements.layerList)return;const{messages:{snappingLayers:e,searchLayers:t}}=this;return c("calcite-block",{heading:e,class:g.layerListBlock,open:!0,collapsible:!0},c("calcite-pick-list",{class:g.layerList,multiple:!0,bind:this,onCalciteListChange:this._layerListChange,filterEnabled:this.viewModel.layerListViewModel.operationalItems.length>=10,"filter-placeholder":t},this.renderLayerListItemCollection(this.viewModel.layerListViewModel.operationalItems)))}renderLayerListItemCollection(e){return e.map((e=>e.children.length>0?this.renderLayerListItemGroup(e):this.renderLayerListItem(e))).toArray()}renderLayerListItem(e){var t;const{messages:{untitledLayer:i}}=this,s=e.title||i,n=(null==(t=e.children)?void 0:t.length)>0,l=e.enabled;return c("calcite-pick-list-item",{slot:n?"parent-item":null,key:`${this.id}-pick-list-item-${e.uid}`,label:s,value:e.layer.id,selected:l})}renderLayerListItemGroup(e){const t=e.title||this.messages.untitledLayer;return c("calcite-pick-list-group",{"group-title":t},[...this.renderLayerListItemCollection(e.children)])}_enableSnappingSwitchChange(e){this.snappingOptions.enabled=e.target.checked}_featureEnabledSwitchChange(e){this.snappingOptions.featureEnabled=e.target.checked}_selfEnabledSwitchChange(e){this.snappingOptions.selfEnabled=e.target.checked}async _layerListChange(e){const t=await e.target.getSelectedItems();this.viewModel.updateEnabledFeatureSources([...t.keys()])}};e([l({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],h.prototype,"label",void 0),e([l(),a("esri/widgets/support/SnappingControls/t9n/SnappingControls")],h.prototype,"messages",void 0),e([l(),a("esri/t9n/common")],h.prototype,"messagesCommon",void 0),e([s("viewModel.snappingOptions")],h.prototype,"snappingOptions",void 0),e([s("viewModel.view")],h.prototype,"view",void 0),e([l()],h.prototype,"viewModel",null),e([l()],h.prototype,"visibleElements",void 0),e([n("visibleElements")],h.prototype,"castVisibleElements",null),h=e([o("esri.widgets.support.SnappingControls")],h);const m=h;export{m as default};
|
|
5
|
+
import{_ as e}from"../../chunks/tslib.es6.js";import{destroyMaybe as t,isNone as i}from"../../core/maybe.js";import{aliasOf as s}from"../../core/accessorSupport/decorators/aliasOf.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{cast as n}from"../../core/accessorSupport/decorators/cast.js";import{property as l}from"../../core/accessorSupport/decorators/property.js";import{subclass as o}from"../../core/accessorSupport/decorators/subclass.js";import r from"../Widget.js";import"./widgetUtils.js";import{messageBundle as a}from"./decorators/messageBundle.js";import"../../core/Logger.js";import{tsx as c}from"./jsxFactory.js";import d from"./SnappingControls/SnappingControlsViewModel.js";const p={header:!0,enabledToggle:!0,selfEnabledToggle:!0,featureEnabledToggle:!0,layerList:!0},g={base:"esri-snapping-controls",container:"esri-snapping-controls__container",panel:"esri-snapping-controls__panel",item:"esri-snapping-controls__item",toggleBlock:"esri-snapping-controls__toggle-block",layerListBlock:"esri-snapping-controls__layer-list-block",layerList:"esri-snapping-controls__layer-list",nestedContainer:"esri-snapping-controls__nested-container",disabled:"esri-disabled",esriWidget:"esri-widget",widgetIcon:"esri-icon-vertex-gps"};let h=class extends r{constructor(e,t){super((()=>{const{view:t,viewModel:i,snappingOptions:s,...n}=e;return n})(),t),this.label=void 0,this.messages=null,this.messagesCommon=null,this.snappingOptions=null,this.view=null,this.visibleElements={...p},this._defaultViewModel=null,null!=e&&e.viewModel?this.viewModel=e.viewModel:(this._defaultViewModel=new d({snappingOptions:e.snappingOptions,view:e.view}),this.viewModel=this._defaultViewModel)}destroy(){this._defaultViewModel=t(this._defaultViewModel)}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-action.js"),import("@esri/calcite-components/dist/components/calcite-block.js"),import("@esri/calcite-components/dist/components/calcite-icon.js"),import("@esri/calcite-components/dist/components/calcite-label.js"),import("@esri/calcite-components/dist/components/calcite-panel.js"),import("@esri/calcite-components/dist/components/calcite-pick-list.js"),import("@esri/calcite-components/dist/components/calcite-pick-list-item.js"),import("@esri/calcite-components/dist/components/calcite-switch.js")])}set viewModel(e){e!==this._get("viewModel")&&((i(this._defaultViewModel)||this._defaultViewModel!==e)&&(this._defaultViewModel=t(this._defaultViewModel)),this._set("viewModel",e))}castVisibleElements(e){return{...p,...e}}render(){const{label:e,visibleElements:{header:t}}=this;return c("div",{"aria-label":e,class:this.classes(g.base,g.esriWidget)},c("div",{class:g.container},t?this.renderHeaderView():this.renderContent()))}renderHeaderView(){return c("calcite-panel",{heading:this.label,class:g.panel},this.renderContent())}renderContent(){return[this.renderToggles(),this.renderLayerList()]}renderToggles(){return c("calcite-block",{class:g.toggleBlock,heading:"",open:!0},this.renderEnabledToggle(),c("div",{class:g.nestedContainer},this.renderSelfEnabledToggle(),this.renderFeatureEnabledToggle()))}renderEnabledToggle(){if(!this.visibleElements.enabledToggle)return;const{messages:{enableSnapping:e},viewModel:{snappingOptions:{enabled:t,enabledToggled:i}}}=this;return c("calcite-label",{layout:"inline-space-between"},e,c("calcite-switch",{checked:t,disabled:i,bind:this,onCalciteSwitchChange:this._enableSnappingSwitchChange}))}renderSelfEnabledToggle(){if(!this.visibleElements.selfEnabledToggle)return;const{messages:{geometryGuides:e},viewModel:{snappingOptions:{enabled:t,selfEnabled:i,enabledToggled:s}}}=this;return c("calcite-label",{layout:"inline-space-between"},e,c("calcite-switch",{checked:i,disabled:s||!t,bind:this,onCalciteSwitchChange:this._selfEnabledSwitchChange}))}renderFeatureEnabledToggle(){if(!this.visibleElements.featureEnabledToggle)return;const{messages:{featureToFeature:e},viewModel:{snappingOptions:{enabled:t,featureEnabled:i,enabledToggled:s}}}=this;return c("calcite-label",{layout:"inline-space-between"},e,c("calcite-switch",{checked:i,disabled:s||!t,bind:this,onCalciteSwitchChange:this._featureEnabledSwitchChange}))}renderLayerList(){if(!this.visibleElements.layerList)return;const{messages:{snappingLayers:e,searchLayers:t}}=this;return c("calcite-block",{heading:e,class:g.layerListBlock,open:!0,collapsible:!0},c("calcite-pick-list",{class:g.layerList,multiple:!0,bind:this,onCalciteListChange:this._layerListChange,filterEnabled:this.viewModel.layerListViewModel.operationalItems.length>=10,"filter-placeholder":t},this.renderLayerListItemCollection(this.viewModel.layerListViewModel.operationalItems)))}renderLayerListItemCollection(e){return e.map((e=>e.children.length>0?this.renderLayerListItemGroup(e):this.renderLayerListItem(e))).toArray()}renderLayerListItem(e){var t;const{messages:{untitledLayer:i}}=this,s=e.title||i,n=(null==(t=e.children)?void 0:t.length)>0,l=e.enabled;return c("calcite-pick-list-item",{slot:n?"parent-item":null,key:`${this.id}-pick-list-item-${e.uid}`,label:s,value:e.layer.id,selected:l})}renderLayerListItemGroup(e){const t=e.title||this.messages.untitledLayer;return c("calcite-pick-list-group",{"group-title":t,key:e.uid},[...this.renderLayerListItemCollection(e.children)])}_enableSnappingSwitchChange(e){this.snappingOptions.enabled=e.target.checked}_featureEnabledSwitchChange(e){this.snappingOptions.featureEnabled=e.target.checked}_selfEnabledSwitchChange(e){this.snappingOptions.selfEnabled=e.target.checked}async _layerListChange(e){const t=await e.target.getSelectedItems();this.viewModel.updateEnabledFeatureSources([...t.keys()])}};e([l({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],h.prototype,"label",void 0),e([l(),a("esri/widgets/support/SnappingControls/t9n/SnappingControls")],h.prototype,"messages",void 0),e([l(),a("esri/t9n/common")],h.prototype,"messagesCommon",void 0),e([s("viewModel.snappingOptions")],h.prototype,"snappingOptions",void 0),e([s("viewModel.view")],h.prototype,"view",void 0),e([l()],h.prototype,"viewModel",null),e([l()],h.prototype,"visibleElements",void 0),e([n("visibleElements")],h.prototype,"castVisibleElements",null),h=e([o("esri.widgets.support.SnappingControls")],h);const m=h;export{m as default};
|