box-model-highlighter.js (2513B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 /** 8 * This module exports thunks. 9 * Thunks are functions that can be dispatched to the Inspector Redux store. 10 * 11 * These functions receive one object with options that contains: 12 * - dispatch() => function to dispatch Redux actions to the store 13 * - getState() => function to get the current state of the entire Inspector Redux store 14 * - inspector => object instance of Inspector client 15 * 16 * They provide a shortcut for React components to invoke the box model highlighter 17 * without having to know where the highlighter exists. 18 */ 19 20 module.exports = { 21 /** 22 * Show the box model highlighter for the currently selected node front. 23 * The selected node is obtained from the Selection instance on the Inspector. 24 * 25 * @param {object} options 26 * Optional configuration options passed to the box model highlighter 27 */ 28 highlightSelectedNode(options = {}) { 29 return async thunkOptions => { 30 const { inspector } = thunkOptions; 31 if (!inspector || inspector._destroyed) { 32 return; 33 } 34 35 const { nodeFront } = inspector.selection; 36 if (!nodeFront) { 37 return; 38 } 39 40 await inspector.highlighters.showHighlighterTypeForNode( 41 inspector.highlighters.TYPES.BOXMODEL, 42 nodeFront, 43 options 44 ); 45 }; 46 }, 47 48 /** 49 * Show the box model highlighter for the given node front. 50 * 51 * @param {NodeFront} nodeFront 52 * Node that should be highlighted. 53 * @param {object} options 54 * Optional configuration options passed to the box model highlighter 55 */ 56 highlightNode(nodeFront, options = {}) { 57 return async thunkOptions => { 58 const { inspector } = thunkOptions; 59 if (!inspector || inspector._destroyed) { 60 return; 61 } 62 63 await inspector.highlighters.showHighlighterTypeForNode( 64 inspector.highlighters.TYPES.BOXMODEL, 65 nodeFront, 66 options 67 ); 68 }; 69 }, 70 71 /** 72 * Hide the box model highlighter for any highlighted node. 73 */ 74 unhighlightNode() { 75 return async thunkOptions => { 76 const { inspector } = thunkOptions; 77 if (!inspector || inspector._destroyed) { 78 return; 79 } 80 81 await inspector.highlighters.hideHighlighterType( 82 inspector.highlighters.TYPES.BOXMODEL 83 ); 84 }; 85 }, 86 };