@lexical/file 0.12.2 → 0.12.4
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 +4 -9
- 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.12.
|
|
11
|
+
var version = "0.12.4";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -17,11 +17,11 @@ var version = "0.12.2";
|
|
|
17
17
|
* LICENSE file in the root directory of this source tree.
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
+
|
|
20
21
|
/**
|
|
21
22
|
* Takes a file and inputs its content into the editor state as an input field.
|
|
22
23
|
* @param editor - The lexical editor.
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
25
|
function importFile(editor) {
|
|
26
26
|
readTextFileFromSystem(text => {
|
|
27
27
|
const json = JSON.parse(text);
|
|
@@ -30,19 +30,16 @@ function importFile(editor) {
|
|
|
30
30
|
editor.dispatchCommand(lexical.CLEAR_HISTORY_COMMAND, undefined);
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
|
|
34
33
|
function readTextFileFromSystem(callback) {
|
|
35
34
|
const input = document.createElement('input');
|
|
36
35
|
input.type = 'file';
|
|
37
36
|
input.accept = '.lexical';
|
|
38
37
|
input.addEventListener('change', event => {
|
|
39
38
|
const target = event.target;
|
|
40
|
-
|
|
41
39
|
if (target.files) {
|
|
42
40
|
const file = target.files[0];
|
|
43
41
|
const reader = new FileReader();
|
|
44
42
|
reader.readAsText(file, 'UTF-8');
|
|
45
|
-
|
|
46
43
|
reader.onload = readerEvent => {
|
|
47
44
|
if (readerEvent.target) {
|
|
48
45
|
const content = readerEvent.target.result;
|
|
@@ -53,7 +50,6 @@ function readTextFileFromSystem(callback) {
|
|
|
53
50
|
});
|
|
54
51
|
input.click();
|
|
55
52
|
}
|
|
56
|
-
|
|
57
53
|
/**
|
|
58
54
|
* Generates a .lexical file to be downloaded by the browser containing the current editor state.
|
|
59
55
|
* @param editor - The lexical editor.
|
|
@@ -71,16 +67,15 @@ function exportFile(editor, config = Object.freeze({})) {
|
|
|
71
67
|
};
|
|
72
68
|
const fileName = config.fileName || now.toISOString();
|
|
73
69
|
exportBlob(documentJSON, `${fileName}.lexical`);
|
|
74
|
-
}
|
|
70
|
+
}
|
|
75
71
|
|
|
72
|
+
// Adapted from https://stackoverflow.com/a/19328891/2013580
|
|
76
73
|
function exportBlob(data, fileName) {
|
|
77
74
|
const a = document.createElement('a');
|
|
78
75
|
const body = document.body;
|
|
79
|
-
|
|
80
76
|
if (body === null) {
|
|
81
77
|
return;
|
|
82
78
|
}
|
|
83
|
-
|
|
84
79
|
body.appendChild(a);
|
|
85
80
|
a.style.display = 'none';
|
|
86
81
|
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.12.
|
|
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.12.4"};{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