From 912354ae3f5bc81b44a64540b6f1f8bf12b29515 Mon Sep 17 00:00:00 2001 From: Gaagul Gigi <70290286+gaagul@users.noreply.github.com> Date: Wed, 18 Oct 2023 02:21:14 +0530 Subject: [PATCH] Created a popover for adding links to editor content (#904) * Created a popover for adding links to editor content * Removed unwanted translations * Optimized function calls * Fixed all styling related issues * Fixed bugs * Reduced length of link edit input * Updated z index and ui gaps * Updated positioning logic * Updated ousideClick logic for link view popOver --- src/components/Editor/LinkPopOver.jsx | 16 +- .../Editor/Menu/Bubble/TableOption.jsx | 6 +- .../Editor/Menu/Fixed/LinkAddPopOver.jsx | 178 +++++++++++++++ .../Editor/Menu/Fixed/LinkOption.jsx | 137 ------------ .../Editor/Menu/Fixed/TableActions.jsx | 6 +- src/components/Editor/Menu/Fixed/constants.js | 192 ----------------- src/components/Editor/Menu/Fixed/index.jsx | 14 +- src/components/Editor/Menu/Fixed/utils.jsx | 203 +++++++++++++++++- src/components/Editor/Menu/Headless/utils.js | 166 +++++++++++++- src/components/Editor/utils.js | 14 ++ src/icons/FileAttachments.jsx | 26 --- src/styles/editor/_link-popover.scss | 38 ++-- src/translations/en.json | 6 +- 13 files changed, 597 insertions(+), 405 deletions(-) create mode 100644 src/components/Editor/Menu/Fixed/LinkAddPopOver.jsx delete mode 100644 src/components/Editor/Menu/Fixed/LinkOption.jsx delete mode 100644 src/icons/FileAttachments.jsx diff --git a/src/components/Editor/LinkPopOver.jsx b/src/components/Editor/LinkPopOver.jsx index ad220996..bca041d3 100644 --- a/src/components/Editor/LinkPopOver.jsx +++ b/src/components/Editor/LinkPopOver.jsx @@ -1,10 +1,11 @@ import React, { useEffect, useState, useRef } from "react"; +import { useOnClickOutside } from "neetocommons/react-utils"; import { Button, Input } from "neetoui"; import { createPortal } from "react-dom"; import { useTranslation } from "react-i18next"; -import { URL_REGEXP } from "src/common/constants"; +import { validateAndFormatUrl } from "./utils"; const LinkPopOver = ({ editor }) => { const [popoverPosition, setPopoverPosition] = useState({ top: 0, left: 0 }); @@ -48,12 +49,14 @@ const LinkPopOver = ({ editor }) => { editor.chain().focus().extendMarkRange("link").unsetLink().run(); const handleLink = () => { - if (URL_REGEXP.test(urlString)) { + const formattedUrl = validateAndFormatUrl(urlString); + + if (formattedUrl) { editor .chain() .focus() .extendMarkRange("link") - .setLink({ href: urlString }) + .setLink({ href: formattedUrl }) .run(); setIsEditing(false); } else { @@ -79,6 +82,8 @@ const LinkPopOver = ({ editor }) => { setIsLinkActive(false); }; + useOnClickOutside(popOverRef, removePopover); + useEffect(() => { window.addEventListener("resize", removePopover); window.addEventListener("wheel", removePopover); @@ -103,7 +108,6 @@ const LinkPopOver = ({ editor }) => { position: "fixed", top: popoverPosition.top, left: popoverPosition.left, - zIndex: 999, transform: `translateY(52px) translateX(${isEditing ? "8px" : "3px"})`, }; @@ -114,7 +118,7 @@ const LinkPopOver = ({ editor }) => { {...{ error }} label={t("menu.link")} placeholder={t("placeholders.url")} - style={{ width: "400px" }} + style={{ width: "250px" }} value={urlString} onChange={({ target: { value } }) => setUrlString(value)} onFocus={() => setError("")} @@ -163,7 +167,7 @@ const LinkPopOver = ({ editor }) => { isLinkActive ? (