mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 17:53:59 +02:00
Allow useSlate and useSlateStatic to use a generic to return a Custom Editor (#4135)
* Have useSlate and useSlateStatic return the Custom Editor * v0.60.12 * Add generic to useSlate and useSlateStatic * v0.60.13 * Fix useSlate and useSlateStatic to return customized Editor type * v0.60.14
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "slate-react",
|
||||
"description": "Tools for building completely customizable richtext editors with React.",
|
||||
"version": "0.60.11",
|
||||
"version": "0.60.14",
|
||||
"license": "MIT",
|
||||
"repository": "git://github.com/ianstormtaylor/slate.git",
|
||||
"main": "dist/index.js",
|
||||
|
@@ -1,12 +1,14 @@
|
||||
import { BaseRange, BaseText } from 'slate'
|
||||
import { ReactEditor } from './plugin/react-editor'
|
||||
|
||||
declare module 'slate' {
|
||||
interface CustomTypes {
|
||||
Text: {
|
||||
Editor: ReactEditor
|
||||
Text: BaseText & {
|
||||
placeholder: string
|
||||
} & BaseText
|
||||
Range: {
|
||||
}
|
||||
Range: BaseRange & {
|
||||
placeholder?: string
|
||||
} & BaseRange
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { createContext, useContext } from 'react'
|
||||
|
||||
import { ReactEditor } from '../plugin/react-editor'
|
||||
import { Editor } from 'slate'
|
||||
|
||||
/**
|
||||
* A React context for sharing the editor object.
|
||||
@@ -12,7 +12,7 @@ export const EditorContext = createContext<ReactEditor | null>(null)
|
||||
* Get the current editor object from the React context.
|
||||
*/
|
||||
|
||||
export const useSlateStatic = () => {
|
||||
export const useSlateStatic = (): Editor => {
|
||||
const editor = useContext(EditorContext)
|
||||
|
||||
if (!editor) {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { createContext, useContext } from 'react'
|
||||
|
||||
import { Editor } from 'slate'
|
||||
import { ReactEditor } from '../plugin/react-editor'
|
||||
|
||||
/**
|
||||
@@ -13,7 +13,7 @@ export const SlateContext = createContext<[ReactEditor] | null>(null)
|
||||
* Get the current editor object from the React context.
|
||||
*/
|
||||
|
||||
export const useSlate = () => {
|
||||
export const useSlate = (): Editor => {
|
||||
const context = useContext(SlateContext)
|
||||
|
||||
if (!context) {
|
||||
|
Reference in New Issue
Block a user