Skip to content

Commit

Permalink
feat(strapi-tiptap-editor): enable figcaption as property
Browse files Browse the repository at this point in the history
  • Loading branch information
AliKdhim87 committed Sep 27, 2023
1 parent 943b9c3 commit 4402c42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ const Editor = ({ editor, settings, productPrice }: EditorProps) => {
const [mediaLibVisible, setMediaLibVisible] = useState(false);
const [forceInsert, setForceInsert] = useState(false);
const handleToggleMediaLib = () => setMediaLibVisible((prev) => !prev);
const getUpdatedImage = (asset: any) => ({
src: asset.url,
alt: asset.alt,
...(asset.width && { width: asset.width }),
...(asset.height && { height: asset.height }),
...(asset.url?.includes('lazy') || (asset.caption === 'lazy' && { loading: 'lazy' })),
});
const getUpdatedImage = (asset: any) => {
return {
src: asset.url,
alt: asset.alt,
'data-figcaption': asset?.caption,
...(asset.width && { width: asset.width }),
...(asset.height && { height: asset.height }),
...(asset.url?.includes('lazy') || (asset.caption === 'lazy' && { loading: 'lazy' })),
};
};

const handleChangeAssets = (assets: any[]) => {
if (!forceInsert && editor.isActive('image')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ const MediaLib: React.FC<MediaLibProps> = ({ isOpen, onChange, onToggle }) => {
const handleSelectAssets = (images: Image[]) => {
const formattedImages = images.map((image) => ({
...image,
alt: image.alternativeText || image.name,
alt: image.alternativeText,
url: prefixFileUrlWithBackendUrl(image.url),
mime: image.mime,
'data-figcaption': image?.caption,
}));

onChange(formattedImages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ const WysiwygContent = ({
width: { default: null },
height: { default: null },
loading: { default: null },
'data-figcaption': { default: null },
renderHTML: (attributes: any) => {
return {
width: attributes.width,
height: attributes.height,
'data-figcaption': attributes?.caption,
loading: attributes.loading,
};
},
Expand Down

0 comments on commit 4402c42

Please sign in to comment.