Skip to content

Commit 4737bf5

Browse files
committed
s/attribute/component/
1 parent 320a776 commit 4737bf5

File tree

11 files changed

+126
-115
lines changed

11 files changed

+126
-115
lines changed

‎src/components/Main.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ReactDOM from 'react-dom';
44

55
const Events = require('../lib/Events.js');
66
const Editor = require('../lib/editor');
7-
import AttributesSidebar from './attributes/AttributesSidebar';
7+
import ComponentsSidebar from './components/Sidebar';
88
import {MenuWidget} from './menu/Menu';
99
import ModalTextures from './modals/ModalTextures';
1010
import SceneGraph from './SceneGraph';
@@ -74,7 +74,7 @@ export default class Main extends React.Component {
7474
<div className='sidebar-title'>scenegraph</div>
7575
<SceneGraph scene={scene}/>
7676
</div>
77-
<AttributesSidebar/>
77+
<ComponentsSidebar/>
7878
</div>
7979
<a href='#' className='toggle-edit' onClick={this.toggleEditor}>
8080
{this.state.editorEnabled ? 'Exit' : 'Edit'}

‎src/components/attributes/AttributesPanel.js‎

Lines changed: 0 additions & 36 deletions
This file was deleted.

‎src/components/attributes/AttributesSidebar.js‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎src/components/attributes/Attributes.js‎ renamed to ‎src/components/components/AddComponent.js‎

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import React from 'react';
22
import Collapsible from '../Collapsible';
3-
import Component from './Component';
4-
import CommonComponents from './CommonComponents';
53

6-
const DEFAULT_COMPONENTS = ['visible', 'position', 'scale', 'rotation'];
7-
8-
class AddComponent extends React.Component {
4+
export default class AddComponent extends React.Component {
95
static propTypes = {
106
entity: React.PropTypes.object
117
};
@@ -59,7 +55,7 @@ class AddComponent extends React.Component {
5955
<select ref='select'>
6056
{this.renderComponentOptions()}
6157
</select>
62-
<a href='#' className='button fa fa-plus-circle' onClick={this.addComponent}></a>
58+
<a href='#' className='button fa fa-plus-circle' onClick={this.addComponent}/>
6359
</span>
6460
</div>
6561
</div>
@@ -68,28 +64,6 @@ class AddComponent extends React.Component {
6864
}
6965
}
7066

71-
const Attributes = props => {
72-
const entity = props.entity;
73-
const components = entity ? entity.components : {};
74-
const defaultComponents = Object.keys(components).filter(function (key) {
75-
return DEFAULT_COMPONENTS.indexOf(key) === -1;
76-
}).sort().map(function (key) {
77-
return <Component entity={entity} key={key} name={key} component={components[key]}/>;
78-
});
79-
80-
return (
81-
<div className='attributes'>
82-
<CommonComponents entity={entity}/>
83-
<AddComponent entity={entity}/>
84-
{defaultComponents}
85-
</div>
86-
);
87-
};
88-
Attributes.PropTypes = {
89-
entity: React.PropTypes.object.isRequired
90-
};
91-
export default Attributes;
92-
9367
/**
9468
* Check if component has multiplicity.
9569
*/

‎src/components/attributes/CommonComponents.js‎ renamed to ‎src/components/components/CommonComponents.js‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React from 'react';
2-
3-
const Events = require('../../lib/Events.js');
42
import {InputWidget} from '../widgets';
5-
import AttributeRow from './AttributeRow';
3+
import PropertyRow from './PropertyRow';
64
import Collapsible from '../Collapsible';
7-
import MixinsComponent from './MixinsComponent';
5+
import Mixins from './Mixins';
86
import {updateEntity} from '../../actions/entity';
7+
const Events = require('../../lib/Events.js');
98

109
// @todo Take this out and use updateEntity?
1110
function changeId (entity, componentName, propertyName, value) {
@@ -15,6 +14,9 @@ function changeId (entity, componentName, propertyName, value) {
1514
}
1615
}
1716

17+
/**
18+
* Core component properties such as id, position, rotation, scale.
19+
*/
1820
const CommonComponents = props => {
1921
const entity = props.entity;
2022
const components = entity ? props.entity.components : {};
@@ -39,13 +41,13 @@ const CommonComponents = props => {
3941
const componentData = components[key];
4042
const schema = AFRAME.components[key].schema;
4143
return (
42-
<AttributeRow onChange={updateEntity} key={key} name={key}
43-
schema={schema} data={componentData.data} componentname={key}
44-
entity={props.entity}/>
44+
<PropertyRow onChange={updateEntity} key={key} name={key}
45+
schema={schema} data={componentData.data} componentname={key}
46+
entity={props.entity}/>
4547
);
4648
})
4749
}
48-
<MixinsComponent entity={entity}/>
50+
<Mixins entity={entity}/>
4951
</div>
5052
</Collapsible>
5153
);

‎src/components/attributes/Component.js‎ renamed to ‎src/components/components/Component.js‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import AttributeRow from './AttributeRow';
3+
import PropertyRow from './PropertyRow';
44
import Collapsible from '../Collapsible';
55

66
function isSingleProperty (schema) {
@@ -10,6 +10,9 @@ function isSingleProperty (schema) {
1010
return 'default' in schema;
1111
}
1212

13+
/**
14+
* Single component.
15+
*/
1316
export default class Component extends React.Component {
1417
static propTypes = {
1518
component: React.PropTypes.any,
@@ -37,19 +40,19 @@ export default class Component extends React.Component {
3740
componentName = componentName.substr(0, componentName.indexOf('__'));
3841
}
3942

40-
let attributeRows;
43+
let propertyRows;
4144
if (isSingleProperty(componentData.schema)) {
4245
var key = componentName.toLowerCase();
4346
var schema = AFRAME.components[key.toLowerCase()].schema;
44-
attributeRows = (
45-
<AttributeRow key={key} name={key} schema={schema}
47+
propertyRows = (
48+
<PropertyRow key={key} name={key} schema={schema}
4649
data={componentData.data} componentname={key}
4750
entity={this.props.entity}/>
4851
);
4952
} else {
50-
attributeRows = Object.keys(componentData.schema).map(key => {
53+
propertyRows = Object.keys(componentData.schema).map(key => {
5154
return (
52-
<AttributeRow key={key} name={key} schema={componentData.schema[key]}
55+
<PropertyRow key={key} name={key} schema={componentData.schema[key]}
5356
data={componentData.data[key]} componentname={this.props.name}
5457
entity={this.props.entity}/>
5558
);
@@ -68,7 +71,7 @@ export default class Component extends React.Component {
6871
</div>
6972
</div>
7073
</div>
71-
<div className='collapsible-content'>{attributeRows}</div>
74+
<div className='collapsible-content'>{propertyRows}</div>
7275
</Collapsible>
7376
);
7477
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React from 'react';
2+
import AddComponent from './AddComponent';
3+
import Component from './Component';
4+
import CommonComponents from './CommonComponents';
5+
const Events = require('../../lib/Events');
6+
7+
const DEFAULT_COMPONENTS = ['visible', 'position', 'scale', 'rotation'];
8+
9+
export default class ComponentsContainer extends React.Component {
10+
static propTypes = {
11+
entity: React.PropTypes.object.isRequired
12+
};
13+
14+
constructor (props) {
15+
super(props);
16+
this.state = {
17+
entity: props.entity
18+
};
19+
}
20+
21+
componentDidMount () {
22+
this.refresh();
23+
Events.on('entitySelected', entity => {
24+
this.setState({entity: entity});
25+
if (entity !== null) {
26+
entity.addEventListener('componentchanged', this.refresh);
27+
}
28+
});
29+
document.addEventListener('componentremoved', event => {
30+
if (this.state.entity === event.detail.target) {
31+
this.refresh();
32+
}
33+
});
34+
}
35+
36+
refresh = () => {
37+
this.forceUpdate();
38+
}
39+
40+
render () {
41+
const entity = this.state.entity;
42+
const components = entity ? entity.components : {};
43+
const defaultComponents = Object.keys(components).filter(function (key) {
44+
return DEFAULT_COMPONENTS.indexOf(key) === -1;
45+
}).sort().map(function (key) {
46+
return <Component entity={entity} key={key} name={key} component={components[key]}/>;
47+
});
48+
49+
return (
50+
<div className='components'>
51+
<CommonComponents entity={entity}/>
52+
<AddComponent entity={entity}/>
53+
{defaultComponents}
54+
</div>
55+
);
56+
}
57+
}

‎src/components/attributes/MixinsComponent.js‎ renamed to ‎src/components/components/Mixins.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function trim (s) {
99
return s;
1010
}
1111

12-
export default class MixinsComponent extends React.Component {
12+
export default class Mixin extends React.Component {
1313
static propTypes = {
1414
entity: React.PropTypes.object.isRequired
1515
};
@@ -29,7 +29,9 @@ export default class MixinsComponent extends React.Component {
2929

3030
addMixin = () => {
3131
const entity = this.props.entity;
32-
entity.setAttribute('mixin', trim(entity.getAttribute('mixin') + ' ' + this.refs.select.value));
32+
entity.setAttribute(
33+
'mixin', trim(entity.getAttribute('mixin') + ' ' + this.refs.select.value));
34+
3335
// @todo Is there some aframe event that we could catch instead of explicitly emit the objectChanged event?
3436
Events.emit('objectChanged', entity);
3537
}

‎src/components/attributes/AttributeRow.js‎ renamed to ‎src/components/components/PropertyRow.js‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,33 @@ import TextureWidget from '../widgets/TextureWidget';
99
import Vec3Widget from '../widgets/Vec3Widget';
1010
import {updateEntity} from '../../actions/entity';
1111

12-
export default class AttributeRow extends React.Component {
12+
export default class PropertyRow extends React.Component {
1313
static propTypes = {
1414
componentname: React.PropTypes.string.isRequired,
15+
id: React.PropTypes.string,
1516
name: React.PropTypes.string.isRequired,
1617
schema: React.PropTypes.object.isRequired
1718
};
1819

20+
constructor (props) {
21+
super(props);
22+
this.id = props.componentname + ':' + props.id;
23+
}
24+
1925
getWidget () {
2026
const props = this.props;
2127
const isMap = props.componentname === 'material' && (props.name === 'envMap' ||
2228
props.name === 'src');
2329
const type = props.schema.type;
30+
2431
const widgetProps = {
2532
componentname: props.componentname,
2633
entity: props.entity,
2734
name: props.name,
28-
onChange: updateEntity,
35+
// Wrap updateEntity for tracking.
36+
onChange: function () {
37+
updateEntity.apply(this, arguments);
38+
},
2939
value: props.data
3040
};
3141
const numberWidgetProps = {
@@ -65,10 +75,9 @@ export default class AttributeRow extends React.Component {
6575
render () {
6676
const props = this.props;
6777
const title = 'type: ' + props.schema.type + ' value: ' + JSON.stringify(props.data);
68-
const id = props.componentname + '.' + props.name;
6978
return (
7079
<div className='row'>
71-
<label htmlFor={id} className='text' title={title}>{props.name}</label>
80+
<label htmlFor={this.id} className='text' title={title}>{props.name}</label>
7281
{this.getWidget(props.schema.type)}
7382
</div>
7483
);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var React = require('react');
2+
3+
import ComponentsContainer from './ComponentsContainer';
4+
5+
export default class Sidebar extends React.Component {
6+
constructor (props) {
7+
super(props);
8+
this.state = {open: false};
9+
}
10+
11+
handleToggle = () => {
12+
this.setState({open: !this.state.open});
13+
}
14+
15+
render () {
16+
return (
17+
<div id='sidebar'>
18+
<div className='sidebar-title'>components</div>
19+
<ComponentsContainer/>
20+
</div>
21+
);
22+
}
23+
}

0 commit comments

Comments
 (0)