Style presets

A style preset is a named CSS cube, stored once and posed on blocks. A pose is a link, not a copy: editing the preset restyles every block that uses it.

It behaves like a CSS class under local overrides: preset values fill the gaps, the block's own values always win.

The logic lives in the StylePresets class; the render-time cascade in BSPK_MERGE_STYLE_PRESET. In the dev panel, the selector is in the "Mise en page" (Layout) tab, and presets are managed in the "Styles prédéfinis" tab.

Data

  • Table BSPK_WEB_STYLE_PRESET (a host database table): uuidKey, name, description, sourceType (the block type it was captured from), cssProperties.
  • A preset's cube has exactly the shape of a block's cssProperties: [part][breakpoint][variant][prop], with parts bspk, input, label, select… (see Styling: CSS cube and Tailwind).
  • A pose is stored on the block:
    properties.stylePresets[part][breakpoint][variant] = "<preset uuidKey>"
    stylePresets is declared by SchemaEngine for every type that has a CSS cube (valueType: object, internal: true); it is not in the type schemas. Several poses may coexist on one block.

Two older forms are still read, without migration: stylePresets[part] = "<uuid>" reads as a pose at default/default, and a cube whose top-level keys are all breakpoints (default, xs…2xl) is "part-neutral": it applies to the part it is posed on.

What one pose contributes

On each axis, the general value takes the whole axis; a precise value takes only itself (expandPose).

Pose atBrings
bspk / default / defaultthe entire preset cube, every part
input / default / defaultpreset.input, every breakpoint and variant
input / md / hoverpreset.input.md.hover only
bspk / md / hoverpreset.bspk.md.hover only

A preset never moves a part onto another: the destination keeps the source coordinates.

The cascade at render

BSPK_MERGE_STYLE_PRESET($cube; $WebContent) modifies a copy of the block's cube. It is called by BSPK_GENERATE_ALL_CSS_CLASS_TW right after BSPK_NORMALIZE_CSS_CUBE, so both the render and the Tailwind manifest see the same merged result.

  1. No pose: immediate return, no database access.
  2. StylePresets.contributions() lists every cell brought by every pose, sorted from general to precise: the most precise writes come last and win.
  3. A property is applied only if the schema makes it available for that block type and part (SchemaEngine.cssPropAvailable): what the Layout tab does not show cannot arrive through a preset. For example, a preset captured on a field and posed on a text block does not pour its input part into it.
  4. Two passes: unconditional properties first, then conditional ones, evaluated against the cube actually obtained (a preset bringing layout: flex makes its own flex* relevant; a refused layout does not let them through).
  5. The block's local values are never overwritten.

The dev panel shows inherited values as placeholders (data-preset-value), built from the same contributions(): what the panel announces is what is rendered.

Dev panel operations

GestureFunctionEffect
Pick a preset in the Layout tab selectorsetBlockPropertyV21 with {isStylePreset: true; target; breakpoint; variant; value}writes or removes the pose at that scope only; an empty value removes it; the block's cube is untouched
"Enregistrer comme modèle" (save as preset)saveBlockAsStylePresetthe preset gets the whole block cube; the block's cssProperties is then emptied and the preset posed at bspk/default/default
"Appliquer" (freeze)applyStylePresetcopies what all poses bring into the block's cube, then removes the poses: the block becomes independent
Edit a preset propertysetStylePresetPropertywrites one property at a scope in the preset cube, with no availability filter, then propagates
Create / renamecreateStylePreset, renameStylePreset
DeletedeleteStylePresetif the preset is in use and force is not set, the panel asks for confirmation (action stylePresetUsages); applyFirst: true first freezes this preset into each block; then deletion and propagation

Behind these gestures, the StylePresets class exposes list, get, create, rename, remove, usages, poses, expandPose, contributions, setPose, cubeFromBlock, applyToBlock, propagate, propagateBlocks, presetUuidFor and scopeForBlock. Results are {success; error} objects; remove and get never throw.

Pitfalls

  • After editing a preset from code, call propagate($uuid). The render picks up the change at once (the cascade runs at render), but output.css only contains classes the Tailwind manifest scanned. Without propagation, the HTML carries classes that do not exist: the style is silently missing. propagate regenerates the manifest page by page. Never pass a multi-page selection to BSPK_UPDATE_CSS_FILE_TW: it writes everything into the first block's page file and empties the others.
  • A pose that brings nothing is refused, with the warning BSPK_stylePresetNothingHere. If you write stylePresets yourself (API, migration), you bypass that check: verify with expandPose(...).length > 0.
  • A posed scope is exact: presetUuidFor only answers for the exact scope. The selector of a precise scope stays empty when the style comes from a general pose; clearing it there does nothing. Remove the pose where it was set.
  • Deleting a preset leaves dead references on blocks, unless it was frozen first. They are ignored at render: the block silently loses the preset's look. applyToBlock also removes dead poses.
  • The usages listed cover page blocks (BSPK_WEB_CONTENT). Before deleting or editing a preset, also check the blocks of your models that might use it.
  • After a delivery or a content exchange, check the look of blocks that use style presets on the target database. When in doubt, freeze the preset ("Appliquer") before delivering.
  • Never modify a preset's or a block's cssProperties in place: OB Copy, modify, then reassign (as setStylePresetProperty and applyToBlock do). 4D does not always detect an in-place change of an object field at save().

See also