@lexical/react 0.6.0 → 0.6.1-next.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.
|
@@ -13,8 +13,8 @@ import type {LexicalEditor} from 'lexical';
|
|
|
13
13
|
import * as React from 'react';
|
|
14
14
|
|
|
15
15
|
type ErrorBoundaryProps = $ReadOnly<{
|
|
16
|
-
children: React
|
|
17
|
-
onError
|
|
16
|
+
children: React$Node,
|
|
17
|
+
onError: (error: Error) => void,
|
|
18
18
|
}>;
|
|
19
19
|
export type ErrorBoundaryType = React.AbstractComponent<ErrorBoundaryProps>;
|
|
20
20
|
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
declare type
|
|
8
|
+
export declare type LexicalErrorBoundaryProps = {
|
|
9
9
|
children: JSX.Element;
|
|
10
10
|
onError: (error: Error) => void;
|
|
11
11
|
};
|
|
12
|
-
export default function LexicalErrorBoundary({ children, onError, }:
|
|
13
|
-
export {};
|
|
12
|
+
export default function LexicalErrorBoundary({ children, onError, }: LexicalErrorBoundaryProps): JSX.Element;
|
|
@@ -4,11 +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
|
+
* @flow strict
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
|
-
type
|
|
10
|
-
children:
|
|
10
|
+
export type LexicalErrorBoundaryProps = $ReadOnly<{
|
|
11
|
+
children: React$Node,
|
|
11
12
|
onError: (error: Error) => void,
|
|
12
13
|
}>;
|
|
13
14
|
|
|
14
|
-
declare export default function LexicalErrorBoundary(
|
|
15
|
+
declare export default function LexicalErrorBoundary(
|
|
16
|
+
props: LexicalErrorBoundaryProps,
|
|
17
|
+
): React$Node;
|
|
@@ -545,11 +545,9 @@ function LexicalTypeaheadMenuPlugin({
|
|
|
545
545
|
}
|
|
546
546
|
}, [onOpen, resolution]);
|
|
547
547
|
React.useEffect(() => {
|
|
548
|
-
let activeRange = document.createRange();
|
|
549
|
-
|
|
550
548
|
const updateListener = () => {
|
|
551
549
|
editor.getEditorState().read(() => {
|
|
552
|
-
const range =
|
|
550
|
+
const range = document.createRange();
|
|
553
551
|
const selection = lexical.$getSelection();
|
|
554
552
|
const text = getQueryTextForSearch(editor);
|
|
555
553
|
|
|
@@ -579,7 +577,6 @@ function LexicalTypeaheadMenuPlugin({
|
|
|
579
577
|
|
|
580
578
|
const removeUpdateListener = editor.registerUpdateListener(updateListener);
|
|
581
579
|
return () => {
|
|
582
|
-
activeRange = null;
|
|
583
580
|
removeUpdateListener();
|
|
584
581
|
};
|
|
585
582
|
}, [editor, triggerFn, onQueryChange, resolution, closeTypeahead, openTypeahead]);
|
|
@@ -4,23 +4,23 @@
|
|
|
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"),n=require("@lexical/utils"),w=require("lexical"),x=require("react"),
|
|
8
|
-
let
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
function
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
[a]);
|
|
17
|
-
a.registerCommand(w.KEY_ARROW_UP_COMMAND,h=>{if(null!==f&&f.length&&null!==g){var
|
|
18
|
-
|
|
19
|
-
function
|
|
20
|
-
"listbox"),d.style.display="block",d.style.position="absolute",document.body.append(d));f.current=d;g.setAttribute("aria-controls","typeahead-menu")}},[e,b,c]);x.useEffect(()=>{let g=e.getRootElement();if(null!==b)return q(),()=>{null!==g&&g.removeAttribute("aria-controls");let d=f.current;null!==d&&d.isConnected&&d.remove()}},[e,q,b]);let p=x.useCallback(g=>{null!==b&&(g||a(null))},[b,a]);
|
|
21
|
-
exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:c,onOpen:e,onSelectOption:f,menuRenderFn:q,anchorClassName:p}){let [g]=k.useLexicalComposerContext(),[d,
|
|
22
|
-
match:{leadOffset:u.length,matchingString:u,replaceableString:u}}))}}):null==a&&null!=d&&r()},[r,g,a,t,d]);return null===d||null===g?null:x.createElement(
|
|
23
|
-
exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,onOpen:e,onClose:f,menuRenderFn:q,triggerFn:p,anchorClassName:g}){let [d]=k.useLexicalComposerContext(),[
|
|
24
|
-
|
|
25
|
-
exports.SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND=
|
|
26
|
-
exports.useDynamicPositioning=
|
|
7
|
+
'use strict';var k=require("@lexical/react/LexicalComposerContext"),n=require("@lexical/utils"),w=require("lexical"),x=require("react"),y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?x.useLayoutEffect:x.useEffect;class z{constructor(b){this.key=b;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(b){this.ref={current:b}}}
|
|
8
|
+
let A=b=>{var a=document.getElementById("typeahead-menu");if(a){a=a.getBoundingClientRect();const c=b.getBoundingClientRect();c.bottom>a.bottom?b.scrollIntoView(!1):c.top<a.top&&b.scrollIntoView()}};function B(b,a){var c=window.getSelection();if(null===c||!c.isCollapsed)return!1;let e=c.anchorNode;c=c.anchorOffset;if(null==e||null==c)return!1;try{a.setStart(e,b),a.setEnd(e,c)}catch(f){return!1}return!0}
|
|
9
|
+
function C(b){let a=null;b.getEditorState().read(()=>{var c=w.$getSelection();if(w.$isRangeSelection(c)){var e=c.anchor;"text"!==e.type?a=null:(c=e.getNode(),c.isSimpleText()?(e=e.offset,a=c.getTextContent().slice(0,e)):a=null)}});return a}
|
|
10
|
+
function D(b,a){b=w.$getSelection();if(!w.$isRangeSelection(b)||!b.isCollapsed())return null;var c=b.anchor;if("text"!==c.type)return null;b=c.getNode();if(!b.isSimpleText())return null;c=c.offset;let e=b.getTextContent().slice(0,c);var f=a.matchingString;a=a.replaceableString.length;for(let p=a;p<=f.length;p++)e.substr(-p)===f.substr(0,p)&&(a=p);a=c-a;if(0>a)return null;let q;0===a?[q]=b.splitText(c):[,q]=b.splitText(a,c);return q}
|
|
11
|
+
function E(b,a){return 0!==a?!1:b.getEditorState().read(()=>{var c=w.$getSelection();return w.$isRangeSelection(c)?(c=c.anchor.getNode().getPreviousSibling(),w.$isTextNode(c)&&c.isTextEntity()):!1})}function F(b){x.startTransition?x.startTransition(b):b()}
|
|
12
|
+
function I(b,a){let c=getComputedStyle(b),e="absolute"===c.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===c.position)return document.body;for(;b=b.parentElement;)if(c=getComputedStyle(b),(!e||"static"!==c.position)&&a.test(c.overflow+c.overflowY+c.overflowX))return b;return document.body}function J(b,a){b=b.getBoundingClientRect();a=a.getBoundingClientRect();return b.top>a.top&&b.top<a.bottom}
|
|
13
|
+
function K(b,a,c,e){let [f]=k.useLexicalComposerContext();x.useEffect(()=>{if(null!=a&&null!=b){let q=f.getRootElement(),p=null!=q?I(q,!1):document.body,g=!1,d=J(a,p),l=function(){g||(window.requestAnimationFrame(function(){c();g=!1}),g=!0);const t=J(a,p);t!==d&&(d=t,null!=e&&e(t))},r=new ResizeObserver(c);window.addEventListener("resize",c);document.addEventListener("scroll",l,{capture:!0,passive:!0});r.observe(a);return()=>{r.unobserve(a);window.removeEventListener("resize",c);document.removeEventListener("scroll",
|
|
14
|
+
l)}}},[a,f,e,c,b])}let L=w.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
|
|
15
|
+
function M({close:b,editor:a,anchorElementRef:c,resolution:e,options:f,menuRenderFn:q,onSelectOption:p}){let [g,d]=x.useState(null);x.useEffect(()=>{d(0)},[e.match.matchingString]);let l=x.useCallback(h=>{a.update(()=>{const m=D(a,e.match);p(h,m,b,e.match.matchingString)})},[b,a,e.match,p]),r=x.useCallback(h=>{const m=a.getRootElement();null!==m&&(m.setAttribute("aria-activedescendant","typeahead-item-"+h),d(h))},[a]);x.useEffect(()=>()=>{let h=a.getRootElement();null!==h&&h.removeAttribute("aria-activedescendant")},
|
|
16
|
+
[a]);y(()=>{null===f?d(null):null===g&&r(0)},[f,g,r]);x.useEffect(()=>n.mergeRegister(a.registerCommand(L,({option:h})=>h.ref&&null!=h.ref.current?(A(h.ref.current),!0):!1,w.COMMAND_PRIORITY_LOW)),[a,r]);x.useEffect(()=>n.mergeRegister(a.registerCommand(w.KEY_ARROW_DOWN_COMMAND,h=>{if(null!==f&&f.length&&null!==g){let m=g!==f.length-1?g+1:0;r(m);let u=f[m];null!=u.ref&&u.ref.current&&a.dispatchCommand(L,{index:m,option:u});h.preventDefault();h.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_CRITICAL),
|
|
17
|
+
a.registerCommand(w.KEY_ARROW_UP_COMMAND,h=>{if(null!==f&&f.length&&null!==g){var m=0!==g?g-1:f.length-1;r(m);m=f[m];null!=m.ref&&m.ref.current&&A(m.ref.current);h.preventDefault();h.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_CRITICAL),a.registerCommand(w.KEY_ESCAPE_COMMAND,h=>{h.preventDefault();h.stopImmediatePropagation();b();return!0},w.COMMAND_PRIORITY_CRITICAL),a.registerCommand(w.KEY_TAB_COMMAND,h=>{if(null===f||null===g||null==f[g])return!1;h.preventDefault();h.stopImmediatePropagation();
|
|
18
|
+
l(f[g]);return!0},w.COMMAND_PRIORITY_CRITICAL),a.registerCommand(w.KEY_ENTER_COMMAND,h=>{if(null===f||null===g||null==f[g])return!1;null!==h&&(h.preventDefault(),h.stopImmediatePropagation());l(f[g]);return!0},w.COMMAND_PRIORITY_CRITICAL)),[l,b,a,f,g,r]);let t=x.useMemo(()=>({options:f,selectOptionAndCleanUp:l,selectedIndex:g,setHighlightedIndex:d}),[l,g,f]);return q(c,t,e.match.matchingString)}
|
|
19
|
+
function N(b,a,c){let [e]=k.useLexicalComposerContext(),f=x.useRef(document.createElement("div")),q=x.useCallback(()=>{const g=e.getRootElement(),d=f.current;if(null!==g&&null!==b){const {left:l,top:r,width:t,height:h}=b.getRect();d.style.top=`${r+window.pageYOffset}px`;d.style.left=`${l+window.pageXOffset}px`;d.style.height=`${h}px`;d.style.width=`${t}px`;d.isConnected||(null!=c&&(d.className=c),d.setAttribute("aria-label","Typeahead menu"),d.setAttribute("id","typeahead-menu"),d.setAttribute("role",
|
|
20
|
+
"listbox"),d.style.display="block",d.style.position="absolute",document.body.append(d));f.current=d;g.setAttribute("aria-controls","typeahead-menu")}},[e,b,c]);x.useEffect(()=>{let g=e.getRootElement();if(null!==b)return q(),()=>{null!==g&&g.removeAttribute("aria-controls");let d=f.current;null!==d&&d.isConnected&&d.remove()}},[e,q,b]);let p=x.useCallback(g=>{null!==b&&(g||a(null))},[b,a]);K(b,f.current,q,p);return f}
|
|
21
|
+
exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:c,onOpen:e,onSelectOption:f,menuRenderFn:q,anchorClassName:p}){let [g]=k.useLexicalComposerContext(),[d,l]=x.useState(null);p=N(d,l,p);let r=x.useCallback(()=>{l(null);null!=c&&null!==d&&c()},[c,d]),t=x.useCallback(h=>{l(h);null!=e&&null===d&&e(h)},[e,d]);x.useEffect(()=>{a&&null==d?g.update(()=>{let h=w.$getNodeByKey(a),m=g.getElementByKey(a);if(null!=h&&null!=m){let u=h.getTextContent();F(()=>t({getRect:()=>m.getBoundingClientRect(),
|
|
22
|
+
match:{leadOffset:u.length,matchingString:u,replaceableString:u}}))}}):null==a&&null!=d&&r()},[r,g,a,t,d]);return null===d||null===g?null:x.createElement(M,{close:r,resolution:d,editor:g,anchorElementRef:p,options:b,menuRenderFn:q,onSelectOption:f})};
|
|
23
|
+
exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,onOpen:e,onClose:f,menuRenderFn:q,triggerFn:p,anchorClassName:g}){let [d]=k.useLexicalComposerContext(),[l,r]=x.useState(null);g=N(l,r,g);let t=x.useCallback(()=>{r(null);null!=f&&null!==l&&f()},[f,l]),h=x.useCallback(m=>{r(m);null!=e&&null===l&&e(m)},[e,l]);x.useEffect(()=>{let m=d.registerUpdateListener(()=>{d.getEditorState().read(()=>{const u=document.createRange(),G=w.$getSelection(),H=C(d);if(w.$isRangeSelection(G)&&
|
|
24
|
+
G.isCollapsed()&&null!==H&&null!==u){var v=p(H,d);a(v?v.matchingString:null);null===v||E(d,v.leadOffset)||null===B(v.leadOffset,u)?t():F(()=>h({getRect:()=>u.getBoundingClientRect(),match:v}))}else t()})});return()=>{m()}},[d,p,a,l,t,h]);return null===l||null===d?null:x.createElement(M,{close:t,resolution:l,editor:d,anchorElementRef:g,options:b,menuRenderFn:q,onSelectOption:c})};exports.PUNCTUATION="\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
|
|
25
|
+
exports.SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND=L;exports.TypeaheadOption=z;exports.getScrollParent=I;exports.useBasicTypeaheadTriggerMatch=function(b,{minLength:a=1,maxLength:c=75}){return x.useCallback(e=>{e=(new RegExp("(^|\\s|\\()(["+b+"]((?:[^"+(b+"\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;\\s]){0,")+c+"}))$")).exec(e);if(null!==e){let f=e[1],q=e[3];if(q.length>=a)return{leadOffset:e.index+f.length,matchingString:q,replaceableString:e[2]}}return null},[c,a,b])};
|
|
26
|
+
exports.useDynamicPositioning=K
|
package/package.json
CHANGED
|
@@ -8,29 +8,29 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.6.0",
|
|
11
|
+
"version": "0.6.1-next.0",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.6.0",
|
|
14
|
-
"@lexical/code": "0.6.0",
|
|
15
|
-
"@lexical/dragon": "0.6.0",
|
|
16
|
-
"@lexical/hashtag": "0.6.0",
|
|
17
|
-
"@lexical/history": "0.6.0",
|
|
18
|
-
"@lexical/link": "0.6.0",
|
|
19
|
-
"@lexical/list": "0.6.0",
|
|
20
|
-
"@lexical/mark": "0.6.0",
|
|
21
|
-
"@lexical/markdown": "0.6.0",
|
|
22
|
-
"@lexical/overflow": "0.6.0",
|
|
23
|
-
"@lexical/plain-text": "0.6.0",
|
|
24
|
-
"@lexical/rich-text": "0.6.0",
|
|
25
|
-
"@lexical/selection": "0.6.0",
|
|
26
|
-
"@lexical/table": "0.6.0",
|
|
27
|
-
"@lexical/text": "0.6.0",
|
|
28
|
-
"@lexical/utils": "0.6.0",
|
|
29
|
-
"@lexical/yjs": "0.6.0",
|
|
13
|
+
"@lexical/clipboard": "0.6.1-next.0",
|
|
14
|
+
"@lexical/code": "0.6.1-next.0",
|
|
15
|
+
"@lexical/dragon": "0.6.1-next.0",
|
|
16
|
+
"@lexical/hashtag": "0.6.1-next.0",
|
|
17
|
+
"@lexical/history": "0.6.1-next.0",
|
|
18
|
+
"@lexical/link": "0.6.1-next.0",
|
|
19
|
+
"@lexical/list": "0.6.1-next.0",
|
|
20
|
+
"@lexical/mark": "0.6.1-next.0",
|
|
21
|
+
"@lexical/markdown": "0.6.1-next.0",
|
|
22
|
+
"@lexical/overflow": "0.6.1-next.0",
|
|
23
|
+
"@lexical/plain-text": "0.6.1-next.0",
|
|
24
|
+
"@lexical/rich-text": "0.6.1-next.0",
|
|
25
|
+
"@lexical/selection": "0.6.1-next.0",
|
|
26
|
+
"@lexical/table": "0.6.1-next.0",
|
|
27
|
+
"@lexical/text": "0.6.1-next.0",
|
|
28
|
+
"@lexical/utils": "0.6.1-next.0",
|
|
29
|
+
"@lexical/yjs": "0.6.1-next.0",
|
|
30
30
|
"react-error-boundary": "^3.1.4"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"lexical": "0.6.0",
|
|
33
|
+
"lexical": "0.6.1-next.0",
|
|
34
34
|
"react": ">=17.x",
|
|
35
35
|
"react-dom": ">=17.x"
|
|
36
36
|
},
|