mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-15 22:31:24 +00:00
Correct handling of pasting tiddlers (#7215)
* First Pass Implementation * Fix Check * Fix Style * Update drag-drop interop example to support copy tiddlers to clipboard --------- Co-authored-by: jeremy@jermolene.com <jeremy@jermolene.com>
This commit is contained in:
@@ -159,7 +159,7 @@ exports.importDataTransfer = function(dataTransfer,fallbackTitle,callback) {
|
||||
if(!$tw.browser.isIE || importDataTypes[t].IECompatible) {
|
||||
// Get the data
|
||||
var dataType = importDataTypes[t];
|
||||
var data = dataTransfer.getData(dataType.type);
|
||||
var data = dataTransfer.getData(dataType.type);
|
||||
// Import the tiddlers in the data
|
||||
if(data !== "" && data !== null) {
|
||||
if($tw.log.IMPORT) {
|
||||
@@ -173,6 +173,36 @@ exports.importDataTransfer = function(dataTransfer,fallbackTitle,callback) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.importPaste = function(item,fallbackTitle,callback) {
|
||||
// Try each provided data type in turn
|
||||
for(var t=0; t<importDataTypes.length; t++) {
|
||||
if(item.type === importDataTypes[t].type) {
|
||||
// Get the data
|
||||
var dataType = importDataTypes[t];
|
||||
|
||||
item.getAsString(function(data){
|
||||
if($tw.log.IMPORT) {
|
||||
console.log("Importing data type '" + dataType.type + "', data: '" + data + "'")
|
||||
}
|
||||
var tiddlerFields = dataType.toTiddlerFieldsArray(data,fallbackTitle);
|
||||
callback(tiddlerFields);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.itemHasValidDataType = function(item) {
|
||||
for(var t=0; t<importDataTypes.length; t++) {
|
||||
if(!$tw.browser.isIE || importDataTypes[t].IECompatible) {
|
||||
if(item.type === importDataTypes[t].type) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
var importDataTypes = [
|
||||
{type: "text/vnd.tiddler", IECompatible: false, toTiddlerFieldsArray: function(data,fallbackTitle) {
|
||||
return parseJSONTiddlers(data,fallbackTitle);
|
||||
@@ -205,7 +235,13 @@ var importDataTypes = [
|
||||
return [{title: fallbackTitle, text: data}];
|
||||
}},
|
||||
{type: "text/uri-list", IECompatible: false, toTiddlerFieldsArray: function(data,fallbackTitle) {
|
||||
return [{title: fallbackTitle, text: data}];
|
||||
// Check for tiddler data URI
|
||||
var match = $tw.utils.decodeURIComponentSafe(data).match(/^data\:text\/vnd\.tiddler,(.*)/i);
|
||||
if(match) {
|
||||
return parseJSONTiddlers(match[1],fallbackTitle);
|
||||
} else {
|
||||
return [{title: fallbackTitle, text: data}]; // As URL string
|
||||
}
|
||||
}}
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user