1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-23 15:32:59 +02: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
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 throttle from 'lodash/throttle'
import scrollIntoView from 'scroll-into-view-if-needed' import scrollIntoView from 'scroll-into-view-if-needed'
import Children from './children' import useChildren from '../hooks/use-children'
import Hotkeys from '../utils/hotkeys' import Hotkeys from '../utils/hotkeys'
import { import {
IS_FIREFOX, IS_FIREFOX,
@@ -986,14 +986,14 @@ export const Editable = (props: EditableProps) => {
[readOnly, attributes.onPaste] [readOnly, attributes.onPaste]
)} )}
> >
<Children {useChildren({
decorate={decorate} decorate,
decorations={decorations} decorations,
node={editor} node: editor,
renderElement={renderElement} renderElement,
renderLeaf={renderLeaf} renderLeaf,
selection={editor.selection} selection: editor.selection,
/> })}
</Component> </Component>
</ReadOnlyContext.Provider> </ReadOnlyContext.Provider>
) )

View File

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

View File

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