Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const CollaborativeDocumentEditor: React.FC<ICollaborativeDocumentEditorProps> =
serverHandler,
tabIndex,
user,
showEmojiSuggestion,
} = props;

const extensions: Extensions = [];
Expand Down Expand Up @@ -72,6 +73,7 @@ const CollaborativeDocumentEditor: React.FC<ICollaborativeDocumentEditorProps> =
serverHandler,
tabIndex,
user,
showEmojiSuggestion,
});

const editorContainerClassNames = getEditorClassNames({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const EditorWrapper: React.FC<Props> = (props) => {
placeholder,
tabIndex,
value,
showEmojiSuggestion,
} = props;

const editor = useEditor({
Expand All @@ -59,6 +60,7 @@ export const EditorWrapper: React.FC<Props> = (props) => {
placeholder,
tabIndex,
value,
showEmojiSuggestion,
});

const editorContainerClassName = getEditorClassNames({
Expand Down
22 changes: 3 additions & 19 deletions packages/editor/src/core/extensions/emoji/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Plugin, PluginKey, Transaction } from "@tiptap/pm/state";
import Suggestion, { SuggestionOptions } from "@tiptap/suggestion";
import emojiRegex from "emoji-regex";
import { isEmojiSupported } from "is-emoji-supported";
import { CORE_EXTENSIONS } from "@/constants/extension";
// helpers
import { customFindSuggestionMatch } from "@/helpers/find-suggestion-match";

Expand Down Expand Up @@ -88,7 +89,7 @@ export const inputRegex = /:([a-zA-Z0-9_+-]+):$/;
export const pasteRegex = /:([a-zA-Z0-9_+-]+):/g;

export const Emoji = Node.create<EmojiOptions, EmojiStorage>({
name: "emoji",
name: CORE_EXTENSIONS.EMOJI,

inline: true,

Expand All @@ -99,7 +100,6 @@ export const Emoji = Node.create<EmojiOptions, EmojiStorage>({
addOptions() {
return {
HTMLAttributes: {},
// emojis: ,
emojis: emojis,
enableEmoticons: false,
forceFallbackImages: false,
Expand Down Expand Up @@ -193,23 +193,7 @@ export const Emoji = Node.create<EmojiOptions, EmojiStorage>({
return ["span", attributes, `:${node.attrs.name}:`];
}

const renderFallbackImage = false;

return [
"span",
attributes,
renderFallbackImage
? [
"img",
{
src: emojiItem.fallbackImage,
draggable: "false",
loading: "lazy",
align: "absmiddle",
},
]
: emojiItem.emoji || `:${emojiItem.shortcodes[0]}:`,
];
return ["span", attributes, emojiItem.emoji || `:${emojiItem.shortcodes[0]}:`];
},

renderText({ node }) {
Expand Down
29 changes: 27 additions & 2 deletions packages/editor/src/core/extensions/emoji/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@
import { gitHubEmojis, shortcodeToEmoji } from "@tiptap/extension-emoji";
import { MarkdownSerializerState } from "@tiptap/pm/markdown";
import { Node as ProseMirrorNode } from "@tiptap/pm/model";
import { Emoji } from "./emoji";
import { Emoji, EmojiOptions } from "./emoji";
import suggestion from "./suggestion";

export const EmojiExtension = Emoji.extend({
export interface ExtendedEmojiOptions extends EmojiOptions {
showSuggestion: boolean;
}

export const EmojiExtension = Emoji.extend<ExtendedEmojiOptions>({
addOptions() {
return {
...this.parent?.(),
showSuggestion: true,
};
},

addStorage() {
return {
...this.parent?.(),
Expand All @@ -23,8 +34,22 @@ export const EmojiExtension = Emoji.extend({
},
};
},

addProseMirrorPlugins() {
const parentPlugins = this.parent?.() || [];

// If showSuggestion is false, filter out the Suggestion plugin
if (!this.options.showSuggestion) {
// Filter out the suggestion plugin (first plugin from parent)
return parentPlugins.filter((plugin, index) => index !== 0);
}

// If showSuggestion is true, return all parent plugins
return parentPlugins;
},
}).configure({
emojis: gitHubEmojis,
suggestion: suggestion,
enableEmoticons: true,
showSuggestion: true,
});
13 changes: 11 additions & 2 deletions packages/editor/src/core/extensions/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ import { CustomStarterKitExtension } from "./starter-kit";

type TArguments = Pick<
IEditorProps,
"disabledExtensions" | "flaggedExtensions" | "fileHandler" | "mentionHandler" | "placeholder" | "tabIndex"
| "disabledExtensions"
| "flaggedExtensions"
| "fileHandler"
| "mentionHandler"
| "placeholder"
| "tabIndex"
| "showEmojiSuggestion"
> & {
enableHistory: boolean;
editable: boolean;
Expand All @@ -54,13 +60,16 @@ export const CoreEditorExtensions = (args: TArguments): Extensions => {
placeholder,
tabIndex,
editable,
showEmojiSuggestion,
} = args;

const extensions = [
CustomStarterKitExtension({
enableHistory,
}),
EmojiExtension,
EmojiExtension.configure({
showSuggestion: showEmojiSuggestion ?? true,
}),
CustomQuoteExtension,
CustomHorizontalRule,
CustomKeymap,
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/core/hooks/use-collaborative-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const useCollaborativeEditor = (props: TCollaborativeEditorHookProps) =>
serverHandler,
tabIndex,
user,
showEmojiSuggestion,
} = props;
// states
const [hasServerConnectionFailed, setHasServerConnectionFailed] = useState(false);
Expand Down Expand Up @@ -113,6 +114,7 @@ export const useCollaborativeEditor = (props: TCollaborativeEditorHookProps) =>
placeholder,
provider,
tabIndex,
showEmojiSuggestion,
});

return {
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/core/hooks/use-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const useEditor = (props: TEditorHookProps) => {
provider,
tabIndex,
value,
showEmojiSuggestion,
} = props;

const editor = useTiptapEditor(
Expand All @@ -67,6 +68,7 @@ export const useEditor = (props: TEditorHookProps) => {
mentionHandler,
placeholder,
tabIndex,
showEmojiSuggestion,
}),
...extensions,
],
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/core/types/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export interface IEditorProps {
placeholder?: string | ((isFocused: boolean, value: string) => string);
tabIndex?: number;
value?: string | null;
showEmojiSuggestion?: boolean;
}

export type ILiteTextEditorProps = IEditorProps;
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/core/types/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type TEditorHookProps = TCoreHookProps &
| "placeholder"
| "tabIndex"
| "value"
| "showEmojiSuggestion"
> & {
editable: boolean;
enableHistory: boolean;
Expand All @@ -44,6 +45,7 @@ export type TCollaborativeEditorHookProps = TCoreHookProps &
| "onTransaction"
| "placeholder"
| "tabIndex"
| "showEmojiSuggestion"
> &
Pick<ICollaborativeDocumentEditorProps, "embedHandler" | "realtimeConfig" | "serverHandler" | "user">;

Expand Down