react-survey-builder 1.0.72 → 1.0.74

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.
@@ -1,168 +1,153 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
8
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
9
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
10
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
12
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
13
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ 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."); }
9
+ 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); }
10
+ 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; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
13
  import React from 'react';
15
14
  import { FaMinusCircle, FaPlusCircle } from 'react-icons/fa';
16
- import { Button, Col, Form, Row } from 'react-bootstrap/esm';
15
+ import { Button, Col, Form, Row } from 'react-bootstrap';
17
16
  import ID from './UUID';
18
- var DynamicOptionList = /*#__PURE__*/function (_React$Component) {
19
- function DynamicOptionList(props) {
20
- var _this;
21
- _classCallCheck(this, DynamicOptionList);
22
- _this = _callSuper(this, DynamicOptionList, [props]);
23
- _this.state = {
24
- element: _this.props.element,
25
- item: _this.props.item,
26
- dirty: false
27
- };
28
- return _this;
29
- }
30
- _inherits(DynamicOptionList, _React$Component);
31
- return _createClass(DynamicOptionList, [{
32
- key: "_setValue",
33
- value: function _setValue(text) {
34
- return text.replace(/[^A-Z0-9]+/ig, '_').toLowerCase();
17
+ import { isObjectNotEmpty } from './utils/objectUtils';
18
+ var DynamicOptionList = function DynamicOptionList(props) {
19
+ var _props$element;
20
+ var _React$useState = React.useState((_props$element = props.element) !== null && _props$element !== void 0 ? _props$element : {}),
21
+ _React$useState2 = _slicedToArray(_React$useState, 2),
22
+ element = _React$useState2[0],
23
+ setElement = _React$useState2[1];
24
+ var _React$useState3 = React.useState(false),
25
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
26
+ dirty = _React$useState4[0],
27
+ setDirty = _React$useState4[1];
28
+ var _setValue = function _setValue(text) {
29
+ return text.replace(/[^A-Z0-9]+/ig, '_').toLowerCase();
30
+ };
31
+ var editOption = function editOption(optionIndex, e) {
32
+ var thisElement = isObjectNotEmpty(element) ? _objectSpread({}, element) : {};
33
+ var val = thisElement.options[optionIndex].value !== _setValue(thisElement.options[optionIndex].text) ? thisElement.options[optionIndex].value : _setValue(e.target.value);
34
+ thisElement.options[optionIndex].text = e.target.value;
35
+ thisElement.options[optionIndex].value = val;
36
+ setElement(thisElement);
37
+ setDirty(true);
38
+ };
39
+ var editValue = function editValue(optionIndex, e) {
40
+ var thisElement = isObjectNotEmpty(element) ? _objectSpread({}, element) : {};
41
+ var val = e.target.value === '' ? _setValue(thisElement.options[optionIndex].text) : e.target.value;
42
+ thisElement.options[optionIndex].value = val;
43
+ setElement(thisElement);
44
+ setDirty(true);
45
+ };
46
+
47
+ // eslint-disable-next-line no-unused-vars
48
+ var editOptionCorrect = function editOptionCorrect(optionIndex, e) {
49
+ var thisElement = isObjectNotEmpty(element) ? _objectSpread({}, element) : {};
50
+ if (thisElement.options[optionIndex].hasOwnProperty('correct')) {
51
+ delete thisElement.options[optionIndex].correct;
52
+ } else {
53
+ thisElement.options[optionIndex].correct = true;
35
54
  }
36
- }, {
37
- key: "editOption",
38
- value: function editOption(optionIndex, e) {
39
- var thisElement = this.state.element;
40
- var val = thisElement.options[optionIndex].value !== this._setValue(thisElement.options[optionIndex].text) ? thisElement.options[optionIndex].value : this._setValue(e.target.value);
41
- thisElement.options[optionIndex].text = e.target.value;
42
- thisElement.options[optionIndex].value = val;
43
- this.setState({
44
- element: thisElement,
45
- dirty: true
46
- });
55
+ setElement(thisElement);
56
+ props.updateElement(thisElement);
57
+ };
58
+ var updateOption = function updateOption() {
59
+ var thisElement = isObjectNotEmpty(element) ? _objectSpread({}, element) : {};
60
+ // to prevent ajax calls with no change
61
+ if (dirty) {
62
+ props.updateElement(thisElement);
63
+ setDirty(false);
47
64
  }
48
- }, {
49
- key: "editValue",
50
- value: function editValue(optionIndex, e) {
51
- var thisElement = this.state.element;
52
- var val = e.target.value === '' ? this._setValue(thisElement.options[optionIndex].text) : e.target.value;
53
- thisElement.options[optionIndex].value = val;
54
- this.setState({
55
- element: thisElement,
65
+ };
66
+ var addOption = function addOption(index) {
67
+ var thisElement = isObjectNotEmpty(element) ? _objectSpread({}, element) : {};
68
+ thisElement.options.splice(index + 1, 0, {
69
+ value: '',
70
+ text: '',
71
+ key: ID.uuid()
72
+ });
73
+ props.updateElement(thisElement);
74
+ };
75
+ var removeOption = function removeOption(index) {
76
+ var thisElement = isObjectNotEmpty(element) ? _objectSpread({}, element) : {};
77
+ thisElement.options.splice(index, 1);
78
+ props.updateElement(thisElement);
79
+ };
80
+ React.useEffect(function () {
81
+ if (dirty) {
82
+ var thisElement = isObjectNotEmpty(element) ? _objectSpread(_objectSpread({}, element), {}, {
83
+ dirty: true
84
+ }) : {
56
85
  dirty: true
57
- });
86
+ };
87
+ props.updateElement(thisElement);
58
88
  }
59
-
60
- // eslint-disable-next-line no-unused-vars
61
- }, {
62
- key: "editOptionCorrect",
63
- value: function editOptionCorrect(optionIndex, e) {
64
- var thisElement = this.state.element;
65
- if (thisElement.options[optionIndex].hasOwnProperty('correct')) {
66
- delete thisElement.options[optionIndex].correct;
67
- } else {
68
- thisElement.options[optionIndex].correct = true;
89
+ }, []);
90
+ return /*#__PURE__*/React.createElement("div", {
91
+ className: "dynamic-option-list"
92
+ }, /*#__PURE__*/React.createElement("ul", null, /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
93
+ sm: 6
94
+ }, /*#__PURE__*/React.createElement("b", null, "Options")), props.canHaveOptionValue && /*#__PURE__*/React.createElement(Col, {
95
+ sm: 2
96
+ }, /*#__PURE__*/React.createElement("b", null, "Value")), props.canHaveOptionValue && props.canHaveOptionCorrect && /*#__PURE__*/React.createElement(Col, {
97
+ sm: 4
98
+ }, /*#__PURE__*/React.createElement("b", null, "Correct")))), props.element.options.map(function (option, index) {
99
+ var val = option.value !== _setValue(option.text) ? option.value : '';
100
+ return /*#__PURE__*/React.createElement("li", {
101
+ className: "clearfix",
102
+ key: "edit_".concat(option.key)
103
+ }, /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
104
+ sm: 6
105
+ }, /*#__PURE__*/React.createElement(Form.Control, {
106
+ tabIndex: index + 1,
107
+ style: {
108
+ width: '100%'
109
+ },
110
+ type: "text",
111
+ name: "text_".concat(index),
112
+ placeholder: "Option text",
113
+ value: option.text,
114
+ onBlur: updateOption,
115
+ onChange: function onChange(e) {
116
+ editOption(index, e);
69
117
  }
70
- this.setState({
71
- element: thisElement
72
- });
73
- this.props.updateElement.call(this.props.preview, thisElement);
74
- }
75
- }, {
76
- key: "updateOption",
77
- value: function updateOption() {
78
- var thisElement = this.state.element;
79
- // to prevent ajax calls with no change
80
- if (this.state.dirty) {
81
- this.props.updateElement.call(this.props.preview, thisElement);
82
- this.setState({
83
- dirty: false
84
- });
118
+ })), props.canHaveOptionValue && /*#__PURE__*/React.createElement(Col, {
119
+ sm: 2
120
+ }, /*#__PURE__*/React.createElement(Form.Control, {
121
+ type: "text",
122
+ name: "value_".concat(index),
123
+ value: val,
124
+ onChange: function onChange(e) {
125
+ editValue(index, e);
85
126
  }
86
- }
87
- }, {
88
- key: "addOption",
89
- value: function addOption(index) {
90
- var thisElement = this.state.element;
91
- thisElement.options.splice(index + 1, 0, {
92
- value: '',
93
- text: '',
94
- key: ID.uuid()
95
- });
96
- this.props.updateElement.call(this.props.preview, thisElement);
97
- }
98
- }, {
99
- key: "removeOption",
100
- value: function removeOption(index) {
101
- var thisElement = this.state.element;
102
- thisElement.options.splice(index, 1);
103
- this.props.updateElement.call(this.props.preview, thisElement);
104
- }
105
- }, {
106
- key: "render",
107
- value: function render() {
108
- var _this2 = this;
109
- if (this.state.dirty) {
110
- this.state.element.dirty = true;
127
+ })), props.canHaveOptionValue && props.canHaveOptionCorrect && /*#__PURE__*/React.createElement(Col, {
128
+ sm: 1
129
+ }, /*#__PURE__*/React.createElement(Form.Check, {
130
+ type: "checkbox",
131
+ value: "1",
132
+ onChange: function onChange(e) {
133
+ editOptionCorrect(index, e);
134
+ },
135
+ checked: option.hasOwnProperty('correct')
136
+ })), /*#__PURE__*/React.createElement(Col, {
137
+ sm: 3
138
+ }, /*#__PURE__*/React.createElement("div", {
139
+ className: "dynamic-options-actions-buttons"
140
+ }, /*#__PURE__*/React.createElement(Button, {
141
+ variant: "success",
142
+ onClick: function onClick() {
143
+ addOption(index);
111
144
  }
112
- return /*#__PURE__*/React.createElement("div", {
113
- className: "dynamic-option-list"
114
- }, /*#__PURE__*/React.createElement("ul", null, /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
115
- sm: 6
116
- }, /*#__PURE__*/React.createElement("b", null, "Options")), this.props.canHaveOptionValue && /*#__PURE__*/React.createElement(Col, {
117
- sm: 2
118
- }, /*#__PURE__*/React.createElement("b", null, "Value")), this.props.canHaveOptionValue && this.props.canHaveOptionCorrect && /*#__PURE__*/React.createElement(Col, {
119
- sm: 4
120
- }, /*#__PURE__*/React.createElement("b", null, "Correct")))), this.props.element.options.map(function (option, index) {
121
- var thisKey = "edit_".concat(option.key);
122
- var val = option.value !== _this2._setValue(option.text) ? option.value : '';
123
- return /*#__PURE__*/React.createElement("li", {
124
- className: "clearfix",
125
- key: thisKey
126
- }, /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
127
- sm: 6
128
- }, /*#__PURE__*/React.createElement(Form.Control, {
129
- tabIndex: index + 1,
130
- style: {
131
- width: '100%'
132
- },
133
- type: "text",
134
- name: "text_".concat(index),
135
- placeholder: "Option text",
136
- value: option.text,
137
- onBlur: _this2.updateOption.bind(_this2),
138
- onChange: _this2.editOption.bind(_this2, index)
139
- })), _this2.props.canHaveOptionValue && /*#__PURE__*/React.createElement(Col, {
140
- sm: 2
141
- }, /*#__PURE__*/React.createElement(Form.Control, {
142
- type: "text",
143
- name: "value_".concat(index),
144
- value: val,
145
- onChange: _this2.editValue.bind(_this2, index)
146
- })), _this2.props.canHaveOptionValue && _this2.props.canHaveOptionCorrect && /*#__PURE__*/React.createElement(Col, {
147
- sm: 1
148
- }, /*#__PURE__*/React.createElement(Form.Check, {
149
- type: "checkbox",
150
- value: "1",
151
- onChange: _this2.editOptionCorrect.bind(_this2, index),
152
- checked: option.hasOwnProperty('correct')
153
- })), /*#__PURE__*/React.createElement(Col, {
154
- sm: 3
155
- }, /*#__PURE__*/React.createElement("div", {
156
- className: "dynamic-options-actions-buttons"
157
- }, /*#__PURE__*/React.createElement(Button, {
158
- variant: "success",
159
- onClick: _this2.addOption.bind(_this2, index)
160
- }, /*#__PURE__*/React.createElement(FaPlusCircle, null)), index > 0 && /*#__PURE__*/React.createElement(Button, {
161
- variant: "danger",
162
- onClick: _this2.removeOption.bind(_this2, index)
163
- }, /*#__PURE__*/React.createElement(FaMinusCircle, null))))));
164
- })));
165
- }
166
- }]);
167
- }(React.Component);
168
- export { DynamicOptionList as default };
145
+ }, /*#__PURE__*/React.createElement(FaPlusCircle, null)), index > 0 && /*#__PURE__*/React.createElement(Button, {
146
+ variant: "danger",
147
+ onClick: function onClick() {
148
+ removeOption(index);
149
+ }
150
+ }, /*#__PURE__*/React.createElement(FaMinusCircle, null))))));
151
+ })));
152
+ };
153
+ export default DynamicOptionList;
@@ -0,0 +1,118 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _excluded = ["item", "controls", "items", "editModeOn", "getItemById", "setAsChild", "removeChild", "seq", "index", "style"];
3
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
8
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
10
+ 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."); }
11
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
14
+ 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."); }
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
+ 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; }
17
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
18
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
20
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } } return target; }
21
+ /* eslint-disable camelcase */
22
+ import React from "react";
23
+ import ComponentHeader from "../survey-elements/component-header";
24
+ import FieldsetDustbin from '../multi-column/dustbin';
25
+ import ItemTypes from "../ItemTypes";
26
+ import { Col, Container, Row } from "react-bootstrap";
27
+ import myxss from "../survey-elements/myxss";
28
+ import { isListNotEmpty, isObjectNotEmpty } from "../utils/objectUtils";
29
+ var accepts = [ItemTypes.BOX, ItemTypes.CARD];
30
+ var ComponentLegend = function ComponentLegend(_ref) {
31
+ var item = _ref.item;
32
+ var labelText = myxss.process(item.label);
33
+ if (!labelText || !labelText.trim()) {
34
+ return null;
35
+ }
36
+ return /*#__PURE__*/React.createElement("legend", {
37
+ dangerouslySetInnerHTML: {
38
+ __html: labelText
39
+ }
40
+ });
41
+ };
42
+ var FieldSetBase = function FieldSetBase(_ref2) {
43
+ var item = _ref2.item,
44
+ controls = _ref2.controls,
45
+ items = _ref2.items,
46
+ editModeOn = _ref2.editModeOn,
47
+ getItemById = _ref2.getItemById,
48
+ setAsChild = _ref2.setAsChild,
49
+ removeChild = _ref2.removeChild,
50
+ seq = _ref2.seq,
51
+ index = _ref2.index,
52
+ style = _ref2.style,
53
+ otherProps = _objectWithoutProperties(_ref2, _excluded);
54
+ var pageBreakBefore = item.pageBreakBefore;
55
+ var baseClasses = "SortableItem rfb-item";
56
+ if (pageBreakBefore) {
57
+ baseClasses += " alwaysbreak";
58
+ }
59
+ var _React$useState = React.useState(isObjectNotEmpty(item) && isListNotEmpty(item === null || item === void 0 ? void 0 : item.childItems) ? _toConsumableArray(item === null || item === void 0 ? void 0 : item.childItems) : [null]),
60
+ _React$useState2 = _slicedToArray(_React$useState, 2),
61
+ childItemIds = _React$useState2[0],
62
+ setChildItemIds = _React$useState2[1];
63
+ var _onDropSuccess = function onDropSuccess(droppedIndex) {
64
+ // let updatedItem = isObjectNotEmpty(item) ? { ...item } : {};
65
+ // let existingChildItemIds = isListNotEmpty(updatedItem.childItems) ? [...updatedItem.childItems] : [null];
66
+ // const isLastChild = existingChildItemIds === (droppedIndex + 1);
67
+ // console.log('onDropSuccess', droppedIndex, existingChildItemIds, childItemIds, item, isLastChild);
68
+
69
+ // if (isLastChild) {
70
+ // let updatedChildItemIds = Array.from({ length: existingChildItemIds.length + 1 }, (v, i) => { return existingChildItemIds[i] ? existingChildItemIds[i] : null });
71
+ // setChildItemIds(updatedChildItemIds);
72
+ // }
73
+ };
74
+ React.useEffect(function () {
75
+ if (isObjectNotEmpty(item) && isListNotEmpty(item === null || item === void 0 ? void 0 : item.childItems)) {
76
+ setChildItemIds([].concat(_toConsumableArray(item === null || item === void 0 ? void 0 : item.childItems), [null]));
77
+ } else {
78
+ setChildItemIds([null]);
79
+ }
80
+ }, [item]);
81
+ return /*#__PURE__*/React.createElement("div", {
82
+ style: _objectSpread({}, style),
83
+ className: baseClasses
84
+ }, /*#__PURE__*/React.createElement(ComponentHeader, _extends({
85
+ item: item,
86
+ index: index,
87
+ editModeOn: editModeOn,
88
+ setAsChild: setAsChild
89
+ }, otherProps)), /*#__PURE__*/React.createElement("fieldset", null, /*#__PURE__*/React.createElement(ComponentLegend, {
90
+ item: item
91
+ }), childItemIds === null || childItemIds === void 0 ? void 0 : childItemIds.map(function (childItemId, childItemIndex) {
92
+ return /*#__PURE__*/React.createElement("div", {
93
+ key: "".concat(childItemIndex, "_").concat(childItemId || "_")
94
+ }, controls ? controls[childItemIndex] : /*#__PURE__*/React.createElement(FieldsetDustbin, {
95
+ style: {
96
+ width: "100%"
97
+ },
98
+ item: item,
99
+ accepts: accepts,
100
+ items: childItemIds,
101
+ key: childItemIndex,
102
+ col: childItemIndex,
103
+ onDropSuccess: function onDropSuccess() {
104
+ _onDropSuccess(childItemIndex);
105
+ },
106
+ parentIndex: index,
107
+ editModeOn: editModeOn,
108
+ _onDestroy: function _onDestroy() {
109
+ removeChild(item, childItemIndex);
110
+ },
111
+ getItemById: getItemById,
112
+ setAsChild: setAsChild,
113
+ seq: seq,
114
+ rowNo: childItemIndex
115
+ }));
116
+ })));
117
+ };
118
+ export default FieldSetBase;
@@ -1,132 +1,2 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["item", "className"];
3
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
8
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } } return target; }
11
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
- 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."); }
13
- 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); }
14
- 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; }
15
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
16
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
- /* eslint-disable camelcase */
18
- import React from "react";
19
- import ComponentHeader from "../survey-elements/component-header";
20
- import FieldsetDustbin from '../multi-column/dustbin';
21
- import ItemTypes from "../ItemTypes";
22
- import { Col, Container, Row } from "react-bootstrap/esm";
23
- import myxss from "../survey-elements/myxss";
24
- var accepts = [ItemTypes.BOX, ItemTypes.CARD];
25
- var ComponentLegend = function ComponentLegend(_ref) {
26
- var item = _ref.item;
27
- var labelText = myxss.process(item.label);
28
- if (!labelText || !labelText.trim()) {
29
- return null;
30
- }
31
- return /*#__PURE__*/React.createElement("legend", {
32
- dangerouslySetInnerHTML: {
33
- __html: labelText
34
- }
35
- });
36
- };
37
- var FieldSet = function FieldSet(props) {
38
- var _React$useState = React.useState({}),
39
- _React$useState2 = _slicedToArray(_React$useState, 2),
40
- childItem = _React$useState2[0],
41
- setChildItem = _React$useState2[1];
42
- var _React$useState3 = React.useState(null),
43
- _React$useState4 = _slicedToArray(_React$useState3, 2),
44
- childItems = _React$useState4[0],
45
- setChildItems = _React$useState4[1];
46
- React.useEffect(function () {
47
- var item = props.item,
48
- className = props.className,
49
- rest = _objectWithoutProperties(props, _excluded);
50
- setChildItem(item);
51
- var count = 1;
52
- createChild(count, item);
53
- }, [props]);
54
- var addNewChild = function addNewChild() {
55
- var $dataItem = props.item;
56
- var colCount = $dataItem.childItems.length + 1;
57
- var oldChilds = $dataItem.childItems;
58
- $dataItem.childItems = Array.from({
59
- length: colCount
60
- }, function (v, i) {
61
- return oldChilds[i] ? oldChilds[i] : null;
62
- });
63
- setChildItems($dataItem.childItems);
64
- };
65
- var _onDropSuccess = function onDropSuccess(droppedIndex) {
66
- var totalChild = childItems ? childItems.length : 0;
67
- var isLastChild = totalChild === droppedIndex + 1;
68
- if (isLastChild) {
69
- addNewChild();
70
- }
71
- };
72
- var createChild = function createChild(count, $dataItem) {
73
- var colCount = count;
74
- if (!$dataItem.childItems) {
75
- // eslint-disable-next-line no-param-reassign
76
- $dataItem.childItems = Array.from({
77
- length: colCount
78
- }, function (v, i) {
79
- return null;
80
- });
81
- $dataItem.isContainer = true;
82
- }
83
- setChildItems($dataItem.childItems);
84
- };
85
- var controls = props.controls,
86
- editModeOn = props.editModeOn,
87
- getItemById = props.getItemById,
88
- setAsChild = props.setAsChild,
89
- removeChild = props.removeChild,
90
- seq = props.seq,
91
- index = props.index;
92
- var pageBreakBefore = childItem.pageBreakBefore;
93
- var baseClasses = "SortableItem rfb-item";
94
- if (pageBreakBefore) {
95
- baseClasses += " alwaysbreak";
96
- }
97
- return /*#__PURE__*/React.createElement("div", {
98
- style: _objectSpread({}, props.style),
99
- className: baseClasses
100
- }, /*#__PURE__*/React.createElement(ComponentHeader, _extends({}, props, {
101
- isFieldSet: true
102
- })), /*#__PURE__*/React.createElement("fieldset", null, /*#__PURE__*/React.createElement(ComponentLegend, props), /*#__PURE__*/React.createElement(Container, {
103
- fluid: true
104
- }, /*#__PURE__*/React.createElement(Row, null, childItems === null || childItems === void 0 ? void 0 : childItems.map(function (x, i) {
105
- return /*#__PURE__*/React.createElement(Col, {
106
- key: "".concat(i, "_").concat(x || "_"),
107
- md: 12
108
- }, controls ? controls[i] : /*#__PURE__*/React.createElement(FieldsetDustbin, {
109
- style: {
110
- width: "100%"
111
- },
112
- item: childItem,
113
- accepts: accepts,
114
- items: childItems,
115
- key: i,
116
- col: i,
117
- onDropSuccess: function onDropSuccess() {
118
- return _onDropSuccess(i);
119
- },
120
- parentIndex: index,
121
- editModeOn: editModeOn,
122
- _onDestroy: function _onDestroy() {
123
- return removeChild(childItem, i);
124
- },
125
- getItemById: getItemById,
126
- setAsChild: setAsChild,
127
- seq: seq,
128
- rowNo: i
129
- }));
130
- })))));
131
- };
132
- export default FieldSet;
1
+ import FieldSet from './FieldSet';
2
+ export { FieldSet };