Added Swagger
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import isFunction from "lodash/isFunction"
|
||||
|
||||
export default function(editor, { onGutterClick }) {
|
||||
editor.on("guttermousedown", (e) => {
|
||||
let editor = e.editor
|
||||
let line = e.getDocumentPosition().row
|
||||
let region = editor.renderer.$gutterLayer.getRegion(e)
|
||||
|
||||
e.stop()
|
||||
|
||||
if(isFunction(onGutterClick)) {
|
||||
onGutterClick({ region, line })
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// TODO: Turn these into actions, that we can override
|
||||
import GutterClick from "./gutter-click"
|
||||
import JsonToYaml from "./json-to-yaml"
|
||||
import TabHandler from "./tab-handler"
|
||||
|
||||
const plugins = [
|
||||
{fn: GutterClick, name: "gutterClick"},
|
||||
{fn: JsonToYaml, name: "jsonToYaml"},
|
||||
{fn: TabHandler, name: "tabHandler"},
|
||||
]
|
||||
|
||||
export default function (editor, props = {}, editorPluginsToRun = [], helpers = {}) {
|
||||
plugins
|
||||
.filter(plugin => ~editorPluginsToRun.indexOf(plugin.name))
|
||||
.forEach( plugin => {
|
||||
try {
|
||||
plugin.fn(editor, props, helpers)
|
||||
} catch(e) {
|
||||
console.error(`${plugin.name || ""} plugin error:`, e)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import YAML from "js-yaml"
|
||||
|
||||
export default function(editor) {
|
||||
editor.on("paste", e => {
|
||||
const originalStr = e.text
|
||||
if (!isJSON(originalStr)) {
|
||||
return
|
||||
}
|
||||
|
||||
let yamlString
|
||||
try {
|
||||
yamlString = YAML.safeDump(YAML.safeLoad(originalStr), {
|
||||
lineWidth: -1 // don't generate line folds
|
||||
})
|
||||
} catch (e) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!confirm("Would you like to convert your JSON into YAML?")) {
|
||||
return
|
||||
}
|
||||
|
||||
// using SelectionRange instead of CursorPosition, because:
|
||||
// SR.start|end === CP when there's no selection
|
||||
// and it catches indentation edge cases when there is one
|
||||
const padding = makePadding(editor.getSelectionRange().start.column)
|
||||
|
||||
// update the pasted content
|
||||
e.text = yamlString
|
||||
.split("\n")
|
||||
.map((line, i) => i == 0 ? line : padding + line) // don't pad first line, it's already indented
|
||||
.join("\n")
|
||||
.replace(/\t/g, " ") // tabs -> spaces, just to be sure
|
||||
})
|
||||
}
|
||||
|
||||
function isJSON (str){
|
||||
// basic test: "does this look like JSON?"
|
||||
let regex = /^[ \r\n\t]*[{\[]/
|
||||
|
||||
return regex.test(str)
|
||||
|
||||
}
|
||||
|
||||
function makePadding(len) {
|
||||
let str = ""
|
||||
|
||||
while(str.length < len) {
|
||||
str += " "
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export default function(editor) {
|
||||
// NOTE: react-ace has an onPaste prop.. we could refactor to that.
|
||||
editor.on("paste", e => {
|
||||
// replace all U+0009 tabs in pasted string with two spaces
|
||||
e.text = e.text.replace(/\t/g, " ")
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user