@commercetools-uikit/rich-text-input 16.0.0 → 16.1.0

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.
@@ -65,7 +65,6 @@ const EditorWrapper = /*#__PURE__*/_styled__default["default"]("div", process.en
65
65
  })("align-self:stretch;cursor:", props => props.isDisabled || props.isReadOnly ? 'not-allowed' : 'inherit', ";" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImVkaXRvci5zdHlsZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBS3FEIiwiZmlsZSI6ImVkaXRvci5zdHlsZXMudHMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCc7XG5pbXBvcnQgdHlwZSB7IFRFZGl0b3JQcm9wcyB9IGZyb20gJy4vZWRpdG9yJztcblxudHlwZSBURWRpdG9yV3JhcHBlclByb3BzID0gUGljazxURWRpdG9yUHJvcHMsICdpc0Rpc2FibGVkJyB8ICdpc1JlYWRPbmx5Jz47XG5cbmNvbnN0IEVkaXRvcldyYXBwZXIgPSBzdHlsZWQuZGl2PFRFZGl0b3JXcmFwcGVyUHJvcHM+YFxuICBhbGlnbi1zZWxmOiBzdHJldGNoO1xuICBjdXJzb3I6ICR7KHByb3BzKSA9PlxuICAgIHByb3BzLmlzRGlzYWJsZWQgfHwgcHJvcHMuaXNSZWFkT25seSA/ICdub3QtYWxsb3dlZCcgOiAnaW5oZXJpdCd9O1xuYDtcblxuZXhwb3J0IHsgRWRpdG9yV3JhcHBlciB9O1xuIl19 */"));
66
66
 
67
67
  function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
68
-
69
68
  function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
70
69
  const HOTKEYS = {
71
70
  'mod+b': 'bold',
@@ -74,40 +73,33 @@ const HOTKEYS = {
74
73
  'mod+`': 'code'
75
74
  };
76
75
  const COLLAPSED_HEIGHT = 32;
77
-
78
76
  const renderElement = props => jsxRuntime.jsx(richTextUtils.Element, _objectSpread$1({}, props));
79
-
80
77
  const renderLeaf = props => jsxRuntime.jsx(richTextUtils.Leaf, _objectSpread$1({}, props));
81
-
82
78
  const Editor = /*#__PURE__*/react.forwardRef((props, forwardedRef) => {
83
79
  const intl = reactIntl.useIntl();
84
80
  const ref = react.useRef(null);
85
- const createEditorWithPlugins = pipe__default["default"](slateReact.withReact, slateHistory.withHistory); // eslint-disable-next-line react-hooks/exhaustive-deps
86
-
81
+ const createEditorWithPlugins = pipe__default["default"](slateReact.withReact, slateHistory.withHistory);
82
+ // eslint-disable-next-line react-hooks/exhaustive-deps
87
83
  const editor = react.useMemo(() => createEditorWithPlugins(slate.createEditor()), []);
88
-
89
84
  const _useState = react.useState(false),
90
- _useState2 = _slicedToArray(_useState, 2),
91
- renderToggleButton = _useState2[0],
92
- setRenderToggleButton = _useState2[1];
93
-
85
+ _useState2 = _slicedToArray(_useState, 2),
86
+ renderToggleButton = _useState2[0],
87
+ setRenderToggleButton = _useState2[1];
94
88
  const updateRenderToggleButton = react.useCallback(() => {
95
89
  var _ref$current;
96
-
97
90
  const doesExceedCollapsedHeightLimit = Number((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.clientHeight) > COLLAPSED_HEIGHT;
98
-
99
91
  if (doesExceedCollapsedHeightLimit && !renderToggleButton) {
100
92
  setRenderToggleButton(true);
101
93
  }
102
-
103
94
  if (!doesExceedCollapsedHeightLimit && renderToggleButton) {
104
95
  setRenderToggleButton(false);
105
96
  }
106
97
  }, [setRenderToggleButton, renderToggleButton]);
107
98
  react.useEffect(() => {
108
99
  updateRenderToggleButton();
109
- }, [editor, updateRenderToggleButton]); // resetting
100
+ }, [editor, updateRenderToggleButton]);
110
101
 
102
+ // resetting
111
103
  const resetValue = react.useCallback(newValue => {
112
104
  richTextUtils.resetEditor(editor, newValue);
113
105
  }, [editor]);
@@ -117,7 +109,6 @@ const Editor = /*#__PURE__*/react.forwardRef((props, forwardedRef) => {
117
109
  to be called from the parent component.
118
110
  e.g. <button onMouseDown={() => ref.current?.resetValue("<p><strong>Value after reset</strong></p>")}>Reset</button>
119
111
  */
120
-
121
112
  react.useImperativeHandle(forwardedRef, () => {
122
113
  return {
123
114
  resetValue
@@ -128,9 +119,9 @@ const Editor = /*#__PURE__*/react.forwardRef((props, forwardedRef) => {
128
119
  isDefaultClosed: !props.defaultExpandMultilineText,
129
120
  children: _ref => {
130
121
  let isOpen = _ref.isOpen,
131
- toggle = _ref.toggle,
132
- containerStyles = _ref.containerStyles,
133
- registerContentNode = _ref.registerContentNode;
122
+ toggle = _ref.toggle,
123
+ containerStyles = _ref.containerStyles,
124
+ registerContentNode = _ref.registerContentNode;
134
125
  const refObj = {
135
126
  containerRef: ref,
136
127
  registerContentNode
@@ -147,7 +138,8 @@ const Editor = /*#__PURE__*/react.forwardRef((props, forwardedRef) => {
147
138
  editor: editor,
148
139
  value: props.value,
149
140
  onChange: props.onChange,
150
- children: jsxRuntime.jsxs(richTextUtils.RichTextBody // @ts-ignore
141
+ children: jsxRuntime.jsxs(richTextUtils.RichTextBody
142
+ // @ts-ignore
151
143
  , {
152
144
  ref: refObj,
153
145
  hasError: props.hasError,
@@ -168,9 +160,8 @@ const Editor = /*#__PURE__*/react.forwardRef((props, forwardedRef) => {
168
160
  onBlur: props.onBlur,
169
161
  onFocus: event => {
170
162
  var _props$onFocus;
171
-
172
- (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 ? void 0 : _props$onFocus.call(props, event); // opens the input if it regains focus and it's closed
173
-
163
+ (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 ? void 0 : _props$onFocus.call(props, event);
164
+ // opens the input if it regains focus and it's closed
174
165
  if (!isOpen) {
175
166
  toggle();
176
167
  richTextUtils.focusEditor(editor);
@@ -215,63 +206,49 @@ Editor.displayName = 'Editor';
215
206
  var Editor$1 = Editor;
216
207
 
217
208
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
218
-
219
209
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
220
-
221
210
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
222
-
223
211
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
224
-
225
212
  let RichTextInput = /*#__PURE__*/function (_PureComponent) {
226
213
  _inherits(RichTextInput, _PureComponent);
227
-
228
214
  var _super = _createSuper(RichTextInput);
229
-
230
215
  function RichTextInput() {
231
216
  var _this;
232
-
233
217
  _classCallCheck(this, RichTextInput);
234
-
235
218
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
236
219
  args[_key] = arguments[_key];
237
220
  }
238
-
239
221
  _this = _super.call(this, ...args);
240
222
  _this.serializedValue = _this.props.value;
241
223
  _this.internalSlateValue = richTextUtils.validSlateStateAdapter(richTextUtils.html.deserialize(_this.props.value || ''));
242
-
243
224
  _this.onValueChange = state => {
244
- const serializedValue = richTextUtils.html.serialize(state); // because we are not using setState, we need to make sure that
225
+ const serializedValue = richTextUtils.html.serialize(state);
226
+ // because we are not using setState, we need to make sure that
245
227
  // we perform an update when the slate value changes
246
228
  // as this can contain things like cursor location
247
229
  // in this case, the internalSlateValue would change
248
230
  // but the serializedValue would NOT change.
249
-
250
231
  const hasInternalSlateValueChanged = _this.internalSlateValue !== state;
251
232
  const hasSerializedValueChanged = serializedValue !== _this.serializedValue;
252
233
  _this.internalSlateValue = richTextUtils.validSlateStateAdapter(state);
253
- _this.serializedValue = serializedValue; // the consumer only cares about the serializedValue, so it doesn't make sense to call
234
+ _this.serializedValue = serializedValue;
235
+ // the consumer only cares about the serializedValue, so it doesn't make sense to call
254
236
  // onChange unless this value changes.
255
-
256
237
  if (hasSerializedValueChanged) {
257
238
  var _this$props$onChange, _this$props;
258
-
259
239
  (_this$props$onChange = (_this$props = _this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props, {
260
240
  target: {
261
241
  value: richTextUtils.html.serialize(state)
262
242
  }
263
243
  });
264
244
  }
265
-
266
245
  if (hasInternalSlateValueChanged && !hasSerializedValueChanged) {
267
246
  // this way we force update if cursor or selection changes
268
247
  _this.forceUpdate();
269
248
  }
270
249
  };
271
-
272
250
  return _this;
273
251
  }
274
-
275
252
  _createClass(RichTextInput, [{
276
253
  key: "componentDidUpdate",
277
254
  value: function componentDidUpdate() {
@@ -296,11 +273,9 @@ let RichTextInput = /*#__PURE__*/function (_PureComponent) {
296
273
  if (!this.props.isReadOnly) {
297
274
  process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.onChange === 'function', 'RichTextInput: "onChange" is required when input is not read only.') : void 0;
298
275
  }
299
-
300
276
  if (this.props.showExpandIcon) {
301
277
  process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.onClickExpand === 'function', 'RichTextInput: "onClickExpand" is required when showExpandIcon is true') : void 0;
302
278
  }
303
-
304
279
  return jsxRuntime.jsx(Editor$1, _objectSpread(_objectSpread({}, utils.filterDataAttributes(this.props)), {}, {
305
280
  isAutofocused: this.props.isAutofocussed,
306
281
  id: this.props.id,
@@ -322,11 +297,8 @@ let RichTextInput = /*#__PURE__*/function (_PureComponent) {
322
297
  }));
323
298
  }
324
299
  }]);
325
-
326
300
  return RichTextInput;
327
301
  }(react.PureComponent); // When component is using `forwardRef` only `defaultProps` and `displayName` are recognized by default as static props
328
-
329
-
330
302
  RichTextInput.defaultProps = {
331
303
  defaultExpandMultilineText: false,
332
304
  horizontalConstraint: 'scale',
@@ -352,9 +324,7 @@ RichTextInput.propTypes = process.env.NODE_ENV !== "production" ? {
352
324
  showExpandIcon: _pt__default["default"].bool,
353
325
  onClickExpand: _pt__default["default"].func
354
326
  } : {};
355
-
356
327
  const isTouched = touched => Boolean(touched);
357
-
358
328
  const RichTextInputWithRef = /*#__PURE__*/react.forwardRef((props, ref) => jsxRuntime.jsx(RichTextInput, _objectSpread({
359
329
  parentRef: ref
360
330
  }, props)));
@@ -364,7 +334,7 @@ RichTextInputWithRef.isTouched = isTouched;
364
334
  var RichTextInputWithRef$1 = RichTextInputWithRef;
365
335
 
366
336
  // NOTE: This string will be replaced on build time with the package version.
367
- var version = "16.0.0";
337
+ var version = "16.1.0";
368
338
 
369
339
  exports["default"] = RichTextInputWithRef$1;
370
340
  exports.version = version;
@@ -61,7 +61,6 @@ const EditorWrapper = /*#__PURE__*/_styled__default["default"]("div", {
61
61
  } )("align-self:stretch;cursor:", props => props.isDisabled || props.isReadOnly ? 'not-allowed' : 'inherit', ";" + ("" ));
62
62
 
63
63
  function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
64
-
65
64
  function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
66
65
  const HOTKEYS = {
67
66
  'mod+b': 'bold',
@@ -70,40 +69,33 @@ const HOTKEYS = {
70
69
  'mod+`': 'code'
71
70
  };
72
71
  const COLLAPSED_HEIGHT = 32;
73
-
74
72
  const renderElement = props => jsxRuntime.jsx(richTextUtils.Element, _objectSpread$1({}, props));
75
-
76
73
  const renderLeaf = props => jsxRuntime.jsx(richTextUtils.Leaf, _objectSpread$1({}, props));
77
-
78
74
  const Editor = /*#__PURE__*/react.forwardRef((props, forwardedRef) => {
79
75
  const intl = reactIntl.useIntl();
80
76
  const ref = react.useRef(null);
81
- const createEditorWithPlugins = pipe__default["default"](slateReact.withReact, slateHistory.withHistory); // eslint-disable-next-line react-hooks/exhaustive-deps
82
-
77
+ const createEditorWithPlugins = pipe__default["default"](slateReact.withReact, slateHistory.withHistory);
78
+ // eslint-disable-next-line react-hooks/exhaustive-deps
83
79
  const editor = react.useMemo(() => createEditorWithPlugins(slate.createEditor()), []);
84
-
85
80
  const _useState = react.useState(false),
86
- _useState2 = _slicedToArray(_useState, 2),
87
- renderToggleButton = _useState2[0],
88
- setRenderToggleButton = _useState2[1];
89
-
81
+ _useState2 = _slicedToArray(_useState, 2),
82
+ renderToggleButton = _useState2[0],
83
+ setRenderToggleButton = _useState2[1];
90
84
  const updateRenderToggleButton = react.useCallback(() => {
91
85
  var _ref$current;
92
-
93
86
  const doesExceedCollapsedHeightLimit = Number((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.clientHeight) > COLLAPSED_HEIGHT;
94
-
95
87
  if (doesExceedCollapsedHeightLimit && !renderToggleButton) {
96
88
  setRenderToggleButton(true);
97
89
  }
98
-
99
90
  if (!doesExceedCollapsedHeightLimit && renderToggleButton) {
100
91
  setRenderToggleButton(false);
101
92
  }
102
93
  }, [setRenderToggleButton, renderToggleButton]);
103
94
  react.useEffect(() => {
104
95
  updateRenderToggleButton();
105
- }, [editor, updateRenderToggleButton]); // resetting
96
+ }, [editor, updateRenderToggleButton]);
106
97
 
98
+ // resetting
107
99
  const resetValue = react.useCallback(newValue => {
108
100
  richTextUtils.resetEditor(editor, newValue);
109
101
  }, [editor]);
@@ -113,7 +105,6 @@ const Editor = /*#__PURE__*/react.forwardRef((props, forwardedRef) => {
113
105
  to be called from the parent component.
114
106
  e.g. <button onMouseDown={() => ref.current?.resetValue("<p><strong>Value after reset</strong></p>")}>Reset</button>
115
107
  */
116
-
117
108
  react.useImperativeHandle(forwardedRef, () => {
118
109
  return {
119
110
  resetValue
@@ -124,9 +115,9 @@ const Editor = /*#__PURE__*/react.forwardRef((props, forwardedRef) => {
124
115
  isDefaultClosed: !props.defaultExpandMultilineText,
125
116
  children: _ref => {
126
117
  let isOpen = _ref.isOpen,
127
- toggle = _ref.toggle,
128
- containerStyles = _ref.containerStyles,
129
- registerContentNode = _ref.registerContentNode;
118
+ toggle = _ref.toggle,
119
+ containerStyles = _ref.containerStyles,
120
+ registerContentNode = _ref.registerContentNode;
130
121
  const refObj = {
131
122
  containerRef: ref,
132
123
  registerContentNode
@@ -143,7 +134,8 @@ const Editor = /*#__PURE__*/react.forwardRef((props, forwardedRef) => {
143
134
  editor: editor,
144
135
  value: props.value,
145
136
  onChange: props.onChange,
146
- children: jsxRuntime.jsxs(richTextUtils.RichTextBody // @ts-ignore
137
+ children: jsxRuntime.jsxs(richTextUtils.RichTextBody
138
+ // @ts-ignore
147
139
  , {
148
140
  ref: refObj,
149
141
  hasError: props.hasError,
@@ -164,9 +156,8 @@ const Editor = /*#__PURE__*/react.forwardRef((props, forwardedRef) => {
164
156
  onBlur: props.onBlur,
165
157
  onFocus: event => {
166
158
  var _props$onFocus;
167
-
168
- (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 ? void 0 : _props$onFocus.call(props, event); // opens the input if it regains focus and it's closed
169
-
159
+ (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 ? void 0 : _props$onFocus.call(props, event);
160
+ // opens the input if it regains focus and it's closed
170
161
  if (!isOpen) {
171
162
  toggle();
172
163
  richTextUtils.focusEditor(editor);
@@ -211,63 +202,49 @@ Editor.displayName = 'Editor';
211
202
  var Editor$1 = Editor;
212
203
 
213
204
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
214
-
215
205
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
216
-
217
206
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
218
-
219
207
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
220
-
221
208
  let RichTextInput = /*#__PURE__*/function (_PureComponent) {
222
209
  _inherits(RichTextInput, _PureComponent);
223
-
224
210
  var _super = _createSuper(RichTextInput);
225
-
226
211
  function RichTextInput() {
227
212
  var _this;
228
-
229
213
  _classCallCheck(this, RichTextInput);
230
-
231
214
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
232
215
  args[_key] = arguments[_key];
233
216
  }
234
-
235
217
  _this = _super.call(this, ...args);
236
218
  _this.serializedValue = _this.props.value;
237
219
  _this.internalSlateValue = richTextUtils.validSlateStateAdapter(richTextUtils.html.deserialize(_this.props.value || ''));
238
-
239
220
  _this.onValueChange = state => {
240
- const serializedValue = richTextUtils.html.serialize(state); // because we are not using setState, we need to make sure that
221
+ const serializedValue = richTextUtils.html.serialize(state);
222
+ // because we are not using setState, we need to make sure that
241
223
  // we perform an update when the slate value changes
242
224
  // as this can contain things like cursor location
243
225
  // in this case, the internalSlateValue would change
244
226
  // but the serializedValue would NOT change.
245
-
246
227
  const hasInternalSlateValueChanged = _this.internalSlateValue !== state;
247
228
  const hasSerializedValueChanged = serializedValue !== _this.serializedValue;
248
229
  _this.internalSlateValue = richTextUtils.validSlateStateAdapter(state);
249
- _this.serializedValue = serializedValue; // the consumer only cares about the serializedValue, so it doesn't make sense to call
230
+ _this.serializedValue = serializedValue;
231
+ // the consumer only cares about the serializedValue, so it doesn't make sense to call
250
232
  // onChange unless this value changes.
251
-
252
233
  if (hasSerializedValueChanged) {
253
234
  var _this$props$onChange, _this$props;
254
-
255
235
  (_this$props$onChange = (_this$props = _this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props, {
256
236
  target: {
257
237
  value: richTextUtils.html.serialize(state)
258
238
  }
259
239
  });
260
240
  }
261
-
262
241
  if (hasInternalSlateValueChanged && !hasSerializedValueChanged) {
263
242
  // this way we force update if cursor or selection changes
264
243
  _this.forceUpdate();
265
244
  }
266
245
  };
267
-
268
246
  return _this;
269
247
  }
270
-
271
248
  _createClass(RichTextInput, [{
272
249
  key: "componentDidUpdate",
273
250
  value: function componentDidUpdate() {
@@ -290,9 +267,7 @@ let RichTextInput = /*#__PURE__*/function (_PureComponent) {
290
267
  key: "render",
291
268
  value: function render() {
292
269
  if (!this.props.isReadOnly) ;
293
-
294
270
  if (this.props.showExpandIcon) ;
295
-
296
271
  return jsxRuntime.jsx(Editor$1, _objectSpread(_objectSpread({}, utils.filterDataAttributes(this.props)), {}, {
297
272
  isAutofocused: this.props.isAutofocussed,
298
273
  id: this.props.id,
@@ -314,11 +289,8 @@ let RichTextInput = /*#__PURE__*/function (_PureComponent) {
314
289
  }));
315
290
  }
316
291
  }]);
317
-
318
292
  return RichTextInput;
319
293
  }(react.PureComponent); // When component is using `forwardRef` only `defaultProps` and `displayName` are recognized by default as static props
320
-
321
-
322
294
  RichTextInput.defaultProps = {
323
295
  defaultExpandMultilineText: false,
324
296
  horizontalConstraint: 'scale',
@@ -327,9 +299,7 @@ RichTextInput.defaultProps = {
327
299
  };
328
300
  RichTextInput.displayName = 'RichTextInput';
329
301
  RichTextInput.propTypes = {};
330
-
331
302
  const isTouched = touched => Boolean(touched);
332
-
333
303
  const RichTextInputWithRef = /*#__PURE__*/react.forwardRef((props, ref) => jsxRuntime.jsx(RichTextInput, _objectSpread({
334
304
  parentRef: ref
335
305
  }, props)));
@@ -339,7 +309,7 @@ RichTextInputWithRef.isTouched = isTouched;
339
309
  var RichTextInputWithRef$1 = RichTextInputWithRef;
340
310
 
341
311
  // NOTE: This string will be replaced on build time with the package version.
342
- var version = "16.0.0";
312
+ var version = "16.1.0";
343
313
 
344
314
  exports["default"] = RichTextInputWithRef$1;
345
315
  exports.version = version;
@@ -41,7 +41,6 @@ const EditorWrapper = /*#__PURE__*/_styled("div", process.env.NODE_ENV === "prod
41
41
  })("align-self:stretch;cursor:", props => props.isDisabled || props.isReadOnly ? 'not-allowed' : 'inherit', ";" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImVkaXRvci5zdHlsZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBS3FEIiwiZmlsZSI6ImVkaXRvci5zdHlsZXMudHMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCc7XG5pbXBvcnQgdHlwZSB7IFRFZGl0b3JQcm9wcyB9IGZyb20gJy4vZWRpdG9yJztcblxudHlwZSBURWRpdG9yV3JhcHBlclByb3BzID0gUGljazxURWRpdG9yUHJvcHMsICdpc0Rpc2FibGVkJyB8ICdpc1JlYWRPbmx5Jz47XG5cbmNvbnN0IEVkaXRvcldyYXBwZXIgPSBzdHlsZWQuZGl2PFRFZGl0b3JXcmFwcGVyUHJvcHM+YFxuICBhbGlnbi1zZWxmOiBzdHJldGNoO1xuICBjdXJzb3I6ICR7KHByb3BzKSA9PlxuICAgIHByb3BzLmlzRGlzYWJsZWQgfHwgcHJvcHMuaXNSZWFkT25seSA/ICdub3QtYWxsb3dlZCcgOiAnaW5oZXJpdCd9O1xuYDtcblxuZXhwb3J0IHsgRWRpdG9yV3JhcHBlciB9O1xuIl19 */"));
42
42
 
43
43
  function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
44
-
45
44
  function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
46
45
  const HOTKEYS = {
47
46
  'mod+b': 'bold',
@@ -50,40 +49,33 @@ const HOTKEYS = {
50
49
  'mod+`': 'code'
51
50
  };
52
51
  const COLLAPSED_HEIGHT = 32;
53
-
54
52
  const renderElement = props => jsx(Element, _objectSpread$1({}, props));
55
-
56
53
  const renderLeaf = props => jsx(Leaf, _objectSpread$1({}, props));
57
-
58
54
  const Editor = /*#__PURE__*/forwardRef((props, forwardedRef) => {
59
55
  const intl = useIntl();
60
56
  const ref = useRef(null);
61
- const createEditorWithPlugins = pipe(withReact, withHistory); // eslint-disable-next-line react-hooks/exhaustive-deps
62
-
57
+ const createEditorWithPlugins = pipe(withReact, withHistory);
58
+ // eslint-disable-next-line react-hooks/exhaustive-deps
63
59
  const editor = useMemo(() => createEditorWithPlugins(createEditor()), []);
64
-
65
60
  const _useState = useState(false),
66
- _useState2 = _slicedToArray(_useState, 2),
67
- renderToggleButton = _useState2[0],
68
- setRenderToggleButton = _useState2[1];
69
-
61
+ _useState2 = _slicedToArray(_useState, 2),
62
+ renderToggleButton = _useState2[0],
63
+ setRenderToggleButton = _useState2[1];
70
64
  const updateRenderToggleButton = useCallback(() => {
71
65
  var _ref$current;
72
-
73
66
  const doesExceedCollapsedHeightLimit = Number((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.clientHeight) > COLLAPSED_HEIGHT;
74
-
75
67
  if (doesExceedCollapsedHeightLimit && !renderToggleButton) {
76
68
  setRenderToggleButton(true);
77
69
  }
78
-
79
70
  if (!doesExceedCollapsedHeightLimit && renderToggleButton) {
80
71
  setRenderToggleButton(false);
81
72
  }
82
73
  }, [setRenderToggleButton, renderToggleButton]);
83
74
  useEffect(() => {
84
75
  updateRenderToggleButton();
85
- }, [editor, updateRenderToggleButton]); // resetting
76
+ }, [editor, updateRenderToggleButton]);
86
77
 
78
+ // resetting
87
79
  const resetValue = useCallback(newValue => {
88
80
  resetEditor(editor, newValue);
89
81
  }, [editor]);
@@ -93,7 +85,6 @@ const Editor = /*#__PURE__*/forwardRef((props, forwardedRef) => {
93
85
  to be called from the parent component.
94
86
  e.g. <button onMouseDown={() => ref.current?.resetValue("<p><strong>Value after reset</strong></p>")}>Reset</button>
95
87
  */
96
-
97
88
  useImperativeHandle(forwardedRef, () => {
98
89
  return {
99
90
  resetValue
@@ -104,9 +95,9 @@ const Editor = /*#__PURE__*/forwardRef((props, forwardedRef) => {
104
95
  isDefaultClosed: !props.defaultExpandMultilineText,
105
96
  children: _ref => {
106
97
  let isOpen = _ref.isOpen,
107
- toggle = _ref.toggle,
108
- containerStyles = _ref.containerStyles,
109
- registerContentNode = _ref.registerContentNode;
98
+ toggle = _ref.toggle,
99
+ containerStyles = _ref.containerStyles,
100
+ registerContentNode = _ref.registerContentNode;
110
101
  const refObj = {
111
102
  containerRef: ref,
112
103
  registerContentNode
@@ -123,7 +114,8 @@ const Editor = /*#__PURE__*/forwardRef((props, forwardedRef) => {
123
114
  editor: editor,
124
115
  value: props.value,
125
116
  onChange: props.onChange,
126
- children: jsxs(RichTextBody // @ts-ignore
117
+ children: jsxs(RichTextBody
118
+ // @ts-ignore
127
119
  , {
128
120
  ref: refObj,
129
121
  hasError: props.hasError,
@@ -144,9 +136,8 @@ const Editor = /*#__PURE__*/forwardRef((props, forwardedRef) => {
144
136
  onBlur: props.onBlur,
145
137
  onFocus: event => {
146
138
  var _props$onFocus;
147
-
148
- (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 ? void 0 : _props$onFocus.call(props, event); // opens the input if it regains focus and it's closed
149
-
139
+ (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 ? void 0 : _props$onFocus.call(props, event);
140
+ // opens the input if it regains focus and it's closed
150
141
  if (!isOpen) {
151
142
  toggle();
152
143
  focusEditor(editor);
@@ -191,63 +182,49 @@ Editor.displayName = 'Editor';
191
182
  var Editor$1 = Editor;
192
183
 
193
184
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
194
-
195
185
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
196
-
197
186
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
198
-
199
187
  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; } }
200
-
201
188
  let RichTextInput = /*#__PURE__*/function (_PureComponent) {
202
189
  _inherits(RichTextInput, _PureComponent);
203
-
204
190
  var _super = _createSuper(RichTextInput);
205
-
206
191
  function RichTextInput() {
207
192
  var _this;
208
-
209
193
  _classCallCheck(this, RichTextInput);
210
-
211
194
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
212
195
  args[_key] = arguments[_key];
213
196
  }
214
-
215
197
  _this = _super.call(this, ...args);
216
198
  _this.serializedValue = _this.props.value;
217
199
  _this.internalSlateValue = validSlateStateAdapter(html.deserialize(_this.props.value || ''));
218
-
219
200
  _this.onValueChange = state => {
220
- const serializedValue = html.serialize(state); // because we are not using setState, we need to make sure that
201
+ const serializedValue = html.serialize(state);
202
+ // because we are not using setState, we need to make sure that
221
203
  // we perform an update when the slate value changes
222
204
  // as this can contain things like cursor location
223
205
  // in this case, the internalSlateValue would change
224
206
  // but the serializedValue would NOT change.
225
-
226
207
  const hasInternalSlateValueChanged = _this.internalSlateValue !== state;
227
208
  const hasSerializedValueChanged = serializedValue !== _this.serializedValue;
228
209
  _this.internalSlateValue = validSlateStateAdapter(state);
229
- _this.serializedValue = serializedValue; // the consumer only cares about the serializedValue, so it doesn't make sense to call
210
+ _this.serializedValue = serializedValue;
211
+ // the consumer only cares about the serializedValue, so it doesn't make sense to call
230
212
  // onChange unless this value changes.
231
-
232
213
  if (hasSerializedValueChanged) {
233
214
  var _this$props$onChange, _this$props;
234
-
235
215
  (_this$props$onChange = (_this$props = _this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props, {
236
216
  target: {
237
217
  value: html.serialize(state)
238
218
  }
239
219
  });
240
220
  }
241
-
242
221
  if (hasInternalSlateValueChanged && !hasSerializedValueChanged) {
243
222
  // this way we force update if cursor or selection changes
244
223
  _this.forceUpdate();
245
224
  }
246
225
  };
247
-
248
226
  return _this;
249
227
  }
250
-
251
228
  _createClass(RichTextInput, [{
252
229
  key: "componentDidUpdate",
253
230
  value: function componentDidUpdate() {
@@ -272,11 +249,9 @@ let RichTextInput = /*#__PURE__*/function (_PureComponent) {
272
249
  if (!this.props.isReadOnly) {
273
250
  process.env.NODE_ENV !== "production" ? warning(typeof this.props.onChange === 'function', 'RichTextInput: "onChange" is required when input is not read only.') : void 0;
274
251
  }
275
-
276
252
  if (this.props.showExpandIcon) {
277
253
  process.env.NODE_ENV !== "production" ? warning(typeof this.props.onClickExpand === 'function', 'RichTextInput: "onClickExpand" is required when showExpandIcon is true') : void 0;
278
254
  }
279
-
280
255
  return jsx(Editor$1, _objectSpread(_objectSpread({}, filterDataAttributes(this.props)), {}, {
281
256
  isAutofocused: this.props.isAutofocussed,
282
257
  id: this.props.id,
@@ -298,11 +273,8 @@ let RichTextInput = /*#__PURE__*/function (_PureComponent) {
298
273
  }));
299
274
  }
300
275
  }]);
301
-
302
276
  return RichTextInput;
303
277
  }(PureComponent); // When component is using `forwardRef` only `defaultProps` and `displayName` are recognized by default as static props
304
-
305
-
306
278
  RichTextInput.defaultProps = {
307
279
  defaultExpandMultilineText: false,
308
280
  horizontalConstraint: 'scale',
@@ -328,9 +300,7 @@ RichTextInput.propTypes = process.env.NODE_ENV !== "production" ? {
328
300
  showExpandIcon: _pt.bool,
329
301
  onClickExpand: _pt.func
330
302
  } : {};
331
-
332
303
  const isTouched = touched => Boolean(touched);
333
-
334
304
  const RichTextInputWithRef = /*#__PURE__*/forwardRef((props, ref) => jsx(RichTextInput, _objectSpread({
335
305
  parentRef: ref
336
306
  }, props)));
@@ -340,6 +310,6 @@ RichTextInputWithRef.isTouched = isTouched;
340
310
  var RichTextInputWithRef$1 = RichTextInputWithRef;
341
311
 
342
312
  // NOTE: This string will be replaced on build time with the package version.
343
- var version = "16.0.0";
313
+ var version = "16.1.0";
344
314
 
345
315
  export { RichTextInputWithRef$1 as default, version };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/rich-text-input",
3
3
  "description": "A controlled rich text input component for rich text with validation states.",
4
- "version": "16.0.0",
4
+ "version": "16.1.0",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -21,18 +21,18 @@
21
21
  "dependencies": {
22
22
  "@babel/runtime": "^7.20.13",
23
23
  "@babel/runtime-corejs3": "^7.20.13",
24
- "@commercetools-uikit/collapsible-motion": "16.0.0",
25
- "@commercetools-uikit/constraints": "16.0.0",
26
- "@commercetools-uikit/design-system": "16.0.0",
27
- "@commercetools-uikit/flat-button": "16.0.0",
28
- "@commercetools-uikit/hooks": "16.0.0",
29
- "@commercetools-uikit/icons": "16.0.0",
30
- "@commercetools-uikit/input-utils": "16.0.0",
31
- "@commercetools-uikit/rich-text-utils": "16.0.0",
32
- "@commercetools-uikit/spacings-inline": "16.0.0",
33
- "@commercetools-uikit/spacings-stack": "16.0.0",
34
- "@commercetools-uikit/tooltip": "16.0.0",
35
- "@commercetools-uikit/utils": "16.0.0",
24
+ "@commercetools-uikit/collapsible-motion": "16.1.0",
25
+ "@commercetools-uikit/constraints": "16.1.0",
26
+ "@commercetools-uikit/design-system": "16.1.0",
27
+ "@commercetools-uikit/flat-button": "16.1.0",
28
+ "@commercetools-uikit/hooks": "16.1.0",
29
+ "@commercetools-uikit/icons": "16.1.0",
30
+ "@commercetools-uikit/input-utils": "16.1.0",
31
+ "@commercetools-uikit/rich-text-utils": "16.1.0",
32
+ "@commercetools-uikit/spacings-inline": "16.1.0",
33
+ "@commercetools-uikit/spacings-stack": "16.1.0",
34
+ "@commercetools-uikit/tooltip": "16.1.0",
35
+ "@commercetools-uikit/utils": "16.1.0",
36
36
  "@emotion/react": "^11.10.5",
37
37
  "@emotion/styled": "^11.10.5",
38
38
  "downshift": "6.1.12",