Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(editor): Passes all codeMirror options to editor #662

Merged
merged 29 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
12d041c
feat(editor): Passes all codeMirror options to editot
SaraVieira Oct 31, 2017
6737194
rename to editorconfig
SaraVieira Nov 9, 2017
721d992
add deprecated prop
SaraVieira Nov 12, 2017
53af58c
removed added option in config
SaraVieira Nov 12, 2017
5ed3350
fix tests
SaraVieira Nov 12, 2017
d9de7d9
Revert "fix tests"
sapegin Nov 13, 2017
0eabb99
Fix: Revert deprecate option changes
sapegin Nov 13, 2017
707404f
Fix: Tweak text
sapegin Nov 13, 2017
b1436d8
Fix: Make all warnings yellow again
sapegin Nov 13, 2017
5ff5199
fix: remove duplicated
SaraVieira Dec 18, 2017
d812a14
fic: fix tests
SaraVieira Dec 18, 2017
cb0c2ed
fix: remove duplicated
SaraVieira Dec 18, 2017
478b151
fix: move to defaults
SaraVieira Dec 18, 2017
ee90b84
update tests
SaraVieira Dec 18, 2017
e1496dc
fix: move to defaults
SaraVieira Dec 18, 2017
fbd4f39
fix: add config tests
SaraVieira Dec 18, 2017
5600c74
fix duplocation
SaraVieira Dec 18, 2017
baa9d2e
move to consts
SaraVieira Dec 18, 2017
8f2640b
change tests
SaraVieira Dec 19, 2017
55e334b
remove jest-cli
SaraVieira Dec 19, 2017
4e78ba4
change tests name
SaraVieira Dec 19, 2017
364f267
revert package-lock
SaraVieira Dec 19, 2017
8c0d54c
update package-lock
SaraVieira Dec 19, 2017
ed20e8c
update lock
SaraVieira Dec 19, 2017
1b7677a
Update package-lock.json
SaraVieira Dec 19, 2017
b74188a
add docs
SaraVieira Dec 19, 2017
87efdde
Merge branch '648' of github.com:styleguidist/react-styleguidist into…
SaraVieira Dec 19, 2017
477ab67
update docs
SaraVieira Dec 19, 2017
1c158fc
change to master
SaraVieira Dec 19, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ By default, Styleguidist will look for `styleguide.config.js` file in your proje
* [`configureServer`](#configureserver)
* [`dangerouslyUpdateWebpackConfig`](#dangerouslyupdatewebpackconfig)
* [`defaultExample`](#defaultexample)
* [`editorConfig`](#editorConfig)
* [`getComponentPathLine`](#getcomponentpathline)
* [`getExampleFilename`](#getexamplefilename)
* [`handlers`](#handlers)
* [`highlightTheme`](#highlighttheme)
* [`ignore`](#ignore)
* [`logger`](#logger)
* [`previewDelay`](#previewdelay)
Expand Down Expand Up @@ -168,6 +168,12 @@ module.exports = {
}
```

#### `editorConfig`

Type: `Object`, default: [scripts/schemas/config.js](https://github.com/styleguidist/react-styleguidist/tree/master/scripts/schemas/config.js#L101)

Source code editor options, see [CodeMirror docs](https://codemirror.net/doc/manual.html#config) for all available options.

#### `getExampleFilename`

Type: `Function`, default: finds `Readme.md` or `ComponentName.md` in the component folder
Expand Down Expand Up @@ -227,12 +233,6 @@ module.exports = {
}
```

#### `highlightTheme`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc changes here :)


Type: `String`, default: `base16-light`

[CodeMirror theme](http://codemirror.net/demo/theme.html) name to use for syntax highlighting in the editor.

#### `ignore`

Type: `String[]`, default: `['**/__tests__/**', '**/*.test.js', '**/*.test.jsx', '**/*.spec.js', '**/*.spec.jsx']`
Expand Down
1 change: 1 addition & 0 deletions loaders/styleguide-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const CLIENT_CONFIG_OPTIONS = [
'theme',
'styles',
'compilerConfig',
'editorConfig',
];

module.exports = function() {};
Expand Down
17 changes: 17 additions & 0 deletions scripts/__tests__/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,20 @@ it('should allow no webpack config', () => {
const fn = () => getConfig();
expect(fn).not.toThrow();
});

it('editorConfig option should have default values', () => {
const result = getConfig();
expect(result.editorConfig).toHaveProperty('mode', 'jsx');
expect(result.editorConfig).toHaveProperty('theme', 'base16-light');
});

it('should merge default editorConfig with options provided by the user', () => {
const result = getConfig({
editorConfig: {
mode: 'js',
},
});

expect(result.editorConfig).toHaveProperty('mode', 'js');
expect(result.editorConfig).toHaveProperty('theme', 'base16-light');
});
3 changes: 2 additions & 1 deletion scripts/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
/* eslint-disable no-console */

const _ = require('lodash/fp');
const chalk = require('chalk');
const logger = require('glogg')('rsg');

const format = message => message.trim() + '\n';

const printers = {
info: message => console.log(format(message)),
warn: message => console.warn(`Warning: ${format(message)}`),
warn: message => console.warn(chalk.yellow(`Warning: ${format(message)}`)),
debug: message => console.log(format(message)),
};

Expand Down
21 changes: 21 additions & 0 deletions scripts/schemas/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ module.exports = {
highlightTheme: {
type: 'string',
default: 'base16-light',
deprecated: 'Use the theme property in the editorConfig option instead',
},
editorConfig: {
type: 'object',
process: (value, config) => {
const defaults = {
theme: 'base16-light',
mode: 'jsx',
lineWrapping: true,
smartIndent: false,
matchBrackets: true,
viewportMargin: Infinity,
lineNumbers: false,
};
return Object.assign(
{},
defaults,
config.highlightTheme && { theme: config.highlightTheme },
value
);
},
},
logger: {
type: 'object',
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils/sanitizeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = function sanitizeConfig(config, schema, rootDir) {
throw new StyleguidistError(message);
}
} else if (props.deprecated) {
logger.warn(`${chalk.bold(key)} config option is deprecated. ${props.deprecated}`);
logger.warn(`${key} config option is deprecated. ${props.deprecated}`);
} else if (props.removed) {
throw new StyleguidistError(`${chalk.bold(key)} config option was removed. ${props.removed}`);
}
Expand Down
17 changes: 2 additions & 15 deletions src/rsg-components/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ require('!!../../../loaders/style-loader!../../../loaders/css-loader!codemirror/
// eslint-disable-next-line import/no-unresolved
require('!!../../../loaders/style-loader!../../../loaders/css-loader!rsg-codemirror-theme.css');

const codemirrorOptions = {
mode: 'jsx',
lineNumbers: false,
lineWrapping: true,
smartIndent: false,
matchBrackets: true,
viewportMargin: Infinity,
};

const UPDATE_DELAY = 10;

export default class Editor extends Component {
Expand All @@ -46,11 +37,7 @@ export default class Editor extends Component {

render() {
const { code } = this.props;
const { highlightTheme } = this.context.config;
const options = {
...codemirrorOptions,
theme: highlightTheme,
};
return <CodeMirror value={code} onChange={this.handleChange} options={options} />;
const { editorConfig } = this.context.config;
return <CodeMirror value={code} onChange={this.handleChange} options={editorConfig} />;
}
}
3 changes: 3 additions & 0 deletions src/rsg-components/Editor/Editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const options = {
config: {
showCode: false,
highlightTheme: 'base16-light',
editorConfig: {
mode: 'js',
},
},
},
childContextTypes: {
Expand Down
8 changes: 1 addition & 7 deletions src/rsg-components/Editor/__snapshots__/Editor.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ exports[`Editor should renderer and editor 1`] = `
onChange={[Function]}
options={
Object {
"lineNumbers": false,
"lineWrapping": true,
"matchBrackets": true,
"mode": "jsx",
"smartIndent": false,
"theme": "base16-light",
"viewportMargin": Infinity,
"mode": "js",
}
}
value=
Expand Down