@payloadcms/richtext-lexical 3.68.0-internal-debug.2eb12b9 → 3.68.0-internal-debug.dafc24d
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/dist/cell/rscEntry.js +13 -5
- package/dist/cell/rscEntry.js.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.js +29 -9
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockCollapsible.js +7 -3
- package/dist/features/blocks/client/component/components/BlockCollapsible.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockEditButton.js +6 -2
- package/dist/features/blocks/client/component/components/BlockEditButton.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockRemoveButton.js +6 -2
- package/dist/features/blocks/client/component/components/BlockRemoveButton.js.map +1 -1
- package/dist/features/blocks/client/component/index.js +124 -43
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/component/index.scss +188 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockContainer.js +7 -3
- package/dist/features/blocks/client/componentInline/components/InlineBlockContainer.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockEditButton.js +6 -2
- package/dist/features/blocks/client/componentInline/components/InlineBlockEditButton.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockLabel.js +6 -2
- package/dist/features/blocks/client/componentInline/components/InlineBlockLabel.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockRemoveButton.js +6 -2
- package/dist/features/blocks/client/componentInline/components/InlineBlockRemoveButton.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +118 -37
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.scss +90 -0
- package/dist/features/blocks/client/getBlockImageComponent.js +7 -3
- package/dist/features/blocks/client/getBlockImageComponent.js.map +1 -1
- package/dist/features/blocks/client/markdown/markdownTransformer.js +1 -0
- package/dist/features/blocks/client/markdown/markdownTransformer.js.map +1 -1
- package/dist/features/blocks/client/nodes/BlocksNode.js +7 -3
- package/dist/features/blocks/client/nodes/BlocksNode.js.map +1 -1
- package/dist/features/blocks/client/nodes/InlineBlocksNode.js +7 -3
- package/dist/features/blocks/client/nodes/InlineBlocksNode.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js +88 -27
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Code.js +7 -3
- package/dist/features/blocks/premade/CodeBlock/Component/Code.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Collapse/index.js +13 -4
- package/dist/features/blocks/premade/CodeBlock/Component/Collapse/index.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Collapse/index.scss +6 -0
- package/dist/features/blocks/premade/CodeBlock/Component/FloatingCollapse/index.js +19 -6
- package/dist/features/blocks/premade/CodeBlock/Component/FloatingCollapse/index.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/FloatingCollapse/index.scss +29 -0
- package/dist/features/blocks/premade/CodeBlock/Component/index.scss +97 -0
- package/dist/features/blocks/server/markdown/markdownTransformer.js +1 -0
- package/dist/features/blocks/server/markdown/markdownTransformer.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.js +9 -5
- package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/blockquote.js +7 -3
- package/dist/features/converters/lexicalToJSX/converter/converters/blockquote.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/heading.js +7 -3
- package/dist/features/converters/lexicalToJSX/converter/converters/heading.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/horizontalRule.js +6 -2
- package/dist/features/converters/lexicalToJSX/converter/converters/horizontalRule.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/linebreak.js +6 -2
- package/dist/features/converters/lexicalToJSX/converter/converters/linebreak.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/link.js +13 -5
- package/dist/features/converters/lexicalToJSX/converter/converters/link.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/list.js +38 -14
- package/dist/features/converters/lexicalToJSX/converter/converters/list.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/paragraph.js +18 -6
- package/dist/features/converters/lexicalToJSX/converter/converters/paragraph.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/table.js +31 -11
- package/dist/features/converters/lexicalToJSX/converter/converters/table.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/text.js +43 -15
- package/dist/features/converters/lexicalToJSX/converter/converters/text.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/upload.js +31 -11
- package/dist/features/converters/lexicalToJSX/converter/converters/upload.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/index.js +8 -4
- package/dist/features/converters/lexicalToJSX/converter/index.js.map +1 -1
- package/dist/features/debug/jsxConverter/client/plugin/index.js +14 -5
- package/dist/features/debug/jsxConverter/client/plugin/index.js.map +1 -1
- package/dist/features/debug/jsxConverter/client/plugin/style.scss +12 -0
- package/dist/features/debug/testRecorder/client/plugin/index.js +62 -21
- package/dist/features/debug/testRecorder/client/plugin/index.js.map +1 -1
- package/dist/features/debug/testRecorder/client/plugin/index.scss +53 -0
- package/dist/features/debug/treeView/client/plugin/index.js +8 -3
- package/dist/features/debug/treeView/client/plugin/index.js.map +1 -1
- package/dist/features/debug/treeView/client/plugin/index.scss +80 -0
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js +225 -72
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.scss +87 -0
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js +32 -11
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.scss +11 -0
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js +21 -9
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.js +26 -9
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.scss +233 -0
- package/dist/features/horizontalRule/client/plugin/index.js +1 -0
- package/dist/features/horizontalRule/client/plugin/index.js.map +1 -1
- package/dist/features/horizontalRule/client/plugin/index.scss +23 -0
- package/dist/features/indent/client/IndentPlugin.js +6 -2
- package/dist/features/indent/client/IndentPlugin.js.map +1 -1
- package/dist/features/link/client/plugins/autoLink/index.js +3 -0
- package/dist/features/link/client/plugins/autoLink/index.js.map +1 -1
- package/dist/features/link/client/plugins/clickableLink/index.js +6 -2
- package/dist/features/link/client/plugins/clickableLink/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +76 -24
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/index.js +8 -3
- package/dist/features/link/client/plugins/floatingLinkEditor/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/index.scss +92 -0
- package/dist/features/link/server/baseFields.js +1 -0
- package/dist/features/link/server/baseFields.js.map +1 -1
- package/dist/features/lists/checklist/client/plugin/index.js +6 -2
- package/dist/features/lists/checklist/client/plugin/index.js.map +1 -1
- package/dist/features/lists/plugin/index.js +6 -2
- package/dist/features/lists/plugin/index.js.map +1 -1
- package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/Component.js +14 -5
- package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/Component.js.map +1 -1
- package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.js +7 -3
- package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.js.map +1 -1
- package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.scss +16 -0
- package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/Component.js +14 -5
- package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/Component.js.map +1 -1
- package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.js +7 -3
- package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.js.map +1 -1
- package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.scss +16 -0
- package/dist/features/relationship/client/components/RelationshipComponent.js +56 -19
- package/dist/features/relationship/client/components/RelationshipComponent.js.map +1 -1
- package/dist/features/relationship/client/components/index.scss +95 -0
- package/dist/features/relationship/client/drawer/index.js +18 -6
- package/dist/features/relationship/client/drawer/index.js.map +1 -1
- package/dist/features/relationship/client/nodes/RelationshipNode.js +7 -3
- package/dist/features/relationship/client/nodes/RelationshipNode.js.map +1 -1
- package/dist/features/relationship/client/plugins/index.js +7 -3
- package/dist/features/relationship/client/plugins/index.js.map +1 -1
- package/dist/features/textState/feature.client.js +18 -6
- package/dist/features/textState/feature.client.js.map +1 -1
- package/dist/features/toolbars/fixed/client/Toolbar/index.js +72 -23
- package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/fixed/client/Toolbar/index.scss +113 -0
- package/dist/features/toolbars/inline/client/Toolbar/index.js +72 -23
- package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.scss +58 -0
- package/dist/features/toolbars/shared/ToolbarButton/index.js +8 -3
- package/dist/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarButton/index.scss +46 -0
- package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js +60 -20
- package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js +37 -12
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.scss +129 -0
- package/dist/features/upload/client/component/index.js +92 -31
- package/dist/features/upload/client/component/index.js.map +1 -1
- package/dist/features/upload/client/component/index.scss +191 -0
- package/dist/features/upload/client/component/pending/index.js +14 -5
- package/dist/features/upload/client/component/pending/index.js.map +1 -1
- package/dist/features/upload/client/drawer/index.js +18 -6
- package/dist/features/upload/client/drawer/index.js.map +1 -1
- package/dist/features/upload/client/nodes/UploadNode.js +12 -4
- package/dist/features/upload/client/nodes/UploadNode.js.map +1 -1
- package/dist/features/upload/client/plugin/index.js +7 -3
- package/dist/features/upload/client/plugin/index.js.map +1 -1
- package/dist/field/Diff/converters/listitem/index.js +37 -12
- package/dist/field/Diff/converters/listitem/index.js.map +1 -1
- package/dist/field/Diff/converters/listitem/index.scss +47 -0
- package/dist/field/Diff/converters/relationship/index.js +37 -12
- package/dist/field/Diff/converters/relationship/index.js.map +1 -1
- package/dist/field/Diff/converters/relationship/index.scss +73 -0
- package/dist/field/Diff/converters/unknown/index.js +31 -10
- package/dist/field/Diff/converters/unknown/index.js.map +1 -1
- package/dist/field/Diff/converters/unknown/index.scss +40 -0
- package/dist/field/Diff/converters/upload/index.js +60 -19
- package/dist/field/Diff/converters/upload/index.js.map +1 -1
- package/dist/field/Diff/converters/upload/index.scss +115 -0
- package/dist/field/Diff/index.js +8 -3
- package/dist/field/Diff/index.js.map +1 -1
- package/dist/field/Diff/index.scss +102 -0
- package/dist/field/Field.js +81 -27
- package/dist/field/Field.js.map +1 -1
- package/dist/field/RenderLexical/index.js +36 -12
- package/dist/field/RenderLexical/index.js.map +1 -1
- package/dist/field/index.js +19 -7
- package/dist/field/index.js.map +1 -1
- package/dist/field/index.scss +41 -0
- package/dist/field/rscEntry.js +7 -3
- package/dist/field/rscEntry.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lexical/EditorPlugin.js +13 -5
- package/dist/lexical/EditorPlugin.js.map +1 -1
- package/dist/lexical/LexicalEditor.js +163 -50
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/LexicalEditor.scss +54 -0
- package/dist/lexical/LexicalProvider.js +49 -17
- package/dist/lexical/LexicalProvider.js.map +1 -1
- package/dist/lexical/config/client/EditorConfigProvider.js +7 -3
- package/dist/lexical/config/client/EditorConfigProvider.js.map +1 -1
- package/dist/lexical/plugins/DecoratorPlugin/index.js +1 -0
- package/dist/lexical/plugins/DecoratorPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/DecoratorPlugin/index.scss +13 -0
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.js +20 -7
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.js.map +1 -1
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.scss +54 -0
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js +2 -0
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js +7 -3
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/index.js +50 -16
- package/dist/lexical/plugins/SlashMenu/index.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/index.scss +68 -0
- package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js +20 -7
- package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.scss +35 -0
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js +32 -11
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.scss +80 -0
- package/dist/lexical/theme/EditorTheme.scss +357 -0
- package/dist/lexical/ui/ContentEditable.js +14 -5
- package/dist/lexical/ui/ContentEditable.js.map +1 -1
- package/dist/lexical/ui/ContentEditable.scss +105 -0
- package/dist/lexical/ui/icons/AI/index.js +37 -13
- package/dist/lexical/ui/icons/AI/index.js.map +1 -1
- package/dist/lexical/ui/icons/Add/index.js +19 -7
- package/dist/lexical/ui/icons/Add/index.js.map +1 -1
- package/dist/lexical/ui/icons/AlignCenter/index.js +25 -9
- package/dist/lexical/ui/icons/AlignCenter/index.js.map +1 -1
- package/dist/lexical/ui/icons/AlignJustify/index.js +25 -9
- package/dist/lexical/ui/icons/AlignJustify/index.js.map +1 -1
- package/dist/lexical/ui/icons/AlignLeft/index.js +25 -9
- package/dist/lexical/ui/icons/AlignLeft/index.js.map +1 -1
- package/dist/lexical/ui/icons/AlignRight/index.js +25 -9
- package/dist/lexical/ui/icons/AlignRight/index.js.map +1 -1
- package/dist/lexical/ui/icons/Block/index.js +25 -9
- package/dist/lexical/ui/icons/Block/index.js.map +1 -1
- package/dist/lexical/ui/icons/Blockquote/index.js +13 -5
- package/dist/lexical/ui/icons/Blockquote/index.js.map +1 -1
- package/dist/lexical/ui/icons/Bold/index.js +13 -5
- package/dist/lexical/ui/icons/Bold/index.js.map +1 -1
- package/dist/lexical/ui/icons/Checklist/index.js +19 -7
- package/dist/lexical/ui/icons/Checklist/index.js.map +1 -1
- package/dist/lexical/ui/icons/Code/index.js +19 -7
- package/dist/lexical/ui/icons/Code/index.js.map +1 -1
- package/dist/lexical/ui/icons/CodeBlock/index.js +13 -5
- package/dist/lexical/ui/icons/CodeBlock/index.js.map +1 -1
- package/dist/lexical/ui/icons/Collapse/index.js +13 -5
- package/dist/lexical/ui/icons/Collapse/index.js.map +1 -1
- package/dist/lexical/ui/icons/H1/index.js +13 -5
- package/dist/lexical/ui/icons/H1/index.js.map +1 -1
- package/dist/lexical/ui/icons/H2/index.js +13 -5
- package/dist/lexical/ui/icons/H2/index.js.map +1 -1
- package/dist/lexical/ui/icons/H3/index.js +13 -5
- package/dist/lexical/ui/icons/H3/index.js.map +1 -1
- package/dist/lexical/ui/icons/H4/index.js +13 -5
- package/dist/lexical/ui/icons/H4/index.js.map +1 -1
- package/dist/lexical/ui/icons/H5/index.js +13 -5
- package/dist/lexical/ui/icons/H5/index.js.map +1 -1
- package/dist/lexical/ui/icons/H6/index.js +13 -5
- package/dist/lexical/ui/icons/H6/index.js.map +1 -1
- package/dist/lexical/ui/icons/HorizontalRule/index.js +13 -5
- package/dist/lexical/ui/icons/HorizontalRule/index.js.map +1 -1
- package/dist/lexical/ui/icons/IndentDecrease/index.js +31 -11
- package/dist/lexical/ui/icons/IndentDecrease/index.js.map +1 -1
- package/dist/lexical/ui/icons/IndentIncrease/index.js +31 -11
- package/dist/lexical/ui/icons/IndentIncrease/index.js.map +1 -1
- package/dist/lexical/ui/icons/InlineBlocks/index.js +13 -5
- package/dist/lexical/ui/icons/InlineBlocks/index.js.map +1 -1
- package/dist/lexical/ui/icons/Italic/index.js +13 -5
- package/dist/lexical/ui/icons/Italic/index.js.map +1 -1
- package/dist/lexical/ui/icons/Link/index.js +13 -5
- package/dist/lexical/ui/icons/Link/index.js.map +1 -1
- package/dist/lexical/ui/icons/Meatballs/index.js +25 -9
- package/dist/lexical/ui/icons/Meatballs/index.js.map +1 -1
- package/dist/lexical/ui/icons/OrderedList/index.js +37 -13
- package/dist/lexical/ui/icons/OrderedList/index.js.map +1 -1
- package/dist/lexical/ui/icons/Relationship/index.js +37 -13
- package/dist/lexical/ui/icons/Relationship/index.js.map +1 -1
- package/dist/lexical/ui/icons/Strikethrough/index.js +19 -7
- package/dist/lexical/ui/icons/Strikethrough/index.js.map +1 -1
- package/dist/lexical/ui/icons/Subscript/index.js +13 -5
- package/dist/lexical/ui/icons/Subscript/index.js.map +1 -1
- package/dist/lexical/ui/icons/Superscript/index.js +13 -5
- package/dist/lexical/ui/icons/Superscript/index.js.map +1 -1
- package/dist/lexical/ui/icons/Table/index.js +13 -5
- package/dist/lexical/ui/icons/Table/index.js.map +1 -1
- package/dist/lexical/ui/icons/Text/index.js +13 -5
- package/dist/lexical/ui/icons/Text/index.js.map +1 -1
- package/dist/lexical/ui/icons/TextState/index.js +7 -3
- package/dist/lexical/ui/icons/TextState/index.js.map +1 -1
- package/dist/lexical/ui/icons/Underline/index.js +19 -7
- package/dist/lexical/ui/icons/Underline/index.js.map +1 -1
- package/dist/lexical/ui/icons/UnorderedList/index.js +43 -15
- package/dist/lexical/ui/icons/UnorderedList/index.js.map +1 -1
- package/dist/lexical/ui/icons/Upload/index.js +25 -9
- package/dist/lexical/ui/icons/Upload/index.js.map +1 -1
- package/dist/packages/@lexical/markdown/MarkdownShortcuts.js +2 -0
- package/dist/packages/@lexical/markdown/MarkdownShortcuts.js.map +1 -1
- package/dist/packages/@lexical/markdown/importTextFormatTransformer.js +2 -0
- package/dist/packages/@lexical/markdown/importTextFormatTransformer.js.map +1 -1
- package/dist/packages/@lexical/markdown/importTextMatchTransformer.js +2 -0
- package/dist/packages/@lexical/markdown/importTextMatchTransformer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/Drawer.js +19 -7
- package/dist/utilities/fieldsDrawer/Drawer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.js +19 -7
- package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalDocumentDrawer.js +7 -3
- package/dist/utilities/fieldsDrawer/useLexicalDocumentDrawer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalListDrawer.js +7 -3
- package/dist/utilities/fieldsDrawer/useLexicalListDrawer.js.map +1 -1
- package/dist/utilities/migrateSlateToLexical/migrateDocumentFieldsRecursively.js +2 -0
- package/dist/utilities/migrateSlateToLexical/migrateDocumentFieldsRecursively.js.map +1 -1
- package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.js +2 -0
- package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.js.map +1 -1
- package/package.json +8 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
|
|
3
3
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
|
|
4
4
|
import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
|
|
5
5
|
import { mergeRegister } from '@lexical/utils';
|
|
@@ -11,23 +11,36 @@ import { useEditorConfigContext } from '../../../../../lexical/config/client/Edi
|
|
|
11
11
|
import { getDOMRangeRect } from '../../../../../lexical/utils/getDOMRangeRect.js';
|
|
12
12
|
import { setFloatingElemPosition } from '../../../../../lexical/utils/setFloatingElemPosition.js';
|
|
13
13
|
import { ToolbarButton } from '../../../shared/ToolbarButton/index.js';
|
|
14
|
+
import './index.scss';
|
|
14
15
|
import { ToolbarDropdown } from '../../../shared/ToolbarDropdown/index.js';
|
|
15
16
|
function ButtonGroupItem({ anchorElem, editor, item }) {
|
|
16
17
|
if (item.Component) {
|
|
17
|
-
return item?.Component && /*#__PURE__*/
|
|
18
|
+
return item?.Component && /*#__PURE__*/ _jsxDEV(item.Component, {
|
|
18
19
|
anchorElem: anchorElem,
|
|
19
20
|
editor: editor,
|
|
20
21
|
item: item
|
|
21
|
-
}, item.key
|
|
22
|
+
}, item.key, false, {
|
|
23
|
+
fileName: "src/features/toolbars/inline/client/Toolbar/index.tsx",
|
|
24
|
+
lineNumber: 41,
|
|
25
|
+
columnNumber: 9
|
|
26
|
+
}, this);
|
|
22
27
|
}
|
|
23
28
|
if (!item.ChildComponent) {
|
|
24
29
|
return null;
|
|
25
30
|
}
|
|
26
|
-
return /*#__PURE__*/
|
|
31
|
+
return /*#__PURE__*/ _jsxDEV(ToolbarButton, {
|
|
27
32
|
editor: editor,
|
|
28
33
|
item: item,
|
|
29
|
-
children: /*#__PURE__*/
|
|
30
|
-
|
|
34
|
+
children: /*#__PURE__*/ _jsxDEV(item.ChildComponent, {}, void 0, false, {
|
|
35
|
+
fileName: "src/features/toolbars/inline/client/Toolbar/index.tsx",
|
|
36
|
+
lineNumber: 51,
|
|
37
|
+
columnNumber: 7
|
|
38
|
+
}, this)
|
|
39
|
+
}, item.key, false, {
|
|
40
|
+
fileName: "src/features/toolbars/inline/client/Toolbar/index.tsx",
|
|
41
|
+
lineNumber: 50,
|
|
42
|
+
columnNumber: 5
|
|
43
|
+
}, this);
|
|
31
44
|
}
|
|
32
45
|
function ToolbarGroupComponent({ anchorElem, editor, group, index }) {
|
|
33
46
|
const { editorConfig } = useEditorConfigContext();
|
|
@@ -55,36 +68,56 @@ function ToolbarGroupComponent({ anchorElem, editor, group, index }) {
|
|
|
55
68
|
}, [
|
|
56
69
|
group
|
|
57
70
|
]);
|
|
58
|
-
return /*#__PURE__*/
|
|
71
|
+
return /*#__PURE__*/ _jsxDEV("div", {
|
|
59
72
|
className: `inline-toolbar-popup__group inline-toolbar-popup__group-${group.key}`,
|
|
60
73
|
"data-toolbar-group-key": group.key,
|
|
61
74
|
children: [
|
|
62
|
-
group.type === 'dropdown' && group.items.length ? DropdownIcon ? /*#__PURE__*/
|
|
75
|
+
group.type === 'dropdown' && group.items.length ? DropdownIcon ? /*#__PURE__*/ _jsxDEV(ToolbarDropdown, {
|
|
63
76
|
anchorElem: anchorElem,
|
|
64
77
|
editor: editor,
|
|
65
78
|
group: group,
|
|
66
79
|
Icon: DropdownIcon,
|
|
67
80
|
maxActiveItems: group.maxActiveItems ?? 1,
|
|
68
81
|
onActiveChange: onActiveChange
|
|
69
|
-
}
|
|
82
|
+
}, void 0, false, {
|
|
83
|
+
fileName: "src/features/toolbars/inline/client/Toolbar/index.tsx",
|
|
84
|
+
lineNumber: 103,
|
|
85
|
+
columnNumber: 11
|
|
86
|
+
}, this) : /*#__PURE__*/ _jsxDEV(ToolbarDropdown, {
|
|
70
87
|
anchorElem: anchorElem,
|
|
71
88
|
editor: editor,
|
|
72
89
|
group: group,
|
|
73
90
|
maxActiveItems: group.maxActiveItems ?? 1,
|
|
74
91
|
onActiveChange: onActiveChange
|
|
75
|
-
}
|
|
92
|
+
}, void 0, false, {
|
|
93
|
+
fileName: "src/features/toolbars/inline/client/Toolbar/index.tsx",
|
|
94
|
+
lineNumber: 112,
|
|
95
|
+
columnNumber: 11
|
|
96
|
+
}, this) : null,
|
|
76
97
|
group.type === 'buttons' && group.items.length ? group.items.map((item)=>{
|
|
77
|
-
return /*#__PURE__*/
|
|
98
|
+
return /*#__PURE__*/ _jsxDEV(ButtonGroupItem, {
|
|
78
99
|
anchorElem: anchorElem,
|
|
79
100
|
editor: editor,
|
|
80
101
|
item: item
|
|
81
|
-
}, item.key
|
|
102
|
+
}, item.key, false, {
|
|
103
|
+
fileName: "src/features/toolbars/inline/client/Toolbar/index.tsx",
|
|
104
|
+
lineNumber: 124,
|
|
105
|
+
columnNumber: 15
|
|
106
|
+
}, this);
|
|
82
107
|
}) : null,
|
|
83
|
-
index < editorConfig.features.toolbarInline?.groups.length - 1 && /*#__PURE__*/
|
|
108
|
+
index < editorConfig.features.toolbarInline?.groups.length - 1 && /*#__PURE__*/ _jsxDEV("div", {
|
|
84
109
|
className: "divider"
|
|
85
|
-
}
|
|
110
|
+
}, void 0, false, {
|
|
111
|
+
fileName: "src/features/toolbars/inline/client/Toolbar/index.tsx",
|
|
112
|
+
lineNumber: 129,
|
|
113
|
+
columnNumber: 9
|
|
114
|
+
}, this)
|
|
86
115
|
]
|
|
87
|
-
}, group.key
|
|
116
|
+
}, group.key, true, {
|
|
117
|
+
fileName: "src/features/toolbars/inline/client/Toolbar/index.tsx",
|
|
118
|
+
lineNumber: 96,
|
|
119
|
+
columnNumber: 5
|
|
120
|
+
}, this);
|
|
88
121
|
}
|
|
89
122
|
function InlineToolbar({ anchorElem, editor }) {
|
|
90
123
|
const floatingToolbarRef = useRef(null);
|
|
@@ -222,24 +255,36 @@ function InlineToolbar({ anchorElem, editor }) {
|
|
|
222
255
|
editor,
|
|
223
256
|
$updateTextFormatFloatingToolbar
|
|
224
257
|
]);
|
|
225
|
-
return /*#__PURE__*/
|
|
258
|
+
return /*#__PURE__*/ _jsxDEV("div", {
|
|
226
259
|
className: "inline-toolbar-popup",
|
|
227
260
|
ref: floatingToolbarRef,
|
|
228
261
|
children: [
|
|
229
|
-
/*#__PURE__*/
|
|
262
|
+
/*#__PURE__*/ _jsxDEV("div", {
|
|
230
263
|
className: "caret",
|
|
231
264
|
ref: caretRef
|
|
232
|
-
}
|
|
265
|
+
}, void 0, false, {
|
|
266
|
+
fileName: "src/features/toolbars/inline/client/Toolbar/index.tsx",
|
|
267
|
+
lineNumber: 300,
|
|
268
|
+
columnNumber: 7
|
|
269
|
+
}, this),
|
|
233
270
|
editorConfig?.features && editorConfig.features?.toolbarInline?.groups.map((group, i)=>{
|
|
234
|
-
return /*#__PURE__*/
|
|
271
|
+
return /*#__PURE__*/ _jsxDEV(ToolbarGroupComponent, {
|
|
235
272
|
anchorElem: anchorElem,
|
|
236
273
|
editor: editor,
|
|
237
274
|
group: group,
|
|
238
275
|
index: i
|
|
239
|
-
}, group.key
|
|
276
|
+
}, group.key, false, {
|
|
277
|
+
fileName: "src/features/toolbars/inline/client/Toolbar/index.tsx",
|
|
278
|
+
lineNumber: 304,
|
|
279
|
+
columnNumber: 13
|
|
280
|
+
}, this);
|
|
240
281
|
})
|
|
241
282
|
]
|
|
242
|
-
}
|
|
283
|
+
}, void 0, true, {
|
|
284
|
+
fileName: "src/features/toolbars/inline/client/Toolbar/index.tsx",
|
|
285
|
+
lineNumber: 299,
|
|
286
|
+
columnNumber: 5
|
|
287
|
+
}, this);
|
|
243
288
|
}
|
|
244
289
|
function useInlineToolbar(editor, anchorElem) {
|
|
245
290
|
const [isText, setIsText] = useState(false);
|
|
@@ -310,10 +355,14 @@ function useInlineToolbar(editor, anchorElem) {
|
|
|
310
355
|
if (!isText || !isEditable) {
|
|
311
356
|
return null;
|
|
312
357
|
}
|
|
313
|
-
return /*#__PURE__*/ createPortal(/*#__PURE__*/
|
|
358
|
+
return /*#__PURE__*/ createPortal(/*#__PURE__*/ _jsxDEV(InlineToolbar, {
|
|
314
359
|
anchorElem: anchorElem,
|
|
315
360
|
editor: editor
|
|
316
|
-
}
|
|
361
|
+
}, void 0, false, {
|
|
362
|
+
fileName: "src/features/toolbars/inline/client/Toolbar/index.tsx",
|
|
363
|
+
lineNumber: 399,
|
|
364
|
+
columnNumber: 23
|
|
365
|
+
}, this), anchorElem);
|
|
317
366
|
}
|
|
318
367
|
export const InlineToolbarPlugin = ({ anchorElem })=>{
|
|
319
368
|
const [editor] = useLexicalComposerContext();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/features/toolbars/inline/client/Toolbar/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { mergeRegister } from '@lexical/utils'\nimport {\n $getSelection,\n $isRangeSelection,\n $isTextNode,\n COMMAND_PRIORITY_LOW,\n getDOMSelection,\n SELECTION_CHANGE_COMMAND,\n} from 'lexical'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport * as React from 'react'\nimport { createPortal } from 'react-dom'\n\nimport type { PluginComponentWithAnchor } from '../../../../typesClient.js'\nimport type { ToolbarGroup, ToolbarGroupItem } from '../../../types.js'\n\nimport { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport { getDOMRangeRect } from '../../../../../lexical/utils/getDOMRangeRect.js'\nimport { setFloatingElemPosition } from '../../../../../lexical/utils/setFloatingElemPosition.js'\nimport { ToolbarButton } from '../../../shared/ToolbarButton/index.js'\nimport './index.scss'\nimport { ToolbarDropdown } from '../../../shared/ToolbarDropdown/index.js'\n\nfunction ButtonGroupItem({\n anchorElem,\n editor,\n item,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n item: ToolbarGroupItem\n}): React.ReactNode {\n if (item.Component) {\n return (\n item?.Component && (\n <item.Component anchorElem={anchorElem} editor={editor} item={item} key={item.key} />\n )\n )\n }\n if (!item.ChildComponent) {\n return null\n }\n\n return (\n <ToolbarButton editor={editor} item={item} key={item.key}>\n <item.ChildComponent />\n </ToolbarButton>\n )\n}\n\nfunction ToolbarGroupComponent({\n anchorElem,\n editor,\n group,\n index,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n group: ToolbarGroup\n index: number\n}): React.ReactNode {\n const { editorConfig } = useEditorConfigContext()\n\n const [DropdownIcon, setDropdownIcon] = React.useState<React.FC | undefined>()\n\n React.useEffect(() => {\n if (group?.type === 'dropdown' && group.items.length && group.ChildComponent) {\n setDropdownIcon(() => group.ChildComponent)\n } else {\n setDropdownIcon(undefined)\n }\n }, [group])\n\n const onActiveChange = useCallback(\n ({ activeItems }: { activeItems: ToolbarGroupItem[] }) => {\n if (!activeItems.length) {\n if (group?.type === 'dropdown' && group.items.length && group.ChildComponent) {\n setDropdownIcon(() => group.ChildComponent)\n } else {\n setDropdownIcon(undefined)\n }\n return\n }\n const item = activeItems[0]\n setDropdownIcon(() => item?.ChildComponent)\n },\n [group],\n )\n\n return (\n <div\n className={`inline-toolbar-popup__group inline-toolbar-popup__group-${group.key}`}\n data-toolbar-group-key={group.key}\n key={group.key}\n >\n {group.type === 'dropdown' && group.items.length ? (\n DropdownIcon ? (\n <ToolbarDropdown\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n Icon={DropdownIcon}\n maxActiveItems={group.maxActiveItems ?? 1}\n onActiveChange={onActiveChange}\n />\n ) : (\n <ToolbarDropdown\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n maxActiveItems={group.maxActiveItems ?? 1}\n onActiveChange={onActiveChange}\n />\n )\n ) : null}\n {group.type === 'buttons' && group.items.length\n ? group.items.map((item) => {\n return (\n <ButtonGroupItem anchorElem={anchorElem} editor={editor} item={item} key={item.key} />\n )\n })\n : null}\n {index < editorConfig.features.toolbarInline?.groups.length - 1 && (\n <div className=\"divider\" />\n )}\n </div>\n )\n}\n\nfunction InlineToolbar({\n anchorElem,\n editor,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n}): React.ReactNode {\n const floatingToolbarRef = useRef<HTMLDivElement | null>(null)\n const caretRef = useRef<HTMLDivElement | null>(null)\n\n const { editorConfig } = useEditorConfigContext()\n\n const closeFloatingToolbar = useCallback(() => {\n if (floatingToolbarRef?.current) {\n const isOpacityZero = floatingToolbarRef.current.style.opacity === '0'\n const isPointerEventsNone = floatingToolbarRef.current.style.pointerEvents === 'none'\n\n if (!isOpacityZero) {\n floatingToolbarRef.current.style.opacity = '0'\n }\n if (!isPointerEventsNone) {\n floatingToolbarRef.current.style.pointerEvents = 'none'\n }\n }\n }, [floatingToolbarRef])\n\n const mouseMoveListener = useCallback(\n (e: MouseEvent) => {\n if (floatingToolbarRef?.current && (e.buttons === 1 || e.buttons === 3)) {\n const isOpacityZero = floatingToolbarRef.current.style.opacity === '0'\n const isPointerEventsNone = floatingToolbarRef.current.style.pointerEvents === 'none'\n if (!isOpacityZero || !isPointerEventsNone) {\n // Check if the mouse is not over the popup\n const x = e.clientX\n const y = e.clientY\n const elementUnderMouse = document.elementFromPoint(x, y)\n if (!floatingToolbarRef.current.contains(elementUnderMouse)) {\n // Mouse is not over the target element => not a normal click, but probably a drag\n closeFloatingToolbar()\n }\n }\n }\n },\n [closeFloatingToolbar],\n )\n\n const mouseUpListener = useCallback(() => {\n if (floatingToolbarRef?.current) {\n if (floatingToolbarRef.current.style.opacity !== '1') {\n floatingToolbarRef.current.style.opacity = '1'\n }\n if (floatingToolbarRef.current.style.pointerEvents !== 'auto') {\n floatingToolbarRef.current.style.pointerEvents = 'auto'\n }\n }\n }, [])\n\n useEffect(() => {\n document.addEventListener('mousemove', mouseMoveListener)\n document.addEventListener('mouseup', mouseUpListener)\n\n return () => {\n document.removeEventListener('mousemove', mouseMoveListener)\n document.removeEventListener('mouseup', mouseUpListener)\n }\n }, [floatingToolbarRef, mouseMoveListener, mouseUpListener])\n\n const $updateTextFormatFloatingToolbar = useCallback(() => {\n const selection = $getSelection()\n\n const nativeSelection = getDOMSelection(editor._window)\n\n if (floatingToolbarRef.current === null) {\n return\n }\n\n const possibleLinkEditor = anchorElem.querySelector(':scope > .link-editor')\n const isLinkEditorVisible =\n possibleLinkEditor !== null &&\n 'style' in possibleLinkEditor &&\n possibleLinkEditor?.style?.['opacity' as keyof typeof possibleLinkEditor.style] === '1'\n\n const rootElement = editor.getRootElement()\n if (\n selection !== null &&\n nativeSelection !== null &&\n !nativeSelection.isCollapsed &&\n rootElement !== null &&\n rootElement.contains(nativeSelection.anchorNode)\n ) {\n const rangeRect = getDOMRangeRect(nativeSelection, rootElement)\n\n // Position floating toolbar\n const offsetIfFlipped = setFloatingElemPosition({\n alwaysDisplayOnTop: isLinkEditorVisible,\n anchorElem,\n floatingElem: floatingToolbarRef.current,\n horizontalPosition: 'center',\n targetRect: rangeRect,\n })\n\n // Position caret\n if (caretRef.current) {\n setFloatingElemPosition({\n anchorElem: floatingToolbarRef.current,\n anchorFlippedOffset: offsetIfFlipped,\n floatingElem: caretRef.current,\n horizontalOffset: 5,\n horizontalPosition: 'center',\n specialHandlingForCaret: true,\n targetRect: rangeRect,\n verticalGap: 8,\n })\n }\n } else {\n closeFloatingToolbar()\n }\n }, [editor, closeFloatingToolbar, anchorElem])\n\n useEffect(() => {\n const scrollerElem = anchorElem.parentElement\n\n const update = () => {\n editor.getEditorState().read(() => {\n $updateTextFormatFloatingToolbar()\n })\n }\n\n window.addEventListener('resize', update)\n if (scrollerElem) {\n scrollerElem.addEventListener('scroll', update)\n }\n\n return () => {\n window.removeEventListener('resize', update)\n if (scrollerElem) {\n scrollerElem.removeEventListener('scroll', update)\n }\n }\n }, [editor, $updateTextFormatFloatingToolbar, anchorElem])\n\n useEffect(() => {\n editor.getEditorState().read(() => {\n $updateTextFormatFloatingToolbar()\n })\n return mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n $updateTextFormatFloatingToolbar()\n })\n }),\n\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n () => {\n $updateTextFormatFloatingToolbar()\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor, $updateTextFormatFloatingToolbar])\n\n return (\n <div className=\"inline-toolbar-popup\" ref={floatingToolbarRef}>\n <div className=\"caret\" ref={caretRef} />\n {editorConfig?.features &&\n editorConfig.features?.toolbarInline?.groups.map((group, i) => {\n return (\n <ToolbarGroupComponent\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n index={i}\n key={group.key}\n />\n )\n })}\n </div>\n )\n}\n\nfunction useInlineToolbar(\n editor: LexicalEditor,\n anchorElem: HTMLElement,\n): null | React.ReactElement {\n const [isText, setIsText] = useState(false)\n const isEditable = useLexicalEditable()\n\n const updatePopup = useCallback(() => {\n editor.getEditorState().read(() => {\n // Should not to pop up the floating toolbar when using IME input\n if (editor.isComposing()) {\n return\n }\n const selection = $getSelection()\n const nativeSelection = getDOMSelection(editor._window)\n const rootElement = editor.getRootElement()\n\n if (\n nativeSelection !== null &&\n (!$isRangeSelection(selection) ||\n rootElement === null ||\n !rootElement.contains(nativeSelection.anchorNode))\n ) {\n setIsText(false)\n return\n }\n\n if (!$isRangeSelection(selection)) {\n return\n }\n\n if (selection.getTextContent() !== '') {\n const nodes = selection.getNodes()\n let foundNodeWithText = false\n for (const node of nodes) {\n if ($isTextNode(node)) {\n setIsText(true)\n foundNodeWithText = true\n break\n }\n }\n if (!foundNodeWithText) {\n setIsText(false)\n }\n } else {\n setIsText(false)\n }\n\n const rawTextContent = selection.getTextContent().replace(/\\n/g, '')\n if (!selection.isCollapsed() && rawTextContent === '') {\n setIsText(false)\n return\n }\n })\n }, [editor])\n\n useEffect(() => {\n document.addEventListener('selectionchange', updatePopup)\n document.addEventListener('mouseup', updatePopup)\n return () => {\n document.removeEventListener('selectionchange', updatePopup)\n document.removeEventListener('mouseup', updatePopup)\n }\n }, [updatePopup])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(() => {\n updatePopup()\n }),\n editor.registerRootListener(() => {\n if (editor.getRootElement() === null) {\n setIsText(false)\n }\n }),\n )\n }, [editor, updatePopup])\n\n if (!isText || !isEditable) {\n return null\n }\n\n return createPortal(<InlineToolbar anchorElem={anchorElem} editor={editor} />, anchorElem)\n}\n\nexport const InlineToolbarPlugin: PluginComponentWithAnchor<undefined> = ({ anchorElem }) => {\n const [editor] = useLexicalComposerContext()\n\n return useInlineToolbar(editor, anchorElem)\n}\n"],"names":["useLexicalComposerContext","useLexicalEditable","mergeRegister","$getSelection","$isRangeSelection","$isTextNode","COMMAND_PRIORITY_LOW","getDOMSelection","SELECTION_CHANGE_COMMAND","useCallback","useEffect","useRef","useState","React","createPortal","useEditorConfigContext","getDOMRangeRect","setFloatingElemPosition","ToolbarButton","ToolbarDropdown","ButtonGroupItem","anchorElem","editor","item","Component","key","ChildComponent","ToolbarGroupComponent","group","index","editorConfig","DropdownIcon","setDropdownIcon","type","items","length","undefined","onActiveChange","activeItems","div","className","data-toolbar-group-key","Icon","maxActiveItems","map","features","toolbarInline","groups","InlineToolbar","floatingToolbarRef","caretRef","closeFloatingToolbar","current","isOpacityZero","style","opacity","isPointerEventsNone","pointerEvents","mouseMoveListener","e","buttons","x","clientX","y","clientY","elementUnderMouse","document","elementFromPoint","contains","mouseUpListener","addEventListener","removeEventListener","$updateTextFormatFloatingToolbar","selection","nativeSelection","_window","possibleLinkEditor","querySelector","isLinkEditorVisible","rootElement","getRootElement","isCollapsed","anchorNode","rangeRect","offsetIfFlipped","alwaysDisplayOnTop","floatingElem","horizontalPosition","targetRect","anchorFlippedOffset","horizontalOffset","specialHandlingForCaret","verticalGap","scrollerElem","parentElement","update","getEditorState","read","window","registerUpdateListener","editorState","registerCommand","ref","i","useInlineToolbar","isText","setIsText","isEditable","updatePopup","isComposing","getTextContent","nodes","getNodes","foundNodeWithText","node","rawTextContent","replace","registerRootListener","InlineToolb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OAAO,MAAM;gBACpC0B,UAAU;YACZ;QACF;IAEJ,GAAG;QAACpF;QAAQsF;KAAY;IAExB,IAAI,CAACH,UAAU,CAACE,YAAY;QAC1B,OAAO;IACT;IAEA,qBAAO7F,2BAAa,KAACkC;QAAc3B,YAAYA;QAAYC,QAAQA;QAAYD;AACjF;AAEA,OAAO,MAAMiG,sBAA4D,CAAC,EAAEjG,UAAU,EAAE;IACtF,MAAM,CAACC,OAAO,GAAGtB;IAEjB,OAAOwG,iBAAiBlF,QAAQD;AAClC,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/features/toolbars/inline/client/Toolbar/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { mergeRegister } from '@lexical/utils'\nimport {\n $getSelection,\n $isRangeSelection,\n $isTextNode,\n COMMAND_PRIORITY_LOW,\n getDOMSelection,\n SELECTION_CHANGE_COMMAND,\n} from 'lexical'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport * as React from 'react'\nimport { createPortal } from 'react-dom'\n\nimport type { PluginComponentWithAnchor } from '../../../../typesClient.js'\nimport type { ToolbarGroup, ToolbarGroupItem } from '../../../types.js'\n\nimport { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport { getDOMRangeRect } from '../../../../../lexical/utils/getDOMRangeRect.js'\nimport { setFloatingElemPosition } from '../../../../../lexical/utils/setFloatingElemPosition.js'\nimport { ToolbarButton } from '../../../shared/ToolbarButton/index.js'\nimport './index.scss'\nimport { ToolbarDropdown } from '../../../shared/ToolbarDropdown/index.js'\n\nfunction ButtonGroupItem({\n anchorElem,\n editor,\n item,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n item: ToolbarGroupItem\n}): React.ReactNode {\n if (item.Component) {\n return (\n item?.Component && (\n <item.Component anchorElem={anchorElem} editor={editor} item={item} key={item.key} />\n )\n )\n }\n if (!item.ChildComponent) {\n return null\n }\n\n return (\n <ToolbarButton editor={editor} item={item} key={item.key}>\n <item.ChildComponent />\n </ToolbarButton>\n )\n}\n\nfunction ToolbarGroupComponent({\n anchorElem,\n editor,\n group,\n index,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n group: ToolbarGroup\n index: number\n}): React.ReactNode {\n const { editorConfig } = useEditorConfigContext()\n\n const [DropdownIcon, setDropdownIcon] = React.useState<React.FC | undefined>()\n\n React.useEffect(() => {\n if (group?.type === 'dropdown' && group.items.length && group.ChildComponent) {\n setDropdownIcon(() => group.ChildComponent)\n } else {\n setDropdownIcon(undefined)\n }\n }, [group])\n\n const onActiveChange = useCallback(\n ({ activeItems }: { activeItems: ToolbarGroupItem[] }) => {\n if (!activeItems.length) {\n if (group?.type === 'dropdown' && group.items.length && group.ChildComponent) {\n setDropdownIcon(() => group.ChildComponent)\n } else {\n setDropdownIcon(undefined)\n }\n return\n }\n const item = activeItems[0]\n setDropdownIcon(() => item?.ChildComponent)\n },\n [group],\n )\n\n return (\n <div\n className={`inline-toolbar-popup__group inline-toolbar-popup__group-${group.key}`}\n data-toolbar-group-key={group.key}\n key={group.key}\n >\n {group.type === 'dropdown' && group.items.length ? (\n DropdownIcon ? (\n <ToolbarDropdown\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n Icon={DropdownIcon}\n maxActiveItems={group.maxActiveItems ?? 1}\n onActiveChange={onActiveChange}\n />\n ) : (\n <ToolbarDropdown\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n maxActiveItems={group.maxActiveItems ?? 1}\n onActiveChange={onActiveChange}\n />\n )\n ) : null}\n {group.type === 'buttons' && group.items.length\n ? group.items.map((item) => {\n return (\n <ButtonGroupItem anchorElem={anchorElem} editor={editor} item={item} key={item.key} />\n )\n })\n : null}\n {index < editorConfig.features.toolbarInline?.groups.length - 1 && (\n <div className=\"divider\" />\n )}\n </div>\n )\n}\n\nfunction InlineToolbar({\n anchorElem,\n editor,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n}): React.ReactNode {\n const floatingToolbarRef = useRef<HTMLDivElement | null>(null)\n const caretRef = useRef<HTMLDivElement | null>(null)\n\n const { editorConfig } = useEditorConfigContext()\n\n const closeFloatingToolbar = useCallback(() => {\n if (floatingToolbarRef?.current) {\n const isOpacityZero = floatingToolbarRef.current.style.opacity === '0'\n const isPointerEventsNone = floatingToolbarRef.current.style.pointerEvents === 'none'\n\n if (!isOpacityZero) {\n floatingToolbarRef.current.style.opacity = '0'\n }\n if (!isPointerEventsNone) {\n floatingToolbarRef.current.style.pointerEvents = 'none'\n }\n }\n }, [floatingToolbarRef])\n\n const mouseMoveListener = useCallback(\n (e: MouseEvent) => {\n if (floatingToolbarRef?.current && (e.buttons === 1 || e.buttons === 3)) {\n const isOpacityZero = floatingToolbarRef.current.style.opacity === '0'\n const isPointerEventsNone = floatingToolbarRef.current.style.pointerEvents === 'none'\n if (!isOpacityZero || !isPointerEventsNone) {\n // Check if the mouse is not over the popup\n const x = e.clientX\n const y = e.clientY\n const elementUnderMouse = document.elementFromPoint(x, y)\n if (!floatingToolbarRef.current.contains(elementUnderMouse)) {\n // Mouse is not over the target element => not a normal click, but probably a drag\n closeFloatingToolbar()\n }\n }\n }\n },\n [closeFloatingToolbar],\n )\n\n const mouseUpListener = useCallback(() => {\n if (floatingToolbarRef?.current) {\n if (floatingToolbarRef.current.style.opacity !== '1') {\n floatingToolbarRef.current.style.opacity = '1'\n }\n if (floatingToolbarRef.current.style.pointerEvents !== 'auto') {\n floatingToolbarRef.current.style.pointerEvents = 'auto'\n }\n }\n }, [])\n\n useEffect(() => {\n document.addEventListener('mousemove', mouseMoveListener)\n document.addEventListener('mouseup', mouseUpListener)\n\n return () => {\n document.removeEventListener('mousemove', mouseMoveListener)\n document.removeEventListener('mouseup', mouseUpListener)\n }\n }, [floatingToolbarRef, mouseMoveListener, mouseUpListener])\n\n const $updateTextFormatFloatingToolbar = useCallback(() => {\n const selection = $getSelection()\n\n const nativeSelection = getDOMSelection(editor._window)\n\n if (floatingToolbarRef.current === null) {\n return\n }\n\n const possibleLinkEditor = anchorElem.querySelector(':scope > .link-editor')\n const isLinkEditorVisible =\n possibleLinkEditor !== null &&\n 'style' in possibleLinkEditor &&\n possibleLinkEditor?.style?.['opacity' as keyof typeof possibleLinkEditor.style] === '1'\n\n const rootElement = editor.getRootElement()\n if (\n selection !== null &&\n nativeSelection !== null &&\n !nativeSelection.isCollapsed &&\n rootElement !== null &&\n rootElement.contains(nativeSelection.anchorNode)\n ) {\n const rangeRect = getDOMRangeRect(nativeSelection, rootElement)\n\n // Position floating toolbar\n const offsetIfFlipped = setFloatingElemPosition({\n alwaysDisplayOnTop: isLinkEditorVisible,\n anchorElem,\n floatingElem: floatingToolbarRef.current,\n horizontalPosition: 'center',\n targetRect: rangeRect,\n })\n\n // Position caret\n if (caretRef.current) {\n setFloatingElemPosition({\n anchorElem: floatingToolbarRef.current,\n anchorFlippedOffset: offsetIfFlipped,\n floatingElem: caretRef.current,\n horizontalOffset: 5,\n horizontalPosition: 'center',\n specialHandlingForCaret: true,\n targetRect: rangeRect,\n verticalGap: 8,\n })\n }\n } else {\n closeFloatingToolbar()\n }\n }, [editor, closeFloatingToolbar, anchorElem])\n\n useEffect(() => {\n const scrollerElem = anchorElem.parentElement\n\n const update = () => {\n editor.getEditorState().read(() => {\n $updateTextFormatFloatingToolbar()\n })\n }\n\n window.addEventListener('resize', update)\n if (scrollerElem) {\n scrollerElem.addEventListener('scroll', update)\n }\n\n return () => {\n window.removeEventListener('resize', update)\n if (scrollerElem) {\n scrollerElem.removeEventListener('scroll', update)\n }\n }\n }, [editor, $updateTextFormatFloatingToolbar, anchorElem])\n\n useEffect(() => {\n editor.getEditorState().read(() => {\n $updateTextFormatFloatingToolbar()\n })\n return mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n $updateTextFormatFloatingToolbar()\n })\n }),\n\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n () => {\n $updateTextFormatFloatingToolbar()\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor, $updateTextFormatFloatingToolbar])\n\n return (\n <div className=\"inline-toolbar-popup\" ref={floatingToolbarRef}>\n <div className=\"caret\" ref={caretRef} />\n {editorConfig?.features &&\n editorConfig.features?.toolbarInline?.groups.map((group, i) => {\n return (\n <ToolbarGroupComponent\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n index={i}\n key={group.key}\n />\n )\n })}\n </div>\n )\n}\n\nfunction useInlineToolbar(\n editor: LexicalEditor,\n anchorElem: HTMLElement,\n): null | React.ReactElement {\n const [isText, setIsText] = useState(false)\n const isEditable = useLexicalEditable()\n\n const updatePopup = useCallback(() => {\n editor.getEditorState().read(() => {\n // Should not to pop up the floating toolbar when using IME input\n if (editor.isComposing()) {\n return\n }\n const selection = $getSelection()\n const nativeSelection = getDOMSelection(editor._window)\n const rootElement = editor.getRootElement()\n\n if (\n nativeSelection !== null &&\n (!$isRangeSelection(selection) ||\n rootElement === null ||\n !rootElement.contains(nativeSelection.anchorNode))\n ) {\n setIsText(false)\n return\n }\n\n if (!$isRangeSelection(selection)) {\n return\n }\n\n if (selection.getTextContent() !== '') {\n const nodes = selection.getNodes()\n let foundNodeWithText = false\n for (const node of nodes) {\n if ($isTextNode(node)) {\n setIsText(true)\n foundNodeWithText = true\n break\n }\n }\n if (!foundNodeWithText) {\n setIsText(false)\n }\n } else {\n setIsText(false)\n }\n\n const rawTextContent = selection.getTextContent().replace(/\\n/g, '')\n if (!selection.isCollapsed() && rawTextContent === '') {\n setIsText(false)\n return\n }\n })\n }, [editor])\n\n useEffect(() => {\n document.addEventListener('selectionchange', updatePopup)\n document.addEventListener('mouseup', updatePopup)\n return () => {\n document.removeEventListener('selectionchange', updatePopup)\n document.removeEventListener('mouseup', updatePopup)\n }\n }, [updatePopup])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(() => {\n updatePopup()\n }),\n editor.registerRootListener(() => {\n if (editor.getRootElement() === null) {\n setIsText(false)\n }\n }),\n )\n }, [editor, updatePopup])\n\n if (!isText || !isEditable) {\n return null\n }\n\n return createPortal(<InlineToolbar anchorElem={anchorElem} editor={editor} />, anchorElem)\n}\n\nexport const InlineToolbarPlugin: PluginComponentWithAnchor<undefined> = ({ anchorElem }) => {\n const [editor] = useLexicalComposerContext()\n\n return useInlineToolbar(editor, anchorElem)\n}\n"],"names":["useLexicalComposerContext","useLexicalEditable","mergeRegister","$getSelection","$isRangeSelection","$isTextNode","COMMAND_PRIORITY_LOW","getDOMSelection","SELECTION_CHANGE_COMMAND","useCallback","useEffect","useRef","useState","React","createPortal","useEditorConfigContext","getDOMRangeRect","setFloatingElemPosition","ToolbarButton","ToolbarDropdown","ButtonGroupItem","anchorElem","editor","item","Component","key","ChildComponent","ToolbarGroupComponent","group","index","editorConfig","DropdownIcon","setDropdownIcon","type","items","length","undefined","onActiveChange","activeItems","div","className","data-toolbar-group-key","Icon","maxActiveItems","map","features","toolbarInline","groups","InlineToolbar","floatingToolbarRef","caretRef","closeFloatingToolbar","current","isOpacityZero","style","opacity","isPointerEventsNone","pointerEvents","mouseMoveListener","e","buttons","x","clientX","y","clientY","elementUnderMouse","document","elementFromPoint","contains","mouseUpListener","addEventListener","removeEventListener","$updateTextFormatFloatingToolbar","selection","nativeSelection","_window","possibleLinkEditor","querySelector","isLinkEditorVisible","rootElement","getRootElement","isCollapsed","anchorNode","rangeRect","offsetIfFlipped","alwaysDisplayOnTop","floatingElem","horizontalPosition","targetRect","anchorFlippedOffset","horizontalOffset","specialHandlingForCaret","verticalGap","scrollerElem","parentElement","update","getEditorState","read","window","registerUpdateListener","editorState","registerCommand","ref","i","useInlineToolbar","isText","setIsText","isEditable","updatePopup","isComposing","getTextContent","nodes","getNodes","foundNodeWithText","node","rawTextContent","replace","registerRootListener","InlineToolbarPlugin"],"mappings":"AAAA;;AAGA,SAASA,yBAAyB,QAAQ,2C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F,OAAO0D,cAAc,OAAO,MAAM;gBACpC0B,UAAU;YACZ;QACF;IAEJ,GAAG;QAACpF;QAAQsF;KAAY;IAExB,IAAI,CAACH,UAAU,CAACE,YAAY;QAC1B,OAAO;IACT;IAEA,qBAAO7F,2BAAa,QAACkC;QAAc3B,YAAYA;QAAYC,QAAQA;;;;;cAAYD;AACjF;AAEA,OAAO,MAAMiG,sBAA4D,CAAC,EAAEjG,UAAU,EAAE;IACtF,MAAM,CAACC,OAAO,GAAGtB;IAEjB,OAAOwG,iBAAiBlF,QAAQD;AAClC,EAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
@import '~@payloadcms/ui/scss';
|
|
2
|
+
|
|
3
|
+
@layer payload-default {
|
|
4
|
+
.inline-toolbar-popup {
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
background: var(--theme-input-bg);
|
|
8
|
+
padding: base(0.2);
|
|
9
|
+
vertical-align: middle;
|
|
10
|
+
position: absolute;
|
|
11
|
+
top: 0;
|
|
12
|
+
left: 0;
|
|
13
|
+
z-index: 2;
|
|
14
|
+
opacity: 0;
|
|
15
|
+
border-radius: $style-radius-m;
|
|
16
|
+
transition: opacity 0.2s;
|
|
17
|
+
will-change: transform;
|
|
18
|
+
box-shadow:
|
|
19
|
+
0px 1px 2px 1px rgba(0, 0, 0, 0.1),
|
|
20
|
+
0px 4px 16px 0px rgba(0, 0, 0, 0.2),
|
|
21
|
+
0px -4px 8px 0px rgba(0, 0, 0, 0.1);
|
|
22
|
+
|
|
23
|
+
.caret {
|
|
24
|
+
z-index: 93;
|
|
25
|
+
position: absolute;
|
|
26
|
+
top: calc(100% - 24px);
|
|
27
|
+
border: base(0.4) solid transparent;
|
|
28
|
+
pointer-events: none;
|
|
29
|
+
border-top-color: var(--theme-input-bg);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&__group {
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
gap: 2px;
|
|
36
|
+
|
|
37
|
+
.icon {
|
|
38
|
+
min-width: 20px;
|
|
39
|
+
height: 20px;
|
|
40
|
+
color: var(--theme-elevation-600);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.divider {
|
|
44
|
+
width: 1px;
|
|
45
|
+
height: 15px;
|
|
46
|
+
background-color: var(--theme-border-color);
|
|
47
|
+
margin: 0 6.25px;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
html[data-theme='light'] {
|
|
52
|
+
.inline-toolbar-popup {
|
|
53
|
+
box-shadow:
|
|
54
|
+
0px 1px 2px 1px rgba(0, 0, 0, 0.05),
|
|
55
|
+
0px 4px 8px 0px rgba(0, 0, 0, 0.1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
|
|
3
3
|
import { mergeRegister } from '@lexical/utils';
|
|
4
4
|
import { $addUpdateTag, $getSelection } from 'lexical';
|
|
5
5
|
import React, { useCallback, useDeferredValue, useEffect, useMemo, useState } from 'react';
|
|
6
6
|
import { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js';
|
|
7
|
+
import './index.scss';
|
|
7
8
|
import { useRunDeprioritized } from '../../../../utilities/useRunDeprioritized.js';
|
|
8
9
|
const baseClass = 'toolbar-popup__button';
|
|
9
10
|
export const ToolbarButton = ({ children, editor, item })=>{
|
|
@@ -96,14 +97,18 @@ export const ToolbarButton = ({ children, editor, item })=>{
|
|
|
96
97
|
// TODO: Find out why exactly it happens and why e.preventDefault() on the mouseDown fixes it. Write that down here, or potentially fix a root cause, if there is any.
|
|
97
98
|
e.preventDefault();
|
|
98
99
|
}, []);
|
|
99
|
-
return /*#__PURE__*/
|
|
100
|
+
return /*#__PURE__*/ _jsxDEV("button", {
|
|
100
101
|
className: className,
|
|
101
102
|
"data-button-key": item.key,
|
|
102
103
|
onClick: handleClick,
|
|
103
104
|
onMouseDown: handleMouseDown,
|
|
104
105
|
type: "button",
|
|
105
106
|
children: children
|
|
106
|
-
}
|
|
107
|
+
}, void 0, false, {
|
|
108
|
+
fileName: "src/features/toolbars/shared/ToolbarButton/index.tsx",
|
|
109
|
+
lineNumber: 105,
|
|
110
|
+
columnNumber: 5
|
|
111
|
+
}, this);
|
|
107
112
|
};
|
|
108
113
|
|
|
109
114
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/features/toolbars/shared/ToolbarButton/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { mergeRegister } from '@lexical/utils'\nimport { $addUpdateTag, $getSelection } from 'lexical'\nimport React, { useCallback, useDeferredValue, useEffect, useMemo, useState } from 'react'\n\nimport type { ToolbarGroupItem } from '../../types.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport './index.scss'\nimport { useRunDeprioritized } from '../../../../utilities/useRunDeprioritized.js'\n\nconst baseClass = 'toolbar-popup__button'\n\nexport const ToolbarButton = ({\n children,\n editor,\n item,\n}: {\n children: React.JSX.Element\n editor: LexicalEditor\n item: ToolbarGroupItem\n}) => {\n const [_state, setState] = useState({ active: false, enabled: true })\n const deferredState = useDeferredValue(_state)\n\n const editorConfigContext = useEditorConfigContext()\n\n const className = useMemo(() => {\n return [\n baseClass,\n !deferredState.enabled ? 'disabled' : '',\n deferredState.active ? 'active' : '',\n item.key ? `${baseClass}-${item.key}` : '',\n ]\n .filter(Boolean)\n .join(' ')\n }, [deferredState, item.key])\n const updateStates = useCallback(() => {\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if (!selection) {\n return\n }\n const newActive = item.isActive\n ? item.isActive({ editor, editorConfigContext, selection })\n : false\n\n const newEnabled = item.isEnabled\n ? item.isEnabled({ editor, editorConfigContext, selection })\n : true\n\n setState((prev) => {\n if (prev.active === newActive && prev.enabled === newEnabled) {\n return prev\n }\n return { active: newActive, enabled: newEnabled }\n })\n })\n }, [editor, editorConfigContext, item])\n\n const runDeprioritized = useRunDeprioritized()\n\n useEffect(() => {\n // Run on mount\n void runDeprioritized(updateStates)\n\n const listener = () => runDeprioritized(updateStates)\n\n const cleanup = mergeRegister(editor.registerUpdateListener(listener))\n document.addEventListener('mouseup', listener)\n\n return () => {\n cleanup()\n document.removeEventListener('mouseup', listener)\n }\n }, [editor, runDeprioritized, updateStates])\n\n const handleClick = useCallback(() => {\n if (!_state.enabled) {\n return\n }\n\n editor.focus(() => {\n editor.update(() => {\n $addUpdateTag('toolbar')\n })\n // We need to wrap the onSelect in the callback, so the editor is properly focused before the onSelect is called.\n item.onSelect?.({\n editor,\n isActive: _state.active,\n })\n })\n }, [editor, item, _state])\n\n const handleMouseDown = useCallback((e: React.MouseEvent) => {\n // This fixes a bug where you are unable to click the button if you are in a NESTED editor (editor in blocks field in editor).\n // Thus only happens if you click on the SVG of the button. Clicking on the outside works. Related issue: https://github.com/payloadcms/payload/issues/4025\n // TODO: Find out why exactly it happens and why e.preventDefault() on the mouseDown fixes it. Write that down here, or potentially fix a root cause, if there is any.\n e.preventDefault()\n }, [])\n\n return (\n <button\n className={className}\n data-button-key={item.key}\n onClick={handleClick}\n onMouseDown={handleMouseDown}\n type=\"button\"\n >\n {children}\n </button>\n )\n}\n"],"names":["mergeRegister","$addUpdateTag","$getSelection","React","useCallback","useDeferredValue","useEffect","useMemo","useState","useEditorConfigContext","useRunDeprioritized","baseClass","ToolbarButton","children","editor","item","_state","setState","active","enabled","deferredState","editorConfigContext","className","key","filter","Boolean","join","updateStates","getEditorState","read","selection","newActive","isActive","newEnabled","isEnabled","prev","runDeprioritized","listener","cleanup","registerUpdateListener","document","addEventListener","removeEventListener","handleClick","focus","update","onSelect","handleMouseDown","e","preventDefault","button","data-button-key","onClick","onMouseDown","type"],"mappings":"AAAA;;AAGA,SAASA,aAAa,QAAQ,iBAAgB;AAC9C,SAASC,aAAa,EAAEC,aAAa,QAAQ,UAAS;AACtD,OAAOC,SAASC,WAAW,EAAEC,gBAAgB,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAI1F,SAASC,sBAAsB,QAAQ,4DAA2D;
|
|
1
|
+
{"version":3,"sources":["../../../../../src/features/toolbars/shared/ToolbarButton/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { mergeRegister } from '@lexical/utils'\nimport { $addUpdateTag, $getSelection } from 'lexical'\nimport React, { useCallback, useDeferredValue, useEffect, useMemo, useState } from 'react'\n\nimport type { ToolbarGroupItem } from '../../types.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport './index.scss'\nimport { useRunDeprioritized } from '../../../../utilities/useRunDeprioritized.js'\n\nconst baseClass = 'toolbar-popup__button'\n\nexport const ToolbarButton = ({\n children,\n editor,\n item,\n}: {\n children: React.JSX.Element\n editor: LexicalEditor\n item: ToolbarGroupItem\n}) => {\n const [_state, setState] = useState({ active: false, enabled: true })\n const deferredState = useDeferredValue(_state)\n\n const editorConfigContext = useEditorConfigContext()\n\n const className = useMemo(() => {\n return [\n baseClass,\n !deferredState.enabled ? 'disabled' : '',\n deferredState.active ? 'active' : '',\n item.key ? `${baseClass}-${item.key}` : '',\n ]\n .filter(Boolean)\n .join(' ')\n }, [deferredState, item.key])\n const updateStates = useCallback(() => {\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if (!selection) {\n return\n }\n const newActive = item.isActive\n ? item.isActive({ editor, editorConfigContext, selection })\n : false\n\n const newEnabled = item.isEnabled\n ? item.isEnabled({ editor, editorConfigContext, selection })\n : true\n\n setState((prev) => {\n if (prev.active === newActive && prev.enabled === newEnabled) {\n return prev\n }\n return { active: newActive, enabled: newEnabled }\n })\n })\n }, [editor, editorConfigContext, item])\n\n const runDeprioritized = useRunDeprioritized()\n\n useEffect(() => {\n // Run on mount\n void runDeprioritized(updateStates)\n\n const listener = () => runDeprioritized(updateStates)\n\n const cleanup = mergeRegister(editor.registerUpdateListener(listener))\n document.addEventListener('mouseup', listener)\n\n return () => {\n cleanup()\n document.removeEventListener('mouseup', listener)\n }\n }, [editor, runDeprioritized, updateStates])\n\n const handleClick = useCallback(() => {\n if (!_state.enabled) {\n return\n }\n\n editor.focus(() => {\n editor.update(() => {\n $addUpdateTag('toolbar')\n })\n // We need to wrap the onSelect in the callback, so the editor is properly focused before the onSelect is called.\n item.onSelect?.({\n editor,\n isActive: _state.active,\n })\n })\n }, [editor, item, _state])\n\n const handleMouseDown = useCallback((e: React.MouseEvent) => {\n // This fixes a bug where you are unable to click the button if you are in a NESTED editor (editor in blocks field in editor).\n // Thus only happens if you click on the SVG of the button. Clicking on the outside works. Related issue: https://github.com/payloadcms/payload/issues/4025\n // TODO: Find out why exactly it happens and why e.preventDefault() on the mouseDown fixes it. Write that down here, or potentially fix a root cause, if there is any.\n e.preventDefault()\n }, [])\n\n return (\n <button\n className={className}\n data-button-key={item.key}\n onClick={handleClick}\n onMouseDown={handleMouseDown}\n type=\"button\"\n >\n {children}\n </button>\n )\n}\n"],"names":["mergeRegister","$addUpdateTag","$getSelection","React","useCallback","useDeferredValue","useEffect","useMemo","useState","useEditorConfigContext","useRunDeprioritized","baseClass","ToolbarButton","children","editor","item","_state","setState","active","enabled","deferredState","editorConfigContext","className","key","filter","Boolean","join","updateStates","getEditorState","read","selection","newActive","isActive","newEnabled","isEnabled","prev","runDeprioritized","listener","cleanup","registerUpdateListener","document","addEventListener","removeEventListener","handleClick","focus","update","onSelect","handleMouseDown","e","preventDefault","button","data-button-key","onClick","onMouseDown","type"],"mappings":"AAAA;;AAGA,SAASA,aAAa,QAAQ,iBAAgB;AAC9C,SAASC,aAAa,EAAEC,aAAa,QAAQ,UAAS;AACtD,OAAOC,SAASC,WAAW,EAAEC,gBAAgB,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ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QACf,KAAK8B,iBAAiBT;QAEtB,MAAMU,WAAW,IAAMD,iBAAiBT;QAExC,MAAMW,UAAUtC,cAAcc,OAAOyB,sBAAsB,CAACF;QAC5DG,SAASC,gBAAgB,CAAC,WAAWJ;QAErC,OAAO;YACLC;YACAE,SAASE,mBAAmB,CAAC,WAAWL;QAC1C;IACF,GAAG;QAACvB;QAAQsB;QAAkBT;KAAa;IAE3C,MAAMgB,cAAcvC,YAAY;QAC9B,IAAI,CAACY,OAAOG,OAAO,EAAE;YACnB;QACF;QAEAL,OAAO8B,KAAK,CAAC;YACX9B,OAAO+B,MAAM,CAAC;gBACZ5C,cAAc;YAChB;YACA,iHAAiH;YACjHc,KAAK+B,QAAQ,GAAG;gBACdhC;gBACAkB,UAAUhB,OAAOE,MAAM;YACzB;QACF;IACF,GAAG;QAACJ;QAAQC;QAAMC;KAAO;IAEzB,MAAM+B,kBAAkB3C,YAAY,CAAC4C;QACnC,8HAA8H;QAC9H,2JAA2J;QAC3J,sKAAsK;QACtKA,EAAEC,cAAc;IAClB,GAAG,EAAE;IAEL,qBACE,QAACC;QACC5B,WAAWA;QACX6B,mBAAiBpC,KAAKQ,GAAG;QACzB6B,SAAST;QACTU,aAAaN;QACbO,MAAK;kBAEJzC;;;;;;AAGP,EAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
@import '~@payloadcms/ui/scss';
|
|
2
|
+
|
|
3
|
+
@layer payload-default {
|
|
4
|
+
.toolbar-popup__button {
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
vertical-align: middle;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
height: 30px;
|
|
10
|
+
width: 30px;
|
|
11
|
+
border: 0;
|
|
12
|
+
background: none;
|
|
13
|
+
border-radius: $style-radius-m;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
padding: 0;
|
|
16
|
+
transition: background-color 0.15s cubic-bezier(0, 0.2, 0.2, 1);
|
|
17
|
+
|
|
18
|
+
&.spaced {
|
|
19
|
+
margin-right: 2px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&:hover:not(.disabled) {
|
|
23
|
+
background-color: var(--theme-elevation-100);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
&.active {
|
|
27
|
+
background-color: var(--theme-elevation-150);
|
|
28
|
+
color: var(--theme-text);
|
|
29
|
+
&:hover {
|
|
30
|
+
background-color: var(--theme-elevation-200);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.icon {
|
|
34
|
+
opacity: 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&.disabled {
|
|
39
|
+
cursor: not-allowed;
|
|
40
|
+
|
|
41
|
+
.icon {
|
|
42
|
+
opacity: 0.2;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
|
|
3
3
|
import { Button } from '@payloadcms/ui';
|
|
4
4
|
import { $addUpdateTag, isDOMNode } from 'lexical';
|
|
5
5
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
@@ -33,7 +33,7 @@ export function DropDownItem({ active, children, editor, enabled, Icon, item, it
|
|
|
33
33
|
ref,
|
|
34
34
|
registerItem
|
|
35
35
|
]);
|
|
36
|
-
return /*#__PURE__*/
|
|
36
|
+
return /*#__PURE__*/ _jsxDEV(Button, {
|
|
37
37
|
"aria-label": tooltip,
|
|
38
38
|
buttonStyle: "none",
|
|
39
39
|
className: className,
|
|
@@ -67,7 +67,11 @@ export function DropDownItem({ active, children, editor, enabled, Icon, item, it
|
|
|
67
67
|
tooltip: tooltip,
|
|
68
68
|
type: "button",
|
|
69
69
|
children: children
|
|
70
|
-
}
|
|
70
|
+
}, void 0, false, {
|
|
71
|
+
fileName: "src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx",
|
|
72
|
+
lineNumber: 64,
|
|
73
|
+
columnNumber: 5
|
|
74
|
+
}, this);
|
|
71
75
|
}
|
|
72
76
|
function DropDownItems({ children, dropDownRef, itemsContainerClassNames, onClose }) {
|
|
73
77
|
const [items, setItems] = useState();
|
|
@@ -130,17 +134,25 @@ function DropDownItems({ children, dropDownRef, itemsContainerClassNames, onClos
|
|
|
130
134
|
items,
|
|
131
135
|
highlightedItem
|
|
132
136
|
]);
|
|
133
|
-
return /*#__PURE__*/
|
|
137
|
+
return /*#__PURE__*/ _jsxDEV(DropDownContext, {
|
|
134
138
|
value: contextValue,
|
|
135
|
-
children: /*#__PURE__*/
|
|
139
|
+
children: /*#__PURE__*/ _jsxDEV("div", {
|
|
136
140
|
className: (itemsContainerClassNames ?? [
|
|
137
141
|
'toolbar-popup__dropdown-items'
|
|
138
142
|
]).join(' '),
|
|
139
143
|
onKeyDown: handleKeyDown,
|
|
140
144
|
ref: dropDownRef,
|
|
141
145
|
children: children
|
|
142
|
-
}
|
|
143
|
-
|
|
146
|
+
}, void 0, false, {
|
|
147
|
+
fileName: "src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx",
|
|
148
|
+
lineNumber: 175,
|
|
149
|
+
columnNumber: 7
|
|
150
|
+
}, this)
|
|
151
|
+
}, void 0, false, {
|
|
152
|
+
fileName: "src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx",
|
|
153
|
+
lineNumber: 174,
|
|
154
|
+
columnNumber: 5
|
|
155
|
+
}, this);
|
|
144
156
|
}
|
|
145
157
|
export function DropDown({ buttonAriaLabel, buttonClassName, children, disabled = false, dropdownKey, Icon, itemsContainerClassNames, label, stopCloseOnClickSelf }) {
|
|
146
158
|
const dropDownRef = useRef(null);
|
|
@@ -194,15 +206,19 @@ export function DropDown({ buttonAriaLabel, buttonClassName, children, disabled
|
|
|
194
206
|
showDropDown,
|
|
195
207
|
stopCloseOnClickSelf
|
|
196
208
|
]);
|
|
197
|
-
const portal = /*#__PURE__*/ createPortal(/*#__PURE__*/
|
|
209
|
+
const portal = /*#__PURE__*/ createPortal(/*#__PURE__*/ _jsxDEV(DropDownItems, {
|
|
198
210
|
dropDownRef: dropDownRef,
|
|
199
211
|
itemsContainerClassNames: itemsContainerClassNames,
|
|
200
212
|
onClose: handleClose,
|
|
201
213
|
children: children
|
|
202
|
-
}
|
|
203
|
-
|
|
214
|
+
}, void 0, false, {
|
|
215
|
+
fileName: "src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx",
|
|
216
|
+
lineNumber: 257,
|
|
217
|
+
columnNumber: 5
|
|
218
|
+
}, this), document.body);
|
|
219
|
+
return /*#__PURE__*/ _jsxDEV(React.Fragment, {
|
|
204
220
|
children: [
|
|
205
|
-
/*#__PURE__*/
|
|
221
|
+
/*#__PURE__*/ _jsxDEV("button", {
|
|
206
222
|
"aria-label": buttonAriaLabel,
|
|
207
223
|
className: buttonClassName + (showDropDown ? ' active' : ''),
|
|
208
224
|
"data-dropdown-key": dropdownKey,
|
|
@@ -220,21 +236,45 @@ export function DropDown({ buttonAriaLabel, buttonClassName, children, disabled
|
|
|
220
236
|
ref: buttonRef,
|
|
221
237
|
type: "button",
|
|
222
238
|
children: [
|
|
223
|
-
Icon && /*#__PURE__*/
|
|
224
|
-
|
|
239
|
+
Icon && /*#__PURE__*/ _jsxDEV(Icon, {}, void 0, false, {
|
|
240
|
+
fileName: "src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx",
|
|
241
|
+
lineNumber: 287,
|
|
242
|
+
columnNumber: 18
|
|
243
|
+
}, this),
|
|
244
|
+
label && /*#__PURE__*/ _jsxDEV("span", {
|
|
225
245
|
className: "toolbar-popup__dropdown-label",
|
|
226
246
|
children: label
|
|
227
|
-
}
|
|
228
|
-
|
|
247
|
+
}, void 0, false, {
|
|
248
|
+
fileName: "src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx",
|
|
249
|
+
lineNumber: 288,
|
|
250
|
+
columnNumber: 19
|
|
251
|
+
}, this),
|
|
252
|
+
/*#__PURE__*/ _jsxDEV("i", {
|
|
229
253
|
className: "toolbar-popup__dropdown-caret"
|
|
230
|
-
}
|
|
254
|
+
}, void 0, false, {
|
|
255
|
+
fileName: "src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx",
|
|
256
|
+
lineNumber: 289,
|
|
257
|
+
columnNumber: 9
|
|
258
|
+
}, this)
|
|
231
259
|
]
|
|
232
|
-
}
|
|
233
|
-
|
|
260
|
+
}, void 0, true, {
|
|
261
|
+
fileName: "src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx",
|
|
262
|
+
lineNumber: 269,
|
|
263
|
+
columnNumber: 7
|
|
264
|
+
}, this),
|
|
265
|
+
showDropDown && /*#__PURE__*/ _jsxDEV(React.Fragment, {
|
|
234
266
|
children: portal
|
|
235
|
-
}
|
|
267
|
+
}, void 0, false, {
|
|
268
|
+
fileName: "src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx",
|
|
269
|
+
lineNumber: 292,
|
|
270
|
+
columnNumber: 24
|
|
271
|
+
}, this)
|
|
236
272
|
]
|
|
237
|
-
}
|
|
273
|
+
}, void 0, true, {
|
|
274
|
+
fileName: "src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx",
|
|
275
|
+
lineNumber: 268,
|
|
276
|
+
columnNumber: 5
|
|
277
|
+
}, this);
|
|
238
278
|
}
|
|
239
279
|
|
|
240
280
|
//# sourceMappingURL=DropDown.js.map
|