tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Grid.js (3325B)


      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 const {
      8  createFactory,
      9  PureComponent,
     10 } = require("resource://devtools/client/shared/vendor/react.mjs");
     11 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
     12 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs");
     13 const {
     14  getStr,
     15 } = require("resource://devtools/client/inspector/layout/utils/l10n.js");
     16 
     17 // Normally, we would only lazy load GridOutline, but we also lazy load
     18 // GridDisplaySettings and GridList because we assume the CSS grid usage is low
     19 // and usually will not appear on the page.
     20 loader.lazyGetter(this, "GridDisplaySettings", function () {
     21  return createFactory(
     22    require("resource://devtools/client/inspector/grids/components/GridDisplaySettings.js")
     23  );
     24 });
     25 loader.lazyGetter(this, "GridList", function () {
     26  return createFactory(
     27    require("resource://devtools/client/inspector/grids/components/GridList.js")
     28  );
     29 });
     30 loader.lazyGetter(this, "GridOutline", function () {
     31  return createFactory(
     32    require("resource://devtools/client/inspector/grids/components/GridOutline.js")
     33  );
     34 });
     35 
     36 const Types = require("resource://devtools/client/inspector/grids/types.js");
     37 
     38 class Grid extends PureComponent {
     39  static get propTypes() {
     40    return {
     41      dispatch: PropTypes.func.isRequired,
     42      getSwatchColorPickerTooltip: PropTypes.func.isRequired,
     43      grids: PropTypes.arrayOf(PropTypes.shape(Types.grid)).isRequired,
     44      highlighterSettings: PropTypes.shape(Types.highlighterSettings)
     45        .isRequired,
     46      onSetGridOverlayColor: PropTypes.func.isRequired,
     47      onToggleGridHighlighter: PropTypes.func.isRequired,
     48      onToggleShowGridAreas: PropTypes.func.isRequired,
     49      onToggleShowGridLineNumbers: PropTypes.func.isRequired,
     50      onToggleShowInfiniteLines: PropTypes.func.isRequired,
     51      setSelectedNode: PropTypes.func.isRequired,
     52    };
     53  }
     54 
     55  render() {
     56    if (!this.props.grids.length) {
     57      return dom.div(
     58        { className: "devtools-sidepanel-no-result" },
     59        getStr("layout.noGridsOnThisPage")
     60      );
     61    }
     62 
     63    const {
     64      dispatch,
     65      getSwatchColorPickerTooltip,
     66      grids,
     67      highlighterSettings,
     68      onSetGridOverlayColor,
     69      onToggleShowGridAreas,
     70      onToggleGridHighlighter,
     71      onToggleShowGridLineNumbers,
     72      onToggleShowInfiniteLines,
     73      setSelectedNode,
     74    } = this.props;
     75    const highlightedGrids = grids.filter(grid => grid.highlighted);
     76 
     77    return dom.div(
     78      { id: "layout-grid-container" },
     79      dom.div(
     80        { className: "grid-content" },
     81        GridList({
     82          dispatch,
     83          getSwatchColorPickerTooltip,
     84          grids,
     85          onSetGridOverlayColor,
     86          onToggleGridHighlighter,
     87          setSelectedNode,
     88        }),
     89        GridDisplaySettings({
     90          highlighterSettings,
     91          onToggleShowGridAreas,
     92          onToggleShowGridLineNumbers,
     93          onToggleShowInfiniteLines,
     94        })
     95      ),
     96      highlightedGrids.length === 1
     97        ? GridOutline({
     98            dispatch,
     99            grids,
    100          })
    101        : null
    102    );
    103  }
    104 }
    105 
    106 module.exports = Grid;