diff --git a/.travis.yml b/.travis.yml index 1b82aef369..0ace36dd56 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,7 @@ script: git config --global user.name "Travis CI" git config --global user.email "travis@reactjs.org" echo "machine github.com login reactjs-bot password $GITHUB_TOKEN" > ~/.netrc - cd website && yarn install && GIT_USER=reactjs-bot npm run publish-gh-pages + cd website && yarn install && GIT_USER=reactjs-bot USE_SSH=true yarn deploy else # Make sure the website builds without error cd website && yarn install && yarn build diff --git a/docs/APIReference-ContentBlock.md b/docs/APIReference-ContentBlock.md index f8bacba1fb..babacbd300 100644 --- a/docs/APIReference-ContentBlock.md +++ b/docs/APIReference-ContentBlock.md @@ -74,7 +74,7 @@ supplied text.
  • -
    getCharacterList(): List
    +
    getCharacterList(): List<CharacterMetadata>
  • @@ -99,7 +99,7 @@ supplied text.
  • -
    getData(): Map
    +
    getData(): Map<any, any>
  • @@ -139,7 +139,7 @@ supplied text.
  • -
    characterList: List
    +
    characterList: List<CharacterMetadata>
  • @@ -149,7 +149,7 @@ supplied text.
  • -
    data: Map
    +
    data: Map<any, any>
  • diff --git a/docs/APIReference-ContentState.md b/docs/APIReference-ContentState.md index a7f5bf9f0f..424cdb9849 100644 --- a/docs/APIReference-ContentState.md +++ b/docs/APIReference-ContentState.md @@ -28,7 +28,7 @@ objects.
  • -
    static createFromBlockArray(blocks: Array): ContentState
    +
    static createFromBlockArray(blocks: Array<ContentBlock>): ContentState
  • diff --git a/docs/Overview.md b/docs/Overview.md index b9ddaea54e..aae4bd202e 100644 --- a/docs/Overview.md +++ b/docs/Overview.md @@ -10,7 +10,7 @@ Draft.js allows you to build any type of rich text input, whether you're only lo Draft.js was introduced at [React.js Conf](https://conf2016.reactjs.org/schedule#rich-text-editing-with-react) in February 2016. - + ## Installation diff --git a/website/.gitignore b/website/.gitignore new file mode 100644 index 0000000000..a708a66629 --- /dev/null +++ b/website/.gitignore @@ -0,0 +1,21 @@ +# Dependencies +node_modules + +# Production +build + +# Generated files +.docusaurus +.cache-loader + +# Misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +# Logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/website/README.md b/website/README.md index d9ecbeb438..55d6be628b 100644 --- a/website/README.md +++ b/website/README.md @@ -1,21 +1,33 @@ -Draft.js uses Docusaurus to maintain our documentation website. Please see the -[Docusaurus Documentation](https://docusaurus.io/) for more info. +# Draft.js website -# Run the server +This website is built using [Docusaurus 2](https://v2.docusaurus.io/), a modern static website generator. -The first time, get all the dependencies loaded via +### Installation -```bash -yarn +``` +$ yarn +``` + +### Local Development + +``` +$ yarn start ``` -in the root directory. +This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server. -Then, run the server via +### Build -```bash -npm start -Open http://localhost:3000 +``` +$ yarn build +``` + +This command generates static content into the `build` directory and can be served using any static contents hosting service. + +### Deployment + +``` +$ GIT_USER= USE_SSH=true yarn deploy ``` -Anytime you change the contents, refresh the page and it's going to be updated +If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. diff --git a/website/core/Footer.js b/website/core/Footer.js deleted file mode 100644 index 989c758d94..0000000000 --- a/website/core/Footer.js +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -const React = require('react'); - -class Footer extends React.Component { - render() { - const config = this.props.config; - const currentYear = new Date().getFullYear(); - return ( - - ); - } -} - -module.exports = Footer; diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js new file mode 100644 index 0000000000..e58139985a --- /dev/null +++ b/website/docusaurus.config.js @@ -0,0 +1,104 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +module.exports = { + title: 'Draft.js', + tagline: 'Rich Text Editor Framework for React', + url: 'https://draftjs.org', + baseUrl: '/', + organizationName: 'facebook', + projectName: 'draft-js', + favicon: 'img/draftjs-logo.ico', + presets: [ + [ + '@docusaurus/preset-classic', + { + docs: { + path: '../docs', + sidebarPath: require.resolve('./sidebars.json'), + editUrl: 'https://github.com/facebook/draft-js/edit/master/docs', + showLastUpdateAuthor: true, + showLastUpdateTime: true, + }, + theme: { + customCss: require.resolve('./src/css/custom.css'), + }, + }, + ], + ], + themeConfig: { + disableDarkMode: true, + navbar: { + title: 'Draft.js', + logo: { + alt: 'Draft.js Logo', + src: 'img/draftjs-logo.svg', + }, + links: [ + {to: 'docs/getting-started', label: 'Docs', position: 'right'}, + { + href: 'https://github.com/facebook/draft-js', + label: 'GitHub', + position: 'right', + }, + ], + }, + algolia: { + apiKey: 'ae94c9e3ee00ea8edddd484adafc37cd', + indexName: 'draft-js', + }, + googleAnalytics: { + trackingID: 'UA-44373548-19', + }, + footer: { + style: 'dark', + links: [ + { + title: 'Docs', + items: [ + { + label: 'Getting Started', + to: 'docs/getting-started', + }, + { + label: 'API Reference', + to: 'docs/api-reference-editor', + }, + ], + }, + { + title: 'Community', + items: [ + { + label: 'Stack Overflow', + href: 'https://stackoverflow.com/questions/tagged/draftjs', + }, + { + label: 'Twitter', + href: 'https://twitter.com/draft_js', + }, + ], + }, + { + title: 'More', + items: [ + { + label: 'GitHub', + href: 'https://github.com/facebook/draft-js', + }, + ], + }, + ], + logo: { + alt: 'Facebook Open Source Logo', + src: '/img/oss_logo.png', + href: 'https://opensource.facebook.com/', + }, + copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, + }, + }, +}; diff --git a/website/i18n/en.json b/website/i18n/en.json deleted file mode 100644 index 21d11eee9e..0000000000 --- a/website/i18n/en.json +++ /dev/null @@ -1,114 +0,0 @@ -{ - "_comment": "This file is auto-generated by write-translations.js", - "localized-strings": { - "next": "Next", - "previous": "Previous", - "tagline": "Rich Text Editor Framework for React", - "docs": { - "advanced-topics-block-components": { - "title": "Custom Block Components" - }, - "advanced-topics-block-styling": { - "title": "Block Styling" - }, - "advanced-topics-custom-block-render-map": { - "title": "Custom Block Rendering" - }, - "advanced-topics-decorators": { - "title": "Decorators" - }, - "advanced-topics-editorstate-race-conditions": { - "title": "EditorState Race Conditions" - }, - "advanced-topics-entities": { - "title": "Entities" - }, - "advanced-topics-inline-styles": { - "title": "Complex Inline Styles" - }, - "advanced-topics-issues-and-pitfalls": { - "title": "Issues and Pitfalls" - }, - "advanced-topics-key-bindings": { - "title": "Key Bindings" - }, - "advanced-topics-managing-focus": { - "title": "Managing Focus" - }, - "advanced-topics-nested-lists": { - "title": "Nested Lists" - }, - "advanced-topics-text-direction": { - "title": "Text Direction" - }, - "v0-10-api-migration": { - "title": "v0.10 API Migration" - }, - "api-reference-atomic-block-utils": { - "title": "AtomicBlockUtils" - }, - "api-reference-character-metadata": { - "title": "CharacterMetadata" - }, - "api-reference-composite-decorator": { - "title": "CompositeDecorator" - }, - "api-reference-content-block": { - "title": "ContentBlock" - }, - "api-reference-content-state": { - "title": "ContentState" - }, - "api-reference-data-conversion": { - "title": "Data Conversion" - }, - "api-reference-editor": { - "title": "Editor Component" - }, - "api-reference-editor-change-type": { - "title": "EditorChangeType" - }, - "api-reference-editor-state": { - "title": "EditorState" - }, - "api-reference-entity": { - "title": "Entity" - }, - "api-reference-key-binding-util": { - "title": "KeyBindingUtil" - }, - "api-reference-modifier": { - "title": "Modifier" - }, - "api-reference-rich-utils": { - "title": "RichUtils" - }, - "api-reference-selection-state": { - "title": "SelectionState" - }, - "getting-started": { - "title": "Overview" - }, - "quickstart-api-basics": { - "title": "API Basics" - }, - "quickstart-rich-styling": { - "title": "Rich Styling" - } - }, - "links": { - "Docs": "Docs", - "GitHub": "GitHub" - }, - "categories": { - "Quick Start": "Quick Start", - "Advanced Topics": "Advanced Topics", - "API Reference": "API Reference" - } - }, - "pages-strings": { - "Help Translate|recruit community translators for your project": "Help Translate", - "Edit this Doc|recruitment message asking to edit the doc source": "Edit", - "Translate this Doc|recruitment message asking to translate the docs": "Translate" - } -} diff --git a/website/package.json b/website/package.json index 89b8a62570..90d96d9989 100644 --- a/website/package.json +++ b/website/package.json @@ -1,19 +1,28 @@ { "scripts": { - "examples": "docusaurus-examples", - "start": "docusaurus-start", - "build": "docusaurus-build", - "publish-gh-pages": "docusaurus-publish", - "write-translations": "docusaurus-write-translations", - "version": "docusaurus-version", - "rename-version": "docusaurus-rename-version" - }, - "devDependencies": { - "docusaurus": "1.14.2" + "start": "docusaurus start", + "build": "docusaurus build", + "swizzle": "docusaurus swizzle", + "deploy": "docusaurus deploy" }, "dependencies": { - "babel-preset-env": "1.7.0", - "babel-preset-react": "6.24.1", - "react": "16.12.0" + "@docusaurus/core": "^2.0.0-alpha.36", + "@docusaurus/preset-classic": "^2.0.0-alpha.36", + "classnames": "^2.2.6", + "draft-js": "^0.11.2", + "react": "^16.10.2", + "react-dom": "^16.10.2" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] } } diff --git a/website/siteConfig.js b/website/siteConfig.js deleted file mode 100644 index 04b0840903..0000000000 --- a/website/siteConfig.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -const siteConfig = { - title: 'Draft.js' /* title for your website */, - tagline: 'Rich Text Editor Framework for React', - url: 'https://draftjs.org' /* your website url */, - cname: 'draftjs.org', - baseUrl: '/' /* base url for your project */, - organizationName: 'facebook', - projectName: 'draft-js', - headerLinks: [ - {doc: 'getting-started', label: 'Docs'}, - { - href: "https://github.com/facebook/draft-js", - label: "GitHub" - } - ], - headerIcon: 'img/draftjs-logo.svg', - favicon: 'img/draftjs-logo.ico', - /* colors for website */ - colors: { - primaryColor: '#3B3738', - secondaryColor: '#843131', - }, - // This copyright info is used in /core/Footer.js and blog rss/atom feeds. - copyright: - 'Copyright © ' + - new Date().getFullYear() + - ' Facebook Inc.', - highlight: { - // Highlight.js theme to use for syntax highlighting in code blocks - theme: 'atelier-forest-light', - }, - scripts: ['https://buttons.github.io/buttons.js'], - // You may provide arbitrary config keys to be used as needed by your template. - repoUrl: 'https://github.com/facebook/draft-js', - - // Google analytics tracking id - gaTrackingId: 'UA-44373548-19', - - // Show page's Table of Contents - onPageNav: 'separate', - - // No .html in the path. - cleanUrl: true, - - // Algolia search. - algolia: { - apiKey: 'ae94c9e3ee00ea8edddd484adafc37cd', - indexName: 'draft-js', - }, -}; - -module.exports = siteConfig; diff --git a/website/static/css/Draft.css b/website/src/components/DraftEditorExample/css/draft.css similarity index 99% rename from website/static/css/Draft.css rename to website/src/components/DraftEditorExample/css/draft.css index aaff2701d1..0cf5703bb7 100644 --- a/website/static/css/Draft.css +++ b/website/src/components/DraftEditorExample/css/draft.css @@ -6,4 +6,5 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -.DraftEditor-editorContainer,.DraftEditor-root,.public-DraftEditor-content{height:inherit;text-align:initial}.public-DraftEditor-content[contenteditable=true]{-webkit-user-modify:read-write-plaintext-only}.DraftEditor-root{position:relative}.DraftEditor-editorContainer{background-color:rgba(255,255,255,0);border-left:.1px solid transparent;position:relative;z-index:1}.public-DraftEditor-block{position:relative}.DraftEditor-alignLeft .public-DraftStyleDefault-block{text-align:left}.DraftEditor-alignLeft .public-DraftEditorPlaceholder-root{left:0;text-align:left}.DraftEditor-alignCenter .public-DraftStyleDefault-block{text-align:center}.DraftEditor-alignCenter .public-DraftEditorPlaceholder-root{margin:0 auto;text-align:center;width:100%}.DraftEditor-alignRight .public-DraftStyleDefault-block{text-align:right}.DraftEditor-alignRight .public-DraftEditorPlaceholder-root{right:0;text-align:right}.public-DraftEditorPlaceholder-root{color:#9197a3;position:absolute;z-index:1}.public-DraftEditorPlaceholder-hasFocus{color:#bdc1c9}.DraftEditorPlaceholder-hidden{display:none}.public-DraftStyleDefault-block{position:relative;white-space:pre-wrap}.public-DraftStyleDefault-ltr{direction:ltr;text-align:left}.public-DraftStyleDefault-rtl{direction:rtl;text-align:right}.public-DraftStyleDefault-listLTR{direction:ltr}.public-DraftStyleDefault-listRTL{direction:rtl}.public-DraftStyleDefault-ol,.public-DraftStyleDefault-ul{margin:16px 0;padding:0}.public-DraftStyleDefault-depth0.public-DraftStyleDefault-listLTR{margin-left:1.5em}.public-DraftStyleDefault-depth0.public-DraftStyleDefault-listRTL{margin-right:1.5em}.public-DraftStyleDefault-depth1.public-DraftStyleDefault-listLTR{margin-left:3em}.public-DraftStyleDefault-depth1.public-DraftStyleDefault-listRTL{margin-right:3em}.public-DraftStyleDefault-depth2.public-DraftStyleDefault-listLTR{margin-left:4.5em}.public-DraftStyleDefault-depth2.public-DraftStyleDefault-listRTL{margin-right:4.5em}.public-DraftStyleDefault-depth3.public-DraftStyleDefault-listLTR{margin-left:6em}.public-DraftStyleDefault-depth3.public-DraftStyleDefault-listRTL{margin-right:6em}.public-DraftStyleDefault-depth4.public-DraftStyleDefault-listLTR{margin-left:7.5em}.public-DraftStyleDefault-depth4.public-DraftStyleDefault-listRTL{margin-right:7.5em}.public-DraftStyleDefault-unorderedListItem{list-style-type:square;position:relative}.public-DraftStyleDefault-unorderedListItem.public-DraftStyleDefault-depth0{list-style-type:disc}.public-DraftStyleDefault-unorderedListItem.public-DraftStyleDefault-depth1{list-style-type:circle}.public-DraftStyleDefault-orderedListItem{list-style-type:none;position:relative}.public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-listLTR:before{left:-36px;position:absolute;text-align:right;width:30px}.public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-listRTL:before{position:absolute;right:-36px;text-align:left;width:30px}.public-DraftStyleDefault-orderedListItem:before{content:counter(ol0) ". ";counter-increment:ol0}.public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth1:before{content:counter(ol1,lower-alpha) ". ";counter-increment:ol1}.public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth2:before{content:counter(ol2,lower-roman) ". ";counter-increment:ol2}.public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth3:before{content:counter(ol3) ". ";counter-increment:ol3}.public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth4:before{content:counter(ol4,lower-alpha) ". ";counter-increment:ol4}.public-DraftStyleDefault-depth0.public-DraftStyleDefault-reset{counter-reset:ol0}.public-DraftStyleDefault-depth1.public-DraftStyleDefault-reset{counter-reset:ol1}.public-DraftStyleDefault-depth2.public-DraftStyleDefault-reset{counter-reset:ol2}.public-DraftStyleDefault-depth3.public-DraftStyleDefault-reset{counter-reset:ol3}.public-DraftStyleDefault-depth4.public-DraftStyleDefault-reset{counter-reset:ol4} \ No newline at end of file + +.DraftEditor-editorContainer,.DraftEditor-root,.public-DraftEditor-content{height:inherit;text-align:initial}.public-DraftEditor-content[contenteditable=true]{-webkit-user-modify:read-write-plaintext-only}.DraftEditor-root{position:relative}.DraftEditor-editorContainer{background-color:rgba(255,255,255,0);border-left:.1px solid transparent;position:relative;z-index:1}.public-DraftEditor-block{position:relative}.DraftEditor-alignLeft .public-DraftStyleDefault-block{text-align:left}.DraftEditor-alignLeft .public-DraftEditorPlaceholder-root{left:0;text-align:left}.DraftEditor-alignCenter .public-DraftStyleDefault-block{text-align:center}.DraftEditor-alignCenter .public-DraftEditorPlaceholder-root{margin:0 auto;text-align:center;width:100%}.DraftEditor-alignRight .public-DraftStyleDefault-block{text-align:right}.DraftEditor-alignRight .public-DraftEditorPlaceholder-root{right:0;text-align:right}.public-DraftEditorPlaceholder-root{color:#9197a3;position:absolute;z-index:1}.public-DraftEditorPlaceholder-hasFocus{color:#bdc1c9}.DraftEditorPlaceholder-hidden{display:none}.public-DraftStyleDefault-block{position:relative;white-space:pre-wrap}.public-DraftStyleDefault-ltr{direction:ltr;text-align:left}.public-DraftStyleDefault-rtl{direction:rtl;text-align:right}.public-DraftStyleDefault-listLTR{direction:ltr}.public-DraftStyleDefault-listRTL{direction:rtl}.public-DraftStyleDefault-ol,.public-DraftStyleDefault-ul{margin:16px 0;padding:0}.public-DraftStyleDefault-depth0.public-DraftStyleDefault-listLTR{margin-left:1.5em}.public-DraftStyleDefault-depth0.public-DraftStyleDefault-listRTL{margin-right:1.5em}.public-DraftStyleDefault-depth1.public-DraftStyleDefault-listLTR{margin-left:3em}.public-DraftStyleDefault-depth1.public-DraftStyleDefault-listRTL{margin-right:3em}.public-DraftStyleDefault-depth2.public-DraftStyleDefault-listLTR{margin-left:4.5em}.public-DraftStyleDefault-depth2.public-DraftStyleDefault-listRTL{margin-right:4.5em}.public-DraftStyleDefault-depth3.public-DraftStyleDefault-listLTR{margin-left:6em}.public-DraftStyleDefault-depth3.public-DraftStyleDefault-listRTL{margin-right:6em}.public-DraftStyleDefault-depth4.public-DraftStyleDefault-listLTR{margin-left:7.5em}.public-DraftStyleDefault-depth4.public-DraftStyleDefault-listRTL{margin-right:7.5em}.public-DraftStyleDefault-unorderedListItem{list-style-type:square;position:relative}.public-DraftStyleDefault-unorderedListItem.public-DraftStyleDefault-depth0{list-style-type:disc}.public-DraftStyleDefault-unorderedListItem.public-DraftStyleDefault-depth1{list-style-type:circle}.public-DraftStyleDefault-orderedListItem{list-style-type:none;position:relative}.public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-listLTR:before{left:-36px;position:absolute;text-align:right;width:30px}.public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-listRTL:before{position:absolute;right:-36px;text-align:left;width:30px}.public-DraftStyleDefault-orderedListItem:before{content:counter(ol0) ". ";counter-increment:ol0}.public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth1:before{content:counter(ol1,lower-alpha) ". ";counter-increment:ol1}.public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth2:before{content:counter(ol2,lower-roman) ". ";counter-increment:ol2}.public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth3:before{content:counter(ol3) ". ";counter-increment:ol3}.public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth4:before{content:counter(ol4,lower-alpha) ". ";counter-increment:ol4}.public-DraftStyleDefault-depth0.public-DraftStyleDefault-reset{counter-reset:ol0}.public-DraftStyleDefault-depth1.public-DraftStyleDefault-reset{counter-reset:ol1}.public-DraftStyleDefault-depth2.public-DraftStyleDefault-reset{counter-reset:ol2}.public-DraftStyleDefault-depth3.public-DraftStyleDefault-reset{counter-reset:ol3}.public-DraftStyleDefault-depth4.public-DraftStyleDefault-reset{counter-reset:ol4} diff --git a/website/src/components/DraftEditorExample/css/example.css b/website/src/components/DraftEditorExample/css/example.css new file mode 100644 index 0000000000..c936b684d4 --- /dev/null +++ b/website/src/components/DraftEditorExample/css/example.css @@ -0,0 +1,100 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#rich-example em { + font-style: italic; +} + +#rich-example h1, +#rich-example h2, +#rich-example h3, +#rich-example h4, +#rich-example h5, +#rich-example h6 { + margin: 10px 0; + font-family: inherit; + font-weight: bold; + line-height: 20px; + color: inherit; + text-rendering: optimizelegibility; +} + +#rich-example h1 small, +#rich-example h2 small, +#rich-example h3 small, +#rich-example h4 small, +#rich-example h5 small, +#rich-example h6 small { + font-weight: normal; + color: #7b7b7b; +} + +#rich-example h1, +#rich-example h2, +#rich-example h3 { + line-height: 40px; +} + +#rich-example h1 { + font-size: 39px; +} + +#rich-example h2 { + font-size: 31px; +} + +#rich-example h3 { + font-size: 23px; +} + +#rich-example h4 { + font-size: 17px; +} + +#rich-example h5 { + font-size: 14px; +} + +#rich-example h6 { + font-size: 11px; +} + +#rich-example h1 small { + font-size: 24px; +} + +#rich-example h2 small { + font-size: 18px; +} + +#rich-example h3 small { + font-size: 16px; +} + +#rich-example h4 small { + font-size: 14px; +} + +#rich-example ul, #rich-example ol { + margin: 0 0 10px 25px; + padding: 0; +} + +#rich-example ul ul, +#rich-example ul ol, +#rich-example ol ol, +#rich-example ol ul { + margin-bottom: 0; +} + +#rich-example li { + line-height: 20px; +} + +#rich-example blockquote { + background-color: inherit; +} diff --git a/website/static/css/RichEditor.css b/website/src/components/DraftEditorExample/css/rich-editor.css similarity index 100% rename from website/static/css/RichEditor.css rename to website/src/components/DraftEditorExample/css/rich-editor.css diff --git a/website/pages/en/index.js b/website/src/components/DraftEditorExample/index.js old mode 100755 new mode 100644 similarity index 55% rename from website/pages/en/index.js rename to website/src/components/DraftEditorExample/index.js index 926140e518..06c7ea1b01 --- a/website/pages/en/index.js +++ b/website/src/components/DraftEditorExample/index.js @@ -5,19 +5,18 @@ * LICENSE file in the root directory of this source tree. */ -const React = require('react'); +import React from 'react'; +import Link from '@docusaurus/Link'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; +import useBaseUrl from '@docusaurus/useBaseUrl'; +import {Editor, EditorState, RichUtils, getDefaultKeyBinding} from 'draft-js'; +import classnames from 'classnames'; -const CompLibrary = require('../../core/CompLibrary.js'); -const MarkdownBlock = CompLibrary.MarkdownBlock; /* Used to read markdown */ -const Container = CompLibrary.Container; -const GridBlock = CompLibrary.GridBlock; +import Layout from '@theme/Layout'; -const siteConfig = require(process.cwd() + '/siteConfig.js'); - -var richExample = ` -'use strict'; - -const {Editor, EditorState, RichUtils, getDefaultKeyBinding} = Draft; +import './css/example.css'; +import './css/draft.css'; +import './css/rich-editor.css'; class RichEditorExample extends React.Component { constructor(props) { @@ -25,7 +24,7 @@ class RichEditorExample extends React.Component { this.state = {editorState: EditorState.createEmpty()}; this.focus = () => this.editor.focus(); - this.onChange = (editorState) => this.setState({editorState}); + this.onChange = editorState => this.setState({editorState}); this.handleKeyCommand = this._handleKeyCommand.bind(this); this.mapKeyToEditorCommand = this._mapKeyToEditorCommand.bind(this); @@ -48,7 +47,7 @@ class RichEditorExample extends React.Component { const newEditorState = RichUtils.onTab( e, this.state.editorState, - 4, /* maxDepth */ + 4 /* maxDepth */, ); if (newEditorState !== this.state.editorState) { this.onChange(newEditorState); @@ -59,20 +58,12 @@ class RichEditorExample extends React.Component { } _toggleBlockType(blockType) { - this.onChange( - RichUtils.toggleBlockType( - this.state.editorState, - blockType - ) - ); + this.onChange(RichUtils.toggleBlockType(this.state.editorState, blockType)); } _toggleInlineStyle(inlineStyle) { this.onChange( - RichUtils.toggleInlineStyle( - this.state.editorState, - inlineStyle - ) + RichUtils.toggleInlineStyle(this.state.editorState, inlineStyle), ); } @@ -84,7 +75,12 @@ class RichEditorExample extends React.Component { let className = 'RichEditor-editor'; var contentState = editorState.getCurrentContent(); if (!contentState.hasText()) { - if (contentState.getBlockMap().first().getType() !== 'unstyled') { + if ( + contentState + .getBlockMap() + .first() + .getType() !== 'unstyled' + ) { className += ' RichEditor-hidePlaceholder'; } } @@ -108,7 +104,7 @@ class RichEditorExample extends React.Component { keyBindingFn={this.mapKeyToEditorCommand} onChange={this.onChange} placeholder="Tell a story..." - ref={(ref) => this.editor = ref} + ref={ref => (this.editor = ref)} spellCheck={true} /> @@ -129,15 +125,17 @@ const styleMap = { function getBlockStyle(block) { switch (block.getType()) { - case 'blockquote': return 'RichEditor-blockquote'; - default: return null; + case 'blockquote': + return 'RichEditor-blockquote'; + default: + return null; } } class StyleButton extends React.Component { constructor() { super(); - this.onToggle = (e) => { + this.onToggle = e => { e.preventDefault(); this.props.onToggle(this.props.style); }; @@ -170,7 +168,7 @@ const BLOCK_TYPES = [ {label: 'Code Block', style: 'code-block'}, ]; -const BlockStyleControls = (props) => { +const BlockStyleControls = props => { const {editorState} = props; const selection = editorState.getSelection(); const blockType = editorState @@ -180,7 +178,7 @@ const BlockStyleControls = (props) => { return (
    - {BLOCK_TYPES.map((type) => + {BLOCK_TYPES.map(type => ( { onToggle={props.onToggle} style={type.style} /> - )} + ))}
    ); }; -var INLINE_STYLES = [ +const INLINE_STYLES = [ {label: 'Bold', style: 'BOLD'}, {label: 'Italic', style: 'ITALIC'}, {label: 'Underline', style: 'UNDERLINE'}, {label: 'Monospace', style: 'CODE'}, ]; -const InlineStyleControls = (props) => { - var currentStyle = props.editorState.getCurrentInlineStyle(); +const InlineStyleControls = props => { + const currentStyle = props.editorState.getCurrentInlineStyle(); return (
    - {INLINE_STYLES.map(type => + {INLINE_STYLES.map(type => ( { onToggle={props.onToggle} style={type.style} /> - )} + ))}
    ); }; -ReactDOM.render( - , - document.getElementById('rich-example') -); -`; - -class Index extends React.Component { - render() { - return ( -
    -
    -
    -
    Draft.js
    -
    - Rich Text Editor Framework for React -
    -
    -
    - -
    -
    -

    - Draft.js is a framework for building rich text editors in React, - powered by an immutable model and abstracting over cross-browser - differences. -

    - -

    - Draft.js makes it easy to build any type of rich text input, - whether you're just looking to support a few inline text styles - or building a complex text editor for composing long-form - articles. -

    - -

    - In Draft.js, everything is customizable – we provide the - building blocks so that you have full control over the user - interface. Here's a simple example of a rich text editor built in - Draft.js: -

    - -
    -
    - -
    - -
    -
    - - - - - - - - -