@lexical/react 0.12.2 → 0.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LexicalAutoEmbedPlugin.d.ts +3 -2
  2. package/LexicalAutoEmbedPlugin.dev.js +4 -14
  3. package/LexicalAutoEmbedPlugin.prod.js +4 -3
  4. package/LexicalAutoFocusPlugin.dev.js +0 -1
  5. package/LexicalAutoLinkPlugin.dev.js +126 -73
  6. package/LexicalAutoLinkPlugin.prod.js +11 -7
  7. package/LexicalBlockWithAlignableContents.dev.js +0 -10
  8. package/LexicalCharacterLimitPlugin.dev.js +7 -46
  9. package/LexicalCheckListPlugin.dev.js +10 -48
  10. package/LexicalClearEditorPlugin.dev.js +1 -1
  11. package/LexicalClickableLinkPlugin.dev.js +2 -20
  12. package/LexicalCollaborationContext.dev.js +0 -3
  13. package/LexicalCollaborationPlugin.dev.js +8 -37
  14. package/LexicalComposer.d.ts +3 -7
  15. package/LexicalComposer.dev.js +9 -11
  16. package/LexicalComposer.js.flow +4 -4
  17. package/LexicalComposer.prod.js +2 -1
  18. package/LexicalComposerContext.dev.js +0 -6
  19. package/LexicalContentEditable.dev.js +1 -2
  20. package/LexicalContextMenuPlugin.d.ts +3 -2
  21. package/LexicalContextMenuPlugin.dev.js +28 -82
  22. package/LexicalContextMenuPlugin.prod.js +16 -15
  23. package/LexicalDecoratorBlockNode.dev.js +0 -6
  24. package/LexicalEditorRefPlugin.dev.js +0 -3
  25. package/LexicalHashtagPlugin.dev.js +73 -43
  26. package/LexicalHorizontalRuleNode.dev.js +0 -21
  27. package/LexicalHorizontalRulePlugin.dev.js +0 -4
  28. package/LexicalLinkPlugin.dev.js +4 -10
  29. package/LexicalListPlugin.dev.js +0 -2
  30. package/LexicalMarkdownShortcutPlugin.dev.js +2 -2
  31. package/LexicalNestedComposer.d.ts +2 -2
  32. package/LexicalNestedComposer.dev.js +18 -16
  33. package/LexicalNestedComposer.js.flow +7 -2
  34. package/LexicalNestedComposer.prod.js +4 -3
  35. package/LexicalNodeEventPlugin.dev.js +2 -6
  36. package/LexicalNodeMenuPlugin.d.ts +3 -2
  37. package/LexicalNodeMenuPlugin.dev.js +27 -83
  38. package/LexicalNodeMenuPlugin.prod.js +15 -15
  39. package/LexicalOnChangePlugin.dev.js +1 -1
  40. package/LexicalPlainTextPlugin.dev.js +8 -12
  41. package/LexicalRichTextPlugin.dev.js +8 -12
  42. package/LexicalTabIndentationPlugin.dev.js +7 -16
  43. package/LexicalTableOfContents.dev.js +5 -33
  44. package/LexicalTablePlugin.dev.js +11 -28
  45. package/LexicalTreeView.dev.js +14 -79
  46. package/LexicalTypeaheadMenuPlugin.d.ts +4 -3
  47. package/LexicalTypeaheadMenuPlugin.dev.js +39 -176
  48. package/LexicalTypeaheadMenuPlugin.prod.js +19 -20
  49. package/package.json +19 -19
  50. package/shared/LexicalMenu.d.ts +3 -2
  51. package/useLexicalEditable.dev.js +1 -5
  52. package/useLexicalIsTextContentEmpty.dev.js +1 -0
  53. package/useLexicalNodeSelection.dev.js +0 -7
  54. package/useLexicalSubscription.dev.js +1 -3
@@ -4,23 +4,22 @@
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/react/LexicalComposerContext"),m=require("lexical"),x=require("react"),y=require("@lexical/utils"),z="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?x.useLayoutEffect:x.useEffect;class A{constructor(b){this.key=b;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(b){this.ref={current:b}}}
8
- let B=b=>{const a=document.getElementById("typeahead-menu");if(a){var c=a.getBoundingClientRect();c.top+c.height>window.innerHeight&&a.scrollIntoView({block:"center"});0>c.top&&a.scrollIntoView({block:"center"});b.scrollIntoView({block:"nearest"})}};
9
- function C(b){var a=m.$getSelection();if(!m.$isRangeSelection(a)||!a.isCollapsed())return null;var c=a.anchor;if("text"!==c.type)return null;a=c.getNode();if(!a.isSimpleText())return null;c=c.offset;let e=a.getTextContent().slice(0,c);var f=b.matchingString;b=b.replaceableString.length;for(let t=b;t<=f.length;t++)e.substr(-t)===f.substr(0,t)&&(b=t);b=c-b;if(0>b)return null;let r;0===b?[r]=a.splitText(c):[,r]=a.splitText(b,c);return r}
10
- function D(b,a){let c=getComputedStyle(b),e="absolute"===c.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===c.position)return document.body;for(;b=b.parentElement;)if(c=getComputedStyle(b),(!e||"static"!==c.position)&&a.test(c.overflow+c.overflowY+c.overflowX))return b;return document.body}function F(b,a){b=b.getBoundingClientRect();a=a.getBoundingClientRect();return b.top>a.top&&b.top<a.bottom}
11
- function G(b,a,c,e){let [f]=k.useLexicalComposerContext();x.useEffect(()=>{if(null!=a&&null!=b){let r=f.getRootElement(),t=null!=r?D(r,!1):document.body,l=!1,d=F(a,t),h=function(){l||(window.requestAnimationFrame(function(){c();l=!1}),l=!0);const n=F(a,t);n!==d&&(d=n,null!=e&&e(n))},q=new ResizeObserver(c);window.addEventListener("resize",c);document.addEventListener("scroll",h,{capture:!0,passive:!0});q.observe(a);return()=>{q.unobserve(a);window.removeEventListener("resize",c);document.removeEventListener("scroll",
12
- h)}}},[a,f,e,c,b])}let H=m.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
13
- function I({close:b,editor:a,anchorElementRef:c,resolution:e,options:f,menuRenderFn:r,onSelectOption:t,shouldSplitNodeWithQuery:l=!1}){let [d,h]=x.useState(null);x.useEffect(()=>{h(0)},[e.match&&e.match.matchingString]);let q=x.useCallback(g=>{a.update(()=>{const p=null!=e.match&&l?C(e.match):null;t(g,p,b,e.match?e.match.matchingString:"")})},[a,l,e.match,t,b]),n=x.useCallback(g=>{const p=a.getRootElement();null!==p&&(p.setAttribute("aria-activedescendant","typeahead-item-"+g),h(g))},[a]);x.useEffect(()=>
14
- ()=>{let g=a.getRootElement();null!==g&&g.removeAttribute("aria-activedescendant")},[a]);z(()=>{null===f?h(null):null===d&&n(0)},[f,d,n]);x.useEffect(()=>y.mergeRegister(a.registerCommand(H,({option:g})=>g.ref&&null!=g.ref.current?(B(g.ref.current),!0):!1,m.COMMAND_PRIORITY_LOW)),[a,n]);x.useEffect(()=>y.mergeRegister(a.registerCommand(m.KEY_ARROW_DOWN_COMMAND,g=>{if(null!==f&&f.length&&null!==d){let p=d!==f.length-1?d+1:0;n(p);let u=f[p];null!=u.ref&&u.ref.current&&a.dispatchCommand(H,{index:p,option:u});
15
- g.preventDefault();g.stopImmediatePropagation()}return!0},m.COMMAND_PRIORITY_LOW),a.registerCommand(m.KEY_ARROW_UP_COMMAND,g=>{if(null!==f&&f.length&&null!==d){var p=0!==d?d-1:f.length-1;n(p);p=f[p];null!=p.ref&&p.ref.current&&B(p.ref.current);g.preventDefault();g.stopImmediatePropagation()}return!0},m.COMMAND_PRIORITY_LOW),a.registerCommand(m.KEY_ESCAPE_COMMAND,g=>{g.preventDefault();g.stopImmediatePropagation();b();return!0},m.COMMAND_PRIORITY_LOW),a.registerCommand(m.KEY_TAB_COMMAND,g=>{if(null===
16
- f||null===d||null==f[d])return!1;g.preventDefault();g.stopImmediatePropagation();q(f[d]);return!0},m.COMMAND_PRIORITY_LOW),a.registerCommand(m.KEY_ENTER_COMMAND,g=>{if(null===f||null===d||null==f[d])return!1;null!==g&&(g.preventDefault(),g.stopImmediatePropagation());q(f[d]);return!0},m.COMMAND_PRIORITY_LOW)),[q,b,a,f,d,n]);let v=x.useMemo(()=>({options:f,selectOptionAndCleanUp:q,selectedIndex:d,setHighlightedIndex:h}),[q,d,f]);return r(c,v,e.match?e.match.matchingString:"")}
17
- function J(b,a,c){let [e]=k.useLexicalComposerContext(),f=x.useRef(document.createElement("div")),r=x.useCallback(()=>{const l=e.getRootElement(),d=f.current;var h=d.firstChild;if(null!==l&&null!==b){const {left:n,top:v,width:g,height:p}=b.getRect();d.style.top=`${v+window.pageYOffset}px`;d.style.left=`${n+window.pageXOffset}px`;d.style.height=`${p}px`;d.style.width=`${g}px`;if(null!==h){var q=h.getBoundingClientRect();h=q.height;q=q.width;const u=l.getBoundingClientRect();n+q>u.right&&(d.style.left=
18
- `${u.right-q+window.pageXOffset}px`);(v+h>window.innerHeight||v+h>u.bottom)&&v-u.top>h&&(d.style.top=`${v-h+window.pageYOffset-(p+10)}px`)}d.isConnected||(null!=c&&(d.className=c),d.setAttribute("aria-label","Typeahead menu"),d.setAttribute("id","typeahead-menu"),d.setAttribute("role","listbox"),d.style.display="block",d.style.position="absolute",document.body.append(d));f.current=d;l.setAttribute("aria-controls","typeahead-menu")}},[e,b,c]);x.useEffect(()=>{let l=e.getRootElement();if(null!==b)return r(),
19
- ()=>{null!==l&&l.removeAttribute("aria-controls");let d=f.current;null!==d&&d.isConnected&&d.remove()}},[e,r,b]);let t=x.useCallback(l=>{null!==b&&(l||a(null))},[b,a]);G(b,f.current,r,t);return f}function K(b,a){var c=window.getSelection();if(null===c||!c.isCollapsed)return!1;let e=c.anchorNode;c=c.anchorOffset;if(null==e||null==c)return!1;try{a.setStart(e,b),a.setEnd(e,c)}catch(f){return!1}return!0}
20
- function L(b){let a=null;b.getEditorState().read(()=>{var c=m.$getSelection();if(m.$isRangeSelection(c)){var e=c.anchor;"text"!==e.type?a=null:(c=e.getNode(),c.isSimpleText()?(e=e.offset,a=c.getTextContent().slice(0,e)):a=null)}});return a}function M(b,a){return 0!==a?!1:b.getEditorState().read(()=>{var c=m.$getSelection();return m.$isRangeSelection(c)?(c=c.anchor.getNode().getPreviousSibling(),m.$isTextNode(c)&&c.isTextEntity()):!1})}function N(b){x.startTransition?x.startTransition(b):b()}
21
- function O(b,a){let c=getComputedStyle(b),e="absolute"===c.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===c.position)return document.body;for(;b=b.parentElement;)if(c=getComputedStyle(b),(!e||"static"!==c.position)&&a.test(c.overflow+c.overflowY+c.overflowX))return b;return document.body}function P(b,a){b=b.getBoundingClientRect();a=a.getBoundingClientRect();return b.top>a.top&&b.top<a.bottom}let Q=m.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
22
- exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,onOpen:e,onClose:f,menuRenderFn:r,triggerFn:t,anchorClassName:l}){let [d]=k.useLexicalComposerContext(),[h,q]=x.useState(null);l=J(h,q,l);let n=x.useCallback(()=>{q(null);null!=f&&null!==h&&f()},[f,h]),v=x.useCallback(g=>{q(g);null!=e&&null===h&&e(g)},[e,h]);x.useEffect(()=>{let g=d.registerUpdateListener(()=>{d.getEditorState().read(()=>{const p=document.createRange(),u=m.$getSelection(),E=L(d);if(m.$isRangeSelection(u)&&
23
- u.isCollapsed()&&null!==E&&null!==p){var w=t(E,d);a(w?w.matchingString:null);null===w||M(d,w.leadOffset)||null===K(w.leadOffset,p)?n():N(()=>v({getRect:()=>p.getBoundingClientRect(),match:w}))}else n()})});return()=>{g()}},[d,t,a,h,n,v]);return null===h||null===d?null:x.createElement(I,{close:n,resolution:h,editor:d,anchorElementRef:l,options:b,menuRenderFn:r,shouldSplitNodeWithQuery:!0,onSelectOption:c})};exports.MenuOption=A;exports.PUNCTUATION="\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
24
- exports.SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND=Q;exports.getScrollParent=O;exports.useBasicTypeaheadTriggerMatch=function(b,{minLength:a=1,maxLength:c=75}){return x.useCallback(e=>{e=(new RegExp("(^|\\s|\\()(["+b+"]((?:[^"+(b+"\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;\\s]){0,")+c+"}))$")).exec(e);if(null!==e){let f=e[1],r=e[3];if(r.length>=a)return{leadOffset:e.index+f.length,matchingString:r,replaceableString:e[2]}}return null},[c,a,b])};
25
- exports.useDynamicPositioning=function(b,a,c,e){let [f]=k.useLexicalComposerContext();x.useEffect(()=>{if(null!=a&&null!=b){let r=f.getRootElement(),t=null!=r?O(r,!1):document.body,l=!1,d=P(a,t),h=function(){l||(window.requestAnimationFrame(function(){c();l=!1}),l=!0);const n=P(a,t);n!==d&&(d=n,null!=e&&e(n))},q=new ResizeObserver(c);window.addEventListener("resize",c);document.addEventListener("scroll",h,{capture:!0,passive:!0});q.observe(a);return()=>{q.unobserve(a);window.removeEventListener("resize",
26
- c);document.removeEventListener("scroll",h)}}},[a,f,e,c,b])}
7
+ 'use strict';var k=require("@lexical/react/LexicalComposerContext"),p=require("lexical"),y=require("react"),z=require("@lexical/utils"),A="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?y.useLayoutEffect:y.useEffect;class B{constructor(b){this.key=b;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(b){this.ref={current:b}}}
8
+ let C=b=>{const a=document.getElementById("typeahead-menu");if(a){var c=a.getBoundingClientRect();c.top+c.height>window.innerHeight&&a.scrollIntoView({block:"center"});0>c.top&&a.scrollIntoView({block:"center"});b.scrollIntoView({block:"nearest"})}};
9
+ function D(b){var a=p.$getSelection();if(!p.$isRangeSelection(a)||!a.isCollapsed())return null;var c=a.anchor;if("text"!==c.type)return null;a=c.getNode();if(!a.isSimpleText())return null;c=c.offset;let d=a.getTextContent().slice(0,c);var e=b.matchingString;b=b.replaceableString.length;for(let t=b;t<=e.length;t++)d.substr(-t)===e.substr(0,t)&&(b=t);b=c-b;if(0>b)return null;let r;0===b?[r]=a.splitText(c):[,r]=a.splitText(b,c);return r}
10
+ function G(b,a){let c=getComputedStyle(b),d="absolute"===c.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===c.position)return document.body;for(;b=b.parentElement;)if(c=getComputedStyle(b),(!d||"static"!==c.position)&&a.test(c.overflow+c.overflowY+c.overflowX))return b;return document.body}function H(b,a){b=b.getBoundingClientRect();a=a.getBoundingClientRect();return b.top>a.top&&b.top<a.bottom}
11
+ function I(b,a,c,d){let [e]=k.useLexicalComposerContext();y.useEffect(()=>{if(null!=a&&null!=b){let r=e.getRootElement(),t=null!=r?G(r,!1):document.body,n=!1,h=H(a,t),f=function(){n||(window.requestAnimationFrame(function(){c();n=!1}),n=!0);const u=H(a,t);u!==h&&(h=u,null!=d&&d(u))},m=new ResizeObserver(c);window.addEventListener("resize",c);document.addEventListener("scroll",f,{capture:!0,passive:!0});m.observe(a);return()=>{m.unobserve(a);window.removeEventListener("resize",c);document.removeEventListener("scroll",
12
+ f,!0)}}},[a,e,d,c,b])}let J=p.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
13
+ function K({close:b,editor:a,anchorElementRef:c,resolution:d,options:e,menuRenderFn:r,onSelectOption:t,shouldSplitNodeWithQuery:n=!1,commandPriority:h=p.COMMAND_PRIORITY_LOW}){let [f,m]=y.useState(null);y.useEffect(()=>{m(0)},[d.match&&d.match.matchingString]);let u=y.useCallback(g=>{a.update(()=>{const l=null!=d.match&&n?D(d.match):null;t(g,l,b,d.match?d.match.matchingString:"")})},[a,n,d.match,t,b]),q=y.useCallback(g=>{const l=a.getRootElement();null!==l&&(l.setAttribute("aria-activedescendant",
14
+ "typeahead-item-"+g),m(g))},[a]);y.useEffect(()=>()=>{let g=a.getRootElement();null!==g&&g.removeAttribute("aria-activedescendant")},[a]);A(()=>{null===e?m(null):null===f&&q(0)},[e,f,q]);y.useEffect(()=>z.mergeRegister(a.registerCommand(J,({option:g})=>g.ref&&null!=g.ref.current?(C(g.ref.current),!0):!1,h)),[a,q,h]);y.useEffect(()=>z.mergeRegister(a.registerCommand(p.KEY_ARROW_DOWN_COMMAND,g=>{if(null!==e&&e.length&&null!==f){let l=f!==e.length-1?f+1:0;q(l);let v=e[l];null!=v.ref&&v.ref.current&&
15
+ a.dispatchCommand(J,{index:l,option:v});g.preventDefault();g.stopImmediatePropagation()}return!0},h),a.registerCommand(p.KEY_ARROW_UP_COMMAND,g=>{if(null!==e&&e.length&&null!==f){var l=0!==f?f-1:e.length-1;q(l);l=e[l];null!=l.ref&&l.ref.current&&C(l.ref.current);g.preventDefault();g.stopImmediatePropagation()}return!0},h),a.registerCommand(p.KEY_ESCAPE_COMMAND,g=>{g.preventDefault();g.stopImmediatePropagation();b();return!0},h),a.registerCommand(p.KEY_TAB_COMMAND,g=>{if(null===e||null===f||null==
16
+ e[f])return!1;g.preventDefault();g.stopImmediatePropagation();u(e[f]);return!0},h),a.registerCommand(p.KEY_ENTER_COMMAND,g=>{if(null===e||null===f||null==e[f])return!1;null!==g&&(g.preventDefault(),g.stopImmediatePropagation());u(e[f]);return!0},h)),[u,b,a,e,f,q,h]);let w=y.useMemo(()=>({options:e,selectOptionAndCleanUp:u,selectedIndex:f,setHighlightedIndex:m}),[u,f,e]);return r(c,w,d.match?d.match.matchingString:"")}
17
+ function L(b,a,c){let [d]=k.useLexicalComposerContext(),e=y.useRef(document.createElement("div")),r=y.useCallback(()=>{e.current.style.top=e.current.style.bottom;const n=d.getRootElement(),h=e.current;var f=h.firstChild;if(null!==n&&null!==b){const {left:u,top:q,width:w,height:g}=b.getRect();h.style.top=`${q+window.pageYOffset+e.current.offsetHeight+3}px`;h.style.left=`${u+window.pageXOffset}px`;h.style.height=`${g}px`;h.style.width=`${w}px`;if(null!==f){f.style.top=`${q}`;var m=f.getBoundingClientRect();
18
+ f=m.height;m=m.width;const l=n.getBoundingClientRect();u+m>l.right&&(h.style.left=`${l.right-m+window.pageXOffset}px`);(q+f>window.innerHeight||q+f>l.bottom)&&q-l.top>f&&(h.style.top=`${q-f+window.pageYOffset-g}px`)}h.isConnected||(null!=c&&(h.className=c),h.setAttribute("aria-label","Typeahead menu"),h.setAttribute("id","typeahead-menu"),h.setAttribute("role","listbox"),h.style.display="block",h.style.position="absolute",document.body.append(h));e.current=h;n.setAttribute("aria-controls","typeahead-menu")}},
19
+ [d,b,c]);y.useEffect(()=>{let n=d.getRootElement();if(null!==b)return r(),()=>{null!==n&&n.removeAttribute("aria-controls");let h=e.current;null!==h&&h.isConnected&&h.remove()}},[d,r,b]);let t=y.useCallback(n=>{null!==b&&(n||a(null))},[b,a]);I(b,e.current,r,t);return e}function M(b,a,c){var d=c.getSelection();if(null===d||!d.isCollapsed)return!1;c=d.anchorNode;d=d.anchorOffset;if(null==c||null==d)return!1;try{a.setStart(c,b),a.setEnd(c,d)}catch(e){return!1}return!0}
20
+ function N(b){let a=null;b.getEditorState().read(()=>{var c=p.$getSelection();if(p.$isRangeSelection(c)){var d=c.anchor;"text"!==d.type?a=null:(c=d.getNode(),c.isSimpleText()?(d=d.offset,a=c.getTextContent().slice(0,d)):a=null)}});return a}function O(b,a){return 0!==a?!1:b.getEditorState().read(()=>{var c=p.$getSelection();return p.$isRangeSelection(c)?(c=c.anchor.getNode().getPreviousSibling(),p.$isTextNode(c)&&c.isTextEntity()):!1})}function P(b){y.startTransition?y.startTransition(b):b()}
21
+ let Q=p.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
22
+ exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,onOpen:d,onClose:e,menuRenderFn:r,triggerFn:t,anchorClassName:n,commandPriority:h=p.COMMAND_PRIORITY_LOW}){let [f]=k.useLexicalComposerContext(),[m,u]=y.useState(null);n=L(m,u,n);let q=y.useCallback(()=>{u(null);null!=e&&null!==m&&e()},[e,m]),w=y.useCallback(g=>{u(g);null!=d&&null===m&&d(g)},[d,m]);y.useEffect(()=>{let g=f.registerUpdateListener(()=>{f.getEditorState().read(()=>{const l=f._window||window,v=l.document.createRange(),
23
+ E=p.$getSelection(),F=N(f);if(p.$isRangeSelection(E)&&E.isCollapsed()&&null!==F&&null!==v){var x=t(F,f);a(x?x.matchingString:null);null===x||O(f,x.leadOffset)||null===M(x.leadOffset,v,l)?q():P(()=>w({getRect:()=>v.getBoundingClientRect(),match:x}))}else q()})});return()=>{g()}},[f,t,a,m,q,w]);return null===m||null===f?null:y.createElement(K,{close:q,resolution:m,editor:f,anchorElementRef:n,options:b,menuRenderFn:r,shouldSplitNodeWithQuery:!0,onSelectOption:c,commandPriority:h})};
24
+ exports.MenuOption=B;exports.PUNCTUATION="\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";exports.SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND=Q;exports.getScrollParent=function(b,a){let c=getComputedStyle(b),d="absolute"===c.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===c.position)return document.body;for(;b=b.parentElement;)if(c=getComputedStyle(b),(!d||"static"!==c.position)&&a.test(c.overflow+c.overflowY+c.overflowX))return b;return document.body};
25
+ exports.useBasicTypeaheadTriggerMatch=function(b,{minLength:a=1,maxLength:c=75}){return y.useCallback(d=>{d=(new RegExp("(^|\\s|\\()(["+b+"]((?:[^"+(b+"\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;\\s]){0,")+c+"}))$")).exec(d);if(null!==d){let e=d[1],r=d[3];if(r.length>=a)return{leadOffset:d.index+e.length,matchingString:r,replaceableString:d[2]}}return null},[c,a,b])};exports.useDynamicPositioning=I
package/package.json CHANGED
@@ -8,29 +8,29 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.12.2",
11
+ "version": "0.12.4",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.12.2",
14
- "@lexical/code": "0.12.2",
15
- "@lexical/dragon": "0.12.2",
16
- "@lexical/hashtag": "0.12.2",
17
- "@lexical/history": "0.12.2",
18
- "@lexical/link": "0.12.2",
19
- "@lexical/list": "0.12.2",
20
- "@lexical/mark": "0.12.2",
21
- "@lexical/markdown": "0.12.2",
22
- "@lexical/overflow": "0.12.2",
23
- "@lexical/plain-text": "0.12.2",
24
- "@lexical/rich-text": "0.12.2",
25
- "@lexical/selection": "0.12.2",
26
- "@lexical/table": "0.12.2",
27
- "@lexical/text": "0.12.2",
28
- "@lexical/utils": "0.12.2",
29
- "@lexical/yjs": "0.12.2",
13
+ "@lexical/clipboard": "0.12.4",
14
+ "@lexical/code": "0.12.4",
15
+ "@lexical/dragon": "0.12.4",
16
+ "@lexical/hashtag": "0.12.4",
17
+ "@lexical/history": "0.12.4",
18
+ "@lexical/link": "0.12.4",
19
+ "@lexical/list": "0.12.4",
20
+ "@lexical/mark": "0.12.4",
21
+ "@lexical/markdown": "0.12.4",
22
+ "@lexical/overflow": "0.12.4",
23
+ "@lexical/plain-text": "0.12.4",
24
+ "@lexical/rich-text": "0.12.4",
25
+ "@lexical/selection": "0.12.4",
26
+ "@lexical/table": "0.12.4",
27
+ "@lexical/text": "0.12.4",
28
+ "@lexical/utils": "0.12.4",
29
+ "@lexical/yjs": "0.12.4",
30
30
  "react-error-boundary": "^3.1.4"
31
31
  },
32
32
  "peerDependencies": {
33
- "lexical": "0.12.2",
33
+ "lexical": "0.12.4",
34
34
  "react": ">=17.x",
35
35
  "react-dom": ">=17.x"
36
36
  },
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import { LexicalCommand, LexicalEditor, TextNode } from 'lexical';
8
+ import { CommandListenerPriority, LexicalCommand, LexicalEditor, TextNode } from 'lexical';
9
9
  import { MutableRefObject, ReactPortal } from 'react';
10
10
  export type MenuTextMatch = {
11
11
  leadOffset: number;
@@ -35,7 +35,7 @@ export declare const SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND: LexicalCommand<{
35
35
  index: number;
36
36
  option: MenuOption;
37
37
  }>;
38
- export declare function LexicalMenu<TOption extends MenuOption>({ close, editor, anchorElementRef, resolution, options, menuRenderFn, onSelectOption, shouldSplitNodeWithQuery, }: {
38
+ export declare function LexicalMenu<TOption extends MenuOption>({ close, editor, anchorElementRef, resolution, options, menuRenderFn, onSelectOption, shouldSplitNodeWithQuery, commandPriority, }: {
39
39
  close: () => void;
40
40
  editor: LexicalEditor;
41
41
  anchorElementRef: MutableRefObject<HTMLElement>;
@@ -44,6 +44,7 @@ export declare function LexicalMenu<TOption extends MenuOption>({ close, editor,
44
44
  shouldSplitNodeWithQuery?: boolean;
45
45
  menuRenderFn: MenuRenderFn<TOption>;
46
46
  onSelectOption: (option: TOption, textNodeContainingQuery: TextNode | null, closeMenu: () => void, matchingString: string) => void;
47
+ commandPriority?: CommandListenerPriority;
47
48
  }): JSX.Element | null;
48
49
  export declare function useMenuAnchorRef(resolution: MenuResolution | null, setResolution: (r: MenuResolution | null) => void, className?: string): MutableRefObject<HTMLElement>;
49
50
  export type TriggerFn = (text: string, editor: LexicalEditor) => MenuTextMatch | null;
@@ -16,6 +16,7 @@ var react = require('react');
16
16
  * LICENSE file in the root directory of this source tree.
17
17
  *
18
18
  */
19
+
19
20
  const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
20
21
 
21
22
  /**
@@ -35,7 +36,6 @@ var useLayoutEffect = useLayoutEffectImpl;
35
36
  * LICENSE file in the root directory of this source tree.
36
37
  *
37
38
  */
38
-
39
39
  /**
40
40
  * Shortcut to Lexical subscriptions when values are used for render.
41
41
  */
@@ -50,12 +50,10 @@ function useLexicalSubscription(subscription) {
50
50
  subscribe
51
51
  } = initializedSubscription;
52
52
  const currentValue = initialValueFn();
53
-
54
53
  if (valueRef.current !== currentValue) {
55
54
  valueRef.current = currentValue;
56
55
  setValue(currentValue);
57
56
  }
58
-
59
57
  return subscribe(newValue => {
60
58
  valueRef.current = newValue;
61
59
  setValue(newValue);
@@ -71,7 +69,6 @@ function useLexicalSubscription(subscription) {
71
69
  * LICENSE file in the root directory of this source tree.
72
70
  *
73
71
  */
74
-
75
72
  function subscription(editor) {
76
73
  return {
77
74
  initialValueFn: () => editor.isEditable(),
@@ -80,7 +77,6 @@ function subscription(editor) {
80
77
  }
81
78
  };
82
79
  }
83
-
84
80
  function useLexicalEditable() {
85
81
  return useLexicalSubscription(subscription);
86
82
  }
@@ -16,6 +16,7 @@ var react = require('react');
16
16
  * LICENSE file in the root directory of this source tree.
17
17
  *
18
18
  */
19
+
19
20
  const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
20
21
 
21
22
  /**
@@ -17,19 +17,15 @@ var react = require('react');
17
17
  * LICENSE file in the root directory of this source tree.
18
18
  *
19
19
  */
20
-
21
20
  function isNodeSelected(editor, key) {
22
21
  return editor.getEditorState().read(() => {
23
22
  const node = lexical.$getNodeByKey(key);
24
-
25
23
  if (node === null) {
26
24
  return false;
27
25
  }
28
-
29
26
  return node.isSelected();
30
27
  });
31
28
  }
32
-
33
29
  function useLexicalNodeSelection(key) {
34
30
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
35
31
  const [isSelected, setIsSelected] = react.useState(() => isNodeSelected(editor, key));
@@ -48,12 +44,10 @@ function useLexicalNodeSelection(key) {
48
44
  const setSelected = react.useCallback(selected => {
49
45
  editor.update(() => {
50
46
  let selection = lexical.$getSelection();
51
-
52
47
  if (!lexical.$isNodeSelection(selection)) {
53
48
  selection = lexical.$createNodeSelection();
54
49
  lexical.$setSelection(selection);
55
50
  }
56
-
57
51
  if (selected) {
58
52
  selection.add(key);
59
53
  } else {
@@ -64,7 +58,6 @@ function useLexicalNodeSelection(key) {
64
58
  const clearSelected = react.useCallback(() => {
65
59
  editor.update(() => {
66
60
  const selection = lexical.$getSelection();
67
-
68
61
  if (lexical.$isNodeSelection(selection)) {
69
62
  selection.clear();
70
63
  }
@@ -16,6 +16,7 @@ var react = require('react');
16
16
  * LICENSE file in the root directory of this source tree.
17
17
  *
18
18
  */
19
+
19
20
  const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
20
21
 
21
22
  /**
@@ -35,7 +36,6 @@ var useLayoutEffect = useLayoutEffectImpl;
35
36
  * LICENSE file in the root directory of this source tree.
36
37
  *
37
38
  */
38
-
39
39
  /**
40
40
  * Shortcut to Lexical subscriptions when values are used for render.
41
41
  */
@@ -50,12 +50,10 @@ function useLexicalSubscription(subscription) {
50
50
  subscribe
51
51
  } = initializedSubscription;
52
52
  const currentValue = initialValueFn();
53
-
54
53
  if (valueRef.current !== currentValue) {
55
54
  valueRef.current = currentValue;
56
55
  setValue(currentValue);
57
56
  }
58
-
59
57
  return subscribe(newValue => {
60
58
  valueRef.current = newValue;
61
59
  setValue(newValue);