slate-react
- Version 0.120.0
- Published
- 2.77 MB
- 6 dependencies
- MIT license
Install
npm i slate-reactyarn add slate-reactpnpm add slate-reactOverview
Tools for building completely customizable richtext editors with React.
Index
Variables
Functions
Interfaces
Type Aliases
Variables
variable Editable
const Editable: React.ForwardRefExoticComponent<any>;Editable.
variable ReactEditor
const ReactEditor: ReactEditorInterface;Functions
function DefaultElement
DefaultElement: (props: RenderElementProps) => JSX.Element;The default element renderer.
function DefaultLeaf
DefaultLeaf: (props: RenderLeafProps) => JSX.Element;function DefaultPlaceholder
DefaultPlaceholder: ({ attributes, children,}: RenderPlaceholderProps) => JSX.Element;The default placeholder element
function defaultScrollSelectionIntoView
defaultScrollSelectionIntoView: ( editor: ReactEditor, domRange: DOMRange) => void;A default implement to scroll dom range into view.
function DefaultText
DefaultText: (props: RenderTextProps) => React.JSX.Element;function Slate
Slate: (props: { editor: ReactEditor; initialValue: Descendant[]; children: React.ReactNode; onChange?: (value: Descendant[]) => void; onSelectionChange?: (selection: Selection) => void; onValueChange?: (value: Descendant[]) => void;}) => React.JSX.Element;A wrapper around the provider to handle
onChangeevents, because the editor is a mutable singleton so it won't ever register as "changed" otherwise.
function useComposing
useComposing: () => boolean;Get the current
composingstate of the editor.
function useEditor
useEditor: () => import('..').ReactEditor;Get the current editor object from the React context.
Deprecated
Use useSlateStatic instead.
function useElement
useElement: () => Element;Get the current element.
function useElementIf
useElementIf: () => import('slate').BaseElement | null;Get the current element, or return null if not inside
renderElement.
function useFocused
useFocused: () => boolean;Get the current
focusedstate of the editor.
function useReadOnly
useReadOnly: () => boolean;Get the current
readOnlystate of the editor.
function useSelected
useSelected: () => boolean;Get the current
selectedstate of an element.
function useSlate
useSlate: () => Editor;Get the current editor object and re-render whenever it changes.
function useSlateSelection
useSlateSelection: () => BaseSelection;Get the current slate selection. Only triggers a rerender when the selection actually changes
function useSlateSelector
useSlateSelector: <T>( selector: (editor: Editor) => T, equalityFn?: (a: T | null, b: T) => boolean, { deferred }?: SlateSelectorOptions) => T;Use redux style selectors to prevent re-rendering on every keystroke.
Bear in mind re-rendering can only prevented if the returned value is a value type or for reference types (e.g. objects and arrays) add a custom equality function.
If
selectoris memoized usinguseCallback, then it will only be called when it or the editor state changes. Otherwise,selectorwill be called every time the component renders.Example 1
const isSelectionActive = useSlateSelector(editor => Boolean(editor.selection))
function useSlateStatic
useSlateStatic: () => Editor;Get the current editor object from the React context.
function useSlateWithV
useSlateWithV: () => { editor: Editor; v: number };Get the current editor object and its version, which increments on every change.
Deprecated
The
vcounter is no longer used except for this hook, and may be removed in a future version.
function withReact
withReact: <T extends BaseEditor>( editor: T, clipboardFormatKey?: string) => T & ReactEditor;withReactadds React and DOM specific behaviors to the editor.If you are using TypeScript, you must extend Slate's CustomTypes to use this plugin.
See https://docs.slatejs.org/concepts/11-typescript to learn how.
Interfaces
interface ReactEditor
interface ReactEditor extends DOMEditor {}A React and DOM-specific version of the
Editorinterface.
property getChunkSize
getChunkSize: (node: Ancestor) => number | null;Determines the chunk size used by the children chunking optimization. If null is returned (which is the default), the chunking optimization is disabled.
interface RenderChunkProps
interface RenderChunkProps {}RenderChunkPropsare passed to therenderChunkhandler
property attributes
attributes: { 'data-slate-chunk': true;};property children
children: any;property highest
highest: boolean;property lowest
lowest: boolean;interface RenderElementProps
interface RenderElementProps {}RenderElementPropsare passed to therenderElementhandler.
property attributes
attributes: { 'data-slate-node': 'element'; 'data-slate-inline'?: true; 'data-slate-void'?: true; dir?: 'rtl'; ref: any;};property children
children: any;property element
element: Element;interface RenderLeafProps
interface RenderLeafProps {}RenderLeafPropsare passed to therenderLeafhandler.
property attributes
attributes: { 'data-slate-leaf': true;};property children
children: any;property leaf
leaf: Text;The leaf node with any applied decorations. If no decorations are applied, it will be identical to the
textproperty.
property leafPosition
leafPosition?: LeafPosition;The position of the leaf within the Text node, only present when the text node is split by decorations.
property text
text: Text;Type Aliases
type RenderPlaceholderProps
type RenderPlaceholderProps = { children: any; attributes: { 'data-slate-placeholder': boolean; dir?: 'rtl'; contentEditable: boolean; ref: React.RefCallback<any>; style: React.CSSProperties; };};The props that get passed to renderPlaceholder
Package Files (18)
- dist/components/editable.d.ts
- dist/components/element.d.ts
- dist/components/leaf.d.ts
- dist/components/slate.d.ts
- dist/components/text.d.ts
- dist/hooks/use-composing.d.ts
- dist/hooks/use-editor.d.ts
- dist/hooks/use-element.d.ts
- dist/hooks/use-focused.d.ts
- dist/hooks/use-read-only.d.ts
- dist/hooks/use-selected.d.ts
- dist/hooks/use-slate-selection.d.ts
- dist/hooks/use-slate-selector.d.ts
- dist/hooks/use-slate-static.d.ts
- dist/hooks/use-slate.d.ts
- dist/index.d.ts
- dist/plugin/react-editor.d.ts
- dist/plugin/with-react.d.ts
Dependencies (6)
Dev Dependencies (16)
Peer Dependencies (4)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/slate-react.
- Markdown[](https://www.jsdocs.io/package/slate-react)
- HTML<a href="https://www.jsdocs.io/package/slate-react"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3818 ms. - Missing or incorrect documentation? Open an issue for this package.
