Editor.js 24 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  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 a}from"../core/maybe.js";import{watch as i,on as o,when as n,initial as r}from"../core/reactiveUtils.js";import{aliasOf as l}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import{cast as d}from"../core/accessorSupport/decorators/cast.js";import{property as c}from"../core/accessorSupport/decorators/property.js";import{subclass as p}from"../core/accessorSupport/decorators/subclass.js";import{getDisplayFieldName as h}from"../layers/support/fieldUtils.js";import m from"../views/interactive/sketch/SketchLabelOptions.js";import u from"../views/interactive/sketch/SketchTooltipOptions.js";import g from"../views/interactive/snapping/SnappingOptions.js";import v from"./Attachments.js";import w from"./FeatureForm.js";import _ from"./FeatureTemplates.js";import f from"./Spinner.js";import k from"./Widget.js";import{workflowDeprecation as b}from"./Editor/deprecationUtils.js";import y from"./Editor/EditorViewModel.js";import{ItemList as C}from"./FeatureTemplates/ItemList.js";import{Heading as M,incrementHeadingLevel as A}from"./support/Heading.js";import F from"./support/SnappingControls.js";import{accessibleHandler as W}from"./support/decorators/accessibleHandler.js";import{messageBundle as T}from"./support/decorators/messageBundle.js";import{vmEvent as S}from"./support/decorators/vmEvent.js";import{tsx as E}from"./support/jsxFactory.js";import{classes as B}from"./support/widgetUtils.js";import{substitute as P}from"../intl/substitute.js";const j={base:"esri-editor esri-widget esri-widget--panel",message:"esri-editor__message",controls:"esri-editor__controls",controlButton:"esri-editor__control-button",progressBar:"esri-editor__progress-bar",panelToolbar:"esri-editor__panel-toolbar",panelToolbarSnappingButton:"esri-editor__panel-toolbar__snapping-button",panelContent:"esri-editor__panel-content",panelContentMessage:"esri-editor__panel-content__message",panelContentSection:"esri-editor__panel-content__section",panelContentSectionGroup:"esri-editor__panel-content__section__group",scroller:"esri-editor__scroller",snappingControlsPopover:"esri-editor__snapping-controls-popover",updateFeaturesActionButtons:"esri-editor__update-features-action-buttons",updateFeaturesActionButtonsButton:"esri-editor__update-features-action-buttons--button",featureTemplatesContainer:"esri-editor__feature-templates-container",promptContainer:"esri-editor__prompt",promptHeader:"esri-editor__prompt__header",promptHeading:"esri-editor__prompt__header__heading",promptMessage:"esri-editor__prompt__message",promptDivider:"esri-editor__prompt__divider",promptActions:"esri-editor__prompt__actions",warningIcon:"esri-icon-notice-triangle",widgetIcon:"esri-icon-edit",button:"esri-button",buttonDisabled:"esri-button--disabled",buttonSecondary:"esri-button--secondary",buttonTertiary:"esri-button--tertiary"},L=B(j.scroller,j.panelContent),x={undoRedoButtons:!1};function U(e){e.focus()}const V="esri.widgets.Editor",D=s.getLogger(V);let I=class extends(t(k)){constructor(e,t){super(e,t),this._candidateCommitted=!1,this._featureForm=new w,this._stateStack=[],this._attachments=new v({visibleElements:{addSubmitButton:!1,cancelAddButton:!1,cancelUpdateButton:!1,deleteButton:!1,errorMessage:!1,progressBar:!1,updateButton:!1}}),this._featureTemplates=new _({enableListScroll:!1}),this._filterText="",this._prompt=null,this._spinner=new f,this._snappingPopover=null,this.activeWorkflow=null,this.allowedWorkflows=null,this.useDeprecatedCreateWorkflow=!1,this.headingLevel=4,this.iconClass=j.widgetIcon,this.label=void 0,this.labelOptions=new m,this.layerInfos=null,this.messages=null,this.messagesCommon=null,this.messagesTemplates=null,this.snappingOptions=new g,this.tooltipOptions=new u,this.supportingWidgetDefaults=null,this.view=null,this.viewModel=new y,this.visibleElements={...x},this._setCandidateFeature=(e,t=!1)=>{if(this._candidateCommitted)return;const s=this._assertActiveUpdateWorkflow();s.data.edits.feature=e,t&&(s.next(),this._candidateCommitted=!0)},this._handleSave=this._handleSave.bind(this),this._handleBack=this._handleBack.bind(this),this._handleDone=this._handleDone.bind(this),this._handleDelete=this._handleDelete.bind(this),this._handleAdd=this._handleAdd.bind(this),this._handleEdit=this._handleEdit.bind(this),this._handleAttachmentAdd=this._handleAttachmentAdd.bind(this),this._handleAttachmentUpdate=this._handleAttachmentUpdate.bind(this),this._handleAttachmentDelete=this._handleAttachmentDelete.bind(this),this.EditorPanel=this.EditorPanel.bind(this)}initialize(){const{view:e,snappingOptions:t}=this;this._snappingControls=new F({snappingOptions:t,view:e,visibleElements:{header:!1}}),this.own([i((()=>this.headingLevel),(e=>{this._featureForm.headingLevel=A(e),this._featureTemplates.headingLevel=A(e)}),r),this.viewModel.featureTemplatesViewModel.on("select",(({item:e})=>this.useDeprecatedCreateWorkflow?this.startCreateWorkflowAtFeatureCreation(e):this.startCreateFeaturesWorkflowAtFeatureCreation(e))),i((()=>this.viewModel.state),((e,t)=>{const s=this._stateStack.indexOf(e);-1===s?this._stateStack.push(t):this._stateStack.splice(s)})),i((()=>this.viewModel),(e=>{this._featureForm.viewModel=e?e.featureFormViewModel:null,this._attachments.viewModel=e?e.attachmentsViewModel:null,this._featureTemplates.viewModel=e?e.featureTemplatesViewModel:null,this._spinner.viewModel=e?e.spinnerViewModel:null}),r),i((()=>this.view),((e,t)=>{const s=`editor-${this.id}-spinner`;t&&t.ui.remove(this._spinner,s),e&&e.ui.add(this._spinner,{key:s,position:"manual"})}),r),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()})),i((()=>this.supportingWidgetDefaults),(e=>{e&&(this._featureForm.set(e.featureForm),this._attachments.set(e.attachments),this._featureTemplates.set(e.featureTemplates),this.viewModel.sketchViewModel.set(e.sketch))}),r),i((()=>this._attachments?.error),(e=>{if(!e)return;const{messages:t,messagesCommon:s}=this;this._prompt={title:t.errorWarningTitle,message:e.message,context:"warning",actions:{primary:{label:s.form.ok,action:()=>{this._prompt=null}}}}})),i((()=>this.viewModel?.failures),(e=>{if(!e)return;const{messages:t}=this,[{error:s,retry:a,cancel:i}]=e;this._prompt={title:t.errorWarningTitle,message:P(t.errorWarningMessageTemplate,{errorMessage:s.message}),context:"warning",actions:{primary:{label:t.retry,action:()=>{a(),this._prompt=null}},secondary:{label:t.ignore,action:()=>(i(),this._prompt=null)}}}})),i((()=>this.viewModel?.state),(e=>{"awaiting-feature-to-update"===e&&(this._filterText=""),"awaiting-update-feature-candidate"===e&&(this._candidateCommitted=!1)})),i((()=>[this._attachments?.selectedFile,this._attachments?.submitting]),(()=>this.scheduleRender())),n((()=>!this.viewModel?.activeWorkflow),(()=>this._featureTemplates.filterText="")),o((()=>this.view),"key-down",(e=>{"Escape"===e.key&&this.viewModel?.activeWorkflow&&this._handleBack()}))])}destroy(){this._attachments.destroy(),this._featureForm.destroy(),this._featureTemplates.destroy(),this._snappingControls.destroy()}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-action.js"),import("@esri/calcite-components/dist/components/calcite-action-menu.js"),import("@esri/calcite-components/dist/components/calcite-button.js"),import("@esri/calcite-components/dist/components/calcite-flow.js"),import("@esri/calcite-components/dist/components/calcite-icon.js"),import("@esri/calcite-components/dist/components/calcite-loader.js"),import("@esri/calcite-components/dist/components/calcite-panel.js"),import("@esri/calcite-components/dist/components/calcite-popover.js"),import("@esri/calcite-components/dist/components/calcite-scrim.js")])}castVisibleElements(e){return{...x,...e}}startCreateWorkflowAtFeatureTypeSelection(){return b(D,"startCreateWorkflowAtFeatureTypeSelection","startCreateFeaturesWorkflowAtFeatureTypeSelection"),this.viewModel.startCreateWorkflowAtFeatureTypeSelection()}startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.viewModel.startCreateFeaturesWorkflowAtFeatureTypeSelection()}startCreateWorkflowAtFeatureCreation(e){return b(D,"startCreateWorkflowAtFeatureCreation","startCreateFeaturesWorkflowAtFeatureCreation"),this.viewModel.startCreateWorkflowAtFeatureCreation(e)}startCreateFeaturesWorkflowAtFeatureCreation(e){return this.viewModel.startCreateFeaturesWorkflowAtFeatureCreation(e)}startCreateWorkflowAtFeatureEdit(e){return b(D,"startCreateWorkflowAtFeatureEdit"),this.viewModel.startCreateWorkflowAtFeatureEdit(e)}startUpdateWorkflowAtFeatureSelection(){return this.viewModel.startUpdateWorkflowAtFeatureSelection()}startUpdateWorkflowAtMultipleFeatureSelection(e){return this.viewModel.startUpdateWorkflowAtMultipleFeatureSelection(e)}startUpdateWorkflowAtFeatureEdit(e){return this.viewModel.startUpdateWorkflowAtFeatureEdit(e)}deleteFeatureFromWorkflow(){return this.viewModel.deleteFeatureFromWorkflow()}cancelWorkflow(e){return this.viewModel.cancelWorkflow(e)}render(){const{_attachments:e,_prompt:t,viewModel:s}=this;if(!s)return E("div",{class:j.base});const{state:i}=s,o=a(t)?E("calcite-scrim",null,this.renderPrompt(t)):null;return E("div",{class:j.base},s.syncing||e.submitting?this.renderProgressBar():null,E("calcite-flow",null,this._stateStack.map((e=>this.renderState(e))),this.renderState(i)),o)}renderState(e){switch(e){case"disabled":break;case"ready":return this.renderLanding(e);case"awaiting-feature-creation-info":return this.renderTemplates(e);case"creating-features":case"editing-new-feature":case"editing-existing-feature":return this.renderAttributeEditing(e);case"awaiting-feature-to-update":return this.renderFeatureUpdating(e);case"awaiting-update-feature-candidate":return this.renderFeatureList(e);case"awaiting-feature-to-create":return this.renderFeatureCreation(e);case"adding-attachment":return this.renderAttachmentAdding(e);case"editing-attachment":return this.renderAttachmentEditing(e)}return E("div",null)}isPanelActive(e){return this.viewModel.state===e}renderTemplates(e){const{EditorPanel:t,headingLevel:s,messages:a,messagesCommon:i,_handleBack:o,_snappingControls:n,viewModel:{sketchViewModel:r}}=this;return E(t,{active:this.isPanelActive(e),key:"templates-panel",handleBack:o,heading:a.selectTemplate,headingLevel:s,messages:a,messagesCommon:i,sketchViewModel:r,snappingControls:n},E("div",{class:L},this._featureTemplates.render()))}renderAttributeEditing(e){const{activeWorkflow:t,EditorPanel:s,messages:a,messagesCommon:i,headingLevel:o,_handleBack:n,_snappingControls:r,viewModel:l}=this,{sketchViewModel:d}=l,c=l.featureFormViewModel;if("create-features"===t.type&&t.pendingFeatures.length<1)return this.renderFeatureCreation(e);const p="update"===t.type&&!t.data.edits.modified||l.syncing,h="update"===t.type?a.editFeature:a.createFeatures,m="update"===t.type?i.update:i.create,u="create-features"===t.type&&"create-new"===t.createFeatureState,g="update"===t.type&&t.data.editableItem.supports.includes("delete"),v="update"===t.type&&t.data.editableItem.hasAttachments,w=[{label:"create-features"===t.type&&t.numPendingFeatures>1?P(a.createFeaturesTemplate,{numFeatures:t.numPendingFeatures}):m,type:"primary",disabled:p,clickHandler:this._handleSave,width:g?"half":"full"}];g&&w.push({label:i.delete,type:"tertiary",clickHandler:this._handleDelete,appearance:"outline",width:"half"});const _=c.inputFields.every((e=>!e.visible))?this.renderMessage(P(a.clickToFinishTemplate,{button:m})):E("div",{class:j.panelContentSection},E("div",{class:j.panelContentSectionGroup},this._featureForm.render(),v?E("div",{key:"attachments"},E("div",null,a.attachments),this._attachments.render()):null));return E(s,{active:this.isPanelActive(e),key:"attribute-editing-panel",heading:h,headingLevel:o,handleBack:n,messages:a,messagesCommon:i,sketchViewModel:d,snappingControls:r},E("div",{class:L},_,u?E("calcite-scrim",null):null),this.renderFooterActions(w))}renderAttachmentAdding(e){const{_attachments:t,EditorPanel:s,_handleBack:a,headingLevel:i,messages:o,messagesCommon:n,_snappingControls:r,viewModel:{sketchViewModel:l}}=this,d=[{label:t.submitting?n.cancel:n.add,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentAdd,width:"full"}];return E(s,{active:this.isPanelActive(e),key:"attachment-adding-panel",heading:o.addAttachment,headingLevel:i,handleBack:a,messages:o,messagesCommon:n,sketchViewModel:l,snappingControls:r},E("div",{class:L},t.render()),this.renderFooterActions(d))}renderAttachmentEditing(e){const{_attachments:t,EditorPanel:s,_handleBack:a,headingLevel:i,messages:o,messagesCommon:n,_snappingControls:r,viewModel:{sketchViewModel:l}}=this,d=[{label:n.update,disabled:t.submitting||!t.selectedFile,type:"primary",clickHandler:this._handleAttachmentUpdate,width:"half"},{label:n.delete,disabled:t.submitting,type:"tertiary",clickHandler:this._handleAttachmentDelete,width:"half",appearance:"outline"}];return E(s,{active:this.isPanelActive(e),key:"attachment-editing-panel",heading:o.editAttachment,headingLevel:i,handleBack:a,messages:o,messagesCommon:n,sketchViewModel:l,snappingControls:r},E("div",{class:L},t.render()),this.renderFooterActions(d))}renderFeatureUpdating(e){const{EditorPanel:t,_handleBack:s,headingLevel:a,messages:i,messagesCommon:o,_snappingControls:n,viewModel:{sketchViewModel:r}}=this;return E(t,{active:this.isPanelActive(e),key:"feature-updating-panel",heading:i.selectFeature,headingLevel:a,handleBack:s,messages:i,messagesCommon:o,sketchViewModel:r,snappingControls:n},E("div",{class:L},this.renderMessage(i.selectFeatureToEdit)))}renderMessage(e){return E("div",{class:j.panelContentMessage},e)}renderFeatureCreation(e){const{EditorPanel:t,_handleBack:s,headingLevel:a,messages:i,messagesCommon:o,_snappingControls:n,viewModel:r}=this,{sketchViewModel:l}=r,d=r.sketchViewModel,c=this._assertActiveCreateWorkflow().data.creationInfo.layer,p=d.canUndo()&&d.createGraphic?d.createGraphic:null,h=this._getSketchingTip(c.geometryType,p);return E(t,{active:this.isPanelActive(e),key:"feature-creation-panel",heading:i.placeFeature,headingLevel:a,handleBack:s,messages:i,messagesCommon:o,sketchViewModel:l,snappingControls:n},E("div",{class:L},this.renderMessage(h)))}renderFooterActions(e){return e.map((({type:e,disabled:t,class:s,...a},i)=>this.renderButton({class:this.classes(j.controlButton,"secondary"===e?j.buttonSecondary:"tertiary"===e?j.buttonTertiary:null,t?j.buttonDisabled:null,s),disabled:t??!1,key:i,slot:"footer-actions",...a})))}renderPrompt({title:e,message:t,context:s,actions:a}){const i=!!a.secondary,o=E("calcite-button",{appearance:"solid",color:"danger"===s?"red":"blue",width:i?"half":"full",onclick:a.primary.action,key:"prompt-primary-button",afterCreate:U},a.primary.label),n=i?E("calcite-button",{appearance:"clear",color:"danger"===s?"red":"blue",width:"half",onclick:a.secondary.action,key:"prompt-secondary-button"},a.secondary.label):null;return E("div",{class:`${j.promptContainer}--${s}`},E("div",{class:j.promptHeader},E("calcite-icon",{icon:"exclamation-mark-triangle"}),E(M,{class:j.promptHeading,level:this.headingLevel},e)),E("div",{class:j.promptMessage},t),E("div",{class:j.promptDivider}),E("div",{class:j.promptActions},n,o))}renderProgressBar(){return E("div",{class:this.classes(j.progressBar),key:"progress-bar"})}renderButton(e){const{disabled:t,class:s,key:a,clickHandler:i,label:o,...n}=e;return E("calcite-button",{class:s,disabled:t,key:a,onclick:i,type:"button",...n},o)}renderLanding(e){const{EditorPanel:t,headingLevel:s,messages:a,messagesCommon:i,_snappingControls:o,viewModel:{sketchViewModel:n}}=this;return E(t,{active:this.isPanelActive(e),key:"landing-panel",heading:a.widgetLabel,headingLevel:s,showBackButton:!1,messages:a,messagesCommon:i,sketchViewModel:n,snappingControls:o},E("div",{class:L},E("div",{key:"edit-actions",class:j.panelContentSection},this.renderUpdateActions()),E("div",{key:"create-actions",class:j.panelContentSection},this.renderCreateActions())))}renderUpdateActions(){const{messages:e,messagesCommon:t}=this;return E("div",null,E(M,{level:A(this.headingLevel)},e.editFeatures),E("div",{class:j.updateFeaturesActionButtons},E("calcite-action",{text:t.select,textEnabled:!0,icon:"cursor",alignment:"start",class:j.updateFeaturesActionButtonsButton,onclick:this._handleEdit})))}renderCreateActions(){const{_featureTemplates:e,headingLevel:t,messages:s}=this;if(0!==e.viewModel.numberOfFeatureTemplates)return E("div",null,E(M,{level:A(t)},s.createFeatures),E("div",{key:"templates",class:j.featureTemplatesContainer},e.render()))}renderFeatureList(e){const{EditorPanel:t,_handleBack:s,headingLevel:a,messages:i,messagesCommon:o,messagesTemplates:n,_snappingControls:r,viewModel:{editableItems:l,sketchViewModel:d}}=this,c=this._assertActiveUpdateWorkflow().data.candidates,p=P(i.multipleFeaturesTemplate,{total:c.length}),h=new Map;let m=0;c.map((e=>({label:this._getLabel(e),id:e.attributes[e.layer.objectIdField],data:e}))).filter((e=>{const{label:t,data:s}=e,a=this._filterText.toLowerCase(),{title:i}=s.layer,o=this.viewModel.editableItems.find((e=>e.layer===s.layer));return o.supports.includes("update")&&(!a||t.toLowerCase().includes(a)||i.toLowerCase().includes(a))})).forEach((e=>{m++;const t=e.data.layer;h.has(t)?h.get(t).items.push(e):h.set(t,{id:`${t.id}`,label:t.title,items:[e]})}));const u=l.filter((({layer:e})=>h.has(e))).map((({layer:e})=>h.get(e))).toArray(),g=m>10||this._filterText.length>0;return E(t,{active:this.isPanelActive(e),key:"feature-list",heading:p,headingLevel:a,handleBack:s,messages:i,messagesCommon:o,sketchViewModel:d,snappingControls:r},E("div",{class:L},C({id:this.id,enableListScroll:!1,filterEnabled:g,filterText:this._filterText,items:u,messages:{filterPlaceholder:n.filterPlaceholder,noItems:n.noItems,noMatches:n.noMatches},onItemMouseEnter:({data:e})=>this._setCandidateFeature(e),onItemMouseLeave:()=>this._setCandidateFeature(null),onItemSelect:({data:e})=>this._setCandidateFeature(e,!0),onFilterChange:e=>this._filterText=e})))}EditorPanel(e,...t){const{active:s,handleBack:a,heading:i,headingLevel:o,key:n,messages:r,messagesCommon:l,showBackButton:d,sketchViewModel:c,snappingControls:p}=e;return E("calcite-panel",{bind:this,key:n,heading:i,headingLevel:o,showBackButton:d??!0,beforeBack:a??null,onCalcitePanelScroll:this._onSnappingPopoverPanelScroll},E("div",{class:j.panelToolbar},E("calcite-popover",{autoClose:s,afterCreate:this._afterSnappingPopoverCreated,afterUpdate:this._afterSnappingPopoverUpdated,bind:this,label:r.snappingSettings,heading:r.snappingSettings,"reference-element":`${n}__snappingButton`,"overlay-positioning":"fixed",placement:"bottom"},E("div",{class:j.snappingControlsPopover},p.render())),E("calcite-button",{id:`${n}__snappingButton`,text:r.snapping,appearance:"transparent",color:"neutral",alignment:"icon-end-space-between","icon-start":"vertex-gps","icon-end":"caret-down",width:"full",class:j.panelToolbarSnappingButton},r.snapping),this.visibleElements.undoRedoButtons?[E("calcite-button",{key:"undo-button",text:l.undo,appearance:"transparent",color:"neutral",alignment:"center","icon-start":"undo",scale:"l",disabled:!c.canUndo(),onclick:c.undo.bind(c)}),E("calcite-button",{key:"redo-button",text:l.redo,appearance:"transparent",color:"neutral",alignment:"center","icon-start":"redo",scale:"l",disabled:!c.canRedo(),onclick:c.redo.bind(c)})]:null),t)}_onSnappingPopoverPanelScroll(){this._snappingPopover?.open&&this._snappingPopover.toggle()}_afterSnappingPopoverCreated(e){this._snappingPopover=e}_afterSnappingPopoverUpdated(e){this._snappingPopover=e}_getSketchingTip(e,t){const{messages:s}=this;if("point"===e)return s.tips.clickToAddPoint;if("polygon"===e||"polyline"===e){if(!t)return s.tips.clickToStart;const a=t.geometry,i="polygon"===e?"rings":"paths",[o]=a[i];return"polygon"===e&&o<4?s.tips.clickToContinue:s.tips.clickToContinueThenDoubleClickToEnd}return s.tips.clickToAddFeature}_getLabel(e){const t=e.layer;if(!t)return null;const{objectIdField:s}=t,{attributes:a}=e,i=h(t);return i&&a[i]&&`${a[i]}`||P(this.messages.untitledFeatureTemplate,{id:a[s]})}_handleDelete(){const{messages:e,messagesCommon:t}=this;this._prompt={title:e.deleteWarningTitle,message:e.deleteWarningMessage,context:"danger",actions:{primary:{label:t.delete,action:()=>{this.viewModel.deleteFeatureFromWorkflow(),this._prompt=null}},secondary:{label:e.keepFeature,action:()=>this._prompt=null}}}}_handleSave(){const{featureFormViewModel:e}=this.viewModel;e.submit(),!e.submittable||e.validateContingencyConstraints(e.getValues(),{includeIncompleteViolations:!0}).length>0||this.viewModel.activeWorkflow.commit()}_handleAttachmentAdd(){const{_attachments:e}=this,{activeWorkflow:t}=this.viewModel;e.addAttachment().then((()=>t.previous()))}_handleAttachmentUpdate(){const{_attachments:e}=this,{activeWorkflow:t}=this.viewModel;e.updateAttachment().then((()=>t.previous()))}_handleAttachmentDelete(){const{messages:e,messagesCommon:t}=this;this._prompt={title:e.deleteAttachmentWarningTitle,message:e.deleteAttachmentWarningMessage,context:"danger",actions:{primary:{label:t.delete,action:()=>{const{_attachments:e}=this,{activeWorkflow:t}=this.viewModel;e.deleteAttachment(e.viewModel.activeAttachmentInfo).then((()=>{t.previous(),this._prompt=null}))}},secondary:{label:e.keepAttachment,action:()=>this._prompt=null}}}}_handleAdd(){this.viewModel.canCreate}_handleEdit(){this.viewModel.canUpdate&&this.viewModel.startUpdateWorkflowAtFeatureSelection()}_handleDone(){this.viewModel.cancelWorkflow({force:!0})}async _handleBack(){const{messages:e}=this,t=this.activeWorkflow,s=()=>{t.hasPreviousStep?t.previous({cancelCurrentStep:!0}):this.viewModel.cancelWorkflow({force:!0})};if("create"===t.type||"create-features"===t.type&&t.numPendingFeatures>0||"editing-existing-feature"===t.stepId&&t.data.edits.modified){const{type:a}=t,i="create"===a?e.cancelAddWarningMessage:e.cancelEditWarningMessage,o="create"===a?e.cancelAddTitle:e.cancelEditTitle,n="create"===a?e.continueAdding:e.continueEditing,r="create"===a?e.discardFeature:e.discardEdits;throw this._prompt={title:o,message:i,context:"danger",actions:{primary:{label:r,action:()=>{s(),this._prompt=null}},secondary:{label:n,action:()=>this._prompt=null}}},this.scheduleRender(),new Error}s()}_assertActiveCreateWorkflow(){const{type:e}=this.viewModel.activeWorkflow;if("create"===e||"create-features"===e)return this.viewModel.activeWorkflow;throw Error("Expected activeWorkflow to be instance of CreateWorkflow or CreateFeaturesWorkflow")}_assertActiveUpdateWorkflow(){if("update"===this.viewModel.activeWorkflow.type)return this.viewModel.activeWorkflow;throw Error("Expected activeWorkflow to be an UpdateWorkflow")}};e([c()],I.prototype,"_attachments",void 0),e([l("viewModel.activeWorkflow")],I.prototype,"activeWorkflow",void 0),e([l("viewModel.allowedWorkflows")],I.prototype,"allowedWorkflows",void 0),e([c()],I.prototype,"useDeprecatedCreateWorkflow",void 0),e([c()],I.prototype,"headingLevel",void 0),e([c()],I.prototype,"iconClass",void 0),e([c({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],I.prototype,"label",void 0),e([l("viewModel.labelOptions")],I.prototype,"labelOptions",void 0),e([l("viewModel.layerInfos")],I.prototype,"layerInfos",void 0),e([c(),T("esri/widgets/Editor/t9n/Editor")],I.prototype,"messages",void 0),e([c(),T("esri/t9n/common")],I.prototype,"messagesCommon",void 0),e([c(),T("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],I.prototype,"messagesTemplates",void 0),e([l("viewModel.snappingOptions")],I.prototype,"snappingOptions",void 0),e([l("viewModel.tooltipOptions")],I.prototype,"tooltipOptions",void 0),e([c()],I.prototype,"supportingWidgetDefaults",void 0),e([l("viewModel.view")],I.prototype,"view",void 0),e([c(),S(["workflow-cancel","workflow-commit"])],I.prototype,"viewModel",void 0),e([c()],I.prototype,"visibleElements",void 0),e([d("visibleElements")],I.prototype,"castVisibleElements",null),e([W()],I.prototype,"_handleDelete",null),e([W()],I.prototype,"_handleAttachmentAdd",null),e([W()],I.prototype,"_handleAttachmentUpdate",null),e([W()],I.prototype,"_handleAttachmentDelete",null),e([W()],I.prototype,"_handleAdd",null),e([W()],I.prototype,"_handleEdit",null),e([W()],I.prototype,"_handleDone",null),I=e([p(V)],I);const O=I;export{O as default};