udp-stencil-component-library 25.18.2-beta.11 → 25.18.2-beta.12

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.
Files changed (61) hide show
  1. package/dist/cjs/{SearchBuilder-C1sUitjQ.js → SearchBuilder-DYM_FL5l.js} +1 -1
  2. package/dist/cjs/advanced-search_12.cjs.entry.js +3 -3
  3. package/dist/cjs/ag-grid-base_6.cjs.entry.js +2 -2
  4. package/dist/cjs/ambient-template-grid.cjs.entry.js +3 -3
  5. package/dist/cjs/api-method-instance-grid.cjs.entry.js +1 -1
  6. package/dist/cjs/{apiUtils-DT-fLJOw.js → apiUtils-bDl8etNp.js} +1 -1
  7. package/dist/cjs/{catalog-store-BOiNPWZB.js → catalog-store-DIF1IDLi.js} +1 -1
  8. package/dist/cjs/entity-maintenance-grid.cjs.entry.js +2 -2
  9. package/dist/cjs/index.cjs.js +4 -4
  10. package/dist/cjs/loader.cjs.js +1 -1
  11. package/dist/cjs/{makeApiCall-CFfg9gI0.js → makeApiCall-B9MMU_Ob.js} +4 -1
  12. package/dist/cjs/search-method-grid.cjs.entry.js +2 -2
  13. package/dist/cjs/stencil-library.cjs.js +1 -1
  14. package/dist/cjs/udp-forms-builder.cjs.entry.js +4 -4
  15. package/dist/cjs/udp-forms-renderer.cjs.entry.js +37 -19
  16. package/dist/collection/components/forms/udp-forms/udp-forms-builder/udp-forms-builder.js +4 -4
  17. package/dist/collection/components/forms/udp-forms/udp-forms-renderer/udp-forms-renderer.js +38 -3
  18. package/dist/collection/components/forms/udp-forms/udp-forms-utils/form-handler/UdpFormHandler.js +7 -7
  19. package/dist/collection/components/forms/udp-forms/udp-forms-utils/form-submission-handler/FormSubmissionHandler.js +14 -5
  20. package/dist/collection/components/forms/udp-forms/udp-forms-utils/form-submission-handler/FormSubmissionHandlerFactory.js +2 -2
  21. package/dist/collection/udp-utilities/api/makeApiCall/makeApiCall.js +4 -1
  22. package/dist/components/makeApiCall.js +1 -1
  23. package/dist/components/udp-forms-builder.js +1 -1
  24. package/dist/components/udp-forms-renderer.js +1 -1
  25. package/dist/docs.json +33 -3
  26. package/dist/esm/{SearchBuilder-CvKqGlUH.js → SearchBuilder-BjVdKjci.js} +1 -1
  27. package/dist/esm/advanced-search_12.entry.js +3 -3
  28. package/dist/esm/ag-grid-base_6.entry.js +2 -2
  29. package/dist/esm/ambient-template-grid.entry.js +3 -3
  30. package/dist/esm/api-method-instance-grid.entry.js +1 -1
  31. package/dist/esm/{apiUtils-cUHs50y0.js → apiUtils-11-yfzUs.js} +1 -1
  32. package/dist/esm/{catalog-store-BhgNAUY6.js → catalog-store-CbwcwIKF.js} +1 -1
  33. package/dist/esm/entity-maintenance-grid.entry.js +2 -2
  34. package/dist/esm/index.js +4 -4
  35. package/dist/esm/loader.js +1 -1
  36. package/dist/esm/{makeApiCall-B-daVutk.js → makeApiCall-2umiVB6u.js} +4 -1
  37. package/dist/esm/search-method-grid.entry.js +2 -2
  38. package/dist/esm/stencil-library.js +1 -1
  39. package/dist/esm/udp-forms-builder.entry.js +4 -4
  40. package/dist/esm/udp-forms-renderer.entry.js +37 -19
  41. package/dist/stencil-library/{SearchBuilder-CvKqGlUH.js → SearchBuilder-BjVdKjci.js} +1 -1
  42. package/dist/stencil-library/advanced-search_12.entry.js +1 -1
  43. package/dist/stencil-library/ag-grid-base_6.entry.js +1 -1
  44. package/dist/stencil-library/ambient-template-grid.entry.js +1 -1
  45. package/dist/stencil-library/api-method-instance-grid.entry.js +1 -1
  46. package/dist/stencil-library/{apiUtils-cUHs50y0.js → apiUtils-11-yfzUs.js} +1 -1
  47. package/dist/stencil-library/{catalog-store-BhgNAUY6.js → catalog-store-CbwcwIKF.js} +1 -1
  48. package/dist/stencil-library/entity-maintenance-grid.entry.js +1 -1
  49. package/dist/stencil-library/index.esm.js +1 -1
  50. package/dist/stencil-library/makeApiCall-2umiVB6u.js +1 -0
  51. package/dist/stencil-library/search-method-grid.entry.js +1 -1
  52. package/dist/stencil-library/stencil-library.esm.js +1 -1
  53. package/dist/stencil-library/udp-forms-builder.entry.js +1 -1
  54. package/dist/stencil-library/udp-forms-renderer.entry.js +1 -1
  55. package/dist/types/components/forms/udp-forms/udp-forms-renderer/udp-forms-renderer.d.ts +1 -0
  56. package/dist/types/components/forms/udp-forms/udp-forms-utils/form-submission-handler/FormSubmissionHandler.d.ts +3 -1
  57. package/dist/types/components/forms/udp-forms/udp-forms-utils/form-submission-handler/FormSubmissionHandlerFactory.d.ts +1 -1
  58. package/dist/types/components.d.ts +4 -2
  59. package/dist/types/udp-utilities/api/makeApiCall/makeApiCall.d.ts +1 -1
  60. package/package.json +1 -1
  61. package/dist/stencil-library/makeApiCall-B-daVutk.js +0 -1
@@ -1 +1 @@
1
- import{p as t,H as s,h as e,t as i}from"./index2.js";import{throttle as o}from"lodash";import{g as n}from"./tenantUtils.js";import{f as r}from"./udp-form-api-utils.js";import{c as a,b as l,U as u,a as c}from"./enums.js";import{b as d}from"./utils.js";import{c as m,m as h}from"./makeApiCall.js";import{S as p,c as f}from"./SearchBuilder.js";import{C as b}from"./configService.js";import{v4 as y}from"uuid";import{d as v}from"./custom-button2.js";import{d as w}from"./file-upload2.js";import{d as j}from"./fluent-dialog2.js";import{d as S}from"./form-metadata-display2.js";import{d as O}from"./image-upload2.js";import{d as g}from"./numeric-field2.js";import{d as F}from"./selectable-list2.js";import{d as I}from"./signature-input2.js";import{d as C}from"./stencil-field2.js";import{d as E}from"./stencil-form2.js";import{d as k}from"./stencil-icon-button2.js";import{d as D}from"./tally.js";import{d as $}from"./text-area2.js";import{d as U}from"./text-field2.js";import{d as x}from"./udp-adornment2.js";import{d as q}from"./udp-ambient-card2.js";import{d as K}from"./udp-ambient-tool-tip2.js";import{d as P}from"./udp-badge2.js";import{d as A}from"./udp-button2.js";import{d as L}from"./udp-container2.js";import{d as R}from"./udp-date-selector2.js";import{d as _}from"./udp-datetime-selector2.js";import{d as M}from"./udp-forms-ui2.js";import{d as T}from"./udp-icon2.js";import{d as V}from"./udp-icon-button2.js";import{d as N}from"./udp-linear-loader2.js";import{d as B}from"./udp-list-renderer2.js";import{d as J}from"./udp-menu-item2.js";import{d as Q}from"./udp-pagination2.js";import{d as z}from"./udp-pop-over2.js";import{d as W}from"./udp-question2.js";import{d as G}from"./udp-question-comments2.js";import{d as H}from"./udp-save-draft-button2.js";import{d as X}from"./udp-selector2.js";import{d as Y}from"./udp-side-sheet2.js";import{d as Z}from"./udp-time-selector2.js";import{d as tt}from"./unity-typography2.js";class st{constructor(t={}){this.id=null,this.formId=null,this.formVersion=null,this.data={},this.unityUserId=null,this.clusterId=null,this.userDisplayName="",this.status=null,this.businessObjectKey="",this.udpTags=[],this.form=null,this.initialCreatedOn=null,this.lastModifiedOn=null,this.submittedOn=null,this.generic1=null,this.generic2=null,this.generic3=null,this.userEmail=null,Object.assign(this,t)}processSubmissionIntoFormDataWithoutValues(t){const s=this.buildBaseSubmissionData(t),e=m(s);return e.append("Data",JSON.stringify(this.data)),e}processSubmissionIntoFormData(t,s){const e=this.buildBaseSubmissionData(s),{cleanedData:i,files:o}=this.extractCleanedDataAndFiles(t),n=m(e);return o.forEach((t=>n.append("FormFiles",t))),n.append("Data",JSON.stringify({submissionResponseData:i,submissionMetadata:this.data.submissionMetadata||null})),n}buildBaseSubmissionData(t){const s={FormId:this.formId,FormVersion:""+this.formVersion,Status:t};return this.id&&(s.Id=this.id),s.InitialCreatedOn=this.initialCreatedOn?this.initialCreatedOn:(new Date).toISOString(),s.LastModifiedOn=this.lastModifiedOn?this.lastModifiedOn:(new Date).toISOString(),this.submittedOn&&(s.submittedOn=this.submittedOn),this.generic1&&(s.generic1=""+this.generic1),this.generic2&&(s.generic2=""+this.generic2),this.generic3&&(s.generic3=""+this.generic3),s}extractCleanedDataAndFiles(t){const s=[],e={};for(const i in t){e[i]={};for(const o in t[i]){const n=t[i][o],{value:r,fieldFiles:a}=this.extractValueAndFiles(n);a&&s.push(...a);const l=this.processComments(n.comments),u=this.processMetadata(n.metadata);e[i][o]=Object.assign({value:r,comments:l},u&&{metadata:u})}}return{cleanedData:e,files:s}}extractValueAndFiles(t){var s,e;let i=(null===(s=null==t?void 0:t.value)||void 0===s?void 0:s.files)?t.value.value:null==t?void 0:t.value;const o=null===(e=null==t?void 0:t.value)||void 0===e?void 0:e.files;return o&&Array.isArray(o)?{value:"string"==typeof i&&""!==i.trim()?i:"",fieldFiles:o}:function(t){return!!Array.isArray(t)&&t.every((t=>t instanceof File))}(i)?{value:i.length>0?i.map((t=>t.name)).join(","):"",fieldFiles:i}:i instanceof File?{value:i.name,fieldFiles:[i]}:Array.isArray(i)?{value:i.map((t=>"string"==typeof t?t:null==t?void 0:t.value)).join(",")}:{value:i}}processComments(t){var s;return null!==(s=null==t?void 0:t.map((t=>Object.assign({},t))))&&void 0!==s?s:[]}processMetadata(t){return t&&Object.keys(t).length>0?Object.assign({},t):void 0}}class et{constructor(t){this.accessMode=t}async addComment(t,s){if(!(null==t?void 0:t.id))throw Error("Cannot add a comment without a submission ID.");const e=`${b.productV1ApiUrl}/UdpFormSubmission/${t.id}/comments/${this.accessMode}`;await h("POST",e,s,!0)}async updateComment(t,s){if(!(null==t?void 0:t.id))throw Error("Cannot update a comment without a submission ID.");const{sectionKey:e,questionKey:i,commentId:o,value:n}=s,r=`${b.productV1ApiUrl}/UdpFormSubmission/${t.id}/comments/${o}`;await h("PUT",r,{value:n,sectionKey:e,questionKey:i},!0)}async deleteComment(t,s){if(!(null==t?void 0:t.id))throw Error("Cannot delete a comment without a submission ID.");const{commentId:e}=s,i=`${b.productV1ApiUrl}/UdpFormSubmission/${t.id}/comments/${e}`;await h("DELETE",i,null,!0)}async fetchAndPopulateUdpFormSubmissionObj(t){if(!(null==t?void 0:t.id))return console.warn("Cannot fetch form submission without an ID."),t;if("public"===this.accessMode){const s=await this.getFormSubmissionByIdAndUser(t.id,t.unityUserId);return s?new st(Object.assign(Object.assign({},t),s)):t}const{id:s}=t,e=await this.getFormSubmissionById(s);return e?new st(Object.assign(Object.assign({},t),e)):t}async createNewLinkedFollowUpFormSubmission(t){if("public"===this.accessMode)throw Error("Follow-up form submissions are not supported for public forms.");return this.saveFormDataWithoutValues(t,a.InProgress)}async saveCurrentFormSubmissionState(t,s){return"public"===this.accessMode?s:this.saveSubmissionToDB(t,s,a.InProgress)}async finalizeFormSubmissionState(t,s){return this.saveSubmissionToDB(t,s,a.Submitted)}async saveFormDataWithoutValues(t,s){const e=t.processSubmissionIntoFormDataWithoutValues(s),{method:i,url:o}=this.getApiRequestInfo(t),n=await h(i,o,e,!0);return""===n?await this.fetchAndPopulateUdpFormSubmissionObj(t):new st(Object.assign(Object.assign({},t),n))}getApiRequestInfo(t){const s=`${b.productV1ApiUrl}/UdpFormSubmission/${this.accessMode}`;return"public"===this.accessMode?{method:"POST",url:s}:t.id?{method:"PUT",url:s}:{method:"POST",url:s}}async saveSubmissionToDB(t,s,e){const i=s.processSubmissionIntoFormData(t,e),{method:o,url:n}=this.getApiRequestInfo(s),r=await h(o,n,i,!0);if(""===r)return await this.fetchAndPopulateUdpFormSubmissionObj(s);const a=new st(Object.assign(Object.assign({},s),r));return Object.assign(s,a),a}async getFormSubmissionById(t){var s;try{const e=new p(1,1).addFilter("id",t,f.EQUALS),i=await e.execute("UdpFormSubmission");return(null===(s=null==i?void 0:i.pageList)||void 0===s?void 0:s[0])||null}catch(t){return console.error("Error fetching form submission by ID:",t),null}}async getFormSubmissionByIdAndUser(t,s){var e;try{const i=new p(1,1).addFilter("id",t,f.EQUALS).addFilter("unityUserId",s,f.EQUALS),o=await i.execute("UdpFormSubmission");return(null===(e=null==o?void 0:o.pageList)||void 0===e?void 0:e[0])||null}catch(t){return console.error("Error fetching form submission by ID:",t),null}}}class it{static create(t,s){return new et(t?"public":"private")}}class ot{constructor(t,s=!1){this.tenantId=t,this.isPublic=s}buildDescribeUrl(t,s){const e=b.productV1ApiUrl;return this.isPublic?`${e}/UdpForm/${t}/${s}/describe/public`:`${e}/UdpForm/${t}/${s}/describe`}async getFormByFormIdAndFormVersion(t,s){const e=this.buildDescribeUrl(t,s),i=await h("GET",e);return i.styleOverrides&&"string"==typeof i.styleOverrides&&(i.styleOverrides=JSON.parse(i.styleOverrides)),i}}class nt{constructor(t){t&&Object.assign(this,t)}}const rt=(t,s)=>{const e=Object.keys(s),i=new Set,o=RegExp(`^${t}_(\\d+)`);return e.forEach((t=>{const s=t.match(o);s&&s[1]&&i.add(Number(s[1]))})),Array.from(i).sort(((t,s)=>t-s))},at=(t,s)=>{const e=`${"undefined"!=typeof window?window.location.pathname:"/page/"+l.FormRendererPageId}?udpf_submissionId=${t}${"undefined"!=typeof window?window.location.hash:""}`,i=s;if(i){if("function"==typeof i.replace)return void i.replace(e);if("function"==typeof i.push)return void i.push(e);if("function"==typeof i){try{i(e,{replace:!0})}catch(t){i(e)}return}}"undefined"!=typeof window&&window.history&&"function"==typeof window.history.replaceState?window.history.replaceState({},"",e):"undefined"!=typeof window&&(window.location.href=e)},lt=(t,s)=>{null==s||s(t,{variant:"success",anchorOrigin:{vertical:"top",horizontal:"center"}})},ut=(t,s)=>{null==s||s(t,{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}})},ct=t=>{if(!t)return{};if("object"==typeof t)return t;if("string"!=typeof t)return{};try{return JSON.parse(t||"{}")}catch(t){return{}}},dt=t(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.isPublic=!1,this.autoSaveDelay=2e3,this.urlContext={},this.currentValues={},this.submitSuccessful=!1,this.isLoading=!1,this.isSaving=!1,this.isSubmitted=!1,this.dynamicSections=[],this.isUpdatingSections=!1,this.reRenderKey=0,this.hasUnsavedChanges=!1,this.sideSheetFollowUpFormsList=[],this.followUpSideSheetTotalItems=0,this.isFollowUpFormsSideSheetOpen=!1,this.followUpSideSheetListPageNumber=1,this.FOLLOW_UP_SIDE_SHEET_PAGE_SIZE=5,this.componentMap={history:"history",listItemData:"listItemData",handleLaunchFollowUpForm:"handleLaunchFollowUpForm"},this.tenantId=n(),this.clientUserInfo={id:null,displayName:null,email:null},this.followUpParentSectionKey="",this.followUpParentQuestionKey="",this.publicFeatures={allowDraftSave:!1,allowComments:!0,allowFollowUpForms:!1},this.handleLaunchFollowUpFormSideSheet=async t=>{try{if(this.isPublic)return;this.followUpParentSectionKey=t.detail.sectionKey,this.followUpParentQuestionKey=t.detail.questionKey,await this.loadFollowUpForms(this.followUpParentSectionKey,this.followUpParentQuestionKey),this.isFollowUpFormsSideSheetOpen=!0}catch(t){console.error("Error loading follow-up forms:",t)}},this.duplicateRepeatableSection=t=>{if(!this.isSubmitted&&!this.isUpdatingSections){this.isUpdatingSections=!0,this.isLoading=!0;try{const{nextDynamicSections:s,nextValues:e}=(t=>{var s,e,i;const{dynamicSections:o,values:n,index:r}=t,a=o[r];if(!a)return{nextDynamicSections:o,nextValues:n};const l=a.name,c=rt(l,n),d=c.length>0?Math.max(...c)+1:2,m=Object.assign(Object.assign({},structuredClone(a)),{formQuestions:(a.formQuestions||[]).map((t=>{const s=structuredClone(t);return s.questionIdentifierKey=`${l}_${d}.${t.name}`,s})),isOriginalSection:!1,sectionPositionSuffix:d});let h=r;for(let t=r+1;t<o.length&&o[t].name===l;t++)h=t;const p=[...o.slice(0,h+1),m,...o.slice(h+1)],f=structuredClone(n||{}),b=`${l}_${d}`,y=(t=>t.isOriginalSection?t.name:`${t.name}_${t.sectionPositionSuffix}`)(a);for(const t of m.formQuestions||[]){f[b]||(f[b]={});let o="";if(t.fieldTypeId===u.Paragraph){const r=null===(e=null===(s=null==n?void 0:n[y])||void 0===s?void 0:s[t.name])||void 0===e?void 0:e.value,a=ct(t.fieldProperties),l=null!==(i=null==a?void 0:a.paragraphText)&&void 0!==i?i:"";o=null!=r?r:l}f[b][t.name]={value:o,comments:[],metadata:{}}}return{nextDynamicSections:p,nextValues:f}})({dynamicSections:this.dynamicSections,values:structuredClone(this.udpFormSubmission.data.submissionResponseData||{}),index:t});this.dynamicSections=s,this.currentValues=Object.assign({},e),this.udpFormSubmission.data.submissionResponseData=Object.assign({},e),this.triggerFormRerender()}finally{this.isUpdatingSections=!1,this.isLoading=!1,this.hasUnsavedChanges=!0}}},this.deleteRepeatableSection=t=>{if(this.isSubmitted)return;const s=this.dynamicSections[t];if(s&&!s.isOriginalSection){this.isUpdatingSections=!0,this.isLoading=!0;try{const{nextDynamicSections:s,nextValues:e}=(t=>{const{dynamicSections:s,values:e,index:i}=t,o=s[i];if(!o||o.isOriginalSection)return{nextDynamicSections:s,nextValues:e};const n=o.name,r=o.sectionPositionSuffix,a=`${n}_${r}`,l=Object.assign({},e||{});delete l[a];const u=structuredClone(s);return u.splice(i,1),u.forEach((t=>{var s;if(t.name!==n||t.isOriginalSection||(null!==(s=t.sectionPositionSuffix)&&void 0!==s?s:0)<=(null!=r?r:0))return;const e=t.sectionPositionSuffix,i=`${n}_${e}`,o=e-1,a=`${n}_${o}`;t.sectionPositionSuffix=o,t.formQuestions=(t.formQuestions||[]).map((t=>{const s=structuredClone(t);return s.questionIdentifierKey=`${a}.${t.name}`,s})),l[i]&&(l[a]=structuredClone(l[i]),delete l[i])})),{nextDynamicSections:u,nextValues:l}})({dynamicSections:this.dynamicSections,values:Object.assign({},this.udpFormSubmission.data.submissionResponseData||{}),index:t});this.dynamicSections=s,this.currentValues=Object.assign({},e),this.udpFormSubmission.data.submissionResponseData=Object.assign({},e),this.triggerFormRerender()}finally{this.isUpdatingSections=!1,this.isLoading=!1,this.hasUnsavedChanges=!0}}},this.performBackgroundSaveAndUpdateLocalSubmissionState=async t=>this.performBackgroundSaveAndUpdateLocalSubmissionStateInternal(t),this.performBackgroundSaveAndUpdateLocalSubmissionStateInternal=async(t,s)=>{var e,i;const o=null!==(e=null==s?void 0:s.allowUrlReplace)&&void 0!==e?e:!this.isPublic,n=null!==(i=null==s?void 0:s.forceCreateDraftIfMissingId)&&void 0!==i&&i;if(!this.isPublic||this.publicFeatures.allowDraftSave||n)try{await this.formSubmissionHandler.saveCurrentFormSubmissionState(t,this.udpFormSubmission),await this.refreshSubmissionAndSyncState(),o&&!new URLSearchParams(window.location.search).has("udpf_submissionId")&&at(this.udpFormSubmission.id,this.history)}catch(t){}finally{this.isSaving=!1,this.hasUnsavedChanges=!1}},this.refreshSubmissionAndSyncState=async()=>{var t,s;if(!(null===(t=this.udpFormSubmission)||void 0===t?void 0:t.id))return;const e=await this.formSubmissionHandler.fetchAndPopulateUdpFormSubmissionObj(this.udpFormSubmission);this.udpFormSubmission=e,this.currentValues=Object.assign({},(null===(s=e.data)||void 0===s?void 0:s.submissionResponseData)||{}),this.isSubmitted=e.status===a.Submitted},this.handleManualSave=async t=>{if(!this.isPublic||this.publicFeatures.allowDraftSave){this.isSaving=!0;try{await this.formSubmissionHandler.saveCurrentFormSubmissionState(t,this.udpFormSubmission),await this.refreshSubmissionAndSyncState(),new URLSearchParams(window.location.search).has("udpf_submissionId")||at(this.udpFormSubmission.id,this.history),lt("Form saved successfully.",this.enqueueSnackbar)}catch(t){ut("There was an error saving this form",this.enqueueSnackbar)}finally{this.isSaving=!1,this.hasUnsavedChanges=!1}}},this.handleFormChange=t=>{this.isUpdatingSections||(this.udpFormSubmission.data.submissionResponseData=t)},this.handleFinish=()=>{this.triggerAction&&this.triggerAction(null,{action:"finish"})},this.triggerFormRerender=()=>{const t=window.scrollY;this.reRenderKey+=1,requestAnimationFrame((()=>{window.scrollTo({top:t,behavior:"auto"})}))},this.handleLaunchFollowUpForm=async(t,s,e,i,o,n,r)=>{const a=await this.formHandler.getFormByFormIdAndFormVersion(t,s),u={submissionResponseData:d(a),submissionMetadata:{ParentSubmission:{submissionId:e,formId:i,formVersion:o}}},c=new st({formId:t,formVersion:s,unityUserId:this.clientUserInfo.id,data:u}),m=it.create(!1,this.clientUserInfo.id),h=await m.createNewLinkedFollowUpFormSubmission(c);this.udpFormSubmission.data.submissionResponseData[n][r].metadata=Object.assign(Object.assign({},this.udpFormSubmission.data.submissionResponseData[n][r].metadata),{followUpFormSubmissionId:h.id}),await this.performBackgroundSaveAndUpdateLocalSubmissionState(this.udpFormSubmission.data.submissionResponseData),window.open(`/page/${l.FormRendererPageId}?udpf_submissionId=${h.id}`,"_blank"),this.handleSideSheetClose(),this.triggerFormRerender()},this.handleSideSheetClose=()=>{this.sideSheetFollowUpFormsList=[],this.followUpSideSheetListPageNumber=1,this.followUpSideSheetTotalItems=0,this.isFollowUpFormsSideSheetOpen=!1,this.followUpParentSectionKey="",this.followUpParentQuestionKey=""}}componentDidLoad(){this.el&&(this.el.addEventListener("questionCommentAction",(async t=>this.handleQuestionCommentLiveCRUD(t))),this.el.addEventListener("launchFollowUpFormSideSheet",(t=>this.handleLaunchFollowUpFormSideSheet(t))),this.el.addEventListener("formDirtyChange",(t=>{this.hasUnsavedChanges=this.hasUnsavedChanges||t.detail})))}async componentWillLoad(){var t;this.isLoading=!0;try{if(this.isPublic)this.clientUserInfo.id="00000000-0000-0000-0000-000000000001",this.clientUserInfo.displayName="Anonymous";else{const s=null===(t=this.getUserCallback)||void 0===t?void 0:t.call(this);s&&(this.clientUserInfo.id=s.id||null,this.clientUserInfo.displayName=s.name||null,this.clientUserInfo.email=s.email||null)}let s,e;this.formSubmissionHandler=it.create(this.isPublic,this.clientUserInfo.id),this.udpFormSubmission=new st({id:this.submissionId,formId:this.formId,formVersion:this.version,unityUserId:this.clientUserInfo.id,generic1:this.urlContext.generic1,generic2:this.urlContext.generic2,generic3:this.urlContext.generic3}),this.submissionId&&(this.udpFormSubmission=await this.formSubmissionHandler.fetchAndPopulateUdpFormSubmissionObj(this.udpFormSubmission)),this.submissionId?(s=this.udpFormSubmission.formId,e=this.udpFormSubmission.formVersion):this.formId&&this.version&&(s=this.formId,e=this.version),this.formHandler=new ot(this.tenantId);const i=await this.formHandler.getFormByFormIdAndFormVersion(s,e);if(this.udpForm=new nt(i),this.currentValues=d(this.udpForm),this.udpFormSubmission.data.submissionResponseData&&(this.currentValues=Object.assign({},this.udpFormSubmission.data.submissionResponseData),this.udpFormSubmission.status===a.Submitted&&(this.isSubmitted=!0)),(!this.udpFormSubmission.id||this.udpFormSubmission.status===a.Created)&&this.urlContext&&Object.keys(this.urlContext).length>0){this.dynamicSections=((t,s,e)=>{var i,o;const n=(t=>{const s={};return Object.keys(t&&"object"==typeof t?t:{}).forEach((t=>{var e;const i=t.match(/^([^._?&#]+)_(\d+)\./);if(!i)return;const o=i[1],n=Number(i[2]);!Number.isFinite(n)||n<2||n>(null!==(e=s[o])&&void 0!==e?e:1)&&(s[o]=n)})),s})(e),r=[],a=structuredClone(t.udpFormUdpFormSection).sort(((t,s)=>t.order-s.order));for(const e of a){e.sectionProperties=JSON.parse(e.sectionProperties||{});const a=rt(e.name,s),l=a.length>0?Math.max(...a):1,u=null!==(i=null==n?void 0:n[e.name])&&void 0!==i?i:1,c=Math.max(l,u);if(e.isOriginalSection=!0,e.sectionPositionSuffix=1,r.push(Object.assign(Object.assign({},structuredClone(e)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===e.id)).sort(((t,s)=>t.questionOrder-s.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${e.name}.${t.name}`,isShowCommentInput:!0})))})),(null===(o=e.sectionProperties)||void 0===o?void 0:o.isRepeatable)&&c>=2)for(let s=2;s<=c;s++){const i=Object.assign(Object.assign({},structuredClone(e)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===e.id)).sort(((t,s)=>t.questionOrder-s.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${e.name}_${s}.${t.name}`,isShowCommentInput:!0}))),isOriginalSection:!1,sectionPositionSuffix:s});r.push(i)}}return r})(this.udpForm,this.currentValues,this.urlContext);const t=((t,s)=>{if(!Array.isArray(t))return;const e=s&&"object"==typeof s?s:{},i={};Object.keys(e).forEach((t=>{i[(t+"").toLowerCase()]=e[t]}));const o={};t.forEach((t=>{const s=t.isOriginalSection?t.name:`${t.name}_${t.sectionPositionSuffix}`;(t.formQuestions||[]).forEach((t=>{if(!t)return;const e=[t.processedSubmissionName,t.questionIdentifierKey,t.name].filter(Boolean);let n;for(const t of e){const s=(t+"").toLowerCase();if(Object.prototype.hasOwnProperty.call(i,s)){n=i[s];break}}null!=n&&(o[s]||(o[s]={}),o[s][t.name]={value:n,comments:[]})}))}));const n={};return Object.entries(o).forEach((([t,s])=>{n[t]||(n[t]={}),Object.entries(s).forEach((([s,e])=>{const i=n[t][s];(null==i||null==i.value||"string"==typeof i.value&&""===i.value.trim())&&(n[t][s]=e)}))})),t.forEach((t=>{const s=t.isOriginalSection?t.name:`${t.name}_${t.sectionPositionSuffix}`;n[s]||(n[s]={}),(t.formQuestions||[]).forEach((t=>{var e;if(t&&t.fieldTypeId===u.Paragraph){const i=n[s][t.name];if(null==i||null==i.value||"string"==typeof i.value&&""===i.value.trim()){let i=null==t?void 0:t.fieldProperties;if("string"==typeof i)try{i=JSON.parse(i||"{}")}catch(t){i={}}n[s][t.name]={value:null!==(e=null==i?void 0:i.paragraphText)&&void 0!==e?e:"",comments:[]}}}}))})),n})(this.dynamicSections,this.urlContext);t&&(this.currentValues=t,this.udpFormSubmission.data.submissionResponseData=Object.assign({},t))}else this.dynamicSections=((t,s)=>{var e;const i=[],o=structuredClone(t.udpFormUdpFormSection).sort(((t,s)=>t.order-s.order));for(const n of o){n.sectionProperties=JSON.parse(n.sectionProperties||{});const o=rt(n.name,s);if(n.isOriginalSection=!0,n.sectionPositionSuffix=1,i.push(Object.assign(Object.assign({},structuredClone(n)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===n.id)).sort(((t,s)=>t.questionOrder-s.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${n.name}.${t.name}`,isShowCommentInput:!0})))})),(null===(e=n.sectionProperties)||void 0===e?void 0:e.isRepeatable)&&o.length>0){const s=Math.max(...o);for(let e=2;e<=s;e++){const s=Object.assign(Object.assign({},structuredClone(n)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===n.id)).sort(((t,s)=>t.questionOrder-s.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${n.name}_${e}.${t.name}`,isShowCommentInput:!0}))),isOriginalSection:!1,sectionPositionSuffix:e});i.push(s)}}}return i})(this.udpForm,this.currentValues);this.debouncedManualSave=o((async t=>{await this.handleManualSave(t)}),2e3,{leading:!0,trailing:!1})}catch(t){console.error("Error failed to load form in the form renderer:",t)}finally{this.isLoading=!1}}async handleSubmit(t){this.isLoading=!0;try{await this.formSubmissionHandler.finalizeFormSubmissionState(t,this.udpFormSubmission),await this.refreshSubmissionAndSyncState(),this.submitSuccessful=!0}catch(t){throw ut("There was an error submitting this form",this.enqueueSnackbar),t}finally{this.isLoading=!1}}async handleQuestionCommentLiveCRUD(t){var s,e,i,o,n,r;if(!this.isPublic||this.publicFeatures.allowComments)try{const{type:l,questionIdentifierKey:u,commentId:c}=t.detail,d=function(t){var s,e,i,o,n;const{actionType:r,questionIdentifierKey:a,commentId:l,currentSubmissionResponseData:u,clientUserInfo:c}=t,d=(a||"").split("."),m=d[0]||"",h=d[1]||"";if(!m||!h)return{sectionKey:m,questionKey:h,nextSubmissionResponseData:u||{},didMutate:!1,shouldPersist:!1,persistIntent:"none",commentId:l};const p=structuredClone(u||{});p[m]||(p[m]={}),p[m][h]?(p[m][h].comments=null!==(s=p[m][h].comments)&&void 0!==s?s:[],p[m][h].draftComments=null!==(e=p[m][h].draftComments)&&void 0!==e?e:[],p[m][h].metadata=null!==(i=p[m][h].metadata)&&void 0!==i?i:{}):p[m][h]={value:"",comments:[],draftComments:[],metadata:{}};const f=p[m][h].draftComments;f&&!Array.isArray(f)?p[m][h].draftComments=[f]:f||(p[m][h].draftComments=[]);const b=p[m][h].comments||[],v=p[m][h].draftComments||[];let w=!1;switch(r){case"add":{const t={value:"",commentId:y(),isTempComment:!0,timestamp:null};p[m][h].draftComments=[t,...v],w=!0;break}case"save":{const t=v.findIndex((t=>t.commentId===l));if(-1===t)return{sectionKey:m,questionKey:h,nextSubmissionResponseData:p,didMutate:!1,shouldPersist:!1,persistIntent:"none",commentId:l};const s=v[t],e=s.timestamp||(new Date).toISOString(),i=Object.assign(Object.assign({},s),{timestamp:e,editedTimestamp:(new Date).toISOString(),userId:null==c?void 0:c.id,userDisplayName:null==c?void 0:c.displayName,isDraftComment:!1}),o=b.findIndex((t=>t.commentId===l));if(-1!==o){const t=[...b];t[o]=Object.assign({},i),p[m][h].comments=t}else p[m][h].comments=[...b,i];p[m][h].draftComments=v.filter((t=>t.commentId!==l)),w=!0;break}case"edit":{const t=b.find((t=>t.commentId===l));if(!t)return{sectionKey:m,questionKey:h,nextSubmissionResponseData:p,didMutate:!1,shouldPersist:!1,persistIntent:"none",commentId:l};const s=Object.assign(Object.assign({},t),{isDraftComment:!0,timestamp:null});p[m][h].draftComments=[s,...v],p[m][h].comments=b,w=!0;break}case"delete":p[m][h].comments=b.map((t=>t.commentId===l?Object.assign(Object.assign({},t),{isDeleted:!0,value:"",editedTimestamp:(new Date).toISOString()}):t)),w=!0;break;case"editClose":p[m][h].draftComments=v.filter((t=>t.commentId!==l)),w=!0}const j="save"===r||"delete"===r;let S;if("save"===r){const t=((null===(n=null===(o=null==p?void 0:p[m])||void 0===o?void 0:o[h])||void 0===n?void 0:n.comments)||[]).find((t=>t.commentId===l));S=null==t?void 0:t.value}return{sectionKey:m,questionKey:h,nextSubmissionResponseData:p,didMutate:w,shouldPersist:j,persistIntent:"none",commentId:l,valueToPersist:S}}({actionType:l,questionIdentifierKey:u,commentId:c,currentSubmissionResponseData:this.udpFormSubmission.data.submissionResponseData||{},clientUserInfo:this.clientUserInfo}),m=d.nextSubmissionResponseData;if(this.udpFormSubmission.data.submissionResponseData=Object.assign({},m),"edit"!==l&&"editClose"!==l&&"add"!==l||(this.currentValues=Object.assign({},m)),d.shouldPersist){const t=(null===(s=this.udpFormSubmission)||void 0===s?void 0:s.status)===a.Submitted,u=(null===(e=this.udpFormSubmission)||void 0===e?void 0:e.unityUserId)===this.clientUserInfo.id,c=((null===(n=null===(o=null===(i=this.currentValues||{})||void 0===i?void 0:i[d.sectionKey])||void 0===o?void 0:o[d.questionKey])||void 0===n?void 0:n.comments)||[]).find((t=>(null==t?void 0:t.commentId)===d.commentId&&!(null==t?void 0:t.isDeleted)));if(t||!u)if(null===(r=this.udpFormSubmission)||void 0===r?void 0:r.id){if("save"===l){const t=d.valueToPersist;if(t)try{c?await this.formSubmissionHandler.updateComment(this.udpFormSubmission,{sectionKey:d.sectionKey,questionKey:d.questionKey,value:t,commentId:d.commentId}):await this.formSubmissionHandler.addComment(this.udpFormSubmission,{sectionKey:d.sectionKey,questionKey:d.questionKey,value:t,commentId:d.commentId}),await this.refreshSubmissionAndSyncState(),lt(c?"Comment updated.":"Comment added.",this.enqueueSnackbar)}catch(t){throw ut(c?"Failed to update comment.":"Failed to add comment.",this.enqueueSnackbar),t}}else if("delete"===l)try{await this.formSubmissionHandler.deleteComment(this.udpFormSubmission,{sectionKey:d.sectionKey,questionKey:d.questionKey,commentId:d.commentId}),await this.refreshSubmissionAndSyncState(),lt("Comment deleted.",this.enqueueSnackbar)}catch(t){throw ut("Failed to delete comment.",this.enqueueSnackbar),t}}else this.currentValues=Object.assign({},m);else this.isPublic?this.currentValues=Object.assign({},m):await this.handleManualSave(m)}else this.currentValues=Object.assign({},m)}catch(t){console.error("Error handling live comment CRUD:",t)}finally{this.triggerFormRerender()}}async loadFollowUpForms(t,s){var e;this.isLoading=!0;try{const i=(await r(this.followUpSideSheetListPageNumber,this.FOLLOW_UP_SIDE_SHEET_PAGE_SIZE,[{searchField:"type",searchOperator:"=",searchValue:c.FollowUp}],{sortDirection:"DESC",sortColumn:"lastModifiedOn"})).data;if(!i||!Array.isArray(i.pageList))throw Error("Malformed form versions data.");this.sideSheetFollowUpFormsList=this.formatFollowUpFormsList(i.pageList,t,s),this.followUpSideSheetTotalItems=null!==(e=i.total)&&void 0!==e?e:0}catch(t){console.error("Failed to follow up form.",t)}finally{this.isLoading=!1}}formatFollowUpFormsList(t,s,e){return t.map((t=>({listItemData:t,history:this.history,handleLaunchFollowUpForm:async()=>await this.handleLaunchFollowUpForm(t.id,t.version,this.udpFormSubmission.id,this.udpFormSubmission.formId,this.udpFormSubmission.formVersion,s,e)})))}async handleSideSheetPageChange(t){this.followUpSideSheetListPageNumber=t,await this.loadFollowUpForms(this.followUpParentSectionKey,this.followUpParentQuestionKey)}renderFollowUpSideSheet(){return this.isPublic?null:e("udp-side-sheet",{title:"Link a Follow Up Form",open:this.isFollowUpFormsSideSheetOpen,onUdpSideSheetClose:()=>this.handleSideSheetClose(),position:"right",width:"md"},this.isLoading&&this.isFollowUpFormsSideSheetOpen&&e("udp-linear-loader",null),e("udp-list-renderer",{itemComponent:"udp-forms-follow-up-list-card",data:this.sideSheetFollowUpFormsList,pagination:!0,isServerSide:!0,isLoading:this.isLoading,itemsPerPage:this.FOLLOW_UP_SIDE_SHEET_PAGE_SIZE,currentPage:this.followUpSideSheetListPageNumber,totalItems:this.followUpSideSheetTotalItems,onPageChange:t=>this.handleSideSheetPageChange(t.detail),componentDataMap:this.componentMap,spacing:"md"}))}isShowManualSaveIcon(){return!this.isPublic&&(!!this.clientUserInfo.id&&this.hasUnsavedChanges)}get isReadOnlyMode(){return this.isSubmitted||this.udpFormSubmission.unityUserId!==this.clientUserInfo.id}render(){return e("div",{key:"37ec47fc7f3ecec70ba7ca3e12717789285be5d8",class:"forms-renderer-container",style:this.isLoading?{minHeight:"100vh"}:{}},this.renderFollowUpSideSheet(),e("udp-forms-ui",{udpForm:this.udpForm,currentValues:this.currentValues,udpFormSubmission:this.udpFormSubmission,submitSuccessful:this.submitSuccessful,isSaving:this.isSaving,readonly:this.isReadOnlyMode,handleSubmit:this.handleSubmit.bind(this),handleSave:t=>Promise.resolve(this.debouncedManualSave(t)),handleChange:this.handleFormChange,handleAction:this.triggerAction,handleFinish:this.handleFinish,clientUserInfo:this.clientUserInfo,isSubmitted:this.isSubmitted,dynamicSections:this.dynamicSections,duplicateRepeatableSection:this.duplicateRepeatableSection,deleteRepeatableSection:this.deleteRepeatableSection,key:"form-rerender-key-"+this.reRenderKey,isShowManualSaveIcon:this.isShowManualSaveIcon(),isLoading:this.isLoading,performBackgroundSaveAndUpdateLocalSubmissionState:this.performBackgroundSaveAndUpdateLocalSubmissionState}))}get el(){return this}},[1,"udp-forms-renderer",{formId:[1,"form-id"],version:[2],submissionId:[1,"submission-id"],triggerAction:[16],isPublic:[4,"is-public"],callbackUrl:[1,"callback-url"],getUserCallback:[16],enqueueSnackbar:[16],closeSnackbar:[16],autoSaveDelay:[2,"auto-save-delay"],history:[8],urlContext:[16],currentValues:[32],submitSuccessful:[32],isLoading:[32],isSaving:[32],isSubmitted:[32],dynamicSections:[32],isUpdatingSections:[32],reRenderKey:[32],hasUnsavedChanges:[32],sideSheetFollowUpFormsList:[32],followUpSideSheetTotalItems:[32],isFollowUpFormsSideSheetOpen:[32],followUpSideSheetListPageNumber:[32]}]),mt=dt,ht=function(){"undefined"!=typeof customElements&&["udp-forms-renderer","custom-button","file-upload","fluent-dialog","form-metadata-display","image-upload","numeric-field","selectable-list","signature-input","stencil-field","stencil-form","stencil-icon-button","tally-display","text-area","text-field","udp-adornment","udp-ambient-card","udp-ambient-tool-tip","udp-badge","udp-button","udp-container","udp-date-selector","udp-datetime-selector","udp-forms-ui","udp-icon","udp-icon-button","udp-linear-loader","udp-list-renderer","udp-menu-item","udp-pagination","udp-pop-over","udp-question","udp-question-comments","udp-save-draft-button","udp-selector","udp-side-sheet","udp-time-selector","unity-typography"].forEach((t=>{switch(t){case"udp-forms-renderer":customElements.get(i(t))||customElements.define(i(t),dt);break;case"custom-button":customElements.get(i(t))||v();break;case"file-upload":customElements.get(i(t))||w();break;case"fluent-dialog":customElements.get(i(t))||j();break;case"form-metadata-display":customElements.get(i(t))||S();break;case"image-upload":customElements.get(i(t))||O();break;case"numeric-field":customElements.get(i(t))||g();break;case"selectable-list":customElements.get(i(t))||F();break;case"signature-input":customElements.get(i(t))||I();break;case"stencil-field":customElements.get(i(t))||C();break;case"stencil-form":customElements.get(i(t))||E();break;case"stencil-icon-button":customElements.get(i(t))||k();break;case"tally-display":customElements.get(i(t))||D();break;case"text-area":customElements.get(i(t))||$();break;case"text-field":customElements.get(i(t))||U();break;case"udp-adornment":customElements.get(i(t))||x();break;case"udp-ambient-card":customElements.get(i(t))||q();break;case"udp-ambient-tool-tip":customElements.get(i(t))||K();break;case"udp-badge":customElements.get(i(t))||P();break;case"udp-button":customElements.get(i(t))||A();break;case"udp-container":customElements.get(i(t))||L();break;case"udp-date-selector":customElements.get(i(t))||R();break;case"udp-datetime-selector":customElements.get(i(t))||_();break;case"udp-forms-ui":customElements.get(i(t))||M();break;case"udp-icon":customElements.get(i(t))||T();break;case"udp-icon-button":customElements.get(i(t))||V();break;case"udp-linear-loader":customElements.get(i(t))||N();break;case"udp-list-renderer":customElements.get(i(t))||B();break;case"udp-menu-item":customElements.get(i(t))||J();break;case"udp-pagination":customElements.get(i(t))||Q();break;case"udp-pop-over":customElements.get(i(t))||z();break;case"udp-question":customElements.get(i(t))||W();break;case"udp-question-comments":customElements.get(i(t))||G();break;case"udp-save-draft-button":customElements.get(i(t))||H();break;case"udp-selector":customElements.get(i(t))||X();break;case"udp-side-sheet":customElements.get(i(t))||Y();break;case"udp-time-selector":customElements.get(i(t))||Z();break;case"unity-typography":customElements.get(i(t))||tt()}}))};export{mt as UdpFormsRenderer,ht as defineCustomElement}
1
+ import{p as t,H as s,h as e,t as i}from"./index2.js";import{throttle as o}from"lodash";import{g as n}from"./tenantUtils.js";import{f as r}from"./udp-form-api-utils.js";import{c as a,b as l,U as u,a as c}from"./enums.js";import{b as d}from"./utils.js";import{c as m,m as h}from"./makeApiCall.js";import{S as p,c as f}from"./SearchBuilder.js";import{C as b}from"./configService.js";import{v4 as y}from"uuid";import{d as v}from"./custom-button2.js";import{d as w}from"./file-upload2.js";import{d as j}from"./fluent-dialog2.js";import{d as S}from"./form-metadata-display2.js";import{d as O}from"./image-upload2.js";import{d as g}from"./numeric-field2.js";import{d as I}from"./selectable-list2.js";import{d as F}from"./signature-input2.js";import{d as C}from"./stencil-field2.js";import{d as E}from"./stencil-form2.js";import{d as k}from"./stencil-icon-button2.js";import{d as D}from"./tally.js";import{d as $}from"./text-area2.js";import{d as U}from"./text-field2.js";import{d as x}from"./udp-adornment2.js";import{d as q}from"./udp-ambient-card2.js";import{d as P}from"./udp-ambient-tool-tip2.js";import{d as K}from"./udp-badge2.js";import{d as T}from"./udp-button2.js";import{d as A}from"./udp-container2.js";import{d as L}from"./udp-date-selector2.js";import{d as R}from"./udp-datetime-selector2.js";import{d as _}from"./udp-forms-ui2.js";import{d as M}from"./udp-icon2.js";import{d as V}from"./udp-icon-button2.js";import{d as N}from"./udp-linear-loader2.js";import{d as B}from"./udp-list-renderer2.js";import{d as J}from"./udp-menu-item2.js";import{d as Q}from"./udp-pagination2.js";import{d as z}from"./udp-pop-over2.js";import{d as W}from"./udp-question2.js";import{d as H}from"./udp-question-comments2.js";import{d as G}from"./udp-save-draft-button2.js";import{d as X}from"./udp-selector2.js";import{d as Y}from"./udp-side-sheet2.js";import{d as Z}from"./udp-time-selector2.js";import{d as tt}from"./unity-typography2.js";class st{constructor(t={}){this.id=null,this.formId=null,this.formVersion=null,this.data={},this.unityUserId=null,this.clusterId=null,this.userDisplayName="",this.status=null,this.businessObjectKey="",this.udpTags=[],this.form=null,this.initialCreatedOn=null,this.lastModifiedOn=null,this.submittedOn=null,this.generic1=null,this.generic2=null,this.generic3=null,this.userEmail=null,Object.assign(this,t)}processSubmissionIntoFormDataWithoutValues(t){const s=this.buildBaseSubmissionData(t),e=m(s);return e.append("Data",JSON.stringify(this.data)),e}processSubmissionIntoFormData(t,s){const e=this.buildBaseSubmissionData(s),{cleanedData:i,files:o}=this.extractCleanedDataAndFiles(t),n=m(e);return o.forEach((t=>n.append("FormFiles",t))),n.append("Data",JSON.stringify({submissionResponseData:i,submissionMetadata:this.data.submissionMetadata||null})),n}buildBaseSubmissionData(t){const s={FormId:this.formId,FormVersion:""+this.formVersion,Status:t};return this.id&&(s.Id=this.id),s.InitialCreatedOn=this.initialCreatedOn?this.initialCreatedOn:(new Date).toISOString(),s.LastModifiedOn=this.lastModifiedOn?this.lastModifiedOn:(new Date).toISOString(),this.submittedOn&&(s.submittedOn=this.submittedOn),this.generic1&&(s.generic1=""+this.generic1),this.generic2&&(s.generic2=""+this.generic2),this.generic3&&(s.generic3=""+this.generic3),s}extractCleanedDataAndFiles(t){const s=[],e={};for(const i in t){e[i]={};for(const o in t[i]){const n=t[i][o],{value:r,fieldFiles:a}=this.extractValueAndFiles(n);a&&s.push(...a);const l=this.processComments(n.comments),u=this.processMetadata(n.metadata);e[i][o]=Object.assign({value:r,comments:l},u&&{metadata:u})}}return{cleanedData:e,files:s}}extractValueAndFiles(t){var s,e;let i=(null===(s=null==t?void 0:t.value)||void 0===s?void 0:s.files)?t.value.value:null==t?void 0:t.value;const o=null===(e=null==t?void 0:t.value)||void 0===e?void 0:e.files;return o&&Array.isArray(o)?{value:"string"==typeof i&&""!==i.trim()?i:"",fieldFiles:o}:function(t){return!!Array.isArray(t)&&t.every((t=>t instanceof File))}(i)?{value:i.length>0?i.map((t=>t.name)).join(","):"",fieldFiles:i}:i instanceof File?{value:i.name,fieldFiles:[i]}:Array.isArray(i)?{value:i.map((t=>"string"==typeof t?t:null==t?void 0:t.value)).join(",")}:{value:i}}processComments(t){var s;return null!==(s=null==t?void 0:t.map((t=>Object.assign({},t))))&&void 0!==s?s:[]}processMetadata(t){return t&&Object.keys(t).length>0?Object.assign({},t):void 0}}class et{constructor(t,s){this.accessMode=t,this.tenantId=s}get extraHeaders(){if("public"===this.accessMode&&this.tenantId)return{currentTenantId:this.tenantId+""}}async addComment(t,s){if(!(null==t?void 0:t.id))throw Error("Cannot add a comment without a submission ID.");const e=`${b.productV1ApiUrl}/UdpFormSubmission/${t.id}/comments/${this.accessMode}`;await h("POST",e,s,!0)}async updateComment(t,s){if(!(null==t?void 0:t.id))throw Error("Cannot update a comment without a submission ID.");const{sectionKey:e,questionKey:i,commentId:o,value:n}=s,r=`${b.productV1ApiUrl}/UdpFormSubmission/${t.id}/comments/${o}`;await h("PUT",r,{value:n,sectionKey:e,questionKey:i},!0,this.extraHeaders)}async deleteComment(t,s){if(!(null==t?void 0:t.id))throw Error("Cannot delete a comment without a submission ID.");const{commentId:e}=s,i=`${b.productV1ApiUrl}/UdpFormSubmission/${t.id}/comments/${e}`;await h("DELETE",i,null,!0,this.extraHeaders)}async fetchAndPopulateUdpFormSubmissionObj(t){if(!(null==t?void 0:t.id))return console.warn("Cannot fetch form submission without an ID."),t;if("public"===this.accessMode){const s=await this.getFormSubmissionByIdAndUser(t.id,t.unityUserId);return s?new st(Object.assign(Object.assign({},t),s)):t}const{id:s}=t,e=await this.getFormSubmissionById(s);return e?new st(Object.assign(Object.assign({},t),e)):t}async createNewLinkedFollowUpFormSubmission(t){if("public"===this.accessMode)throw Error("Follow-up form submissions are not supported for public forms.");return this.saveFormDataWithoutValues(t,a.InProgress)}async saveCurrentFormSubmissionState(t,s){return"public"===this.accessMode?s:this.saveSubmissionToDB(t,s,a.InProgress)}async finalizeFormSubmissionState(t,s){return this.saveSubmissionToDB(t,s,a.Submitted)}async saveFormDataWithoutValues(t,s){const e=t.processSubmissionIntoFormDataWithoutValues(s),{method:i,url:o}=this.getApiRequestInfo(t),n=await h(i,o,e,!0,this.extraHeaders);return""===n?await this.fetchAndPopulateUdpFormSubmissionObj(t):new st(Object.assign(Object.assign({},t),n))}getApiRequestInfo(t){const s=`${b.productV1ApiUrl}/UdpFormSubmission/${this.accessMode}`;return"public"===this.accessMode?{method:"POST",url:s}:t.id?{method:"PUT",url:s}:{method:"POST",url:s}}async saveSubmissionToDB(t,s,e){const i=s.processSubmissionIntoFormData(t,e),{method:o,url:n}=this.getApiRequestInfo(s),r=await h(o,n,i,!0,this.extraHeaders);if(""===r)return await this.fetchAndPopulateUdpFormSubmissionObj(s);const a=new st(Object.assign(Object.assign({},s),r));return Object.assign(s,a),a}async getFormSubmissionById(t){var s;try{const e=new p(1,1).addFilter("id",t,f.EQUALS),i=await e.execute("UdpFormSubmission");return(null===(s=null==i?void 0:i.pageList)||void 0===s?void 0:s[0])||null}catch(t){return console.error("Error fetching form submission by ID:",t),null}}async getFormSubmissionByIdAndUser(t,s){var e;try{const i=new p(1,1).addFilter("id",t,f.EQUALS).addFilter("unityUserId",s,f.EQUALS),o=await i.execute("UdpFormSubmission");return(null===(e=null==o?void 0:o.pageList)||void 0===e?void 0:e[0])||null}catch(t){return console.error("Error fetching form submission by ID:",t),null}}}class it{static create(t,s,e){return new et(t?"public":"private",null!=e?e:void 0)}}class ot{constructor(t,s=!1){this.tenantId=t,this.isPublic=s}buildDescribeUrl(t,s){const e=b.productV1ApiUrl,i="number"==typeof s?"/"+s:"";return this.isPublic?`${e}/UdpForm/${t}${i}/describe/public`:`${e}/UdpForm/${t}${i}/describe`}async getFormByFormIdAndFormVersion(t,s){const e=this.buildDescribeUrl(t,s),i=this.isPublic&&this.tenantId?{currentTenantId:this.tenantId+""}:void 0,o=await h("GET",e,void 0,!1,i);return o.styleOverrides&&"string"==typeof o.styleOverrides&&(o.styleOverrides=JSON.parse(o.styleOverrides)),o}}class nt{constructor(t){t&&Object.assign(this,t)}}const rt=(t,s)=>{const e=Object.keys(s),i=new Set,o=RegExp(`^${t}_(\\d+)`);return e.forEach((t=>{const s=t.match(o);s&&s[1]&&i.add(Number(s[1]))})),Array.from(i).sort(((t,s)=>t-s))},at=(t,s)=>{const e=`${"undefined"!=typeof window?window.location.pathname:"/page/"+l.FormRendererPageId}?udpf_submissionId=${t}${"undefined"!=typeof window?window.location.hash:""}`,i=s;if(i){if("function"==typeof i.replace)return void i.replace(e);if("function"==typeof i.push)return void i.push(e);if("function"==typeof i){try{i(e,{replace:!0})}catch(t){i(e)}return}}"undefined"!=typeof window&&window.history&&"function"==typeof window.history.replaceState?window.history.replaceState({},"",e):"undefined"!=typeof window&&(window.location.href=e)},lt=(t,s)=>{null==s||s(t,{variant:"success",anchorOrigin:{vertical:"top",horizontal:"center"}})},ut=(t,s)=>{null==s||s(t,{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}})},ct=t=>{if(!t)return{};if("object"==typeof t)return t;if("string"!=typeof t)return{};try{return JSON.parse(t||"{}")}catch(t){return{}}},dt=t(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.isPublic=!1,this.autoSaveDelay=2e3,this.urlContext={},this.currentValues={},this.submitSuccessful=!1,this.isLoading=!1,this.isSaving=!1,this.isSubmitted=!1,this.dynamicSections=[],this.isUpdatingSections=!1,this.reRenderKey=0,this.hasUnsavedChanges=!1,this.sideSheetFollowUpFormsList=[],this.followUpSideSheetTotalItems=0,this.isFollowUpFormsSideSheetOpen=!1,this.followUpSideSheetListPageNumber=1,this.FOLLOW_UP_SIDE_SHEET_PAGE_SIZE=5,this.componentMap={history:"history",listItemData:"listItemData",handleLaunchFollowUpForm:"handleLaunchFollowUpForm"},this.tenantId=n(),this.clientUserInfo={id:null,displayName:null,email:null},this.followUpParentSectionKey="",this.followUpParentQuestionKey="",this.publicFeatures={allowDraftSave:!1,allowComments:!0,allowFollowUpForms:!1},this.handleLaunchFollowUpFormSideSheet=async t=>{try{if(this.isPublic)return;this.followUpParentSectionKey=t.detail.sectionKey,this.followUpParentQuestionKey=t.detail.questionKey,await this.loadFollowUpForms(this.followUpParentSectionKey,this.followUpParentQuestionKey),this.isFollowUpFormsSideSheetOpen=!0}catch(t){console.error("Error loading follow-up forms:",t)}},this.duplicateRepeatableSection=t=>{if(!this.isSubmitted&&!this.isUpdatingSections){this.isUpdatingSections=!0,this.isLoading=!0;try{const{nextDynamicSections:s,nextValues:e}=(t=>{var s,e,i;const{dynamicSections:o,values:n,index:r}=t,a=o[r];if(!a)return{nextDynamicSections:o,nextValues:n};const l=a.name,c=rt(l,n),d=c.length>0?Math.max(...c)+1:2,m=Object.assign(Object.assign({},structuredClone(a)),{formQuestions:(a.formQuestions||[]).map((t=>{const s=structuredClone(t);return s.questionIdentifierKey=`${l}_${d}.${t.name}`,s})),isOriginalSection:!1,sectionPositionSuffix:d});let h=r;for(let t=r+1;t<o.length&&o[t].name===l;t++)h=t;const p=[...o.slice(0,h+1),m,...o.slice(h+1)],f=structuredClone(n||{}),b=`${l}_${d}`,y=(t=>t.isOriginalSection?t.name:`${t.name}_${t.sectionPositionSuffix}`)(a);for(const t of m.formQuestions||[]){f[b]||(f[b]={});let o="";if(t.fieldTypeId===u.Paragraph){const r=null===(e=null===(s=null==n?void 0:n[y])||void 0===s?void 0:s[t.name])||void 0===e?void 0:e.value,a=ct(t.fieldProperties),l=null!==(i=null==a?void 0:a.paragraphText)&&void 0!==i?i:"";o=null!=r?r:l}f[b][t.name]={value:o,comments:[],metadata:{}}}return{nextDynamicSections:p,nextValues:f}})({dynamicSections:this.dynamicSections,values:structuredClone(this.udpFormSubmission.data.submissionResponseData||{}),index:t});this.dynamicSections=s,this.currentValues=Object.assign({},e),this.udpFormSubmission.data.submissionResponseData=Object.assign({},e),this.triggerFormRerender()}finally{this.isUpdatingSections=!1,this.isLoading=!1,this.hasUnsavedChanges=!0}}},this.deleteRepeatableSection=t=>{if(this.isSubmitted)return;const s=this.dynamicSections[t];if(s&&!s.isOriginalSection){this.isUpdatingSections=!0,this.isLoading=!0;try{const{nextDynamicSections:s,nextValues:e}=(t=>{const{dynamicSections:s,values:e,index:i}=t,o=s[i];if(!o||o.isOriginalSection)return{nextDynamicSections:s,nextValues:e};const n=o.name,r=o.sectionPositionSuffix,a=`${n}_${r}`,l=Object.assign({},e||{});delete l[a];const u=structuredClone(s);return u.splice(i,1),u.forEach((t=>{var s;if(t.name!==n||t.isOriginalSection||(null!==(s=t.sectionPositionSuffix)&&void 0!==s?s:0)<=(null!=r?r:0))return;const e=t.sectionPositionSuffix,i=`${n}_${e}`,o=e-1,a=`${n}_${o}`;t.sectionPositionSuffix=o,t.formQuestions=(t.formQuestions||[]).map((t=>{const s=structuredClone(t);return s.questionIdentifierKey=`${a}.${t.name}`,s})),l[i]&&(l[a]=structuredClone(l[i]),delete l[i])})),{nextDynamicSections:u,nextValues:l}})({dynamicSections:this.dynamicSections,values:Object.assign({},this.udpFormSubmission.data.submissionResponseData||{}),index:t});this.dynamicSections=s,this.currentValues=Object.assign({},e),this.udpFormSubmission.data.submissionResponseData=Object.assign({},e),this.triggerFormRerender()}finally{this.isUpdatingSections=!1,this.isLoading=!1,this.hasUnsavedChanges=!0}}},this.performBackgroundSaveAndUpdateLocalSubmissionState=async t=>this.performBackgroundSaveAndUpdateLocalSubmissionStateInternal(t),this.performBackgroundSaveAndUpdateLocalSubmissionStateInternal=async(t,s)=>{var e,i;const o=null!==(e=null==s?void 0:s.allowUrlReplace)&&void 0!==e?e:!this.isPublic,n=null!==(i=null==s?void 0:s.forceCreateDraftIfMissingId)&&void 0!==i&&i;if(!this.isPublic||this.publicFeatures.allowDraftSave||n)try{await this.formSubmissionHandler.saveCurrentFormSubmissionState(t,this.udpFormSubmission),await this.refreshSubmissionAndSyncState(),o&&!new URLSearchParams(window.location.search).has("udpf_submissionId")&&at(this.udpFormSubmission.id,this.history)}catch(t){}finally{this.isSaving=!1,this.hasUnsavedChanges=!1}},this.refreshSubmissionAndSyncState=async()=>{var t,s;if(!(null===(t=this.udpFormSubmission)||void 0===t?void 0:t.id))return;const e=await this.formSubmissionHandler.fetchAndPopulateUdpFormSubmissionObj(this.udpFormSubmission);this.udpFormSubmission=e,this.currentValues=Object.assign({},(null===(s=e.data)||void 0===s?void 0:s.submissionResponseData)||{}),this.isSubmitted=e.status===a.Submitted},this.handleManualSave=async t=>{if(!this.isPublic||this.publicFeatures.allowDraftSave){this.isSaving=!0;try{await this.formSubmissionHandler.saveCurrentFormSubmissionState(t,this.udpFormSubmission),await this.refreshSubmissionAndSyncState(),new URLSearchParams(window.location.search).has("udpf_submissionId")||at(this.udpFormSubmission.id,this.history),lt("Form saved successfully.",this.enqueueSnackbar)}catch(t){ut("There was an error saving this form",this.enqueueSnackbar)}finally{this.isSaving=!1,this.hasUnsavedChanges=!1}}},this.handleFormChange=t=>{this.isUpdatingSections||(this.udpFormSubmission.data.submissionResponseData=t)},this.handleFinish=()=>{this.triggerAction&&this.triggerAction(null,{action:"finish"})},this.triggerFormRerender=()=>{const t=window.scrollY;this.reRenderKey+=1,requestAnimationFrame((()=>{window.scrollTo({top:t,behavior:"auto"})}))},this.handleLaunchFollowUpForm=async(t,s,e,i,o,n,r)=>{const a=await this.formHandler.getFormByFormIdAndFormVersion(t,s),u={submissionResponseData:d(a),submissionMetadata:{ParentSubmission:{submissionId:e,formId:i,formVersion:o}}},c=new st({formId:t,formVersion:s,unityUserId:this.clientUserInfo.id,data:u}),m=it.create(!1,this.clientUserInfo.id),h=await m.createNewLinkedFollowUpFormSubmission(c);this.udpFormSubmission.data.submissionResponseData[n][r].metadata=Object.assign(Object.assign({},this.udpFormSubmission.data.submissionResponseData[n][r].metadata),{followUpFormSubmissionId:h.id}),await this.performBackgroundSaveAndUpdateLocalSubmissionState(this.udpFormSubmission.data.submissionResponseData),window.open(`/page/${l.FormRendererPageId}?udpf_submissionId=${h.id}`,"_blank"),this.handleSideSheetClose(),this.triggerFormRerender()},this.handleSideSheetClose=()=>{this.sideSheetFollowUpFormsList=[],this.followUpSideSheetListPageNumber=1,this.followUpSideSheetTotalItems=0,this.isFollowUpFormsSideSheetOpen=!1,this.followUpParentSectionKey="",this.followUpParentQuestionKey=""}}componentDidLoad(){this.el&&(this.el.addEventListener("questionCommentAction",(async t=>this.handleQuestionCommentLiveCRUD(t))),this.el.addEventListener("launchFollowUpFormSideSheet",(t=>this.handleLaunchFollowUpFormSideSheet(t))),this.el.addEventListener("formDirtyChange",(t=>{this.hasUnsavedChanges=this.hasUnsavedChanges||t.detail})))}async componentWillLoad(){var t;this.isLoading=!0;try{if(this.isPublic){const t=new URLSearchParams(window.location.search).get("udpf_currentTenantId");if(!t)throw Error("Public form renderer requires currentTenantId in the URL query string.");this.tenantId=t}if(this.isPublic)this.clientUserInfo.id="00000000-0000-0000-0000-000000000001",this.clientUserInfo.displayName="Anonymous";else{const s=null===(t=this.getUserCallback)||void 0===t?void 0:t.call(this);s&&(this.clientUserInfo.id=s.id||null,this.clientUserInfo.displayName=s.name||null,this.clientUserInfo.email=s.email||null)}let s,e;this.formSubmissionHandler=it.create(this.isPublic,this.clientUserInfo.id,this.tenantId),this.udpFormSubmission=new st({id:this.submissionId,formId:this.formId,formVersion:this.version,unityUserId:this.clientUserInfo.id,generic1:this.urlContext.generic1,generic2:this.urlContext.generic2,generic3:this.urlContext.generic3}),this.submissionId&&(this.udpFormSubmission=await this.formSubmissionHandler.fetchAndPopulateUdpFormSubmissionObj(this.udpFormSubmission)),this.submissionId?(s=this.udpFormSubmission.formId,e=this.udpFormSubmission.formVersion):this.formId&&this.version&&(s=this.formId,e=this.version),this.formHandler=new ot(this.tenantId,this.isPublic);const i=await this.formHandler.getFormByFormIdAndFormVersion(s,e);if(this.udpForm=new nt(i),this.currentValues=d(this.udpForm),this.udpFormSubmission.data.submissionResponseData&&(this.currentValues=Object.assign({},this.udpFormSubmission.data.submissionResponseData),this.udpFormSubmission.status===a.Submitted&&(this.isSubmitted=!0)),(!this.udpFormSubmission.id||this.udpFormSubmission.status===a.Created)&&this.urlContext&&Object.keys(this.urlContext).length>0){this.dynamicSections=((t,s,e)=>{var i,o;const n=(t=>{const s={};return Object.keys(t&&"object"==typeof t?t:{}).forEach((t=>{var e;const i=t.match(/^([^._?&#]+)_(\d+)\./);if(!i)return;const o=i[1],n=Number(i[2]);!Number.isFinite(n)||n<2||n>(null!==(e=s[o])&&void 0!==e?e:1)&&(s[o]=n)})),s})(e),r=[],a=structuredClone(t.udpFormUdpFormSection).sort(((t,s)=>t.order-s.order));for(const e of a){e.sectionProperties=JSON.parse(e.sectionProperties||{});const a=rt(e.name,s),l=a.length>0?Math.max(...a):1,u=null!==(i=null==n?void 0:n[e.name])&&void 0!==i?i:1,c=Math.max(l,u);if(e.isOriginalSection=!0,e.sectionPositionSuffix=1,r.push(Object.assign(Object.assign({},structuredClone(e)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===e.id)).sort(((t,s)=>t.questionOrder-s.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${e.name}.${t.name}`,isShowCommentInput:!0})))})),(null===(o=e.sectionProperties)||void 0===o?void 0:o.isRepeatable)&&c>=2)for(let s=2;s<=c;s++){const i=Object.assign(Object.assign({},structuredClone(e)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===e.id)).sort(((t,s)=>t.questionOrder-s.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${e.name}_${s}.${t.name}`,isShowCommentInput:!0}))),isOriginalSection:!1,sectionPositionSuffix:s});r.push(i)}}return r})(this.udpForm,this.currentValues,this.urlContext);const t=((t,s)=>{if(!Array.isArray(t))return;const e=s&&"object"==typeof s?s:{},i={};Object.keys(e).forEach((t=>{i[(t+"").toLowerCase()]=e[t]}));const o={};t.forEach((t=>{const s=t.isOriginalSection?t.name:`${t.name}_${t.sectionPositionSuffix}`;(t.formQuestions||[]).forEach((t=>{if(!t)return;const e=[t.processedSubmissionName,t.questionIdentifierKey,t.name].filter(Boolean);let n;for(const t of e){const s=(t+"").toLowerCase();if(Object.prototype.hasOwnProperty.call(i,s)){n=i[s];break}}null!=n&&(o[s]||(o[s]={}),o[s][t.name]={value:n,comments:[]})}))}));const n={};return Object.entries(o).forEach((([t,s])=>{n[t]||(n[t]={}),Object.entries(s).forEach((([s,e])=>{const i=n[t][s];(null==i||null==i.value||"string"==typeof i.value&&""===i.value.trim())&&(n[t][s]=e)}))})),t.forEach((t=>{const s=t.isOriginalSection?t.name:`${t.name}_${t.sectionPositionSuffix}`;n[s]||(n[s]={}),(t.formQuestions||[]).forEach((t=>{var e;if(t&&t.fieldTypeId===u.Paragraph){const i=n[s][t.name];if(null==i||null==i.value||"string"==typeof i.value&&""===i.value.trim()){let i=null==t?void 0:t.fieldProperties;if("string"==typeof i)try{i=JSON.parse(i||"{}")}catch(t){i={}}n[s][t.name]={value:null!==(e=null==i?void 0:i.paragraphText)&&void 0!==e?e:"",comments:[]}}}}))})),n})(this.dynamicSections,this.urlContext);t&&(this.currentValues=t,this.udpFormSubmission.data.submissionResponseData=Object.assign({},t))}else this.dynamicSections=((t,s)=>{var e;const i=[],o=structuredClone(t.udpFormUdpFormSection).sort(((t,s)=>t.order-s.order));for(const n of o){n.sectionProperties=JSON.parse(n.sectionProperties||{});const o=rt(n.name,s);if(n.isOriginalSection=!0,n.sectionPositionSuffix=1,i.push(Object.assign(Object.assign({},structuredClone(n)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===n.id)).sort(((t,s)=>t.questionOrder-s.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${n.name}.${t.name}`,isShowCommentInput:!0})))})),(null===(e=n.sectionProperties)||void 0===e?void 0:e.isRepeatable)&&o.length>0){const s=Math.max(...o);for(let e=2;e<=s;e++){const s=Object.assign(Object.assign({},structuredClone(n)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===n.id)).sort(((t,s)=>t.questionOrder-s.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${n.name}_${e}.${t.name}`,isShowCommentInput:!0}))),isOriginalSection:!1,sectionPositionSuffix:e});i.push(s)}}}return i})(this.udpForm,this.currentValues);this.debouncedManualSave=o((async t=>{await this.handleManualSave(t)}),2e3,{leading:!0,trailing:!1})}catch(t){console.error("Error failed to load form in the form renderer:",t)}finally{this.isLoading=!1}}async handleSubmit(t){this.isLoading=!0;try{await this.formSubmissionHandler.finalizeFormSubmissionState(t,this.udpFormSubmission),await this.refreshSubmissionAndSyncState(),this.submitSuccessful=!0}catch(t){throw ut("There was an error submitting this form",this.enqueueSnackbar),t}finally{this.isLoading=!1}}async handleQuestionCommentLiveCRUD(t){var s,e,i,o,n,r;if(!this.isPublic||this.publicFeatures.allowComments)try{const{type:l,questionIdentifierKey:u,commentId:c}=t.detail,d=function(t){var s,e,i,o,n;const{actionType:r,questionIdentifierKey:a,commentId:l,currentSubmissionResponseData:u,clientUserInfo:c}=t,d=(a||"").split("."),m=d[0]||"",h=d[1]||"";if(!m||!h)return{sectionKey:m,questionKey:h,nextSubmissionResponseData:u||{},didMutate:!1,shouldPersist:!1,persistIntent:"none",commentId:l};const p=structuredClone(u||{});p[m]||(p[m]={}),p[m][h]?(p[m][h].comments=null!==(s=p[m][h].comments)&&void 0!==s?s:[],p[m][h].draftComments=null!==(e=p[m][h].draftComments)&&void 0!==e?e:[],p[m][h].metadata=null!==(i=p[m][h].metadata)&&void 0!==i?i:{}):p[m][h]={value:"",comments:[],draftComments:[],metadata:{}};const f=p[m][h].draftComments;f&&!Array.isArray(f)?p[m][h].draftComments=[f]:f||(p[m][h].draftComments=[]);const b=p[m][h].comments||[],v=p[m][h].draftComments||[];let w=!1;switch(r){case"add":{const t={value:"",commentId:y(),isTempComment:!0,timestamp:null};p[m][h].draftComments=[t,...v],w=!0;break}case"save":{const t=v.findIndex((t=>t.commentId===l));if(-1===t)return{sectionKey:m,questionKey:h,nextSubmissionResponseData:p,didMutate:!1,shouldPersist:!1,persistIntent:"none",commentId:l};const s=v[t],e=s.timestamp||(new Date).toISOString(),i=Object.assign(Object.assign({},s),{timestamp:e,editedTimestamp:(new Date).toISOString(),userId:null==c?void 0:c.id,userDisplayName:null==c?void 0:c.displayName,isDraftComment:!1}),o=b.findIndex((t=>t.commentId===l));if(-1!==o){const t=[...b];t[o]=Object.assign({},i),p[m][h].comments=t}else p[m][h].comments=[...b,i];p[m][h].draftComments=v.filter((t=>t.commentId!==l)),w=!0;break}case"edit":{const t=b.find((t=>t.commentId===l));if(!t)return{sectionKey:m,questionKey:h,nextSubmissionResponseData:p,didMutate:!1,shouldPersist:!1,persistIntent:"none",commentId:l};const s=Object.assign(Object.assign({},t),{isDraftComment:!0,timestamp:null});p[m][h].draftComments=[s,...v],p[m][h].comments=b,w=!0;break}case"delete":p[m][h].comments=b.map((t=>t.commentId===l?Object.assign(Object.assign({},t),{isDeleted:!0,value:"",editedTimestamp:(new Date).toISOString()}):t)),w=!0;break;case"editClose":p[m][h].draftComments=v.filter((t=>t.commentId!==l)),w=!0}const j="save"===r||"delete"===r;let S;if("save"===r){const t=((null===(n=null===(o=null==p?void 0:p[m])||void 0===o?void 0:o[h])||void 0===n?void 0:n.comments)||[]).find((t=>t.commentId===l));S=null==t?void 0:t.value}return{sectionKey:m,questionKey:h,nextSubmissionResponseData:p,didMutate:w,shouldPersist:j,persistIntent:"none",commentId:l,valueToPersist:S}}({actionType:l,questionIdentifierKey:u,commentId:c,currentSubmissionResponseData:this.udpFormSubmission.data.submissionResponseData||{},clientUserInfo:this.clientUserInfo}),m=d.nextSubmissionResponseData;if(this.udpFormSubmission.data.submissionResponseData=Object.assign({},m),"edit"!==l&&"editClose"!==l&&"add"!==l||(this.currentValues=Object.assign({},m)),d.shouldPersist){const t=(null===(s=this.udpFormSubmission)||void 0===s?void 0:s.status)===a.Submitted,u=(null===(e=this.udpFormSubmission)||void 0===e?void 0:e.unityUserId)===this.clientUserInfo.id,c=((null===(n=null===(o=null===(i=this.currentValues||{})||void 0===i?void 0:i[d.sectionKey])||void 0===o?void 0:o[d.questionKey])||void 0===n?void 0:n.comments)||[]).find((t=>(null==t?void 0:t.commentId)===d.commentId&&!(null==t?void 0:t.isDeleted)));if(t||!u)if(null===(r=this.udpFormSubmission)||void 0===r?void 0:r.id){if("save"===l){const t=d.valueToPersist;if(t)try{c?await this.formSubmissionHandler.updateComment(this.udpFormSubmission,{sectionKey:d.sectionKey,questionKey:d.questionKey,value:t,commentId:d.commentId}):await this.formSubmissionHandler.addComment(this.udpFormSubmission,{sectionKey:d.sectionKey,questionKey:d.questionKey,value:t,commentId:d.commentId}),await this.refreshSubmissionAndSyncState(),lt(c?"Comment updated.":"Comment added.",this.enqueueSnackbar)}catch(t){throw ut(c?"Failed to update comment.":"Failed to add comment.",this.enqueueSnackbar),t}}else if("delete"===l)try{await this.formSubmissionHandler.deleteComment(this.udpFormSubmission,{sectionKey:d.sectionKey,questionKey:d.questionKey,commentId:d.commentId}),await this.refreshSubmissionAndSyncState(),lt("Comment deleted.",this.enqueueSnackbar)}catch(t){throw ut("Failed to delete comment.",this.enqueueSnackbar),t}}else this.currentValues=Object.assign({},m);else this.isPublic?this.currentValues=Object.assign({},m):await this.handleManualSave(m)}else this.currentValues=Object.assign({},m)}catch(t){console.error("Error handling live comment CRUD:",t)}finally{this.triggerFormRerender()}}async loadFollowUpForms(t,s){var e;this.isLoading=!0;try{const i=(await r(this.followUpSideSheetListPageNumber,this.FOLLOW_UP_SIDE_SHEET_PAGE_SIZE,[{searchField:"type",searchOperator:"=",searchValue:c.FollowUp}],{sortDirection:"DESC",sortColumn:"lastModifiedOn"})).data;if(!i||!Array.isArray(i.pageList))throw Error("Malformed form versions data.");this.sideSheetFollowUpFormsList=this.formatFollowUpFormsList(i.pageList,t,s),this.followUpSideSheetTotalItems=null!==(e=i.total)&&void 0!==e?e:0}catch(t){console.error("Failed to follow up form.",t)}finally{this.isLoading=!1}}formatFollowUpFormsList(t,s,e){return t.map((t=>({listItemData:t,history:this.history,handleLaunchFollowUpForm:async()=>await this.handleLaunchFollowUpForm(t.id,t.version,this.udpFormSubmission.id,this.udpFormSubmission.formId,this.udpFormSubmission.formVersion,s,e)})))}async handleSideSheetPageChange(t){this.followUpSideSheetListPageNumber=t,await this.loadFollowUpForms(this.followUpParentSectionKey,this.followUpParentQuestionKey)}renderFollowUpSideSheet(){return this.isPublic?null:e("udp-side-sheet",{title:"Link a Follow Up Form",open:this.isFollowUpFormsSideSheetOpen,onUdpSideSheetClose:()=>this.handleSideSheetClose(),position:"right",width:"md"},this.isLoading&&this.isFollowUpFormsSideSheetOpen&&e("udp-linear-loader",null),e("udp-list-renderer",{itemComponent:"udp-forms-follow-up-list-card",data:this.sideSheetFollowUpFormsList,pagination:!0,isServerSide:!0,isLoading:this.isLoading,itemsPerPage:this.FOLLOW_UP_SIDE_SHEET_PAGE_SIZE,currentPage:this.followUpSideSheetListPageNumber,totalItems:this.followUpSideSheetTotalItems,onPageChange:t=>this.handleSideSheetPageChange(t.detail),componentDataMap:this.componentMap,spacing:"md"}))}isShowManualSaveIcon(){return!this.isPublic&&(!!this.clientUserInfo.id&&this.hasUnsavedChanges)}get isReadOnlyMode(){return this.isSubmitted||this.udpFormSubmission.unityUserId!==this.clientUserInfo.id}render(){return e("div",{key:"f53b65027554505a1301ab98379035e0316735dc",class:"forms-renderer-container",style:this.isLoading?{minHeight:"100vh"}:{}},this.renderFollowUpSideSheet(),e("udp-forms-ui",{udpForm:this.udpForm,currentValues:this.currentValues,udpFormSubmission:this.udpFormSubmission,submitSuccessful:this.submitSuccessful,isSaving:this.isSaving,readonly:this.isReadOnlyMode,handleSubmit:this.handleSubmit.bind(this),handleSave:t=>Promise.resolve(this.debouncedManualSave(t)),handleChange:this.handleFormChange,handleAction:this.triggerAction,handleFinish:this.handleFinish,clientUserInfo:this.clientUserInfo,isSubmitted:this.isSubmitted,dynamicSections:this.dynamicSections,duplicateRepeatableSection:this.duplicateRepeatableSection,deleteRepeatableSection:this.deleteRepeatableSection,key:"form-rerender-key-"+this.reRenderKey,isShowManualSaveIcon:this.isShowManualSaveIcon(),isLoading:this.isLoading,performBackgroundSaveAndUpdateLocalSubmissionState:this.performBackgroundSaveAndUpdateLocalSubmissionState}))}get el(){return this}},[1,"udp-forms-renderer",{formId:[1,"form-id"],version:[2],urlTenantId:[1,"url-tenant-id"],submissionId:[1,"submission-id"],triggerAction:[16],isPublic:[4,"is-public"],callbackUrl:[1,"callback-url"],getUserCallback:[16],enqueueSnackbar:[16],closeSnackbar:[16],autoSaveDelay:[2,"auto-save-delay"],history:[8],urlContext:[16],currentValues:[32],submitSuccessful:[32],isLoading:[32],isSaving:[32],isSubmitted:[32],dynamicSections:[32],isUpdatingSections:[32],reRenderKey:[32],hasUnsavedChanges:[32],sideSheetFollowUpFormsList:[32],followUpSideSheetTotalItems:[32],isFollowUpFormsSideSheetOpen:[32],followUpSideSheetListPageNumber:[32]}]),mt=dt,ht=function(){"undefined"!=typeof customElements&&["udp-forms-renderer","custom-button","file-upload","fluent-dialog","form-metadata-display","image-upload","numeric-field","selectable-list","signature-input","stencil-field","stencil-form","stencil-icon-button","tally-display","text-area","text-field","udp-adornment","udp-ambient-card","udp-ambient-tool-tip","udp-badge","udp-button","udp-container","udp-date-selector","udp-datetime-selector","udp-forms-ui","udp-icon","udp-icon-button","udp-linear-loader","udp-list-renderer","udp-menu-item","udp-pagination","udp-pop-over","udp-question","udp-question-comments","udp-save-draft-button","udp-selector","udp-side-sheet","udp-time-selector","unity-typography"].forEach((t=>{switch(t){case"udp-forms-renderer":customElements.get(i(t))||customElements.define(i(t),dt);break;case"custom-button":customElements.get(i(t))||v();break;case"file-upload":customElements.get(i(t))||w();break;case"fluent-dialog":customElements.get(i(t))||j();break;case"form-metadata-display":customElements.get(i(t))||S();break;case"image-upload":customElements.get(i(t))||O();break;case"numeric-field":customElements.get(i(t))||g();break;case"selectable-list":customElements.get(i(t))||I();break;case"signature-input":customElements.get(i(t))||F();break;case"stencil-field":customElements.get(i(t))||C();break;case"stencil-form":customElements.get(i(t))||E();break;case"stencil-icon-button":customElements.get(i(t))||k();break;case"tally-display":customElements.get(i(t))||D();break;case"text-area":customElements.get(i(t))||$();break;case"text-field":customElements.get(i(t))||U();break;case"udp-adornment":customElements.get(i(t))||x();break;case"udp-ambient-card":customElements.get(i(t))||q();break;case"udp-ambient-tool-tip":customElements.get(i(t))||P();break;case"udp-badge":customElements.get(i(t))||K();break;case"udp-button":customElements.get(i(t))||T();break;case"udp-container":customElements.get(i(t))||A();break;case"udp-date-selector":customElements.get(i(t))||L();break;case"udp-datetime-selector":customElements.get(i(t))||R();break;case"udp-forms-ui":customElements.get(i(t))||_();break;case"udp-icon":customElements.get(i(t))||M();break;case"udp-icon-button":customElements.get(i(t))||V();break;case"udp-linear-loader":customElements.get(i(t))||N();break;case"udp-list-renderer":customElements.get(i(t))||B();break;case"udp-menu-item":customElements.get(i(t))||J();break;case"udp-pagination":customElements.get(i(t))||Q();break;case"udp-pop-over":customElements.get(i(t))||z();break;case"udp-question":customElements.get(i(t))||W();break;case"udp-question-comments":customElements.get(i(t))||H();break;case"udp-save-draft-button":customElements.get(i(t))||G();break;case"udp-selector":customElements.get(i(t))||X();break;case"udp-side-sheet":customElements.get(i(t))||Y();break;case"udp-time-selector":customElements.get(i(t))||Z();break;case"unity-typography":customElements.get(i(t))||tt()}}))};export{mt as UdpFormsRenderer,ht as defineCustomElement}
package/dist/docs.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "timestamp": "2026-01-30T20:07:09",
2
+ "timestamp": "2026-02-03T17:14:55",
3
3
  "compiler": {
4
4
  "name": "@stencil/core",
5
5
  "version": "4.41.3",
@@ -34542,10 +34542,10 @@
34542
34542
  "docsTags": [
34543
34543
  {
34544
34544
  "name": "default",
34545
- "text": "true"
34545
+ "text": "false"
34546
34546
  }
34547
34547
  ],
34548
- "default": "true",
34548
+ "default": "false",
34549
34549
  "values": [
34550
34550
  {
34551
34551
  "type": "boolean"
@@ -36306,6 +36306,36 @@
36306
36306
  "getter": false,
36307
36307
  "setter": false
36308
36308
  },
36309
+ {
36310
+ "name": "urlTenantId",
36311
+ "type": "string",
36312
+ "complexType": {
36313
+ "original": "Guid | null",
36314
+ "resolved": "string",
36315
+ "references": {
36316
+ "Guid": {
36317
+ "location": "import",
36318
+ "path": "src/global/types",
36319
+ "id": "src/global/types.ts::Guid",
36320
+ "referenceLocation": "Guid"
36321
+ }
36322
+ }
36323
+ },
36324
+ "mutable": false,
36325
+ "attr": "url-tenant-id",
36326
+ "reflectToAttr": false,
36327
+ "docs": "",
36328
+ "docsTags": [],
36329
+ "values": [
36330
+ {
36331
+ "type": "string"
36332
+ }
36333
+ ],
36334
+ "optional": true,
36335
+ "required": false,
36336
+ "getter": false,
36337
+ "setter": false
36338
+ },
36309
36339
  {
36310
36340
  "name": "version",
36311
36341
  "type": "number",
@@ -1,4 +1,4 @@
1
- import { m as makeApiCall } from './makeApiCall-B-daVutk.js';
1
+ import { m as makeApiCall } from './makeApiCall-2umiVB6u.js';
2
2
  import { C as ConfigService } from './configService-BqLfkVKh.js';
3
3
 
4
4
  var LogicalSearchOperator;
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, c as createEvent, f as forceUpdate, h, a as getElement } from './index-DFnjA9NX.js';
2
2
  import { u as useTreeDatasource } from './conversionFunctions-CNWYTvRs.js';
3
- import { s as state } from './catalog-store-BhgNAUY6.js';
3
+ import { s as state } from './catalog-store-CbwcwIKF.js';
4
4
  import Close24 from '@carbon/icons/es/close/24';
5
5
  import { v4 } from 'uuid';
6
6
  import Save16 from '@carbon/icons/es/save/16';
@@ -13,9 +13,9 @@ import AdvancedQuery16 from '@carbon/icons/es/ibm-watson--discovery/16';
13
13
  import DataEnrichment16 from '@carbon/icons/es/idea/16';
14
14
  import Renew16 from '@carbon/icons/es/renew/16';
15
15
  import '@stencil/store';
16
- import './apiUtils-cUHs50y0.js';
16
+ import './apiUtils-11-yfzUs.js';
17
17
  import 'deep-equal';
18
- import './makeApiCall-B-daVutk.js';
18
+ import './makeApiCall-2umiVB6u.js';
19
19
  import 'axios';
20
20
  import './configService-BqLfkVKh.js';
21
21
  import './tenantUtils-Basdb1b1.js';
@@ -1,7 +1,7 @@
1
1
  import { h, r as registerInstance, c as createEvent, a as getElement, H as Host } from './index-DFnjA9NX.js';
2
2
  import { ModuleRegistry, themeQuartz, createGrid } from 'ag-grid-community-v33';
3
3
  import { AllEnterpriseModule, LicenseManager } from 'ag-grid-enterprise-v33';
4
- import { x as getGridViewsWithConfigurations, i as deleteSelectedView, s as saveView, u as updateView, p as getAvailableGridActions, y as getGridConfigurationsByGridId, w as getPromotedMethodEntities, o as executeQueryAdHoc } from './apiUtils-cUHs50y0.js';
4
+ import { x as getGridViewsWithConfigurations, i as deleteSelectedView, s as saveView, u as updateView, p as getAvailableGridActions, y as getGridConfigurationsByGridId, w as getPromotedMethodEntities, o as executeQueryAdHoc } from './apiUtils-11-yfzUs.js';
5
5
  import { g as getIconFromName } from './iconUtils-DcPvHO4A.js';
6
6
  import { g as getCurrentApiCatalogId } from './getCurrentApiCatalogId-DeurXd9l.js';
7
7
  import { C as ConfigService } from './configService-BqLfkVKh.js';
@@ -10,7 +10,7 @@ import { S as StatusRenderer, I as IconRenderer, D as DateTimeCellRenderer, C as
10
10
  import { c as configureUdpColumnMods } from './configureUdpColumnMods-CoCTzhve.js';
11
11
  import isEqual from 'lodash/isEqual';
12
12
  import 'deep-equal';
13
- import './makeApiCall-B-daVutk.js';
13
+ import './makeApiCall-2umiVB6u.js';
14
14
  import 'axios';
15
15
  import '@stencil/store';
16
16
  import './iconMapping-CPerGeNF.js';
@@ -1,10 +1,10 @@
1
1
  import { r as registerInstance, c as createEvent, h, a as getElement } from './index-DFnjA9NX.js';
2
2
  import { produce } from 'immer';
3
- import { s as state } from './catalog-store-BhgNAUY6.js';
3
+ import { s as state } from './catalog-store-CbwcwIKF.js';
4
4
  import ChooseItem16 from '@carbon/icons/es/choose-item/16';
5
5
  import Star16 from '@carbon/icons/es/star/16';
6
6
  import List16 from '@carbon/icons/es/list/16';
7
- import { g as getCleanData, a as getApiCatalogAndProduct, b as getApiMethodInstance, c as getApiMethod, d as getPromotedLookupMethod, e as getApiCatalogById, u as updateView, f as getAvailableViews, h as getSelectedView, i as deleteSelectedView, j as getAllHotlists, k as addRecordToAHotlist, l as deleteAHotlist, m as loadAHotlist, n as createAHotlist, o as executeQueryAdHoc, p as getAvailableGridActions, q as executeQueryWithParameters, s as saveView, r as updateViewAndConfigurations, t as removeRecordFromHotlist, v as executeQueryAdHocAndMapLookups } from './apiUtils-cUHs50y0.js';
7
+ import { g as getCleanData, a as getApiCatalogAndProduct, b as getApiMethodInstance, c as getApiMethod, d as getPromotedLookupMethod, e as getApiCatalogById, u as updateView, f as getAvailableViews, h as getSelectedView, i as deleteSelectedView, j as getAllHotlists, k as addRecordToAHotlist, l as deleteAHotlist, m as loadAHotlist, n as createAHotlist, o as executeQueryAdHoc, p as getAvailableGridActions, q as executeQueryWithParameters, s as saveView, r as updateViewAndConfigurations, t as removeRecordFromHotlist, v as executeQueryAdHocAndMapLookups } from './apiUtils-11-yfzUs.js';
8
8
  import { t as transformSearchData, c as convertToAgGridColumns } from './transformSearchData-DBjFnXu6.js';
9
9
  import { u as useTreeDatasource, U as UdpGridColumnDefs } from './conversionFunctions-CNWYTvRs.js';
10
10
  import * as localforage from 'localforage';
@@ -16,7 +16,7 @@ import { v4 } from 'uuid';
16
16
  import { g as getCurrentTenantId } from './tenantUtils-Basdb1b1.js';
17
17
  import '@stencil/store';
18
18
  import 'deep-equal';
19
- import './makeApiCall-B-daVutk.js';
19
+ import './makeApiCall-2umiVB6u.js';
20
20
  import 'axios';
21
21
  import './configService-BqLfkVKh.js';
22
22
  import './iconUtils-DcPvHO4A.js';
@@ -1,5 +1,5 @@
1
1
  import { r as registerInstance, h } from './index-DFnjA9NX.js';
2
- import { m as makeApiCall } from './makeApiCall-B-daVutk.js';
2
+ import { m as makeApiCall } from './makeApiCall-2umiVB6u.js';
3
3
  import isEqual from 'lodash/isEqual';
4
4
  import { c as configureUdpColumnMods } from './configureUdpColumnMods-CoCTzhve.js';
5
5
  import { C as ConfigService } from './configService-BqLfkVKh.js';
@@ -1,5 +1,5 @@
1
1
  import deepEqual from 'deep-equal';
2
- import { m as makeApiCall } from './makeApiCall-B-daVutk.js';
2
+ import { m as makeApiCall } from './makeApiCall-2umiVB6u.js';
3
3
  import { C as ConfigService } from './configService-BqLfkVKh.js';
4
4
  import { createStore } from '@stencil/store';
5
5
  import { g as getCurrentTenantId } from './tenantUtils-Basdb1b1.js';
@@ -1,5 +1,5 @@
1
1
  import { createStore } from '@stencil/store';
2
- import { e as getApiCatalogById } from './apiUtils-cUHs50y0.js';
2
+ import { e as getApiCatalogById } from './apiUtils-11-yfzUs.js';
3
3
 
4
4
  // src/global/state.ts
5
5
  const { state, onChange } = createStore({
@@ -1,7 +1,7 @@
1
1
  import { r as registerInstance, c as createEvent, h } from './index-DFnjA9NX.js';
2
- import { w as getPromotedMethodEntities } from './apiUtils-cUHs50y0.js';
2
+ import { w as getPromotedMethodEntities } from './apiUtils-11-yfzUs.js';
3
3
  import 'deep-equal';
4
- import './makeApiCall-B-daVutk.js';
4
+ import './makeApiCall-2umiVB6u.js';
5
5
  import 'axios';
6
6
  import './configService-BqLfkVKh.js';
7
7
  import '@stencil/store';
package/dist/esm/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import axios from 'axios';
2
2
  export { c as convertToAgGridColumns, a as createStructuredQuery, d as defaultPayload, b as demoMSSearchData, t as transformSearchData } from './transformSearchData-DBjFnXu6.js';
3
- export { l as loadCatalogData, o as onChange, s as state } from './catalog-store-BhgNAUY6.js';
4
- export { L as LogicalSearchOperator, S as SearchBuilder, b as SearchGroupingType, a as SearchUtilities, c as SqlFilterOperators } from './SearchBuilder-CvKqGlUH.js';
3
+ export { l as loadCatalogData, o as onChange, s as state } from './catalog-store-CbwcwIKF.js';
4
+ export { L as LogicalSearchOperator, S as SearchBuilder, b as SearchGroupingType, a as SearchUtilities, c as SqlFilterOperators } from './SearchBuilder-BjVdKjci.js';
5
5
  export { C as ConfigService } from './configService-BqLfkVKh.js';
6
6
  import '@stencil/store';
7
- import './apiUtils-cUHs50y0.js';
7
+ import './apiUtils-11-yfzUs.js';
8
8
  import 'deep-equal';
9
- import './makeApiCall-B-daVutk.js';
9
+ import './makeApiCall-2umiVB6u.js';
10
10
  import './tenantUtils-Basdb1b1.js';
11
11
 
12
12
  // export const getAccessToken = async () => {