1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-13 18:53:59 +02:00

Merge TypeScript types from master into main

This commit is contained in:
Sunny Hirai
2020-11-27 16:31:16 -08:00
74 changed files with 3410 additions and 3414 deletions

View File

@@ -24,6 +24,7 @@
},
"devDependencies": {
"slate": "^0.60.0",
"slate-history": "^0.60.0",
"slate-hyperscript": "^0.60.0"
},
"peerDependencies": {

View File

@@ -9,6 +9,7 @@ import {
Transforms,
Path,
} from 'slate'
import { HistoryEditor } from 'slate-history'
import throttle from 'lodash/throttle'
import scrollIntoView from 'scroll-into-view-if-needed'
@@ -766,7 +767,7 @@ export const Editable = (props: EditableProps) => {
if (Hotkeys.isRedo(nativeEvent)) {
event.preventDefault()
if (typeof editor.redo === 'function') {
if (HistoryEditor.isHistoryEditor(editor)) {
editor.redo()
}
@@ -776,7 +777,7 @@ export const Editable = (props: EditableProps) => {
if (Hotkeys.isUndo(nativeEvent)) {
event.preventDefault()
if (typeof editor.undo === 'function') {
if (HistoryEditor.isHistoryEditor(editor)) {
editor.undo()
}

View File

@@ -1,6 +1,5 @@
import React from 'react'
import { Text, Element } from 'slate'
import { Element, Text } from 'slate'
import String from './string'
import { PLACEHOLDER_SYMBOL } from '../utils/weak-maps'
import { RenderLeafProps } from './editable'
@@ -46,7 +45,7 @@ const Leaf = (props: {
textDecoration: 'none',
}}
>
{leaf.placeholder as React.ReactNode}
{leaf.placeholder}
</span>
{children}
</React.Fragment>
@@ -75,10 +74,6 @@ const MemoizedLeaf = React.memo(Leaf, (prev, next) => {
)
})
/**
* The default custom leaf renderer.
*/
export const DefaultLeaf = (props: RenderLeafProps) => {
const { attributes, children } = props
return <span {...attributes}>{children}</span>

View File

@@ -1,5 +1,5 @@
import React, { useMemo, useState, useCallback, useEffect } from 'react'
import { Node } from 'slate'
import { Node, Element, Descendant } from 'slate'
import { ReactEditor } from '../plugin/react-editor'
import { FocusedContext } from '../hooks/use-focused'
@@ -14,10 +14,9 @@ import { EDITOR_TO_ON_CHANGE } from '../utils/weak-maps'
export const Slate = (props: {
editor: ReactEditor
value: Node[]
value: Descendant[]
children: React.ReactNode
onChange: (value: Node[]) => void
[key: string]: unknown
onChange: (value: Descendant[]) => void
}) => {
const { editor, children, onChange, value, ...rest } = props
const [key, setKey] = useState(0)

View File

@@ -0,0 +1,12 @@
import { CustomTypes } from 'slate'
declare module 'slate' {
interface CustomTypes {
Text: {
placeholder: string
}
Range: {
placeholder?: string
}
}
}

View File

@@ -12,6 +12,7 @@ import DOMText = globalThis.Text
import DOMRange = globalThis.Range
import DOMSelection = globalThis.Selection
import DOMStaticRange = globalThis.StaticRange
export {
DOMNode,
DOMComment,