From e7065af358cb36997f470c70dccc4b739e352cd5 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Fri, 11 Oct 2024 19:11:39 +0530 Subject: [PATCH] [WEB-2494] dev: custom text color and background color extensions (#5786) * dev: created custom text color and background color extensions * chore: update slash commands icon style * chore: update constants * chore: update variables css file selectors --- packages/editor/package.json | 2 - .../menus/bubble-menu/color-selector.tsx | 36 +- .../src/core/components/menus/menu-items.ts | 2 +- packages/editor/src/core/constants/common.ts | 56 ++- .../src/core/extensions/core-without-props.ts | 10 +- .../extensions/custom-background-color.ts | 78 ++++ .../src/core/extensions/custom-text-color.ts | 78 ++++ .../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 | 117 ++--- packages/editor/src/styles/variables.css | 96 ++++ .../pages/editor/header/color-dropdown.tsx | 32 +- yarn.lock | 10 - 19 files changed, 604 insertions(+), 393 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 58f99a1e9..a152342a0 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 cc3eb5412..12495213d 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,17 @@ export const BubbleMenuColorSelector: FC = (props) => { "bg-custom-background-100": !activeBackgroundColor, } )} - style={ - activeBackgroundColor - ? { - backgroundColor: activeBackgroundColor.backgroundColor, - } - : {} - } + style={{ + backgroundColor: activeBackgroundColor ? activeBackgroundColor.backgroundColor : "transparent", + }} > @@ -70,13 +58,13 @@ export const BubbleMenuColorSelector: FC = (props) => {
{COLORS_LIST.map((color) => (