carbon-react 118.2.0 → 118.3.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/button-minor/button-minor.component.d.ts +5 -1
- package/esm/components/button-minor/button-minor.component.js +4 -1
- package/esm/components/button-minor/button-minor.style.d.ts +2 -1
- package/esm/components/button-minor/button-minor.style.js +17 -0
- package/esm/components/button-minor/index.d.ts +1 -1
- package/esm/components/i18n-provider/i18n-provider.component.js +4 -0
- package/esm/components/menu/menu-full-screen/menu-full-screen.component.js +18 -0
- package/esm/components/menu/menu-item/menu-item.component.js +1 -1
- package/esm/components/menu/menu-item/menu-item.style.js +13 -11
- package/esm/components/password/index.d.ts +2 -0
- package/esm/components/password/index.js +1 -0
- package/esm/components/password/password.component.d.ts +9 -0
- package/esm/components/password/password.component.js +580 -0
- package/esm/components/password/password.style.d.ts +5 -0
- package/esm/components/password/password.style.js +8 -0
- package/esm/components/text-editor/__internal__/decorators/index.d.ts +2 -2
- package/esm/components/text-editor/__internal__/decorators/link-decorator.d.ts +7 -6
- package/esm/components/text-editor/__internal__/editor-counter/editor-counter.component.d.ts +15 -0
- package/esm/components/text-editor/__internal__/editor-counter/editor-counter.component.js +5 -15
- package/esm/components/text-editor/__internal__/editor-counter/editor-counter.style.d.ts +5 -0
- package/esm/components/text-editor/__internal__/editor-counter/index.d.ts +2 -2
- package/esm/components/text-editor/__internal__/editor-link/editor-link.component.d.ts +9 -0
- package/esm/components/text-editor/__internal__/editor-link/editor-link.component.js +3 -4
- package/esm/components/text-editor/__internal__/editor-link/editor-link.style.d.ts +3 -0
- package/esm/components/text-editor/__internal__/editor-link/index.d.ts +2 -2
- package/esm/components/text-editor/__internal__/label-wrapper/index.d.ts +2 -2
- package/esm/components/text-editor/__internal__/label-wrapper/label-wrapper.component.d.ts +12 -0
- package/esm/components/text-editor/__internal__/label-wrapper/label-wrapper.component.js +4 -3
- package/esm/components/text-editor/__internal__/toolbar/index.d.ts +2 -2
- package/esm/components/text-editor/__internal__/toolbar/toolbar-button/index.d.ts +2 -2
- package/esm/components/text-editor/__internal__/toolbar/toolbar-button/toolbar-button.component.d.ts +25 -0
- package/esm/components/text-editor/__internal__/toolbar/toolbar-button/toolbar-button.component.js +12 -23
- package/esm/components/text-editor/__internal__/toolbar/toolbar-button/toolbar-button.style.d.ts +6 -0
- package/esm/components/text-editor/__internal__/toolbar/toolbar.component.d.ts +16 -0
- package/esm/components/text-editor/__internal__/toolbar/toolbar.component.js +40 -36
- package/esm/components/text-editor/__internal__/toolbar/toolbar.style.d.ts +4 -0
- package/esm/components/text-editor/__internal__/utils/index.d.ts +1 -1
- package/esm/components/text-editor/__internal__/utils/utils.d.ts +27 -26
- package/esm/components/text-editor/__internal__/utils/utils.js +9 -10
- package/esm/components/text-editor/index.d.ts +2 -2
- package/esm/components/text-editor/text-editor.component.d.ts +36 -7
- package/esm/components/text-editor/text-editor.component.js +230 -87
- package/esm/components/text-editor/text-editor.style.d.ts +11 -3
- package/esm/components/text-editor/text-editor.style.js +1 -2
- package/esm/components/text-editor/types.d.ts +6 -0
- package/esm/components/text-editor/types.js +4 -0
- package/esm/components/textbox/textbox.component.js +1 -1
- package/esm/{__internal__/utils/helpers → hooks/__internal__}/useUniqueId/index.js +1 -1
- package/esm/locales/en-gb.js +4 -0
- package/esm/locales/locale.d.ts +4 -0
- package/esm/locales/pl-pl.js +4 -0
- package/lib/components/button-minor/button-minor.component.d.ts +5 -1
- package/lib/components/button-minor/button-minor.component.js +4 -1
- package/lib/components/button-minor/button-minor.style.d.ts +2 -1
- package/lib/components/button-minor/button-minor.style.js +17 -0
- package/lib/components/button-minor/index.d.ts +1 -1
- package/lib/components/i18n-provider/i18n-provider.component.js +4 -0
- package/lib/components/menu/menu-full-screen/menu-full-screen.component.js +18 -0
- package/lib/components/menu/menu-item/menu-item.component.js +1 -1
- package/lib/components/menu/menu-item/menu-item.style.js +13 -11
- package/lib/components/password/index.d.ts +2 -0
- package/lib/components/password/index.js +15 -0
- package/lib/components/password/package.json +6 -0
- package/lib/components/password/password.component.d.ts +9 -0
- package/lib/components/password/password.component.js +600 -0
- package/lib/components/password/password.style.d.ts +5 -0
- package/lib/components/password/password.style.js +21 -0
- package/lib/components/text-editor/__internal__/decorators/index.d.ts +2 -2
- package/lib/components/text-editor/__internal__/decorators/link-decorator.d.ts +7 -6
- package/lib/components/text-editor/__internal__/editor-counter/editor-counter.component.d.ts +15 -0
- package/lib/components/text-editor/__internal__/editor-counter/editor-counter.component.js +5 -15
- package/lib/components/text-editor/__internal__/editor-counter/editor-counter.style.d.ts +5 -0
- package/lib/components/text-editor/__internal__/editor-counter/index.d.ts +2 -2
- package/lib/components/text-editor/__internal__/editor-link/editor-link.component.d.ts +9 -0
- package/lib/components/text-editor/__internal__/editor-link/editor-link.component.js +3 -4
- package/lib/components/text-editor/__internal__/editor-link/editor-link.style.d.ts +3 -0
- package/lib/components/text-editor/__internal__/editor-link/index.d.ts +2 -2
- package/lib/components/text-editor/__internal__/label-wrapper/index.d.ts +2 -2
- package/lib/components/text-editor/__internal__/label-wrapper/label-wrapper.component.d.ts +12 -0
- package/lib/components/text-editor/__internal__/label-wrapper/label-wrapper.component.js +2 -8
- package/lib/components/text-editor/__internal__/toolbar/index.d.ts +2 -2
- package/lib/components/text-editor/__internal__/toolbar/toolbar-button/index.d.ts +2 -2
- package/lib/components/text-editor/__internal__/toolbar/toolbar-button/toolbar-button.component.d.ts +25 -0
- package/lib/components/text-editor/__internal__/toolbar/toolbar-button/toolbar-button.component.js +13 -24
- package/lib/components/text-editor/__internal__/toolbar/toolbar-button/toolbar-button.style.d.ts +6 -0
- package/lib/components/text-editor/__internal__/toolbar/toolbar.component.d.ts +16 -0
- package/lib/components/text-editor/__internal__/toolbar/toolbar.component.js +50 -46
- package/lib/components/text-editor/__internal__/toolbar/toolbar.style.d.ts +4 -0
- package/lib/components/text-editor/__internal__/utils/index.d.ts +1 -1
- package/lib/components/text-editor/__internal__/utils/utils.d.ts +27 -26
- package/lib/components/text-editor/__internal__/utils/utils.js +10 -11
- package/lib/components/text-editor/index.d.ts +2 -2
- package/lib/components/text-editor/text-editor.component.d.ts +36 -7
- package/lib/components/text-editor/text-editor.component.js +231 -88
- package/lib/components/text-editor/text-editor.style.d.ts +11 -3
- package/lib/components/text-editor/text-editor.style.js +1 -2
- package/lib/components/text-editor/types.d.ts +6 -0
- package/lib/components/text-editor/types.js +14 -0
- package/lib/components/textbox/textbox.component.js +1 -1
- package/lib/{__internal__/utils/helpers → hooks/__internal__}/useUniqueId/index.js +1 -1
- package/lib/hooks/__internal__/useUniqueId/package.json +6 -0
- package/lib/locales/en-gb.js +4 -0
- package/lib/locales/locale.d.ts +4 -0
- package/lib/locales/pl-pl.js +4 -0
- package/package.json +4 -4
- package/esm/__internal__/DeprecationWarning.js +0 -20
- package/esm/__internal__/utils/storybook/partial-action.d.ts +0 -3
- package/esm/__internal__/utils/storybook/partial-action.js +0 -13
- package/esm/components/text-editor/__internal__/editor-counter/editor-counter.d.ts +0 -11
- package/esm/components/text-editor/__internal__/editor-link/editor-link.d.ts +0 -11
- package/esm/components/text-editor/__internal__/label-wrapper/label-wrapper.d.ts +0 -10
- package/esm/components/text-editor/__internal__/toolbar/toolbar-button/toolbar-button.d.ts +0 -20
- package/esm/components/text-editor/__internal__/toolbar/toolbar.d.ts +0 -13
- package/esm/components/text-editor/text-editor.d.ts +0 -40
- package/lib/__internal__/DeprecationWarning.js +0 -31
- package/lib/__internal__/utils/helpers/useUniqueId/package.json +0 -6
- package/lib/__internal__/utils/storybook/partial-action.d.ts +0 -3
- package/lib/__internal__/utils/storybook/partial-action.js +0 -21
- package/lib/components/text-editor/__internal__/editor-counter/editor-counter.d.ts +0 -11
- package/lib/components/text-editor/__internal__/editor-link/editor-link.d.ts +0 -11
- package/lib/components/text-editor/__internal__/label-wrapper/label-wrapper.d.ts +0 -10
- package/lib/components/text-editor/__internal__/toolbar/toolbar-button/toolbar-button.d.ts +0 -20
- package/lib/components/text-editor/__internal__/toolbar/toolbar.d.ts +0 -13
- package/lib/components/text-editor/text-editor.d.ts +0 -40
- /package/esm/{__internal__/utils/helpers → hooks/__internal__}/useUniqueId/index.d.ts +0 -0
- /package/lib/{__internal__/utils/helpers → hooks/__internal__}/useUniqueId/index.d.ts +0 -0
|
@@ -10,7 +10,6 @@ const Counter = ({
|
|
|
10
10
|
warning,
|
|
11
11
|
info
|
|
12
12
|
}) => /*#__PURE__*/React.createElement(StyledCounterWrapper, {
|
|
13
|
-
hasIcon: !!(error || warning || info),
|
|
14
13
|
"data-component": "text-editor-counter"
|
|
15
14
|
}, !!(error || warning || info) && /*#__PURE__*/React.createElement(ValidationIcon, {
|
|
16
15
|
error: error,
|
|
@@ -23,19 +22,10 @@ const Counter = ({
|
|
|
23
22
|
}, `${limit - count}`));
|
|
24
23
|
|
|
25
24
|
Counter.propTypes = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/** Message to be displayed when there is an error */
|
|
33
|
-
error: PropTypes.string,
|
|
34
|
-
|
|
35
|
-
/** Message to be displayed when there is a warning */
|
|
36
|
-
warning: PropTypes.string,
|
|
37
|
-
|
|
38
|
-
/** Message to be displayed when there is an info */
|
|
39
|
-
info: PropTypes.string
|
|
25
|
+
"count": PropTypes.number,
|
|
26
|
+
"error": PropTypes.string,
|
|
27
|
+
"info": PropTypes.string,
|
|
28
|
+
"limit": PropTypes.number,
|
|
29
|
+
"warning": PropTypes.string
|
|
40
30
|
};
|
|
41
31
|
export default Counter;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const StyledCounter: import("styled-components").StyledComponent<"span", any, {
|
|
2
|
+
hasError: boolean;
|
|
3
|
+
}, never>;
|
|
4
|
+
declare const StyledCounterWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
|
+
export { StyledCounter, StyledCounterWrapper };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./editor-counter";
|
|
2
|
-
export
|
|
1
|
+
export { default } from "./editor-counter.component";
|
|
2
|
+
export type { EditorCounterProps } from "./editor-counter.component";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ContentState } from "draft-js";
|
|
3
|
+
export interface EditorLinkProps {
|
|
4
|
+
children: React.ReactElement[];
|
|
5
|
+
contentState?: ContentState;
|
|
6
|
+
entityKey?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const EditorLink: ({ children, contentState, entityKey, ...rest }: EditorLinkProps) => JSX.Element;
|
|
9
|
+
export default EditorLink;
|
|
@@ -32,7 +32,6 @@ const EditorLink = ({
|
|
|
32
32
|
}, [validUrl]);
|
|
33
33
|
return /*#__PURE__*/React.createElement(StyledLink, _extends({
|
|
34
34
|
href: !editMode ? validUrl : undefined,
|
|
35
|
-
title: validUrl,
|
|
36
35
|
"aria-label": !editMode ? validUrl : undefined,
|
|
37
36
|
target: "_blank",
|
|
38
37
|
rel: "noopener noreferrer"
|
|
@@ -40,8 +39,8 @@ const EditorLink = ({
|
|
|
40
39
|
};
|
|
41
40
|
|
|
42
41
|
EditorLink.propTypes = {
|
|
43
|
-
children: PropTypes.
|
|
44
|
-
contentState: PropTypes.object,
|
|
45
|
-
entityKey: PropTypes.string
|
|
42
|
+
"children": PropTypes.arrayOf(PropTypes.element).isRequired,
|
|
43
|
+
"contentState": PropTypes.object,
|
|
44
|
+
"entityKey": PropTypes.string
|
|
46
45
|
};
|
|
47
46
|
export default EditorLink;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare const StyledEditorLink: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../../../link").LinkProps & import("react").RefAttributes<HTMLButtonElement | HTMLLinkElement>>, any, {}, never>;
|
|
3
|
+
export default StyledEditorLink;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./editor-link";
|
|
2
|
-
export
|
|
1
|
+
export { default } from "./editor-link.component";
|
|
2
|
+
export type { EditorLinkProps } from "./editor-link.component";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./label-wrapper";
|
|
2
|
-
export
|
|
1
|
+
export { default } from "./label-wrapper.component";
|
|
2
|
+
export type { LabelWrapperProps } from "./label-wrapper.component";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* TextEditor component is composed with divs and spans.
|
|
4
|
+
* We have to manually trigger focus on TextEditor by clicking on label component.
|
|
5
|
+
* This wrapper allows us to trigger focus on TextEditor
|
|
6
|
+
*/
|
|
7
|
+
export interface LabelWrapperProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
onClick: (event: React.MouseEvent<HTMLSpanElement>) => void;
|
|
10
|
+
}
|
|
11
|
+
declare const LabelWrapper: ({ onClick, children }: LabelWrapperProps) => JSX.Element;
|
|
12
|
+
export default LabelWrapper;
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
4
4
|
import React from "react";
|
|
5
|
-
import PropTypes from "prop-types";
|
|
6
5
|
/**
|
|
7
6
|
* TextEditor component is composed with divs and spans.
|
|
8
7
|
* We have to manually trigger focus on TextEditor by clicking on label component.
|
|
9
8
|
* This wrapper allows us to trigger focus on TextEditor
|
|
10
9
|
*/
|
|
11
10
|
|
|
11
|
+
import PropTypes from "prop-types";
|
|
12
|
+
|
|
12
13
|
const LabelWrapper = ({
|
|
13
14
|
onClick,
|
|
14
15
|
children
|
|
@@ -19,7 +20,7 @@ const LabelWrapper = ({
|
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
LabelWrapper.propTypes = {
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
"children": PropTypes.node,
|
|
24
|
+
"onClick": PropTypes.func.isRequired
|
|
24
25
|
};
|
|
25
26
|
export default LabelWrapper;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./toolbar";
|
|
2
|
-
export
|
|
1
|
+
export { default } from "./toolbar.component";
|
|
2
|
+
export type { ToolbarProps } from "./toolbar.component";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./toolbar-button";
|
|
2
|
-
export
|
|
1
|
+
export { default } from "./toolbar-button.component";
|
|
2
|
+
export type { ToolbarButtonProps } from "./toolbar-button.component";
|
package/esm/components/text-editor/__internal__/toolbar/toolbar-button/toolbar-button.component.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface ToolbarButtonProps {
|
|
3
|
+
/** Accessibility label for a button */
|
|
4
|
+
ariaLabel: string;
|
|
5
|
+
/** The children for the button */
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
/** Used to control the button's active status */
|
|
8
|
+
activated?: boolean;
|
|
9
|
+
/** Callback to handle any keydown events on a button */
|
|
10
|
+
onKeyDown: (ev: React.KeyboardEvent<HTMLButtonElement>) => void;
|
|
11
|
+
/** Callback to handle any mousedown events on a button */
|
|
12
|
+
onMouseDown: (ev: React.MouseEvent<HTMLButtonElement>) => void;
|
|
13
|
+
/** Callback to handle any mouseover events on a button */
|
|
14
|
+
onMouseOver?: (ev: React.MouseEvent<HTMLButtonElement>) => void;
|
|
15
|
+
/** Callback to handle any mouseleave events on a button */
|
|
16
|
+
onMouseLeave?: (ev: React.MouseEvent<HTMLButtonElement>) => void;
|
|
17
|
+
/** Callback to handle any focus events on a button */
|
|
18
|
+
onFocus?: (ev: React.FocusEvent<HTMLButtonElement>) => void;
|
|
19
|
+
/** Callback to handle any blur events on a button */
|
|
20
|
+
onBlur?: (ev: React.FocusEvent<HTMLButtonElement>) => void;
|
|
21
|
+
/** Controls whether the button can be tabbed to */
|
|
22
|
+
tabbable?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare const ToolbarButton: React.ForwardRefExoticComponent<ToolbarButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
25
|
+
export default ToolbarButton;
|
package/esm/components/text-editor/__internal__/toolbar/toolbar-button/toolbar-button.component.js
CHANGED
|
@@ -25,8 +25,6 @@ const ToolbarButton = /*#__PURE__*/React.forwardRef(({
|
|
|
25
25
|
}, !tabbable && {
|
|
26
26
|
tabIndex: -1
|
|
27
27
|
}, {
|
|
28
|
-
activated: activated,
|
|
29
|
-
tabbable: tabbable,
|
|
30
28
|
onMouseOver: onMouseOver,
|
|
31
29
|
onMouseLeave: onMouseLeave,
|
|
32
30
|
onFocus: onFocus,
|
|
@@ -34,26 +32,17 @@ const ToolbarButton = /*#__PURE__*/React.forwardRef(({
|
|
|
34
32
|
}), children);
|
|
35
33
|
});
|
|
36
34
|
ToolbarButton.propTypes = {
|
|
37
|
-
|
|
38
|
-
ariaLabel: PropTypes.string.isRequired,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
onKeyDown: PropTypes.func.isRequired,
|
|
48
|
-
|
|
49
|
-
/** Callback to handle any mouse down events on a button */
|
|
50
|
-
onMouseDown: PropTypes.func.isRequired,
|
|
51
|
-
|
|
52
|
-
/** Controls whether the button can be tabbed to */
|
|
53
|
-
tabbable: PropTypes.bool,
|
|
54
|
-
onMouseOver: PropTypes.func,
|
|
55
|
-
onMouseLeave: PropTypes.func,
|
|
56
|
-
onFocus: PropTypes.func,
|
|
57
|
-
onBlur: PropTypes.func
|
|
35
|
+
"activated": PropTypes.bool,
|
|
36
|
+
"ariaLabel": PropTypes.string.isRequired,
|
|
37
|
+
"children": PropTypes.node,
|
|
38
|
+
"onBlur": PropTypes.func,
|
|
39
|
+
"onFocus": PropTypes.func,
|
|
40
|
+
"onKeyDown": PropTypes.func.isRequired,
|
|
41
|
+
"onMouseDown": PropTypes.func.isRequired,
|
|
42
|
+
"onMouseLeave": PropTypes.func,
|
|
43
|
+
"onMouseOver": PropTypes.func,
|
|
44
|
+
"tabbable": PropTypes.bool
|
|
58
45
|
};
|
|
46
|
+
export { ToolbarButton };
|
|
47
|
+
ToolbarButton.displayName = "ToolbarButton";
|
|
59
48
|
export default ToolbarButton;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { InlineStyleType, BlockType } from "../../types";
|
|
3
|
+
export interface ToolbarProps {
|
|
4
|
+
/** Used to override the active status of the inline controls */
|
|
5
|
+
activeControls: Record<InlineStyleType | BlockType, boolean>;
|
|
6
|
+
/** Flag to trigger control focusing */
|
|
7
|
+
canFocus?: boolean;
|
|
8
|
+
/** Callback to handle setting the inline styles */
|
|
9
|
+
setInlineStyle: (ev: React.KeyboardEvent<HTMLButtonElement> | React.MouseEvent<HTMLButtonElement>, inlineType: InlineStyleType) => void;
|
|
10
|
+
/** Callback to handle setting the block styles */
|
|
11
|
+
setBlockStyle: (ev: React.KeyboardEvent<HTMLButtonElement> | React.MouseEvent<HTMLButtonElement>, blockType: BlockType) => void;
|
|
12
|
+
/** Additional elements to be rendered in the Toolbar, e.g. Save and Cancel Button */
|
|
13
|
+
toolbarElements?: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
declare const Toolbar: ({ activeControls, canFocus, toolbarElements, setBlockStyle, setInlineStyle, }: ToolbarProps) => JSX.Element;
|
|
16
|
+
export default Toolbar;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useEffect,
|
|
1
|
+
import React, { useCallback, useEffect, useState, useRef } from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import { StyledToolbar, StyledEditorStyleControls, StyledEditorActionControls } from "./toolbar.style";
|
|
4
4
|
import ToolbarButton from "./toolbar-button";
|
|
@@ -6,10 +6,7 @@ import Events from "../../../../__internal__/utils/helpers/events";
|
|
|
6
6
|
import Icon from "../../../icon";
|
|
7
7
|
import Tooltip from "../../../tooltip";
|
|
8
8
|
import useLocale from "../../../../hooks/__internal__/useLocale";
|
|
9
|
-
|
|
10
|
-
const ITALIC = "ITALIC";
|
|
11
|
-
const UNORDERED_LIST = "unordered-list-item";
|
|
12
|
-
const ORDERED_LIST = "ordered-list-item";
|
|
9
|
+
import { BOLD, ITALIC, UNORDERED_LIST, ORDERED_LIST } from "../../types";
|
|
13
10
|
|
|
14
11
|
const Toolbar = ({
|
|
15
12
|
activeControls,
|
|
@@ -25,8 +22,8 @@ const Toolbar = ({
|
|
|
25
22
|
tooltipMessages,
|
|
26
23
|
ariaLabels
|
|
27
24
|
} = textEditor;
|
|
28
|
-
const controlRefs =
|
|
29
|
-
const [focusIndex, setFocusIndex] = useState(
|
|
25
|
+
const controlRefs = useRef([/*#__PURE__*/React.createRef(), /*#__PURE__*/React.createRef(), /*#__PURE__*/React.createRef(), /*#__PURE__*/React.createRef()]);
|
|
26
|
+
const [focusIndex, setFocusIndex] = useState(null);
|
|
30
27
|
const [tabbable, setTabbable] = useState(true);
|
|
31
28
|
const [activeTooltip, setActiveTooltip] = useState("");
|
|
32
29
|
const handleInlineStyleChange = useCallback((ev, inlineType) => {
|
|
@@ -39,7 +36,7 @@ const Toolbar = ({
|
|
|
39
36
|
if (Events.isTabKey(ev)) {
|
|
40
37
|
setFocusIndex(null);
|
|
41
38
|
} else if (Events.isSpaceKey(ev) || Events.isEnterKey(ev)) {
|
|
42
|
-
if (
|
|
39
|
+
if (type === BOLD || type === ITALIC) {
|
|
43
40
|
handleInlineStyleChange(ev, type);
|
|
44
41
|
} else {
|
|
45
42
|
handleBlockType(ev, type);
|
|
@@ -49,26 +46,35 @@ const Toolbar = ({
|
|
|
49
46
|
setTabbable(true);
|
|
50
47
|
} else if (Events.isLeftKey(ev)) {
|
|
51
48
|
if (focusIndex === null || focusIndex === 0) {
|
|
52
|
-
|
|
49
|
+
var _controlRefs$current$;
|
|
50
|
+
|
|
51
|
+
(_controlRefs$current$ = controlRefs.current[3].current) === null || _controlRefs$current$ === void 0 ? void 0 : _controlRefs$current$.focus();
|
|
53
52
|
setFocusIndex(3);
|
|
54
53
|
} else {
|
|
55
|
-
|
|
54
|
+
var _controlRefs$current$2;
|
|
55
|
+
|
|
56
|
+
(_controlRefs$current$2 = controlRefs.current[focusIndex - 1].current) === null || _controlRefs$current$2 === void 0 ? void 0 : _controlRefs$current$2.focus();
|
|
56
57
|
setFocusIndex(focusIndex - 1);
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
setTabbable(false);
|
|
60
61
|
} else if (Events.isRightKey(ev)) {
|
|
61
62
|
if (focusIndex === 3) {
|
|
62
|
-
|
|
63
|
+
var _controlRefs$current$3;
|
|
64
|
+
|
|
65
|
+
(_controlRefs$current$3 = controlRefs.current[0].current) === null || _controlRefs$current$3 === void 0 ? void 0 : _controlRefs$current$3.focus();
|
|
63
66
|
setFocusIndex(0);
|
|
64
67
|
} else {
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
var _controlRefs$current$4;
|
|
69
|
+
|
|
70
|
+
const currentIndex = focusIndex === null ? 0 : focusIndex;
|
|
71
|
+
(_controlRefs$current$4 = controlRefs.current[currentIndex + 1].current) === null || _controlRefs$current$4 === void 0 ? void 0 : _controlRefs$current$4.focus();
|
|
72
|
+
setFocusIndex(currentIndex + 1);
|
|
67
73
|
}
|
|
68
74
|
|
|
69
75
|
setTabbable(false);
|
|
70
76
|
}
|
|
71
|
-
}, [
|
|
77
|
+
}, [focusIndex, handleBlockType, handleInlineStyleChange]);
|
|
72
78
|
useEffect(() => {
|
|
73
79
|
if (focusIndex === null) {
|
|
74
80
|
setTabbable(true);
|
|
@@ -79,13 +85,15 @@ const Toolbar = ({
|
|
|
79
85
|
setFocusIndex(null);
|
|
80
86
|
}
|
|
81
87
|
}, [canFocus]);
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
|
|
89
|
+
const isTabbable = index => {
|
|
90
|
+
if (!controlRefs.current[index] || !controlRefs.current[index].current) {
|
|
84
91
|
return false;
|
|
85
92
|
}
|
|
86
93
|
|
|
87
|
-
return controlRefs[index].current === document.activeElement;
|
|
88
|
-
}
|
|
94
|
+
return controlRefs.current[index].current === document.activeElement;
|
|
95
|
+
};
|
|
96
|
+
|
|
89
97
|
return /*#__PURE__*/React.createElement(StyledToolbar, {
|
|
90
98
|
"data-component": "text-editor-toolbar"
|
|
91
99
|
}, /*#__PURE__*/React.createElement(StyledEditorStyleControls, null, /*#__PURE__*/React.createElement(Tooltip, {
|
|
@@ -97,7 +105,7 @@ const Toolbar = ({
|
|
|
97
105
|
onKeyDown: ev => handleKeyDown(ev, BOLD),
|
|
98
106
|
onMouseDown: ev => handleInlineStyleChange(ev, BOLD),
|
|
99
107
|
activated: activeControls.BOLD,
|
|
100
|
-
ref: controlRefs[0],
|
|
108
|
+
ref: controlRefs.current[0],
|
|
101
109
|
tabbable: tabbable,
|
|
102
110
|
onMouseOver: () => setActiveTooltip("Bold"),
|
|
103
111
|
onMouseLeave: () => setActiveTooltip(""),
|
|
@@ -114,7 +122,7 @@ const Toolbar = ({
|
|
|
114
122
|
onKeyDown: ev => handleKeyDown(ev, ITALIC),
|
|
115
123
|
onMouseDown: ev => handleInlineStyleChange(ev, ITALIC),
|
|
116
124
|
activated: activeControls.ITALIC,
|
|
117
|
-
ref: controlRefs[1],
|
|
125
|
+
ref: controlRefs.current[1],
|
|
118
126
|
tabbable: isTabbable(1),
|
|
119
127
|
onMouseOver: () => setActiveTooltip("Italic"),
|
|
120
128
|
onMouseLeave: () => setActiveTooltip(""),
|
|
@@ -131,7 +139,7 @@ const Toolbar = ({
|
|
|
131
139
|
onKeyDown: ev => handleKeyDown(ev, UNORDERED_LIST),
|
|
132
140
|
onMouseDown: ev => handleBlockType(ev, UNORDERED_LIST),
|
|
133
141
|
activated: activeControls[UNORDERED_LIST],
|
|
134
|
-
ref: controlRefs[2],
|
|
142
|
+
ref: controlRefs.current[2],
|
|
135
143
|
tabbable: isTabbable(2),
|
|
136
144
|
onMouseOver: () => setActiveTooltip("Bulleted List"),
|
|
137
145
|
onMouseLeave: () => setActiveTooltip(""),
|
|
@@ -148,7 +156,7 @@ const Toolbar = ({
|
|
|
148
156
|
onKeyDown: ev => handleKeyDown(ev, ORDERED_LIST),
|
|
149
157
|
onMouseDown: ev => handleBlockType(ev, ORDERED_LIST),
|
|
150
158
|
activated: activeControls[ORDERED_LIST],
|
|
151
|
-
ref: controlRefs[3],
|
|
159
|
+
ref: controlRefs.current[3],
|
|
152
160
|
tabbable: isTabbable(3),
|
|
153
161
|
onMouseOver: () => setActiveTooltip("Numbered List"),
|
|
154
162
|
onMouseLeave: () => setActiveTooltip(""),
|
|
@@ -160,19 +168,15 @@ const Toolbar = ({
|
|
|
160
168
|
};
|
|
161
169
|
|
|
162
170
|
Toolbar.propTypes = {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
setBlockStyle: PropTypes.func.isRequired,
|
|
174
|
-
|
|
175
|
-
/** Additional elements to be rendered in the Toolbar, e.g. Save and Cancel Button */
|
|
176
|
-
toolbarElements: PropTypes.node
|
|
171
|
+
"activeControls": PropTypes.shape({
|
|
172
|
+
"BOLD": PropTypes.bool.isRequired,
|
|
173
|
+
"ITALIC": PropTypes.bool.isRequired,
|
|
174
|
+
"ordered-list-item": PropTypes.bool.isRequired,
|
|
175
|
+
"unordered-list-item": PropTypes.bool.isRequired
|
|
176
|
+
}).isRequired,
|
|
177
|
+
"canFocus": PropTypes.bool,
|
|
178
|
+
"setBlockStyle": PropTypes.func.isRequired,
|
|
179
|
+
"setInlineStyle": PropTypes.func.isRequired,
|
|
180
|
+
"toolbarElements": PropTypes.node
|
|
177
181
|
};
|
|
178
182
|
export default Toolbar;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const StyledToolbar: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
2
|
+
declare const StyledEditorStyleControls: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
3
|
+
declare const StyledEditorActionControls: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
|
+
export { StyledToolbar, StyledEditorActionControls, StyledEditorStyleControls };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { computeBlockType, getContent, getContentInfo, getDecoratedValue, getSelection, getSelectionInfo, getSelectedLength, moveSelectionToEnd, resetBlockType, isASCIIChar, replaceText, hasBlockStyle, hasInlineStyle, blockStyleFn } from "./utils";
|
|
1
|
+
export { computeBlockType, getContent, getContentInfo, getDecoratedValue, getSelection, getSelectionInfo, getSelectedLength, moveSelectionToEnd, resetBlockType, isASCIIChar, replaceText, hasBlockStyle, hasInlineStyle, blockStyleFn, } from "./utils";
|
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export function
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
blockText: any;
|
|
17
|
-
blockMap: any;
|
|
1
|
+
import { EditorState, ContentBlock, DraftInlineStyle, ContentState } from "draft-js";
|
|
2
|
+
import { BlockType, InlineStyleType } from "../../types";
|
|
3
|
+
export declare const computeBlockType: (char: string, type: string) => "unordered-list-item" | "ordered-list-item" | "unstyled";
|
|
4
|
+
export declare const resetBlockType: (value: EditorState, newType?: BlockType | "unstyled") => EditorState;
|
|
5
|
+
export declare function blockStyleFn(block: ContentBlock): "" | "text-editor-block-unordered" | "text-editor-block-ordered";
|
|
6
|
+
export declare const getDecoratedValue: (value: EditorState) => EditorState;
|
|
7
|
+
export declare const getContent: (value: EditorState) => ContentState;
|
|
8
|
+
export declare const getSelection: (value: EditorState) => Draft.Model.ImmutableData.SelectionState;
|
|
9
|
+
export declare const getContentInfo: (value: EditorState) => {
|
|
10
|
+
content: ContentState;
|
|
11
|
+
currentBlock: ContentBlock;
|
|
12
|
+
blockType: string;
|
|
13
|
+
blockLength: number;
|
|
14
|
+
blockText: string;
|
|
15
|
+
blockMap: Draft.Model.ImmutableData.BlockMap;
|
|
18
16
|
};
|
|
19
|
-
export
|
|
20
|
-
selection:
|
|
21
|
-
startKey:
|
|
22
|
-
endKey:
|
|
23
|
-
startOffset:
|
|
24
|
-
endOffset:
|
|
17
|
+
export declare const getSelectionInfo: (value: EditorState) => {
|
|
18
|
+
selection: Draft.Model.ImmutableData.SelectionState;
|
|
19
|
+
startKey: string;
|
|
20
|
+
endKey: string;
|
|
21
|
+
startOffset: number;
|
|
22
|
+
endOffset: number;
|
|
25
23
|
};
|
|
26
|
-
export
|
|
27
|
-
export
|
|
28
|
-
|
|
24
|
+
export declare const moveSelectionToEnd: (value: EditorState) => EditorState;
|
|
25
|
+
export declare const getSelectedLength: (value: EditorState) => number;
|
|
26
|
+
export declare function hasBlockStyle(value: EditorState, type: BlockType): boolean;
|
|
27
|
+
export declare function hasInlineStyle(value: EditorState, style: InlineStyleType): boolean;
|
|
28
|
+
export declare function isASCIIChar(str: string): boolean;
|
|
29
|
+
export declare function replaceText(editorState: EditorState, text: string, inlineStyle: DraftInlineStyle): EditorState;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { EditorState, Modifier } from "draft-js";
|
|
2
2
|
import decorators from "../decorators";
|
|
3
|
-
|
|
4
|
-
const UNORDERLIST_TYPE = "unordered-list-item";
|
|
3
|
+
import { ORDERED_LIST, UNORDERED_LIST } from "../../types";
|
|
5
4
|
export const computeBlockType = (char, type) => {
|
|
6
|
-
if (char === "." && type !==
|
|
7
|
-
return
|
|
5
|
+
if (char === "." && type !== ORDERED_LIST) {
|
|
6
|
+
return ORDERED_LIST;
|
|
8
7
|
}
|
|
9
8
|
|
|
10
|
-
if (char === "*" && type !==
|
|
11
|
-
return
|
|
9
|
+
if (char === "*" && type !== UNORDERED_LIST) {
|
|
10
|
+
return UNORDERED_LIST;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
return "unstyled";
|
|
@@ -19,10 +18,10 @@ Returns default block-level metadata for various block type. Empty object otherw
|
|
|
19
18
|
|
|
20
19
|
const getDefaultBlockData = (blockType, initialData = {}) => {
|
|
21
20
|
switch (blockType) {
|
|
22
|
-
case
|
|
21
|
+
case ORDERED_LIST:
|
|
23
22
|
return {};
|
|
24
23
|
|
|
25
|
-
case
|
|
24
|
+
case UNORDERED_LIST:
|
|
26
25
|
return {};
|
|
27
26
|
|
|
28
27
|
default:
|
|
@@ -181,7 +180,7 @@ export function hasInlineStyle(value, style) {
|
|
|
181
180
|
export function isASCIIChar(str) {
|
|
182
181
|
return /^\S+$/.test(str);
|
|
183
182
|
}
|
|
184
|
-
export function replaceText(editorState, text, inlineStyle
|
|
183
|
+
export function replaceText(editorState, text, inlineStyle) {
|
|
185
184
|
const contentState = Modifier.replaceText(editorState.getCurrentContent(), editorState.getSelection(), text, inlineStyle);
|
|
186
|
-
return EditorState.push(editorState, contentState, "insert-characters"
|
|
185
|
+
return EditorState.push(editorState, contentState, "insert-characters");
|
|
187
186
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./text-editor";
|
|
2
|
-
export
|
|
1
|
+
export { default, TextEditorState as EditorState, TextEditorContentState as ContentState, } from "./text-editor.component";
|
|
2
|
+
export type { TextEditorProps } from "./text-editor.component";
|
|
@@ -1,8 +1,37 @@
|
|
|
1
|
-
export const EditorContext: React.Context<{}>;
|
|
2
|
-
export const TextEditorState: typeof EditorState;
|
|
3
|
-
export const TextEditorContentState: typeof ContentState;
|
|
4
|
-
export default TextEditor;
|
|
5
1
|
import React from "react";
|
|
6
|
-
import {
|
|
7
|
-
import { ContentState } from "draft-js";
|
|
8
|
-
declare const
|
|
2
|
+
import { MarginProps } from "styled-system";
|
|
3
|
+
import { ContentState, EditorState, Editor } from "draft-js";
|
|
4
|
+
export declare const EditorContext: React.Context<{
|
|
5
|
+
onLinkAdded?: ((url: string) => void) | undefined;
|
|
6
|
+
editMode?: boolean | undefined;
|
|
7
|
+
}>;
|
|
8
|
+
export interface TextEditorProps extends MarginProps {
|
|
9
|
+
/** The maximum characters that the input will accept */
|
|
10
|
+
characterLimit?: number;
|
|
11
|
+
/** The text for the editor's label */
|
|
12
|
+
labelText: string;
|
|
13
|
+
/** onChange callback to control value updates */
|
|
14
|
+
onChange: (event: EditorState) => void;
|
|
15
|
+
/** Additional elements to be rendered in the Editor Toolbar, e.g. Save and Cancel Button */
|
|
16
|
+
toolbarElements?: React.ReactNode;
|
|
17
|
+
/** The value of the input, this is an EditorState immutable object */
|
|
18
|
+
value: EditorState;
|
|
19
|
+
/** Flag to configure component as mandatory */
|
|
20
|
+
required?: boolean;
|
|
21
|
+
/** Message to be displayed when there is an error */
|
|
22
|
+
error?: string;
|
|
23
|
+
/** Message to be displayed when there is a warning */
|
|
24
|
+
warning?: string;
|
|
25
|
+
/** Message to be displayed when there is an info */
|
|
26
|
+
info?: string;
|
|
27
|
+
/** Number greater than 2 multiplied by line-height (21px) to override the default min-height of the editor */
|
|
28
|
+
rows?: number;
|
|
29
|
+
/** The previews to display of any links added to the Editor */
|
|
30
|
+
previews?: React.ReactNode;
|
|
31
|
+
/** Callback to report a url when a link is added */
|
|
32
|
+
onLinkAdded?: (url: string) => void;
|
|
33
|
+
}
|
|
34
|
+
export declare const TextEditor: React.ForwardRefExoticComponent<TextEditorProps & React.RefAttributes<Editor>>;
|
|
35
|
+
export declare const TextEditorState: typeof EditorState;
|
|
36
|
+
export declare const TextEditorContentState: typeof ContentState;
|
|
37
|
+
export default TextEditor;
|