@react-fabric/lexical 1.0.0-beta.6 → 1.0.0-beta.60

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.
Files changed (76) hide show
  1. package/{src/editor/Lexical.module.css → css/_lexical.css} +8 -4
  2. package/css/styles.css +24 -0
  3. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +62 -20
  4. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
  5. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +11 -11
  6. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +643 -245
  7. package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +1 -1
  8. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +29 -22
  9. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +13 -6
  10. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +1 -1
  11. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  12. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +242 -141
  13. package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +1 -1
  14. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +11 -10
  15. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +594 -255
  16. package/dist/cjs/node_modules/@lexical/list/LexicalList.js +1 -1
  17. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +23 -16
  18. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +102 -53
  19. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
  20. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
  21. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +275 -194
  22. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +5 -1
  23. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +28 -18
  24. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +2293 -878
  25. package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +1 -1
  26. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +53 -40
  27. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +471 -193
  28. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +13 -1
  29. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +47 -32
  30. package/dist/cjs/node_modules/prismjs/prism.js +1 -1
  31. package/dist/cjs/packages/lexical/src/components/StickyComponent.js +1 -1
  32. package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +30 -5
  33. package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +86 -83
  34. package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +25 -17
  35. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +62 -20
  36. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
  37. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
  38. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +637 -246
  39. package/dist/esm/node_modules/@lexical/code/LexicalCode.js +1 -1
  40. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +4 -4
  41. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +14 -7
  42. package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +1 -1
  43. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  44. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +244 -144
  45. package/dist/esm/node_modules/@lexical/link/LexicalLink.js +1 -1
  46. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +4 -4
  47. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +590 -257
  48. package/dist/esm/node_modules/@lexical/list/LexicalList.js +1 -1
  49. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +5 -4
  50. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +104 -55
  51. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
  52. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +4 -4
  53. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +267 -196
  54. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +4 -2
  55. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +4 -4
  56. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +2283 -881
  57. package/dist/esm/node_modules/@lexical/table/LexicalTable.js +1 -1
  58. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +4 -4
  59. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +457 -194
  60. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +8 -2
  61. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
  62. package/dist/esm/node_modules/prismjs/prism.js +1 -1
  63. package/dist/esm/packages/lexical/src/components/StickyComponent.js +1 -1
  64. package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +30 -5
  65. package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +88 -85
  66. package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +25 -17
  67. package/dist/types/editor/LexicalEditor.d.ts +25 -0
  68. package/dist/types/hooks/useFormatWatcher.d.ts +2 -2
  69. package/dist/types/nodes/StickyNode.d.ts +0 -1
  70. package/package.json +14 -13
  71. package/src/components/StickyComponent.tsx +2 -2
  72. package/src/editor/LexicalEditor.tsx +57 -26
  73. package/src/hooks/useFormatWatcher.ts +35 -31
  74. package/src/plugins/ToolbarPlugin.tsx +27 -17
  75. package/dist/cjs/editor/Lexical.module.css +0 -1
  76. package/dist/esm/editor/Lexical.module.css +0 -1
@@ -11,11 +11,17 @@ import * as LexicalUtils_prod from './LexicalUtils.prod.js';
11
11
  *
12
12
  */
13
13
 
14
- const mod = process.env.NODE_ENV === 'development' ? LexicalUtils_dev : LexicalUtils_prod;
14
+ const mod = process.env.NODE_ENV !== 'production' ? LexicalUtils_dev : LexicalUtils_prod;
15
+ const $descendantsMatching = mod.$descendantsMatching;
15
16
  const $findMatchingParent = mod.$findMatchingParent;
17
+ const $getAdjacentCaret = mod.$getAdjacentCaret;
16
18
  const $getNearestBlockElementAncestorOrThrow = mod.$getNearestBlockElementAncestorOrThrow;
17
19
  const $getNearestNodeOfType = mod.$getNearestNodeOfType;
20
+ const $insertFirst = mod.$insertFirst;
21
+ const $insertNodeToNearestRoot = mod.$insertNodeToNearestRoot;
22
+ const $unwrapAndFilterDescendants = mod.$unwrapAndFilterDescendants;
18
23
  const addClassNamesToElement = mod.addClassNamesToElement;
24
+ const calculateZoomLevel = mod.calculateZoomLevel;
19
25
  const isBlockDomNode = mod.isBlockDomNode;
20
26
  const isHTMLAnchorElement = mod.isHTMLAnchorElement;
21
27
  const isHTMLElement = mod.isHTMLElement;
@@ -23,4 +29,4 @@ const mergeRegister = mod.mergeRegister;
23
29
  const objectKlassEquals = mod.objectKlassEquals;
24
30
  const removeClassNamesFromElement = mod.removeClassNamesFromElement;
25
31
 
26
- export { $findMatchingParent, $getNearestBlockElementAncestorOrThrow, $getNearestNodeOfType, addClassNamesToElement, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, mergeRegister, objectKlassEquals, removeClassNamesFromElement };
32
+ export { $descendantsMatching, $findMatchingParent, $getAdjacentCaret, $getNearestBlockElementAncestorOrThrow, $getNearestNodeOfType, $insertFirst, $insertNodeToNearestRoot, $unwrapAndFilterDescendants, addClassNamesToElement, calculateZoomLevel, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, mergeRegister, objectKlassEquals, removeClassNamesFromElement };
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import { $getRoot, $isElementNode, $cloneWithProperties, $setSelection, $getSelection, $getPreviousSelection, $isRangeSelection, $isRootOrShadowRoot, $isTextNode, $splitNode, $createParagraphNode, TextNode } from 'lexical';
3
+ import { isHTMLElement, $getRoot, $isElementNode, $getChildCaret, $getSiblingCaret, $getAdjacentChildCaret, $getChildCaretOrSelf, makeStepwiseIterator, $isChildCaret, $cloneWithProperties, $setSelection, $getSelection, $getPreviousSelection, $isRangeSelection, $caretFromPoint, $createParagraphNode, $normalizeCaret, $setSelectionFromCaretRange, $getCollapsedCaretRange, $getCaretInDirection, $splitAtPointCaretNext, $isTextPointCaret, $isSiblingCaret, $rewindSiblingCaret, $getState, $setState, getDOMTextNode } from 'lexical';
4
4
  export { $splitNode, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, isInlineDomNode } from 'lexical';
5
5
  import { createRectsFromDOMRange } from '../selection/LexicalSelection.js';
6
6
 
@@ -12,6 +12,6 @@ import { createRectsFromDOMRange } from '../selection/LexicalSelection.js';
12
12
  *
13
13
  */
14
14
 
15
- function g(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var p=g((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const h="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,m=h&&"documentMode"in document?document.documentMode:null,v=h&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),y=h&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),w=!(!h||!("InputEvent"in window)||m)&&"getTargetRanges"in new window.InputEvent("input"),E=h&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),P=h&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,S=h&&/Android/.test(navigator.userAgent),x=h&&/^(?=.*Chrome).*/i.test(navigator.userAgent),N=h&&S&&x,A=h&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!x;function L(...e){const t=[];for(const n of e)if(n&&"string"==typeof n)for(const[e]of n.matchAll(/\S+/g))t.push(e);return t}function b(...e){return ()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0;}}function T(e){return `${e}px`}const M={attributes:!0,characterData:!0,childList:!0,subtree:!0};function C(e,t,n){let o=null,r=null,l=null,i=[];const s=document.createElement("div");function u(){null===o&&p(182),null===r&&p(183);const{left:l,top:u}=o.getBoundingClientRect(),c=r,f=createRectsFromDOMRange(e,t);s.isConnected||c.append(s);let a=!1;for(let e=0;e<f.length;e++){const t=f[e],n=i[e]||document.createElement("div"),o=n.style;"absolute"!==o.position&&(o.position="absolute",a=!0);const r=T(t.left-l);o.left!==r&&(o.left=r,a=!0);const c=T(t.top-u);o.top!==c&&(n.style.top=c,a=!0);const d=T(t.width);o.width!==d&&(n.style.width=d,a=!0);const g=T(t.height);o.height!==g&&(n.style.height=g,a=!0),n.parentNode!==s&&(s.append(n),a=!0),i[e]=n;}for(;i.length>f.length;)i.pop();a&&n(i);}function c(){r=null,o=null,null!==l&&l.disconnect(),l=null,s.remove();for(const e of i)e.remove();i=[];}const f=e.registerRootListener((function t(){const n=e.getRootElement();if(null===n)return c();const i=n.parentElement;if(!(i instanceof HTMLElement))return c();c(),o=n,r=i,l=new MutationObserver((n=>{const l=e.getRootElement(),i=l&&l.parentElement;if(l!==o||i!==r)return t();for(const e of n)if(!s.contains(e.target))return u()})),l.observe(i,M),u();}));return ()=>{f(),c();}}function B(o,r){let l=null,i=null,s=null,u=null,c=()=>{};function f(f){f.read((()=>{const f=$getSelection();if(!$isRangeSelection(f))return l=null,i=null,s=null,u=null,c(),void(c=()=>{});const{anchor:a,focus:d}=f,g=a.getNode(),h=g.getKey(),m=a.offset,v=d.getNode(),y=v.getKey(),w=d.offset,E=o.getElementByKey(h),P=o.getElementByKey(y),S=null===l||null===E||m!==i||h!==l.getKey()||g!==l&&(!(l instanceof TextNode)||g.updateDOM(l,E,o._config)),x=null===s||null===P||w!==u||y!==s.getKey()||v!==s&&(!(s instanceof TextNode)||v.updateDOM(s,P,o._config));if(S||x){const e=o.getElementByKey(a.getNode().getKey()),t=o.getElementByKey(d.getNode().getKey());if(null!==e&&null!==t&&"SPAN"===e.tagName&&"SPAN"===t.tagName){const n=document.createRange();let l,i,s,u;d.isBefore(a)?(l=t,i=d.offset,s=e,u=a.offset):(l=e,i=a.offset,s=t,u=d.offset);const f=l.firstChild;null===f&&p(181);const g=s.firstChild;null===g&&p(181),n.setStart(f,i),n.setEnd(g,u),c(),c=C(o,n,(e=>{for(const t of e){const e=t.style;"Highlight"!==e.background&&(e.background="Highlight"),"HighlightText"!==e.color&&(e.color="HighlightText"),"-1"!==e.zIndex&&(e.zIndex="-1"),"none"!==e.pointerEvents&&(e.pointerEvents="none"),e.marginTop!==T(-1.5)&&(e.marginTop=T(-1.5)),e.paddingTop!==T(4)&&(e.paddingTop=T(4)),e.paddingBottom!==T(0)&&(e.paddingBottom=T(0));}void 0!==r&&r(e);}));}}l=g,i=m,s=v,u=w;}));}return f(o.getEditorState()),b(o.registerUpdateListener((({editorState:e})=>f(e))),c,(()=>{c();}))}const _=w,K=h,O=S,R=N,I=v,D=A,H=x,z=y,k=P,F=E;function $(e,...t){const n=L(...t);n.length>0&&e.classList.add(...n);}function U(e,...t){const n=L(...t);n.length>0&&e.classList.remove(...n);}function W(e,t){for(const n of t)if(e.type.startsWith(n))return !0;return !1}function j(e,t){const n=e[Symbol.iterator]();return new Promise(((e,o)=>{const r=[],l=()=>{const{done:i,value:s}=n.next();if(i)return e(r);const u=new FileReader;u.addEventListener("error",o),u.addEventListener("load",(()=>{const e=u.result;"string"==typeof e&&r.push({file:s,result:e}),l();})),W(s,t)?u.readAsDataURL(s):l();};l();}))}function V(e,t){const n=[],l=(e||$getRoot()).getLatest(),i=t||$isElementNode(l)&&l.getLastDescendant()||l;let s=l,u=function(e){let t=e,n=0;for(;null!==(t=t.getParent());)n++;return n}(s);for(;null!==s&&!s.is(i);)if(n.push({depth:u,node:s}),$isElementNode(s)&&s.getChildrenSize()>0)s=s.getFirstChild(),u++;else {let e=null;for(;null===e&&null!==s;)e=s.getNextSibling(),null===e?(s=s.getParent(),u--):s=e;}return null!==s&&s.is(i)&&n.push({depth:u,node:s}),n}function q(e){let t=e;if($isElementNode(t)&&t.getChildrenSize()>0)t=t.getLastChild();else {let e=null;for(;null===e&&null!==t;)e=t.getPreviousSibling(),t=null===e?t.getParent():e;}return t}function G(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent();}return null}function J(e){const t=Q(e,(e=>$isElementNode(e)&&!e.isInline()));return $isElementNode(t)||p(4,e.__key),t}const Q=(e,t)=>{let n=e;for(;n!==$getRoot()&&null!=n;){if(t(n))return n;n=n.getParent();}return null};function X(e,t,n,o){const r=e=>e instanceof t;return e.registerNodeTransform(t,(e=>{const t=(e=>{const t=e.getChildren();for(let e=0;e<t.length;e++){const n=t[e];if(r(n))return null}let n=e,o=e;for(;null!==n;)if(o=n,n=n.getParent(),r(n))return {child:o,parent:n};return null})(e);if(null!==t){const{child:r,parent:l}=t;if(r.is(e)){o(l,e);const t=r.getNextSiblings(),i=t.length;if(l.insertAfter(r),0!==i){const e=n(l);r.insertAfter(e);for(let n=0;n<i;n++)e.append(t[n]);}l.canBeEmpty()||0!==l.getChildrenSize()||l.remove();}}}))}function Y(e,t){const n=new Map,o=e._pendingEditorState;for(const[e,o]of t._nodeMap)n.set(e,$cloneWithProperties(o));o&&(o._nodeMap=n),e._dirtyType=2;const r=t._selection;$setSelection(null===r?null:r.clone());}function Z(n){const r=$getSelection()||$getPreviousSelection();if($isRangeSelection(r)){const{focus:e}=r,t=e.getNode(),o=e.offset;if($isRootOrShadowRoot(t)){const e=t.getChildAtIndex(o);null==e?t.append(n):e.insertBefore(n),n.selectNext();}else {let e,r;$isTextNode(t)?(e=t.getParentOrThrow(),r=t.getIndexWithinParent(),o>0&&(r+=1,t.splitText(o))):(e=t,r=o);const[,l]=$splitNode(e,r);l.insertBefore(n),l.selectStart();}}else {if(null!=r){const e=r.getNodes();e[e.length-1].getTopLevelElementOrThrow().insertAfter(n);}else {$getRoot().append(n);}const e=$createParagraphNode();n.insertAfter(e),e.select();}return n.getLatest()}function ee(e,t){const n=t();return e.replace(n),n.append(e),n}function te(e,t){return null!==e&&Object.getPrototypeOf(e).constructor.name===t.name}function ne(e,t){const n=[];for(let o=0;o<e.length;o++){const r=t(e[o]);null!==r&&n.push(r);}return n}function oe(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t);}function re(e){if(z)return 1;let t=1;for(;e;)t*=Number(window.getComputedStyle(e).getPropertyValue("zoom")),e=e.parentElement;return t}function le(e){return null!==e._parentEditor}
15
+ function N(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const M="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,R=M&&"documentMode"in document?document.documentMode:null,T=M&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),B=M&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),_=!(!M||!("InputEvent"in window)||R)&&"getTargetRanges"in new window.InputEvent("input"),k=M&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),K=M&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,H=M&&/Android/.test(navigator.userAgent),O=M&&/^(?=.*Chrome).*/i.test(navigator.userAgent),$=M&&H&&O,D=M&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!O;function I(...t){const e=[];for(const n of t)if(n&&"string"==typeof n)for(const[t]of n.matchAll(/\S+/g))e.push(t);return e}function j(...t){return ()=>{for(let e=t.length-1;e>=0;e--)t[e]();t.length=0;}}function F(t){return `${t}px`}const U={attributes:!0,characterData:!0,childList:!0,subtree:!0};function z(e,n,o){let r=null,i=null,l=null,u=[];const s=document.createElement("div");function c(){null===r&&N(182),null===i&&N(183);const{left:t,top:l}=i.getBoundingClientRect(),c=createRectsFromDOMRange(e,n);var f,a;s.isConnected||(a=s,(f=i).insertBefore(a,f.firstChild));let d=!1;for(let e=0;e<c.length;e++){const n=c[e],o=u[e]||document.createElement("div"),r=o.style;"absolute"!==r.position&&(r.position="absolute",d=!0);const i=F(n.left-t);r.left!==i&&(r.left=i,d=!0);const f=F(n.top-l);r.top!==f&&(o.style.top=f,d=!0);const a=F(n.width);r.width!==a&&(o.style.width=a,d=!0);const g=F(n.height);r.height!==g&&(o.style.height=g,d=!0),o.parentNode!==s&&(s.append(o),d=!0),u[e]=o;}for(;u.length>c.length;)u.pop();d&&o(u);}function f(){i=null,r=null,null!==l&&l.disconnect(),l=null,s.remove();for(const t of u)t.remove();u=[];}s.style.position="relative";const a=e.registerRootListener((function n(){const o=e.getRootElement();if(null===o)return f();const u=o.parentElement;if(!isHTMLElement(u))return f();f(),r=o,i=u,l=new MutationObserver((t=>{const o=e.getRootElement(),l=o&&o.parentElement;if(o!==r||l!==i)return n();for(const e of t)if(!s.contains(e.target))return c()})),l.observe(u,U),c();}));return ()=>{a(),f();}}function V(t,e,n){if("text"!==t.type&&$isElementNode(e)){const o=e.getDOMSlot(n);return [o.element,o.getFirstChildOffset()+t.offset]}return [getDOMTextNode(n)||n,t.offset]}function W(t,o){let r=null,i=null,l=null,u=null,s=null,c=null,f=()=>{};function a(a){a.read((()=>{const a=$getSelection();if(!$isRangeSelection(a))return r=null,l=null,u=null,c=null,f(),void(f=()=>{});const[d,g]=function(t){const e=t.getStartEndPoints();return t.isBackward()?[e[1],e[0]]:e}(a),p=d.getNode(),m=p.getKey(),h=d.offset,v=g.getNode(),y=v.getKey(),w=g.offset,x=t.getElementByKey(m),E=t.getElementByKey(y),S=null===r||x!==i||h!==l||m!==r.getKey(),A=null===u||E!==s||w!==c||y!==u.getKey();if((S||A)&&null!==x&&null!==E){const e=function(t,e,n,o,r,i,l){const u=(t._window?t._window.document:document).createRange();return u.setStart(...V(e,n,o)),u.setEnd(...V(r,i,l)),u}(t,d,p,x,g,v,E);f(),f=z(t,e,(t=>{if(void 0===o)for(const e of t){const t=e.style;"Highlight"!==t.background&&(t.background="Highlight"),"HighlightText"!==t.color&&(t.color="HighlightText"),t.marginTop!==F(-1.5)&&(t.marginTop=F(-1.5)),t.paddingTop!==F(4)&&(t.paddingTop=F(4)),t.paddingBottom!==F(0)&&(t.paddingBottom=F(0));}else o(t);}));}r=p,i=x,l=h,u=v,s=E,c=w;}));}return a(t.getEditorState()),j(t.registerUpdateListener((({editorState:t})=>a(t))),(()=>{f();}))}function G(t){let e=null;const n=()=>{const n=getSelection(),o=n&&n.anchorNode,r=t.getRootElement();null!==o&&null!==r&&r.contains(o)?null!==e&&(e(),e=null):null===e&&(e=W(t));};return document.addEventListener("selectionchange",n),()=>{null!==e&&e(),document.removeEventListener("selectionchange",n);}}const q=_,J=M,Q=H,X=$,Y=T,Z=D,tt=O,et=B,nt=K,ot=k;function rt(t,...e){const n=I(...e);n.length>0&&t.classList.add(...n);}function it(t,...e){const n=I(...e);n.length>0&&t.classList.remove(...n);}function lt(t,e){for(const n of e)if(t.type.startsWith(n))return !0;return !1}function ut(t,e){const n=t[Symbol.iterator]();return new Promise(((t,o)=>{const r=[],i=()=>{const{done:l,value:u}=n.next();if(l)return t(r);const s=new FileReader;s.addEventListener("error",o),s.addEventListener("load",(()=>{const t=s.result;"string"==typeof t&&r.push({file:u,result:t}),i();})),lt(u,e)?s.readAsDataURL(u):i();};i();}))}function st(t,e){return Array.from(at(t,e))}function ct(t){return t?t.getAdjacentCaret():null}function ft(t,e){return Array.from(ht(t,e))}function at(t,e){return dt("next",t,e)}function dt(t,e,n){const r=$getRoot(),d=e||r,g=$isElementNode(d)?$getChildCaret(d,t):$getSiblingCaret(d,t),p=pt(d),m=n?$getAdjacentChildCaret($getChildCaretOrSelf($getSiblingCaret(n,t))):function(t,e){const n=$t($getSiblingCaret(t,e));return n&&n[0]}(d,t);let h=p;return makeStepwiseIterator({hasNext:t=>null!==t,initial:g,map:t=>({depth:h,node:t.origin}),step:t=>{if(t.isSameNodeCaret(m))return null;$isChildCaret(t)&&h++;const e=$t(t);return !e||e[0].isSameNodeCaret(m)?null:(h+=e[1],e[0])}})}function gt(t){const e=$t($getSiblingCaret(t,"next"));return e&&[e[0].origin,e[1]]}function pt(t){let e=-1;for(let n=t;null!==n;n=n.getParent())e++;return e}function mt(t){const e=$t($getChildCaretOrSelf($getSiblingCaret(t,"previous")),"root");return e&&e[0].origin}function ht(t,e){return dt("previous",t,e)}function vt(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent();}return null}function yt(t){const e=wt(t,(t=>$isElementNode(t)&&!t.isInline()));return $isElementNode(e)||N(4,t.__key),e}const wt=(t,e)=>{let n=t;for(;n!==$getRoot()&&null!=n;){if(e(n))return n;n=n.getParent();}return null};function xt(t,e,n,o){const r=t=>t instanceof e;return t.registerNodeTransform(e,(t=>{const e=(t=>{const e=t.getChildren();for(let t=0;t<e.length;t++){const n=e[t];if(r(n))return null}let n=t,o=t;for(;null!==n;)if(o=n,n=n.getParent(),r(n))return {child:o,parent:n};return null})(t);if(null!==e){const{child:r,parent:i}=e;if(r.is(t)){o(i,t);const e=r.getNextSiblings(),l=e.length;if(i.insertAfter(r),0!==l){const t=n(i);r.insertAfter(t);for(let n=0;n<l;n++)t.append(e[n]);}i.canBeEmpty()||0!==i.getChildrenSize()||i.remove();}}}))}function Et(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,$cloneWithProperties(o));o&&(o._nodeMap=n),t._dirtyType=2;const r=e._selection;$setSelection(null===r?null:r.clone());}function St(t){const o=$getSelection()||$getPreviousSelection();let r;if($isRangeSelection(o))r=$caretFromPoint(o.focus,"next");else {if(null!=o){const t=o.getNodes(),e=t[t.length-1];e&&(r=$getSiblingCaret(e,"next"));}r=r||$getChildCaret($getRoot(),"previous").getFlipped().insert($createParagraphNode());}const c=At(t,r),f=$getAdjacentChildCaret(c),d=$isChildCaret(f)?$normalizeCaret(f):c;return $setSelectionFromCaretRange($getCollapsedCaretRange(d)),t.getLatest()}function At(t,e,n){let o=$getCaretInDirection(e,"next");for(let t=o;t;t=$splitAtPointCaretNext(t,n))o=t;return $isTextPointCaret(o)&&N(283),o.insert(t.isInline()?$createParagraphNode().append(t):t),$getCaretInDirection($getSiblingCaret(t.getLatest(),"next"),e.direction)}function Ct(t,e){const n=e();return t.replace(n),n.append(t),n}function Lt(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function Pt(t,e){const n=[];for(let o=0;o<t.length;o++){const r=e(t[o]);null!==r&&n.push(r);}return n}function bt(t,e){$getChildCaret(t,"next").insert(e);}let Nt=!(et||!J)&&void 0;function Mt(t){let e=1;if(function(){if(void 0===Nt){const t=document.createElement("div");t.style.cssText="position: absolute; opacity: 0; width: 100px; left: -1000px;",document.body.appendChild(t);const e=t.getBoundingClientRect();t.style.setProperty("zoom","2"),Nt=t.getBoundingClientRect().width===e.width,document.body.removeChild(t);}return Nt}())for(;t;)e*=Number(window.getComputedStyle(t).getPropertyValue("zoom")),t=t.parentElement;return e}function Rt(t){return null!==t._parentEditor}function Tt(t,e){return Bt(t,e,null)}function Bt(t,e,n){let r=!1;for(const i of Kt(t))e(i)?null!==n&&n(i):(r=!0,$isElementNode(i)&&Bt(i,e,n||(t=>i.insertAfter(t))),i.remove());return r}function _t(t,e){const n=[],r=Array.from(t).reverse();for(let t=r.pop();void 0!==t;t=r.pop())if(e(t))n.push(t);else if($isElementNode(t))for(const e of Kt(t))r.push(e);return n}function kt(t){return Ht($getChildCaret(t,"next"))}function Kt(t){return Ht($getChildCaret(t,"previous"))}function Ht(t){return makeStepwiseIterator({hasNext:$isSiblingCaret,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function Ot(t){$rewindSiblingCaret($getSiblingCaret(t,"next")).splice(1,t.getChildren());}function $t(t,e="root"){let n=0,o=t,r=$getAdjacentChildCaret(o);for(;null===r;){if(n--,r=o.getParentCaret(e),!r)return null;o=r,r=$getAdjacentChildCaret(o);}return r&&[r,n]}function Dt(t){const e=e=>$getState(e,t),n=(e,n)=>$setState(e,t,n);return {$get:e,$set:n,accessors:[e,n],makeGetterMethod:()=>function(){return e(this)},makeSetterMethod:()=>function(t){return n(this,t)},stateConfig:t}}
16
16
 
17
- export { V as $dfs, ne as $filter, Q as $findMatchingParent, J as $getNearestBlockElementAncestorOrThrow, G as $getNearestNodeOfType, q as $getNextRightPreorderNode, oe as $insertFirst, Z as $insertNodeToNearestRoot, le as $isEditorIsNestedEditor, Y as $restoreEditorState, ee as $wrapNodeInElement, _ as CAN_USE_BEFORE_INPUT, K as CAN_USE_DOM, O as IS_ANDROID, R as IS_ANDROID_CHROME, I as IS_APPLE, D as IS_APPLE_WEBKIT, H as IS_CHROME, z as IS_FIREFOX, k as IS_IOS, F as IS_SAFARI, $ as addClassNamesToElement, re as calculateZoomLevel, W as isMimeType, B as markSelection, j as mediaFileReader, b as mergeRegister, te as objectKlassEquals, C as positionNodeOnRange, X as registerNestedElementResolver, U as removeClassNamesFromElement };
17
+ export { _t as $descendantsMatching, st as $dfs, at as $dfsIterator, Pt as $filter, wt as $findMatchingParent, kt as $firstToLastIterator, ct as $getAdjacentCaret, $t as $getAdjacentSiblingOrParentSiblingCaret, pt as $getDepth, yt as $getNearestBlockElementAncestorOrThrow, vt as $getNearestNodeOfType, mt as $getNextRightPreorderNode, gt as $getNextSiblingOrParentSibling, bt as $insertFirst, St as $insertNodeToNearestRoot, At as $insertNodeToNearestRootAtCaret, Rt as $isEditorIsNestedEditor, Kt as $lastToFirstIterator, Et as $restoreEditorState, ft as $reverseDfs, ht as $reverseDfsIterator, Tt as $unwrapAndFilterDescendants, Ot as $unwrapNode, Ct as $wrapNodeInElement, q as CAN_USE_BEFORE_INPUT, J as CAN_USE_DOM, Q as IS_ANDROID, X as IS_ANDROID_CHROME, Y as IS_APPLE, Z as IS_APPLE_WEBKIT, tt as IS_CHROME, et as IS_FIREFOX, nt as IS_IOS, ot as IS_SAFARI, rt as addClassNamesToElement, Mt as calculateZoomLevel, lt as isMimeType, Dt as makeStateWrapper, W as markSelection, ut as mediaFileReader, j as mergeRegister, Lt as objectKlassEquals, z as positionNodeOnRange, xt as registerNestedElementResolver, it as removeClassNamesFromElement, G as selectionAlwaysOnDisplay };
@@ -231,7 +231,7 @@ import { __module as prism } from '../../_virtual/prism.js';
231
231
  if (typeof document === 'undefined') {
232
232
  return null;
233
233
  }
234
- if ('currentScript' in document && 1 < 2 /* hack to trip TS' flow analysis */) {
234
+ if (document.currentScript && document.currentScript.tagName === 'SCRIPT' && 1 < 2 /* hack to trip TS' flow analysis */) {
235
235
  return /** @type {any} */ (document.currentScript);
236
236
  }
237
237
 
@@ -4,7 +4,7 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
4
  import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin';
5
5
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
6
6
  import { ContentEditable } from '@lexical/react/LexicalContentEditable';
7
- import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
7
+ import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
8
8
  import { LexicalNestedComposer } from '@lexical/react/LexicalNestedComposer';
9
9
  import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
10
10
  import { mdiFormatColorFill, mdiClose } from '../../../../node_modules/@mdi/js/mdi.js';
@@ -21,18 +21,42 @@ import { useRef, useState, useCallback, useEffect, useMemo } from 'react';
21
21
  import { StickyNode } from '../nodes/StickyNode.js';
22
22
  import { DraggableBlockPlugin } from '../plugins/DraggableBlockPlugin.js';
23
23
  import { StickyPlugin } from '../plugins/StickyPlugin.js';
24
- import classes from './Lexical.module.css';
25
- import { LexicalTheme } from './theme.js';
26
24
  import { ToolbarPlugin } from '../plugins/ToolbarPlugin.js';
25
+ import { LexicalTheme } from './theme.js';
27
26
  import { jsxs, jsx } from 'react/jsx-runtime';
28
27
 
28
+ /**
29
+ * LexicalEditor component is a rich text editor built using Lexical.
30
+ * It supports various features such as code highlighting, lists, tables, and sticky notes.
31
+ * It provides a customizable toolbar and handles editor state changes.
32
+ * It also supports drag-and-drop functionality for blocks.
33
+ * It can be used in both read-only and editable modes, and supports publishing mode for exporting content.
34
+ * It uses a custom theme and provides error handling for Lexical updates.
35
+ *
36
+ * @param {EditorProps} props - The properties for the LexicalEditor component.
37
+ * @returns {JSX.Element} The rendered LexicalEditor component.
38
+ *
39
+ * @example
40
+ * ```jsx
41
+ * <LexicalEditor
42
+ * value={initialValue}
43
+ * readOnly={false}
44
+ * publishMode={false}
45
+ * onChange={(value) => console.log("Editor value changed:", value)}
46
+ * onDirty={(isDirty) => console.log("Editor is dirty:", isDirty)}
47
+ * />
48
+ * ```
49
+ *
50
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/lexical-playground--playground}
51
+ * @see {@link https://lexical.dev/docs/}
52
+ */
29
53
  var LexicalEditor = function LexicalEditor(_ref) {
30
54
  var value = _ref.value,
31
55
  readOnly = _ref.readOnly,
32
56
  publishMode = _ref.publishMode,
33
57
  onChange = _ref.onChange,
34
58
  onDirty = _ref.onDirty;
35
- var editorRef = useRef();
59
+ var editorRef = useRef(null);
36
60
  var _useState = useState(null),
37
61
  _useState2 = _slicedToArray(_useState, 2),
38
62
  editorContainer = _useState2[0],
@@ -108,7 +132,7 @@ var LexicalEditor = function LexicalEditor(_ref) {
108
132
  return !publishMode ? /*#__PURE__*/jsxs("div", {
109
133
  className: "lexical-scroller area-content overflow-auto",
110
134
  children: [/*#__PURE__*/jsx("div", {
111
- className: classNames(classes.lexicalToolbar, "sticky top-0 z-1"),
135
+ className: classNames("fabric-lexicalToolbar", "sticky top-0 z-1"),
112
136
  children: /*#__PURE__*/jsx(Header, {
113
137
  className: "bg-base",
114
138
  children: /*#__PURE__*/jsx(ToolbarPlugin, {})
@@ -124,7 +148,7 @@ var LexicalEditor = function LexicalEditor(_ref) {
124
148
  colorScheme: "light",
125
149
  children: /*#__PURE__*/jsxs("div", {
126
150
  role: "none",
127
- className: classNames(classes.lexicalEditor, "lexical-container relative bg-white min-h-full mx-auto shadow-md print:shadow-none"),
151
+ className: classNames("fabric-lexicalEditor", "lexical-container relative bg-white min-h-full mx-auto shadow-md print:shadow-none"),
128
152
  onDragOver: function onDragOver(e) {
129
153
  return e.stopPropagation();
130
154
  },
@@ -134,6 +158,7 @@ var LexicalEditor = function LexicalEditor(_ref) {
134
158
  ref: setEditorContainer,
135
159
  children: [/*#__PURE__*/jsx(RichTextPlugin, {
136
160
  contentEditable: /*#__PURE__*/jsx(ContentEditable, {
161
+ readOnly: !!readOnly || publishMode,
137
162
  className: "lexical-editor px-[2cm] py-[1cm] min-h-screen"
138
163
  }),
139
164
  placeholder: /*#__PURE__*/jsx("div", {
@@ -11,8 +11,9 @@ import { $isHeadingNode, $createQuoteNode, $createHeadingNode, $isQuoteNode } fr
11
11
  import { $isParentElementRTL, $getSelectionStyleValueForProperty, $patchStyleText, $setBlocksType, $isAtNodeEnd } from '../../../../node_modules/@lexical/selection/LexicalSelection.js';
12
12
  import { $isTableNode } from '../../../../node_modules/@lexical/table/LexicalTable.js';
13
13
  import { $findMatchingParent, $getNearestNodeOfType, mergeRegister, $getNearestBlockElementAncestorOrThrow } from '../../../../node_modules/@lexical/utils/LexicalUtils.js';
14
- import { $getSelection, $isRangeSelection, $isRootOrShadowRoot, FOCUS_COMMAND, COMMAND_PRIORITY_CRITICAL, SELECTION_CHANGE_COMMAND, CAN_UNDO_COMMAND, CAN_REDO_COMMAND, $createParagraphNode, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, $isTextNode } from 'lexical';
15
- import { useTransition, useState, useCallback, useEffect } from 'react';
14
+ import { isNil } from '@react-fabric/utilities';
15
+ import { $getSelection, $isRangeSelection, $isRootOrShadowRoot, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, CAN_UNDO_COMMAND, CAN_REDO_COMMAND, $setSelection, $createParagraphNode, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, $isTextNode } from 'lexical';
16
+ import { useState, useCallback, useEffect } from 'react';
16
17
 
17
18
  var blockTypeToBlockName = {
18
19
  bullet: "Bulleted List",
@@ -44,9 +45,6 @@ function getSelectedNode(selection) {
44
45
  }
45
46
  }
46
47
  var useFormatWatcher = function useFormatWatcher() {
47
- var _useTransition = useTransition(),
48
- _useTransition2 = _slicedToArray(_useTransition, 2),
49
- startTransition = _useTransition2[1];
50
48
  var _useLexicalComposerCo = useLexicalComposerContext(),
51
49
  _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
52
50
  editor = _useLexicalComposerCo2[0];
@@ -54,88 +52,92 @@ var useFormatWatcher = function useFormatWatcher() {
54
52
  _useState2 = _slicedToArray(_useState, 2),
55
53
  activeEditor = _useState2[0],
56
54
  setActiveEditor = _useState2[1];
57
- var _useState3 = useState("paragraph"),
55
+ var _useState3 = useState(),
58
56
  _useState4 = _slicedToArray(_useState3, 2),
59
- blockType = _useState4[0],
60
- setBlockType = _useState4[1];
61
- var _useState5 = useState("root"),
57
+ currentSelection = _useState4[0],
58
+ setCurrentSelection = _useState4[1];
59
+ var _useState5 = useState("paragraph"),
62
60
  _useState6 = _slicedToArray(_useState5, 2),
63
- rootType = _useState6[0],
64
- setRootType = _useState6[1];
65
- var _useState7 = useState(null),
61
+ blockType = _useState6[0],
62
+ setBlockType = _useState6[1];
63
+ var _useState7 = useState("root"),
66
64
  _useState8 = _slicedToArray(_useState7, 2),
67
- selectedElementKey = _useState8[0],
68
- setSelectedElementKey = _useState8[1];
69
- var _useState9 = useState("16"),
65
+ rootType = _useState8[0],
66
+ setRootType = _useState8[1];
67
+ var _useState9 = useState(null),
70
68
  _useState10 = _slicedToArray(_useState9, 2),
71
- fontSize = _useState10[0],
72
- setFontSize = _useState10[1];
73
- var _useState11 = useState("#000"),
69
+ selectedElementKey = _useState10[0],
70
+ setSelectedElementKey = _useState10[1];
71
+ var _useState11 = useState("16"),
74
72
  _useState12 = _slicedToArray(_useState11, 2),
75
- fontColor = _useState12[0],
76
- setFontColor = _useState12[1];
77
- var _useState13 = useState("#fff"),
73
+ fontSize = _useState12[0],
74
+ setFontSize = _useState12[1];
75
+ var _useState13 = useState("#000"),
78
76
  _useState14 = _slicedToArray(_useState13, 2),
79
- bgColor = _useState14[0],
80
- setBgColor = _useState14[1];
81
- var _useState15 = useState("Arial"),
77
+ fontColor = _useState14[0],
78
+ setFontColor = _useState14[1];
79
+ var _useState15 = useState("#fff"),
82
80
  _useState16 = _slicedToArray(_useState15, 2),
83
- fontFamily = _useState16[0],
84
- setFontFamily = _useState16[1];
85
- var _useState17 = useState(false),
81
+ bgColor = _useState16[0],
82
+ setBgColor = _useState16[1];
83
+ var _useState17 = useState("Arial"),
86
84
  _useState18 = _slicedToArray(_useState17, 2),
87
- isLink = _useState18[0],
88
- setIsLink = _useState18[1];
85
+ fontFamily = _useState18[0],
86
+ setFontFamily = _useState18[1];
89
87
  var _useState19 = useState(false),
90
88
  _useState20 = _slicedToArray(_useState19, 2),
91
- isBold = _useState20[0],
92
- setIsBold = _useState20[1];
89
+ isLink = _useState20[0],
90
+ setIsLink = _useState20[1];
93
91
  var _useState21 = useState(false),
94
92
  _useState22 = _slicedToArray(_useState21, 2),
95
- isItalic = _useState22[0],
96
- setIsItalic = _useState22[1];
93
+ isBold = _useState22[0],
94
+ setIsBold = _useState22[1];
97
95
  var _useState23 = useState(false),
98
96
  _useState24 = _slicedToArray(_useState23, 2),
99
- isUnderline = _useState24[0],
100
- setIsUnderline = _useState24[1];
97
+ isItalic = _useState24[0],
98
+ setIsItalic = _useState24[1];
101
99
  var _useState25 = useState(false),
102
100
  _useState26 = _slicedToArray(_useState25, 2),
103
- isStrikethrough = _useState26[0],
104
- setIsStrikethrough = _useState26[1];
101
+ isUnderline = _useState26[0],
102
+ setIsUnderline = _useState26[1];
105
103
  var _useState27 = useState(false),
106
104
  _useState28 = _slicedToArray(_useState27, 2),
107
- isSubscript = _useState28[0],
108
- setIsSubscript = _useState28[1];
105
+ isStrikethrough = _useState28[0],
106
+ setIsStrikethrough = _useState28[1];
109
107
  var _useState29 = useState(false),
110
108
  _useState30 = _slicedToArray(_useState29, 2),
111
- isSuperscript = _useState30[0],
112
- setIsSuperscript = _useState30[1];
109
+ isSubscript = _useState30[0],
110
+ setIsSubscript = _useState30[1];
113
111
  var _useState31 = useState(false),
114
112
  _useState32 = _slicedToArray(_useState31, 2),
115
- isCode = _useState32[0],
116
- setIsCode = _useState32[1];
113
+ isSuperscript = _useState32[0],
114
+ setIsSuperscript = _useState32[1];
117
115
  var _useState33 = useState(false),
118
116
  _useState34 = _slicedToArray(_useState33, 2),
119
- canUndo = _useState34[0],
120
- setCanUndo = _useState34[1];
117
+ isCode = _useState34[0],
118
+ setIsCode = _useState34[1];
121
119
  var _useState35 = useState(false),
122
120
  _useState36 = _slicedToArray(_useState35, 2),
123
- canRedo = _useState36[0],
124
- setCanRedo = _useState36[1];
121
+ canUndo = _useState36[0],
122
+ setCanUndo = _useState36[1];
125
123
  var _useState37 = useState(false),
126
124
  _useState38 = _slicedToArray(_useState37, 2),
127
- isRTL = _useState38[0],
128
- setIsRTL = _useState38[1];
129
- var _useState39 = useState(""),
125
+ canRedo = _useState38[0],
126
+ setCanRedo = _useState38[1];
127
+ var _useState39 = useState(false),
130
128
  _useState40 = _slicedToArray(_useState39, 2),
131
- codeLanguage = _useState40[0],
132
- setCodeLanguage = _useState40[1];
133
- var _useState41 = useState(function () {
129
+ isRTL = _useState40[0],
130
+ setIsRTL = _useState40[1];
131
+ var _useState41 = useState(""),
132
+ _useState42 = _slicedToArray(_useState41, 2),
133
+ codeLanguage = _useState42[0],
134
+ setCodeLanguage = _useState42[1];
135
+ var _useState43 = useState(function () {
134
136
  return editor.isEditable();
135
137
  }),
136
- _useState42 = _slicedToArray(_useState41, 2),
137
- isEditable = _useState42[0],
138
- setIsEditable = _useState42[1];
138
+ _useState44 = _slicedToArray(_useState43, 2),
139
+ isEditable = _useState44[0],
140
+ setIsEditable = _useState44[1];
139
141
  var $updateToolbar = useCallback(function () {
140
142
  var selection = $getSelection();
141
143
  if ($isRangeSelection(selection)) {
@@ -158,7 +160,9 @@ var useFormatWatcher = function useFormatWatcher() {
158
160
  setIsSubscript(selection.hasFormat("subscript"));
159
161
  setIsSuperscript(selection.hasFormat("superscript"));
160
162
  setIsCode(selection.hasFormat("code"));
161
- setIsRTL($isParentElementRTL(selection));
163
+ editor.read(function () {
164
+ setIsRTL($isParentElementRTL(selection));
165
+ });
162
166
 
163
167
  // Update links
164
168
  var node = getSelectedNode(selection);
@@ -194,22 +198,29 @@ var useFormatWatcher = function useFormatWatcher() {
194
198
  }
195
199
  // Handle buttons
196
200
  setFontSize(parseInt($getSelectionStyleValueForProperty(selection, "font-size", "16")) + "");
197
- setFontColor($getSelectionStyleValueForProperty(selection, "color", "#000"));
198
- setBgColor($getSelectionStyleValueForProperty(selection, "background-color", "#fff"));
201
+ setFontColor($getSelectionStyleValueForProperty(selection, "color",
202
+ // @ts-expect-error ignore
203
+ // eslint-disable-next-line no-new-wrappers
204
+ new String("#000")));
205
+ setBgColor($getSelectionStyleValueForProperty(selection, "background-color",
206
+ // @ts-expect-error ignore
207
+ // eslint-disable-next-line no-new-wrappers
208
+ new String("#fff")));
199
209
  setFontFamily($getSelectionStyleValueForProperty(selection, "font-family", "inherit"));
200
210
  }
201
- }, [activeEditor]);
211
+ }, []);
202
212
  useEffect(function () {
203
- return editor.registerCommand(FOCUS_COMMAND, function (_payload, newEditor) {
213
+ return editor.registerCommand(SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
204
214
  setActiveEditor(newEditor);
215
+ setCurrentSelection($getSelection());
216
+ $updateToolbar();
205
217
  return false;
206
218
  }, COMMAND_PRIORITY_CRITICAL);
207
- }, [editor]);
219
+ }, [editor, $updateToolbar]);
208
220
  useEffect(function () {
209
- return activeEditor.registerCommand(SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
221
+ activeEditor.getEditorState().read(function () {
210
222
  $updateToolbar();
211
- return false;
212
- }, COMMAND_PRIORITY_CRITICAL);
223
+ });
213
224
  }, [activeEditor, $updateToolbar]);
214
225
  useEffect(function () {
215
226
  return mergeRegister(editor.registerEditableListener(function (editable) {
@@ -228,15 +239,14 @@ var useFormatWatcher = function useFormatWatcher() {
228
239
  }, COMMAND_PRIORITY_CRITICAL));
229
240
  }, [$updateToolbar, activeEditor, editor]);
230
241
  var applyStyleText = useCallback(function (styles) {
231
- setTimeout(function () {
232
- editor.update(function () {
233
- var selection = $getSelection();
234
- if ($isRangeSelection(selection)) {
235
- $patchStyleText(selection, styles);
236
- }
237
- });
238
- }, 100);
239
- }, [editor]);
242
+ // activeEditor.focus();
243
+ activeEditor.update(function () {
244
+ if (!isNil(currentSelection)) {
245
+ $setSelection(currentSelection.clone());
246
+ $patchStyleText(currentSelection, styles);
247
+ }
248
+ });
249
+ }, [activeEditor, currentSelection]);
240
250
  var formatBulletList = function formatBulletList() {
241
251
  setTimeout(function () {
242
252
  if (blockType !== "bullet") {
@@ -364,25 +374,18 @@ var useFormatWatcher = function useFormatWatcher() {
364
374
  });
365
375
  }, [activeEditor]);
366
376
  var onSizeChange = useCallback(function (value) {
367
- startTransition(function () {
368
- return setFontColor(value);
369
- });
370
377
  applyStyleText({
371
378
  "font-size": +value + "px"
372
379
  });
373
380
  }, [applyStyleText]);
374
- var onFontColorSelect = useCallback(function (value) {
375
- startTransition(function () {
376
- return setFontColor(value);
377
- });
381
+ var onFontColorSelect = useCallback(function () {
382
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#000000";
378
383
  applyStyleText({
379
384
  color: value
380
385
  });
381
386
  }, [applyStyleText]);
382
- var onBgColorSelect = useCallback(function (value) {
383
- startTransition(function () {
384
- return setBgColor(value);
385
- });
387
+ var onBgColorSelect = useCallback(function () {
388
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#ffffff";
386
389
  applyStyleText({
387
390
  "background-color": value
388
391
  });
@@ -135,9 +135,11 @@ var ToolbarPlugin = function ToolbarPlugin() {
135
135
  variant: "link",
136
136
  children: [/*#__PURE__*/jsx(ButtonWrapper, {
137
137
  value: "start",
138
- rtlFlip: true,
139
138
  label: t("tool.alignStart"),
140
- icon: CoreIcons.alignLeft,
139
+ icon: {
140
+ icon: CoreIcons.alignLeft,
141
+ rtlFlip: true
142
+ },
141
143
  onClick: function onClick() {
142
144
  return watch.activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, "start");
143
145
  }
@@ -150,33 +152,41 @@ var ToolbarPlugin = function ToolbarPlugin() {
150
152
  }
151
153
  }), /*#__PURE__*/jsx(ButtonWrapper, {
152
154
  value: "end",
153
- rtlFlip: true,
154
155
  label: t("tool.alignEnd"),
155
- icon: CoreIcons.alignRight,
156
+ icon: {
157
+ icon: CoreIcons.alignRight,
158
+ rtlFlip: true
159
+ },
156
160
  onClick: function onClick() {
157
161
  return watch.activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, "end");
158
162
  }
159
163
  }), /*#__PURE__*/jsx(ButtonWrapper, {
160
164
  value: "justify",
161
- rtlFlip: true,
162
165
  label: t("tool.alignJustify"),
163
- icon: CoreIcons.alignJustify,
166
+ icon: {
167
+ icon: CoreIcons.alignJustify,
168
+ rtlFlip: true
169
+ },
164
170
  onClick: function onClick() {
165
171
  return watch.activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, "justify");
166
172
  }
167
173
  }), /*#__PURE__*/jsx(ButtonWrapper, {
168
174
  value: "justify",
169
- rtlFlip: true,
170
175
  label: t("tool.indentOut"),
171
- icon: CoreIcons.formatIndentDecrease,
176
+ icon: {
177
+ icon: CoreIcons.formatIndentDecrease,
178
+ rtlFlip: true
179
+ },
172
180
  onClick: function onClick() {
173
181
  return watch.outdent();
174
182
  }
175
183
  }), /*#__PURE__*/jsx(ButtonWrapper, {
176
184
  value: "justify",
177
- rtlFlip: true,
178
185
  label: t("tool.identIn"),
179
- icon: CoreIcons.formatIndentIncrease,
186
+ icon: {
187
+ icon: CoreIcons.formatIndentIncrease,
188
+ rtlFlip: true
189
+ },
180
190
  onClick: function onClick() {
181
191
  return watch.indent();
182
192
  }
@@ -220,9 +230,8 @@ var ToolbarPlugin = function ToolbarPlugin() {
220
230
  }), /*#__PURE__*/jsx(ColorInput, {
221
231
  noOutline: true,
222
232
  value: watch.fontColor,
223
- onChange: function onChange() {
224
- var v = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#000";
225
- return watch.onFontColorSelect(v);
233
+ onChange: function onChange(v) {
234
+ return watch.onFontColorSelect(v !== null && v !== void 0 ? v : undefined);
226
235
  },
227
236
  decorateStart: /*#__PURE__*/jsx(Icon, {
228
237
  icon: CoreIcons.formatText
@@ -230,9 +239,8 @@ var ToolbarPlugin = function ToolbarPlugin() {
230
239
  }), /*#__PURE__*/jsx(ColorInput, {
231
240
  noOutline: true,
232
241
  value: watch.bgColor,
233
- onChange: function onChange() {
234
- var v = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#fff";
235
- return watch.onBgColorSelect(v);
242
+ onChange: function onChange(v) {
243
+ return watch.onBgColorSelect(v !== null && v !== void 0 ? v : undefined);
236
244
  },
237
245
  decorateStart: /*#__PURE__*/jsx(Icon, {
238
246
  icon: CoreIcons.formatFill
@@ -251,7 +259,7 @@ var ToolbarPlugin = function ToolbarPlugin() {
251
259
  onClick: function onClick() {
252
260
  return watch.clearFormatting();
253
261
  }
254
- }), /*#__PURE__*/jsx(Divider, {})]
262
+ })]
255
263
  });
256
264
  };
257
265
 
@@ -10,4 +10,29 @@ export interface EditorProps {
10
10
  onChange?: (value: KeyValue) => void;
11
11
  onDirty?: (isDirty: boolean) => void;
12
12
  }
13
+ /**
14
+ * LexicalEditor component is a rich text editor built using Lexical.
15
+ * It supports various features such as code highlighting, lists, tables, and sticky notes.
16
+ * It provides a customizable toolbar and handles editor state changes.
17
+ * It also supports drag-and-drop functionality for blocks.
18
+ * It can be used in both read-only and editable modes, and supports publishing mode for exporting content.
19
+ * It uses a custom theme and provides error handling for Lexical updates.
20
+ *
21
+ * @param {EditorProps} props - The properties for the LexicalEditor component.
22
+ * @returns {JSX.Element} The rendered LexicalEditor component.
23
+ *
24
+ * @example
25
+ * ```jsx
26
+ * <LexicalEditor
27
+ * value={initialValue}
28
+ * readOnly={false}
29
+ * publishMode={false}
30
+ * onChange={(value) => console.log("Editor value changed:", value)}
31
+ * onDirty={(isDirty) => console.log("Editor is dirty:", isDirty)}
32
+ * />
33
+ * ```
34
+ *
35
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/lexical-playground--playground}
36
+ * @see {@link https://lexical.dev/docs/}
37
+ */
13
38
  export declare const LexicalEditor: ({ value, readOnly, publishMode, onChange, onDirty, }: EditorProps) => import("react/jsx-runtime").JSX.Element;
@@ -27,8 +27,8 @@ export declare const useFormatWatcher: () => {
27
27
  indent: () => void;
28
28
  outdent: () => void;
29
29
  clearFormatting: () => void;
30
- onFontColorSelect: (value: string) => void;
31
- onBgColorSelect: (value: string) => void;
30
+ onFontColorSelect: (value?: string) => void;
31
+ onBgColorSelect: (value?: string) => void;
32
32
  formatQuote: () => void;
33
33
  onSizeChange: (value: string) => void;
34
34
  formatBlock: () => void;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { DecoratorNode, type DOMConversionMap, type DOMExportOutput, type EditorConfig, type LexicalEditor, type LexicalNode, type NodeKey, type SerializedLexicalNode, type Spread } from "lexical";
3
2
  type StickyNoteColor = "pink" | "yellow" | "green" | "blue";
4
3
  interface StickyNodeType {