@ukhomeoffice/formio-gds-template 2.0.2 → 3.0.0-bravo

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 (150) hide show
  1. package/.github/workflows/build-and-test.yml +3 -3
  2. package/LICENCE.md +21 -0
  3. package/README.md +8 -0
  4. package/eslint.config.mjs +59 -0
  5. package/lib/components/datamap/GDSDataMap.d.ts +5 -14
  6. package/lib/components/datamap/GDSDataMap.d.ts.map +1 -0
  7. package/lib/components/datamap/GDSDataMap.js +9 -29
  8. package/lib/components/datetime/GDSDatetimeComponent.d.ts +43 -22
  9. package/lib/components/datetime/GDSDatetimeComponent.d.ts.map +1 -0
  10. package/lib/components/datetime/GDSDatetimeComponent.js +167 -178
  11. package/lib/components/index.d.ts +3 -0
  12. package/lib/components/index.d.ts.map +1 -0
  13. package/lib/components/index.js +6 -4
  14. package/lib/components/select/GDSSelect.d.ts +143 -0
  15. package/lib/components/select/GDSSelect.d.ts.map +1 -0
  16. package/lib/components/select/GDSSelect.js +340 -0
  17. package/lib/components/selectboxes/GDSCheckBoxes.d.ts +5 -2
  18. package/lib/components/selectboxes/GDSCheckBoxes.d.ts.map +1 -0
  19. package/lib/components/selectboxes/GDSCheckBoxes.js +7 -33
  20. package/lib/components/time/GDSTimeComponent.d.ts +13 -10
  21. package/lib/components/time/GDSTimeComponent.d.ts.map +1 -0
  22. package/lib/components/time/GDSTimeComponent.js +59 -84
  23. package/lib/components/util/TimeHelper.d.ts +6 -4
  24. package/lib/components/util/TimeHelper.d.ts.map +1 -0
  25. package/lib/components/util/TimeHelper.js +13 -16
  26. package/lib/index.d.ts +4 -2
  27. package/lib/index.d.ts.map +1 -0
  28. package/lib/index.js +2 -2
  29. package/lib/templates/gds/button/index.d.ts +1 -0
  30. package/lib/templates/gds/button/index.d.ts.map +1 -0
  31. package/lib/templates/gds/button/index.js +1 -1
  32. package/lib/templates/gds/checkbox/index.d.ts +1 -0
  33. package/lib/templates/gds/checkbox/index.d.ts.map +1 -0
  34. package/lib/templates/gds/checkbox/index.js +1 -1
  35. package/lib/templates/gds/columns/index.d.ts +1 -0
  36. package/lib/templates/gds/columns/index.d.ts.map +1 -0
  37. package/lib/templates/gds/columns/index.js +1 -1
  38. package/lib/templates/gds/component/index.d.ts +1 -0
  39. package/lib/templates/gds/component/index.d.ts.map +1 -0
  40. package/lib/templates/gds/component/index.js +1 -1
  41. package/lib/templates/gds/container/index.d.ts +1 -0
  42. package/lib/templates/gds/container/index.d.ts.map +1 -0
  43. package/lib/templates/gds/container/index.js +1 -1
  44. package/lib/templates/gds/cssClasses.d.ts +1 -0
  45. package/lib/templates/gds/cssClasses.d.ts.map +1 -0
  46. package/lib/templates/gds/datagrid/form.ejs.js +2 -2
  47. package/lib/templates/gds/datagrid/index.d.ts +1 -0
  48. package/lib/templates/gds/datagrid/index.d.ts.map +1 -0
  49. package/lib/templates/gds/datagrid/index.js +1 -1
  50. package/lib/templates/gds/datamap/index.d.ts +1 -0
  51. package/lib/templates/gds/datamap/index.d.ts.map +1 -0
  52. package/lib/templates/gds/datamap/index.js +1 -1
  53. package/lib/templates/gds/datetime/index.d.ts +1 -0
  54. package/lib/templates/gds/datetime/index.d.ts.map +1 -0
  55. package/lib/templates/gds/datetime/index.js +1 -1
  56. package/lib/templates/gds/day/index.d.ts +1 -0
  57. package/lib/templates/gds/day/index.d.ts.map +1 -0
  58. package/lib/templates/gds/day/index.js +1 -1
  59. package/lib/templates/gds/editgrid/index.d.ts +1 -0
  60. package/lib/templates/gds/editgrid/index.d.ts.map +1 -0
  61. package/lib/templates/gds/editgrid/index.js +1 -1
  62. package/lib/templates/gds/field/index.d.ts +1 -0
  63. package/lib/templates/gds/field/index.d.ts.map +1 -0
  64. package/lib/templates/gds/field/index.js +1 -1
  65. package/lib/templates/gds/fieldset/index.d.ts +1 -0
  66. package/lib/templates/gds/fieldset/index.d.ts.map +1 -0
  67. package/lib/templates/gds/fieldset/index.js +1 -1
  68. package/lib/templates/gds/file/index.d.ts +1 -0
  69. package/lib/templates/gds/file/index.d.ts.map +1 -0
  70. package/lib/templates/gds/file/index.js +1 -1
  71. package/lib/templates/gds/iconClass.d.ts +2 -1
  72. package/lib/templates/gds/iconClass.d.ts.map +1 -0
  73. package/lib/templates/gds/iconClass.js +3 -3
  74. package/lib/templates/gds/index.d.ts +3 -2
  75. package/lib/templates/gds/index.d.ts.map +1 -0
  76. package/lib/templates/gds/index.js +72 -64
  77. package/lib/templates/gds/input/index.d.ts +1 -0
  78. package/lib/templates/gds/input/index.d.ts.map +1 -0
  79. package/lib/templates/gds/input/index.js +1 -1
  80. package/lib/templates/gds/label/index.d.ts +1 -0
  81. package/lib/templates/gds/label/index.d.ts.map +1 -0
  82. package/lib/templates/gds/label/index.js +1 -1
  83. package/lib/templates/gds/message/index.d.ts +1 -0
  84. package/lib/templates/gds/message/index.d.ts.map +1 -0
  85. package/lib/templates/gds/message/index.js +1 -1
  86. package/lib/templates/gds/panel/index.d.ts +1 -0
  87. package/lib/templates/gds/panel/index.d.ts.map +1 -0
  88. package/lib/templates/gds/panel/index.js +1 -1
  89. package/lib/templates/gds/radio/index.d.ts +1 -0
  90. package/lib/templates/gds/radio/index.d.ts.map +1 -0
  91. package/lib/templates/gds/radio/index.js +1 -1
  92. package/lib/templates/gds/select/index.d.ts +1 -0
  93. package/lib/templates/gds/select/index.d.ts.map +1 -0
  94. package/lib/templates/gds/select/index.js +1 -1
  95. package/lib/templates/gds/selectOption/index.d.ts +1 -0
  96. package/lib/templates/gds/selectOption/index.d.ts.map +1 -0
  97. package/lib/templates/gds/selectOption/index.js +1 -1
  98. package/lib/templates/gds/selectboxes/index.d.ts +1 -0
  99. package/lib/templates/gds/selectboxes/index.d.ts.map +1 -0
  100. package/lib/templates/gds/selectboxes/index.js +1 -1
  101. package/lib/templates/gds/survey/index.d.ts +1 -0
  102. package/lib/templates/gds/survey/index.d.ts.map +1 -0
  103. package/lib/templates/gds/survey/index.js +1 -1
  104. package/lib/templates/gds/tab/index.d.ts +1 -0
  105. package/lib/templates/gds/tab/index.d.ts.map +1 -0
  106. package/lib/templates/gds/tab/index.js +1 -1
  107. package/lib/templates/gds/table/index.d.ts +1 -0
  108. package/lib/templates/gds/table/index.d.ts.map +1 -0
  109. package/lib/templates/gds/table/index.js +1 -1
  110. package/lib/templates/gds/template.css +27 -0
  111. package/lib/templates/gds/template.css.map +1 -1
  112. package/lib/templates/gds/time/index.d.ts +1 -0
  113. package/lib/templates/gds/time/index.d.ts.map +1 -0
  114. package/lib/templates/gds/time/index.js +1 -1
  115. package/lib/templates/gds/warning/index.d.ts +1 -0
  116. package/lib/templates/gds/warning/index.d.ts.map +1 -0
  117. package/lib/templates/gds/warning/index.js +1 -1
  118. package/lib/templates/gds/wizard/index.d.ts +1 -0
  119. package/lib/templates/gds/wizard/index.d.ts.map +1 -0
  120. package/lib/templates/gds/wizard/index.js +1 -1
  121. package/lib/templates/gds/wizardHeader/index.d.ts +1 -0
  122. package/lib/templates/gds/wizardHeader/index.d.ts.map +1 -0
  123. package/lib/templates/gds/wizardHeader/index.js +1 -1
  124. package/lib/templates/gds/wizardNav/index.d.ts +1 -0
  125. package/lib/templates/gds/wizardNav/index.d.ts.map +1 -0
  126. package/lib/templates/gds/wizardNav/index.js +1 -1
  127. package/lib/templates/index.d.ts +3 -2
  128. package/lib/templates/index.d.ts.map +1 -0
  129. package/lib/templates/index.js +1 -1
  130. package/lib/types.d.ts +37 -0
  131. package/lib/types.d.ts.map +1 -0
  132. package/lib/types.js +2 -0
  133. package/package.json +14 -7
  134. package/src/components/datamap/GDSDataMap.ts +5 -14
  135. package/src/components/datetime/GDSDatetimeComponent.ts +128 -91
  136. package/src/components/index.ts +2 -0
  137. package/src/components/select/GDSSelect.spec.ts +538 -0
  138. package/src/components/select/GDSSelect.ts +418 -0
  139. package/src/components/selectboxes/GDSCheckBoxes.ts +7 -8
  140. package/src/components/time/GDSTimeComponent.ts +37 -27
  141. package/src/components/util/TimeHelper.ts +6 -5
  142. package/src/css.d.ts +4 -0
  143. package/src/templates/gds/datagrid/form.ejs +1 -2
  144. package/src/templates/gds/iconClass.ts +1 -1
  145. package/src/templates/gds/index.ts +43 -33
  146. package/src/templates/gds/template.scss +48 -1
  147. package/src/types.ts +56 -0
  148. package/tsconfig.json +21 -5
  149. package/webpack.config.js +1 -1
  150. package/tslint.json +0 -22
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
3
  if (k2 === undefined) k2 = k;
19
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -37,95 +22,62 @@ var __importStar = (this && this.__importStar) || function (mod) {
37
22
  __setModuleDefault(result, mod);
38
23
  return result;
39
24
  };
40
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
41
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
42
- if (ar || !(i in from)) {
43
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
44
- ar[i] = from[i];
45
- }
46
- }
47
- return to.concat(ar || Array.prototype.slice.call(from));
48
- };
49
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
27
  };
52
28
  Object.defineProperty(exports, "__esModule", { value: true });
53
- var formiojs_1 = require("formiojs");
54
- var utils_1 = __importDefault(require("formiojs/utils"));
55
- var _ = __importStar(require("lodash"));
56
- var moment_1 = __importDefault(require("moment"));
57
- var TimeHelper_1 = __importDefault(require("../util/TimeHelper"));
58
- var Field = formiojs_1.Components.components.field;
59
- var Day = formiojs_1.Components.components.day;
60
- // @ts-ignore
61
- var GDSDatetimeComponent = /** @class */ (function (_super) {
62
- __extends(GDSDatetimeComponent, _super);
63
- function GDSDatetimeComponent() {
64
- var _this = _super !== null && _super.apply(this, arguments) || this;
65
- _this.timeHelper = new TimeHelper_1.default();
66
- return _this;
29
+ const js_1 = require("@formio/js");
30
+ const js_2 = require("@formio/js");
31
+ const _ = __importStar(require("lodash"));
32
+ const moment_1 = __importDefault(require("moment"));
33
+ const TimeHelper_1 = __importDefault(require("../util/TimeHelper"));
34
+ const Field = js_1.Components.components.field;
35
+ const Day = js_1.Components.components.day;
36
+ class GDSDatetimeComponent extends Day {
37
+ constructor() {
38
+ super(...arguments);
39
+ this.timeHelper = new TimeHelper_1.default();
67
40
  }
68
- Object.defineProperty(GDSDatetimeComponent.prototype, "format", {
69
- get: function () {
70
- return 'DD-MM-YYYY';
71
- },
72
- enumerable: false,
73
- configurable: true
74
- });
75
- Object.defineProperty(GDSDatetimeComponent.prototype, "defaultValue", {
76
- // @ts-ignore
77
- get: function () {
78
- var defaultValue = this.component.defaultValue;
79
- if (!defaultValue && this.component.defaultDate) {
80
- defaultValue = utils_1.default.getDateSetting(this.component.defaultDate);
81
- defaultValue = defaultValue ? (0, moment_1.default)(defaultValue).format() : '';
82
- }
83
- return defaultValue;
84
- },
85
- enumerable: false,
86
- configurable: true
87
- });
88
- Object.defineProperty(GDSDatetimeComponent.prototype, "emptyValue", {
89
- // @ts-ignore
90
- get: function () {
91
- return null;
92
- },
93
- enumerable: false,
94
- configurable: true
95
- });
96
- Object.defineProperty(GDSDatetimeComponent.prototype, "parts", {
97
- get: function () {
98
- return {
99
- day: this.getFieldValue('day'),
100
- month: this.getFieldValue('month'),
101
- year: this.getFieldValue('year'),
102
- hour: this.getFieldValue('hour'),
103
- minute: this.getFieldValue('minute'),
104
- };
105
- },
106
- enumerable: false,
107
- configurable: true
108
- });
109
- GDSDatetimeComponent.prototype.attach = function (element) {
110
- var _this = this;
41
+ get format() {
42
+ return 'DD-MM-YYYY';
43
+ }
44
+ get defaultValue() {
45
+ let defaultValue = this.component.defaultValue;
46
+ if (!defaultValue && this.component.defaultDate) {
47
+ defaultValue = js_2.Utils.getDateSetting(this.component.defaultDate);
48
+ defaultValue = defaultValue ? (0, moment_1.default)(defaultValue).format() : '';
49
+ }
50
+ return defaultValue !== null && defaultValue !== void 0 ? defaultValue : '';
51
+ }
52
+ get emptyValue() {
53
+ return null;
54
+ }
55
+ get parts() {
56
+ return {
57
+ day: this.getFieldValue('day'),
58
+ month: this.getFieldValue('month'),
59
+ year: this.getFieldValue('year'),
60
+ hour: this.getFieldValue('hour'),
61
+ minute: this.getFieldValue('minute'),
62
+ };
63
+ }
64
+ // element typed as `any` to match the base Day.attach(element: any) override signature
65
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
66
+ attach(element) {
111
67
  this.loadRefs(element, { hour: 'single', minute: 'single' });
112
- this.addEventListener(this.refs.hour, 'input', function () {
113
- _this.timeHelper.checkAndValidateHour(_this.refs.hour);
114
- _this.setPristine(false);
115
- _this.checkComponentValidity(_this.data, true);
116
- _this.updateValue(null, {
117
- modified: true,
118
- });
119
- _this.triggerChange();
68
+ this.addEventListener(this.refs.hour, 'input', () => {
69
+ this.timeHelper.checkAndValidateHour(this.refs.hour);
70
+ this.setPristine(false);
71
+ this.checkComponentValidity(this.data, true);
72
+ this.updateValue(null, { modified: true });
73
+ this.triggerChange();
120
74
  });
121
- this.addEventListener(this.refs.minute, 'input', function () {
122
- _this.timeHelper.checkAndValidateMinutes(_this.refs.minute);
123
- _this.setPristine(false);
124
- _this.checkComponentValidity(_this.data, true);
125
- _this.updateValue(null, {
126
- modified: true,
127
- });
128
- _this.triggerChange();
75
+ this.addEventListener(this.refs.minute, 'input', () => {
76
+ this.timeHelper.checkAndValidateMinutes(this.refs.minute);
77
+ this.setPristine(false);
78
+ this.checkComponentValidity(this.data, true);
79
+ this.updateValue(null, { modified: true });
80
+ this.triggerChange();
129
81
  });
130
82
  this.addEventListener(this.refs.hour, 'keypress', this.timeHelper.preventNonNumericKeyPress);
131
83
  this.addEventListener(this.refs.minute, 'keypress', this.timeHelper.preventNonNumericKeyPress);
@@ -133,48 +85,73 @@ var GDSDatetimeComponent = /** @class */ (function (_super) {
133
85
  this.setDisabled(this.refs.hour, true);
134
86
  this.setDisabled(this.refs.minute, true);
135
87
  }
136
- var superAttach = _super.prototype.attach.call(this, element);
88
+ const superAttach = super.attach(element);
137
89
  this.addEventListener(this.refs.year, 'keypress', this.timeHelper.preventNonNumericKeyPress);
138
90
  this.addEventListener(this.refs.month, 'keypress', this.timeHelper.preventNonNumericKeyPress);
139
91
  this.addEventListener(this.refs.day, 'keypress', this.timeHelper.preventNonNumericKeyPress);
140
- this.addEventListener(this.refs.year, 'input', function () {
141
- _this.timeHelper.validateDateInput(_this.refs.year, 4);
92
+ this.addEventListener(this.refs.year, 'input', () => {
93
+ this.timeHelper.validateDateInput(this.refs.year, 4);
142
94
  });
143
- this.addEventListener(this.refs.day, 'input', function () {
144
- _this.timeHelper.validateDateInput(_this.refs.day, 2);
95
+ this.addEventListener(this.refs.day, 'input', () => {
96
+ this.timeHelper.validateDateInput(this.refs.day, 2);
145
97
  });
146
- this.addEventListener(this.refs.month, 'input', function () {
147
- _this.timeHelper.validateDateInput(_this.refs.month, 2);
98
+ this.addEventListener(this.refs.month, 'input', () => {
99
+ this.timeHelper.validateDateInput(this.refs.month, 2);
148
100
  });
149
101
  return superAttach;
150
- };
151
- GDSDatetimeComponent.prototype.init = function () {
152
- _super.prototype.init.call(this);
153
- this.validators = this.validators.filter(function (v) { return v !== 'day'; }).concat(['date']);
154
- this.component.maxDate = this.component.datePicker.maxDate;
155
- this.component.minDate = this.component.datePicker.minDate;
102
+ }
103
+ /**
104
+ * Override t() to remap translation keys emitted by @formio/core validators that
105
+ * differ from the @formio/js English translation map.
106
+ *
107
+ * @formio/core's date validator emits FieldError('invalidDate', ...) (camelCase).
108
+ * @formio/js translations only define 'invalid_date' (underscore). When t()
109
+ * cannot find 'invalidDate' it returns the raw key as the error message.
110
+ *
111
+ * We map the camelCase core keys to their underscored @formio/js equivalents so
112
+ * the user sees a proper human-readable message.
113
+ */
114
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
115
+ t(text, ...args) {
116
+ var _a;
117
+ const keyMap = {
118
+ invalidDate: 'invalid_date',
119
+ };
120
+ return super.t((_a = keyMap[text]) !== null && _a !== void 0 ? _a : text, ...args);
121
+ }
122
+ init() {
123
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
124
+ super.init();
125
+ // @formio/js@5.x: this.validators is not pre-populated by the base class; guard before filtering
126
+ this.validators = (this.validators || []).filter((v) => v !== 'day').concat(['date']);
127
+ this.component.maxDate = (_b = (_a = this.component.datePicker) === null || _a === void 0 ? void 0 : _a.maxDate) !== null && _b !== void 0 ? _b : undefined;
128
+ this.component.minDate = (_d = (_c = this.component.datePicker) === null || _c === void 0 ? void 0 : _c.minDate) !== null && _d !== void 0 ? _d : undefined;
156
129
  this.component.suffix = null;
157
- this.component.fields.day.required = this.component.validate.required;
158
- this.component.fields.month.required = this.component.validate.required;
159
- this.component.fields.year.required = this.component.validate.required;
130
+ this.component.fields.day.required = (_e = this.component.validate) === null || _e === void 0 ? void 0 : _e.required;
131
+ this.component.fields.month.required = (_f = this.component.validate) === null || _f === void 0 ? void 0 : _f.required;
132
+ this.component.fields.year.required = (_g = this.component.validate) === null || _g === void 0 ? void 0 : _g.required;
160
133
  this.component.fields.hour = {
161
- type: 'number', placeholder: 'HH',
162
- required: this.component.validate.required,
134
+ type: 'number',
135
+ placeholder: 'HH',
136
+ required: (_h = this.component.validate) === null || _h === void 0 ? void 0 : _h.required,
163
137
  };
164
138
  this.component.fields.minute = {
165
- type: 'number', placeholder: 'MM',
166
- required: this.component.validate.required,
139
+ type: 'number',
140
+ placeholder: 'MM',
141
+ required: (_j = this.component.validate) === null || _j === void 0 ? void 0 : _j.required,
167
142
  };
168
- };
169
- GDSDatetimeComponent.prototype.setErrorClasses = function (elements, dirty, hasError) {
170
- // @ts-ignore
171
- _super.prototype.setErrorClasses.call(this, __spreadArray([this.refs.hour, this.refs.minute], elements, true), dirty, hasError);
172
- };
173
- GDSDatetimeComponent.prototype.removeInputError = function (elements) {
174
- // @ts-ignore
175
- _super.prototype.removeInputError.call(this, __spreadArray([this.refs.hour, this.refs.minute], elements, true));
176
- };
177
- GDSDatetimeComponent.prototype.render = function () {
143
+ }
144
+ // elements typed as `any` to match the base Day.setErrorClasses(elements: any, ...) override signature
145
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
146
+ setErrorClasses(elements, dirty, hasError) {
147
+ super.setErrorClasses([this.refs.hour, this.refs.minute, ...elements], dirty, hasError);
148
+ }
149
+ // elements typed as `any` to match the base Component.removeInputError(elements: any) signature
150
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
151
+ removeInputError(elements) {
152
+ super.removeInputError([this.refs.hour, this.refs.minute, ...elements]);
153
+ }
154
+ render() {
178
155
  return Field.prototype.render.call(this, this.renderTemplate('datetime', {
179
156
  component: this.component,
180
157
  dataValue: this.dataValue,
@@ -186,45 +163,49 @@ var GDSDatetimeComponent = /** @class */ (function (_super) {
186
163
  hour: this.renderField('hour'),
187
164
  minute: this.renderField('minute'),
188
165
  }));
189
- };
190
- GDSDatetimeComponent.prototype.getDate = function (value) {
191
- var defaults = [];
192
- var _a = [0, 1, 2, 3, 4], DAY = _a[0], MONTH = _a[1], YEAR = _a[2], HOUR = _a[3], MINUTE = _a[4];
193
- var defaultValue = value || this.component.defaultValue;
166
+ }
167
+ // value typed as `any` to match the base Day.getDate(value: any): null | string signature
168
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
169
+ getDate(value) {
170
+ const defaults = [];
171
+ const [DAY, MONTH, YEAR, HOUR, MINUTE] = [0, 1, 2, 3, 4];
172
+ const defaultValue = value || this.component.defaultValue;
194
173
  if (defaultValue) {
195
174
  try {
196
- var defaultDate = (0, moment_1.default)(defaultValue);
175
+ const defaultDate = (0, moment_1.default)(defaultValue);
197
176
  defaults[DAY] = defaultDate.format('DD');
198
177
  defaults[MONTH] = defaultDate.format('MM');
199
178
  defaults[YEAR] = defaultDate.format('YYYY');
200
179
  defaults[HOUR] = defaultDate.format('HH');
201
180
  defaults[MINUTE] = defaultDate.format('mm');
202
181
  }
203
- catch (e) {
182
+ catch (_a) {
204
183
  // ignored
205
184
  }
206
185
  }
207
- var day = this.processField('day', defaults, DAY);
208
- var month = this.processField('month', defaults, MONTH);
209
- var year = this.processField('year', defaults, YEAR);
210
- var hour = this.processField('hour', defaults, HOUR);
211
- var minute = this.processField('minute', defaults, MINUTE);
186
+ const day = this.processField('day', defaults, DAY);
187
+ const month = this.processField('month', defaults, MONTH);
188
+ const year = this.processField('year', defaults, YEAR);
189
+ const hour = this.processField('hour', defaults, HOUR);
190
+ const minute = this.processField('minute', defaults, MINUTE);
212
191
  if (!day && !month && !year && (!hour && !minute)) {
213
192
  return null;
214
193
  }
215
- day = day.toString().padStart(2, 0);
216
- month = month.toString().padStart(2, 0);
217
- year = year.toString().padStart(4, 0);
218
- hour = hour.toString().padStart(2, 0);
219
- minute = minute.toString().padStart(2, 0);
220
- var toMoment = (0, moment_1.default)("".concat(year, "-").concat(month, "-").concat(day, " ").concat(hour, ":").concat(minute), 'YYYY-MM-DD HH:mm');
194
+ const dayStr = day.toString().padStart(2, '0');
195
+ const monthStr = month.toString().padStart(2, '0');
196
+ const yearStr = year.toString().padStart(4, '0');
197
+ const hourStr = hour.toString().padStart(2, '0');
198
+ const minuteStr = minute.toString().padStart(2, '0');
199
+ const toMoment = (0, moment_1.default)(`${yearStr}-${monthStr}-${dayStr} ${hourStr}:${minuteStr}`, 'YYYY-MM-DD HH:mm');
221
200
  return toMoment.format();
222
- };
223
- GDSDatetimeComponent.prototype.getFieldValue = function (name) {
201
+ }
202
+ // name typed as `any` to match the base Day.getFieldValue(name: any): number signature
203
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
204
+ getFieldValue(name) {
224
205
  if (this.dataValue && this.dataValue !== 'Invalid date') {
225
206
  try {
226
- var val = null;
227
- var date = (0, moment_1.default)(this.dataValue, 'YYYY-MM-DD HH:mm');
207
+ let val = null;
208
+ const date = (0, moment_1.default)(this.dataValue, 'YYYY-MM-DD HH:mm');
228
209
  switch (name) {
229
210
  case 'month':
230
211
  val = date.format('MM');
@@ -244,13 +225,13 @@ var GDSDatetimeComponent = /** @class */ (function (_super) {
244
225
  }
245
226
  return val;
246
227
  }
247
- catch (e) {
228
+ catch (_a) {
248
229
  return null;
249
230
  }
250
231
  }
251
232
  return null;
252
- };
253
- GDSDatetimeComponent.prototype.boolValue = function (value) {
233
+ }
234
+ boolValue(value) {
254
235
  if (_.isBoolean(value)) {
255
236
  return value;
256
237
  }
@@ -260,14 +241,15 @@ var GDSDatetimeComponent = /** @class */ (function (_super) {
260
241
  else {
261
242
  return !!value;
262
243
  }
263
- };
264
- GDSDatetimeComponent.prototype.setValueAt = function (index, value) {
265
- // temporary solution to avoid input reset
266
- // on invalid date.
244
+ }
245
+ // value typed as `any` to match the base Day.setValueAt(index: number, value: any) signature
246
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
247
+ setValueAt(_index, value) {
248
+ // temporary solution to avoid input reset on invalid date.
267
249
  if (!value || value === 'Invalid date') {
268
250
  return;
269
251
  }
270
- var date = (0, moment_1.default)(value, moment_1.default.ISO_8601);
252
+ const date = (0, moment_1.default)(value, moment_1.default.ISO_8601);
271
253
  if (date.isValid()) {
272
254
  if (this.refs.day) {
273
255
  this.refs.day.value = date.format('DD');
@@ -285,10 +267,10 @@ var GDSDatetimeComponent = /** @class */ (function (_super) {
285
267
  this.refs.minute.value = date.format('mm');
286
268
  }
287
269
  }
288
- };
289
- GDSDatetimeComponent.prototype.getValueAt = function (index) {
290
- // @ts-ignore
291
- var date = this.date;
270
+ }
271
+ getValueAt(index) {
272
+ // `date` is a public getter declared on DayComponent: get date(): string | null
273
+ const date = this.date;
292
274
  if (date) {
293
275
  this.refs.input[index].value = date;
294
276
  return this.refs.input[index].value;
@@ -297,39 +279,46 @@ var GDSDatetimeComponent = /** @class */ (function (_super) {
297
279
  this.refs.input[index].value = '';
298
280
  return null;
299
281
  }
300
- };
301
- GDSDatetimeComponent.prototype.normalizeValue = function (value) {
282
+ }
283
+ // value typed as `any` to match the base Component.normalizeValue(value: any): any signature
284
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
285
+ normalizeValue(value) {
302
286
  return value;
303
- };
304
- GDSDatetimeComponent.prototype.validateRequired = function (setting, value) {
305
- var _a = this.parts, day = _a.day, month = _a.month, year = _a.year, minute = _a.minute, hour = _a.hour;
306
- if (this.component.validate.required && (!day || parseInt(day, 10) === 0)) {
287
+ }
288
+ // setting/value typed as `any` to match the base Day.validateRequired(setting: any, value: any) signature
289
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
290
+ validateRequired(setting, value) {
291
+ var _a, _b, _c, _d, _e;
292
+ const { day, month, year, minute, hour } = this.parts;
293
+ if (((_a = this.component.validate) === null || _a === void 0 ? void 0 : _a.required) && (!day || parseInt(day, 10) === 0)) {
307
294
  return false;
308
295
  }
309
- if (this.component.validate.required && (!month || parseInt(month, 10) === 0)) {
296
+ if (((_b = this.component.validate) === null || _b === void 0 ? void 0 : _b.required) && (!month || parseInt(month, 10) === 0)) {
310
297
  return false;
311
298
  }
312
- if (this.component.validate.required && (!year || parseInt(year, 10) === 0)) {
299
+ if (((_c = this.component.validate) === null || _c === void 0 ? void 0 : _c.required) && (!year || parseInt(year, 10) === 0)) {
313
300
  return false;
314
301
  }
315
- if (this.component.validate.required && ((this.refs.minute && this.refs.minute.value === '') || !minute)) {
302
+ if (((_d = this.component.validate) === null || _d === void 0 ? void 0 : _d.required) && (this.refs.minute.value === '' || !minute)) {
316
303
  return false;
317
304
  }
318
- if (this.component.validate.required && ((this.refs.hour && this.refs.hour.value === '') || !hour)) {
305
+ if (((_e = this.component.validate) === null || _e === void 0 ? void 0 : _e.required) && (this.refs.hour.value === '' || !hour)) {
319
306
  return false;
320
307
  }
321
308
  if (!this.boolValue(setting)) {
322
309
  return true;
323
310
  }
324
311
  return !this.isEmpty(value);
325
- };
326
- GDSDatetimeComponent.prototype.processField = function (field, defaults, fieldIndex) {
327
- var fieldValue = this.refs["".concat(field)] ? parseInt(this.refs["".concat(field)].value, 10) : undefined;
312
+ }
313
+ processField(field, defaults, fieldIndex) {
314
+ const refKey = field;
315
+ const ref = this.refs[refKey];
316
+ const inputRef = ref instanceof HTMLInputElement ? ref : undefined;
317
+ let fieldValue = inputRef ? parseInt(inputRef.value, 10) : undefined;
328
318
  if (fieldValue === undefined || _.isNaN(fieldValue)) {
329
- fieldValue = defaults[fieldIndex] && !_.isNaN(defaults[fieldIndex]) ? defaults[fieldIndex] : 0;
319
+ fieldValue = defaults[fieldIndex] && !_.isNaN(defaults[fieldIndex]) ? Number(defaults[fieldIndex]) : 0;
330
320
  }
331
321
  return fieldValue;
332
- };
333
- return GDSDatetimeComponent;
334
- }(Day));
322
+ }
323
+ }
335
324
  exports.default = GDSDatetimeComponent;
@@ -1,11 +1,14 @@
1
1
  import datamap from './datamap/GDSDataMap';
2
2
  import datetime from './datetime/GDSDatetimeComponent';
3
+ import select from './select/GDSSelect';
3
4
  import selectboxes from './selectboxes/GDSCheckBoxes';
4
5
  import time from './time/GDSTimeComponent';
5
6
  declare const _default: {
6
7
  datamap: typeof datamap;
7
8
  datetime: typeof datetime;
9
+ select: typeof select;
8
10
  selectboxes: typeof selectboxes;
9
11
  time: typeof time;
10
12
  };
11
13
  export default _default;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,sBAAsB,CAAC;AAC3C,OAAO,QAAQ,MAAM,iCAAiC,CAAC;AACvD,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,WAAW,MAAM,6BAA6B,CAAC;AACtD,OAAO,IAAI,MAAM,yBAAyB,CAAC;;;;;;;;AAE3C,wBAME"}
@@ -3,13 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var GDSDataMap_1 = __importDefault(require("./datamap/GDSDataMap"));
7
- var GDSDatetimeComponent_1 = __importDefault(require("./datetime/GDSDatetimeComponent"));
8
- var GDSCheckBoxes_1 = __importDefault(require("./selectboxes/GDSCheckBoxes"));
9
- var GDSTimeComponent_1 = __importDefault(require("./time/GDSTimeComponent"));
6
+ const GDSDataMap_1 = __importDefault(require("./datamap/GDSDataMap"));
7
+ const GDSDatetimeComponent_1 = __importDefault(require("./datetime/GDSDatetimeComponent"));
8
+ const GDSSelect_1 = __importDefault(require("./select/GDSSelect"));
9
+ const GDSCheckBoxes_1 = __importDefault(require("./selectboxes/GDSCheckBoxes"));
10
+ const GDSTimeComponent_1 = __importDefault(require("./time/GDSTimeComponent"));
10
11
  exports.default = {
11
12
  datamap: GDSDataMap_1.default,
12
13
  datetime: GDSDatetimeComponent_1.default,
14
+ select: GDSSelect_1.default,
13
15
  selectboxes: GDSCheckBoxes_1.default,
14
16
  time: GDSTimeComponent_1.default,
15
17
  };
@@ -0,0 +1,143 @@
1
+ import { SelectComponent as CoreSelectComponent } from '../../types';
2
+ declare const Select: any;
3
+ interface ChoiceItem {
4
+ label: string;
5
+ active: boolean;
6
+ rank: number;
7
+ id: string | number;
8
+ choiceEl?: HTMLElement;
9
+ [key: string]: unknown;
10
+ }
11
+ interface SearchResult {
12
+ item: ChoiceItem;
13
+ score: number;
14
+ rank: number;
15
+ }
16
+ interface ChoicesInstance {
17
+ _isSearching: boolean;
18
+ _currentValue: string;
19
+ _store: {
20
+ choices: ChoiceItem[];
21
+ dispatch(action: {
22
+ type: string;
23
+ active?: boolean;
24
+ results?: SearchResult[];
25
+ }): void;
26
+ };
27
+ _searchChoices?: (needle: string) => number | null;
28
+ input?: {
29
+ element?: HTMLInputElement;
30
+ };
31
+ }
32
+ /**
33
+ * A formio item from a URL datasource — at minimum it has an id and arbitrary
34
+ * string fields (e.g. name, code). We only constrain what we actually access.
35
+ */
36
+ interface ReferenceItem {
37
+ id?: string | number;
38
+ label?: string;
39
+ [key: string]: unknown;
40
+ }
41
+ /**
42
+ * Shape of the `value` argument passed to itemTemplate / getOptionTemplate.
43
+ * For reference selects (valueProperty = '') this is the full item object;
44
+ * for string selects it is a plain string.
45
+ */
46
+ type SelectValue = ReferenceItem | string | number | null | undefined;
47
+ export default class GDSSelect extends Select {
48
+ component: CoreSelectComponent;
49
+ protected _gdsSearchPatchedChoices?: ChoicesInstance;
50
+ protected _gdsFilterKey?: string;
51
+ constructor(component?: any, options?: any, data?: any);
52
+ init(): any;
53
+ /**
54
+ * Patch the choices.js instance attached to this component so that every
55
+ * search query uses a plain case-insensitive substring filter instead of
56
+ * fuse.js. The patch is applied lazily the first time items are set so
57
+ * that `this.choices` is guaranteed to exist.
58
+ */
59
+ protected _patchChoicesSearch(): void;
60
+ /**
61
+ * True when this select's `filter` is interpolated from other form data
62
+ * (e.g. a port list filtered by the selected country).
63
+ */
64
+ protected get _gdsHasDynamicFilter(): boolean;
65
+ /** The interpolated filter, used to detect when the dependency changed. */
66
+ protected _gdsCurrentFilterKey(): string;
67
+ setItems(items: unknown, fromSearch?: boolean): void;
68
+ attach(element: HTMLElement): Promise<unknown>;
69
+ checkComponentConditions(data: any, flags: any, row: any): boolean;
70
+ updateItems(searchInput: unknown, forceUpdate: boolean): any;
71
+ /**
72
+ * Override getOptionTemplate to escape item data values with `_.escape()`
73
+ * before interpolating them into the template.
74
+ *
75
+ * ## Security model
76
+ *
77
+ * formio 5.x `getOptionTemplate` (ListComponent) passes the assembled template
78
+ * string through `DOMPurify.sanitize()` — which internally calls
79
+ * `DOMParser.parseFromString()`. With thousands of reference-data items this
80
+ * is the dominant performance cost (~300 ms).
81
+ *
82
+ * We replace that post-hoc sanitization with pre-interpolation escaping:
83
+ *
84
+ * 1. Every string value in the item object is passed through `_.escape()`
85
+ * **before** it is substituted into the template. `_.escape` converts
86
+ * `< > & " '` to their HTML-entity equivalents (`&lt;` etc.).
87
+ * 2. The assembled template string — now containing only safe entity-encoded
88
+ * text where user/API data appears — is returned directly without any
89
+ * further DOMPurify call.
90
+ *
91
+ * ### Why this is equivalent security to DOMPurify for text-content templates
92
+ *
93
+ * A template such as `<span>{{ item.name }}</span>` embeds the API value as
94
+ * the *text content* of an element. The only injection vector is:
95
+ *
96
+ * ```
97
+ * item.name = '</span><script>alert(1)</script>'
98
+ * ```
99
+ *
100
+ * After `_.escape()` this becomes:
101
+ *
102
+ * ```
103
+ * &lt;/span&gt;&lt;script&gt;alert(1)&lt;/script&gt;
104
+ * ```
105
+ *
106
+ * The browser renders this as literal text, never as markup or script.
107
+ * DOMPurify would produce the same effective result by stripping the tags.
108
+ *
109
+ * ### Limitation — attribute / URL contexts
110
+ *
111
+ * `_.escape()` is **not** sufficient if the template places a value inside
112
+ * an HTML attribute or a URL (e.g. `<a href="{{ item.url }}">`).
113
+ * HTML-entity encoding does not prevent `javascript:` injection in `href`.
114
+ * If any form schema introduces such a template, this override must be
115
+ * revisited and either DOMPurify reinstated or the attribute value
116
+ * sanitized separately.
117
+ *
118
+ * Current GDS templates are all text-content only (`<span>{{ item.name }}</span>`
119
+ * etc.) so this limitation does not apply today.
120
+ */
121
+ getOptionTemplate(data: ReferenceItem, value: SelectValue, index?: number): string;
122
+ /**
123
+ * Override itemTemplate to skip the redundant outer `sanitize()` call that
124
+ * formio 5.x `ListComponent.itemTemplate` wraps around `getOptionTemplate()`.
125
+ *
126
+ * ## Why the outer sanitize is now safe to skip
127
+ *
128
+ * Our `getOptionTemplate` override (above) pre-escapes all API data values
129
+ * with `_.escape()` before they are interpolated into the template. The
130
+ * assembled string therefore contains no unescaped HTML from variable sources.
131
+ * Running DOMPurify on that string a second time is idempotent — it produces
132
+ * the same output — but costs a full `DOMParser.parseFromString` call per item.
133
+ *
134
+ * This override handles only the common URL-datasource path (object data with
135
+ * a component template). All other branches — primitives, arrays, read-only,
136
+ * selectData, reference fields — fall through to `super.itemTemplate` which
137
+ * retains its full sanitize() call unchanged.
138
+ */
139
+ itemTemplate(data: ReferenceItem | string | number | unknown[], value: SelectValue, index?: number): any;
140
+ choicesOptions(): Record<string, any>;
141
+ }
142
+ export {};
143
+ //# sourceMappingURL=GDSSelect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GDSSelect.d.ts","sourceRoot":"","sources":["../../../src/components/select/GDSSelect.ts"],"names":[],"mappings":"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"}