tor-browser

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

InlinePreview.js (2181B)


      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 React, { PureComponent } from "devtools/client/shared/vendor/react";
      6 import { span } from "devtools/client/shared/vendor/react-dom-factories";
      7 import PropTypes from "devtools/client/shared/vendor/react-prop-types";
      8 const Reps = ChromeUtils.importESModule(
      9  "resource://devtools/client/shared/components/reps/index.mjs"
     10 );
     11 
     12 const {
     13  REPS: {
     14    Rep,
     15    ElementNode: { supportsObject: isElement },
     16  },
     17  MODE,
     18 } = Reps;
     19 
     20 // Renders single variable preview inside a codemirror line widget
     21 class InlinePreview extends PureComponent {
     22  static get propTypes() {
     23    return {
     24      highlightDomElement: PropTypes.func.isRequired,
     25      openElementInInspector: PropTypes.func.isRequired,
     26      unHighlightDomElement: PropTypes.func.isRequired,
     27      type: PropTypes.string.isRequired,
     28      value: PropTypes.any,
     29      variable: PropTypes.string.isRequired,
     30    };
     31  }
     32 
     33  showInScopes() {
     34    // TODO: focus on variable value in the scopes sidepanel
     35    // we will need more info from parent comp
     36  }
     37 
     38  render() {
     39    const {
     40      type,
     41      value,
     42      variable,
     43      openElementInInspector,
     44      highlightDomElement,
     45      unHighlightDomElement,
     46    } = this.props;
     47 
     48    const mode = isElement(value) ? MODE.TINY : MODE.SHORT;
     49    return span(
     50      {
     51        className: "inline-preview-outer",
     52        onClick: () => this.showInScopes(variable),
     53      },
     54      span(
     55        {
     56          className: `inline-preview-label ${type}`,
     57        },
     58        variable,
     59        ":"
     60      ),
     61      span(
     62        {
     63          className: "inline-preview-value",
     64        },
     65        React.createElement(Rep, {
     66          object: value,
     67          mode,
     68          onDOMNodeClick: grip => openElementInInspector(grip),
     69          onInspectIconClick: grip => openElementInInspector(grip),
     70          onDOMNodeMouseOver: grip => highlightDomElement(grip),
     71          onDOMNodeMouseOut: grip => unHighlightDomElement(grip),
     72        })
     73      )
     74    );
     75  }
     76 }
     77 
     78 export default InlinePreview;