import { h as ValidationViolation } from "./errors-CyuuoKx0.js"; import { i as ValidationBuilder } from "./rule-DYNYH_ha.js"; //#region src/core/content/field-types.d.ts /** One choice in a closed set. `label` is what the editor reads; `value` is what * is stored; a token differs from its presentation for the usual reason. */ interface FieldOption { value: string; label?: string; } /** * Choices fetched at edit time rather than declared in the catalog. * * The reason this exists is ADR 0010's: a picker whose choices come from an API—Square * locations, a product catalog—could not be expressed at all. `options` * took a literal array, so the only way to build one was the settings drawer's * `render` escape hatch, which the section inspector doesn't have. * * Called with no arguments: a resolver is declared in the site's catalog module * and closes over whatever config it needs, so nothing has to be threaded through * the schema layer to reach it. */ type FieldOptionsResolver = () => Promise; /** Either a literal set of choices or something that fetches them. */ type FieldOptions = FieldOption[] | FieldOptionsResolver; /** * The names a field may declare: every built-in, plus any string. * * The `(string & {})` arm is what makes a site's own `defineFieldType` actually * usable. A closed union is checkable but not extensible, and slice 1 hit the * wall: a type registered at runtime widened the registry and not the type a * catalog could write, so the test that proved "one registration is enough" had * to reach for a cast. * * The intersection is the standard trick for keeping both—TypeScript won't * collapse the union to `string`, so editors still complete the ten built-ins, * while a registered name type-checks. What's lost is the typo check: `"txet"` is * now legal to write, and an unregistered type validates as nothing rather than * failing—which is why {@link unknownFieldTypes} exists for a catalog that * wants the stricter guarantee back. */ type FieldTypeName = "text" | "textarea" | "richText" | "array" | "image" | "select" | "link" | "toggle" | "color" | "links" | (string & {}); /** * Whether `value` is a destination Louise will store and a site may render into * an `href`. * * Exported because a stored destination is not only a section field: site * settings hold `navLinks` / `socialLinks`, rendered into the site chrome on * every page. Nothing checked those until an editor could have planted * `javascript:` in one—so the two paths now share a predicate rather than a * convention. * * Empty is safe: "no link yet" is a value, and what an unset link renders is the * site component's decision. */ declare function isSafeLinkUrl(value: unknown): boolean; //#endregion //#region src/core/content/sections.d.ts /** * The names a section field may declare. * * Now an alias for {@link FieldTypeName}—one list for sections and settings * both, where there used to be `SectionFieldType` (8) and `SettingsFieldType` (6), * overlapping on four and disagreeing on the rest. A type added to one was * silently missing from the other, and that asymmetry had teeth: settings had a * `links` type and no `link` type, so there was nowhere for a scheme check to * live, and stored nav destinations went unvalidated until it was found. * * Kept as its own name because it is the published one—a site's catalog is * typed with it. */ type SectionFieldType = FieldTypeName; /** * Editor options for a `richText` field. * * Schema, not UI—plain data describing which affordances the field wants, which * is why it lives in core alongside the rest of the field's declaration rather * than with the ProseKit editor that reads it. */ interface RichTextFieldOptions { /** The page builder's palette of builder blocks (Hero/Columns/Gallery…). * Meant for full page bodies, not a one-line heading; leave it off for most * section fields. */ builder?: boolean; /** @deprecated Renamed {@link RichTextFieldOptions.builder} (#537): a * section's `blocks` are a different thing. Still read when `builder` is unset. */ blocks?: boolean; /** Lazy-load Harper for grammar checking. */ grammar?: boolean; /** Inline formatting only: the light bubble (bold/italic/underline/strike/ * link/colour). `false` surfaces the prose block buttons and the AI-rewrite * sparkle. Defaults to `true` for a section field. */ minimal?: boolean; /** Show the "Insert image" button. Default `true`; drop it from a heading or * tagline where an inline image doesn't belong. */ image?: boolean; /** Single-line mode: the value serializes as inline HTML with no block wrapper, * so editing can't turn an `

` into a `

` nested inside the site's own * element and lose its styling. */ inline?: boolean; /** * The text colors the format bubble offers, as theme tokens. Picking one * stores `color: var(--color-)`, so the text follows a re-theme, and * any token works that the site's theme defines as `--color-`, such * as `brand-orange`. The palette is a brand fact, so the site passes it: on * the field, or for every field on the `mountSections` `richText` default. * Default: primary, secondary, accent, and neutral; the state colors (info, * success, warning, error) aren't offered, since text in them reads as a * message. An empty list hides the color button. */ colors?: readonly RichTextColor[]; /** * Typographic input rules, off by default (#606). With `typography: {}`, * typing `--` gives an em dash and `...` an ellipsis. Add `quotes`, the four * marks your language uses as opening double, closing double, opening single, * and closing single, such as `"“”‘’"` or `"«»‹›"`, and straight quotes become * those. Quote marks differ by language, so there's no default pair. Only * typing is converted, never a paste, and undo right after reverts it. */ typography?: RichTextTypography; /** * Show a Language button in the format bubble, which marks the selection as * another language with ``, so a screen reader pronounces it * right (#606). Off by default. */ language?: boolean; } /** One text color the rich-text editor offers: a label, and a theme token. */ interface RichTextColor { /** What the swatch is called, such as `"Brand orange"`. */ label: string; /** The theme token, lowercase with hyphens: `--color-` must exist. */ token: string; } /** The typographic input rules a rich-text field turns on. */ interface RichTextTypography { /** Four quote marks: opening and closing double, then opening and closing single. */ quotes?: string; } interface SectionField { type: SectionFieldType; label?: string; placeholder?: string; /** * `richText` only—this field's editor options. * * Declared here because they were always a property of the FIELD. They shipped * as a mount-level `richTextModes` map keyed by a `data-louise-rt` name the * render stamped, which meant a rendezvous between two files to say something * one of them already knew: the catalog declares a heading is a heading. * * Wins over the mount-level `richText` / `richTextModes`, both of which still * work. */ richText?: RichTextFieldOptions; /** Whether this field is edited in place on the bespoke render (a visible text * node) vs. in the dock (a value you can't point at, for example, a link URL). * Defaults to `true` for text/textarea, `false` for `array`. */ inline?: boolean; /** * `select` only—the allowed values, in the order the picker shows them. * A stored value outside this set is a validation error, the same way an * undeclared `_layout` token is. * * `label` is what the editor reads; `value` is what's stored. They differ for * the usual reason a token differs from its presentation—"Brand" is a label, * `brand` is the thing the site's class map is keyed on. * * May instead be a {@link FieldOptionsResolver}—an async function returning * the choices—for a picker whose values come from an API rather than the * catalog. Note the trade: a resolved set is NOT checked on write, because that * would put a network call on the save path. See the `select` type's own * comment in `field-types.ts`. */ options?: FieldOptions; /** * `select` only—an opaque hint for how the picker should render (for example, * `"swatch"` for colour tokens). Passed through untouched: the schema * layer has no business knowing what a swatch looks like, and a site's * renderer may ignore it entirely. */ display?: string; /** * `select` only—the value is a **string array**, any number of the options * (ADR 0010 Phase B). Rendered as a checkbox list rather than a dropdown; * validated as an array whose every member is an allowed value (resolver- * backed sets keep the same write-path exemption as single selects). The * shape a mirror's filter lists need—"these subcategories", "these items * hidden". */ multiple?: boolean; /** `array` only—label for each repeated item (for example, "Feature"). */ itemLabel?: string; /** `array` only—the fields of each repeated item. With a {@link SectionField.discriminator} * these are the fields shared by *every* variant; the variant adds more on top. */ itemFields?: Record; /** * `array` only—makes the array a *discriminated union* of item shapes * (blocks: image vs. quote vs. embed …) instead of one fixed `itemFields` * shape, mirroring `ArrayFieldConfig.discriminator` (`core/content/types.ts`) * one level down—the proving slice for a first-class `blocks` layer (ADR 0005). * `key` names the field holding each item's variant (set by the type-switcher, * not typed in place); `variants` maps each variant value to the *additional* * fields layered on top of `itemFields`, validated/shown only for items whose * `key` field holds that value. `variantsAdmin` gives the "add"/switch picker a * per-variant `label` + opaque `icon` string. Storage is unchanged—`array` * stays one JSON column; this only changes the item's field set. */ discriminator?: { key: string; variants: Record>; variantsAdmin?: Record; }; /** Optional per-field validation, reusing the content `Rule` builder, for example, * `validation: (r) => r.required().max(120)`. Enforced server-side by * {@link validateSections}. */ validation?: ValidationBuilder; } interface SectionDef { /** Palette label. */ label: string; /** * Optional palette icon. The add picker draws it when it's inline SVG * markup, such as a Phosphor icon imported with `?raw`, and sizes it to the * text with `currentColor`. Any other string passes through untouched, and * the picker doesn't draw it. */ icon?: string; /** * Optional one-sentence description the add picker shows under the label, * so an owner knows what a type looks like before adding it. For example, * "An image beside a heading and text." */ description?: string; /** The section's editable fields, keyed by prop name. */ fields: Record; /** * Opt this section into the first-class **block layer** (ADR 0005)—the * organising layer *within* a section. Declaring this policy is what promotes * a section's reserved `blocks` array from ignored free-form data to a * validated, ordered list of polymorphic {@link BlockItem}s, each resolved * against the {@link BlockCatalog} passed to {@link validateSections}. This is * the sections analogue of `SectionField.discriminator` one level up. * * `allow` bounds which block types this section accepts (any block in the * catalog when omitted); `min` / `max` bound the block count. Storage is * unchanged—`blocks` rides in the same `sections` JSON column. */ blocks?: { allow?: string[]; min?: number; max?: number; }; /** * Named layout variants for this section (ADR 0005 §5), surfaced in the * inspector rail as a picker. A stored {@link SectionItem._layout} must be one * of these keys. Louise stores only the chosen **token**—the site component * maps it to actual grid/flex/CSS, so layout stays 100% site-owned. */ layouts?: Record; /** * Non-inline **settings** fields (background, spacing, columns, alignment …), * edited in the inspector rail rather than in place (ADR 0005 §5). Reuse * {@link SectionField}, so they validate exactly like regular fields; their * values live under {@link SectionItem._settings}. Louise stores tokens/values * only, never CSS—the site component reads them and switches its own styles. */ settings?: Record; /** * Where this section's CONTENT truth lives, when it isn't the page (ADR 0010 * Phase B). Marks a section that mirrors a system the site doesn't own—a * Square-backed product grid—so the editor rings it yellow and its wrench * configures the mirror (category, filters, hidden items), never the * mirrored content itself. Omitted means the page owns it, which is every * section that existed before Phase B. * * The bare `"external"` form is the tone alone; the object form additionally * declares the mirror's configuration, which the inspector renders as its * own group writing to SITE SETTINGS—immediately, not into the page draft * (see {@link ExternalSource}). */ source?: "external" | ExternalSource; /** * Site-settings keys this section READS when it renders—for example, * `["addressStreet", "hours"]` for a location panel. The coupling is * otherwise invisible (it lives inside the site's own component), and it * is what the shared-value editor counts to say "used in N surfaces" * before a green-ring edit changes every one of them. */ consumes?: string[]; } /** * The object form of {@link SectionDef.source}—an external mirror plus its * site-owned configuration (ADR 0010 Phase B). * * `settings` are the knobs of the MIRROR (which category, which filters, which * items hidden), not of the section: their values live in the site-settings * `custom` JSON under `settingsKey`, shared by every page that renders the * section—which is why the inspector writes them through the settings route, * immediately, instead of staging them into a page draft. A field may be a * resolver-backed `select` (the usual case—the choices come from the external * system's API). */ interface ExternalSource { kind: "external"; /** Editor-facing name of the system—"Square"—used to title the inspector * group. Falls back to "Source". */ label?: string; /** The site-settings custom key holding this mirror's configuration object, * for example, `"shop"` → `site_settings.custom.shop`. Required for `settings` to * have anywhere to live. */ settingsKey?: string; /** The mirror's configuration fields, keyed by property within that object. */ settings?: Record; } /** Normalize {@link SectionDef.source}—`"external"` and the object form both * answer, so consumers switch on one shape. `null` for a page-owned section. */ declare function externalSourceOf(def: SectionDef | undefined): ExternalSource | null; /** The site's catalog of preconfigured section types (schema only—the bespoke * render components live on the site). */ type SectionCatalog = Record; /** One block type's schema (label/icon + fields)—the block-level analogue of * {@link SectionDef}. Block fields reuse {@link SectionField} verbatim, so a * block validates exactly like a section's field set: the same `Rule` chain and * the same `array` / `discriminator` support, no separate path. */ interface BlockDef { label: string; /** Optional palette icon, drawn as {@link SectionDef.icon} is. */ icon?: string; /** Optional one-sentence description, shown as {@link SectionDef.description} is. */ description?: string; fields: Record; /** Inspector-rail settings for this block (ADR 0005 §5): the block-level * analogue of {@link SectionDef.settings}; values live under * {@link BlockItem._settings}. Blocks carry settings but not layouts. */ settings?: Record; } /** The site's catalog of block types (schema only—bespoke renders live on the * site), the block-level analogue of {@link SectionCatalog} (ADR 0005). */ type BlockCatalog = Record; /** One stored block: a `_type` discriminant plus its field values—the * block-level analogue of {@link SectionItem}. Flat and ordered; blocks do not * nest blocks in v1 (named slots / cross-section moves are deferred). */ interface BlockItem { _type: string; /** Inspector-rail setting values for this block (ADR 0005 §5), validated * against {@link BlockDef.settings}. Tokens/values only, never CSS. */ _settings?: Record; [key: string]: unknown; } /** One stored section: a `_type` discriminant plus its field values. */ interface SectionItem { _type: string; /** * The optional organising layer *within* this section (ADR 0005): an ordered * list of polymorphic blocks. Reserved structural key—a section opts into * validation by declaring {@link SectionDef.blocks}. Additive: absent on every * pre-block section, and a section may carry both direct fields and blocks * during a transition. */ blocks?: BlockItem[]; /** * A named layout token (ADR 0005 §5)—one of {@link SectionDef.layouts}' * keys. Louise stores only the token; the site component maps it to CSS. */ _layout?: string; /** * Inspector-rail setting values for this section (ADR 0005 §5), validated * against {@link SectionDef.settings}. Tokens/values only, never CSS. */ _settings?: Record; [key: string]: unknown; } interface ValidateSectionsOptions { operation: "create" | "update"; /** * The site's `MEDIA_URL` base. When set, an `image` field whose value is a * non-empty string that isn't served from this base is a violation—enforcing * that section images come from the media library, not an external * hotlink. Omit to skip the origin check (image fields still validate as * strings). See {@link isMediaUrl}. */ mediaBase?: string; /** * The site's {@link BlockCatalog} (ADR 0005). Required to validate any * section that opts into the block layer via {@link SectionDef.blocks}: each * block's `_type` resolves to a {@link BlockDef} here and its fields validate * like a section's. Omit when no section uses blocks; a block whose `_type` * isn't in the catalog is rejected as unknown. */ blockCatalog?: BlockCatalog; } /** * Validate a page's `sections` value against a catalog, returning every * violation (errors and warnings). Checks, in order: * - the value is an array; * - each item is an object with a `_type` present in the catalog; * - each declared field's value has the right primitive shape (text/textarea → * string, array → array of objects whose `itemFields` are validated in turn); * - for a section that declares a `blocks` policy, its `blocks` array (count vs. * `min`/`max`, each block's `_type` against the policy `allow` + the * `blockCatalog`, then that block's fields—ADR 0005); * - `_layout` (must be a declared layout token) and `_settings` (validated * against the def's `settings` fields), on sections and blocks—ADR 0005 §5; * - any field's `validation` Rule chain (reused from the content validator). * Absent/`undefined` (the field wasn't part of a partial update) is a no-op—presence * is the route allowlist's job, not this validator's. */ declare function validateSections(catalog: SectionCatalog, value: unknown, options?: ValidateSectionsOptions): Promise; /** * Run {@link validateSections} and throw {@link LouiseValidationError} if any * error-severity violations are found (warnings are returned, never thrown). * Mirrors {@link assertValid} so the pages route can reject an invalid * `sections` write with a 422 carrying the per-field violations. */ declare function assertValidSections(catalog: SectionCatalog, value: unknown, options?: ValidateSectionsOptions): Promise; /** * Return a copy of a page's `sections` with every `richText` field—section-level * and block-level—run through `sanitize`. A richText field stores HTML (edited * in place with the light ProseKit editor, #182), so it must be sanitized on write * just like the page body; call this from the collection's `beforeChange` next to * the body sanitize. Non-array input and unknown `_type`s pass through untouched. * * `array` item fields ARE recursed, at any depth: a catalog can declare richText * inside `itemFields`, so anything the schema can express must be covered here. */ declare function sanitizeSectionsRichText(sections: unknown, catalog: SectionCatalog, sanitize: (html: string) => string, blockCatalog?: BlockCatalog): unknown; //#endregion export { isSafeLinkUrl as S, validateSections as _, RichTextColor as a, FieldOptionsResolver as b, SectionCatalog as c, SectionFieldType as d, SectionItem as f, sanitizeSectionsRichText as g, externalSourceOf as h, ExternalSource as i, SectionDef as l, assertValidSections as m, BlockDef as n, RichTextFieldOptions as o, ValidateSectionsOptions as p, BlockItem as r, RichTextTypography as s, BlockCatalog as t, SectionField as u, FieldOption as v, FieldTypeName as x, FieldOptions as y };