visibleBreakpoints.js (1727B)
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 import { createSelector } from "devtools/client/shared/vendor/reselect"; 6 7 import { getBreakpointsList } from "./breakpoints"; 8 import { getSelectedSource } from "./sources"; 9 10 import { sortSelectedBreakpoints } from "../utils/breakpoint/index"; 11 import { getSelectedLocation } from "../utils/selected-location"; 12 13 /* 14 * Finds the breakpoints, which appear in the selected source. 15 */ 16 export const getVisibleBreakpoints = createSelector( 17 getSelectedSource, 18 getBreakpointsList, 19 (selectedSource, breakpoints) => { 20 if (!selectedSource) { 21 return null; 22 } 23 24 return breakpoints.filter( 25 breakpoint => 26 selectedSource && 27 getSelectedLocation(breakpoint, selectedSource)?.source.id === 28 selectedSource.id && 29 !breakpoint.options.hidden 30 ); 31 } 32 ); 33 34 /* 35 * Finds the first breakpoint per line, which appear in the selected source. 36 */ 37 export const getFirstVisibleBreakpoints = createSelector( 38 getVisibleBreakpoints, 39 getSelectedSource, 40 (breakpoints, selectedSource) => { 41 if (!breakpoints || !selectedSource) { 42 return []; 43 } 44 45 // Filter the array so it only return the first breakpoint when there's multiple 46 // breakpoints on the same line. 47 const handledLines = new Set(); 48 return sortSelectedBreakpoints(breakpoints, selectedSource).filter(bp => { 49 const line = getSelectedLocation(bp, selectedSource).line; 50 if (handledLines.has(line)) { 51 return false; 52 } 53 handledLines.add(line); 54 return true; 55 }); 56 } 57 );