@lexical/react 0.5.1-next.1 → 0.5.1-next.2
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.dev.js +21 -11
- package/DEPRECATED_useLexicalDecorators.prod.js +6 -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/LexicalPlainTextPlugin.dev.js +24 -14
- package/LexicalPlainTextPlugin.prod.js +7 -6
- package/LexicalRichTextPlugin.dev.js +24 -14
- package/LexicalRichTextPlugin.prod.js +7 -6
- package/LexicalTablePlugin.dev.js +34 -6
- package/LexicalTablePlugin.prod.js +4 -4
- package/package.json +19 -19
|
@@ -132,14 +132,19 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
132
132
|
* LICENSE file in the root directory of this source tree.
|
|
133
133
|
*
|
|
134
134
|
*/
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
|
|
136
|
+
const fallbackRenderer$1 = () => null;
|
|
137
|
+
|
|
138
|
+
const DefaultErrorBoundary$1 = ({
|
|
137
139
|
children,
|
|
138
140
|
onError
|
|
139
141
|
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
140
|
-
|
|
142
|
+
fallbackRender: fallbackRenderer$1,
|
|
141
143
|
onError: onError
|
|
142
|
-
}, children)
|
|
144
|
+
}, children);
|
|
145
|
+
|
|
146
|
+
function useDecorators(editor, // TODO 0.6 Make non-optional non-default
|
|
147
|
+
ErrorBoundary = DefaultErrorBoundary$1) {
|
|
143
148
|
const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
|
|
144
149
|
|
|
145
150
|
useLayoutEffect(() => {
|
|
@@ -162,7 +167,7 @@ ErrorBoundary$1 = ({
|
|
|
162
167
|
|
|
163
168
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
164
169
|
const nodeKey = decoratorKeys[i];
|
|
165
|
-
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary
|
|
170
|
+
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
166
171
|
onError: e => editor._onError(e)
|
|
167
172
|
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
168
173
|
fallback: null
|
|
@@ -175,7 +180,7 @@ ErrorBoundary$1 = ({
|
|
|
175
180
|
}
|
|
176
181
|
|
|
177
182
|
return decoratedPortals;
|
|
178
|
-
}, [ErrorBoundary
|
|
183
|
+
}, [ErrorBoundary, decorators, editor]);
|
|
179
184
|
}
|
|
180
185
|
|
|
181
186
|
/**
|
|
@@ -185,15 +190,20 @@ ErrorBoundary$1 = ({
|
|
|
185
190
|
* LICENSE file in the root directory of this source tree.
|
|
186
191
|
*
|
|
187
192
|
*/
|
|
188
|
-
|
|
189
|
-
|
|
193
|
+
|
|
194
|
+
const fallbackRenderer = () => null;
|
|
195
|
+
|
|
196
|
+
const DefaultErrorBoundary = ({
|
|
190
197
|
children,
|
|
191
198
|
onError
|
|
192
199
|
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
193
|
-
|
|
200
|
+
fallbackRender: fallbackRenderer,
|
|
194
201
|
onError: onError
|
|
195
|
-
}, children)
|
|
196
|
-
|
|
202
|
+
}, children);
|
|
203
|
+
|
|
204
|
+
function useLexicalDecorators(editor, // TODO 0.6 Make non-optional non-default
|
|
205
|
+
ErrorBoundary = DefaultErrorBoundary) {
|
|
206
|
+
return useDecorators(editor, ErrorBoundary);
|
|
197
207
|
}
|
|
198
208
|
|
|
199
209
|
exports.useLexicalDecorators = useLexicalDecorators;
|
|
@@ -4,9 +4,9 @@
|
|
|
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
|
-
class p extends
|
|
9
|
-
|
|
10
|
-
var q="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?
|
|
11
|
-
function
|
|
12
|
-
|
|
7
|
+
'use strict';var c=require("react"),k=require("react-dom");let l=(a=[],b=[])=>a.length!==b.length||a.some((d,e)=>!Object.is(d,b[e])),m={error:null};
|
|
8
|
+
class p extends c.Component{constructor(a){super(a);this.state=m;this.resetErrorBoundary=this.resetErrorBoundary.bind(this)}static getDerivedStateFromError(a){return{error:a}}resetErrorBoundary(...a){this.props.onReset&&this.props.onReset(...a);this.reset()}reset(){this.setState(m)}componentDidCatch(a,b){this.props.onError&&this.props.onError(a,b)}componentDidUpdate(a,b){let {error:d}=this.state,{resetKeys:e}=this.props;null!==d&&null!==b.error&&l(a.resetKeys,e)&&(this.props.onResetKeysChange&&this.props.onResetKeysChange(a.resetKeys,
|
|
9
|
+
e),this.reset())}render(){var {error:a}=this.state;let {fallbackRender:b,FallbackComponent:d,fallback:e}=this.props;if(null!==a){a={error:a,resetErrorBoundary:this.resetErrorBoundary};if(c.isValidElement(e))return e;if("function"===typeof b)return b(a);if(d)return c.createElement(d,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?c.useLayoutEffect:c.useEffect;let r=()=>null,t=({children:a,onError:b})=>c.createElement(p,{fallbackRender:r,onError:b},a);
|
|
11
|
+
function u(a,b=t){let [d,e]=c.useState(()=>a.getDecorators());q(()=>a.registerDecoratorListener(g=>{k.flushSync(()=>{e(g)})}),[a]);c.useEffect(()=>{e(a.getDecorators())},[a]);return c.useMemo(()=>{let g=[],n=Object.keys(d);for(let h=0;h<n.length;h++){var f=n[h];let w=c.createElement(b,{onError:v=>a._onError(v)},c.createElement(c.Suspense,{fallback:null},d[f]));f=a.getElementByKey(f);null!==f&&g.push(k.createPortal(w,f))}return g},[b,d,a])}
|
|
12
|
+
let x=()=>null,y=({children:a,onError:b})=>c.createElement(p,{fallbackRender:x,onError:b},a);exports.useLexicalDecorators=function(a,b=y){return u(a,b)}
|
|
@@ -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}
|
|
@@ -168,14 +168,19 @@ function useCanShowPlaceholder(editor) {
|
|
|
168
168
|
* LICENSE file in the root directory of this source tree.
|
|
169
169
|
*
|
|
170
170
|
*/
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
|
|
172
|
+
const fallbackRenderer$1 = () => null;
|
|
173
|
+
|
|
174
|
+
const DefaultErrorBoundary$1 = ({
|
|
173
175
|
children,
|
|
174
176
|
onError
|
|
175
177
|
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
176
|
-
|
|
178
|
+
fallbackRender: fallbackRenderer$1,
|
|
177
179
|
onError: onError
|
|
178
|
-
}, children)
|
|
180
|
+
}, children);
|
|
181
|
+
|
|
182
|
+
function useDecorators(editor, // TODO 0.6 Make non-optional non-default
|
|
183
|
+
ErrorBoundary = DefaultErrorBoundary$1) {
|
|
179
184
|
const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
|
|
180
185
|
|
|
181
186
|
useLayoutEffect(() => {
|
|
@@ -198,7 +203,7 @@ ErrorBoundary$1 = ({
|
|
|
198
203
|
|
|
199
204
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
200
205
|
const nodeKey = decoratorKeys[i];
|
|
201
|
-
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary
|
|
206
|
+
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
202
207
|
onError: e => editor._onError(e)
|
|
203
208
|
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
204
209
|
fallback: null
|
|
@@ -211,7 +216,7 @@ ErrorBoundary$1 = ({
|
|
|
211
216
|
}
|
|
212
217
|
|
|
213
218
|
return decoratedPortals;
|
|
214
|
-
}, [ErrorBoundary
|
|
219
|
+
}, [ErrorBoundary, decorators, editor]);
|
|
215
220
|
}
|
|
216
221
|
|
|
217
222
|
/**
|
|
@@ -235,21 +240,26 @@ function usePlainTextSetup(editor) {
|
|
|
235
240
|
* LICENSE file in the root directory of this source tree.
|
|
236
241
|
*
|
|
237
242
|
*/
|
|
243
|
+
|
|
244
|
+
const fallbackRenderer = () => null;
|
|
245
|
+
|
|
246
|
+
const DefaultErrorBoundary = ({
|
|
247
|
+
children,
|
|
248
|
+
onError
|
|
249
|
+
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
250
|
+
fallbackRender: fallbackRenderer,
|
|
251
|
+
onError: onError
|
|
252
|
+
}, children);
|
|
253
|
+
|
|
238
254
|
function PlainTextPlugin({
|
|
239
255
|
contentEditable,
|
|
240
256
|
placeholder,
|
|
241
257
|
// TODO 0.6 Make non-optional non-default
|
|
242
|
-
ErrorBoundary
|
|
243
|
-
children,
|
|
244
|
-
onError
|
|
245
|
-
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
246
|
-
fallback: null,
|
|
247
|
-
onError: onError
|
|
248
|
-
}, children)
|
|
258
|
+
ErrorBoundary = DefaultErrorBoundary
|
|
249
259
|
}) {
|
|
250
260
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
251
261
|
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
252
|
-
const decorators = useDecorators(editor, ErrorBoundary
|
|
262
|
+
const decorators = useDecorators(editor, ErrorBoundary);
|
|
253
263
|
usePlainTextSetup(editor);
|
|
254
264
|
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
|
|
255
265
|
}
|
|
@@ -4,9 +4,10 @@
|
|
|
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 d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),p=require("@lexical/dragon"),q=require("@lexical/plain-text");let t=(a=[],
|
|
8
|
-
class v extends h.Component{constructor(a){super(a);this.state=u;this.resetErrorBoundary=this.resetErrorBoundary.bind(this)}static getDerivedStateFromError(a){return{error:a}}resetErrorBoundary(...a){this.props.onReset&&this.props.onReset(...a);this.reset()}reset(){this.setState(u)}componentDidCatch(a,
|
|
9
|
-
|
|
10
|
-
var w="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function x(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isEditable()))}function y(a){let [e
|
|
11
|
-
|
|
12
|
-
[e,c
|
|
7
|
+
'use strict';var d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),p=require("@lexical/dragon"),q=require("@lexical/plain-text");let t=(a=[],b=[])=>a.length!==b.length||a.some((e,c)=>!Object.is(e,b[c])),u={error:null};
|
|
8
|
+
class v extends h.Component{constructor(a){super(a);this.state=u;this.resetErrorBoundary=this.resetErrorBoundary.bind(this)}static getDerivedStateFromError(a){return{error:a}}resetErrorBoundary(...a){this.props.onReset&&this.props.onReset(...a);this.reset()}reset(){this.setState(u)}componentDidCatch(a,b){this.props.onError&&this.props.onError(a,b)}componentDidUpdate(a,b){let {error:e}=this.state,{resetKeys:c}=this.props;null!==e&&null!==b.error&&t(a.resetKeys,c)&&(this.props.onResetKeysChange&&this.props.onResetKeysChange(a.resetKeys,
|
|
9
|
+
c),this.reset())}render(){var {error:a}=this.state;let {fallbackRender:b,FallbackComponent:e,fallback:c}=this.props;if(null!==a){a={error:a,resetErrorBoundary:this.resetErrorBoundary};if(h.isValidElement(c))return c;if("function"===typeof b)return b(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}}
|
|
10
|
+
var w="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function x(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isEditable()))}function y(a){let [b,e]=h.useState(()=>x(a));w(()=>{function c(){let f=x(a);e(f)}c();return m.mergeRegister(a.registerUpdateListener(()=>{c()}),a.registerEditableListener(()=>{c()}))},[a]);return b}
|
|
11
|
+
let z=()=>null,A=({children:a,onError:b})=>h.createElement(v,{fallbackRender:z,onError:b},a);
|
|
12
|
+
function B(a,b=A){let [e,c]=h.useState(()=>a.getDecorators());w(()=>a.registerDecoratorListener(f=>{n.flushSync(()=>{c(f)})}),[a]);h.useEffect(()=>{c(a.getDecorators())},[a]);return h.useMemo(()=>{let f=[],r=Object.keys(e);for(let k=0;k<r.length;k++){var g=r[k];let D=h.createElement(b,{onError:C=>a._onError(C)},h.createElement(h.Suspense,{fallback:null},e[g]));g=a.getElementByKey(g);null!==g&&f.push(n.createPortal(D,g))}return f},[b,e,a])}
|
|
13
|
+
function E(a){w(()=>m.mergeRegister(q.registerPlainText(a),p.registerDragonSupport(a)),[a])}let F=()=>null,G=({children:a,onError:b})=>h.createElement(v,{fallbackRender:F,onError:b},a);exports.PlainTextPlugin=function({contentEditable:a,placeholder:b,ErrorBoundary:e=G}){let [c]=d.useLexicalComposerContext(),f=y(c);e=B(c,e);E(c);return h.createElement(h.Fragment,null,a,f&&b,e)}
|
|
@@ -168,14 +168,19 @@ function useCanShowPlaceholder(editor) {
|
|
|
168
168
|
* LICENSE file in the root directory of this source tree.
|
|
169
169
|
*
|
|
170
170
|
*/
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
|
|
172
|
+
const fallbackRenderer$1 = () => null;
|
|
173
|
+
|
|
174
|
+
const DefaultErrorBoundary$1 = ({
|
|
173
175
|
children,
|
|
174
176
|
onError
|
|
175
177
|
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
176
|
-
|
|
178
|
+
fallbackRender: fallbackRenderer$1,
|
|
177
179
|
onError: onError
|
|
178
|
-
}, children)
|
|
180
|
+
}, children);
|
|
181
|
+
|
|
182
|
+
function useDecorators(editor, // TODO 0.6 Make non-optional non-default
|
|
183
|
+
ErrorBoundary = DefaultErrorBoundary$1) {
|
|
179
184
|
const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
|
|
180
185
|
|
|
181
186
|
useLayoutEffect(() => {
|
|
@@ -198,7 +203,7 @@ ErrorBoundary$1 = ({
|
|
|
198
203
|
|
|
199
204
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
200
205
|
const nodeKey = decoratorKeys[i];
|
|
201
|
-
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary
|
|
206
|
+
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
202
207
|
onError: e => editor._onError(e)
|
|
203
208
|
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
204
209
|
fallback: null
|
|
@@ -211,7 +216,7 @@ ErrorBoundary$1 = ({
|
|
|
211
216
|
}
|
|
212
217
|
|
|
213
218
|
return decoratedPortals;
|
|
214
|
-
}, [ErrorBoundary
|
|
219
|
+
}, [ErrorBoundary, decorators, editor]);
|
|
215
220
|
}
|
|
216
221
|
|
|
217
222
|
/**
|
|
@@ -235,21 +240,26 @@ function useRichTextSetup(editor) {
|
|
|
235
240
|
* LICENSE file in the root directory of this source tree.
|
|
236
241
|
*
|
|
237
242
|
*/
|
|
243
|
+
|
|
244
|
+
const fallbackRenderer = () => null;
|
|
245
|
+
|
|
246
|
+
const DefaultErrorBoundary = ({
|
|
247
|
+
children,
|
|
248
|
+
onError
|
|
249
|
+
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
250
|
+
fallbackRender: fallbackRenderer,
|
|
251
|
+
onError: onError
|
|
252
|
+
}, children);
|
|
253
|
+
|
|
238
254
|
function RichTextPlugin({
|
|
239
255
|
contentEditable,
|
|
240
256
|
placeholder,
|
|
241
257
|
// TODO 0.6 Make non-optional non-default
|
|
242
|
-
ErrorBoundary
|
|
243
|
-
children,
|
|
244
|
-
onError
|
|
245
|
-
}) => /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
246
|
-
fallback: null,
|
|
247
|
-
onError: onError
|
|
248
|
-
}, children)
|
|
258
|
+
ErrorBoundary = DefaultErrorBoundary
|
|
249
259
|
}) {
|
|
250
260
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
251
261
|
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
252
|
-
const decorators = useDecorators(editor, ErrorBoundary
|
|
262
|
+
const decorators = useDecorators(editor, ErrorBoundary);
|
|
253
263
|
useRichTextSetup(editor);
|
|
254
264
|
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
|
|
255
265
|
}
|
|
@@ -4,9 +4,10 @@
|
|
|
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 d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),p=require("@lexical/dragon"),q=require("@lexical/rich-text");let t=(a=[],
|
|
8
|
-
class v extends h.Component{constructor(a){super(a);this.state=u;this.resetErrorBoundary=this.resetErrorBoundary.bind(this)}static getDerivedStateFromError(a){return{error:a}}resetErrorBoundary(...a){this.props.onReset&&this.props.onReset(...a);this.reset()}reset(){this.setState(u)}componentDidCatch(a,
|
|
9
|
-
|
|
10
|
-
var w="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function x(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isEditable()))}function y(a){let [e
|
|
11
|
-
|
|
12
|
-
[e,c
|
|
7
|
+
'use strict';var d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),p=require("@lexical/dragon"),q=require("@lexical/rich-text");let t=(a=[],b=[])=>a.length!==b.length||a.some((e,c)=>!Object.is(e,b[c])),u={error:null};
|
|
8
|
+
class v extends h.Component{constructor(a){super(a);this.state=u;this.resetErrorBoundary=this.resetErrorBoundary.bind(this)}static getDerivedStateFromError(a){return{error:a}}resetErrorBoundary(...a){this.props.onReset&&this.props.onReset(...a);this.reset()}reset(){this.setState(u)}componentDidCatch(a,b){this.props.onError&&this.props.onError(a,b)}componentDidUpdate(a,b){let {error:e}=this.state,{resetKeys:c}=this.props;null!==e&&null!==b.error&&t(a.resetKeys,c)&&(this.props.onResetKeysChange&&this.props.onResetKeysChange(a.resetKeys,
|
|
9
|
+
c),this.reset())}render(){var {error:a}=this.state;let {fallbackRender:b,FallbackComponent:e,fallback:c}=this.props;if(null!==a){a={error:a,resetErrorBoundary:this.resetErrorBoundary};if(h.isValidElement(c))return c;if("function"===typeof b)return b(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}}
|
|
10
|
+
var w="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function x(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isEditable()))}function y(a){let [b,e]=h.useState(()=>x(a));w(()=>{function c(){let f=x(a);e(f)}c();return m.mergeRegister(a.registerUpdateListener(()=>{c()}),a.registerEditableListener(()=>{c()}))},[a]);return b}
|
|
11
|
+
let z=()=>null,A=({children:a,onError:b})=>h.createElement(v,{fallbackRender:z,onError:b},a);
|
|
12
|
+
function B(a,b=A){let [e,c]=h.useState(()=>a.getDecorators());w(()=>a.registerDecoratorListener(f=>{n.flushSync(()=>{c(f)})}),[a]);h.useEffect(()=>{c(a.getDecorators())},[a]);return h.useMemo(()=>{let f=[],r=Object.keys(e);for(let k=0;k<r.length;k++){var g=r[k];let D=h.createElement(b,{onError:C=>a._onError(C)},h.createElement(h.Suspense,{fallback:null},e[g]));g=a.getElementByKey(g);null!==g&&f.push(n.createPortal(D,g))}return f},[b,e,a])}
|
|
13
|
+
function E(a){w(()=>m.mergeRegister(q.registerRichText(a),p.registerDragonSupport(a)),[a])}let F=()=>null,G=({children:a,onError:b})=>h.createElement(v,{fallbackRender:F,onError:b},a);exports.RichTextPlugin=function({contentEditable:a,placeholder:b,ErrorBoundary:e=G}){let [c]=d.useLexicalComposerContext(),f=y(c);e=B(c,e);E(c);return h.createElement(h.Fragment,null,a,f&&b,e)}
|
|
@@ -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,28 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.5.1-next.
|
|
11
|
+
"version": "0.5.1-next.2",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.5.1-next.
|
|
14
|
-
"@lexical/code": "0.5.1-next.
|
|
15
|
-
"@lexical/dragon": "0.5.1-next.
|
|
16
|
-
"@lexical/hashtag": "0.5.1-next.
|
|
17
|
-
"@lexical/history": "0.5.1-next.
|
|
18
|
-
"@lexical/link": "0.5.1-next.
|
|
19
|
-
"@lexical/list": "0.5.1-next.
|
|
20
|
-
"@lexical/mark": "0.5.1-next.
|
|
21
|
-
"@lexical/markdown": "0.5.1-next.
|
|
22
|
-
"@lexical/overflow": "0.5.1-next.
|
|
23
|
-
"@lexical/plain-text": "0.5.1-next.
|
|
24
|
-
"@lexical/rich-text": "0.5.1-next.
|
|
25
|
-
"@lexical/selection": "0.5.1-next.
|
|
26
|
-
"@lexical/table": "0.5.1-next.
|
|
27
|
-
"@lexical/text": "0.5.1-next.
|
|
28
|
-
"@lexical/utils": "0.5.1-next.
|
|
29
|
-
"@lexical/yjs": "0.5.1-next.
|
|
13
|
+
"@lexical/clipboard": "0.5.1-next.2",
|
|
14
|
+
"@lexical/code": "0.5.1-next.2",
|
|
15
|
+
"@lexical/dragon": "0.5.1-next.2",
|
|
16
|
+
"@lexical/hashtag": "0.5.1-next.2",
|
|
17
|
+
"@lexical/history": "0.5.1-next.2",
|
|
18
|
+
"@lexical/link": "0.5.1-next.2",
|
|
19
|
+
"@lexical/list": "0.5.1-next.2",
|
|
20
|
+
"@lexical/mark": "0.5.1-next.2",
|
|
21
|
+
"@lexical/markdown": "0.5.1-next.2",
|
|
22
|
+
"@lexical/overflow": "0.5.1-next.2",
|
|
23
|
+
"@lexical/plain-text": "0.5.1-next.2",
|
|
24
|
+
"@lexical/rich-text": "0.5.1-next.2",
|
|
25
|
+
"@lexical/selection": "0.5.1-next.2",
|
|
26
|
+
"@lexical/table": "0.5.1-next.2",
|
|
27
|
+
"@lexical/text": "0.5.1-next.2",
|
|
28
|
+
"@lexical/utils": "0.5.1-next.2",
|
|
29
|
+
"@lexical/yjs": "0.5.1-next.2"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"lexical": "0.5.1-next.
|
|
32
|
+
"lexical": "0.5.1-next.2",
|
|
33
33
|
"react": ">=17.x",
|
|
34
34
|
"react-dom": ">=17.x"
|
|
35
35
|
},
|