diff --git a/src/component/contents/DraftEditorLeaf.react.js b/src/component/contents/DraftEditorLeaf.react.js index 82eb2e5ef6..b1affbf9da 100644 --- a/src/component/contents/DraftEditorLeaf.react.js +++ b/src/component/contents/DraftEditorLeaf.react.js @@ -17,11 +17,11 @@ import type {DraftInlineStyle} from 'DraftInlineStyle'; import type SelectionState from 'SelectionState'; const DraftEditorTextNode = require('DraftEditorTextNode.react'); -var React = require('React'); -var ReactDOM = require('ReactDOM'); +const React = require('React'); +const ReactDOM = require('ReactDOM'); const invariant = require('invariant'); -var setDraftEditorSelection = require('setDraftEditorSelection'); +const setDraftEditorSelection = require('setDraftEditorSelection'); type Props = { // The block that contains this leaf. diff --git a/src/component/handlers/composition/DraftEditorCompositionHandler.js b/src/component/handlers/composition/DraftEditorCompositionHandler.js index 4790163045..de3f1cd8f1 100644 --- a/src/component/handlers/composition/DraftEditorCompositionHandler.js +++ b/src/component/handlers/composition/DraftEditorCompositionHandler.js @@ -45,7 +45,7 @@ let resolved = false; let stillComposing = false; let textInputData = ''; -var DraftEditorCompositionHandler = { +const DraftEditorCompositionHandler = { onBeforeInput: function(editor: DraftEditor, e: SyntheticInputEvent<>): void { textInputData = (textInputData || '') + e.data; }, diff --git a/src/component/handlers/drag/DraftEditorDragHandler.js b/src/component/handlers/drag/DraftEditorDragHandler.js index 4c3a7d9a6a..ee0aeaf0ff 100644 --- a/src/component/handlers/drag/DraftEditorDragHandler.js +++ b/src/component/handlers/drag/DraftEditorDragHandler.js @@ -39,7 +39,7 @@ function getSelectionForEvent( * found when Flow v0.68 was deployed. To see the error delete this comment * and run Flow. */ if (typeof document.caretRangeFromPoint === 'function') { - var dropRange = document.caretRangeFromPoint(event.x, event.y); + const dropRange = document.caretRangeFromPoint(event.x, event.y); node = dropRange.startContainer; offset = dropRange.startOffset; } else if (event.rangeParent) { @@ -62,7 +62,7 @@ function getSelectionForEvent( ); } -var DraftEditorDragHandler = { +const DraftEditorDragHandler = { /** * Drag originating from input terminated. */ diff --git a/src/component/handlers/edit/commands/SecondaryClipboard.js b/src/component/handlers/edit/commands/SecondaryClipboard.js index 828a61a9d8..2c89e4d641 100644 --- a/src/component/handlers/edit/commands/SecondaryClipboard.js +++ b/src/component/handlers/edit/commands/SecondaryClipboard.js @@ -15,27 +15,27 @@ import type {BlockMap} from 'BlockMap'; import type SelectionState from 'SelectionState'; -var DraftModifier = require('DraftModifier'); -var EditorState = require('EditorState'); +const DraftModifier = require('DraftModifier'); +const EditorState = require('EditorState'); -var getContentStateFragment = require('getContentStateFragment'); -var nullthrows = require('nullthrows'); +const getContentStateFragment = require('getContentStateFragment'); +const nullthrows = require('nullthrows'); -var clipboard: ?BlockMap = null; +let clipboard: ?BlockMap = null; /** * Some systems offer a "secondary" clipboard to allow quick internal cut * and paste behavior. For instance, Ctrl+K (cut) and Ctrl+Y (paste). */ -var SecondaryClipboard = { +const SecondaryClipboard = { cut: function(editorState: EditorState): EditorState { - var content = editorState.getCurrentContent(); - var selection = editorState.getSelection(); - var targetRange: ?SelectionState = null; + const content = editorState.getCurrentContent(); + const selection = editorState.getSelection(); + let targetRange: ?SelectionState = null; if (selection.isCollapsed()) { - var anchorKey = selection.getAnchorKey(); - var blockEnd = content.getBlockForKey(anchorKey).getLength(); + const anchorKey = selection.getAnchorKey(); + const blockEnd = content.getBlockForKey(anchorKey).getLength(); if (blockEnd === selection.getAnchorOffset()) { return editorState; @@ -49,7 +49,7 @@ var SecondaryClipboard = { targetRange = nullthrows(targetRange); clipboard = getContentStateFragment(content, targetRange); - var afterRemoval = DraftModifier.removeRange( + const afterRemoval = DraftModifier.removeRange( content, targetRange, 'forward', @@ -67,7 +67,7 @@ var SecondaryClipboard = { return editorState; } - var newContent = DraftModifier.replaceWithFragment( + const newContent = DraftModifier.replaceWithFragment( editorState.getCurrentContent(), editorState.getSelection(), clipboard, diff --git a/src/component/handlers/edit/commands/keyCommandBackspaceToStartOfLine.js b/src/component/handlers/edit/commands/keyCommandBackspaceToStartOfLine.js index 3442cc0f3d..8027c1b332 100644 --- a/src/component/handlers/edit/commands/keyCommandBackspaceToStartOfLine.js +++ b/src/component/handlers/edit/commands/keyCommandBackspaceToStartOfLine.js @@ -12,17 +12,17 @@ 'use strict'; -var EditorState = require('EditorState'); +const EditorState = require('EditorState'); -var expandRangeToStartOfLine = require('expandRangeToStartOfLine'); -var getDraftEditorSelectionWithNodes = require('getDraftEditorSelectionWithNodes'); -var moveSelectionBackward = require('moveSelectionBackward'); -var removeTextWithStrategy = require('removeTextWithStrategy'); +const expandRangeToStartOfLine = require('expandRangeToStartOfLine'); +const getDraftEditorSelectionWithNodes = require('getDraftEditorSelectionWithNodes'); +const moveSelectionBackward = require('moveSelectionBackward'); +const removeTextWithStrategy = require('removeTextWithStrategy'); function keyCommandBackspaceToStartOfLine( editorState: EditorState, ): EditorState { - var afterRemoval = removeTextWithStrategy( + const afterRemoval = removeTextWithStrategy( editorState, strategyState => { const selection = strategyState.getSelection(); @@ -30,8 +30,8 @@ function keyCommandBackspaceToStartOfLine( return moveSelectionBackward(strategyState, 1); } - var domSelection = global.getSelection(); - var range = domSelection.getRangeAt(0); + const domSelection = global.getSelection(); + let range = domSelection.getRangeAt(0); range = expandRangeToStartOfLine(range); return getDraftEditorSelectionWithNodes( diff --git a/src/component/handlers/edit/commands/keyCommandBackspaceWord.js b/src/component/handlers/edit/commands/keyCommandBackspaceWord.js index 42bb802483..e42b656178 100644 --- a/src/component/handlers/edit/commands/keyCommandBackspaceWord.js +++ b/src/component/handlers/edit/commands/keyCommandBackspaceWord.js @@ -12,33 +12,33 @@ 'use strict'; -var DraftRemovableWord = require('DraftRemovableWord'); -var EditorState = require('EditorState'); +const DraftRemovableWord = require('DraftRemovableWord'); +const EditorState = require('EditorState'); -var moveSelectionBackward = require('moveSelectionBackward'); -var removeTextWithStrategy = require('removeTextWithStrategy'); +const moveSelectionBackward = require('moveSelectionBackward'); +const removeTextWithStrategy = require('removeTextWithStrategy'); /** * Delete the word that is left of the cursor, as well as any spaces or * punctuation after the word. */ function keyCommandBackspaceWord(editorState: EditorState): EditorState { - var afterRemoval = removeTextWithStrategy( + const afterRemoval = removeTextWithStrategy( editorState, strategyState => { - var selection = strategyState.getSelection(); - var offset = selection.getStartOffset(); + const selection = strategyState.getSelection(); + const offset = selection.getStartOffset(); // If there are no words before the cursor, remove the preceding newline. if (offset === 0) { return moveSelectionBackward(strategyState, 1); } - var key = selection.getStartKey(); - var content = strategyState.getCurrentContent(); - var text = content + const key = selection.getStartKey(); + const content = strategyState.getCurrentContent(); + const text = content .getBlockForKey(key) .getText() .slice(0, offset); - var toRemove = DraftRemovableWord.getBackward(text); + const toRemove = DraftRemovableWord.getBackward(text); return moveSelectionBackward(strategyState, toRemove.length || 1); }, 'backward', diff --git a/src/component/handlers/edit/commands/keyCommandDeleteWord.js b/src/component/handlers/edit/commands/keyCommandDeleteWord.js index 34468728fb..4b196e089a 100644 --- a/src/component/handlers/edit/commands/keyCommandDeleteWord.js +++ b/src/component/handlers/edit/commands/keyCommandDeleteWord.js @@ -12,29 +12,29 @@ 'use strict'; -var DraftRemovableWord = require('DraftRemovableWord'); -var EditorState = require('EditorState'); +const DraftRemovableWord = require('DraftRemovableWord'); +const EditorState = require('EditorState'); -var moveSelectionForward = require('moveSelectionForward'); -var removeTextWithStrategy = require('removeTextWithStrategy'); +const moveSelectionForward = require('moveSelectionForward'); +const removeTextWithStrategy = require('removeTextWithStrategy'); /** * Delete the word that is right of the cursor, as well as any spaces or * punctuation before the word. */ function keyCommandDeleteWord(editorState: EditorState): EditorState { - var afterRemoval = removeTextWithStrategy( + const afterRemoval = removeTextWithStrategy( editorState, strategyState => { - var selection = strategyState.getSelection(); - var offset = selection.getStartOffset(); - var key = selection.getStartKey(); - var content = strategyState.getCurrentContent(); - var text = content + const selection = strategyState.getSelection(); + const offset = selection.getStartOffset(); + const key = selection.getStartKey(); + const content = strategyState.getCurrentContent(); + const text = content .getBlockForKey(key) .getText() .slice(offset); - var toRemove = DraftRemovableWord.getForward(text); + const toRemove = DraftRemovableWord.getForward(text); // If there are no words in front of the cursor, remove the newline. return moveSelectionForward(strategyState, toRemove.length || 1); diff --git a/src/component/handlers/edit/commands/keyCommandInsertNewline.js b/src/component/handlers/edit/commands/keyCommandInsertNewline.js index eb183991e0..2822fe5131 100644 --- a/src/component/handlers/edit/commands/keyCommandInsertNewline.js +++ b/src/component/handlers/edit/commands/keyCommandInsertNewline.js @@ -12,11 +12,11 @@ 'use strict'; -var DraftModifier = require('DraftModifier'); -var EditorState = require('EditorState'); +const DraftModifier = require('DraftModifier'); +const EditorState = require('EditorState'); function keyCommandInsertNewline(editorState: EditorState): EditorState { - var contentState = DraftModifier.splitBlock( + const contentState = DraftModifier.splitBlock( editorState.getCurrentContent(), editorState.getSelection(), ); diff --git a/src/component/handlers/edit/commands/keyCommandMoveSelectionToEndOfBlock.js b/src/component/handlers/edit/commands/keyCommandMoveSelectionToEndOfBlock.js index e30ee2c302..48127a3fa9 100644 --- a/src/component/handlers/edit/commands/keyCommandMoveSelectionToEndOfBlock.js +++ b/src/component/handlers/edit/commands/keyCommandMoveSelectionToEndOfBlock.js @@ -12,7 +12,7 @@ 'use strict'; -var EditorState = require('EditorState'); +const EditorState = require('EditorState'); /** * See comment for `moveSelectionToStartOfBlock`. @@ -20,10 +20,10 @@ var EditorState = require('EditorState'); function keyCommandMoveSelectionToEndOfBlock( editorState: EditorState, ): EditorState { - var selection = editorState.getSelection(); - var endKey = selection.getEndKey(); - var content = editorState.getCurrentContent(); - var textLength = content.getBlockForKey(endKey).getLength(); + const selection = editorState.getSelection(); + const endKey = selection.getEndKey(); + const content = editorState.getCurrentContent(); + const textLength = content.getBlockForKey(endKey).getLength(); return EditorState.set(editorState, { selection: selection.merge({ anchorKey: endKey, diff --git a/src/component/handlers/edit/commands/keyCommandMoveSelectionToStartOfBlock.js b/src/component/handlers/edit/commands/keyCommandMoveSelectionToStartOfBlock.js index 32069c1251..fcd36618b7 100644 --- a/src/component/handlers/edit/commands/keyCommandMoveSelectionToStartOfBlock.js +++ b/src/component/handlers/edit/commands/keyCommandMoveSelectionToStartOfBlock.js @@ -12,7 +12,7 @@ 'use strict'; -var EditorState = require('EditorState'); +const EditorState = require('EditorState'); /** * Collapse selection at the start of the first selected block. This is used @@ -22,8 +22,8 @@ var EditorState = require('EditorState'); function keyCommandMoveSelectionToStartOfBlock( editorState: EditorState, ): EditorState { - var selection = editorState.getSelection(); - var startKey = selection.getStartKey(); + const selection = editorState.getSelection(); + const startKey = selection.getStartKey(); return EditorState.set(editorState, { selection: selection.merge({ anchorKey: startKey, diff --git a/src/component/handlers/edit/commands/keyCommandPlainBackspace.js b/src/component/handlers/edit/commands/keyCommandPlainBackspace.js index 4bd966534a..f87b872d48 100644 --- a/src/component/handlers/edit/commands/keyCommandPlainBackspace.js +++ b/src/component/handlers/edit/commands/keyCommandPlainBackspace.js @@ -12,11 +12,11 @@ 'use strict'; -var EditorState = require('EditorState'); -var UnicodeUtils = require('UnicodeUtils'); +const EditorState = require('EditorState'); +const UnicodeUtils = require('UnicodeUtils'); -var moveSelectionBackward = require('moveSelectionBackward'); -var removeTextWithStrategy = require('removeTextWithStrategy'); +const moveSelectionBackward = require('moveSelectionBackward'); +const removeTextWithStrategy = require('removeTextWithStrategy'); /** * Remove the selected range. If the cursor is collapsed, remove the preceding @@ -24,14 +24,14 @@ var removeTextWithStrategy = require('removeTextWithStrategy'); * will remove a surrogate pair properly as well. */ function keyCommandPlainBackspace(editorState: EditorState): EditorState { - var afterRemoval = removeTextWithStrategy( + const afterRemoval = removeTextWithStrategy( editorState, strategyState => { - var selection = strategyState.getSelection(); - var content = strategyState.getCurrentContent(); - var key = selection.getAnchorKey(); - var offset = selection.getAnchorOffset(); - var charBehind = content.getBlockForKey(key).getText()[offset - 1]; + const selection = strategyState.getSelection(); + const content = strategyState.getCurrentContent(); + const key = selection.getAnchorKey(); + const offset = selection.getAnchorOffset(); + const charBehind = content.getBlockForKey(key).getText()[offset - 1]; return moveSelectionBackward( strategyState, charBehind ? UnicodeUtils.getUTF16Length(charBehind, 0) : 1, @@ -44,7 +44,7 @@ function keyCommandPlainBackspace(editorState: EditorState): EditorState { return editorState; } - var selection = editorState.getSelection(); + const selection = editorState.getSelection(); return EditorState.push( editorState, afterRemoval.set('selectionBefore', selection), diff --git a/src/component/handlers/edit/commands/keyCommandPlainDelete.js b/src/component/handlers/edit/commands/keyCommandPlainDelete.js index c353c83349..a8cd73f81e 100644 --- a/src/component/handlers/edit/commands/keyCommandPlainDelete.js +++ b/src/component/handlers/edit/commands/keyCommandPlainDelete.js @@ -12,11 +12,11 @@ 'use strict'; -var EditorState = require('EditorState'); -var UnicodeUtils = require('UnicodeUtils'); +const EditorState = require('EditorState'); +const UnicodeUtils = require('UnicodeUtils'); -var moveSelectionForward = require('moveSelectionForward'); -var removeTextWithStrategy = require('removeTextWithStrategy'); +const moveSelectionForward = require('moveSelectionForward'); +const removeTextWithStrategy = require('removeTextWithStrategy'); /** * Remove the selected range. If the cursor is collapsed, remove the following @@ -24,14 +24,14 @@ var removeTextWithStrategy = require('removeTextWithStrategy'); * will remove a surrogate pair properly as well. */ function keyCommandPlainDelete(editorState: EditorState): EditorState { - var afterRemoval = removeTextWithStrategy( + const afterRemoval = removeTextWithStrategy( editorState, strategyState => { - var selection = strategyState.getSelection(); - var content = strategyState.getCurrentContent(); - var key = selection.getAnchorKey(); - var offset = selection.getAnchorOffset(); - var charAhead = content.getBlockForKey(key).getText()[offset]; + const selection = strategyState.getSelection(); + const content = strategyState.getCurrentContent(); + const key = selection.getAnchorKey(); + const offset = selection.getAnchorOffset(); + const charAhead = content.getBlockForKey(key).getText()[offset]; return moveSelectionForward( strategyState, charAhead ? UnicodeUtils.getUTF16Length(charAhead, 0) : 1, @@ -44,7 +44,7 @@ function keyCommandPlainDelete(editorState: EditorState): EditorState { return editorState; } - var selection = editorState.getSelection(); + const selection = editorState.getSelection(); return EditorState.push( editorState, diff --git a/src/component/handlers/edit/commands/keyCommandTransposeCharacters.js b/src/component/handlers/edit/commands/keyCommandTransposeCharacters.js index 205a06f112..efcab2924d 100644 --- a/src/component/handlers/edit/commands/keyCommandTransposeCharacters.js +++ b/src/component/handlers/edit/commands/keyCommandTransposeCharacters.js @@ -12,10 +12,10 @@ 'use strict'; -var DraftModifier = require('DraftModifier'); -var EditorState = require('EditorState'); +const DraftModifier = require('DraftModifier'); +const EditorState = require('EditorState'); -var getContentStateFragment = require('getContentStateFragment'); +const getContentStateFragment = require('getContentStateFragment'); /** * Transpose the characters on either side of a collapsed cursor, or @@ -23,28 +23,28 @@ var getContentStateFragment = require('getContentStateFragment'); * characters. */ function keyCommandTransposeCharacters(editorState: EditorState): EditorState { - var selection = editorState.getSelection(); + const selection = editorState.getSelection(); if (!selection.isCollapsed()) { return editorState; } - var offset = selection.getAnchorOffset(); + const offset = selection.getAnchorOffset(); if (offset === 0) { return editorState; } - var blockKey = selection.getAnchorKey(); - var content = editorState.getCurrentContent(); - var block = content.getBlockForKey(blockKey); - var length = block.getLength(); + const blockKey = selection.getAnchorKey(); + const content = editorState.getCurrentContent(); + const block = content.getBlockForKey(blockKey); + const length = block.getLength(); // Nothing to transpose if there aren't two characters. if (length <= 1) { return editorState; } - var removalRange; - var finalSelection; + let removalRange; + let finalSelection; if (offset === length) { // The cursor is at the end of the block. Swap the last two characters. @@ -57,28 +57,28 @@ function keyCommandTransposeCharacters(editorState: EditorState): EditorState { // Extract the character to move as a fragment. This preserves its // styling and entity, if any. - var movedFragment = getContentStateFragment(content, removalRange); - var afterRemoval = DraftModifier.removeRange( + const movedFragment = getContentStateFragment(content, removalRange); + const afterRemoval = DraftModifier.removeRange( content, removalRange, 'backward', ); // After the removal, the insertion target is one character back. - var selectionAfter = afterRemoval.getSelectionAfter(); - var targetOffset = selectionAfter.getAnchorOffset() - 1; - var targetRange = selectionAfter.merge({ + const selectionAfter = afterRemoval.getSelectionAfter(); + const targetOffset = selectionAfter.getAnchorOffset() - 1; + const targetRange = selectionAfter.merge({ anchorOffset: targetOffset, focusOffset: targetOffset, }); - var afterInsert = DraftModifier.replaceWithFragment( + const afterInsert = DraftModifier.replaceWithFragment( afterRemoval, targetRange, movedFragment, ); - var newEditorState = EditorState.push( + const newEditorState = EditorState.push( editorState, afterInsert, 'insert-fragment', diff --git a/src/component/handlers/edit/commands/keyCommandUndo.js b/src/component/handlers/edit/commands/keyCommandUndo.js index 7fb1728179..0a3ebf56ca 100644 --- a/src/component/handlers/edit/commands/keyCommandUndo.js +++ b/src/component/handlers/edit/commands/keyCommandUndo.js @@ -12,21 +12,21 @@ 'use strict'; -var EditorState = require('EditorState'); +const EditorState = require('EditorState'); function keyCommandUndo( e: SyntheticKeyboardEvent<>, editorState: EditorState, updateFn: (editorState: EditorState) => void, ): void { - var undoneState = EditorState.undo(editorState); + const undoneState = EditorState.undo(editorState); // If the last change to occur was a spellcheck change, allow the undo // event to fall through to the browser. This allows the browser to record // the unwanted change, which should soon lead it to learn not to suggest // the correction again. if (editorState.getLastChangeType() === 'spellcheck-change') { - var nativelyRenderedContent = undoneState.getCurrentContent(); + const nativelyRenderedContent = undoneState.getCurrentContent(); updateFn(EditorState.set(undoneState, {nativelyRenderedContent})); return; } diff --git a/src/component/handlers/edit/commands/moveSelectionBackward.js b/src/component/handlers/edit/commands/moveSelectionBackward.js index 855e561505..7fecd14b2f 100644 --- a/src/component/handlers/edit/commands/moveSelectionBackward.js +++ b/src/component/handlers/edit/commands/moveSelectionBackward.js @@ -27,21 +27,21 @@ function moveSelectionBackward( editorState: EditorState, maxDistance: number, ): SelectionState { - var selection = editorState.getSelection(); - var content = editorState.getCurrentContent(); - var key = selection.getStartKey(); - var offset = selection.getStartOffset(); + const selection = editorState.getSelection(); + const content = editorState.getCurrentContent(); + const key = selection.getStartKey(); + const offset = selection.getStartOffset(); - var focusKey = key; - var focusOffset = 0; + let focusKey = key; + let focusOffset = 0; if (maxDistance > offset) { - var keyBefore = content.getKeyBefore(key); + const keyBefore = content.getKeyBefore(key); if (keyBefore == null) { focusKey = key; } else { focusKey = keyBefore; - var blockBefore = content.getBlockForKey(keyBefore); + const blockBefore = content.getBlockForKey(keyBefore); focusOffset = blockBefore.getText().length; } } else { diff --git a/src/component/handlers/edit/commands/moveSelectionForward.js b/src/component/handlers/edit/commands/moveSelectionForward.js index c6fa3e2939..ca8d722e3e 100644 --- a/src/component/handlers/edit/commands/moveSelectionForward.js +++ b/src/component/handlers/edit/commands/moveSelectionForward.js @@ -27,15 +27,15 @@ function moveSelectionForward( editorState: EditorState, maxDistance: number, ): SelectionState { - var selection = editorState.getSelection(); - var key = selection.getStartKey(); - var offset = selection.getStartOffset(); - var content = editorState.getCurrentContent(); + const selection = editorState.getSelection(); + const key = selection.getStartKey(); + const offset = selection.getStartOffset(); + const content = editorState.getCurrentContent(); - var focusKey = key; - var focusOffset; + let focusKey = key; + let focusOffset; - var block = content.getBlockForKey(key); + const block = content.getBlockForKey(key); if (maxDistance > block.getText().length - offset) { focusKey = content.getKeyAfter(key); diff --git a/src/component/handlers/edit/commands/removeTextWithStrategy.js b/src/component/handlers/edit/commands/removeTextWithStrategy.js index b26da7dc77..f2a00536c2 100644 --- a/src/component/handlers/edit/commands/removeTextWithStrategy.js +++ b/src/component/handlers/edit/commands/removeTextWithStrategy.js @@ -17,7 +17,7 @@ import type {DraftRemovalDirection} from 'DraftRemovalDirection'; import type EditorState from 'EditorState'; import type SelectionState from 'SelectionState'; -var DraftModifier = require('DraftModifier'); +const DraftModifier = require('DraftModifier'); /** * For a collapsed selection state, remove text based on the specified strategy. @@ -28,9 +28,9 @@ function removeTextWithStrategy( strategy: (editorState: EditorState) => SelectionState, direction: DraftRemovalDirection, ): ContentState { - var selection = editorState.getSelection(); - var content = editorState.getCurrentContent(); - var target = selection; + const selection = editorState.getSelection(); + const content = editorState.getCurrentContent(); + let target = selection; if (selection.isCollapsed()) { if (direction === 'forward') { if (editorState.isSelectionAtEndOfContent()) { diff --git a/src/component/handlers/edit/editOnBeforeInput.js b/src/component/handlers/edit/editOnBeforeInput.js index 6bf02e1595..425a60ad83 100644 --- a/src/component/handlers/edit/editOnBeforeInput.js +++ b/src/component/handlers/edit/editOnBeforeInput.js @@ -15,16 +15,16 @@ import type DraftEditor from 'DraftEditor.react'; import type {DraftInlineStyle} from 'DraftInlineStyle'; -var BlockTree = require('BlockTree'); -var DraftModifier = require('DraftModifier'); -var EditorState = require('EditorState'); -var UserAgent = require('UserAgent'); +const BlockTree = require('BlockTree'); +const DraftModifier = require('DraftModifier'); +const EditorState = require('EditorState'); +const UserAgent = require('UserAgent'); -var getEntityKeyForSelection = require('getEntityKeyForSelection'); +const getEntityKeyForSelection = require('getEntityKeyForSelection'); const isEventHandled = require('isEventHandled'); -var isSelectionAtLeafStart = require('isSelectionAtLeafStart'); -var nullthrows = require('nullthrows'); -var setImmediate = require('setImmediate'); +const isSelectionAtLeafStart = require('isSelectionAtLeafStart'); +const nullthrows = require('nullthrows'); +const setImmediate = require('setImmediate'); // When nothing is focused, Firefox regards two characters, `'` and `/`, as // commands that should open and focus the "quickfind" search bar. This should @@ -33,9 +33,9 @@ var setImmediate = require('setImmediate'); // This breaks the input. Special case these characters to ensure that when // they are typed, we prevent default on the event to make sure not to // trigger quickfind. -var FF_QUICKFIND_CHAR = "'"; -var FF_QUICKFIND_LINK_CHAR = '/'; -var isFirefox = UserAgent.isBrowser('Firefox'); +const FF_QUICKFIND_CHAR = "'"; +const FF_QUICKFIND_LINK_CHAR = '/'; +const isFirefox = UserAgent.isBrowser('Firefox'); function mustPreventDefaultForCharacter(character: string): boolean { return ( @@ -54,7 +54,7 @@ function replaceText( inlineStyle: DraftInlineStyle, entityKey: ?string, ): EditorState { - var contentState = DraftModifier.replaceText( + const contentState = DraftModifier.replaceText( editorState.getCurrentContent(), editorState.getSelection(), text, @@ -84,7 +84,7 @@ function editOnBeforeInput( const editorState = editor._latestEditorState; - var chars = e.data; + const chars = e.data; // In some cases (ex: IE ideographic space insertion) no character data // is provided. There's nothing to do when this happens. @@ -108,10 +108,10 @@ function editOnBeforeInput( // If selection is collapsed, conditionally allow native behavior. This // reduces re-renders and preserves spellcheck highlighting. If the selection // is not collapsed, we will re-render. - var selection = editorState.getSelection(); - var selectionStart = selection.getStartOffset(); - var selectionEnd = selection.getEndOffset(); - var anchorKey = selection.getAnchorKey(); + const selection = editorState.getSelection(); + const selectionStart = selection.getStartOffset(); + const selectionEnd = selection.getEndOffset(); + const anchorKey = selection.getAnchorKey(); if (!selection.isCollapsed()) { e.preventDefault(); @@ -119,7 +119,7 @@ function editOnBeforeInput( // If the currently selected text matches what the user is trying to // replace it with, let's just update the `SelectionState`. If not, update // the `ContentState` with the new text. - var currentlySelectedChars = editorState + const currentlySelectedChars = editorState .getCurrentContent() .getPlainText() .slice(selectionStart, selectionEnd); @@ -149,7 +149,7 @@ function editOnBeforeInput( return; } - var newEditorState = replaceText( + let newEditorState = replaceText( editorState, chars, editorState.getCurrentInlineStyle(), @@ -190,10 +190,10 @@ function editOnBeforeInput( // Check the old and new "fingerprints" of the current block to determine // whether this insertion requires any addition or removal of text nodes, // in which case we would prevent the native character insertion. - var originalFingerprint = BlockTree.getFingerprint( + const originalFingerprint = BlockTree.getFingerprint( editorState.getBlockTree(anchorKey), ); - var newFingerprint = BlockTree.getFingerprint( + const newFingerprint = BlockTree.getFingerprint( newEditorState.getBlockTree(anchorKey), ); mustPreventNative = originalFingerprint !== newFingerprint; diff --git a/src/component/handlers/edit/editOnBlur.js b/src/component/handlers/edit/editOnBlur.js index 5463cf3689..11a3d86cd7 100644 --- a/src/component/handlers/edit/editOnBlur.js +++ b/src/component/handlers/edit/editOnBlur.js @@ -40,13 +40,13 @@ function editOnBlur(editor: DraftEditor, e: SyntheticEvent<>): void { } } - var editorState = editor._latestEditorState; - var currentSelection = editorState.getSelection(); + const editorState = editor._latestEditorState; + const currentSelection = editorState.getSelection(); if (!currentSelection.getHasFocus()) { return; } - var selection = currentSelection.set('hasFocus', false); + const selection = currentSelection.set('hasFocus', false); editor.props.onBlur && editor.props.onBlur(e); editor.update(EditorState.acceptSelection(editorState, selection)); } diff --git a/src/component/handlers/edit/editOnCompositionStart.js b/src/component/handlers/edit/editOnCompositionStart.js index fc14fd2e6c..201486f426 100644 --- a/src/component/handlers/edit/editOnCompositionStart.js +++ b/src/component/handlers/edit/editOnCompositionStart.js @@ -14,7 +14,7 @@ import type DraftEditor from 'DraftEditor.react'; -var EditorState = require('EditorState'); +const EditorState = require('EditorState'); /** * The user has begun using an IME input system. Switching to `composite` mode diff --git a/src/component/handlers/edit/editOnCopy.js b/src/component/handlers/edit/editOnCopy.js index 0155c31f15..605532e70a 100644 --- a/src/component/handlers/edit/editOnCopy.js +++ b/src/component/handlers/edit/editOnCopy.js @@ -14,7 +14,7 @@ import type DraftEditor from 'DraftEditor.react'; -var getFragmentFromSelection = require('getFragmentFromSelection'); +const getFragmentFromSelection = require('getFragmentFromSelection'); /** * If we have a selection, create a ContentState fragment and store @@ -22,8 +22,8 @@ var getFragmentFromSelection = require('getFragmentFromSelection'); * fragment if no external clipboard data is supplied. */ function editOnCopy(editor: DraftEditor, e: SyntheticClipboardEvent<>): void { - var editorState = editor._latestEditorState; - var selection = editorState.getSelection(); + const editorState = editor._latestEditorState; + const selection = editorState.getSelection(); // No selection, so there's nothing to copy. if (selection.isCollapsed()) { diff --git a/src/component/handlers/edit/editOnFocus.js b/src/component/handlers/edit/editOnFocus.js index 33bd0e9099..eb12d12a69 100644 --- a/src/component/handlers/edit/editOnFocus.js +++ b/src/component/handlers/edit/editOnFocus.js @@ -14,17 +14,17 @@ import type DraftEditor from 'DraftEditor.react'; -var EditorState = require('EditorState'); -var UserAgent = require('UserAgent'); +const EditorState = require('EditorState'); +const UserAgent = require('UserAgent'); function editOnFocus(editor: DraftEditor, e: SyntheticFocusEvent<>): void { - var editorState = editor._latestEditorState; - var currentSelection = editorState.getSelection(); + const editorState = editor._latestEditorState; + const currentSelection = editorState.getSelection(); if (currentSelection.getHasFocus()) { return; } - var selection = currentSelection.set('hasFocus', true); + const selection = currentSelection.set('hasFocus', true); editor.props.onFocus && editor.props.onFocus(e); // When the tab containing this text editor is hidden and the user does a diff --git a/src/component/handlers/edit/editOnInput.js b/src/component/handlers/edit/editOnInput.js index aa7a7c9d2f..0e481fc41e 100644 --- a/src/component/handlers/edit/editOnInput.js +++ b/src/component/handlers/edit/editOnInput.js @@ -14,18 +14,18 @@ import type DraftEditor from 'DraftEditor.react'; -var DraftModifier = require('DraftModifier'); -var DraftOffsetKey = require('DraftOffsetKey'); -var EditorState = require('EditorState'); -var UserAgent = require('UserAgent'); +const DraftModifier = require('DraftModifier'); +const DraftOffsetKey = require('DraftOffsetKey'); +const EditorState = require('EditorState'); +const UserAgent = require('UserAgent'); -var findAncestorOffsetKey = require('findAncestorOffsetKey'); +const findAncestorOffsetKey = require('findAncestorOffsetKey'); const gkx = require('gkx'); -var nullthrows = require('nullthrows'); +const nullthrows = require('nullthrows'); -var isGecko = UserAgent.isEngine('Gecko'); +const isGecko = UserAgent.isEngine('Gecko'); -var DOUBLE_NEWLINE = '\n\n'; +const DOUBLE_NEWLINE = '\n\n'; /** * This function is intended to handle spellcheck and autocorrect changes, @@ -45,9 +45,9 @@ function editOnInput(editor: DraftEditor): void { editor._pendingStateFromBeforeInput = undefined; } - var domSelection = global.getSelection(); + const domSelection = global.getSelection(); - var {anchorNode, isCollapsed} = domSelection; + const {anchorNode, isCollapsed} = domSelection; const isNotTextNode = anchorNode.nodeType !== Node.TEXT_NODE; const isNotTextOrElementNode = anchorNode.nodeType !== Node.TEXT_NODE && @@ -85,18 +85,18 @@ function editOnInput(editor: DraftEditor): void { } } - var domText = anchorNode.textContent; - var editorState = editor._latestEditorState; - var offsetKey = nullthrows(findAncestorOffsetKey(anchorNode)); - var {blockKey, decoratorKey, leafKey} = DraftOffsetKey.decode(offsetKey); + let domText = anchorNode.textContent; + const editorState = editor._latestEditorState; + const offsetKey = nullthrows(findAncestorOffsetKey(anchorNode)); + const {blockKey, decoratorKey, leafKey} = DraftOffsetKey.decode(offsetKey); - var {start, end} = editorState + const {start, end} = editorState .getBlockTree(blockKey) .getIn([decoratorKey, 'leaves', leafKey]); - var content = editorState.getCurrentContent(); - var block = content.getBlockForKey(blockKey); - var modelText = block.getText().slice(start, end); + const content = editorState.getCurrentContent(); + const block = content.getBlockForKey(blockKey); + const modelText = block.getText().slice(start, end); // Special-case soft newlines here. If the DOM text ends in a soft newline, // we will have manually inserted an extra soft newline in DraftEditorLeaf. @@ -115,10 +115,10 @@ function editOnInput(editor: DraftEditor): void { return; } - var selection = editorState.getSelection(); + const selection = editorState.getSelection(); // We'll replace the entire leaf with the text content of the target. - var targetRange = selection.merge({ + const targetRange = selection.merge({ anchorOffset: start, focusOffset: end, isBackward: false, @@ -143,7 +143,7 @@ function editOnInput(editor: DraftEditor): void { preserveEntity ? block.getEntityAt(start) : null, ); - var anchorOffset, focusOffset, startOffset, endOffset; + let anchorOffset, focusOffset, startOffset, endOffset; if (isGecko) { // Firefox selection does not change while the context menu is open, so @@ -160,7 +160,7 @@ function editOnInput(editor: DraftEditor): void { // DOM selection. Don't trust it. Instead, use our existing SelectionState // and adjust it based on the number of characters changed during the // mutation. - var charDelta = domText.length - modelText.length; + const charDelta = domText.length - modelText.length; startOffset = selection.getStartOffset(); endOffset = selection.getEndOffset(); @@ -171,7 +171,7 @@ function editOnInput(editor: DraftEditor): void { // Segmented entities are completely or partially removed when their // text content changes. For this case we do not want any text to be selected // after the change, so we are not merging the selection. - var contentWithAdjustedDOMSelection = newContent.merge({ + const contentWithAdjustedDOMSelection = newContent.merge({ selectionBefore: content.getSelectionAfter(), selectionAfter: selection.merge({anchorOffset, focusOffset}), }); diff --git a/src/component/handlers/edit/editOnKeyDown.js b/src/component/handlers/edit/editOnKeyDown.js index 7cdcef70d2..4f48a0551f 100644 --- a/src/component/handlers/edit/editOnKeyDown.js +++ b/src/component/handlers/edit/editOnKeyDown.js @@ -15,27 +15,27 @@ import type DraftEditor from 'DraftEditor.react'; import type {DraftEditorCommand} from 'DraftEditorCommand'; -var DraftModifier = require('DraftModifier'); -var EditorState = require('EditorState'); -var KeyBindingUtil = require('KeyBindingUtil'); -var Keys = require('Keys'); -var SecondaryClipboard = require('SecondaryClipboard'); -var UserAgent = require('UserAgent'); +const DraftModifier = require('DraftModifier'); +const EditorState = require('EditorState'); +const KeyBindingUtil = require('KeyBindingUtil'); +const Keys = require('Keys'); +const SecondaryClipboard = require('SecondaryClipboard'); +const UserAgent = require('UserAgent'); const isEventHandled = require('isEventHandled'); -var keyCommandBackspaceToStartOfLine = require('keyCommandBackspaceToStartOfLine'); -var keyCommandBackspaceWord = require('keyCommandBackspaceWord'); -var keyCommandDeleteWord = require('keyCommandDeleteWord'); -var keyCommandInsertNewline = require('keyCommandInsertNewline'); -var keyCommandMoveSelectionToEndOfBlock = require('keyCommandMoveSelectionToEndOfBlock'); -var keyCommandMoveSelectionToStartOfBlock = require('keyCommandMoveSelectionToStartOfBlock'); -var keyCommandPlainBackspace = require('keyCommandPlainBackspace'); -var keyCommandPlainDelete = require('keyCommandPlainDelete'); -var keyCommandTransposeCharacters = require('keyCommandTransposeCharacters'); -var keyCommandUndo = require('keyCommandUndo'); +const keyCommandBackspaceToStartOfLine = require('keyCommandBackspaceToStartOfLine'); +const keyCommandBackspaceWord = require('keyCommandBackspaceWord'); +const keyCommandDeleteWord = require('keyCommandDeleteWord'); +const keyCommandInsertNewline = require('keyCommandInsertNewline'); +const keyCommandMoveSelectionToEndOfBlock = require('keyCommandMoveSelectionToEndOfBlock'); +const keyCommandMoveSelectionToStartOfBlock = require('keyCommandMoveSelectionToStartOfBlock'); +const keyCommandPlainBackspace = require('keyCommandPlainBackspace'); +const keyCommandPlainDelete = require('keyCommandPlainDelete'); +const keyCommandTransposeCharacters = require('keyCommandTransposeCharacters'); +const keyCommandUndo = require('keyCommandUndo'); -var {isOptionKeyCommand} = KeyBindingUtil; -var isChrome = UserAgent.isBrowser('Chrome'); +const {isOptionKeyCommand} = KeyBindingUtil; +const isChrome = UserAgent.isBrowser('Chrome'); /** * Map a `DraftEditorCommand` command value to a corresponding function. @@ -84,8 +84,8 @@ function onKeyCommand( * component may provide a custom mapping via the `keyBindingFn` prop. */ function editOnKeyDown(editor: DraftEditor, e: SyntheticKeyboardEvent<>): void { - var keyCode = e.which; - var editorState = editor._latestEditorState; + const keyCode = e.which; + const editorState = editor._latestEditorState; function callDeprecatedHandler( handlerName: | 'onDownArrow' @@ -163,7 +163,7 @@ function editOnKeyDown(editor: DraftEditor, e: SyntheticKeyboardEvent<>): void { } } - var command = editor.props.keyBindingFn(e); + const command = editor.props.keyBindingFn(e); // If no command is specified, allow keydown event to continue. if (!command) { @@ -189,7 +189,7 @@ function editOnKeyDown(editor: DraftEditor, e: SyntheticKeyboardEvent<>): void { return; } - var newState = onKeyCommand(command, editorState); + const newState = onKeyCommand(command, editorState); if (newState !== editorState) { editor.update(newState); } diff --git a/src/component/handlers/edit/editOnPaste.js b/src/component/handlers/edit/editOnPaste.js index fad7f09e6b..738788ad59 100644 --- a/src/component/handlers/edit/editOnPaste.js +++ b/src/component/handlers/edit/editOnPaste.js @@ -16,30 +16,30 @@ import type {BlockMap} from 'BlockMap'; import type DraftEditor from 'DraftEditor.react'; import type {EntityMap} from 'EntityMap'; -var BlockMapBuilder = require('BlockMapBuilder'); -var CharacterMetadata = require('CharacterMetadata'); -var DataTransfer = require('DataTransfer'); -var DraftModifier = require('DraftModifier'); -var DraftPasteProcessor = require('DraftPasteProcessor'); -var EditorState = require('EditorState'); -var RichTextEditorUtil = require('RichTextEditorUtil'); - -var getEntityKeyForSelection = require('getEntityKeyForSelection'); -var getTextContentFromFiles = require('getTextContentFromFiles'); +const BlockMapBuilder = require('BlockMapBuilder'); +const CharacterMetadata = require('CharacterMetadata'); +const DataTransfer = require('DataTransfer'); +const DraftModifier = require('DraftModifier'); +const DraftPasteProcessor = require('DraftPasteProcessor'); +const EditorState = require('EditorState'); +const RichTextEditorUtil = require('RichTextEditorUtil'); + +const getEntityKeyForSelection = require('getEntityKeyForSelection'); +const getTextContentFromFiles = require('getTextContentFromFiles'); const isEventHandled = require('isEventHandled'); -var splitTextIntoTextBlocks = require('splitTextIntoTextBlocks'); +const splitTextIntoTextBlocks = require('splitTextIntoTextBlocks'); /** * Paste content. */ function editOnPaste(editor: DraftEditor, e: SyntheticClipboardEvent<>): void { e.preventDefault(); - var data = new DataTransfer(e.clipboardData); + const data = new DataTransfer(e.clipboardData); // Get files, unless this is likely to be a string the user wants inline. if (!data.isRichText()) { - var files = data.getFiles(); - var defaultFileText = data.getText(); + const files = data.getFiles(); + const defaultFileText = data.getText(); if (files.length > 0) { // Allow customized paste handling for images, etc. Otherwise, fall // through to insert text contents into the editor. @@ -56,27 +56,27 @@ function editOnPaste(editor: DraftEditor, e: SyntheticClipboardEvent<>): void { return; } - var editorState = editor._latestEditorState; - var blocks = splitTextIntoTextBlocks(fileText); - var character = CharacterMetadata.create({ + const editorState = editor._latestEditorState; + const blocks = splitTextIntoTextBlocks(fileText); + const character = CharacterMetadata.create({ style: editorState.getCurrentInlineStyle(), entity: getEntityKeyForSelection( editorState.getCurrentContent(), editorState.getSelection(), ), }); - var currentBlockType = RichTextEditorUtil.getCurrentBlockType( + const currentBlockType = RichTextEditorUtil.getCurrentBlockType( editorState, ); - var text = DraftPasteProcessor.processText( + const text = DraftPasteProcessor.processText( blocks, character, currentBlockType, ); - var fragment = BlockMapBuilder.createFromArray(text); + const fragment = BlockMapBuilder.createFromArray(text); - var withInsertedText = DraftModifier.replaceWithFragment( + const withInsertedText = DraftModifier.replaceWithFragment( editorState.getCurrentContent(), editorState.getSelection(), fragment, @@ -150,14 +150,14 @@ function editOnPaste(editor: DraftEditor, e: SyntheticClipboardEvent<>): void { // If there is html paste data, try to parse that. if (html) { - var htmlFragment = DraftPasteProcessor.processHTML( + const htmlFragment = DraftPasteProcessor.processHTML( html, editor.props.blockRenderMap, ); if (htmlFragment) { const {contentBlocks, entityMap} = htmlFragment; if (contentBlocks) { - var htmlMap = BlockMapBuilder.createFromArray(contentBlocks); + const htmlMap = BlockMapBuilder.createFromArray(contentBlocks); editor.update( insertFragment(editor._latestEditorState, htmlMap, entityMap), ); @@ -172,7 +172,7 @@ function editOnPaste(editor: DraftEditor, e: SyntheticClipboardEvent<>): void { } if (textBlocks.length) { - var character = CharacterMetadata.create({ + const character = CharacterMetadata.create({ style: editorState.getCurrentInlineStyle(), entity: getEntityKeyForSelection( editorState.getCurrentContent(), @@ -180,15 +180,17 @@ function editOnPaste(editor: DraftEditor, e: SyntheticClipboardEvent<>): void { ), }); - var currentBlockType = RichTextEditorUtil.getCurrentBlockType(editorState); + const currentBlockType = RichTextEditorUtil.getCurrentBlockType( + editorState, + ); - var textFragment = DraftPasteProcessor.processText( + const textFragment = DraftPasteProcessor.processText( textBlocks, character, currentBlockType, ); - var textMap = BlockMapBuilder.createFromArray(textFragment); + const textMap = BlockMapBuilder.createFromArray(textFragment); editor.update(insertFragment(editor._latestEditorState, textMap)); } } @@ -198,7 +200,7 @@ function insertFragment( fragment: BlockMap, entityMap: ?EntityMap, ): EditorState { - var newContent = DraftModifier.replaceWithFragment( + const newContent = DraftModifier.replaceWithFragment( editorState.getCurrentContent(), editorState.getSelection(), fragment, diff --git a/src/component/handlers/edit/editOnSelect.js b/src/component/handlers/edit/editOnSelect.js index 2187632261..39c957c3ce 100644 --- a/src/component/handlers/edit/editOnSelect.js +++ b/src/component/handlers/edit/editOnSelect.js @@ -15,10 +15,10 @@ import type DraftEditor from 'DraftEditor.react'; const DraftJsDebugLogging = require('DraftJsDebugLogging'); -var EditorState = require('EditorState'); -var ReactDOM = require('ReactDOM'); +const EditorState = require('EditorState'); +const ReactDOM = require('ReactDOM'); -var getDraftEditorSelection = require('getDraftEditorSelection'); +const getDraftEditorSelection = require('getDraftEditorSelection'); const invariant = require('invariant'); function editOnSelect(editor: DraftEditor): void { @@ -39,18 +39,18 @@ function editOnSelect(editor: DraftEditor): void { return; } - var editorState = editor.props.editorState; + let editorState = editor.props.editorState; const editorNode = ReactDOM.findDOMNode(editor.editorContainer); invariant(editorNode, 'Missing editorNode'); invariant( editorNode.firstChild instanceof HTMLElement, 'editorNode.firstChild is not an HTMLElement', ); - var documentSelection = getDraftEditorSelection( + const documentSelection = getDraftEditorSelection( editorState, editorNode.firstChild, ); - var updatedSelectionState = documentSelection.selectionState; + const updatedSelectionState = documentSelection.selectionState; if (updatedSelectionState !== editorState.getSelection()) { if (documentSelection.needsRecovery) { diff --git a/src/component/handlers/edit/getFragmentFromSelection.js b/src/component/handlers/edit/getFragmentFromSelection.js index ade367a244..eaeb74aefb 100644 --- a/src/component/handlers/edit/getFragmentFromSelection.js +++ b/src/component/handlers/edit/getFragmentFromSelection.js @@ -15,10 +15,10 @@ import type {BlockMap} from 'BlockMap'; import type EditorState from 'EditorState'; -var getContentStateFragment = require('getContentStateFragment'); +const getContentStateFragment = require('getContentStateFragment'); function getFragmentFromSelection(editorState: EditorState): ?BlockMap { - var selectionState = editorState.getSelection(); + const selectionState = editorState.getSelection(); if (selectionState.isCollapsed()) { return null; diff --git a/src/component/selection/DraftOffsetKey.js b/src/component/selection/DraftOffsetKey.js index 1e4defc992..76e3746dcd 100644 --- a/src/component/selection/DraftOffsetKey.js +++ b/src/component/selection/DraftOffsetKey.js @@ -14,9 +14,9 @@ import type {DraftOffsetKeyPath} from 'DraftOffsetKeyPath'; -var KEY_DELIMITER = '-'; +const KEY_DELIMITER = '-'; -var DraftOffsetKey = { +const DraftOffsetKey = { encode: function( blockKey: string, decoratorKey: number, @@ -26,7 +26,7 @@ var DraftOffsetKey = { }, decode: function(offsetKey: string): DraftOffsetKeyPath { - var [blockKey, decoratorKey, leafKey] = offsetKey.split(KEY_DELIMITER); + const [blockKey, decoratorKey, leafKey] = offsetKey.split(KEY_DELIMITER); return { blockKey, decoratorKey: parseInt(decoratorKey, 10), diff --git a/src/component/selection/expandRangeToStartOfLine.js b/src/component/selection/expandRangeToStartOfLine.js index c1898e2a5f..726fcb9c71 100644 --- a/src/component/selection/expandRangeToStartOfLine.js +++ b/src/component/selection/expandRangeToStartOfLine.js @@ -10,17 +10,17 @@ * @flow */ -var UnicodeUtils = require('UnicodeUtils'); +const UnicodeUtils = require('UnicodeUtils'); -var getRangeClientRects = require('getRangeClientRects'); -var invariant = require('invariant'); +const getRangeClientRects = require('getRangeClientRects'); +const invariant = require('invariant'); /** * Return the computed line height, in pixels, for the provided element. */ function getLineHeightPx(element: Element): number { - var computed = getComputedStyle(element); - var div = document.createElement('div'); + const computed = getComputedStyle(element); + const div = document.createElement('div'); div.style.fontFamily = computed.fontFamily; div.style.fontSize = computed.fontSize; div.style.fontStyle = computed.fontStyle; @@ -34,7 +34,7 @@ function getLineHeightPx(element: Element): number { // forced layout here documentBody.appendChild(div); - var rect = div.getBoundingClientRect(); + const rect = div.getBoundingClientRect(); documentBody.removeChild(div); return rect.height; @@ -56,13 +56,13 @@ function areRectsOnOneLine( rects: Array, lineHeight: number, ): boolean { - var minTop = Infinity; - var minBottom = Infinity; - var maxTop = -Infinity; - var maxBottom = -Infinity; + let minTop = Infinity; + let minBottom = Infinity; + let maxTop = -Infinity; + let maxBottom = -Infinity; - for (var ii = 0; ii < rects.length; ii++) { - var rect = rects[ii]; + for (let ii = 0; ii < rects.length; ii++) { + const rect = rects[ii]; if (rect.width === 0 || rect.width === 1) { // When a range starts or ends a soft wrap, many browsers (Chrome, IE, // Safari) include an empty rect on the previous or next line. When the @@ -114,11 +114,11 @@ function expandRangeToStartOfLine(range: Range): Range { ); range = range.cloneRange(); - var containingElement = range.startContainer; + let containingElement = range.startContainer; if (containingElement.nodeType !== 1) { containingElement = containingElement.parentNode; } - var lineHeight = getLineHeightPx((containingElement: any)); + const lineHeight = getLineHeightPx((containingElement: any)); // Imagine our text looks like: //
once upon a time, there was a boy @@ -131,8 +131,8 @@ function expandRangeToStartOfLine(range: Range): Range { // the break point is inside the span, then inside the , then in its text // node child, the actual break point before "who". - var bestContainer = range.endContainer; - var bestOffset = range.endOffset; + let bestContainer = range.endContainer; + let bestOffset = range.endOffset; range.setStart(range.startContainer, 0); while (areRectsOnOneLine(getRangeClientRects(range), lineHeight)) { @@ -161,13 +161,14 @@ function expandRangeToStartOfLine(range: Range): Range { // At all times, (bestContainer, bestOffset) is the latest single-line start // point that we know of. - var currentContainer = bestContainer; - var maxIndexToConsider = bestOffset - 1; + let currentContainer = bestContainer; + let maxIndexToConsider = bestOffset - 1; do { - var nodeValue = currentContainer.nodeValue; + const nodeValue = currentContainer.nodeValue; + let ii = maxIndexToConsider; - for (var ii = maxIndexToConsider; ii >= 0; ii--) { + for (; ii >= 0; ii--) { if ( nodeValue != null && ii > 0 && diff --git a/src/component/selection/findAncestorOffsetKey.js b/src/component/selection/findAncestorOffsetKey.js index ccc2812ae6..befa142820 100644 --- a/src/component/selection/findAncestorOffsetKey.js +++ b/src/component/selection/findAncestorOffsetKey.js @@ -12,7 +12,7 @@ 'use strict'; -var getSelectionOffsetKeyForNode = require('getSelectionOffsetKeyForNode'); +const getSelectionOffsetKeyForNode = require('getSelectionOffsetKeyForNode'); /** * Get the key from the node's nearest offset-aware ancestor. @@ -20,7 +20,7 @@ var getSelectionOffsetKeyForNode = require('getSelectionOffsetKeyForNode'); function findAncestorOffsetKey(node: Node): ?string { let searchNode = node; while (searchNode && searchNode !== document.documentElement) { - var key = getSelectionOffsetKeyForNode(searchNode); + const key = getSelectionOffsetKeyForNode(searchNode); if (key != null) { return key; } diff --git a/src/component/selection/getDraftEditorSelection.js b/src/component/selection/getDraftEditorSelection.js index 6eed3fd793..59df1bb00a 100644 --- a/src/component/selection/getDraftEditorSelection.js +++ b/src/component/selection/getDraftEditorSelection.js @@ -15,7 +15,7 @@ import type {DOMDerivedSelection} from 'DOMDerivedSelection'; import type EditorState from 'EditorState'; -var getDraftEditorSelectionWithNodes = require('getDraftEditorSelectionWithNodes'); +const getDraftEditorSelectionWithNodes = require('getDraftEditorSelectionWithNodes'); /** * Convert the current selection range to an anchor/focus pair of offset keys @@ -25,7 +25,7 @@ function getDraftEditorSelection( editorState: EditorState, root: HTMLElement, ): DOMDerivedSelection { - var selection = global.getSelection(); + const selection = global.getSelection(); // No active selection. if (selection.rangeCount === 0) { diff --git a/src/component/selection/getDraftEditorSelectionWithNodes.js b/src/component/selection/getDraftEditorSelectionWithNodes.js index 57c64a8b70..cb1f6b1b20 100644 --- a/src/component/selection/getDraftEditorSelectionWithNodes.js +++ b/src/component/selection/getDraftEditorSelectionWithNodes.js @@ -15,11 +15,11 @@ import type {DOMDerivedSelection} from 'DOMDerivedSelection'; import type EditorState from 'EditorState'; -var findAncestorOffsetKey = require('findAncestorOffsetKey'); -var getSelectionOffsetKeyForNode = require('getSelectionOffsetKeyForNode'); -var getUpdatedSelectionState = require('getUpdatedSelectionState'); -var invariant = require('invariant'); -var nullthrows = require('nullthrows'); +const findAncestorOffsetKey = require('findAncestorOffsetKey'); +const getSelectionOffsetKeyForNode = require('getSelectionOffsetKeyForNode'); +const getUpdatedSelectionState = require('getUpdatedSelectionState'); +const invariant = require('invariant'); +const nullthrows = require('nullthrows'); type SelectionPoint = { key: string, @@ -38,8 +38,8 @@ function getDraftEditorSelectionWithNodes( focusNode: Node, focusOffset: number, ): DOMDerivedSelection { - var anchorIsTextNode = anchorNode.nodeType === Node.TEXT_NODE; - var focusIsTextNode = focusNode.nodeType === Node.TEXT_NODE; + const anchorIsTextNode = anchorNode.nodeType === Node.TEXT_NODE; + const focusIsTextNode = focusNode.nodeType === Node.TEXT_NODE; // If the selection range lies only on text nodes, the task is simple. // Find the nearest offset-aware elements and use the @@ -57,9 +57,9 @@ function getDraftEditorSelectionWithNodes( }; } - var anchorPoint = null; - var focusPoint = null; - var needsRecovery = true; + let anchorPoint = null; + let focusPoint = null; + let needsRecovery = true; // An element is selected. Convert this selection range into leaf offset // keys and offset values for consumption at the component level. This @@ -155,7 +155,7 @@ function getPointForNonTextNode( childOffset: number, ): SelectionPoint { let node = startNode; - var offsetKey: ?string = findAncestorOffsetKey(node); + const offsetKey: ?string = findAncestorOffsetKey(node); invariant( offsetKey != null || @@ -181,19 +181,19 @@ function getPointForNonTextNode( // find the leftmost ("first") leaf in the tree and use that as the offset // key. if (childOffset === 0) { - var key: ?string = null; + let key: ?string = null; if (offsetKey != null) { key = offsetKey; } else { - var firstLeaf = getFirstLeaf(node); + const firstLeaf = getFirstLeaf(node); key = nullthrows(getSelectionOffsetKeyForNode(firstLeaf)); } return {key, offset: 0}; } - var nodeBeforeCursor = node.childNodes[childOffset - 1]; - var leafKey: ?string = null; - var textLength: ?number = null; + const nodeBeforeCursor = node.childNodes[childOffset - 1]; + let leafKey: ?string = null; + let textLength: ?number = null; if (!getSelectionOffsetKeyForNode(nodeBeforeCursor)) { // Our target node may be a leaf or a text node, in which case we're @@ -204,7 +204,7 @@ function getPointForNonTextNode( } else { // Otherwise, we'll look at the child to the left of the cursor and find // the last leaf node in its subtree. - var lastLeaf = getLastLeaf(nodeBeforeCursor); + const lastLeaf = getLastLeaf(nodeBeforeCursor); leafKey = nullthrows(getSelectionOffsetKeyForNode(lastLeaf)); textLength = getTextContentLength(lastLeaf); } @@ -222,7 +222,7 @@ function getPointForNonTextNode( * render newlines instead of break tags. */ function getTextContentLength(node: Node): number { - var textContent = node.textContent; + const textContent = node.textContent; return textContent === '\n' ? 0 : textContent.length; } diff --git a/src/component/selection/getRangeBoundingClientRect.js b/src/component/selection/getRangeBoundingClientRect.js index 6c362fef23..55c2d5e88d 100644 --- a/src/component/selection/getRangeBoundingClientRect.js +++ b/src/component/selection/getRangeBoundingClientRect.js @@ -12,7 +12,7 @@ 'use strict'; -var getRangeClientRects = require('getRangeClientRects'); +const getRangeClientRects = require('getRangeClientRects'); export type FakeClientRect = { left: number, @@ -31,11 +31,11 @@ function getRangeBoundingClientRect(range: Range): FakeClientRect { // the first rectangle in list and all of the remaining rectangles of which // the height or width is not zero." // http://www.w3.org/TR/cssom-view/#dom-range-getboundingclientrect - var rects = getRangeClientRects(range); - var top = 0; - var right = 0; - var bottom = 0; - var left = 0; + const rects = getRangeClientRects(range); + let top = 0; + let right = 0; + let bottom = 0; + let left = 0; if (rects.length) { // If the first rectangle has 0 width, we use the second, this is needed @@ -47,8 +47,8 @@ function getRangeBoundingClientRect(range: Range): FakeClientRect { ({top, right, bottom, left} = rects[0]); } - for (var ii = 1; ii < rects.length; ii++) { - var rect = rects[ii]; + for (let ii = 1; ii < rects.length; ii++) { + let rect = rects[ii]; if (rect.height !== 0 && rect.width !== 0) { top = Math.min(top, rect.top); right = Math.max(right, rect.right); diff --git a/src/component/selection/getRangeClientRects.js b/src/component/selection/getRangeClientRects.js index 84b08593e3..d6744815be 100644 --- a/src/component/selection/getRangeClientRects.js +++ b/src/component/selection/getRangeClientRects.js @@ -12,11 +12,11 @@ 'use strict'; -var UserAgent = require('UserAgent'); +const UserAgent = require('UserAgent'); -var invariant = require('invariant'); +const invariant = require('invariant'); -var isChrome = UserAgent.isBrowser('Chrome'); +const isChrome = UserAgent.isBrowser('Chrome'); // In Chrome, the client rects will include the entire bounds of all nodes that // begin (have a start tag) within the selection, even if the selection does @@ -25,23 +25,23 @@ var isChrome = UserAgent.isBrowser('Chrome'); // https://code.google.com/p/chromium/issues/detail?id=324437 /* eslint-disable consistent-return */ function getRangeClientRectsChrome(range: Range): Array { - var tempRange = range.cloneRange(); - var clientRects = []; + const tempRange = range.cloneRange(); + const clientRects = []; for ( - var ancestor = range.endContainer; + let ancestor = range.endContainer; ancestor != null; ancestor = ancestor.parentNode ) { // If we've climbed up to the common ancestor, we can now use the // original start point and stop climbing the tree. - var atCommonAncestor = ancestor === range.commonAncestorContainer; + const atCommonAncestor = ancestor === range.commonAncestorContainer; if (atCommonAncestor) { tempRange.setStart(range.startContainer, range.startOffset); } else { tempRange.setStart(tempRange.endContainer, 0); } - var rects = Array.from(tempRange.getClientRects()); + const rects = Array.from(tempRange.getClientRects()); clientRects.push(rects); if (atCommonAncestor) { clientRects.reverse(); @@ -60,7 +60,7 @@ function getRangeClientRectsChrome(range: Range): Array { /** * Like range.getClientRects() but normalizes for browser bugs. */ -var getRangeClientRects = isChrome +const getRangeClientRects = isChrome ? getRangeClientRectsChrome : function(range: Range): Array { return Array.from(range.getClientRects()); diff --git a/src/component/selection/getSampleSelectionMocksForTesting.js b/src/component/selection/getSampleSelectionMocksForTesting.js index 8d8f90069e..c24f6764bb 100644 --- a/src/component/selection/getSampleSelectionMocksForTesting.js +++ b/src/component/selection/getSampleSelectionMocksForTesting.js @@ -6,6 +6,7 @@ * 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 */ 'use strict'; @@ -15,7 +16,6 @@ const ContentBlock = require('ContentBlock'); const ContentState = require('ContentState'); const EditorState = require('EditorState'); const Immutable = require('immutable'); - const {BOLD} = require('SampleDraftInlineStyle'); const {EMPTY} = CharacterMetadata; diff --git a/src/component/selection/getSampleSelectionMocksForTestingNestedBlocks.js b/src/component/selection/getSampleSelectionMocksForTestingNestedBlocks.js index 743b69a04a..2f6765c903 100644 --- a/src/component/selection/getSampleSelectionMocksForTestingNestedBlocks.js +++ b/src/component/selection/getSampleSelectionMocksForTestingNestedBlocks.js @@ -6,6 +6,7 @@ * 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 */ 'use strict'; diff --git a/src/component/selection/getSelectionOffsetKeyForNode.js b/src/component/selection/getSelectionOffsetKeyForNode.js index 04fc6be0bc..a7553138b4 100644 --- a/src/component/selection/getSelectionOffsetKeyForNode.js +++ b/src/component/selection/getSelectionOffsetKeyForNode.js @@ -18,12 +18,12 @@ */ function getSelectionOffsetKeyForNode(node: Node): ?string { if (node instanceof Element) { - var offsetKey = node.getAttribute('data-offset-key'); + const offsetKey = node.getAttribute('data-offset-key'); if (offsetKey) { return offsetKey; } - for (var ii = 0; ii < node.childNodes.length; ii++) { - var childOffsetKey = getSelectionOffsetKeyForNode(node.childNodes[ii]); + for (let ii = 0; ii < node.childNodes.length; ii++) { + const childOffsetKey = getSelectionOffsetKeyForNode(node.childNodes[ii]); if (childOffsetKey) { return childOffsetKey; } diff --git a/src/component/selection/getUpdatedSelectionState.js b/src/component/selection/getUpdatedSelectionState.js index 9f559d538e..9957a08d80 100644 --- a/src/component/selection/getUpdatedSelectionState.js +++ b/src/component/selection/getUpdatedSelectionState.js @@ -15,9 +15,9 @@ import type EditorState from 'EditorState'; import type SelectionState from 'SelectionState'; -var DraftOffsetKey = require('DraftOffsetKey'); +const DraftOffsetKey = require('DraftOffsetKey'); -var nullthrows = require('nullthrows'); +const nullthrows = require('nullthrows'); function getUpdatedSelectionState( editorState: EditorState, @@ -26,7 +26,7 @@ function getUpdatedSelectionState( focusKey: string, focusOffset: number, ): SelectionState { - var selection: SelectionState = nullthrows(editorState.getSelection()); + const selection: SelectionState = nullthrows(editorState.getSelection()); if (__DEV__) { if (!anchorKey || !focusKey) { /*eslint-disable no-console */ @@ -36,25 +36,25 @@ function getUpdatedSelectionState( } } - var anchorPath = DraftOffsetKey.decode(anchorKey); - var anchorBlockKey = anchorPath.blockKey; - var anchorLeaf = editorState + const anchorPath = DraftOffsetKey.decode(anchorKey); + const anchorBlockKey = anchorPath.blockKey; + const anchorLeaf = editorState .getBlockTree(anchorBlockKey) .getIn([anchorPath.decoratorKey, 'leaves', anchorPath.leafKey]); - var focusPath = DraftOffsetKey.decode(focusKey); - var focusBlockKey = focusPath.blockKey; - var focusLeaf = editorState + const focusPath = DraftOffsetKey.decode(focusKey); + const focusBlockKey = focusPath.blockKey; + const focusLeaf = editorState .getBlockTree(focusBlockKey) .getIn([focusPath.decoratorKey, 'leaves', focusPath.leafKey]); - var anchorLeafStart: number = anchorLeaf.get('start'); - var focusLeafStart: number = focusLeaf.get('start'); + const anchorLeafStart: number = anchorLeaf.get('start'); + const focusLeafStart: number = focusLeaf.get('start'); - var anchorBlockOffset = anchorLeaf ? anchorLeafStart + anchorOffset : null; - var focusBlockOffset = focusLeaf ? focusLeafStart + focusOffset : null; + const anchorBlockOffset = anchorLeaf ? anchorLeafStart + anchorOffset : null; + const focusBlockOffset = focusLeaf ? focusLeafStart + focusOffset : null; - var areEqual = + const areEqual = selection.getAnchorKey() === anchorBlockKey && selection.getAnchorOffset() === anchorBlockOffset && selection.getFocusKey() === focusBlockKey && @@ -64,17 +64,17 @@ function getUpdatedSelectionState( return selection; } - var isBackward = false; + let isBackward = false; if (anchorBlockKey === focusBlockKey) { - var anchorLeafEnd: number = anchorLeaf.get('end'); - var focusLeafEnd: number = focusLeaf.get('end'); + const anchorLeafEnd: number = anchorLeaf.get('end'); + const focusLeafEnd: number = focusLeaf.get('end'); if (focusLeafStart === anchorLeafStart && focusLeafEnd === anchorLeafEnd) { isBackward = focusOffset < anchorOffset; } else { isBackward = focusLeafStart < anchorLeafStart; } } else { - var startKey = editorState + const startKey = editorState .getCurrentContent() .getBlockMap() .keySeq() diff --git a/src/component/selection/isSelectionAtLeafStart.js b/src/component/selection/isSelectionAtLeafStart.js index 78e3bb035f..5325155a6e 100644 --- a/src/component/selection/isSelectionAtLeafStart.js +++ b/src/component/selection/isSelectionAtLeafStart.js @@ -15,12 +15,12 @@ import type EditorState from 'EditorState'; function isSelectionAtLeafStart(editorState: EditorState): boolean { - var selection = editorState.getSelection(); - var anchorKey = selection.getAnchorKey(); - var blockTree = editorState.getBlockTree(anchorKey); - var offset = selection.getStartOffset(); + const selection = editorState.getSelection(); + const anchorKey = selection.getAnchorKey(); + const blockTree = editorState.getBlockTree(anchorKey); + const offset = selection.getStartOffset(); - var isAtStart = false; + let isAtStart = false; blockTree.some(leafSet => { if (offset === leafSet.get('start')) { @@ -30,7 +30,7 @@ function isSelectionAtLeafStart(editorState: EditorState): boolean { if (offset < leafSet.get('end')) { return leafSet.get('leaves').some(leaf => { - var leafStart = leaf.get('start'); + const leafStart = leaf.get('start'); if (offset === leafStart) { isAtStart = true; return true; diff --git a/src/component/selection/setDraftEditorSelection.js b/src/component/selection/setDraftEditorSelection.js index d260cc943c..0308210f57 100644 --- a/src/component/selection/setDraftEditorSelection.js +++ b/src/component/selection/setDraftEditorSelection.js @@ -28,7 +28,7 @@ function getAnonymizedDOM( return '[empty]'; } - var anonymized = anonymizeTextWithin(node, getNodeLabels); + const anonymized = anonymizeTextWithin(node, getNodeLabels); if (anonymized.nodeType === Node.TEXT_NODE) { return anonymized.textContent; } @@ -47,7 +47,7 @@ function anonymizeTextWithin( const labels = getNodeLabels !== undefined ? getNodeLabels(node) : []; if (node.nodeType === Node.TEXT_NODE) { - var length = node.textContent.length; + const length = node.textContent.length; return document.createTextNode( '[text ' + length + @@ -56,12 +56,12 @@ function anonymizeTextWithin( ); } - var clone = node.cloneNode(); + const clone = node.cloneNode(); if (clone.nodeType === 1 && labels.length) { ((clone: any): Element).setAttribute('data-labels', labels.join(', ')); } - var childNodes = node.childNodes; - for (var ii = 0; ii < childNodes.length; ii++) { + const childNodes = node.childNodes; + for (let ii = 0; ii < childNodes.length; ii++) { clone.appendChild(anonymizeTextWithin(childNodes[ii], getNodeLabels)); } @@ -117,17 +117,17 @@ function setDraftEditorSelection( return; } - var selection = global.getSelection(); - var anchorKey = selectionState.getAnchorKey(); - var anchorOffset = selectionState.getAnchorOffset(); - var focusKey = selectionState.getFocusKey(); - var focusOffset = selectionState.getFocusOffset(); - var isBackward = selectionState.getIsBackward(); + const selection = global.getSelection(); + let anchorKey = selectionState.getAnchorKey(); + let anchorOffset = selectionState.getAnchorOffset(); + let focusKey = selectionState.getFocusKey(); + let focusOffset = selectionState.getFocusOffset(); + let isBackward = selectionState.getIsBackward(); // IE doesn't support backward selection. Swap key/offset pairs. if (!selection.extend && isBackward) { - var tempKey = anchorKey; - var tempOffset = anchorOffset; + const tempKey = anchorKey; + const tempOffset = anchorOffset; anchorKey = focusKey; anchorOffset = focusOffset; focusKey = tempKey; @@ -135,12 +135,12 @@ function setDraftEditorSelection( isBackward = false; } - var hasAnchor = + const hasAnchor = anchorKey === blockKey && nodeStart <= anchorOffset && nodeEnd >= anchorOffset; - var hasFocus = + const hasFocus = focusKey === blockKey && nodeStart <= focusOffset && nodeEnd >= focusOffset; // If the selection is entirely bound within this node, set the selection @@ -204,8 +204,8 @@ function setDraftEditorSelection( // We keep track of it, reset the selection range, and extend it // back to the focus point. if (hasAnchor) { - var storedFocusNode = selection.focusNode; - var storedFocusOffset = selection.focusOffset; + const storedFocusNode = selection.focusNode; + const storedFocusOffset = selection.focusOffset; selection.removeAllRanges(); addPointToSelection( @@ -302,7 +302,7 @@ function addFocusToSelection( // Additionally, clone the selection range. IE11 throws an // InvalidStateError when attempting to access selection properties // after the range is detached. - var range = selection.getRangeAt(0); + const range = selection.getRangeAt(0); range.setEnd(node, offset); selection.addRange(range.cloneRange()); } @@ -314,7 +314,7 @@ function addPointToSelection( offset: number, selectionState: SelectionState, ): void { - var range = document.createRange(); + const range = document.createRange(); // logging to catch bug that is being reported in t16250795 if (offset > getNodeLength(node)) { // in this case we know that the call to 'range.setStart' is about to throw diff --git a/src/component/utils/KeyBindingUtil.js b/src/component/utils/KeyBindingUtil.js index 07889a6cc6..4eb8ca5fb9 100644 --- a/src/component/utils/KeyBindingUtil.js +++ b/src/component/utils/KeyBindingUtil.js @@ -12,11 +12,11 @@ 'use strict'; -var UserAgent = require('UserAgent'); +const UserAgent = require('UserAgent'); -var isOSX = UserAgent.isPlatform('Mac OS X'); +const isOSX = UserAgent.isPlatform('Mac OS X'); -var KeyBindingUtil = { +const KeyBindingUtil = { /** * Check whether the ctrlKey modifier is *not* being used in conjunction with * the altKey modifier. If they are combined, the result is an `altGraph` diff --git a/src/component/utils/getDefaultKeyBinding.js b/src/component/utils/getDefaultKeyBinding.js index 874d4b5a2f..0c84b3f5eb 100644 --- a/src/component/utils/getDefaultKeyBinding.js +++ b/src/component/utils/getDefaultKeyBinding.js @@ -14,18 +14,18 @@ import type {DraftEditorCommand} from 'DraftEditorCommand'; -var KeyBindingUtil = require('KeyBindingUtil'); -var Keys = require('Keys'); -var UserAgent = require('UserAgent'); +const KeyBindingUtil = require('KeyBindingUtil'); +const Keys = require('Keys'); +const UserAgent = require('UserAgent'); -var isOSX = UserAgent.isPlatform('Mac OS X'); +const isOSX = UserAgent.isPlatform('Mac OS X'); // Firefox on OSX had a bug resulting in navigation instead of cursor movement. // This bug was fixed in Firefox 29. Feature detection is virtually impossible // so we just check the version number. See #342765. -var shouldFixFirefoxMovement = isOSX && UserAgent.isBrowser('Firefox < 29'); +const shouldFixFirefoxMovement = isOSX && UserAgent.isBrowser('Firefox < 29'); -var {hasCommandModifier, isCtrlKeyCommand} = KeyBindingUtil; +const {hasCommandModifier, isCtrlKeyCommand} = KeyBindingUtil; function shouldRemoveWord(e: SyntheticKeyboardEvent<>): boolean { return (isOSX && e.altKey) || isCtrlKeyCommand(e); diff --git a/src/component/utils/getTextContentFromFiles.js b/src/component/utils/getTextContentFromFiles.js index c4b1f4e38d..582f83e6c9 100644 --- a/src/component/utils/getTextContentFromFiles.js +++ b/src/component/utils/getTextContentFromFiles.js @@ -14,16 +14,16 @@ const invariant = require('invariant'); -var TEXT_CLIPPING_REGEX = /\.textClipping$/; +const TEXT_CLIPPING_REGEX = /\.textClipping$/; -var TEXT_TYPES = { +const TEXT_TYPES = { 'text/plain': true, 'text/html': true, 'text/rtf': true, }; // Somewhat arbitrary upper bound on text size. Let's not lock up the browser. -var TEXT_SIZE_UPPER_BOUND = 5000; +const TEXT_SIZE_UPPER_BOUND = 5000; /** * Extract the text content from a file list. @@ -32,8 +32,8 @@ function getTextContentFromFiles( files: Array, callback: (contents: string) => void, ): void { - var readCount = 0; - var results = []; + let readCount = 0; + const results = []; files.forEach(function(/*blob*/ file) { readFile(file, function(/*string*/ text) { readCount++; @@ -55,7 +55,7 @@ function readFile(file: File, callback: (contents: string) => void): void { } if (file.type === '') { - var contents = ''; + let contents = ''; // Special-case text clippings, which have an empty type but include // `.textClipping` in the file name. `readAsText` results in an empty // string for text clippings, so we force the file name to serve @@ -67,7 +67,7 @@ function readFile(file: File, callback: (contents: string) => void): void { return; } - var reader = new FileReader(); + const reader = new FileReader(); reader.onload = function() { const result = reader.result; invariant( diff --git a/src/component/utils/isSoftNewlineEvent.js b/src/component/utils/isSoftNewlineEvent.js index 8337804532..af7433a288 100644 --- a/src/component/utils/isSoftNewlineEvent.js +++ b/src/component/utils/isSoftNewlineEvent.js @@ -12,7 +12,7 @@ 'use strict'; -var Keys = require('Keys'); +const Keys = require('Keys'); function isSoftNewlineEvent(e: SyntheticKeyboardEvent<>): boolean { return ( diff --git a/src/component/utils/splitTextIntoTextBlocks.js b/src/component/utils/splitTextIntoTextBlocks.js index 7cb6b3c7da..24ca0f697a 100644 --- a/src/component/utils/splitTextIntoTextBlocks.js +++ b/src/component/utils/splitTextIntoTextBlocks.js @@ -12,7 +12,7 @@ 'use strict'; -var NEWLINE_REGEX = /\r\n?|\n/g; +const NEWLINE_REGEX = /\r\n?|\n/g; function splitTextIntoTextBlocks(text: string): Array { return text.split(NEWLINE_REGEX); diff --git a/src/model/decorators/CompositeDraftDecorator.js b/src/model/decorators/CompositeDraftDecorator.js index dcecc8fdbc..3376116223 100644 --- a/src/model/decorators/CompositeDraftDecorator.js +++ b/src/model/decorators/CompositeDraftDecorator.js @@ -16,11 +16,11 @@ import type {BlockNodeRecord} from 'BlockNodeRecord'; import type ContentState from 'ContentState'; import type {DraftDecorator} from 'DraftDecorator'; -var Immutable = require('immutable'); +const Immutable = require('immutable'); -var {List} = Immutable; +const {List} = Immutable; -var DELIMITER = '.'; +const DELIMITER = '.'; /** * A CompositeDraftDecorator traverses through a list of DraftDecorator @@ -55,12 +55,12 @@ class CompositeDraftDecorator { block: BlockNodeRecord, contentState: ContentState, ): List { - var decorations = Array(block.getText().length).fill(null); + const decorations = Array(block.getText().length).fill(null); this._decorators.forEach((/*object*/ decorator, /*number*/ ii) => { - var counter = 0; - var strategy = decorator.strategy; - var callback = (/*number*/ start, /*number*/ end) => { + let counter = 0; + const strategy = decorator.strategy; + const callback = (/*number*/ start, /*number*/ end) => { // Find out if any of our matching range is already occupied // by another decorator. If so, discard the match. Otherwise, store // the component key for rendering. @@ -76,12 +76,12 @@ class CompositeDraftDecorator { } getComponentForKey(key: string): Function { - var componentKey = parseInt(key.split(DELIMITER)[0], 10); + const componentKey = parseInt(key.split(DELIMITER)[0], 10); return this._decorators[componentKey].component; } getPropsForKey(key: string): ?Object { - var componentKey = parseInt(key.split(DELIMITER)[0], 10); + const componentKey = parseInt(key.split(DELIMITER)[0], 10); return this._decorators[componentKey].props; } } @@ -95,7 +95,7 @@ function canOccupySlice( start: number, end: number, ): boolean { - for (var ii = start; ii < end; ii++) { + for (let ii = start; ii < end; ii++) { if (decorations[ii] != null) { return false; } @@ -113,7 +113,7 @@ function occupySlice( end: number, componentKey: string, ): void { - for (var ii = start; ii < end; ii++) { + for (let ii = start; ii < end; ii++) { targetArr[ii] = componentKey; } } diff --git a/src/model/encoding/DraftStringKey.js b/src/model/encoding/DraftStringKey.js index f45b655ecf..8f35514ae2 100644 --- a/src/model/encoding/DraftStringKey.js +++ b/src/model/encoding/DraftStringKey.js @@ -12,7 +12,7 @@ 'use strict'; -var DraftStringKey = { +const DraftStringKey = { stringify: function(key: mixed): string { return '_' + String(key); }, diff --git a/src/model/encoding/createCharacterList.js b/src/model/encoding/createCharacterList.js index ea5e7d2bf8..2723bfc570 100644 --- a/src/model/encoding/createCharacterList.js +++ b/src/model/encoding/createCharacterList.js @@ -14,17 +14,17 @@ import type {DraftInlineStyle} from 'DraftInlineStyle'; -var CharacterMetadata = require('CharacterMetadata'); -var Immutable = require('immutable'); +const CharacterMetadata = require('CharacterMetadata'); +const Immutable = require('immutable'); -var {List} = Immutable; +const {List} = Immutable; function createCharacterList( inlineStyles: Array, entities: Array, ): List { - var characterArray = inlineStyles.map((style, ii) => { - var entity = entities[ii]; + const characterArray = inlineStyles.map((style, ii) => { + const entity = entities[ii]; return CharacterMetadata.create({style, entity}); }); return List(characterArray); diff --git a/src/model/encoding/decodeEntityRanges.js b/src/model/encoding/decodeEntityRanges.js index 13380436d4..7260136c26 100644 --- a/src/model/encoding/decodeEntityRanges.js +++ b/src/model/encoding/decodeEntityRanges.js @@ -12,9 +12,9 @@ 'use strict'; -var UnicodeUtils = require('UnicodeUtils'); +const UnicodeUtils = require('UnicodeUtils'); -var {substr} = UnicodeUtils; +const {substr} = UnicodeUtils; /** * Convert to native JavaScript string lengths to determine ranges. @@ -23,14 +23,14 @@ function decodeEntityRanges( text: string, ranges: Array, ): Array { - var entities = Array(text.length).fill(null); + const entities = Array(text.length).fill(null); if (ranges) { ranges.forEach(range => { // Using Unicode-enabled substrings converted to JavaScript lengths, // fill the output array with entity keys. - var start = substr(text, 0, range.offset).length; - var end = start + substr(text, range.offset, range.length).length; - for (var ii = start; ii < end; ii++) { + const start = substr(text, 0, range.offset).length; + const end = start + substr(text, range.offset, range.length).length; + for (let ii = start; ii < end; ii++) { entities[ii] = range.key; } }); diff --git a/src/model/encoding/decodeInlineStyleRanges.js b/src/model/encoding/decodeInlineStyleRanges.js index 55d5eedc7e..86bacf247b 100644 --- a/src/model/encoding/decodeInlineStyleRanges.js +++ b/src/model/encoding/decodeInlineStyleRanges.js @@ -12,10 +12,10 @@ 'use strict'; -var {OrderedSet} = require('immutable'); -var UnicodeUtils = require('UnicodeUtils'); +const {OrderedSet} = require('immutable'); +const UnicodeUtils = require('UnicodeUtils'); -var {substr} = UnicodeUtils; +const {substr} = UnicodeUtils; import type {DraftInlineStyle} from 'DraftInlineStyle'; @@ -28,11 +28,11 @@ function decodeInlineStyleRanges( text: string, ranges?: Array, ): Array { - var styles = Array(text.length).fill(EMPTY_SET); + const styles = Array(text.length).fill(EMPTY_SET); if (ranges) { ranges.forEach((/*object*/ range) => { - var cursor = substr(text, 0, range.offset).length; - var end = cursor + substr(text, range.offset, range.length).length; + let cursor = substr(text, 0, range.offset).length; + const end = cursor + substr(text, range.offset, range.length).length; while (cursor < end) { styles[cursor] = styles[cursor].add(range.style); cursor++; diff --git a/src/model/encoding/encodeEntityRanges.js b/src/model/encoding/encodeEntityRanges.js index 9e07f5a631..61e4fa4d2c 100644 --- a/src/model/encoding/encodeEntityRanges.js +++ b/src/model/encoding/encodeEntityRanges.js @@ -15,10 +15,10 @@ import type {BlockNodeRecord} from 'BlockNodeRecord'; import type {EntityRange} from 'EntityRange'; -var DraftStringKey = require('DraftStringKey'); -var UnicodeUtils = require('UnicodeUtils'); +const DraftStringKey = require('DraftStringKey'); +const UnicodeUtils = require('UnicodeUtils'); -var {strlen} = UnicodeUtils; +const {strlen} = UnicodeUtils; /** * Convert to UTF-8 character counts for storage. @@ -27,12 +27,12 @@ function encodeEntityRanges( block: BlockNodeRecord, storageMap: Object, ): Array { - var encoded = []; + const encoded = []; block.findEntityRanges( character => !!character.getEntity(), (/*number*/ start, /*number*/ end) => { - var text = block.getText(); - var key = block.getEntityAt(start); + const text = block.getText(); + const key = block.getEntityAt(start); encoded.push({ offset: strlen(text.slice(0, start)), length: strlen(text.slice(start, end)), diff --git a/src/model/encoding/encodeInlineStyleRanges.js b/src/model/encoding/encodeInlineStyleRanges.js index 5f839d011f..8b1e632b39 100644 --- a/src/model/encoding/encodeInlineStyleRanges.js +++ b/src/model/encoding/encodeInlineStyleRanges.js @@ -17,13 +17,13 @@ import type {DraftInlineStyle} from 'DraftInlineStyle'; import type {InlineStyleRange} from 'InlineStyleRange'; import type {List} from 'immutable'; -var UnicodeUtils = require('UnicodeUtils'); +const UnicodeUtils = require('UnicodeUtils'); -var findRangesImmutable = require('findRangesImmutable'); +const findRangesImmutable = require('findRangesImmutable'); -var areEqual = (a, b) => a === b; -var isTruthy = a => !!a; -var EMPTY_ARRAY = []; +const areEqual = (a, b) => a === b; +const isTruthy = a => !!a; +const EMPTY_ARRAY = []; /** * Helper function for getting encoded styles for each inline style. Convert @@ -34,10 +34,10 @@ function getEncodedInlinesForType( styleList: List, styleToEncode: string, ): Array { - var ranges = []; + const ranges = []; // Obtain an array with ranges for only the specified style. - var filteredInlines = styleList + const filteredInlines = styleList .map(style => style.has(styleToEncode)) .toList(); @@ -47,7 +47,7 @@ function getEncodedInlinesForType( // We only want to keep ranges with nonzero style values. isTruthy, (start, end) => { - var text = block.getText(); + const text = block.getText(); ranges.push({ offset: UnicodeUtils.strlen(text.slice(0, start)), length: UnicodeUtils.strlen(text.slice(start, end)), @@ -66,11 +66,11 @@ function getEncodedInlinesForType( function encodeInlineStyleRanges( block: BlockNodeRecord, ): Array { - var styleList = block + const styleList = block .getCharacterList() .map(c => c.getStyle()) .toList(); - var ranges = styleList + const ranges = styleList .flatten() .toSet() .map(style => getEncodedInlinesForType(block, styleList, style)); diff --git a/src/model/encoding/sanitizeDraftText.js b/src/model/encoding/sanitizeDraftText.js index 82eb5304ea..8527c5f5fa 100644 --- a/src/model/encoding/sanitizeDraftText.js +++ b/src/model/encoding/sanitizeDraftText.js @@ -12,7 +12,7 @@ 'use strict'; -var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g'); +const REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g'); function sanitizeDraftText(input: string): string { return input.replace(REGEX_BLOCK_DELIMITER, ''); diff --git a/src/model/entity/DraftEntity.js b/src/model/entity/DraftEntity.js index eae088afbb..f2b13e89c3 100644 --- a/src/model/entity/DraftEntity.js +++ b/src/model/entity/DraftEntity.js @@ -13,15 +13,15 @@ import type {DraftEntityMutability} from 'DraftEntityMutability'; import type {DraftEntityType} from 'DraftEntityType'; -var DraftEntityInstance = require('DraftEntityInstance'); -var Immutable = require('immutable'); +const DraftEntityInstance = require('DraftEntityInstance'); +const Immutable = require('immutable'); -var invariant = require('invariant'); +const invariant = require('invariant'); -var {Map} = Immutable; +const {Map} = Immutable; -var instances: Map = Map(); -var instanceKey = 0; +let instances: Map = Map(); +let instanceKey = 0; /** * Temporary utility for generating the warnings @@ -95,7 +95,7 @@ export type DraftEntityMapObject = { * generated via DraftEntity.create() and used to obtain entity metadata * via DraftEntity.get(). */ -var DraftEntity: DraftEntityMapObject = { +const DraftEntity: DraftEntityMapObject = { /** * WARNING: This method will be deprecated soon! * Please use 'contentState.getLastCreatedEntityKey' instead. @@ -219,7 +219,7 @@ var DraftEntity: DraftEntityMapObject = { * useful when restoring instances from the server. */ __add: function(instance: DraftEntityInstance): string { - var key = '' + ++instanceKey; + const key = '' + ++instanceKey; instances = instances.set(key, instance); return key; }, @@ -228,7 +228,7 @@ var DraftEntity: DraftEntityMapObject = { * Retrieve the entity corresponding to the supplied key string. */ __get: function(key: string): DraftEntityInstance { - var instance = instances.get(key); + const instance = instances.get(key); invariant(!!instance, 'Unknown DraftEntity key: %s.', key); return instance; }, @@ -242,9 +242,9 @@ var DraftEntity: DraftEntityMapObject = { key: string, toMerge: {[key: string]: any}, ): DraftEntityInstance { - var instance = DraftEntity.__get(key); - var newData = {...instance.getData(), ...toMerge}; - var newInstance = instance.set('data', newData); + const instance = DraftEntity.__get(key); + const newData = {...instance.getData(), ...toMerge}; + const newInstance = instance.set('data', newData); instances = instances.set(key, newInstance); return newInstance; }, diff --git a/src/model/entity/DraftEntityInstance.js b/src/model/entity/DraftEntityInstance.js index 4d38a289ba..e79b111e35 100644 --- a/src/model/entity/DraftEntityInstance.js +++ b/src/model/entity/DraftEntityInstance.js @@ -16,11 +16,11 @@ import type {DraftEntityMutability} from 'DraftEntityMutability'; import type {DraftEntityType} from 'DraftEntityType'; -var Immutable = require('immutable'); +const Immutable = require('immutable'); -var {Record} = Immutable; +const {Record} = Immutable; -var DraftEntityInstanceRecord = Record({ +const DraftEntityInstanceRecord = Record({ type: 'TOKEN', mutability: 'IMMUTABLE', data: Object, diff --git a/src/model/entity/DraftEntityMutability.js b/src/model/entity/DraftEntityMutability.js index 92507029af..e334f3cba0 100644 --- a/src/model/entity/DraftEntityMutability.js +++ b/src/model/entity/DraftEntityMutability.js @@ -12,7 +12,7 @@ 'use strict'; -var ComposedEntityMutability = require('ComposedEntityMutability'); +const ComposedEntityMutability = require('ComposedEntityMutability'); /** * An enum representing the possible "mutability" options for an entity. diff --git a/src/model/entity/__mocks__/DraftEntity.js b/src/model/entity/__mocks__/DraftEntity.js index ec7d0022fa..a233a4b8d3 100644 --- a/src/model/entity/__mocks__/DraftEntity.js +++ b/src/model/entity/__mocks__/DraftEntity.js @@ -9,15 +9,15 @@ * @format */ -var DraftEntity = jest.genMockFromModule('DraftEntity'); +const DraftEntity = jest.genMockFromModule('DraftEntity'); -var DraftEntityInstance = { +const DraftEntityInstance = { getType: jest.fn(() => ''), getMutability: jest.fn(() => ''), getData: jest.fn(() => ({})), }; -var count = 0; +let count = 0; DraftEntity.create = jest.fn(function() { count++; diff --git a/src/model/entity/getEntityKeyForSelection.js b/src/model/entity/getEntityKeyForSelection.js index 7c8378945a..1fa85f8277 100644 --- a/src/model/entity/getEntityKeyForSelection.js +++ b/src/model/entity/getEntityKeyForSelection.js @@ -25,11 +25,11 @@ function getEntityKeyForSelection( contentState: ContentState, targetSelection: SelectionState, ): ?string { - var entityKey; + let entityKey; if (targetSelection.isCollapsed()) { - var key = targetSelection.getAnchorKey(); - var offset = targetSelection.getAnchorOffset(); + const key = targetSelection.getAnchorKey(); + const offset = targetSelection.getAnchorOffset(); if (offset > 0) { entityKey = contentState.getBlockForKey(key).getEntityAt(offset - 1); if (entityKey !== contentState.getBlockForKey(key).getEntityAt(offset)) { @@ -40,9 +40,9 @@ function getEntityKeyForSelection( return null; } - var startKey = targetSelection.getStartKey(); - var startOffset = targetSelection.getStartOffset(); - var startBlock = contentState.getBlockForKey(startKey); + const startKey = targetSelection.getStartKey(); + const startOffset = targetSelection.getStartOffset(); + const startBlock = contentState.getBlockForKey(startKey); entityKey = startOffset === startBlock.getLength() @@ -58,7 +58,7 @@ function getEntityKeyForSelection( */ function filterKey(entityMap: EntityMap, entityKey: ?string): ?string { if (entityKey) { - var entity = entityMap.__get(entityKey); + const entity = entityMap.__get(entityKey); return entity.getMutability() === 'MUTABLE' ? entityKey : null; } return null; diff --git a/src/model/entity/getTextAfterNearestEntity.js b/src/model/entity/getTextAfterNearestEntity.js index 104b3f77ca..d16aec2474 100644 --- a/src/model/entity/getTextAfterNearestEntity.js +++ b/src/model/entity/getTextAfterNearestEntity.js @@ -22,7 +22,7 @@ function getTextAfterNearestEntity( block: BlockNodeRecord, offset: number, ): string { - var start = offset; + let start = offset; // Get start based on where the last entity ended. while (start > 0 && block.getEntityAt(start - 1) === null) { diff --git a/src/model/immutable/BlockMapBuilder.js b/src/model/immutable/BlockMapBuilder.js index b79f39f5af..f4bbf1f3cf 100644 --- a/src/model/immutable/BlockMapBuilder.js +++ b/src/model/immutable/BlockMapBuilder.js @@ -15,11 +15,11 @@ import type {BlockMap} from 'BlockMap'; import type {BlockNodeRecord} from 'BlockNodeRecord'; -var Immutable = require('immutable'); +const Immutable = require('immutable'); -var {OrderedMap} = Immutable; +const {OrderedMap} = Immutable; -var BlockMapBuilder = { +const BlockMapBuilder = { createFromArray: function(blocks: Array): BlockMap { return OrderedMap(blocks.map(block => [block.getKey(), block])); }, diff --git a/src/model/immutable/BlockTree.js b/src/model/immutable/BlockTree.js index 097c4c01af..5caaf8d6e4 100644 --- a/src/model/immutable/BlockTree.js +++ b/src/model/immutable/BlockTree.js @@ -17,18 +17,18 @@ import type CharacterMetadata from 'CharacterMetadata'; import type ContentState from 'ContentState'; import type {DraftDecoratorType} from 'DraftDecoratorType'; -var Immutable = require('immutable'); +const Immutable = require('immutable'); -var emptyFunction = require('emptyFunction'); -var findRangesImmutable = require('findRangesImmutable'); +const emptyFunction = require('emptyFunction'); +const findRangesImmutable = require('findRangesImmutable'); -var {List, Repeat, Record} = Immutable; +const {List, Repeat, Record} = Immutable; -var returnTrue = emptyFunction.thatReturnsTrue; +const returnTrue = emptyFunction.thatReturnsTrue; -var FINGERPRINT_DELIMITER = '-'; +const FINGERPRINT_DELIMITER = '-'; -var defaultLeafRange: { +const defaultLeafRange: { start: ?number, end: ?number, } = { @@ -36,9 +36,9 @@ var defaultLeafRange: { end: null, }; -var LeafRange = Record(defaultLeafRange); +const LeafRange = Record(defaultLeafRange); -var defaultDecoratorRange: { +const defaultDecoratorRange: { start: ?number, end: ?number, decoratorKey: ?string, @@ -50,9 +50,9 @@ var defaultDecoratorRange: { leaves: null, }; -var DecoratorRange = Record(defaultDecoratorRange); +const DecoratorRange = Record(defaultDecoratorRange); -var BlockTree = { +const BlockTree = { /** * Generate a block tree for a given ContentBlock/decorator pair. */ @@ -61,7 +61,7 @@ var BlockTree = { block: BlockNodeRecord, decorator: ?DraftDecoratorType, ): List { - var textLength = block.getLength(); + const textLength = block.getLength(); if (!textLength) { return List.of( new DecoratorRange({ @@ -73,12 +73,12 @@ var BlockTree = { ); } - var leafSets = []; - var decorations = decorator + const leafSets = []; + const decorations = decorator ? decorator.getDecorations(block, contentState) : List(Repeat(null, textLength)); - var chars = block.getCharacterList(); + const chars = block.getCharacterList(); findRangesImmutable(decorations, areEqual, returnTrue, (start, end) => { leafSets.push( @@ -102,8 +102,8 @@ var BlockTree = { getFingerprint: function(tree: List): string { return tree .map(leafSet => { - var decoratorKey = leafSet.get('decoratorKey'); - var fingerprintString = + const decoratorKey = leafSet.get('decoratorKey'); + const fingerprintString = decoratorKey !== null ? decoratorKey + '.' + (leafSet.get('end') - leafSet.get('start')) : ''; @@ -120,8 +120,8 @@ function generateLeaves( characters: List, offset: number, ): List { - var leaves = []; - var inlineStyles = characters.map(c => c.getStyle()).toList(); + const leaves = []; + const inlineStyles = characters.map(c => c.getStyle()).toList(); findRangesImmutable(inlineStyles, areEqual, returnTrue, (start, end) => { leaves.push( new LeafRange({ diff --git a/src/model/immutable/CharacterMetadata.js b/src/model/immutable/CharacterMetadata.js index 7b47bd71d3..d737875d2c 100644 --- a/src/model/immutable/CharacterMetadata.js +++ b/src/model/immutable/CharacterMetadata.js @@ -14,7 +14,7 @@ import type {DraftInlineStyle} from 'DraftInlineStyle'; -var {Map, OrderedSet, Record} = require('immutable'); +const {Map, OrderedSet, Record} = require('immutable'); // Immutable.map is typed such that the value for every key in the map // must be the same type @@ -27,12 +27,12 @@ type CharacterMetadataConfig = { const EMPTY_SET = OrderedSet(); -var defaultRecord: CharacterMetadataConfig = { +const defaultRecord: CharacterMetadataConfig = { style: EMPTY_SET, entity: null, }; -var CharacterMetadataRecord = Record(defaultRecord); +const CharacterMetadataRecord = Record(defaultRecord); class CharacterMetadata extends CharacterMetadataRecord { getStyle(): DraftInlineStyle { @@ -51,7 +51,7 @@ class CharacterMetadata extends CharacterMetadataRecord { record: CharacterMetadata, style: string, ): CharacterMetadata { - var withStyle = record.set('style', record.getStyle().add(style)); + const withStyle = record.set('style', record.getStyle().add(style)); return CharacterMetadata.create(withStyle); } @@ -59,7 +59,7 @@ class CharacterMetadata extends CharacterMetadataRecord { record: CharacterMetadata, style: string, ): CharacterMetadata { - var withoutStyle = record.set('style', record.getStyle().remove(style)); + const withoutStyle = record.set('style', record.getStyle().remove(style)); return CharacterMetadata.create(withoutStyle); } @@ -67,7 +67,7 @@ class CharacterMetadata extends CharacterMetadataRecord { record: CharacterMetadata, entityKey: ?string, ): CharacterMetadata { - var withEntity = + const withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey); @@ -91,21 +91,21 @@ class CharacterMetadata extends CharacterMetadataRecord { }; // Fill in unspecified properties, if necessary. - var configMap = Map(defaultConfig).merge(config); + const configMap = Map(defaultConfig).merge(config); - var existing: ?CharacterMetadata = pool.get(configMap); + const existing: ?CharacterMetadata = pool.get(configMap); if (existing) { return existing; } - var newCharacter = new CharacterMetadata(configMap); + const newCharacter = new CharacterMetadata(configMap); pool = pool.set(configMap, newCharacter); return newCharacter; } } -var EMPTY = new CharacterMetadata(); -var pool: Map, CharacterMetadata> = Map([ +const EMPTY = new CharacterMetadata(); +let pool: Map, CharacterMetadata> = Map([ [Map(defaultRecord), EMPTY], ]); diff --git a/src/model/immutable/ContentBlock.js b/src/model/immutable/ContentBlock.js index 9abe28aaa4..4e32b4a1c9 100644 --- a/src/model/immutable/ContentBlock.js +++ b/src/model/immutable/ContentBlock.js @@ -84,12 +84,12 @@ class ContentBlock extends ContentBlockRecord implements BlockNode { } getInlineStyleAt(offset: number): DraftInlineStyle { - var character = this.getCharacterList().get(offset); + const character = this.getCharacterList().get(offset); return character ? character.getStyle() : EMPTY_SET; } getEntityAt(offset: number): ?string { - var character = this.getCharacterList().get(offset); + const character = this.getCharacterList().get(offset); return character ? character.getEntity() : null; } diff --git a/src/model/immutable/ContentBlockNode.js b/src/model/immutable/ContentBlockNode.js index 8ec5fde408..2396750061 100644 --- a/src/model/immutable/ContentBlockNode.js +++ b/src/model/immutable/ContentBlockNode.js @@ -111,12 +111,12 @@ class ContentBlockNode extends Record(defaultRecord) implements BlockNode { } getInlineStyleAt(offset: number): DraftInlineStyle { - var character = this.getCharacterList().get(offset); + const character = this.getCharacterList().get(offset); return character ? character.getStyle() : EMPTY_SET; } getEntityAt(offset: number): ?string { - var character = this.getCharacterList().get(offset); + const character = this.getCharacterList().get(offset); return character ? character.getEntity() : null; } diff --git a/src/model/immutable/ContentState.js b/src/model/immutable/ContentState.js index 4c3bf2fb28..78010155fa 100644 --- a/src/model/immutable/ContentState.js +++ b/src/model/immutable/ContentState.js @@ -71,7 +71,7 @@ class ContentState extends ContentStateRecord { } getBlockForKey(key: string): BlockNodeRecord { - var block: BlockNodeRecord = this.getBlockMap().get(key); + const block: BlockNodeRecord = this.getBlockMap().get(key); return block; } @@ -133,7 +133,7 @@ class ContentState extends ContentStateRecord { } hasText(): boolean { - var blockMap = this.getBlockMap(); + const blockMap = this.getBlockMap(); return blockMap.size > 1 || blockMap.first().getLength() > 0; } @@ -177,8 +177,8 @@ class ContentState extends ContentStateRecord { ): ContentState { // TODO: remove this when we completely deprecate the old entity API const theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks; - var blockMap = BlockMapBuilder.createFromArray(theBlocks); - var selectionState = blockMap.isEmpty() + const blockMap = BlockMapBuilder.createFromArray(theBlocks); + const selectionState = blockMap.isEmpty() ? new SelectionState() : SelectionState.createEmpty(blockMap.first().getKey()); return new ContentState({ diff --git a/src/model/immutable/EditorBidiService.js b/src/model/immutable/EditorBidiService.js index 63ac811392..7de0cc704f 100644 --- a/src/model/immutable/EditorBidiService.js +++ b/src/model/immutable/EditorBidiService.js @@ -14,16 +14,16 @@ import type ContentState from 'ContentState'; -var Immutable = require('immutable'); -var UnicodeBidiService = require('UnicodeBidiService'); +const Immutable = require('immutable'); +const UnicodeBidiService = require('UnicodeBidiService'); -var nullthrows = require('nullthrows'); +const nullthrows = require('nullthrows'); -var {OrderedMap} = Immutable; +const {OrderedMap} = Immutable; -var bidiService; +let bidiService; -var EditorBidiService = { +const EditorBidiService = { getDirectionMap: function( content: ContentState, prevBidiMap: ?OrderedMap, @@ -34,11 +34,11 @@ var EditorBidiService = { bidiService.reset(); } - var blockMap = content.getBlockMap(); - var nextBidi = blockMap + const blockMap = content.getBlockMap(); + const nextBidi = blockMap .valueSeq() .map(block => nullthrows(bidiService).getDirection(block.getText())); - var bidiMap = OrderedMap(blockMap.keySeq().zip(nextBidi)); + const bidiMap = OrderedMap(blockMap.keySeq().zip(nextBidi)); if (prevBidiMap != null && Immutable.is(prevBidiMap, bidiMap)) { return prevBidiMap; diff --git a/src/model/immutable/EditorState.js b/src/model/immutable/EditorState.js index f4f7928a7b..6c1b40c37f 100644 --- a/src/model/immutable/EditorState.js +++ b/src/model/immutable/EditorState.js @@ -19,13 +19,13 @@ import type {EditorChangeType} from 'EditorChangeType'; import type {EntityMap} from 'EntityMap'; import type {List, OrderedMap} from 'immutable'; -var BlockTree = require('BlockTree'); -var ContentState = require('ContentState'); -var EditorBidiService = require('EditorBidiService'); -var Immutable = require('immutable'); -var SelectionState = require('SelectionState'); +const BlockTree = require('BlockTree'); +const ContentState = require('ContentState'); +const EditorBidiService = require('EditorBidiService'); +const Immutable = require('immutable'); +const SelectionState = require('SelectionState'); -var {OrderedSet, Record, Stack} = Immutable; +const {OrderedSet, Record, Stack} = Immutable; type EditorStateRecordType = { allowUndo: boolean, @@ -43,7 +43,7 @@ type EditorStateRecordType = { undoStack: Stack, }; -var defaultRecord: EditorStateRecordType = { +const defaultRecord: EditorStateRecordType = { allowUndo: true, currentContent: null, decorator: null, @@ -59,7 +59,7 @@ var defaultRecord: EditorStateRecordType = { undoStack: Stack(), }; -var EditorStateRecord = Record(defaultRecord); +const EditorStateRecord = Record(defaultRecord); class EditorState { _immutable: EditorStateRecord; @@ -75,7 +75,7 @@ class EditorState { contentState: ContentState, decorator?: ?DraftDecoratorType, ): EditorState { - var firstKey = contentState + const firstKey = contentState .getBlockMap() .first() .getKey(); @@ -89,8 +89,8 @@ class EditorState { } static create(config: Object): EditorState { - var {currentContent, decorator} = config; - var recordConfig = { + const {currentContent, decorator} = config; + const recordConfig = { ...config, treeMap: generateNewTreeMap(currentContent, decorator), directionMap: EditorBidiService.getDirectionMap(currentContent), @@ -99,20 +99,20 @@ class EditorState { } static set(editorState: EditorState, put: Object): EditorState { - var map = editorState.getImmutable().withMutations(state => { - var existingDecorator = state.get('decorator'); - var decorator = existingDecorator; + const map = editorState.getImmutable().withMutations(state => { + const existingDecorator = state.get('decorator'); + let decorator = existingDecorator; if (put.decorator === null) { decorator = null; } else if (put.decorator) { decorator = put.decorator; } - var newContent = put.currentContent || editorState.getCurrentContent(); + const newContent = put.currentContent || editorState.getCurrentContent(); if (decorator !== existingDecorator) { - var treeMap: OrderedMap = state.get('treeMap'); - var newTreeMap; + const treeMap: OrderedMap = state.get('treeMap'); + let newTreeMap; if (decorator && existingDecorator) { newTreeMap = regenerateTreeForNewDecorator( newContent, @@ -133,7 +133,7 @@ class EditorState { return; } - var existingContent = editorState.getCurrentContent(); + const existingContent = editorState.getCurrentContent(); if (newContent !== existingContent) { state.set( 'treeMap', @@ -221,13 +221,13 @@ class EditorState { * based on the location of the selection state. */ getCurrentInlineStyle(): DraftInlineStyle { - var override = this.getInlineStyleOverride(); + const override = this.getInlineStyleOverride(); if (override != null) { return override; } - var content = this.getCurrentContent(); - var selection = this.getSelection(); + const content = this.getCurrentContent(); + const selection = this.getSelection(); if (selection.isCollapsed()) { return getInlineStyleForCollapsedSelection(content, selection); @@ -241,7 +241,7 @@ class EditorState { } isSelectionAtStartOfContent(): boolean { - var firstKey = this.getCurrentContent() + const firstKey = this.getCurrentContent() .getBlockMap() .first() .getKey(); @@ -249,10 +249,10 @@ class EditorState { } isSelectionAtEndOfContent(): boolean { - var content = this.getCurrentContent(); - var blockMap = content.getBlockMap(); - var last = blockMap.last(); - var end = last.getLength(); + const content = this.getCurrentContent(); + const blockMap = content.getBlockMap(); + const last = blockMap.last(); + const end = last.getLength(); return this.getSelection().hasEdgeWithin(last.getKey(), end, end); } @@ -301,10 +301,10 @@ class EditorState { * Move selection to the end of the editor without forcing focus. */ static moveSelectionToEnd(editorState: EditorState): EditorState { - var content = editorState.getCurrentContent(); - var lastBlock = content.getLastBlock(); - var lastKey = lastBlock.getKey(); - var length = lastBlock.getLength(); + const content = editorState.getCurrentContent(); + const lastBlock = content.getLastBlock(); + const lastKey = lastBlock.getKey(); + const length = lastBlock.getLength(); return EditorState.acceptSelection( editorState, @@ -324,7 +324,7 @@ class EditorState { * to allow the user to continue working seamlessly. */ static moveFocusToEnd(editorState: EditorState): EditorState { - var afterSelectionMove = EditorState.moveSelectionToEnd(editorState); + const afterSelectionMove = EditorState.moveSelectionToEnd(editorState); return EditorState.forceSelection( afterSelectionMove, afterSelectionMove.getSelection(), @@ -345,8 +345,8 @@ class EditorState { return editorState; } - var forceSelection = changeType !== 'insert-characters'; - var directionMap = EditorBidiService.getDirectionMap( + const forceSelection = changeType !== 'insert-characters'; + const directionMap = EditorBidiService.getDirectionMap( contentState, editorState.getDirectionMap(), ); @@ -362,10 +362,10 @@ class EditorState { }); } - var selection = editorState.getSelection(); - var currentContent = editorState.getCurrentContent(); - var undoStack = editorState.getUndoStack(); - var newContent = contentState; + const selection = editorState.getSelection(); + const currentContent = editorState.getCurrentContent(); + let undoStack = editorState.getUndoStack(); + let newContent = contentState; if ( selection !== currentContent.getSelectionAfter() || @@ -388,7 +388,7 @@ class EditorState { let inlineStyleOverride = editorState.getInlineStyleOverride(); // Don't discard inline style overrides for the following change types: - var overrideChangeTypes = [ + const overrideChangeTypes = [ 'adjust-depth', 'change-block-type', 'split-block', @@ -398,7 +398,7 @@ class EditorState { inlineStyleOverride = null; } - var editorStateChanges = { + const editorStateChanges = { currentContent: newContent, directionMap, undoStack, @@ -421,14 +421,14 @@ class EditorState { return editorState; } - var undoStack = editorState.getUndoStack(); - var newCurrentContent = undoStack.peek(); + const undoStack = editorState.getUndoStack(); + const newCurrentContent = undoStack.peek(); if (!newCurrentContent) { return editorState; } - var currentContent = editorState.getCurrentContent(); - var directionMap = EditorBidiService.getDirectionMap( + const currentContent = editorState.getCurrentContent(); + const directionMap = EditorBidiService.getDirectionMap( newCurrentContent, editorState.getDirectionMap(), ); @@ -455,14 +455,14 @@ class EditorState { return editorState; } - var redoStack = editorState.getRedoStack(); - var newCurrentContent = redoStack.peek(); + const redoStack = editorState.getRedoStack(); + const newCurrentContent = redoStack.peek(); if (!newCurrentContent) { return editorState; } - var currentContent = editorState.getCurrentContent(); - var directionMap = EditorBidiService.getDirectionMap( + const currentContent = editorState.getCurrentContent(); + const directionMap = EditorBidiService.getDirectionMap( newCurrentContent, editorState.getDirectionMap(), ); @@ -540,8 +540,8 @@ function regenerateTreeForNewBlocks( const contentState = editorState .getCurrentContent() .set('entityMap', newEntityMap); - var prevBlockMap = contentState.getBlockMap(); - var prevTreeMap = editorState.getImmutable().get('treeMap'); + const prevBlockMap = contentState.getBlockMap(); + const prevTreeMap = editorState.getImmutable().get('treeMap'); return prevTreeMap.merge( newBlockMap .toSeq() @@ -587,7 +587,7 @@ function mustBecomeBoundary( editorState: EditorState, changeType: EditorChangeType, ): boolean { - var lastChangeType = editorState.getLastChangeType(); + const lastChangeType = editorState.getLastChangeType(); return ( changeType !== lastChangeType || (changeType !== 'insert-characters' && @@ -600,9 +600,9 @@ function getInlineStyleForCollapsedSelection( content: ContentState, selection: SelectionState, ): DraftInlineStyle { - var startKey = selection.getStartKey(); - var startOffset = selection.getStartOffset(); - var startBlock = content.getBlockForKey(startKey); + const startKey = selection.getStartKey(); + const startOffset = selection.getStartOffset(); + const startBlock = content.getBlockForKey(startKey); // If the cursor is not at the start of the block, look backward to // preserve the style of the preceding character. @@ -624,9 +624,9 @@ function getInlineStyleForNonCollapsedSelection( content: ContentState, selection: SelectionState, ): DraftInlineStyle { - var startKey = selection.getStartKey(); - var startOffset = selection.getStartOffset(); - var startBlock = content.getBlockForKey(startKey); + const startKey = selection.getStartKey(); + const startOffset = selection.getStartOffset(); + const startBlock = content.getBlockForKey(startKey); // If there is a character just inside the selection, use its style. if (startOffset < startBlock.getLength()) { @@ -647,7 +647,7 @@ function lookUpwardForInlineStyle( content: ContentState, fromKey: string, ): DraftInlineStyle { - var lastNonEmpty = content + const lastNonEmpty = content .getBlockMap() .reverse() .skipUntil((_, k) => k === fromKey) diff --git a/src/model/immutable/SelectionState.js b/src/model/immutable/SelectionState.js index a503ef8b46..12cdd89172 100644 --- a/src/model/immutable/SelectionState.js +++ b/src/model/immutable/SelectionState.js @@ -12,11 +12,11 @@ 'use strict'; -var Immutable = require('immutable'); +const Immutable = require('immutable'); -var {Record} = Immutable; +const {Record} = Immutable; -var defaultRecord: { +const defaultRecord: { anchorKey: string, anchorOffset: number, focusKey: string, @@ -32,7 +32,7 @@ var defaultRecord: { hasFocus: false, }; -var SelectionStateRecord = Record(defaultRecord); +const SelectionStateRecord = Record(defaultRecord); class SelectionState extends SelectionStateRecord { serialize(): string { @@ -84,12 +84,12 @@ class SelectionState extends SelectionStateRecord { * SelectionState. */ hasEdgeWithin(blockKey: string, start: number, end: number): boolean { - var anchorKey = this.getAnchorKey(); - var focusKey = this.getFocusKey(); + const anchorKey = this.getAnchorKey(); + const focusKey = this.getFocusKey(); if (anchorKey === focusKey && anchorKey === blockKey) { - var selectionStart = this.getStartOffset(); - var selectionEnd = this.getEndOffset(); + const selectionStart = this.getStartOffset(); + const selectionEnd = this.getEndOffset(); return start <= selectionEnd && selectionStart <= end; } @@ -97,7 +97,7 @@ class SelectionState extends SelectionStateRecord { return false; } - var offsetToCheck = + const offsetToCheck = blockKey === anchorKey ? this.getAnchorOffset() : this.getFocusOffset(); return start <= offsetToCheck && end >= offsetToCheck; diff --git a/src/model/immutable/findRangesImmutable.js b/src/model/immutable/findRangesImmutable.js index 45d77b8f1f..06a7dc1365 100644 --- a/src/model/immutable/findRangesImmutable.js +++ b/src/model/immutable/findRangesImmutable.js @@ -31,7 +31,7 @@ function findRangesImmutable( return; } - var cursor: number = 0; + let cursor: number = 0; haystack.reduce((value: T, nextValue, nextIndex) => { if (!areEqualFn(value, nextValue)) { diff --git a/src/model/modifier/DraftEntitySegments.js b/src/model/modifier/DraftEntitySegments.js index 73bf76c33a..4585c5d818 100644 --- a/src/model/modifier/DraftEntitySegments.js +++ b/src/model/modifier/DraftEntitySegments.js @@ -38,7 +38,7 @@ import type {DraftRemovalDirection} from 'DraftRemovalDirection'; * 'John F. Kennedy' -> 'F. Kennedy' * ^ */ -var DraftEntitySegments = { +const DraftEntitySegments = { getRemovalRange: function( selectionStart: number, selectionEnd: number, @@ -46,7 +46,7 @@ var DraftEntitySegments = { entityStart: number, direction: DraftRemovalDirection, ): DraftRange { - var segments = text.split(' '); + let segments = text.split(' '); segments = segments.map((/*string*/ segment, /*number*/ ii) => { if (direction === 'forward') { if (ii > 0) { @@ -58,13 +58,13 @@ var DraftEntitySegments = { return segment; }); - var segmentStart = entityStart; - var segmentEnd; - var segment; - var removalStart: any = null; - var removalEnd: any = null; + let segmentStart = entityStart; + let segmentEnd; + let segment; + let removalStart: any = null; + let removalEnd: any = null; - for (var jj = 0; jj < segments.length; jj++) { + for (let jj = 0; jj < segments.length; jj++) { segment = segments[jj]; segmentEnd = segmentStart + segment.length; @@ -83,9 +83,9 @@ var DraftEntitySegments = { segmentStart = segmentEnd; } - var entityEnd = entityStart + text.length; - var atStart = removalStart === entityStart; - var atEnd = removalEnd === entityEnd; + const entityEnd = entityStart + text.length; + const atStart = removalStart === entityStart; + const atEnd = removalEnd === entityEnd; if ((!atStart && atEnd) || (atStart && !atEnd)) { if (direction === 'forward') { diff --git a/src/model/modifier/DraftModifier.js b/src/model/modifier/DraftModifier.js index d1c0027e05..8cc4fe12fe 100644 --- a/src/model/modifier/DraftModifier.js +++ b/src/model/modifier/DraftModifier.js @@ -20,21 +20,21 @@ import type {DraftRemovalDirection} from 'DraftRemovalDirection'; import type SelectionState from 'SelectionState'; import type {Map} from 'immutable'; -var CharacterMetadata = require('CharacterMetadata'); -var ContentStateInlineStyle = require('ContentStateInlineStyle'); -var Immutable = require('immutable'); +const CharacterMetadata = require('CharacterMetadata'); +const ContentStateInlineStyle = require('ContentStateInlineStyle'); +const Immutable = require('immutable'); -var applyEntityToContentState = require('applyEntityToContentState'); -var getCharacterRemovalRange = require('getCharacterRemovalRange'); -var getContentStateFragment = require('getContentStateFragment'); -var gkx = require('gkx'); -var insertFragmentIntoContentState = require('insertFragmentIntoContentState'); -var insertTextIntoContentState = require('insertTextIntoContentState'); -var invariant = require('invariant'); -var modifyBlockForContentState = require('modifyBlockForContentState'); -var removeEntitiesAtEdges = require('removeEntitiesAtEdges'); -var removeRangeFromContentState = require('removeRangeFromContentState'); -var splitBlockInContentState = require('splitBlockInContentState'); +const applyEntityToContentState = require('applyEntityToContentState'); +const getCharacterRemovalRange = require('getCharacterRemovalRange'); +const getContentStateFragment = require('getContentStateFragment'); +const gkx = require('gkx'); +const insertFragmentIntoContentState = require('insertFragmentIntoContentState'); +const insertTextIntoContentState = require('insertTextIntoContentState'); +const invariant = require('invariant'); +const modifyBlockForContentState = require('modifyBlockForContentState'); +const removeEntitiesAtEdges = require('removeEntitiesAtEdges'); +const removeRangeFromContentState = require('removeRangeFromContentState'); +const splitBlockInContentState = require('splitBlockInContentState'); const {OrderedSet} = Immutable; @@ -48,7 +48,7 @@ const {OrderedSet} = Immutable; * * These functions encapsulate some of the most common transaction sequences. */ -var DraftModifier = { +const DraftModifier = { replaceText: function( contentState: ContentState, rangeToReplace: SelectionState, @@ -56,13 +56,13 @@ var DraftModifier = { inlineStyle?: DraftInlineStyle, entityKey?: ?string, ): ContentState { - var withoutEntities = removeEntitiesAtEdges(contentState, rangeToReplace); - var withoutText = removeRangeFromContentState( + const withoutEntities = removeEntitiesAtEdges(contentState, rangeToReplace); + const withoutText = removeRangeFromContentState( withoutEntities, rangeToReplace, ); - var character = CharacterMetadata.create({ + const character = CharacterMetadata.create({ style: inlineStyle || OrderedSet(), entity: entityKey || null, }); @@ -100,9 +100,9 @@ var DraftModifier = { removalRange: SelectionState, targetRange: SelectionState, ): ContentState { - var movedFragment = getContentStateFragment(contentState, removalRange); + const movedFragment = getContentStateFragment(contentState, removalRange); - var afterRemoval = DraftModifier.removeRange( + const afterRemoval = DraftModifier.removeRange( contentState, removalRange, 'backward', @@ -120,8 +120,11 @@ var DraftModifier = { targetRange: SelectionState, fragment: BlockMap, ): ContentState { - var withoutEntities = removeEntitiesAtEdges(contentState, targetRange); - var withoutText = removeRangeFromContentState(withoutEntities, targetRange); + const withoutEntities = removeEntitiesAtEdges(contentState, targetRange); + const withoutText = removeRangeFromContentState( + withoutEntities, + targetRange, + ); return insertFragmentIntoContentState( withoutText, @@ -182,7 +185,7 @@ var DraftModifier = { ); } - var withoutEntities = removeEntitiesAtEdges( + const withoutEntities = removeEntitiesAtEdges( contentState, adjustedRemovalRange, ); @@ -193,8 +196,8 @@ var DraftModifier = { contentState: ContentState, selectionState: SelectionState, ): ContentState { - var withoutEntities = removeEntitiesAtEdges(contentState, selectionState); - var withoutText = removeRangeFromContentState( + const withoutEntities = removeEntitiesAtEdges(contentState, selectionState); + const withoutText = removeRangeFromContentState( withoutEntities, selectionState, ); @@ -264,7 +267,7 @@ var DraftModifier = { selectionState: SelectionState, entityKey: ?string, ): ContentState { - var withoutEntities = removeEntitiesAtEdges(contentState, selectionState); + const withoutEntities = removeEntitiesAtEdges(contentState, selectionState); return applyEntityToContentState( withoutEntities, selectionState, diff --git a/src/model/modifier/DraftRemovableWord.js b/src/model/modifier/DraftRemovableWord.js index ce638ccc8c..6f48eafb76 100644 --- a/src/model/modifier/DraftRemovableWord.js +++ b/src/model/modifier/DraftRemovableWord.js @@ -12,21 +12,21 @@ 'use strict'; -var TokenizeUtil = require('TokenizeUtil'); +const TokenizeUtil = require('TokenizeUtil'); -var punctuation = TokenizeUtil.getPunctuation(); +const punctuation = TokenizeUtil.getPunctuation(); // The apostrophe and curly single quotes behave in a curious way: when // surrounded on both sides by word characters, they behave as word chars; when // either neighbor is punctuation or an end of the string, they behave as // punctuation. -var CHAMELEON_CHARS = "['\u2018\u2019]"; +const CHAMELEON_CHARS = "['\u2018\u2019]"; // Remove the underscore, which should count as part of the removable word. The // "chameleon chars" also count as punctuation in this regex. -var WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation; +const WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation; -var DELETE_STRING = +const DELETE_STRING = '^' + '(?:' + WHITESPACE_AND_PUNCTUATION + @@ -39,9 +39,9 @@ var DELETE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)'; -var DELETE_REGEX = new RegExp(DELETE_STRING); +const DELETE_REGEX = new RegExp(DELETE_STRING); -var BACKSPACE_STRING = +const BACKSPACE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)' + @@ -54,16 +54,16 @@ var BACKSPACE_STRING = WHITESPACE_AND_PUNCTUATION + ')*' + '$'; -var BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING); +const BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING); function getRemovableWord(text: string, isBackward: boolean): string { - var matches = isBackward + const matches = isBackward ? BACKSPACE_REGEX.exec(text) : DELETE_REGEX.exec(text); return matches ? matches[0] : text; } -var DraftRemovableWord = { +const DraftRemovableWord = { getBackward: function(text: string): string { return getRemovableWord(text, true); }, diff --git a/src/model/modifier/RichTextEditorUtil.js b/src/model/modifier/RichTextEditorUtil.js index 34b2a33476..455d2d124e 100644 --- a/src/model/modifier/RichTextEditorUtil.js +++ b/src/model/modifier/RichTextEditorUtil.js @@ -26,7 +26,7 @@ const nullthrows = require('nullthrows'); const RichTextEditorUtil = { currentBlockContainsLink: function(editorState: EditorState): boolean { - var selection = editorState.getSelection(); + const selection = editorState.getSelection(); const contentState = editorState.getCurrentContent(); const entityMap = contentState.getEntityMap(); return contentState @@ -34,13 +34,13 @@ const RichTextEditorUtil = { .getCharacterList() .slice(selection.getStartOffset(), selection.getEndOffset()) .some(v => { - var entity = v.getEntity(); + const entity = v.getEntity(); return !!entity && entityMap.__get(entity).getType() === 'LINK'; }); }, getCurrentBlockType: function(editorState: EditorState): DraftBlockType { - var selection = editorState.getSelection(); + const selection = editorState.getSelection(); return editorState .getCurrentContent() .getBlockForKey(selection.getStartKey()) @@ -79,7 +79,7 @@ const RichTextEditorUtil = { }, insertSoftNewline: function(editorState: EditorState): EditorState { - var contentState = DraftModifier.insertText( + const contentState = DraftModifier.insertText( editorState.getCurrentContent(), editorState.getSelection(), '\n', @@ -87,7 +87,7 @@ const RichTextEditorUtil = { null, ); - var newEditorState = EditorState.push( + const newEditorState = EditorState.push( editorState, contentState, 'insert-characters', @@ -104,7 +104,7 @@ const RichTextEditorUtil = { * just remove the existing style. */ onBackspace: function(editorState: EditorState): ?EditorState { - var selection = editorState.getSelection(); + const selection = editorState.getSelection(); if ( !selection.isCollapsed() || selection.getAnchorOffset() || @@ -114,13 +114,13 @@ const RichTextEditorUtil = { } // First, try to remove a preceding atomic block. - var content = editorState.getCurrentContent(); - var startKey = selection.getStartKey(); - var blockBefore = content.getBlockBefore(startKey); + const content = editorState.getCurrentContent(); + const startKey = selection.getStartKey(); + const blockBefore = content.getBlockBefore(startKey); if (blockBefore && blockBefore.getType() === 'atomic') { const blockMap = content.getBlockMap().delete(blockBefore.getKey()); - var withoutAtomicBlock = content.merge({ + const withoutAtomicBlock = content.merge({ blockMap, selectionAfter: selection, }); @@ -134,7 +134,7 @@ const RichTextEditorUtil = { } // If that doesn't succeed, try to remove the current block style. - var withoutBlockStyle = RichTextEditorUtil.tryToRemoveBlockStyle( + const withoutBlockStyle = RichTextEditorUtil.tryToRemoveBlockStyle( editorState, ); @@ -194,27 +194,27 @@ const RichTextEditorUtil = { editorState: EditorState, maxDepth: number, ): EditorState { - var selection = editorState.getSelection(); - var key = selection.getAnchorKey(); + const selection = editorState.getSelection(); + const key = selection.getAnchorKey(); if (key !== selection.getFocusKey()) { return editorState; } - var content = editorState.getCurrentContent(); - var block = content.getBlockForKey(key); - var type = block.getType(); + const content = editorState.getCurrentContent(); + const block = content.getBlockForKey(key); + const type = block.getType(); if (type !== 'unordered-list-item' && type !== 'ordered-list-item') { return editorState; } event.preventDefault(); - var depth = block.getDepth(); + const depth = block.getDepth(); if (!event.shiftKey && depth === maxDepth) { return editorState; } - var withAdjustment = adjustBlockDepthForContentState( + const withAdjustment = adjustBlockDepthForContentState( content, selection, event.shiftKey ? -1 : 1, @@ -228,18 +228,18 @@ const RichTextEditorUtil = { editorState: EditorState, blockType: DraftBlockType, ): EditorState { - var selection = editorState.getSelection(); - var startKey = selection.getStartKey(); - var endKey = selection.getEndKey(); - var content = editorState.getCurrentContent(); - var target = selection; + const selection = editorState.getSelection(); + const startKey = selection.getStartKey(); + let endKey = selection.getEndKey(); + const content = editorState.getCurrentContent(); + let target = selection; // Triple-click can lead to a selection that includes offset 0 of the // following block. The `SelectionState` for this case is accurate, but // we should avoid toggling block type for the trailing block because it // is a confusing interaction. if (startKey !== endKey && selection.getEndOffset() === 0) { - var blockBefore = nullthrows(content.getBlockBefore(endKey)); + const blockBefore = nullthrows(content.getBlockBefore(endKey)); endKey = blockBefore.getKey(); target = target.merge({ anchorKey: startKey, @@ -250,7 +250,7 @@ const RichTextEditorUtil = { }); } - var hasAtomicBlock = content + const hasAtomicBlock = content .getBlockMap() .skipWhile((_, k) => k !== startKey) .reverse() @@ -261,7 +261,7 @@ const RichTextEditorUtil = { return editorState; } - var typeToSet = + const typeToSet = content.getBlockForKey(startKey).getType() === blockType ? 'unstyled' : blockType; @@ -274,9 +274,9 @@ const RichTextEditorUtil = { }, toggleCode: function(editorState: EditorState): EditorState { - var selection = editorState.getSelection(); - var anchorKey = selection.getAnchorKey(); - var focusKey = selection.getFocusKey(); + const selection = editorState.getSelection(); + const anchorKey = selection.getAnchorKey(); + const focusKey = selection.getFocusKey(); if (selection.isCollapsed() || anchorKey !== focusKey) { return RichTextEditorUtil.toggleBlockType(editorState, 'code-block'); @@ -295,8 +295,8 @@ const RichTextEditorUtil = { editorState: EditorState, inlineStyle: string, ): EditorState { - var selection = editorState.getSelection(); - var currentStyle = editorState.getCurrentInlineStyle(); + const selection = editorState.getSelection(); + const currentStyle = editorState.getCurrentInlineStyle(); // If the selection is collapsed, toggle the specified style on or off and // set the result as the new inline style override. This will then be @@ -312,8 +312,8 @@ const RichTextEditorUtil = { // If characters are selected, immediately apply or remove the // inline style on the document state itself. - var content = editorState.getCurrentContent(); - var newContent; + const content = editorState.getCurrentContent(); + let newContent; // If the style is already present for the selection range, remove it. // Otherwise, apply it. @@ -339,7 +339,7 @@ const RichTextEditorUtil = { targetSelection: SelectionState, entityKey: ?string, ): EditorState { - var withoutLink = DraftModifier.applyEntity( + const withoutLink = DraftModifier.applyEntity( editorState.getCurrentContent(), targetSelection, entityKey, @@ -353,15 +353,15 @@ const RichTextEditorUtil = { * type to 'unstyled'. Returns null if selection does not meet that criteria. */ tryToRemoveBlockStyle: function(editorState: EditorState): ?ContentState { - var selection = editorState.getSelection(); - var offset = selection.getAnchorOffset(); + const selection = editorState.getSelection(); + const offset = selection.getAnchorOffset(); if (selection.isCollapsed() && offset === 0) { - var key = selection.getAnchorKey(); - var content = editorState.getCurrentContent(); - var block = content.getBlockForKey(key); + const key = selection.getAnchorKey(); + const content = editorState.getCurrentContent(); + const block = content.getBlockForKey(key); - var type = block.getType(); - var blockBefore = content.getBlockBefore(key); + const type = block.getType(); + const blockBefore = content.getBlockBefore(key); if ( type === 'code-block' && blockBefore && diff --git a/src/model/modifier/getCharacterRemovalRange.js b/src/model/modifier/getCharacterRemovalRange.js index d22d9b91c3..a4f748a176 100644 --- a/src/model/modifier/getCharacterRemovalRange.js +++ b/src/model/modifier/getCharacterRemovalRange.js @@ -17,10 +17,10 @@ import type {DraftRemovalDirection} from 'DraftRemovalDirection'; import type {EntityMap} from 'EntityMap'; import type SelectionState from 'SelectionState'; -var DraftEntitySegments = require('DraftEntitySegments'); +const DraftEntitySegments = require('DraftEntitySegments'); -var getRangesForDraftEntity = require('getRangesForDraftEntity'); -var invariant = require('invariant'); +const getRangesForDraftEntity = require('getRangesForDraftEntity'); +const invariant = require('invariant'); /** * Given a SelectionState and a removal direction, determine the entire range @@ -38,14 +38,14 @@ function getCharacterRemovalRange( selectionState: SelectionState, direction: DraftRemovalDirection, ): SelectionState { - var start = selectionState.getStartOffset(); - var end = selectionState.getEndOffset(); - var startEntityKey = startBlock.getEntityAt(start); - var endEntityKey = endBlock.getEntityAt(end - 1); + const start = selectionState.getStartOffset(); + const end = selectionState.getEndOffset(); + const startEntityKey = startBlock.getEntityAt(start); + const endEntityKey = endBlock.getEntityAt(end - 1); if (!startEntityKey && !endEntityKey) { return selectionState; } - var newSelectionState = selectionState; + let newSelectionState = selectionState; if (startEntityKey && startEntityKey === endEntityKey) { newSelectionState = getEntityRemovalRange( entityMap, @@ -121,10 +121,10 @@ function getEntityRemovalRange( isEntireSelectionWithinEntity: boolean, isEntityAtStart: boolean, ): SelectionState { - var start = selectionState.getStartOffset(); - var end = selectionState.getEndOffset(); - var entity = entityMap.__get(entityKey); - var mutability = entity.getMutability(); + let start = selectionState.getStartOffset(); + let end = selectionState.getEndOffset(); + const entity = entityMap.__get(entityKey); + const mutability = entity.getMutability(); const sideToConsider = isEntityAtStart ? start : end; // `MUTABLE` entities can just have the specified range of text removed @@ -134,7 +134,7 @@ function getEntityRemovalRange( } // Find the entity range that overlaps with our removal range. - var entityRanges = getRangesForDraftEntity(block, entityKey).filter( + const entityRanges = getRangesForDraftEntity(block, entityKey).filter( range => sideToConsider <= range.end && sideToConsider >= range.start, ); @@ -143,7 +143,7 @@ function getEntityRemovalRange( 'There should only be one entity range within this removal range.', ); - var entityRange = entityRanges[0]; + const entityRange = entityRanges[0]; // For `IMMUTABLE` entity types, we will remove the entire entity range. if (mutability === 'IMMUTABLE') { @@ -164,7 +164,7 @@ function getEntityRemovalRange( } } - var removalRange = DraftEntitySegments.getRemovalRange( + const removalRange = DraftEntitySegments.getRemovalRange( start, end, block.getText().slice(entityRange.start, entityRange.end), diff --git a/src/model/modifier/getRangesForDraftEntity.js b/src/model/modifier/getRangesForDraftEntity.js index 94b950e9ad..0c061b6256 100644 --- a/src/model/modifier/getRangesForDraftEntity.js +++ b/src/model/modifier/getRangesForDraftEntity.js @@ -15,7 +15,7 @@ import type {BlockNodeRecord} from 'BlockNodeRecord'; import type {DraftRange} from 'DraftRange'; -var invariant = require('invariant'); +const invariant = require('invariant'); /** * Obtain the start and end positions of the range that has the @@ -29,7 +29,7 @@ function getRangesForDraftEntity( block: BlockNodeRecord, key: string, ): Array { - var ranges = []; + const ranges = []; block.findEntityRanges( c => c.getEntity() === key, (start, end) => { diff --git a/src/model/paste/__mocks__/getSafeBodyFromHTML.js b/src/model/paste/__mocks__/getSafeBodyFromHTML.js index 623b4d0434..8ae242e204 100644 --- a/src/model/paste/__mocks__/getSafeBodyFromHTML.js +++ b/src/model/paste/__mocks__/getSafeBodyFromHTML.js @@ -12,8 +12,8 @@ // THIS IS PURELY A MOCK TO GET AROUND THE TEST FRAMEWORK // Never use this for anything else ever. function getUnsafeBodyFromHTML(html) { - var fragment = document.createElement('body'); - var match = html.match(/(.*?)<\/body>/); + const fragment = document.createElement('body'); + const match = html.match(/(.*?)<\/body>/); fragment.innerHTML = match ? match[1] : html; return fragment; } diff --git a/src/model/paste/getSafeBodyFromHTML.js b/src/model/paste/getSafeBodyFromHTML.js index b21af81cfa..d742975e1f 100644 --- a/src/model/paste/getSafeBodyFromHTML.js +++ b/src/model/paste/getSafeBodyFromHTML.js @@ -12,19 +12,19 @@ 'use strict'; -var UserAgent = require('UserAgent'); +const UserAgent = require('UserAgent'); const invariant = require('invariant'); -var isOldIE = UserAgent.isBrowser('IE <= 9'); +const isOldIE = UserAgent.isBrowser('IE <= 9'); // Provides a dom node that will not execute scripts // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/HTML_to_DOM function getSafeBodyFromHTML(html: string): ?Element { - var doc; - var root = null; + let doc; + let root = null; // Provides a safe context if ( !isOldIE && diff --git a/src/model/transaction/ContentStateInlineStyle.js b/src/model/transaction/ContentStateInlineStyle.js index 460edda6d0..c3b68959b3 100644 --- a/src/model/transaction/ContentStateInlineStyle.js +++ b/src/model/transaction/ContentStateInlineStyle.js @@ -15,10 +15,10 @@ import type ContentState from 'ContentState'; import type SelectionState from 'SelectionState'; -var CharacterMetadata = require('CharacterMetadata'); -var {Map} = require('immutable'); +const CharacterMetadata = require('CharacterMetadata'); +const {Map} = require('immutable'); -var ContentStateInlineStyle = { +const ContentStateInlineStyle = { add: function( contentState: ContentState, selectionState: SelectionState, @@ -42,19 +42,19 @@ function modifyInlineStyle( inlineStyle: string, addOrRemove: boolean, ): ContentState { - var blockMap = contentState.getBlockMap(); - var startKey = selectionState.getStartKey(); - var startOffset = selectionState.getStartOffset(); - var endKey = selectionState.getEndKey(); - var endOffset = selectionState.getEndOffset(); + const blockMap = contentState.getBlockMap(); + const startKey = selectionState.getStartKey(); + const startOffset = selectionState.getStartOffset(); + const endKey = selectionState.getEndKey(); + const endOffset = selectionState.getEndOffset(); - var newBlocks = blockMap + const newBlocks = blockMap .skipUntil((_, k) => k === startKey) .takeUntil((_, k) => k === endKey) .concat(Map([[endKey, blockMap.get(endKey)]])) .map((block, blockKey) => { - var sliceStart; - var sliceEnd; + let sliceStart; + let sliceEnd; if (startKey === endKey) { sliceStart = startOffset; @@ -64,8 +64,8 @@ function modifyInlineStyle( sliceEnd = blockKey === endKey ? endOffset : block.getLength(); } - var chars = block.getCharacterList(); - var current; + let chars = block.getCharacterList(); + let current; while (sliceStart < sliceEnd) { current = chars.get(sliceStart); chars = chars.set( diff --git a/src/model/transaction/adjustBlockDepthForContentState.js b/src/model/transaction/adjustBlockDepthForContentState.js index 936985a7b2..a75803d4b5 100644 --- a/src/model/transaction/adjustBlockDepthForContentState.js +++ b/src/model/transaction/adjustBlockDepthForContentState.js @@ -21,16 +21,16 @@ function adjustBlockDepthForContentState( adjustment: number, maxDepth: number, ): ContentState { - var startKey = selectionState.getStartKey(); - var endKey = selectionState.getEndKey(); - var blockMap = contentState.getBlockMap(); - var blocks = blockMap + const startKey = selectionState.getStartKey(); + const endKey = selectionState.getEndKey(); + let blockMap = contentState.getBlockMap(); + const blocks = blockMap .toSeq() .skipUntil((_, k) => k === startKey) .takeUntil((_, k) => k === endKey) .concat([[endKey, blockMap.get(endKey)]]) .map(block => { - var depth = block.getDepth() + adjustment; + let depth = block.getDepth() + adjustment; depth = Math.max(0, Math.min(depth, maxDepth)); return block.set('depth', depth); }); diff --git a/src/model/transaction/applyEntityToContentBlock.js b/src/model/transaction/applyEntityToContentBlock.js index c49ec0ad22..1a1ed361ce 100644 --- a/src/model/transaction/applyEntityToContentBlock.js +++ b/src/model/transaction/applyEntityToContentBlock.js @@ -14,7 +14,7 @@ import type {BlockNodeRecord} from 'BlockNodeRecord'; -var CharacterMetadata = require('CharacterMetadata'); +const CharacterMetadata = require('CharacterMetadata'); function applyEntityToContentBlock( contentBlock: BlockNodeRecord, @@ -22,7 +22,7 @@ function applyEntityToContentBlock( end: number, entityKey: ?string, ): BlockNodeRecord { - var characterList = contentBlock.getCharacterList(); + let characterList = contentBlock.getCharacterList(); while (start < end) { characterList = characterList.set( start, diff --git a/src/model/transaction/applyEntityToContentState.js b/src/model/transaction/applyEntityToContentState.js index 22e7c34b34..557a71d7c2 100644 --- a/src/model/transaction/applyEntityToContentState.js +++ b/src/model/transaction/applyEntityToContentState.js @@ -15,9 +15,9 @@ import type ContentState from 'ContentState'; import type SelectionState from 'SelectionState'; -var Immutable = require('immutable'); +const Immutable = require('immutable'); -var applyEntityToContentBlock = require('applyEntityToContentBlock'); +const applyEntityToContentBlock = require('applyEntityToContentBlock'); function applyEntityToContentState( contentState: ContentState, diff --git a/src/model/transaction/insertIntoList.js b/src/model/transaction/insertIntoList.js index 3959fa70f0..847f0011f5 100644 --- a/src/model/transaction/insertIntoList.js +++ b/src/model/transaction/insertIntoList.js @@ -31,8 +31,8 @@ function insertIntoList( targetList = targetList.unshift(c); }); } else { - var head = targetList.slice(0, offset); - var tail = targetList.slice(offset); + const head = targetList.slice(0, offset); + const tail = targetList.slice(offset); targetList = head.concat(toInsert, tail).toList(); } return targetList; diff --git a/src/model/transaction/insertTextIntoContentState.js b/src/model/transaction/insertTextIntoContentState.js index ced592fdb3..d0a1b8dc40 100644 --- a/src/model/transaction/insertTextIntoContentState.js +++ b/src/model/transaction/insertTextIntoContentState.js @@ -12,12 +12,12 @@ 'use strict'; -var Immutable = require('immutable'); +const Immutable = require('immutable'); -var insertIntoList = require('insertIntoList'); -var invariant = require('invariant'); +const insertIntoList = require('insertIntoList'); +const invariant = require('invariant'); -var {Repeat} = Immutable; +const {Repeat} = Immutable; import type CharacterMetadata from 'CharacterMetadata'; import type ContentState from 'ContentState'; @@ -34,18 +34,18 @@ function insertTextIntoContentState( '`insertText` should only be called with a collapsed range.', ); - var len = text.length; + const len = text.length; if (!len) { return contentState; } - var blockMap = contentState.getBlockMap(); - var key = selectionState.getStartKey(); - var offset = selectionState.getStartOffset(); - var block = blockMap.get(key); - var blockText = block.getText(); + const blockMap = contentState.getBlockMap(); + const key = selectionState.getStartKey(); + const offset = selectionState.getStartOffset(); + const block = blockMap.get(key); + const blockText = block.getText(); - var newBlock = block.merge({ + const newBlock = block.merge({ text: blockText.slice(0, offset) + text + @@ -57,7 +57,7 @@ function insertTextIntoContentState( ), }); - var newOffset = offset + len; + const newOffset = offset + len; return contentState.merge({ blockMap: blockMap.set(key, newBlock), diff --git a/src/model/transaction/modifyBlockForContentState.js b/src/model/transaction/modifyBlockForContentState.js index 2f029e8898..592324cad6 100644 --- a/src/model/transaction/modifyBlockForContentState.js +++ b/src/model/transaction/modifyBlockForContentState.js @@ -25,10 +25,10 @@ function modifyBlockForContentState( selectionState: SelectionState, operation: (block: BlockNodeRecord) => BlockNodeRecord, ): ContentState { - var startKey = selectionState.getStartKey(); - var endKey = selectionState.getEndKey(); - var blockMap = contentState.getBlockMap(); - var newBlocks = blockMap + const startKey = selectionState.getStartKey(); + const endKey = selectionState.getEndKey(); + const blockMap = contentState.getBlockMap(); + const newBlocks = blockMap .toSeq() .skipUntil((_, k) => k === startKey) .takeUntil((_, k) => k === endKey) diff --git a/src/model/transaction/removeEntitiesAtEdges.js b/src/model/transaction/removeEntitiesAtEdges.js index 634def68b5..61193f56bf 100644 --- a/src/model/transaction/removeEntitiesAtEdges.js +++ b/src/model/transaction/removeEntitiesAtEdges.js @@ -18,37 +18,37 @@ import type {EntityMap} from 'EntityMap'; import type SelectionState from 'SelectionState'; import type {List} from 'immutable'; -var CharacterMetadata = require('CharacterMetadata'); +const CharacterMetadata = require('CharacterMetadata'); -var findRangesImmutable = require('findRangesImmutable'); -var invariant = require('invariant'); +const findRangesImmutable = require('findRangesImmutable'); +const invariant = require('invariant'); function removeEntitiesAtEdges( contentState: ContentState, selectionState: SelectionState, ): ContentState { - var blockMap = contentState.getBlockMap(); - var entityMap = contentState.getEntityMap(); + const blockMap = contentState.getBlockMap(); + const entityMap = contentState.getEntityMap(); - var updatedBlocks = {}; + const updatedBlocks = {}; - var startKey = selectionState.getStartKey(); - var startOffset = selectionState.getStartOffset(); - var startBlock = blockMap.get(startKey); - var updatedStart = removeForBlock(entityMap, startBlock, startOffset); + const startKey = selectionState.getStartKey(); + const startOffset = selectionState.getStartOffset(); + const startBlock = blockMap.get(startKey); + const updatedStart = removeForBlock(entityMap, startBlock, startOffset); if (updatedStart !== startBlock) { updatedBlocks[startKey] = updatedStart; } - var endKey = selectionState.getEndKey(); - var endOffset = selectionState.getEndOffset(); - var endBlock = blockMap.get(endKey); + const endKey = selectionState.getEndKey(); + const endOffset = selectionState.getEndOffset(); + let endBlock = blockMap.get(endKey); if (startKey === endKey) { endBlock = updatedStart; } - var updatedEnd = removeForBlock(entityMap, endBlock, endOffset); + const updatedEnd = removeForBlock(entityMap, endBlock, endOffset); if (updatedEnd !== endBlock) { updatedBlocks[endKey] = updatedEnd; @@ -77,7 +77,7 @@ function getRemovalRange( start: number, end: number, } { - var removalRange; + let removalRange; // Iterates through a list looking for ranges of matching items // based on the 'isEqual' callback. @@ -110,17 +110,17 @@ function removeForBlock( block: BlockNodeRecord, offset: number, ): BlockNodeRecord { - var chars = block.getCharacterList(); - var charBefore = offset > 0 ? chars.get(offset - 1) : undefined; - var charAfter = offset < chars.count() ? chars.get(offset) : undefined; - var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined; - var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined; + let chars = block.getCharacterList(); + const charBefore = offset > 0 ? chars.get(offset - 1) : undefined; + const charAfter = offset < chars.count() ? chars.get(offset) : undefined; + const entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined; + const entityAfterCursor = charAfter ? charAfter.getEntity() : undefined; if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) { - var entity = entityMap.__get(entityAfterCursor); + const entity = entityMap.__get(entityAfterCursor); if (entity.getMutability() !== 'MUTABLE') { - var {start, end} = getRemovalRange(chars, entityAfterCursor, offset); - var current; + let {start, end} = getRemovalRange(chars, entityAfterCursor, offset); + let current; while (start < end) { current = chars.get(start); chars = chars.set(start, CharacterMetadata.applyEntity(current, null));