@lexical/history 0.7.6 → 0.7.8

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.
@@ -128,7 +128,15 @@ function isTextNodeUnchanged(key, prevEditorState, nextEditorState) {
128
128
 
129
129
  const nextNode = nextEditorState._nodeMap.get(key);
130
130
 
131
- if (lexical.$isTextNode(prevNode) && lexical.$isTextNode(nextNode)) {
131
+ const prevSelection = prevEditorState._selection;
132
+ const nextSelection = nextEditorState._selection;
133
+ let isDeletingLine = false;
134
+
135
+ if (lexical.$isRangeSelection(prevSelection) && lexical.$isRangeSelection(nextSelection)) {
136
+ isDeletingLine = prevSelection.anchor.type === 'element' && prevSelection.focus.type === 'element' && nextSelection.anchor.type === 'text' && nextSelection.focus.type === 'text';
137
+ }
138
+
139
+ if (!isDeletingLine && lexical.$isTextNode(prevNode) && lexical.$isTextNode(nextNode)) {
132
140
  return prevNode.__type === nextNode.__type && prevNode.__text === nextNode.__text && prevNode.__mode === nextNode.__mode && prevNode.__detail === nextNode.__detail && prevNode.__style === nextNode.__style && prevNode.__format === nextNode.__format && prevNode.__parent === nextNode.__parent;
133
141
  }
134
142
 
@@ -4,12 +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
- 'use strict';var d=require("@lexical/utils"),u=require("lexical");
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 e=[];for(let g of m)m=p.get(g),void 0!==m&&e.push(m);for(let [g,n]of k)n&&(k=p.get(g),void 0===k||u.$isRootNode(k)||e.push(k));if(0===e.length)return 0;if(1<e.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
- 1===a.__text.length&&1===f.anchor.offset?2:0;a=e[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,e,g,n)=>{let r=Date.now();if(n.has("historic"))return k=0,m=r,2;let q=v(p,f,e,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<e.size||0<g.size?!1===h&&0!==q&&q===k&&r<m+a&&l||1===e.size&&(h=Array.from(e)[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
- exports.registerHistory=function(b,a,m){let k=w(b,m);m=({editorState:c,prevEditorState:e,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(e,c,q,g,n,r);if(1===g)0!==t.length&&(a.redoStack=[]),null!==q&&(l.push({...q,undoSelection:e.read(u.$getSelection)}),b.dispatchCommand(u.CAN_UNDO_COMMAND,!0));else if(2===g)return;a.current={editor:b,editorState:c}}};let p=d.mergeRegister(b.registerCommand(u.UNDO_COMMAND,
13
- ()=>{let c=a.redoStack,e=a.undoStack;if(0!==e.length){let g=a.current,n=e.pop();null!==g&&(c.push(g),b.dispatchCommand(u.CAN_REDO_COMMAND,!0));0===e.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 e=a.undoStack;if(0!==c.length){let g=a.current;null!==g&&(e.push(g),b.dispatchCommand(u.CAN_UNDO_COMMAND,!0));
14
- e=c.pop();0===c.length&&b.dispatchCommand(u.CAN_REDO_COMMAND,!1);a.current=e||null;e&&e.editor.setEditorState(e.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;b.dispatchCommand(u.CAN_REDO_COMMAND,!1);b.dispatchCommand(u.CAN_UNDO_COMMAND,!1);return!0},u.COMMAND_PRIORITY_EDITOR),
15
- b.registerUpdateListener(m)),f=b.registerUpdateListener(m);return()=>{p();f()}}
7
+ 'use strict';var c=require("@lexical/utils"),x=require("lexical");
8
+ function y(b,a,m,k,n){if(null===b||0===m.size&&0===k.size&&!n)return 0;var f=a._selection,d=b._selection;if(n)return 1;if(!(x.$isRangeSelection(f)&&x.$isRangeSelection(d)&&d.isCollapsed()&&f.isCollapsed()))return 0;n=a._nodeMap;let e=[];for(let g of m)m=n.get(g),void 0!==m&&e.push(m);for(let [g,p]of k)p&&(k=n.get(g),void 0===k||x.$isRootNode(k)||e.push(k));if(0===e.length)return 0;if(1<e.length)return k=a._nodeMap,a=k.get(f.anchor.key),d=k.get(d.anchor.key),a&&d&&!b._nodeMap.has(a.__key)&&x.$isTextNode(a)&&
9
+ 1===a.__text.length&&1===f.anchor.offset?2:0;a=e[0];b=b._nodeMap.get(a.__key);if(!x.$isTextNode(b)||!x.$isTextNode(a)||b.__mode!==a.__mode)return 0;b=b.__text;a=a.__text;if(b===a)return 0;f=f.anchor;d=d.anchor;if(f.key!==d.key||"text"!==f.type)return 0;f=f.offset;d=d.offset;b=a.length-b.length;return 1===b&&d===f-1?2:-1===b&&d===f+1?3:-1===b&&d===f?4:0}
10
+ function z(b,a){let m=Date.now(),k=0;return(n,f,d,e,g,p)=>{let r=Date.now();if(p.has("historic"))return k=0,m=r,2;let q=y(n,f,e,g,b.isComposing()),v=(()=>{var l=null===d||d.editor===b,h=p.has("history-push");if(!h&&l&&p.has("history-merge"))return 0;if(null===n)return 1;var t=f._selection,u=n._selection;if(!(0<e.size||0<g.size))return null===u&&null!==t?0:2;if(!1===h&&0!==q&&q===k&&r<m+a&&l)return 0;if(1===e.size){{h=Array.from(e)[0];l=n._nodeMap.get(h);h=f._nodeMap.get(h);t=n._selection;u=f._selection;
11
+ let w=!1;x.$isRangeSelection(t)&&x.$isRangeSelection(u)&&(w="element"===t.anchor.type&&"element"===t.focus.type&&"text"===u.anchor.type&&"text"===u.focus.type);l=!w&&x.$isTextNode(l)&&x.$isTextNode(h)?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}if(l)return 0}return 1})();m=r;k=q;return v}}exports.createEmptyHistoryState=function(){return{current:null,redoStack:[],undoStack:[]}};
12
+ exports.registerHistory=function(b,a,m){let k=z(b,m);m=({editorState:d,prevEditorState:e,dirtyLeaves:g,dirtyElements:p,tags:r})=>{const q=a.current,v=a.redoStack,l=a.undoStack,h=null===q?null:q.editorState;if(null===q||d!==h){g=k(e,d,q,g,p,r);if(1===g)0!==v.length&&(a.redoStack=[]),null!==q&&(l.push({...q,undoSelection:e.read(x.$getSelection)}),b.dispatchCommand(x.CAN_UNDO_COMMAND,!0));else if(2===g)return;a.current={editor:b,editorState:d}}};let n=c.mergeRegister(b.registerCommand(x.UNDO_COMMAND,
13
+ ()=>{let d=a.redoStack,e=a.undoStack;if(0!==e.length){let g=a.current,p=e.pop();null!==g&&(d.push(g),b.dispatchCommand(x.CAN_REDO_COMMAND,!0));0===e.length&&b.dispatchCommand(x.CAN_UNDO_COMMAND,!1);a.current=p||null;p&&p.editor.setEditorState(p.editorState.clone(p.undoSelection),{tag:"historic"})}return!0},x.COMMAND_PRIORITY_EDITOR),b.registerCommand(x.REDO_COMMAND,()=>{let d=a.redoStack;var e=a.undoStack;if(0!==d.length){let g=a.current;null!==g&&(e.push(g),b.dispatchCommand(x.CAN_UNDO_COMMAND,!0));
14
+ e=d.pop();0===d.length&&b.dispatchCommand(x.CAN_REDO_COMMAND,!1);a.current=e||null;e&&e.editor.setEditorState(e.editorState,{tag:"historic"})}return!0},x.COMMAND_PRIORITY_EDITOR),b.registerCommand(x.CLEAR_EDITOR_COMMAND,()=>{a.undoStack=[];a.redoStack=[];a.current=null;return!1},x.COMMAND_PRIORITY_EDITOR),b.registerCommand(x.CLEAR_HISTORY_COMMAND,()=>{a.undoStack=[];a.redoStack=[];a.current=null;b.dispatchCommand(x.CAN_REDO_COMMAND,!1);b.dispatchCommand(x.CAN_UNDO_COMMAND,!1);return!0},x.COMMAND_PRIORITY_EDITOR),
15
+ b.registerUpdateListener(m)),f=b.registerUpdateListener(m);return()=>{n();f()}}
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "history"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.7.6",
11
+ "version": "0.7.8",
12
12
  "main": "LexicalHistory.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.7.6"
14
+ "lexical": "0.7.8"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.7.6"
17
+ "@lexical/utils": "0.7.8"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",