44
55// @flow
66import React , { Component } from "react" ;
7+ import ReactDOM from "react-dom" ;
78import classnames from "classnames" ;
89
910import CloseButton from "../shared/Button/Close" ;
1011
12+ import { createEditor } from "../../utils/breakpoint" ;
1113import { features } from "../../utils/prefs" ;
14+
1215import type { LocalBreakpoint } from "./Breakpoints" ;
16+ import type SourceEditor from "../../utils/editor/source-editor" ;
1317
1418type Props = {
1519 breakpoint : LocalBreakpoint ,
@@ -30,6 +34,54 @@ function getBreakpointLocation(source, line, column) {
3034}
3135
3236class BreakpointItem extends Component < Props > {
37+ editor : SourceEditor ;
38+
39+ componentDidMount ( ) {
40+ this . setupEditor ( ) ;
41+ }
42+ componentDidUpdate ( ) {
43+ this . setupEditor ( ) ;
44+ }
45+
46+ componentWillUnmount ( ) {
47+ if ( this . editor ) {
48+ this . editor . destroy ( ) ;
49+ }
50+ }
51+
52+ shouldComponentUpdate ( nextProps : Props ) {
53+ const prevBreakpoint = this . props . breakpoint ;
54+ const nextBreakpoint = nextProps . breakpoint ;
55+
56+ return (
57+ ! prevBreakpoint ||
58+ ( prevBreakpoint . text != nextBreakpoint . text ||
59+ prevBreakpoint . disabled != nextBreakpoint . disabled ||
60+ prevBreakpoint . condition != nextBreakpoint . condition ||
61+ prevBreakpoint . hidden != nextBreakpoint . hidden ||
62+ prevBreakpoint . isCurrentlyPaused != nextBreakpoint . isCurrentlyPaused )
63+ ) ;
64+ }
65+
66+ setupEditor ( ) {
67+ const { breakpoint } = this . props ;
68+ this . editor = createEditor ( breakpoint . text ) ;
69+
70+ // disables the default search shortcuts
71+ // $FlowIgnore
72+ this . editor . _initShortcuts = ( ) => { } ;
73+
74+ const node = ReactDOM . findDOMNode ( this ) ;
75+ if ( node instanceof HTMLElement ) {
76+ const mountNode = node . querySelector ( ".breakpoint-label" ) ;
77+ if ( node instanceof HTMLElement ) {
78+ // $FlowIgnore
79+ mountNode . innerHTML = "" ;
80+ this . editor . appendToLocalElement ( mountNode ) ;
81+ }
82+ }
83+ }
84+
3385 render ( ) {
3486 const {
3587 breakpoint,
0 commit comments