|
1 | 1 | import React from 'react'; |
2 | | -import Clipboard from 'clipboard'; |
3 | | -import Events from '../../lib/Events.js'; |
4 | | -import {getSceneName, generateHtml} from '../../lib/exporter'; |
5 | | - |
6 | | -var primitivesDefinitions = { |
7 | | - 'Entity': {group: 'entities', element: 'a-entity', components: {}}, |
8 | | - |
9 | | - 'Box': {group: 'primitives', element: 'a-entity', components: {geometry: 'primitive:box', material: 'color:#f00'}}, |
10 | | - 'Sphere': {group: 'primitives', element: 'a-entity', components: {geometry: 'primitive:sphere', material: 'color:#ff0'}}, |
11 | | - 'Cylinder': {group: 'primitives', element: 'a-entity', components: {geometry: 'primitive:cylinder', material: 'color:#00f'}}, |
12 | | - 'Plane': {group: 'primitives', element: 'a-entity', components: {geometry: 'primitive:plane', material: 'color:#fff'}}, |
13 | | - 'Torus': {group: 'primitives', element: 'a-entity', components: {geometry: 'primitive:torus', material: 'color:#0f0'}}, |
14 | | - 'TorusKnot': {group: 'primitives', element: 'a-entity', components: {geometry: 'primitive:torusKnot', material: 'color:#f0f'}}, |
15 | | - 'Circle': {group: 'primitives', element: 'a-entity', components: {geometry: 'primitive:circle', material: 'color:#f0f'}}, |
16 | | - 'Ring': {group: 'primitives', element: 'a-entity', components: {geometry: 'primitive:ring', material: 'color:#0ff'}}, |
17 | | - |
18 | | - 'Ambient': {group: 'lights', element: 'a-entity', components: {light: 'type:ambient'}}, |
19 | | - 'Directional': {group: 'lights', element: 'a-entity', components: {light: 'type:directional'}}, |
20 | | - 'Hemisphere': {group: 'lights', element: 'a-entity', components: {light: 'type:hemisphere'}}, |
21 | | - 'Point': {group: 'lights', element: 'a-entity', components: {light: 'type:point'}}, |
22 | | - 'Spot': {group: 'lights', element: 'a-entity', components: {light: 'type:spot'}}, |
23 | | - |
24 | | - 'Camera': {group: 'cameras', element: 'a-entity', components: {camera: ''}} |
25 | | -}; |
26 | | - |
27 | | -function createEntity (definition) { |
28 | | - Events.emit('createNewEntity', primitivesDefinitions[definition]); |
29 | | -} |
30 | | - |
31 | | -export const CreateMenu = props => { |
32 | | - var prevGroup = null; |
33 | | - var definitions = primitivesDefinitions; |
34 | | - return ( |
35 | | - <div className="menu"> |
36 | | - <div className="title">Create</div> |
37 | | - <div className="options"> |
38 | | - { |
39 | | - Object.keys(definitions).map(function(definition) { |
40 | | - var output = []; |
41 | | - if (prevGroup === null) { |
42 | | - prevGroup = definitions[definition].group; |
43 | | - } else if (prevGroup !== definitions[definition].group) { |
44 | | - prevGroup = definitions[definition].group; |
45 | | - output.push(<hr/>); |
46 | | - } |
47 | | - output.push(<div className="option" key={definition} value={definition} |
48 | | - onClick={() => createEntity(definition)}>{definition}</div>); |
49 | | - return output; |
50 | | - }.bind(this)) |
51 | | - } |
52 | | - </div> |
53 | | - </div> |
54 | | - ); |
55 | | -}; |
56 | | - |
57 | | -export const EditMenu = () => { |
58 | | - var prevGroup = null; |
59 | | - var definitions = primitivesDefinitions; |
60 | | - return ( |
61 | | - <div className="menu"> |
62 | | - <div className="title">Create</div> |
63 | | - <div className="options"> |
64 | | - { |
65 | | - Object.keys(definitions).map(function(definition) { |
66 | | - var output = []; |
67 | | - if (prevGroup === null) { |
68 | | - prevGroup = definitions[definition].group; |
69 | | - } else if (prevGroup !== definitions[definition].group) { |
70 | | - prevGroup = definitions[definition].group; |
71 | | - output.push(<hr/>); |
72 | | - } |
73 | | - output.push(<div className="option" key={definition} value={definition}>{definition}</div>); |
74 | | - return output; |
75 | | - }.bind(this)) |
76 | | - } |
77 | | - </div> |
78 | | - </div> |
79 | | - ); |
80 | | -}; |
| 2 | +import {CreateMenu} from './CreateMenu'; |
| 3 | +import {EditMenu} from './EditMenu'; |
| 4 | +import {ExportMenu} from './ExportMenu'; |
81 | 5 |
|
82 | 6 | export class MenuWidget extends React.Component { |
83 | | - componentDidMount() { |
84 | | - var clipboard = new Clipboard('[data-action="copy-to-clipboard"]', { |
85 | | - text: function (trigger) { |
86 | | - return generateHtml(); |
87 | | - } |
88 | | - }); |
89 | | - clipboard.on('error', function(e) { |
90 | | - console.error('Error while copying to clipboard:', e.action, e.trigger); |
91 | | - }); |
92 | | - } |
93 | | - |
94 | | - update = e => { |
95 | | - var value = e.target.value; |
96 | | - this.setState({value: value}); |
97 | | - if (this.props.onChange) |
98 | | - this.props.onChange(this.props.entity, this.props.componentname, this.props.name, value); |
99 | | - } |
100 | | - |
101 | | - saveToHTML() { |
102 | | - var link = document.createElement('a'); |
103 | | - link.style.display = 'none'; |
104 | | - link.setAttribute('data-aframe-editor', 'download'); |
105 | | - document.body.appendChild(link); |
106 | | - function save (blob, filename) { |
107 | | - link.href = URL.createObjectURL(blob); |
108 | | - link.download = filename || 'data.json'; |
109 | | - link.click(); |
110 | | - // URL.revokeObjectURL(url); breaks Firefox... |
111 | | - } |
112 | | - function saveString (text, filename) { |
113 | | - save(new Blob([ text ], { type: 'text/plain' }), filename); |
114 | | - } |
115 | | - |
116 | | - var sceneName = getSceneName(document.querySelector('a-scene')); |
117 | | - saveString(generateHtml(), sceneName); |
118 | | - } |
119 | | - |
120 | | - render() { |
| 7 | + render () { |
121 | 8 | return ( |
122 | | - <div className="Panel" id="menubar"> |
123 | | - <div className="menu aframe-logo"> |
124 | | - <div className="title"> |
| 9 | + <div className='panel' id='menubar'> |
| 10 | + <div className='menu aframe-logo'> |
| 11 | + <div className='title'> |
125 | 12 | <span style={{color: '#ed3160'}}>A-</span> |
126 | 13 | <span style={{color: '#fff'}}>Frame</span> |
127 | 14 | </div> |
128 | 15 | </div> |
129 | | - <div className="menu"> |
130 | | - <div className="title">Export</div> |
131 | | - <div className="options"> |
132 | | - <div className="option" onClick={this.saveToHTML}>Save HTML</div> |
133 | | - <div className="option" data-action="copy-to-clipboard">Copy to clipboard</div> |
134 | | - </div> |
135 | | - </div> |
136 | | - <div className="menu"> |
137 | | - <div className="title">Edit</div> |
138 | | - </div> |
| 16 | + <ExportMenu/> |
| 17 | + <EditMenu/> |
139 | 18 | <CreateMenu/> |
140 | 19 | </div> |
141 | 20 | ); |
|
0 commit comments