docs: design and OpenSpec change add-page-anchor-links
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
f66219f247
commit
c20a0c105c
6 files changed
+183
No files matched your search
@@ -0,0 +1,2 @@
|
||||
schema: spec-driven
|
||||
created: 2026-12-03
|
||||
@@ -0,0 +1,27 @@
|
||||
## Context
|
||||
|
||||
See `docs/superpowers/specs/2026-12-03-page-anchor-links-design.md`. Blocks are one JSON column on `cms_page`; services-counter validates them; mobile-api passes them through as maps; the portal renders them. Custom HTML runs in an opaque-origin frame (`allow-scripts allow-popups allow-popups-to-escape-sandbox`) whose injected script already posts height reports, which `HtmlFrame` accepts only from its own `contentWindow`.
|
||||
|
||||
## Goals / Non-Goals
|
||||
|
||||
**Goals:** named block targets; `#name` links from buttons, rich text and Custom HTML.
|
||||
|
||||
**Non-Goals:** automatic ids; any new frame permission; scroll offsets for a sticky header (the public page has none).
|
||||
|
||||
## Decisions
|
||||
|
||||
1. **Field `anchor` on the block**, pattern `^[a-z0-9][a-z0-9-]{0,39}$`, unique per page. Stored in the blocks JSON, so no DDL. Refusal codes: `PagesBadAnchor`, `PagesAnchorTaken`.
|
||||
2. **Link rule.** `#` plus the same pattern is a safe link everywhere a link is checked: `CmsBlockValidator.safeLink`, `isSafeLink`, the editor's `SAFE_LINK`, and the sanitiser (sanitize-html already keeps scheme-less hrefs; a test pins it).
|
||||
3. **Ids.** The block wrapper in `CmsBlocks` gets `id={anchor}` for every type, the HTML frame included. Rendered only when the name matches the pattern, so rows written another way cannot inject odd ids.
|
||||
4. **Frame bridge.** The injected script adds one click listener: for `a[href^="#"]` with a valid name it prevents the default and posts `{type:"colite-frame-anchor", name, y}`, where `y` is the in-frame element's document offset or `null`. `HtmlFrame` checks the source window as for heights, validates the message in a pure `frameAnchor()` helper, then scrolls the window to `frame top + y`, or to `document.getElementById(name)`, else ignores it. Smooth scroll.
|
||||
5. **Messages are data only.** The page never navigates or evaluates anything from a frame message; it only scrolls.
|
||||
|
||||
## Risks / Trade-offs
|
||||
|
||||
- A frame script could post anchor requests at will → it can only scroll its own page, which it could already make tall. Accepted.
|
||||
- A link name equal to an id the portal already uses on that page (e.g. `main`) would clash → the public page renders no ids of its own apart from block anchors; the preview shell may, so only behaviour on the public page is specified.
|
||||
- Pages saved by an older release lose link names → only on rollback; noted in the proposal.
|
||||
|
||||
## Migration Plan
|
||||
|
||||
Deploy services-counter and the portal; run `sql/01-anchor-labels.sql`. Rollback: previous images and `sql/99-rollback.sql`.
|
||||
@@ -0,0 +1,28 @@
|
||||
## Why
|
||||
|
||||
Landing pages cannot link within themselves. Buttons and rich-text links refuse `#anchor`, blocks have no id to jump to, and links inside a Custom HTML block do nothing because the sealed frame never scrolls and may not scroll the page. The INS page's "Get My Free Consultation" button therefore cannot take visitors to the sign-up form. Design: `docs/superpowers/specs/2026-12-03-page-anchor-links-design.md`.
|
||||
|
||||
## What Changes
|
||||
|
||||
- Each block gets an optional link name, unique on the page, rendered as the block's id.
|
||||
- Button and rich-text links accept `#name`.
|
||||
- The Custom HTML frame reports clicks on `#name` links to the page, which scrolls to the target inside the frame or to the named block.
|
||||
- New and changed editor labels in English and Chinese.
|
||||
|
||||
## Capabilities
|
||||
|
||||
### New Capabilities
|
||||
|
||||
None.
|
||||
|
||||
### Modified Capabilities
|
||||
|
||||
- `landing-pages`: same-page links and block link names.
|
||||
|
||||
## Impact
|
||||
|
||||
- services-counter: `CmsBlock` gains `anchor`; `CmsBlockValidator` checks it and accepts `#name` links. No DDL: blocks are stored as JSON.
|
||||
- mobile-api: none (blocks pass through as maps).
|
||||
- Portal: `cmsPages.ts` (`isSafeLink`, model), `RichTextEditor.tsx`, `pageHtml.ts`, `frameHtml.ts` (script and message parsing), `HtmlFrame.tsx`, `CmsBlocks.tsx` (ids), `BlockFields.tsx` (field), labels.
|
||||
- SQL: `sql/01-anchor-labels.sql` and `sql/99-rollback.sql` (labels only).
|
||||
- Older releases ignore the new field on read, and a page saved by an older release loses its link names.
|
||||
@@ -0,0 +1,73 @@
|
||||
## MODIFIED Requirements
|
||||
|
||||
### Requirement: Page Content Cannot Run Scripts
|
||||
|
||||
A button SHALL have both a label and a link or neither. The link SHALL start with a single `/`, `https://`, `mailto:`, `tel:`, or `#` plus a valid block link name. A save SHALL be refused when RICH_TEXT or IMAGE_TEXT HTML holds a `script` element, an `on*` attribute or a `javascript:` URL. The public page SHALL also sanitise that HTML against an allow-list. HTML blocks are exempt: they only run sealed.
|
||||
|
||||
#### Scenario: Script link on a button
|
||||
|
||||
- **WHEN** a page is saved with a HERO button link `javascript:alert(1)`
|
||||
- **THEN** the save is refused on field `blocks[0].buttonUrl`
|
||||
|
||||
#### Scenario: Script in rich text
|
||||
|
||||
- **WHEN** a page is saved with rich text holding `<img src=x onerror=alert(1)>`
|
||||
- **THEN** the save is refused on that block's HTML field
|
||||
|
||||
#### Scenario: Script in an HTML block
|
||||
|
||||
- **WHEN** a page is saved with an HTML block holding `<script>document.title = "x"</script>`
|
||||
- **THEN** the save succeeds
|
||||
|
||||
#### Scenario: Same-page button link
|
||||
|
||||
- **WHEN** a page is saved with a HERO button link `#signup`
|
||||
- **THEN** the save succeeds
|
||||
|
||||
#### Scenario: Malformed same-page link
|
||||
|
||||
- **WHEN** a page is saved with a HERO button link `#Sign Up`
|
||||
- **THEN** the save is refused on field `blocks[0].buttonUrl`
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Block Link Names
|
||||
|
||||
Any block MAY carry a link name. A link name SHALL be 1 to 40 characters of lowercase letters, digits and `-`, starting with a letter or digit, and SHALL be unique within the page. A save breaking either rule SHALL be refused on that block's link-name field, writing nothing. The public page and the staff preview SHALL give the block that name as its element id, so a `#name` link scrolls to it.
|
||||
|
||||
#### Scenario: Hero button jumps to the form
|
||||
|
||||
- **GIVEN** a published page whose FORM block has the link name `signup` and whose HERO button links to `#signup`
|
||||
- **WHEN** a visitor clicks the button
|
||||
- **THEN** the page scrolls to the form
|
||||
|
||||
#### Scenario: Duplicate link name
|
||||
|
||||
- **WHEN** a page is saved with two blocks named `signup`
|
||||
- **THEN** the save is refused on field `blocks[1].anchor` and nothing is written
|
||||
|
||||
#### Scenario: Bad link name
|
||||
|
||||
- **WHEN** a page is saved with a block named `Sign Up`
|
||||
- **THEN** the save is refused on field `blocks[0].anchor` and nothing is written
|
||||
|
||||
### Requirement: Same-Page Links From A Custom HTML Frame
|
||||
|
||||
A click on a `#name` link inside a Custom HTML block SHALL scroll the page, without navigating the frame. The target SHALL be the element with that id inside the same frame when there is one, otherwise the block on the page with that link name, otherwise nothing happens. The page SHALL act only on such requests from its own frames and only for names of the link-name pattern. The frame SHALL gain no new sandbox permissions.
|
||||
|
||||
#### Scenario: Link to the form below the frame
|
||||
|
||||
- **GIVEN** a published page with an HTML block holding `<a href="#signup">` and a FORM block named `signup`
|
||||
- **WHEN** a visitor clicks that link
|
||||
- **THEN** the page scrolls to the form
|
||||
|
||||
#### Scenario: Link inside the frame
|
||||
|
||||
- **GIVEN** a published HTML block whose content holds `<a href="#top">` near its bottom and an element with id `top` at its start
|
||||
- **WHEN** a visitor scrolls down and clicks that link
|
||||
- **THEN** the page scrolls back to the start of the frame
|
||||
|
||||
#### Scenario: Another window asks to scroll
|
||||
|
||||
- **WHEN** a different window posts a same-page link request to the page
|
||||
- **THEN** the page does not scroll
|
||||
@@ -0,0 +1,20 @@
|
||||
# Tasks: add-page-anchor-links
|
||||
|
||||
Design: `design.md`. Every task is TDD. Work is serial in the main session, with a self-review per task.
|
||||
|
||||
## 1. services-counter
|
||||
|
||||
- [ ] 1.1 `CmsBlock.anchor`; `CmsBlockValidator`: link-name pattern and uniqueness (`PagesBadAnchor`, `PagesAnchorTaken` on `blocks[i].anchor`), `#name` accepted by `safeLink`.
|
||||
- Verify: `mvn -T 1C -B -pl solvway-services-counter -am verify`
|
||||
|
||||
## 2. Portal
|
||||
|
||||
- [ ] 2.1 Link rules: `isSafeLink`, the rich-text editor's `SAFE_LINK`, a sanitiser test that `#name` hrefs survive; block ids in `CmsBlocks` (pattern-checked).
|
||||
- [ ] 2.2 Frame bridge: click listener in the frame script, `frameAnchor()` message check, `HtmlFrame` scroll (own frame only).
|
||||
- [ ] 2.3 Editor: "Link name" field per block with field errors; label changes in `defaultMessages.ts` and `zh_CN.seed.json`, then `npm run i18n:sql`; `sql/01-anchor-labels.sql` (new labels, plus English and Chinese updates of `PagesBadLink` and `PagesLinkPrompt`) and `sql/99-rollback.sql`.
|
||||
- Verify (2.1 to 2.3): `cd solvway-admin-portal && npx vitest run; echo VITEST=$? && npx tsc --noEmit && npm run lint`
|
||||
|
||||
## 3. Release
|
||||
|
||||
- [ ] 3.1 `docs/deployment.md`: SQL rows, drop the `#anchor` known gap, add the INS page note (name the FORM block `signup`, change the HTML's `#consult` to `#signup`).
|
||||
- [ ] 3.2 Live check (Playwright) on a local portal: hero button to a named form block; Custom HTML `#name` to the form and `#top` inside the frame; refusals for a bad and a duplicate link name; 1280 and 360 px.
|
||||
Reference in new issue
Block a user