@lexical/react 0.9.0 → 0.9.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.
@@ -107,6 +107,10 @@ function LexicalAutoEmbedPlugin({
107
107
 
108
108
  if (result != null) {
109
109
  editor.update(() => {
110
+ if (!lexical.$getSelection()) {
111
+ linkNode.selectEnd();
112
+ }
113
+
110
114
  activeEmbedConfig.insertNode(editor, result);
111
115
 
112
116
  if (linkNode.isAttached()) {
@@ -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 e=require("@lexical/link"),k=require("@lexical/react/LexicalComposerContext"),m=require("@lexical/react/LexicalTypeaheadMenuPlugin"),q=require("@lexical/utils"),r=require("lexical"),z=require("react");let A=r.createCommand("INSERT_EMBED_COMMAND");class B extends m.TypeaheadOption{constructor(f,n){super(f);this.title=f;this.onSelect=n.onSelect.bind(this)}}exports.AutoEmbedOption=B;exports.INSERT_EMBED_COMMAND=A;
8
- exports.LexicalAutoEmbedPlugin=function({embedConfigs:f,onOpenEmbedModalForConfig:n,getMenuOptions:t,menuRenderFn:C}){let [b]=k.useLexicalComposerContext(),[g,u]=z.useState(null),[h,v]=z.useState(null),l=z.useCallback(()=>{u(null);v(null)},[]),w=z.useCallback(c=>{b.getEditorState().read(async()=>{const a=r.$getNodeByKey(c);if(e.$isLinkNode(a))for(let d=0;d<f.length;d++){const p=f[d];null!=await Promise.resolve(p.parseUrl(a.__url))&&(v(p),u(a.getKey()))}})},[b,f]);z.useEffect(()=>{let c=(a,{updateTags:d,
9
- dirtyLeaves:p})=>{for(const [x,D]of a)"created"===D&&d.has("paste")&&1===p.size?w(x):x===g&&l()};return q.mergeRegister(...[e.LinkNode,e.AutoLinkNode].map(a=>b.registerMutationListener(a,(...d)=>c(...d))))},[w,b,f,g,l]);z.useEffect(()=>b.registerCommand(A,c=>{let a=f.find(({type:d})=>d===c);return a?(n(a),!0):!1},r.COMMAND_PRIORITY_EDITOR),[b,f,n]);let y=z.useCallback(async()=>{if(null!=h&&null!=g){const c=b.getEditorState().read(()=>{const a=r.$getNodeByKey(g);return e.$isLinkNode(a)?a:null});if(e.$isLinkNode(c)){const a=
10
- await Promise.resolve(h.parseUrl(c.__url));null!=a&&b.update(()=>{h.insertNode(b,a);c.isAttached()&&c.remove()})}}},[h,b,g]),E=z.useMemo(()=>null!=h&&null!=g?t(h,y,l):[],[h,y,t,g,l]),F=z.useCallback((c,a,d)=>{b.update(()=>{c.onSelect(a);d()})},[b]);return null!=g?z.createElement(m.LexicalNodeMenuPlugin,{nodeKey:g,onClose:l,onSelectOption:F,options:E,menuRenderFn:C}):null};exports.URL_MATCHER=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/
7
+ 'use strict';var e=require("@lexical/link"),k=require("@lexical/react/LexicalComposerContext"),l=require("@lexical/react/LexicalTypeaheadMenuPlugin"),q=require("@lexical/utils"),r=require("lexical"),z=require("react");let A=r.createCommand("INSERT_EMBED_COMMAND");class B extends l.TypeaheadOption{constructor(f,n){super(f);this.title=f;this.onSelect=n.onSelect.bind(this)}}exports.AutoEmbedOption=B;exports.INSERT_EMBED_COMMAND=A;
8
+ exports.LexicalAutoEmbedPlugin=function({embedConfigs:f,onOpenEmbedModalForConfig:n,getMenuOptions:t,menuRenderFn:C}){let [c]=k.useLexicalComposerContext(),[g,u]=z.useState(null),[h,v]=z.useState(null),m=z.useCallback(()=>{u(null);v(null)},[]),w=z.useCallback(b=>{c.getEditorState().read(async()=>{const a=r.$getNodeByKey(b);if(e.$isLinkNode(a))for(let d=0;d<f.length;d++){const p=f[d];null!=await Promise.resolve(p.parseUrl(a.__url))&&(v(p),u(a.getKey()))}})},[c,f]);z.useEffect(()=>{let b=(a,{updateTags:d,
9
+ dirtyLeaves:p})=>{for(const [x,D]of a)"created"===D&&d.has("paste")&&1===p.size?w(x):x===g&&m()};return q.mergeRegister(...[e.LinkNode,e.AutoLinkNode].map(a=>c.registerMutationListener(a,(...d)=>b(...d))))},[w,c,f,g,m]);z.useEffect(()=>c.registerCommand(A,b=>{let a=f.find(({type:d})=>d===b);return a?(n(a),!0):!1},r.COMMAND_PRIORITY_EDITOR),[c,f,n]);let y=z.useCallback(async()=>{if(null!=h&&null!=g){const b=c.getEditorState().read(()=>{const a=r.$getNodeByKey(g);return e.$isLinkNode(a)?a:null});if(e.$isLinkNode(b)){const a=
10
+ await Promise.resolve(h.parseUrl(b.__url));null!=a&&c.update(()=>{r.$getSelection()||b.selectEnd();h.insertNode(c,a);b.isAttached()&&b.remove()})}}},[h,c,g]),E=z.useMemo(()=>null!=h&&null!=g?t(h,y,m):[],[h,y,t,g,m]),F=z.useCallback((b,a,d)=>{c.update(()=>{b.onSelect(a);d()})},[c]);return null!=g?z.createElement(l.LexicalNodeMenuPlugin,{nodeKey:g,onClose:m,onSelectOption:F,options:E,menuRenderFn:C}):null};exports.URL_MATCHER=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/
@@ -16,6 +16,12 @@ declare type LinkMatcherResult = {
16
16
  url: string;
17
17
  };
18
18
  export declare type LinkMatcher = (text: string) => LinkMatcherResult | null;
19
+ export declare function createLinkMatcherWithRegExp(regExp: RegExp, urlTransformer?: (text: string) => string): (text: string) => {
20
+ index: number;
21
+ length: number;
22
+ text: string;
23
+ url: string;
24
+ } | null;
19
25
  export declare function AutoLinkPlugin({ matchers, onChange, }: {
20
26
  matchers: Array<LinkMatcher>;
21
27
  onChange?: ChangeHandler;
@@ -19,6 +19,18 @@ var react = require('react');
19
19
  * LICENSE file in the root directory of this source tree.
20
20
  *
21
21
  */
22
+ function createLinkMatcherWithRegExp(regExp, urlTransformer = text => text) {
23
+ return text => {
24
+ const match = regExp.exec(text);
25
+ if (match === null) return null;
26
+ return {
27
+ index: match.index,
28
+ length: match[0].length,
29
+ text: match[0],
30
+ url: urlTransformer(text)
31
+ };
32
+ };
33
+ }
22
34
 
23
35
  function findFirstMatch(text, matchers) {
24
36
  for (let i = 0; i < matchers.length; i++) {
@@ -244,3 +256,4 @@ function AutoLinkPlugin({
244
256
  }
245
257
 
246
258
  exports.AutoLinkPlugin = AutoLinkPlugin;
259
+ exports.createLinkMatcherWithRegExp = createLinkMatcherWithRegExp;
@@ -21,6 +21,11 @@ type LinkMatcherResult = {
21
21
 
22
22
  export type LinkMatcher = (text: string) => LinkMatcherResult | null;
23
23
 
24
+ declare export function createLinkMatcherWithRegExp(
25
+ regExp: RegExp,
26
+ urlTransformer?: (text: string) => string,
27
+ ): LinkMatcher;
28
+
24
29
  declare export function AutoLinkPlugin(props: {
25
30
  matchers: Array<LinkMatcher>,
26
31
  onChange?: ChangeHandler,
@@ -10,4 +10,4 @@ function F(a,b,c){var d=a.getChildren();let e=d.length;for(let f=0;f<e;f++){let
10
10
  null,d)))):(G(a),c(null,a.getURL()))}function G(a){let b=a.getChildren();var c=b.length;for(--c;0<=c;c--)a.insertAfter(b[c]);a.remove();return b.map(d=>d.getLatest())}
11
11
  function H(a,b,c){w.useEffect(()=>{if(!a.hasNodes([h.AutoLinkNode]))throw Error("Minified Lexical error #77; visit https://lexical.dev/docs/error?code=77 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let d=(e,f)=>{c&&c(e,f)};return p.mergeRegister(a.registerNodeTransform(u.TextNode,e=>{var f=e.getParentOrThrow(),l=e.getPreviousSibling();if(h.$isAutoLinkNode(f))F(f,b,d);else if(!h.$isLinkNode(f)){if(e.isSimpleText()&&(B.test(e.getTextContent()[0])||
12
12
  !h.$isAutoLinkNode(l))){l=f=e.getTextContent();let m=0,v=e;for(var g;(g=A(l,b))&&null!==g;){let r=g.index,x=g.length,y=r+x;var t=m+r,q=m+y,z=f,D=e;if((0<t?B.test(z[t-1]):C(D))&&(q<z.length?B.test(z[q]):E(D))){var k=void 0;0===m+r?[k,v]=v.splitText(m+x):[,k,v]=v.splitText(m+r,m+r+x);t=h.$createAutoLinkNode(g.url,g.attributes);q=u.$createTextNode(g.text);q.setFormat(k.getFormat());q.setDetail(k.getDetail());t.append(q);k.replace(t);c&&c(g.url,null);m=0}else m+=y;l=l.substring(y)}}f=e.getPreviousSibling();
13
- g=e.getNextSibling();k=e.getTextContent();h.$isAutoLinkNode(f)&&!B.test(k[0])&&(f.append(e),F(f,b,d),e=f.getURL(),c&&c(null,e));h.$isAutoLinkNode(g)&&!B.test(k[k.length-1])&&(G(g),F(g,b,d),e=g.getURL(),c&&c(null,e))}}))},[a,b,c])}exports.AutoLinkPlugin=function({matchers:a,onChange:b}){let [c]=n.useLexicalComposerContext();H(c,a,b);return null}
13
+ g=e.getNextSibling();k=e.getTextContent();h.$isAutoLinkNode(f)&&!B.test(k[0])&&(f.append(e),F(f,b,d),e=f.getURL(),c&&c(null,e));h.$isAutoLinkNode(g)&&!B.test(k[k.length-1])&&(G(g),F(g,b,d),e=g.getURL(),c&&c(null,e))}}))},[a,b,c])}exports.AutoLinkPlugin=function({matchers:a,onChange:b}){let [c]=n.useLexicalComposerContext();H(c,a,b);return null};exports.createLinkMatcherWithRegExp=function(a,b=c=>c){return c=>{let d=a.exec(c);return null===d?null:{index:d.index,length:d[0].length,text:d[0],url:b(c)}}}
@@ -7,10 +7,10 @@
7
7
  */
8
8
  /// <reference types="react" />
9
9
  import type { Doc } from 'yjs';
10
- import { Provider } from '@lexical/yjs';
10
+ import { ExcludedProperties, Provider } from '@lexical/yjs';
11
11
  import { InitialEditorStateType } from './LexicalComposer';
12
12
  import { CursorsContainerRef } from './shared/useYjsCollaboration';
13
- export declare function CollaborationPlugin({ id, providerFactory, shouldBootstrap, username, cursorColor, cursorsContainerRef, initialEditorState, }: {
13
+ declare type Props = {
14
14
  id: string;
15
15
  providerFactory: (id: string, yjsDocMap: Map<string, Doc>) => Provider;
16
16
  shouldBootstrap: boolean;
@@ -18,4 +18,7 @@ export declare function CollaborationPlugin({ id, providerFactory, shouldBootstr
18
18
  cursorColor?: string;
19
19
  cursorsContainerRef?: CursorsContainerRef;
20
20
  initialEditorState?: InitialEditorStateType;
21
- }): JSX.Element;
21
+ excludedProperties?: ExcludedProperties;
22
+ };
23
+ export declare function CollaborationPlugin({ id, providerFactory, shouldBootstrap, username, cursorColor, cursorsContainerRef, initialEditorState, excludedProperties, }: Props): JSX.Element;
24
+ export {};
@@ -22,10 +22,10 @@ var yjs$1 = require('yjs');
22
22
  * LICENSE file in the root directory of this source tree.
23
23
  *
24
24
  */
25
- function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBootstrap, cursorsContainerRef, initialEditorState) {
25
+ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBootstrap, cursorsContainerRef, initialEditorState, excludedProperties) {
26
26
  const isReloadingDoc = React.useRef(false);
27
27
  const [doc, setDoc] = React.useState(docMap.get(id));
28
- const binding = React.useMemo(() => yjs.createBinding(editor, provider, id, doc, docMap), [editor, provider, id, docMap, doc]);
28
+ const binding = React.useMemo(() => yjs.createBinding(editor, provider, id, doc, docMap, excludedProperties), [editor, provider, id, docMap, doc, excludedProperties]);
29
29
  const connect = React.useCallback(() => {
30
30
  provider.connect();
31
31
  }, [provider]);
@@ -290,7 +290,8 @@ function CollaborationPlugin({
290
290
  username,
291
291
  cursorColor,
292
292
  cursorsContainerRef,
293
- initialEditorState
293
+ initialEditorState,
294
+ excludedProperties
294
295
  }) {
295
296
  const collabContext = LexicalCollaborationContext.useCollaborationContext(username, cursorColor);
296
297
  const {
@@ -310,7 +311,7 @@ function CollaborationPlugin({
310
311
  };
311
312
  }, [collabContext, editor]);
312
313
  const provider = React.useMemo(() => providerFactory(id, yjsDocMap), [id, providerFactory, yjsDocMap]);
313
- const [cursors, binding] = useYjsCollaboration(editor, id, provider, yjsDocMap, name, color, shouldBootstrap, cursorsContainerRef, initialEditorState);
314
+ const [cursors, binding] = useYjsCollaboration(editor, id, provider, yjsDocMap, name, color, shouldBootstrap, cursorsContainerRef, initialEditorState, excludedProperties);
314
315
  collabContext.clientID = binding.clientID;
315
316
  useYjsHistory(editor, binding);
316
317
  useYjsFocusTracking(editor, provider, name, color);
@@ -4,12 +4,12 @@
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 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"),K=require("yjs");
8
- function L(b,c,a,d,p,x,y,l,t){let q=h.useRef(!1),[v,r]=h.useState(d.get(c)),g=h.useMemo(()=>H.createBinding(b,a,c,v,d),[b,a,c,d,v]),n=h.useCallback(()=>{a.connect()},[a]),w=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=>{y&&k&&m.isEmpty()&&0===m._xmlText._length&&!1===q.current&&M(b,t);q.current=!1},D=()=>{H.syncCursorPositions(g,a)},E=(k,u)=>{u=u.origin;u!==g&&H.syncYjsChangesToLexical(g,
9
- a,k,u instanceof K.UndoManager)};H.initLocalState(a,p,x,document.activeElement===b.getRootElement());let F=k=>{N(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 R=b.registerUpdateListener(({prevEditorState:k,editorState:u,dirtyLeaves:O,dirtyElements:P,normalizedNodes:Q,tags:G})=>{!1===G.has("skip-collab")&&H.syncLexicalUpdateToYjs(g,a,k,u,P,O,Q,G)});n();return()=>{!1===q.current&&w();a.off("sync",C);a.off("status",
10
- B);a.off("reload",F);A.off("update",D);m.getSharedType().unobserveDeep(E);d.delete(c);R()}},[g,x,n,w,d,b,c,t,p,a,y]);let S=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!==w&&(m?(console.log("Collaboration connected!"),n()):(console.log("Collaboration disconnected!"),w()));return!0},I.COMMAND_PRIORITY_EDITOR),[n,w,b]);return[S,g]}
11
- function T(b,c,a,d){h.useEffect(()=>z.mergeRegister(b.registerCommand(I.FOCUS_COMMAND,()=>{H.setLocalStateFocus(c,a,d,!0);return!1},I.COMMAND_PRIORITY_EDITOR),b.registerCommand(I.BLUR_COMMAND,()=>{H.setLocalStateFocus(c,a,d,!1);return!1},I.COMMAND_PRIORITY_EDITOR)),[d,b,a,c])}
12
- function U(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
- function M(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
- function N(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,cursorColor:p,cursorsContainerRef:x,initialEditorState:y}){let l=e.useCollaborationContext(d,p),{yjsDocMap:t,name:q,color:v}=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]=L(r,b,d,t,q,v,a,x,y);l.clientID=n.clientID;U(r,n);T(r,d,q,v);return g}
7
+ 'use strict';var e=require("@lexical/react/LexicalCollaborationContext"),f=require("@lexical/react/LexicalComposerContext"),h=require("react"),A=require("@lexical/utils"),I=require("@lexical/yjs"),J=require("lexical"),K=require("react-dom"),L=require("yjs");
8
+ function M(b,c,a,d,p,y,z,v,m,t){let q=h.useRef(!1),[w,r]=h.useState(d.get(c)),g=h.useMemo(()=>I.createBinding(b,a,c,w,d,t),[b,a,c,d,w,t]),n=h.useCallback(()=>{a.connect()},[a]),x=h.useCallback(()=>{try{a.disconnect()}catch(l){}},[a]);h.useEffect(()=>{let {root:l}=g,{awareness:B}=a,C=({status:k})=>{b.dispatchCommand(I.CONNECTED_COMMAND,"connected"===k)},D=k=>{z&&k&&l.isEmpty()&&0===l._xmlText._length&&!1===q.current&&N(b,m);q.current=!1},E=()=>{I.syncCursorPositions(g,a)},F=(k,u)=>{u=u.origin;u!==
9
+ g&&I.syncYjsChangesToLexical(g,a,k,u instanceof L.UndoManager)};I.initLocalState(a,p,y,document.activeElement===b.getRootElement());let G=k=>{O(b,g);r(k);d.set(c,k);q.current=!0};a.on("reload",G);a.on("status",C);a.on("sync",D);B.on("update",E);l.getSharedType().observeDeep(F);let S=b.registerUpdateListener(({prevEditorState:k,editorState:u,dirtyLeaves:P,dirtyElements:Q,normalizedNodes:R,tags:H})=>{!1===H.has("skip-collab")&&I.syncLexicalUpdateToYjs(g,a,k,u,Q,P,R,H)});n();return()=>{!1===q.current&&
10
+ x();a.off("sync",D);a.off("status",C);a.off("reload",G);B.off("update",E);l.getSharedType().unobserveDeep(F);d.delete(c);S()}},[g,y,n,x,d,b,c,m,p,a,z]);let T=h.useMemo(()=>K.createPortal(h.createElement("div",{ref:l=>{g.cursorsContainer=l}}),v&&v.current||document.body),[g,v]);h.useEffect(()=>b.registerCommand(I.TOGGLE_CONNECT_COMMAND,l=>{void 0!==n&&void 0!==x&&(l?(console.log("Collaboration connected!"),n()):(console.log("Collaboration disconnected!"),x()));return!0},J.COMMAND_PRIORITY_EDITOR),
11
+ [n,x,b]);return[T,g]}function U(b,c,a,d){h.useEffect(()=>A.mergeRegister(b.registerCommand(J.FOCUS_COMMAND,()=>{I.setLocalStateFocus(c,a,d,!0);return!1},J.COMMAND_PRIORITY_EDITOR),b.registerCommand(J.BLUR_COMMAND,()=>{I.setLocalStateFocus(c,a,d,!1);return!1},J.COMMAND_PRIORITY_EDITOR)),[d,b,a,c])}
12
+ function V(b,c){let a=h.useMemo(()=>I.createUndoManager(c,c.root.getSharedType()),[c]);h.useEffect(()=>A.mergeRegister(b.registerCommand(J.UNDO_COMMAND,()=>{a.undo();return!0},J.COMMAND_PRIORITY_EDITOR),b.registerCommand(J.REDO_COMMAND,()=>{a.redo();return!0},J.COMMAND_PRIORITY_EDITOR)));return h.useCallback(()=>{a.clear()},[a])}
13
+ function N(b,c){b.update(()=>{var a=J.$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(()=>{J.$getRoot().isEmpty()&&c(b)},{tag:"history-merge"})}else d=J.$createParagraphNode(),a.append(d),{activeElement:a}=document,(null!==J.$getSelection()||null!==a&&a===b.getRootElement())&&d.select()},{tag:"history-merge"})}
14
+ function O(b,c){b.update(()=>{let d=J.$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,cursorColor:p,cursorsContainerRef:y,initialEditorState:z,excludedProperties:v}){let m=e.useCollaborationContext(d,p),{yjsDocMap:t,name:q,color:w}=m,[r]=f.useLexicalComposerContext();h.useEffect(()=>{m.isCollabActive=!0;return()=>{null==r._parentEditor&&(m.isCollabActive=!1)}},[m,r]);d=h.useMemo(()=>c(b,t),[b,c,t]);let [g,n]=M(r,b,d,t,q,w,a,y,z,v);m.clientID=n.clientID;V(r,n);U(r,d,q,w);return g}
@@ -57,7 +57,7 @@ function LexicalComposer({
57
57
 
58
58
  if (editor === null) {
59
59
  const newEditor = lexical.createEditor({
60
- editable: false,
60
+ editable: initialConfig.editable,
61
61
  namespace,
62
62
  nodes,
63
63
  onError: error => onError(error, newEditor),
@@ -6,4 +6,4 @@
6
6
  */
7
7
  'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),g=require("react");let m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;var n=m?g.useLayoutEffect:g.useEffect;let p={tag:"history-merge"};
8
8
  function q(a,c){if(null!==c)if(void 0===c)a.update(()=>{var b=f.$getRoot();if(b.isEmpty()){let d=f.$createParagraphNode();b.append(d);b=m?document.activeElement:null;(null!==f.$getSelection()||null!==b&&b===a.getRootElement())&&d.select()}},p);else if(null!==c)switch(typeof c){case "string":let b=a.parseEditorState(c);a.setEditorState(b,p);break;case "object":a.setEditorState(c,p);break;case "function":a.update(()=>{f.$getRoot().isEmpty()&&c(a)},p)}}
9
- exports.LexicalComposer=function({initialConfig:a,children:c}){let b=g.useMemo(()=>{const {theme:d,namespace:h,editor__DEPRECATED:r,nodes:t,onError:u,editorState:v}=a,w=e.createLexicalComposerContext(null,d);let k=r||null;if(null===k){const l=f.createEditor({editable:!1,namespace:h,nodes:t,onError:x=>u(x,l),theme:d});q(l,v);k=l}return[k,w]},[]);n(()=>{let d=a.editable,[h]=b;h.setEditable(void 0!==d?d:!0)},[]);return g.createElement(e.LexicalComposerContext.Provider,{value:b},c)}
9
+ exports.LexicalComposer=function({initialConfig:a,children:c}){let b=g.useMemo(()=>{const {theme:d,namespace:h,editor__DEPRECATED:r,nodes:t,onError:u,editorState:v}=a,w=e.createLexicalComposerContext(null,d);let k=r||null;if(null===k){const l=f.createEditor({editable:a.editable,namespace:h,nodes:t,onError:x=>u(x,l),theme:d});q(l,v);k=l}return[k,w]},[]);n(()=>{let d=a.editable,[h]=b;h.setEditable(void 0!==d?d:!0)},[]);return g.createElement(e.LexicalComposerContext.Provider,{value:b},c)}
@@ -10,7 +10,7 @@
10
10
  import * as React from 'react';
11
11
 
12
12
  export type Props = $ReadOnly<{
13
- ...$Partial<HTMLDivElement>,
13
+ ...Partial<HTMLDivElement>,
14
14
  ariaActiveDescendant?: HTMLDivElement['aria-activedescendant'],
15
15
  ariaAutoComplete?: HTMLDivElement['aria-autocomplete'],
16
16
  ariaControls?: HTMLDivElement['aria-controls'],
@@ -8,10 +8,7 @@
8
8
  /// <reference types="react" />
9
9
  import type { DOMConversionMap, DOMExportOutput, LexicalCommand, LexicalNode, SerializedLexicalNode } from 'lexical';
10
10
  import { DecoratorNode } from 'lexical';
11
- export declare type SerializedHorizontalRuleNode = SerializedLexicalNode & {
12
- type: 'horizontalrule';
13
- version: 1;
14
- };
11
+ export declare type SerializedHorizontalRuleNode = SerializedLexicalNode;
15
12
  export declare const INSERT_HORIZONTAL_RULE_COMMAND: LexicalCommand<void>;
16
13
  export declare class HorizontalRuleNode extends DecoratorNode<JSX.Element> {
17
14
  static getType(): string;
@@ -21,9 +18,9 @@ export declare class HorizontalRuleNode extends DecoratorNode<JSX.Element> {
21
18
  exportJSON(): SerializedLexicalNode;
22
19
  exportDOM(): DOMExportOutput;
23
20
  createDOM(): HTMLElement;
24
- getTextContent(): '\n';
21
+ getTextContent(): string;
25
22
  isInline(): false;
26
- updateDOM(): false;
23
+ updateDOM(): boolean;
27
24
  decorate(): JSX.Element;
28
25
  }
29
26
  export declare function $createHorizontalRuleNode(): HorizontalRuleNode;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ type Props = $ReadOnly<{}>;
11
+
12
+ declare export function HorizontalRulePlugin(props: Props): null;
@@ -43,11 +43,13 @@ function LinkPlugin({
43
43
  const {
44
44
  url,
45
45
  target,
46
- rel
46
+ rel,
47
+ title
47
48
  } = payload;
48
49
  link.toggleLink(url, {
49
50
  rel,
50
- target
51
+ target,
52
+ title
51
53
  });
52
54
  return true;
53
55
  }
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict';var b=require("@lexical/link"),c=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/utils"),l=require("lexical"),m=require("react");
8
- exports.LinkPlugin=function({validateUrl:d}){let [e]=c.useLexicalComposerContext();m.useEffect(()=>{if(!e.hasNodes([b.LinkNode]))throw Error("LinkPlugin: LinkNode not registered on editor");return k.mergeRegister(e.registerCommand(b.TOGGLE_LINK_COMMAND,a=>{if(null===a)return b.toggleLink(a),!0;if("string"===typeof a)return void 0===d||d(a)?(b.toggleLink(a),!0):!1;let {url:f,target:g,rel:h}=a;b.toggleLink(f,{rel:h,target:g});return!0},l.COMMAND_PRIORITY_LOW),void 0!==d?e.registerCommand(l.PASTE_COMMAND,
8
+ exports.LinkPlugin=function({validateUrl:d}){let [e]=c.useLexicalComposerContext();m.useEffect(()=>{if(!e.hasNodes([b.LinkNode]))throw Error("LinkPlugin: LinkNode not registered on editor");return k.mergeRegister(e.registerCommand(b.TOGGLE_LINK_COMMAND,a=>{if(null===a)return b.toggleLink(a),!0;if("string"===typeof a)return void 0===d||d(a)?(b.toggleLink(a),!0):!1;let {url:f,target:g,rel:h,title:n}=a;b.toggleLink(f,{rel:h,target:g,title:n});return!0},l.COMMAND_PRIORITY_LOW),void 0!==d?e.registerCommand(l.PASTE_COMMAND,
9
9
  a=>{let f=l.$getSelection();if(!l.$isRangeSelection(f)||f.isCollapsed()||!(a instanceof ClipboardEvent)||null==a.clipboardData)return!1;let g=a.clipboardData.getData("text");return d(g)?f.getNodes().some(h=>l.$isElementNode(h))?!1:(e.dispatchCommand(b.TOGGLE_LINK_COMMAND,g),a.preventDefault(),!0):!1},l.COMMAND_PRIORITY_LOW):()=>{})},[e,d]);return null}
@@ -9,5 +9,5 @@ import type { EditorState, LexicalEditor } from 'lexical';
9
9
  export declare function OnChangePlugin({ ignoreHistoryMergeTagChange, ignoreSelectionChange, onChange, }: {
10
10
  ignoreHistoryMergeTagChange?: boolean;
11
11
  ignoreSelectionChange?: boolean;
12
- onChange: (editorState: EditorState, editor: LexicalEditor) => void;
12
+ onChange: (editorState: EditorState, editor: LexicalEditor, tags: Set<string>) => void;
13
13
  }): null;
@@ -54,7 +54,7 @@ function OnChangePlugin({
54
54
  return;
55
55
  }
56
56
 
57
- onChange(editorState, editor);
57
+ onChange(editorState, editor, tags);
58
58
  });
59
59
  }
60
60
  }, [editor, ignoreHistoryMergeTagChange, ignoreSelectionChange, onChange]);
@@ -4,5 +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 c=require("@lexical/react/LexicalComposerContext"),f=require("react"),g="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;
8
- exports.OnChangePlugin=function({ignoreHistoryMergeTagChange:d=!0,ignoreSelectionChange:e=!1,onChange:a}){let [b]=c.useLexicalComposerContext();g(()=>{if(a)return b.registerUpdateListener(({editorState:h,dirtyElements:k,dirtyLeaves:l,prevEditorState:m,tags:n})=>{e&&0===k.size&&0===l.size||d&&n.has("history-merge")||m.isEmpty()||a(h,b)})},[b,d,e,a]);return null}
7
+ 'use strict';var c=require("@lexical/react/LexicalComposerContext"),g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;
8
+ exports.OnChangePlugin=function({ignoreHistoryMergeTagChange:d=!0,ignoreSelectionChange:e=!1,onChange:a}){let [b]=c.useLexicalComposerContext();h(()=>{if(a)return b.registerUpdateListener(({editorState:k,dirtyElements:l,dirtyLeaves:m,prevEditorState:n,tags:f})=>{e&&0===l.size&&0===m.size||d&&f.has("history-merge")||n.isEmpty()||a(k,b,f)})},[b,d,e,a]);return null}
@@ -8,6 +8,7 @@
8
8
 
9
9
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
10
  var table = require('@lexical/table');
11
+ var utils = require('@lexical/utils');
11
12
  var lexical = require('lexical');
12
13
  var react = require('react');
13
14
 
@@ -32,36 +33,12 @@ function TablePlugin() {
32
33
  rows,
33
34
  includeHeaders
34
35
  }) => {
35
- const selection = lexical.$getSelection();
36
+ const tableNode = table.$createTableNodeWithDimensions(Number(rows), Number(columns), includeHeaders);
37
+ utils.$insertNodeToNearestRoot(tableNode);
38
+ const firstDescendant = tableNode.getFirstDescendant();
36
39
 
37
- if (!lexical.$isRangeSelection(selection)) {
38
- return true;
39
- }
40
-
41
- const focus = selection.focus;
42
- const focusNode = focus.getNode();
43
-
44
- if (focusNode !== null) {
45
- const tableNode = table.$createTableNodeWithDimensions(Number(rows), Number(columns), includeHeaders);
46
-
47
- if (lexical.$isRootOrShadowRoot(focusNode)) {
48
- const target = focusNode.getChildAtIndex(focus.offset);
49
-
50
- if (target !== null) {
51
- target.insertBefore(tableNode);
52
- } else {
53
- focusNode.append(tableNode);
54
- }
55
-
56
- tableNode.insertBefore(lexical.$createParagraphNode());
57
- } else {
58
- const topLevelNode = focusNode.getTopLevelElementOrThrow();
59
- topLevelNode.insertAfter(tableNode);
60
- }
61
-
62
- tableNode.insertAfter(lexical.$createParagraphNode());
63
- const firstCell = tableNode.getFirstChildOrThrow().getFirstChildOrThrow();
64
- firstCell.select();
40
+ if (lexical.$isTextNode(firstDescendant)) {
41
+ firstDescendant.select();
65
42
  }
66
43
 
67
44
  return true;
@@ -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 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}
7
+ 'use strict';var c=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/table"),l=require("@lexical/utils"),n=require("lexical"),p=require("react");
8
+ exports.TablePlugin=function(){let [e]=c.useLexicalComposerContext();p.useEffect(()=>{if(!e.hasNodes([g.TableNode,g.TableCellNode,g.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(g.INSERT_TABLE_COMMAND,({columns:a,rows:h,includeHeaders:k})=>{a=g.$createTableNodeWithDimensions(Number(h),Number(a),k);l.$insertNodeToNearestRoot(a);
9
+ a=a.getFirstDescendant();n.$isTextNode(a)&&a.select();return!0},n.COMMAND_PRIORITY_EDITOR)},[e]);p.useEffect(()=>{let a=new Map,h=b=>{const d=b.getKey(),f=e.getElementByKey(d);f&&!a.has(d)&&(b=g.applyTableHandlers(b,f,e),a.set(d,b))};e.getEditorState().read(()=>{let b=n.$nodesOfType(g.TableNode);for(let d of b)g.$isTableNode(d)&&h(d)});let k=e.registerMutationListener(g.TableNode,b=>{for(const [d,f]of b)"created"===f?e.getEditorState().read(()=>{const m=n.$getNodeByKey(d);g.$isTableNode(m)&&h(m)}):
10
+ "destroyed"===f&&(b=a.get(d),void 0!==b&&(b.removeListeners(),a.delete(d)))});return()=>{k();for(let [,b]of a)b.removeListeners()}},[e]);return null}
@@ -364,7 +364,7 @@ function printAllTextNodeProperties(node) {
364
364
  }
365
365
 
366
366
  function printAllLinkNodeProperties(node) {
367
- return [printTargetProperties(node), printRelProperties(node)].filter(Boolean).join(', ');
367
+ return [printTargetProperties(node), printRelProperties(node), printTitleProperties(node)].filter(Boolean).join(', ');
368
368
  }
369
369
 
370
370
  function printDetailProperties(nodeOrSelection) {
@@ -417,6 +417,16 @@ function printRelProperties(node) {
417
417
  return str;
418
418
  }
419
419
 
420
+ function printTitleProperties(node) {
421
+ let str = node.getTitle(); // TODO Fix nullish on LinkNode
422
+
423
+ if (str != null) {
424
+ str = 'title: ' + str;
425
+ }
426
+
427
+ return str;
428
+ }
429
+
420
430
  function printSelectedCharsLine({
421
431
  indent,
422
432
  isSelected,
@@ -4,20 +4,20 @@
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 k=require("@lexical/link"),t=require("@lexical/mark"),u=require("@lexical/utils"),F=require("lexical"),J=require("react");let K=Object.freeze({"\t":"\\t","\n":"\\n"}),L=new RegExp(Object.keys(K).join("|"),"g"),M=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
8
- function N(a){let [c,d]=J.useState([]);J.useEffect(()=>{let l=new Set;for(let [g]of a._commands)l.add(a.registerCommand(g,b=>{d(e=>{e=[...e];e.push({payload:b,type:g.type?g.type:"UNKNOWN"});10<e.length&&e.shift();return e});return!1},F.COMMAND_PRIORITY_HIGH));return()=>l.forEach(g=>g())},[a]);return J.useMemo(()=>c,[c])}
9
- function Q(a){let c="";var d=R(a);c+=`: range ${""!==d?`{ ${d} }`:""} ${""!==a.style?`{ style: ${a.style} } `:""}`;d=a.anchor;a=a.focus;let l=d.offset,g=a.offset;c+=`\n \u251c anchor { key: ${d.key}, offset: ${null===l?"null":l}, type: ${d.type} }`;return c+=`\n \u2514 focus { key: ${a.key}, offset: ${null===g?"null":g}, type: ${a.type} }`}
10
- function S(a,c,d,l,g){let b=" root\n";a=a.read(()=>{const e=F.$getSelection();T(F.$getRoot(),(h,y)=>{const v=`(${h.getKey()})`,r=h.getType()||"",z=h.isSelected(),n=t.$isMarkNode(h)?` id: [ ${h.getIDs().join(", ")} ] `:"";var x=b,D=z?M.selectedLine:" ",A=y.join(" ");if(F.$isTextNode(h)){var m=h.getTextContent();var p=0===m.length?"(empty)":`"${U(m)}"`;m=[R(h),V(h),W(h)].filter(Boolean).join(", ");m=[p,0!==m.length?`{ ${m} }`:null].filter(Boolean).join(" ").trim()}else if(k.$isLinkNode(h)){m=h.getURL();
11
- m=0===m.length?"(empty)":`"${U(m)}"`;p=h.getTarget();null!=p&&(p="target: "+p);var G=Boolean;let q=h.getRel();null!=q&&(q="rel: "+q);p=[p,q].filter(G).join(", ");m=[m,0!==p.length?`{ ${p} }`:null].filter(Boolean).join(" ").trim()}else m="";b=x+`${D} ${A} ${v} ${r} ${n} ${m}\n`;b+=X({indent:y,isSelected:z,node:h,nodeKeyDisplay:v,selection:e,typeDisplay:r})});return null===e?": null":F.$isRangeSelection(e)?Q(e):F.DEPRECATED_$isGridSelection(e)?`: grid\n \u2514 { grid: ${e.gridKey}, anchorCell: ${e.anchor.key}, focusCell: ${e.focus.key} }`:
7
+ 'use strict';var k=require("@lexical/link"),t=require("@lexical/mark"),u=require("@lexical/utils"),G=require("lexical"),K=require("react");let L=Object.freeze({"\t":"\\t","\n":"\\n"}),M=new RegExp(Object.keys(L).join("|"),"g"),N=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
8
+ function O(a){let [c,d]=K.useState([]);K.useEffect(()=>{let l=new Set;for(let [g]of a._commands)l.add(a.registerCommand(g,b=>{d(e=>{e=[...e];e.push({payload:b,type:g.type?g.type:"UNKNOWN"});10<e.length&&e.shift();return e});return!1},G.COMMAND_PRIORITY_HIGH));return()=>l.forEach(g=>g())},[a]);return K.useMemo(()=>c,[c])}
9
+ function R(a){let c="";var d=S(a);c+=`: range ${""!==d?`{ ${d} }`:""} ${""!==a.style?`{ style: ${a.style} } `:""}`;d=a.anchor;a=a.focus;let l=d.offset,g=a.offset;c+=`\n \u251c anchor { key: ${d.key}, offset: ${null===l?"null":l}, type: ${d.type} }`;return c+=`\n \u2514 focus { key: ${a.key}, offset: ${null===g?"null":g}, type: ${a.type} }`}
10
+ function T(a,c,d,l,g){let b=" root\n";a=a.read(()=>{const e=G.$getSelection();U(G.$getRoot(),(h,y)=>{const v=`(${h.getKey()})`,r=h.getType()||"",z=h.isSelected(),n=t.$isMarkNode(h)?` id: [ ${h.getIDs().join(", ")} ] `:"";var x=b,E=z?N.selectedLine:" ",A=y.join(" ");if(G.$isTextNode(h)){var m=h.getTextContent();var p=0===m.length?"(empty)":`"${V(m)}"`;m=[S(h),W(h),X(h)].filter(Boolean).join(", ");m=[p,0!==m.length?`{ ${m} }`:null].filter(Boolean).join(" ").trim()}else if(k.$isLinkNode(h)){m=h.getURL();
11
+ m=0===m.length?"(empty)":`"${V(m)}"`;p=h.getTarget();null!=p&&(p="target: "+p);var H=Boolean;var q=h.getRel();null!=q&&(q="rel: "+q);let B=h.getTitle();null!=B&&(B="title: "+B);p=[p,q,B].filter(H).join(", ");m=[m,0!==p.length?`{ ${p} }`:null].filter(Boolean).join(" ").trim()}else m="";b=x+`${E} ${A} ${v} ${r} ${n} ${m}\n`;b+=Y({indent:y,isSelected:z,node:h,nodeKeyDisplay:v,selection:e,typeDisplay:r})});return null===e?": null":G.$isRangeSelection(e)?R(e):G.DEPRECATED_$isGridSelection(e)?`: grid\n \u2514 { grid: ${e.gridKey}, anchorCell: ${e.anchor.key}, focusCell: ${e.focus.key} }`:
12
12
  `: node\n \u2514 [${Array.from(e._nodes).join(", ")}]`});b+="\n selection"+a;b+="\n\n commands:";if(d.length)for(let {type:e,payload:h}of d)b+=`\n \u2514 { type: ${e}, payload: ${h instanceof Event?h.constructor.name:h} }`;else b+="\n \u2514 None dispatched.";b+="\n\n editor:";b+=`\n \u2514 namespace ${c.namespace}`;null!==l&&(b+=`\n \u2514 compositionKey ${l}`);return b+=`\n \u2514 editable ${String(g)}`}
13
- function T(a,c,d=[]){a=a.getChildren();let l=a.length;a.forEach((g,b)=>{c(g,d.concat(b===l-1?M.isLastChild:M.hasNextSibling));F.$isElementNode(g)&&T(g,c,d.concat(b===l-1?M.ancestorIsLastChild:M.ancestorHasNextSibling))})}function U(a){return Object.entries(K).reduce((c,[d,l])=>c.replace(new RegExp(d,"g"),String(l)),a)}
14
- let Y=[a=>a.hasFormat("bold")&&"Bold",a=>a.hasFormat("code")&&"Code",a=>a.hasFormat("italic")&&"Italic",a=>a.hasFormat("strikethrough")&&"Strikethrough",a=>a.hasFormat("subscript")&&"Subscript",a=>a.hasFormat("superscript")&&"Superscript",a=>a.hasFormat("underline")&&"Underline"],Z=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],aa=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented"];
15
- function V(a){let c=Z.map(d=>d(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="detail: "+c);return c}function W(a){let c=aa.map(d=>d(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="mode: "+c);return c}function R(a){let c=Y.map(d=>d(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="format: "+c);return c}
16
- function X({indent:a,isSelected:c,node:d,nodeKeyDisplay:l,selection:g,typeDisplay:b}){if(!F.$isTextNode(d)||!F.$isRangeSelection(g)||!c||F.$isElementNode(d))return"";c=g.anchor;var e=g.focus;if(""===d.getTextContent()||c.getNode()===g.focus.getNode()&&c.offset===e.offset)return"";e=g.anchor;let h=g.focus,y=d.getTextContent(),v=y.length;c=g=-1;if("text"===e.type&&"text"===h.type){let n=e.getNode(),x=h.getNode();n===x&&d===n&&e.offset!==h.offset?[g,c]=e.offset<h.offset?[e.offset,h.offset]:[h.offset,
17
- e.offset]:d===n?[g,c]=n.isBefore(x)?[e.offset,v]:[0,e.offset]:d===x?[g,c]=x.isBefore(n)?[h.offset,v]:[0,h.offset]:[g,c]=[0,v]}d=(y.slice(0,g).match(L)||[]).length;e=(y.slice(g,c).match(L)||[]).length;let [r,z]=[g+d,c+d+e];if(r===z)return"";d=a[a.length-1]===M.hasNextSibling?M.ancestorHasNextSibling:M.ancestorIsLastChild;a=[...a.slice(0,a.length-1),d];d=Array(r+1).fill(" ");g=Array(z-r).fill(M.selectedChar);l=Array(l.length+(b.length+3)).fill(" ");return[M.selectedLine,a.join(" "),[...l,...d,...g].join("")].join(" ")+
13
+ function U(a,c,d=[]){a=a.getChildren();let l=a.length;a.forEach((g,b)=>{c(g,d.concat(b===l-1?N.isLastChild:N.hasNextSibling));G.$isElementNode(g)&&U(g,c,d.concat(b===l-1?N.ancestorIsLastChild:N.ancestorHasNextSibling))})}function V(a){return Object.entries(L).reduce((c,[d,l])=>c.replace(new RegExp(d,"g"),String(l)),a)}
14
+ let Z=[a=>a.hasFormat("bold")&&"Bold",a=>a.hasFormat("code")&&"Code",a=>a.hasFormat("italic")&&"Italic",a=>a.hasFormat("strikethrough")&&"Strikethrough",a=>a.hasFormat("subscript")&&"Subscript",a=>a.hasFormat("superscript")&&"Superscript",a=>a.hasFormat("underline")&&"Underline"],aa=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],ba=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented"];
15
+ function W(a){let c=aa.map(d=>d(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="detail: "+c);return c}function X(a){let c=ba.map(d=>d(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="mode: "+c);return c}function S(a){let c=Z.map(d=>d(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="format: "+c);return c}
16
+ function Y({indent:a,isSelected:c,node:d,nodeKeyDisplay:l,selection:g,typeDisplay:b}){if(!G.$isTextNode(d)||!G.$isRangeSelection(g)||!c||G.$isElementNode(d))return"";c=g.anchor;var e=g.focus;if(""===d.getTextContent()||c.getNode()===g.focus.getNode()&&c.offset===e.offset)return"";e=g.anchor;let h=g.focus,y=d.getTextContent(),v=y.length;c=g=-1;if("text"===e.type&&"text"===h.type){let n=e.getNode(),x=h.getNode();n===x&&d===n&&e.offset!==h.offset?[g,c]=e.offset<h.offset?[e.offset,h.offset]:[h.offset,
17
+ e.offset]:d===n?[g,c]=n.isBefore(x)?[e.offset,v]:[0,e.offset]:d===x?[g,c]=x.isBefore(n)?[h.offset,v]:[0,h.offset]:[g,c]=[0,v]}d=(y.slice(0,g).match(M)||[]).length;e=(y.slice(g,c).match(M)||[]).length;let [r,z]=[g+d,c+d+e];if(r===z)return"";d=a[a.length-1]===N.hasNextSibling?N.ancestorHasNextSibling:N.ancestorIsLastChild;a=[...a.slice(0,a.length-1),d];d=Array(r+1).fill(" ");g=Array(z-r).fill(N.selectedChar);l=Array(l.length+(b.length+3)).fill(" ");return[N.selectedLine,a.join(" "),[...l,...d,...g].join("")].join(" ")+
18
18
  "\n"}
19
- exports.TreeView=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:d,viewClassName:l,timeTravelPanelClassName:g,editor:b}){let [e,h]=J.useState([]),[y,v]=J.useState(""),[r,z]=J.useState(!1),n=J.useRef(0),x=J.useRef(null),D=J.useRef(null),[A,m]=J.useState(!1),[p,G]=J.useState(!1),[q,ba]=J.useState(!1),H=J.useRef(null),B=N(b),I=J.useCallback(f=>{const w=S(b.getEditorState(),b._config,B,b._compositionKey,b._editable);v(w);r||h(E=>[...E,[Date.now(),f]])},
20
- [B,b,r]);J.useEffect(()=>{let f=b.getEditorState();!q&&1E3<f._nodeMap.size&&v(S(f,b._config,B,b._compositionKey,b._editable))},[B,b,q]);J.useEffect(()=>u.mergeRegister(b.registerUpdateListener(({editorState:f})=>{if(!q&&1E3<f._nodeMap.size&&(H.current=f,G(!0),!q))return;I(f)}),b.registerEditableListener(()=>{let f=S(b.getEditorState(),b._config,B,b._compositionKey,b._editable);v(f)})),[B,b,p,I,q]);let C=e.length;J.useEffect(()=>{if(A){let f,w=()=>{const E=n.current;E===C-1?m(!1):f=setTimeout(()=>
21
- {n.current++;const O=n.current,P=D.current;null!==P&&(P.value=String(O));b.setEditorState(e[O][1]);w()},e[E+1][0]-e[E][0])};w();return()=>{clearTimeout(f)}}},[e,A,b,C]);J.useEffect(()=>{let f=x.current;if(null!==f)return f.__lexicalEditor=b,()=>{f.__lexicalEditor=null}},[b]);return J.createElement("div",{className:l},!q&&p?J.createElement("div",{style:{padding:20}},J.createElement("span",{style:{marginRight:20}},"Detected large EditorState, this can impact debugging performance."),J.createElement("button",
22
- {onClick:()=>{ba(!0);let f=H.current;null!==f&&(H.current=null,I(f))},style:{background:"transparent",border:"1px solid white",color:"white",cursor:"pointer",padding:5}},"Show full tree")):null,!r&&(q||!p)&&2<C&&J.createElement("button",{onClick:()=>{let f=b.getRootElement();null!==f&&(f.contentEditable="false",n.current=C-1,z(!0))},className:a,type:"button"},"Time Travel"),(q||!p)&&J.createElement("pre",{ref:x},y),r&&(q||!p)&&J.createElement("div",{className:g},J.createElement("button",{className:d,
23
- onClick:()=>{n.current===C-1&&(n.current=1);m(!A)},type:"button"},A?"Pause":"Play"),J.createElement("input",{className:c,ref:D,onChange:f=>{f=Number(f.target.value);let w=e[f];w&&(n.current=f,b.setEditorState(w[1]))},type:"range",min:"1",max:C-1}),J.createElement("button",{className:d,onClick:()=>{var f=b.getRootElement();if(null!==f){f.contentEditable="true";f=e.length-1;b.setEditorState(e[f][1]);let w=D.current;null!==w&&(w.value=String(f));z(!1);m(!1)}},type:"button"},"Exit")))}
19
+ exports.TreeView=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:d,viewClassName:l,timeTravelPanelClassName:g,editor:b}){let [e,h]=K.useState([]),[y,v]=K.useState(""),[r,z]=K.useState(!1),n=K.useRef(0),x=K.useRef(null),E=K.useRef(null),[A,m]=K.useState(!1),[p,H]=K.useState(!1),[q,B]=K.useState(!1),I=K.useRef(null),C=O(b),J=K.useCallback(f=>{const w=T(b.getEditorState(),b._config,C,b._compositionKey,b._editable);v(w);r||h(F=>[...F,[Date.now(),f]])},
20
+ [C,b,r]);K.useEffect(()=>{let f=b.getEditorState();!q&&1E3<f._nodeMap.size&&v(T(f,b._config,C,b._compositionKey,b._editable))},[C,b,q]);K.useEffect(()=>u.mergeRegister(b.registerUpdateListener(({editorState:f})=>{if(!q&&1E3<f._nodeMap.size&&(I.current=f,H(!0),!q))return;J(f)}),b.registerEditableListener(()=>{let f=T(b.getEditorState(),b._config,C,b._compositionKey,b._editable);v(f)})),[C,b,p,J,q]);let D=e.length;K.useEffect(()=>{if(A){let f,w=()=>{const F=n.current;F===D-1?m(!1):f=setTimeout(()=>
21
+ {n.current++;const P=n.current,Q=E.current;null!==Q&&(Q.value=String(P));b.setEditorState(e[P][1]);w()},e[F+1][0]-e[F][0])};w();return()=>{clearTimeout(f)}}},[e,A,b,D]);K.useEffect(()=>{let f=x.current;if(null!==f)return f.__lexicalEditor=b,()=>{f.__lexicalEditor=null}},[b]);return K.createElement("div",{className:l},!q&&p?K.createElement("div",{style:{padding:20}},K.createElement("span",{style:{marginRight:20}},"Detected large EditorState, this can impact debugging performance."),K.createElement("button",
22
+ {onClick:()=>{B(!0);let f=I.current;null!==f&&(I.current=null,J(f))},style:{background:"transparent",border:"1px solid white",color:"white",cursor:"pointer",padding:5}},"Show full tree")):null,!r&&(q||!p)&&2<D&&K.createElement("button",{onClick:()=>{let f=b.getRootElement();null!==f&&(f.contentEditable="false",n.current=D-1,z(!0))},className:a,type:"button"},"Time Travel"),(q||!p)&&K.createElement("pre",{ref:x},y),r&&(q||!p)&&K.createElement("div",{className:g},K.createElement("button",{className:d,
23
+ onClick:()=>{n.current===D-1&&(n.current=1);m(!A)},type:"button"},A?"Pause":"Play"),K.createElement("input",{className:c,ref:E,onChange:f=>{f=Number(f.target.value);let w=e[f];w&&(n.current=f,b.setEditorState(w[1]))},type:"range",min:"1",max:D-1}),K.createElement("button",{className:d,onClick:()=>{var f=b.getRootElement();if(null!==f){f.contentEditable="true";f=e.length-1;b.setEditorState(e[f][1]);let w=E.current;null!==w&&(w.value=String(f));z(!1);m(!1)}},type:"button"},"Exit")))}
@@ -56,9 +56,7 @@ class TypeaheadOption {
56
56
  }
57
57
 
58
58
  const scrollIntoViewIfNeeded = target => {
59
- const container = document.getElementById('typeahead-menu');
60
- if (!container) return;
61
- const typeaheadContainerNode = container.querySelector('.typeahead-popover');
59
+ const typeaheadContainerNode = document.getElementById('typeahead-menu');
62
60
  if (!typeaheadContainerNode) return;
63
61
  const typeaheadRect = typeaheadContainerNode.getBoundingClientRect();
64
62
 
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict';var k=require("@lexical/react/LexicalComposerContext"),n=require("@lexical/utils"),x=require("lexical"),y=require("react"),z="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?y.useLayoutEffect:y.useEffect;class A{constructor(c){this.key=c;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(c){this.ref={current:c}}}
8
- let B=c=>{var a=document.getElementById("typeahead-menu");if(a&&(a=a.querySelector(".typeahead-popover"))){var b=a.getBoundingClientRect();b.top+b.height>window.innerHeight&&a.scrollIntoView({block:"center"});0>b.top&&a.scrollIntoView({block:"center"});c.scrollIntoView({block:"nearest"})}};function C(c,a){var b=window.getSelection();if(null===b||!b.isCollapsed)return!1;let e=b.anchorNode;b=b.anchorOffset;if(null==e||null==b)return!1;try{a.setStart(e,c),a.setEnd(e,b)}catch(g){return!1}return!0}
8
+ let B=c=>{const a=document.getElementById("typeahead-menu");if(a){var b=a.getBoundingClientRect();b.top+b.height>window.innerHeight&&a.scrollIntoView({block:"center"});0>b.top&&a.scrollIntoView({block:"center"});c.scrollIntoView({block:"nearest"})}};function C(c,a){var b=window.getSelection();if(null===b||!b.isCollapsed)return!1;let e=b.anchorNode;b=b.anchorOffset;if(null==e||null==b)return!1;try{a.setStart(e,c),a.setEnd(e,b)}catch(g){return!1}return!0}
9
9
  function D(c){let a=null;c.getEditorState().read(()=>{var b=x.$getSelection();if(x.$isRangeSelection(b)){var e=b.anchor;"text"!==e.type?a=null:(b=e.getNode(),b.isSimpleText()?(e=e.offset,a=b.getTextContent().slice(0,e)):a=null)}});return a}
10
10
  function E(c,a){c=x.$getSelection();if(!x.$isRangeSelection(c)||!c.isCollapsed())return null;var b=c.anchor;if("text"!==b.type)return null;c=b.getNode();if(!c.isSimpleText())return null;b=b.offset;let e=c.getTextContent().slice(0,b);var g=a.matchingString;a=a.replaceableString.length;for(let p=a;p<=g.length;p++)e.substr(-p)===g.substr(0,p)&&(a=p);a=b-a;if(0>a)return null;let q;0===a?[q]=c.splitText(b):[,q]=c.splitText(a,b);return q}
11
11
  function F(c,a){return 0!==a?!1:c.getEditorState().read(()=>{var b=x.$getSelection();return x.$isRangeSelection(b)?(b=b.anchor.getNode().getPreviousSibling(),x.$isTextNode(b)&&b.isTextEntity()):!1})}function G(c){y.startTransition?y.startTransition(c):c()}
package/package.json CHANGED
@@ -8,29 +8,29 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.9.0",
11
+ "version": "0.9.2",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.9.0",
14
- "@lexical/code": "0.9.0",
15
- "@lexical/dragon": "0.9.0",
16
- "@lexical/hashtag": "0.9.0",
17
- "@lexical/history": "0.9.0",
18
- "@lexical/link": "0.9.0",
19
- "@lexical/list": "0.9.0",
20
- "@lexical/mark": "0.9.0",
21
- "@lexical/markdown": "0.9.0",
22
- "@lexical/overflow": "0.9.0",
23
- "@lexical/plain-text": "0.9.0",
24
- "@lexical/rich-text": "0.9.0",
25
- "@lexical/selection": "0.9.0",
26
- "@lexical/table": "0.9.0",
27
- "@lexical/text": "0.9.0",
28
- "@lexical/utils": "0.9.0",
29
- "@lexical/yjs": "0.9.0",
13
+ "@lexical/clipboard": "0.9.2",
14
+ "@lexical/code": "0.9.2",
15
+ "@lexical/dragon": "0.9.2",
16
+ "@lexical/hashtag": "0.9.2",
17
+ "@lexical/history": "0.9.2",
18
+ "@lexical/link": "0.9.2",
19
+ "@lexical/list": "0.9.2",
20
+ "@lexical/mark": "0.9.2",
21
+ "@lexical/markdown": "0.9.2",
22
+ "@lexical/overflow": "0.9.2",
23
+ "@lexical/plain-text": "0.9.2",
24
+ "@lexical/rich-text": "0.9.2",
25
+ "@lexical/selection": "0.9.2",
26
+ "@lexical/table": "0.9.2",
27
+ "@lexical/text": "0.9.2",
28
+ "@lexical/utils": "0.9.2",
29
+ "@lexical/yjs": "0.9.2",
30
30
  "react-error-boundary": "^3.1.4"
31
31
  },
32
32
  "peerDependencies": {
33
- "lexical": "0.9.0",
33
+ "lexical": "0.9.2",
34
34
  "react": ">=17.x",
35
35
  "react-dom": ">=17.x"
36
36
  },
@@ -5,12 +5,12 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { Binding, Provider } from '@lexical/yjs';
8
+ import type { Binding, ExcludedProperties, Provider } from '@lexical/yjs';
9
9
  import type { LexicalEditor } from 'lexical';
10
10
  import * as React from 'react';
11
11
  import { Doc } from 'yjs';
12
12
  import { InitialEditorStateType } from '../LexicalComposer';
13
13
  export declare type CursorsContainerRef = React.MutableRefObject<HTMLElement | null>;
14
- export declare function useYjsCollaboration(editor: LexicalEditor, id: string, provider: Provider, docMap: Map<string, Doc>, name: string, color: string, shouldBootstrap: boolean, cursorsContainerRef?: CursorsContainerRef, initialEditorState?: InitialEditorStateType): [JSX.Element, Binding];
14
+ export declare function useYjsCollaboration(editor: LexicalEditor, id: string, provider: Provider, docMap: Map<string, Doc>, name: string, color: string, shouldBootstrap: boolean, cursorsContainerRef?: CursorsContainerRef, initialEditorState?: InitialEditorStateType, excludedProperties?: ExcludedProperties): [JSX.Element, Binding];
15
15
  export declare function useYjsFocusTracking(editor: LexicalEditor, provider: Provider, name: string, color: string): void;
16
16
  export declare function useYjsHistory(editor: LexicalEditor, binding: Binding): () => void;