@lexical/history 0.36.2-nightly.20250930.0 → 0.36.2
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.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/extension"),t=require("@lexical/utils"),n=require("lexical");
|
|
9
|
+
"use strict";var e=require("@lexical/extension"),t=require("@lexical/utils"),n=require("lexical");function r(e,t,r,o,i){if(null===e||0===r.size&&0===o.size&&!i)return 0;const s=t._selection,a=e._selection;if(i)return 1;if(!(n.$isRangeSelection(s)&&n.$isRangeSelection(a)&&a.isCollapsed()&&s.isCollapsed()))return 0;const c=function(e,t,r){const o=e._nodeMap,i=[];for(const e of t){const t=o.get(e);void 0!==t&&i.push(t)}for(const[e,t]of r){if(!t)continue;const r=o.get(e);void 0===r||n.$isRootNode(r)||i.push(r)}return i}(t,r,o);if(0===c.length)return 0;if(c.length>1){const r=t._nodeMap,o=r.get(s.anchor.key),i=r.get(a.anchor.key);return o&&i&&!e._nodeMap.has(o.__key)&&n.$isTextNode(o)&&1===o.__text.length&&1===s.anchor.offset?2:0}const d=c[0],u=e._nodeMap.get(d.__key);if(!n.$isTextNode(u)||!n.$isTextNode(d)||u.__mode!==d.__mode)return 0;const l=u.__text,_=d.__text;if(l===_)return 0;const f=s.anchor,p=a.anchor;if(f.key!==p.key||"text"!==f.type)return 0;const h=f.offset,O=p.offset,S=_.length-l.length;return 1===S&&O===h-1?2:-1===S&&O===h+1?3:-1===S&&O===h?4:0}function o(e,t){let o=Date.now(),i=0;return(s,a,c,d,u,l)=>{const _=Date.now();if(l.has(n.HISTORIC_TAG))return i=0,o=_,2;const f=r(s,a,d,u,e.isComposing()),p=(()=>{const r=null===c||c.editor===e,p=l.has(n.HISTORY_PUSH_TAG);if(!p&&r&&l.has(n.HISTORY_MERGE_TAG))return 0;if(null===s)return 1;const h=a._selection;if(!(d.size>0||u.size>0))return null!==h?0:2;const O="number"==typeof t?t:t.peek();if(!1===p&&0!==f&&f===i&&_<o+O&&r)return 0;if(1===d.size){if(function(e,t,r){const o=t._nodeMap.get(e),i=r._nodeMap.get(e),s=t._selection,a=r._selection;return!(n.$isRangeSelection(s)&&n.$isRangeSelection(a)&&"element"===s.anchor.type&&"element"===s.focus.type&&"text"===a.anchor.type&&"text"===a.focus.type||!n.$isTextNode(o)||!n.$isTextNode(i)||o.__parent!==i.__parent)&&JSON.stringify(t.read(()=>o.exportJSON()))===JSON.stringify(r.read(()=>i.exportJSON()))}(Array.from(d)[0],s,a))return 0}return 1})();return o=_,i=f,p}}function i(e){e.undoStack=[],e.redoStack=[],e.current=null}function s(e,r,s){const a=o(e,s),c=t.mergeRegister(e.registerCommand(n.UNDO_COMMAND,()=>(function(e,t){const r=t.redoStack,o=t.undoStack;if(0!==o.length){const i=t.current,s=o.pop();null!==i&&(r.push(i),e.dispatchCommand(n.CAN_REDO_COMMAND,!0)),0===o.length&&e.dispatchCommand(n.CAN_UNDO_COMMAND,!1),t.current=s||null,s&&s.editor.setEditorState(s.editorState,{tag:n.HISTORIC_TAG})}}(e,r),!0),n.COMMAND_PRIORITY_EDITOR),e.registerCommand(n.REDO_COMMAND,()=>(function(e,t){const r=t.redoStack,o=t.undoStack;if(0!==r.length){const i=t.current;null!==i&&(o.push(i),e.dispatchCommand(n.CAN_UNDO_COMMAND,!0));const s=r.pop();0===r.length&&e.dispatchCommand(n.CAN_REDO_COMMAND,!1),t.current=s||null,s&&s.editor.setEditorState(s.editorState,{tag:n.HISTORIC_TAG})}}(e,r),!0),n.COMMAND_PRIORITY_EDITOR),e.registerCommand(n.CLEAR_EDITOR_COMMAND,()=>(i(r),!1),n.COMMAND_PRIORITY_EDITOR),e.registerCommand(n.CLEAR_HISTORY_COMMAND,()=>(i(r),e.dispatchCommand(n.CAN_REDO_COMMAND,!1),e.dispatchCommand(n.CAN_UNDO_COMMAND,!1),!0),n.COMMAND_PRIORITY_EDITOR),e.registerUpdateListener(({editorState:t,prevEditorState:o,dirtyLeaves:i,dirtyElements:s,tags:c})=>{const d=r.current,u=r.redoStack,l=r.undoStack,_=null===d?null:d.editorState;if(null!==d&&t===_)return;const f=a(o,t,d,i,s,c);if(1===f)0!==u.length&&(r.redoStack=[],e.dispatchCommand(n.CAN_REDO_COMMAND,!1)),null!==d&&(l.push({...d}),e.dispatchCommand(n.CAN_UNDO_COMMAND,!0));else if(2===f)return;r.current={editor:e,editorState:t}}));return c}function a(){return{current:null,redoStack:[],undoStack:[]}}const c=n.defineExtension({build:(t,{delay:n,createInitialHistoryState:r,disabled:o})=>e.namedSignals({delay:n,disabled:o,historyState:r(t)}),config:n.safeCast({createInitialHistoryState:a,delay:300,disabled:"undefined"==typeof window}),name:"@lexical/history/History",register:(t,n,r)=>{const o=r.getOutput();return e.effect(()=>o.disabled.value?void 0:s(t,o.historyState.value,o.delay))}});const d=n.defineExtension({dependencies:[n.configExtension(c,{createInitialHistoryState:()=>{throw new Error("SharedHistory did not inherit parent history")},disabled:!0})],name:"@lexical/history/SharedHistory",register(t,n,r){const{output:o}=r.getDependency(c),i=function(t){return t?e.getPeerDependencyFromEditor(t,c.name):null}(t._parentEditor);if(!i)return()=>{};const s=i.output;return e.effect(()=>e.batch(()=>{o.delay.value=s.delay.value,o.historyState.value=s.historyState.value,o.disabled.value=s.disabled.value}))}});exports.HistoryExtension=c,exports.SharedHistoryExtension=d,exports.createEmptyHistoryState=a,exports.registerHistory=s;
|
package/LexicalHistory.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{namedSignals as t,effect as e,batch as n,getPeerDependencyFromEditor as r}from"@lexical/extension";import{mergeRegister as o}from"@lexical/utils";import{defineExtension as i,safeCast as a,configExtension as s,UNDO_COMMAND as c,COMMAND_PRIORITY_EDITOR as d,REDO_COMMAND as u,CLEAR_EDITOR_COMMAND as l,CLEAR_HISTORY_COMMAND as f,CAN_REDO_COMMAND as p,CAN_UNDO_COMMAND as h,HISTORIC_TAG as m,HISTORY_PUSH_TAG as y,HISTORY_MERGE_TAG as g,$isRangeSelection as S,$isTextNode as _,$isRootNode as k}from"lexical";
|
|
9
|
+
import{namedSignals as t,effect as e,batch as n,getPeerDependencyFromEditor as r}from"@lexical/extension";import{mergeRegister as o}from"@lexical/utils";import{defineExtension as i,safeCast as a,configExtension as s,UNDO_COMMAND as c,COMMAND_PRIORITY_EDITOR as d,REDO_COMMAND as u,CLEAR_EDITOR_COMMAND as l,CLEAR_HISTORY_COMMAND as f,CAN_REDO_COMMAND as p,CAN_UNDO_COMMAND as h,HISTORIC_TAG as m,HISTORY_PUSH_TAG as y,HISTORY_MERGE_TAG as g,$isRangeSelection as S,$isTextNode as _,$isRootNode as k}from"lexical";function x(t,e,n,r,o){if(null===t||0===n.size&&0===r.size&&!o)return 0;const i=e._selection,a=t._selection;if(o)return 1;if(!(S(i)&&S(a)&&a.isCollapsed()&&i.isCollapsed()))return 0;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||k(n)||o.push(n)}return o}(e,n,r);if(0===s.length)return 0;if(s.length>1){const n=e._nodeMap,r=n.get(i.anchor.key),o=n.get(a.anchor.key);return r&&o&&!t._nodeMap.has(r.__key)&&_(r)&&1===r.__text.length&&1===i.anchor.offset?2:0}const c=s[0],d=t._nodeMap.get(c.__key);if(!_(d)||!_(c)||d.__mode!==c.__mode)return 0;const u=d.__text,l=c.__text;if(u===l)return 0;const f=i.anchor,p=a.anchor;if(f.key!==p.key||"text"!==f.type)return 0;const h=f.offset,m=p.offset,y=l.length-u.length;return 1===y&&m===h-1?2:-1===y&&m===h+1?3:-1===y&&m===h?4:0}function C(t,e){let n=Date.now(),r=0;return(o,i,a,s,c,d)=>{const u=Date.now();if(d.has(m))return r=0,n=u,2;const l=x(o,i,s,c,t.isComposing()),f=(()=>{const f=null===a||a.editor===t,p=d.has(y);if(!p&&f&&d.has(g))return 0;if(null===o)return 1;const h=i._selection;if(!(s.size>0||c.size>0))return null!==h?0:2;const m="number"==typeof e?e:e.peek();if(!1===p&&0!==l&&l===r&&u<n+m&&f)return 0;if(1===s.size){if(function(t,e,n){const r=e._nodeMap.get(t),o=n._nodeMap.get(t),i=e._selection,a=n._selection;return!(S(i)&&S(a)&&"element"===i.anchor.type&&"element"===i.focus.type&&"text"===a.anchor.type&&"text"===a.focus.type||!_(r)||!_(o)||r.__parent!==o.__parent)&&JSON.stringify(e.read(()=>r.exportJSON()))===JSON.stringify(n.read(()=>o.exportJSON()))}(Array.from(s)[0],o,i))return 0}return 1})();return n=u,r=l,f}}function v(t){t.undoStack=[],t.redoStack=[],t.current=null}function b(t,e,n){const r=C(t,n),i=o(t.registerCommand(c,()=>(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(p,!0)),0===r.length&&t.dispatchCommand(h,!1),e.current=i||null,i&&i.editor.setEditorState(i.editorState,{tag:m})}}(t,e),!0),d),t.registerCommand(u,()=>(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(h,!0));const i=n.pop();0===n.length&&t.dispatchCommand(p,!1),e.current=i||null,i&&i.editor.setEditorState(i.editorState,{tag:m})}}(t,e),!0),d),t.registerCommand(l,()=>(v(e),!1),d),t.registerCommand(f,()=>(v(e),t.dispatchCommand(p,!1),t.dispatchCommand(h,!1),!0),d),t.registerUpdateListener(({editorState:n,prevEditorState:o,dirtyLeaves:i,dirtyElements:a,tags:s})=>{const c=e.current,d=e.redoStack,u=e.undoStack,l=null===c?null:c.editorState;if(null!==c&&n===l)return;const f=r(o,n,c,i,a,s);if(1===f)0!==d.length&&(e.redoStack=[],t.dispatchCommand(p,!1)),null!==c&&(u.push({...c}),t.dispatchCommand(h,!0));else if(2===f)return;e.current={editor:t,editorState:n}}));return i}function w(){return{current:null,redoStack:[],undoStack:[]}}const E=i({build:(e,{delay:n,createInitialHistoryState:r,disabled:o})=>t({delay:n,disabled:o,historyState:r(e)}),config:a({createInitialHistoryState:w,delay:300,disabled:"undefined"==typeof window}),name:"@lexical/history/History",register:(t,n,r)=>{const o=r.getOutput();return e(()=>o.disabled.value?void 0:b(t,o.historyState.value,o.delay))}});const H=i({dependencies:[s(E,{createInitialHistoryState:()=>{throw new Error("SharedHistory did not inherit parent history")},disabled:!0})],name:"@lexical/history/SharedHistory",register(t,o,i){const{output:a}=i.getDependency(E),s=function(t){return t?r(t,E.name):null}(t._parentEditor);if(!s)return()=>{};const c=s.output;return e(()=>n(()=>{a.delay.value=c.delay.value,a.historyState.value=c.historyState.value,a.disabled.value=c.disabled.value}))}});export{E as HistoryExtension,H as SharedHistoryExtension,w as createEmptyHistoryState,b as registerHistory};
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"history"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.36.2
|
|
11
|
+
"version": "0.36.2",
|
|
12
12
|
"main": "LexicalHistory.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/extension": "0.36.2
|
|
16
|
-
"@lexical/utils": "0.36.2
|
|
17
|
-
"lexical": "0.36.2
|
|
15
|
+
"@lexical/extension": "0.36.2",
|
|
16
|
+
"@lexical/utils": "0.36.2",
|
|
17
|
+
"lexical": "0.36.2"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|