Skip to content
Merged
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
13 changes: 13 additions & 0 deletions packages/editor/src/ce/extensions/ai-features/handle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// extensions
import { SideMenuHandleOptions, SideMenuPluginProps } from "@/extensions";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const AIHandlePlugin = (options: SideMenuPluginProps): SideMenuHandleOptions => {
const view = () => {};
const domEvents = {};

return {
view,
domEvents,
};
};
1 change: 1 addition & 0 deletions packages/editor/src/ce/extensions/ai-features/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./handle";
1 change: 1 addition & 0 deletions packages/editor/src/ce/extensions/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./ai-features";
export * from "./document-extensions";
18 changes: 2 additions & 16 deletions packages/editor/src/core/components/editors/document/editor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React from "react";
// components
import { PageRenderer } from "@/components/editors";
// helpers
Expand Down Expand Up @@ -46,13 +46,6 @@ const DocumentEditor = (props: IDocumentEditor) => {
tabIndex,
value,
} = props;
// states
const [hideDragHandleOnMouseLeave, setHideDragHandleOnMouseLeave] = useState<() => void>(() => {});
// this essentially sets the hideDragHandle function from the DragAndDrop extension as the Plugin
// loads such that we can invoke it from react when the cursor leaves the container
const setHideDragHandleFunction = (hideDragHandlerFromDragDrop: () => void) => {
setHideDragHandleOnMouseLeave(() => hideDragHandlerFromDragDrop);
};

// use document editor
const { editor, isIndexedDbSynced } = useDocumentEditor({
Expand All @@ -67,7 +60,6 @@ const DocumentEditor = (props: IDocumentEditor) => {
forwardedRef,
mentionHandler,
placeholder,
setHideDragHandleFunction,
tabIndex,
});

Expand All @@ -80,13 +72,7 @@ const DocumentEditor = (props: IDocumentEditor) => {
if (!editor || !isIndexedDbSynced) return null;

return (
<PageRenderer
editor={editor}
editorContainerClassName={editorContainerClassNames}
hideDragHandle={hideDragHandleOnMouseLeave}
id={id}
tabIndex={tabIndex}
/>
<PageRenderer editor={editor} editorContainerClassName={editorContainerClassNames} id={id} tabIndex={tabIndex} />
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ import { BlockMenu } from "@/components/menus";
type IPageRenderer = {
editor: Editor;
editorContainerClassName: string;
hideDragHandle?: () => void;
id: string;
tabIndex?: number;
};

export const PageRenderer = (props: IPageRenderer) => {
const { editor, editorContainerClassName, hideDragHandle, id, tabIndex } = props;
const { editor, editorContainerClassName, id, tabIndex } = props;
// states
const [linkViewProps, setLinkViewProps] = useState<LinkViewProps>();
const [isOpen, setIsOpen] = useState(false);
Expand Down Expand Up @@ -129,14 +128,9 @@ export const PageRenderer = (props: IPageRenderer) => {
return (
<>
<div className="frame-renderer flex-grow w-full -mx-5" onMouseOver={handleLinkHover}>
<EditorContainer
editor={editor}
editorContainerClassName={editorContainerClassName}
hideDragHandle={hideDragHandle}
id={id}
>
<EditorContainer editor={editor} editorContainerClassName={editorContainerClassName} id={id}>
<EditorContentWrapper editor={editor} id={id} tabIndex={tabIndex} />
{editor && editor.isEditable && <BlockMenu editor={editor} />}
{editor.isEditable && <BlockMenu editor={editor} />}
</EditorContainer>
</div>
{isOpen && linkViewProps && coordinates && (
Expand Down
12 changes: 9 additions & 3 deletions packages/editor/src/core/components/editors/editor-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ interface EditorContainerProps {
children: ReactNode;
editor: Editor | null;
editorContainerClassName: string;
hideDragHandle?: () => void;
id: string;
}

export const EditorContainer: FC<EditorContainerProps> = (props) => {
const { children, editor, editorContainerClassName, hideDragHandle, id } = props;
const { children, editor, editorContainerClassName, id } = props;

const handleContainerClick = () => {
if (!editor) return;
Expand Down Expand Up @@ -53,11 +52,18 @@ export const EditorContainer: FC<EditorContainerProps> = (props) => {
}
};

const handleContainerMouseLeave = () => {
const dragHandleElement = document.querySelector("#editor-side-menu");
if (!dragHandleElement?.classList.contains("side-menu-hidden")) {
dragHandleElement?.classList.add("side-menu-hidden");
}
};

return (
<div
id={`editor-container-${id}`}
onClick={handleContainerClick}
onMouseLeave={hideDragHandle}
onMouseLeave={handleContainerMouseLeave}
className={cn(
"cursor-text relative",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { EditorContentWrapper } from "./editor-content";
type Props = IEditorProps & {
children?: (editor: Editor) => React.ReactNode;
extensions: Extension<any, any>[];
hideDragHandleOnMouseLeave: () => void;
};

export const EditorWrapper: React.FC<Props> = (props) => {
Expand All @@ -20,7 +19,6 @@ export const EditorWrapper: React.FC<Props> = (props) => {
containerClassName,
editorClassName = "",
extensions,
hideDragHandleOnMouseLeave,
id,
initialValue,
fileHandler,
Expand Down Expand Up @@ -56,12 +54,7 @@ export const EditorWrapper: React.FC<Props> = (props) => {
if (!editor) return null;

return (
<EditorContainer
editor={editor}
editorContainerClassName={editorContainerClassName}
id={id}
hideDragHandle={hideDragHandleOnMouseLeave}
>
<EditorContainer editor={editor} editorContainerClassName={editorContainerClassName} id={id}>
{children?.(editor)}
<div className="flex flex-col">
<EditorContentWrapper editor={editor} id={id} tabIndex={tabIndex} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const LiteTextEditor = (props: ILiteTextEditor) => {

const extensions = [EnterKeyExtension(onEnterKeyPress)];

return <EditorWrapper {...props} extensions={extensions} hideDragHandleOnMouseLeave={() => {}} />;
return <EditorWrapper {...props} extensions={extensions} />;
};

const LiteTextEditorWithRef = forwardRef<EditorRefApi, ILiteTextEditor>((props, ref) => (
Expand Down
21 changes: 9 additions & 12 deletions packages/editor/src/core/components/editors/rich-text/editor.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import { forwardRef, useCallback, useState } from "react";
import { forwardRef, useCallback } from "react";
// components
import { EditorWrapper } from "@/components/editors";
import { EditorBubbleMenu } from "@/components/menus";
// extensions
import { DragAndDrop, SlashCommand } from "@/extensions";
import { SideMenuExtension, SlashCommand } from "@/extensions";
// types
import { EditorRefApi, IRichTextEditor } from "@/types";

const RichTextEditor = (props: IRichTextEditor) => {
const { dragDropEnabled, fileHandler } = props;
// states
const [hideDragHandleOnMouseLeave, setHideDragHandleOnMouseLeave] = useState<() => void>(() => {});

// this essentially sets the hideDragHandle function from the DragAndDrop extension as the Plugin
// loads such that we can invoke it from react when the cursor leaves the container
const setHideDragHandleFunction = (hideDragHandlerFromDragDrop: () => void) => {
setHideDragHandleOnMouseLeave(() => hideDragHandlerFromDragDrop);
};

const getExtensions = useCallback(() => {
const extensions = [SlashCommand(fileHandler.upload)];

if (dragDropEnabled) extensions.push(DragAndDrop(setHideDragHandleFunction));
extensions.push(
SideMenuExtension({
aiEnabled: false,
dragDropEnabled: !!dragDropEnabled,
})
);

return extensions;
}, [dragDropEnabled, fileHandler.upload]);

return (
<EditorWrapper {...props} extensions={getExtensions()} hideDragHandleOnMouseLeave={hideDragHandleOnMouseLeave}>
<EditorWrapper {...props} extensions={getExtensions()}>
{(editor) => <>{editor && <EditorBubbleMenu editor={editor} />}</>}
</EditorWrapper>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/core/extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export * from "./typography";
export * from "./core-without-props";
export * from "./document-without-props";
export * from "./custom-code-inline";
export * from "./drag-drop";
export * from "./drop";
export * from "./enter-key-extension";
export * from "./extensions";
export * from "./horizontal-rule";
export * from "./keymap";
export * from "./quote";
export * from "./read-only-extensions";
export * from "./side-menu";
export * from "./slash-commands";
Loading