@webiny/lexical-editor 0.0.0-unstable.ecd8734205 → 5.35.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/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.js.map +1 -1
- package/components/AddRichTextEditorPlugin.d.ts +2 -0
- package/components/AddRichTextEditorPlugin.js +4 -2
- package/components/AddRichTextEditorPlugin.js.map +1 -1
- package/components/AddToolbarAction.js.map +1 -1
- package/components/Editor/HeadingEditor.js +2 -1
- package/components/Editor/HeadingEditor.js.map +1 -1
- package/components/Editor/ParagraphEditor.js +3 -3
- package/components/Editor/ParagraphEditor.js.map +1 -1
- package/components/Editor/RichTextEditor.d.ts +4 -1
- package/components/Editor/RichTextEditor.js +37 -6
- package/components/Editor/RichTextEditor.js.map +1 -1
- package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +9 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +17 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -0
- package/components/LexicalHtmlRenderer.d.ts +8 -1
- package/components/LexicalHtmlRenderer.js +29 -6
- package/components/LexicalHtmlRenderer.js.map +1 -1
- package/components/Toolbar/HeadingToolbar.js.map +1 -1
- package/components/Toolbar/ParagraphToolbar.js.map +1 -1
- package/components/Toolbar/Toolbar.css +9 -0
- package/components/Toolbar/Toolbar.js +25 -5
- package/components/Toolbar/Toolbar.js.map +1 -1
- package/components/ToolbarActions/BoldAction.d.ts +0 -3
- package/components/ToolbarActions/BoldAction.js +8 -3
- package/components/ToolbarActions/BoldAction.js.map +1 -1
- package/components/ToolbarActions/BulletListAction.d.ts +0 -3
- package/components/ToolbarActions/BulletListAction.js +17 -55
- package/components/ToolbarActions/BulletListAction.js.map +1 -1
- package/components/ToolbarActions/CodeHighlightAction.d.ts +0 -4
- package/components/ToolbarActions/CodeHighlightAction.js +8 -4
- package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
- 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.js +0 -3
- package/components/ToolbarActions/FontSizeAction.js.map +1 -1
- package/components/ToolbarActions/ItalicAction.d.ts +0 -3
- package/components/ToolbarActions/ItalicAction.js +8 -3
- package/components/ToolbarActions/ItalicAction.js.map +1 -1
- package/components/ToolbarActions/LinkAction.d.ts +0 -5
- package/components/ToolbarActions/LinkAction.js +0 -5
- package/components/ToolbarActions/LinkAction.js.map +1 -1
- package/components/ToolbarActions/NumberedListAction.d.ts +0 -3
- package/components/ToolbarActions/NumberedListAction.js +17 -53
- package/components/ToolbarActions/NumberedListAction.js.map +1 -1
- package/components/ToolbarActions/QuoteAction.d.ts +0 -2
- package/components/ToolbarActions/QuoteAction.js +16 -29
- package/components/ToolbarActions/QuoteAction.js.map +1 -1
- package/components/ToolbarActions/TypographyAction.d.ts +11 -0
- package/components/ToolbarActions/TypographyAction.js +118 -0
- package/components/ToolbarActions/TypographyAction.js.map +1 -0
- package/components/ToolbarActions/UnderlineAction.d.ts +0 -3
- package/components/ToolbarActions/UnderlineAction.js +8 -3
- package/components/ToolbarActions/UnderlineAction.js.map +1 -1
- package/components/ToolbarPresets/HeadingToolbarPreset.js +8 -0
- package/components/ToolbarPresets/HeadingToolbarPreset.js.map +1 -1
- package/components/ToolbarPresets/ParagraphToolbarPreset.js +8 -0
- package/components/ToolbarPresets/ParagraphToolbarPreset.js.map +1 -1
- 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 +10 -0
- package/context/RichTextEditorContext.js +28 -1
- package/context/RichTextEditorContext.js.map +1 -1
- package/context/SharedHistoryContext.d.ts +11 -0
- package/context/SharedHistoryContext.js +26 -0
- package/context/SharedHistoryContext.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/useRichTextEditor.js.map +1 -1
- package/hooks/useTypographyAction.d.ts +1 -0
- package/hooks/useTypographyAction.js +15 -0
- package/hooks/useTypographyAction.js.map +1 -0
- package/hooks/useWebinyList.d.ts +2 -0
- package/hooks/useWebinyList.js +39 -0
- package/hooks/useWebinyList.js.map +1 -0
- package/hooks/useWebinyQuote.d.ts +2 -0
- package/hooks/useWebinyQuote.js +20 -0
- package/hooks/useWebinyQuote.js.map +1 -0
- package/images/icons/font-color.svg +1 -0
- package/index.d.ts +7 -1
- package/index.js +44 -2
- package/index.js.map +1 -1
- package/nodes/FontColorNode.d.ts +43 -0
- package/nodes/FontColorNode.js +127 -0
- package/nodes/FontColorNode.js.map +1 -0
- package/nodes/TypographyElementNode.d.ts +42 -0
- package/nodes/TypographyElementNode.js +154 -0
- package/nodes/TypographyElementNode.js.map +1 -0
- package/nodes/WebinyQuoteNode.d.ts +29 -0
- package/nodes/WebinyQuoteNode.js +148 -0
- package/nodes/WebinyQuoteNode.js.map +1 -0
- package/nodes/list-node/WebinyListItemNode.d.ts +46 -0
- package/nodes/list-node/WebinyListItemNode.js +441 -0
- package/nodes/list-node/WebinyListItemNode.js.map +1 -0
- package/nodes/list-node/WebinyListNode.d.ts +38 -0
- package/nodes/list-node/WebinyListNode.js +253 -0
- package/nodes/list-node/WebinyListNode.js.map +1 -0
- package/nodes/list-node/formatList.d.ts +12 -0
- package/nodes/list-node/formatList.js +423 -0
- package/nodes/list-node/formatList.js.map +1 -0
- package/nodes/webinyNodes.d.ts +6 -1
- package/nodes/webinyNodes.js +8 -2
- package/nodes/webinyNodes.js.map +1 -1
- package/package.json +9 -6
- package/plugins/AutoLinkPlugin/AutoLinkPlugin.js.map +1 -1
- package/plugins/AutoLinkPlugin/index.js.map +1 -1
- package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
- package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.js.map +1 -1
- package/plugins/ClickableLinkPlugin/index.js.map +1 -1
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
- package/plugins/FontColorPlugin/FontColorPlugin.d.ts +2 -0
- package/plugins/FontColorPlugin/FontColorPlugin.js +38 -0
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -0
- package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js.map +1 -1
- package/plugins/LexicalUpdateStatePlugin/index.js.map +1 -1
- package/plugins/TypographyPlugin/TypographyPlugin.d.ts +2 -0
- package/plugins/TypographyPlugin/TypographyPlugin.js +31 -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 +0 -2
- package/themes/webinyLexicalTheme.d.ts +7 -8
- package/themes/webinyLexicalTheme.js +7 -27
- package/themes/webinyLexicalTheme.js.map +1 -1
- package/types.d.ts +59 -0
- package/types.js +8 -1
- package/types.js.map +1 -1
- package/ui/Divider.js.map +1 -1
- package/ui/DropDown.d.ts +2 -1
- package/ui/DropDown.js +7 -2
- package/ui/DropDown.js.map +1 -1
- package/ui/LinkPreview.js.map +1 -1
- package/ui/Placeholder.js.map +1 -1
- package/ui/TextInput.js.map +1 -1
- package/ui/ToolbarActionDialog.d.ts +12 -0
- package/ui/ToolbarActionDialog.js +106 -0
- package/ui/ToolbarActionDialog.js.map +1 -0
- package/utils/generateInitialLexicalValue.js.map +1 -1
- package/utils/getDOMRangeRect.js.map +1 -1
- package/utils/getLexicalTextSelectionState.d.ts +5 -0
- package/utils/getLexicalTextSelectionState.js +141 -0
- package/utils/getLexicalTextSelectionState.js.map +1 -0
- package/utils/getSelectedNode.js.map +1 -1
- package/utils/isValidJSON.js.map +1 -1
- package/utils/isValidLexicalData.js.map +1 -1
- 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/formatToParagraph.d.ts +2 -0
- package/utils/nodes/formatToParagraph.js +19 -0
- package/utils/nodes/formatToParagraph.js.map +1 -0
- package/utils/nodes/formatToQuote.d.ts +2 -0
- package/utils/nodes/formatToQuote.js +20 -0
- package/utils/nodes/formatToQuote.js.map +1 -0
- package/utils/nodes/list-node.d.ts +11 -0
- package/utils/nodes/list-node.js +107 -0
- package/utils/nodes/list-node.js.map +1 -0
- package/utils/point.js.map +1 -1
- package/utils/rect.js.map +1 -1
- package/utils/sanitizeUrl.js.map +1 -1
- package/utils/setFloatingElemPosition.js.map +1 -1
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["ClickableLinkPlugin","filter","newTab","useLexicalComposerContext","editor","useEffect","onClick","e","event","linkDomNode","getLinkDomNode","href","getAttribute","undefined","selection","getEditorState","read","$getSelection","$isRangeSelection","isCollapsed","linkNode","update","maybeLinkNode","$getNearestNodeFromDOMNode","$isLinkNode","window","open","metaKey","ctrlKey","registerRootListener","rootElement","prevRootElement","removeEventListener","addEventListener","isLinkDomNode","domNode","nodeName","toLowerCase","target","parentNode"],"sources":["ClickableLinkPlugin.tsx"],"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 */\n\nimport type { LinkNode } from \"@lexical/link\";\nimport type { LexicalEditor } from \"lexical\";\n\nimport { $isLinkNode } from \"@lexical/link\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { $getNearestNodeFromDOMNode, $getSelection, $isRangeSelection } from \"lexical\";\nimport { useEffect } from \"react\";\n\ntype LinkFilter = (event: MouseEvent, linkNode: LinkNode) => boolean;\n\nexport function ClickableLinkPlugin({\n filter,\n newTab = true\n}: {\n filter?: LinkFilter;\n newTab?: boolean;\n}): JSX.Element | null {\n const [editor] = useLexicalComposerContext();\n useEffect(() => {\n function onClick(e: Event) {\n const event = e as MouseEvent;\n const linkDomNode = getLinkDomNode(event, editor);\n\n if (linkDomNode === null) {\n return;\n }\n\n const href = linkDomNode.getAttribute(\"href\");\n\n if (linkDomNode.getAttribute(\"contenteditable\") === \"false\" || href === undefined) {\n return;\n }\n\n // Allow user to select link text without following url\n const selection = editor.getEditorState().read($getSelection);\n if ($isRangeSelection(selection) && !selection.isCollapsed()) {\n return;\n }\n\n let linkNode = null;\n editor.update(() => {\n const maybeLinkNode = $getNearestNodeFromDOMNode(linkDomNode);\n\n if ($isLinkNode(maybeLinkNode)) {\n linkNode = maybeLinkNode;\n }\n });\n\n if (linkNode === null || (filter !== undefined && !filter(event, linkNode))) {\n return;\n }\n\n try {\n if (href !== null) {\n window.open(\n href,\n newTab || event.metaKey || event.ctrlKey ? \"_blank\" : \"_self\"\n );\n }\n } catch {\n // It didn't work, which is better than throwing an exception!\n }\n }\n\n return editor.registerRootListener(\n (rootElement: null | HTMLElement, prevRootElement: null | HTMLElement) => {\n if (prevRootElement !== null) {\n prevRootElement.removeEventListener(\"click\", onClick);\n }\n\n if (rootElement !== null) {\n rootElement.addEventListener(\"click\", onClick);\n }\n }\n );\n }, [editor, filter, newTab]);\n return null;\n}\n\nfunction isLinkDomNode(domNode: Node): boolean {\n return domNode.nodeName.toLowerCase() === \"a\";\n}\n\nfunction getLinkDomNode(event: MouseEvent, editor: LexicalEditor): HTMLAnchorElement | null {\n return editor.getEditorState().read(() => {\n const domNode = event.target as Node;\n\n if (isLinkDomNode(domNode)) {\n return domNode as HTMLAnchorElement;\n }\n\n if (domNode.parentNode && isLinkDomNode(domNode.parentNode)) {\n return domNode.parentNode as HTMLAnchorElement;\n }\n\n return null;\n });\n}\n"],"mappings":";;;;;;;;AAWA;AACA;AACA;AACA;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYO,SAASA,mBAAmB,OAMZ;EAAA,IALnBC,MAAM,QAANA,MAAM;IAAA,mBACNC,MAAM;IAANA,MAAM,4BAAG,IAAI;EAKb,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,IAAAC,gBAAS,EAAC,YAAM;IACZ,SAASC,OAAO,CAACC,CAAQ,EAAE;MACvB,IAAMC,KAAK,GAAGD,CAAe;MAC7B,IAAME,WAAW,GAAGC,cAAc,CAACF,KAAK,EAAEJ,MAAM,CAAC;MAEjD,IAAIK,WAAW,KAAK,IAAI,EAAE;QACtB;MACJ;MAEA,IAAME,IAAI,GAAGF,WAAW,CAACG,YAAY,CAAC,MAAM,CAAC;MAE7C,IAAIH,WAAW,CAACG,YAAY,CAAC,iBAAiB,CAAC,KAAK,OAAO,IAAID,IAAI,KAAK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C,OAAa,EAAW;EAC3C,OAAOA,OAAO,CAACC,QAAQ,CAACC,WAAW,EAAE,KAAK,GAAG;AACjD;AAEA,SAAS3B,cAAc,CAACF,KAAiB,EAAEJ,MAAqB,EAA4B;EACxF,OAAOA,MAAM,CAACW,cAAc,EAAE,CAACC,IAAI,CAAC,YAAM;IACtC,IAAMmB,OAAO,GAAG3B,KAAK,CAAC8B,MAAc;IAEpC,IAAIJ,aAAa,CAACC,OAAO,CAAC,EAAE;MACxB,OAAOA,OAAO;IAClB;IAEA,IAAIA,OAAO,CAACI,UAAU,IAAIL,aAAa,CAACC,OAAO,CAACI,UAAU,CAAC,EAAE;MACzD,OAAOJ,OAAO,CAACI,UAAU;IAC7B;IAEA,OAAO,IAAI;EACf,CAAC,CAAC;AACN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./ClickableLinkPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["CodeHighlightPlugin","useLexicalComposerContext","editor","useEffect","registerCodeHighlighting"],"sources":["CodeHighlightPlugin.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { registerCodeHighlighting } from \"@lexical/code\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\n\nexport function CodeHighlightPlugin() {\n const [editor] = useLexicalComposerContext();\n useEffect(() => {\n return registerCodeHighlighting(editor);\n }, [editor]);\n return null;\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AAEO,SAASA,mBAAmB,GAAG;EAClC,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,IAAAC,gBAAS,EAAC,YAAM;IACZ,OAAO,IAAAC,8BAAwB,EAACF,MAAM,CAAC;EAC3C,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EACZ,OAAO,IAAI;AACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./CodeHighlightPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_link","_LexicalComposerContext","_utils","_lexical","_reactDom","_LinkPreview","_getSelectedNode","_sanitizeUrl","_setFloatingElemPosition","FloatingLinkEditor","_ref","editor","anchorElem","editorRef","useRef","inputRef","_useState","useState","_useState2","_slicedToArray2","default","linkUrl","setLinkUrl","_useState3","_useState4","isEditMode","setEditMode","_useState5","_useState6","lastSelection","setLastSelection","updateLinkEditor","useCallback","selection","$getSelection","$isRangeSelection","node","getSelectedNode","parent","getParent","$isLinkNode","getURL","editorElem","current","nativeSelection","window","getSelection","activeElement","document","rootElement","getRootElement","contains","anchorNode","domRange","getRangeAt","rect","inner","firstElementChild","getBoundingClientRect","setFloatingElemPosition","className","removeLink","dispatchCommand","TOGGLE_LINK_COMMAND","useEffect","scrollerElem","parentElement","update","getEditorState","read","addEventListener","removeEventListener","mergeRegister","registerUpdateListener","_ref2","editorState","registerCommand","SELECTION_CHANGE_COMMAND","COMMAND_PRIORITY_LOW","focus","createElement","ref","value","onChange","event","target","onKeyDown","key","preventDefault","sanitizeUrl","Fragment","href","rel","role","tabIndex","onMouseDown","onClick","LinkPreview","url","useFloatingLinkEditorToolbar","_useState7","_useState8","activeEditor","setActiveEditor","_useState9","_useState10","isLink","setIsLink","updateToolbar","linkParent","$findMatchingParent","autoLinkParent","$isAutoLinkNode","_payload","newEditor","COMMAND_PRIORITY_CRITICAL","createPortal","FloatingLinkEditorPlugin","_ref3","_ref3$anchorElem","body","_useLexicalComposerCo","useLexicalComposerContext","_useLexicalComposerCo2"],"sources":["FloatingLinkEditorPlugin.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport \"./FloatingLinkEditorPlugin.css\";\nimport { $isAutoLinkNode, $isLinkNode, TOGGLE_LINK_COMMAND } from \"@lexical/link\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { $findMatchingParent, mergeRegister } from \"@lexical/utils\";\nimport {\n $getSelection,\n $isRangeSelection,\n COMMAND_PRIORITY_CRITICAL,\n COMMAND_PRIORITY_LOW,\n GridSelection,\n LexicalEditor,\n NodeSelection,\n RangeSelection,\n SELECTION_CHANGE_COMMAND\n} from \"lexical\";\n\nimport { createPortal } from \"react-dom\";\nimport { LinkPreview } from \"../../ui/LinkPreview\";\nimport { getSelectedNode } from \"../../utils/getSelectedNode\";\nimport { sanitizeUrl } from \"../../utils/sanitizeUrl\";\nimport { setFloatingElemPosition } from \"../../utils/setFloatingElemPosition\";\n\nfunction FloatingLinkEditor({\n editor,\n anchorElem\n}: {\n editor: LexicalEditor;\n anchorElem: HTMLElement;\n}): JSX.Element {\n const editorRef = useRef<HTMLDivElement | null>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const [linkUrl, setLinkUrl] = useState(\"\");\n const [isEditMode, setEditMode] = useState(false);\n const [lastSelection, setLastSelection] = useState<\n RangeSelection | GridSelection | NodeSelection | null\n >(null);\n\n const updateLinkEditor = useCallback(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n const node = getSelectedNode(selection);\n const parent = node.getParent();\n if ($isLinkNode(parent)) {\n setLinkUrl(parent.getURL());\n } else if ($isLinkNode(node)) {\n setLinkUrl(node.getURL());\n } else {\n setLinkUrl(\"\");\n }\n }\n const editorElem = editorRef.current;\n const nativeSelection = window.getSelection();\n const activeElement = document.activeElement;\n\n if (editorElem === null) {\n return;\n }\n\n const rootElement = editor.getRootElement();\n\n if (\n selection !== null &&\n nativeSelection !== null &&\n rootElement !== null &&\n rootElement.contains(nativeSelection.anchorNode)\n ) {\n const domRange = nativeSelection.getRangeAt(0);\n let rect;\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 setFloatingElemPosition(rect, editorElem, anchorElem);\n setLastSelection(selection);\n } else if (!activeElement || activeElement.className !== \"link-input\") {\n if (rootElement !== null) {\n setFloatingElemPosition(null, editorElem, anchorElem);\n }\n setLastSelection(null);\n setEditMode(false);\n setLinkUrl(\"\");\n }\n\n return true;\n }, [anchorElem, editor]);\n\n const removeLink = () => {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);\n setEditMode(false);\n };\n\n useEffect(() => {\n const scrollerElem = anchorElem.parentElement;\n\n const update = () => {\n editor.getEditorState().read(() => {\n updateLinkEditor();\n });\n };\n\n window.addEventListener(\"resize\", update);\n\n if (scrollerElem) {\n scrollerElem.addEventListener(\"scroll\", update);\n }\n\n return () => {\n window.removeEventListener(\"resize\", update);\n\n if (scrollerElem) {\n scrollerElem.removeEventListener(\"scroll\", update);\n }\n };\n }, [anchorElem.parentElement, editor, updateLinkEditor]);\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n updateLinkEditor();\n });\n }),\n\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n () => {\n updateLinkEditor();\n return true;\n },\n COMMAND_PRIORITY_LOW\n )\n );\n }, [editor, updateLinkEditor]);\n\n useEffect(() => {\n editor.getEditorState().read(() => {\n updateLinkEditor();\n });\n }, [editor, updateLinkEditor]);\n\n useEffect(() => {\n if (isEditMode && inputRef.current) {\n inputRef.current.focus();\n }\n }, [isEditMode]);\n\n return (\n <div ref={editorRef} className=\"link-editor\">\n {isEditMode ? (\n <input\n ref={inputRef}\n className=\"link-input\"\n value={linkUrl}\n onChange={event => {\n setLinkUrl(event.target.value);\n }}\n onKeyDown={event => {\n if (event.key === \"Enter\") {\n event.preventDefault();\n if (lastSelection !== null) {\n if (linkUrl !== \"\") {\n editor.dispatchCommand(\n TOGGLE_LINK_COMMAND,\n sanitizeUrl(linkUrl)\n );\n }\n setEditMode(false);\n }\n } else if (event.key === \"Escape\") {\n event.preventDefault();\n setEditMode(false);\n }\n }}\n />\n ) : (\n <>\n <div className=\"link-input\">\n <a href={linkUrl} target=\"_blank\" rel=\"noopener noreferrer\">\n {linkUrl}\n </a>\n <div\n className=\"link-edit\"\n role=\"button\"\n tabIndex={0}\n onMouseDown={event => event.preventDefault()}\n onClick={() => {\n setEditMode(true);\n }}\n />\n <div\n className=\"link-unlink\"\n role=\"button\"\n tabIndex={0}\n onMouseDown={event => event.preventDefault()}\n onClick={() => {\n removeLink();\n }}\n />\n </div>\n <LinkPreview url={linkUrl} />\n </>\n )}\n </div>\n );\n}\n\nfunction useFloatingLinkEditorToolbar(\n editor: LexicalEditor,\n anchorElem: HTMLElement\n): JSX.Element | null {\n const [activeEditor, setActiveEditor] = useState(editor);\n const [isLink, setIsLink] = useState(false);\n\n const updateToolbar = useCallback(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n const node = getSelectedNode(selection);\n const linkParent = $findMatchingParent(node, $isLinkNode);\n const autoLinkParent = $findMatchingParent(node, $isAutoLinkNode);\n\n // We don't want this menu to open for auto links.\n if (linkParent != null && autoLinkParent == null) {\n setIsLink(true);\n } else {\n setIsLink(false);\n }\n }\n }, []);\n\n useEffect(() => {\n return editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n (_payload, newEditor) => {\n updateToolbar();\n setActiveEditor(newEditor);\n return false;\n },\n COMMAND_PRIORITY_CRITICAL\n );\n }, [editor, updateToolbar]);\n\n return isLink\n ? createPortal(\n <FloatingLinkEditor editor={activeEditor} anchorElem={anchorElem} />,\n anchorElem\n )\n : null;\n}\n\nexport function FloatingLinkEditorPlugin({\n anchorElem = document.body\n}: {\n anchorElem?: HTMLElement;\n}): JSX.Element | null {\n const [editor] = useLexicalComposerContext();\n return useFloatingLinkEditorToolbar(editor, anchorElem);\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACAA,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,uBAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAYA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AACA,IAAAO,gBAAA,GAAAP,OAAA;AACA,IAAAQ,YAAA,GAAAR,OAAA;AACA,IAAAS,wBAAA,GAAAT,OAAA;AAEA,SAASU,kBAAkBA,CAAAC,IAAA,EAMX;EAAA,IALZC,MAAM,GAAAD,IAAA,CAANC,MAAM;IACNC,UAAU,GAAAF,IAAA,CAAVE,UAAU;EAKV,IAAMC,SAAS,GAAG,IAAAC,aAAM,EAAwB,IAAI,CAAC;EACrD,IAAMC,QAAQ,GAAG,IAAAD,aAAM,EAAmB,IAAI,CAAC;EAC/C,IAAAE,SAAA,GAA8B,IAAAC,eAAQ,EAAC,EAAE,CAAC;IAAAC,UAAA,OAAAC,eAAA,CAAAC,OAAA,EAAAJ,SAAA;IAAnCK,OAAO,GAAAH,UAAA;IAAEI,UAAU,GAAAJ,UAAA;EAC1B,IAAAK,UAAA,GAAkC,IAAAN,eAAQ,EAAC,KAAK,CAAC;IAAAO,UAAA,OAAAL,eAAA,CAAAC,OAAA,EAAAG,UAAA;IAA1CE,UAAU,GAAAD,UAAA;IAAEE,WAAW,GAAAF,UAAA;EAC9B,IAAAG,UAAA,GAA0C,IAAAV,eAAQ,EAEhD,IAAI,CAAC;IAAAW,UAAA,OAAAT,eAAA,CAAAC,OAAA,EAAAO,UAAA;IAFAE,aAAa,GAAAD,UAAA;IAAEE,gBAAgB,GAAAF,UAAA;EAItC,IAAM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C,IAAI,CAAC;MACnB,CAAC,MAAM;QACHA,SAAS,CAAC,KAAK,CAAC;MACpB;IACJ;EACJ,CAAC,EAAE,EAAE,CAAC;EAEN,IAAA3C,gBAAS,EAAC,YAAM;IACZ,OAAOrD,MAAM,CAACiE,eAAe,CACzBC,iCAAwB,EACxB,UAACoC,QAAQ,EAAEC,SAAS,EAAK;MACrBN,aAAa,EAAE;MACfL,eAAe,CAACW,SAAS,CAAC;MAC1B,OAAO,KAAK;IAChB,CAAC,EACDC,kCAAyB,CAC5B;EACL,CAAC,EAAE,CAACxG,MAAM,EAAEiG,aAAa,CAAC,CAAC;EAE3B,OAAOF,MAAM,gBACP,IAAAU,sBAAY,gBACRvH,MAAA,CAAAuB,OAAA,CAAA4D,aAAA,CAACvE,kBAAkB;IAACE,MAAM,EAAE2F,YAAa;IAAC1F,UAAU,EAAEA;EAAW,EAAG,EACpEA,UAAU,CACb,GACD,IAAI;AACd;AAEO,SAASyG,wBAAwBA,CAAAC,KAAA,EAIjB;EAAA,IAAAC,gBAAA,GAAAD,KAAA,CAHnB1G,UAAU;IAAVA,UAAU,GAAA2G,gBAAA,cAAGvE,QAAQ,CAACwE,IAAI,GAAAD,gBAAA;EAI1B,IAAAE,qBAAA,GAAiB,IAAAC,iDAAyB,GAAE;IAAAC,sBAAA,OAAAxG,eAAA,CAAAC,OAAA,EAAAqG,qBAAA;IAArC9G,MAAM,GAAAgH,sBAAA;EACb,OAAOxB,4BAA4B,CAACxF,MAAM,EAAEC,UAAU,CAAC;AAC3D"}
|
|
1
|
+
{"version":3,"names":["FloatingLinkEditor","editor","anchorElem","editorRef","useRef","inputRef","useState","linkUrl","setLinkUrl","isEditMode","setEditMode","lastSelection","setLastSelection","updateLinkEditor","useCallback","selection","$getSelection","$isRangeSelection","node","getSelectedNode","parent","getParent","$isLinkNode","getURL","editorElem","current","nativeSelection","window","getSelection","activeElement","document","rootElement","getRootElement","contains","anchorNode","domRange","getRangeAt","rect","inner","firstElementChild","getBoundingClientRect","setFloatingElemPosition","className","removeLink","dispatchCommand","TOGGLE_LINK_COMMAND","useEffect","scrollerElem","parentElement","update","getEditorState","read","addEventListener","removeEventListener","mergeRegister","registerUpdateListener","editorState","registerCommand","SELECTION_CHANGE_COMMAND","COMMAND_PRIORITY_LOW","focus","event","target","value","key","preventDefault","sanitizeUrl","useFloatingLinkEditorToolbar","activeEditor","setActiveEditor","isLink","setIsLink","updateToolbar","linkParent","$findMatchingParent","autoLinkParent","$isAutoLinkNode","_payload","newEditor","COMMAND_PRIORITY_CRITICAL","createPortal","FloatingLinkEditorPlugin","body","useLexicalComposerContext"],"sources":["FloatingLinkEditorPlugin.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport \"./FloatingLinkEditorPlugin.css\";\nimport { $isAutoLinkNode, $isLinkNode, TOGGLE_LINK_COMMAND } from \"@lexical/link\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { $findMatchingParent, mergeRegister } from \"@lexical/utils\";\nimport {\n $getSelection,\n $isRangeSelection,\n COMMAND_PRIORITY_CRITICAL,\n COMMAND_PRIORITY_LOW,\n GridSelection,\n LexicalEditor,\n NodeSelection,\n RangeSelection,\n SELECTION_CHANGE_COMMAND\n} from \"lexical\";\n\nimport { createPortal } from \"react-dom\";\nimport { LinkPreview } from \"../../ui/LinkPreview\";\nimport { getSelectedNode } from \"../../utils/getSelectedNode\";\nimport { sanitizeUrl } from \"../../utils/sanitizeUrl\";\nimport { setFloatingElemPosition } from \"../../utils/setFloatingElemPosition\";\n\nfunction FloatingLinkEditor({\n editor,\n anchorElem\n}: {\n editor: LexicalEditor;\n anchorElem: HTMLElement;\n}): JSX.Element {\n const editorRef = useRef<HTMLDivElement | null>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const [linkUrl, setLinkUrl] = useState(\"\");\n const [isEditMode, setEditMode] = useState(false);\n const [lastSelection, setLastSelection] = useState<\n RangeSelection | GridSelection | NodeSelection | null\n >(null);\n\n const updateLinkEditor = useCallback(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n const node = getSelectedNode(selection);\n const parent = node.getParent();\n if ($isLinkNode(parent)) {\n setLinkUrl(parent.getURL());\n } else if ($isLinkNode(node)) {\n setLinkUrl(node.getURL());\n } else {\n setLinkUrl(\"\");\n }\n }\n const editorElem = editorRef.current;\n const nativeSelection = window.getSelection();\n const activeElement = document.activeElement;\n\n if (editorElem === null) {\n return;\n }\n\n const rootElement = editor.getRootElement();\n\n if (\n selection !== null &&\n nativeSelection !== null &&\n rootElement !== null &&\n rootElement.contains(nativeSelection.anchorNode)\n ) {\n const domRange = nativeSelection.getRangeAt(0);\n let rect;\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 setFloatingElemPosition(rect, editorElem, anchorElem);\n setLastSelection(selection);\n } else if (!activeElement || activeElement.className !== \"link-input\") {\n if (rootElement !== null) {\n setFloatingElemPosition(null, editorElem, anchorElem);\n }\n setLastSelection(null);\n setEditMode(false);\n setLinkUrl(\"\");\n }\n\n return true;\n }, [anchorElem, editor]);\n\n const removeLink = () => {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);\n setEditMode(false);\n };\n\n useEffect(() => {\n const scrollerElem = anchorElem.parentElement;\n\n const update = () => {\n editor.getEditorState().read(() => {\n updateLinkEditor();\n });\n };\n\n window.addEventListener(\"resize\", update);\n\n if (scrollerElem) {\n scrollerElem.addEventListener(\"scroll\", update);\n }\n\n return () => {\n window.removeEventListener(\"resize\", update);\n\n if (scrollerElem) {\n scrollerElem.removeEventListener(\"scroll\", update);\n }\n };\n }, [anchorElem.parentElement, editor, updateLinkEditor]);\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n updateLinkEditor();\n });\n }),\n\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n () => {\n updateLinkEditor();\n return true;\n },\n COMMAND_PRIORITY_LOW\n )\n );\n }, [editor, updateLinkEditor]);\n\n useEffect(() => {\n editor.getEditorState().read(() => {\n updateLinkEditor();\n });\n }, [editor, updateLinkEditor]);\n\n useEffect(() => {\n if (isEditMode && inputRef.current) {\n inputRef.current.focus();\n }\n }, [isEditMode]);\n\n return (\n <div ref={editorRef} className=\"link-editor\">\n {isEditMode ? (\n <input\n ref={inputRef}\n className=\"link-input\"\n value={linkUrl}\n onChange={event => {\n setLinkUrl(event.target.value);\n }}\n onKeyDown={event => {\n if (event.key === \"Enter\") {\n event.preventDefault();\n if (lastSelection !== null) {\n if (linkUrl !== \"\") {\n editor.dispatchCommand(\n TOGGLE_LINK_COMMAND,\n sanitizeUrl(linkUrl)\n );\n }\n setEditMode(false);\n }\n } else if (event.key === \"Escape\") {\n event.preventDefault();\n setEditMode(false);\n }\n }}\n />\n ) : (\n <>\n <div className=\"link-input\">\n <a href={linkUrl} target=\"_blank\" rel=\"noopener noreferrer\">\n {linkUrl}\n </a>\n <div\n className=\"link-edit\"\n role=\"button\"\n tabIndex={0}\n onMouseDown={event => event.preventDefault()}\n onClick={() => {\n setEditMode(true);\n }}\n />\n <div\n className=\"link-unlink\"\n role=\"button\"\n tabIndex={0}\n onMouseDown={event => event.preventDefault()}\n onClick={() => {\n removeLink();\n }}\n />\n </div>\n <LinkPreview url={linkUrl} />\n </>\n )}\n </div>\n );\n}\n\nfunction useFloatingLinkEditorToolbar(\n editor: LexicalEditor,\n anchorElem: HTMLElement\n): JSX.Element | null {\n const [activeEditor, setActiveEditor] = useState(editor);\n const [isLink, setIsLink] = useState(false);\n\n const updateToolbar = useCallback(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n const node = getSelectedNode(selection);\n const linkParent = $findMatchingParent(node, $isLinkNode);\n const autoLinkParent = $findMatchingParent(node, $isAutoLinkNode);\n\n // We don't want this menu to open for auto links.\n if (linkParent != null && autoLinkParent == null) {\n setIsLink(true);\n } else {\n setIsLink(false);\n }\n }\n }, []);\n\n useEffect(() => {\n return editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n (_payload, newEditor) => {\n updateToolbar();\n setActiveEditor(newEditor);\n return false;\n },\n COMMAND_PRIORITY_CRITICAL\n );\n }, [editor, updateToolbar]);\n\n return isLink\n ? createPortal(\n <FloatingLinkEditor editor={activeEditor} anchorElem={anchorElem} />,\n anchorElem\n )\n : null;\n}\n\nexport function FloatingLinkEditorPlugin({\n anchorElem = document.body\n}: {\n anchorElem?: HTMLElement;\n}): JSX.Element | null {\n const [editor] = useLexicalComposerContext();\n return useFloatingLinkEditorToolbar(editor, anchorElem);\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAYA;AACA;AACA;AACA;AACA;AAEA,SAASA,kBAAkB,OAMX;EAAA,IALZC,MAAM,QAANA,MAAM;IACNC,UAAU,QAAVA,UAAU;EAKV,IAAMC,SAAS,GAAG,IAAAC,aAAM,EAAwB,IAAI,CAAC;EACrD,IAAMC,QAAQ,GAAG,IAAAD,aAAM,EAAmB,IAAI,CAAC;EAC/C,gBAA8B,IAAAE,eAAQ,EAAC,EAAE,CAAC;IAAA;IAAnCC,OAAO;IAAEC,UAAU;EAC1B,iBAAkC,IAAAF,eAAQ,EAAC,KAAK,CAAC;IAAA;IAA1CG,UAAU;IAAEC,WAAW;EAC9B,iBAA0C,IAAAJ,eAAQ,EAEhD,IAAI,CAAC;IAAA;IAFAK,aAAa;IAAEC,gBAAgB;EAItC,IAAMC,gBAAgB,GAAG,IAAAC,kBAAW,EAAC,YAAM;IACvC,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;IACjC,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,EAAE;MAC9B,IAAMG,IAAI,GAAG,IAAAC,gCAAe,EAACJ,SAAS,CAAC;MACvC,IAAMK,MAAM,GAAGF,IAAI,CAACG,SAAS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AAS,CAAC,EAAE;MAC9B,IAAMG,IAAI,GAAG,IAAAC,gCAAe,EAACJ,SAAS,CAAC;MACvC,IAAM0D,UAAU,GAAG,IAAAC,0BAAmB,EAACxD,IAAI,EAAEI,iBAAW,CAAC;MACzD,IAAMqD,cAAc,GAAG,IAAAD,0BAAmB,EAACxD,IAAI,EAAE0D,qBAAe,CAAC;;MAEjE;MACA,IAAIH,UAAU,IAAI,IAAI,IAAIE,cAAc,IAAI,IAAI,EAAE;QAC9CJ,SAAS,CAAC,IAAI,CAAC;MACnB,CAAC,MAAM;QACHA,SAAS,CAAC,KAAK,CAAC;MACpB;IACJ;EACJ,CAAC,EAAE,EAAE,CAAC;EAEN,IAAAzB,gBAAS,EAAC,YAAM;IACZ,OAAO7C,MAAM,CAACwD,eAAe,CACzBC,iCAAwB,EACxB,UAACmB,QAAQ,EAAEC,SAAS,EAAK;MACrBN,aAAa,EAAE;MACfH,eAAe,CAACS,SAAS,CAAC;MAC1B,OAAO,KAAK;IAChB,CAAC,EACDC,kCAAyB,CAC5B;EACL,CAAC,EAAE,CAAC9E,MAAM,EAAEuE,aAAa,CAAC,CAAC;EAE3B,OAAOF,MAAM,gBACP,IAAAU,sBAAY,gBACR,6BAAC,kBAAkB;IAAC,MAAM,EAAEZ,YAAa;IAAC,UAAU,EAAElE;EAAW,EAAG,EACpEA,UAAU,CACb,GACD,IAAI;AACd;AAEO,SAAS+E,wBAAwB,QAIjB;EAAA,6BAHnB/E,UAAU;IAAVA,UAAU,iCAAG4B,QAAQ,CAACoD,IAAI;EAI1B,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArClF,MAAM;EACb,OAAOkE,4BAA4B,CAAClE,MAAM,EAAEC,UAAU,CAAC;AAC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./FloatingLinkEditorPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.FontColorPlugin = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
11
|
+
var _FontColorNode = require("../../nodes/FontColorNode");
|
|
12
|
+
var _lexical = require("lexical");
|
|
13
|
+
var _utils = require("@lexical/utils");
|
|
14
|
+
var FontColorPlugin = function FontColorPlugin() {
|
|
15
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
16
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
17
|
+
editor = _useLexicalComposerCo2[0];
|
|
18
|
+
(0, _react.useEffect)(function () {
|
|
19
|
+
return editor.registerCommand(_FontColorNode.ADD_FONT_COLOR_COMMAND, function (payload) {
|
|
20
|
+
editor.update(function () {
|
|
21
|
+
var color = payload.color,
|
|
22
|
+
themeColorName = payload.themeColorName;
|
|
23
|
+
var selection = (0, _lexical.$getSelection)();
|
|
24
|
+
if ((0, _lexical.$isRangeSelection)(selection)) {
|
|
25
|
+
var fontColorNode = (0, _FontColorNode.$createFontColorNode)(selection.getTextContent(), color, themeColorName);
|
|
26
|
+
(0, _FontColorNode.$applyStylesToNode)(fontColorNode, selection);
|
|
27
|
+
(0, _lexical.$insertNodes)([fontColorNode]);
|
|
28
|
+
if ((0, _lexical.$isRootOrShadowRoot)(fontColorNode.getParentOrThrow())) {
|
|
29
|
+
(0, _utils.$wrapNodeInElement)(fontColorNode, _lexical.$createParagraphNode).selectEnd();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return true;
|
|
34
|
+
}, _lexical.COMMAND_PRIORITY_EDITOR);
|
|
35
|
+
}, [editor]);
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
38
|
+
exports.FontColorPlugin = FontColorPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FontColorPlugin","useLexicalComposerContext","editor","useEffect","registerCommand","ADD_FONT_COLOR_COMMAND","payload","update","color","themeColorName","selection","$getSelection","$isRangeSelection","fontColorNode","$createFontColorNode","getTextContent","$applyStylesToNode","$insertNodes","$isRootOrShadowRoot","getParentOrThrow","$wrapNodeInElement","$createParagraphNode","selectEnd","COMMAND_PRIORITY_EDITOR"],"sources":["FontColorPlugin.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport {\n $applyStylesToNode,\n $createFontColorNode,\n ADD_FONT_COLOR_COMMAND,\n FontColorPayload\n} from \"~/nodes/FontColorNode\";\nimport {\n $createParagraphNode,\n $getSelection,\n $insertNodes,\n $isRangeSelection,\n $isRootOrShadowRoot,\n COMMAND_PRIORITY_EDITOR\n} from \"lexical\";\nimport { $wrapNodeInElement } from \"@lexical/utils\";\n\nexport const FontColorPlugin: React.FC = () => {\n const [editor] = useLexicalComposerContext();\n\n useEffect(() => {\n return editor.registerCommand<FontColorPayload>(\n ADD_FONT_COLOR_COMMAND,\n payload => {\n editor.update(() => {\n const { color, themeColorName } = payload;\n const selection = $getSelection();\n\n if ($isRangeSelection(selection)) {\n const fontColorNode = $createFontColorNode(\n selection.getTextContent(),\n color,\n themeColorName\n );\n $applyStylesToNode(fontColorNode, selection);\n $insertNodes([fontColorNode]);\n if ($isRootOrShadowRoot(fontColorNode.getParentOrThrow())) {\n $wrapNodeInElement(fontColorNode, $createParagraphNode).selectEnd();\n }\n }\n });\n return true;\n },\n COMMAND_PRIORITY_EDITOR\n );\n }, [editor]);\n\n return null;\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AAMA;AAQA;AAEO,IAAMA,eAAyB,GAAG,SAA5BA,eAAyB,GAAS;EAC3C,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EAEb,IAAAC,gBAAS,EAAC,YAAM;IACZ,OAAOD,MAAM,CAACE,eAAe,CACzBC,qCAAsB,EACtB,UAAAC,OAAO,EAAI;MACPJ,MAAM,CAACK,MAAM,CAAC,YAAM;QAChB,IAAQC,KAAK,GAAqBF,OAAO,CAAjCE,KAAK;UAAEC,cAAc,GAAKH,OAAO,CAA1BG,cAAc;QAC7B,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;QAEjC,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,EAAE;UAC9B,IAAMG,aAAa,GAAG,IAAAC,mCAAoB,EACtCJ,SAAS,CAACK,cAAc,EAAE,EAC1BP,KAAK,EACLC,cAAc,CACjB;UACD,IAAAO,iCAAkB,EAACH,aAAa,EAAEH,SAAS,CAAC;UAC5C,IAAAO,qBAAY,EAAC,CAACJ,aAAa,CAAC,CAAC;UAC7B,IAAI,IAAAK,4BAAmB,EAACL,aAAa,CAACM,gBAAgB,EAAE,CAAC,EAAE;YACvD,IAAAC,yBAAkB,EAACP,aAAa,EAAEQ,6BAAoB,CAAC,CAACC,SAAS,EAAE;UACvE;QACJ;MACJ,CAAC,CAAC;MACF,OAAO,IAAI;IACf,CAAC,EACDC,gCAAuB,CAC1B;EACL,CAAC,EAAE,CAACrB,MAAM,CAAC,CAAC;EAEZ,OAAO,IAAI;AACf,CAAC;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["LexicalUpdateStatePlugin","value","useLexicalComposerContext","editor","useEffect","editorState","getEditorState","JSON","stringify","toJSON","initialEditorState","parseEditorState","isValidLexicalData","generateInitialLexicalValue","setEditorState"],"sources":["LexicalUpdateStatePlugin.tsx"],"sourcesContent":["import { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport React, { FC, useEffect } from \"react\";\nimport { isValidLexicalData } from \"~/utils/isValidLexicalData\";\nimport { generateInitialLexicalValue } from \"~/utils/generateInitialLexicalValue\";\nimport { LexicalValue } from \"~/types\";\n\ninterface LexicalUpdateStatePlugin {\n value: LexicalValue | null;\n readOnly?: boolean;\n}\n\n/*\n * Updates the lexical state if new value is provided to the lexical editor trough props\n */\nexport const LexicalUpdateStatePlugin: FC<LexicalUpdateStatePlugin> = ({\n value\n}): React.ReactElement => {\n const [editor] = useLexicalComposerContext();\n useEffect(() => {\n if (value && editor) {\n const editorState = editor.getEditorState();\n if (JSON.stringify(editorState.toJSON()) === value) {\n return;\n }\n\n const initialEditorState = editor.parseEditorState(\n isValidLexicalData(value)\n ? (value as string)\n : (generateInitialLexicalValue() as string)\n );\n editor.setEditorState(initialEditorState);\n }\n }, [value, editor]);\n\n return <></>;\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AAQA;AACA;AACA;AACO,IAAMA,wBAAsD,GAAG,SAAzDA,wBAAsD,OAEzC;EAAA,IADtBC,KAAK,QAALA,KAAK;EAEL,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,IAAAC,gBAAS,EAAC,YAAM;IACZ,IAAIH,KAAK,IAAIE,MAAM,EAAE;MACjB,IAAME,WAAW,GAAGF,MAAM,CAACG,cAAc,EAAE;MAC3C,IAAIC,IAAI,CAACC,SAAS,CAACH,WAAW,CAACI,MAAM,EAAE,CAAC,KAAKR,KAAK,EAAE;QAChD;MACJ;MAEA,IAAMS,kBAAkB,GAAGP,MAAM,CAACQ,gBAAgB,CAC9C,IAAAC,sCAAkB,EAACX,KAAK,CAAC,GAClBA,KAAK,GACL,IAAAY,wDAA2B,GAAa,CAClD;MACDV,MAAM,CAACW,cAAc,CAACJ,kBAAkB,CAAC;IAC7C;EACJ,CAAC,EAAE,CAACT,KAAK,EAAEE,MAAM,CAAC,CAAC;EAEnB,oBAAO,2DAAK;AAChB,CAAC;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./LexicalUpdateStatePlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.TypographyPlugin = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
11
|
+
var _lexical = require("lexical");
|
|
12
|
+
var _TypographyElementNode = require("../../nodes/TypographyElementNode");
|
|
13
|
+
var _selection = require("@lexical/selection");
|
|
14
|
+
var TypographyPlugin = function TypographyPlugin() {
|
|
15
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
16
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
17
|
+
editor = _useLexicalComposerCo2[0];
|
|
18
|
+
(0, _react.useEffect)(function () {
|
|
19
|
+
return editor.registerCommand(_TypographyElementNode.ADD_TYPOGRAPHY_ELEMENT_COMMAND, function (payload) {
|
|
20
|
+
var selection = (0, _lexical.$getSelection)();
|
|
21
|
+
if ((0, _lexical.$isRangeSelection)(selection)) {
|
|
22
|
+
(0, _selection.$wrapNodes)(selection, function () {
|
|
23
|
+
return (0, _TypographyElementNode.$createTypographyNode)(payload.value);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}, _lexical.COMMAND_PRIORITY_EDITOR);
|
|
28
|
+
}, [editor]);
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
exports.TypographyPlugin = TypographyPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TypographyPlugin","useLexicalComposerContext","editor","useEffect","registerCommand","ADD_TYPOGRAPHY_ELEMENT_COMMAND","payload","selection","$getSelection","$isRangeSelection","$wrapNodes","$createTypographyNode","value","COMMAND_PRIORITY_EDITOR"],"sources":["TypographyPlugin.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR } from \"lexical\";\nimport {\n $createTypographyNode,\n ADD_TYPOGRAPHY_ELEMENT_COMMAND,\n TypographyPayload\n} from \"~/nodes/TypographyElementNode\";\nimport { $wrapNodes } from \"@lexical/selection\";\n\nexport const TypographyPlugin: React.FC = () => {\n const [editor] = useLexicalComposerContext();\n\n useEffect(() => {\n return editor.registerCommand<TypographyPayload>(\n ADD_TYPOGRAPHY_ELEMENT_COMMAND,\n payload => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n $wrapNodes(selection, () => $createTypographyNode(payload.value));\n }\n return true;\n },\n COMMAND_PRIORITY_EDITOR\n );\n }, [editor]);\n\n return null;\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AAKA;AAEO,IAAMA,gBAA0B,GAAG,SAA7BA,gBAA0B,GAAS;EAC5C,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EAEb,IAAAC,gBAAS,EAAC,YAAM;IACZ,OAAOD,MAAM,CAACE,eAAe,CACzBC,qDAA8B,EAC9B,UAAAC,OAAO,EAAI;MACP,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;MACjC,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,EAAE;QAC9B,IAAAG,qBAAU,EAACH,SAAS,EAAE;UAAA,OAAM,IAAAI,4CAAqB,EAACL,OAAO,CAACM,KAAK,CAAC;QAAA,EAAC;MACrE;MACA,OAAO,IAAI;IACf,CAAC,EACDC,gCAAuB,CAC1B;EACL,CAAC,EAAE,CAACX,MAAM,CAAC,CAAC;EAEZ,OAAO,IAAI;AACf,CAAC;AAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function WebinyListPlugin(): null;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.WebinyListPlugin = WebinyListPlugin;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
var _WebinyListNode = require("../../nodes/list-node/WebinyListNode");
|
|
12
|
+
var _WebinyListItemNode = require("../../nodes/list-node/WebinyListItemNode");
|
|
13
|
+
var _useWebinyList = require("../../hooks/useWebinyList");
|
|
14
|
+
function WebinyListPlugin() {
|
|
15
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
16
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
17
|
+
editor = _useLexicalComposerCo2[0];
|
|
18
|
+
(0, _react.useEffect)(function () {
|
|
19
|
+
if (!editor.hasNodes([_WebinyListNode.WebinyListNode, _WebinyListItemNode.WebinyListItemNode])) {
|
|
20
|
+
throw new Error("WebinyListPlugin: WebinyListNode and/or WebinyListItemNode not registered on editor");
|
|
21
|
+
}
|
|
22
|
+
}, [editor]);
|
|
23
|
+
(0, _useWebinyList.useWebinyList)(editor);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["WebinyListPlugin","useLexicalComposerContext","editor","useEffect","hasNodes","WebinyListNode","WebinyListItemNode","Error","useWebinyList"],"sources":["WebinyListPlugin.ts"],"sourcesContent":["import { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { useEffect } from \"react\";\nimport { WebinyListNode } from \"~/nodes/list-node/WebinyListNode\";\nimport { WebinyListItemNode } from \"~/nodes/list-node/WebinyListItemNode\";\nimport { useWebinyList } from \"~/hooks/useWebinyList\";\n\nexport function WebinyListPlugin(): null {\n const [editor] = useLexicalComposerContext();\n\n useEffect(() => {\n if (!editor.hasNodes([WebinyListNode, WebinyListItemNode])) {\n throw new Error(\n \"WebinyListPlugin: WebinyListNode and/or WebinyListItemNode not registered on editor\"\n );\n }\n }, [editor]);\n\n useWebinyList(editor);\n\n return null;\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEO,SAASA,gBAAgB,GAAS;EACrC,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EAEb,IAAAC,gBAAS,EAAC,YAAM;IACZ,IAAI,CAACD,MAAM,CAACE,QAAQ,CAAC,CAACC,8BAAc,EAAEC,sCAAkB,CAAC,CAAC,EAAE;MACxD,MAAM,IAAIC,KAAK,CACX,qFAAqF,CACxF;IACL;EACJ,CAAC,EAAE,CAACL,MAAM,CAAC,CAAC;EAEZ,IAAAM,4BAAa,EAACN,MAAM,CAAC;EAErB,OAAO,IAAI;AACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function WebinyQuotePlugin(): null;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.WebinyQuotePlugin = WebinyQuotePlugin;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
var _WebinyQuoteNode = require("../../nodes/WebinyQuoteNode");
|
|
12
|
+
var _useWebinyQuote = require("../../hooks/useWebinyQuote");
|
|
13
|
+
function WebinyQuotePlugin() {
|
|
14
|
+
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
15
|
+
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
16
|
+
editor = _useLexicalComposerCo2[0];
|
|
17
|
+
(0, _react.useEffect)(function () {
|
|
18
|
+
if (!editor.hasNodes([_WebinyQuoteNode.WebinyQuoteNode])) {
|
|
19
|
+
throw new Error("WebinyQuoteNodePlugin: WebinyQuoteNode is e not registered on editor");
|
|
20
|
+
}
|
|
21
|
+
}, [editor]);
|
|
22
|
+
(0, _useWebinyQuote.useWebinyQuote)(editor);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["WebinyQuotePlugin","useLexicalComposerContext","editor","useEffect","hasNodes","WebinyQuoteNode","Error","useWebinyQuote"],"sources":["WebinyQuoteNodePlugin.ts"],"sourcesContent":["import { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { useEffect } from \"react\";\nimport { WebinyQuoteNode } from \"~/nodes/WebinyQuoteNode\";\nimport { useWebinyQuote } from \"~/hooks/useWebinyQuote\";\n\nexport function WebinyQuotePlugin(): null {\n const [editor] = useLexicalComposerContext();\n\n useEffect(() => {\n if (!editor.hasNodes([WebinyQuoteNode])) {\n throw new Error(\"WebinyQuoteNodePlugin: WebinyQuoteNode is e not registered on editor\");\n }\n }, [editor]);\n\n useWebinyQuote(editor);\n\n return null;\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AAEO,SAASA,iBAAiB,GAAS;EACtC,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EAEb,IAAAC,gBAAS,EAAC,YAAM;IACZ,IAAI,CAACD,MAAM,CAACE,QAAQ,CAAC,CAACC,gCAAe,CAAC,CAAC,EAAE;MACrC,MAAM,IAAIC,KAAK,CAAC,sEAAsE,CAAC;IAC3F;EACJ,CAAC,EAAE,CAACJ,MAAM,CAAC,CAAC;EAEZ,IAAAK,8BAAc,EAACL,MAAM,CAAC;EAEtB,OAAO,IAAI;AACf"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
1
|
import type { EditorThemeClasses } from "lexical";
|
|
9
2
|
import "./webinyLexicalTheme.css";
|
|
10
|
-
|
|
3
|
+
import { ThemeEmotionMap } from "../types";
|
|
4
|
+
export declare type WebinyTheme = {
|
|
5
|
+
styles?: Record<string, any>;
|
|
6
|
+
emotionMap?: ThemeEmotionMap;
|
|
7
|
+
};
|
|
8
|
+
export declare type WebinyEditorTheme = WebinyTheme & EditorThemeClasses;
|
|
9
|
+
export declare const webinyEditorTheme: WebinyEditorTheme;
|
|
@@ -3,17 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.webinyEditorTheme = void 0;
|
|
7
7
|
require("./webinyLexicalTheme.css");
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
var theme = {
|
|
8
|
+
var webinyEditorTheme = {
|
|
9
|
+
styles: undefined,
|
|
10
|
+
emotionMap: undefined,
|
|
17
11
|
characterLimit: "WebinyLexical__characterLimit",
|
|
18
12
|
code: "WebinyLexical__code",
|
|
19
13
|
codeHighlight: {
|
|
@@ -61,7 +55,6 @@ var theme = {
|
|
|
61
55
|
h5: "WebinyLexical__h5",
|
|
62
56
|
h6: "WebinyLexical__h6"
|
|
63
57
|
},
|
|
64
|
-
image: "editor-image",
|
|
65
58
|
link: "WebinyLexical__link",
|
|
66
59
|
list: {
|
|
67
60
|
listitem: "WebinyLexical__listItem",
|
|
@@ -79,20 +72,6 @@ var theme = {
|
|
|
79
72
|
paragraph: "WebinyLexical__paragraph",
|
|
80
73
|
quote: "WebinyLexical__quote",
|
|
81
74
|
rtl: "WebinyLexical__rtl",
|
|
82
|
-
table: "WebinyLexical__table",
|
|
83
|
-
tableAddColumns: "WebinyLexical__tableAddColumns",
|
|
84
|
-
tableAddRows: "WebinyLexical__tableAddRows",
|
|
85
|
-
tableCell: "WebinyLexical__tableCell",
|
|
86
|
-
tableCellActionButton: "WebinyLexical__tableCellActionButton",
|
|
87
|
-
tableCellActionButtonContainer: "WebinyLexical__tableCellActionButtonContainer",
|
|
88
|
-
tableCellEditing: "WebinyLexical__tableCellEditing",
|
|
89
|
-
tableCellHeader: "WebinyLexical__tableCellHeader",
|
|
90
|
-
tableCellPrimarySelected: "WebinyLexical__tableCellPrimarySelected",
|
|
91
|
-
tableCellResizer: "WebinyLexical__tableCellResizer",
|
|
92
|
-
tableCellSelected: "WebinyLexical__tableCellSelected",
|
|
93
|
-
tableCellSortedIndicator: "WebinyLexical__tableCellSortedIndicator",
|
|
94
|
-
tableResizeRuler: "WebinyLexical__tableCellResizeRuler",
|
|
95
|
-
tableSelected: "WebinyLexical__tableSelected",
|
|
96
75
|
text: {
|
|
97
76
|
bold: "WebinyLexical__textBold",
|
|
98
77
|
code: "WebinyLexical__textCode",
|
|
@@ -102,6 +81,7 @@ var theme = {
|
|
|
102
81
|
superscript: "WebinyLexical__textSuperscript",
|
|
103
82
|
underline: "WebinyLexical__textUnderline",
|
|
104
83
|
underlineStrikethrough: "WebinyLexical__textUnderlineStrikethrough"
|
|
105
|
-
}
|
|
84
|
+
},
|
|
85
|
+
fontColorText: "WebinyLexical__fontColorText"
|
|
106
86
|
};
|
|
107
|
-
exports.
|
|
87
|
+
exports.webinyEditorTheme = webinyEditorTheme;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["webinyEditorTheme","styles","undefined","emotionMap","characterLimit","code","codeHighlight","atrule","attr","boolean","builtin","cdata","char","class","comment","constant","deleted","doctype","entity","function","important","inserted","keyword","namespace","number","operator","prolog","property","punctuation","regex","selector","string","symbol","tag","url","variable","embedBlock","base","focus","hashtag","heading","h1","h2","h3","h4","h5","h6","link","list","listitem","listitemChecked","listitemUnchecked","nested","olDepth","ul","ltr","mark","markOverlap","paragraph","quote","rtl","text","bold","italic","strikethrough","subscript","superscript","underline","underlineStrikethrough","fontColorText"],"sources":["webinyLexicalTheme.ts"],"sourcesContent":["import type { EditorThemeClasses } from \"lexical\";\n\nimport \"./webinyLexicalTheme.css\";\nimport { ThemeEmotionMap } from \"~/types\";\n\nexport type WebinyTheme = {\n styles?: Record<string, any>;\n emotionMap?: ThemeEmotionMap;\n};\n\nexport type WebinyEditorTheme = WebinyTheme & EditorThemeClasses;\n\nexport const webinyEditorTheme: WebinyEditorTheme = {\n styles: undefined,\n emotionMap: undefined,\n characterLimit: \"WebinyLexical__characterLimit\",\n code: \"WebinyLexical__code\",\n codeHighlight: {\n atrule: \"WebinyLexical__tokenAttr\",\n attr: \"WebinyLexical__tokenAttr\",\n boolean: \"WebinyLexical__tokenProperty\",\n builtin: \"WebinyLexical__tokenSelector\",\n cdata: \"WebinyLexical__tokenComment\",\n char: \"WebinyLexical__tokenSelector\",\n class: \"WebinyLexical__tokenFunction\",\n \"class-name\": \"WebinyLexical__tokenFunction\",\n comment: \"WebinyLexical__tokenComment\",\n constant: \"WebinyLexical__tokenProperty\",\n deleted: \"WebinyLexical__tokenProperty\",\n doctype: \"WebinyLexical__tokenComment\",\n entity: \"WebinyLexical__tokenOperator\",\n function: \"WebinyLexical__tokenFunction\",\n important: \"WebinyLexical__tokenVariable\",\n inserted: \"WebinyLexical__tokenSelector\",\n keyword: \"WebinyLexical__tokenAttr\",\n namespace: \"WebinyLexical__tokenVariable\",\n number: \"WebinyLexical__tokenProperty\",\n operator: \"WebinyLexical__tokenOperator\",\n prolog: \"WebinyLexical__tokenComment\",\n property: \"WebinyLexical__tokenProperty\",\n punctuation: \"WebinyLexical__tokenPunctuation\",\n regex: \"WebinyLexical__tokenVariable\",\n selector: \"WebinyLexical__tokenSelector\",\n string: \"WebinyLexical__tokenSelector\",\n symbol: \"WebinyLexical__tokenProperty\",\n tag: \"WebinyLexical__tokenProperty\",\n url: \"WebinyLexical__tokenOperator\",\n variable: \"WebinyLexical__tokenVariable\"\n },\n embedBlock: {\n base: \"WebinyLexical__embedBlock\",\n focus: \"WebinyLexical__embedBlockFocus\"\n },\n hashtag: \"WebinyLexical__hashtag\",\n heading: {\n h1: \"WebinyLexical__h1\",\n h2: \"WebinyLexical__h2\",\n h3: \"WebinyLexical__h3\",\n h4: \"WebinyLexical__h4\",\n h5: \"WebinyLexical__h5\",\n h6: \"WebinyLexical__h6\"\n },\n link: \"WebinyLexical__link\",\n list: {\n listitem: \"WebinyLexical__listItem\",\n listitemChecked: \"WebinyLexical__listItemChecked\",\n listitemUnchecked: \"WebinyLexical__listItemUnchecked\",\n nested: {\n listitem: \"WebinyLexical__nestedListItem\"\n },\n olDepth: [\n \"WebinyLexical__ol1\",\n \"WebinyLexical__ol2\",\n \"WebinyLexical__ol3\",\n \"WebinyLexical__ol4\",\n \"WebinyLexical__ol5\"\n ],\n ul: \"WebinyLexical__ul\"\n },\n ltr: \"WebinyLexical__ltr\",\n mark: \"WebinyLexical__mark\",\n markOverlap: \"WebinyLexical__markOverlap\",\n paragraph: \"WebinyLexical__paragraph\",\n quote: \"WebinyLexical__quote\",\n rtl: \"WebinyLexical__rtl\",\n text: {\n bold: \"WebinyLexical__textBold\",\n code: \"WebinyLexical__textCode\",\n italic: \"WebinyLexical__textItalic\",\n strikethrough: \"WebinyLexical__textStrikethrough\",\n subscript: \"WebinyLexical__textSubscript\",\n superscript: \"WebinyLexical__textSuperscript\",\n underline: \"WebinyLexical__textUnderline\",\n underlineStrikethrough: \"WebinyLexical__textUnderlineStrikethrough\"\n },\n fontColorText: \"WebinyLexical__fontColorText\"\n};\n"],"mappings":";;;;;;AAEA;AAUO,IAAMA,iBAAoC,GAAG;EAChDC,MAAM,EAAEC,SAAS;EACjBC,UAAU,EAAED,SAAS;EACrBE,cAAc,EAAE,+BAA+B;EAC/CC,IAAI,EAAE,qBAAqB;EAC3BC,aAAa,EAAE;IACXC,MAAM,EAAE,0BAA0B;IAClCC,IAAI,EAAE,0BAA0B;IAChCC,OAAO,EAAE,8BAA8B;IACvCC,OAAO,EAAE,8BAA8B;IACvCC,KAAK,EAAE,6BAA6B;IACpCC,IAAI,EAAE,8BAA8B;IACpCC,KAAK,EAAE,8BAA8B;IACrC,YAAY,EAAE,8BAA8B;IAC5CC,OAAO,EAAE,6BAA6B;IACtCC,QAAQ,EAAE,8BAA8B;IACxCC,OAAO,EAAE,8BAA8B;IACvCC,OAAO,EAAE,6BAA6B;IACtCC,MAAM,EAAE,8BAA8B;IACtCC,QAAQ,EAAE,8BAA8B;IACxCC,SAAS,EAAE,8BAA8B;IACzCC,QAAQ,EAAE,8BAA8B;IACxCC,OAAO,EAAE,0BAA0B;IACnCC,SAAS,EAAE,8BAA8B;IACzCC,MAAM,EAAE,8BAA8B;IACtCC,QAAQ,EAAE,8BAA8B;IACxCC,MAAM,EAAE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AE,8BAA8B;IACzCC,sBAAsB,EAAE;EAC5B,CAAC;EACDC,aAAa,EAAE;AACnB,CAAC;AAAC"}
|
package/types.d.ts
CHANGED
|
@@ -1,2 +1,61 @@
|
|
|
1
|
+
import { ElementNode, LexicalNode, NodeSelection, RangeSelection, TextNode } from "lexical";
|
|
2
|
+
import { ListType } from "@lexical/list";
|
|
3
|
+
import { CSSObject } from "@emotion/react";
|
|
1
4
|
export declare type ToolbarType = "heading" | "paragraph" | string;
|
|
2
5
|
export declare type LexicalValue = string;
|
|
6
|
+
export { FontColorPicker } from "./components/ToolbarActions/FontColorAction";
|
|
7
|
+
export declare type LexicalTextType = ListType | "paragraph" | "heading" | "quoteblock" | "bullet" | "number" | "link" | undefined;
|
|
8
|
+
export declare type TextFormatting = {
|
|
9
|
+
bold: boolean;
|
|
10
|
+
underline: boolean;
|
|
11
|
+
italic: boolean;
|
|
12
|
+
code: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare type NodeState = {
|
|
15
|
+
isSelected: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare type ToolbarState = {
|
|
18
|
+
bold: boolean;
|
|
19
|
+
underline: boolean;
|
|
20
|
+
italic: boolean;
|
|
21
|
+
code: boolean;
|
|
22
|
+
link: NodeState;
|
|
23
|
+
typography: NodeState;
|
|
24
|
+
fontColor: NodeState;
|
|
25
|
+
list: NodeState;
|
|
26
|
+
quote: NodeState;
|
|
27
|
+
textType: LexicalTextType;
|
|
28
|
+
};
|
|
29
|
+
export declare type TextBlockSelection = {
|
|
30
|
+
elementKey?: string;
|
|
31
|
+
selection: RangeSelection | NodeSelection | null;
|
|
32
|
+
element: LexicalNode;
|
|
33
|
+
parent: ElementNode | null;
|
|
34
|
+
node: ElementNode | TextNode;
|
|
35
|
+
anchorNode: ElementNode | TextNode;
|
|
36
|
+
isElementDom: boolean;
|
|
37
|
+
state: ToolbarState | undefined;
|
|
38
|
+
};
|
|
39
|
+
export declare type ListHtmlTag = "ol" | "ul";
|
|
40
|
+
export declare type HeadingHtmlTag = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
41
|
+
export declare type ParagraphHtmlTag = "p";
|
|
42
|
+
export declare type QuoteBlockHtmlTag = "quoteblock";
|
|
43
|
+
export declare type TypographyHTMLTag = HeadingHtmlTag | ParagraphHtmlTag | ListHtmlTag | QuoteBlockHtmlTag;
|
|
44
|
+
export declare type TypographyValue = {
|
|
45
|
+
css: CSSObject;
|
|
46
|
+
id: string;
|
|
47
|
+
tag: TypographyHTMLTag;
|
|
48
|
+
name: string;
|
|
49
|
+
};
|
|
50
|
+
export interface WebinyThemeNode {
|
|
51
|
+
getStyleId: () => string;
|
|
52
|
+
}
|
|
53
|
+
export declare type ThemeEmotionMap = {
|
|
54
|
+
[styleId: string]: {
|
|
55
|
+
id: string;
|
|
56
|
+
tag: TypographyHTMLTag;
|
|
57
|
+
name: string;
|
|
58
|
+
styles: Record<string, any>;
|
|
59
|
+
className: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
package/types.js
CHANGED
|
@@ -2,4 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
});
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "FontColorPicker", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _FontColorAction.FontColorPicker;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _FontColorAction = require("./components/ToolbarActions/FontColorAction");
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { ElementNode, LexicalNode, NodeSelection, RangeSelection, TextNode } from \"lexical\";\nimport { ListType } from \"@lexical/list\";\nimport { CSSObject } from \"@emotion/react\";\nexport type ToolbarType = \"heading\" | \"paragraph\" | string;\nexport type LexicalValue = string;\nexport { FontColorPicker } from \"~/components/ToolbarActions/FontColorAction\";\n\nexport type LexicalTextType =\n | ListType\n | \"paragraph\"\n | \"heading\"\n | \"quoteblock\"\n | \"bullet\"\n | \"number\"\n | \"link\"\n | undefined;\n\nexport type TextFormatting = {\n bold: boolean;\n underline: boolean;\n italic: boolean;\n // highlight: boolean #TODO implement with highlight action\n code: boolean;\n};\n\nexport type NodeState = {\n isSelected: boolean;\n};\n\nexport type ToolbarState = {\n // text format\n bold: boolean;\n underline: boolean;\n italic: boolean;\n code: boolean;\n // nodes selection state\n link: NodeState;\n typography: NodeState;\n fontColor: NodeState;\n list: NodeState;\n quote: NodeState;\n textType: LexicalTextType;\n};\n\n/*\n * Represent set of data from the current selection of the text and nodes selected by the user.\n * You can access this object through the @see useRichTextEditor context.\n */\nexport type TextBlockSelection = {\n elementKey?: string;\n selection: RangeSelection | NodeSelection | null;\n element: LexicalNode;\n parent: ElementNode | null;\n node: ElementNode | TextNode;\n anchorNode: ElementNode | TextNode;\n isElementDom: boolean;\n state: ToolbarState | undefined;\n};\n\n// Supported HTML tags by webiny lexical implementation\nexport type ListHtmlTag = \"ol\" | \"ul\";\nexport type HeadingHtmlTag = \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\nexport type ParagraphHtmlTag = \"p\";\nexport type QuoteBlockHtmlTag = \"quoteblock\";\n\n// Typography\nexport type TypographyHTMLTag = HeadingHtmlTag | ParagraphHtmlTag | ListHtmlTag | QuoteBlockHtmlTag;\n\nexport type TypographyValue = {\n // CSSObject type\n css: CSSObject;\n id: string;\n tag: TypographyHTMLTag;\n // Display name\n name: string;\n};\n\n/* Nodes */\nexport interface WebinyThemeNode {\n /*\n * Get theme style id\n */\n getStyleId: () => string;\n}\n\n/*\n * Contains IDs of the styles and Emotion generated classes.\n */\nexport type ThemeEmotionMap = {\n [styleId: string]: {\n id: string;\n tag: TypographyHTMLTag;\n name: string;\n styles: Record<string, any>;\n // emotion generated class\n className: string;\n };\n};\n"],"mappings":";;;;;;;;;;;AAKA"}
|
package/ui/Divider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["Divider"],"sources":["Divider.tsx"],"sourcesContent":["import React from \"react\";\n\nexport function Divider(): JSX.Element {\n return <div className=\"divider\"></div>;\n}\n"],"mappings":";;;;;;;AAAA;AAEO,SAASA,OAAO,GAAgB;EACnC,oBAAO;IAAK,SAAS,EAAC;EAAS,EAAO;AAC1C"}
|
package/ui/DropDown.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare function DropDownItem({ children, className, onClick, title }: {
|
|
|
14
14
|
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
15
15
|
title?: string;
|
|
16
16
|
}): JSX.Element;
|
|
17
|
-
export declare function DropDown({ disabled, buttonLabel, buttonAriaLabel, buttonClassName, buttonIconClassName, children, stopCloseOnClickSelf }: {
|
|
17
|
+
export declare function DropDown({ disabled, buttonLabel, buttonAriaLabel, buttonClassName, buttonIconClassName, children, stopCloseOnClickSelf, showScroll }: {
|
|
18
18
|
disabled?: boolean;
|
|
19
19
|
buttonAriaLabel?: string;
|
|
20
20
|
buttonClassName: string;
|
|
@@ -22,4 +22,5 @@ export declare function DropDown({ disabled, buttonLabel, buttonAriaLabel, butto
|
|
|
22
22
|
buttonLabel?: string;
|
|
23
23
|
children: ReactNode;
|
|
24
24
|
stopCloseOnClickSelf?: boolean;
|
|
25
|
+
showScroll?: boolean;
|
|
25
26
|
}): JSX.Element;
|