Repository navigation
Description
Overview
BaseNodeViewer currently contains hardcoded node-type-specific logic that violates the plugin architecture pattern. This refactoring will make BaseNodeViewer fully type-agnostic by moving all type-specific handling to the plugin registry or individual node components.
Problem Statement
BaseNodeViewer has several instances of type-specific code that should be delegated to the plugin system:
-
Task-specific metadata extraction (lines 376-395):
// Task nodes: Map schema status to taskState for icon rendering if (node.nodeType === 'task') { // ... task-specific logic }
-
Task-specific state mapping (lines 402-413):
function mapNodeStateToSchemaStatus(state: string): CoreTaskStatus { // ... hardcoded task state mapping }
-
Hardcoded structured node types (lines 348-357):
const STRUCTURED_NODE_TYPES = ['code-block', 'quote-block'] as const;
Self-Contained Scope
- Remove all hardcoded
nodeType === 'task'checks from BaseNodeViewer - Remove hardcoded
STRUCTURED_NODE_TYPESarray - Create plugin registry interfaces for type-specific behaviors
- Migrate task-specific logic to TaskNode plugin
- Migrate structured node logic to respective plugins
- Ensure all existing functionality continues to work
Implementation Approach
Phase 1: Define Plugin Interfaces
Add new optional methods to the plugin interface in plugin-registry.ts:
interface NodePluginDefinition {
// Existing properties...
// NEW: Type-specific metadata extraction
extractMetadata?: (node: Node) => Record<string, unknown>;
// NEW: Type-specific state mapping (for schema fields)
mapStateToSchema?: (state: string, fieldName: string) => unknown;
// NEW: Whether this node type accepts content merges
acceptsContentMerge?: boolean; // default: true
}Phase 2: Migrate Task-Specific Logic
- Move
extractNodeMetadatatask logic to TaskNode plugin - Move
mapNodeStateToSchemaStatusto TaskNode plugin - Update BaseNodeViewer to call plugin registry for metadata extraction
Phase 3: Migrate Structured Node Logic
- Add
acceptsContentMerge: falseto code-block and quote-block plugins - Replace
isStructuredNode()with plugin registry lookup - Remove
STRUCTURED_NODE_TYPESconstant
Phase 4: Update BaseNodeViewer
- Replace direct type checks with plugin registry calls
- Add fallback behavior for plugins without optional methods
- Ensure backward compatibility during transition
Acceptance Criteria
- No hardcoded
nodeType === 'task'checks in BaseNodeViewer - No hardcoded
STRUCTURED_NODE_TYPESarray in BaseNodeViewer - Plugin interface extended with optional type-specific methods
- TaskNode plugin implements
extractMetadataandmapStateToSchema - Code-block and quote-block plugins implement
acceptsContentMerge: false -
isStructuredNode()replaced with plugin registry lookup - All existing task state cycling functionality works
- All existing backspace/merge protection works for structured nodes
- All tests pass
- Code passes
bun run quality:fix
Technical Implementation Notes
Files to Modify
-
src/lib/plugins/plugin-registry.ts- Extend
NodePluginDefinitioninterface - Add helper methods for type-specific lookups
- Extend
-
src/lib/design/components/base-node-viewer.svelte- Remove
extractNodeMetadatatask-specific logic - Remove
mapNodeStateToSchemaStatusfunction - Remove
STRUCTURED_NODE_TYPESconstant - Remove
isStructuredNodefunction - Replace with plugin registry calls
- Remove
-
src/lib/plugins/definitions/task-node.ts- Add
extractMetadataimplementation - Add
mapStateToSchemaimplementation
- Add
-
src/lib/plugins/definitions/code-block-node.ts- Add
acceptsContentMerge: false
- Add
-
src/lib/plugins/definitions/quote-block-node.ts- Add
acceptsContentMerge: false
- Add
Patterns to Follow
- Reference existing plugin registration patterns in
src/lib/plugins/definitions/ - Follow the lazy-loading pattern already established
- Use optional chaining for backward compatibility with existing plugins
Testing Approach
- Verify task state cycling (pending → inProgress → completed) still works
- Verify backspace at start of node after code-block is blocked
- Verify backspace at start of node after quote-block is blocked
- Run full test suite:
bun run test:all
Resources & References
- Plugin Registry:
src/lib/plugins/plugin-registry.ts - BaseNodeViewer:
src/lib/design/components/base-node-viewer.svelte - Task Plugin:
src/lib/plugins/definitions/task-node.ts - Architecture Guide:
docs/architecture/components/component-architecture-guide.md
Definition of Done
- All type-specific logic removed from BaseNodeViewer
- Plugin interface properly extended
- All plugins updated with new optional methods where needed
- All tests pass (
bun run test:all) - Code quality verified (
bun run quality:fix) - Existing functionality unchanged from user perspective
- Code review completed
Related Issues
- Eliminate date-node-viewer onTitleChange callback effect #694 (established type-agnostic pattern for pane-content.svelte)
Activity
malibio commentedon Dec 1, 2025
🧪 Test Baseline Recorded
Frontend Tests: 728 passed
Rust Tests: Running... (checking completion)
Starting implementation of type-agnostic BaseNodeViewer refactoring.
Refactor BaseNodeViewer to be fully type-agnostic (closes #698)
Refactor BaseNodeViewer to be fully type-agnostic (closes #698) (#705)
Refactor BaseNodeViewer to be fully type-agnostic (closes #698) (#705)
Refactor BaseNodeViewer to be fully type-agnostic (closes #698) (#705)