carbon-react 154.13.1 → 154.13.2
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/__internal__/validation-message/validation-message.component.d.ts +3 -2
- package/esm/__internal__/validation-message/validation-message.component.js +1 -1
- package/esm/components/text-editor/text-editor.component.d.ts +4 -0
- package/esm/components/text-editor/text-editor.component.js +1 -1
- package/esm/components/text-editor/text-editor.style.d.ts +2 -11
- package/esm/components/text-editor/text-editor.style.js +1 -1
- package/lib/__internal__/validation-message/validation-message.component.d.ts +3 -2
- package/lib/__internal__/validation-message/validation-message.component.js +1 -1
- package/lib/components/text-editor/text-editor.component.d.ts +4 -0
- package/lib/components/text-editor/text-editor.component.js +1 -1
- package/lib/components/text-editor/text-editor.style.d.ts +2 -11
- package/lib/components/text-editor/text-editor.style.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
2
|
+
import { TagProps } from "../../__internal__/utils/helpers/tags";
|
|
3
|
+
export interface ValidationMessageProps extends TagProps {
|
|
3
4
|
/** Indicate that error has occurred
|
|
4
5
|
Pass string to display hint with error */
|
|
5
6
|
error?: boolean | string;
|
|
@@ -11,5 +12,5 @@ export interface ValidationMessageProps {
|
|
|
11
12
|
/** Whether this component resides on a dark background */
|
|
12
13
|
isDarkBackground?: boolean;
|
|
13
14
|
}
|
|
14
|
-
declare const ValidationMessage: ({ error, validationId, warning, isDarkBackground, }: ValidationMessageProps) => React.JSX.Element | null;
|
|
15
|
+
declare const ValidationMessage: ({ error, validationId, warning, isDarkBackground, "data-element": dataElement, "data-role": dataRole, }: ValidationMessageProps) => React.JSX.Element | null;
|
|
15
16
|
export default ValidationMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import"react";import t from"./validation-message.style.js";import r from"../utils/helpers/tags/tags.js";function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const o=({error:o,validationId:a,warning:i,isDarkBackground:c,"data-element":s,"data-role":l="validation-message"})=>{const p=o||i;return"string"==typeof p?e(t,(u=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},o=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),o.forEach((function(t){n(e,t,r[t])}))}return e}({id:a,isWarning:!(o||!i),isDarkBackground:c},r("validation-message",{"data-element":s,"data-role":l})),b=null!=(b={children:p})?b:{},Object.getOwnPropertyDescriptors?Object.defineProperties(u,Object.getOwnPropertyDescriptors(b)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(b)).forEach((function(e){Object.defineProperty(u,e,Object.getOwnPropertyDescriptor(b,e))})),u)):null;var u,b};export{o as default};
|
|
@@ -53,6 +53,10 @@ export interface TextEditorProps extends MarginProps, TagProps {
|
|
|
53
53
|
warning?: string;
|
|
54
54
|
/** The initial value of the editor, as a HTML string, or JSON */
|
|
55
55
|
value?: string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Allows the injection of one or more Lexical-compatible React components into the editor to extend its functionality.
|
|
58
|
+
* This prop is optional and supports a single plugin, multiple plugins (via fragments or arrays), or `null`.
|
|
59
|
+
*/
|
|
56
60
|
customPlugins?: React.ReactNode;
|
|
57
61
|
}
|
|
58
62
|
export declare const TextEditor: React.ForwardRefExoticComponent<TextEditorProps & React.RefAttributes<TextEditorHandle>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as r}from"react/jsx-runtime";import{LexicalComposer as t}from"@lexical/react/LexicalComposer";import{ClickableLinkPlugin as n}from"@lexical/react/LexicalClickableLinkPlugin";import{EditorRefPlugin as o}from"@lexical/react/LexicalEditorRefPlugin";import{LexicalErrorBoundary as i}from"@lexical/react/LexicalErrorBoundary";import{HistoryPlugin as a}from"@lexical/react/LexicalHistoryPlugin";import{MarkdownShortcutPlugin as l}from"@lexical/react/LexicalMarkdownShortcutPlugin";import{RichTextPlugin as c}from"@lexical/react/LexicalRichTextPlugin";import{LinkPlugin as s}from"@lexical/react/LexicalLinkPlugin";import{ListPlugin as p}from"@lexical/react/LexicalListPlugin";import{$getRoot as u}from"lexical";import{forwardRef as d,useRef as m,useState as f,useImperativeHandle as _,useEffect as g,useMemo as
|
|
1
|
+
import{jsx as e,jsxs as r}from"react/jsx-runtime";import{LexicalComposer as t}from"@lexical/react/LexicalComposer";import{ClickableLinkPlugin as n}from"@lexical/react/LexicalClickableLinkPlugin";import{EditorRefPlugin as o}from"@lexical/react/LexicalEditorRefPlugin";import{LexicalErrorBoundary as i}from"@lexical/react/LexicalErrorBoundary";import{HistoryPlugin as a}from"@lexical/react/LexicalHistoryPlugin";import{MarkdownShortcutPlugin as l}from"@lexical/react/LexicalMarkdownShortcutPlugin";import{RichTextPlugin as c}from"@lexical/react/LexicalRichTextPlugin";import{LinkPlugin as s}from"@lexical/react/LexicalLinkPlugin";import{ListPlugin as p}from"@lexical/react/LexicalListPlugin";import{$getRoot as u}from"lexical";import{forwardRef as d,useRef as m,useState as f,useImperativeHandle as _,useEffect as g,useMemo as b,useCallback as h}from"react";import{SerializeLexical as v,validateUrl as x}from"./__internal__/helpers.js";import j from"../../__internal__/label/label.component.js";import y from"../../hooks/__internal__/useLocale/useLocale.js";import O from"../../__internal__/utils/logger/index.js";import{markdownNodes as w,theme as L,COMPONENT_PREFIX as P}from"./__internal__/constants.js";import E from"./__internal__/plugins/AutoLinker/auto-link.component.js";import k from"./__internal__/plugins/CharacterCounter/character-counter.component.js";import C from"./__internal__/plugins/ContentEditor/content-editor.component.js";import S from"./__internal__/plugins/LinkMonitor/link-monitor.plugin.js";import"./__internal__/plugins/LinkPreviewer/link-previewer.style.js";import T from"./__internal__/plugins/OnChange/on-change.plugin.js";import $ from"./__internal__/plugins/Placeholder/placeholder.component.js";import B from"./__internal__/plugins/Toolbar/toolbar.component.js";import"./__internal__/plugins/useCursorAtEnd/index.js";import q from"./text-editor.context.js";import{StyledTextEditorWrapper as A,StyledWrapper as H,StyledEditorToolbarWrapper as D,StyledHeaderWrapper as I,StyledTextEditor as R,StyledFooterWrapper as F}from"./text-editor.style.js";import{createEmpty as M}from"./utils.js";import{HintText as U}from"../../__internal__/hint-text/hint-text.component.js";import z from"../../__internal__/validation-message/validation-message.component.js";import G from"../textbox/textbox.style.js";import"../../style/utils/filter-styled-system-padding-props.js";import J from"../../style/utils/filter-styled-system-margin-props.js";import K from"../../__internal__/utils/helpers/tags/tags.js";function N(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function Q(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})))),n.forEach((function(r){N(e,r,t[r])}))}return e}let V=!1;const W=d(((d,N)=>{var{characterLimit:W=3e3,error:X,footer:Y,header:Z,inputHint:ee,isOptional:re=!1,labelText:te,namespace:ne=P,onBlur:oe,onCancel:ie,onChange:ae,onFocus:le,onLinkAdded:ce,onSave:se,placeholder:pe,previews:ue=[],readOnly:de=!1,required:me=!1,rows:fe,warning:_e,value:ge,customPlugins:be}=d,he=function(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t=i[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)t=i[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}(d,["characterLimit","error","footer","header","inputHint","isOptional","labelText","namespace","onBlur","onCancel","onChange","onFocus","onLinkAdded","onSave","placeholder","previews","readOnly","required","rows","warning","value","customPlugins"]);!V&&re&&(V=!0,O.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."));const ve=m(void 0),xe=y(),[je,ye]=f(void 0),Oe=m(null),[we,Le]=f(!1);_(N,(()=>({focus(){var e;null===(e=Oe.current)||void 0===e||e.focus()}})),[]),g((()=>{const e=null==Oe?void 0:Oe.current,r=()=>{Le(!0)},t=()=>{Le(!1)};return null==e||e.addEventListener("focus",r),null==e||e.addEventListener("blur",t),()=>{null==e||e.removeEventListener("focus",r),null==e||e.removeEventListener("blur",t)}}),[Oe]);const[Pe,Ee]=f(!1),ke=b((()=>({namespace:ne,nodes:w,onError:console.error,theme:L,editorState:ge,editable:!de})),[ne,de,ge]),Ce=h((e=>{const r=e.read((()=>u().getTextContent()));if(ae){const e=ve.current?v(ve.current):{};null==ae||ae(r,e)}if(W>0){const e=W-r.length;ye(e<0?xe.textEditor.characterLimit(Math.abs(e)):void 0)}}),[W,xe.textEditor,ae]),Se=h((()=>{var e;(null===(e=ve.current)||void 0===e?void 0:e.isEditable())&&ie&&(Ee((e=>!e)),ie())}),[ie]);g((()=>{const e=ge||M();if(ve.current){const r=ve.current.parseEditorState(e);ve.current.setEditorState(r)}}),[Pe,ge]);const Te=b((()=>({namespace:ne,onCancel:ie?Se:void 0,onSave:se})),[Se,ne,ie,se]),$e=_e||je;return e(A,(Be=Q({"data-role":`${ne}-editor-wrapper`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||null==oe||oe(e)},onFocus:e=>{e.currentTarget.contains(e.relatedTarget)||null==le||le(e)}},J(he),K("text-editor",he)),qe=null!=(qe={children:r(q.Provider,{value:{onLinkAdded:ce},children:[e(j,{isRequired:me,optional:re,labelId:`${ne}-label`,children:te}),ee&&e(U,{id:`${ne}-input-hint`,marginBottom:"var(--spacing100)",children:ee}),r(t,{initialConfig:ke,children:[e(o,{editorRef:ve}),r(H,{"data-role":`${ne}-wrapper`,children:[e(z,{error:X,warning:$e,validationId:`${ne}-validation-message`,"data-role":`${ne}-validation-message`}),(X||$e)&&e(G,{warning:!(X||!$e)}),r(D,{"data-role":`${ne}-editor-toolbar-wrapper`,id:`${ne}-editor-toolbar-wrapper`,focused:we,error:!!X,children:[Z&&e(I,{"data-role":`${ne}-header-wrapper`,children:Z}),!de&&e(B,Q({hasHeader:Boolean(Z)},Te)),r(R,{"data-role":`${ne}-editor`,children:[e(c,{contentEditable:e(C,{ref:Oe,inputHint:ee,namespace:ne,previews:ue,rows:fe,readOnly:de,required:me,error:!!X,warning:!!_e||!!je}),placeholder:e($,{namespace:ne,text:pe}),ErrorBoundary:i}),e(p,{}),e(a,{}),e(l,{}),e(T,{onChange:Ce}),e(s,{validateUrl:x}),e(n,{newTab:!0}),e(E,{}),be]}),Y&&e(F,{"data-role":`${ne}-footer-wrapper`,children:Y}),e(S,{})]}),W>0&&!de&&e(k,{maxChars:W,namespace:ne})]})]})]})})?qe:{},Object.getOwnPropertyDescriptors?Object.defineProperties(Be,Object.getOwnPropertyDescriptors(qe)):function(e){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r.push.apply(r,t)}return r}(Object(qe)).forEach((function(e){Object.defineProperty(Be,e,Object.getOwnPropertyDescriptor(qe,e))})),Be));var Be,qe}));export{W as TextEditor,W as default};
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { MarginProps } from "styled-system";
|
|
2
2
|
type StyledTextEditorWrapperProps = MarginProps;
|
|
3
|
-
interface StyledWrapperProps {
|
|
4
|
-
error?: string;
|
|
5
|
-
namespace: string;
|
|
6
|
-
warning?: string;
|
|
7
|
-
}
|
|
8
|
-
interface StyledValidationMessageProps {
|
|
9
|
-
error?: string;
|
|
10
|
-
}
|
|
11
3
|
interface StyledEditorToolbarWrapperProps {
|
|
12
4
|
focused?: boolean;
|
|
13
|
-
|
|
5
|
+
error?: boolean;
|
|
14
6
|
}
|
|
15
7
|
export declare const StyledTextEditor: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
16
8
|
export declare const StyledTextEditorWrapper: import("styled-components").StyledComponent<"div", any, StyledTextEditorWrapperProps, never>;
|
|
17
|
-
export declare const StyledWrapper: import("styled-components").StyledComponent<"div", any,
|
|
9
|
+
export declare const StyledWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
18
10
|
export declare const StyledEditorToolbarWrapper: import("styled-components").StyledComponent<"div", any, StyledEditorToolbarWrapperProps, never>;
|
|
19
11
|
export declare const StyledHeaderWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
20
12
|
export declare const StyledFooterWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
21
|
-
export declare const StyledValidationMessage: import("styled-components").StyledComponent<"div", any, StyledValidationMessageProps, never>;
|
|
22
13
|
export default StyledTextEditor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import o,{css as t}from"styled-components";import{margin as
|
|
1
|
+
import o,{css as t}from"styled-components";import{margin as e}from"styled-system";import r from"../../style/utils/add-focus-styling.js";const i=o.div.withConfig({displayName:"text-editor.style__StyledTextEditor",componentId:"sc-cb8130a9-0"})(["position:relative;"]),a=o.div.withConfig({displayName:"text-editor.style__StyledTextEditorWrapper",componentId:"sc-cb8130a9-1"})(["margin-bottom:var(--fieldSpacing);",""],e),d=o.div.withConfig({displayName:"text-editor.style__StyledWrapper",componentId:"sc-cb8130a9-2"})(['position:relative;.textBold{font-weight:bold;}.textItalic{font-style:italic;}a:not([data-component="link-preview"]){color:var(--colorsActionMajor500);cursor:pointer;&:hover{color:var(--colorsActionMajor600);}&:focus{outline:none;text-decoration:none;color:var(--colorsActionMajorYin090);background-color:var(--colorsSemanticFocus250);border-radius:var(--borderRadius025);box-shadow:0 var(--spacing050) 0 0 var(--colorsUtilityYin090);}}']),n=o.div.withConfig({displayName:"text-editor.style__StyledEditorToolbarWrapper",componentId:"sc-cb8130a9-3"})(["",""],(({focused:o,error:e})=>t(["border-radius:var(--borderRadius100);outline:1px solid var(--colorsUtilityMajor200);"," ",""],e&&t(["outline:none;border:2px solid var(--colorsSemanticNegative500);"]),o&&r()))),s=o.div.withConfig({displayName:"text-editor.style__StyledHeaderWrapper",componentId:"sc-cb8130a9-4"})(["padding:var(--spacing200);"]),l=o.div.withConfig({displayName:"text-editor.style__StyledFooterWrapper",componentId:"sc-cb8130a9-5"})(["border-top:1px solid var(--colorsUtilityMajor200);padding:var(--spacing200);"]);export{n as StyledEditorToolbarWrapper,l as StyledFooterWrapper,s as StyledHeaderWrapper,i as StyledTextEditor,a as StyledTextEditorWrapper,d as StyledWrapper,i as default};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
2
|
+
import { TagProps } from "../../__internal__/utils/helpers/tags";
|
|
3
|
+
export interface ValidationMessageProps extends TagProps {
|
|
3
4
|
/** Indicate that error has occurred
|
|
4
5
|
Pass string to display hint with error */
|
|
5
6
|
error?: boolean | string;
|
|
@@ -11,5 +12,5 @@ export interface ValidationMessageProps {
|
|
|
11
12
|
/** Whether this component resides on a dark background */
|
|
12
13
|
isDarkBackground?: boolean;
|
|
13
14
|
}
|
|
14
|
-
declare const ValidationMessage: ({ error, validationId, warning, isDarkBackground, }: ValidationMessageProps) => React.JSX.Element | null;
|
|
15
|
+
declare const ValidationMessage: ({ error, validationId, warning, isDarkBackground, "data-element": dataElement, "data-role": dataRole, }: ValidationMessageProps) => React.JSX.Element | null;
|
|
15
16
|
export default ValidationMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime");require("react");var r=require("./validation-message.style.js");exports.default=({error:a,validationId:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime");require("react");var r=require("./validation-message.style.js"),t=require("../utils/helpers/tags/tags.js");function n(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}exports.default=({error:a,validationId:o,warning:i,isDarkBackground:s,"data-element":c,"data-role":l="validation-message"})=>{const u=a||i;return"string"==typeof u?e.jsx(r.default,(p=function(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},a=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(a=a.concat(Object.getOwnPropertySymbols(t).filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})))),a.forEach((function(r){n(e,r,t[r])}))}return e}({id:o,isWarning:!(a||!i),isDarkBackground:s},t.default("validation-message",{"data-element":c,"data-role":l})),b=null!=(b={children:u})?b:{},Object.getOwnPropertyDescriptors?Object.defineProperties(p,Object.getOwnPropertyDescriptors(b)):function(e){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r.push.apply(r,t)}return r}(Object(b)).forEach((function(e){Object.defineProperty(p,e,Object.getOwnPropertyDescriptor(b,e))})),p)):null;var p,b};
|
|
@@ -53,6 +53,10 @@ export interface TextEditorProps extends MarginProps, TagProps {
|
|
|
53
53
|
warning?: string;
|
|
54
54
|
/** The initial value of the editor, as a HTML string, or JSON */
|
|
55
55
|
value?: string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Allows the injection of one or more Lexical-compatible React components into the editor to extend its functionality.
|
|
58
|
+
* This prop is optional and supports a single plugin, multiple plugins (via fragments or arrays), or `null`.
|
|
59
|
+
*/
|
|
56
60
|
customPlugins?: React.ReactNode;
|
|
57
61
|
}
|
|
58
62
|
export declare const TextEditor: React.ForwardRefExoticComponent<TextEditorProps & React.RefAttributes<TextEditorHandle>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("@lexical/react/LexicalComposer"),t=require("@lexical/react/LexicalClickableLinkPlugin"),n=require("@lexical/react/LexicalEditorRefPlugin"),i=require("@lexical/react/LexicalErrorBoundary"),a=require("@lexical/react/LexicalHistoryPlugin"),l=require("@lexical/react/LexicalMarkdownShortcutPlugin"),o=require("@lexical/react/LexicalRichTextPlugin"),s=require("@lexical/react/LexicalLinkPlugin"),u=require("@lexical/react/LexicalListPlugin"),c=require("lexical"),d=require("react"),p=require("./__internal__/helpers.js"),x=require("../../__internal__/label/label.component.js"),f=require("../../hooks/__internal__/useLocale/useLocale.js"),g=require("../../__internal__/utils/logger/index.js"),_=require("./__internal__/constants.js"),j=require("./__internal__/plugins/AutoLinker/auto-link.component.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("@lexical/react/LexicalComposer"),t=require("@lexical/react/LexicalClickableLinkPlugin"),n=require("@lexical/react/LexicalEditorRefPlugin"),i=require("@lexical/react/LexicalErrorBoundary"),a=require("@lexical/react/LexicalHistoryPlugin"),l=require("@lexical/react/LexicalMarkdownShortcutPlugin"),o=require("@lexical/react/LexicalRichTextPlugin"),s=require("@lexical/react/LexicalLinkPlugin"),u=require("@lexical/react/LexicalListPlugin"),c=require("lexical"),d=require("react"),p=require("./__internal__/helpers.js"),x=require("../../__internal__/label/label.component.js"),f=require("../../hooks/__internal__/useLocale/useLocale.js"),g=require("../../__internal__/utils/logger/index.js"),_=require("./__internal__/constants.js"),j=require("./__internal__/plugins/AutoLinker/auto-link.component.js"),b=require("./__internal__/plugins/CharacterCounter/character-counter.component.js"),m=require("./__internal__/plugins/ContentEditor/content-editor.component.js"),v=require("./__internal__/plugins/LinkMonitor/link-monitor.plugin.js");require("./__internal__/plugins/LinkPreviewer/link-previewer.style.js");var h=require("./__internal__/plugins/OnChange/on-change.plugin.js"),y=require("./__internal__/plugins/Placeholder/placeholder.component.js"),q=require("./__internal__/plugins/Toolbar/toolbar.component.js");require("./__internal__/plugins/useCursorAtEnd/index.js");var O=require("./text-editor.context.js"),w=require("./text-editor.style.js"),P=require("./utils.js"),L=require("../../__internal__/hint-text/hint-text.component.js"),E=require("../../__internal__/validation-message/validation-message.component.js"),k=require("../textbox/textbox.style.js");require("../../style/utils/filter-styled-system-padding-props.js");var S=require("../../style/utils/filter-styled-system-margin-props.js"),C=require("../../__internal__/utils/helpers/tags/tags.js");function T(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function $(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})))),n.forEach((function(r){T(e,r,t[r])}))}return e}let R=!1;const H=d.forwardRef(((T,H)=>{var{characterLimit:B=3e3,error:M,footer:I,header:A,inputHint:F,isOptional:W=!1,labelText:D,namespace:N=_.COMPONENT_PREFIX,onBlur:U,onCancel:z,onChange:X,onFocus:G,onLinkAdded:J,onSave:K,placeholder:Q,previews:V=[],readOnly:Y=!1,required:Z=!1,rows:ee,warning:re,value:te,customPlugins:ne}=T,ie=function(e,r){if(null==e)return{};var t,n,i=function(e,r){if(null==e)return{};var t,n,i={},a=Object.keys(e);for(n=0;n<a.length;n++)t=a[n],r.indexOf(t)>=0||(i[t]=e[t]);return i}(e,r);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)t=a[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}(T,["characterLimit","error","footer","header","inputHint","isOptional","labelText","namespace","onBlur","onCancel","onChange","onFocus","onLinkAdded","onSave","placeholder","previews","readOnly","required","rows","warning","value","customPlugins"]);!R&&W&&(R=!0,g.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."));const ae=d.useRef(void 0),le=f.default(),[oe,se]=d.useState(void 0),ue=d.useRef(null),[ce,de]=d.useState(!1);d.useImperativeHandle(H,(()=>({focus(){var e;null===(e=ue.current)||void 0===e||e.focus()}})),[]),d.useEffect((()=>{const e=null==ue?void 0:ue.current,r=()=>{de(!0)},t=()=>{de(!1)};return null==e||e.addEventListener("focus",r),null==e||e.addEventListener("blur",t),()=>{null==e||e.removeEventListener("focus",r),null==e||e.removeEventListener("blur",t)}}),[ue]);const[pe,xe]=d.useState(!1),fe=d.useMemo((()=>({namespace:N,nodes:_.markdownNodes,onError:console.error,theme:_.theme,editorState:te,editable:!Y})),[N,Y,te]),ge=d.useCallback((e=>{const r=e.read((()=>c.$getRoot().getTextContent()));if(X){const e=ae.current?p.SerializeLexical(ae.current):{};null==X||X(r,e)}if(B>0){const e=B-r.length;se(e<0?le.textEditor.characterLimit(Math.abs(e)):void 0)}}),[B,le.textEditor,X]),_e=d.useCallback((()=>{var e;(null===(e=ae.current)||void 0===e?void 0:e.isEditable())&&z&&(xe((e=>!e)),z())}),[z]);d.useEffect((()=>{const e=te||P.createEmpty();if(ae.current){const r=ae.current.parseEditorState(e);ae.current.setEditorState(r)}}),[pe,te]);const je=d.useMemo((()=>({namespace:N,onCancel:z?_e:void 0,onSave:K})),[_e,N,z,K]),be=re||oe;return e.jsx(w.StyledTextEditorWrapper,(me=$({"data-role":`${N}-editor-wrapper`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||null==U||U(e)},onFocus:e=>{e.currentTarget.contains(e.relatedTarget)||null==G||G(e)}},S.default(ie),C.default("text-editor",ie)),ve=null!=(ve={children:e.jsxs(O.default.Provider,{value:{onLinkAdded:J},children:[e.jsx(x.default,{isRequired:Z,optional:W,labelId:`${N}-label`,children:D}),F&&e.jsx(L.HintText,{id:`${N}-input-hint`,marginBottom:"var(--spacing100)",children:F}),e.jsxs(r.LexicalComposer,{initialConfig:fe,children:[e.jsx(n.EditorRefPlugin,{editorRef:ae}),e.jsxs(w.StyledWrapper,{"data-role":`${N}-wrapper`,children:[e.jsx(E.default,{error:M,warning:be,validationId:`${N}-validation-message`,"data-role":`${N}-validation-message`}),(M||be)&&e.jsx(k.default,{warning:!(M||!be)}),e.jsxs(w.StyledEditorToolbarWrapper,{"data-role":`${N}-editor-toolbar-wrapper`,id:`${N}-editor-toolbar-wrapper`,focused:ce,error:!!M,children:[A&&e.jsx(w.StyledHeaderWrapper,{"data-role":`${N}-header-wrapper`,children:A}),!Y&&e.jsx(q.default,$({hasHeader:Boolean(A)},je)),e.jsxs(w.StyledTextEditor,{"data-role":`${N}-editor`,children:[e.jsx(o.RichTextPlugin,{contentEditable:e.jsx(m.default,{ref:ue,inputHint:F,namespace:N,previews:V,rows:ee,readOnly:Y,required:Z,error:!!M,warning:!!re||!!oe}),placeholder:e.jsx(y.default,{namespace:N,text:Q}),ErrorBoundary:i.LexicalErrorBoundary}),e.jsx(u.ListPlugin,{}),e.jsx(a.HistoryPlugin,{}),e.jsx(l.MarkdownShortcutPlugin,{}),e.jsx(h.default,{onChange:ge}),e.jsx(s.LinkPlugin,{validateUrl:p.validateUrl}),e.jsx(t.ClickableLinkPlugin,{newTab:!0}),e.jsx(j.default,{}),ne]}),I&&e.jsx(w.StyledFooterWrapper,{"data-role":`${N}-footer-wrapper`,children:I}),e.jsx(v.default,{})]}),B>0&&!Y&&e.jsx(b.default,{maxChars:B,namespace:N})]})]})]})})?ve:{},Object.getOwnPropertyDescriptors?Object.defineProperties(me,Object.getOwnPropertyDescriptors(ve)):function(e){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r.push.apply(r,t)}return r}(Object(ve)).forEach((function(e){Object.defineProperty(me,e,Object.getOwnPropertyDescriptor(ve,e))})),me));var me,ve}));exports.TextEditor=H,exports.default=H;
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { MarginProps } from "styled-system";
|
|
2
2
|
type StyledTextEditorWrapperProps = MarginProps;
|
|
3
|
-
interface StyledWrapperProps {
|
|
4
|
-
error?: string;
|
|
5
|
-
namespace: string;
|
|
6
|
-
warning?: string;
|
|
7
|
-
}
|
|
8
|
-
interface StyledValidationMessageProps {
|
|
9
|
-
error?: string;
|
|
10
|
-
}
|
|
11
3
|
interface StyledEditorToolbarWrapperProps {
|
|
12
4
|
focused?: boolean;
|
|
13
|
-
|
|
5
|
+
error?: boolean;
|
|
14
6
|
}
|
|
15
7
|
export declare const StyledTextEditor: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
16
8
|
export declare const StyledTextEditorWrapper: import("styled-components").StyledComponent<"div", any, StyledTextEditorWrapperProps, never>;
|
|
17
|
-
export declare const StyledWrapper: import("styled-components").StyledComponent<"div", any,
|
|
9
|
+
export declare const StyledWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
18
10
|
export declare const StyledEditorToolbarWrapper: import("styled-components").StyledComponent<"div", any, StyledEditorToolbarWrapperProps, never>;
|
|
19
11
|
export declare const StyledHeaderWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
20
12
|
export declare const StyledFooterWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
21
|
-
export declare const StyledValidationMessage: import("styled-components").StyledComponent<"div", any, StyledValidationMessageProps, never>;
|
|
22
13
|
export default StyledTextEditor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("styled-components"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("styled-components"),t=require("styled-system"),o=require("../../style/utils/add-focus-styling.js");function r(e){return e&&e.__esModule?e:{default:e}}var i=r(e);const a=i.default.div.withConfig({displayName:"text-editor.style__StyledTextEditor",componentId:"sc-cb8130a9-0"})(["position:relative;"]),d=i.default.div.withConfig({displayName:"text-editor.style__StyledTextEditorWrapper",componentId:"sc-cb8130a9-1"})(["margin-bottom:var(--fieldSpacing);",""],t.margin),l=i.default.div.withConfig({displayName:"text-editor.style__StyledWrapper",componentId:"sc-cb8130a9-2"})(['position:relative;.textBold{font-weight:bold;}.textItalic{font-style:italic;}a:not([data-component="link-preview"]){color:var(--colorsActionMajor500);cursor:pointer;&:hover{color:var(--colorsActionMajor600);}&:focus{outline:none;text-decoration:none;color:var(--colorsActionMajorYin090);background-color:var(--colorsSemanticFocus250);border-radius:var(--borderRadius025);box-shadow:0 var(--spacing050) 0 0 var(--colorsUtilityYin090);}}']),s=i.default.div.withConfig({displayName:"text-editor.style__StyledEditorToolbarWrapper",componentId:"sc-cb8130a9-3"})(["",""],(({focused:t,error:r})=>e.css(["border-radius:var(--borderRadius100);outline:1px solid var(--colorsUtilityMajor200);"," ",""],r&&e.css(["outline:none;border:2px solid var(--colorsSemanticNegative500);"]),t&&o.default()))),n=i.default.div.withConfig({displayName:"text-editor.style__StyledHeaderWrapper",componentId:"sc-cb8130a9-4"})(["padding:var(--spacing200);"]),p=i.default.div.withConfig({displayName:"text-editor.style__StyledFooterWrapper",componentId:"sc-cb8130a9-5"})(["border-top:1px solid var(--colorsUtilityMajor200);padding:var(--spacing200);"]);exports.StyledEditorToolbarWrapper=s,exports.StyledFooterWrapper=p,exports.StyledHeaderWrapper=n,exports.StyledTextEditor=a,exports.StyledTextEditorWrapper=d,exports.StyledWrapper=l,exports.default=a;
|