@lexical/react 0.25.0 → 0.25.1-nightly.20250224.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.
Files changed (42) hide show
  1. package/LexicalClickableLinkPlugin.d.ts +0 -2
  2. package/LexicalClickableLinkPlugin.dev.js +0 -1
  3. package/LexicalClickableLinkPlugin.dev.mjs +1 -1
  4. package/LexicalClickableLinkPlugin.js.flow +0 -2
  5. package/LexicalClickableLinkPlugin.mjs +1 -2
  6. package/LexicalClickableLinkPlugin.node.mjs +1 -2
  7. package/LexicalClickableLinkPlugin.prod.js +1 -1
  8. package/LexicalClickableLinkPlugin.prod.mjs +1 -1
  9. package/LexicalErrorBoundary.d.ts +0 -2
  10. package/LexicalErrorBoundary.dev.js +0 -1
  11. package/LexicalErrorBoundary.dev.mjs +1 -1
  12. package/LexicalErrorBoundary.js.flow +0 -3
  13. package/LexicalErrorBoundary.mjs +1 -2
  14. package/LexicalErrorBoundary.node.mjs +1 -2
  15. package/LexicalErrorBoundary.prod.js +1 -1
  16. package/LexicalErrorBoundary.prod.mjs +1 -1
  17. package/package.json +20 -50
  18. package/useLexicalEditable.d.ts +0 -2
  19. package/useLexicalEditable.dev.js +0 -1
  20. package/useLexicalEditable.dev.mjs +1 -1
  21. package/useLexicalEditable.js.flow +0 -3
  22. package/useLexicalEditable.mjs +0 -1
  23. package/useLexicalEditable.node.mjs +0 -1
  24. package/useLexicalEditable.prod.js +1 -1
  25. package/useLexicalEditable.prod.mjs +1 -1
  26. package/useLexicalSubscription.d.ts +0 -2
  27. package/useLexicalSubscription.dev.js +0 -1
  28. package/useLexicalSubscription.dev.mjs +1 -1
  29. package/useLexicalSubscription.js.flow +0 -3
  30. package/useLexicalSubscription.mjs +0 -1
  31. package/useLexicalSubscription.node.mjs +0 -1
  32. package/useLexicalSubscription.prod.js +1 -1
  33. package/useLexicalSubscription.prod.mjs +1 -1
  34. package/LexicalTableOfContents.d.ts +0 -13
  35. package/LexicalTableOfContents.dev.js +0 -217
  36. package/LexicalTableOfContents.dev.mjs +0 -215
  37. package/LexicalTableOfContents.js +0 -11
  38. package/LexicalTableOfContents.js.flow +0 -13
  39. package/LexicalTableOfContents.mjs +0 -12
  40. package/LexicalTableOfContents.node.mjs +0 -10
  41. package/LexicalTableOfContents.prod.js +0 -9
  42. package/LexicalTableOfContents.prod.mjs +0 -9
@@ -9,5 +9,3 @@ export declare function ClickableLinkPlugin({ newTab, disabled, }: {
9
9
  newTab?: boolean;
10
10
  disabled?: boolean;
11
11
  }): null;
12
- /** @deprecated use the named export {@link ClickableLinkPlugin} */
13
- export default ClickableLinkPlugin;
@@ -101,4 +101,3 @@ function ClickableLinkPlugin({
101
101
  }
102
102
 
103
103
  exports.ClickableLinkPlugin = ClickableLinkPlugin;
104
- exports.default = ClickableLinkPlugin;
@@ -98,4 +98,4 @@ function ClickableLinkPlugin({
98
98
  return null;
99
99
  }
100
100
 
101
- export { ClickableLinkPlugin, ClickableLinkPlugin as default };
101
+ export { ClickableLinkPlugin };
@@ -10,5 +10,3 @@
10
10
  declare export function ClickableLinkPlugin({
11
11
  newTab?: boolean,
12
12
  }): null;
13
-
14
- declare export default typeof ClickableLinkPlugin;
@@ -9,5 +9,4 @@
9
9
  import * as modDev from './LexicalClickableLinkPlugin.dev.mjs';
10
10
  import * as modProd from './LexicalClickableLinkPlugin.prod.mjs';
11
11
  const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
12
- export const ClickableLinkPlugin = mod.ClickableLinkPlugin;
13
- export default mod.default;
12
+ export const ClickableLinkPlugin = mod.ClickableLinkPlugin;
@@ -7,5 +7,4 @@
7
7
  */
8
8
 
9
9
  const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalClickableLinkPlugin.dev.mjs') : import('./LexicalClickableLinkPlugin.prod.mjs'));
10
- export const ClickableLinkPlugin = mod.ClickableLinkPlugin;
11
- export default mod.default;
10
+ export const ClickableLinkPlugin = mod.ClickableLinkPlugin;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/link"),t=require("@lexical/react/LexicalComposerContext"),n=require("@lexical/utils"),r=require("lexical"),l=require("react");function i({newTab:i=!0,disabled:o=!1}){const[u]=t.useLexicalComposerContext();return l.useEffect((()=>{const t=t=>{const l=t.target;if(!r.isDOMNode(l))return;const s=r.getNearestEditorFromDOMNode(l);if(null===s)return;let a=null,c=null;if(s.update((()=>{const t=r.$getNearestNodeFromDOMNode(l);if(null!==t){const i=n.$findMatchingParent(t,r.$isElementNode);if(!o)if(e.$isLinkNode(i))a=i.sanitizeUrl(i.getURL()),c=i.getTarget();else{const e=function(e,t){let n=e;for(;null!=n;){if(t(n))return n;n=n.parentNode}return null}(l,n.isHTMLAnchorElement);null!==e&&(a=e.href,c=e.target)}}})),null===a||""===a)return;const d=u.getEditorState().read(r.$getSelection);if(r.$isRangeSelection(d)&&!d.isCollapsed())return void t.preventDefault();const f="auxclick"===t.type&&1===t.button;window.open(a,i||f||t.metaKey||t.ctrlKey||"_blank"===c?"_blank":"_self"),t.preventDefault()},l=e=>{1===e.button&&t(e)};return u.registerRootListener(((e,n)=>{null!==n&&(n.removeEventListener("click",t),n.removeEventListener("mouseup",l)),null!==e&&(e.addEventListener("click",t),e.addEventListener("mouseup",l))}))}),[u,i,o]),null}exports.ClickableLinkPlugin=i,exports.default=i;
9
+ "use strict";var e=require("@lexical/link"),t=require("@lexical/react/LexicalComposerContext"),n=require("@lexical/utils"),r=require("lexical"),l=require("react");exports.ClickableLinkPlugin=function({newTab:i=!0,disabled:o=!1}){const[u]=t.useLexicalComposerContext();return l.useEffect((()=>{const t=t=>{const l=t.target;if(!r.isDOMNode(l))return;const s=r.getNearestEditorFromDOMNode(l);if(null===s)return;let a=null,c=null;if(s.update((()=>{const t=r.$getNearestNodeFromDOMNode(l);if(null!==t){const i=n.$findMatchingParent(t,r.$isElementNode);if(!o)if(e.$isLinkNode(i))a=i.sanitizeUrl(i.getURL()),c=i.getTarget();else{const e=function(e,t){let n=e;for(;null!=n;){if(t(n))return n;n=n.parentNode}return null}(l,n.isHTMLAnchorElement);null!==e&&(a=e.href,c=e.target)}}})),null===a||""===a)return;const d=u.getEditorState().read(r.$getSelection);if(r.$isRangeSelection(d)&&!d.isCollapsed())return void t.preventDefault();const f="auxclick"===t.type&&1===t.button;window.open(a,i||f||t.metaKey||t.ctrlKey||"_blank"===c?"_blank":"_self"),t.preventDefault()},l=e=>{1===e.button&&t(e)};return u.registerRootListener(((e,n)=>{null!==n&&(n.removeEventListener("click",t),n.removeEventListener("mouseup",l)),null!==e&&(e.addEventListener("click",t),e.addEventListener("mouseup",l))}))}),[u,i,o]),null};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{$isLinkNode as e}from"@lexical/link";import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{$findMatchingParent as n,isHTMLAnchorElement as r}from"@lexical/utils";import{isDOMNode as l,getNearestEditorFromDOMNode as o,$getNearestNodeFromDOMNode as i,$isElementNode as u,$getSelection as a,$isRangeSelection as s}from"lexical";import{useEffect as c}from"react";function f({newTab:f=!0,disabled:m=!1}){const[p]=t();return c((()=>{const t=t=>{const c=t.target;if(!l(c))return;const d=o(c);if(null===d)return;let v=null,x=null;if(d.update((()=>{const t=i(c);if(null!==t){const l=n(t,u);if(!m)if(e(l))v=l.sanitizeUrl(l.getURL()),x=l.getTarget();else{const e=function(e,t){let n=e;for(;null!=n;){if(t(n))return n;n=n.parentNode}return null}(c,r);null!==e&&(v=e.href,x=e.target)}}})),null===v||""===v)return;const g=p.getEditorState().read(a);if(s(g)&&!g.isCollapsed())return void t.preventDefault();const L="auxclick"===t.type&&1===t.button;window.open(v,f||L||t.metaKey||t.ctrlKey||"_blank"===x?"_blank":"_self"),t.preventDefault()},c=e=>{1===e.button&&t(e)};return p.registerRootListener(((e,n)=>{null!==n&&(n.removeEventListener("click",t),n.removeEventListener("mouseup",c)),null!==e&&(e.addEventListener("click",t),e.addEventListener("mouseup",c))}))}),[p,f,m]),null}export{f as ClickableLinkPlugin,f as default};
9
+ import{$isLinkNode as e}from"@lexical/link";import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{$findMatchingParent as n,isHTMLAnchorElement as r}from"@lexical/utils";import{isDOMNode as l,getNearestEditorFromDOMNode as o,$getNearestNodeFromDOMNode as i,$isElementNode as u,$getSelection as a,$isRangeSelection as c}from"lexical";import{useEffect as s}from"react";function f({newTab:f=!0,disabled:m=!1}){const[p]=t();return s((()=>{const t=t=>{const s=t.target;if(!l(s))return;const d=o(s);if(null===d)return;let v=null,x=null;if(d.update((()=>{const t=i(s);if(null!==t){const l=n(t,u);if(!m)if(e(l))v=l.sanitizeUrl(l.getURL()),x=l.getTarget();else{const e=function(e,t){let n=e;for(;null!=n;){if(t(n))return n;n=n.parentNode}return null}(s,r);null!==e&&(v=e.href,x=e.target)}}})),null===v||""===v)return;const g=p.getEditorState().read(a);if(c(g)&&!g.isCollapsed())return void t.preventDefault();const L="auxclick"===t.type&&1===t.button;window.open(v,f||L||t.metaKey||t.ctrlKey||"_blank"===x?"_blank":"_self"),t.preventDefault()},s=e=>{1===e.button&&t(e)};return p.registerRootListener(((e,n)=>{null!==n&&(n.removeEventListener("click",t),n.removeEventListener("mouseup",s)),null!==e&&(e.addEventListener("click",t),e.addEventListener("mouseup",s))}))}),[p,f,m]),null}export{f as ClickableLinkPlugin};
@@ -11,5 +11,3 @@ export type LexicalErrorBoundaryProps = {
11
11
  onError: (error: Error) => void;
12
12
  };
13
13
  export declare function LexicalErrorBoundary({ children, onError, }: LexicalErrorBoundaryProps): JSX.Element;
14
- /** @deprecated use the named export {@link LexicalErrorBoundary} */
15
- export default LexicalErrorBoundary;
@@ -176,4 +176,3 @@ function LexicalErrorBoundary({
176
176
  }
177
177
 
178
178
  exports.LexicalErrorBoundary = LexicalErrorBoundary;
179
- exports.default = LexicalErrorBoundary;
@@ -160,4 +160,4 @@ function LexicalErrorBoundary({
160
160
  });
161
161
  }
162
162
 
163
- export { LexicalErrorBoundary, LexicalErrorBoundary as default };
163
+ export { LexicalErrorBoundary };
@@ -15,6 +15,3 @@ export type LexicalErrorBoundaryProps = $ReadOnly<{
15
15
  declare export function LexicalErrorBoundary(
16
16
  props: LexicalErrorBoundaryProps,
17
17
  ): React.Node;
18
-
19
- /** @deprecated use the named export {@link LexicalErrorBoundary} */
20
- export default typeof LexicalErrorBoundary;
@@ -9,5 +9,4 @@
9
9
  import * as modDev from './LexicalErrorBoundary.dev.mjs';
10
10
  import * as modProd from './LexicalErrorBoundary.prod.mjs';
11
11
  const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
12
- export const LexicalErrorBoundary = mod.LexicalErrorBoundary;
13
- export default mod.default;
12
+ export const LexicalErrorBoundary = mod.LexicalErrorBoundary;
@@ -7,5 +7,4 @@
7
7
  */
8
8
 
9
9
  const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalErrorBoundary.dev.mjs') : import('./LexicalErrorBoundary.prod.mjs'));
10
- export const LexicalErrorBoundary = mod.LexicalErrorBoundary;
11
- export default mod.default;
10
+ export const LexicalErrorBoundary = mod.LexicalErrorBoundary;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var r=require("react"),e=require("react/jsx-runtime");function t(r){var e=Object.create(null);if(r)for(var t in r)e[t]=r[t];return e.default=r,e}var n=t(r);function o(r,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,e){return r.__proto__=e,r},o(r,e)}var a={error:null},s=function(r){var e,t;function s(){for(var e,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];return(e=r.call.apply(r,[this].concat(n))||this).state=a,e.resetErrorBoundary=function(){for(var r,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];null==e.props.onReset||(r=e.props).onReset.apply(r,n),e.reset()},e}t=r,(e=s).prototype=Object.create(t.prototype),e.prototype.constructor=e,o(e,t),s.getDerivedStateFromError=function(r){return{error:r}};var i=s.prototype;return i.reset=function(){this.setState(a)},i.componentDidCatch=function(r,e){var t,n;null==(t=(n=this.props).onError)||t.call(n,r,e)},i.componentDidUpdate=function(r,e){var t,n,o,a,s=this.state.error,i=this.props.resetKeys;null!==s&&null!==e.error&&(void 0===(o=r.resetKeys)&&(o=[]),void 0===(a=i)&&(a=[]),o.length!==a.length||o.some((function(r,e){return!Object.is(r,a[e])})))&&(null==(t=(n=this.props).onResetKeysChange)||t.call(n,r.resetKeys,i),this.reset())},i.render=function(){var r=this.state.error,e=this.props,t=e.fallbackRender,o=e.FallbackComponent,a=e.fallback;if(null!==r){var s={error:r,resetErrorBoundary:this.resetErrorBoundary};if(n.isValidElement(a))return a;if("function"==typeof t)return t(s);if(o)return n.createElement(o,s);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},s}(n.Component);function i({children:r,onError:t}){return e.jsx(s,{fallback:e.jsx("div",{style:{border:"1px solid #f00",color:"#f00",padding:"8px"},children:"An error was thrown."}),onError:t,children:r})}exports.LexicalErrorBoundary=i,exports.default=i;
9
+ "use strict";var r=require("react"),e=require("react/jsx-runtime");function t(r){var e=Object.create(null);if(r)for(var t in r)e[t]=r[t];return e.default=r,e}var n=t(r);function o(r,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,e){return r.__proto__=e,r},o(r,e)}var a={error:null},i=function(r){var e,t;function i(){for(var e,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];return(e=r.call.apply(r,[this].concat(n))||this).state=a,e.resetErrorBoundary=function(){for(var r,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];null==e.props.onReset||(r=e.props).onReset.apply(r,n),e.reset()},e}t=r,(e=i).prototype=Object.create(t.prototype),e.prototype.constructor=e,o(e,t),i.getDerivedStateFromError=function(r){return{error:r}};var s=i.prototype;return s.reset=function(){this.setState(a)},s.componentDidCatch=function(r,e){var t,n;null==(t=(n=this.props).onError)||t.call(n,r,e)},s.componentDidUpdate=function(r,e){var t,n,o,a,i=this.state.error,s=this.props.resetKeys;null!==i&&null!==e.error&&(void 0===(o=r.resetKeys)&&(o=[]),void 0===(a=s)&&(a=[]),o.length!==a.length||o.some((function(r,e){return!Object.is(r,a[e])})))&&(null==(t=(n=this.props).onResetKeysChange)||t.call(n,r.resetKeys,s),this.reset())},s.render=function(){var r=this.state.error,e=this.props,t=e.fallbackRender,o=e.FallbackComponent,a=e.fallback;if(null!==r){var i={error:r,resetErrorBoundary:this.resetErrorBoundary};if(n.isValidElement(a))return a;if("function"==typeof t)return t(i);if(o)return n.createElement(o,i);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},i}(n.Component);exports.LexicalErrorBoundary=function({children:r,onError:t}){return e.jsx(i,{fallback:e.jsx("div",{style:{border:"1px solid #f00",color:"#f00",padding:"8px"},children:"An error was thrown."}),onError:t,children:r})};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import*as r from"react";import{jsx as e}from"react/jsx-runtime";function t(r,e){return t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,e){return r.__proto__=e,r},t(r,e)}var o={error:null},n=function(e){var n,a;function s(){for(var r,t=arguments.length,n=new Array(t),a=0;a<t;a++)n[a]=arguments[a];return(r=e.call.apply(e,[this].concat(n))||this).state=o,r.resetErrorBoundary=function(){for(var e,t=arguments.length,o=new Array(t),n=0;n<t;n++)o[n]=arguments[n];null==r.props.onReset||(e=r.props).onReset.apply(e,o),r.reset()},r}a=e,(n=s).prototype=Object.create(a.prototype),n.prototype.constructor=n,t(n,a),s.getDerivedStateFromError=function(r){return{error:r}};var l=s.prototype;return l.reset=function(){this.setState(o)},l.componentDidCatch=function(r,e){var t,o;null==(t=(o=this.props).onError)||t.call(o,r,e)},l.componentDidUpdate=function(r,e){var t,o,n,a,s=this.state.error,l=this.props.resetKeys;null!==s&&null!==e.error&&(void 0===(n=r.resetKeys)&&(n=[]),void 0===(a=l)&&(a=[]),n.length!==a.length||n.some((function(r,e){return!Object.is(r,a[e])})))&&(null==(t=(o=this.props).onResetKeysChange)||t.call(o,r.resetKeys,l),this.reset())},l.render=function(){var e=this.state.error,t=this.props,o=t.fallbackRender,n=t.FallbackComponent,a=t.fallback;if(null!==e){var s={error:e,resetErrorBoundary:this.resetErrorBoundary};if(r.isValidElement(a))return a;if("function"==typeof o)return o(s);if(n)return r.createElement(n,s);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},s}(r.Component);function a({children:r,onError:t}){return e(n,{fallback:e("div",{style:{border:"1px solid #f00",color:"#f00",padding:"8px"},children:"An error was thrown."}),onError:t,children:r})}export{a as LexicalErrorBoundary,a as default};
9
+ import*as r from"react";import{jsx as e}from"react/jsx-runtime";function t(r,e){return t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,e){return r.__proto__=e,r},t(r,e)}var o={error:null},n=function(e){var n,a;function s(){for(var r,t=arguments.length,n=new Array(t),a=0;a<t;a++)n[a]=arguments[a];return(r=e.call.apply(e,[this].concat(n))||this).state=o,r.resetErrorBoundary=function(){for(var e,t=arguments.length,o=new Array(t),n=0;n<t;n++)o[n]=arguments[n];null==r.props.onReset||(e=r.props).onReset.apply(e,o),r.reset()},r}a=e,(n=s).prototype=Object.create(a.prototype),n.prototype.constructor=n,t(n,a),s.getDerivedStateFromError=function(r){return{error:r}};var i=s.prototype;return i.reset=function(){this.setState(o)},i.componentDidCatch=function(r,e){var t,o;null==(t=(o=this.props).onError)||t.call(o,r,e)},i.componentDidUpdate=function(r,e){var t,o,n,a,s=this.state.error,i=this.props.resetKeys;null!==s&&null!==e.error&&(void 0===(n=r.resetKeys)&&(n=[]),void 0===(a=i)&&(a=[]),n.length!==a.length||n.some((function(r,e){return!Object.is(r,a[e])})))&&(null==(t=(o=this.props).onResetKeysChange)||t.call(o,r.resetKeys,i),this.reset())},i.render=function(){var e=this.state.error,t=this.props,o=t.fallbackRender,n=t.FallbackComponent,a=t.fallback;if(null!==e){var s={error:e,resetErrorBoundary:this.resetErrorBoundary};if(r.isValidElement(a))return a;if("function"==typeof o)return o(s);if(n)return r.createElement(n,s);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},s}(r.Component);function a({children:r,onError:t}){return e(n,{fallback:e("div",{style:{border:"1px solid #f00",color:"#f00",padding:"8px"},children:"An error was thrown."}),onError:t,children:r})}export{a as LexicalErrorBoundary};
package/package.json CHANGED
@@ -8,27 +8,27 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.25.0",
11
+ "version": "0.25.1-nightly.20250224.0",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.25.0",
14
- "@lexical/code": "0.25.0",
15
- "@lexical/devtools-core": "0.25.0",
16
- "@lexical/dragon": "0.25.0",
17
- "@lexical/hashtag": "0.25.0",
18
- "@lexical/history": "0.25.0",
19
- "@lexical/link": "0.25.0",
20
- "@lexical/list": "0.25.0",
21
- "@lexical/mark": "0.25.0",
22
- "@lexical/markdown": "0.25.0",
23
- "@lexical/overflow": "0.25.0",
24
- "@lexical/plain-text": "0.25.0",
25
- "@lexical/rich-text": "0.25.0",
26
- "@lexical/selection": "0.25.0",
27
- "@lexical/table": "0.25.0",
28
- "@lexical/text": "0.25.0",
29
- "@lexical/utils": "0.25.0",
30
- "@lexical/yjs": "0.25.0",
31
- "lexical": "0.25.0",
13
+ "@lexical/clipboard": "0.25.1-nightly.20250224.0",
14
+ "@lexical/code": "0.25.1-nightly.20250224.0",
15
+ "@lexical/devtools-core": "0.25.1-nightly.20250224.0",
16
+ "@lexical/dragon": "0.25.1-nightly.20250224.0",
17
+ "@lexical/hashtag": "0.25.1-nightly.20250224.0",
18
+ "@lexical/history": "0.25.1-nightly.20250224.0",
19
+ "@lexical/link": "0.25.1-nightly.20250224.0",
20
+ "@lexical/list": "0.25.1-nightly.20250224.0",
21
+ "@lexical/mark": "0.25.1-nightly.20250224.0",
22
+ "@lexical/markdown": "0.25.1-nightly.20250224.0",
23
+ "@lexical/overflow": "0.25.1-nightly.20250224.0",
24
+ "@lexical/plain-text": "0.25.1-nightly.20250224.0",
25
+ "@lexical/rich-text": "0.25.1-nightly.20250224.0",
26
+ "@lexical/selection": "0.25.1-nightly.20250224.0",
27
+ "@lexical/table": "0.25.1-nightly.20250224.0",
28
+ "@lexical/text": "0.25.1-nightly.20250224.0",
29
+ "@lexical/utils": "0.25.1-nightly.20250224.0",
30
+ "@lexical/yjs": "0.25.1-nightly.20250224.0",
31
+ "lexical": "0.25.1-nightly.20250224.0",
32
32
  "react-error-boundary": "^3.1.4"
33
33
  },
34
34
  "peerDependencies": {
@@ -1031,36 +1031,6 @@
1031
1031
  "default": "./LexicalTabIndentationPlugin.js"
1032
1032
  }
1033
1033
  },
1034
- "./LexicalTableOfContents": {
1035
- "import": {
1036
- "types": "./LexicalTableOfContents.d.ts",
1037
- "development": "./LexicalTableOfContents.dev.mjs",
1038
- "production": "./LexicalTableOfContents.prod.mjs",
1039
- "node": "./LexicalTableOfContents.node.mjs",
1040
- "default": "./LexicalTableOfContents.mjs"
1041
- },
1042
- "require": {
1043
- "types": "./LexicalTableOfContents.d.ts",
1044
- "development": "./LexicalTableOfContents.dev.js",
1045
- "production": "./LexicalTableOfContents.prod.js",
1046
- "default": "./LexicalTableOfContents.js"
1047
- }
1048
- },
1049
- "./LexicalTableOfContents.js": {
1050
- "import": {
1051
- "types": "./LexicalTableOfContents.d.ts",
1052
- "development": "./LexicalTableOfContents.dev.mjs",
1053
- "production": "./LexicalTableOfContents.prod.mjs",
1054
- "node": "./LexicalTableOfContents.node.mjs",
1055
- "default": "./LexicalTableOfContents.mjs"
1056
- },
1057
- "require": {
1058
- "types": "./LexicalTableOfContents.d.ts",
1059
- "development": "./LexicalTableOfContents.dev.js",
1060
- "production": "./LexicalTableOfContents.prod.js",
1061
- "default": "./LexicalTableOfContents.js"
1062
- }
1063
- },
1064
1034
  "./LexicalTableOfContentsPlugin": {
1065
1035
  "import": {
1066
1036
  "types": "./LexicalTableOfContentsPlugin.d.ts",
@@ -14,5 +14,3 @@
14
14
  * React StrictMode (the default for development) or concurrency.
15
15
  */
16
16
  export declare function useLexicalEditable(): boolean;
17
- /** @deprecated use the named export {@link useLexicalEditable} */
18
- export default useLexicalEditable;
@@ -99,5 +99,4 @@ function useLexicalEditable() {
99
99
  return useLexicalSubscription(subscription);
100
100
  }
101
101
 
102
- exports.default = useLexicalEditable;
103
102
  exports.useLexicalEditable = useLexicalEditable;
@@ -97,4 +97,4 @@ function useLexicalEditable() {
97
97
  return useLexicalSubscription(subscription);
98
98
  }
99
99
 
100
- export { useLexicalEditable as default, useLexicalEditable };
100
+ export { useLexicalEditable };
@@ -10,6 +10,3 @@
10
10
  import type {LexicalEditor} from 'lexical';
11
11
 
12
12
  declare export function useLexicalEditable(): boolean;
13
-
14
- /** @deprecated use the named export {@link useLexicalEditable} */
15
- declare export default typeof useLexicalEditable;
@@ -9,5 +9,4 @@
9
9
  import * as modDev from './useLexicalEditable.dev.mjs';
10
10
  import * as modProd from './useLexicalEditable.prod.mjs';
11
11
  const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
12
- export default mod.default;
13
12
  export const useLexicalEditable = mod.useLexicalEditable;
@@ -7,5 +7,4 @@
7
7
  */
8
8
 
9
9
  const mod = await (process.env.NODE_ENV !== 'production' ? import('./useLexicalEditable.dev.mjs') : import('./useLexicalEditable.prod.mjs'));
10
- export default mod.default;
11
10
  export const useLexicalEditable = mod.useLexicalEditable;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react");const i="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;function n(e){return{initialValueFn:()=>e.isEditable(),subscribe:t=>e.registerEditableListener(t)}}function r(){return function(n){const[r]=e.useLexicalComposerContext(),u=t.useMemo((()=>n(r)),[r,n]),[o,c]=t.useState((()=>u.initialValueFn())),s=t.useRef(o);return i((()=>{const{initialValueFn:e,subscribe:t}=u,i=e();return s.current!==i&&(s.current=i,c(i)),t((e=>{s.current=e,c(e)}))}),[u,n]),o}(n)}exports.default=r,exports.useLexicalEditable=r;
9
+ "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react");const i="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;function n(e){return{initialValueFn:()=>e.isEditable(),subscribe:t=>e.registerEditableListener(t)}}exports.useLexicalEditable=function(){return function(n){const[r]=e.useLexicalComposerContext(),u=t.useMemo((()=>n(r)),[r,n]),[c,o]=t.useState((()=>u.initialValueFn())),s=t.useRef(c);return i((()=>{const{initialValueFn:e,subscribe:t}=u,i=e();return s.current!==i&&(s.current=i,o(i)),t((e=>{s.current=e,o(e)}))}),[u,n]),c}(n)};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as t,useEffect as n,useMemo as i,useState as r,useRef as o}from"react";const u="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t:n;function c(e){return{initialValueFn:()=>e.isEditable(),subscribe:t=>e.registerEditableListener(t)}}function a(){return function(t){const[n]=e(),c=i((()=>t(n)),[n,t]),[a,l]=r((()=>c.initialValueFn())),d=o(a);return u((()=>{const{initialValueFn:e,subscribe:t}=c,n=e();return d.current!==n&&(d.current=n,l(n)),t((e=>{d.current=e,l(e)}))}),[c,t]),a}(c)}export{a as default,a as useLexicalEditable};
9
+ import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as n,useEffect as t,useMemo as i,useState as r,useRef as o}from"react";const c="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?n:t;function u(e){return{initialValueFn:()=>e.isEditable(),subscribe:n=>e.registerEditableListener(n)}}function a(){return function(n){const[t]=e(),u=i((()=>n(t)),[t,n]),[a,l]=r((()=>u.initialValueFn())),d=o(a);return c((()=>{const{initialValueFn:e,subscribe:n}=u,t=e();return d.current!==t&&(d.current=t,l(t)),n((e=>{d.current=e,l(e)}))}),[u,n]),a}(u)}export{a as useLexicalEditable};
@@ -15,5 +15,3 @@ export type LexicalSubscription<T> = {
15
15
  * @param subscription - The function to create the {@link LexicalSubscription}. This function's identity must be stable (e.g. defined at module scope or with useCallback).
16
16
  */
17
17
  export declare function useLexicalSubscription<T>(subscription: (editor: LexicalEditor) => LexicalSubscription<T>): T;
18
- /** @deprecated use the named export {@link useLexicalSubscription} */
19
- export default useLexicalSubscription;
@@ -70,5 +70,4 @@ function useLexicalSubscription(subscription) {
70
70
  return value;
71
71
  }
72
72
 
73
- exports.default = useLexicalSubscription;
74
73
  exports.useLexicalSubscription = useLexicalSubscription;
@@ -68,4 +68,4 @@ function useLexicalSubscription(subscription) {
68
68
  return value;
69
69
  }
70
70
 
71
- export { useLexicalSubscription as default, useLexicalSubscription };
71
+ export { useLexicalSubscription };
@@ -17,6 +17,3 @@ export type LexicalSubscription<T> = {
17
17
  declare export function useLexicalSubscription<T>(
18
18
  subscription: (editor: LexicalEditor) => LexicalSubscription<T>,
19
19
  ): T;
20
-
21
- /** @deprecated use the named export {@link useLexicalSubscription} */
22
- declare export default typeof useLexicalSubscription;
@@ -9,5 +9,4 @@
9
9
  import * as modDev from './useLexicalSubscription.dev.mjs';
10
10
  import * as modProd from './useLexicalSubscription.prod.mjs';
11
11
  const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
12
- export default mod.default;
13
12
  export const useLexicalSubscription = mod.useLexicalSubscription;
@@ -7,5 +7,4 @@
7
7
  */
8
8
 
9
9
  const mod = await (process.env.NODE_ENV !== 'production' ? import('./useLexicalSubscription.dev.mjs') : import('./useLexicalSubscription.prod.mjs'));
10
- export default mod.default;
11
10
  export const useLexicalSubscription = mod.useLexicalSubscription;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react");const n="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;function r(r){const[u]=e.useLexicalComposerContext(),i=t.useMemo((()=>r(u)),[u,r]),[o,c]=t.useState((()=>i.initialValueFn())),s=t.useRef(o);return n((()=>{const{initialValueFn:e,subscribe:t}=i,n=e();return s.current!==n&&(s.current=n,c(n)),t((e=>{s.current=e,c(e)}))}),[i,r]),o}exports.default=r,exports.useLexicalSubscription=r;
9
+ "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react");const n="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;exports.useLexicalSubscription=function(r){const[u]=e.useLexicalComposerContext(),i=t.useMemo((()=>r(u)),[u,r]),[o,c]=t.useState((()=>i.initialValueFn())),s=t.useRef(o);return n((()=>{const{initialValueFn:e,subscribe:t}=i,n=e();return s.current!==n&&(s.current=n,c(n)),t((e=>{s.current=e,c(e)}))}),[i,r]),o};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as t,useEffect as n,useMemo as o,useState as r,useRef as i}from"react";const c="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t:n;function u(t){const[n]=e(),u=o((()=>t(n)),[n,t]),[a,d]=r((()=>u.initialValueFn())),l=i(a);return c((()=>{const{initialValueFn:e,subscribe:t}=u,n=e();return l.current!==n&&(l.current=n,d(n)),t((e=>{l.current=e,d(e)}))}),[u,t]),a}export{u as default,u as useLexicalSubscription};
9
+ import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as n,useEffect as t,useMemo as o,useState as r,useRef as i}from"react";const c="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?n:t;function u(n){const[t]=e(),u=o((()=>n(t)),[t,n]),[a,d]=r((()=>u.initialValueFn())),l=i(a);return c((()=>{const{initialValueFn:e,subscribe:n}=u,t=e();return l.current!==t&&(l.current=t,d(t)),n((e=>{l.current=e,d(e)}))}),[u,n]),a}export{u as useLexicalSubscription};
@@ -1,13 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- /** @deprecated moved to @lexical/react/LexicalTableOfContentsPlugin */
9
- import { type TableOfContentsEntry, TableOfContentsPlugin } from './LexicalTableOfContentsPlugin';
10
- /** @deprecated use the module @lexical/react/LexicalTableOfContentsPlugin */
11
- export { type TableOfContentsEntry };
12
- /** @deprecated use module @lexical/react/LexicalTableOfContentsPlugin */
13
- export default TableOfContentsPlugin;
@@ -1,217 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- 'use strict';
10
-
11
- var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
12
- var richText = require('@lexical/rich-text');
13
- var utils = require('@lexical/utils');
14
- var lexical = require('lexical');
15
- var react = require('react');
16
-
17
- /**
18
- * Copyright (c) Meta Platforms, Inc. and affiliates.
19
- *
20
- * This source code is licensed under the MIT license found in the
21
- * LICENSE file in the root directory of this source tree.
22
- *
23
- */
24
-
25
- function toEntry(heading) {
26
- return [heading.getKey(), heading.getTextContent(), heading.getTag()];
27
- }
28
- function $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents) {
29
- if (newHeading === null) {
30
- return currentTableOfContents;
31
- }
32
- const newEntry = toEntry(newHeading);
33
- let newTableOfContents = [];
34
- if (prevHeading === null) {
35
- // check if key already exists
36
- if (currentTableOfContents.length > 0 && currentTableOfContents[0][0] === newHeading.__key) {
37
- return currentTableOfContents;
38
- }
39
- newTableOfContents = [newEntry, ...currentTableOfContents];
40
- } else {
41
- for (let i = 0; i < currentTableOfContents.length; i++) {
42
- const key = currentTableOfContents[i][0];
43
- newTableOfContents.push(currentTableOfContents[i]);
44
- if (key === prevHeading.getKey() && key !== newHeading.getKey()) {
45
- // check if key already exists
46
- if (i + 1 < currentTableOfContents.length && currentTableOfContents[i + 1][0] === newHeading.__key) {
47
- return currentTableOfContents;
48
- }
49
- newTableOfContents.push(newEntry);
50
- }
51
- }
52
- }
53
- return newTableOfContents;
54
- }
55
- function $deleteHeadingFromTableOfContents(key, currentTableOfContents) {
56
- const newTableOfContents = [];
57
- for (const heading of currentTableOfContents) {
58
- if (heading[0] !== key) {
59
- newTableOfContents.push(heading);
60
- }
61
- }
62
- return newTableOfContents;
63
- }
64
- function $updateHeadingInTableOfContents(heading, currentTableOfContents) {
65
- const newTableOfContents = [];
66
- for (const oldHeading of currentTableOfContents) {
67
- if (oldHeading[0] === heading.getKey()) {
68
- newTableOfContents.push(toEntry(heading));
69
- } else {
70
- newTableOfContents.push(oldHeading);
71
- }
72
- }
73
- return newTableOfContents;
74
- }
75
-
76
- /**
77
- * Returns the updated table of contents, placing the given `heading` before the given `prevHeading`. If `prevHeading`
78
- * is undefined, `heading` is placed at the start of table of contents
79
- */
80
- function $updateHeadingPosition(prevHeading, heading, currentTableOfContents) {
81
- const newTableOfContents = [];
82
- const newEntry = toEntry(heading);
83
- if (!prevHeading) {
84
- newTableOfContents.push(newEntry);
85
- }
86
- for (const oldHeading of currentTableOfContents) {
87
- if (oldHeading[0] === heading.getKey()) {
88
- continue;
89
- }
90
- newTableOfContents.push(oldHeading);
91
- if (prevHeading && oldHeading[0] === prevHeading.getKey()) {
92
- newTableOfContents.push(newEntry);
93
- }
94
- }
95
- return newTableOfContents;
96
- }
97
- function $getPreviousHeading(node) {
98
- let prevHeading = utils.$getNextRightPreorderNode(node);
99
- while (prevHeading !== null && !richText.$isHeadingNode(prevHeading)) {
100
- prevHeading = utils.$getNextRightPreorderNode(prevHeading);
101
- }
102
- return prevHeading;
103
- }
104
- function TableOfContentsPlugin({
105
- children
106
- }) {
107
- const [tableOfContents, setTableOfContents] = react.useState([]);
108
- const [editor] = LexicalComposerContext.useLexicalComposerContext();
109
- react.useEffect(() => {
110
- // Set table of contents initial state
111
- let currentTableOfContents = [];
112
- editor.getEditorState().read(() => {
113
- const updateCurrentTableOfContents = node => {
114
- for (const child of node.getChildren()) {
115
- if (richText.$isHeadingNode(child)) {
116
- currentTableOfContents.push([child.getKey(), child.getTextContent(), child.getTag()]);
117
- } else if (lexical.$isElementNode(child)) {
118
- updateCurrentTableOfContents(child);
119
- }
120
- }
121
- };
122
- updateCurrentTableOfContents(lexical.$getRoot());
123
- setTableOfContents(currentTableOfContents);
124
- });
125
- const removeRootUpdateListener = editor.registerUpdateListener(({
126
- editorState,
127
- dirtyElements
128
- }) => {
129
- editorState.read(() => {
130
- const updateChildHeadings = node => {
131
- for (const child of node.getChildren()) {
132
- if (richText.$isHeadingNode(child)) {
133
- const prevHeading = $getPreviousHeading(child);
134
- currentTableOfContents = $updateHeadingPosition(prevHeading, child, currentTableOfContents);
135
- setTableOfContents(currentTableOfContents);
136
- } else if (lexical.$isElementNode(child)) {
137
- updateChildHeadings(child);
138
- }
139
- }
140
- };
141
-
142
- // If a node is changes, all child heading positions need to be updated
143
- lexical.$getRoot().getChildren().forEach(node => {
144
- if (lexical.$isElementNode(node) && dirtyElements.get(node.__key)) {
145
- updateChildHeadings(node);
146
- }
147
- });
148
- });
149
- });
150
-
151
- // Listen to updates to heading mutations and update state
152
- const removeHeaderMutationListener = editor.registerMutationListener(richText.HeadingNode, mutatedNodes => {
153
- editor.getEditorState().read(() => {
154
- for (const [nodeKey, mutation] of mutatedNodes) {
155
- if (mutation === 'created') {
156
- const newHeading = lexical.$getNodeByKey(nodeKey);
157
- if (newHeading !== null) {
158
- const prevHeading = $getPreviousHeading(newHeading);
159
- currentTableOfContents = $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents);
160
- }
161
- } else if (mutation === 'destroyed') {
162
- currentTableOfContents = $deleteHeadingFromTableOfContents(nodeKey, currentTableOfContents);
163
- } else if (mutation === 'updated') {
164
- const newHeading = lexical.$getNodeByKey(nodeKey);
165
- if (newHeading !== null) {
166
- const prevHeading = $getPreviousHeading(newHeading);
167
- currentTableOfContents = $updateHeadingPosition(prevHeading, newHeading, currentTableOfContents);
168
- }
169
- }
170
- }
171
- setTableOfContents(currentTableOfContents);
172
- });
173
- },
174
- // Initialization is handled separately
175
- {
176
- skipInitialization: true
177
- });
178
-
179
- // Listen to text node mutation updates
180
- const removeTextNodeMutationListener = editor.registerMutationListener(lexical.TextNode, mutatedNodes => {
181
- editor.getEditorState().read(() => {
182
- for (const [nodeKey, mutation] of mutatedNodes) {
183
- if (mutation === 'updated') {
184
- const currNode = lexical.$getNodeByKey(nodeKey);
185
- if (currNode !== null) {
186
- const parentNode = currNode.getParentOrThrow();
187
- if (richText.$isHeadingNode(parentNode)) {
188
- currentTableOfContents = $updateHeadingInTableOfContents(parentNode, currentTableOfContents);
189
- setTableOfContents(currentTableOfContents);
190
- }
191
- }
192
- }
193
- }
194
- });
195
- },
196
- // Initialization is handled separately
197
- {
198
- skipInitialization: true
199
- });
200
- return () => {
201
- removeHeaderMutationListener();
202
- removeTextNodeMutationListener();
203
- removeRootUpdateListener();
204
- };
205
- }, [editor]);
206
- return children(tableOfContents, editor);
207
- }
208
-
209
- /**
210
- * Copyright (c) Meta Platforms, Inc. and affiliates.
211
- *
212
- * This source code is licensed under the MIT license found in the
213
- * LICENSE file in the root directory of this source tree.
214
- *
215
- */
216
-
217
- exports.default = TableOfContentsPlugin;
@@ -1,215 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
10
- import { HeadingNode, $isHeadingNode } from '@lexical/rich-text';
11
- import { $getNextRightPreorderNode } from '@lexical/utils';
12
- import { $getRoot, $isElementNode, $getNodeByKey, TextNode } from 'lexical';
13
- import { useState, useEffect } from 'react';
14
-
15
- /**
16
- * Copyright (c) Meta Platforms, Inc. and affiliates.
17
- *
18
- * This source code is licensed under the MIT license found in the
19
- * LICENSE file in the root directory of this source tree.
20
- *
21
- */
22
-
23
- function toEntry(heading) {
24
- return [heading.getKey(), heading.getTextContent(), heading.getTag()];
25
- }
26
- function $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents) {
27
- if (newHeading === null) {
28
- return currentTableOfContents;
29
- }
30
- const newEntry = toEntry(newHeading);
31
- let newTableOfContents = [];
32
- if (prevHeading === null) {
33
- // check if key already exists
34
- if (currentTableOfContents.length > 0 && currentTableOfContents[0][0] === newHeading.__key) {
35
- return currentTableOfContents;
36
- }
37
- newTableOfContents = [newEntry, ...currentTableOfContents];
38
- } else {
39
- for (let i = 0; i < currentTableOfContents.length; i++) {
40
- const key = currentTableOfContents[i][0];
41
- newTableOfContents.push(currentTableOfContents[i]);
42
- if (key === prevHeading.getKey() && key !== newHeading.getKey()) {
43
- // check if key already exists
44
- if (i + 1 < currentTableOfContents.length && currentTableOfContents[i + 1][0] === newHeading.__key) {
45
- return currentTableOfContents;
46
- }
47
- newTableOfContents.push(newEntry);
48
- }
49
- }
50
- }
51
- return newTableOfContents;
52
- }
53
- function $deleteHeadingFromTableOfContents(key, currentTableOfContents) {
54
- const newTableOfContents = [];
55
- for (const heading of currentTableOfContents) {
56
- if (heading[0] !== key) {
57
- newTableOfContents.push(heading);
58
- }
59
- }
60
- return newTableOfContents;
61
- }
62
- function $updateHeadingInTableOfContents(heading, currentTableOfContents) {
63
- const newTableOfContents = [];
64
- for (const oldHeading of currentTableOfContents) {
65
- if (oldHeading[0] === heading.getKey()) {
66
- newTableOfContents.push(toEntry(heading));
67
- } else {
68
- newTableOfContents.push(oldHeading);
69
- }
70
- }
71
- return newTableOfContents;
72
- }
73
-
74
- /**
75
- * Returns the updated table of contents, placing the given `heading` before the given `prevHeading`. If `prevHeading`
76
- * is undefined, `heading` is placed at the start of table of contents
77
- */
78
- function $updateHeadingPosition(prevHeading, heading, currentTableOfContents) {
79
- const newTableOfContents = [];
80
- const newEntry = toEntry(heading);
81
- if (!prevHeading) {
82
- newTableOfContents.push(newEntry);
83
- }
84
- for (const oldHeading of currentTableOfContents) {
85
- if (oldHeading[0] === heading.getKey()) {
86
- continue;
87
- }
88
- newTableOfContents.push(oldHeading);
89
- if (prevHeading && oldHeading[0] === prevHeading.getKey()) {
90
- newTableOfContents.push(newEntry);
91
- }
92
- }
93
- return newTableOfContents;
94
- }
95
- function $getPreviousHeading(node) {
96
- let prevHeading = $getNextRightPreorderNode(node);
97
- while (prevHeading !== null && !$isHeadingNode(prevHeading)) {
98
- prevHeading = $getNextRightPreorderNode(prevHeading);
99
- }
100
- return prevHeading;
101
- }
102
- function TableOfContentsPlugin({
103
- children
104
- }) {
105
- const [tableOfContents, setTableOfContents] = useState([]);
106
- const [editor] = useLexicalComposerContext();
107
- useEffect(() => {
108
- // Set table of contents initial state
109
- let currentTableOfContents = [];
110
- editor.getEditorState().read(() => {
111
- const updateCurrentTableOfContents = node => {
112
- for (const child of node.getChildren()) {
113
- if ($isHeadingNode(child)) {
114
- currentTableOfContents.push([child.getKey(), child.getTextContent(), child.getTag()]);
115
- } else if ($isElementNode(child)) {
116
- updateCurrentTableOfContents(child);
117
- }
118
- }
119
- };
120
- updateCurrentTableOfContents($getRoot());
121
- setTableOfContents(currentTableOfContents);
122
- });
123
- const removeRootUpdateListener = editor.registerUpdateListener(({
124
- editorState,
125
- dirtyElements
126
- }) => {
127
- editorState.read(() => {
128
- const updateChildHeadings = node => {
129
- for (const child of node.getChildren()) {
130
- if ($isHeadingNode(child)) {
131
- const prevHeading = $getPreviousHeading(child);
132
- currentTableOfContents = $updateHeadingPosition(prevHeading, child, currentTableOfContents);
133
- setTableOfContents(currentTableOfContents);
134
- } else if ($isElementNode(child)) {
135
- updateChildHeadings(child);
136
- }
137
- }
138
- };
139
-
140
- // If a node is changes, all child heading positions need to be updated
141
- $getRoot().getChildren().forEach(node => {
142
- if ($isElementNode(node) && dirtyElements.get(node.__key)) {
143
- updateChildHeadings(node);
144
- }
145
- });
146
- });
147
- });
148
-
149
- // Listen to updates to heading mutations and update state
150
- const removeHeaderMutationListener = editor.registerMutationListener(HeadingNode, mutatedNodes => {
151
- editor.getEditorState().read(() => {
152
- for (const [nodeKey, mutation] of mutatedNodes) {
153
- if (mutation === 'created') {
154
- const newHeading = $getNodeByKey(nodeKey);
155
- if (newHeading !== null) {
156
- const prevHeading = $getPreviousHeading(newHeading);
157
- currentTableOfContents = $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents);
158
- }
159
- } else if (mutation === 'destroyed') {
160
- currentTableOfContents = $deleteHeadingFromTableOfContents(nodeKey, currentTableOfContents);
161
- } else if (mutation === 'updated') {
162
- const newHeading = $getNodeByKey(nodeKey);
163
- if (newHeading !== null) {
164
- const prevHeading = $getPreviousHeading(newHeading);
165
- currentTableOfContents = $updateHeadingPosition(prevHeading, newHeading, currentTableOfContents);
166
- }
167
- }
168
- }
169
- setTableOfContents(currentTableOfContents);
170
- });
171
- },
172
- // Initialization is handled separately
173
- {
174
- skipInitialization: true
175
- });
176
-
177
- // Listen to text node mutation updates
178
- const removeTextNodeMutationListener = editor.registerMutationListener(TextNode, mutatedNodes => {
179
- editor.getEditorState().read(() => {
180
- for (const [nodeKey, mutation] of mutatedNodes) {
181
- if (mutation === 'updated') {
182
- const currNode = $getNodeByKey(nodeKey);
183
- if (currNode !== null) {
184
- const parentNode = currNode.getParentOrThrow();
185
- if ($isHeadingNode(parentNode)) {
186
- currentTableOfContents = $updateHeadingInTableOfContents(parentNode, currentTableOfContents);
187
- setTableOfContents(currentTableOfContents);
188
- }
189
- }
190
- }
191
- }
192
- });
193
- },
194
- // Initialization is handled separately
195
- {
196
- skipInitialization: true
197
- });
198
- return () => {
199
- removeHeaderMutationListener();
200
- removeTextNodeMutationListener();
201
- removeRootUpdateListener();
202
- };
203
- }, [editor]);
204
- return children(tableOfContents, editor);
205
- }
206
-
207
- /**
208
- * Copyright (c) Meta Platforms, Inc. and affiliates.
209
- *
210
- * This source code is licensed under the MIT license found in the
211
- * LICENSE file in the root directory of this source tree.
212
- *
213
- */
214
-
215
- export { TableOfContentsPlugin as default };
@@ -1,11 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- 'use strict'
10
- const LexicalTableOfContents = process.env.NODE_ENV !== 'production' ? require('./LexicalTableOfContents.dev.js') : require('./LexicalTableOfContents.prod.js');
11
- module.exports = LexicalTableOfContents;
@@ -1,13 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict
8
- */
9
-
10
- import {TableOfContentsPlugin} from '@lexical/react/LexicalTableOfContentsPlugin';
11
-
12
- /** @deprecated use the named export {@link LexicalTableOfContentsPlugin} */
13
- declare export default typeof TableOfContentsPlugin;
@@ -1,12 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- import * as modDev from './LexicalTableOfContents.dev.mjs';
10
- import * as modProd from './LexicalTableOfContents.prod.mjs';
11
- const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
12
- export default mod.default;
@@ -1,10 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalTableOfContents.dev.mjs') : import('./LexicalTableOfContents.prod.mjs'));
10
- export default mod.default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("@lexical/rich-text"),n=require("@lexical/utils"),o=require("lexical"),r=require("react");function i(e){return[e.getKey(),e.getTextContent(),e.getTag()]}function s(e,t,n){if(null===t)return n;const o=i(t);let r=[];if(null===e){if(n.length>0&&n[0][0]===t.__key)return n;r=[o,...n]}else for(let i=0;i<n.length;i++){const s=n[i][0];if(r.push(n[i]),s===e.getKey()&&s!==t.getKey()){if(i+1<n.length&&n[i+1][0]===t.__key)return n;r.push(o)}}return r}function u(e,t){const n=[];for(const o of t)o[0]!==e&&n.push(o);return n}function l(e,t){const n=[];for(const o of t)o[0]===e.getKey()?n.push(i(e)):n.push(o);return n}function c(e,t,n){const o=[],r=i(t);e||o.push(r);for(const i of n)i[0]!==t.getKey()&&(o.push(i),e&&i[0]===e.getKey()&&o.push(r));return o}function d(e){let o=n.$getNextRightPreorderNode(e);for(;null!==o&&!t.$isHeadingNode(o);)o=n.$getNextRightPreorderNode(o);return o}exports.default=function({children:n}){const[i,g]=r.useState([]),[f]=e.useLexicalComposerContext();return r.useEffect((()=>{let e=[];f.getEditorState().read((()=>{const n=r=>{for(const i of r.getChildren())t.$isHeadingNode(i)?e.push([i.getKey(),i.getTextContent(),i.getTag()]):o.$isElementNode(i)&&n(i)};n(o.$getRoot()),g(e)}));const n=f.registerUpdateListener((({editorState:n,dirtyElements:r})=>{n.read((()=>{const n=r=>{for(const i of r.getChildren())if(t.$isHeadingNode(i)){const t=d(i);e=c(t,i,e),g(e)}else o.$isElementNode(i)&&n(i)};o.$getRoot().getChildren().forEach((e=>{o.$isElementNode(e)&&r.get(e.__key)&&n(e)}))}))})),r=f.registerMutationListener(t.HeadingNode,(t=>{f.getEditorState().read((()=>{for(const[n,r]of t)if("created"===r){const t=o.$getNodeByKey(n);if(null!==t){const n=d(t);e=s(n,t,e)}}else if("destroyed"===r)e=u(n,e);else if("updated"===r){const t=o.$getNodeByKey(n);if(null!==t){const n=d(t);e=c(n,t,e)}}g(e)}))}),{skipInitialization:!0}),i=f.registerMutationListener(o.TextNode,(n=>{f.getEditorState().read((()=>{for(const[r,i]of n)if("updated"===i){const n=o.$getNodeByKey(r);if(null!==n){const o=n.getParentOrThrow();t.$isHeadingNode(o)&&(e=l(o,e),g(e))}}}))}),{skipInitialization:!0});return()=>{r(),i(),n()}}),[f]),n(i,f)};
@@ -1,9 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{HeadingNode as e,$isHeadingNode as n}from"@lexical/rich-text";import{$getNextRightPreorderNode as r}from"@lexical/utils";import{$getRoot as o,$isElementNode as i,$getNodeByKey as s,TextNode as f}from"lexical";import{useState as c,useEffect as l}from"react";function u(t){return[t.getKey(),t.getTextContent(),t.getTag()]}function a(t,e,n){if(null===e)return n;const r=u(e);let o=[];if(null===t){if(n.length>0&&n[0][0]===e.__key)return n;o=[r,...n]}else for(let i=0;i<n.length;i++){const s=n[i][0];if(o.push(n[i]),s===t.getKey()&&s!==e.getKey()){if(i+1<n.length&&n[i+1][0]===e.__key)return n;o.push(r)}}return o}function g(t,e){const n=[];for(const r of e)r[0]!==t&&n.push(r);return n}function d(t,e){const n=[];for(const r of e)r[0]===t.getKey()?n.push(u(t)):n.push(r);return n}function p(t,e,n){const r=[],o=u(e);t||r.push(o);for(const i of n)i[0]!==e.getKey()&&(r.push(i),t&&i[0]===t.getKey()&&r.push(o));return r}function h(t){let e=r(t);for(;null!==e&&!n(e);)e=r(e);return e}function m({children:r}){const[u,m]=c([]),[y]=t();return l((()=>{let t=[];y.getEditorState().read((()=>{const e=r=>{for(const o of r.getChildren())n(o)?t.push([o.getKey(),o.getTextContent(),o.getTag()]):i(o)&&e(o)};e(o()),m(t)}));const r=y.registerUpdateListener((({editorState:e,dirtyElements:r})=>{e.read((()=>{const e=r=>{for(const o of r.getChildren())if(n(o)){const e=h(o);t=p(e,o,t),m(t)}else i(o)&&e(o)};o().getChildren().forEach((t=>{i(t)&&r.get(t.__key)&&e(t)}))}))})),c=y.registerMutationListener(e,(e=>{y.getEditorState().read((()=>{for(const[n,r]of e)if("created"===r){const e=s(n);if(null!==e){const n=h(e);t=a(n,e,t)}}else if("destroyed"===r)t=g(n,t);else if("updated"===r){const e=s(n);if(null!==e){const n=h(e);t=p(n,e,t)}}m(t)}))}),{skipInitialization:!0}),l=y.registerMutationListener(f,(e=>{y.getEditorState().read((()=>{for(const[r,o]of e)if("updated"===o){const e=s(r);if(null!==e){const r=e.getParentOrThrow();n(r)&&(t=d(r,t),m(t))}}}))}),{skipInitialization:!0});return()=>{c(),l(),r()}}),[y]),r(u,y)}export{m as default};