UNPKG

ckeditor5-image-upload-base64

Version:

The development environment of CKEditor 5 – the best browser-based rich text editor.

81 lines (61 loc) 2.1 kB
/** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ /** * @module watchdog/utils/areconnectedthroughproperties */ /* globals console */ import getSubNodes from './getsubnodes'; /** * Traverses both structures to find out whether there is a reference that is shared between both structures. * * @param {Object|Array} target1 * @param {Object|Array} target2 */ export default function areConnectedThroughProperties( target1, target2, excludedNodes = new Set() ) { if ( target1 === target2 && isObject( target1 ) ) { return true; } // @if CK_DEBUG_WATCHDOG // return checkConnectionBetweenProps( target1, target2, excludedNodes ); const subNodes1 = getSubNodes( target1, excludedNodes ); const subNodes2 = getSubNodes( target2, excludedNodes ); for ( const node of subNodes1 ) { if ( subNodes2.has( node ) ) { return true; } } return false; } /* istanbul ignore next */ // eslint-disable-next-line function checkConnectionBetweenProps( target1, target2, excludedNodes ) { const { subNodes: subNodes1, prevNodeMap: prevNodeMap1 } = getSubNodes( target1, excludedNodes.subNodes ); const { subNodes: subNodes2, prevNodeMap: prevNodeMap2 } = getSubNodes( target2, excludedNodes.subNodes ); for ( const sharedNode of subNodes1 ) { if ( subNodes2.has( sharedNode ) ) { const connection = []; connection.push( sharedNode ); let node = prevNodeMap1.get( sharedNode ); while ( node && node !== target1 ) { connection.push( node ); node = prevNodeMap1.get( node ); } node = prevNodeMap2.get( sharedNode ); while ( node && node !== target2 ) { connection.unshift( node ); node = prevNodeMap2.get( node ); } console.log( '--------' ); console.log( { target1 } ); console.log( { sharedNode } ); console.log( { target2 } ); console.log( { connection } ); return true; } } return false; } function isObject( structure ) { return typeof structure === 'object' && structure !== null; }