forked from dabbott/javascript-playgrounds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.js
53 lines (43 loc) · 1.19 KB
/
player.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import Sandbox from './components/player/Sandbox'
import { getHashString } from './utils/HashString'
import { prefix, prefixAndApply } from './utils/PrefixInlineStyles'
import { appendCSS } from './utils/Styles'
import VendorComponents from './components/player/VendorComponents'
const style = prefix({
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
overflow: 'hidden',
flex: '1 1 auto',
})
const {
id = '0',
assetRoot = '',
vendorComponents = '[]',
styleSheet = 'reset',
css = '',
} = getHashString()
if (styleSheet === 'reset') {
require('./styles/reset.css')
}
require('./styles/player.css')
if (css) {
appendCSS(css)
}
const root = (
<div style={style}>
<Sandbox
id={id}
assetRoot={assetRoot}
/>
</div>
)
const mount = document.getElementById('react-root')
// Set mount node to flex in a vendor-prefixed way
prefixAndApply({ display: 'flex' }, mount)
// if we have vendor components, we need to pre-load those
// otherwise, we can just render normally
const components = JSON.parse(vendorComponents)
VendorComponents.load(components, () => ReactDOM.render(root, mount))