Skip to content

Phase 2.2: Rich Link Decorations and Context System #74

Closed

Description

@malibio

Parent Issue

Part of Epic #69: Text Editor Architecture Enhancement - Phase 2

Summary

Implement rich node type decoration system that provides contextual visual representations for nodespace:// URI references, where each node type controls its own appearance through the decorateReference() method pattern.

Background

Building on Phase 2.1's Universal Node Reference Service, this adds sophisticated visual decorations that make NodeSpace's node referencing system superior to other knowledge management tools by providing rich, type-specific context.

Architectural Foundation: Content-driven decoration system where BaseNode provides default decoration and derived types override decorateReference() for custom appearance.

Core Functionality

  • Node Type Decorations: Visual indicators based on target node type (TaskNode, UserNode, DateNode)
  • Content-Driven System: Each node type interprets its content property for decoration
  • Contextual Information: Rich metadata display (completion status, due dates, online status)
  • Performance Optimized: Viewport-based processing and decoration caching

Decoration Interface

// Base decoration pattern - all nodes inherit this
abstract class BaseNode {
  id: string;
  content: string;  // Raw content - interpretation up to derived types
  
  /**
   * Default decoration renders content as simple link
   * Derived classes override this method for custom appearance
   */
  decorateReference(): string {
    return `<a href="nodespace://${this.id}" class="ns-noderef">${this.escapeHtml(this.content)}</a>`;
  }
  
  getDisplayText(): string {
    return this.content;
  }
}

// Node type specific decorations
class TaskNode extends BaseNode {
  status: 'not-started' | 'in-progress' | 'completed' | 'blocked';
  priority: 'low' | 'medium' | 'high' | 'critical';
  due_date?: Date;
  
  decorateReference(): string {
    const checkbox = this.status === 'completed' ? '✅' : '☐';
    const statusClass = `task-${this.status}`;
    const priorityClass = `priority-${this.priority}`;
    
    let decoration = `<a href="nodespace://${this.id}" class="ns-noderef ns-task ${statusClass} ${priorityClass}">`;
    decoration += `${checkbox} ${this.escapeHtml(this.content)}`;
    
    if (this.due_date && this.isDueSoon()) {
      decoration += `<span class="due-indicator">📅 ${this.formatDueDate()}</span>`;
    }
    
    decoration += '</a>';
    return decoration;
  }
}

class UserNode extends BaseNode {
  email: string;
  role: string;
  is_online: boolean;
  avatar_url?: string;
  
  decorateReference(): string {
    const statusIndicator = this.is_online ? '🟢' : '⚫';
    const roleClass = `role-${this.role.toLowerCase()}`;
    
    let decoration = `<a href="nodespace://${this.id}" class="ns-noderef ns-user ${roleClass}">`;
    
    if (this.avatar_url) {
      decoration += `<img src="${this.avatar_url}" class="user-avatar" alt="${this.content}">`;
    } else {
      decoration += `<span class="user-icon">👤</span>`;
    }
    
    decoration += `${this.escapeHtml(this.content)} ${statusIndicator}`;
    decoration += '</a>';
    return decoration;
  }
}

class DateNode extends BaseNode {
  date: Date;
  date_type: 'date' | 'datetime' | 'time' | 'duration';
  
  decorateReference(): string {
    const calendarIcon = this.getCalendarIcon();
    const formattedDate = this.formatDate();
    const dateClass = `date-${this.date_type}`;
    
    let decoration = `<a href="nodespace://${this.id}" class="ns-noderef ns-date ${dateClass}">`;
    decoration += `${calendarIcon} ${formattedDate}`;
    
    const relativeTime = this.getRelativeTime();
    if (relativeTime) {
      decoration += `<span class="relative-time">(${relativeTime})</span>`;
    }
    
    decoration += '</a>';
    return decoration;
  }
}

ContentProcessor Integration

class ContentProcessor {
  private nodeRegistry: NodeLookupService;
  private NODESPACE_LINK_REGEX = /\[([^\]]+)\]\(nodespace:\/\/([^)]+)\)/g;
  
  /**
   * Process nodespace:// links with node-specific decorations
   */
  private processNodespaceLinks(content: string): string {
    return content.replace(this.NODESPACE_LINK_REGEX, (match, linkText, nodeId) => {
      try {
        const node = this.nodeRegistry.getNode(nodeId);
        
        if (node && typeof node.decorateReference === 'function') {
          return node.decorateReference();
        } else {
          return `<a href="nodespace://${nodeId}" class="ns-noderef ns-missing">${this.escapeHtml(linkText)}</a>`;
        }
      } catch (error) {
        return `<a href="nodespace://${nodeId}" class="ns-noderef ns-error">${this.escapeHtml(linkText)}</a>`;
      }
    });
  }
}

Implementation Tasks

  • Enhance ContentProcessor to detect and render nodespace:// URIs
  • Implement BaseNode decorateReference() default method
  • Create TaskNode decorations (checkboxes, status, due dates, priority)
  • Implement UserNode decorations (avatars, online status, role indicators)
  • Build DateNode decorations (calendar icons, relative time, formatting)
  • Create DocumentNode decorations (file types, preview snippets)
  • Implement NodeLookupService for UUID resolution and caching
  • Build CSS framework for all decoration types (.ns-noderef system)
  • Add decoration caching for performance optimization
  • Integrate with TextNode component for real-time rendering

Acceptance Criteria

  • nodespace:// URIs render with appropriate node type decorations
  • TaskNode references show completion status, due dates, and priority indicators
  • UserNode references display avatars, online status, and role information
  • DateNode references show calendar icons and relative time formatting
  • DocumentNode references display file type icons and preview content
  • Missing nodes render with graceful fallback styling
  • Performance handles 500+ decorated references efficiently
  • All decorations are accessible and keyboard navigable
  • Real-time updates when referenced nodes change
  • CSS styling preserves NodeSpace's hierarchical design

Dependencies

Estimated Effort

8-9 days

Definition of Done

  • ContentProcessor enhanced for nodespace:// link decoration
  • All major node types implement decorateReference() method
  • Rich decorations working for TaskNode, UserNode, DateNode, DocumentNode
  • NodeLookupService operational with caching
  • CSS framework complete with responsive design
  • Performance optimization with viewport-based processing
  • Real-time decoration updates via EventBus integration
  • Comprehensive testing and documentation completed

Technical Notes

This system leverages the content-driven philosophy where each node type uses its actual content property (not artificial display names) and controls its own visual representation through the decorateReference() method. The approach provides maximum flexibility while maintaining consistency.

Activity

  1. self-assigned this
    on Aug 21, 2025
  2. malibio commented on Sep 25, 2025

    @malibio
    CollaboratorAuthor

    Closing as superseded by business logic layer approach. Link decorations will be handled by the new Rust backend system with proper node behaviors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions