8383 <Input v-model =" importPrefix" :placeholder =" __('e.g. hero_')" />
8484 </Field >
8585
86+ <Field
87+ v-if =" selectedFieldsetHasSections"
88+ :label =" __('Section Behavior')"
89+ :instructions =" __('Choose whether imported fieldset sections should be preserved or flattened into this section.')"
90+ class =" mt-6"
91+ >
92+ <RadioGroup v-model =" sectionBehavior" >
93+ <Radio :label =" __('Preserve')" :description =" __('Keep imported sections as-is.')" value =" preserve" />
94+ <Radio :label =" __('Flatten')" :description =" __('Merge all fields into this section.')" value =" flatten" />
95+ </RadioGroup >
96+ </Field >
97+
8698 <Button
8799 class =" w-full mt-6"
88100 variant =" primary"
98110
99111<script >
100112import { nanoid as uniqid } from ' nanoid' ;
101- import { Combobox , Button , Input , Heading , Field , Stack , StackClose } from ' @/components/ui' ;
113+ import { Combobox , Button , Input , Heading , Field , Stack , StackClose , RadioGroup , Radio } from ' @/components/ui' ;
102114import { usePage } from ' @inertiajs/vue3' ;
103115
104116export default {
105- components: { Heading, Combobox, Button, Input, Field, Stack, StackClose },
117+ components: { Heading, Combobox, Button, Input, Field, Stack, StackClose, RadioGroup, Radio },
106118
107119 props: {
108120 excludeFieldset: String ,
@@ -134,6 +146,7 @@ export default {
134146 reference: null ,
135147 fieldset: null ,
136148 importPrefix: null ,
149+ sectionBehavior: ' preserve' ,
137150 fieldSuggestions,
138151 fieldsetSuggestions: fieldsets .map ((fieldset ) => ({
139152 value: fieldset .handle ,
@@ -143,6 +156,22 @@ export default {
143156 };
144157 },
145158
159+ computed: {
160+ selectedFieldsetHasSections () {
161+ if (! this .fieldset ) return false ;
162+
163+ return this .fieldsets .find ((f ) => f .handle === this .fieldset )? .has_sections === true ;
164+ },
165+ },
166+
167+ watch: {
168+ fieldset () {
169+ if (! this .selectedFieldsetHasSections ) {
170+ this .sectionBehavior = ' preserve' ;
171+ }
172+ },
173+ },
174+
146175 mounted () {
147176 if (this .withCommandPalette ) {
148177 this .addToCommandPalette ();
@@ -171,12 +200,18 @@ export default {
171200 },
172201
173202 linkFieldset () {
174- this . linkAndClose ( {
203+ const field = {
175204 _id: uniqid (),
176205 type: ' import' ,
177206 fieldset: this .fieldset ,
178207 prefix: this .importPrefix ,
179- });
208+ };
209+
210+ if (this .selectedFieldsetHasSections ) {
211+ field .section_behavior = this .sectionBehavior ;
212+ }
213+
214+ this .linkAndClose (field);
180215 },
181216
182217 linkAndClose (field ) {
@@ -185,6 +220,7 @@ export default {
185220 this .reference = null ;
186221 this .fieldset = null ;
187222 this .importPrefix = null ;
223+ this .sectionBehavior = ' preserve' ;
188224 },
189225
190226 addToCommandPalette () {
0 commit comments