1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-08 00:06:37 +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:
Sunny Hirai
2021-03-20 20:49:58 -07:00
committed by GitHub
parent b0c27496ec
commit 3caf0e1849
6 changed files with 26 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
{ {
"lerna": "2.7.1", "lerna": "2.7.1",
"version": "0.60.11", "version": "0.60.14",
"npmClient": "yarn", "npmClient": "yarn",
"useWorkspaces": true "useWorkspaces": true
} }

View File

@@ -1,7 +1,7 @@
{ {
"name": "slate-react", "name": "slate-react",
"description": "Tools for building completely customizable richtext editors with React.", "description": "Tools for building completely customizable richtext editors with React.",
"version": "0.60.11", "version": "0.60.14",
"license": "MIT", "license": "MIT",
"repository": "git://github.com/ianstormtaylor/slate.git", "repository": "git://github.com/ianstormtaylor/slate.git",
"main": "dist/index.js", "main": "dist/index.js",

View File

@@ -1,12 +1,14 @@
import { BaseRange, BaseText } from 'slate' import { BaseRange, BaseText } from 'slate'
import { ReactEditor } from './plugin/react-editor'
declare module 'slate' { declare module 'slate' {
interface CustomTypes { interface CustomTypes {
Text: { Editor: ReactEditor
Text: BaseText & {
placeholder: string placeholder: string
} & BaseText }
Range: { Range: BaseRange & {
placeholder?: string placeholder?: string
} & BaseRange }
} }
} }

View File

@@ -1,6 +1,6 @@
import { createContext, useContext } from 'react' import { createContext, useContext } from 'react'
import { ReactEditor } from '../plugin/react-editor' import { ReactEditor } from '../plugin/react-editor'
import { Editor } from 'slate'
/** /**
* A React context for sharing the editor object. * 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. * Get the current editor object from the React context.
*/ */
export const useSlateStatic = () => { export const useSlateStatic = (): Editor => {
const editor = useContext(EditorContext) const editor = useContext(EditorContext)
if (!editor) { if (!editor) {

View File

@@ -1,5 +1,5 @@
import { createContext, useContext } from 'react' import { createContext, useContext } from 'react'
import { Editor } from 'slate'
import { ReactEditor } from '../plugin/react-editor' 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. * Get the current editor object from the React context.
*/ */
export const useSlate = () => { export const useSlate = (): Editor => {
const context = useContext(SlateContext) const context = useContext(SlateContext)
if (!context) { if (!context) {

View File

@@ -1,4 +1,14 @@
import { Text, createEditor, Node, Element, Editor, Descendant } from 'slate' import {
Text,
createEditor,
Node,
Element,
Editor,
Descendant,
BaseEditor,
} from 'slate'
import { ReactEditor } from 'slate-react'
import { HistoryEditor } from 'slate-history'
export type BlockQuoteElement = { type: 'block-quote'; children: Descendant[] } export type BlockQuoteElement = { type: 'block-quote'; children: Descendant[] }
@@ -79,8 +89,11 @@ export type EmptyText = {
text: string text: string
} }
export type CustomEditor = BaseEditor & ReactEditor & HistoryEditor
declare module 'slate' { declare module 'slate' {
interface CustomTypes { interface CustomTypes {
Editor: CustomEditor
Element: CustomElement Element: CustomElement
Text: CustomText | EmptyText Text: CustomText | EmptyText
} }