react-form-builder-more-flexibility 1.0.55 → 1.0.58

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.
package/README.md CHANGED
@@ -1,68 +1,64 @@
1
1
  [![npm version](https://badge.fury.io/js/react-form-builder2.svg)](//npmjs.com/package/react-form-builder2)
2
2
  [![downloads](https://img.shields.io/npm/dm/react-form-builder2.svg)](https://img.shields.io/npm/dm/react-form-builder2.svg)
3
+
3
4
  # React Form Builder 2
4
- A complete react form builder that interfaces with a json endpoint to load and save generated forms.
5
- - Upgraded to React 16.8.6
6
- - Bootstrap 4.x, Font-Awesome 5.x
7
- - Use react-dnd for Drag & Drop
8
- - Save form data with dummy api server
9
- - Show posted data on readonly form
10
- - Multi column row
11
- - Custom Components
12
5
 
13
- [DEMO](https://kiho.github.io/react-form-builder/) Slow Loading.... back-end is running at FREE Heroku, hence it may not work if free time runs out for month.
6
+ A complete react form builder that interfaces with a json endpoint to load and save generated forms.
14
7
 
15
- ![](screenshot.png)
8
+ - Upgraded to React 18.3.1
9
+ - Upgraded related packages
16
10
 
17
11
  ### Editing Items
12
+
18
13
  ![](screenshot2.png)
19
14
 
20
15
  # Basic Usage
21
16
 
22
17
  ```javascript
23
- import React from 'react';
24
- import ReactDOM from 'react-dom';
25
- import { ReactFormBuilder } from 'react-form-builder2';
26
- import 'react-form-builder2/dist/app.css';
18
+ import React from "react";
19
+ import ReactDOM from "react-dom";
20
+ import { ReactFormBuilder } from "react-form-builder2";
21
+ import "react-form-builder2/dist/app.css";
27
22
 
28
- ReactDOM.render(
29
- <ReactFormBuilder />,
30
- document.body
31
- )
23
+ ReactDOM.render(<ReactFormBuilder />, document.body);
32
24
  ```
33
25
 
34
26
  # Props
35
27
 
36
28
  ```javascript
37
- var items = [{
38
- key: 'Header',
39
- name: 'Header Text',
40
- icon: 'fa fa-header',
41
- static: true,
42
- content: 'Placeholder Text...'
43
- },
44
- {
45
- key: 'Paragraph',
46
- name: 'Paragraph',
47
- static: true,
48
- icon: 'fa fa-paragraph',
49
- content: 'Placeholder Text...'
50
- }];
29
+ var items = [
30
+ {
31
+ key: "Header",
32
+ name: "Header Text",
33
+ icon: "fa fa-header",
34
+ static: true,
35
+ content: "Placeholder Text...",
36
+ },
37
+ {
38
+ key: "Paragraph",
39
+ name: "Paragraph",
40
+ static: true,
41
+ icon: "fa fa-paragraph",
42
+ content: "Placeholder Text...",
43
+ },
44
+ ];
51
45
 
52
46
  <ReactFormBuilder
53
- url='path/to/GET/initial.json'
47
+ url="path/to/GET/initial.json"
54
48
  toolbarItems={items}
55
- saveUrl='path/to/POST/built/form.json' />
49
+ saveUrl="path/to/POST/built/form.json"
50
+ />;
56
51
  ```
57
52
 
58
53
  # React Form Generator
54
+
59
55
  Now that a form is built and saved, let's generate it from the saved json.
60
56
 
61
57
  ```javascript
62
- import React from 'react';
63
- import ReactDOM from 'react-dom';
64
- import { ReactFormGenerator } from 'react-form-builder2';
65
- import 'react-form-builder2/dist/app.css';
58
+ import React from "react";
59
+ import ReactDOM from "react-dom";
60
+ import { ReactFormGenerator } from "react-form-builder2";
61
+ import "react-form-builder2/dist/app.css";
66
62
 
67
63
  ReactDOM.render(
68
64
  <ReactFormGenerator
@@ -74,30 +70,31 @@ ReactDOM.render(
74
70
  data={JSON_QUESTION_DATA} // Question data
75
71
  />,
76
72
  document.body
77
- )
73
+ );
78
74
  ```
79
75
 
80
76
  ### Form Params
81
77
 
82
- Name | Type | Required? | Description
83
- --- | --- | --- | ---
84
- form_action | string | Required | URL path to submit the form
85
- form_method | string | Required | Verb used in the form submission.
86
- action_name | string | Optional | Defines form submit button text. Defaults to "Submit"
87
- onSubmit | function | optional | Invoke when submit data, if exists will override form post.
88
- onChange | function | optional | Invoke when Change data. only on generator
89
- onBlur | function | optional | Invoke when Blur data. only on generator
90
- data | array | Required | Question data retrieved from the database
91
- back_action | string | Optional | URL path to go back if needed.
92
- back_name | string | Optional | Button text for back action. Defaults to "Cancel".
93
- task_id | integer | Optional | User to submit a hidden variable with id to the form on the backend database.
94
- answer_data | array | Optional | Answer data, only used if loading a pre-existing form with values.
95
- authenticity_token | string | Optional | If using Rails and need an auth token to submit form.
96
- hide_actions | boolean | Optional | If you would like to hide the submit / cancel buttons set to true.
97
- skip_validations | boolean | Optional | Suppress form validations on submit, if set to true.
98
- display_short | boolean | Optional | Display an optional "shorter page/form" which is common for legal documents or situations where the user will just have to sign or fill out a shorter form with only the critical elements.
99
- read_only | boolean | Optional | Shows a read only version which has fields disabled and removes "required" labels.
100
- variables | object | Optional | Key/value object that can be used for Signature variable replacement.
78
+ | Name | Type | Required? | Description |
79
+ | ------------------ | -------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
80
+ | form_action | string | Required | URL path to submit the form |
81
+ | form_method | string | Required | Verb used in the form submission. |
82
+ | action_name | string | Optional | Defines form submit button text. Defaults to "Submit" |
83
+ | onSubmit | function | optional | Invoke when submit data, if exists will override form post. |
84
+ | onChange | function | optional | Invoke when Change data. only on generator |
85
+ | onBlur | function | optional | Invoke when Blur data. only on generator |
86
+ | data | array | Required | Question data retrieved from the database |
87
+ | back_action | string | Optional | URL path to go back if needed. |
88
+ | back_name | string | Optional | Button text for back action. Defaults to "Cancel". |
89
+ | task_id | integer | Optional | User to submit a hidden variable with id to the form on the backend database. |
90
+ | answer_data | array | Optional | Answer data, only used if loading a pre-existing form with values. |
91
+ | authenticity_token | string | Optional | If using Rails and need an auth token to submit form. |
92
+ | hide_actions | boolean | Optional | If you would like to hide the submit / cancel buttons set to true. |
93
+ | skip_validations | boolean | Optional | Suppress form validations on submit, if set to true. |
94
+ | display_short | boolean | Optional | Display an optional "shorter page/form" which is common for legal documents or situations where the user will just have to sign or fill out a shorter form with only the critical elements. |
95
+ | read_only | boolean | Optional | Shows a read only version which has fields disabled and removes "required" labels. |
96
+ | variables | object | Optional | Key/value object that can be used for Signature variable replacement. |
97
+ | option_key_value | string | Optional | Use "key" or "value" of checked option item in json data, default is "key". |
101
98
 
102
99
  ### Read only Signatures
103
100
 
@@ -112,35 +109,40 @@ The signature data should be in base 64 format.
112
109
  There is a `variables.js` file that contains a sample base 64 signature. This variable is passed into the demo builder and generator for testing. Use the variable key "JOHN" to test the variable replacement.
113
110
 
114
111
  # Vendor Dependencies
112
+
115
113
  In order to make the form builder look pretty, there are a few dependencies other than React. Style sheets from `Bootstrap` and `FontAwesome` must be added to index.html. See the example code in [index.html](https://github.com/Kiho/react-form-builder/blob/master/public/index.html#L5) for more details.
116
114
 
117
115
  - Bootstrap
118
116
  - FontAwesome
119
117
 
120
118
  # SASS
119
+
121
120
  All relevant styles located in css/application.css.scss.
122
121
 
123
122
  # Develop
123
+
124
124
  ```bash
125
- $ yarn install
126
- $ yarn run build:dist
127
- $ yarn run serve:api
128
- $ yarn start
125
+ $ npm install
126
+ $ NODE_OPTIONS=--openssl-legacy-provider npm run build:dist
127
+ $ npm run serve:api
128
+ $ NODE_OPTIONS=--openssl-legacy-provider npm run start
129
129
  ```
130
+
130
131
  Then navigate to http://localhost:8080/ in your browser and you should be able to see the form builder in action.
131
132
 
132
133
  # Customizations
134
+
133
135
  - to customize the field edit form copy "src/form-elements-edit.jsx" to your project and pass it to the ReactFormBuilder as a prop. Here is an example
136
+
134
137
  ```jsx
135
138
  <ReactFormBuilder
136
- edit
137
- data={form}
138
- //toolbarItems={items}
139
- customToolbarItems={items}
140
- onChange={handleUpdate}
141
- onSubmit={handleSubmit}
142
-
143
- renderEditForm={props => <FormElementsEdit {...props}/>}
139
+ edit
140
+ data={form}
141
+ //toolbarItems={items}
142
+ customToolbarItems={items}
143
+ onChange={handleUpdate}
144
+ onSubmit={handleSubmit}
145
+ renderEditForm={(props) => <FormElementsEdit {...props} />}
144
146
  />
145
147
  ```
146
148
 
@@ -148,93 +150,123 @@ Then navigate to http://localhost:8080/ in your browser and you should be able t
148
150
 
149
151
  ```jsx
150
152
  <ReactFormGenerator
151
- data={form}
152
- toolbarItems={items}
153
- onSubmit={handleSubmit}
154
- actionName="Set this to change the default submit button text"
155
- submitButton={<button type="submit" className="btn btn-primary">Submit</button>}
156
- backButton={<a href="/" className="btn btn-default btn-cancel btn-big">Back</a>}
153
+ data={form}
154
+ toolbarItems={items}
155
+ onSubmit={handleSubmit}
156
+ actionName="Set this to change the default submit button text"
157
+ submitButton={
158
+ <button type="submit" className="btn btn-primary">
159
+ Submit
160
+ </button>
161
+ }
162
+ backButton={
163
+ <a href="/" className="btn btn-default btn-cancel btn-big">
164
+ Back
165
+ </a>
166
+ }
157
167
  />
158
168
  ```
159
169
 
160
170
  # Custom Components
171
+
161
172
  - Import component registry from react-form-builder2
173
+
162
174
  ```jsx
163
- import { ReactFormBuilder, ElementStore, Registry } from 'react-form-builder2';
175
+ import { ReactFormBuilder, ElementStore, Registry } from "react-form-builder2";
164
176
  ```
165
177
 
166
- - Simple Custom Component
178
+ - Simple Custom Component
179
+
167
180
  ```jsx
168
181
  const TestComponent = () => <h2>Hello</h2>;
169
182
  ```
170
183
 
171
184
  - Custom Component with input element
185
+
172
186
  ```jsx
173
187
  const MyInput = React.forwardRef((props, ref) => {
174
188
  const { name, defaultValue, disabled } = props;
175
- return <input ref={ref} name={name} defaultValue={defaultValue} disabled={disabled} />;
189
+ return (
190
+ <input
191
+ ref={ref}
192
+ name={name}
193
+ defaultValue={defaultValue}
194
+ disabled={disabled}
195
+ />
196
+ );
176
197
  });
177
198
  ```
178
199
 
179
200
  - Register custom components to be used in form builder
201
+
180
202
  ```jsx
181
- Registry.register('MyInput', MyInput);
182
- Registry.register('TestComponent', TestComponent);
203
+ Registry.register("MyInput", MyInput);
204
+ Registry.register("TestComponent", TestComponent);
183
205
  ```
184
206
 
185
207
  - Define Custom Components in Toolbar
208
+
186
209
  ```jsx
187
- const items = [{
188
- key: 'TestComponent',
189
- element: 'CustomElement',
190
- component: TestComponent,
191
- type: 'custom',
192
- field_name: 'test_component',
193
- name: 'Something You Want',
194
- icon: 'fa fa-cog',
195
- static: true,
196
- props: { test: 'test_comp' },
197
- label: 'Label Test',
198
- }, {
199
- key: 'MyInput',
200
- element: 'CustomElement',
201
- component: MyInput,
202
- type: 'custom',
203
- forwardRef: true,
204
- field_name: 'my_input_',
205
- name: 'My Input',
206
- icon: 'fa fa-cog',
207
- props: { test: 'test_input' },
208
- label: 'Label Input',
209
- },
210
- // Additional standard components, you don't need full definition if no modification is required.
211
- {
212
- key: 'Header',
213
- }, {
214
- key: 'TextInput',
215
- }, {
216
- key: 'TextArea',
217
- }, {
218
- key: 'RadioButtons',
219
- }, {
220
- key: 'Checkboxes',
221
- }, {
222
- key: 'Image',
223
- }];
210
+ const items = [
211
+ {
212
+ key: "TestComponent",
213
+ element: "CustomElement",
214
+ component: TestComponent,
215
+ type: "custom",
216
+ field_name: "test_component",
217
+ name: "Something You Want",
218
+ icon: "fa fa-cog",
219
+ static: true,
220
+ props: { test: "test_comp" },
221
+ label: "Label Test",
222
+ },
223
+ {
224
+ key: "MyInput",
225
+ element: "CustomElement",
226
+ component: MyInput,
227
+ type: "custom",
228
+ forwardRef: true,
229
+ field_name: "my_input_",
230
+ name: "My Input",
231
+ icon: "fa fa-cog",
232
+ props: { test: "test_input" },
233
+ label: "Label Input",
234
+ },
235
+ // Additional standard components, you don't need full definition if no modification is required.
236
+ {
237
+ key: "Header",
238
+ },
239
+ {
240
+ key: "TextInput",
241
+ },
242
+ {
243
+ key: "TextArea",
244
+ },
245
+ {
246
+ key: "RadioButtons",
247
+ },
248
+ {
249
+ key: "Checkboxes",
250
+ },
251
+ {
252
+ key: "Image",
253
+ },
254
+ ];
224
255
  ```
225
256
 
226
257
  - Use defined Toolbar in ReactFormBuilder
258
+
227
259
  ```jsx
228
260
  <ReactFormBuilder
229
261
  ...
230
262
  toolbarItems={items}
231
263
  />
232
264
  ```
233
-
234
- - Find working example [here](https://github.com/Kiho/react-form-builder/blob/master/examples/custom/app.js)
235
265
 
266
+ - Find working example [here](https://github.com/Kiho/react-form-builder/blob/master/examples/custom/app.js)
236
267
 
237
268
  # Examples
269
+
238
270
  - [Basic](https://github.com/Kiho/react-form-builder/tree/master/examples/demo)
239
271
  - [JSON Post](https://github.com/Kiho/react-form-builder/tree/master/examples/custom)
240
272
  - [UMD](https://github.com/Kiho/react-form-builder/tree/master/examples/umd)
@@ -243,7 +275,9 @@ const items = [{
243
275
  - [create-react-app](https://github.com/Kiho/react-form-builder/tree/master/examples/cra)
244
276
 
245
277
  # Tests
278
+
246
279
  ```bash
247
280
  $ npm test
248
281
  ```
282
+
249
283
  Test is not working at this moment.
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunkReactFormBuilder=self.webpackChunkReactFormBuilder||[]).push([[845],{845:(e,t,n)=>{n.r(t),n.d(t,{default:()=>z});var a=n(3029),l=n(2901),o=n(6822),r=n(3954),i=n(5361),s=n(4012),c=n.n(s),m=n(8168),p=n(8587),d=n(7003),h=function(e,t){"function"!=typeof e?e.current=t:e(t)},u={"min-height":"0","max-height":"none",height:"0",visibility:"hidden",overflow:"hidden",position:"absolute","z-index":"-1000",top:"0",right:"0",display:"block"},E=function(e){Object.keys(u).forEach(function(t){e.style.setProperty(t,u[t],"important")})},f=null,v=function(e,t){var n=e.scrollHeight;return"border-box"===t.sizingStyle.boxSizing?n+t.borderSize:n-t.paddingSize},b=function(){},y=["borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","boxSizing","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textRendering","textTransform","width","wordBreak","wordSpacing","scrollbarGutter"],g=!!document.documentElement.currentStyle;function N(e,t,n){var a,l,o=(a=n,l=c().useRef(a),(0,d.A)(function(){l.current=a}),l);s.useLayoutEffect(function(){var n=function(e){return o.current(e)};if(e)return e.addEventListener(t,n),function(){return e.removeEventListener(t,n)}},[])}var x=["cacheMeasurements","maxRows","minRows","onChange","onHeightChange"],w=function(e,t){var n,a=e.cacheMeasurements,l=e.maxRows,o=e.minRows,r=e.onChange,i=void 0===r?b:r,d=e.onHeightChange,u=void 0===d?b:d,w=(0,p.A)(e,x),k=void 0!==w.value,C=s.useRef(null),P=function(e,t){var n=c().useRef();return c().useCallback(function(a){e.current=a,n.current&&h(n.current,null),n.current=t,t&&h(t,a)},[t])}(C,t),O=s.useRef(0),A=s.useRef(),S=function(){var e=C.current,t=a&&A.current?A.current:function(e){var t=window.getComputedStyle(e);if(null===t)return null;var n,a=(n=t,y.reduce(function(e,t){return e[t]=n[t],e},{})),l=a.boxSizing;return""===l?null:(g&&"border-box"===l&&(a.width=parseFloat(a.width)+parseFloat(a.borderRightWidth)+parseFloat(a.borderLeftWidth)+parseFloat(a.paddingRight)+parseFloat(a.paddingLeft)+"px"),{sizingStyle:a,paddingSize:parseFloat(a.paddingBottom)+parseFloat(a.paddingTop),borderSize:parseFloat(a.borderBottomWidth)+parseFloat(a.borderTopWidth)})}(e);if(t){A.current=t;var n=function(e,t,n,a){void 0===n&&(n=1),void 0===a&&(a=1/0),f||((f=document.createElement("textarea")).setAttribute("tabindex","-1"),f.setAttribute("aria-hidden","true"),E(f)),null===f.parentNode&&document.body.appendChild(f);var l=e.paddingSize,o=e.borderSize,r=e.sizingStyle,i=r.boxSizing;Object.keys(r).forEach(function(e){var t=e;f.style[t]=r[t]}),E(f),f.value=t;var s=v(f,e);f.value=t,s=v(f,e),f.value="x";var c=f.scrollHeight-l,m=c*n;"border-box"===i&&(m=m+l+o),s=Math.max(m,s);var p=c*a;return"border-box"===i&&(p=p+l+o),[s=Math.min(p,s),c]}(t,e.value||e.placeholder||"x",o,l),r=n[0],i=n[1];O.current!==r&&(O.current=r,e.style.setProperty("height",r+"px","important"),u(r,{rowHeight:i}))}};return s.useLayoutEffect(S),function(e,t){N(document.body,"reset",function(n){e.current.form===n.target&&t()})}(C,function(){if(!k){var e=C.current.value;requestAnimationFrame(function(){var t=C.current;t&&e!==t.value&&S()})}}),N(window,"resize",S),n=S,N(document.fonts,"loadingdone",n),s.createElement("textarea",(0,m.A)({},w,{onChange:function(e){k||S(),i(e)},ref:P}))},k=s.forwardRef(w),C=n(5143),P=n(9987),O=n.n(P),A=n(3754),S=n(7654),F=n.n(S),B=n(8886);function _(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(_=function(){return!!e})()}var V=function(e){function t(e){var n,l,i,s;return(0,a.A)(this,t),l=this,i=t,s=[e],i=(0,r.A)(i),(n=(0,o.A)(l,_()?Reflect.construct(i,s||[],(0,r.A)(l).constructor):i.apply(l,s))).state={element:n.props.element,data:n.props.data,dirty:!1},n}return(0,i.A)(t,e),(0,l.A)(t,[{key:"_setValue",value:function(e){return e.replace(/[^A-Z0-9]+/gi,"_").toLowerCase()}},{key:"editOption",value:function(e,t){var n=this.state.element,a=n.options[e].value!==this._setValue(n.options[e].text)?n.options[e].value:this._setValue(t.target.value);n.options[e].text=t.target.value,n.options[e].value=a,this.setState({element:n,dirty:!0})}},{key:"editValue",value:function(e,t){var n=this.state.element,a=""===t.target.value?this._setValue(n.options[e].text):t.target.value;n.options[e].value=a,this.setState({element:n,dirty:!0})}},{key:"editOptionCorrect",value:function(e,t){var n=this.state.element;n.options[e].hasOwnProperty("correct")?delete n.options[e].correct:n.options[e].correct=!0,this.setState({element:n}),this.props.updateElement.call(this.props.preview,n)}},{key:"updateOption",value:function(){var e=this.state.element;this.state.dirty&&(this.props.updateElement.call(this.props.preview,e),this.setState({dirty:!1}))}},{key:"addOption",value:function(e){var t=this.state.element,n=t.element.toLowerCase();t.options.splice(e+1,0,{value:"",text:"",key:"".concat(n,"_option_").concat(F().uuid())}),this.props.updateElement.call(this.props.preview,t)}},{key:"removeOption",value:function(e){var t=this.state.element;t.options.splice(e,1),this.props.updateElement.call(this.props.preview,t)}},{key:"render",value:function(){var e=this;return this.state.dirty&&(this.state.element.dirty=!0),c().createElement("div",{className:"dynamic-option-list"},c().createElement("ul",null,c().createElement("li",null,c().createElement("div",{className:"row"},c().createElement("div",{className:"col-sm-6"},c().createElement("b",null,c().createElement(B.A,{id:"options"}))),this.props.canHaveOptionValue&&c().createElement("div",{className:"col-sm-2"},c().createElement("b",null,c().createElement(B.A,{id:"value"}))),this.props.canHaveOptionValue&&this.props.canHaveOptionCorrect&&c().createElement("div",{className:"col-sm-4"},c().createElement("b",null,c().createElement(B.A,{id:"correct"}))))),this.props.element.options.map(function(t,n){var a="edit_".concat(t.key),l=t.value!==e._setValue(t.text)?t.value:"";return c().createElement("li",{className:"clearfix",key:a},c().createElement("div",{className:"row"},c().createElement("div",{className:"col-sm-6"},c().createElement("input",{tabIndex:n+1,className:"form-control",style:{width:"100%"},type:"text",name:"text_".concat(n),placeholder:"Option text",value:t.text,onBlur:e.updateOption.bind(e),onChange:e.editOption.bind(e,n)})),e.props.canHaveOptionValue&&c().createElement("div",{className:"col-sm-2"},c().createElement("input",{className:"form-control",type:"text",name:"value_".concat(n),value:l,onChange:e.editValue.bind(e,n)})),e.props.canHaveOptionValue&&e.props.canHaveOptionCorrect&&c().createElement("div",{className:"col-sm-1"},c().createElement("input",{className:"form-control",type:"checkbox",value:"1",onChange:e.editOptionCorrect.bind(e,n),checked:t.hasOwnProperty("correct")})),c().createElement("div",{className:"col-sm-3"},c().createElement("div",{className:"dynamic-options-actions-buttons"},c().createElement("button",{onClick:e.addOption.bind(e,n),className:"btn btn-success"},c().createElement("i",{className:"fas fa-plus-circle"})),n>0&&c().createElement("button",{onClick:e.removeOption.bind(e,n),className:"btn btn-danger"},c().createElement("i",{className:"fas fa-minus-circle"}))))))})))}}])}(c().Component),H=n(968);function T(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(T=function(){return!!e})()}var R={options:["inline","list","textAlign","fontSize","link","history"],inline:{inDropdown:!1,className:void 0,options:["bold","italic","underline","superscript","subscript"]}},z=function(e){function t(e){var n,l,i,s;return(0,a.A)(this,t),l=this,i=t,s=[e],i=(0,r.A)(i),(n=(0,o.A)(l,T()?Reflect.construct(i,s||[],(0,r.A)(l).constructor):i.apply(l,s))).state={element:n.props.element,data:n.props.data,dirty:!1},n}return(0,i.A)(t,e),(0,l.A)(t,[{key:"toggleRequired",value:function(){}},{key:"editElementProp",value:function(e,t,n){var a=this,l=this.state.element;l[e]=n.target[t],this.setState({element:l,dirty:!0},function(){"checked"===t&&a.updateElement()})}},{key:"onEditorStateChange",value:function(e,t,n){var a=O()((0,C.convertToRaw)(n.getCurrentContent())).replace(/<p>/g,"").replace(/<\/p>/g,"").replace(/&nbsp;/g," ").replace(/(?:\r\n|\r|\n)/g," "),l=this.state.element;l[t]=a,this.setState({element:l,dirty:!0})}},{key:"updateElement",value:function(){var e=this.state.element;this.state.dirty&&(this.props.updateElement.call(this.props.preview,e),this.setState({dirty:!1}))}},{key:"convertFromHTML",value:function(e){var t=(0,C.convertFromHTML)(e);if(!t.contentBlocks||!t.contentBlocks.length)return C.EditorState.createEmpty();var n=C.ContentState.createFromBlockArray(t);return C.EditorState.createWithContent(n)}},{key:"addOptions",value:function(){var e=this,t=document.getElementById("optionsApiUrl").value;t&&(0,H.J)(t).then(function(t){e.props.element.options=[];var n=e.props.element.options;t.forEach(function(e){e.key=F().uuid(),n.push(e)});var a=e.state.element;e.setState({element:a,dirty:!0})})}},{key:"render",value:function(){this.state.dirty&&(this.props.element.dirty=!0);var e,t,n,a=!!this.props.element.hasOwnProperty("required")&&this.props.element.required,l=!!this.props.element.hasOwnProperty("defaultChecked")&&this.props.element.defaultChecked,o=!!this.props.element.hasOwnProperty("hasPopUp")&&this.props.element.hasPopUp,r=!!this.props.element.hasOwnProperty("readOnly")&&this.props.element.readOnly,i=!!this.props.element.hasOwnProperty("defaultToday")&&this.props.element.defaultToday,s=(!!this.props.element.hasOwnProperty("showTimeSelect")&&this.props.element.showTimeSelect,!!this.props.element.hasOwnProperty("showTimeSelectOnly")&&this.props.element.showTimeSelectOnly,!!this.props.element.hasOwnProperty("showTimeInput")&&this.props.element.showTimeInput,!!this.props.element.hasOwnProperty("inline")&&this.props.element.inline),m=!!this.props.element.hasOwnProperty("bold")&&this.props.element.bold,p=!!this.props.element.hasOwnProperty("italic")&&this.props.element.italic,d=!!this.props.element.hasOwnProperty("center")&&this.props.element.center,h=(!!this.props.element.hasOwnProperty("pageBreakBefore")&&this.props.element.pageBreakBefore,!!this.props.element.hasOwnProperty("alternateForm")&&this.props.element.alternateForm,this.props.element),u=(h.canHavePageBreakBefore,h.canHaveAlternateForm,h.canHaveDisplayHorizontal),E=h.canHaveOptionCorrect,f=h.canHaveOptionValue,v="Image"===this.state.element.element||"Camera"===this.state.element.element,b=this.props.files.length?this.props.files:[];return(b.length<1||b.length>0&&""!==b[0].id)&&b.unshift({id:"",file_name:""}),this.props.element.hasOwnProperty("content")&&(e=this.convertFromHTML(this.props.element.content)),this.props.element.hasOwnProperty("label")&&(e=this.convertFromHTML(this.props.element.label)),this.props.element.hasOwnProperty("boxLabel")&&(t=this.convertFromHTML(this.props.element.boxLabel)),this.props.element.hasOwnProperty("popUpBody")&&(n=this.convertFromHTML(this.props.element.popUpBody)),c().createElement("div",null,c().createElement("div",{className:"clearfix"},c().createElement("h4",{className:"float-left"},this.props.element.text),c().createElement("i",{className:"float-right fas fa-times dismiss-edit",onClick:this.props.manualEditModeOff})),this.props.element.hasOwnProperty("content")&&c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label"},c().createElement(B.A,{id:"text-to-display"}),":"),c().createElement(A.Editor,{toolbar:R,defaultEditorState:e,onBlur:this.updateElement.bind(this),onEditorStateChange:this.onEditorStateChange.bind(this,0,"content"),stripPastedStyles:!0})),this.props.element.hasOwnProperty("file_path")&&c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label",htmlFor:"fileSelect"},c().createElement(B.A,{id:"choose-file"}),":"),c().createElement("select",{id:"fileSelect",className:"form-control",defaultValue:this.props.element.file_path,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"file_path","value")},b.map(function(e){var t="file_".concat(e.id);return c().createElement("option",{value:e.id,key:t},e.file_name)}))),this.props.element.hasOwnProperty("href")&&c().createElement("div",{className:"form-group"},c().createElement(k,{type:"text",className:"form-control",defaultValue:this.props.element.href,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"href","value")})),this.props.element.hasOwnProperty("label")&&c().createElement("div",{className:"form-group"},!this.props.element.hide_display_label&&c().createElement(c().Fragment,null,c().createElement("label",null,c().createElement(B.A,{id:"display-label"})),c().createElement(A.Editor,{toolbar:R,defaultEditorState:e,onBlur:this.updateElement.bind(this),onEditorStateChange:this.onEditorStateChange.bind(this,0,"label"),stripPastedStyles:!0})),c().createElement("br",null),!this.props.element.hide_required&&c().createElement("div",{className:"custom-control custom-checkbox"},c().createElement("input",{id:"is-required",className:"custom-control-input",type:"checkbox",checked:a,value:!0,onChange:this.editElementProp.bind(this,"required","checked")}),c().createElement("label",{className:"custom-control-label",htmlFor:"is-required"},c().createElement(B.A,{id:"required"}))),this.props.element.hasOwnProperty("readOnly")&&c().createElement("div",{className:"custom-control custom-checkbox"},c().createElement("input",{id:"is-read-only",className:"custom-control-input",type:"checkbox",checked:r,value:!0,onChange:this.editElementProp.bind(this,"readOnly","checked")}),c().createElement("label",{className:"custom-control-label",htmlFor:"is-read-only"},c().createElement(B.A,{id:"read-only"}))),this.props.element.hasOwnProperty("defaultToday")&&c().createElement("div",{className:"custom-control custom-checkbox"},c().createElement("input",{id:"is-default-to-today",className:"custom-control-input",type:"checkbox",checked:i,value:!0,onChange:this.editElementProp.bind(this,"defaultToday","checked")}),c().createElement("label",{className:"custom-control-label",htmlFor:"is-default-to-today"},c().createElement(B.A,{id:"default-to-today"}),"?")),-1!==["Checkboxes","Checkbox"].indexOf(this.state.element.element)&&c().createElement("div",{className:"custom-control custom-checkbox"},c().createElement("input",{id:"display-horizontal",className:"custom-control-input",type:"checkbox",checked:l,value:!0,onChange:this.editElementProp.bind(this,"defaultChecked","checked")}),c().createElement("label",{className:"custom-control-label",htmlFor:"display-horizontal"},c().createElement(B.A,{id:"default-checked"}))),-1!==["Checkbox"].indexOf(this.state.element.element)&&c().createElement("div",{className:"custom-control custom-checkbox"},c().createElement("input",{id:"input-has-popup",className:"custom-control-input",type:"checkbox",checked:o,value:!0,onChange:this.editElementProp.bind(this,"hasPopUp","checked")}),c().createElement("label",{className:"custom-control-label",htmlFor:"input-has-popup"},c().createElement(B.A,{id:"checkbox-has-popup"}))),("RadioButtons"===this.state.element.element||"Checkboxes"===this.state.element.element)&&u&&c().createElement("div",{className:"custom-control custom-checkbox"},c().createElement("input",{id:"display-horizontal",className:"custom-control-input",type:"checkbox",checked:s,value:!0,onChange:this.editElementProp.bind(this,"inline","checked")}),c().createElement("label",{className:"custom-control-label",htmlFor:"display-horizontal"},c().createElement(B.A,{id:"display-horizontal"})))),"Checkbox"===this.state.element.element&&c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label"},c().createElement(B.A,{id:"checkbox-label-text"}),":"),c().createElement(A.Editor,{toolbar:R,defaultEditorState:t,onBlur:this.updateElement.bind(this),onEditorStateChange:this.onEditorStateChange.bind(this,0,"boxLabel"),stripPastedStyles:!0})),o&&c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label"},"Pop Up:"),c().createElement(A.Editor,{toolbar:R,defaultEditorState:n,onBlur:this.updateElement.bind(this),onEditorStateChange:this.onEditorStateChange.bind(this,0,"popUpBody"),stripPastedStyles:!0})),this.props.element.hasOwnProperty("src")&&c().createElement("div",null,c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label",htmlFor:"srcInput"},c().createElement(B.A,{id:"link-to"}),":"),c().createElement("input",{id:"srcInput",type:"text",className:"form-control",defaultValue:this.props.element.src,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"src","value")}))),v&&c().createElement("div",null,c().createElement("div",{className:"form-group"},c().createElement("div",{className:"custom-control custom-checkbox"},c().createElement("input",{id:"do-center",className:"custom-control-input",type:"checkbox",checked:d,value:!0,onChange:this.editElementProp.bind(this,"center","checked")}),c().createElement("label",{className:"custom-control-label",htmlFor:"do-center"},c().createElement(B.A,{id:"center"}),"?"))),c().createElement("div",{className:"row"},c().createElement("div",{className:"col-sm-3"},c().createElement("label",{className:"control-label",htmlFor:"elementWidth"},c().createElement(B.A,{id:"width"}),":"),c().createElement("input",{id:"elementWidth",type:"text",className:"form-control",defaultValue:this.props.element.width,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"width","value")})),c().createElement("div",{className:"col-sm-3"},c().createElement("label",{className:"control-label",htmlFor:"elementHeight"},c().createElement(B.A,{id:"height"}),":"),c().createElement("input",{id:"elementHeight",type:"text",className:"form-control",defaultValue:this.props.element.height,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"height","value")})))),"FileUpload"===this.state.element.element&&c().createElement("div",null,c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label",htmlFor:"fileType"},c().createElement(B.A,{id:"choose-file-type"}),":"),c().createElement("select",{id:"fileType",className:"form-control",onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"fileType","value")},[{type:"image, application/pdf, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.presentation, video/mp4,video/x-m4v,video/*",typeName:"All File Type"},{type:"image",typeName:"Image"},{type:"application/pdf",typeName:"PDF"},{type:"application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document",typeName:"Word"},{type:"application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",typeName:"Excel"},{type:"application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.presentation",typeName:"Powerpoint"},{type:"video/mp4,video/x-m4v,video/*",typeName:"Videos"}].map(function(e,t){return c().createElement("option",{value:e.type,key:t},e.typeName)})))),this.props.element.hasOwnProperty("step")&&c().createElement("div",{className:"form-group"},c().createElement("div",{className:"form-group-range"},c().createElement("label",{className:"control-label",htmlFor:"rangeStep"},c().createElement(B.A,{id:"step"})),c().createElement("input",{id:"rangeStep",type:"number",className:"form-control",defaultValue:this.props.element.step,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"step","value")}))),this.props.element.hasOwnProperty("min_value")&&c().createElement("div",{className:"form-group"},c().createElement("div",{className:"form-group-range"},c().createElement("label",{className:"control-label",htmlFor:"rangeMin"},c().createElement(B.A,{id:"min"})),c().createElement("input",{id:"rangeMin",type:"number",className:"form-control",defaultValue:this.props.element.min_value,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"min_value","value")}),c().createElement("input",{type:"text",className:"form-control",defaultValue:this.props.element.min_label,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"min_label","value")}))),this.props.element.hasOwnProperty("max_value")&&c().createElement("div",{className:"form-group"},c().createElement("div",{className:"form-group-range"},c().createElement("label",{className:"control-label",htmlFor:"rangeMax"},c().createElement(B.A,{id:"max"})),c().createElement("input",{id:"rangeMax",type:"number",className:"form-control",defaultValue:this.props.element.max_value,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"max_value","value")}),c().createElement("input",{type:"text",className:"form-control",defaultValue:this.props.element.max_label,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"max_label","value")}))),this.props.element.hasOwnProperty("default_value")&&c().createElement("div",{className:"form-group"},c().createElement("div",{className:"form-group-range"},c().createElement("label",{className:"control-label",htmlFor:"defaultSelected"},c().createElement(B.A,{id:"default-selected"})),c().createElement("input",{id:"defaultSelected",type:"number",className:"form-control",defaultValue:this.props.element.default_value,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"default_value","value")}))),this.props.element.hasOwnProperty("static")&&this.props.element.static&&c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label"},c().createElement(B.A,{id:"text-style"})),c().createElement("div",{className:"custom-control custom-checkbox"},c().createElement("input",{id:"do-bold",className:"custom-control-input",type:"checkbox",checked:m,value:!0,onChange:this.editElementProp.bind(this,"bold","checked")}),c().createElement("label",{className:"custom-control-label",htmlFor:"do-bold"},c().createElement(B.A,{id:"bold"}))),c().createElement("div",{className:"custom-control custom-checkbox"},c().createElement("input",{id:"do-italic",className:"custom-control-input",type:"checkbox",checked:p,value:!0,onChange:this.editElementProp.bind(this,"italic","checked")}),c().createElement("label",{className:"custom-control-label",htmlFor:"do-italic"},c().createElement(B.A,{id:"italic"})))),this.props.element.showPlaceholder&&c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label",htmlFor:"placeholder"},c().createElement(B.A,{id:"place-holder-text-label"})),c().createElement("input",{type:"text",className:"form-control",id:"placeholder",defaultValue:this.props.element.placeholder,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"placeholder","value")})),this.props.element.show_custom_name&&c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label",htmlFor:"custom_name"},c().createElement(B.A,{id:"custom-name-label"})),c().createElement("input",{type:"text",className:"form-control",id:"custom_name",defaultValue:this.props.element.custom_name,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"custom_name","value")})),this.props.element.showDescription&&c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label",htmlFor:"questionDescription"},c().createElement(B.A,{id:"description"})),c().createElement(k,{type:"text",className:"form-control",id:"questionDescription",defaultValue:this.props.element.description,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"description","value")})),"TextInput"===this.state.element.element&&c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label"},"Validation Message:"),c().createElement("input",{type:"text",className:"form-control",defaultValue:this.props.element.validationMessage||"",onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"validationMessage","value")})),"TextInput"===this.state.element.element&&c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label"},"Validation Pattern (Regex):"),c().createElement("input",{type:"text",className:"form-control",defaultValue:this.props.element.validationPattern||"",onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"validationPattern","value")})),this.props.showCorrectColumn&&this.props.element.canHaveAnswer&&!this.props.element.hasOwnProperty("options")&&c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label",htmlFor:"correctAnswer"},c().createElement(B.A,{id:"correct-answer"})),c().createElement("input",{id:"correctAnswer",type:"text",className:"form-control",defaultValue:this.props.element.correct,onBlur:this.updateElement.bind(this),onChange:this.editElementProp.bind(this,"correct","value")})),this.props.element.canPopulateFromApi&&this.props.element.hasOwnProperty("options")&&c().createElement("div",{className:"form-group"},c().createElement("label",{className:"control-label",htmlFor:"optionsApiUrl"},c().createElement(B.A,{id:"populate-options-from-api"})),c().createElement("div",{className:"row"},c().createElement("div",{className:"col-sm-6"},c().createElement("input",{className:"form-control",style:{width:"100%"},type:"text",id:"optionsApiUrl",placeholder:"http://localhost:8080/api/optionsdata"})),c().createElement("div",{className:"col-sm-6"},c().createElement("button",{onClick:this.addOptions.bind(this),className:"btn btn-success"},c().createElement(B.A,{id:"populate"}))))),this.props.element.hasOwnProperty("options")&&c().createElement(V,{showCorrectColumn:this.props.showCorrectColumn,canHaveOptionCorrect:E,canHaveOptionValue:f,data:this.props.preview.state.data,updateElement:this.props.updateElement,preview:this.props.preview,element:this.props.element,key:this.props.element.options.length}))}}])}(c().Component);z.defaultProps={className:"edit-element-fields"}}}]);