@lexical/history 0.14.4 → 0.15.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 +5 -6
- package/LexicalHistory.dev.mjs +5 -6
- package/LexicalHistory.js +2 -0
- package/LexicalHistory.mjs +2 -0
- package/LexicalHistory.node.mjs +2 -0
- package/LexicalHistory.prod.js +10 -9
- package/LexicalHistory.prod.mjs +3 -1
- package/package.json +3 -3
package/LexicalHistory.dev.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict';
|
|
8
10
|
|
|
9
11
|
var utils = require('@lexical/utils');
|
|
@@ -16,6 +18,7 @@ var lexical = require('lexical');
|
|
|
16
18
|
* LICENSE file in the root directory of this source tree.
|
|
17
19
|
*
|
|
18
20
|
*/
|
|
21
|
+
|
|
19
22
|
const HISTORY_MERGE = 0;
|
|
20
23
|
const HISTORY_PUSH = 1;
|
|
21
24
|
const DISCARD_HISTORY_CANDIDATE = 2;
|
|
@@ -262,7 +265,7 @@ function registerHistory(editor, historyState, delay) {
|
|
|
262
265
|
editorState
|
|
263
266
|
};
|
|
264
267
|
};
|
|
265
|
-
const
|
|
268
|
+
const unregister = utils.mergeRegister(editor.registerCommand(lexical.UNDO_COMMAND, () => {
|
|
266
269
|
undo(editor, historyState);
|
|
267
270
|
return true;
|
|
268
271
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.REDO_COMMAND, () => {
|
|
@@ -277,11 +280,7 @@ function registerHistory(editor, historyState, delay) {
|
|
|
277
280
|
editor.dispatchCommand(lexical.CAN_UNDO_COMMAND, false);
|
|
278
281
|
return true;
|
|
279
282
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerUpdateListener(applyChange));
|
|
280
|
-
|
|
281
|
-
return () => {
|
|
282
|
-
unregisterCommandListener();
|
|
283
|
-
unregisterUpdateListener();
|
|
284
|
-
};
|
|
283
|
+
return unregister;
|
|
285
284
|
}
|
|
286
285
|
|
|
287
286
|
/**
|
package/LexicalHistory.dev.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import { mergeRegister } from '@lexical/utils';
|
|
8
10
|
import { UNDO_COMMAND, COMMAND_PRIORITY_EDITOR, REDO_COMMAND, CLEAR_EDITOR_COMMAND, CLEAR_HISTORY_COMMAND, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, $isRangeSelection, $isTextNode, $isRootNode } from 'lexical';
|
|
9
11
|
|
|
@@ -14,6 +16,7 @@ import { UNDO_COMMAND, COMMAND_PRIORITY_EDITOR, REDO_COMMAND, CLEAR_EDITOR_COMMA
|
|
|
14
16
|
* LICENSE file in the root directory of this source tree.
|
|
15
17
|
*
|
|
16
18
|
*/
|
|
19
|
+
|
|
17
20
|
const HISTORY_MERGE = 0;
|
|
18
21
|
const HISTORY_PUSH = 1;
|
|
19
22
|
const DISCARD_HISTORY_CANDIDATE = 2;
|
|
@@ -260,7 +263,7 @@ function registerHistory(editor, historyState, delay) {
|
|
|
260
263
|
editorState
|
|
261
264
|
};
|
|
262
265
|
};
|
|
263
|
-
const
|
|
266
|
+
const unregister = mergeRegister(editor.registerCommand(UNDO_COMMAND, () => {
|
|
264
267
|
undo(editor, historyState);
|
|
265
268
|
return true;
|
|
266
269
|
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(REDO_COMMAND, () => {
|
|
@@ -275,11 +278,7 @@ function registerHistory(editor, historyState, delay) {
|
|
|
275
278
|
editor.dispatchCommand(CAN_UNDO_COMMAND, false);
|
|
276
279
|
return true;
|
|
277
280
|
}, COMMAND_PRIORITY_EDITOR), editor.registerUpdateListener(applyChange));
|
|
278
|
-
|
|
279
|
-
return () => {
|
|
280
|
-
unregisterCommandListener();
|
|
281
|
-
unregisterUpdateListener();
|
|
282
|
-
};
|
|
281
|
+
return unregister;
|
|
283
282
|
}
|
|
284
283
|
|
|
285
284
|
/**
|
package/LexicalHistory.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict'
|
|
8
10
|
const LexicalHistory = process.env.NODE_ENV === 'development' ? require('./LexicalHistory.dev.js') : require('./LexicalHistory.prod.js');
|
|
9
11
|
module.exports = LexicalHistory;
|
package/LexicalHistory.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import * as modDev from './LexicalHistory.dev.mjs';
|
|
8
10
|
import * as modProd from './LexicalHistory.prod.mjs';
|
|
9
11
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
package/LexicalHistory.node.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalHistory.dev.mjs') : import('./LexicalHistory.prod.mjs'));
|
|
8
10
|
export const createEmptyHistoryState = mod.createEmptyHistoryState;
|
|
9
11
|
export const registerHistory = mod.registerHistory;
|
package/LexicalHistory.prod.js
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
()=>{let
|
|
14
|
-
b.dispatchCommand(x.CAN_REDO_COMMAND,!1);a.current=
|
|
15
|
-
|
|
8
|
+
|
|
9
|
+
'use strict';var d=require("@lexical/utils"),x=require("lexical");
|
|
10
|
+
function y(b,a,n,h,f){if(null===b||0===n.size&&0===h.size&&!f)return 0;var c=a._selection,e=b._selection;if(f)return 1;if(!(x.$isRangeSelection(c)&&x.$isRangeSelection(e)&&e.isCollapsed()&&c.isCollapsed()))return 0;f=a._nodeMap;let g=[];for(let p of n)n=f.get(p),void 0!==n&&g.push(n);for(let [p,m]of h)m&&(h=f.get(p),void 0===h||x.$isRootNode(h)||g.push(h));if(0===g.length)return 0;if(1<g.length)return h=a._nodeMap,a=h.get(c.anchor.key),e=h.get(e.anchor.key),a&&e&&!b._nodeMap.has(a.__key)&&x.$isTextNode(a)&&
|
|
11
|
+
1===a.__text.length&&1===c.anchor.offset?2:0;a=g[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;c=c.anchor;e=e.anchor;if(c.key!==e.key||"text"!==c.type)return 0;c=c.offset;e=e.offset;b=a.length-b.length;return 1===b&&e===c-1?2:-1===b&&e===c+1?3:-1===b&&e===c?4:0}
|
|
12
|
+
function z(b,a){let n=Date.now(),h=0;return(f,c,e,g,p,m)=>{let q=Date.now();if(m.has("historic"))return h=0,n=q,2;let r=y(f,c,g,p,b.isComposing()),v=(()=>{var l=null===e||e.editor===b,k=m.has("history-push");if(!k&&l&&m.has("history-merge"))return 0;if(null===f)return 1;var t=c._selection;if(!(0<g.size||0<p.size))return null!==t?0:2;if(!1===k&&0!==r&&r===h&&q<n+a&&l)return 0;if(1===g.size){{k=Array.from(g)[0];l=f._nodeMap.get(k);k=c._nodeMap.get(k);t=f._selection;let u=c._selection,w=!1;x.$isRangeSelection(t)&&
|
|
13
|
+
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(k)?l.__type===k.__type&&l.__text===k.__text&&l.__mode===k.__mode&&l.__detail===k.__detail&&l.__style===k.__style&&l.__format===k.__format&&l.__parent===k.__parent:!1}if(l)return 0}return 1})();n=q;h=r;return v}}exports.createEmptyHistoryState=function(){return{current:null,redoStack:[],undoStack:[]}};
|
|
14
|
+
exports.registerHistory=function(b,a,n){let h=z(b,n);return d.mergeRegister(b.registerCommand(x.UNDO_COMMAND,()=>{let f=a.redoStack,c=a.undoStack;if(0!==c.length){let e=a.current,g=c.pop();null!==e&&(f.push(e),b.dispatchCommand(x.CAN_REDO_COMMAND,!0));0===c.length&&b.dispatchCommand(x.CAN_UNDO_COMMAND,!1);a.current=g||null;g&&g.editor.setEditorState(g.editorState,{tag:"historic"})}return!0},x.COMMAND_PRIORITY_EDITOR),b.registerCommand(x.REDO_COMMAND,()=>{let f=a.redoStack;var c=a.undoStack;if(0!==
|
|
15
|
+
f.length){let e=a.current;null!==e&&(c.push(e),b.dispatchCommand(x.CAN_UNDO_COMMAND,!0));c=f.pop();0===f.length&&b.dispatchCommand(x.CAN_REDO_COMMAND,!1);a.current=c||null;c&&c.editor.setEditorState(c.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,
|
|
16
|
+
!1);b.dispatchCommand(x.CAN_UNDO_COMMAND,!1);return!0},x.COMMAND_PRIORITY_EDITOR),b.registerUpdateListener(({editorState:f,prevEditorState:c,dirtyLeaves:e,dirtyElements:g,tags:p})=>{const m=a.current,q=a.redoStack,r=a.undoStack,v=null===m?null:m.editorState;if(null===m||f!==v){c=h(c,f,m,e,g,p);if(1===c)0!==q.length&&(a.redoStack=[],b.dispatchCommand(x.CAN_REDO_COMMAND,!1)),null!==m&&(r.push({...m}),b.dispatchCommand(x.CAN_UNDO_COMMAND,!0));else if(2===c)return;a.current={editor:b,editorState:f}}}))}
|
package/LexicalHistory.prod.mjs
CHANGED
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
import{mergeRegister as t}from"@lexical/utils";import{UNDO_COMMAND as e,COMMAND_PRIORITY_EDITOR as n,REDO_COMMAND as o,CLEAR_EDITOR_COMMAND as r,CLEAR_HISTORY_COMMAND as i,CAN_REDO_COMMAND as s,CAN_UNDO_COMMAND as c,$isRangeSelection as a,$isTextNode as u,$isRootNode as d}from"lexical";const l=0,_=1,f=2,p=0,h=1,m=2,g=3,y=4;function S(t,e,n,o,r){if(null===t||0===n.size&&0===o.size&&!r)return p;const i=e._selection,s=t._selection;if(r)return h;if(!(a(i)&&a(s)&&s.isCollapsed()&&i.isCollapsed()))return p;const c=function(t,e,n){const o=t._nodeMap,r=[];for(const t of e){const e=o.get(t);void 0!==e&&r.push(e)}for(const[t,e]of n){if(!e)continue;const n=o.get(t);void 0===n||d(n)||r.push(n)}return r}(e,n,o);if(0===c.length)return p;if(c.length>1){const n=e._nodeMap,o=n.get(i.anchor.key),r=n.get(s.anchor.key);return o&&r&&!t._nodeMap.has(o.__key)&&u(o)&&1===o.__text.length&&1===i.anchor.offset?m:p}const l=c[0],_=t._nodeMap.get(l.__key);if(!u(_)||!u(l)||_.__mode!==l.__mode)return p;const f=_.__text,S=l.__text;if(f===S)return p;const k=i.anchor,C=s.anchor;if(k.key!==C.key||"text"!==k.type)return p;const x=k.offset,M=C.offset,z=S.length-f.length;return 1===z&&M===x-1?m:-1===z&&M===x+1?g:-1===z&&M===x?y:p}function k(t,e){let n=Date.now(),o=p;return(r,i,s,c,d,h)=>{const m=Date.now();if(h.has("historic"))return o=p,n=m,f;const g=S(r,i,c,d,t.isComposing()),y=(()=>{const y=null===s||s.editor===t,S=h.has("history-push");if(!S&&y&&h.has("history-merge"))return l;if(null===r)return _;const k=i._selection;if(!(c.size>0||d.size>0))return null!==k?l:f;if(!1===S&&g!==p&&g===o&&m<n+e&&y)return l;if(1===c.size){if(function(t,e,n){const o=e._nodeMap.get(t),r=n._nodeMap.get(t),i=e._selection,s=n._selection;let c=!1;return a(i)&&a(s)&&(c="element"===i.anchor.type&&"element"===i.focus.type&&"text"===s.anchor.type&&"text"===s.focus.type),!(c||!u(o)||!u(r))&&o.__type===r.__type&&o.__text===r.__text&&o.__mode===r.__mode&&o.__detail===r.__detail&&o.__style===r.__style&&o.__format===r.__format&&o.__parent===r.__parent}(Array.from(c)[0],r,i))return l}return _})();return n=m,o=g,y}}function C(t){t.undoStack=[],t.redoStack=[],t.current=null}function x(a,u,d){const l=k(a,d),p=t(a.registerCommand(e,(()=>(function(t,e){const n=e.redoStack,o=e.undoStack;if(0!==o.length){const r=e.current,i=o.pop();null!==r&&(n.push(r),t.dispatchCommand(s,!0)),0===o.length&&t.dispatchCommand(c,!1),e.current=i||null,i&&i.editor.setEditorState(i.editorState,{tag:"historic"})}}(a,u),!0)),n),a.registerCommand(o,(()=>(function(t,e){const n=e.redoStack,o=e.undoStack;if(0!==n.length){const r=e.current;null!==r&&(o.push(r),t.dispatchCommand(c,!0));const i=n.pop();0===n.length&&t.dispatchCommand(s,!1),e.current=i||null,i&&i.editor.setEditorState(i.editorState,{tag:"historic"})}}(a,u),!0)),n),a.registerCommand(r,(()=>(C(u),!1)),n),a.registerCommand(i,(()=>(C(u),a.dispatchCommand(s,!1),a.dispatchCommand(c,!1),!0)),n),a.registerUpdateListener((({editorState:t,prevEditorState:e,dirtyLeaves:n,dirtyElements:o,tags:r})=>{const i=u.current,d=u.redoStack,p=u.undoStack,h=null===i?null:i.editorState;if(null!==i&&t===h)return;const m=l(e,t,i,n,o,r);if(m===_)0!==d.length&&(u.redoStack=[],a.dispatchCommand(s,!1)),null!==i&&(p.push({...i}),a.dispatchCommand(c,!0));else if(m===f)return;u.current={editor:a,editorState:t}})));return p}function M(){return{current:null,redoStack:[],undoStack:[]}}export{M as createEmptyHistoryState,x as registerHistory};
|
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"history"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.15.0",
|
|
12
12
|
"main": "LexicalHistory.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/utils": "0.
|
|
16
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/utils": "0.15.0",
|
|
16
|
+
"lexical": "0.15.0"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|