Applied app-input/app-form-field/app-button to 9 of 11 Project Editor sections: general, branding, theme, footer, homepage, widgets, languages, navigation, preview. header and features sections were left unchanged - they contain only checkboxes and selects, and no Checkbox/Select primitive exists yet. Theme section's 8 color pickers stay native <input type=color> (app-input's type union doesn't include 'color') but are now wrapped in app-form-field for consistent label/hint treatment. Added app-form-field.full grid-column rule to section.shared.scss (shared by all 11 sections) alongside the existing label.full rule, since the custom element doesn't match that selector. Production build green, arch:check passes.
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { ProjectEditorFacade } from '../facade/project-editor.facade';
|
|
import { TranslatePipe } from '../../../i18n/translate.pipe';
|
|
import { InputComponent } from '../../../shared/ui/input/input.component';
|
|
|
|
@Component({
|
|
selector: 'app-project-editor-widgets-section',
|
|
standalone: true,
|
|
imports: [FormsModule, TranslatePipe, InputComponent],
|
|
templateUrl: './widgets-section.component.html',
|
|
styleUrls: ['./section.shared.scss'],
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
})
|
|
export class ProjectEditorWidgetsSectionComponent {
|
|
private readonly facade = inject(ProjectEditorFacade);
|
|
readonly widgets = this.facade.homepageWidgets;
|
|
|
|
updateWidget(widgetId: string, updater: (props: Record<string, unknown>) => Record<string, unknown>): void {
|
|
this.facade.updateBootstrap(current => ({
|
|
...current,
|
|
pages: current.pages.map(page => ({
|
|
...page,
|
|
sections: page.sections.map(section => ({
|
|
...section,
|
|
widgets: section.widgets.map(widget => widget.id !== widgetId ? widget : ({
|
|
...widget,
|
|
props: updater(widget.props ?? {})
|
|
}))
|
|
}))
|
|
}))
|
|
}));
|
|
}
|
|
|
|
updateProp(widgetId: string, key: string, value: unknown): void {
|
|
this.updateWidget(widgetId, props => ({ ...props, [key]: value }));
|
|
}
|
|
|
|
updateJson(widgetId: string, raw: string): void {
|
|
try {
|
|
this.updateWidget(widgetId, () => JSON.parse(raw));
|
|
} catch {
|
|
// Ignore malformed draft until valid JSON is provided.
|
|
}
|
|
}
|
|
|
|
propsJson(props: Record<string, unknown>): string {
|
|
return JSON.stringify(props ?? {}, null, 2);
|
|
}
|
|
}
|