comment-node.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. "use strict";
  6. // Make this available to both AMD and CJS environments
  7. define(function (require, exports, module) {
  8. // ReactJS
  9. const React = require("devtools/client/shared/vendor/react");
  10. const { isGrip, cropString, cropMultipleLines } = require("./rep-utils");
  11. // Utils
  12. const nodeConstants = require("devtools/shared/dom-node-constants");
  13. // Shortcuts
  14. const { span } = React.DOM;
  15. /**
  16. * Renders DOM comment node.
  17. */
  18. const CommentNode = React.createClass({
  19. displayName: "CommentNode",
  20. propTypes: {
  21. object: React.PropTypes.object.isRequired,
  22. mode: React.PropTypes.string,
  23. },
  24. render: function () {
  25. let {object} = this.props;
  26. let mode = this.props.mode || "short";
  27. let {textContent} = object.preview;
  28. if (mode === "tiny") {
  29. textContent = cropMultipleLines(textContent, 30);
  30. } else if (mode === "short") {
  31. textContent = cropString(textContent, 50);
  32. }
  33. return span({className: "objectBox theme-comment"}, `<!-- ${textContent} -->`);
  34. },
  35. });
  36. // Registration
  37. function supportsObject(object, type) {
  38. if (!isGrip(object)) {
  39. return false;
  40. }
  41. return object.preview && object.preview.nodeType === nodeConstants.COMMENT_NODE;
  42. }
  43. // Exports from this module
  44. exports.CommentNode = {
  45. rep: CommentNode,
  46. supportsObject: supportsObject
  47. };
  48. });