Loading...

HAXcms Themes Make the Values They Draw Editable In Place

RULES.md

When a theme draws a site or page value itself (the site title, site description, site icon, banner or logo, the license, the author's name, image, email or social links, or a page's title, description, icon, image or tags, in a hero, header, footer, sidebar or card), it wraps that value in `haxcms-in-place` with the value's address, so a logged-in person can change it where it is drawn. The addresses are a fixed allow-list in `@haxtheweb/haxcms-elements/lib/core/utils/HAXCMSInPlaceFields.js`: `site:title`, `site:description`, `site:icon`, `site:image` (its alt text saves as `site:imageAlt`), `site:logo` (where the platform allows SEO settings, `seoManifest`), `site:authorName`, `site:authorImage`, `site:authorEmail`, `site:authorSocialLink`, `site:authorSocialLink2`, `site:license` (where it allows author settings, `authorManifest`), and `page:title:<id>`, `page:description:<id>`, `page:icon:<id>`, `page:image:<id>`, `page:tags:<id>` for any page, not only the active one. Pass the address of the value actually shown: when a theme falls back from one value to another (the page's image, else the site's; the site title, else the author's name), the address follows what is drawn, and an inherited image is addressed to the page that owns it. Mark the drawn text with `data-in-place-text`: `<haxcms-in-place address="site:description"><span data-in-place-text>${description}</span></haxcms-in-place>`. For an icon, image or a value changed in a panel (the license, email, social links, tags) pass the saved value as `.value` (and `.alt`; tags as their list or comma separated text), and preview a pick by listening for the `haxcms-in-place-draft` event (`{address, value}`, `null` for the saved value again). Wrap a value drawn as a link outside the link, as `site-title` does, never inside it, so no button sits in a link. The core elements already do this (`site-title` for the site title, `site-active-title` for the page title and the page icon beside it, `site-active-media-banner` for the page image and description, `site-active-tags` for the page's tags), so a theme that uses them gets it without writing anything; prefer them to drawing those values by hand. When a value is drawn on top of another (a title over its page's image), wrap each: over the text the text's control is offered, elsewhere the image's; give a full-width image's wrapper the `inset` attribute so its outline is drawn inside it, and `display: block` so it keeps the width. Do not add a theme's own edit buttons, bars or forms for these values: every value has one control (a rounded square pencil, the top bar's primary button, inside the value's top end corner, so the pointer stays on the value on its way to it; an image or icon also opens on a double click, and an image takes an image file dropped on it), one save and one toast, the same in every theme. Give a value room for that pencil: a long one-word title wraps (`overflow-wrap: anywhere`) rather than running off a phone screen. To visitors, on a server-drawn page, in Preview and in edit mode the wrapper is `display: contents` and adds nothing, so the theme's layout and theme-shell numbers do not change. Nothing changes in place while the page is open in HAX (edit mode): the editor owns the page then, and the editor refuses any in-place save it is sent. A value a theme hides when it is empty can still be drawn for logged-in people outside edit mode, so its "Add …" prompt shows (journey-theme's "Add a banner" band); the base class's `editsInPlace` getter (logged in and not editing) says when. A value drawn inside a link the whole of a card is (a post card), is drawn for that time without the card link around it: the title becomes the link and a cover link under the values keeps the rest of the card working, so no control sits in a link; a page's title in a list of page links (a footer's page grid) is wrapped outside its link the same way. Text drawn inside a picture (an element with `role="img"`, like a TV screen's animated title sequence) is part of that picture, not text to type over: it needs no wrapper when the same value is drawn, wrapped, elsewhere on the page; where the picture is the only place the value is drawn, wrap the picture with the `panel` attribute and pass the text as `.value`, so the pencil opens a text field in a panel (vhs-blog-theme's TV on the shelf). Only addresses on the allow-list do anything; a new field is added to that list and to both backends' fixed operations, never invented in a theme. Import `@haxtheweb/haxcms-elements/lib/core/micros/haxcms-in-place.js`. Checked in webcomponents by `scripts/in-place-values-check.mjs` (the in-place-values workflow): every theme in themes.json is opened logged in with marker values, and a value drawn without an available wrapper fails the pull request; a new theme has no baseline entry. In PRAW RULES.md (scope: haxcms). Nothing enforces this yet.

Status: gap

Connects to

Links