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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request!
Please have a look at my feedback to #649, most of the comments are valid here too.
I left the option there :)
Okay , makes sense |
I still think we should add a deprecation warning, it’s not good to have two valid ways of changing one option. |
Name has been changed sir ! How should I add that warning ? :) |
You need to add react-styleguidist/scripts/utils/sanitizeConfig.js Lines 91 to 92 in 043ba23
|
You also need to merge the old option with the new object in the config, we shouldn’t access the old option anywhere else. |
scripts/utils/sanitizeConfig.js
Outdated
@@ -89,7 +88,8 @@ 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}`); | |||
// eslint-disable-next-line no-console | |||
console.log(chalk.yellow.bold(`${key} config option is deprecated. ${props.deprecated}`)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It simply did not log anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to find what’s the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was actually a bug, I’ve fixed it in master and updated your branch — should work now.
src/rsg-components/Editor/Editor.js
Outdated
lineWrapping: true, | ||
smartIndent: false, | ||
matchBrackets: true, | ||
viewportMargin: Infinity, | ||
lineNumbers: false, | ||
theme: 'base16-light', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we have the same defaults object two times. Keep it in the config only and merge using process
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry , what do you mean ? :(
Too many words
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- You have this object twice: here and in the config schema. We need only one in the schema.
- Check how
process
method is used in the schema, you need something similar. You also need it to merge the old option with the new one.
src/rsg-components/Editor/Editor.js
Outdated
@@ -46,9 +47,10 @@ export default class Editor extends Component { | |||
|
|||
render() { | |||
const { code } = this.props; | |||
const { highlightTheme } = this.context.config; | |||
const { highlightTheme, editorConfig } = this.context.config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not use highlightTheme
anywhere except the config schema. Now you’re overwriting the right option with the wrong one anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I thought this is where you meant fpr me to merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to merge the old option with the new object in the config, we shouldn’t access the old option anywhere else.
Codecov Report
|
@SaraVieira Hey Sara, any plans to finish? It’s almost done 🦄 |
This reverts commit afe03cf.
Hello ! Sorry for the time it passed :( I was in london and super busy :( It's not repeated anymore :) About the process .... should it get the value i+and if none is return the hightlight theme one and the defaults ? |
Something like this: editorConfig: {
// ...
process: (value, config) => {
return Object.assign({}, { theme: config.highlightTheme }, value);
},
}, |
Like this ? |
Almost: defaults should be in the schema. |
The CI can't find jest :( |
We need to find what’s the issue because it works in master. |
I know , the weirdest is that I didn't change anything on any files that have anything to do with config :( |
@sapegin did you do anything ? The tests are now passing |
I’ve cleared Travis cache and restarted them. |
The very last thing: docs! 📖 |
@@ -227,11 +227,22 @@ module.exports = { | |||
} | |||
``` | |||
|
|||
#### `highlightTheme` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc changes here :)
docs/Configuration.md
Outdated
|
||
Type: `String`, default: `base16-light` | ||
Type: `Object`, default: | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d put a link to the source instead of an object.
docs/Configuration.md
Outdated
@@ -17,7 +17,7 @@ By default, Styleguidist will look for `styleguide.config.js` file in your proje | |||
* [`getComponentPathLine`](#getcomponentpathline) | |||
* [`getExampleFilename`](#getexamplefilename) | |||
* [`handlers`](#handlers) | |||
* [`highlightTheme`](#highlighttheme) | |||
* [`editorConfig`](#editorConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They aren’t ordered now.
docs/Configuration.md
Outdated
|
||
[CodeMirror theme](http://codemirror.net/demo/theme.html) name to use for syntax highlighting in the editor. | ||
This will determine how your editor looks, you can check [here](https://codemirror.net/doc/manual.html#config) all the available options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shorter at least:
Source code editor options, see CodeMirror docs for all available options.
Docs updated! Sorry , didn't notice it was in alphabetic order 🤦♀️ |
docs/Configuration.md
Outdated
@@ -168,6 +168,12 @@ module.exports = { | |||
} | |||
``` | |||
|
|||
#### `editorConfig` | |||
|
|||
Type: `Object`, default: [scripts/schemas/config.js](https://github.com/styleguidist/react-styleguidist/blob/87efdde2d52209e9c4072368402d11030943d69f/scripts/schemas/config.js#L101) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to point to master in case we change the options.
That was dumb of me 🤦♀️ Done !! 🙂 |
Awesome! Praying for CI again 🙏 |
Weird, some links are failing in the snapshots only on node 4 |
Yup, that’s very weird. We have that in master too. Restart often helps. |
Merged! |
YES 🌈 |
## New features * New option `editorConfig` to change CodeMirror options (#648, [#662](#662) by @SaraVieira) * Allow descriptions for sections ([#743](#743) by @SaraVieira) * Add TypeScript files to default components and ignore patterns ([#749](#749), part of [#750](#750)) ## Bug fixes * Fix global access to all components in isolation mode ([#738](#738)) * Fix color issue in Safari ([#739](#739)) * Allow overriding of renderer-only components ([#710](#710)) * Do not overflow floated elements in examples (#772, [#773](#773) by @roblevintennis) * HTML escaping in Add example block ([#741](#741)) * Fix infinite loop caused by markdown-to-jsx ([#742](#742))
## New features * New option `editorConfig` to change CodeMirror options (#648, [#662](#662) by @SaraVieira) * Allow descriptions for sections ([#743](#743) by @SaraVieira) * Add TypeScript files to default components and ignore patterns ([#749](#749), part of [#750](#750)) ## Bug fixes * Fix global access to all components in isolation mode ([#738](#738)) * Fix color issue in Safari ([#739](#739)) * Allow overriding of renderer-only components ([#710](#710)) * Do not overflow floated elements in examples (#772, [#773](#773) by @roblevintennis) * HTML escaping in Add example block ([#741](#741)) * Fix infinite loop caused by markdown-to-jsx ([#742](#742))
## New features * New option `editorConfig` to change CodeMirror options (#648, [#662](#662) by @SaraVieira) * Allow descriptions for sections ([#743](#743) by @SaraVieira) * Add TypeScript files to default components and ignore patterns ([#749](#749), part of [#750](#750)) ## Bug fixes * Fix global access to all components in isolation mode ([#738](#738)) * Fix color issue in Safari ([#739](#739)) * Allow overriding of renderer-only components ([#710](#710)) * Do not overflow floated elements in examples (#772, [#773](#773) by @roblevintennis) * HTML escaping in Add example block ([#741](#741)) * Fix infinite loop caused by markdown-to-jsx ([#742](#742))
## New features * New option `editorConfig` to change CodeMirror options (#648, [#662](styleguidist/react-styleguidist#662) by @SaraVieira) * Allow descriptions for sections ([#743](styleguidist/react-styleguidist#743) by @SaraVieira) * Add TypeScript files to default components and ignore patterns ([#749](styleguidist/react-styleguidist#749), part of [#750](styleguidist/react-styleguidist#750)) ## Bug fixes * Fix global access to all components in isolation mode ([#738](styleguidist/react-styleguidist#738)) * Fix color issue in Safari ([#739](styleguidist/react-styleguidist#739)) * Allow overriding of renderer-only components ([#710](styleguidist/react-styleguidist#710)) * Do not overflow floated elements in examples (#772, [#773](styleguidist/react-styleguidist#773) by @roblevintennis) * HTML escaping in Add example block ([#741](styleguidist/react-styleguidist#741)) * Fix infinite loop caused by markdown-to-jsx ([#742](styleguidist/react-styleguidist#742))
## New features * New option `editorConfig` to change CodeMirror options (#648, [#662](styleguidist/react-styleguidist#662) by @SaraVieira) * Allow descriptions for sections ([#743](styleguidist/react-styleguidist#743) by @SaraVieira) * Add TypeScript files to default components and ignore patterns ([#749](styleguidist/react-styleguidist#749), part of [#750](styleguidist/react-styleguidist#750)) ## Bug fixes * Fix global access to all components in isolation mode ([#738](styleguidist/react-styleguidist#738)) * Fix color issue in Safari ([#739](styleguidist/react-styleguidist#739)) * Allow overriding of renderer-only components ([#710](styleguidist/react-styleguidist#710)) * Do not overflow floated elements in examples (#772, [#773](styleguidist/react-styleguidist#773) by @roblevintennis) * HTML escaping in Add example block ([#741](styleguidist/react-styleguidist#741)) * Fix infinite loop caused by markdown-to-jsx ([#742](styleguidist/react-styleguidist#742))
## New features * New option `editorConfig` to change CodeMirror options (#648, [#662](styleguidist/react-styleguidist#662) by @SaraVieira) * Allow descriptions for sections ([#743](styleguidist/react-styleguidist#743) by @SaraVieira) * Add TypeScript files to default components and ignore patterns ([#749](styleguidist/react-styleguidist#749), part of [#750](styleguidist/react-styleguidist#750)) ## Bug fixes * Fix global access to all components in isolation mode ([#738](styleguidist/react-styleguidist#738)) * Fix color issue in Safari ([#739](styleguidist/react-styleguidist#739)) * Allow overriding of renderer-only components ([#710](styleguidist/react-styleguidist#710)) * Do not overflow floated elements in examples (#772, [#773](styleguidist/react-styleguidist#773) by @roblevintennis) * HTML escaping in Add example block ([#741](styleguidist/react-styleguidist#741)) * Fix infinite loop caused by markdown-to-jsx ([#742](styleguidist/react-styleguidist#742))
All you now pass inside codeMirrorOptions in your styleguide config will be passed to codeMirror.
I left highlight theme out because I didn't want to cause a breaking change
closes #648