8000 feat: section anchors, tabs opened from the URL, slider peek, gutter by Klehm · Pull Request #102 · Klehm/content-blocks-project · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CLAUDE.md

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions docs/.vitepress/data/blocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,13 @@
"customWidth": 600,
"customHeightAuto": true,
"customHeight": 400,
"customHeightTablet": null,
"customHeightMobile": null,
"ratio": "auto",
"fit": "cover",
"align": "center",
"url": "",
"newTab": false,
"caption": "",
"borderRadius" 10000 ;: {
"linked": true
Expand Down Expand Up @@ -172,7 +175,8 @@
"src": "",
"alt": "",
"caption": "",
"url": ""
"url": "",
"newTab": false
}
]
}
Expand Down Expand Up @@ -306,7 +310,8 @@
"title": "Card title",
"content": "Card text",
"url": "",
"buttonText": ""
"buttonText": "",
"newTab": false
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/backward-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Every key of the three semantic config trees (`content_blocks`, `content_blocks_
| `content_blocks_export` | `GET` on an area, answering the export archive; `?assets=0` |
| `content_blocks_import` | `POST` of an export in one request, the single-request path kept for scripts |
| `content_blocks_area_publish`, `content_blocks_area_discard` | `POST` with the CSRF header, and an optional JSON body `{"locales": [...]}` naming the locales whose translations the call covers (without it, every locale); a `400` with `error: "invalid_locales"` for a malformed list; a `409` with `error: "refused"`, `message` and `reasons` when a [listener refused](./events.md#refusing-an-action) |
| `content_blocks_asset_layout`, `content_blocks_asset_styling`, `content_blocks_asset_slider`, `content_blocks_kit_asset_css` | `GET`, the stylesheet or script a public page links; `?v=` with the content's version is cached for a year |
| `content_blocks_asset_layout`, `content_blocks_asset_styling`, `content_blocks_asset_slider`, `content_blocks_asset_panels`, `content_blocks_kit_asset_css` | `GET`, the stylesheet or script a public page links; `?v=` with the content's version is cached for a year |
| `content_blocks_asset_report` | `GET`, the read-only asset report page |
| `content_blocks_ai_text`, `content_blocks_ai_alt_text`, `content_blocks_ai_content` | `POST` with the CSRF header; the content action's `action` (`add`, `edit_section`, `edit_page`), `prompt`, `targetSectionId` / `targetBlockId`; `404` with `error: "disabled"` while the action is off or unsupported, `502` with `error: "provider_failed"` when the provider throws; the text actions answer `{"text"}`, the content action `sectionIds`, `blockIds`, `skippedBlockTypes`, `droppedFields`, or a `409` / `422` with `error` |
| `content_blocks_area_schema` | `GET` on an area, answering the [content schema](./content-schema.md) (`format: content-blocks/schema-v1`); `?examples=`. Later versions may add keys to the document, never remove one |
Expand Down
4 changes: 3 additions & 1 deletion docs/guide/headless.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ With `klehm/content-blocks-i18n` installed, the locale works exactly as on the H
{
"id": 40,
"layout": "two_cols",
"anchor": "pricing",
"display": { "desktop": "grid", "tablet": "grid", "mobile": "accordion" },
"accordion": { "single": false, "collapsed": false },
"slider": null,
Expand Down Expand Up @@ -101,8 +102,9 @@ With `klehm/content-blocks-i18n` installed, the locale works exactly as on the H
| `mode` | `public` or `preview`: which state was read. |
| `locale` | The locale the tree was rendered in: the one you passed, else the request's. |
| `contentVersion` | The area's [content version](./content-versioning.md) stamp, `null` before versioning. |
| `sections[].anchor` | The section's [anchor](./host-services.md#section-anchors-and-links-to-a-tab), checked like the HTML render checks it; `null` without one. Unlike the HTML, two sections may carry the same one. |
| `sections[].display` | The display per viewport, already resolved (`grid`, `tabs`, `accordion`, `slider`): tablet and mobile inherit from above and can only get more compact. |
| `sections[].accordion` / `slider` | The options of that display, `null` when no viewport uses it. `slider.perView` is the slides shown at once per viewport. |
| `sections[].accordion` / `slider` | The options of that display, `null` when no viewport uses it. `slider.perView` is the slides shown at once per viewport, `slider.peek` whether the next slide shows at the edge. |
| `sections[].settings` | The settings the HTML render reads: the style preset merged underneath, values equal to their default left out. |
| `columns[].span` | The width on the 12-unit grid, from `preset`. `width` is the custom weight from the *Column widths* field, `null` for equal widths. |
| `columns[].label` | The column's title, shown by the tabs and accordion displays. |
Expand Down
54 changes: 53 additions & 1 deletion docs/guide/host-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,34 @@ parameters:

Like `maxWidth`, this drives the form radio pre-selection (`SectionSettingsType`), the defaults provider (`CoreSectionDefaults`), and the render fallback (`BuiltInSectionDecorator`) in lock-step.

### Section gutter

Out of the box a section has no inline padding, so in full width its content
touches the edges of the screen. Set one gutter for every section:

```yaml
# config/packages/content_blocks.yaml
content_blocks:
section:
gutter: 'clamp(1rem, 4vw, 2rem)' # any CSS length; null (default) = none
```

The area gets `cb-content-area--gutter`, and each section an inline padding of
that size. A section whose own padding is set in its *Style* tab keeps it, side
by side: the gutter is only what an unset side falls back on. The background
still spans the full width, and a centered section caps its row inside the
gutter. To change it per screen, set `--cb-section-gutter` in your CSS, which
wins over the configured value:

```css
@media (max-width: 540px) {
.cb-content-area { --cb-section-gutter: 0.75rem; }
}
```

Off by default because it changes the public page of a site that already
spaces its sections itself.

### Initial settings of a new section

A default only reaches what the render falls back on — width mode and max width
Expand Down Expand Up @@ -421,6 +449,26 @@ Its custom properties and classes:
A style preset may carry `display: tabs` or `display: accordion` in its
`settings`, like any other section setting.

### Section anchors and links to a tab

The **Anchor** field (*Advanced* panel, setting `anchor`) gives a section its
`id`, so `/page#pricing` scrolls to it. A pasted `#` is dropped and spaces become
dashes on save; what is left must be a letter followed by letters, digits, `-`
or `_` (64 at most), or the sidebar refuses it. The render checks again, since
an import or a preset never meets the form. Two sections with the same anchor
(a duplicate keeps it) both render, but only the first one in the page gets the
`id`.

A tab or an accordion panel opens from the URL: `#pricing-2` opens the second
panel of the section anchored `pricing`, counting from 1. A panel's own id
(`#cb-tabs-12-1-panel`), or the id of anything inside a closed panel, works too.
A small script does it, linked only by a public page with tabs or an accordion
(`content_blocks_asset_panels`, a public route like the slider's); it also
follows a later change of the hash. An element whose own id is `pricing-2`
wins over the panel rule.

The headless tree carries the anchor as `sections[].anchor`.

### Display per viewport

*Display* has the same desktop / tablet / mobile switch as the spacing fields.
Expand Down Expand Up @@ -459,6 +507,9 @@ sidebar sets:
hover and keyboard focus, stops in a hidden tab, and never runs for visitors
who ask for reduced motion, nor in the builder.
- **Arrows loop back** (`sliderLoop`): the last slide's arrow goes to the first.
- **Show a glimpse of the next slide** (`sliderPeek`): the slides narrow so
the start of the next one shows at the edge, a hint that the row scrolls.
The sliver is `--cb-slide-peek` (default `12%` of the row) plus a gap.

The arrows, dots and ARIA roles come from a small script the page loads only
when a section needs it (`content_blocks_asset_slider`, a public route like the
Expand Down Expand Up @@ -499,7 +550,8 @@ and keep any other key as it is: a field you added to the section form with a
type extension (see [Add a section field](./recipes/add-section-field.md)) can
be preset too, at the top level or under `styling`. A key one or two letters
away from a core key is refused at `cache:clear` as a typo
(`widthMod` → *did you mean "widthMode"?*). Custom keys also travel with the
(`widthMod` → *did you mean "widthMode"?*), unless it extends that key:
`anchorId` stays yours. Custom keys also travel with the
section through duplicate, copy/paste, section templates and export/import.

### Adding (or overriding) defaults via a provider
Expand Down
47 changes: 47 additions & 0 deletions docs/internals/rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,53 @@ end, pauses on hover, focus and a hidden tab, and is off under
`prefers-reduced-motion` and in the builder preview. Loop means the arrows
rewind; an infinite loop would clone slides.

### A glimpse of the next slide

`sliderPeek` adds `cb-section--slider-peek`, which sets `--cb-slide-peek-w` on
the row: the sliver plus one gap. Every slide-width rule subtracts it with a
`0px` fallback, so a slider without it computes the very width it did before,
and nothing in the script changes: its stops are the slides' offsets, clamped to
the scroll end.

## Section anchors

The anchor is a setting, not a column: it is part of the draft/published pair
like every other, so a new anchor reaches the public page on Publish only.
`SectionAnchor` is its one definition, read by the form (clean, then refuse),
the decorator and the headless tree (both re-check, as an import, a preset or a
template writes settings without the form). It is checked in a listener, not a
`Constraint`: the section form must build from a bare form factory, which has
no validator.

The render, not the save, keeps ids unique. Refusing a duplicate on save would
have held every other field of a duplicated section, and a paste or an import
writes no form at all. So the area render walks its sections in page order and
drops an `id` already given, or one on a section pending deletion. A section
rendered alone (a hot reload in the builder) is not deduplicated; that is the
preview, where nothing follows a fragment. The builder's `patchSection` copies
the `id`, or a changed anchor would only show after a reload.

## Opening a tab from the URL

Tabs and the accordion are CSS only, so nothing reads the URL. `panels.js`
does, and only that: on load and on `hashchange` it finds the panel the
fragment names, checks its radio or checkbox (`{panel id}` minus `-panel`) and
scrolls to the target, which the browser could not do while it was hidden.
`#anchor-N` counts the live panels of the section from 1; an element whose
own id matches comes first, so the rule never hides a real id. The builder does
not link it: its preview has no URL an editor follows.

## The section gutter

`section.gutter` is off by default because a default padding in `layout.css`
would move every existing site. The area carries the value as
`--cb-gutter-default`, the host's `--cb-section-gutter` wins over it, and the
result is `--cb-s-gutter` on each section. An unstyled section takes it as
`padding-inline`; a styled one (`cb-section--styled`, which writes all four
sides) takes it as the fallback of its left and right padding, so an explicit
side still wins. The gated rule (`.cb-content-area--gutter > .cb-section`) is
what keeps a host's own `.cb-section` padding untouched when it is unset.

## Order per viewport

Sections and blocks can be reordered for tablet and mobile. Columns cannot
Expand Down
3 changes: 2 additions & 1 deletion docs/kit/blocks/card.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Initial values for a new block. Override per host with `defaults:`.
| --- | --- |
| `layout` | `grid` |
| `columns` | `3` |
| `items` | `[{"src":"","title":"Card title","content":"Card text","url":"","buttonText":""}]` |
| `items` | `[{"src":"","title":"Card title","content":"Card text","url":"","buttonText":"","newTab":false}]` |

#### Example

Expand All @@ -64,6 +64,7 @@ Rendered markup: `.cb-kit-card` items inside `.cb-kit-cards`. Style it by overri
## Notes

- The `max_columns` option caps the grid column choice for a given host.
- A card button may open in a new tab (`newTab` on the entry).
- Card media is resolved through [`ImageUrlResolverInterface`](../../guide/host-services.md#imageurlresolverinterface-responsive-images). A tile is fluid, so no display width is passed and a resolver returning candidates owns `sizes` itself.

---
Expand Down
3 changes: 2 additions & 1 deletion docs/kit/blocks/gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Initial values for a new block. Override per host with `defaults:`.
| `columns` | `3` |
| `fit` 10BC8 | `cover` |
| `borderRadius` | `{"linked":true}` |
| `items` | `[{"src":"","alt":"","caption":"","url":""}]` |
| `items` | `[{"src":"","alt":"","caption":"","url":"","newTab":false}]` |

#### Example

Expand All @@ -72,6 +72,7 @@ Enable `cb-gallery` under `@klehm/content-blocks-kit` in your host `assets/contr

- The `cb-gallery` controller is only needed for the **slider** layout; a pure grid is CSS-only.
- Use the `max_columns` option to restrict the `columns` choice list for a given host.
- Each linked image may open in a new tab (`newTab` on the entry).
- Item sources are resolved through [`ImageUrlResolverInterface`](../../guide/host-services.md#imageurlresolverinterface-responsive-images). A cell is fluid, so no display width is passed and a resolver returning candidates owns `sizes` itself.

---
Expand Down
5 changes: 5 additions & 0 deletions docs/kit/blocks/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ Initial values for a new block. Override per host with `defaults:`.
| `customWidth` | `600` |
| `customHeightAuto` | `true` |
| `customHeight` | `400` |
| `customHeightTablet` | `null` |
| `customHeightMobile` | `null` |
| `ratio` | `auto` |
| `fit` | `cover` |
| `align` | `center` |
| `url` | `''` |
| `newTab` | `false` |
| `caption` | `''` |
| `borderRadius` | `{"linked":true}` |

Expand All @@ -66,6 +69,8 @@ Rendered markup: `.cb-kit-image` — wraps a `<figure>` when a caption is presen
## Notes

- Picking `size: custom` reveals `customWidth` / `customHeight` (with a `customHeightAuto` toggle) via conditional fields.
- A fixed custom height can differ on tablet (`customHeightTablet`, ≤ 768px) and mobile (`customHeightMobile`, ≤ 540px); blank inherits the wider screen. The heights then travel as `--cb-kit-img-h`, `-t` and `-m` on `.cb-kit-image__img--vp-height`.
- With a link, `newTab` opens it in a new tab (`target="_blank" rel="noopener noreferrer"`).
- Requires [file storage](../../guide/host-services.md#file-storage) to be configured for uploads to work. The field accepts a picked *or* dropped file.
- The stored source is resolved through [`ImageUrlResolverInterface`](../../guide/host-services.md#imageurlresolverinterface-responsive-images), which the display width (sm=400, md=800, lg=1200, or the custom width) is handed to. With no resolver wired the source renders as-is; wire one and this block emits `srcset`/`sizes`.
- Opts into preview hot-reload — the upload JS is in the sidebar, not the view.
Expand Down
1 change: 1 addition & 0 deletions docs/kit/blocks/video.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Rendered markup: `.cb-kit-video` (a `<figure>`), `.cb-kit-video__player` on the
## Notes

- Uploads need `video/mp4` and/or `video/webm` added to `content_blocks.upload.allowed_mime_types`: they are not in the default list.
- A YouTube or Vimeo page pasted as the file is refused, with a message naming the `embed` block.
- Autoplay is always muted, since browsers refuse unmuted autoplay, and a video without autoplay always shows its controls, since it could not be started otherwise.
- The poster goes through [`ImageUrlResolverInterface`](../../guide/host-services.md#imageurlresolverinterface-responsive-images).
- Captions are a WebVTT file given by path or URL, rendered as a default `<track kind="captions">`. The file must be served as `text/vtt`. Both the file and its language are translatable, so each language can point at its own file.
Expand Down
5 changes: 5 additions & 0 deletions docs/scripts/blocks-meta.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ further wiring, and nothing in the kit changes.
markup: '`.cb-kit-image` — wraps a `<figure>` when a caption is present.',
notes: [
'Picking `size: custom` reveals `customWidth` / `customHeight` (with a `customHeightAuto` toggle) via conditional fields.',
'A fixed custom height can differ on tablet (`customHeightTablet`, ≤ 768px) and mobile (`customHeightMobile`, ≤ 540px); blank inherits the wider screen. The heights then travel as `--cb-kit-img-h`, `-t` and `-m` on `.cb-kit-image__img--vp-height`.',
'With a link, `newTab` opens it in a new tab (`target="_blank" rel="noopener noreferrer"`).',
'Requires [file storage](../../guide/host-services.md#file-storage) to be configured for uploads to work. The field accepts a picked *or* dropped file.',
'The stored source is resolved through [`ImageUrlResolverInterface`](../../guide/host-services.md#imageurlresolverinterface-responsive-images), which the display width (sm=400, md=800, lg=1200, or the custom width) is handed to. With no resolver wired the source renders as-is; wire one and this block emits `srcset`/`sizes`.',
'Opts into preview hot-reload — the upload JS is in the sidebar, not the view.',
Expand All @@ -229,6 +231,7 @@ further wiring, and nothing in the kit changes.
notes: [
'The `cb-gallery` controller is only needed for the **slider** layout; a pure grid is CSS-only.',
'Use the `max_columns` option to restrict the `columns` choice list for a given host.',
'Each linked image may open in a new tab (`newTab` on the entry).',
'Item sources are resolved through [`ImageUrlResolverInterface`](../../guide/host-services.md#imageurlresolverinterface-responsive-images). A cell is fluid, so no display width is passed and a resolver returning candidates owns `sizes` itself.',
],
},
Expand Down Expand Up @@ -262,6 +265,7 @@ further wiring, and nothing in the kit changes.
markup: '`.cb-kit-card` items inside `.cb-kit-cards`.',
notes: [
'The `max_columns` option caps the grid column choice for a given host.',
'A card button may open in a new tab (`newTab` on the entry).',
'Card media is resolved through [`ImageUrlResolverInterface`](../../guide/host-services.md#imageurlresolverinterface-responsive-images). A tile is fluid, so no display width is passed and a resolver returning candidates owns `sizes` itself.',
],
},
Expand Down Expand Up @@ -335,6 +339,7 @@ further wiring, and nothing in the kit changes.
markup: '`.cb-kit-video` (a `<figure>`), `.cb-kit-video__player` on the `<video>`, `.cb-kit-video__caption` on the caption.',
notes: [
'Uploads need `video/mp4` and/or `video/webm` added to `content_blocks.upload.allowed_mime_types`: they are not in the default list.',
'A YouTube or Vimeo page pasted as the file is refused, with a message naming the `embed` block.',
'Autoplay is always muted, since browsers refuse unmuted autoplay, and a video without autoplay always shows its controls, since it could not be started otherwise.',
'The poster goes through [`ImageUrlResolverInterface`](../../guide/host-services.md#imageurlresolverinterface-responsive-images).',
'Captions are a WebVTT file given by path or URL, rendered as a default `<track kind="captions">`. The file must be served as `text/vtt`. Both the file and its language are translatable, so each language can point at its own file.',
Expand Down
Loading
< 171E ghcc-consent id="ghcc" class="position-fixed bottom-0 left-0" style="z-index: 999999" data-locale="en" data-initial-cookie-consent-allowed="" data-cookie-consent-required="true" >
0