docs: archive 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
7229437ced
commit
915f5d316b
9 files changed
+58
-2
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 `^(?!reg-)[a-z0-9][a-z0-9-]{0,39}$`, unique per page. `reg-` is reserved because the sign-up form renders its fields with literal `reg-*` ids. 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 sign-up form's field ids all start with `reg-`, which link names may not; other ids on the page come from `useId` and cannot match the pattern. The staff preview runs inside the back-office shell, whose ids are not checked against link names.
|
||||
- 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,78 @@
|
||||
## 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, SHALL NOT start with `reg-` (the sign-up form's own field ids), 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: Reserved link name
|
||||
|
||||
- **WHEN** a page is saved with a block named `reg-email`
|
||||
- **THEN** the save is refused on field `blocks[0].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,18 @@
|
||||
-- The labels added or changed by add-page-anchor-links, cut from the output of `npm run i18n:sql`. Run it only in an environment that already ran add-zh-cn-messages/sql/03-zh-cn-messages.sql; otherwise run that 03 file, which includes these labels.
|
||||
SET NAMES utf8mb4;
|
||||
USE `service-system`;
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesLinkPrompt', JSON_OBJECT('en_US', 'Link address (https://, mailto:, tel:, / or #name)', 'zh_CN', '链接地址(https://、mailto:、tel:、/ 或 #名称)'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesLinkPrompt') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '链接地址(https://、mailto:、tel:、/ 或 #名称)') WHERE LOWER(code) = LOWER('PagesLinkPrompt') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBadLink', JSON_OBJECT('en_US', 'Use a link that starts with https://, mailto:, tel:, / or #.', 'zh_CN', '链接须以 https://、mailto:、tel:、/ 或 # 开头。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBadLink') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '链接须以 https://、mailto:、tel:、/ 或 # 开头。') WHERE LOWER(code) = LOWER('PagesBadLink') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesAnchor', JSON_OBJECT('en_US', 'Link name (optional)', 'zh_CN', '链接名称(可选)'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesAnchor') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '链接名称(可选)') WHERE LOWER(code) = LOWER('PagesAnchor') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesAnchorHint', JSON_OBJECT('en_US', 'Link to this block with #name, for example #signup. Lowercase letters, digits and - only.', 'zh_CN', '用 #名称 链接到此区块,例如 #signup。仅限小写字母、数字和 -。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesAnchorHint') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '用 #名称 链接到此区块,例如 #signup。仅限小写字母、数字和 -。') WHERE LOWER(code) = LOWER('PagesAnchorHint') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBadAnchor', JSON_OBJECT('en_US', 'Use lowercase letters, digits and - (up to 40), starting with a letter or digit and not with reg-.', 'zh_CN', '请使用小写字母、数字和 -(最多 40 个),以字母或数字开头,且不能以 reg- 开头。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBadAnchor') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '请使用小写字母、数字和 -(最多 40 个),以字母或数字开头,且不能以 reg- 开头。') WHERE LOWER(code) = LOWER('PagesBadAnchor') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesAnchorTaken', JSON_OBJECT('en_US', 'Another block on this page already has this link name.', 'zh_CN', '本页已有其他区块使用此链接名称。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesAnchorTaken') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '本页已有其他区块使用此链接名称。') WHERE LOWER(code) = LOWER('PagesAnchorTaken') AND area = 'A';
|
||||
-- PagesLinkPrompt and PagesBadLink already exist: their English changes too.
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.en_US', 'Link address (https://, mailto:, tel:, / or #name)') WHERE LOWER(code) = LOWER('PagesLinkPrompt') AND area = 'A';
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.en_US', 'Use a link that starts with https://, mailto:, tel:, / or #.') WHERE LOWER(code) = LOWER('PagesBadLink') AND area = 'A';
|
||||
@@ -0,0 +1,8 @@
|
||||
-- Co-Lite change add-page-anchor-links: rollback of the labels. Blocks keep their link names in the JSON; the previous
|
||||
-- release ignores them on read, and a page saved by it loses them. Pages with #name links must be edited before
|
||||
-- they are saved under the previous release, which refuses such links.
|
||||
SET NAMES utf8mb4;
|
||||
USE `service-system`;
|
||||
DELETE FROM message WHERE code IN ('PagesAnchor', 'PagesAnchorHint', 'PagesBadAnchor', 'PagesAnchorTaken') AND area = 'A';
|
||||
UPDATE message SET content = JSON_SET(content, '$.en_US', 'Link address (https://, mailto:, tel: or /)', '$.zh_CN', '链接地址(https://、mailto:、tel: 或 /)') WHERE LOWER(code) = LOWER('PagesLinkPrompt') AND area = 'A';
|
||||
UPDATE message SET content = JSON_SET(content, '$.en_US', 'Use a link that starts with https://, mailto:, tel: or /.', '$.zh_CN', '链接须以 https://、mailto:、tel: 或 / 开头。') WHERE LOWER(code) = LOWER('PagesBadLink') AND area = 'A';
|
||||
@@ -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
|
||||
|
||||
- [x] 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
|
||||
|
||||
- [x] 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).
|
||||
- [x] 2.2 Frame bridge: click listener in the frame script, `frameAnchor()` message check, `HtmlFrame` scroll (own frame only).
|
||||
- [x] 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
|
||||
|
||||
- [x] 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`).
|
||||
- [x] 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