@lexical/react 0.12.6 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,11 @@ function AutoFocusPlugin({
21
21
  }) {
22
22
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
23
23
  react.useEffect(() => {
24
+ editor.registerUpdateListener(({
25
+ editorState
26
+ }) => {
27
+ console.info(editorState.toJSON());
28
+ });
24
29
  editor.focus(() => {
25
30
  // If we try and move selection to the same point with setBaseAndExtent, it won't
26
31
  // trigger a re-focus on the element. So in the case this occurs, we'll need to correct it.
@@ -4,4 +4,4 @@
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/LexicalComposerContext"),f=require("react");exports.AutoFocusPlugin=function({defaultSelection:c}){let [a]=e.useLexicalComposerContext();f.useEffect(()=>{a.focus(()=>{let d=document.activeElement,b=a.getRootElement();null===b||null!==d&&b.contains(d)||b.focus({preventScroll:!0})},{defaultSelection:c})},[c,a]);return null}
7
+ 'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("react");exports.AutoFocusPlugin=function({defaultSelection:d}){let [a]=e.useLexicalComposerContext();f.useEffect(()=>{a.registerUpdateListener(({editorState:b})=>{console.info(b.toJSON())});a.focus(()=>{let b=document.activeElement,c=a.getRootElement();null===c||null!==b&&c.contains(b)||c.focus({preventScroll:!0})},{defaultSelection:d})},[d,a]);return null}
@@ -164,14 +164,15 @@ function createAutoLinkNode(nodes, startIndex, endIndex, match) {
164
164
  }
165
165
  function handleLinkCreation(nodes, matchers, onChange) {
166
166
  let currentNodes = [...nodes];
167
- let text = currentNodes.map(node => node.getTextContent()).join('');
167
+ const initialText = currentNodes.map(node => node.getTextContent()).join('');
168
+ let text = initialText;
168
169
  let match;
169
170
  let invalidMatchEnd = 0;
170
171
  while ((match = findFirstMatch(text, matchers)) && match !== null) {
171
172
  const matchStart = match.index;
172
173
  const matchLength = match.length;
173
174
  const matchEnd = matchStart + matchLength;
174
- const isValid = isContentAroundIsValid(invalidMatchEnd + matchStart, invalidMatchEnd + matchEnd, text, currentNodes);
175
+ const isValid = isContentAroundIsValid(invalidMatchEnd + matchStart, invalidMatchEnd + matchEnd, initialText, currentNodes);
175
176
  if (isValid) {
176
177
  const [matchingOffset,, matchingNodes, unmodifiedAfterNodes] = extractMatchingNodes(currentNodes, invalidMatchEnd + matchStart, invalidMatchEnd + matchEnd);
177
178
  const actualMatchStart = invalidMatchEnd + matchStart - matchingOffset;
@@ -4,14 +4,14 @@
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"),n=require("@lexical/react/LexicalComposerContext"),p=require("@lexical/utils"),r=require("lexical"),t=require("react");function u(a){let c=new URLSearchParams;c.append("code",a);for(let b=1;b<arguments.length;b++)c.append("v",arguments[b]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${c} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- function v(a,c){for(let b=0;b<c.length;b++){let d=c[b](a);if(d)return d}return null}let w=/[.,;\s]/;function x(a){a=a.getPreviousSibling();r.$isElementNode(a)&&(a=a.getLastDescendant());var c;!(c=null===a||r.$isLineBreakNode(a))&&(c=r.$isTextNode(a))&&(a=a.getTextContent(),c=w.test(a[a.length-1]));return c}function y(a){a=a.getNextSibling();r.$isElementNode(a)&&(a=a.getFirstDescendant());return null===a||r.$isLineBreakNode(a)||r.$isTextNode(a)&&w.test(a.getTextContent()[0])}
9
- function z(a,c,b,d){return(0<a?w.test(b[a-1]):x(d[0]))?c<b.length?w.test(b[c]):y(d[d.length-1]):!1}function A(a,c,b){let d=[],f=[],e=[],g=0,h=0;for(a=[...a];0<a.length;){let l=a[0],m=l.getTextContent().length,q=h;h+m<=c?(d.push(l),g+=m):q>=b?e.push(l):f.push(l);h+=m;a.shift()}return[g,d,f,e]}
10
- function B(a,c,b,d){let f=k.$createAutoLinkNode(d.url,d.attributes);if(1===a.length){var e=a[0];0===c?[h,e]=e.splitText(b):[,h,e]=e.splitText(c,b);var g=r.$createTextNode(d.text);g.setFormat(h.getFormat());g.setDetail(h.getDetail());f.append(g);h.replace(f);return e}if(1<a.length){d=a[0];var h=d.getTextContent().length;0===c?e=d:[,e]=d.splitText(c);c=[];for(d=1;d<a.length;d++){let l=a[d],m=l.getTextContent().length,q=h,E=h+m;if(q<b)if(E<=b)c.push(l);else{let [F,G]=l.splitText(b-q);c.push(F);g=G}h+=
11
- m}a=(b=r.$getSelection())?b.getNodes().find(r.$isTextNode):void 0;h=r.$createTextNode(e.getTextContent());h.setFormat(e.getFormat());h.setDetail(e.getDetail());f.append(h,...c);a&&a===e&&(r.$isRangeSelection(b)?h.select(b.anchor.offset,b.focus.offset):r.$isNodeSelection(b)&&h.select(0,h.getTextContent().length));e.replace(f);return g}}
12
- function C(a,c,b){var d=[...a];a=d.map(g=>g.getTextContent()).join("");let f,e=0;for(;(f=v(a,c))&&null!==f;){let g=f.index,h=g+f.length;if(z(e+g,e+h,a,d)){let [l,,m,q]=A(d,e+g,e+h);d=(d=B(m,e+g-l,e+h-l,f))?[d,...q]:q;b(f.url,null);e=0}else e+=h;a=a.substring(h)}}
13
- function D(a,c,b){var d=a.getChildren();let f=d.length;for(let e=0;e<f;e++){let g=d[e];if(!r.$isTextNode(g)||!g.isSimpleText()){H(a);b(null,a.getURL());return}}d=a.getTextContent();c=v(d,c);null===c||c.text!==d?(H(a),b(null,a.getURL())):x(a)&&y(a)?(d=a.getURL(),d!==c.url&&(a.setURL(c.url),b(c.url,d)),c.attributes&&(d=a.getRel(),d!==c.attributes.rel&&(a.setRel(c.attributes.rel||null),b(c.attributes.rel||null,d)),d=a.getTarget(),d!==c.attributes.target&&(a.setTarget(c.attributes.target||null),b(c.attributes.target||
7
+ 'use strict';var k=require("@lexical/link"),n=require("@lexical/react/LexicalComposerContext"),p=require("@lexical/utils"),t=require("lexical"),u=require("react");function v(a){let c=new URLSearchParams;c.append("code",a);for(let b=1;b<arguments.length;b++)c.append("v",arguments[b]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${c} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
+ function w(a,c){for(let b=0;b<c.length;b++){let d=c[b](a);if(d)return d}return null}let x=/[.,;\s]/;function y(a){a=a.getPreviousSibling();t.$isElementNode(a)&&(a=a.getLastDescendant());var c;!(c=null===a||t.$isLineBreakNode(a))&&(c=t.$isTextNode(a))&&(a=a.getTextContent(),c=x.test(a[a.length-1]));return c}function z(a){a=a.getNextSibling();t.$isElementNode(a)&&(a=a.getFirstDescendant());return null===a||t.$isLineBreakNode(a)||t.$isTextNode(a)&&x.test(a.getTextContent()[0])}
9
+ function A(a,c,b,d){return(0<a?x.test(b[a-1]):y(d[0]))?c<b.length?x.test(b[c]):z(d[d.length-1]):!1}function B(a,c,b){let d=[],h=[],e=[],f=0,g=0;for(a=[...a];0<a.length;){let l=a[0],m=l.getTextContent().length,q=g;g+m<=c?(d.push(l),f+=m):q>=b?e.push(l):h.push(l);g+=m;a.shift()}return[f,d,h,e]}
10
+ function C(a,c,b,d){let h=k.$createAutoLinkNode(d.url,d.attributes);if(1===a.length){var e=a[0];0===c?[g,e]=e.splitText(b):[,g,e]=e.splitText(c,b);var f=t.$createTextNode(d.text);f.setFormat(g.getFormat());f.setDetail(g.getDetail());h.append(f);g.replace(h);return e}if(1<a.length){d=a[0];var g=d.getTextContent().length;0===c?e=d:[,e]=d.splitText(c);c=[];for(d=1;d<a.length;d++){let l=a[d],m=l.getTextContent().length,q=g,r=g+m;if(q<b)if(r<=b)c.push(l);else{let [F,G]=l.splitText(b-q);c.push(F);f=G}g+=
11
+ m}a=(b=t.$getSelection())?b.getNodes().find(t.$isTextNode):void 0;g=t.$createTextNode(e.getTextContent());g.setFormat(e.getFormat());g.setDetail(e.getDetail());h.append(g,...c);a&&a===e&&(t.$isRangeSelection(b)?g.select(b.anchor.offset,b.focus.offset):t.$isNodeSelection(b)&&g.select(0,g.getTextContent().length));e.replace(h);return f}}
12
+ function D(a,c,b){var d=[...a];let h=a=d.map(g=>g.getTextContent()).join(""),e,f=0;for(;(e=w(h,c))&&null!==e;){let g=e.index,l=g+e.length;if(A(f+g,f+l,a,d)){let [m,,q,r]=B(d,f+g,f+l);d=(d=C(q,f+g-m,f+l-m,e))?[d,...r]:r;b(e.url,null);f=0}else f+=l;h=h.substring(l)}}
13
+ function E(a,c,b){var d=a.getChildren();let h=d.length;for(let e=0;e<h;e++){let f=d[e];if(!t.$isTextNode(f)||!f.isSimpleText()){H(a);b(null,a.getURL());return}}d=a.getTextContent();c=w(d,c);null===c||c.text!==d?(H(a),b(null,a.getURL())):y(a)&&z(a)?(d=a.getURL(),d!==c.url&&(a.setURL(c.url),b(c.url,d)),c.attributes&&(d=a.getRel(),d!==c.attributes.rel&&(a.setRel(c.attributes.rel||null),b(c.attributes.rel||null,d)),d=a.getTarget(),d!==c.attributes.target&&(a.setTarget(c.attributes.target||null),b(c.attributes.target||
14
14
  null,d)))):(H(a),b(null,a.getURL()))}function H(a){let c=a.getChildren();var b=c.length;for(--b;0<=b;b--)a.insertAfter(c[b]);a.remove();return c.map(d=>d.getLatest())}
15
- function I(a,c,b){t.useEffect(()=>{a.hasNodes([k.AutoLinkNode])||u(77);let d=(f,e)=>{b&&b(f,e)};return p.mergeRegister(a.registerNodeTransform(r.TextNode,f=>{var e=f.getParentOrThrow(),g=f.getPreviousSibling();if(k.$isAutoLinkNode(e))D(e,c,d);else if(!k.$isLinkNode(e)){if(f.isSimpleText()&&(w.test(f.getTextContent()[0])||!k.$isAutoLinkNode(g))){e=[f];for(g=f.getNextSibling();null!==g&&r.$isTextNode(g)&&g.isSimpleText();){e.push(g);if(/[\s]/.test(g.getTextContent()))break;g=g.getNextSibling()}C(e,
16
- c,d)}let h=f.getPreviousSibling();e=f.getNextSibling();g=f.getTextContent();k.$isAutoLinkNode(h)&&!w.test(g[0])&&(h.append(f),D(h,c,d),f=h.getURL(),b&&b(null,f));k.$isAutoLinkNode(e)&&!w.test(g[g.length-1])&&(H(e),D(e,c,d),f=e.getURL(),b&&b(null,f))}}))},[a,c,b])}exports.AutoLinkPlugin=function({matchers:a,onChange:c}){let [b]=n.useLexicalComposerContext();I(b,a,c);return null};
15
+ function I(a,c,b){u.useEffect(()=>{a.hasNodes([k.AutoLinkNode])||v(77);let d=(h,e)=>{b&&b(h,e)};return p.mergeRegister(a.registerNodeTransform(t.TextNode,h=>{var e=h.getParentOrThrow(),f=h.getPreviousSibling();if(k.$isAutoLinkNode(e))E(e,c,d);else if(!k.$isLinkNode(e)){if(h.isSimpleText()&&(x.test(h.getTextContent()[0])||!k.$isAutoLinkNode(f))){e=[h];for(f=h.getNextSibling();null!==f&&t.$isTextNode(f)&&f.isSimpleText();){e.push(f);if(/[\s]/.test(f.getTextContent()))break;f=f.getNextSibling()}D(e,
16
+ c,d)}let g=h.getPreviousSibling();e=h.getNextSibling();f=h.getTextContent();k.$isAutoLinkNode(g)&&!x.test(f[0])&&(g.append(h),E(g,c,d),h=g.getURL(),b&&b(null,h));k.$isAutoLinkNode(e)&&!x.test(f[f.length-1])&&(H(e),E(e,c,d),h=e.getURL(),b&&b(null,h))}}))},[a,c,b])}exports.AutoLinkPlugin=function({matchers:a,onChange:c}){let [b]=n.useLexicalComposerContext();I(b,a,c);return null};
17
17
  exports.createLinkMatcherWithRegExp=function(a,c=b=>b){return b=>{b=a.exec(b);return null===b?null:{index:b.index,length:b[0].length,text:b[0],url:c(b[0])}}}
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- /// <reference types="react" />
9
8
  import { EditorState, EditorThemeClasses, HTMLConfig, Klass, LexicalEditor, LexicalNode, LexicalNodeReplacement } from 'lexical';
9
+ import * as React from 'react';
10
10
  export type InitialEditorStateType = null | string | EditorState | ((editor: LexicalEditor) => void);
11
11
  export type InitialConfigType = Readonly<{
12
12
  editor__DEPRECATED?: LexicalEditor | null;
@@ -18,9 +18,8 @@ export type InitialConfigType = Readonly<{
18
18
  editorState?: InitialEditorStateType;
19
19
  html?: HTMLConfig;
20
20
  }>;
21
- type Props = {
22
- children: JSX.Element | string | (JSX.Element | string)[];
21
+ type Props = React.PropsWithChildren<{
23
22
  initialConfig: InitialConfigType;
24
- };
23
+ }>;
25
24
  export declare function LexicalComposer({ initialConfig, children }: Props): JSX.Element;
26
25
  export {};
@@ -25,6 +25,7 @@ export type LexicalContextMenuPluginProps<TOption extends MenuOption> = {
25
25
  menuRenderFn: ContextMenuRenderFn<TOption>;
26
26
  anchorClassName?: string;
27
27
  commandPriority?: CommandListenerPriority;
28
+ parent?: HTMLElement;
28
29
  };
29
- export declare function LexicalContextMenuPlugin<TOption extends MenuOption>({ options, onClose, onOpen, onSelectOption, menuRenderFn: contextMenuRenderFn, anchorClassName, commandPriority, }: LexicalContextMenuPluginProps<TOption>): JSX.Element | null;
30
+ export declare function LexicalContextMenuPlugin<TOption extends MenuOption>({ options, onClose, onOpen, onSelectOption, menuRenderFn: contextMenuRenderFn, anchorClassName, commandPriority, parent, }: LexicalContextMenuPluginProps<TOption>): JSX.Element | null;
30
31
  export { MenuOption, MenuRenderFn, MenuResolution };
@@ -305,7 +305,7 @@ function LexicalMenu({
305
305
  }), [selectOptionAndCleanUp, selectedIndex, options]);
306
306
  return menuRenderFn(anchorElementRef, listItemProps, resolution.match ? resolution.match.matchingString : '');
307
307
  }
308
- function useMenuAnchorRef(resolution, setResolution, className) {
308
+ function useMenuAnchorRef(resolution, setResolution, className, parent = document.body) {
309
309
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
310
310
  const anchorElementRef = React.useRef(document.createElement('div'));
311
311
  const positionMenu = React.useCallback(() => {
@@ -347,12 +347,12 @@ function useMenuAnchorRef(resolution, setResolution, className) {
347
347
  containerDiv.setAttribute('role', 'listbox');
348
348
  containerDiv.style.display = 'block';
349
349
  containerDiv.style.position = 'absolute';
350
- document.body.append(containerDiv);
350
+ parent.append(containerDiv);
351
351
  }
352
352
  anchorElementRef.current = containerDiv;
353
353
  rootElement.setAttribute('aria-controls', 'typeahead-menu');
354
354
  }
355
- }, [editor, resolution, className]);
355
+ }, [editor, resolution, className, parent]);
356
356
  React.useEffect(() => {
357
357
  const rootElement = editor.getRootElement();
358
358
  if (resolution !== null) {
@@ -394,12 +394,13 @@ function LexicalContextMenuPlugin({
394
394
  onSelectOption,
395
395
  menuRenderFn: contextMenuRenderFn,
396
396
  anchorClassName,
397
- commandPriority = lexical.COMMAND_PRIORITY_LOW
397
+ commandPriority = lexical.COMMAND_PRIORITY_LOW,
398
+ parent
398
399
  }) {
399
400
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
400
401
  const [resolution, setResolution] = React.useState(null);
401
402
  const menuRef = React.useRef(null);
402
- const anchorElementRef = useMenuAnchorRef(resolution, setResolution, anchorClassName);
403
+ const anchorElementRef = useMenuAnchorRef(resolution, setResolution, anchorClassName, parent);
403
404
  const closeNodeMenu = React.useCallback(() => {
404
405
  setResolution(null);
405
406
  if (onClose != null && resolution !== null) {
@@ -4,19 +4,19 @@
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"),u=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 d=a.getBoundingClientRect();d.top+d.height>window.innerHeight&&a.scrollIntoView({block:"center"});0>d.top&&a.scrollIntoView({block:"center"});b.scrollIntoView({block:"nearest"})}};
9
- function C(b){var a=u.$getSelection();if(!u.$isRangeSelection(a)||!a.isCollapsed())return null;var d=a.anchor;if("text"!==d.type)return null;a=d.getNode();if(!a.isSimpleText())return null;d=d.offset;let l=a.getTextContent().slice(0,d);var e=b.matchingString;b=b.replaceableString.length;for(let t=b;t<=e.length;t++)l.substr(-t)===e.substr(0,t)&&(b=t);b=d-b;if(0>b)return null;let p;0===b?[p]=a.splitText(d):[,p]=a.splitText(b,d);return p}
10
- function D(b,a){let d=getComputedStyle(b),l="absolute"===d.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===d.position)return document.body;for(;b=b.parentElement;)if(d=getComputedStyle(b),(!l||"static"!==d.position)&&a.test(d.overflow+d.overflowY+d.overflowX))return b;return document.body}function E(b,a){b=b.getBoundingClientRect();a=a.getBoundingClientRect();return b.top>a.top&&b.top<a.bottom}
11
- function F(b,a,d,l){let [e]=k.useLexicalComposerContext();x.useEffect(()=>{if(null!=a&&null!=b){let p=e.getRootElement(),t=null!=p?D(p,!1):document.body,m=!1,c=E(a,t),h=function(){m||(window.requestAnimationFrame(function(){d();m=!1}),m=!0);const q=E(a,t);q!==c&&(c=q,null!=l&&l(q))},n=new ResizeObserver(d);window.addEventListener("resize",d);document.addEventListener("scroll",h,{capture:!0,passive:!0});n.observe(a);return()=>{n.unobserve(a);window.removeEventListener("resize",d);document.removeEventListener("scroll",
12
- h,!0)}}},[a,e,l,d,b])}let G=u.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
13
- function H({close:b,editor:a,anchorElementRef:d,resolution:l,options:e,menuRenderFn:p,onSelectOption:t,shouldSplitNodeWithQuery:m=!1,commandPriority:c=u.COMMAND_PRIORITY_LOW}){let [h,n]=x.useState(null);x.useEffect(()=>{n(0)},[l.match&&l.match.matchingString]);let q=x.useCallback(g=>{a.update(()=>{const f=null!=l.match&&m?C(l.match):null;t(g,f,b,l.match?l.match.matchingString:"")})},[a,m,l.match,t,b]),r=x.useCallback(g=>{const f=a.getRootElement();null!==f&&(f.setAttribute("aria-activedescendant",
14
- "typeahead-item-"+g),n(g))},[a]);x.useEffect(()=>()=>{let g=a.getRootElement();null!==g&&g.removeAttribute("aria-activedescendant")},[a]);z(()=>{null===e?n(null):null===h&&r(0)},[e,h,r]);x.useEffect(()=>y.mergeRegister(a.registerCommand(G,({option:g})=>g.ref&&null!=g.ref.current?(B(g.ref.current),!0):!1,c)),[a,r,c]);x.useEffect(()=>y.mergeRegister(a.registerCommand(u.KEY_ARROW_DOWN_COMMAND,g=>{if(null!==e&&e.length&&null!==h){let f=h!==e.length-1?h+1:0;r(f);let w=e[f];null!=w.ref&&w.ref.current&&
15
- a.dispatchCommand(G,{index:f,option:w});g.preventDefault();g.stopImmediatePropagation()}return!0},c),a.registerCommand(u.KEY_ARROW_UP_COMMAND,g=>{if(null!==e&&e.length&&null!==h){var f=0!==h?h-1:e.length-1;r(f);f=e[f];null!=f.ref&&f.ref.current&&B(f.ref.current);g.preventDefault();g.stopImmediatePropagation()}return!0},c),a.registerCommand(u.KEY_ESCAPE_COMMAND,g=>{g.preventDefault();g.stopImmediatePropagation();b();return!0},c),a.registerCommand(u.KEY_TAB_COMMAND,g=>{if(null===e||null===h||null==
16
- e[h])return!1;g.preventDefault();g.stopImmediatePropagation();q(e[h]);return!0},c),a.registerCommand(u.KEY_ENTER_COMMAND,g=>{if(null===e||null===h||null==e[h])return!1;null!==g&&(g.preventDefault(),g.stopImmediatePropagation());q(e[h]);return!0},c)),[q,b,a,e,h,r,c]);let v=x.useMemo(()=>({options:e,selectOptionAndCleanUp:q,selectedIndex:h,setHighlightedIndex:n}),[q,h,e]);return p(d,v,l.match?l.match.matchingString:"")}
17
- function I(b,a,d){let [l]=k.useLexicalComposerContext(),e=x.useRef(document.createElement("div")),p=x.useCallback(()=>{e.current.style.top=e.current.style.bottom;const m=l.getRootElement(),c=e.current;var h=c.firstChild;if(null!==m&&null!==b){const {left:q,top:r,width:v,height:g}=b.getRect();c.style.top=`${r+window.pageYOffset+e.current.offsetHeight+3}px`;c.style.left=`${q+window.pageXOffset}px`;c.style.height=`${g}px`;c.style.width=`${v}px`;if(null!==h){h.style.top=`${r}`;var n=h.getBoundingClientRect();
18
- h=n.height;n=n.width;const f=m.getBoundingClientRect();q+n>f.right&&(c.style.left=`${f.right-n+window.pageXOffset}px`);(r+h>window.innerHeight||r+h>f.bottom)&&r-f.top>h&&(c.style.top=`${r-h+window.pageYOffset-g}px`)}c.isConnected||(null!=d&&(c.className=d),c.setAttribute("aria-label","Typeahead menu"),c.setAttribute("id","typeahead-menu"),c.setAttribute("role","listbox"),c.style.display="block",c.style.position="absolute",document.body.append(c));e.current=c;m.setAttribute("aria-controls","typeahead-menu")}},
19
- [l,b,d]);x.useEffect(()=>{let m=l.getRootElement();if(null!==b)return p(),()=>{null!==m&&m.removeAttribute("aria-controls");let c=e.current;null!==c&&c.isConnected&&c.remove()}},[l,p,b]);let t=x.useCallback(m=>{null!==b&&(m||a(null))},[b,a]);F(b,e.current,p,t);return e}
20
- exports.LexicalContextMenuPlugin=function({options:b,onClose:a,onOpen:d,onSelectOption:l,menuRenderFn:e,anchorClassName:p,commandPriority:t=u.COMMAND_PRIORITY_LOW}){let [m]=k.useLexicalComposerContext(),[c,h]=x.useState(null),n=x.useRef(null);p=I(c,h,p);let q=x.useCallback(()=>{h(null);null!=a&&null!==c&&a()},[a,c]),r=x.useCallback(f=>{h(f);null!=d&&null===c&&d(f)},[d,c]),v=x.useCallback(f=>{f.preventDefault();r({getRect:()=>new DOMRect(f.clientX,f.clientY,1,1)})},[r]),g=x.useCallback(f=>{null===
21
- c||null==n.current||null==f.target||n.current.contains(f.target)||q()},[q,c]);x.useEffect(()=>{let f=m.getRootElement();if(f)return f.addEventListener("contextmenu",v),()=>f.removeEventListener("contextmenu",v)},[m,v]);x.useEffect(()=>{document.addEventListener("click",g);return()=>document.removeEventListener("click",g)},[m,g]);return null===c||null===m?null:x.createElement(H,{close:q,resolution:c,editor:m,anchorElementRef:p,options:b,menuRenderFn:(f,w)=>e(f,w,{setMenuRef:J=>{n.current=J}}),onSelectOption:l,
22
- commandPriority:t})};exports.MenuOption=A
7
+ 'use strict';var h=require("@lexical/react/LexicalComposerContext"),v=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(c){this.key=c;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(c){this.ref={current:c}}}
8
+ let B=c=>{const a=document.getElementById("typeahead-menu");if(a){var d=a.getBoundingClientRect();d.top+d.height>window.innerHeight&&a.scrollIntoView({block:"center"});0>d.top&&a.scrollIntoView({block:"center"});c.scrollIntoView({block:"nearest"})}};
9
+ function C(c){var a=v.$getSelection();if(!v.$isRangeSelection(a)||!a.isCollapsed())return null;var d=a.anchor;if("text"!==d.type)return null;a=d.getNode();if(!a.isSimpleText())return null;d=d.offset;let l=a.getTextContent().slice(0,d);var f=c.matchingString;c=c.replaceableString.length;for(let r=c;r<=f.length;r++)l.substr(-r)===f.substr(0,r)&&(c=r);c=d-c;if(0>c)return null;let n;0===c?[n]=a.splitText(d):[,n]=a.splitText(c,d);return n}
10
+ function D(c,a){let d=getComputedStyle(c),l="absolute"===d.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===d.position)return document.body;for(;c=c.parentElement;)if(d=getComputedStyle(c),(!l||"static"!==d.position)&&a.test(d.overflow+d.overflowY+d.overflowX))return c;return document.body}function E(c,a){c=c.getBoundingClientRect();a=a.getBoundingClientRect();return c.top>a.top&&c.top<a.bottom}
11
+ function F(c,a,d,l){let [f]=h.useLexicalComposerContext();x.useEffect(()=>{if(null!=a&&null!=c){let n=f.getRootElement(),r=null!=n?D(n,!1):document.body,w=!1,g=E(a,r),b=function(){w||(window.requestAnimationFrame(function(){d();w=!1}),w=!0);const q=E(a,r);q!==g&&(g=q,null!=l&&l(q))},p=new ResizeObserver(d);window.addEventListener("resize",d);document.addEventListener("scroll",b,{capture:!0,passive:!0});p.observe(a);return()=>{p.unobserve(a);window.removeEventListener("resize",d);document.removeEventListener("scroll",
12
+ b,!0)}}},[a,f,l,d,c])}let G=v.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
13
+ function H({close:c,editor:a,anchorElementRef:d,resolution:l,options:f,menuRenderFn:n,onSelectOption:r,shouldSplitNodeWithQuery:w=!1,commandPriority:g=v.COMMAND_PRIORITY_LOW}){let [b,p]=x.useState(null);x.useEffect(()=>{p(0)},[l.match&&l.match.matchingString]);let q=x.useCallback(e=>{a.update(()=>{const m=null!=l.match&&w?C(l.match):null;r(e,m,c,l.match?l.match.matchingString:"")})},[a,w,l.match,r,c]),t=x.useCallback(e=>{const m=a.getRootElement();null!==m&&(m.setAttribute("aria-activedescendant",
14
+ "typeahead-item-"+e),p(e))},[a]);x.useEffect(()=>()=>{let e=a.getRootElement();null!==e&&e.removeAttribute("aria-activedescendant")},[a]);z(()=>{null===f?p(null):null===b&&t(0)},[f,b,t]);x.useEffect(()=>y.mergeRegister(a.registerCommand(G,({option:e})=>e.ref&&null!=e.ref.current?(B(e.ref.current),!0):!1,g)),[a,t,g]);x.useEffect(()=>y.mergeRegister(a.registerCommand(v.KEY_ARROW_DOWN_COMMAND,e=>{if(null!==f&&f.length&&null!==b){let m=b!==f.length-1?b+1:0;t(m);let k=f[m];null!=k.ref&&k.ref.current&&
15
+ a.dispatchCommand(G,{index:m,option:k});e.preventDefault();e.stopImmediatePropagation()}return!0},g),a.registerCommand(v.KEY_ARROW_UP_COMMAND,e=>{if(null!==f&&f.length&&null!==b){var m=0!==b?b-1:f.length-1;t(m);m=f[m];null!=m.ref&&m.ref.current&&B(m.ref.current);e.preventDefault();e.stopImmediatePropagation()}return!0},g),a.registerCommand(v.KEY_ESCAPE_COMMAND,e=>{e.preventDefault();e.stopImmediatePropagation();c();return!0},g),a.registerCommand(v.KEY_TAB_COMMAND,e=>{if(null===f||null===b||null==
16
+ f[b])return!1;e.preventDefault();e.stopImmediatePropagation();q(f[b]);return!0},g),a.registerCommand(v.KEY_ENTER_COMMAND,e=>{if(null===f||null===b||null==f[b])return!1;null!==e&&(e.preventDefault(),e.stopImmediatePropagation());q(f[b]);return!0},g)),[q,c,a,f,b,t,g]);let u=x.useMemo(()=>({options:f,selectOptionAndCleanUp:q,selectedIndex:b,setHighlightedIndex:p}),[q,b,f]);return n(d,u,l.match?l.match.matchingString:"")}
17
+ function I(c,a,d,l=document.body){let [f]=h.useLexicalComposerContext(),n=x.useRef(document.createElement("div")),r=x.useCallback(()=>{n.current.style.top=n.current.style.bottom;const g=f.getRootElement(),b=n.current;var p=b.firstChild;if(null!==g&&null!==c){const {left:t,top:u,width:e,height:m}=c.getRect();b.style.top=`${u+window.pageYOffset+n.current.offsetHeight+3}px`;b.style.left=`${t+window.pageXOffset}px`;b.style.height=`${m}px`;b.style.width=`${e}px`;if(null!==p){p.style.top=`${u}`;var q=p.getBoundingClientRect();
18
+ p=q.height;q=q.width;const k=g.getBoundingClientRect();t+q>k.right&&(b.style.left=`${k.right-q+window.pageXOffset}px`);(u+p>window.innerHeight||u+p>k.bottom)&&u-k.top>p&&(b.style.top=`${u-p+window.pageYOffset-m}px`)}b.isConnected||(null!=d&&(b.className=d),b.setAttribute("aria-label","Typeahead menu"),b.setAttribute("id","typeahead-menu"),b.setAttribute("role","listbox"),b.style.display="block",b.style.position="absolute",l.append(b));n.current=b;g.setAttribute("aria-controls","typeahead-menu")}},
19
+ [f,c,d,l]);x.useEffect(()=>{let g=f.getRootElement();if(null!==c)return r(),()=>{null!==g&&g.removeAttribute("aria-controls");let b=n.current;null!==b&&b.isConnected&&b.remove()}},[f,r,c]);let w=x.useCallback(g=>{null!==c&&(g||a(null))},[c,a]);F(c,n.current,r,w);return n}
20
+ exports.LexicalContextMenuPlugin=function({options:c,onClose:a,onOpen:d,onSelectOption:l,menuRenderFn:f,anchorClassName:n,commandPriority:r=v.COMMAND_PRIORITY_LOW,parent:w}){let [g]=h.useLexicalComposerContext(),[b,p]=x.useState(null),q=x.useRef(null);n=I(b,p,n,w);let t=x.useCallback(()=>{p(null);null!=a&&null!==b&&a()},[a,b]),u=x.useCallback(k=>{p(k);null!=d&&null===b&&d(k)},[d,b]),e=x.useCallback(k=>{k.preventDefault();u({getRect:()=>new DOMRect(k.clientX,k.clientY,1,1)})},[u]),m=x.useCallback(k=>
21
+ {null===b||null==q.current||null==k.target||q.current.contains(k.target)||t()},[t,b]);x.useEffect(()=>{let k=g.getRootElement();if(k)return k.addEventListener("contextmenu",e),()=>k.removeEventListener("contextmenu",e)},[g,e]);x.useEffect(()=>{document.addEventListener("click",m);return()=>document.removeEventListener("click",m)},[g,m]);return null===b||null===g?null:x.createElement(H,{close:t,resolution:b,editor:g,anchorElementRef:n,options:c,menuRenderFn:(k,J)=>f(k,J,{setMenuRef:K=>{q.current=K}}),
22
+ onSelectOption:l,commandPriority:r})};exports.MenuOption=A
@@ -25,4 +25,4 @@ declare export class DecoratorBlockNode<T> extends DecoratorNode<T> {
25
25
 
26
26
  declare export function $isDecoratorBlockNode(
27
27
  node: ?LexicalNode,
28
- ): boolean %checks(node instanceof DecoratorBlockNode);
28
+ ): node is DecoratorBlockNode<{...}>;
@@ -23,6 +23,6 @@ declare export class HorizontalRuleNode extends DecoratorNode<React$Node> {
23
23
  declare export function $createHorizontalRuleNode(): HorizontalRuleNode;
24
24
  declare export function $isHorizontalRuleNode(
25
25
  node: ?LexicalNode,
26
- ): boolean %checks(node instanceof HorizontalRuleNode);
26
+ ): node is HorizontalRuleNode;
27
27
 
28
28
  declare export var INSERT_HORIZONTAL_RULE_COMMAND: LexicalCommand<void>;
@@ -18,6 +18,7 @@ export type NodeMenuPluginProps<TOption extends MenuOption> = {
18
18
  menuRenderFn: MenuRenderFn<TOption>;
19
19
  anchorClassName?: string;
20
20
  commandPriority?: CommandListenerPriority;
21
+ parent?: HTMLElement;
21
22
  };
22
- export declare function LexicalNodeMenuPlugin<TOption extends MenuOption>({ options, nodeKey, onClose, onOpen, onSelectOption, menuRenderFn, anchorClassName, commandPriority, }: NodeMenuPluginProps<TOption>): JSX.Element | null;
23
+ export declare function LexicalNodeMenuPlugin<TOption extends MenuOption>({ options, nodeKey, onClose, onOpen, onSelectOption, menuRenderFn, anchorClassName, commandPriority, parent, }: NodeMenuPluginProps<TOption>): JSX.Element | null;
23
24
  export { MenuOption, MenuRenderFn, MenuResolution };
@@ -305,7 +305,7 @@ function LexicalMenu({
305
305
  }), [selectOptionAndCleanUp, selectedIndex, options]);
306
306
  return menuRenderFn(anchorElementRef, listItemProps, resolution.match ? resolution.match.matchingString : '');
307
307
  }
308
- function useMenuAnchorRef(resolution, setResolution, className) {
308
+ function useMenuAnchorRef(resolution, setResolution, className, parent = document.body) {
309
309
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
310
310
  const anchorElementRef = React.useRef(document.createElement('div'));
311
311
  const positionMenu = React.useCallback(() => {
@@ -347,12 +347,12 @@ function useMenuAnchorRef(resolution, setResolution, className) {
347
347
  containerDiv.setAttribute('role', 'listbox');
348
348
  containerDiv.style.display = 'block';
349
349
  containerDiv.style.position = 'absolute';
350
- document.body.append(containerDiv);
350
+ parent.append(containerDiv);
351
351
  }
352
352
  anchorElementRef.current = containerDiv;
353
353
  rootElement.setAttribute('aria-controls', 'typeahead-menu');
354
354
  }
355
- }, [editor, resolution, className]);
355
+ }, [editor, resolution, className, parent]);
356
356
  React.useEffect(() => {
357
357
  const rootElement = editor.getRootElement();
358
358
  if (resolution !== null) {
@@ -401,11 +401,12 @@ function LexicalNodeMenuPlugin({
401
401
  onSelectOption,
402
402
  menuRenderFn,
403
403
  anchorClassName,
404
- commandPriority = lexical.COMMAND_PRIORITY_LOW
404
+ commandPriority = lexical.COMMAND_PRIORITY_LOW,
405
+ parent
405
406
  }) {
406
407
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
407
408
  const [resolution, setResolution] = React.useState(null);
408
- const anchorElementRef = useMenuAnchorRef(resolution, setResolution, anchorClassName);
409
+ const anchorElementRef = useMenuAnchorRef(resolution, setResolution, anchorClassName, parent);
409
410
  const closeNodeMenu = React.useCallback(() => {
410
411
  setResolution(null);
411
412
  if (onClose != null && resolution !== null) {
@@ -4,18 +4,18 @@
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"),u=require("lexical"),w=require("react"),y=require("@lexical/utils"),z="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?w.useLayoutEffect:w.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 f=a.getBoundingClientRect();f.top+f.height>window.innerHeight&&a.scrollIntoView({block:"center"});0>f.top&&a.scrollIntoView({block:"center"});b.scrollIntoView({block:"nearest"})}};
9
- function C(b){var a=u.$getSelection();if(!u.$isRangeSelection(a)||!a.isCollapsed())return null;var f=a.anchor;if("text"!==f.type)return null;a=f.getNode();if(!a.isSimpleText())return null;f=f.offset;let h=a.getTextContent().slice(0,f);var g=b.matchingString;b=b.replaceableString.length;for(let m=b;m<=g.length;m++)h.substr(-m)===g.substr(0,m)&&(b=m);b=f-b;if(0>b)return null;let t;0===b?[t]=a.splitText(f):[,t]=a.splitText(b,f);return t}
10
- function D(b,a){let f=getComputedStyle(b),h="absolute"===f.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===f.position)return document.body;for(;b=b.parentElement;)if(f=getComputedStyle(b),(!h||"static"!==f.position)&&a.test(f.overflow+f.overflowY+f.overflowX))return b;return document.body}function E(b,a){b=b.getBoundingClientRect();a=a.getBoundingClientRect();return b.top>a.top&&b.top<a.bottom}
11
- function F(b,a,f,h){let [g]=k.useLexicalComposerContext();w.useEffect(()=>{if(null!=a&&null!=b){let t=g.getRootElement(),m=null!=t?D(t,!1):document.body,n=!1,c=E(a,m),d=function(){n||(window.requestAnimationFrame(function(){f();n=!1}),n=!0);const q=E(a,m);q!==c&&(c=q,null!=h&&h(q))},p=new ResizeObserver(f);window.addEventListener("resize",f);document.addEventListener("scroll",d,{capture:!0,passive:!0});p.observe(a);return()=>{p.unobserve(a);window.removeEventListener("resize",f);document.removeEventListener("scroll",
12
- d,!0)}}},[a,g,h,f,b])}let G=u.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
13
- function H({close:b,editor:a,anchorElementRef:f,resolution:h,options:g,menuRenderFn:t,onSelectOption:m,shouldSplitNodeWithQuery:n=!1,commandPriority:c=u.COMMAND_PRIORITY_LOW}){let [d,p]=w.useState(null);w.useEffect(()=>{p(0)},[h.match&&h.match.matchingString]);let q=w.useCallback(e=>{a.update(()=>{const l=null!=h.match&&n?C(h.match):null;m(e,l,b,h.match?h.match.matchingString:"")})},[a,n,h.match,m,b]),r=w.useCallback(e=>{const l=a.getRootElement();null!==l&&(l.setAttribute("aria-activedescendant",
14
- "typeahead-item-"+e),p(e))},[a]);w.useEffect(()=>()=>{let e=a.getRootElement();null!==e&&e.removeAttribute("aria-activedescendant")},[a]);z(()=>{null===g?p(null):null===d&&r(0)},[g,d,r]);w.useEffect(()=>y.mergeRegister(a.registerCommand(G,({option:e})=>e.ref&&null!=e.ref.current?(B(e.ref.current),!0):!1,c)),[a,r,c]);w.useEffect(()=>y.mergeRegister(a.registerCommand(u.KEY_ARROW_DOWN_COMMAND,e=>{if(null!==g&&g.length&&null!==d){let l=d!==g.length-1?d+1:0;r(l);let x=g[l];null!=x.ref&&x.ref.current&&
15
- a.dispatchCommand(G,{index:l,option:x});e.preventDefault();e.stopImmediatePropagation()}return!0},c),a.registerCommand(u.KEY_ARROW_UP_COMMAND,e=>{if(null!==g&&g.length&&null!==d){var l=0!==d?d-1:g.length-1;r(l);l=g[l];null!=l.ref&&l.ref.current&&B(l.ref.current);e.preventDefault();e.stopImmediatePropagation()}return!0},c),a.registerCommand(u.KEY_ESCAPE_COMMAND,e=>{e.preventDefault();e.stopImmediatePropagation();b();return!0},c),a.registerCommand(u.KEY_TAB_COMMAND,e=>{if(null===g||null===d||null==
16
- g[d])return!1;e.preventDefault();e.stopImmediatePropagation();q(g[d]);return!0},c),a.registerCommand(u.KEY_ENTER_COMMAND,e=>{if(null===g||null===d||null==g[d])return!1;null!==e&&(e.preventDefault(),e.stopImmediatePropagation());q(g[d]);return!0},c)),[q,b,a,g,d,r,c]);let v=w.useMemo(()=>({options:g,selectOptionAndCleanUp:q,selectedIndex:d,setHighlightedIndex:p}),[q,d,g]);return t(f,v,h.match?h.match.matchingString:"")}
17
- function I(b,a,f){let [h]=k.useLexicalComposerContext(),g=w.useRef(document.createElement("div")),t=w.useCallback(()=>{g.current.style.top=g.current.style.bottom;const n=h.getRootElement(),c=g.current;var d=c.firstChild;if(null!==n&&null!==b){const {left:q,top:r,width:v,height:e}=b.getRect();c.style.top=`${r+window.pageYOffset+g.current.offsetHeight+3}px`;c.style.left=`${q+window.pageXOffset}px`;c.style.height=`${e}px`;c.style.width=`${v}px`;if(null!==d){d.style.top=`${r}`;var p=d.getBoundingClientRect();
18
- d=p.height;p=p.width;const l=n.getBoundingClientRect();q+p>l.right&&(c.style.left=`${l.right-p+window.pageXOffset}px`);(r+d>window.innerHeight||r+d>l.bottom)&&r-l.top>d&&(c.style.top=`${r-d+window.pageYOffset-e}px`)}c.isConnected||(null!=f&&(c.className=f),c.setAttribute("aria-label","Typeahead menu"),c.setAttribute("id","typeahead-menu"),c.setAttribute("role","listbox"),c.style.display="block",c.style.position="absolute",document.body.append(c));g.current=c;n.setAttribute("aria-controls","typeahead-menu")}},
19
- [h,b,f]);w.useEffect(()=>{let n=h.getRootElement();if(null!==b)return t(),()=>{null!==n&&n.removeAttribute("aria-controls");let c=g.current;null!==c&&c.isConnected&&c.remove()}},[h,t,b]);let m=w.useCallback(n=>{null!==b&&(n||a(null))},[b,a]);F(b,g.current,t,m);return g}function J(b){w.startTransition?w.startTransition(b):b()}
20
- exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:f,onOpen:h,onSelectOption:g,menuRenderFn:t,anchorClassName:m,commandPriority:n=u.COMMAND_PRIORITY_LOW}){let [c]=k.useLexicalComposerContext(),[d,p]=w.useState(null);m=I(d,p,m);let q=w.useCallback(()=>{p(null);null!=f&&null!==d&&f()},[f,d]),r=w.useCallback(e=>{p(e);null!=h&&null===d&&h(e)},[h,d]),v=w.useCallback(()=>{a?c.update(()=>{const e=u.$getNodeByKey(a),l=c.getElementByKey(a);null!=e&&null!=l&&null==d&&J(()=>r({getRect:()=>l.getBoundingClientRect()}))}):
21
- null==a&&null!=d&&q()},[q,c,a,r,d]);w.useEffect(()=>{v()},[v,a]);w.useEffect(()=>{if(null!=a)return c.registerUpdateListener(({dirtyElements:e})=>{e.get(a)&&v()})},[c,v,a]);return null===d||null===c?null:w.createElement(H,{close:q,resolution:d,editor:c,anchorElementRef:m,options:b,menuRenderFn:t,onSelectOption:g,commandPriority:n})};exports.MenuOption=A
7
+ 'use strict';var k=require("@lexical/react/LexicalComposerContext"),t=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 d=a.getBoundingClientRect();d.top+d.height>window.innerHeight&&a.scrollIntoView({block:"center"});0>d.top&&a.scrollIntoView({block:"center"});b.scrollIntoView({block:"nearest"})}};
9
+ function C(b){var a=t.$getSelection();if(!t.$isRangeSelection(a)||!a.isCollapsed())return null;var d=a.anchor;if("text"!==d.type)return null;a=d.getNode();if(!a.isSimpleText())return null;d=d.offset;let l=a.getTextContent().slice(0,d);var f=b.matchingString;b=b.replaceableString.length;for(let n=b;n<=f.length;n++)l.substr(-n)===f.substr(0,n)&&(b=n);b=d-b;if(0>b)return null;let p;0===b?[p]=a.splitText(d):[,p]=a.splitText(b,d);return p}
10
+ function D(b,a){let d=getComputedStyle(b),l="absolute"===d.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===d.position)return document.body;for(;b=b.parentElement;)if(d=getComputedStyle(b),(!l||"static"!==d.position)&&a.test(d.overflow+d.overflowY+d.overflowX))return b;return document.body}function E(b,a){b=b.getBoundingClientRect();a=a.getBoundingClientRect();return b.top>a.top&&b.top<a.bottom}
11
+ function F(b,a,d,l){let [f]=k.useLexicalComposerContext();x.useEffect(()=>{if(null!=a&&null!=b){let p=f.getRootElement(),n=null!=p?D(p,!1):document.body,w=!1,m=E(a,n),c=function(){w||(window.requestAnimationFrame(function(){d();w=!1}),w=!0);const q=E(a,n);q!==m&&(m=q,null!=l&&l(q))},g=new ResizeObserver(d);window.addEventListener("resize",d);document.addEventListener("scroll",c,{capture:!0,passive:!0});g.observe(a);return()=>{g.unobserve(a);window.removeEventListener("resize",d);document.removeEventListener("scroll",
12
+ c,!0)}}},[a,f,l,d,b])}let G=t.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
13
+ function H({close:b,editor:a,anchorElementRef:d,resolution:l,options:f,menuRenderFn:p,onSelectOption:n,shouldSplitNodeWithQuery:w=!1,commandPriority:m=t.COMMAND_PRIORITY_LOW}){let [c,g]=x.useState(null);x.useEffect(()=>{g(0)},[l.match&&l.match.matchingString]);let q=x.useCallback(e=>{a.update(()=>{const h=null!=l.match&&w?C(l.match):null;n(e,h,b,l.match?l.match.matchingString:"")})},[a,w,l.match,n,b]),r=x.useCallback(e=>{const h=a.getRootElement();null!==h&&(h.setAttribute("aria-activedescendant",
14
+ "typeahead-item-"+e),g(e))},[a]);x.useEffect(()=>()=>{let e=a.getRootElement();null!==e&&e.removeAttribute("aria-activedescendant")},[a]);z(()=>{null===f?g(null):null===c&&r(0)},[f,c,r]);x.useEffect(()=>y.mergeRegister(a.registerCommand(G,({option:e})=>e.ref&&null!=e.ref.current?(B(e.ref.current),!0):!1,m)),[a,r,m]);x.useEffect(()=>y.mergeRegister(a.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>{if(null!==f&&f.length&&null!==c){let h=c!==f.length-1?c+1:0;r(h);let u=f[h];null!=u.ref&&u.ref.current&&
15
+ a.dispatchCommand(G,{index:h,option:u});e.preventDefault();e.stopImmediatePropagation()}return!0},m),a.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{if(null!==f&&f.length&&null!==c){var h=0!==c?c-1:f.length-1;r(h);h=f[h];null!=h.ref&&h.ref.current&&B(h.ref.current);e.preventDefault();e.stopImmediatePropagation()}return!0},m),a.registerCommand(t.KEY_ESCAPE_COMMAND,e=>{e.preventDefault();e.stopImmediatePropagation();b();return!0},m),a.registerCommand(t.KEY_TAB_COMMAND,e=>{if(null===f||null===c||null==
16
+ f[c])return!1;e.preventDefault();e.stopImmediatePropagation();q(f[c]);return!0},m),a.registerCommand(t.KEY_ENTER_COMMAND,e=>{if(null===f||null===c||null==f[c])return!1;null!==e&&(e.preventDefault(),e.stopImmediatePropagation());q(f[c]);return!0},m)),[q,b,a,f,c,r,m]);let v=x.useMemo(()=>({options:f,selectOptionAndCleanUp:q,selectedIndex:c,setHighlightedIndex:g}),[q,c,f]);return p(d,v,l.match?l.match.matchingString:"")}
17
+ function I(b,a,d,l=document.body){let [f]=k.useLexicalComposerContext(),p=x.useRef(document.createElement("div")),n=x.useCallback(()=>{p.current.style.top=p.current.style.bottom;const m=f.getRootElement(),c=p.current;var g=c.firstChild;if(null!==m&&null!==b){const {left:r,top:v,width:e,height:h}=b.getRect();c.style.top=`${v+window.pageYOffset+p.current.offsetHeight+3}px`;c.style.left=`${r+window.pageXOffset}px`;c.style.height=`${h}px`;c.style.width=`${e}px`;if(null!==g){g.style.top=`${v}`;var q=g.getBoundingClientRect();
18
+ g=q.height;q=q.width;const u=m.getBoundingClientRect();r+q>u.right&&(c.style.left=`${u.right-q+window.pageXOffset}px`);(v+g>window.innerHeight||v+g>u.bottom)&&v-u.top>g&&(c.style.top=`${v-g+window.pageYOffset-h}px`)}c.isConnected||(null!=d&&(c.className=d),c.setAttribute("aria-label","Typeahead menu"),c.setAttribute("id","typeahead-menu"),c.setAttribute("role","listbox"),c.style.display="block",c.style.position="absolute",l.append(c));p.current=c;m.setAttribute("aria-controls","typeahead-menu")}},
19
+ [f,b,d,l]);x.useEffect(()=>{let m=f.getRootElement();if(null!==b)return n(),()=>{null!==m&&m.removeAttribute("aria-controls");let c=p.current;null!==c&&c.isConnected&&c.remove()}},[f,n,b]);let w=x.useCallback(m=>{null!==b&&(m||a(null))},[b,a]);F(b,p.current,n,w);return p}function J(b){x.startTransition?x.startTransition(b):b()}
20
+ exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:d,onOpen:l,onSelectOption:f,menuRenderFn:p,anchorClassName:n,commandPriority:w=t.COMMAND_PRIORITY_LOW,parent:m}){let [c]=k.useLexicalComposerContext(),[g,q]=x.useState(null);n=I(g,q,n,m);let r=x.useCallback(()=>{q(null);null!=d&&null!==g&&d()},[d,g]),v=x.useCallback(h=>{q(h);null!=l&&null===g&&l(h)},[l,g]),e=x.useCallback(()=>{a?c.update(()=>{const h=t.$getNodeByKey(a),u=c.getElementByKey(a);null!=h&&null!=u&&null==g&&J(()=>v({getRect:()=>
21
+ u.getBoundingClientRect()}))}):null==a&&null!=g&&r()},[r,c,a,v,g]);x.useEffect(()=>{e()},[e,a]);x.useEffect(()=>{if(null!=a)return c.registerUpdateListener(({dirtyElements:h})=>{h.get(a)&&e()})},[c,e,a]);return null===g||null===c?null:x.createElement(H,{close:r,resolution:g,editor:c,anchorElementRef:n,options:b,menuRenderFn:p,onSelectOption:f,commandPriority:w})};exports.MenuOption=A
@@ -103,20 +103,20 @@ function TablePlugin({
103
103
  if (node.getColSpan() > 1 || node.getRowSpan() > 1) {
104
104
  // When we have rowSpan we have to map the entire Table to understand where the new Cells
105
105
  // fit best; let's analyze all Cells at once to save us from further transform iterations
106
- const [,, gridNode] = lexical.DEPRECATED_$getNodeTriplet(node);
107
- const [gridMap] = lexical.DEPRECATED_$computeGridMap(gridNode, node, node);
106
+ const [,, gridNode] = table.$getNodeTriplet(node);
107
+ const [gridMap] = table.$computeTableMap(gridNode, node, node);
108
108
  // TODO this function expects Tables to be normalized. Look into this once it exists
109
109
  const rowsCount = gridMap.length;
110
110
  const columnsCount = gridMap[0].length;
111
111
  let row = gridNode.getFirstChild();
112
- if (!lexical.DEPRECATED_$isGridRowNode(row)) {
112
+ if (!table.$isTableRowNode(row)) {
113
113
  throw Error(`Expected TableNode first child to be a RowNode`);
114
114
  }
115
115
  const unmerged = [];
116
116
  for (let i = 0; i < rowsCount; i++) {
117
117
  if (i !== 0) {
118
118
  row = row.getNextSibling();
119
- if (!lexical.DEPRECATED_$isGridRowNode(row)) {
119
+ if (!table.$isTableRowNode(row)) {
120
120
  throw Error(`Expected TableNode first child to be a RowNode`);
121
121
  }
122
122
  }
@@ -4,9 +4,8 @@
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"),k=require("@lexical/table"),r=require("@lexical/utils"),v=require("lexical"),w=require("react");function x(m){let n=new URLSearchParams;n.append("code",m);for(let p=1;p<arguments.length;p++)n.append("v",arguments[p]);throw Error(`Minified Lexical error #${m}; visit https://lexical.dev/docs/error?${n} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- exports.TablePlugin=function({hasCellMerge:m=!0,hasCellBackgroundColor:n=!0,hasTabHandler:p=!0}){let [d]=c.useLexicalComposerContext();w.useEffect(()=>{d.hasNodes([k.TableNode,k.TableCellNode,k.TableRowNode])||x(10);return d.registerCommand(k.INSERT_TABLE_COMMAND,({columns:a,rows:e,includeHeaders:h})=>{a=k.$createTableNodeWithDimensions(Number(e),Number(a),h);r.$insertNodeToNearestRoot(a);a=a.getFirstDescendant();v.$isTextNode(a)&&a.select();return!0},v.COMMAND_PRIORITY_EDITOR)},[d]);w.useEffect(()=>
9
- {let a=new Map,e=b=>{const f=b.getKey(),l=d.getElementByKey(f);l&&!a.has(f)&&(b=k.applyTableHandlers(b,l,d,p),a.set(f,b))};d.getEditorState().read(()=>{let b=v.$nodesOfType(k.TableNode);for(let f of b)k.$isTableNode(f)&&e(f)});let h=d.registerMutationListener(k.TableNode,b=>{for(const [f,l]of b)"created"===l?d.getEditorState().read(()=>{const g=v.$getNodeByKey(f);k.$isTableNode(g)&&e(g)}):"destroyed"===l&&(b=a.get(f),void 0!==b&&(b.removeListeners(),a.delete(f)))});return()=>{h();for(let [,b]of a)b.removeListeners()}},
10
- [d,p]);w.useEffect(()=>{if(!m)return d.registerNodeTransform(k.TableCellNode,a=>{if(1<a.getColSpan()||1<a.getRowSpan()){var [,,e]=v.DEPRECATED_$getNodeTriplet(a);[a]=v.DEPRECATED_$computeGridMap(e,a,a);let b=a.length,f=a[0].length;e=e.getFirstChild();if(!v.DEPRECATED_$isGridRowNode(e))throw Error("Expected TableNode first child to be a RowNode");let l=[];for(let g=0;g<b;g++){if(0!==g&&(e=e.getNextSibling(),!v.DEPRECATED_$isGridRowNode(e)))throw Error("Expected TableNode first child to be a RowNode");
11
- let u=null;for(let t=0;t<f;t++){var h=a[g][t];let q=h.cell;if(h.startRow===g&&h.startColumn===t)u=q,l.push(q);else if(1<q.getColSpan()||1<q.getRowSpan()){if(!k.$isTableCellNode(q))throw Error("Expected TableNode cell to be a TableCellNode");h=k.$createTableCellNode(q.__headerState);null!==u?u.insertAfter(h):r.$insertFirst(e,h)}}}for(let g of l)g.setColSpan(1),g.setRowSpan(1)}})},[d,m]);w.useEffect(()=>{if(!n)return d.registerNodeTransform(k.TableCellNode,a=>{null!==a.getBackgroundColor()&&a.setBackgroundColor(null)})},
12
- [d,n,m]);return null}
7
+ 'use strict';var b=require("@lexical/react/LexicalComposerContext"),q=require("@lexical/table"),r=require("@lexical/utils"),v=require("lexical"),w=require("react");function x(l){let m=new URLSearchParams;m.append("code",l);for(let n=1;n<arguments.length;n++)m.append("v",arguments[n]);throw Error(`Minified Lexical error #${l}; visit https://lexical.dev/docs/error?${m} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
+ exports.TablePlugin=function({hasCellMerge:l=!0,hasCellBackgroundColor:m=!0,hasTabHandler:n=!0}){let [d]=b.useLexicalComposerContext();w.useEffect(()=>{d.hasNodes([q.TableNode,q.TableCellNode,q.TableRowNode])||x(10);return d.registerCommand(q.INSERT_TABLE_COMMAND,({columns:a,rows:e,includeHeaders:h})=>{a=q.$createTableNodeWithDimensions(Number(e),Number(a),h);r.$insertNodeToNearestRoot(a);a=a.getFirstDescendant();v.$isTextNode(a)&&a.select();return!0},v.COMMAND_PRIORITY_EDITOR)},[d]);w.useEffect(()=>
9
+ {let a=new Map,e=c=>{const f=c.getKey(),k=d.getElementByKey(f);k&&!a.has(f)&&(c=q.applyTableHandlers(c,k,d,n),a.set(f,c))};d.getEditorState().read(()=>{let c=v.$nodesOfType(q.TableNode);for(let f of c)q.$isTableNode(f)&&e(f)});let h=d.registerMutationListener(q.TableNode,c=>{for(const [f,k]of c)"created"===k?d.getEditorState().read(()=>{const g=v.$getNodeByKey(f);q.$isTableNode(g)&&e(g)}):"destroyed"===k&&(c=a.get(f),void 0!==c&&(c.removeListeners(),a.delete(f)))});return()=>{h();for(let [,c]of a)c.removeListeners()}},
10
+ [d,n]);w.useEffect(()=>{if(!l)return d.registerNodeTransform(q.TableCellNode,a=>{if(1<a.getColSpan()||1<a.getRowSpan()){var [,,e]=q.$getNodeTriplet(a);[a]=q.$computeTableMap(e,a,a);let c=a.length,f=a[0].length;e=e.getFirstChild();if(!q.$isTableRowNode(e))throw Error("Expected TableNode first child to be a RowNode");let k=[];for(let g=0;g<c;g++){if(0!==g&&(e=e.getNextSibling(),!q.$isTableRowNode(e)))throw Error("Expected TableNode first child to be a RowNode");let u=null;for(let t=0;t<f;t++){var h=
11
+ a[g][t];let p=h.cell;if(h.startRow===g&&h.startColumn===t)u=p,k.push(p);else if(1<p.getColSpan()||1<p.getRowSpan()){if(!q.$isTableCellNode(p))throw Error("Expected TableNode cell to be a TableCellNode");h=q.$createTableCellNode(p.__headerState);null!==u?u.insertAfter(h):r.$insertFirst(e,h)}}}for(let g of k)g.setColSpan(1),g.setRowSpan(1)}})},[d,l]);w.useEffect(()=>{if(!m)return d.registerNodeTransform(q.TableCellNode,a=>{null!==a.getBackgroundColor()&&a.setBackgroundColor(null)})},[d,m,l]);return null}
@@ -254,8 +254,8 @@ function printNodeSelection(selection) {
254
254
  if (!lexical.$isNodeSelection(selection)) return '';
255
255
  return `: node\n └ [${Array.from(selection._nodes).join(', ')}]`;
256
256
  }
257
- function printGridSelection(selection) {
258
- return `: grid\n └ { grid: ${selection.gridKey}, anchorCell: ${selection.anchor.key}, focusCell: ${selection.focus.key} }`;
257
+ function printTableSelection(selection) {
258
+ return `: table\n └ { table: ${selection.tableKey}, anchorCell: ${selection.anchor.key}, focusCell: ${selection.focus.key} }`;
259
259
  }
260
260
  function generateContent(editor, commandsLog, exportDOM) {
261
261
  const editorState = editor.getEditorState();
@@ -288,7 +288,7 @@ function generateContent(editor, commandsLog, exportDOM) {
288
288
  typeDisplay
289
289
  });
290
290
  });
291
- return selection === null ? ': null' : lexical.$isRangeSelection(selection) ? printRangeSelection(selection) : table.$isGridSelection(selection) ? printGridSelection(selection) : printNodeSelection(selection);
291
+ return selection === null ? ': null' : lexical.$isRangeSelection(selection) ? printRangeSelection(selection) : table.$isTableSelection(selection) ? printTableSelection(selection) : printNodeSelection(selection);
292
292
  });
293
293
  res += '\n selection' + selectionString;
294
294
  res += '\n\n commands:';
@@ -447,8 +447,11 @@ function prettifyHTML(node, level) {
447
447
  return node;
448
448
  }
449
449
  function $getSelectionStartEnd(node, selection) {
450
- const anchor = selection.anchor;
451
- const focus = selection.focus;
450
+ const anchorAndFocus = selection.getStartEndPoints();
451
+ if (lexical.$isNodeSelection(selection) || anchorAndFocus === null) {
452
+ return [-1, -1];
453
+ }
454
+ const [anchor, focus] = anchorAndFocus;
452
455
  const textContent = node.getTextContent();
453
456
  const textLength = textContent.length;
454
457
  let start = -1;
@@ -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 g=require("@lexical/html"),w=require("@lexical/link"),x=require("@lexical/mark"),I=require("@lexical/table"),M=require("@lexical/utils"),N=require("lexical"),O=require("react");let P=Object.freeze({"\t":"\\t","\n":"\\n"}),Q=new RegExp(Object.keys(P).join("|"),"g"),R=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
8
- function U(a){let [b,c]=O.useState([]);O.useEffect(()=>{let l=new Set;for(let [e]of a._commands)l.add(a.registerCommand(e,p=>{c(d=>{d=[...d];d.push({payload:p,type:e.type?e.type:"UNKNOWN"});10<d.length&&d.shift();return d});return!1},N.COMMAND_PRIORITY_HIGH));return()=>l.forEach(e=>e())},[a]);return O.useMemo(()=>b,[b])}
9
- function aa(a){let b="";var c=V(a);b+=`: range ${""!==c?`{ ${c} }`:""} ${""!==a.style?`{ style: ${a.style} } `:""}`;c=a.anchor;a=a.focus;let l=c.offset,e=a.offset;b+=`\n \u251c anchor { key: ${c.key}, offset: ${null===l?"null":l}, type: ${c.type} }`;return b+=`\n \u2514 focus { key: ${a.key}, offset: ${null===e?"null":e}, type: ${a.type} }`}function ba(a){return N.$isNodeSelection(a)?`: node\n \u2514 [${Array.from(a._nodes).join(", ")}]`:""}
10
- function W(a,b,c){let l=a.getEditorState(),e=a._config,p=a._compositionKey,d=a._editable;if(c){let m="";l.read(()=>{var k=g.$generateHtmlFromNodes(a);let t=document.createElement("div");t.innerHTML=k.trim();m=X(t,0).innerHTML});return m}let h=" root\n";c=l.read(()=>{const m=N.$getSelection();Y(N.$getRoot(),(k,t)=>{const y=`(${k.getKey()})`,v=k.getType()||"",q=k.isSelected(),J=x.$isMarkNode(k)?` id: [ ${k.getIDs().join(", ")} ] `:"";var A=h,H=q?R.selectedLine:" ",F=t.join(" ");if(N.$isTextNode(k)){var n=
11
- k.getTextContent();var u=0===n.length?"(empty)":`"${Z(n)}"`;n=[V(k),ca(k),da(k)].filter(Boolean).join(", ");n=[u,0!==n.length?`{ ${n} }`:null].filter(Boolean).join(" ").trim()}else if(w.$isLinkNode(k)){n=k.getURL();n=0===n.length?"(empty)":`"${Z(n)}"`;u=k.getTarget();null!=u&&(u="target: "+u);var B=Boolean;var C=k.getRel();null!=C&&(C="rel: "+C);let r=k.getTitle();null!=r&&(r="title: "+r);u=[u,C,r].filter(B).join(", ");n=[n,0!==u.length?`{ ${u} }`:null].filter(Boolean).join(" ").trim()}else n="";
12
- h=A+`${H} ${F} ${y} ${v} ${J} ${n}\n`;h+=ea({indent:t,isSelected:q,node:k,nodeKeyDisplay:y,selection:m,typeDisplay:v})});return null===m?": null":N.$isRangeSelection(m)?aa(m):I.$isGridSelection(m)?`: grid\n \u2514 { grid: ${m.gridKey}, anchorCell: ${m.anchor.key}, focusCell: ${m.focus.key} }`:ba(m)});h+="\n selection"+c;h+="\n\n commands:";if(b.length)for(let {type:m,payload:k}of b)h+=`\n \u2514 { type: ${m}, payload: ${k instanceof Event?k.constructor.name:k} }`;else h+="\n \u2514 None dispatched.";
13
- h+="\n\n editor:";h+=`\n \u2514 namespace ${e.namespace}`;null!==p&&(h+=`\n \u2514 compositionKey ${p}`);return h+=`\n \u2514 editable ${String(d)}`}function Y(a,b,c=[]){a=a.getChildren();let l=a.length;a.forEach((e,p)=>{b(e,c.concat(p===l-1?R.isLastChild:R.hasNextSibling));N.$isElementNode(e)&&Y(e,b,c.concat(p===l-1?R.ancestorIsLastChild:R.ancestorHasNextSibling))})}function Z(a){return Object.entries(P).reduce((b,[c,l])=>b.replace(new RegExp(c,"g"),String(l)),a)}
7
+ 'use strict';var g=require("@lexical/html"),v=require("@lexical/link"),x=require("@lexical/mark"),I=require("@lexical/table"),M=require("@lexical/utils"),N=require("lexical"),O=require("react");let P=Object.freeze({"\t":"\\t","\n":"\\n"}),Q=new RegExp(Object.keys(P).join("|"),"g"),R=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
8
+ function U(a){let [b,c]=O.useState([]);O.useEffect(()=>{let m=new Set;for(let [d]of a._commands)m.add(a.registerCommand(d,p=>{c(e=>{e=[...e];e.push({payload:p,type:d.type?d.type:"UNKNOWN"});10<e.length&&e.shift();return e});return!1},N.COMMAND_PRIORITY_HIGH));return()=>m.forEach(d=>d())},[a]);return O.useMemo(()=>b,[b])}
9
+ function aa(a){let b="";var c=V(a);b+=`: range ${""!==c?`{ ${c} }`:""} ${""!==a.style?`{ style: ${a.style} } `:""}`;c=a.anchor;a=a.focus;let m=c.offset,d=a.offset;b+=`\n \u251c anchor { key: ${c.key}, offset: ${null===m?"null":m}, type: ${c.type} }`;return b+=`\n \u2514 focus { key: ${a.key}, offset: ${null===d?"null":d}, type: ${a.type} }`}function ba(a){return N.$isNodeSelection(a)?`: node\n \u2514 [${Array.from(a._nodes).join(", ")}]`:""}
10
+ function W(a,b,c){let m=a.getEditorState(),d=a._config,p=a._compositionKey,e=a._editable;if(c){let l="";m.read(()=>{var k=g.$generateHtmlFromNodes(a);let t=document.createElement("div");t.innerHTML=k.trim();l=X(t,0).innerHTML});return l}let h=" root\n";c=m.read(()=>{const l=N.$getSelection();Y(N.$getRoot(),(k,t)=>{const y=`(${k.getKey()})`,w=k.getType()||"",q=k.isSelected(),J=x.$isMarkNode(k)?` id: [ ${k.getIDs().join(", ")} ] `:"";var A=h,H=q?R.selectedLine:" ",F=t.join(" ");if(N.$isTextNode(k)){var n=
11
+ k.getTextContent();var u=0===n.length?"(empty)":`"${Z(n)}"`;n=[V(k),ca(k),da(k)].filter(Boolean).join(", ");n=[u,0!==n.length?`{ ${n} }`:null].filter(Boolean).join(" ").trim()}else if(v.$isLinkNode(k)){n=k.getURL();n=0===n.length?"(empty)":`"${Z(n)}"`;u=k.getTarget();null!=u&&(u="target: "+u);var B=Boolean;var C=k.getRel();null!=C&&(C="rel: "+C);let r=k.getTitle();null!=r&&(r="title: "+r);u=[u,C,r].filter(B).join(", ");n=[n,0!==u.length?`{ ${u} }`:null].filter(Boolean).join(" ").trim()}else n="";
12
+ h=A+`${H} ${F} ${y} ${w} ${J} ${n}\n`;h+=ea({indent:t,isSelected:q,node:k,nodeKeyDisplay:y,selection:l,typeDisplay:w})});return null===l?": null":N.$isRangeSelection(l)?aa(l):I.$isTableSelection(l)?`: table\n \u2514 { table: ${l.tableKey}, anchorCell: ${l.anchor.key}, focusCell: ${l.focus.key} }`:ba(l)});h+="\n selection"+c;h+="\n\n commands:";if(b.length)for(let {type:l,payload:k}of b)h+=`\n \u2514 { type: ${l}, payload: ${k instanceof Event?k.constructor.name:k} }`;else h+="\n \u2514 None dispatched.";
13
+ h+="\n\n editor:";h+=`\n \u2514 namespace ${d.namespace}`;null!==p&&(h+=`\n \u2514 compositionKey ${p}`);return h+=`\n \u2514 editable ${String(e)}`}function Y(a,b,c=[]){a=a.getChildren();let m=a.length;a.forEach((d,p)=>{b(d,c.concat(p===m-1?R.isLastChild:R.hasNextSibling));N.$isElementNode(d)&&Y(d,b,c.concat(p===m-1?R.ancestorIsLastChild:R.ancestorHasNextSibling))})}function Z(a){return Object.entries(P).reduce((b,[c,m])=>b.replace(new RegExp(c,"g"),String(m)),a)}
14
14
  let fa=[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"],ha=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],ia=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented"];
15
15
  function ca(a){let b=ha.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="detail: "+b);return b}function da(a){let b=ia.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="mode: "+b);return b}function V(a){let b=fa.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="format: "+b);return b}
16
- function ea({indent:a,isSelected:b,node:c,nodeKeyDisplay:l,selection:e,typeDisplay:p}){if(!N.$isTextNode(c)||!N.$isRangeSelection(e)||!b||N.$isElementNode(c))return"";b=e.anchor;var d=e.focus;if(""===c.getTextContent()||b.getNode()===e.focus.getNode()&&b.offset===d.offset)return"";d=e.anchor;let h=e.focus,m=c.getTextContent(),k=m.length;b=e=-1;if("text"===d.type&&"text"===h.type){let v=d.getNode(),q=h.getNode();v===q&&c===v&&d.offset!==h.offset?[e,b]=d.offset<h.offset?[d.offset,h.offset]:[h.offset,
17
- d.offset]:c===v?[e,b]=v.isBefore(q)?[d.offset,k]:[0,d.offset]:c===q?[e,b]=q.isBefore(v)?[h.offset,k]:[0,h.offset]:[e,b]=[0,k]}c=(m.slice(0,e).match(Q)||[]).length;d=(m.slice(e,b).match(Q)||[]).length;let [t,y]=[e+c,b+c+d];if(t===y)return"";c=a[a.length-1]===R.hasNextSibling?R.ancestorHasNextSibling:R.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(t+1).fill(" ");e=Array(y-t).fill(R.selectedChar);l=Array(l.length+(p.length+3)).fill(" ");return[R.selectedLine,a.join(" "),[...l,...c,...e].join("")].join(" ")+
18
- "\n"}function X(a,b){let c=Array(b++ +1).join(" "),l=Array(b-1).join(" "),e;for(let p=0;p<a.children.length;p++)e=document.createTextNode("\n"+c),a.insertBefore(e,a.children[p]),X(a.children[p],b),a.lastElementChild===a.children[p]&&(e=document.createTextNode("\n"+l),a.appendChild(e));return a}
19
- exports.TreeView=function({treeTypeButtonClassName:a,timeTravelButtonClassName:b,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:l,viewClassName:e,timeTravelPanelClassName:p,editor:d}){let [h,m]=O.useState([]),[k,t]=O.useState(""),[y,v]=O.useState(!1),[q,J]=O.useState(!1),A=O.useRef(0),H=O.useRef(null),F=O.useRef(null),[n,u]=O.useState(!1),[B,C]=O.useState(!1),[r,ja]=O.useState(!1),K=O.useRef(null),D=U(d),L=O.useCallback(f=>{const z=W(d,D,q);t(z);y||m(G=>[...G,[Date.now(),f]])},[D,
20
- d,y,q]);O.useEffect(()=>{let f=d.getEditorState();!r&&1E3>f._nodeMap.size&&t(W(d,D,q))},[D,d,r,q]);O.useEffect(()=>M.mergeRegister(d.registerUpdateListener(({editorState:f})=>{if(!r&&1E3<f._nodeMap.size&&(K.current=f,C(!0),!r))return;L(f)}),d.registerEditableListener(()=>{let f=W(d,D,q);t(f)})),[D,d,q,B,L,r]);let E=h.length;O.useEffect(()=>{if(n){let f,z=()=>{const G=A.current;G===E-1?u(!1):f=setTimeout(()=>{A.current++;const S=A.current,T=F.current;null!==T&&(T.value=String(S));d.setEditorState(h[S][1]);
21
- z()},h[G+1][0]-h[G][0])};z();return()=>{clearTimeout(f)}}},[h,n,d,E]);O.useEffect(()=>{let f=H.current;if(null!==f)return f.__lexicalEditor=d,()=>{f.__lexicalEditor=null}},[d]);return O.createElement("div",{className:e},!r&&B?O.createElement("div",{style:{padding:20}},O.createElement("span",{style:{marginRight:20}},"Detected large EditorState, this can impact debugging performance."),O.createElement("button",{onClick:()=>{ja(!0);let f=K.current;null!==f&&(K.current=null,L(f))},style:{background:"transparent",
22
- border:"1px solid white",color:"white",cursor:"pointer",padding:5}},"Show full tree")):null,r?null:O.createElement("button",{onClick:()=>J(!q),className:a,type:"button"},q?"Tree":"Export DOM"),!y&&(r||!B)&&2<E&&O.createElement("button",{onClick:()=>{let f=d.getRootElement();null!==f&&(f.contentEditable="false",A.current=E-1,v(!0))},className:b,type:"button"},"Time Travel"),(r||!B)&&O.createElement("pre",{ref:H},k),y&&(r||!B)&&O.createElement("div",{className:p},O.createElement("button",{className:l,
23
- onClick:()=>{A.current===E-1&&(A.current=1);u(!n)},type:"button"},n?"Pause":"Play"),O.createElement("input",{className:c,ref:F,onChange:f=>{f=Number(f.target.value);let z=h[f];z&&(A.current=f,d.setEditorState(z[1]))},type:"range",min:"1",max:E-1}),O.createElement("button",{className:l,onClick:()=>{var f=d.getRootElement();if(null!==f){f.contentEditable="true";f=h.length-1;d.setEditorState(h[f][1]);let z=F.current;null!==z&&(z.value=String(f));v(!1);u(!1)}},type:"button"},"Exit")))}
16
+ function ea({indent:a,isSelected:b,node:c,nodeKeyDisplay:m,selection:d,typeDisplay:p}){if(!N.$isTextNode(c)||!N.$isRangeSelection(d)||!b||N.$isElementNode(c))return"";b=d.anchor;var e=d.focus;if(""===c.getTextContent()||b.getNode()===d.focus.getNode()&&b.offset===e.offset)return"";b=d.getStartEndPoints();if(N.$isNodeSelection(d)||null===b)c=[-1,-1];else{var [h,l]=b;e=c.getTextContent();var k=e.length;b=d=-1;if("text"===h.type&&"text"===l.type){let w=h.getNode(),q=l.getNode();w===q&&c===w&&h.offset!==
17
+ l.offset?[d,b]=h.offset<l.offset?[h.offset,l.offset]:[l.offset,h.offset]:c===w?[d,b]=w.isBefore(q)?[h.offset,k]:[0,h.offset]:c===q?[d,b]=q.isBefore(w)?[l.offset,k]:[0,l.offset]:[d,b]=[0,k]}c=(e.slice(0,d).match(Q)||[]).length;e=(e.slice(d,b).match(Q)||[]).length;c=[d+c,b+c+e]}let [t,y]=c;if(t===y)return"";c=a[a.length-1]===R.hasNextSibling?R.ancestorHasNextSibling:R.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(t+1).fill(" ");d=Array(y-t).fill(R.selectedChar);m=Array(m.length+(p.length+
18
+ 3)).fill(" ");return[R.selectedLine,a.join(" "),[...m,...c,...d].join("")].join(" ")+"\n"}function X(a,b){let c=Array(b++ +1).join(" "),m=Array(b-1).join(" "),d;for(let p=0;p<a.children.length;p++)d=document.createTextNode("\n"+c),a.insertBefore(d,a.children[p]),X(a.children[p],b),a.lastElementChild===a.children[p]&&(d=document.createTextNode("\n"+m),a.appendChild(d));return a}
19
+ exports.TreeView=function({treeTypeButtonClassName:a,timeTravelButtonClassName:b,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:m,viewClassName:d,timeTravelPanelClassName:p,editor:e}){let [h,l]=O.useState([]),[k,t]=O.useState(""),[y,w]=O.useState(!1),[q,J]=O.useState(!1),A=O.useRef(0),H=O.useRef(null),F=O.useRef(null),[n,u]=O.useState(!1),[B,C]=O.useState(!1),[r,ja]=O.useState(!1),K=O.useRef(null),D=U(e),L=O.useCallback(f=>{const z=W(e,D,q);t(z);y||l(G=>[...G,[Date.now(),f]])},[D,
20
+ e,y,q]);O.useEffect(()=>{let f=e.getEditorState();!r&&1E3>f._nodeMap.size&&t(W(e,D,q))},[D,e,r,q]);O.useEffect(()=>M.mergeRegister(e.registerUpdateListener(({editorState:f})=>{if(!r&&1E3<f._nodeMap.size&&(K.current=f,C(!0),!r))return;L(f)}),e.registerEditableListener(()=>{let f=W(e,D,q);t(f)})),[D,e,q,B,L,r]);let E=h.length;O.useEffect(()=>{if(n){let f,z=()=>{const G=A.current;G===E-1?u(!1):f=setTimeout(()=>{A.current++;const S=A.current,T=F.current;null!==T&&(T.value=String(S));e.setEditorState(h[S][1]);
21
+ z()},h[G+1][0]-h[G][0])};z();return()=>{clearTimeout(f)}}},[h,n,e,E]);O.useEffect(()=>{let f=H.current;if(null!==f)return f.__lexicalEditor=e,()=>{f.__lexicalEditor=null}},[e]);return O.createElement("div",{className:d},!r&&B?O.createElement("div",{style:{padding:20}},O.createElement("span",{style:{marginRight:20}},"Detected large EditorState, this can impact debugging performance."),O.createElement("button",{onClick:()=>{ja(!0);let f=K.current;null!==f&&(K.current=null,L(f))},style:{background:"transparent",
22
+ border:"1px solid white",color:"white",cursor:"pointer",padding:5}},"Show full tree")):null,r?null:O.createElement("button",{onClick:()=>J(!q),className:a,type:"button"},q?"Tree":"Export DOM"),!y&&(r||!B)&&2<E&&O.createElement("button",{onClick:()=>{let f=e.getRootElement();null!==f&&(f.contentEditable="false",A.current=E-1,w(!0))},className:b,type:"button"},"Time Travel"),(r||!B)&&O.createElement("pre",{ref:H},k),y&&(r||!B)&&O.createElement("div",{className:p},O.createElement("button",{className:m,
23
+ onClick:()=>{A.current===E-1&&(A.current=1);u(!n)},type:"button"},n?"Pause":"Play"),O.createElement("input",{className:c,ref:F,onChange:f=>{f=Number(f.target.value);let z=h[f];z&&(A.current=f,e.setEditorState(z[1]))},type:"range",min:"1",max:E-1}),O.createElement("button",{className:m,onClick:()=>{var f=e.getRootElement();if(null!==f){f.contentEditable="true";f=h.length-1;e.setEditorState(h[f][1]);let z=F.current;null!==z&&(z.value=String(f));w(!1);u(!1)}},type:"button"},"Exit")))}
@@ -30,6 +30,7 @@ export type TypeaheadMenuPluginProps<TOption extends MenuOption> = {
30
30
  onClose?: () => void;
31
31
  anchorClassName?: string;
32
32
  commandPriority?: CommandListenerPriority;
33
+ parent?: HTMLElement;
33
34
  };
34
- export declare function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>({ options, onQueryChange, onSelectOption, onOpen, onClose, menuRenderFn, triggerFn, anchorClassName, commandPriority, }: TypeaheadMenuPluginProps<TOption>): JSX.Element | null;
35
+ export declare function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>({ options, onQueryChange, onSelectOption, onOpen, onClose, menuRenderFn, triggerFn, anchorClassName, commandPriority, parent, }: TypeaheadMenuPluginProps<TOption>): JSX.Element | null;
35
36
  export { MenuOption, MenuRenderFn, MenuResolution, MenuTextMatch, TriggerFn };
@@ -305,7 +305,7 @@ function LexicalMenu({
305
305
  }), [selectOptionAndCleanUp, selectedIndex, options]);
306
306
  return menuRenderFn(anchorElementRef, listItemProps, resolution.match ? resolution.match.matchingString : '');
307
307
  }
308
- function useMenuAnchorRef(resolution, setResolution, className) {
308
+ function useMenuAnchorRef(resolution, setResolution, className, parent = document.body) {
309
309
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
310
310
  const anchorElementRef = React.useRef(document.createElement('div'));
311
311
  const positionMenu = React.useCallback(() => {
@@ -347,12 +347,12 @@ function useMenuAnchorRef(resolution, setResolution, className) {
347
347
  containerDiv.setAttribute('role', 'listbox');
348
348
  containerDiv.style.display = 'block';
349
349
  containerDiv.style.position = 'absolute';
350
- document.body.append(containerDiv);
350
+ parent.append(containerDiv);
351
351
  }
352
352
  anchorElementRef.current = containerDiv;
353
353
  rootElement.setAttribute('aria-controls', 'typeahead-menu');
354
354
  }
355
- }, [editor, resolution, className]);
355
+ }, [editor, resolution, className, parent]);
356
356
  React.useEffect(() => {
357
357
  const rootElement = editor.getRootElement();
358
358
  if (resolution !== null) {
@@ -503,11 +503,12 @@ function LexicalTypeaheadMenuPlugin({
503
503
  menuRenderFn,
504
504
  triggerFn,
505
505
  anchorClassName,
506
- commandPriority = lexical.COMMAND_PRIORITY_LOW
506
+ commandPriority = lexical.COMMAND_PRIORITY_LOW,
507
+ parent
507
508
  }) {
508
509
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
509
510
  const [resolution, setResolution] = React.useState(null);
510
- const anchorElementRef = useMenuAnchorRef(resolution, setResolution, anchorClassName);
511
+ const anchorElementRef = useMenuAnchorRef(resolution, setResolution, anchorClassName, parent);
511
512
  const closeTypeahead = React.useCallback(() => {
512
513
  setResolution(null);
513
514
  if (onClose != null && resolution !== null) {
@@ -47,6 +47,11 @@ export type MenuRenderFn<TOption> = (
47
47
  matchingString: string,
48
48
  ) => React.Portal | React.MixedElement | null;
49
49
 
50
+ declare export function getScrollParent(
51
+ element: HTMLElement,
52
+ includeHidden: boolean,
53
+ ): HTMLElement | HTMLBodyElement;
54
+
50
55
  declare export function useBasicTypeaheadTriggerMatch(
51
56
  trigger: string,
52
57
  options: {minLength?: number, maxLength?: number},
@@ -4,22 +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"),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
7
+ 'use strict';var l=require("@lexical/react/LexicalComposerContext"),q=require("lexical"),y=require("react"),A=require("@lexical/utils"),B="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?y.useLayoutEffect:y.useEffect;class C{constructor(b){this.key=b;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(b){this.ref={current:b}}}
8
+ let D=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 E(b){var a=q.$getSelection();if(!q.$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 f=b.matchingString;b=b.replaceableString.length;for(let r=b;r<=f.length;r++)d.substr(-r)===f.substr(0,r)&&(b=r);b=c-b;if(0>b)return null;let n;0===b?[n]=a.splitText(c):[,n]=a.splitText(b,c);return n}
10
+ function H(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 I(b,a){b=b.getBoundingClientRect();a=a.getBoundingClientRect();return b.top>a.top&&b.top<a.bottom}
11
+ function J(b,a,c,d){let [f]=l.useLexicalComposerContext();y.useEffect(()=>{if(null!=a&&null!=b){let n=f.getRootElement(),r=null!=n?H(n,!1):document.body,v=!1,p=I(a,r),e=function(){v||(window.requestAnimationFrame(function(){c();v=!1}),v=!0);const k=I(a,r);k!==p&&(p=k,null!=d&&d(k))},h=new ResizeObserver(c);window.addEventListener("resize",c);document.addEventListener("scroll",e,{capture:!0,passive:!0});h.observe(a);return()=>{h.unobserve(a);window.removeEventListener("resize",c);document.removeEventListener("scroll",
12
+ e,!0)}}},[a,f,d,c,b])}let K=q.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
13
+ function L({close:b,editor:a,anchorElementRef:c,resolution:d,options:f,menuRenderFn:n,onSelectOption:r,shouldSplitNodeWithQuery:v=!1,commandPriority:p=q.COMMAND_PRIORITY_LOW}){let [e,h]=y.useState(null);y.useEffect(()=>{h(0)},[d.match&&d.match.matchingString]);let k=y.useCallback(g=>{a.update(()=>{const m=null!=d.match&&v?E(d.match):null;r(g,m,b,d.match?d.match.matchingString:"")})},[a,v,d.match,r,b]),t=y.useCallback(g=>{const m=a.getRootElement();null!==m&&(m.setAttribute("aria-activedescendant",
14
+ "typeahead-item-"+g),h(g))},[a]);y.useEffect(()=>()=>{let g=a.getRootElement();null!==g&&g.removeAttribute("aria-activedescendant")},[a]);B(()=>{null===f?h(null):null===e&&t(0)},[f,e,t]);y.useEffect(()=>A.mergeRegister(a.registerCommand(K,({option:g})=>g.ref&&null!=g.ref.current?(D(g.ref.current),!0):!1,p)),[a,t,p]);y.useEffect(()=>A.mergeRegister(a.registerCommand(q.KEY_ARROW_DOWN_COMMAND,g=>{if(null!==f&&f.length&&null!==e){let m=e!==f.length-1?e+1:0;t(m);let w=f[m];null!=w.ref&&w.ref.current&&
15
+ a.dispatchCommand(K,{index:m,option:w});g.preventDefault();g.stopImmediatePropagation()}return!0},p),a.registerCommand(q.KEY_ARROW_UP_COMMAND,g=>{if(null!==f&&f.length&&null!==e){var m=0!==e?e-1:f.length-1;t(m);m=f[m];null!=m.ref&&m.ref.current&&D(m.ref.current);g.preventDefault();g.stopImmediatePropagation()}return!0},p),a.registerCommand(q.KEY_ESCAPE_COMMAND,g=>{g.preventDefault();g.stopImmediatePropagation();b();return!0},p),a.registerCommand(q.KEY_TAB_COMMAND,g=>{if(null===f||null===e||null==
16
+ f[e])return!1;g.preventDefault();g.stopImmediatePropagation();k(f[e]);return!0},p),a.registerCommand(q.KEY_ENTER_COMMAND,g=>{if(null===f||null===e||null==f[e])return!1;null!==g&&(g.preventDefault(),g.stopImmediatePropagation());k(f[e]);return!0},p)),[k,b,a,f,e,t,p]);let u=y.useMemo(()=>({options:f,selectOptionAndCleanUp:k,selectedIndex:e,setHighlightedIndex:h}),[k,e,f]);return n(c,u,d.match?d.match.matchingString:"")}
17
+ function M(b,a,c,d=document.body){let [f]=l.useLexicalComposerContext(),n=y.useRef(document.createElement("div")),r=y.useCallback(()=>{n.current.style.top=n.current.style.bottom;const p=f.getRootElement(),e=n.current;var h=e.firstChild;if(null!==p&&null!==b){const {left:t,top:u,width:g,height:m}=b.getRect();e.style.top=`${u+window.pageYOffset+n.current.offsetHeight+3}px`;e.style.left=`${t+window.pageXOffset}px`;e.style.height=`${m}px`;e.style.width=`${g}px`;if(null!==h){h.style.top=`${u}`;var k=h.getBoundingClientRect();
18
+ h=k.height;k=k.width;const w=p.getBoundingClientRect();t+k>w.right&&(e.style.left=`${w.right-k+window.pageXOffset}px`);(u+h>window.innerHeight||u+h>w.bottom)&&u-w.top>h&&(e.style.top=`${u-h+window.pageYOffset-m}px`)}e.isConnected||(null!=c&&(e.className=c),e.setAttribute("aria-label","Typeahead menu"),e.setAttribute("id","typeahead-menu"),e.setAttribute("role","listbox"),e.style.display="block",e.style.position="absolute",d.append(e));n.current=e;p.setAttribute("aria-controls","typeahead-menu")}},
19
+ [f,b,c,d]);y.useEffect(()=>{let p=f.getRootElement();if(null!==b)return r(),()=>{null!==p&&p.removeAttribute("aria-controls");let e=n.current;null!==e&&e.isConnected&&e.remove()}},[f,r,b]);let v=y.useCallback(p=>{null!==b&&(p||a(null))},[b,a]);J(b,n.current,r,v);return n}function N(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(f){return!1}return!0}
20
+ function O(b){let a=null;b.getEditorState().read(()=>{var c=q.$getSelection();if(q.$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 P(b,a){return 0!==a?!1:b.getEditorState().read(()=>{var c=q.$getSelection();return q.$isRangeSelection(c)?(c=c.anchor.getNode().getPreviousSibling(),q.$isTextNode(c)&&c.isTextEntity()):!1})}function Q(b){y.startTransition?y.startTransition(b):b()}
21
+ let R=q.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
22
+ exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,onOpen:d,onClose:f,menuRenderFn:n,triggerFn:r,anchorClassName:v,commandPriority:p=q.COMMAND_PRIORITY_LOW,parent:e}){let [h]=l.useLexicalComposerContext(),[k,t]=y.useState(null);v=M(k,t,v,e);let u=y.useCallback(()=>{t(null);null!=f&&null!==k&&f()},[f,k]),g=y.useCallback(m=>{t(m);null!=d&&null===k&&d(m)},[d,k]);y.useEffect(()=>{let m=h.registerUpdateListener(()=>{h.getEditorState().read(()=>{const w=h._window||window,
23
+ z=w.document.createRange(),F=q.$getSelection(),G=O(h);if(q.$isRangeSelection(F)&&F.isCollapsed()&&null!==G&&null!==z){var x=r(G,h);a(x?x.matchingString:null);null===x||P(h,x.leadOffset)||null===N(x.leadOffset,z,w)?u():Q(()=>g({getRect:()=>z.getBoundingClientRect(),match:x}))}else u()})});return()=>{m()}},[h,r,a,k,u,g]);return null===k||null===h?null:y.createElement(L,{close:u,resolution:k,editor:h,anchorElementRef:v,options:b,menuRenderFn:n,shouldSplitNodeWithQuery:!0,onSelectOption:c,commandPriority:p})};
24
+ exports.MenuOption=C;exports.PUNCTUATION="\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";exports.SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND=R;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 f=d[1],n=d[3];if(n.length>=a)return{leadOffset:d.index+f.length,matchingString:n,replaceableString:d[2]}}return null},[c,a,b])};exports.useDynamicPositioning=J
package/package.json CHANGED
@@ -8,29 +8,29 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.12.6",
11
+ "version": "0.13.0",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.12.6",
14
- "@lexical/code": "0.12.6",
15
- "@lexical/dragon": "0.12.6",
16
- "@lexical/hashtag": "0.12.6",
17
- "@lexical/history": "0.12.6",
18
- "@lexical/link": "0.12.6",
19
- "@lexical/list": "0.12.6",
20
- "@lexical/mark": "0.12.6",
21
- "@lexical/markdown": "0.12.6",
22
- "@lexical/overflow": "0.12.6",
23
- "@lexical/plain-text": "0.12.6",
24
- "@lexical/rich-text": "0.12.6",
25
- "@lexical/selection": "0.12.6",
26
- "@lexical/table": "0.12.6",
27
- "@lexical/text": "0.12.6",
28
- "@lexical/utils": "0.12.6",
29
- "@lexical/yjs": "0.12.6",
13
+ "@lexical/clipboard": "0.13.0",
14
+ "@lexical/code": "0.13.0",
15
+ "@lexical/dragon": "0.13.0",
16
+ "@lexical/hashtag": "0.13.0",
17
+ "@lexical/history": "0.13.0",
18
+ "@lexical/link": "0.13.0",
19
+ "@lexical/list": "0.13.0",
20
+ "@lexical/mark": "0.13.0",
21
+ "@lexical/markdown": "0.13.0",
22
+ "@lexical/overflow": "0.13.0",
23
+ "@lexical/plain-text": "0.13.0",
24
+ "@lexical/rich-text": "0.13.0",
25
+ "@lexical/selection": "0.13.0",
26
+ "@lexical/table": "0.13.0",
27
+ "@lexical/text": "0.13.0",
28
+ "@lexical/utils": "0.13.0",
29
+ "@lexical/yjs": "0.13.0",
30
30
  "react-error-boundary": "^3.1.4"
31
31
  },
32
32
  "peerDependencies": {
33
- "lexical": "0.12.6",
33
+ "lexical": "0.13.0",
34
34
  "react": ">=17.x",
35
35
  "react-dom": ">=17.x"
36
36
  },
@@ -46,5 +46,5 @@ export declare function LexicalMenu<TOption extends MenuOption>({ close, editor,
46
46
  onSelectOption: (option: TOption, textNodeContainingQuery: TextNode | null, closeMenu: () => void, matchingString: string) => void;
47
47
  commandPriority?: CommandListenerPriority;
48
48
  }): JSX.Element | null;
49
- export declare function useMenuAnchorRef(resolution: MenuResolution | null, setResolution: (r: MenuResolution | null) => void, className?: string): MutableRefObject<HTMLElement>;
49
+ export declare function useMenuAnchorRef(resolution: MenuResolution | null, setResolution: (r: MenuResolution | null) => void, className?: string, parent?: HTMLElement): MutableRefObject<HTMLElement>;
50
50
  export type TriggerFn = (text: string, editor: LexicalEditor) => MenuTextMatch | null;