chore: refine named exports (#2249)

This commit is contained in:
Tony Alves 2019-03-27 13:47:28 -07:00 committed by Shawn Erquhart
parent 4db497b496
commit b4041d3971
26 changed files with 185 additions and 179 deletions

View File

@ -1,55 +1,8 @@
import bootstrap from './bootstrap'; import bootstrap from './bootstrap';
import { import Registry from 'Lib/registry';
registerPreviewStyle,
getPreviewStyles,
registerPreviewTemplate,
getPreviewTemplate,
registerWidget,
getWidget,
resolveWidget,
registerEditorComponent,
getEditorComponents,
registerWidgetValueSerializer,
getWidgetValueSerializer,
registerBackend,
getBackend,
registerMediaLibrary,
getMediaLibrary,
} from 'Lib/registry';
export const NetlifyCmsCore = { export const NetlifyCmsCore = {
registerPreviewStyle, ...Registry,
getPreviewStyles,
registerPreviewTemplate,
getPreviewTemplate,
registerWidget,
getWidget,
resolveWidget,
registerEditorComponent,
getEditorComponents,
registerWidgetValueSerializer,
getWidgetValueSerializer,
registerBackend,
getBackend,
registerMediaLibrary,
getMediaLibrary,
init: bootstrap, init: bootstrap,
}; };
export { export default NetlifyCmsCore;
registerPreviewStyle,
getPreviewStyles,
registerPreviewTemplate,
getPreviewTemplate,
registerWidget,
getWidget,
resolveWidget,
registerEditorComponent,
getEditorComponents,
registerWidgetValueSerializer,
getWidgetValueSerializer,
registerBackend,
getBackend,
registerMediaLibrary,
getMediaLibrary,
bootstrap as init,
};

View File

@ -40,15 +40,3 @@ export const NetlifyCmsDefaultExports = {
ReactDOM, ReactDOM,
UUId, UUId,
}; };
export {
EmotionCore,
EmotionStyled,
Immutable,
ImmutablePropTypes,
Lodash,
Moment,
PropTypes,
React,
ReactDOM,
UUId,
};

View File

@ -1,3 +1,10 @@
import controlComponent from './BooleanControl'; import controlComponent from './BooleanControl';
export const NetlifyCmsWidgetBoolean = { controlComponent };
export { controlComponent }; const Widget = (opts = {}) => ({
name: 'boolean',
controlComponent,
...opts,
});
export const NetlifyCmsWidgetBoolean = { Widget, controlComponent };
export default NetlifyCmsWidgetBoolean;

View File

@ -9,4 +9,4 @@ const Widget = (opts = {}) => ({
}); });
export const NetlifyCmsWidgetDate = { Widget, controlComponent, previewComponent }; export const NetlifyCmsWidgetDate = { Widget, controlComponent, previewComponent };
export { Widget as default, controlComponent, previewComponent }; export default NetlifyCmsWidgetDate;

View File

@ -1,5 +1,7 @@
import React from 'react'; import React from 'react';
import { controlComponent as DateControl } from 'netlify-cms-widget-date'; import NetlifyCmsWidgetDate from 'netlify-cms-widget-date';
const DateControl = NetlifyCmsWidgetDate.controlComponent;
export default class DateTimeControl extends React.Component { export default class DateTimeControl extends React.Component {
render() { render() {

View File

@ -1,6 +1,7 @@
import controlComponent from './DateTimeControl'; import controlComponent from './DateTimeControl';
import { previewComponent } from 'netlify-cms-widget-date'; import NetlifyCmsWidgetDate from 'netlify-cms-widget-date';
const previewComponent = NetlifyCmsWidgetDate.previewComponent;
const Widget = (opts = {}) => ({ const Widget = (opts = {}) => ({
name: 'datetime', name: 'datetime',
controlComponent, controlComponent,
@ -9,4 +10,4 @@ const Widget = (opts = {}) => ({
}); });
export const NetlifyCmsWidgetDatetime = { Widget, controlComponent, previewComponent }; export const NetlifyCmsWidgetDatetime = { Widget, controlComponent, previewComponent };
export { Widget as default, controlComponent, previewComponent }; export default NetlifyCmsWidgetDatetime;

View File

@ -2,5 +2,12 @@ import withFileControl from './withFileControl';
import previewComponent from './FilePreview'; import previewComponent from './FilePreview';
const controlComponent = withFileControl(); const controlComponent = withFileControl();
export const NetlifyCmsWidgetFile = { controlComponent, previewComponent, withFileControl }; const Widget = (opts = {}) => ({
export { controlComponent, previewComponent, withFileControl }; name: 'file',
controlComponent,
previewComponent,
...opts,
});
export const NetlifyCmsWidgetFile = { Widget, controlComponent, previewComponent, withFileControl };
export default NetlifyCmsWidgetFile;

View File

@ -1,6 +1,12 @@
import { withFileControl } from 'netlify-cms-widget-file'; import NetlifyCmsWidgetFile from 'netlify-cms-widget-file';
const controlComponent = withFileControl({ forImage: true });
import previewComponent from './ImagePreview'; import previewComponent from './ImagePreview';
export const NetlifyCmsWidgetImage = { controlComponent, previewComponent };
export { controlComponent, previewComponent }; const controlComponent = NetlifyCmsWidgetFile.withFileControl({ forImage: true });
const Widget = (opts = {}) => ({
name: 'image',
controlComponent,
...opts,
});
export const NetlifyCmsWidgetImage = { Widget, controlComponent, previewComponent };
export default NetlifyCmsWidgetImage;

View File

@ -7,7 +7,7 @@ import { jsx, css, ClassNames } from '@emotion/core';
import { List, Map } from 'immutable'; import { List, Map } from 'immutable';
import { partial } from 'lodash'; import { partial } from 'lodash';
import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc'; import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';
import { controlComponent as ObjectControl } from 'netlify-cms-widget-object'; import NetlifyCmsWidgetObject from 'netlify-cms-widget-object';
import { import {
TYPES_KEY, TYPES_KEY,
getTypedFieldForValue, getTypedFieldForValue,
@ -20,6 +20,8 @@ function valueToString(value) {
return value ? value.join(',').replace(/,([^\s]|$)/g, ', $1') : ''; return value ? value.join(',').replace(/,([^\s]|$)/g, ', $1') : '';
} }
const ObjectControl = NetlifyCmsWidgetObject.controlComponent;
const ListItem = styled.div(); const ListItem = styled.div();
const SortableListItem = SortableElement(ListItem); const SortableListItem = SortableElement(ListItem);

View File

@ -1,4 +1,13 @@
import controlComponent from './ListControl'; import controlComponent from './ListControl';
import { previewComponent } from 'netlify-cms-widget-object'; import NetlifyCmsWidgetObject from 'netlify-cms-widget-object';
export const NetlifyCmsWidgetList = { controlComponent, previewComponent };
export { controlComponent, previewComponent }; const previewComponent = NetlifyCmsWidgetObject.previewComponent;
const Widget = (opts = {}) => ({
name: 'list',
controlComponent,
previewComponent,
...opts,
});
export const NetlifyCmsWidgetList = { Widget, controlComponent, previewComponent };
export default NetlifyCmsWidgetList;

View File

@ -1,6 +1,13 @@
import withMapControl from './withMapControl'; import withMapControl from './withMapControl';
import previewComponent from './MapPreview'; import previewComponent from './MapPreview';
const controlComponent = withMapControl();
export const NetlifyCmsWidgetMap = { controlComponent, previewComponent }; const controlComponent = withMapControl();
export { controlComponent, previewComponent }; const Widget = (opts = {}) => ({
name: 'map',
controlComponent,
previewComponent,
...opts,
});
export const NetlifyCmsWidgetMap = { Widget, controlComponent, previewComponent };
export default NetlifyCmsWidgetMap;

View File

@ -1,4 +1,12 @@
import controlComponent from './MarkdownControl'; import controlComponent from './MarkdownControl';
import previewComponent from './MarkdownPreview'; import previewComponent from './MarkdownPreview';
export const NetlifyCmsWidgetMarkdown = { controlComponent, previewComponent };
export { controlComponent, previewComponent }; const Widget = (opts = {}) => ({
name: 'markdown',
controlComponent,
previewComponent,
...opts,
});
export const NetlifyCmsWidgetMarkdown = { Widget, controlComponent, previewComponent };
export default NetlifyCmsWidgetMarkdown;

View File

@ -3,7 +3,9 @@ import { fromJS } from 'immutable';
import { render, fireEvent } from 'react-testing-library'; import { render, fireEvent } from 'react-testing-library';
import 'react-testing-library/cleanup-after-each'; import 'react-testing-library/cleanup-after-each';
import 'jest-dom/extend-expect'; import 'jest-dom/extend-expect';
import { controlComponent as NumberControl } from '../'; import { NetlifyCmsWidgetNumber } from '../';
const NumberControl = NetlifyCmsWidgetNumber.controlComponent;
const fieldSettings = { const fieldSettings = {
min: -20, min: -20,

View File

@ -1,4 +1,12 @@
import controlComponent from './NumberControl'; import controlComponent from './NumberControl';
import previewComponent from './NumberPreview'; import previewComponent from './NumberPreview';
export const NetlifyCmsWidgetNumber = { controlComponent, previewComponent };
export { controlComponent, previewComponent }; const Widget = (opts = {}) => ({
name: 'number',
controlComponent,
previewComponent,
...opts,
});
export const NetlifyCmsWidgetNumber = { Widget, controlComponent, previewComponent };
export default NetlifyCmsWidgetNumber;

View File

@ -1,4 +1,12 @@
import controlComponent from './ObjectControl'; import controlComponent from './ObjectControl';
import previewComponent from './ObjectPreview'; import previewComponent from './ObjectPreview';
export const NetlifyCmsWidgetObject = { controlComponent, previewComponent };
export { controlComponent, previewComponent }; const Widget = (opts = {}) => ({
name: 'object',
controlComponent,
previewComponent,
...opts,
});
export const NetlifyCmsWidgetObject = { Widget, controlComponent, previewComponent };
export default NetlifyCmsWidgetObject;

View File

@ -4,7 +4,9 @@ import { last } from 'lodash';
import { render, fireEvent, wait } from 'react-testing-library'; import { render, fireEvent, wait } from 'react-testing-library';
import 'react-testing-library/cleanup-after-each'; import 'react-testing-library/cleanup-after-each';
import 'jest-dom/extend-expect'; import 'jest-dom/extend-expect';
import { controlComponent as RelationControl } from '../'; import { NetlifyCmsWidgetRelation } from '../';
const RelationControl = NetlifyCmsWidgetRelation.controlComponent;
const fieldConfig = { const fieldConfig = {
name: 'post', name: 'post',

View File

@ -1,4 +1,12 @@
import controlComponent from './RelationControl'; import controlComponent from './RelationControl';
import previewComponent from './RelationPreview'; import previewComponent from './RelationPreview';
export const NetlifyCmsWidgetRelation = { controlComponent, previewComponent };
export { controlComponent, previewComponent }; const Widget = (opts = {}) => ({
name: 'relation',
controlComponent,
previewComponent,
...opts,
});
export const NetlifyCmsWidgetRelation = { Widget, controlComponent, previewComponent };
export default NetlifyCmsWidgetRelation;

View File

@ -3,7 +3,9 @@ import { fromJS } from 'immutable';
import { render, fireEvent } from 'react-testing-library'; import { render, fireEvent } from 'react-testing-library';
import 'react-testing-library/cleanup-after-each'; import 'react-testing-library/cleanup-after-each';
import 'jest-dom/extend-expect'; import 'jest-dom/extend-expect';
import { controlComponent as SelectControl } from '../'; import { NetlifyCmsWidgetSelect } from '../';
const SelectControl = NetlifyCmsWidgetSelect.controlComponent;
const options = [ const options = [
{ value: 'foo', label: 'Foo' }, { value: 'foo', label: 'Foo' },

View File

@ -1,4 +1,12 @@
import controlComponent from './SelectControl'; import controlComponent from './SelectControl';
import previewComponent from './SelectPreview'; import previewComponent from './SelectPreview';
export const NetlifyCmsWidgetSelect = { controlComponent, previewComponent };
export { controlComponent, previewComponent }; const Widget = (opts = {}) => ({
name: 'select',
controlComponent,
previewComponent,
...opts,
});
export const NetlifyCmsWidgetSelect = { Widget, controlComponent, previewComponent };
export default NetlifyCmsWidgetSelect;

View File

@ -1,4 +1,12 @@
import controlComponent from './StringControl'; import controlComponent from './StringControl';
import previewComponent from './StringPreview'; import previewComponent from './StringPreview';
export const NetlifyCmsWidgetString = { controlComponent, previewComponent };
export { controlComponent, previewComponent }; const Widget = (opts = {}) => ({
name: 'string',
controlComponent,
previewComponent,
...opts,
});
export const NetlifyCmsWidgetString = { Widget, controlComponent, previewComponent };
export default NetlifyCmsWidgetString;

View File

@ -1,5 +1,12 @@
import controlComponent from './TextControl'; import controlComponent from './TextControl';
import previewComponent from './TextPreview'; import previewComponent from './TextPreview';
export const NetlifyCmsWidgetText = { controlComponent, previewComponent }; const Widget = (opts = {}) => ({
export { controlComponent, previewComponent }; name: 'text',
controlComponent,
previewComponent,
...opts,
});
export const NetlifyCmsWidgetText = { Widget, controlComponent, previewComponent };
export default NetlifyCmsWidgetText;

View File

@ -1,12 +1,12 @@
import { registerBackend } from 'netlify-cms-core'; import { NetlifyCmsCore as CMS } from 'netlify-cms-core';
import { GitHubBackend } from 'netlify-cms-backend-github'; import { GitHubBackend } from 'netlify-cms-backend-github';
import { GitLabBackend } from 'netlify-cms-backend-gitlab'; import { GitLabBackend } from 'netlify-cms-backend-gitlab';
import { GitGatewayBackend } from 'netlify-cms-backend-git-gateway'; import { GitGatewayBackend } from 'netlify-cms-backend-git-gateway';
import { BitbucketBackend } from 'netlify-cms-backend-bitbucket'; import { BitbucketBackend } from 'netlify-cms-backend-bitbucket';
import { TestBackend } from 'netlify-cms-backend-test'; import { TestBackend } from 'netlify-cms-backend-test';
registerBackend('git-gateway', GitGatewayBackend); CMS.registerBackend('git-gateway', GitGatewayBackend);
registerBackend('github', GitHubBackend); CMS.registerBackend('github', GitHubBackend);
registerBackend('gitlab', GitLabBackend); CMS.registerBackend('gitlab', GitLabBackend);
registerBackend('bitbucket', BitbucketBackend); CMS.registerBackend('bitbucket', BitbucketBackend);
registerBackend('test-repo', TestBackend); CMS.registerBackend('test-repo', TestBackend);

View File

@ -1,4 +1,4 @@
import { registerEditorComponent } from 'netlify-cms-core'; import { NetlifyCmsCore as CMS } from 'netlify-cms-core';
import image from 'netlify-cms-editor-component-image'; import image from 'netlify-cms-editor-component-image';
registerEditorComponent(image); CMS.registerEditorComponent(image);

View File

@ -1,6 +1,6 @@
import createReactClass from 'create-react-class'; import createReactClass from 'create-react-class';
import React from 'react'; import React from 'react';
import * as CMS from 'netlify-cms-core'; import { NetlifyCmsCore as CMS } from 'netlify-cms-core';
import './backends'; import './backends';
import './widgets'; import './widgets';
import './editor-components'; import './editor-components';

View File

@ -1,6 +1,6 @@
import { registerMediaLibrary } from 'netlify-cms-core'; import { NetlifyCmsCore as CMS } from 'netlify-cms-core';
import uploadcare from 'netlify-cms-media-library-uploadcare'; import uploadcare from 'netlify-cms-media-library-uploadcare';
import cloudinary from 'netlify-cms-media-library-cloudinary'; import cloudinary from 'netlify-cms-media-library-cloudinary';
registerMediaLibrary(uploadcare); CMS.registerMediaLibrary(uploadcare);
registerMediaLibrary(cloudinary); CMS.registerMediaLibrary(cloudinary);

View File

@ -1,69 +1,32 @@
import { registerWidget } from 'netlify-cms-core'; import { NetlifyCmsCore as CMS } from 'netlify-cms-core';
import * as NetlifyCmsWidgetString from 'netlify-cms-widget-string'; import NetlifyCmsWidgetString from 'netlify-cms-widget-string';
import * as NetlifyCmsWidgetNumber from 'netlify-cms-widget-number'; import NetlifyCmsWidgetNumber from 'netlify-cms-widget-number';
import * as NetlifyCmsWidgetText from 'netlify-cms-widget-text'; import NetlifyCmsWidgetText from 'netlify-cms-widget-text';
import * as NetlifyCmsWidgetImage from 'netlify-cms-widget-image'; import NetlifyCmsWidgetImage from 'netlify-cms-widget-image';
import * as NetlifyCmsWidgetFile from 'netlify-cms-widget-file'; import NetlifyCmsWidgetFile from 'netlify-cms-widget-file';
import * as NetlifyCmsWidgetSelect from 'netlify-cms-widget-select'; import NetlifyCmsWidgetSelect from 'netlify-cms-widget-select';
import * as NetlifyCmsWidgetMarkdown from 'netlify-cms-widget-markdown'; import NetlifyCmsWidgetMarkdown from 'netlify-cms-widget-markdown';
import * as NetlifyCmsWidgetList from 'netlify-cms-widget-list'; import NetlifyCmsWidgetList from 'netlify-cms-widget-list';
import * as NetlifyCmsWidgetObject from 'netlify-cms-widget-object'; import NetlifyCmsWidgetObject from 'netlify-cms-widget-object';
import * as NetlifyCmsWidgetRelation from 'netlify-cms-widget-relation'; import NetlifyCmsWidgetRelation from 'netlify-cms-widget-relation';
import * as NetlifyCmsWidgetBoolean from 'netlify-cms-widget-boolean'; import NetlifyCmsWidgetBoolean from 'netlify-cms-widget-boolean';
import * as NetlifyCmsWidgetMap from 'netlify-cms-widget-map'; import NetlifyCmsWidgetMap from 'netlify-cms-widget-map';
import { NetlifyCmsWidgetDate } from 'netlify-cms-widget-date'; import NetlifyCmsWidgetDate from 'netlify-cms-widget-date';
import { NetlifyCmsWidgetDatetime } from 'netlify-cms-widget-datetime'; import NetlifyCmsWidgetDatetime from 'netlify-cms-widget-datetime';
registerWidget( CMS.registerWidget([
'string', NetlifyCmsWidgetString.Widget(),
NetlifyCmsWidgetString.controlComponent, NetlifyCmsWidgetNumber.Widget(),
NetlifyCmsWidgetString.previewComponent, NetlifyCmsWidgetText.Widget(),
); NetlifyCmsWidgetImage.Widget(),
registerWidget( NetlifyCmsWidgetFile.Widget(),
'number', NetlifyCmsWidgetSelect.Widget(),
NetlifyCmsWidgetNumber.controlComponent, NetlifyCmsWidgetMarkdown.Widget(),
NetlifyCmsWidgetNumber.previewComponent, NetlifyCmsWidgetList.Widget(),
); NetlifyCmsWidgetObject.Widget(),
registerWidget( NetlifyCmsWidgetRelation.Widget(),
'text', NetlifyCmsWidgetBoolean.Widget(),
NetlifyCmsWidgetText.controlComponent, NetlifyCmsWidgetMap.Widget(),
NetlifyCmsWidgetText.previewComponent, NetlifyCmsWidgetDate.Widget(),
); NetlifyCmsWidgetDatetime.Widget(),
registerWidget( ]);
'list',
NetlifyCmsWidgetList.controlComponent,
NetlifyCmsWidgetList.previewComponent,
);
registerWidget(
'markdown',
NetlifyCmsWidgetMarkdown.controlComponent,
NetlifyCmsWidgetMarkdown.previewComponent,
);
registerWidget(
'image',
NetlifyCmsWidgetImage.controlComponent,
NetlifyCmsWidgetImage.previewComponent,
);
registerWidget(
'file',
NetlifyCmsWidgetFile.controlComponent,
NetlifyCmsWidgetFile.previewComponent,
);
registerWidget(
'select',
NetlifyCmsWidgetSelect.controlComponent,
NetlifyCmsWidgetSelect.previewComponent,
);
registerWidget(
'object',
NetlifyCmsWidgetObject.controlComponent,
NetlifyCmsWidgetObject.previewComponent,
);
registerWidget(
'relation',
NetlifyCmsWidgetRelation.controlComponent,
NetlifyCmsWidgetRelation.previewComponent,
);
registerWidget('boolean', NetlifyCmsWidgetBoolean.controlComponent);
registerWidget('map', NetlifyCmsWidgetMap.controlComponent, NetlifyCmsWidgetMap.previewComponent);
registerWidget([NetlifyCmsWidgetDate.Widget(), NetlifyCmsWidgetDatetime.Widget()]);