react-bannerkit

    Normalising

    normalizeTemplate takes an authored or stored BannerTemplate and returns a complete, valid one. Every component calls it internally — you never ship a document that has not been through the repair pass.

    import { normalizeTemplate } from 'react-bannerkit'
     
    const safe = normalizeTemplate(stored)

    What it repairs

    • Missing fields — every element, panel, and breakpoint field that the schema requires but the source omitted is filled with a sensible default.
    • Invalid enums — an out-of-range value is replaced with the default for that field.
    • Generated ids — every node and element receives an id if one is missing. The factory is injectable for deterministic test output.

    Silent by default

    The repair pass does not warn. A misspelled key is dropped and replaced with a default, with no console output and no callback. This is deliberate: the document is always valid, and the only way to know an authoring typo survived is the subset assertion in the test suite.

    onWarn

    An optional callback you can pass to normalizeTemplate:

    normalizeTemplate(doc, { onWarn: (msg) => console.warn(msg) })

    It fires when the repair pass drops or replaces a value. Useful during development, not recommended in production — the warnings are for authors, not users.

    Schema migration

    When the document schema gains a new field, normalizeTemplate fills it with a default. When a field is removed, the repair pass drops it. This means a document saved by an older version of the builder always renders correctly in a newer version of the renderer, and vice versa.