mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-25 11:15:34 +00:00
925311bc77
Differential Revision: https://phabricator.services.mozilla.com/D42300 --HG-- extra : moz-landing-system : lando
150 lines
3.8 KiB
JavaScript
150 lines
3.8 KiB
JavaScript
/* 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/. */
|
|
|
|
/* global DomProvider */
|
|
|
|
"use strict";
|
|
|
|
// React & Redux
|
|
const {
|
|
Component,
|
|
createFactory,
|
|
} = require("devtools/client/shared/vendor/react");
|
|
const PropTypes = require("devtools/client/shared/vendor/react-prop-types");
|
|
|
|
const { connect } = require("devtools/client/shared/vendor/react-redux");
|
|
|
|
const TreeView = createFactory(
|
|
require("devtools/client/shared/components/tree/TreeView")
|
|
);
|
|
// Reps
|
|
const { REPS, MODE } = require("devtools/client/shared/components/reps/reps");
|
|
const { Rep } = REPS;
|
|
|
|
const Grip = REPS.Grip;
|
|
// DOM Panel
|
|
const { GripProvider } = require("../grip-provider");
|
|
|
|
const { DomDecorator } = require("../dom-decorator");
|
|
|
|
/**
|
|
* Renders DOM panel tree.
|
|
*/
|
|
class DomTree extends Component {
|
|
static get propTypes() {
|
|
return {
|
|
dispatch: PropTypes.func.isRequired,
|
|
filter: PropTypes.string,
|
|
grips: PropTypes.object,
|
|
object: PropTypes.any,
|
|
openLink: PropTypes.func,
|
|
};
|
|
}
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
this.onFilter = this.onFilter.bind(this);
|
|
}
|
|
|
|
/**
|
|
* Filter DOM properties. Return true if the object
|
|
* should be visible in the tree.
|
|
*/
|
|
onFilter(object) {
|
|
if (!this.props.filter) {
|
|
return true;
|
|
}
|
|
|
|
return object.name && object.name.indexOf(this.props.filter) > -1;
|
|
}
|
|
|
|
/**
|
|
* Render DOM panel content
|
|
*/
|
|
render() {
|
|
const { dispatch, grips, object, openLink } = this.props;
|
|
|
|
const columns = [
|
|
{
|
|
id: "value",
|
|
},
|
|
];
|
|
|
|
let onDOMNodeMouseOver;
|
|
let onDOMNodeMouseOut;
|
|
let onInspectIconClick;
|
|
const toolbox = DomProvider.getToolbox();
|
|
if (toolbox) {
|
|
onDOMNodeMouseOver = async (grip, options = {}) => {
|
|
await toolbox.initInspector();
|
|
if (!toolbox.highlighter) {
|
|
return null;
|
|
}
|
|
const nodeFront = await toolbox.walker.gripToNodeFront(grip);
|
|
return toolbox.highlighter.highlight(nodeFront, options);
|
|
};
|
|
onDOMNodeMouseOut = (forceHide = false) => {
|
|
return toolbox.highlighter
|
|
? toolbox.highlighter.unhighlight(forceHide)
|
|
: null;
|
|
};
|
|
onInspectIconClick = async grip => {
|
|
await toolbox.initInspector();
|
|
const onSelectInspector = toolbox.selectTool(
|
|
"inspector",
|
|
"inspect_dom"
|
|
);
|
|
const onGripNodeToFront = toolbox.walker.gripToNodeFront(grip);
|
|
const [front, inspector] = await Promise.all([
|
|
onGripNodeToFront,
|
|
onSelectInspector,
|
|
]);
|
|
|
|
const onInspectorUpdated = inspector.once("inspector-updated");
|
|
const onNodeFrontSet = toolbox.selection.setNodeFront(front, {
|
|
reason: "console",
|
|
});
|
|
|
|
return Promise.all([onNodeFrontSet, onInspectorUpdated]);
|
|
};
|
|
}
|
|
|
|
// This is the integration point with Reps. The DomTree is using
|
|
// Reps to render all values. The code also specifies default rep
|
|
// used for data types that don't have its own specific template.
|
|
const renderValue = props => {
|
|
return Rep(
|
|
Object.assign({}, props, {
|
|
onDOMNodeMouseOver,
|
|
onDOMNodeMouseOut,
|
|
onInspectIconClick,
|
|
defaultRep: Grip,
|
|
cropLimit: 50,
|
|
})
|
|
);
|
|
};
|
|
|
|
return TreeView({
|
|
columns,
|
|
decorator: new DomDecorator(),
|
|
mode: MODE.SHORT,
|
|
object,
|
|
onFilter: this.onFilter,
|
|
openLink,
|
|
provider: new GripProvider(grips, dispatch),
|
|
renderValue,
|
|
});
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = state => {
|
|
return {
|
|
grips: state.grips,
|
|
filter: state.filter,
|
|
};
|
|
};
|
|
|
|
// Exports from this module
|
|
module.exports = connect(mapStateToProps)(DomTree);
|