PHP 8.2.30
Preview: Context.tsx Size: 1.42 KB
/proc/thread-self/root/home/byroehnu/.trash/node_modules11/@tiptap/react/src/Context.tsx

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

import { EditorContent } from './EditorContent.js'
import { useEditor, UseEditorOptions } from './useEditor.js'

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

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

export const EditorConsumer = EditorContext.Consumer

/**
 * A hook to get the current editor instance.
 */
export const useCurrentEditor = () => useContext(EditorContext)

export type EditorProviderProps = {
  children?: ReactNode;
  slotBefore?: ReactNode;
  slotAfter?: ReactNode;
  editorContainerProps?: HTMLAttributes<HTMLDivElement>;
} & UseEditorOptions

/**
 * This is the provider component for the editor.
 * It allows the editor to be accessible across the entire component tree
 * with `useCurrentEditor`.
 */
export function EditorProvider({
  children, slotAfter, slotBefore, editorContainerProps = {}, ...editorOptions
}: EditorProviderProps) {
  const editor = useEditor(editorOptions)

  if (!editor) {
    return null
  }

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

Directory Contents

Dirs: 0 × Files: 14

Name Size Perms Modified Actions
1.56 KB lrw-r--r-- 2026-02-28 11:47:14
Edit Download
1.42 KB lrw-r--r-- 2026-02-28 11:47:14
Edit Download
510 B lrw-r--r-- 2026-02-28 11:47:14
Edit Download
5.75 KB lrw-r--r-- 2026-02-28 11:47:14
Edit Download
1.56 KB lrw-r--r-- 2026-02-28 11:47:14
Edit Download
443 B lrw-r--r-- 2026-02-28 11:47:14
Edit Download
546 B lrw-r--r-- 2026-02-28 11:47:14
Edit Download
579 B lrw-r--r-- 2026-02-28 11:47:14
Edit Download
10.57 KB lrw-r--r-- 2026-02-28 11:47:14
Edit Download
6.18 KB lrw-r--r-- 2026-02-28 11:47:14
Edit Download
210 B lrw-r--r-- 2026-02-28 11:47:14
Edit Download
12.35 KB lrw-r--r-- 2026-02-28 11:47:14
Edit Download
5.54 KB lrw-r--r-- 2026-02-28 11:47:14
Edit Download
392 B lrw-r--r-- 2026-02-28 11:47:14
Edit Download

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