Skip to content

Commit

Permalink
fix: set src image to a relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoa committed Nov 11, 2024
1 parent 9c189e4 commit 8588bc9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/editors/sharedComponents/ImageUploadModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ export const imgProps = ({
selection,
lmsEndpointUrl,
editorType,
isLibrary,
}) => {
let url = selection?.externalUrl;
if (url?.startsWith(lmsEndpointUrl) && editorType !== 'expandable') {
const sourceEndIndex = lmsEndpointUrl.length;
url = url.substring(sourceEndIndex);
}
if (isLibrary) {
const index = url.indexOf('static/');
url = url.substring(index);
}
return {
src: url,
alt: settings.isDecorative ? '' : settings.altText,
Expand All @@ -36,13 +41,14 @@ export const imgProps = ({
};

export const saveToEditor = ({
settings, selection, lmsEndpointUrl, editorType, editorRef,
settings, selection, lmsEndpointUrl, editorType, editorRef, isLibrary,
}) => {
const newImgTag = module.hooks.imgTag({
settings,
selection,
lmsEndpointUrl,
editorType,
isLibrary,
});

editorRef.current.execCommand(
Expand Down Expand Up @@ -130,6 +136,7 @@ const ImageUploadModal = ({
images,
editorType,
lmsEndpointUrl,
isLibrary,
}) => {
if (selection && selection.externalUrl) {
return (
Expand All @@ -148,6 +155,7 @@ const ImageUploadModal = ({
setSelection,
lmsEndpointUrl,
clearSelection,
isLibrary,
}),
returnToSelection: clearSelection,
}}
Expand Down Expand Up @@ -190,6 +198,7 @@ ImageUploadModal.propTypes = {
images: PropTypes.shape({}).isRequired,
lmsEndpointUrl: PropTypes.string.isRequired,
editorType: PropTypes.string,
isLibrary: PropTypes.string,
};

export const ImageUploadModalInternal = ImageUploadModal; // For testing only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ exports[`TinyMceWidget snapshots SourcecodeModal is not rendered 1`] = `
],
}
}
isLibrary={true}
isOpen={false}
lmsEndpointUrl="http://localhost:18000"
selection="hooks.selectedImage.selection"
Expand Down Expand Up @@ -146,6 +147,7 @@ exports[`TinyMceWidget snapshots renders as expected with default behavior 1`] =
],
}
}
isLibrary={true}
isOpen={false}
lmsEndpointUrl="http://localhost:18000"
selection="hooks.selectedImage.selection"
Expand Down
1 change: 1 addition & 0 deletions src/editors/sharedComponents/TinyMceWidget/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const TinyMceWidget = ({
images={imagesRef}
editorType={editorType}
lmsEndpointUrl={getConfig().LMS_BASE_URL}
isLibrary
{...imageSelection}
/>
)}
Expand Down

0 comments on commit 8588bc9

Please sign in to comment.