@lexical/history 0.2.5 → 0.2.6

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.
@@ -5,6 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
+
8
9
  import type {
9
10
  EditorState,
10
11
  GridSelection,
@@ -15,7 +15,6 @@ var lexical = require('lexical');
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
17
  *
18
- *
19
18
  */
20
19
  const HISTORY_MERGE = 0;
21
20
  const HISTORY_PUSH = 1;
@@ -202,10 +201,13 @@ function redo(editor, historyState) {
202
201
  editor.dispatchCommand(lexical.CAN_REDO_COMMAND, false);
203
202
  }
204
203
 
205
- historyState.current = historyStateEntry;
206
- historyStateEntry.editor.setEditorState(historyStateEntry.editorState, {
207
- tag: 'historic'
208
- });
204
+ historyState.current = historyStateEntry || null;
205
+
206
+ if (historyStateEntry) {
207
+ historyStateEntry.editor.setEditorState(historyStateEntry.editorState, {
208
+ tag: 'historic'
209
+ });
210
+ }
209
211
  }
210
212
  }
211
213
 
@@ -227,10 +229,13 @@ function undo(editor, historyState) {
227
229
  editor.dispatchCommand(lexical.CAN_UNDO_COMMAND, false);
228
230
  }
229
231
 
230
- historyState.current = historyStateEntry;
231
- historyStateEntry.editor.setEditorState(historyStateEntry.editorState.clone(historyStateEntry.undoSelection), {
232
- tag: 'historic'
233
- });
232
+ historyState.current = historyStateEntry || null;
233
+
234
+ if (historyStateEntry) {
235
+ historyStateEntry.editor.setEditorState(historyStateEntry.editorState.clone(historyStateEntry.undoSelection), {
236
+ tag: 'historic'
237
+ });
238
+ }
234
239
  }
235
240
  }
236
241
 
@@ -10,6 +10,6 @@ function v(b,a,k,h,m){if(null===b||0===k.size&&0===h.size)return 0;var f=a._sele
10
10
  function w(b,a){let k=Date.now(),h=0;return(m,f,c,d,g,l)=>{const p=Date.now();if(l.has("historic"))return h=0,k=p,2;const n=v(m,f,d,g,b.isComposing()),t=(()=>{const r=l.has("history-push");if(!r&&l.has("history-merge"))return 0;if(null===m)return 1;var q=f._selection;const x=m._selection;if(!(0<d.size||0<g.size))return null===x&&null!==q?0:2;q=null===c||c.editor===b;return!1===r&&0!==n&&n===h&&p<k+a&&q?0:1})();k=p;h=n;return t}}
11
11
  exports.createEmptyHistoryState=function(){return{current:null,redoStack:[],undoStack:[]}};
12
12
  exports.registerHistory=function(b,a,k){const h=w(b,k);k=({editorState:c,prevEditorState:d,dirtyLeaves:g,dirtyElements:l,tags:p})=>{const n=a.current,t=a.redoStack,r=a.undoStack,q=null===n?null:n.editorState;if(null===n||c!==q){g=h(d,c,n,g,l,p);if(1===g)0!==t.length&&(a.redoStack=[]),null!==n&&(r.push({...n,undoSelection:d.read(u.$getSelection)}),b.dispatchCommand(u.CAN_UNDO_COMMAND,!0));else if(2===g)return;a.current={editor:b,editorState:c}}};const m=e.mergeRegister(b.registerCommand(u.UNDO_COMMAND,
13
- ()=>{const c=a.redoStack,d=a.undoStack;if(0!==d.length){const g=a.current,l=d.pop();null!==g&&(c.push(g),b.dispatchCommand(u.CAN_REDO_COMMAND,!0));0===d.length&&b.dispatchCommand(u.CAN_UNDO_COMMAND,!1);a.current=l;l.editor.setEditorState(l.editorState.clone(l.undoSelection),{tag:"historic"})}return!0},u.COMMAND_PRIORITY_EDITOR),b.registerCommand(u.REDO_COMMAND,()=>{const c=a.redoStack;var d=a.undoStack;if(0!==c.length){const g=a.current;null!==g&&(d.push(g),b.dispatchCommand(u.CAN_UNDO_COMMAND,!0));
14
- d=c.pop();0===c.length&&b.dispatchCommand(u.CAN_REDO_COMMAND,!1);a.current=d;d.editor.setEditorState(d.editorState,{tag:"historic"})}return!0},u.COMMAND_PRIORITY_EDITOR),b.registerCommand(u.CLEAR_EDITOR_COMMAND,()=>{a.undoStack=[];a.redoStack=[];a.current=null;return!1},u.COMMAND_PRIORITY_EDITOR),b.registerCommand(u.CLEAR_HISTORY_COMMAND,()=>{a.undoStack=[];a.redoStack=[];a.current=null;return!0},u.COMMAND_PRIORITY_EDITOR),b.registerUpdateListener(k)),f=b.registerUpdateListener(k);return()=>{m();
15
- f()}};
13
+ ()=>{const c=a.redoStack,d=a.undoStack;if(0!==d.length){const g=a.current,l=d.pop();null!==g&&(c.push(g),b.dispatchCommand(u.CAN_REDO_COMMAND,!0));0===d.length&&b.dispatchCommand(u.CAN_UNDO_COMMAND,!1);a.current=l||null;l&&l.editor.setEditorState(l.editorState.clone(l.undoSelection),{tag:"historic"})}return!0},u.COMMAND_PRIORITY_EDITOR),b.registerCommand(u.REDO_COMMAND,()=>{const c=a.redoStack;var d=a.undoStack;if(0!==c.length){const g=a.current;null!==g&&(d.push(g),b.dispatchCommand(u.CAN_UNDO_COMMAND,
14
+ !0));d=c.pop();0===c.length&&b.dispatchCommand(u.CAN_REDO_COMMAND,!1);a.current=d||null;d&&d.editor.setEditorState(d.editorState,{tag:"historic"})}return!0},u.COMMAND_PRIORITY_EDITOR),b.registerCommand(u.CLEAR_EDITOR_COMMAND,()=>{a.undoStack=[];a.redoStack=[];a.current=null;return!1},u.COMMAND_PRIORITY_EDITOR),b.registerCommand(u.CLEAR_HISTORY_COMMAND,()=>{a.undoStack=[];a.redoStack=[];a.current=null;return!0},u.COMMAND_PRIORITY_EDITOR),b.registerUpdateListener(k)),f=b.registerUpdateListener(k);return()=>
15
+ {m();f()}};
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "history"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.2.5",
11
+ "version": "0.2.6",
12
12
  "main": "LexicalHistory.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.2.5"
14
+ "lexical": "0.2.6"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.2.5"
17
+ "@lexical/utils": "0.2.6"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",