static-cms/src/index.js

68 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-02-25 00:45:56 -08:00
import React from 'react';
import createReactClass from 'create-react-class';
2016-02-25 00:45:56 -08:00
import { render } from 'react-dom';
2016-09-15 18:53:24 +02:00
import { AppContainer } from 'react-hot-loader';
2017-08-23 14:06:34 -04:00
import 'normalize.css';
import ErrorBoundary from './components/UI/ErrorBoundary/ErrorBoundary';
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>
<ErrorBoundary>
<Root />
</ErrorBoundary>
2016-09-13 17:08:26 +02:00
</AppContainer>
2016-02-25 00:45:56 -08:00
), el);
2017-06-12 17:59:58 -07:00
if (module.hot) {
module.hot.accept('./root', () => { render(Root); });
2016-09-13 17:08:26 +02:00
}
const builtInPlugins = [{
label: 'Image',
id: 'image',
fromBlock: match => match && {
image: match[2],
alt: match[1],
},
toBlock: data => `![${ data.alt || "" }](${ data.image || "" })`,
toPreview: (data, getAsset) => <img src={getAsset(data.image) || ""} alt={data.alt || ""} />,
pattern: /^!\[([^\]]+)]\(([^)]+)\)$/,
fields: [{
label: 'Image',
name: 'image',
widget: 'image',
}, {
label: 'Alt Text',
name: 'alt',
}],
}];
builtInPlugins.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 || createReactClass;
window.h = window.h || React.createElement;
}
export default CMS;