mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-26 17:00:38 +01:00
Merge pull request #661 from orangemug/fix/issue-660-v2
Added JSON linting back into <SourceTypeEditor/>
This commit is contained in:
commit
1fede3af3a
2 changed files with 29 additions and 0 deletions
|
@ -214,6 +214,11 @@ class GeoJSONSourceJSONEditor extends React.Component {
|
|||
<JSONEditor
|
||||
layer={this.props.source.data}
|
||||
maxHeight={200}
|
||||
mode={{
|
||||
name: "javascript",
|
||||
json: true
|
||||
}}
|
||||
lint={true}
|
||||
onChange={data => {
|
||||
this.props.onChange({
|
||||
...this.props.source,
|
||||
|
|
|
@ -12,6 +12,30 @@ CodeMirror.defineMode("mgl", function(config, parserConfig) {
|
|||
);
|
||||
});
|
||||
|
||||
CodeMirror.registerHelper("lint", "json", function(text) {
|
||||
const found = [];
|
||||
|
||||
// NOTE: This was modified from the original to remove the global, also the
|
||||
// old jsonlint API was 'jsonlint.parseError' its now
|
||||
// 'jsonlint.parser.parseError'
|
||||
jsonlint.parser.parseError = function(str, hash) {
|
||||
const loc = hash.loc;
|
||||
found.push({
|
||||
from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
|
||||
to: CodeMirror.Pos(loc.last_line - 1, loc.last_column),
|
||||
message: str
|
||||
});
|
||||
};
|
||||
|
||||
try {
|
||||
jsonlint.parse(text);
|
||||
}
|
||||
catch(e) {
|
||||
// Do nothing we catch the error above
|
||||
}
|
||||
return found;
|
||||
});
|
||||
|
||||
CodeMirror.registerHelper("lint", "mgl", function(text, opts, doc) {
|
||||
const found = [];
|
||||
const {parser} = jsonlint;
|
||||
|
|
Loading…
Reference in a new issue