Implement the staged changeset store and the colour/typography primitives with unit tests #194
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills#194
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Implement the staged-changeset store and the two design-token primitives,
penpot_create_colorandpenpot_create_typography. Primitives stage changes rather than writing them, so a whole design system (or a whole screen) can be applied as a singleupdate-filecall in a later step.Background
Depends on: #193
This is the first write-side step, and the architecture it establishes is deliberate: Penpot shape and asset ids are client-generated, so the extension can build a complete change list offline and apply it in one call.
update-fileapplies changes in order, so a parent and its children are created atomically, a rejected batch applies nothing, and the file's revision advances exactly once.Three pieces are needed:
changes[], and the baserevnobserved when staging began. Keyed by file id so two files can be staged independently.{ type: "add-color", color: { id, name, color: "#RRGGBB", opacity } }, which lands atdata.colors.<id>. Theidis a client-generated UUID.{ type: "add-typography", typography: { id, name, fontId, fontFamily, fontVariantId, fontSize, fontWeight, fontStyle, lineHeight, letterSpacing, textTransform } }— all fields are required, and the server does not validate the font against the team's font list. A typography naming a font the instance does not ship is accepted but will not render as intended, so the tool must resolve fonts deliberately and record substitutions (see below).Nothing here performs an HTTP write; the commit step does that. Keeping the payload construction pure is what makes the write path testable without a live instance.
Documentation Required
A separate process downloads these into the listed folders before this issue is implemented. Check the folders for the actual reference material before starting.
docs/reference/penpot-api/<PENPOT_URL>/api/main/doc/openapi.json— theupdate-filecommand and the change-type union; confirmadd-colorandadd-typographyparameter shapes on this instance.docs/reference/pi-coding-agent/anddocs/reference/typebox/Type.Object,Type.Optional,Type.Number,Type.String; how to express a hex-colour pattern and numeric ranges.Implementation Details
extensions/penpot/src/changeset.ts— pure, unit-testedcreateChangeset(fileId)/stageChange(state, change)/discardChangeset(fileId)/changesetStatus(fileId).{ fileId, revn, changes: Change[], createdAt }, held in a module-levelMap<fileId, Changeset>.newId()— client-side UUID generation usingcrypto.randomUUID()(Node built-in). Every staged asset/shape gets one at stage time.describeChanges(changes)— a human-readable, deterministic preview used by both this milestone's status reporting and the commit preview: one line per change (add-color "flip7-gold" #2BA8A2,add-typography "h2" Inter 24/600).changesetStatus()output: target file, baserevn, change count by type, and the preview lines.extensions/penpot/src/tools/tokens.ts— the two toolspenpot_create_color— paramsfile_id,name,color(hex#RRGGBB, or#RRGGBBAAsplit into hex + opacity),opacity(0–1, optional, default 1). Validate the hex format before staging and reject anything else with a clear message.penpot_create_typography— paramsfile_id,name,font_family(e.g.Inter),font_size(number),font_weight(e.g.400/600/700),font_style(normal/italic, defaultnormal),line_height(number, default 1.2),letter_spacing(number, default 0),text_transform(defaultnone).get-font-variantsfor the team and pick the closest available variant; fall back to a documented default when the requested family is absent. Never invent afontId."Inter requested → Source Sans Pro used (not installed on this instance)") so the agent can report it rather than silently producing a design that will not render as intended.file_idthat is not the current staged target (or a target with staged changes for a different file) with a clear message — the changeset is per file and mixing files would be a silent data-integrity bug.Do not add an HTTP write here. Do not add an
update-filecall.Acceptance Criteria
penpot_create_colorstages anadd-colorchange with a client-generated UUID and the exact payload shape{type, color: {id, name, color, opacity}}.penpot_create_typographystages anadd-typographychange with every required field present and a font id resolved from the instance's font variants.penpot_discard(or equivalent status/discard tool) clears them and reports what was discarded.revn, change counts and a deterministic preview.file_idin the same session is handled explicitly (either isolated per file or refused with a clear message) — never silently merged.update-filecall is made.Test Plan
Live sanity check of the read half (which fonts exist), requires
PENPOT_URL/PENPOT_TOKEN:get-font-variantsfor the team (via the client or a temporary debug path) and confirm the resolvedfontId/fontVariantIdvalues come from that list.revn(the actual commit is validated in the next step).pi-loop opened and merged a pull request for this issue: #227