@lexical/history 0.3.11 → 0.4.0

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.
@@ -9,13 +9,7 @@
9
9
  var utils = require('@lexical/utils');
10
10
  var lexical = require('lexical');
11
11
 
12
- /**
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- *
18
- */
12
+ /** @module @lexical/history */
19
13
  const HISTORY_MERGE = 0;
20
14
  const HISTORY_PUSH = 1;
21
15
  const DISCARD_HISTORY_CANDIDATE = 2;
@@ -157,8 +151,9 @@ function createMergeActionGetter(editor, delay) {
157
151
  const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
158
152
 
159
153
  const mergeAction = (() => {
154
+ const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
160
155
  const shouldPushHistory = tags.has('history-push');
161
- const shouldMergeHistory = !shouldPushHistory && tags.has('history-merge');
156
+ const shouldMergeHistory = !shouldPushHistory && isSameEditor && tags.has('history-merge');
162
157
 
163
158
  if (shouldMergeHistory) {
164
159
  return HISTORY_MERGE;
@@ -180,8 +175,6 @@ function createMergeActionGetter(editor, delay) {
180
175
  return DISCARD_HISTORY_CANDIDATE;
181
176
  }
182
177
 
183
- const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
184
-
185
178
  if (shouldPushHistory === false && changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
186
179
  return HISTORY_MERGE;
187
180
  } // A single node might have been marked as dirty, but not have changed
@@ -7,8 +7,8 @@
7
7
  'use strict';var e=require("@lexical/utils"),u=require("lexical");
8
8
  function v(b,a,m,k,p){if(null===b||0===m.size&&0===k.size&&!p)return 0;var f=a._selection,c=b._selection;if(p)return 1;if(!(u.$isRangeSelection(f)&&u.$isRangeSelection(c)&&c.isCollapsed()&&f.isCollapsed()))return 0;p=a._nodeMap;let d=[];for(let g of m)m=p.get(g),void 0!==m&&d.push(m);for(let [g,n]of k)n&&(k=p.get(g),void 0===k||u.$isRootNode(k)||d.push(k));if(0===d.length)return 0;if(1<d.length)return k=a._nodeMap,a=k.get(f.anchor.key),c=k.get(c.anchor.key),a&&c&&!b._nodeMap.has(a.__key)&&u.$isTextNode(a)&&
9
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 m=Date.now(),k=0;return(p,f,c,d,g,n)=>{let r=Date.now();if(n.has("historic"))return k=0,m=r,2;let q=v(p,f,d,g,b.isComposing()),t=(()=>{var l=n.has("history-push");if(!l&&n.has("history-merge"))return 0;if(null===p)return 1;var h=f._selection;const x=p._selection;if(!(0<d.size||0<g.size))return null===x&&null!==h?0:2;h=null===c||c.editor===b;return!1===l&&0!==q&&q===k&&r<m+a&&h||1===d.size&&(h=Array.from(d)[0],l=p._nodeMap.get(h),h=f._nodeMap.get(h),l=u.$isTextNode(l)&&u.$isTextNode(h)?
11
- l.__type===h.__type&&l.__text===h.__text&&l.__mode===h.__mode&&l.__detail===h.__detail&&l.__style===h.__style&&l.__format===h.__format&&l.__parent===h.__parent:!1,l)?0:1})();m=r;k=q;return t}}exports.createEmptyHistoryState=function(){return{current:null,redoStack:[],undoStack:[]}};
10
+ function w(b,a){let m=Date.now(),k=0;return(p,f,c,d,g,n)=>{let r=Date.now();if(n.has("historic"))return k=0,m=r,2;let q=v(p,f,d,g,b.isComposing()),t=(()=>{var l=null===c||c.editor===b,h=n.has("history-push");if(!h&&l&&n.has("history-merge"))return 0;if(null===p)return 1;const x=f._selection,y=p._selection;return 0<d.size||0<g.size?!1===h&&0!==q&&q===k&&r<m+a&&l||1===d.size&&(h=Array.from(d)[0],l=p._nodeMap.get(h),h=f._nodeMap.get(h),l=u.$isTextNode(l)&&u.$isTextNode(h)?l.__type===h.__type&&l.__text===
11
+ h.__text&&l.__mode===h.__mode&&l.__detail===h.__detail&&l.__style===h.__style&&l.__format===h.__format&&l.__parent===h.__parent:!1,l)?0:1:null===y&&null!==x?0:2})();m=r;k=q;return t}}exports.createEmptyHistoryState=function(){return{current:null,redoStack:[],undoStack:[]}};
12
12
  exports.registerHistory=function(b,a,m){let k=w(b,m);m=({editorState:c,prevEditorState:d,dirtyLeaves:g,dirtyElements:n,tags:r})=>{const q=a.current,t=a.redoStack,l=a.undoStack,h=null===q?null:q.editorState;if(null===q||c!==h){g=k(d,c,q,g,n,r);if(1===g)0!==t.length&&(a.redoStack=[]),null!==q&&(l.push({...q,undoSelection:d.read(u.$getSelection)}),b.dispatchCommand(u.CAN_UNDO_COMMAND,!0));else if(2===g)return;a.current={editor:b,editorState:c}}};let p=e.mergeRegister(b.registerCommand(u.UNDO_COMMAND,
13
13
  ()=>{let c=a.redoStack,d=a.undoStack;if(0!==d.length){let g=a.current,n=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=n||null;n&&n.editor.setEditorState(n.editorState.clone(n.undoSelection),{tag:"historic"})}return!0},u.COMMAND_PRIORITY_EDITOR),b.registerCommand(u.REDO_COMMAND,()=>{let c=a.redoStack;var d=a.undoStack;if(0!==c.length){let g=a.current;null!==g&&(d.push(g),b.dispatchCommand(u.CAN_UNDO_COMMAND,!0));
14
14
  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(m)),f=b.registerUpdateListener(m);return()=>
package/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /** @module @lexical/history */
1
2
  /**
2
3
  * Copyright (c) Meta Platforms, Inc. and affiliates.
3
4
  *
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "history"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.3.11",
11
+ "version": "0.4.0",
12
12
  "main": "LexicalHistory.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.3.11"
14
+ "lexical": "0.4.0"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.3.11"
17
+ "@lexical/utils": "0.4.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",