Ghost/ghost/admin/app/utils/fetch-koenig-lexical.js
Daniel Lockyer 639be25f1d Updated Koenig-Lexical bundling
refs https://github.com/TryGhost/DevOps/issues/83

- this will now continue use the dev server assets if we tell it to,
  or copy the dependency package files to the built folder otherwise
- removes `editor` from config API because it's no longer needed
- removes dependency on `editor.url` in tests, as this no longer exists
- edits dev script to pass dev server URL as env var
- adds `@tryghost/koenig-lexical` dependency to Admin
2023-10-04 12:50:21 +02:00

23 lines
884 B
JavaScript

import config from 'ghost-admin/config/environment';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
export default async function fetchKoenigLexical() {
if (window['@tryghost/koenig-lexical']) {
return window['@tryghost/koenig-lexical'];
}
// If we pass an editor URL (the env var from the dev script), use that
// Else, if we pass a CDN URL, use that
// Else, use the asset root from the ghostPaths util
const baseUrl = (config.editorUrl || (config.cdnUrl ? `${config.cdnUrl}assets/koenig-lexical/` : `${ghostPaths().assetRootWithHost}koenig-lexical/`));
const url = new URL(`${baseUrl}koenig-lexical.umd.js`);
if (url.protocol === 'http:') {
await import(`http://${url.host}${url.pathname}`);
} else {
await import(`https://${url.host}${url.pathname}`);
}
return window['@tryghost/koenig-lexical'];
}