0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Added pintura config for lexical editor (#16698)

refs https://github.com/TryGhost/Team/issues/3034

- passes pintura editor config to Koenig lexical editor, allowing integrating it with lexical cards like image and product.
This commit is contained in:
Rishabh Garg 2023-04-21 20:18:28 +05:30 committed by GitHub
parent f9fbac8fa5
commit a704071448
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -129,10 +129,65 @@ export default class KoenigLexicalEditor extends Component {
@service ghostPaths;
@service session;
@service store;
@service settings;
@inject config;
offers = null;
get pinturaJsUrl() {
if (!this.settings.pintura) {
return null;
}
return this.config.pintura?.js || this.settings.pinturaJsUrl;
}
get pinturaCSSUrl() {
if (!this.settings.pintura) {
return null;
}
return this.config.pintura?.css || this.settings.pinturaCssUrl;
}
get pinturaConfig() {
const jsUrl = this.getImageEditorJSUrl();
const cssUrl = this.getImageEditorCSSUrl();
if (!this.feature.imageEditor || !jsUrl || !cssUrl) {
return null;
}
return {
jsUrl,
cssUrl
};
}
getImageEditorJSUrl() {
let importUrl = this.pinturaJsUrl;
if (!importUrl) {
return null;
}
// load the script from admin root if relative
if (importUrl.startsWith('/')) {
importUrl = window.location.origin + this.ghostPaths.adminRoot.replace(/\/$/, '') + importUrl;
}
return importUrl;
}
getImageEditorCSSUrl() {
let cssImportUrl = this.pinturaCSSUrl;
if (!cssImportUrl) {
return null;
}
// load the css from admin root if relative
if (cssImportUrl.startsWith('/')) {
cssImportUrl = window.location.origin + this.ghostPaths.adminRoot.replace(/\/$/, '') + cssImportUrl;
}
return cssImportUrl;
}
@action
onError(error) {
// ensure we're still showing errors in development
@ -198,7 +253,7 @@ export default class KoenigLexicalEditor extends Component {
fetchEmbed: fetchEmbed,
fetchAutocompleteLinks
};
const cardConfig = Object.assign({}, defaultCardConfig, props.cardConfig);
const cardConfig = Object.assign({}, defaultCardConfig, props.cardConfig, {pinturaConfig: this.pinturaConfig});
const useFileUpload = (type = 'image') => {
const [progress, setProgress] = React.useState(0);