├── .all-contributorsrc
├── .bookignore
├── .editorconfig
├── .eslintignore
├── .eslintrc
├── .gitignore
├── .nvmrc
├── .prettierignore
├── .prettierrc
├── .storybook
└── config.js
├── .travis.yml
├── LICENSE
├── README.md
├── SUMMARY.md
├── babel.config.js
├── draft-js-plugins-next.code-workspace
├── examples
├── add-video-block
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ ├── index.html
│ │ └── manifest.json
│ └── src
│ │ ├── App.js
│ │ ├── InsertBlock.js
│ │ ├── Mentions.js
│ │ ├── index.css
│ │ └── index.js
├── atomic-block
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ └── index.html
│ └── src
│ │ ├── index.js
│ │ └── styles.css
├── block-switcher
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ ├── index.html
│ │ └── manifest.json
│ └── src
│ │ ├── App.js
│ │ ├── BlockSwitch.js
│ │ ├── index.css
│ │ └── index.js
├── counter
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ └── index.html
│ └── src
│ │ ├── WordCountPlugin.js
│ │ ├── index.js
│ │ └── styles.css
├── divider-example
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ └── index.html
│ └── src
│ │ ├── InsertDivider.js
│ │ ├── index.js
│ │ └── styles.css
├── editor
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ ├── index.html
│ │ └── manifest.json
│ └── src
│ │ ├── App.js
│ │ ├── Mentions.js
│ │ ├── index.css
│ │ └── index.js
├── emoji-example
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ └── index.html
│ └── src
│ │ ├── index.js
│ │ └── styles.css
├── hashtag-example
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ └── index.html
│ └── src
│ │ ├── Hashtag
│ │ ├── hashtagStrategy.js
│ │ └── index.js
│ │ ├── index.js
│ │ └── styles.css
├── inline-toolbar
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ ├── index.html
│ │ └── manifest.json
│ └── src
│ │ ├── App.js
│ │ ├── index.css
│ │ └── index.js
├── linkify-example
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ └── index.html
│ └── src
│ │ ├── Link.js
│ │ ├── index.js
│ │ ├── linkStrategy.js
│ │ └── styles.css
├── mentions-example
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ └── index.html
│ └── src
│ │ ├── index.js
│ │ └── styles.css
├── static-toolbar-example
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ ├── index.html
│ │ └── manifest.json
│ └── src
│ │ ├── App.js
│ │ ├── index.css
│ │ └── index.js
└── undo-example
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ └── index.html
│ └── src
│ ├── Undo
│ ├── components
│ │ ├── Redo.js
│ │ └── Undo.js
│ └── index.js
│ ├── index.js
│ └── styles.css
├── lerna.json
├── logo.sketch
├── package-lock.json
├── package.json
├── packages
├── atomic-block
│ ├── .flowconfig
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── rollup.config.js
│ └── src
│ │ ├── AtomicBlock.js
│ │ ├── index.js
│ │ └── styles.css
├── autocomplete
│ ├── .flowconfig
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── rollup.config.js
│ └── src
│ │ ├── index.js
│ │ └── styles.css
├── block-type-toggle
│ ├── .flowconfig
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── rollup.config.js
│ └── src
│ │ └── index.js
├── core
│ ├── .flowconfig
│ ├── README.md
│ ├── flow-lib
│ │ └── draft-js
│ │ │ ├── AtomicBlockUtils.js
│ │ │ ├── BlockMap.js.flow
│ │ │ ├── BlockMapBuilder.js.flow
│ │ │ ├── BlockNode.js.flow
│ │ │ ├── BlockNodeRecord.js.flow
│ │ │ ├── BlockTree.js.flow
│ │ │ ├── CharacterMetadata.js.flow
│ │ │ ├── ComposedEntityMutability.js.flow
│ │ │ ├── CompositeDraftDecorator.js.flow
│ │ │ ├── ContentBlock.js.flow
│ │ │ ├── ContentBlockNode.js.flow
│ │ │ ├── ContentState.js.flow
│ │ │ ├── ContentStateInlineStyle.js.flow
│ │ │ ├── DOMDerivedSelection.js.flow
│ │ │ ├── DefaultDraftBlockRenderMap.js.flow
│ │ │ ├── DefaultDraftInlineStyle.js.flow
│ │ │ ├── Draft.js.flow
│ │ │ ├── DraftBlockRenderConfig.js.flow
│ │ │ ├── DraftBlockRenderMap.js.flow
│ │ │ ├── DraftBlockType.js.flow
│ │ │ ├── DraftDecorator.js.flow
│ │ │ ├── DraftDecoratorType.js.flow
│ │ │ ├── DraftDragType.js.flow
│ │ │ ├── DraftEditor.react.js.flow
│ │ │ ├── DraftEditorBlock.react.js.flow
│ │ │ ├── DraftEditorBlockNode.react.js.flow
│ │ │ ├── DraftEditorCommand.js.flow
│ │ │ ├── DraftEditorCompositionHandler.js.flow
│ │ │ ├── DraftEditorContents-core.react.js.flow
│ │ │ ├── DraftEditorContents.react.js.flow
│ │ │ ├── DraftEditorContentsExperimental.react.js.flow
│ │ │ ├── DraftEditorDecoratedLeaves.react.js.flow
│ │ │ ├── DraftEditorDragHandler.js.flow
│ │ │ ├── DraftEditorEditHandler.js.flow
│ │ │ ├── DraftEditorLeaf.js.flow
│ │ │ ├── DraftEditorLeaf.react.js.flow
│ │ │ ├── DraftEditorModes.js.flow
│ │ │ ├── DraftEditorNode.react.js.flow
│ │ │ ├── DraftEditorPlaceholder.react.js.flow
│ │ │ ├── DraftEditorProps.js.flow
│ │ │ ├── DraftEditorTextNode.react.js.flow
│ │ │ ├── DraftEntity.js.flow
│ │ │ ├── DraftEntityInstance.js.flow
│ │ │ ├── DraftEntityMutability.js.flow
│ │ │ ├── DraftEntitySegments.js.flow
│ │ │ ├── DraftEntityType.js.flow
│ │ │ ├── DraftFeatureFlags-core.js.flow
│ │ │ ├── DraftFeatureFlags.js.flow
│ │ │ ├── DraftHandleValue.js.flow
│ │ │ ├── DraftInlineStyle.js.flow
│ │ │ ├── DraftInsertionType.js.flow
│ │ │ ├── DraftJsDebugLogging.js.flow
│ │ │ ├── DraftModifier.js.flow
│ │ │ ├── DraftODS.js.flow
│ │ │ ├── DraftOffsetKey.js.flow
│ │ │ ├── DraftOffsetKeyPath.js.flow
│ │ │ ├── DraftPasteProcessor.js.flow
│ │ │ ├── DraftRange.js.flow
│ │ │ ├── DraftRemovableWord.js.flow
│ │ │ ├── DraftRemovalDirection.js.flow
│ │ │ ├── DraftScrollPosition.js.flow
│ │ │ ├── DraftStringKey.js.flow
│ │ │ ├── DraftTextAlignment.js.flow
│ │ │ ├── DraftTreeAdapter.js.flow
│ │ │ ├── EditorBidiService.js.flow
│ │ │ ├── EditorChangeType.js.flow
│ │ │ ├── EditorState.js.flow
│ │ │ ├── EditorStateCreationConfig.js.flow
│ │ │ ├── EntityMap.js.flow
│ │ │ ├── EntityRange.js.flow
│ │ │ ├── InlineStyleRange.js.flow
│ │ │ ├── KeyBindingUtil.js.flow
│ │ │ ├── RawDraftContentBlock.js.flow
│ │ │ ├── RawDraftContentState.js.flow
│ │ │ ├── RawDraftEntity.js.flow
│ │ │ ├── RichTextEditorUtil.js.flow
│ │ │ ├── SampleDraftInlineStyle.js.flow
│ │ │ ├── SecondaryClipboard.js.flow
│ │ │ ├── SelectionState.js.flow
│ │ │ ├── _DraftTestHelper.js.flow
│ │ │ ├── addEntityToContentState.js.flow
│ │ │ ├── addEntityToEntityMap.js.flow
│ │ │ ├── adjustBlockDepthForContentState.js.flow
│ │ │ ├── applyEntityToContentBlock.js.flow
│ │ │ ├── applyEntityToContentState.js.flow
│ │ │ ├── convertFromDraftStateToRaw.js.flow
│ │ │ ├── convertFromHTMLToContentBlocks.js.flow
│ │ │ ├── convertFromRawToDraftState.js.flow
│ │ │ ├── createCharacterList.js.flow
│ │ │ ├── createEntityInContentState.js.flow
│ │ │ ├── decodeEntityRanges.js.flow
│ │ │ ├── decodeInlineStyleRanges.js.flow
│ │ │ ├── editOnBeforeInput.js.flow
│ │ │ ├── editOnBlur.js.flow
│ │ │ ├── editOnCompositionStart.js.flow
│ │ │ ├── editOnCopy.js.flow
│ │ │ ├── editOnCut.js.flow
│ │ │ ├── editOnDragOver.js.flow
│ │ │ ├── editOnDragStart.js.flow
│ │ │ ├── editOnFocus.js.flow
│ │ │ ├── editOnInput.js.flow
│ │ │ ├── editOnKeyDown.js.flow
│ │ │ ├── editOnPaste.js.flow
│ │ │ ├── editOnSelect.js.flow
│ │ │ ├── encodeEntityRanges.js.flow
│ │ │ ├── encodeInlineStyleRanges.js.flow
│ │ │ ├── expandRangeToStartOfLine.js.flow
│ │ │ ├── findAncestorOffsetKey.js.flow
│ │ │ ├── findRangesImmutable.js.flow
│ │ │ ├── generateRandomKey.js.flow
│ │ │ ├── getCharacterRemovalRange.js.flow
│ │ │ ├── getContentStateFragment.js.flow
│ │ │ ├── getDefaultKeyBinding.js.flow
│ │ │ ├── getDraftEditorSelection.js.flow
│ │ │ ├── getDraftEditorSelectionWithNodes.js.flow
│ │ │ ├── getEntityKeyForSelection.js.flow
│ │ │ ├── getFragmentFromSelection.js.flow
│ │ │ ├── getNextDelimiterBlockKey.js.flow
│ │ │ ├── getRangeBoundingClientRect.js.flow
│ │ │ ├── getRangeClientRects.js.flow
│ │ │ ├── getRangesForDraftEntity.js.flow
│ │ │ ├── getSafeBodyFromHTML.js.flow
│ │ │ ├── getSampleSelectionMocksForTesting.js.flow
│ │ │ ├── getSampleSelectionMocksForTestingNestedBlocks.js.flow
│ │ │ ├── getSampleStateForTesting.js.flow
│ │ │ ├── getSelectionOffsetKeyForNode.js.flow
│ │ │ ├── getTextAfterNearestEntity.js.flow
│ │ │ ├── getTextContentFromFiles.js.flow
│ │ │ ├── getUpdatedSelectionState.js.flow
│ │ │ ├── getVisibleSelectionRect.js.flow
│ │ │ ├── gkx.js.flow
│ │ │ ├── insertFragmentIntoContentState.js.flow
│ │ │ ├── insertIntoList.js.flow
│ │ │ ├── insertTextIntoContentState.js.flow
│ │ │ ├── isEventHandled.js.flow
│ │ │ ├── isSelectionAtLeafStart.js.flow
│ │ │ ├── isSoftNewlineEvent.js.flow
│ │ │ ├── keyCommandBackspaceToStartOfLine.js.flow
│ │ │ ├── keyCommandBackspaceWord.js.flow
│ │ │ ├── keyCommandDeleteWord.js.flow
│ │ │ ├── keyCommandInsertNewline.js.flow
│ │ │ ├── keyCommandMoveSelectionToEndOfBlock.js.flow
│ │ │ ├── keyCommandMoveSelectionToStartOfBlock.js.flow
│ │ │ ├── keyCommandPlainBackspace.js.flow
│ │ │ ├── keyCommandPlainDelete.js.flow
│ │ │ ├── keyCommandTransposeCharacters.js.flow
│ │ │ ├── keyCommandUndo.js.flow
│ │ │ ├── modifyBlockForContentState.js.flow
│ │ │ ├── moveBlockInContentState.js.flow
│ │ │ ├── moveSelectionBackward.js.flow
│ │ │ ├── moveSelectionForward.js.flow
│ │ │ ├── randomizeBlockMapKeys.js.flow
│ │ │ ├── removeEntitiesAtEdges.js.flow
│ │ │ ├── removeRangeFromContentState.js.flow
│ │ │ ├── removeTextWithStrategy.js.flow
│ │ │ ├── sanitizeDraftText.js.flow
│ │ │ ├── setDraftEditorSelection.js.flow
│ │ │ ├── splitBlockInContentState.js.flow
│ │ │ ├── splitTextIntoTextBlocks.js.flow
│ │ │ └── updateEntityDataInContentState.js.flow
│ ├── package-lock.json
│ ├── package.json
│ ├── rollup.config.js
│ └── src
│ │ ├── Editor.js
│ │ ├── EditorContainer.js
│ │ ├── Plugin.js
│ │ ├── constants.js
│ │ ├── index.js
│ │ └── types.js
├── inline-style-toggle
│ ├── .flowconfig
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── rollup.config.js
│ └── src
│ │ └── index.js
└── utils
│ ├── .flowconfig
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── rollup.config.js
│ └── src
│ ├── __test__
│ └── index.js
│ └── index.js
├── rationale.md
└── scripts
└── publish.js
/.all-contributorsrc:
--------------------------------------------------------------------------------
1 | {
2 | "projectName": "next",
3 | "projectOwner": "draft-js-plugins",
4 | "repoType": "github",
5 | "repoHost": "https://github.com",
6 | "files": [
7 | "README.md"
8 | ],
9 | "imageSize": 100,
10 | "commit": true,
11 | "contributors": [
12 | {
13 | "login": "freedomlang",
14 | "name": "blackywkl",
15 | "avatar_url": "https://avatars2.githubusercontent.com/u/11409069?v=4",
16 | "profile": "http://freedomlang.com",
17 | "contributions": [
18 | "code",
19 | "doc",
20 | "example"
21 | ]
22 | },
23 | {
24 | "login": "hosmelq",
25 | "name": "Hosmel Quintana",
26 | "avatar_url": "https://avatars2.githubusercontent.com/u/1166143?v=4",
27 | "profile": "http://hosmelq.com",
28 | "contributions": [
29 | "code"
30 | ]
31 | },
32 | {
33 | "login": "Rosey",
34 | "name": "Rose",
35 | "avatar_url": "https://avatars0.githubusercontent.com/u/1326431?v=4",
36 | "profile": "http://r.osey.me",
37 | "contributions": [
38 | "code"
39 | ]
40 | }
41 | ]
42 | }
43 |
--------------------------------------------------------------------------------
/.bookignore:
--------------------------------------------------------------------------------
1 | **/node_modules
2 | **/*.js
3 | **/*.jsx
4 | **/*.png
5 | **/*.jpg
6 | **/package.json
7 | **/package-lock.json
8 | **/*.log
9 | **/.flowconfig
10 | dist
11 | examples
12 | **/src
13 | .vscode
14 | flow-lib
15 | .storybook
16 | .git
17 | .DS_Store
18 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | .storybook
4 | public
5 | _book
6 | .book
7 | .storybook
8 | build
9 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "parser": "babel-eslint",
3 | "extends": [
4 | "standard",
5 | "plugin:react/recommended",
6 | "plugin:flowtype/recommended",
7 | "prettier",
8 | "prettier/flowtype",
9 | "prettier/react",
10 | "prettier/standard",
11 | ],
12 | "parserOptions": {
13 | "sourceType": "module",
14 | "ecmaFeatures": {
15 | "jsx": true
16 | }
17 | },
18 | "settings": {
19 | "react": {
20 | "version": "16"
21 | }
22 | },
23 | "plugins": ["prettier", "flowtype", "react", "standard"],
24 | "env": {
25 | "es6": true,
26 | "browser": true,
27 | "mocha": true
28 | },
29 | "rules": {
30 | "prettier/prettier": "error"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 | _book
4 | build
5 | dist
6 | **/dist
7 | yarn.lock
8 | .vscode
9 | yarn-error.log
10 | lerna-debug.log
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | 8.10.0
2 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | _book
4 | .book
5 | .storybook
6 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "trailingComma": "es5",
3 | "semi": false,
4 | "singleQuote": true,
5 | "jsxBracketSameLine": true
6 | }
7 |
--------------------------------------------------------------------------------
/.storybook/config.js:
--------------------------------------------------------------------------------
1 | import { configure } from '@kadira/storybook';
2 |
3 | function requireAll(requireContext) {
4 | return requireContext.keys().map(requireContext);
5 | }
6 |
7 | function loadStories() {
8 | requireAll(require.context("../examples", true, /story\.jsx?$/));
9 | }
10 |
11 | configure(loadStories, module);
12 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "8.10.0"
4 | script:
5 | - npm cache verify
6 | - ./node_modules/.bin/lerna exec -- npm cache verify
7 | - ./node_modules/.bin/lerna bootstrap --hoist
8 | - npm run build
9 | - npm run lint
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015-present Lerna Contributors
2 |
3 | MIT License
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/SUMMARY.md:
--------------------------------------------------------------------------------
1 | # Summary
2 |
3 | * [Introduction](README.md)
4 |
5 | ## Packages
6 | * [Core](packages/core/README.md)
7 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = function(api) {
2 | api.cache(true)
3 | return {
4 | presets: [
5 | [
6 | '@babel/preset-env',
7 | {
8 | targets: '> 0.25%, not dead',
9 | },
10 | ],
11 | '@babel/preset-flow',
12 | '@babel/preset-react',
13 | ],
14 | plugins: [
15 | '@babel/plugin-proposal-class-properties',
16 | '@babel/plugin-proposal-export-default-from',
17 | '@babel/plugin-proposal-export-namespace-from',
18 | ],
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/draft-js-plugins-next.code-workspace:
--------------------------------------------------------------------------------
1 | {
2 | "folders": [
3 | {
4 | "path": "."
5 | }
6 | ],
7 | "settings": {
8 | "eslint.nodePath": "${workspaceRoot}./node_modules"
9 | }
10 | }
--------------------------------------------------------------------------------
/examples/add-video-block/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/add-video-block-example",
3 | "homepage": "https://github.com/draft-js-plugins/next#readme",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/atomic-block": "^0.1.5",
9 | "@djsp/core": "^0.1.5",
10 | "@djsp/utils": "^0.1.5",
11 | "prop-types": "^15.6.1",
12 | "react": "16.5.0",
13 | "react-dom": "16.5.0",
14 | "react-scripts": "^1.1.1",
15 | "react-text-selection-popover": "^1.0.3",
16 | "styled-components": "^3.4.5"
17 | },
18 | "scripts": {
19 | "start": "react-scripts start",
20 | "build": "react-scripts build",
21 | "test": "react-scripts test --env=jsdom",
22 | "eject": "react-scripts eject"
23 | },
24 | "devDependencies": {
25 | "draft-js": "^0.10.5"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/examples/add-video-block/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @djsp/add-video-block-example
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/add-video-block/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "@djsp/core",
3 | "name": "@djsp/core",
4 | "start_url": "./index.html",
5 | "display": "standalone",
6 | "theme_color": "#000000",
7 | "background_color": "#ffffff"
8 | }
9 |
--------------------------------------------------------------------------------
/examples/add-video-block/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { EditorState } from 'draft-js'
3 | import { EditorContainer, Editor } from '@djsp/core'
4 | import InsertBlock from './InsertBlock'
5 |
6 | export default class App extends Component {
7 | state = {
8 | editorState: EditorState.createEmpty(),
9 | }
10 |
11 | onChange = editorState => this.setState({ editorState })
12 |
13 | render() {
14 | return (
15 |
16 |
19 |
20 |
21 |
22 |
23 | )
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/examples/add-video-block/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: sans-serif;
5 | font-size: 1.5em;
6 | }
7 |
8 | * {
9 | box-sizing: border-box;
10 | }
11 |
12 | .public-DraftEditor-content {
13 | position: fixed;
14 | top: 0;
15 | left: 0;
16 | padding: 2em;
17 | width: 100%;
18 | height: 100%;
19 | }
20 |
21 |
22 | .public-DraftEditor-content [contenteditable="false"] {
23 | user-select: none;
24 | }
25 |
26 | .paragraph {
27 | position: relative;
28 | }
29 |
30 | .block-menu {
31 | position: absolute;
32 | right: 0;
33 | top: 0;
34 | }
35 |
36 | .insert-link-placeholder {
37 | position: absolute;
38 | color: #999;
39 | top: 0;
40 | left: 0;
41 | }
42 |
43 | .insert-link-instructions {
44 | font-size: .8em;
45 | }
--------------------------------------------------------------------------------
/examples/add-video-block/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom'
3 |
4 | import './index.css'
5 | import App from './App'
6 |
7 | ReactDOM.render(, document.getElementById('root'))
8 |
--------------------------------------------------------------------------------
/examples/atomic-block/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/atomic-block-example",
3 | "homepage": "https://juliankrispel.github.io/djs-autocomplete",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/atomic-block": "^0.1.5",
9 | "@djsp/core": "^0.1.5",
10 | "emoji.json": "^11.0.0",
11 | "prop-types": "^15.6.1",
12 | "react": "16.5.0",
13 | "react-dom": "16.5.0",
14 | "react-scripts": "^1.1.1"
15 | },
16 | "scripts": {
17 | "start": "react-scripts start",
18 | "build": "react-scripts build",
19 | "test": "react-scripts test --env=jsdom",
20 | "eject": "react-scripts eject"
21 | },
22 | "devDependencies": {
23 | "draft-js": "^0.10.5"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/examples/atomic-block/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @djsp/suggestions
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/atomic-block/src/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import ReactDOM from 'react-dom'
3 |
4 | import { EditorState, convertFromRaw } from 'draft-js'
5 | import { EditorContainer, Editor } from '@djsp/core'
6 | import AtomicBlock from '@djsp/atomic-block'
7 | import './styles.css'
8 |
9 | const rawContent = {
10 | blocks: [
11 | {
12 | text: 'Hey there duder',
13 | },
14 | {
15 | type: 'atomic',
16 | text: ' ',
17 | entityRanges: [
18 | {
19 | key: 0,
20 | length: 1,
21 | offset: 0,
22 | },
23 | ],
24 | },
25 | ],
26 | entityMap: {
27 | 0: {
28 | data: {
29 | title: 'Kitten',
30 | src: 'https://placekitten.com/200/200',
31 | },
32 | mutability: 'IMMUTABLE',
33 | type: 'IMAGE',
34 | },
35 | },
36 | }
37 |
38 | class App extends Component {
39 | state = {
40 | editorState: EditorState.createWithContent(convertFromRaw(rawContent)),
41 | }
42 |
43 | onChange = editorState => this.setState({ editorState })
44 |
45 | render() {
46 | return (
47 |
48 |
51 |
52 |
53 |
54 | {({ isFocused, blockProps: { src, title } }) => {
55 | return (
56 |
61 | )
62 | }}
63 |
64 |
65 |
66 | )
67 | }
68 | }
69 |
70 | ReactDOM.render(, document.getElementById('root'))
71 |
--------------------------------------------------------------------------------
/examples/atomic-block/src/styles.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.8em;
4 | padding: 1em;
5 | background: #12312e;
6 | }
7 |
8 | .public-DraftEditor-content {
9 | padding: 2em;
10 | border-radius: 5px;
11 | color: #fff;
12 | border: #555;
13 | background: #244a46;
14 | }
15 |
16 | .autocomplete {
17 | margin-top: 1em;
18 | }
19 |
20 | .list__item {
21 | display: block;
22 | padding: .5em;
23 | color: #ccc;
24 | background: transparent;
25 | transition: 100ms;
26 | }
27 |
28 | .list__item--focused {
29 | color: #fff;
30 | padding-left: 1.2em;
31 | background: #2a6f51;
32 | border-radius: 5px;
33 | }
34 |
35 | .focused {
36 | border: 2px solid blue;
37 | }
38 |
--------------------------------------------------------------------------------
/examples/block-switcher/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/block-switcher-example",
3 | "homepage": "https://github.com/draft-js-plugins/next#readme",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/atomic-block": "^0.1.5",
9 | "@djsp/core": "^0.1.5",
10 | "@djsp/utils": "^0.1.5",
11 | "prop-types": "^15.6.1",
12 | "react": "16.5.0",
13 | "react-dom": "16.5.0",
14 | "react-scripts": "^1.1.1"
15 | },
16 | "scripts": {
17 | "start": "react-scripts start",
18 | "build": "react-scripts build",
19 | "test": "react-scripts test --env=jsdom",
20 | "eject": "react-scripts eject"
21 | },
22 | "devDependencies": {
23 | "draft-js": "^0.10.5"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/examples/block-switcher/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | @djsp/block-switcher-example
10 |
11 |
12 |
13 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/examples/block-switcher/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "@djsp/core",
3 | "name": "@djsp/core",
4 | "start_url": "./index.html",
5 | "display": "standalone",
6 | "theme_color": "#000000",
7 | "background_color": "#ffffff"
8 | }
9 |
--------------------------------------------------------------------------------
/examples/block-switcher/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { EditorState } from 'draft-js'
3 | import { EditorContainer, Editor } from '@djsp/core'
4 | import BlockSwitch from './BlockSwitch'
5 | import 'draft-js/dist/Draft.css'
6 |
7 | export default class App extends Component {
8 | state = {
9 | editorState: EditorState.createEmpty(),
10 | }
11 |
12 | onChange = editorState => this.setState({ editorState })
13 |
14 | render() {
15 | return (
16 |
17 |
20 |
24 |
25 |
26 |
27 | )
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/examples/block-switcher/src/BlockSwitch.js:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import React, { Component, Fragment } from 'react'
4 | import { EditorState, EditorBlock, RichUtils } from 'draft-js'
5 | import { withPluginContext } from '@djsp/core'
6 | import type { PluginProps } from '@djsp/core'
7 |
8 | const blockTypes = [
9 | 'unstyled',
10 | 'paragraph',
11 | 'header-one',
12 | 'header-two',
13 | 'header-three',
14 | 'header-four',
15 | 'header-five',
16 | 'header-six',
17 | 'unordered-list-item',
18 | 'ordered-list-item',
19 | 'blockquote',
20 | 'code-block',
21 | ]
22 |
23 | type Props = {
24 | block: Object,
25 | blockProps: {
26 | editorState: EditorState,
27 | setEditorState: EditorState => void,
28 | },
29 | }
30 |
31 | class SelectBlock extends Component {
32 | render() {
33 | const {
34 | block,
35 | blockProps: { setEditorState, editorState },
36 | } = this.props
37 |
38 | const selection = editorState.getSelection()
39 | const showSwitch =
40 | selection.getStartKey() === selection.getEndKey() &&
41 | selection.getEndKey() === block.getKey()
42 |
43 | return (
44 |
45 |
46 | {showSwitch && (
47 |
48 | e.stopPropagation()}>
49 |
61 |
62 |
63 | )}
64 |
65 | )
66 | }
67 | }
68 |
69 | class BlockSwitch extends Component {
70 | _unregister: () => void
71 |
72 | componentWillUnmount() {
73 | this._unregister()
74 | }
75 |
76 | componentDidMount() {
77 | const { registerPlugin } = this.props
78 |
79 | this._unregister = registerPlugin({
80 | blockRendererFn: block => {
81 | if (blockTypes.includes(block.getType())) {
82 | return {
83 | component: SelectBlock,
84 | editable: true,
85 | props: this.props,
86 | }
87 | }
88 | },
89 | })
90 | }
91 |
92 | render() {
93 | return null
94 | }
95 | }
96 |
97 | export default withPluginContext(BlockSwitch)
98 |
--------------------------------------------------------------------------------
/examples/block-switcher/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: sans-serif;
5 | font-size: 1.5em;
6 | }
7 |
8 | * {
9 | box-sizing: border-box;
10 | }
11 |
12 | .public-DraftEditor-content {
13 | position: fixed;
14 | top: 0;
15 | left: 0;
16 | padding: 2em;
17 | width: 100%;
18 | height: 100%;
19 | }
20 |
21 |
22 | .public-DraftEditor-content [contenteditable="false"] {
23 | user-select: none;
24 | }
25 |
26 | .paragraph {
27 | position: relative;
28 | }
29 |
30 | .block-menu {
31 | position: absolute;
32 | right: 0;
33 | top: 0;
34 | }
35 |
36 | .insert-link-placeholder {
37 | position: absolute;
38 | color: #999;
39 | top: 0;
40 | left: 0;
41 | }
42 |
43 | .insert-link-instructions {
44 | font-size: .8em;
45 | }
--------------------------------------------------------------------------------
/examples/block-switcher/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom'
3 |
4 | import './index.css'
5 | import App from './App'
6 |
7 | ReactDOM.render(, document.getElementById('root'))
8 |
--------------------------------------------------------------------------------
/examples/counter/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/counter-example",
3 | "homepage": "https://github.com/draft-js-plugins/next#readme",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/utils": "^0.1.5",
9 | "@djsp/core": "^0.1.5",
10 | "react": "16.5.0",
11 | "react-dom": "16.5.0",
12 | "react-scripts": "^1.1.1"
13 | },
14 | "scripts": {
15 | "start": "react-scripts start",
16 | "build": "react-scripts build",
17 | "test": "react-scripts test --env=jsdom",
18 | "eject": "react-scripts eject"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/examples/counter/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @djsp/counter-example
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/counter/src/WordCountPlugin.js:
--------------------------------------------------------------------------------
1 | import React, { Fragment } from 'react'
2 | import { Plugin } from '@djsp/core'
3 | import { getCharCount, getWordCount, getLineCount } from '@djsp/utils'
4 |
5 | export default function WordCountPlugin() {
6 | return (
7 |
8 | {({ editorState }) => (
9 |
10 | Char count: {getCharCount(editorState)}
11 | Word count: {getWordCount(editorState)}
12 | Line count: {getLineCount(editorState)}
13 |
14 | )}
15 |
16 | )
17 | }
18 |
--------------------------------------------------------------------------------
/examples/counter/src/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import ReactDOM from 'react-dom'
3 |
4 | import { EditorState, ContentState } from 'draft-js'
5 | import { EditorContainer, Editor } from '@djsp/core'
6 | import WordCountPlugin from './WordCountPlugin'
7 | import './styles.css'
8 |
9 | class App extends Component {
10 | state = {
11 | editorState: EditorState.createWithContent(
12 | ContentState.createFromText('Just type!')
13 | ),
14 | }
15 |
16 | onChange = editorState => this.setState({ editorState })
17 |
18 | render() {
19 | return (
20 |
21 |
24 |
25 |
26 |
27 |
28 | )
29 | }
30 | }
31 |
32 | ReactDOM.render(, document.getElementById('root'))
33 |
--------------------------------------------------------------------------------
/examples/counter/src/styles.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.8em;
4 | padding: 1em;
5 | background: #12312e;
6 | }
7 |
8 | .public-DraftEditor-content {
9 | padding: 2em;
10 | border-radius: 5px;
11 | color: #fff;
12 | border: #555;
13 | background: #244a46;
14 | }
15 |
--------------------------------------------------------------------------------
/examples/divider-example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/divider-example",
3 | "homepage": "https://github.com/draft-js-plugins/next#readme",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/utils": "^0.1.5",
9 | "@djsp/atomic-block": "^0.1.5",
10 | "@djsp/core": "^0.1.5",
11 | "react": "16.5.0",
12 | "react-dom": "16.5.0",
13 | "react-scripts": "^1.1.1"
14 | },
15 | "scripts": {
16 | "start": "react-scripts start",
17 | "build": "react-scripts build",
18 | "test": "react-scripts test --env=jsdom",
19 | "eject": "react-scripts eject"
20 | },
21 | "devDependencies": {
22 | "draft-js": "^0.10.5"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/examples/divider-example/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @djsp/divider-example
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/divider-example/src/InsertDivider.js:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import React, { Component, Fragment } from 'react'
4 | import { Plugin } from '@djsp/core'
5 | import AtomicBlock from '@djsp/atomic-block'
6 | import { insertEntityBlock } from '@djsp/utils'
7 |
8 | type Props = {
9 | editorState: EditorState,
10 | setEditorState: EditorState => void,
11 | }
12 |
13 | class DividerButton extends Component {
14 | onClick = event => {
15 | event.stopPropagation()
16 |
17 | const { setEditorState, editorState } = this.props
18 | setEditorState(insertEntityBlock(editorState, 'divider'))
19 | }
20 |
21 | render() {
22 | return (
23 |
26 | )
27 | }
28 | }
29 |
30 | const InsertDivider = () => (
31 |
32 |
33 | {({ isFocused }) => (
34 |
35 | )}
36 |
37 |
38 |
39 | {({ editorState, setEditorState }) => (
40 |
44 | )}
45 |
46 |
47 | )
48 |
49 | export default InsertDivider
50 |
--------------------------------------------------------------------------------
/examples/divider-example/src/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import ReactDOM from 'react-dom'
3 |
4 | import { EditorState, convertFromRaw } from 'draft-js'
5 | import { EditorContainer, Editor } from '@djsp/core'
6 | import InsertDivider from './InsertDivider'
7 | import './styles.css'
8 |
9 | const rawContent = {
10 | blocks: [
11 | {
12 | text: 'Here is the divider!',
13 | },
14 | {
15 | type: 'atomic',
16 | text: ' ',
17 | entityRanges: [
18 | {
19 | key: 0,
20 | length: 1,
21 | offset: 0,
22 | },
23 | ],
24 | },
25 | {
26 | text: 'You can add another divider below.',
27 | },
28 | ],
29 | entityMap: {
30 | 0: {
31 | mutability: 'IMMUTABLE',
32 | type: 'DIVIDER',
33 | },
34 | },
35 | }
36 |
37 | class App extends Component {
38 | state = {
39 | editorState: EditorState.createWithContent(convertFromRaw(rawContent)),
40 | }
41 |
42 | onChange = editorState => this.setState({ editorState })
43 |
44 | render() {
45 | return (
46 |
47 |
50 |
51 |
52 |
53 |
54 | )
55 | }
56 | }
57 |
58 | ReactDOM.render(, document.getElementById('root'))
59 |
--------------------------------------------------------------------------------
/examples/divider-example/src/styles.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.8em;
4 | padding: 1em;
5 | background: #12312e;
6 | }
7 |
8 | .public-DraftEditor-content {
9 | padding: 2em;
10 | border-radius: 5px;
11 | color: #fff;
12 | border: #555;
13 | background: #244a46;
14 | }
15 |
16 |
17 | .divider {
18 | display: flex;
19 | align-items: center;
20 | justify-content: center;
21 | width: 100%;
22 | height: 100%;
23 | margin: 32px 0;
24 | border: none; /* strip default hr styling */
25 | text-align: center;
26 | }
27 |
28 | .divider::after {
29 | margin-left: 48px;
30 | color: rgba(0, 0, 0, 0.26); /* pick a color */
31 | font-size: 2.125rem;
32 | letter-spacing: 48px; /* increase space between dots */
33 | content: '•••';
34 | }
35 |
36 | .divider:hover {
37 | border-radius: 2px;
38 | box-shadow: 0 0 0 2px #D2E3F7;
39 | }
40 |
41 | .divider.focused {
42 | border-radius: 2px;
43 | box-shadow: 0 0 0 2px #ACCEF7;
44 | }
--------------------------------------------------------------------------------
/examples/editor/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/core-example",
3 | "homepage": "https://juliankrispel.github.io/@djsp/core",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/core": "^0.1.5",
9 | "draft-js": "^0.10.5",
10 | "prop-types": "^15.6.1",
11 | "react": "16.5.0",
12 | "react-dom": "16.5.0",
13 | "react-scripts": "^1.1.1",
14 | "react-text-selection-popover": "^1.0.3",
15 | "styled-components": "^3.4.5"
16 | },
17 | "scripts": {
18 | "start": "react-scripts start",
19 | "build": "react-scripts build",
20 | "test": "react-scripts test --env=jsdom",
21 | "eject": "react-scripts eject"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/editor/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @djsp/core
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/editor/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "@djsp/core",
3 | "name": "@djsp/core",
4 | "start_url": "./index.html",
5 | "display": "standalone",
6 | "theme_color": "#000000",
7 | "background_color": "#ffffff"
8 | }
9 |
--------------------------------------------------------------------------------
/examples/editor/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 |
3 | import { EditorState } from 'draft-js'
4 | import { EditorContainer, Editor, Plugin } from '@djsp/core'
5 |
6 | export default class App extends Component {
7 | state = {
8 | editorState: EditorState.createEmpty(),
9 | }
10 |
11 | render() {
12 | return (
13 |
14 |
this.setState({ editorState })}>
17 | Hello
18 | console.log('yo', e)}
20 | handleBeforeInput={e => console.log('handle before input', e)}
21 | keyBindingFn={e => {
22 | console.log('keybinding fn', e.key)
23 | }}
24 | />
25 |
26 |
27 |
28 | )
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/examples/editor/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: sans-serif;
5 | }
6 |
--------------------------------------------------------------------------------
/examples/editor/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom'
3 |
4 | import './index.css'
5 | import App from './App'
6 |
7 | ReactDOM.render(, document.getElementById('root'))
8 |
--------------------------------------------------------------------------------
/examples/emoji-example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/emoji-example",
3 | "homepage": "https://github.com/draft-js-plugins/next#readme",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/autocomplete": "^0.1.5",
9 | "@djsp/core": "^0.1.5",
10 | "draft-js": "^0.10.5",
11 | "emoji.json": "^11.0.0",
12 | "prop-types": "^15.6.1",
13 | "react": "16.5.0",
14 | "react-dom": "16.5.0",
15 | "react-scripts": "^1.1.1"
16 | },
17 | "scripts": {
18 | "start": "react-scripts start",
19 | "build": "react-scripts build",
20 | "test": "react-scripts test --env=jsdom",
21 | "eject": "react-scripts eject"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/emoji-example/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @djsp/emoji-example
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/emoji-example/src/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import ReactDOM from 'react-dom'
3 |
4 | import { EditorState, ContentState, Modifier } from 'draft-js'
5 | import { EditorContainer, Editor } from '@djsp/core'
6 | import Autocomplete from '@djsp/autocomplete'
7 | import emojis from 'emoji.json'
8 | import '@djsp/autocomplete/dist/index.css'
9 | import './styles.css'
10 |
11 | class App extends Component {
12 | state = {
13 | editorState: EditorState.createWithContent(
14 | ContentState.createFromText(
15 | 'To trigger the emoji autocomplete just type :'
16 | )
17 | ),
18 | suggestions: [],
19 | }
20 |
21 | renderSuggestion = ({ suggestion, isFocused }) => {
22 | const classNames = ['list__item']
23 | if (isFocused) classNames.push('list__item--focused')
24 | return (
25 |
26 | {suggestion.char} {suggestion.name}
27 |
28 | )
29 | }
30 |
31 | setSuggestions = searchText => {
32 | const search = searchText.slice(1)
33 | this.setState({
34 | suggestions: emojis
35 | .filter(
36 | item => item.name.includes(search) || item.keywords.includes(search)
37 | )
38 | .slice(0, 30),
39 | })
40 | }
41 |
42 | insertEmoji = (emoji, searchText) => {
43 | const { editorState } = this.state
44 | const selection = editorState.getSelection()
45 |
46 | this.setState({
47 | editorState: EditorState.push(
48 | editorState,
49 | Modifier.replaceText(
50 | editorState.getCurrentContent(),
51 | selection.merge({
52 | anchorOffset: selection.getAnchorOffset() - searchText.length,
53 | }),
54 | emoji.char
55 | )
56 | ),
57 | })
58 | }
59 |
60 | onChange = editorState => {
61 | this.setState({ editorState })
62 | }
63 |
64 | render() {
65 | return (
66 |
67 |
70 |
71 |
72 |
81 |
82 |
83 | )
84 | }
85 | }
86 |
87 | ReactDOM.render(, document.getElementById('root'))
88 |
--------------------------------------------------------------------------------
/examples/emoji-example/src/styles.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.8em;
4 | padding: 1em;
5 | background: #12312e;
6 | }
7 |
8 | .public-DraftEditor-content {
9 | padding: 2em;
10 | border-radius: 5px;
11 | color: #fff;
12 | border: #555;
13 | background: #244a46;
14 | }
15 |
16 | .autocomplete {
17 | margin-top: 1em;
18 | }
19 |
20 | .list__item {
21 | display: block;
22 | padding: .5em;
23 | color: #ccc;
24 | background: transparent;
25 | transition: 100ms;
26 | }
27 |
28 | .list__item--focused {
29 | color: #fff;
30 | padding-left: 1.2em;
31 | background: #2a6f51;
32 | border-radius: 5px;
33 | }
34 |
--------------------------------------------------------------------------------
/examples/hashtag-example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/hashtag-example",
3 | "homepage": "https://github.com/draft-js-plugins/next#readme",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/core": "^0.1.5",
9 | "@djsp/utils": "^0.1.5",
10 | "react": "16.5.0",
11 | "react-dom": "16.5.0",
12 | "react-scripts": "^1.1.1"
13 | },
14 | "scripts": {
15 | "start": "react-scripts start",
16 | "build": "react-scripts build",
17 | "test": "react-scripts test --env=jsdom",
18 | "eject": "react-scripts eject"
19 | },
20 | "devDependencies": {
21 | "draft-js": "^0.10.5"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/hashtag-example/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @djsp/hashtag-example
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/hashtag-example/src/Hashtag/hashtagStrategy.js:
--------------------------------------------------------------------------------
1 | /* @flow */
2 | import { findWithRegex } from '@djsp/utils'
3 |
4 | // Note: these aren't very good regexes, don't use them! Please consider draft-js-hashtag-plugin's strategy
5 | // eslint-disable-next-line no-useless-escape
6 | const HASHTAG_REGEX = /\#[\w\u0590-\u05ff]+/g
7 | export default function hashtagStrategy(contentBlock, callback, contentState) {
8 | findWithRegex(HASHTAG_REGEX, contentBlock, callback)
9 | }
10 |
--------------------------------------------------------------------------------
/examples/hashtag-example/src/Hashtag/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 |
3 | export default class Hashtag extends Component {
4 | render() {
5 | return
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/examples/hashtag-example/src/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import ReactDOM from 'react-dom'
3 |
4 | import { EditorState, convertFromRaw } from 'draft-js'
5 | import { EditorContainer, Editor, Plugin } from '@djsp/core'
6 | import hashtagStrategy from './Hashtag/hashtagStrategy'
7 | import Hashtag from './Hashtag'
8 | import './styles.css'
9 |
10 | const rawContent = {
11 | blocks: [
12 | {
13 | text: 'Here is an example for hashtag! #djsp',
14 | },
15 | ],
16 | entityMap: {},
17 | }
18 |
19 | class App extends Component {
20 | state = {
21 | editorState: EditorState.createWithContent(convertFromRaw(rawContent)),
22 | }
23 |
24 | onChange = editorState => this.setState({ editorState })
25 |
26 | render() {
27 | return (
28 |
43 | )
44 | }
45 | }
46 |
47 | ReactDOM.render(, document.getElementById('root'))
48 |
--------------------------------------------------------------------------------
/examples/hashtag-example/src/styles.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.8em;
4 | padding: 1em;
5 | background: #12312e;
6 | }
7 |
8 | .public-DraftEditor-content {
9 | padding: 2em;
10 | border-radius: 5px;
11 | color: #fff;
12 | border: #555;
13 | background: #244a46;
14 | }
15 |
16 | .hashtag {
17 | color: #5e93c5;
18 | }
19 |
--------------------------------------------------------------------------------
/examples/inline-toolbar/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/inline-toolbar-example",
3 | "homepage": "https://github.com/draft-js-plugins/next#readme",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/block-type-toggle": "^0.1.5",
9 | "@djsp/core": "^0.1.5",
10 | "@djsp/inline-style-toggle": "^0.1.5",
11 | "draft-js": "^0.10.5",
12 | "prop-types": "^15.6.1",
13 | "react": "16.5.0",
14 | "react-dom": "16.5.0",
15 | "react-scripts": "^1.1.1",
16 | "react-text-selection-popover": "^1.2.1",
17 | "styled-components": "^3.4.5"
18 | },
19 | "scripts": {
20 | "start": "react-scripts start",
21 | "build": "react-scripts build",
22 | "test": "react-scripts test --env=jsdom",
23 | "eject": "react-scripts eject"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/examples/inline-toolbar/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @djsp/inline-toolbar-example
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/inline-toolbar/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "@djsp/core",
3 | "name": "@djsp/core",
4 | "start_url": "./index.html",
5 | "display": "standalone",
6 | "theme_color": "#000000",
7 | "background_color": "#ffffff"
8 | }
9 |
--------------------------------------------------------------------------------
/examples/inline-toolbar/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-size: 1.8em;
5 | font-family: sans-serif;
6 | }
7 |
8 | .public-DraftEditor-content {
9 | padding: 2em;
10 | height: 100%;
11 | }
12 |
13 | .toolbar {
14 | border-radius: 5px;
15 | overflow: hidden;
16 | padding: 0;
17 | display: flex;
18 | }
19 |
20 | .toolbar__button {
21 | border: none;
22 | margin: 0;
23 | cursor: pointer;
24 | padding: .5em 1em;
25 | font-size: 14px;
26 | background: #333;
27 | color: #fff;
28 | }
29 |
30 | .toolbar__button:last-child {
31 | border-right: none;
32 | }
33 |
34 | .toolbar__button--active {
35 | background: #000;
36 | color: #fff;
37 | }
38 |
39 | .container {
40 | position: fixed;
41 | width: 100%;
42 | height: 100%;
43 | top: 0;
44 | left: 0;
45 | display: flex;
46 | flex-direction: column;
47 | }
48 |
--------------------------------------------------------------------------------
/examples/inline-toolbar/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom'
3 |
4 | import './index.css'
5 | import App from './App'
6 |
7 | ReactDOM.render(, document.getElementById('root'))
8 |
--------------------------------------------------------------------------------
/examples/linkify-example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/linkify-example",
3 | "homepage": "https://github.com/draft-js-plugins/next#readme",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/core": "^0.1.5",
9 | "linkify-it": "^2.0.3",
10 | "react": "16.5.0",
11 | "react-dom": "16.5.0",
12 | "react-scripts": "^1.1.1",
13 | "tlds": "^1.203.1"
14 | },
15 | "scripts": {
16 | "start": "react-scripts start",
17 | "build": "react-scripts build",
18 | "test": "react-scripts test --env=jsdom",
19 | "eject": "react-scripts eject"
20 | },
21 | "devDependencies": {
22 | "draft-js": "^0.10.5"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/examples/linkify-example/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @djsp/linkify-example
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/linkify-example/src/Link.js:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import React, { Component } from 'react'
4 | import { Plugin } from '@djsp/core'
5 | import linkStrategy from './linkStrategy'
6 | import linkifyIt from 'linkify-it'
7 | import tlds from 'tlds'
8 | import type { DraftDecoratorComponentProps } from 'draft-js'
9 |
10 | const linkify = linkifyIt()
11 | linkify.tlds(tlds)
12 |
13 | type Props = DraftDecoratorComponentProps & {
14 | target?: string,
15 | rel?: string,
16 | }
17 |
18 | class LinkComponent extends Component {
19 | render() {
20 | const {
21 | decoratedText,
22 | target = '_self',
23 | rel = 'noreferrer noopener',
24 | children,
25 | } = this.props
26 |
27 | const links = linkify.match(decoratedText)
28 | const href = links && links[0] ? links[0].url : ''
29 |
30 | const props = {
31 | href,
32 | children,
33 | target,
34 | rel,
35 | className: 'link',
36 | }
37 |
38 | // eslint-disable-next-line jsx-a11y/anchor-has-content
39 | return
40 | }
41 | }
42 |
43 | export default function Link() {
44 | return (
45 |
53 | )
54 | }
55 |
--------------------------------------------------------------------------------
/examples/linkify-example/src/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import ReactDOM from 'react-dom'
3 |
4 | import { EditorState, convertFromRaw } from 'draft-js'
5 | import { EditorContainer, Editor } from '@djsp/core'
6 | import Link from './Link'
7 | import './styles.css'
8 |
9 | const rawContent = {
10 | blocks: [
11 | {
12 | text: 'Type some website address.',
13 | },
14 | ],
15 | entityMap: {},
16 | }
17 |
18 | class App extends Component {
19 | state = {
20 | editorState: EditorState.createWithContent(convertFromRaw(rawContent)),
21 | }
22 |
23 | onChange = editorState => this.setState({ editorState })
24 |
25 | render() {
26 | return (
27 |
28 |
31 |
32 |
33 |
34 |
35 | )
36 | }
37 | }
38 |
39 | ReactDOM.render(, document.getElementById('root'))
40 |
--------------------------------------------------------------------------------
/examples/linkify-example/src/linkStrategy.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | // This strategy is from https://github.com/draft-js-plugins/draft-js-plugins/blob/master/draft-js-linkify-plugin/src/linkStrategy.js
3 | import { ContentBlock } from 'draft-js'
4 | import linkifyIt from 'linkify-it'
5 | import tlds from 'tlds'
6 |
7 | const linkify = linkifyIt()
8 | linkify.tlds(tlds)
9 |
10 | // Gets all the links in the text, and returns them via the callback
11 | const linkStrategy = (contentBlock: ContentBlock, callback: Function): void => {
12 | const links = linkify.match(contentBlock.get('text'))
13 | if (typeof links !== 'undefined' && links !== null) {
14 | for (let i = 0; i < links.length; i += 1) {
15 | callback(links[i].index, links[i].lastIndex)
16 | }
17 | }
18 | }
19 |
20 | export default linkStrategy
21 |
--------------------------------------------------------------------------------
/examples/linkify-example/src/styles.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.8em;
4 | padding: 1em;
5 | background: #12312e;
6 | }
7 |
8 | .public-DraftEditor-content {
9 | padding: 2em;
10 | border-radius: 5px;
11 | color: #fff;
12 | border: #555;
13 | background: #244a46;
14 | }
15 |
16 |
17 | .link, .link:visited {
18 | color: #5e93c5;
19 | text-decoration: none;
20 | }
21 |
22 | .link:hover, .link:focus {
23 | color: #7eadda;
24 | outline: 0; /* reset for :focus */
25 | cursor: pointer;
26 | }
27 |
28 | .link:active {
29 | color: #4a7bab;
30 | }
31 |
--------------------------------------------------------------------------------
/examples/mentions-example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/mentions-example",
3 | "homepage": "https://github.com/draft-js-plugins/next#readme",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/autocomplete": "^0.1.5",
9 | "@djsp/core": "^0.1.5",
10 | "@djsp/utils": "^0.1.5",
11 | "prop-types": "^15.6.1",
12 | "react": "16.5.0",
13 | "react-dom": "16.5.0",
14 | "react-scripts": "^1.1.1"
15 | },
16 | "scripts": {
17 | "start": "react-scripts start",
18 | "build": "react-scripts build",
19 | "test": "react-scripts test --env=jsdom",
20 | "eject": "react-scripts eject"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/examples/mentions-example/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @djsp/mentions-example
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/mentions-example/src/index.js:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import React, { Component } from 'react'
4 | import ReactDOM from 'react-dom'
5 |
6 | import { EditorState, Modifier } from 'draft-js'
7 | import { EditorContainer, Editor, Plugin } from '@djsp/core'
8 | import Autocomplete from '@djsp/autocomplete'
9 | import { createEntityDecorator, insertTextWithEntity } from '@djsp/utils'
10 | import '@djsp/autocomplete/dist/index.css'
11 | import './styles.css'
12 |
13 | const Mention = (props: { children: React.Element }) => {
14 | return {props.children}
15 | }
16 |
17 | const MENTION = 'MENTION'
18 |
19 | const mentionDecorator = createEntityDecorator(MENTION, Mention)
20 |
21 | const suggestions = [
22 | {
23 | label: 'Julian Krispel-Samsel',
24 | value: 'julian',
25 | },
26 | {
27 | label: 'Nik Graf',
28 | value: 'nik',
29 | },
30 | ]
31 |
32 | class App extends Component {
33 | state = {
34 | editorState: EditorState.createEmpty(),
35 | suggestions: [],
36 | }
37 |
38 | setSuggestions = searchText => {
39 | console.log('set suggestions', searchText)
40 | this.setState({
41 | suggestions: suggestions.filter(item =>
42 | item.label.includes(searchText.slice(1))
43 | ),
44 | })
45 | }
46 |
47 | insertMention = (mention, searchText) => {
48 | const { editorState } = this.state
49 | const selection = editorState.getSelection()
50 |
51 | let content = Modifier.removeRange(
52 | editorState.getCurrentContent(),
53 | selection.merge({
54 | anchorOffset: selection.getAnchorOffset() - searchText.length,
55 | })
56 | )
57 |
58 | content = insertTextWithEntity(
59 | content,
60 | content.getSelectionAfter(),
61 | MENTION,
62 | mention.label,
63 | 'SEGMENTED',
64 | mention
65 | )
66 |
67 | // insert a space after
68 | content = Modifier.insertText(content, content.getSelectionAfter(), ' ')
69 |
70 | this.setState({
71 | editorState: EditorState.push(editorState, content, 'replace-fragment'),
72 | })
73 | }
74 |
75 | render() {
76 | return (
77 |
78 |
this.setState({ editorState })}>
81 | Hello
82 |
83 |
84 |
90 |
91 |
92 | )
93 | }
94 | }
95 |
96 | ReactDOM.render(, document.getElementById('root'))
97 |
--------------------------------------------------------------------------------
/examples/mentions-example/src/styles.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | }
4 |
5 | .mention {
6 | padding: .2em;
7 | border-radius: 3px;
8 | background: #000;
9 | color: #fff;
10 | }
11 |
--------------------------------------------------------------------------------
/examples/static-toolbar-example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/static-toolbar-example",
3 | "homepage": "https://github.com/draft-js-plugins/next#readme",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/block-type-toggle": "^0.1.5",
9 | "@djsp/core": "^0.1.5",
10 | "@djsp/inline-style-toggle": "^0.1.5",
11 | "draft-js": "^0.10.5",
12 | "prop-types": "^15.6.1",
13 | "react": "16.5.0",
14 | "react-dom": "16.5.0",
15 | "react-scripts": "^1.1.1",
16 | "styled-components": "^3.4.5"
17 | },
18 | "scripts": {
19 | "start": "react-scripts start",
20 | "build": "react-scripts build",
21 | "test": "react-scripts test --env=jsdom",
22 | "eject": "react-scripts eject"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/examples/static-toolbar-example/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @djsp/static-toolbar-example
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/static-toolbar-example/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "@djsp/core",
3 | "name": "@djsp/core",
4 | "start_url": "./index.html",
5 | "display": "standalone",
6 | "theme_color": "#000000",
7 | "background_color": "#ffffff"
8 | }
9 |
--------------------------------------------------------------------------------
/examples/static-toolbar-example/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-size: 1.8em;
5 | font-family: sans-serif;
6 | }
7 |
8 | .public-DraftEditor-content {
9 | padding: 1em 2em 2em;
10 | height: 100%;
11 | }
12 |
13 | .toolbar {
14 | padding: 2em 2em 0;
15 | }
16 |
17 | .toolbar__button {
18 | border: 1px solid #ccc;
19 | border-radius: 2px;
20 | cursor: pointer;
21 | background: none;
22 | }
23 |
24 | .toolbar__button--active {
25 | background: #000;
26 | color: #fff;
27 | }
28 |
29 | .container {
30 | position: fixed;
31 | width: 100%;
32 | height: 100%;
33 | top: 0;
34 | left: 0;
35 | display: flex;
36 | flex-direction: column;
37 | }
38 |
--------------------------------------------------------------------------------
/examples/static-toolbar-example/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom'
3 |
4 | import './index.css'
5 | import App from './App'
6 |
7 | ReactDOM.render(, document.getElementById('root'))
8 |
--------------------------------------------------------------------------------
/examples/undo-example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/undo-example",
3 | "homepage": "https://github.com/draft-js-plugins/next#readme",
4 | "version": "0.1.5",
5 | "private": true,
6 | "license": "MIT",
7 | "dependencies": {
8 | "@djsp/core": "^0.1.5",
9 | "react": "16.5.0",
10 | "react-dom": "16.5.0",
11 | "react-scripts": "^1.1.1"
12 | },
13 | "scripts": {
14 | "start": "react-scripts start",
15 | "build": "react-scripts build",
16 | "test": "react-scripts test --env=jsdom",
17 | "eject": "react-scripts eject"
18 | },
19 | "devDependencies": {
20 | "draft-js": "^0.10.5"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/examples/undo-example/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @djsp/undo-example
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/undo-example/src/Undo/components/Redo.js:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import React, { Component } from 'react'
4 | import { EditorState } from 'draft-js'
5 |
6 | type Props = {
7 | editorState: EditorState,
8 | setEditorState: EditorState => void,
9 | }
10 |
11 | class Redo extends Component {
12 | onClick = event => {
13 | event.stopPropagation()
14 | this.props.setEditorState(EditorState.redo(this.props.editorState))
15 | }
16 |
17 | render() {
18 | return (
19 |
28 | )
29 | }
30 | }
31 |
32 | export default Redo
33 |
--------------------------------------------------------------------------------
/examples/undo-example/src/Undo/components/Undo.js:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import React, { Component } from 'react'
4 | import { EditorState } from 'draft-js'
5 |
6 | type Props = {
7 | editorState: EditorState,
8 | setEditorState: EditorState => void,
9 | }
10 |
11 | class Undo extends Component {
12 | onClick = event => {
13 | event.stopPropagation()
14 | this.props.setEditorState(EditorState.undo(this.props.editorState))
15 | }
16 |
17 | render() {
18 | return (
19 |
28 | )
29 | }
30 | }
31 |
32 | export default Undo
33 |
--------------------------------------------------------------------------------
/examples/undo-example/src/Undo/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Plugin } from '@djsp/core'
3 | import Redo from './components/Redo'
4 | import Undo from './components/Undo'
5 |
6 | const RedoButton = () => (
7 |
8 | {({ editorState, setEditorState }) => (
9 |
10 | )}
11 |
12 | )
13 |
14 | const UndoButton = () => (
15 |
16 | {({ editorState, setEditorState }) => (
17 |
18 | )}
19 |
20 | )
21 |
22 | export { RedoButton, UndoButton }
23 |
--------------------------------------------------------------------------------
/examples/undo-example/src/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import ReactDOM from 'react-dom'
3 |
4 | import { EditorState, ContentState } from 'draft-js'
5 | import { EditorContainer, Editor } from '@djsp/core'
6 | import { RedoButton, UndoButton } from './Undo'
7 | import './styles.css'
8 |
9 | class App extends Component {
10 | state = {
11 | editorState: EditorState.createWithContent(
12 | ContentState.createFromText(
13 | 'Just type something and click the undo and redo button!'
14 | )
15 | ),
16 | }
17 |
18 | onChange = editorState => this.setState({ editorState })
19 |
20 | render() {
21 | return (
22 |
23 |
26 |
27 |
28 |
29 |
30 |
31 | )
32 | }
33 | }
34 |
35 | ReactDOM.render(, document.getElementById('root'))
36 |
--------------------------------------------------------------------------------
/examples/undo-example/src/styles.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | font-size: 1.8em;
4 | padding: 1em;
5 | background: #12312e;
6 | }
7 |
8 | .public-DraftEditor-content {
9 | padding: 2em;
10 | border-radius: 5px;
11 | color: #fff;
12 | border: #555;
13 | background: #244a46;
14 | }
15 |
--------------------------------------------------------------------------------
/lerna.json:
--------------------------------------------------------------------------------
1 | {
2 | "lerna": "2.11.0",
3 | "packages": [
4 | "examples/*",
5 | "packages/*"
6 | ],
7 | "version": "0.1.5"
8 | }
9 |
--------------------------------------------------------------------------------
/logo.sketch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/draft-js-plugins/next/f82f37fb33041e9326a1332ea104a2776257d732/logo.sketch
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "devDependencies": {
3 | "@babel/core": "^7.1.2",
4 | "@babel/plugin-proposal-class-properties": "^7.1.0",
5 | "@babel/plugin-proposal-export-default-from": "^7.0.0",
6 | "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
7 | "@babel/preset-env": "^7.1.0",
8 | "@babel/preset-flow": "^7.0.0",
9 | "@babel/preset-react": "^7.0.0",
10 | "@babel/register": "^7.0.0",
11 | "babel-eslint": "^10.0.1",
12 | "chai": "^4.2.0",
13 | "eslint": "^5.6.1",
14 | "eslint-config-prettier": "^3.1.0",
15 | "eslint-config-react": "^1.1.7",
16 | "eslint-config-standard": "^12.0.0",
17 | "eslint-config-standard-react": "^7.0.2",
18 | "eslint-plugin-flowtype": "^2.50.3",
19 | "eslint-plugin-import": "^2.14.0",
20 | "eslint-plugin-node": "^7.0.1",
21 | "eslint-plugin-prettier": "^3.0.0",
22 | "eslint-plugin-promise": "^4.0.1",
23 | "eslint-plugin-react": "^7.11.1",
24 | "eslint-plugin-standard": "^4.0.0",
25 | "fbjs": "^1.0.0",
26 | "flow-bin": "^0.80.0",
27 | "flow-typed": "^2.5.1",
28 | "husky": "^1.1.1",
29 | "lerna": "^3.4.1",
30 | "mocha": "^5.2.0",
31 | "prettier": "^1.14.3",
32 | "prettier-eslint": "^8.8.2",
33 | "prettier-eslint-cli": "^4.7.1",
34 | "to-fast-properties": "^2.0.0"
35 | },
36 | "scripts": {
37 | "test": "./node_modules/.bin/mocha --require @babel/register \"./packages/*/!(node_modules)/**/__test__/*.js\"",
38 | "eslint-check": "eslint --print-config . | eslint-config-prettier-check",
39 | "docs": "./node_modules/.bin/gitbook serve",
40 | "storybook": "start-storybook -p 9001 -c .storybook",
41 | "build": "./node_modules/.bin/lerna exec -- npm run build",
42 | "contributors": "./node_modules/.bin/all-contributors",
43 | "contributors:add": "./node_modules/.bin/all-contributors add",
44 | "contributors:generate": "./node_modules/.bin/all-contributors generate",
45 | "format": "./node_modules/.bin/prettier-eslint --write **/*.js",
46 | "lint": "./node_modules/.bin/eslint '**/*.js'",
47 | "reinstall": "./node_modules/.bin/lerna exec -- rm -rf ./node_modules && ./node_modules/.bin/lerna exec -- npm install",
48 | "publish:all": "node ./scripts/publish.js",
49 | "flow": "./node_modules/.bin/lerna run flow",
50 | "unlink": "./node_modules/.bin/lerna exec -- npm unlink"
51 | },
52 | "husky": {
53 | "hooks": {
54 | "pre-commit": "npm run format",
55 | "pre-push": "npm run lint && npm test && npm run flow"
56 | }
57 | },
58 | "dependencies": {}
59 | }
60 |
--------------------------------------------------------------------------------
/packages/atomic-block/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | .*/node_modules/draft-js
3 | .*/node_modules/@babel/.*
4 | .*/node_modules/@octokit/.*
5 | .*/node_modules/@types/.*
6 | .*/node_modules/\([a-c]\|[g-h]\|e\|[j-z]\).*/.*
7 | .*/core/src/.*
8 | .*/EditorContainer/.*
9 |
10 |
11 | [include]
12 | node_modules/react
13 |
14 | [libs]
15 | node_modules/@djsp/core/flow-lib
16 |
17 | [lints]
18 |
19 | [options]
20 |
21 | [strict]
22 |
23 | [version]
24 | ^0.81.0
25 |
--------------------------------------------------------------------------------
/packages/atomic-block/README.md:
--------------------------------------------------------------------------------
1 | # @djsp/atomic-block
2 |
3 | 
4 | [](https://www.npmjs.com/package/@djsp/atomic-block) [](https://standardjs.com)
5 |
6 | [Atomic blocks](https://draftjs.org/docs/advanced-topics-block-components#defining-custom-block-components) are draft-js's abstraction for displaying media that isn't text. Like images or embedded videos.
7 |
8 | The Atomic block plugin solves two common problems:
9 | - Focusing atomic blocks.
10 | - Keyboard interaction with atomic blocks.
11 |
12 | ## Installation
13 |
14 | ```sh
15 | npm install --save @djsp/utils @djsp/core @djsp/atomic-block
16 | # or alternately
17 | yarn add @djsp/utils @djsp/atomic-block
18 | ```
19 |
20 | ## Usage
21 |
22 | ```jsx
23 |
24 |
25 |
26 |
27 | {(props) => }
28 |
29 |
30 |
31 | {(props) => }
32 |
33 |
34 | ```
35 |
36 | ## API Props
37 |
38 | - `type` - A `string`. Entity type of the atomic block. e.g. `IMAGE`, `VIDEO`, `EMBED` or whatever you want to call your block type :)
39 | - `children` - Render Prop.
40 |
41 |
42 |
43 |
44 | ## Examples
45 | - [Editor with image](https://codesandbox.io/s/github/draft-js-plugins/next/tree/master/examples/atomic-block)
46 | - [Editor with divider](https://codesandbox.io/s/github/draft-js-plugins/next/tree/master/examples/divider-example)
--------------------------------------------------------------------------------
/packages/atomic-block/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/atomic-block",
3 | "version": "0.1.5",
4 | "description": "Plugin for atomic block",
5 | "author": "Julian Krispel",
6 | "license": "MIT",
7 | "repository": "draft-js-plugins/next/tree/master/packages/atomic-block",
8 | "main": "dist/index.js",
9 | "module": "dist/index.es.js",
10 | "jsnext:main": "dist/index.es.js",
11 | "scripts": {
12 | "test": "cross-env CI=1 react-scripts test --env=jsdom",
13 | "test:watch": "react-scripts test --env=jsdom",
14 | "build": "./node_modules/.bin/rollup -c",
15 | "start": "./node_modules/.bin/rollup -c -w",
16 | "prepare": "yarn run build",
17 | "flow": "./node_modules/.bin/flow",
18 | "predeploy": "cd example && yarn install && yarn run build",
19 | "deploy": "gh-pages -d example/build"
20 | },
21 | "publishConfig": {
22 | "access": "public"
23 | },
24 | "dependencies": {
25 | "@djsp/core": "^0.1.5",
26 | "@djsp/utils": "^0.1.5"
27 | },
28 | "peerDependencies": {
29 | "prop-types": "^15.5.4",
30 | "react": "16.5.0",
31 | "react-dom": "16.5.0"
32 | },
33 | "devDependencies": {
34 | "flow-bin": "^0.81.0",
35 | "flow-typed": "^2.5.1",
36 | "react": "16.5.0",
37 | "react-dom": "16.5.0",
38 | "react-scripts": "^1.1.1",
39 | "rollup": "^0.66.2",
40 | "rollup-plugin-babel": "^4.0.3",
41 | "rollup-plugin-commonjs": "^9.1.8",
42 | "rollup-plugin-node-resolve": "^3.4.0",
43 | "rollup-plugin-peer-deps-external": "^2.2.0",
44 | "rollup-plugin-postcss": "^1.6.2",
45 | "rollup-plugin-url": "^1.4.0"
46 | },
47 | "files": [
48 | "dist"
49 | ]
50 | }
51 |
--------------------------------------------------------------------------------
/packages/atomic-block/rollup.config.js:
--------------------------------------------------------------------------------
1 | import babel from 'rollup-plugin-babel'
2 | import commonjs from 'rollup-plugin-commonjs'
3 | import external from 'rollup-plugin-peer-deps-external'
4 | import postcss from 'rollup-plugin-postcss'
5 | import resolve from 'rollup-plugin-node-resolve'
6 | import url from 'rollup-plugin-url'
7 |
8 | import pkg from './package.json'
9 |
10 | export default {
11 | external: [
12 | '@djsp/core',
13 | '@djsp/utils',
14 | 'draft-js',
15 | 'draft-js/lib/DraftOffsetKey',
16 | 'react',
17 | ],
18 | input: 'src/index.js',
19 | output: [
20 | {
21 | file: pkg.main,
22 | format: 'cjs',
23 | },
24 | {
25 | file: pkg.module,
26 | format: 'es',
27 | },
28 | ],
29 | plugins: [
30 | external(),
31 | postcss({
32 | modules: true,
33 | extract: true,
34 | }),
35 | url(),
36 | babel({
37 | babelrc: false,
38 | configFile: '../../babel.config.js',
39 | exclude: 'node_modules/**',
40 | }),
41 | resolve(),
42 | commonjs(),
43 | ],
44 | }
45 |
--------------------------------------------------------------------------------
/packages/atomic-block/src/AtomicBlock.js:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import React, { Component } from 'react'
4 | import type { Node } from 'react'
5 |
6 | type Props = {
7 | onClick: (event: SyntheticMouseEvent<*>) => void,
8 | children: Node,
9 | }
10 |
11 | export default class AtomicBlock extends Component {
12 | render() {
13 | const { onClick, children } = this.props
14 |
15 | return {children}
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/packages/atomic-block/src/styles.css:
--------------------------------------------------------------------------------
1 | .focused {
2 | border: 2px solid blue;
3 | }
4 |
--------------------------------------------------------------------------------
/packages/autocomplete/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | .*/node_modules/draft-js
3 | .*/node_modules/@babel/.*
4 | .*/node_modules/@octokit/.*
5 | .*/node_modules/@types/.*
6 | .*/node_modules/\([a-c]\|[g-h]\|e\|[j-z]\).*/.*
7 |
8 |
9 | [include]
10 | node_modules/react
11 |
12 | [libs]
13 | node_modules/@djsp/core/flow-lib
14 |
15 | [lints]
16 |
17 | [options]
18 |
19 | [strict]
20 |
21 | [version]
22 | ^0.83.0
23 |
--------------------------------------------------------------------------------
/packages/autocomplete/README.md:
--------------------------------------------------------------------------------
1 | # @djsp/autocomplete - Not released, please use with caution ;)
2 |
3 | 
4 | [](https://www.npmjs.com/package/@djsp/suggestions) [](https://standardjs.com)
5 |
6 |
7 |
--------------------------------------------------------------------------------
/packages/autocomplete/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/autocomplete",
3 | "version": "0.1.5",
4 | "description": "Autocomplete plugin",
5 | "author": "juliankrispel",
6 | "license": "MIT",
7 | "repository": "draft-js-plugins/next/tree/master/packages/autocomplete",
8 | "main": "dist/index.js",
9 | "module": "dist/index.es.js",
10 | "jsnext:main": "dist/index.es.js",
11 | "scripts": {
12 | "test": "cross-env CI=1 react-scripts test --env=jsdom",
13 | "test:watch": "react-scripts test --env=jsdom",
14 | "build": "./node_modules/.bin/rollup -c",
15 | "flow": "./node_modules/.bin/flow",
16 | "start": "./node_modules/.bin/rollup -c -w",
17 | "prepare": "yarn run build",
18 | "predeploy": "cd example && yarn install && yarn run build",
19 | "deploy": "gh-pages -d example/build"
20 | },
21 | "publishConfig": {
22 | "access": "public"
23 | },
24 | "dependencies": {
25 | "@djsp/core": "^0.1.5"
26 | },
27 | "peerDependencies": {
28 | "prop-types": "^15.5.4",
29 | "react": "16.5.0",
30 | "react-dom": "16.5.0"
31 | },
32 | "devDependencies": {
33 | "cross-env": "^5.1.4",
34 | "flow-bin": "^0.83.0",
35 | "gh-pages": "^1.1.0",
36 | "react": "16.5.0",
37 | "react-dom": "16.5.0",
38 | "react-scripts": "^1.1.1",
39 | "rollup": "^0.54.0",
40 | "rollup-plugin-babel": "^4.0.3",
41 | "rollup-plugin-commonjs": "^8.2.1",
42 | "rollup-plugin-node-resolve": "^3.0.2",
43 | "rollup-plugin-peer-deps-external": "^2.0.0",
44 | "rollup-plugin-postcss": "^1.1.0",
45 | "rollup-plugin-url": "^1.3.0"
46 | },
47 | "files": [
48 | "dist"
49 | ]
50 | }
51 |
--------------------------------------------------------------------------------
/packages/autocomplete/rollup.config.js:
--------------------------------------------------------------------------------
1 | import babel from 'rollup-plugin-babel'
2 | import commonjs from 'rollup-plugin-commonjs'
3 | import external from 'rollup-plugin-peer-deps-external'
4 | import postcss from 'rollup-plugin-postcss'
5 | import resolve from 'rollup-plugin-node-resolve'
6 | import url from 'rollup-plugin-url'
7 |
8 | import pkg from './package.json'
9 |
10 | export default {
11 | external: ['@djsp/core', 'draft-js'],
12 | input: 'src/index.js',
13 | output: [
14 | {
15 | file: pkg.main,
16 | format: 'cjs',
17 | },
18 | {
19 | file: pkg.module,
20 | format: 'es',
21 | },
22 | ],
23 | plugins: [
24 | external(),
25 | postcss({
26 | modules: true,
27 | extract: true,
28 | }),
29 | url(),
30 | babel({
31 | babelrc: false,
32 | configFile: '../../babel.config.js',
33 | exclude: 'node_modules/**',
34 | }),
35 | resolve(),
36 | commonjs(),
37 | ],
38 | }
39 |
--------------------------------------------------------------------------------
/packages/autocomplete/src/styles.css:
--------------------------------------------------------------------------------
1 | .ul {
2 | list-style-type: none;
3 | margin: 0;
4 | padding: 0;
5 | }
6 |
7 | .li {
8 | padding: 0;
9 | list-style-type: none;
10 | }
11 |
12 | .suggestion {
13 | padding: 0 .5em;
14 | }
15 |
16 | .suggestionFocused {
17 | background: teal;
18 | }
19 |
--------------------------------------------------------------------------------
/packages/block-type-toggle/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | .*/node_modules/draft-js
3 | .*/node_modules/@babel/.*
4 | .*/node_modules/@octokit/.*
5 | .*/node_modules/@types/.*
6 | .*/node_modules/\([a-e]\|[g-z]\).*/.*
7 |
8 | [include]
9 | node_modules/react
10 |
11 | [libs]
12 | node_modules/@djsp/core/flow-lib
13 |
14 | [lints]
15 |
16 | [options]
17 |
18 | [strict]
19 |
20 | [version]
21 | ^0.83.0
22 |
--------------------------------------------------------------------------------
/packages/block-type-toggle/README.md:
--------------------------------------------------------------------------------
1 | # @djsp/buttons
2 |
3 | > Buttons for draft js plugins
4 |
5 | 
6 | [](https://www.npmjs.com/package/@djsp/buttons) [](https://standardjs.com)
7 |
8 | ## Install
9 |
10 | ```bash
11 | npm install --save @djsp/buttons
12 | ```
13 |
14 | ## Usage
15 |
16 | ```jsx
17 | import React, { Component } from 'react'
18 |
19 | import MyComponent from '@djsp/buttons'
20 |
21 | class Example extends Component {
22 | render () {
23 | return (
24 |
25 | )
26 | }
27 | }
28 | ```
29 |
30 | ## License
31 |
32 | MIT © [juliankrispel](https://github.com/juliankrispel)
33 |
--------------------------------------------------------------------------------
/packages/block-type-toggle/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@djsp/block-type-toggle",
3 | "version": "0.1.5",
4 | "description": "Block Type Toggle for draft js plugins",
5 | "author": "juliankrispel",
6 | "license": "MIT",
7 | "repository": "draft-js-plugins/next/tree/master/packages/block-type-toggle",
8 | "main": "dist/index.js",
9 | "module": "dist/index.es.js",
10 | "jsnext:main": "dist/index.es.js",
11 | "scripts": {
12 | "test": "cross-env CI=1 react-scripts test --env=jsdom",
13 | "test:watch": "react-scripts test --env=jsdom",
14 | "build": "./node_modules/.bin/rollup -c",
15 | "start": "./node_modules/.bin/rollup -c -w",
16 | "flow": "./node_modules/.bin/flow",
17 | "prepare": "yarn run build",
18 | "predeploy": "cd example && yarn install && yarn run build",
19 | "deploy": "gh-pages -d example/build"
20 | },
21 | "publishConfig": {
22 | "access": "public"
23 | },
24 | "dependencies": {
25 | "@djsp/core": "^0.1.5"
26 | },
27 | "peerDependencies": {
28 | "prop-types": "^15.5.4",
29 | "react": "16.5.0",
30 | "react-dom": "16.5.0"
31 | },
32 | "devDependencies": {
33 | "cross-env": "^5.1.4",
34 | "flow-bin": "^0.83.0",
35 | "gh-pages": "^1.1.0",
36 | "react": "^16.2.0",
37 | "react-dom": "^16.2.0",
38 | "react-scripts": "^1.1.1",
39 | "rollup": "^0.54.0",
40 | "rollup-plugin-babel": "^4.0.3",
41 | "rollup-plugin-commonjs": "^8.2.1",
42 | "rollup-plugin-node-resolve": "^3.0.2",
43 | "rollup-plugin-peer-deps-external": "^2.0.0",
44 | "rollup-plugin-postcss": "^1.1.0",
45 | "rollup-plugin-url": "^1.3.0"
46 | },
47 | "files": [
48 | "dist"
49 | ]
50 | }
51 |
--------------------------------------------------------------------------------
/packages/block-type-toggle/rollup.config.js:
--------------------------------------------------------------------------------
1 | import babel from 'rollup-plugin-babel'
2 | import commonjs from 'rollup-plugin-commonjs'
3 | import external from 'rollup-plugin-peer-deps-external'
4 | import postcss from 'rollup-plugin-postcss'
5 | import resolve from 'rollup-plugin-node-resolve'
6 | import url from 'rollup-plugin-url'
7 |
8 | import pkg from './package.json'
9 |
10 | export default {
11 | input: 'src/index.js',
12 | external: ['@djsp/core', 'draft-js'],
13 | output: [
14 | {
15 | file: pkg.main,
16 | format: 'cjs',
17 | },
18 | {
19 | file: pkg.module,
20 | format: 'es',
21 | },
22 | ],
23 | plugins: [
24 | external(),
25 | postcss({
26 | modules: true,
27 | }),
28 | url(),
29 | babel({
30 | babelrc: false,
31 | configFile: '../../babel.config.js',
32 | exclude: 'node_modules/**',
33 | }),
34 | resolve(),
35 | commonjs(),
36 | ],
37 | }
38 |
--------------------------------------------------------------------------------
/packages/block-type-toggle/src/index.js:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import { Component } from 'react'
4 | import { RichUtils } from 'draft-js'
5 | import { withPluginContext } from '@djsp/core'
6 | import type { PluginProps } from '@djsp/core'
7 |
8 | type BlockTypeRenderProps = {
9 | toggleBlockType: () => void,
10 | hasBlockType: boolean,
11 | }
12 |
13 | type BlockTypeProps = PluginProps & {
14 | children: BlockTypeRenderProps => React.Element,
15 | blockType: string,
16 | }
17 |
18 | class BlockTypeToggle extends Component {
19 | render() {
20 | const { setEditorState, editorState, blockType, children } = this.props
21 |
22 | const hasBlockType =
23 | editorState != null &&
24 | RichUtils.getCurrentBlockType(editorState) === blockType
25 |
26 | const toggleBlockType = () =>
27 | setEditorState(RichUtils.toggleBlockType(editorState, blockType))
28 |
29 | return children({ hasBlockType, toggleBlockType })
30 | }
31 | }
32 |
33 | export default withPluginContext(BlockTypeToggle)
34 |
--------------------------------------------------------------------------------
/packages/core/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | .*/node_modules/draft-js/lib.*
3 | .*/node_modules/@babel/.*
4 | .*/dist/.*
5 | .*/node_modules/@octokit/.*
6 | .*/node_modules/@types/.*
7 | .*/node_modules/\([a-c]\|[g-h]\|e\|[j-z]\).*/.*
8 |
9 | [include]
10 |
11 | [libs]
12 | flow-lib
13 |
14 | [lints]
15 |
16 | [options]
17 |
18 | [strict]
19 |
20 | [version]
21 | ^0.83.0
22 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/AtomicBlockUtils.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule AtomicBlockUtils
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict'
15 |
16 | import type { BlockNodeRecord } from './BlockNodeRecord'
17 | import type { DraftInsertionType } from './DraftInsertionType'
18 |
19 | import EditorState from './EditorState'
20 | import type SelectionState from './SelectionState'
21 |
22 | declare module 'draft-js/lib/AtomidBlockUtils' {
23 | declare export type AtomicBlockUtils = {
24 | insertAtomicBlock: (
25 | editorState: EditorState,
26 | entityKey: string,
27 | character: string
28 | ) => EditorState,
29 | moveAtomicBlock: (
30 | editorState: EditorState,
31 | atomicBlock: BlockNodeRecord,
32 | targetRange: SelectionState,
33 | insertionMode?: DraftInsertionType
34 | ) => EditorState,
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/BlockMap.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule BlockMap
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type { BlockNodeRecord } from './BlockNodeRecord';
17 | import type { OrderedMap } from 'immutable';
18 |
19 | declare module 'draft-js/lib/BlockMap' {
20 | declare export type BlockMap = OrderedMap;
21 | }
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/BlockMapBuilder.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule BlockMapBuilder
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type { BlockMap } from './BlockMap';
17 | import type { BlockNodeRecord } from './BlockNodeRecord';
18 |
19 | var Immutable = require('immutable');
20 |
21 | var { OrderedMap } = Immutable;
22 |
23 | declare module 'draft-js/lib/BlockMapBuilder' {
24 | declare type BlockMapBuilder = {
25 | createFromArray: (blocks: Array) => BlockMap
26 | }
27 |
28 | declare export default BlockMapBuilder;
29 | }
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/BlockNode.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule BlockNode
10 | * @format
11 | * @flow
12 | */
13 |
14 | import type CharacterMetadata from './CharacterMetadata'
15 | import type { DraftBlockType } from './DraftBlockType'
16 | import type { DraftInlineStyle } from './DraftInlineStyle'
17 | import type { List, Map } from 'immutable'
18 |
19 | declare module 'draft-js/lib/BlockNode' {
20 | declare export type BlockNodeKey = string
21 |
22 | declare export type BlockNodeConfig = {
23 | characterList?: List,
24 | data?: Map,
25 | depth?: number,
26 | key?: BlockNodeKey,
27 | text?: string,
28 | type?: DraftBlockType,
29 | }
30 |
31 | // https://github.com/facebook/draft-js/issues/1492
32 | // prettier-ignore
33 | declare export interface BlockNode {
34 | +findEntityRanges: (filterFn: (value: CharacterMetadata) => boolean, callback: (start: number, end: number) => void) => void;
35 |
36 | +findStyleRanges: (filterFn: (value: CharacterMetadata) => boolean, callback: (start: number, end: number) => void) => void;
37 |
38 | +getCharacterList: () => List;
39 |
40 | +getData: () => Map;
41 |
42 | +getDepth: () => number;
43 |
44 | +getEntityAt: (offset: number) => ?string;
45 |
46 | +getInlineStyleAt: (offset: number) => DraftInlineStyle;
47 |
48 | +getKey: () => BlockNodeKey;
49 |
50 | +getLength: () => number;
51 |
52 | +getText: () => string;
53 |
54 | +getType: () => DraftBlockType;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/BlockNodeRecord.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule BlockNodeRecord
10 | * @format
11 | * @flow
12 | */
13 |
14 | import type ContentBlock from './ContentBlock'
15 | import type ContentBlockNode from './ContentBlockNode'
16 |
17 | declare module 'draft-js/lib/BlockNodeRecord' {
18 | declare export type BlockNodeRecord = ContentBlock | ContentBlockNode
19 | }
20 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/BlockTree.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule BlockTree
10 | * @format
11 | * @flow
12 | */
13 |
14 | import type { BlockNodeRecord } from './BlockNodeRecord'
15 | import type ContentState from './ContentState'
16 | import type { DraftDecoratorType } from './DraftDecoratorType'
17 |
18 | declare module 'draft-js/lib/BlockTree' {
19 | declare type LeafRange = {
20 | start: ?number,
21 | end: ?number,
22 | }
23 |
24 | declare type DecoratorRange = {
25 | start: ?number,
26 | end: ?number,
27 | decoratorKey: ?string,
28 | leaves: ?List,
29 | }
30 |
31 | declare export type BlockTree = {
32 | generate: (
33 | contentState: ContentState,
34 | block: BlockNodeRecord,
35 | decorator: ?DraftDecoratorType
36 | ) => List,
37 | getFingerprint: (tree: List) => string,
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/CharacterMetadata.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule CharacterMetadata
10 | * @format
11 | * @flow
12 | */
13 |
14 | import type { DraftInlineStyle } from './DraftInlineStyle'
15 | import type { Record, OrderedSet } from 'immutable'
16 |
17 | declare module 'draft-js/lib/CharacterMetadata' {
18 | declare type CharacterMetadataConfigValueType = DraftInlineStyle | ?string
19 |
20 | declare type CharacterMetadataConfig = {
21 | style?: CharacterMetadataConfigValueType,
22 | entity?: CharacterMetadataConfigValueType,
23 | }
24 |
25 | declare export default class CharacterMetadata extends Record<{
26 | style: OrderedSet,
27 | entity: null,
28 | }> {
29 | getStyle(): DraftInlineStyle;
30 | getEntity(): ?string;
31 | hasStyle(style: string): boolean;
32 | static applyStyle(
33 | record: CharacterMetadata,
34 | style: string
35 | ): CharacterMetadata;
36 | static removeStyle(
37 | record: CharacterMetadata,
38 | style: string
39 | ): CharacterMetadata;
40 | static applyEntity(
41 | record: CharacterMetadata,
42 | entityKey: ?string
43 | ): CharacterMetadata;
44 | static create(config?: CharacterMetadataConfig): CharacterMetadata;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/ComposedEntityMutability.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule ComposedEntityMutability
10 | * @format
11 | * @flow
12 | */
13 |
14 | declare module 'draft-js/lib/ComposedEntityMutability' {
15 | declare type ComposedEntityMutability = {
16 | MUTABLE: boolean,
17 | IMMUTABLE: boolean,
18 | SEGMENTED: boolean,
19 | }
20 |
21 | declare export default ComposedEntityMutability
22 | }
23 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/CompositeDraftDecorator.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule CompositeDraftDecorator
10 | * @format
11 | * @flow
12 | */
13 |
14 | import type { BlockNodeRecord } from './BlockNodeRecord'
15 | import type ContentState from './ContentState'
16 | import type { DraftDecorator } from './DraftDecorator'
17 | import type { List } from 'immutable'
18 |
19 | declare module 'draft-js/lib/CompositeDraftDecorator' {
20 | declare export class CompositeDraftDecorator {
21 | _decorators: Array;
22 | constructor(decorators: Array): CompositeDraftDecorator;
23 | getDecorations(
24 | block: BlockNodeRecord,
25 | contentState: ContentState
26 | ): List;
27 | getComponentForKey(key: string): Function;
28 | getPropsForKey(key: string): ?Object;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/ContentBlock.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule ContentBlock
10 | * @format
11 | * @flow
12 | */
13 |
14 | import type { BlockNode, BlockNodeConfig, BlockNodeKey } from './BlockNode'
15 | import type { DraftBlockType } from './DraftBlockType'
16 | import type { DraftInlineStyle } from './DraftInlineStyle'
17 | import type { Record } from 'immutable'
18 |
19 | declare module 'draft-js/lib/CompositeDraftDecorator' {
20 | declare export default class ContentBlock extends Record
21 | implements BlockNode {
22 | getKey(): BlockNodeKey;
23 | getType(): DraftBlockType;
24 | getText(): string;
25 | getCharacterList(): List;
26 | getLength(): number;
27 | getDepth(): number;
28 | getData(): Map;
29 | getInlineStyleAt(offset: number): DraftInlineStyle;
30 | getEntityAt(offset: number): ?string;
31 | findStyleRanges(
32 | filterFn: (value: CharacterMetadata) => boolean,
33 | callback: (start: number, end: number) => void
34 | ): void;
35 | findEntityRanges(
36 | filterFn: (value: CharacterMetadata) => boolean,
37 | callback: (start: number, end: number) => void
38 | ): void;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/ContentState.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule ContentState
10 | * @format
11 | * @flow
12 | */
13 |
14 | import type { BlockMap } from './BlockMap'
15 | import type { BlockNodeRecord } from './BlockNodeRecord'
16 | import type DraftEntityInstance from './DraftEntityInstance'
17 | import type { DraftEntityMutability } from './DraftEntityMutability'
18 | import { Record } from 'immutable'
19 | import BlockMapBuilder from './BlockMapBuilder'
20 | import CharacterMetadata from './CharacterMetadata'
21 | import SelectionState from './Selection'
22 |
23 | declare module 'draft-js/lib/ContentState' {
24 | declare export default class ContentState extends Record<{
25 | entityMap: ?any,
26 | blockMap: ?BlockMap,
27 | selectionBefore: ?SelectionState,
28 | selectionAfter: ?SelectionState,
29 | }> {
30 | getEntityMap(): any;
31 | getBlockMap(): BlockMap;
32 | getSelectionBefore(): SelectionState;
33 | getSelectionAfter(): SelectionState;
34 | getBlockForKey(key: string): BlockNodeRecord;
35 | getKeyBefore(key: string): ?string;
36 | getKeyAfter(key: string): ?string;
37 | getBlockAfter(key: string): ?BlockNodeRecord;
38 | getBlockBefore(key: string): ?BlockNodeRecord;
39 | getBlocksAsArray(): Array;
40 | getFirstBlock(): BlockNodeRecord;
41 | getLastBlock(): BlockNodeRecord;
42 | getPlainText(delimiter?: string): string;
43 | getLastCreatedEntityKey(): ?string;
44 | hasText(): boolean;
45 | createEntity(
46 | type: string,
47 | mutability: DraftEntityMutability,
48 | data?: Object
49 | ): ContentState;
50 | mergeEntityData(key: string, toMerge: { [key: string]: any }): ContentState;
51 | replaceEntityData(
52 | key: string,
53 | newData: { [key: string]: any }
54 | ): ContentState;
55 | addEntity(instance: DraftEntityInstance): ContentState;
56 | getEntity(key: string): DraftEntityInstance;
57 | static createFromBlockArray(
58 | Array | { contentBlocks: Array },
59 | entityMap: ?any
60 | ): ContentState;
61 | static createFromText(
62 | text: string,
63 | delimiter: string | RegExp
64 | ): ContentState;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/ContentStateInlineStyle.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import type ContentState from './ContentState'
4 | import type SelectionState from './SelectionState'
5 |
6 | declare module 'draft-js/lib/ContentStateInlineStyle' {
7 | declare type ContentStateInlineStyle = {
8 | add: (
9 | contentState: ContentState,
10 | selectionState: SelectionState,
11 | inlineStyle: string
12 | ) => ContentState,
13 | remove: (
14 | contentState: ContentState,
15 | selectionState: SelectionState,
16 | inlineStyle: string
17 | ) => ContentState,
18 | }
19 |
20 | declare export default ContentStateInlineStyle
21 | }
22 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DOMDerivedSelection.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import type SelectionState from './SelectionState'
4 |
5 | declare module 'draft-js/lib/DOMDerivedSelection' {
6 | declare export type DOMDerivedSelection = {
7 | selectionState: SelectionState,
8 | needsRecovery: boolean,
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DefaultDraftBlockRenderMap.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import type { DraftBlockRenderConfig } from './DraftBlockRenderConfig'
4 | import type { CoreDraftBlockType } from './DraftBlockType'
5 |
6 | declare module 'draft-js/lib/DefaultDraftBlockRenderMap' {
7 | declare type DefaultDraftBlockRenderMap = Map<
8 | CoreDraftBlockType,
9 | DraftBlockRenderConfig
10 | >
11 | declare export default DefaultDraftBlockRenderMap
12 | }
13 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DefaultDraftInlineStyle.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DefaultDraftInlineStyle
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | export default {
17 | BOLD: {
18 | fontWeight: 'bold'
19 | },
20 |
21 | CODE: {
22 | fontFamily: 'monospace',
23 | wordWrap: 'break-word'
24 | },
25 |
26 | ITALIC: {
27 | fontStyle: 'italic'
28 | },
29 |
30 | STRIKETHROUGH: {
31 | textDecoration: 'line-through'
32 | },
33 |
34 | UNDERLINE: {
35 | textDecoration: 'underline'
36 | }
37 | };
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/Draft.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import React from 'react'
4 | import type KeyBindingUtil from './KeyBindingUtil'
5 | import AtomicBlockUtils from './AtomicBlockUtils'
6 | import BlockMapBuilder from './BlockMapBuilder'
7 | import CharacterMetadata from './CharacterMetadata'
8 | import CompositeDraftDecorator from './CompositeDraftDecorator'
9 | import ContentBlock from './ContentBlock'
10 | import ContentState from './ContentState'
11 | import DefaultDraftBlockRenderMap from './DefaultDraftBlockRenderMap'
12 | import DefaultDraftInlineStyle from './DefaultDraftInlineStyle'
13 | // import type DraftEditor from './DraftEditor.react'
14 | import DraftEditorProps from './DraftEditorProps'
15 | import DraftEditorBlock from './DraftEditorBlock.react'
16 | import DraftEntity from './DraftEntity'
17 | import DraftModifier from './DraftModifier'
18 | import DraftEntityInstance from './DraftEntityInstance'
19 | import EditorState from './EditorState'
20 |
21 | import RichTextEditorUtil from './RichTextEditorUtil'
22 | import SelectionState from './SelectionState'
23 |
24 | import convertFromDraftStateToRaw from './convertFromDraftStateToRaw'
25 | import convertFromHTMLToContentBlocks from './convertFromHTMLToContentBlocks'
26 | import convertFromRawToDraftState from './convertFromRawToDraftState'
27 | import generateRandomKey from './generateRandomKey'
28 | import getDefaultKeyBinding from './getDefaultKeyBinding'
29 | import getVisibleSelectionRect from './getVisibleSelectionRect'
30 |
31 | declare module 'draft-js' {
32 | declare module.exports: {
33 | Editor: React.Component<{ editorState: boolean }>,
34 | EditorBlock: DraftEditorBlock,
35 | EditorState: EditorState,
36 |
37 | CompositeDecorator: CompositeDraftDecorator,
38 | Entity: DraftEntity,
39 | EntityInstance: DraftEntityInstance,
40 |
41 | BlockMapBuilder: BlockMapBuilder,
42 | CharacterMetadata: CharacterMetadata,
43 | ContentBlock: ContentBlock,
44 | ContentState: ContentState,
45 | SelectionState: SelectionState,
46 |
47 | AtomicBlockUtils: AtomicBlockUtils,
48 | KeyBindingUtil: KeyBindingUtil,
49 | Modifier: DraftModifier,
50 | RichUtils: RichTextEditorUtil,
51 |
52 | DefaultDraftBlockRenderMap: DefaultDraftBlockRenderMap,
53 | DefaultDraftInlineStyle: DefaultDraftInlineStyle,
54 |
55 | convertFromHTML: convertFromHTMLToContentBlocks,
56 | convertFromRaw: convertFromRawToDraftState,
57 | convertToRaw: convertFromDraftStateToRaw,
58 | genKey: generateRandomKey,
59 | getDefaultKeyBinding: getDefaultKeyBinding,
60 | getVisibleSelectionRect: getVisibleSelectionRect,
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftBlockRenderConfig.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftBlockRenderConfig
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | export type DraftBlockRenderConfig = {
17 | element: string;
18 | wrapper?: React$Element;
19 | aliasedElements?: Array;
20 | };
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftBlockRenderMap.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import type { DraftBlockRenderConfig } from './DraftBlockRenderConfig'
4 | import type { Map } from 'immutable'
5 |
6 | declare module 'draft-js/lib/DraftBlockRenderMap' {
7 | declare export type DraftBlockRenderMap = Map
8 | }
9 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftBlockType.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | declare module 'draft-js/lib/DraftBlockType' {
4 | declare export type CoreDraftBlockType =
5 | | 'unstyled'
6 | | 'paragraph'
7 | | 'header-one'
8 | | 'header-two'
9 | | 'header-three'
10 | | 'header-four'
11 | | 'header-five'
12 | | 'header-six'
13 | | 'unordered-list-item'
14 | | 'ordered-list-item'
15 | | 'blockquote'
16 | | 'code-block'
17 | | 'atomic'
18 | declare export type CustomBlockType = string
19 | declare export type DraftBlockType = CoreDraftBlockType | CustomBlockType
20 | }
21 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftDecorator.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import type { BlockNodeRecord } from './BlockNodeRecord'
4 | import type ContentState from './ContentState'
5 |
6 | declare module 'draft-js/lib/DraftDecorator' {
7 | declare export type DraftDecoratorStrategy = (
8 | block: BlockNodeRecord,
9 | callback: (start: number, end: number) => void,
10 | contentState: ContentState
11 | ) => void
12 |
13 | declare export type DraftDecorator = {
14 | strategy: DraftDecoratorStrategy,
15 | component: Function,
16 | props?: Object,
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftDecoratorType.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import type { BlockNodeRecord } from './BlockNodeRecord'
4 | import type ContentState from './ContentState'
5 | import type { List } from 'immutable'
6 |
7 | declare module 'draft-js/lib/DraftDecoratorType' {
8 | declare export type DraftDecoratorType = {
9 | getDecorations: (
10 | block: BlockNodeRecord,
11 | contentState: ContentState
12 | ) => List,
13 | getComponentForKey: (key: string) => Function,
14 | getPropsForKey: (key: string) => ?Object,
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftDragType.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | declare module 'draft-js/lib/DraftDragType' {
4 | declare export type DraftDragType = 'internal' | 'external'
5 | }
6 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftEditor.react.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import type { DraftEditorProps } from 'draft-js/lib/DraftEditorProps'
4 |
5 | declare module 'draft-js/lib/DraftEditor.react' {
6 | declare export default class DraftEditor extends React$Component<
7 | DraftEditorProps
8 | > {}
9 | }
10 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftEditorCommand.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | declare module 'draft-js/lib/DraftEditorCommand' {
4 | declare export type DraftEditorCommand =
5 | | 'undo'
6 | | 'redo'
7 | | 'delete'
8 | | 'delete-word'
9 | | 'backspace'
10 | | 'backspace-word'
11 | | 'backspace-to-start-of-line'
12 | | 'bold'
13 | | 'italic'
14 | | 'underline'
15 | | 'code'
16 | | 'split-block'
17 | | 'transpose-characters'
18 | | 'move-selection-to-start-of-block'
19 | | 'move-selection-to-end-of-block'
20 | | 'secondary-cut'
21 | | 'secondary-paste'
22 | }
23 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftEditorContents.react.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftEditorContents.react
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | const DraftEditorContents = require('./DraftEditorContents-core.react');
17 |
18 | export default DraftEditorContents;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftEditorDecoratedLeaves.react.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftEditorDecoratedLeaves.react
10 | * @format
11 | * @flow
12 | *
13 | * This is unstable and not part of the public API and should not be used by
14 | * production systems. This file may be update/removed without notice.
15 | */
16 |
17 | 'use strict';
18 |
19 | import type { BlockNodeRecord } from './BlockNodeRecord';
20 | import type ContentState from './ContentState';
21 | import type { DraftDecoratorType } from './DraftDecoratorType';
22 | import type { BidiDirection } from 'fbjs/lib/UnicodeBidiDirection';
23 | import type { Set } from 'immutable';
24 |
25 | const DraftOffsetKey = require('./DraftOffsetKey');
26 | const React = require('react');
27 | const UnicodeBidi = require('fbjs/lib/UnicodeBidi');
28 | const UnicodeBidiDirection = require('fbjs/lib/UnicodeBidiDirection');
29 |
30 | type Props = {
31 | block: BlockNodeRecord;
32 | children: ?Array;
33 | contentState: ContentState;
34 | decorator: DraftDecoratorType;
35 | decoratorKey: string;
36 | direction: BidiDirection;
37 | text: string;
38 | leafSet: Set;
39 | };
40 |
41 | class DraftEditorDecoratedLeaves extends React.Component {
42 | render(): React.Node {
43 | const {
44 | block,
45 | children,
46 | contentState,
47 | decorator,
48 | decoratorKey,
49 | direction,
50 | leafSet,
51 | text
52 | } = this.props;
53 |
54 | const blockKey = block.getKey();
55 | const leavesForLeafSet = leafSet.get('leaves');
56 | const DecoratorComponent = decorator.getComponentForKey(decoratorKey);
57 | const decoratorProps = decorator.getPropsForKey(decoratorKey);
58 | const decoratorOffsetKey = DraftOffsetKey.encode(blockKey, parseInt(decoratorKey, 10), 0);
59 |
60 | const decoratedText = text.slice(leavesForLeafSet.first().get('start'), leavesForLeafSet.last().get('end'));
61 |
62 | // Resetting dir to the same value on a child node makes Chrome/Firefox
63 | // confused on cursor movement. See http://jsfiddle.net/d157kLck/3/
64 | const dir = UnicodeBidiDirection.getHTMLDirIfDifferent(UnicodeBidi.getDirection(decoratedText), direction);
65 |
66 | return
67 | {children}
68 | ;
69 | }
70 | }
71 |
72 | export default DraftEditorDecoratedLeaves;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftEditorEditHandler.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftEditorEditHandler
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | const onBeforeInput = require('./editOnBeforeInput');
17 | const onBlur = require('./editOnBlur');
18 | const onCompositionStart = require('./editOnCompositionStart');
19 | const onCopy = require('./editOnCopy');
20 | const onCut = require('./editOnCut');
21 | const onDragOver = require('./editOnDragOver');
22 | const onDragStart = require('./editOnDragStart');
23 | const onFocus = require('./editOnFocus');
24 | const onInput = require('./editOnInput');
25 | const onKeyDown = require('./editOnKeyDown');
26 | const onPaste = require('./editOnPaste');
27 | const onSelect = require('./editOnSelect');
28 |
29 | const DraftEditorEditHandler = {
30 | onBeforeInput,
31 | onBlur,
32 | onCompositionStart,
33 | onCopy,
34 | onCut,
35 | onDragOver,
36 | onDragStart,
37 | onFocus,
38 | onInput,
39 | onKeyDown,
40 | onPaste,
41 | onSelect
42 | };
43 |
44 | export default DraftEditorEditHandler;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftEditorModes.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftEditorModes
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | export type DraftEditorModes =
17 | /**
18 | * `edit` is the most common mode for text entry. This includes most typing,
19 | * deletion, cut/copy/paste, and other behaviors.
20 | */
21 | 'edit'
22 |
23 | /**
24 | * `composite` mode handles IME text entry.
25 | */
26 | | 'composite'
27 |
28 | /**
29 | * `drag` mode handles editor behavior while a drag event is occurring.
30 | */
31 | | 'drag'
32 |
33 | /**
34 | * `cut` mode allows us to effectively ignore all edit behaviors while the`
35 | * browser performs a native `cut` operation on the DOM.
36 | */
37 | | 'cut'
38 |
39 | /**
40 | * `render` mode is the normal "null" mode, during which no edit behavior is
41 | * expected or observed.
42 | */
43 | | 'render';
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftEditorPlaceholder.react.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftEditorPlaceholder.react
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type { DraftTextAlignment } from './DraftTextAlignment';
17 | import type EditorState from './EditorState';
18 |
19 | const React = require('react');
20 |
21 | const cx = require('fbjs/lib/cx');
22 |
23 | type Props = {
24 | accessibilityID: string;
25 | editorState: EditorState;
26 | text: string;
27 | textAlignment: DraftTextAlignment;
28 | };
29 |
30 | /**
31 | * This component is responsible for rendering placeholder text for the
32 | * `DraftEditor` component.
33 | *
34 | * Override placeholder style via CSS.
35 | */
36 | class DraftEditorPlaceholder extends React.Component {
37 | shouldComponentUpdate(nextProps: Props): boolean {
38 | return this.props.text !== nextProps.text || this.props.editorState.getSelection().getHasFocus() !== nextProps.editorState.getSelection().getHasFocus();
39 | }
40 |
41 | render(): React.Node {
42 | const hasFocus = this.props.editorState.getSelection().getHasFocus();
43 |
44 | const className = cx({
45 | 'public/DraftEditorPlaceholder/root': true,
46 | 'public/DraftEditorPlaceholder/hasFocus': hasFocus
47 | });
48 |
49 | const contentStyle = {
50 | whiteSpace: 'pre-wrap'
51 | };
52 |
53 | return
54 |
55 | {this.props.text}
56 |
57 |
;
58 | }
59 | }
60 |
61 | export default DraftEditorPlaceholder;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftEntityInstance.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 | import type { DraftEntityMutability } from './DraftEntityMutability'
3 | import type { DraftEntityType } from './DraftEntityType'
4 |
5 | declare module 'draft-js/lib/DraftEntityInstance' {
6 | declare export default class DraftEntityInstance {
7 | getType(): DraftEntityType;
8 | getMutability(): DraftEntityMutability;
9 | getData(): Object;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftEntityMutability.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftEntityMutability
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | var ComposedEntityMutability = require('./ComposedEntityMutability');
17 |
18 | /**
19 | * An enum representing the possible "mutability" options for an entity.
20 | * This refers to the behavior that should occur when inserting or removing
21 | * characters in a text range with an entity applied to it.
22 | *
23 | * `MUTABLE`:
24 | * The text range can be modified freely. Generally used in cases where
25 | * the text content and the entity do not necessarily have a direct
26 | * relationship. For instance, the text and URI for a link may be completely
27 | * different. The user is allowed to edit the text as needed, and the entity
28 | * is preserved and applied to any characters added within the range.
29 | *
30 | * `IMMUTABLE`:
31 | * Not to be confused with immutable data structures used to represent the
32 | * state of the editor. Immutable entity ranges cannot be modified in any
33 | * way. Adding characters within the range will remove the entity from the
34 | * entire range. Deleting characters will delete the entire range. Example:
35 | * Facebook Page mentions.
36 | *
37 | * `SEGMENTED`:
38 | * Segmented entities allow the removal of partial ranges of text, as
39 | * separated by a delimiter. Adding characters within the range will remove
40 | * the entity from the entire range. Deleting characters within a segmented
41 | * entity will delete only the segments affected by the deletion. Example:
42 | * Facebook User mentions.
43 | */
44 |
45 | export type DraftEntityMutability = $Keys;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftEntityType.js.flow:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/draft-js-plugins/next/f82f37fb33041e9326a1332ea104a2776257d732/packages/core/flow-lib/draft-js/DraftEntityType.js.flow
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftFeatureFlags-core.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftFeatureFlags-core
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | var DraftFeatureFlags = {
17 | draft_killswitch_allow_nontextnodes: false,
18 | draft_segmented_entities_behavior: false,
19 | draft_handlebeforeinput_composed_text: false,
20 | draft_tree_data_support: false
21 | };
22 |
23 | export default DraftFeatureFlags;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftFeatureFlags.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftFeatureFlags
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | var DraftFeatureFlags = require('./DraftFeatureFlags-core');
17 |
18 | export default DraftFeatureFlags;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftHandleValue.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | declare module 'draft-js/lib/DraftHandleValue' {
4 | declare export type DraftHandleValue = 'handled' | 'not-handled'
5 | }
6 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftInlineStyle.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftInlineStyle
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type Immutable from 'immutable';
17 |
18 | export type DraftInlineStyle = Immutable.OrderedSet;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftInsertionType.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftInsertionType
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | /**
17 | * A type that defines if an fragment shall be inserted before or after
18 | * another fragment or if the selected fragment shall be replaced
19 | */
20 |
21 | export type DraftInsertionType = 'replace' | 'before' | 'after';
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftJsDebugLogging.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftJsDebugLogging
10 | */
11 |
12 | 'use strict';
13 |
14 | export default {
15 | logSelectionStateFailure: () => null
16 | };
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftODS.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftODS
10 | */
11 |
12 | 'use strict';
13 |
14 | export default {
15 | init: function init() {}
16 | };
17 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftOffsetKey.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftOffsetKey
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type { DraftOffsetKeyPath } from './DraftOffsetKeyPath';
17 |
18 | var KEY_DELIMITER = '-';
19 |
20 | var DraftOffsetKey = {
21 | encode: function (blockKey: string, decoratorKey: number, leafKey: number): string {
22 | return blockKey + KEY_DELIMITER + decoratorKey + KEY_DELIMITER + leafKey;
23 | },
24 |
25 | decode: function (offsetKey: string): DraftOffsetKeyPath {
26 | var [blockKey, decoratorKey, leafKey] = offsetKey.split(KEY_DELIMITER);
27 | return {
28 | blockKey,
29 | decoratorKey: parseInt(decoratorKey, 10),
30 | leafKey: parseInt(leafKey, 10)
31 | };
32 | }
33 | };
34 |
35 |
36 | declare module 'draft-js/lib/DraftOffsetKey' {
37 | declare type DraftOffsetKey = {
38 | encode: (
39 | blockKey: string,
40 | decoratorKey: number,
41 | leafKey: number
42 | ) => string,
43 | decode: (offsetKey: string) => DraftOffsetKeyPath,
44 | }
45 |
46 | declare export default DraftOffsetKey
47 | }
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftOffsetKeyPath.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftOffsetKeyPath
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | export type DraftOffsetKeyPath = {
17 | blockKey: string;
18 | decoratorKey: number;
19 | leafKey: number;
20 | };
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftRange.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 | declare module 'draft-js/lib/DraftRange' {
3 | declare export type DraftRange = {
4 | start: number,
5 | end: number,
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftRemovableWord.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftRemovableWord
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | var TokenizeUtil = require('fbjs/lib/TokenizeUtil');
17 |
18 | var punctuation = TokenizeUtil.getPunctuation();
19 |
20 | // The apostrophe and curly single quotes behave in a curious way: when
21 | // surrounded on both sides by word characters, they behave as word chars; when
22 | // either neighbor is punctuation or an end of the string, they behave as
23 | // punctuation.
24 | var CHAMELEON_CHARS = "['\u2018\u2019]";
25 |
26 | // Remove the underscore, which should count as part of the removable word. The
27 | // "chameleon chars" also count as punctuation in this regex.
28 | var WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation;
29 |
30 | var DELETE_STRING = '^' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)';
31 | var DELETE_REGEX = new RegExp(DELETE_STRING);
32 |
33 | var BACKSPACE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '$';
34 | var BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING);
35 |
36 | function getRemovableWord(text: string, isBackward: boolean): string {
37 | var matches = isBackward ? BACKSPACE_REGEX.exec(text) : DELETE_REGEX.exec(text);
38 | return matches ? matches[0] : text;
39 | }
40 |
41 | var DraftRemovableWord = {
42 | getBackward: function (text: string): string {
43 | return getRemovableWord(text, true);
44 | },
45 |
46 | getForward: function (text: string): string {
47 | return getRemovableWord(text, false);
48 | }
49 | };
50 |
51 | export default DraftRemovableWord;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftRemovalDirection.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftRemovalDirection
10 | * @format
11 | * @flow
12 | */
13 |
14 | /*eslint-disable no-bitwise*/
15 |
16 | 'use strict';
17 |
18 | /**
19 | * A type that allows us to avoid passing boolean arguments
20 | * around to indicate whether a deletion is forward or backward.
21 | */
22 |
23 | export type DraftRemovalDirection = 'backward' | 'forward';
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftScrollPosition.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftScrollPosition
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | export type DraftScrollPosition = {
17 | x: number;
18 | y: number;
19 | };
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftStringKey.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftStringKey
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | var DraftStringKey = {
17 | stringify: function (key: mixed): string {
18 | return '_' + String(key);
19 | },
20 |
21 | unstringify: function (key: string): string {
22 | return key.slice(1);
23 | }
24 | };
25 |
26 | export default DraftStringKey;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/DraftTextAlignment.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule DraftTextAlignment
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | declare module 'draft-js/lib/DraftTextAlignment' {
17 | declare export type DraftTextAlignment = 'left' | 'center' | 'right';
18 | }
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/EditorBidiService.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule EditorBidiService
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type ContentState from './ContentState';
17 |
18 | var Immutable = require('immutable');
19 | var UnicodeBidiService = require('fbjs/lib/UnicodeBidiService');
20 |
21 | var nullthrows = require('fbjs/lib/nullthrows');
22 |
23 | var { OrderedMap } = Immutable;
24 |
25 | var bidiService;
26 |
27 | var EditorBidiService = {
28 | getDirectionMap: function (content: ContentState, prevBidiMap: ?OrderedMap): OrderedMap {
29 | if (!bidiService) {
30 | bidiService = new UnicodeBidiService();
31 | } else {
32 | bidiService.reset();
33 | }
34 |
35 | var blockMap = content.getBlockMap();
36 | var nextBidi = blockMap.valueSeq().map(block => nullthrows(bidiService).getDirection(block.getText()));
37 | var bidiMap = OrderedMap(blockMap.keySeq().zip(nextBidi));
38 |
39 | if (prevBidiMap != null && Immutable.is(prevBidiMap, bidiMap)) {
40 | return prevBidiMap;
41 | }
42 |
43 | return bidiMap;
44 | }
45 | };
46 |
47 | export default EditorBidiService;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/EditorChangeType.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule EditorChangeType
10 | * @format
11 | * @flow
12 | */
13 |
14 | /*eslint-disable no-bitwise*/
15 |
16 | 'use strict';
17 |
18 | export type EditorChangeType = 'adjust-depth' | 'apply-entity' | 'backspace-character' | 'change-block-data' | 'change-block-type' | 'change-inline-style' | 'move-block' | 'delete-character' | 'insert-characters' | 'insert-fragment' | 'redo' | 'remove-range' | 'spellcheck-change' | 'split-block' | 'undo';
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/EditorStateCreationConfig.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule EditorStateCreationConfig
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type ContentState from './ContentState';
17 | import type { DraftDecoratorType } from './DraftDecoratorType';
18 | import type SelectionState from './SelectionState';
19 |
20 | export type EditorStateCreationConfig = {
21 | allowUndo: boolean;
22 | currentContent: ContentState;
23 | decorator: ?DraftDecoratorType;
24 | selection: SelectionState;
25 | };
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/EntityMap.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule EntityMap
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type { DraftEntityMapObject } from './DraftEntity';
17 |
18 | // TODO: when removing the deprecated Entity api
19 | // change this to be
20 | // OrderedMap;
21 | export type EntityMap = DraftEntityMapObject;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/EntityRange.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule EntityRange
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | /**
17 | * A plain object representation of an entity attribution.
18 | *
19 | * The `key` value corresponds to the key of the entity in the `entityMap` of
20 | * a `ComposedText` object, not for use with `DraftEntity.get()`.
21 | */
22 |
23 | export type EntityRange = {
24 | key: number;
25 | offset: number;
26 | length: number;
27 | };
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/InlineStyleRange.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule InlineStyleRange
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | /**
17 | * A plain object representation of an inline style range.
18 | */
19 |
20 | export type InlineStyleRange = {
21 | style: string;
22 | offset: number;
23 | length: number;
24 | };
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/KeyBindingUtil.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | declare module 'draft-js/lib/KeyBindingUtil' {
4 | declare type KeyBindingUtil = {
5 | isCtrlKeyCommand: (e: SyntheticKeyboardEvent<>) => boolean,
6 | isOptionKeyCommand: (e: SyntheticKeyboardEvent<>) => boolean,
7 | hasCommandModifier: (e: SyntheticKeyboardEvent<>) => boolean,
8 | }
9 |
10 | declare export default KeyBindingUtil
11 | }
12 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/RawDraftContentBlock.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule RawDraftContentBlock
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type { DraftBlockType } from './DraftBlockType';
17 | import type { EntityRange } from './EntityRange';
18 | import type { InlineStyleRange } from './InlineStyleRange';
19 |
20 | /**
21 | * A plain object representation of a ContentBlock, with all style and entity
22 | * attribution repackaged as range objects.
23 | */
24 | export type RawDraftContentBlock = {
25 | key: ?string;
26 | type: DraftBlockType;
27 | text: string;
28 | depth: ?number;
29 | inlineStyleRanges: ?Array;
30 | entityRanges: ?Array;
31 | data?: Object;
32 | children?: Array;
33 | };
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/RawDraftContentState.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule RawDraftContentState
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type { RawDraftContentBlock } from './RawDraftContentBlock';
17 | import type { RawDraftEntity } from './RawDraftEntity';
18 |
19 | /**
20 | * A type that represents a composed document as vanilla JavaScript objects,
21 | * with all styles and entities represented as ranges. Corresponding entity
22 | * objects are packaged as objects as well.
23 | *
24 | * This object is especially useful when sending the document state to the
25 | * server for storage, as its representation is more concise than our
26 | * immutable objects.
27 | */
28 | export type RawDraftContentState = {
29 | blocks: Array;
30 | entityMap: { [key: string]: RawDraftEntity };
31 | };
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/RawDraftEntity.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule RawDraftEntity
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type { DraftEntityMutability } from './DraftEntityMutability';
17 | import type { DraftEntityType } from './DraftEntityType';
18 |
19 | /**
20 | * A plain object representation of an EntityInstance.
21 | */
22 | export type RawDraftEntity = {
23 | type: DraftEntityType;
24 | mutability: DraftEntityMutability;
25 | data: ?{ [key: string]: any };
26 | };
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/RichTextEditorUtil.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import type ContentState from './ContentState'
4 | import type { DraftBlockType } from './DraftBlockType'
5 | import type { DraftEditorCommand } from './DraftEditorCommand'
6 | import type URI from 'fbjs/lib/URI'
7 |
8 | type RichTextEditorUtil = {
9 | currentBlockContainsLink: (editorState: EditorState) => boolean,
10 | getCurrentBlockType: (editorState: EditorState) => DraftBlockType,
11 | getDataObjectForLinkURL: (uri: URI) => Object,
12 | handleKeyCommand: (
13 | editorState: EditorState,
14 | command: DraftEditorCommand | string
15 | ) => ?EditorState,
16 | insertSoftNewline: (editorState: EditorState) => EditorState,
17 | onBackspace: (editorState: EditorState) => ?EditorState,
18 | onDelete: (editorState: EditorState) => ?EditorState,
19 | onTab: (
20 | event: SyntheticKeyboardEvent<>,
21 | editorState: EditorState,
22 | maxDepth: number
23 | ) => EditorState,
24 | toggleBlockType: (
25 | editorState: EditorState,
26 | blockType: DraftBlockType
27 | ) => EditorState,
28 | toggleCode: (editorState: EditorState) => EditorState,
29 | toggleInlineStyle: (
30 | editorState: EditorState,
31 | inlineStyle: string
32 | ) => EditorState,
33 | toggleLink: (
34 | editorState: EditorState,
35 | targetSelection: SelectionState,
36 | entityKey: ?string
37 | ) => EditorState,
38 | tryToRemoveBlockStyle: (editorState: EditorState) => ?ContentState,
39 | }
40 |
41 | declare module 'draft-js/lib/RichTextEditorUtil' {
42 | declare export default RichTextEditorUtil
43 | }
44 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/SampleDraftInlineStyle.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule SampleDraftInlineStyle
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | const { OrderedSet } = require('immutable');
17 |
18 | export default {
19 | BOLD: OrderedSet.of('BOLD'),
20 | BOLD_ITALIC: OrderedSet.of('BOLD', 'ITALIC'),
21 | BOLD_ITALIC_UNDERLINE: OrderedSet.of('BOLD', 'ITALIC', 'UNDERLINE'),
22 | BOLD_UNDERLINE: OrderedSet.of('BOLD', 'UNDERLINE'),
23 | CODE: OrderedSet.of('CODE'),
24 | ITALIC: OrderedSet.of('ITALIC'),
25 | ITALIC_UNDERLINE: OrderedSet.of('ITALIC', 'UNDERLINE'),
26 | NONE: OrderedSet(),
27 | STRIKETHROUGH: OrderedSet.of('STRIKETHROUGH'),
28 | UNDERLINE: OrderedSet.of('UNDERLINE')
29 | };
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/SecondaryClipboard.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule SecondaryClipboard
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type { BlockMap } from './BlockMap';
17 | import type SelectionState from './SelectionState';
18 |
19 | var DraftModifier = require('./DraftModifier');
20 | var EditorState = require('./EditorState');
21 |
22 | var getContentStateFragment = require('./getContentStateFragment');
23 | var nullthrows = require('fbjs/lib/nullthrows');
24 |
25 | var clipboard: ?BlockMap = null;
26 |
27 | /**
28 | * Some systems offer a "secondary" clipboard to allow quick internal cut
29 | * and paste behavior. For instance, Ctrl+K (cut) and Ctrl+Y (paste).
30 | */
31 | var SecondaryClipboard = {
32 | cut: function (editorState: EditorState): EditorState {
33 | var content = editorState.getCurrentContent();
34 | var selection = editorState.getSelection();
35 | var targetRange: ?SelectionState = null;
36 |
37 | if (selection.isCollapsed()) {
38 | var anchorKey = selection.getAnchorKey();
39 | var blockEnd = content.getBlockForKey(anchorKey).getLength();
40 |
41 | if (blockEnd === selection.getAnchorOffset()) {
42 | return editorState;
43 | }
44 |
45 | targetRange = selection.set('focusOffset', blockEnd);
46 | } else {
47 | targetRange = selection;
48 | }
49 |
50 | targetRange = nullthrows(targetRange);
51 | clipboard = getContentStateFragment(content, targetRange);
52 |
53 | var afterRemoval = DraftModifier.removeRange(content, targetRange, 'forward');
54 |
55 | if (afterRemoval === content) {
56 | return editorState;
57 | }
58 |
59 | return EditorState.push(editorState, afterRemoval, 'remove-range');
60 | },
61 |
62 | paste: function (editorState: EditorState): EditorState {
63 | if (!clipboard) {
64 | return editorState;
65 | }
66 |
67 | var newContent = DraftModifier.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), clipboard);
68 |
69 | return EditorState.push(editorState, newContent, 'insert-fragment');
70 | }
71 | };
72 |
73 | export default SecondaryClipboard;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/SelectionState.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import { Record } from 'immutable'
4 |
5 | declare module 'draft-js/lib/SelectionState' {
6 | declare export default class SelectionState extends Record<{
7 | anchorKey: string,
8 | anchorOffset: number,
9 | focusKey: string,
10 | focusOffset: number,
11 | isBackward: boolean,
12 | hasFocus: boolean,
13 | }> {
14 | serialize(): string;
15 | getAnchorKey(): string;
16 | getAnchorOffset(): number;
17 | getFocusKey(): string;
18 | getFocusOffset(): number;
19 | getIsBackward(): boolean;
20 | getHasFocus(): boolean;
21 | hasEdgeWithin(blockKey: string, start: number, end: number): boolean;
22 | isCollapsed(): boolean;
23 | getStartKey(): string;
24 | getStartOffset(): number;
25 | getEndKey(): string;
26 | getEndOffset(): number;
27 | static createEmpty(key: string): SelectionState;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/_DraftTestHelper.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule _DraftTestHelper
10 | * @flow
11 | * @format
12 | */
13 |
14 | const BLACK_LIST_PROPS = ['data-reactroot'];
15 | const transformSnapshotProps = (node: any, blackList: Array = BLACK_LIST_PROPS) => {
16 | const stack = [node];
17 | while (stack.length) {
18 | const node = stack.pop();
19 | if (node.props) {
20 | if (node.props.className) {
21 | node.props.className = node.props.className.replace(/-/g, '__');
22 | }
23 | BLACK_LIST_PROPS.forEach(prop => delete node.props[prop]);
24 | }
25 | if (Array.isArray(node.children)) {
26 | stack.push(...node.children);
27 | }
28 | }
29 | return node;
30 | };
31 |
32 | const DraftTestHelper = {
33 | /**
34 | * This is meant to be used in combination with ReactTestRenderer
35 | * to ensure compatibility with running our snapshot tests internally
36 | *
37 | * usage example:
38 | *
39 | * const blockNode = ReactTestRenderer.create(
40 | * ,
41 | * );
42 | *
43 | * expect(transformSnapshotProps(blockNode.toJSON())).toMatchSnapshot();
44 | */
45 | transformSnapshotProps
46 | };
47 |
48 | export default DraftTestHelper;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/addEntityToContentState.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule addEntityToContentState
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type ContentState from './ContentState';
17 | import type DraftEntityInstance from './DraftEntityInstance';
18 |
19 | const addEntityToEntityMap = require('./addEntityToEntityMap');
20 |
21 | function addEntityToContentState(contentState: ContentState, instance: DraftEntityInstance): ContentState {
22 | return contentState.set('entityMap', addEntityToEntityMap(contentState.getEntityMap(), instance));
23 | }
24 |
25 | export default addEntityToContentState;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/addEntityToEntityMap.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule addEntityToEntityMap
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type DraftEntityInstance from './DraftEntityInstance';
17 | import type { OrderedMap } from 'immutable';
18 | // TODO: when removing the deprecated API update this to use the EntityMap type
19 | // instead of OrderedMap
20 |
21 | let key = 0;
22 |
23 | function addEntityToEntityMap(entityMap: OrderedMap<*, *>, instance: DraftEntityInstance): OrderedMap<*, *> {
24 | return entityMap.set(`${++key}`, instance);
25 | }
26 |
27 | export default addEntityToEntityMap;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/adjustBlockDepthForContentState.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule adjustBlockDepthForContentState
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type ContentState from './ContentState';
17 | import type SelectionState from './SelectionState';
18 |
19 | function adjustBlockDepthForContentState(contentState: ContentState, selectionState: SelectionState, adjustment: number, maxDepth: number): ContentState {
20 | var startKey = selectionState.getStartKey();
21 | var endKey = selectionState.getEndKey();
22 | var blockMap = contentState.getBlockMap();
23 | var blocks = blockMap.toSeq().skipUntil((_, k) => k === startKey).takeUntil((_, k) => k === endKey).concat([[endKey, blockMap.get(endKey)]]).map(block => {
24 | var depth = block.getDepth() + adjustment;
25 | depth = Math.max(0, Math.min(depth, maxDepth));
26 | return block.set('depth', depth);
27 | });
28 |
29 | blockMap = blockMap.merge(blocks);
30 |
31 | return contentState.merge({
32 | blockMap,
33 | selectionBefore: selectionState,
34 | selectionAfter: selectionState
35 | });
36 | }
37 |
38 | export default adjustBlockDepthForContentState;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/applyEntityToContentBlock.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule applyEntityToContentBlock
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type { BlockNodeRecord } from './BlockNodeRecord';
17 |
18 | var CharacterMetadata = require('./CharacterMetadata');
19 |
20 | function applyEntityToContentBlock(contentBlock: BlockNodeRecord, start: number, end: number, entityKey: ?string): BlockNodeRecord {
21 | var characterList = contentBlock.getCharacterList();
22 | while (start < end) {
23 | characterList = characterList.set(start, CharacterMetadata.applyEntity(characterList.get(start), entityKey));
24 | start++;
25 | }
26 | return contentBlock.set('characterList', characterList);
27 | }
28 |
29 | export default applyEntityToContentBlock;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/applyEntityToContentState.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule applyEntityToContentState
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type ContentState from './ContentState';
17 | import type SelectionState from './SelectionState';
18 |
19 | var Immutable = require('immutable');
20 |
21 | var applyEntityToContentBlock = require('./applyEntityToContentBlock');
22 |
23 | function applyEntityToContentState(contentState: ContentState, selectionState: SelectionState, entityKey: ?string): ContentState {
24 | const blockMap = contentState.getBlockMap();
25 | const startKey = selectionState.getStartKey();
26 | const startOffset = selectionState.getStartOffset();
27 | const endKey = selectionState.getEndKey();
28 | const endOffset = selectionState.getEndOffset();
29 |
30 | const newBlocks = blockMap.skipUntil((_, k) => k === startKey).takeUntil((_, k) => k === endKey).toOrderedMap().merge(Immutable.OrderedMap([[endKey, blockMap.get(endKey)]])).map((block, blockKey) => {
31 | const sliceStart = blockKey === startKey ? startOffset : 0;
32 | const sliceEnd = blockKey === endKey ? endOffset : block.getLength();
33 | return applyEntityToContentBlock(block, sliceStart, sliceEnd, entityKey);
34 | });
35 |
36 | return contentState.merge({
37 | blockMap: blockMap.merge(newBlocks),
38 | selectionBefore: selectionState,
39 | selectionAfter: selectionState
40 | });
41 | }
42 |
43 | export default applyEntityToContentState;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/convertFromDraftStateToRaw.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import type ContentState from './ContentState'
4 | import type { RawDraftContentState } from './RawDraftContentState'
5 |
6 | declare module 'draft-js/lib/convertFromDraftStateToRaw' {
7 | declare export default (contentState: ContentState) => RawDraftContentState
8 | }
9 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/convertFromHTMLToContentBlocks.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import type { BlockNodeRecord } from './BlockNodeRecord'
4 | import type { DraftBlockRenderMap } from './DraftBlockRenderMap'
5 | import type { EntityMap } from './EntityMap'
6 |
7 | declare module 'draft-js/lib/convertFromHTMLtoContentBlocks' {
8 | declare export default (
9 | html: string,
10 | DOMBuilder: Function,
11 | blockRenderMap?: DraftBlockRenderMap
12 | ) => ?{
13 | contentBlocks: ?Array,
14 | entityMap: EntityMap,
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/convertFromRawToDraftState.js.flow:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | import type ContentState from './ContentState'
4 | import type { RawDraftContentState } from './RawDraftContentState'
5 |
6 | declare module 'draft-js/lib/convertFromRawToDraftState' {
7 | declare export default (rawState: RawDraftContentState) => ContentState
8 | }
9 |
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/createCharacterList.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule createCharacterList
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type { DraftInlineStyle } from './DraftInlineStyle';
17 |
18 | var CharacterMetadata = require('./CharacterMetadata');
19 | var Immutable = require('immutable');
20 |
21 | var { List } = Immutable;
22 |
23 | function createCharacterList(inlineStyles: Array, entities: Array): List {
24 | var characterArray = inlineStyles.map((style, ii) => {
25 | var entity = entities[ii];
26 | return CharacterMetadata.create({ style, entity });
27 | });
28 | return List(characterArray);
29 | }
30 |
31 | export default createCharacterList;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/createEntityInContentState.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule createEntityInContentState
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | import type ContentState from './ContentState';
17 | import type { DraftEntityMutability } from './DraftEntityMutability';
18 | import type { DraftEntityType } from './DraftEntityType';
19 |
20 | const DraftEntityInstance = require('./DraftEntityInstance');
21 |
22 | const addEntityToContentState = require('./addEntityToContentState');
23 |
24 | function createEntityInContentState(contentState: ContentState, type: DraftEntityType, mutability: DraftEntityMutability, data?: Object): ContentState {
25 | return addEntityToContentState(contentState, new DraftEntityInstance({ type, mutability, data: data || {} }));
26 | }
27 |
28 | export default createEntityInContentState;
--------------------------------------------------------------------------------
/packages/core/flow-lib/draft-js/decodeEntityRanges.js.flow:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | * @providesModule decodeEntityRanges
10 | * @format
11 | * @flow
12 | */
13 |
14 | 'use strict';
15 |
16 | var UnicodeUtils = require('fbjs/lib/UnicodeUtils');
17 |
18 | var { substr } = UnicodeUtils;
19 |
20 | /**
21 | * Convert to native JavaScript string lengths to determine ranges.
22 | */
23 | function decodeEntityRanges(text: string, ranges: Array