PHP 8.2.30
Preview: FloatingMenu.tsx Size: 1.51 KB
/home/byroehnu/.trash/node_modules11/@adminjs/design-system/node_modules/@tiptap/react/src/FloatingMenu.tsx

import { FloatingMenuPlugin, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'
import React, {
  useEffect, useState,
} from 'react'

import { useCurrentEditor } from './Context.js'

type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>

export type FloatingMenuProps = Omit<Optional<FloatingMenuPluginProps, 'pluginKey' | 'editor'>, 'element'> & {
  className?: string,
  children: React.ReactNode
}

export const FloatingMenu = (props: FloatingMenuProps) => {
  const [element, setElement] = useState<HTMLDivElement | null>(null)
  const { editor: currentEditor } = useCurrentEditor()

  useEffect(() => {
    if (!element) {
      return
    }

    if (props.editor?.isDestroyed || currentEditor?.isDestroyed) {
      return
    }

    const {
      pluginKey = 'floatingMenu',
      editor,
      tippyOptions = {},
      shouldShow = null,
    } = props

    const menuEditor = editor || currentEditor

    if (!menuEditor) {
      console.warn('FloatingMenu component is not rendered inside of an editor component or does not have editor prop.')
      return
    }

    const plugin = FloatingMenuPlugin({
      pluginKey,
      editor: menuEditor,
      element,
      tippyOptions,
      shouldShow,
    })

    menuEditor.registerPlugin(plugin)
    return () => menuEditor.unregisterPlugin(pluginKey)
  }, [
    props.editor,
    currentEditor,
    element,
  ])

  return (
    <div ref={setElement} className={props.className} style={{ visibility: 'hidden' }}>
      {props.children}
    </div>
  )
}

Directory Contents

Dirs: 0 × Files: 12

Name Size Perms Modified Actions
1.51 KB lrw-r--r-- 2026-02-28 11:47:04
Edit Download
1.12 KB lrw-r--r-- 2026-02-28 11:47:04
Edit Download
489 B lrw-r--r-- 2026-02-28 11:47:04
Edit Download
3.52 KB lrw-r--r-- 2026-02-28 11:47:04
Edit Download
1.51 KB lrw-r--r-- 2026-02-28 11:47:04
Edit Download
379 B lrw-r--r-- 2026-02-28 11:47:04
Edit Download
528 B lrw-r--r-- 2026-02-28 11:47:04
Edit Download
561 B lrw-r--r-- 2026-02-28 11:47:04
Edit Download
5.92 KB lrw-r--r-- 2026-02-28 11:47:04
Edit Download
2.19 KB lrw-r--r-- 2026-02-28 11:47:04
Edit Download
2.96 KB lrw-r--r-- 2026-02-28 11:47:04
Edit Download
392 B lrw-r--r-- 2026-02-28 11:47:04
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).