@lexical/react 0.3.9 → 0.4.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/DEPRECATED_useLexical.dev.js +2 -2
- package/DEPRECATED_useLexical.prod.js +2 -2
- package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +2 -2
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +2 -2
- package/DEPRECATED_useLexicalEditor.dev.js +2 -2
- package/DEPRECATED_useLexicalEditor.prod.js +2 -2
- package/LexicalAutoEmbedPlugin.d.ts +1 -1
- package/LexicalAutoEmbedPlugin.dev.js +3 -337
- package/LexicalAutoEmbedPlugin.js.flow +72 -0
- package/LexicalAutoEmbedPlugin.prod.js +5 -15
- package/LexicalCheckListPlugin.dev.js +2 -2
- package/LexicalCheckListPlugin.prod.js +2 -2
- package/LexicalCollaborationPlugin.dev.js +2 -1
- package/LexicalCollaborationPlugin.js.flow +1 -16
- package/LexicalComposer.d.ts +1 -1
- package/LexicalComposer.dev.js +3 -3
- package/LexicalComposer.prod.js +1 -1
- package/LexicalContentEditable.dev.js +11 -11
- package/LexicalContentEditable.prod.js +2 -2
- package/LexicalHorizontalRuleNode.dev.js +47 -3
- package/LexicalHorizontalRuleNode.prod.js +5 -3
- package/LexicalMarkdownShortcutPlugin.d.ts +1 -0
- package/LexicalMarkdownShortcutPlugin.dev.js +2 -0
- package/LexicalMarkdownShortcutPlugin.js.flow +2 -0
- package/LexicalMarkdownShortcutPlugin.prod.js +2 -2
- package/LexicalOnChangePlugin.dev.js +1 -1
- package/LexicalOnChangePlugin.js.flow +1 -1
- package/LexicalPlainTextPlugin.dev.js +2 -2
- package/LexicalPlainTextPlugin.prod.js +2 -2
- package/LexicalRichTextPlugin.dev.js +2 -2
- package/LexicalRichTextPlugin.prod.js +2 -2
- package/LexicalTypeaheadMenuPlugin.d.ts +3 -3
- package/LexicalTypeaheadMenuPlugin.dev.js +12 -13
- package/LexicalTypeaheadMenuPlugin.js.flow +99 -0
- package/LexicalTypeaheadMenuPlugin.prod.js +14 -14
- package/package.json +19 -19
package/LexicalComposer.dev.js
CHANGED
|
@@ -57,10 +57,10 @@ function LexicalComposer({
|
|
|
57
57
|
|
|
58
58
|
if (editor === null) {
|
|
59
59
|
const newEditor = lexical.createEditor({
|
|
60
|
+
editable: false,
|
|
60
61
|
namespace,
|
|
61
62
|
nodes,
|
|
62
63
|
onError: error => onError(error, newEditor),
|
|
63
|
-
readOnly: true,
|
|
64
64
|
theme
|
|
65
65
|
});
|
|
66
66
|
initializeEditor(newEditor, initialEditorState);
|
|
@@ -72,9 +72,9 @@ function LexicalComposer({
|
|
|
72
72
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
73
|
[]);
|
|
74
74
|
useLayoutEffect(() => {
|
|
75
|
-
const
|
|
75
|
+
const isEditable = initialConfig.editable;
|
|
76
76
|
const [editor] = composerContext;
|
|
77
|
-
editor.
|
|
77
|
+
editor.setEditable(isEditable || true); // We only do this for init
|
|
78
78
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
79
79
|
}, []);
|
|
80
80
|
return /*#__PURE__*/React.createElement(LexicalComposerContext.LexicalComposerContext.Provider, {
|
package/LexicalComposer.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var c=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),l=require("react"),m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?l.useLayoutEffect:l.useEffect;let n={tag:"history-merge"};
|
|
8
8
|
function p(b,a){if(null!==a&&void 0!==a&&null!==a)switch(typeof a){case "string":let d=b.parseEditorState(a);b.setEditorState(d,n);break;case "object":b.setEditorState(a,n);break;case "function":b.update(()=>{f.$getRoot().isEmpty()&&a(b)},n)}}
|
|
9
|
-
exports.LexicalComposer=function({initialConfig:b,children:a}){let d=l.useMemo(()=>{const {theme:e,namespace:g,editor__DEPRECATED:q,nodes:r,onError:t,editorState:u}=b,v=c.createLexicalComposerContext(null,e);let h=q||null;if(null===h){const k=f.createEditor({namespace:g,nodes:r,onError:w=>t(w,k),
|
|
9
|
+
exports.LexicalComposer=function({initialConfig:b,children:a}){let d=l.useMemo(()=>{const {theme:e,namespace:g,editor__DEPRECATED:q,nodes:r,onError:t,editorState:u}=b,v=c.createLexicalComposerContext(null,e);let h=q||null;if(null===h){const k=f.createEditor({editable:!1,namespace:g,nodes:r,onError:w=>t(w,k),theme:e});p(k,u);h=k}return[h,v]},[]);m(()=>{let e=b.editable,[g]=d;g.setEditable(e||!0)},[]);return l.createElement(c.LexicalComposerContext.Provider,{value:d},a)}
|
|
@@ -58,37 +58,37 @@ function ContentEditable({
|
|
|
58
58
|
testid
|
|
59
59
|
}) {
|
|
60
60
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
61
|
-
const [
|
|
61
|
+
const [isEditable, setEditable] = React.useState(true);
|
|
62
62
|
const ref = React.useCallback(rootElement => {
|
|
63
63
|
editor.setRootElement(rootElement);
|
|
64
64
|
}, [editor]);
|
|
65
65
|
useLayoutEffect(() => {
|
|
66
|
-
|
|
67
|
-
return editor.
|
|
68
|
-
|
|
66
|
+
setEditable(editor.isEditable());
|
|
67
|
+
return editor.registerEditableListener(currentIsEditable => {
|
|
68
|
+
setEditable(currentIsEditable);
|
|
69
69
|
});
|
|
70
70
|
}, [editor]);
|
|
71
71
|
return /*#__PURE__*/React.createElement("div", {
|
|
72
|
-
"aria-activedescendant":
|
|
73
|
-
"aria-autocomplete":
|
|
74
|
-
"aria-controls":
|
|
72
|
+
"aria-activedescendant": !isEditable ? null : ariaActiveDescendantID,
|
|
73
|
+
"aria-autocomplete": !isEditable ? null : ariaAutoComplete,
|
|
74
|
+
"aria-controls": !isEditable ? null : ariaControls,
|
|
75
75
|
"aria-describedby": ariaDescribedBy,
|
|
76
|
-
"aria-expanded":
|
|
76
|
+
"aria-expanded": !isEditable ? null : role === 'combobox' ? !!ariaExpanded : null,
|
|
77
77
|
"aria-label": ariaLabel,
|
|
78
78
|
"aria-labelledby": ariaLabelledBy,
|
|
79
79
|
"aria-multiline": ariaMultiline,
|
|
80
|
-
"aria-owns":
|
|
80
|
+
"aria-owns": !isEditable ? null : ariaOwneeID,
|
|
81
81
|
"aria-required": ariaRequired,
|
|
82
82
|
autoCapitalize: autoCapitalize !== undefined ? String(autoCapitalize) : undefined // @ts-ignore This is a valid attribute
|
|
83
83
|
,
|
|
84
84
|
autoComplete: autoComplete,
|
|
85
85
|
autoCorrect: autoCorrect !== undefined ? String(autoCorrect) : undefined,
|
|
86
86
|
className: className,
|
|
87
|
-
contentEditable:
|
|
87
|
+
contentEditable: isEditable,
|
|
88
88
|
"data-testid": testid,
|
|
89
89
|
id: id,
|
|
90
90
|
ref: ref,
|
|
91
|
-
role:
|
|
91
|
+
role: !isEditable ? undefined : role,
|
|
92
92
|
spellCheck: spellCheck,
|
|
93
93
|
style: style,
|
|
94
94
|
tabIndex: tabIndex
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var b=require("@lexical/react/LexicalComposerContext"),k=require("react"),l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?k.useLayoutEffect:k.useEffect;
|
|
8
|
-
exports.ContentEditable=function({ariaActiveDescendantID:m,ariaAutoComplete:n,ariaControls:p,ariaDescribedBy:q,ariaExpanded:r,ariaLabel:t,ariaLabelledBy:u,ariaMultiline:v,ariaOwneeID:w,ariaRequired:x,autoCapitalize:e,autoComplete:y,autoCorrect:f,className:z,id:A,role:g="textbox",spellCheck:B=!0,style:C,tabIndex:D,testid:E}){let [c]=b.useLexicalComposerContext(),[a,h]=k.useState(!0),F=k.useCallback(d=>{c.setRootElement(d)},[c]);l(()=>{h(c.
|
|
9
|
-
[c]);return k.createElement("div",{"aria-activedescendant":a?null
|
|
8
|
+
exports.ContentEditable=function({ariaActiveDescendantID:m,ariaAutoComplete:n,ariaControls:p,ariaDescribedBy:q,ariaExpanded:r,ariaLabel:t,ariaLabelledBy:u,ariaMultiline:v,ariaOwneeID:w,ariaRequired:x,autoCapitalize:e,autoComplete:y,autoCorrect:f,className:z,id:A,role:g="textbox",spellCheck:B=!0,style:C,tabIndex:D,testid:E}){let [c]=b.useLexicalComposerContext(),[a,h]=k.useState(!0),F=k.useCallback(d=>{c.setRootElement(d)},[c]);l(()=>{h(c.isEditable());return c.registerEditableListener(d=>{h(d)})},
|
|
9
|
+
[c]);return k.createElement("div",{"aria-activedescendant":a?m:null,"aria-autocomplete":a?n:null,"aria-controls":a?p:null,"aria-describedby":q,"aria-expanded":a?"combobox"===g?!!r:null:null,"aria-label":t,"aria-labelledby":u,"aria-multiline":v,"aria-owns":a?w:null,"aria-required":x,autoCapitalize:void 0!==e?String(e):void 0,autoComplete:y,autoCorrect:void 0!==f?String(f):void 0,className:z,contentEditable:a,"data-testid":E,id:A,ref:F,role:a?g:void 0,spellCheck:B,style:C,tabIndex:D})}
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
|
+
var useLexicalNodeSelection = require('@lexical/react/useLexicalNodeSelection');
|
|
11
|
+
var utils = require('@lexical/utils');
|
|
9
12
|
var lexical = require('lexical');
|
|
10
13
|
var React = require('react');
|
|
11
14
|
|
|
@@ -18,8 +21,47 @@ var React = require('react');
|
|
|
18
21
|
*/
|
|
19
22
|
const INSERT_HORIZONTAL_RULE_COMMAND = lexical.createCommand();
|
|
20
23
|
|
|
21
|
-
function HorizontalRuleComponent(
|
|
22
|
-
|
|
24
|
+
function HorizontalRuleComponent({
|
|
25
|
+
nodeKey
|
|
26
|
+
}) {
|
|
27
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
28
|
+
const hrRef = React.useRef(null);
|
|
29
|
+
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection.useLexicalNodeSelection(nodeKey);
|
|
30
|
+
const onDelete = React.useCallback(payload => {
|
|
31
|
+
if (isSelected && lexical.$isNodeSelection(lexical.$getSelection())) {
|
|
32
|
+
const event = payload;
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
const node = lexical.$getNodeByKey(nodeKey);
|
|
35
|
+
|
|
36
|
+
if ($isHorizontalRuleNode(node)) {
|
|
37
|
+
node.remove();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
setSelected(false);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
}, [isSelected, nodeKey, setSelected]);
|
|
45
|
+
React.useEffect(() => {
|
|
46
|
+
return utils.mergeRegister(editor.registerCommand(lexical.CLICK_COMMAND, event => {
|
|
47
|
+
const hrElem = hrRef.current;
|
|
48
|
+
|
|
49
|
+
if (event.target === hrElem) {
|
|
50
|
+
if (!event.shiftKey) {
|
|
51
|
+
clearSelection();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setSelected(!isSelected);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return false;
|
|
59
|
+
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_DELETE_COMMAND, onDelete, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, onDelete, lexical.COMMAND_PRIORITY_LOW));
|
|
60
|
+
}, [clearSelection, editor, isSelected, onDelete, setSelected]);
|
|
61
|
+
return /*#__PURE__*/React.createElement("hr", {
|
|
62
|
+
ref: hrRef,
|
|
63
|
+
className: isSelected ? 'selected' : undefined
|
|
64
|
+
});
|
|
23
65
|
}
|
|
24
66
|
|
|
25
67
|
class HorizontalRuleNode extends lexical.DecoratorNode {
|
|
@@ -61,7 +103,9 @@ class HorizontalRuleNode extends lexical.DecoratorNode {
|
|
|
61
103
|
}
|
|
62
104
|
|
|
63
105
|
decorate() {
|
|
64
|
-
return /*#__PURE__*/React.createElement(HorizontalRuleComponent,
|
|
106
|
+
return /*#__PURE__*/React.createElement(HorizontalRuleComponent, {
|
|
107
|
+
nodeKey: this.__key
|
|
108
|
+
});
|
|
65
109
|
}
|
|
66
110
|
|
|
67
111
|
}
|
|
@@ -4,6 +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
|
-
|
|
9
|
-
|
|
7
|
+
'use strict';var a=require("@lexical/react/LexicalComposerContext"),d=require("@lexical/react/useLexicalNodeSelection"),h=require("@lexical/utils"),n=require("lexical"),p=require("react");let q=n.createCommand();
|
|
8
|
+
function r({nodeKey:b}){let [f]=a.useLexicalComposerContext(),l=p.useRef(null),[e,g,m]=d.useLexicalNodeSelection(b),k=p.useCallback(c=>{e&&n.$isNodeSelection(n.$getSelection())&&(c.preventDefault(),c=n.$getNodeByKey(b),t(c)&&c.remove(),g(!1));return!1},[e,b,g]);p.useEffect(()=>h.mergeRegister(f.registerCommand(n.CLICK_COMMAND,c=>c.target===l.current?(c.shiftKey||m(),g(!e),!0):!1,n.COMMAND_PRIORITY_LOW),f.registerCommand(n.KEY_DELETE_COMMAND,k,n.COMMAND_PRIORITY_LOW),f.registerCommand(n.KEY_BACKSPACE_COMMAND,
|
|
9
|
+
k,n.COMMAND_PRIORITY_LOW)),[m,f,e,k,g]);return p.createElement("hr",{ref:l,className:e?"selected":void 0})}
|
|
10
|
+
class u extends n.DecoratorNode{static getType(){return"horizontalrule"}static clone(b){return new u(b.__key)}static importJSON(){return v()}exportJSON(){return{type:"horizontalrule",version:1}}createDOM(){let b=document.createElement("div");b.style.display="contents";return b}getTextContent(){return"\n"}isTopLevel(){return!0}updateDOM(){return!1}decorate(){return p.createElement(r,{nodeKey:this.__key})}}function v(){return new u}function t(b){return b instanceof u}
|
|
11
|
+
exports.$createHorizontalRuleNode=v;exports.$isHorizontalRuleNode=t;exports.HorizontalRuleNode=u;exports.INSERT_HORIZONTAL_RULE_COMMAND=q
|
|
@@ -19,6 +19,7 @@ var react = require('react');
|
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
21
|
const HR = {
|
|
22
|
+
dependencies: [LexicalHorizontalRuleNode.HorizontalRuleNode],
|
|
22
23
|
export: node => {
|
|
23
24
|
return LexicalHorizontalRuleNode.$isHorizontalRuleNode(node) ? '***' : null;
|
|
24
25
|
},
|
|
@@ -47,4 +48,5 @@ function MarkdownShortcutPlugin({
|
|
|
47
48
|
return null;
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
exports.DEFAULT_TRANSFORMERS = DEFAULT_TRANSFORMERS;
|
|
50
52
|
exports.MarkdownShortcutPlugin = MarkdownShortcutPlugin;
|
|
@@ -4,5 +4,5 @@
|
|
|
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/markdown"),d=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/react/LexicalHorizontalRuleNode"),f=require("react");let
|
|
8
|
-
exports.MarkdownShortcutPlugin=function({transformers:a=
|
|
7
|
+
'use strict';var c=require("@lexical/markdown"),d=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/react/LexicalHorizontalRuleNode"),f=require("react");let g=[{dependencies:[e.HorizontalRuleNode],export:a=>e.$isHorizontalRuleNode(a)?"***":null,regExp:/^(---|\*\*\*|___)\s?$/,replace:(a,b,k,h)=>{b=e.$createHorizontalRuleNode();h||null!=a.getNextSibling()?a.replace(b):a.insertBefore(b);b.selectNext()},type:"element"},...c.TRANSFORMERS];exports.DEFAULT_TRANSFORMERS=g;
|
|
8
|
+
exports.MarkdownShortcutPlugin=function({transformers:a=g}){let [b]=d.useLexicalComposerContext();f.useEffect(()=>c.registerMarkdownShortcuts(b,a),[b,a]);return null}
|
|
@@ -11,7 +11,7 @@ import type {EditorState, LexicalEditor} from 'lexical';
|
|
|
11
11
|
|
|
12
12
|
declare export function OnChangePlugin({
|
|
13
13
|
ignoreHistoryMergeTagChange?: boolean,
|
|
14
|
-
// TODO 0.
|
|
14
|
+
// TODO 0.5 remove
|
|
15
15
|
ignoreInitialChange?: boolean,
|
|
16
16
|
ignoreSelectionChange?: boolean,
|
|
17
17
|
onChange: (editorState: EditorState, editor: LexicalEditor) => void,
|
|
@@ -61,7 +61,7 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
61
61
|
*/
|
|
62
62
|
|
|
63
63
|
function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
64
|
-
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing(), editor.
|
|
64
|
+
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing(), editor.isEditable()));
|
|
65
65
|
return currentCanShowPlaceholder;
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -76,7 +76,7 @@ function useCanShowPlaceholder(editor) {
|
|
|
76
76
|
resetCanShowPlaceholder();
|
|
77
77
|
return utils.mergeRegister(editor.registerUpdateListener(() => {
|
|
78
78
|
resetCanShowPlaceholder();
|
|
79
|
-
}), editor.
|
|
79
|
+
}), editor.registerEditableListener(() => {
|
|
80
80
|
resetCanShowPlaceholder();
|
|
81
81
|
}));
|
|
82
82
|
}, [editor]);
|
|
@@ -4,7 +4,7 @@
|
|
|
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 d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),p=require("@lexical/dragon"),q=require("@lexical/plain-text"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function t(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.
|
|
8
|
-
function u(a){let [c,f]=h.useState(()=>t(a));r(()=>{function b(){let g=t(a);f(g)}b();return m.mergeRegister(a.registerUpdateListener(()=>{b()}),a.
|
|
7
|
+
'use strict';var d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),p=require("@lexical/dragon"),q=require("@lexical/plain-text"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function t(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isEditable()))}
|
|
8
|
+
function u(a){let [c,f]=h.useState(()=>t(a));r(()=>{function b(){let g=t(a);f(g)}b();return m.mergeRegister(a.registerUpdateListener(()=>{b()}),a.registerEditableListener(()=>{b()}))},[a]);return c}
|
|
9
9
|
function v(a){let [c,f]=h.useState(()=>a.getDecorators());r(()=>a.registerDecoratorListener(b=>{n.flushSync(()=>{f(b)})}),[a]);h.useEffect(()=>{f(a.getDecorators())},[a]);return h.useMemo(()=>{let b=[],g=Object.keys(c);for(let k=0;k<g.length;k++){var e=g[k];let w=c[e];e=a.getElementByKey(e);null!==e&&b.push(n.createPortal(w,e))}return b},[c,a])}function x(a,c){r(()=>m.mergeRegister(q.registerPlainText(a,c),p.registerDragonSupport(a)),[a])}
|
|
10
10
|
exports.PlainTextPlugin=function({contentEditable:a,placeholder:c,initialEditorState:f}){let [b]=d.useLexicalComposerContext(),g=u(b),e=v(b);x(b,f);return h.createElement(h.Fragment,null,a,g&&c,e)}
|
|
@@ -61,7 +61,7 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
61
61
|
*/
|
|
62
62
|
|
|
63
63
|
function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
64
|
-
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing(), editor.
|
|
64
|
+
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing(), editor.isEditable()));
|
|
65
65
|
return currentCanShowPlaceholder;
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -76,7 +76,7 @@ function useCanShowPlaceholder(editor) {
|
|
|
76
76
|
resetCanShowPlaceholder();
|
|
77
77
|
return utils.mergeRegister(editor.registerUpdateListener(() => {
|
|
78
78
|
resetCanShowPlaceholder();
|
|
79
|
-
}), editor.
|
|
79
|
+
}), editor.registerEditableListener(() => {
|
|
80
80
|
resetCanShowPlaceholder();
|
|
81
81
|
}));
|
|
82
82
|
}, [editor]);
|
|
@@ -4,7 +4,7 @@
|
|
|
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 d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),p=require("@lexical/dragon"),q=require("@lexical/rich-text"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function t(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.
|
|
8
|
-
function u(a){let [c,f]=h.useState(()=>t(a));r(()=>{function b(){let g=t(a);f(g)}b();return m.mergeRegister(a.registerUpdateListener(()=>{b()}),a.
|
|
7
|
+
'use strict';var d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),p=require("@lexical/dragon"),q=require("@lexical/rich-text"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function t(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isEditable()))}
|
|
8
|
+
function u(a){let [c,f]=h.useState(()=>t(a));r(()=>{function b(){let g=t(a);f(g)}b();return m.mergeRegister(a.registerUpdateListener(()=>{b()}),a.registerEditableListener(()=>{b()}))},[a]);return c}
|
|
9
9
|
function v(a){let [c,f]=h.useState(()=>a.getDecorators());r(()=>a.registerDecoratorListener(b=>{n.flushSync(()=>{f(b)})}),[a]);h.useEffect(()=>{f(a.getDecorators())},[a]);return h.useMemo(()=>{let b=[],g=Object.keys(c);for(let k=0;k<g.length;k++){var e=g[k];let w=c[e];e=a.getElementByKey(e);null!==e&&b.push(n.createPortal(w,e))}return b},[c,a])}function x(a,c){r(()=>m.mergeRegister(q.registerRichText(a,c),p.registerDragonSupport(a)),[a])}
|
|
10
10
|
exports.RichTextPlugin=function({contentEditable:a,placeholder:c,initialEditorState:f}){let [b]=d.useLexicalComposerContext(),g=u(b),e=v(b);x(b,f);return h.createElement(h.Fragment,null,a,g&&c,e)}
|
|
@@ -23,7 +23,7 @@ export declare class TypeaheadOption {
|
|
|
23
23
|
constructor(key: string);
|
|
24
24
|
setRefElement(element: HTMLElement | null): void;
|
|
25
25
|
}
|
|
26
|
-
declare type MenuRenderFn<TOption extends TypeaheadOption> = (anchorElement: HTMLElement | null, itemProps: {
|
|
26
|
+
export declare type MenuRenderFn<TOption extends TypeaheadOption> = (anchorElement: HTMLElement | null, itemProps: {
|
|
27
27
|
selectedIndex: number | null;
|
|
28
28
|
selectOptionAndCleanUp: (option: TOption) => void;
|
|
29
29
|
setHighlightedIndex: (index: number) => void;
|
|
@@ -32,14 +32,14 @@ export declare function useBasicTypeaheadTriggerMatch(trigger: string, { minLeng
|
|
|
32
32
|
minLength?: number;
|
|
33
33
|
maxLength?: number;
|
|
34
34
|
}): TriggerFn;
|
|
35
|
-
declare type TypeaheadMenuPluginArgs<TOption extends TypeaheadOption> = {
|
|
35
|
+
export declare type TypeaheadMenuPluginArgs<TOption extends TypeaheadOption> = {
|
|
36
36
|
onQueryChange: (matchingString: string | null) => void;
|
|
37
37
|
onSelectOption: (option: TOption, textNodeContainingQuery: TextNode | null, closeMenu: () => void, matchingString: string) => void;
|
|
38
38
|
options: Array<TOption>;
|
|
39
39
|
menuRenderFn: MenuRenderFn<TOption>;
|
|
40
40
|
triggerFn: TriggerFn;
|
|
41
41
|
};
|
|
42
|
-
declare type TriggerFn = (text: string, editor: LexicalEditor) => QueryMatch | null;
|
|
42
|
+
export declare type TriggerFn = (text: string, editor: LexicalEditor) => QueryMatch | null;
|
|
43
43
|
export declare function LexicalTypeaheadMenuPlugin<TOption extends TypeaheadOption>({ options, onQueryChange, onSelectOption, menuRenderFn, triggerFn, }: TypeaheadMenuPluginArgs<TOption>): JSX.Element | null;
|
|
44
44
|
declare type NodeMenuPluginArgs<TOption extends TypeaheadOption> = {
|
|
45
45
|
onSelectOption: (option: TOption, textNodeContainingQuery: TextNode | null, closeMenu: () => void, matchingString: string) => void;
|
|
@@ -276,7 +276,7 @@ function LexicalPopoverMenu({
|
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
return true;
|
|
279
|
-
}, lexical.
|
|
279
|
+
}, lexical.COMMAND_PRIORITY_NORMAL), editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, payload => {
|
|
280
280
|
const event = payload;
|
|
281
281
|
|
|
282
282
|
if (options !== null && options.length && selectedIndex !== null) {
|
|
@@ -293,13 +293,13 @@ function LexicalPopoverMenu({
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
return true;
|
|
296
|
-
}, lexical.
|
|
296
|
+
}, lexical.COMMAND_PRIORITY_NORMAL), editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, payload => {
|
|
297
297
|
const event = payload;
|
|
298
298
|
event.preventDefault();
|
|
299
299
|
event.stopImmediatePropagation();
|
|
300
300
|
close();
|
|
301
301
|
return true;
|
|
302
|
-
}, lexical.
|
|
302
|
+
}, lexical.COMMAND_PRIORITY_NORMAL), editor.registerCommand(lexical.KEY_TAB_COMMAND, payload => {
|
|
303
303
|
const event = payload;
|
|
304
304
|
|
|
305
305
|
if (options === null || selectedIndex === null || options[selectedIndex] == null) {
|
|
@@ -310,7 +310,7 @@ function LexicalPopoverMenu({
|
|
|
310
310
|
event.stopImmediatePropagation();
|
|
311
311
|
selectOptionAndCleanUp(options[selectedIndex]);
|
|
312
312
|
return true;
|
|
313
|
-
}, lexical.
|
|
313
|
+
}, lexical.COMMAND_PRIORITY_NORMAL), editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
|
|
314
314
|
if (options === null || selectedIndex === null || options[selectedIndex] == null) {
|
|
315
315
|
return false;
|
|
316
316
|
}
|
|
@@ -322,7 +322,7 @@ function LexicalPopoverMenu({
|
|
|
322
322
|
|
|
323
323
|
selectOptionAndCleanUp(options[selectedIndex]);
|
|
324
324
|
return true;
|
|
325
|
-
}, lexical.
|
|
325
|
+
}, lexical.COMMAND_PRIORITY_NORMAL));
|
|
326
326
|
}, [selectOptionAndCleanUp, close, editor, options, selectedIndex, updateSelectedIndex]);
|
|
327
327
|
const listItemProps = React.useMemo(() => ({
|
|
328
328
|
selectOptionAndCleanUp,
|
|
@@ -358,7 +358,7 @@ function useBasicTypeaheadTriggerMatch(trigger, {
|
|
|
358
358
|
}, [maxLength, minLength, trigger]);
|
|
359
359
|
}
|
|
360
360
|
|
|
361
|
-
function useAnchorElementRef(resolution
|
|
361
|
+
function useAnchorElementRef(resolution) {
|
|
362
362
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
363
363
|
const anchorElementRef = React.useRef(document.createElement('div'));
|
|
364
364
|
React.useEffect(() => {
|
|
@@ -374,11 +374,10 @@ function useAnchorElementRef(resolution, options) {
|
|
|
374
374
|
const {
|
|
375
375
|
left,
|
|
376
376
|
top,
|
|
377
|
-
height
|
|
378
|
-
width
|
|
377
|
+
height
|
|
379
378
|
} = resolution.getRect();
|
|
380
|
-
containerDiv.style.top = `${top + height + window.pageYOffset}px`;
|
|
381
|
-
containerDiv.style.left = `${left +
|
|
379
|
+
containerDiv.style.top = `${top + height + 5 + window.pageYOffset}px`;
|
|
380
|
+
containerDiv.style.left = `${left + window.pageXOffset}px`;
|
|
382
381
|
containerDiv.style.display = 'block';
|
|
383
382
|
containerDiv.style.position = 'absolute';
|
|
384
383
|
|
|
@@ -402,7 +401,7 @@ function useAnchorElementRef(resolution, options) {
|
|
|
402
401
|
}
|
|
403
402
|
};
|
|
404
403
|
}
|
|
405
|
-
}, [editor, resolution
|
|
404
|
+
}, [editor, resolution]);
|
|
406
405
|
return anchorElementRef;
|
|
407
406
|
}
|
|
408
407
|
|
|
@@ -415,7 +414,7 @@ function LexicalTypeaheadMenuPlugin({
|
|
|
415
414
|
}) {
|
|
416
415
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
417
416
|
const [resolution, setResolution] = React.useState(null);
|
|
418
|
-
const anchorElementRef = useAnchorElementRef(resolution
|
|
417
|
+
const anchorElementRef = useAnchorElementRef(resolution);
|
|
419
418
|
React.useEffect(() => {
|
|
420
419
|
let activeRange = document.createRange();
|
|
421
420
|
let previousText = null;
|
|
@@ -479,7 +478,7 @@ function LexicalNodeMenuPlugin({
|
|
|
479
478
|
}) {
|
|
480
479
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
481
480
|
const [resolution, setResolution] = React.useState(null);
|
|
482
|
-
const anchorElementRef = useAnchorElementRef(resolution
|
|
481
|
+
const anchorElementRef = useAnchorElementRef(resolution);
|
|
483
482
|
React.useEffect(() => {
|
|
484
483
|
if (nodeKey && resolution == null) {
|
|
485
484
|
editor.update(() => {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {LexicalEditor, NodeKey, TextNode} from 'lexical';
|
|
11
|
+
import * as React from 'react';
|
|
12
|
+
|
|
13
|
+
export type QueryMatch = {
|
|
14
|
+
leadOffset: number,
|
|
15
|
+
matchingString: string,
|
|
16
|
+
replaceableString: string,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type Resolution = {
|
|
20
|
+
match: QueryMatch,
|
|
21
|
+
getRect: () => ClientRect,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const PUNCTUATION: string =
|
|
25
|
+
'\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%\'"~=<>_:;';
|
|
26
|
+
|
|
27
|
+
declare export class TypeaheadOption {
|
|
28
|
+
key: string;
|
|
29
|
+
ref: React$ElementRef<HTMLElement | null>;
|
|
30
|
+
constructor(key: string): void;
|
|
31
|
+
setRefElement(element: HTMLElement | null): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type MenuRenderFn<TOption> = (
|
|
35
|
+
anchorElement: HTMLElement | null,
|
|
36
|
+
itemProps: {
|
|
37
|
+
selectedIndex: number | null,
|
|
38
|
+
selectOptionAndCleanUp: (option: TOption) => void,
|
|
39
|
+
setHighlightedIndex: (index: number) => void,
|
|
40
|
+
},
|
|
41
|
+
matchingString: string,
|
|
42
|
+
) => React.Portal | React.MixedElement | null;
|
|
43
|
+
|
|
44
|
+
const scrollIntoViewIfNeeded = (target: HTMLElement) => {
|
|
45
|
+
const container = document.getElementById('typeahead-menu');
|
|
46
|
+
if (container) {
|
|
47
|
+
const containerRect = container.getBoundingClientRect();
|
|
48
|
+
const targetRect = target.getBoundingClientRect();
|
|
49
|
+
if (targetRect.bottom > containerRect.bottom) {
|
|
50
|
+
target.scrollIntoView(false);
|
|
51
|
+
} else if (targetRect.top < containerRect.top) {
|
|
52
|
+
target.scrollIntoView();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
declare export function useBasicTypeaheadTriggerMatch(
|
|
58
|
+
trigger: string,
|
|
59
|
+
options: {minLength?: number, maxLength?: number},
|
|
60
|
+
): TriggerFn;
|
|
61
|
+
|
|
62
|
+
export type TypeaheadMenuPluginArgs<TOption> = {
|
|
63
|
+
onQueryChange: (matchingString: string | null) => void,
|
|
64
|
+
onSelectOption: (
|
|
65
|
+
option: TOption,
|
|
66
|
+
textNodeContainingQuery: TextNode | null,
|
|
67
|
+
closeMenu: () => void,
|
|
68
|
+
matchingString: string,
|
|
69
|
+
) => void,
|
|
70
|
+
options: Array<TOption>,
|
|
71
|
+
menuRenderFn: MenuRenderFn<TOption>,
|
|
72
|
+
triggerFn: TriggerFn,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type TriggerFn = (
|
|
76
|
+
text: string,
|
|
77
|
+
editor: LexicalEditor,
|
|
78
|
+
) => QueryMatch | null;
|
|
79
|
+
|
|
80
|
+
declare export function LexicalTypeaheadMenuPlugin<TOption>(
|
|
81
|
+
options: TypeaheadMenuPluginArgs<TOption>,
|
|
82
|
+
): React.MixedElement | null;
|
|
83
|
+
|
|
84
|
+
type NodeMenuPluginArgs<TOption> = {
|
|
85
|
+
onSelectOption: (
|
|
86
|
+
option: TOption,
|
|
87
|
+
textNodeContainingQuery: TextNode | null,
|
|
88
|
+
closeMenu: () => void,
|
|
89
|
+
matchingString: string,
|
|
90
|
+
) => void,
|
|
91
|
+
options: Array<TOption>,
|
|
92
|
+
nodeKey: NodeKey | null,
|
|
93
|
+
onClose: () => void,
|
|
94
|
+
menuRenderFn: MenuRenderFn<TOption>,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
declare export function LexicalNodeMenuPlugin<TOption>(
|
|
98
|
+
options: NodeMenuPluginArgs<TOption>,
|
|
99
|
+
): React.MixedElement | null;
|
|
@@ -5,18 +5,18 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var m=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 C(b,a){var c=window.getSelection();if(null===c||!c.isCollapsed)return!1;let
|
|
9
|
-
function D(b){let a=null;b.getEditorState().read(()=>{var c=w.$getSelection();if(w.$isRangeSelection(c)){var
|
|
10
|
-
function E(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
|
|
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 C(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 D(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 E(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 k=a;k<=f.length;k++)e.substr(-k)===f.substr(0,k)&&(a=k);a=c-a;if(0>a)return null;let d;0===a?[d]=b.splitText(c):[,d]=b.splitText(a,c);return d}
|
|
11
11
|
function F(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 G(b){x.startTransition?x.startTransition(b):b()}
|
|
12
|
-
function H({close:b,editor:a,anchorElement:c,resolution:
|
|
13
|
-
[a]);y(()=>{null===
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function I(b
|
|
17
|
-
d
|
|
18
|
-
exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:c,onSelectOption:
|
|
19
|
-
{close:c,resolution:
|
|
20
|
-
exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,menuRenderFn:
|
|
21
|
-
l)?
|
|
22
|
-
exports.useBasicTypeaheadTriggerMatch=function(b,{minLength:a=1,maxLength:c=75}){return x.useCallback(
|
|
12
|
+
function H({close:b,editor:a,anchorElement:c,resolution:e,options:f,menuRenderFn:d,onSelectOption:k}){let [g,q]=x.useState(null);x.useEffect(()=>{q(0)},[e.match.matchingString]);let r=x.useCallback(async h=>{a.update(()=>{const l=E(a,e.match);k(h,l,b,e.match.matchingString)})},[b,a,e.match,k]),p=x.useCallback(h=>{const l=a.getRootElement();null!==l&&(l.setAttribute("aria-activedescendant","typeahead-item-"+h),q(h))},[a]);x.useEffect(()=>()=>{let h=a.getRootElement();null!==h&&h.removeAttribute("aria-activedescendant")},
|
|
13
|
+
[a]);y(()=>{null===f?q(null):null===g&&p(0)},[f,g,p]);x.useEffect(()=>n.mergeRegister(a.registerCommand(w.KEY_ARROW_DOWN_COMMAND,h=>{if(null!==f&&f.length&&null!==g){var l=g!==f.length-1?g+1:0;p(l);l=f[l];null!=l.ref&&l.ref.current&&A(l.ref.current);h.preventDefault();h.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_NORMAL),a.registerCommand(w.KEY_ARROW_UP_COMMAND,h=>{if(null!==f&&f.length&&null!==g){var l=0!==g?g-1:f.length-1;p(l);l=f[l];null!=l.ref&&l.ref.current&&A(l.ref.current);h.preventDefault();
|
|
14
|
+
h.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_NORMAL),a.registerCommand(w.KEY_ESCAPE_COMMAND,h=>{h.preventDefault();h.stopImmediatePropagation();b();return!0},w.COMMAND_PRIORITY_NORMAL),a.registerCommand(w.KEY_TAB_COMMAND,h=>{if(null===f||null===g||null==f[g])return!1;h.preventDefault();h.stopImmediatePropagation();r(f[g]);return!0},w.COMMAND_PRIORITY_NORMAL),a.registerCommand(w.KEY_ENTER_COMMAND,h=>{if(null===f||null===g||null==f[g])return!1;null!==h&&(h.preventDefault(),h.stopImmediatePropagation());
|
|
15
|
+
r(f[g]);return!0},w.COMMAND_PRIORITY_NORMAL)),[r,b,a,f,g,p]);let t=x.useMemo(()=>({selectOptionAndCleanUp:r,selectedIndex:g,setHighlightedIndex:q}),[r,g]);return d(c,t,e.match.matchingString)}
|
|
16
|
+
function I(b){let [a]=m.useLexicalComposerContext(),c=x.useRef(document.createElement("div"));x.useEffect(()=>{function e(){let d=c.current;d.setAttribute("aria-label","Typeahead menu");d.setAttribute("id","typeahead-menu");d.setAttribute("role","listbox");if(null!==f&&null!==b){let {left:k,top:g,height:q}=b.getRect();d.style.top=`${g+q+5+window.pageYOffset}px`;d.style.left=`${k+window.pageXOffset}px`;d.style.display="block";d.style.position="absolute";d.isConnected||document.body.append(d);c.current=
|
|
17
|
+
d;f.setAttribute("aria-controls","typeahead-menu")}}let f=a.getRootElement();if(null!==b)return e(),window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e);null!==f&&f.removeAttribute("aria-controls")}},[a,b]);return c}
|
|
18
|
+
exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:c,onSelectOption:e,menuRenderFn:f}){let [d]=m.useLexicalComposerContext(),[k,g]=x.useState(null),q=I(k);x.useEffect(()=>{a&&null==k?d.update(()=>{let r=w.$getNodeByKey(a),p=d.getElementByKey(a);if(null!=r&&null!=p){let t=r.getTextContent();G(()=>g({getRect:()=>p.getBoundingClientRect(),match:{leadOffset:t.length,matchingString:t,replaceableString:t}}))}}):null==a&&null!=k&&g(null)},[d,a,k]);return null===k||null===d?null:x.createElement(H,
|
|
19
|
+
{close:c,resolution:k,editor:d,anchorElement:q.current,options:b,menuRenderFn:f,onSelectOption:e})};
|
|
20
|
+
exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,menuRenderFn:e,triggerFn:f}){let [d]=m.useLexicalComposerContext(),[k,g]=x.useState(null),q=I(k);x.useEffect(()=>{let p=document.createRange(),t=null,h=d.registerUpdateListener(()=>{d.getEditorState().read(()=>{const l=p,B=w.$getSelection(),v=D(d);if(w.$isRangeSelection(B)&&B.isCollapsed()&&v!==t&&null!==v&&null!==l){t=v;var u=f(v,d);a(u?u.matchingString:null);null===u||F(d,u.leadOffset)||null===C(u.leadOffset,
|
|
21
|
+
l)?g(null):G(()=>g({getRect:()=>l.getBoundingClientRect(),match:u}))}else g(null)})});return()=>{p=null;h()}},[d,f,a,k]);let r=x.useCallback(()=>{g(null)},[]);return null===k||null===d?null:x.createElement(H,{close:r,resolution:k,editor:d,anchorElement:q.current,options:b,menuRenderFn:e,onSelectOption:c})};exports.PUNCTUATION="\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";exports.TypeaheadOption=z;
|
|
22
|
+
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],d=e[3];if(d.length>=a)return{leadOffset:e.index+f.length,matchingString:d,replaceableString:e[2]}}return null},[c,a,b])}
|