@lexical/file 0.9.1 → 0.9.2
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 +12 -1
- package/LexicalFile.prod.js +1 -1
- package/fileImportExport.d.ts +10 -0
- 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.9.
|
|
11
|
+
var version = "0.9.2";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -17,6 +17,11 @@ var version = "0.9.1";
|
|
|
17
17
|
* LICENSE file in the root directory of this source tree.
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
+
/**
|
|
21
|
+
* Takes a file and inputs its content into the editor state as an input field.
|
|
22
|
+
* @param editor - The lexical editor.
|
|
23
|
+
*/
|
|
24
|
+
|
|
20
25
|
function importFile(editor) {
|
|
21
26
|
readTextFileFromSystem(text => {
|
|
22
27
|
const json = JSON.parse(text);
|
|
@@ -49,6 +54,12 @@ function readTextFileFromSystem(callback) {
|
|
|
49
54
|
input.click();
|
|
50
55
|
}
|
|
51
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Generates a .lexical file to be downloaded by the browser containing the current editor state.
|
|
59
|
+
* @param editor - The lexical editor.
|
|
60
|
+
* @param config - An object that optionally contains fileName and source. fileName defaults to
|
|
61
|
+
* the current date (as a string) and source defaults to lexical.
|
|
62
|
+
*/
|
|
52
63
|
function exportFile(editor, config = Object.freeze({})) {
|
|
53
64
|
const now = new Date();
|
|
54
65
|
const editorState = editor.getEditorState();
|
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.9.
|
|
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.9.2"};{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/fileImportExport.d.ts
CHANGED
|
@@ -6,7 +6,17 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import type { LexicalEditor } from 'lexical';
|
|
9
|
+
/**
|
|
10
|
+
* Takes a file and inputs its content into the editor state as an input field.
|
|
11
|
+
* @param editor - The lexical editor.
|
|
12
|
+
*/
|
|
9
13
|
export declare function importFile(editor: LexicalEditor): void;
|
|
14
|
+
/**
|
|
15
|
+
* Generates a .lexical file to be downloaded by the browser containing the current editor state.
|
|
16
|
+
* @param editor - The lexical editor.
|
|
17
|
+
* @param config - An object that optionally contains fileName and source. fileName defaults to
|
|
18
|
+
* the current date (as a string) and source defaults to lexical.
|
|
19
|
+
*/
|
|
10
20
|
export declare function exportFile(editor: LexicalEditor, config?: Readonly<{
|
|
11
21
|
fileName?: string;
|
|
12
22
|
source?: string;
|
package/package.json
CHANGED