@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.
- package/LexicalAutoFocusPlugin.dev.js +5 -0
- package/LexicalAutoFocusPlugin.prod.js +1 -1
- package/LexicalAutoLinkPlugin.dev.js +3 -2
- package/LexicalAutoLinkPlugin.prod.js +9 -9
- package/LexicalComposer.d.ts +3 -4
- package/LexicalContextMenuPlugin.d.ts +2 -1
- package/LexicalContextMenuPlugin.dev.js +6 -5
- package/LexicalContextMenuPlugin.prod.js +16 -16
- package/LexicalDecoratorBlockNode.js.flow +1 -1
- package/LexicalHorizontalRuleNode.js.flow +1 -1
- package/LexicalNodeMenuPlugin.d.ts +2 -1
- package/LexicalNodeMenuPlugin.dev.js +6 -5
- package/LexicalNodeMenuPlugin.prod.js +15 -15
- package/LexicalTablePlugin.dev.js +4 -4
- package/LexicalTablePlugin.prod.js +5 -6
- package/LexicalTreeView.dev.js +8 -5
- package/LexicalTreeView.prod.js +15 -15
- package/LexicalTypeaheadMenuPlugin.d.ts +2 -1
- package/LexicalTypeaheadMenuPlugin.dev.js +6 -5
- package/LexicalTypeaheadMenuPlugin.js.flow +5 -0
- package/LexicalTypeaheadMenuPlugin.prod.js +19 -19
- package/package.json +19 -19
- package/shared/LexicalMenu.d.ts +1 -1
|
@@ -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:
|
|
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
|
-
|
|
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,
|
|
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"),
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
m}a=(b=
|
|
12
|
-
function
|
|
13
|
-
function
|
|
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){
|
|
16
|
-
c,d)}let h
|
|
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])}}}
|
package/LexicalComposer.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
8
|
-
let B=
|
|
9
|
-
function C(
|
|
10
|
-
function D(
|
|
11
|
-
function F(
|
|
12
|
-
|
|
13
|
-
function H({close:
|
|
14
|
-
"typeahead-item-"+
|
|
15
|
-
a.dispatchCommand(G,{index:
|
|
16
|
-
|
|
17
|
-
function I(
|
|
18
|
-
|
|
19
|
-
[
|
|
20
|
-
exports.LexicalContextMenuPlugin=function({options:
|
|
21
|
-
|
|
22
|
-
commandPriority:
|
|
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
|
|
@@ -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
|
-
):
|
|
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
|
-
|
|
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"),
|
|
8
|
-
let B=b=>{const a=document.getElementById("typeahead-menu");if(a){var
|
|
9
|
-
function C(b){var a=
|
|
10
|
-
function D(b,a){let
|
|
11
|
-
function F(b,a,
|
|
12
|
-
|
|
13
|
-
function H({close:b,editor:a,anchorElementRef:
|
|
14
|
-
"typeahead-item-"+e),
|
|
15
|
-
a.dispatchCommand(G,{index:
|
|
16
|
-
|
|
17
|
-
function I(b,a,
|
|
18
|
-
|
|
19
|
-
[
|
|
20
|
-
exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:
|
|
21
|
-
null==a&&null!=
|
|
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] =
|
|
107
|
-
const [gridMap] =
|
|
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 (!
|
|
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 (!
|
|
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
|
|
8
|
-
exports.TablePlugin=function({hasCellMerge:
|
|
9
|
-
{let a=new Map,e=
|
|
10
|
-
[d,
|
|
11
|
-
|
|
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}
|
package/LexicalTreeView.dev.js
CHANGED
|
@@ -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
|
|
258
|
-
return `:
|
|
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.$
|
|
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
|
|
451
|
-
|
|
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;
|
package/LexicalTreeView.prod.js
CHANGED
|
@@ -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"),
|
|
8
|
-
function U(a){let [b,c]=O.useState([]);O.useEffect(()=>{let
|
|
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
|
|
10
|
-
function W(a,b,c){let
|
|
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(
|
|
12
|
-
h=A+`${H} ${F} ${y} ${
|
|
13
|
-
h+="\n\n editor:";h+=`\n \u2514 namespace ${
|
|
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:
|
|
17
|
-
d.offset]:c===
|
|
18
|
-
"\n"}function X(a,b){let c=Array(b++ +1).join(" "),
|
|
19
|
-
exports.TreeView=function({treeTypeButtonClassName:a,timeTravelButtonClassName:b,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:
|
|
20
|
-
|
|
21
|
-
z()},h[G+1][0]-h[G][0])};z();return()=>{clearTimeout(f)}}},[h,n,
|
|
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=
|
|
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,
|
|
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
|
-
|
|
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
|
|
8
|
-
let
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
"typeahead-item-"+g),
|
|
15
|
-
a.dispatchCommand(
|
|
16
|
-
e
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
[
|
|
20
|
-
function
|
|
21
|
-
let
|
|
22
|
-
exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,onOpen:d,onClose:
|
|
23
|
-
|
|
24
|
-
exports.MenuOption=
|
|
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
|
|
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.
|
|
11
|
+
"version": "0.13.0",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.
|
|
14
|
-
"@lexical/code": "0.
|
|
15
|
-
"@lexical/dragon": "0.
|
|
16
|
-
"@lexical/hashtag": "0.
|
|
17
|
-
"@lexical/history": "0.
|
|
18
|
-
"@lexical/link": "0.
|
|
19
|
-
"@lexical/list": "0.
|
|
20
|
-
"@lexical/mark": "0.
|
|
21
|
-
"@lexical/markdown": "0.
|
|
22
|
-
"@lexical/overflow": "0.
|
|
23
|
-
"@lexical/plain-text": "0.
|
|
24
|
-
"@lexical/rich-text": "0.
|
|
25
|
-
"@lexical/selection": "0.
|
|
26
|
-
"@lexical/table": "0.
|
|
27
|
-
"@lexical/text": "0.
|
|
28
|
-
"@lexical/utils": "0.
|
|
29
|
-
"@lexical/yjs": "0.
|
|
13
|
+
"@lexical/clipboard": "0.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.
|
|
33
|
+
"lexical": "0.13.0",
|
|
34
34
|
"react": ">=17.x",
|
|
35
35
|
"react-dom": ">=17.x"
|
|
36
36
|
},
|
package/shared/LexicalMenu.d.ts
CHANGED
|
@@ -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;
|