Skip to content

Commit

Permalink
chore: Remove duplicate trigger definition for suggestion extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
tommoor committed Jan 23, 2025
1 parent 184e562 commit 53f4c72
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 20 deletions.
5 changes: 1 addition & 4 deletions app/editor/components/BlockMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import SuggestionsMenu, {
} from "./SuggestionsMenu";
import SuggestionsMenuItem from "./SuggestionsMenuItem";

type Props = Omit<
SuggestionsMenuProps,
"renderMenuItem" | "items" | "trigger"
> &
type Props = Omit<SuggestionsMenuProps, "renderMenuItem" | "items"> &
Required<Pick<SuggestionsMenuProps, "embeds">>;

function BlockMenu(props: Props) {
Expand Down
3 changes: 1 addition & 2 deletions app/editor/components/EmojiMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Emoji = {

type Props = Omit<
SuggestionsMenuProps<Emoji>,
"renderMenuItem" | "items" | "embeds" | "trigger"
"renderMenuItem" | "items" | "embeds"
>;

const EmojiMenu = (props: Props) => {
Expand Down Expand Up @@ -48,7 +48,6 @@ const EmojiMenu = (props: Props) => {
return (
<SuggestionsMenu
{...props}
trigger=":"
filterable={false}
renderMenuItem={(item, _index, options) => (
<EmojiMenuItem
Expand Down
3 changes: 1 addition & 2 deletions app/editor/components/MentionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface MentionItem extends MenuItem {

type Props = Omit<
SuggestionsMenuProps<MentionItem>,
"renderMenuItem" | "items" | "embeds" | "trigger"
"renderMenuItem" | "items" | "embeds"
>;

function MentionMenu({ search, isActive, ...rest }: Props) {
Expand Down Expand Up @@ -194,7 +194,6 @@ function MentionMenu({ search, isActive, ...rest }: Props) {
{...rest}
isActive={isActive}
filterable={false}
trigger="@"
search={search}
onSelect={handleSelect}
renderMenuItem={(item, _index, options) => (
Expand Down
3 changes: 2 additions & 1 deletion app/editor/components/PasteMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SuggestionsMenuItem from "./SuggestionsMenuItem";

type Props = Omit<
SuggestionsMenuProps,
"renderMenuItem" | "items" | "embeds"
"renderMenuItem" | "items" | "embeds" | "trigger"
> & {
pastedText: string;
embeds: EmbedDescriptor[];
Expand Down Expand Up @@ -48,6 +48,7 @@ const PasteMenu = ({ embeds, ...props }: Props) => {
return (
<SuggestionsMenu
{...props}
trigger=""
filterable={false}
renderMenuItem={(item, _index, options) => (
<SuggestionsMenuItem
Expand Down
26 changes: 16 additions & 10 deletions app/editor/extensions/BlockMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,28 @@ export default class BlockMenuExtension extends Suggestion {
];
}

private handleClose = action((insertNewLine: boolean) => {
const { view } = this.editor;

if (insertNewLine) {
const transaction = view.state.tr.split(view.state.selection.to);
view.dispatch(transaction);
view.focus();
}

this.state.open = false;
});

widget = ({ rtl }: WidgetProps) => {
const { props, view } = this.editor;
const { props } = this.editor;

return (
<BlockMenu
rtl={rtl}
trigger={this.options.trigger}
isActive={this.state.open}
search={this.state.query}
onClose={action((insertNewLine) => {
if (insertNewLine) {
const transaction = view.state.tr.split(view.state.selection.to);
view.dispatch(transaction);
view.focus();
}

this.state.open = false;
})}
onClose={this.handleClose}
uploadFile={props.uploadFile}
onFileUploadStart={props.onFileUploadStart}
onFileUploadStop={props.onFileUploadStop}
Expand Down
1 change: 1 addition & 0 deletions app/editor/extensions/EmojiMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default class EmojiMenuExtension extends Suggestion {
widget = ({ rtl }: WidgetProps) => (
<EmojiMenu
rtl={rtl}
trigger={this.options.trigger}
isActive={this.state.open}
search={this.state.query}
onClose={action(() => {
Expand Down
1 change: 1 addition & 0 deletions app/editor/extensions/MentionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class MentionMenuExtension extends Suggestion {
widget = ({ rtl }: WidgetProps) => (
<MentionMenu
rtl={rtl}
trigger={this.options.trigger}
isActive={this.state.open}
search={this.state.query}
onClose={action(() => {
Expand Down
1 change: 0 additions & 1 deletion app/editor/extensions/PasteHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ export default class PasteHandler extends Extension {
widget = ({ rtl }: WidgetProps) => (
<PasteMenu
rtl={rtl}
trigger=""
embeds={this.editor.props.embeds}
pastedText={this.state.pastedText}
isActive={this.state.open}
Expand Down

0 comments on commit 53f4c72

Please sign in to comment.