@lexical/react 0.45.1-nightly.20260608.0 → 0.45.1-nightly.20260610.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LexicalComposer.d.ts +9 -0
- package/dist/LexicalComposer.dev.js +4 -0
- package/dist/LexicalComposer.dev.mjs +4 -0
- package/dist/LexicalComposer.js.flow +1 -0
- package/dist/LexicalComposer.prod.js +1 -1
- package/dist/LexicalComposer.prod.mjs +1 -1
- package/dist/LexicalTableOfContentsPlugin.dev.js +2 -2
- package/dist/LexicalTableOfContentsPlugin.dev.mjs +2 -2
- package/dist/LexicalTableOfContentsPlugin.prod.js +1 -1
- package/dist/LexicalTableOfContentsPlugin.prod.mjs +1 -1
- package/package.json +19 -19
- package/src/LexicalComposer.tsx +11 -0
- package/src/LexicalTableOfContentsPlugin.tsx +4 -4
|
@@ -36,6 +36,15 @@ export type InitialConfigType = Readonly<{
|
|
|
36
36
|
namespace: string;
|
|
37
37
|
nodes?: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>;
|
|
38
38
|
onError: (error: Error, editor: LexicalEditor) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Optional handler for recoverable, warn-level conditions (e.g. the
|
|
41
|
+
* update-recursion guard tripping) that the editor has already recovered
|
|
42
|
+
* from. Mirrors {@link InitialConfigType.onError} but at warn severity, so
|
|
43
|
+
* embedders can route the condition to telemetry without raising an error
|
|
44
|
+
* alarm. Defaults (in core `createEditor`) to a handler that throws in
|
|
45
|
+
* development and only `console.warn`s in production.
|
|
46
|
+
*/
|
|
47
|
+
onWarn?: (error: Error, editor: LexicalEditor) => void;
|
|
39
48
|
editable?: boolean;
|
|
40
49
|
theme?: EditorThemeClasses;
|
|
41
50
|
/**
|
|
@@ -73,6 +73,7 @@ function LexicalComposer({
|
|
|
73
73
|
namespace,
|
|
74
74
|
nodes,
|
|
75
75
|
onError,
|
|
76
|
+
onWarn,
|
|
76
77
|
editorState: initialEditorState,
|
|
77
78
|
html
|
|
78
79
|
} = initialConfig;
|
|
@@ -83,6 +84,9 @@ function LexicalComposer({
|
|
|
83
84
|
namespace,
|
|
84
85
|
nodes,
|
|
85
86
|
onError: error => onError(error, editor),
|
|
87
|
+
...(onWarn ? {
|
|
88
|
+
onWarn: error => onWarn(error, editor)
|
|
89
|
+
} : {}),
|
|
86
90
|
theme
|
|
87
91
|
});
|
|
88
92
|
initializeEditor(editor, initialEditorState);
|
|
@@ -71,6 +71,7 @@ function LexicalComposer({
|
|
|
71
71
|
namespace,
|
|
72
72
|
nodes,
|
|
73
73
|
onError,
|
|
74
|
+
onWarn,
|
|
74
75
|
editorState: initialEditorState,
|
|
75
76
|
html
|
|
76
77
|
} = initialConfig;
|
|
@@ -81,6 +82,9 @@ function LexicalComposer({
|
|
|
81
82
|
namespace,
|
|
82
83
|
nodes,
|
|
83
84
|
onError: error => onError(error, editor),
|
|
85
|
+
...(onWarn ? {
|
|
86
|
+
onWarn: error => onWarn(error, editor)
|
|
87
|
+
} : {}),
|
|
84
88
|
theme
|
|
85
89
|
});
|
|
86
90
|
initializeEditor(editor, initialEditorState);
|
|
@@ -29,6 +29,7 @@ export type InitialConfigType = Readonly<{
|
|
|
29
29
|
theme?: EditorThemeClasses,
|
|
30
30
|
editorState?: InitialEditorStateType,
|
|
31
31
|
onError: (error: Error, editor: LexicalEditor) => void,
|
|
32
|
+
onWarn?: (error: Error, editor: LexicalEditor) => void,
|
|
32
33
|
html?: HTMLConfig,
|
|
33
34
|
}>;
|
|
34
35
|
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),o=require("react"),r=require("react/jsx-runtime");const
|
|
9
|
+
"use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),o=require("react"),r=require("react/jsx-runtime");const n=t.CAN_USE_DOM?o.useLayoutEffect:o.useEffect,a={tag:t.HISTORY_MERGE_TAG};exports.LexicalComposer=function({initialConfig:i,children:c}){const s=o.useMemo(()=>{const{theme:o,namespace:r,nodes:n,onError:c,onWarn:s,editorState:l,html:u}=i,d=e.createLexicalComposerContext(null,o),m=t.createEditor({editable:i.editable,html:u,namespace:r,nodes:n,onError:e=>c(e,m),...s?{onWarn:e=>s(e,m)}:{},theme:o});return function(e,o){if(null===o)return;if(void 0===o)e.update(()=>{const o=t.$getRoot();if(o.isEmpty()){const r=t.$createParagraphNode();o.append(r);const n=t.CAN_USE_DOM?document.activeElement:null;(null!==t.$getSelection()||null!==n&&n===e.getRootElement())&&r.select()}},a);else if(null!==o)switch(typeof o){case"string":{const t=e.parseEditorState(o);e.setEditorState(t,a);break}case"object":e.setEditorState(o,a);break;case"function":e.update(()=>{t.$getRoot().isEmpty()&&o(e)},a)}}(m,l),[m,d]},[]);return n(()=>{const e=i.editable,[t]=s;t.setEditable(void 0===e||e)},[]),r.jsx(e.LexicalComposerContext.Provider,{value:s,children:c})};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{createLexicalComposerContext as t,LexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{CAN_USE_DOM as
|
|
9
|
+
import{createLexicalComposerContext as t,LexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{CAN_USE_DOM as n,createEditor as o,$getRoot as r,$createParagraphNode as i,$getSelection as a,HISTORY_MERGE_TAG as l}from"lexical";import{useLayoutEffect as c,useEffect as s,useMemo as m}from"react";import{jsx as d}from"react/jsx-runtime";const u=n?c:s,p={tag:l};function f({initialConfig:l,children:c}){const s=m(()=>{const{theme:e,namespace:c,nodes:s,onError:m,onWarn:d,editorState:u,html:f}=l,E=t(null,e),b=o({editable:l.editable,html:f,namespace:c,nodes:s,onError:t=>m(t,b),...d?{onWarn:t=>d(t,b)}:{},theme:e});return function(t,e){if(null===e)return;if(void 0===e)t.update(()=>{const e=r();if(e.isEmpty()){const o=i();e.append(o);const r=n?document.activeElement:null;(null!==a()||null!==r&&r===t.getRootElement())&&o.select()}},p);else if(null!==e)switch(typeof e){case"string":{const n=t.parseEditorState(e);t.setEditorState(n,p);break}case"object":t.setEditorState(e,p);break;case"function":t.update(()=>{r().isEmpty()&&e(t)},p)}}(b,u),[b,E]},[]);return u(()=>{const t=l.editable,[e]=s;e.setEditable(void 0===t||t)},[]),d(e.Provider,{value:s,children:c})}export{f as LexicalComposer};
|
|
@@ -154,7 +154,7 @@ function TableOfContentsPlugin({
|
|
|
154
154
|
for (const [nodeKey, mutation] of mutatedNodes) {
|
|
155
155
|
if (mutation === 'created') {
|
|
156
156
|
const newHeading = lexical.$getNodeByKey(nodeKey);
|
|
157
|
-
if (newHeading
|
|
157
|
+
if (richText.$isHeadingNode(newHeading)) {
|
|
158
158
|
const prevHeading = $getPreviousHeading(newHeading);
|
|
159
159
|
currentTableOfContents = $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents);
|
|
160
160
|
}
|
|
@@ -162,7 +162,7 @@ function TableOfContentsPlugin({
|
|
|
162
162
|
currentTableOfContents = $deleteHeadingFromTableOfContents(nodeKey, currentTableOfContents);
|
|
163
163
|
} else if (mutation === 'updated') {
|
|
164
164
|
const newHeading = lexical.$getNodeByKey(nodeKey);
|
|
165
|
-
if (newHeading
|
|
165
|
+
if (richText.$isHeadingNode(newHeading)) {
|
|
166
166
|
const prevHeading = $getPreviousHeading(newHeading);
|
|
167
167
|
currentTableOfContents = $updateHeadingPosition(prevHeading, newHeading, currentTableOfContents);
|
|
168
168
|
}
|
|
@@ -152,7 +152,7 @@ function TableOfContentsPlugin({
|
|
|
152
152
|
for (const [nodeKey, mutation] of mutatedNodes) {
|
|
153
153
|
if (mutation === 'created') {
|
|
154
154
|
const newHeading = $getNodeByKey(nodeKey);
|
|
155
|
-
if (newHeading
|
|
155
|
+
if ($isHeadingNode(newHeading)) {
|
|
156
156
|
const prevHeading = $getPreviousHeading(newHeading);
|
|
157
157
|
currentTableOfContents = $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents);
|
|
158
158
|
}
|
|
@@ -160,7 +160,7 @@ function TableOfContentsPlugin({
|
|
|
160
160
|
currentTableOfContents = $deleteHeadingFromTableOfContents(nodeKey, currentTableOfContents);
|
|
161
161
|
} else if (mutation === 'updated') {
|
|
162
162
|
const newHeading = $getNodeByKey(nodeKey);
|
|
163
|
-
if (newHeading
|
|
163
|
+
if ($isHeadingNode(newHeading)) {
|
|
164
164
|
const prevHeading = $getPreviousHeading(newHeading);
|
|
165
165
|
currentTableOfContents = $updateHeadingPosition(prevHeading, newHeading, currentTableOfContents);
|
|
166
166
|
}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
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
|
|
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 d(e,t){const n=[];for(const o of t)o[0]!==e&&n.push(o);return n}function u(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 g(e){let o=n.$getNextRightPreorderNode(e);for(;null!==o&&!t.$isHeadingNode(o);)o=n.$getNextRightPreorderNode(o);return o}exports.TableOfContentsPlugin=function({children:n}){const[i,l]=r.useState([]),[a]=e.useLexicalComposerContext();return r.useEffect(()=>{let e=[];a.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()),l(e)});const n=a.registerUpdateListener(({editorState:n,dirtyElements:r})=>{n.read(()=>{const n=r=>{for(const i of r.getChildren())if(t.$isHeadingNode(i)){const t=g(i);e=c(t,i,e),l(e)}else o.$isElementNode(i)&&n(i)};o.$getRoot().getChildren().forEach(e=>{o.$isElementNode(e)&&r.get(e.__key)&&n(e)})})}),r=a.registerMutationListener(t.HeadingNode,n=>{a.getEditorState().read(()=>{for(const[r,i]of n)if("created"===i){const n=o.$getNodeByKey(r);if(t.$isHeadingNode(n)){const t=g(n);e=s(t,n,e)}}else if("destroyed"===i)e=d(r,e);else if("updated"===i){const n=o.$getNodeByKey(r);if(t.$isHeadingNode(n)){const t=g(n);e=c(t,n,e)}}l(e)})},{skipInitialization:!0}),i=a.registerMutationListener(o.TextNode,n=>{a.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=u(o,e),l(e))}}})},{skipInitialization:!0});return()=>{r(),i(),n()}},[a]),n(i,a)};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
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[
|
|
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[r,o]of e)if("created"===o){const e=s(r);if(n(e)){const n=h(e);t=a(n,e,t)}}else if("destroyed"===o)t=g(r,t);else if("updated"===o){const e=s(r);if(n(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 TableOfContentsPlugin};
|
package/package.json
CHANGED
|
@@ -8,28 +8,28 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.45.1-nightly.
|
|
11
|
+
"version": "0.45.1-nightly.20260610.0",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@floating-ui/react": "^0.27.19",
|
|
14
14
|
"react-error-boundary": "^6.1.1",
|
|
15
|
-
"@lexical/
|
|
16
|
-
"@lexical/
|
|
17
|
-
"@lexical/
|
|
18
|
-
"@lexical/history": "0.45.1-nightly.
|
|
19
|
-
"@lexical/
|
|
20
|
-
"@lexical/
|
|
21
|
-
"@lexical/
|
|
22
|
-
"@lexical/list": "0.45.1-nightly.
|
|
23
|
-
"@lexical/mark": "0.45.1-nightly.
|
|
24
|
-
"@lexical/markdown": "0.45.1-nightly.
|
|
25
|
-
"@lexical/overflow": "0.45.1-nightly.
|
|
26
|
-
"@lexical/
|
|
27
|
-
"@lexical/
|
|
28
|
-
"@lexical/table": "0.45.1-nightly.
|
|
29
|
-
"@lexical/text": "0.45.1-nightly.
|
|
30
|
-
"@lexical/
|
|
31
|
-
"lexical": "0.45.1-nightly.
|
|
32
|
-
"
|
|
15
|
+
"@lexical/dragon": "0.45.1-nightly.20260610.0",
|
|
16
|
+
"@lexical/devtools-core": "0.45.1-nightly.20260610.0",
|
|
17
|
+
"@lexical/extension": "0.45.1-nightly.20260610.0",
|
|
18
|
+
"@lexical/history": "0.45.1-nightly.20260610.0",
|
|
19
|
+
"@lexical/hashtag": "0.45.1-nightly.20260610.0",
|
|
20
|
+
"@lexical/internal": "0.45.1-nightly.20260610.0",
|
|
21
|
+
"@lexical/link": "0.45.1-nightly.20260610.0",
|
|
22
|
+
"@lexical/list": "0.45.1-nightly.20260610.0",
|
|
23
|
+
"@lexical/mark": "0.45.1-nightly.20260610.0",
|
|
24
|
+
"@lexical/markdown": "0.45.1-nightly.20260610.0",
|
|
25
|
+
"@lexical/overflow": "0.45.1-nightly.20260610.0",
|
|
26
|
+
"@lexical/rich-text": "0.45.1-nightly.20260610.0",
|
|
27
|
+
"@lexical/plain-text": "0.45.1-nightly.20260610.0",
|
|
28
|
+
"@lexical/table": "0.45.1-nightly.20260610.0",
|
|
29
|
+
"@lexical/text": "0.45.1-nightly.20260610.0",
|
|
30
|
+
"@lexical/yjs": "0.45.1-nightly.20260610.0",
|
|
31
|
+
"@lexical/utils": "0.45.1-nightly.20260610.0",
|
|
32
|
+
"lexical": "0.45.1-nightly.20260610.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": ">=17.x",
|
package/src/LexicalComposer.tsx
CHANGED
|
@@ -68,6 +68,15 @@ export type InitialConfigType = Readonly<{
|
|
|
68
68
|
namespace: string;
|
|
69
69
|
nodes?: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>;
|
|
70
70
|
onError: (error: Error, editor: LexicalEditor) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Optional handler for recoverable, warn-level conditions (e.g. the
|
|
73
|
+
* update-recursion guard tripping) that the editor has already recovered
|
|
74
|
+
* from. Mirrors {@link InitialConfigType.onError} but at warn severity, so
|
|
75
|
+
* embedders can route the condition to telemetry without raising an error
|
|
76
|
+
* alarm. Defaults (in core `createEditor`) to a handler that throws in
|
|
77
|
+
* development and only `console.warn`s in production.
|
|
78
|
+
*/
|
|
79
|
+
onWarn?: (error: Error, editor: LexicalEditor) => void;
|
|
71
80
|
editable?: boolean;
|
|
72
81
|
theme?: EditorThemeClasses;
|
|
73
82
|
/**
|
|
@@ -96,6 +105,7 @@ export function LexicalComposer({initialConfig, children}: Props): JSX.Element {
|
|
|
96
105
|
namespace,
|
|
97
106
|
nodes,
|
|
98
107
|
onError,
|
|
108
|
+
onWarn,
|
|
99
109
|
editorState: initialEditorState,
|
|
100
110
|
html,
|
|
101
111
|
} = initialConfig;
|
|
@@ -111,6 +121,7 @@ export function LexicalComposer({initialConfig, children}: Props): JSX.Element {
|
|
|
111
121
|
namespace,
|
|
112
122
|
nodes,
|
|
113
123
|
onError: error => onError(error, editor),
|
|
124
|
+
...(onWarn ? {onWarn: error => onWarn(error, editor)} : {}),
|
|
114
125
|
theme,
|
|
115
126
|
});
|
|
116
127
|
initializeEditor(editor, initialEditorState);
|
|
@@ -207,8 +207,8 @@ export function TableOfContentsPlugin({children}: Props): JSX.Element {
|
|
|
207
207
|
editor.getEditorState().read(() => {
|
|
208
208
|
for (const [nodeKey, mutation] of mutatedNodes) {
|
|
209
209
|
if (mutation === 'created') {
|
|
210
|
-
const newHeading = $getNodeByKey
|
|
211
|
-
if (newHeading
|
|
210
|
+
const newHeading = $getNodeByKey(nodeKey);
|
|
211
|
+
if ($isHeadingNode(newHeading)) {
|
|
212
212
|
const prevHeading = $getPreviousHeading(newHeading);
|
|
213
213
|
currentTableOfContents = $insertHeadingIntoTableOfContents(
|
|
214
214
|
prevHeading,
|
|
@@ -222,8 +222,8 @@ export function TableOfContentsPlugin({children}: Props): JSX.Element {
|
|
|
222
222
|
currentTableOfContents,
|
|
223
223
|
);
|
|
224
224
|
} else if (mutation === 'updated') {
|
|
225
|
-
const newHeading = $getNodeByKey
|
|
226
|
-
if (newHeading
|
|
225
|
+
const newHeading = $getNodeByKey(nodeKey);
|
|
226
|
+
if ($isHeadingNode(newHeading)) {
|
|
227
227
|
const prevHeading = $getPreviousHeading(newHeading);
|
|
228
228
|
currentTableOfContents = $updateHeadingPosition(
|
|
229
229
|
prevHeading,
|