@lexical/file 0.7.8 → 0.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalFile.dev.js +3 -8
- package/LexicalFile.prod.js +1 -1
- package/package.json +2 -2
package/LexicalFile.dev.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
var lexical = require('lexical');
|
|
10
10
|
|
|
11
|
-
var version = "0.7.
|
|
11
|
+
var version = "0.7.9";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -25,19 +25,16 @@ function importFile(editor) {
|
|
|
25
25
|
editor.dispatchCommand(lexical.CLEAR_HISTORY_COMMAND, undefined);
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
|
|
29
28
|
function readTextFileFromSystem(callback) {
|
|
30
29
|
const input = document.createElement('input');
|
|
31
30
|
input.type = 'file';
|
|
32
31
|
input.accept = '.lexical';
|
|
33
32
|
input.addEventListener('change', event => {
|
|
34
33
|
const target = event.target;
|
|
35
|
-
|
|
36
34
|
if (target.files) {
|
|
37
35
|
const file = target.files[0];
|
|
38
36
|
const reader = new FileReader();
|
|
39
37
|
reader.readAsText(file, 'UTF-8');
|
|
40
|
-
|
|
41
38
|
reader.onload = readerEvent => {
|
|
42
39
|
if (readerEvent.target) {
|
|
43
40
|
const content = readerEvent.target.result;
|
|
@@ -48,7 +45,6 @@ function readTextFileFromSystem(callback) {
|
|
|
48
45
|
});
|
|
49
46
|
input.click();
|
|
50
47
|
}
|
|
51
|
-
|
|
52
48
|
function exportFile(editor, config = Object.freeze({})) {
|
|
53
49
|
const now = new Date();
|
|
54
50
|
const editorState = editor.getEditorState();
|
|
@@ -60,16 +56,15 @@ function exportFile(editor, config = Object.freeze({})) {
|
|
|
60
56
|
};
|
|
61
57
|
const fileName = config.fileName || now.toISOString();
|
|
62
58
|
exportBlob(documentJSON, `${fileName}.lexical`);
|
|
63
|
-
}
|
|
59
|
+
}
|
|
64
60
|
|
|
61
|
+
// Adapted from https://stackoverflow.com/a/19328891/2013580
|
|
65
62
|
function exportBlob(data, fileName) {
|
|
66
63
|
const a = document.createElement('a');
|
|
67
64
|
const body = document.body;
|
|
68
|
-
|
|
69
65
|
if (body === null) {
|
|
70
66
|
return;
|
|
71
67
|
}
|
|
72
|
-
|
|
73
68
|
body.appendChild(a);
|
|
74
69
|
a.style.display = 'none';
|
|
75
70
|
const json = JSON.stringify(data);
|
package/LexicalFile.prod.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'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()}
|
|
8
|
-
exports.exportFile=function(a,c=Object.freeze({})){var b=new Date;a={editorState:a.getEditorState(),lastSaved:b.getTime(),source:c.source||"Lexical",version:"0.7.
|
|
8
|
+
exports.exportFile=function(a,c=Object.freeze({})){var b=new Date;a={editorState:a.getEditorState(),lastSaved:b.getTime(),source:c.source||"Lexical",version:"0.7.9"};{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())}};
|
|
9
9
|
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)})}
|
package/package.json
CHANGED