@goldenpine/react-form-builder2 0.18.4-patch.1 → 0.20.3-build.1

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.
@@ -91,10 +91,11 @@ var DynamicOptionList = /*#__PURE__*/function (_React$Component) {
91
91
  key: "addOption",
92
92
  value: function addOption(index) {
93
93
  var this_element = this.state.element;
94
+ var groupKey = this_element.element.toLowerCase();
94
95
  this_element.options.splice(index + 1, 0, {
95
96
  value: '',
96
97
  text: '',
97
- key: _UUID["default"].uuid()
98
+ key: "".concat(groupKey, "_option_").concat(_UUID["default"].uuid())
98
99
  });
99
100
  this.props.updateElement.call(this.props.preview, this_element);
100
101
  }
@@ -6,86 +6,62 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports["default"] = void 0;
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
14
10
  var _react = _interopRequireWildcard(require("react"));
15
11
  var _reactDnd = require("react-dnd");
16
12
  var _reactDndHtml5Backend = require("react-dnd-html5-backend");
17
13
  var _ItemTypes = _interopRequireDefault(require("../ItemTypes"));
18
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
21
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
22
16
  var style = {
23
- // display: 'inline-block',
24
- // border: '1px dashed gray',
25
- // padding: '0.5rem 1rem',
26
- // backgroundColor: 'white',
27
17
  cursor: 'move'
28
18
  };
29
- var dragHandleSource = {
30
- beginDrag: function beginDrag(props) {
31
- var data = props.data,
32
- index = props.index,
33
- onDestroy = props.onDestroy,
34
- setAsChild = props.setAsChild,
35
- getDataById = props.getDataById;
36
- return {
37
- itemType: _ItemTypes["default"].BOX,
38
- index: data.parentId ? -1 : index,
39
- parentIndex: data.parentIndex,
40
- id: data.id,
41
- col: data.col,
42
- onDestroy: onDestroy,
43
- setAsChild: setAsChild,
44
- getDataById: getDataById,
45
- data: data
46
- };
47
- }
48
- };
49
- var DragHandle = /*#__PURE__*/function (_PureComponent) {
50
- (0, _inherits2["default"])(DragHandle, _PureComponent);
51
- var _super = _createSuper(DragHandle);
52
- function DragHandle() {
53
- (0, _classCallCheck2["default"])(this, DragHandle);
54
- return _super.apply(this, arguments);
55
- }
56
- (0, _createClass2["default"])(DragHandle, [{
57
- key: "componentDidMount",
58
- value: function componentDidMount() {
59
- var connectDragPreview = this.props.connectDragPreview;
60
- if (connectDragPreview) {
61
- // Use empty image as a drag preview so browsers don't draw it
62
- // and we can draw whatever we want on the custom drag layer instead.
63
- connectDragPreview((0, _reactDndHtml5Backend.getEmptyImage)(), {
64
- // IE fallback: specify that we'd rather screenshot the node
65
- // when it already knows it's being dragged so we can hide it with CSS.
66
- captureDraggingState: true
67
- });
19
+ var DragHandle = function DragHandle(props) {
20
+ var data = props.data,
21
+ index = props.index,
22
+ onDestroy = props.onDestroy,
23
+ setAsChild = props.setAsChild,
24
+ getDataById = props.getDataById;
25
+ var _useDrag = (0, _reactDnd.useDrag)({
26
+ type: _ItemTypes["default"].BOX,
27
+ item: function item() {
28
+ return {
29
+ itemType: _ItemTypes["default"].BOX,
30
+ index: data.parentId ? -1 : index,
31
+ parentIndex: data.parentIndex,
32
+ id: data.id,
33
+ col: data.col,
34
+ onDestroy: onDestroy,
35
+ setAsChild: setAsChild,
36
+ getDataById: getDataById,
37
+ data: data
38
+ };
39
+ },
40
+ collect: function collect(monitor) {
41
+ return {
42
+ isDragging: monitor.isDragging()
43
+ };
68
44
  }
69
- }
70
- }, {
71
- key: "render",
72
- value: function render() {
73
- var connectDragSource = this.props.connectDragSource;
74
- return connectDragSource(/*#__PURE__*/_react["default"].createElement("div", {
75
- className: "btn is-isolated",
76
- style: style
77
- }, /*#__PURE__*/_react["default"].createElement("i", {
78
- className: "is-isolated fas fa-grip-vertical"
79
- })));
80
- }
81
- }]);
82
- return DragHandle;
83
- }(_react.PureComponent);
84
- var _default = (0, _reactDnd.DragSource)(_ItemTypes["default"].BOX, dragHandleSource, function (connect, monitor) {
85
- return {
86
- connectDragSource: connect.dragSource(),
87
- connectDragPreview: connect.dragPreview(),
88
- isDragging: monitor.isDragging()
89
- };
90
- })(DragHandle);
45
+ }),
46
+ _useDrag2 = (0, _slicedToArray2["default"])(_useDrag, 3),
47
+ dragRef = _useDrag2[1],
48
+ dragPreviewRef = _useDrag2[2];
49
+
50
+ // Use empty image as drag preview
51
+ (0, _react.useEffect)(function () {
52
+ dragPreviewRef((0, _reactDndHtml5Backend.getEmptyImage)(), {
53
+ // IE fallback: specify that we'd rather screenshot the node
54
+ // when it already knows it's being dragged so we can hide it with CSS.
55
+ captureDraggingState: true
56
+ });
57
+ }, [dragPreviewRef]);
58
+ return /*#__PURE__*/_react["default"].createElement("div", {
59
+ ref: dragRef,
60
+ className: "btn is-isolated",
61
+ style: style
62
+ }, /*#__PURE__*/_react["default"].createElement("i", {
63
+ className: "is-isolated fas fa-grip-vertical"
64
+ }));
65
+ };
66
+ var _default = DragHandle;
91
67
  exports["default"] = _default;
@@ -18,9 +18,7 @@ var layerStyles = {
18
18
  width: '100%',
19
19
  height: '100%'
20
20
  };
21
- function getItemStyles(props) {
22
- var initialOffset = props.initialOffset,
23
- currentOffset = props.currentOffset;
21
+ function getItemStyles(initialOffset, currentOffset) {
24
22
  if (!initialOffset || !currentOffset) {
25
23
  return {
26
24
  display: 'none'
@@ -34,10 +32,21 @@ function getItemStyles(props) {
34
32
  WebkitTransform: transform
35
33
  };
36
34
  }
37
- var CustomDragLayer = function CustomDragLayer(props) {
38
- var item = props.item,
39
- itemType = props.itemType,
40
- isDragging = props.isDragging;
35
+ var CustomDragLayer = function CustomDragLayer() {
36
+ var _useDragLayer = (0, _reactDnd.useDragLayer)(function (monitor) {
37
+ return {
38
+ item: monitor.getItem(),
39
+ itemType: monitor.getItemType(),
40
+ initialOffset: monitor.getInitialSourceClientOffset(),
41
+ currentOffset: monitor.getSourceClientOffset(),
42
+ isDragging: monitor.isDragging()
43
+ };
44
+ }),
45
+ itemType = _useDragLayer.itemType,
46
+ isDragging = _useDragLayer.isDragging,
47
+ item = _useDragLayer.item,
48
+ initialOffset = _useDragLayer.initialOffset,
49
+ currentOffset = _useDragLayer.currentOffset;
41
50
  function renderItem() {
42
51
  switch (itemType) {
43
52
  case _ItemTypes["default"].BOX:
@@ -54,16 +63,8 @@ var CustomDragLayer = function CustomDragLayer(props) {
54
63
  return /*#__PURE__*/_react["default"].createElement("div", {
55
64
  style: layerStyles
56
65
  }, /*#__PURE__*/_react["default"].createElement("div", {
57
- style: getItemStyles(props)
66
+ style: getItemStyles(initialOffset, currentOffset)
58
67
  }, renderItem()));
59
68
  };
60
- var _default = (0, _reactDnd.DragLayer)(function (monitor) {
61
- return {
62
- item: monitor.getItem(),
63
- itemType: monitor.getItemType(),
64
- initialOffset: monitor.getInitialSourceClientOffset(),
65
- currentOffset: monitor.getSourceClientOffset(),
66
- isDragging: monitor.isDragging()
67
- };
68
- })(CustomDragLayer);
69
+ var _default = CustomDragLayer;
69
70
  exports["default"] = _default;
@@ -12,7 +12,7 @@ var _react = _interopRequireWildcard(require("react"));
12
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
13
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
14
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } /* eslint-disable no-nested-ternary */ /* eslint-disable import/prefer-default-export */ /* eslint-disable no-unused-vars */
16
16
  var boxStyles = {
17
17
  border: '1px dashed gray',
18
18
  padding: '0.5rem 1rem',
@@ -42,14 +42,6 @@ var BoxDragPreview = function BoxDragPreview(_ref2) {
42
42
  var text = item.data.content ? item.data.content : item.data.label ? item.data.label : item.data.text;
43
43
  var isLongText = text.length > 20;
44
44
  var previewText = isLongText ? "".concat(text.slice(0, 20), "...") : text;
45
-
46
- // useEffect(function subscribeToIntervalTick() {
47
- // const interval = setInterval(() => {
48
- // setTickTock(!tickTock);
49
- // }, 500);
50
- // return () => clearInterval(interval);
51
- // }, [tickTock]);
52
-
53
45
  return /*#__PURE__*/_react["default"].createElement("div", {
54
46
  style: styles,
55
47
  role: "BoxPreview"
@@ -14,8 +14,8 @@ var _react = _interopRequireDefault(require("react"));
14
14
  var _componentDragHandle = _interopRequireDefault(require("./component-drag-handle"));
15
15
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
16
16
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /**
17
- * <HeaderBar />
18
- */ // import Grip from '../multi-column/grip';
17
+ * <HeaderBar />
18
+ */ // import Grip from '../multi-column/grip';
19
19
  var HeaderBar = /*#__PURE__*/function (_React$Component) {
20
20
  (0, _inherits2["default"])(HeaderBar, _React$Component);
21
21
  var _super = _createSuper(HeaderBar);
@@ -29,7 +29,7 @@ var _myxss = _interopRequireDefault(require("./myxss"));
29
29
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
30
30
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
31
31
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
32
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } // eslint-disable-next-line max-classes-per-file
32
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /* eslint-disable quote-props */ // eslint-disable-next-line max-classes-per-file
33
33
  var FormElements = {};
34
34
  var Header = /*#__PURE__*/function (_React$Component) {
35
35
  (0, _inherits2["default"])(Header, _React$Component);
@@ -923,7 +923,7 @@ var FileUpload = /*#__PURE__*/function (_React$Component20) {
923
923
  return (0, _isomorphicFetch["default"])(sourceUrl, {
924
924
  method: 'GET',
925
925
  headers: {
926
- Accept: 'application/json',
926
+ 'Accept': 'application/json',
927
927
  'Content-Type': 'application/json; charset=utf-8'
928
928
  },
929
929
  responseType: 'blob'
@@ -8,12 +8,12 @@ exports["default"] = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
11
12
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12
13
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
14
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
15
  var _react = _interopRequireDefault(require("react"));
15
16
  var _propTypes = _interopRequireDefault(require("prop-types"));
16
- var _reactDom = _interopRequireDefault(require("react-dom"));
17
17
  var _classnames = _interopRequireDefault(require("classnames"));
18
18
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
19
19
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
@@ -40,6 +40,15 @@ var StarRating = /*#__PURE__*/function (_React$Component) {
40
40
  _this = _super.call(this, props);
41
41
  _this.min = 0;
42
42
  _this.max = props.ratingAmount || 5;
43
+
44
+ // Pre-bind methods to avoid creating new functions on each render
45
+ _this.handleMouseLeave = _this.handleMouseLeave.bind((0, _assertThisInitialized2["default"])(_this));
46
+ _this.handleMouseMove = _this.handleMouseMove.bind((0, _assertThisInitialized2["default"])(_this));
47
+ _this.handleClick = _this.handleClick.bind((0, _assertThisInitialized2["default"])(_this));
48
+
49
+ // Create refs properly
50
+ _this.rootNode = /*#__PURE__*/_react["default"].createRef();
51
+ _this.ratingContainerNode = /*#__PURE__*/_react["default"].createRef();
43
52
  var ratingVal = props.rating;
44
53
  var ratingCache = {
45
54
  pos: ratingVal ? _this.getStarRatingPosition(ratingVal) : 0,
@@ -70,39 +79,24 @@ var StarRating = /*#__PURE__*/function (_React$Component) {
70
79
  }
71
80
  return stars;
72
81
  }
73
-
74
- // componentWillMount() {
75
- // this.min = 0;
76
- // this.max = this.props.ratingAmount || 5;
77
- // if (this.props.rating) {
78
- // this.state.editing = this.props.editing || false;
79
- // const ratingVal = this.props.rating;
80
- // this.state.ratingCache.pos = this.getStarRatingPosition(ratingVal);
81
- // this.state.ratingCache.rating = ratingVal;
82
-
83
- // this.setState({
84
- // ratingCache: this.state.ratingCache,
85
- // rating: ratingVal,
86
- // pos: this.getStarRatingPosition(ratingVal),
87
- // });
88
- // }
89
- // }
90
82
  }, {
91
83
  key: "componentDidMount",
92
84
  value: function componentDidMount() {
93
- this.root = _reactDom["default"].findDOMNode(this.rootNode);
94
- this.ratingContainer = _reactDom["default"].findDOMNode(this.node);
95
- }
96
- }, {
97
- key: "componentWillUnmount",
98
- value: function componentWillUnmount() {
99
- delete this.root;
100
- delete this.ratingContainer;
85
+ // Initialize with proper values from props
86
+ if (this.props.rating) {
87
+ this.setState({
88
+ pos: this.getStarRatingPosition(this.props.rating),
89
+ rating: this.props.rating
90
+ });
91
+ }
101
92
  }
93
+
94
+ // REMOVED componentWillUnmount as it wasn't doing anything useful
102
95
  }, {
103
96
  key: "getPosition",
104
97
  value: function getPosition(e) {
105
- return e.pageX - this.root.getBoundingClientRect().left;
98
+ if (!this.rootNode.current) return 0;
99
+ return e.pageX - this.rootNode.current.getBoundingClientRect().left;
106
100
  }
107
101
  }, {
108
102
  key: "applyPrecision",
@@ -118,6 +112,7 @@ var StarRating = /*#__PURE__*/function (_React$Component) {
118
112
  }, {
119
113
  key: "getWidthFromValue",
120
114
  value: function getWidthFromValue(val) {
115
+ if (val === null || val === undefined || typeof val !== 'number') return 0;
121
116
  var min = this.min;
122
117
  var max = this.max;
123
118
  if (val <= min || min === max) {
@@ -126,13 +121,15 @@ var StarRating = /*#__PURE__*/function (_React$Component) {
126
121
  if (val >= max) {
127
122
  return 100;
128
123
  }
129
- return val / (max - min) * 100;
124
+ return (val - min) / (max - min) * 100;
130
125
  }
131
126
  }, {
132
127
  key: "getValueFromPosition",
133
128
  value: function getValueFromPosition(pos) {
129
+ if (!this.ratingContainerNode.current) return 0;
134
130
  var precision = this.getDecimalPlaces(this.props.step);
135
- var maxWidth = this.ratingContainer.offsetWidth;
131
+ var maxWidth = this.ratingContainerNode.current.offsetWidth;
132
+ if (!maxWidth) return 0;
136
133
  var diff = this.max - this.min;
137
134
  var factor = diff * pos / (maxWidth * this.props.step);
138
135
  factor = Math.ceil(factor);
@@ -144,8 +141,7 @@ var StarRating = /*#__PURE__*/function (_React$Component) {
144
141
  key: "calculate",
145
142
  value: function calculate(pos) {
146
143
  var val = this.getValueFromPosition(pos);
147
- var width = this.getWidthFromValue(val);
148
- width += '%';
144
+ var width = "".concat(this.getWidthFromValue(val), "%");
149
145
  return {
150
146
  width: width,
151
147
  val: val
@@ -173,9 +169,9 @@ var StarRating = /*#__PURE__*/function (_React$Component) {
173
169
  xmlns: "http://www.w3.org/2000/svg"
174
170
  }, /*#__PURE__*/_react["default"].createElement("g", {
175
171
  stroke: "none",
176
- "stroke-width": "1",
172
+ strokeWidth: "1",
177
173
  fill: "none",
178
- "fill-rule": "evenodd"
174
+ fillRule: "evenodd"
179
175
  }, /*#__PURE__*/_react["default"].createElement("polygon", {
180
176
  id: "star-flat",
181
177
  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 "
@@ -192,26 +188,46 @@ var StarRating = /*#__PURE__*/function (_React$Component) {
192
188
  }, {
193
189
  key: "handleMouseMove",
194
190
  value: function handleMouseMove(e) {
195
- // get hover position
196
- var ratingEvent = this.getRatingEvent(e);
197
- this.updateRating(ratingEvent.width, ratingEvent.val);
198
- }
199
- }, {
200
- key: "updateRating",
201
- value: function updateRating(width, val) {
202
- this.setState({
203
- pos: width,
204
- rating: val
205
- });
191
+ // Only process if editing is enabled
192
+ if (!this.props.disabled && (this.state.editing || this.props.editing)) {
193
+ // get hover position
194
+ var ratingEvent = this.getRatingEvent(e);
195
+ this.setState({
196
+ pos: ratingEvent.width,
197
+ rating: ratingEvent.val
198
+ });
199
+ }
206
200
  }
201
+
202
+ // REMOVED updateRating method which was causing issues
203
+
204
+ // Fixed shouldComponentUpdate to prevent infinite loops
207
205
  }, {
208
206
  key: "shouldComponentUpdate",
209
207
  value: function shouldComponentUpdate(nextProps, nextState) {
210
- if (nextProps !== this.props) {
211
- this.updateRating(this.getStarRatingPosition(nextProps.rating), nextProps.rating);
208
+ // Don't trigger a state update from this method!
209
+ if (nextProps.rating !== this.props.rating) {
212
210
  return true;
213
211
  }
214
- return nextState.ratingCache.rating !== this.state.ratingCache.rating || nextState.rating !== this.state.rating;
212
+ return nextState.ratingCache.rating !== this.state.ratingCache.rating || nextState.rating !== this.state.rating || nextState.pos !== this.state.pos;
213
+ }
214
+
215
+ // Handle rating changes in componentDidUpdate instead
216
+ }, {
217
+ key: "componentDidUpdate",
218
+ value: function componentDidUpdate(prevProps) {
219
+ // Only update if the rating prop changed
220
+ if (prevProps.rating !== this.props.rating && this.props.rating !== this.state.rating) {
221
+ // Update state without causing an infinite loop
222
+ this.setState({
223
+ pos: this.getStarRatingPosition(this.props.rating),
224
+ rating: this.props.rating,
225
+ ratingCache: {
226
+ pos: this.getStarRatingPosition(this.props.rating),
227
+ rating: this.props.rating
228
+ }
229
+ });
230
+ }
215
231
  }
216
232
  }, {
217
233
  key: "handleClick",
@@ -222,15 +238,24 @@ var StarRating = /*#__PURE__*/function (_React$Component) {
222
238
  e.preventDefault();
223
239
  return false;
224
240
  }
241
+
242
+ // Get the current rating based on click position
243
+ var ratingEvent = this.getRatingEvent(e);
225
244
  var ratingCache = {
226
- pos: this.state.pos,
227
- rating: this.state.rating,
245
+ pos: ratingEvent.width,
246
+ rating: ratingEvent.val,
228
247
  caption: this.props.caption,
229
248
  name: this.props.name
230
249
  };
250
+
251
+ // Update the state with new values
231
252
  this.setState({
232
- ratingCache: ratingCache
253
+ ratingCache: ratingCache,
254
+ pos: ratingEvent.width,
255
+ rating: ratingEvent.val
233
256
  });
257
+
258
+ // Call the callback with the new rating
234
259
  this.props.onRatingClick(e, ratingCache);
235
260
  return true;
236
261
  }
@@ -245,31 +270,23 @@ var StarRating = /*#__PURE__*/function (_React$Component) {
245
270
  }, {
246
271
  key: "render",
247
272
  value: function render() {
248
- var _cx,
249
- _this2 = this;
250
- // let caption = null;
273
+ var _cx;
251
274
  var classes = (0, _classnames["default"])((_cx = {
252
275
  'react-star-rating__root': true,
253
276
  'rating-disabled': this.props.disabled
254
277
  }, (0, _defineProperty2["default"])(_cx, "react-star-rating__size--".concat(this.props.size), this.props.size), (0, _defineProperty2["default"])(_cx, 'rating-editing', this.state.editing), _cx));
255
278
 
256
- // is there a caption?
257
- // if (this.props.caption) {
258
- // caption = (<span className="react-rating-caption">{this.props.caption}</span>);
259
- // }
260
-
261
279
  // are we editing this rating?
262
280
  var starRating;
263
- if (this.state.editing) {
281
+ var isEditable = !this.props.disabled && (this.state.editing || this.props.editing);
282
+ if (isEditable) {
264
283
  starRating = /*#__PURE__*/_react["default"].createElement("div", {
265
- ref: function ref(c) {
266
- return _this2.node = c;
267
- },
284
+ ref: this.ratingContainerNode,
268
285
  className: "rating-container rating-gly-star",
269
286
  "data-content": this.state.glyph,
270
- onMouseMove: this.handleMouseMove.bind(this),
271
- onMouseLeave: this.handleMouseLeave.bind(this),
272
- onClick: this.handleClick.bind(this)
287
+ onMouseMove: this.handleMouseMove,
288
+ onMouseLeave: this.handleMouseLeave,
289
+ onClick: this.handleClick
273
290
  }, /*#__PURE__*/_react["default"].createElement("div", {
274
291
  className: "rating-stars",
275
292
  "data-content": this.state.glyph,
@@ -279,9 +296,7 @@ var StarRating = /*#__PURE__*/function (_React$Component) {
279
296
  }));
280
297
  } else {
281
298
  starRating = /*#__PURE__*/_react["default"].createElement("div", {
282
- ref: function ref(c) {
283
- return _this2.node = c;
284
- },
299
+ ref: this.ratingContainerNode,
285
300
  className: "rating-container rating-gly-star",
286
301
  "data-content": this.state.glyph
287
302
  }, /*#__PURE__*/_react["default"].createElement("div", {
@@ -295,26 +310,23 @@ var StarRating = /*#__PURE__*/function (_React$Component) {
295
310
  return /*#__PURE__*/_react["default"].createElement("span", {
296
311
  className: "react-star-rating"
297
312
  }, /*#__PURE__*/_react["default"].createElement("span", {
298
- ref: function ref(c) {
299
- return _this2.rootNode = c;
300
- },
313
+ ref: this.rootNode,
301
314
  style: {
302
- cursor: 'pointer'
315
+ cursor: isEditable ? 'pointer' : 'default'
303
316
  },
304
317
  className: classes
305
- }, starRating, /*#__PURE__*/_react["default"].createElement("input", (0, _defineProperty2["default"])({
318
+ }, starRating, /*#__PURE__*/_react["default"].createElement("input", {
306
319
  type: "hidden",
307
320
  name: this.props.name,
308
- value: this.state.ratingCache.rating,
321
+ value: this.state.rating || 0,
309
322
  style: {
310
- display: 'none !important'
323
+ display: 'none !important',
324
+ width: 65
311
325
  },
312
326
  min: this.min,
313
327
  max: this.max,
314
328
  readOnly: true
315
- }, "style", {
316
- width: 65
317
- }))));
329
+ })));
318
330
  }
319
331
  }]);
320
332
  return StarRating;
@@ -68,9 +68,8 @@ var FormElementsEdit = /*#__PURE__*/function (_React$Component) {
68
68
  }, {
69
69
  key: "onEditorStateChange",
70
70
  value: function onEditorStateChange(index, property, editorContent) {
71
- var html = (0, _draftjsToHtml["default"])((0, _draftJs.convertToRaw)(editorContent.getCurrentContent())).replace(/<p>/g, '<div>').replace(/<\/p>/g, '</div>');
72
- //const html = draftToHtml(convertToRaw(editorContent.getCurrentContent())).replace(/<p>/g, '').replace(/<\/p>/g, '').replace(/&nbsp;/g, ' ')
73
- // .replace(/(?:\r\n|\r|\n)/g, ' ');
71
+ // const html = draftToHtml(convertToRaw(editorContent.getCurrentContent())).replace(/<p>/g, '<div>').replace(/<\/p>/g, '</div>');
72
+ var html = (0, _draftjsToHtml["default"])((0, _draftJs.convertToRaw)(editorContent.getCurrentContent())).replace(/<p>/g, '').replace(/<\/p>/g, '').replace(/&nbsp;/g, ' ').replace(/(?:\r\n|\r|\n)/g, ' ');
74
73
  var this_element = this.state.element;
75
74
  this_element[property] = html;
76
75
  this.setState({