diff --git a/CLAUDE.md b/CLAUDE.md index 83039a3..d508332 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -4,10 +4,70 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co ## Overview -TestDrive-JSUI is a standalone JavaScript UI rendering engine and testing framework. It's designed as an independent, reusable capability that provides: -- Interactive JavaScript UI for markdown editing/viewing -- Python-JavaScript test integration bridge -- Self-contained plugin architecture with no hardcoded paths +**TestDrive-JSUI is a JavaScript-first markdown editor library.** + +This is a pure JavaScript library for interactive markdown editing that works standalone in any browser. Language adapters (Python, Ruby, Java) are **optional integration helpers** - they do NOT provide core functionality. + +**Key Facts**: +- **Core:** Complete JavaScript library (`js/testdrive-jsui.js`) +- **Dependencies:** Only marked.js for markdown parsing +- **Standalone:** Works without any backend (can run from file://) +- **Optional Adapters:** Python/Ruby/Java adapters help with asset serving and backend integration +- **Architecture:** JavaScript-first design (see `ARCHITECTURE.md`) + +## JavaScript Library + +### Quick Start + +```html + + +
+ + + + + + + + +``` + +### API + +**Constructor Options:** +- `container` (required): CSS selector or DOM element +- `markdown`: Initial content +- `mode`: 'edit' or 'view' (default: 'edit') +- `theme`: Theme name (default: 'github') +- `autosave`: Auto-save enabled (default: false) +- `shortcuts`: Keyboard shortcuts (default: true) +- `sections`: Section-based editing (default: true) +- `debug`: Debug mode (default: false) + +**Methods:** +- `getMarkdown()`: Get current content +- `setMarkdown(markdown)`: Set content +- `getStatus()`: Get editor status +- `save()`: Trigger save event +- `download(filename)`: Download as .md file +- `on(event, callback)`: Listen to events +- `destroy()`: Clean up + +**Events:** `initialized`, `save`, `content-changed`, `autosave`, `download`, `reset`, `destroyed` + +### Examples + +See `/examples`: +- `standalone.html` - Minimal proof of concept +- `full-editor.html` - Complete demo with all features ## Migration Status @@ -88,38 +148,55 @@ make testdrive-jsui-clean ### Directory Structure ``` testdrive-jsui/ -├── src/testdrive_jsui/ # Python package -│ ├── core/ # Core framework components -│ ├── components/ # UI component helpers -│ ├── utils/ # Utility functions -│ └── testing/ # Python-JS bridge -│ ├── js_test_runner.py # JavaScript test execution -│ └── integration.py # Pytest integration -├── js/ # JavaScript source (consolidated) +├── js/ # JavaScript library (Core functionality) +│ ├── testdrive-jsui.js # 🎯 Main library entry point │ ├── core/ # Core JS: debug-system, section-manager -│ ├── components/ # UI components: dom-renderer, debug-panel +│ ├── components/ # UI components: dom-renderer, debug-panel, document-controls │ ├── controls/ # Control panels: edit, debug, status, contents │ ├── plugins/ # JS plugins │ ├── widgets/ # UI widgets │ ├── utils/ # JS utilities -│ ├── tests/ # JavaScript tests +│ ├── tests/ # JavaScript tests (Jest) │ ├── config-loader.js # Configuration loader -│ ├── main.js # Original main entry point +│ ├── main.js # Legacy main entry point │ └── main-updated.js # Refactored main entry +├── examples/ # 📚 Working examples +│ ├── standalone.html # Minimal proof of concept +│ └── full-editor.html # Complete demo +├── src/testdrive_jsui/ # Python adapter (optional) +│ ├── core/ # Adapter core +│ ├── components/ # Adapter helpers +│ ├── utils/ # Utilities +│ └── testing/ # Python-JS bridge +│ ├── js_test_runner.py # JavaScript test execution +│ └── integration.py # Pytest integration ├── static/ # Static assets │ ├── css/ # Stylesheets (editor, controls, themes) │ ├── images/ # Image assets and icons -│ └── templates/ # HTML templates (index.html) -└── tests/ # Python tests +│ └── templates/ # HTML templates +├── tests/ # Python tests +├── docs/ # Documentation +│ ├── prototypes/ # Archived HTML prototypes +│ └── migration/ # Migration records +├── ARCHITECTURE.md # JavaScript-first architecture details +└── README.md # Main documentation ``` ### Key Design Principles +**JavaScript-First Architecture** (NEW in v1.0.0) +- **Core functionality in JavaScript**: All UI logic, rendering, and editing in JS +- **Standalone capable**: Works without any backend (can run from file://) +- **marked.js only dependency**: For markdown parsing +- **Language adapters optional**: Python/Ruby/Java are integration helpers, not functionality providers +- **Event-driven API**: Clean event system for integration +- **See `ARCHITECTURE.md`** for complete architectural documentation + **Plugin Independence** - **Self-declaring**: Plugin declares its own location - no hardcoded paths needed - **Single source of truth**: All assets in one capability directory -- **Clean boundaries**: JSON config interface between Python and JavaScript -- **No code mixing**: JavaScript stays in `.js` files, never embedded in Python strings +- **Clean boundaries**: JSON config interface between adapters and JavaScript +- **No code mixing**: JavaScript stays in `.js` files, never embedded in strings - Works regardless of installation location **Testing Architecture** diff --git a/README.md b/README.md index 212b7aa..f4d8caf 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,131 @@ # TestDrive-JSUI -A standalone JavaScript UI rendering engine and testing framework. Originally developed for MarkiTect, TestDrive-JSUI is designed as an independent, reusable capability that can be integrated into any Python project. +**A JavaScript-first markdown editor and UI library.** + +TestDrive-JSUI is a pure JavaScript library for interactive markdown editing with section-based management. Language adapters (Python, Ruby, Java) are optional integration helpers for serving assets and backend integration - they do not provide core functionality. ## 🎯 **Purpose** TestDrive-JSUI is designed to: -- **📝 Render markdown with interactive JavaScript UI** for editing and viewing -- **🔌 Work as a standalone plugin** or integrate with any Python project -- **🔒 Protect existing JavaScript UI functionality** during refactoring and development -- **🧪 Integrate JavaScript tests** into Python test suites -- **🏗️ Provide a clean architecture** for JavaScript framework development -- **📊 Enable comprehensive testing** of JavaScript UI components -- **🚀 Support extensibility** for JavaScript framework evolution +- **📝 Provide a complete JavaScript library** for interactive markdown editing +- **🌐 Work standalone in any browser** without backend requirements +- **🔌 Offer optional language adapters** for Python, Ruby, Java, etc. +- **✂️ Enable section-based editing** with independent section management +- **🎨 Support multiple modes** (edit/view) and themes +- **💾 Handle content persistence** (localStorage, download, custom backends) +- **🧪 Include comprehensive testing** for JavaScript and integrations +- **🚀 Support extensibility** through events and configuration + +## 🏛️ **Architecture: JavaScript-First Design** + +TestDrive-JSUI follows a **JavaScript-first architecture**: + +``` +┌─────────────────────────────────────┐ +│ Core: JavaScript Library │ +│ - All functionality in JS │ +│ - Works standalone in browser │ +│ - No backend required │ +│ - Uses marked.js for markdown │ +└─────────────────────────────────────┘ + ↑ ↑ ↑ + │ │ │ +┌──────────┴──┐ ┌───┴────┐ ┌──┴──────┐ +│ Python │ │ Ruby │ │ Java │ +│ Adapter │ │ Adapter│ │ Adapter │ +│ (optional) │ │(future)│ │(future) │ +└─────────────┘ └────────┘ └─────────┘ +``` + +**Key Principle:** JavaScript provides ALL functionality. Language adapters only help with: +- Asset serving +- Configuration injection +- Backend integration (storage, auth, etc.) +- Testing infrastructure + +### Quick Start: JavaScript Library + +```html + + + + + + + + + + + +``` + +### API Reference + +#### Constructor Options + +```javascript +new TestDriveJSUI({ + container: '#editor', // CSS selector or DOM element (required) + markdown: '# Content', // Initial markdown content + mode: 'edit', // 'edit' or 'view' (default: 'edit') + theme: 'github', // Theme name (default: 'github') + autosave: false, // Auto-save to localStorage (default: false) + shortcuts: true, // Keyboard shortcuts (default: true) + sections: true, // Section-based editing (default: true) + debug: false // Debug mode (default: false) +}) +``` + +#### Methods + +| Method | Description | +|--------|-------------| +| `getMarkdown()` | Get current document content | +| `setMarkdown(markdown)` | Set document content | +| `getStatus()` | Get editor status (sections, words, etc.) | +| `save()` | Trigger save event | +| `download(filename)` | Download as markdown file | +| `loadFromLocalStorage()` | Load from browser storage | +| `saveToLocalStorage()` | Save to browser storage | +| `resetAll()` | Reset all sections to original content | +| `destroy()` | Clean up and destroy editor | +| `on(event, callback)` | Listen to events | +| `off(event, callback)` | Remove event listener | + +#### Events + +| Event | Data | Description | +|-------|------|-------------| +| `initialized` | `{mode, theme, sections}` | Editor finished initializing | +| `save` | `{markdown}` | Save triggered | +| `content-changed` | `{markdown}` | Content modified | +| `autosave` | `{markdown}` | Auto-save occurred | +| `download` | `{filename, markdown}` | Document downloaded | +| `reset` | `{}` | Document reset | +| `destroyed` | `{}` | Editor destroyed | + +### Examples + +See the `/examples` directory for: +- **`standalone.html`** - Minimal proof of concept (works from file://) +- **`full-editor.html`** - Complete demo with all features + +## 🐍 **Python Adapter (Optional)** + +For Python projects, TestDrive-JSUI provides an **optional adapter** for integration: ## 🏗️ **Architecture** @@ -459,6 +572,9 @@ MIT License - See main MarkiTect project for details. --- -*Generated: 2025-11-09* -*Status: Phase 1 Implementation* -*Next: Copy JavaScript files and create integration tests* \ No newline at end of file +**Version:** 1.0.0 +**Status:** Full JavaScript Library Implementation Complete ✅ +**Architecture:** JavaScript-First with Optional Language Adapters +**Last Updated:** 2025-12-16 + +See `/examples` for working demos and `ARCHITECTURE.md` for detailed design documentation. \ No newline at end of file diff --git a/examples/README.md b/examples/README.md index 56dc9fd..9b4e019 100644 --- a/examples/README.md +++ b/examples/README.md @@ -6,9 +6,9 @@ This directory contains examples demonstrating TestDrive-JSUI as a standalone Ja ## 📁 Examples -### `standalone.html` - Pure JavaScript Demo +### `standalone.html` - Proof of Concept -**Purpose**: Proves TestDrive-JSUI can work as a pure JavaScript library with no backend. +**Purpose**: Minimal proof that TestDrive-JSUI can work as a pure JavaScript library. **Features**: - ✅ Runs directly in browser (no server needed) @@ -37,25 +37,88 @@ python3 -m http.server 8000 --- +### `full-editor.html` - Complete Library Demo + +**Purpose**: Demonstrates the full TestDriveJSUI library with all features. + +**Features**: +- ✅ **Full Library Integration**: Uses complete `TestDriveJSUI` class +- ✅ **Section-Based Editing**: Click sections to edit them independently +- ✅ **Interactive Controls**: Floating control panel with document operations +- ✅ **Event System**: Listen to save, content-changed, and other events +- ✅ **Multiple Modes**: Switch between edit and view modes +- ✅ **Auto-save**: Optional automatic saving (currently disabled) +- ✅ **Keyboard Shortcuts**: Ctrl+S to save, Escape to close editor +- ✅ **Status Bar**: Real-time document statistics +- ✅ **Image Editing**: Advanced image editing with drag & drop + +**How to Use**: +```bash +# Serve with any static server (required for proper module loading) +python3 -m http.server 8000 +# Then visit: http://localhost:8000/examples/full-editor.html +``` + +**What It Demonstrates**: +- Complete TestDriveJSUI API usage +- Integration of all components (SectionManager, DOMRenderer, DocumentControls) +- Event-driven architecture +- Mode switching (edit/view) +- Document operations (save, load, download, reset) +- Real-time status updates + +**API Example from Demo**: +```javascript +// Initialize editor +const editor = new TestDriveJSUI({ + container: '#editor-container', + markdown: '# Hello World', + mode: 'edit', + theme: 'github', + autosave: false, + shortcuts: true +}); + +// Listen to events +editor.on('save', (data) => { + console.log('Saved:', data.markdown); +}); + +// Get/set content +const markdown = editor.getMarkdown(); +editor.setMarkdown('# Updated content'); + +// Get status +const status = editor.getStatus(); +console.log('Sections:', status.totalSections); +``` + +--- + ## 🎯 Architecture Validation -This standalone example validates the JavaScript-first architecture: +These examples validate the JavaScript-first architecture: -### ✅ What Works Without Backend +### ✅ Implemented Features - Markdown parsing (marked.js) - HTML rendering -- UI display +- UI display and styling - Content management - Save/load (localStorage) - File download +- **Interactive editing UI** ✅ +- **Section-based editing** ✅ +- **Control panels (edit, debug, status)** ✅ +- **Keyboard shortcuts** ✅ +- **Themes** ✅ +- **Event system** ✅ -### ⏸️ What's Still TODO (Full Implementation) -- Interactive editing UI -- Section-based editing -- Control panels (edit, debug, status) -- Keyboard shortcuts -- Themes +### 🚧 Future Enhancements - Plugin system +- Additional themes +- Collaborative editing +- Cloud storage adapters +- Mobile-optimized UI ### 🔧 What Backend Adapters Provide (Optional) - Asset serving at scale @@ -66,27 +129,54 @@ This standalone example validates the JavaScript-first architecture: --- -## 🚀 Next Steps +## 🚀 Getting Started -### 1. Validate Proof of Concept +### 1. Try the Proof of Concept ```bash -# Open standalone.html -# Verify markdown renders correctly -# Try save/load/download buttons +# Open standalone.html in any browser +open examples/standalone.html + +# Test basic functionality: +# - Markdown rendering +# - Save/load/download buttons ``` -### 2. Full JavaScript Library -After validating the concept: -- Create `js/testdrive-jsui.js` main class -- Add interactive editing -- Implement control panels -- Full section management +### 2. Explore the Full Editor +```bash +# Serve the examples directory +cd examples +python3 -m http.server 8000 -### 3. Refactor Python Adapter -Once JavaScript is complete: -- Simplify Python to thin adapter -- Remove HTML generation -- Keep only asset serving and testing +# Open in browser: +# http://localhost:8000/full-editor.html + +# Test advanced features: +# - Click sections to edit +# - Use toolbar buttons +# - Try keyboard shortcuts (Ctrl+S, Escape) +# - Switch between edit/view modes +``` + +### 3. Integrate Into Your Project +```html + + + + + + + + + + + +``` --- @@ -110,5 +200,6 @@ Want to add an example? Please ensure it: --- -**Status**: Proof of Concept +**Status**: Full Implementation Complete ✅ **Last Updated**: 2025-12-16 +**Library Version**: 1.0.0 diff --git a/examples/full-editor.html b/examples/full-editor.html new file mode 100644 index 0000000..156ceab --- /dev/null +++ b/examples/full-editor.html @@ -0,0 +1,535 @@ + + + + + ++ Complete interactive markdown editor demonstrating the full TestDrive-JSUI library. + Click any section to edit, use the toolbar for document operations. +
+