@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,84 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
type Props = {
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
rect?: DOMRect;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const SafeSpace = (props: Props) => {
|
|
9
|
+
const { rect, debug } = props;
|
|
10
|
+
|
|
11
|
+
const { x = 0, y = 0, height: h = 0, width: w = 0 } = rect || {};
|
|
12
|
+
|
|
13
|
+
const [mouseX, mouseY] = useMousePosition();
|
|
14
|
+
|
|
15
|
+
const isReversed = mouseX > x + w;
|
|
16
|
+
const width = isReversed ? mouseX - x - w : x - mouseX;
|
|
17
|
+
const height = h;
|
|
18
|
+
|
|
19
|
+
const style = {
|
|
20
|
+
width,
|
|
21
|
+
height: h,
|
|
22
|
+
top: y,
|
|
23
|
+
left: isReversed ? x + w : mouseX,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const points = isReversed
|
|
27
|
+
? `0,0 ${width + 10},${mouseY - y} 0,${height}`
|
|
28
|
+
: `0,${mouseY - y} ${width},0 ${width},${height}`;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<svg
|
|
32
|
+
style={{
|
|
33
|
+
...style,
|
|
34
|
+
pointerEvents: 'none',
|
|
35
|
+
zIndex: 20,
|
|
36
|
+
position: 'fixed',
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
{/* Safe Area */}
|
|
40
|
+
<polygon
|
|
41
|
+
points={points}
|
|
42
|
+
fill={debug ? 'rgba(0,0,0,0.25)' : 'transparent'}
|
|
43
|
+
pointerEvents="all"
|
|
44
|
+
/>
|
|
45
|
+
</svg>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const useMousePosition = () => {
|
|
50
|
+
const [mousePosition, setMousePosition] = useState([0, 0]);
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const updateMousePosition = (ev: MouseEvent) => {
|
|
54
|
+
setMousePosition([ev.clientX, ev.clientY]);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const throttledUpdateMousePosition = throttle(updateMousePosition, 500);
|
|
58
|
+
|
|
59
|
+
document.addEventListener('mousemove', updateMousePosition, {
|
|
60
|
+
once: true,
|
|
61
|
+
});
|
|
62
|
+
document.addEventListener('mousemove', throttledUpdateMousePosition);
|
|
63
|
+
|
|
64
|
+
return () => {
|
|
65
|
+
document.removeEventListener('mousemove', updateMousePosition);
|
|
66
|
+
document.removeEventListener('mousemove', throttledUpdateMousePosition);
|
|
67
|
+
};
|
|
68
|
+
}, []);
|
|
69
|
+
|
|
70
|
+
return mousePosition;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
function throttle(callback: (...args: any[]) => void, delay: number) {
|
|
74
|
+
let previousCall = Date.now();
|
|
75
|
+
|
|
76
|
+
return function (this: any, ...args: any[]) {
|
|
77
|
+
const time = Date.now();
|
|
78
|
+
|
|
79
|
+
if (time - previousCall >= delay) {
|
|
80
|
+
previousCall = time;
|
|
81
|
+
callback.apply(this, args);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
.delimiter {
|
|
2
|
+
border-width: 1px 0 0 0;
|
|
3
|
+
border-style: solid;
|
|
4
|
+
border-color: var(--kona-editor-border-color);
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 1px;
|
|
7
|
+
margin: 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/* MenuItem styles */
|
|
11
|
+
.menuItemRoot {
|
|
12
|
+
list-style: none;
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
padding: 0 4px;
|
|
15
|
+
margin: 0;
|
|
16
|
+
border-radius: 4px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.menuItemRootNonSelectable {
|
|
20
|
+
cursor: default;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.menuItemContent {
|
|
24
|
+
border-radius: 4px;
|
|
25
|
+
padding: 8px 8px;
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
gap: 4px;
|
|
29
|
+
user-select: none;
|
|
30
|
+
color: var(--kona-editor-text-color);
|
|
31
|
+
background-color: transparent;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.menuItemContentSelected {
|
|
35
|
+
color: #0066cc;
|
|
36
|
+
background-color: #e6f0ff;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.menuItemContentDanger {
|
|
40
|
+
color: #cc0000;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* MenuIcon styles */
|
|
44
|
+
.menuIcon {
|
|
45
|
+
display: inline-flex;
|
|
46
|
+
width: 16px;
|
|
47
|
+
height: 16px;
|
|
48
|
+
align-items: center;
|
|
49
|
+
justify-content: center;
|
|
50
|
+
color: inherit;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* MenuTitle styles */
|
|
54
|
+
.menuTitle {
|
|
55
|
+
flex-grow: 1;
|
|
56
|
+
min-width: 70px;
|
|
57
|
+
color: inherit;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* MenuHotkey styles */
|
|
61
|
+
.menuHotkey {
|
|
62
|
+
display: inline-flex;
|
|
63
|
+
align-items: center;
|
|
64
|
+
justify-content: center;
|
|
65
|
+
background-color: rgba(0, 0, 0, 0.05);
|
|
66
|
+
border-radius: 4px;
|
|
67
|
+
padding: 0 4px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* Menu styles */
|
|
71
|
+
.menu {
|
|
72
|
+
position: absolute;
|
|
73
|
+
z-index: 13;
|
|
74
|
+
margin: 0;
|
|
75
|
+
padding: 4px 0;
|
|
76
|
+
background-color: var(--kona-editor-background-color);
|
|
77
|
+
border: 1px solid var(--kona-editor-border-color);
|
|
78
|
+
border-radius: 8px;
|
|
79
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
|
80
|
+
overflow: hidden;
|
|
81
|
+
box-sizing: border-box;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.menuVisible {
|
|
85
|
+
opacity: 1;
|
|
86
|
+
transform: scale(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.menuBody {
|
|
90
|
+
display: flex;
|
|
91
|
+
flex-direction: column;
|
|
92
|
+
height: 100%;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.menuScrollable {
|
|
96
|
+
overflow-y: auto;
|
|
97
|
+
overflow-x: hidden;
|
|
98
|
+
flex-grow: 1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.menuScrollable::-webkit-scrollbar {
|
|
102
|
+
background: #f5f5f5;
|
|
103
|
+
width: 6px;
|
|
104
|
+
border-radius: 8px;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.menuScrollable::-webkit-scrollbar-thumb {
|
|
108
|
+
background: #cccccc;
|
|
109
|
+
border-radius: 8px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.menuBackdrop {
|
|
113
|
+
position: fixed;
|
|
114
|
+
inset: 0;
|
|
115
|
+
z-index: 20;
|
|
116
|
+
background-color: rgba(0, 0, 0, 0.025);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.menuEnterAnimation {
|
|
120
|
+
animation: menuEnter 0.2s ease-in forwards;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@keyframes menuEnter {
|
|
124
|
+
from {
|
|
125
|
+
opacity: 0;
|
|
126
|
+
transform: scale(0.95);
|
|
127
|
+
}
|
|
128
|
+
to {
|
|
129
|
+
opacity: 1;
|
|
130
|
+
transform: scale(1);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@keyframes menuExit {
|
|
135
|
+
from {
|
|
136
|
+
opacity: 1;
|
|
137
|
+
transform: scale(1);
|
|
138
|
+
}
|
|
139
|
+
to {
|
|
140
|
+
opacity: 0;
|
|
141
|
+
transform: scale(0.95);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type MenuConfig = {
|
|
4
|
+
items?: MenuItem[];
|
|
5
|
+
header?: () => ReactNode;
|
|
6
|
+
footer?: () => ReactNode;
|
|
7
|
+
onOpen?: () => void;
|
|
8
|
+
onFocus?: () => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type MenuItem = {
|
|
12
|
+
render: () => ReactNode;
|
|
13
|
+
selectable?: boolean;
|
|
14
|
+
autoClose?: boolean;
|
|
15
|
+
config?: MenuConfig;
|
|
16
|
+
danger?: boolean;
|
|
17
|
+
onSelect?: () => void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export type Coords = [number, number];
|
|
4
|
+
|
|
5
|
+
type Point = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
class Context {
|
|
11
|
+
private readonly p: Point;
|
|
12
|
+
private rect: DOMRect;
|
|
13
|
+
|
|
14
|
+
constructor(p: Point, rect: DOMRect) {
|
|
15
|
+
this.p = { x: p.x, y: p.y };
|
|
16
|
+
this.rect = rect;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get point() {
|
|
20
|
+
return this.p;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
helpers = {
|
|
24
|
+
isWithinWindow: (): [boolean, boolean] => {
|
|
25
|
+
const left = this.p.x + this.rect.width;
|
|
26
|
+
|
|
27
|
+
return [
|
|
28
|
+
left < document.documentElement.clientWidth,
|
|
29
|
+
this.p.y + this.rect.height < document.documentElement.clientHeight,
|
|
30
|
+
];
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
flip = ([horizontal, vertical]: [boolean, boolean]) => {
|
|
35
|
+
if (horizontal) {
|
|
36
|
+
this.p.x -= this.rect.width;
|
|
37
|
+
}
|
|
38
|
+
if (vertical) {
|
|
39
|
+
this.p.y -= this.rect.height;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return this;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
move = (x: number, y: number) => {
|
|
46
|
+
this.p.x += x;
|
|
47
|
+
this.p.y += y;
|
|
48
|
+
|
|
49
|
+
return this;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const useMenuPosition = (point: Point, transform: (context: Context) => Point) => {
|
|
54
|
+
const [coords, setCoords] = useState<Point>(point);
|
|
55
|
+
|
|
56
|
+
const ref = useCallback(
|
|
57
|
+
(element: HTMLElement) => {
|
|
58
|
+
if (!element) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const rect = element.getBoundingClientRect();
|
|
63
|
+
const newCoords = transform(new Context(point, rect));
|
|
64
|
+
if (coords.x !== newCoords.x || coords.y !== newCoords.y) {
|
|
65
|
+
setCoords(newCoords);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
[point.x, point.y],
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return [ref, coords] as const;
|
|
72
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merges multiple React refs into a single ref callback.
|
|
5
|
+
*
|
|
6
|
+
* @template T The type of the ref value
|
|
7
|
+
* @param {React.Ref<T>[]} refs Array of refs to merge (can be both callback refs and object refs)
|
|
8
|
+
* @returns {React.RefCallback<T> | null} A merged ref callback or null if all input refs are null
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* function Component() {
|
|
12
|
+
* const firstRef = useRef<HTMLDivElement>(null)
|
|
13
|
+
* const secondRef = useRef<HTMLDivElement>(null)
|
|
14
|
+
* const forwardedRef = useForwardedRef<HTMLDivElement>(null)
|
|
15
|
+
*
|
|
16
|
+
* const mergedRef = useMergeRefs([firstRef, secondRef, forwardedRef])
|
|
17
|
+
*
|
|
18
|
+
* return (
|
|
19
|
+
* <div ref={mergedRef}>
|
|
20
|
+
* This div will be referenced by all three refs
|
|
21
|
+
* </div>
|
|
22
|
+
* )
|
|
23
|
+
* }
|
|
24
|
+
*/
|
|
25
|
+
export const useMergeRefs = <T>(refs: React.Ref<T>[]) =>
|
|
26
|
+
useMemo(() => {
|
|
27
|
+
if (refs.every((ref) => ref == null)) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return (refValue: T) => {
|
|
31
|
+
refs.forEach((ref) => {
|
|
32
|
+
if (typeof ref === 'function') {
|
|
33
|
+
ref(refValue);
|
|
34
|
+
} else if (ref != null) {
|
|
35
|
+
(ref as React.MutableRefObject<T | null>).current = refValue;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Editor } from 'slate';
|
|
2
|
+
import type { RenderElementProps } from 'slate-react';
|
|
3
|
+
import type { IPlugin } from '../../types';
|
|
4
|
+
import type { Options } from './types';
|
|
5
|
+
|
|
6
|
+
export class AttachmentsPlugin implements IPlugin {
|
|
7
|
+
constructor(private options: Options) {}
|
|
8
|
+
|
|
9
|
+
static ATTACHMENT_ELEMENT = 'attach';
|
|
10
|
+
|
|
11
|
+
handlers = {
|
|
12
|
+
onPaste: (event: ClipboardEvent, editor: Editor) => {
|
|
13
|
+
const items = Array.from(event.clipboardData?.items || []);
|
|
14
|
+
for (const item of items) {
|
|
15
|
+
if (item?.type.startsWith('image/')) {
|
|
16
|
+
const file = item.getAsFile();
|
|
17
|
+
if (file) {
|
|
18
|
+
this.options.onPaste?.(editor, file);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
blocks = [
|
|
26
|
+
{
|
|
27
|
+
type: AttachmentsPlugin.ATTACHMENT_ELEMENT,
|
|
28
|
+
isVoid: true,
|
|
29
|
+
render: (props: RenderElementProps) => {
|
|
30
|
+
const { Attachment } = this.options;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<div {...props.attributes} contentEditable={false}>
|
|
34
|
+
{props.children}
|
|
35
|
+
<Attachment {...props} />
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AttachmentsPlugin } from './AttachmentsPlugin';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Editor } from 'slate';
|
|
2
|
+
import { RenderElementProps } from 'slate-react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
export type Options = {
|
|
6
|
+
onDragEnter?: () => void;
|
|
7
|
+
onDragLeave?: () => void;
|
|
8
|
+
onPaste?: (editor: Editor, file: File) => void;
|
|
9
|
+
onDelete?: (editor: Editor, fileId?: string) => void;
|
|
10
|
+
onDownload?: (fileId: string) => void;
|
|
11
|
+
Attachment: (props: RenderElementProps) => ReactNode;
|
|
12
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Editor } from 'slate';
|
|
2
|
+
import type { CustomElement, CustomText } from '../../../types';
|
|
3
|
+
import type { IPlugin } from '../../types';
|
|
4
|
+
|
|
5
|
+
type CustomLeaf = CustomText & {
|
|
6
|
+
bold?: boolean;
|
|
7
|
+
italic?: boolean;
|
|
8
|
+
underline?: boolean;
|
|
9
|
+
strikethrough?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export class BasicFormattingPlugin
|
|
13
|
+
implements IPlugin<Editor, CustomElement, CustomLeaf>
|
|
14
|
+
{
|
|
15
|
+
hotkeys = [
|
|
16
|
+
['cmd+b', (_, editor) => BasicFormattingPlugin.toggleBold(editor)] as const,
|
|
17
|
+
[
|
|
18
|
+
'ctrl+b',
|
|
19
|
+
(_, editor) => BasicFormattingPlugin.toggleBold(editor),
|
|
20
|
+
] as const,
|
|
21
|
+
|
|
22
|
+
[
|
|
23
|
+
'cmd+i',
|
|
24
|
+
(_, editor) => BasicFormattingPlugin.toggleItalic(editor),
|
|
25
|
+
] as const,
|
|
26
|
+
[
|
|
27
|
+
'ctrl+i',
|
|
28
|
+
(_, editor) => BasicFormattingPlugin.toggleItalic(editor),
|
|
29
|
+
] as const,
|
|
30
|
+
|
|
31
|
+
[
|
|
32
|
+
'cmd+u',
|
|
33
|
+
(_, editor) => BasicFormattingPlugin.toggleUnderline(editor),
|
|
34
|
+
] as const,
|
|
35
|
+
[
|
|
36
|
+
'ctrl+u',
|
|
37
|
+
(_, editor) => BasicFormattingPlugin.toggleUnderline(editor),
|
|
38
|
+
] as const,
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
leafs: IPlugin<Editor, CustomElement, CustomLeaf>['leafs'] = [
|
|
42
|
+
{
|
|
43
|
+
render: (props) => {
|
|
44
|
+
const { leaf, attributes, children } = props;
|
|
45
|
+
|
|
46
|
+
let content = children;
|
|
47
|
+
|
|
48
|
+
if (leaf.bold) {
|
|
49
|
+
content = <strong>{content}</strong>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (leaf.italic) {
|
|
53
|
+
content = <em>{content}</em>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (leaf.underline) {
|
|
57
|
+
content = <u>{content}</u>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (leaf.strikethrough) {
|
|
61
|
+
content = <s>{content}</s>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return <span {...attributes}>{content}</span>;
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
static isMarkActive(editor: Editor, mark: keyof CustomLeaf) {
|
|
70
|
+
const marks: Record<string, boolean> | null = Editor.marks(editor);
|
|
71
|
+
|
|
72
|
+
return marks ? marks[mark] === true : false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static toggleMark(editor: Editor, mark: keyof CustomLeaf) {
|
|
76
|
+
const isActive = BasicFormattingPlugin.isMarkActive(editor, mark);
|
|
77
|
+
|
|
78
|
+
if (isActive) {
|
|
79
|
+
editor.removeMark(mark);
|
|
80
|
+
} else {
|
|
81
|
+
editor.addMark(mark, true);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static toggleBold(editor: Editor) {
|
|
86
|
+
BasicFormattingPlugin.toggleMark(editor, 'bold');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static toggleItalic(editor: Editor) {
|
|
90
|
+
BasicFormattingPlugin.toggleMark(editor, 'italic');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static toggleUnderline(editor: Editor) {
|
|
94
|
+
BasicFormattingPlugin.toggleMark(editor, 'underline');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static toggleStrikethrough(editor: Editor) {
|
|
98
|
+
BasicFormattingPlugin.toggleMark(editor, 'strikethrough');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BasicFormattingPlugin } from './BasicFormattingPlugin';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { KeyboardEvent } from 'react';
|
|
2
|
+
import { Editor, Transforms } from 'slate';
|
|
3
|
+
import type { CustomElement } from '../../../types';
|
|
4
|
+
import type { IPlugin } from '../../types';
|
|
5
|
+
|
|
6
|
+
type Options = {
|
|
7
|
+
breakNodes: string[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export class BreaksPlugin implements IPlugin {
|
|
11
|
+
constructor(private options: Options) {}
|
|
12
|
+
|
|
13
|
+
init(editor: Editor) {
|
|
14
|
+
const { insertBreak } = editor;
|
|
15
|
+
|
|
16
|
+
editor.insertBreak = () => {
|
|
17
|
+
const node = Editor.above<CustomElement>(editor, {
|
|
18
|
+
match: (n) => Editor.isBlock(editor, n as CustomElement),
|
|
19
|
+
mode: 'lowest',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (!node) {
|
|
23
|
+
insertBreak();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const [element, path] = node;
|
|
28
|
+
|
|
29
|
+
const { selection } = editor;
|
|
30
|
+
if (!selection) {
|
|
31
|
+
insertBreak();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (this.options.breakNodes.includes(element.type)) {
|
|
36
|
+
const { anchor } = selection;
|
|
37
|
+
|
|
38
|
+
const isStart = Editor.isStart(editor, anchor, path);
|
|
39
|
+
|
|
40
|
+
if (isStart) {
|
|
41
|
+
Transforms.insertNodes(editor, {
|
|
42
|
+
type: 'paragraph',
|
|
43
|
+
children: [{ text: '' }],
|
|
44
|
+
});
|
|
45
|
+
Transforms.move(editor);
|
|
46
|
+
return;
|
|
47
|
+
} else {
|
|
48
|
+
insertBreak();
|
|
49
|
+
|
|
50
|
+
Transforms.setNodes(editor, {
|
|
51
|
+
type: 'paragraph',
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
insertBreak();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return editor;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
handlers = {
|
|
63
|
+
onKeyDown: (event: KeyboardEvent, editor: Editor) => {
|
|
64
|
+
if (event.key === 'Enter' && event.shiftKey) {
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
editor.insertText('\n');
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BreaksPlugin } from './BreaksPlugin';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { RenderElementProps } from 'slate-react';
|
|
3
|
+
import styles from './styles.module.css';
|
|
4
|
+
import type { CodeElement } from './types';
|
|
5
|
+
|
|
6
|
+
type Props = RenderElementProps & {
|
|
7
|
+
element: CodeElement;
|
|
8
|
+
renderLanguageSelector: (element: CodeElement) => ReactNode;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const CodeBlock = (props: Props) => {
|
|
12
|
+
return (
|
|
13
|
+
<div {...props.attributes} className={styles.code} spellCheck={false}>
|
|
14
|
+
<div contentEditable={false}>
|
|
15
|
+
{props.renderLanguageSelector(props.element)}
|
|
16
|
+
</div>
|
|
17
|
+
<div className={styles.content}>{props.children}</div>
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
};
|