Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCLD-17783 Removes usage of deprecated draftjs props #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dist
docs/.yalc/
docs/yalc.lock
stats.json
report.html
report.html
.idea/
6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

58 changes: 0 additions & 58 deletions .idea/workspace.xml

This file was deleted.

54 changes: 35 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"dependencies": {
"classnames": "^2.2.6",
"draftjs-utils": "^0.10.2",
"fbjs": "^1.0.0",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the package that draft-js uses to get Keys

"html-to-draftjs": "^1.5.0",
"linkify-it": "^2.2.0",
"prop-types": "^15.7.2"
Expand Down
25 changes: 21 additions & 4 deletions src/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
convertFromRaw,
CompositeDecorator
} from "draft-js";
import getDefaultKeyBinding from 'draft-js/lib/getDefaultKeyBinding';
import {
changeDepth,
handleNewLine,
Expand All @@ -18,6 +19,7 @@ import {
extractInlineStyle,
getSelectedBlocksType
} from "draftjs-utils";
import Keys from "fbjs/lib/Keys";
import classNames from "classnames";
import ModalHandler from "../event-handler/modals";
import FocusHandler from "../event-handler/focus";
Expand All @@ -37,6 +39,8 @@ import localeTranslations from "../i18n";
import "./styles.css";
import "../../css/Draft.css";

import type {DraftEditorCommand} from 'draft-js/lib/DraftEditorCommand';

export default class WysiwygEditor extends Component {
static propTypes = {
onChange: PropTypes.func,
Expand Down Expand Up @@ -196,6 +200,21 @@ export default class WysiwygEditor extends Component {
this.focusHandler.onEditorMouseDown();
};

keyBindingFn: Function = (e): ?DraftEditorCommand => {
// eslint-disable-next-line default-case
switch (e.keyCode) {
case Keys.TAB:
this.onTab(e);
break;
case Keys.UP:
case Keys.DOWN:
this.onUpDownArrow(e);
break;
}

return getDefaultKeyBinding(e);
}

onTab: Function = (event): boolean => {
const { onTab } = this.props;
if (!onTab || !onTab(event)) {
Expand Down Expand Up @@ -519,7 +538,7 @@ export default class WysiwygEditor extends Component {
toolbarCustomButtons.map((button, index) =>
React.cloneElement(button, { key: index, ...controlProps })
)}
</div>
</div>
)}
<div
ref={this.setWrapperReference}
Expand All @@ -533,9 +552,7 @@ export default class WysiwygEditor extends Component {
>
<Editor
ref={this.setEditorReference}
onTab={this.onTab}
onUpArrow={this.onUpDownArrow}
onDownArrow={this.onUpDownArrow}
keyBindingFn={this.keyBindingFn}
editorState={editorState}
onChange={this.onChange}
blockStyleFn={blockStyleFn}
Expand Down