@lexical/history 0.9.2 → 0.11.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.
- package/LexicalHistory.dev.js +2 -3
- package/LexicalHistory.prod.js +7 -7
- package/index.d.ts +1 -2
- package/package.json +3 -3
package/LexicalHistory.dev.js
CHANGED
|
@@ -254,7 +254,7 @@ function undo(editor, historyState) {
|
|
|
254
254
|
historyState.current = historyStateEntry || null;
|
|
255
255
|
|
|
256
256
|
if (historyStateEntry) {
|
|
257
|
-
historyStateEntry.editor.setEditorState(historyStateEntry.editorState
|
|
257
|
+
historyStateEntry.editor.setEditorState(historyStateEntry.editorState, {
|
|
258
258
|
tag: 'historic'
|
|
259
259
|
});
|
|
260
260
|
}
|
|
@@ -305,8 +305,7 @@ function registerHistory(editor, historyState, delay) {
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
if (current !== null) {
|
|
308
|
-
undoStack.push({ ...current
|
|
309
|
-
undoSelection: prevEditorState.read(lexical.$getSelection)
|
|
308
|
+
undoStack.push({ ...current
|
|
310
309
|
});
|
|
311
310
|
editor.dispatchCommand(lexical.CAN_UNDO_COMMAND, true);
|
|
312
311
|
}
|
package/LexicalHistory.prod.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var c=require("@lexical/utils"),x=require("lexical");
|
|
8
|
-
function y(b,a,
|
|
8
|
+
function y(b,a,l,h,n){if(null===b||0===l.size&&0===h.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 m of l)l=n.get(m),void 0!==l&&e.push(l);for(let [m,p]of h)p&&(h=n.get(m),void 0===h||x.$isRootNode(h)||e.push(h));if(0===e.length)return 0;if(1<e.length)return h=a._nodeMap,a=h.get(f.anchor.key),d=h.get(d.anchor.key),a&&d&&!b._nodeMap.has(a.__key)&&x.$isTextNode(a)&&
|
|
9
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
|
|
11
|
-
x.$isRangeSelection(u)&&(w="element"===t.anchor.type&&"element"===t.focus.type&&"text"===u.anchor.type&&"text"===u.focus.type);
|
|
12
|
-
exports.registerHistory=function(b,a,
|
|
13
|
-
()=>{let d=a.redoStack,e=a.undoStack;if(0!==e.length){let
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
function z(b,a){let l=Date.now(),h=0;return(n,f,d,e,m,p)=>{let r=Date.now();if(p.has("historic"))return h=0,l=r,2;let q=y(n,f,e,m,b.isComposing()),v=(()=>{var k=null===d||d.editor===b,g=p.has("history-push");if(!g&&k&&p.has("history-merge"))return 0;if(null===n)return 1;var t=f._selection;if(!(0<e.size||0<m.size))return null!==t?0:2;if(!1===g&&0!==q&&q===h&&r<l+a&&k)return 0;if(1===e.size){{g=Array.from(e)[0];k=n._nodeMap.get(g);g=f._nodeMap.get(g);t=n._selection;let u=f._selection,w=!1;x.$isRangeSelection(t)&&
|
|
11
|
+
x.$isRangeSelection(u)&&(w="element"===t.anchor.type&&"element"===t.focus.type&&"text"===u.anchor.type&&"text"===u.focus.type);k=!w&&x.$isTextNode(k)&&x.$isTextNode(g)?k.__type===g.__type&&k.__text===g.__text&&k.__mode===g.__mode&&k.__detail===g.__detail&&k.__style===g.__style&&k.__format===g.__format&&k.__parent===g.__parent:!1}if(k)return 0}return 1})();l=r;h=q;return v}}exports.createEmptyHistoryState=function(){return{current:null,redoStack:[],undoStack:[]}};
|
|
12
|
+
exports.registerHistory=function(b,a,l){let h=z(b,l);l=({editorState:d,prevEditorState:e,dirtyLeaves:m,dirtyElements:p,tags:r})=>{const q=a.current,v=a.redoStack,k=a.undoStack,g=null===q?null:q.editorState;if(null===q||d!==g){e=h(e,d,q,m,p,r);if(1===e)0!==v.length&&(a.redoStack=[],b.dispatchCommand(x.CAN_REDO_COMMAND,!1)),null!==q&&(k.push({...q}),b.dispatchCommand(x.CAN_UNDO_COMMAND,!0));else if(2===e)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 m=a.current,p=e.pop();null!==m&&(d.push(m),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,{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 m=a.current;null!==m&&(e.push(m),b.dispatchCommand(x.CAN_UNDO_COMMAND,!0));e=d.pop();0===d.length&&
|
|
14
|
+
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),b.registerUpdateListener(l)),
|
|
15
|
+
f=b.registerUpdateListener(l);return()=>{n();f()}}
|
package/index.d.ts
CHANGED
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
import type { EditorState,
|
|
9
|
+
import type { EditorState, LexicalEditor } from 'lexical';
|
|
10
10
|
export declare type HistoryStateEntry = {
|
|
11
11
|
editor: LexicalEditor;
|
|
12
12
|
editorState: EditorState;
|
|
13
|
-
undoSelection?: RangeSelection | NodeSelection | GridSelection | null;
|
|
14
13
|
};
|
|
15
14
|
export declare type HistoryState = {
|
|
16
15
|
current: null | HistoryStateEntry;
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"history"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.11.0",
|
|
12
12
|
"main": "LexicalHistory.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.
|
|
14
|
+
"lexical": "0.11.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.
|
|
17
|
+
"@lexical/utils": "0.11.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|