@rhc-shared-components/rich-text-editor 0.3.0 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -123,6 +123,24 @@ var InsertCss$1 = function InsertCss() {
123
123
  }
124
124
  };
125
125
 
126
+ function _extends() {
127
+ _extends = Object.assign || function (target) {
128
+ for (var i = 1; i < arguments.length; i++) {
129
+ var source = arguments[i];
130
+
131
+ for (var key in source) {
132
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
133
+ target[key] = source[key];
134
+ }
135
+ }
136
+ }
137
+
138
+ return target;
139
+ };
140
+
141
+ return _extends.apply(this, arguments);
142
+ }
143
+
126
144
  function _objectWithoutPropertiesLoose$1(source, excluded) {
127
145
  if (source == null) return {};
128
146
  var target = {};
@@ -212,17 +230,21 @@ var RichTextEditorFormComponent = function RichTextEditorFormComponent(_ref) {
212
230
  var _useFormikContext = formik.useFormikContext(),
213
231
  isSubmitting = _useFormikContext.isSubmitting,
214
232
  setFieldValue = _useFormikContext.setFieldValue,
215
- validateField = _useFormikContext.validateField;
233
+ validateField = _useFormikContext.validateField,
234
+ setTouched = _useFormikContext.setTouched,
235
+ touched = _useFormikContext.touched;
216
236
 
217
237
  var _React$useState = React__namespace.useState(maxLength || 0),
218
238
  numberOfCharacters = _React$useState[0],
219
239
  setNoOfCharacters = _React$useState[1];
220
240
 
221
241
  React__namespace.useEffect(function () {
222
- setNoOfCharacters(value && value.length && maxLength ? maxLength - value.length : 0);
242
+ if (maxLength) {
243
+ setNoOfCharacters(value && value.length ? maxLength - value.length : maxLength);
244
+ }
223
245
  }, [value, maxLength]);
224
246
  return React__namespace.createElement(FormGroupContainer, {
225
- validated: meta.error ? reactCore.ValidatedOptions.error : reactCore.ValidatedOptions["default"],
247
+ validated: meta.touched && meta.error ? reactCore.ValidatedOptions.error : reactCore.ValidatedOptions["default"],
226
248
  onClick: function onClick() {
227
249
  if (editorRef) {
228
250
  // @ts-ignore
@@ -239,6 +261,7 @@ var RichTextEditorFormComponent = function RichTextEditorFormComponent(_ref) {
239
261
  id: rest.name,
240
262
  name: rest.name,
241
263
  onReady: function onReady(editor) {
264
+ editor.setData(value);
242
265
  editorRef.current = editor;
243
266
  },
244
267
  disabled: disabled || isSubmitting,
@@ -247,13 +270,16 @@ var RichTextEditorFormComponent = function RichTextEditorFormComponent(_ref) {
247
270
  validateField(rest.name);
248
271
  },
249
272
  onBlur: function onBlur(data) {
273
+ var _extends2;
274
+
275
+ setTouched(_extends({}, touched, (_extends2 = {}, _extends2[rest.name] = true, _extends2)));
250
276
  setFieldValue(rest.name, data);
251
277
  validateField(rest.name);
252
278
  }
253
279
  }), showMaxLengthText && React__namespace.createElement("div", {
254
280
  "data-testid": 'formTextAreaMaxLengthText',
255
281
  className: 'max-char-length' + (numberOfCharacters < 0 ? ' maxlength-error' : '')
256
- }, numberOfCharacters, " character", numberOfCharacters !== 1 && 's', ' ', "remaining"));
282
+ }, numberOfCharacters, " character", numberOfCharacters !== 1 && 's', ' ', "remaining (includes HTML markup)"));
257
283
  };
258
284
 
259
285
  exports.RichTextEditor = RichTextEditor;
@@ -100,6 +100,24 @@ const InsertCss$1 = () => {
100
100
  }
101
101
  };
102
102
 
103
+ function _extends() {
104
+ _extends = Object.assign || function (target) {
105
+ for (var i = 1; i < arguments.length; i++) {
106
+ var source = arguments[i];
107
+
108
+ for (var key in source) {
109
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
110
+ target[key] = source[key];
111
+ }
112
+ }
113
+ }
114
+
115
+ return target;
116
+ };
117
+
118
+ return _extends.apply(this, arguments);
119
+ }
120
+
103
121
  function _objectWithoutPropertiesLoose$1(source, excluded) {
104
122
  if (source == null) return {};
105
123
  var target = {};
@@ -193,14 +211,18 @@ const RichTextEditorFormComponent = _ref => {
193
211
  const {
194
212
  isSubmitting,
195
213
  setFieldValue,
196
- validateField
214
+ validateField,
215
+ setTouched,
216
+ touched
197
217
  } = useFormikContext();
198
218
  const [numberOfCharacters, setNoOfCharacters] = React.useState(maxLength || 0);
199
219
  React.useEffect(() => {
200
- setNoOfCharacters(value && value.length && maxLength ? maxLength - value.length : 0);
220
+ if (maxLength) {
221
+ setNoOfCharacters(value && value.length ? maxLength - value.length : maxLength);
222
+ }
201
223
  }, [value, maxLength]);
202
224
  return React.createElement(FormGroupContainer, {
203
- validated: meta.error ? ValidatedOptions.error : ValidatedOptions.default,
225
+ validated: meta.touched && meta.error ? ValidatedOptions.error : ValidatedOptions.default,
204
226
  onClick: () => {
205
227
  if (editorRef) {
206
228
  // @ts-ignore
@@ -217,6 +239,7 @@ const RichTextEditorFormComponent = _ref => {
217
239
  id: rest.name,
218
240
  name: rest.name,
219
241
  onReady: editor => {
242
+ editor.setData(value);
220
243
  editorRef.current = editor;
221
244
  },
222
245
  disabled: disabled || isSubmitting,
@@ -225,13 +248,16 @@ const RichTextEditorFormComponent = _ref => {
225
248
  validateField(rest.name);
226
249
  },
227
250
  onBlur: data => {
251
+ setTouched(_extends({}, touched, {
252
+ [rest.name]: true
253
+ }));
228
254
  setFieldValue(rest.name, data);
229
255
  validateField(rest.name);
230
256
  }
231
257
  }), showMaxLengthText && React.createElement("div", {
232
258
  "data-testid": 'formTextAreaMaxLengthText',
233
259
  className: 'max-char-length' + (numberOfCharacters < 0 ? ' maxlength-error' : '')
234
- }, numberOfCharacters, " character", numberOfCharacters !== 1 && 's', ' ', "remaining"));
260
+ }, numberOfCharacters, " character", numberOfCharacters !== 1 && 's', ' ', "remaining (includes HTML markup)"));
235
261
  };
236
262
 
237
263
  export { RichTextEditor, RichTextEditorFormComponent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhc-shared-components/rich-text-editor",
3
- "version": "0.3.0",
3
+ "version": "0.3.3",
4
4
  "description": "WYSWYG Editor for Red Hat Certified Apps",
5
5
  "author": "gautamkrishnar",
6
6
  "license": "MIT",
@@ -75,6 +75,5 @@
75
75
  "formik": "^2.1.4",
76
76
  "react": "^16.13.1",
77
77
  "react-dom": "^16.13.1"
78
- },
79
- "gitHead": "9b859638f0e80c5a77f3660defbe00edcab15840"
78
+ }
80
79
  }