import {type CSSResultGroup, html, type PropertyValues, unsafeCSS} from 'lit'; import { emptyPageState, generateSectionId, PAGE_SECTION_MIME, PAGE_TYPE_MIME, type PageSection, type PageSectionType, type PageState, sectionChildren, sectionSummary, } from './page.types'; import {HasSlotController} from '../../internal/slot'; import {ifDefined} from 'lit/directives/if-defined.js'; import {PageSectionRegistry} from './page-registry'; import {property, state} from 'lit/decorators.js'; import {watch} from '../../internal/watch'; import ZincElement from '../../internal/zinc-element'; import ZnCollapsible from '../collapsible'; import ZnIcon from '../icon'; import ZnInput from '../input'; import ZnPagePaletteItem from './modules/page-palette-item'; import ZnPageSectionCard from './modules/page-section-card'; import styles from './page-builder.scss'; const HISTORY_LIMIT = 50; /** Sections beyond this are dropped (with a warning) when external state is applied. */ const MAX_SECTIONS = 500; /** Per-container children beyond this are dropped when external state is applied. */ const MAX_CHILDREN = 24; /** Builder width below which the palette auto-collapses — keep in sync with the @container query in page-builder.scss. */ const NARROW_WIDTH = 768; const AUTO_SAVE_DEFAULT_MINUTES = 5; const AUTO_SAVE_TTL_MS = 24 * 60 * 60 * 1000; /** Compact relative time for the auto-save status ("just now", "3m ago"). */ function timeAgo(ms: number): string { const s = Math.floor(ms / 1000); if (s < 10) return 'just now'; if (s < 60) return `${s}s ago`; const m = Math.floor(s / 60); if (m < 60) return `${m}m ago`; const h = Math.floor(m / 60); if (h < 24) return `${h}h ago`; return `${Math.floor(h / 24)}d ago`; } /** * @summary A config-driven page composer: a palette of predefined section types, a linear * canvas of section cards, and an inspector for editing each section's content. * @documentation https://zinc.style/components/page-builder * @status experimental * @since 1.0 * * @dependency zn-collapsible * @dependency zn-icon * @dependency zn-input * @dependency zn-page-palette-item * @dependency zn-page-section-card * * @event zn-page-change - Emitted whenever the page state changes. `event.detail.state` is the new PageState. * @event zn-page-selection-change - Emitted when the selected section changes. `event.detail.sectionId`. * * @slot config - `