From 87f66d83b6eabc55d3eee4ae5b81c034e1879b2c Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Thu, 23 Mar 2023 20:24:28 +0300 Subject: [PATCH] cleanup code --- .../Editor/EditorBubbleMenu.module.scss | 8 +++ src/components/Editor/EditorBubbleMenu.tsx | 68 ++++++------------- 2 files changed, 27 insertions(+), 49 deletions(-) diff --git a/src/components/Editor/EditorBubbleMenu.module.scss b/src/components/Editor/EditorBubbleMenu.module.scss index 294b1e9c..effd55df 100644 --- a/src/components/Editor/EditorBubbleMenu.module.scss +++ b/src/components/Editor/EditorBubbleMenu.module.scss @@ -13,6 +13,14 @@ .triangle { margin-left: 4px; } + + .colorWheel { + display: inline-block; + width: 20px; + height: 20px; + border-radius: 50%; + background: #f6e3a1; + } } &:hover, diff --git a/src/components/Editor/EditorBubbleMenu.tsx b/src/components/Editor/EditorBubbleMenu.tsx index cdc85bfa..392630a2 100644 --- a/src/components/Editor/EditorBubbleMenu.tsx +++ b/src/components/Editor/EditorBubbleMenu.tsx @@ -6,8 +6,9 @@ import { clsx } from 'clsx' import { createEditorTransaction } from 'solid-tiptap' import { useLocalize } from '../../context/localize' import validateUrl from '../../utils/validateUrl' -import list from '../Feed/List' +type HeadingLevel = 1 | 2 | 3 +type ActionName = 'heading' | 'bold' | 'italic' | 'blockquote' | 'isOrderedList' | 'isBulletList' type BubbleMenuProps = { editor: Editor ref: (el: HTMLDivElement) => void @@ -22,42 +23,14 @@ export const EditorBubbleMenu = (props: BubbleMenuProps) => { const [prevUrl, setPrevUrl] = createSignal(null) const [linkError, setLinkError] = createSignal(null) - const isBold = createEditorTransaction( - () => props.editor, - (editor) => editor && editor.isActive('bold') - ) - const isItalic = createEditorTransaction( - () => props.editor, - (editor) => editor && editor.isActive('italic') - ) - - //props.editor.isActive('heading', { level: 1 }) - либо инлайново либо как-то возвращать что активно - const isHOne = createEditorTransaction( - () => props.editor, - (editor) => editor && editor.isActive('heading', { level: 1 }) - ) - const isHTwo = createEditorTransaction( - () => props.editor, - (editor) => editor && editor.isActive('heading', { level: 2 }) - ) - const isHThree = createEditorTransaction( - () => props.editor, - (editor) => editor && editor.isActive('heading', { level: 3 }) - ) - const isBlockQuote = createEditorTransaction( - () => props.editor, - (editor) => editor && editor.isActive('blockquote') - ) - const isOrderedList = createEditorTransaction( - () => props.editor, - (editor) => editor && editor.isActive('isOrderedList') - ) - const isBulletList = createEditorTransaction( - () => props.editor, - (editor) => editor && editor.isActive('isBulletList') - ) + const activeControl = (action: ActionName, actionLevel?: HeadingLevel, prevLink?: boolean) => + createEditorTransaction( + () => props.editor, + (editor) => editor && editor.isActive(action, actionLevel && { actionLevel }) + ) const isLink = createEditorTransaction( + // вызов этой ф-ии обусловлен не через хэлпер activeControl только проверкой установленна ли ссылка () => props.editor, (editor) => { editor && editor.isActive('link') @@ -72,12 +45,6 @@ export const EditorBubbleMenu = (props: BubbleMenuProps) => { const handleSubmitLink = (e) => { e.preventDefault() - if (url().length === 0) { - props.editor.chain().focus().unsetLink().run() - clearLinkForm() - return - } - if (url().length > 1 && validateUrl(url())) { props.editor.commands.toggleLink({ href: url() }) clearLinkForm() @@ -137,7 +104,7 @@ export const EditorBubbleMenu = (props: BubbleMenuProps) => { + @@ -228,7 +198,7 @@ export const EditorBubbleMenu = (props: BubbleMenuProps) => {