Skip to content

Commit

Permalink
docs: convert remaining examples and update next
Browse files Browse the repository at this point in the history
  • Loading branch information
wendellhu committed Jul 6, 2020
1 parent 0bea53c commit 354682e
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
useReadOnly,
ReactEditor,
} from 'slate-react'
import { Editor, Transforms, Range, Point, createEditor } from 'slate'
import { Node, Editor, Transforms, Range, Point, createEditor } from 'slate'
import { css } from 'emotion'
import { withHistory } from 'slate-history'

const CheckListsExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const renderElement = useCallback(props => <Element {...props} />, [])
const editor = useMemo(
() => withChecklists(withHistory(withReact(createEditor()))),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useMemo } from 'react'
import { Transforms, createEditor } from 'slate'
import { Transforms, createEditor, Node } from 'slate'
import { Slate, Editable, useEditor, withReact } from 'slate-react'
import { withHistory } from 'slate-history'
import { css } from 'emotion'
Expand All @@ -8,7 +8,7 @@ import RichTextEditor from './richtext'
import { Button, Icon, Toolbar } from '../components'

const EditableVoidsExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const editor = useMemo(
() => withEditableVoids(withHistory(withReact(createEditor()))),
[]
Expand Down
4 changes: 2 additions & 2 deletions site/examples/embeds.js → site/examples/embeds.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useMemo } from 'react'
import { Transforms, createEditor } from 'slate'
import { Transforms, createEditor, Node } from 'slate'
import {
Slate,
Editable,
Expand All @@ -11,7 +11,7 @@ import {
} from 'slate-react'

const EmbedsExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const editor = useMemo(() => withEmbeds(withReact(createEditor())), [])
return (
<Slate editor={editor} value={value} onChange={value => setValue(value)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const withLayout = editor => {
}

const ForcedLayoutExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const renderElement = useCallback(props => <Element {...props} />, [])
const editor = useMemo(
() => withLayout(withHistory(withReact(createEditor()))),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useState, useMemo, useRef, useEffect } from 'react'
import { Slate, Editable, ReactEditor, withReact, useSlate } from 'slate-react'
import { Editor, Transforms, Text, createEditor } from 'slate'
import { Editor, Transforms, Text, createEditor, Node } from 'slate'
import { css } from 'emotion'
import { withHistory } from 'slate-history'

import { Button, Icon, Menu, Portal } from '../components'
import { Range } from 'slate'

const HoveringMenuExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const editor = useMemo(() => withHistory(withReact(createEditor())), [])

return (
Expand All @@ -17,7 +17,7 @@ const HoveringMenuExample = () => {
<Editable
renderLeaf={props => <Leaf {...props} />}
placeholder="Enter some text..."
onDOMBeforeInput={event => {
onDOMBeforeInput={(event: InputEvent) => {
event.preventDefault()
switch (event.inputType) {
case 'formatBold':
Expand Down Expand Up @@ -67,7 +67,7 @@ const Leaf = ({ attributes, children, leaf }) => {
}

const HoveringToolbar = () => {
const ref = useRef()
const ref = useRef<HTMLDivElement | null>()
const editor = useSlate()

useEffect(() => {
Expand All @@ -91,7 +91,7 @@ const HoveringToolbar = () => {
const domSelection = window.getSelection()
const domRange = domSelection.getRangeAt(0)
const rect = domRange.getBoundingClientRect()
el.style.opacity = 1
el.style.opacity = '1'
el.style.top = `${rect.top + window.pageYOffset - el.offsetHeight}px`
el.style.left = `${rect.left +
window.pageXOffset -
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions site/examples/images.js → site/examples/images.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useMemo } from 'react'
import imageExtensions from 'image-extensions'
import isUrl from 'is-url'
import { Transforms, createEditor } from 'slate'
import { Node, Transforms, createEditor } from 'slate'
import {
Slate,
Editable,
Expand All @@ -16,7 +16,7 @@ import { css } from 'emotion'
import { Button, Icon, Toolbar } from '../components'

const ImagesExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const editor = useMemo(
() => withImages(withHistory(withReact(createEditor()))),
[]
Expand Down
4 changes: 2 additions & 2 deletions site/examples/links.js → site/examples/links.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useState, useMemo } from 'react'
import isUrl from 'is-url'
import { Slate, Editable, withReact, useSlate } from 'slate-react'
import { Transforms, Editor, Range, createEditor } from 'slate'
import { Node, Transforms, Editor, Range, createEditor } from 'slate'
import { withHistory } from 'slate-history'

import { Button, Icon, Toolbar } from '../components'

const LinkExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const editor = useMemo(
() => withLinks(withHistory(withReact(createEditor()))),
[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Prism from 'prismjs'
import React, { useState, useCallback, useMemo } from 'react'
import { Slate, Editable, withReact } from 'slate-react'
import { Text, createEditor } from 'slate'
import { Node, Text, createEditor } from 'slate'
import { withHistory } from 'slate-history'
import { css } from 'emotion'

// eslint-disable-next-line
;Prism.languages.markdown=Prism.languages.extend("markup",{}),Prism.languages.insertBefore("markdown","prolog",{blockquote:{pattern:/^>(?:[\t ]*>)*/m,alias:"punctuation"},code:[{pattern:/^(?: {4}|\t).+/m,alias:"keyword"},{pattern:/``.+?``|`[^`\n]+`/,alias:"keyword"}],title:[{pattern:/\w+.*(?:\r?\n|\r)(?:==+|--+)/,alias:"important",inside:{punctuation:/==+$|--+$/}},{pattern:/(^\s*)#+.+/m,lookbehind:!0,alias:"important",inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/(^\s*)([*-])([\t ]*\2){2,}(?=\s*$)/m,lookbehind:!0,alias:"punctuation"},list:{pattern:/(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,lookbehind:!0,alias:"punctuation"},"url-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,punctuation:/^[\[\]!:]|[<>]/},alias:"url"},bold:{pattern:/(^|[^\\])(\*\*|__)(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,lookbehind:!0,inside:{punctuation:/^\*\*|^__|\*\*$|__$/}},italic:{pattern:/(^|[^\\])([*_])(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,lookbehind:!0,inside:{punctuation:/^[*_]|[*_]$/}},url:{pattern:/!?\[[^\]]+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)| ?\[[^\]\n]*\])/,inside:{variable:{pattern:/(!?\[)[^\]]+(?=\]$)/,lookbehind:!0},string:{pattern:/"(?:\\.|[^"\\])*"(?=\)$)/}}}}),Prism.languages.markdown.bold.inside.url=Prism.util.clone(Prism.languages.markdown.url),Prism.languages.markdown.italic.inside.url=Prism.util.clone(Prism.languages.markdown.url),Prism.languages.markdown.bold.inside.italic=Prism.util.clone(Prism.languages.markdown.italic),Prism.languages.markdown.italic.inside.bold=Prism.util.clone(Prism.languages.markdown.bold); // prettier-ignore

const MarkdownPreviewExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const renderLeaf = useCallback(props => <Leaf {...props} />, [])
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
const decorate = useCallback(([node, path]) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useCallback, useMemo } from 'react'
import { Slate, Editable, withReact } from 'slate-react'
import { Editor, Transforms, Range, Point, createEditor } from 'slate'
import { Node, Editor, Transforms, Range, Point, createEditor } from 'slate'
import { withHistory } from 'slate-history'

const SHORTCUTS = {
Expand All @@ -17,7 +17,7 @@ const SHORTCUTS = {
}

const MarkdownShortcutsExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const renderElement = useCallback(props => <Element {...props} />, [])
const editor = useMemo(
() => withShortcuts(withReact(withHistory(createEditor()))),
Expand Down
8 changes: 4 additions & 4 deletions site/examples/mentions.js → site/examples/mentions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo, useCallback, useRef, useEffect, useState } from 'react'
import { Editor, Transforms, Range, createEditor } from 'slate'
import { Node, Editor, Transforms, Range, createEditor } from 'slate'
import { withHistory } from 'slate-history'
import {
Slate,
Expand All @@ -13,9 +13,9 @@ import {
import { Portal } from '../components'

const MentionExample = () => {
const ref = useRef()
const [value, setValue] = useState(initialValue)
const [target, setTarget] = useState()
const ref = useRef<HTMLDivElement | null>()
const [value, setValue] = useState<Node[]>(initialValue)
const [target, setTarget] = useState<Range | undefined>()
const [index, setIndex] = useState(0)
const [search, setSearch] = useState('')
const renderElement = useCallback(props => <Element {...props} />, [])
Expand Down
4 changes: 2 additions & 2 deletions site/examples/paste-html.js → site/examples/paste-html.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useCallback, useMemo } from 'react'
import { jsx } from 'slate-hyperscript'
import { Transforms, createEditor } from 'slate'
import { Node, Transforms, createEditor } from 'slate'
import { withHistory } from 'slate-history'
import { css } from 'emotion'
import {
Expand Down Expand Up @@ -80,7 +80,7 @@ export const deserialize = el => {
}

const PasteHtmlExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const renderElement = useCallback(props => <Element {...props} />, [])
const renderLeaf = useCallback(props => <Leaf {...props} />, [])
const editor = useMemo(
Expand Down
4 changes: 2 additions & 2 deletions site/examples/plaintext.js → site/examples/plaintext.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState, useMemo } from 'react'
import { createEditor } from 'slate'
import { Node, createEditor } from 'slate'
import { Slate, Editable, withReact } from 'slate-react'
import { withHistory } from 'slate-history'

const PlainTextExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
return (
<Slate editor={editor} value={value} onChange={value => setValue(value)}>
Expand Down
4 changes: 2 additions & 2 deletions site/examples/read-only.js → site/examples/read-only.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useState, useMemo } from 'react'
import { createEditor } from 'slate'
import { createEditor, Node } from 'slate'
import { Slate, Editable, withReact } from 'slate-react'

const ReadOnlyExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const editor = useMemo(() => withReact(createEditor()), [])
return (
<Slate editor={editor} value={value} onChange={value => setValue(value)}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useState, useCallback, useMemo } from 'react'
import { Slate, Editable, withReact } from 'slate-react'
import { Text, createEditor } from 'slate'
import { Text, Node, createEditor } from 'slate'
import { css } from 'emotion'
import { withHistory } from 'slate-history'

import { Icon, Toolbar } from '../components'

const SearchHighlightingExample = () => {
const [value, setValue] = useState(initialValue)
const [search, setSearch] = useState()
const [value, setValue] = useState<Node[]>(initialValue)
const [search, setSearch] = useState<string | undefined>()
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
const decorate = useCallback(
([node, path]) => {
Expand Down
4 changes: 2 additions & 2 deletions site/examples/tables.js → site/examples/tables.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState, useCallback, useMemo } from 'react'
import { Slate, Editable, withReact } from 'slate-react'
import { Editor, Range, Point, createEditor } from 'slate'
import { Editor, Range, Point, Node, createEditor } from 'slate'
import { withHistory } from 'slate-history'

const TablesExample = () => {
const [value, setValue] = useState(initialValue)
const [value, setValue] = useState<Node[]>(initialValue)
const renderElement = useCallback(props => <Element {...props} />, [])
const renderLeaf = useCallback(props => <Leaf {...props} />, [])
const editor = useMemo(
Expand Down
3 changes: 1 addition & 2 deletions site/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ module.exports = {
continue
}

let example = file.replace('.js', '')
example = file.replace('.tsx', '')
const example = file.replace('.tsx', '')
pages[`/examples/${example}`] = { page: '/examples/[example]', example }
}

Expand Down

0 comments on commit 354682e

Please sign in to comment.