forked from github/plane
fix: lexical
This commit is contained in:
parent
945a75e18b
commit
b8ad8a78c9
@ -1,4 +1,10 @@
|
|||||||
import { EditorState, LexicalEditor, $getRoot, $getSelection } from "lexical";
|
import {
|
||||||
|
EditorState,
|
||||||
|
$getRoot,
|
||||||
|
$getSelection,
|
||||||
|
SerializedEditorState,
|
||||||
|
LexicalEditor,
|
||||||
|
} from "lexical";
|
||||||
import { LexicalComposer } from "@lexical/react/LexicalComposer";
|
import { LexicalComposer } from "@lexical/react/LexicalComposer";
|
||||||
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
||||||
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
||||||
@ -21,7 +27,7 @@ import { getValidatedValue } from "./helpers/editor";
|
|||||||
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
|
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
|
||||||
|
|
||||||
export interface RichTextEditorProps {
|
export interface RichTextEditorProps {
|
||||||
onChange: (state: string) => void;
|
onChange: (state: SerializedEditorState) => void;
|
||||||
id: string;
|
id: string;
|
||||||
value: string;
|
value: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
@ -33,11 +39,17 @@ const RichTextEditor: React.FC<RichTextEditorProps> = ({
|
|||||||
value,
|
value,
|
||||||
placeholder = "Enter some text...",
|
placeholder = "Enter some text...",
|
||||||
}) => {
|
}) => {
|
||||||
function handleChange(state: EditorState, editor: LexicalEditor) {
|
const handleChange = (editorState: EditorState) => {
|
||||||
state.read(() => {
|
editorState.read(() => {
|
||||||
onChange(JSON.stringify(state.toJSON()));
|
let editorData = editorState.toJSON();
|
||||||
|
if (onChange) onChange(editorData);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
// function handleChange(state: EditorState, editor: LexicalEditor) {
|
||||||
|
// state.read(() => {
|
||||||
|
// onChange(state.toJSON());
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LexicalComposer
|
<LexicalComposer
|
||||||
|
@ -6,9 +6,7 @@ export const positionEditorElement = (editor: any, rect: any) => {
|
|||||||
editor.style.left = "-1000px";
|
editor.style.left = "-1000px";
|
||||||
} else {
|
} else {
|
||||||
editor.style.opacity = "1";
|
editor.style.opacity = "1";
|
||||||
editor.style.top = `${
|
editor.style.top = `${rect.top + rect.height + window.pageYOffset + 10}px`;
|
||||||
rect.top + rect.height + window.pageYOffset + 10
|
|
||||||
}px`;
|
|
||||||
editor.style.left = `${
|
editor.style.left = `${
|
||||||
rect.left + window.pageXOffset - editor.offsetWidth / 2 + rect.width / 2
|
rect.left + window.pageXOffset - editor.offsetWidth / 2 + rect.width / 2
|
||||||
}px`;
|
}px`;
|
||||||
@ -22,9 +20,9 @@ export const getValidatedValue = (value: string) => {
|
|||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
try {
|
try {
|
||||||
const json = JSON.parse(value);
|
console.log(value);
|
||||||
return JSON.stringify(json);
|
return value;
|
||||||
} catch (error) {
|
} catch (e) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ type Props = {
|
|||||||
const defaultValues: Partial<IIssue> = {
|
const defaultValues: Partial<IIssue> = {
|
||||||
project: "",
|
project: "",
|
||||||
name: "",
|
name: "",
|
||||||
description: "",
|
// description: "",
|
||||||
state: "",
|
state: "",
|
||||||
sprints: "",
|
sprints: "",
|
||||||
priority: "",
|
priority: "",
|
||||||
@ -176,7 +176,6 @@ const CreateUpdateIssuesModal: React.FC<Props> = ({
|
|||||||
if (!activeWorkspace || !activeProject) return;
|
if (!activeWorkspace || !activeProject) return;
|
||||||
const payload: Partial<IIssue> = {
|
const payload: Partial<IIssue> = {
|
||||||
...formData,
|
...formData,
|
||||||
description: JSON.stringify(formData.description),
|
|
||||||
target_date: formData.target_date ? renderDateFormat(formData.target_date ?? "") : null,
|
target_date: formData.target_date ? renderDateFormat(formData.target_date ?? "") : null,
|
||||||
};
|
};
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
@ -184,9 +184,9 @@ const ListView: React.FC<Props> = ({
|
|||||||
<td className="px-3 py-4 font-medium text-gray-900 truncate text-xs max-w-[15rem]">
|
<td className="px-3 py-4 font-medium text-gray-900 truncate text-xs max-w-[15rem]">
|
||||||
{/* <LexicalViewer
|
{/* <LexicalViewer
|
||||||
id={`descriptionViewer-${issue.id}`}
|
id={`descriptionViewer-${issue.id}`}
|
||||||
value={JSON.parse(issue.description)}
|
value={issue.description}
|
||||||
/> */}
|
/> */}
|
||||||
{issue.description}
|
{/* {issue.description} */}
|
||||||
</td>
|
</td>
|
||||||
) : (key as keyof Properties) === "priority" ? (
|
) : (key as keyof Properties) === "priority" ? (
|
||||||
<td className="px-3 py-4 text-sm font-medium text-gray-900 relative">
|
<td className="px-3 py-4 text-sm font-medium text-gray-900 relative">
|
||||||
|
Loading…
Reference in New Issue
Block a user