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:
parent
6e10308f53
commit
c2dd9e79c5
1 changed files with 14 additions and 0 deletions
|
|
@ -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],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue