-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
insert Image via url #24
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for that you can change position of image by dragging and dropping to the upper nodes but it has internal bug of duplication |
export const InsertImageButton: (props: InsertImageButtonProps) => JSX.Element = ({ icon, iconColor = '#ffffff' }) => { | ||
const editor = useSlate(); | ||
return ( | ||
<Button | ||
onMouseDown={(event) => { | ||
event.preventDefault(); | ||
const url = window.prompt('Enter the URL of the image:'); | ||
if (!url) return; | ||
insertImage(editor, url); | ||
}} | ||
> | ||
<Icon reversed active={false} svg={icon} color={iconColor}> | ||
image | ||
</Icon> | ||
</Button> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
insert Image via url logic and button
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for that you can change position of image by dragging and dropping to the upper nodes but it has internal bug of duplication
@Hamzaalam we have to resolve this issue, there should be some way to add some text to the bottom of the image, especially if the last node is an image node. Also, moving the image doesn't remove it.
The best way would be to add an empty node on either enter key or down key press.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fahad-Mahmood inserting the empty block at the bottom of image is working on Enter
, just need to trace the cursor and only triggers this at the end of the line.
if (type === 'image' && block.properties) { | ||
return { id: block._id, type, children, url: block.properties.document[0].properties }; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deserialization (DB to slate)
case `image`: | ||
return ( | ||
<div {...attributes}> | ||
<div contentEditable={false}> | ||
<Image src={element.url} /> | ||
</div> | ||
{children} | ||
</div> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Image element to render the image inside of slate editor
export const Image = styled.img` | ||
display: block; | ||
max-width: 100%; | ||
max-height: 20em; | ||
padding: 4px 0px 0px 20px; | ||
`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
image Styled component
const withImages = (editor: ReactEditor) => { | ||
const { isVoid } = editor; | ||
const localEditor = editor; | ||
localEditor.isVoid = (element) => { | ||
return element.type === 'image' ? true : isVoid(element); | ||
}; | ||
return localEditor; | ||
}; | ||
export default withImages; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Image plugin to support he drag and drop of existing image
let properties = []; | ||
if (textType === 'image') { | ||
properties.push(paragraphNode.url); | ||
} else { | ||
properties = getParagraphProperties(childNodes); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serialization logic (slate to DB structure)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works fine!
Data structure to save into DB:
Slate internal data structure: