@lexical/react 0.5.1-next.1 → 0.6.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/DEPRECATED_useLexicalDecorators.d.ts +1 -1
- package/DEPRECATED_useLexicalDecorators.dev.js +5 -116
- package/DEPRECATED_useLexicalDecorators.js.flow +1 -2
- package/DEPRECATED_useLexicalDecorators.prod.js +2 -6
- package/LexicalCollaborationContext.d.ts +1 -1
- package/LexicalCollaborationContext.dev.js +6 -2
- package/LexicalCollaborationContext.prod.js +3 -2
- package/LexicalCollaborationPlugin.d.ts +2 -1
- package/LexicalCollaborationPlugin.dev.js +2 -1
- package/LexicalCollaborationPlugin.prod.js +4 -4
- package/LexicalErrorBoundary.d.ts +13 -0
- package/LexicalErrorBoundary.dev.js +159 -0
- package/LexicalErrorBoundary.js +9 -0
- package/LexicalErrorBoundary.js.flow +14 -0
- package/LexicalErrorBoundary.prod.js +10 -0
- package/LexicalPlainTextPlugin.d.ts +1 -1
- package/LexicalPlainTextPlugin.dev.js +5 -116
- package/LexicalPlainTextPlugin.js.flow +1 -2
- package/LexicalPlainTextPlugin.prod.js +4 -6
- package/LexicalRichTextPlugin.d.ts +1 -1
- package/LexicalRichTextPlugin.dev.js +5 -116
- package/LexicalRichTextPlugin.js.flow +1 -2
- package/LexicalRichTextPlugin.prod.js +4 -6
- package/LexicalTablePlugin.dev.js +34 -6
- package/LexicalTablePlugin.prod.js +4 -4
- package/package.json +20 -19
- package/shared/useDecorators.d.ts +1 -1
- package/shared/ReactErrorBoundary.d.ts +0 -63
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { LexicalEditor } from 'lexical';
|
|
9
9
|
import { ErrorBoundaryType } from './shared/useDecorators';
|
|
10
|
-
export declare function useLexicalDecorators(editor: LexicalEditor, ErrorBoundary
|
|
10
|
+
export declare function useLexicalDecorators(editor: LexicalEditor, ErrorBoundary: ErrorBoundaryType): Array<JSX.Element>;
|
|
@@ -9,103 +9,6 @@
|
|
|
9
9
|
var React = require('react');
|
|
10
10
|
var reactDom = require('react-dom');
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
const changedArray = (a = [], b = []) => a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
21
|
-
|
|
22
|
-
const initialState = {
|
|
23
|
-
error: null
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
class ErrorBoundary extends React.Component {
|
|
27
|
-
constructor(props) {
|
|
28
|
-
super(props);
|
|
29
|
-
this.state = initialState;
|
|
30
|
-
this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static getDerivedStateFromError(error) {
|
|
34
|
-
return {
|
|
35
|
-
error
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
resetErrorBoundary(...args) {
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
// eslint-disable-next-line no-unused-expressions
|
|
42
|
-
this.props.onReset && this.props.onReset(...args);
|
|
43
|
-
this.reset();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
reset() {
|
|
47
|
-
this.setState(initialState);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
componentDidCatch(error, info) {
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
// eslint-disable-next-line no-unused-expressions
|
|
53
|
-
this.props.onError && this.props.onError(error, info);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
componentDidUpdate(prevProps, prevState) {
|
|
57
|
-
const {
|
|
58
|
-
error
|
|
59
|
-
} = this.state;
|
|
60
|
-
const {
|
|
61
|
-
resetKeys
|
|
62
|
-
} = this.props; // There's an edge case where if the thing that triggered the error
|
|
63
|
-
// happens to *also* be in the resetKeys array, we'd end up resetting
|
|
64
|
-
// the error boundary immediately. This would likely trigger a second
|
|
65
|
-
// error to be thrown.
|
|
66
|
-
// So we make sure that we don't check the resetKeys on the first call
|
|
67
|
-
// of cDU after the error is set
|
|
68
|
-
|
|
69
|
-
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
70
|
-
// @ts-ignore
|
|
71
|
-
// eslint-disable-next-line no-unused-expressions
|
|
72
|
-
this.props.onResetKeysChange && this.props.onResetKeysChange(prevProps.resetKeys, resetKeys);
|
|
73
|
-
this.reset();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
render() {
|
|
78
|
-
const {
|
|
79
|
-
error
|
|
80
|
-
} = this.state;
|
|
81
|
-
const {
|
|
82
|
-
fallbackRender,
|
|
83
|
-
FallbackComponent,
|
|
84
|
-
fallback
|
|
85
|
-
} = this.props;
|
|
86
|
-
|
|
87
|
-
if (error !== null) {
|
|
88
|
-
const props = {
|
|
89
|
-
error,
|
|
90
|
-
resetErrorBoundary: this.resetErrorBoundary
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
if ( /*#__PURE__*/React.isValidElement(fallback)) {
|
|
94
|
-
return fallback;
|
|
95
|
-
} else if (typeof fallbackRender === 'function') {
|
|
96
|
-
return fallbackRender(props);
|
|
97
|
-
} else if (FallbackComponent) {
|
|
98
|
-
return /*#__PURE__*/React.createElement(FallbackComponent, props);
|
|
99
|
-
} else {
|
|
100
|
-
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return this.props.children;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
12
|
/**
|
|
110
13
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
111
14
|
*
|
|
@@ -132,14 +35,7 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
132
35
|
* LICENSE file in the root directory of this source tree.
|
|
133
36
|
*
|
|
134
37
|
*/
|
|
135
|
-
function useDecorators(editor,
|
|
136
|
-
ErrorBoundary$1 = ({
|
|
137
|
-
children,
|
|
138
|
-
onError
|
|
139
|
-
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
140
|
-
fallback: null,
|
|
141
|
-
onError: onError
|
|
142
|
-
}, children)) {
|
|
38
|
+
function useDecorators(editor, ErrorBoundary) {
|
|
143
39
|
const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
|
|
144
40
|
|
|
145
41
|
useLayoutEffect(() => {
|
|
@@ -162,7 +58,7 @@ ErrorBoundary$1 = ({
|
|
|
162
58
|
|
|
163
59
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
164
60
|
const nodeKey = decoratorKeys[i];
|
|
165
|
-
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary
|
|
61
|
+
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
166
62
|
onError: e => editor._onError(e)
|
|
167
63
|
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
168
64
|
fallback: null
|
|
@@ -175,7 +71,7 @@ ErrorBoundary$1 = ({
|
|
|
175
71
|
}
|
|
176
72
|
|
|
177
73
|
return decoratedPortals;
|
|
178
|
-
}, [ErrorBoundary
|
|
74
|
+
}, [ErrorBoundary, decorators, editor]);
|
|
179
75
|
}
|
|
180
76
|
|
|
181
77
|
/**
|
|
@@ -185,15 +81,8 @@ ErrorBoundary$1 = ({
|
|
|
185
81
|
* LICENSE file in the root directory of this source tree.
|
|
186
82
|
*
|
|
187
83
|
*/
|
|
188
|
-
function useLexicalDecorators(editor,
|
|
189
|
-
|
|
190
|
-
children,
|
|
191
|
-
onError
|
|
192
|
-
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
193
|
-
fallback: null,
|
|
194
|
-
onError: onError
|
|
195
|
-
}, children)) {
|
|
196
|
-
return useDecorators(editor, ErrorBoundary$1);
|
|
84
|
+
function useLexicalDecorators(editor, ErrorBoundary) {
|
|
85
|
+
return useDecorators(editor, ErrorBoundary);
|
|
197
86
|
}
|
|
198
87
|
|
|
199
88
|
exports.useLexicalDecorators = useLexicalDecorators;
|
|
@@ -20,6 +20,5 @@ export type ErrorBoundaryType = React.AbstractComponent<ErrorBoundaryProps>;
|
|
|
20
20
|
|
|
21
21
|
declare export function useLexicalDecorators(
|
|
22
22
|
editor: LexicalEditor,
|
|
23
|
-
|
|
24
|
-
ErrorBoundary?: ErrorBoundaryType,
|
|
23
|
+
ErrorBoundary: ErrorBoundaryType,
|
|
25
24
|
): Array<React.Node>;
|
|
@@ -4,9 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var
|
|
8
|
-
|
|
9
|
-
d),this.reset())}render(){var {error:a}=this.state;let {fallbackRender:b,FallbackComponent:c,fallback:d}=this.props;if(null!==a){a={error:a,resetErrorBoundary:this.resetErrorBoundary};if(e.isValidElement(d))return d;if("function"===typeof b)return b(a);if(c)return e.createElement(c,a);throw Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");}return this.props.children}}
|
|
10
|
-
var q="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;
|
|
11
|
-
function r(a,b=({children:c,onError:d})=>e.createElement(p,{fallback:null,onError:d},c)){let [c,d]=e.useState(()=>a.getDecorators());q(()=>a.registerDecoratorListener(g=>{k.flushSync(()=>{d(g)})}),[a]);e.useEffect(()=>{d(a.getDecorators())},[a]);return e.useMemo(()=>{let g=[],n=Object.keys(c);for(let h=0;h<n.length;h++){var f=n[h];let u=e.createElement(b,{onError:t=>a._onError(t)},e.createElement(e.Suspense,{fallback:null},c[f]));f=a.getElementByKey(f);null!==f&&g.push(k.createPortal(u,f))}return g},
|
|
12
|
-
[b,c,a])}exports.useLexicalDecorators=function(a,b=({children:c,onError:d})=>e.createElement(p,{fallback:null,onError:d},c)){return r(a,b)}
|
|
7
|
+
'use strict';var b=require("react"),h=require("react-dom"),m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?b.useLayoutEffect:b.useEffect;
|
|
8
|
+
function n(a,d){let [f,k]=b.useState(()=>a.getDecorators());m(()=>a.registerDecoratorListener(e=>{h.flushSync(()=>{k(e)})}),[a]);b.useEffect(()=>{k(a.getDecorators())},[a]);return b.useMemo(()=>{let e=[],l=Object.keys(f);for(let g=0;g<l.length;g++){var c=l[g];let q=b.createElement(d,{onError:p=>a._onError(p)},b.createElement(b.Suspense,{fallback:null},f[c]));c=a.getElementByKey(c);null!==c&&e.push(h.createPortal(q,c))}return e},[d,f,a])}exports.useLexicalDecorators=function(a,d){return n(a,d)}
|
|
@@ -15,5 +15,5 @@ declare type CollaborationContextType = {
|
|
|
15
15
|
yjsDocMap: Map<string, Doc>;
|
|
16
16
|
};
|
|
17
17
|
export declare const CollaborationContext: import("react").Context<CollaborationContextType>;
|
|
18
|
-
export declare function useCollaborationContext(username?: string): CollaborationContextType;
|
|
18
|
+
export declare function useCollaborationContext(username?: string, color?: string): CollaborationContextType;
|
|
19
19
|
export {};
|
|
@@ -15,7 +15,7 @@ var react = require('react');
|
|
|
15
15
|
* LICENSE file in the root directory of this source tree.
|
|
16
16
|
*
|
|
17
17
|
*/
|
|
18
|
-
const entries = [['Cat', '255,165,0'], ['Dog', '0,200,55'], ['Rabbit', '160,0,200'], ['Frog', '0,172,200'], ['Fox', '197,200,0'], ['Hedgehog', '31,200,0'], ['Pigeon', '200,0,0'], ['Squirrel', '200,0,148'], ['Bear', '255,235,0'], ['Tiger', '86,255,0'], ['Leopard', '0,255,208'], ['Zebra', '0,243,255'], ['Wolf', '0,102,255'], ['Owl', '147,0,255'], ['Gull', '255,0,153'], ['Squid', '0,220,255']];
|
|
18
|
+
const entries = [['Cat', 'rgb(255,165,0)'], ['Dog', 'rgb(0,200,55)'], ['Rabbit', 'rgb(160,0,200)'], ['Frog', 'rgb(0,172,200)'], ['Fox', 'rgb(197,200,0)'], ['Hedgehog', 'rgb(31,200,0)'], ['Pigeon', 'rgb(200,0,0)'], ['Squirrel', 'rgb(200,0,148)'], ['Bear', 'rgb(255,235,0)'], ['Tiger', 'rgb(86,255,0)'], ['Leopard', 'rgb(0,255,208)'], ['Zebra', 'rgb(0,243,255)'], ['Wolf', 'rgb(0,102,255)'], ['Owl', 'rgb(147,0,255)'], ['Gull', 'rgb(255,0,153)'], ['Squid', 'rgb(0,220,255)']];
|
|
19
19
|
const randomEntry = entries[Math.floor(Math.random() * entries.length)];
|
|
20
20
|
const CollaborationContext = /*#__PURE__*/react.createContext({
|
|
21
21
|
clientID: 0,
|
|
@@ -24,13 +24,17 @@ const CollaborationContext = /*#__PURE__*/react.createContext({
|
|
|
24
24
|
name: randomEntry[0],
|
|
25
25
|
yjsDocMap: new Map()
|
|
26
26
|
});
|
|
27
|
-
function useCollaborationContext(username) {
|
|
27
|
+
function useCollaborationContext(username, color) {
|
|
28
28
|
const collabContext = react.useContext(CollaborationContext);
|
|
29
29
|
|
|
30
30
|
if (username != null) {
|
|
31
31
|
collabContext.name = username;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
if (color != null) {
|
|
35
|
+
collabContext.color = color;
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
return collabContext;
|
|
35
39
|
}
|
|
36
40
|
|
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var
|
|
8
|
-
|
|
7
|
+
'use strict';var b=require("react");
|
|
8
|
+
let c=[["Cat","rgb(255,165,0)"],["Dog","rgb(0,200,55)"],["Rabbit","rgb(160,0,200)"],["Frog","rgb(0,172,200)"],["Fox","rgb(197,200,0)"],["Hedgehog","rgb(31,200,0)"],["Pigeon","rgb(200,0,0)"],["Squirrel","rgb(200,0,148)"],["Bear","rgb(255,235,0)"],["Tiger","rgb(86,255,0)"],["Leopard","rgb(0,255,208)"],["Zebra","rgb(0,243,255)"],["Wolf","rgb(0,102,255)"],["Owl","rgb(147,0,255)"],["Gull","rgb(255,0,153)"],["Squid","rgb(0,220,255)"]],d=c[Math.floor(Math.random()*c.length)],e=b.createContext({clientID:0,
|
|
9
|
+
color:d[1],isCollabActive:!1,name:d[0],yjsDocMap:new Map});exports.CollaborationContext=e;exports.useCollaborationContext=function(f,g){let a=b.useContext(e);null!=f&&(a.name=f);null!=g&&(a.color=g);return a}
|
|
@@ -9,11 +9,12 @@ import type { Doc } from 'yjs';
|
|
|
9
9
|
import { WebsocketProvider } from 'y-websocket';
|
|
10
10
|
import { InitialEditorStateType } from './LexicalComposer';
|
|
11
11
|
import { CursorsContainerRef } from './shared/useYjsCollaboration';
|
|
12
|
-
export declare function CollaborationPlugin({ id, providerFactory, shouldBootstrap, username, cursorsContainerRef, initialEditorState, }: {
|
|
12
|
+
export declare function CollaborationPlugin({ id, providerFactory, shouldBootstrap, username, cursorColor, cursorsContainerRef, initialEditorState, }: {
|
|
13
13
|
id: string;
|
|
14
14
|
providerFactory: (id: string, yjsDocMap: Map<string, Doc>) => WebsocketProvider;
|
|
15
15
|
shouldBootstrap: boolean;
|
|
16
16
|
username?: string;
|
|
17
|
+
cursorColor?: string;
|
|
17
18
|
cursorsContainerRef?: CursorsContainerRef;
|
|
18
19
|
initialEditorState?: InitialEditorStateType;
|
|
19
20
|
}): JSX.Element;
|
|
@@ -284,10 +284,11 @@ function CollaborationPlugin({
|
|
|
284
284
|
providerFactory,
|
|
285
285
|
shouldBootstrap,
|
|
286
286
|
username,
|
|
287
|
+
cursorColor,
|
|
287
288
|
cursorsContainerRef,
|
|
288
289
|
initialEditorState
|
|
289
290
|
}) {
|
|
290
|
-
const collabContext = LexicalCollaborationContext.useCollaborationContext(username);
|
|
291
|
+
const collabContext = LexicalCollaborationContext.useCollaborationContext(username, cursorColor);
|
|
291
292
|
const {
|
|
292
293
|
yjsDocMap,
|
|
293
294
|
name,
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var e=require("@lexical/react/LexicalCollaborationContext"),f=require("@lexical/react/LexicalComposerContext"),h=require("react"),z=require("@lexical/utils"),H=require("@lexical/yjs"),I=require("lexical"),J=require("react-dom");
|
|
8
|
-
function K(b,c,a,d,p,w,
|
|
9
|
-
a,k)};H.initLocalState(a,p,w,document.activeElement===b.getRootElement());let F=k=>{M(b,g);
|
|
10
|
-
A.off("update",D);
|
|
8
|
+
function K(b,c,a,d,p,w,x,l,t){let q=h.useRef(!1),[u,r]=h.useState(d.get(c)),g=h.useMemo(()=>H.createBinding(b,a,c,u,d),[b,a,c,d,u]),n=h.useCallback(()=>{a.connect()},[a]),v=h.useCallback(()=>{try{a.disconnect()}catch(m){}},[a]);h.useEffect(()=>{let {root:m}=g,{awareness:A}=a,B=({status:k})=>{b.dispatchCommand(H.CONNECTED_COMMAND,"connected"===k)},C=k=>{x&&k&&m.isEmpty()&&0===m._xmlText._length&&!1===q.current&&L(b,t);q.current=!1},D=()=>{H.syncCursorPositions(g,a)},E=(k,y)=>{y.origin!==g&&H.syncYjsChangesToLexical(g,
|
|
9
|
+
a,k)};H.initLocalState(a,p,w,document.activeElement===b.getRootElement());let F=k=>{M(b,g);r(k);d.set(c,k);q.current=!0};a.on("reload",F);a.on("status",B);a.on("sync",C);A.on("update",D);m.getSharedType().observeDeep(E);let Q=b.registerUpdateListener(({prevEditorState:k,editorState:y,dirtyLeaves:N,dirtyElements:O,normalizedNodes:P,tags:G})=>{!1===G.has("skip-collab")&&H.syncLexicalUpdateToYjs(g,a,k,y,O,N,P,G)});n();return()=>{!1===q.current&&v();a.off("sync",C);a.off("status",B);a.off("reload",F);
|
|
10
|
+
A.off("update",D);m.getSharedType().unobserveDeep(E);d.delete(c);Q()}},[g,w,n,v,d,b,c,t,p,a,x]);let R=h.useMemo(()=>J.createPortal(h.createElement("div",{ref:m=>{g.cursorsContainer=m}}),l&&l.current||document.body),[g,l]);h.useEffect(()=>b.registerCommand(H.TOGGLE_CONNECT_COMMAND,m=>{void 0!==n&&void 0!==v&&(m?(console.log("Collaboration connected!"),n()):(console.log("Collaboration disconnected!"),v()));return!0},I.COMMAND_PRIORITY_EDITOR),[n,v,b]);return[R,g]}
|
|
11
11
|
function S(b,c,a,d){h.useEffect(()=>z.mergeRegister(b.registerCommand(I.FOCUS_COMMAND,()=>{H.setLocalStateFocus(c,a,d,!0);return!0},I.COMMAND_PRIORITY_EDITOR),b.registerCommand(I.BLUR_COMMAND,()=>{H.setLocalStateFocus(c,a,d,!1);return!0},I.COMMAND_PRIORITY_EDITOR)),[d,b,a,c])}
|
|
12
12
|
function T(b,c){let a=h.useMemo(()=>H.createUndoManager(c,c.root.getSharedType()),[c]);h.useEffect(()=>z.mergeRegister(b.registerCommand(I.UNDO_COMMAND,()=>{a.undo();return!0},I.COMMAND_PRIORITY_EDITOR),b.registerCommand(I.REDO_COMMAND,()=>{a.redo();return!0},I.COMMAND_PRIORITY_EDITOR)));return h.useCallback(()=>{a.clear()},[a])}
|
|
13
13
|
function L(b,c){b.update(()=>{var a=I.$getRoot();if(a.isEmpty())if(c)switch(typeof c){case "string":var d=b.parseEditorState(c);b.setEditorState(d,{tag:"history-merge"});break;case "object":b.setEditorState(c,{tag:"history-merge"});break;case "function":b.update(()=>{I.$getRoot().isEmpty()&&c(b)},{tag:"history-merge"})}else d=I.$createParagraphNode(),a.append(d),{activeElement:a}=document,(null!==I.$getSelection()||null!==a&&a===b.getRootElement())&&d.select()},{tag:"history-merge"})}
|
|
14
14
|
function M(b,c){b.update(()=>{let d=I.$getRoot();d.clear();d.select()},{tag:"skip-collab"});if(null!=c.cursors&&(b=c.cursors,null!=b&&(c=c.cursorsContainer,null!=c))){b=Array.from(b.values());for(let d=0;d<b.length;d++){var a=b[d].selection;if(a&&null!=a.selections){a=a.selections;for(let p=0;p<a.length;p++)c.removeChild(a[d])}}}}
|
|
15
|
-
exports.CollaborationPlugin=function({id:b,providerFactory:c,shouldBootstrap:a,username:d,
|
|
15
|
+
exports.CollaborationPlugin=function({id:b,providerFactory:c,shouldBootstrap:a,username:d,cursorColor:p,cursorsContainerRef:w,initialEditorState:x}){let l=e.useCollaborationContext(d,p),{yjsDocMap:t,name:q,color:u}=l,[r]=f.useLexicalComposerContext();h.useEffect(()=>{l.isCollabActive=!0;return()=>{null==r._parentEditor&&(l.isCollabActive=!1)}},[l,r]);d=h.useMemo(()=>c(b,t),[b,c,t]);let [g,n]=K(r,b,d,t,q,u,a,w,x);l.clientID=n.clientID;T(r,n);S(r,d,q,u);return g}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
declare type Props = {
|
|
9
|
+
children: JSX.Element;
|
|
10
|
+
onError: (error: Error) => void;
|
|
11
|
+
};
|
|
12
|
+
export default function LexicalErrorBoundary({ children, onError, }: Props): JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var React = require('react');
|
|
10
|
+
|
|
11
|
+
function _setPrototypeOf(o, p) {
|
|
12
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
13
|
+
o.__proto__ = p;
|
|
14
|
+
return o;
|
|
15
|
+
};
|
|
16
|
+
return _setPrototypeOf(o, p);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function _inheritsLoose(subClass, superClass) {
|
|
20
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
21
|
+
subClass.prototype.constructor = subClass;
|
|
22
|
+
_setPrototypeOf(subClass, superClass);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var changedArray = function changedArray(a, b) {
|
|
26
|
+
if (a === void 0) {
|
|
27
|
+
a = [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (b === void 0) {
|
|
31
|
+
b = [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return a.length !== b.length || a.some(function (item, index) {
|
|
35
|
+
return !Object.is(item, b[index]);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
var initialState = {
|
|
40
|
+
error: null
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
44
|
+
_inheritsLoose(ErrorBoundary, _React$Component);
|
|
45
|
+
|
|
46
|
+
function ErrorBoundary() {
|
|
47
|
+
var _this;
|
|
48
|
+
|
|
49
|
+
for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
50
|
+
_args[_key] = arguments[_key];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
|
|
54
|
+
_this.state = initialState;
|
|
55
|
+
|
|
56
|
+
_this.resetErrorBoundary = function () {
|
|
57
|
+
var _this$props;
|
|
58
|
+
|
|
59
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
60
|
+
args[_key2] = arguments[_key2];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
_this.props.onReset == null ? void 0 : (_this$props = _this.props).onReset.apply(_this$props, args);
|
|
64
|
+
|
|
65
|
+
_this.reset();
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return _this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
|
|
72
|
+
return {
|
|
73
|
+
error: error
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
var _proto = ErrorBoundary.prototype;
|
|
78
|
+
|
|
79
|
+
_proto.reset = function reset() {
|
|
80
|
+
this.setState(initialState);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
_proto.componentDidCatch = function componentDidCatch(error, info) {
|
|
84
|
+
var _this$props$onError, _this$props2;
|
|
85
|
+
|
|
86
|
+
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
90
|
+
var error = this.state.error;
|
|
91
|
+
var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
|
|
92
|
+
// happens to *also* be in the resetKeys array, we'd end up resetting
|
|
93
|
+
// the error boundary immediately. This would likely trigger a second
|
|
94
|
+
// error to be thrown.
|
|
95
|
+
// So we make sure that we don't check the resetKeys on the first call
|
|
96
|
+
// of cDU after the error is set
|
|
97
|
+
|
|
98
|
+
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
99
|
+
var _this$props$onResetKe, _this$props3;
|
|
100
|
+
|
|
101
|
+
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
102
|
+
this.reset();
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
_proto.render = function render() {
|
|
107
|
+
var error = this.state.error;
|
|
108
|
+
var _this$props4 = this.props,
|
|
109
|
+
fallbackRender = _this$props4.fallbackRender,
|
|
110
|
+
FallbackComponent = _this$props4.FallbackComponent,
|
|
111
|
+
fallback = _this$props4.fallback;
|
|
112
|
+
|
|
113
|
+
if (error !== null) {
|
|
114
|
+
var _props = {
|
|
115
|
+
error: error,
|
|
116
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
if ( /*#__PURE__*/React.isValidElement(fallback)) {
|
|
120
|
+
return fallback;
|
|
121
|
+
} else if (typeof fallbackRender === 'function') {
|
|
122
|
+
return fallbackRender(_props);
|
|
123
|
+
} else if (FallbackComponent) {
|
|
124
|
+
return /*#__PURE__*/React.createElement(FallbackComponent, _props);
|
|
125
|
+
} else {
|
|
126
|
+
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return this.props.children;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return ErrorBoundary;
|
|
134
|
+
}(React.Component);
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
138
|
+
*
|
|
139
|
+
* This source code is licensed under the MIT license found in the
|
|
140
|
+
* LICENSE file in the root directory of this source tree.
|
|
141
|
+
*
|
|
142
|
+
*/
|
|
143
|
+
function LexicalErrorBoundary({
|
|
144
|
+
children,
|
|
145
|
+
onError
|
|
146
|
+
}) {
|
|
147
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
148
|
+
fallback: /*#__PURE__*/React.createElement("div", {
|
|
149
|
+
style: {
|
|
150
|
+
border: '1px solid #f00',
|
|
151
|
+
color: '#f00',
|
|
152
|
+
padding: '8px'
|
|
153
|
+
}
|
|
154
|
+
}, "An error was thrown."),
|
|
155
|
+
onError: onError
|
|
156
|
+
}, children);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
module.exports = LexicalErrorBoundary;
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
'use strict'
|
|
8
|
+
const LexicalErrorBoundary = process.env.NODE_ENV === 'development' ? require('./LexicalErrorBoundary.dev.js') : require('./LexicalErrorBoundary.prod.js')
|
|
9
|
+
module.exports = LexicalErrorBoundary;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
type Props = $ReadOnly<{
|
|
10
|
+
children: JSX.Element,
|
|
11
|
+
onError: (error: Error) => void,
|
|
12
|
+
}>;
|
|
13
|
+
|
|
14
|
+
declare export default function LexicalErrorBoundary(): React.ReactNode;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
'use strict';var h=require("react");function m(b,c){m=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(g,a){g.__proto__=a;return g};return m(b,c)}function n(b,c){b.prototype=Object.create(c.prototype);b.prototype.constructor=b;m(b,c)}function r(b,c){void 0===b&&(b=[]);void 0===c&&(c=[]);return b.length!==c.length||b.some(function(g,a){return!Object.is(g,c[a])})}
|
|
8
|
+
var t={error:null},u=function(b){function c(){for(var a,d=arguments.length,f=Array(d),e=0;e<d;e++)f[e]=arguments[e];a=b.call.apply(b,[this].concat(f))||this;a.state=t;a.resetErrorBoundary=function(){for(var k,p=arguments.length,q=Array(p),l=0;l<p;l++)q[l]=arguments[l];null==a.props.onReset?void 0:(k=a.props).onReset.apply(k,q);a.reset()};return a}n(c,b);c.getDerivedStateFromError=function(a){return{error:a}};var g=c.prototype;g.reset=function(){this.setState(t)};g.componentDidCatch=function(a,d){var f,
|
|
9
|
+
e;null==(f=(e=this.props).onError)?void 0:f.call(e,a,d)};g.componentDidUpdate=function(a,d){var f=this.props.resetKeys;if(null!==this.state.error&&null!==d.error&&r(a.resetKeys,f)){var e,k;null==(e=(k=this.props).onResetKeysChange)?void 0:e.call(k,a.resetKeys,f);this.reset()}};g.render=function(){var a=this.state.error,d=this.props,f=d.fallbackRender,e=d.FallbackComponent;d=d.fallback;if(null!==a){a={error:a,resetErrorBoundary:this.resetErrorBoundary};if(h.isValidElement(d))return d;if("function"===
|
|
10
|
+
typeof f)return f(a);if(e)return h.createElement(e,a);throw Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");}return this.props.children};return c}(h.Component);module.exports=function({children:b,onError:c}){return h.createElement(u,{fallback:h.createElement("div",{style:{border:"1px solid #f00",color:"#f00",padding:"8px"}},"An error was thrown."),onError:c},b)}
|
|
@@ -9,5 +9,5 @@ import { ErrorBoundaryType } from './shared/useDecorators';
|
|
|
9
9
|
export declare function PlainTextPlugin({ contentEditable, placeholder, ErrorBoundary, }: {
|
|
10
10
|
contentEditable: JSX.Element;
|
|
11
11
|
placeholder: JSX.Element | string;
|
|
12
|
-
ErrorBoundary
|
|
12
|
+
ErrorBoundary: ErrorBoundaryType;
|
|
13
13
|
}): JSX.Element;
|
|
@@ -14,103 +14,6 @@ var reactDom = require('react-dom');
|
|
|
14
14
|
var dragon = require('@lexical/dragon');
|
|
15
15
|
var plainText = require('@lexical/plain-text');
|
|
16
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
|
-
const changedArray = (a = [], b = []) => a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
26
|
-
|
|
27
|
-
const initialState = {
|
|
28
|
-
error: null
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
class ErrorBoundary extends React.Component {
|
|
32
|
-
constructor(props) {
|
|
33
|
-
super(props);
|
|
34
|
-
this.state = initialState;
|
|
35
|
-
this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static getDerivedStateFromError(error) {
|
|
39
|
-
return {
|
|
40
|
-
error
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
resetErrorBoundary(...args) {
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
// eslint-disable-next-line no-unused-expressions
|
|
47
|
-
this.props.onReset && this.props.onReset(...args);
|
|
48
|
-
this.reset();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
reset() {
|
|
52
|
-
this.setState(initialState);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
componentDidCatch(error, info) {
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
// eslint-disable-next-line no-unused-expressions
|
|
58
|
-
this.props.onError && this.props.onError(error, info);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
componentDidUpdate(prevProps, prevState) {
|
|
62
|
-
const {
|
|
63
|
-
error
|
|
64
|
-
} = this.state;
|
|
65
|
-
const {
|
|
66
|
-
resetKeys
|
|
67
|
-
} = this.props; // There's an edge case where if the thing that triggered the error
|
|
68
|
-
// happens to *also* be in the resetKeys array, we'd end up resetting
|
|
69
|
-
// the error boundary immediately. This would likely trigger a second
|
|
70
|
-
// error to be thrown.
|
|
71
|
-
// So we make sure that we don't check the resetKeys on the first call
|
|
72
|
-
// of cDU after the error is set
|
|
73
|
-
|
|
74
|
-
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
// eslint-disable-next-line no-unused-expressions
|
|
77
|
-
this.props.onResetKeysChange && this.props.onResetKeysChange(prevProps.resetKeys, resetKeys);
|
|
78
|
-
this.reset();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
render() {
|
|
83
|
-
const {
|
|
84
|
-
error
|
|
85
|
-
} = this.state;
|
|
86
|
-
const {
|
|
87
|
-
fallbackRender,
|
|
88
|
-
FallbackComponent,
|
|
89
|
-
fallback
|
|
90
|
-
} = this.props;
|
|
91
|
-
|
|
92
|
-
if (error !== null) {
|
|
93
|
-
const props = {
|
|
94
|
-
error,
|
|
95
|
-
resetErrorBoundary: this.resetErrorBoundary
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
if ( /*#__PURE__*/React.isValidElement(fallback)) {
|
|
99
|
-
return fallback;
|
|
100
|
-
} else if (typeof fallbackRender === 'function') {
|
|
101
|
-
return fallbackRender(props);
|
|
102
|
-
} else if (FallbackComponent) {
|
|
103
|
-
return /*#__PURE__*/React.createElement(FallbackComponent, props);
|
|
104
|
-
} else {
|
|
105
|
-
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return this.props.children;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
17
|
/**
|
|
115
18
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
116
19
|
*
|
|
@@ -168,14 +71,7 @@ function useCanShowPlaceholder(editor) {
|
|
|
168
71
|
* LICENSE file in the root directory of this source tree.
|
|
169
72
|
*
|
|
170
73
|
*/
|
|
171
|
-
function useDecorators(editor,
|
|
172
|
-
ErrorBoundary$1 = ({
|
|
173
|
-
children,
|
|
174
|
-
onError
|
|
175
|
-
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
176
|
-
fallback: null,
|
|
177
|
-
onError: onError
|
|
178
|
-
}, children)) {
|
|
74
|
+
function useDecorators(editor, ErrorBoundary) {
|
|
179
75
|
const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
|
|
180
76
|
|
|
181
77
|
useLayoutEffect(() => {
|
|
@@ -198,7 +94,7 @@ ErrorBoundary$1 = ({
|
|
|
198
94
|
|
|
199
95
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
200
96
|
const nodeKey = decoratorKeys[i];
|
|
201
|
-
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary
|
|
97
|
+
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
202
98
|
onError: e => editor._onError(e)
|
|
203
99
|
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
204
100
|
fallback: null
|
|
@@ -211,7 +107,7 @@ ErrorBoundary$1 = ({
|
|
|
211
107
|
}
|
|
212
108
|
|
|
213
109
|
return decoratedPortals;
|
|
214
|
-
}, [ErrorBoundary
|
|
110
|
+
}, [ErrorBoundary, decorators, editor]);
|
|
215
111
|
}
|
|
216
112
|
|
|
217
113
|
/**
|
|
@@ -238,18 +134,11 @@ function usePlainTextSetup(editor) {
|
|
|
238
134
|
function PlainTextPlugin({
|
|
239
135
|
contentEditable,
|
|
240
136
|
placeholder,
|
|
241
|
-
|
|
242
|
-
ErrorBoundary: ErrorBoundary$1 = ({
|
|
243
|
-
children,
|
|
244
|
-
onError
|
|
245
|
-
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
246
|
-
fallback: null,
|
|
247
|
-
onError: onError
|
|
248
|
-
}, children)
|
|
137
|
+
ErrorBoundary
|
|
249
138
|
}) {
|
|
250
139
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
251
140
|
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
252
|
-
const decorators = useDecorators(editor, ErrorBoundary
|
|
141
|
+
const decorators = useDecorators(editor, ErrorBoundary);
|
|
253
142
|
usePlainTextSetup(editor);
|
|
254
143
|
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
|
|
255
144
|
}
|
|
@@ -19,6 +19,5 @@ type InitialEditorStateType =
|
|
|
19
19
|
declare export function PlainTextPlugin({
|
|
20
20
|
contentEditable: React$Node,
|
|
21
21
|
placeholder: React$Node,
|
|
22
|
-
|
|
23
|
-
ErrorBoundary?: ErrorBoundaryType,
|
|
22
|
+
ErrorBoundary: ErrorBoundaryType,
|
|
24
23
|
}): React$Node;
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function z(a,e=({children:c,onError:b})=>h.createElement(v,{fallback:null,onError:b},c)){let [c,b]=h.useState(()=>a.getDecorators());w(()=>a.registerDecoratorListener(f=>{n.flushSync(()=>{b(f)})}),[a]);h.useEffect(()=>{b(a.getDecorators())},[a]);return h.useMemo(()=>{let f=[],r=Object.keys(c);for(let k=0;k<r.length;k++){var g=r[k];let B=h.createElement(e,{onError:A=>a._onError(A)},h.createElement(h.Suspense,{fallback:null},c[g]));g=a.getElementByKey(g);null!==g&&f.push(n.createPortal(B,g))}return f},
|
|
12
|
-
[e,c,a])}function C(a){w(()=>m.mergeRegister(q.registerPlainText(a),p.registerDragonSupport(a)),[a])}exports.PlainTextPlugin=function({contentEditable:a,placeholder:e,ErrorBoundary:c=({children:b,onError:f})=>h.createElement(v,{fallback:null,onError:f},b)}){let [b]=d.useLexicalComposerContext(),f=y(b);c=z(b,c);C(b);return h.createElement(h.Fragment,null,a,f&&e,c)}
|
|
7
|
+
'use strict';var b=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),q=require("@lexical/dragon"),r=require("@lexical/plain-text"),t="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function u(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isEditable()))}
|
|
8
|
+
function v(a){let [f,d]=h.useState(()=>u(a));t(()=>{function c(){let e=u(a);d(e)}c();return m.mergeRegister(a.registerUpdateListener(()=>{c()}),a.registerEditableListener(()=>{c()}))},[a]);return f}
|
|
9
|
+
function w(a,f){let [d,c]=h.useState(()=>a.getDecorators());t(()=>a.registerDecoratorListener(e=>{n.flushSync(()=>{c(e)})}),[a]);h.useEffect(()=>{c(a.getDecorators())},[a]);return h.useMemo(()=>{let e=[],p=Object.keys(d);for(let k=0;k<p.length;k++){var g=p[k];let y=h.createElement(f,{onError:x=>a._onError(x)},h.createElement(h.Suspense,{fallback:null},d[g]));g=a.getElementByKey(g);null!==g&&e.push(n.createPortal(y,g))}return e},[f,d,a])}
|
|
10
|
+
function z(a){t(()=>m.mergeRegister(r.registerPlainText(a),q.registerDragonSupport(a)),[a])}exports.PlainTextPlugin=function({contentEditable:a,placeholder:f,ErrorBoundary:d}){let [c]=b.useLexicalComposerContext(),e=v(c);d=w(c,d);z(c);return h.createElement(h.Fragment,null,a,e&&f,d)}
|
|
@@ -9,5 +9,5 @@ import { ErrorBoundaryType } from './shared/useDecorators';
|
|
|
9
9
|
export declare function RichTextPlugin({ contentEditable, placeholder, ErrorBoundary, }: Readonly<{
|
|
10
10
|
contentEditable: JSX.Element;
|
|
11
11
|
placeholder: JSX.Element | string;
|
|
12
|
-
ErrorBoundary
|
|
12
|
+
ErrorBoundary: ErrorBoundaryType;
|
|
13
13
|
}>): JSX.Element;
|
|
@@ -14,103 +14,6 @@ var reactDom = require('react-dom');
|
|
|
14
14
|
var dragon = require('@lexical/dragon');
|
|
15
15
|
var richText = require('@lexical/rich-text');
|
|
16
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
|
-
const changedArray = (a = [], b = []) => a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
26
|
-
|
|
27
|
-
const initialState = {
|
|
28
|
-
error: null
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
class ErrorBoundary extends React.Component {
|
|
32
|
-
constructor(props) {
|
|
33
|
-
super(props);
|
|
34
|
-
this.state = initialState;
|
|
35
|
-
this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static getDerivedStateFromError(error) {
|
|
39
|
-
return {
|
|
40
|
-
error
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
resetErrorBoundary(...args) {
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
// eslint-disable-next-line no-unused-expressions
|
|
47
|
-
this.props.onReset && this.props.onReset(...args);
|
|
48
|
-
this.reset();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
reset() {
|
|
52
|
-
this.setState(initialState);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
componentDidCatch(error, info) {
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
// eslint-disable-next-line no-unused-expressions
|
|
58
|
-
this.props.onError && this.props.onError(error, info);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
componentDidUpdate(prevProps, prevState) {
|
|
62
|
-
const {
|
|
63
|
-
error
|
|
64
|
-
} = this.state;
|
|
65
|
-
const {
|
|
66
|
-
resetKeys
|
|
67
|
-
} = this.props; // There's an edge case where if the thing that triggered the error
|
|
68
|
-
// happens to *also* be in the resetKeys array, we'd end up resetting
|
|
69
|
-
// the error boundary immediately. This would likely trigger a second
|
|
70
|
-
// error to be thrown.
|
|
71
|
-
// So we make sure that we don't check the resetKeys on the first call
|
|
72
|
-
// of cDU after the error is set
|
|
73
|
-
|
|
74
|
-
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
// eslint-disable-next-line no-unused-expressions
|
|
77
|
-
this.props.onResetKeysChange && this.props.onResetKeysChange(prevProps.resetKeys, resetKeys);
|
|
78
|
-
this.reset();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
render() {
|
|
83
|
-
const {
|
|
84
|
-
error
|
|
85
|
-
} = this.state;
|
|
86
|
-
const {
|
|
87
|
-
fallbackRender,
|
|
88
|
-
FallbackComponent,
|
|
89
|
-
fallback
|
|
90
|
-
} = this.props;
|
|
91
|
-
|
|
92
|
-
if (error !== null) {
|
|
93
|
-
const props = {
|
|
94
|
-
error,
|
|
95
|
-
resetErrorBoundary: this.resetErrorBoundary
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
if ( /*#__PURE__*/React.isValidElement(fallback)) {
|
|
99
|
-
return fallback;
|
|
100
|
-
} else if (typeof fallbackRender === 'function') {
|
|
101
|
-
return fallbackRender(props);
|
|
102
|
-
} else if (FallbackComponent) {
|
|
103
|
-
return /*#__PURE__*/React.createElement(FallbackComponent, props);
|
|
104
|
-
} else {
|
|
105
|
-
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return this.props.children;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
17
|
/**
|
|
115
18
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
116
19
|
*
|
|
@@ -168,14 +71,7 @@ function useCanShowPlaceholder(editor) {
|
|
|
168
71
|
* LICENSE file in the root directory of this source tree.
|
|
169
72
|
*
|
|
170
73
|
*/
|
|
171
|
-
function useDecorators(editor,
|
|
172
|
-
ErrorBoundary$1 = ({
|
|
173
|
-
children,
|
|
174
|
-
onError
|
|
175
|
-
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
176
|
-
fallback: null,
|
|
177
|
-
onError: onError
|
|
178
|
-
}, children)) {
|
|
74
|
+
function useDecorators(editor, ErrorBoundary) {
|
|
179
75
|
const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
|
|
180
76
|
|
|
181
77
|
useLayoutEffect(() => {
|
|
@@ -198,7 +94,7 @@ ErrorBoundary$1 = ({
|
|
|
198
94
|
|
|
199
95
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
200
96
|
const nodeKey = decoratorKeys[i];
|
|
201
|
-
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary
|
|
97
|
+
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
202
98
|
onError: e => editor._onError(e)
|
|
203
99
|
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
204
100
|
fallback: null
|
|
@@ -211,7 +107,7 @@ ErrorBoundary$1 = ({
|
|
|
211
107
|
}
|
|
212
108
|
|
|
213
109
|
return decoratedPortals;
|
|
214
|
-
}, [ErrorBoundary
|
|
110
|
+
}, [ErrorBoundary, decorators, editor]);
|
|
215
111
|
}
|
|
216
112
|
|
|
217
113
|
/**
|
|
@@ -238,18 +134,11 @@ function useRichTextSetup(editor) {
|
|
|
238
134
|
function RichTextPlugin({
|
|
239
135
|
contentEditable,
|
|
240
136
|
placeholder,
|
|
241
|
-
|
|
242
|
-
ErrorBoundary: ErrorBoundary$1 = ({
|
|
243
|
-
children,
|
|
244
|
-
onError
|
|
245
|
-
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
246
|
-
fallback: null,
|
|
247
|
-
onError: onError
|
|
248
|
-
}, children)
|
|
137
|
+
ErrorBoundary
|
|
249
138
|
}) {
|
|
250
139
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
251
140
|
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
252
|
-
const decorators = useDecorators(editor, ErrorBoundary
|
|
141
|
+
const decorators = useDecorators(editor, ErrorBoundary);
|
|
253
142
|
useRichTextSetup(editor);
|
|
254
143
|
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
|
|
255
144
|
}
|
|
@@ -19,6 +19,5 @@ type InitialEditorStateType =
|
|
|
19
19
|
declare export function RichTextPlugin({
|
|
20
20
|
contentEditable: React$Node,
|
|
21
21
|
placeholder: React$Node,
|
|
22
|
-
|
|
23
|
-
ErrorBoundary?: ErrorBoundaryType,
|
|
22
|
+
ErrorBoundary: ErrorBoundaryType,
|
|
24
23
|
}): React$Node;
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function z(a,e=({children:c,onError:b})=>h.createElement(v,{fallback:null,onError:b},c)){let [c,b]=h.useState(()=>a.getDecorators());w(()=>a.registerDecoratorListener(f=>{n.flushSync(()=>{b(f)})}),[a]);h.useEffect(()=>{b(a.getDecorators())},[a]);return h.useMemo(()=>{let f=[],r=Object.keys(c);for(let k=0;k<r.length;k++){var g=r[k];let B=h.createElement(e,{onError:A=>a._onError(A)},h.createElement(h.Suspense,{fallback:null},c[g]));g=a.getElementByKey(g);null!==g&&f.push(n.createPortal(B,g))}return f},
|
|
12
|
-
[e,c,a])}function C(a){w(()=>m.mergeRegister(q.registerRichText(a),p.registerDragonSupport(a)),[a])}exports.RichTextPlugin=function({contentEditable:a,placeholder:e,ErrorBoundary:c=({children:b,onError:f})=>h.createElement(v,{fallback:null,onError:f},b)}){let [b]=d.useLexicalComposerContext(),f=y(b);c=z(b,c);C(b);return h.createElement(h.Fragment,null,a,f&&e,c)}
|
|
7
|
+
'use strict';var b=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),q=require("@lexical/dragon"),r=require("@lexical/rich-text"),t="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function u(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isEditable()))}
|
|
8
|
+
function v(a){let [f,d]=h.useState(()=>u(a));t(()=>{function c(){let e=u(a);d(e)}c();return m.mergeRegister(a.registerUpdateListener(()=>{c()}),a.registerEditableListener(()=>{c()}))},[a]);return f}
|
|
9
|
+
function w(a,f){let [d,c]=h.useState(()=>a.getDecorators());t(()=>a.registerDecoratorListener(e=>{n.flushSync(()=>{c(e)})}),[a]);h.useEffect(()=>{c(a.getDecorators())},[a]);return h.useMemo(()=>{let e=[],p=Object.keys(d);for(let k=0;k<p.length;k++){var g=p[k];let y=h.createElement(f,{onError:x=>a._onError(x)},h.createElement(h.Suspense,{fallback:null},d[g]));g=a.getElementByKey(g);null!==g&&e.push(n.createPortal(y,g))}return e},[f,d,a])}
|
|
10
|
+
function z(a){t(()=>m.mergeRegister(r.registerRichText(a),q.registerDragonSupport(a)),[a])}exports.RichTextPlugin=function({contentEditable:a,placeholder:f,ErrorBoundary:d}){let [c]=b.useLexicalComposerContext(),e=v(c);d=w(c,d);z(c);return h.createElement(h.Fragment,null,a,e&&f,d)}
|
|
@@ -69,16 +69,36 @@ function TablePlugin() {
|
|
|
69
69
|
}, [editor]);
|
|
70
70
|
react.useEffect(() => {
|
|
71
71
|
const tableSelections = new Map();
|
|
72
|
-
|
|
72
|
+
|
|
73
|
+
const initializeTableNode = tableNode => {
|
|
74
|
+
const nodeKey = tableNode.getKey();
|
|
75
|
+
const tableElement = editor.getElementByKey(nodeKey);
|
|
76
|
+
|
|
77
|
+
if (tableElement && !tableSelections.has(nodeKey)) {
|
|
78
|
+
const tableSelection = table.applyTableHandlers(tableNode, tableElement, editor);
|
|
79
|
+
tableSelections.set(nodeKey, tableSelection);
|
|
80
|
+
}
|
|
81
|
+
}; // Plugins might be loaded _after_ initial content is set, hence existing table nodes
|
|
82
|
+
// won't be initialized from mutation[create] listener. Instead doing it here,
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
editor.getEditorState().read(() => {
|
|
86
|
+
const tableNodes = lexical.$nodesOfType(table.TableNode);
|
|
87
|
+
|
|
88
|
+
for (const tableNode of tableNodes) {
|
|
89
|
+
if (table.$isTableNode(tableNode)) {
|
|
90
|
+
initializeTableNode(tableNode);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
const unregisterMutationListener = editor.registerMutationListener(table.TableNode, nodeMutations => {
|
|
73
95
|
for (const [nodeKey, mutation] of nodeMutations) {
|
|
74
96
|
if (mutation === 'created') {
|
|
75
|
-
editor.
|
|
76
|
-
const tableElement = editor.getElementByKey(nodeKey);
|
|
97
|
+
editor.getEditorState().read(() => {
|
|
77
98
|
const tableNode = lexical.$getNodeByKey(nodeKey);
|
|
78
99
|
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
tableSelections.set(nodeKey, tableSelection);
|
|
100
|
+
if (table.$isTableNode(tableNode)) {
|
|
101
|
+
initializeTableNode(tableNode);
|
|
82
102
|
}
|
|
83
103
|
});
|
|
84
104
|
} else if (mutation === 'destroyed') {
|
|
@@ -91,6 +111,14 @@ function TablePlugin() {
|
|
|
91
111
|
}
|
|
92
112
|
}
|
|
93
113
|
});
|
|
114
|
+
return () => {
|
|
115
|
+
unregisterMutationListener(); // Hook might be called multiple times so cleaning up tables listeners as well,
|
|
116
|
+
// as it'll be reinitialized during recurring call
|
|
117
|
+
|
|
118
|
+
for (const [, tableSelection] of tableSelections) {
|
|
119
|
+
tableSelection.removeListeners();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
94
122
|
}, [editor]);
|
|
95
123
|
return null;
|
|
96
124
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var
|
|
8
|
-
exports.TablePlugin=function(){let [
|
|
9
|
-
|
|
10
|
-
b
|
|
7
|
+
'use strict';var d=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/table"),l=require("lexical"),n=require("react");
|
|
8
|
+
exports.TablePlugin=function(){let [e]=d.useLexicalComposerContext();n.useEffect(()=>{if(!e.hasNodes([f.TableNode,f.TableCellNode,f.TableRowNode]))throw Error("Minified Lexical error #10; visit https://lexical.dev/docs/error?code=10 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return e.registerCommand(f.INSERT_TABLE_COMMAND,({columns:b,rows:g,includeHeaders:k})=>{var a=l.$getSelection();if(!l.$isRangeSelection(a))return!0;let c=a.focus;
|
|
9
|
+
a=c.getNode();null!==a&&(b=f.$createTableNodeWithDimensions(Number(g),Number(b),k),l.$isRootOrShadowRoot(a)?(g=a.getChildAtIndex(c.offset),null!==g?g.insertBefore(b):a.append(b),b.insertBefore(l.$createParagraphNode())):a.getTopLevelElementOrThrow().insertAfter(b),b.insertAfter(l.$createParagraphNode()),b.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0},l.COMMAND_PRIORITY_EDITOR)},[e]);n.useEffect(()=>{let b=new Map,g=a=>{const c=a.getKey(),h=e.getElementByKey(c);h&&!b.has(c)&&(a=
|
|
10
|
+
f.applyTableHandlers(a,h,e),b.set(c,a))};e.getEditorState().read(()=>{let a=l.$nodesOfType(f.TableNode);for(let c of a)f.$isTableNode(c)&&g(c)});let k=e.registerMutationListener(f.TableNode,a=>{for(const [c,h]of a)"created"===h?e.getEditorState().read(()=>{const m=l.$getNodeByKey(c);f.$isTableNode(m)&&g(m)}):"destroyed"===h&&(a=b.get(c),void 0!==a&&(a.removeListeners(),b.delete(c)))});return()=>{k();for(let [,a]of b)a.removeListeners()}},[e]);return null}
|
package/package.json
CHANGED
|
@@ -8,28 +8,29 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.6.0",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.
|
|
14
|
-
"@lexical/code": "0.
|
|
15
|
-
"@lexical/dragon": "0.
|
|
16
|
-
"@lexical/hashtag": "0.
|
|
17
|
-
"@lexical/history": "0.
|
|
18
|
-
"@lexical/link": "0.
|
|
19
|
-
"@lexical/list": "0.
|
|
20
|
-
"@lexical/mark": "0.
|
|
21
|
-
"@lexical/markdown": "0.
|
|
22
|
-
"@lexical/overflow": "0.
|
|
23
|
-
"@lexical/plain-text": "0.
|
|
24
|
-
"@lexical/rich-text": "0.
|
|
25
|
-
"@lexical/selection": "0.
|
|
26
|
-
"@lexical/table": "0.
|
|
27
|
-
"@lexical/text": "0.
|
|
28
|
-
"@lexical/utils": "0.
|
|
29
|
-
"@lexical/yjs": "0.
|
|
13
|
+
"@lexical/clipboard": "0.6.0",
|
|
14
|
+
"@lexical/code": "0.6.0",
|
|
15
|
+
"@lexical/dragon": "0.6.0",
|
|
16
|
+
"@lexical/hashtag": "0.6.0",
|
|
17
|
+
"@lexical/history": "0.6.0",
|
|
18
|
+
"@lexical/link": "0.6.0",
|
|
19
|
+
"@lexical/list": "0.6.0",
|
|
20
|
+
"@lexical/mark": "0.6.0",
|
|
21
|
+
"@lexical/markdown": "0.6.0",
|
|
22
|
+
"@lexical/overflow": "0.6.0",
|
|
23
|
+
"@lexical/plain-text": "0.6.0",
|
|
24
|
+
"@lexical/rich-text": "0.6.0",
|
|
25
|
+
"@lexical/selection": "0.6.0",
|
|
26
|
+
"@lexical/table": "0.6.0",
|
|
27
|
+
"@lexical/text": "0.6.0",
|
|
28
|
+
"@lexical/utils": "0.6.0",
|
|
29
|
+
"@lexical/yjs": "0.6.0",
|
|
30
|
+
"react-error-boundary": "^3.1.4"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
|
-
"lexical": "0.
|
|
33
|
+
"lexical": "0.6.0",
|
|
33
34
|
"react": ">=17.x",
|
|
34
35
|
"react-dom": ">=17.x"
|
|
35
36
|
},
|
|
@@ -12,5 +12,5 @@ declare type ErrorBoundaryProps = {
|
|
|
12
12
|
onError: (error: Error) => void;
|
|
13
13
|
};
|
|
14
14
|
export declare type ErrorBoundaryType = React.ComponentClass<ErrorBoundaryProps> | React.FC<ErrorBoundaryProps>;
|
|
15
|
-
export declare function useDecorators(editor: LexicalEditor, ErrorBoundary
|
|
15
|
+
export declare function useDecorators(editor: LexicalEditor, ErrorBoundary: ErrorBoundaryType): Array<JSX.Element>;
|
|
16
16
|
export {};
|
|
@@ -1,63 +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
|
-
import * as React from 'react';
|
|
9
|
-
interface FallbackProps {
|
|
10
|
-
error: Error;
|
|
11
|
-
resetErrorBoundary: (...args: Array<unknown>) => void;
|
|
12
|
-
}
|
|
13
|
-
interface ErrorBoundaryPropsWithComponent {
|
|
14
|
-
onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
|
|
15
|
-
onReset?: (...args: Array<unknown>) => void;
|
|
16
|
-
onError?: (error: Error, info: {
|
|
17
|
-
componentStack: string;
|
|
18
|
-
}) => void;
|
|
19
|
-
resetKeys?: Array<unknown>;
|
|
20
|
-
fallback?: never;
|
|
21
|
-
FallbackComponent: React.ComponentType<FallbackProps>;
|
|
22
|
-
fallbackRender?: never;
|
|
23
|
-
}
|
|
24
|
-
declare function FallbackRender(props: FallbackProps): React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null;
|
|
25
|
-
interface ErrorBoundaryPropsWithRender {
|
|
26
|
-
onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
|
|
27
|
-
onReset?: (...args: Array<unknown>) => void;
|
|
28
|
-
onError?: (error: Error, info: {
|
|
29
|
-
componentStack: string;
|
|
30
|
-
}) => void;
|
|
31
|
-
resetKeys?: Array<unknown>;
|
|
32
|
-
fallback?: never;
|
|
33
|
-
FallbackComponent?: never;
|
|
34
|
-
fallbackRender: typeof FallbackRender;
|
|
35
|
-
}
|
|
36
|
-
interface ErrorBoundaryPropsWithFallback {
|
|
37
|
-
onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
|
|
38
|
-
onReset?: (...args: Array<unknown>) => void;
|
|
39
|
-
onError?: (error: Error, info: {
|
|
40
|
-
componentStack: string;
|
|
41
|
-
}) => void;
|
|
42
|
-
resetKeys?: Array<unknown>;
|
|
43
|
-
fallback: React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null;
|
|
44
|
-
FallbackComponent?: never;
|
|
45
|
-
fallbackRender?: never;
|
|
46
|
-
}
|
|
47
|
-
declare type ErrorBoundaryProps = ErrorBoundaryPropsWithFallback | ErrorBoundaryPropsWithComponent | ErrorBoundaryPropsWithRender;
|
|
48
|
-
declare type ErrorBoundaryState = {
|
|
49
|
-
error: Error | null;
|
|
50
|
-
};
|
|
51
|
-
declare class ErrorBoundary extends React.Component<React.PropsWithRef<React.PropsWithChildren<ErrorBoundaryProps>>, ErrorBoundaryState> {
|
|
52
|
-
state: ErrorBoundaryState;
|
|
53
|
-
constructor(props: ErrorBoundaryProps);
|
|
54
|
-
static getDerivedStateFromError(error: Error): {
|
|
55
|
-
error: Error;
|
|
56
|
-
};
|
|
57
|
-
resetErrorBoundary(...args: Array<unknown>): void;
|
|
58
|
-
reset(): void;
|
|
59
|
-
componentDidCatch(error: Error, info: React.ErrorInfo): void;
|
|
60
|
-
componentDidUpdate(prevProps: ErrorBoundaryProps, prevState: ErrorBoundaryState): void;
|
|
61
|
-
render(): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
|
|
62
|
-
}
|
|
63
|
-
export { ErrorBoundary };
|