1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-24 01:02:31 +01:00

Use children (#4152)

* useChildren

* path fix

* Revert .github files

* Revert .github files to earlier version

Co-authored-by: Radim Malota <radim.malota@suitu.cz>
This commit is contained in:
Sunny Hirai 2021-03-30 21:52:46 -07:00 committed by GitHub
parent 7b6c986661
commit 2ca10c7f95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 27 deletions

View File

@ -13,7 +13,7 @@ import { HistoryEditor } from 'slate-history'
import throttle from 'lodash/throttle'
import scrollIntoView from 'scroll-into-view-if-needed'
import Children from './children'
import useChildren from '../hooks/use-children'
import Hotkeys from '../utils/hotkeys'
import {
IS_FIREFOX,
@ -986,14 +986,14 @@ export const Editable = (props: EditableProps) => {
[readOnly, attributes.onPaste]
)}
>
<Children
decorate={decorate}
decorations={decorations}
node={editor}
renderElement={renderElement}
renderLeaf={renderLeaf}
selection={editor.selection}
/>
{useChildren({
decorate,
decorations,
node: editor,
renderElement,
renderLeaf,
selection: editor.selection,
})}
</Component>
</ReadOnlyContext.Provider>
)

View File

@ -3,7 +3,7 @@ import getDirection from 'direction'
import { Editor, Node, Range, NodeEntry, Element as SlateElement } from 'slate'
import Text from './text'
import Children from './children'
import useChildren from '../hooks/use-children'
import { ReactEditor, useSlateStatic, useReadOnly } from '..'
import { SelectedContext } from '../hooks/use-selected'
import { useIsomorphicLayoutEffect } from '../hooks/use-isomorphic-layout-effect'
@ -42,16 +42,14 @@ const Element = (props: {
const isInline = editor.isInline(element)
const key = ReactEditor.findKey(editor, element)
let children: JSX.Element | null = (
<Children
decorate={decorate}
decorations={decorations}
node={element}
renderElement={renderElement}
renderLeaf={renderLeaf}
selection={selection}
/>
)
let children: JSX.Element | null = useChildren({
decorate,
decorations,
node: element,
renderElement,
renderLeaf,
selection,
})
// Attributes that the developer must mix into the element in their
// custom node renderer component.

View File

@ -1,18 +1,18 @@
import React from 'react'
import { Editor, Range, Element, NodeEntry, Ancestor, Descendant } from 'slate'
import ElementComponent from './element'
import TextComponent from './text'
import ElementComponent from '../components/element'
import TextComponent from '../components/text'
import { ReactEditor } from '..'
import { useSlateStatic } from '../hooks/use-slate-static'
import { useSlateStatic } from './use-slate-static'
import { NODE_TO_INDEX, NODE_TO_PARENT } from '../utils/weak-maps'
import { RenderElementProps, RenderLeafProps } from './editable'
import { RenderElementProps, RenderLeafProps } from '../components/editable'
/**
* Children.
*/
const Children = (props: {
const useChildren = (props: {
decorate: (entry: NodeEntry) => Range[]
decorations: Range[]
node: Ancestor
@ -81,7 +81,7 @@ const Children = (props: {
NODE_TO_PARENT.set(n, node)
}
return <React.Fragment>{children}</React.Fragment>
return children
}
export default Children
export default useChildren