@use-kona/editor 0.1.0-rc.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/README.md +23 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -0
- package/dist/core/createEditable.d.ts +7 -0
- package/dist/core/createEditable.js +110 -0
- package/dist/core/createEditor.d.ts +2 -0
- package/dist/core/createEditor.js +167 -0
- package/dist/core/deserialize.d.ts +3 -0
- package/dist/core/deserialize.js +33 -0
- package/dist/core/queries.d.ts +2 -0
- package/dist/core/queries.js +10 -0
- package/dist/core/serialize.d.ts +3 -0
- package/dist/core/serialize.js +13 -0
- package/dist/core/styles.module.js +6 -0
- package/dist/core/styles_module.css +29 -0
- package/dist/defaultValue.d.ts +4 -0
- package/dist/defaultValue.js +13 -0
- package/dist/editor.d.ts +10 -0
- package/dist/editor.js +43 -0
- package/dist/elements/BaseElement.d.ts +2 -0
- package/dist/elements/BaseElement.js +6 -0
- package/dist/examples/Backdrop.d.ts +5 -0
- package/dist/examples/Backdrop.js +13 -0
- package/dist/examples/Backdrop.module.js +5 -0
- package/dist/examples/Backdrop_module.css +6 -0
- package/dist/examples/DragBlock.d.ts +11 -0
- package/dist/examples/DragBlock.js +38 -0
- package/dist/examples/DragBlock.module.js +9 -0
- package/dist/examples/DragBlock_module.css +43 -0
- package/dist/examples/DragHandler.d.ts +2 -0
- package/dist/examples/DragHandler.js +44 -0
- package/dist/examples/DragHandler.module.js +8 -0
- package/dist/examples/DragHandler_module.css +18 -0
- package/dist/examples/Editor.d.ts +2 -0
- package/dist/examples/Editor.js +23 -0
- package/dist/examples/Editor.module.js +12 -0
- package/dist/examples/Editor_module.css +128 -0
- package/dist/examples/FloatingMenu.d.ts +17 -0
- package/dist/examples/FloatingMenu.js +244 -0
- package/dist/examples/FloatingMenu.module.js +9 -0
- package/dist/examples/FloatingMenu_module.css +75 -0
- package/dist/examples/LanguageSelector.d.ts +10 -0
- package/dist/examples/LanguageSelector.js +154 -0
- package/dist/examples/LanguageSelector.module.js +7 -0
- package/dist/examples/LanguageSelector_module.css +52 -0
- package/dist/examples/LinksHint.d.ts +7 -0
- package/dist/examples/LinksHint.js +50 -0
- package/dist/examples/LinksHint.module.js +6 -0
- package/dist/examples/LinksHint_module.css +28 -0
- package/dist/examples/Menu.d.ts +6 -0
- package/dist/examples/Menu.js +79 -0
- package/dist/examples/Menu.module.js +8 -0
- package/dist/examples/Menu_module.css +38 -0
- package/dist/examples/colors.d.ts +10 -0
- package/dist/examples/colors.js +12 -0
- package/dist/examples/getCommands.d.ts +2 -0
- package/dist/examples/getCommands.js +87 -0
- package/dist/examples/getPlugins.d.ts +2 -0
- package/dist/examples/getPlugins.js +127 -0
- package/dist/examples/getShortcuts.d.ts +2 -0
- package/dist/examples/getShortcuts.js +90 -0
- package/dist/examples/icons/bold.d.ts +2 -0
- package/dist/examples/icons/bold.js +27 -0
- package/dist/examples/icons/check.d.ts +2 -0
- package/dist/examples/icons/check.js +24 -0
- package/dist/examples/icons/chevronRight.d.ts +2 -0
- package/dist/examples/icons/chevronRight.js +24 -0
- package/dist/examples/icons/color.d.ts +2 -0
- package/dist/examples/icons/color.js +30 -0
- package/dist/examples/icons/copy.d.ts +2 -0
- package/dist/examples/icons/copy.js +27 -0
- package/dist/examples/icons/cross.d.ts +2 -0
- package/dist/examples/icons/cross.js +27 -0
- package/dist/examples/icons/drag.d.ts +2 -0
- package/dist/examples/icons/drag.js +39 -0
- package/dist/examples/icons/edit.d.ts +2 -0
- package/dist/examples/icons/edit.js +30 -0
- package/dist/examples/icons/external.d.ts +2 -0
- package/dist/examples/icons/external.js +30 -0
- package/dist/examples/icons/heading1.d.ts +2 -0
- package/dist/examples/icons/heading1.js +45 -0
- package/dist/examples/icons/heading2.d.ts +2 -0
- package/dist/examples/icons/heading2.js +45 -0
- package/dist/examples/icons/heading3.d.ts +2 -0
- package/dist/examples/icons/heading3.js +48 -0
- package/dist/examples/icons/italic.d.ts +2 -0
- package/dist/examples/icons/italic.js +30 -0
- package/dist/examples/icons/link.d.ts +2 -0
- package/dist/examples/icons/link.js +30 -0
- package/dist/examples/icons/ol.d.ts +2 -0
- package/dist/examples/icons/ol.js +36 -0
- package/dist/examples/icons/strikethrough.d.ts +2 -0
- package/dist/examples/icons/strikethrough.js +27 -0
- package/dist/examples/icons/text.d.ts +2 -0
- package/dist/examples/icons/text.js +22 -0
- package/dist/examples/icons/types.d.ts +3 -0
- package/dist/examples/icons/types.js +0 -0
- package/dist/examples/icons/ul.d.ts +2 -0
- package/dist/examples/icons/ul.js +39 -0
- package/dist/examples/icons/underline.d.ts +2 -0
- package/dist/examples/icons/underline.js +27 -0
- package/dist/examples/store.d.ts +8 -0
- package/dist/examples/store.js +6 -0
- package/dist/examples/styles.module.js +11 -0
- package/dist/examples/styles_module.css +78 -0
- package/dist/examples/text.d.ts +3 -0
- package/dist/examples/text.js +60 -0
- package/dist/examples/ui/Button/Button.d.ts +8 -0
- package/dist/examples/ui/Button/Button.js +15 -0
- package/dist/examples/ui/Button/ButtonWrapper.d.ts +4 -0
- package/dist/examples/ui/Button/ButtonWrapper.js +14 -0
- package/dist/examples/ui/Button/index.d.ts +2 -0
- package/dist/examples/ui/Button/index.js +3 -0
- package/dist/examples/ui/Button/styles.module.js +10 -0
- package/dist/examples/ui/Button/styles_module.css +72 -0
- package/dist/examples/ui/Button/types.d.ts +1 -0
- package/dist/examples/ui/Button/types.js +0 -0
- package/dist/examples/ui/Dropdown/Dropdown.d.ts +16 -0
- package/dist/examples/ui/Dropdown/Dropdown.js +75 -0
- package/dist/examples/ui/Dropdown/index.d.ts +1 -0
- package/dist/examples/ui/Dropdown/index.js +2 -0
- package/dist/examples/ui/Menu/Menu.d.ts +41 -0
- package/dist/examples/ui/Menu/Menu.js +404 -0
- package/dist/examples/ui/Menu/MenuDelimiter.d.ts +1 -0
- package/dist/examples/ui/Menu/MenuDelimiter.js +6 -0
- package/dist/examples/ui/Menu/MenuHotkey.d.ts +6 -0
- package/dist/examples/ui/Menu/MenuHotkey.js +12 -0
- package/dist/examples/ui/Menu/MenuIcon.d.ts +6 -0
- package/dist/examples/ui/Menu/MenuIcon.js +12 -0
- package/dist/examples/ui/Menu/MenuItem.d.ts +6 -0
- package/dist/examples/ui/Menu/MenuItem.js +17 -0
- package/dist/examples/ui/Menu/MenuTitle.d.ts +6 -0
- package/dist/examples/ui/Menu/MenuTitle.js +12 -0
- package/dist/examples/ui/Menu/SafeSpace.d.ts +6 -0
- package/dist/examples/ui/Menu/SafeSpace.js +65 -0
- package/dist/examples/ui/Menu/index.d.ts +2 -0
- package/dist/examples/ui/Menu/index.js +2 -0
- package/dist/examples/ui/Menu/styles.module.js +21 -0
- package/dist/examples/ui/Menu/styles_module.css +140 -0
- package/dist/examples/ui/Menu/types.d.ts +16 -0
- package/dist/examples/ui/Menu/types.js +0 -0
- package/dist/examples/ui/useMenuPosition.d.ts +18 -0
- package/dist/examples/ui/useMenuPosition.js +51 -0
- package/dist/examples/ui/useMergeRefs.d.ts +23 -0
- package/dist/examples/ui/useMergeRefs.js +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/plugins/AttachmentsPlugin/AttachmentsPlugin.d.ts +17 -0
- package/dist/plugins/AttachmentsPlugin/AttachmentsPlugin.js +37 -0
- package/dist/plugins/AttachmentsPlugin/index.d.ts +1 -0
- package/dist/plugins/AttachmentsPlugin/index.js +2 -0
- package/dist/plugins/AttachmentsPlugin/types.d.ts +11 -0
- package/dist/plugins/AttachmentsPlugin/types.js +0 -0
- package/dist/plugins/BasicFormattingPlugin/BasicFormattingPlugin.d.ts +20 -0
- package/dist/plugins/BasicFormattingPlugin/BasicFormattingPlugin.js +76 -0
- package/dist/plugins/BasicFormattingPlugin/index.d.ts +1 -0
- package/dist/plugins/BasicFormattingPlugin/index.js +2 -0
- package/dist/plugins/BreaksPlugin/BreaksPlugin.d.ts +15 -0
- package/dist/plugins/BreaksPlugin/BreaksPlugin.js +50 -0
- package/dist/plugins/BreaksPlugin/index.d.ts +1 -0
- package/dist/plugins/BreaksPlugin/index.js +2 -0
- package/dist/plugins/CodeBlockPlugin/CodeBlock.d.ts +9 -0
- package/dist/plugins/CodeBlockPlugin/CodeBlock.js +18 -0
- package/dist/plugins/CodeBlockPlugin/CodeBlockLine.d.ts +2 -0
- package/dist/plugins/CodeBlockPlugin/CodeBlockLine.js +9 -0
- package/dist/plugins/CodeBlockPlugin/CodeBlockPlugin.d.ts +55 -0
- package/dist/plugins/CodeBlockPlugin/CodeBlockPlugin.js +224 -0
- package/dist/plugins/CodeBlockPlugin/index.d.ts +1 -0
- package/dist/plugins/CodeBlockPlugin/index.js +2 -0
- package/dist/plugins/CodeBlockPlugin/styles.module.js +6 -0
- package/dist/plugins/CodeBlockPlugin/styles_module.css +12 -0
- package/dist/plugins/CodeBlockPlugin/types.d.ts +8 -0
- package/dist/plugins/CodeBlockPlugin/types.js +0 -0
- package/dist/plugins/CodeBlockPlugin/utils.d.ts +13 -0
- package/dist/plugins/CodeBlockPlugin/utils.js +87 -0
- package/dist/plugins/CommandsPlugin/CommandsPlugin.d.ts +11 -0
- package/dist/plugins/CommandsPlugin/CommandsPlugin.js +65 -0
- package/dist/plugins/CommandsPlugin/Menu.d.ts +11 -0
- package/dist/plugins/CommandsPlugin/Menu.js +153 -0
- package/dist/plugins/CommandsPlugin/actions.d.ts +7 -0
- package/dist/plugins/CommandsPlugin/actions.js +29 -0
- package/dist/plugins/CommandsPlugin/index.d.ts +2 -0
- package/dist/plugins/CommandsPlugin/index.js +2 -0
- package/dist/plugins/CommandsPlugin/styles.module.js +9 -0
- package/dist/plugins/CommandsPlugin/styles_module.css +66 -0
- package/dist/plugins/CommandsPlugin/types.d.ts +27 -0
- package/dist/plugins/CommandsPlugin/types.js +0 -0
- package/dist/plugins/DnDPlugin/DnDPlugin.d.ts +33 -0
- package/dist/plugins/DnDPlugin/DnDPlugin.js +110 -0
- package/dist/plugins/DnDPlugin/index.d.ts +1 -0
- package/dist/plugins/DnDPlugin/index.js +2 -0
- package/dist/plugins/DnDPlugin/styles.module.js +9 -0
- package/dist/plugins/DnDPlugin/styles_module.css +43 -0
- package/dist/plugins/FloatingMenuPlugin/FloatingMenu.d.ts +9 -0
- package/dist/plugins/FloatingMenuPlugin/FloatingMenu.js +89 -0
- package/dist/plugins/FloatingMenuPlugin/FloatingMenuPlugin.d.ts +15 -0
- package/dist/plugins/FloatingMenuPlugin/FloatingMenuPlugin.js +36 -0
- package/dist/plugins/FloatingMenuPlugin/index.d.ts +2 -0
- package/dist/plugins/FloatingMenuPlugin/index.js +2 -0
- package/dist/plugins/FloatingMenuPlugin/styles.module.js +7 -0
- package/dist/plugins/FloatingMenuPlugin/styles_module.css +23 -0
- package/dist/plugins/FloatingMenuPlugin/types.d.ts +16 -0
- package/dist/plugins/FloatingMenuPlugin/types.js +0 -0
- package/dist/plugins/HeadingsPlugin/HeadingsPlugin.d.ts +19 -0
- package/dist/plugins/HeadingsPlugin/HeadingsPlugin.js +64 -0
- package/dist/plugins/HeadingsPlugin/index.d.ts +1 -0
- package/dist/plugins/HeadingsPlugin/index.js +2 -0
- package/dist/plugins/HighlightsPlugin/HighlightsPlugin.d.ts +16 -0
- package/dist/plugins/HighlightsPlugin/HighlightsPlugin.js +36 -0
- package/dist/plugins/HighlightsPlugin/index.d.ts +1 -0
- package/dist/plugins/HighlightsPlugin/index.js +2 -0
- package/dist/plugins/LinksPlugin/Link.d.ts +11 -0
- package/dist/plugins/LinksPlugin/Link.js +89 -0
- package/dist/plugins/LinksPlugin/LinksPlugin.d.ts +17 -0
- package/dist/plugins/LinksPlugin/LinksPlugin.js +102 -0
- package/dist/plugins/LinksPlugin/constants.d.ts +1 -0
- package/dist/plugins/LinksPlugin/constants.js +2 -0
- package/dist/plugins/LinksPlugin/index.d.ts +2 -0
- package/dist/plugins/LinksPlugin/index.js +2 -0
- package/dist/plugins/LinksPlugin/styles.module.js +11 -0
- package/dist/plugins/LinksPlugin/styles_module.css +71 -0
- package/dist/plugins/LinksPlugin/types.d.ts +18 -0
- package/dist/plugins/LinksPlugin/types.js +0 -0
- package/dist/plugins/ListsPlugin/ListsPlugin.d.ts +32 -0
- package/dist/plugins/ListsPlugin/ListsPlugin.js +218 -0
- package/dist/plugins/ListsPlugin/index.d.ts +1 -0
- package/dist/plugins/ListsPlugin/index.js +2 -0
- package/dist/plugins/ListsPlugin/styles.module.js +6 -0
- package/dist/plugins/ListsPlugin/styles_module.css +8 -0
- package/dist/plugins/MenuPlugin/Menu.d.ts +2 -0
- package/dist/plugins/MenuPlugin/Menu.js +14 -0
- package/dist/plugins/MenuPlugin/MenuPlugin.d.ts +7 -0
- package/dist/plugins/MenuPlugin/MenuPlugin.js +19 -0
- package/dist/plugins/MenuPlugin/index.d.ts +1 -0
- package/dist/plugins/MenuPlugin/index.js +2 -0
- package/dist/plugins/MenuPlugin/styles.module.js +6 -0
- package/dist/plugins/MenuPlugin/styles_module.css +33 -0
- package/dist/plugins/MenuPlugin/types.d.ts +4 -0
- package/dist/plugins/MenuPlugin/types.js +0 -0
- package/dist/plugins/NodeIdPlugin/NodeIdPlugin.d.ts +15 -0
- package/dist/plugins/NodeIdPlugin/NodeIdPlugin.js +36 -0
- package/dist/plugins/NodeIdPlugin/index.d.ts +1 -0
- package/dist/plugins/NodeIdPlugin/index.js +2 -0
- package/dist/plugins/PlaceholderPlugin/PlaceholderPlugin.d.ts +16 -0
- package/dist/plugins/PlaceholderPlugin/PlaceholderPlugin.js +44 -0
- package/dist/plugins/PlaceholderPlugin/index.d.ts +1 -0
- package/dist/plugins/PlaceholderPlugin/index.js +2 -0
- package/dist/plugins/PlaceholderPlugin/styles.module.js +5 -0
- package/dist/plugins/PlaceholderPlugin/styles_module.css +14 -0
- package/dist/plugins/ShortcutsPlugin/ShortcutsPlugin.d.ts +24 -0
- package/dist/plugins/ShortcutsPlugin/ShortcutsPlugin.js +55 -0
- package/dist/plugins/ShortcutsPlugin/index.d.ts +2 -0
- package/dist/plugins/ShortcutsPlugin/index.js +2 -0
- package/dist/plugins/TableOfContentsPlugin/TableOfContentsPlugin.d.ts +18 -0
- package/dist/plugins/TableOfContentsPlugin/TableOfContentsPlugin.js +76 -0
- package/dist/plugins/TableOfContentsPlugin/index.d.ts +1 -0
- package/dist/plugins/TableOfContentsPlugin/index.js +2 -0
- package/dist/plugins/TableOfContentsPlugin/styles.module.js +10 -0
- package/dist/plugins/TableOfContentsPlugin/styles_module.css +114 -0
- package/dist/plugins/index.d.ts +16 -0
- package/dist/plugins/index.js +17 -0
- package/dist/queries/getMatchedGroups.d.ts +0 -0
- package/dist/queries/getMatchedGroups.js +0 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.js +0 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +8 -0
- package/package.json +71 -0
- package/src/constants.ts +1 -0
- package/src/core/createEditable.tsx +159 -0
- package/src/core/createEditor.ts +244 -0
- package/src/core/deserialize.ts +57 -0
- package/src/core/queries.ts +10 -0
- package/src/core/serialize.ts +38 -0
- package/src/core/styles.module.css +28 -0
- package/src/defaultValue.ts +10 -0
- package/src/editor.tsx +55 -0
- package/src/elements/BaseElement.tsx +5 -0
- package/src/examples/Backdrop.module.css +8 -0
- package/src/examples/Backdrop.tsx +16 -0
- package/src/examples/DragBlock.module.css +42 -0
- package/src/examples/DragBlock.tsx +57 -0
- package/src/examples/DragHandler.module.css +17 -0
- package/src/examples/DragHandler.tsx +39 -0
- package/src/examples/Editor.module.css +130 -0
- package/src/examples/Editor.tsx +26 -0
- package/src/examples/FloatingMenu.module.css +74 -0
- package/src/examples/FloatingMenu.tsx +274 -0
- package/src/examples/LanguageSelector.module.css +51 -0
- package/src/examples/LanguageSelector.tsx +99 -0
- package/src/examples/LinksHint.module.css +27 -0
- package/src/examples/LinksHint.tsx +58 -0
- package/src/examples/Menu.module.css +37 -0
- package/src/examples/Menu.tsx +80 -0
- package/src/examples/colors.ts +11 -0
- package/src/examples/getCommands.tsx +76 -0
- package/src/examples/getPlugins.tsx +143 -0
- package/src/examples/getShortcuts.ts +107 -0
- package/src/examples/icons/bold.tsx +20 -0
- package/src/examples/icons/check.tsx +19 -0
- package/src/examples/icons/chevronRight.tsx +19 -0
- package/src/examples/icons/color.tsx +23 -0
- package/src/examples/icons/copy.tsx +20 -0
- package/src/examples/icons/cross.tsx +20 -0
- package/src/examples/icons/drag.tsx +24 -0
- package/src/examples/icons/edit.tsx +21 -0
- package/src/examples/icons/external.tsx +21 -0
- package/src/examples/icons/heading1.tsx +26 -0
- package/src/examples/icons/heading2.tsx +26 -0
- package/src/examples/icons/heading3.tsx +27 -0
- package/src/examples/icons/italic.tsx +21 -0
- package/src/examples/icons/link.tsx +21 -0
- package/src/examples/icons/ol.tsx +23 -0
- package/src/examples/icons/strikethrough.tsx +20 -0
- package/src/examples/icons/text.tsx +18 -0
- package/src/examples/icons/types.ts +3 -0
- package/src/examples/icons/ul.tsx +24 -0
- package/src/examples/icons/underline.tsx +20 -0
- package/src/examples/store.ts +14 -0
- package/src/examples/styles.module.css +77 -0
- package/src/examples/text.tsx +133 -0
- package/src/examples/ui/Button/Button.tsx +34 -0
- package/src/examples/ui/Button/ButtonWrapper.tsx +22 -0
- package/src/examples/ui/Button/index.ts +2 -0
- package/src/examples/ui/Button/styles.module.css +75 -0
- package/src/examples/ui/Button/types.ts +1 -0
- package/src/examples/ui/Dropdown/Dropdown.tsx +101 -0
- package/src/examples/ui/Dropdown/index.ts +1 -0
- package/src/examples/ui/Menu/Menu.tsx +576 -0
- package/src/examples/ui/Menu/MenuDelimiter.tsx +3 -0
- package/src/examples/ui/Menu/MenuHotkey.tsx +17 -0
- package/src/examples/ui/Menu/MenuIcon.tsx +17 -0
- package/src/examples/ui/Menu/MenuItem.tsx +45 -0
- package/src/examples/ui/Menu/MenuTitle.tsx +17 -0
- package/src/examples/ui/Menu/SafeSpace.tsx +84 -0
- package/src/examples/ui/Menu/index.ts +2 -0
- package/src/examples/ui/Menu/styles.module.css +143 -0
- package/src/examples/ui/Menu/types.ts +18 -0
- package/src/examples/ui/useMenuPosition.ts +72 -0
- package/src/examples/ui/useMergeRefs.ts +39 -0
- package/src/index.ts +2 -0
- package/src/plugins/AttachmentsPlugin/AttachmentsPlugin.tsx +41 -0
- package/src/plugins/AttachmentsPlugin/index.ts +1 -0
- package/src/plugins/AttachmentsPlugin/types.ts +12 -0
- package/src/plugins/BasicFormattingPlugin/BasicFormattingPlugin.tsx +100 -0
- package/src/plugins/BasicFormattingPlugin/index.ts +1 -0
- package/src/plugins/BreaksPlugin/BreaksPlugin.tsx +70 -0
- package/src/plugins/BreaksPlugin/index.ts +1 -0
- package/src/plugins/CodeBlockPlugin/CodeBlock.tsx +20 -0
- package/src/plugins/CodeBlockPlugin/CodeBlockLine.tsx +7 -0
- package/src/plugins/CodeBlockPlugin/CodeBlockPlugin.tsx +304 -0
- package/src/plugins/CodeBlockPlugin/index.ts +1 -0
- package/src/plugins/CodeBlockPlugin/styles.module.css +11 -0
- package/src/plugins/CodeBlockPlugin/types.ts +10 -0
- package/src/plugins/CodeBlockPlugin/utils.ts +117 -0
- package/src/plugins/CommandsPlugin/CommandsPlugin.tsx +99 -0
- package/src/plugins/CommandsPlugin/Menu.tsx +205 -0
- package/src/plugins/CommandsPlugin/actions.ts +41 -0
- package/src/plugins/CommandsPlugin/index.ts +2 -0
- package/src/plugins/CommandsPlugin/styles.module.css +69 -0
- package/src/plugins/CommandsPlugin/types.ts +32 -0
- package/src/plugins/DnDPlugin/DnDPlugin.tsx +200 -0
- package/src/plugins/DnDPlugin/index.ts +1 -0
- package/src/plugins/DnDPlugin/styles.module.css +42 -0
- package/src/plugins/FloatingMenuPlugin/FloatingMenu.tsx +144 -0
- package/src/plugins/FloatingMenuPlugin/FloatingMenuPlugin.tsx +44 -0
- package/src/plugins/FloatingMenuPlugin/index.ts +2 -0
- package/src/plugins/FloatingMenuPlugin/styles.module.css +22 -0
- package/src/plugins/FloatingMenuPlugin/types.ts +18 -0
- package/src/plugins/HeadingsPlugin/HeadingsPlugin.tsx +75 -0
- package/src/plugins/HeadingsPlugin/index.ts +1 -0
- package/src/plugins/HighlightsPlugin/HighlightsPlugin.tsx +56 -0
- package/src/plugins/HighlightsPlugin/index.ts +1 -0
- package/src/plugins/LinksPlugin/Link.tsx +90 -0
- package/src/plugins/LinksPlugin/LinksPlugin.tsx +128 -0
- package/src/plugins/LinksPlugin/constants.ts +1 -0
- package/src/plugins/LinksPlugin/index.ts +2 -0
- package/src/plugins/LinksPlugin/styles.module.css +73 -0
- package/src/plugins/LinksPlugin/types.ts +19 -0
- package/src/plugins/ListsPlugin/ListsPlugin.tsx +355 -0
- package/src/plugins/ListsPlugin/index.ts +1 -0
- package/src/plugins/ListsPlugin/styles.module.css +7 -0
- package/src/plugins/MenuPlugin/Menu.tsx +9 -0
- package/src/plugins/MenuPlugin/MenuPlugin.tsx +20 -0
- package/src/plugins/MenuPlugin/index.ts +1 -0
- package/src/plugins/MenuPlugin/styles.module.css +33 -0
- package/src/plugins/MenuPlugin/types.ts +5 -0
- package/src/plugins/NodeIdPlugin/NodeIdPlugin.ts +62 -0
- package/src/plugins/NodeIdPlugin/index.ts +1 -0
- package/src/plugins/PlaceholderPlugin/PlaceholderPlugin.tsx +66 -0
- package/src/plugins/PlaceholderPlugin/index.ts +1 -0
- package/src/plugins/PlaceholderPlugin/styles.module.css +17 -0
- package/src/plugins/ShortcutsPlugin/ShortcutsPlugin.tsx +133 -0
- package/src/plugins/ShortcutsPlugin/index.ts +2 -0
- package/src/plugins/TableOfContentsPlugin/TableOfContentsPlugin.tsx +102 -0
- package/src/plugins/TableOfContentsPlugin/index.ts +1 -0
- package/src/plugins/TableOfContentsPlugin/styles.module.css +113 -0
- package/src/plugins/index.ts +20 -0
- package/src/queries/getMatchedGroups.ts +0 -0
- package/src/types.ts +87 -0
- package/src/utils.ts +15 -0
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import {
|
|
3
|
+
forwardRef,
|
|
4
|
+
type JSX,
|
|
5
|
+
type ReactNode,
|
|
6
|
+
useEffect,
|
|
7
|
+
useLayoutEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from 'react';
|
|
11
|
+
import { createPortal } from 'react-dom';
|
|
12
|
+
import { ChevronRightIcon } from '../../icons/chevronRight';
|
|
13
|
+
import { useMenuPosition } from '../useMenuPosition';
|
|
14
|
+
import { useMergeRefs } from '../useMergeRefs';
|
|
15
|
+
import { MenuDelimiter } from './MenuDelimiter';
|
|
16
|
+
import { MenuHotkey } from './MenuHotkey';
|
|
17
|
+
import { MenuIcon } from './MenuIcon';
|
|
18
|
+
import { MenuItem } from './MenuItem';
|
|
19
|
+
import { MenuTitle } from './MenuTitle';
|
|
20
|
+
import { SafeSpace } from './SafeSpace';
|
|
21
|
+
import styles from './styles.module.css';
|
|
22
|
+
import type { MenuConfig } from './types';
|
|
23
|
+
|
|
24
|
+
type Coords = [number, number];
|
|
25
|
+
|
|
26
|
+
type MenuProps = {
|
|
27
|
+
config: MenuConfig;
|
|
28
|
+
className?: string;
|
|
29
|
+
isOpen?: boolean;
|
|
30
|
+
coords: Coords;
|
|
31
|
+
target?: HTMLElement;
|
|
32
|
+
onToggle?: (isOpen?: boolean) => void;
|
|
33
|
+
Menu?: JSX.ElementType;
|
|
34
|
+
MenuBody?: JSX.ElementType;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Component for rendering various types of menus.
|
|
39
|
+
*/
|
|
40
|
+
export const MenuComponent = forwardRef<HTMLMenuElement, MenuProps>(
|
|
41
|
+
(props, menuRef) => {
|
|
42
|
+
const {
|
|
43
|
+
isOpen,
|
|
44
|
+
className,
|
|
45
|
+
coords,
|
|
46
|
+
config,
|
|
47
|
+
Menu: MenuRootComponent,
|
|
48
|
+
MenuBody,
|
|
49
|
+
onToggle,
|
|
50
|
+
target = document.body,
|
|
51
|
+
} = props;
|
|
52
|
+
const ref = useRef<HTMLMenuElement>(null);
|
|
53
|
+
|
|
54
|
+
const mergedRef = useMergeRefs([menuRef, ref]);
|
|
55
|
+
|
|
56
|
+
const refs = useRef<Record<string, HTMLLIElement>>({});
|
|
57
|
+
|
|
58
|
+
const [rects, setRects] = useState<Record<string, DOMRect>>({});
|
|
59
|
+
const [prevSelected, setPrevSelected] = useState<Array<number>>([]);
|
|
60
|
+
const [selected, setSelected] = useState<Array<number>>([]);
|
|
61
|
+
|
|
62
|
+
const isSelected = (index: number, level: number) => {
|
|
63
|
+
return selected[level] === index;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const getConfig = (path: number[], level: number) => {
|
|
67
|
+
return path
|
|
68
|
+
.slice(0, level + 1)
|
|
69
|
+
.reduce<MenuConfig | null>((prev, current) => {
|
|
70
|
+
return (prev || config).items?.[current]?.config || null;
|
|
71
|
+
}, null);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const getCurrentConfig = (path: number[]) => {
|
|
75
|
+
if (path.length === 1) {
|
|
76
|
+
return config;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return path.reduce<MenuConfig | null>((prev = config, current) => {
|
|
80
|
+
const currentConfig = prev || config;
|
|
81
|
+
return currentConfig.items?.[current]?.config || prev;
|
|
82
|
+
}, null);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const updateRect = (path: number[]) => {
|
|
86
|
+
const rect = refs.current[path.join(',')]?.getBoundingClientRect();
|
|
87
|
+
setRects({
|
|
88
|
+
...rects,
|
|
89
|
+
[path.join(',')]: rect,
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: we care only about is open
|
|
94
|
+
useLayoutEffect(() => {
|
|
95
|
+
if (ref.current) {
|
|
96
|
+
const rect = ref.current.getBoundingClientRect();
|
|
97
|
+
setRects({ '@': rect });
|
|
98
|
+
}
|
|
99
|
+
}, [isOpen]);
|
|
100
|
+
|
|
101
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: we care only about is open
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (isOpen) {
|
|
104
|
+
const firstSelectable = config.items?.findIndex(
|
|
105
|
+
(item) => item.selectable ?? true,
|
|
106
|
+
);
|
|
107
|
+
if (firstSelectable !== undefined) {
|
|
108
|
+
setSelected([firstSelectable]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}, [isOpen]);
|
|
112
|
+
|
|
113
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: we don't care about other props
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
if (!isOpen) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let timeout: ReturnType<typeof setTimeout>;
|
|
120
|
+
|
|
121
|
+
selected.forEach((_, level) => {
|
|
122
|
+
const config = level === 0 ? props.config : getConfig(selected, level);
|
|
123
|
+
|
|
124
|
+
if (config?.onOpen && prevSelected[level] !== selected[level]) {
|
|
125
|
+
timeout = setTimeout(() => {
|
|
126
|
+
config.onOpen?.();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
setPrevSelected(selected);
|
|
132
|
+
|
|
133
|
+
return () => {
|
|
134
|
+
clearTimeout(timeout);
|
|
135
|
+
};
|
|
136
|
+
}, [selected, isOpen]);
|
|
137
|
+
|
|
138
|
+
const currentConfig = getCurrentConfig(selected);
|
|
139
|
+
|
|
140
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: we care only about these props
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (isOpen) {
|
|
143
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
144
|
+
switch (event.key) {
|
|
145
|
+
case 'ArrowDown': {
|
|
146
|
+
const firstSelectableIndex =
|
|
147
|
+
currentConfig?.items?.findIndex(
|
|
148
|
+
(item) => item.selectable ?? true,
|
|
149
|
+
) ?? -1;
|
|
150
|
+
const nextSelectableIndex = currentConfig?.items?.findIndex(
|
|
151
|
+
(item, index) => {
|
|
152
|
+
return (
|
|
153
|
+
(item.selectable ?? true) &&
|
|
154
|
+
index > selected[selected.length - 1]
|
|
155
|
+
);
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
if (nextSelectableIndex) {
|
|
160
|
+
setSelected((selected) => {
|
|
161
|
+
const newSelected = [
|
|
162
|
+
...selected.slice(0, selected.length - 1),
|
|
163
|
+
nextSelectableIndex === -1
|
|
164
|
+
? firstSelectableIndex
|
|
165
|
+
: nextSelectableIndex,
|
|
166
|
+
];
|
|
167
|
+
updateRect(newSelected);
|
|
168
|
+
refs.current[newSelected.join(',')]?.scrollIntoView({
|
|
169
|
+
block: 'nearest',
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return newSelected;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
event.stopPropagation();
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case 'ArrowUp': {
|
|
180
|
+
if (!currentConfig?.items?.length) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const lastSelectableIndex = currentConfig?.items?.reduce(
|
|
185
|
+
(acc, item, index) => {
|
|
186
|
+
return (item.selectable ?? true) ? index : acc;
|
|
187
|
+
},
|
|
188
|
+
-1,
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const prevSelectableIndex = currentConfig?.items
|
|
192
|
+
?.slice(0, selected[selected.length - 1])
|
|
193
|
+
.reverse()
|
|
194
|
+
.findIndex((item) => item.selectable ?? true);
|
|
195
|
+
|
|
196
|
+
const newSelected = [
|
|
197
|
+
...selected.slice(0, selected.length - 1),
|
|
198
|
+
prevSelectableIndex === -1
|
|
199
|
+
? lastSelectableIndex
|
|
200
|
+
: selected[selected.length - 1] - prevSelectableIndex - 1,
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
setSelected(() => {
|
|
204
|
+
updateRect(newSelected);
|
|
205
|
+
refs.current[newSelected.join(',')].scrollIntoView({
|
|
206
|
+
block: 'nearest',
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return newSelected;
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
event.stopPropagation();
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
case 'ArrowRight': {
|
|
217
|
+
const currentItem =
|
|
218
|
+
currentConfig?.items?.[selected[selected.length - 1]];
|
|
219
|
+
|
|
220
|
+
if (currentItem?.config?.items) {
|
|
221
|
+
const firstSelectableIndex = currentConfig?.items?.findIndex(
|
|
222
|
+
(item) => item.selectable ?? true,
|
|
223
|
+
);
|
|
224
|
+
if (firstSelectableIndex !== undefined) {
|
|
225
|
+
setSelected((selected) => {
|
|
226
|
+
const newSelected = [...selected, firstSelectableIndex];
|
|
227
|
+
updateRect(newSelected);
|
|
228
|
+
|
|
229
|
+
return newSelected;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
currentItem.config?.onFocus?.();
|
|
233
|
+
}
|
|
234
|
+
event.preventDefault();
|
|
235
|
+
event.stopPropagation();
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
case 'ArrowLeft': {
|
|
239
|
+
setSelected((selected) => {
|
|
240
|
+
return selected.slice(0, selected.length - 1);
|
|
241
|
+
});
|
|
242
|
+
event.preventDefault();
|
|
243
|
+
event.stopPropagation();
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
case 'Escape': {
|
|
247
|
+
onToggle?.(false);
|
|
248
|
+
event.preventDefault();
|
|
249
|
+
event.stopPropagation();
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
case 'Enter': {
|
|
253
|
+
const currentItem =
|
|
254
|
+
currentConfig?.items?.[selected[selected.length - 1]];
|
|
255
|
+
if (currentItem?.onSelect) {
|
|
256
|
+
currentItem.onSelect();
|
|
257
|
+
}
|
|
258
|
+
onToggle?.(false);
|
|
259
|
+
event.preventDefault();
|
|
260
|
+
event.stopPropagation();
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case ' ': {
|
|
264
|
+
const currentItem =
|
|
265
|
+
currentConfig?.items?.[selected[selected.length - 1]];
|
|
266
|
+
if (currentItem?.onSelect) {
|
|
267
|
+
currentItem.onSelect();
|
|
268
|
+
}
|
|
269
|
+
event.preventDefault();
|
|
270
|
+
event.stopPropagation();
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
277
|
+
|
|
278
|
+
return () => {
|
|
279
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}, [isOpen, currentConfig, selected]);
|
|
283
|
+
|
|
284
|
+
const renderSubMenu = (): ReactNode => {
|
|
285
|
+
return selected.map((_, selectedIndex) => {
|
|
286
|
+
const config = getConfig(selected, selectedIndex);
|
|
287
|
+
const items = config?.items;
|
|
288
|
+
|
|
289
|
+
const path = selected.slice(0, selectedIndex + 1).join(',');
|
|
290
|
+
const rect = rects[path];
|
|
291
|
+
|
|
292
|
+
if (!rect || !items) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const coords = [rect.left + rect.width, rect.top] as Coords;
|
|
297
|
+
|
|
298
|
+
return createPortal(
|
|
299
|
+
<InnerMenu
|
|
300
|
+
key={path}
|
|
301
|
+
rect={rect}
|
|
302
|
+
coords={coords}
|
|
303
|
+
Menu={MenuRootComponent}
|
|
304
|
+
MenuBody={MenuBody}
|
|
305
|
+
>
|
|
306
|
+
{config?.header?.()}
|
|
307
|
+
<Scrollable>
|
|
308
|
+
{items.map((item, index) => (
|
|
309
|
+
<MenuItem
|
|
310
|
+
key={index}
|
|
311
|
+
ref={(element) => {
|
|
312
|
+
if (element && (item.selectable ?? true)) {
|
|
313
|
+
const selectedPath = [
|
|
314
|
+
...selected.slice(0, selectedIndex + 1),
|
|
315
|
+
index,
|
|
316
|
+
];
|
|
317
|
+
refs.current[selectedPath.join(',')] = element;
|
|
318
|
+
}
|
|
319
|
+
}}
|
|
320
|
+
selectable={item.selectable}
|
|
321
|
+
isSelected={isSelected(index, selectedIndex + 1)}
|
|
322
|
+
onMouseEnter={(event) => {
|
|
323
|
+
if (item.selectable ?? true) {
|
|
324
|
+
const selectedPath = [
|
|
325
|
+
...selected.slice(0, selectedIndex + 1),
|
|
326
|
+
index,
|
|
327
|
+
];
|
|
328
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
329
|
+
|
|
330
|
+
setSelected(selectedPath);
|
|
331
|
+
setRects((rects) => ({
|
|
332
|
+
...rects,
|
|
333
|
+
[selectedPath.join(',')]: rect,
|
|
334
|
+
}));
|
|
335
|
+
}
|
|
336
|
+
}}
|
|
337
|
+
onClick={() => {
|
|
338
|
+
const autoClose = item.autoClose ?? true;
|
|
339
|
+
autoClose && onToggle?.(false);
|
|
340
|
+
item.onSelect?.();
|
|
341
|
+
}}
|
|
342
|
+
>
|
|
343
|
+
{item.render()}
|
|
344
|
+
{item.config?.items && <ChevronRightIcon size={16} />}
|
|
345
|
+
</MenuItem>
|
|
346
|
+
))}
|
|
347
|
+
</Scrollable>
|
|
348
|
+
{config?.footer?.()}
|
|
349
|
+
</InnerMenu>,
|
|
350
|
+
target,
|
|
351
|
+
);
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
if (!isOpen) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return (
|
|
360
|
+
<>
|
|
361
|
+
{createPortal(
|
|
362
|
+
<>
|
|
363
|
+
<InnerMenu
|
|
364
|
+
className={className}
|
|
365
|
+
ref={mergedRef}
|
|
366
|
+
coords={coords}
|
|
367
|
+
rect={rects['@']}
|
|
368
|
+
Menu={MenuRootComponent}
|
|
369
|
+
MenuBody={MenuBody}
|
|
370
|
+
root
|
|
371
|
+
>
|
|
372
|
+
{config?.header?.()}
|
|
373
|
+
<Scrollable>
|
|
374
|
+
{config.items?.map((item, index) => (
|
|
375
|
+
<MenuItem
|
|
376
|
+
key={index}
|
|
377
|
+
ref={(element) => {
|
|
378
|
+
if (element && (item.selectable ?? true)) {
|
|
379
|
+
refs.current[index] = element;
|
|
380
|
+
}
|
|
381
|
+
}}
|
|
382
|
+
selectable={item.selectable}
|
|
383
|
+
isSelected={isSelected(index, 0)}
|
|
384
|
+
onMouseEnter={(event) => {
|
|
385
|
+
if (item.selectable ?? true) {
|
|
386
|
+
const rect =
|
|
387
|
+
event.currentTarget.getBoundingClientRect();
|
|
388
|
+
|
|
389
|
+
setSelected([index]);
|
|
390
|
+
setRects((rects) => ({
|
|
391
|
+
...rects,
|
|
392
|
+
[index]: rect,
|
|
393
|
+
}));
|
|
394
|
+
}
|
|
395
|
+
}}
|
|
396
|
+
onClick={() => {
|
|
397
|
+
const autoClose = item.autoClose ?? true;
|
|
398
|
+
autoClose && onToggle?.(false);
|
|
399
|
+
item.onSelect?.();
|
|
400
|
+
}}
|
|
401
|
+
>
|
|
402
|
+
{item.render()}
|
|
403
|
+
{item.config?.items && <ChevronRightIcon size={16} />}
|
|
404
|
+
</MenuItem>
|
|
405
|
+
))}
|
|
406
|
+
</Scrollable>
|
|
407
|
+
{config?.footer?.()}
|
|
408
|
+
</InnerMenu>
|
|
409
|
+
<Backdrop onClick={() => onToggle?.(false)} />
|
|
410
|
+
</>,
|
|
411
|
+
target,
|
|
412
|
+
)}
|
|
413
|
+
{renderSubMenu()}
|
|
414
|
+
</>
|
|
415
|
+
);
|
|
416
|
+
},
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
type InnerMenuProps = {
|
|
420
|
+
rect: DOMRect;
|
|
421
|
+
children: React.ReactNode;
|
|
422
|
+
className?: string;
|
|
423
|
+
coords: Coords;
|
|
424
|
+
root?: boolean;
|
|
425
|
+
Menu?: JSX.ElementType;
|
|
426
|
+
MenuBody?: JSX.ElementType;
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
const InnerMenu = forwardRef<HTMLMenuElement, InnerMenuProps>((props, ref) => {
|
|
430
|
+
const {
|
|
431
|
+
root,
|
|
432
|
+
className,
|
|
433
|
+
coords,
|
|
434
|
+
rect,
|
|
435
|
+
children,
|
|
436
|
+
Menu: MenuRootComponent = Root,
|
|
437
|
+
MenuBody: MenuBodyComponent = MenuBody,
|
|
438
|
+
} = props;
|
|
439
|
+
|
|
440
|
+
const [itemRect, setItemRect] = useState<DOMRect>();
|
|
441
|
+
const itemRef = useRef<HTMLDivElement>(null);
|
|
442
|
+
|
|
443
|
+
const [transform, newCoords] = useMenuPosition(
|
|
444
|
+
{
|
|
445
|
+
x: coords[0],
|
|
446
|
+
y: coords[1],
|
|
447
|
+
},
|
|
448
|
+
(context) => {
|
|
449
|
+
const [horizontal, vertical] = context.helpers.isWithinWindow();
|
|
450
|
+
|
|
451
|
+
if (root) {
|
|
452
|
+
return context.point;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (!rect) {
|
|
456
|
+
return context.point;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (!horizontal) {
|
|
460
|
+
context.flip([true, false]).move(-rect?.width, 0).move(-4, 0);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (!vertical) {
|
|
464
|
+
context.flip([false, true]).move(0, rect?.height).move(0, -4);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
return context.point;
|
|
468
|
+
},
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: we care only about these props
|
|
472
|
+
useLayoutEffect(() => {
|
|
473
|
+
if (itemRef.current && !root) {
|
|
474
|
+
transform(itemRef.current);
|
|
475
|
+
}
|
|
476
|
+
}, [coords[0], coords[1], root]);
|
|
477
|
+
|
|
478
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: we care only about these props
|
|
479
|
+
useEffect(() => {
|
|
480
|
+
if (itemRef.current) {
|
|
481
|
+
setItemRect(itemRef.current.getBoundingClientRect());
|
|
482
|
+
}
|
|
483
|
+
}, [newCoords]);
|
|
484
|
+
|
|
485
|
+
const menuCoords = root ? coords : [newCoords.x, newCoords.y];
|
|
486
|
+
|
|
487
|
+
return (
|
|
488
|
+
<>
|
|
489
|
+
{!root && <SafeSpace rect={itemRect} />}
|
|
490
|
+
<MenuRootComponent
|
|
491
|
+
className={className}
|
|
492
|
+
ref={ref}
|
|
493
|
+
coords={menuCoords}
|
|
494
|
+
style={{ left: menuCoords[0], top: menuCoords[1] }}
|
|
495
|
+
>
|
|
496
|
+
<MenuBodyComponent ref={itemRef}>{children}</MenuBodyComponent>
|
|
497
|
+
</MenuRootComponent>
|
|
498
|
+
</>
|
|
499
|
+
);
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
export const Menu = MenuComponent as typeof MenuComponent & {
|
|
503
|
+
Root: typeof Root;
|
|
504
|
+
Body: typeof MenuBody;
|
|
505
|
+
Item: typeof MenuItem;
|
|
506
|
+
Icon: typeof MenuIcon;
|
|
507
|
+
Title: typeof MenuTitle;
|
|
508
|
+
Hotkey: typeof MenuHotkey;
|
|
509
|
+
Delimiter: typeof MenuDelimiter;
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
interface RootProps extends React.MenuHTMLAttributes<HTMLMenuElement> {
|
|
513
|
+
coords: Coords;
|
|
514
|
+
className?: string;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const Root = forwardRef<HTMLMenuElement, RootProps>((props, ref) => {
|
|
518
|
+
const { coords, className, children, ...rest } = props;
|
|
519
|
+
|
|
520
|
+
return (
|
|
521
|
+
<menu
|
|
522
|
+
ref={ref}
|
|
523
|
+
className={clsx(styles.menu, styles.menuEnterAnimation, className)}
|
|
524
|
+
style={{ left: coords[0], top: coords[1] }}
|
|
525
|
+
{...rest}
|
|
526
|
+
>
|
|
527
|
+
{children}
|
|
528
|
+
</menu>
|
|
529
|
+
);
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
interface MenuBodyProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
533
|
+
className?: string;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const MenuBody = forwardRef<HTMLDivElement, MenuBodyProps>((props, ref) => {
|
|
537
|
+
const { className, children, ...rest } = props;
|
|
538
|
+
|
|
539
|
+
return (
|
|
540
|
+
<div ref={ref} className={clsx(styles.menuBody, className)} {...rest}>
|
|
541
|
+
{children}
|
|
542
|
+
</div>
|
|
543
|
+
);
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
interface ScrollableProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
547
|
+
className?: string;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const Scrollable: React.FC<ScrollableProps> = (props) => {
|
|
551
|
+
const { className, children, ...rest } = props;
|
|
552
|
+
|
|
553
|
+
return (
|
|
554
|
+
<div className={clsx(styles.menuScrollable, className)} {...rest}>
|
|
555
|
+
{children}
|
|
556
|
+
</div>
|
|
557
|
+
);
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
interface BackdropProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
561
|
+
className?: string;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const Backdrop: React.FC<BackdropProps> = (props) => {
|
|
565
|
+
const { className, ...rest } = props;
|
|
566
|
+
|
|
567
|
+
return <div className={clsx(styles.menuBackdrop, className)} {...rest} />;
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
Menu.Root = Root;
|
|
571
|
+
Menu.Body = MenuBody;
|
|
572
|
+
Menu.Item = MenuItem;
|
|
573
|
+
Menu.Icon = MenuIcon;
|
|
574
|
+
Menu.Title = MenuTitle;
|
|
575
|
+
Menu.Hotkey = MenuHotkey;
|
|
576
|
+
Menu.Delimiter = MenuDelimiter;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import styles from './styles.module.css';
|
|
3
|
+
|
|
4
|
+
type MenuHotkeyProps = {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
className?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const MenuHotkey = (props: MenuHotkeyProps) => {
|
|
10
|
+
const { children, className, ...rest } = props;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<span className={clsx(styles.menuHotkey, className)} {...rest}>
|
|
14
|
+
{children}
|
|
15
|
+
</span>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import styles from './styles.module.css';
|
|
3
|
+
|
|
4
|
+
type MenuIconProps = {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
className?: string;
|
|
7
|
+
} & React.HTMLAttributes<HTMLSpanElement>;
|
|
8
|
+
|
|
9
|
+
export const MenuIcon = (props: MenuIconProps) => {
|
|
10
|
+
const { children, className, ...rest } = props;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<span className={clsx(styles.menuIcon, className)} {...rest}>
|
|
14
|
+
{children}
|
|
15
|
+
</span>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import styles from './styles.module.css';
|
|
4
|
+
|
|
5
|
+
type MenuItemProps = {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
selectable?: boolean;
|
|
8
|
+
isSelected?: boolean;
|
|
9
|
+
danger?: boolean;
|
|
10
|
+
} & React.HTMLAttributes<HTMLLIElement>;
|
|
11
|
+
|
|
12
|
+
export const MenuItem = forwardRef<HTMLLIElement, MenuItemProps>(
|
|
13
|
+
(props, ref) => {
|
|
14
|
+
const {
|
|
15
|
+
children,
|
|
16
|
+
selectable = true,
|
|
17
|
+
isSelected,
|
|
18
|
+
danger,
|
|
19
|
+
className,
|
|
20
|
+
...rest
|
|
21
|
+
} = props;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<li
|
|
25
|
+
ref={ref}
|
|
26
|
+
className={clsx(
|
|
27
|
+
styles.menuItemRoot,
|
|
28
|
+
!selectable && styles.menuItemRootNonSelectable,
|
|
29
|
+
className,
|
|
30
|
+
)}
|
|
31
|
+
{...rest}
|
|
32
|
+
>
|
|
33
|
+
<div
|
|
34
|
+
className={clsx(
|
|
35
|
+
styles.menuItemContent,
|
|
36
|
+
isSelected && styles.menuItemContentSelected,
|
|
37
|
+
danger && styles.menuItemContentDanger,
|
|
38
|
+
)}
|
|
39
|
+
>
|
|
40
|
+
{children}
|
|
41
|
+
</div>
|
|
42
|
+
</li>
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import styles from './styles.module.css';
|
|
3
|
+
|
|
4
|
+
type MenuTitleProps = {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
className?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const MenuTitle = (props: MenuTitleProps) => {
|
|
10
|
+
const { children, className, ...rest } = props;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<span className={clsx(styles.menuTitle, className)} {...rest}>
|
|
14
|
+
{children}
|
|
15
|
+
</span>
|
|
16
|
+
);
|
|
17
|
+
};
|