Skip to content

Commit

Permalink
Commandeers and applies PR feedback to facebookarchive#1877
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio Procida committed Nov 19, 2018
1 parent d27b28b commit de81349
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 45 deletions.
2 changes: 1 addition & 1 deletion meta/bundle-size-stats/Draft.js.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion meta/bundle-size-stats/Draft.min.js.json

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions src/component/selection/setDraftEditorSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ function anonymizeTextWithin(

if (node.nodeType === Node.TEXT_NODE) {
const length = node.textContent.length;
const documentObject = getCorrectDocumentFromNode(node);

return documentObject.createTextNode(
return getCorrectDocumentFromNode(node).createTextNode(
'[text ' +
length +
(labels.length ? ' | ' + labels.join(', ') : '') +
Expand Down Expand Up @@ -89,6 +87,7 @@ function getAnonymizedEditorDOM(
return getAnonymizedDOM(currentNode, getNodeLabels);
} else {
currentNode = currentNode.parentNode;
castedNode = (currentNode: any);
}
}
return 'Could not find contentEditable parent of node';
Expand Down Expand Up @@ -321,8 +320,7 @@ function addPointToSelection(
offset: number,
selectionState: SelectionState,
): void {
const documentObject = getCorrectDocumentFromNode(node);
const range = documentObject.createRange();
const range = getCorrectDocumentFromNode(node).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
Expand Down
15 changes: 14 additions & 1 deletion src/component/utils/getCorrectDocumentFromNode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
function getCorrectDocumentFromNode(node) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @format
* @flow
* @emails oncall+draft_js
*/

function getCorrectDocumentFromNode(node: ?Node) {
if (!node || !node.ownerDocument) {
return document;
}
Expand Down
23 changes: 15 additions & 8 deletions src/component/utils/isElement.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
function isElement(node) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @format
* @flow
* @emails oncall+draft_js
*/

function isElement(node: ?Node): boolean {
if (!node || !node.ownerDocument) {
return false;
}
if (!node.ownerDocument.defaultView) {
return node instanceof Element;
}
if (node instanceof node.ownerDocument.defaultView.Element) {
return true;
}
return false;
return node.nodeType === Node.ELEMENT_NODE;
}

module.exports = isElement;
25 changes: 17 additions & 8 deletions src/component/utils/isHTMLAnchorElement.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
function isHTMLAnchorElement(node) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @format
* @flow
* @emails oncall+draft_js
*/

const isElement = require('isElement');

function isHTMLAnchorElement(node: ?Node): boolean {
if (!node || !node.ownerDocument) {
return false;
}
if (!node.ownerDocument.defaultView) {
return node instanceof HTMLAnchorElement;
}
if (node instanceof node.ownerDocument.defaultView.HTMLAnchorElement) {
return true;
}
return false;
return isElement(node) && node.nodeName === 'A';
}

module.exports = isHTMLAnchorElement;
15 changes: 14 additions & 1 deletion src/component/utils/isHTMLElement.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
function isHTMLElement(node) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @format
* @flow
* @emails oncall+draft_js
*/

function isHTMLElement(node: ?Node): boolean {
if (!node || !node.ownerDocument) {
return false;
}
Expand Down
25 changes: 17 additions & 8 deletions src/component/utils/isHTMLImageElement.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
function isHTMLImageElement(node) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @format
* @flow
* @emails oncall+draft_js
*/

const isElement = require('isElement');

function isHTMLImageElement(node: ?Node): boolean {
if (!node || !node.ownerDocument) {
return false;
}
if (!node.ownerDocument.defaultView) {
return node instanceof HTMLImageElement;
}
if (node instanceof node.ownerDocument.defaultView.HTMLImageElement) {
return true;
}
return false;
return isElement(node) && node.nodeName === 'IMG';
}

module.exports = isHTMLImageElement;
31 changes: 24 additions & 7 deletions src/component/utils/isInstanceOfNode.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
function isInstanceOfNode(node) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @format
* @flow
* @emails oncall+draft_js
*/

function isInstanceOfNode(target: ?EventTarget): boolean {
// we changed the name because of having duplicate module provider (fbjs)
if (!node || !node.ownerDocument) {
if (!target || !('ownerDocument' in target)) {
return false;
}
if (!node.ownerDocument.defaultView) {
return node instanceof Node;
}
if (node instanceof node.ownerDocument.defaultView.Node) {
return true;
if ('ownerDocument' in target) {
const node: Node = (target: any);
if (!node.ownerDocument.defaultView) {
return node instanceof Node;
}
// $FlowFixMe https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11508#issuecomment-256045682
if (node instanceof node.ownerDocument.defaultView.Node) {
return true;
}
}
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions src/model/encoding/convertFromHTMLToContentBlocks2.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ const getListItemDepth = (node: HTMLElement, depth: number = 0): number => {
* Return true if the provided HTML Element can be used to build a
* Draftjs-compatible link.
*/
const isValidAnchor = (node: Node) => {
const isValidAnchor = (node: Node): boolean => {
if (isHTMLAnchorElement(node)) {
const castedNode: HTMLAnchorElement = (node: any);
return (
return Boolean(
castedNode.href &&
(castedNode.protocol === 'http:' ||
castedNode.protocol === 'https:' ||
castedNode.protocol === 'mailto:')
(castedNode.protocol === 'http:' ||
castedNode.protocol === 'https:' ||
castedNode.protocol === 'mailto:'),
);
}
return false;
Expand Down

0 comments on commit de81349

Please sign in to comment.