[WIKI-725] regression: editor floaters propagation #7938
This commit is contained in:
parent
5d161f671d
commit
d8c1dff34f
6 changed files with 32 additions and 13 deletions
|
|
@ -44,25 +44,18 @@ export const EmojisListDropdown = forwardRef<EmojiListRef, EmojisListDropdownPro
|
||||||
if (query.length <= 0) {
|
if (query.length <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (event.key === "Escape") {
|
|
||||||
event.preventDefault();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key === "ArrowUp") {
|
if (event.key === "ArrowUp") {
|
||||||
event.preventDefault();
|
|
||||||
setSelectedIndex((prev) => (prev + items.length - 1) % items.length);
|
setSelectedIndex((prev) => (prev + items.length - 1) % items.length);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === "ArrowDown") {
|
if (event.key === "ArrowDown") {
|
||||||
event.preventDefault();
|
|
||||||
setSelectedIndex((prev) => (prev + 1) % items.length);
|
setSelectedIndex((prev) => (prev + 1) % items.length);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
event.preventDefault();
|
|
||||||
selectItem(selectedIndex);
|
selectItem(selectedIndex);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -130,6 +123,12 @@ export const EmojisListDropdown = forwardRef<EmojiListRef, EmojisListDropdownPro
|
||||||
style={{
|
style={{
|
||||||
zIndex: 100,
|
zIndex: 100,
|
||||||
}}
|
}}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
onMouseDown={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{items.length ? (
|
{items.length ? (
|
||||||
items.map((item, index) => {
|
items.map((item, index) => {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { ReactRenderer, type Editor } from "@tiptap/react";
|
||||||
import { CORE_EXTENSIONS } from "@/constants/extension";
|
import { CORE_EXTENSIONS } from "@/constants/extension";
|
||||||
// helpers
|
// helpers
|
||||||
import { updateFloatingUIFloaterPosition } from "@/helpers/floating-ui";
|
import { updateFloatingUIFloaterPosition } from "@/helpers/floating-ui";
|
||||||
import { CommandListInstance } from "@/helpers/tippy";
|
import { CommandListInstance, DROPDOWN_NAVIGATION_KEYS } from "@/helpers/tippy";
|
||||||
// local imports
|
// local imports
|
||||||
import { type EmojiItem, EmojisListDropdown, EmojisListDropdownProps } from "./components/emojis-list";
|
import { type EmojiItem, EmojisListDropdown, EmojisListDropdownProps } from "./components/emojis-list";
|
||||||
|
|
||||||
|
|
@ -82,11 +82,17 @@ export const emojiSuggestion: EmojiOptions["suggestion"] = {
|
||||||
cleanup = updateFloatingUIFloaterPosition(props.editor, component.element).cleanup;
|
cleanup = updateFloatingUIFloaterPosition(props.editor, component.element).cleanup;
|
||||||
},
|
},
|
||||||
onKeyDown: ({ event }) => {
|
onKeyDown: ({ event }) => {
|
||||||
|
if ([...DROPDOWN_NAVIGATION_KEYS, "Escape"].includes(event.key)) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
if (event.key === "Escape") {
|
if (event.key === "Escape") {
|
||||||
handleClose();
|
handleClose();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return component?.ref?.onKeyDown({ event }) || false;
|
|
||||||
|
return component?.ref?.onKeyDown({ event }) ?? false;
|
||||||
},
|
},
|
||||||
|
|
||||||
onExit: ({ editor }) => {
|
onExit: ({ editor }) => {
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ export const MentionsListDropdown = forwardRef((props: MentionsListDropdownProps
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
onKeyDown: ({ event }: { event: KeyboardEvent }) => {
|
onKeyDown: ({ event }: { event: KeyboardEvent }) => {
|
||||||
if (!DROPDOWN_NAVIGATION_KEYS.includes(event.key)) return false;
|
if (!DROPDOWN_NAVIGATION_KEYS.includes(event.key)) return false;
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
selectItem(selectedIndex.section, selectedIndex.item);
|
selectItem(selectedIndex.section, selectedIndex.item);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import type { SuggestionOptions } from "@tiptap/suggestion";
|
||||||
import { CORE_EXTENSIONS } from "@/constants/extension";
|
import { CORE_EXTENSIONS } from "@/constants/extension";
|
||||||
// helpers
|
// helpers
|
||||||
import { updateFloatingUIFloaterPosition } from "@/helpers/floating-ui";
|
import { updateFloatingUIFloaterPosition } from "@/helpers/floating-ui";
|
||||||
import { CommandListInstance } from "@/helpers/tippy";
|
import { CommandListInstance, DROPDOWN_NAVIGATION_KEYS } from "@/helpers/tippy";
|
||||||
// types
|
// types
|
||||||
import { TMentionHandler } from "@/types";
|
import { TMentionHandler } from "@/types";
|
||||||
// local components
|
// local components
|
||||||
|
|
@ -51,6 +51,11 @@ export const renderMentionsDropdown =
|
||||||
cleanup = updateFloatingUIFloaterPosition(props.editor, component.element).cleanup;
|
cleanup = updateFloatingUIFloaterPosition(props.editor, component.element).cleanup;
|
||||||
},
|
},
|
||||||
onKeyDown: ({ event }) => {
|
onKeyDown: ({ event }) => {
|
||||||
|
if ([...DROPDOWN_NAVIGATION_KEYS, "Escape"].includes(event.key)) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
if (event.key === "Escape") {
|
if (event.key === "Escape") {
|
||||||
handleClose();
|
handleClose();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,6 @@ export const SlashCommandsMenu = forwardRef((props: SlashCommandsMenuProps, ref)
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
onKeyDown: ({ event }: { event: KeyboardEvent }) => {
|
onKeyDown: ({ event }: { event: KeyboardEvent }) => {
|
||||||
if (!DROPDOWN_NAVIGATION_KEYS.includes(event.key)) return false;
|
if (!DROPDOWN_NAVIGATION_KEYS.includes(event.key)) return false;
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
selectItem(selectedIndex.section, selectedIndex.item);
|
selectItem(selectedIndex.section, selectedIndex.item);
|
||||||
|
|
@ -136,6 +135,12 @@ export const SlashCommandsMenu = forwardRef((props: SlashCommandsMenuProps, ref)
|
||||||
style={{
|
style={{
|
||||||
zIndex: 100,
|
zIndex: 100,
|
||||||
}}
|
}}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
onMouseDown={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{sections.map((section, sectionIndex) => (
|
{sections.map((section, sectionIndex) => (
|
||||||
<div key={section.key} className="space-y-2">
|
<div key={section.key} className="space-y-2">
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import Suggestion, { type SuggestionOptions } from "@tiptap/suggestion";
|
||||||
import { CORE_EXTENSIONS } from "@/constants/extension";
|
import { CORE_EXTENSIONS } from "@/constants/extension";
|
||||||
// helpers
|
// helpers
|
||||||
import { updateFloatingUIFloaterPosition } from "@/helpers/floating-ui";
|
import { updateFloatingUIFloaterPosition } from "@/helpers/floating-ui";
|
||||||
import { CommandListInstance } from "@/helpers/tippy";
|
import { CommandListInstance, DROPDOWN_NAVIGATION_KEYS } from "@/helpers/tippy";
|
||||||
// types
|
// types
|
||||||
import { IEditorProps, ISlashCommandItem, TEditorCommands, TSlashCommandSectionKeys } from "@/types";
|
import { IEditorProps, ISlashCommandItem, TEditorCommands, TSlashCommandSectionKeys } from "@/types";
|
||||||
// components
|
// components
|
||||||
|
|
@ -88,6 +88,11 @@ const Command = Extension.create<SlashCommandOptions>({
|
||||||
},
|
},
|
||||||
|
|
||||||
onKeyDown: ({ event }) => {
|
onKeyDown: ({ event }) => {
|
||||||
|
if ([...DROPDOWN_NAVIGATION_KEYS, "Escape"].includes(event.key)) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
if (event.key === "Escape") {
|
if (event.key === "Escape") {
|
||||||
handleClose(this.editor);
|
handleClose(this.editor);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue