import React, { useCallback } from 'react'
import { Node } from 'slate'
import {
Slate,
ReactEditor,
Editable,
RenderLeafProps,
useSlate
} from 'slate-react'
import { ClientFrame, IconButton, Icon } from './Components'
import Caret from './Caret'
import { isBlockActive, toggleBlock } from './plugins/block'
import { isMarkActive, toggleMark } from './plugins/mark'
import { isLinkActive, insertLink, unwrapLink } from './plugins/link'
export interface EditorFrame {
editor: ReactEditor
value: Node[]
decorate: any
onChange: (value: Node[]) => void
}
const renderElement = (props: any) =>
const EditorFrame: React.FC = ({
editor,
value,
decorate,
onChange
}) => {
const renderLeaf = useCallback((props: any) => , [
decorate
])
return (
)
}
export default EditorFrame
const Element: React.FC = ({ attributes, children, element }) => {
switch (element.type) {
case 'link':
return (
{children}
)
case 'block-quote':
return {children}
case 'bulleted-list':
return
case 'heading-one':
return {children}
case 'heading-two':
return {children}
case 'list-item':
return {children}
case 'numbered-list':
return {children}
default:
return {children}
}
}
const Leaf: React.FC = ({ attributes, children, leaf }) => {
if (leaf.bold) {
children = {children}
}
if (leaf.code) {
children = {children}
}
if (leaf.italic) {
children = {children}
}
if (leaf.underline) {
children = {children}
}
return (
{leaf.isCaret ? : null}
{children}
)
}
const BlockButton: React.FC = ({ format, icon }) => {
const editor = useSlate()
return (
{
event.preventDefault()
toggleBlock(editor, format)
}}
>
{icon}
)
}
const MarkButton: React.FC = ({ format, icon }) => {
const editor = useSlate()
return (
{
event.preventDefault()
toggleMark(editor, format)
}}
>
{icon}
)
}
const LinkButton = () => {
const editor = useSlate()
const isActive = isLinkActive(editor)
return (
{
event.preventDefault()
if (isActive) return unwrapLink(editor)
const url = window.prompt('Enter the URL of the link:')
url && insertLink(editor, url)
}}
>
link
)
}