udp-stencil-component-library 25.18.2-beta.10 → 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
@@ -6,8 +6,8 @@ var tenantUtils = require('./tenantUtils-BCKSE0vq.js');
6
6
  var udpFormApiUtils = require('./udp-form-api-utils-BwNeblH_.js');
7
7
  var enums = require('./enums-B3aaCQaV.js');
8
8
  var utils = require('./utils-Bp02BX38.js');
9
- var makeApiCall = require('./makeApiCall-CFfg9gI0.js');
10
- var SearchBuilder = require('./SearchBuilder-C1sUitjQ.js');
9
+ var makeApiCall = require('./makeApiCall-B9MMU_Ob.js');
10
+ var SearchBuilder = require('./SearchBuilder-DYM_FL5l.js');
11
11
  var configService = require('./configService-BmGAegZf.js');
12
12
  var uuid = require('uuid');
13
13
  require('axios');
@@ -165,8 +165,17 @@ class UdpFormSubmission {
165
165
  * comments use dedicated comment endpoints once a submission exists.
166
166
  */
167
167
  class FormSubmissionHandler {
168
- constructor(accessMode) {
168
+ constructor(accessMode, tenantId) {
169
169
  this.accessMode = accessMode;
170
+ this.tenantId = tenantId;
171
+ }
172
+ get extraHeaders() {
173
+ // Public endpoints require currentTenantId header.
174
+ if (this.accessMode !== 'public')
175
+ return undefined;
176
+ if (!this.tenantId)
177
+ return undefined;
178
+ return { currentTenantId: String(this.tenantId) };
170
179
  }
171
180
  async addComment(udpFormSubmission, comment) {
172
181
  if (!(udpFormSubmission === null || udpFormSubmission === void 0 ? void 0 : udpFormSubmission.id)) {
@@ -186,7 +195,7 @@ class FormSubmissionHandler {
186
195
  // Backend contract: PUT /UdpFormSubmission/{submissionId}/comments/{commentId}
187
196
  // Body: { value, sectionKey, questionKey }
188
197
  const url = `${configService.ConfigService.productV1ApiUrl}/UdpFormSubmission/${udpFormSubmission.id}/comments/${commentId}`;
189
- await makeApiCall.makeApiCall('PUT', url, { value, sectionKey, questionKey }, true);
198
+ await makeApiCall.makeApiCall('PUT', url, { value, sectionKey, questionKey }, true, this.extraHeaders);
190
199
  }
191
200
  async deleteComment(udpFormSubmission, args) {
192
201
  if (!(udpFormSubmission === null || udpFormSubmission === void 0 ? void 0 : udpFormSubmission.id)) {
@@ -195,7 +204,7 @@ class FormSubmissionHandler {
195
204
  const { commentId } = args;
196
205
  // Backend contract: DELETE /UdpFormSubmission/{submissionId}/comments/{commentId}
197
206
  const url = `${configService.ConfigService.productV1ApiUrl}/UdpFormSubmission/${udpFormSubmission.id}/comments/${commentId}`;
198
- await makeApiCall.makeApiCall('DELETE', url, null, true);
207
+ await makeApiCall.makeApiCall('DELETE', url, null, true, this.extraHeaders);
199
208
  }
200
209
  async fetchAndPopulateUdpFormSubmissionObj(udpFormSubmission) {
201
210
  if (!(udpFormSubmission === null || udpFormSubmission === void 0 ? void 0 : udpFormSubmission.id)) {
@@ -234,7 +243,7 @@ class FormSubmissionHandler {
234
243
  async saveFormDataWithoutValues(udpFormSubmission, status) {
235
244
  const formData = udpFormSubmission.processSubmissionIntoFormDataWithoutValues(status);
236
245
  const { method, url } = this.getApiRequestInfo(udpFormSubmission);
237
- const response = await makeApiCall.makeApiCall(method, url, formData, true);
246
+ const response = await makeApiCall.makeApiCall(method, url, formData, true, this.extraHeaders);
238
247
  if (response === '') {
239
248
  return await this.fetchAndPopulateUdpFormSubmissionObj(udpFormSubmission);
240
249
  }
@@ -254,7 +263,7 @@ class FormSubmissionHandler {
254
263
  async saveSubmissionToDB(values, udpFormSubmission, status) {
255
264
  const formData = udpFormSubmission.processSubmissionIntoFormData(values, status);
256
265
  const { method, url } = this.getApiRequestInfo(udpFormSubmission);
257
- const response = await makeApiCall.makeApiCall(method, url, formData, true);
266
+ const response = await makeApiCall.makeApiCall(method, url, formData, true, this.extraHeaders);
258
267
  if (response === '') {
259
268
  return await this.fetchAndPopulateUdpFormSubmissionObj(udpFormSubmission);
260
269
  }
@@ -296,8 +305,8 @@ class FormSubmissionHandler {
296
305
  * Factory for creating form submission handlers.
297
306
  */
298
307
  class FormSubmissionHandlerFactory {
299
- static create(isPublic, userId) {
300
- return new FormSubmissionHandler(isPublic ? 'public' : 'private');
308
+ static create(isPublic, userId, currentTenantId) {
309
+ return new FormSubmissionHandler(isPublic ? 'public' : 'private', currentTenantId !== null && currentTenantId !== void 0 ? currentTenantId : undefined);
301
310
  }
302
311
  }
303
312
 
@@ -308,16 +317,16 @@ class UdpFormHandler {
308
317
  }
309
318
  buildDescribeUrl(formId, formVersion) {
310
319
  const base = configService.ConfigService.productV1ApiUrl;
311
- if (this.isPublic) {
312
- return `${base}/UdpForm/${formId}/${formVersion}/describe/public`;
313
- }
314
- else {
315
- return `${base}/UdpForm/${formId}/${formVersion}/describe`;
316
- }
320
+ const versionSegment = typeof formVersion === 'number' ? `/${formVersion}` : '';
321
+ return this.isPublic
322
+ ? `${base}/UdpForm/${formId}${versionSegment}/describe/public`
323
+ : `${base}/UdpForm/${formId}${versionSegment}/describe`;
317
324
  }
318
325
  async getFormByFormIdAndFormVersion(formId, formVersion) {
319
326
  const url = this.buildDescribeUrl(formId, formVersion);
320
- const formData = await makeApiCall.makeApiCall('GET', url);
327
+ // For public endpoints, backend requires currentTenantId in the header.
328
+ const extraHeaders = this.isPublic && this.tenantId ? { currentTenantId: String(this.tenantId) } : undefined;
329
+ const formData = await makeApiCall.makeApiCall('GET', url, undefined, false, extraHeaders);
321
330
  if (formData.styleOverrides && typeof formData.styleOverrides === 'string') {
322
331
  formData.styleOverrides = JSON.parse(formData.styleOverrides);
323
332
  }
@@ -1080,6 +1089,15 @@ const UdpFormsRenderer = class {
1080
1089
  var _a;
1081
1090
  this.isLoading = true;
1082
1091
  try {
1092
+ // Public forms require currentTenantId in request headers. It must be provided via URL param.
1093
+ if (this.isPublic) {
1094
+ const params = new URLSearchParams(window.location.search);
1095
+ const currentTenantId = params.get('udpf_currentTenantId');
1096
+ if (!currentTenantId) {
1097
+ throw new Error('Public form renderer requires currentTenantId in the URL query string.');
1098
+ }
1099
+ this.tenantId = currentTenantId;
1100
+ }
1083
1101
  // Get client user info if available
1084
1102
  if (this.isPublic) {
1085
1103
  this.clientUserInfo.id = '00000000-0000-0000-0000-000000000001';
@@ -1093,7 +1111,7 @@ const UdpFormsRenderer = class {
1093
1111
  this.clientUserInfo.email = user.email || null;
1094
1112
  }
1095
1113
  }
1096
- this.formSubmissionHandler = FormSubmissionHandlerFactory.create(this.isPublic, this.clientUserInfo.id);
1114
+ this.formSubmissionHandler = FormSubmissionHandlerFactory.create(this.isPublic, this.clientUserInfo.id, this.tenantId);
1097
1115
  this.udpFormSubmission = new UdpFormSubmission({ 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 });
1098
1116
  // fetch existing submission from Udp.FormSubmission if submissionId is provided
1099
1117
  // take exisitng object, and populate with db values, and return new obj with updated values
@@ -1112,7 +1130,7 @@ const UdpFormsRenderer = class {
1112
1130
  formId = this.formId;
1113
1131
  formVersion = this.version;
1114
1132
  }
1115
- this.formHandler = new UdpFormHandler(this.tenantId);
1133
+ this.formHandler = new UdpFormHandler(this.tenantId, this.isPublic);
1116
1134
  const formData = await this.formHandler.getFormByFormIdAndFormVersion(formId, formVersion);
1117
1135
  this.udpForm = new UdpForm(formData);
1118
1136
  this.currentValues = utils.buildEmptyCurrentValues(this.udpForm);
@@ -1326,7 +1344,7 @@ const UdpFormsRenderer = class {
1326
1344
  return this.isSubmitted || this.udpFormSubmission.unityUserId !== this.clientUserInfo.id;
1327
1345
  }
1328
1346
  render() {
1329
- return (index.h("div", { key: '37ec47fc7f3ecec70ba7ca3e12717789285be5d8', class: "forms-renderer-container", style: this.isLoading ? { minHeight: '100vh' } : {} }, this.renderFollowUpSideSheet(), index.h("udp-forms-ui", { udpForm: this.udpForm, currentValues: this.currentValues, udpFormSubmission: this.udpFormSubmission, submitSuccessful: this.submitSuccessful, isSaving: this.isSaving,
1347
+ return (index.h("div", { key: 'f53b65027554505a1301ab98379035e0316735dc', class: "forms-renderer-container", style: this.isLoading ? { minHeight: '100vh' } : {} }, this.renderFollowUpSideSheet(), index.h("udp-forms-ui", { udpForm: this.udpForm, currentValues: this.currentValues, udpFormSubmission: this.udpFormSubmission, submitSuccessful: this.submitSuccessful, isSaving: this.isSaving,
1330
1348
  // saveErrorMessage={this.saveErrorMessage}
1331
1349
  // showAutoSaveStatus={this.formSubmissionHandler.supportsAutoSave() && !!this.userId}
1332
1350
  readonly: this.isReadOnlyMode, handleSubmit: this.handleSubmit.bind(this), handleSave: values => Promise.resolve(this.debouncedManualSave(values)), 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 })));
@@ -22,9 +22,9 @@ import { styleOverrideDefault, formSectionDefault, formMetadataDefault, deepClon
22
22
  import { UdpFormsPageIdEnum, UdpFormsTypeEnum } from "../udp-forms-utils/enums";
23
23
  export class UdpFormsBuilder {
24
24
  constructor() {
25
- this.isFollowUpFormConfigOn = false; // allow form engine to use follow-up forms feature
26
- this.isPublicFormConfigOn = false; // allow form engine to use public forms feature
27
- this.isCommentingConfigOn = true; // allow form engine to use commenting feature
25
+ this.isFollowUpFormConfigOn = false; // allow form engine to use follow-up forms feature, default is false
26
+ this.isPublicFormConfigOn = false; // allow form engine to use public forms feature, default is false
27
+ this.isCommentingConfigOn = false; // allow form engine to use commenting feature, default is false
28
28
  this.formsBuilderUrlPath = ''; // alternative path for redirect to the form builder page. If not provided, use default path.
29
29
  this.formMetadata = formMetadataDefault;
30
30
  this.formSections = [];
@@ -769,7 +769,7 @@ export class UdpFormsBuilder {
769
769
  "setter": false,
770
770
  "reflect": false,
771
771
  "attribute": "is-commenting-config-on",
772
- "defaultValue": "true"
772
+ "defaultValue": "false"
773
773
  },
774
774
  "formsBuilderUrlPath": {
775
775
  "type": "string",
@@ -263,6 +263,15 @@ export class UdpFormsRenderer {
263
263
  var _a;
264
264
  this.isLoading = true;
265
265
  try {
266
+ // Public forms require currentTenantId in request headers. It must be provided via URL param.
267
+ if (this.isPublic) {
268
+ const params = new URLSearchParams(window.location.search);
269
+ const currentTenantId = params.get('udpf_currentTenantId');
270
+ if (!currentTenantId) {
271
+ throw new Error('Public form renderer requires currentTenantId in the URL query string.');
272
+ }
273
+ this.tenantId = currentTenantId;
274
+ }
266
275
  // Get client user info if available
267
276
  if (this.isPublic) {
268
277
  this.clientUserInfo.id = '00000000-0000-0000-0000-000000000001';
@@ -276,7 +285,7 @@ export class UdpFormsRenderer {
276
285
  this.clientUserInfo.email = user.email || null;
277
286
  }
278
287
  }
279
- this.formSubmissionHandler = FormSubmissionHandlerFactory.create(this.isPublic, this.clientUserInfo.id);
288
+ this.formSubmissionHandler = FormSubmissionHandlerFactory.create(this.isPublic, this.clientUserInfo.id, this.tenantId);
280
289
  this.udpFormSubmission = new UdpFormSubmission({ 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 });
281
290
  // fetch existing submission from Udp.FormSubmission if submissionId is provided
282
291
  // take exisitng object, and populate with db values, and return new obj with updated values
@@ -295,7 +304,7 @@ export class UdpFormsRenderer {
295
304
  formId = this.formId;
296
305
  formVersion = this.version;
297
306
  }
298
- this.formHandler = new UdpFormHandler(this.tenantId);
307
+ this.formHandler = new UdpFormHandler(this.tenantId, this.isPublic);
299
308
  const formData = await this.formHandler.getFormByFormIdAndFormVersion(formId, formVersion);
300
309
  this.udpForm = new UdpForm(formData);
301
310
  this.currentValues = buildEmptyCurrentValues(this.udpForm);
@@ -509,7 +518,7 @@ export class UdpFormsRenderer {
509
518
  return this.isSubmitted || this.udpFormSubmission.unityUserId !== this.clientUserInfo.id;
510
519
  }
511
520
  render() {
512
- return (h("div", { key: '37ec47fc7f3ecec70ba7ca3e12717789285be5d8', class: "forms-renderer-container", style: this.isLoading ? { minHeight: '100vh' } : {} }, this.renderFollowUpSideSheet(), h("udp-forms-ui", { udpForm: this.udpForm, currentValues: this.currentValues, udpFormSubmission: this.udpFormSubmission, submitSuccessful: this.submitSuccessful, isSaving: this.isSaving,
521
+ return (h("div", { key: 'f53b65027554505a1301ab98379035e0316735dc', class: "forms-renderer-container", style: this.isLoading ? { minHeight: '100vh' } : {} }, this.renderFollowUpSideSheet(), h("udp-forms-ui", { udpForm: this.udpForm, currentValues: this.currentValues, udpFormSubmission: this.udpFormSubmission, submitSuccessful: this.submitSuccessful, isSaving: this.isSaving,
513
522
  // saveErrorMessage={this.saveErrorMessage}
514
523
  // showAutoSaveStatus={this.formSubmissionHandler.supportsAutoSave() && !!this.userId}
515
524
  readonly: this.isReadOnlyMode, handleSubmit: this.handleSubmit.bind(this), handleSave: values => Promise.resolve(this.debouncedManualSave(values)), 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 })));
@@ -563,6 +572,32 @@ export class UdpFormsRenderer {
563
572
  "reflect": false,
564
573
  "attribute": "version"
565
574
  },
575
+ "urlTenantId": {
576
+ "type": "string",
577
+ "mutable": false,
578
+ "complexType": {
579
+ "original": "Guid | null",
580
+ "resolved": "string",
581
+ "references": {
582
+ "Guid": {
583
+ "location": "import",
584
+ "path": "src/global/types",
585
+ "id": "src/global/types.ts::Guid",
586
+ "referenceLocation": "Guid"
587
+ }
588
+ }
589
+ },
590
+ "required": false,
591
+ "optional": true,
592
+ "docs": {
593
+ "tags": [],
594
+ "text": ""
595
+ },
596
+ "getter": false,
597
+ "setter": false,
598
+ "reflect": false,
599
+ "attribute": "url-tenant-id"
600
+ },
566
601
  "submissionId": {
567
602
  "type": "string",
568
603
  "mutable": false,
@@ -7,16 +7,16 @@ export class UdpFormHandler {
7
7
  }
8
8
  buildDescribeUrl(formId, formVersion) {
9
9
  const base = ConfigService.productV1ApiUrl;
10
- if (this.isPublic) {
11
- return `${base}/UdpForm/${formId}/${formVersion}/describe/public`;
12
- }
13
- else {
14
- return `${base}/UdpForm/${formId}/${formVersion}/describe`;
15
- }
10
+ const versionSegment = typeof formVersion === 'number' ? `/${formVersion}` : '';
11
+ return this.isPublic
12
+ ? `${base}/UdpForm/${formId}${versionSegment}/describe/public`
13
+ : `${base}/UdpForm/${formId}${versionSegment}/describe`;
16
14
  }
17
15
  async getFormByFormIdAndFormVersion(formId, formVersion) {
18
16
  const url = this.buildDescribeUrl(formId, formVersion);
19
- const formData = await makeApiCall('GET', url);
17
+ // For public endpoints, backend requires currentTenantId in the header.
18
+ const extraHeaders = this.isPublic && this.tenantId ? { currentTenantId: String(this.tenantId) } : undefined;
19
+ const formData = await makeApiCall('GET', url, undefined, false, extraHeaders);
20
20
  if (formData.styleOverrides && typeof formData.styleOverrides === 'string') {
21
21
  formData.styleOverrides = JSON.parse(formData.styleOverrides);
22
22
  }
@@ -13,8 +13,17 @@ import { UdpFormsSubmissionStatusEnum } from "../enums";
13
13
  * comments use dedicated comment endpoints once a submission exists.
14
14
  */
15
15
  export class FormSubmissionHandler {
16
- constructor(accessMode) {
16
+ constructor(accessMode, tenantId) {
17
17
  this.accessMode = accessMode;
18
+ this.tenantId = tenantId;
19
+ }
20
+ get extraHeaders() {
21
+ // Public endpoints require currentTenantId header.
22
+ if (this.accessMode !== 'public')
23
+ return undefined;
24
+ if (!this.tenantId)
25
+ return undefined;
26
+ return { currentTenantId: String(this.tenantId) };
18
27
  }
19
28
  async addComment(udpFormSubmission, comment) {
20
29
  if (!(udpFormSubmission === null || udpFormSubmission === void 0 ? void 0 : udpFormSubmission.id)) {
@@ -34,7 +43,7 @@ export class FormSubmissionHandler {
34
43
  // Backend contract: PUT /UdpFormSubmission/{submissionId}/comments/{commentId}
35
44
  // Body: { value, sectionKey, questionKey }
36
45
  const url = `${ConfigService.productV1ApiUrl}/UdpFormSubmission/${udpFormSubmission.id}/comments/${commentId}`;
37
- await makeApiCall('PUT', url, { value, sectionKey, questionKey }, true);
46
+ await makeApiCall('PUT', url, { value, sectionKey, questionKey }, true, this.extraHeaders);
38
47
  }
39
48
  async deleteComment(udpFormSubmission, args) {
40
49
  if (!(udpFormSubmission === null || udpFormSubmission === void 0 ? void 0 : udpFormSubmission.id)) {
@@ -43,7 +52,7 @@ export class FormSubmissionHandler {
43
52
  const { commentId } = args;
44
53
  // Backend contract: DELETE /UdpFormSubmission/{submissionId}/comments/{commentId}
45
54
  const url = `${ConfigService.productV1ApiUrl}/UdpFormSubmission/${udpFormSubmission.id}/comments/${commentId}`;
46
- await makeApiCall('DELETE', url, null, true);
55
+ await makeApiCall('DELETE', url, null, true, this.extraHeaders);
47
56
  }
48
57
  async fetchAndPopulateUdpFormSubmissionObj(udpFormSubmission) {
49
58
  if (!(udpFormSubmission === null || udpFormSubmission === void 0 ? void 0 : udpFormSubmission.id)) {
@@ -82,7 +91,7 @@ export class FormSubmissionHandler {
82
91
  async saveFormDataWithoutValues(udpFormSubmission, status) {
83
92
  const formData = udpFormSubmission.processSubmissionIntoFormDataWithoutValues(status);
84
93
  const { method, url } = this.getApiRequestInfo(udpFormSubmission);
85
- const response = await makeApiCall(method, url, formData, true);
94
+ const response = await makeApiCall(method, url, formData, true, this.extraHeaders);
86
95
  if (response === '') {
87
96
  return await this.fetchAndPopulateUdpFormSubmissionObj(udpFormSubmission);
88
97
  }
@@ -102,7 +111,7 @@ export class FormSubmissionHandler {
102
111
  async saveSubmissionToDB(values, udpFormSubmission, status) {
103
112
  const formData = udpFormSubmission.processSubmissionIntoFormData(values, status);
104
113
  const { method, url } = this.getApiRequestInfo(udpFormSubmission);
105
- const response = await makeApiCall(method, url, formData, true);
114
+ const response = await makeApiCall(method, url, formData, true, this.extraHeaders);
106
115
  if (response === '') {
107
116
  return await this.fetchAndPopulateUdpFormSubmissionObj(udpFormSubmission);
108
117
  }
@@ -3,7 +3,7 @@ import { FormSubmissionHandler } from "./FormSubmissionHandler";
3
3
  * Factory for creating form submission handlers.
4
4
  */
5
5
  export class FormSubmissionHandlerFactory {
6
- static create(isPublic, userId) {
7
- return new FormSubmissionHandler(isPublic ? 'public' : 'private');
6
+ static create(isPublic, userId, currentTenantId) {
7
+ return new FormSubmissionHandler(isPublic ? 'public' : 'private', currentTenantId !== null && currentTenantId !== void 0 ? currentTenantId : undefined);
8
8
  }
9
9
  }
@@ -60,7 +60,7 @@ export const createFormData = (data) => {
60
60
  * // Send entire object (not just the 'data' property)
61
61
  * await makeApiCall('POST', '/api/complex', complexObject, true);
62
62
  */
63
- export const makeApiCall = async (method, url, wrappedData, useWrappedDataOnly = false) => {
63
+ export const makeApiCall = async (method, url, wrappedData, useWrappedDataOnly = false, extraHeaders) => {
64
64
  var _a;
65
65
  // Check if the data is FormData
66
66
  const isFormData = wrappedData instanceof FormData;
@@ -69,6 +69,9 @@ export const makeApiCall = async (method, url, wrappedData, useWrappedDataOnly =
69
69
  if (!isFormData) {
70
70
  headers['Content-Type'] = 'application/json';
71
71
  }
72
+ if (extraHeaders) {
73
+ Object.assign(headers, extraHeaders);
74
+ }
72
75
  // Uncomment when authentication is needed
73
76
  // headers.Authorization = `Bearer ${accessToken}`;
74
77
  // Extract the actual data to send
@@ -1 +1 @@
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}
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,e)=>{t instanceof File||t instanceof Blob?o.append(`${n}[${e}]`,t):o.append(`${n}[${e}]`,String(t))})):o.append(n,String(t)))})),o},t=async(o,t,e,a=!1,l)=>{var c;const s=e instanceof FormData,i={};s||(i["Content-Type"]="application/json"),l&&Object.assign(i,l);let r=null;e&&(r=s||a?e:null!==(c=null==e?void 0:e.data)&&void 0!==c?c:e);const u={method:o,url:t,headers:i,timeout:3e5};["POST","PUT","PATCH"].includes(o)&&null!=r&&(u.data=s?r:JSON.stringify(r));try{const e=await n(u);return console.log(`${o} ${t} - Response:`,e.data),e.data}catch(n){throw console.error(`${o} ${t} - API call failed:`,n),n}};export{o as c,t as m}
@@ -1 +1 @@
1
- import{p as t,H as e,h as i,t as s}from"./index2.js";import{m as o}from"./makeApiCall.js";import{q as r,d as n}from"./question-specific-configs-renderer2.js";import{g as a,d as c}from"./udp-icon2.js";import{g as d}from"./tenantUtils.js";import l from"sortablejs";import{v4 as u}from"uuid";import{f as m,d as h,a as p,s as f}from"./forms-builder-utils.js";import{b,a as g}from"./enums.js";import{d as v}from"./custom-button2.js";import{d as y}from"./date-time-renderer2.js";import{d as j}from"./file-upload-renderer2.js";import{d as O}from"./fluent-dialog2.js";import{d as k}from"./form-metadata-display-renderer2.js";import{d as x}from"./list-options-renderer2.js";import{d as E}from"./numeric-field2.js";import{d as C}from"./primary-action-header2.js";import{d as q}from"./question-configs-renderer2.js";import{d as S}from"./section-configs-renderer2.js";import{d as w}from"./signature-renderer2.js";import{d as F}from"./stencil-chip2.js";import{d as I}from"./stencil-icon-button2.js";import{d as T}from"./stencil-toggle2.js";import{d as D}from"./text-area2.js";import{d as N}from"./text-field2.js";import{d as P}from"./text-input-renderer2.js";import{d as U}from"./udp-ambient-tool-tip2.js";import{d as B}from"./udp-avatar2.js";import{d as V}from"./udp-badge2.js";import{d as A}from"./udp-button2.js";import{d as Q}from"./udp-container2.js";import{d as $}from"./udp-date-selector2.js";import{d as z}from"./udp-datetime-selector2.js";import{d as M}from"./udp-forms-builder-menu2.js";import{d as J}from"./udp-forms-builder-question-item2.js";import{d as L}from"./udp-linear-loader2.js";import{d as _}from"./udp-menu-item2.js";import{d as G}from"./udp-pop-over2.js";import{d as W}from"./udp-selector2.js";import{d as R}from"./udp-side-sheet2.js";import{d as H}from"./udp-tabs2.js";import{d as K}from"./udp-time-selector2.js";import{d as X}from"./unity-typography2.js";import{C as Y}from"./configService.js";const Z=t(class extends e{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.isFollowUpFormConfigOn=!1,this.isPublicFormConfigOn=!1,this.isCommentingConfigOn=!0,this.formsBuilderUrlPath="",this.formMetadata=m,this.formSections=[],this.formSectionsDraft=[],this.isNewForm=!0,this.isMostRecentFormVersion=!1,this.isError=!1,this.isLoading=!1,this.isShowStyleOverrides=!1,this.isStyleSheetOpen=!1,this.isDialogOpen=!1,this.showMenuAtIndex=null,this.editingQuestion=null,this.editingSection=null,this.isQuestionEditorOpen=!1,this.isSectionEditorOpen=!1,this.lookupOptionsDataProcessed=[],this.dialogAction=null,this.dialogMessage="Are you sure you want to delete this?",this.sortableInstances=[],this.formsBuilderPageId=b.FormBuilderPageId,this.formTypeOptions=Object.keys(g).filter((t=>isNaN(Number(t)))).map((t=>({value:g[t]+"",label:t}))),this.toggleStyleSheet=()=>{this.isStyleSheetOpen=!this.isStyleSheetOpen},this.getQuestionTypeName=t=>{const e=r.find((e=>e.fieldTypeId===t));return e?e.questionTypeName:"Unknown"},this.getIsContainsOptionItems=t=>{const e=r.find((e=>e.fieldTypeId===t));return e&&e.isContainsOptionItems||!1},this.getIconForQuestion=t=>{const e=r.find((e=>e.fieldTypeId===t));return e?e.icon:null},this.handleQuestionDelete=(t,e)=>{const i=h(this.formSections);i[t].formQuestions.splice(e,1),this.formSections=i},this.handleQuestionCopy=(t,e)=>{const i=h(this.formSections),s=this.formSections[t].formQuestions[e],o=Object.assign(Object.assign({},s),{questionText:(s.questionText||"")+" (Copy)",id:u()});i[t].formQuestions.splice(e+1,0,o),this.formSections=i},this.handleQuestionClick=(t,e)=>{this.editingQuestion={sIndex:t,qIndex:e},this.isQuestionEditorOpen=!0,this.formSectionsDraft=h(this.formSections)},this.closeQuestionEditor=()=>{this.isQuestionEditorOpen=!1,this.editingQuestion=null,this.formSectionsDraft=null},this.addQuestionOfType=(t,e,i)=>{const s={questionTypeName:t.questionTypeName,fieldTypeId:t.fieldTypeId,fieldProperties:t.defaultFieldProperties,helperText:"",questionText:"",section:void 0!==e?e+1:this.formSections.length>0?this.formSections[this.formSections.length-1].formQuestions[0].section:1,isContainsOptionItems:t.isContainsOptionItems,icon:t.icon,required:!1,form:null,isPrivate:!0,id:u()},o=h(this.formSections);let r=e,n=i;if(void 0!==e&&void 0!==i)if(o[e].formQuestions)o[e].formQuestions.splice(i,0,s);else{const t=o.length-1;o[t].formQuestions.push(s),r=t,n=o[t].formQuestions.length-1}else{const t=o.length-1;t<0||0===o[t].formQuestions.length?(o.push(Object.assign(Object.assign({},p),{formQuestions:[s]})),r=o.length-1,n=0):(o[t].formQuestions.push(s),r=t,n=o[t].formQuestions.length-1)}return this.formSectionsDraft=o,this.showMenuAtIndex&&(this.showMenuAtIndex=null),{sIndex:r,qIndex:n}},this.handleSectionMoveDown=t=>{if(t>=this.formSections.length-1)return;const e=[...this.formSections];[e[t],e[t+1]]=[e[t+1],e[t]],this.formSections=e},this.handleSectionMoveUp=t=>{if(t<=0)return;const e=[...this.formSections];[e[t],e[t-1]]=[e[t-1],e[t]],this.formSections=e},this.handleSectionDelete=t=>{const e=[...this.formSections];e.splice(t,1),this.formSections=e},this.updateFormSectionsWithDraft=()=>{this.formSections=this.formSectionsDraft,this.formSectionsDraft=null},this.hasUnsavedFormSectionsChanges=()=>JSON.stringify(this.formSections)!==JSON.stringify(this.formSectionsDraft),this.handleSectionEditClick=t=>{this.editingSection={sIndex:t},this.isSectionEditorOpen=!0,this.formSectionsDraft=h(this.formSections)},this.closeSectionEditor=()=>{this.isSectionEditorOpen=!1,this.editingSection=null,this.formSectionsDraft=null}}async initializeForm(){this.formMetadata.isPrivate=m.isPrivate,this.formMetadata.tenantId=d(),this.formMetadata.type=m.type,this.formMetadata.version=m.version,this.formMetadata.name=m.name,this.formMetadata.description=m.description,this.formMetadata.styleOverrides=f;try{this.isLoading=!0;const t=await o("GET",Y.productV1ApiUrl+"/UdpLookup");if(!t)throw Error("Error fetching lookup data");if(this.lookupOptionsDataProcessed=t.map((t=>Object.assign(Object.assign({},t),{value:t.id,label:t.name}))),this.formId&&this.version){const t=await o("GET",`${Y.productV1ApiUrl}/UdpForm/${this.formId}/${this.version}/describe`),e=await o("GET",`${Y.productV1ApiUrl}/UdpForm/${this.formId}/describe`);if(this.isNewForm=!1,!(t&&e&&t.id&&e))throw Error("Error fetching form data");t.id==e.id&&t.version==e.version&&(this.isMostRecentFormVersion=!0);const i=structuredClone(t.udpFormUdpFormSection).map((t=>Object.assign(Object.assign({},t),{formQuestions:[]})));i.forEach((t=>{t.sectionProperties=t.sectionProperties?JSON.parse(t.sectionProperties):{}})),t.formQuestions.forEach((t=>{const e=i.find((e=>e.id===t.formSectionId));if(e){const i=Object.assign({},t.fieldProperties);"lookupId"in i&&"items"in i&&delete i.items,e.formQuestions.push(Object.assign(Object.assign({},t),{fieldProperties:i,questionTypeName:this.getQuestionTypeName(t.fieldTypeId),isContainsOptionItems:this.getIsContainsOptionItems(t.fieldTypeId),icon:this.getIconForQuestion(t.fieldTypeId)}))}})),i.forEach((t=>{t.formQuestions.sort(((t,e)=>t.questionOrder-e.questionOrder))})),i.sort(((t,e)=>t.order-e.order));const s=function(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(t);o<s.length;o++)e.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(t,s[o])&&(i[s[o]]=t[s[o]])}return i}(t,[]);s.styleOverrides=this.deepMerge(f,JSON.parse(s.styleOverrides)||{}),this.formMetadata=s,this.formSections=i,this.isLoading=!1}}catch(t){this.isError=!0,this.enqueueSnackbar("Error loading form data",{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}})}finally{this.isLoading=!1}}async submitForm(){if(this.isValidForm()){this.isLoading=!0;try{const t={name:this.formMetadata.name,description:this.formMetadata.description,tenantId:this.formMetadata.tenantId,isPrivate:this.formMetadata.isPrivate,type:this.formMetadata.type,styleOverrides:JSON.stringify(this.formMetadata.styleOverrides),id:this.formMetadata.id,version:this.formMetadata.version},e=`${Y.productV1ApiUrl}/UdpForm${this.isMostRecentFormVersion?"/versions":""}`,i=await o("POST",e,t),s=i.id,r=i.version;if(!i||!i.id||!i.version)throw Error("Invalid form response: "+JSON.stringify(i));let n=0,a=0;const c=[];for(const[t,e]of this.formSections.entries()){n+=1;const i=Object.assign(Object.assign({},e),{formId:s,formVersion:r,order:n,sectionProperties:JSON.stringify(e.sectionProperties),name:"section"+n}),d=await o("POST",Y.productV1ApiUrl+"/UdpFormSection",i);if(!d||!d.id)throw Error("Invalid section response: "+JSON.stringify(d));const l=d.id;for(const i of e.formQuestions){a+=1;const e=Object.assign(Object.assign({},i),{formId:s,formVersion:r,section:t+1,questionOrder:a,formSectionId:l,name:"question"+a}),n=o("POST",Y.productV1ApiUrl+"/UdpFormQuestion",e);c.push(n)}}if(await Promise.all(c),this.enqueueSnackbar("Success",{variant:"success",anchorOrigin:{vertical:"top",horizontal:"center"}}),this.formsBuilderUrlPath)return void this.history.push(`${this.formsBuilderUrlPath}&udpf_formId=${s}&udpf_version=${r}`);this.history.push(`/page/${this.formsBuilderPageId}?udpf_formId=${s}&udpf_version=${r}`)}catch(t){console.error("Form submission error:",t),this.enqueueSnackbar("Error saving form",{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}})}finally{this.isLoading=!1}}}componentDidLoad(){this.initializeSortable()}componentDidUpdate(){this.initializeSortable()}componentWillLoad(){this.initializeForm()}onFormIdOrVersionChange(){this.initializeForm()}initializeSortable(){(this.isNewForm||this.isMostRecentFormVersion)&&(this.sortableInstances.forEach((t=>t.destroy())),this.sortableInstances=[],this.formSections.forEach(((t,e)=>{const i=this.hostEl.shadowRoot.querySelector("#section-"+e);if(i){const t=new l(i,{animation:200,easing:"cubic-bezier(0.25, 1, 0.5, 1)",draggable:"udp-forms-builder-question-item",handle:".form-question-drag-handle",ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",direction:"vertical",forceFallback:!1,dragoverBubble:!1,swapThreshold:.6,onEnd:t=>this.handleDragEnd(t,e)});this.sortableInstances.push(t)}})))}handleDragEnd(t,e){const i=t.oldIndex,s=t.newIndex;if(i===s||null==i||null==s)return;const o=structuredClone(this.formSections[e]),[r]=o.formQuestions.splice(i,1);o.formQuestions.splice(s,0,r);const n=h(this.formSections);n[e]=o,this.formSections=n}deepMerge(t,e){const i=Object.assign({},t);for(const s in e)i[s]=e[s]&&"object"==typeof e[s]&&!Array.isArray(e[s])?this.deepMerge(t[s]||{},e[s]):e[s];return i}isValidForm(){return this.validateFormMetadata()&&this.validateFormSections()&&this.validateAllQuestions()}validateFormMetadata(){var t;return!!(null===(t=this.formMetadata.name)||void 0===t?void 0:t.trim())||(this.enqueueSnackbar("Please enter a form name.",{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}}),!1)}validateFormSections(){if(this.formSections.length<1)return this.enqueueSnackbar("Please add at least one section to the form.",{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}}),!1;for(let t=0;t<this.formSections.length;t++){const e=this.formSections[t];if(((null==e?void 0:e.formQuestions)||[]).length<1)return this.enqueueSnackbar(`Section ${(null==e?void 0:e.title)?`"${e.title}"`:"#"+(t+1)} must contain at least one question.`,{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}}),!1}return!0}validateAllQuestions(){for(let t=0;t<this.formSections.length;t++){const e=this.formSections[t],i=(null==e?void 0:e.formQuestions)||[];for(let e=0;e<i.length;e++)if(!this.validateQuestionItem(t,e))return this.enqueueSnackbar("Please validate all questions.",{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}}),!1}return!0}validateQuestionItem(t,e){const i=this.formSections[t].formQuestions[e],s=r.find((t=>t.fieldTypeId===i.fieldTypeId));if(!(s&&s.questionTextOptional||i.questionText))return!1;if(i.isContainsOptionItems){const t=i.fieldProperties;if(!(null==t?void 0:t.lookupId)){if(!Array.isArray(null==t?void 0:t.items)||0===t.items.length)return!1;if(t.items.some((t=>!t.display||!t.value)))return!1}}return!0}render(){if(this.isError)return i("div",null," There is an Error With the Form Builder");const t=this.isNewForm||this.isMostRecentFormVersion;return i("div",null,i("primary-action-header",{title:"UDP Form Builder",actionButtonLabel:t?this.isMostRecentFormVersion?`Create New Version (v.${this.version+1})`:"Create New Form":"",primaryActionClick:t?()=>this.submitForm():null,defaultActionButtons:t?[{label:"Style Overrides",clickHandler:this.toggleStyleSheet,tooltip:"Style Overrides",visible:!1,icon:a("settings")}]:[],tabs:!1}),i("udp-side-sheet",{open:this.isQuestionEditorOpen,onUdpSideSheetClose:()=>this.closeQuestionEditor(),onUdpPrimaryButtonClick:()=>{this.hasUnsavedFormSectionsChanges()&&(this.updateFormSectionsWithDraft(),this.closeQuestionEditor())},primaryButtonDisabled:!this.hasUnsavedFormSectionsChanges(),title:"Edit Question",position:"right",width:"md",primaryButtonLabel:"Update"},this.isQuestionEditorOpen&&i("div",{class:"question-editor-container"},i("question-configs-renderer",{formSectionsDraft:this.formSectionsDraft,sIndex:this.editingQuestion.sIndex,qIndex:this.editingQuestion.qIndex,isViewOnly:!t,onFormSectionsDraftChange:t=>this.formSectionsDraft=t,lookupOptions:this.lookupOptionsDataProcessed,formType:this.formMetadata.type,isFollowUpFormConfigOn:this.isFollowUpFormConfigOn,isCommentingConfigOn:this.isCommentingConfigOn}))),i("udp-side-sheet",{open:this.isSectionEditorOpen,onUdpSideSheetClose:()=>this.closeSectionEditor(),title:"Edit Section Fields",position:"right",width:"md",primaryButtonDisabled:!this.hasUnsavedFormSectionsChanges(),primaryButtonLabel:"Update",onUdpPrimaryButtonClick:()=>{this.hasUnsavedFormSectionsChanges()&&(this.updateFormSectionsWithDraft(),this.closeSectionEditor())}},this.isSectionEditorOpen&&i("div",{class:"section-editor-container"},i("section-configs-renderer",{formSectionsDraft:this.formSectionsDraft,sIndex:this.editingSection.sIndex,isViewOnly:!t,onFormSectionsDraftChange:t=>this.formSectionsDraft=t}))),i("fluent-dialog",{open:this.isDialogOpen,message:this.dialogMessage,labelOne:"Confirm",labelTwo:"Cancel",actionOne:()=>{"function"==typeof this.dialogAction&&this.dialogAction()},actionTwo:()=>this.isDialogOpen=!1}),this.isLoading&&i("udp-linear-loader",null),!this.isLoading&&i("udp-container",{maxWidth:"lg"},i("div",{class:"udp-forms-page"},i("div",{class:"form-details-container"},i("div",{class:"form-details-name-container"},t?i("div",{class:"form-details-name-input"},i("text-field",{label:"Form Name",value:this.formMetadata.name,placeholder:"Form Name",disabled:!t,required:!0,margin:"none",maxCharacter:128,onInput:t=>{this.formMetadata=Object.assign(Object.assign({},this.formMetadata),{name:t.target.value})}})):i("div",{class:"form-details-name-display"},i("unity-typography",{variant:"h2"},this.formMetadata.name+" (View Only)"))),i("div",{class:"form-details-description-container"},t?i("div",{class:"form-details-details-input"},i("text-area",{label:"Form Description",value:this.formMetadata.description,placeholder:"Form Description",disabled:!t,required:!1,margin:"none",maxCharacter:256,onInput:t=>{this.formMetadata=Object.assign(Object.assign({},this.formMetadata),{description:t.target.value})}})):i("div",{class:"form-details-description-display"},i("unity-typography",null,this.formMetadata.description))),this.isFollowUpFormConfigOn&&(this.isNewForm?i("udp-selector",{label:"Form Type",key:"udo-form-type-selector",initialValue:this.formMetadata.type,options:this.formTypeOptions,disabled:!t||!this.isNewForm,required:!0,onChange:t=>{this.formMetadata=Object.assign(Object.assign({},this.formMetadata),{type:t.detail})}}):i("div",{class:"form-details-version-container"},i("unity-typography",null,"Form Type: ",g[this.formMetadata.type]))),i("div",{class:"form-details-version-container"},i("unity-typography",null,"Version: ",this.formMetadata.version)),this.isPublicFormConfigOn&&i("div",{class:"form-details-private-container"},i("div",{class:"toggle-container"},i("stencil-toggle",{label:"Private Form",margin:"none",disabled:!t,checked:!0===this.formMetadata.isPrivate,labelPosition:"right",onToggledChange:()=>{let t=!this.formMetadata.isPrivate;this.formMetadata=Object.assign(Object.assign({},this.formMetadata),{isPrivate:t})}})))),t&&i("div",{class:"add-question-button-container"},i("udp-button",{startIcon:i("udp-icon",{iconName:"add",color:"inherit"}),onClick:()=>{const t=this.formSections.length,e=h(this.formSections);e.push(Object.assign(Object.assign({},p),{order:t+1,title:"Section "+(t+1)})),this.formSections=e}},"Add a Section")),this.formSections.map(((e,s)=>{var o,n;return i("div",{key:s,class:"form-section"},i("div",{class:"form-section-header"},i("div",{class:"form-section-header-title"},i("unity-typography",{variant:"h6",color:"inherit"},e.title)),t&&i("div",{class:"form-section-header-actions"},s>0&&i("stencil-icon-button",{icon:a("arrowUp"),tooltip:"Move Section Up",onClick:()=>{this.handleSectionMoveUp(s)}}),s<this.formSections.length-1&&i("stencil-icon-button",{icon:a("arrowDown"),tooltip:"Move Section Down",onClick:()=>{this.handleSectionMoveDown(s)}}),i("stencil-icon-button",{icon:a("edit"),tooltip:"Edit Section Fields",onClick:()=>this.handleSectionEditClick(s)}),i("stencil-icon-button",{icon:a("trashCan"),tooltip:"Delete Section",onClick:t=>{t.stopPropagation(),this.dialogMessage="Are you sure you want to delete this section?",this.dialogAction=()=>{this.handleSectionDelete(s),this.isDialogOpen=!1},this.isDialogOpen=!0}}))),i("div",{class:"form-section-questions-container"},(this.isNewForm||this.isMostRecentFormVersion)&&this.showMenuAtIndex&&this.showMenuAtIndex.sIndex===s&&0===this.showMenuAtIndex.qIndex&&i("udp-forms-builder-menu",{isVisible:!0,questionsTemplate:r,onAddSection:()=>{const t=this.formSections.length,e=h(this.formSections);e.push(Object.assign(Object.assign({},p),{order:t,title:"Section "+(t+1)})),this.formSections=e,this.showMenuAtIndex={sIndex:t,qIndex:0}},onAddQuestion:t=>{const e=this.showMenuAtIndex?this.addQuestionOfType(t.detail,this.showMenuAtIndex.sIndex,this.showMenuAtIndex.qIndex):this.addQuestionOfType(t.detail);this.editingQuestion=Object.assign({},e),this.isQuestionEditorOpen=!0},onCancelClick:()=>this.showMenuAtIndex=null}),i("div",{class:"form-section-questions-draggable-container",id:"section-"+s},e.formQuestions.map(((e,o)=>i("udp-forms-builder-question-item",{key:e.id,iconName:e.icon,primaryText:""+e.questionText,secondaryText:e.helperText?e.helperText:null,avatarBackgroundColor:this.validateQuestionItem(s,o)?"info":"warning"},i("stencil-chip",{slot:"status-chip",text:"Required",showDelete:!1,clickable:!1,hidden:!e.required}),t&&i("div",{slot:"drag-and-drop"},i("div",{class:"form-question-drag-handle"},i("div",{class:"drag-wrapper"},i("stencil-icon-button",{icon:a("draggable"),tooltip:"Move Question",noBackground:!0})))),i("div",{slot:"actions"},t?i("fragment",null,i("stencil-icon-button",{icon:a("edit"),tooltip:"Edit Question Details",onClick:t=>{t.stopPropagation(),this.handleQuestionClick(s,o)},noBackground:!0}),i("stencil-icon-button",{icon:a("copy"),tooltip:"Duplicate Question",onClick:t=>{t.stopPropagation(),this.handleQuestionCopy(s,o)},noBackground:!0}),i("stencil-icon-button",{icon:a("trashCan"),tooltip:"Delete Question",onClick:t=>{t.stopPropagation(),this.dialogMessage="Are you sure you want to delete this question?",this.dialogAction=()=>{this.handleQuestionDelete(s,o),this.isDialogOpen=!1},this.isDialogOpen=!0},noBackground:!0})):i("stencil-icon-button",{icon:a("view"),tooltip:"View Question Details",onClick:t=>{t.stopPropagation(),this.handleQuestionClick(s,o)},noBackground:!0})))))),t&&!this.showMenuAtIndex&&i("div",{class:"add-question-to-section-button-container"},i("udp-button",{variant:"text",onClick:()=>{this.showMenuAtIndex={sIndex:s,qIndex:e.formQuestions.length}},startIcon:i("udp-icon",{iconName:"add",color:"inherit"})},"Add a Question")),t&&(null===(o=this.showMenuAtIndex)||void 0===o?void 0:o.sIndex)===s&&(null===(n=this.showMenuAtIndex)||void 0===n?void 0:n.qIndex)===e.formQuestions.length&&e.formQuestions.length>0&&i("udp-forms-builder-menu",{isVisible:!0,questionsTemplate:r,onAddSection:()=>{const t=h(this.formSections);t.splice(s+1,0,[]),this.formSections=t,this.showMenuAtIndex=null},onAddQuestion:t=>{if(this.showMenuAtIndex){const e=this.addQuestionOfType(t.detail,this.showMenuAtIndex.sIndex,this.showMenuAtIndex.qIndex);this.editingQuestion=Object.assign({},e),this.isQuestionEditorOpen=!0}},onCancelClick:()=>this.showMenuAtIndex=null})))})))))}get hostEl(){return this}static get watchers(){return{formId:[{onFormIdOrVersionChange:0}],version:[{onFormIdOrVersionChange:0}]}}static get style(){return":host{display:block;--udp-form-primary-color:#007bff;--udp-form-spacing-unit:16px}.udp-forms-page{display:flex;flex-direction:column;gap:var(--spacing-06, 32px);padding:var(--spacing-06, 32px);padding-bottom:var(--spacing-12)}.form-section-questions-container{display:flex;flex-direction:column}.form-details-container{display:flex;flex-direction:column;padding:var(--spacing-05, 24px);background-color:var(--card-background-color, white)}.form-details-version-container{margin-bottom:var(--spacing-05)}.udp-form-builder-field-container,.udp-forms-builder-item-generic-configs,.udp-forms-builder-item-specific-configs{display:flex;flex-direction:column;gap:var(--spacing-04, 16px)}.form-section{}.form-section-header{display:flex;flex-direction:row;justify-content:space-between;background-color:var(--primary-color-dark, #000);color:var(--primary-contrast-text, #FFF);padding:var(--spacing-04, 16px) var(--spacing-05, 24px);align-items:center}.add-question-button-container{display:flex;justify-content:center;align-items:center}.question-editor-container{padding:var(--spacing-05, 24px);display:flex;flex-direction:column;gap:var(--spacing-05, 24px)}.add-question-to-section-button-container{padding:var(--spacing-02, 8px) 0;margin:auto}.sortable-ghost{opacity:0.5;transform:scale(0.98);background:#f4f4f4;border:1px dashed #ccc}.sortable-chosen{background:#eef6ff;box-shadow:0 0 4px 2px rgba(51, 153, 255, 0.3)}.form-question-drag-handle{transform:rotate(90deg);cursor:grab}.form-question-drag-handle:active{cursor:grabbing}.form-question-drag-handle .drag-wrapper{cursor:inherit}.form-question-drag-handle stencil-icon-button{pointer-events:none;}"}},[1,"udp-forms-builder",{formId:[1,"form-id"],version:[2],enqueueSnackbar:[16],closeSnackbar:[16],history:[16],isFollowUpFormConfigOn:[4,"is-follow-up-form-config-on"],isPublicFormConfigOn:[4,"is-public-form-config-on"],isCommentingConfigOn:[4,"is-commenting-config-on"],formsBuilderUrlPath:[1,"forms-builder-url-path"],formMetadata:[32],formSections:[32],formSectionsDraft:[32],isNewForm:[32],isMostRecentFormVersion:[32],isError:[32],isLoading:[32],isShowStyleOverrides:[32],isStyleSheetOpen:[32],isDialogOpen:[32],showMenuAtIndex:[32],editingQuestion:[32],editingSection:[32],isQuestionEditorOpen:[32],isSectionEditorOpen:[32],lookupOptionsDataProcessed:[32],dialogAction:[32],dialogMessage:[32]},void 0,{formId:[{onFormIdOrVersionChange:0}],version:[{onFormIdOrVersionChange:0}]}]),tt=Z,et=function(){"undefined"!=typeof customElements&&["udp-forms-builder","custom-button","date-time-renderer","file-upload-renderer","fluent-dialog","form-metadata-display-renderer","list-options-renderer","numeric-field","primary-action-header","question-configs-renderer","question-specific-configs-renderer","section-configs-renderer","signature-renderer","stencil-chip","stencil-icon-button","stencil-toggle","text-area","text-field","text-input-renderer","udp-ambient-tool-tip","udp-avatar","udp-badge","udp-button","udp-container","udp-date-selector","udp-datetime-selector","udp-forms-builder-menu","udp-forms-builder-question-item","udp-icon","udp-linear-loader","udp-menu-item","udp-pop-over","udp-selector","udp-side-sheet","udp-tabs","udp-time-selector","unity-typography"].forEach((t=>{switch(t){case"udp-forms-builder":customElements.get(s(t))||customElements.define(s(t),Z);break;case"custom-button":customElements.get(s(t))||v();break;case"date-time-renderer":customElements.get(s(t))||y();break;case"file-upload-renderer":customElements.get(s(t))||j();break;case"fluent-dialog":customElements.get(s(t))||O();break;case"form-metadata-display-renderer":customElements.get(s(t))||k();break;case"list-options-renderer":customElements.get(s(t))||x();break;case"numeric-field":customElements.get(s(t))||E();break;case"primary-action-header":customElements.get(s(t))||C();break;case"question-configs-renderer":customElements.get(s(t))||q();break;case"question-specific-configs-renderer":customElements.get(s(t))||n();break;case"section-configs-renderer":customElements.get(s(t))||S();break;case"signature-renderer":customElements.get(s(t))||w();break;case"stencil-chip":customElements.get(s(t))||F();break;case"stencil-icon-button":customElements.get(s(t))||I();break;case"stencil-toggle":customElements.get(s(t))||T();break;case"text-area":customElements.get(s(t))||D();break;case"text-field":customElements.get(s(t))||N();break;case"text-input-renderer":customElements.get(s(t))||P();break;case"udp-ambient-tool-tip":customElements.get(s(t))||U();break;case"udp-avatar":customElements.get(s(t))||B();break;case"udp-badge":customElements.get(s(t))||V();break;case"udp-button":customElements.get(s(t))||A();break;case"udp-container":customElements.get(s(t))||Q();break;case"udp-date-selector":customElements.get(s(t))||$();break;case"udp-datetime-selector":customElements.get(s(t))||z();break;case"udp-forms-builder-menu":customElements.get(s(t))||M();break;case"udp-forms-builder-question-item":customElements.get(s(t))||J();break;case"udp-icon":customElements.get(s(t))||c();break;case"udp-linear-loader":customElements.get(s(t))||L();break;case"udp-menu-item":customElements.get(s(t))||_();break;case"udp-pop-over":customElements.get(s(t))||G();break;case"udp-selector":customElements.get(s(t))||W();break;case"udp-side-sheet":customElements.get(s(t))||R();break;case"udp-tabs":customElements.get(s(t))||H();break;case"udp-time-selector":customElements.get(s(t))||K();break;case"unity-typography":customElements.get(s(t))||X()}}))};export{tt as UdpFormsBuilder,et as defineCustomElement}
1
+ import{p as t,H as e,h as i,t as s}from"./index2.js";import{m as o}from"./makeApiCall.js";import{q as r,d as n}from"./question-specific-configs-renderer2.js";import{g as a,d as c}from"./udp-icon2.js";import{g as d}from"./tenantUtils.js";import l from"sortablejs";import{v4 as u}from"uuid";import{f as m,d as h,a as p,s as f}from"./forms-builder-utils.js";import{b,a as g}from"./enums.js";import{d as v}from"./custom-button2.js";import{d as y}from"./date-time-renderer2.js";import{d as j}from"./file-upload-renderer2.js";import{d as O}from"./fluent-dialog2.js";import{d as k}from"./form-metadata-display-renderer2.js";import{d as x}from"./list-options-renderer2.js";import{d as E}from"./numeric-field2.js";import{d as C}from"./primary-action-header2.js";import{d as q}from"./question-configs-renderer2.js";import{d as S}from"./section-configs-renderer2.js";import{d as w}from"./signature-renderer2.js";import{d as F}from"./stencil-chip2.js";import{d as I}from"./stencil-icon-button2.js";import{d as T}from"./stencil-toggle2.js";import{d as D}from"./text-area2.js";import{d as N}from"./text-field2.js";import{d as P}from"./text-input-renderer2.js";import{d as U}from"./udp-ambient-tool-tip2.js";import{d as B}from"./udp-avatar2.js";import{d as V}from"./udp-badge2.js";import{d as A}from"./udp-button2.js";import{d as Q}from"./udp-container2.js";import{d as $}from"./udp-date-selector2.js";import{d as z}from"./udp-datetime-selector2.js";import{d as M}from"./udp-forms-builder-menu2.js";import{d as J}from"./udp-forms-builder-question-item2.js";import{d as L}from"./udp-linear-loader2.js";import{d as _}from"./udp-menu-item2.js";import{d as G}from"./udp-pop-over2.js";import{d as W}from"./udp-selector2.js";import{d as R}from"./udp-side-sheet2.js";import{d as H}from"./udp-tabs2.js";import{d as K}from"./udp-time-selector2.js";import{d as X}from"./unity-typography2.js";import{C as Y}from"./configService.js";const Z=t(class extends e{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.isFollowUpFormConfigOn=!1,this.isPublicFormConfigOn=!1,this.isCommentingConfigOn=!1,this.formsBuilderUrlPath="",this.formMetadata=m,this.formSections=[],this.formSectionsDraft=[],this.isNewForm=!0,this.isMostRecentFormVersion=!1,this.isError=!1,this.isLoading=!1,this.isShowStyleOverrides=!1,this.isStyleSheetOpen=!1,this.isDialogOpen=!1,this.showMenuAtIndex=null,this.editingQuestion=null,this.editingSection=null,this.isQuestionEditorOpen=!1,this.isSectionEditorOpen=!1,this.lookupOptionsDataProcessed=[],this.dialogAction=null,this.dialogMessage="Are you sure you want to delete this?",this.sortableInstances=[],this.formsBuilderPageId=b.FormBuilderPageId,this.formTypeOptions=Object.keys(g).filter((t=>isNaN(Number(t)))).map((t=>({value:g[t]+"",label:t}))),this.toggleStyleSheet=()=>{this.isStyleSheetOpen=!this.isStyleSheetOpen},this.getQuestionTypeName=t=>{const e=r.find((e=>e.fieldTypeId===t));return e?e.questionTypeName:"Unknown"},this.getIsContainsOptionItems=t=>{const e=r.find((e=>e.fieldTypeId===t));return e&&e.isContainsOptionItems||!1},this.getIconForQuestion=t=>{const e=r.find((e=>e.fieldTypeId===t));return e?e.icon:null},this.handleQuestionDelete=(t,e)=>{const i=h(this.formSections);i[t].formQuestions.splice(e,1),this.formSections=i},this.handleQuestionCopy=(t,e)=>{const i=h(this.formSections),s=this.formSections[t].formQuestions[e],o=Object.assign(Object.assign({},s),{questionText:(s.questionText||"")+" (Copy)",id:u()});i[t].formQuestions.splice(e+1,0,o),this.formSections=i},this.handleQuestionClick=(t,e)=>{this.editingQuestion={sIndex:t,qIndex:e},this.isQuestionEditorOpen=!0,this.formSectionsDraft=h(this.formSections)},this.closeQuestionEditor=()=>{this.isQuestionEditorOpen=!1,this.editingQuestion=null,this.formSectionsDraft=null},this.addQuestionOfType=(t,e,i)=>{const s={questionTypeName:t.questionTypeName,fieldTypeId:t.fieldTypeId,fieldProperties:t.defaultFieldProperties,helperText:"",questionText:"",section:void 0!==e?e+1:this.formSections.length>0?this.formSections[this.formSections.length-1].formQuestions[0].section:1,isContainsOptionItems:t.isContainsOptionItems,icon:t.icon,required:!1,form:null,isPrivate:!0,id:u()},o=h(this.formSections);let r=e,n=i;if(void 0!==e&&void 0!==i)if(o[e].formQuestions)o[e].formQuestions.splice(i,0,s);else{const t=o.length-1;o[t].formQuestions.push(s),r=t,n=o[t].formQuestions.length-1}else{const t=o.length-1;t<0||0===o[t].formQuestions.length?(o.push(Object.assign(Object.assign({},p),{formQuestions:[s]})),r=o.length-1,n=0):(o[t].formQuestions.push(s),r=t,n=o[t].formQuestions.length-1)}return this.formSectionsDraft=o,this.showMenuAtIndex&&(this.showMenuAtIndex=null),{sIndex:r,qIndex:n}},this.handleSectionMoveDown=t=>{if(t>=this.formSections.length-1)return;const e=[...this.formSections];[e[t],e[t+1]]=[e[t+1],e[t]],this.formSections=e},this.handleSectionMoveUp=t=>{if(t<=0)return;const e=[...this.formSections];[e[t],e[t-1]]=[e[t-1],e[t]],this.formSections=e},this.handleSectionDelete=t=>{const e=[...this.formSections];e.splice(t,1),this.formSections=e},this.updateFormSectionsWithDraft=()=>{this.formSections=this.formSectionsDraft,this.formSectionsDraft=null},this.hasUnsavedFormSectionsChanges=()=>JSON.stringify(this.formSections)!==JSON.stringify(this.formSectionsDraft),this.handleSectionEditClick=t=>{this.editingSection={sIndex:t},this.isSectionEditorOpen=!0,this.formSectionsDraft=h(this.formSections)},this.closeSectionEditor=()=>{this.isSectionEditorOpen=!1,this.editingSection=null,this.formSectionsDraft=null}}async initializeForm(){this.formMetadata.isPrivate=m.isPrivate,this.formMetadata.tenantId=d(),this.formMetadata.type=m.type,this.formMetadata.version=m.version,this.formMetadata.name=m.name,this.formMetadata.description=m.description,this.formMetadata.styleOverrides=f;try{this.isLoading=!0;const t=await o("GET",Y.productV1ApiUrl+"/UdpLookup");if(!t)throw Error("Error fetching lookup data");if(this.lookupOptionsDataProcessed=t.map((t=>Object.assign(Object.assign({},t),{value:t.id,label:t.name}))),this.formId&&this.version){const t=await o("GET",`${Y.productV1ApiUrl}/UdpForm/${this.formId}/${this.version}/describe`),e=await o("GET",`${Y.productV1ApiUrl}/UdpForm/${this.formId}/describe`);if(this.isNewForm=!1,!(t&&e&&t.id&&e))throw Error("Error fetching form data");t.id==e.id&&t.version==e.version&&(this.isMostRecentFormVersion=!0);const i=structuredClone(t.udpFormUdpFormSection).map((t=>Object.assign(Object.assign({},t),{formQuestions:[]})));i.forEach((t=>{t.sectionProperties=t.sectionProperties?JSON.parse(t.sectionProperties):{}})),t.formQuestions.forEach((t=>{const e=i.find((e=>e.id===t.formSectionId));if(e){const i=Object.assign({},t.fieldProperties);"lookupId"in i&&"items"in i&&delete i.items,e.formQuestions.push(Object.assign(Object.assign({},t),{fieldProperties:i,questionTypeName:this.getQuestionTypeName(t.fieldTypeId),isContainsOptionItems:this.getIsContainsOptionItems(t.fieldTypeId),icon:this.getIconForQuestion(t.fieldTypeId)}))}})),i.forEach((t=>{t.formQuestions.sort(((t,e)=>t.questionOrder-e.questionOrder))})),i.sort(((t,e)=>t.order-e.order));const s=function(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(t);o<s.length;o++)e.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(t,s[o])&&(i[s[o]]=t[s[o]])}return i}(t,[]);s.styleOverrides=this.deepMerge(f,JSON.parse(s.styleOverrides)||{}),this.formMetadata=s,this.formSections=i,this.isLoading=!1}}catch(t){this.isError=!0,this.enqueueSnackbar("Error loading form data",{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}})}finally{this.isLoading=!1}}async submitForm(){if(this.isValidForm()){this.isLoading=!0;try{const t={name:this.formMetadata.name,description:this.formMetadata.description,tenantId:this.formMetadata.tenantId,isPrivate:this.formMetadata.isPrivate,type:this.formMetadata.type,styleOverrides:JSON.stringify(this.formMetadata.styleOverrides),id:this.formMetadata.id,version:this.formMetadata.version},e=`${Y.productV1ApiUrl}/UdpForm${this.isMostRecentFormVersion?"/versions":""}`,i=await o("POST",e,t),s=i.id,r=i.version;if(!i||!i.id||!i.version)throw Error("Invalid form response: "+JSON.stringify(i));let n=0,a=0;const c=[];for(const[t,e]of this.formSections.entries()){n+=1;const i=Object.assign(Object.assign({},e),{formId:s,formVersion:r,order:n,sectionProperties:JSON.stringify(e.sectionProperties),name:"section"+n}),d=await o("POST",Y.productV1ApiUrl+"/UdpFormSection",i);if(!d||!d.id)throw Error("Invalid section response: "+JSON.stringify(d));const l=d.id;for(const i of e.formQuestions){a+=1;const e=Object.assign(Object.assign({},i),{formId:s,formVersion:r,section:t+1,questionOrder:a,formSectionId:l,name:"question"+a}),n=o("POST",Y.productV1ApiUrl+"/UdpFormQuestion",e);c.push(n)}}if(await Promise.all(c),this.enqueueSnackbar("Success",{variant:"success",anchorOrigin:{vertical:"top",horizontal:"center"}}),this.formsBuilderUrlPath)return void this.history.push(`${this.formsBuilderUrlPath}&udpf_formId=${s}&udpf_version=${r}`);this.history.push(`/page/${this.formsBuilderPageId}?udpf_formId=${s}&udpf_version=${r}`)}catch(t){console.error("Form submission error:",t),this.enqueueSnackbar("Error saving form",{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}})}finally{this.isLoading=!1}}}componentDidLoad(){this.initializeSortable()}componentDidUpdate(){this.initializeSortable()}componentWillLoad(){this.initializeForm()}onFormIdOrVersionChange(){this.initializeForm()}initializeSortable(){(this.isNewForm||this.isMostRecentFormVersion)&&(this.sortableInstances.forEach((t=>t.destroy())),this.sortableInstances=[],this.formSections.forEach(((t,e)=>{const i=this.hostEl.shadowRoot.querySelector("#section-"+e);if(i){const t=new l(i,{animation:200,easing:"cubic-bezier(0.25, 1, 0.5, 1)",draggable:"udp-forms-builder-question-item",handle:".form-question-drag-handle",ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",direction:"vertical",forceFallback:!1,dragoverBubble:!1,swapThreshold:.6,onEnd:t=>this.handleDragEnd(t,e)});this.sortableInstances.push(t)}})))}handleDragEnd(t,e){const i=t.oldIndex,s=t.newIndex;if(i===s||null==i||null==s)return;const o=structuredClone(this.formSections[e]),[r]=o.formQuestions.splice(i,1);o.formQuestions.splice(s,0,r);const n=h(this.formSections);n[e]=o,this.formSections=n}deepMerge(t,e){const i=Object.assign({},t);for(const s in e)i[s]=e[s]&&"object"==typeof e[s]&&!Array.isArray(e[s])?this.deepMerge(t[s]||{},e[s]):e[s];return i}isValidForm(){return this.validateFormMetadata()&&this.validateFormSections()&&this.validateAllQuestions()}validateFormMetadata(){var t;return!!(null===(t=this.formMetadata.name)||void 0===t?void 0:t.trim())||(this.enqueueSnackbar("Please enter a form name.",{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}}),!1)}validateFormSections(){if(this.formSections.length<1)return this.enqueueSnackbar("Please add at least one section to the form.",{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}}),!1;for(let t=0;t<this.formSections.length;t++){const e=this.formSections[t];if(((null==e?void 0:e.formQuestions)||[]).length<1)return this.enqueueSnackbar(`Section ${(null==e?void 0:e.title)?`"${e.title}"`:"#"+(t+1)} must contain at least one question.`,{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}}),!1}return!0}validateAllQuestions(){for(let t=0;t<this.formSections.length;t++){const e=this.formSections[t],i=(null==e?void 0:e.formQuestions)||[];for(let e=0;e<i.length;e++)if(!this.validateQuestionItem(t,e))return this.enqueueSnackbar("Please validate all questions.",{variant:"error",anchorOrigin:{vertical:"top",horizontal:"center"}}),!1}return!0}validateQuestionItem(t,e){const i=this.formSections[t].formQuestions[e],s=r.find((t=>t.fieldTypeId===i.fieldTypeId));if(!(s&&s.questionTextOptional||i.questionText))return!1;if(i.isContainsOptionItems){const t=i.fieldProperties;if(!(null==t?void 0:t.lookupId)){if(!Array.isArray(null==t?void 0:t.items)||0===t.items.length)return!1;if(t.items.some((t=>!t.display||!t.value)))return!1}}return!0}render(){if(this.isError)return i("div",null," There is an Error With the Form Builder");const t=this.isNewForm||this.isMostRecentFormVersion;return i("div",null,i("primary-action-header",{title:"UDP Form Builder",actionButtonLabel:t?this.isMostRecentFormVersion?`Create New Version (v.${this.version+1})`:"Create New Form":"",primaryActionClick:t?()=>this.submitForm():null,defaultActionButtons:t?[{label:"Style Overrides",clickHandler:this.toggleStyleSheet,tooltip:"Style Overrides",visible:!1,icon:a("settings")}]:[],tabs:!1}),i("udp-side-sheet",{open:this.isQuestionEditorOpen,onUdpSideSheetClose:()=>this.closeQuestionEditor(),onUdpPrimaryButtonClick:()=>{this.hasUnsavedFormSectionsChanges()&&(this.updateFormSectionsWithDraft(),this.closeQuestionEditor())},primaryButtonDisabled:!this.hasUnsavedFormSectionsChanges(),title:"Edit Question",position:"right",width:"md",primaryButtonLabel:"Update"},this.isQuestionEditorOpen&&i("div",{class:"question-editor-container"},i("question-configs-renderer",{formSectionsDraft:this.formSectionsDraft,sIndex:this.editingQuestion.sIndex,qIndex:this.editingQuestion.qIndex,isViewOnly:!t,onFormSectionsDraftChange:t=>this.formSectionsDraft=t,lookupOptions:this.lookupOptionsDataProcessed,formType:this.formMetadata.type,isFollowUpFormConfigOn:this.isFollowUpFormConfigOn,isCommentingConfigOn:this.isCommentingConfigOn}))),i("udp-side-sheet",{open:this.isSectionEditorOpen,onUdpSideSheetClose:()=>this.closeSectionEditor(),title:"Edit Section Fields",position:"right",width:"md",primaryButtonDisabled:!this.hasUnsavedFormSectionsChanges(),primaryButtonLabel:"Update",onUdpPrimaryButtonClick:()=>{this.hasUnsavedFormSectionsChanges()&&(this.updateFormSectionsWithDraft(),this.closeSectionEditor())}},this.isSectionEditorOpen&&i("div",{class:"section-editor-container"},i("section-configs-renderer",{formSectionsDraft:this.formSectionsDraft,sIndex:this.editingSection.sIndex,isViewOnly:!t,onFormSectionsDraftChange:t=>this.formSectionsDraft=t}))),i("fluent-dialog",{open:this.isDialogOpen,message:this.dialogMessage,labelOne:"Confirm",labelTwo:"Cancel",actionOne:()=>{"function"==typeof this.dialogAction&&this.dialogAction()},actionTwo:()=>this.isDialogOpen=!1}),this.isLoading&&i("udp-linear-loader",null),!this.isLoading&&i("udp-container",{maxWidth:"lg"},i("div",{class:"udp-forms-page"},i("div",{class:"form-details-container"},i("div",{class:"form-details-name-container"},t?i("div",{class:"form-details-name-input"},i("text-field",{label:"Form Name",value:this.formMetadata.name,placeholder:"Form Name",disabled:!t,required:!0,margin:"none",maxCharacter:128,onInput:t=>{this.formMetadata=Object.assign(Object.assign({},this.formMetadata),{name:t.target.value})}})):i("div",{class:"form-details-name-display"},i("unity-typography",{variant:"h2"},this.formMetadata.name+" (View Only)"))),i("div",{class:"form-details-description-container"},t?i("div",{class:"form-details-details-input"},i("text-area",{label:"Form Description",value:this.formMetadata.description,placeholder:"Form Description",disabled:!t,required:!1,margin:"none",maxCharacter:256,onInput:t=>{this.formMetadata=Object.assign(Object.assign({},this.formMetadata),{description:t.target.value})}})):i("div",{class:"form-details-description-display"},i("unity-typography",null,this.formMetadata.description))),this.isFollowUpFormConfigOn&&(this.isNewForm?i("udp-selector",{label:"Form Type",key:"udo-form-type-selector",initialValue:this.formMetadata.type,options:this.formTypeOptions,disabled:!t||!this.isNewForm,required:!0,onChange:t=>{this.formMetadata=Object.assign(Object.assign({},this.formMetadata),{type:t.detail})}}):i("div",{class:"form-details-version-container"},i("unity-typography",null,"Form Type: ",g[this.formMetadata.type]))),i("div",{class:"form-details-version-container"},i("unity-typography",null,"Version: ",this.formMetadata.version)),this.isPublicFormConfigOn&&i("div",{class:"form-details-private-container"},i("div",{class:"toggle-container"},i("stencil-toggle",{label:"Private Form",margin:"none",disabled:!t,checked:!0===this.formMetadata.isPrivate,labelPosition:"right",onToggledChange:()=>{let t=!this.formMetadata.isPrivate;this.formMetadata=Object.assign(Object.assign({},this.formMetadata),{isPrivate:t})}})))),t&&i("div",{class:"add-question-button-container"},i("udp-button",{startIcon:i("udp-icon",{iconName:"add",color:"inherit"}),onClick:()=>{const t=this.formSections.length,e=h(this.formSections);e.push(Object.assign(Object.assign({},p),{order:t+1,title:"Section "+(t+1)})),this.formSections=e}},"Add a Section")),this.formSections.map(((e,s)=>{var o,n;return i("div",{key:s,class:"form-section"},i("div",{class:"form-section-header"},i("div",{class:"form-section-header-title"},i("unity-typography",{variant:"h6",color:"inherit"},e.title)),t&&i("div",{class:"form-section-header-actions"},s>0&&i("stencil-icon-button",{icon:a("arrowUp"),tooltip:"Move Section Up",onClick:()=>{this.handleSectionMoveUp(s)}}),s<this.formSections.length-1&&i("stencil-icon-button",{icon:a("arrowDown"),tooltip:"Move Section Down",onClick:()=>{this.handleSectionMoveDown(s)}}),i("stencil-icon-button",{icon:a("edit"),tooltip:"Edit Section Fields",onClick:()=>this.handleSectionEditClick(s)}),i("stencil-icon-button",{icon:a("trashCan"),tooltip:"Delete Section",onClick:t=>{t.stopPropagation(),this.dialogMessage="Are you sure you want to delete this section?",this.dialogAction=()=>{this.handleSectionDelete(s),this.isDialogOpen=!1},this.isDialogOpen=!0}}))),i("div",{class:"form-section-questions-container"},(this.isNewForm||this.isMostRecentFormVersion)&&this.showMenuAtIndex&&this.showMenuAtIndex.sIndex===s&&0===this.showMenuAtIndex.qIndex&&i("udp-forms-builder-menu",{isVisible:!0,questionsTemplate:r,onAddSection:()=>{const t=this.formSections.length,e=h(this.formSections);e.push(Object.assign(Object.assign({},p),{order:t,title:"Section "+(t+1)})),this.formSections=e,this.showMenuAtIndex={sIndex:t,qIndex:0}},onAddQuestion:t=>{const e=this.showMenuAtIndex?this.addQuestionOfType(t.detail,this.showMenuAtIndex.sIndex,this.showMenuAtIndex.qIndex):this.addQuestionOfType(t.detail);this.editingQuestion=Object.assign({},e),this.isQuestionEditorOpen=!0},onCancelClick:()=>this.showMenuAtIndex=null}),i("div",{class:"form-section-questions-draggable-container",id:"section-"+s},e.formQuestions.map(((e,o)=>i("udp-forms-builder-question-item",{key:e.id,iconName:e.icon,primaryText:""+e.questionText,secondaryText:e.helperText?e.helperText:null,avatarBackgroundColor:this.validateQuestionItem(s,o)?"info":"warning"},i("stencil-chip",{slot:"status-chip",text:"Required",showDelete:!1,clickable:!1,hidden:!e.required}),t&&i("div",{slot:"drag-and-drop"},i("div",{class:"form-question-drag-handle"},i("div",{class:"drag-wrapper"},i("stencil-icon-button",{icon:a("draggable"),tooltip:"Move Question",noBackground:!0})))),i("div",{slot:"actions"},t?i("fragment",null,i("stencil-icon-button",{icon:a("edit"),tooltip:"Edit Question Details",onClick:t=>{t.stopPropagation(),this.handleQuestionClick(s,o)},noBackground:!0}),i("stencil-icon-button",{icon:a("copy"),tooltip:"Duplicate Question",onClick:t=>{t.stopPropagation(),this.handleQuestionCopy(s,o)},noBackground:!0}),i("stencil-icon-button",{icon:a("trashCan"),tooltip:"Delete Question",onClick:t=>{t.stopPropagation(),this.dialogMessage="Are you sure you want to delete this question?",this.dialogAction=()=>{this.handleQuestionDelete(s,o),this.isDialogOpen=!1},this.isDialogOpen=!0},noBackground:!0})):i("stencil-icon-button",{icon:a("view"),tooltip:"View Question Details",onClick:t=>{t.stopPropagation(),this.handleQuestionClick(s,o)},noBackground:!0})))))),t&&!this.showMenuAtIndex&&i("div",{class:"add-question-to-section-button-container"},i("udp-button",{variant:"text",onClick:()=>{this.showMenuAtIndex={sIndex:s,qIndex:e.formQuestions.length}},startIcon:i("udp-icon",{iconName:"add",color:"inherit"})},"Add a Question")),t&&(null===(o=this.showMenuAtIndex)||void 0===o?void 0:o.sIndex)===s&&(null===(n=this.showMenuAtIndex)||void 0===n?void 0:n.qIndex)===e.formQuestions.length&&e.formQuestions.length>0&&i("udp-forms-builder-menu",{isVisible:!0,questionsTemplate:r,onAddSection:()=>{const t=h(this.formSections);t.splice(s+1,0,[]),this.formSections=t,this.showMenuAtIndex=null},onAddQuestion:t=>{if(this.showMenuAtIndex){const e=this.addQuestionOfType(t.detail,this.showMenuAtIndex.sIndex,this.showMenuAtIndex.qIndex);this.editingQuestion=Object.assign({},e),this.isQuestionEditorOpen=!0}},onCancelClick:()=>this.showMenuAtIndex=null})))})))))}get hostEl(){return this}static get watchers(){return{formId:[{onFormIdOrVersionChange:0}],version:[{onFormIdOrVersionChange:0}]}}static get style(){return":host{display:block;--udp-form-primary-color:#007bff;--udp-form-spacing-unit:16px}.udp-forms-page{display:flex;flex-direction:column;gap:var(--spacing-06, 32px);padding:var(--spacing-06, 32px);padding-bottom:var(--spacing-12)}.form-section-questions-container{display:flex;flex-direction:column}.form-details-container{display:flex;flex-direction:column;padding:var(--spacing-05, 24px);background-color:var(--card-background-color, white)}.form-details-version-container{margin-bottom:var(--spacing-05)}.udp-form-builder-field-container,.udp-forms-builder-item-generic-configs,.udp-forms-builder-item-specific-configs{display:flex;flex-direction:column;gap:var(--spacing-04, 16px)}.form-section{}.form-section-header{display:flex;flex-direction:row;justify-content:space-between;background-color:var(--primary-color-dark, #000);color:var(--primary-contrast-text, #FFF);padding:var(--spacing-04, 16px) var(--spacing-05, 24px);align-items:center}.add-question-button-container{display:flex;justify-content:center;align-items:center}.question-editor-container{padding:var(--spacing-05, 24px);display:flex;flex-direction:column;gap:var(--spacing-05, 24px)}.add-question-to-section-button-container{padding:var(--spacing-02, 8px) 0;margin:auto}.sortable-ghost{opacity:0.5;transform:scale(0.98);background:#f4f4f4;border:1px dashed #ccc}.sortable-chosen{background:#eef6ff;box-shadow:0 0 4px 2px rgba(51, 153, 255, 0.3)}.form-question-drag-handle{transform:rotate(90deg);cursor:grab}.form-question-drag-handle:active{cursor:grabbing}.form-question-drag-handle .drag-wrapper{cursor:inherit}.form-question-drag-handle stencil-icon-button{pointer-events:none;}"}},[1,"udp-forms-builder",{formId:[1,"form-id"],version:[2],enqueueSnackbar:[16],closeSnackbar:[16],history:[16],isFollowUpFormConfigOn:[4,"is-follow-up-form-config-on"],isPublicFormConfigOn:[4,"is-public-form-config-on"],isCommentingConfigOn:[4,"is-commenting-config-on"],formsBuilderUrlPath:[1,"forms-builder-url-path"],formMetadata:[32],formSections:[32],formSectionsDraft:[32],isNewForm:[32],isMostRecentFormVersion:[32],isError:[32],isLoading:[32],isShowStyleOverrides:[32],isStyleSheetOpen:[32],isDialogOpen:[32],showMenuAtIndex:[32],editingQuestion:[32],editingSection:[32],isQuestionEditorOpen:[32],isSectionEditorOpen:[32],lookupOptionsDataProcessed:[32],dialogAction:[32],dialogMessage:[32]},void 0,{formId:[{onFormIdOrVersionChange:0}],version:[{onFormIdOrVersionChange:0}]}]),tt=Z,et=function(){"undefined"!=typeof customElements&&["udp-forms-builder","custom-button","date-time-renderer","file-upload-renderer","fluent-dialog","form-metadata-display-renderer","list-options-renderer","numeric-field","primary-action-header","question-configs-renderer","question-specific-configs-renderer","section-configs-renderer","signature-renderer","stencil-chip","stencil-icon-button","stencil-toggle","text-area","text-field","text-input-renderer","udp-ambient-tool-tip","udp-avatar","udp-badge","udp-button","udp-container","udp-date-selector","udp-datetime-selector","udp-forms-builder-menu","udp-forms-builder-question-item","udp-icon","udp-linear-loader","udp-menu-item","udp-pop-over","udp-selector","udp-side-sheet","udp-tabs","udp-time-selector","unity-typography"].forEach((t=>{switch(t){case"udp-forms-builder":customElements.get(s(t))||customElements.define(s(t),Z);break;case"custom-button":customElements.get(s(t))||v();break;case"date-time-renderer":customElements.get(s(t))||y();break;case"file-upload-renderer":customElements.get(s(t))||j();break;case"fluent-dialog":customElements.get(s(t))||O();break;case"form-metadata-display-renderer":customElements.get(s(t))||k();break;case"list-options-renderer":customElements.get(s(t))||x();break;case"numeric-field":customElements.get(s(t))||E();break;case"primary-action-header":customElements.get(s(t))||C();break;case"question-configs-renderer":customElements.get(s(t))||q();break;case"question-specific-configs-renderer":customElements.get(s(t))||n();break;case"section-configs-renderer":customElements.get(s(t))||S();break;case"signature-renderer":customElements.get(s(t))||w();break;case"stencil-chip":customElements.get(s(t))||F();break;case"stencil-icon-button":customElements.get(s(t))||I();break;case"stencil-toggle":customElements.get(s(t))||T();break;case"text-area":customElements.get(s(t))||D();break;case"text-field":customElements.get(s(t))||N();break;case"text-input-renderer":customElements.get(s(t))||P();break;case"udp-ambient-tool-tip":customElements.get(s(t))||U();break;case"udp-avatar":customElements.get(s(t))||B();break;case"udp-badge":customElements.get(s(t))||V();break;case"udp-button":customElements.get(s(t))||A();break;case"udp-container":customElements.get(s(t))||Q();break;case"udp-date-selector":customElements.get(s(t))||$();break;case"udp-datetime-selector":customElements.get(s(t))||z();break;case"udp-forms-builder-menu":customElements.get(s(t))||M();break;case"udp-forms-builder-question-item":customElements.get(s(t))||J();break;case"udp-icon":customElements.get(s(t))||c();break;case"udp-linear-loader":customElements.get(s(t))||L();break;case"udp-menu-item":customElements.get(s(t))||_();break;case"udp-pop-over":customElements.get(s(t))||G();break;case"udp-selector":customElements.get(s(t))||W();break;case"udp-side-sheet":customElements.get(s(t))||R();break;case"udp-tabs":customElements.get(s(t))||H();break;case"udp-time-selector":customElements.get(s(t))||K();break;case"unity-typography":customElements.get(s(t))||X()}}))};export{tt as UdpFormsBuilder,et as defineCustomElement}