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

Commit

Permalink
1/n splitting PR #1828: Initial forking of RichTextEditorUtil (#1828)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mitermayer authored and facebook-github-bot committed Aug 6, 2018
1 parent cf48f77 commit 328ddc6
Show file tree
Hide file tree
Showing 5 changed files with 3,445 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/model/modifier/RichTextEditorUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @format
* @flow
* @flow strict-local
*/

'use strict';

import type ContentState from 'ContentState';
import type {DraftBlockType} from 'DraftBlockType';
import type {DraftEditorCommand} from 'DraftEditorCommand';
import type {DataObjectForLink, RichTextUtils} from 'RichTextUtils';
import type SelectionState from 'SelectionState';
import type URI from 'URI';

const DraftModifier = require('DraftModifier');
const EditorState = require('EditorState');
const SelectionState = require('SelectionState');

const adjustBlockDepthForContentState = require('adjustBlockDepthForContentState');
const nullthrows = require('nullthrows');

const RichTextEditorUtil = {
const RichTextEditorUtil: RichTextUtils = {
currentBlockContainsLink: function(editorState: EditorState): boolean {
const selection = editorState.getSelection();
const contentState = editorState.getCurrentContent();
Expand All @@ -47,7 +48,7 @@ const RichTextEditorUtil = {
.getType();
},

getDataObjectForLinkURL: function(uri: URI): Object {
getDataObjectForLinkURL: function(uri: URI): DataObjectForLink {
return {url: uri.toString()};
},

Expand Down
67 changes: 67 additions & 0 deletions src/model/modifier/RichTextUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @format
* @flow strict-local
*/

import type ContentState from 'ContentState';
import type {DraftBlockType} from 'DraftBlockType';
import type {DraftEditorCommand} from 'DraftEditorCommand';
import type EditorState from 'EditorState';
import type SelectionState from 'SelectionState';
import type URI from 'URI';

export type DataObjectForLink = {
url: string,
};

export type RichTextUtils = {
currentBlockContainsLink: (editorState: EditorState) => boolean,

getCurrentBlockType: (editorState: EditorState) => DraftBlockType,

getDataObjectForLinkURL: (uri: URI) => DataObjectForLink,

handleKeyCommand: (
editorState: EditorState,
command: DraftEditorCommand | string,
) => ?EditorState,

insertSoftNewline: (editorState: EditorState) => EditorState,

onBackspace: (editorState: EditorState) => ?EditorState,

onDelete: (editorState: EditorState) => ?EditorState,

onTab: (
event: SyntheticKeyboardEvent<>,
editorState: EditorState,
maxDepth: number,
) => EditorState,

toggleBlockType: (
editorState: EditorState,
blockType: DraftBlockType,
) => EditorState,

toggleCode: (editorState: EditorState) => EditorState,

toggleInlineStyle: (
editorState: EditorState,
inlineStyle: string,
) => EditorState,

toggleLink: (
editorState: EditorState,
targetSelection: SelectionState,
entityKey: ?string,
) => EditorState,

tryToRemoveBlockStyle: (editorState: EditorState) => ?ContentState,
};
Loading

0 comments on commit 328ddc6

Please sign in to comment.