carbon-react 118.2.1 → 118.3.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/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/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/hooks/__internal__/useFloating/useFloating.js +6 -2
- 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/esm/style/design-tokens/debug-theme.util.d.ts +17 -0
- package/esm/style/themes/sage/index.d.ts +17 -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/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/hooks/__internal__/useFloating/useFloating.js +6 -2
- 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/lib/style/design-tokens/debug-theme.util.d.ts +17 -0
- package/lib/style/themes/sage/index.d.ts +17 -0
- package/package.json +6 -6
- 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
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ContentBlock } from "draft-js";
|
|
3
|
+
declare type StrategyCallback = (start: number, end: number) => void;
|
|
4
|
+
declare const _default: {
|
|
5
|
+
strategy: (contentBlock: ContentBlock, callback: StrategyCallback) => void;
|
|
6
|
+
component: ({ children, contentState, entityKey, ...rest }: import("../editor-link").EditorLinkProps) => JSX.Element;
|
|
7
|
+
};
|
|
5
8
|
export default _default;
|
|
6
|
-
declare function linkStrategy(contentBlock: any, callback: any): void;
|
|
7
|
-
import EditorLink from "../editor-link";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface EditorCounterProps {
|
|
3
|
+
/** Sets the current count value */
|
|
4
|
+
count?: number;
|
|
5
|
+
/** Sets the current limit value */
|
|
6
|
+
limit?: number;
|
|
7
|
+
/** Message to be displayed when there is an error */
|
|
8
|
+
error?: string;
|
|
9
|
+
/** Message to be displayed when there is a warning */
|
|
10
|
+
warning?: string;
|
|
11
|
+
/** Message to be displayed when there is an info */
|
|
12
|
+
info?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const Counter: ({ count, limit, error, warning, info, }: EditorCounterProps) => JSX.Element;
|
|
15
|
+
export default Counter;
|
|
@@ -22,7 +22,6 @@ const Counter = ({
|
|
|
22
22
|
warning,
|
|
23
23
|
info
|
|
24
24
|
}) => /*#__PURE__*/_react.default.createElement(_editorCounter.StyledCounterWrapper, {
|
|
25
|
-
hasIcon: !!(error || warning || info),
|
|
26
25
|
"data-component": "text-editor-counter"
|
|
27
26
|
}, !!(error || warning || info) && /*#__PURE__*/_react.default.createElement(_validations.default, {
|
|
28
27
|
error: error,
|
|
@@ -35,20 +34,11 @@ const Counter = ({
|
|
|
35
34
|
}, `${limit - count}`));
|
|
36
35
|
|
|
37
36
|
Counter.propTypes = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/** Message to be displayed when there is an error */
|
|
45
|
-
error: _propTypes.default.string,
|
|
46
|
-
|
|
47
|
-
/** Message to be displayed when there is a warning */
|
|
48
|
-
warning: _propTypes.default.string,
|
|
49
|
-
|
|
50
|
-
/** Message to be displayed when there is an info */
|
|
51
|
-
info: _propTypes.default.string
|
|
37
|
+
"count": _propTypes.default.number,
|
|
38
|
+
"error": _propTypes.default.string,
|
|
39
|
+
"info": _propTypes.default.string,
|
|
40
|
+
"limit": _propTypes.default.number,
|
|
41
|
+
"warning": _propTypes.default.string
|
|
52
42
|
};
|
|
53
43
|
var _default = Counter;
|
|
54
44
|
exports.default = _default;
|
|
@@ -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;
|
|
@@ -48,7 +48,6 @@ const EditorLink = ({
|
|
|
48
48
|
}, [validUrl]);
|
|
49
49
|
return /*#__PURE__*/_react.default.createElement(_editorLink.default, _extends({
|
|
50
50
|
href: !editMode ? validUrl : undefined,
|
|
51
|
-
title: validUrl,
|
|
52
51
|
"aria-label": !editMode ? validUrl : undefined,
|
|
53
52
|
target: "_blank",
|
|
54
53
|
rel: "noopener noreferrer"
|
|
@@ -56,9 +55,9 @@ const EditorLink = ({
|
|
|
56
55
|
};
|
|
57
56
|
|
|
58
57
|
EditorLink.propTypes = {
|
|
59
|
-
children: _propTypes.default.
|
|
60
|
-
contentState: _propTypes.default.object,
|
|
61
|
-
entityKey: _propTypes.default.string
|
|
58
|
+
"children": _propTypes.default.arrayOf(_propTypes.default.element).isRequired,
|
|
59
|
+
"contentState": _propTypes.default.object,
|
|
60
|
+
"entityKey": _propTypes.default.string
|
|
62
61
|
};
|
|
63
62
|
var _default = EditorLink;
|
|
64
63
|
exports.default = _default;
|
|
@@ -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;
|
|
@@ -14,12 +14,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
14
14
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
15
15
|
|
|
16
16
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* TextEditor component is composed with divs and spans.
|
|
20
|
-
* We have to manually trigger focus on TextEditor by clicking on label component.
|
|
21
|
-
* This wrapper allows us to trigger focus on TextEditor
|
|
22
|
-
*/
|
|
23
17
|
const LabelWrapper = ({
|
|
24
18
|
onClick,
|
|
25
19
|
children
|
|
@@ -30,8 +24,8 @@ const LabelWrapper = ({
|
|
|
30
24
|
};
|
|
31
25
|
|
|
32
26
|
LabelWrapper.propTypes = {
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
"children": _propTypes.default.node,
|
|
28
|
+
"onClick": _propTypes.default.func.isRequired
|
|
35
29
|
};
|
|
36
30
|
var _default = LabelWrapper;
|
|
37
31
|
exports.default = _default;
|
|
@@ -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/lib/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/lib/components/text-editor/__internal__/toolbar/toolbar-button/toolbar-button.component.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.ToolbarButton = void 0;
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
@@ -37,8 +37,6 @@ const ToolbarButton = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
37
37
|
}, !tabbable && {
|
|
38
38
|
tabIndex: -1
|
|
39
39
|
}, {
|
|
40
|
-
activated: activated,
|
|
41
|
-
tabbable: tabbable,
|
|
42
40
|
onMouseOver: onMouseOver,
|
|
43
41
|
onMouseLeave: onMouseLeave,
|
|
44
42
|
onFocus: onFocus,
|
|
@@ -46,28 +44,19 @@ const ToolbarButton = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
46
44
|
}), children);
|
|
47
45
|
});
|
|
48
46
|
|
|
47
|
+
exports.ToolbarButton = ToolbarButton;
|
|
49
48
|
ToolbarButton.propTypes = {
|
|
50
|
-
|
|
51
|
-
ariaLabel: _propTypes.default.string.isRequired,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
onKeyDown: _propTypes.default.func.isRequired,
|
|
61
|
-
|
|
62
|
-
/** Callback to handle any mouse down events on a button */
|
|
63
|
-
onMouseDown: _propTypes.default.func.isRequired,
|
|
64
|
-
|
|
65
|
-
/** Controls whether the button can be tabbed to */
|
|
66
|
-
tabbable: _propTypes.default.bool,
|
|
67
|
-
onMouseOver: _propTypes.default.func,
|
|
68
|
-
onMouseLeave: _propTypes.default.func,
|
|
69
|
-
onFocus: _propTypes.default.func,
|
|
70
|
-
onBlur: _propTypes.default.func
|
|
49
|
+
"activated": _propTypes.default.bool,
|
|
50
|
+
"ariaLabel": _propTypes.default.string.isRequired,
|
|
51
|
+
"children": _propTypes.default.node,
|
|
52
|
+
"onBlur": _propTypes.default.func,
|
|
53
|
+
"onFocus": _propTypes.default.func,
|
|
54
|
+
"onKeyDown": _propTypes.default.func.isRequired,
|
|
55
|
+
"onMouseDown": _propTypes.default.func.isRequired,
|
|
56
|
+
"onMouseLeave": _propTypes.default.func,
|
|
57
|
+
"onMouseOver": _propTypes.default.func,
|
|
58
|
+
"tabbable": _propTypes.default.bool
|
|
71
59
|
};
|
|
60
|
+
ToolbarButton.displayName = "ToolbarButton";
|
|
72
61
|
var _default = ToolbarButton;
|
|
73
62
|
exports.default = _default;
|
|
@@ -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;
|
|
@@ -21,17 +21,14 @@ var _tooltip = _interopRequireDefault(require("../../../tooltip"));
|
|
|
21
21
|
|
|
22
22
|
var _useLocale = _interopRequireDefault(require("../../../../hooks/__internal__/useLocale"));
|
|
23
23
|
|
|
24
|
+
var _types = require("../../types");
|
|
25
|
+
|
|
24
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
27
|
|
|
26
28
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
27
29
|
|
|
28
30
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
31
|
|
|
30
|
-
const BOLD = "BOLD";
|
|
31
|
-
const ITALIC = "ITALIC";
|
|
32
|
-
const UNORDERED_LIST = "unordered-list-item";
|
|
33
|
-
const ORDERED_LIST = "ordered-list-item";
|
|
34
|
-
|
|
35
32
|
const Toolbar = ({
|
|
36
33
|
activeControls,
|
|
37
34
|
canFocus,
|
|
@@ -46,8 +43,8 @@ const Toolbar = ({
|
|
|
46
43
|
tooltipMessages,
|
|
47
44
|
ariaLabels
|
|
48
45
|
} = textEditor;
|
|
49
|
-
const controlRefs =
|
|
50
|
-
const [focusIndex, setFocusIndex] = (0, _react.useState)(
|
|
46
|
+
const controlRefs = (0, _react.useRef)([/*#__PURE__*/_react.default.createRef(), /*#__PURE__*/_react.default.createRef(), /*#__PURE__*/_react.default.createRef(), /*#__PURE__*/_react.default.createRef()]);
|
|
47
|
+
const [focusIndex, setFocusIndex] = (0, _react.useState)(null);
|
|
51
48
|
const [tabbable, setTabbable] = (0, _react.useState)(true);
|
|
52
49
|
const [activeTooltip, setActiveTooltip] = (0, _react.useState)("");
|
|
53
50
|
const handleInlineStyleChange = (0, _react.useCallback)((ev, inlineType) => {
|
|
@@ -60,7 +57,7 @@ const Toolbar = ({
|
|
|
60
57
|
if (_events.default.isTabKey(ev)) {
|
|
61
58
|
setFocusIndex(null);
|
|
62
59
|
} else if (_events.default.isSpaceKey(ev) || _events.default.isEnterKey(ev)) {
|
|
63
|
-
if (
|
|
60
|
+
if (type === _types.BOLD || type === _types.ITALIC) {
|
|
64
61
|
handleInlineStyleChange(ev, type);
|
|
65
62
|
} else {
|
|
66
63
|
handleBlockType(ev, type);
|
|
@@ -70,26 +67,35 @@ const Toolbar = ({
|
|
|
70
67
|
setTabbable(true);
|
|
71
68
|
} else if (_events.default.isLeftKey(ev)) {
|
|
72
69
|
if (focusIndex === null || focusIndex === 0) {
|
|
73
|
-
|
|
70
|
+
var _controlRefs$current$;
|
|
71
|
+
|
|
72
|
+
(_controlRefs$current$ = controlRefs.current[3].current) === null || _controlRefs$current$ === void 0 ? void 0 : _controlRefs$current$.focus();
|
|
74
73
|
setFocusIndex(3);
|
|
75
74
|
} else {
|
|
76
|
-
|
|
75
|
+
var _controlRefs$current$2;
|
|
76
|
+
|
|
77
|
+
(_controlRefs$current$2 = controlRefs.current[focusIndex - 1].current) === null || _controlRefs$current$2 === void 0 ? void 0 : _controlRefs$current$2.focus();
|
|
77
78
|
setFocusIndex(focusIndex - 1);
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
setTabbable(false);
|
|
81
82
|
} else if (_events.default.isRightKey(ev)) {
|
|
82
83
|
if (focusIndex === 3) {
|
|
83
|
-
|
|
84
|
+
var _controlRefs$current$3;
|
|
85
|
+
|
|
86
|
+
(_controlRefs$current$3 = controlRefs.current[0].current) === null || _controlRefs$current$3 === void 0 ? void 0 : _controlRefs$current$3.focus();
|
|
84
87
|
setFocusIndex(0);
|
|
85
88
|
} else {
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
var _controlRefs$current$4;
|
|
90
|
+
|
|
91
|
+
const currentIndex = focusIndex === null ? 0 : focusIndex;
|
|
92
|
+
(_controlRefs$current$4 = controlRefs.current[currentIndex + 1].current) === null || _controlRefs$current$4 === void 0 ? void 0 : _controlRefs$current$4.focus();
|
|
93
|
+
setFocusIndex(currentIndex + 1);
|
|
88
94
|
}
|
|
89
95
|
|
|
90
96
|
setTabbable(false);
|
|
91
97
|
}
|
|
92
|
-
}, [
|
|
98
|
+
}, [focusIndex, handleBlockType, handleInlineStyleChange]);
|
|
93
99
|
(0, _react.useEffect)(() => {
|
|
94
100
|
if (focusIndex === null) {
|
|
95
101
|
setTabbable(true);
|
|
@@ -100,13 +106,15 @@ const Toolbar = ({
|
|
|
100
106
|
setFocusIndex(null);
|
|
101
107
|
}
|
|
102
108
|
}, [canFocus]);
|
|
103
|
-
|
|
104
|
-
|
|
109
|
+
|
|
110
|
+
const isTabbable = index => {
|
|
111
|
+
if (!controlRefs.current[index] || !controlRefs.current[index].current) {
|
|
105
112
|
return false;
|
|
106
113
|
}
|
|
107
114
|
|
|
108
|
-
return controlRefs[index].current === document.activeElement;
|
|
109
|
-
}
|
|
115
|
+
return controlRefs.current[index].current === document.activeElement;
|
|
116
|
+
};
|
|
117
|
+
|
|
110
118
|
return /*#__PURE__*/_react.default.createElement(_toolbar.StyledToolbar, {
|
|
111
119
|
"data-component": "text-editor-toolbar"
|
|
112
120
|
}, /*#__PURE__*/_react.default.createElement(_toolbar.StyledEditorStyleControls, null, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
@@ -115,10 +123,10 @@ const Toolbar = ({
|
|
|
115
123
|
position: "top"
|
|
116
124
|
}, /*#__PURE__*/_react.default.createElement(_toolbarButton.default, {
|
|
117
125
|
ariaLabel: ariaLabels.bold(),
|
|
118
|
-
onKeyDown: ev => handleKeyDown(ev, BOLD),
|
|
119
|
-
onMouseDown: ev => handleInlineStyleChange(ev, BOLD),
|
|
126
|
+
onKeyDown: ev => handleKeyDown(ev, _types.BOLD),
|
|
127
|
+
onMouseDown: ev => handleInlineStyleChange(ev, _types.BOLD),
|
|
120
128
|
activated: activeControls.BOLD,
|
|
121
|
-
ref: controlRefs[0],
|
|
129
|
+
ref: controlRefs.current[0],
|
|
122
130
|
tabbable: tabbable,
|
|
123
131
|
onMouseOver: () => setActiveTooltip("Bold"),
|
|
124
132
|
onMouseLeave: () => setActiveTooltip(""),
|
|
@@ -132,10 +140,10 @@ const Toolbar = ({
|
|
|
132
140
|
position: "top"
|
|
133
141
|
}, /*#__PURE__*/_react.default.createElement(_toolbarButton.default, {
|
|
134
142
|
ariaLabel: ariaLabels.italic(),
|
|
135
|
-
onKeyDown: ev => handleKeyDown(ev, ITALIC),
|
|
136
|
-
onMouseDown: ev => handleInlineStyleChange(ev, ITALIC),
|
|
143
|
+
onKeyDown: ev => handleKeyDown(ev, _types.ITALIC),
|
|
144
|
+
onMouseDown: ev => handleInlineStyleChange(ev, _types.ITALIC),
|
|
137
145
|
activated: activeControls.ITALIC,
|
|
138
|
-
ref: controlRefs[1],
|
|
146
|
+
ref: controlRefs.current[1],
|
|
139
147
|
tabbable: isTabbable(1),
|
|
140
148
|
onMouseOver: () => setActiveTooltip("Italic"),
|
|
141
149
|
onMouseLeave: () => setActiveTooltip(""),
|
|
@@ -149,10 +157,10 @@ const Toolbar = ({
|
|
|
149
157
|
position: "top"
|
|
150
158
|
}, /*#__PURE__*/_react.default.createElement(_toolbarButton.default, {
|
|
151
159
|
ariaLabel: ariaLabels.bulletList(),
|
|
152
|
-
onKeyDown: ev => handleKeyDown(ev, UNORDERED_LIST),
|
|
153
|
-
onMouseDown: ev => handleBlockType(ev, UNORDERED_LIST),
|
|
154
|
-
activated: activeControls[UNORDERED_LIST],
|
|
155
|
-
ref: controlRefs[2],
|
|
160
|
+
onKeyDown: ev => handleKeyDown(ev, _types.UNORDERED_LIST),
|
|
161
|
+
onMouseDown: ev => handleBlockType(ev, _types.UNORDERED_LIST),
|
|
162
|
+
activated: activeControls[_types.UNORDERED_LIST],
|
|
163
|
+
ref: controlRefs.current[2],
|
|
156
164
|
tabbable: isTabbable(2),
|
|
157
165
|
onMouseOver: () => setActiveTooltip("Bulleted List"),
|
|
158
166
|
onMouseLeave: () => setActiveTooltip(""),
|
|
@@ -166,10 +174,10 @@ const Toolbar = ({
|
|
|
166
174
|
position: "top"
|
|
167
175
|
}, /*#__PURE__*/_react.default.createElement(_toolbarButton.default, {
|
|
168
176
|
ariaLabel: ariaLabels.numberList(),
|
|
169
|
-
onKeyDown: ev => handleKeyDown(ev, ORDERED_LIST),
|
|
170
|
-
onMouseDown: ev => handleBlockType(ev, ORDERED_LIST),
|
|
171
|
-
activated: activeControls[ORDERED_LIST],
|
|
172
|
-
ref: controlRefs[3],
|
|
177
|
+
onKeyDown: ev => handleKeyDown(ev, _types.ORDERED_LIST),
|
|
178
|
+
onMouseDown: ev => handleBlockType(ev, _types.ORDERED_LIST),
|
|
179
|
+
activated: activeControls[_types.ORDERED_LIST],
|
|
180
|
+
ref: controlRefs.current[3],
|
|
173
181
|
tabbable: isTabbable(3),
|
|
174
182
|
onMouseOver: () => setActiveTooltip("Numbered List"),
|
|
175
183
|
onMouseLeave: () => setActiveTooltip(""),
|
|
@@ -181,20 +189,16 @@ const Toolbar = ({
|
|
|
181
189
|
};
|
|
182
190
|
|
|
183
191
|
Toolbar.propTypes = {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
setBlockStyle: _propTypes.default.func.isRequired,
|
|
195
|
-
|
|
196
|
-
/** Additional elements to be rendered in the Toolbar, e.g. Save and Cancel Button */
|
|
197
|
-
toolbarElements: _propTypes.default.node
|
|
192
|
+
"activeControls": _propTypes.default.shape({
|
|
193
|
+
"BOLD": _propTypes.default.bool.isRequired,
|
|
194
|
+
"ITALIC": _propTypes.default.bool.isRequired,
|
|
195
|
+
"ordered-list-item": _propTypes.default.bool.isRequired,
|
|
196
|
+
"unordered-list-item": _propTypes.default.bool.isRequired
|
|
197
|
+
}).isRequired,
|
|
198
|
+
"canFocus": _propTypes.default.bool,
|
|
199
|
+
"setBlockStyle": _propTypes.default.func.isRequired,
|
|
200
|
+
"setInlineStyle": _propTypes.default.func.isRequired,
|
|
201
|
+
"toolbarElements": _propTypes.default.node
|
|
198
202
|
};
|
|
199
203
|
var _default = Toolbar;
|
|
200
204
|
exports.default = _default;
|
|
@@ -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;
|
|
@@ -14,18 +14,17 @@ var _draftJs = require("draft-js");
|
|
|
14
14
|
|
|
15
15
|
var _decorators = _interopRequireDefault(require("../decorators"));
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
var _types = require("../../types");
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
const UNORDERLIST_TYPE = "unordered-list-item";
|
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
20
|
|
|
22
21
|
const computeBlockType = (char, type) => {
|
|
23
|
-
if (char === "." && type !==
|
|
24
|
-
return
|
|
22
|
+
if (char === "." && type !== _types.ORDERED_LIST) {
|
|
23
|
+
return _types.ORDERED_LIST;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
if (char === "*" && type !==
|
|
28
|
-
return
|
|
26
|
+
if (char === "*" && type !== _types.UNORDERED_LIST) {
|
|
27
|
+
return _types.UNORDERED_LIST;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
return "unstyled";
|
|
@@ -39,10 +38,10 @@ exports.computeBlockType = computeBlockType;
|
|
|
39
38
|
|
|
40
39
|
const getDefaultBlockData = (blockType, initialData = {}) => {
|
|
41
40
|
switch (blockType) {
|
|
42
|
-
case
|
|
41
|
+
case _types.ORDERED_LIST:
|
|
43
42
|
return {};
|
|
44
43
|
|
|
45
|
-
case
|
|
44
|
+
case _types.UNORDERED_LIST:
|
|
46
45
|
return {};
|
|
47
46
|
|
|
48
47
|
default:
|
|
@@ -229,8 +228,8 @@ function isASCIIChar(str) {
|
|
|
229
228
|
return /^\S+$/.test(str);
|
|
230
229
|
}
|
|
231
230
|
|
|
232
|
-
function replaceText(editorState, text, inlineStyle
|
|
231
|
+
function replaceText(editorState, text, inlineStyle) {
|
|
233
232
|
const contentState = _draftJs.Modifier.replaceText(editorState.getCurrentContent(), editorState.getSelection(), text, inlineStyle);
|
|
234
233
|
|
|
235
|
-
return _draftJs.EditorState.push(editorState, contentState, "insert-characters"
|
|
234
|
+
return _draftJs.EditorState.push(editorState, contentState, "insert-characters");
|
|
236
235
|
}
|
|
@@ -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";
|