@webiny/lexical-editor 0.0.0-unstable.085ff6572f
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/LICENSE +21 -0
- package/README.md +17 -0
- package/commands/webiny-list.d.ts +7 -0
- package/commands/webiny-list.js +13 -0
- package/commands/webiny-list.js.map +1 -0
- package/commands/webiny-quote.d.ts +5 -0
- package/commands/webiny-quote.js +9 -0
- package/commands/webiny-quote.js.map +1 -0
- package/components/AddRichTextEditorNodeType.d.ts +6 -0
- package/components/AddRichTextEditorNodeType.js +28 -0
- package/components/AddRichTextEditorNodeType.js.map +1 -0
- package/components/AddRichTextEditorPlugin.d.ts +12 -0
- package/components/AddRichTextEditorPlugin.js +33 -0
- package/components/AddRichTextEditorPlugin.js.map +1 -0
- package/components/AddToolbarAction.d.ts +7 -0
- package/components/AddToolbarAction.js +33 -0
- package/components/AddToolbarAction.js.map +1 -0
- package/components/Editor/HeadingEditor.d.ts +7 -0
- package/components/Editor/HeadingEditor.js +29 -0
- package/components/Editor/HeadingEditor.js.map +1 -0
- package/components/Editor/ParagraphEditor.d.ts +7 -0
- package/components/Editor/ParagraphEditor.js +30 -0
- package/components/Editor/ParagraphEditor.js.map +1 -0
- package/components/Editor/RichTextEditor.d.ts +26 -0
- package/components/Editor/RichTextEditor.js +138 -0
- package/components/Editor/RichTextEditor.js.map +1 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +11 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +19 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -0
- package/components/LexicalHtmlRenderer.d.ts +16 -0
- package/components/LexicalHtmlRenderer.js +67 -0
- package/components/LexicalHtmlRenderer.js.map +1 -0
- package/components/Toolbar/HeadingToolbar.d.ts +12 -0
- package/components/Toolbar/HeadingToolbar.js +23 -0
- package/components/Toolbar/HeadingToolbar.js.map +1 -0
- package/components/Toolbar/ParagraphToolbar.d.ts +12 -0
- package/components/Toolbar/ParagraphToolbar.js +23 -0
- package/components/Toolbar/ParagraphToolbar.js.map +1 -0
- package/components/Toolbar/Toolbar.css +435 -0
- package/components/Toolbar/Toolbar.d.ts +13 -0
- package/components/Toolbar/Toolbar.js +215 -0
- package/components/Toolbar/Toolbar.js.map +1 -0
- package/components/ToolbarActions/BoldAction.d.ts +2 -0
- package/components/ToolbarActions/BoldAction.js +43 -0
- package/components/ToolbarActions/BoldAction.js.map +1 -0
- package/components/ToolbarActions/BulletListAction.d.ts +2 -0
- package/components/ToolbarActions/BulletListAction.js +56 -0
- package/components/ToolbarActions/BulletListAction.js.map +1 -0
- package/components/ToolbarActions/CodeHighlightAction.d.ts +2 -0
- package/components/ToolbarActions/CodeHighlightAction.js +43 -0
- package/components/ToolbarActions/CodeHighlightAction.js.map +1 -0
- package/components/ToolbarActions/FontColorAction.d.ts +11 -0
- package/components/ToolbarActions/FontColorAction.js +83 -0
- package/components/ToolbarActions/FontColorAction.js.map +1 -0
- package/components/ToolbarActions/FontSizeAction.d.ts +2 -0
- package/components/ToolbarActions/FontSizeAction.js +101 -0
- package/components/ToolbarActions/FontSizeAction.js.map +1 -0
- package/components/ToolbarActions/ItalicAction.d.ts +2 -0
- package/components/ToolbarActions/ItalicAction.js +43 -0
- package/components/ToolbarActions/ItalicAction.js.map +1 -0
- package/components/ToolbarActions/LinkAction.d.ts +2 -0
- package/components/ToolbarActions/LinkAction.js +64 -0
- package/components/ToolbarActions/LinkAction.js.map +1 -0
- package/components/ToolbarActions/NumberedListAction.d.ts +2 -0
- package/components/ToolbarActions/NumberedListAction.js +58 -0
- package/components/ToolbarActions/NumberedListAction.js.map +1 -0
- package/components/ToolbarActions/QuoteAction.d.ts +2 -0
- package/components/ToolbarActions/QuoteAction.js +52 -0
- package/components/ToolbarActions/QuoteAction.js.map +1 -0
- package/components/ToolbarActions/TextAlignmentAction.d.ts +11 -0
- package/components/ToolbarActions/TextAlignmentAction.js +70 -0
- package/components/ToolbarActions/TextAlignmentAction.js.map +1 -0
- package/components/ToolbarActions/TypographyAction.d.ts +11 -0
- package/components/ToolbarActions/TypographyAction.js +145 -0
- package/components/ToolbarActions/TypographyAction.js.map +1 -0
- package/components/ToolbarActions/UnderlineAction.d.ts +2 -0
- package/components/ToolbarActions/UnderlineAction.js +43 -0
- package/components/ToolbarActions/UnderlineAction.js.map +1 -0
- package/components/ToolbarPresets/HeadingToolbarPreset.d.ts +2 -0
- package/components/ToolbarPresets/HeadingToolbarPreset.js +56 -0
- package/components/ToolbarPresets/HeadingToolbarPreset.js.map +1 -0
- package/components/ToolbarPresets/ParagraphToolbarPreset.d.ts +2 -0
- package/components/ToolbarPresets/ParagraphToolbarPreset.js +71 -0
- package/components/ToolbarPresets/ParagraphToolbarPreset.js.map +1 -0
- package/context/FontColorActionContext.d.ts +6 -0
- package/context/FontColorActionContext.js +10 -0
- package/context/FontColorActionContext.js.map +1 -0
- package/context/RichTextEditorContext.d.ts +26 -0
- package/context/RichTextEditorContext.js +68 -0
- package/context/RichTextEditorContext.js.map +1 -0
- package/context/SharedHistoryContext.d.ts +11 -0
- package/context/SharedHistoryContext.js +26 -0
- package/context/SharedHistoryContext.js.map +1 -0
- package/context/TextAlignmentActionContextProps.d.ts +9 -0
- package/context/TextAlignmentActionContextProps.js +10 -0
- package/context/TextAlignmentActionContextProps.js.map +1 -0
- package/context/TypographyActionContext.d.ts +7 -0
- package/context/TypographyActionContext.js +10 -0
- package/context/TypographyActionContext.js.map +1 -0
- package/hooks/useFontColorPicker.d.ts +2 -0
- package/hooks/useFontColorPicker.js +15 -0
- package/hooks/useFontColorPicker.js.map +1 -0
- package/hooks/useList.d.ts +2 -0
- package/hooks/useList.js +39 -0
- package/hooks/useList.js.map +1 -0
- package/hooks/useQuote.d.ts +2 -0
- package/hooks/useQuote.js +20 -0
- package/hooks/useQuote.js.map +1 -0
- package/hooks/useRichTextEditor.d.ts +2 -0
- package/hooks/useRichTextEditor.js +15 -0
- package/hooks/useRichTextEditor.js.map +1 -0
- package/hooks/useTextAlignmentAction.d.ts +1 -0
- package/hooks/useTextAlignmentAction.js +15 -0
- package/hooks/useTextAlignmentAction.js.map +1 -0
- package/hooks/useTypographyAction.d.ts +1 -0
- package/hooks/useTypographyAction.js +15 -0
- package/hooks/useTypographyAction.js.map +1 -0
- package/images/icons/LICENSE.md +5 -0
- package/images/icons/chat-square-quote.svg +1 -0
- package/images/icons/chevron-down.svg +1 -0
- package/images/icons/code.svg +1 -0
- package/images/icons/font-color.svg +1 -0
- package/images/icons/indent.svg +3 -0
- package/images/icons/justify.svg +3 -0
- package/images/icons/link.svg +1 -0
- package/images/icons/list-ol.svg +1 -0
- package/images/icons/list-ul.svg +1 -0
- package/images/icons/outdent.svg +3 -0
- package/images/icons/pencil-fill.svg +1 -0
- package/images/icons/text-center.svg +1 -0
- package/images/icons/text-left.svg +1 -0
- package/images/icons/text-paragraph.svg +1 -0
- package/images/icons/text-right.svg +1 -0
- package/images/icons/type-bold.svg +1 -0
- package/images/icons/type-h1.svg +1 -0
- package/images/icons/type-h2.svg +1 -0
- package/images/icons/type-h3.svg +1 -0
- package/images/icons/type-h4.svg +1 -0
- package/images/icons/type-h5.svg +1 -0
- package/images/icons/type-h6.svg +1 -0
- package/images/icons/type-italic.svg +1 -0
- package/images/icons/type-strikethrough.svg +1 -0
- package/images/icons/type-underline.svg +1 -0
- package/images/icons/unlink_icon.svg +1 -0
- package/index.d.ts +42 -0
- package/index.js +295 -0
- package/index.js.map +1 -0
- package/nodes/FontColorNode.d.ts +43 -0
- package/nodes/FontColorNode.js +127 -0
- package/nodes/FontColorNode.js.map +1 -0
- package/nodes/HeadingNode.d.ts +34 -0
- package/nodes/HeadingNode.js +192 -0
- package/nodes/HeadingNode.js.map +1 -0
- package/nodes/ListItemNode.d.ts +46 -0
- package/nodes/ListItemNode.js +441 -0
- package/nodes/ListItemNode.js.map +1 -0
- package/nodes/ListNode/formatList.d.ts +12 -0
- package/nodes/ListNode/formatList.js +424 -0
- package/nodes/ListNode/formatList.js.map +1 -0
- package/nodes/ListNode.d.ts +42 -0
- package/nodes/ListNode.js +294 -0
- package/nodes/ListNode.js.map +1 -0
- package/nodes/ParagraphNode.d.ts +32 -0
- package/nodes/ParagraphNode.js +218 -0
- package/nodes/ParagraphNode.js.map +1 -0
- package/nodes/QuoteNode.d.ts +34 -0
- package/nodes/QuoteNode.js +225 -0
- package/nodes/QuoteNode.js.map +1 -0
- package/nodes/TypographyElementNode.d.ts +42 -0
- package/nodes/TypographyElementNode.js +155 -0
- package/nodes/TypographyElementNode.js.map +1 -0
- package/nodes/types.d.ts +15 -0
- package/nodes/types.js +5 -0
- package/nodes/types.js.map +1 -0
- package/nodes/webinyNodes.d.ts +7 -0
- package/nodes/webinyNodes.js +45 -0
- package/nodes/webinyNodes.js.map +1 -0
- package/package.json +41 -0
- package/plugins/AutoLinkPlugin/AutoLinkPlugin.d.ts +11 -0
- package/plugins/AutoLinkPlugin/AutoLinkPlugin.js +46 -0
- package/plugins/AutoLinkPlugin/AutoLinkPlugin.js.map +1 -0
- package/plugins/AutoLinkPlugin/index.d.ts +1 -0
- package/plugins/AutoLinkPlugin/index.js +16 -0
- package/plugins/AutoLinkPlugin/index.js.map +1 -0
- package/plugins/BlurEventPlugin/BlurEventPlugin.d.ts +7 -0
- package/plugins/BlurEventPlugin/BlurEventPlugin.js +28 -0
- package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -0
- package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.d.ts +17 -0
- package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.js +88 -0
- package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.js.map +1 -0
- package/plugins/ClickableLinkPlugin/index.d.ts +1 -0
- package/plugins/ClickableLinkPlugin/index.js +16 -0
- package/plugins/ClickableLinkPlugin/index.js.map +1 -0
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.d.ts +1 -0
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +20 -0
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -0
- package/plugins/CodeHighlightPlugin/index.d.ts +1 -0
- package/plugins/CodeHighlightPlugin/index.js +16 -0
- package/plugins/CodeHighlightPlugin/index.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +118 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +7 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +222 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/index.d.ts +1 -0
- package/plugins/FloatingLinkEditorPlugin/index.js +16 -0
- package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -0
- package/plugins/FontColorPlugin/FontColorPlugin.d.ts +2 -0
- package/plugins/FontColorPlugin/FontColorPlugin.js +39 -0
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -0
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.d.ts +8 -0
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js +34 -0
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js.map +1 -0
- package/plugins/LexicalUpdateStatePlugin/index.d.ts +1 -0
- package/plugins/LexicalUpdateStatePlugin/index.js +16 -0
- package/plugins/LexicalUpdateStatePlugin/index.js.map +1 -0
- package/plugins/TypographyPlugin/TypographyPlugin.d.ts +2 -0
- package/plugins/TypographyPlugin/TypographyPlugin.js +35 -0
- package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -0
- package/plugins/WebinyListPLugin/WebinyListPlugin.d.ts +1 -0
- package/plugins/WebinyListPLugin/WebinyListPlugin.js +25 -0
- package/plugins/WebinyListPLugin/WebinyListPlugin.js.map +1 -0
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.d.ts +1 -0
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js +24 -0
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js.map +1 -0
- package/themes/webinyLexicalTheme.css +429 -0
- package/themes/webinyLexicalTheme.d.ts +9 -0
- package/themes/webinyLexicalTheme.js +87 -0
- package/themes/webinyLexicalTheme.js.map +1 -0
- package/types.d.ts +63 -0
- package/types.js +25 -0
- package/types.js.map +1 -0
- package/ui/Divider.d.ts +2 -0
- package/ui/Divider.js +13 -0
- package/ui/Divider.js.map +1 -0
- package/ui/DropDown.d.ts +26 -0
- package/ui/DropDown.js +206 -0
- package/ui/DropDown.js.map +1 -0
- package/ui/Input.css +32 -0
- package/ui/LinkPreview.css +69 -0
- package/ui/LinkPreview.d.ts +12 -0
- package/ui/LinkPreview.js +101 -0
- package/ui/LinkPreview.js.map +1 -0
- package/ui/Placeholder.css +23 -0
- package/ui/Placeholder.d.ts +13 -0
- package/ui/Placeholder.js +24 -0
- package/ui/Placeholder.js.map +1 -0
- package/ui/TextInput.d.ts +18 -0
- package/ui/TextInput.js +39 -0
- package/ui/TextInput.js.map +1 -0
- package/ui/ToolbarActionDialog.d.ts +12 -0
- package/ui/ToolbarActionDialog.js +106 -0
- package/ui/ToolbarActionDialog.js.map +1 -0
- package/utils/findTypographyStyleByHtmlTag.d.ts +8 -0
- package/utils/findTypographyStyleByHtmlTag.js +16 -0
- package/utils/findTypographyStyleByHtmlTag.js.map +1 -0
- package/utils/generateInitialLexicalValue.d.ts +5 -0
- package/utils/generateInitialLexicalValue.js +30 -0
- package/utils/generateInitialLexicalValue.js.map +1 -0
- package/utils/getDOMRangeRect.d.ts +10 -0
- package/utils/getDOMRangeRect.js +27 -0
- package/utils/getDOMRangeRect.js.map +1 -0
- package/utils/getLexicalTextSelectionState.d.ts +5 -0
- package/utils/getLexicalTextSelectionState.js +163 -0
- package/utils/getLexicalTextSelectionState.js.map +1 -0
- package/utils/getSelectedNode.d.ts +2 -0
- package/utils/getSelectedNode.js +30 -0
- package/utils/getSelectedNode.js.map +1 -0
- package/utils/isValidJSON.d.ts +1 -0
- package/utils/isValidJSON.js +18 -0
- package/utils/isValidJSON.js.map +1 -0
- package/utils/isValidLexicalData.d.ts +2 -0
- package/utils/isValidLexicalData.js +24 -0
- package/utils/isValidLexicalData.js.map +1 -0
- package/utils/nodes/clearNodeFormating.d.ts +2 -0
- package/utils/nodes/clearNodeFormating.js +28 -0
- package/utils/nodes/clearNodeFormating.js.map +1 -0
- package/utils/nodes/formatToHeading.d.ts +3 -0
- package/utils/nodes/formatToHeading.js +25 -0
- package/utils/nodes/formatToHeading.js.map +1 -0
- package/utils/nodes/formatToParagraph.d.ts +2 -0
- package/utils/nodes/formatToParagraph.js +20 -0
- package/utils/nodes/formatToParagraph.js.map +1 -0
- package/utils/nodes/formatToQuote.d.ts +2 -0
- package/utils/nodes/formatToQuote.js +25 -0
- package/utils/nodes/formatToQuote.js.map +1 -0
- package/utils/nodes/listNode.d.ts +11 -0
- package/utils/nodes/listNode.js +107 -0
- package/utils/nodes/listNode.js.map +1 -0
- package/utils/point.d.ts +21 -0
- package/utils/point.js +77 -0
- package/utils/point.js.map +1 -0
- package/utils/rect.d.ts +47 -0
- package/utils/rect.js +169 -0
- package/utils/rect.js.map +1 -0
- package/utils/sanitizeUrl.d.ts +8 -0
- package/utils/sanitizeUrl.js +27 -0
- package/utils/sanitizeUrl.js.map +1 -0
- package/utils/setFloatingElemPosition.d.ts +3 -0
- package/utils/setFloatingElemPosition.js +40 -0
- package/utils/setFloatingElemPosition.js.map +1 -0
- package/utils/styleObjectToString.d.ts +2 -0
- package/utils/styleObjectToString.js +22 -0
- package/utils/styleObjectToString.js.map +1 -0
- package/utils/toTypographyEmotionMap.d.ts +3 -0
- package/utils/toTypographyEmotionMap.js +36 -0
- package/utils/toTypographyEmotionMap.js.map +1 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ToolbarActionDialog = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
function MenuContainer(_ref) {
|
|
12
|
+
var children = _ref.children,
|
|
13
|
+
menuContainerRef = _ref.menuContainerRef,
|
|
14
|
+
onClose = _ref.onClose;
|
|
15
|
+
var handleKeyDown = function handleKeyDown(event) {
|
|
16
|
+
var key = event.key;
|
|
17
|
+
if (["Escape", "ArrowUp", "ArrowDown", "Tab"].includes(key)) {
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
}
|
|
20
|
+
if (key === "Escape" || key === "Tab") {
|
|
21
|
+
onClose();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var handleContainerClick = function handleContainerClick(e) {
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
console.log("click", e);
|
|
27
|
+
};
|
|
28
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
29
|
+
style: {
|
|
30
|
+
position: "relative"
|
|
31
|
+
}
|
|
32
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
33
|
+
onClick: function onClick(e) {
|
|
34
|
+
return handleContainerClick(e);
|
|
35
|
+
},
|
|
36
|
+
style: {
|
|
37
|
+
position: "absolute",
|
|
38
|
+
top: -10,
|
|
39
|
+
left: 0,
|
|
40
|
+
width: 240,
|
|
41
|
+
backgroundColor: "#fff"
|
|
42
|
+
},
|
|
43
|
+
ref: menuContainerRef !== null && menuContainerRef !== void 0 ? menuContainerRef : null,
|
|
44
|
+
onKeyDown: handleKeyDown
|
|
45
|
+
}, children));
|
|
46
|
+
}
|
|
47
|
+
var ToolbarActionDialog = function ToolbarActionDialog(_ref2) {
|
|
48
|
+
var disabled = _ref2.disabled,
|
|
49
|
+
buttonAriaLabel = _ref2.buttonAriaLabel,
|
|
50
|
+
buttonClassName = _ref2.buttonClassName,
|
|
51
|
+
buttonIconClassName = _ref2.buttonIconClassName,
|
|
52
|
+
buttonLabel = _ref2.buttonLabel,
|
|
53
|
+
children = _ref2.children,
|
|
54
|
+
stopCloseOnClickSelf = _ref2.stopCloseOnClickSelf;
|
|
55
|
+
var menuWindowRef = (0, React.useRef)(null);
|
|
56
|
+
var _useState = (0, React.useState)(false),
|
|
57
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
58
|
+
showDropDown = _useState2[0],
|
|
59
|
+
setShowDropDown = _useState2[1];
|
|
60
|
+
var handleClose = function handleClose() {
|
|
61
|
+
if (menuWindowRef && menuWindowRef.current) {
|
|
62
|
+
setShowDropDown(false);
|
|
63
|
+
menuWindowRef.current.focus();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
(0, React.useEffect)(function () {
|
|
67
|
+
if (!showDropDown) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
var handle = function handle(event) {
|
|
71
|
+
/* const target = event.target;
|
|
72
|
+
if (!button.contains(target as Node)) {
|
|
73
|
+
setShowDropDown(false);
|
|
74
|
+
}*/
|
|
75
|
+
console.log("handle", event);
|
|
76
|
+
};
|
|
77
|
+
document.addEventListener("click", handle);
|
|
78
|
+
return function () {
|
|
79
|
+
document.removeEventListener("click", handle);
|
|
80
|
+
};
|
|
81
|
+
}, [showDropDown, stopCloseOnClickSelf]);
|
|
82
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
83
|
+
style: {
|
|
84
|
+
position: "relative"
|
|
85
|
+
}
|
|
86
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
87
|
+
style: {
|
|
88
|
+
position: "relative"
|
|
89
|
+
},
|
|
90
|
+
disabled: disabled,
|
|
91
|
+
"aria-label": buttonAriaLabel || buttonLabel,
|
|
92
|
+
className: buttonClassName,
|
|
93
|
+
onClick: function onClick() {
|
|
94
|
+
setShowDropDown(!showDropDown);
|
|
95
|
+
}
|
|
96
|
+
}, buttonIconClassName && /*#__PURE__*/React.createElement("span", {
|
|
97
|
+
className: buttonIconClassName
|
|
98
|
+
}), buttonLabel && /*#__PURE__*/React.createElement("span", {
|
|
99
|
+
className: "text dropdown-button-text"
|
|
100
|
+
}, buttonLabel), /*#__PURE__*/React.createElement("i", {
|
|
101
|
+
className: "chevron-down"
|
|
102
|
+
})), showDropDown && /*#__PURE__*/React.createElement(MenuContainer, {
|
|
103
|
+
onClose: handleClose
|
|
104
|
+
}, children));
|
|
105
|
+
};
|
|
106
|
+
exports.ToolbarActionDialog = ToolbarActionDialog;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["MenuContainer","children","menuContainerRef","onClose","handleKeyDown","event","key","includes","preventDefault","handleContainerClick","e","console","log","position","top","left","width","backgroundColor","ToolbarActionDialog","disabled","buttonAriaLabel","buttonClassName","buttonIconClassName","buttonLabel","stopCloseOnClickSelf","menuWindowRef","useRef","useState","showDropDown","setShowDropDown","handleClose","current","focus","useEffect","handle","document","addEventListener","removeEventListener"],"sources":["ToolbarActionDialog.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport * as React from \"react\";\n\nfunction MenuContainer({\n children,\n menuContainerRef,\n onClose\n}: {\n children: React.ReactNode | React.ReactNode[];\n menuContainerRef?: React.Ref<HTMLDivElement>;\n onClose: () => void;\n}) {\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n const key = event.key;\n\n if ([\"Escape\", \"ArrowUp\", \"ArrowDown\", \"Tab\"].includes(key)) {\n event.preventDefault();\n }\n\n if (key === \"Escape\" || key === \"Tab\") {\n onClose();\n }\n };\n\n const handleContainerClick = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n e.preventDefault();\n console.log(\"click\", e);\n };\n\n return (\n <div style={{ position: \"relative\" }}>\n <div\n onClick={e => handleContainerClick(e)}\n style={{\n position: \"absolute\",\n top: -10,\n left: 0,\n width: 240,\n backgroundColor: \"#fff\"\n }}\n ref={menuContainerRef ?? null}\n onKeyDown={handleKeyDown}\n >\n {children}\n </div>\n </div>\n );\n}\ninterface ToolbarActionDialogProps {\n disabled: boolean;\n buttonLabel?: string;\n buttonAriaLabel: string;\n buttonClassName: string;\n buttonIconClassName: string;\n children: React.ReactNode | React.ReactNode[];\n stopCloseOnClickSelf?: boolean;\n}\n\nexport const ToolbarActionDialog: React.FC<ToolbarActionDialogProps> = ({\n disabled,\n buttonAriaLabel,\n buttonClassName,\n buttonIconClassName,\n buttonLabel,\n children,\n stopCloseOnClickSelf\n}): JSX.Element => {\n const menuWindowRef = useRef<HTMLDivElement>(null);\n const [showDropDown, setShowDropDown] = useState(false);\n\n const handleClose = () => {\n if (menuWindowRef && menuWindowRef.current) {\n setShowDropDown(false);\n menuWindowRef.current.focus();\n }\n };\n\n useEffect(() => {\n if (!showDropDown) {\n return;\n }\n\n const handle = (event: MouseEvent) => {\n /* const target = event.target;\n if (!button.contains(target as Node)) {\n setShowDropDown(false);\n }*/\n console.log(\"handle\", event);\n };\n document.addEventListener(\"click\", handle);\n\n return () => {\n document.removeEventListener(\"click\", handle);\n };\n }, [showDropDown, stopCloseOnClickSelf]);\n\n return (\n <div style={{ position: \"relative\" }}>\n <button\n style={{ position: \"relative\" }}\n disabled={disabled}\n aria-label={buttonAriaLabel || buttonLabel}\n className={buttonClassName}\n onClick={() => {\n setShowDropDown(!showDropDown);\n }}\n >\n {buttonIconClassName && <span className={buttonIconClassName} />}\n {buttonLabel && <span className=\"text dropdown-button-text\">{buttonLabel}</span>}\n <i className=\"chevron-down\" />\n </button>\n {showDropDown && <MenuContainer onClose={handleClose}>{children}</MenuContainer>}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AAGA,SAASA,aAAa,OAQnB;EAAA,IAPCC,QAAQ,QAARA,QAAQ;IACRC,gBAAgB,QAAhBA,gBAAgB;IAChBC,OAAO,QAAP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;EAAY,GAAE7B,QAAQ,CAAiB,CAC9E;AAEd,CAAC;AAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ThemeEmotionMap } from "../types";
|
|
2
|
+
export declare const findTypographyStyleByHtmlTag: (htmlTag: string, themeEmotionMap: ThemeEmotionMap) => {
|
|
3
|
+
id: string;
|
|
4
|
+
tag: import("../types").TypographyHTMLTag;
|
|
5
|
+
name: string;
|
|
6
|
+
styles: Record<string, any>;
|
|
7
|
+
className: string;
|
|
8
|
+
} | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findTypographyStyleByHtmlTag = void 0;
|
|
7
|
+
var findTypographyStyleByHtmlTag = function findTypographyStyleByHtmlTag(htmlTag, themeEmotionMap) {
|
|
8
|
+
for (var styleId in themeEmotionMap) {
|
|
9
|
+
var style = themeEmotionMap[styleId];
|
|
10
|
+
if (style.tag === htmlTag) {
|
|
11
|
+
return style;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
};
|
|
16
|
+
exports.findTypographyStyleByHtmlTag = findTypographyStyleByHtmlTag;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["findTypographyStyleByHtmlTag","htmlTag","themeEmotionMap","styleId","style","tag","undefined"],"sources":["findTypographyStyleByHtmlTag.ts"],"sourcesContent":["import { ThemeEmotionMap } from \"~/types\";\n\nexport const findTypographyStyleByHtmlTag = (htmlTag: string, themeEmotionMap: ThemeEmotionMap) => {\n for (const styleId in themeEmotionMap) {\n const style = themeEmotionMap[styleId];\n if (style.tag === htmlTag) {\n return style;\n }\n }\n return undefined;\n};\n"],"mappings":";;;;;;AAEO,IAAMA,4BAA4B,GAAG,SAA/BA,4BAA4B,CAAIC,OAAe,EAAEC,eAAgC,EAAK;EAC/F,KAAK,IAAMC,OAAO,IAAID,eAAe,EAAE;IACnC,IAAME,KAAK,GAAGF,eAAe,CAACC,OAAO,CAAC;IACtC,IAAIC,KAAK,CAACC,GAAG,KAAKJ,OAAO,EAAE;MACvB,OAAOG,KAAK;IAChB;EACJ;EACA,OAAOE,SAAS;AACpB,CAAC;AAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateInitialLexicalValue = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @description Basic JSON data string that will initialize the editor.
|
|
9
|
+
*/
|
|
10
|
+
var generateInitialLexicalValue = function generateInitialLexicalValue() {
|
|
11
|
+
return JSON.stringify({
|
|
12
|
+
root: {
|
|
13
|
+
children: [{
|
|
14
|
+
children: [],
|
|
15
|
+
direction: null,
|
|
16
|
+
format: "",
|
|
17
|
+
indent: 0,
|
|
18
|
+
styles: [],
|
|
19
|
+
type: "paragraph-element",
|
|
20
|
+
version: 1
|
|
21
|
+
}],
|
|
22
|
+
direction: null,
|
|
23
|
+
format: "",
|
|
24
|
+
indent: 0,
|
|
25
|
+
type: "root",
|
|
26
|
+
version: 1
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
exports.generateInitialLexicalValue = generateInitialLexicalValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["generateInitialLexicalValue","JSON","stringify","root","children","direction","format","indent","styles","type","version"],"sources":["generateInitialLexicalValue.ts"],"sourcesContent":["import { LexicalValue } from \"~/types\";\n\n/**\n * @description Basic JSON data string that will initialize the editor.\n */\nexport const generateInitialLexicalValue = (): LexicalValue => {\n return JSON.stringify({\n root: {\n children: [\n {\n children: [],\n direction: null,\n format: \"\",\n indent: 0,\n styles: [],\n type: \"paragraph-element\",\n version: 1\n }\n ],\n direction: null,\n format: \"\",\n indent: 0,\n type: \"root\",\n version: 1\n }\n });\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACO,IAAMA,2BAA2B,GAAG,SAA9BA,2BAA2B,GAAuB;EAC3D,OAAOC,IAAI,CAACC,SAAS,CAAC;IAClBC,IAAI,EAAE;MACFC,QAAQ,EAAE,CACN;QACIA,QAAQ,EAAE,EAAE;QACZC,SAAS,EAAE,IAAI;QACfC,MAAM,EAAE,EAAE;QACVC,MAAM,EAAE,CAAC;QACTC,MAAM,EAAE,EAAE;QACVC,IAAI,EAAE,mBAAmB;QACzBC,OAAO,EAAE;MACb,CAAC,CACJ;MACDL,SAAS,EAAE,IAAI;MACfC,MAAM,EAAE,EAAE;MACVC,MAAM,EAAE,CAAC;MACTE,IAAI,EAAE,MAAM;MACZC,OAAO,EAAE;IACb;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="web" />
|
|
2
|
+
/// <reference types="react" />
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export declare function getDOMRangeRect(nativeSelection: Selection, rootElement: HTMLElement): DOMRect;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDOMRangeRect = getDOMRangeRect;
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
function getDOMRangeRect(nativeSelection, rootElement) {
|
|
15
|
+
var domRange = nativeSelection.getRangeAt(0);
|
|
16
|
+
var rect;
|
|
17
|
+
if (nativeSelection.anchorNode === rootElement) {
|
|
18
|
+
var inner = rootElement;
|
|
19
|
+
while (inner.firstElementChild != null) {
|
|
20
|
+
inner = inner.firstElementChild;
|
|
21
|
+
}
|
|
22
|
+
rect = inner.getBoundingClientRect();
|
|
23
|
+
} else {
|
|
24
|
+
rect = domRange.getBoundingClientRect();
|
|
25
|
+
}
|
|
26
|
+
return rect;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getDOMRangeRect","nativeSelection","rootElement","domRange","getRangeAt","rect","anchorNode","inner","firstElementChild","getBoundingClientRect"],"sources":["getDOMRangeRect.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nexport function getDOMRangeRect(nativeSelection: Selection, rootElement: HTMLElement): DOMRect {\n const domRange = nativeSelection.getRangeAt(0);\n\n let rect;\n\n if (nativeSelection.anchorNode === rootElement) {\n let inner = rootElement;\n while (inner.firstElementChild != null) {\n inner = inner.firstElementChild as HTMLElement;\n }\n rect = inner.getBoundingClientRect();\n } else {\n rect = domRange.getBoundingClientRect();\n }\n\n return rect;\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAe,CAACC,eAA0B,EAAEC,WAAwB,EAAW;EAC3F,IAAMC,QAAQ,GAAGF,eAAe,CAACG,UAAU,CAAC,CAAC,CAAC;EAE9C,IAAIC,IAAI;EAER,IAAIJ,eAAe,CAACK,UAAU,KAAKJ,WAAW,EAAE;IAC5C,IAAIK,KAAK,GAAGL,WAAW;IACvB,OAAOK,KAAK,CAACC,iBAAiB,IAAI,IAAI,EAAE;MACpCD,KAAK,GAAGA,KAAK,CAACC,iBAAgC;IAClD;IACAH,IAAI,GAAGE,KAAK,CAACE,qBAAqB,EAAE;EACxC,CAAC,MAAM;IACHJ,IAAI,GAAGF,QAAQ,CAACM,qBAAqB,EAAE;EAC3C;EAEA,OAAOJ,IAAI;AACf"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TextFormatting, TextBlockSelection, ToolbarState } from "../types";
|
|
2
|
+
import { ElementNode, LexicalEditor, LexicalNode, RangeSelection, TextNode } from "lexical";
|
|
3
|
+
export declare const getSelectionTextFormat: (selection: RangeSelection | undefined) => TextFormatting;
|
|
4
|
+
export declare const getToolbarState: (selection: RangeSelection, node: LexicalNode, parent: LexicalNode | null, element: LexicalNode | null, anchorNode: ElementNode | TextNode) => ToolbarState;
|
|
5
|
+
export declare const getLexicalTextSelectionState: (activeEditor: LexicalEditor, selection: RangeSelection) => TextBlockSelection | null;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getToolbarState = exports.getSelectionTextFormat = exports.getLexicalTextSelectionState = void 0;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _lexical = require("lexical");
|
|
10
|
+
var _utils = require("@lexical/utils");
|
|
11
|
+
var _getSelectedNode = require("./getSelectedNode");
|
|
12
|
+
var _link = require("@lexical/link");
|
|
13
|
+
var _ListNode = require("../nodes/ListNode");
|
|
14
|
+
var _richText = require("@lexical/rich-text");
|
|
15
|
+
var _TypographyElementNode = require("../nodes/TypographyElementNode");
|
|
16
|
+
var _FontColorNode = require("../nodes/FontColorNode");
|
|
17
|
+
var _ParagraphNode = require("../nodes/ParagraphNode");
|
|
18
|
+
var _HeadingNode = require("../nodes/HeadingNode");
|
|
19
|
+
var _QuoteNode = require("../nodes/QuoteNode");
|
|
20
|
+
var _selection = require("@lexical/selection");
|
|
21
|
+
var getSelectionTextFormat = function getSelectionTextFormat(selection) {
|
|
22
|
+
return !(0, _lexical.$isRangeSelection)(selection) ? {
|
|
23
|
+
italic: false,
|
|
24
|
+
bold: false,
|
|
25
|
+
underline: false,
|
|
26
|
+
code: false
|
|
27
|
+
} : {
|
|
28
|
+
bold: selection.hasFormat("bold"),
|
|
29
|
+
italic: selection.hasFormat("italic"),
|
|
30
|
+
underline: selection.hasFormat("underline"),
|
|
31
|
+
code: selection.hasFormat("code")
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.getSelectionTextFormat = getSelectionTextFormat;
|
|
35
|
+
var getDefaultToolbarState = function getDefaultToolbarState() {
|
|
36
|
+
return {
|
|
37
|
+
bold: false,
|
|
38
|
+
italic: false,
|
|
39
|
+
underline: false,
|
|
40
|
+
code: false,
|
|
41
|
+
isRTL: false,
|
|
42
|
+
link: {
|
|
43
|
+
isSelected: false
|
|
44
|
+
},
|
|
45
|
+
list: {
|
|
46
|
+
isSelected: false
|
|
47
|
+
},
|
|
48
|
+
typography: {
|
|
49
|
+
isSelected: false
|
|
50
|
+
},
|
|
51
|
+
fontColor: {
|
|
52
|
+
isSelected: false
|
|
53
|
+
},
|
|
54
|
+
quote: {
|
|
55
|
+
isSelected: false
|
|
56
|
+
},
|
|
57
|
+
paragraph: {
|
|
58
|
+
isSelected: false
|
|
59
|
+
},
|
|
60
|
+
heading: {
|
|
61
|
+
isSelected: false
|
|
62
|
+
},
|
|
63
|
+
textType: undefined
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
var getToolbarState = function getToolbarState(selection, node, parent, element, anchorNode) {
|
|
67
|
+
var textFormat = getSelectionTextFormat(selection);
|
|
68
|
+
var state = getDefaultToolbarState();
|
|
69
|
+
state = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, state), {}, {
|
|
70
|
+
bold: textFormat.bold,
|
|
71
|
+
italic: textFormat.italic,
|
|
72
|
+
underline: textFormat.underline,
|
|
73
|
+
code: textFormat.code
|
|
74
|
+
});
|
|
75
|
+
state.isRTL = (0, _selection.$isParentElementRTL)(selection);
|
|
76
|
+
|
|
77
|
+
// link
|
|
78
|
+
state.link.isSelected = (0, _link.$isLinkNode)(parent) || (0, _link.$isLinkNode)(node);
|
|
79
|
+
if (state.link.isSelected) {
|
|
80
|
+
state.textType = "link";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// font color
|
|
84
|
+
if ((0, _FontColorNode.$isFontColorNode)(node)) {
|
|
85
|
+
state.fontColor.isSelected = true;
|
|
86
|
+
}
|
|
87
|
+
if ((0, _ListNode.$isListNode)(element)) {
|
|
88
|
+
var parentList = (0, _utils.$getNearestNodeOfType)(anchorNode, _ListNode.ListNode);
|
|
89
|
+
var type = parentList ? parentList.getListType() : element.getListType();
|
|
90
|
+
state.textType = type;
|
|
91
|
+
}
|
|
92
|
+
if ((0, _richText.$isHeadingNode)(element)) {
|
|
93
|
+
state.textType = "heading";
|
|
94
|
+
}
|
|
95
|
+
if ((0, _HeadingNode.$isHeadingNode)(element)) {
|
|
96
|
+
state.textType = "heading";
|
|
97
|
+
state.heading.isSelected = true;
|
|
98
|
+
}
|
|
99
|
+
if ((0, _lexical.$isParagraphNode)(element)) {
|
|
100
|
+
state.textType = "paragraph";
|
|
101
|
+
}
|
|
102
|
+
if ((0, _ParagraphNode.$isParagraphNode)(element)) {
|
|
103
|
+
state.textType = "paragraph";
|
|
104
|
+
state.paragraph.isSelected = true;
|
|
105
|
+
}
|
|
106
|
+
if ((0, _TypographyElementNode.$isTypographyElementNode)(element)) {
|
|
107
|
+
state.typography.isSelected = true;
|
|
108
|
+
var value = element === null || element === void 0 ? void 0 : element.getTypographyValue();
|
|
109
|
+
if (value.tag.includes("h")) {
|
|
110
|
+
state.textType = "heading";
|
|
111
|
+
}
|
|
112
|
+
if (value.tag.includes("p")) {
|
|
113
|
+
state.textType = "paragraph";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if ((0, _TypographyElementNode.$isTypographyElementNode)(element)) {
|
|
117
|
+
state.fontColor.isSelected = true;
|
|
118
|
+
}
|
|
119
|
+
if ((0, _QuoteNode.$isQuoteNode)(element)) {
|
|
120
|
+
state.textType = "quoteblock";
|
|
121
|
+
state.quote.isSelected = true;
|
|
122
|
+
}
|
|
123
|
+
return state;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/*
|
|
127
|
+
* @desc Get selection data and provide processed toolbar state and data about the text, element and parent nodes.
|
|
128
|
+
*/
|
|
129
|
+
exports.getToolbarState = getToolbarState;
|
|
130
|
+
var getLexicalTextSelectionState = function getLexicalTextSelectionState(activeEditor, selection) {
|
|
131
|
+
if ((0, _lexical.$isRangeSelection)(selection)) {
|
|
132
|
+
var anchorNode = selection.anchor.getNode();
|
|
133
|
+
var element = anchorNode.getKey() === "root" ? anchorNode : (0, _utils.$findMatchingParent)(anchorNode, function (e) {
|
|
134
|
+
var parent = e.getParent();
|
|
135
|
+
return parent !== null && (0, _lexical.$isRootOrShadowRoot)(parent);
|
|
136
|
+
});
|
|
137
|
+
if (element === null) {
|
|
138
|
+
element = anchorNode.getTopLevelElementOrThrow();
|
|
139
|
+
}
|
|
140
|
+
var elementKey = element.getKey();
|
|
141
|
+
var elementDOM = activeEditor.getElementByKey(elementKey);
|
|
142
|
+
|
|
143
|
+
// Update links
|
|
144
|
+
var node = (0, _getSelectedNode.getSelectedNode)(selection);
|
|
145
|
+
var parent = node.getParent();
|
|
146
|
+
var isElementDom = elementDOM !== null;
|
|
147
|
+
var selectedText = selection.getTextContent();
|
|
148
|
+
return {
|
|
149
|
+
// node/element data from selection
|
|
150
|
+
elementKey: elementKey,
|
|
151
|
+
element: element,
|
|
152
|
+
parent: parent,
|
|
153
|
+
node: node,
|
|
154
|
+
anchorNode: anchorNode,
|
|
155
|
+
selection: selection,
|
|
156
|
+
isElementDom: isElementDom,
|
|
157
|
+
selectedText: selectedText,
|
|
158
|
+
state: getToolbarState(selection, node, parent, element, anchorNode)
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
};
|
|
163
|
+
exports.getLexicalTextSelectionState = getLexicalTextSelectionState;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getSelectionTextFormat","selection","$isRangeSelection","italic","bold","underline","code","hasFormat","getDefaultToolbarState","isRTL","link","isSelected","list","typography","fontColor","quote","paragraph","heading","textType","undefined","getToolbarState","node","parent","element","anchorNode","textFormat","state","$isParentElementRTL","$isLinkNode","$isFontColorNode","$isListNode","parentList","$getNearestNodeOfType","ListNode","type","getListType","$isBaseHeadingNode","$isHeadingNode","$isBaseParagraphNode","$isParagraphNode","$isTypographyElementNode","value","getTypographyValue","tag","includes","$isQuoteNode","getLexicalTextSelectionState","activeEditor","anchor","getNode","getKey","$findMatchingParent","e","getParent","$isRootOrShadowRoot","getTopLevelElementOrThrow","elementKey","elementDOM","getElementByKey","getSelectedNode","isElementDom","selectedText","getTextContent"],"sources":["getLexicalTextSelectionState.ts"],"sourcesContent":["import { TextFormatting, TextBlockSelection, ToolbarState, TypographyValue } from \"~/types\";\nimport {\n $isParagraphNode as $isBaseParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n ElementNode,\n LexicalEditor,\n LexicalNode,\n RangeSelection,\n TextNode\n} from \"lexical\";\nimport { $findMatchingParent, $getNearestNodeOfType } from \"@lexical/utils\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { $isLinkNode } from \"@lexical/link\";\nimport { $isListNode, ListNode } from \"~/nodes/ListNode\";\nimport { $isHeadingNode as $isBaseHeadingNode } from \"@lexical/rich-text\";\nimport { $isTypographyElementNode } from \"~/nodes/TypographyElementNode\";\nimport { $isFontColorNode } from \"~/nodes/FontColorNode\";\nimport { $isParagraphNode } from \"~/nodes/ParagraphNode\";\nimport { $isHeadingNode } from \"~/nodes/HeadingNode\";\nimport { $isQuoteNode } from \"~/nodes/QuoteNode\";\nimport { $isParentElementRTL } from \"@lexical/selection\";\n\nexport const getSelectionTextFormat = (selection: RangeSelection | undefined): TextFormatting => {\n return !$isRangeSelection(selection)\n ? {\n italic: false,\n bold: false,\n underline: false,\n code: false\n }\n : {\n bold: selection.hasFormat(\"bold\"),\n italic: selection.hasFormat(\"italic\"),\n underline: selection.hasFormat(\"underline\"),\n code: selection.hasFormat(\"code\")\n };\n};\n\nconst getDefaultToolbarState = (): ToolbarState => {\n return {\n bold: false,\n italic: false,\n underline: false,\n code: false,\n isRTL: false,\n link: { isSelected: false },\n list: { isSelected: false },\n typography: { isSelected: false },\n fontColor: { isSelected: false },\n quote: { isSelected: false },\n paragraph: { isSelected: false },\n heading: { isSelected: false },\n textType: undefined\n };\n};\n\nexport const getToolbarState = (\n selection: RangeSelection,\n node: LexicalNode,\n parent: LexicalNode | null,\n element: LexicalNode | null,\n anchorNode: ElementNode | TextNode\n): ToolbarState => {\n const textFormat = getSelectionTextFormat(selection);\n let state: ToolbarState = getDefaultToolbarState();\n state = {\n ...state,\n bold: textFormat.bold,\n italic: textFormat.italic,\n underline: textFormat.underline,\n code: textFormat.code\n };\n\n state.isRTL = $isParentElementRTL(selection);\n\n // link\n state.link.isSelected = $isLinkNode(parent) || $isLinkNode(node);\n if (state.link.isSelected) {\n state.textType = \"link\";\n }\n\n // font color\n if ($isFontColorNode(node)) {\n state.fontColor.isSelected = true;\n }\n\n if ($isListNode(element)) {\n const parentList = $getNearestNodeOfType<ListNode>(anchorNode, ListNode);\n const type = parentList ? parentList.getListType() : element.getListType();\n state.textType = type;\n }\n\n if ($isBaseHeadingNode(element)) {\n state.textType = \"heading\";\n }\n\n if ($isHeadingNode(element)) {\n state.textType = \"heading\";\n state.heading.isSelected = true;\n }\n\n if ($isBaseParagraphNode(element)) {\n state.textType = \"paragraph\";\n }\n\n if ($isParagraphNode(element)) {\n state.textType = \"paragraph\";\n state.paragraph.isSelected = true;\n }\n\n if ($isTypographyElementNode(element)) {\n state.typography.isSelected = true;\n const value = element?.getTypographyValue() as TypographyValue;\n if (value.tag.includes(\"h\")) {\n state.textType = \"heading\";\n }\n if (value.tag.includes(\"p\")) {\n state.textType = \"paragraph\";\n }\n }\n\n if ($isTypographyElementNode(element)) {\n state.fontColor.isSelected = true;\n }\n\n if ($isQuoteNode(element)) {\n state.textType = \"quoteblock\";\n state.quote.isSelected = true;\n }\n\n return state;\n};\n\n/*\n * @desc Get selection data and provide processed toolbar state and data about the text, element and parent nodes.\n */\nexport const getLexicalTextSelectionState = (\n activeEditor: LexicalEditor,\n selection: RangeSelection\n): TextBlockSelection | null => {\n if ($isRangeSelection(selection)) {\n const anchorNode = selection.anchor.getNode();\n let element =\n anchorNode.getKey() === \"root\"\n ? anchorNode\n : $findMatchingParent(anchorNode, e => {\n const parent = e.getParent();\n return parent !== null && $isRootOrShadowRoot(parent);\n });\n\n if (element === null) {\n element = anchorNode.getTopLevelElementOrThrow();\n }\n\n const elementKey = element.getKey();\n const elementDOM = activeEditor.getElementByKey(elementKey);\n\n // Update links\n const node = getSelectedNode(selection);\n const parent = node.getParent();\n const isElementDom = elementDOM !== null;\n const selectedText = selection.getTextContent();\n\n return {\n // node/element data from selection\n elementKey,\n element,\n parent,\n node,\n anchorNode,\n selection,\n isElementDom,\n selectedText,\n state: getToolbarState(selection, node, parent, element, anchorNode)\n };\n }\n return null;\n};\n"],"mappings":";;;;;;;;AACA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAsB,CAAIC,SAAqC,EAAqB;EAC7F,OAAO,CAAC,IAAAC,0BAAiB,EAACD,SAAS,CAAC,GAC9B;IACIE,MAAM,EAAE,KAAK;IACbC,IAAI,EAAE,KAAK;IACXC,SAAS,EAAE,KAAK;IAChBC,IAAI,EAAE;EACV,CAAC,GACD;IACIF,IAAI,EAAEH,SAAS,CAACM,SAAS,CAAC,MAAM,CAAC;IACjCJ,MAAM,EAAEF,SAAS,CAACM,SAAS,CAAC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CAAC2B,MAAM,EAAE;IACnC,IAAMO,UAAU,GAAGV,YAAY,CAACW,eAAe,CAACF,UAAU,CAAC;;IAE3D;IACA,IAAMnC,IAAI,GAAG,IAAAsC,gCAAe,EAAC1D,SAAS,CAAC;IACvC,IAAMqB,MAAM,GAAGD,IAAI,CAACgC,SAAS,EAAE;IAC/B,IAAMO,YAAY,GAAGH,UAAU,KAAK,IAAI;IACxC,IAAMI,YAAY,GAAG5D,SAAS,CAAC6D,cAAc,EAAE;IAE/C,OAAO;MACH;MACAN,UAAU,EAAVA,UAAU;MACVjC,OAAO,EAAPA,OAAO;MACPD,MAAM,EAANA,MAAM;MACND,IAAI,EAAJA,IAAI;MACJG,UAAU,EAAVA,UAAU;MACVvB,SAAS,EAATA,SAAS;MACT2D,YAAY,EAAZA,YAAY;MACZC,YAAY,EAAZA,YAAY;MACZnC,KAAK,EAAEN,eAAe,CAACnB,SAAS,EAAEoB,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAEC,UAAU;IACvE,CAAC;EACL;EACA,OAAO,IAAI;AACf,CAAC;AAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSelectedNode = getSelectedNode;
|
|
7
|
+
var _selection = require("@lexical/selection");
|
|
8
|
+
/**
|
|
9
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10
|
+
*
|
|
11
|
+
* This source code is licensed under the MIT license found in the
|
|
12
|
+
* LICENSE file in the root directory of this source tree.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function getSelectedNode(selection) {
|
|
17
|
+
var anchor = selection.anchor;
|
|
18
|
+
var focus = selection.focus;
|
|
19
|
+
var anchorNode = selection.anchor.getNode();
|
|
20
|
+
var focusNode = selection.focus.getNode();
|
|
21
|
+
if (anchorNode === focusNode) {
|
|
22
|
+
return anchorNode;
|
|
23
|
+
}
|
|
24
|
+
var isBackward = selection.isBackward();
|
|
25
|
+
if (isBackward) {
|
|
26
|
+
return (0, _selection.$isAtNodeEnd)(focus) ? anchorNode : focusNode;
|
|
27
|
+
} else {
|
|
28
|
+
return (0, _selection.$isAtNodeEnd)(anchor) ? focusNode : anchorNode;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getSelectedNode","selection","anchor","focus","anchorNode","getNode","focusNode","isBackward","$isAtNodeEnd"],"sources":["getSelectedNode.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport { $isAtNodeEnd } from \"@lexical/selection\";\nimport { ElementNode, RangeSelection, TextNode } from \"lexical\";\n\nexport function getSelectedNode(selection: RangeSelection): TextNode | ElementNode {\n const anchor = selection.anchor;\n const focus = selection.focus;\n const anchorNode = selection.anchor.getNode();\n const focusNode = selection.focus.getNode();\n if (anchorNode === focusNode) {\n return anchorNode;\n }\n const isBackward = selection.isBackward();\n if (isBackward) {\n return $isAtNodeEnd(focus) ? anchorNode : focusNode;\n } else {\n return $isAtNodeEnd(anchor) ? focusNode : anchorNode;\n }\n}\n"],"mappings":";;;;;;AAOA;AAPA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIO,SAASA,eAAe,CAACC,SAAyB,EAA0B;EAC/E,IAAMC,MAAM,GAAGD,SAAS,CAACC,MAAM;EAC/B,IAAMC,KAAK,GAAGF,SAAS,CAACE,KAAK;EAC7B,IAAMC,UAAU,GAAGH,SAAS,CAACC,MAAM,CAACG,OAAO,EAAE;EAC7C,IAAMC,SAAS,GAAGL,SAAS,CAACE,KAAK,CAACE,OAAO,EAAE;EAC3C,IAAID,UAAU,KAAKE,SAAS,EAAE;IAC1B,OAAOF,UAAU;EACrB;EACA,IAAMG,UAAU,GAAGN,SAAS,CAACM,UAAU,EAAE;EACzC,IAAIA,UAAU,EAAE;IACZ,OAAO,IAAAC,uBAAY,EAACL,KAAK,CAAC,GAAGC,UAAU,GAAGE,SAAS;EACvD,CAAC,MAAM;IACH,OAAO,IAAAE,uBAAY,EAACN,MAAM,CAAC,GAAGI,SAAS,GAAGF,UAAU;EACxD;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isValidJSON: (value: string | undefined | null) => boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isValidJSON = void 0;
|
|
7
|
+
var isValidJSON = function isValidJSON(value) {
|
|
8
|
+
if (!value) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
var o = JSON.parse(value);
|
|
13
|
+
return !!o && typeof o === "object" && !Array.isArray(o);
|
|
14
|
+
} catch (_unused) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.isValidJSON = isValidJSON;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isValidJSON","value","o","JSON","parse","Array","isArray"],"sources":["isValidJSON.ts"],"sourcesContent":["export const isValidJSON = (value: string | undefined | null): boolean => {\n if (!value) {\n return false;\n }\n try {\n const o = JSON.parse(value);\n return !!o && typeof o === \"object\" && !Array.isArray(o);\n } catch {\n return false;\n }\n};\n"],"mappings":";;;;;;AAAO,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,KAAgC,EAAc;EACtE,IAAI,CAACA,KAAK,EAAE;IACR,OAAO,KAAK;EAChB;EACA,IAAI;IACA,IAAMC,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACH,KAAK,CAAC;IAC3B,OAAO,CAAC,CAACC,CAAC,IAAI,OAAOA,CAAC,KAAK,QAAQ,IAAI,CAACG,KAAK,CAACC,OAAO,CAACJ,CAAC,CAAC;EAC5D,CAAC,CAAC,gBAAM;IACJ,OAAO,KAAK;EAChB;AACJ,CAAC;AAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isValidLexicalData = void 0;
|
|
7
|
+
var _isValidJSON = require("./isValidJSON");
|
|
8
|
+
/*
|
|
9
|
+
* @description Checks for valid lexical data.
|
|
10
|
+
*
|
|
11
|
+
* Check for first level of properties that empty editor state data need to have.
|
|
12
|
+
* @see generateInitialLexicalValue
|
|
13
|
+
*/
|
|
14
|
+
var isValidLexicalData = function isValidLexicalData(editorStateValue) {
|
|
15
|
+
if (!editorStateValue) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (!(0, _isValidJSON.isValidJSON)(editorStateValue)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
var data = JSON.parse(editorStateValue);
|
|
22
|
+
return !!data["root"];
|
|
23
|
+
};
|
|
24
|
+
exports.isValidLexicalData = isValidLexicalData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isValidLexicalData","editorStateValue","isValidJSON","data","JSON","parse"],"sources":["isValidLexicalData.ts"],"sourcesContent":["import { isValidJSON } from \"~/utils/isValidJSON\";\nimport { LexicalValue } from \"~/types\";\n/*\n * @description Checks for valid lexical data.\n *\n * Check for first level of properties that empty editor state data need to have.\n * @see generateInitialLexicalValue\n */\nexport const isValidLexicalData = (editorStateValue: LexicalValue | null): boolean => {\n if (!editorStateValue) {\n return false;\n }\n if (!isValidJSON(editorStateValue)) {\n return false;\n }\n const data = JSON.parse(editorStateValue);\n return !!data[\"root\"];\n};\n"],"mappings":";;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAkB,CAAIC,gBAAqC,EAAc;EAClF,IAAI,CAACA,gBAAgB,EAAE;IACnB,OAAO,KAAK;EAChB;EACA,IAAI,CAAC,IAAAC,wBAAW,EAACD,gBAAgB,CAAC,EAAE;IAChC,OAAO,KAAK;EAChB;EACA,IAAME,IAAI,GAAGC,IAAI,CAACC,KAAK,CAACJ,gBAAgB,CAAC;EACzC,OAAO,CAAC,CAACE,IAAI,CAAC,MAAM,CAAC;AACzB,CAAC;AAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.clearNodeFormatting = void 0;
|
|
7
|
+
var _lexical = require("lexical");
|
|
8
|
+
var _selection = require("@lexical/selection");
|
|
9
|
+
var _utils = require("@lexical/utils");
|
|
10
|
+
var _LexicalDecoratorBlockNode = require("@lexical/react/LexicalDecoratorBlockNode");
|
|
11
|
+
var clearNodeFormatting = function clearNodeFormatting(activeEditor, selection) {
|
|
12
|
+
activeEditor.update(function () {
|
|
13
|
+
if ((0, _lexical.$isRangeSelection)(selection)) {
|
|
14
|
+
(0, _selection.$selectAll)(selection);
|
|
15
|
+
selection.getNodes().forEach(function (node) {
|
|
16
|
+
if ((0, _lexical.$isTextNode)(node)) {
|
|
17
|
+
node.setFormat(0);
|
|
18
|
+
node.setStyle("");
|
|
19
|
+
(0, _utils.$getNearestBlockElementAncestorOrThrow)(node).setFormat("");
|
|
20
|
+
}
|
|
21
|
+
if ((0, _LexicalDecoratorBlockNode.$isDecoratorBlockNode)(node)) {
|
|
22
|
+
node.setFormat("");
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
exports.clearNodeFormatting = clearNodeFormatting;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["clearNodeFormatting","activeEditor","selection","update","$isRangeSelection","$selectAll","getNodes","forEach","node","$isTextNode","setFormat","setStyle","$getNearestBlockElementAncestorOrThrow","$isDecoratorBlockNode"],"sources":["clearNodeFormating.ts"],"sourcesContent":["import {\n $isRangeSelection,\n $isTextNode,\n GridSelection,\n LexicalEditor,\n NodeSelection,\n RangeSelection\n} from \"lexical\";\nimport { $selectAll } from \"@lexical/selection\";\nimport { $getNearestBlockElementAncestorOrThrow } from \"@lexical/utils\";\nimport { $isDecoratorBlockNode } from \"@lexical/react/LexicalDecoratorBlockNode\";\n\nexport const clearNodeFormatting = (\n activeEditor: LexicalEditor,\n selection: RangeSelection | NodeSelection | GridSelection | null\n) => {\n activeEditor.update(() => {\n if ($isRangeSelection(selection)) {\n $selectAll(selection);\n selection.getNodes().forEach(node => {\n if ($isTextNode(node)) {\n node.setFormat(0);\n node.setStyle(\"\");\n $getNearestBlockElementAncestorOrThrow(node).setFormat(\"\");\n }\n if ($isDecoratorBlockNode(node)) {\n node.setFormat(\"\");\n }\n });\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAQA;AACA;AACA;AAEO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAmB,CAC5BC,YAA2B,EAC3BC,SAAgE,EAC/D;EACDD,YAAY,CAACE,MAAM,CAAC,YAAM;IACtB,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,EAAE;MAC9B,IAAAG,qBAAU,EAACH,SAAS,CAAC;MACrBA,SAAS,CAACI,QAAQ,EAAE,CAACC,OAAO,CAAC,UAAAC,IAAI,EAAI;QACjC,IAAI,IAAAC,oBAAW,EAACD,IAAI,CAAC,EAAE;UACnBA,IAAI,CAACE,SAAS,CAAC,CAAC,CAAC;UACjBF,IAAI,CAACG,QAAQ,CAAC,EAAE,CAAC;UACjB,IAAAC,6CAAsC,EAACJ,IAAI,CAAC,CAACE,SAAS,CAAC,EAAE,CAAC;QAC9D;QACA,IAAI,IAAAG,gDAAqB,EAACL,IAAI,CAAC,EAAE;UAC7BA,IAAI,CAACE,SAAS,CAAC,EAAE,CAAC;QACtB;MACJ,CAAC,CAAC;IACN;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.formatToHeading = void 0;
|
|
7
|
+
var _lexical = require("lexical");
|
|
8
|
+
var _selection = require("@lexical/selection");
|
|
9
|
+
var _HeadingNode = require("../../nodes/HeadingNode");
|
|
10
|
+
/*
|
|
11
|
+
* Will change the selected HTML tag to specified heading or h1-h6.
|
|
12
|
+
* For example if the selection is p with content inside after formatting the root tag
|
|
13
|
+
* will be h1 with heading 1 theme style and the same content inside.
|
|
14
|
+
* */
|
|
15
|
+
var formatToHeading = function formatToHeading(editor, tag, typographyStyleId) {
|
|
16
|
+
editor.update(function () {
|
|
17
|
+
var selection = (0, _lexical.$getSelection)();
|
|
18
|
+
if ((0, _lexical.$isRangeSelection)(selection) || (0, _lexical.DEPRECATED_$isGridSelection)(selection)) {
|
|
19
|
+
(0, _selection.$setBlocksType)(selection, function () {
|
|
20
|
+
return (0, _HeadingNode.$createHeadingNode)(tag, typographyStyleId);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.formatToHeading = formatToHeading;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["formatToHeading","editor","tag","typographyStyleId","update","selection","$getSelection","$isRangeSelection","DEPRECATED_$isGridSelection","$setBlocksType","$createHeadingNode"],"sources":["formatToHeading.ts"],"sourcesContent":["import {\n $getSelection,\n $isRangeSelection,\n DEPRECATED_$isGridSelection,\n LexicalEditor\n} from \"lexical\";\nimport { $setBlocksType } from \"@lexical/selection\";\nimport { $createHeadingNode } from \"~/nodes/HeadingNode\";\nimport { HeadingTagType } from \"@lexical/rich-text\";\n\n/*\n * Will change the selected HTML tag to specified heading or h1-h6.\n * For example if the selection is p with content inside after formatting the root tag\n * will be h1 with heading 1 theme style and the same content inside.\n * */\nexport const formatToHeading = (\n editor: LexicalEditor,\n tag: HeadingTagType,\n typographyStyleId?: string\n) => {\n editor.update(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {\n $setBlocksType(selection, () => $createHeadingNode(tag, typographyStyleId));\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAMA;AACA;AAGA;AACA;AACA;AACA;AACA;AACO,IAAMA,eAAe,GAAG,SAAlBA,eAAe,CACxBC,MAAqB,EACrBC,GAAmB,EACnBC,iBAA0B,EACzB;EACDF,MAAM,CAACG,MAAM,CAAC,YAAM;IAChB,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;IACjC,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,IAAI,IAAAG,oCAA2B,EAACH,SAAS,CAAC,EAAE;MACxE,IAAAI,yBAAc,EAACJ,SAAS,EAAE;QAAA,OAAM,IAAAK,+BAAkB,EAACR,GAAG,EAAEC,iBAAiB,CAAC;MAAA,EAAC;IAC/E;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|