Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit 328ddc6

Browse files
mitermayerfacebook-github-bot
authored andcommitted
1/n splitting PR #1828: Initial forking of RichTextEditorUtil (#1828)
Summary: We are splitting up and updating pieces of this PR by Mitermayer. This chunk forks the RichTextEditorUtil and puts them both under the same Flow interface, also adding a test. The forked NestedRichTextEditorUtil is a WIP version of this utility. This is directly taken from mitermayer 's fork, props to him Pull Request resolved: #1828 Reviewed By: mitermayer Differential Revision: D9181952 Pulled By: mitermayer fbshipit-source-id: 75f08fdb228ae1b45f97ae29aeae2f3d5ea53650
1 parent cf48f77 commit 328ddc6

File tree

5 files changed

+3445
-4
lines changed

5 files changed

+3445
-4
lines changed

src/model/modifier/RichTextEditorUtil.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*
99
* @format
10-
* @flow
10+
* @flow strict-local
1111
*/
1212

1313
'use strict';
1414

1515
import type ContentState from 'ContentState';
1616
import type {DraftBlockType} from 'DraftBlockType';
1717
import type {DraftEditorCommand} from 'DraftEditorCommand';
18+
import type {DataObjectForLink, RichTextUtils} from 'RichTextUtils';
19+
import type SelectionState from 'SelectionState';
1820
import type URI from 'URI';
1921

2022
const DraftModifier = require('DraftModifier');
2123
const EditorState = require('EditorState');
22-
const SelectionState = require('SelectionState');
2324

2425
const adjustBlockDepthForContentState = require('adjustBlockDepthForContentState');
2526
const nullthrows = require('nullthrows');
2627

27-
const RichTextEditorUtil = {
28+
const RichTextEditorUtil: RichTextUtils = {
2829
currentBlockContainsLink: function(editorState: EditorState): boolean {
2930
const selection = editorState.getSelection();
3031
const contentState = editorState.getCurrentContent();
@@ -47,7 +48,7 @@ const RichTextEditorUtil = {
4748
.getType();
4849
},
4950

50-
getDataObjectForLinkURL: function(uri: URI): Object {
51+
getDataObjectForLinkURL: function(uri: URI): DataObjectForLink {
5152
return {url: uri.toString()};
5253
},
5354

src/model/modifier/RichTextUtils.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
* @format
10+
* @flow strict-local
11+
*/
12+
13+
import type ContentState from 'ContentState';
14+
import type {DraftBlockType} from 'DraftBlockType';
15+
import type {DraftEditorCommand} from 'DraftEditorCommand';
16+
import type EditorState from 'EditorState';
17+
import type SelectionState from 'SelectionState';
18+
import type URI from 'URI';
19+
20+
export type DataObjectForLink = {
21+
url: string,
22+
};
23+
24+
export type RichTextUtils = {
25+
currentBlockContainsLink: (editorState: EditorState) => boolean,
26+
27+
getCurrentBlockType: (editorState: EditorState) => DraftBlockType,
28+
29+
getDataObjectForLinkURL: (uri: URI) => DataObjectForLink,
30+
31+
handleKeyCommand: (
32+
editorState: EditorState,
33+
command: DraftEditorCommand | string,
34+
) => ?EditorState,
35+
36+
insertSoftNewline: (editorState: EditorState) => EditorState,
37+
38+
onBackspace: (editorState: EditorState) => ?EditorState,
39+
40+
onDelete: (editorState: EditorState) => ?EditorState,
41+
42+
onTab: (
43+
event: SyntheticKeyboardEvent<>,
44+
editorState: EditorState,
45+
maxDepth: number,
46+
) => EditorState,
47+
48+
toggleBlockType: (
49+
editorState: EditorState,
50+
blockType: DraftBlockType,
51+
) => EditorState,
52+
53+
toggleCode: (editorState: EditorState) => EditorState,
54+
55+
toggleInlineStyle: (
56+
editorState: EditorState,
57+
inlineStyle: string,
58+
) => EditorState,
59+
60+
toggleLink: (
61+
editorState: EditorState,
62+
targetSelection: SelectionState,
63+
entityKey: ?string,
64+
) => EditorState,
65+
66+
tryToRemoveBlockStyle: (editorState: EditorState) => ?ContentState,
67+
};

0 commit comments

Comments
 (0)