@3t-transform/threeteeui 0.1.28 → 0.1.30

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 (190) hide show
  1. package/dist/cjs/{index-dc6cc829.js → index-457ca775.js} +104 -2
  2. package/dist/cjs/loader.cjs.js +4 -3
  3. package/dist/cjs/tttx-button.cjs.entry.js +24 -24
  4. package/dist/cjs/tttx-filter.cjs.entry.js +159 -159
  5. package/dist/cjs/tttx-form.cjs.entry.js +376 -364
  6. package/dist/cjs/tttx-icon.cjs.entry.js +11 -11
  7. package/dist/cjs/tttx-keyvalue-block.cjs.entry.js +59 -59
  8. package/dist/cjs/tttx-list.cjs.entry.js +43 -43
  9. package/dist/cjs/tttx-loading-spinner.cjs.entry.js +16 -16
  10. package/dist/cjs/tttx-sorter.cjs.entry.js +102 -102
  11. package/dist/cjs/tttx-standalone-input.cjs.entry.js +62 -62
  12. package/dist/cjs/tttx-toolbar.cjs.entry.js +10 -10
  13. package/dist/cjs/tttx.cjs.js +7 -3
  14. package/dist/collection/collection-manifest.json +2 -2
  15. package/dist/collection/components/atoms/tttx-button/tttx-button.js +110 -110
  16. package/dist/collection/components/atoms/tttx-button/tttx-button.stories.js +14 -14
  17. package/dist/collection/components/atoms/tttx-icon/tttx-icon.js +62 -62
  18. package/dist/collection/components/atoms/tttx-icon/tttx-icon.stories.js +22 -22
  19. package/dist/collection/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.js +109 -109
  20. package/dist/collection/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.stories.js +38 -38
  21. package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.js +67 -67
  22. package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.js +17 -17
  23. package/dist/collection/components/molecules/tttx-filter/tttx-filter.js +334 -334
  24. package/dist/collection/components/molecules/tttx-filter/tttx-filter.stories.js +62 -62
  25. package/dist/collection/components/molecules/tttx-form/lib/setErrorState.js +37 -35
  26. package/dist/collection/components/molecules/tttx-form/lib/validityCheck.js +58 -58
  27. package/dist/collection/components/molecules/tttx-form/tttx-form.css +5 -0
  28. package/dist/collection/components/molecules/tttx-form/tttx-form.js +396 -364
  29. package/dist/collection/components/molecules/tttx-form/tttx-form.stories.js +248 -127
  30. package/dist/collection/components/molecules/tttx-list/tttx-list.js +105 -105
  31. package/dist/collection/components/molecules/tttx-list/tttx-list.stories.js +43 -43
  32. package/dist/collection/components/molecules/tttx-sorter/tttx-sorter.js +224 -224
  33. package/dist/collection/components/molecules/tttx-sorter/tttx-sorter.stories.js +42 -42
  34. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.css +27 -5
  35. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.js +645 -645
  36. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.stories.js +163 -163
  37. package/dist/collection/components/molecules/tttx-toolbar/tttx-toolbar.js +44 -44
  38. package/dist/collection/components/molecules/tttx-toolbar/tttx-toolbar.stories.js +14 -14
  39. package/dist/collection/components/palette.stories.js +7 -7
  40. package/dist/collection/docs/gettingstarted-developer.stories.js +5 -5
  41. package/dist/collection/icons.js +2838 -2838
  42. package/dist/collection/index.js +1 -1
  43. package/dist/collection/shared/domsanitiser.options.js +14 -14
  44. package/dist/components/index.d.ts +9 -0
  45. package/dist/components/index.js +1 -1
  46. package/dist/components/tttx-button.js +48 -48
  47. package/dist/components/tttx-filter.js +191 -191
  48. package/dist/components/tttx-form.js +394 -381
  49. package/dist/components/tttx-icon2.js +28 -28
  50. package/dist/components/tttx-keyvalue-block.js +76 -76
  51. package/dist/components/tttx-list.js +65 -65
  52. package/dist/components/tttx-loading-spinner.js +33 -33
  53. package/dist/components/tttx-sorter.js +130 -130
  54. package/dist/components/tttx-standalone-input.js +110 -110
  55. package/dist/components/tttx-toolbar.js +26 -26
  56. package/dist/esm/{index-86faeaab.js → index-d784fb3e.js} +104 -3
  57. package/dist/esm/loader.js +4 -3
  58. package/dist/esm/polyfills/core-js.js +0 -0
  59. package/dist/esm/polyfills/css-shim.js +1 -1
  60. package/dist/esm/polyfills/dom.js +0 -0
  61. package/dist/esm/polyfills/es5-html-element.js +0 -0
  62. package/dist/esm/polyfills/index.js +0 -0
  63. package/dist/esm/polyfills/system.js +0 -0
  64. package/dist/esm/tttx-button.entry.js +24 -24
  65. package/dist/esm/tttx-filter.entry.js +159 -159
  66. package/dist/esm/tttx-form.entry.js +376 -364
  67. package/dist/esm/tttx-icon.entry.js +11 -11
  68. package/dist/esm/tttx-keyvalue-block.entry.js +59 -59
  69. package/dist/esm/tttx-list.entry.js +43 -43
  70. package/dist/esm/tttx-loading-spinner.entry.js +16 -16
  71. package/dist/esm/tttx-sorter.entry.js +102 -102
  72. package/dist/esm/tttx-standalone-input.entry.js +62 -62
  73. package/dist/esm/tttx-toolbar.entry.js +10 -10
  74. package/dist/esm/tttx.js +4 -3
  75. package/dist/tttx/p-0ebffdfc.js +2 -0
  76. package/dist/tttx/p-1112ed2e.entry.js +1 -0
  77. package/dist/tttx/p-13495422.entry.js +1 -0
  78. package/dist/tttx/{p-ae00cae3.entry.js → p-1ed7a43d.entry.js} +1 -1
  79. package/dist/tttx/p-237fe0d5.entry.js +1 -0
  80. package/dist/tttx/p-2731fbc6.entry.js +1 -0
  81. package/dist/tttx/p-280b8e45.entry.js +1 -0
  82. package/dist/tttx/p-3772f4d0.entry.js +1 -0
  83. package/dist/tttx/p-390d97dd.entry.js +1 -0
  84. package/dist/tttx/p-49796abf.entry.js +1 -0
  85. package/dist/tttx/p-4f68f1eb.entry.js +1 -0
  86. package/dist/tttx/p-53793ed2.entry.js +1 -0
  87. package/dist/tttx/p-5f335153.entry.js +1 -0
  88. package/dist/tttx/p-60a0fee2.entry.js +1 -0
  89. package/dist/tttx/p-6ab75c0b.entry.js +1 -0
  90. package/dist/tttx/{p-daa27411.entry.js → p-6b006ccf.entry.js} +1 -1
  91. package/dist/tttx/p-6cbe1824.entry.js +1 -0
  92. package/dist/tttx/p-6cefa1ce.entry.js +1 -0
  93. package/dist/tttx/p-72e7f7dd.entry.js +3 -0
  94. package/dist/tttx/{p-c72d1a03.entry.js → p-798a098a.entry.js} +1 -1
  95. package/dist/tttx/p-824af346.entry.js +1 -0
  96. package/dist/tttx/{p-f1d7eb35.entry.js → p-91e42647.entry.js} +1 -1
  97. package/dist/tttx/{p-8f3badad.entry.js → p-b720c4ad.entry.js} +1 -1
  98. package/dist/tttx/p-c06f1207.entry.js +1 -0
  99. package/dist/tttx/p-c0a15524.entry.js +1 -0
  100. package/dist/tttx/{p-e25d5fe2.entry.js → p-c4162029.entry.js} +1 -1
  101. package/dist/tttx/p-c7c968dd.entry.js +1 -0
  102. package/dist/tttx/{p-c4538d55.entry.js → p-cac26a1b.entry.js} +1 -1
  103. package/dist/tttx/p-ce728715.entry.js +1 -0
  104. package/dist/tttx/p-d3932db5.entry.js +1 -0
  105. package/dist/tttx/p-d575ef2d.entry.js +1 -0
  106. package/dist/tttx/p-d83edcfb.entry.js +1 -0
  107. package/dist/tttx/p-d8e03ed6.entry.js +1 -0
  108. package/dist/tttx/p-ebb496a2.entry.js +1 -0
  109. package/dist/tttx/p-fb5e737b.entry.js +1 -0
  110. package/dist/tttx/p-fce571c2.entry.js +1 -0
  111. package/dist/tttx/tttx.esm.js +1 -1
  112. package/dist/types/components/atoms/tttx-button/tttx-button.d.ts +10 -10
  113. package/dist/types/components/atoms/tttx-button/tttx-button.stories.d.ts +10 -10
  114. package/dist/types/components/atoms/tttx-icon/tttx-icon.d.ts +5 -5
  115. package/dist/types/components/atoms/tttx-icon/tttx-icon.stories.d.ts +20 -20
  116. package/dist/types/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.d.ts +7 -7
  117. package/dist/types/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.stories.d.ts +9 -9
  118. package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.d.ts +6 -6
  119. package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.d.ts +17 -17
  120. package/dist/types/components/molecules/tttx-filter/tttx-filter.d.ts +39 -39
  121. package/dist/types/components/molecules/tttx-filter/tttx-filter.stories.d.ts +68 -68
  122. package/dist/types/components/molecules/tttx-form/lib/setErrorState.d.ts +13 -13
  123. package/dist/types/components/molecules/tttx-form/lib/validityCheck.d.ts +17 -17
  124. package/dist/types/components/molecules/tttx-form/tttx-form.d.ts +111 -114
  125. package/dist/types/components/molecules/tttx-form/tttx-form.stories.d.ts +13 -13
  126. package/dist/types/components/molecules/tttx-list/tttx-list.d.ts +11 -11
  127. package/dist/types/components/molecules/tttx-list/tttx-list.stories.d.ts +14 -14
  128. package/dist/types/components/molecules/tttx-sorter/tttx-sorter.d.ts +19 -19
  129. package/dist/types/components/molecules/tttx-sorter/tttx-sorter.stories.d.ts +30 -30
  130. package/dist/types/components/molecules/tttx-standalone-input/tttx-standalone-input.d.ts +60 -60
  131. package/dist/types/components/molecules/tttx-standalone-input/tttx-standalone-input.stories.d.ts +128 -128
  132. package/dist/types/components/molecules/tttx-toolbar/tttx-toolbar.d.ts +4 -4
  133. package/dist/types/components/molecules/tttx-toolbar/tttx-toolbar.stories.d.ts +13 -13
  134. package/dist/types/components/palette.stories.d.ts +6 -6
  135. package/dist/types/components.d.ts +3 -2
  136. package/dist/types/docs/gettingstarted-developer.stories.d.ts +5 -5
  137. package/dist/types/icons.d.ts +2 -2
  138. package/dist/types/index.d.ts +1 -1
  139. package/dist/types/shared/domsanitiser.options.d.ts +10 -10
  140. package/dist/types/stencil-public-runtime.d.ts +59 -3
  141. package/loader/index.d.ts +9 -0
  142. package/package.json +1 -1
  143. package/dist/cjs/domsanitiser.options-277161b9.js +0 -1667
  144. package/dist/collection/components/atoms/tttx-button/test/tttx-button.e2e.js +0 -9
  145. package/dist/collection/components/atoms/tttx-button/test/tttx-button.spec.js +0 -83
  146. package/dist/collection/components/atoms/tttx-icon/test/tttx-icon.e2e.js +0 -9
  147. package/dist/collection/components/atoms/tttx-icon/test/tttx-icon.spec.js +0 -16
  148. package/dist/collection/components/atoms/tttx-keyvalue-block/test/tttx-keyvalue-block.spec.js +0 -216
  149. package/dist/collection/components/atoms/tttx-loading-spinner/Test/tttx-loading-spinner.spec.js +0 -64
  150. package/dist/collection/components/molecules/tttx-filter/test/tttx-filter.spec.js +0 -231
  151. package/dist/collection/components/molecules/tttx-form/lib/setErrorState.spec.js +0 -38
  152. package/dist/collection/components/molecules/tttx-form/lib/validityCheck.spec.js +0 -214
  153. package/dist/collection/components/molecules/tttx-form/test/tttx-form.e2e.js +0 -9
  154. package/dist/collection/components/molecules/tttx-form/test/tttx-form.spec.js +0 -232
  155. package/dist/collection/components/molecules/tttx-list/test/ttttx-list.spec.e2e.js +0 -26
  156. package/dist/collection/components/molecules/tttx-list/test/tttx-list.spec.js +0 -183
  157. package/dist/collection/components/molecules/tttx-sorter/test/tttx-sorter.spec.js +0 -87
  158. package/dist/collection/components/molecules/tttx-standalone-input/test/tttx-standalone-input.e2e.js +0 -9
  159. package/dist/collection/components/molecules/tttx-standalone-input/test/tttx-standalone-input.spec.js +0 -215
  160. package/dist/collection/components/molecules/tttx-toolbar/test/tttx-toolbar.spec.js +0 -52
  161. package/dist/collection/shared/test/domsanitiser.options.spec.js +0 -23
  162. package/dist/components/domsanitiser.options.js +0 -1664
  163. package/dist/esm/domsanitiser.options-cc420431.js +0 -1664
  164. package/dist/tttx/p-12fc0b16.entry.js +0 -3
  165. package/dist/tttx/p-2e43a578.entry.js +0 -1
  166. package/dist/tttx/p-33c0cbdc.entry.js +0 -1
  167. package/dist/tttx/p-52a47b7c.js +0 -2
  168. package/dist/tttx/p-72b4c98a.entry.js +0 -1
  169. package/dist/tttx/p-7e6fa227.entry.js +0 -1
  170. package/dist/tttx/p-90b0f72a.entry.js +0 -1
  171. package/dist/tttx/p-b4290a5b.js +0 -3
  172. package/dist/tttx/p-c4f2186e.entry.js +0 -1
  173. package/dist/types/components/atoms/tttx-button/test/tttx-button.e2e.d.ts +0 -1
  174. package/dist/types/components/atoms/tttx-button/test/tttx-button.spec.d.ts +0 -1
  175. package/dist/types/components/atoms/tttx-icon/test/tttx-icon.e2e.d.ts +0 -1
  176. package/dist/types/components/atoms/tttx-icon/test/tttx-icon.spec.d.ts +0 -1
  177. package/dist/types/components/atoms/tttx-keyvalue-block/test/tttx-keyvalue-block.spec.d.ts +0 -1
  178. package/dist/types/components/atoms/tttx-loading-spinner/Test/tttx-loading-spinner.spec.d.ts +0 -1
  179. package/dist/types/components/molecules/tttx-filter/test/tttx-filter.spec.d.ts +0 -1
  180. package/dist/types/components/molecules/tttx-form/lib/setErrorState.spec.d.ts +0 -1
  181. package/dist/types/components/molecules/tttx-form/lib/validityCheck.spec.d.ts +0 -1
  182. package/dist/types/components/molecules/tttx-form/test/tttx-form.e2e.d.ts +0 -1
  183. package/dist/types/components/molecules/tttx-form/test/tttx-form.spec.d.ts +0 -1
  184. package/dist/types/components/molecules/tttx-list/test/ttttx-list.spec.e2e.d.ts +0 -1
  185. package/dist/types/components/molecules/tttx-list/test/tttx-list.spec.d.ts +0 -1
  186. package/dist/types/components/molecules/tttx-sorter/test/tttx-sorter.spec.d.ts +0 -1
  187. package/dist/types/components/molecules/tttx-standalone-input/test/tttx-standalone-input.e2e.d.ts +0 -1
  188. package/dist/types/components/molecules/tttx-standalone-input/test/tttx-standalone-input.spec.d.ts +0 -1
  189. package/dist/types/components/molecules/tttx-toolbar/test/tttx-toolbar.spec.d.ts +0 -1
  190. package/dist/types/shared/test/domsanitiser.options.spec.d.ts +0 -1
@@ -2,376 +2,388 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const index = require('./index-dc6cc829.js');
5
+ const index = require('./index-457ca775.js');
6
6
 
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 };
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 };
63
63
  }
64
64
 
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
- const errorIcon = document.createElement('span');
83
- // Set the class of the error icon to a pre-defined CSS class that specifies the icon's appearance
84
- errorIcon.className = 'material-symbols-rounded';
85
- // Set the text content of the error icon to the word "warning"
86
- errorIcon.textContent = 'warning';
87
- // errorBubble.replaceChildren cannot be used here because the tests don't support this new feature :(
88
- errorBubble.innerHTML = '';
89
- errorBubble.append(errorIcon);
90
- errorBubble.append(errorMessage);
91
- // errorBubble.replaceChildren(errorIcon, errorMessage);
92
- }
93
- // If no error was detected, remove the "invalid" class from the input field and clear the error bubble
94
- else {
95
- target.className = '';
96
- errorBubble.innerHTML = '';
97
- }
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
+ }
98
100
  }
99
101
 
100
- 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}.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}";
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}input[readonly]{cursor:default;pointer-events:none}.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}";
101
103
 
102
- const TttxForm = class {
103
- constructor(hostRef) {
104
- index.registerInstance(this, hostRef);
105
- this.dataSubmitted = index.createEvent(this, "dataSubmitted", 7);
106
- this.dataChanged = index.createEvent(this, "dataChanged", 7);
107
- // Create a new template element using the HTMLTemplateElement interface.
108
- this.template = document.createElement('template');
109
- this.formschema = undefined;
110
- this.submitValue = undefined;
111
- }
112
- // This method is called whenever the "formschema" property changes
113
- onFormSchemaChange(newValue) {
114
- // Check if the new value is a string, indicating that it needs to be parsed
115
- if (typeof newValue === 'string') {
116
- // Parse the string and set the "_formSchema" property
117
- this._formSchema = JSON.parse(newValue);
118
- }
119
- else {
120
- // If the new value is already an object, set the "_formSchema" property directly
121
- this._formSchema = newValue;
122
- }
123
- }
124
- /**
125
- * Handles the focus event for a form field and emits a "dataChanged" event
126
- * to the parent component with the field name and its new value.
127
- *
128
- * @param {ChangeEvent} event - The focus event triggered by the field.
129
- * @return {void}
130
- */
131
- fieldChanged(event) {
132
- // Extract the name and value of the field from the event
133
- const fieldName = event.target.name;
134
- const fieldValue = event.target.value;
135
- // Emit an event to signal that the field's data has changed
136
- this.dataChanged.emit({ name: fieldName, value: fieldValue });
137
- }
138
- /**
139
- * Submits the form data to the server.
140
- *
141
- * @param {SubmitEvent} event - The event object for the form submission.
142
- * @returns {void}
143
- *
144
- * @example
145
- * const form = document.getElementById('myForm');
146
- * form.addEventListener('submit', (event) => {
147
- * doSubmit(event);
148
- * });
149
- */
150
- doSubmit(event) {
151
- // prevent the form from submitting normally
152
- event.preventDefault();
153
- // create a new FormData object with the form data
154
- const formData = new FormData(event.target);
155
- // emit the form data through the `dataSubmitted` event
156
- this.dataSubmitted.emit(formData);
157
- }
158
- // This method is called before the component is loaded into the DOM
159
- componentWillLoad() {
160
- // Initialize the form schema by calling the "onFormSchemaChange" method with the current "formschema" property
161
- this.onFormSchemaChange(this.formschema);
162
- }
163
- // This method is called before the component is rendered
164
- componentWillRender() {
165
- // Clear the template to account for a potential re-render scenario
166
- this.template = document.createElement('template');
167
- // Populate the form from the form schema
168
- this.populateFormFromSchema();
169
- }
170
- /**
171
- * Creates a new HTMLInputElement with the specified name, type, and placeholder (if any),
172
- * and sets its autocomplete and autocapitalization properties to off.
173
- *
174
- * @param {string} formKey - The name of the input field, as specified in the form schema.
175
- * @param {Object} formProperties - An object containing additional properties for the input field, such as its type and placeholder value.
176
- * @param {string} formProperties.type - The type of the input field (e.g., "text", "email", "number", etc.).
177
- * @param {string} [formProperties.placeholder] - An optional placeholder value to display in the input field.
178
- * @return {HTMLInputElement} - The new input element.
179
- */
180
- createInput(formKey, formProperties) {
181
- var _a;
182
- // Create a new <input> element with the specified name and type
183
- const input = document.createElement('input');
184
- input.name = formKey;
185
- input.type = formProperties.type;
186
- // Set the placeholder attribute to the specified value (if any)
187
- input.placeholder = (_a = formProperties.placeholder) !== null && _a !== void 0 ? _a : '';
188
- // Disable autocomplete and autocapitalization
189
- input.autocomplete = 'off';
190
- input.autocapitalize = 'off';
191
- // Return the input element
192
- return input;
193
- }
194
- /**
195
- * Applies validation attributes to an input element based on the specified validation object.
196
- * If a certain property is present in the object, it will set the corresponding attribute on
197
- * the input element (e.g., "required" will set the "required" and "data-required" attributes,
198
- * "pattern" will set the "pattern" and "data-pattern" attributes, etc.).
199
- *
200
- * @param {HTMLInputElement} input - The input element to apply validation attributes to.
201
- * @param {Object} validation - An object containing the validation rules for the input field.
202
- * @param {Object} [validation.required] - An object containing a "message" property to display if the field is required.
203
- * @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.
204
- * @param {Object} [validation.badInput] - An object containing a "message" property to display if the field value is invalid.
205
- * @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.
206
- * @param {string} [validation.maxlength] - The maximum length of the input field.
207
- * @return {void}
208
- */
209
- applyValidation(input, validation) {
210
- var _a, _b;
211
- // If the "required" property is present, add the "required" attribute to the input element and
212
- // set its "data-required" attribute to the specified message (if any)
213
- if (validation.required) {
214
- input.setAttribute('required', '');
215
- input.setAttribute('data-required', (_a = validation.required.message) !== null && _a !== void 0 ? _a : '');
216
- }
217
- // If the "pattern" property is present, add the "pattern" attribute to the input element and set
218
- // its "data-pattern" attribute to the specified message (if any)
219
- if (validation.pattern) {
220
- input.setAttribute('pattern', validation.pattern.pattern);
221
- input.setAttribute('data-pattern', (_b = validation.pattern.message) !== null && _b !== void 0 ? _b : '');
222
- }
223
- // If the "badInput" property is present, set the input element's "data-badinput" attribute to
224
- // the specified message
225
- if (validation.badInput) {
226
- input.setAttribute('data-badinput', validation.badInput.message);
227
- }
228
- // If the "minmax" property is present, add the "min" and "max" attributes to the input element
229
- // and set its "data-range" attribute to the specified message (if any)
230
- if (validation.minmax) {
231
- input.setAttribute('min', validation.minmax.min);
232
- input.setAttribute('max', validation.minmax.max);
233
- input.setAttribute('data-range', validation.minmax.message);
234
- }
235
- // If the "maxlength" property is present, add the "maxlength" attribute to the input element
236
- if (validation.maxlength) {
237
- input.setAttribute('maxlength', validation.maxlength);
238
- }
239
- }
240
- // Create a new error bubble element
241
- createErrorBubble() {
242
- // Create a new <div> element with the "errorBubble" class
243
- const errorBubble = document.createElement('div');
244
- errorBubble.className = 'errorBubble';
245
- // Return the error bubble element
246
- return errorBubble;
247
- }
248
- /**
249
- * Creates a new <label> element with the "inputBlock" class and the specified label text,
250
- * and appends the input element and error bubble element to it. If the form property has
251
- * no validation object, it adds an "optional" span element to the label.
252
- *
253
- * @param {Object} formProperties - An object containing properties for the form field, including its label text and validation rules.
254
- * @param {HTMLInputElement} input - The input element to associate with the label.
255
- * @param {HTMLDivElement} errorBubble - The error bubble element to display error messages in.
256
- * @return {HTMLLabelElement} - The new label element.
257
- */
258
- createLabel(formProperties, input, errorBubble) {
259
- // Create a new <label> element with the "inputBlock" class and the specified text
260
- const label = document.createElement('label');
261
- label.className = 'inputBlock';
262
- label.innerText = formProperties.label;
263
- // If the form property has no validation object, add an "optional" span element to the label
264
- if (!formProperties.validation) {
265
- const optionalSpan = document.createElement('span');
266
- optionalSpan.className = 'optional';
267
- optionalSpan.innerHTML = '&nbsp;(optional)';
268
- label.appendChild(optionalSpan);
269
- }
270
- // Append the input element and error bubble element to the label
271
- label.appendChild(input);
272
- label.appendChild(errorBubble);
273
- // Return the label element
274
- return label;
275
- }
276
- /**
277
- * Creates a new <input> element with the "submit" type, the "primary-blue" class, and the
278
- * specified label text (i.e., "Save" by default), and returns the new submit button element.
279
- *
280
- * @return {HTMLInputElement} - The new submit button element.
281
- */
282
- createSubmitButton() {
283
- // Create a new <input> element with the "submit" type and the specified class and value
284
- const submitButton = document.createElement('input');
285
- submitButton.type = 'submit';
286
- submitButton.className = 'button primary-blue';
287
- submitButton.value = 'Save';
288
- // Return the submit button element
289
- return submitButton;
290
- }
291
- /**
292
- * Populates the form template with input fields and labels based on the properties of the
293
- * current form schema. For each property in the schema, it creates an input element, applies
294
- * any validation rules to it, creates an error bubble and label element, and appends them
295
- * to the form template. Finally, it creates and appends a submit button element to the form.
296
- *
297
- * @return {void}
298
- */
299
- populateFormFromSchema() {
300
- // If there is no form schema, return early
301
- if (!this._formSchema)
302
- return;
303
- // Get the properties of the form schema and their keys
304
- const properties = this._formSchema.properties;
305
- const propertyKeys = Object.keys(properties);
306
- // Loop through each property key and create an input, label, and error bubble for it
307
- propertyKeys.forEach(formKey => {
308
- const formItem = properties[formKey];
309
- const formProperties = formItem.form;
310
- const input = this.createInput(formKey, formProperties);
311
- // If the form property has validation, apply it to the input
312
- if (formProperties.validation) {
313
- this.applyValidation(input, formProperties.validation);
314
- }
315
- // Create an error bubble and label element for the input
316
- const errorBubble = this.createErrorBubble();
317
- const label = this.createLabel(formProperties, input, errorBubble);
318
- // Append the label element to the form template
319
- this.template.content.append(label);
320
- });
321
- // Create and append a submit button element to the form template
322
- const submitButton = this.createSubmitButton();
323
- this.template.content.append(submitButton);
324
- }
325
- /**
326
- * Clones the form template and binds event listeners to its input elements. First, it checks if
327
- * there is a form schema present. If so, it clones the template's content, binds events to form
328
- * input elements, and appends the cloned form elements to the fieldset. The event listeners include
329
- * "oninvalid" (to check input validity on submit), "onblur" (to check input validity on blur),
330
- * "onkeyup" (to handle changes in input fields), and "onchange" (to handle changes in select fields).
331
- *
332
- * @return {void}
333
- */
334
- componentDidRender() {
335
- // If there's no form schema, return
336
- if (!this._formSchema) {
337
- return;
338
- }
339
- // Clone the template's content and store it in a variable
340
- const formItems = this.template.content.cloneNode(true);
341
- // Bind event listeners to form elements
342
- const properties = this._formSchema.properties;
343
- const propertyKeys = Object.keys(properties);
344
- propertyKeys.forEach((formKey) => {
345
- const formInput = formItems.querySelector(`[name=${formKey}]`);
346
- // Bind events to form input elements
347
- formInput.oninvalid = this.validityCheckWrapper.bind(this);
348
- formInput.onblur = this.validityCheckWrapper.bind(this);
349
- formInput.onkeyup = this.fieldChanged.bind(this);
350
- formInput.onchange = this.fieldChanged.bind(this);
351
- });
352
- // Append the cloned form elements to the fieldset
353
- this.fieldset.appendChild(formItems);
354
- }
355
- validityCheckWrapper(event) {
356
- const { target, hasError, errorMessage } = validityCheck(event);
357
- setErrorState(target, hasError, errorMessage);
358
- }
359
- /**
360
- * Renders the component's template as a form element with a fieldset container. The form's
361
- * "onSubmit" event is bound to the "doSubmit" function, which handles the form submission
362
- * and emits a "dataSubmitted" event with the form data. The fieldset element is assigned
363
- * to the "fieldset" instance variable using a ref, so it can be populated with form elements
364
- * later on.
365
- *
366
- * @return {JSX.Element} - The rendered form template as a JSX element.
367
- */
368
- render() {
369
- return (index.h(index.Host, null, index.h("form", { onSubmit: this.doSubmit.bind(this) }, index.h("fieldset", { ref: el => (this.fieldset = el) }))));
370
- }
371
- static get watchers() { return {
372
- "formschema": ["onFormSchemaChange"]
373
- }; }
374
- };
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 && !formProperties.readonly) {
285
+ const optionalSpan = document.createElement('span');
286
+ optionalSpan.className = 'optional';
287
+ optionalSpan.innerHTML = '&nbsp;(optional)';
288
+ label.appendChild(optionalSpan);
289
+ }
290
+ else if (formProperties.readonly) {
291
+ const readonlySpan = document.createElement('span');
292
+ readonlySpan.className = 'optional';
293
+ readonlySpan.innerHTML = '&nbsp;(read&nbsp;only)';
294
+ label.appendChild(readonlySpan);
295
+ }
296
+ // Append the input element and error bubble element to the label
297
+ label.appendChild(input);
298
+ label.appendChild(errorBubble);
299
+ // Return the label element
300
+ return label;
301
+ }
302
+ /**
303
+ * Populates the form template with input fields and labels based on the properties of the
304
+ * current form schema. For each property in the schema, it creates an input element, applies
305
+ * any validation rules to it, creates an error bubble and label element, and appends them
306
+ * to the form template. Finally, it creates and appends a submit button element to the form.
307
+ *
308
+ * @return {void}
309
+ */
310
+ populateFormFromSchema() {
311
+ // If there is no form schema, return early
312
+ if (!this._formSchema)
313
+ return;
314
+ // Get the properties of the form schema and their keys
315
+ const properties = this._formSchema.properties;
316
+ const propertyKeys = Object.keys(properties);
317
+ // Loop through each property key and create an input, label, and error bubble for it
318
+ propertyKeys.forEach(formKey => {
319
+ const formItem = properties[formKey];
320
+ const formProperties = formItem.form;
321
+ const input = this.createInput(formKey, formProperties);
322
+ // If the form property has validation, apply it to the input
323
+ if (formProperties.validation) {
324
+ this.applyValidation(input, formProperties.validation);
325
+ }
326
+ // Create an error bubble and label element for the input
327
+ const errorBubble = this.createErrorBubble();
328
+ const label = this.createLabel(formProperties, input, errorBubble);
329
+ // Append the label element to the form template
330
+ this.template.content.append(label);
331
+ });
332
+ }
333
+ /**
334
+ * Clones the form template and binds event listeners to its input elements. First, it checks if
335
+ * there is a form schema present. If so, it clones the template's content, binds events to form
336
+ * input elements, and appends the cloned form elements to the fieldset. The event listeners include
337
+ * "oninvalid" (to check input validity on submit), "onblur" (to check input validity on blur),
338
+ * "onkeyup" (to handle changes in input fields), and "onchange" (to handle changes in select fields).
339
+ *
340
+ * @return {void}
341
+ */
342
+ componentDidRender() {
343
+ // If there's no form schema, return
344
+ if (!this._formSchema) {
345
+ return;
346
+ }
347
+ // Clone the template's content and store it in a variable
348
+ const formItems = this.template.content.cloneNode(true);
349
+ // Bind event listeners to form elements
350
+ const properties = this._formSchema.properties;
351
+ const propertyKeys = Object.keys(properties);
352
+ propertyKeys.forEach((formKey) => {
353
+ const formInput = formItems.querySelector(`[name=${formKey}]`);
354
+ // Bind events to form input elements
355
+ formInput.oninvalid = this.validityCheckWrapper.bind(this);
356
+ formInput.onblur = this.validityCheckWrapper.bind(this);
357
+ formInput.onkeyup = this.fieldChanged.bind(this);
358
+ formInput.onchange = this.fieldChanged.bind(this);
359
+ if (this._data && this._data[formKey] !== undefined && this._data[formKey] !== null) {
360
+ formInput.value = this._data[formKey];
361
+ }
362
+ });
363
+ // Append the cloned form elements to the fieldset
364
+ this.fieldset.appendChild(formItems);
365
+ }
366
+ validityCheckWrapper(event) {
367
+ const { target, hasError, errorMessage } = validityCheck(event);
368
+ setErrorState(target, hasError, errorMessage);
369
+ }
370
+ /**
371
+ * Renders the component's template as a form element with a fieldset container. The form's
372
+ * "onSubmit" event is bound to the "doSubmit" function, which handles the form submission
373
+ * and emits a "dataSubmitted" event with the form data. The fieldset element is assigned
374
+ * to the "fieldset" instance variable using a ref, so it can be populated with form elements
375
+ * later on.
376
+ *
377
+ * @return {JSX.Element} - The rendered form template as a JSX element.
378
+ */
379
+ render() {
380
+ 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' } }))));
381
+ }
382
+ static get watchers() { return {
383
+ "formschema": ["onFormSchemaChange"],
384
+ "data": ["onDataChange"]
385
+ }; }
386
+ };
375
387
  TttxForm.style = tttxFormCss;
376
388
 
377
389
  exports.tttx_form = TttxForm;