Skip to content

Commit 9fd6a20

Browse files
committed
Fix button positioning and test change for static site
1 parent d47ee07 commit 9fd6a20

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

composables/useVisualEditing.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ interface ApplyOptions {
99
}
1010

1111
export default function useVisualEditing() {
12-
// Use useState for state that persists across navigation
1312
const isVisualEditingEnabled = useState('visual-editing-enabled', () => false);
1413
const route = useRoute();
1514

1615
const {
1716
public: { enableVisualEditing, directusUrl },
1817
} = useRuntimeConfig();
1918

20-
// Check query param on composable initialization.
21-
if (route.query['visual-editing'] === 'true' && enableVisualEditing) {
22-
isVisualEditingEnabled.value = true;
23-
} else if (route.query['visual-editing'] === 'false') {
24-
isVisualEditingEnabled.value = false;
25-
}
19+
onMounted(() => {
20+
if (enableVisualEditing && route.query['visual-editing'] === 'true') {
21+
isVisualEditingEnabled.value = true;
22+
} else if (route.query['visual-editing'] === 'false') {
23+
isVisualEditingEnabled.value = false;
24+
}
25+
});
2626

2727
const apply = (options: Pick<ApplyOptions, 'elements' | 'onSaved' | 'customClass'>) => {
2828
if (!isVisualEditingEnabled.value) return;
@@ -33,7 +33,6 @@ export default function useVisualEditing() {
3333
});
3434
};
3535

36-
// Auto-apply visual editing on mount for block components
3736
const autoApply = (elementSelector: string, refreshCallback?: () => Promise<void>) => {
3837
onMounted(() => {
3938
if (!isVisualEditingEnabled.value) return;
@@ -45,7 +44,7 @@ export default function useVisualEditing() {
4544
elements: el,
4645
customClass: 'visual-editing-button-class',
4746
onSaved: async () => {
48-
if (refreshCallback) await refreshCallback();
47+
await refreshCallback?.();
4948
await nextTick();
5049
apply({ elements: el });
5150
},

pages/[...permalink].vue

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ onMounted(() => {
173173
<template>
174174
<div class="relative">
175175
<PageBuilder v-if="sections" :spacing-top="page?.spacing_top" :sections="sections" />
176-
<div
177-
v-if="isVisualEditingEnabled && page"
178-
class="fixed z-50 w-full bottom-4 left-0 right-0 p-4 flex justify-center items-center gap-2"
179-
>
176+
<div v-if="isVisualEditingEnabled && page" class="visual-editing-button-container">
180177
<!-- If you're not using the visual editor it's safe to remove this element. Just a helper to let editors add edit / add new blocks to a page. -->
181178
<BaseButton
182179
id="visual-editing-button"
@@ -193,6 +190,20 @@ onMounted(() => {
193190
</template>
194191

195192
<style>
193+
.visual-editing-button-container {
194+
position: fixed;
195+
z-index: 50;
196+
width: 100%;
197+
bottom: 1rem;
198+
left: 0;
199+
right: 0;
200+
padding: 1rem;
201+
display: flex;
202+
justify-content: center;
203+
align-items: center;
204+
gap: 0.5rem;
205+
}
206+
196207
.directus-visual-editing-overlay.visual-editing-button-class .directus-visual-editing-edit-button {
197208
position: absolute;
198209
inset: 0;

0 commit comments

Comments
 (0)