Skip to content

Commit

Permalink
refact: layout setting value change
Browse files Browse the repository at this point in the history
  • Loading branch information
biaogebusy committed Jan 31, 2024
1 parent 4856d0f commit cd5e51c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 43 deletions.
10 changes: 1 addition & 9 deletions src/app/core/state/BuilderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ export class BuilderState {
public builderRightContent$ = new Subject<IBuilderDynamicContent>();
public showRightDrawer: boolean = true;
public builderPopupSelect$ = new Subject<any>();
public builderLayoutSetting$ = new Subject<{
value: {
[key: string]: any;
};
index?: number | undefined;
uuid: string;
i?: number | undefined;
pageIndex?: number;
}>();
public builderLayoutSetting$ = new Subject<any>();
public closeBuilderRightDrawer$ = new Subject<boolean>();
public fixedChange$ = new Subject<boolean>();
public animateDisable$ = new Subject<boolean>();
Expand Down
24 changes: 6 additions & 18 deletions src/app/modules/builder/layout-builder/layout-builder.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,12 @@ export class LayoutBuilderComponent implements OnInit, OnDestroy {
const { i, index, value, uuid } = data;
if (uuid === this.uuid) {
const { elements } = this.content;
Object.keys(value).forEach((config) => {
if (config) {
if (
this.isLayoutWidget(i, index) &&
isNumber(i) &&
isNumber(index)
) {
elements[i].elements[index] = defaultsDeep(
value[config],
elements[i].elements[index]
);
}
if (i !== undefined && i >= 0 && index === undefined) {
elements[i] = defaultsDeep(value[config], elements[i]);
}
}
});

if (this.isLayoutWidget(i, index) && isNumber(i) && isNumber(index)) {
elements[i].elements[index] = value;
}
if (i !== undefined && i >= 0 && index === undefined) {
elements[i] = value;
}
this.builder.updateComponent(this.pageIndex, this.content);
this.cd.detectChanges();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,15 @@ export class LayoutSettingComponent implements OnInit, OnDestroy {
// emit value to dynamic component
if (level === 'block') {
this.builder.builderLayoutSetting$.next({
value: {
bgImg,
},
value: this.content.content,
pageIndex: this.content.pageIndex,
uuid: this.content.uuid,
});
}

if (level === 'layout') {
this.builder.builderLayoutSetting$.next({
value: {
bgImg,
},
value: this.content.content,
i: this.content.i,
uuid: this.content.uuid,
});
Expand All @@ -88,11 +84,14 @@ export class LayoutSettingComponent implements OnInit, OnDestroy {
};
this.cd.detectChanges();
this.builder.builderLayoutSetting$.next({
value: {
bg: {
classes: 'bg-fill-width',
value: defaultsDeep(
{
bg: {
classes: 'bg-fill-width',
},
},
},
this.content.content
),
index: this.content.index,
uuid: this.content.uuid,
});
Expand All @@ -101,8 +100,14 @@ export class LayoutSettingComponent implements OnInit, OnDestroy {
onModelChange(value: any) {
const { flex } = value;
this.renderLayoutPreview(flex);
let content: any = {};
Object.keys(value).forEach((config) => {
if (config) {
content = defaultsDeep(value[config], this.content.content);
}
});
this.builder.builderLayoutSetting$.next({
value,
value: content,
i: this.content.i,
index: this.content.index,
pageIndex: this.content.pageIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ export class DynamicComponentComponent
.subscribe((data) => {
const { value, uuid, pageIndex } = data;
if (this.uuid === uuid) {
let content: any = {};
Object.keys(value).forEach((config) => {
content = defaultsDeep(value[config], content);
});
this.inputs = { ...this.inputs.content, ...content };
this.inputs = value;
this.loadComponent();
if (isNumber(pageIndex)) {
this.builder.updateComponent(pageIndex, this.inputs);
Expand Down

0 comments on commit cd5e51c

Please sign in to comment.