@webiny/lexical-editor 5.37.8 → 5.38.0-beta.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/commands/image.d.ts +6 -0
- package/commands/{insertFiles.js → image.js} +3 -1
- package/commands/image.js.map +1 -0
- package/commands/index.d.ts +3 -0
- package/commands/index.js +40 -0
- package/commands/index.js.map +1 -0
- package/commands/list.d.ts +7 -0
- package/commands/list.js +15 -0
- package/commands/list.js.map +1 -0
- package/commands/quote.d.ts +5 -0
- package/commands/quote.js +11 -0
- package/commands/quote.js.map +1 -0
- package/components/Editor/HeadingEditor.js +3 -1
- package/components/Editor/ParagraphEditor.js +3 -1
- package/components/Editor/RichTextEditor.d.ts +2 -2
- package/components/Editor/RichTextEditor.js +19 -12
- package/components/Editor/RichTextEditor.js.map +1 -1
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +3 -1
- package/components/LexicalEditorConfig/components/Node.js +3 -1
- package/components/LexicalEditorConfig/components/Plugin.js +3 -1
- package/components/LexicalEditorConfig/components/ToolbarElement.js +3 -1
- package/components/LexicalHtmlRenderer.d.ts +2 -2
- package/components/LexicalHtmlRenderer.js +24 -17
- package/components/LexicalHtmlRenderer.js.map +1 -1
- package/components/Toolbar/StaticToolbar.d.ts +2 -2
- package/components/Toolbar/StaticToolbar.js +7 -78
- package/components/Toolbar/StaticToolbar.js.map +1 -1
- package/components/Toolbar/Toolbar.d.ts +1 -1
- package/components/Toolbar/Toolbar.js +27 -80
- package/components/Toolbar/Toolbar.js.map +1 -1
- package/components/ToolbarActions/BoldAction.js +10 -20
- package/components/ToolbarActions/BoldAction.js.map +1 -1
- package/components/ToolbarActions/BulletListAction.js +17 -23
- package/components/ToolbarActions/BulletListAction.js.map +1 -1
- package/components/ToolbarActions/CodeHighlightAction.js +10 -20
- package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
- package/components/ToolbarActions/FontColorAction.js +20 -37
- package/components/ToolbarActions/FontColorAction.js.map +1 -1
- package/components/ToolbarActions/FontSizeAction.js +11 -27
- package/components/ToolbarActions/FontSizeAction.js.map +1 -1
- package/components/ToolbarActions/ImageAction.js +6 -4
- package/components/ToolbarActions/ImageAction.js.map +1 -1
- package/components/ToolbarActions/ItalicAction.js +10 -20
- package/components/ToolbarActions/ItalicAction.js.map +1 -1
- package/components/ToolbarActions/LinkAction.js +18 -36
- package/components/ToolbarActions/LinkAction.js.map +1 -1
- package/components/ToolbarActions/NumberedListAction.js +18 -27
- package/components/ToolbarActions/NumberedListAction.js.map +1 -1
- package/components/ToolbarActions/QuoteAction.js +15 -24
- package/components/ToolbarActions/QuoteAction.js.map +1 -1
- package/components/ToolbarActions/TextAlignmentAction.js +27 -21
- package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
- package/components/ToolbarActions/TypographyAction.js +53 -60
- package/components/ToolbarActions/TypographyAction.js.map +1 -1
- package/components/ToolbarActions/UnderlineAction.js +11 -21
- package/components/ToolbarActions/UnderlineAction.js.map +1 -1
- package/context/FontColorActionContext.js +3 -1
- package/context/RichTextEditorContext.d.ts +2 -6
- package/context/RichTextEditorContext.js +20 -36
- package/context/RichTextEditorContext.js.map +1 -1
- package/context/SharedHistoryContext.js +3 -1
- package/context/TextAlignmentActionContextProps.js +3 -1
- package/context/TypographyActionContext.d.ts +1 -1
- package/context/TypographyActionContext.js +3 -1
- package/context/TypographyActionContext.js.map +1 -1
- package/hooks/index.d.ts +7 -0
- package/hooks/index.js +84 -0
- package/hooks/index.js.map +1 -0
- package/hooks/useCurrentElement.d.ts +7 -0
- package/hooks/useCurrentElement.js +33 -0
- package/hooks/useCurrentElement.js.map +1 -0
- package/hooks/useCurrentSelection.d.ts +12 -0
- package/hooks/useCurrentSelection.js +72 -0
- package/hooks/useCurrentSelection.js.map +1 -0
- package/hooks/useFontColorPicker.js +3 -1
- package/hooks/useIsMounted.d.ts +1 -0
- package/hooks/useIsMounted.js +20 -0
- package/hooks/useIsMounted.js.map +1 -0
- package/hooks/useList.js +22 -21
- package/hooks/useList.js.map +1 -1
- package/hooks/useQuote.d.ts +1 -1
- package/hooks/useQuote.js +9 -7
- package/hooks/useQuote.js.map +1 -1
- package/hooks/useRichTextEditor.js +3 -1
- package/hooks/useTextAlignmentAction.js +3 -1
- package/hooks/useTypographyAction.js +3 -1
- package/index.d.ts +4 -8
- package/index.js +71 -48
- package/index.js.map +1 -1
- package/package.json +16 -20
- package/plugins/BlurEventPlugin/BlurEventPlugin.js +3 -1
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +3 -1
- package/plugins/CodeHighlightPlugin/index.js +3 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +11 -9
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.js +3 -1
- package/plugins/FontColorPlugin/FontColorPlugin.js +8 -7
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
- package/plugins/ImagesPlugin/ImagesPlugin.d.ts +1 -1
- package/plugins/ImagesPlugin/ImagesPlugin.js +11 -9
- package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.d.ts +9 -0
- package/plugins/LexicalUpdateStatePlugin/{LexicalUpdateStatePlugin.js → UpdateStatePlugin.js} +22 -14
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.js.map +1 -0
- package/plugins/LexicalUpdateStatePlugin/index.d.ts +1 -1
- package/plugins/LexicalUpdateStatePlugin/index.js +7 -5
- package/plugins/LexicalUpdateStatePlugin/index.js.map +1 -1
- package/plugins/LinkPlugin/LinkPlugin.d.ts +5 -0
- package/plugins/LinkPlugin/LinkPlugin.js +68 -0
- package/plugins/LinkPlugin/LinkPlugin.js.map +1 -0
- package/plugins/ListPLugin/ListPlugin.js +6 -5
- package/plugins/ListPLugin/ListPlugin.js.map +1 -1
- package/plugins/TypographyPlugin/TypographyPlugin.js +7 -7
- package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js +6 -4
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js.map +1 -1
- package/types.d.ts +1 -60
- package/types.js +5 -3
- package/types.js.map +1 -1
- package/ui/ContentEditable.js +3 -1
- package/ui/Divider.js +3 -1
- package/ui/DropDown.js +3 -1
- package/ui/ImageResizer.js +3 -1
- package/ui/LinkPreview.js +3 -1
- package/ui/Placeholder.js +3 -1
- package/ui/TextInput.js +3 -1
- package/ui/ToolbarActionDialog.js +3 -1
- package/utils/canUseDOM.js +3 -1
- package/utils/files.d.ts +1 -1
- package/utils/files.js +3 -1
- package/utils/files.js.map +1 -1
- package/utils/generateInitialLexicalValue.js +3 -1
- package/utils/getDOMRangeRect.js +3 -1
- package/utils/getSelectedNode.js +3 -1
- package/utils/getTransparentImage.js +3 -1
- package/utils/insertImage.d.ts +2 -0
- package/utils/{nodes/insertImage.js → insertImage.js} +6 -5
- package/utils/insertImage.js.map +1 -0
- package/utils/isHTMLElement.js +3 -1
- package/utils/isUrlLinkReference.js +3 -1
- package/utils/isValidJSON.js +3 -1
- package/utils/isValidLexicalData.js +3 -1
- package/utils/point.js +3 -1
- package/utils/rect.js +3 -1
- package/utils/sanitizeUrl.js +3 -1
- package/utils/setFloatingElemPosition.js +3 -1
- package/commands/insertFiles.d.ts +0 -14
- package/commands/insertFiles.js.map +0 -1
- package/commands/webiny-list.d.ts +0 -7
- package/commands/webiny-list.js +0 -13
- package/commands/webiny-list.js.map +0 -1
- package/commands/webiny-quote.d.ts +0 -5
- package/commands/webiny-quote.js +0 -9
- package/commands/webiny-quote.js.map +0 -1
- package/components/ImageComponent.d.ts +0 -23
- package/components/ImageComponent.js +0 -252
- package/components/ImageComponent.js.map +0 -1
- package/nodes/FontColorNode.d.ts +0 -43
- package/nodes/FontColorNode.js +0 -123
- package/nodes/FontColorNode.js.map +0 -1
- package/nodes/HeadingNode.d.ts +0 -34
- package/nodes/HeadingNode.js +0 -191
- package/nodes/HeadingNode.js.map +0 -1
- package/nodes/ImageNode.d.ts +0 -50
- package/nodes/ImageNode.js +0 -206
- package/nodes/ImageNode.js.map +0 -1
- package/nodes/ListItemNode.d.ts +0 -46
- package/nodes/ListItemNode.js +0 -447
- package/nodes/ListItemNode.js.map +0 -1
- package/nodes/ListNode/formatList.d.ts +0 -19
- package/nodes/ListNode/formatList.js +0 -447
- package/nodes/ListNode/formatList.js.map +0 -1
- package/nodes/ListNode.d.ts +0 -42
- package/nodes/ListNode.js +0 -288
- package/nodes/ListNode.js.map +0 -1
- package/nodes/ParagraphNode.d.ts +0 -32
- package/nodes/ParagraphNode.js +0 -218
- package/nodes/ParagraphNode.js.map +0 -1
- package/nodes/QuoteNode.d.ts +0 -34
- package/nodes/QuoteNode.js +0 -225
- package/nodes/QuoteNode.js.map +0 -1
- package/nodes/TypographyElementNode.d.ts +0 -42
- package/nodes/TypographyElementNode.js +0 -151
- package/nodes/TypographyElementNode.js.map +0 -1
- package/nodes/imageNode.css +0 -43
- package/nodes/link-node.d.ts +0 -19
- package/nodes/link-node.js +0 -120
- package/nodes/link-node.js.map +0 -1
- package/nodes/types.d.ts +0 -15
- package/nodes/types.js +0 -5
- package/nodes/types.js.map +0 -1
- package/nodes/webinyNodes.d.ts +0 -7
- package/nodes/webinyNodes.js +0 -60
- package/nodes/webinyNodes.js.map +0 -1
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.d.ts +0 -8
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js.map +0 -1
- package/themes/webinyLexicalTheme.css +0 -423
- package/themes/webinyLexicalTheme.d.ts +0 -9
- package/themes/webinyLexicalTheme.js +0 -90
- package/themes/webinyLexicalTheme.js.map +0 -1
- package/utils/findTypographyStyleByHtmlTag.d.ts +0 -8
- package/utils/findTypographyStyleByHtmlTag.js +0 -16
- package/utils/findTypographyStyleByHtmlTag.js.map +0 -1
- package/utils/getLexicalTextSelectionState.d.ts +0 -5
- package/utils/getLexicalTextSelectionState.js +0 -167
- package/utils/getLexicalTextSelectionState.js.map +0 -1
- package/utils/nodes/clearNodeFormating.d.ts +0 -2
- package/utils/nodes/clearNodeFormating.js +0 -28
- package/utils/nodes/clearNodeFormating.js.map +0 -1
- package/utils/nodes/formatToHeading.d.ts +0 -3
- package/utils/nodes/formatToHeading.js +0 -25
- package/utils/nodes/formatToHeading.js.map +0 -1
- package/utils/nodes/formatToParagraph.d.ts +0 -2
- package/utils/nodes/formatToParagraph.js +0 -20
- package/utils/nodes/formatToParagraph.js.map +0 -1
- package/utils/nodes/formatToQuote.d.ts +0 -2
- package/utils/nodes/formatToQuote.js +0 -25
- package/utils/nodes/formatToQuote.js.map +0 -1
- package/utils/nodes/insertImage.d.ts +0 -2
- package/utils/nodes/insertImage.js.map +0 -1
- package/utils/nodes/listNode.d.ts +0 -11
- package/utils/nodes/listNode.js +0 -107
- package/utils/nodes/listNode.js.map +0 -1
- package/utils/styleObjectToString.d.ts +0 -2
- package/utils/styleObjectToString.js +0 -22
- package/utils/styleObjectToString.js.map +0 -1
- package/utils/toTypographyEmotionMap.d.ts +0 -3
- package/utils/toTypographyEmotionMap.js +0 -41
- package/utils/toTypographyEmotionMap.js.map +0 -1
|
@@ -9,9 +9,11 @@ exports.TextAlignmentAction = exports.BaseTextAlignmentDropDown = void 0;
|
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _lexical = require("lexical");
|
|
12
|
-
var
|
|
12
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
13
13
|
var _reactComposition = require("@webiny/react-composition");
|
|
14
14
|
var _TextAlignmentActionContextProps = require("../../context/TextAlignmentActionContextProps");
|
|
15
|
+
var _useCurrentSelection = require("../../hooks/useCurrentSelection");
|
|
16
|
+
var _getSelectedNode = require("../../utils/getSelectedNode");
|
|
15
17
|
/*
|
|
16
18
|
* Base text alignment dropdown composable component.
|
|
17
19
|
* Note: To add a custom dropdown component use @see LexicalEditorConfig API.
|
|
@@ -35,36 +37,40 @@ var TextAlignmentActionDropDown = function TextAlignmentActionDropDown(_ref) {
|
|
|
35
37
|
});
|
|
36
38
|
};
|
|
37
39
|
var TextAlignmentAction = function TextAlignmentAction() {
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
setAlignmentValue(value);
|
|
40
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
41
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
42
|
+
editor = _useLexicalComposerCo2[0];
|
|
43
|
+
var alignmentValue = (0, _useCurrentSelection.useDeriveValueFromSelection)(function (_ref2) {
|
|
44
|
+
var rangeSelection = _ref2.rangeSelection;
|
|
45
|
+
var node = rangeSelection ? (0, _getSelectedNode.getSelectedNode)(rangeSelection) : null;
|
|
46
|
+
if (node) {
|
|
47
|
+
var _node$getParent;
|
|
48
|
+
return ((_node$getParent = node.getParent()) === null || _node$getParent === void 0 ? void 0 : _node$getParent.getFormatType()) || "";
|
|
48
49
|
}
|
|
50
|
+
return "";
|
|
51
|
+
});
|
|
52
|
+
var applyTextAlignment = function applyTextAlignment(value) {
|
|
53
|
+
editor.dispatchCommand(_lexical.FORMAT_ELEMENT_COMMAND, value);
|
|
49
54
|
};
|
|
50
55
|
var outdentText = function outdentText() {
|
|
51
|
-
|
|
52
|
-
activeEditor.dispatchCommand(_lexical.OUTDENT_CONTENT_COMMAND, undefined);
|
|
53
|
-
}
|
|
56
|
+
editor.dispatchCommand(_lexical.OUTDENT_CONTENT_COMMAND, undefined);
|
|
54
57
|
};
|
|
55
58
|
var indentText = function indentText() {
|
|
56
|
-
|
|
57
|
-
activeEditor.dispatchCommand(_lexical.INDENT_CONTENT_COMMAND, undefined);
|
|
58
|
-
}
|
|
59
|
+
editor.dispatchCommand(_lexical.INDENT_CONTENT_COMMAND, undefined);
|
|
59
60
|
};
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
var context = (0, _react.useMemo)(function () {
|
|
62
|
+
return {
|
|
62
63
|
value: alignmentValue,
|
|
63
64
|
applyTextAlignment: applyTextAlignment,
|
|
64
65
|
outdentText: outdentText,
|
|
65
66
|
indentText: indentText
|
|
66
|
-
}
|
|
67
|
+
};
|
|
68
|
+
}, [alignmentValue]);
|
|
69
|
+
return /*#__PURE__*/_react.default.createElement(_TextAlignmentActionContextProps.TextAlignmentActionContext.Provider, {
|
|
70
|
+
value: context
|
|
67
71
|
}, /*#__PURE__*/_react.default.createElement(BaseTextAlignmentDropDown, null));
|
|
68
72
|
};
|
|
69
73
|
exports.TextAlignmentAction = TextAlignmentAction;
|
|
70
|
-
TextAlignmentAction.TextAlignmentDropDown = TextAlignmentActionDropDown;
|
|
74
|
+
TextAlignmentAction.TextAlignmentDropDown = TextAlignmentActionDropDown;
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=TextAlignmentAction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_lexical","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_lexical","_LexicalComposerContext","_reactComposition","_TextAlignmentActionContextProps","_useCurrentSelection","_getSelectedNode","BaseTextAlignmentDropDown","makeComposable","useEffect","console","log","exports","TextAlignmentActionDropDown","_ref","element","default","createElement","Compose","component","with","_with","TextAlignmentAction","_useLexicalComposerCo","useLexicalComposerContext","_useLexicalComposerCo2","_slicedToArray2","editor","alignmentValue","useDeriveValueFromSelection","_ref2","rangeSelection","node","getSelectedNode","_node$getParent","getParent","getFormatType","applyTextAlignment","value","dispatchCommand","FORMAT_ELEMENT_COMMAND","outdentText","OUTDENT_CONTENT_COMMAND","undefined","indentText","INDENT_CONTENT_COMMAND","context","useMemo","TextAlignmentActionContext","Provider","TextAlignmentDropDown"],"sources":["TextAlignmentAction.tsx"],"sourcesContent":["import React, { useEffect, useMemo } from \"react\";\nimport {\n ElementFormatType,\n FORMAT_ELEMENT_COMMAND,\n INDENT_CONTENT_COMMAND,\n OUTDENT_CONTENT_COMMAND\n} from \"lexical\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { Compose, makeComposable } from \"@webiny/react-composition\";\nimport { TextAlignmentActionContext } from \"~/context/TextAlignmentActionContextProps\";\nimport { useDeriveValueFromSelection } from \"~/hooks/useCurrentSelection\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\n\n/*\n * Base text alignment dropdown composable component.\n * Note: To add a custom dropdown component use @see LexicalEditorConfig API.\n */\nexport const BaseTextAlignmentDropDown = makeComposable(\n \"BaseTextAlignmentDropDown\",\n (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default BaseTextAlignmentDropDown, please add your own component\");\n }, []);\n return null;\n }\n);\n\ninterface TextAlignmentActionDropdownProps {\n element: JSX.Element;\n}\n\nconst TextAlignmentActionDropDown: React.FC<TextAlignmentActionDropdownProps> = ({\n element\n}): JSX.Element => {\n return <Compose component={BaseTextAlignmentDropDown} with={() => () => element} />;\n};\n\nexport interface TextAlignmentAction extends React.FC<unknown> {\n TextAlignmentDropDown: typeof TextAlignmentActionDropDown;\n}\n\nexport const TextAlignmentAction: TextAlignmentAction = () => {\n const [editor] = useLexicalComposerContext();\n const alignmentValue: ElementFormatType = useDeriveValueFromSelection(({ rangeSelection }) => {\n const node = rangeSelection ? getSelectedNode(rangeSelection) : null;\n if (node) {\n return node.getParent()?.getFormatType() || \"\";\n }\n return \"\";\n });\n\n const applyTextAlignment = (value: ElementFormatType) => {\n editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, value);\n };\n\n const outdentText = () => {\n editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);\n };\n\n const indentText = () => {\n editor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined);\n };\n\n const context = useMemo(\n () => ({\n value: alignmentValue,\n applyTextAlignment,\n outdentText,\n indentText\n }),\n [alignmentValue]\n );\n\n return (\n <TextAlignmentActionContext.Provider value={context}>\n <BaseTextAlignmentDropDown />\n </TextAlignmentActionContext.Provider>\n );\n};\n\nTextAlignmentAction.TextAlignmentDropDown = TextAlignmentActionDropDown;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAMA,IAAAE,uBAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,gCAAA,GAAAJ,OAAA;AACA,IAAAK,oBAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AAEA;AACA;AACA;AACA;AACO,IAAMO,yBAAyB,GAAG,IAAAC,gCAAc,EACnD,2BAA2B,EAC3B,YAA0B;EACtB,IAAAC,gBAAS,EAAC,YAAM;IACZC,OAAO,CAACC,GAAG,CAAC,kEAAkE,CAAC;EACnF,CAAC,EAAE,EAAE,CAAC;EACN,OAAO,IAAI;AACf,CACJ,CAAC;AAACC,OAAA,CAAAL,yBAAA,GAAAA,yBAAA;AAMF,IAAMM,2BAAuE,GAAG,SAA1EA,2BAAuEA,CAAAC,IAAA,EAE1D;EAAA,IADfC,OAAO,GAAAD,IAAA,CAAPC,OAAO;EAEP,oBAAOjB,MAAA,CAAAkB,OAAA,CAAAC,aAAA,CAACd,iBAAA,CAAAe,OAAO;IAACC,SAAS,EAAEZ,yBAA0B;IAACa,IAAI,EAAE,SAAAC,MAAA;MAAA,OAAM;QAAA,OAAMN,OAAO;MAAA;IAAA;EAAC,CAAE,CAAC;AACvF,CAAC;AAMM,IAAMO,mBAAwC,GAAG,SAA3CA,mBAAwCA,CAAA,EAAS;EAC1D,IAAAC,qBAAA,GAAiB,I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gBAChDhD,MAAA,CAAAkB,OAAA,CAAAC,aAAA,CAACV,yBAAyB,MAAE,CACK,CAAC;AAE9C,CAAC;AAACK,OAAA,CAAAU,mBAAA,GAAAA,mBAAA;AAEFA,mBAAmB,CAAC4B,qBAAqB,GAAGrC,2BAA2B"}
|
|
@@ -11,13 +11,10 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
11
11
|
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
12
12
|
var _reactComposition = require("@webiny/react-composition");
|
|
13
13
|
var _TypographyActionContext = require("../../context/TypographyActionContext");
|
|
14
|
-
var
|
|
14
|
+
var _lexicalNodes = require("@webiny/lexical-nodes");
|
|
15
15
|
var _useRichTextEditor2 = require("../../hooks/useRichTextEditor");
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var _ParagraphNode = require("../../nodes/ParagraphNode");
|
|
19
|
-
var _HeadingNode = require("../../nodes/HeadingNode");
|
|
20
|
-
var _QuoteNode = require("../../nodes/QuoteNode");
|
|
16
|
+
var _commands = require("../../commands");
|
|
17
|
+
var _useCurrentElement2 = require("../../hooks/useCurrentElement");
|
|
21
18
|
/*
|
|
22
19
|
* Base composable action component that is mounted on toolbar action as a placeholder for the custom toolbar action.
|
|
23
20
|
* Note: Toa add custom component access trough @see LexicalEditorConfig API
|
|
@@ -41,7 +38,6 @@ var TypographyActionDropDown = function TypographyActionDropDown(_ref) {
|
|
|
41
38
|
});
|
|
42
39
|
};
|
|
43
40
|
var TypographyAction = function TypographyAction() {
|
|
44
|
-
var _textBlockSelection$s, _textBlockSelection$s2, _textBlockSelection$s3, _textBlockSelection$s4, _textBlockSelection$s5;
|
|
45
41
|
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
46
42
|
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
47
43
|
editor = _useLexicalComposerCo2[0];
|
|
@@ -50,87 +46,85 @@ var TypographyAction = function TypographyAction() {
|
|
|
50
46
|
typography = _useState2[0],
|
|
51
47
|
setTypography = _useState2[1];
|
|
52
48
|
var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
|
|
53
|
-
textBlockSelection = _useRichTextEditor.textBlockSelection,
|
|
54
49
|
themeEmotionMap = _useRichTextEditor.themeEmotionMap;
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
var
|
|
50
|
+
var _useCurrentElement = (0, _useCurrentElement2.useCurrentElement)(),
|
|
51
|
+
element = _useCurrentElement.element;
|
|
52
|
+
var isTypographySelected = (0, _lexicalNodes.$isTypographyNode)(element);
|
|
53
|
+
var isParagraphSelected = (0, _lexicalNodes.$isParagraphNode)(element);
|
|
54
|
+
var isHeadingSelected = (0, _lexicalNodes.$isHeadingNode)(element);
|
|
55
|
+
var isQuoteSelected = (0, _lexicalNodes.$isQuoteNode)(element);
|
|
60
56
|
var setTypographySelect = (0, _react.useCallback)(function (value) {
|
|
61
57
|
setTypography(value);
|
|
62
58
|
}, [typography]);
|
|
63
59
|
var onTypographySelect = (0, _react.useCallback)(function (value) {
|
|
64
60
|
setTypographySelect(value);
|
|
65
61
|
if (value.tag.includes("h") || value.tag.includes("p")) {
|
|
66
|
-
editor.dispatchCommand(
|
|
62
|
+
editor.dispatchCommand(_lexicalNodes.ADD_TYPOGRAPHY_COMMAND, {
|
|
67
63
|
value: value
|
|
68
64
|
});
|
|
69
65
|
}
|
|
70
66
|
if (value.tag === "ol") {
|
|
71
|
-
editor.dispatchCommand(
|
|
67
|
+
editor.dispatchCommand(_commands.INSERT_ORDERED_LIST_COMMAND, {
|
|
72
68
|
themeStyleId: value.id
|
|
73
69
|
});
|
|
74
70
|
}
|
|
75
71
|
if (value.tag === "ul") {
|
|
76
|
-
editor.dispatchCommand(
|
|
72
|
+
editor.dispatchCommand(_commands.INSERT_UNORDERED_LIST_COMMAND, {
|
|
77
73
|
themeStyleId: value.id
|
|
78
74
|
});
|
|
79
75
|
}
|
|
80
76
|
if (value.tag === "quoteblock") {
|
|
81
|
-
editor.dispatchCommand(
|
|
77
|
+
editor.dispatchCommand(_commands.INSERT_QUOTE_COMMAND, {
|
|
82
78
|
themeStyleId: value.id
|
|
83
79
|
});
|
|
84
80
|
}
|
|
85
81
|
}, []);
|
|
86
82
|
(0, _react.useEffect)(function () {
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
83
|
+
if (!element) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
// header and paragraph elements inserted with typography node
|
|
87
|
+
if (isTypographySelected) {
|
|
88
|
+
var el = element;
|
|
89
|
+
setTypography(el.getTypographyValue());
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (isParagraphSelected || isHeadingSelected || isQuoteSelected) {
|
|
93
|
+
var styleId = element.getTypographyStyleId();
|
|
94
|
+
if (!styleId) {
|
|
93
95
|
return;
|
|
94
96
|
}
|
|
95
|
-
if (
|
|
96
|
-
var elementWithThemeStyle = textBlockSelection === null || textBlockSelection === void 0 ? void 0 : textBlockSelection.element;
|
|
97
|
-
var styleId = elementWithThemeStyle.getTypographyStyleId();
|
|
98
|
-
if (!styleId) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (!themeEmotionMap) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
var style = themeEmotionMap[styleId];
|
|
105
|
-
if (style) {
|
|
106
|
-
setTypography({
|
|
107
|
-
name: style === null || style === void 0 ? void 0 : style.name,
|
|
108
|
-
id: style.id,
|
|
109
|
-
css: style.styles,
|
|
110
|
-
tag: style.tag
|
|
111
|
-
});
|
|
112
|
-
}
|
|
97
|
+
if (!themeEmotionMap) {
|
|
113
98
|
return;
|
|
114
99
|
}
|
|
100
|
+
var style = themeEmotionMap[styleId];
|
|
101
|
+
if (style) {
|
|
102
|
+
setTypography({
|
|
103
|
+
name: style === null || style === void 0 ? void 0 : style.name,
|
|
104
|
+
id: style.id,
|
|
105
|
+
css: style.styles,
|
|
106
|
+
tag: style.tag
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
115
111
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
-
}
|
|
112
|
+
// list and quote element
|
|
113
|
+
if (themeEmotionMap && element !== null && element !== void 0 && element.getStyleId) {
|
|
114
|
+
var themeStyleId = (element === null || element === void 0 ? void 0 : element.getStyleId()) || undefined;
|
|
115
|
+
if (themeStyleId) {
|
|
116
|
+
var elementStyle = themeEmotionMap[themeStyleId];
|
|
117
|
+
if (elementStyle) {
|
|
118
|
+
setTypography({
|
|
119
|
+
id: elementStyle.id,
|
|
120
|
+
css: elementStyle.styles,
|
|
121
|
+
name: elementStyle.name,
|
|
122
|
+
tag: elementStyle.tag
|
|
123
|
+
});
|
|
130
124
|
}
|
|
131
125
|
}
|
|
132
126
|
}
|
|
133
|
-
}, [
|
|
127
|
+
}, [element, isTypographySelected, isQuoteSelected, isParagraphSelected, isHeadingSelected]);
|
|
134
128
|
return /*#__PURE__*/_react.default.createElement(_TypographyActionContext.TypographyActionContext.Provider, {
|
|
135
129
|
value: {
|
|
136
130
|
value: typography,
|
|
@@ -139,7 +133,6 @@ var TypographyAction = function TypographyAction() {
|
|
|
139
133
|
}, /*#__PURE__*/_react.default.createElement(BaseTypographyActionDropDown, null));
|
|
140
134
|
};
|
|
141
135
|
exports.TypographyAction = TypographyAction;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
TypographyAction.TypographyDropDown = TypographyActionDropDown;
|
|
136
|
+
TypographyAction.TypographyDropDown = TypographyActionDropDown;
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=TypographyAction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_LexicalComposerContext","_reactComposition","_TypographyActionContext","_TypographyElementNode","_useRichTextEditor2","_webinyList","_webinyQuote","_ParagraphNode","_HeadingNode","_QuoteNode","BaseTypographyActionDropDown","makeComposable","useEffect","console","log","exports","TypographyActionDropDown","_ref","element","default","createElement","Compose","component","with","_with","TypographyAction","_textBlockSelection$s","_textBlockSelection$s2","_textBlockSelection$s3","_textBlockSelection$s4","_textBlockSelection$s5","_useLexicalComposerCo","useLexicalComposerContext","_useLexicalComposerCo2","_slicedToArray2","editor","_useState","useState","_useState2","typography","setTypography","_useRichTextEditor","useRichTextEditor","textBlockSelection","themeEmotionMap","isTypographySelected","state","isSelected","isParagraphSelected","paragraph","isHeadingSelected","heading","textType","isQuoteSelected","quote","setTypographySelect","useCallback","value","onTypographySelect","tag","includes","dispatchCommand","ADD_TYPOGRAPHY_ELEMENT_COMMAND","INSERT_ORDERED_WEBINY_LIST_COMMAND","themeStyleId","id","INSERT_UNORDERED_WEBINY_LIST_COMMAND","INSERT_WEBINY_QUOTE_COMMAND","_textBlockSelection$e","$isTypographyElementNode","el","getTypographyValue","$isParagraphNode","$isHeadingNode","$isQuoteNode","elementWithThemeStyle","styleId","getTypographyStyleId","style","name","css","styles","getStyleId","_textBlockSelection$e2","undefined","elementStyle","TypographyActionContext","Provider","applyTypography","TypographyDropDown"],"sources":["TypographyAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { LexicalCommand } from \"lexical\";\nimport { Compose, makeComposable } from \"@webiny/react-composition\";\nimport { TypographyActionContext } from \"~/context/TypographyActionContext\";\n\nimport { TypographyValue } from \"~/types\";\nimport {\n $isTypographyElementNode,\n ADD_TYPOGRAPHY_ELEMENT_COMMAND,\n TypographyElementNode,\n TypographyPayload\n} from \"~/nodes/TypographyElementNode\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport {\n INSERT_ORDERED_WEBINY_LIST_COMMAND,\n INSERT_UNORDERED_WEBINY_LIST_COMMAND,\n WebinyListCommandPayload\n} from \"~/commands/webiny-list\";\nimport { INSERT_WEBINY_QUOTE_COMMAND, WebinyQuoteCommandPayload } from \"~/commands/webiny-quote\";\nimport { $isParagraphNode } from \"~/nodes/ParagraphNode\";\nimport { $isHeadingNode } from \"~/nodes/HeadingNode\";\nimport { $isQuoteNode } from \"~/nodes/QuoteNode\";\n\n/*\n * Base composable action component that is mounted on toolbar action as a placeholder for the custom toolbar action.\n * Note: Toa add custom component access trough @see LexicalEditorConfig API\n * */\nexport const BaseTypographyActionDropDown = makeComposable(\n \"BaseTypographyActionDropDown\",\n (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default BaseTypographyActionDropDown, please add your own component\");\n }, []);\n return null;\n }\n);\n\ninterface TypographyActionDropdownProps {\n element: JSX.Element;\n}\n\nconst TypographyActionDropDown: React.FC<TypographyActionDropdownProps> = ({\n element\n}): JSX.Element => {\n return <Compose component={BaseTypographyActionDropDown} with={() => () => element} />;\n};\n\nexport interface TypographyAction extends React.FC<unknown> {\n TypographyDropDown: typeof TypographyActionDropDown;\n}\n\nexport const TypographyAction: TypographyAction = () => {\n const [editor] = useLexicalComposerContext();\n const [typography, setTypography] = useState<TypographyValue>();\n const { textBlockSelection, themeEmotionMap } = useRichTextEditor();\n const isTypographySelected = textBlockSelection?.state?.typography.isSelected || false;\n const isParagraphSelected = textBlockSelection?.state?.paragraph.isSelected || false;\n const isHeadingSelected = textBlockSelection?.state?.heading.isSelected || false;\n const textType = textBlockSelection?.state?.textType;\n const isQuoteSelected = textBlockSelection?.state?.quote.isSelected || false;\n const setTypographySelect = useCallback(\n (value: TypographyValue) => {\n setTypography(value);\n },\n [typography]\n );\n\n const onTypographySelect = useCallback((value: TypographyValue) => {\n setTypographySelect(value);\n if (value.tag.includes(\"h\") || value.tag.includes(\"p\")) {\n editor.dispatchCommand<LexicalCommand<TypographyPayload>>(\n ADD_TYPOGRAPHY_ELEMENT_COMMAND,\n {\n value\n }\n );\n }\n\n if (value.tag === \"ol\") {\n editor.dispatchCommand<LexicalCommand<WebinyListCommandPayload>>(\n INSERT_ORDERED_WEBINY_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"ul\") {\n editor.dispatchCommand<LexicalCommand<WebinyListCommandPayload>>(\n INSERT_UNORDERED_WEBINY_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"quoteblock\") {\n editor.dispatchCommand<LexicalCommand<WebinyQuoteCommandPayload>>(\n INSERT_WEBINY_QUOTE_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n }, []);\n\n useEffect(() => {\n if (textBlockSelection) {\n // header and paragraph elements inserted with typography node\n if ($isTypographyElementNode(textBlockSelection?.element)) {\n const el = textBlockSelection.element as TypographyElementNode;\n setTypography(el.getTypographyValue());\n return;\n }\n\n if (\n $isParagraphNode(textBlockSelection?.element) ||\n $isHeadingNode(textBlockSelection?.element) ||\n $isQuoteNode(textBlockSelection?.element)\n ) {\n const elementWithThemeStyle = textBlockSelection?.element;\n const styleId = elementWithThemeStyle.getTypographyStyleId();\n if (!styleId) {\n return;\n }\n\n if (!themeEmotionMap) {\n return;\n }\n\n const style = themeEmotionMap[styleId];\n if (style) {\n setTypography({\n name: style?.name,\n id: style.id,\n css: style.styles,\n tag: style.tag\n });\n }\n return;\n }\n\n // list and quote element\n if (themeEmotionMap && textBlockSelection?.element?.getStyleId) {\n const themeStyleId = textBlockSelection?.element?.getStyleId() || undefined;\n if (themeStyleId) {\n const elementStyle = themeEmotionMap[themeStyleId];\n if (elementStyle) {\n setTypography({\n id: elementStyle.id,\n css: elementStyle.styles,\n name: elementStyle.name,\n tag: elementStyle.tag\n });\n }\n }\n }\n }\n }, [isTypographySelected, textType, isQuoteSelected, isParagraphSelected, isHeadingSelected]);\n\n return (\n <TypographyActionContext.Provider\n value={{\n value: typography,\n applyTypography: onTypographySelect\n }}\n >\n <BaseTypographyActionDropDown />\n </TypographyActionContext.Provider>\n );\n};\n\n{\n /* Typography dropdown settings */\n}\nTypographyAction.TypographyDropDown = TypographyActionDropDown;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AAEA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,wBAAA,GAAAH,OAAA;AAGA,IAAAI,sBAAA,GAAAJ,OAAA;AAMA,IAAAK,mBAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAKA,IAAAO,YAAA,GAAAP,OAAA;AACA,IAAAQ,cAAA,GAAAR,OAAA;AACA,IAAAS,YAAA,GAAAT,OAAA;AACA,IAAAU,UAAA,GAAAV,OAAA;AAEA;AACA;AACA;AACA;AACO,IAAMW,4BAA4B,GAAG,IAAAC,gCAAc,EACtD,8BAA8B,EAC9B,YAA0B;EACtB,IAAAC,gBAAS,EAAC,YAAM;IACZC,OAAO,CAACC,GAAG,CAAC,qEAAqE,CAAC;EACtF,CAAC,EAAE,EAAE,CAAC;EACN,OAAO,IAAI;AACf,CACJ,CAAC;AAACC,OAAA,CAAAL,4BAAA,GAAAA,4BAAA;AAMF,IAAMM,wBAAiE,GAAG,SAApEA,wBAAiEA,CAAAC,IAAA,EAEpD;EAAA,IADfC,OAAO,GAAAD,IAAA,CAAPC,OAAO;EAEP,oBAAOrB,MAAA,CAAAsB,OAAA,CAAAC,aAAA,CAACnB,iBAAA,CAAAoB,OAAO;IAACC,SAAS,EAAEZ,4BAA6B;IAACa,IAAI,EAAE,SAAAC,MAAA;MAAA,OAAM;QAAA,OAAMN,OAAO;MAAA;IAAA;EAAC,CAAE,CAAC;AAC1F,CAAC;AAMM,IAAMO,gBAAkC,GAAG,SAArCA,gBAAkCA,CAAA,EAAS;EAAA,I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B,YAAY,GAAG,CAAArB,kBAAkB,aAAlBA,kBAAkB,wBAAAwC,sBAAA,GAAlBxC,kBAAkB,CAAEzB,OAAO,cAAAiE,sBAAA,uBAA3BA,sBAAA,CAA6BD,UAAU,CAAC,CAAC,KAAIE,SAAS;QAC3E,IAAIpB,YAAY,EAAE;UACd,IAAMqB,YAAY,GAAGzC,eAAe,CAACoB,YAAY,CAAC;UAClD,IAAIqB,YAAY,EAAE;YACd7C,aAAa,CAAC;cACVyB,EAAE,EAAEoB,YAAY,CAACpB,EAAE;cACnBe,GAAG,EAAEK,YAAY,CAACJ,MAAM;cACxBF,IAAI,EAAEM,YAAY,CAACN,IAAI;cACvBpB,GAAG,EAAE0B,YAAY,CAAC1B;YACtB,CAAC,CAAC;UACN;QACJ;MACJ;IACJ;EACJ,CAAC,EAAE,CAACd,oBAAoB,EAAEO,QAAQ,EAAEC,eAAe,EAAEL,mBAAmB,EAAEE,iBAAiB,CAAC,CAAC;EAE7F,oBACIrD,MAAA,CAAAsB,OAAA,CAAAC,aAAA,CAAClB,wBAAA,CAAAoF,uBAAuB,CAACC,QAAQ;IAC7B9B,KAAK,EAAE;MACHA,KAAK,EAAElB,UAAU;MACjBiD,eAAe,EAAE9B;IACrB;EAAE,gBAEF7D,MAAA,CAAAsB,OAAA,CAAAC,aAAA,CAACV,4BAA4B,MAAE,CACD,CAAC;AAE3C,CAAC;AAACK,OAAA,CAAAU,gBAAA,GAAAA,gBAAA;AAEF;EACI;AAAA;AAEJA,gBAAgB,CAACgE,kBAAkB,GAAGzE,wBAAwB"}
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_LexicalComposerContext","_reactComposition","_TypographyActionContext","_lexicalNodes","_useRichTextEditor2","_commands","_useCurrentElement2","BaseTypographyActionDropDown","makeComposable","useEffect","console","log","exports","TypographyActionDropDown","_ref","element","default","createElement","Compose","component","with","_with","TypographyAction","_useLexicalComposerCo","useLexicalComposerContext","_useLexicalComposerCo2","_slicedToArray2","editor","_useState","useState","_useState2","typography","setTypography","_useRichTextEditor","useRichTextEditor","themeEmotionMap","_useCurrentElement","useCurrentElement","isTypographySelected","$isTypographyNode","isParagraphSelected","$isParagraphNode","isHeadingSelected","$isHeadingNode","isQuoteSelected","$isQuoteNode","setTypographySelect","useCallback","value","onTypographySelect","tag","includes","dispatchCommand","ADD_TYPOGRAPHY_COMMAND","INSERT_ORDERED_LIST_COMMAND","themeStyleId","id","INSERT_UNORDERED_LIST_COMMAND","INSERT_QUOTE_COMMAND","el","getTypographyValue","styleId","getTypographyStyleId","style","name","css","styles","getStyleId","undefined","elementStyle","TypographyActionContext","Provider","applyTypography","TypographyDropDown"],"sources":["TypographyAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { LexicalCommand } from \"lexical\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { Compose, makeComposable } from \"@webiny/react-composition\";\nimport { TypographyValue } from \"@webiny/lexical-theme\";\nimport { TypographyActionContext } from \"~/context/TypographyActionContext\";\nimport {\n $isHeadingNode,\n $isParagraphNode,\n $isQuoteNode,\n $isTypographyNode,\n ADD_TYPOGRAPHY_COMMAND,\n TypographyNode,\n TypographyPayload\n} from \"@webiny/lexical-nodes\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport {\n INSERT_ORDERED_LIST_COMMAND,\n INSERT_UNORDERED_LIST_COMMAND,\n INSERT_QUOTE_COMMAND,\n ListCommandPayload,\n QuoteCommandPayload\n} from \"~/commands\";\nimport { useCurrentElement } from \"~/hooks/useCurrentElement\";\n\n/*\n * Base composable action component that is mounted on toolbar action as a placeholder for the custom toolbar action.\n * Note: Toa add custom component access trough @see LexicalEditorConfig API\n * */\nexport const BaseTypographyActionDropDown = makeComposable(\n \"BaseTypographyActionDropDown\",\n (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default BaseTypographyActionDropDown, please add your own component\");\n }, []);\n return null;\n }\n);\n\ninterface TypographyActionDropdownProps {\n element: JSX.Element;\n}\n\nconst TypographyActionDropDown: React.FC<TypographyActionDropdownProps> = ({\n element\n}): JSX.Element => {\n return <Compose component={BaseTypographyActionDropDown} with={() => () => element} />;\n};\n\nexport interface TypographyAction extends React.FC<unknown> {\n TypographyDropDown: typeof TypographyActionDropDown;\n}\n\nexport const TypographyAction: TypographyAction = () => {\n const [editor] = useLexicalComposerContext();\n const [typography, setTypography] = useState<TypographyValue>();\n const { themeEmotionMap } = useRichTextEditor();\n const { element } = useCurrentElement();\n const isTypographySelected = $isTypographyNode(element);\n const isParagraphSelected = $isParagraphNode(element);\n const isHeadingSelected = $isHeadingNode(element);\n const isQuoteSelected = $isQuoteNode(element);\n\n const setTypographySelect = useCallback(\n (value: TypographyValue) => {\n setTypography(value);\n },\n [typography]\n );\n\n const onTypographySelect = useCallback((value: TypographyValue) => {\n setTypographySelect(value);\n if (value.tag.includes(\"h\") || value.tag.includes(\"p\")) {\n editor.dispatchCommand<LexicalCommand<TypographyPayload>>(ADD_TYPOGRAPHY_COMMAND, {\n value\n });\n }\n\n if (value.tag === \"ol\") {\n editor.dispatchCommand<LexicalCommand<ListCommandPayload>>(\n INSERT_ORDERED_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"ul\") {\n editor.dispatchCommand<LexicalCommand<ListCommandPayload>>(\n INSERT_UNORDERED_LIST_COMMAND,\n {\n themeStyleId: value.id\n }\n );\n }\n\n if (value.tag === \"quoteblock\") {\n editor.dispatchCommand<LexicalCommand<QuoteCommandPayload>>(INSERT_QUOTE_COMMAND, {\n themeStyleId: value.id\n });\n }\n }, []);\n\n useEffect(() => {\n if (!element) {\n return;\n }\n // header and paragraph elements inserted with typography node\n if (isTypographySelected) {\n const el = element as TypographyNode;\n setTypography(el.getTypographyValue());\n return;\n }\n\n if (isParagraphSelected || isHeadingSelected || isQuoteSelected) {\n const styleId = element.getTypographyStyleId();\n if (!styleId) {\n return;\n }\n\n if (!themeEmotionMap) {\n return;\n }\n\n const style = themeEmotionMap[styleId];\n if (style) {\n setTypography({\n name: style?.name,\n id: style.id,\n css: style.styles,\n tag: style.tag\n });\n }\n return;\n }\n\n // list and quote element\n if (themeEmotionMap && element?.getStyleId) {\n const themeStyleId = element?.getStyleId() || undefined;\n if (themeStyleId) {\n const elementStyle = themeEmotionMap[themeStyleId];\n if (elementStyle) {\n setTypography({\n id: elementStyle.id,\n css: elementStyle.styles,\n name: elementStyle.name,\n tag: elementStyle.tag\n });\n }\n }\n }\n }, [element, isTypographySelected, isQuoteSelected, isParagraphSelected, isHeadingSelected]);\n\n return (\n <TypographyActionContext.Provider\n value={{\n value: typography,\n applyTypography: onTypographySelect\n }}\n >\n <BaseTypographyActionDropDown />\n </TypographyActionContext.Provider>\n );\n};\n\nTypographyAction.TypographyDropDown = TypographyActionDropDown;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,uBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AAEA,IAAAG,wBAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AASA,IAAAK,mBAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAOA,IAAAO,mBAAA,GAAAP,OAAA;AAEA;AACA;AACA;AACA;AACO,IAAMQ,4BAA4B,GAAG,IAAAC,gCAAc,EACtD,8BAA8B,EAC9B,YAA0B;EACtB,IAAAC,gBAAS,EAAC,YAAM;IACZC,OAAO,CAACC,GAAG,CAAC,qEAAqE,CAAC;EACtF,CAAC,EAAE,EAAE,CAAC;EACN,OAAO,IAAI;AACf,CACJ,CAAC;AAACC,OAAA,CAAAL,4BAAA,GAAAA,4BAAA;AAMF,IAAMM,wBAAiE,GAAG,SAApEA,wBAAiEA,CAAAC,IAAA,EAEpD;EAAA,IADfC,OAAO,GAAAD,IAAA,CAAPC,OAAO;EAEP,oBAAOlB,MAAA,CAAAmB,OAAA,CA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|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.UnderlineAction = void 0;
|
|
9
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
-
var _react =
|
|
11
|
-
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
12
10
|
var _lexical = require("lexical");
|
|
13
|
-
var
|
|
11
|
+
var _useCurrentSelection2 = require("../../hooks/useCurrentSelection");
|
|
12
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
14
13
|
var UnderlineAction = function UnderlineAction() {
|
|
15
|
-
var _textBlockSelection$s;
|
|
16
14
|
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
17
15
|
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
18
16
|
editor = _useLexicalComposerCo2[0];
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
setIsUnderline = _useState2[1];
|
|
23
|
-
var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
|
|
24
|
-
textBlockSelection = _useRichTextEditor.textBlockSelection;
|
|
25
|
-
var isUnderlineSelected = !!(textBlockSelection !== null && textBlockSelection !== void 0 && (_textBlockSelection$s = textBlockSelection.state) !== null && _textBlockSelection$s !== void 0 && _textBlockSelection$s.underline);
|
|
26
|
-
(0, _react.useEffect)(function () {
|
|
27
|
-
setIsUnderline(isUnderlineSelected);
|
|
28
|
-
}, [isUnderlineSelected]);
|
|
17
|
+
var _useCurrentSelection = (0, _useCurrentSelection2.useCurrentSelection)(),
|
|
18
|
+
rangeSelection = _useCurrentSelection.rangeSelection;
|
|
19
|
+
var isUnderlineSelected = rangeSelection ? rangeSelection.hasFormat("underline") : false;
|
|
29
20
|
var handleClick = function handleClick() {
|
|
30
21
|
editor.dispatchCommand(_lexical.FORMAT_TEXT_COMMAND, "underline");
|
|
31
|
-
setIsUnderline(!isUnderline);
|
|
32
22
|
};
|
|
33
23
|
return /*#__PURE__*/_react.default.createElement("button", {
|
|
34
|
-
onClick:
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
className: "popup-item spaced " + (isUnderline ? "active" : ""),
|
|
24
|
+
onClick: handleClick,
|
|
25
|
+
className: "popup-item spaced " + (isUnderlineSelected ? "active" : ""),
|
|
38
26
|
"aria-label": "Format text as italic"
|
|
39
27
|
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
40
28
|
className: "format underline"
|
|
41
29
|
}));
|
|
42
30
|
};
|
|
43
|
-
exports.UnderlineAction = UnderlineAction;
|
|
31
|
+
exports.UnderlineAction = UnderlineAction;
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=UnderlineAction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_lexical","_useCurrentSelection2","_LexicalComposerContext","UnderlineAction","_useLexicalComposerCo","useLexicalComposerContext","_useLexicalComposerCo2","_slicedToArray2","default","editor","_useCurrentSelection","useCurrentSelection","rangeSelection","isUnderlineSelected","hasFormat","handleClick","dispatchCommand","FORMAT_TEXT_COMMAND","createElement","onClick","className","exports"],"sources":["UnderlineAction.tsx"],"sourcesContent":["import React from \"react\";\nimport { FORMAT_TEXT_COMMAND } from \"lexical\";\nimport { useCurrentSelection } from \"~/hooks/useCurrentSelection\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\n\nexport const UnderlineAction = () => {\n const [editor] = useLexicalComposerContext();\n const { rangeSelection } = useCurrentSelection();\n const isUnderlineSelected = rangeSelection ? rangeSelection.hasFormat(\"underline\") : false;\n\n const handleClick = () => {\n editor.dispatchCommand(FORMAT_TEXT_COMMAND, \"underline\");\n };\n\n return (\n <button\n onClick={handleClick}\n className={\"popup-item spaced \" + (isUnderlineSelected ? \"active\" : \"\")}\n aria-label=\"Format text as italic\"\n >\n <i className=\"format underline\" />\n </button>\n );\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,qBAAA,GAAAF,OAAA;AACA,IAAAG,uBAAA,GAAAH,OAAA;AAEO,IAAMI,eAAe,GAAG,SAAlBA,eAAeA,CAAA,EAAS;EACjC,IAAAC,qBAAA,GAAiB,IAAAC,iDAAyB,EAAC,CAAC;IAAAC,sBAAA,OAAAC,eAAA,CAAAC,OAAA,EAAAJ,qBAAA;IAArCK,MAAM,GAAAH,sBAAA;EACb,IAAAI,oBAAA,GAA2B,IAAAC,yCAAmB,EAAC,CAAC;IAAxCC,cAAc,GAAAF,oBAAA,CAAdE,cAAc;EACtB,IAAMC,mBAAmB,GAAGD,cAAc,GAAGA,cAAc,CAACE,SAAS,CAAC,WAAW,CAAC,GAAG,KAAK;EAE1F,IAAMC,WAAW,GAAG,SAAdA,WAAWA,CAAA,EAAS;IACtBN,MAAM,CAACO,eAAe,CAACC,4BAAmB,EAAE,WAAW,CAAC;EAC5D,CAAC;EAED,oBACIpB,MAAA,CAAAW,OAAA,CAAAU,aAAA;IACIC,OAAO,EAAEJ,WAAY;IACrBK,SAAS,EAAE,oBAAoB,IAAIP,mBAAmB,GAAG,QAAQ,GAAG,EAAE,CAAE;IACxE,cAAW;EAAuB,gBAElChB,MAAA,CAAAW,OAAA,CAAAU,aAAA;IAAGE,SAAS,EAAC;EAAkB,CAAE,CAC7B,CAAC;AAEjB,CAAC;AAACC,OAAA,CAAAlB,eAAA,GAAAA,eAAA"}
|
|
@@ -7,4 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.FontColorActionContext = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var FontColorActionContext = /*#__PURE__*/_react.default.createContext(undefined);
|
|
10
|
-
exports.FontColorActionContext = FontColorActionContext;
|
|
10
|
+
exports.FontColorActionContext = FontColorActionContext;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=FontColorActionContext.js.map
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { TextBlockSelection, ThemeEmotionMap, ToolbarActionPlugin, ToolbarType } from "../types";
|
|
3
|
-
import { WebinyTheme } from "../themes/webinyLexicalTheme";
|
|
4
2
|
import { LexicalEditor } from "lexical";
|
|
3
|
+
import type { ThemeEmotionMap, WebinyTheme } from "@webiny/lexical-theme";
|
|
4
|
+
import { ToolbarActionPlugin, ToolbarType } from "../types";
|
|
5
5
|
export interface RichTextEditorContext {
|
|
6
|
-
nodeIsText: boolean;
|
|
7
|
-
setNodeIsText: (nodeIsText: boolean) => void;
|
|
8
6
|
toolbarType?: ToolbarType;
|
|
9
7
|
setToolbarType: (type: ToolbarType) => void;
|
|
10
|
-
textBlockSelection: TextBlockSelection | null;
|
|
11
|
-
setTextBlockSelection: (textBlockSelection: TextBlockSelection) => void;
|
|
12
8
|
theme?: WebinyTheme;
|
|
13
9
|
setTheme: (theme: WebinyTheme) => void;
|
|
14
10
|
themeEmotionMap?: ThemeEmotionMap;
|
|
@@ -12,52 +12,34 @@ var RichTextEditorContext = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
|
12
12
|
exports.RichTextEditorContext = RichTextEditorContext;
|
|
13
13
|
var RichTextEditorProvider = function RichTextEditorProvider(_ref) {
|
|
14
14
|
var children = _ref.children;
|
|
15
|
-
var _useState = (0, _react.useState)(
|
|
15
|
+
var _useState = (0, _react.useState)(),
|
|
16
16
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var _useState3 = (0, _react.useState)(),
|
|
17
|
+
toolbarType = _useState2[0],
|
|
18
|
+
setToolbarType = _useState2[1];
|
|
19
|
+
var _useState3 = (0, _react.useState)(undefined),
|
|
20
20
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
theme = _useState4[0],
|
|
22
|
+
setTheme = _useState4[1];
|
|
23
23
|
var _useState5 = (0, _react.useState)(undefined),
|
|
24
24
|
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var _useState7 = (0, _react.useState)(
|
|
25
|
+
themeEmotionMap = _useState6[0],
|
|
26
|
+
setThemeEmotionMap = _useState6[1];
|
|
27
|
+
var _useState7 = (0, _react.useState)([]),
|
|
28
28
|
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var _useState9 = (0, _react.useState)(
|
|
29
|
+
toolbarActionPlugins = _useState8[0],
|
|
30
|
+
setToolbarActionPlugins = _useState8[1];
|
|
31
|
+
var _useState9 = (0, _react.useState)(),
|
|
32
32
|
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var _useState11 = (0, _react.useState)(),
|
|
33
|
+
activeEditor = _useState10[0],
|
|
34
|
+
setActiveEditor = _useState10[1];
|
|
35
|
+
var _useState11 = (0, _react.useState)(false),
|
|
36
36
|
_useState12 = (0, _slicedToArray2.default)(_useState11, 2),
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var _useState13 = (0, _react.useState)(false),
|
|
40
|
-
_useState14 = (0, _slicedToArray2.default)(_useState13, 2),
|
|
41
|
-
isEditable = _useState14[0],
|
|
42
|
-
setIsEditable = _useState14[1];
|
|
43
|
-
/*
|
|
44
|
-
* @desc Keeps data from current user text selection like range selection, nodes, node key...
|
|
45
|
-
*/
|
|
46
|
-
var _useState15 = (0, _react.useState)(null),
|
|
47
|
-
_useState16 = (0, _slicedToArray2.default)(_useState15, 2),
|
|
48
|
-
textBlockSelection = _useState16[0],
|
|
49
|
-
setTextBlockSelection = _useState16[1];
|
|
50
|
-
var setNodeIsText = function setNodeIsText(nodeIsText) {
|
|
51
|
-
setIsText(nodeIsText);
|
|
52
|
-
};
|
|
37
|
+
isEditable = _useState12[0],
|
|
38
|
+
setIsEditable = _useState12[1];
|
|
53
39
|
return /*#__PURE__*/_react.default.createElement(RichTextEditorContext.Provider, {
|
|
54
40
|
value: {
|
|
55
|
-
nodeIsText: nodeIsText,
|
|
56
|
-
setNodeIsText: setNodeIsText,
|
|
57
41
|
toolbarType: toolbarType,
|
|
58
42
|
setToolbarType: setToolbarType,
|
|
59
|
-
textBlockSelection: textBlockSelection,
|
|
60
|
-
setTextBlockSelection: setTextBlockSelection,
|
|
61
43
|
theme: theme,
|
|
62
44
|
setTheme: setTheme,
|
|
63
45
|
themeEmotionMap: themeEmotionMap,
|
|
@@ -71,4 +53,6 @@ var RichTextEditorProvider = function RichTextEditorProvider(_ref) {
|
|
|
71
53
|
}
|
|
72
54
|
}, children);
|
|
73
55
|
};
|
|
74
|
-
exports.RichTextEditorProvider = RichTextEditorProvider;
|
|
56
|
+
exports.RichTextEditorProvider = RichTextEditorProvider;
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=RichTextEditorContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","RichTextEditorContext","createContext","undefined","exports","RichTextEditorProvider","_ref","children","_useState","useState","_useState2","_slicedToArray2","default","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","RichTextEditorContext","createContext","undefined","exports","RichTextEditorProvider","_ref","children","_useState","useState","_useState2","_slicedToArray2","default","toolbarType","setToolbarType","_useState3","_useState4","theme","setTheme","_useState5","_useState6","themeEmotionMap","setThemeEmotionMap","_useState7","_useState8","toolbarActionPlugins","setToolbarActionPlugins","_useState9","_useState10","activeEditor","setActiveEditor","_useState11","_useState12","isEditable","setIsEditable","createElement","Provider","value"],"sources":["RichTextEditorContext.tsx"],"sourcesContent":["import React, { createContext, useState } from \"react\";\nimport { LexicalEditor } from \"lexical\";\nimport type { ThemeEmotionMap, WebinyTheme } from \"@webiny/lexical-theme\";\nimport { ToolbarActionPlugin, ToolbarType } from \"~/types\";\n\nexport interface RichTextEditorContext {\n toolbarType?: ToolbarType;\n setToolbarType: (type: ToolbarType) => void;\n theme?: WebinyTheme;\n setTheme: (theme: WebinyTheme) => void;\n themeEmotionMap?: ThemeEmotionMap;\n setThemeEmotionMap: (themeEmotionMap?: ThemeEmotionMap) => void;\n toolbarActionPlugins: ToolbarActionPlugin[];\n setToolbarActionPlugins: (actionPlugins: ToolbarActionPlugin[]) => void;\n activeEditor?: LexicalEditor;\n setActiveEditor: (editor: LexicalEditor) => void;\n isEditable: boolean;\n setIsEditable: (isEditable: boolean) => void;\n}\n\nexport const RichTextEditorContext = createContext<RichTextEditorContext | undefined>(undefined);\n\ninterface RichTextEditorProviderProps {\n children?: React.ReactNode | React.ReactNode[];\n}\n\nexport const RichTextEditorProvider: React.FC<RichTextEditorProviderProps> = ({ children }) => {\n const [toolbarType, setToolbarType] = useState<ToolbarType | undefined>();\n const [theme, setTheme] = useState<WebinyTheme | undefined>(undefined);\n const [themeEmotionMap, setThemeEmotionMap] = useState<ThemeEmotionMap | undefined>(undefined);\n const [toolbarActionPlugins, setToolbarActionPlugins] = useState<ToolbarActionPlugin[]>([]);\n const [activeEditor, setActiveEditor] = useState<LexicalEditor>();\n const [isEditable, setIsEditable] = useState<boolean>(false);\n\n return (\n <RichTextEditorContext.Provider\n value={{\n toolbarType,\n setToolbarType,\n theme,\n setTheme,\n themeEmotionMap,\n setThemeEmotionMap,\n activeEditor,\n setActiveEditor,\n isEditable,\n setIsEditable,\n toolbarActionPlugins,\n setToolbarActionPlugins\n }}\n >\n {children}\n </RichTextEditorContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;A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AAU,GAAAD,WAAA;IAAEE,aAAa,GAAAF,WAAA;EAEhC,oBACIlC,MAAA,CAAAc,OAAA,CAAAuB,aAAA,CAAClC,qBAAqB,CAACmC,QAAQ;IAC3BC,KAAK,EAAE;MACHxB,WAAW,EAAXA,WAAW;MACXC,cAAc,EAAdA,cAAc;MACdG,KAAK,EAALA,KAAK;MACLC,QAAQ,EAARA,QAAQ;MACRG,eAAe,EAAfA,eAAe;MACfC,kBAAkB,EAAlBA,kBAAkB;MAClBO,YAAY,EAAZA,YAAY;MACZC,eAAe,EAAfA,eAAe;MACfG,UAAU,EAAVA,UAAU;MACVC,aAAa,EAAbA,aAAa;MACbT,oBAAoB,EAApBA,oBAAoB;MACpBC,uBAAuB,EAAvBA;IACJ;EAAE,GAEDnB,QAC2B,CAAC;AAEzC,CAAC;AAACH,OAAA,CAAAC,sBAAA,GAAAA,sBAAA"}
|
|
@@ -23,4 +23,6 @@ exports.SharedHistoryContext = SharedHistoryContext;
|
|
|
23
23
|
var useSharedHistoryContext = function useSharedHistoryContext() {
|
|
24
24
|
return (0, React.useContext)(Context);
|
|
25
25
|
};
|
|
26
|
-
exports.useSharedHistoryContext = useSharedHistoryContext;
|
|
26
|
+
exports.useSharedHistoryContext = useSharedHistoryContext;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=SharedHistoryContext.js.map
|
|
@@ -7,4 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.TextAlignmentActionContext = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var TextAlignmentActionContext = /*#__PURE__*/_react.default.createContext(undefined);
|
|
10
|
-
exports.TextAlignmentActionContext = TextAlignmentActionContext;
|
|
10
|
+
exports.TextAlignmentActionContext = TextAlignmentActionContext;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=TextAlignmentActionContextProps.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { TypographyValue } from "
|
|
2
|
+
import { TypographyValue } from "@webiny/lexical-theme";
|
|
3
3
|
export interface TypographyActionContextProps {
|
|
4
4
|
value: TypographyValue | undefined;
|
|
5
5
|
applyTypography: (value: TypographyValue) => void;
|
|
@@ -7,4 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.TypographyActionContext = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var TypographyActionContext = /*#__PURE__*/_react.default.createContext(undefined);
|
|
10
|
-
exports.TypographyActionContext = TypographyActionContext;
|
|
10
|
+
exports.TypographyActionContext = TypographyActionContext;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=TypographyActionContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireDefault","require","TypographyActionContext","React","createContext","undefined","exports"],"sources":["TypographyActionContext.tsx"],"sourcesContent":["import React from \"react\";\nimport { TypographyValue } from \"
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","TypographyActionContext","React","createContext","undefined","exports"],"sources":["TypographyActionContext.tsx"],"sourcesContent":["import React from \"react\";\nimport { TypographyValue } from \"@webiny/lexical-theme\";\n\nexport interface TypographyActionContextProps {\n /*\n * @desc Current selected typography\n * */\n value: TypographyValue | undefined;\n\n /*\n * @desc Apply font family to selected text.\n * @params: value\n */\n applyTypography: (value: TypographyValue) => void;\n}\n\nexport const TypographyActionContext = React.createContext<\n TypographyActionContextProps | undefined\n>(undefined);\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAgBO,IAAMC,uBAAuB,gBAAGC,cAAK,CAACC,aAAa,CAExDC,SAAS,CAAC;AAACC,OAAA,CAAAJ,uBAAA,GAAAA,uBAAA"}
|
package/hooks/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./useRichTextEditor";
|
|
2
|
+
export * from "./useFontColorPicker";
|
|
3
|
+
export * from "./useTypographyAction";
|
|
4
|
+
export * from "./useTextAlignmentAction";
|
|
5
|
+
export * from "./useCurrentSelection";
|
|
6
|
+
export * from "./useCurrentElement";
|
|
7
|
+
export * from "./useIsMounted";
|