@lexical/react 0.7.7 → 0.7.8
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/LexicalTypeaheadMenuPlugin.dev.js +18 -14
- package/LexicalTypeaheadMenuPlugin.prod.js +18 -18
- package/package.json +19 -19
|
@@ -57,22 +57,26 @@ class TypeaheadOption {
|
|
|
57
57
|
|
|
58
58
|
const scrollIntoViewIfNeeded = target => {
|
|
59
59
|
const container = document.getElementById('typeahead-menu');
|
|
60
|
+
if (!container) return;
|
|
61
|
+
const typeaheadContainerNode = container.querySelector('.typeahead-popover');
|
|
62
|
+
if (!typeaheadContainerNode) return;
|
|
63
|
+
const typeaheadRect = typeaheadContainerNode.getBoundingClientRect();
|
|
64
|
+
|
|
65
|
+
if (typeaheadRect.top + typeaheadRect.height > window.innerHeight) {
|
|
66
|
+
typeaheadContainerNode.scrollIntoView({
|
|
67
|
+
block: 'center'
|
|
68
|
+
});
|
|
69
|
+
}
|
|
60
70
|
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const parentRect = parentNode.getBoundingClientRect();
|
|
66
|
-
|
|
67
|
-
if (parentRect.top + parentRect.height > window.innerHeight) {
|
|
68
|
-
parentNode.scrollIntoView(false);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
parentNode.scrollTop = target.offsetTop - target.clientHeight;
|
|
72
|
-
} else {
|
|
73
|
-
target.scrollIntoView(false);
|
|
74
|
-
}
|
|
71
|
+
if (typeaheadRect.top < 0) {
|
|
72
|
+
typeaheadContainerNode.scrollIntoView({
|
|
73
|
+
block: 'center'
|
|
74
|
+
});
|
|
75
75
|
}
|
|
76
|
+
|
|
77
|
+
target.scrollIntoView({
|
|
78
|
+
block: 'nearest'
|
|
79
|
+
});
|
|
76
80
|
};
|
|
77
81
|
|
|
78
82
|
function getTextUpToAnchor(selection) {
|
|
@@ -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"),y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?x.useLayoutEffect:x.useEffect;class z{constructor(
|
|
8
|
-
let A=
|
|
9
|
-
function C(
|
|
10
|
-
function D(
|
|
11
|
-
function E(
|
|
12
|
-
function I(
|
|
13
|
-
function K(
|
|
14
|
-
l)}}},[a,f,e,c
|
|
15
|
-
function M({close:
|
|
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(c){this.key=c;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(c){this.ref={current:c}}}
|
|
8
|
+
let A=c=>{var a=document.getElementById("typeahead-menu");if(a&&(a=a.querySelector(".typeahead-popover"))){var b=a.getBoundingClientRect();b.top+b.height>window.innerHeight&&a.scrollIntoView({block:"center"});0>b.top&&a.scrollIntoView({block:"center"});c.scrollIntoView({block:"nearest"})}};function B(c,a){var b=window.getSelection();if(null===b||!b.isCollapsed)return!1;let e=b.anchorNode;b=b.anchorOffset;if(null==e||null==b)return!1;try{a.setStart(e,c),a.setEnd(e,b)}catch(f){return!1}return!0}
|
|
9
|
+
function C(c){let a=null;c.getEditorState().read(()=>{var b=w.$getSelection();if(w.$isRangeSelection(b)){var e=b.anchor;"text"!==e.type?a=null:(b=e.getNode(),b.isSimpleText()?(e=e.offset,a=b.getTextContent().slice(0,e)):a=null)}});return a}
|
|
10
|
+
function D(c,a){c=w.$getSelection();if(!w.$isRangeSelection(c)||!c.isCollapsed())return null;var b=c.anchor;if("text"!==b.type)return null;c=b.getNode();if(!c.isSimpleText())return null;b=b.offset;let e=c.getTextContent().slice(0,b);var 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=b-a;if(0>a)return null;let q;0===a?[q]=c.splitText(b):[,q]=c.splitText(a,b);return q}
|
|
11
|
+
function E(c,a){return 0!==a?!1:c.getEditorState().read(()=>{var b=w.$getSelection();return w.$isRangeSelection(b)?(b=b.anchor.getNode().getPreviousSibling(),w.$isTextNode(b)&&b.isTextEntity()):!1})}function F(c){x.startTransition?x.startTransition(c):c()}
|
|
12
|
+
function I(c,a){let b=getComputedStyle(c),e="absolute"===b.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===b.position)return document.body;for(;c=c.parentElement;)if(b=getComputedStyle(c),(!e||"static"!==b.position)&&a.test(b.overflow+b.overflowY+b.overflowX))return c;return document.body}function J(c,a){c=c.getBoundingClientRect();a=a.getBoundingClientRect();return c.top>a.top&&c.top<a.bottom}
|
|
13
|
+
function K(c,a,b,e){let [f]=k.useLexicalComposerContext();x.useEffect(()=>{if(null!=a&&null!=c){let q=f.getRootElement(),p=null!=q?I(q,!1):document.body,g=!1,d=J(a,p),l=function(){g||(window.requestAnimationFrame(function(){b();g=!1}),g=!0);const t=J(a,p);t!==d&&(d=t,null!=e&&e(t))},r=new ResizeObserver(b);window.addEventListener("resize",b);document.addEventListener("scroll",l,{capture:!0,passive:!0});r.observe(a);return()=>{r.unobserve(a);window.removeEventListener("resize",b);document.removeEventListener("scroll",
|
|
14
|
+
l)}}},[a,f,e,b,c])}let L=w.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
|
|
15
|
+
function M({close:c,editor:a,anchorElementRef:b,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,c,e.match.matchingString)})},[c,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
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_LOW),
|
|
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_LOW),a.registerCommand(w.KEY_ESCAPE_COMMAND,h=>{h.preventDefault();h.stopImmediatePropagation();
|
|
18
|
-
l(f[g]);return!0},w.COMMAND_PRIORITY_LOW),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_LOW)),[l,
|
|
19
|
-
function N(
|
|
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
|
|
21
|
-
exports.LexicalNodeMenuPlugin=function({options:
|
|
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:
|
|
23
|
-
exports.LexicalTypeaheadMenuPlugin=function({options:
|
|
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:
|
|
25
|
-
exports.SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND=L;exports.TypeaheadOption=z;exports.getScrollParent=I;exports.useBasicTypeaheadTriggerMatch=function(
|
|
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_LOW),a.registerCommand(w.KEY_ESCAPE_COMMAND,h=>{h.preventDefault();h.stopImmediatePropagation();c();return!0},w.COMMAND_PRIORITY_LOW),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_LOW),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_LOW)),[l,c,a,f,g,r]);let t=x.useMemo(()=>({options:f,selectOptionAndCleanUp:l,selectedIndex:g,setHighlightedIndex:d}),[l,g,f]);return q(b,t,e.match.matchingString)}
|
|
19
|
+
function N(c,a,b){let [e]=k.useLexicalComposerContext(),f=x.useRef(document.createElement("div")),q=x.useCallback(()=>{const g=e.getRootElement(),d=f.current;if(null!==g&&null!==c){const {left:l,top:r,width:t,height:h}=c.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!=b&&(d.className=b),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,c,b]);x.useEffect(()=>{let g=e.getRootElement();if(null!==c)return q(),()=>{null!==g&&g.removeAttribute("aria-controls");let d=f.current;null!==d&&d.isConnected&&d.remove()}},[e,q,c]);let p=x.useCallback(g=>{null!==c&&(g||a(null))},[c,a]);K(c,f.current,q,p);return f}
|
|
21
|
+
exports.LexicalNodeMenuPlugin=function({options:c,nodeKey:a,onClose:b,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!=b&&null!==d&&b()},[b,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:c,menuRenderFn:q,onSelectOption:f})};
|
|
23
|
+
exports.LexicalTypeaheadMenuPlugin=function({options:c,onQueryChange:a,onSelectOption:b,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:c,menuRenderFn:q,onSelectOption:b})};exports.PUNCTUATION="\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
|
|
25
|
+
exports.SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND=L;exports.TypeaheadOption=z;exports.getScrollParent=I;exports.useBasicTypeaheadTriggerMatch=function(c,{minLength:a=1,maxLength:b=75}){return x.useCallback(e=>{e=(new RegExp("(^|\\s|\\()(["+c+"]((?:[^"+(c+"\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;\\s]){0,")+b+"}))$")).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},[b,a,c])};
|
|
26
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.7.
|
|
11
|
+
"version": "0.7.8",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.7.
|
|
14
|
-
"@lexical/code": "0.7.
|
|
15
|
-
"@lexical/dragon": "0.7.
|
|
16
|
-
"@lexical/hashtag": "0.7.
|
|
17
|
-
"@lexical/history": "0.7.
|
|
18
|
-
"@lexical/link": "0.7.
|
|
19
|
-
"@lexical/list": "0.7.
|
|
20
|
-
"@lexical/mark": "0.7.
|
|
21
|
-
"@lexical/markdown": "0.7.
|
|
22
|
-
"@lexical/overflow": "0.7.
|
|
23
|
-
"@lexical/plain-text": "0.7.
|
|
24
|
-
"@lexical/rich-text": "0.7.
|
|
25
|
-
"@lexical/selection": "0.7.
|
|
26
|
-
"@lexical/table": "0.7.
|
|
27
|
-
"@lexical/text": "0.7.
|
|
28
|
-
"@lexical/utils": "0.7.
|
|
29
|
-
"@lexical/yjs": "0.7.
|
|
13
|
+
"@lexical/clipboard": "0.7.8",
|
|
14
|
+
"@lexical/code": "0.7.8",
|
|
15
|
+
"@lexical/dragon": "0.7.8",
|
|
16
|
+
"@lexical/hashtag": "0.7.8",
|
|
17
|
+
"@lexical/history": "0.7.8",
|
|
18
|
+
"@lexical/link": "0.7.8",
|
|
19
|
+
"@lexical/list": "0.7.8",
|
|
20
|
+
"@lexical/mark": "0.7.8",
|
|
21
|
+
"@lexical/markdown": "0.7.8",
|
|
22
|
+
"@lexical/overflow": "0.7.8",
|
|
23
|
+
"@lexical/plain-text": "0.7.8",
|
|
24
|
+
"@lexical/rich-text": "0.7.8",
|
|
25
|
+
"@lexical/selection": "0.7.8",
|
|
26
|
+
"@lexical/table": "0.7.8",
|
|
27
|
+
"@lexical/text": "0.7.8",
|
|
28
|
+
"@lexical/utils": "0.7.8",
|
|
29
|
+
"@lexical/yjs": "0.7.8",
|
|
30
30
|
"react-error-boundary": "^3.1.4"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"lexical": "0.7.
|
|
33
|
+
"lexical": "0.7.8",
|
|
34
34
|
"react": ">=17.x",
|
|
35
35
|
"react-dom": ">=17.x"
|
|
36
36
|
},
|