-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathindex.js
64 lines (55 loc) · 1.54 KB
/
index.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
54
55
56
57
58
59
60
61
62
63
64
import React from 'react';
import createReactClass from 'create-react-class';
import { render } from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import 'normalize.css';
import Root from './root';
import registry from './lib/registry';
import './index.css';
if (process.env.NODE_ENV !== 'production') {
require('./utils.css'); // eslint-disable-line
}
// Log the version number
console.log(`Netlify CMS version ${NETLIFY_CMS_VERSION}`);
// Create mount element dynamically
const el = document.createElement('div');
el.id = 'root';
document.body.appendChild(el);
render((
<AppContainer>
<Root />
</AppContainer>
), el);
if (module.hot) {
module.hot.accept('./root', () => { render(Root); });
}
const builtInPlugins = [{
label: 'Image',
id: 'image',
fromBlock: match => match && {
image: match[2],
alt: match[1],
},
toBlock: data => ``,
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;