forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext-node.js
More file actions
101 lines (85 loc) · 2.39 KB
/
Copy pathtext-node.js
File metadata and controls
101 lines (85 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// ReactJS
const PropTypes = require("prop-types");
// Reps
const { isGrip, cropString, wrapRender } = require("./rep-utils");
const { MODE } = require("./constants");
const dom = require("react-dom-factories");
const { span } = dom;
/**
* Renders DOM #text node.
*/
TextNode.propTypes = {
object: PropTypes.object.isRequired,
// @TODO Change this to Object.values when supported in Node's version of V8
mode: PropTypes.oneOf(Object.keys(MODE).map(key => MODE[key])),
onDOMNodeMouseOver: PropTypes.func,
onDOMNodeMouseOut: PropTypes.func,
onInspectIconClick: PropTypes.func
};
function TextNode(props) {
const {
object: grip,
mode = MODE.SHORT,
onDOMNodeMouseOver,
onDOMNodeMouseOut,
onInspectIconClick
} = props;
const baseConfig = {
"data-link-actor-id": grip.actor,
className: "objectBox objectBox-textNode"
};
let inspectIcon;
const isInTree = grip.preview && grip.preview.isConnected === true;
if (isInTree) {
if (onDOMNodeMouseOver) {
Object.assign(baseConfig, {
onMouseOver: _ => onDOMNodeMouseOver(grip)
});
}
if (onDOMNodeMouseOut) {
Object.assign(baseConfig, {
onMouseOut: onDOMNodeMouseOut
});
}
if (onInspectIconClick) {
inspectIcon = dom.button({
className: "open-inspector",
draggable: false,
// TODO: Localize this with "openNodeInInspector" when Bug 1317038 lands
title: "Click to select the node in the inspector",
onClick: e => onInspectIconClick(grip, e)
});
}
}
if (mode === MODE.TINY) {
return span(baseConfig, getTitle(grip), inspectIcon);
}
return span(
baseConfig,
getTitle(grip),
span({ className: "nodeValue" }, " ", `"${getTextContent(grip)}"`),
inspectIcon
);
}
function getTextContent(grip) {
return cropString(grip.preview.textContent);
}
function getTitle(grip) {
const title = "#text";
return span({}, title);
}
// Registration
function supportsObject(grip, noGrip = false) {
if (noGrip === true || !isGrip(grip)) {
return false;
}
return grip.preview && grip.class == "Text";
}
// Exports from this module
module.exports = {
rep: wrapRender(TextNode),
supportsObject
};