tor-browser

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

document.mjs (1860B)


      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 /* eslint no-shadow: ["error", { "allow": ["Document", "location"] }] */
      6 
      7 import PropTypes from "resource://devtools/client/shared/vendor/react-prop-types.mjs";
      8 import { span } from "resource://devtools/client/shared/vendor/react-dom-factories.mjs";
      9 
     10 import { getGripType, getURLDisplayString, wrapRender } from "./rep-utils.mjs";
     11 
     12 /**
     13 * Renders DOM document object.
     14 */
     15 
     16 DocumentRep.propTypes = {
     17  object: PropTypes.object.isRequired,
     18  shouldRenderTooltip: PropTypes.bool,
     19 };
     20 
     21 function DocumentRep(props) {
     22  const grip = props.object;
     23  const shouldRenderTooltip = props.shouldRenderTooltip;
     24  const location = getLocation(grip);
     25  const config = getElementConfig({ grip, location, shouldRenderTooltip });
     26  return span(
     27    config,
     28    getTitle(grip),
     29    location ? span({ className: "location" }, ` ${location}`) : null
     30  );
     31 }
     32 
     33 function getElementConfig(opts) {
     34  const { grip, location, shouldRenderTooltip } = opts;
     35  const config = {
     36    "data-link-actor-id": grip.actor,
     37    className: "objectBox objectBox-document",
     38  };
     39 
     40  if (!shouldRenderTooltip || !location) {
     41    return config;
     42  }
     43  config.title = `${grip.class} ${location}`;
     44  return config;
     45 }
     46 
     47 function getLocation(grip) {
     48  const location = grip.preview.location;
     49  return location ? getURLDisplayString(location) : null;
     50 }
     51 
     52 function getTitle(grip) {
     53  return span(
     54    {
     55      className: "objectTitle",
     56    },
     57    grip.class
     58  );
     59 }
     60 
     61 // Registration
     62 function supportsObject(object, noGrip = false) {
     63  return object?.preview && getGripType(object, noGrip) === "HTMLDocument";
     64 }
     65 
     66 const rep = wrapRender(DocumentRep);
     67 
     68 // Exports from this module
     69 export { rep, supportsObject };