Initial prettier formatted files

This commit is contained in:
Dmitry Yankowski
2020-02-24 13:44:50 -05:00
parent 1543c990ca
commit 777e629b3d
83 changed files with 18556 additions and 19258 deletions

View File

@@ -3,86 +3,79 @@
</template>
<script>
const DEFAULT_THEME = "twilight";
const DEFAULT_THEME = 'twilight'
import ace from "ace-builds";
import * as gql from "graphql";
import { getAutocompleteSuggestions } from "graphql-language-service-interface";
import "ace-builds/webpack-resolver";
import "ace-builds/src-noconflict/ext-language_tools";
import debounce from "../../functions/utils/debounce";
import ace from 'ace-builds'
import * as gql from 'graphql'
import { getAutocompleteSuggestions } from 'graphql-language-service-interface'
import 'ace-builds/webpack-resolver'
import 'ace-builds/src-noconflict/ext-language_tools'
import debounce from '../../functions/utils/debounce'
export default {
props: {
value: {
type: String,
default: ""
default: '',
},
theme: {
type: String,
required: false
required: false,
},
lang: {
type: String,
default: "json"
default: 'json',
},
options: {
type: Object,
default: {}
}
default: {},
},
},
data() {
return {
editor: null,
cacheValue: "",
validationSchema: null
};
cacheValue: '',
validationSchema: null,
}
},
watch: {
value(value) {
if (value !== this.cacheValue) {
this.editor.session.setValue(value, 1);
this.cacheValue = value;
this.editor.session.setValue(value, 1)
this.cacheValue = value
}
},
theme() {
this.editor.setTheme(`ace/theme/${this.defineTheme()}`);
this.editor.setTheme(`ace/theme/${this.defineTheme()}`)
},
lang(value) {
this.editor.getSession().setMode(`ace/mode/${value}`);
this.editor.getSession().setMode(`ace/mode/${value}`)
},
options(value) {
this.editor.setOptions(value);
}
this.editor.setOptions(value)
},
},
mounted() {
let langTools = ace.require("ace/ext/language_tools");
let langTools = ace.require('ace/ext/language_tools')
const editor = ace.edit(this.$refs.editor, {
theme: `ace/theme/${this.defineTheme()}`,
mode: `ace/mode/${this.lang}`,
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
...this.options
});
...this.options,
})
const completer = {
getCompletions: (
editor,
_session,
{ row, column },
_prefix,
callback
) => {
getCompletions: (editor, _session, { row, column }, _prefix, callback) => {
if (this.validationSchema) {
const completions = getAutocompleteSuggestions(
this.validationSchema,
editor.getValue(),
{ line: row, character: column }
);
const completions = getAutocompleteSuggestions(this.validationSchema, editor.getValue(), {
line: row,
character: column,
})
callback(
null,
@@ -90,64 +83,60 @@ export default {
name: label,
value: label,
score: 1.0,
meta: detail
meta: detail,
}))
);
)
} else {
callback(null, []);
callback(null, [])
}
}
};
},
}
langTools.setCompleters([completer]);
langTools.setCompleters([completer])
if (this.value) editor.setValue(this.value, 1);
if (this.value) editor.setValue(this.value, 1)
this.editor = editor;
this.cacheValue = this.value;
this.editor = editor
this.cacheValue = this.value
editor.on("change", () => {
const content = editor.getValue();
this.$emit("input", content);
this.parseContents(content);
this.cacheValue = content;
});
editor.on('change', () => {
const content = editor.getValue()
this.$emit('input', content)
this.parseContents(content)
this.cacheValue = content
})
this.parseContents(this.value);
this.parseContents(this.value)
},
methods: {
defineTheme() {
if (this.theme) {
return this.theme;
return this.theme
} else {
return (
this.$store.state.postwoman.settings.THEME_ACE_EDITOR || DEFAULT_THEME
);
return this.$store.state.postwoman.settings.THEME_ACE_EDITOR || DEFAULT_THEME
}
},
setValidationSchema(schema) {
this.validationSchema = schema;
this.parseContents(this.cacheValue);
this.validationSchema = schema
this.parseContents(this.cacheValue)
},
parseContents: debounce(function(content) {
if (content !== "") {
if (content !== '') {
try {
const doc = gql.parse(content);
const doc = gql.parse(content)
if (this.validationSchema) {
this.editor.session.setAnnotations(
gql
.validate(this.validationSchema, doc)
.map(({ locations, message }) => ({
row: locations[0].line - 1,
column: locations[0].column - 1,
text: message,
type: "error"
}))
);
gql.validate(this.validationSchema, doc).map(({ locations, message }) => ({
row: locations[0].line - 1,
column: locations[0].column - 1,
text: message,
type: 'error',
}))
)
}
} catch (e) {
this.editor.session.setAnnotations([
@@ -155,19 +144,19 @@ export default {
row: e.locations[0].line - 1,
column: e.locations[0].column - 1,
text: e.message,
type: "error"
}
]);
type: 'error',
},
])
}
} else {
this.editor.session.setAnnotations([]);
this.editor.session.setAnnotations([])
}
}, 2000)
}, 2000),
},
beforeDestroy() {
this.editor.destroy();
this.editor.container.remove();
}
};
this.editor.destroy()
this.editor.container.remove()
},
}
</script>