Skip to content

refactor(patterns): split 7 variant-heavy patterns into framework-specific DemoSection files with shared data#171

Merged
masuP9 merged 8 commits into
mainfrom
refactor/demo-section-split-data
May 11, 2026
Merged

refactor(patterns): split 7 variant-heavy patterns into framework-specific DemoSection files with shared data#171
masuP9 merged 8 commits into
mainfrom
refactor/demo-section-split-data

Conversation

@masuP9
Copy link
Copy Markdown
Owner

@masuP9 masuP9 commented May 11, 2026

Summary

PR #169 (9 pattern 分割) のフォローアップ第 1 弾。残り 23 pattern のうち、共通 data の切り出しが有効な 7 pattern (accordion / listbox / radio-group / tabs / tree-view / table / treegrid) を framework 別 DemoSection に分割し、新たに {pattern}-demo-data.ts 規約を導入する。本 PR の目的は混在状態 (9 移行 + 23 legacy) の解消ロードマップを進めること。dispatcher の legacy fallback は維持し、残り 16 pattern は後続 PR-B で対応する。

なぜ全分割するか

ファイル名/ディレクトリから責務が読めることの認知負荷削減と、将来 Vue SFC を含む pattern を追加した際に legacy 形式由来の $RefreshSig$ regression に巻き込まれない予防策。Issue #170 とは独立な構造一貫性改善。

変更内容

種別 件数
新規 {pattern}-demo-data.ts 7
新規 DemoSection.{react,vue,svelte,web-component}.astro 28 (7 × 4)
削除 legacy DemoSection.astro 7
修正 CLAUDE.md (transitional 追記) 1

共通 data 切り出しルール (新規規約)

4 framework で内容が完全に同一かつ概ね 8 行以上 の純 data (配列/オブジェクトリテラル) を {pattern}-demo-data.ts に切り出す。framework 固有の prop 名変換 (Vue ariaLabel ↔ React aria-label 等) や関数 (renderCell 等) は各 DemoSection に残す。

検証

allowlist 付き probe で全 32 pattern × 4 framework × 2 locale のうち、Issue #170 関連の 9 Vue ページのみが期待 500、他は全て 200:

```bash
known_failing_vue=(alert checkbox combobox disclosure menu-button menubar slider slider-multithumb toolbar)
unexpected=0
for d in src/patterns/*/; do
p=$(basename "$d")
for fw in react vue svelte astro; do
expected=200
[ "$fw" = "vue" ] && [[ " ${known_failing_vue[@]} " =~ " $p " ]] && expected=500
actual=$(curl -s -o /dev/null -w '%{http_code}' "http://localhost:4336/apg-patterns-examples/patterns/$p/$fw/")
[ "$actual" != "$expected" ] && { echo "UNEXPECTED: $p/$fw expected=$expected got=$actual"; unexpected=$((unexpected+1)); }
done
done
echo "unexpected=$unexpected"
```

結果:
```
unexpected=0
```

  • npm run lint: 0 errors (table の未使用 sortableColumns declaration 1 件減って 28 → 27 hints)
  • npm run build: success (553 pages built)

Pattern 別 acceptance

pattern 注意点
tabs 3 variant の data ファイル化 (中規模代表として POC-1)
treegrid 130 行バイリンガル data (columnsEn/Ja, nodesEn/Ja) を data ファイル化 (POC-2、最大ケース)
tree-view inline <script is:inline> (activate event handler) は DemoSection.web-component.astro 1 箇所のみに残した
accordion 3 種 items (default / multiple / disabled)
listbox 2 種 options (Vue/Svelte/Astro 共有; React 変種は wrapper component 経由で別)
radio-group 4 種 options
table 6 種 columns/rows variant + 未使用だった sortableColumns を data ファイルから除外

PR-B 予定 (本 PR merge 後)

  • 残り 16 pattern (alias 7 + 中規模 7 + 大規模残り 2 [data-grid, dialog, grid]) を分割
  • dispatcher (en/ja) の legacy fallback を撤去 + framework prop を削除
  • docs を確定記述に (transitional 注記の削除、.internal/page-template.md 等の更新)

関連

Test plan

🤖 Generated with Claude Code

masuP9 and others added 8 commits May 11, 2026 19:30
…shared demo data

Apply the PR #169 framework-split convention to the tabs pattern, plus
extract shared variant data (demoTabs / manualTabs / verticalTabs) into
a dedicated `tabs-demo-data.ts` to avoid duplicating ~20 lines of data
across the four framework files.

The shared data rule (per the migration plan):
- 4 frameworks reference the data identically (8+ lines, pure data only)
- framework-specific prop name differences (e.g. `activationMode` vs
  `activation`, `label` vs `defaultSelectedId`) stay in each per-framework
  DemoSection file

Verified:
- /patterns/tabs/{react,vue,svelte,astro}/ return 200 (en)
- /ja/patterns/tabs/{react,vue,svelte,astro}/ return 200 (ja)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The treegrid pattern has the largest shared demo data: 130 lines covering
columnsEn / columnsJa / nodesEn / nodesJa for the Astro Web Component
variant (the React/Vue/Svelte variants use locale-specific wrapper
components TreeGridDemo / TreeGridDemoJa with their own internal data).

Extract the Astro variant's data to treegrid-demo-data.ts and split the
DemoSection into four framework files. Also switch the locale check from
\`Astro.url.pathname.startsWith('/ja/')\` to the \`locale\` prop, matching
the convention established by PR #169.

Verified:
- /patterns/treegrid/{react,vue,svelte,astro}/ return 200 (en)
- /ja/patterns/treegrid/{react,vue,svelte,astro}/ return 200 (ja)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extract defaultItems / multipleItems / disabledItems to accordion-demo-data.ts
and split DemoSection into four framework files.

Verified: /patterns/accordion/{react,vue,svelte,astro}/ and the /ja/ variants
all return 200.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extract fruitOptions / colorOptions to listbox-demo-data.ts (used by
Vue/Svelte/Astro variants; the React variant has its own wrapper
components with internal data) and split DemoSection into four framework
files.

Verified: /patterns/listbox/{react,vue,svelte,astro}/ and the /ja/ variants
all return 200.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extract colorOptions / sizeOptions / planOptions / ratingOptions to
radio-group-demo-data.ts and split DemoSection into four framework files.
Framework prop name differences (e.g. Vue \`ariaLabel\` vs React/Svelte/Astro
\`aria-label\`) are kept in each per-framework file rather than in the
shared data, per the migration convention.

Verified: /patterns/radio-group/{react,vue,svelte,astro}/ and /ja/ variants
all return 200.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extract fileSystemNodes / disabledNodes to tree-view-demo-data.ts and split
DemoSection into four framework files. The inline \`<script is:inline>\` that
listens for \`activate\` events on \`<apg-treeview>\` is kept only in
DemoSection.web-component.astro (where the Astro Web Component is rendered),
per the migration plan.

Also switch the locale check from \`Astro.url.pathname.startsWith('/ja/')\` to
the \`locale\` prop, matching the convention.

Verified: /patterns/tree-view/{react,vue,svelte,astro}/ and /ja/ variants
all return 200.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extract pure data (basicColumns/Rows, rowHeaderRows, virtualizedRows,
spanningColumns/Rows) used by the Astro Web Component variant to
table-demo-data.ts. The React / Vue / Svelte variants use wrapper demo
components with their own internal data. The sortable demo, even for the
Astro page, uses the React SortableTableDemo via \`client:load\`.

Note: the previously declared but unused \`sortableColumns\` is dropped,
clearing the existing astro check warning at DemoSection.astro:45.

Verified: /patterns/table/{react,vue,svelte,astro}/ and /ja/ variants
all return 200.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
After PR #169 (9 patterns) and PR-A (7 patterns), 16 of 32 patterns now
use the framework-split DemoSection format. CLAUDE.md is updated to:

- describe the new \`{pattern}-demo-data.ts\` convention (introduced in
  PR-A for variant-heavy patterns)
- list the currently migrated patterns
- note that the legacy format and dispatcher fallback will be removed in
  PR-B once all 32 patterns are split

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying apg-patterns-examples with  Cloudflare Pages  Cloudflare Pages

Latest commit: 16f4caf
Status: ✅  Deploy successful!
Preview URL: https://6e600875.apg-patterns-examples.pages.dev
Branch Preview URL: https://refactor-demo-section-split.apg-patterns-examples.pages.dev

View logs

@masuP9 masuP9 merged commit c9f378d into main May 11, 2026
17 checks passed
@masuP9 masuP9 deleted the refactor/demo-section-split-data branch May 11, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant