carbon-react 154.3.2 → 154.4.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/esm/components/text-editor/index.d.ts +1 -1
- package/esm/components/text-editor/text-editor.component.d.ts +5 -1
- package/esm/components/text-editor/text-editor.component.js +9 -4
- package/lib/components/text-editor/index.d.ts +1 -1
- package/lib/components/text-editor/text-editor.component.d.ts +5 -1
- package/lib/components/text-editor/text-editor.component.js +8 -4
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { default } from "./text-editor.component";
|
|
2
2
|
export { createEmpty, createFromHTML } from "./utils";
|
|
3
|
-
export type { TextEditorProps, EditorFormattedValues, } from "./text-editor.component";
|
|
3
|
+
export type { TextEditorHandle, TextEditorProps, EditorFormattedValues, } from "./text-editor.component";
|
|
@@ -2,6 +2,10 @@ import React from "react";
|
|
|
2
2
|
import { MarginProps } from "styled-system";
|
|
3
3
|
import { EditorFormattedValues as SaveCallbackProps } from "./__internal__/plugins/Toolbar/buttons/save.component";
|
|
4
4
|
import { TagProps } from "../../__internal__/utils/helpers/tags";
|
|
5
|
+
export interface TextEditorHandle {
|
|
6
|
+
/** Programmatically focus on the text editor. */
|
|
7
|
+
focus: () => void;
|
|
8
|
+
}
|
|
5
9
|
export type EditorFormattedValues = SaveCallbackProps;
|
|
6
10
|
export interface TextEditorProps extends MarginProps, TagProps {
|
|
7
11
|
/** The maximum number of characters allowed in the editor */
|
|
@@ -50,5 +54,5 @@ export interface TextEditorProps extends MarginProps, TagProps {
|
|
|
50
54
|
/** The initial value of the editor, as a HTML string, or JSON */
|
|
51
55
|
value?: string | undefined;
|
|
52
56
|
}
|
|
53
|
-
export declare const TextEditor:
|
|
57
|
+
export declare const TextEditor: React.ForwardRefExoticComponent<TextEditorProps & React.RefAttributes<TextEditorHandle>>;
|
|
54
58
|
export default TextEditor;
|
|
@@ -10,7 +10,7 @@ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
|
10
10
|
import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
|
|
11
11
|
import { ListPlugin } from "@lexical/react/LexicalListPlugin";
|
|
12
12
|
import { $getRoot } from "lexical";
|
|
13
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
13
|
+
import React, { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, forwardRef } from "react";
|
|
14
14
|
import { SerializeLexical, validateUrl } from "./__internal__/helpers";
|
|
15
15
|
import Label from "../../__internal__/label";
|
|
16
16
|
import useLocale from "../../hooks/__internal__/useLocale";
|
|
@@ -24,7 +24,7 @@ import HintText from "../../__internal__/hint-text";
|
|
|
24
24
|
import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
25
25
|
import tagComponent from "../../__internal__/utils/helpers/tags";
|
|
26
26
|
let deprecateOptionalWarnTriggered = false;
|
|
27
|
-
export const TextEditor = ({
|
|
27
|
+
export const TextEditor = /*#__PURE__*/forwardRef(({
|
|
28
28
|
characterLimit = 3000,
|
|
29
29
|
error,
|
|
30
30
|
footer,
|
|
@@ -47,7 +47,7 @@ export const TextEditor = ({
|
|
|
47
47
|
warning,
|
|
48
48
|
value,
|
|
49
49
|
...rest
|
|
50
|
-
}) => {
|
|
50
|
+
}, ref) => {
|
|
51
51
|
if (!deprecateOptionalWarnTriggered && isOptional) {
|
|
52
52
|
deprecateOptionalWarnTriggered = true;
|
|
53
53
|
Logger.deprecate("`isOptional` is deprecated in TextEditor and support will soon be removed. If the value of this component is not required, use the `required` prop and set it to false instead.");
|
|
@@ -58,6 +58,11 @@ export const TextEditor = ({
|
|
|
58
58
|
const hasWarningOrError = Boolean(error || characterLimitWarning || warning);
|
|
59
59
|
const contentEditorRef = useRef(null);
|
|
60
60
|
const [isFocused, setIsFocused] = useState(false);
|
|
61
|
+
useImperativeHandle(ref, () => ({
|
|
62
|
+
focus() {
|
|
63
|
+
contentEditorRef.current?.focus();
|
|
64
|
+
}
|
|
65
|
+
}), []);
|
|
61
66
|
useEffect(() => {
|
|
62
67
|
const editorElement = contentEditorRef?.current;
|
|
63
68
|
const handleFocus = () => {
|
|
@@ -206,5 +211,5 @@ export const TextEditor = ({
|
|
|
206
211
|
maxChars: characterLimit,
|
|
207
212
|
namespace: namespace
|
|
208
213
|
})))));
|
|
209
|
-
};
|
|
214
|
+
});
|
|
210
215
|
export default TextEditor;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { default } from "./text-editor.component";
|
|
2
2
|
export { createEmpty, createFromHTML } from "./utils";
|
|
3
|
-
export type { TextEditorProps, EditorFormattedValues, } from "./text-editor.component";
|
|
3
|
+
export type { TextEditorHandle, TextEditorProps, EditorFormattedValues, } from "./text-editor.component";
|
|
@@ -2,6 +2,10 @@ import React from "react";
|
|
|
2
2
|
import { MarginProps } from "styled-system";
|
|
3
3
|
import { EditorFormattedValues as SaveCallbackProps } from "./__internal__/plugins/Toolbar/buttons/save.component";
|
|
4
4
|
import { TagProps } from "../../__internal__/utils/helpers/tags";
|
|
5
|
+
export interface TextEditorHandle {
|
|
6
|
+
/** Programmatically focus on the text editor. */
|
|
7
|
+
focus: () => void;
|
|
8
|
+
}
|
|
5
9
|
export type EditorFormattedValues = SaveCallbackProps;
|
|
6
10
|
export interface TextEditorProps extends MarginProps, TagProps {
|
|
7
11
|
/** The maximum number of characters allowed in the editor */
|
|
@@ -50,5 +54,5 @@ export interface TextEditorProps extends MarginProps, TagProps {
|
|
|
50
54
|
/** The initial value of the editor, as a HTML string, or JSON */
|
|
51
55
|
value?: string | undefined;
|
|
52
56
|
}
|
|
53
|
-
export declare const TextEditor:
|
|
57
|
+
export declare const TextEditor: React.ForwardRefExoticComponent<TextEditorProps & React.RefAttributes<TextEditorHandle>>;
|
|
54
58
|
export default TextEditor;
|
|
@@ -32,7 +32,7 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
32
32
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
33
33
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } /* eslint-disable no-console */
|
|
34
34
|
let deprecateOptionalWarnTriggered = false;
|
|
35
|
-
const TextEditor = ({
|
|
35
|
+
const TextEditor = exports.TextEditor = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
36
36
|
characterLimit = 3000,
|
|
37
37
|
error,
|
|
38
38
|
footer,
|
|
@@ -55,7 +55,7 @@ const TextEditor = ({
|
|
|
55
55
|
warning,
|
|
56
56
|
value,
|
|
57
57
|
...rest
|
|
58
|
-
}) => {
|
|
58
|
+
}, ref) => {
|
|
59
59
|
if (!deprecateOptionalWarnTriggered && isOptional) {
|
|
60
60
|
deprecateOptionalWarnTriggered = true;
|
|
61
61
|
_logger.default.deprecate("`isOptional` is deprecated in TextEditor and support will soon be removed. If the value of this component is not required, use the `required` prop and set it to false instead.");
|
|
@@ -66,6 +66,11 @@ const TextEditor = ({
|
|
|
66
66
|
const hasWarningOrError = Boolean(error || characterLimitWarning || warning);
|
|
67
67
|
const contentEditorRef = (0, _react.useRef)(null);
|
|
68
68
|
const [isFocused, setIsFocused] = (0, _react.useState)(false);
|
|
69
|
+
(0, _react.useImperativeHandle)(ref, () => ({
|
|
70
|
+
focus() {
|
|
71
|
+
contentEditorRef.current?.focus();
|
|
72
|
+
}
|
|
73
|
+
}), []);
|
|
69
74
|
(0, _react.useEffect)(() => {
|
|
70
75
|
const editorElement = contentEditorRef?.current;
|
|
71
76
|
const handleFocus = () => {
|
|
@@ -214,6 +219,5 @@ const TextEditor = ({
|
|
|
214
219
|
maxChars: characterLimit,
|
|
215
220
|
namespace: namespace
|
|
216
221
|
})))));
|
|
217
|
-
};
|
|
218
|
-
exports.TextEditor = TextEditor;
|
|
222
|
+
});
|
|
219
223
|
var _default = exports.default = TextEditor;
|