From ed5f34ac69999adccca6842d337dd1db58e2b75e Mon Sep 17 00:00:00 2001 From: Ilya Y <75578537+ilya-bkv@users.noreply.github.com> Date: Fri, 28 Jul 2023 22:53:21 +0300 Subject: [PATCH] Fix Pack (#148) --- .../Editor/InlineForm/InlineForm.tsx | 10 ++-- .../Editor/InsertLinkForm/InsertLinkForm.tsx | 4 +- src/components/Editor/SimplifiedEditor.tsx | 9 ++-- .../Editor/TextBubbleMenu/TextBubbleMenu.tsx | 18 ++++++- .../UploadModalContent/UploadModalContent.tsx | 1 - .../_shared/SolidSwiper/SolidSwiper.tsx | 48 ++++++++++--------- src/pages/create.page.tsx | 4 +- 7 files changed, 57 insertions(+), 37 deletions(-) diff --git a/src/components/Editor/InlineForm/InlineForm.tsx b/src/components/Editor/InlineForm/InlineForm.tsx index 188bcc57..b2f59003 100644 --- a/src/components/Editor/InlineForm/InlineForm.tsx +++ b/src/components/Editor/InlineForm/InlineForm.tsx @@ -1,6 +1,6 @@ import styles from './InlineForm.module.scss' import { Icon } from '../../_shared/Icon' -import { createSignal } from 'solid-js' +import { createSignal, onMount } from 'solid-js' import { clsx } from 'clsx' import { Popover } from '../../_shared/Popover' import { useLocalize } from '../../../context/localize' @@ -13,7 +13,6 @@ type Props = { initialValue?: string showInput?: boolean placeholder: string - autoFocus?: boolean } export const InlineForm = (props: Props) => { @@ -21,6 +20,7 @@ export const InlineForm = (props: Props) => { const [formValue, setFormValue] = createSignal(props.initialValue || '') const [formValueError, setFormValueError] = createSignal() + const inputRef: { current: HTMLInputElement } = { current: null } const handleFormInput = (e) => { const value = e.currentTarget.value setFormValueError() @@ -57,11 +57,15 @@ export const InlineForm = (props: Props) => { props.initialValue ? props.onClear() : props.onClose() } + onMount(() => { + inputRef.current.focus() + }) + return (
(inputRef.current = el)} type="text" value={props.initialValue ?? ''} placeholder={props.placeholder} diff --git a/src/components/Editor/InsertLinkForm/InsertLinkForm.tsx b/src/components/Editor/InsertLinkForm/InsertLinkForm.tsx index 5ef0df3f..957b7442 100644 --- a/src/components/Editor/InsertLinkForm/InsertLinkForm.tsx +++ b/src/components/Editor/InsertLinkForm/InsertLinkForm.tsx @@ -1,12 +1,12 @@ import { Editor } from '@tiptap/core' import { validateUrl } from '../../../utils/validateUrl' -import { hideModal } from '../../../stores/ui' import { InlineForm } from '../InlineForm' import { useLocalize } from '../../../context/localize' import { createEditorTransaction } from 'solid-tiptap' type Props = { editor: Editor + onClose: () => void } export const checkUrl = (url) => { @@ -48,7 +48,7 @@ export const InsertLinkForm = (props: Props) => { onClear={handleClearLinkForm} validate={(value) => (validateUrl(value) ? '' : t('Invalid url format'))} onSubmit={handleLinkFormSubmit} - onClose={() => hideModal()} + onClose={() => props.onClose()} />
) diff --git a/src/components/Editor/SimplifiedEditor.tsx b/src/components/Editor/SimplifiedEditor.tsx index 8badf04a..66158589 100644 --- a/src/components/Editor/SimplifiedEditor.tsx +++ b/src/components/Editor/SimplifiedEditor.tsx @@ -138,6 +138,7 @@ const SimplifiedEditor = (props: Props) => { } if (event.code === 'KeyK' && (event.metaKey || event.ctrlKey) && !editor().state.selection.empty) { + event.preventDefault() showModal('editorInsertLink') } } @@ -149,7 +150,7 @@ const SimplifiedEditor = (props: Props) => { onCleanup(() => { window.removeEventListener('keydown', handleKeyDown) }) - const handleToggleBlockquote = () => editor().chain().focus().toggleBlockquote().run() + const handleInsertLink = () => !editor().state.selection.empty && showModal('editorInsertLink') return (
{
- + hideModal()} /> diff --git a/src/components/Editor/TextBubbleMenu/TextBubbleMenu.tsx b/src/components/Editor/TextBubbleMenu/TextBubbleMenu.tsx index ba5c964b..eeb67c5c 100644 --- a/src/components/Editor/TextBubbleMenu/TextBubbleMenu.tsx +++ b/src/components/Editor/TextBubbleMenu/TextBubbleMenu.tsx @@ -1,4 +1,4 @@ -import { Switch, Match, createSignal, Show } from 'solid-js' +import { Switch, Match, createSignal, Show, onMount, onCleanup } from 'solid-js' import type { Editor } from '@tiptap/core' import styles from './TextBubbleMenu.module.scss' import { Icon } from '../../_shared/Icon' @@ -51,12 +51,26 @@ export const TextBubbleMenu = (props: BubbleMenuProps) => { } setListBubbleOpen((prev) => !prev) } + const handleKeyDown = async (event) => { + if (event.code === 'KeyK' && (event.metaKey || event.ctrlKey) && !props.editor.state.selection.empty) { + event.preventDefault() + setLinkEditorOpen(true) + } + } + + onMount(() => { + window.addEventListener('keydown', handleKeyDown) + }) + + onCleanup(() => { + window.removeEventListener('keydown', handleKeyDown) + }) return (
- + setLinkEditorOpen(false)} /> <> diff --git a/src/components/Editor/UploadModalContent/UploadModalContent.tsx b/src/components/Editor/UploadModalContent/UploadModalContent.tsx index 0e7fb83c..c5c91890 100644 --- a/src/components/Editor/UploadModalContent/UploadModalContent.tsx +++ b/src/components/Editor/UploadModalContent/UploadModalContent.tsx @@ -106,7 +106,6 @@ export const UploadModalContent = (props: Props) => {
{ diff --git a/src/components/_shared/SolidSwiper/SolidSwiper.tsx b/src/components/_shared/SolidSwiper/SolidSwiper.tsx index 35e58e51..3a98b24c 100644 --- a/src/components/_shared/SolidSwiper/SolidSwiper.tsx +++ b/src/components/_shared/SolidSwiper/SolidSwiper.tsx @@ -304,29 +304,31 @@ export const SolidSwiper = (props: Props) => {
} > -
- handleSlideDescriptionChange(slideIndex(), 'title', event.target.value)} - /> - handleSlideDescriptionChange(slideIndex(), 'source', event.target.value)} - /> - handleSlideDescriptionChange(slideIndex(), 'body', value)} - submitButtonText={t('Save')} - /> -
+ 0}> +
+ handleSlideDescriptionChange(slideIndex(), 'title', event.target.value)} + /> + handleSlideDescriptionChange(slideIndex(), 'source', event.target.value)} + /> + handleSlideDescriptionChange(slideIndex(), 'body', value)} + submitButtonText={t('Save')} + /> +
+
) diff --git a/src/pages/create.page.tsx b/src/pages/create.page.tsx index 381b8364..69339410 100644 --- a/src/pages/create.page.tsx +++ b/src/pages/create.page.tsx @@ -30,10 +30,10 @@ export const CreatePage = () => {
  • - +
  • handleCreate('image')}>