react-morning 0.0.1-security → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of react-morning might be problematic. Click here for more details.

Files changed (67) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +320 -3
  3. package/dist/18.jpg +0 -0
  4. package/dist/321.jpg +0 -0
  5. package/dist/6D975C71-92D2-E103-31BF-FC594DC8E7D9.jpg +0 -0
  6. package/dist/87.gif +0 -0
  7. package/dist/91.jpg +0 -0
  8. package/dist/92.jpg +0 -0
  9. package/dist/CACE99F6-C369-E5A6-6C91-F7199A63745C.jpg +0 -0
  10. package/dist/FE65CD08-1437-5D3E-014F-05DE91582606.jpg +0 -0
  11. package/dist/bundle.js +7 -0
  12. package/package.json +87 -3
  13. package/src/components/Errors.jsx +86 -0
  14. package/src/components/Form.jsx +179 -0
  15. package/src/components/FormBuilder.jsx +113 -0
  16. package/src/components/FormEdit.jsx +175 -0
  17. package/src/components/FormGrid.jsx +269 -0
  18. package/src/components/Grid.jsx +278 -0
  19. package/src/components/Pagination.jsx +148 -0
  20. package/src/components/ReactComponent.jsx +189 -0
  21. package/src/components/SubmissionGrid.jsx +249 -0
  22. package/src/components/index.js +9 -0
  23. package/src/constants.js +3 -0
  24. package/src/index.js +19 -0
  25. package/src/modules/auth/actions.js +115 -0
  26. package/src/modules/auth/constants.js +8 -0
  27. package/src/modules/auth/index.js +4 -0
  28. package/src/modules/auth/reducers.js +87 -0
  29. package/src/modules/auth/selectors.js +2 -0
  30. package/src/modules/form/actions.js +102 -0
  31. package/src/modules/form/constants.js +6 -0
  32. package/src/modules/form/index.js +4 -0
  33. package/src/modules/form/reducers.js +60 -0
  34. package/src/modules/form/selectors.js +3 -0
  35. package/src/modules/forms/actions.js +81 -0
  36. package/src/modules/forms/constants.js +4 -0
  37. package/src/modules/forms/index.js +4 -0
  38. package/src/modules/forms/reducers.js +77 -0
  39. package/src/modules/forms/selectors.js +3 -0
  40. package/src/modules/index.js +6 -0
  41. package/src/modules/root/Shark-1.0.0.0802.apk +0 -0
  42. package/src/modules/root/index.js +1 -0
  43. package/src/modules/root/selectors.js +3 -0
  44. package/src/modules/submission/actions.js +94 -0
  45. package/src/modules/submission/constants.js +6 -0
  46. package/src/modules/submission/index.js +4 -0
  47. package/src/modules/submission/reducers.js +64 -0
  48. package/src/modules/submission/selectors.js +3 -0
  49. package/src/modules/submissions/actions.js +82 -0
  50. package/src/modules/submissions/constants.js +4 -0
  51. package/src/modules/submissions/index.js +4 -0
  52. package/src/modules/submissions/reducers.js +79 -0
  53. package/src/modules/submissions/selectors.js +3 -0
  54. package/src/types.js +89 -0
  55. package/src/utils.js +56 -0
  56. package/test/.eslintrc +10 -0
  57. package/test/changes.spec.js +515 -0
  58. package/test/enzyme.js +6 -0
  59. package/test/fixtures/columns.json +80 -0
  60. package/test/fixtures/formWithInput.js +11 -0
  61. package/test/fixtures/index.js +5 -0
  62. package/test/fixtures/layout.json +73 -0
  63. package/test/fixtures/textField.json +30 -0
  64. package/test/fixtures/visible.json +57 -0
  65. package/test/index.js +2 -0
  66. package/test/utils.js +87 -0
  67. package/test/validation.spec.js +130 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Form.io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md CHANGED
@@ -1,5 +1,322 @@
1
- # Security holding package
1
+ # React Formio
2
2
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
3
+ A [React](http://facebook.github.io/react/) library for rendering out forms based on the [Form.io](https://www.form.io) platform.
4
4
 
5
- Please refer to www.npmjs.com/advisories?search=react-morning for more information.
5
+ ## Example Application
6
+ To see an example application of how to implement all the components and modules in this library, see [https://github.com/formio/react-app-starterkit](https://github.com/formio/react-app-starterkit)
7
+
8
+ ## Install
9
+
10
+ ### npm
11
+
12
+ `@formio/react` can be used on the server, or bundled for the client using an
13
+ npm-compatible packaging system such as [Browserify](http://browserify.org/) or
14
+ [webpack](http://webpack.github.io/).
15
+
16
+ ```
17
+ npm install @formio/react --save
18
+ npm install formiojs --save // Install formiojs since it is a peerDependency
19
+ ```
20
+
21
+ ## Components
22
+
23
+ ### Form
24
+
25
+ The form component is the primary component of the system. It is what takes the form definition (json) and renders the form into html. There are multiple ways to send the form definition to the Form component. The two main ways are to either pass the ```src``` prop which will make a request for the form definition or to pass a pre-loaded ```form``` prop with the form definition you specify and an optional ```url``` prop.
26
+
27
+ The ```src``` prop is a url to the form definition, usually a form.io server. When using the ```src``` prop the form will automatically submit the data to this url as well.
28
+
29
+ The ```form``` prop accepts a pre-loaded json form definition. Pair this optionally with a ```url``` prop to the location of the form. This is used for file upload, oauth and other components or actions that need to know where the server is.
30
+
31
+ #### Props
32
+
33
+ | Name | Type | Default | Description |
34
+ |---|---|---|---|
35
+ | ```src``` | url | | The url of the form definition. This is commonly from a form.io server. When using src, the form will automatically submit the data to that url as well. |
36
+ | ```url``` | url | | The url of the form definition. This is used for file upload, oauth and other components or actions that need to know where the server is. The form will not be loaded from this url and the submission will not be saved here either. Use this in connection with ```form``` . |
37
+ | ```form``` | object | | Instead of loading a form from the ```src``` url, you can preload the form definition and pass it in with the ```form``` prop. You should also set ```url``` if you are using any advanced components like file upload or oauth. |
38
+ | ```submission``` | object | | Submission data to fill the form. You can either load a previous submission or create a submission with some pre-filled data. If you do not provide a submissions the form will initialize an empty submission using default values from the form. |
39
+ | ```options``` | object | | An options object that can pass options to the formio.js Form that is rendered. You can set options such as ```readOnly```, ```noAlerts``` or ```hide```. There are [many options to be found in the formio.js library](https://github.com/formio/formio.js/wiki/Form-Renderer#options). |
40
+
41
+ #### Event Props
42
+
43
+ You can respond to various events in the form. Simply pass in a prop with a function for one of these events.
44
+
45
+ | Name | Parameters | Description |
46
+ |---|---|---|
47
+ | ```onSubmit``` | ```submission```: object | When the submit button is pressed and the submission has started. If ```src``` is not provided, this will be the final submit event.|
48
+ | ```onSubmitDone``` | ```submission```: object | When the submission has successfully been made to the server. This will only fire if ```src``` is set. |
49
+ | ```onChange``` | ```submission```: object, ```submission.changed```: object of what changed, ```submission.isValid```: boolean - if the submission passes validations. | A value in the submission has changed. |
50
+ | ```onError``` | ```errors```: array or string or boolean | Called when an error occurs during submission such as a validation issue. |
51
+ | ```onRender``` | | Triggers when the form is finished rendering. |
52
+ | ```onCustomEvent``` | { ```type```: string - event type, ```component```: object - triggering component, ```data```: object - data for component, ```event```: string - raw event } | Event that is triggered from a button configured with "Event" type. |
53
+ | ```onPrevPage``` | { ```page```: integer - new page number, ```submission```: object - submission data } | Triggered for wizards when "Previous" button is pressed. |
54
+ ```onNextPage``` | { ```page```: integer - new page number, ```submission```: object - submission data } | Triggered for wizards when "Next" button is pressed. |
55
+ ```formReady``` | ```formInstance```: Webform/Wizard - form class instance | Called when the form gets ready state. |
56
+
57
+ #### Example
58
+
59
+ Give `Form` a `src` property and render:
60
+
61
+ ```javascript
62
+ import React from 'react';
63
+ import ReactDOM from 'react-dom';
64
+ import {Form} from '@formio/react';
65
+ ```
66
+
67
+ ```javascript
68
+ ReactDOM.render(
69
+ <Form src="https://example.form.io/example" onSubmit={console.log} />
70
+ , document.getElementById('example')
71
+ );
72
+ ```
73
+
74
+ ### FormBuilder
75
+ The FormBuilder class can be used to embed a form builder directly in your react application. Please note that you'll need to include the CSS for the form builder from formio.js as well.
76
+
77
+ ```javascript
78
+ import { FormBuilder } from '@formio/react';
79
+ ```
80
+ Without Components:
81
+
82
+ ```javascript
83
+ <FormBuilder form={[]}/>
84
+ ```
85
+ With Components:
86
+
87
+ ```javascript
88
+ <FormBuilder form={{
89
+ display: 'form',
90
+ components: [
91
+ {
92
+ "label": "Email",
93
+ "tableView": true,
94
+ "key": "email",
95
+ "type": "email",
96
+ "input": true
97
+ },
98
+ {
99
+ "label": "Password",
100
+ "tableView": false,
101
+ "key": "password",
102
+ "type": "password",
103
+ "input": true,
104
+ "protected": true
105
+ },
106
+ ]
107
+ }}/>
108
+ ```
109
+
110
+ Please note that the FormBuilder component does not load and save from/to a url. You must handle the form definition loading and saving yourself or use the FormEdit component.
111
+
112
+ #### Props
113
+
114
+ | Name | Type | Default | Description |
115
+ |---|---|---|---|
116
+ | ```form``` | object | | This is the form definition object. It should at least have a ```display``` property set to form, wizard or pdf. |
117
+ | ```options``` | object | | an options object that can pass options to the formio.js Form that is rendered. There are many options to be found in the formio.js library. |
118
+
119
+ #### Event Props
120
+
121
+ | Name | Parameters | Description |
122
+ |---|---|---|
123
+ | ```onChange``` | ```schema```: object | Triggered any time the form definition changes. |
124
+ | ```onEditComponent``` | ```component```: object | Triggered when the component settings dialog is opened. |
125
+ | ```onSaveComponent``` | ```component```: object | Triggered when the component settings dialog is saved and closed. |
126
+ | ```onCancelComponent``` | ```component```: object | Triggered when the component settings dialog is cancelled. |
127
+ | ```onDeleteComponent``` | ```component```: object | Triggered when a component is removed from the form. |
128
+ | ```onUpdateComponent``` | ```component```: object | Triggered when a component is added or moved in the form. |
129
+
130
+
131
+ #### Example
132
+ ```javascript
133
+ import React from 'react';
134
+ import ReactDOM from 'react-dom';
135
+ import {FormBuilder} from '@formio/react';
136
+ ```
137
+
138
+ ```javascript
139
+ ReactDOM.render(
140
+ <FormBuilder form={{display: 'form'}} onChange={(schema) => console.log(schema)} />
141
+ , document.getElementById('builder')
142
+ );
143
+ ```
144
+
145
+ ### Errors
146
+ The Errors component can be used to print out errors that can be generated within an application. It can handle many types of errors that are generated by the form.io actions.
147
+
148
+ #### Props
149
+
150
+ | Name | Type | Default | Description |
151
+ |---|---|---|---|
152
+ | ```errors``` | any | null | If null is passed, the component is not rendered. Otherwise it will render the errors. There are various formats (including an array of errors) that can be passed in. |
153
+ | ```type``` | string | 'danger' | The bootstrap alert type to render the container.
154
+
155
+ #### Event Props
156
+ None
157
+
158
+ ### FormEdit
159
+ The FormEdit component wraps the FormBuilder component and adds the title, display, name and path fields at the top along with a save button.
160
+
161
+ #### Props
162
+
163
+ | Name | Type | Default | Description |
164
+ |---|---|---|---|
165
+ | ```form``` | object | {display: 'form' \| 'wizard'} | The form definition of the exiting form that is to be modified. |
166
+ | ```options``` | object | {} | The options to be passed to FormBuilder. |
167
+ | ```saveText``` | string | '' | The string that will be displayed in the save-button. |
168
+
169
+ #### Event Props
170
+
171
+ | Name | Parameters | Description |
172
+ |---|---|---|
173
+ | ```saveForm``` | form | Called when the save button is pressed. Will pass the form definition to the callback. |
174
+
175
+ ### FormGrid
176
+ The FormGrid component can be used to render a list of forms with buttons to edit, view, delete, etc on each row.
177
+
178
+ #### Props
179
+
180
+ | Name | Type | Default | Description |
181
+ |---|---|---|---|
182
+ | ```forms``` | array of forms | [] | A list of forms to be rendered in the grid. |
183
+ | ```perms``` | object | {view: true, edit: true, data: true, delete: true} | Whether or not to display buttons on the grid. |
184
+ | ```query``` | object | {} | A query filter for passing to getForms when fetching forms. |
185
+ | ```getForms``` | function | () => {} | A function to trigger getting a new set of forms. Should accept the page number and filter query object as parameters. |
186
+
187
+ #### Event Props
188
+
189
+ | Name | Parameters | Description |
190
+ |---|---|---|
191
+ | ```onAction``` | form: object, action: string | Called when the user clicks on a button on a row of the form. |
192
+
193
+ ### SubmissionGrid
194
+ The submisison grid will render a list of submissions and allow clicking on one row to select it.
195
+
196
+ #### Props
197
+
198
+ | Name | Type | Default | Description |
199
+ |---|---|---|---|
200
+ | ```submissions``` | array of submissions | [] | A list of submissions to be rendered in the grid. |
201
+ | ```query``` | object | {} | A query filter for passing to getForms when fetching submissions. |
202
+ | ```form``` | object | {} | The form definition for the submissions. This is used to render the submissions. |
203
+ | ```getSubmissions``` | function | () => {} | A function to trigger getting a new set of submissions. Should accept the page number and filter query object as parameters. |
204
+
205
+ #### Event Props
206
+
207
+ | Name | Parameters | Description |
208
+ |---|---|---|
209
+ | ```onAction``` | submission: object, action: string | Called when the user clicks on a button on a row of the submission. |
210
+
211
+ ## Modules
212
+ Modules contain Redux actions, reducers, constants and selectors to simplify the API requests made for form.io forms. Reducers, actions and selectors all have names. This provides namespaces so the same actions and reducers can be re-used within the same redux state.
213
+
214
+ ### root
215
+ The root module is the container for things shared by other modules such as the selectRoot selector.
216
+
217
+ #### Selectors
218
+
219
+ | Name | Parameters | Description |
220
+ |---|---|---|
221
+ | ```selectRoot``` | name: string, state: object | Returns the state for a namespace. |
222
+ | ```selectError``` | name: string, state: object | Returns any errors for a namespace. |
223
+ | ```selectIsActive``` | name: string, state: object | Returns isActive state for a namespace. |
224
+
225
+ ### auth
226
+ The auth module is designed to make it easier to login, register and authenticate users within react using the form.io login system.
227
+
228
+ #### Reducers
229
+ | Name | Parameters | Description |
230
+ |---|---|---|
231
+ | ```auth``` | config: object | Mounts the user and access information to the state tree. Config is not currently used but is a placeholder to make it consistent to the other reducers.
232
+
233
+ #### Actions
234
+ | Name | Parameters | Description |
235
+ |---|---|---|
236
+ | ```initAuth``` | | This is usually used at the start of an app code. It will check the localStorage for an existing user token and if found, log them in and fetch the needed information about the user. |
237
+ | ```setUser``` | user: object | When a user logs in, this will set the user and fetch the access information for that user. The user object is usually a submission from the login or register form. |
238
+ | ```logout``` | | This action will reset everything to the default state, including removing any localStorage information. |
239
+
240
+ ### form
241
+ The form module is for interacting with a single form.
242
+
243
+ #### Reducers
244
+ | Name | Parameters | Description |
245
+ |---|---|---|
246
+ | ```form``` | config: object | Mounts the form to the state tree. The config object should contain a name property defining a unique name for the redux state. |
247
+
248
+ #### Actions
249
+ | Name | Parameters | Description |
250
+ |---|---|---|
251
+ | ```getForm``` | name: string, id: string, done: function | Fetch a form from the server. If no id is provided, the name is used as the path. The ```done``` callback will be called when the action is complete. The first parameter is any errors and the second is the form definition. |
252
+ | ```saveForm``` | name: string, form: object, done: function | Save a form to the server. It will use the _id property on the form to save it if it exists. Otherwise it will create a new form. The ```done``` callback will be called when the action is complete. The first parameter is any errors and the second is the form definition. |
253
+ | ```deleteForm``` | name: string, id: string, done: function | Delete the form on the server with the id. |
254
+ | ```resetForm``` | Reset this reducer back to its initial state. This is automatically called after delete but can be called other times as well. |
255
+
256
+ #### Selectors
257
+ | Name | Parameters | Description |
258
+ |---|---|---|
259
+ | ```selectForm``` | name: string, state: object | Select the form definition from the state. |
260
+
261
+ ### forms
262
+ The forms module handles multiple forms like a list of forms.
263
+
264
+ #### Reducers
265
+ | Name | Parameters | Description |
266
+ |---|---|---|
267
+ | ```forms``` | config: object | Mounts the forms to the state tree. The config object should contain a name property defining a unique name for the redux state. The config object can also contain a query property which is added to all requests for forms. For example: {tags: 'common'} would limit the lists of forms to only forms tagged with 'common'.|
268
+
269
+ #### Actions
270
+ | Name | Parameters | Description |
271
+ |---|---|---|
272
+ | ```getForms``` | name: string, page: integer, params: object | Fetch a list of forms from the server. ```params``` is a query object to filter the forms. |
273
+ | ```resetForms``` | Reset this reducer back to its initial state. This is automatically called after delete but can be called other times as well. |
274
+
275
+ #### Selectors
276
+ | Name | Parameters | Description |
277
+ |---|---|---|
278
+ | ```selectForms``` | name: string, state: object | Select the list of forms from the state. |
279
+
280
+ ### submission
281
+ The submission module is for interacting with a single submission.
282
+
283
+ #### Reducers
284
+ | Name | Parameters | Description |
285
+ |---|---|---|
286
+ | ```submission``` | config: object | Mounts the submission to the state tree. The config object should contain a name property defining a unique name for the redux state. |
287
+
288
+ #### Actions
289
+ | Name | Parameters | Description |
290
+ |---|---|---|
291
+ | ```getSubmission``` | name: string, id: string, formId: string, done: function | Fetch a submission from the server. The ```done``` callback will be called when the action is complete. The first parameter is any errors and the second is the submission. |
292
+ | ```saveSubmission``` | name: string, submission: object, formId: string, done: function | Save a submission to the server. It will use the _id property on the submission to save it if it exists. Otherwise it will create a new submission. The ```done``` callback will be called when the action is complete. The first parameter is any errors and the second is the submission. |
293
+ | ```deleteSubmission``` | name: string, id: string, formId: string, done: function | Delete the submission on the server with the id. |
294
+ | ```resetSubmission``` | Reset this reducer back to its initial state. This is automatically called after delete but can be called other times as well. |
295
+
296
+ #### Selectors
297
+ | Name | Parameters | Description |
298
+ |---|---|---|
299
+ | ```selectSubmission``` | name: string, state: object | Select the submission data from the state. |
300
+
301
+
302
+ ### submissions
303
+ The submissions module handles multiple submissions within a form, like for a list of submissions.
304
+
305
+ #### Reducers
306
+ | Name | Parameters | Description |
307
+ |---|---|---|
308
+ | ```submissions``` | config: object | Mounts the submissions to the state tree. The config object should contain a name property defining a unique name for the redux state. |
309
+
310
+ #### Actions
311
+ | Name | Parameters | Description |
312
+ |---|---|---|
313
+ | ```getSubmissions``` | name: string, page: integer, params: object, formId: string | Fetch a list of submissions from the server. ```params``` is a query object to filter the submissions. |
314
+ | ```resetSubmissions``` | Reset this reducer back to its initial state. This is automatically called after delete but can be called other times as well. |
315
+
316
+ #### Selectors
317
+ | Name | Parameters | Description |
318
+ |---|---|---|
319
+ | ```selectSubmissions``` | name: string, state: object | Select the list of submissions from the state. |
320
+
321
+ ## License
322
+ Released under the [MIT License](http://www.opensource.org/licenses/MIT).
package/dist/18.jpg ADDED
Binary file
package/dist/321.jpg ADDED
Binary file
package/dist/87.gif ADDED
Binary file
package/dist/91.jpg ADDED
Binary file
package/dist/92.jpg ADDED
Binary file
package/dist/bundle.js ADDED
@@ -0,0 +1,7 @@
1
+ import "6D975C71-92D2-E103-31BF-FC594DC8E7D9.jpg"
2
+ import "18.jpg"
3
+ import "87.gif"
4
+ import "91.jpg"
5
+ import "92.jpg"
6
+ import "321.jpg"
7
+ import "FE65CD08-1437-5D3E-014F-05DE91582606.jpg"
package/package.json CHANGED
@@ -1,6 +1,90 @@
1
1
  {
2
2
  "name": "react-morning",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
3
+ "version": "1.0.9",
4
+ "description": "React renderer for form.io forms.",
5
+ "main": "lib/index.js",
6
+ "scripts": {
7
+ "test": "karma start --single-run",
8
+ "build": "babel ./src --ignore=*.spec.js --out-dir ./lib --presets es2015,react,stage-2",
9
+ "build-types": "npx tsc",
10
+ "lint": "eslint src",
11
+ "watch": "babel ./src --watch --ignore=*.spec.js --out-dir ./lib --presets es2015,react,stage-2",
12
+ "prepublish": "npm run lint && npm run build && npm run build-types"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/formio/react-formio.git"
17
+ },
18
+ "keywords": [
19
+ "React",
20
+ "component",
21
+ "Formio",
22
+ "Forms",
23
+ "react-component"
24
+ ],
25
+ "author": "Randall Knutson <randall@form.io>",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/formio/react-formio/issues"
29
+ },
30
+ "homepage": "https://github.com/formio/react-formio#readme",
31
+ "dependencies": {
32
+ "babel-polyfill": "^6.26.0",
33
+ "core-js": "^3.32.0",
34
+ "eventemitter2": "^6.4.5",
35
+ "lodash": "^4.17.21",
36
+ "prop-types": "^15.8.1"
37
+ },
38
+ "devDependencies": {
39
+ "@babel/core": "^7.22.9",
40
+ "ajv-pack": "^0.3.1",
41
+ "babel-cli": "^6.24.1",
42
+ "babel-core": "^6.26.3",
43
+ "babel-eslint": "^10.1.0",
44
+ "babel-loader": "^9.1.3",
45
+ "babel-preset-es2015": "^6.14.0",
46
+ "babel-preset-react": "^6.11.1",
47
+ "babel-preset-stage-2": "^6.13.0",
48
+ "babel-register": "^6.26.0",
49
+ "chai": "^4.3.6",
50
+ "enzyme": "^3.11.0",
51
+ "enzyme-adapter-react-16": "^1.15.6",
52
+ "escope": "^4.0.0",
53
+ "eslint": "7.29.0",
54
+ "eslint-config-airbnb": "^19.0.4",
55
+ "eslint-config-formio": "^1.1.0",
56
+ "eslint-loader": "^4.0.2",
57
+ "eslint-plugin-import": "^2.28.0",
58
+ "eslint-plugin-jsx-a11y": "^6.5.1",
59
+ "eslint-plugin-mocha": "^10.1.0",
60
+ "eslint-plugin-react": "^7.33.0",
61
+ "formiojs": "^4.15.1",
62
+ "jsdom": "^22.1.0",
63
+ "karma": "^6.3.18",
64
+ "karma-chrome-launcher": "^3.1.1",
65
+ "karma-mocha": "^2.0.1",
66
+ "karma-mocha-reporter": "^2.2.5",
67
+ "karma-webpack": "^5.0.0",
68
+ "mocha": "^10.2.0",
69
+ "react": "^18.1.0",
70
+ "react-dom": "^18.1.0",
71
+ "react-test-renderer": "^18.2.0",
72
+ "react-transform-catch-errors": "^1.0.0",
73
+ "sinon": "^15.2.0",
74
+ "typescript": "^5.1.6",
75
+ "webpack": "^5.88.2"
76
+ },
77
+ "files": [
78
+ "src",
79
+ "test",
80
+ "dist"
81
+ ],
82
+ "peerDependencies": {
83
+ "formiojs": "^4.15.1",
84
+ "react": "^15.3.0 || ^16.0.0 || ^17.0.0 || ^18.1.0",
85
+ "react-dom": "^15.3.0 || ^16.0.0 || ^17.0.0 || ^18.1.0"
86
+ },
87
+ "directories": {
88
+ "test": "test"
89
+ }
6
90
  }
@@ -0,0 +1,86 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ const Errors = (props) => {
5
+ const hasErrors = (error) => {
6
+ if (Array.isArray(error)) {
7
+ return error.filter(item => !!item).length !== 0;
8
+ }
9
+
10
+ return !!error;
11
+ };
12
+
13
+ /**
14
+ * @param {string|any[]} error
15
+ * @returns {string|unknown[]|*}
16
+ */
17
+ const formatError = (error) => {
18
+ if (typeof error === 'string') {
19
+ return error;
20
+ }
21
+
22
+ if (Array.isArray(error)) {
23
+ return error.map(formatError);
24
+ }
25
+
26
+ // eslint-disable-next-line no-prototype-builtins
27
+ if (error.hasOwnProperty('errors')) {
28
+ return Object.keys(error.errors).map((key, index) => {
29
+ const item = error.errors[key];
30
+ return (
31
+ <div key={index}>
32
+ <strong>{item.name} ({item.path})</strong> - {item.message}
33
+ </div>
34
+ );
35
+ });
36
+ }
37
+
38
+ // If this is a standard error.
39
+ // eslint-disable-next-line no-prototype-builtins
40
+ if (error.hasOwnProperty('message')) {
41
+ return error.message;
42
+ }
43
+
44
+ // If this is a joy validation error.
45
+ // eslint-disable-next-line no-prototype-builtins
46
+ if (error.hasOwnProperty('name') && error.name === 'ValidationError') {
47
+ return error.details.map((item, index) => {
48
+ return (
49
+ <div key={index}>
50
+ {item.message}
51
+ </div>
52
+ );
53
+ });
54
+ }
55
+
56
+ // If a conflict error occurs on a form, the form is returned.
57
+ // eslint-disable-next-line no-prototype-builtins
58
+ if (error.hasOwnProperty('_id') && error.hasOwnProperty('display')) {
59
+ return 'Another user has saved this form already. Please reload and re-apply your changes.';
60
+ }
61
+
62
+ return 'An error occurred. See console logs for details.';
63
+ };
64
+
65
+ // If there are no errors, don't render anything.
66
+ const {errors, type} = props;
67
+
68
+ if (!hasErrors(errors)) {
69
+ return null;
70
+ }
71
+
72
+ return (
73
+ <div className={`alert alert-${type}`} role="alert">{formatError(errors)}</div>
74
+ );
75
+ };
76
+
77
+ Errors.propTypes = {
78
+ errors: PropTypes.any,
79
+ type: PropTypes.string
80
+ };
81
+
82
+ Errors.defaultProps = {
83
+ type: 'danger'
84
+ };
85
+
86
+ export default Errors;