2015-06-03 20:55:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-06-03 20:55:52 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2015-06-03 20:55:52 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
|
2015-06-03 20:55:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-01-03 21:38:50 +00:00
|
|
|
const BoxInspector = require('BoxInspector');
|
2017-04-12 23:09:48 +00:00
|
|
|
const PropTypes = require('prop-types');
|
2017-05-30 16:55:20 +00:00
|
|
|
const React = require('React');
|
2017-01-03 21:38:50 +00:00
|
|
|
const StyleInspector = require('StyleInspector');
|
|
|
|
const StyleSheet = require('StyleSheet');
|
|
|
|
const Text = require('Text');
|
|
|
|
const TouchableHighlight = require('TouchableHighlight');
|
|
|
|
const TouchableWithoutFeedback = require('TouchableWithoutFeedback');
|
|
|
|
const View = require('View');
|
2015-06-03 20:55:52 +00:00
|
|
|
|
2017-01-03 21:38:50 +00:00
|
|
|
const flattenStyle = require('flattenStyle');
|
|
|
|
const mapWithSeparator = require('mapWithSeparator');
|
|
|
|
const openFileInEditor = require('openFileInEditor');
|
2015-06-03 20:55:52 +00:00
|
|
|
|
2018-03-07 21:12:51 +00:00
|
|
|
import type {DangerouslyImpreciseStyleProp} from 'StyleSheet';
|
2017-11-14 21:13:40 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class ElementProperties extends React.Component<{
|
|
|
|
hierarchy: Array<$FlowFixMe>,
|
2018-03-07 21:12:51 +00:00
|
|
|
style?: DangerouslyImpreciseStyleProp,
|
2017-08-18 01:36:54 +00:00
|
|
|
source?: {
|
|
|
|
fileName?: string,
|
|
|
|
lineNumber?: number,
|
|
|
|
},
|
|
|
|
}> {
|
2016-07-26 08:00:02 +00:00
|
|
|
static propTypes = {
|
2015-06-03 20:55:52 +00:00
|
|
|
hierarchy: PropTypes.array.isRequired,
|
2015-07-22 23:36:46 +00:00
|
|
|
style: PropTypes.oneOfType([
|
|
|
|
PropTypes.object,
|
|
|
|
PropTypes.array,
|
|
|
|
PropTypes.number,
|
|
|
|
]),
|
2016-05-18 03:55:28 +00:00
|
|
|
source: PropTypes.shape({
|
|
|
|
fileName: PropTypes.string,
|
|
|
|
lineNumber: PropTypes.number,
|
|
|
|
}),
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-06-04 17:27:51 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2017-01-03 21:38:50 +00:00
|
|
|
const style = flattenStyle(this.props.style);
|
2016-07-26 08:00:02 +00:00
|
|
|
// $FlowFixMe found when converting React.createClass to ES6
|
2017-01-03 21:38:50 +00:00
|
|
|
const selection = this.props.selection;
|
|
|
|
let openFileButton;
|
|
|
|
const source = this.props.source;
|
|
|
|
const {fileName, lineNumber} = source || {};
|
2016-05-18 03:55:28 +00:00
|
|
|
if (fileName && lineNumber) {
|
2017-01-03 21:38:50 +00:00
|
|
|
const parts = fileName.split('/');
|
|
|
|
const fileNameShort = parts[parts.length - 1];
|
2016-05-18 03:55:28 +00:00
|
|
|
openFileButton = (
|
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.openButton}
|
2016-07-13 11:34:52 +00:00
|
|
|
onPress={openFileInEditor.bind(null, fileName, lineNumber)}>
|
2016-05-18 03:55:28 +00:00
|
|
|
<Text style={styles.openButtonTitle} numberOfLines={1}>
|
|
|
|
{fileNameShort}:{lineNumber}
|
|
|
|
</Text>
|
|
|
|
</TouchableHighlight>
|
|
|
|
);
|
|
|
|
}
|
2015-06-04 17:27:51 +00:00
|
|
|
// Without the `TouchableWithoutFeedback`, taps on this inspector pane
|
|
|
|
// would change the inspected element to whatever is under the inspector
|
2015-06-03 20:55:52 +00:00
|
|
|
return (
|
2015-06-04 17:27:51 +00:00
|
|
|
<TouchableWithoutFeedback>
|
|
|
|
<View style={styles.info}>
|
|
|
|
<View style={styles.breadcrumb}>
|
|
|
|
{mapWithSeparator(
|
|
|
|
this.props.hierarchy,
|
2017-05-30 16:55:20 +00:00
|
|
|
(hierarchyItem, i) => (
|
2015-06-04 17:27:51 +00:00
|
|
|
<TouchableHighlight
|
2016-01-26 02:36:10 +00:00
|
|
|
key={'item-' + i}
|
2015-06-04 17:27:51 +00:00
|
|
|
style={[styles.breadItem, i === selection && styles.selected]}
|
2016-07-26 08:00:02 +00:00
|
|
|
// $FlowFixMe found when converting React.createClass to ES6
|
2015-06-04 17:27:51 +00:00
|
|
|
onPress={() => this.props.setSelection(i)}>
|
2018-05-11 02:06:46 +00:00
|
|
|
<Text style={styles.breadItemText}>{hierarchyItem.name}</Text>
|
2015-06-04 17:27:51 +00:00
|
|
|
</TouchableHighlight>
|
|
|
|
),
|
2018-05-11 02:06:46 +00:00
|
|
|
i => (
|
2016-01-26 02:36:10 +00:00
|
|
|
<Text key={'sep-' + i} style={styles.breadSep}>
|
|
|
|
▸
|
|
|
|
</Text>
|
2018-05-11 02:06:46 +00:00
|
|
|
),
|
2015-06-04 17:27:51 +00:00
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
<View style={styles.row}>
|
2016-05-18 03:55:28 +00:00
|
|
|
<View style={styles.col}>
|
|
|
|
<StyleInspector style={style} />
|
|
|
|
{openFileButton}
|
|
|
|
</View>
|
2016-07-26 08:00:02 +00:00
|
|
|
{
|
|
|
|
// $FlowFixMe found when converting React.createClass to ES6
|
2018-05-11 02:06:46 +00:00
|
|
|
<BoxInspector style={style} frame={this.props.frame} />
|
|
|
|
}
|
2015-06-04 17:27:51 +00:00
|
|
|
</View>
|
2015-06-03 20:55:52 +00:00
|
|
|
</View>
|
2015-06-04 17:27:51 +00:00
|
|
|
</TouchableWithoutFeedback>
|
2015-06-03 20:55:52 +00:00
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-03 20:55:52 +00:00
|
|
|
|
2017-01-03 21:38:50 +00:00
|
|
|
const styles = StyleSheet.create({
|
2015-06-04 17:27:51 +00:00
|
|
|
breadSep: {
|
|
|
|
fontSize: 8,
|
|
|
|
color: 'white',
|
|
|
|
},
|
|
|
|
breadcrumb: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
flexWrap: 'wrap',
|
2016-06-15 18:06:26 +00:00
|
|
|
alignItems: 'flex-start',
|
2015-06-04 17:27:51 +00:00
|
|
|
marginBottom: 5,
|
|
|
|
},
|
|
|
|
selected: {
|
|
|
|
borderColor: 'white',
|
|
|
|
borderRadius: 5,
|
|
|
|
},
|
|
|
|
breadItem: {
|
|
|
|
borderWidth: 1,
|
|
|
|
borderColor: 'transparent',
|
|
|
|
marginHorizontal: 2,
|
|
|
|
},
|
|
|
|
breadItemText: {
|
|
|
|
fontSize: 10,
|
|
|
|
color: 'white',
|
|
|
|
marginHorizontal: 5,
|
|
|
|
},
|
2015-06-03 20:55:52 +00:00
|
|
|
row: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
2015-06-04 17:27:51 +00:00
|
|
|
justifyContent: 'space-between',
|
2015-06-03 20:55:52 +00:00
|
|
|
},
|
2016-05-18 03:55:28 +00:00
|
|
|
col: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
2015-06-03 20:55:52 +00:00
|
|
|
info: {
|
|
|
|
padding: 10,
|
|
|
|
},
|
2016-05-18 03:55:28 +00:00
|
|
|
openButton: {
|
|
|
|
padding: 10,
|
|
|
|
backgroundColor: '#000',
|
|
|
|
marginVertical: 5,
|
|
|
|
marginRight: 5,
|
|
|
|
borderRadius: 2,
|
|
|
|
},
|
|
|
|
openButtonTitle: {
|
|
|
|
color: 'white',
|
|
|
|
fontSize: 8,
|
2018-05-11 02:06:46 +00:00
|
|
|
},
|
2015-06-03 20:55:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = ElementProperties;
|