@desynova-digital/components 9.0.9 → 9.0.11

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.
@@ -60,7 +60,8 @@ var DraftInputText = function DraftInputText(_ref) {
60
60
  label = _ref.label,
61
61
  value = _ref.value,
62
62
  autoFocus = _ref.autoFocus,
63
- props = _objectWithoutProperties(_ref, ['maxLength', 'defaultValue', 'type', 'showLengthCount', 'label', 'value', 'autoFocus']);
63
+ isFocused = _ref.isFocused,
64
+ props = _objectWithoutProperties(_ref, ['maxLength', 'defaultValue', 'type', 'showLengthCount', 'label', 'value', 'autoFocus', 'isFocused']);
64
65
 
65
66
  var _useState = (0, _react.useState)(true),
66
67
  _useState2 = _slicedToArray(_useState, 2),
@@ -72,7 +73,7 @@ var DraftInputText = function DraftInputText(_ref) {
72
73
  diff = _useState4[0],
73
74
  setDiff = _useState4[1];
74
75
 
75
- var _useState5 = (0, _react.useState)(autoFocus),
76
+ var _useState5 = (0, _react.useState)(false),
76
77
  _useState6 = _slicedToArray(_useState5, 2),
77
78
  focus = _useState6[0],
78
79
  setFocus = _useState6[1];
@@ -242,7 +243,9 @@ var DraftInputText = function DraftInputText(_ref) {
242
243
  return match === '<em>' ? '<i>' : '</i>';
243
244
  });
244
245
  };
245
-
246
+ /**
247
+ * this useEffect is used to send value to parent component as soon as editor state gets updated
248
+ */
246
249
  (0, _react.useEffect)(function () {
247
250
  var html = (0, _draftConvert.convertToHTML)(editorState.getCurrentContent());
248
251
  html = removeOuterPTag(html);
@@ -256,19 +259,31 @@ var DraftInputText = function DraftInputText(_ref) {
256
259
  }
257
260
  }, [editorState]);
258
261
 
262
+ /**
263
+ * This useEffect handles our focus condition and also updates state when the props value changes
264
+ */
259
265
  (0, _react.useEffect)(function () {
260
266
  if (diff && value !== '' && value !== undefined) {
261
267
  props.simpleEdit = true;
262
268
  setDiff(false);
263
- setFocus(true);
264
269
  var dummy = (0, _draftConvert.convertFromHTML)(value);
265
270
  var newState = _draftJs.EditorState.createWithContent(dummy);
266
- setEditorState(function () {
267
- return _draftJs.EditorState.moveFocusToEnd(newState);
268
- });
271
+
272
+ if (focus) {
273
+ isFocused = true;
274
+ }
275
+ if (isFocused) {
276
+ setEditorState(function () {
277
+ return _draftJs.EditorState.moveFocusToEnd(newState);
278
+ });
279
+ } else {
280
+ setEditorState(newState);
281
+ }
269
282
  }
270
283
  }, [value]);
271
-
284
+ /**
285
+ * This useEffect is used to chnage our value when timeline is changed
286
+ */
272
287
  (0, _react.useEffect)(function () {
273
288
  if (listScrollTop !== null) {
274
289
  if (!props.simpleEdit) {
@@ -281,11 +296,15 @@ var DraftInputText = function DraftInputText(_ref) {
281
296
  }
282
297
  }, [listScrollTop]);
283
298
 
299
+ /**
300
+ * This useEffect is used to focus on Line1 when a new segment is created
301
+ */
284
302
  (0, _react.useEffect)(function () {
285
303
  if (autoFocus) {
286
304
  editorRef.current.focus();
287
305
  }
288
306
  }, [autoFocus]);
307
+
289
308
  return _react2.default.createElement(
290
309
  DraftInputTextDiv,
291
310
  { theme: props.theme, inputWidth: props.inputWidth },
@@ -424,11 +443,13 @@ DraftInputText.propTypes = {
424
443
  showLengthCount: _propTypes2.default.bool,
425
444
  simpleEdit: _propTypes2.default.bool,
426
445
  autoFocus: _propTypes2.default.bool,
446
+ isFocused: _propTypes2.default.bool,
427
447
  theme: _propTypes2.default.oneOf(['light', 'dark', 'nexc']),
428
448
  fieldType: _propTypes2.default.oneOf(['inputField', 'textArea'])
429
449
  };
430
450
 
431
451
  DraftInputText.defaultProps = {
452
+ isFocused: false,
432
453
  autoFocus: false,
433
454
  fieldType: 'textArea',
434
455
  readOnly: false,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@desynova-digital/components",
3
- "version": "9.0.9",
3
+ "version": "9.0.11",
4
4
  "description": "Components for Desynova Digital",
5
5
  "main": "index.js",
6
6
  "author": "desynova-digital",
7
7
  "license": "MIT",
8
8
  "repository": "desynova-digital",
9
9
  "dependencies": {
10
- "@desynova-digital/tokens": "9.0.9",
10
+ "@desynova-digital/tokens": "9.0.11",
11
11
  "prop-types": "^15.7.2",
12
12
  "styled-components": "^4.3.2"
13
13
  },