@lexical/react 0.3.8 → 0.3.11

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.
@@ -143,7 +143,7 @@ function getFullMatchOffset(documentText, entryText, offset) {
143
143
  return triggerOffset;
144
144
  }
145
145
  /**
146
- * Split Lexica TextNode and return a new TextNode only containing matched text.
146
+ * Split Lexical TextNode and return a new TextNode only containing matched text.
147
147
  * Common use cases include: removing the node, replacing with a new node.
148
148
  */
149
149
 
@@ -207,59 +207,27 @@ function isSelectionOnEntityBoundary(editor, offset) {
207
207
  });
208
208
  }
209
209
 
210
- function ShortcutTypeahead({
210
+ function startTransition(callback) {
211
+ if (React.startTransition) {
212
+ React.startTransition(callback);
213
+ } else {
214
+ callback();
215
+ }
216
+ }
217
+
218
+ function LexicalPopoverMenu({
211
219
  close,
212
220
  editor,
221
+ anchorElement,
213
222
  resolution,
214
223
  options,
215
224
  menuRenderFn,
216
225
  onSelectOption
217
226
  }) {
218
227
  const [selectedIndex, setHighlightedIndex] = React.useState(null);
219
- const anchorElementRef = React.useRef(document.createElement('div'));
220
228
  React.useEffect(() => {
221
229
  setHighlightedIndex(0);
222
230
  }, [resolution.match.matchingString]);
223
- React.useEffect(() => {
224
- const rootElement = editor.getRootElement();
225
-
226
- function positionMenu() {
227
- const containerDiv = anchorElementRef.current;
228
- containerDiv.setAttribute('aria-label', 'Typeahead menu');
229
- containerDiv.setAttribute('id', 'typeahead-menu');
230
- containerDiv.setAttribute('role', 'listbox');
231
-
232
- if (rootElement !== null) {
233
- const range = resolution.range;
234
- const {
235
- left,
236
- top,
237
- height
238
- } = range.getBoundingClientRect();
239
- containerDiv.style.top = `${top + height + window.pageYOffset}px`;
240
- containerDiv.style.left = `${left + window.pageXOffset}px`;
241
- containerDiv.style.display = 'block';
242
- containerDiv.style.position = 'absolute';
243
-
244
- if (!containerDiv.isConnected) {
245
- document.body.append(containerDiv);
246
- }
247
-
248
- anchorElementRef.current = containerDiv;
249
- rootElement.setAttribute('aria-controls', 'typeahead-menu');
250
- }
251
- }
252
-
253
- positionMenu();
254
- window.addEventListener('resize', positionMenu);
255
- return () => {
256
- window.removeEventListener('resize', positionMenu);
257
-
258
- if (rootElement !== null) {
259
- rootElement.removeAttribute('aria-controls');
260
- }
261
- };
262
- }, [editor, resolution, options]);
263
231
  const selectOptionAndCleanUp = React.useCallback(async selectedEntry => {
264
232
  editor.update(() => {
265
233
  const textNodeContainingQuery = splitNodeContainingQuery(editor, resolution.match);
@@ -294,7 +262,7 @@ function ShortcutTypeahead({
294
262
  return utils.mergeRegister(editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, payload => {
295
263
  const event = payload;
296
264
 
297
- if (options !== null && selectedIndex !== null) {
265
+ if (options !== null && options.length && selectedIndex !== null) {
298
266
  const newSelectedIndex = selectedIndex !== options.length - 1 ? selectedIndex + 1 : 0;
299
267
  updateSelectedIndex(newSelectedIndex);
300
268
  const option = options[newSelectedIndex];
@@ -311,7 +279,7 @@ function ShortcutTypeahead({
311
279
  }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, payload => {
312
280
  const event = payload;
313
281
 
314
- if (options !== null && selectedIndex !== null) {
282
+ if (options !== null && options.length && selectedIndex !== null) {
315
283
  const newSelectedIndex = selectedIndex !== 0 ? selectedIndex - 1 : options.length - 1;
316
284
  updateSelectedIndex(newSelectedIndex);
317
285
  const option = options[newSelectedIndex];
@@ -327,11 +295,6 @@ function ShortcutTypeahead({
327
295
  return true;
328
296
  }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, payload => {
329
297
  const event = payload;
330
-
331
- if (options === null || selectedIndex === null) {
332
- return false;
333
- }
334
-
335
298
  event.preventDefault();
336
299
  event.stopImmediatePropagation();
337
300
  close();
@@ -366,7 +329,7 @@ function ShortcutTypeahead({
366
329
  selectedIndex,
367
330
  setHighlightedIndex
368
331
  }), [selectOptionAndCleanUp, selectedIndex]);
369
- return menuRenderFn(anchorElementRef.current, listItemProps, resolution.match.matchingString);
332
+ return menuRenderFn(anchorElement, listItemProps, resolution.match.matchingString);
370
333
  }
371
334
 
372
335
  function useBasicTypeaheadTriggerMatch(trigger, {
@@ -394,6 +357,55 @@ function useBasicTypeaheadTriggerMatch(trigger, {
394
357
  return null;
395
358
  }, [maxLength, minLength, trigger]);
396
359
  }
360
+
361
+ function useAnchorElementRef(resolution, options) {
362
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
363
+ const anchorElementRef = React.useRef(document.createElement('div'));
364
+ React.useEffect(() => {
365
+ const rootElement = editor.getRootElement();
366
+
367
+ function positionMenu() {
368
+ const containerDiv = anchorElementRef.current;
369
+ containerDiv.setAttribute('aria-label', 'Typeahead menu');
370
+ containerDiv.setAttribute('id', 'typeahead-menu');
371
+ containerDiv.setAttribute('role', 'listbox');
372
+
373
+ if (rootElement !== null && resolution !== null) {
374
+ const {
375
+ left,
376
+ top,
377
+ height,
378
+ width
379
+ } = resolution.getRect();
380
+ containerDiv.style.top = `${top + height + window.pageYOffset}px`;
381
+ containerDiv.style.left = `${left + width + window.pageXOffset}px`;
382
+ containerDiv.style.display = 'block';
383
+ containerDiv.style.position = 'absolute';
384
+
385
+ if (!containerDiv.isConnected) {
386
+ document.body.append(containerDiv);
387
+ }
388
+
389
+ anchorElementRef.current = containerDiv;
390
+ rootElement.setAttribute('aria-controls', 'typeahead-menu');
391
+ }
392
+ }
393
+
394
+ if (resolution !== null) {
395
+ positionMenu();
396
+ window.addEventListener('resize', positionMenu);
397
+ return () => {
398
+ window.removeEventListener('resize', positionMenu);
399
+
400
+ if (rootElement !== null) {
401
+ rootElement.removeAttribute('aria-controls');
402
+ }
403
+ };
404
+ }
405
+ }, [editor, resolution, options]);
406
+ return anchorElementRef;
407
+ }
408
+
397
409
  function LexicalTypeaheadMenuPlugin({
398
410
  options,
399
411
  onQueryChange,
@@ -403,6 +415,7 @@ function LexicalTypeaheadMenuPlugin({
403
415
  }) {
404
416
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
405
417
  const [resolution, setResolution] = React.useState(null);
418
+ const anchorElementRef = useAnchorElementRef(resolution, options);
406
419
  React.useEffect(() => {
407
420
  let activeRange = document.createRange();
408
421
  let previousText = null;
@@ -414,27 +427,27 @@ function LexicalTypeaheadMenuPlugin({
414
427
  const text = getQueryTextForSearch(editor);
415
428
 
416
429
  if (!lexical.$isRangeSelection(selection) || !selection.isCollapsed() || text === previousText || text === null || range === null) {
417
- React.startTransition(() => setResolution(null));
430
+ setResolution(null);
418
431
  return;
419
432
  }
420
433
 
421
434
  previousText = text;
422
- const match = triggerFn(text);
435
+ const match = triggerFn(text, editor);
423
436
  onQueryChange(match ? match.matchingString : null);
424
437
 
425
438
  if (match !== null && !isSelectionOnEntityBoundary(editor, match.leadOffset)) {
426
439
  const isRangePositioned = tryToPositionRange(match.leadOffset, range);
427
440
 
428
441
  if (isRangePositioned !== null) {
429
- React.startTransition(() => setResolution({
430
- match,
431
- range
442
+ startTransition(() => setResolution({
443
+ getRect: () => range.getBoundingClientRect(),
444
+ match
432
445
  }));
433
446
  return;
434
447
  }
435
448
  }
436
449
 
437
- React.startTransition(() => setResolution(null));
450
+ setResolution(null);
438
451
  });
439
452
  };
440
453
 
@@ -447,16 +460,60 @@ function LexicalTypeaheadMenuPlugin({
447
460
  const closeTypeahead = React.useCallback(() => {
448
461
  setResolution(null);
449
462
  }, []);
450
- return resolution === null || editor === null ? null : /*#__PURE__*/React.createElement(ShortcutTypeahead, {
463
+ return resolution === null || editor === null ? null : /*#__PURE__*/React.createElement(LexicalPopoverMenu, {
451
464
  close: closeTypeahead,
452
465
  resolution: resolution,
453
466
  editor: editor,
467
+ anchorElement: anchorElementRef.current,
468
+ options: options,
469
+ menuRenderFn: menuRenderFn,
470
+ onSelectOption: onSelectOption
471
+ });
472
+ }
473
+ function LexicalNodeMenuPlugin({
474
+ options,
475
+ nodeKey,
476
+ onClose,
477
+ onSelectOption,
478
+ menuRenderFn
479
+ }) {
480
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
481
+ const [resolution, setResolution] = React.useState(null);
482
+ const anchorElementRef = useAnchorElementRef(resolution, options);
483
+ React.useEffect(() => {
484
+ if (nodeKey && resolution == null) {
485
+ editor.update(() => {
486
+ const node = lexical.$getNodeByKey(nodeKey);
487
+ const domElement = editor.getElementByKey(nodeKey);
488
+
489
+ if (node != null && domElement != null) {
490
+ const text = node.getTextContent();
491
+ startTransition(() => setResolution({
492
+ getRect: () => domElement.getBoundingClientRect(),
493
+ match: {
494
+ leadOffset: text.length,
495
+ matchingString: text,
496
+ replaceableString: text
497
+ }
498
+ }));
499
+ }
500
+ });
501
+ } else if (nodeKey == null && resolution != null) {
502
+ setResolution(null);
503
+ }
504
+ }, [editor, nodeKey, resolution]);
505
+ return resolution === null || editor === null ? null : /*#__PURE__*/React.createElement(LexicalPopoverMenu, {
506
+ close: onClose,
507
+ resolution: resolution,
508
+ editor: editor,
509
+ anchorElement: anchorElementRef.current,
454
510
  options: options,
455
511
  menuRenderFn: menuRenderFn,
456
512
  onSelectOption: onSelectOption
457
513
  });
458
514
  }
459
515
 
516
+ exports.LexicalNodeMenuPlugin = LexicalNodeMenuPlugin;
460
517
  exports.LexicalTypeaheadMenuPlugin = LexicalTypeaheadMenuPlugin;
461
518
  exports.PUNCTUATION = PUNCTUATION;
462
519
  exports.TypeaheadOption = TypeaheadOption;
@@ -4,16 +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 h=require("@lexical/react/LexicalComposerContext"),k=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(d){this.key=d;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(d){this.ref={current:d}}}
8
- let A=d=>{var a=document.getElementById("typeahead-menu");if(a){a=a.getBoundingClientRect();const b=d.getBoundingClientRect();b.bottom>a.bottom?d.scrollIntoView(!1):b.top<a.top&&d.scrollIntoView()}};function B(d,a){var b=window.getSelection();if(null===b||!b.isCollapsed)return!1;let c=b.anchorNode;b=b.anchorOffset;if(null==c||null==b)return!1;try{a.setStart(c,d),a.setEnd(c,b)}catch(n){return!1}return!0}
9
- function C(d){let a=null;d.getEditorState().read(()=>{var b=w.$getSelection();if(w.$isRangeSelection(b)){var c=b.anchor;"text"!==c.type?a=null:(b=c.getNode(),b.isSimpleText()?(c=c.offset,a=b.getTextContent().slice(0,c)):a=null)}});return a}
10
- function D(d,a){d=w.$getSelection();if(!w.$isRangeSelection(d)||!d.isCollapsed())return null;var b=d.anchor;if("text"!==b.type)return null;d=b.getNode();if(!d.isSimpleText())return null;b=b.offset;let c=d.getTextContent().slice(0,b);var n=a.matchingString;a=a.replaceableString.length;for(let f=a;f<=n.length;f++)c.substr(-f)===n.substr(0,f)&&(a=f);a=b-a;if(0>a)return null;let l;0===a?[l]=d.splitText(b):[,l]=d.splitText(a,b);return l}
11
- function E(d,a){return 0!==a?!1:d.getEditorState().read(()=>{var b=w.$getSelection();return w.$isRangeSelection(b)?(b=b.anchor.getNode().getPreviousSibling(),w.$isTextNode(b)&&b.isTextEntity()):!1})}
12
- function F({close:d,editor:a,resolution:b,options:c,menuRenderFn:n,onSelectOption:l}){let [f,p]=x.useState(null),u=x.useRef(document.createElement("div"));x.useEffect(()=>{p(0)},[b.match.matchingString]);x.useEffect(()=>{function e(){let m=u.current;m.setAttribute("aria-label","Typeahead menu");m.setAttribute("id","typeahead-menu");m.setAttribute("role","listbox");if(null!==g){let {left:q,top:G,height:H}=b.range.getBoundingClientRect();m.style.top=`${G+H+window.pageYOffset}px`;m.style.left=`${q+window.pageXOffset}px`;
13
- m.style.display="block";m.style.position="absolute";m.isConnected||document.body.append(m);u.current=m;g.setAttribute("aria-controls","typeahead-menu")}}let g=a.getRootElement();e();window.addEventListener("resize",e);return()=>{window.removeEventListener("resize",e);null!==g&&g.removeAttribute("aria-controls")}},[a,b,c]);let r=x.useCallback(async e=>{a.update(()=>{const g=D(a,b.match);l(e,g,d,b.match.matchingString)})},[d,a,b.match,l]),t=x.useCallback(e=>{const g=a.getRootElement();null!==g&&(g.setAttribute("aria-activedescendant",
14
- "typeahead-item-"+e),p(e))},[a]);x.useEffect(()=>()=>{let e=a.getRootElement();null!==e&&e.removeAttribute("aria-activedescendant")},[a]);y(()=>{null===c?p(null):null===f&&t(0)},[c,f,t]);x.useEffect(()=>k.mergeRegister(a.registerCommand(w.KEY_ARROW_DOWN_COMMAND,e=>{if(null!==c&&null!==f){var g=f!==c.length-1?f+1:0;t(g);g=c[g];null!=g.ref&&g.ref.current&&A(g.ref.current);e.preventDefault();e.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_LOW),a.registerCommand(w.KEY_ARROW_UP_COMMAND,e=>{if(null!==
15
- c&&null!==f){var g=0!==f?f-1:c.length-1;t(g);g=c[g];null!=g.ref&&g.ref.current&&A(g.ref.current);e.preventDefault();e.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_LOW),a.registerCommand(w.KEY_ESCAPE_COMMAND,e=>{if(null===c||null===f)return!1;e.preventDefault();e.stopImmediatePropagation();d();return!0},w.COMMAND_PRIORITY_LOW),a.registerCommand(w.KEY_TAB_COMMAND,e=>{if(null===c||null===f||null==c[f])return!1;e.preventDefault();e.stopImmediatePropagation();r(c[f]);return!0},w.COMMAND_PRIORITY_LOW),
16
- a.registerCommand(w.KEY_ENTER_COMMAND,e=>{if(null===c||null===f||null==c[f])return!1;null!==e&&(e.preventDefault(),e.stopImmediatePropagation());r(c[f]);return!0},w.COMMAND_PRIORITY_LOW)),[r,d,a,c,f,t]);let v=x.useMemo(()=>({selectOptionAndCleanUp:r,selectedIndex:f,setHighlightedIndex:p}),[r,f]);return n(u.current,v,b.match.matchingString)}
17
- exports.LexicalTypeaheadMenuPlugin=function({options:d,onQueryChange:a,onSelectOption:b,menuRenderFn:c,triggerFn:n}){let [l]=h.useLexicalComposerContext(),[f,p]=x.useState(null);x.useEffect(()=>{let r=document.createRange(),t=null,v=l.registerUpdateListener(()=>{l.getEditorState().read(()=>{const e=r,g=w.$getSelection(),m=C(l);if(w.$isRangeSelection(g)&&g.isCollapsed()&&m!==t&&null!==m&&null!==e){t=m;var q=n(m);a(q?q.matchingString:null);null===q||E(l,q.leadOffset)||null===B(q.leadOffset,e)?x.startTransition(()=>
18
- p(null)):x.startTransition(()=>p({match:q,range:e}))}else x.startTransition(()=>p(null))})});return()=>{r=null;v()}},[l,n,a,f]);let u=x.useCallback(()=>{p(null)},[]);return null===f||null===l?null:x.createElement(F,{close:u,resolution:f,editor:l,options:d,menuRenderFn:c,onSelectOption:b})};exports.PUNCTUATION="\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";exports.TypeaheadOption=z;
19
- exports.useBasicTypeaheadTriggerMatch=function(d,{minLength:a=1,maxLength:b=75}){return x.useCallback(c=>{c=(new RegExp("(^|\\s|\\()(["+d+"]((?:[^"+(d+"\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;\\s]){0,")+b+"}))$")).exec(c);if(null!==c){let n=c[1],l=c[3];if(l.length>=a)return{leadOffset:c.index+n.length,matchingString:l,replaceableString:c[2]}}return null},[b,a,d])}
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 d=c.anchorNode;c=c.anchorOffset;if(null==d||null==c)return!1;try{a.setStart(d,b),a.setEnd(d,c)}catch(e){return!1}return!0}
9
+ function D(b){let a=null;b.getEditorState().read(()=>{var c=w.$getSelection();if(w.$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}
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 d=b.getTextContent().slice(0,c);var e=a.matchingString;a=a.replaceableString.length;for(let f=a;f<=e.length;f++)d.substr(-f)===e.substr(0,f)&&(a=f);a=c-a;if(0>a)return null;let g;0===a?[g]=b.splitText(c):[,g]=b.splitText(a,c);return g}
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:d,options:e,menuRenderFn:g,onSelectOption:f}){let [h,r]=x.useState(null);x.useEffect(()=>{r(0)},[d.match.matchingString]);let q=x.useCallback(async k=>{a.update(()=>{const l=E(a,d.match);f(k,l,b,d.match.matchingString)})},[b,a,d.match,f]),p=x.useCallback(k=>{const l=a.getRootElement();null!==l&&(l.setAttribute("aria-activedescendant","typeahead-item-"+k),r(k))},[a]);x.useEffect(()=>()=>{let k=a.getRootElement();null!==k&&k.removeAttribute("aria-activedescendant")},
13
+ [a]);y(()=>{null===e?r(null):null===h&&p(0)},[e,h,p]);x.useEffect(()=>n.mergeRegister(a.registerCommand(w.KEY_ARROW_DOWN_COMMAND,k=>{if(null!==e&&e.length&&null!==h){var l=h!==e.length-1?h+1:0;p(l);l=e[l];null!=l.ref&&l.ref.current&&A(l.ref.current);k.preventDefault();k.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_LOW),a.registerCommand(w.KEY_ARROW_UP_COMMAND,k=>{if(null!==e&&e.length&&null!==h){var l=0!==h?h-1:e.length-1;p(l);l=e[l];null!=l.ref&&l.ref.current&&A(l.ref.current);k.preventDefault();
14
+ k.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_LOW),a.registerCommand(w.KEY_ESCAPE_COMMAND,k=>{k.preventDefault();k.stopImmediatePropagation();b();return!0},w.COMMAND_PRIORITY_LOW),a.registerCommand(w.KEY_TAB_COMMAND,k=>{if(null===e||null===h||null==e[h])return!1;k.preventDefault();k.stopImmediatePropagation();q(e[h]);return!0},w.COMMAND_PRIORITY_LOW),a.registerCommand(w.KEY_ENTER_COMMAND,k=>{if(null===e||null===h||null==e[h])return!1;null!==k&&(k.preventDefault(),k.stopImmediatePropagation());
15
+ q(e[h]);return!0},w.COMMAND_PRIORITY_LOW)),[q,b,a,e,h,p]);let t=x.useMemo(()=>({selectOptionAndCleanUp:q,selectedIndex:h,setHighlightedIndex:r}),[q,h]);return g(c,t,d.match.matchingString)}
16
+ function I(b,a){let [c]=m.useLexicalComposerContext(),d=x.useRef(document.createElement("div"));x.useEffect(()=>{function e(){let f=d.current;f.setAttribute("aria-label","Typeahead menu");f.setAttribute("id","typeahead-menu");f.setAttribute("role","listbox");if(null!==g&&null!==b){let {left:h,top:r,height:q,width:p}=b.getRect();f.style.top=`${r+q+window.pageYOffset}px`;f.style.left=`${h+p+window.pageXOffset}px`;f.style.display="block";f.style.position="absolute";f.isConnected||document.body.append(f);
17
+ d.current=f;g.setAttribute("aria-controls","typeahead-menu")}}let g=c.getRootElement();if(null!==b)return e(),window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e);null!==g&&g.removeAttribute("aria-controls")}},[c,b,a]);return d}
18
+ exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:c,onSelectOption:d,menuRenderFn:e}){let [g]=m.useLexicalComposerContext(),[f,h]=x.useState(null),r=I(f,b);x.useEffect(()=>{a&&null==f?g.update(()=>{let q=w.$getNodeByKey(a),p=g.getElementByKey(a);if(null!=q&&null!=p){let t=q.getTextContent();G(()=>h({getRect:()=>p.getBoundingClientRect(),match:{leadOffset:t.length,matchingString:t,replaceableString:t}}))}}):null==a&&null!=f&&h(null)},[g,a,f]);return null===f||null===g?null:x.createElement(H,
19
+ {close:c,resolution:f,editor:g,anchorElement:r.current,options:b,menuRenderFn:e,onSelectOption:d})};
20
+ exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,menuRenderFn:d,triggerFn:e}){let [g]=m.useLexicalComposerContext(),[f,h]=x.useState(null),r=I(f,b);x.useEffect(()=>{let p=document.createRange(),t=null,k=g.registerUpdateListener(()=>{g.getEditorState().read(()=>{const l=p,B=w.$getSelection(),v=D(g);if(w.$isRangeSelection(B)&&B.isCollapsed()&&v!==t&&null!==v&&null!==l){t=v;var u=e(v,g);a(u?u.matchingString:null);null===u||F(g,u.leadOffset)||null===C(u.leadOffset,
21
+ l)?h(null):G(()=>h({getRect:()=>l.getBoundingClientRect(),match:u}))}else h(null)})});return()=>{p=null;k()}},[g,e,a,f]);let q=x.useCallback(()=>{h(null)},[]);return null===f||null===g?null:x.createElement(H,{close:q,resolution:f,editor:g,anchorElement:r.current,options:b,menuRenderFn:d,onSelectOption:c})};exports.PUNCTUATION="\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";exports.TypeaheadOption=z;
22
+ exports.useBasicTypeaheadTriggerMatch=function(b,{minLength:a=1,maxLength:c=75}){return x.useCallback(d=>{d=(new RegExp("(^|\\s|\\()(["+b+"]((?:[^"+(b+"\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;\\s]){0,")+c+"}))$")).exec(d);if(null!==d){let e=d[1],g=d[3];if(g.length>=a)return{leadOffset:d.index+e.length,matchingString:g,replaceableString:d[2]}}return null},[c,a,b])}
package/package.json CHANGED
@@ -8,28 +8,28 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.3.8",
11
+ "version": "0.3.11",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.3.8",
14
- "@lexical/code": "0.3.8",
15
- "@lexical/dragon": "0.3.8",
16
- "@lexical/hashtag": "0.3.8",
17
- "@lexical/history": "0.3.8",
18
- "@lexical/link": "0.3.8",
19
- "@lexical/list": "0.3.8",
20
- "@lexical/mark": "0.3.8",
21
- "@lexical/markdown": "0.3.8",
22
- "@lexical/overflow": "0.3.8",
23
- "@lexical/plain-text": "0.3.8",
24
- "@lexical/rich-text": "0.3.8",
25
- "@lexical/selection": "0.3.8",
26
- "@lexical/table": "0.3.8",
27
- "@lexical/text": "0.3.8",
28
- "@lexical/utils": "0.3.8",
29
- "@lexical/yjs": "0.3.8"
13
+ "@lexical/clipboard": "0.3.11",
14
+ "@lexical/code": "0.3.11",
15
+ "@lexical/dragon": "0.3.11",
16
+ "@lexical/hashtag": "0.3.11",
17
+ "@lexical/history": "0.3.11",
18
+ "@lexical/link": "0.3.11",
19
+ "@lexical/list": "0.3.11",
20
+ "@lexical/mark": "0.3.11",
21
+ "@lexical/markdown": "0.3.11",
22
+ "@lexical/overflow": "0.3.11",
23
+ "@lexical/plain-text": "0.3.11",
24
+ "@lexical/rich-text": "0.3.11",
25
+ "@lexical/selection": "0.3.11",
26
+ "@lexical/table": "0.3.11",
27
+ "@lexical/text": "0.3.11",
28
+ "@lexical/utils": "0.3.11",
29
+ "@lexical/yjs": "0.3.11"
30
30
  },
31
31
  "peerDependencies": {
32
- "lexical": "0.3.8",
32
+ "lexical": "0.3.11",
33
33
  "react": ">=17.x",
34
34
  "react-dom": ">=17.x"
35
35
  },