@ukhomeoffice/cop-react-form-renderer 3.2.6 → 3.3.1-alpha

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.
@@ -37,14 +37,6 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
37
37
 
38
38
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
39
39
 
40
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
41
-
42
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
43
-
44
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
45
-
46
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
47
-
48
40
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
49
41
 
50
42
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -97,7 +89,7 @@ var Collection = function Collection(_ref) {
97
89
  var itemIndex = value.findIndex(function (item) {
98
90
  return item.id === target.name;
99
91
  });
100
- reportChange([].concat(_toConsumableArray(value.slice(0, itemIndex)), [target.value], _toConsumableArray(value.slice(itemIndex + 1))));
92
+ reportChange([].concat(value.slice(0, itemIndex), [target.value], value.slice(itemIndex + 1)));
101
93
  }
102
94
  }
103
95
  };
@@ -108,7 +100,7 @@ var Collection = function Collection(_ref) {
108
100
  while (1) {
109
101
  switch (_context.prev = _context.next) {
110
102
  case 0:
111
- reportChange([].concat(_toConsumableArray(value), [{
103
+ reportChange([].concat(value, [{
112
104
  id: Date.now().toString()
113
105
  }]));
114
106
 
@@ -24,18 +24,6 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
24
24
 
25
25
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
26
26
 
27
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
28
-
29
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
30
-
31
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
32
-
33
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
34
-
35
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
36
-
37
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
38
-
39
27
  describe('components.FormPage', function () {
40
28
  describe('FormPage', function () {
41
29
  var TEXT = {
@@ -142,11 +130,9 @@ describe('components.FormPage', function () {
142
130
  expect(outerWrapper.classList).toContain('hods-autocomplete__outer-wrapper');
143
131
  var autocomplete = outerWrapper.childNodes[0];
144
132
  expect(autocomplete.classList).toContain('hods-autocomplete__wrapper');
145
-
146
- var input = _toConsumableArray(autocomplete.childNodes).filter(function (e) {
133
+ var input = [].concat(autocomplete.childNodes).filter(function (e) {
147
134
  return e.tagName === 'INPUT';
148
135
  })[0];
149
-
150
136
  expect(input.classList).toContain('hods-autocomplete__input');
151
137
  expect(input.tagName).toEqual('INPUT');
152
138
  expect(input.id).toEqual(fieldId);
@@ -17,14 +17,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
17
17
 
18
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
19
 
20
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
21
-
22
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
23
-
24
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
25
-
26
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
27
-
28
20
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
29
21
 
30
22
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -59,7 +51,7 @@ var ValidationContextProvider = function ValidationContextProvider(_ref) {
59
51
  switch (_context.prev = _context.next) {
60
52
  case 0:
61
53
  setErrors(function (prev) {
62
- return [].concat(_toConsumableArray(prev), _toConsumableArray(errors)).filter(function (e) {
54
+ return [].concat(prev, errors).filter(function (e) {
63
55
  return !!e;
64
56
  });
65
57
  });
@@ -19,6 +19,7 @@ var TYPE_RADIOS = 'radios';
19
19
  var TYPE_TEXT = 'text';
20
20
  var TYPE_TEXT_AREA = 'textarea';
21
21
  var TYPE_TIME = 'time';
22
+ var TYPE_WARNING = 'warning';
22
23
  var ComponentTypes = {
23
24
  AUTOCOMPLETE: TYPE_AUTOCOMPLETE,
24
25
  CHECKBOXES: TYPE_CHECKBOXES,
@@ -34,7 +35,8 @@ var ComponentTypes = {
34
35
  RADIOS: TYPE_RADIOS,
35
36
  TEXT: TYPE_TEXT,
36
37
  TEXT_AREA: TYPE_TEXT_AREA,
37
- TIME: TYPE_TIME
38
+ TIME: TYPE_TIME,
39
+ WARNING: TYPE_WARNING
38
40
  };
39
41
  var _default = ComponentTypes;
40
42
  exports.default = _default;
@@ -15,18 +15,6 @@ var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
19
-
20
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
21
-
22
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
23
-
24
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
25
-
26
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
27
-
28
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
29
-
30
18
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
31
19
 
32
20
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -76,7 +64,7 @@ var getCYARowsForCollection = function getCYARowsForCollection(page, collection,
76
64
  var labelCount = (collection.countOffset || 0) + index + 1;
77
65
  var full_path = "".concat(collection.full_path || collection.fieldId, "[").concat(index, "]");
78
66
  var container = getContainerForItem(collection, item, labelCount, full_path);
79
- return [getTitleRowForItem(collection, item, page.id, labelCount, full_path)].concat(_toConsumableArray((0, _getCYARowsForContainer.default)(page, container, item, onAction)));
67
+ return [getTitleRowForItem(collection, item, page.id, labelCount, full_path)].concat((0, _getCYARowsForContainer.default)(page, container, item, onAction));
80
68
  }).filter(function (r) {
81
69
  return !!r;
82
70
  });
@@ -7,18 +7,6 @@ exports.default = exports.JSON_ONLY_PROPERTIES = void 0;
7
7
 
8
8
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
9
9
 
10
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
11
-
12
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
-
14
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
-
16
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
17
-
18
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
19
-
20
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
21
-
22
10
  var JSON_ONLY_PROPERTIES = ['source', 'use', 'show_when', 'options', 'additionalValidation', 'full_path', 'formData'];
23
11
  /**
24
12
  * This method removes and properties that are entirely specific to the JSON
@@ -36,7 +24,7 @@ exports.JSON_ONLY_PROPERTIES = JSON_ONLY_PROPERTIES;
36
24
 
37
25
  var cleanAttributes = function cleanAttributes(options) {
38
26
  var alsoRemove = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
39
- var removeKeys = Array.isArray(alsoRemove) ? [].concat(JSON_ONLY_PROPERTIES, _toConsumableArray(alsoRemove)) : JSON_ONLY_PROPERTIES;
27
+ var removeKeys = Array.isArray(alsoRemove) ? [].concat(JSON_ONLY_PROPERTIES, alsoRemove) : JSON_ONLY_PROPERTIES;
40
28
 
41
29
  if (options && _typeof(options) === 'object') {
42
30
  return Object.keys(options).reduce(function (obj, key) {
@@ -114,6 +114,11 @@ var getTime = function getTime(config) {
114
114
  return /*#__PURE__*/_react.default.createElement(_copReactComponents.TimeInput, attrs);
115
115
  };
116
116
 
117
+ var getWarningText = function getWarningText(config) {
118
+ var attrs = (0, _cleanAttributes.default)(config);
119
+ return /*#__PURE__*/_react.default.createElement(_copReactComponents.WarningText, attrs, config.content);
120
+ };
121
+
117
122
  var getComponentByType = function getComponentByType(config) {
118
123
  switch (config.type) {
119
124
  case _models.ComponentTypes.HTML:
@@ -151,6 +156,9 @@ var getComponentByType = function getComponentByType(config) {
151
156
  case _models.ComponentTypes.FILE:
152
157
  return getFileUpload(config);
153
158
 
159
+ case _models.ComponentTypes.WARNING:
160
+ return getWarningText(config);
161
+
154
162
  default:
155
163
  {
156
164
  return null;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+
5
+ var _models = require("../../../models");
6
+
7
+ var _getComponent = _interopRequireDefault(require("../getComponent"));
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ // Global imports
12
+ // Local imports
13
+ describe('utils.Component.get', function () {
14
+ it('should return an appropriately rendered warning-text component', function () {
15
+ var ID = 'test-id';
16
+ var CONTENT = 'Warning Text';
17
+ var COMPONENT = {
18
+ type: _models.ComponentTypes.WARNING,
19
+ content: CONTENT,
20
+ 'data-testid': ID
21
+ };
22
+
23
+ var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
24
+ container = _render.container;
25
+
26
+ var warningText = (0, _react.getByTestId)(container, ID);
27
+ expect(warningText.innerHTML).toContain(CONTENT);
28
+ expect(warningText.tagName).toEqual('DIV');
29
+ expect(warningText.classList).toContain('govuk-warning-text');
30
+ });
31
+ });
@@ -8,18 +8,7 @@ var _getEditableComponents = _interopRequireDefault(require("./getEditableCompon
8
8
 
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
10
 
11
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
-
13
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
-
15
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
-
17
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
18
-
19
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
20
-
21
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
22
-
11
+ // Local imports
23
12
  describe('utils.Container.getEditableComponents', function () {
24
13
  var HTML = {
25
14
  type: 'html',
@@ -130,13 +119,13 @@ describe('utils.Container.getEditableComponents', function () {
130
119
  });
131
120
 
132
121
  var NON_EDITABLE_COMPONENTS = [HTML, INSET_TEXT, HEADING];
133
- var COMPONENTS = [].concat(_toConsumableArray(EDITABLE_COMPONENTS), NON_EDITABLE_COMPONENTS, [{
122
+ var COMPONENTS = [].concat(EDITABLE_COMPONENTS, NON_EDITABLE_COMPONENTS, [{
134
123
  type: _models.ComponentTypes.CONTAINER,
135
124
  id: 'inner',
136
- components: [].concat(_toConsumableArray(EDITABLE_COMPONENTS), NON_EDITABLE_COMPONENTS, [{
125
+ components: [].concat(EDITABLE_COMPONENTS, NON_EDITABLE_COMPONENTS, [{
137
126
  type: _models.ComponentTypes.CONTAINER,
138
127
  id: 'inner-inner',
139
- components: [].concat(NON_EDITABLE_COMPONENTS, _toConsumableArray(EDITABLE_COMPONENTS))
128
+ components: [].concat(NON_EDITABLE_COMPONENTS, EDITABLE_COMPONENTS)
140
129
  }])
141
130
  }]);
142
131
  var RESULT = (0, _getEditableComponents.default)({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "3.2.6",
3
+ "version": "3.3.1-alpha",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",
@@ -16,7 +16,7 @@
16
16
  "post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
17
17
  },
18
18
  "dependencies": {
19
- "@ukhomeoffice/cop-react-components": "1.7.4",
19
+ "@ukhomeoffice/cop-react-components": "1.8.0",
20
20
  "axios": "^0.21.1",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^3.13.0",