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';
|
feat(builder): implement visual homepage builder
New HomepageOverviewComponent (Tasks 1+8), mounted at the top of the
existing Homepage section page: completion ring, active/hidden section
counts, recommended next step, last-modified timestamp, and a 6-item
Homepage Health checklist (hero/categories/products/promotion/
newsletter/any-sections) - all derived from the real page.sections/
widgets data already in the facade, nothing fabricated.
Existing page-level drag-and-drop reordering (homepage-section's
CdkDragDrop over page.sections) was already implemented pre-Sprint 5 -
left as-is per "build on top of, do not replace."
Widgets section (Task 2) rewritten from a bare list into visual cards:
per-widget icon + humanized type label (hero/categories/product-
collection), a visible/hidden toggle and badge, up/down move buttons
(keyboard-accessible reorder within a section - see Known limitations
for why this replaces pointer drag for widgets specifically), duplicate,
and remove (with confirm). The existing per-type field editors (hero/
categories/product-collection) are unchanged; the raw-JSON fallback for
unknown widget types now sits behind a collapsed "Advanced settings"
disclosure instead of being the default view.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-18 10:24:13 +04:00
|
|
|
import { WidgetConfig } from '../../../shared/models/config';
|
|
|
|
|
|
|
|
|
|
const WIDGET_ICONS: Record<string, string> = {
|
|
|
|
|
hero: 'pi-image',
|
|
|
|
|
categories: 'pi-th-large',
|
|
|
|
|
'product-collection': 'pi-box',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const WIDGET_LABEL_KEYS: Record<string, string> = {
|
|
|
|
|
hero: 'builder.widgetTypeHero',
|
|
|
|
|
categories: 'builder.widgetTypeCategories',
|
|
|
|
|
'product-collection': 'builder.widgetTypeProducts',
|
|
|
|
|
};
|
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',
|
feat(builder): implement visual homepage builder
New HomepageOverviewComponent (Tasks 1+8), mounted at the top of the
existing Homepage section page: completion ring, active/hidden section
counts, recommended next step, last-modified timestamp, and a 6-item
Homepage Health checklist (hero/categories/products/promotion/
newsletter/any-sections) - all derived from the real page.sections/
widgets data already in the facade, nothing fabricated.
Existing page-level drag-and-drop reordering (homepage-section's
CdkDragDrop over page.sections) was already implemented pre-Sprint 5 -
left as-is per "build on top of, do not replace."
Widgets section (Task 2) rewritten from a bare list into visual cards:
per-widget icon + humanized type label (hero/categories/product-
collection), a visible/hidden toggle and badge, up/down move buttons
(keyboard-accessible reorder within a section - see Known limitations
for why this replaces pointer drag for widgets specifically), duplicate,
and remove (with confirm). The existing per-type field editors (hero/
categories/product-collection) are unchanged; the raw-JSON fallback for
unknown widget types now sits behind a collapsed "Advanced settings"
disclosure instead of being the default view.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-18 10:24:13 +04:00
|
|
|
styleUrls: ['./section.shared.scss', './widgets-section.component.scss'],
|
2026-07-10 13:43:53 +04:00
|
|
|
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
|
|
|
|
feat(builder): implement visual homepage builder
New HomepageOverviewComponent (Tasks 1+8), mounted at the top of the
existing Homepage section page: completion ring, active/hidden section
counts, recommended next step, last-modified timestamp, and a 6-item
Homepage Health checklist (hero/categories/products/promotion/
newsletter/any-sections) - all derived from the real page.sections/
widgets data already in the facade, nothing fabricated.
Existing page-level drag-and-drop reordering (homepage-section's
CdkDragDrop over page.sections) was already implemented pre-Sprint 5 -
left as-is per "build on top of, do not replace."
Widgets section (Task 2) rewritten from a bare list into visual cards:
per-widget icon + humanized type label (hero/categories/product-
collection), a visible/hidden toggle and badge, up/down move buttons
(keyboard-accessible reorder within a section - see Known limitations
for why this replaces pointer drag for widgets specifically), duplicate,
and remove (with confirm). The existing per-type field editors (hero/
categories/product-collection) are unchanged; the raw-JSON fallback for
unknown widget types now sits behind a collapsed "Advanced settings"
disclosure instead of being the default view.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-18 10:24:13 +04:00
|
|
|
widgetIcon(type: string): string {
|
|
|
|
|
return WIDGET_ICONS[type] ?? 'pi-stop';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
widgetLabel(widget: WidgetConfig): string {
|
|
|
|
|
if (widget.title) {
|
|
|
|
|
return widget.title;
|
|
|
|
|
}
|
|
|
|
|
const key = WIDGET_LABEL_KEYS[widget.type];
|
|
|
|
|
return key ? this.translate.t(key) : widget.type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isVisible(widget: WidgetConfig): boolean {
|
|
|
|
|
return widget.visible !== false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleVisible(widgetId: string): void {
|
|
|
|
|
this.updateWidgetConfig(widgetId, widget => ({ ...widget, visible: !this.isVisible(widget) }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
moveWidget(widgetId: string, direction: -1 | 1): void {
|
|
|
|
|
this.facade.updateBootstrap(current => ({
|
|
|
|
|
...current,
|
|
|
|
|
pages: current.pages.map(page => ({
|
|
|
|
|
...page,
|
|
|
|
|
sections: page.sections.map(section => {
|
|
|
|
|
const index = section.widgets.findIndex(w => w.id === widgetId);
|
|
|
|
|
if (index === -1) {
|
|
|
|
|
return section;
|
|
|
|
|
}
|
|
|
|
|
const targetIndex = index + direction;
|
|
|
|
|
if (targetIndex < 0 || targetIndex >= section.widgets.length) {
|
|
|
|
|
return section;
|
|
|
|
|
}
|
|
|
|
|
const widgets = [...section.widgets];
|
|
|
|
|
[widgets[index], widgets[targetIndex]] = [widgets[targetIndex], widgets[index]];
|
|
|
|
|
return { ...section, widgets };
|
|
|
|
|
})
|
|
|
|
|
}))
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
duplicateWidget(widgetId: string): void {
|
|
|
|
|
this.facade.updateBootstrap(current => ({
|
|
|
|
|
...current,
|
|
|
|
|
pages: current.pages.map(page => ({
|
|
|
|
|
...page,
|
|
|
|
|
sections: page.sections.map(section => {
|
|
|
|
|
const index = section.widgets.findIndex(w => w.id === widgetId);
|
|
|
|
|
if (index === -1) {
|
|
|
|
|
return section;
|
|
|
|
|
}
|
|
|
|
|
const original = section.widgets[index];
|
|
|
|
|
const copy: WidgetConfig = { ...original, id: `${original.id}-copy-${Date.now()}` };
|
|
|
|
|
const widgets = [...section.widgets];
|
|
|
|
|
widgets.splice(index + 1, 0, copy);
|
|
|
|
|
return { ...section, widgets };
|
|
|
|
|
})
|
|
|
|
|
}))
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeWidget(widgetId: string): void {
|
|
|
|
|
if (!confirm(this.translate.t('builder.widgetRemoveConfirm'))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.facade.updateBootstrap(current => ({
|
|
|
|
|
...current,
|
|
|
|
|
pages: current.pages.map(page => ({
|
|
|
|
|
...page,
|
|
|
|
|
sections: page.sections.map(section => ({
|
|
|
|
|
...section,
|
|
|
|
|
widgets: section.widgets.filter(w => w.id !== widgetId)
|
|
|
|
|
}))
|
|
|
|
|
}))
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private updateWidgetConfig(widgetId: string, updater: (widget: WidgetConfig) => WidgetConfig): void {
|
2026-07-10 13:43:53 +04:00
|
|
|
this.facade.updateBootstrap(current => ({
|
|
|
|
|
...current,
|
|
|
|
|
pages: current.pages.map(page => ({
|
|
|
|
|
...page,
|
|
|
|
|
sections: page.sections.map(section => ({
|
|
|
|
|
...section,
|
feat(builder): implement visual homepage builder
New HomepageOverviewComponent (Tasks 1+8), mounted at the top of the
existing Homepage section page: completion ring, active/hidden section
counts, recommended next step, last-modified timestamp, and a 6-item
Homepage Health checklist (hero/categories/products/promotion/
newsletter/any-sections) - all derived from the real page.sections/
widgets data already in the facade, nothing fabricated.
Existing page-level drag-and-drop reordering (homepage-section's
CdkDragDrop over page.sections) was already implemented pre-Sprint 5 -
left as-is per "build on top of, do not replace."
Widgets section (Task 2) rewritten from a bare list into visual cards:
per-widget icon + humanized type label (hero/categories/product-
collection), a visible/hidden toggle and badge, up/down move buttons
(keyboard-accessible reorder within a section - see Known limitations
for why this replaces pointer drag for widgets specifically), duplicate,
and remove (with confirm). The existing per-type field editors (hero/
categories/product-collection) are unchanged; the raw-JSON fallback for
unknown widget types now sits behind a collapsed "Advanced settings"
disclosure instead of being the default view.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-18 10:24:13 +04:00
|
|
|
widgets: section.widgets.map(widget => widget.id !== widgetId ? widget : updater(widget))
|
2026-07-10 13:43:53 +04:00
|
|
|
}))
|
|
|
|
|
}))
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
feat(builder): implement visual homepage builder
New HomepageOverviewComponent (Tasks 1+8), mounted at the top of the
existing Homepage section page: completion ring, active/hidden section
counts, recommended next step, last-modified timestamp, and a 6-item
Homepage Health checklist (hero/categories/products/promotion/
newsletter/any-sections) - all derived from the real page.sections/
widgets data already in the facade, nothing fabricated.
Existing page-level drag-and-drop reordering (homepage-section's
CdkDragDrop over page.sections) was already implemented pre-Sprint 5 -
left as-is per "build on top of, do not replace."
Widgets section (Task 2) rewritten from a bare list into visual cards:
per-widget icon + humanized type label (hero/categories/product-
collection), a visible/hidden toggle and badge, up/down move buttons
(keyboard-accessible reorder within a section - see Known limitations
for why this replaces pointer drag for widgets specifically), duplicate,
and remove (with confirm). The existing per-type field editors (hero/
categories/product-collection) are unchanged; the raw-JSON fallback for
unknown widget types now sits behind a collapsed "Advanced settings"
disclosure instead of being the default view.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-18 10:24:13 +04:00
|
|
|
updateWidget(widgetId: string, updater: (props: Record<string, unknown>) => Record<string, unknown>): void {
|
|
|
|
|
this.updateWidgetConfig(widgetId, widget => ({ ...widget, props: updater(widget.props ?? {}) }));
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-10 13:43:53 +04:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|