forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResult.js
More file actions
160 lines (147 loc) · 4.5 KB
/
Copy pathResult.js
File metadata and controls
160 lines (147 loc) · 4.5 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* 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/>. */
const React = require("react");
const { Component } = React;
const PropTypes = require("prop-types");
const dom = require("react-dom-factories");
const { MODE } = require("../../reps/constants");
const { ObjectInspector } = require("../../index").objectInspector;
const { Rep } = require("../../reps/rep");
class Result extends Component {
static get propTypes() {
return {
expression: PropTypes.object.isRequired,
showResultPacket: PropTypes.func.isRequired,
hideResultPacket: PropTypes.func.isRequired
};
}
constructor(props) {
super(props);
this.copyPacketToClipboard = this.copyPacketToClipboard.bind(this);
this.onHeaderClick = this.onHeaderClick.bind(this);
this.renderRepInAllModes = this.renderRepInAllModes.bind(this);
this.renderRep = this.renderRep.bind(this);
this.renderPacket = this.renderPacket.bind(this);
}
copyPacketToClipboard(e, packet) {
e.stopPropagation();
const textField = document.createElement("textarea");
// eslint-disable-next-line no-unsanitized/property
textField.innerHTML = JSON.stringify(packet, null, " ");
document.body.appendChild(textField);
textField.select();
document.execCommand("copy");
textField.remove();
}
onHeaderClick() {
const { expression } = this.props;
if (expression.showPacket === true) {
this.props.hideResultPacket();
} else {
this.props.showResultPacket();
}
}
renderRepInAllModes({ object }) {
return Object.keys(MODE).map(modeKey =>
this.renderRep({ object, modeKey })
);
}
renderRep({ object, modeKey }) {
const path = Symbol(modeKey + object.actor);
return dom.div(
{
className: "rep-element",
key: path.toString(),
"data-mode": modeKey
},
ObjectInspector({
roots: [
{
path,
contents: {
value: object
}
}
],
autoExpandDepth: 0,
mode: MODE[modeKey],
// The following properties are optional function props called by the
// objectInspector on some occasions. Here we pass dull functions that
// only logs the parameters with which the callback was called.
onCmdCtrlClick: (node, { depth, event, focused, expanded }) =>
console.log("CmdCtrlClick", {
node,
depth,
event,
focused,
expanded
}),
onInspectIconClick: nodeFront =>
console.log("inspectIcon click", { nodeFront }),
onViewSourceInDebugger: location =>
console.log("onViewSourceInDebugger", { location }),
recordTelemetryEvent: (eventName, extra = {}) => {
console.log("📊", eventName, "📊", extra);
}
})
);
}
renderPacket(expression) {
const { packet, showPacket } = expression;
const headerClassName = showPacket ? "packet-expanded" : "packet-collapsed";
const headerLabel = showPacket
? "Hide expression packet"
: "Show expression packet";
return dom.div(
{ className: "packet" },
dom.header(
{
className: headerClassName,
onClick: this.onHeaderClick
},
headerLabel,
dom.span({ className: "copy-label" }, "Copy"),
dom.button(
{
className: "copy-packet-button",
onClick: e => this.copyPacketToClipboard(e, packet.result)
},
"grip"
),
dom.button(
{
className: "copy-packet-button",
onClick: e => this.copyPacketToClipboard(e, packet)
},
"packet"
)
),
...(showPacket
? Object.keys(packet).map(k =>
dom.div(
{ className: "packet-rep" },
`${k}: `,
Rep({ object: packet[k], noGrip: true, mode: MODE.LONG })
)
)
: [])
);
}
render() {
const { expression } = this.props;
const { input, packet } = expression;
return dom.div(
{ className: "rep-row" },
dom.div({ className: "rep-input" }, input),
dom.div(
{ className: "reps" },
this.renderRepInAllModes({
object: packet.exception || packet.result
})
),
this.renderPacket(expression)
);
}
}
module.exports = Result;