-
Hi, Is it possible to use plate as a pure rich text viewer that dynamically updates as props update? My use case is as user types in the Plate editor, i would like to show whatever user has entered in a readonly preview. I know we can use the Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
i have the same problem,but i an build a lib and use in a vue project,even if i use the different instant of Plate that also have the problem |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I'm using React's "ultrahack" like this. Since react will destroy the tree based on different key from previous render, everything will be reinitialized with new initialValue. Maybe it's not the best way in terms of performance, but works fine for me.
|
Beta Was this translation helpful? Give feedback.
-
guys im new to plate js and WYSWYG editors in general and im kinda stuck. im trying to render some markdown content passed as props from an api endpoint and it doesnt seem to parse the content into markdown and also I cant seem to delete any text from the editor. I can only update it. here is my code where im passing the coverletter string as a prop to the editor. Any workaround or help is highly appreciated. Thanks import { withProps } from "@udecode/cn";
import {
createPlugins,
Plate,
RenderAfterEditable,
PlateLeaf,
} from "@udecode/plate-common";
import {
createParagraphPlugin,
ELEMENT_PARAGRAPH,
} from "@udecode/plate-paragraph";
import {
createHeadingPlugin,
ELEMENT_H1,
ELEMENT_H2,
ELEMENT_H3,
ELEMENT_H4,
ELEMENT_H5,
ELEMENT_H6,
} from "@udecode/plate-heading";
import {
createBlockquotePlugin,
ELEMENT_BLOCKQUOTE,
} from "@udecode/plate-block-quote";
import {
createCodeBlockPlugin,
ELEMENT_CODE_BLOCK,
ELEMENT_CODE_LINE,
ELEMENT_CODE_SYNTAX,
} from "@udecode/plate-code-block";
import {
createHorizontalRulePlugin,
ELEMENT_HR,
} from "@udecode/plate-horizontal-rule";
import { createLinkPlugin, ELEMENT_LINK } from "@udecode/plate-link";
import {
createImagePlugin,
ELEMENT_IMAGE,
createMediaEmbedPlugin,
ELEMENT_MEDIA_EMBED,
} from "@udecode/plate-media";
import { createCaptionPlugin } from "@udecode/plate-caption";
import {
createMentionPlugin,
ELEMENT_MENTION,
ELEMENT_MENTION_INPUT,
} from "@udecode/plate-mention";
import {
createTablePlugin,
ELEMENT_TABLE,
ELEMENT_TR,
ELEMENT_TD,
ELEMENT_TH,
} from "@udecode/plate-table";
import { createTodoListPlugin, ELEMENT_TODO_LI } from "@udecode/plate-list";
import {
createExcalidrawPlugin,
ELEMENT_EXCALIDRAW,
} from "@udecode/plate-excalidraw";
import {
createBoldPlugin,
MARK_BOLD,
createItalicPlugin,
MARK_ITALIC,
createUnderlinePlugin,
MARK_UNDERLINE,
createStrikethroughPlugin,
MARK_STRIKETHROUGH,
createCodePlugin,
MARK_CODE,
createSubscriptPlugin,
MARK_SUBSCRIPT,
createSuperscriptPlugin,
MARK_SUPERSCRIPT,
} from "@udecode/plate-basic-marks";
import {
createFontColorPlugin,
createFontBackgroundColorPlugin,
createFontSizePlugin,
} from "@udecode/plate-font";
import {
createHighlightPlugin,
MARK_HIGHLIGHT,
} from "@udecode/plate-highlight";
import { createKbdPlugin, MARK_KBD } from "@udecode/plate-kbd";
import { createAlignPlugin } from "@udecode/plate-alignment";
import { createIndentPlugin } from "@udecode/plate-indent";
import { createIndentListPlugin } from "@udecode/plate-indent-list";
import { createLineHeightPlugin } from "@udecode/plate-line-height";
import { createComboboxPlugin } from "@udecode/plate-combobox";
import { createDndPlugin } from "@udecode/plate-dnd";
import { createEmojiPlugin } from "@udecode/plate-emoji";
import {
createExitBreakPlugin,
createSoftBreakPlugin,
} from "@udecode/plate-break";
import { createNodeIdPlugin } from "@udecode/plate-node-id";
import { createResetNodePlugin } from "@udecode/plate-reset-node";
import {
createSelectOnBackspacePlugin,
createDeletePlugin,
} from "@udecode/plate-select";
import { createTabbablePlugin } from "@udecode/plate-tabbable";
import { createTrailingBlockPlugin } from "@udecode/plate-trailing-block";
import {
createCommentsPlugin,
CommentsProvider,
MARK_COMMENT,
} from "@udecode/plate-comments";
import { createAutoformatPlugin } from "@udecode/plate-autoformat";
import { createBlockSelectionPlugin } from "@udecode/plate-selection";
import { createDeserializeDocxPlugin } from "@udecode/plate-serializer-docx";
import { createDeserializeCsvPlugin } from "@udecode/plate-serializer-csv";
import { createDeserializeMdPlugin } from "@udecode/plate-serializer-md";
import { createJuicePlugin } from "@udecode/plate-juice";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import { BlockquoteElement } from "@/components/plate-ui/blockquote-element";
import { CodeBlockElement } from "@/components/plate-ui/code-block-element";
import { CodeLineElement } from "@/components/plate-ui/code-line-element";
import { CodeSyntaxLeaf } from "@/components/plate-ui/code-syntax-leaf";
import { ExcalidrawElement } from "@/components/plate-ui/excalidraw-element";
import { HrElement } from "@/components/plate-ui/hr-element";
import { ImageElement } from "@/components/plate-ui/image-element";
import { LinkElement } from "@/components/plate-ui/link-element";
import { LinkFloatingToolbar } from "@/components/plate-ui/link-floating-toolbar";
import { HeadingElement } from "@/components/plate-ui/heading-element";
import { MediaEmbedElement } from "@/components/plate-ui/media-embed-element";
import { MentionElement } from "@/components/plate-ui/mention-element";
import { MentionInputElement } from "@/components/plate-ui/mention-input-element";
import { MentionCombobox } from "@/components/plate-ui/mention-combobox";
import { ParagraphElement } from "@/components/plate-ui/paragraph-element";
import { TableElement } from "@/components/plate-ui/table-element";
import { TableRowElement } from "@/components/plate-ui/table-row-element";
import {
TableCellElement,
TableCellHeaderElement,
} from "@/components/plate-ui/table-cell-element";
import { TodoListElement } from "@/components/plate-ui/todo-list-element";
import { CodeLeaf } from "@/components/plate-ui/code-leaf";
import { CommentLeaf } from "@/components/plate-ui/comment-leaf";
import { CommentsPopover } from "@/components/plate-ui/comments-popover";
import { HighlightLeaf } from "@/components/plate-ui/highlight-leaf";
import { KbdLeaf } from "@/components/plate-ui/kbd-leaf";
import { Editor } from "@/components/plate-ui/editor";
import { FixedToolbar } from "@/components/plate-ui/fixed-toolbar";
import { FixedToolbarButtons } from "@/components/plate-ui/fixed-toolbar-buttons";
import { FloatingToolbar } from "@/components/plate-ui/floating-toolbar";
import { FloatingToolbarButtons } from "@/components/plate-ui/floating-toolbar-buttons";
import { withPlaceholders } from "@/components/plate-ui/placeholder";
import { withDraggables } from "@/components/plate-ui/with-draggables";
import { EmojiCombobox } from "@/components/plate-ui/emoji-combobox";
const plugins = createPlugins(
[
createParagraphPlugin(),
createHeadingPlugin(),
createBlockquotePlugin(),
createCodeBlockPlugin(),
createHorizontalRulePlugin(),
createLinkPlugin({
renderAfterEditable: LinkFloatingToolbar as RenderAfterEditable,
}),
createImagePlugin(),
createMediaEmbedPlugin(),
createCaptionPlugin({
options: {
pluginKeys: [
// ELEMENT_IMAGE, ELEMENT_MEDIA_EMBED
],
},
}),
createMentionPlugin(),
createTablePlugin(),
createTodoListPlugin(),
createExcalidrawPlugin(),
createBoldPlugin(),
createItalicPlugin(),
createUnderlinePlugin(),
createStrikethroughPlugin(),
createCodePlugin(),
createSubscriptPlugin(),
createSuperscriptPlugin(),
createFontColorPlugin(),
createFontBackgroundColorPlugin(),
createFontSizePlugin(),
createHighlightPlugin(),
createKbdPlugin(),
createAlignPlugin({
inject: {
props: {
validTypes: [
ELEMENT_PARAGRAPH,
// ELEMENT_H1, ELEMENT_H2, ELEMENT_H3
],
},
},
}),
createIndentPlugin({
inject: {
props: {
validTypes: [
ELEMENT_PARAGRAPH,
// ELEMENT_H1, ELEMENT_H2, ELEMENT_H3, ELEMENT_BLOCKQUOTE, ELEMENT_CODE_BLOCK
],
},
},
}),
createIndentListPlugin({
inject: {
props: {
validTypes: [
ELEMENT_PARAGRAPH,
// ELEMENT_H1, ELEMENT_H2, ELEMENT_H3, ELEMENT_BLOCKQUOTE, ELEMENT_CODE_BLOCK
],
},
},
}),
createLineHeightPlugin({
inject: {
props: {
defaultNodeValue: 1.5,
validNodeValues: [1, 1.2, 1.5, 2, 3],
validTypes: [
ELEMENT_PARAGRAPH,
// ELEMENT_H1, ELEMENT_H2, ELEMENT_H3
],
},
},
}),
createComboboxPlugin(),
createDndPlugin({
options: { enableScroller: true },
}),
createEmojiPlugin({
renderAfterEditable: EmojiCombobox,
}),
createExitBreakPlugin({
options: {
rules: [
{
hotkey: "mod+enter",
},
{
hotkey: "mod+shift+enter",
before: true,
},
{
hotkey: "enter",
query: {
start: true,
end: true,
// allow: KEYS_HEADING,
},
relative: true,
level: 1,
},
],
},
}),
createNodeIdPlugin(),
createResetNodePlugin({
options: {
rules: [
// Usage: https://platejs.org/docs/reset-node
],
},
}),
createSelectOnBackspacePlugin({
options: {
query: {
allow: [
// ELEMENT_IMAGE, ELEMENT_HR
],
},
},
}),
createDeletePlugin(),
createSoftBreakPlugin({
options: {
rules: [
{ hotkey: "shift+enter" },
{
hotkey: "enter",
query: {
allow: [
// ELEMENT_CODE_BLOCK, ELEMENT_BLOCKQUOTE, ELEMENT_TD
],
},
},
],
},
}),
createTabbablePlugin(),
createTrailingBlockPlugin({
options: { type: ELEMENT_PARAGRAPH },
}),
createCommentsPlugin(),
createAutoformatPlugin({
options: {
rules: [
// Usage: https://platejs.org/docs/autoformat
],
enableUndoOnDelete: true,
},
}),
createBlockSelectionPlugin({
options: {
sizes: {
top: 0,
bottom: 0,
},
},
}),
createDeserializeDocxPlugin(),
createDeserializeCsvPlugin(),
createDeserializeMdPlugin(),
createJuicePlugin(),
],
{
components: withDraggables(
withPlaceholders({
[ELEMENT_BLOCKQUOTE]: BlockquoteElement,
[ELEMENT_CODE_BLOCK]: CodeBlockElement,
[ELEMENT_CODE_LINE]: CodeLineElement,
[ELEMENT_CODE_SYNTAX]: CodeSyntaxLeaf,
[ELEMENT_EXCALIDRAW]: ExcalidrawElement,
[ELEMENT_HR]: HrElement,
[ELEMENT_IMAGE]: ImageElement,
[ELEMENT_LINK]: LinkElement,
[ELEMENT_H1]: withProps(HeadingElement, { variant: "h1" }),
[ELEMENT_H2]: withProps(HeadingElement, { variant: "h2" }),
[ELEMENT_H3]: withProps(HeadingElement, { variant: "h3" }),
[ELEMENT_H4]: withProps(HeadingElement, { variant: "h4" }),
[ELEMENT_H5]: withProps(HeadingElement, { variant: "h5" }),
[ELEMENT_H6]: withProps(HeadingElement, { variant: "h6" }),
[ELEMENT_MEDIA_EMBED]: MediaEmbedElement,
[ELEMENT_MENTION]: MentionElement,
[ELEMENT_MENTION_INPUT]: MentionInputElement,
[ELEMENT_PARAGRAPH]: ParagraphElement,
[ELEMENT_TABLE]: TableElement,
[ELEMENT_TR]: TableRowElement,
[ELEMENT_TD]: TableCellElement,
[ELEMENT_TH]: TableCellHeaderElement,
[ELEMENT_TODO_LI]: TodoListElement,
[MARK_BOLD]: withProps(PlateLeaf, { as: "strong" }),
[MARK_CODE]: CodeLeaf,
[MARK_COMMENT]: CommentLeaf,
[MARK_HIGHLIGHT]: HighlightLeaf,
[MARK_ITALIC]: withProps(PlateLeaf, { as: "em" }),
[MARK_KBD]: KbdLeaf,
[MARK_STRIKETHROUGH]: withProps(PlateLeaf, { as: "s" }),
[MARK_SUBSCRIPT]: withProps(PlateLeaf, { as: "sub" }),
[MARK_SUPERSCRIPT]: withProps(PlateLeaf, { as: "sup" }),
[MARK_UNDERLINE]: withProps(PlateLeaf, { as: "u" }),
})
),
}
);
export function PlateEditor({ coverLetter }: { coverLetter: string }) {
const value = [
{
id: "1",
type: "p",
children: [{ text: coverLetter }],
},
];
return (
<DndProvider backend={HTML5Backend}>
<CommentsProvider users={{}} myUserId="1">
<Plate plugins={plugins} value={value}>
<FixedToolbar>
<FixedToolbarButtons />
</FixedToolbar>
<Editor />
<FloatingToolbar>
<FloatingToolbarButtons />
</FloatingToolbar>
<MentionCombobox items={[]} />
<CommentsPopover />
</Plate>
</CommentsProvider>
</DndProvider>
);
} |
Beta Was this translation helpful? Give feedback.
initialValue
, orvalue
, or setValue but updating the value without slate transforms will require you to call resetEditor