@webiny/lexical-editor 5.43.2-beta.0 → 6.0.0-alpha.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.js +2 -8
- package/commands/image.js.map +1 -1
- package/commands/index.js +4 -49
- package/commands/index.js.map +1 -1
- package/commands/list.js +4 -10
- package/commands/list.js.map +1 -1
- package/commands/quote.js +2 -8
- package/commands/quote.js.map +1 -1
- package/commands/toolbar.js +2 -8
- package/commands/toolbar.js.map +1 -1
- package/components/Editor/EnsureHeadingTagPlugin.js +10 -16
- package/components/Editor/EnsureHeadingTagPlugin.js.map +1 -1
- package/components/Editor/HeadingEditor.js +13 -21
- package/components/Editor/HeadingEditor.js.map +1 -1
- package/components/Editor/ParagraphEditor.js +12 -19
- package/components/Editor/ParagraphEditor.js.map +1 -1
- package/components/Editor/RichTextEditor.js +92 -105
- package/components/Editor/RichTextEditor.js.map +1 -1
- package/components/Editor/normalizeInputValue.js +2 -8
- package/components/Editor/normalizeInputValue.js.map +1 -1
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +39 -49
- package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
- package/components/LexicalEditorConfig/components/Node.js +17 -26
- package/components/LexicalEditorConfig/components/Node.js.map +1 -1
- package/components/LexicalEditorConfig/components/Plugin.js +17 -26
- package/components/LexicalEditorConfig/components/Plugin.js.map +1 -1
- package/components/LexicalEditorConfig/components/ToolbarElement.js +17 -26
- package/components/LexicalEditorConfig/components/ToolbarElement.js.map +1 -1
- package/components/LexicalHtmlRenderer.js +37 -46
- package/components/LexicalHtmlRenderer.js.map +1 -1
- package/components/Toolbar/StaticToolbar.d.ts +3 -1
- package/components/Toolbar/StaticToolbar.js +19 -23
- package/components/Toolbar/StaticToolbar.js.map +1 -1
- package/components/Toolbar/Toolbar.js +66 -75
- package/components/Toolbar/Toolbar.js.map +1 -1
- package/components/ToolbarActions/BoldAction.js +16 -21
- package/components/ToolbarActions/BoldAction.js.map +1 -1
- package/components/ToolbarActions/BulletListAction.js +26 -31
- package/components/ToolbarActions/BulletListAction.js.map +1 -1
- package/components/ToolbarActions/CodeHighlightAction.js +16 -21
- package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
- package/components/ToolbarActions/FontColorAction.js +32 -42
- package/components/ToolbarActions/FontColorAction.js.map +1 -1
- package/components/ToolbarActions/FontSizeAction.js +53 -71
- package/components/ToolbarActions/FontSizeAction.js.map +1 -1
- package/components/ToolbarActions/ImageAction.js +19 -34
- package/components/ToolbarActions/ImageAction.js.map +1 -1
- package/components/ToolbarActions/ItalicAction.js +16 -21
- package/components/ToolbarActions/ItalicAction.js.map +1 -1
- package/components/ToolbarActions/LinkAction.js +19 -24
- package/components/ToolbarActions/LinkAction.js.map +1 -1
- package/components/ToolbarActions/NumberedListAction.js +26 -33
- package/components/ToolbarActions/NumberedListAction.js.map +1 -1
- package/components/ToolbarActions/QuoteAction.js +20 -25
- package/components/ToolbarActions/QuoteAction.js.map +1 -1
- package/components/ToolbarActions/TextAlignmentAction.js +36 -45
- package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
- package/components/ToolbarActions/TypographyAction.js +43 -55
- package/components/ToolbarActions/TypographyAction.js.map +1 -1
- package/components/ToolbarActions/UnderlineAction.js +16 -21
- package/components/ToolbarActions/UnderlineAction.js.map +1 -1
- package/context/FontColorActionContext.js +2 -9
- package/context/FontColorActionContext.js.map +1 -1
- package/context/RichTextEditorContext.js +15 -26
- package/context/RichTextEditorContext.js.map +1 -1
- package/context/SharedHistoryContext.js +12 -20
- package/context/SharedHistoryContext.js.map +1 -1
- package/context/TextAlignmentActionContextProps.js +2 -9
- package/context/TextAlignmentActionContextProps.js.map +1 -1
- package/context/TypographyActionContext.js +2 -9
- package/context/TypographyActionContext.js.map +1 -1
- package/hooks/index.js +8 -93
- package/hooks/index.js.map +1 -1
- package/hooks/useCurrentElement.d.ts +2 -2
- package/hooks/useCurrentElement.js +12 -18
- package/hooks/useCurrentElement.js.map +1 -1
- package/hooks/useCurrentSelection.js +27 -40
- package/hooks/useCurrentSelection.js.map +1 -1
- package/hooks/useFontColorPicker.js +5 -11
- package/hooks/useFontColorPicker.js.map +1 -1
- package/hooks/useIsMounted.js +6 -14
- package/hooks/useIsMounted.js.map +1 -1
- package/hooks/useList.js +31 -35
- package/hooks/useList.js.map +1 -1
- package/hooks/useQuote.js +12 -17
- package/hooks/useQuote.js.map +1 -1
- package/hooks/useRichTextEditor.js +5 -11
- package/hooks/useRichTextEditor.js.map +1 -1
- package/hooks/useTextAlignmentAction.js +5 -11
- package/hooks/useTextAlignmentAction.js.map +1 -1
- package/hooks/useTypographyAction.js +5 -11
- package/hooks/useTypographyAction.js.map +1 -1
- package/index.js +49 -322
- package/index.js.map +1 -1
- package/package.json +8 -7
- package/plugins/BlurEventPlugin/BlurEventPlugin.js +16 -22
- package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +9 -14
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/index.js +1 -16
- package/plugins/CodeHighlightPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.d.ts +16 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +158 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.d.ts +8 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js +62 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +2 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +5 -16
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +11 -180
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.d.ts +2 -3
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js +54 -68
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.d.ts +1 -1
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js +16 -26
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.js +1 -16
- package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js +3 -9
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js.map +1 -1
- package/plugins/FontColorPlugin/FontColorPlugin.js +19 -22
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
- package/plugins/FontColorPlugin/applyColorToNode.js +4 -10
- package/plugins/FontColorPlugin/applyColorToNode.js.map +1 -1
- package/plugins/FontColorPlugin/applyColorToSelection.js +28 -44
- package/plugins/FontColorPlugin/applyColorToSelection.js.map +1 -1
- package/plugins/ImagesPlugin/ImagesPlugin.js +59 -58
- package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.js +23 -23
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.js.map +1 -1
- package/plugins/LexicalUpdateStatePlugin/index.js +1 -16
- package/plugins/LexicalUpdateStatePlugin/index.js.map +1 -1
- package/plugins/LinkPlugin/LinkPlugin.js +30 -37
- package/plugins/LinkPlugin/LinkPlugin.js.map +1 -1
- package/plugins/ListPLugin/ListPlugin.js +10 -15
- package/plugins/ListPLugin/ListPlugin.js.map +1 -1
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js +11 -16
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js.map +1 -1
- package/plugins/TypographyPlugin/TypographyPlugin.js +16 -21
- package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
- package/types.d.ts +3 -3
- package/types.js +6 -38
- package/types.js.map +1 -1
- package/ui/ContentEditable.js +7 -14
- package/ui/ContentEditable.js.map +1 -1
- package/ui/Divider.js +3 -10
- package/ui/Divider.js.map +1 -1
- package/ui/DropDown.js +61 -88
- package/ui/DropDown.js.map +1 -1
- package/ui/ImageResizer.js +78 -83
- package/ui/ImageResizer.js.map +1 -1
- package/ui/LinkPreview.js +22 -29
- package/ui/LinkPreview.js.map +1 -1
- package/ui/Placeholder.js +10 -16
- package/ui/Placeholder.js.map +1 -1
- package/ui/TextInput.js +11 -18
- package/ui/TextInput.js.map +1 -1
- package/ui/ToolbarActionDialog.js +30 -42
- package/ui/ToolbarActionDialog.js.map +1 -1
- package/utils/canUseDOM.js +1 -7
- package/utils/canUseDOM.js.map +1 -1
- package/utils/files.js +9 -26
- package/utils/files.js.map +1 -1
- package/utils/generateInitialLexicalValue.js +2 -8
- package/utils/generateInitialLexicalValue.js.map +1 -1
- package/utils/getDOMRangeRect.js +4 -10
- package/utils/getDOMRangeRect.js.map +1 -1
- package/utils/getSelectedNode.js +9 -16
- package/utils/getSelectedNode.js.map +1 -1
- package/utils/getTransparentImage.js +1 -7
- package/utils/getTransparentImage.js.map +1 -1
- package/utils/insertImage.js +8 -14
- package/utils/insertImage.js.map +1 -1
- package/utils/isAnchorLink.js +1 -7
- package/utils/isAnchorLink.js.map +1 -1
- package/utils/isChildOfFloatingToolbar.js +3 -9
- package/utils/isChildOfFloatingToolbar.js.map +1 -1
- package/utils/isHTMLElement.js +1 -7
- package/utils/isHTMLElement.js.map +1 -1
- package/utils/isValidJSON.js +3 -9
- package/utils/isValidJSON.js.map +1 -1
- package/utils/isValidLexicalData.d.ts +1 -1
- package/utils/isValidLexicalData.js +6 -12
- package/utils/isValidLexicalData.js.map +1 -1
- package/utils/point.js +35 -60
- package/utils/point.js.map +1 -1
- package/utils/rect.js +114 -149
- package/utils/rect.js.map +1 -1
- package/utils/sanitizeUrl.js +6 -13
- package/utils/sanitizeUrl.js.map +1 -1
- package/utils/setFloatingElemPosition.js +11 -19
- package/utils/setFloatingElemPosition.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.d.ts +0 -2
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js +0 -96
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","FORMAT_TEXT_COMMAND","useCurrentSelection","useRichTextEditor","CodeHighlightAction","editor","rangeSelection","isCodeSelected","hasFormat","handleClick","dispatchCommand","createElement","onClick","className"],"sources":["CodeHighlightAction.tsx"],"sourcesContent":["import React from \"react\";\nimport { FORMAT_TEXT_COMMAND } from \"lexical\";\nimport { useCurrentSelection } from \"~/hooks/useCurrentSelection\";\nimport { useRichTextEditor } from \"~/hooks\";\n\nexport const CodeHighlightAction = () => {\n const { editor } = useRichTextEditor();\n const { rangeSelection } = useCurrentSelection();\n const isCodeSelected = rangeSelection ? rangeSelection.hasFormat(\"code\") : false;\n\n const handleClick = () => {\n editor.dispatchCommand(FORMAT_TEXT_COMMAND, \"code\");\n };\n\n return (\n <button\n onClick={handleClick}\n className={\"popup-item spaced \" + (isCodeSelected ? \"active\" : \"\")}\n aria-label=\"Text code highlight\"\n >\n <i className=\"format code\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,mBAAmB,QAAQ,SAAS;AAC7C,SAASC,mBAAmB;AAC5B,SAASC,iBAAiB;AAE1B,OAAO,MAAMC,mBAAmB,GAAGA,CAAA,KAAM;EACrC,MAAM;IAAEC;EAAO,CAAC,GAAGF,iBAAiB,CAAC,CAAC;EACtC,MAAM;IAAEG;EAAe,CAAC,GAAGJ,mBAAmB,CAAC,CAAC;EAChD,MAAMK,cAAc,GAAGD,cAAc,GAAGA,cAAc,CAACE,SAAS,CAAC,MAAM,CAAC,GAAG,KAAK;EAEhF,MAAMC,WAAW,GAAGA,CAAA,KAAM;IACtBJ,MAAM,CAACK,eAAe,CAACT,mBAAmB,EAAE,MAAM,CAAC;EACvD,CAAC;EAED,oBACID,KAAA,CAAAW,aAAA;IACIC,OAAO,EAAEH,WAAY;IACrBI,SAAS,EAAE,oBAAoB,IAAIN,cAAc,GAAG,QAAQ,GAAG,EAAE,CAAE;IACnE,cAAW;EAAqB,gBAEhCP,KAAA,CAAAW,aAAA;IAAGE,SAAS,EAAC;EAAa,CAAE,CACxB,CAAC;AAEjB,CAAC","ignoreList":[]}
|
|
@@ -1,59 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _FontColorActionContext = require("../../context/FontColorActionContext");
|
|
11
|
-
var _lexicalNodes = require("@webiny/lexical-nodes");
|
|
12
|
-
var _getSelectedNode = require("../../utils/getSelectedNode");
|
|
13
|
-
var _useCurrentSelection = require("../../hooks/useCurrentSelection");
|
|
14
|
-
var _hooks = require("../../hooks");
|
|
15
|
-
var FontColorPicker = exports.FontColorPicker = (0, _reactComposition.makeDecoratable)("FontColorPicker", function () {
|
|
16
|
-
(0, _react.useEffect)(function () {
|
|
1
|
+
import React, { useCallback, useEffect, useMemo } from "react";
|
|
2
|
+
import { Compose, makeDecoratable } from "@webiny/react-composition";
|
|
3
|
+
import { FontColorActionContext } from "../../context/FontColorActionContext";
|
|
4
|
+
import { $isFontColorNode, ADD_FONT_COLOR_COMMAND, ThemeColorValue } from "@webiny/lexical-nodes";
|
|
5
|
+
import { getSelectedNode } from "../../utils/getSelectedNode";
|
|
6
|
+
import { useDeriveValueFromSelection } from "../../hooks/useCurrentSelection";
|
|
7
|
+
import { useRichTextEditor } from "../../hooks";
|
|
8
|
+
export const FontColorPicker = makeDecoratable("FontColorPicker", () => {
|
|
9
|
+
useEffect(() => {
|
|
17
10
|
console.log("Default FontColorPicker, please add your own component");
|
|
18
11
|
}, []);
|
|
19
12
|
return null;
|
|
20
13
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
const FontActionColorPicker = ({
|
|
15
|
+
element
|
|
16
|
+
}) => {
|
|
17
|
+
return /*#__PURE__*/React.createElement(Compose, {
|
|
24
18
|
component: FontColorPicker,
|
|
25
|
-
with:
|
|
26
|
-
return function () {
|
|
27
|
-
return element;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
19
|
+
with: () => () => element
|
|
30
20
|
});
|
|
31
21
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
editor
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
export const FontColorAction = () => {
|
|
23
|
+
const {
|
|
24
|
+
editor
|
|
25
|
+
} = useRichTextEditor();
|
|
26
|
+
const fontColor = useDeriveValueFromSelection(({
|
|
27
|
+
rangeSelection
|
|
28
|
+
}) => {
|
|
37
29
|
if (!rangeSelection) {
|
|
38
30
|
return "#000";
|
|
39
31
|
}
|
|
40
|
-
|
|
41
|
-
return
|
|
32
|
+
const node = getSelectedNode(rangeSelection);
|
|
33
|
+
return $isFontColorNode(node) ? node.getColorStyle().color : "#000";
|
|
42
34
|
});
|
|
43
|
-
|
|
44
|
-
editor.dispatchCommand(
|
|
45
|
-
color: new
|
|
35
|
+
const onFontColorSelect = useCallback((colorValue, themeColorName) => {
|
|
36
|
+
editor.dispatchCommand(ADD_FONT_COLOR_COMMAND, {
|
|
37
|
+
color: new ThemeColorValue(colorValue, themeColorName)
|
|
46
38
|
});
|
|
47
39
|
}, []);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, [onFontColorSelect, fontColor]);
|
|
54
|
-
return /*#__PURE__*/_react.default.createElement(_FontColorActionContext.FontColorActionContext.Provider, {
|
|
40
|
+
const context = useMemo(() => ({
|
|
41
|
+
value: fontColor,
|
|
42
|
+
applyColor: onFontColorSelect
|
|
43
|
+
}), [onFontColorSelect, fontColor]);
|
|
44
|
+
return /*#__PURE__*/React.createElement(FontColorActionContext.Provider, {
|
|
55
45
|
value: context
|
|
56
|
-
}, /*#__PURE__*/
|
|
46
|
+
}, /*#__PURE__*/React.createElement(FontColorPicker, null));
|
|
57
47
|
};
|
|
58
48
|
FontColorAction.ColorPicker = FontActionColorPicker;
|
|
59
49
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","useCallback","useEffect","useMemo","Compose","makeDecoratable","FontColorActionContext","$isFontColorNode","ADD_FONT_COLOR_COMMAND","ThemeColorValue","getSelectedNode","useDeriveValueFromSelection","useRichTextEditor","FontColorPicker","console","log","FontActionColorPicker","element","createElement","component","with","FontColorAction","editor","fontColor","rangeSelection","node","getColorStyle","color","onFontColorSelect","colorValue","themeColorName","dispatchCommand","context","value","applyColor","Provider","ColorPicker"],"sources":["FontColorAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo } from \"react\";\nimport { LexicalCommand } from \"lexical\";\nimport { Compose, makeDecoratable } from \"@webiny/react-composition\";\nimport { FontColorActionContext } from \"~/context/FontColorActionContext\";\nimport {\n $isFontColorNode,\n ADD_FONT_COLOR_COMMAND,\n FontColorPayload,\n ThemeColorValue\n} from \"@webiny/lexical-nodes\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { useDeriveValueFromSelection } from \"~/hooks/useCurrentSelection\";\nimport { useRichTextEditor } from \"~/hooks\";\n\nexport const FontColorPicker = makeDecoratable(\"FontColorPicker\", (): JSX.Element | null => {\n useEffect(() => {\n console.log(\"Default FontColorPicker, please add your own component\");\n }, []);\n return null;\n});\n\ninterface FontActionColorPicker {\n element: JSX.Element;\n}\n\nconst FontActionColorPicker = ({ element }: FontActionColorPicker): JSX.Element => {\n return <Compose component={FontColorPicker} with={() => () => element} />;\n};\n\nexport type FontColorAction = React.ComponentType<unknown> & {\n ColorPicker: typeof FontActionColorPicker;\n};\n\nexport const FontColorAction: FontColorAction = () => {\n const { editor } = useRichTextEditor();\n const fontColor = useDeriveValueFromSelection(({ rangeSelection }) => {\n if (!rangeSelection) {\n return \"#000\";\n }\n\n const node = getSelectedNode(rangeSelection);\n return $isFontColorNode(node) ? node.getColorStyle().color : \"#000\";\n });\n\n const onFontColorSelect = useCallback(\n (colorValue: string, themeColorName: string | undefined) => {\n editor.dispatchCommand<LexicalCommand<FontColorPayload>>(ADD_FONT_COLOR_COMMAND, {\n color: new ThemeColorValue(colorValue, themeColorName)\n });\n },\n []\n );\n\n const context = useMemo(\n () => ({\n value: fontColor,\n applyColor: onFontColorSelect\n }),\n [onFontColorSelect, fontColor]\n );\n\n return (\n <FontColorActionContext.Provider value={context}>\n <FontColorPicker />\n </FontColorActionContext.Provider>\n );\n};\n\nFontColorAction.ColorPicker = FontActionColorPicker;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAE9D,SAASC,OAAO,EAAEC,eAAe,QAAQ,2BAA2B;AACpE,SAASC,sBAAsB;AAC/B,SACIC,gBAAgB,EAChBC,sBAAsB,EAEtBC,eAAe,QACZ,uBAAuB;AAC9B,SAASC,eAAe;AACxB,SAASC,2BAA2B;AACpC,SAASC,iBAAiB;AAE1B,OAAO,MAAMC,eAAe,GAAGR,eAAe,CAAC,iBAAiB,EAAE,MAA0B;EACxFH,SAAS,CAAC,MAAM;IACZY,OAAO,CAACC,GAAG,CAAC,wDAAwD,CAAC;EACzE,CAAC,EAAE,EAAE,CAAC;EACN,OAAO,IAAI;AACf,CAAC,CAAC;AAMF,MAAMC,qBAAqB,GAAGA,CAAC;EAAEC;AAA+B,CAAC,KAAkB;EAC/E,oBAAOjB,KAAA,CAAAkB,aAAA,CAACd,OAAO;IAACe,SAAS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|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _DropDown = require("../../ui/DropDown");
|
|
16
|
-
var _useCurrentSelection = require("../../hooks/useCurrentSelection");
|
|
17
|
-
var _hooks = require("../../hooks");
|
|
18
|
-
var FONT_SIZES_FALLBACK = exports.FONT_SIZES_FALLBACK = ["8px", "9px", "10px", "11px", "12px", "14px", "15px", "16px", "18px", "21px", "24px", "30px", "36px", "48px", "60px", "72px", "96px"].map(function (size) {
|
|
19
|
-
return {
|
|
20
|
-
id: size,
|
|
21
|
-
name: size,
|
|
22
|
-
value: size,
|
|
23
|
-
default: size === "15px"
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
var emptyOption = {
|
|
1
|
+
import React, { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { $getSelectionStyleValueForProperty, $patchStyleText } from "@lexical/selection";
|
|
3
|
+
import { mergeRegister } from "@lexical/utils";
|
|
4
|
+
import { $getSelection, $isRangeSelection } from "lexical";
|
|
5
|
+
import { DropDown, DropDownItem } from "../../ui/DropDown";
|
|
6
|
+
import { useDeriveValueFromSelection } from "../../hooks/useCurrentSelection";
|
|
7
|
+
import { useRichTextEditor } from "../../hooks";
|
|
8
|
+
export const FONT_SIZES_FALLBACK = ["8px", "9px", "10px", "11px", "12px", "14px", "15px", "16px", "18px", "21px", "24px", "30px", "36px", "48px", "60px", "72px", "96px"].map(size => ({
|
|
9
|
+
id: size,
|
|
10
|
+
name: size,
|
|
11
|
+
value: size,
|
|
12
|
+
default: size === "15px"
|
|
13
|
+
}));
|
|
14
|
+
const emptyOption = {
|
|
27
15
|
value: "",
|
|
28
16
|
name: "Font Size",
|
|
29
17
|
id: "empty"
|
|
@@ -35,75 +23,69 @@ function dropDownActiveClass(active) {
|
|
|
35
23
|
return "";
|
|
36
24
|
}
|
|
37
25
|
function FontSizeDropDown(props) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
disabled =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
26
|
+
const {
|
|
27
|
+
editor,
|
|
28
|
+
value,
|
|
29
|
+
fontSizes,
|
|
30
|
+
disabled = false
|
|
31
|
+
} = props;
|
|
32
|
+
const handleClick = useCallback(option => {
|
|
33
|
+
editor.update(() => {
|
|
34
|
+
const selection = $getSelection();
|
|
35
|
+
if ($isRangeSelection(selection)) {
|
|
36
|
+
$patchStyleText(selection, {
|
|
37
|
+
["font-size"]: option.value
|
|
38
|
+
});
|
|
48
39
|
}
|
|
49
40
|
});
|
|
50
41
|
}, [editor]);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}) ?? emptyOption;
|
|
54
|
-
return /*#__PURE__*/_react.default.createElement(_DropDown.DropDown, {
|
|
42
|
+
const selectedOption = fontSizes.find(opt => opt.value === value) ?? emptyOption;
|
|
43
|
+
return /*#__PURE__*/React.createElement(DropDown, {
|
|
55
44
|
disabled: disabled,
|
|
56
45
|
buttonClassName: "toolbar-item font-size",
|
|
57
46
|
buttonLabel: selectedOption.name,
|
|
58
47
|
buttonAriaLabel: "Formatting options for font size"
|
|
59
|
-
}, fontSizes.map(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
67
|
-
className: "text"
|
|
68
|
-
}, option.name));
|
|
69
|
-
}));
|
|
48
|
+
}, fontSizes.map(option => /*#__PURE__*/React.createElement(DropDownItem, {
|
|
49
|
+
className: `item fontsize-item ${dropDownActiveClass(value === option.id)}`,
|
|
50
|
+
onClick: () => handleClick(option),
|
|
51
|
+
key: option.id
|
|
52
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
53
|
+
className: "text"
|
|
54
|
+
}, option.name))));
|
|
70
55
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
editor
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
setIsEditable = _useState2[1];
|
|
82
|
-
var fontSize = (0, _useCurrentSelection.useDeriveValueFromSelection)(function (_ref2) {
|
|
83
|
-
var rangeSelection = _ref2.rangeSelection;
|
|
56
|
+
const FontSize = ({
|
|
57
|
+
fontSizes = FONT_SIZES_FALLBACK
|
|
58
|
+
}) => {
|
|
59
|
+
const {
|
|
60
|
+
editor
|
|
61
|
+
} = useRichTextEditor();
|
|
62
|
+
const [isEditable, setIsEditable] = useState(() => editor.isEditable());
|
|
63
|
+
const fontSize = useDeriveValueFromSelection(({
|
|
64
|
+
rangeSelection
|
|
65
|
+
}) => {
|
|
84
66
|
if (!rangeSelection) {
|
|
85
67
|
return undefined;
|
|
86
68
|
}
|
|
87
69
|
try {
|
|
88
|
-
return
|
|
89
|
-
} catch
|
|
70
|
+
return $getSelectionStyleValueForProperty(rangeSelection, "font-size");
|
|
71
|
+
} catch {
|
|
90
72
|
return undefined;
|
|
91
73
|
}
|
|
92
74
|
});
|
|
93
|
-
|
|
94
|
-
return
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
return mergeRegister(editor.registerEditableListener(editable => {
|
|
95
77
|
setIsEditable(editable);
|
|
96
78
|
}));
|
|
97
79
|
}, [editor]);
|
|
98
|
-
return /*#__PURE__*/
|
|
80
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FontSizeDropDown, {
|
|
99
81
|
disabled: !isEditable,
|
|
100
82
|
value: fontSize,
|
|
101
83
|
editor: editor,
|
|
102
84
|
fontSizes: fontSizes
|
|
103
85
|
}));
|
|
104
86
|
};
|
|
105
|
-
|
|
106
|
-
FONT_SIZES_FALLBACK
|
|
87
|
+
export const FontSizeAction = Object.assign(FontSize, {
|
|
88
|
+
FONT_SIZES_FALLBACK
|
|
107
89
|
});
|
|
108
90
|
|
|
109
91
|
//# sourceMappingURL=FontSizeAction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","useCallback","useEffect","useState","$getSelectionStyleValueForProperty","$patchStyleText","mergeRegister","$getSelection","$isRangeSelection","DropDown","DropDownItem","useDeriveValueFromSelection","useRichTextEditor","FONT_SIZES_FALLBACK","map","size","id","name","value","default","emptyOption","dropDownActiveClass","active","FontSizeDropDown","props","editor","fontSizes","disabled","handleClick","option","update","selection","selectedOption","find","opt","createElement","buttonClassName","buttonLabel","buttonAriaLabel","className","onClick","key","FontSize","isEditable","setIsEditable","fontSize","rangeSelection","undefined","registerEditableListener","editable","Fragment","FontSizeAction","Object","assign"],"sources":["FontSizeAction.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { $getSelectionStyleValueForProperty, $patchStyleText } from \"@lexical/selection\";\nimport { mergeRegister } from \"@lexical/utils\";\nimport { $getSelection, $isRangeSelection, LexicalEditor } from \"lexical\";\nimport { DropDown, DropDownItem } from \"~/ui/DropDown\";\nimport { useDeriveValueFromSelection } from \"~/hooks/useCurrentSelection\";\nimport { useRichTextEditor } from \"~/hooks\";\n\nexport interface FontSize {\n id: string;\n name: string;\n value: string;\n}\n\nexport const FONT_SIZES_FALLBACK: FontSize[] = [\n \"8px\",\n \"9px\",\n \"10px\",\n \"11px\",\n \"12px\",\n \"14px\",\n \"15px\",\n \"16px\",\n \"18px\",\n \"21px\",\n \"24px\",\n \"30px\",\n \"36px\",\n \"48px\",\n \"60px\",\n \"72px\",\n \"96px\"\n].map(size => ({\n id: size,\n name: size,\n value: size,\n default: size === \"15px\"\n}));\n\nconst emptyOption: FontSize = {\n value: \"\",\n name: \"Font Size\",\n id: \"empty\"\n};\n\nfunction dropDownActiveClass(active: boolean) {\n if (active) {\n return \"active dropdown-item-active\";\n }\n return \"\";\n}\n\ninterface FontSizeDropDownProps {\n fontSizes: FontSize[];\n editor: LexicalEditor;\n value: string | undefined;\n disabled?: boolean;\n}\n\nfunction FontSizeDropDown(props: FontSizeDropDownProps): JSX.Element {\n const { editor, value, fontSizes, disabled = false } = props;\n\n const handleClick = useCallback(\n (option: FontSize) => {\n editor.update(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n $patchStyleText(selection, {\n [\"font-size\"]: option.value\n });\n }\n });\n },\n [editor]\n );\n\n const selectedOption = fontSizes.find(opt => opt.value === value) ?? emptyOption;\n\n return (\n <DropDown\n disabled={disabled}\n buttonClassName=\"toolbar-item font-size\"\n buttonLabel={selectedOption.name}\n buttonAriaLabel={\"Formatting options for font size\"}\n >\n {fontSizes.map(option => (\n <DropDownItem\n className={`item fontsize-item ${dropDownActiveClass(value === option.id)}`}\n onClick={() => handleClick(option)}\n key={option.id}\n >\n <span className=\"text\">{option.name}</span>\n </DropDownItem>\n ))}\n </DropDown>\n );\n}\n\ninterface FontSizeActionProps {\n fontSizes?: FontSize[];\n}\n\nconst FontSize = ({ fontSizes = FONT_SIZES_FALLBACK }: FontSizeActionProps) => {\n const { editor } = useRichTextEditor();\n const [isEditable, setIsEditable] = useState(() => editor.isEditable());\n const fontSize = useDeriveValueFromSelection(({ rangeSelection }) => {\n if (!rangeSelection) {\n return undefined;\n }\n try {\n return $getSelectionStyleValueForProperty(rangeSelection, \"font-size\");\n } catch {\n return undefined;\n }\n });\n\n useEffect(() => {\n return mergeRegister(\n editor.registerEditableListener(editable => {\n setIsEditable(editable);\n })\n );\n }, [editor]);\n\n return (\n <>\n <FontSizeDropDown\n disabled={!isEditable}\n value={fontSize}\n editor={editor}\n fontSizes={fontSizes}\n />\n </>\n );\n};\n\nexport const FontSizeAction = Object.assign(FontSize, { FONT_SIZES_FALLBACK });\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC/D,SAASC,kCAAkC,EAAEC,eAAe,QAAQ,oBAAoB;AACxF,SAASC,aAAa,QAAQ,gBAAgB;AAC9C,SAASC,a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QAAQ,IAAI;MACxCL,aAAa,CAACK,QAAQ,CAAC;IAC3B,CAAC,CACL,CAAC;EACL,CAAC,EAAE,CAACxB,MAAM,CAAC,CAAC;EAEZ,oBACIzB,KAAA,CAAAmC,aAAA,CAAAnC,KAAA,CAAAkD,QAAA,qBACIlD,KAAA,CAAAmC,aAAA,CAACZ,gBAAgB;IACbI,QAAQ,EAAE,CAACgB,UAAW;IACtBzB,KAAK,EAAE2B,QAAS;IAChBpB,MAAM,EAAEA,MAAO;IACfC,SAAS,EAAEA;EAAU,CACxB,CACH,CAAC;AAEX,CAAC;AAED,OAAO,MAAMyB,cAAc,GAAGC,MAAM,CAACC,MAAM,CAACX,QAAQ,EAAE;EAAE7B;AAAoB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,50 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _files = require("../../utils/files");
|
|
13
|
-
var _commands = require("../../commands");
|
|
14
|
-
var ImageAction = exports.ImageAction = function ImageAction() {
|
|
15
|
-
var _useRichTextEditor = (0, _useRichTextEditor2.useRichTextEditor)(),
|
|
16
|
-
editor = _useRichTextEditor.editor,
|
|
17
|
-
toolbarActionPlugins = _useRichTextEditor.toolbarActionPlugins;
|
|
18
|
-
var _useState = (0, _react.useState)(),
|
|
19
|
-
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
20
|
-
imageActionPlugin = _useState2[0],
|
|
21
|
-
setImageActionPlugin = _useState2[1];
|
|
22
|
-
(0, _react.useEffect)(function () {
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import { useRichTextEditor } from "../../hooks/useRichTextEditor";
|
|
3
|
+
import { fileToImagePayload } from "../../utils/files";
|
|
4
|
+
import { INSERT_IMAGE_COMMAND } from "../../commands";
|
|
5
|
+
export const ImageAction = () => {
|
|
6
|
+
const {
|
|
7
|
+
editor,
|
|
8
|
+
toolbarActionPlugins
|
|
9
|
+
} = useRichTextEditor();
|
|
10
|
+
const [imageActionPlugin, setImageActionPlugin] = useState();
|
|
11
|
+
useEffect(() => {
|
|
23
12
|
if (!!toolbarActionPlugins?.length) {
|
|
24
|
-
|
|
25
|
-
return action.targetAction === "image-action";
|
|
26
|
-
});
|
|
13
|
+
const actionPlugin = toolbarActionPlugins.find(action => action.targetAction === "image-action");
|
|
27
14
|
setImageActionPlugin(actionPlugin);
|
|
28
15
|
}
|
|
29
16
|
}, [toolbarActionPlugins]);
|
|
30
|
-
|
|
17
|
+
const handleClick = () => {
|
|
31
18
|
if (typeof imageActionPlugin?.plugin === "function") {
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
const cb = data => {
|
|
20
|
+
const imagePayload = fileToImagePayload(data);
|
|
34
21
|
if (imagePayload) {
|
|
35
|
-
editor.dispatchCommand(
|
|
22
|
+
editor.dispatchCommand(INSERT_IMAGE_COMMAND, imagePayload);
|
|
36
23
|
}
|
|
37
24
|
};
|
|
38
25
|
imageActionPlugin.plugin(cb);
|
|
39
26
|
}
|
|
40
27
|
};
|
|
41
|
-
return /*#__PURE__*/
|
|
42
|
-
onClick:
|
|
43
|
-
return handleClick();
|
|
44
|
-
},
|
|
28
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
29
|
+
onClick: () => handleClick(),
|
|
45
30
|
className: "popup-item",
|
|
46
31
|
"aria-label": "Insert image"
|
|
47
|
-
}, /*#__PURE__*/
|
|
32
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
48
33
|
className: "icon insert-image"
|
|
49
34
|
}));
|
|
50
35
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","useEffect","useState","useRichTextEditor","fileToImagePayload","INSERT_IMAGE_COMMAND","ImageAction","editor","toolbarActionPlugins","imageActionPlugin","setImageActionPlugin","length","actionPlugin","find","action","targetAction","handleClick","plugin","cb","data","imagePayload","dispatchCommand","createElement","onClick","className"],"sources":["ImageAction.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { LexicalCommand } from \"lexical\";\nimport { useRichTextEditor } from \"~/hooks/useRichTextEditor\";\nimport { FileManagerFileItem, fileToImagePayload } from \"~/utils/files\";\nimport { ImagePayload, INSERT_IMAGE_COMMAND } from \"~/commands\";\nimport { ToolbarActionPlugin } from \"~/types\";\n\nexport const ImageAction = () => {\n const { editor, toolbarActionPlugins } = useRichTextEditor();\n const [imageActionPlugin, setImageActionPlugin] = useState<ToolbarActionPlugin | undefined>();\n\n useEffect(() => {\n if (!!toolbarActionPlugins?.length) {\n const actionPlugin = toolbarActionPlugins.find(\n action => action.targetAction === \"image-action\"\n );\n setImageActionPlugin(actionPlugin);\n }\n }, [toolbarActionPlugins]);\n\n const handleClick = () => {\n if (typeof imageActionPlugin?.plugin === \"function\") {\n const cb = (data: FileManagerFileItem) => {\n const imagePayload = fileToImagePayload(data);\n if (imagePayload) {\n editor.dispatchCommand<LexicalCommand<ImagePayload>>(\n INSERT_IMAGE_COMMAND,\n imagePayload\n );\n }\n };\n imageActionPlugin.plugin(cb);\n }\n };\n\n return (\n <button onClick={() => handleClick()} className={\"popup-item\"} aria-label=\"Insert image\">\n <i className=\"icon insert-image\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAElD,SAASC,iBAAiB;AAC1B,SAA8BC,kBAAkB;AAChD,SAAuBC,oBAAoB;AAG3C,OAAO,MAAMC,WAAW,GAAGA,CAAA,KAAM;EAC7B,MAAM;IAAEC,MAAM;IAAEC;EAAqB,CAAC,GAAGL,iBAAiB,CAAC,CAAC;EAC5D,MAAM,CAACM,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGR,QAAQ,CAAkC,CAAC;EAE7FD,SAAS,CAAC,MAAM;IACZ,IAAI,CAAC,CAACO,oBAAoB,EAAEG,MAAM,EAAE;MAChC,MAAMC,YAAY,GAAGJ,oBAAoB,CAACK,IAAI,CAC1CC,MAAM,IAAIA,MAAM,CAACC,YAAY,KAAK,cACtC,CAAC;MACDL,oBAAoB,CAACE,YAAY,CAAC;IACtC;EACJ,CAAC,EAAE,CAACJ,oBAAoB,CAAC,CAAC;EAE1B,MAAMQ,WAAW,GAAGA,CAAA,KAAM;IACtB,IAAI,OAAOP,iBAAiB,EAAEQ,MAAM,KAAK,UAAU,EAAE;MACjD,MAAMC,EAAE,GAAIC,IAAyB,IAAK;QACtC,MAAMC,YAAY,GAAGhB,kBAAkB,CAACe,IAAI,CAAC;QAC7C,IAAIC,YAAY,EAAE;UACdb,MAAM,CAACc,eAAe,CAClBhB,oBAAoB,EACpBe,YACJ,CAAC;QACL;MACJ,CAAC;MACDX,iBAAiB,CAACQ,MAAM,CAACC,EAAE,CAAC;IAChC;EACJ,CAAC;EAED,oBACIlB,KAAA,CAAAsB,aAAA;IAAQC,OAAO,EAAEA,CAAA,KAAMP,WAAW,CAAC,CAAE;IAACQ,SAAS,EAAE,YAAa;IAAC,cAAW;EAAc,gBACpFxB,KAAA,CAAAsB,aAAA;IAAGE,SAAS,EAAC;EAAmB,CAAE,CAC9B,CAAC;AAEjB,CAAC","ignoreList":[]}
|
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
editor
|
|
15
|
-
var _useCurrentSelection = (0, _useCurrentSelection2.useCurrentSelection)(),
|
|
16
|
-
rangeSelection = _useCurrentSelection.rangeSelection;
|
|
17
|
-
var isItalicSelected = rangeSelection ? rangeSelection.hasFormat("italic") : false;
|
|
18
|
-
var handleClick = function handleClick() {
|
|
19
|
-
editor.dispatchCommand(_lexical.FORMAT_TEXT_COMMAND, "italic");
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FORMAT_TEXT_COMMAND } from "lexical";
|
|
3
|
+
import { useCurrentSelection } from "../../hooks/useCurrentSelection";
|
|
4
|
+
import { useRichTextEditor } from "../../hooks";
|
|
5
|
+
export const ItalicAction = () => {
|
|
6
|
+
const {
|
|
7
|
+
editor
|
|
8
|
+
} = useRichTextEditor();
|
|
9
|
+
const {
|
|
10
|
+
rangeSelection
|
|
11
|
+
} = useCurrentSelection();
|
|
12
|
+
const isItalicSelected = rangeSelection ? rangeSelection.hasFormat("italic") : false;
|
|
13
|
+
const handleClick = () => {
|
|
14
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "italic");
|
|
20
15
|
};
|
|
21
|
-
return /*#__PURE__*/
|
|
16
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
22
17
|
onClick: handleClick,
|
|
23
18
|
className: "popup-item spaced " + (isItalicSelected ? "active" : ""),
|
|
24
19
|
"aria-label": "Format text as italic"
|
|
25
|
-
}, /*#__PURE__*/
|
|
20
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
26
21
|
className: "format italic"
|
|
27
22
|
}));
|
|
28
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","FORMAT_TEXT_COMMAND","useCurrentSelection","useRichTextEditor","ItalicAction","editor","rangeSelection","isItalicSelected","hasFormat","handleClick","dispatchCommand","createElement","onClick","className"],"sources":["ItalicAction.tsx"],"sourcesContent":["import React from \"react\";\nimport { FORMAT_TEXT_COMMAND } from \"lexical\";\nimport { useCurrentSelection } from \"~/hooks/useCurrentSelection\";\nimport { useRichTextEditor } from \"~/hooks\";\n\nexport const ItalicAction = () => {\n const { editor } = useRichTextEditor();\n const { rangeSelection } = useCurrentSelection();\n const isItalicSelected = rangeSelection ? rangeSelection.hasFormat(\"italic\") : false;\n\n const handleClick = () => {\n editor.dispatchCommand(FORMAT_TEXT_COMMAND, \"italic\");\n };\n\n return (\n <button\n onClick={handleClick}\n className={\"popup-item spaced \" + (isItalicSelected ? \"active\" : \"\")}\n aria-label=\"Format text as italic\"\n >\n <i className=\"format italic\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,mBAAmB,QAAQ,SAAS;AAC7C,SAASC,mBAAmB;AAC5B,SAASC,iBAAiB;AAE1B,OAAO,MAAMC,YAAY,GAAGA,CAAA,KAAM;EAC9B,MAAM;IAAEC;EAAO,CAAC,GAAGF,iBAAiB,CAAC,CAAC;EACtC,MAAM;IAAEG;EAAe,CAAC,GAAGJ,mBAAmB,CAAC,CAAC;EAChD,MAAMK,gBAAgB,GAAGD,cAAc,GAAGA,cAAc,CAACE,SAAS,CAAC,QAAQ,CAAC,GAAG,KAAK;EAEpF,MAAMC,WAAW,GAAGA,CAAA,KAAM;IACtBJ,MAAM,CAACK,eAAe,CAACT,mBAAmB,EAAE,QAAQ,CAAC;EACzD,CAAC;EAED,oBACID,KAAA,CAAAW,aAAA;IACIC,OAAO,EAAEH,WAAY;IACrBI,SAAS,EAAE,oBAAoB,IAAIN,gBAAgB,GAAG,QAAQ,GAAG,EAAE,CAAE;IACrE,cAAW;EAAuB,gBAElCP,KAAA,CAAAW,aAAA;IAAGE,SAAS,EAAC;EAAe,CAAE,CAC1B,CAAC;AAEjB,CAAC","ignoreList":[]}
|
|
@@ -1,40 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var LinkAction = exports.LinkAction = function LinkAction() {
|
|
14
|
-
var _useRichTextEditor = (0, _hooks.useRichTextEditor)(),
|
|
15
|
-
editor = _useRichTextEditor.editor;
|
|
16
|
-
var isLink = (0, _useCurrentSelection.useDeriveValueFromSelection)(function (_ref) {
|
|
17
|
-
var rangeSelection = _ref.rangeSelection;
|
|
1
|
+
import React, { useCallback } from "react";
|
|
2
|
+
import { $isLinkNode, TOGGLE_LINK_COMMAND } from "@webiny/lexical-nodes";
|
|
3
|
+
import { getNodeFromSelection } from "../../hooks/useCurrentElement";
|
|
4
|
+
import { useDeriveValueFromSelection } from "../../hooks/useCurrentSelection";
|
|
5
|
+
import { useRichTextEditor } from "../../hooks";
|
|
6
|
+
export const LinkAction = () => {
|
|
7
|
+
const {
|
|
8
|
+
editor
|
|
9
|
+
} = useRichTextEditor();
|
|
10
|
+
const isLink = useDeriveValueFromSelection(({
|
|
11
|
+
rangeSelection
|
|
12
|
+
}) => {
|
|
18
13
|
if (!rangeSelection) {
|
|
19
14
|
return false;
|
|
20
15
|
}
|
|
21
|
-
|
|
22
|
-
return node ?
|
|
16
|
+
const node = getNodeFromSelection(rangeSelection);
|
|
17
|
+
return node ? $isLinkNode(node) || $isLinkNode(node.getParent()) : false;
|
|
23
18
|
});
|
|
24
|
-
|
|
19
|
+
const insertLink = useCallback(() => {
|
|
25
20
|
if (!isLink) {
|
|
26
|
-
editor.dispatchCommand(
|
|
21
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, {
|
|
27
22
|
url: "https://"
|
|
28
23
|
});
|
|
29
24
|
} else {
|
|
30
|
-
editor.dispatchCommand(
|
|
25
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
31
26
|
}
|
|
32
27
|
}, [editor, isLink]);
|
|
33
|
-
return /*#__PURE__*/
|
|
28
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
34
29
|
onClick: insertLink,
|
|
35
30
|
className: "popup-item spaced " + (isLink ? "active" : ""),
|
|
36
31
|
"aria-label": "Insert link"
|
|
37
|
-
}, /*#__PURE__*/
|
|
32
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
38
33
|
className: "format link"
|
|
39
34
|
}));
|
|
40
35
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","useCallback","$isLinkNode","TOGGLE_LINK_COMMAND","getNodeFromSelection","useDeriveValueFromSelection","useRichTextEditor","LinkAction","editor","isLink","rangeSelection","node","getParent","insertLink","dispatchCommand","url","createElement","onClick","className"],"sources":["LinkAction.tsx"],"sourcesContent":["import React, { useCallback } from \"react\";\nimport { $isLinkNode, TOGGLE_LINK_COMMAND } from \"@webiny/lexical-nodes\";\nimport { getNodeFromSelection } from \"~/hooks/useCurrentElement\";\nimport { useDeriveValueFromSelection } from \"~/hooks/useCurrentSelection\";\nimport { useRichTextEditor } from \"~/hooks\";\n\nexport const LinkAction = () => {\n const { editor } = useRichTextEditor();\n const isLink = useDeriveValueFromSelection(({ rangeSelection }) => {\n if (!rangeSelection) {\n return false;\n }\n const node = getNodeFromSelection(rangeSelection);\n return node ? $isLinkNode(node) || $isLinkNode(node.getParent()) : false;\n });\n\n const insertLink = useCallback(() => {\n if (!isLink) {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, { url: \"https://\" });\n } else {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);\n }\n }, [editor, isLink]);\n\n return (\n <button\n onClick={insertLink}\n className={\"popup-item spaced \" + (isLink ? \"active\" : \"\")}\n aria-label=\"Insert link\"\n >\n <i className=\"format link\" />\n </button>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,QAAQ,OAAO;AAC1C,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,uBAAuB;AACxE,SAASC,oBAAoB;AAC7B,SAASC,2BAA2B;AACpC,SAASC,iBAAiB;AAE1B,OAAO,MAAMC,UAAU,GAAGA,CAAA,KAAM;EAC5B,MAAM;IAAEC;EAAO,CAAC,GAAGF,iBAAiB,CAAC,CAAC;EACtC,MAAMG,MAAM,GAAGJ,2BAA2B,CAAC,CAAC;IAAEK;EAAe,CAAC,KAAK;IAC/D,IAAI,CAACA,cAAc,EAAE;MACjB,OAAO,KAAK;IAChB;IACA,MAAMC,IAAI,GAAGP,oBAAoB,CAACM,cAAc,CAAC;IACjD,OAAOC,IAAI,GAAGT,WAAW,CAACS,IAAI,CAAC,IAAIT,WAAW,CAACS,IAAI,CAACC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK;EAC5E,CAAC,CAAC;EAEF,MAAMC,UAAU,GAAGZ,WAAW,CAAC,MAAM;IACjC,IAAI,CAACQ,MAAM,EAAE;MACTD,MAAM,CAACM,eAAe,CAACX,mBAAmB,EAAE;QAAEY,GAAG,EAAE;MAAW,CAAC,CAAC;IACpE,CAAC,MAAM;MACHP,MAAM,CAACM,eAAe,CAACX,mBAAmB,EAAE,IAAI,CAAC;IACrD;EACJ,CAAC,EAAE,CAACK,MAAM,EAAEC,MAAM,CAAC,CAAC;EAEpB,oBACIT,KAAA,CAAAgB,aAAA;IACIC,OAAO,EAAEJ,UAAW;IACpBK,SAAS,EAAE,oBAAoB,IAAIT,MAAM,GAAG,QAAQ,GAAG,EAAE,CAAE;IAC3D,cAAW;EAAa,gBAExBT,KAAA,CAAAgB,aAAA;IAAGE,SAAS,EAAC;EAAa,CAAE,CACxB,CAAC;AAEjB,CAAC","ignoreList":[]}
|