@lexical/file
Advanced tools
Comparing version 0.8.1 to 0.9.0
@@ -11,3 +11,3 @@ /** | ||
var version = "0.8.1"; | ||
var version = "0.9.0"; | ||
@@ -29,2 +29,3 @@ /** | ||
} | ||
function readTextFileFromSystem(callback) { | ||
@@ -36,2 +37,3 @@ const input = document.createElement('input'); | ||
const target = event.target; | ||
if (target.files) { | ||
@@ -41,2 +43,3 @@ const file = target.files[0]; | ||
reader.readAsText(file, 'UTF-8'); | ||
reader.onload = readerEvent => { | ||
@@ -52,2 +55,3 @@ if (readerEvent.target) { | ||
} | ||
function exportFile(editor, config = Object.freeze({})) { | ||
@@ -64,11 +68,12 @@ const now = new Date(); | ||
exportBlob(documentJSON, `${fileName}.lexical`); | ||
} | ||
} // Adapted from https://stackoverflow.com/a/19328891/2013580 | ||
// Adapted from https://stackoverflow.com/a/19328891/2013580 | ||
function exportBlob(data, fileName) { | ||
const a = document.createElement('a'); | ||
const body = document.body; | ||
if (body === null) { | ||
return; | ||
} | ||
body.appendChild(a); | ||
@@ -75,0 +80,0 @@ a.style.display = 'none'; |
@@ -8,3 +8,3 @@ /** | ||
'use strict';var f=require("lexical");function g(a){let c=document.createElement("input");c.type="file";c.accept=".lexical";c.addEventListener("change",b=>{b=b.target;if(b.files){b=b.files[0];let d=new FileReader;d.readAsText(b,"UTF-8");d.onload=e=>{e.target&&a(e.target.result)}}});c.click()} | ||
exports.exportFile=function(a,c=Object.freeze({})){var b=new Date;a={editorState:a.getEditorState(),lastSaved:b.getTime(),source:c.source||"Lexical",version:"0.8.1"};{c=`${c.fileName||b.toISOString()}.lexical`;b=document.createElement("a");let d=document.body;null!==d&&(d.appendChild(b),b.style.display="none",a=JSON.stringify(a),a=new Blob([a],{type:"octet/stream"}),a=window.URL.createObjectURL(a),b.href=a,b.download=c,b.click(),window.URL.revokeObjectURL(a),b.remove())}}; | ||
exports.exportFile=function(a,c=Object.freeze({})){var b=new Date;a={editorState:a.getEditorState(),lastSaved:b.getTime(),source:c.source||"Lexical",version:"0.9.0"};{c=`${c.fileName||b.toISOString()}.lexical`;b=document.createElement("a");let d=document.body;null!==d&&(d.appendChild(b),b.style.display="none",a=JSON.stringify(a),a=new Blob([a],{type:"octet/stream"}),a=window.URL.createObjectURL(a),b.href=a,b.download=c,b.click(),window.URL.revokeObjectURL(a),b.remove())}}; | ||
exports.importFile=function(a){g(c=>{c=JSON.parse(c);c=a.parseEditorState(JSON.stringify(c.editorState));a.setEditorState(c);a.dispatchCommand(f.CLEAR_HISTORY_COMMAND,void 0)})} |
@@ -13,6 +13,6 @@ { | ||
"license": "MIT", | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"main": "LexicalFile.js", | ||
"peerDependencies": { | ||
"lexical": "0.8.1" | ||
"lexical": "0.9.0" | ||
}, | ||
@@ -19,0 +19,0 @@ "repository": { |
6684
24
119