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