@3t-transform/threeteeui 0.1.36 → 0.1.41

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 (125) hide show
  1. package/dist/cjs/domsanitiser.options-277161b9.js +1667 -0
  2. package/dist/cjs/{index-457ca775.js → index-76f14107.js} +2 -88
  3. package/dist/cjs/loader.cjs.js +2 -3
  4. package/dist/cjs/tttx-button.cjs.entry.js +25 -25
  5. package/dist/cjs/tttx-filter.cjs.entry.js +159 -159
  6. package/dist/cjs/tttx-form.cjs.entry.js +457 -373
  7. package/dist/cjs/tttx-icon.cjs.entry.js +11 -11
  8. package/dist/cjs/tttx-keyvalue-block.cjs.entry.js +59 -59
  9. package/dist/cjs/tttx-list.cjs.entry.js +32 -1694
  10. package/dist/cjs/tttx-loading-spinner.cjs.entry.js +16 -16
  11. package/dist/cjs/tttx-sorter.cjs.entry.js +102 -102
  12. package/dist/cjs/tttx-standalone-input.cjs.entry.js +79 -79
  13. package/dist/cjs/tttx-toolbar.cjs.entry.js +10 -10
  14. package/dist/cjs/tttx.cjs.js +2 -6
  15. package/dist/collection/collection-manifest.json +2 -2
  16. package/dist/collection/components/atoms/tttx-button/tttx-button.css +4 -4
  17. package/dist/collection/components/atoms/tttx-button/tttx-button.js +110 -110
  18. package/dist/collection/components/atoms/tttx-button/tttx-button.stories.js +14 -14
  19. package/dist/collection/components/atoms/tttx-icon/tttx-icon.js +62 -62
  20. package/dist/collection/components/atoms/tttx-icon/tttx-icon.stories.js +22 -22
  21. package/dist/collection/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.js +109 -109
  22. package/dist/collection/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.stories.js +38 -38
  23. package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.js +67 -67
  24. package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.js +17 -17
  25. package/dist/collection/components/molecules/tttx-filter/tttx-filter.js +334 -334
  26. package/dist/collection/components/molecules/tttx-filter/tttx-filter.stories.js +62 -62
  27. package/dist/collection/components/molecules/tttx-form/lib/setErrorState.js +37 -37
  28. package/dist/collection/components/molecules/tttx-form/lib/validityCheck.js +61 -58
  29. package/dist/collection/components/molecules/tttx-form/tttx-form.css +98 -2
  30. package/dist/collection/components/molecules/tttx-form/tttx-form.js +477 -393
  31. package/dist/collection/components/molecules/tttx-form/tttx-form.stories.js +274 -218
  32. package/dist/collection/components/molecules/tttx-list/tttx-list.js +105 -105
  33. package/dist/collection/components/molecules/tttx-list/tttx-list.stories.js +43 -43
  34. package/dist/collection/components/molecules/tttx-sorter/tttx-sorter.js +224 -224
  35. package/dist/collection/components/molecules/tttx-sorter/tttx-sorter.stories.js +42 -42
  36. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.js +759 -759
  37. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.stories.js +172 -172
  38. package/dist/collection/components/molecules/tttx-toolbar/tttx-toolbar.js +44 -44
  39. package/dist/collection/components/molecules/tttx-toolbar/tttx-toolbar.stories.js +14 -14
  40. package/dist/collection/components/palette.stories.js +7 -7
  41. package/dist/collection/docs/gettingstarted-developer.stories.js +5 -5
  42. package/dist/collection/icons.js +2838 -2838
  43. package/dist/collection/index.js +1 -1
  44. package/dist/collection/shared/domsanitiser.options.js +14 -14
  45. package/dist/components/domsanitiser.options.js +1664 -0
  46. package/dist/components/index.d.ts +0 -9
  47. package/dist/components/index.js +1 -1
  48. package/dist/components/tttx-button.js +49 -49
  49. package/dist/components/tttx-filter.js +191 -191
  50. package/dist/components/tttx-form.js +475 -391
  51. package/dist/components/tttx-icon2.js +28 -28
  52. package/dist/components/tttx-keyvalue-block.js +76 -76
  53. package/dist/components/tttx-list.js +54 -1716
  54. package/dist/components/tttx-loading-spinner.js +33 -33
  55. package/dist/components/tttx-sorter.js +130 -130
  56. package/dist/components/tttx-standalone-input.js +130 -130
  57. package/dist/components/tttx-toolbar.js +26 -26
  58. package/dist/esm/domsanitiser.options-cc420431.js +1664 -0
  59. package/dist/esm/{index-d784fb3e.js → index-9cde46a5.js} +3 -88
  60. package/dist/esm/loader.js +2 -3
  61. package/dist/esm/polyfills/core-js.js +0 -0
  62. package/dist/esm/polyfills/css-shim.js +1 -1
  63. package/dist/esm/polyfills/dom.js +0 -0
  64. package/dist/esm/polyfills/es5-html-element.js +0 -0
  65. package/dist/esm/polyfills/index.js +0 -0
  66. package/dist/esm/polyfills/system.js +0 -0
  67. package/dist/esm/tttx-button.entry.js +25 -25
  68. package/dist/esm/tttx-filter.entry.js +159 -159
  69. package/dist/esm/tttx-form.entry.js +457 -373
  70. package/dist/esm/tttx-icon.entry.js +11 -11
  71. package/dist/esm/tttx-keyvalue-block.entry.js +59 -59
  72. package/dist/esm/tttx-list.entry.js +32 -1694
  73. package/dist/esm/tttx-loading-spinner.entry.js +16 -16
  74. package/dist/esm/tttx-sorter.entry.js +102 -102
  75. package/dist/esm/tttx-standalone-input.entry.js +79 -79
  76. package/dist/esm/tttx-toolbar.entry.js +10 -10
  77. package/dist/esm/tttx.js +2 -3
  78. package/dist/tttx/{p-400868f1.entry.js → p-3b1be372.entry.js} +1 -1
  79. package/dist/tttx/{p-563605b2.entry.js → p-561224f5.entry.js} +1 -1
  80. package/dist/tttx/{p-b720c4ad.entry.js → p-9f1e9cc1.entry.js} +1 -1
  81. package/dist/tttx/{p-798a098a.entry.js → p-aef96333.entry.js} +1 -1
  82. package/dist/tttx/p-b4290a5b.js +3 -0
  83. package/dist/tttx/p-bd1edaed.entry.js +1 -0
  84. package/dist/tttx/p-d0ff9ad0.entry.js +1 -0
  85. package/dist/tttx/{p-cac26a1b.entry.js → p-d2f1aa8e.entry.js} +1 -1
  86. package/dist/tttx/p-db059a69.js +2 -0
  87. package/dist/tttx/p-dc2a37b0.entry.js +1 -0
  88. package/dist/tttx/{p-ab6ce9f6.entry.js → p-e53c7f9d.entry.js} +1 -1
  89. package/dist/tttx/{p-92cade7f.entry.js → p-f885f17a.entry.js} +1 -1
  90. package/dist/tttx/tttx.esm.js +1 -1
  91. package/dist/types/components/atoms/tttx-button/tttx-button.d.ts +10 -10
  92. package/dist/types/components/atoms/tttx-button/tttx-button.stories.d.ts +10 -10
  93. package/dist/types/components/atoms/tttx-icon/tttx-icon.d.ts +5 -5
  94. package/dist/types/components/atoms/tttx-icon/tttx-icon.stories.d.ts +20 -20
  95. package/dist/types/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.d.ts +7 -7
  96. package/dist/types/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.stories.d.ts +9 -9
  97. package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.d.ts +6 -6
  98. package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.d.ts +17 -17
  99. package/dist/types/components/molecules/tttx-filter/tttx-filter.d.ts +39 -39
  100. package/dist/types/components/molecules/tttx-filter/tttx-filter.stories.d.ts +68 -68
  101. package/dist/types/components/molecules/tttx-form/lib/setErrorState.d.ts +13 -13
  102. package/dist/types/components/molecules/tttx-form/lib/validityCheck.d.ts +17 -17
  103. package/dist/types/components/molecules/tttx-form/tttx-form.d.ts +133 -111
  104. package/dist/types/components/molecules/tttx-form/tttx-form.stories.d.ts +278 -13
  105. package/dist/types/components/molecules/tttx-list/tttx-list.d.ts +11 -11
  106. package/dist/types/components/molecules/tttx-list/tttx-list.stories.d.ts +14 -14
  107. package/dist/types/components/molecules/tttx-sorter/tttx-sorter.d.ts +19 -19
  108. package/dist/types/components/molecules/tttx-sorter/tttx-sorter.stories.d.ts +30 -30
  109. package/dist/types/components/molecules/tttx-standalone-input/tttx-standalone-input.d.ts +69 -69
  110. package/dist/types/components/molecules/tttx-standalone-input/tttx-standalone-input.stories.d.ts +143 -143
  111. package/dist/types/components/molecules/tttx-toolbar/tttx-toolbar.d.ts +4 -4
  112. package/dist/types/components/molecules/tttx-toolbar/tttx-toolbar.stories.d.ts +13 -13
  113. package/dist/types/components/palette.stories.d.ts +6 -6
  114. package/dist/types/components.d.ts +1 -1
  115. package/dist/types/docs/gettingstarted-developer.stories.d.ts +5 -5
  116. package/dist/types/icons.d.ts +2 -2
  117. package/dist/types/index.d.ts +1 -1
  118. package/dist/types/shared/domsanitiser.options.d.ts +10 -10
  119. package/dist/types/stencil-public-runtime.d.ts +3 -59
  120. package/loader/index.d.ts +0 -9
  121. package/package.json +1 -1
  122. package/dist/tttx/p-0ebffdfc.js +0 -2
  123. package/dist/tttx/p-72e7f7dd.entry.js +0 -3
  124. package/dist/tttx/p-c4162029.entry.js +0 -1
  125. package/dist/tttx/p-eb126fd0.entry.js +0 -1
@@ -2,385 +2,469 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const index = require('./index-457ca775.js');
5
+ const index = require('./index-76f14107.js');
6
+ const domsanitiser_options = require('./domsanitiser.options-277161b9.js');
6
7
 
7
- /**
8
- * Validates the input field on focusout event by checking its validity state,
9
- * sets an error message if there's an issue, and emits a "dataChanged" event to
10
- * the parent component with the field name and its new value.
11
- *
12
- * @param {Event} event - The focusout event triggered by the input field.
13
- * @return {void}
14
- */
15
- function validityCheck(event) {
16
- var _a, _b, _c, _d;
17
- event.preventDefault();
18
- const target = event.target;
19
- let hasError = true;
20
- let errorMessage = '';
21
- // validity object on HTML5 inputs has the following options
22
- // badInput
23
- // customError
24
- // patternMismatch
25
- // rangeOverflow
26
- // rangeUnderflow
27
- // stepMismatch
28
- // tooLong
29
- // tooShort
30
- // typeMismatch
31
- // valid
32
- // valueMissing
33
- // customErrors can be set with
34
- // target.setCustomValidity('custom error!');
35
- // and cleared with
36
- // target.setCustomValidity('');
37
- // Check the validity of the input field and set an error message if needed
38
- switch (true) {
39
- // The field is required, but has no value
40
- case target.validity.valueMissing:
41
- errorMessage = (_a = target.dataset.required) !== null && _a !== void 0 ? _a : 'This field is required';
42
- break;
43
- // The field's value does not match the expected pattern
44
- case target.validity.patternMismatch:
45
- errorMessage = (_b = target.dataset.pattern) !== null && _b !== void 0 ? _b : 'Incorrect format';
46
- break;
47
- // The field's value is not of the correct input type
48
- case target.validity.badInput:
49
- // IE string in a number field
50
- errorMessage = (_c = target.dataset.badinput) !== null && _c !== void 0 ? _c : 'Wrong input type';
51
- break;
52
- // The field's value is above or below the range set in the "min" and "max" attributes
53
- case target.validity.rangeOverflow || target.validity.rangeUnderflow:
54
- // IE date or number is above or below value set in min or max tags
55
- errorMessage = (_d = target.dataset.range) !== null && _d !== void 0 ? _d : 'Invalid value';
56
- break;
57
- // No error detected
58
- default:
59
- hasError = false;
60
- }
61
- // Return the error state
62
- return { target, hasError, errorMessage };
8
+ /**
9
+ * Validates the input field on focusout event by checking its validity state,
10
+ * sets an error message if there's an issue, and emits a "dataChanged" event to
11
+ * the parent component with the field name and its new value.
12
+ *
13
+ * @param {Event} event - The focusout event triggered by the input field.
14
+ * @return {void}
15
+ */
16
+ function validityCheck(event) {
17
+ var _a, _b, _c, _d;
18
+ event.preventDefault();
19
+ const target = event.target;
20
+ let hasError = true;
21
+ let errorMessage = '';
22
+ // validity object on HTML5 inputs has the following options
23
+ // badInput
24
+ // customError
25
+ // patternMismatch
26
+ // rangeOverflow
27
+ // rangeUnderflow
28
+ // stepMismatch
29
+ // tooLong
30
+ // tooShort
31
+ // typeMismatch
32
+ // valid
33
+ // valueMissing
34
+ // customErrors can be set with
35
+ // target.setCustomValidity('custom error!');
36
+ // and cleared with
37
+ // target.setCustomValidity('');
38
+ // Check the validity of the input field and set an error message if needed
39
+ switch (true) {
40
+ // The field is required, but has no value
41
+ case target.validity.valueMissing:
42
+ errorMessage = (_a = target.dataset.required) !== null && _a !== void 0 ? _a : 'This field is required';
43
+ break;
44
+ // The field's value does not match the expected pattern
45
+ case target.validity.patternMismatch:
46
+ errorMessage = (_b = target.dataset.pattern) !== null && _b !== void 0 ? _b : 'Incorrect format';
47
+ break;
48
+ // The field's value is not of the correct input type
49
+ case target.validity.badInput:
50
+ // IE string in a number field
51
+ errorMessage = (_c = target.dataset.badinput) !== null && _c !== void 0 ? _c : 'Wrong input type';
52
+ break;
53
+ // The field's value is above or below the range set in the "min" and "max" attributes
54
+ case target.validity.rangeOverflow || target.validity.rangeUnderflow:
55
+ // IE date or number is above or below value set in min or max tags
56
+ errorMessage = (_d = target.dataset.range) !== null && _d !== void 0 ? _d : 'Invalid value';
57
+ break;
58
+ case target.validity.customError:
59
+ errorMessage = target.validationMessage;
60
+ break;
61
+ // No error detected
62
+ default:
63
+ hasError = false;
64
+ }
65
+ // Return the error state
66
+ return { target, hasError, errorMessage };
63
67
  }
64
68
 
65
- /**
66
- * Sets the error state of an input field by updating its class and error message.
67
- * If an error was detected, it sets the input field's class to "invalid" and
68
- * displays the error message in an error bubble. If no error was detected,
69
- * it removes the "invalid" class from the input field and clears the error bubble.
70
- *
71
- * @param {HTMLInputElement} target - The input field to update.
72
- * @param {boolean} hasError - Whether an error was detected in the field.
73
- * @param {string} errorMessage - The error message to display (if any).
74
- * @return {void}
75
- */
76
- function setErrorState(target, hasError, errorMessage) {
77
- // Find the error bubble element for the input field
78
- const errorBubble = target.parentElement.querySelector('.errorBubble');
79
- // If an error was detected, set the input field's class to "invalid" and display the error message in the error bubble
80
- if (hasError) {
81
- target.className = 'invalid';
82
- errorBubble.classList.add('visible');
83
- const errorIcon = document.createElement('span');
84
- // Set the class of the error icon to a pre-defined CSS class that specifies the icon's appearance
85
- errorIcon.className = 'material-symbols-rounded';
86
- // Set the text content of the error icon to the word "warning"
87
- errorIcon.textContent = 'warning';
88
- // errorBubble.replaceChildren cannot be used here because the tests don't support this new feature :(
89
- errorBubble.innerHTML = '';
90
- errorBubble.append(errorIcon);
91
- errorBubble.append(errorMessage);
92
- // errorBubble.replaceChildren(errorIcon, errorMessage);
93
- }
94
- // If no error was detected, remove the "invalid" class from the input field and clear the error bubble
95
- else {
96
- errorBubble.classList.remove('visible');
97
- target.className = '';
98
- errorBubble.innerHTML = '';
99
- }
69
+ /**
70
+ * Sets the error state of an input field by updating its class and error message.
71
+ * If an error was detected, it sets the input field's class to "invalid" and
72
+ * displays the error message in an error bubble. If no error was detected,
73
+ * it removes the "invalid" class from the input field and clears the error bubble.
74
+ *
75
+ * @param {HTMLInputElement} target - The input field to update.
76
+ * @param {boolean} hasError - Whether an error was detected in the field.
77
+ * @param {string} errorMessage - The error message to display (if any).
78
+ * @return {void}
79
+ */
80
+ function setErrorState(target, hasError, errorMessage) {
81
+ // Find the error bubble element for the input field
82
+ const errorBubble = target.parentElement.querySelector('.errorBubble');
83
+ // If an error was detected, set the input field's class to "invalid" and display the error message in the error bubble
84
+ if (hasError) {
85
+ target.classList.add('invalid');
86
+ errorBubble.classList.add('visible');
87
+ const errorIcon = document.createElement('span');
88
+ // Set the class of the error icon to a pre-defined CSS class that specifies the icon's appearance
89
+ errorIcon.className = 'material-symbols-rounded';
90
+ // Set the text content of the error icon to the word "warning"
91
+ errorIcon.textContent = 'warning';
92
+ // errorBubble.replaceChildren cannot be used here because the tests don't support this new feature :(
93
+ errorBubble.innerHTML = '';
94
+ errorBubble.append(errorIcon);
95
+ errorBubble.append(errorMessage);
96
+ // errorBubble.replaceChildren(errorIcon, errorMessage);
97
+ }
98
+ // If no error was detected, remove the "invalid" class from the input field and clear the error bubble
99
+ else {
100
+ errorBubble.classList.remove('visible');
101
+ target.classList.remove('invalid');
102
+ errorBubble.innerHTML = '';
103
+ }
100
104
  }
101
105
 
102
- const tttxFormCss = ".material-symbols-rounded{font-variation-settings:\"FILL\" 1, \"wght\" 400, \"GRAD\" 0, \"opsz\" 24}.material-symbols-rounded{font-variation-settings:\"FILL\" 1, \"wght\" 400, \"GRAD\" 0, \"opsz\" 24}.material-symbols-rounded{font-family:\"Material Symbols Rounded\", sans-serif;font-weight:normal;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;color:#9e9e9e}.icon-left,.icon-right{flex-basis:24px}.icon-left span,.icon-right span{font-size:24px;line-height:24px;text-align:center;display:block;width:24px;height:24px;margin-top:4px}.icon-left span{margin-left:4px}.icon-right span{margin-right:4px}.icon-right{margin-top:5px}.icon-left{margin-top:5px;margin-left:4px}.iconleft .input{padding-left:4px}.iconright .input{padding-right:4px}.input-icon{position:absolute;margin-top:9px;margin-left:4px}.errormsg{display:flex;justify-content:center;align-items:center;float:left;margin-bottom:16px;box-sizing:border-box;background-color:transparent;height:26px;font-size:14px;line-height:16px;border-radius:none;z-index:2;color:#dc0000}.errormsg .validationicon{width:16px;height:16px;font-size:16px;line-height:19px;margin-right:4px;vertical-align:middle;color:#dc0000}.danger{color:#dc0000}.optional{color:#757575;font-weight:normal}label.inputBlock{display:block;position:relative;line-height:21px}label.inputInline{display:flex;white-space:nowrap;align-items:center}label.inputInline .input-container{margin:0 4px;width:100%;display:flex;align-items:center;gap:4px;position:relative}label{font-weight:500;font-size:16px;line-height:19px;margin-bottom:16px}input:not([type=submit]){font-family:\"Roboto\", serif;box-sizing:border-box;width:100%;height:36px;padding:0 16px;font-size:16px;line-height:19px;border:1px solid #d5d5d5;border-radius:4px;margin-top:4px}input[type=date]{background:white;display:block;min-width:calc(100% - 18px);line-height:37px}@media (max-width: 600px){input[type=date]{padding-top:6px}}input.invalid:invalid,input.standalone.invalid{border:1px solid #dc0000}.input-icon~input{padding:0 32px}input~.errorBubble{position:relative;font-size:14px;line-height:16px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000;display:flex;align-content:center;align-items:center;justify-items:center;margin-top:4px}input~.errorBubble:not(.visible){display:none}input~.errorBubble span{color:#dc0000;font-size:16px;margin-right:4px}input.invalid:invalid~.errorBubble{position:relative;font-size:14px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000}input:focus{border-color:#1479c6}input:focus-visible{outline:none}.secondarylabel{color:#757575;font-size:14px;line-height:16px;font-weight:normal;display:flex;margin-top:4px}label.inputBlock.readonly{pointer-events:none;user-select:none;color:gray}input[readonly]{cursor:default;pointer-events:none;user-select:none;color:gray}.button{font-family:Roboto, serif;box-sizing:border-box;height:36px;min-width:36px;padding:0;margin:0;background:transparent;color:#212121;border:1px solid #c8c8c8;border-radius:4px;text-transform:uppercase;display:flex;justify-content:left;align-items:center;font-size:14px;font-weight:400}.button-content{display:block;padding:0 16px}.icon-left,.icon-right{margin-top:4px}.iconleft{padding-left:8px}.iconleft .button-content{padding-left:4px}.iconright{padding-right:8px}.iconright .button-content{padding-right:4px}.notext{padding:0 6px}.button:hover{background:rgba(17, 17, 17, 0.1);border:1px solid #D5D5D5}.button:active{background:rgba(17, 17, 17, 0.2);border:1px solid #D5D5D5}.primary{background:#1479c6;border:1px solid #1479c6;color:white}.primary:hover{background:#146EB3;border:1px solid #146EB3}.primary:active{background:#1464A2;border:1px solid #1464A2}.borderless{background:transparent;border:none;color:#212121}.borderless:hover{background:rgba(17, 17, 17, 0.1);border:none}.borderless:active{background:rgba(17, 17, 17, 0.2);border:none}.danger{background:#DC0000;border:1px solid #DC0000;color:white}.danger:hover{background:#C60000;border:1px solid #C60000}.danger:active{background:#B00000;border:1px solid #B00000}.disabled{background:#aeaeae;border:none;color:#4c4c4c;cursor:not-allowed}.disabled:hover{background:#aeaeae;border:none;color:#4c4c4c;cursor:not-allowed}.disabled:active{background:#aeaeae;border:none;color:#4c4c4c;cursor:not-allowed}:host{display:block}fieldset{margin:0;padding:0;border:none}input[type=submit]{margin-left:auto}";
106
+ const tttxFormCss = ".material-symbols-rounded{font-variation-settings:\"FILL\" 1, \"wght\" 400, \"GRAD\" 0, \"opsz\" 24}.material-symbols-rounded{font-variation-settings:\"FILL\" 1, \"wght\" 400, \"GRAD\" 0, \"opsz\" 24}.material-symbols-rounded{font-family:\"Material Symbols Rounded\", sans-serif;font-weight:normal;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;color:#9e9e9e}.icon-left,.icon-right{flex-basis:24px}.icon-left span,.icon-right span{font-size:24px;line-height:24px;text-align:center;display:block;width:24px;height:24px;margin-top:4px}.icon-left span{margin-left:4px}.icon-right span{margin-right:4px}.icon-right{margin-top:5px}.icon-left{margin-top:5px;margin-left:4px}.iconleft .input{padding-left:4px}.iconright .input{padding-right:4px}.input-icon{position:absolute;margin-top:9px;margin-left:4px}.errormsg{display:flex;justify-content:center;align-items:center;float:left;margin-bottom:16px;box-sizing:border-box;background-color:transparent;height:26px;font-size:14px;line-height:16px;border-radius:none;z-index:2;color:#dc0000}.errormsg .validationicon{width:16px;height:16px;font-size:16px;line-height:19px;margin-right:4px;vertical-align:middle;color:#dc0000}.danger{color:#dc0000}.optional{color:#757575;font-weight:normal}label.inputBlock{display:block;position:relative;line-height:21px}label.inputInline{display:flex;white-space:nowrap;align-items:center}label.inputInline .input-container{margin:0 4px;width:100%;display:flex;align-items:center;gap:4px;position:relative}label{font-weight:500;font-size:16px;line-height:19px;margin-bottom:16px}input:not([type=submit]){font-family:\"Roboto\", serif;box-sizing:border-box;width:100%;height:36px;padding:0 16px;font-size:16px;line-height:19px;border:1px solid #d5d5d5;border-radius:4px;margin-top:4px}input[type=date]{background:white;display:block;min-width:calc(100% - 18px);line-height:37px}@media (max-width: 600px){input[type=date]{padding-top:6px}}input.invalid:invalid,input.standalone.invalid{border:1px solid #dc0000}.input-icon~input{padding:0 32px}input~.errorBubble{position:relative;font-size:14px;line-height:16px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000;display:flex;align-content:center;align-items:center;justify-items:center;margin-top:4px}input~.errorBubble:not(.visible){display:none}input~.errorBubble span{color:#dc0000;font-size:16px;margin-right:4px}input.invalid:invalid~.errorBubble{position:relative;font-size:14px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000}input:focus{border-color:#1479c6}input:focus-visible{outline:none}.secondarylabel{color:#757575;font-size:14px;line-height:16px;font-weight:normal;display:flex;margin-top:4px}label.inputBlock.readonly{pointer-events:none;user-select:none;color:gray}input[readonly]{cursor:default;pointer-events:none;user-select:none;color:gray}button{cursor:pointer}.button{font-family:Roboto, serif;box-sizing:border-box;height:36px;min-width:36px;padding:0;margin:0;background:transparent;color:#212121;border:1px solid #c8c8c8;border-radius:4px;text-transform:uppercase;display:flex;justify-content:left;align-items:center;font-size:14px;font-weight:400}.button-content{display:block;padding:0 16px}.icon-left,.icon-right{margin-top:4px}.iconleft{padding-left:8px}.iconleft .button-content{padding-left:4px}.iconright{padding-right:8px}.iconright .button-content{padding-right:4px}.notext{padding:0 6px}.button:hover{background:rgba(17, 17, 17, 0.1);border:1px solid #D5D5D5}.button:active{background:rgba(17, 17, 17, 0.2);border:1px solid #D5D5D5}.primary{background:#1479c6;border:1px solid #1479c6;color:white}.primary:hover{background:#146EB3;border:1px solid #146EB3}.primary:active{background:#1464A2;border:1px solid #1464A2}.borderless{background:transparent;border:none;color:#212121}.borderless:hover{background:rgba(17, 17, 17, 0.1);border:none}.borderless:active{background:rgba(17, 17, 17, 0.2);border:none}.danger{background:#DC0000;border:1px solid #DC0000;color:white}.danger:hover{background:#C60000;border:1px solid #C60000}.danger:active{background:#B00000;border:1px solid #B00000}.disabled{background:#aeaeae;border:none;color:#4c4c4c;cursor:not-allowed}.disabled:hover{background:#aeaeae;border:none;color:#4c4c4c;cursor:not-allowed}.disabled:active{background:#aeaeae;border:none;color:#4c4c4c;cursor:not-allowed}:host{display:block}fieldset{margin:0;padding:0;border:none}label.inputBlock.inlineBlock{display:inline-block}.inlineLabel{font-weight:400;display:inline-block;vertical-align:top;padding-top:4px}input[type=checkbox]{width:18px;height:18px}input~label{font-weight:400}select{font-family:\"Roboto\", serif;box-sizing:border-box;width:100%;height:36px;padding:0 16px;font-size:16px;border:1px solid #d5d5d5;border-radius:4px;margin-top:4px}.placeholder{color:#9e9e9e}.placeholder option{color:initial}select.invalid:invalid{border:1px solid #dc0000}select~.errorBubble{position:relative;font-size:14px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000;display:flex;align-content:center;align-items:center;justify-items:center}select~.errorBubble:not(.visible){visibility:hidden}select~.errorBubble span{color:#dc0000;font-size:16px;margin-right:4px;height:16px}select.invalid:invalid~.errorBubble{position:relative;font-size:14px;font-weight:normal;width:100%;font-family:\"Roboto\", sans-serif;color:#dc0000;visibility:visible}select:focus{border-color:#1479c6}select:focus-visible{outline:none}.button{padding:0 16px}.footer{display:flex;gap:16px;flex-direction:row-reverse}";
103
107
 
104
- const TttxForm = class {
105
- constructor(hostRef) {
106
- index.registerInstance(this, hostRef);
107
- this.dataSubmitted = index.createEvent(this, "dataSubmitted", 7);
108
- this.dataChanged = index.createEvent(this, "dataChanged", 7);
109
- // Create a new template element using the HTMLTemplateElement interface.
110
- this.template = document.createElement('template');
111
- this.formschema = undefined;
112
- this.data = undefined;
113
- }
114
- // This method is called whenever the "formschema" property changes
115
- onFormSchemaChange(newValue) {
116
- // Check if the new value is a string, indicating that it needs to be parsed
117
- if (typeof newValue === 'string') {
118
- // Parse the string and set the "_formSchema" property
119
- this._formSchema = JSON.parse(newValue);
120
- }
121
- else {
122
- // If the new value is already an object, set the "_formSchema" property directly
123
- this._formSchema = newValue;
124
- }
125
- }
126
- onDataChange(newValue) {
127
- if (typeof newValue === 'string') {
128
- this._data = JSON.parse(newValue);
129
- }
130
- else {
131
- this._data = newValue;
132
- }
133
- }
134
- /**
135
- * Handles the focus event for a form field and emits a "dataChanged" event
136
- * to the parent component with the field name and its new value.
137
- *
138
- * @param {ChangeEvent} event - The focus event triggered by the field.
139
- * @return {void}
140
- */
141
- fieldChanged(event) {
142
- // Extract the name and value of the field from the event
143
- const fieldName = event.target.name;
144
- const fieldValue = event.target.value;
145
- // Emit an event to signal that the field's data has changed
146
- this.dataChanged.emit({ name: fieldName, value: fieldValue });
147
- }
148
- async submit() {
149
- this.submitButton.click();
150
- }
151
- /**
152
- * Submits the form data to the server.
153
- *
154
- * @param {SubmitEvent} event - The event object for the form submission.
155
- * @returns {void}
156
- *
157
- * @example
158
- * const form = document.getElementById('myForm');
159
- * form.addEventListener('submit', (event) => {
160
- * doSubmit(event);
161
- * });
162
- */
163
- doSubmit(event) {
164
- // prevent the form from submitting normally
165
- event.preventDefault();
166
- // create a new FormData object with the form data
167
- const formData = new FormData(event.target);
168
- // emit the form data through the `dataSubmitted` event
169
- this.dataSubmitted.emit(formData);
170
- }
171
- // This method is called before the component is loaded into the DOM
172
- componentWillLoad() {
173
- // Initialize the form schema by calling the "onFormSchemaChange" method with the current "formschema" property
174
- this.onFormSchemaChange(this.formschema);
175
- if (this.data) {
176
- this.onDataChange(this.data);
177
- }
178
- }
179
- // This method is called before the component is rendered
180
- componentWillRender() {
181
- // Clear the template to account for a potential re-render scenario
182
- this.template = document.createElement('template');
183
- // Populate the form from the form schema
184
- this.populateFormFromSchema();
185
- }
186
- /**
187
- * Creates a new HTMLInputElement with the specified name, type, and placeholder (if any),
188
- * and sets its autocomplete and autocapitalization properties to off.
189
- *
190
- * @param {string} formKey - The name of the input field, as specified in the form schema.
191
- * @param {Object} formProperties - An object containing additional properties for the input field, such as its type and placeholder value.
192
- * @param {string} formProperties.type - The type of the input field (e.g., "text", "email", "number", etc.).
193
- * @param {string} [formProperties.placeholder] - An optional placeholder value to display in the input field.
194
- * @return {HTMLInputElement} - The new input element.
195
- */
196
- createInput(formKey, formProperties) {
197
- var _a;
198
- // Create a new <input> element with the specified name and type
199
- const input = document.createElement('input');
200
- input.name = formKey;
201
- input.type = formProperties.type;
202
- // Set the placeholder attribute to the specified value (if any)
203
- input.placeholder = (_a = formProperties.placeholder) !== null && _a !== void 0 ? _a : '';
204
- // Disable autocomplete and autocapitalization
205
- input.autocomplete = 'off';
206
- input.autocapitalize = 'off';
207
- if (formProperties.readonly) {
208
- //input.setAttribute('readonly', 'true');
209
- input.readOnly = true;
210
- }
211
- // Return the input element
212
- return input;
213
- }
214
- /**
215
- * Applies validation attributes to an input element based on the specified validation object.
216
- * If a certain property is present in the object, it will set the corresponding attribute on
217
- * the input element (e.g., "required" will set the "required" and "data-required" attributes,
218
- * "pattern" will set the "pattern" and "data-pattern" attributes, etc.).
219
- *
220
- * @param {HTMLInputElement} input - The input element to apply validation attributes to.
221
- * @param {Object} validation - An object containing the validation rules for the input field.
222
- * @param {Object} [validation.required] - An object containing a "message" property to display if the field is required.
223
- * @param {Object} [validation.pattern] - An object containing a "pattern" property to match against the field value, and a "message" property to display if the pattern doesn't match.
224
- * @param {Object} [validation.badInput] - An object containing a "message" property to display if the field value is invalid.
225
- * @param {Object} [validation.minmax] - An object containing "min" and "max" properties to validate the field value against, and a "message" property to display if the value is out of range.
226
- * @param {string} [validation.maxlength] - The maximum length of the input field.
227
- * @return {void}
228
- */
229
- applyValidation(input, validation) {
230
- var _a, _b;
231
- // If the "required" property is present, add the "required" attribute to the input element and
232
- // set its "data-required" attribute to the specified message (if any)
233
- if (validation.required) {
234
- input.setAttribute('required', '');
235
- input.setAttribute('data-required', (_a = validation.required.message) !== null && _a !== void 0 ? _a : '');
236
- }
237
- // If the "pattern" property is present, add the "pattern" attribute to the input element and set
238
- // its "data-pattern" attribute to the specified message (if any)
239
- if (validation.pattern) {
240
- input.setAttribute('pattern', validation.pattern.pattern);
241
- input.setAttribute('data-pattern', (_b = validation.pattern.message) !== null && _b !== void 0 ? _b : '');
242
- }
243
- // If the "badInput" property is present, set the input element's "data-badinput" attribute to
244
- // the specified message
245
- if (validation.badInput) {
246
- input.setAttribute('data-badinput', validation.badInput.message);
247
- }
248
- // If the "minmax" property is present, add the "min" and "max" attributes to the input element
249
- // and set its "data-range" attribute to the specified message (if any)
250
- if (validation.minmax) {
251
- input.setAttribute('min', validation.minmax.min);
252
- input.setAttribute('max', validation.minmax.max);
253
- input.setAttribute('data-range', validation.minmax.message);
254
- }
255
- // If the "maxlength" property is present, add the "maxlength" attribute to the input element
256
- if (validation.maxlength) {
257
- input.setAttribute('maxlength', validation.maxlength);
258
- }
259
- }
260
- // Create a new error bubble element
261
- createErrorBubble() {
262
- // Create a new <div> element with the "errorBubble" class
263
- const errorBubble = document.createElement('div');
264
- errorBubble.className = 'errorBubble';
265
- // Return the error bubble element
266
- return errorBubble;
267
- }
268
- /**
269
- * Creates a new <label> element with the "inputBlock" class and the specified label text,
270
- * and appends the input element and error bubble element to it. If the form property has
271
- * no validation object, it adds an "optional" span element to the label.
272
- *
273
- * @param {Object} formProperties - An object containing properties for the form field, including its label text and validation rules.
274
- * @param {HTMLInputElement} input - The input element to associate with the label.
275
- * @param {HTMLDivElement} errorBubble - The error bubble element to display error messages in.
276
- * @return {HTMLLabelElement} - The new label element.
277
- */
278
- createLabel(formProperties, input, errorBubble) {
279
- // Create a new <label> element with the "inputBlock" class and the specified text
280
- const label = document.createElement('label');
281
- label.className = 'inputBlock';
282
- label.innerText = formProperties.label;
283
- // If the form property has no validation object, add an "optional" span element to the label
284
- if (!formProperties.validation) {
285
- const optionalSpan = document.createElement('span');
286
- optionalSpan.className = 'optional';
287
- optionalSpan.innerHTML = '&nbsp;(optional)';
288
- label.appendChild(optionalSpan);
289
- }
290
- if (formProperties.readonly) {
291
- label.classList.add('readonly');
292
- }
293
- // Append the input element and error bubble element to the label
294
- label.appendChild(input);
295
- label.appendChild(errorBubble);
296
- // Return the label element
297
- return label;
298
- }
299
- /**
300
- * Populates the form template with input fields and labels based on the properties of the
301
- * current form schema. For each property in the schema, it creates an input element, applies
302
- * any validation rules to it, creates an error bubble and label element, and appends them
303
- * to the form template. Finally, it creates and appends a submit button element to the form.
304
- *
305
- * @return {void}
306
- */
307
- populateFormFromSchema() {
308
- // If there is no form schema, return early
309
- if (!this._formSchema)
310
- return;
311
- // Get the properties of the form schema and their keys
312
- const properties = this._formSchema.properties;
313
- const propertyKeys = Object.keys(properties);
314
- // Loop through each property key and create an input, label, and error bubble for it
315
- propertyKeys.forEach(formKey => {
316
- const formItem = properties[formKey];
317
- const formProperties = formItem.form;
318
- const input = this.createInput(formKey, formProperties);
319
- // If the form property has validation, apply it to the input
320
- if (formProperties.validation) {
321
- this.applyValidation(input, formProperties.validation);
322
- }
323
- // Create an error bubble and label element for the input
324
- const errorBubble = this.createErrorBubble();
325
- const label = this.createLabel(formProperties, input, errorBubble);
326
- // Append the label element to the form template
327
- this.template.content.append(label);
328
- });
329
- }
330
- /**
331
- * Clones the form template and binds event listeners to its input elements. First, it checks if
332
- * there is a form schema present. If so, it clones the template's content, binds events to form
333
- * input elements, and appends the cloned form elements to the fieldset. The event listeners include
334
- * "oninvalid" (to check input validity on submit), "onblur" (to check input validity on blur),
335
- * "onkeyup" (to handle changes in input fields), and "onchange" (to handle changes in select fields).
336
- *
337
- * @return {void}
338
- */
339
- componentDidRender() {
340
- // If there's no form schema, return
341
- if (!this._formSchema) {
342
- return;
343
- }
344
- // Clone the template's content and store it in a variable
345
- const formItems = this.template.content.cloneNode(true);
346
- // Bind event listeners to form elements
347
- const properties = this._formSchema.properties;
348
- const propertyKeys = Object.keys(properties);
349
- propertyKeys.forEach((formKey) => {
350
- const formInput = formItems.querySelector(`[name=${formKey}]`);
351
- // Bind events to form input elements
352
- formInput.oninvalid = this.validityCheckWrapper.bind(this);
353
- formInput.onblur = this.validityCheckWrapper.bind(this);
354
- formInput.onkeyup = this.fieldChanged.bind(this);
355
- formInput.onchange = this.fieldChanged.bind(this);
356
- if (this._data && this._data[formKey] !== undefined && this._data[formKey] !== null) {
357
- formInput.value = this._data[formKey];
358
- }
359
- });
360
- // Append the cloned form elements to the fieldset
361
- this.fieldset.appendChild(formItems);
362
- }
363
- validityCheckWrapper(event) {
364
- const { target, hasError, errorMessage } = validityCheck(event);
365
- setErrorState(target, hasError, errorMessage);
366
- }
367
- /**
368
- * Renders the component's template as a form element with a fieldset container. The form's
369
- * "onSubmit" event is bound to the "doSubmit" function, which handles the form submission
370
- * and emits a "dataSubmitted" event with the form data. The fieldset element is assigned
371
- * to the "fieldset" instance variable using a ref, so it can be populated with form elements
372
- * later on.
373
- *
374
- * @return {JSX.Element} - The rendered form template as a JSX element.
375
- */
376
- render() {
377
- return (index.h(index.Host, null, index.h("form", { onSubmit: this.doSubmit.bind(this) }, index.h("fieldset", { ref: el => (this.fieldset = el) }), index.h("input", { type: 'submit', ref: el => (this.submitButton = el), style: { display: 'none' } }))));
378
- }
379
- static get watchers() { return {
380
- "formschema": ["onFormSchemaChange"],
381
- "data": ["onDataChange"]
382
- }; }
383
- };
108
+ const TttxForm = class {
109
+ constructor(hostRef) {
110
+ index.registerInstance(this, hostRef);
111
+ this.dataSubmitted = index.createEvent(this, "dataSubmitted", 7);
112
+ this.dataChanged = index.createEvent(this, "dataChanged", 7);
113
+ // Create a new template element using the HTMLTemplateElement interface.
114
+ this.template = document.createElement('template');
115
+ this.formschema = undefined;
116
+ this.data = undefined;
117
+ }
118
+ // This method is called whenever the "formschema" property changes
119
+ onFormSchemaChange(newValue) {
120
+ // If the formSchema changes and the form data is uncontrolled, store the data since the fields will be removed to avoid form duplication
121
+ if (!this.data && this.form && this._formSchema) {
122
+ const formData = new FormData(this.form);
123
+ this._data = Object.fromEntries(Object.keys(this._formSchema.properties).map((formKey) => {
124
+ return [
125
+ formKey,
126
+ formData.get(formKey)
127
+ ];
128
+ }));
129
+ }
130
+ // Check if the new value is a string, indicating that it needs to be parsed
131
+ if (typeof newValue === 'string') {
132
+ // Parse the string and set the "_formSchema" property
133
+ this._formSchema = JSON.parse(newValue);
134
+ }
135
+ else {
136
+ // If the new value is already an object, set the "_formSchema" property directly
137
+ this._formSchema = newValue;
138
+ }
139
+ }
140
+ onDataChange(newValue) {
141
+ if (typeof newValue === 'string') {
142
+ this._data = JSON.parse(newValue);
143
+ }
144
+ else {
145
+ this._data = newValue;
146
+ }
147
+ }
148
+ /**
149
+ * Handles the focus event for a form field and emits a "dataChanged" event
150
+ * to the parent component with the field name and its new value.
151
+ *
152
+ * @param {ChangeEvent} event - The focus event triggered by the field.
153
+ * @return {void}
154
+ */
155
+ fieldChanged(event) {
156
+ // Extract the name and value of the field from the event
157
+ const fieldName = event.target.name;
158
+ const fieldValue = event.target.value;
159
+ // Emit an event to signal that the field's data has changed
160
+ this.dataChanged.emit({ name: fieldName, value: fieldValue });
161
+ }
162
+ async submit() {
163
+ this.submitButton.click();
164
+ }
165
+ /**
166
+ * Submits the form data to the server.
167
+ *
168
+ * @param {SubmitEvent} event - The event object for the form submission.
169
+ * @returns {void}
170
+ *
171
+ * @example
172
+ * const form = document.getElementById('myForm');
173
+ * form.addEventListener('submit', (event) => {
174
+ * doSubmit(event);
175
+ * });
176
+ */
177
+ doSubmit(event) {
178
+ // prevent the form from submitting normally
179
+ event.preventDefault();
180
+ // create a new FormData object with the form data
181
+ const formData = new FormData(event.target);
182
+ // emit the form data through the `dataSubmitted` event
183
+ this.dataSubmitted.emit(formData);
184
+ }
185
+ // This method is called before the component is loaded into the DOM
186
+ componentWillLoad() {
187
+ // Initialize the form schema by calling the "onFormSchemaChange" method with the current "formschema" property
188
+ this.onFormSchemaChange(this.formschema);
189
+ if (this.data) {
190
+ this.onDataChange(this.data);
191
+ }
192
+ }
193
+ // This method is called before the component is rendered
194
+ componentWillRender() {
195
+ // Clear the template to account for a potential re-render scenario
196
+ this.template = document.createElement('template');
197
+ // Populate the form from the form schema
198
+ this.populateFormFromSchema();
199
+ }
200
+ /**
201
+ * Creates a new HTMLSelectElement with a set of options.
202
+ *
203
+ * @param {string} formKey - The name of the dropdown field, as specified in the form schema.
204
+ * @param {Object} formProperties - An object containing additional properties, such as the field type and options properties.
205
+ * @param {'select'} formProperties.type - The type of form field. In this case, it will always be "select".
206
+ * @param {Object} formProperties.validation - A set of validation rules for the field.
207
+ * @param {Object[]} formProperties.options - A list of properties to pass to the select options.
208
+ * @param {string} formProperties.options.label - The visible value of the option.
209
+ * @param {string} formProperties.options.value - The actual value of the option.
210
+ */
211
+ createSelect(formKey, formProperties) {
212
+ const select = document.createElement('select');
213
+ select.setAttribute('name', formKey);
214
+ formProperties.options.forEach(optionProperties => {
215
+ this.appendOption(select, optionProperties);
216
+ });
217
+ return select;
218
+ }
219
+ /**
220
+ * Appends an option to a select element
221
+ *
222
+ * @param {HTMLSelectElement} select - The select elements to attach the option to.
223
+ * @param {value} value - The value of the option.
224
+ * @param {label} label - The label which will be displayed on the form for the option.
225
+ */
226
+ appendOption(select, optionProperties) {
227
+ const option = document.createElement('option');
228
+ option.setAttribute('value', optionProperties.value);
229
+ if (optionProperties.placeholder) {
230
+ option.setAttribute('disabled', '');
231
+ option.setAttribute('selected', '');
232
+ option.setAttribute('hidden', '');
233
+ select.classList.add('placeholder');
234
+ }
235
+ if (optionProperties.label)
236
+ option.innerHTML = domsanitiser_options.purify.sanitize(optionProperties.label, domsanitiser_options.domSanitiserOptions);
237
+ select.appendChild(option);
238
+ }
239
+ /**
240
+ * Creates a new HTMLInputElement with the specified name, type, and placeholder (if any),
241
+ * and sets its autocomplete and autocapitalization properties to off.
242
+ *
243
+ * @param {string} formKey - The name of the input field, as specified in the form schema.
244
+ * @param {Object} formProperties - An object containing additional properties for the input field, such as its type and placeholder value.
245
+ * @param {string} formProperties.type - The type of the input field (e.g., "text", "email", "number", etc.).
246
+ * @param {string} [formProperties.placeholder] - An optional placeholder value to display in the input field.
247
+ * @return {HTMLInputElement} - The new input element.
248
+ */
249
+ createInput(formKey, formProperties) {
250
+ var _a;
251
+ // Create a new <input> element with the specified name and type
252
+ const input = document.createElement('input');
253
+ input.name = formKey;
254
+ input.type = formProperties.type;
255
+ // Set the placeholder attribute to the specified value (if any)
256
+ input.placeholder = (_a = formProperties.placeholder) !== null && _a !== void 0 ? _a : '';
257
+ // Disable autocomplete and autocapitalization
258
+ input.autocomplete = 'off';
259
+ input.autocapitalize = 'off';
260
+ if (formProperties.readonly) {
261
+ input.readOnly = true;
262
+ }
263
+ // Return the input element
264
+ return input;
265
+ }
266
+ /**
267
+ * Applies validation attributes to an input element based on the specified validation object.
268
+ * If a certain property is present in the object, it will set the corresponding attribute on
269
+ * the input element (e.g., "required" will set the "required" and "data-required" attributes,
270
+ * "pattern" will set the "pattern" and "data-pattern" attributes, etc.).
271
+ *
272
+ * @param {HTMLInputElement} input - The input element to apply validation attributes to.
273
+ * @param {Object} validation - An object containing the validation rules for the input field.
274
+ * @param {Object} [validation.required] - An object containing a "message" property to display if the field is required.
275
+ * @param {Object} [validation.pattern] - An object containing a "pattern" property to match against the field value, and a "message" property to display if the pattern doesn't match.
276
+ * @param {Object} [validation.badInput] - An object containing a "message" property to display if the field value is invalid.
277
+ * @param {Object} [validation.minmax] - An object containing "min" and "max" properties to validate the field value against, and a "message" property to display if the value is out of range.
278
+ * @param {string} [validation.maxlength] - The maximum length of the input field.
279
+ * @return {void}
280
+ */
281
+ applyValidation(input, validation) {
282
+ var _a, _b;
283
+ // If the "required" property is present, add the "required" attribute to the input element and
284
+ // set its "data-required" attribute to the specified message (if any)
285
+ if (validation.required) {
286
+ input.setAttribute('required', '');
287
+ input.setAttribute('data-required', (_a = validation.required.message) !== null && _a !== void 0 ? _a : '');
288
+ }
289
+ // If the "pattern" property is present, add the "pattern" attribute to the input element and set
290
+ // its "data-pattern" attribute to the specified message (if any)
291
+ if (validation.pattern) {
292
+ input.setAttribute('pattern', validation.pattern.pattern);
293
+ input.setAttribute('data-pattern', (_b = validation.pattern.message) !== null && _b !== void 0 ? _b : '');
294
+ }
295
+ // If the "badInput" property is present, set the input element's "data-badinput" attribute to
296
+ // the specified message
297
+ if (validation.badInput) {
298
+ input.setAttribute('data-badinput', validation.badInput.message);
299
+ }
300
+ // If the "minmax" property is present, add the "min" and "max" attributes to the input element
301
+ // and set its "data-range" attribute to the specified message (if any)
302
+ if (validation.minmax) {
303
+ input.setAttribute('min', validation.minmax.min);
304
+ input.setAttribute('max', validation.minmax.max);
305
+ input.setAttribute('data-range', validation.minmax.message);
306
+ }
307
+ // If the "maxlength" property is present, add the "maxlength" attribute to the input element
308
+ if (validation.maxlength) {
309
+ input.setAttribute('maxlength', validation.maxlength);
310
+ }
311
+ }
312
+ // Create a new error bubble element
313
+ createErrorBubble() {
314
+ // Create a new <div> element with the "errorBubble" class
315
+ const errorBubble = document.createElement('div');
316
+ errorBubble.className = 'errorBubble';
317
+ // Return the error bubble element
318
+ return errorBubble;
319
+ }
320
+ appendCheckboxInput(formProperties, input, label) {
321
+ if (formProperties.label) {
322
+ const lineBreak = document.createElement('br');
323
+ label.appendChild(lineBreak);
324
+ }
325
+ // Append the input element and error bubble element to the label
326
+ label.appendChild(input);
327
+ if (!formProperties.inlineLabel)
328
+ return;
329
+ const inlineLabel = document.createElement('span');
330
+ inlineLabel.className = 'inlineLabel';
331
+ inlineLabel.textContent = formProperties.inlineLabel;
332
+ label.appendChild(inlineLabel);
333
+ }
334
+ /**
335
+ * Creates a new <label> element with the "inputBlock" class and the specified label text,
336
+ * and appends the input element and error bubble element to it. If the form property has
337
+ * no validation object, it adds an "optional" span element to the label.
338
+ *
339
+ * @param {Object} formProperties - An object containing properties for the form field, including its label text and validation rules.
340
+ * @param {HTMLInputElement} input - The input element to associate with the label.
341
+ * @param {HTMLDivElement} errorBubble - The error bubble element to display error messages in.
342
+ * @return {HTMLLabelElement} - The new label element.
343
+ */
344
+ createLabel(formProperties, input, errorBubble) {
345
+ // Create a new <label> element with the "inputBlock" class and the specified text
346
+ const label = document.createElement('label');
347
+ label.className = 'inputBlock';
348
+ label.innerText = formProperties.label;
349
+ // If the form property has no validation object, add an "optional" span element to the label
350
+ if (!formProperties.validation) {
351
+ const optionalSpan = document.createElement('span');
352
+ optionalSpan.className = 'optional';
353
+ optionalSpan.innerHTML = '&nbsp;(optional)';
354
+ label.appendChild(optionalSpan);
355
+ }
356
+ if (formProperties.readonly) {
357
+ label.classList.add('readonly');
358
+ }
359
+ if (formProperties.type === 'checkbox') {
360
+ label.className += ' inlineBlock';
361
+ this.appendCheckboxInput(formProperties, input, label);
362
+ }
363
+ else {
364
+ // Append the input element and error bubble element to the label
365
+ label.appendChild(input);
366
+ }
367
+ label.appendChild(errorBubble);
368
+ // Return the label element
369
+ return label;
370
+ }
371
+ /**
372
+ * Populates the form template with input fields and labels based on the properties of the
373
+ * current form schema. For each property in the schema, it creates an input element, applies
374
+ * any validation rules to it, creates an error bubble and label element, and appends them
375
+ * to the form template. Finally, it creates and appends a submit button element to the form.
376
+ *
377
+ * @return {void}
378
+ */
379
+ populateFormFromSchema() {
380
+ // If there is no form schema, return early
381
+ if (!this._formSchema)
382
+ return;
383
+ // Get the properties of the form schema and their keys
384
+ const properties = this._formSchema.properties;
385
+ const propertyKeys = Object.keys(properties);
386
+ // Loop through each property key and create an input, label, and error bubble for it
387
+ propertyKeys.forEach(formKey => {
388
+ const formItem = properties[formKey];
389
+ const formProperties = formItem.form;
390
+ const input = formProperties.type === 'select' ? this.createSelect(formKey, formProperties) : this.createInput(formKey, formProperties);
391
+ // If the form property has validation, apply it to the input
392
+ if (formProperties.validation) {
393
+ this.applyValidation(input, formProperties.validation);
394
+ }
395
+ // Create an error bubble and label element for the input
396
+ const errorBubble = this.createErrorBubble();
397
+ const label = this.createLabel(formProperties, input, errorBubble);
398
+ // Append the label element to the form template
399
+ this.template.content.append(label);
400
+ });
401
+ }
402
+ /**
403
+ * Clones the form template and binds event listeners to its input elements. First, it checks if
404
+ * there is a form schema present. If so, it clones the template's content, binds events to form
405
+ * input elements, and appends the cloned form elements to the fieldset. The event listeners include
406
+ * "oninvalid" (to check input validity on submit), "onblur" (to check input validity on blur),
407
+ * "onkeyup" (to handle changes in input fields), and "onchange" (to handle changes in select fields).
408
+ *
409
+ * @return {void}
410
+ */
411
+ componentDidRender() {
412
+ // If there's no form schema, return
413
+ if (!this._formSchema) {
414
+ return;
415
+ }
416
+ // Clone the template's content and store it in a variable
417
+ const formItems = this.template.content.cloneNode(true);
418
+ // Bind event listeners to form elements
419
+ const properties = this._formSchema.properties;
420
+ const propertyKeys = Object.keys(properties);
421
+ propertyKeys.forEach(formKey => {
422
+ var _a;
423
+ const formInput = formItems.querySelector(`[name=${formKey}]`);
424
+ // Bind events to form input elements
425
+ formInput.oninvalid = this.validityCheckWrapper.bind(this);
426
+ formInput.onblur = this.validityCheckWrapper.bind(this);
427
+ formInput.onkeyup = this.fieldChanged.bind(this);
428
+ formInput.onchange = this.fieldChanged.bind(this);
429
+ if (this._data && this._data[formKey] !== undefined && this._data[formKey] !== null) {
430
+ formInput.value = this._data[formKey];
431
+ }
432
+ // If explicitly setting input as invalid, set invalid state and error message on render
433
+ if ((_a = properties[formKey].form.validation) === null || _a === void 0 ? void 0 : _a.invalid) {
434
+ const errorMessage = properties[formKey].form.validation.invalid.message;
435
+ formInput.setCustomValidity(errorMessage); // Prevents the invalid styling from resetting on blur
436
+ setErrorState(formInput, true, errorMessage);
437
+ }
438
+ if (properties[formKey].form.type === 'select' && formInput.classList.contains('placeholder')) {
439
+ formInput.addEventListener('change', () => {
440
+ formInput.classList.remove('placeholder');
441
+ });
442
+ }
443
+ });
444
+ // Append the cloned form elements to the fieldset
445
+ this.fieldset.replaceChildren(formItems);
446
+ }
447
+ validityCheckWrapper(event) {
448
+ const { target, hasError, errorMessage } = validityCheck(event);
449
+ setErrorState(target, hasError, errorMessage);
450
+ }
451
+ /**
452
+ * Renders the component's template as a form element with a fieldset container. The form's
453
+ * "onSubmit" event is bound to the "doSubmit" function, which handles the form submission
454
+ * and emits a "dataSubmitted" event with the form data. The fieldset element is assigned
455
+ * to the "fieldset" instance variable using a ref, so it can be populated with form elements
456
+ * later on.
457
+ *
458
+ * @return {JSX.Element} - The rendered form template as a JSX element.
459
+ */
460
+ render() {
461
+ return (index.h(index.Host, null, index.h("form", { ref: el => (this.form = el), onSubmit: this.doSubmit.bind(this) }, index.h("fieldset", { ref: el => (this.fieldset = el) }), index.h("input", { type: "submit", ref: el => (this.submitButton = el), style: { display: 'none' } }))));
462
+ }
463
+ static get watchers() { return {
464
+ "formschema": ["onFormSchemaChange"],
465
+ "data": ["onDataChange"]
466
+ }; }
467
+ };
384
468
  TttxForm.style = tttxFormCss;
385
469
 
386
470
  exports.tttx_form = TttxForm;