@lexical/history 0.30.1-nightly.20250410.0 → 0.30.1-nightly.20250414.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
CHANGED
|
@@ -126,7 +126,7 @@ function createMergeActionGetter(editor, delay) {
|
|
|
126
126
|
|
|
127
127
|
// If applying changes from history stack there's no need
|
|
128
128
|
// to run history logic again, as history entries already calculated
|
|
129
|
-
if (tags.has(
|
|
129
|
+
if (tags.has(lexical.HISTORIC_TAG)) {
|
|
130
130
|
prevChangeType = OTHER;
|
|
131
131
|
prevChangeTime = changeTime;
|
|
132
132
|
return DISCARD_HISTORY_CANDIDATE;
|
|
@@ -134,8 +134,8 @@ function createMergeActionGetter(editor, delay) {
|
|
|
134
134
|
const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
|
|
135
135
|
const mergeAction = (() => {
|
|
136
136
|
const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
|
|
137
|
-
const shouldPushHistory = tags.has(
|
|
138
|
-
const shouldMergeHistory = !shouldPushHistory && isSameEditor && tags.has(
|
|
137
|
+
const shouldPushHistory = tags.has(lexical.HISTORY_PUSH_TAG);
|
|
138
|
+
const shouldMergeHistory = !shouldPushHistory && isSameEditor && tags.has(lexical.HISTORY_MERGE_TAG);
|
|
139
139
|
if (shouldMergeHistory) {
|
|
140
140
|
return HISTORY_MERGE;
|
|
141
141
|
}
|
|
@@ -185,7 +185,7 @@ function redo(editor, historyState) {
|
|
|
185
185
|
historyState.current = historyStateEntry || null;
|
|
186
186
|
if (historyStateEntry) {
|
|
187
187
|
historyStateEntry.editor.setEditorState(historyStateEntry.editorState, {
|
|
188
|
-
tag:
|
|
188
|
+
tag: lexical.HISTORIC_TAG
|
|
189
189
|
});
|
|
190
190
|
}
|
|
191
191
|
}
|
|
@@ -207,7 +207,7 @@ function undo(editor, historyState) {
|
|
|
207
207
|
historyState.current = historyStateEntry || null;
|
|
208
208
|
if (historyStateEntry) {
|
|
209
209
|
historyStateEntry.editor.setEditorState(historyStateEntry.editorState, {
|
|
210
|
-
tag:
|
|
210
|
+
tag: lexical.HISTORIC_TAG
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
213
|
}
|
package/LexicalHistory.dev.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { mergeRegister } from '@lexical/utils';
|
|
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';
|
|
10
|
+
import { UNDO_COMMAND, COMMAND_PRIORITY_EDITOR, REDO_COMMAND, CLEAR_EDITOR_COMMAND, CLEAR_HISTORY_COMMAND, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, HISTORIC_TAG, HISTORY_PUSH_TAG, HISTORY_MERGE_TAG, $isRangeSelection, $isTextNode, $isRootNode } from 'lexical';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -124,7 +124,7 @@ function createMergeActionGetter(editor, delay) {
|
|
|
124
124
|
|
|
125
125
|
// If applying changes from history stack there's no need
|
|
126
126
|
// to run history logic again, as history entries already calculated
|
|
127
|
-
if (tags.has(
|
|
127
|
+
if (tags.has(HISTORIC_TAG)) {
|
|
128
128
|
prevChangeType = OTHER;
|
|
129
129
|
prevChangeTime = changeTime;
|
|
130
130
|
return DISCARD_HISTORY_CANDIDATE;
|
|
@@ -132,8 +132,8 @@ function createMergeActionGetter(editor, delay) {
|
|
|
132
132
|
const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
|
|
133
133
|
const mergeAction = (() => {
|
|
134
134
|
const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
|
|
135
|
-
const shouldPushHistory = tags.has(
|
|
136
|
-
const shouldMergeHistory = !shouldPushHistory && isSameEditor && tags.has(
|
|
135
|
+
const shouldPushHistory = tags.has(HISTORY_PUSH_TAG);
|
|
136
|
+
const shouldMergeHistory = !shouldPushHistory && isSameEditor && tags.has(HISTORY_MERGE_TAG);
|
|
137
137
|
if (shouldMergeHistory) {
|
|
138
138
|
return HISTORY_MERGE;
|
|
139
139
|
}
|
|
@@ -183,7 +183,7 @@ function redo(editor, historyState) {
|
|
|
183
183
|
historyState.current = historyStateEntry || null;
|
|
184
184
|
if (historyStateEntry) {
|
|
185
185
|
historyStateEntry.editor.setEditorState(historyStateEntry.editorState, {
|
|
186
|
-
tag:
|
|
186
|
+
tag: HISTORIC_TAG
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
189
|
}
|
|
@@ -205,7 +205,7 @@ function undo(editor, historyState) {
|
|
|
205
205
|
historyState.current = historyStateEntry || null;
|
|
206
206
|
if (historyStateEntry) {
|
|
207
207
|
historyStateEntry.editor.setEditorState(historyStateEntry.editorState, {
|
|
208
|
-
tag:
|
|
208
|
+
tag: HISTORIC_TAG
|
|
209
209
|
});
|
|
210
210
|
}
|
|
211
211
|
}
|
package/LexicalHistory.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var t=require("@lexical/utils"),e=require("lexical");const n=0,r=1,o=2,i=0,s=1,c=2,a=3,u=4;function d(t,n,r,o,d){if(null===t||0===r.size&&0===o.size&&!d)return i;const
|
|
9
|
+
"use strict";var t=require("@lexical/utils"),e=require("lexical");const n=0,r=1,o=2,i=0,s=1,c=2,a=3,u=4;function d(t,n,r,o,d){if(null===t||0===r.size&&0===o.size&&!d)return i;const _=n._selection,l=t._selection;if(d)return s;if(!(e.$isRangeSelection(_)&&e.$isRangeSelection(l)&&l.isCollapsed()&&_.isCollapsed()))return i;const f=function(t,n,r){const o=t._nodeMap,i=[];for(const t of n){const e=o.get(t);void 0!==e&&i.push(e)}for(const[t,n]of r){if(!n)continue;const r=o.get(t);void 0===r||e.$isRootNode(r)||i.push(r)}return i}(n,r,o);if(0===f.length)return i;if(f.length>1){const r=n._nodeMap,o=r.get(_.anchor.key),s=r.get(l.anchor.key);return o&&s&&!t._nodeMap.has(o.__key)&&e.$isTextNode(o)&&1===o.__text.length&&1===_.anchor.offset?c:i}const O=f[0],C=t._nodeMap.get(O.__key);if(!e.$isTextNode(C)||!e.$isTextNode(O)||C.__mode!==O.__mode)return i;const p=C.__text,M=O.__text;if(p===M)return i;const N=_.anchor,g=l.anchor;if(N.key!==g.key||"text"!==N.type)return i;const S=N.offset,h=g.offset,m=M.length-p.length;return 1===m&&h===S-1?c:-1===m&&h===S+1?a:-1===m&&h===S?u:i}function _(t,s){let c=Date.now(),a=i;return(u,_,l,f,O,C)=>{const p=Date.now();if(C.has(e.HISTORIC_TAG))return a=i,c=p,o;const M=d(u,_,f,O,t.isComposing()),N=(()=>{const d=null===l||l.editor===t,N=C.has(e.HISTORY_PUSH_TAG);if(!N&&d&&C.has(e.HISTORY_MERGE_TAG))return n;if(null===u)return r;const g=_._selection;if(!(f.size>0||O.size>0))return null!==g?n:o;if(!1===N&&M!==i&&M===a&&p<c+s&&d)return n;if(1===f.size){if(function(t,n,r){const o=n._nodeMap.get(t),i=r._nodeMap.get(t),s=n._selection,c=r._selection;return!(e.$isRangeSelection(s)&&e.$isRangeSelection(c)&&"element"===s.anchor.type&&"element"===s.focus.type&&"text"===c.anchor.type&&"text"===c.focus.type||!e.$isTextNode(o)||!e.$isTextNode(i)||o.__parent!==i.__parent)&&JSON.stringify(n.read((()=>o.exportJSON())))===JSON.stringify(r.read((()=>i.exportJSON())))}(Array.from(f)[0],u,_))return n}return r})();return c=p,a=M,N}}function l(t){t.undoStack=[],t.redoStack=[],t.current=null}exports.createEmptyHistoryState=function(){return{current:null,redoStack:[],undoStack:[]}},exports.registerHistory=function(n,i,s){const c=_(n,s);return t.mergeRegister(n.registerCommand(e.UNDO_COMMAND,(()=>(function(t,n){const r=n.redoStack,o=n.undoStack;if(0!==o.length){const i=n.current,s=o.pop();null!==i&&(r.push(i),t.dispatchCommand(e.CAN_REDO_COMMAND,!0)),0===o.length&&t.dispatchCommand(e.CAN_UNDO_COMMAND,!1),n.current=s||null,s&&s.editor.setEditorState(s.editorState,{tag:e.HISTORIC_TAG})}}(n,i),!0)),e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.REDO_COMMAND,(()=>(function(t,n){const r=n.redoStack,o=n.undoStack;if(0!==r.length){const i=n.current;null!==i&&(o.push(i),t.dispatchCommand(e.CAN_UNDO_COMMAND,!0));const s=r.pop();0===r.length&&t.dispatchCommand(e.CAN_REDO_COMMAND,!1),n.current=s||null,s&&s.editor.setEditorState(s.editorState,{tag:e.HISTORIC_TAG})}}(n,i),!0)),e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.CLEAR_EDITOR_COMMAND,(()=>(l(i),!1)),e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.CLEAR_HISTORY_COMMAND,(()=>(l(i),n.dispatchCommand(e.CAN_REDO_COMMAND,!1),n.dispatchCommand(e.CAN_UNDO_COMMAND,!1),!0)),e.COMMAND_PRIORITY_EDITOR),n.registerUpdateListener((({editorState:t,prevEditorState:s,dirtyLeaves:a,dirtyElements:u,tags:d})=>{const _=i.current,l=i.redoStack,f=i.undoStack,O=null===_?null:_.editorState;if(null!==_&&t===O)return;const C=c(s,t,_,a,u,d);if(C===r)0!==l.length&&(i.redoStack=[],n.dispatchCommand(e.CAN_REDO_COMMAND,!1)),null!==_&&(f.push({..._}),n.dispatchCommand(e.CAN_UNDO_COMMAND,!0));else if(C===o)return;i.current={editor:n,editorState:t}})))};
|
package/LexicalHistory.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{mergeRegister as t}from"@lexical/utils";import{UNDO_COMMAND as e,COMMAND_PRIORITY_EDITOR as n,REDO_COMMAND as r,CLEAR_EDITOR_COMMAND as o,CLEAR_HISTORY_COMMAND as i,CAN_REDO_COMMAND as
|
|
9
|
+
import{mergeRegister as t}from"@lexical/utils";import{UNDO_COMMAND as e,COMMAND_PRIORITY_EDITOR as n,REDO_COMMAND as r,CLEAR_EDITOR_COMMAND as o,CLEAR_HISTORY_COMMAND as i,CAN_REDO_COMMAND as c,CAN_UNDO_COMMAND as s,HISTORIC_TAG as a,HISTORY_PUSH_TAG as u,HISTORY_MERGE_TAG as d,$isRangeSelection as l,$isTextNode as f,$isRootNode as p}from"lexical";const m=0,h=1,_=2,g=0,S=1,k=2,y=3,C=4;function x(t,e,n,r,o){if(null===t||0===n.size&&0===r.size&&!o)return g;const i=e._selection,c=t._selection;if(o)return S;if(!(l(i)&&l(c)&&c.isCollapsed()&&i.isCollapsed()))return g;const s=function(t,e,n){const r=t._nodeMap,o=[];for(const t of e){const e=r.get(t);void 0!==e&&o.push(e)}for(const[t,e]of n){if(!e)continue;const n=r.get(t);void 0===n||p(n)||o.push(n)}return o}(e,n,r);if(0===s.length)return g;if(s.length>1){const n=e._nodeMap,r=n.get(i.anchor.key),o=n.get(c.anchor.key);return r&&o&&!t._nodeMap.has(r.__key)&&f(r)&&1===r.__text.length&&1===i.anchor.offset?k:g}const a=s[0],u=t._nodeMap.get(a.__key);if(!f(u)||!f(a)||u.__mode!==a.__mode)return g;const d=u.__text,m=a.__text;if(d===m)return g;const h=i.anchor,_=c.anchor;if(h.key!==_.key||"text"!==h.type)return g;const x=h.offset,M=_.offset,z=m.length-d.length;return 1===z&&M===x-1?k:-1===z&&M===x+1?y:-1===z&&M===x?C:g}function M(t,e){let n=Date.now(),r=g;return(o,i,c,s,p,S)=>{const k=Date.now();if(S.has(a))return r=g,n=k,_;const y=x(o,i,s,p,t.isComposing()),C=(()=>{const a=null===c||c.editor===t,C=S.has(u);if(!C&&a&&S.has(d))return m;if(null===o)return h;const x=i._selection;if(!(s.size>0||p.size>0))return null!==x?m:_;if(!1===C&&y!==g&&y===r&&k<n+e&&a)return m;if(1===s.size){if(function(t,e,n){const r=e._nodeMap.get(t),o=n._nodeMap.get(t),i=e._selection,c=n._selection;return!(l(i)&&l(c)&&"element"===i.anchor.type&&"element"===i.focus.type&&"text"===c.anchor.type&&"text"===c.focus.type||!f(r)||!f(o)||r.__parent!==o.__parent)&&JSON.stringify(e.read((()=>r.exportJSON())))===JSON.stringify(n.read((()=>o.exportJSON())))}(Array.from(s)[0],o,i))return m}return h})();return n=k,r=y,C}}function z(t){t.undoStack=[],t.redoStack=[],t.current=null}function v(u,d,l){const f=M(u,l),p=t(u.registerCommand(e,(()=>(function(t,e){const n=e.redoStack,r=e.undoStack;if(0!==r.length){const o=e.current,i=r.pop();null!==o&&(n.push(o),t.dispatchCommand(c,!0)),0===r.length&&t.dispatchCommand(s,!1),e.current=i||null,i&&i.editor.setEditorState(i.editorState,{tag:a})}}(u,d),!0)),n),u.registerCommand(r,(()=>(function(t,e){const n=e.redoStack,r=e.undoStack;if(0!==n.length){const o=e.current;null!==o&&(r.push(o),t.dispatchCommand(s,!0));const i=n.pop();0===n.length&&t.dispatchCommand(c,!1),e.current=i||null,i&&i.editor.setEditorState(i.editorState,{tag:a})}}(u,d),!0)),n),u.registerCommand(o,(()=>(z(d),!1)),n),u.registerCommand(i,(()=>(z(d),u.dispatchCommand(c,!1),u.dispatchCommand(s,!1),!0)),n),u.registerUpdateListener((({editorState:t,prevEditorState:e,dirtyLeaves:n,dirtyElements:r,tags:o})=>{const i=d.current,a=d.redoStack,l=d.undoStack,p=null===i?null:i.editorState;if(null!==i&&t===p)return;const m=f(e,t,i,n,r,o);if(m===h)0!==a.length&&(d.redoStack=[],u.dispatchCommand(c,!1)),null!==i&&(l.push({...i}),u.dispatchCommand(s,!0));else if(m===_)return;d.current={editor:u,editorState:t}})));return p}function E(){return{current:null,redoStack:[],undoStack:[]}}export{E as createEmptyHistoryState,v as registerHistory};
|
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"history"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.30.1-nightly.
|
|
11
|
+
"version": "0.30.1-nightly.20250414.0",
|
|
12
12
|
"main": "LexicalHistory.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/utils": "0.30.1-nightly.
|
|
16
|
-
"lexical": "0.30.1-nightly.
|
|
15
|
+
"@lexical/utils": "0.30.1-nightly.20250414.0",
|
|
16
|
+
"lexical": "0.30.1-nightly.20250414.0"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|