@lexical/react 0.15.0 → 0.16.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 (118) hide show
  1. package/LexicalAutoEmbedPlugin.dev.js +12 -24
  2. package/LexicalAutoEmbedPlugin.dev.mjs +2 -2
  3. package/LexicalAutoEmbedPlugin.prod.js +4 -5
  4. package/LexicalAutoEmbedPlugin.prod.mjs +1 -1
  5. package/LexicalBlockWithAlignableContents.dev.js +9 -20
  6. package/LexicalBlockWithAlignableContents.dev.mjs +5 -4
  7. package/LexicalBlockWithAlignableContents.prod.js +4 -4
  8. package/LexicalBlockWithAlignableContents.prod.mjs +1 -1
  9. package/LexicalCharacterLimitPlugin.dev.js +10 -22
  10. package/LexicalCharacterLimitPlugin.dev.mjs +5 -5
  11. package/LexicalCharacterLimitPlugin.prod.js +9 -9
  12. package/LexicalCharacterLimitPlugin.prod.mjs +1 -1
  13. package/LexicalCheckListPlugin.dev.js +2 -0
  14. package/LexicalCheckListPlugin.dev.mjs +2 -0
  15. package/LexicalCheckListPlugin.prod.js +2 -2
  16. package/LexicalCheckListPlugin.prod.mjs +1 -1
  17. package/LexicalClearEditorPlugin.dev.js +4 -0
  18. package/LexicalClearEditorPlugin.dev.mjs +4 -0
  19. package/LexicalClickableLinkPlugin.d.ts +3 -1
  20. package/LexicalClickableLinkPlugin.dev.js +3 -2
  21. package/LexicalClickableLinkPlugin.dev.mjs +2 -2
  22. package/LexicalClickableLinkPlugin.js.flow +3 -1
  23. package/LexicalClickableLinkPlugin.mjs +1 -0
  24. package/LexicalClickableLinkPlugin.node.mjs +1 -0
  25. package/LexicalClickableLinkPlugin.prod.js +4 -3
  26. package/LexicalClickableLinkPlugin.prod.mjs +1 -1
  27. package/LexicalCollaborationPlugin.dev.js +2 -1
  28. package/LexicalCollaborationPlugin.dev.mjs +2 -1
  29. package/LexicalCollaborationPlugin.prod.js +9 -9
  30. package/LexicalCollaborationPlugin.prod.mjs +1 -1
  31. package/LexicalComposer.dev.js +12 -19
  32. package/LexicalComposer.dev.mjs +9 -4
  33. package/LexicalComposer.prod.js +3 -4
  34. package/LexicalComposer.prod.mjs +1 -1
  35. package/LexicalContentEditable.dev.js +20 -34
  36. package/LexicalContentEditable.dev.mjs +16 -18
  37. package/LexicalContentEditable.prod.js +3 -4
  38. package/LexicalContentEditable.prod.mjs +1 -1
  39. package/LexicalContextMenuPlugin.dev.js +6 -1
  40. package/LexicalContextMenuPlugin.dev.mjs +6 -1
  41. package/LexicalContextMenuPlugin.prod.js +15 -15
  42. package/LexicalContextMenuPlugin.prod.mjs +1 -1
  43. package/LexicalErrorBoundary.d.ts +3 -1
  44. package/LexicalErrorBoundary.dev.js +11 -7
  45. package/LexicalErrorBoundary.dev.mjs +10 -7
  46. package/LexicalErrorBoundary.js.flow +4 -1
  47. package/LexicalErrorBoundary.mjs +1 -0
  48. package/LexicalErrorBoundary.node.mjs +1 -0
  49. package/LexicalErrorBoundary.prod.js +4 -4
  50. package/LexicalErrorBoundary.prod.mjs +1 -1
  51. package/LexicalHorizontalRuleNode.d.ts +2 -2
  52. package/LexicalHorizontalRuleNode.dev.js +16 -21
  53. package/LexicalHorizontalRuleNode.dev.mjs +13 -6
  54. package/LexicalHorizontalRuleNode.prod.js +5 -5
  55. package/LexicalHorizontalRuleNode.prod.mjs +1 -1
  56. package/LexicalNestedComposer.dev.js +11 -22
  57. package/LexicalNestedComposer.dev.mjs +5 -4
  58. package/LexicalNestedComposer.prod.js +5 -5
  59. package/LexicalNestedComposer.prod.mjs +1 -1
  60. package/LexicalNodeMenuPlugin.dev.js +6 -1
  61. package/LexicalNodeMenuPlugin.dev.mjs +6 -1
  62. package/LexicalNodeMenuPlugin.prod.js +13 -13
  63. package/LexicalNodeMenuPlugin.prod.mjs +1 -1
  64. package/LexicalOnChangePlugin.dev.js +4 -0
  65. package/LexicalOnChangePlugin.dev.mjs +4 -0
  66. package/LexicalPlainTextPlugin.dev.js +24 -28
  67. package/LexicalPlainTextPlugin.dev.mjs +19 -11
  68. package/LexicalPlainTextPlugin.js.flow +1 -1
  69. package/LexicalPlainTextPlugin.prod.js +4 -4
  70. package/LexicalPlainTextPlugin.prod.mjs +1 -1
  71. package/LexicalRichTextPlugin.dev.js +24 -28
  72. package/LexicalRichTextPlugin.dev.mjs +19 -11
  73. package/LexicalRichTextPlugin.js.flow +1 -1
  74. package/LexicalRichTextPlugin.prod.js +4 -4
  75. package/LexicalRichTextPlugin.prod.mjs +1 -1
  76. package/LexicalTableOfContents.d.ts +6 -13
  77. package/LexicalTableOfContents.dev.js +10 -2
  78. package/LexicalTableOfContents.dev.mjs +10 -2
  79. package/LexicalTableOfContents.js.flow +3 -7
  80. package/LexicalTableOfContents.prod.js +1 -1
  81. package/LexicalTableOfContentsPlugin.d.ts +20 -0
  82. package/LexicalTableOfContentsPlugin.dev.js +198 -0
  83. package/LexicalTableOfContentsPlugin.dev.mjs +196 -0
  84. package/LexicalTableOfContentsPlugin.js +11 -0
  85. package/LexicalTableOfContentsPlugin.js.flow +18 -0
  86. package/LexicalTableOfContentsPlugin.mjs +12 -0
  87. package/LexicalTableOfContentsPlugin.node.mjs +10 -0
  88. package/LexicalTableOfContentsPlugin.prod.js +12 -0
  89. package/LexicalTableOfContentsPlugin.prod.mjs +9 -0
  90. package/LexicalTreeView.d.ts +3 -1
  91. package/LexicalTreeView.dev.js +5 -3
  92. package/LexicalTreeView.dev.mjs +5 -3
  93. package/LexicalTreeView.js.flow +2 -0
  94. package/LexicalTreeView.prod.js +3 -3
  95. package/LexicalTreeView.prod.mjs +1 -1
  96. package/LexicalTypeaheadMenuPlugin.dev.js +6 -1
  97. package/LexicalTypeaheadMenuPlugin.dev.mjs +6 -1
  98. package/LexicalTypeaheadMenuPlugin.prod.js +17 -17
  99. package/LexicalTypeaheadMenuPlugin.prod.mjs +1 -1
  100. package/package.json +50 -20
  101. package/useLexicalEditable.d.ts +11 -1
  102. package/useLexicalEditable.dev.js +16 -1
  103. package/useLexicalEditable.dev.mjs +15 -1
  104. package/useLexicalEditable.js.flow +4 -1
  105. package/useLexicalEditable.mjs +2 -1
  106. package/useLexicalEditable.node.mjs +2 -1
  107. package/useLexicalEditable.prod.js +1 -1
  108. package/useLexicalEditable.prod.mjs +1 -1
  109. package/useLexicalIsTextContentEmpty.dev.js +4 -0
  110. package/useLexicalIsTextContentEmpty.dev.mjs +4 -0
  111. package/useLexicalSubscription.d.ts +4 -1
  112. package/useLexicalSubscription.dev.js +7 -1
  113. package/useLexicalSubscription.dev.mjs +6 -1
  114. package/useLexicalSubscription.js.flow +4 -1
  115. package/useLexicalSubscription.mjs +2 -1
  116. package/useLexicalSubscription.node.mjs +2 -1
  117. package/useLexicalSubscription.prod.js +2 -2
  118. package/useLexicalSubscription.prod.mjs +1 -1
@@ -29,6 +29,10 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
29
29
  *
30
30
  */
31
31
 
32
+
33
+ // This workaround is no longer necessary in React 19,
34
+ // but we currently support React >=17.x
35
+ // https://github.com/facebook/react/pull/26395
32
36
  const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
33
37
 
34
38
  /**
@@ -27,6 +27,10 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
27
27
  *
28
28
  */
29
29
 
30
+
31
+ // This workaround is no longer necessary in React 19,
32
+ // but we currently support React >=17.x
33
+ // https://github.com/facebook/react/pull/26395
30
34
  const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
31
35
 
32
36
  /**
@@ -10,26 +10,14 @@
10
10
 
11
11
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
12
12
  var useLexicalEditable = require('@lexical/react/useLexicalEditable');
13
- var React = require('react');
14
13
  var text = require('@lexical/text');
15
14
  var utils = require('@lexical/utils');
15
+ var react = require('react');
16
16
  var reactDom = require('react-dom');
17
+ var jsxRuntime = require('react/jsx-runtime');
17
18
  var dragon = require('@lexical/dragon');
18
19
  var plainText = require('@lexical/plain-text');
19
20
 
20
- function _interopNamespaceDefault(e) {
21
- var n = Object.create(null);
22
- if (e) {
23
- for (var k in e) {
24
- n[k] = e[k];
25
- }
26
- }
27
- n.default = e;
28
- return n;
29
- }
30
-
31
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
32
-
33
21
  /**
34
22
  * Copyright (c) Meta Platforms, Inc. and affiliates.
35
23
  *
@@ -48,7 +36,11 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
48
36
  *
49
37
  */
50
38
 
51
- const useLayoutEffectImpl = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
39
+
40
+ // This workaround is no longer necessary in React 19,
41
+ // but we currently support React >=17.x
42
+ // https://github.com/facebook/react/pull/26395
43
+ const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
52
44
 
53
45
  /**
54
46
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -63,7 +55,7 @@ function canShowPlaceholderFromCurrentEditorState(editor) {
63
55
  return currentCanShowPlaceholder;
64
56
  }
65
57
  function useCanShowPlaceholder(editor) {
66
- const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
58
+ const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
67
59
  useLayoutEffectImpl(() => {
68
60
  function resetCanShowPlaceholder() {
69
61
  const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
@@ -88,7 +80,7 @@ function useCanShowPlaceholder(editor) {
88
80
  */
89
81
 
90
82
  function useDecorators(editor, ErrorBoundary) {
91
- const [decorators, setDecorators] = React.useState(() => editor.getDecorators());
83
+ const [decorators, setDecorators] = react.useState(() => editor.getDecorators());
92
84
 
93
85
  // Subscribe to changes
94
86
  useLayoutEffectImpl(() => {
@@ -98,7 +90,7 @@ function useDecorators(editor, ErrorBoundary) {
98
90
  });
99
91
  });
100
92
  }, [editor]);
101
- React.useEffect(() => {
93
+ react.useEffect(() => {
102
94
  // If the content editable mounts before the subscription is added, then
103
95
  // nothing will be rendered on initial pass. We can get around that by
104
96
  // ensuring that we set the value.
@@ -106,16 +98,18 @@ function useDecorators(editor, ErrorBoundary) {
106
98
  }, [editor]);
107
99
 
108
100
  // Return decorators defined as React Portals
109
- return React.useMemo(() => {
101
+ return react.useMemo(() => {
110
102
  const decoratedPortals = [];
111
103
  const decoratorKeys = Object.keys(decorators);
112
104
  for (let i = 0; i < decoratorKeys.length; i++) {
113
105
  const nodeKey = decoratorKeys[i];
114
- const reactDecorator = /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
115
- onError: e => editor._onError(e)
116
- }, /*#__PURE__*/React__namespace.createElement(React.Suspense, {
117
- fallback: null
118
- }, decorators[nodeKey]));
106
+ const reactDecorator = /*#__PURE__*/jsxRuntime.jsx(ErrorBoundary, {
107
+ onError: e => editor._onError(e),
108
+ children: /*#__PURE__*/jsxRuntime.jsx(react.Suspense, {
109
+ fallback: null,
110
+ children: decorators[nodeKey]
111
+ })
112
+ });
119
113
  const element = editor.getElementByKey(nodeKey);
120
114
  if (element !== null) {
121
115
  decoratedPortals.push( /*#__PURE__*/reactDom.createPortal(reactDecorator, element, nodeKey));
@@ -158,16 +152,18 @@ function PlainTextPlugin({
158
152
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
159
153
  const decorators = useDecorators(editor, ErrorBoundary);
160
154
  usePlainTextSetup(editor);
161
- return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, contentEditable, /*#__PURE__*/React__namespace.createElement(Placeholder, {
162
- content: placeholder
163
- }), decorators);
155
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
156
+ children: [contentEditable, /*#__PURE__*/jsxRuntime.jsx(Placeholder, {
157
+ content: placeholder
158
+ }), decorators]
159
+ });
164
160
  }
165
161
  function Placeholder({
166
162
  content
167
163
  }) {
168
164
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
169
165
  const showPlaceholder = useCanShowPlaceholder(editor);
170
- const editable = useLexicalEditable();
166
+ const editable = useLexicalEditable.useLexicalEditable();
171
167
  if (!showPlaceholder) {
172
168
  return null;
173
169
  }
@@ -7,12 +7,12 @@
7
7
  */
8
8
 
9
9
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
10
- import useLexicalEditable from '@lexical/react/useLexicalEditable';
11
- import * as React from 'react';
12
- import { useLayoutEffect, useEffect, useState, useMemo, Suspense } from 'react';
10
+ import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
13
11
  import { $canShowPlaceholderCurry } from '@lexical/text';
14
12
  import { mergeRegister } from '@lexical/utils';
13
+ import { useLayoutEffect, useEffect, useState, useMemo, Suspense } from 'react';
15
14
  import { flushSync, createPortal } from 'react-dom';
15
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
16
16
  import { registerDragonSupport } from '@lexical/dragon';
17
17
  import { registerPlainText } from '@lexical/plain-text';
18
18
 
@@ -34,6 +34,10 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
34
34
  *
35
35
  */
36
36
 
37
+
38
+ // This workaround is no longer necessary in React 19,
39
+ // but we currently support React >=17.x
40
+ // https://github.com/facebook/react/pull/26395
37
41
  const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
38
42
 
39
43
  /**
@@ -97,11 +101,13 @@ function useDecorators(editor, ErrorBoundary) {
97
101
  const decoratorKeys = Object.keys(decorators);
98
102
  for (let i = 0; i < decoratorKeys.length; i++) {
99
103
  const nodeKey = decoratorKeys[i];
100
- const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
101
- onError: e => editor._onError(e)
102
- }, /*#__PURE__*/React.createElement(Suspense, {
103
- fallback: null
104
- }, decorators[nodeKey]));
104
+ const reactDecorator = /*#__PURE__*/jsx(ErrorBoundary, {
105
+ onError: e => editor._onError(e),
106
+ children: /*#__PURE__*/jsx(Suspense, {
107
+ fallback: null,
108
+ children: decorators[nodeKey]
109
+ })
110
+ });
105
111
  const element = editor.getElementByKey(nodeKey);
106
112
  if (element !== null) {
107
113
  decoratedPortals.push( /*#__PURE__*/createPortal(reactDecorator, element, nodeKey));
@@ -144,9 +150,11 @@ function PlainTextPlugin({
144
150
  const [editor] = useLexicalComposerContext();
145
151
  const decorators = useDecorators(editor, ErrorBoundary);
146
152
  usePlainTextSetup(editor);
147
- return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, /*#__PURE__*/React.createElement(Placeholder, {
148
- content: placeholder
149
- }), decorators);
153
+ return /*#__PURE__*/jsxs(Fragment, {
154
+ children: [contentEditable, /*#__PURE__*/jsx(Placeholder, {
155
+ content: placeholder
156
+ }), decorators]
157
+ });
150
158
  }
151
159
  function Placeholder({
152
160
  content
@@ -9,7 +9,7 @@
9
9
 
10
10
  import type {EditorState, LexicalEditor} from 'lexical';
11
11
 
12
- import typeof LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
12
+ import {typeof LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary';
13
13
 
14
14
  import * as React from 'react';
15
15
 
@@ -6,7 +6,7 @@
6
6
  *
7
7
  */
8
8
 
9
- 'use strict';var b=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/react/useLexicalEditable"),h=require("react"),m=require("@lexical/text"),n=require("@lexical/utils"),p=require("react-dom"),q=require("@lexical/dragon"),r=require("@lexical/plain-text"),v=Object.create(null);if(h)for(var w in h)v[w]=h[w];v.default=h;let x="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
10
- function y(a){return a.getEditorState().read(m.$canShowPlaceholderCurry(a.isComposing()))}function z(a){let [d,c]=h.useState(()=>y(a));x(()=>{function e(){let g=y(a);c(g)}e();return n.mergeRegister(a.registerUpdateListener(()=>{e()}),a.registerEditableListener(()=>{e()}))},[a]);return d}
11
- function A(a,d){let [c,e]=h.useState(()=>a.getDecorators());x(()=>a.registerDecoratorListener(g=>{p.flushSync(()=>{e(g)})}),[a]);h.useEffect(()=>{e(a.getDecorators())},[a]);return h.useMemo(()=>{let g=[],t=Object.keys(c);for(let k=0;k<t.length;k++){let l=t[k],C=v.createElement(d,{onError:B=>a._onError(B)},v.createElement(h.Suspense,{fallback:null},c[l])),u=a.getElementByKey(l);null!==u&&g.push(p.createPortal(C,u,l))}return g},[d,c,a])}
12
- function D(a){x(()=>n.mergeRegister(r.registerPlainText(a),q.registerDragonSupport(a)),[a])}function E({content:a}){var [d]=b.useLexicalComposerContext();d=z(d);let c=f();return d?"function"===typeof a?a(c):a:null}exports.PlainTextPlugin=function({contentEditable:a,placeholder:d,ErrorBoundary:c}){let [e]=b.useLexicalComposerContext();c=A(e,c);D(e);return v.createElement(v.Fragment,null,a,v.createElement(E,{content:d}),c)}
9
+ 'use strict';var e=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/react/useLexicalEditable"),h=require("@lexical/text"),m=require("@lexical/utils"),n=require("react"),p=require("react-dom"),q=require("react/jsx-runtime"),u=require("@lexical/dragon"),v=require("@lexical/plain-text");let w="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?n.useLayoutEffect:n.useEffect;
10
+ function x(a){return a.getEditorState().read(h.$canShowPlaceholderCurry(a.isComposing()))}function y(a){let [c,b]=n.useState(()=>x(a));w(()=>{function d(){let f=x(a);b(f)}d();return m.mergeRegister(a.registerUpdateListener(()=>{d()}),a.registerEditableListener(()=>{d()}))},[a]);return c}
11
+ function z(a,c){let [b,d]=n.useState(()=>a.getDecorators());w(()=>a.registerDecoratorListener(f=>{p.flushSync(()=>{d(f)})}),[a]);n.useEffect(()=>{d(a.getDecorators())},[a]);return n.useMemo(()=>{let f=[],r=Object.keys(b);for(let k=0;k<r.length;k++){let l=r[k],B=q.jsx(c,{onError:A=>a._onError(A),children:q.jsx(n.Suspense,{fallback:null,children:b[l]})}),t=a.getElementByKey(l);null!==t&&f.push(p.createPortal(B,t,l))}return f},[c,b,a])}
12
+ function C(a){w(()=>m.mergeRegister(v.registerPlainText(a),u.registerDragonSupport(a)),[a])}function D({content:a}){var [c]=e.useLexicalComposerContext();c=y(c);let b=g.useLexicalEditable();return c?"function"===typeof a?a(b):a:null}exports.PlainTextPlugin=function({contentEditable:a,placeholder:c,ErrorBoundary:b}){let [d]=e.useLexicalComposerContext();b=z(d,b);C(d);return q.jsxs(q.Fragment,{children:[a,q.jsx(D,{content:c}),b]})}
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import t from"@lexical/react/useLexicalEditable";import*as r from"react";import{useLayoutEffect as o,useEffect as n,useState as c,useMemo as i,Suspense as l}from"react";import{$canShowPlaceholderCurry as a}from"@lexical/text";import{mergeRegister as m}from"@lexical/utils";import{flushSync as u,createPortal as s}from"react-dom";import{registerDragonSupport as f}from"@lexical/dragon";import{registerPlainText as d}from"@lexical/plain-text";const p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?o:n;function E(e){return e.getEditorState().read(a(e.isComposing()))}function x({contentEditable:t,placeholder:o,ErrorBoundary:a}){const[E]=e(),x=function(e,t){const[o,a]=c((()=>e.getDecorators()));return p((()=>e.registerDecoratorListener((e=>{u((()=>{a(e)}))}))),[e]),n((()=>{a(e.getDecorators())}),[e]),i((()=>{const n=[],c=Object.keys(o);for(let i=0;i<c.length;i++){const a=c[i],m=r.createElement(t,{onError:t=>e._onError(t)},r.createElement(l,{fallback:null},o[a])),u=e.getElementByKey(a);null!==u&&n.push(s(m,u,a))}return n}),[t,o,e])}(E,a);return function(e){p((()=>m(d(e),f(e))),[e])}(E),r.createElement(r.Fragment,null,t,r.createElement(g,{content:o}),x)}function g({content:r}){const[o]=e(),n=function(e){const[t,r]=c((()=>E(e)));return p((()=>{function t(){const t=E(e);r(t)}return t(),m(e.registerUpdateListener((()=>{t()})),e.registerEditableListener((()=>{t()})))}),[e]),t}(o),i=t();return n?"function"==typeof r?r(i):r:null}export{x as PlainTextPlugin};
9
+ import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as e}from"@lexical/react/useLexicalEditable";import{$canShowPlaceholderCurry as r}from"@lexical/text";import{mergeRegister as o}from"@lexical/utils";import{useLayoutEffect as n,useEffect as i,useState as c,useMemo as l,Suspense as a}from"react";import{flushSync as m,createPortal as u}from"react-dom";import{jsx as s,jsxs as d,Fragment as f}from"react/jsx-runtime";import{registerDragonSupport as p}from"@lexical/dragon";import{registerPlainText as x}from"@lexical/plain-text";const g="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?n:i;function E(t){return t.getEditorState().read(r(t.isComposing()))}function h({contentEditable:e,placeholder:r,ErrorBoundary:n}){const[E]=t(),h=function(t,e){const[r,o]=c((()=>t.getDecorators()));return g((()=>t.registerDecoratorListener((t=>{m((()=>{o(t)}))}))),[t]),i((()=>{o(t.getDecorators())}),[t]),l((()=>{const o=[],n=Object.keys(r);for(let i=0;i<n.length;i++){const c=n[i],l=s(e,{onError:e=>t._onError(e),children:s(a,{fallback:null,children:r[c]})}),m=t.getElementByKey(c);null!==m&&o.push(u(l,m,c))}return o}),[e,r,t])}(E,n);return function(t){g((()=>o(x(t),p(t))),[t])}(E),d(f,{children:[e,s(w,{content:r}),h]})}function w({content:r}){const[n]=t(),i=function(t){const[e,r]=c((()=>E(t)));return g((()=>{function e(){const e=E(t);r(e)}return e(),o(t.registerUpdateListener((()=>{e()})),t.registerEditableListener((()=>{e()})))}),[t]),e}(n),l=e();return i?"function"==typeof r?r(l):r:null}export{h as PlainTextPlugin};
@@ -10,26 +10,14 @@
10
10
 
11
11
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
12
12
  var useLexicalEditable = require('@lexical/react/useLexicalEditable');
13
- var React = require('react');
14
13
  var text = require('@lexical/text');
15
14
  var utils = require('@lexical/utils');
15
+ var react = require('react');
16
16
  var reactDom = require('react-dom');
17
+ var jsxRuntime = require('react/jsx-runtime');
17
18
  var dragon = require('@lexical/dragon');
18
19
  var richText = require('@lexical/rich-text');
19
20
 
20
- function _interopNamespaceDefault(e) {
21
- var n = Object.create(null);
22
- if (e) {
23
- for (var k in e) {
24
- n[k] = e[k];
25
- }
26
- }
27
- n.default = e;
28
- return n;
29
- }
30
-
31
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
32
-
33
21
  /**
34
22
  * Copyright (c) Meta Platforms, Inc. and affiliates.
35
23
  *
@@ -48,7 +36,11 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
48
36
  *
49
37
  */
50
38
 
51
- const useLayoutEffectImpl = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
39
+
40
+ // This workaround is no longer necessary in React 19,
41
+ // but we currently support React >=17.x
42
+ // https://github.com/facebook/react/pull/26395
43
+ const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
52
44
 
53
45
  /**
54
46
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -63,7 +55,7 @@ function canShowPlaceholderFromCurrentEditorState(editor) {
63
55
  return currentCanShowPlaceholder;
64
56
  }
65
57
  function useCanShowPlaceholder(editor) {
66
- const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
58
+ const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
67
59
  useLayoutEffectImpl(() => {
68
60
  function resetCanShowPlaceholder() {
69
61
  const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
@@ -88,7 +80,7 @@ function useCanShowPlaceholder(editor) {
88
80
  */
89
81
 
90
82
  function useDecorators(editor, ErrorBoundary) {
91
- const [decorators, setDecorators] = React.useState(() => editor.getDecorators());
83
+ const [decorators, setDecorators] = react.useState(() => editor.getDecorators());
92
84
 
93
85
  // Subscribe to changes
94
86
  useLayoutEffectImpl(() => {
@@ -98,7 +90,7 @@ function useDecorators(editor, ErrorBoundary) {
98
90
  });
99
91
  });
100
92
  }, [editor]);
101
- React.useEffect(() => {
93
+ react.useEffect(() => {
102
94
  // If the content editable mounts before the subscription is added, then
103
95
  // nothing will be rendered on initial pass. We can get around that by
104
96
  // ensuring that we set the value.
@@ -106,16 +98,18 @@ function useDecorators(editor, ErrorBoundary) {
106
98
  }, [editor]);
107
99
 
108
100
  // Return decorators defined as React Portals
109
- return React.useMemo(() => {
101
+ return react.useMemo(() => {
110
102
  const decoratedPortals = [];
111
103
  const decoratorKeys = Object.keys(decorators);
112
104
  for (let i = 0; i < decoratorKeys.length; i++) {
113
105
  const nodeKey = decoratorKeys[i];
114
- const reactDecorator = /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
115
- onError: e => editor._onError(e)
116
- }, /*#__PURE__*/React__namespace.createElement(React.Suspense, {
117
- fallback: null
118
- }, decorators[nodeKey]));
106
+ const reactDecorator = /*#__PURE__*/jsxRuntime.jsx(ErrorBoundary, {
107
+ onError: e => editor._onError(e),
108
+ children: /*#__PURE__*/jsxRuntime.jsx(react.Suspense, {
109
+ fallback: null,
110
+ children: decorators[nodeKey]
111
+ })
112
+ });
119
113
  const element = editor.getElementByKey(nodeKey);
120
114
  if (element !== null) {
121
115
  decoratedPortals.push( /*#__PURE__*/reactDom.createPortal(reactDecorator, element, nodeKey));
@@ -158,16 +152,18 @@ function RichTextPlugin({
158
152
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
159
153
  const decorators = useDecorators(editor, ErrorBoundary);
160
154
  useRichTextSetup(editor);
161
- return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, contentEditable, /*#__PURE__*/React__namespace.createElement(Placeholder, {
162
- content: placeholder
163
- }), decorators);
155
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
156
+ children: [contentEditable, /*#__PURE__*/jsxRuntime.jsx(Placeholder, {
157
+ content: placeholder
158
+ }), decorators]
159
+ });
164
160
  }
165
161
  function Placeholder({
166
162
  content
167
163
  }) {
168
164
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
169
165
  const showPlaceholder = useCanShowPlaceholder(editor);
170
- const editable = useLexicalEditable();
166
+ const editable = useLexicalEditable.useLexicalEditable();
171
167
  if (!showPlaceholder) {
172
168
  return null;
173
169
  }
@@ -7,12 +7,12 @@
7
7
  */
8
8
 
9
9
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
10
- import useLexicalEditable from '@lexical/react/useLexicalEditable';
11
- import * as React from 'react';
12
- import { useLayoutEffect, useEffect, useState, useMemo, Suspense } from 'react';
10
+ import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
13
11
  import { $canShowPlaceholderCurry } from '@lexical/text';
14
12
  import { mergeRegister } from '@lexical/utils';
13
+ import { useLayoutEffect, useEffect, useState, useMemo, Suspense } from 'react';
15
14
  import { flushSync, createPortal } from 'react-dom';
15
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
16
16
  import { registerDragonSupport } from '@lexical/dragon';
17
17
  import { registerRichText } from '@lexical/rich-text';
18
18
 
@@ -34,6 +34,10 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
34
34
  *
35
35
  */
36
36
 
37
+
38
+ // This workaround is no longer necessary in React 19,
39
+ // but we currently support React >=17.x
40
+ // https://github.com/facebook/react/pull/26395
37
41
  const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
38
42
 
39
43
  /**
@@ -97,11 +101,13 @@ function useDecorators(editor, ErrorBoundary) {
97
101
  const decoratorKeys = Object.keys(decorators);
98
102
  for (let i = 0; i < decoratorKeys.length; i++) {
99
103
  const nodeKey = decoratorKeys[i];
100
- const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
101
- onError: e => editor._onError(e)
102
- }, /*#__PURE__*/React.createElement(Suspense, {
103
- fallback: null
104
- }, decorators[nodeKey]));
104
+ const reactDecorator = /*#__PURE__*/jsx(ErrorBoundary, {
105
+ onError: e => editor._onError(e),
106
+ children: /*#__PURE__*/jsx(Suspense, {
107
+ fallback: null,
108
+ children: decorators[nodeKey]
109
+ })
110
+ });
105
111
  const element = editor.getElementByKey(nodeKey);
106
112
  if (element !== null) {
107
113
  decoratedPortals.push( /*#__PURE__*/createPortal(reactDecorator, element, nodeKey));
@@ -144,9 +150,11 @@ function RichTextPlugin({
144
150
  const [editor] = useLexicalComposerContext();
145
151
  const decorators = useDecorators(editor, ErrorBoundary);
146
152
  useRichTextSetup(editor);
147
- return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, /*#__PURE__*/React.createElement(Placeholder, {
148
- content: placeholder
149
- }), decorators);
153
+ return /*#__PURE__*/jsxs(Fragment, {
154
+ children: [contentEditable, /*#__PURE__*/jsx(Placeholder, {
155
+ content: placeholder
156
+ }), decorators]
157
+ });
150
158
  }
151
159
  function Placeholder({
152
160
  content
@@ -9,7 +9,7 @@
9
9
 
10
10
  import type {EditorState, LexicalEditor} from 'lexical';
11
11
 
12
- import typeof LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
12
+ import {typeof LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary';
13
13
 
14
14
  import * as React from 'react';
15
15
 
@@ -6,7 +6,7 @@
6
6
  *
7
7
  */
8
8
 
9
- 'use strict';var b=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/react/useLexicalEditable"),h=require("react"),m=require("@lexical/text"),n=require("@lexical/utils"),p=require("react-dom"),q=require("@lexical/dragon"),r=require("@lexical/rich-text"),v=Object.create(null);if(h)for(var w in h)v[w]=h[w];v.default=h;let x="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
10
- function y(a){return a.getEditorState().read(m.$canShowPlaceholderCurry(a.isComposing()))}function z(a){let [d,c]=h.useState(()=>y(a));x(()=>{function e(){let g=y(a);c(g)}e();return n.mergeRegister(a.registerUpdateListener(()=>{e()}),a.registerEditableListener(()=>{e()}))},[a]);return d}
11
- function A(a,d){let [c,e]=h.useState(()=>a.getDecorators());x(()=>a.registerDecoratorListener(g=>{p.flushSync(()=>{e(g)})}),[a]);h.useEffect(()=>{e(a.getDecorators())},[a]);return h.useMemo(()=>{let g=[],t=Object.keys(c);for(let k=0;k<t.length;k++){let l=t[k],C=v.createElement(d,{onError:B=>a._onError(B)},v.createElement(h.Suspense,{fallback:null},c[l])),u=a.getElementByKey(l);null!==u&&g.push(p.createPortal(C,u,l))}return g},[d,c,a])}
12
- function D(a){x(()=>n.mergeRegister(r.registerRichText(a),q.registerDragonSupport(a)),[a])}function E({content:a}){var [d]=b.useLexicalComposerContext();d=z(d);let c=f();return d?"function"===typeof a?a(c):a:null}exports.RichTextPlugin=function({contentEditable:a,placeholder:d,ErrorBoundary:c}){let [e]=b.useLexicalComposerContext();c=A(e,c);D(e);return v.createElement(v.Fragment,null,a,v.createElement(E,{content:d}),c)}
9
+ 'use strict';var e=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/react/useLexicalEditable"),h=require("@lexical/text"),m=require("@lexical/utils"),n=require("react"),p=require("react-dom"),q=require("react/jsx-runtime"),u=require("@lexical/dragon"),v=require("@lexical/rich-text");let w="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?n.useLayoutEffect:n.useEffect;
10
+ function x(a){return a.getEditorState().read(h.$canShowPlaceholderCurry(a.isComposing()))}function y(a){let [c,b]=n.useState(()=>x(a));w(()=>{function d(){let f=x(a);b(f)}d();return m.mergeRegister(a.registerUpdateListener(()=>{d()}),a.registerEditableListener(()=>{d()}))},[a]);return c}
11
+ function z(a,c){let [b,d]=n.useState(()=>a.getDecorators());w(()=>a.registerDecoratorListener(f=>{p.flushSync(()=>{d(f)})}),[a]);n.useEffect(()=>{d(a.getDecorators())},[a]);return n.useMemo(()=>{let f=[],r=Object.keys(b);for(let k=0;k<r.length;k++){let l=r[k],B=q.jsx(c,{onError:A=>a._onError(A),children:q.jsx(n.Suspense,{fallback:null,children:b[l]})}),t=a.getElementByKey(l);null!==t&&f.push(p.createPortal(B,t,l))}return f},[c,b,a])}
12
+ function C(a){w(()=>m.mergeRegister(v.registerRichText(a),u.registerDragonSupport(a)),[a])}function D({content:a}){var [c]=e.useLexicalComposerContext();c=y(c);let b=g.useLexicalEditable();return c?"function"===typeof a?a(b):a:null}exports.RichTextPlugin=function({contentEditable:a,placeholder:c,ErrorBoundary:b}){let [d]=e.useLexicalComposerContext();b=z(d,b);C(d);return q.jsxs(q.Fragment,{children:[a,q.jsx(D,{content:c}),b]})}
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import t from"@lexical/react/useLexicalEditable";import*as r from"react";import{useLayoutEffect as o,useEffect as n,useState as c,useMemo as i,Suspense as l}from"react";import{$canShowPlaceholderCurry as a}from"@lexical/text";import{mergeRegister as m}from"@lexical/utils";import{flushSync as u,createPortal as s}from"react-dom";import{registerDragonSupport as f}from"@lexical/dragon";import{registerRichText as d}from"@lexical/rich-text";const p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?o:n;function E(e){return e.getEditorState().read(a(e.isComposing()))}function x({contentEditable:t,placeholder:o,ErrorBoundary:a}){const[E]=e(),x=function(e,t){const[o,a]=c((()=>e.getDecorators()));return p((()=>e.registerDecoratorListener((e=>{u((()=>{a(e)}))}))),[e]),n((()=>{a(e.getDecorators())}),[e]),i((()=>{const n=[],c=Object.keys(o);for(let i=0;i<c.length;i++){const a=c[i],m=r.createElement(t,{onError:t=>e._onError(t)},r.createElement(l,{fallback:null},o[a])),u=e.getElementByKey(a);null!==u&&n.push(s(m,u,a))}return n}),[t,o,e])}(E,a);return function(e){p((()=>m(d(e),f(e))),[e])}(E),r.createElement(r.Fragment,null,t,r.createElement(g,{content:o}),x)}function g({content:r}){const[o]=e(),n=function(e){const[t,r]=c((()=>E(e)));return p((()=>{function t(){const t=E(e);r(t)}return t(),m(e.registerUpdateListener((()=>{t()})),e.registerEditableListener((()=>{t()})))}),[e]),t}(o),i=t();return n?"function"==typeof r?r(i):r:null}export{x as RichTextPlugin};
9
+ import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as e}from"@lexical/react/useLexicalEditable";import{$canShowPlaceholderCurry as r}from"@lexical/text";import{mergeRegister as o}from"@lexical/utils";import{useLayoutEffect as n,useEffect as i,useState as c,useMemo as l,Suspense as a}from"react";import{flushSync as m,createPortal as u}from"react-dom";import{jsx as s,jsxs as d,Fragment as f}from"react/jsx-runtime";import{registerDragonSupport as p}from"@lexical/dragon";import{registerRichText as x}from"@lexical/rich-text";const g="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?n:i;function E(t){return t.getEditorState().read(r(t.isComposing()))}function h({contentEditable:e,placeholder:r,ErrorBoundary:n}){const[E]=t(),h=function(t,e){const[r,o]=c((()=>t.getDecorators()));return g((()=>t.registerDecoratorListener((t=>{m((()=>{o(t)}))}))),[t]),i((()=>{o(t.getDecorators())}),[t]),l((()=>{const o=[],n=Object.keys(r);for(let i=0;i<n.length;i++){const c=n[i],l=s(e,{onError:e=>t._onError(e),children:s(a,{fallback:null,children:r[c]})}),m=t.getElementByKey(c);null!==m&&o.push(u(l,m,c))}return o}),[e,r,t])}(E,n);return function(t){g((()=>o(x(t),p(t))),[t])}(E),d(f,{children:[e,s(w,{content:r}),h]})}function w({content:r}){const[n]=t(),i=function(t){const[e,r]=c((()=>E(t)));return g((()=>{function e(){const e=E(t);r(e)}return e(),o(t.registerUpdateListener((()=>{e()})),t.registerEditableListener((()=>{e()})))}),[t]),e}(n),l=e();return i?"function"==typeof r?r(l):r:null}export{h as RichTextPlugin};
@@ -5,16 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- /// <reference types="react" />
9
- import { HeadingTagType } from '@lexical/rich-text';
10
- import { LexicalEditor, NodeKey } from 'lexical';
11
- export type TableOfContentsEntry = [
12
- key: NodeKey,
13
- text: string,
14
- tag: HeadingTagType
15
- ];
16
- type Props = {
17
- children: (values: Array<TableOfContentsEntry>, editor: LexicalEditor) => JSX.Element;
18
- };
19
- export default function LexicalTableOfContentsPlugin({ children, }: Props): JSX.Element;
20
- export {};
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;
@@ -101,7 +101,7 @@ function $getPreviousHeading(node) {
101
101
  }
102
102
  return prevHeading;
103
103
  }
104
- function LexicalTableOfContentsPlugin({
104
+ function TableOfContentsPlugin({
105
105
  children
106
106
  }) {
107
107
  const [tableOfContents, setTableOfContents] = react.useState([]);
@@ -195,4 +195,12 @@ function LexicalTableOfContentsPlugin({
195
195
  return children(tableOfContents, editor);
196
196
  }
197
197
 
198
- module.exports = LexicalTableOfContentsPlugin;
198
+ /**
199
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
200
+ *
201
+ * This source code is licensed under the MIT license found in the
202
+ * LICENSE file in the root directory of this source tree.
203
+ *
204
+ */
205
+
206
+ exports.default = TableOfContentsPlugin;
@@ -99,7 +99,7 @@ function $getPreviousHeading(node) {
99
99
  }
100
100
  return prevHeading;
101
101
  }
102
- function LexicalTableOfContentsPlugin({
102
+ function TableOfContentsPlugin({
103
103
  children
104
104
  }) {
105
105
  const [tableOfContents, setTableOfContents] = useState([]);
@@ -193,4 +193,12 @@ function LexicalTableOfContentsPlugin({
193
193
  return children(tableOfContents, editor);
194
194
  }
195
195
 
196
- export { LexicalTableOfContentsPlugin as default };
196
+ /**
197
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
198
+ *
199
+ * This source code is licensed under the MIT license found in the
200
+ * LICENSE file in the root directory of this source tree.
201
+ *
202
+ */
203
+
204
+ export { TableOfContentsPlugin as default };
@@ -7,11 +7,7 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type {HeadingTagType} from '@lexical/rich-text';
11
- import type {NodeKey} from 'lexical';
10
+ import {TableOfContentsPlugin} from '@lexical/react/LexicalTableOfContentsPlugin';
12
11
 
13
- declare export default function LexicalTableOfContentsPlugin({
14
- children: (
15
- tableOfContents: Array<[NodeKey, string, HeadingTagType]>,
16
- ) => React$Node,
17
- }): React$Node;
12
+ /** @deprecated use the named export {@link LexicalTableOfContentsPlugin} */
13
+ declare export default typeof TableOfContentsPlugin;
@@ -7,6 +7,6 @@
7
7
  */
8
8
 
9
9
  'use strict';var h=require("@lexical/react/LexicalComposerContext"),q=require("@lexical/rich-text"),v=require("@lexical/utils"),w=require("lexical"),x=require("react");function y(d){return[d.getKey(),d.getTextContent(),d.getTag()]}function z(d,t,n){let e=[],c=y(t);d||e.push(c);for(let r of n)r[0]!==t.getKey()&&(e.push(r),d&&r[0]===d.getKey()&&e.push(c));return e}function B(d){for(d=v.$getNextRightPreorderNode(d);null!==d&&!q.$isHeadingNode(d);)d=v.$getNextRightPreorderNode(d);return d}
10
- module.exports=function({children:d}){let [t,n]=x.useState([]),[e]=h.useLexicalComposerContext();x.useEffect(()=>{let c=[];e.getEditorState().read(()=>{let l=w.$getRoot().getChildren();for(let a of l)q.$isHeadingNode(a)&&c.push([a.getKey(),a.getTextContent(),a.getTag()]);n(c)});let r=e.registerUpdateListener(({editorState:l,dirtyElements:a})=>{l.read(()=>{const f=b=>{for(const g of b.getChildren())q.$isHeadingNode(g)?(b=B(g),c=z(b,g,c),n(c)):w.$isElementNode(g)&&f(g)};w.$getRoot().getChildren().forEach(b=>
10
+ exports.default=function({children:d}){let [t,n]=x.useState([]),[e]=h.useLexicalComposerContext();x.useEffect(()=>{let c=[];e.getEditorState().read(()=>{let l=w.$getRoot().getChildren();for(let a of l)q.$isHeadingNode(a)&&c.push([a.getKey(),a.getTextContent(),a.getTag()]);n(c)});let r=e.registerUpdateListener(({editorState:l,dirtyElements:a})=>{l.read(()=>{const f=b=>{for(const g of b.getChildren())q.$isHeadingNode(g)?(b=B(g),c=z(b,g,c),n(c)):w.$isElementNode(g)&&f(g)};w.$getRoot().getChildren().forEach(b=>
11
11
  {w.$isElementNode(b)&&a.get(b.__key)&&f(b)})})}),C=e.registerMutationListener(q.HeadingNode,l=>{e.getEditorState().read(()=>{for(const [g,m]of l)if("created"===m){var a=w.$getNodeByKey(g);if(null!==a)a:{var f=B(a),b=c;if(null===a){c=b;break a}let k=y(a),u=[];if(null===f){if(0<b.length&&b[0][0]===a.__key){c=b;break a}u=[k,...b]}else for(let p=0;p<b.length;p++){let A=b[p][0];u.push(b[p]);if(A===f.getKey()&&A!==a.getKey()){if(p+1<b.length&&b[p+1][0]===a.__key){c=b;break a}u.push(k)}}c=u}}else if("destroyed"===
12
12
  m){f=g;a=c;b=[];for(let k of a)k[0]!==f&&b.push(k);c=b}else"updated"===m&&(f=w.$getNodeByKey(g),null!==f&&(a=B(f),c=z(a,f,c)));n(c)})}),D=e.registerMutationListener(w.TextNode,l=>{e.getEditorState().read(()=>{for(const [b,g]of l)if("updated"===g){var a=w.$getNodeByKey(b);if(null!==a&&(a=a.getParentOrThrow(),q.$isHeadingNode(a))){var f=c;let m=[];for(let k of f)k[0]===a.getKey()?m.push(y(a)):m.push(k);c=m;n(c)}}})});return()=>{C();D();r()}},[e]);return d(t,e)}
@@ -0,0 +1,20 @@
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
+ /// <reference types="react" />
9
+ import { HeadingTagType } from '@lexical/rich-text';
10
+ import { LexicalEditor, NodeKey } from 'lexical';
11
+ export type TableOfContentsEntry = [
12
+ key: NodeKey,
13
+ text: string,
14
+ tag: HeadingTagType
15
+ ];
16
+ type Props = {
17
+ children: (values: Array<TableOfContentsEntry>, editor: LexicalEditor) => JSX.Element;
18
+ };
19
+ export declare function TableOfContentsPlugin({ children }: Props): JSX.Element;
20
+ export {};