@lumel/mention 5.2.4 → 5.2.5

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.
@@ -1,7 +1,7 @@
1
1
  import { AriaProps, EditorCommand } from '@draft-js-plugins/editor';
2
2
  import { DraftHandleValue, EditorState, SelectionState } from 'draft-js';
3
3
  import PropTypes from 'prop-types';
4
- import { Component, ComponentType, KeyboardEvent, ReactElement, RefAttributes } from 'react';
4
+ import React, { Component, ComponentType, KeyboardEvent, ReactElement, RefAttributes } from 'react';
5
5
  import { MentionData, MentionPluginStore, PopperOptions } from '..';
6
6
  import { MentionPluginTheme } from '../theme';
7
7
  import { PositionSuggestionsFn } from '../utils/positionSuggestions';
@@ -31,6 +31,8 @@ export interface MentionSuggestionsPubProps {
31
31
  entryComponent?: ComponentType<EntryComponentProps>;
32
32
  popoverContainer?: ComponentType<PopoverProps>;
33
33
  renderEmptyPopup?: boolean;
34
+ handleScroll?: React.UIEventHandler<HTMLElement>;
35
+ isMentionLoading?: boolean;
34
36
  }
35
37
  export interface MentionSuggestionsProps extends MentionSuggestionsPubProps {
36
38
  callbacks: MentionSuggestionCallbacks;
@@ -43,6 +45,16 @@ export interface MentionSuggestionsProps extends MentionSuggestionsPubProps {
43
45
  entityMutability: 'SEGMENTED' | 'IMMUTABLE' | 'MUTABLE';
44
46
  popperOptions?: PopperOptions;
45
47
  }
48
+ interface RenderSuggestionsProps {
49
+ suggestions: MentionData[];
50
+ focusedOptionIndex: number;
51
+ onMentionSelect: (mention: MentionData | null) => void;
52
+ onMentionFocus: (index: number) => void;
53
+ theme: MentionPluginTheme;
54
+ lastSearchValue?: string;
55
+ entryComponent?: ComponentType<EntryComponentProps>;
56
+ isMentionLoading?: boolean;
57
+ }
46
58
  export declare class MentionSuggestions extends Component<MentionSuggestionsProps> {
47
59
  static propTypes: {
48
60
  open: PropTypes.Validator<boolean>;
@@ -51,6 +63,8 @@ export declare class MentionSuggestions extends Component<MentionSuggestionsProp
51
63
  entryComponent: PropTypes.Requireable<(...args: any[]) => any>;
52
64
  onAddMention: PropTypes.Requireable<(...args: any[]) => any>;
53
65
  suggestions: PropTypes.Validator<any[]>;
66
+ handleScroll: PropTypes.Requireable<(...args: any[]) => any>;
67
+ isMentionLoading: PropTypes.Requireable<boolean>;
54
68
  };
55
69
  state: {
56
70
  focusedOptionIndex: number;
@@ -76,6 +90,7 @@ export declare class MentionSuggestions extends Component<MentionSuggestionsProp
76
90
  openDropdown: () => void;
77
91
  closeDropdown: () => void;
78
92
  private getMentionKey;
93
+ renderSuggestionsList: (props: RenderSuggestionsProps) => JSX.Element;
79
94
  render(): ReactElement | null;
80
95
  }
81
96
  export default MentionSuggestions;
@@ -1,10 +1,11 @@
1
- import { ReactElement, ReactNode } from 'react';
1
+ import React, { ReactElement, ReactNode } from 'react';
2
2
  import { MentionPluginStore, PopperOptions } from '..';
3
3
  import { MentionPluginTheme } from '../theme';
4
4
  export interface PopoverProps {
5
5
  store: MentionPluginStore;
6
6
  children: ReactNode;
7
- popperOptions?: PopperOptions;
8
7
  theme: MentionPluginTheme;
8
+ popperOptions?: PopperOptions;
9
+ handleScroll?: React.UIEventHandler<HTMLElement>;
9
10
  }
10
- export default function Popover({ store, children, theme, popperOptions, }: PopoverProps): ReactElement;
11
+ export default function Popover({ store, children, theme, popperOptions, handleScroll, }: PopoverProps): ReactElement;
package/lib/index.cjs.js CHANGED
@@ -433,7 +433,8 @@ function Popover(_ref) {
433
433
  _ref$popperOptions = _ref.popperOptions,
434
434
  popperOptions = _ref$popperOptions === void 0 ? {
435
435
  placement: 'bottom-start'
436
- } : _ref$popperOptions;
436
+ } : _ref$popperOptions,
437
+ handleScroll = _ref.handleScroll;
437
438
  var _useState = React.useState(function () {
438
439
  return clsx(theme.mentionSuggestions, theme.mentionSuggestionsPopup);
439
440
  }),
@@ -455,16 +456,17 @@ function Popover(_ref) {
455
456
  style: styles.popper
456
457
  }, attributes.popper, {
457
458
  className: className,
458
- role: "listbox"
459
+ role: "listbox",
460
+ onScroll: handleScroll
459
461
  }), children);
460
462
  }
461
463
 
462
- var _excluded = ["entryComponent", "popoverComponent", "popperOptions", "popoverContainer", "onOpenChange", "onAddMention", "onSearchChange", "suggestions", "ariaProps", "callbacks", "theme", "store", "entityMutability", "positionSuggestions", "mentionTriggers", "mentionPrefix"];
464
+ var _excluded = ["entryComponent", "popoverComponent", "popperOptions", "popoverContainer", "onOpenChange", "onAddMention", "onSearchChange", "suggestions", "ariaProps", "callbacks", "theme", "store", "entityMutability", "positionSuggestions", "mentionTriggers", "mentionPrefix", "handleScroll", "isMentionLoading"];
463
465
  var MentionSuggestions = /*#__PURE__*/function (_Component) {
464
466
  _inheritsLoose(MentionSuggestions, _Component);
465
- function MentionSuggestions(props) {
467
+ function MentionSuggestions(_props) {
466
468
  var _this;
467
- _this = _Component.call(this, props) || this;
469
+ _this = _Component.call(this, _props) || this;
468
470
  _this.state = {
469
471
  focusedOptionIndex: 0
470
472
  };
@@ -623,6 +625,37 @@ var MentionSuggestions = /*#__PURE__*/function (_Component) {
623
625
  _this.props.ariaProps.ariaOwneeID = undefined;
624
626
  _this.props.onOpenChange(false);
625
627
  };
628
+ _this.renderSuggestionsList = function (props) {
629
+ var suggestions = props.suggestions,
630
+ focusedOptionIndex = props.focusedOptionIndex,
631
+ onMentionSelect = props.onMentionSelect,
632
+ onMentionFocus = props.onMentionFocus,
633
+ theme = props.theme,
634
+ lastSearchValue = props.lastSearchValue,
635
+ entryComponent = props.entryComponent,
636
+ isMentionLoading = props.isMentionLoading;
637
+ return /*#__PURE__*/React.createElement(React.Fragment, null, suggestions.map(function (mention, index) {
638
+ return /*#__PURE__*/React.createElement(Entry, {
639
+ key: _this.getMentionKey(mention, index),
640
+ onMentionSelect: onMentionSelect,
641
+ onMentionFocus: onMentionFocus,
642
+ isFocused: focusedOptionIndex === index,
643
+ mention: mention,
644
+ index: index,
645
+ id: "mention-option-" + index,
646
+ theme: theme,
647
+ searchValue: lastSearchValue,
648
+ entryComponent: entryComponent || DefaultEntryComponent
649
+ });
650
+ }), isMentionLoading && /*#__PURE__*/React.createElement("div", {
651
+ className: "list-title",
652
+ style: {
653
+ padding: '8px 8px',
654
+ marginTop: '8px',
655
+ marginLeft: '40px'
656
+ }
657
+ }, "Loading..."));
658
+ };
626
659
  _this.props.callbacks.onChange = _this.onEditorStateChange;
627
660
  return _this;
628
661
  }
@@ -685,17 +718,19 @@ var MentionSuggestions = /*#__PURE__*/function (_Component) {
685
718
  _this$props.onOpenChange;
686
719
  _this$props.onAddMention;
687
720
  _this$props.onSearchChange;
688
- _this$props.suggestions;
721
+ var suggestions = _this$props.suggestions;
689
722
  _this$props.ariaProps;
690
723
  _this$props.callbacks;
691
724
  var _this$props$theme = _this$props.theme,
692
- theme = _this$props$theme === void 0 ? {} : _this$props$theme;
693
- _this$props.store;
725
+ theme = _this$props$theme === void 0 ? {} : _this$props$theme,
726
+ store = _this$props.store;
694
727
  _this$props.entityMutability;
695
728
  var positionSuggestions = _this$props.positionSuggestions;
696
729
  _this$props.mentionTriggers;
697
730
  _this$props.mentionPrefix;
698
- var elementProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
731
+ var handleScroll = _this$props.handleScroll,
732
+ isMentionLoading = _this$props.isMentionLoading,
733
+ elementProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
699
734
  if (popoverComponent || positionSuggestions) {
700
735
  warning('The properties `popoverComponent` and `positionSuggestions` are deprecated and will be removed in @draft-js-plugins/mentions 6.0 . Use `popperOptions` instead');
701
736
  return /*#__PURE__*/React.cloneElement(popoverComponent || /*#__PURE__*/React.createElement("div", null), _extends({}, elementProps, {
@@ -704,43 +739,41 @@ var MentionSuggestions = /*#__PURE__*/function (_Component) {
704
739
  id: "mentions-list-" + this.key,
705
740
  ref: function ref(element) {
706
741
  _this2.popover = element;
707
- }
708
- }), this.props.suggestions.map(function (mention, index) {
709
- return /*#__PURE__*/React.createElement(Entry, {
710
- key: _this2.getMentionKey(mention, index),
711
- onMentionSelect: _this2.onMentionSelect,
712
- onMentionFocus: _this2.onMentionFocus,
713
- isFocused: _this2.state.focusedOptionIndex === index,
714
- mention: mention,
715
- index: index,
716
- id: "mention-option-" + _this2.key + "-" + index,
717
- theme: theme,
718
- searchValue: _this2.lastSearchValue,
719
- entryComponent: entryComponent || DefaultEntryComponent
720
- });
721
- }));
742
+ },
743
+ handleScroll: handleScroll
744
+ }), /*#__PURE__*/React.createElement("div", {
745
+ id: 'mention-suggestion-popoverComponent'
746
+ }, this.renderSuggestionsList({
747
+ suggestions: suggestions,
748
+ focusedOptionIndex: this.state.focusedOptionIndex,
749
+ onMentionSelect: this.onMentionSelect,
750
+ onMentionFocus: this.onMentionFocus,
751
+ theme: theme,
752
+ lastSearchValue: this.lastSearchValue,
753
+ entryComponent: entryComponent,
754
+ isMentionLoading: isMentionLoading
755
+ })));
722
756
  }
723
- if (!this.props.renderEmptyPopup && this.props.suggestions.length === 0) {
757
+ if (!this.props.renderEmptyPopup && suggestions.length === 0 && !isMentionLoading) {
724
758
  return null;
725
759
  }
726
760
  return /*#__PURE__*/React.createElement(PopoverContainer, {
727
- store: this.props.store,
761
+ store: store,
728
762
  popperOptions: popperOptions,
729
- theme: theme
730
- }, this.props.suggestions.map(function (mention, index) {
731
- return /*#__PURE__*/React.createElement(Entry, {
732
- key: _this2.getMentionKey(mention, index),
733
- onMentionSelect: _this2.onMentionSelect,
734
- onMentionFocus: _this2.onMentionFocus,
735
- isFocused: _this2.state.focusedOptionIndex === index,
736
- mention: mention,
737
- index: index,
738
- id: "mention-option-" + _this2.key + "-" + index,
739
- theme: theme,
740
- searchValue: _this2.lastSearchValue,
741
- entryComponent: entryComponent || DefaultEntryComponent
742
- });
743
- }));
763
+ theme: theme,
764
+ handleScroll: handleScroll
765
+ }, /*#__PURE__*/React.createElement("div", {
766
+ id: 'mention-suggestion-PopoverContainer'
767
+ }, this.renderSuggestionsList({
768
+ suggestions: suggestions,
769
+ focusedOptionIndex: this.state.focusedOptionIndex,
770
+ onMentionSelect: this.onMentionSelect,
771
+ onMentionFocus: this.onMentionFocus,
772
+ theme: theme,
773
+ lastSearchValue: this.lastSearchValue,
774
+ entryComponent: entryComponent,
775
+ isMentionLoading: isMentionLoading
776
+ })));
744
777
  };
745
778
  return MentionSuggestions;
746
779
  }(React.Component);
@@ -750,7 +783,9 @@ MentionSuggestions.propTypes = {
750
783
  entityMutability: PropTypes.oneOf(['SEGMENTED', 'IMMUTABLE', 'MUTABLE']),
751
784
  entryComponent: PropTypes.func,
752
785
  onAddMention: PropTypes.func,
753
- suggestions: PropTypes.array.isRequired
786
+ suggestions: PropTypes.array.isRequired,
787
+ handleScroll: PropTypes.func,
788
+ isMentionLoading: PropTypes.bool
754
789
  };
755
790
 
756
791
  var useIsomorphicLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
package/lib/index.esm.js CHANGED
@@ -429,7 +429,8 @@ function Popover(_ref) {
429
429
  _ref$popperOptions = _ref.popperOptions,
430
430
  popperOptions = _ref$popperOptions === void 0 ? {
431
431
  placement: 'bottom-start'
432
- } : _ref$popperOptions;
432
+ } : _ref$popperOptions,
433
+ handleScroll = _ref.handleScroll;
433
434
  var _useState = useState(function () {
434
435
  return clsx(theme.mentionSuggestions, theme.mentionSuggestionsPopup);
435
436
  }),
@@ -451,16 +452,17 @@ function Popover(_ref) {
451
452
  style: styles.popper
452
453
  }, attributes.popper, {
453
454
  className: className,
454
- role: "listbox"
455
+ role: "listbox",
456
+ onScroll: handleScroll
455
457
  }), children);
456
458
  }
457
459
 
458
- var _excluded = ["entryComponent", "popoverComponent", "popperOptions", "popoverContainer", "onOpenChange", "onAddMention", "onSearchChange", "suggestions", "ariaProps", "callbacks", "theme", "store", "entityMutability", "positionSuggestions", "mentionTriggers", "mentionPrefix"];
460
+ var _excluded = ["entryComponent", "popoverComponent", "popperOptions", "popoverContainer", "onOpenChange", "onAddMention", "onSearchChange", "suggestions", "ariaProps", "callbacks", "theme", "store", "entityMutability", "positionSuggestions", "mentionTriggers", "mentionPrefix", "handleScroll", "isMentionLoading"];
459
461
  var MentionSuggestions = /*#__PURE__*/function (_Component) {
460
462
  _inheritsLoose(MentionSuggestions, _Component);
461
- function MentionSuggestions(props) {
463
+ function MentionSuggestions(_props) {
462
464
  var _this;
463
- _this = _Component.call(this, props) || this;
465
+ _this = _Component.call(this, _props) || this;
464
466
  _this.state = {
465
467
  focusedOptionIndex: 0
466
468
  };
@@ -619,6 +621,37 @@ var MentionSuggestions = /*#__PURE__*/function (_Component) {
619
621
  _this.props.ariaProps.ariaOwneeID = undefined;
620
622
  _this.props.onOpenChange(false);
621
623
  };
624
+ _this.renderSuggestionsList = function (props) {
625
+ var suggestions = props.suggestions,
626
+ focusedOptionIndex = props.focusedOptionIndex,
627
+ onMentionSelect = props.onMentionSelect,
628
+ onMentionFocus = props.onMentionFocus,
629
+ theme = props.theme,
630
+ lastSearchValue = props.lastSearchValue,
631
+ entryComponent = props.entryComponent,
632
+ isMentionLoading = props.isMentionLoading;
633
+ return /*#__PURE__*/React.createElement(React.Fragment, null, suggestions.map(function (mention, index) {
634
+ return /*#__PURE__*/React.createElement(Entry, {
635
+ key: _this.getMentionKey(mention, index),
636
+ onMentionSelect: onMentionSelect,
637
+ onMentionFocus: onMentionFocus,
638
+ isFocused: focusedOptionIndex === index,
639
+ mention: mention,
640
+ index: index,
641
+ id: "mention-option-" + index,
642
+ theme: theme,
643
+ searchValue: lastSearchValue,
644
+ entryComponent: entryComponent || DefaultEntryComponent
645
+ });
646
+ }), isMentionLoading && /*#__PURE__*/React.createElement("div", {
647
+ className: "list-title",
648
+ style: {
649
+ padding: '8px 8px',
650
+ marginTop: '8px',
651
+ marginLeft: '40px'
652
+ }
653
+ }, "Loading..."));
654
+ };
622
655
  _this.props.callbacks.onChange = _this.onEditorStateChange;
623
656
  return _this;
624
657
  }
@@ -681,17 +714,19 @@ var MentionSuggestions = /*#__PURE__*/function (_Component) {
681
714
  _this$props.onOpenChange;
682
715
  _this$props.onAddMention;
683
716
  _this$props.onSearchChange;
684
- _this$props.suggestions;
717
+ var suggestions = _this$props.suggestions;
685
718
  _this$props.ariaProps;
686
719
  _this$props.callbacks;
687
720
  var _this$props$theme = _this$props.theme,
688
- theme = _this$props$theme === void 0 ? {} : _this$props$theme;
689
- _this$props.store;
721
+ theme = _this$props$theme === void 0 ? {} : _this$props$theme,
722
+ store = _this$props.store;
690
723
  _this$props.entityMutability;
691
724
  var positionSuggestions = _this$props.positionSuggestions;
692
725
  _this$props.mentionTriggers;
693
726
  _this$props.mentionPrefix;
694
- var elementProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
727
+ var handleScroll = _this$props.handleScroll,
728
+ isMentionLoading = _this$props.isMentionLoading,
729
+ elementProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
695
730
  if (popoverComponent || positionSuggestions) {
696
731
  warning('The properties `popoverComponent` and `positionSuggestions` are deprecated and will be removed in @draft-js-plugins/mentions 6.0 . Use `popperOptions` instead');
697
732
  return /*#__PURE__*/React.cloneElement(popoverComponent || /*#__PURE__*/React.createElement("div", null), _extends({}, elementProps, {
@@ -700,43 +735,41 @@ var MentionSuggestions = /*#__PURE__*/function (_Component) {
700
735
  id: "mentions-list-" + this.key,
701
736
  ref: function ref(element) {
702
737
  _this2.popover = element;
703
- }
704
- }), this.props.suggestions.map(function (mention, index) {
705
- return /*#__PURE__*/React.createElement(Entry, {
706
- key: _this2.getMentionKey(mention, index),
707
- onMentionSelect: _this2.onMentionSelect,
708
- onMentionFocus: _this2.onMentionFocus,
709
- isFocused: _this2.state.focusedOptionIndex === index,
710
- mention: mention,
711
- index: index,
712
- id: "mention-option-" + _this2.key + "-" + index,
713
- theme: theme,
714
- searchValue: _this2.lastSearchValue,
715
- entryComponent: entryComponent || DefaultEntryComponent
716
- });
717
- }));
738
+ },
739
+ handleScroll: handleScroll
740
+ }), /*#__PURE__*/React.createElement("div", {
741
+ id: 'mention-suggestion-popoverComponent'
742
+ }, this.renderSuggestionsList({
743
+ suggestions: suggestions,
744
+ focusedOptionIndex: this.state.focusedOptionIndex,
745
+ onMentionSelect: this.onMentionSelect,
746
+ onMentionFocus: this.onMentionFocus,
747
+ theme: theme,
748
+ lastSearchValue: this.lastSearchValue,
749
+ entryComponent: entryComponent,
750
+ isMentionLoading: isMentionLoading
751
+ })));
718
752
  }
719
- if (!this.props.renderEmptyPopup && this.props.suggestions.length === 0) {
753
+ if (!this.props.renderEmptyPopup && suggestions.length === 0 && !isMentionLoading) {
720
754
  return null;
721
755
  }
722
756
  return /*#__PURE__*/React.createElement(PopoverContainer, {
723
- store: this.props.store,
757
+ store: store,
724
758
  popperOptions: popperOptions,
725
- theme: theme
726
- }, this.props.suggestions.map(function (mention, index) {
727
- return /*#__PURE__*/React.createElement(Entry, {
728
- key: _this2.getMentionKey(mention, index),
729
- onMentionSelect: _this2.onMentionSelect,
730
- onMentionFocus: _this2.onMentionFocus,
731
- isFocused: _this2.state.focusedOptionIndex === index,
732
- mention: mention,
733
- index: index,
734
- id: "mention-option-" + _this2.key + "-" + index,
735
- theme: theme,
736
- searchValue: _this2.lastSearchValue,
737
- entryComponent: entryComponent || DefaultEntryComponent
738
- });
739
- }));
759
+ theme: theme,
760
+ handleScroll: handleScroll
761
+ }, /*#__PURE__*/React.createElement("div", {
762
+ id: 'mention-suggestion-PopoverContainer'
763
+ }, this.renderSuggestionsList({
764
+ suggestions: suggestions,
765
+ focusedOptionIndex: this.state.focusedOptionIndex,
766
+ onMentionSelect: this.onMentionSelect,
767
+ onMentionFocus: this.onMentionFocus,
768
+ theme: theme,
769
+ lastSearchValue: this.lastSearchValue,
770
+ entryComponent: entryComponent,
771
+ isMentionLoading: isMentionLoading
772
+ })));
740
773
  };
741
774
  return MentionSuggestions;
742
775
  }(Component);
@@ -746,7 +779,9 @@ MentionSuggestions.propTypes = {
746
779
  entityMutability: PropTypes.oneOf(['SEGMENTED', 'IMMUTABLE', 'MUTABLE']),
747
780
  entryComponent: PropTypes.func,
748
781
  onAddMention: PropTypes.func,
749
- suggestions: PropTypes.array.isRequired
782
+ suggestions: PropTypes.array.isRequired,
783
+ handleScroll: PropTypes.func,
784
+ isMentionLoading: PropTypes.bool
750
785
  };
751
786
 
752
787
  var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumel/mention",
3
- "version": "5.2.4",
3
+ "version": "5.2.5",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],