2016-06-24 10:22:48 -07:00
|
|
|
|
|
|
|
import React from 'react'
|
|
|
|
import ReactDOM from 'react-dom'
|
2017-05-04 16:48:42 -07:00
|
|
|
import { HashRouter, NavLink, Route, Redirect, Switch } from 'react-router-dom'
|
2016-06-24 10:22:48 -07:00
|
|
|
|
2017-03-28 12:55:48 -04:00
|
|
|
import CheckLists from './check-lists'
|
2016-07-06 14:05:35 -07:00
|
|
|
import CodeHighlighting from './code-highlighting'
|
2016-07-28 15:38:17 -07:00
|
|
|
import Embeds from './embeds'
|
2016-09-23 18:46:24 +02:00
|
|
|
import Emojis from './emojis'
|
2017-07-31 21:19:45 -04:00
|
|
|
import ForcedLayout from './forced-layout'
|
2017-10-30 11:59:23 -05:00
|
|
|
import History from './history'
|
2016-06-28 15:47:29 -07:00
|
|
|
import HoveringMenu from './hovering-menu'
|
2017-10-13 15:48:08 -07:00
|
|
|
import HugeDocument from './huge-document'
|
2016-06-28 18:26:56 -07:00
|
|
|
import Images from './images'
|
2016-06-24 10:22:48 -07:00
|
|
|
import Links from './links'
|
2017-03-30 14:12:56 -04:00
|
|
|
import MarkdownPreview from './markdown-preview'
|
|
|
|
import MarkdownShortcuts from './markdown-shortcuts'
|
2016-06-29 10:43:22 -07:00
|
|
|
import PasteHtml from './paste-html'
|
2016-06-24 10:22:48 -07:00
|
|
|
import PlainText from './plain-text'
|
2016-07-26 12:15:21 -07:00
|
|
|
import Plugins from './plugins'
|
2016-08-05 12:40:54 -07:00
|
|
|
import RTL from './rtl'
|
2016-07-17 15:57:27 -07:00
|
|
|
import ReadOnly from './read-only'
|
2016-06-24 10:22:48 -07:00
|
|
|
import RichText from './rich-text'
|
2017-10-13 12:04:22 -07:00
|
|
|
import SearchHighlighting from './search-highlighting'
|
2017-10-13 16:24:00 -07:00
|
|
|
import SyncingOperations from './syncing-operations'
|
2016-06-24 10:22:48 -07:00
|
|
|
import Tables from './tables'
|
2016-08-05 12:40:54 -07:00
|
|
|
|
2017-05-04 16:48:42 -07:00
|
|
|
/**
|
|
|
|
* Examples.
|
|
|
|
*
|
|
|
|
* @type {Array}
|
|
|
|
*/
|
|
|
|
|
|
|
|
const EXAMPLES = [
|
|
|
|
['Rich Text', RichText, '/rich-text'],
|
|
|
|
['Plain Text', PlainText, '/plain-text'],
|
|
|
|
['Hovering Menu', HoveringMenu, '/hovering-menu'],
|
|
|
|
['Links', Links, '/links'],
|
|
|
|
['Images', Images, '/images'],
|
|
|
|
['Embeds', Embeds, '/embeds'],
|
|
|
|
['Emojis', Emojis, '/emojis'],
|
|
|
|
['Markdown Preview', MarkdownPreview, '/markdown-preview'],
|
|
|
|
['Markdown Shortcuts', MarkdownShortcuts, '/markdown-shortcuts'],
|
|
|
|
['Check Lists', CheckLists, '/check-lists'],
|
|
|
|
['Code Highlighting', CodeHighlighting, '/code-highlighting'],
|
|
|
|
['Tables', Tables, '/tables'],
|
|
|
|
['Paste HTML', PasteHtml, '/paste-html'],
|
2017-10-13 12:04:22 -07:00
|
|
|
['Search Highlighting', SearchHighlighting, '/search-highlighting'],
|
2017-10-13 16:24:00 -07:00
|
|
|
['Syncing Operations', SyncingOperations, '/syncing-operations'],
|
2017-05-04 16:48:42 -07:00
|
|
|
['Read-only', ReadOnly, '/read-only'],
|
|
|
|
['RTL', RTL, '/rtl'],
|
|
|
|
['Plugins', Plugins, '/plugins'],
|
2017-07-31 21:19:45 -04:00
|
|
|
['Forced Layout', ForcedLayout, '/forced-layout'],
|
2017-10-13 16:24:00 -07:00
|
|
|
['Huge Document', HugeDocument, '/huge-document'],
|
2017-10-30 11:59:23 -05:00
|
|
|
['History', History, '/history'],
|
2017-05-04 16:48:42 -07:00
|
|
|
]
|
2016-07-12 22:26:57 -07:00
|
|
|
|
2016-06-24 10:22:48 -07:00
|
|
|
/**
|
2017-05-04 16:48:42 -07:00
|
|
|
* App.
|
2016-06-24 10:22:48 -07:00
|
|
|
*
|
2017-05-04 16:48:42 -07:00
|
|
|
* @type {Component}
|
2016-06-24 10:22:48 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
class App extends React.Component {
|
|
|
|
|
2017-10-13 18:34:35 -07:00
|
|
|
state = {
|
|
|
|
error: null,
|
|
|
|
info: null,
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidCatch(error, info) {
|
|
|
|
this.setState({ error, info })
|
|
|
|
}
|
|
|
|
|
2016-06-24 10:22:48 -07:00
|
|
|
render() {
|
|
|
|
return (
|
2016-07-06 14:05:35 -07:00
|
|
|
<div className="app">
|
2017-05-04 16:48:42 -07:00
|
|
|
<div className="nav">
|
|
|
|
<span className="nav-title">Slate Examples</span>
|
|
|
|
<div className="nav-links">
|
|
|
|
<a className="nav-link" href="https://github.com/ianstormtaylor/slate">GitHub</a>
|
|
|
|
<a className="nav-link" href="https://docs.slatejs.org/">Docs</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="tabs">
|
2017-10-13 15:48:08 -07:00
|
|
|
{EXAMPLES.map(([ name, Component, path ]) => (
|
|
|
|
<NavLink key={path} to={path} className="tab"activeClassName="active">
|
|
|
|
{name}
|
|
|
|
</NavLink>
|
2017-05-04 16:48:42 -07:00
|
|
|
))}
|
|
|
|
</div>
|
2017-10-13 18:34:35 -07:00
|
|
|
{this.state.error
|
|
|
|
? this.renderError()
|
|
|
|
: this.renderExample()}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderExample() {
|
|
|
|
return (
|
|
|
|
<div className="example">
|
|
|
|
<Switch>
|
|
|
|
{EXAMPLES.map(([ name, Component, path ]) => (
|
|
|
|
<Route key={path} path={path} component={Component} />
|
|
|
|
))}
|
|
|
|
<Redirect from="/" to="/rich-text" />
|
|
|
|
</Switch>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderError() {
|
|
|
|
return (
|
|
|
|
<div className="error">
|
|
|
|
<p>
|
|
|
|
An error was thrown by one of the example's React components!
|
|
|
|
</p>
|
|
|
|
<pre className="info">
|
|
|
|
<code>
|
|
|
|
{this.state.error.stack}
|
|
|
|
{'\n'}
|
|
|
|
{this.state.info.componentStack}
|
|
|
|
</code>
|
|
|
|
</pre>
|
2016-06-24 10:22:48 -07:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Router.
|
|
|
|
*
|
|
|
|
* @type {Element} router
|
|
|
|
*/
|
|
|
|
|
2017-05-04 16:48:42 -07:00
|
|
|
const router = <HashRouter><App /></HashRouter>
|
|
|
|
|
2016-06-24 10:22:48 -07:00
|
|
|
/**
|
|
|
|
* Mount the router.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const root = document.body.querySelector('main')
|
|
|
|
ReactDOM.render(router, root)
|