Smart Canvas Library Overview

Comprehensive canvas system for Angular applications with drag & drop, connections, theming, and mobile support

Smart Canvas Library Overview

๐ŸŽฏ What is Smart Canvas?

Smart Canvas (@smart-canvas) is a comprehensive, intelligent canvas system designed to replace multiple canvas implementations across the GoGrab Space monorepo. It provides a unified, feature-rich solution for building interactive node-based interfaces, flow composers, and visual editors.

โœจ Key Features

๐ŸŽจ Multi-Theme Ready

๐Ÿ–ฑ๏ธ Advanced Interactions

๐Ÿ“ฑ Mobile Optimized

๐Ÿ”— Node Connectivity

๐Ÿ’พ Intelligent Storage

๐ŸŽ›๏ธ Rich Configuration

๐Ÿ—๏ธ Architecture

Core Components

@smart-canvas/
โ”œโ”€โ”€ SmartCanvasComponent     # Main canvas container
โ”œโ”€โ”€ CanvasNodeComponent      # Individual node rendering
โ”œโ”€โ”€ CanvasConnectionComponent # SVG connection rendering
โ”œโ”€โ”€ CanvasGridComponent      # Background grid system
โ”œโ”€โ”€ CanvasToolbarComponent   # Action toolbar
โ”œโ”€โ”€ CanvasConfigPanel        # Configuration UI
โ””โ”€โ”€ CanvasMinimapComponent   # Navigation minimap

Core Services

@smart-canvas/services/
โ”œโ”€โ”€ SmartCanvasService       # State management & persistence
โ”œโ”€โ”€ CanvasInteractionService # User interaction handling
โ””โ”€โ”€ CanvasDragDropService    # Drag & drop operations

Type System

interface SmartCanvasConfig {
  viewport: CanvasViewport;
  transform: CanvasTransform;
  features: CanvasFeatures;
  interactions: CanvasInteractionConfig;
  appearance: CanvasAppearanceConfig;
  performance: CanvasPerformanceConfig;
  content: CanvasContentConfig;
}

๐Ÿš€ Quick Start

Installation

# Smart Canvas is part of the monorepo
yarn install

Basic Usage

import { SmartCanvasComponent } from '@smart-canvas';

@Component({
  template: `
    <lib-smart-canvas
      [nodes]="nodes"
      [connections]="connections"
      [config]="canvasConfig">
    </lib-smart-canvas>
  `
})
export class MyCanvasComponent {
  nodes: CanvasNode[] = [
    {
      id: 'node-1',
      type: 'process',
      position: { x: 100, y: 100, z: 1 },
      size: { width: 120, height: 80 },
      data: { title: 'Start Process' },
      ports: [
        { id: 'out-1', type: 'output', position: { x: 1, y: 0.5 } }
      ]
    }
  ];

  canvasConfig: Partial<SmartCanvasConfig> = {
    features: {
      enablePanning: true,
      enableZooming: true,
      enableSelection: true,
      showGrid: true
    }
  };
}

Advanced Configuration

canvasConfig: SmartCanvasConfig = {
  appearance: {
    theme: 'modern',
    grid: {
      enabled: true,
      type: 'dots',
      size: 40,
      color: '#e5e5e5',
      opacity: 0.4
    }
  },
  interactions: {
    panSensitivity: 1,
    zoomSensitivity: 0.8,
    selectionRectangle: true,
    panWithSpace: false
  },
  features: {
    enableMultiSelection: true,
    enableConnectionCreation: true,
    showToolbar: true,
    showConfigPanel: true
  }
};

๐ŸŽฎ User Interactions

Mouse Controls

Keyboard Shortcuts

Touch Gestures

๐Ÿ”ง Integration Examples

Flow Composer Integration

// Replace existing canvas with Smart Canvas
@Component({
  template: `
    <lib-smart-canvas
      [nodes]="flowNodes"
      [connections]="flowConnections"
      [config]="flowConfig"
      (nodeUpdate)="onNodeUpdate($event)"
      (connectionCreate)="onConnectionCreate($event)"
      (contextMenu)="onContextMenu($event)">
    </lib-smart-canvas>
  `
})
export class FlowComposerComponent {
  // Migrate existing flow data to Smart Canvas format
}

Logic Builder Integration

// Convert logic blocks to Smart Canvas nodes
const logicNodes = logicBlocks.map(block => ({
  id: block.id,
  type: 'logic',
  position: block.position,
  size: block.size,
  data: block.config,
  ports: block.inputs.concat(block.outputs)
}));

๐Ÿ“Š Performance Features

Optimization Strategies

Performance Monitoring

canvasConfig.performance = {
  enableVirtualScrolling: true,
  maxVisibleNodes: 1000,
  debounceMs: 16,
  updateStrategy: 'frame-aligned'
};

๐ŸŽจ Theming System

Built-in Themes

Custom Themes

canvasConfig.appearance.customTheme = {
  primary: '#your-primary-color',
  background: '#your-bg-color',
  grid: '#your-grid-color',
  nodes: {
    default: '#your-node-color',
    selected: '#your-selection-color'
  }
};

๐Ÿ”— API Reference

Core Interfaces

Event System

๐Ÿงช Testing

Unit Tests

# Run Smart Canvas tests
yarn test smart-canvas

Integration Tests

# Test with Flow Composer
yarn test flow-composer-integration

๐Ÿ“ˆ Migration Guide

From Space Canvas

  1. Replace <space-canvas> with <lib-smart-canvas>
  2. Update node data structure to include ports
  3. Configure theme to 'space' for consistent appearance

From Logic Builder

  1. Convert logic blocks to CanvasNode format
  2. Map input/output connections to ports
  3. Update event handlers for new API

From Flow Composer

  1. Migrate flow data to Smart Canvas format
  2. Update connection creation logic
  3. Integrate with new toolbar and config panel

๐ŸŽฏ Best Practices

Performance

Accessibility

User Experience

๐Ÿ”ฎ Future Roadmap

Planned Features

Performance Improvements


Smart Canvas represents the next generation of canvas systems in the GoGrab Space ecosystem, providing a unified, powerful, and extensible foundation for all visual editing needs.