Files
markitect-main/testdrive-jsui/static/js/controls/contents-control.js
tegwick 8ef356af57 feat: implement plugin infrastructure for rendering engines
Added comprehensive plugin system for independent JavaScript UI development:

**Plugin Infrastructure:**
- Extended existing MarkiTect plugin system with RenderingEnginePlugin base class
- Added RENDERING plugin type to PluginType enum
- Created RenderingConfig for asset management and deployment
- Implemented RenderingEngineManager for plugin discovery and lifecycle

**TestDrive JSUI Plugin:**
- Extracted JavaScript UI components to independent testdrive-jsui plugin
- Created standalone development environment (no Python required)
- Implemented compass-positioned control panels (NW, NE, E, SE)
- Added clean JSON configuration interface for Python↔JavaScript data transfer

**Asset Management:**
- Development mode: serve assets directly from plugin source directory
- Production mode: deploy to _markitect/plugins/[plugin-name]/ structure
- Configurable asset URLs and deployment strategies
- Support for external dependencies (CDN resources)

**Standalone Development:**
- testdrive-jsui/test.html for browser-based development
- Package.json with npm scripts for development server
- Complete separation of JavaScript development from Python environment
- Hot reload and standard web development workflow

**Integration Demo:**
- demo_plugin_integration.py showcasing all plugin capabilities
- Standalone, plugin discovery, production deployment examples
- Asset URL generation for different deployment modes

This enables JavaScript-first development while maintaining clean integration
with the MarkiTect Python ecosystem. Developers can now work on UI components
independently using standard web development tools and workflows.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-14 06:49:41 +01:00

93 lines
3.4 KiB
JavaScript

/**
* Contents Control - Displays document table of contents
* Implements the Robustness Principle with Fail Fast mode support
*/
class ContentsControl {
constructor() {
this.control = Object.create(Control);
this.control.config = {
icon: '☰',
title: 'Contents',
className: 'contents-control',
defaultContent: 'Click to view table of contents',
ariaLabel: 'Contents Control',
position: 'w'
};
// Bind methods to control
this.control.buildContent = () => {
const content = this.control.element.querySelector('.control-content');
const headings = this.extractHeadings();
content.innerHTML = `
<div style="padding: 1rem; font-size: 0.8rem;">
<h4 style="margin-top: 0;">Table of Contents</h4>
<div style="max-height: 250px; overflow-y: auto;">
${headings.length > 0 ?
headings.map(heading =>
`<div style="margin-bottom: 0.3rem; padding-left: ${(heading.level - 1) * 15}px;">
<a href="#${heading.id}"
style="text-decoration: none; color: #0066cc; font-size: ${0.9 - (heading.level - 1) * 0.05}rem;"
onclick="document.getElementById('${heading.id}')?.scrollIntoView({behavior: 'smooth'})">
${heading.text}
</a>
</div>`
).join('') :
'<p>No headings found in document</p>'
}
</div>
<div style="margin-top: 1rem; font-size: 0.7rem; color: #666;">
${headings.length} heading${headings.length !== 1 ? 's' : ''} found
</div>
</div>
`;
this.control.isExpanded = true;
};
this.control.toggle = () => {
if (this.control.isExpanded) {
this.control.element.querySelector('.control-content').style.display = 'none';
this.control.isExpanded = false;
} else {
this.control.buildContent();
this.control.element.querySelector('.control-content').style.display = 'block';
}
};
}
extractHeadings() {
const headings = [];
const elements = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
elements.forEach((heading, index) => {
const level = parseInt(heading.tagName.charAt(1));
const text = heading.textContent || heading.innerText || '';
let id = heading.id;
// Generate ID if not present
if (!id) {
id = text.toLowerCase()
.replace(/[^\w\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-')
.replace(/^-|-$/g, '') || `heading-${index}`;
heading.id = id;
}
headings.push({
level: level,
text: text.trim(),
id: id
});
});
return headings;
}
createControl() {
return this.control.createControl();
}
}
window.ContentsControl = ContentsControl;