@lexical/history 0.2.1 → 0.2.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.
@@ -25,7 +25,6 @@ const COMPOSING_CHARACTER = 1;
25
25
  const INSERT_CHARACTER_AFTER_SELECTION = 2;
26
26
  const DELETE_CHARACTER_BEFORE_SELECTION = 3;
27
27
  const DELETE_CHARACTER_AFTER_SELECTION = 4;
28
- const EditorPriority = 0;
29
28
 
30
29
  function getDirtyNodes(editorState, dirtyLeaves, dirtyElements) {
31
30
  const nodeMap = editorState._nodeMap;
@@ -287,16 +286,16 @@ function registerHistory(editor, historyState, delay) {
287
286
  const unregisterCommandListener = utils.mergeRegister(editor.registerCommand(lexical.UNDO_COMMAND, () => {
288
287
  undo(editor, historyState);
289
288
  return true;
290
- }, EditorPriority), editor.registerCommand(lexical.REDO_COMMAND, () => {
289
+ }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.REDO_COMMAND, () => {
291
290
  redo(editor, historyState);
292
291
  return true;
293
- }, EditorPriority), editor.registerCommand(lexical.CLEAR_EDITOR_COMMAND, () => {
292
+ }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CLEAR_EDITOR_COMMAND, () => {
294
293
  clearHistory(historyState);
295
294
  return false;
296
- }, EditorPriority), editor.registerCommand(lexical.CLEAR_HISTORY_COMMAND, () => {
295
+ }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CLEAR_HISTORY_COMMAND, () => {
297
296
  clearHistory(historyState);
298
297
  return true;
299
- }, EditorPriority), editor.registerUpdateListener(applyChange));
298
+ }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerUpdateListener(applyChange));
300
299
  const unregisterUpdateListener = editor.registerUpdateListener(applyChange);
301
300
  return () => {
302
301
  unregisterCommandListener();
@@ -4,11 +4,12 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- var g=require("@lexical/utils"),u=require("lexical");
8
- function v(b,a,k,h,m){if(null===b||0===k.size&&0===h.size)return 0;var e=a._selection,c=b._selection;if(m)return 1;if(!(u.$isRangeSelection(e)&&u.$isRangeSelection(c)&&c.isCollapsed()&&e.isCollapsed()))return 0;m=a._nodeMap;const d=[];for(const f of k)k=m.get(f),void 0!==k&&d.push(k);for(const [f,l]of h)l&&(h=m.get(f),void 0===h||u.$isRootNode(h)||d.push(h));if(0===d.length)return 0;if(1<d.length)return h=a._nodeMap,a=h.get(e.anchor.key),c=h.get(c.anchor.key),a&&c&&!b._nodeMap.has(a.__key)&&u.$isTextNode(a)&&
9
- 1===a.__text.length&&1===e.anchor.offset?2:0;a=d[0];b=b._nodeMap.get(a.__key);if(!u.$isTextNode(b)||!u.$isTextNode(a)||b.__mode!==a.__mode)return 0;b=b.__text;a=a.__text;if(b===a)return 0;e=e.anchor;c=c.anchor;if(e.key!==c.key||"text"!==e.type)return 0;e=e.offset;c=c.offset;b=a.length-b.length;return 1===b&&c===e-1?2:-1===b&&c===e+1?3:-1===b&&c===e?4:0}
10
- function w(b,a){let k=Date.now(),h=0;return(m,e,c,d,f,l)=>{const p=Date.now();if(l.has("historic"))return h=0,k=p,2;const n=v(m,e,d,f,b.isComposing()),t=(()=>{const r=l.has("history-push");if(!r&&l.has("history-merge"))return 0;if(null===m)return 1;var q=e._selection;const x=m._selection;if(!(0<d.size||0<f.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}}
7
+ var e=require("@lexical/utils"),u=require("lexical");
8
+ function v(b,a,k,h,m){if(null===b||0===k.size&&0===h.size)return 0;var f=a._selection,c=b._selection;if(m)return 1;if(!(u.$isRangeSelection(f)&&u.$isRangeSelection(c)&&c.isCollapsed()&&f.isCollapsed()))return 0;m=a._nodeMap;const d=[];for(const g of k)k=m.get(g),void 0!==k&&d.push(k);for(const [g,l]of h)l&&(h=m.get(g),void 0===h||u.$isRootNode(h)||d.push(h));if(0===d.length)return 0;if(1<d.length)return h=a._nodeMap,a=h.get(f.anchor.key),c=h.get(c.anchor.key),a&&c&&!b._nodeMap.has(a.__key)&&u.$isTextNode(a)&&
9
+ 1===a.__text.length&&1===f.anchor.offset?2:0;a=d[0];b=b._nodeMap.get(a.__key);if(!u.$isTextNode(b)||!u.$isTextNode(a)||b.__mode!==a.__mode)return 0;b=b.__text;a=a.__text;if(b===a)return 0;f=f.anchor;c=c.anchor;if(f.key!==c.key||"text"!==f.type)return 0;f=f.offset;c=c.offset;b=a.length-b.length;return 1===b&&c===f-1?2:-1===b&&c===f+1?3:-1===b&&c===f?4:0}
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
- exports.registerHistory=function(b,a,k){const h=w(b,k);k=({editorState:c,prevEditorState:d,dirtyLeaves:f,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){f=h(d,c,n,f,l,p);if(1===f)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===f)return;a.current={editor:b,editorState:c}}};const m=g.mergeRegister(b.registerCommand(u.UNDO_COMMAND,
13
- ()=>{const c=a.redoStack,d=a.undoStack;if(0!==d.length){const f=a.current,l=d.pop();null!==f&&(c.push(f),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},0),b.registerCommand(u.REDO_COMMAND,()=>{const c=a.redoStack;var d=a.undoStack;if(0!==c.length){const f=a.current;null!==f&&(d.push(f),b.dispatchCommand(u.CAN_UNDO_COMMAND,!0));d=c.pop();0===c.length&&
14
- b.dispatchCommand(u.CAN_REDO_COMMAND,!1);a.current=d;d.editor.setEditorState(d.editorState,{tag:"historic"})}return!0},0),b.registerCommand(u.CLEAR_EDITOR_COMMAND,()=>{a.undoStack=[];a.redoStack=[];a.current=null;return!1},0),b.registerCommand(u.CLEAR_HISTORY_COMMAND,()=>{a.undoStack=[];a.redoStack=[];a.current=null;return!0},0),b.registerUpdateListener(k)),e=b.registerUpdateListener(k);return()=>{m();e()}};
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()}};
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "history"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.2.1",
11
+ "version": "0.2.4",
12
12
  "main": "LexicalHistory.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.2.1"
14
+ "lexical": "0.2.4"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.2.1"
17
+ "@lexical/utils": "0.2.4"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",