feat(CkEditorComponent): add dynamic navbar height adjustment

Implement dynamic adjustment of the editor's viewport offset based on the navbar height during window resize events.
This commit is contained in:
Jérémy Munsch 2026-09-29 14:21:49 +02:00
parent 6e10308f53
commit c2dd9e79c5
No known key found for this signature in database
GPG key ID: 2AAECDA6B7330F91

View file

@ -85,6 +85,17 @@ const counterParameters = reactive<{
// * COMPUTED
const isUsedWithProps = computed<boolean>(() => attrs.json === undefined);
function getNavbarHeight(): number {
const navbar = document.querySelector(".sticky-top .navbar") ?? document.querySelector(".sticky-top");
return navbar ? Math.round(navbar.getBoundingClientRect().height) : 48;
}
const handleResize = (): void => {
if (editorInstance.value) {
editorInstance.value.ui.viewportOffset = {top: getNavbarHeight(),};
}
};
// * LIFECYCLE
onMounted(() => {
const json = String(attrs.json ?? "{}"),
@ -98,16 +109,19 @@ onMounted(() => {
}
hiddenInput.value?.addEventListener("ss:ck:set-data", onExternalSetData as EventListener);
window.addEventListener("resize", handleResize);
});
onBeforeUnmount(() => {
hiddenInput.value?.removeEventListener("ss:ck:set-data", onExternalSetData as EventListener);
window.removeEventListener("resize", handleResize);
});
// * METHODS
async function makeSuperBuild(): Promise<void> {
const editorConfig: EditorConfig = {
ui: {viewportOffset: {top: getNavbarHeight()}},
attachTo: ckeditor.value as HTMLElement,
plugins: builtinPlugins,
translations: [frTranslations],