1.2.1 β€’ Published 10 months ago

@eavfw/er-diagram v1.2.1

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

@eavfw/er-diagram

A powerful React component library for visualizing and editing Entity-Relationship diagrams with built-in internationalization support, module organization, and interactive features.

ER Diagram Example

Features

  • 🎨 Interactive ER diagram visualization
  • 🌐 Built-in internationalization (i18n) support
  • πŸ“¦ Module-based organization
  • ↔️ Smart relationship routing
  • πŸ”„ Real-time updates
  • πŸ“± Responsive design
  • 🎯 Context menus for quick actions
  • πŸ”‘ Primary and foreign key visualization
  • 🎭 Dark mode support

Installation

npm install @eavfw/er-diagram

Quick Start

import { ERDiagram, DataModelProvider } from '@eavfw/er-diagram';

function App() {
  const schema = {
    modules: ['Core'],
    tables: [
      {
        name: 'users',
        module: 'Core',
        locales: {
          '1033': { singular: 'User', plural: 'Users' }
        },
        attributes: {
          id: { 
            name: 'id', 
            type: 'uuid', 
            isPrimary: true 
          },
          email: { 
            name: 'email', 
            type: 'varchar(255)' 
          }
        }
      }
    ]
  };

  return (
    <DataModelProvider initialSchema={schema}>
      <div className="w-screen h-screen">
        <ERDiagram />
      </div>
    </DataModelProvider>
  );
}

Schema Structure

SchemaData

interface SchemaData {
  modules: string[];           // List of modules
  tables: Table[];            // List of tables
  variables?: Record<string, any>; // Optional variables for reuse
}

Table Definition

interface Table {
  name: string;               // Table name
  pluralName?: string;        // Plural form
  module?: string;            // Module name
  sitemap?: string;          // UI navigation location
  locales?: Record<string, {  // Localized names
    singular: string;
    plural: string;
  }>;
  attributes: {              // Table columns
    [key: string]: {
      name: string;
      type: string;
      isPrimary?: boolean;
      isForeign?: boolean;
      references?: {
        table: string;
        attribute: string;
      };
    }
  };
}

Advanced Features

Variable Support

Use variables to define reusable attribute sets:

const schema = {
  variables: {
    audit: {
      "Modified On": {
        type: { type: "DateTime", required: true },
        locale: { "1030": { displayName: "Γ†ndret" } }
      },
      "Created On": {
        type: { type: "DateTime", required: true },
        locale: { "1030": { displayName: "Oprettet" } }
      }
    }
  },
  tables: [
    {
      name: "users",
      attributes: {
        "[merge()]": "[variables('audit')]",
        // ... other attributes
      }
    }
  ]
};

Supported Localizations

The component supports multiple locales out of the box:

  • πŸ‡ΊπŸ‡Έ English (US) - 1033
  • πŸ‡©πŸ‡° Danish - 1030
  • πŸ‡©πŸ‡ͺ German - 1031
  • πŸ‡«πŸ‡· French - 1036
  • πŸ‡ͺπŸ‡Έ Spanish - 1034
  • πŸ‡³πŸ‡΄ Norwegian - 1044
  • πŸ‡ΈπŸ‡ͺ Swedish - 1053

Module Organization

Tables can be organized into modules for better visualization:

const schema = {
  modules: ['Core', 'Blog', 'Commerce'],
  tables: [
    {
      name: 'products',
      module: 'Commerce',
      // ... other properties
    }
  ]
};

API Reference

Components

ERDiagram

Main component for rendering the ER diagram.

<ERDiagram />

DataModelProvider

Context provider for schema data and actions.

<DataModelProvider initialSchema={schema}>
  {children}
</DataModelProvider>

Hooks

useDataModel

Access and modify the data model from any component.

const { schema, dispatch, selectedLocale } = useDataModel();

Contributing

Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Acknowledgments

  • Built with React and ReactFlow
  • Styled with Tailwind CSS
  • UI components from Radix UI
1.2.1

10 months ago

1.2.0

10 months ago

1.1.0

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago