与tiptap的React-Admin RichTextinput与图像扩展不起作用
我想在React-Admin上插入我的RichTextinput组件,但这不起作用。
即使是在文档上使用水平all子的示例也无法正常工作。该按钮不起作用,默认情况下,RA-Input-input-text已经具有Horizontalrules扩展名,如果我在文本上输入“ ---”,则可以工作。
我想要的确切的是将图像URL放在工具栏上,并将其插入我的光标在编辑器上的位置。但是,即使是手动放置标签(如< img src =“ https://source.unsplash.com/8xznagy4hcy/800x400”/>
),图像没有呈现。
This is my current RichTextInput component:
import {
DefaultEditorOptions,
RichTextInput,
RichTextInputToolbar,
LevelSelect,
FormatButtons,
AlignmentButtons,
ListButtons,
LinkButtons,
QuoteButtons,
ClearButtons
} from 'ra-input-rich-text';
import { ToggleButton } from '@mui/material';
import { useEditor } from '@tiptap/react'
import Image from '@tiptap/extension-image'
import Remove from '@mui/icons-material/Remove';
import { Box } from '@mui/material';
export const MyRichTextInput = ({ size, ...props }) => {
const editor = useEditor(MyEditorOptions)
return (
<RichTextInput
editorOptions={MyEditorOptions}
toolbar={
<RichTextInputToolbar>
<Box sx={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
flexWrap: 'wrap',
}} >
<LevelSelect size={size} />
<FormatButtons size={size} />
<AlignmentButtons size={size} />
<ListButtons size={size} />
<LinkButtons size={size} />
<QuoteButtons size={size} />
<ClearButtons size={size} />
</Box>
<ToggleButton
value="Image"
aria-label="Add an image"
title="Add an image"
onClick={() => editor.chain().focus().setImage({ src: url }).run()}
selected={editor && editor.isActive('image')}
>
<Remove fontSize="inherit" />
</ToggleButton>
</RichTextInputToolbar>
}
label="Body"
source="body"
{...props}
/>
)
}
export const MyEditorOptions = {
...DefaultEditorOptions,
extensions: [
...DefaultEditorOptions.extensions,
Image
],
};
What I need to put an image and this be rendered here and in the "RichTextField"?以及如何创建一个按钮问我URL并将图像插入编辑器上?
I want to insert on my RichTextInput component on React-Admin, but that is not working.
Even the example on the docs about using HorizontalRules are not working too. The button doesn't work, and by default ra-input-rich-text already have HorizontalRules extension, it works if I input "---" on the text.
What I want exactly is put the image url with a button on my toolbar and it would be inserted where my cursor is on the editor. But even manually putting the tag (as <img src="https://source.unsplash.com/8xznAGy4HcY/800x400" />
), the image is not rendered.
This is my current RichTextInput component:
import {
DefaultEditorOptions,
RichTextInput,
RichTextInputToolbar,
LevelSelect,
FormatButtons,
AlignmentButtons,
ListButtons,
LinkButtons,
QuoteButtons,
ClearButtons
} from 'ra-input-rich-text';
import { ToggleButton } from '@mui/material';
import { useEditor } from '@tiptap/react'
import Image from '@tiptap/extension-image'
import Remove from '@mui/icons-material/Remove';
import { Box } from '@mui/material';
export const MyRichTextInput = ({ size, ...props }) => {
const editor = useEditor(MyEditorOptions)
return (
<RichTextInput
editorOptions={MyEditorOptions}
toolbar={
<RichTextInputToolbar>
<Box sx={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
flexWrap: 'wrap',
}} >
<LevelSelect size={size} />
<FormatButtons size={size} />
<AlignmentButtons size={size} />
<ListButtons size={size} />
<LinkButtons size={size} />
<QuoteButtons size={size} />
<ClearButtons size={size} />
</Box>
<ToggleButton
value="Image"
aria-label="Add an image"
title="Add an image"
onClick={() => editor.chain().focus().setImage({ src: url }).run()}
selected={editor && editor.isActive('image')}
>
<Remove fontSize="inherit" />
</ToggleButton>
</RichTextInputToolbar>
}
label="Body"
source="body"
{...props}
/>
)
}
export const MyEditorOptions = {
...DefaultEditorOptions,
extensions: [
...DefaultEditorOptions.extensions,
Image
],
};
What I need to put an image and this be rendered here and in the "RichTextField"? And how to create a button to ask me the url and insert the image on the editor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
他们将React Admin(我使用的4.15)更新为4.20,现在它支持图像和水平线。
现在工具栏响应迅速。
该问题中的信息信息: https://github.com/marmeLab/marmelab/react-admin/问题/7806
They updated React Admin (I was using 4.15) to 4.20 and now it supports Image and horizontal line.
And now the toolbar is responsive.
Mor info in the issue: https://github.com/marmelab/react-admin/issues/7806
TIPTAP通过操纵
编辑器
对象由目标richtextinput
组件进行编辑。您可以使用
richtextinput
组件访问编辑器
对象,使用usetiptapeditor()
。因此,您需要创建另一个按钮或工具栏组件,然后加载它。
然后, myimagebutton组件
将其加载到
richtextinput
中Tiptap edits input by manipulating the
editor
object held by the targetRichTextInput
component.You can access the
editor
object in the context of the targetRichTextInput
component by usinguseTiptapEditor()
.So you need to create another button or toolbar component and then load it.
MyImageButton component
then load it in
RichTextInput