Thanks to visit codestin.com
Credit goes to github.com

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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"@tailwindcss/forms": "^0.5.10",
"@tailwindcss/line-clamp": "^0.4.4",
"@tailwindcss/typography": "^0.5.16",
"@tiptap/extension-bubble-menu": "^3.7.0",
"@tiptap/extension-bullet-list": "^2.12.0",
"@tiptap/extension-highlight": "^3.6.5",
"@tiptap/extension-link": "^2.11.5",
Expand Down
4 changes: 3 additions & 1 deletion src/core/components/canvas/IframeInitialContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const IframeInitialContent: string = `<!doctype html>
</style>
<style>
.react-colorful {
height: 150px !important;
height: 120px !important;
width: 180px !important;
}
.react-colorful > div {
Expand All @@ -69,6 +69,8 @@ export const IframeInitialContent: string = `<!doctype html>
width: 16px !important;
height: 16px !important;
border: 1.5px solid #fff !important;
cursor: pointer !important;
z-index: 10002 !important;
}
</style>
<style type="text/tailwindcss">
Expand Down
61 changes: 15 additions & 46 deletions src/core/components/canvas/static/with-block-text-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { useInlineEditing } from "@/core/hooks/use-inline-editing";
import { useLanguages } from "@/core/hooks/use-languages";
import { useSelectedBlockIds } from "@/core/hooks/use-selected-blockIds";
import { useUpdateBlocksProps } from "@/core/hooks/use-update-blocks-props";
import { MenuBar, useRTEditor } from "@/core/rjsf-widgets";
import { useRTEditor } from "@/core/rjsf-widgets/rte-widget/use-rte-editor";
import RteMenubar from "@/core/rjsf-widgets/rte-widget/rte-menu-bar";
import { ChaiBlock } from "@/types/chai-block";
import { getRegisteredChaiBlock } from "@chaibuilder/runtime";
import { useDebouncedCallback } from "@react-hookz/web";
import { EditorContent } from "@tiptap/react";
import { BubbleMenu, EditorContent } from "@tiptap/react";
import { cloneDeep, get, has } from "lodash-es";
import { createElement, memo, useCallback, useEffect, useMemo, useRef, useState } from "react";

Expand Down Expand Up @@ -46,7 +47,6 @@ const RichTextEditor = memo(
onChange: (content: string) => void;
onEscape: (e: KeyboardEvent) => void;
}) => {
const [showMenu, setShowMenu] = useState({ show: false, top: 0, left: 0 });
const { document } = useFrame();

const editor = useRTEditor({
Expand Down Expand Up @@ -86,41 +86,6 @@ const RichTextEditor = memo(
event: new FocusEvent("focus"),
transaction: [] as any,
});
setTimeout(() => {
const editorRect = editor?.view?.dom?.getBoundingClientRect();
let top = editorRect?.top - 32;
let left = editorRect?.left;
if (top < 0) {
top = editorRect?.bottom;
}
if (left + 276 >= document.body.offsetWidth) {
left = editorRect?.right - 276;
}
setShowMenu({ show: true, top: top, left: left });
}, 100);

let timeout: any;
const handleScroll = () => {
setShowMenu({ show: false, top: 0, left: 0 });
clearTimeout(timeout);
timeout = setTimeout(() => {
const editorRect = editor?.view?.dom?.getBoundingClientRect();
let top = editorRect?.top - 32;
let left = editorRect?.left;
if (top < 0) {
top = editorRect?.bottom;
}
if (left + 276 >= document.body.offsetWidth) {
left = editorRect?.right - 276;
}
setShowMenu({ show: true, top: top, left: left });
}, 500);
};
document.addEventListener("scroll", handleScroll);
return () => {
document.removeEventListener("scroll", handleScroll);
clearTimeout(timeout);
};
}, [editor]);

const editorClassName = useMemo(() => {
Expand All @@ -138,14 +103,18 @@ const RichTextEditor = memo(
};

return (
<div onKeyDown={onKeyDown} onClick={(e) => e.stopPropagation()} className="relative">
{showMenu?.show && (
<div className="fixed" style={{ top: showMenu.top, left: showMenu.left }}>
<MenuBar editor={editor} from="canvas" />
</div>
)}
<EditorContent onKeyDown={onKeyDown} value={blockContent} editor={editor} className={editorClassName} />
</div>
editor && (
<div onKeyDown={onKeyDown} onClick={(e) => e.stopPropagation()} className="relative">
<BubbleMenu
editor={editor}
shouldShow={() => editor && editor?.isFocused}
tippyOptions={{ duration: 100, arrow: true, hideOnClick: false }}
className="w-max">
<RteMenubar editor={editor} from="canvas" />
</BubbleMenu>
<EditorContent onKeyDown={onKeyDown} value={blockContent} editor={editor} className={editorClassName} />
</div>
)
);
},
);
Expand Down
8 changes: 7 additions & 1 deletion src/core/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ select:focus {

/* Color picker */
.react-colorful {
height: 150px !important;
height: 120px !important;
width: 180px !important;
}
.react-colorful > div {
Expand All @@ -243,6 +243,12 @@ select:focus {
width: 16px !important;
height: 16px !important;
border: 1.5px solid #fff !important;
cursor: pointer !important;
z-index: 10002 !important;
}

.ProseMirror {
@apply min-h-[100px] outline-none;
}

.rte {
Expand Down
2 changes: 1 addition & 1 deletion src/core/rjsf-widgets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export * from "@/core/rjsf-widgets/Icon";
export * from "@/core/rjsf-widgets/image";
export * from "@/core/rjsf-widgets/link";
export * from "@/core/rjsf-widgets/row-col";
export * from "@/core/rjsf-widgets/rte-widget";
export * from "@/core/rjsf-widgets/rte-widget/rte-widget";
export * from "@/core/rjsf-widgets/slider";
export * from "@/core/rjsf-widgets/sources";
Loading
Loading