react-form-builder-more-flexibility 1.0.56 → 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.
@@ -13,7 +13,6 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
13
13
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
14
  var _react = _interopRequireDefault(require("react"));
15
15
  var _propTypes = _interopRequireDefault(require("prop-types"));
16
- var _reactDom = _interopRequireDefault(require("react-dom"));
17
16
  var _classnames = _interopRequireDefault(require("classnames"));
18
17
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
19
18
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
@@ -38,6 +37,15 @@ var StarRating = exports["default"] = /*#__PURE__*/function (_React$Component) {
38
37
  _this = _callSuper(this, StarRating, [props]);
39
38
  _this.min = 0;
40
39
  _this.max = props.ratingAmount || 5;
40
+
41
+ // Pre-bind methods to avoid creating new functions on each render
42
+ _this.handleMouseLeave = _this.handleMouseLeave.bind(_this);
43
+ _this.handleMouseMove = _this.handleMouseMove.bind(_this);
44
+ _this.handleClick = _this.handleClick.bind(_this);
45
+
46
+ // Create refs properly
47
+ _this.rootNode = /*#__PURE__*/_react["default"].createRef();
48
+ _this.ratingContainerNode = /*#__PURE__*/_react["default"].createRef();
41
49
  var ratingVal = props.rating;
42
50
  var ratingCache = {
43
51
  pos: ratingVal ? _this.getStarRatingPosition(ratingVal) : 0,
@@ -69,39 +77,24 @@ var StarRating = exports["default"] = /*#__PURE__*/function (_React$Component) {
69
77
  }
70
78
  return stars;
71
79
  }
72
-
73
- // componentWillMount() {
74
- // this.min = 0;
75
- // this.max = this.props.ratingAmount || 5;
76
- // if (this.props.rating) {
77
- // this.state.editing = this.props.editing || false;
78
- // const ratingVal = this.props.rating;
79
- // this.state.ratingCache.pos = this.getStarRatingPosition(ratingVal);
80
- // this.state.ratingCache.rating = ratingVal;
81
-
82
- // this.setState({
83
- // ratingCache: this.state.ratingCache,
84
- // rating: ratingVal,
85
- // pos: this.getStarRatingPosition(ratingVal),
86
- // });
87
- // }
88
- // }
89
80
  }, {
90
81
  key: "componentDidMount",
91
82
  value: function componentDidMount() {
92
- this.root = _reactDom["default"].findDOMNode(this.rootNode);
93
- this.ratingContainer = _reactDom["default"].findDOMNode(this.node);
94
- }
95
- }, {
96
- key: "componentWillUnmount",
97
- value: function componentWillUnmount() {
98
- delete this.root;
99
- delete this.ratingContainer;
83
+ // Initialize with proper values from props
84
+ if (this.props.rating) {
85
+ this.setState({
86
+ pos: this.getStarRatingPosition(this.props.rating),
87
+ rating: this.props.rating
88
+ });
89
+ }
100
90
  }
91
+
92
+ // REMOVED componentWillUnmount as it wasn't doing anything useful
101
93
  }, {
102
94
  key: "getPosition",
103
95
  value: function getPosition(e) {
104
- return e.pageX - this.root.getBoundingClientRect().left;
96
+ if (!this.rootNode.current) return 0;
97
+ return e.pageX - this.rootNode.current.getBoundingClientRect().left;
105
98
  }
106
99
  }, {
107
100
  key: "applyPrecision",
@@ -117,6 +110,7 @@ var StarRating = exports["default"] = /*#__PURE__*/function (_React$Component) {
117
110
  }, {
118
111
  key: "getWidthFromValue",
119
112
  value: function getWidthFromValue(val) {
113
+ if (val === null || val === undefined || typeof val !== 'number') return 0;
120
114
  var min = this.min;
121
115
  var max = this.max;
122
116
  if (val <= min || min === max) {
@@ -125,13 +119,15 @@ var StarRating = exports["default"] = /*#__PURE__*/function (_React$Component) {
125
119
  if (val >= max) {
126
120
  return 100;
127
121
  }
128
- return val / (max - min) * 100;
122
+ return (val - min) / (max - min) * 100;
129
123
  }
130
124
  }, {
131
125
  key: "getValueFromPosition",
132
126
  value: function getValueFromPosition(pos) {
127
+ if (!this.ratingContainerNode.current) return 0;
133
128
  var precision = this.getDecimalPlaces(this.props.step);
134
- var maxWidth = this.ratingContainer.offsetWidth;
129
+ var maxWidth = this.ratingContainerNode.current.offsetWidth;
130
+ if (!maxWidth) return 0;
135
131
  var diff = this.max - this.min;
136
132
  var factor = diff * pos / (maxWidth * this.props.step);
137
133
  factor = Math.ceil(factor);
@@ -143,8 +139,7 @@ var StarRating = exports["default"] = /*#__PURE__*/function (_React$Component) {
143
139
  key: "calculate",
144
140
  value: function calculate(pos) {
145
141
  var val = this.getValueFromPosition(pos);
146
- var width = this.getWidthFromValue(val);
147
- width += '%';
142
+ var width = "".concat(this.getWidthFromValue(val), "%");
148
143
  return {
149
144
  width: width,
150
145
  val: val
@@ -172,9 +167,9 @@ var StarRating = exports["default"] = /*#__PURE__*/function (_React$Component) {
172
167
  xmlns: "http://www.w3.org/2000/svg"
173
168
  }, /*#__PURE__*/_react["default"].createElement("g", {
174
169
  stroke: "none",
175
- "stroke-width": "1",
170
+ strokeWidth: "1",
176
171
  fill: "none",
177
- "fill-rule": "evenodd"
172
+ fillRule: "evenodd"
178
173
  }, /*#__PURE__*/_react["default"].createElement("polygon", {
179
174
  id: "star-flat",
180
175
  points: "143 225 54.8322122 271.352549 71.6707613 173.176275 0.341522556 103.647451 98.9161061 89.3237254 143 0 187.083894 89.3237254 285.658477 103.647451 214.329239 173.176275 231.167788 271.352549 "
@@ -191,26 +186,46 @@ var StarRating = exports["default"] = /*#__PURE__*/function (_React$Component) {
191
186
  }, {
192
187
  key: "handleMouseMove",
193
188
  value: function handleMouseMove(e) {
194
- // get hover position
195
- var ratingEvent = this.getRatingEvent(e);
196
- this.updateRating(ratingEvent.width, ratingEvent.val);
197
- }
198
- }, {
199
- key: "updateRating",
200
- value: function updateRating(width, val) {
201
- this.setState({
202
- pos: width,
203
- rating: val
204
- });
189
+ // Only process if editing is enabled
190
+ if (!this.props.disabled && (this.state.editing || this.props.editing)) {
191
+ // get hover position
192
+ var ratingEvent = this.getRatingEvent(e);
193
+ this.setState({
194
+ pos: ratingEvent.width,
195
+ rating: ratingEvent.val
196
+ });
197
+ }
205
198
  }
199
+
200
+ // REMOVED updateRating method which was causing issues
201
+
202
+ // Fixed shouldComponentUpdate to prevent infinite loops
206
203
  }, {
207
204
  key: "shouldComponentUpdate",
208
205
  value: function shouldComponentUpdate(nextProps, nextState) {
209
- if (nextProps !== this.props) {
210
- this.updateRating(this.getStarRatingPosition(nextProps.rating), nextProps.rating);
206
+ // Don't trigger a state update from this method!
207
+ if (nextProps.rating !== this.props.rating) {
211
208
  return true;
212
209
  }
213
- return nextState.ratingCache.rating !== this.state.ratingCache.rating || nextState.rating !== this.state.rating;
210
+ return nextState.ratingCache.rating !== this.state.ratingCache.rating || nextState.rating !== this.state.rating || nextState.pos !== this.state.pos;
211
+ }
212
+
213
+ // Handle rating changes in componentDidUpdate instead
214
+ }, {
215
+ key: "componentDidUpdate",
216
+ value: function componentDidUpdate(prevProps) {
217
+ // Only update if the rating prop changed
218
+ if (prevProps.rating !== this.props.rating && this.props.rating !== this.state.rating) {
219
+ // Update state without causing an infinite loop
220
+ this.setState({
221
+ pos: this.getStarRatingPosition(this.props.rating),
222
+ rating: this.props.rating,
223
+ ratingCache: {
224
+ pos: this.getStarRatingPosition(this.props.rating),
225
+ rating: this.props.rating
226
+ }
227
+ });
228
+ }
214
229
  }
215
230
  }, {
216
231
  key: "handleClick",
@@ -221,15 +236,24 @@ var StarRating = exports["default"] = /*#__PURE__*/function (_React$Component) {
221
236
  e.preventDefault();
222
237
  return false;
223
238
  }
239
+
240
+ // Get the current rating based on click position
241
+ var ratingEvent = this.getRatingEvent(e);
224
242
  var ratingCache = {
225
- pos: this.state.pos,
226
- rating: this.state.rating,
243
+ pos: ratingEvent.width,
244
+ rating: ratingEvent.val,
227
245
  caption: this.props.caption,
228
246
  name: this.props.name
229
247
  };
248
+
249
+ // Update the state with new values
230
250
  this.setState({
231
- ratingCache: ratingCache
251
+ ratingCache: ratingCache,
252
+ pos: ratingEvent.width,
253
+ rating: ratingEvent.val
232
254
  });
255
+
256
+ // Call the callback with the new rating
233
257
  this.props.onRatingClick(e, ratingCache);
234
258
  return true;
235
259
  }
@@ -244,30 +268,22 @@ var StarRating = exports["default"] = /*#__PURE__*/function (_React$Component) {
244
268
  }, {
245
269
  key: "render",
246
270
  value: function render() {
247
- var _this2 = this;
248
- // let caption = null;
249
271
  var classes = (0, _classnames["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])({
250
272
  'react-star-rating__root': true,
251
273
  'rating-disabled': this.props.disabled
252
274
  }, "react-star-rating__size--".concat(this.props.size), this.props.size), 'rating-editing', this.state.editing));
253
275
 
254
- // is there a caption?
255
- // if (this.props.caption) {
256
- // caption = (<span className="react-rating-caption">{this.props.caption}</span>);
257
- // }
258
-
259
276
  // are we editing this rating?
260
277
  var starRating;
261
- if (this.state.editing) {
278
+ var isEditable = !this.props.disabled && (this.state.editing || this.props.editing);
279
+ if (isEditable) {
262
280
  starRating = /*#__PURE__*/_react["default"].createElement("div", {
263
- ref: function ref(c) {
264
- return _this2.node = c;
265
- },
281
+ ref: this.ratingContainerNode,
266
282
  className: "rating-container rating-gly-star",
267
283
  "data-content": this.state.glyph,
268
- onMouseMove: this.handleMouseMove.bind(this),
269
- onMouseLeave: this.handleMouseLeave.bind(this),
270
- onClick: this.handleClick.bind(this)
284
+ onMouseMove: this.handleMouseMove,
285
+ onMouseLeave: this.handleMouseLeave,
286
+ onClick: this.handleClick
271
287
  }, /*#__PURE__*/_react["default"].createElement("div", {
272
288
  className: "rating-stars",
273
289
  "data-content": this.state.glyph,
@@ -277,9 +293,7 @@ var StarRating = exports["default"] = /*#__PURE__*/function (_React$Component) {
277
293
  }));
278
294
  } else {
279
295
  starRating = /*#__PURE__*/_react["default"].createElement("div", {
280
- ref: function ref(c) {
281
- return _this2.node = c;
282
- },
296
+ ref: this.ratingContainerNode,
283
297
  className: "rating-container rating-gly-star",
284
298
  "data-content": this.state.glyph
285
299
  }, /*#__PURE__*/_react["default"].createElement("div", {
@@ -293,26 +307,23 @@ var StarRating = exports["default"] = /*#__PURE__*/function (_React$Component) {
293
307
  return /*#__PURE__*/_react["default"].createElement("span", {
294
308
  className: "react-star-rating"
295
309
  }, /*#__PURE__*/_react["default"].createElement("span", {
296
- ref: function ref(c) {
297
- return _this2.rootNode = c;
298
- },
310
+ ref: this.rootNode,
299
311
  style: {
300
- cursor: 'pointer'
312
+ cursor: isEditable ? 'pointer' : 'default'
301
313
  },
302
314
  className: classes
303
- }, starRating, /*#__PURE__*/_react["default"].createElement("input", (0, _defineProperty2["default"])({
315
+ }, starRating, /*#__PURE__*/_react["default"].createElement("input", {
304
316
  type: "hidden",
305
317
  name: this.props.name,
306
- value: this.state.ratingCache.rating,
318
+ value: this.state.rating || 0,
307
319
  style: {
308
- display: 'none !important'
320
+ display: 'none !important',
321
+ width: 65
309
322
  },
310
323
  min: this.min,
311
324
  max: this.max,
312
325
  readOnly: true
313
- }, "style", {
314
- width: 65
315
- }))));
326
+ })));
316
327
  }
317
328
  }]);
318
329
  }(_react["default"].Component);
package/lib/form.js CHANGED
@@ -13,7 +13,6 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
13
13
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
15
  var _react = _interopRequireDefault(require("react"));
16
- var _reactDom = _interopRequireDefault(require("react-dom"));
17
16
  var _fbemitter = require("fbemitter");
18
17
  var _reactIntl = require("react-intl");
19
18
  var _formValidator = _interopRequireDefault(require("./form-validator"));
@@ -23,7 +22,7 @@ var _fieldset = require("./fieldset");
23
22
  var _customElement = _interopRequireDefault(require("./form-elements/custom-element"));
24
23
  var _registry = _interopRequireDefault(require("./stores/registry"));
25
24
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
26
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /**
25
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /* eslint-disable arrow-body-style */ /* eslint-disable camelcase */ /**
27
26
  * <Form />
28
27
  */
29
28
  var Image = _formElements["default"].Image,
@@ -132,7 +131,7 @@ var ReactForm = /*#__PURE__*/function (_React$Component) {
132
131
  } else if (item.element === 'FileUpload') {
133
132
  $item.value = ref.state.fileUpload;
134
133
  } else if (ref && ref.inputField && ref.inputField.current) {
135
- $item = _reactDom["default"].findDOMNode(ref.inputField.current);
134
+ $item = ref.inputField.current;
136
135
  if (trimValue && $item && typeof $item.value === 'string') {
137
136
  $item.value = $item.value.trim();
138
137
  }
@@ -147,7 +146,7 @@ var ReactForm = /*#__PURE__*/function (_React$Component) {
147
146
  var ref = this.inputs[item.field_name];
148
147
  if (item.element === 'Checkboxes' || item.element === 'RadioButtons') {
149
148
  item.options.forEach(function (option) {
150
- var $option = _reactDom["default"].findDOMNode(ref.options["child_ref_".concat(option.key)]);
149
+ var $option = ref.options["child_ref_".concat(option.key)];
151
150
  if (option.hasOwnProperty('correct') && !$option.checked || !option.hasOwnProperty('correct') && $option.checked) {
152
151
  incorrect = true;
153
152
  }
@@ -174,7 +173,7 @@ var ReactForm = /*#__PURE__*/function (_React$Component) {
174
173
  if (item.element === 'Checkboxes' || item.element === 'RadioButtons') {
175
174
  var checked_options = 0;
176
175
  item.options.forEach(function (option) {
177
- var $option = _reactDom["default"].findDOMNode(ref.options["child_ref_".concat(option.key)]);
176
+ var $option = ref.options["child_ref_".concat(option.key)];
178
177
  if ($option.checked) {
179
178
  checked_options += 1;
180
179
  }
@@ -210,7 +209,7 @@ var ReactForm = /*#__PURE__*/function (_React$Component) {
210
209
  if (item.element === 'Checkboxes' || item.element === 'RadioButtons') {
211
210
  var checked_options = [];
212
211
  item.options.forEach(function (option) {
213
- var $option = _reactDom["default"].findDOMNode(ref.options["child_ref_".concat(option.key)]);
212
+ var $option = ref.options["child_ref_".concat(option.key)];
214
213
  if ($option.checked) {
215
214
  checked_options.push(_this3._getOptionKeyValue(option));
216
215
  }
@@ -250,7 +249,7 @@ var ReactForm = /*#__PURE__*/function (_React$Component) {
250
249
  if ($canvas_sig) {
251
250
  var base64 = $canvas_sig.toDataURL().replace('data:image/png;base64,', '');
252
251
  var isEmpty = $canvas_sig.isEmpty();
253
- var $input_sig = _reactDom["default"].findDOMNode(ref.inputField.current);
252
+ var $input_sig = ref.inputField.current;
254
253
  if (isEmpty) {
255
254
  $input_sig.value = '';
256
255
  } else {
@@ -276,14 +275,14 @@ var ReactForm = /*#__PURE__*/function (_React$Component) {
276
275
  var data = this._collectFormData(this.props.data, true);
277
276
  onSubmit(data);
278
277
  } else {
279
- var $form = _reactDom["default"].findDOMNode(this.form);
278
+ var $form = this.form;
280
279
  $form.submit();
281
280
  }
282
281
  }
283
282
  }
284
283
  }, {
285
284
  key: "handleBlur",
286
- value: function handleBlur(event) {
285
+ value: function handleBlur() {
287
286
  // Call submit function on blur
288
287
  if (this.props.onBlur) {
289
288
  var onBlur = this.props.onBlur;
@@ -293,7 +292,7 @@ var ReactForm = /*#__PURE__*/function (_React$Component) {
293
292
  }
294
293
  }, {
295
294
  key: "handleChange",
296
- value: function handleChange(event) {
295
+ value: function handleChange() {
297
296
  // Call submit function on change
298
297
  if (this.props.onChange) {
299
298
  var onChange = this.props.onChange;
@@ -22,8 +22,7 @@ var draftToHtml = _interopRequireWildcard(require("draftjs-to-html"));
22
22
  exports.draftToHtml = draftToHtml;
23
23
  var _reactDraftWysiwyg = require("react-draft-wysiwyg");
24
24
  var _UUID = _interopRequireDefault(require("../UUID"));
25
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
26
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
25
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
27
26
  var generateUUID = exports.generateUUID = function generateUUID() {
28
27
  return _UUID["default"].uuid();
29
28
  };
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports["default"] = void 0;
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
10
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
11
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
12
  var _react = _interopRequireWildcard(require("react"));
@@ -15,9 +16,8 @@ var _ItemTypes = _interopRequireDefault(require("../ItemTypes"));
15
16
  var _customElement = _interopRequireDefault(require("../form-elements/custom-element"));
16
17
  var _registry = _interopRequireDefault(require("../stores/registry"));
17
18
  var _store = _interopRequireDefault(require("../stores/store"));
18
- var _excluded = ["onDropSuccess", "seq", "draggedItem", "parentIndex", "canDrop", "isOver", "isOverCurrent", "connectDropTarget", "items", "col", "getDataById"];
19
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
20
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
19
+ var _excluded = ["onDropSuccess", "seq", "parentIndex", "items", "col", "getDataById", "accepts", "data", "setAsChild"];
20
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
21
21
  function getCustomElement(item, props) {
22
22
  if (!item.component || typeof item.component !== 'function') {
23
23
  item.component = _registry["default"].get(item.key);
@@ -67,89 +67,75 @@ function isContainer(item) {
67
67
  }
68
68
  return false;
69
69
  }
70
- var Dustbin = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
70
+ var Dustbin = function Dustbin(_ref) {
71
+ var _draggedItem$data;
71
72
  var onDropSuccess = _ref.onDropSuccess,
72
73
  seq = _ref.seq,
73
- draggedItem = _ref.draggedItem,
74
74
  parentIndex = _ref.parentIndex,
75
- canDrop = _ref.canDrop,
76
- isOver = _ref.isOver,
77
- isOverCurrent = _ref.isOverCurrent,
78
- connectDropTarget = _ref.connectDropTarget,
79
75
  items = _ref.items,
80
76
  col = _ref.col,
81
77
  getDataById = _ref.getDataById,
78
+ accepts = _ref.accepts,
79
+ data = _ref.data,
80
+ setAsChild = _ref.setAsChild,
82
81
  rest = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
82
+ var dropRef = (0, _react.useRef)(null);
83
83
  var item = getDataById(items[col]);
84
- (0, _react.useImperativeHandle)(ref, function () {
85
- return {
86
- onDrop: function onDrop(dropped) {
87
- console.log("dropped ites");
88
- var data = dropped.data;
89
- if (data) {
90
- onDropSuccess && onDropSuccess();
91
- _store["default"].dispatch('deleteLastItem');
84
+ var _useDrop = (0, _reactDnd.useDrop)({
85
+ accept: accepts,
86
+ collect: function collect(monitor) {
87
+ return {
88
+ isOver: monitor.isOver(),
89
+ canDrop: monitor.canDrop(),
90
+ draggedItem: monitor.getItem()
91
+ };
92
+ },
93
+ drop: function drop(droppedItem) {
94
+ // Do nothing when moving the box inside the same column
95
+ if (col === droppedItem.col && items[col] === droppedItem.id) return;
96
+
97
+ // Do not allow replace component other than both items in same multi column row
98
+ if (droppedItem.col === undefined && items[col]) {
99
+ _store["default"].dispatch('resetLastItem');
100
+ return;
101
+ }
102
+ if (!isContainer(droppedItem)) {
103
+ console.log("Item dropped", droppedItem);
104
+ var isBusy = !!items[col];
105
+ if (droppedItem.data) {
106
+ var isNew = !droppedItem.data.id;
107
+ var itemData = isNew ? droppedItem.onCreate(droppedItem.data) : droppedItem.data;
108
+ if (typeof setAsChild === 'function') {
109
+ setAsChild(data, itemData, col, isBusy);
110
+ }
111
+ onDropSuccess && onDropSuccess();
112
+ _store["default"].dispatch('deleteLastItem');
113
+ }
92
114
  }
115
+ },
116
+ canDrop: function canDrop(item) {
117
+ // Add any custom logic for when an item can be dropped
118
+ return true;
93
119
  }
94
- };
95
- }, []);
120
+ }),
121
+ _useDrop2 = (0, _slicedToArray2["default"])(_useDrop, 2),
122
+ _useDrop2$ = _useDrop2[0],
123
+ isOver = _useDrop2$.isOver,
124
+ canDrop = _useDrop2$.canDrop,
125
+ draggedItem = _useDrop2$.draggedItem,
126
+ drop = _useDrop2[1];
96
127
  var element = getElement(item, rest);
97
128
  var sameCard = draggedItem ? draggedItem.index === parentIndex : false;
98
-
99
- // console.log('dragIndex:',draggedItem?.index)
100
- // console.log('HoverIndex:',parentIndex)
101
- // console.log('SameCard:',sameCard)
102
-
103
129
  var backgroundColor = 'rgba(0, 0, 0, .03)';
104
- if (!sameCard && isOver && canDrop && !draggedItem.data.isContainer) {
130
+ if (!sameCard && isOver && canDrop && draggedItem && !((_draggedItem$data = draggedItem.data) !== null && _draggedItem$data !== void 0 && _draggedItem$data.isContainer)) {
105
131
  backgroundColor = '#F7F589';
106
132
  }
107
133
 
108
- // console.log('sameCard, canDrop', sameCard, canDrop);
109
- return connectDropTarget(/*#__PURE__*/_react["default"].createElement("div", {
110
- style: !sameCard ? getStyle(backgroundColor) : getStyle('rgba(0, 0, 0, .03')
111
- }, !element && /*#__PURE__*/_react["default"].createElement("span", null, "Drop your element here "), element));
112
- });
113
- var _default = exports["default"] = (0, _reactDnd.DropTarget)(function (props) {
114
- return props.accepts;
115
- }, {
116
- drop: function drop(props, monitor, component) {
117
- if (!component) {
118
- return;
119
- }
120
-
121
- // //Do nothing whith busy dustbin
122
- // if(props.items[props.col]) return;
123
- // Allow swap column if target and source are in same multi column row
124
- var isBusy = !!props.items[props.col];
125
- var item = monitor.getItem();
126
-
127
- // Do nothing when moving the box inside the same column
128
- if (props.col === item.col && props.items[props.col] === item.id) return;
129
-
130
- // Do not allow replace component other than both items in same multi column row
131
- if (item.col === undefined && props.items[props.col]) {
132
- _store["default"].dispatch('resetLastItem');
133
- return;
134
- }
135
- if (!isContainer(item)) {
136
- component.onDrop(item);
137
- console.log("calling on Drop from 137", item);
138
- if (item.data && typeof props.setAsChild === 'function') {
139
- var isNew = !item.data.id;
140
- var data = isNew ? item.onCreate(item.data) : item.data;
141
- props.setAsChild(props.data, data, props.col, isBusy);
142
- }
143
- }
144
- }
145
- }, function (connect, monitor) {
146
- return {
147
- connectDropTarget: connect.dropTarget(),
148
- draggedItem: monitor.getItem() ? monitor.getItem() : null,
149
- isOver: monitor.isOver(),
150
- isOverCurrent: monitor.isOver({
151
- shallow: true
152
- }),
153
- canDrop: monitor.canDrop()
154
- };
155
- })(Dustbin);
134
+ // Connect the drop ref to the DOM element
135
+ drop(dropRef);
136
+ return /*#__PURE__*/_react["default"].createElement("div", {
137
+ ref: dropRef,
138
+ style: !sameCard ? getStyle(backgroundColor) : getStyle('rgba(0, 0, 0, .03)')
139
+ }, !element && /*#__PURE__*/_react["default"].createElement("span", null, "Drop your element here"), element);
140
+ };
141
+ var _default = exports["default"] = Dustbin;