File tree Expand file tree Collapse file tree 3 files changed +29
-14
lines changed
Expand file tree Collapse file tree 3 files changed +29
-14
lines changed Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ import {
174174import {
175175 useBuildSettings ,
176176 useColumnErrorCheck ,
177- useMergeProps ,
177+ useDeepMerge ,
178178} from ' ./composables/helpers' ;
179179import componentEmits from ' ./utils/emits' ;
180180import { AllProps } from ' ./utils/props' ;
@@ -190,7 +190,7 @@ const injectedOptions = inject(globalOptions, {});
190190
191191// -------------------------------------------------- Props //
192192const props = withDefaults (defineProps <Props >(), AllProps );
193- let stepperProps: Settings = reactive <Settings >(useMergeProps (attrs , injectedOptions , props ));
193+ let stepperProps: Settings = reactive <Settings >(useDeepMerge (attrs , injectedOptions , props ));
194194const { direction, title, width } = toRefs (props );
195195const pages = reactive <Page []>(props .pages );
196196const originalPages = JSON .parse (JSON .stringify (pages ));
@@ -208,7 +208,7 @@ const stepperSettings = computed(() => useBindingSettings(settings.value as Part
208208]));
209209
210210watch (props , () => {
211- stepperProps = useMergeProps (attrs , injectedOptions , props );
211+ stepperProps = useDeepMerge (attrs , injectedOptions , props );
212212 settings .value = useBuildSettings (stepperProps );
213213}, { deep: true });
214214
Original file line number Diff line number Diff line change 1+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
12import { watchDebounced } from '@vueuse/core' ;
23import {
34 UseAutoPage ,
45 UseBuildSettings ,
56 UseColumnErrorCheck ,
6- UseMergeProps ,
7+ UseDeepMerge ,
78} from '@/plugin/types' ;
89
910
1011/**
1112* Merges props from three objects.
1213*/
13- export const useMergeProps : UseMergeProps = ( A , B , C ) => {
14- const res : Record < string , any > = { } ;
15-
16- Object . keys ( { ...A , ...B , ...C } ) . map ( key => {
17- res [ key ] = ( C [ key ] ?? B [ key ] ?? A [ key ] ) as any ;
18- } ) ;
14+ type AnyObject = Record < string , any > ;
15+
16+ export const useDeepMerge : UseDeepMerge = ( A , B , C ) => {
17+ const deepMerge = ( obj1 : AnyObject , obj2 : AnyObject ) : AnyObject => {
18+ const result : AnyObject = { ...obj1 } ;
19+ for ( const key in obj2 ) {
20+ if (
21+ obj2 [ key ] &&
22+ typeof obj2 [ key ] === 'object' &&
23+ ! Array . isArray ( obj2 [ key ] )
24+ ) {
25+ result [ key ] = deepMerge ( result [ key ] ?? { } , obj2 [ key ] ) ;
26+ }
27+ else {
28+ result [ key ] = obj2 [ key ] ;
29+ }
30+ }
31+ return result ;
32+ } ;
1933
20- return res ;
34+ // Merge A, B, and C with priority order C > B > A
35+ return deepMerge ( deepMerge ( A , B ) , C ) ;
2136} ;
2237
2338
Original file line number Diff line number Diff line change @@ -257,11 +257,11 @@ export interface UseBuildSettings {
257257 ) : Settings ;
258258}
259259// ------------------------- Helpers //
260- export interface UseMergeProps {
260+ export interface UseDeepMerge {
261261 (
262262 A : Record < string , any > ,
263- B : PluginOptions ,
264- C : Props
263+ B : Record < string , any > ,
264+ C : Record < string , any >
265265 ) : Record < string , any > ;
266266}
267267
You can’t perform that action at this time.
0 commit comments