61 lines
2.5 KiB
Markdown
61 lines
2.5 KiB
Markdown
---
|
|
id: TASK-41
|
|
title: Build dynamic Shape Registry to replace hardcoded switch statements
|
|
status: Done
|
|
assignee: []
|
|
created_date: '2026-02-18 20:06'
|
|
updated_date: '2026-03-11 23:01'
|
|
labels:
|
|
- infrastructure
|
|
- phase-0
|
|
- ecosystem
|
|
milestone: m-1
|
|
dependencies: []
|
|
references:
|
|
- rspace-online/lib/folk-shape.ts
|
|
- rspace-online/website/canvas.html
|
|
- rspace-online/lib/community-sync.ts
|
|
priority: high
|
|
---
|
|
|
|
## Description
|
|
|
|
<!-- SECTION:DESCRIPTION:BEGIN -->
|
|
Replace the 170-line switch statement in canvas.html's `createShapeElement()` and the 100-line type-switch in community-sync.ts's `#updateShapeElement()` with a dynamic ShapeRegistry.
|
|
|
|
Create lib/shape-registry.ts with:
|
|
- ShapeRegistration interface (tagName, elementClass, defaults, category, portDescriptors, eventDescriptors)
|
|
- ShapeRegistry class with register(), createElement(), updateElement(), listAll(), getByCategory()
|
|
- Each folk-*.ts gets a static `registration` property and static `fromData()` method
|
|
|
|
This is the prerequisite for all other ecosystem features (pipes, events, groups, nesting, embedding).
|
|
<!-- SECTION:DESCRIPTION:END -->
|
|
|
|
## Acceptance Criteria
|
|
<!-- AC:BEGIN -->
|
|
- [x] #1 ShapeRegistry class created with register/createElement/updateElement methods
|
|
- [x] #2 All 30+ folk-*.ts shapes have static registration property
|
|
- [x] #3 canvas.html switch statement replaced with registry.createElement()
|
|
- [x] #4 community-sync.ts type-switch replaced with registry.updateElement()
|
|
- [x] #5 All existing shapes still create and sync correctly
|
|
- [x] #6 No regression in shape creation or remote sync
|
|
<!-- AC:END -->
|
|
|
|
## Final Summary
|
|
|
|
<!-- SECTION:FINAL_SUMMARY:BEGIN -->
|
|
## Completed: Dynamic Shape Registry
|
|
|
|
Created `lib/shape-registry.ts` — `ShapeRegistry` class with `register()`, `createElement()`, `updateElement()`, `has()`, `listAll()`. Singleton `shapeRegistry` exported from `lib/index.ts`.
|
|
|
|
Added `static fromData(data)` and `applyData(data)` to all 41 shape classes (base `FolkShape` + 40 subclasses including `FolkArrow`). Each shape's creation/sync logic is now co-located with its `toJSON()`.
|
|
|
|
Replaced 300-line `newShapeElement()` switch in `canvas.html` with ~25-line registry call. Special cases preserved: `wb-svg` whiteboard drawings, `folk-canvas` parentSlug, `folk-rapp` spaceSlug context defaults.
|
|
|
|
Replaced 165-line `#updateShapeElement()` if-chain in `community-sync.ts` with single `shape.applyData(data)` delegation (~10 lines).
|
|
|
|
All existing shapes create and sync identically. No TypeScript errors introduced.
|
|
|
|
Commit: c4717e3
|
|
<!-- SECTION:FINAL_SUMMARY:END -->
|