Add saved components: reusable HTML boxes, placed as copies or linked
Test and deploy / test (push) Successful in 2m13s
Test and deploy / deploy (push) Successful in 1m23s

A component (models.Component, component.graphql) is a named HTML box.
"+ New box" now lists components and places a copy, as it did with the
hard-coded starters; the canvas's new Components button (ComponentPanel)
can also place one linked. A linked box has Box.componentId, its row's
html is nil, and the resolvers fill in the component's html before
answering (fillLinked), so saving the html in the box editor saves the
component and every linked box on every page changes. Only the html is
shared: title, geometry, frame and visibility stay each box's own.

The box editor gains "Save as component" (makes one from an html box and
links it) and, on a linked box, a banner with Detach (gives the box its
own copy). updateBox refuses html on a linked box. Deleting a component
detaches its boxes first, so no page changes. Layouts store the link and
the html; loading relinks only if the component still exists.

The built-in starters in templates.js are no longer listed directly:
"Import built-ins" in the panel creates them as components (skipping
names already taken), so they can be edited and deleted like the rest.
The html helpers there are unchanged. Everything is @admin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-23 22:32:40 +01:00
co-authored by Claude Opus 5.5
parent 263e16b70d
commit 7969859955
24 changed files with 2431 additions and 65 deletions
+15 -6
View File
@@ -1,8 +1,16 @@
/**
* Starter HTML for the "New box" menu. Each runs inside the sandboxed iframe
* (see HtmlBox.vue), so scripts work but can only reach APIs that allow
* cross-origin requests from an opaque origin — i.e. that answer with
* `Access-Control-Allow-Origin: *` and need no key. Open-Meteo is one.
* The built-in starter HTML. The "+ New box" menu no longer reads TEMPLATES
* directly: it lists saved components, and TEMPLATES is what the Components
* panel's "Import built-ins" turns into components (stores/components.js), so
* they can be edited and deleted like any other. Changing an entry here only
* reaches a site whose admin imports it again (after deleting the old one).
* The helpers at the bottom are still used directly, by dropped uploads and
* the starter layouts.
*
* Each runs inside the sandboxed iframe (see HtmlBox.vue), so scripts work but
* can only reach APIs that allow cross-origin requests from an opaque origin —
* i.e. that answer with `Access-Control-Allow-Origin: *` and need no key.
* Open-Meteo is one.
*
* The site's colour and font tokens are already defined in the frame
* (frameStyles.js), so templates use var(--color-…) freely.
@@ -158,8 +166,9 @@ const videoHtml = (src) => `<style>
<video src="${src}" controls loop muted></video>`;
/**
* Menu entries; `size` is [w, h] in canvas px. `adminOnly` sets the new
* box's flag, which can be changed afterwards in the editor.
* Built-in starters; `label` becomes the component's name and `size` ([w, h]
* in canvas px) its default size. `adminOnly` sets a new box's flag, which can
* be changed afterwards in the editor.
*/
export const TEMPLATES = [
{ label: "Note (admin only)", title: "Note", html: NOTE, size: [260, 200], framed: false, adminOnly: true },