@commercetools-uikit/localized-rich-text-input 14.0.6 → 15.0.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.
- package/README.md +1 -0
- package/dist/commercetools-uikit-localized-rich-text-input.cjs.dev.js +187 -237
- package/dist/commercetools-uikit-localized-rich-text-input.cjs.prod.js +178 -166
- package/dist/commercetools-uikit-localized-rich-text-input.esm.js +189 -239
- package/dist/declarations/src/editor.d.ts +13 -32
- package/dist/declarations/src/localized-rich-text-input.d.ts +16 -24
- package/dist/declarations/src/rich-text-input.d.ts +18 -56
- package/package.json +19 -19
- package/dist/declarations/src/editor.types.d.ts +0 -103
|
@@ -11,7 +11,6 @@ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/ob
|
|
|
11
11
|
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
12
12
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
13
13
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
14
|
-
require('prop-types');
|
|
15
14
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
16
15
|
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
17
16
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
@@ -30,10 +29,8 @@ var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
|
30
29
|
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
31
30
|
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
32
31
|
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
32
|
+
require('prop-types');
|
|
33
33
|
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
34
|
-
var _setTimeout = require('@babel/runtime-corejs3/core-js-stable/set-timeout');
|
|
35
|
-
var pick = require('lodash/pick');
|
|
36
|
-
var slateReact = require('slate-react');
|
|
37
34
|
var _styled = require('@emotion/styled/base');
|
|
38
35
|
var reactIntl = require('react-intl');
|
|
39
36
|
var designSystem = require('@commercetools-uikit/design-system');
|
|
@@ -41,6 +38,11 @@ var CollapsibleMotion = require('@commercetools-uikit/collapsible-motion');
|
|
|
41
38
|
var icons = require('@commercetools-uikit/icons');
|
|
42
39
|
var Text = require('@commercetools-uikit/text');
|
|
43
40
|
var FlatButton = require('@commercetools-uikit/flat-button');
|
|
41
|
+
var slateReact = require('slate-react');
|
|
42
|
+
var slate = require('slate');
|
|
43
|
+
var slateHistory = require('slate-history');
|
|
44
|
+
var isHotkey = require('is-hotkey');
|
|
45
|
+
var pipe = require('lodash/fp/pipe');
|
|
44
46
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
45
47
|
var messages = require('@commercetools-uikit/messages');
|
|
46
48
|
|
|
@@ -60,12 +62,12 @@ var Stack__default = /*#__PURE__*/_interopDefault(Stack);
|
|
|
60
62
|
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
61
63
|
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
62
64
|
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
63
|
-
var _setTimeout__default = /*#__PURE__*/_interopDefault(_setTimeout);
|
|
64
|
-
var pick__default = /*#__PURE__*/_interopDefault(pick);
|
|
65
65
|
var _styled__default = /*#__PURE__*/_interopDefault(_styled);
|
|
66
66
|
var CollapsibleMotion__default = /*#__PURE__*/_interopDefault(CollapsibleMotion);
|
|
67
67
|
var Text__default = /*#__PURE__*/_interopDefault(Text);
|
|
68
68
|
var FlatButton__default = /*#__PURE__*/_interopDefault(FlatButton);
|
|
69
|
+
var isHotkey__default = /*#__PURE__*/_interopDefault(isHotkey);
|
|
70
|
+
var pipe__default = /*#__PURE__*/_interopDefault(pipe);
|
|
69
71
|
|
|
70
72
|
function ownKeys$4(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; }
|
|
71
73
|
|
|
@@ -95,6 +97,12 @@ var ToggleButtonWrapper = _styled__default["default"]("div", {
|
|
|
95
97
|
function ownKeys$3(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; }
|
|
96
98
|
|
|
97
99
|
function _objectSpread$3(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$3(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$3(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
100
|
+
var HOTKEYS = {
|
|
101
|
+
'mod+b': 'bold',
|
|
102
|
+
'mod+i': 'italic',
|
|
103
|
+
'mod+u': 'underline',
|
|
104
|
+
'mod+`': 'code'
|
|
105
|
+
};
|
|
98
106
|
var COLLAPSED_HEIGHT = 32;
|
|
99
107
|
|
|
100
108
|
var LeftColumn = _styled__default["default"]("div", {
|
|
@@ -118,17 +126,27 @@ var Row = _styled__default["default"]("div", {
|
|
|
118
126
|
styles: "display:flex;justify-content:flex-end"
|
|
119
127
|
} );
|
|
120
128
|
|
|
129
|
+
var renderElement = function renderElement(props) {
|
|
130
|
+
return jsxRuntime.jsx(richTextUtils.Element, _objectSpread$3({}, props));
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
var renderLeaf = function renderLeaf(props) {
|
|
134
|
+
return jsxRuntime.jsx(richTextUtils.Leaf, _objectSpread$3({}, props));
|
|
135
|
+
};
|
|
136
|
+
|
|
121
137
|
var _ref$1 = {
|
|
122
138
|
name: "bcltzc",
|
|
123
139
|
styles: "flex:auto;width:0;border-top-left-radius:0;border-bottom-left-radius:0"
|
|
124
140
|
} ;
|
|
125
141
|
|
|
126
|
-
var Editor
|
|
127
|
-
var _props$editor, _props$editor2, _props$editor3, _props$editor4;
|
|
128
|
-
|
|
142
|
+
var Editor = /*#__PURE__*/react$1.forwardRef(function (props, forwardedRef) {
|
|
129
143
|
var intl = reactIntl.useIntl();
|
|
130
144
|
var ref = react$1.useRef();
|
|
131
|
-
var
|
|
145
|
+
var createEditorWithPlugins = pipe__default["default"](slateReact.withReact, slateHistory.withHistory); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
146
|
+
|
|
147
|
+
var editor = react$1.useMemo(function () {
|
|
148
|
+
return createEditorWithPlugins(slate.createEditor());
|
|
149
|
+
}, []);
|
|
132
150
|
|
|
133
151
|
if (props.showExpandIcon) ;
|
|
134
152
|
|
|
@@ -156,20 +174,31 @@ var Editor$1 = function Editor(props) {
|
|
|
156
174
|
}, [setRenderToggleButton, renderToggleButton]);
|
|
157
175
|
react$1.useEffect(function () {
|
|
158
176
|
updateRenderToggleButton();
|
|
159
|
-
}, [
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
177
|
+
}, [editor, updateRenderToggleButton]); // resetting
|
|
178
|
+
|
|
179
|
+
var resetValue = react$1.useCallback(function (newValue) {
|
|
180
|
+
richTextUtils.resetEditor(editor, newValue);
|
|
181
|
+
}, [editor]);
|
|
182
|
+
/*
|
|
183
|
+
Resetting the editor requires access to `editor` object returned from `useSlate` hook.
|
|
184
|
+
Therefore, `reset` function is attached to the passed `ref` object via `useImperativeHandle`
|
|
185
|
+
to be called from the parent component.
|
|
186
|
+
e.g. <button onMouseDown={() => ref.current?.resetValue("<p><strong>Value after reset</strong></p>")}>Reset</button>
|
|
187
|
+
*/
|
|
164
188
|
|
|
189
|
+
react$1.useImperativeHandle(forwardedRef, function () {
|
|
190
|
+
return {
|
|
191
|
+
resetValue: resetValue
|
|
192
|
+
};
|
|
193
|
+
});
|
|
165
194
|
var shouldToggleButtonTakeSpace =
|
|
166
|
-
/*
|
|
195
|
+
/*
|
|
167
196
|
- if hasLanguagesControl and there are no errors/warnings to display
|
|
168
197
|
- then the toggleButton is absolutely positioned
|
|
169
198
|
This is because the toggle button is placed next to the LocalizedInputToggle without being siblings in the DOM.
|
|
170
199
|
If there is a error or warning showing,
|
|
171
200
|
then it can be placed statically because it will then be a sibling to the error/warning message
|
|
172
|
-
and LocalizedInputToggle is placed below the errors/warnings.
|
|
201
|
+
and LocalizedInputToggle is placed below the errors/warnings.
|
|
173
202
|
*/
|
|
174
203
|
renderToggleButton && !props.hasLanguagesControl || props.error || props.warning;
|
|
175
204
|
var theme = react.useTheme();
|
|
@@ -189,31 +218,73 @@ var Editor$1 = function Editor(props) {
|
|
|
189
218
|
};
|
|
190
219
|
return jsxRuntime.jsxs(Stack__default["default"], {
|
|
191
220
|
scale: "xs",
|
|
192
|
-
children: [jsxRuntime.
|
|
221
|
+
children: [jsxRuntime.jsx(EditorWrapper, {
|
|
193
222
|
isDisabled: props.isDisabled,
|
|
194
223
|
isReadOnly: props.isReadOnly,
|
|
195
|
-
children:
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
224
|
+
children: jsxRuntime.jsxs(slateReact.Slate, {
|
|
225
|
+
editor: editor,
|
|
226
|
+
value: props.value,
|
|
227
|
+
onChange: props.onChange,
|
|
228
|
+
children: [jsxRuntime.jsx(EditorLanguageLabel, {
|
|
229
|
+
htmlFor: props.id,
|
|
230
|
+
theme: theme,
|
|
231
|
+
children: jsxRuntime.jsx(Text__default["default"].Detail, {
|
|
232
|
+
tone: "secondary",
|
|
233
|
+
children: props.language.toUpperCase()
|
|
234
|
+
})
|
|
235
|
+
}), jsxRuntime.jsxs(richTextUtils.RichTextBody // @ts-ignore
|
|
236
|
+
, {
|
|
237
|
+
ref: refObj,
|
|
238
|
+
styles: {
|
|
239
|
+
container: _ref$1
|
|
240
|
+
},
|
|
241
|
+
hasError: props.hasError,
|
|
242
|
+
isDisabled: props.isDisabled,
|
|
243
|
+
hasWarning: props.hasWarning,
|
|
244
|
+
isReadOnly: Boolean(props.isReadOnly),
|
|
245
|
+
showExpandIcon: Boolean(props.showExpandIcon),
|
|
246
|
+
onClickExpand: props.onClickExpand,
|
|
247
|
+
containerStyles: containerStyles,
|
|
248
|
+
children: [jsxRuntime.jsx(slateReact.Editable, _objectSpread$3(_objectSpread$3({}, utils.filterDataAttributes(props)), {}, {
|
|
249
|
+
name: props.name,
|
|
250
|
+
renderElement: renderElement,
|
|
251
|
+
renderLeaf: renderLeaf,
|
|
252
|
+
placeholder: props.placeholder,
|
|
253
|
+
autoFocus: props.isAutofocused,
|
|
254
|
+
onBlur: props.onBlur,
|
|
255
|
+
onFocus: function onFocus(event) {
|
|
256
|
+
var _props$onFocus;
|
|
257
|
+
|
|
258
|
+
(_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
|
|
259
|
+
|
|
260
|
+
if (!isOpen) {
|
|
261
|
+
toggle();
|
|
262
|
+
richTextUtils.focusEditor(editor);
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
readOnly: props.isReadOnly,
|
|
266
|
+
disabled: props.isDisabled,
|
|
267
|
+
onKeyDown: function onKeyDown(event) {
|
|
268
|
+
for (var hotkey in HOTKEYS) {
|
|
269
|
+
if (isHotkey__default["default"](hotkey, event)) {
|
|
270
|
+
event.preventDefault();
|
|
271
|
+
var mark = HOTKEYS[hotkey];
|
|
272
|
+
richTextUtils.toggleMark(editor, mark);
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
})), props.children, jsxRuntime.jsx(richTextUtils.HiddenInput, {
|
|
278
|
+
isFocused: slateReact.ReactEditor.isFocused(editor),
|
|
279
|
+
handleFocus: function handleFocus() {
|
|
280
|
+
richTextUtils.focusEditor(editor);
|
|
281
|
+
},
|
|
282
|
+
id: props.id,
|
|
283
|
+
disabled: props.isDisabled,
|
|
284
|
+
readOnly: props.isReadOnly
|
|
285
|
+
})]
|
|
286
|
+
})]
|
|
287
|
+
})
|
|
217
288
|
}, props.language), jsxRuntime.jsxs(Row // NOTE: applying this style withing the `styled` component results in the production
|
|
218
289
|
// bundle to apply the style in the wrong order.
|
|
219
290
|
// For instance, we need to override the marging of the spacing component, which also
|
|
@@ -253,58 +324,17 @@ var Editor$1 = function Editor(props) {
|
|
|
253
324
|
});
|
|
254
325
|
}
|
|
255
326
|
});
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
Editor$1
|
|
259
|
-
|
|
260
|
-
var renderEditor = function renderEditor(props, editor, next) {
|
|
261
|
-
var _props$editor5;
|
|
262
|
-
|
|
263
|
-
if (props.options.showExpandIcon) ;
|
|
264
|
-
|
|
265
|
-
var internalId = "".concat(props.id, "__internal__id");
|
|
266
|
-
var children = /*#__PURE__*/react$1.cloneElement(next(), {
|
|
267
|
-
id: internalId
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
var passedProps = _objectSpread$3(_objectSpread$3({
|
|
271
|
-
id: props.id,
|
|
272
|
-
isDisabled: props.disabled,
|
|
273
|
-
isReadOnly: props.readOnly
|
|
274
|
-
}, pick__default["default"](props.options, ['defaultExpandMultilineText', 'language', 'warning', 'error', 'hasWarning', 'hasError', 'toggleLanguage', 'isOpen', 'showExpandIcon', 'onClickExpand', 'hasLanguagesControl'])), utils.filterDataAttributes(props));
|
|
275
|
-
|
|
276
|
-
var isFocused = (_props$editor5 = props.editor) === null || _props$editor5 === void 0 ? void 0 : _props$editor5.value.selection.isFocused;
|
|
277
|
-
return jsxRuntime.jsxs(Editor$1, _objectSpread$3(_objectSpread$3({
|
|
278
|
-
editor: editor
|
|
279
|
-
}, passedProps), {}, {
|
|
280
|
-
children: [children, jsxRuntime.jsx(richTextUtils.HiddenInput, {
|
|
281
|
-
isFocused: Boolean(isFocused),
|
|
282
|
-
handleFocus: editor.focus,
|
|
283
|
-
disabled: props.disabled,
|
|
284
|
-
readOnly: props.readOnly,
|
|
285
|
-
id: props.id
|
|
286
|
-
})]
|
|
287
|
-
}));
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
Editor$1.displayName = 'Editor';
|
|
291
|
-
var renderEditor$1 = renderEditor;
|
|
292
|
-
|
|
293
|
-
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); }; }
|
|
294
|
-
|
|
295
|
-
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; } }
|
|
327
|
+
});
|
|
328
|
+
Editor.displayName = 'Editor';
|
|
329
|
+
var Editor$1 = Editor;
|
|
296
330
|
|
|
297
331
|
function ownKeys$2(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; }
|
|
298
332
|
|
|
299
333
|
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys$2(Object(source))).call(_context3, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
300
334
|
|
|
301
|
-
|
|
302
|
-
// TODO: remove after upgrade of `slate-react` to the latest version
|
|
303
|
-
var Editor = function Editor(props) {
|
|
304
|
-
return jsxRuntime.jsx(slateReact.Editor, _objectSpread$2({}, props));
|
|
305
|
-
};
|
|
335
|
+
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); }; }
|
|
306
336
|
|
|
307
|
-
|
|
337
|
+
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; } }
|
|
308
338
|
|
|
309
339
|
var RichTextInput = /*#__PURE__*/function (_PureComponent) {
|
|
310
340
|
_inherits(RichTextInput, _PureComponent);
|
|
@@ -324,33 +354,25 @@ var RichTextInput = /*#__PURE__*/function (_PureComponent) {
|
|
|
324
354
|
|
|
325
355
|
_this = _super.call.apply(_super, _concatInstanceProperty__default["default"](_context = [this]).call(_context, args));
|
|
326
356
|
_this.serializedValue = _this.props.value || '';
|
|
327
|
-
_this.internalSlateValue = richTextUtils.html.deserialize(_this.props.value || '');
|
|
357
|
+
_this.internalSlateValue = richTextUtils.validSlateStateAdapter(richTextUtils.html.deserialize(_this.props.value || ''));
|
|
328
358
|
|
|
329
|
-
_this.onValueChange = function (
|
|
330
|
-
var serializedValue = richTextUtils.html.serialize(
|
|
359
|
+
_this.onValueChange = function (state) {
|
|
360
|
+
var serializedValue = richTextUtils.html.serialize(state); // because we are not using setState, we need to make sure that
|
|
331
361
|
// we perform an update when the slate value changes
|
|
332
362
|
// as this can contain things like cursor location
|
|
333
363
|
// in this case, the internalSlateValue would change
|
|
334
364
|
// but the serializedValue would NOT change.
|
|
335
365
|
|
|
336
|
-
var hasInternalSlateValueChanged = _this.internalSlateValue !==
|
|
366
|
+
var hasInternalSlateValueChanged = _this.internalSlateValue !== state;
|
|
337
367
|
var hasSerializedValueChanged = serializedValue !== _this.serializedValue;
|
|
338
|
-
_this.internalSlateValue =
|
|
368
|
+
_this.internalSlateValue = richTextUtils.validSlateStateAdapter(state);
|
|
339
369
|
_this.serializedValue = serializedValue; // the consumer only cares about the serializedValue, so it doesn't make sense to call
|
|
340
370
|
// onChange unless this value changes.
|
|
341
371
|
|
|
342
372
|
if (hasSerializedValueChanged) {
|
|
343
373
|
var _this$props$onChange, _this$props;
|
|
344
374
|
|
|
345
|
-
|
|
346
|
-
target: {
|
|
347
|
-
id: _this.props.id,
|
|
348
|
-
name: _this.props.name,
|
|
349
|
-
language: _this.props.language,
|
|
350
|
-
value: serializedValue
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
(_this$props$onChange = (_this$props = _this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props, fakeEvent);
|
|
375
|
+
(_this$props$onChange = (_this$props = _this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props, richTextUtils.html.serialize(state));
|
|
354
376
|
}
|
|
355
377
|
|
|
356
378
|
if (hasInternalSlateValueChanged && !hasSerializedValueChanged) {
|
|
@@ -359,44 +381,6 @@ var RichTextInput = /*#__PURE__*/function (_PureComponent) {
|
|
|
359
381
|
}
|
|
360
382
|
};
|
|
361
383
|
|
|
362
|
-
_this.onBlur = function (_event, _editor, next) {
|
|
363
|
-
next();
|
|
364
|
-
|
|
365
|
-
if (_this.props.onBlur) {
|
|
366
|
-
var fakeEvent = {
|
|
367
|
-
target: {
|
|
368
|
-
id: _this.props.id,
|
|
369
|
-
name: _this.props.name
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
|
|
373
|
-
_setTimeout__default["default"](function () {
|
|
374
|
-
var _this$props$onBlur, _this$props2;
|
|
375
|
-
|
|
376
|
-
return (_this$props$onBlur = (_this$props2 = _this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props2, fakeEvent);
|
|
377
|
-
}, 0);
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
_this.onFocus = function (_event, _editor, next) {
|
|
382
|
-
next();
|
|
383
|
-
|
|
384
|
-
if (_this.props.onFocus) {
|
|
385
|
-
var fakeEvent = {
|
|
386
|
-
target: {
|
|
387
|
-
id: _this.props.id,
|
|
388
|
-
name: _this.props.name
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
_setTimeout__default["default"](function () {
|
|
393
|
-
var _this$props$onFocus, _this$props3;
|
|
394
|
-
|
|
395
|
-
return (_this$props$onFocus = (_this$props3 = _this.props).onFocus) === null || _this$props$onFocus === void 0 ? void 0 : _this$props$onFocus.call(_this$props3, fakeEvent);
|
|
396
|
-
}, 0);
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
|
|
400
384
|
return _this;
|
|
401
385
|
}
|
|
402
386
|
|
|
@@ -404,7 +388,7 @@ var RichTextInput = /*#__PURE__*/function (_PureComponent) {
|
|
|
404
388
|
key: "componentDidUpdate",
|
|
405
389
|
value: function componentDidUpdate() {
|
|
406
390
|
if (this.props.value !== this.serializedValue) {
|
|
407
|
-
this.internalSlateValue = richTextUtils.html.deserialize(this.props.value);
|
|
391
|
+
this.internalSlateValue = richTextUtils.validSlateStateAdapter(richTextUtils.html.deserialize(this.props.value));
|
|
408
392
|
this.serializedValue = this.props.value;
|
|
409
393
|
this.forceUpdate();
|
|
410
394
|
}
|
|
@@ -416,21 +400,28 @@ var RichTextInput = /*#__PURE__*/function (_PureComponent) {
|
|
|
416
400
|
|
|
417
401
|
if (this.props.showExpandIcon) ;
|
|
418
402
|
|
|
419
|
-
return jsxRuntime.jsx(Editor, _objectSpread$2(_objectSpread$2({}, utils.filterDataAttributes(this.props)), {}, {
|
|
420
|
-
id: this.props.id,
|
|
403
|
+
return jsxRuntime.jsx(Editor$1, _objectSpread$2(_objectSpread$2({}, utils.filterDataAttributes(this.props)), {}, {
|
|
421
404
|
name: this.props.name,
|
|
422
|
-
|
|
423
|
-
readOnly: this.props.isReadOnly || this.props.isDisabled,
|
|
424
|
-
value: this.internalSlateValue,
|
|
425
|
-
onFocus: this.onFocus,
|
|
426
|
-
onBlur: this.onBlur // we can only pass this.props to the Editor that Slate understands without getting
|
|
427
|
-
// warning in the console,
|
|
428
|
-
// so instead we pass our extra this.props through this `options` prop.
|
|
429
|
-
,
|
|
430
|
-
options: pick__default["default"](this.props, ['language', 'onToggle', 'toggleLanguage', 'isOpen', 'warning', 'error', 'defaultExpandMultilineText', 'hasWarning', 'hasError', 'placeholder', 'onClickExpand', 'showExpandIcon', 'hasLanguagesControl']),
|
|
405
|
+
isReadOnly: this.props.isReadOnly || this.props.isDisabled,
|
|
431
406
|
onChange: this.onValueChange,
|
|
432
|
-
|
|
433
|
-
|
|
407
|
+
id: this.props.id,
|
|
408
|
+
value: this.internalSlateValue,
|
|
409
|
+
onFocus: this.props.onFocus,
|
|
410
|
+
onBlur: this.props.onBlur,
|
|
411
|
+
isDisabled: this.props.isDisabled,
|
|
412
|
+
defaultExpandMultilineText: this.props.defaultExpandMultilineText,
|
|
413
|
+
hasWarning: this.props.hasWarning,
|
|
414
|
+
hasError: this.props.hasError,
|
|
415
|
+
placeholder: this.props.placeholder,
|
|
416
|
+
showExpandIcon: this.props.showExpandIcon,
|
|
417
|
+
onClickExpand: this.props.onClickExpand,
|
|
418
|
+
language: this.props.language,
|
|
419
|
+
toggleLanguage: this.props.toggleLanguage,
|
|
420
|
+
isOpen: this.props.isOpen,
|
|
421
|
+
warning: this.props.warning,
|
|
422
|
+
error: this.props.error,
|
|
423
|
+
hasLanguagesControl: this.props.hasLanguagesControl,
|
|
424
|
+
ref: this.props.parentRef
|
|
434
425
|
}));
|
|
435
426
|
}
|
|
436
427
|
}]);
|
|
@@ -444,7 +435,13 @@ RichTextInput.defaultProps = {
|
|
|
444
435
|
};
|
|
445
436
|
RichTextInput.displayName = 'RichTextInput';
|
|
446
437
|
RichTextInput.propTypes = {};
|
|
447
|
-
var
|
|
438
|
+
var RichTextInputWithRef = /*#__PURE__*/react$1.forwardRef(function (props, ref) {
|
|
439
|
+
return jsxRuntime.jsx(RichTextInput, _objectSpread$2({
|
|
440
|
+
parentRef: ref
|
|
441
|
+
}, props));
|
|
442
|
+
});
|
|
443
|
+
RichTextInputWithRef.displayName = 'RichTextInputWithRef';
|
|
444
|
+
var RichTextInput$1 = RichTextInputWithRef;
|
|
448
445
|
|
|
449
446
|
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; }
|
|
450
447
|
|
|
@@ -499,7 +496,7 @@ var _ref = {
|
|
|
499
496
|
styles: "align-self:flex-start"
|
|
500
497
|
} ;
|
|
501
498
|
|
|
502
|
-
var LocalizedRichTextInput = function
|
|
499
|
+
var LocalizedRichTextInput = /*#__PURE__*/react$1.forwardRef(function (props, ref) {
|
|
503
500
|
var _context2;
|
|
504
501
|
|
|
505
502
|
if (!props.isReadOnly) ;
|
|
@@ -517,8 +514,7 @@ var LocalizedRichTextInput = function LocalizedRichTextInput(props) {
|
|
|
517
514
|
expandedTranslationsState = _useReducer2[0],
|
|
518
515
|
expandedTranslationsDispatch = _useReducer2[1];
|
|
519
516
|
|
|
520
|
-
var defaultExpansionState = props.hideLanguageExpansionControls || props.defaultExpandLanguages
|
|
521
|
-
false;
|
|
517
|
+
var defaultExpansionState = Boolean(props.hideLanguageExpansionControls || props.defaultExpandLanguages);
|
|
522
518
|
|
|
523
519
|
var _useToggleState = hooks.useToggleState(defaultExpansionState),
|
|
524
520
|
_useToggleState2 = _slicedToArray(_useToggleState, 2),
|
|
@@ -531,6 +527,21 @@ var LocalizedRichTextInput = function LocalizedRichTextInput(props) {
|
|
|
531
527
|
payload: language
|
|
532
528
|
});
|
|
533
529
|
}, [expandedTranslationsDispatch]);
|
|
530
|
+
var createChangeHandler = react$1.useCallback(function (language) {
|
|
531
|
+
return function (state) {
|
|
532
|
+
var _props$onChange;
|
|
533
|
+
|
|
534
|
+
return (_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, {
|
|
535
|
+
target: {
|
|
536
|
+
id: props.id,
|
|
537
|
+
name: props.name,
|
|
538
|
+
language: language,
|
|
539
|
+
value: state
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
544
|
+
[props.id, props.name, props.onChange]);
|
|
534
545
|
var languages = localizedUtils.sortLanguages(props.selectedLanguage, _Object$keys__default["default"](props.value));
|
|
535
546
|
var hasErrorInRemainingLanguages = props.hasError || localizedUtils.getHasErrorOnRemainingLanguages(props.errors, props.selectedLanguage);
|
|
536
547
|
var hasWarningInRemainingLanguages = props.hasWarning || localizedUtils.getHasWarningOnRemainingLanguages(props.warnings, props.selectedLanguage);
|
|
@@ -554,11 +565,12 @@ var LocalizedRichTextInput = function LocalizedRichTextInput(props) {
|
|
|
554
565
|
if (!isFirstLanguage && !areLanguagesOpened) return null;
|
|
555
566
|
var isLastLanguage = index === languages.length - 1;
|
|
556
567
|
var hasLanguagesControl = isFirstLanguage && !areLanguagesOpened || isLastLanguage;
|
|
557
|
-
return
|
|
558
|
-
|
|
559
|
-
|
|
568
|
+
return react.createElement(RichTextInput$1, _objectSpread(_objectSpread({}, utils.filterDataAttributes(props)), {}, {
|
|
569
|
+
key: language,
|
|
570
|
+
id: localizedUtils.getId(props.id, language),
|
|
571
|
+
name: localizedUtils.getName(props.name, language),
|
|
560
572
|
value: props.value[language],
|
|
561
|
-
onChange:
|
|
573
|
+
onChange: createChangeHandler(language),
|
|
562
574
|
language: language,
|
|
563
575
|
isOpen: expandedTranslationsState[language],
|
|
564
576
|
toggleLanguage: toggleLanguage,
|
|
@@ -573,8 +585,10 @@ var LocalizedRichTextInput = function LocalizedRichTextInput(props) {
|
|
|
573
585
|
error: props.errors && props.errors[language],
|
|
574
586
|
showExpandIcon: props.showExpandIcon,
|
|
575
587
|
onClickExpand: props.onClickExpand,
|
|
576
|
-
hasLanguagesControl: hasLanguagesControl
|
|
577
|
-
|
|
588
|
+
hasLanguagesControl: hasLanguagesControl,
|
|
589
|
+
defaultExpandMultilineText: Boolean(props.defaultExpandMultilineText),
|
|
590
|
+
ref: ref
|
|
591
|
+
}, localizedUtils.createLocalizedDataAttributes(props, language)));
|
|
578
592
|
})
|
|
579
593
|
}), shouldRenderLanguagesControl && jsxRuntime.jsx("div", {
|
|
580
594
|
css: _ref,
|
|
@@ -587,9 +601,7 @@ var LocalizedRichTextInput = function LocalizedRichTextInput(props) {
|
|
|
587
601
|
})]
|
|
588
602
|
})
|
|
589
603
|
});
|
|
590
|
-
};
|
|
591
|
-
|
|
592
|
-
LocalizedRichTextInput.propTypes = {};
|
|
604
|
+
});
|
|
593
605
|
LocalizedRichTextInput.displayName = 'LocalizedRichTextInput';
|
|
594
606
|
LocalizedRichTextInput.RequiredValueErrorMessage = RequiredValueErrorMessage$1;
|
|
595
607
|
LocalizedRichTextInput.getId = localizedUtils.getId;
|
|
@@ -602,7 +614,7 @@ LocalizedRichTextInput.isTouched = localizedUtils.isTouched;
|
|
|
602
614
|
var LocalizedRichTextInput$1 = LocalizedRichTextInput;
|
|
603
615
|
|
|
604
616
|
// NOTE: This string will be replaced on build time with the package version.
|
|
605
|
-
var version = "
|
|
617
|
+
var version = "15.0.0";
|
|
606
618
|
|
|
607
619
|
exports["default"] = LocalizedRichTextInput$1;
|
|
608
620
|
exports.version = version;
|