TS: Converted app file and animations service
Some checks are pending
lint-js / build (push) Waiting to run
test-js / build (push) Waiting to run

Extracted functions out of app file during changes to clean up.
Altered animation function to use normal css prop names instead of JS
CSS prop names.
This commit is contained in:
Dan Brown
2024-10-11 15:19:19 +01:00
parent 2e8d6ce7d9
commit f41c02cbd7
11 changed files with 108 additions and 84 deletions

View File

@ -99,3 +99,49 @@ export function wait(timeMs: number): Promise<any> {
setTimeout(res, timeMs);
});
}
/**
* Generate a full URL from the given relative URL, using a base
* URL defined in the head of the page.
*/
export function baseUrl(path: string): string {
let targetPath = path;
const baseUrlMeta = document.querySelector('meta[name="base-url"]');
if (!baseUrlMeta) {
throw new Error('Could not find expected base-url meta tag in document');
}
let basePath = baseUrlMeta.getAttribute('content') || '';
if (basePath[basePath.length - 1] === '/') {
basePath = basePath.slice(0, basePath.length - 1);
}
if (targetPath[0] === '/') {
targetPath = targetPath.slice(1);
}
return `${basePath}/${targetPath}`;
}
/**
* Get the current version of BookStack in use.
* Grabs this from the version query used on app assets.
*/
function getVersion(): string {
const styleLink = document.querySelector('link[href*="/dist/styles.css?version="]');
if (!styleLink) {
throw new Error('Could not find expected style link in document for version use');
}
const href = (styleLink.getAttribute('href') || '');
return href.split('?version=').pop() || '';
}
/**
* Perform a module import, Ensuring the import is fetched with the current
* app version as a cache-breaker.
*/
export function importVersioned(moduleName: string): Promise<object> {
const importPath = window.baseUrl(`dist/${moduleName}.js?version=${getVersion()}`);
return import(importPath);
}