This commit addresses multiple collection management issues to improve user experience:
## Template Selection Modal Improvements
- Replace inline styles with CSS classes for reliable visual feedback
- Fix default template selection conflicts that showed multiple templates as selected
- Add styled template previews that show actual CSS styling differences
- Improve modal responsiveness and visual hierarchy
## Collection Item Creation Fixes
- Fix empty collection items with no content/height that were unclickable
- Preserve template placeholder content during item creation instead of clearing it
- Implement proper positioning system using GetMaxPosition to place new items at collection end
- Add position calculation logic to prevent new items from jumping to beginning
## Backend Positioning System
- Add GetMaxPosition method to all repository implementations (SQLite, PostgreSQL, HTTPClient)
- Update CreateCollectionItemFromTemplate to calculate correct position (maxPos + 1)
- Maintain reconstruction ordering by position ASC for consistent item placement
## Frontend Template Selection
- CSS class-based selection states replace problematic inline style manipulation
- Template previews now render actual HTML with real page styling
- Improved hover states and selection visual feedback
- Fixed auto-selection interference with user interaction
These changes ensure collection items appear in expected order and template selection
provides clear visual feedback with actual styling previews.
Restore missing content hydration logic in reconstructCollectionItems method that was accidentally removed during the engine file split (b46f643). Collection items were appearing empty instead of displaying original developer content. This fix restores the database-first behavior where content is properly extracted, stored, and injected back into .insertr elements within collection items.
Replace nil context with context.Background() in content.go to prevent database operations from hanging indefinitely. Clean up outdated documentation files and add current project structure analysis.
Split monolithic engine.go (776 lines) into specialized files:
- engine.go: Core orchestration (142 lines, 82% reduction)
- collection.go: Collection processing and management (445 lines)
- content.go: Content injection and extraction (152 lines)
- discovery.go: Element discovery and DOM traversal (85 lines)
Benefits:
- Single responsibility principle applied to each file
- Better code organization and navigation
- Improved testability of individual components
- Easier team development and code reviews
- Maintained full API compatibility with no breaking changes
- Move addClass and setAttribute from ContentEngine/Injector to utils.go
- Remove duplicate hasInsertrClass implementation
- Add RemoveClass and HasClass utilities for completeness
- Eliminates 74+ lines of exact duplication across files
- Eliminate content.Enhancer wrapper around engine.ContentEngine
- Update cmd/enhance.go to call engine.ProcessFile/ProcessDirectory directly
- Update sites/manager.go to use engine.NewContentEngineWithAuth directly
- Remove unused EnhancementConfig and discovery configuration logic
- Simplify enhance command to use input path as site ID
- Remove CLI config dependency from config package
- Implement complete mushroom foraging blog with chanterelles article
- Add rich demonstration of .insertr and .insertr-add functionality
- Include comprehensive documentation for future .insertr-content vision
- Update project styling and configuration to support blog demo
- Enhance engine and API handlers for improved content management
- Remove dan-eden-portfolio and devigo-web demo sites
- Clean up demo testing infrastructure and scripts
- Remove frontend test files (html-preservation, style-detection tests)
- Update configuration and auth improvements
- Simplify demo structure to focus on core functionality
This cleanup reduces repository size and focuses on essential demos.
- Remove auto-discovery entirely (~450 lines)
* Delete internal/content/discoverer.go
* Simplify enhancer to single-phase processing
* Remove duplicate container expansion logic
- Consolidate repository implementations
* Move internal/content/client.go → internal/db/http_client.go
* Group all repository implementations in db/ package
- Add file utilities to engine following Go stdlib patterns
* Add engine.ProcessFile() and ProcessDirectory() methods
* Engine now handles both content processing AND file operations
- Move site management to dedicated package
* Move internal/content/site_manager.go → internal/sites/manager.go
* Clear separation of site lifecycle from content processing
- Preserve container expansion (syntactic sugar)
* .insertr on containers still auto-applies to viable children
* Container detection logic consolidated in engine/utils.go
Result: Clean architecture with single source of truth for .insertr processing
- Add comprehensive nested route structure with proper authentication layers
- Implement UpdateContent and ReorderCollectionItems handlers with repository pattern
- Add automatic mock JWT token fetching for seamless development workflow
- Restore content editing and collection reordering functionality broken after database refactoring
- Provide production-ready authentication architecture with development convenience
- Enable full CMS operations in browser with proper CRUD and bulk transaction support
- Replace type switching with clean repository pattern using sqlc-generated code
- Move ContentRepository interface and domain models to db package
- Create separate SQLiteRepository and PostgreSQLRepository implementations
- Remove unnecessary RepositoryAdapter and ContentClient interface duplication
- Update all clients (HTTP, Mock) to implement db.ContentRepository directly
- Add context.Context parameters to all repository methods (Go best practice)
- Eliminate duplicate domain models and type conversions
- Remove type aliases - use db package types directly throughout codebase
- Update engine, content managers, and API handlers to use repositories directly
Benefits:
- Zero runtime type switching overhead
- Single source of truth for domain models
- Clean package boundaries and separation of concerns
- Standard Go interface patterns with context support
- Easier testing with mockable repository interface
- Maintainable: adding new database types requires no changes to existing code
- Update collection manager to use data-collection-id instead of data-content-id
- Add safety checks to prevent undefined Map access in addItemControls
- Add validation in editor to only initialize collections with valid collection IDs
- Resolves TypeError and missing attribute errors in frontend collection management
- Add bulk reorder API endpoint (PUT /api/collections/{id}/reorder) with atomic transactions
- Replace individual position updates with efficient bulk operations in frontend
- Implement unified ID generation and proper data-item-id injection during enhancement
- Fix collection item position persistence through content edit cycles
- Add optimistic UI with rollback capability for better user experience
- Update sqlc queries to include last_edited_by fields in position updates
- Remove obsolete data-content-type attributes and unify naming conventions
Consolidates duplicate code and removes technical debt accumulated during rapid development. This cleanup improves maintainability while preserving all functionality.
Backend cleanup:
- Remove unused legacy function findViableChildrenLegacy()
- Consolidate duplicate SQL null string helper functions into shared utils
- Unify text extraction functions across utils, engine, and id_generator
- Consolidate duplicate attribute getter functions into single implementation
Frontend cleanup:
- Remove duplicate authentication methods (authenticateWithOAuth vs performOAuthFlow)
- Remove unused hasPermission() method from auth.js
- Centralize repetitive API endpoint construction in api-client.js
- Reduce excessive console logging while preserving important error logs
Impact: -144 lines of code, improved maintainability, no functionality changes
All tests pass and builds succeed
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
• Add full collection REST API with CRUD operations for collections and items
• Implement collection models, handlers, and database integration with SQLite/PostgreSQL support
• Add collection endpoints: GET/POST/PUT/DELETE for collections and collection items
• Fix critical server enhancement bug by consolidating to engine.DatabaseClient
• Remove obsolete content.DatabaseClient that lacked collection support
• Enable proper collection reconstruction during server-side enhancement
• Collections now persist correctly and display new items after API modifications
• Add full multi-table schema for collections with normalized design (collections, collection_templates, collection_items, collection_item_versions)
• Implement collection detection and processing in enhancement pipeline for .insertr-add elements
• Add template extraction and storage from existing HTML children with multi-variant support
• Enable collection reconstruction from database on server restart with proper DOM rebuilding
• Extend ContentClient interface with collection operations and full database integration
• Update enhance command to use engine.DatabaseClient for collection persistence support
- Remove .insertr-default-style special styling (blue background, border, dot indicator)
- Make ALL buttons use .insertr-style-preview with unified appearance
- Maintain authentic style previews in isolated .insertr-style-sample layer
- Bold buttons show bold text, .brand buttons show green uppercase text, etc.
- Eliminate visual inconsistency between semantic and detected style buttons
- Simplify CSS by removing ~50 lines of duplicate button styling
- Provide consistent professional toolbar appearance across all formatting options
- Move padding from .insertr-button-frame to .insertr-style-btn.insertr-style-preview
- Add align-items and justify-content to button container for proper centering
- Remove width: 100% from button frame to prevent unnecessary stretching
- Fix off-center text in default Bold, Italic, and Link buttons
- Maintain style isolation while ensuring consistent button alignment
- Add margin/padding reset to .insertr-style-sample to prevent browser defaults
- Remove unused .insertr-default-preview CSS that was causing confusion
- Ensure consistent spacing across all button types (default vs detected styles)
- Clean up legacy CSS classes that are no longer used with three-layer architecture
- Add button frame isolation layer to prevent site CSS from affecting toolbar appearance
- Create style sample container for authentic style previews without layout interference
- Update CSS with proper containment boundaries and !important rules for button structure
- Preserve all authentic styling (color, weight, transform, decoration) in isolated preview
- Fix inconsistent button appearance across different site stylesheets (e.g. .brand class)
- Maintain professional toolbar UX while showing accurate style previews
Multi-Property Editor Polish:
- Add comprehensive form styling (.insertr-form-group, .insertr-form-input, etc.)
- Professional layout with titles, validation, auto-focus, and help text
- Enhanced link/button/image editors with real-time validation
- Consistent spacing, colors, and visual hierarchy
Smart Default Formatting:
- Add Bold, Italic, Link options when not detected in content
- Intelligent detection respects existing developer styles
- Visual distinction for default vs detected styles with info-colored borders
- Content-aware: only adds to elements that benefit from text formatting
Link Interface Unification:
- Create shared createLinkConfigurationForm() component
- Eliminate code duplication between direct editing and popup creation
- Update createLinkEditor() and showLinkConfigPopup() to use shared component
- Fix link button styling to match other style buttons with preview content
Benefits:
- Consistent professional editing experience across all interfaces
- Reduced maintenance burden through code unification
- Enhanced UX with validation, keyboard shortcuts, and visual feedback
- Maintains CLASSES.md philosophy while improving out-of-box experience
Major architectural simplification removing content type complexity:
Database Schema:
- Remove 'type' field from content and content_versions tables
- Simplify to pure HTML storage with html_content + original_template
- Regenerate all sqlc models for SQLite and PostgreSQL
API Simplification:
- Remove content type routing and validation
- Eliminate type-specific handlers (text/markdown/structured)
- Unified HTML-first approach for all content operations
- Simplify CreateContent and UpdateContent to HTML-only
Backend Enhancements:
- Update enhancer to only generate data-content-id (no data-content-type)
- Improve container expansion utilities with comprehensive block/inline rules
- Add Phase 3 preparation with boundary-respecting traversal logic
- Strengthen element classification for viable children detection
Documentation:
- Update TODO.md to reflect Phase 1-3 completion status
- Add WORKING_ON.md documenting the architectural transformation
- Mark container expansion and HTML-first architecture as complete
This completes the transition to a unified HTML-first content management system
with automatic style detection and element-based behavior, eliminating the
complex multi-type system in favor of semantic HTML-driven editing.
- Add backend container transformation in engine.go following syntactic sugar specification
- Containers with .insertr get class removed and viable children get .insertr added
- Remove incorrect frontend container expansion - frontend only finds enhanced elements
- Fix StyleAwareEditor hasMultiPropertyElements runtime error
- Add addClass/removeClass methods to ContentEngine for class manipulation
- Update frontend to match HTML-first approach with no runtime container logic
- Test verified: container <section class='insertr'> transforms to individual h1.insertr, p.insertr, button.insertr
This completes the container expansion functionality per CLASSES.md:
Developer convenience (one .insertr enables section editing) + granular control (individual element editing)
- Add sibling context detection to identify unique heading content
- Include parent container context with enhanced class filtering
- Look for heading siblings (h1-h6) that provide unique container context
- Extract up to 12 chars of sibling heading text for differentiation
Results:
✅ Collision Elimination: From 8 collisions to 0 collisions
✅ Unique Base IDs: Each element gets distinct ID (no -1, -2, -3 suffixes)
✅ Better Context: 'Example 1', 'Example 2' headings provide unique signatures
✅ Maintained Stability: Same elements still get same IDs across runs
Before: index-p-cad2a8, index-p-cad2a8-1, index-p-cad2a8-2... (8 collisions)
After: index-p-1198e8, index-p-215de9, index-p-604e11... (0 collisions)
- Remove content preview from ID generation for stable structural IDs
- Implement database-first approach to check content existence before creation
- Add enhanced DOM path, semantic context, and precise sibling indexing
- Replace HTML attribute checking with reliable database lookups
- Add collision handling with increment counters for similar elements
Fixes:
✅ UNIQUE constraint errors eliminated (multiple enhancement runs work)
✅ Structural stability (same element keeps same ID regardless of content changes)
✅ Database-driven workflow (single source of truth for content existence)
✅ Enhanced collision resistance with detailed structural differentiation
Results: No more 'Failed to store content' errors, stable enhance workflow.
- Remove --clean-db flag references from all documentation
- Update SERVER_UPDATE.md with enhanced deterministic ID generation achievements
- Mark Phase 3a as COMPLETE & PRODUCTION READY
- Document enhance button workflow completion
- Clean up development workflow examples
Phase 3a HTML-first architecture implementation is now fully documented and complete.
- Replace random UUID with 6-component deterministic signature
- Use filePath|domPath|tag|classes|contentPreview|siblingIndex for uniqueness
- Enhance sibling positioning with insertr-aware index calculation
- Improve DOM path generation with meaningful class inclusion
- Restore ID consistency across enhancement runs for reliable content injection
Results:
✅ ID Consistency: Same elements always get same IDs (index-p-639460)
✅ Collision Resistance: Different elements get different IDs (4c7206, 23df20, 5a975d)
✅ File Scoping: Same structure in different files gets different IDs
✅ Enhanced Workflow: API edit → enhance button → content injected successfully
Fixes enhance button by ensuring API content IDs match enhancement-generated IDs.
- Replace random UUID suffix with deterministic hash-based signature
- Use element DOM path, sibling position, and content preview for uniqueness
- Ensure same elements always get the same content ID across enhancements
- Fix critical bug where content updates weren't being injected into static files
This resolves the enhance button workflow: API content updates → enhance trigger → static file injection.
- Extract content from formData.content instead of passing whole object
- Add logic to call updateContent() for existing content vs createContent() for new
- Fix 400 Invalid JSON error caused by sending object instead of string
- Handle different formData formats: string, {content: string}, {text: string}
The frontend was sending html_content as {type:'html', content:'...'} object
but server expected a plain string. Now properly extracts the content value.
- Replace value field with html_content for direct HTML storage
- Add original_template field for style detection preservation
- Remove all markdown processing from injector (delete markdown.go)
- Fix critical content extraction/injection bugs in engine
- Add missing UpdateContent PUT handler for content persistence
- Fix API client field names and add updateContent() method
- Resolve content type validation (only allow text/link types)
- Add UUID-based ID generation to prevent collisions
- Complete first-pass processing workflow for unprocessed elements
- Verify end-to-end: Enhancement → Database → API → Editor → Persistence
All 37 files updated for HTML-first content management system.
Phase 3a implementation complete and production ready.
## Library Code Cleanup (~1,200+ lines removed)
- Remove legacy markdown system (markdown.js, previewer.js)
- Delete unused EditContext code from ui/editor.js (~400 lines)
- Remove version history UI components from form-renderer.js (~180 lines)
- Clean unused CSS styles from insertr.css (~120 lines)
- Update package.json dependencies (remove marked, turndown)
## Documentation Updates
- README.md: Update from markdown to HTML-first approach
- AGENTS.md: Add current architecture guidance and HTML-first principles
- TODO.md: Complete rewrite with realistic roadmap and current status
- demos/README.md: Update for development demo server usage
## System Reality Alignment
- All documentation now reflects current working system
- Removed aspirational features in favor of actual capabilities
- Clear separation between development and production workflows
- Accurate description of style-aware editor with HTML preservation
## Code Cleanup Benefits
- Simplified codebase focused on HTML-first approach
- Removed markdown conversion complexity
- Cleaner build process without unused dependencies
- Better alignment between frontend capabilities and documentation
Ready for Phase 3a server updates with clean foundation.
- Document HTML-first API architecture vision
- Define template lifecycle management system
- Plan schema updates for content and template storage
- Outline development vs production mode handling
- Specify implementation tasks and priorities
- Add JavaScript-based style copying from original elements to toolbar buttons
- Use getComputedStyle() to dynamically apply color, font-weight, text-decoration, text-transform
- Preserve button clickability with protected backgrounds and hover states
- Support any CSS framework/custom styles without hardcoded mappings
- Add comprehensive documentation to TODO.md for future enhancements
Examples:
- 'Emphasis' button now shows red bold text (from .emph class)
- 'Highlight' button displays with style preview while remaining clickable
- 'Brand' button demonstrates text-transform and color changes
This provides intuitive visual feedback so users immediately understand
what each formatting button will do to their content.
- Remove clunky multi-property editor with separate text + URL inputs
- Implement single rich text editor (contentEditable) for all content
- Add popup-based link configuration: select text → click 🔗 Link → configure
- Filter out link styles from formatting toolbar (links use popup, not buttons)
- Consolidate CSS: remove separate style-aware-editor.css, integrate into insertr.css
- Clean up 200+ lines of unused multi-property form code and styles
- Fix duplicate link style detection (no more 'Fancy Link' + 'Link' buttons)
Result: Much cleaner UX similar to modern editors where formatting uses
toolbar buttons and complex elements (links) use dedicated popups.
- Fix TypeError when accessing form.style by adding fallback selectors
- Support both legacy (.insertr-edit-form) and new editor class names
- Add null checks to prevent crashes when form element is not found
- Ensure ensureModalVisible works with all editor types
Resolves positioning error when opening style-aware editor interface.
- Add StyleAwareEditor class with intelligent editing strategy detection
- Implement three editing modes: simple text, rich content, multi-property forms
- Create dynamic formatting toolbar with buttons for detected styles
- Add multi-property editing forms for complex elements (links, images, buttons)
- Integrate contentEditable with style application/removal functionality
- Replace markdown-based editor.js with style-aware architecture
- Add comprehensive CSS styling for modern, responsive editor interface
- Support fallback editing for error cases with graceful degradation
- Enable real-time style application to selected text in rich editor
- Preserve all element attributes and structure during editing workflow
Complete implementation of CLASSES.md style preservation specification.
Phase 2 foundation ready for final testing and refinement.
- Add StyleDetectionEngine with one-layer-deep nested element analysis
- Add HTMLPreservationEngine for direct HTML manipulation without lossy conversion
- Implement structure-preserving content parsing that maintains element positions
- Add multi-property element support for links (href + content), images (src + alt), buttons
- Create comprehensive test suite with real DOM element validation
- Replace markdown-based system foundation with HTML-first architecture
- Preserve all element attributes (classes, IDs, data-*, aria-*) during editing
- Generate human-readable style names from detected nested elements
- Support template extraction with multiple insertion points for complex elements
Foundation complete for Phase 2 style-aware editor interface per CLASSES.md specification.
- Remove complex style preservation system from editor
- Simplify markdown conversion back to straightforward approach
- Remove StyleContext class and style-aware conversion methods
- Switch content type from 'html' back to 'markdown' for consistency
- Clean up editor workflow to focus on core markdown editing
- Remove ~500 lines of unnecessary style complexity
This completes the UI unification cleanup by removing the overly complex
style preservation system that was making the editor harder to maintain.
- Add StyleContext class for extracting and applying HTML attributes/styles
- Enhance MarkdownConverter with style-aware conversion methods
- Switch backend storage from markdown to HTML with 'html' content type
- Update editor workflow to preserve CSS classes, IDs, and attributes
- Maintain markdown editing UX while storing HTML for style preservation
- Support complex attributes like rel, data-*, aria-*, etc.
This enables editing styled content like <a class="fancy" rel="me">text</a>
while preserving all styling attributes through the markdown editing process.
- Add syntactic sugar for container transformation: .insertr containers → children get .insertr
- Fix discovery auto-running when disabled with site-specific config loading
- Add comprehensive styling test examples for HTML attribute preservation
- Include test input for syntactic sugar validation
- Update discovery defaults to respect developer intent (disabled by default)