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

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{r as t,h as i,a as s}from"./index-DFnjA9NX.js";import{throttle as e}from"lodash";import{g as n}from"./tenantUtils-Basdb1b1.js";import{f as o}from"./udp-form-api-utils-vPSYCvIA.js";import{b as r,U as a,c as l,a as h}from"./enums-D5dod6Ie.js";import{b as c}from"./utils-kwLwITIE.js";import{c as u,m as d}from"./makeApiCall-B-daVutk.js";import{S as m,c as f}from"./SearchBuilder-CvKqGlUH.js";import{C as v}from"./configService-BqLfkVKh.js";import{v4 as b}from"uuid";import"axios";class p{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 i=this.buildBaseSubmissionData(t),s=u(i);return s.append("Data",JSON.stringify(this.data)),s}processSubmissionIntoFormData(t,i){const s=this.buildBaseSubmissionData(i),{cleanedData:e,files:n}=this.extractCleanedDataAndFiles(t),o=u(s);return n.forEach((t=>o.append("FormFiles",t))),o.append("Data",JSON.stringify({submissionResponseData:e,submissionMetadata:this.data.submissionMetadata||null})),o}buildBaseSubmissionData(t){const i={FormId:this.formId,FormVersion:this.formVersion.toString(),Status:t};return this.id&&(i.Id=this.id),i.InitialCreatedOn=this.initialCreatedOn?this.initialCreatedOn:(new Date).toISOString(),i.LastModifiedOn=this.lastModifiedOn?this.lastModifiedOn:(new Date).toISOString(),this.submittedOn&&(i.submittedOn=this.submittedOn),this.generic1&&(i.generic1=this.generic1.toString()),this.generic2&&(i.generic2=this.generic2.toString()),this.generic3&&(i.generic3=this.generic3.toString()),i}extractCleanedDataAndFiles(t){const i=[],s={};for(const e in t){s[e]={};for(const n in t[e]){const o=t[e][n],{value:r,fieldFiles:a}=this.extractValueAndFiles(o);a&&i.push(...a);const l=this.processComments(o.comments),h=this.processMetadata(o.metadata);s[e][n]=Object.assign({value:r,comments:l},h&&{metadata:h})}}return{cleanedData:s,files:i}}extractValueAndFiles(t){var i,s;let e=(null===(i=null==t?void 0:t.value)||void 0===i?void 0:i.files)?t.value.value:null==t?void 0:t.value;const n=null===(s=null==t?void 0:t.value)||void 0===s?void 0:s.files;return n&&Array.isArray(n)?{value:"string"==typeof e&&""!==e.trim()?e:"",fieldFiles:n}:(o=e,Array.isArray(o)&&o.every((t=>t instanceof File))?{value:e.length>0?e.map((t=>t.name)).join(","):"",fieldFiles:e}:e instanceof File?{value:e.name,fieldFiles:[e]}:Array.isArray(e)?{value:e.map((t=>"string"==typeof t?t:null==t?void 0:t.value)).join(",")}:{value:e});var o}processComments(t){var i;return null!==(i=null==t?void 0:t.map((t=>Object.assign({},t))))&&void 0!==i?i:[]}processMetadata(t){return t&&Object.keys(t).length>0?Object.assign({},t):void 0}}class y{constructor(t){this.accessMode=t}async addComment(t,i){if(!(null==t?void 0:t.id))throw new Error("Cannot add a comment without a submission ID.");const s=`${v.productV1ApiUrl}/UdpFormSubmission/${t.id}/comments/${this.accessMode}`;await d("POST",s,i,!0)}async updateComment(t,i){if(!(null==t?void 0:t.id))throw new Error("Cannot update a comment without a submission ID.");const{sectionKey:s,questionKey:e,commentId:n,value:o}=i,r=`${v.productV1ApiUrl}/UdpFormSubmission/${t.id}/comments/${n}`;await d("PUT",r,{value:o,sectionKey:s,questionKey:e},!0)}async deleteComment(t,i){if(!(null==t?void 0:t.id))throw new Error("Cannot delete a comment without a submission ID.");const{commentId:s}=i,e=`${v.productV1ApiUrl}/UdpFormSubmission/${t.id}/comments/${s}`;await d("DELETE",e,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 i=await this.getFormSubmissionByIdAndUser(t.id,t.unityUserId);return i?new p(Object.assign(Object.assign({},t),i)):t}const{id:i}=t,s=await this.getFormSubmissionById(i);return s?new p(Object.assign(Object.assign({},t),s)):t}async createNewLinkedFollowUpFormSubmission(t){if("public"===this.accessMode)throw new Error("Follow-up form submissions are not supported for public forms.");return this.saveFormDataWithoutValues(t,r.InProgress)}async saveCurrentFormSubmissionState(t,i){return"public"===this.accessMode?i:this.saveSubmissionToDB(t,i,r.InProgress)}async finalizeFormSubmissionState(t,i){return this.saveSubmissionToDB(t,i,r.Submitted)}async saveFormDataWithoutValues(t,i){const s=t.processSubmissionIntoFormDataWithoutValues(i),{method:e,url:n}=this.getApiRequestInfo(t),o=await d(e,n,s,!0);return""===o?await this.fetchAndPopulateUdpFormSubmissionObj(t):new p(Object.assign(Object.assign({},t),o))}getApiRequestInfo(t){const i=`${v.productV1ApiUrl}/UdpFormSubmission/${this.accessMode}`;return"public"===this.accessMode?{method:"POST",url:i}:t.id?{method:"PUT",url:i}:{method:"POST",url:i}}async saveSubmissionToDB(t,i,s){const e=i.processSubmissionIntoFormData(t,s),{method:n,url:o}=this.getApiRequestInfo(i),r=await d(n,o,e,!0);if(""===r)return await this.fetchAndPopulateUdpFormSubmissionObj(i);const a=new p(Object.assign(Object.assign({},i),r));return Object.assign(i,a),a}async getFormSubmissionById(t){var i;try{const s=new m(1,1).addFilter("id",t,f.EQUALS),e=await s.execute("UdpFormSubmission");return(null===(i=null==e?void 0:e.pageList)||void 0===i?void 0:i[0])||null}catch(t){return console.error("Error fetching form submission by ID:",t),null}}async getFormSubmissionByIdAndUser(t,i){var s;try{const e=new m(1,1).addFilter("id",t,f.EQUALS).addFilter("unityUserId",i,f.EQUALS),n=await e.execute("UdpFormSubmission");return(null===(s=null==n?void 0:n.pageList)||void 0===s?void 0:s[0])||null}catch(t){return console.error("Error fetching form submission by ID:",t),null}}}class w{static create(t,i){return new y(t?"public":"private")}}class S{constructor(t,i=!1){this.tenantId=t,this.isPublic=i}buildDescribeUrl(t,i){const s=v.productV1ApiUrl;return this.isPublic?`${s}/UdpForm/${t}/${i}/describe/public`:`${s}/UdpForm/${t}/${i}/describe`}async getFormByFormIdAndFormVersion(t,i){const s=this.buildDescribeUrl(t,i),e=await d("GET",s);return e.styleOverrides&&"string"==typeof e.styleOverrides&&(e.styleOverrides=JSON.parse(e.styleOverrides)),e}}class O{constructor(t){t&&Object.assign(this,t)}}const j=(t,i)=>{const s=Object.keys(i),e=new Set,n=new RegExp(`^${t}_(\\d+)`);return s.forEach((t=>{const i=t.match(n);i&&i[1]&&e.add(Number(i[1]))})),Array.from(e).sort(((t,i)=>t-i))},I=(t,i)=>{const s=`${"undefined"!=typeof window?window.location.pathname:`/page/${a.FormRendererPageId}`}?udpf_submissionId=${t}${"undefined"!=typeof window?window.location.hash:""}`,e=i;if(e){if("function"==typeof e.replace)return void e.replace(s);if("function"==typeof e.push)return void e.push(s);if("function"==typeof e){try{e(s,{replace:!0})}catch(t){e(s)}return}}"undefined"!=typeof window&&window.history&&"function"==typeof window.history.replaceState?window.history.replaceState({},"",s):"undefined"!=typeof window&&(window.location.href=s)},F=(t,i)=>{null==i||i(t,{variant:"success",anchorOrigin:{vertical:"top",horizontal:"center"}})},C=(t,i)=>{null==i||i(t,{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}})},D=t=>{if(!t)return{};if("object"==typeof t)return t;if("string"!=typeof t)return{};try{return JSON.parse(t||"{}")}catch(t){return{}}},$=class{constructor(i){t(this,i),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:i,nextValues:s}=(t=>{var i,s,e;const{dynamicSections:n,values:o,index:r}=t,a=n[r];if(!a)return{nextDynamicSections:n,nextValues:o};const h=a.name,c=j(h,o),u=c.length>0?Math.max(...c)+1:2,d=Object.assign(Object.assign({},structuredClone(a)),{formQuestions:(a.formQuestions||[]).map((t=>{const i=structuredClone(t);return i.questionIdentifierKey=`${h}_${u}.${t.name}`,i})),isOriginalSection:!1,sectionPositionSuffix:u});let m=r;for(let t=r+1;t<n.length&&n[t].name===h;t++)m=t;const f=[...n.slice(0,m+1),d,...n.slice(m+1)],v=structuredClone(o||{}),b=`${h}_${u}`,p=(y=a).isOriginalSection?y.name:`${y.name}_${y.sectionPositionSuffix}`;var y;for(const t of d.formQuestions||[]){v[b]||(v[b]={});let n="";if(t.fieldTypeId===l.Paragraph){const r=null===(s=null===(i=null==o?void 0:o[p])||void 0===i?void 0:i[t.name])||void 0===s?void 0:s.value,a=D(t.fieldProperties),l=null!==(e=null==a?void 0:a.paragraphText)&&void 0!==e?e:"";n=null!=r?r:l}v[b][t.name]={value:n,comments:[],metadata:{}}}return{nextDynamicSections:f,nextValues:v}})({dynamicSections:this.dynamicSections,values:structuredClone(this.udpFormSubmission.data.submissionResponseData||{}),index:t});this.dynamicSections=i,this.currentValues=Object.assign({},s),this.udpFormSubmission.data.submissionResponseData=Object.assign({},s),this.triggerFormRerender()}finally{this.isUpdatingSections=!1,this.isLoading=!1,this.hasUnsavedChanges=!0}}},this.deleteRepeatableSection=t=>{if(this.isSubmitted)return;const i=this.dynamicSections[t];if(i&&!i.isOriginalSection){this.isUpdatingSections=!0,this.isLoading=!0;try{const{nextDynamicSections:i,nextValues:s}=(t=>{const{dynamicSections:i,values:s,index:e}=t,n=i[e];if(!n||n.isOriginalSection)return{nextDynamicSections:i,nextValues:s};const o=n.name,r=n.sectionPositionSuffix,a=`${o}_${r}`,l=Object.assign({},s||{});delete l[a];const h=structuredClone(i);return h.splice(e,1),h.forEach((t=>{var i;if(t.name!==o||t.isOriginalSection||(null!==(i=t.sectionPositionSuffix)&&void 0!==i?i:0)<=(null!=r?r:0))return;const s=t.sectionPositionSuffix,e=`${o}_${s}`,n=s-1,a=`${o}_${n}`;t.sectionPositionSuffix=n,t.formQuestions=(t.formQuestions||[]).map((t=>{const i=structuredClone(t);return i.questionIdentifierKey=`${a}.${t.name}`,i})),l[e]&&(l[a]=structuredClone(l[e]),delete l[e])})),{nextDynamicSections:h,nextValues:l}})({dynamicSections:this.dynamicSections,values:Object.assign({},this.udpFormSubmission.data.submissionResponseData||{}),index:t});this.dynamicSections=i,this.currentValues=Object.assign({},s),this.udpFormSubmission.data.submissionResponseData=Object.assign({},s),this.triggerFormRerender()}finally{this.isUpdatingSections=!1,this.isLoading=!1,this.hasUnsavedChanges=!0}}},this.performBackgroundSaveAndUpdateLocalSubmissionState=async t=>this.performBackgroundSaveAndUpdateLocalSubmissionStateInternal(t),this.performBackgroundSaveAndUpdateLocalSubmissionStateInternal=async(t,i)=>{var s,e;const n=null!==(s=null==i?void 0:i.allowUrlReplace)&&void 0!==s?s:!this.isPublic,o=null!==(e=null==i?void 0:i.forceCreateDraftIfMissingId)&&void 0!==e&&e;if(!this.isPublic||this.publicFeatures.allowDraftSave||o)try{await this.formSubmissionHandler.saveCurrentFormSubmissionState(t,this.udpFormSubmission),await this.refreshSubmissionAndSyncState(),n&&!new URLSearchParams(window.location.search).has("udpf_submissionId")&&I(this.udpFormSubmission.id,this.history)}catch(t){}finally{this.isSaving=!1,this.hasUnsavedChanges=!1}},this.refreshSubmissionAndSyncState=async()=>{var t,i;if(!(null===(t=this.udpFormSubmission)||void 0===t?void 0:t.id))return;const s=await this.formSubmissionHandler.fetchAndPopulateUdpFormSubmissionObj(this.udpFormSubmission);this.udpFormSubmission=s,this.currentValues=Object.assign({},(null===(i=s.data)||void 0===i?void 0:i.submissionResponseData)||{}),this.isSubmitted=s.status===r.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")||I(this.udpFormSubmission.id,this.history),F("Form saved successfully.",this.enqueueSnackbar)}catch(t){C("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,i,s,e,n,o,r)=>{const l=await this.formHandler.getFormByFormIdAndFormVersion(t,i),h={submissionResponseData:c(l),submissionMetadata:{ParentSubmission:{submissionId:s,formId:e,formVersion:n}}},u=new p({formId:t,formVersion:i,unityUserId:this.clientUserInfo.id,data:h}),d=w.create(!1,this.clientUserInfo.id),m=await d.createNewLinkedFollowUpFormSubmission(u);this.udpFormSubmission.data.submissionResponseData[o][r].metadata=Object.assign(Object.assign({},this.udpFormSubmission.data.submissionResponseData[o][r].metadata),{followUpFormSubmissionId:m.id}),await this.performBackgroundSaveAndUpdateLocalSubmissionState(this.udpFormSubmission.data.submissionResponseData),window.open(`/page/${a.FormRendererPageId}?udpf_submissionId=${m.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 i=null===(t=this.getUserCallback)||void 0===t?void 0:t.call(this);i&&(this.clientUserInfo.id=i.id||null,this.clientUserInfo.displayName=i.name||null,this.clientUserInfo.email=i.email||null)}let i,s;this.formSubmissionHandler=w.create(this.isPublic,this.clientUserInfo.id),this.udpFormSubmission=new p({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?(i=this.udpFormSubmission.formId,s=this.udpFormSubmission.formVersion):this.formId&&this.version&&(i=this.formId,s=this.version),this.formHandler=new S(this.tenantId);const n=await this.formHandler.getFormByFormIdAndFormVersion(i,s);if(this.udpForm=new O(n),this.currentValues=c(this.udpForm),this.udpFormSubmission.data.submissionResponseData&&(this.currentValues=Object.assign({},this.udpFormSubmission.data.submissionResponseData),this.udpFormSubmission.status===r.Submitted&&(this.isSubmitted=!0)),(!this.udpFormSubmission.id||this.udpFormSubmission.status===r.Created)&&this.urlContext&&Object.keys(this.urlContext).length>0){this.dynamicSections=((t,i,s)=>{var e,n;const o=(t=>{const i={};return Object.keys(t&&"object"==typeof t?t:{}).forEach((t=>{var s;const e=t.match(/^([^._?&#]+)_(\d+)\./);if(!e)return;const n=e[1],o=Number(e[2]);!Number.isFinite(o)||o<2||o>(null!==(s=i[n])&&void 0!==s?s:1)&&(i[n]=o)})),i})(s),r=[],a=structuredClone(t.udpFormUdpFormSection).sort(((t,i)=>t.order-i.order));for(const s of a){s.sectionProperties=JSON.parse(s.sectionProperties||{});const a=j(s.name,i),l=a.length>0?Math.max(...a):1,h=null!==(e=null==o?void 0:o[s.name])&&void 0!==e?e:1,c=Math.max(l,h);if(s.isOriginalSection=!0,s.sectionPositionSuffix=1,r.push(Object.assign(Object.assign({},structuredClone(s)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===s.id)).sort(((t,i)=>t.questionOrder-i.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${s.name}.${t.name}`,isShowCommentInput:!0})))})),(null===(n=s.sectionProperties)||void 0===n?void 0:n.isRepeatable)&&c>=2)for(let i=2;i<=c;i++){const e=Object.assign(Object.assign({},structuredClone(s)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===s.id)).sort(((t,i)=>t.questionOrder-i.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${s.name}_${i}.${t.name}`,isShowCommentInput:!0}))),isOriginalSection:!1,sectionPositionSuffix:i});r.push(e)}}return r})(this.udpForm,this.currentValues,this.urlContext);const t=((t,i)=>{if(!Array.isArray(t))return;const s=i&&"object"==typeof i?i:{},e={};Object.keys(s).forEach((t=>{e[String(t).toLowerCase()]=s[t]}));const n={};t.forEach((t=>{const i=t.isOriginalSection?t.name:`${t.name}_${t.sectionPositionSuffix}`;(t.formQuestions||[]).forEach((t=>{if(!t)return;const s=[t.processedSubmissionName,t.questionIdentifierKey,t.name].filter(Boolean);let o;for(const t of s){const i=String(t).toLowerCase();if(Object.prototype.hasOwnProperty.call(e,i)){o=e[i];break}}null!=o&&(n[i]||(n[i]={}),n[i][t.name]={value:o,comments:[]})}))}));const o={};return Object.entries(n).forEach((([t,i])=>{o[t]||(o[t]={}),Object.entries(i).forEach((([i,s])=>{const e=o[t][i];(null==e||null==e.value||"string"==typeof e.value&&""===e.value.trim())&&(o[t][i]=s)}))})),t.forEach((t=>{const i=t.isOriginalSection?t.name:`${t.name}_${t.sectionPositionSuffix}`;o[i]||(o[i]={}),(t.formQuestions||[]).forEach((t=>{var s;if(t&&t.fieldTypeId===l.Paragraph){const e=o[i][t.name];if(null==e||null==e.value||"string"==typeof e.value&&""===e.value.trim()){let e=null==t?void 0:t.fieldProperties;if("string"==typeof e)try{e=JSON.parse(e||"{}")}catch(t){e={}}o[i][t.name]={value:null!==(s=null==e?void 0:e.paragraphText)&&void 0!==s?s:"",comments:[]}}}}))})),o})(this.dynamicSections,this.urlContext);t&&(this.currentValues=t,this.udpFormSubmission.data.submissionResponseData=Object.assign({},t))}else this.dynamicSections=((t,i)=>{var s;const e=[],n=structuredClone(t.udpFormUdpFormSection).sort(((t,i)=>t.order-i.order));for(const o of n){o.sectionProperties=JSON.parse(o.sectionProperties||{});const n=j(o.name,i);if(o.isOriginalSection=!0,o.sectionPositionSuffix=1,e.push(Object.assign(Object.assign({},structuredClone(o)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===o.id)).sort(((t,i)=>t.questionOrder-i.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${o.name}.${t.name}`,isShowCommentInput:!0})))})),(null===(s=o.sectionProperties)||void 0===s?void 0:s.isRepeatable)&&n.length>0){const i=Math.max(...n);for(let s=2;s<=i;s++){const i=Object.assign(Object.assign({},structuredClone(o)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===o.id)).sort(((t,i)=>t.questionOrder-i.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${o.name}_${s}.${t.name}`,isShowCommentInput:!0}))),isOriginalSection:!1,sectionPositionSuffix:s});e.push(i)}}}return e})(this.udpForm,this.currentValues);this.debouncedManualSave=e((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 C("There was an error submitting this form",this.enqueueSnackbar),t}finally{this.isLoading=!1}}async handleQuestionCommentLiveCRUD(t){var i,s,e,n,o,a;if(!this.isPublic||this.publicFeatures.allowComments)try{const{type:l,questionIdentifierKey:h,commentId:c}=t.detail,u=function(t){var i,s,e,n,o;const{actionType:r,questionIdentifierKey:a,commentId:l,currentSubmissionResponseData:h,clientUserInfo:c}=t,u=(a||"").split("."),d=u[0]||"",m=u[1]||"";if(!d||!m)return{sectionKey:d,questionKey:m,nextSubmissionResponseData:h||{},didMutate:!1,shouldPersist:!1,persistIntent:"none",commentId:l};const f=structuredClone(h||{});f[d]||(f[d]={}),f[d][m]?(f[d][m].comments=null!==(i=f[d][m].comments)&&void 0!==i?i:[],f[d][m].draftComments=null!==(s=f[d][m].draftComments)&&void 0!==s?s:[],f[d][m].metadata=null!==(e=f[d][m].metadata)&&void 0!==e?e:{}):f[d][m]={value:"",comments:[],draftComments:[],metadata:{}};const v=f[d][m].draftComments;v&&!Array.isArray(v)?f[d][m].draftComments=[v]:v||(f[d][m].draftComments=[]);const p=f[d][m].comments||[],y=f[d][m].draftComments||[];let w=!1;switch(r){case"add":{const t={value:"",commentId:b(),isTempComment:!0,timestamp:null};f[d][m].draftComments=[t,...y],w=!0;break}case"save":{const t=y.findIndex((t=>t.commentId===l));if(-1===t)return{sectionKey:d,questionKey:m,nextSubmissionResponseData:f,didMutate:!1,shouldPersist:!1,persistIntent:"none",commentId:l};const i=y[t],s=i.timestamp||(new Date).toISOString(),e=Object.assign(Object.assign({},i),{timestamp:s,editedTimestamp:(new Date).toISOString(),userId:null==c?void 0:c.id,userDisplayName:null==c?void 0:c.displayName,isDraftComment:!1}),n=p.findIndex((t=>t.commentId===l));if(-1!==n){const t=[...p];t[n]=Object.assign({},e),f[d][m].comments=t}else f[d][m].comments=[...p,e];f[d][m].draftComments=y.filter((t=>t.commentId!==l)),w=!0;break}case"edit":{const t=p.find((t=>t.commentId===l));if(!t)return{sectionKey:d,questionKey:m,nextSubmissionResponseData:f,didMutate:!1,shouldPersist:!1,persistIntent:"none",commentId:l};const i=Object.assign(Object.assign({},t),{isDraftComment:!0,timestamp:null});f[d][m].draftComments=[i,...y],f[d][m].comments=p,w=!0;break}case"delete":f[d][m].comments=p.map((t=>t.commentId===l?Object.assign(Object.assign({},t),{isDeleted:!0,value:"",editedTimestamp:(new Date).toISOString()}):t)),w=!0;break;case"editClose":f[d][m].draftComments=y.filter((t=>t.commentId!==l)),w=!0}const S="save"===r||"delete"===r;let O;if("save"===r){const t=((null===(o=null===(n=null==f?void 0:f[d])||void 0===n?void 0:n[m])||void 0===o?void 0:o.comments)||[]).find((t=>t.commentId===l));O=null==t?void 0:t.value}return{sectionKey:d,questionKey:m,nextSubmissionResponseData:f,didMutate:w,shouldPersist:S,persistIntent:"none",commentId:l,valueToPersist:O}}({actionType:l,questionIdentifierKey:h,commentId:c,currentSubmissionResponseData:this.udpFormSubmission.data.submissionResponseData||{},clientUserInfo:this.clientUserInfo}),d=u.nextSubmissionResponseData;if(this.udpFormSubmission.data.submissionResponseData=Object.assign({},d),"edit"!==l&&"editClose"!==l&&"add"!==l||(this.currentValues=Object.assign({},d)),u.shouldPersist){const t=(null===(i=this.udpFormSubmission)||void 0===i?void 0:i.status)===r.Submitted,h=(null===(s=this.udpFormSubmission)||void 0===s?void 0:s.unityUserId)===this.clientUserInfo.id,c=((null===(o=null===(n=null===(e=this.currentValues||{})||void 0===e?void 0:e[u.sectionKey])||void 0===n?void 0:n[u.questionKey])||void 0===o?void 0:o.comments)||[]).find((t=>(null==t?void 0:t.commentId)===u.commentId&&!(null==t?void 0:t.isDeleted)));if(t||!h)if(null===(a=this.udpFormSubmission)||void 0===a?void 0:a.id){if("save"===l){const t=u.valueToPersist;if(t)try{c?await this.formSubmissionHandler.updateComment(this.udpFormSubmission,{sectionKey:u.sectionKey,questionKey:u.questionKey,value:t,commentId:u.commentId}):await this.formSubmissionHandler.addComment(this.udpFormSubmission,{sectionKey:u.sectionKey,questionKey:u.questionKey,value:t,commentId:u.commentId}),await this.refreshSubmissionAndSyncState(),F(c?"Comment updated.":"Comment added.",this.enqueueSnackbar)}catch(t){throw C(c?"Failed to update comment.":"Failed to add comment.",this.enqueueSnackbar),t}}else if("delete"===l)try{await this.formSubmissionHandler.deleteComment(this.udpFormSubmission,{sectionKey:u.sectionKey,questionKey:u.questionKey,commentId:u.commentId}),await this.refreshSubmissionAndSyncState(),F("Comment deleted.",this.enqueueSnackbar)}catch(t){throw C("Failed to delete comment.",this.enqueueSnackbar),t}}else this.currentValues=Object.assign({},d);else this.isPublic?this.currentValues=Object.assign({},d):await this.handleManualSave(d)}else this.currentValues=Object.assign({},d)}catch(t){console.error("Error handling live comment CRUD:",t)}finally{this.triggerFormRerender()}}async loadFollowUpForms(t,i){var s;this.isLoading=!0;try{const e=(await o(this.followUpSideSheetListPageNumber,this.FOLLOW_UP_SIDE_SHEET_PAGE_SIZE,[{searchField:"type",searchOperator:"=",searchValue:h.FollowUp}],{sortDirection:"DESC",sortColumn:"lastModifiedOn"})).data;if(!e||!Array.isArray(e.pageList))throw new Error("Malformed form versions data.");this.sideSheetFollowUpFormsList=this.formatFollowUpFormsList(e.pageList,t,i),this.followUpSideSheetTotalItems=null!==(s=e.total)&&void 0!==s?s:0}catch(t){console.error("Failed to follow up form.",t)}finally{this.isLoading=!1}}formatFollowUpFormsList(t,i,s){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,i,s)})))}async handleSideSheetPageChange(t){this.followUpSideSheetListPageNumber=t,await this.loadFollowUpForms(this.followUpParentSectionKey,this.followUpParentQuestionKey)}renderFollowUpSideSheet(){return this.isPublic?null:i("udp-side-sheet",{title:"Link a Follow Up Form",open:this.isFollowUpFormsSideSheetOpen,onUdpSideSheetClose:()=>this.handleSideSheetClose(),position:"right",width:"md"},this.isLoading&&this.isFollowUpFormsSideSheetOpen&&i("udp-linear-loader",null),i("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 i("div",{key:"37ec47fc7f3ecec70ba7ca3e12717789285be5d8",class:"forms-renderer-container",style:this.isLoading?{minHeight:"100vh"}:{}},this.renderFollowUpSideSheet(),i("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 s(this)}};export{$ as udp_forms_renderer}
1
+ import{r as t,h as i,a as s}from"./index-DFnjA9NX.js";import{throttle as e}from"lodash";import{g as n}from"./tenantUtils-Basdb1b1.js";import{f as o}from"./udp-form-api-utils-vPSYCvIA.js";import{b as r,U as a,c as h,a as l}from"./enums-D5dod6Ie.js";import{b as u}from"./utils-kwLwITIE.js";import{c,m as d}from"./makeApiCall-2umiVB6u.js";import{S as m,c as f}from"./SearchBuilder-BjVdKjci.js";import{C as v}from"./configService-BqLfkVKh.js";import{v4 as b}from"uuid";import"axios";class p{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 i=this.buildBaseSubmissionData(t),s=c(i);return s.append("Data",JSON.stringify(this.data)),s}processSubmissionIntoFormData(t,i){const s=this.buildBaseSubmissionData(i),{cleanedData:e,files:n}=this.extractCleanedDataAndFiles(t),o=c(s);return n.forEach((t=>o.append("FormFiles",t))),o.append("Data",JSON.stringify({submissionResponseData:e,submissionMetadata:this.data.submissionMetadata||null})),o}buildBaseSubmissionData(t){const i={FormId:this.formId,FormVersion:this.formVersion.toString(),Status:t};return this.id&&(i.Id=this.id),i.InitialCreatedOn=this.initialCreatedOn?this.initialCreatedOn:(new Date).toISOString(),i.LastModifiedOn=this.lastModifiedOn?this.lastModifiedOn:(new Date).toISOString(),this.submittedOn&&(i.submittedOn=this.submittedOn),this.generic1&&(i.generic1=this.generic1.toString()),this.generic2&&(i.generic2=this.generic2.toString()),this.generic3&&(i.generic3=this.generic3.toString()),i}extractCleanedDataAndFiles(t){const i=[],s={};for(const e in t){s[e]={};for(const n in t[e]){const o=t[e][n],{value:r,fieldFiles:a}=this.extractValueAndFiles(o);a&&i.push(...a);const h=this.processComments(o.comments),l=this.processMetadata(o.metadata);s[e][n]=Object.assign({value:r,comments:h},l&&{metadata:l})}}return{cleanedData:s,files:i}}extractValueAndFiles(t){var i,s;let e=(null===(i=null==t?void 0:t.value)||void 0===i?void 0:i.files)?t.value.value:null==t?void 0:t.value;const n=null===(s=null==t?void 0:t.value)||void 0===s?void 0:s.files;return n&&Array.isArray(n)?{value:"string"==typeof e&&""!==e.trim()?e:"",fieldFiles:n}:(o=e,Array.isArray(o)&&o.every((t=>t instanceof File))?{value:e.length>0?e.map((t=>t.name)).join(","):"",fieldFiles:e}:e instanceof File?{value:e.name,fieldFiles:[e]}:Array.isArray(e)?{value:e.map((t=>"string"==typeof t?t:null==t?void 0:t.value)).join(",")}:{value:e});var o}processComments(t){var i;return null!==(i=null==t?void 0:t.map((t=>Object.assign({},t))))&&void 0!==i?i:[]}processMetadata(t){return t&&Object.keys(t).length>0?Object.assign({},t):void 0}}class y{constructor(t,i){this.accessMode=t,this.tenantId=i}get extraHeaders(){if("public"===this.accessMode&&this.tenantId)return{currentTenantId:String(this.tenantId)}}async addComment(t,i){if(!(null==t?void 0:t.id))throw new Error("Cannot add a comment without a submission ID.");const s=`${v.productV1ApiUrl}/UdpFormSubmission/${t.id}/comments/${this.accessMode}`;await d("POST",s,i,!0)}async updateComment(t,i){if(!(null==t?void 0:t.id))throw new Error("Cannot update a comment without a submission ID.");const{sectionKey:s,questionKey:e,commentId:n,value:o}=i,r=`${v.productV1ApiUrl}/UdpFormSubmission/${t.id}/comments/${n}`;await d("PUT",r,{value:o,sectionKey:s,questionKey:e},!0,this.extraHeaders)}async deleteComment(t,i){if(!(null==t?void 0:t.id))throw new Error("Cannot delete a comment without a submission ID.");const{commentId:s}=i,e=`${v.productV1ApiUrl}/UdpFormSubmission/${t.id}/comments/${s}`;await d("DELETE",e,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 i=await this.getFormSubmissionByIdAndUser(t.id,t.unityUserId);return i?new p(Object.assign(Object.assign({},t),i)):t}const{id:i}=t,s=await this.getFormSubmissionById(i);return s?new p(Object.assign(Object.assign({},t),s)):t}async createNewLinkedFollowUpFormSubmission(t){if("public"===this.accessMode)throw new Error("Follow-up form submissions are not supported for public forms.");return this.saveFormDataWithoutValues(t,r.InProgress)}async saveCurrentFormSubmissionState(t,i){return"public"===this.accessMode?i:this.saveSubmissionToDB(t,i,r.InProgress)}async finalizeFormSubmissionState(t,i){return this.saveSubmissionToDB(t,i,r.Submitted)}async saveFormDataWithoutValues(t,i){const s=t.processSubmissionIntoFormDataWithoutValues(i),{method:e,url:n}=this.getApiRequestInfo(t),o=await d(e,n,s,!0,this.extraHeaders);return""===o?await this.fetchAndPopulateUdpFormSubmissionObj(t):new p(Object.assign(Object.assign({},t),o))}getApiRequestInfo(t){const i=`${v.productV1ApiUrl}/UdpFormSubmission/${this.accessMode}`;return"public"===this.accessMode?{method:"POST",url:i}:t.id?{method:"PUT",url:i}:{method:"POST",url:i}}async saveSubmissionToDB(t,i,s){const e=i.processSubmissionIntoFormData(t,s),{method:n,url:o}=this.getApiRequestInfo(i),r=await d(n,o,e,!0,this.extraHeaders);if(""===r)return await this.fetchAndPopulateUdpFormSubmissionObj(i);const a=new p(Object.assign(Object.assign({},i),r));return Object.assign(i,a),a}async getFormSubmissionById(t){var i;try{const s=new m(1,1).addFilter("id",t,f.EQUALS),e=await s.execute("UdpFormSubmission");return(null===(i=null==e?void 0:e.pageList)||void 0===i?void 0:i[0])||null}catch(t){return console.error("Error fetching form submission by ID:",t),null}}async getFormSubmissionByIdAndUser(t,i){var s;try{const e=new m(1,1).addFilter("id",t,f.EQUALS).addFilter("unityUserId",i,f.EQUALS),n=await e.execute("UdpFormSubmission");return(null===(s=null==n?void 0:n.pageList)||void 0===s?void 0:s[0])||null}catch(t){return console.error("Error fetching form submission by ID:",t),null}}}class w{static create(t,i,s){return new y(t?"public":"private",null!=s?s:void 0)}}class S{constructor(t,i=!1){this.tenantId=t,this.isPublic=i}buildDescribeUrl(t,i){const s=v.productV1ApiUrl,e="number"==typeof i?`/${i}`:"";return this.isPublic?`${s}/UdpForm/${t}${e}/describe/public`:`${s}/UdpForm/${t}${e}/describe`}async getFormByFormIdAndFormVersion(t,i){const s=this.buildDescribeUrl(t,i),e=this.isPublic&&this.tenantId?{currentTenantId:String(this.tenantId)}:void 0,n=await d("GET",s,void 0,!1,e);return n.styleOverrides&&"string"==typeof n.styleOverrides&&(n.styleOverrides=JSON.parse(n.styleOverrides)),n}}class O{constructor(t){t&&Object.assign(this,t)}}const j=(t,i)=>{const s=Object.keys(i),e=new Set,n=new RegExp(`^${t}_(\\d+)`);return s.forEach((t=>{const i=t.match(n);i&&i[1]&&e.add(Number(i[1]))})),Array.from(e).sort(((t,i)=>t-i))},I=(t,i)=>{const s=`${"undefined"!=typeof window?window.location.pathname:`/page/${a.FormRendererPageId}`}?udpf_submissionId=${t}${"undefined"!=typeof window?window.location.hash:""}`,e=i;if(e){if("function"==typeof e.replace)return void e.replace(s);if("function"==typeof e.push)return void e.push(s);if("function"==typeof e){try{e(s,{replace:!0})}catch(t){e(s)}return}}"undefined"!=typeof window&&window.history&&"function"==typeof window.history.replaceState?window.history.replaceState({},"",s):"undefined"!=typeof window&&(window.location.href=s)},F=(t,i)=>{null==i||i(t,{variant:"success",anchorOrigin:{vertical:"top",horizontal:"center"}})},C=(t,i)=>{null==i||i(t,{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}})},g=t=>{if(!t)return{};if("object"==typeof t)return t;if("string"!=typeof t)return{};try{return JSON.parse(t||"{}")}catch(t){return{}}},$=class{constructor(i){t(this,i),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:i,nextValues:s}=(t=>{var i,s,e;const{dynamicSections:n,values:o,index:r}=t,a=n[r];if(!a)return{nextDynamicSections:n,nextValues:o};const l=a.name,u=j(l,o),c=u.length>0?Math.max(...u)+1:2,d=Object.assign(Object.assign({},structuredClone(a)),{formQuestions:(a.formQuestions||[]).map((t=>{const i=structuredClone(t);return i.questionIdentifierKey=`${l}_${c}.${t.name}`,i})),isOriginalSection:!1,sectionPositionSuffix:c});let m=r;for(let t=r+1;t<n.length&&n[t].name===l;t++)m=t;const f=[...n.slice(0,m+1),d,...n.slice(m+1)],v=structuredClone(o||{}),b=`${l}_${c}`,p=(y=a).isOriginalSection?y.name:`${y.name}_${y.sectionPositionSuffix}`;var y;for(const t of d.formQuestions||[]){v[b]||(v[b]={});let n="";if(t.fieldTypeId===h.Paragraph){const r=null===(s=null===(i=null==o?void 0:o[p])||void 0===i?void 0:i[t.name])||void 0===s?void 0:s.value,a=g(t.fieldProperties),h=null!==(e=null==a?void 0:a.paragraphText)&&void 0!==e?e:"";n=null!=r?r:h}v[b][t.name]={value:n,comments:[],metadata:{}}}return{nextDynamicSections:f,nextValues:v}})({dynamicSections:this.dynamicSections,values:structuredClone(this.udpFormSubmission.data.submissionResponseData||{}),index:t});this.dynamicSections=i,this.currentValues=Object.assign({},s),this.udpFormSubmission.data.submissionResponseData=Object.assign({},s),this.triggerFormRerender()}finally{this.isUpdatingSections=!1,this.isLoading=!1,this.hasUnsavedChanges=!0}}},this.deleteRepeatableSection=t=>{if(this.isSubmitted)return;const i=this.dynamicSections[t];if(i&&!i.isOriginalSection){this.isUpdatingSections=!0,this.isLoading=!0;try{const{nextDynamicSections:i,nextValues:s}=(t=>{const{dynamicSections:i,values:s,index:e}=t,n=i[e];if(!n||n.isOriginalSection)return{nextDynamicSections:i,nextValues:s};const o=n.name,r=n.sectionPositionSuffix,a=`${o}_${r}`,h=Object.assign({},s||{});delete h[a];const l=structuredClone(i);return l.splice(e,1),l.forEach((t=>{var i;if(t.name!==o||t.isOriginalSection||(null!==(i=t.sectionPositionSuffix)&&void 0!==i?i:0)<=(null!=r?r:0))return;const s=t.sectionPositionSuffix,e=`${o}_${s}`,n=s-1,a=`${o}_${n}`;t.sectionPositionSuffix=n,t.formQuestions=(t.formQuestions||[]).map((t=>{const i=structuredClone(t);return i.questionIdentifierKey=`${a}.${t.name}`,i})),h[e]&&(h[a]=structuredClone(h[e]),delete h[e])})),{nextDynamicSections:l,nextValues:h}})({dynamicSections:this.dynamicSections,values:Object.assign({},this.udpFormSubmission.data.submissionResponseData||{}),index:t});this.dynamicSections=i,this.currentValues=Object.assign({},s),this.udpFormSubmission.data.submissionResponseData=Object.assign({},s),this.triggerFormRerender()}finally{this.isUpdatingSections=!1,this.isLoading=!1,this.hasUnsavedChanges=!0}}},this.performBackgroundSaveAndUpdateLocalSubmissionState=async t=>this.performBackgroundSaveAndUpdateLocalSubmissionStateInternal(t),this.performBackgroundSaveAndUpdateLocalSubmissionStateInternal=async(t,i)=>{var s,e;const n=null!==(s=null==i?void 0:i.allowUrlReplace)&&void 0!==s?s:!this.isPublic,o=null!==(e=null==i?void 0:i.forceCreateDraftIfMissingId)&&void 0!==e&&e;if(!this.isPublic||this.publicFeatures.allowDraftSave||o)try{await this.formSubmissionHandler.saveCurrentFormSubmissionState(t,this.udpFormSubmission),await this.refreshSubmissionAndSyncState(),n&&!new URLSearchParams(window.location.search).has("udpf_submissionId")&&I(this.udpFormSubmission.id,this.history)}catch(t){}finally{this.isSaving=!1,this.hasUnsavedChanges=!1}},this.refreshSubmissionAndSyncState=async()=>{var t,i;if(!(null===(t=this.udpFormSubmission)||void 0===t?void 0:t.id))return;const s=await this.formSubmissionHandler.fetchAndPopulateUdpFormSubmissionObj(this.udpFormSubmission);this.udpFormSubmission=s,this.currentValues=Object.assign({},(null===(i=s.data)||void 0===i?void 0:i.submissionResponseData)||{}),this.isSubmitted=s.status===r.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")||I(this.udpFormSubmission.id,this.history),F("Form saved successfully.",this.enqueueSnackbar)}catch(t){C("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,i,s,e,n,o,r)=>{const h=await this.formHandler.getFormByFormIdAndFormVersion(t,i),l={submissionResponseData:u(h),submissionMetadata:{ParentSubmission:{submissionId:s,formId:e,formVersion:n}}},c=new p({formId:t,formVersion:i,unityUserId:this.clientUserInfo.id,data:l}),d=w.create(!1,this.clientUserInfo.id),m=await d.createNewLinkedFollowUpFormSubmission(c);this.udpFormSubmission.data.submissionResponseData[o][r].metadata=Object.assign(Object.assign({},this.udpFormSubmission.data.submissionResponseData[o][r].metadata),{followUpFormSubmissionId:m.id}),await this.performBackgroundSaveAndUpdateLocalSubmissionState(this.udpFormSubmission.data.submissionResponseData),window.open(`/page/${a.FormRendererPageId}?udpf_submissionId=${m.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 new 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 i=null===(t=this.getUserCallback)||void 0===t?void 0:t.call(this);i&&(this.clientUserInfo.id=i.id||null,this.clientUserInfo.displayName=i.name||null,this.clientUserInfo.email=i.email||null)}let i,s;this.formSubmissionHandler=w.create(this.isPublic,this.clientUserInfo.id,this.tenantId),this.udpFormSubmission=new p({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?(i=this.udpFormSubmission.formId,s=this.udpFormSubmission.formVersion):this.formId&&this.version&&(i=this.formId,s=this.version),this.formHandler=new S(this.tenantId,this.isPublic);const n=await this.formHandler.getFormByFormIdAndFormVersion(i,s);if(this.udpForm=new O(n),this.currentValues=u(this.udpForm),this.udpFormSubmission.data.submissionResponseData&&(this.currentValues=Object.assign({},this.udpFormSubmission.data.submissionResponseData),this.udpFormSubmission.status===r.Submitted&&(this.isSubmitted=!0)),(!this.udpFormSubmission.id||this.udpFormSubmission.status===r.Created)&&this.urlContext&&Object.keys(this.urlContext).length>0){this.dynamicSections=((t,i,s)=>{var e,n;const o=(t=>{const i={};return Object.keys(t&&"object"==typeof t?t:{}).forEach((t=>{var s;const e=t.match(/^([^._?&#]+)_(\d+)\./);if(!e)return;const n=e[1],o=Number(e[2]);!Number.isFinite(o)||o<2||o>(null!==(s=i[n])&&void 0!==s?s:1)&&(i[n]=o)})),i})(s),r=[],a=structuredClone(t.udpFormUdpFormSection).sort(((t,i)=>t.order-i.order));for(const s of a){s.sectionProperties=JSON.parse(s.sectionProperties||{});const a=j(s.name,i),h=a.length>0?Math.max(...a):1,l=null!==(e=null==o?void 0:o[s.name])&&void 0!==e?e:1,u=Math.max(h,l);if(s.isOriginalSection=!0,s.sectionPositionSuffix=1,r.push(Object.assign(Object.assign({},structuredClone(s)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===s.id)).sort(((t,i)=>t.questionOrder-i.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${s.name}.${t.name}`,isShowCommentInput:!0})))})),(null===(n=s.sectionProperties)||void 0===n?void 0:n.isRepeatable)&&u>=2)for(let i=2;i<=u;i++){const e=Object.assign(Object.assign({},structuredClone(s)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===s.id)).sort(((t,i)=>t.questionOrder-i.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${s.name}_${i}.${t.name}`,isShowCommentInput:!0}))),isOriginalSection:!1,sectionPositionSuffix:i});r.push(e)}}return r})(this.udpForm,this.currentValues,this.urlContext);const t=((t,i)=>{if(!Array.isArray(t))return;const s=i&&"object"==typeof i?i:{},e={};Object.keys(s).forEach((t=>{e[String(t).toLowerCase()]=s[t]}));const n={};t.forEach((t=>{const i=t.isOriginalSection?t.name:`${t.name}_${t.sectionPositionSuffix}`;(t.formQuestions||[]).forEach((t=>{if(!t)return;const s=[t.processedSubmissionName,t.questionIdentifierKey,t.name].filter(Boolean);let o;for(const t of s){const i=String(t).toLowerCase();if(Object.prototype.hasOwnProperty.call(e,i)){o=e[i];break}}null!=o&&(n[i]||(n[i]={}),n[i][t.name]={value:o,comments:[]})}))}));const o={};return Object.entries(n).forEach((([t,i])=>{o[t]||(o[t]={}),Object.entries(i).forEach((([i,s])=>{const e=o[t][i];(null==e||null==e.value||"string"==typeof e.value&&""===e.value.trim())&&(o[t][i]=s)}))})),t.forEach((t=>{const i=t.isOriginalSection?t.name:`${t.name}_${t.sectionPositionSuffix}`;o[i]||(o[i]={}),(t.formQuestions||[]).forEach((t=>{var s;if(t&&t.fieldTypeId===h.Paragraph){const e=o[i][t.name];if(null==e||null==e.value||"string"==typeof e.value&&""===e.value.trim()){let e=null==t?void 0:t.fieldProperties;if("string"==typeof e)try{e=JSON.parse(e||"{}")}catch(t){e={}}o[i][t.name]={value:null!==(s=null==e?void 0:e.paragraphText)&&void 0!==s?s:"",comments:[]}}}}))})),o})(this.dynamicSections,this.urlContext);t&&(this.currentValues=t,this.udpFormSubmission.data.submissionResponseData=Object.assign({},t))}else this.dynamicSections=((t,i)=>{var s;const e=[],n=structuredClone(t.udpFormUdpFormSection).sort(((t,i)=>t.order-i.order));for(const o of n){o.sectionProperties=JSON.parse(o.sectionProperties||{});const n=j(o.name,i);if(o.isOriginalSection=!0,o.sectionPositionSuffix=1,e.push(Object.assign(Object.assign({},structuredClone(o)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===o.id)).sort(((t,i)=>t.questionOrder-i.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${o.name}.${t.name}`,isShowCommentInput:!0})))})),(null===(s=o.sectionProperties)||void 0===s?void 0:s.isRepeatable)&&n.length>0){const i=Math.max(...n);for(let s=2;s<=i;s++){const i=Object.assign(Object.assign({},structuredClone(o)),{formQuestions:structuredClone(t.formQuestions).filter((t=>t.formSectionId===o.id)).sort(((t,i)=>t.questionOrder-i.questionOrder)).map((t=>Object.assign(Object.assign({},t),{questionIdentifierKey:`${o.name}_${s}.${t.name}`,isShowCommentInput:!0}))),isOriginalSection:!1,sectionPositionSuffix:s});e.push(i)}}}return e})(this.udpForm,this.currentValues);this.debouncedManualSave=e((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 C("There was an error submitting this form",this.enqueueSnackbar),t}finally{this.isLoading=!1}}async handleQuestionCommentLiveCRUD(t){var i,s,e,n,o,a;if(!this.isPublic||this.publicFeatures.allowComments)try{const{type:h,questionIdentifierKey:l,commentId:u}=t.detail,c=function(t){var i,s,e,n,o;const{actionType:r,questionIdentifierKey:a,commentId:h,currentSubmissionResponseData:l,clientUserInfo:u}=t,c=(a||"").split("."),d=c[0]||"",m=c[1]||"";if(!d||!m)return{sectionKey:d,questionKey:m,nextSubmissionResponseData:l||{},didMutate:!1,shouldPersist:!1,persistIntent:"none",commentId:h};const f=structuredClone(l||{});f[d]||(f[d]={}),f[d][m]?(f[d][m].comments=null!==(i=f[d][m].comments)&&void 0!==i?i:[],f[d][m].draftComments=null!==(s=f[d][m].draftComments)&&void 0!==s?s:[],f[d][m].metadata=null!==(e=f[d][m].metadata)&&void 0!==e?e:{}):f[d][m]={value:"",comments:[],draftComments:[],metadata:{}};const v=f[d][m].draftComments;v&&!Array.isArray(v)?f[d][m].draftComments=[v]:v||(f[d][m].draftComments=[]);const p=f[d][m].comments||[],y=f[d][m].draftComments||[];let w=!1;switch(r){case"add":{const t={value:"",commentId:b(),isTempComment:!0,timestamp:null};f[d][m].draftComments=[t,...y],w=!0;break}case"save":{const t=y.findIndex((t=>t.commentId===h));if(-1===t)return{sectionKey:d,questionKey:m,nextSubmissionResponseData:f,didMutate:!1,shouldPersist:!1,persistIntent:"none",commentId:h};const i=y[t],s=i.timestamp||(new Date).toISOString(),e=Object.assign(Object.assign({},i),{timestamp:s,editedTimestamp:(new Date).toISOString(),userId:null==u?void 0:u.id,userDisplayName:null==u?void 0:u.displayName,isDraftComment:!1}),n=p.findIndex((t=>t.commentId===h));if(-1!==n){const t=[...p];t[n]=Object.assign({},e),f[d][m].comments=t}else f[d][m].comments=[...p,e];f[d][m].draftComments=y.filter((t=>t.commentId!==h)),w=!0;break}case"edit":{const t=p.find((t=>t.commentId===h));if(!t)return{sectionKey:d,questionKey:m,nextSubmissionResponseData:f,didMutate:!1,shouldPersist:!1,persistIntent:"none",commentId:h};const i=Object.assign(Object.assign({},t),{isDraftComment:!0,timestamp:null});f[d][m].draftComments=[i,...y],f[d][m].comments=p,w=!0;break}case"delete":f[d][m].comments=p.map((t=>t.commentId===h?Object.assign(Object.assign({},t),{isDeleted:!0,value:"",editedTimestamp:(new Date).toISOString()}):t)),w=!0;break;case"editClose":f[d][m].draftComments=y.filter((t=>t.commentId!==h)),w=!0}const S="save"===r||"delete"===r;let O;if("save"===r){const t=((null===(o=null===(n=null==f?void 0:f[d])||void 0===n?void 0:n[m])||void 0===o?void 0:o.comments)||[]).find((t=>t.commentId===h));O=null==t?void 0:t.value}return{sectionKey:d,questionKey:m,nextSubmissionResponseData:f,didMutate:w,shouldPersist:S,persistIntent:"none",commentId:h,valueToPersist:O}}({actionType:h,questionIdentifierKey:l,commentId:u,currentSubmissionResponseData:this.udpFormSubmission.data.submissionResponseData||{},clientUserInfo:this.clientUserInfo}),d=c.nextSubmissionResponseData;if(this.udpFormSubmission.data.submissionResponseData=Object.assign({},d),"edit"!==h&&"editClose"!==h&&"add"!==h||(this.currentValues=Object.assign({},d)),c.shouldPersist){const t=(null===(i=this.udpFormSubmission)||void 0===i?void 0:i.status)===r.Submitted,l=(null===(s=this.udpFormSubmission)||void 0===s?void 0:s.unityUserId)===this.clientUserInfo.id,u=((null===(o=null===(n=null===(e=this.currentValues||{})||void 0===e?void 0:e[c.sectionKey])||void 0===n?void 0:n[c.questionKey])||void 0===o?void 0:o.comments)||[]).find((t=>(null==t?void 0:t.commentId)===c.commentId&&!(null==t?void 0:t.isDeleted)));if(t||!l)if(null===(a=this.udpFormSubmission)||void 0===a?void 0:a.id){if("save"===h){const t=c.valueToPersist;if(t)try{u?await this.formSubmissionHandler.updateComment(this.udpFormSubmission,{sectionKey:c.sectionKey,questionKey:c.questionKey,value:t,commentId:c.commentId}):await this.formSubmissionHandler.addComment(this.udpFormSubmission,{sectionKey:c.sectionKey,questionKey:c.questionKey,value:t,commentId:c.commentId}),await this.refreshSubmissionAndSyncState(),F(u?"Comment updated.":"Comment added.",this.enqueueSnackbar)}catch(t){throw C(u?"Failed to update comment.":"Failed to add comment.",this.enqueueSnackbar),t}}else if("delete"===h)try{await this.formSubmissionHandler.deleteComment(this.udpFormSubmission,{sectionKey:c.sectionKey,questionKey:c.questionKey,commentId:c.commentId}),await this.refreshSubmissionAndSyncState(),F("Comment deleted.",this.enqueueSnackbar)}catch(t){throw C("Failed to delete comment.",this.enqueueSnackbar),t}}else this.currentValues=Object.assign({},d);else this.isPublic?this.currentValues=Object.assign({},d):await this.handleManualSave(d)}else this.currentValues=Object.assign({},d)}catch(t){console.error("Error handling live comment CRUD:",t)}finally{this.triggerFormRerender()}}async loadFollowUpForms(t,i){var s;this.isLoading=!0;try{const e=(await o(this.followUpSideSheetListPageNumber,this.FOLLOW_UP_SIDE_SHEET_PAGE_SIZE,[{searchField:"type",searchOperator:"=",searchValue:l.FollowUp}],{sortDirection:"DESC",sortColumn:"lastModifiedOn"})).data;if(!e||!Array.isArray(e.pageList))throw new Error("Malformed form versions data.");this.sideSheetFollowUpFormsList=this.formatFollowUpFormsList(e.pageList,t,i),this.followUpSideSheetTotalItems=null!==(s=e.total)&&void 0!==s?s:0}catch(t){console.error("Failed to follow up form.",t)}finally{this.isLoading=!1}}formatFollowUpFormsList(t,i,s){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,i,s)})))}async handleSideSheetPageChange(t){this.followUpSideSheetListPageNumber=t,await this.loadFollowUpForms(this.followUpParentSectionKey,this.followUpParentQuestionKey)}renderFollowUpSideSheet(){return this.isPublic?null:i("udp-side-sheet",{title:"Link a Follow Up Form",open:this.isFollowUpFormsSideSheetOpen,onUdpSideSheetClose:()=>this.handleSideSheetClose(),position:"right",width:"md"},this.isLoading&&this.isFollowUpFormsSideSheetOpen&&i("udp-linear-loader",null),i("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 i("div",{key:"f53b65027554505a1301ab98379035e0316735dc",class:"forms-renderer-container",style:this.isLoading?{minHeight:"100vh"}:{}},this.renderFollowUpSideSheet(),i("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 s(this)}};export{$ as udp_forms_renderer}
@@ -3,6 +3,7 @@ export declare class UdpFormsRenderer {
3
3
  el: HTMLElement;
4
4
  formId?: Guid | null;
5
5
  version?: number | null;
6
+ urlTenantId?: Guid | null;
6
7
  submissionId?: Guid | null;
7
8
  triggerAction: (actionId: Guid, params: Object) => void;
8
9
  isPublic: boolean;
@@ -12,7 +12,9 @@ export type UdpFormSubmissionAccessMode = 'public' | 'private';
12
12
  */
13
13
  export declare class FormSubmissionHandler implements IFormSubmissionHandler {
14
14
  private readonly accessMode;
15
- constructor(accessMode: UdpFormSubmissionAccessMode);
15
+ private readonly tenantId?;
16
+ constructor(accessMode: UdpFormSubmissionAccessMode, tenantId?: string | null);
17
+ private get extraHeaders();
16
18
  addComment(udpFormSubmission: UdpFormSubmission, comment: {
17
19
  sectionKey: string;
18
20
  questionKey: string;
@@ -4,5 +4,5 @@ import { Guid } from '../types';
4
4
  * Factory for creating form submission handlers.
5
5
  */
6
6
  export declare class FormSubmissionHandlerFactory {
7
- static create(isPublic: boolean, userId?: Guid | null): IFormSubmissionHandler;
7
+ static create(isPublic: boolean, userId?: Guid | null, currentTenantId?: Guid | null): IFormSubmissionHandler;
8
8
  }
@@ -3651,7 +3651,7 @@ export namespace Components {
3651
3651
  "formsBuilderUrlPath": string;
3652
3652
  "history": { push: (path: string) => void };
3653
3653
  /**
3654
- * @default true
3654
+ * @default false
3655
3655
  */
3656
3656
  "isCommentingConfigOn": boolean;
3657
3657
  /**
@@ -3778,6 +3778,7 @@ export namespace Components {
3778
3778
  * @default {}
3779
3779
  */
3780
3780
  "urlContext": Record<string, any>;
3781
+ "urlTenantId"?: Guid | null;
3781
3782
  "version"?: number | null;
3782
3783
  }
3783
3784
  interface UdpFormsUi {
@@ -11690,7 +11691,7 @@ declare namespace LocalJSX {
11690
11691
  "formsBuilderUrlPath"?: string;
11691
11692
  "history"?: { push: (path: string) => void };
11692
11693
  /**
11693
- * @default true
11694
+ * @default false
11694
11695
  */
11695
11696
  "isCommentingConfigOn"?: boolean;
11696
11697
  /**
@@ -11824,6 +11825,7 @@ declare namespace LocalJSX {
11824
11825
  * @default {}
11825
11826
  */
11826
11827
  "urlContext"?: Record<string, any>;
11828
+ "urlTenantId"?: Guid | null;
11827
11829
  "version"?: number | null;
11828
11830
  }
11829
11831
  interface UdpFormsUi {
@@ -40,5 +40,5 @@ export declare const createFormData: (data: Record<string, any>) => FormData;
40
40
  * // Send entire object (not just the 'data' property)
41
41
  * await makeApiCall('POST', '/api/complex', complexObject, true);
42
42
  */
43
- export declare const makeApiCall: <T extends WrappedData | FormData>(method: HttpMethod, url: string, wrappedData?: T, useWrappedDataOnly?: boolean) => Promise<any>;
43
+ export declare const makeApiCall: <T extends WrappedData | FormData>(method: HttpMethod, url: string, wrappedData?: T, useWrappedDataOnly?: boolean, extraHeaders?: Record<string, string>) => Promise<any>;
44
44
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "udp-stencil-component-library",
3
- "version": "25.18.2-beta.11",
3
+ "version": "25.18.2-beta.13",
4
4
  "description": "A Stencil based component library for UDP",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -1 +0,0 @@
1
- import n from"axios";const o=n=>{const o=new FormData;return Object.entries(n).forEach((([n,t])=>{null!=t&&(t instanceof File||t instanceof Blob?o.append(n,t):Array.isArray(t)?t.forEach(((t,a)=>{t instanceof File||t instanceof Blob?o.append(`${n}[${a}]`,t):o.append(`${n}[${a}]`,String(t))})):o.append(n,String(t)))})),o},t=async(o,t,a,e=!1)=>{var l;const s=a instanceof FormData,c={};s||(c["Content-Type"]="application/json");let i=null;a&&(i=s||e?a:null!==(l=null==a?void 0:a.data)&&void 0!==l?l:a);const r={method:o,url:t,headers:c,timeout:3e5};["POST","PUT","PATCH"].includes(o)&&null!=i&&(r.data=s?i:JSON.stringify(i));try{const a=await n(r);return console.log(`${o} ${t} - Response:`,a.data),a.data}catch(n){throw console.error(`${o} ${t} - API call failed:`,n),n}};export{o as c,t as m}