Download node_modules/@tiptap/react/src/Context.tsx from sitcod3/modul-s: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/sitcod3/modul-s/resolve/c06e4783a2be21cd7ca9fedf1ede4d4f0156ba3a/node_modules/%40tiptap/react/src/Context.tsx
- Command line
-
hf download hf://spaces/sitcod3/modul-s@c06e4783a2be21cd7ca9fedf1ede4d4f0156ba3a/node_modules/@tiptap/react/src/Context.tsx
-
curl -L -o Context.tsx https://huggingface.co/spaces/sitcod3/modul-s/resolve/c06e4783a2be21cd7ca9fedf1ede4d4f0156ba3a/node_modules/%40tiptap/react/src/Context.tsx
1.6 kB
| import type { Editor } from '@tiptap/core' | |
| import type { HTMLAttributes, ReactNode } from 'react' | |
| import React, { createContext, useContext, useMemo } from 'react' | |
| import { EditorContent } from './EditorContent.js' | |
| import type { UseEditorOptions } from './useEditor.js' | |
| import { useEditor } 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) | |
| const contextValue = useMemo(() => ({ editor }), [editor]) | |
| if (!editor) { | |
| return null | |
| } | |
| return ( | |
| <EditorContext.Provider value={contextValue}> | |
| {slotBefore} | |
| <EditorConsumer> | |
| {({ editor: currentEditor }) => ( | |
| <EditorContent editor={currentEditor} {...editorContainerProps} /> | |
| )} | |
| </EditorConsumer> | |
| {children} | |
| {slotAfter} | |
| </EditorContext.Provider> | |
| ) | |
| } | |