update: improved logic with backwards compat.

This commit is contained in:
Darshan committed 2025-11-26 14:28:19 +05:30
1 parent bfe8024583
commit 9c9d5b7be6
4 files changed
+41 -9

No files matched your search

@@ -7,6 +7,8 @@
import PinkBackground from '$lib/images/pink-background.svg';
import { bannerSpacing } from '$lib/layout/headerAlert.svelte';
import { createEventDispatcher, onMount, onDestroy } from 'svelte';
import { headerAlert } from '$lib/stores/headerAlert';
import { ProfileMode, resolvedProfile } from '$lib/profiles/index.svelte';
export let variant: 'gradient' | 'image' = 'gradient';
@@ -16,12 +18,13 @@
const queryLayoutElements = () => ({
header: document.querySelector<HTMLElement>('main > header'),
sidebar: document.querySelector<HTMLElement>('main > div > nav'),
content: document.querySelector<HTMLElement>('main > div > section')
content: document.querySelector<HTMLElement>('main > div > section'),
contentDiv: document.querySelector<HTMLElement>('main > .content')
});
const setNavigationHeight = () => {
const alertHeight = container?.getBoundingClientRect()?.height || 0;
const { header, sidebar, content } = queryLayoutElements();
const { header, sidebar, content, contentDiv } = queryLayoutElements();
const headerHeight = header?.getBoundingClientRect().height || 0;
const offset = alertHeight + (!$isTabletViewport && header ? headerHeight : 0);
@@ -35,11 +38,18 @@
// for sidebar and sub-navigation!
bannerSpacing.set(`${alertHeight}px`);
headerAlert.setTopSpacing(alertHeight);
}
if (content) {
content.style.paddingBlockStart = `${alertHeight}px`;
}
if (contentDiv && resolvedProfile.id === ProfileMode.STUDIO) {
const headerHeight = header?.getBoundingClientRect().height ?? 0;
// push the content enough to show the borders of the content view!
contentDiv.style.marginBlockStart = `${alertHeight + headerHeight}px`;
}
};
onMount(setNavigationHeight);
+12
View File
@@ -1,6 +1,7 @@
<script module lang="ts">
import { writable } from 'svelte/store';
// this is for backwards compatibility rn.
export const bannerSpacing = writable<string | null>(null);
</script>
@@ -12,6 +13,8 @@
import { Icon } from '@appwrite.io/pink-svelte';
import { IconX } from '@appwrite.io/pink-icons-svelte';
import { afterNavigate } from '$app/navigation';
import { headerAlert } from '$lib/stores/headerAlert';
import { ProfileMode, resolvedProfile } from '$lib/profiles/index.svelte';
export let title: string;
export let type: 'info' | 'success' | 'warning' | 'error' | 'default' = 'info';
@@ -31,12 +34,15 @@
const header: HTMLHeadingElement = document.querySelector('main > header');
const sidebar: HTMLElement = document.querySelector('main > div > nav');
const contentSection: HTMLElement = document.querySelector('main > div > section');
const contentDiv: HTMLElement = document.querySelector('main > .content');
if (alertHeight) {
// for sidebar and sub-navigation!
bannerSpacing.set(`${alertHeight}px`);
headerAlert.setTopSpacing(alertHeight);
} else {
bannerSpacing.set(undefined);
headerAlert.setTopSpacing(0);
}
if (header) {
@@ -54,6 +60,12 @@
if (contentSection) {
contentSection.style.paddingBlockStart = `${alertHeight}px`;
}
if (contentDiv && resolvedProfile.id === ProfileMode.STUDIO) {
const headerHeight = header?.getBoundingClientRect().height ?? 0;
// push the content enough to show the borders of the content view!
contentDiv.style.marginBlockStart = `${alertHeight + headerHeight}px`;
}
}
onMount(() => {
+16 -5
View File
@@ -9,11 +9,13 @@ export type HeaderAlert = {
};
export type HeaderAlertStore = {
top: number;
components: HeaderAlert[];
};
function createHeaderAlertStore() {
const { subscribe, update, set } = writable<HeaderAlertStore>({
const { set, update, subscribe } = writable<HeaderAlertStore>({
top: 0,
components: []
});
@@ -48,14 +50,23 @@ function createHeaderAlertStore() {
});
return component as HeaderAlert;
},
isShowing: (): boolean => {
let showing = false;
setTopSpacing: (value: number) => {
update((n) => {
return {
...n,
top: value
};
});
},
getTopSpacing: (): number => {
let top = 0;
update((n) => {
if (n.components.length === 0) return n;
showing = n.components.some((c) => c.show);
top = n.top;
return n;
});
return showing;
return top;
}
};
}
+1 -2
View File
@@ -12,7 +12,6 @@ import { headerAlert } from '$lib/stores/headerAlert';
const COMPONENT_SELECTOR = 'imagine-web-components-wrapper[data-appwrite-studio]';
const STYLE_ATTRIBUTE = 'data-appwrite-studio-style';
const BLOCK_BANNER_OFFSET = 96;
const BLOCK_START_BASE_OFFSET = 48;
export const CDN_URL = env?.PUBLIC_IMAGINE_CDN_URL + '/web-components.js';
export const CDN_CSS_URL = env?.PUBLIC_IMAGINE_CDN_URL + '/web-components.css';
@@ -196,7 +195,7 @@ function updatePosition() {
return;
}
const bannerOffset = headerAlert.isShowing() ? BLOCK_BANNER_OFFSET : 0;
const bannerOffset = headerAlert.getTopSpacing();
const rect = anchorElement.getBoundingClientRect();
const { offsetX, offsetY } = currentOptions;