chore: fix super editor menus overflowing

This commit is contained in:
Aman Harwara
2024-01-20 20:16:26 +05:30
parent b53ae1d09b
commit 5463b7b58e
6 changed files with 16 additions and 11 deletions

View File

@@ -989,7 +989,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
)}
{editorMode === 'super' && (
<div className={classNames('blocks-editor w-full flex-grow overflow-hidden overflow-y-auto')}>
<div className={classNames('blocks-editor w-full flex-grow overflow-hidden')}>
<SuperEditor
key={this.note.uuid}
application={this.application}

View File

@@ -3,7 +3,7 @@ import { isMobileScreen } from '@/Utils'
import { CSSProperties } from 'react'
import { PopoverAlignment, PopoverSide } from './Types'
import { OppositeSide, checkCollisions, getNonCollidingAlignment } from './Utils/Collisions'
import { getAppRect, getPopoverMaxHeight, getPositionedPopoverRect } from './Utils/Rect'
import { getPopoverMaxHeight, getPositionedPopoverRect } from './Utils/Rect'
const percentOf = (percent: number, value: number) => (percent / 100) * value
@@ -154,7 +154,7 @@ export const getPositionedPopoverStyles = ({
)
let maxHeight = getPopoverMaxHeight(
getAppRect(),
documentRect,
anchorRect,
disableFlip ? side : sideWithLessOverflows,
finalAlignment,

View File

@@ -24,7 +24,7 @@ export const getPopoverMaxHeight = (
if (buttonRect) {
switch (side) {
case 'top':
constraint = appRect.height - buttonRect.top
constraint = Math.abs(appRect.height - buttonRect.top)
if (topSafeAreaInset > 0) {
constraint += topSafeAreaInset
}

View File

@@ -65,6 +65,7 @@ import { useStateRef } from '@/Hooks/useStateRef'
import { getDOMRangeRect } from '../../Lexical/Utils/getDOMRangeRect'
import { getPositionedPopoverStyles } from '@/Components/Popover/GetPositionedPopoverStyles'
import usePreference from '@/Hooks/usePreference'
import { ElementIds } from '@/Constants/ElementIDs'
const TOGGLE_LINK_AND_EDIT_COMMAND = createCommand<string | null>('TOGGLE_LINK_AND_EDIT_COMMAND')
@@ -503,7 +504,7 @@ const ToolbarPlugin = () => {
const [isFocusInEditor, setIsFocusInEditor] = useState(false)
const [isFocusInToolbar, setIsFocusInToolbar] = useState(false)
const canShowToolbarOnMobile = isFocusInEditor || isFocusInToolbar
const canShowToolbarOnMobile = true
const canShowAllItems = isMobile || isToolbarFixedToTop
useEffect(() => {
@@ -583,7 +584,8 @@ const ToolbarPlugin = () => {
toolbarStore,
])
const popoverDocumentElement = editor.getRootElement()?.parentElement ?? document.body
const popoverDocumentElement =
document.getElementById(ElementIds.SuperEditor) ?? editor.getRootElement()?.parentElement ?? document.body
return (
<>
@@ -760,7 +762,7 @@ const ToolbarPlugin = () => {
disableMobileFullscreenTakeover
disableFlip
portal={false}
documentElement={isMobile ? popoverDocumentElement : undefined}
documentElement={popoverDocumentElement}
>
<div className="mb-1.5 mt-1 px-3 text-sm font-semibold uppercase text-text">Table of Contents</div>
<LexicalTableOfContents>
@@ -816,7 +818,7 @@ const ToolbarPlugin = () => {
disableFlip
containerClassName="md:!min-w-60 md:!w-auto"
portal={false}
documentElement={isMobile ? popoverDocumentElement : undefined}
documentElement={popoverDocumentElement}
>
<Menu a11yLabel="Text formatting options" className="!px-0" onClick={() => setIsTextFormatMenuOpen(false)}>
<ToolbarMenuItem
@@ -857,7 +859,7 @@ const ToolbarPlugin = () => {
disableFlip
containerClassName="md:!min-w-60 md:!w-auto"
portal={false}
documentElement={isMobile ? popoverDocumentElement : undefined}
documentElement={popoverDocumentElement}
>
<Menu a11yLabel="Text style" className="!px-0" onClick={() => setIsTextStyleMenuOpen(false)}>
<ToolbarMenuItem
@@ -930,7 +932,7 @@ const ToolbarPlugin = () => {
disableFlip
containerClassName="md:!min-w-60 md:!w-auto"
portal={false}
documentElement={isMobile ? popoverDocumentElement : undefined}
documentElement={popoverDocumentElement}
>
<Menu a11yLabel="Alignment" className="!px-0" onClick={() => setIsAlignmentMenuOpen(false)}>
<ToolbarMenuItem
@@ -971,7 +973,7 @@ const ToolbarPlugin = () => {
disableFlip
containerClassName="md:!min-w-60 md:!w-auto"
portal={false}
documentElement={isMobile ? popoverDocumentElement : undefined}
documentElement={popoverDocumentElement}
>
<Menu a11yLabel="Insert" className="!px-0" onClick={() => setIsInsertMenuOpen(false)}>
<ToolbarMenuItem

View File

@@ -39,6 +39,7 @@ import AutoFocusPlugin from './Plugins/AutoFocusPlugin'
import usePreference from '@/Hooks/usePreference'
import BlockPickerMenuPlugin from './Plugins/BlockPickerPlugin/BlockPickerPlugin'
import { EditorEventSource } from '@/Types/EditorEventSource'
import { ElementIds } from '@/Constants/ElementIDs'
export const SuperNotePreviewCharLimit = 160
@@ -187,6 +188,7 @@ export const SuperEditor: FunctionComponent<Props> = ({
return (
<div
id={ElementIds.SuperEditor}
className="font-editor relative flex h-full w-full flex-col"
style={
{

View File

@@ -14,4 +14,5 @@ export const ElementIds = {
ItemLinkAutocompleteInput: 'item-link-autocomplete-input',
SearchBar: 'search-bar',
ConflictResolutionButton: 'conflict-resolution-button',
SuperEditor: 'super-editor',
} as const