From 467df605a6cf478b351ff5d38fc16962abfad7ca Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal Date: Wed, 9 Oct 2024 20:45:19 +0530 Subject: [PATCH] dev: created custom text color and background color extensions --- packages/editor/package.json | 2 - .../menus/bubble-menu/color-selector.tsx | 42 +- .../src/core/components/menus/menu-items.ts | 2 +- packages/editor/src/core/constants/common.ts | 50 ++- .../src/core/extensions/core-without-props.ts | 10 +- .../extensions/custom-background-color.ts | 65 +++ .../src/core/extensions/custom-text-color.ts | 65 +++ .../editor/src/core/extensions/extensions.tsx | 10 +- packages/editor/src/core/extensions/index.ts | 2 + .../core/extensions/read-only-extensions.tsx | 10 +- .../slash-commands/command-items-list.tsx | 422 +++++++++--------- .../slash-commands/command-menu.tsx | 4 +- .../core/extensions/slash-commands/root.tsx | 2 - .../src/core/helpers/editor-commands.ts | 29 +- packages/editor/src/index.ts | 1 + packages/editor/src/styles/editor.css | 112 +++-- packages/editor/src/styles/variables.css | 94 ++++ .../pages/editor/header/color-dropdown.tsx | 42 +- yarn.lock | 10 - 19 files changed, 576 insertions(+), 398 deletions(-) create mode 100644 packages/editor/src/core/extensions/custom-background-color.ts create mode 100644 packages/editor/src/core/extensions/custom-text-color.ts create mode 100644 packages/editor/src/styles/variables.css diff --git a/packages/editor/package.json b/packages/editor/package.json index 01d03db1fd..d0c323423e 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -42,8 +42,6 @@ "@tiptap/extension-blockquote": "^2.1.13", "@tiptap/extension-character-count": "^2.6.5", "@tiptap/extension-collaboration": "^2.3.2", - "@tiptap/extension-color": "^2.7.1", - "@tiptap/extension-highlight": "^2.7.1", "@tiptap/extension-image": "^2.1.13", "@tiptap/extension-list-item": "^2.1.13", "@tiptap/extension-mention": "^2.1.13", diff --git a/packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx b/packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx index cc3eb5412e..0f0ae62b5b 100644 --- a/packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx +++ b/packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx @@ -16,12 +16,8 @@ type Props = { export const BubbleMenuColorSelector: FC = (props) => { const { editor, isOpen, setIsOpen } = props; - const activeTextColor = COLORS_LIST.find((c) => editor.getAttributes("textStyle").color === c.textColor); - const activeBackgroundColor = COLORS_LIST.find((c) => - editor.isActive("highlight", { - color: c.backgroundColor, - }) - ); + const activeTextColor = COLORS_LIST.find((c) => editor.getAttributes("textStyle").color === c.key); + const activeBackgroundColor = COLORS_LIST.find((c) => editor.getAttributes("textStyle").backgroundColor === c.key); return (
@@ -41,25 +37,19 @@ export const BubbleMenuColorSelector: FC = (props) => { "bg-custom-background-100": !activeBackgroundColor, } )} - style={ - activeBackgroundColor - ? { - backgroundColor: activeBackgroundColor.backgroundColor, - } - : {} - } + style={{ + backgroundColor: activeBackgroundColor + ? `var(${activeBackgroundColor.backgroundColorVariable})` + : "transparent", + }} > @@ -70,13 +60,13 @@ export const BubbleMenuColorSelector: FC = (props) => {
{COLORS_LIST.map((color) => (