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

Commit

Permalink
Upgrade to Flow explicit inexact object type syntax
Browse files Browse the repository at this point in the history
Reviewed By: dunnbobcat

Differential Revision: D19416353

fbshipit-source-id: 26f111ed06e8ad7cee6717dbcb391f94e096f91a
  • Loading branch information
jbrown215 authored and facebook-github-bot committed Jan 16, 2020
1 parent 824fd12 commit b051fc1
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/model/decorators/DraftDecorator.js
Expand Up @@ -43,6 +43,7 @@ export type DraftDecorator = {
strategy: DraftDecoratorStrategy,
component: Function,
props?: Object,
...
};

/**
Expand All @@ -57,7 +58,6 @@ export type DraftDecoratorComponentProps = {
decoratedText: string,
dir: ?HTMLDir,
end: number,

// Many folks mistakenly assume that there will always be an 'entityKey'
// passed to a DecoratorComponent.
// To find the `entityKey`, Draft calls
Expand All @@ -66,8 +66,8 @@ export type DraftDecoratorComponentProps = {
// undefined. That's why `getEntityKeyAt()` is typed to return `?string`.
// See https://github.com/facebook/draft-js/blob/2da3dcb1c4c106d1b2a0f07b3d0275b8d724e777/src/model/immutable/BlockNode.js#L51
entityKey: ?string,

key: React.Key,
offsetKey: string,
start: number,
...
};
3 changes: 1 addition & 2 deletions src/model/decorators/DraftDecoratorType.js
Expand Up @@ -29,16 +29,15 @@ export type DraftDecoratorType = {
block: BlockNodeRecord,
contentState: ContentState,
): List<?string>,

/**
* Given a decorator key, return the component to use when rendering
* this decorated range.
*/
getComponentForKey(key: string): Function,

/**
* Given a decorator key, optionally return the props to use when rendering
* this decorated range.
*/
getPropsForKey(key: string): ?Object,
...
};
1 change: 1 addition & 0 deletions src/model/encoding/EntityRange.js
Expand Up @@ -21,4 +21,5 @@ export type EntityRange = {
key: number,
offset: number,
length: number,
...
};
1 change: 1 addition & 0 deletions src/model/encoding/InlineStyleRange.js
Expand Up @@ -18,4 +18,5 @@ export type InlineStyleRange = {
style: string,
offset: number,
length: number,
...
};
1 change: 1 addition & 0 deletions src/model/encoding/RawDraftContentBlock.js
Expand Up @@ -28,4 +28,5 @@ export type RawDraftContentBlock = {
entityRanges: ?Array<EntityRange>,
data?: Object,
children?: Array<RawDraftContentBlock>,
...
};
3 changes: 2 additions & 1 deletion src/model/encoding/RawDraftContentState.js
Expand Up @@ -25,5 +25,6 @@ import type {RawDraftEntity} from 'RawDraftEntity';
*/
export type RawDraftContentState = {
blocks: Array<RawDraftContentBlock>,
entityMap: {[key: string]: RawDraftEntity},
entityMap: {[key: string]: RawDraftEntity, ...},
...
};
3 changes: 2 additions & 1 deletion src/model/encoding/RawDraftEntity.js
Expand Up @@ -20,5 +20,6 @@ import type {DraftEntityType} from 'DraftEntityType';
export type RawDraftEntity = {
type: DraftEntityType,
mutability: DraftEntityMutability,
data: ?{[key: string]: any},
data: ?{[key: string]: any, ...},
...
};
9 changes: 8 additions & 1 deletion src/model/encoding/convertFromHTMLToContentBlocks.js
Expand Up @@ -241,6 +241,7 @@ type ContentBlockConfig = {
prevSibling: ?string,
nextSibling: ?string,
childConfigs: Array<ContentBlockConfig>,
...
};

/**
Expand Down Expand Up @@ -338,6 +339,7 @@ class ContentBlocksBuilder {
getContentBlocks(): {
contentBlocks: ?Array<BlockNodeRecord>,
entityMap: EntityMap,
...
} {
if (this.contentBlocks.length === 0) {
if (experimentalTreeDataSupport) {
Expand Down Expand Up @@ -725,6 +727,7 @@ class ContentBlocksBuilder {
): {
text: string,
characterList: List<CharacterMetadata>,
...
} {
const l = blockConfigs.length - 1;
let text = '';
Expand Down Expand Up @@ -753,7 +756,11 @@ const convertFromHTMLToContentBlocks = (
html: string,
DOMBuilder: Function = getSafeBodyFromHTML,
blockRenderMap?: DraftBlockRenderMap = DefaultDraftBlockRenderMap,
): ?{contentBlocks: ?Array<BlockNodeRecord>, entityMap: EntityMap} => {
): ?{
contentBlocks: ?Array<BlockNodeRecord>,
entityMap: EntityMap,
...
} => {
// Be ABSOLUTELY SURE that the dom builder you pass here won't execute
// arbitrary code in whatever environment you're running this in. For an
// example of how we try to do this in-browser, see getSafeBodyFromHTML.
Expand Down
28 changes: 9 additions & 19 deletions src/model/entity/DraftEntity.js
Expand Up @@ -37,48 +37,38 @@ function logWarning(oldMethodCall, newMethodCall) {

export type DraftEntityMapObject = {
getLastCreatedEntityKey: () => string,

create: (
type: DraftEntityType,
mutability: DraftEntityMutability,
data?: Object,
) => string,

add: (instance: DraftEntityInstance) => string,

get: (key: string) => DraftEntityInstance,

mergeData: (
key: string,
toMerge: {[key: string]: any},
toMerge: {[key: string]: any, ...},
) => DraftEntityInstance,

replaceData: (
key: string,
newData: {[key: string]: any},
newData: {[key: string]: any, ...},
) => DraftEntityInstance,

__getLastCreatedEntityKey: () => string,

__create: (
type: DraftEntityType,
mutability: DraftEntityMutability,
data?: Object,
) => string,

__add: (instance: DraftEntityInstance) => string,

__get: (key: string) => DraftEntityInstance,

__mergeData: (
key: string,
toMerge: {[key: string]: any},
toMerge: {[key: string]: any, ...},
) => DraftEntityInstance,

__replaceData: (
key: string,
newData: {[key: string]: any},
newData: {[key: string]: any, ...},
) => DraftEntityInstance,
...
};

/**
Expand Down Expand Up @@ -163,7 +153,7 @@ const DraftEntity: DraftEntityMapObject = {
*/
mergeData: function(
key: string,
toMerge: {[key: string]: any},
toMerge: {[key: string]: any, ...},
): DraftEntityInstance {
logWarning('DraftEntity.mergeData', 'contentState.mergeEntityData');
return DraftEntity.__mergeData(key, toMerge);
Expand All @@ -177,7 +167,7 @@ const DraftEntity: DraftEntityMapObject = {
*/
replaceData: function(
key: string,
newData: {[key: string]: any},
newData: {[key: string]: any, ...},
): DraftEntityInstance {
logWarning('DraftEntity.replaceData', 'contentState.replaceEntityData');
return DraftEntity.__replaceData(key, newData);
Expand Down Expand Up @@ -239,7 +229,7 @@ const DraftEntity: DraftEntityMapObject = {
*/
__mergeData: function(
key: string,
toMerge: {[key: string]: any},
toMerge: {[key: string]: any, ...},
): DraftEntityInstance {
const instance = DraftEntity.__get(key);
const newData = {...instance.getData(), ...toMerge};
Expand All @@ -253,7 +243,7 @@ const DraftEntity: DraftEntityMapObject = {
*/
__replaceData: function(
key: string,
newData: {[key: string]: any},
newData: {[key: string]: any, ...},
): DraftEntityInstance {
const instance = DraftEntity.__get(key);
const newInstance = instance.set('data', newData);
Expand Down
1 change: 1 addition & 0 deletions src/model/immutable/BlockNode.js
Expand Up @@ -25,6 +25,7 @@ export type BlockNodeConfig = {
key?: BlockNodeKey,
text?: string,
type?: DraftBlockType,
...
};

// https://github.com/facebook/draft-js/issues/1492
Expand Down
2 changes: 2 additions & 0 deletions src/model/immutable/BlockTree.js
Expand Up @@ -28,6 +28,7 @@ const returnTrue = function() {
const defaultLeafRange: {
start: ?number,
end: ?number,
...
} = {
start: null,
end: null,
Expand All @@ -40,6 +41,7 @@ const defaultDecoratorRange: {
end: ?number,
decoratorKey: ?string,
leaves: ?List<LeafRange>,
...
} = {
start: null,
end: null,
Expand Down
1 change: 1 addition & 0 deletions src/model/immutable/CharacterMetadata.js
Expand Up @@ -22,6 +22,7 @@ type CharacterMetadataConfigValueType = DraftInlineStyle | ?string;
type CharacterMetadataConfig = {
style?: CharacterMetadataConfigValueType,
entity?: CharacterMetadataConfigValueType,
...
};

const EMPTY_SET = OrderedSet();
Expand Down
1 change: 1 addition & 0 deletions src/model/immutable/ContentBlockNode.js
Expand Up @@ -33,6 +33,7 @@ type ContentBlockNodeConfig = BlockNodeConfig & {
parent?: ?BlockNodeKey,
prevSibling?: ?BlockNodeKey,
nextSibling?: ?BlockNodeKey,
...
};

const EMPTY_SET = OrderedSet();
Expand Down
15 changes: 12 additions & 3 deletions src/model/immutable/ContentState.js
Expand Up @@ -36,6 +36,7 @@ const defaultRecord: {
blockMap: ?BlockMap,
selectionBefore: ?SelectionState,
selectionAfter: ?SelectionState,
...
} = {
entityMap: null,
blockMap: null,
Expand Down Expand Up @@ -144,13 +145,19 @@ class ContentState extends ContentStateRecord {
return this;
}

mergeEntityData(key: string, toMerge: {[key: string]: any}): ContentState {
mergeEntityData(
key: string,
toMerge: {[key: string]: any, ...},
): ContentState {
// TODO: update this when we fully remove DraftEntity
DraftEntity.__mergeData(key, toMerge);
return this;
}

replaceEntityData(key: string, newData: {[key: string]: any}): ContentState {
replaceEntityData(
key: string,
newData: {[key: string]: any, ...},
): ContentState {
// TODO: update this when we fully remove DraftEntity
DraftEntity.__replaceData(key, newData);
return this;
Expand All @@ -169,7 +176,9 @@ class ContentState extends ContentStateRecord {

static createFromBlockArray(
// TODO: update flow type when we completely deprecate the old entity API
blocks: Array<BlockNodeRecord> | {contentBlocks: Array<BlockNodeRecord>},
blocks:
| Array<BlockNodeRecord>
| {contentBlocks: Array<BlockNodeRecord>, ...},
entityMap: ?any,
): ContentState {
// TODO: remove this when we completely deprecate the old entity API
Expand Down
1 change: 1 addition & 0 deletions src/model/immutable/DraftBlockRenderConfig.js
Expand Up @@ -17,4 +17,5 @@ export type DraftBlockRenderConfig = {
element: string,
wrapper?: React.Node,
aliasedElements?: Array<string>,
...
};
1 change: 1 addition & 0 deletions src/model/immutable/EditorState.js
Expand Up @@ -41,6 +41,7 @@ type EditorStateRecordType = {
selection: ?SelectionState,
treeMap: ?OrderedMap<string, List<any>>,
undoStack: Stack<ContentState>,
...
};

const defaultRecord: EditorStateRecordType = {
Expand Down
1 change: 1 addition & 0 deletions src/model/immutable/EditorStateCreationConfig.js
Expand Up @@ -20,4 +20,5 @@ export type EditorStateCreationConfig = {
currentContent: ContentState,
decorator: ?DraftDecoratorType,
selection: SelectionState,
...
};
1 change: 1 addition & 0 deletions src/model/immutable/SelectionState.js
Expand Up @@ -22,6 +22,7 @@ const defaultRecord: {
focusOffset: number,
isBackward: boolean,
hasFocus: boolean,
...
} = {
anchorKey: '',
anchorOffset: 0,
Expand Down
1 change: 1 addition & 0 deletions src/model/modifier/DraftRange.js
Expand Up @@ -14,4 +14,5 @@
export type DraftRange = {
start: number,
end: number,
...
};
17 changes: 2 additions & 15 deletions src/model/modifier/RichTextUtils.js
Expand Up @@ -16,51 +16,38 @@ import type EditorState from 'EditorState';
import type SelectionState from 'SelectionState';
import type URI from 'URI';

export type DataObjectForLink = {
url: string,
};
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,
...
};
6 changes: 5 additions & 1 deletion src/model/paste/DraftPasteProcessor.js
Expand Up @@ -38,7 +38,11 @@ const DraftPasteProcessor = {
processHTML(
html: string,
blockRenderMap?: DraftBlockRenderMap,
): ?{contentBlocks: ?Array<BlockNodeRecord>, entityMap: EntityMap} {
): ?{
contentBlocks: ?Array<BlockNodeRecord>,
entityMap: EntityMap,
...
} {
return convertFromHTMLToContentBlocks(
html,
getSafeBodyFromHTML,
Expand Down
1 change: 1 addition & 0 deletions src/model/transaction/removeEntitiesAtEdges.js
Expand Up @@ -75,6 +75,7 @@ function getRemovalRange(
): {
start: number,
end: number,
...
} {
let removalRange;

Expand Down

0 comments on commit b051fc1

Please sign in to comment.