Skip to content

Beautiful Open-Source Form Builder

Enhance form components with focused mode image seeding

Julien Nahum7f883e4827c4
diff --git a/client/components/open/forms/components/form-components/PresentationStyleSwitch.vue b/client/components/open/forms/components/form-components/PresentationStyleSwitch.vue
index 039401e6c..7eecdce8c 100644
--- a/client/components/open/forms/components/form-components/PresentationStyleSwitch.vue
+++ b/client/components/open/forms/components/form-components/PresentationStyleSwitch.vue
@@ -60,6 +60,7 @@
<script setup>
import blocksTypes from '~/data/blocks_types.json'
import BlockTypeIcon from '../BlockTypeIcon.vue'
+import seedFocusedFirstBlockImage from '~/lib/forms/seed-focused-image'
const workingFormStore = useWorkingFormStore()
const formRef = storeToRefs(workingFormStore).content
@@ -101,6 +102,8 @@ const modalDescription = computed(() => {
: 'Switch to Focused style.'
})
+// Use shared helper to seed first block image for focused mode
+
function onSelectStyle(newVal) {
if (!form.value) return
const oldVal = currentStyle.value
@@ -134,6 +137,8 @@ function onSelectStyle(newVal) {
form.value.presentation_style = 'focused'
// Ensure large input size in focused mode
form.value.size = 'lg'
+ // Seed first block with an abstract image to highlight focused mode
+ seedFocusedFirstBlockImage(form.value)
workingFormStore.closeAllSidebars()
return
}
@@ -158,6 +163,8 @@ function confirmSwitch() {
// Ensure large input size in focused mode
if (target === 'focused') {
form.value.size = 'lg'
+ // Seed first block with an abstract image to highlight focused mode
+ seedFocusedFirstBlockImage(form.value)
} else if (target === 'classic') {
// Reset input size when returning to classic
form.value.size = 'md'
diff --git a/client/components/pages/forms/create/CreateFormBaseModal.vue b/client/components/pages/forms/create/CreateFormBaseModal.vue
index 7b9eebab6..b7c468b70 100644
--- a/client/components/pages/forms/create/CreateFormBaseModal.vue
+++ b/client/components/pages/forms/create/CreateFormBaseModal.vue
@@ -194,6 +194,7 @@ import AIFormLoadingMessages from "~/components/open/forms/components/AIFormLoad
import { formsApi } from "~/api/forms"
import { useElementSize } from '@vueuse/core'
import TrackClick from '~/components/global/TrackClick.vue'
+import seedFocusedFirstBlockImage from '~/lib/forms/seed-focused-image'
const props = defineProps({
show: { type: Boolean, required: true },
@@ -258,6 +259,8 @@ function selectStyle(style) {
if (workingFormStore.content.settings.navigation_arrows === undefined) {
workingFormStore.content.settings.navigation_arrows = true
}
+ // Seed first block image to highlight focused mode
+ seedFocusedFirstBlockImage(workingFormStore.content)
}
// Close any open sidebars since layout may change
workingFormStore.closeAllSidebars()
@@ -297,10 +300,12 @@ const fetchGeneratedForm = (generationId) => {
.then((data) => {
if (data.ai_form_completion.status === "completed") {
useAlert().success(data.message)
- emit(
- "form-generated",
- JSON.parse(data.ai_form_completion.result),
- )
+ const generated = JSON.parse(data.ai_form_completion.result)
+ // Apply seeding based on user's style choice in the modal
+ if (selectedStyle.value === 'focused') {
+ seedFocusedFirstBlockImage(generated)
+ }
+ emit("form-generated", generated)
emit("close")
} else if (data.ai_form_completion.status === "failed") {
useAlert().error("Something went wrong, please try again.")
diff --git a/client/lib/forms/seed-focused-image.js b/client/lib/forms/seed-focused-image.js
new file mode 100644
index 000000000..89a0f482d
--- /dev/null
+++ b/client/lib/forms/seed-focused-image.js
@@ -0,0 +1,34 @@
+// Utility to seed the first block with a random abstract image and right-split layout
+
+const ABSTRACT_IMAGES = [
+ 'https://images.unsplash.com/photo-1564951434112-64d74cc2a2d7?ixlib=rb-4.1.0&auto=format&fit=crop&q=80&w=1600',
+ 'https://images.unsplash.com/photo-1585854467604-cf2080ccef31?ixlib=rb-4.1.0&auto=format&fit=crop&q=80&w=1600',
+ 'https://images.unsplash.com/photo-1653299832314-5d3dc1e5a83c?ixlib=rb-4.1.0&auto=format&fit=crop&q=80&w=1600',
+ 'https://images.unsplash.com/photo-1604076913837-52ab5629fba9?ixlib=rb-4.1.0&auto=format&fit=crop&q=80&w=1600',
+ 'https://images.unsplash.com/photo-1599496507927-9056debd0f0a?ixlib=rb-4.1.0&auto=format&fit=crop&q=80&w=1600',
+ 'https://images.unsplash.com/photo-1506744038136-46273834b3fb?ixlib=rb-4.1.0&auto=format&fit=crop&q=80&w=1600',
+ 'https://images.unsplash.com/photo-1500964757637-c85e8a162699?ixlib=rb-4.1.0&auto=format&fit=crop&q=80&w=1600',
+ 'https://images.unsplash.com/photo-1519681393784-d120267933ba?ixlib=rb-4.1.0&auto=format&fit=crop&q=80&w=1600'
+]
+
+function getRandomAbstractImageUrl() {
+ const index = Math.floor(Math.random() * ABSTRACT_IMAGES.length)
+ return ABSTRACT_IMAGES[index]
+}
+
+export function seedFocusedFirstBlockImage(content) {
+ if (!content || !Array.isArray(content.properties) || content.properties.length === 0) return
+ const firstBlock = content.properties[0]
+ if (!firstBlock) return
+ firstBlock.image = firstBlock.image || {}
+ if (!firstBlock.image.url) {
+ firstBlock.image.url = getRandomAbstractImageUrl()
+ }
+ if (!firstBlock.image.layout) {
+ firstBlock.image.layout = 'right-split'
+ }
+}
+
+export default seedFocusedFirstBlockImage
+
+