static-cms/src/index.js

72 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-02-25 00:45:56 -08:00
import React from 'react';
import { render } from 'react-dom';
2016-09-15 18:53:24 +02:00
import { AppContainer } from 'react-hot-loader';
2016-02-25 00:45:56 -08:00
import 'file?name=index.html!../example/index.html';
2016-09-15 18:53:24 +02:00
import 'react-toolbox/lib/commons.scss';
2016-10-06 16:11:11 +02:00
import Root from './root';
import registry from './lib/registry';
2016-07-08 07:12:52 -03:00
import './index.css';
2016-02-25 00:45:56 -08:00
2016-10-06 16:11:11 +02:00
if (process.env.NODE_ENV !== 'production') {
require('./utils.css'); // eslint-disable-line
}
2017-04-15 01:35:08 +01:00
// Log the version number
console.log(`Netlify CMS version ${NETLIFY_CMS_VERSION}`);
2016-09-13 17:08:26 +02:00
// Create mount element dynamically
2016-02-25 00:45:56 -08:00
const el = document.createElement('div');
2016-07-05 15:48:18 -03:00
el.id = 'root';
2016-02-25 00:45:56 -08:00
document.body.appendChild(el);
render((
2016-09-13 17:08:26 +02:00
<AppContainer>
<Root />
</AppContainer>
2016-02-25 00:45:56 -08:00
), el);
if (process.env.NODE_ENV !== 'production' && module.hot) {
2016-09-13 17:08:26 +02:00
module.hot.accept('./root', () => {
const NextRoot = require('./root').default; // eslint-disable-line
2016-09-13 17:08:26 +02:00
render((
<AppContainer>
<NextRoot />
</AppContainer>
), el);
});
}
const buildtInPlugins = [{
label: 'Image',
id: 'image',
fromBlock: match => match && {
image: match[2],
alt: match[1],
},
toBlock: data => `![${ data.alt }](${ data.image })`,
toPreview: data => <img src={data.image} alt={data.alt} />,
pattern: /^!\[([^\]]+)]\(([^)]+)\)$/,
fields: [{
label: 'Image',
name: 'image',
widget: 'image',
}, {
label: 'Alt Text',
name: 'alt',
}],
}];
buildtInPlugins.forEach(plugin => registry.registerEditorComponent(plugin));
const CMS = {};
for (const method in registry) { // eslint-disable-line
CMS[method] = registry[method];
}
if (typeof window !== 'undefined') {
window.CMS = CMS;
window.createClass = window.createClass || React.createClass;
window.h = window.h || React.createElement;
}
export default CMS;