diff --git a/frontend/src/Metamaps/Import.js b/frontend/src/Metamaps/Import.js index 54e256b2..8fc07262 100644 --- a/frontend/src/Metamaps/Import.js +++ b/frontend/src/Metamaps/Import.js @@ -388,6 +388,36 @@ const Import = { } ) }, + + handleTEXT: function(text, opts = {}) { + let coords = opts.coords + if (!coords || coords.x === undefined || coords.y === undefined) { + coords = AutoLayout.getNextCoord({ mappings: DataModel.Mappings }) + } + + const name = text + const url = "" + const metacode = opts.metacode || 'Wildcard' + const importId = opts.importId || null // don't store a cidMapping + const permission = opts.permission || null // use default + const desc = opts.desc || "" + + Import.createTopicWithParameters( + name, + metacode, + permission, + desc, + url, + coords.x, + coords.y, + importId, + { + success: function(topic) { + return + } + } + ) + }, /* * helper functions diff --git a/frontend/src/Metamaps/PasteInput.js b/frontend/src/Metamaps/PasteInput.js index 03a92f86..c31cb19b 100644 --- a/frontend/src/Metamaps/PasteInput.js +++ b/frontend/src/Metamaps/PasteInput.js @@ -7,8 +7,7 @@ import Visualize from './Visualize' const PasteInput = { // thanks to https://github.com/kevva/url-regex // eslint-disable-next-line no-useless-escape - URL_REGEX: new RegExp('^(?:(?:(?:[a-z]+:)?//)|www\.)(?:\S+(?::\S*)?@)?(?:localhost|(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#][^\s"]*)?$'), - + URL_REGEX: new RegExp(/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/,"i"), init: function() { var self = PasteInput @@ -29,12 +28,10 @@ const PasteInput = { if (e.dataTransfer.files.length > 0) { self.handleFile(e.dataTransfer.files[0], coords) } - // OMG import bookmarks 😍 + // OMG import bookmarks 😍 (Or just text :P) if (e.dataTransfer.items && e.dataTransfer.items.length > 0) { e.dataTransfer.items[0].getAsString(function(text) { - if (text.match(self.URL_REGEX)) { - self.handle(text, coords) - } + self.handle(text,coords) }) } }, false) @@ -70,11 +67,25 @@ const PasteInput = { Import.handleURL(text, coords) } else if (text[0] === '{') { Import.handleJSON(text) - } else if (text.match(/\t/)) { + } else if (text.match(/[Tt]opics\t/) || text.match(/[Ss]ynapses\t/)) { + console.log("Tab sep!") Import.handleTSV(text) } else { - // just try to see if CSV works - Import.handleCSV(text) + //Handle as plain text + console.log("The text is:",text,"!") + let textItems = text.split("\n") + if (textItems.length === 1){ + if(textItems[0].trim() !== ""){ + Import.handleTEXT(textItems[0].trim(),coords) + } + } + else if (window.confirm('Are you sure you want to create ' + textItems.length + ' new topics?')) { + textItems.forEach(item => { + if(item.trim() !== ""){ + self.handle(item.trim(),coords) + } + }) + } } } }