-
Notifications
You must be signed in to change notification settings - Fork 72
/
ColumnBreakpoint.js
128 lines (98 loc) · 3.95 KB
/
ColumnBreakpoint.js
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
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _react = require("devtools/client/shared/vendor/react");
var _classnames = require("devtools/client/debugger/dist/vendors").vendored["classnames"];
var _classnames2 = _interopRequireDefault(_classnames);
var _devtoolsContextmenu = require("devtools/client/debugger/dist/vendors").vendored["devtools-contextmenu"];
var _editor = require("../../utils/editor/index");
var _breakpoints = require("./menus/breakpoints");
var _selectedLocation = require("../../utils/selected-location");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// eslint-disable-next-line max-len
/* 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 breakpointButton = document.createElement("button");
breakpointButton.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 11 13" width="11" height="13"><path d="M5.07.5H1.5c-.54 0-1 .46-1 1v10c0 .54.46 1 1 1h3.57c.58 0 1.15-.26 1.53-.7l3.7-5.3-3.7-5.3C6.22.76 5.65.5 5.07.5z"/></svg>';
function makeBookmark({ breakpoint }, { onClick, onContextMenu }) {
const bp = breakpointButton.cloneNode(true);
const isActive = breakpoint && !breakpoint.disabled;
const isDisabled = breakpoint && breakpoint.disabled;
const condition = breakpoint && breakpoint.options.condition;
const logValue = breakpoint && breakpoint.options.logValue;
bp.className = (0, _classnames2.default)("column-breakpoint", {
"has-condition": condition,
"has-log": logValue,
active: isActive,
disabled: isDisabled
});
bp.setAttribute("title", logValue || condition || "");
bp.onclick = onClick;
// NOTE: flow does not know about oncontextmenu
bp.oncontextmenu = onContextMenu;
return bp;
}
class ColumnBreakpoint extends _react.PureComponent {
constructor(...args) {
var _temp;
return _temp = super(...args), this.addColumnBreakpoint = nextProps => {
const { columnBreakpoint, source } = nextProps || this.props;
const sourceId = source.id;
const doc = (0, _editor.getDocument)(sourceId);
if (!doc) {
return;
}
const { line, column } = columnBreakpoint.location;
const widget = makeBookmark(columnBreakpoint, {
onClick: this.onClick,
onContextMenu: this.onContextMenu
});
this.bookmark = doc.setBookmark({ line: line - 1, ch: column }, { widget });
}, this.clearColumnBreakpoint = () => {
if (this.bookmark) {
this.bookmark.clear();
this.bookmark = null;
}
}, this.onClick = event => {
event.stopPropagation();
event.preventDefault();
const { cx, columnBreakpoint, breakpointActions } = this.props;
if (columnBreakpoint.breakpoint) {
breakpointActions.removeBreakpoint(cx, columnBreakpoint.breakpoint);
} else {
breakpointActions.addBreakpoint(cx, columnBreakpoint.location);
}
}, this.onContextMenu = event => {
event.stopPropagation();
event.preventDefault();
const {
cx,
columnBreakpoint: { breakpoint, location },
source,
breakpointActions
} = this.props;
let items = (0, _breakpoints.createBreakpointItems)(cx, location, breakpointActions);
if (breakpoint) {
const selectedLocation = (0, _selectedLocation.getSelectedLocation)(breakpoint, source);
items = (0, _breakpoints.breakpointItems)(cx, breakpoint, selectedLocation, breakpointActions);
}
(0, _devtoolsContextmenu.showMenu)(event, items);
}, _temp;
}
componentDidMount() {
this.addColumnBreakpoint();
}
componentWillUnmount() {
this.clearColumnBreakpoint();
}
componentDidUpdate() {
this.clearColumnBreakpoint();
this.addColumnBreakpoint();
}
render() {
return null;
}
}
exports.default = ColumnBreakpoint;