Fix empty image fields saving null or undefined.

This commit is contained in:
Caleb
2017-11-17 15:45:42 -07:00
committed by Shawn Erquhart
parent 0515a70c03
commit 5271e0f7e7

View File

@ -29,15 +29,15 @@ if (module.hot) {
module.hot.accept('./root', () => { render(Root); }); module.hot.accept('./root', () => { render(Root); });
} }
const buildtInPlugins = [{ const builtInPlugins = [{
label: 'Image', label: 'Image',
id: 'image', id: 'image',
fromBlock: match => match && { fromBlock: match => match && {
image: match[2], image: match[2],
alt: match[1], alt: match[1],
}, },
toBlock: data => `![${ data.alt }](${ data.image })`, toBlock: data => `![${ data.alt || "" }](${ data.image || "" })`,
toPreview: (data, getAsset) => <img src={getAsset(data.image)} alt={data.alt} />, toPreview: (data, getAsset) => <img src={getAsset(data.image) || ""} alt={data.alt || ""} />,
pattern: /^!\[([^\]]+)]\(([^)]+)\)$/, pattern: /^!\[([^\]]+)]\(([^)]+)\)$/,
fields: [{ fields: [{
label: 'Image', label: 'Image',
@ -48,7 +48,7 @@ const buildtInPlugins = [{
name: 'alt', name: 'alt',
}], }],
}]; }];
buildtInPlugins.forEach(plugin => registry.registerEditorComponent(plugin)); builtInPlugins.forEach(plugin => registry.registerEditorComponent(plugin));
const CMS = {}; const CMS = {};
for (const method in registry) { // eslint-disable-line for (const method in registry) { // eslint-disable-line