2026-07-17 18:14:58 +04:00
|
|
|
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
|
2026-07-10 13:43:53 +04:00
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
|
|
import { ProjectEditorFacade } from '../facade/project-editor.facade';
|
|
|
|
|
import { TranslatePipe } from '../../../i18n/translate.pipe';
|
2026-07-17 16:18:22 +04:00
|
|
|
import { TranslateService } from '../../../i18n/translate.service';
|
feat(project-editor): adopt Design System primitives across editor sections
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.
2026-07-15 07:55:38 +04:00
|
|
|
import { InputComponent } from '../../../shared/ui/input/input.component';
|
2026-07-16 02:07:41 +04:00
|
|
|
import { SectionCardComponent } from '../../../shared/ui/section-card/section-card.component';
|
|
|
|
|
import { ToggleComponent } from '../../../shared/ui/toggle/toggle.component';
|
2026-07-10 13:43:53 +04:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-project-editor-widgets-section',
|
|
|
|
|
standalone: true,
|
2026-07-16 02:07:41 +04:00
|
|
|
imports: [FormsModule, TranslatePipe, InputComponent, SectionCardComponent, ToggleComponent],
|
2026-07-10 13:43:53 +04:00
|
|
|
templateUrl: './widgets-section.component.html',
|
|
|
|
|
styleUrls: ['./section.shared.scss'],
|
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
|
|
|
})
|
|
|
|
|
export class ProjectEditorWidgetsSectionComponent {
|
|
|
|
|
private readonly facade = inject(ProjectEditorFacade);
|
2026-07-17 16:18:22 +04:00
|
|
|
private readonly translate = inject(TranslateService);
|
2026-07-10 13:43:53 +04:00
|
|
|
readonly widgets = this.facade.homepageWidgets;
|
2026-07-17 16:18:22 +04:00
|
|
|
readonly fieldError = (key: string): string | null => {
|
|
|
|
|
const messageKey = this.facade.fieldError(key);
|
|
|
|
|
return messageKey ? this.translate.t(messageKey) : null;
|
|
|
|
|
};
|
2026-07-10 13:43:53 +04:00
|
|
|
|
|
|
|
|
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 }));
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-17 18:14:58 +04:00
|
|
|
private readonly jsonDrafts = signal<Record<string, string>>({});
|
|
|
|
|
private readonly jsonErrors = signal<Record<string, string>>({});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* While the textarea holds invalid JSON, keep showing the user's own draft
|
|
|
|
|
* (not the last-committed props) so their in-progress edit isn't silently
|
|
|
|
|
* overwritten on the next change-detection pass.
|
|
|
|
|
*/
|
|
|
|
|
widgetJsonValue(widgetId: string, props: Record<string, unknown>): string {
|
|
|
|
|
return this.jsonDrafts()[widgetId] ?? this.propsJson(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
widgetJsonError(widgetId: string): string | null {
|
|
|
|
|
return this.jsonErrors()[widgetId] ?? null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-10 13:43:53 +04:00
|
|
|
updateJson(widgetId: string, raw: string): void {
|
|
|
|
|
try {
|
2026-07-17 18:14:58 +04:00
|
|
|
const parsed = JSON.parse(raw);
|
|
|
|
|
this.updateWidget(widgetId, () => parsed);
|
|
|
|
|
this.jsonDrafts.update(({ [widgetId]: _removed, ...rest }) => rest);
|
|
|
|
|
this.jsonErrors.update(({ [widgetId]: _removed, ...rest }) => rest);
|
2026-07-10 13:43:53 +04:00
|
|
|
} catch {
|
2026-07-17 18:14:58 +04:00
|
|
|
this.jsonDrafts.update(drafts => ({ ...drafts, [widgetId]: raw }));
|
|
|
|
|
this.jsonErrors.update(errors => ({ ...errors, [widgetId]: this.translate.t('builder.widgetJsonInvalid') }));
|
2026-07-10 13:43:53 +04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
propsJson(props: Record<string, unknown>): string {
|
|
|
|
|
return JSON.stringify(props ?? {}, null, 2);
|
|
|
|
|
}
|
|
|
|
|
}
|