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

import { EditorOptions } from '@tiptap/core'
import React, { createContext, ReactNode, useContext } from 'react'

import { Editor } from './Editor.js'
import { EditorContent } from './EditorContent.js'
import { useEditor } from './useEditor.js'

export type EditorContextValue = {
  editor: Editor | null;
}

export const EditorContext = createContext<EditorContextValue>({
  editor: null,
})

export const EditorConsumer = EditorContext.Consumer

export const useCurrentEditor = () => useContext(EditorContext)

export type EditorProviderProps = {
  children: ReactNode;
  slotBefore?: ReactNode;
  slotAfter?: ReactNode;
} & Partial<EditorOptions>

export const EditorProvider = ({
  children, slotAfter, slotBefore, ...editorOptions
}: EditorProviderProps) => {
  const editor = useEditor(editorOptions)

  if (!editor) {
    return null
  }

  return (
    <EditorContext.Provider value={{ editor }}>
      {slotBefore}
      <EditorConsumer>
        {({ editor: currentEditor }) => (
          <EditorContent editor={currentEditor} />
        )}
      </EditorConsumer>
      {children}
      {slotAfter}
    </EditorContext.Provider>
  )
}

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).