import React, { useState, PropsWithChildren, Ref, ErrorInfo } from 'react' import { cx, css } from '@emotion/css' import Head from 'next/head' import Link from 'next/link' import dynamic from 'next/dynamic' import { ErrorBoundary } from 'react-error-boundary' import { Icon } from '../../examples/ts/components/index' import AndroidTests from '../../examples/ts/android-tests' import CheckLists from '../../examples/ts/check-lists' import CodeHighlighting from '../../examples/ts/code-highlighting' import EditableVoids from '../../examples/ts/editable-voids' import Embeds from '../../examples/ts/embeds' import ForcedLayout from '../../examples/ts/forced-layout' import HoveringToolbar from '../../examples/ts/hovering-toolbar' import HugeDocument from '../../examples/ts/huge-document' import Images from '../../examples/ts/images' import Inlines from '../../examples/ts/inlines' import MarkdownPreview from '../../examples/ts/markdown-preview' import MarkdownShortcuts from '../../examples/ts/markdown-shortcuts' import Mentions from '../../examples/ts/mentions' import PasteHtml from '../../examples/ts/paste-html' import PlainText from '../../examples/ts/plaintext' import ReadOnly from '../../examples/ts/read-only' import RichText from '../../examples/ts/richtext' import SearchHighlighting from '../../examples/ts/search-highlighting' import ShadowDOM from '../../examples/ts/shadow-dom' import Styling from '../../examples/ts/styling' import Tables from '../../examples/ts/tables' import IFrames from '../../examples/ts/iframe' import CustomPlaceholder from '../../examples/ts/custom-placeholder' // node import { getAllExamples } from '../api' type ExampleTuple = [name: string, component: React.ComponentType, path: string] const EXAMPLES: ExampleTuple[] = [ ['Android Tests', AndroidTests, 'android-tests'], ['Checklists', CheckLists, 'check-lists'], ['Code Highlighting', CodeHighlighting, 'code-highlighting'], ['Custom Placeholder', CustomPlaceholder, 'custom-placeholder'], ['Editable Voids', EditableVoids, 'editable-voids'], ['Embeds', Embeds, 'embeds'], ['Forced Layout', ForcedLayout, 'forced-layout'], ['Hovering Toolbar', HoveringToolbar, 'hovering-toolbar'], ['Huge Document', HugeDocument, 'huge-document'], ['Images', Images, 'images'], ['Inlines', Inlines, 'inlines'], ['Markdown Preview', MarkdownPreview, 'markdown-preview'], ['Markdown Shortcuts', MarkdownShortcuts, 'markdown-shortcuts'], ['Mentions', Mentions, 'mentions'], ['Paste HTML', PasteHtml, 'paste-html'], ['Plain Text', PlainText, 'plaintext'], ['Read-only', ReadOnly, 'read-only'], ['Rendering in iframes', IFrames, 'iframe'], ['Rich Text', RichText, 'richtext'], ['Search Highlighting', SearchHighlighting, 'search-highlighting'], ['Shadow DOM', ShadowDOM, 'shadow-dom'], ['Styling', Styling, 'styling'], ['Tables', Tables, 'tables'], ] const HIDDEN_EXAMPLES = ['android-tests'] const NON_HIDDEN_EXAMPLES = EXAMPLES.filter( ([, , path]) => !HIDDEN_EXAMPLES.includes(path) ) const Header = (props: React.HTMLAttributes) => (
) const Title = (props: React.HTMLAttributes) => ( ) const LinkList = (props: React.HTMLAttributes) => (
) const A = (props: React.AnchorHTMLAttributes) => ( ) const Pill = (props: React.HTMLAttributes) => ( ) const TabList = ({ isVisible, ...props }: React.HTMLAttributes & { isVisible?: boolean }) => (
) const TabListUnderlay = ({ isVisible, ...props }: React.HTMLAttributes & { isVisible?: boolean }) => (
) const TabButton = (props: React.HTMLAttributes) => ( ) const Tab = React.forwardRef( ( { active, href, ...props }: PropsWithChildren<{ active: boolean href: string [key: string]: unknown }>, ref: Ref ) => ( ) ) const Wrapper = ({ className, ...props }: React.HTMLAttributes) => (
) const ExampleHeader = (props: React.HTMLAttributes) => (
) const ExampleTitle = (props: React.HTMLAttributes) => ( ) const ExampleContent = (props: React.HTMLAttributes) => ( ) const Warning = (props: React.HTMLAttributes) => ( pre { background: #fbf1bd; white-space: pre; overflow-x: scroll; margin-bottom: 0; } `} /> ) const ExamplePage = ({ example }: { example: string }) => { const [error, setError] = useState(undefined) const [stacktrace, setStacktrace] = useState(undefined) const [showTabs, setShowTabs] = useState(false) const EXAMPLE = EXAMPLES.find(e => e[2] === example) const [name, Component, path] = EXAMPLE! return ( { setError(error) setStacktrace(stacktrace) }} fallbackRender={({ error, resetErrorBoundary }) => (

An error was thrown by one of the example's React components!

            
              {error.stack}
              {'\n'}
              {stacktrace}
            
          
)} >
Slate Examples
Slate Examples GitHub Docs
{ e.stopPropagation() setShowTabs(!showTabs) }} > menu {name} JS Code TS Code {NON_HIDDEN_EXAMPLES.map(([n, , p]) => ( setShowTabs(false)}>{n} ))} {error ? (

An error was thrown by one of the example's React components!

              
                <>
                  {error.stack}
                  {'\n'}
                  {stacktrace}
                
              
            
) : ( )} setShowTabs(false)} />
) } // Disable SSR because it results in a double rendering which makes debugging // examples more challenging. No idea how any of this works. const NoSsrExamplePage = dynamic(() => Promise.resolve(ExamplePage), { ssr: false, }) export async function getStaticPaths() { const paths = getAllExamples() return { paths: paths.map(path => ({ params: { example: path, }, })), fallback: false, } } export async function getStaticProps({ params, }: { params: { example: string } }) { return { props: { example: params.example, }, } } export default NoSsrExamplePage