@commercetools-uikit/localized-rich-text-input 15.15.0 → 16.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/dist/commercetools-uikit-localized-rich-text-input.cjs.d.ts +1 -0
- package/dist/commercetools-uikit-localized-rich-text-input.cjs.d.ts.map +1 -0
- package/dist/commercetools-uikit-localized-rich-text-input.cjs.dev.js +109 -131
- package/dist/commercetools-uikit-localized-rich-text-input.cjs.prod.js +109 -131
- package/dist/commercetools-uikit-localized-rich-text-input.esm.js +109 -131
- package/package.json +19 -19
|
@@ -71,11 +71,9 @@ var FlatButton__default = /*#__PURE__*/_interopDefault(FlatButton);
|
|
|
71
71
|
var isHotkey__default = /*#__PURE__*/_interopDefault(isHotkey);
|
|
72
72
|
var pipe__default = /*#__PURE__*/_interopDefault(pipe);
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
return "1px solid ".concat(props.isReadOnly ? designSystem.designTokens.borderColorForInputWhenReadonly : designSystem.designTokens.borderColorForInputWhenDisabled);
|
|
76
|
-
};
|
|
74
|
+
const getEditorLanguageLabelBorderColor = props => "1px solid ".concat(props.isReadOnly ? designSystem.designTokens.borderColorForInputWhenReadonly : designSystem.designTokens.borderColorForInputWhenDisabled);
|
|
77
75
|
|
|
78
|
-
|
|
76
|
+
const getBackgroundColor = props => {
|
|
79
77
|
if (props.isDisabled) {
|
|
80
78
|
return designSystem.designTokens.backgroundColorForInputWhenDisabled;
|
|
81
79
|
}
|
|
@@ -87,23 +85,15 @@ var getBackgroundColor = function getBackgroundColor(props) {
|
|
|
87
85
|
return designSystem.designTokens.backgroundColorForInput;
|
|
88
86
|
};
|
|
89
87
|
|
|
90
|
-
|
|
88
|
+
const EditorLanguageLabel = /*#__PURE__*/_styled__default["default"]("label", {
|
|
91
89
|
target: "ew063c2"
|
|
92
|
-
} )("white-space:nowrap;flex:0;color:", designSystem.designTokens.fontColorForInputWhenDisabled, ";line-height:calc(\n ", designSystem.designTokens.sizeHeightInput, " - 2 * ", designSystem.designTokens.borderRadius1, "\n );background-color:",
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return getEditorLanguageLabelBorderColor(props);
|
|
96
|
-
}, ";padding:", designSystem.designTokens.paddingForLocalizedRichTextInputLabel, ";transition:border-color ", designSystem.designTokens.transitionStandard, ",background-color ", designSystem.designTokens.transitionStandard, ",color ", designSystem.designTokens.transitionStandard, ";border-right:0;box-shadow:none;appearance:none;display:", function (props) {
|
|
97
|
-
return props.isNewTheme && 'flex';
|
|
98
|
-
}, ";align-items:center;cursor:inherit;" + ("" ));
|
|
99
|
-
|
|
100
|
-
var EditorWrapper = /*#__PURE__*/_styled__default["default"]("div", {
|
|
90
|
+
} )("white-space:nowrap;flex:0;color:", designSystem.designTokens.fontColorForInputWhenDisabled, ";line-height:calc(\n ", designSystem.designTokens.sizeHeightInput, " - 2 * ", designSystem.designTokens.borderRadius1, "\n );background-color:", props => getBackgroundColor(props), ";border-top-left-radius:", designSystem.designTokens.borderRadiusForInput, ";border-bottom-left-radius:", designSystem.designTokens.borderRadiusForInput, ";border:", props => getEditorLanguageLabelBorderColor(props), ";padding:", designSystem.designTokens.paddingForLocalizedRichTextInputLabel, ";transition:border-color ", designSystem.designTokens.transitionStandard, ",background-color ", designSystem.designTokens.transitionStandard, ",color ", designSystem.designTokens.transitionStandard, ";border-right:0;box-shadow:none;appearance:none;display:", props => props.isNewTheme && 'flex', ";align-items:center;cursor:inherit;" + ("" ));
|
|
91
|
+
|
|
92
|
+
const EditorWrapper = /*#__PURE__*/_styled__default["default"]("div", {
|
|
101
93
|
target: "ew063c1"
|
|
102
|
-
} )("width:100%;position:relative;display:flex;cursor:",
|
|
103
|
-
return props.isDisabled || props.isReadOnly ? 'not-allowed' : 'inherit';
|
|
104
|
-
}, ";" + ("" ));
|
|
94
|
+
} )("width:100%;position:relative;display:flex;cursor:", props => props.isDisabled || props.isReadOnly ? 'not-allowed' : 'inherit', ";" + ("" ));
|
|
105
95
|
|
|
106
|
-
|
|
96
|
+
const ToggleButtonWrapper = /*#__PURE__*/_styled__default["default"]("div", {
|
|
107
97
|
target: "ew063c0"
|
|
108
98
|
} )({
|
|
109
99
|
name: "ejz79s",
|
|
@@ -113,76 +103,70 @@ var ToggleButtonWrapper = /*#__PURE__*/_styled__default["default"]("div", {
|
|
|
113
103
|
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; }
|
|
114
104
|
|
|
115
105
|
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; }
|
|
116
|
-
|
|
106
|
+
const HOTKEYS = {
|
|
117
107
|
'mod+b': 'bold',
|
|
118
108
|
'mod+i': 'italic',
|
|
119
109
|
'mod+u': 'underline',
|
|
120
110
|
'mod+`': 'code'
|
|
121
111
|
};
|
|
122
|
-
|
|
112
|
+
const COLLAPSED_HEIGHT = 32;
|
|
123
113
|
|
|
124
|
-
|
|
114
|
+
const LeftColumn = /*#__PURE__*/_styled__default["default"]("div", {
|
|
125
115
|
target: "el9zors2"
|
|
126
116
|
} )({
|
|
127
117
|
name: "147rp59",
|
|
128
118
|
styles: "flex:1;display:flex;align-items:flex-start"
|
|
129
119
|
} );
|
|
130
120
|
|
|
131
|
-
|
|
121
|
+
const RightColumn = /*#__PURE__*/_styled__default["default"]("div", {
|
|
132
122
|
target: "el9zors1"
|
|
133
123
|
} )({
|
|
134
124
|
name: "1m04uhl",
|
|
135
125
|
styles: "position:relative;flex:0;display:flex;align-items:flex-start"
|
|
136
126
|
} );
|
|
137
127
|
|
|
138
|
-
|
|
128
|
+
const Row = /*#__PURE__*/_styled__default["default"]("div", {
|
|
139
129
|
target: "el9zors0"
|
|
140
130
|
} )({
|
|
141
131
|
name: "skgbeu",
|
|
142
132
|
styles: "display:flex;justify-content:flex-end"
|
|
143
133
|
} );
|
|
144
134
|
|
|
145
|
-
|
|
146
|
-
return jsxRuntime.jsx(richTextUtils.Element, _objectSpread$3({}, props));
|
|
147
|
-
};
|
|
135
|
+
const renderElement = props => jsxRuntime.jsx(richTextUtils.Element, _objectSpread$3({}, props));
|
|
148
136
|
|
|
149
|
-
|
|
150
|
-
return jsxRuntime.jsx(richTextUtils.Leaf, _objectSpread$3({}, props));
|
|
151
|
-
};
|
|
137
|
+
const renderLeaf = props => jsxRuntime.jsx(richTextUtils.Leaf, _objectSpread$3({}, props));
|
|
152
138
|
|
|
153
139
|
var _ref = {
|
|
154
140
|
name: "bcltzc",
|
|
155
141
|
styles: "flex:auto;width:0;border-top-left-radius:0;border-bottom-left-radius:0"
|
|
156
142
|
} ;
|
|
157
143
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
144
|
+
const Editor = /*#__PURE__*/react.forwardRef((props, forwardedRef) => {
|
|
145
|
+
const intl = reactIntl.useIntl();
|
|
146
|
+
const ref = react.useRef();
|
|
161
147
|
|
|
162
|
-
|
|
163
|
-
|
|
148
|
+
const _useTheme = designSystem.useTheme(),
|
|
149
|
+
isNewTheme = _useTheme.isNewTheme;
|
|
164
150
|
|
|
165
|
-
|
|
151
|
+
const createEditorWithPlugins = pipe__default["default"](slateReact.withReact, slateHistory.withHistory); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
166
152
|
|
|
167
|
-
|
|
168
|
-
return createEditorWithPlugins(slate.createEditor());
|
|
169
|
-
}, []);
|
|
153
|
+
const editor = react.useMemo(() => createEditorWithPlugins(slate.createEditor()), []);
|
|
170
154
|
|
|
171
155
|
if (props.showExpandIcon) ;
|
|
172
156
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
157
|
+
const _useState = react.useState(false),
|
|
158
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
159
|
+
renderToggleButton = _useState2[0],
|
|
160
|
+
setRenderToggleButton = _useState2[1];
|
|
177
161
|
|
|
178
|
-
|
|
179
|
-
|
|
162
|
+
const toggleLanguage = props.toggleLanguage;
|
|
163
|
+
const onToggle = react.useCallback(() => {
|
|
180
164
|
toggleLanguage(props.language);
|
|
181
165
|
}, [toggleLanguage, props.language]);
|
|
182
|
-
|
|
166
|
+
const updateRenderToggleButton = react.useCallback(() => {
|
|
183
167
|
var _ref$current;
|
|
184
168
|
|
|
185
|
-
|
|
169
|
+
const doesExceedCollapsedHeightLimit = Number((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.clientHeight) > COLLAPSED_HEIGHT;
|
|
186
170
|
|
|
187
171
|
if (doesExceedCollapsedHeightLimit && !renderToggleButton) {
|
|
188
172
|
setRenderToggleButton(true);
|
|
@@ -192,14 +176,14 @@ var Editor = /*#__PURE__*/react.forwardRef(function (props, forwardedRef) {
|
|
|
192
176
|
setRenderToggleButton(false);
|
|
193
177
|
}
|
|
194
178
|
}, [setRenderToggleButton, renderToggleButton]);
|
|
195
|
-
react.useEffect(
|
|
179
|
+
react.useEffect(() => {
|
|
196
180
|
updateRenderToggleButton();
|
|
197
181
|
}, [editor, updateRenderToggleButton]); // resetting
|
|
198
182
|
|
|
199
|
-
|
|
183
|
+
const resetValue = react.useCallback(newValue => {
|
|
200
184
|
var _newValue$props$langu;
|
|
201
185
|
|
|
202
|
-
|
|
186
|
+
const 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 : '';
|
|
203
187
|
richTextUtils.resetEditor(editor, newStringValue);
|
|
204
188
|
}, [editor, props.language]);
|
|
205
189
|
/*
|
|
@@ -209,12 +193,12 @@ var Editor = /*#__PURE__*/react.forwardRef(function (props, forwardedRef) {
|
|
|
209
193
|
e.g. <button onMouseDown={() => ref.current?.resetValue("<p><strong>Value after reset</strong></p>")}>Reset</button>
|
|
210
194
|
*/
|
|
211
195
|
|
|
212
|
-
react.useImperativeHandle(forwardedRef,
|
|
196
|
+
react.useImperativeHandle(forwardedRef, () => {
|
|
213
197
|
return {
|
|
214
|
-
resetValue
|
|
198
|
+
resetValue
|
|
215
199
|
};
|
|
216
200
|
});
|
|
217
|
-
|
|
201
|
+
const shouldToggleButtonTakeSpace =
|
|
218
202
|
/*
|
|
219
203
|
- if hasLanguagesControl and there are no errors/warnings to display
|
|
220
204
|
- then the toggleButton is absolutely positioned
|
|
@@ -229,14 +213,14 @@ var Editor = /*#__PURE__*/react.forwardRef(function (props, forwardedRef) {
|
|
|
229
213
|
isClosed: !props.isOpen,
|
|
230
214
|
onToggle: onToggle,
|
|
231
215
|
isDefaultClosed: !props.defaultExpandMultilineText,
|
|
232
|
-
children:
|
|
233
|
-
|
|
216
|
+
children: _ref2 => {
|
|
217
|
+
let isOpen = _ref2.isOpen,
|
|
234
218
|
toggle = _ref2.toggle,
|
|
235
219
|
containerStyles = _ref2.containerStyles,
|
|
236
220
|
registerContentNode = _ref2.registerContentNode;
|
|
237
|
-
|
|
221
|
+
const refObj = {
|
|
238
222
|
containerRef: ref,
|
|
239
|
-
registerContentNode
|
|
223
|
+
registerContentNode
|
|
240
224
|
};
|
|
241
225
|
return jsxRuntime.jsxs(Stack__default["default"], {
|
|
242
226
|
scale: "xs",
|
|
@@ -276,7 +260,7 @@ var Editor = /*#__PURE__*/react.forwardRef(function (props, forwardedRef) {
|
|
|
276
260
|
placeholder: props.placeholder,
|
|
277
261
|
autoFocus: props.isAutofocused,
|
|
278
262
|
onBlur: props.onBlur,
|
|
279
|
-
onFocus:
|
|
263
|
+
onFocus: event => {
|
|
280
264
|
var _props$onFocus;
|
|
281
265
|
|
|
282
266
|
(_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
|
|
@@ -288,11 +272,11 @@ var Editor = /*#__PURE__*/react.forwardRef(function (props, forwardedRef) {
|
|
|
288
272
|
},
|
|
289
273
|
readOnly: props.isReadOnly,
|
|
290
274
|
disabled: props.isDisabled,
|
|
291
|
-
onKeyDown:
|
|
292
|
-
for (
|
|
275
|
+
onKeyDown: event => {
|
|
276
|
+
for (const hotkey in HOTKEYS) {
|
|
293
277
|
if (isHotkey__default["default"](hotkey, event)) {
|
|
294
278
|
event.preventDefault();
|
|
295
|
-
|
|
279
|
+
const mark = HOTKEYS[hotkey];
|
|
296
280
|
richTextUtils.toggleMark(editor, mark);
|
|
297
281
|
break;
|
|
298
282
|
}
|
|
@@ -300,7 +284,7 @@ var Editor = /*#__PURE__*/react.forwardRef(function (props, forwardedRef) {
|
|
|
300
284
|
}
|
|
301
285
|
})), props.children, jsxRuntime.jsx(richTextUtils.HiddenInput, {
|
|
302
286
|
isFocused: slateReact.ReactEditor.isFocused(editor),
|
|
303
|
-
handleFocus:
|
|
287
|
+
handleFocus: () => {
|
|
304
288
|
richTextUtils.focusEditor(editor);
|
|
305
289
|
},
|
|
306
290
|
id: props.id,
|
|
@@ -318,7 +302,7 @@ var Editor = /*#__PURE__*/react.forwardRef(function (props, forwardedRef) {
|
|
|
318
302
|
// TODO: revisit the logic and the implementation to maybe avoid having to apply this style.
|
|
319
303
|
, {
|
|
320
304
|
css: /*#__PURE__*/react$1.css("margin-top:", shouldToggleButtonTakeSpace ? 'inherit' : '0px !important', ";" + ("" ), "" ),
|
|
321
|
-
children: [
|
|
305
|
+
children: [(() => {
|
|
322
306
|
if (props.error) return jsxRuntime.jsx(LeftColumn, {
|
|
323
307
|
children: jsxRuntime.jsx("div", {
|
|
324
308
|
children: props.error
|
|
@@ -330,7 +314,7 @@ var Editor = /*#__PURE__*/react.forwardRef(function (props, forwardedRef) {
|
|
|
330
314
|
})
|
|
331
315
|
});
|
|
332
316
|
return null;
|
|
333
|
-
}(), renderToggleButton && jsxRuntime.jsx(RightColumn, {
|
|
317
|
+
})(), renderToggleButton && jsxRuntime.jsx(RightColumn, {
|
|
334
318
|
children: jsxRuntime.jsx(ToggleButtonWrapper, {
|
|
335
319
|
css: [!shouldToggleButtonTakeSpace && /*#__PURE__*/react$1.css("position:absolute;top:0;right:0;margin-top:", designSystem.designTokens.spacing10, ";" + ("" ), "" ), "" , "" ],
|
|
336
320
|
children: jsxRuntime.jsx(FlatButton__default["default"], {
|
|
@@ -354,20 +338,18 @@ var Editor$1 = Editor;
|
|
|
354
338
|
|
|
355
339
|
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; }
|
|
356
340
|
|
|
357
|
-
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
341
|
+
function _objectSpread$2(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$2(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$2(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
358
342
|
|
|
359
343
|
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); }; }
|
|
360
344
|
|
|
361
345
|
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; } }
|
|
362
346
|
|
|
363
|
-
|
|
347
|
+
let RichTextInput = /*#__PURE__*/function (_PureComponent) {
|
|
364
348
|
_inherits(RichTextInput, _PureComponent);
|
|
365
349
|
|
|
366
350
|
var _super = _createSuper(RichTextInput);
|
|
367
351
|
|
|
368
352
|
function RichTextInput() {
|
|
369
|
-
var _context;
|
|
370
|
-
|
|
371
353
|
var _this;
|
|
372
354
|
|
|
373
355
|
_classCallCheck(this, RichTextInput);
|
|
@@ -376,19 +358,19 @@ var RichTextInput = /*#__PURE__*/function (_PureComponent) {
|
|
|
376
358
|
args[_key] = arguments[_key];
|
|
377
359
|
}
|
|
378
360
|
|
|
379
|
-
_this = _super.call
|
|
361
|
+
_this = _super.call(this, ...args);
|
|
380
362
|
_this.serializedValue = _this.props.value || '';
|
|
381
363
|
_this.internalSlateValue = richTextUtils.validSlateStateAdapter(richTextUtils.html.deserialize(_this.props.value || ''));
|
|
382
364
|
|
|
383
|
-
_this.onValueChange =
|
|
384
|
-
|
|
365
|
+
_this.onValueChange = state => {
|
|
366
|
+
const serializedValue = richTextUtils.html.serialize(state); // because we are not using setState, we need to make sure that
|
|
385
367
|
// we perform an update when the slate value changes
|
|
386
368
|
// as this can contain things like cursor location
|
|
387
369
|
// in this case, the internalSlateValue would change
|
|
388
370
|
// but the serializedValue would NOT change.
|
|
389
371
|
|
|
390
|
-
|
|
391
|
-
|
|
372
|
+
const hasInternalSlateValueChanged = _this.internalSlateValue !== state;
|
|
373
|
+
const hasSerializedValueChanged = serializedValue !== _this.serializedValue;
|
|
392
374
|
_this.internalSlateValue = richTextUtils.validSlateStateAdapter(state);
|
|
393
375
|
_this.serializedValue = serializedValue; // the consumer only cares about the serializedValue, so it doesn't make sense to call
|
|
394
376
|
// onChange unless this value changes.
|
|
@@ -459,11 +441,9 @@ RichTextInput.defaultProps = {
|
|
|
459
441
|
};
|
|
460
442
|
RichTextInput.displayName = 'RichTextInput';
|
|
461
443
|
RichTextInput.propTypes = {};
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}, props));
|
|
466
|
-
});
|
|
444
|
+
const RichTextInputWithRef = /*#__PURE__*/react.forwardRef((props, ref) => jsxRuntime.jsx(RichTextInput, _objectSpread$2({
|
|
445
|
+
parentRef: ref
|
|
446
|
+
}, props)));
|
|
467
447
|
RichTextInputWithRef.displayName = 'RichTextInputWithRef';
|
|
468
448
|
var RichTextInput$1 = RichTextInputWithRef;
|
|
469
449
|
|
|
@@ -471,11 +451,9 @@ function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["d
|
|
|
471
451
|
|
|
472
452
|
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; }
|
|
473
453
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
});
|
|
478
|
-
};
|
|
454
|
+
const RequiredValueErrorMessage = () => jsxRuntime.jsx(messages.ErrorMessage, {
|
|
455
|
+
children: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$1({}, inputUtils.messagesLocalizedInput.missingRequiredField))
|
|
456
|
+
});
|
|
479
457
|
|
|
480
458
|
RequiredValueErrorMessage.displayName = 'RequiredValueErrorMessage';
|
|
481
459
|
var RequiredValueErrorMessage$1 = RequiredValueErrorMessage;
|
|
@@ -483,22 +461,26 @@ var RequiredValueErrorMessage$1 = RequiredValueErrorMessage;
|
|
|
483
461
|
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; }
|
|
484
462
|
|
|
485
463
|
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; }
|
|
486
|
-
|
|
464
|
+
const defaultProps = {
|
|
487
465
|
horizontalConstraint: 'scale',
|
|
488
466
|
showExpandIcon: false
|
|
489
467
|
};
|
|
490
468
|
|
|
491
|
-
|
|
469
|
+
const expandedTranslationsReducer = (state, action) => {
|
|
492
470
|
switch (action.type) {
|
|
493
471
|
case 'toggle':
|
|
494
|
-
return _objectSpread(_objectSpread({}, state), {},
|
|
472
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
473
|
+
[action.payload]: !state[action.payload]
|
|
474
|
+
});
|
|
495
475
|
|
|
496
476
|
case 'toggleAll':
|
|
497
477
|
{
|
|
498
478
|
var _context;
|
|
499
479
|
|
|
500
|
-
|
|
501
|
-
return _objectSpread(
|
|
480
|
+
const newState = _reduceInstanceProperty__default["default"](_context = _Object$keys__default["default"](state)).call(_context, (translations, locale) => {
|
|
481
|
+
return _objectSpread({
|
|
482
|
+
[locale]: true
|
|
483
|
+
}, translations);
|
|
502
484
|
}, {});
|
|
503
485
|
|
|
504
486
|
return newState;
|
|
@@ -515,7 +497,7 @@ var expandedTranslationsReducer = function expandedTranslationsReducer(state, ac
|
|
|
515
497
|
// languages.
|
|
516
498
|
|
|
517
499
|
|
|
518
|
-
|
|
500
|
+
const LocalizedRichTextInput = /*#__PURE__*/react.forwardRef((props, ref) => {
|
|
519
501
|
var _context2;
|
|
520
502
|
|
|
521
503
|
if (!props.isReadOnly) ;
|
|
@@ -524,46 +506,44 @@ var LocalizedRichTextInput = /*#__PURE__*/react.forwardRef(function (props, ref)
|
|
|
524
506
|
|
|
525
507
|
if (props.hideLanguageExpansionControls) ;
|
|
526
508
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
}, {});
|
|
509
|
+
const initialExpandedTranslationsState = _reduceInstanceProperty__default["default"](_context2 = _Object$keys__default["default"](props.value)).call(_context2, (translations, locale) => _objectSpread(_objectSpread({}, translations), {}, {
|
|
510
|
+
[locale]: Boolean(props.defaultExpandMultilineText)
|
|
511
|
+
}), {});
|
|
530
512
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
513
|
+
const _useReducer = react.useReducer(expandedTranslationsReducer, initialExpandedTranslationsState),
|
|
514
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
515
|
+
expandedTranslationsState = _useReducer2[0],
|
|
516
|
+
expandedTranslationsDispatch = _useReducer2[1];
|
|
535
517
|
|
|
536
|
-
|
|
518
|
+
const defaultExpansionState = Boolean(props.hideLanguageExpansionControls || props.defaultExpandLanguages);
|
|
537
519
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
520
|
+
const _useToggleState = hooks.useToggleState(defaultExpansionState),
|
|
521
|
+
_useToggleState2 = _slicedToArray(_useToggleState, 2),
|
|
522
|
+
areLanguagesOpened = _useToggleState2[0],
|
|
523
|
+
toggleLanguages = _useToggleState2[1];
|
|
542
524
|
|
|
543
|
-
|
|
525
|
+
const toggleLanguage = react.useCallback(language => {
|
|
544
526
|
expandedTranslationsDispatch({
|
|
545
527
|
type: 'toggle',
|
|
546
528
|
payload: language
|
|
547
529
|
});
|
|
548
530
|
}, [expandedTranslationsDispatch]);
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
});
|
|
561
|
-
};
|
|
531
|
+
const createChangeHandler = react.useCallback(language => state => {
|
|
532
|
+
var _props$onChange, _context3, _context4;
|
|
533
|
+
|
|
534
|
+
(_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, {
|
|
535
|
+
target: {
|
|
536
|
+
id: props !== null && props !== void 0 && props.id ? _concatInstanceProperty__default["default"](_context3 = "".concat(props.id, ".")).call(_context3, language) : '',
|
|
537
|
+
name: props !== null && props !== void 0 && props.name ? _concatInstanceProperty__default["default"](_context4 = "".concat(props.name, ".")).call(_context4, language) : '',
|
|
538
|
+
language,
|
|
539
|
+
value: state
|
|
540
|
+
}
|
|
541
|
+
});
|
|
562
542
|
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
563
543
|
[props.id, props.name, props.onChange]);
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
544
|
+
const languages = localizedUtils.sortLanguages(props.selectedLanguage, _Object$keys__default["default"](props.value));
|
|
545
|
+
const hasErrorInRemainingLanguages = props.hasError || localizedUtils.getHasErrorOnRemainingLanguages(props.errors, props.selectedLanguage);
|
|
546
|
+
const hasWarningInRemainingLanguages = props.hasWarning || localizedUtils.getHasWarningOnRemainingLanguages(props.warnings, props.selectedLanguage);
|
|
567
547
|
|
|
568
548
|
if (hasErrorInRemainingLanguages || hasWarningInRemainingLanguages) {
|
|
569
549
|
if (!areLanguagesOpened) {
|
|
@@ -573,30 +553,30 @@ var LocalizedRichTextInput = /*#__PURE__*/react.forwardRef(function (props, ref)
|
|
|
573
553
|
}
|
|
574
554
|
}
|
|
575
555
|
|
|
576
|
-
|
|
577
|
-
|
|
556
|
+
const langRefs = react.useRef(new _Map__default["default"]());
|
|
557
|
+
const resetValue = react.useCallback(newValue => {
|
|
578
558
|
var _context5;
|
|
579
559
|
|
|
580
|
-
_forEachInstanceProperty__default["default"](_context5 = langRefs.current).call(_context5,
|
|
560
|
+
_forEachInstanceProperty__default["default"](_context5 = langRefs.current).call(_context5, langRef => {
|
|
581
561
|
langRef.resetValue(newValue);
|
|
582
562
|
});
|
|
583
563
|
}, []);
|
|
584
|
-
react.useImperativeHandle(ref,
|
|
564
|
+
react.useImperativeHandle(ref, () => {
|
|
585
565
|
return {
|
|
586
|
-
resetValue
|
|
566
|
+
resetValue
|
|
587
567
|
};
|
|
588
568
|
});
|
|
589
|
-
|
|
569
|
+
const shouldRenderLanguagesControl = languages.length > 1 && !props.hideLanguageExpansionControls;
|
|
590
570
|
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
591
571
|
max: props.horizontalConstraint,
|
|
592
572
|
children: jsxRuntime.jsxs(Stack__default["default"], {
|
|
593
573
|
scale: "xs",
|
|
594
574
|
children: [jsxRuntime.jsx(Stack__default["default"], {
|
|
595
|
-
children: _mapInstanceProperty__default["default"](languages).call(languages,
|
|
596
|
-
|
|
575
|
+
children: _mapInstanceProperty__default["default"](languages).call(languages, (language, index) => {
|
|
576
|
+
const isFirstLanguage = index === 0;
|
|
597
577
|
if (!isFirstLanguage && !areLanguagesOpened) return null;
|
|
598
|
-
|
|
599
|
-
|
|
578
|
+
const isLastLanguage = index === languages.length - 1;
|
|
579
|
+
const hasLanguagesControl = isFirstLanguage && !areLanguagesOpened || isLastLanguage;
|
|
600
580
|
return react$1.createElement(RichTextInput$1, _objectSpread(_objectSpread({}, utils.filterDataAttributes(props)), {}, {
|
|
601
581
|
key: language,
|
|
602
582
|
id: localizedUtils.getId(props.id, language),
|
|
@@ -619,9 +599,7 @@ var LocalizedRichTextInput = /*#__PURE__*/react.forwardRef(function (props, ref)
|
|
|
619
599
|
onClickExpand: props.onClickExpand,
|
|
620
600
|
hasLanguagesControl: hasLanguagesControl,
|
|
621
601
|
defaultExpandMultilineText: Boolean(props.defaultExpandMultilineText),
|
|
622
|
-
ref:
|
|
623
|
-
return langRefs.current.set(language, el);
|
|
624
|
-
}
|
|
602
|
+
ref: el => langRefs.current.set(language, el)
|
|
625
603
|
}, localizedUtils.createLocalizedDataAttributes(props, language)));
|
|
626
604
|
})
|
|
627
605
|
}), shouldRenderLanguagesControl && jsxRuntime.jsx(inputUtils.LocalizedInputToggle, {
|
|
@@ -645,7 +623,7 @@ LocalizedRichTextInput.isTouched = localizedUtils.isTouched;
|
|
|
645
623
|
var LocalizedRichTextInput$1 = LocalizedRichTextInput;
|
|
646
624
|
|
|
647
625
|
// NOTE: This string will be replaced on build time with the package version.
|
|
648
|
-
var version = "
|
|
626
|
+
var version = "16.0.0";
|
|
649
627
|
|
|
650
628
|
exports["default"] = LocalizedRichTextInput$1;
|
|
651
629
|
exports.version = version;
|